repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
thebuggenie/b2db | src/Table.php | Table.rawSelectOne | public function rawSelectOne(Query $query, $join = 'all')
{
$query->setTable($this);
$query->setupJoinTables($join);
$query->setLimit(1);
$query->generateSelectSQL();
$resultset = Statement::getPreparedStatement($query)->execute();
$resultset->next();
return $resultset->getCurrentRow();
} | php | public function rawSelectOne(Query $query, $join = 'all')
{
$query->setTable($this);
$query->setupJoinTables($join);
$query->setLimit(1);
$query->generateSelectSQL();
$resultset = Statement::getPreparedStatement($query)->execute();
$resultset->next();
return $resultset->getCurrentRow();
} | [
"public",
"function",
"rawSelectOne",
"(",
"Query",
"$",
"query",
",",
"$",
"join",
"=",
"'all'",
")",
"{",
"$",
"query",
"->",
"setTable",
"(",
"$",
"this",
")",
";",
"$",
"query",
"->",
"setupJoinTables",
"(",
"$",
"join",
")",
";",
"$",
"query",
... | Selects one row from the table based on the given criteria
@param Query $query
@param mixed $join
@return Row
@throws Exception | [
"Selects",
"one",
"row",
"from",
"the",
"table",
"based",
"on",
"the",
"given",
"criteria"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Table.php#L447-L458 | train |
thebuggenie/b2db | src/Table.php | Table.selectOne | public function selectOne(Query $query, $join = 'all')
{
$row = $this->rawSelectOne($query, $join);
return $this->populateFromRow($row);
} | php | public function selectOne(Query $query, $join = 'all')
{
$row = $this->rawSelectOne($query, $join);
return $this->populateFromRow($row);
} | [
"public",
"function",
"selectOne",
"(",
"Query",
"$",
"query",
",",
"$",
"join",
"=",
"'all'",
")",
"{",
"$",
"row",
"=",
"$",
"this",
"->",
"rawSelectOne",
"(",
"$",
"query",
",",
"$",
"join",
")",
";",
"return",
"$",
"this",
"->",
"populateFromRow"... | Selects one object based on the given criteria
@param Query $query
@param mixed $join
@return Saveable | [
"Selects",
"one",
"object",
"based",
"on",
"the",
"given",
"criteria"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Table.php#L468-L472 | train |
thebuggenie/b2db | src/Table.php | Table.rawDelete | public function rawDelete(Query $query)
{
$query->setTable($this);
$query->generateDeleteSQL();
$value = Statement::getPreparedStatement($query)->execute();
$this->clearB2DBCachedObjects();
return $value;
} | php | public function rawDelete(Query $query)
{
$query->setTable($this);
$query->generateDeleteSQL();
$value = Statement::getPreparedStatement($query)->execute();
$this->clearB2DBCachedObjects();
return $value;
} | [
"public",
"function",
"rawDelete",
"(",
"Query",
"$",
"query",
")",
"{",
"$",
"query",
"->",
"setTable",
"(",
"$",
"this",
")",
";",
"$",
"query",
"->",
"generateDeleteSQL",
"(",
")",
";",
"$",
"value",
"=",
"Statement",
"::",
"getPreparedStatement",
"("... | Perform an SQL delete
@param Query $query
@return Resultset | [
"Perform",
"an",
"SQL",
"delete"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Table.php#L543-L552 | train |
thebuggenie/b2db | src/Table.php | Table.rawDeleteById | public function rawDeleteById($id)
{
if (!$id) {
return null;
}
$query = new Query($this);
$query->where($this->id_column, $id);
$query->generateDeleteSQL();
$this->deleteB2DBObjectFromCache($id);
return Statement::getPreparedStatement($query)->execute();
} | php | public function rawDeleteById($id)
{
if (!$id) {
return null;
}
$query = new Query($this);
$query->where($this->id_column, $id);
$query->generateDeleteSQL();
$this->deleteB2DBObjectFromCache($id);
return Statement::getPreparedStatement($query)->execute();
} | [
"public",
"function",
"rawDeleteById",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"!",
"$",
"id",
")",
"{",
"return",
"null",
";",
"}",
"$",
"query",
"=",
"new",
"Query",
"(",
"$",
"this",
")",
";",
"$",
"query",
"->",
"where",
"(",
"$",
"this",
"->"... | Perform an SQL delete by an id
@param integer $id
@return Resultset|null | [
"Perform",
"an",
"SQL",
"delete",
"by",
"an",
"id"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Table.php#L561-L574 | train |
thebuggenie/b2db | src/Table.php | Table.create | public function create()
{
$sql = $this->generateCreateSql();
$query = new RawQuery($sql);
try {
$this->drop();
return Statement::getPreparedStatement($query)->execute();
} catch (\Exception $e) {
throw new Exception('Error creating table ' . $this->getB2DBName() . ': ' . $e->getMessage(), $sql);
}
} | php | public function create()
{
$sql = $this->generateCreateSql();
$query = new RawQuery($sql);
try {
$this->drop();
return Statement::getPreparedStatement($query)->execute();
} catch (\Exception $e) {
throw new Exception('Error creating table ' . $this->getB2DBName() . ': ' . $e->getMessage(), $sql);
}
} | [
"public",
"function",
"create",
"(",
")",
"{",
"$",
"sql",
"=",
"$",
"this",
"->",
"generateCreateSql",
"(",
")",
";",
"$",
"query",
"=",
"new",
"RawQuery",
"(",
"$",
"sql",
")",
";",
"try",
"{",
"$",
"this",
"->",
"drop",
"(",
")",
";",
"return"... | creates the table by executing the sql create statement
@return Resultset | [
"creates",
"the",
"table",
"by",
"executing",
"the",
"sql",
"create",
"statement"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Table.php#L581-L591 | train |
thebuggenie/b2db | src/Table.php | Table.upgrade | public function upgrade(Table $old_table)
{
$old_columns = $old_table->getColumns();
$new_columns = $this->getColumns();
$added_columns = \array_diff_key($new_columns, $old_columns);
$altered_columns = Tools::array_diff_recursive($old_columns, $new_columns);
$dropped_columns = \array_keys(array_diff_key($old_columns, $new_columns));
/** @var RawQuery[] $queries */
$queries = [];
foreach ($added_columns as $details) {
$queries[] = $this->getAddColumnQuery($details);
}
foreach ($queries as $query) {
if ($query instanceof QueryInterface) {
Statement::getPreparedStatement($query)->execute();
}
}
$this->migrateData($old_table);
$queries = [];
foreach ($altered_columns as $column => $details) {
if (in_array($column, $dropped_columns)) continue;
$queries[] = $this->getAlterColumnQuery($new_columns[$column]);
$queries[] = $this->getAlterColumnDefaultQuery($new_columns[$column]);
}
foreach ($dropped_columns as $details) {
$queries[] = $this->getDropColumnQuery($details);
}
foreach ($queries as $query) {
if ($query instanceof RawQuery) {
Statement::getPreparedStatement($query)->execute();
}
}
} | php | public function upgrade(Table $old_table)
{
$old_columns = $old_table->getColumns();
$new_columns = $this->getColumns();
$added_columns = \array_diff_key($new_columns, $old_columns);
$altered_columns = Tools::array_diff_recursive($old_columns, $new_columns);
$dropped_columns = \array_keys(array_diff_key($old_columns, $new_columns));
/** @var RawQuery[] $queries */
$queries = [];
foreach ($added_columns as $details) {
$queries[] = $this->getAddColumnQuery($details);
}
foreach ($queries as $query) {
if ($query instanceof QueryInterface) {
Statement::getPreparedStatement($query)->execute();
}
}
$this->migrateData($old_table);
$queries = [];
foreach ($altered_columns as $column => $details) {
if (in_array($column, $dropped_columns)) continue;
$queries[] = $this->getAlterColumnQuery($new_columns[$column]);
$queries[] = $this->getAlterColumnDefaultQuery($new_columns[$column]);
}
foreach ($dropped_columns as $details) {
$queries[] = $this->getDropColumnQuery($details);
}
foreach ($queries as $query) {
if ($query instanceof RawQuery) {
Statement::getPreparedStatement($query)->execute();
}
}
} | [
"public",
"function",
"upgrade",
"(",
"Table",
"$",
"old_table",
")",
"{",
"$",
"old_columns",
"=",
"$",
"old_table",
"->",
"getColumns",
"(",
")",
";",
"$",
"new_columns",
"=",
"$",
"this",
"->",
"getColumns",
"(",
")",
";",
"$",
"added_columns",
"=",
... | Perform upgrade for a table, by comparing one table to an old version
of the same table
@param Table $old_table | [
"Perform",
"upgrade",
"for",
"a",
"table",
"by",
"comparing",
"one",
"table",
"to",
"an",
"old",
"version",
"of",
"the",
"same",
"table"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Table.php#L912-L950 | train |
thebuggenie/b2db | src/Cache.php | Cache.set | public function set($key, $value)
{
if (!$this->enabled) {
return false;
}
switch ($this->type) {
case self::TYPE_APC:
apc_store($key, $value);
break;
case self::TYPE_FILE:
$filename = $this->path . $key . '.cache';
file_put_contents($filename, serialize($value));
break;
}
return true;
} | php | public function set($key, $value)
{
if (!$this->enabled) {
return false;
}
switch ($this->type) {
case self::TYPE_APC:
apc_store($key, $value);
break;
case self::TYPE_FILE:
$filename = $this->path . $key . '.cache';
file_put_contents($filename, serialize($value));
break;
}
return true;
} | [
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"enabled",
")",
"{",
"return",
"false",
";",
"}",
"switch",
"(",
"$",
"this",
"->",
"type",
")",
"{",
"case",
"self",
"::",
"TYPE_APC",
... | Store an item in the cache
@param string $key The cache key to store the item under
@param mixed $value The value to store
@return bool | [
"Store",
"an",
"item",
"in",
"the",
"cache"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Cache.php#L131-L149 | train |
thebuggenie/b2db | src/Cache.php | Cache.delete | public function delete($key)
{
if (!$this->enabled) return;
switch ($this->type) {
case self::TYPE_APC:
apc_delete($key);
break;
case self::TYPE_FILE:
$filename = $this->path . $key . '.cache';
unlink($filename);
}
} | php | public function delete($key)
{
if (!$this->enabled) return;
switch ($this->type) {
case self::TYPE_APC:
apc_delete($key);
break;
case self::TYPE_FILE:
$filename = $this->path . $key . '.cache';
unlink($filename);
}
} | [
"public",
"function",
"delete",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"enabled",
")",
"return",
";",
"switch",
"(",
"$",
"this",
"->",
"type",
")",
"{",
"case",
"self",
"::",
"TYPE_APC",
":",
"apc_delete",
"(",
"$",
"key",
... | Delete an entry from the cache
@param string $key The cache key to delete | [
"Delete",
"an",
"entry",
"from",
"the",
"cache"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Cache.php#L156-L168 | train |
thebuggenie/b2db | src/Cache.php | Cache.flush | public function flush()
{
if (!$this->enabled) return;
switch ($this->type) {
case self::TYPE_FILE:
$iterator = new \DirectoryIterator($this->path);
foreach ($iterator as $file_info)
{
if (!$file_info->isDir())
{
unlink($file_info->getPathname());
}
}
}
} | php | public function flush()
{
if (!$this->enabled) return;
switch ($this->type) {
case self::TYPE_FILE:
$iterator = new \DirectoryIterator($this->path);
foreach ($iterator as $file_info)
{
if (!$file_info->isDir())
{
unlink($file_info->getPathname());
}
}
}
} | [
"public",
"function",
"flush",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"enabled",
")",
"return",
";",
"switch",
"(",
"$",
"this",
"->",
"type",
")",
"{",
"case",
"self",
"::",
"TYPE_FILE",
":",
"$",
"iterator",
"=",
"new",
"\\",
"Director... | Flush all entries in the cache | [
"Flush",
"all",
"entries",
"in",
"the",
"cache"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Cache.php#L199-L214 | train |
thebuggenie/b2db | src/Resultset.php | Resultset.getCurrentRow | public function getCurrentRow()
{
if (isset($this->rows[($this->int_ptr - 1)])) {
return $this->rows[($this->int_ptr - 1)];
}
return null;
} | php | public function getCurrentRow()
{
if (isset($this->rows[($this->int_ptr - 1)])) {
return $this->rows[($this->int_ptr - 1)];
}
return null;
} | [
"public",
"function",
"getCurrentRow",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"rows",
"[",
"(",
"$",
"this",
"->",
"int_ptr",
"-",
"1",
")",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"rows",
"[",
"(",
"$",
"this",
"->... | Returns the current row
@return Row | [
"Returns",
"the",
"current",
"row"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Resultset.php#L94-L100 | train |
thebuggenie/b2db | src/Resultset.php | Resultset.getNextRow | public function getNextRow()
{
if ($this->_next()) {
$row = $this->getCurrentRow();
if ($row instanceof Row) {
return $row;
}
throw new \Exception('This should never happen. Please file a bug report');
} else {
return false;
}
} | php | public function getNextRow()
{
if ($this->_next()) {
$row = $this->getCurrentRow();
if ($row instanceof Row) {
return $row;
}
throw new \Exception('This should never happen. Please file a bug report');
} else {
return false;
}
} | [
"public",
"function",
"getNextRow",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_next",
"(",
")",
")",
"{",
"$",
"row",
"=",
"$",
"this",
"->",
"getCurrentRow",
"(",
")",
";",
"if",
"(",
"$",
"row",
"instanceof",
"Row",
")",
"{",
"return",
"$",... | Advances through the resultset and returns the current row
Returns false when there are no more rows
@return Row|false | [
"Advances",
"through",
"the",
"resultset",
"and",
"returns",
"the",
"current",
"row",
"Returns",
"false",
"when",
"there",
"are",
"no",
"more",
"rows"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Resultset.php#L108-L119 | train |
thebuggenie/b2db | src/SqlGenerator.php | SqlGenerator.addValue | protected function addValue($value, $force_null = false)
{
if (is_array($value)) {
foreach ($value as $single_value) {
$this->addValue($single_value);
}
} else {
if ($value !== null || $force_null) {
$this->values[] = $this->query->getDatabaseValue($value);
}
}
} | php | protected function addValue($value, $force_null = false)
{
if (is_array($value)) {
foreach ($value as $single_value) {
$this->addValue($single_value);
}
} else {
if ($value !== null || $force_null) {
$this->values[] = $this->query->getDatabaseValue($value);
}
}
} | [
"protected",
"function",
"addValue",
"(",
"$",
"value",
",",
"$",
"force_null",
"=",
"false",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"$",
"single_value",
")",
"{",
"$",
"this",
"->",
"... | Add a specified value
@param mixed $value
@param bool $force_null | [
"Add",
"a",
"specified",
"value"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/SqlGenerator.php#L48-L59 | train |
thebuggenie/b2db | src/SqlGenerator.php | SqlGenerator.generateWhereSQL | protected function generateWhereSQL($strip = false)
{
$sql = $this->generateWherePartSql($strip);
$sql .= $this->generateGroupPartSql();
$sql .= $this->generateOrderByPartSql();
if ($this->query->isSelect()) {
if ($this->query->hasLimit()) {
$sql .= ' LIMIT ' . $this->query->getLimit();
}
if ($this->query->hasOffset()) {
$sql .= ' OFFSET ' . $this->query->getOffset();
}
}
return $sql;
} | php | protected function generateWhereSQL($strip = false)
{
$sql = $this->generateWherePartSql($strip);
$sql .= $this->generateGroupPartSql();
$sql .= $this->generateOrderByPartSql();
if ($this->query->isSelect()) {
if ($this->query->hasLimit()) {
$sql .= ' LIMIT ' . $this->query->getLimit();
}
if ($this->query->hasOffset()) {
$sql .= ' OFFSET ' . $this->query->getOffset();
}
}
return $sql;
} | [
"protected",
"function",
"generateWhereSQL",
"(",
"$",
"strip",
"=",
"false",
")",
"{",
"$",
"sql",
"=",
"$",
"this",
"->",
"generateWherePartSql",
"(",
"$",
"strip",
")",
";",
"$",
"sql",
".=",
"$",
"this",
"->",
"generateGroupPartSql",
"(",
")",
";",
... | Generate the "where" part of the query
@param bool $strip
@return string | [
"Generate",
"the",
"where",
"part",
"of",
"the",
"query"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/SqlGenerator.php#L159-L174 | train |
thebuggenie/b2db | src/SqlGenerator.php | SqlGenerator.generateJoinSQL | protected function generateJoinSQL()
{
$sql = ' FROM ' . $this->getTable()->getSelectFromSql();
foreach ($this->query->getJoins() as $join) {
$sql .= ' ' . $join->getJoinType() . ' ' . $join->getTable()->getSelectFromSql();
$sql .= ' ON (' . Query::quoteIdentifier($join->getLeftColumn()) . Criterion::EQUALS . Query::quoteIdentifier($join->getRightColumn());
if ($join->hasAdditionalCriteria()) {
$sql_parts = [];
foreach ($join->getAdditionalCriteria() as $criteria) {
$criteria->setQuery($this->query);
$sql_parts[] = $criteria->getSql();
foreach ($criteria->getValues() as $value) {
$this->query->addValue($value);
}
}
$sql .= ' AND ' . join(' AND ', $sql_parts);
}
$sql .= ')';
}
return $sql;
} | php | protected function generateJoinSQL()
{
$sql = ' FROM ' . $this->getTable()->getSelectFromSql();
foreach ($this->query->getJoins() as $join) {
$sql .= ' ' . $join->getJoinType() . ' ' . $join->getTable()->getSelectFromSql();
$sql .= ' ON (' . Query::quoteIdentifier($join->getLeftColumn()) . Criterion::EQUALS . Query::quoteIdentifier($join->getRightColumn());
if ($join->hasAdditionalCriteria()) {
$sql_parts = [];
foreach ($join->getAdditionalCriteria() as $criteria) {
$criteria->setQuery($this->query);
$sql_parts[] = $criteria->getSql();
foreach ($criteria->getValues() as $value) {
$this->query->addValue($value);
}
}
$sql .= ' AND ' . join(' AND ', $sql_parts);
}
$sql .= ')';
}
return $sql;
} | [
"protected",
"function",
"generateJoinSQL",
"(",
")",
"{",
"$",
"sql",
"=",
"' FROM '",
".",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"getSelectFromSql",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"query",
"->",
"getJoins",
"(",
")",
"as",... | Generate the "join" part of the sql
@return string | [
"Generate",
"the",
"join",
"part",
"of",
"the",
"sql"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/SqlGenerator.php#L181-L206 | train |
thebuggenie/b2db | src/SqlGenerator.php | SqlGenerator.addAllSelectColumns | protected function addAllSelectColumns()
{
foreach ($this->getTable()->getAliasColumns() as $column) {
$this->query->addSelectionColumnRaw($column);
}
foreach ($this->query->getJoins() as $join) {
foreach ($join->getTable()->getAliasColumns() as $column) {
$this->query->addSelectionColumnRaw($column);
}
}
} | php | protected function addAllSelectColumns()
{
foreach ($this->getTable()->getAliasColumns() as $column) {
$this->query->addSelectionColumnRaw($column);
}
foreach ($this->query->getJoins() as $join) {
foreach ($join->getTable()->getAliasColumns() as $column) {
$this->query->addSelectionColumnRaw($column);
}
}
} | [
"protected",
"function",
"addAllSelectColumns",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"getAliasColumns",
"(",
")",
"as",
"$",
"column",
")",
"{",
"$",
"this",
"->",
"query",
"->",
"addSelectionColumnRaw",
"(",
"$",
... | Adds all select columns from all available tables in the query | [
"Adds",
"all",
"select",
"columns",
"from",
"all",
"available",
"tables",
"in",
"the",
"query"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/SqlGenerator.php#L211-L222 | train |
thebuggenie/b2db | src/SqlGenerator.php | SqlGenerator.generateSelectAllSQL | protected function generateSelectAllSQL()
{
$sql_parts = [];
foreach ($this->query->getSelectionColumns() as $selection) {
$sql_parts[] = $selection->getSql();
}
return implode(', ', $sql_parts);
} | php | protected function generateSelectAllSQL()
{
$sql_parts = [];
foreach ($this->query->getSelectionColumns() as $selection) {
$sql_parts[] = $selection->getSql();
}
return implode(', ', $sql_parts);
} | [
"protected",
"function",
"generateSelectAllSQL",
"(",
")",
"{",
"$",
"sql_parts",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"query",
"->",
"getSelectionColumns",
"(",
")",
"as",
"$",
"selection",
")",
"{",
"$",
"sql_parts",
"[",
"]",
"=",
... | Generates "select all" SQL
@return string | [
"Generates",
"select",
"all",
"SQL"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/SqlGenerator.php#L229-L236 | train |
thebuggenie/b2db | src/SqlGenerator.php | SqlGenerator.generateSelectSQL | protected function generateSelectSQL()
{
$sql = ($this->query->isDistinct()) ? 'SELECT DISTINCT ' : 'SELECT ';
if ($this->query->isCustomSelection()) {
if ($this->query->isDistinct() && Core::getDriver() == Core::DRIVER_POSTGRES) {
foreach ($this->query->getSortOrders() as $sort_order) {
$this->query->addSelectionColumn($sort_order->getColumn());
}
}
$sql_parts = [];
foreach ($this->query->getSelectionColumns() as $column => $selection) {
$alias = ($selection->getAlias()) ?? $this->query->getSelectionAlias($column);
$sub_sql = $selection->getVariableString();
if ($selection->isSpecial()) {
$sub_sql .= mb_strtoupper($selection->getSpecial()) . '(' . Query::quoteIdentifier($selection->getColumn()) . ')';
if ($selection->hasAdditional())
$sub_sql .= ' ' . $selection->getAdditional() . ' ';
if (mb_strpos($selection->getSpecial(), '(') !== false)
$sub_sql .= ')';
} else {
$sub_sql .= Query::quoteIdentifier($selection->getColumn());
}
$sub_sql .= ' AS ' . Query::quoteIdentifier($alias);
$sql_parts[] = $sub_sql;
}
$sql .= implode(', ', $sql_parts);
} else {
$this->addAllSelectColumns();
$sql .= $this->generateSelectAllSQL();
}
return $sql;
} | php | protected function generateSelectSQL()
{
$sql = ($this->query->isDistinct()) ? 'SELECT DISTINCT ' : 'SELECT ';
if ($this->query->isCustomSelection()) {
if ($this->query->isDistinct() && Core::getDriver() == Core::DRIVER_POSTGRES) {
foreach ($this->query->getSortOrders() as $sort_order) {
$this->query->addSelectionColumn($sort_order->getColumn());
}
}
$sql_parts = [];
foreach ($this->query->getSelectionColumns() as $column => $selection) {
$alias = ($selection->getAlias()) ?? $this->query->getSelectionAlias($column);
$sub_sql = $selection->getVariableString();
if ($selection->isSpecial()) {
$sub_sql .= mb_strtoupper($selection->getSpecial()) . '(' . Query::quoteIdentifier($selection->getColumn()) . ')';
if ($selection->hasAdditional())
$sub_sql .= ' ' . $selection->getAdditional() . ' ';
if (mb_strpos($selection->getSpecial(), '(') !== false)
$sub_sql .= ')';
} else {
$sub_sql .= Query::quoteIdentifier($selection->getColumn());
}
$sub_sql .= ' AS ' . Query::quoteIdentifier($alias);
$sql_parts[] = $sub_sql;
}
$sql .= implode(', ', $sql_parts);
} else {
$this->addAllSelectColumns();
$sql .= $this->generateSelectAllSQL();
}
return $sql;
} | [
"protected",
"function",
"generateSelectSQL",
"(",
")",
"{",
"$",
"sql",
"=",
"(",
"$",
"this",
"->",
"query",
"->",
"isDistinct",
"(",
")",
")",
"?",
"'SELECT DISTINCT '",
":",
"'SELECT '",
";",
"if",
"(",
"$",
"this",
"->",
"query",
"->",
"isCustomSele... | Generate the "select" part of the query
@return string | [
"Generate",
"the",
"select",
"part",
"of",
"the",
"query"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/SqlGenerator.php#L243-L277 | train |
thebuggenie/b2db | src/SqlGenerator.php | SqlGenerator.getSelectSQL | public function getSelectSQL($all = false)
{
if (!$this->query->getTable() instanceof Table) {
throw new Exception('Trying to generate sql when no table is being used.');
}
$sql = $this->generateSelectSQL();
$sql .= $this->generateJoinSQL();
if (!$all) {
$sql .= $this->generateWhereSQL();
}
return $sql;
} | php | public function getSelectSQL($all = false)
{
if (!$this->query->getTable() instanceof Table) {
throw new Exception('Trying to generate sql when no table is being used.');
}
$sql = $this->generateSelectSQL();
$sql .= $this->generateJoinSQL();
if (!$all) {
$sql .= $this->generateWhereSQL();
}
return $sql;
} | [
"public",
"function",
"getSelectSQL",
"(",
"$",
"all",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"query",
"->",
"getTable",
"(",
")",
"instanceof",
"Table",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Trying to generate sql when no table i... | Generate a "select" query
@param boolean $all [optional]
@return string | [
"Generate",
"a",
"select",
"query"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/SqlGenerator.php#L285-L297 | train |
thebuggenie/b2db | src/SqlGenerator.php | SqlGenerator.generateCountSQL | protected function generateCountSQL()
{
$sql = ($this->query->isDistinct()) ? 'SELECT COUNT(DISTINCT ' : 'SELECT COUNT(';
$sql .= Query::quoteIdentifier($this->query->getSelectionColumn($this->getTable()->getIdColumn()));
$sql .= ') as num_col';
return $sql;
} | php | protected function generateCountSQL()
{
$sql = ($this->query->isDistinct()) ? 'SELECT COUNT(DISTINCT ' : 'SELECT COUNT(';
$sql .= Query::quoteIdentifier($this->query->getSelectionColumn($this->getTable()->getIdColumn()));
$sql .= ') as num_col';
return $sql;
} | [
"protected",
"function",
"generateCountSQL",
"(",
")",
"{",
"$",
"sql",
"=",
"(",
"$",
"this",
"->",
"query",
"->",
"isDistinct",
"(",
")",
")",
"?",
"'SELECT COUNT(DISTINCT '",
":",
"'SELECT COUNT('",
";",
"$",
"sql",
".=",
"Query",
"::",
"quoteIdentifier",... | Generate the "count" part of the query
@return string | [
"Generate",
"the",
"count",
"part",
"of",
"the",
"query"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/SqlGenerator.php#L304-L311 | train |
thebuggenie/b2db | src/SqlGenerator.php | SqlGenerator.getCountSQL | public function getCountSQL()
{
if (!$this->query->getTable() instanceof Table) {
throw new Exception('Trying to generate sql when no table is being used.');
}
$sql = $this->generateCountSQL();
$sql .= $this->generateJoinSQL();
$sql .= $this->generateWhereSQL();
return $sql;
} | php | public function getCountSQL()
{
if (!$this->query->getTable() instanceof Table) {
throw new Exception('Trying to generate sql when no table is being used.');
}
$sql = $this->generateCountSQL();
$sql .= $this->generateJoinSQL();
$sql .= $this->generateWhereSQL();
return $sql;
} | [
"public",
"function",
"getCountSQL",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"query",
"->",
"getTable",
"(",
")",
"instanceof",
"Table",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Trying to generate sql when no table is being used.'",
")",
";",
"}... | Generate a "count" query
@return string | [
"Generate",
"a",
"count",
"query"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/SqlGenerator.php#L318-L328 | train |
thebuggenie/b2db | src/SqlGenerator.php | SqlGenerator.generateUpdateSQL | protected function generateUpdateSQL(Update $update)
{
$updates = [];
foreach ($update->getValues() as $column => $value) {
$column = mb_substr($column, mb_strpos($column, '.') + 1);
$prefix = Query::quoteIdentifier($column);
$updates[] = $prefix . Criterion::EQUALS . '?';
$this->addValue($value, true);
}
$sql = 'UPDATE ' . $this->getTable()->getSqlTableName() . ' SET ' . implode(', ', $updates);
return $sql;
} | php | protected function generateUpdateSQL(Update $update)
{
$updates = [];
foreach ($update->getValues() as $column => $value) {
$column = mb_substr($column, mb_strpos($column, '.') + 1);
$prefix = Query::quoteIdentifier($column);
$updates[] = $prefix . Criterion::EQUALS . '?';
$this->addValue($value, true);
}
$sql = 'UPDATE ' . $this->getTable()->getSqlTableName() . ' SET ' . implode(', ', $updates);
return $sql;
} | [
"protected",
"function",
"generateUpdateSQL",
"(",
"Update",
"$",
"update",
")",
"{",
"$",
"updates",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"update",
"->",
"getValues",
"(",
")",
"as",
"$",
"column",
"=>",
"$",
"value",
")",
"{",
"$",
"column",
"=... | Generate the "update" part of the query
@param Update $update
@return string | [
"Generate",
"the",
"update",
"part",
"of",
"the",
"query"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/SqlGenerator.php#L336-L348 | train |
thebuggenie/b2db | src/SqlGenerator.php | SqlGenerator.getUpdateSQL | public function getUpdateSQL(Update $update)
{
if (!$this->query->getTable() instanceof Table) {
throw new Exception('Trying to generate sql when no table is being used.');
}
$sql = $this->generateUpdateSQL($update);
$sql .= $this->generateWhereSQL(true);
return $sql;
} | php | public function getUpdateSQL(Update $update)
{
if (!$this->query->getTable() instanceof Table) {
throw new Exception('Trying to generate sql when no table is being used.');
}
$sql = $this->generateUpdateSQL($update);
$sql .= $this->generateWhereSQL(true);
return $sql;
} | [
"public",
"function",
"getUpdateSQL",
"(",
"Update",
"$",
"update",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"query",
"->",
"getTable",
"(",
")",
"instanceof",
"Table",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Trying to generate sql when no table is b... | Generate an "update" query
@param Update $update
@return string
@throws Exception | [
"Generate",
"an",
"update",
"query"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/SqlGenerator.php#L357-L366 | train |
thebuggenie/b2db | src/SqlGenerator.php | SqlGenerator.getDeleteSQL | public function getDeleteSQL()
{
if (!$this->query->getTable() instanceof Table) {
throw new Exception('Trying to generate sql when no table is being used.');
}
$sql = 'DELETE FROM ' . $this->getTable()->getSqlTableName();
$sql .= $this->generateWhereSQL(true);
return $sql;
} | php | public function getDeleteSQL()
{
if (!$this->query->getTable() instanceof Table) {
throw new Exception('Trying to generate sql when no table is being used.');
}
$sql = 'DELETE FROM ' . $this->getTable()->getSqlTableName();
$sql .= $this->generateWhereSQL(true);
return $sql;
} | [
"public",
"function",
"getDeleteSQL",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"query",
"->",
"getTable",
"(",
")",
"instanceof",
"Table",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Trying to generate sql when no table is being used.'",
")",
";",
"... | Generate a "delete" query
@return string | [
"Generate",
"a",
"delete",
"query"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/SqlGenerator.php#L410-L419 | train |
thebuggenie/b2db | src/Query.php | Query.setTable | public function setTable(Table $table, $setup_join_tables = false): self
{
$this->table = $table;
if ($setup_join_tables) {
$this->setupJoinTables();
}
return $this;
} | php | public function setTable(Table $table, $setup_join_tables = false): self
{
$this->table = $table;
if ($setup_join_tables) {
$this->setupJoinTables();
}
return $this;
} | [
"public",
"function",
"setTable",
"(",
"Table",
"$",
"table",
",",
"$",
"setup_join_tables",
"=",
"false",
")",
":",
"self",
"{",
"$",
"this",
"->",
"table",
"=",
"$",
"table",
";",
"if",
"(",
"$",
"setup_join_tables",
")",
"{",
"$",
"this",
"->",
"s... | Set the "from" table
@param Table $table The table
@param bool $setup_join_tables [optional] Whether to automatically join other tables
@return Query | [
"Set",
"the",
"from",
"table"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Query.php#L116-L125 | train |
thebuggenie/b2db | src/Query.php | Query.addValue | public function addValue($value)
{
if (is_array($value)) {
foreach ($value as $single_value) {
$this->addValue($single_value);
}
} else {
if ($value !== null) {
$this->values[] = $this->getDatabaseValue($value);
}
}
} | php | public function addValue($value)
{
if (is_array($value)) {
foreach ($value as $single_value) {
$this->addValue($single_value);
}
} else {
if ($value !== null) {
$this->values[] = $this->getDatabaseValue($value);
}
}
} | [
"public",
"function",
"addValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"$",
"single_value",
")",
"{",
"$",
"this",
"->",
"addValue",
"(",
"$",
"single_value",
")",
... | Add a value to the value container
@param mixed $value | [
"Add",
"a",
"value",
"to",
"the",
"value",
"container"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Query.php#L204-L215 | train |
thebuggenie/b2db | src/Query.php | Query.addSelectionColumn | public function addSelectionColumn($column, $alias = '', $special = '', $variable = '', $additional = ''): self
{
if (!$this->table instanceof Table) {
throw new \Exception('You must set the from-table before adding selection columns');
}
$column = $this->getSelectionColumn($column);
$alias = ($alias === '') ? str_replace('.', '_', $column) : $alias;
$this->is_custom_selection = true;
$this->addSelectionColumnRaw($column, $alias, $special, $variable, $additional);
return $this;
} | php | public function addSelectionColumn($column, $alias = '', $special = '', $variable = '', $additional = ''): self
{
if (!$this->table instanceof Table) {
throw new \Exception('You must set the from-table before adding selection columns');
}
$column = $this->getSelectionColumn($column);
$alias = ($alias === '') ? str_replace('.', '_', $column) : $alias;
$this->is_custom_selection = true;
$this->addSelectionColumnRaw($column, $alias, $special, $variable, $additional);
return $this;
} | [
"public",
"function",
"addSelectionColumn",
"(",
"$",
"column",
",",
"$",
"alias",
"=",
"''",
",",
"$",
"special",
"=",
"''",
",",
"$",
"variable",
"=",
"''",
",",
"$",
"additional",
"=",
"''",
")",
":",
"self",
"{",
"if",
"(",
"!",
"$",
"this",
... | Add a column to select
@param string $column The column
@param string $alias [optional] An alias for the column
@param string $special [optional] Whether to use a special method on the column
@param string $variable [optional] An optional variable to assign it to
@param string $additional [optional] Additional parameter
@return Query | [
"Add",
"a",
"column",
"to",
"select"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Query.php#L228-L241 | train |
thebuggenie/b2db | src/Query.php | Query.update | public function update($column, $value): self
{
if (is_object($value)) {
throw new Exception("Invalid value, can't be an object.");
}
$this->updates[] = compact('column', 'value');
return $this;
} | php | public function update($column, $value): self
{
if (is_object($value)) {
throw new Exception("Invalid value, can't be an object.");
}
$this->updates[] = compact('column', 'value');
return $this;
} | [
"public",
"function",
"update",
"(",
"$",
"column",
",",
"$",
"value",
")",
":",
"self",
"{",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Invalid value, can't be an object.\"",
")",
";",
"}",
"$",
"this"... | Add a field to update
@param string $column The column name
@param mixed $value The value to update
@return Query | [
"Add",
"a",
"field",
"to",
"update"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Query.php#L261-L269 | train |
thebuggenie/b2db | src/Query.php | Query.join | public function join(Table $table, $joined_table_column, $column, $criteria = [], $join_type = Join::LEFT, $on_table = null)
{
if (!$this->table instanceof Table) {
throw new Exception('Cannot use ' . $this->table . ' as a table. You need to call setTable() before trying to join a new table');
}
if (!$table instanceof Table) {
throw new Exception('Cannot join table ' . $table . ' since it is not a table');
}
foreach ($this->joins as $join) {
if ($join->getTable()->getB2DBAlias() === $table->getB2DBAlias()) {
$table = clone $table;
break;
}
}
$left_column = $table->getB2DBAlias() . '.' . Table::getColumnName($joined_table_column);
$join_on_table = $on_table ?? $this->table;
$right_column = $join_on_table->getB2DBAlias() . '.' . Table::getColumnName($column);
$this->joins[$table->getB2DBAlias()] = new Join($table, $left_column, $right_column, $this->getRealColumnName($column), $criteria, $join_type);
return $table;
} | php | public function join(Table $table, $joined_table_column, $column, $criteria = [], $join_type = Join::LEFT, $on_table = null)
{
if (!$this->table instanceof Table) {
throw new Exception('Cannot use ' . $this->table . ' as a table. You need to call setTable() before trying to join a new table');
}
if (!$table instanceof Table) {
throw new Exception('Cannot join table ' . $table . ' since it is not a table');
}
foreach ($this->joins as $join) {
if ($join->getTable()->getB2DBAlias() === $table->getB2DBAlias()) {
$table = clone $table;
break;
}
}
$left_column = $table->getB2DBAlias() . '.' . Table::getColumnName($joined_table_column);
$join_on_table = $on_table ?? $this->table;
$right_column = $join_on_table->getB2DBAlias() . '.' . Table::getColumnName($column);
$this->joins[$table->getB2DBAlias()] = new Join($table, $left_column, $right_column, $this->getRealColumnName($column), $criteria, $join_type);
return $table;
} | [
"public",
"function",
"join",
"(",
"Table",
"$",
"table",
",",
"$",
"joined_table_column",
",",
"$",
"column",
",",
"$",
"criteria",
"=",
"[",
"]",
",",
"$",
"join_type",
"=",
"Join",
"::",
"LEFT",
",",
"$",
"on_table",
"=",
"null",
")",
"{",
"if",
... | Join one table on another
@param Table $table The table to join
@param string $joined_table_column The left matching column
@param string $column The right matching column
@param Criteria[] $criteria An array of criteria (ex: array(array(DB_FLD_ISSUE_ID, 1), array(DB_FLD_ISSUE_STATE, 1));
@param string $join_type Type of join
@param Table $on_table If different than the main table, specify the left side of the join here
@return Table | [
"Join",
"one",
"table",
"on",
"another"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Query.php#L359-L383 | train |
thebuggenie/b2db | src/Query.php | Query.getSelectionColumn | public function getSelectionColumn($column)
{
if (isset($this->selections[$column])) {
return $this->selections[$column]->getColumn();
}
foreach ($this->selections as $selection) {
if ($selection->getAlias() == $column) {
return $column;
}
}
list($table_name, $column_name) = (strpos($column, '.') !== false) ? explode('.', $column) : [$this->table->getB2DBName(), $column];
if ($this->table->getB2DBAlias() == $table_name || $this->table->getB2DBName() == $table_name) {
return $this->table->getB2DBAlias() . '.' . $column_name;
} elseif (isset($this->joins[$table_name])) {
return $this->joins[$table_name]->getTable()->getB2DBAlias() . '.' . $column_name;
}
foreach ($this->joins as $join) {
if ($join->getTable()->getB2DBName() == $table_name) {
return $join->getTable()->getB2DBAlias() . '.' . $column_name;
}
}
throw new Exception("Couldn't find table name '{$table_name}' for column '{$column_name}', column was '{$column}'. If this is a column from a foreign table, make sure the foreign table is joined.");
} | php | public function getSelectionColumn($column)
{
if (isset($this->selections[$column])) {
return $this->selections[$column]->getColumn();
}
foreach ($this->selections as $selection) {
if ($selection->getAlias() == $column) {
return $column;
}
}
list($table_name, $column_name) = (strpos($column, '.') !== false) ? explode('.', $column) : [$this->table->getB2DBName(), $column];
if ($this->table->getB2DBAlias() == $table_name || $this->table->getB2DBName() == $table_name) {
return $this->table->getB2DBAlias() . '.' . $column_name;
} elseif (isset($this->joins[$table_name])) {
return $this->joins[$table_name]->getTable()->getB2DBAlias() . '.' . $column_name;
}
foreach ($this->joins as $join) {
if ($join->getTable()->getB2DBName() == $table_name) {
return $join->getTable()->getB2DBAlias() . '.' . $column_name;
}
}
throw new Exception("Couldn't find table name '{$table_name}' for column '{$column_name}', column was '{$column}'. If this is a column from a foreign table, make sure the foreign table is joined.");
} | [
"public",
"function",
"getSelectionColumn",
"(",
"$",
"column",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"selections",
"[",
"$",
"column",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"selections",
"[",
"$",
"column",
"]",
"->",
"get... | Return a select column
@param string $column
@return string | [
"Return",
"a",
"select",
"column"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Query.php#L470-L497 | train |
thebuggenie/b2db | src/Query.php | Query.getSelectionAlias | public function getSelectionAlias($column)
{
if (!is_numeric($column) && !is_string($column)) {
if (is_array($column) && array_key_exists('column', $column)) {
$column = $column['column'];
} else {
throw new Exception('Invalid column!');
}
}
if (!isset($this->aliases[$column])) {
$this->aliases[$column] = str_replace('.', '_', $column);
}
return $this->aliases[$column];
} | php | public function getSelectionAlias($column)
{
if (!is_numeric($column) && !is_string($column)) {
if (is_array($column) && array_key_exists('column', $column)) {
$column = $column['column'];
} else {
throw new Exception('Invalid column!');
}
}
if (!isset($this->aliases[$column])) {
$this->aliases[$column] = str_replace('.', '_', $column);
}
return $this->aliases[$column];
} | [
"public",
"function",
"getSelectionAlias",
"(",
"$",
"column",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"column",
")",
"&&",
"!",
"is_string",
"(",
"$",
"column",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"column",
")",
"&&",
"array_ke... | Get the selection alias for a specified column
@param string $column
@return string | [
"Get",
"the",
"selection",
"alias",
"for",
"a",
"specified",
"column"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Query.php#L506-L520 | train |
thebuggenie/b2db | src/Query.php | Query.addOrderBy | public function addOrderBy($column, $sort = null)
{
if (is_array($column)) {
foreach ($column as $single_column) {
$this->addOrderBy($single_column[0], $single_column[1]);
}
} else {
$this->sort_orders[] = new QueryColumnSort($column, $sort);
}
return $this;
} | php | public function addOrderBy($column, $sort = null)
{
if (is_array($column)) {
foreach ($column as $single_column) {
$this->addOrderBy($single_column[0], $single_column[1]);
}
} else {
$this->sort_orders[] = new QueryColumnSort($column, $sort);
}
return $this;
} | [
"public",
"function",
"addOrderBy",
"(",
"$",
"column",
",",
"$",
"sort",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"column",
")",
")",
"{",
"foreach",
"(",
"$",
"column",
"as",
"$",
"single_column",
")",
"{",
"$",
"this",
"->",
"addO... | Add an order by clause
@param string|array $column The column to order by
@param string $sort [optional] The sort order
@return Query | [
"Add",
"an",
"order",
"by",
"clause"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Query.php#L530-L541 | train |
thebuggenie/b2db | src/Query.php | Query.addGroupBy | public function addGroupBy($column, $sort = null)
{
if (is_array($column)) {
foreach ($column as $single_column) {
$this->addGroupBy($single_column[0], $single_column[1]);
}
} else {
$this->sort_groups[] = new QueryColumnSort($column, $sort);
}
return $this;
} | php | public function addGroupBy($column, $sort = null)
{
if (is_array($column)) {
foreach ($column as $single_column) {
$this->addGroupBy($single_column[0], $single_column[1]);
}
} else {
$this->sort_groups[] = new QueryColumnSort($column, $sort);
}
return $this;
} | [
"public",
"function",
"addGroupBy",
"(",
"$",
"column",
",",
"$",
"sort",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"column",
")",
")",
"{",
"foreach",
"(",
"$",
"column",
"as",
"$",
"single_column",
")",
"{",
"$",
"this",
"->",
"addG... | Add a group by clause
@param string|array $column The column to group by
@param string $sort [optional] The sort order
@return Query | [
"Add",
"a",
"group",
"by",
"clause"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Query.php#L588-L599 | train |
thebuggenie/b2db | src/Query.php | Query.setupJoinTables | public function setupJoinTables($join = 'all')
{
if (is_array($join)) {
foreach ($join as $join_column) {
$foreign_table = $this->table->getForeignTableByLocalColumn($join_column);
$this->join($foreign_table->getTable(), $foreign_table->getKeyColumnName(), $this->table->getB2DBAlias() . '.' . $foreign_table->getColumnName());
}
} elseif (!is_array($join) && $join == 'all') {
foreach ($this->table->getForeignTables() as $foreign_table) {
$this->join($foreign_table->getTable(), $foreign_table->getKeyColumnName(), $this->table->getB2DBAlias() . '.' . $foreign_table->getColumnName());
}
}
} | php | public function setupJoinTables($join = 'all')
{
if (is_array($join)) {
foreach ($join as $join_column) {
$foreign_table = $this->table->getForeignTableByLocalColumn($join_column);
$this->join($foreign_table->getTable(), $foreign_table->getKeyColumnName(), $this->table->getB2DBAlias() . '.' . $foreign_table->getColumnName());
}
} elseif (!is_array($join) && $join == 'all') {
foreach ($this->table->getForeignTables() as $foreign_table) {
$this->join($foreign_table->getTable(), $foreign_table->getKeyColumnName(), $this->table->getB2DBAlias() . '.' . $foreign_table->getColumnName());
}
}
} | [
"public",
"function",
"setupJoinTables",
"(",
"$",
"join",
"=",
"'all'",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"join",
")",
")",
"{",
"foreach",
"(",
"$",
"join",
"as",
"$",
"join_column",
")",
"{",
"$",
"foreign_table",
"=",
"$",
"this",
"->",
... | Add all available foreign tables
@param array|string|bool $join [optional] | [
"Add",
"all",
"available",
"foreign",
"tables"
] | 8501d737cd824ff961659e059cd920dc0ebd17cf | https://github.com/thebuggenie/b2db/blob/8501d737cd824ff961659e059cd920dc0ebd17cf/src/Query.php#L742-L754 | train |
contributte/utils | src/FileSystem.php | FileSystem.copy | public static function copy(string $source, string $dest, bool $overwrite = true): void
{
NetteFileSystem::copy($source, $dest, $overwrite);
} | php | public static function copy(string $source, string $dest, bool $overwrite = true): void
{
NetteFileSystem::copy($source, $dest, $overwrite);
} | [
"public",
"static",
"function",
"copy",
"(",
"string",
"$",
"source",
",",
"string",
"$",
"dest",
",",
"bool",
"$",
"overwrite",
"=",
"true",
")",
":",
"void",
"{",
"NetteFileSystem",
"::",
"copy",
"(",
"$",
"source",
",",
"$",
"dest",
",",
"$",
"ove... | Copies a file or directory.
@throws IOException | [
"Copies",
"a",
"file",
"or",
"directory",
"."
] | 3afb4010ee60fd01307850c13000b1918dc90859 | https://github.com/contributte/utils/blob/3afb4010ee60fd01307850c13000b1918dc90859/src/FileSystem.php#L74-L77 | train |
contributte/utils | src/Http.php | Http.metadata | public static function metadata(string $content): array
{
if (preg_match_all(self::$metadataPattern, $content, $matches) !== false) {
$combine = array_combine($matches[1], $matches[2]);
if ($combine === false) {
throw new LogicException('Matches count is not equal.');
}
return $combine;
}
return [];
} | php | public static function metadata(string $content): array
{
if (preg_match_all(self::$metadataPattern, $content, $matches) !== false) {
$combine = array_combine($matches[1], $matches[2]);
if ($combine === false) {
throw new LogicException('Matches count is not equal.');
}
return $combine;
}
return [];
} | [
"public",
"static",
"function",
"metadata",
"(",
"string",
"$",
"content",
")",
":",
"array",
"{",
"if",
"(",
"preg_match_all",
"(",
"self",
"::",
"$",
"metadataPattern",
",",
"$",
"content",
",",
"$",
"matches",
")",
"!==",
"false",
")",
"{",
"$",
"co... | Gets http metadata from string
@return string[] [name => content] | [
"Gets",
"http",
"metadata",
"from",
"string"
] | 3afb4010ee60fd01307850c13000b1918dc90859 | https://github.com/contributte/utils/blob/3afb4010ee60fd01307850c13000b1918dc90859/src/Http.php#L37-L50 | train |
GiacoCorsiglia/php-stubs-generator | src/NodeVisitor.php | NodeVisitor.getStubStmts | public function getStubStmts(): array
{
foreach ($this->classLikes as $classLike) {
$this->resolveClassLike($classLike);
}
if ($this->allAreGlobal($this->namespaces) && $this->allAreGlobal($this->classLikeNamespaces)) {
return array_merge(
$this->reduceStmts($this->classLikeNamespaces),
$this->reduceStmts($this->namespaces),
$this->globalNamespace->stmts,
$this->globalExpressions
);
}
return array_merge(
$this->classLikeNamespaces,
$this->namespaces,
$this->globalNamespace->stmts ? [$this->globalNamespace] : [],
$this->globalExpressions ? [new Namespace_(null, $this->globalExpressions)] : []
);
} | php | public function getStubStmts(): array
{
foreach ($this->classLikes as $classLike) {
$this->resolveClassLike($classLike);
}
if ($this->allAreGlobal($this->namespaces) && $this->allAreGlobal($this->classLikeNamespaces)) {
return array_merge(
$this->reduceStmts($this->classLikeNamespaces),
$this->reduceStmts($this->namespaces),
$this->globalNamespace->stmts,
$this->globalExpressions
);
}
return array_merge(
$this->classLikeNamespaces,
$this->namespaces,
$this->globalNamespace->stmts ? [$this->globalNamespace] : [],
$this->globalExpressions ? [new Namespace_(null, $this->globalExpressions)] : []
);
} | [
"public",
"function",
"getStubStmts",
"(",
")",
":",
"array",
"{",
"foreach",
"(",
"$",
"this",
"->",
"classLikes",
"as",
"$",
"classLike",
")",
"{",
"$",
"this",
"->",
"resolveClassLike",
"(",
"$",
"classLike",
")",
";",
"}",
"if",
"(",
"$",
"this",
... | Returns the stored set of stub nodes which are built up during traversal.
@return Node[] | [
"Returns",
"the",
"stored",
"set",
"of",
"stub",
"nodes",
"which",
"are",
"built",
"up",
"during",
"traversal",
"."
] | c5796427ebc8052c6c662e5101e8250ed5f295fe | https://github.com/GiacoCorsiglia/php-stubs-generator/blob/c5796427ebc8052c6c662e5101e8250ed5f295fe/src/NodeVisitor.php#L263-L284 | train |
GiacoCorsiglia/php-stubs-generator | src/NodeVisitor.php | NodeVisitor.count | private function count(string $type, string $name = null): bool
{
assert(isset($this->counts[$type]), 'Expected valid `$type`');
if (!$name) {
return false;
}
return ($this->counts[$type][$name] = ($this->counts[$type][$name] ?? 0) + 1) === 1;
} | php | private function count(string $type, string $name = null): bool
{
assert(isset($this->counts[$type]), 'Expected valid `$type`');
if (!$name) {
return false;
}
return ($this->counts[$type][$name] = ($this->counts[$type][$name] ?? 0) + 1) === 1;
} | [
"private",
"function",
"count",
"(",
"string",
"$",
"type",
",",
"string",
"$",
"name",
"=",
"null",
")",
":",
"bool",
"{",
"assert",
"(",
"isset",
"(",
"$",
"this",
"->",
"counts",
"[",
"$",
"type",
"]",
")",
",",
"'Expected valid `$type`'",
")",
";... | Keeps a count of declarations by type and name of node.
@param string $type One of `array_keys($this->counts)`.
@param string|null $name Name of the node. Theoretically could be null.
@return bool If true, this is the first declaration of this type with
this name, so it can be safely included. | [
"Keeps",
"a",
"count",
"of",
"declarations",
"by",
"type",
"and",
"name",
"of",
"node",
"."
] | c5796427ebc8052c6c662e5101e8250ed5f295fe | https://github.com/GiacoCorsiglia/php-stubs-generator/blob/c5796427ebc8052c6c662e5101e8250ed5f295fe/src/NodeVisitor.php#L364-L373 | train |
GiacoCorsiglia/php-stubs-generator | src/NodeVisitor.php | NodeVisitor.resolveClassLike | private function resolveClassLike(ClassLikeWithDependencies $clwd): void
{
if (isset($this->resolvedClassLikes[$clwd->fullyQualifiedName])) {
// Already resolved.
return;
}
$this->resolvedClassLikes[$clwd->fullyQualifiedName] = true;
foreach ($clwd->dependencies as $dependencyName) {
if (isset($this->classLikes[$dependencyName])) {
$this->resolveClassLike($this->classLikes[$dependencyName]);
}
}
if (!$this->currentClassLikeNamespace) {
$namespaceMatches = false;
} elseif ($this->currentClassLikeNamespace->name) {
$namespaceMatches = $this->currentClassLikeNamespace->name->toString() === $clwd->namespace;
} else {
$namespaceMatches = !$clwd->namespace;
}
// Reduntant check to make Psalm happy.
if ($this->currentClassLikeNamespace && $namespaceMatches) {
$this->currentClassLikeNamespace->stmts[] = $clwd->node;
} else {
$name = $clwd->namespace ? new Name($clwd->namespace) : null;
$this->currentClassLikeNamespace = new Namespace_($name, [$clwd->node]);
$this->classLikeNamespaces[] = $this->currentClassLikeNamespace;
}
} | php | private function resolveClassLike(ClassLikeWithDependencies $clwd): void
{
if (isset($this->resolvedClassLikes[$clwd->fullyQualifiedName])) {
// Already resolved.
return;
}
$this->resolvedClassLikes[$clwd->fullyQualifiedName] = true;
foreach ($clwd->dependencies as $dependencyName) {
if (isset($this->classLikes[$dependencyName])) {
$this->resolveClassLike($this->classLikes[$dependencyName]);
}
}
if (!$this->currentClassLikeNamespace) {
$namespaceMatches = false;
} elseif ($this->currentClassLikeNamespace->name) {
$namespaceMatches = $this->currentClassLikeNamespace->name->toString() === $clwd->namespace;
} else {
$namespaceMatches = !$clwd->namespace;
}
// Reduntant check to make Psalm happy.
if ($this->currentClassLikeNamespace && $namespaceMatches) {
$this->currentClassLikeNamespace->stmts[] = $clwd->node;
} else {
$name = $clwd->namespace ? new Name($clwd->namespace) : null;
$this->currentClassLikeNamespace = new Namespace_($name, [$clwd->node]);
$this->classLikeNamespaces[] = $this->currentClassLikeNamespace;
}
} | [
"private",
"function",
"resolveClassLike",
"(",
"ClassLikeWithDependencies",
"$",
"clwd",
")",
":",
"void",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"resolvedClassLikes",
"[",
"$",
"clwd",
"->",
"fullyQualifiedName",
"]",
")",
")",
"{",
"// Already res... | Populates the `classLikeNamespaces` property with namespaces with classes
declared in a valid order.
@param ClassLikeWithDependencies $clwd
@return void | [
"Populates",
"the",
"classLikeNamespaces",
"property",
"with",
"namespaces",
"with",
"classes",
"declared",
"in",
"a",
"valid",
"order",
"."
] | c5796427ebc8052c6c662e5101e8250ed5f295fe | https://github.com/GiacoCorsiglia/php-stubs-generator/blob/c5796427ebc8052c6c662e5101e8250ed5f295fe/src/NodeVisitor.php#L382-L412 | train |
GiacoCorsiglia/php-stubs-generator | src/NodeVisitor.php | NodeVisitor.allAreGlobal | private function allAreGlobal(array $namespaces): bool
{
foreach ($namespaces as $namespace) {
if ($namespace->name && $namespace->name->toString() !== '') {
return false;
}
}
return true;
} | php | private function allAreGlobal(array $namespaces): bool
{
foreach ($namespaces as $namespace) {
if ($namespace->name && $namespace->name->toString() !== '') {
return false;
}
}
return true;
} | [
"private",
"function",
"allAreGlobal",
"(",
"array",
"$",
"namespaces",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"namespaces",
"as",
"$",
"namespace",
")",
"{",
"if",
"(",
"$",
"namespace",
"->",
"name",
"&&",
"$",
"namespace",
"->",
"name",
"->",
"... | Determines if each namespace in the list is a global namespace.
@param Namespace_[] $namespaces
@return bool | [
"Determines",
"if",
"each",
"namespace",
"in",
"the",
"list",
"is",
"a",
"global",
"namespace",
"."
] | c5796427ebc8052c6c662e5101e8250ed5f295fe | https://github.com/GiacoCorsiglia/php-stubs-generator/blob/c5796427ebc8052c6c662e5101e8250ed5f295fe/src/NodeVisitor.php#L420-L428 | train |
GiacoCorsiglia/php-stubs-generator | src/NodeVisitor.php | NodeVisitor.reduceStmts | private function reduceStmts(array $namespaces): array
{
$stmts = [];
foreach ($namespaces as $namespace) {
foreach ($namespace->stmts as $stmt) {
$stmts[] = $stmt;
}
}
return $stmts;
} | php | private function reduceStmts(array $namespaces): array
{
$stmts = [];
foreach ($namespaces as $namespace) {
foreach ($namespace->stmts as $stmt) {
$stmts[] = $stmt;
}
}
return $stmts;
} | [
"private",
"function",
"reduceStmts",
"(",
"array",
"$",
"namespaces",
")",
":",
"array",
"{",
"$",
"stmts",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"namespaces",
"as",
"$",
"namespace",
")",
"{",
"foreach",
"(",
"$",
"namespace",
"->",
"stmts",
"as",... | Merges the statements of each namespace into one array.
@param Namespace_[] $namespaces
@return Stmt[] | [
"Merges",
"the",
"statements",
"of",
"each",
"namespace",
"into",
"one",
"array",
"."
] | c5796427ebc8052c6c662e5101e8250ed5f295fe | https://github.com/GiacoCorsiglia/php-stubs-generator/blob/c5796427ebc8052c6c662e5101e8250ed5f295fe/src/NodeVisitor.php#L436-L445 | train |
hiqdev/yii2-data-mapper | src/components/EntityManager.php | EntityManager.getRepository | public function getRepository($entityClass)
{
if (is_object($entityClass)) {
$entityClass = get_class($entityClass);
}
if (!isset($this->repositories[$entityClass])) {
throw new \Exception("no repository defined for: $entityClass");
}
if (!is_object($this->repositories[$entityClass])) {
$this->repositories[$entityClass] = $this->di->get($this->repositories[$entityClass]);
}
return $this->repositories[$entityClass];
} | php | public function getRepository($entityClass)
{
if (is_object($entityClass)) {
$entityClass = get_class($entityClass);
}
if (!isset($this->repositories[$entityClass])) {
throw new \Exception("no repository defined for: $entityClass");
}
if (!is_object($this->repositories[$entityClass])) {
$this->repositories[$entityClass] = $this->di->get($this->repositories[$entityClass]);
}
return $this->repositories[$entityClass];
} | [
"public",
"function",
"getRepository",
"(",
"$",
"entityClass",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"entityClass",
")",
")",
"{",
"$",
"entityClass",
"=",
"get_class",
"(",
"$",
"entityClass",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
... | Get entity repository by entity or class.
@param object|string $entityClass entity or class
@return BaseRepository | [
"Get",
"entity",
"repository",
"by",
"entity",
"or",
"class",
"."
] | 2e39de404b010b2beb527b913ddf3149422ed738 | https://github.com/hiqdev/yii2-data-mapper/blob/2e39de404b010b2beb527b913ddf3149422ed738/src/components/EntityManager.php#L75-L90 | train |
contributte/utils | src/DateTime.php | DateTime.setCurrentTime | public function setCurrentTime(): self
{
return $this->modifyClone()->setTime((int) date('H'), (int) date('i'), (int) date('s'));
} | php | public function setCurrentTime(): self
{
return $this->modifyClone()->setTime((int) date('H'), (int) date('i'), (int) date('s'));
} | [
"public",
"function",
"setCurrentTime",
"(",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"modifyClone",
"(",
")",
"->",
"setTime",
"(",
"(",
"int",
")",
"date",
"(",
"'H'",
")",
",",
"(",
"int",
")",
"date",
"(",
"'i'",
")",
",",
"(",
"in... | Set time to current time | [
"Set",
"time",
"to",
"current",
"time"
] | 3afb4010ee60fd01307850c13000b1918dc90859 | https://github.com/contributte/utils/blob/3afb4010ee60fd01307850c13000b1918dc90859/src/DateTime.php#L37-L40 | train |
contributte/utils | src/DateTime.php | DateTime.setToday | public function setToday(): self
{
return $this->modifyClone()->setDate((int) date('Y'), (int) date('m'), (int) date('d'));
} | php | public function setToday(): self
{
return $this->modifyClone()->setDate((int) date('Y'), (int) date('m'), (int) date('d'));
} | [
"public",
"function",
"setToday",
"(",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"modifyClone",
"(",
")",
"->",
"setDate",
"(",
"(",
"int",
")",
"date",
"(",
"'Y'",
")",
",",
"(",
"int",
")",
"date",
"(",
"'m'",
")",
",",
"(",
"int",
... | Set date to today | [
"Set",
"date",
"to",
"today"
] | 3afb4010ee60fd01307850c13000b1918dc90859 | https://github.com/contributte/utils/blob/3afb4010ee60fd01307850c13000b1918dc90859/src/DateTime.php#L69-L72 | train |
TargetLiu/PHPRedis | src/Database.php | Database.createClient | protected function createClient(array $servers)
{
$clients = [];
foreach ($servers as $key => $server) {
$clients[$key] = new \Redis();
$clients[$key]->pconnect($server['host'], $server['port'], 0, $key . $server['database']);
if (!empty($server['password'])) {
$clients[$key]->auth($server['password']);
}
if (!empty($server['database'])) {
$clients[$key]->select($server['database']);
}
}
return $clients;
} | php | protected function createClient(array $servers)
{
$clients = [];
foreach ($servers as $key => $server) {
$clients[$key] = new \Redis();
$clients[$key]->pconnect($server['host'], $server['port'], 0, $key . $server['database']);
if (!empty($server['password'])) {
$clients[$key]->auth($server['password']);
}
if (!empty($server['database'])) {
$clients[$key]->select($server['database']);
}
}
return $clients;
} | [
"protected",
"function",
"createClient",
"(",
"array",
"$",
"servers",
")",
"{",
"$",
"clients",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"servers",
"as",
"$",
"key",
"=>",
"$",
"server",
")",
"{",
"$",
"clients",
"[",
"$",
"key",
"]",
"=",
"new",
... | Create an array of connection clients.
@param array $servers
@param array $options
@return array | [
"Create",
"an",
"array",
"of",
"connection",
"clients",
"."
] | 5930a9233e603754ff284c35a96575ed1e384af1 | https://github.com/TargetLiu/PHPRedis/blob/5930a9233e603754ff284c35a96575ed1e384af1/src/Database.php#L62-L79 | train |
hiqdev/yii2-data-mapper | src/repositories/BaseRepository.php | BaseRepository.findByIds | public function findByIds(array $ids): array
{
$spec = $this->createSpecification()->where(['id' => $ids]);
return $this->findAll($spec);
} | php | public function findByIds(array $ids): array
{
$spec = $this->createSpecification()->where(['id' => $ids]);
return $this->findAll($spec);
} | [
"public",
"function",
"findByIds",
"(",
"array",
"$",
"ids",
")",
":",
"array",
"{",
"$",
"spec",
"=",
"$",
"this",
"->",
"createSpecification",
"(",
")",
"->",
"where",
"(",
"[",
"'id'",
"=>",
"$",
"ids",
"]",
")",
";",
"return",
"$",
"this",
"->"... | Selects entities from DB by given IDs.
@param string[] $ids
@return array | [
"Selects",
"entities",
"from",
"DB",
"by",
"given",
"IDs",
"."
] | 2e39de404b010b2beb527b913ddf3149422ed738 | https://github.com/hiqdev/yii2-data-mapper/blob/2e39de404b010b2beb527b913ddf3149422ed738/src/repositories/BaseRepository.php#L68-L73 | train |
TargetLiu/PHPRedis | src/Queue/PHPRedisQueue.php | PHPRedisQueue.migrateAllExpiredJobs | protected function migrateAllExpiredJobs($queue)
{
$this->migrateExpiredJobs($queue . ':delayed', $queue);
$this->migrateExpiredJobs($queue . ':reserved', $queue);
} | php | protected function migrateAllExpiredJobs($queue)
{
$this->migrateExpiredJobs($queue . ':delayed', $queue);
$this->migrateExpiredJobs($queue . ':reserved', $queue);
} | [
"protected",
"function",
"migrateAllExpiredJobs",
"(",
"$",
"queue",
")",
"{",
"$",
"this",
"->",
"migrateExpiredJobs",
"(",
"$",
"queue",
".",
"':delayed'",
",",
"$",
"queue",
")",
";",
"$",
"this",
"->",
"migrateExpiredJobs",
"(",
"$",
"queue",
".",
"':r... | Migrate all of the waiting jobs in the queue.
@param string $queue
@return void | [
"Migrate",
"all",
"of",
"the",
"waiting",
"jobs",
"in",
"the",
"queue",
"."
] | 5930a9233e603754ff284c35a96575ed1e384af1 | https://github.com/TargetLiu/PHPRedis/blob/5930a9233e603754ff284c35a96575ed1e384af1/src/Queue/PHPRedisQueue.php#L161-L166 | train |
contributte/utils | src/Strings.php | Strings.spaceless | public static function spaceless(string $s)
{
$s = trim($s);
$s = self::replace($s, '#\s#', '');
return $s;
} | php | public static function spaceless(string $s)
{
$s = trim($s);
$s = self::replace($s, '#\s#', '');
return $s;
} | [
"public",
"static",
"function",
"spaceless",
"(",
"string",
"$",
"s",
")",
"{",
"$",
"s",
"=",
"trim",
"(",
"$",
"s",
")",
";",
"$",
"s",
"=",
"self",
"::",
"replace",
"(",
"$",
"s",
",",
"'#\\s#'",
",",
"''",
")",
";",
"return",
"$",
"s",
";... | Remove spaces from the beginning and end of a string
and between chars
@return mixed | [
"Remove",
"spaces",
"from",
"the",
"beginning",
"and",
"end",
"of",
"a",
"string",
"and",
"between",
"chars"
] | 3afb4010ee60fd01307850c13000b1918dc90859 | https://github.com/contributte/utils/blob/3afb4010ee60fd01307850c13000b1918dc90859/src/Strings.php#L40-L46 | train |
contributte/utils | src/Strings.php | Strings.doublespaceless | public static function doublespaceless(string $s)
{
$s = trim($s);
$s = self::replace($s, '#\s{2,}#', ' ');
return $s;
} | php | public static function doublespaceless(string $s)
{
$s = trim($s);
$s = self::replace($s, '#\s{2,}#', ' ');
return $s;
} | [
"public",
"static",
"function",
"doublespaceless",
"(",
"string",
"$",
"s",
")",
"{",
"$",
"s",
"=",
"trim",
"(",
"$",
"s",
")",
";",
"$",
"s",
"=",
"self",
"::",
"replace",
"(",
"$",
"s",
",",
"'#\\s{2,}#'",
",",
"' '",
")",
";",
"return",
"$",
... | Remove spaces from the beginning and end of a string
and convert double and more spaces between chars to one space
@return mixed | [
"Remove",
"spaces",
"from",
"the",
"beginning",
"and",
"end",
"of",
"a",
"string",
"and",
"convert",
"double",
"and",
"more",
"spaces",
"between",
"chars",
"to",
"one",
"space"
] | 3afb4010ee60fd01307850c13000b1918dc90859 | https://github.com/contributte/utils/blob/3afb4010ee60fd01307850c13000b1918dc90859/src/Strings.php#L54-L60 | train |
contributte/utils | src/Strings.php | Strings.dashless | public static function dashless(string $s)
{
$s = trim($s);
$s = self::replace($s, '#\-#', '');
return $s;
} | php | public static function dashless(string $s)
{
$s = trim($s);
$s = self::replace($s, '#\-#', '');
return $s;
} | [
"public",
"static",
"function",
"dashless",
"(",
"string",
"$",
"s",
")",
"{",
"$",
"s",
"=",
"trim",
"(",
"$",
"s",
")",
";",
"$",
"s",
"=",
"self",
"::",
"replace",
"(",
"$",
"s",
",",
"'#\\-#'",
",",
"''",
")",
";",
"return",
"$",
"s",
";"... | Remove spaces from the beginning and end of a string and remove dashes
@return mixed | [
"Remove",
"spaces",
"from",
"the",
"beginning",
"and",
"end",
"of",
"a",
"string",
"and",
"remove",
"dashes"
] | 3afb4010ee60fd01307850c13000b1918dc90859 | https://github.com/contributte/utils/blob/3afb4010ee60fd01307850c13000b1918dc90859/src/Strings.php#L67-L73 | train |
contributte/utils | src/Strings.php | Strings.slashless | public static function slashless(string $s): string
{
$s = trim($s);
$s = self::replace($s, '#\/{2,}#', '/');
return $s;
} | php | public static function slashless(string $s): string
{
$s = trim($s);
$s = self::replace($s, '#\/{2,}#', '/');
return $s;
} | [
"public",
"static",
"function",
"slashless",
"(",
"string",
"$",
"s",
")",
":",
"string",
"{",
"$",
"s",
"=",
"trim",
"(",
"$",
"s",
")",
";",
"$",
"s",
"=",
"self",
"::",
"replace",
"(",
"$",
"s",
",",
"'#\\/{2,}#'",
",",
"'/'",
")",
";",
"ret... | Remove spaces from the beginning and end of a string
and convert double and more slashes between chars to one slash | [
"Remove",
"spaces",
"from",
"the",
"beginning",
"and",
"end",
"of",
"a",
"string",
"and",
"convert",
"double",
"and",
"more",
"slashes",
"between",
"chars",
"to",
"one",
"slash"
] | 3afb4010ee60fd01307850c13000b1918dc90859 | https://github.com/contributte/utils/blob/3afb4010ee60fd01307850c13000b1918dc90859/src/Strings.php#L79-L85 | train |
hiqdev/yii2-data-mapper | src/hydrator/ConfigurableAggregateHydrator.php | ConfigurableAggregateHydrator.extractAll | public function extractAll(array $array, int $depth = 1)
{
$depth--;
$res = [];
foreach ($array as $key => $object) {
$res[$key] = $depth>0 ? $this->extractAll($object, $depth) : $this->extract($object);
}
return $res;
} | php | public function extractAll(array $array, int $depth = 1)
{
$depth--;
$res = [];
foreach ($array as $key => $object) {
$res[$key] = $depth>0 ? $this->extractAll($object, $depth) : $this->extract($object);
}
return $res;
} | [
"public",
"function",
"extractAll",
"(",
"array",
"$",
"array",
",",
"int",
"$",
"depth",
"=",
"1",
")",
"{",
"$",
"depth",
"--",
";",
"$",
"res",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"object",
")",
"{"... | Extract multiple objects.
@param array $array
@return array | [
"Extract",
"multiple",
"objects",
"."
] | 2e39de404b010b2beb527b913ddf3149422ed738 | https://github.com/hiqdev/yii2-data-mapper/blob/2e39de404b010b2beb527b913ddf3149422ed738/src/hydrator/ConfigurableAggregateHydrator.php#L105-L114 | train |
GiacoCorsiglia/php-stubs-generator | src/Result.php | Result.getDuplicates | public function getDuplicates(): array
{
$dupes = [];
foreach ($this->visitor->getCounts() as $type => $names) {
foreach ($names as $name => $count) {
if ($count > 1) {
$dupes[] = [
'type' => $type,
'name' => $type === 'globals' ? '$' . $name : ltrim($name, '\\'),
'count' => $count,
];
}
}
}
usort($dupes, function (array $a, array $b): int {
return $a['type'] <=> $b['type'] ?: $a['name'] <=> $b['name'];
});
return $dupes;
} | php | public function getDuplicates(): array
{
$dupes = [];
foreach ($this->visitor->getCounts() as $type => $names) {
foreach ($names as $name => $count) {
if ($count > 1) {
$dupes[] = [
'type' => $type,
'name' => $type === 'globals' ? '$' . $name : ltrim($name, '\\'),
'count' => $count,
];
}
}
}
usort($dupes, function (array $a, array $b): int {
return $a['type'] <=> $b['type'] ?: $a['name'] <=> $b['name'];
});
return $dupes;
} | [
"public",
"function",
"getDuplicates",
"(",
")",
":",
"array",
"{",
"$",
"dupes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"visitor",
"->",
"getCounts",
"(",
")",
"as",
"$",
"type",
"=>",
"$",
"names",
")",
"{",
"foreach",
"(",
"$",
... | Returns a list which includes any symbols for which more than one
declaration was found during stub generation.
@return (string|int)[][]
@psalm-return array<array{ type: string, name: string, count: int }> | [
"Returns",
"a",
"list",
"which",
"includes",
"any",
"symbols",
"for",
"which",
"more",
"than",
"one",
"declaration",
"was",
"found",
"during",
"stub",
"generation",
"."
] | c5796427ebc8052c6c662e5101e8250ed5f295fe | https://github.com/GiacoCorsiglia/php-stubs-generator/blob/c5796427ebc8052c6c662e5101e8250ed5f295fe/src/Result.php#L75-L95 | train |
GiacoCorsiglia/php-stubs-generator | src/Result.php | Result.prettyPrint | public function prettyPrint(PrettyPrinterAbstract $printer = null): string
{
if (!$printer) {
$printer = new Standard();
}
return $printer->prettyPrintFile($this->getStubStmts());
} | php | public function prettyPrint(PrettyPrinterAbstract $printer = null): string
{
if (!$printer) {
$printer = new Standard();
}
return $printer->prettyPrintFile($this->getStubStmts());
} | [
"public",
"function",
"prettyPrint",
"(",
"PrettyPrinterAbstract",
"$",
"printer",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"!",
"$",
"printer",
")",
"{",
"$",
"printer",
"=",
"new",
"Standard",
"(",
")",
";",
"}",
"return",
"$",
"printer",
"->... | Shortcut to pretty print all the stubs as one file.
If no `$printer` is provided, a `\PhpParser\PrettyPrinter\Standard` will
be used.
@param PrettyPrinterAbstract|null $printer Pretty printer instance.
@return string The pretty printed version. | [
"Shortcut",
"to",
"pretty",
"print",
"all",
"the",
"stubs",
"as",
"one",
"file",
"."
] | c5796427ebc8052c6c662e5101e8250ed5f295fe | https://github.com/GiacoCorsiglia/php-stubs-generator/blob/c5796427ebc8052c6c662e5101e8250ed5f295fe/src/Result.php#L107-L113 | train |
vanry/laravel-scout-tntsearch | src/TokenizerManager.php | TokenizerManager.createAnalysisDriver | public function createAnalysisDriver()
{
$analysis = new Phpanalysis;
foreach ($this->getConfig('analysis') as $key => $value) {
$key = camel_case($key);
if (property_exists($analysis, $key)) {
$analysis->$key = $value;
}
}
return new PhpAnalysisTokenizer($analysis);
} | php | public function createAnalysisDriver()
{
$analysis = new Phpanalysis;
foreach ($this->getConfig('analysis') as $key => $value) {
$key = camel_case($key);
if (property_exists($analysis, $key)) {
$analysis->$key = $value;
}
}
return new PhpAnalysisTokenizer($analysis);
} | [
"public",
"function",
"createAnalysisDriver",
"(",
")",
"{",
"$",
"analysis",
"=",
"new",
"Phpanalysis",
";",
"foreach",
"(",
"$",
"this",
"->",
"getConfig",
"(",
"'analysis'",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"key",
"=",
"came... | Create a PhpAnalysis tokenizer instance.
@return \Vanry\Scout\Tokenizers\PhpAnalysisTokenizer | [
"Create",
"a",
"PhpAnalysis",
"tokenizer",
"instance",
"."
] | ece71f76030f2c055214ec496a21e123388fa63f | https://github.com/vanry/laravel-scout-tntsearch/blob/ece71f76030f2c055214ec496a21e123388fa63f/src/TokenizerManager.php#L30-L43 | train |
Litepie/Message | src/Message.php | Message.count | public function count($folder, $label = null, $read = 1)
{
return $this->repository
->pushCriteria(new MessageResourceCriteria($folder, $label, $read))
->mailCount();
} | php | public function count($folder, $label = null, $read = 1)
{
return $this->repository
->pushCriteria(new MessageResourceCriteria($folder, $label, $read))
->mailCount();
} | [
"public",
"function",
"count",
"(",
"$",
"folder",
",",
"$",
"label",
"=",
"null",
",",
"$",
"read",
"=",
"1",
")",
"{",
"return",
"$",
"this",
"->",
"repository",
"->",
"pushCriteria",
"(",
"new",
"MessageResourceCriteria",
"(",
"$",
"folder",
",",
"$... | Returns count of message.
@param array $filter
@return int | [
"Returns",
"count",
"of",
"message",
"."
] | 6c123f0feea627d572141fd71935250f3ba3cad0 | https://github.com/Litepie/Message/blob/6c123f0feea627d572141fd71935250f3ba3cad0/src/Message.php#L31-L36 | train |
Litepie/Message | src/Message.php | Message.list | public function list($folder, $label = null, $read = 1)
{
return $this->repository
->pushCriteria(new MessageResourceCriteria($folder, $label, $read))
->mailList();
} | php | public function list($folder, $label = null, $read = 1)
{
return $this->repository
->pushCriteria(new MessageResourceCriteria($folder, $label, $read))
->mailList();
} | [
"public",
"function",
"list",
"(",
"$",
"folder",
",",
"$",
"label",
"=",
"null",
",",
"$",
"read",
"=",
"1",
")",
"{",
"return",
"$",
"this",
"->",
"repository",
"->",
"pushCriteria",
"(",
"new",
"MessageResourceCriteria",
"(",
"$",
"folder",
",",
"$"... | Returns count of message with given label.
@param array $filter
@return int | [
"Returns",
"count",
"of",
"message",
"with",
"given",
"label",
"."
] | 6c123f0feea627d572141fd71935250f3ba3cad0 | https://github.com/Litepie/Message/blob/6c123f0feea627d572141fd71935250f3ba3cad0/src/Message.php#L45-L50 | train |
Litepie/Message | src/Http/Requests/MessageRequest.php | MessageRequest.canAccess | protected function canAccess()
{
if ($this->formRequest->user()->isAdmin() || $this->formRequest->user()->isUser()) {
return true;
}
return $this->formRequest->user()->canDo('message.message.view');
} | php | protected function canAccess()
{
if ($this->formRequest->user()->isAdmin() || $this->formRequest->user()->isUser()) {
return true;
}
return $this->formRequest->user()->canDo('message.message.view');
} | [
"protected",
"function",
"canAccess",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"formRequest",
"->",
"user",
"(",
")",
"->",
"isAdmin",
"(",
")",
"||",
"$",
"this",
"->",
"formRequest",
"->",
"user",
"(",
")",
"->",
"isUser",
"(",
")",
")",
"{",... | Check whether the user can access the module.
@return bool | [
"Check",
"whether",
"the",
"user",
"can",
"access",
"the",
"module",
"."
] | 6c123f0feea627d572141fd71935250f3ba3cad0 | https://github.com/Litepie/Message/blob/6c123f0feea627d572141fd71935250f3ba3cad0/src/Http/Requests/MessageRequest.php#L78-L85 | train |
Litepie/Message | src/Policies/MessagePolicy.php | MessagePolicy.view | public function view(UserPolicy $user, Message $message)
{
if ($user->canDo('message.message.view') && $user->hasRole('admin')) {
return true;
}
return $user->id == $message->user_id && get_class($user) == $message->user_type;
} | php | public function view(UserPolicy $user, Message $message)
{
if ($user->canDo('message.message.view') && $user->hasRole('admin')) {
return true;
}
return $user->id == $message->user_id && get_class($user) == $message->user_type;
} | [
"public",
"function",
"view",
"(",
"UserPolicy",
"$",
"user",
",",
"Message",
"$",
"message",
")",
"{",
"if",
"(",
"$",
"user",
"->",
"canDo",
"(",
"'message.message.view'",
")",
"&&",
"$",
"user",
"->",
"hasRole",
"(",
"'admin'",
")",
")",
"{",
"retur... | Determine if the given user can view the message.
@param User $user
@param Message $message
@return bool | [
"Determine",
"if",
"the",
"given",
"user",
"can",
"view",
"the",
"message",
"."
] | 6c123f0feea627d572141fd71935250f3ba3cad0 | https://github.com/Litepie/Message/blob/6c123f0feea627d572141fd71935250f3ba3cad0/src/Policies/MessagePolicy.php#L18-L25 | train |
Litepie/Message | src/Policies/MessagePolicy.php | MessagePolicy.update | public function update(UserPolicy $user, Message $message)
{
return $user->id == $message->user_id && get_class($user) == $message->user_type;
} | php | public function update(UserPolicy $user, Message $message)
{
return $user->id == $message->user_id && get_class($user) == $message->user_type;
} | [
"public",
"function",
"update",
"(",
"UserPolicy",
"$",
"user",
",",
"Message",
"$",
"message",
")",
"{",
"return",
"$",
"user",
"->",
"id",
"==",
"$",
"message",
"->",
"user_id",
"&&",
"get_class",
"(",
"$",
"user",
")",
"==",
"$",
"message",
"->",
... | Determine if the given user can update the given message.
@param User $user
@param Message $message
@return bool | [
"Determine",
"if",
"the",
"given",
"user",
"can",
"update",
"the",
"given",
"message",
"."
] | 6c123f0feea627d572141fd71935250f3ba3cad0 | https://github.com/Litepie/Message/blob/6c123f0feea627d572141fd71935250f3ba3cad0/src/Policies/MessagePolicy.php#L48-L51 | train |
Litepie/Message | src/Http/Controllers/MessageResourceController.php | MessageResourceController.index | public function index(MessageRequest $request)
{
if ($this->response->typeIs('json')) {
$pageLimit = $request->input('pageLimit');
$data = $this->repository
->setPresenter(\Litepie\Message\Repositories\Presenter\MessageListPresenter::class)
->getDataTable($pageLimit);
return $this->response
->data($data)
->output();
}
$messages = $this->repository->paginate();
return $this->response->title(trans('message::message.names'))
->view('message::message.index', true)
->data(compact('messages'))
->output();
} | php | public function index(MessageRequest $request)
{
if ($this->response->typeIs('json')) {
$pageLimit = $request->input('pageLimit');
$data = $this->repository
->setPresenter(\Litepie\Message\Repositories\Presenter\MessageListPresenter::class)
->getDataTable($pageLimit);
return $this->response
->data($data)
->output();
}
$messages = $this->repository->paginate();
return $this->response->title(trans('message::message.names'))
->view('message::message.index', true)
->data(compact('messages'))
->output();
} | [
"public",
"function",
"index",
"(",
"MessageRequest",
"$",
"request",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"response",
"->",
"typeIs",
"(",
"'json'",
")",
")",
"{",
"$",
"pageLimit",
"=",
"$",
"request",
"->",
"input",
"(",
"'pageLimit'",
")",
";",
... | Display a list of message.
@return Response | [
"Display",
"a",
"list",
"of",
"message",
"."
] | 6c123f0feea627d572141fd71935250f3ba3cad0 | https://github.com/Litepie/Message/blob/6c123f0feea627d572141fd71935250f3ba3cad0/src/Http/Controllers/MessageResourceController.php#L36-L56 | train |
Litepie/Message | src/Http/Controllers/MessageResourceController.php | MessageResourceController.show | public function show(MessageRequest $request, Message $message)
{
if ($message->exists) {
$view = 'message::message.show';
} else {
$view = 'message::message.new';
}
return $this->response->title(trans('app.view') . ' ' . trans('message::message.name'))
->data(compact('message'))
->view($view, true)
->output();
} | php | public function show(MessageRequest $request, Message $message)
{
if ($message->exists) {
$view = 'message::message.show';
} else {
$view = 'message::message.new';
}
return $this->response->title(trans('app.view') . ' ' . trans('message::message.name'))
->data(compact('message'))
->view($view, true)
->output();
} | [
"public",
"function",
"show",
"(",
"MessageRequest",
"$",
"request",
",",
"Message",
"$",
"message",
")",
"{",
"if",
"(",
"$",
"message",
"->",
"exists",
")",
"{",
"$",
"view",
"=",
"'message::message.show'",
";",
"}",
"else",
"{",
"$",
"view",
"=",
"'... | Display message.
@param Request $request
@param Model $message
@return Response | [
"Display",
"message",
"."
] | 6c123f0feea627d572141fd71935250f3ba3cad0 | https://github.com/Litepie/Message/blob/6c123f0feea627d572141fd71935250f3ba3cad0/src/Http/Controllers/MessageResourceController.php#L66-L79 | train |
Litepie/Message | src/Http/Controllers/MessageResourceController.php | MessageResourceController.store | public function store(MessageRequest $request)
{
try {
$mail_to = $request->get('mails');
$status = $request->get('status');
$sent = $request->all();
$inbox = $request->all();
$draft = $request->all();
if (empty($mail_to)) {
return response()->json([
'message' => trans('messages.success.updated', ['Module' => trans('message::message.name')]),
'code' => 204,
'redirect' => trans_url('/admin/message/message/0'),
], 201);
}
foreach ($mail_to as $user_id) {
if ($status == 'Draft') {
//draft
$draft['user_id'] = user_id('admin.web');
$draft['user_type'] = user_type('admin.web');
$draft['to'] = $user_id;
$draft['status'] = "Draft";
$message1 = $this->repository->create($draft);
} else {
//sent
$sent['user_id'] = user_id('admin.web');
$sent['user_type'] = user_type('admin.web');
$sent['to'] = $user_id;
$message = $this->repository->create($sent);
//inbox
$inbox['user_id'] = user_id('admin.web');
$inbox['user_type'] = user_type('admin.web');
$inbox['to'] = $user_id;
$inbox['status'] = "Inbox";
$message1 = $this->repository->create($inbox);
}
}
$inbox_count = $this->repository->msgCount('Inbox');
$draft_count = $this->repository->msgCount('Draft');
$sent_count = $this->repository->msgCount('Sent');
return response()->json([
'message' => trans('messages.success.updated', ['Module' => trans('message::message.name')]),
'code' => 204,
'redirect' => trans_url('/admin/message/message/status/Inbox'),
'inbox_count' => $inbox_count,
'draft_count' => $draft_count,
'sent_count' => $sent_count,
], 201);
} catch (Exception $e) {
return response()->json([
'message' => $e->getMessage(),
'code' => 400,
], 400);
}
} | php | public function store(MessageRequest $request)
{
try {
$mail_to = $request->get('mails');
$status = $request->get('status');
$sent = $request->all();
$inbox = $request->all();
$draft = $request->all();
if (empty($mail_to)) {
return response()->json([
'message' => trans('messages.success.updated', ['Module' => trans('message::message.name')]),
'code' => 204,
'redirect' => trans_url('/admin/message/message/0'),
], 201);
}
foreach ($mail_to as $user_id) {
if ($status == 'Draft') {
//draft
$draft['user_id'] = user_id('admin.web');
$draft['user_type'] = user_type('admin.web');
$draft['to'] = $user_id;
$draft['status'] = "Draft";
$message1 = $this->repository->create($draft);
} else {
//sent
$sent['user_id'] = user_id('admin.web');
$sent['user_type'] = user_type('admin.web');
$sent['to'] = $user_id;
$message = $this->repository->create($sent);
//inbox
$inbox['user_id'] = user_id('admin.web');
$inbox['user_type'] = user_type('admin.web');
$inbox['to'] = $user_id;
$inbox['status'] = "Inbox";
$message1 = $this->repository->create($inbox);
}
}
$inbox_count = $this->repository->msgCount('Inbox');
$draft_count = $this->repository->msgCount('Draft');
$sent_count = $this->repository->msgCount('Sent');
return response()->json([
'message' => trans('messages.success.updated', ['Module' => trans('message::message.name')]),
'code' => 204,
'redirect' => trans_url('/admin/message/message/status/Inbox'),
'inbox_count' => $inbox_count,
'draft_count' => $draft_count,
'sent_count' => $sent_count,
], 201);
} catch (Exception $e) {
return response()->json([
'message' => $e->getMessage(),
'code' => 400,
], 400);
}
} | [
"public",
"function",
"store",
"(",
"MessageRequest",
"$",
"request",
")",
"{",
"try",
"{",
"$",
"mail_to",
"=",
"$",
"request",
"->",
"get",
"(",
"'mails'",
")",
";",
"$",
"status",
"=",
"$",
"request",
"->",
"get",
"(",
"'status'",
")",
";",
"$",
... | Create new message.
@param Request $request
@return Response | [
"Create",
"new",
"message",
"."
] | 6c123f0feea627d572141fd71935250f3ba3cad0 | https://github.com/Litepie/Message/blob/6c123f0feea627d572141fd71935250f3ba3cad0/src/Http/Controllers/MessageResourceController.php#L105-L169 | train |
Litepie/Message | src/Http/Controllers/MessageResourceController.php | MessageResourceController.edit | public function edit(MessageRequest $request, Message $message)
{
Form::populate($message);
return response()->view('message::message.edit', compact('message'));
} | php | public function edit(MessageRequest $request, Message $message)
{
Form::populate($message);
return response()->view('message::message.edit', compact('message'));
} | [
"public",
"function",
"edit",
"(",
"MessageRequest",
"$",
"request",
",",
"Message",
"$",
"message",
")",
"{",
"Form",
"::",
"populate",
"(",
"$",
"message",
")",
";",
"return",
"response",
"(",
")",
"->",
"view",
"(",
"'message::message.edit'",
",",
"comp... | Show message for editing.
@param Request $request
@param Model $message
@return Response | [
"Show",
"message",
"for",
"editing",
"."
] | 6c123f0feea627d572141fd71935250f3ba3cad0 | https://github.com/Litepie/Message/blob/6c123f0feea627d572141fd71935250f3ba3cad0/src/Http/Controllers/MessageResourceController.php#L179-L183 | train |
Litepie/Message | src/Http/Controllers/MessageResourceController.php | MessageResourceController.destroy | public function destroy(MessageRequest $request, Message $message)
{
try {
if (!empty($request->get('arrayIds'))) {
$ids = $request->get('arrayIds');
$t = $this->repository->deleteMultiple($ids);
return $t;
} else {
$t = $message->delete();
}
$this->repository->pushCriteria(new \Litepie\Message\Repositories\Criteria\MessageAdminCriteria());
$inbox_count = $this->repository->msgCount('Inbox');
$trash_count = $this->repository->msgCount('Trash');
return response()->json([
'message' => trans('messages.success.deleted', ['Module' => trans('message::message.name')]),
'code' => 202,
'redirect' => trans_url('/admin/message/message/0'),
'inbox_count' => $inbox_count,
'trash_count' => $trash_count,
], 202);
} catch (Exception $e) {
return response()->json([
'message' => $e->getMessage(),
'code' => 400,
'redirect' => trans_url('/admin/message/message/' . $message->getRouteKey()),
], 400);
}
} | php | public function destroy(MessageRequest $request, Message $message)
{
try {
if (!empty($request->get('arrayIds'))) {
$ids = $request->get('arrayIds');
$t = $this->repository->deleteMultiple($ids);
return $t;
} else {
$t = $message->delete();
}
$this->repository->pushCriteria(new \Litepie\Message\Repositories\Criteria\MessageAdminCriteria());
$inbox_count = $this->repository->msgCount('Inbox');
$trash_count = $this->repository->msgCount('Trash');
return response()->json([
'message' => trans('messages.success.deleted', ['Module' => trans('message::message.name')]),
'code' => 202,
'redirect' => trans_url('/admin/message/message/0'),
'inbox_count' => $inbox_count,
'trash_count' => $trash_count,
], 202);
} catch (Exception $e) {
return response()->json([
'message' => $e->getMessage(),
'code' => 400,
'redirect' => trans_url('/admin/message/message/' . $message->getRouteKey()),
], 400);
}
} | [
"public",
"function",
"destroy",
"(",
"MessageRequest",
"$",
"request",
",",
"Message",
"$",
"message",
")",
"{",
"try",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"request",
"->",
"get",
"(",
"'arrayIds'",
")",
")",
")",
"{",
"$",
"ids",
"=",
"$",
"r... | Remove the message.
@param Model $message
@return Response | [
"Remove",
"the",
"message",
"."
] | 6c123f0feea627d572141fd71935250f3ba3cad0 | https://github.com/Litepie/Message/blob/6c123f0feea627d572141fd71935250f3ba3cad0/src/Http/Controllers/MessageResourceController.php#L227-L260 | train |
kherge-abandoned/php-phar-update | src/lib/Herrera/Phar/Update/Manifest.php | Manifest.load | public static function load($json)
{
$j = new Json();
return self::create($j->decode($json), $j);
} | php | public static function load($json)
{
$j = new Json();
return self::create($j->decode($json), $j);
} | [
"public",
"static",
"function",
"load",
"(",
"$",
"json",
")",
"{",
"$",
"j",
"=",
"new",
"Json",
"(",
")",
";",
"return",
"self",
"::",
"create",
"(",
"$",
"j",
"->",
"decode",
"(",
"$",
"json",
")",
",",
"$",
"j",
")",
";",
"}"
] | Loads the manifest from a JSON encoded string.
@param string $json The JSON encoded string.
@return Manifest The manifest. | [
"Loads",
"the",
"manifest",
"from",
"a",
"JSON",
"encoded",
"string",
"."
] | 15643c90d3d43620a4f45c910e6afb7a0ad4b488 | https://github.com/kherge-abandoned/php-phar-update/blob/15643c90d3d43620a4f45c910e6afb7a0ad4b488/src/lib/Herrera/Phar/Update/Manifest.php#L88-L93 | train |
kherge-abandoned/php-phar-update | src/lib/Herrera/Phar/Update/Manifest.php | Manifest.loadFile | public static function loadFile($file)
{
$json = new Json();
return self::create($json->decodeFile($file), $json);
} | php | public static function loadFile($file)
{
$json = new Json();
return self::create($json->decodeFile($file), $json);
} | [
"public",
"static",
"function",
"loadFile",
"(",
"$",
"file",
")",
"{",
"$",
"json",
"=",
"new",
"Json",
"(",
")",
";",
"return",
"self",
"::",
"create",
"(",
"$",
"json",
"->",
"decodeFile",
"(",
"$",
"file",
")",
",",
"$",
"json",
")",
";",
"}"... | Loads the manifest from a JSON encoded file.
@param string $file The JSON encoded file.
@return Manifest The manifest. | [
"Loads",
"the",
"manifest",
"from",
"a",
"JSON",
"encoded",
"file",
"."
] | 15643c90d3d43620a4f45c910e6afb7a0ad4b488 | https://github.com/kherge-abandoned/php-phar-update/blob/15643c90d3d43620a4f45c910e6afb7a0ad4b488/src/lib/Herrera/Phar/Update/Manifest.php#L102-L107 | train |
kherge-abandoned/php-phar-update | src/lib/Herrera/Phar/Update/Manifest.php | Manifest.create | private static function create($decoded, Json $json)
{
$json->validate(
$json->decodeFile(PHAR_UPDATE_MANIFEST_SCHEMA),
$decoded
);
$updates = array();
foreach ($decoded as $update) {
$updates[] = new Update(
$update->name,
$update->sha1,
$update->url,
Parser::toVersion($update->version),
isset($update->publicKey) ? $update->publicKey : null
);
}
usort(
$updates,
function (Update $a, Update $b) {
return Comparator::isGreaterThan(
$a->getVersion(),
$b->getVersion()
);
}
);
return new static($updates);
} | php | private static function create($decoded, Json $json)
{
$json->validate(
$json->decodeFile(PHAR_UPDATE_MANIFEST_SCHEMA),
$decoded
);
$updates = array();
foreach ($decoded as $update) {
$updates[] = new Update(
$update->name,
$update->sha1,
$update->url,
Parser::toVersion($update->version),
isset($update->publicKey) ? $update->publicKey : null
);
}
usort(
$updates,
function (Update $a, Update $b) {
return Comparator::isGreaterThan(
$a->getVersion(),
$b->getVersion()
);
}
);
return new static($updates);
} | [
"private",
"static",
"function",
"create",
"(",
"$",
"decoded",
",",
"Json",
"$",
"json",
")",
"{",
"$",
"json",
"->",
"validate",
"(",
"$",
"json",
"->",
"decodeFile",
"(",
"PHAR_UPDATE_MANIFEST_SCHEMA",
")",
",",
"$",
"decoded",
")",
";",
"$",
"updates... | Validates the data, processes it, and returns a new instance of Manifest.
@param array $decoded The decoded JSON data.
@param Json $json The Json instance used to decode the data.
@return Manifest The new instance. | [
"Validates",
"the",
"data",
"processes",
"it",
"and",
"returns",
"a",
"new",
"instance",
"of",
"Manifest",
"."
] | 15643c90d3d43620a4f45c910e6afb7a0ad4b488 | https://github.com/kherge-abandoned/php-phar-update/blob/15643c90d3d43620a4f45c910e6afb7a0ad4b488/src/lib/Herrera/Phar/Update/Manifest.php#L117-L147 | train |
prooph/laravel-package | src/Migration/Schema/SnapshotSchema.php | SnapshotSchema.create | public static function create($snapshotName = 'snapshot')
{
Schema::create($snapshotName, function (Blueprint $snapshot) use ($snapshotName) {
// UUID4 of linked aggregate
$snapshot->char('aggregate_id', 36);
// Class of the linked aggregate
$snapshot->string('aggregate_type', 150);
// Version of the aggregate after event was recorded
$snapshot->integer('last_version', false, true);
// DateTime ISO8601 + microseconds UTC stored as a string e.g. 2016-02-02T11:45:39.000000
$snapshot->char('created_at', 26);
$snapshot->binary('aggregate_root');
$snapshot->index(['aggregate_id', 'aggregate_type'], $snapshotName . '_m_v_uix');
});
} | php | public static function create($snapshotName = 'snapshot')
{
Schema::create($snapshotName, function (Blueprint $snapshot) use ($snapshotName) {
// UUID4 of linked aggregate
$snapshot->char('aggregate_id', 36);
// Class of the linked aggregate
$snapshot->string('aggregate_type', 150);
// Version of the aggregate after event was recorded
$snapshot->integer('last_version', false, true);
// DateTime ISO8601 + microseconds UTC stored as a string e.g. 2016-02-02T11:45:39.000000
$snapshot->char('created_at', 26);
$snapshot->binary('aggregate_root');
$snapshot->index(['aggregate_id', 'aggregate_type'], $snapshotName . '_m_v_uix');
});
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"snapshotName",
"=",
"'snapshot'",
")",
"{",
"Schema",
"::",
"create",
"(",
"$",
"snapshotName",
",",
"function",
"(",
"Blueprint",
"$",
"snapshot",
")",
"use",
"(",
"$",
"snapshotName",
")",
"{",
"// UUI... | Creates a snapshot schema
@param Schema $schema
@param string $snapshotName Defaults to 'snapshot' | [
"Creates",
"a",
"snapshot",
"schema"
] | e9647921ad1dc7b9753010e4648933555d89cddc | https://github.com/prooph/laravel-package/blob/e9647921ad1dc7b9753010e4648933555d89cddc/src/Migration/Schema/SnapshotSchema.php#L30-L45 | train |
prooph/laravel-package | src/Facades/QueryBus.php | QueryBus.resultFrom | public static function resultFrom($aQuery)
{
/** @var \Prooph\ServiceBus\QueryBus $instance */
$instance = self::getFacadeRoot();
$ret = null;
$instance
->dispatch($aQuery)
->done(function ($result) use (&$ret) {
$ret = $result;
}, function () use ($aQuery) {
throw QueryResultFailed::fromQuery($aQuery, func_get_args());
});
return $ret;
} | php | public static function resultFrom($aQuery)
{
/** @var \Prooph\ServiceBus\QueryBus $instance */
$instance = self::getFacadeRoot();
$ret = null;
$instance
->dispatch($aQuery)
->done(function ($result) use (&$ret) {
$ret = $result;
}, function () use ($aQuery) {
throw QueryResultFailed::fromQuery($aQuery, func_get_args());
});
return $ret;
} | [
"public",
"static",
"function",
"resultFrom",
"(",
"$",
"aQuery",
")",
"{",
"/** @var \\Prooph\\ServiceBus\\QueryBus $instance */",
"$",
"instance",
"=",
"self",
"::",
"getFacadeRoot",
"(",
")",
";",
"$",
"ret",
"=",
"null",
";",
"$",
"instance",
"->",
"dispatch... | The default dispatch method will return you a promise
sometimes you might want to just get the result instead
this method will return you the result on a successful
query, and throw an exception instead if the query
fails.
@throws QueryResultFailed
@param Query|mixed $aQuery
@return mixed | [
"The",
"default",
"dispatch",
"method",
"will",
"return",
"you",
"a",
"promise",
"sometimes",
"you",
"might",
"want",
"to",
"just",
"get",
"the",
"result",
"instead",
"this",
"method",
"will",
"return",
"you",
"the",
"result",
"on",
"a",
"successful",
"query... | e9647921ad1dc7b9753010e4648933555d89cddc | https://github.com/prooph/laravel-package/blob/e9647921ad1dc7b9753010e4648933555d89cddc/src/Facades/QueryBus.php#L39-L54 | train |
DivineOmega/array_undot | src/ArrayHelpers.php | ArrayHelpers.undot | public function undot(array $dotNotationArray)
{
$array = [];
foreach ($dotNotationArray as $key => $value) {
$this->set($array, $key, $value);
}
return $array;
} | php | public function undot(array $dotNotationArray)
{
$array = [];
foreach ($dotNotationArray as $key => $value) {
$this->set($array, $key, $value);
}
return $array;
} | [
"public",
"function",
"undot",
"(",
"array",
"$",
"dotNotationArray",
")",
"{",
"$",
"array",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"dotNotationArray",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"$",
"array",
... | Expands a dot notation array into a full multi-dimensional array
@param array $dotNotationArray
@return array | [
"Expands",
"a",
"dot",
"notation",
"array",
"into",
"a",
"full",
"multi",
"-",
"dimensional",
"array"
] | 44aed525e775718e3821d670b08046fd84914d10 | https://github.com/DivineOmega/array_undot/blob/44aed525e775718e3821d670b08046fd84914d10/src/ArrayHelpers.php#L14-L22 | train |
dreamfactorysoftware/df-sqldb | src/Database/Schema/SqlSchema.php | SqlSchema.getSupportedResourceTypes | public function getSupportedResourceTypes()
{
return [
DbResourceTypes::TYPE_SCHEMA,
DbResourceTypes::TYPE_TABLE,
DbResourceTypes::TYPE_TABLE_FIELD,
DbResourceTypes::TYPE_TABLE_CONSTRAINT,
DbResourceTypes::TYPE_TABLE_RELATIONSHIP,
DbResourceTypes::TYPE_VIEW,
DbResourceTypes::TYPE_FUNCTION,
DbResourceTypes::TYPE_PROCEDURE,
];
} | php | public function getSupportedResourceTypes()
{
return [
DbResourceTypes::TYPE_SCHEMA,
DbResourceTypes::TYPE_TABLE,
DbResourceTypes::TYPE_TABLE_FIELD,
DbResourceTypes::TYPE_TABLE_CONSTRAINT,
DbResourceTypes::TYPE_TABLE_RELATIONSHIP,
DbResourceTypes::TYPE_VIEW,
DbResourceTypes::TYPE_FUNCTION,
DbResourceTypes::TYPE_PROCEDURE,
];
} | [
"public",
"function",
"getSupportedResourceTypes",
"(",
")",
"{",
"return",
"[",
"DbResourceTypes",
"::",
"TYPE_SCHEMA",
",",
"DbResourceTypes",
"::",
"TYPE_TABLE",
",",
"DbResourceTypes",
"::",
"TYPE_TABLE_FIELD",
",",
"DbResourceTypes",
"::",
"TYPE_TABLE_CONSTRAINT",
... | Return an array of supported schema resource types.
@return array | [
"Return",
"an",
"array",
"of",
"supported",
"schema",
"resource",
"types",
"."
] | f5b6c45fae068db5043419405299bfbc928fa90b | https://github.com/dreamfactorysoftware/df-sqldb/blob/f5b6c45fae068db5043419405299bfbc928fa90b/src/Database/Schema/SqlSchema.php#L33-L45 | train |
dreamfactorysoftware/df-sqldb | src/Resources/StoredProcedure.php | StoredProcedure.describeProcedures | protected function describeProcedures($names, $refresh = false)
{
$names = static::validateAsArray(
$names,
',',
true,
'The request contains no valid procedure names or properties.'
);
$out = [];
foreach ($names as $name) {
$out[] = $this->describeProcedure($name, $refresh);
}
return $out;
} | php | protected function describeProcedures($names, $refresh = false)
{
$names = static::validateAsArray(
$names,
',',
true,
'The request contains no valid procedure names or properties.'
);
$out = [];
foreach ($names as $name) {
$out[] = $this->describeProcedure($name, $refresh);
}
return $out;
} | [
"protected",
"function",
"describeProcedures",
"(",
"$",
"names",
",",
"$",
"refresh",
"=",
"false",
")",
"{",
"$",
"names",
"=",
"static",
"::",
"validateAsArray",
"(",
"$",
"names",
",",
"','",
",",
"true",
",",
"'The request contains no valid procedure names ... | Get multiple procedures and their properties
@param string | array $names Procedure names comma-delimited string or array
@param bool $refresh Force a refresh of the schema from the database
@return array
@throws \Exception | [
"Get",
"multiple",
"procedures",
"and",
"their",
"properties"
] | f5b6c45fae068db5043419405299bfbc928fa90b | https://github.com/dreamfactorysoftware/df-sqldb/blob/f5b6c45fae068db5043419405299bfbc928fa90b/src/Resources/StoredProcedure.php#L273-L288 | train |
dreamfactorysoftware/df-sqldb | src/Resources/StoredProcedure.php | StoredProcedure.describeProcedure | protected function describeProcedure($name, $refresh = false)
{
$name = (is_array($name) ? array_get($name, 'name') : $name);
if (empty($name)) {
throw new BadRequestException('Procedure name can not be empty.');
}
$this->checkPermission(Verbs::GET, $name);
try {
$procedure = $this->getProcedure($name, $refresh);
$result = $procedure->toArray();
$result['access'] = $this->getPermissions($name);
return $result;
} catch (RestException $ex) {
throw $ex;
} catch (\Exception $ex) {
throw new InternalServerErrorException("Failed to query database schema.\n{$ex->getMessage()}");
}
} | php | protected function describeProcedure($name, $refresh = false)
{
$name = (is_array($name) ? array_get($name, 'name') : $name);
if (empty($name)) {
throw new BadRequestException('Procedure name can not be empty.');
}
$this->checkPermission(Verbs::GET, $name);
try {
$procedure = $this->getProcedure($name, $refresh);
$result = $procedure->toArray();
$result['access'] = $this->getPermissions($name);
return $result;
} catch (RestException $ex) {
throw $ex;
} catch (\Exception $ex) {
throw new InternalServerErrorException("Failed to query database schema.\n{$ex->getMessage()}");
}
} | [
"protected",
"function",
"describeProcedure",
"(",
"$",
"name",
",",
"$",
"refresh",
"=",
"false",
")",
"{",
"$",
"name",
"=",
"(",
"is_array",
"(",
"$",
"name",
")",
"?",
"array_get",
"(",
"$",
"name",
",",
"'name'",
")",
":",
"$",
"name",
")",
";... | Get any properties related to the procedure
@param string | array $name Procedure name or defining properties
@param bool $refresh Force a refresh of the schema from the database
@return array
@throws \Exception | [
"Get",
"any",
"properties",
"related",
"to",
"the",
"procedure"
] | f5b6c45fae068db5043419405299bfbc928fa90b | https://github.com/dreamfactorysoftware/df-sqldb/blob/f5b6c45fae068db5043419405299bfbc928fa90b/src/Resources/StoredProcedure.php#L299-L319 | train |
nglasl/silverstripe-mediawesome | src/pages/MediaPage.php | MediaPage.validate | public function validate() {
$parent = $this->getParent();
// The URL segment will conflict with a year/month/day/media format when numeric.
if(is_numeric($this->URLSegment) || !($parent instanceof MediaHolder) || ($this->MediaTypeID && ($parent->MediaTypeID != $this->MediaTypeID))) {
// Customise a validation error message.
if(is_numeric($this->URLSegment)) {
$message = '"URL Segment" must not be numeric!';
}
else if(!($parent instanceof MediaHolder)) {
$message = 'The parent needs to be a published media holder!';
}
else {
$message = "The media holder type doesn't match this!";
}
$error = new HTTPResponse_Exception($message, 403);
$error->getResponse()->addHeader('X-Status', rawurlencode($message));
// Allow extension customisation.
$this->extend('validateMediaPage', $error);
throw $error;
}
return parent::validate();
} | php | public function validate() {
$parent = $this->getParent();
// The URL segment will conflict with a year/month/day/media format when numeric.
if(is_numeric($this->URLSegment) || !($parent instanceof MediaHolder) || ($this->MediaTypeID && ($parent->MediaTypeID != $this->MediaTypeID))) {
// Customise a validation error message.
if(is_numeric($this->URLSegment)) {
$message = '"URL Segment" must not be numeric!';
}
else if(!($parent instanceof MediaHolder)) {
$message = 'The parent needs to be a published media holder!';
}
else {
$message = "The media holder type doesn't match this!";
}
$error = new HTTPResponse_Exception($message, 403);
$error->getResponse()->addHeader('X-Status', rawurlencode($message));
// Allow extension customisation.
$this->extend('validateMediaPage', $error);
throw $error;
}
return parent::validate();
} | [
"public",
"function",
"validate",
"(",
")",
"{",
"$",
"parent",
"=",
"$",
"this",
"->",
"getParent",
"(",
")",
";",
"// The URL segment will conflict with a year/month/day/media format when numeric.",
"if",
"(",
"is_numeric",
"(",
"$",
"this",
"->",
"URLSegment",
")... | Confirm that the current page is valid. | [
"Confirm",
"that",
"the",
"current",
"page",
"is",
"valid",
"."
] | 0537ad9934f69a680cd20115269efed13e082abf | https://github.com/nglasl/silverstripe-mediawesome/blob/0537ad9934f69a680cd20115269efed13e082abf/src/pages/MediaPage.php#L322-L350 | train |
nglasl/silverstripe-mediawesome | src/pages/MediaPage.php | MediaPage.Link | public function Link($action = null) {
$parent = $this->getParent();
if(!$parent) {
return null;
}
$date = ($parent->URLFormatting !== '-') ? $this->dbObject('Date')->Format($parent->URLFormatting ?: 'y/MM/dd/') : '';
$join = array(
$parent->Link(),
"{$date}{$this->URLSegment}/"
);
if($action) {
$join[] = "{$action}/";
}
$link = Controller::join_links($join);
return $link;
} | php | public function Link($action = null) {
$parent = $this->getParent();
if(!$parent) {
return null;
}
$date = ($parent->URLFormatting !== '-') ? $this->dbObject('Date')->Format($parent->URLFormatting ?: 'y/MM/dd/') : '';
$join = array(
$parent->Link(),
"{$date}{$this->URLSegment}/"
);
if($action) {
$join[] = "{$action}/";
}
$link = Controller::join_links($join);
return $link;
} | [
"public",
"function",
"Link",
"(",
"$",
"action",
"=",
"null",
")",
"{",
"$",
"parent",
"=",
"$",
"this",
"->",
"getParent",
"(",
")",
";",
"if",
"(",
"!",
"$",
"parent",
")",
"{",
"return",
"null",
";",
"}",
"$",
"date",
"=",
"(",
"$",
"parent... | Determine the URL by using the media holder's defined URL format. | [
"Determine",
"the",
"URL",
"by",
"using",
"the",
"media",
"holder",
"s",
"defined",
"URL",
"format",
"."
] | 0537ad9934f69a680cd20115269efed13e082abf | https://github.com/nglasl/silverstripe-mediawesome/blob/0537ad9934f69a680cd20115269efed13e082abf/src/pages/MediaPage.php#L405-L421 | train |
nglasl/silverstripe-mediawesome | src/pages/MediaPage.php | MediaPage.AbsoluteLink | public function AbsoluteLink($action = null) {
$parent = $this->getParent();
if(!$parent) {
return null;
}
$date = ($parent->URLFormatting !== '-') ? $this->dbObject('Date')->Format($parent->URLFormatting ?: 'y/MM/dd/') : '';
$link = $parent->AbsoluteLink() . "{$date}{$this->URLSegment}/";
if($action) {
$link .= "{$action}/";
}
return $link;
} | php | public function AbsoluteLink($action = null) {
$parent = $this->getParent();
if(!$parent) {
return null;
}
$date = ($parent->URLFormatting !== '-') ? $this->dbObject('Date')->Format($parent->URLFormatting ?: 'y/MM/dd/') : '';
$link = $parent->AbsoluteLink() . "{$date}{$this->URLSegment}/";
if($action) {
$link .= "{$action}/";
}
return $link;
} | [
"public",
"function",
"AbsoluteLink",
"(",
"$",
"action",
"=",
"null",
")",
"{",
"$",
"parent",
"=",
"$",
"this",
"->",
"getParent",
"(",
")",
";",
"if",
"(",
"!",
"$",
"parent",
")",
"{",
"return",
"null",
";",
"}",
"$",
"date",
"=",
"(",
"$",
... | Determine the absolute URL by using the media holder's defined URL format. | [
"Determine",
"the",
"absolute",
"URL",
"by",
"using",
"the",
"media",
"holder",
"s",
"defined",
"URL",
"format",
"."
] | 0537ad9934f69a680cd20115269efed13e082abf | https://github.com/nglasl/silverstripe-mediawesome/blob/0537ad9934f69a680cd20115269efed13e082abf/src/pages/MediaPage.php#L427-L439 | train |
dreamfactorysoftware/df-sqldb | src/Database/Schema/SqliteSchema.php | SqliteSchema.addForeignKey | public function addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete = null, $update = null)
{
throw new \Exception('Adding a foreign key constraint to an existing table is not supported by SQLite.');
} | php | public function addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete = null, $update = null)
{
throw new \Exception('Adding a foreign key constraint to an existing table is not supported by SQLite.');
} | [
"public",
"function",
"addForeignKey",
"(",
"$",
"name",
",",
"$",
"table",
",",
"$",
"columns",
",",
"$",
"refTable",
",",
"$",
"refColumns",
",",
"$",
"delete",
"=",
"null",
",",
"$",
"update",
"=",
"null",
")",
"{",
"throw",
"new",
"\\",
"Exceptio... | Builds a SQL statement for adding a foreign key constraint to an existing table.
Because SQLite does not support adding foreign key to an existing table, calling this method will throw an
exception.
@param string $name the name of the foreign key constraint.
@param string $table the table that the foreign key constraint will be added to.
@param string $columns the name of the column to that the constraint will be added on. If there are multiple
columns, separate them with commas.
@param string $refTable the table that the foreign key references to.
@param string $refColumns the name of the column that the foreign key references to. If there are multiple
columns, separate them with commas.
@param string $delete the ON DELETE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION,
SET DEFAULT, SET NULL
@param string $update the ON UPDATE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION,
SET DEFAULT, SET NULL
@throws \Exception
@return string the SQL statement for adding a foreign key constraint to an existing table. | [
"Builds",
"a",
"SQL",
"statement",
"for",
"adding",
"a",
"foreign",
"key",
"constraint",
"to",
"an",
"existing",
"table",
".",
"Because",
"SQLite",
"does",
"not",
"support",
"adding",
"foreign",
"key",
"to",
"an",
"existing",
"table",
"calling",
"this",
"met... | f5b6c45fae068db5043419405299bfbc928fa90b | https://github.com/dreamfactorysoftware/df-sqldb/blob/f5b6c45fae068db5043419405299bfbc928fa90b/src/Database/Schema/SqliteSchema.php#L472-L475 | train |
nglasl/silverstripe-mediawesome | src/objects/MediaTag.php | MediaTag.validate | public function validate() {
$result = parent::validate();
// Confirm that the current tag has been given a title and doesn't already exist.
$this->Title = strtolower($this->Title);
if($result->isValid() && !$this->Title) {
$result->addError('"Title" required!');
}
else if($result->isValid() && MediaTag::get_one(MediaTag::class, array(
'ID != ?' => $this->ID,
'Title = ?' => $this->Title
))) {
$result->addError('Tag already exists!');
}
// Allow extension customisation.
$this->extend('validateMediaTag', $result);
return $result;
} | php | public function validate() {
$result = parent::validate();
// Confirm that the current tag has been given a title and doesn't already exist.
$this->Title = strtolower($this->Title);
if($result->isValid() && !$this->Title) {
$result->addError('"Title" required!');
}
else if($result->isValid() && MediaTag::get_one(MediaTag::class, array(
'ID != ?' => $this->ID,
'Title = ?' => $this->Title
))) {
$result->addError('Tag already exists!');
}
// Allow extension customisation.
$this->extend('validateMediaTag', $result);
return $result;
} | [
"public",
"function",
"validate",
"(",
")",
"{",
"$",
"result",
"=",
"parent",
"::",
"validate",
"(",
")",
";",
"// Confirm that the current tag has been given a title and doesn't already exist.",
"$",
"this",
"->",
"Title",
"=",
"strtolower",
"(",
"$",
"this",
"->"... | Confirm that the current tag is valid. | [
"Confirm",
"that",
"the",
"current",
"tag",
"is",
"valid",
"."
] | 0537ad9934f69a680cd20115269efed13e082abf | https://github.com/nglasl/silverstripe-mediawesome/blob/0537ad9934f69a680cd20115269efed13e082abf/src/objects/MediaTag.php#L46-L67 | train |
MetaModels/filter_fromto | src/FilterRule/FromTo.php | FromTo.setLowerBound | public function setLowerBound($value, $inclusive)
{
$this->lowerBound = $value;
$this->lowerInclusive = (bool) $inclusive;
return $this;
} | php | public function setLowerBound($value, $inclusive)
{
$this->lowerBound = $value;
$this->lowerInclusive = (bool) $inclusive;
return $this;
} | [
"public",
"function",
"setLowerBound",
"(",
"$",
"value",
",",
"$",
"inclusive",
")",
"{",
"$",
"this",
"->",
"lowerBound",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"lowerInclusive",
"=",
"(",
"bool",
")",
"$",
"inclusive",
";",
"return",
"$",
"this"... | Mark the lower bound of the range to search.
@param mixed $value The value to use for the lower bound.
@param bool $inclusive Flag if the value shall also be included in the result.
@return FromTo | [
"Mark",
"the",
"lower",
"bound",
"of",
"the",
"range",
"to",
"search",
"."
] | 0d65f4b14f3eceab9e022c79388fbced5e47ed9d | https://github.com/MetaModels/filter_fromto/blob/0d65f4b14f3eceab9e022c79388fbced5e47ed9d/src/FilterRule/FromTo.php#L90-L96 | train |
MetaModels/filter_fromto | src/FilterRule/FromTo.php | FromTo.setUpperBound | public function setUpperBound($value, $inclusive)
{
$this->upperBound = $value;
$this->upperInclusive = (bool) $inclusive;
return $this;
} | php | public function setUpperBound($value, $inclusive)
{
$this->upperBound = $value;
$this->upperInclusive = (bool) $inclusive;
return $this;
} | [
"public",
"function",
"setUpperBound",
"(",
"$",
"value",
",",
"$",
"inclusive",
")",
"{",
"$",
"this",
"->",
"upperBound",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"upperInclusive",
"=",
"(",
"bool",
")",
"$",
"inclusive",
";",
"return",
"$",
"this"... | Mark the upper bound of the range to search.
@param mixed $value The value to use for the upper bound.
@param bool $inclusive Flag if the value shall also be included in the result.
@return FromTo | [
"Mark",
"the",
"upper",
"bound",
"of",
"the",
"range",
"to",
"search",
"."
] | 0d65f4b14f3eceab9e022c79388fbced5e47ed9d | https://github.com/MetaModels/filter_fromto/blob/0d65f4b14f3eceab9e022c79388fbced5e47ed9d/src/FilterRule/FromTo.php#L127-L133 | train |
MetaModels/filter_fromto | src/FilterRule/FromTo.php | FromTo.evaluateLowerBound | protected function evaluateLowerBound()
{
if (empty($this->lowerBound)) {
return null;
}
return $this->executeRule(
new GreaterThan($this->getAttribute(), $this->getLowerBound(), $this->isLowerInclusive())
);
} | php | protected function evaluateLowerBound()
{
if (empty($this->lowerBound)) {
return null;
}
return $this->executeRule(
new GreaterThan($this->getAttribute(), $this->getLowerBound(), $this->isLowerInclusive())
);
} | [
"protected",
"function",
"evaluateLowerBound",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"lowerBound",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"executeRule",
"(",
"new",
"GreaterThan",
"(",
"$",
"this",
... | Evaluate the lower bounding of the range.
@return null|\string[] | [
"Evaluate",
"the",
"lower",
"bounding",
"of",
"the",
"range",
"."
] | 0d65f4b14f3eceab9e022c79388fbced5e47ed9d | https://github.com/MetaModels/filter_fromto/blob/0d65f4b14f3eceab9e022c79388fbced5e47ed9d/src/FilterRule/FromTo.php#L182-L191 | train |
MetaModels/filter_fromto | src/FilterRule/FromTo.php | FromTo.evaluateUpperBound | protected function evaluateUpperBound()
{
if (empty($this->upperBound)) {
return null;
}
return $this->executeRule(
new LessThan($this->getAttribute(), $this->getUpperBound(), $this->isUpperInclusive())
);
} | php | protected function evaluateUpperBound()
{
if (empty($this->upperBound)) {
return null;
}
return $this->executeRule(
new LessThan($this->getAttribute(), $this->getUpperBound(), $this->isUpperInclusive())
);
} | [
"protected",
"function",
"evaluateUpperBound",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"upperBound",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"executeRule",
"(",
"new",
"LessThan",
"(",
"$",
"this",
"->... | Evaluate the upper bounding of the range.
@return null|\string[] | [
"Evaluate",
"the",
"upper",
"bounding",
"of",
"the",
"range",
"."
] | 0d65f4b14f3eceab9e022c79388fbced5e47ed9d | https://github.com/MetaModels/filter_fromto/blob/0d65f4b14f3eceab9e022c79388fbced5e47ed9d/src/FilterRule/FromTo.php#L198-L207 | train |
MetaModels/filter_fromto | src/EventListener/FilterRangeDateRegexpListener.php | FilterRangeDateRegexpListener.onAddCustomRegexp | public static function onAddCustomRegexp($rgxp, $value, $widget)
{
if ('MetaModelsFilterRangeDateRgXp' !== $rgxp) {
return;
}
$format = $widget->dateformat;
if (!\preg_match('~^'. Date::getRegexp($format) .'$~i', $value)) {
$widget->addError(\sprintf($GLOBALS['TL_LANG']['ERR']['date'], Date::getInputFormat($format)));
} else {
// Validate the date (see https://github.com/contao/core/issues/5086)
try {
new Date($value, $format);
} catch (\OutOfBoundsException $e) {
$widget->addError(\sprintf($GLOBALS['TL_LANG']['ERR']['invalidDate'], $value));
}
}
} | php | public static function onAddCustomRegexp($rgxp, $value, $widget)
{
if ('MetaModelsFilterRangeDateRgXp' !== $rgxp) {
return;
}
$format = $widget->dateformat;
if (!\preg_match('~^'. Date::getRegexp($format) .'$~i', $value)) {
$widget->addError(\sprintf($GLOBALS['TL_LANG']['ERR']['date'], Date::getInputFormat($format)));
} else {
// Validate the date (see https://github.com/contao/core/issues/5086)
try {
new Date($value, $format);
} catch (\OutOfBoundsException $e) {
$widget->addError(\sprintf($GLOBALS['TL_LANG']['ERR']['invalidDate'], $value));
}
}
} | [
"public",
"static",
"function",
"onAddCustomRegexp",
"(",
"$",
"rgxp",
",",
"$",
"value",
",",
"$",
"widget",
")",
"{",
"if",
"(",
"'MetaModelsFilterRangeDateRgXp'",
"!==",
"$",
"rgxp",
")",
"{",
"return",
";",
"}",
"$",
"format",
"=",
"$",
"widget",
"->... | Process a custom date regexp on a widget.
@param string $rgxp The rgxp being evaluated.
@param string $value The value to check.
@param Widget $widget The widget to process.
@return void
@SuppressWarnings(PHPMD.Superglobals)
@SuppressWarnings(PHPMD.CamelCaseVariableName) | [
"Process",
"a",
"custom",
"date",
"regexp",
"on",
"a",
"widget",
"."
] | 0d65f4b14f3eceab9e022c79388fbced5e47ed9d | https://github.com/MetaModels/filter_fromto/blob/0d65f4b14f3eceab9e022c79388fbced5e47ed9d/src/EventListener/FilterRangeDateRegexpListener.php#L47-L64 | train |
MetaModels/filter_fromto | src/FilterSetting/AbstractFromTo.php | AbstractFromTo.getParameterValue | protected function getParameterValue($filterUrl)
{
$parameterName = $this->getParamName();
if (isset($filterUrl[$parameterName]) && !empty($filterUrl[$parameterName])) {
if (\is_array($filterUrl[$parameterName])) {
return \array_values($filterUrl[$parameterName]);
}
return \array_values(\explode(',', $filterUrl[$parameterName]));
}
return null;
} | php | protected function getParameterValue($filterUrl)
{
$parameterName = $this->getParamName();
if (isset($filterUrl[$parameterName]) && !empty($filterUrl[$parameterName])) {
if (\is_array($filterUrl[$parameterName])) {
return \array_values($filterUrl[$parameterName]);
}
return \array_values(\explode(',', $filterUrl[$parameterName]));
}
return null;
} | [
"protected",
"function",
"getParameterValue",
"(",
"$",
"filterUrl",
")",
"{",
"$",
"parameterName",
"=",
"$",
"this",
"->",
"getParamName",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"filterUrl",
"[",
"$",
"parameterName",
"]",
")",
"&&",
"!",
"empty"... | Retrieve the parameter value from the filter url.
@param array $filterUrl The filter url from which to extract the parameter.
@return null|string|array | [
"Retrieve",
"the",
"parameter",
"value",
"from",
"the",
"filter",
"url",
"."
] | 0d65f4b14f3eceab9e022c79388fbced5e47ed9d | https://github.com/MetaModels/filter_fromto/blob/0d65f4b14f3eceab9e022c79388fbced5e47ed9d/src/FilterSetting/AbstractFromTo.php#L84-L96 | train |
MetaModels/filter_fromto | src/FilterSetting/AbstractFromTo.php | AbstractFromTo.getReferencedAttributes | public function getReferencedAttributes()
{
$objAttribute = null;
if (!($this->get('attr_id')
&& ($objAttribute = $this->getMetaModel()->getAttributeById($this->get('attr_id'))))) {
return [];
}
return $objAttribute ? [$objAttribute->getColName()] : [];
} | php | public function getReferencedAttributes()
{
$objAttribute = null;
if (!($this->get('attr_id')
&& ($objAttribute = $this->getMetaModel()->getAttributeById($this->get('attr_id'))))) {
return [];
}
return $objAttribute ? [$objAttribute->getColName()] : [];
} | [
"public",
"function",
"getReferencedAttributes",
"(",
")",
"{",
"$",
"objAttribute",
"=",
"null",
";",
"if",
"(",
"!",
"(",
"$",
"this",
"->",
"get",
"(",
"'attr_id'",
")",
"&&",
"(",
"$",
"objAttribute",
"=",
"$",
"this",
"->",
"getMetaModel",
"(",
")... | Retrieve the attribute name that is referenced in this filter setting.
@return array | [
"Retrieve",
"the",
"attribute",
"name",
"that",
"is",
"referenced",
"in",
"this",
"filter",
"setting",
"."
] | 0d65f4b14f3eceab9e022c79388fbced5e47ed9d | https://github.com/MetaModels/filter_fromto/blob/0d65f4b14f3eceab9e022c79388fbced5e47ed9d/src/FilterSetting/AbstractFromTo.php#L103-L112 | train |
MetaModels/filter_fromto | src/FilterSetting/AbstractFromTo.php | AbstractFromTo.prepareWidgetOptions | protected function prepareWidgetOptions($arrIds, $objAttribute)
{
$arrOptions = $objAttribute->getFilterOptions(
($this->get('onlypossible') ? $arrIds : null),
(bool) $this->get('onlyused')
);
// Remove empty values from list.
foreach ($arrOptions as $mixKeyOption => $mixOption) {
// Remove html/php tags.
$mixOption = \strip_tags($mixOption);
$mixOption = \trim($mixOption);
if ($mixOption === '' || $mixOption === null) {
unset($arrOptions[$mixKeyOption]);
}
}
return $arrOptions;
} | php | protected function prepareWidgetOptions($arrIds, $objAttribute)
{
$arrOptions = $objAttribute->getFilterOptions(
($this->get('onlypossible') ? $arrIds : null),
(bool) $this->get('onlyused')
);
// Remove empty values from list.
foreach ($arrOptions as $mixKeyOption => $mixOption) {
// Remove html/php tags.
$mixOption = \strip_tags($mixOption);
$mixOption = \trim($mixOption);
if ($mixOption === '' || $mixOption === null) {
unset($arrOptions[$mixKeyOption]);
}
}
return $arrOptions;
} | [
"protected",
"function",
"prepareWidgetOptions",
"(",
"$",
"arrIds",
",",
"$",
"objAttribute",
")",
"{",
"$",
"arrOptions",
"=",
"$",
"objAttribute",
"->",
"getFilterOptions",
"(",
"(",
"$",
"this",
"->",
"get",
"(",
"'onlypossible'",
")",
"?",
"$",
"arrIds"... | Prepare options for the widget.
@param array $arrIds List of ids.
@param IAttribute $objAttribute The metamodel attribute.
@return array | [
"Prepare",
"options",
"for",
"the",
"widget",
"."
] | 0d65f4b14f3eceab9e022c79388fbced5e47ed9d | https://github.com/MetaModels/filter_fromto/blob/0d65f4b14f3eceab9e022c79388fbced5e47ed9d/src/FilterSetting/AbstractFromTo.php#L180-L199 | train |
MetaModels/filter_fromto | src/FilterSetting/AbstractFromTo.php | AbstractFromTo.prepareWidgetParamAndFilterUrl | protected function prepareWidgetParamAndFilterUrl($arrFilterUrl)
{
// Split up our param so the widgets can use it again.
$parameterName = $this->getParamName();
$privateFilterUrl = $arrFilterUrl;
$parameterValue = null;
// If we have a value, we have to explode it by double underscore to have a valid value which the active checks
// may cope with.
if (\array_key_exists($parameterName, $arrFilterUrl) && !empty($arrFilterUrl[$parameterName])) {
if (\is_array($arrFilterUrl[$parameterName])) {
$parameterValue = $arrFilterUrl[$parameterName];
} else {
$parameterValue = \explode(',', $arrFilterUrl[$parameterName], 2);
}
if ($parameterValue && ($parameterValue[0] || $parameterValue[1])) {
$privateFilterUrl[$parameterName] = $parameterValue;
return [$privateFilterUrl, $parameterValue];
} else {
// No values given, clear the array.
$parameterValue = null;
return [$privateFilterUrl, $parameterValue];
}
}
return [$privateFilterUrl, $parameterValue];
} | php | protected function prepareWidgetParamAndFilterUrl($arrFilterUrl)
{
// Split up our param so the widgets can use it again.
$parameterName = $this->getParamName();
$privateFilterUrl = $arrFilterUrl;
$parameterValue = null;
// If we have a value, we have to explode it by double underscore to have a valid value which the active checks
// may cope with.
if (\array_key_exists($parameterName, $arrFilterUrl) && !empty($arrFilterUrl[$parameterName])) {
if (\is_array($arrFilterUrl[$parameterName])) {
$parameterValue = $arrFilterUrl[$parameterName];
} else {
$parameterValue = \explode(',', $arrFilterUrl[$parameterName], 2);
}
if ($parameterValue && ($parameterValue[0] || $parameterValue[1])) {
$privateFilterUrl[$parameterName] = $parameterValue;
return [$privateFilterUrl, $parameterValue];
} else {
// No values given, clear the array.
$parameterValue = null;
return [$privateFilterUrl, $parameterValue];
}
}
return [$privateFilterUrl, $parameterValue];
} | [
"protected",
"function",
"prepareWidgetParamAndFilterUrl",
"(",
"$",
"arrFilterUrl",
")",
"{",
"// Split up our param so the widgets can use it again.",
"$",
"parameterName",
"=",
"$",
"this",
"->",
"getParamName",
"(",
")",
";",
"$",
"privateFilterUrl",
"=",
"$",
"arrF... | Prepare the widget Param and filter url.
@param array $arrFilterUrl The filter url.
@return array | [
"Prepare",
"the",
"widget",
"Param",
"and",
"filter",
"url",
"."
] | 0d65f4b14f3eceab9e022c79388fbced5e47ed9d | https://github.com/MetaModels/filter_fromto/blob/0d65f4b14f3eceab9e022c79388fbced5e47ed9d/src/FilterSetting/AbstractFromTo.php#L208-L237 | train |
MetaModels/filter_fromto | src/FilterSetting/AbstractFromTo.php | AbstractFromTo.formatEmpty | private function formatEmpty($value)
{
if (empty($value = \trim($value))) {
return $value;
}
return $this->formatValue($value);
} | php | private function formatEmpty($value)
{
if (empty($value = \trim($value))) {
return $value;
}
return $this->formatValue($value);
} | [
"private",
"function",
"formatEmpty",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"value",
"=",
"\\",
"trim",
"(",
"$",
"value",
")",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"return",
"$",
"this",
"->",
"formatValue",
"(",
... | Format the value but return empty if it is empty.
@param string $value The value to format.
@return bool|string | [
"Format",
"the",
"value",
"but",
"return",
"empty",
"if",
"it",
"is",
"empty",
"."
] | 0d65f4b14f3eceab9e022c79388fbced5e47ed9d | https://github.com/MetaModels/filter_fromto/blob/0d65f4b14f3eceab9e022c79388fbced5e47ed9d/src/FilterSetting/AbstractFromTo.php#L351-L358 | train |
MetaModels/filter_fromto | src/FilterSetting/AbstractFromTo.php | AbstractFromTo.createFromToRule | private function createFromToRule(IAttribute $attribute, $formattedValueZero, $formattedValueOne)
{
// If something went wrong return an empty list.
if ($formattedValueZero === false || $formattedValueOne === false) {
return new StaticIdList([]);
}
// Add rule to the filter.
$rule = $this->buildFromToRule($attribute);
if (null !== $formattedValueOne) {
$rule->setLowerBound($formattedValueZero, $this->get('moreequal'))
->setUpperBound($formattedValueOne, $this->get('lessequal'));
return $rule;
}
if ($this->get('fromfield')) {
$rule->setLowerBound($formattedValueZero, $this->get('moreequal'));
return $rule;
}
$rule->setUpperBound($formattedValueZero, $this->get('lessequal'));
return $rule;
} | php | private function createFromToRule(IAttribute $attribute, $formattedValueZero, $formattedValueOne)
{
// If something went wrong return an empty list.
if ($formattedValueZero === false || $formattedValueOne === false) {
return new StaticIdList([]);
}
// Add rule to the filter.
$rule = $this->buildFromToRule($attribute);
if (null !== $formattedValueOne) {
$rule->setLowerBound($formattedValueZero, $this->get('moreequal'))
->setUpperBound($formattedValueOne, $this->get('lessequal'));
return $rule;
}
if ($this->get('fromfield')) {
$rule->setLowerBound($formattedValueZero, $this->get('moreequal'));
return $rule;
}
$rule->setUpperBound($formattedValueZero, $this->get('lessequal'));
return $rule;
} | [
"private",
"function",
"createFromToRule",
"(",
"IAttribute",
"$",
"attribute",
",",
"$",
"formattedValueZero",
",",
"$",
"formattedValueOne",
")",
"{",
"// If something went wrong return an empty list.",
"if",
"(",
"$",
"formattedValueZero",
"===",
"false",
"||",
"$",
... | Create and populate a rule instance.
@param IAttribute $attribute The attribute to filter on.
@param string $formattedValueZero The formatted first value.
@param string $formattedValueOne The formatted second value.
@return \MetaModels\FilterFromToBundle\FilterRule\FromTo|StaticIdList | [
"Create",
"and",
"populate",
"a",
"rule",
"instance",
"."
] | 0d65f4b14f3eceab9e022c79388fbced5e47ed9d | https://github.com/MetaModels/filter_fromto/blob/0d65f4b14f3eceab9e022c79388fbced5e47ed9d/src/FilterSetting/AbstractFromTo.php#L369-L391 | train |
nglasl/silverstripe-mediawesome | src/controllers/MediaHolderController.php | MediaHolderController.index | public function index() {
// Use a custom media type holder template if one exists.
$type = $this->data()->MediaType();
$templates = array();
if($type->exists()) {
$templates[] = 'MediaHolder_' . str_replace(' ', '', $type->Title);
}
$templates[] = 'MediaHolder';
$templates[] = 'Page';
$this->extend('updateTemplates', $templates);
return $this->renderWith($templates);
} | php | public function index() {
// Use a custom media type holder template if one exists.
$type = $this->data()->MediaType();
$templates = array();
if($type->exists()) {
$templates[] = 'MediaHolder_' . str_replace(' ', '', $type->Title);
}
$templates[] = 'MediaHolder';
$templates[] = 'Page';
$this->extend('updateTemplates', $templates);
return $this->renderWith($templates);
} | [
"public",
"function",
"index",
"(",
")",
"{",
"// Use a custom media type holder template if one exists.",
"$",
"type",
"=",
"$",
"this",
"->",
"data",
"(",
")",
"->",
"MediaType",
"(",
")",
";",
"$",
"templates",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$... | Determine the template for this media holder. | [
"Determine",
"the",
"template",
"for",
"this",
"media",
"holder",
"."
] | 0537ad9934f69a680cd20115269efed13e082abf | https://github.com/nglasl/silverstripe-mediawesome/blob/0537ad9934f69a680cd20115269efed13e082abf/src/controllers/MediaHolderController.php#L36-L49 | train |
nglasl/silverstripe-mediawesome | src/controllers/MediaHolderController.php | MediaHolderController.resolveURL | private function resolveURL() {
// Retrieve the current request URL segments.
$request = $this->getRequest();
$URL = $request->getURL();
$holder = substr($URL, 0, strpos($URL, '/'));
$page = substr($URL, strrpos($URL, '/') + 1);
// Determine whether a media page child once existed.
$resolution = self::find_old_page(array(
$holder,
$page
));
$comparison = trim($resolution, '/');
// Make sure the current request URL doesn't match the resolution.
if($resolution && ($page !== substr($comparison, strrpos($comparison, '/') + 1))) {
// Retrieve the current request parameters.
$parameters = $request->getVars();
unset($parameters['url']);
// Appropriately redirect towards the updated media page URL.
$response = new HTTPResponse();
return $response->redirect(self::join_links($resolution, !empty($parameters) ? '?' . http_build_query($parameters) : null), 301);
}
else {
// The media page child doesn't resolve.
return null;
}
} | php | private function resolveURL() {
// Retrieve the current request URL segments.
$request = $this->getRequest();
$URL = $request->getURL();
$holder = substr($URL, 0, strpos($URL, '/'));
$page = substr($URL, strrpos($URL, '/') + 1);
// Determine whether a media page child once existed.
$resolution = self::find_old_page(array(
$holder,
$page
));
$comparison = trim($resolution, '/');
// Make sure the current request URL doesn't match the resolution.
if($resolution && ($page !== substr($comparison, strrpos($comparison, '/') + 1))) {
// Retrieve the current request parameters.
$parameters = $request->getVars();
unset($parameters['url']);
// Appropriately redirect towards the updated media page URL.
$response = new HTTPResponse();
return $response->redirect(self::join_links($resolution, !empty($parameters) ? '?' . http_build_query($parameters) : null), 301);
}
else {
// The media page child doesn't resolve.
return null;
}
} | [
"private",
"function",
"resolveURL",
"(",
")",
"{",
"// Retrieve the current request URL segments.",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"$",
"URL",
"=",
"$",
"request",
"->",
"getURL",
"(",
")",
";",
"$",
"holder",
"=",
"s... | Determine whether a media page child once existed for the current request, and redirect appropriately.
@return http response | [
"Determine",
"whether",
"a",
"media",
"page",
"child",
"once",
"existed",
"for",
"the",
"current",
"request",
"and",
"redirect",
"appropriately",
"."
] | 0537ad9934f69a680cd20115269efed13e082abf | https://github.com/nglasl/silverstripe-mediawesome/blob/0537ad9934f69a680cd20115269efed13e082abf/src/controllers/MediaHolderController.php#L353-L390 | train |
nglasl/silverstripe-mediawesome | src/controllers/MediaHolderController.php | MediaHolderController.getDateFilterForm | public function getDateFilterForm() {
// Display a form that allows filtering from a specified date.
$children = MediaPage::get()->filter('ParentID', $this->data()->ID);
$form = Form::create(
$this,
'getDateFilterForm',
FieldList::create(
$date = DateField::create(
'from',
'From'
)->setMinDate($children->min('Date'))->setMaxDate($children->max('Date')),
HiddenField::create(
'category'
),
HiddenField::create(
'tag'
)
),
FieldList::create(
FormAction::create(
'dateFilter',
'Filter'
),
FormAction::create(
'clearFilters',
'Clear'
)
)
);
$form->setFormMethod('get');
// Remove validation if clear has been triggered.
$request = $this->getRequest();
if($request->getVar('action_clearFilters')) {
$form->unsetValidator();
}
// Allow extension customisation.
$this->extend('updateFilterForm', $form);
// Display existing request filters.
$form->loadDataFrom($request->getVars());
return $form;
} | php | public function getDateFilterForm() {
// Display a form that allows filtering from a specified date.
$children = MediaPage::get()->filter('ParentID', $this->data()->ID);
$form = Form::create(
$this,
'getDateFilterForm',
FieldList::create(
$date = DateField::create(
'from',
'From'
)->setMinDate($children->min('Date'))->setMaxDate($children->max('Date')),
HiddenField::create(
'category'
),
HiddenField::create(
'tag'
)
),
FieldList::create(
FormAction::create(
'dateFilter',
'Filter'
),
FormAction::create(
'clearFilters',
'Clear'
)
)
);
$form->setFormMethod('get');
// Remove validation if clear has been triggered.
$request = $this->getRequest();
if($request->getVar('action_clearFilters')) {
$form->unsetValidator();
}
// Allow extension customisation.
$this->extend('updateFilterForm', $form);
// Display existing request filters.
$form->loadDataFrom($request->getVars());
return $form;
} | [
"public",
"function",
"getDateFilterForm",
"(",
")",
"{",
"// Display a form that allows filtering from a specified date.",
"$",
"children",
"=",
"MediaPage",
"::",
"get",
"(",
")",
"->",
"filter",
"(",
"'ParentID'",
",",
"$",
"this",
"->",
"data",
"(",
")",
"->",... | Retrieve a simple date filter form.
@return form | [
"Retrieve",
"a",
"simple",
"date",
"filter",
"form",
"."
] | 0537ad9934f69a680cd20115269efed13e082abf | https://github.com/nglasl/silverstripe-mediawesome/blob/0537ad9934f69a680cd20115269efed13e082abf/src/controllers/MediaHolderController.php#L398-L446 | train |
nglasl/silverstripe-mediawesome | src/controllers/MediaHolderController.php | MediaHolderController.dateFilter | public function dateFilter() {
// Apply the from date filter.
$request = $this->getRequest();
$from = $request->getVar('from');
$link = $this->Link();
$separator = '?';
if($from) {
// Determine the formatted URL to represent the request filter.
$date = DBDate::create()->setValue($from);
$link .= $date->Format('y/MM/dd/');
}
// Preserve the category/tag filters if they exist.
$category = $request->getVar('category');
$tag = $request->getVar('tag');
if($category) {
$link = HTTP::setGetVar('category', $category, $link, $separator);
$separator = '&';
}
if($tag) {
$link = HTTP::setGetVar('tag', $tag, $link, $separator);
}
// Allow extension customisation.
$this->extend('updateFilter', $link);
// Request the filtered paginated children.
return $this->redirect($link);
} | php | public function dateFilter() {
// Apply the from date filter.
$request = $this->getRequest();
$from = $request->getVar('from');
$link = $this->Link();
$separator = '?';
if($from) {
// Determine the formatted URL to represent the request filter.
$date = DBDate::create()->setValue($from);
$link .= $date->Format('y/MM/dd/');
}
// Preserve the category/tag filters if they exist.
$category = $request->getVar('category');
$tag = $request->getVar('tag');
if($category) {
$link = HTTP::setGetVar('category', $category, $link, $separator);
$separator = '&';
}
if($tag) {
$link = HTTP::setGetVar('tag', $tag, $link, $separator);
}
// Allow extension customisation.
$this->extend('updateFilter', $link);
// Request the filtered paginated children.
return $this->redirect($link);
} | [
"public",
"function",
"dateFilter",
"(",
")",
"{",
"// Apply the from date filter.",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"$",
"from",
"=",
"$",
"request",
"->",
"getVar",
"(",
"'from'",
")",
";",
"$",
"link",
"=",
"$",
... | Request media page children from the filtered date. | [
"Request",
"media",
"page",
"children",
"from",
"the",
"filtered",
"date",
"."
] | 0537ad9934f69a680cd20115269efed13e082abf | https://github.com/nglasl/silverstripe-mediawesome/blob/0537ad9934f69a680cd20115269efed13e082abf/src/controllers/MediaHolderController.php#L452-L487 | train |
nglasl/silverstripe-mediawesome | src/objects/MediaAttribute.php | MediaAttribute.checkPermissions | public function checkPermissions($member = null) {
// Retrieve the current site configuration permissions for customisation of media.
$configuration = SiteConfig::current_site_config();
return Permission::check($configuration->MediaPermission, 'any', $member);
} | php | public function checkPermissions($member = null) {
// Retrieve the current site configuration permissions for customisation of media.
$configuration = SiteConfig::current_site_config();
return Permission::check($configuration->MediaPermission, 'any', $member);
} | [
"public",
"function",
"checkPermissions",
"(",
"$",
"member",
"=",
"null",
")",
"{",
"// Retrieve the current site configuration permissions for customisation of media.",
"$",
"configuration",
"=",
"SiteConfig",
"::",
"current_site_config",
"(",
")",
";",
"return",
"Permiss... | Determine access for the current CMS user from the site configuration permissions.
@parameter <{CURRENT_MEMBER}> member
@return boolean | [
"Determine",
"access",
"for",
"the",
"current",
"CMS",
"user",
"from",
"the",
"site",
"configuration",
"permissions",
"."
] | 0537ad9934f69a680cd20115269efed13e082abf | https://github.com/nglasl/silverstripe-mediawesome/blob/0537ad9934f69a680cd20115269efed13e082abf/src/objects/MediaAttribute.php#L74-L80 | train |
nglasl/silverstripe-mediawesome | src/objects/MediaAttribute.php | MediaAttribute.validate | public function validate() {
$result = parent::validate();
// Confirm that the current attribute has been given a title.
if($result->isValid() && !$this->Title) {
$result->addError('"Title" required!');
}
// Allow extension customisation.
$this->extend('validateMediaAttribute', $result);
return $result;
} | php | public function validate() {
$result = parent::validate();
// Confirm that the current attribute has been given a title.
if($result->isValid() && !$this->Title) {
$result->addError('"Title" required!');
}
// Allow extension customisation.
$this->extend('validateMediaAttribute', $result);
return $result;
} | [
"public",
"function",
"validate",
"(",
")",
"{",
"$",
"result",
"=",
"parent",
"::",
"validate",
"(",
")",
";",
"// Confirm that the current attribute has been given a title.",
"if",
"(",
"$",
"result",
"->",
"isValid",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
... | Confirm that the current attribute is valid. | [
"Confirm",
"that",
"the",
"current",
"attribute",
"is",
"valid",
"."
] | 0537ad9934f69a680cd20115269efed13e082abf | https://github.com/nglasl/silverstripe-mediawesome/blob/0537ad9934f69a680cd20115269efed13e082abf/src/objects/MediaAttribute.php#L99-L113 | train |
jonnitto/Jonnitto.PrettyEmbedYoutube | Classes/Eel/YoutubeHelper.php | YoutubeHelper.parseID | function parseID($url) {
if (!$url) {
return false;
}
$regs = array();
if (preg_match('/(?<=(?:(?<=v)|(?<=i)|(?<=list))=)[a-zA-Z0-9-]+(?=&)|(?<=(?:(?<=v)|(?<=i)|(?<=list))\/)[^&\n]+|(?<=embed\/)[^"&\n]+|(?<=(?:(?<=v)|(?<=i)|(?<=list))=)[^&\n]+|(?<=youtu.be\/)[^&\n]+/im', $url, $regs)) {
return $regs[0];
}
return $url;
} | php | function parseID($url) {
if (!$url) {
return false;
}
$regs = array();
if (preg_match('/(?<=(?:(?<=v)|(?<=i)|(?<=list))=)[a-zA-Z0-9-]+(?=&)|(?<=(?:(?<=v)|(?<=i)|(?<=list))\/)[^&\n]+|(?<=embed\/)[^"&\n]+|(?<=(?:(?<=v)|(?<=i)|(?<=list))=)[^&\n]+|(?<=youtu.be\/)[^&\n]+/im', $url, $regs)) {
return $regs[0];
}
return $url;
} | [
"function",
"parseID",
"(",
"$",
"url",
")",
"{",
"if",
"(",
"!",
"$",
"url",
")",
"{",
"return",
"false",
";",
"}",
"$",
"regs",
"=",
"array",
"(",
")",
";",
"if",
"(",
"preg_match",
"(",
"'/(?<=(?:(?<=v)|(?<=i)|(?<=list))=)[a-zA-Z0-9-]+(?=&)|(?<=(?:(?<=v)|... | Get Youtube video id from url
@param string $url The URL
@return string the video id extracted from url | [
"Get",
"Youtube",
"video",
"id",
"from",
"url"
] | 2df6d1ced7fce9fd1cea327bc6cb617a25e714d0 | https://github.com/jonnitto/Jonnitto.PrettyEmbedYoutube/blob/2df6d1ced7fce9fd1cea327bc6cb617a25e714d0/Classes/Eel/YoutubeHelper.php#L23-L32 | train |
jonnitto/Jonnitto.PrettyEmbedYoutube | Classes/Eel/YoutubeHelper.php | YoutubeHelper.data | function data($id)
{
if (!$id) {
return false;
}
$data = json_decode(@file_get_contents('https://www.youtube.com/oembed?url=https%3A//youtube.com/watch%3Fv%3D' . $id));
if (!$data) {
return false;
}
return $data;
} | php | function data($id)
{
if (!$id) {
return false;
}
$data = json_decode(@file_get_contents('https://www.youtube.com/oembed?url=https%3A//youtube.com/watch%3Fv%3D' . $id));
if (!$data) {
return false;
}
return $data;
} | [
"function",
"data",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"!",
"$",
"id",
")",
"{",
"return",
"false",
";",
"}",
"$",
"data",
"=",
"json_decode",
"(",
"@",
"file_get_contents",
"(",
"'https://www.youtube.com/oembed?url=https%3A//youtube.com/watch%3Fv%3D'",
".",
... | Grab the data of a publicly embeddable video hosted on youtube
@param string $id The "id" of a video
@return mixed The data or false if there's an error | [
"Grab",
"the",
"data",
"of",
"a",
"publicly",
"embeddable",
"video",
"hosted",
"on",
"youtube"
] | 2df6d1ced7fce9fd1cea327bc6cb617a25e714d0 | https://github.com/jonnitto/Jonnitto.PrettyEmbedYoutube/blob/2df6d1ced7fce9fd1cea327bc6cb617a25e714d0/Classes/Eel/YoutubeHelper.php#L39-L49 | train |
jonnitto/Jonnitto.PrettyEmbedYoutube | Classes/Eel/YoutubeHelper.php | YoutubeHelper.title | function title($id) {
$data = $this->data($id);
if (!$data) {
return false;
}
return $data->title;
} | php | function title($id) {
$data = $this->data($id);
if (!$data) {
return false;
}
return $data->title;
} | [
"function",
"title",
"(",
"$",
"id",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"data",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"data",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"data",
"->",
"title",
";",
"}"
] | Grab the title of a publicly embeddable video hosted on youtube
@param string $id The "id" of a video
@return mixed The title or false if there's an error | [
"Grab",
"the",
"title",
"of",
"a",
"publicly",
"embeddable",
"video",
"hosted",
"on",
"youtube"
] | 2df6d1ced7fce9fd1cea327bc6cb617a25e714d0 | https://github.com/jonnitto/Jonnitto.PrettyEmbedYoutube/blob/2df6d1ced7fce9fd1cea327bc6cb617a25e714d0/Classes/Eel/YoutubeHelper.php#L56-L62 | train |
nglasl/silverstripe-mediawesome | src/extensions/SiteConfigMediaPermissionExtension.php | SiteConfigMediaPermissionExtension.updateCMSFields | public function updateCMSFields(FieldList $fields) {
$permissions = array(
'ADMIN' => 'Administrators and developers',
'SITETREE_EDIT_ALL' => 'Content authors'
);
// Confirm that the current CMS user has permission.
if(Permission::check('EDIT_SITECONFIG') === false) {
$fields->addFieldToTab('Root.Access', $options = ReadonlyField::create(
'Media',
'Who can customise media?',
$permissions[$this->owner->MediaPermission]
));
}
else {
// Display the permission configuration.
$fields->addFieldToTab('Root.Access', $options = OptionsetField::create(
'MediaPermission',
'Who can customise media?',
$permissions
));
}
// Allow extension customisation.
$this->owner->extend('updateSiteConfigMediaPermissionExtensionCMSFields', $fields);
} | php | public function updateCMSFields(FieldList $fields) {
$permissions = array(
'ADMIN' => 'Administrators and developers',
'SITETREE_EDIT_ALL' => 'Content authors'
);
// Confirm that the current CMS user has permission.
if(Permission::check('EDIT_SITECONFIG') === false) {
$fields->addFieldToTab('Root.Access', $options = ReadonlyField::create(
'Media',
'Who can customise media?',
$permissions[$this->owner->MediaPermission]
));
}
else {
// Display the permission configuration.
$fields->addFieldToTab('Root.Access', $options = OptionsetField::create(
'MediaPermission',
'Who can customise media?',
$permissions
));
}
// Allow extension customisation.
$this->owner->extend('updateSiteConfigMediaPermissionExtensionCMSFields', $fields);
} | [
"public",
"function",
"updateCMSFields",
"(",
"FieldList",
"$",
"fields",
")",
"{",
"$",
"permissions",
"=",
"array",
"(",
"'ADMIN'",
"=>",
"'Administrators and developers'",
",",
"'SITETREE_EDIT_ALL'",
"=>",
"'Content authors'",
")",
";",
"// Confirm that the current C... | Allow permission configuration for customisation of media. | [
"Allow",
"permission",
"configuration",
"for",
"customisation",
"of",
"media",
"."
] | 0537ad9934f69a680cd20115269efed13e082abf | https://github.com/nglasl/silverstripe-mediawesome/blob/0537ad9934f69a680cd20115269efed13e082abf/src/extensions/SiteConfigMediaPermissionExtension.php#L30-L60 | train |
MetaModels/filter_fromto | src/FilterRule/FromToDate.php | FromToDate.runSimpleQuery | private function runSimpleQuery($operation, $value)
{
$attribute = $this->getAttribute();
if (!$attribute instanceof ISimple) {
throw new \RuntimeException('Filtering for time ranges is only possible on simple attributes.');
}
return $this->executeRule(new SimpleQuery(
\sprintf(
'SELECT id FROM %s WHERE TIME(FROM_UNIXTIME(%s)) %s ?)',
$attribute->getMetaModel()->getTableName(),
$attribute->getColName(),
$operation
),
[$value],
'id',
$this->connection
));
} | php | private function runSimpleQuery($operation, $value)
{
$attribute = $this->getAttribute();
if (!$attribute instanceof ISimple) {
throw new \RuntimeException('Filtering for time ranges is only possible on simple attributes.');
}
return $this->executeRule(new SimpleQuery(
\sprintf(
'SELECT id FROM %s WHERE TIME(FROM_UNIXTIME(%s)) %s ?)',
$attribute->getMetaModel()->getTableName(),
$attribute->getColName(),
$operation
),
[$value],
'id',
$this->connection
));
} | [
"private",
"function",
"runSimpleQuery",
"(",
"$",
"operation",
",",
"$",
"value",
")",
"{",
"$",
"attribute",
"=",
"$",
"this",
"->",
"getAttribute",
"(",
")",
";",
"if",
"(",
"!",
"$",
"attribute",
"instanceof",
"ISimple",
")",
"{",
"throw",
"new",
"... | Run a simple query against the attribute when using time only filtering.
@param string $operation The mathematical operation to use for evaluating.
@param string $value The value to match against.
@return array|null
@throws \RuntimeException When the attribute is not a simple one. | [
"Run",
"a",
"simple",
"query",
"against",
"the",
"attribute",
"when",
"using",
"time",
"only",
"filtering",
"."
] | 0d65f4b14f3eceab9e022c79388fbced5e47ed9d | https://github.com/MetaModels/filter_fromto/blob/0d65f4b14f3eceab9e022c79388fbced5e47ed9d/src/FilterRule/FromToDate.php#L99-L118 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.