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 |
---|---|---|---|---|---|---|---|---|---|---|---|
silverstripe/silverstripe-framework | src/ORM/DataQuery.php | DataQuery.initialiseQuery | protected function initialiseQuery()
{
// Join on base table and let lazy loading join subtables
$baseClass = DataObject::getSchema()->baseDataClass($this->dataClass());
if (!$baseClass) {
throw new InvalidArgumentException("DataQuery::create() Can't find data classes for '{$this->dataClass}'");
}
// Build our intial query
$this->query = new SQLSelect(array());
$this->query->setDistinct(true);
if ($sort = singleton($this->dataClass)->config()->get('default_sort')) {
$this->sort($sort);
}
$baseTable = DataObject::getSchema()->tableName($baseClass);
$this->query->setFrom("\"{$baseTable}\"");
$obj = Injector::inst()->get($baseClass);
$obj->extend('augmentDataQueryCreation', $this->query, $this);
} | php | protected function initialiseQuery()
{
// Join on base table and let lazy loading join subtables
$baseClass = DataObject::getSchema()->baseDataClass($this->dataClass());
if (!$baseClass) {
throw new InvalidArgumentException("DataQuery::create() Can't find data classes for '{$this->dataClass}'");
}
// Build our intial query
$this->query = new SQLSelect(array());
$this->query->setDistinct(true);
if ($sort = singleton($this->dataClass)->config()->get('default_sort')) {
$this->sort($sort);
}
$baseTable = DataObject::getSchema()->tableName($baseClass);
$this->query->setFrom("\"{$baseTable}\"");
$obj = Injector::inst()->get($baseClass);
$obj->extend('augmentDataQueryCreation', $this->query, $this);
} | [
"protected",
"function",
"initialiseQuery",
"(",
")",
"{",
"// Join on base table and let lazy loading join subtables",
"$",
"baseClass",
"=",
"DataObject",
"::",
"getSchema",
"(",
")",
"->",
"baseDataClass",
"(",
"$",
"this",
"->",
"dataClass",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"baseClass",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"DataQuery::create() Can't find data classes for '{$this->dataClass}'\"",
")",
";",
"}",
"// Build our intial query",
"$",
"this",
"->",
"query",
"=",
"new",
"SQLSelect",
"(",
"array",
"(",
")",
")",
";",
"$",
"this",
"->",
"query",
"->",
"setDistinct",
"(",
"true",
")",
";",
"if",
"(",
"$",
"sort",
"=",
"singleton",
"(",
"$",
"this",
"->",
"dataClass",
")",
"->",
"config",
"(",
")",
"->",
"get",
"(",
"'default_sort'",
")",
")",
"{",
"$",
"this",
"->",
"sort",
"(",
"$",
"sort",
")",
";",
"}",
"$",
"baseTable",
"=",
"DataObject",
"::",
"getSchema",
"(",
")",
"->",
"tableName",
"(",
"$",
"baseClass",
")",
";",
"$",
"this",
"->",
"query",
"->",
"setFrom",
"(",
"\"\\\"{$baseTable}\\\"\"",
")",
";",
"$",
"obj",
"=",
"Injector",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"$",
"baseClass",
")",
";",
"$",
"obj",
"->",
"extend",
"(",
"'augmentDataQueryCreation'",
",",
"$",
"this",
"->",
"query",
",",
"$",
"this",
")",
";",
"}"
]
| Set up the simplest initial query | [
"Set",
"up",
"the",
"simplest",
"initial",
"query"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataQuery.php#L162-L183 | train |
silverstripe/silverstripe-framework | src/ORM/DataQuery.php | DataQuery.ensureSelectContainsOrderbyColumns | protected function ensureSelectContainsOrderbyColumns($query, $originalSelect = array())
{
if ($orderby = $query->getOrderBy()) {
$newOrderby = array();
$i = 0;
foreach ($orderby as $k => $dir) {
$newOrderby[$k] = $dir;
// don't touch functions in the ORDER BY or public function calls
// selected as fields
if (strpos($k, '(') !== false) {
continue;
}
$col = str_replace('"', '', trim($k));
$parts = explode('.', $col);
// Pull through SortColumn references from the originalSelect variables
if (preg_match('/_SortColumn/', $col)) {
if (isset($originalSelect[$col])) {
$query->selectField($originalSelect[$col], $col);
}
continue;
}
if (count($parts) == 1) {
// Get expression for sort value
$qualCol = "\"{$parts[0]}\"";
$table = DataObject::getSchema()->tableForField($this->dataClass(), $parts[0]);
if ($table) {
$qualCol = "\"{$table}\".{$qualCol}";
}
// remove original sort
unset($newOrderby[$k]);
// add new columns sort
$newOrderby[$qualCol] = $dir;
// To-do: Remove this if block once SQLSelect::$select has been refactored to store getSelect()
// format internally; then this check can be part of selectField()
$selects = $query->getSelect();
if (!isset($selects[$col]) && !in_array($qualCol, $selects)) {
$query->selectField($qualCol);
}
} else {
$qualCol = '"' . implode('"."', $parts) . '"';
if (!in_array($qualCol, $query->getSelect())) {
unset($newOrderby[$k]);
$newOrderby["\"_SortColumn$i\""] = $dir;
$query->selectField($qualCol, "_SortColumn$i");
$i++;
}
}
}
$query->setOrderBy($newOrderby);
}
} | php | protected function ensureSelectContainsOrderbyColumns($query, $originalSelect = array())
{
if ($orderby = $query->getOrderBy()) {
$newOrderby = array();
$i = 0;
foreach ($orderby as $k => $dir) {
$newOrderby[$k] = $dir;
// don't touch functions in the ORDER BY or public function calls
// selected as fields
if (strpos($k, '(') !== false) {
continue;
}
$col = str_replace('"', '', trim($k));
$parts = explode('.', $col);
// Pull through SortColumn references from the originalSelect variables
if (preg_match('/_SortColumn/', $col)) {
if (isset($originalSelect[$col])) {
$query->selectField($originalSelect[$col], $col);
}
continue;
}
if (count($parts) == 1) {
// Get expression for sort value
$qualCol = "\"{$parts[0]}\"";
$table = DataObject::getSchema()->tableForField($this->dataClass(), $parts[0]);
if ($table) {
$qualCol = "\"{$table}\".{$qualCol}";
}
// remove original sort
unset($newOrderby[$k]);
// add new columns sort
$newOrderby[$qualCol] = $dir;
// To-do: Remove this if block once SQLSelect::$select has been refactored to store getSelect()
// format internally; then this check can be part of selectField()
$selects = $query->getSelect();
if (!isset($selects[$col]) && !in_array($qualCol, $selects)) {
$query->selectField($qualCol);
}
} else {
$qualCol = '"' . implode('"."', $parts) . '"';
if (!in_array($qualCol, $query->getSelect())) {
unset($newOrderby[$k]);
$newOrderby["\"_SortColumn$i\""] = $dir;
$query->selectField($qualCol, "_SortColumn$i");
$i++;
}
}
}
$query->setOrderBy($newOrderby);
}
} | [
"protected",
"function",
"ensureSelectContainsOrderbyColumns",
"(",
"$",
"query",
",",
"$",
"originalSelect",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"$",
"orderby",
"=",
"$",
"query",
"->",
"getOrderBy",
"(",
")",
")",
"{",
"$",
"newOrderby",
"=",
"array",
"(",
")",
";",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"orderby",
"as",
"$",
"k",
"=>",
"$",
"dir",
")",
"{",
"$",
"newOrderby",
"[",
"$",
"k",
"]",
"=",
"$",
"dir",
";",
"// don't touch functions in the ORDER BY or public function calls",
"// selected as fields",
"if",
"(",
"strpos",
"(",
"$",
"k",
",",
"'('",
")",
"!==",
"false",
")",
"{",
"continue",
";",
"}",
"$",
"col",
"=",
"str_replace",
"(",
"'\"'",
",",
"''",
",",
"trim",
"(",
"$",
"k",
")",
")",
";",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"col",
")",
";",
"// Pull through SortColumn references from the originalSelect variables",
"if",
"(",
"preg_match",
"(",
"'/_SortColumn/'",
",",
"$",
"col",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"originalSelect",
"[",
"$",
"col",
"]",
")",
")",
"{",
"$",
"query",
"->",
"selectField",
"(",
"$",
"originalSelect",
"[",
"$",
"col",
"]",
",",
"$",
"col",
")",
";",
"}",
"continue",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
"==",
"1",
")",
"{",
"// Get expression for sort value",
"$",
"qualCol",
"=",
"\"\\\"{$parts[0]}\\\"\"",
";",
"$",
"table",
"=",
"DataObject",
"::",
"getSchema",
"(",
")",
"->",
"tableForField",
"(",
"$",
"this",
"->",
"dataClass",
"(",
")",
",",
"$",
"parts",
"[",
"0",
"]",
")",
";",
"if",
"(",
"$",
"table",
")",
"{",
"$",
"qualCol",
"=",
"\"\\\"{$table}\\\".{$qualCol}\"",
";",
"}",
"// remove original sort",
"unset",
"(",
"$",
"newOrderby",
"[",
"$",
"k",
"]",
")",
";",
"// add new columns sort",
"$",
"newOrderby",
"[",
"$",
"qualCol",
"]",
"=",
"$",
"dir",
";",
"// To-do: Remove this if block once SQLSelect::$select has been refactored to store getSelect()",
"// format internally; then this check can be part of selectField()",
"$",
"selects",
"=",
"$",
"query",
"->",
"getSelect",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"selects",
"[",
"$",
"col",
"]",
")",
"&&",
"!",
"in_array",
"(",
"$",
"qualCol",
",",
"$",
"selects",
")",
")",
"{",
"$",
"query",
"->",
"selectField",
"(",
"$",
"qualCol",
")",
";",
"}",
"}",
"else",
"{",
"$",
"qualCol",
"=",
"'\"'",
".",
"implode",
"(",
"'\".\"'",
",",
"$",
"parts",
")",
".",
"'\"'",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"qualCol",
",",
"$",
"query",
"->",
"getSelect",
"(",
")",
")",
")",
"{",
"unset",
"(",
"$",
"newOrderby",
"[",
"$",
"k",
"]",
")",
";",
"$",
"newOrderby",
"[",
"\"\\\"_SortColumn$i\\\"\"",
"]",
"=",
"$",
"dir",
";",
"$",
"query",
"->",
"selectField",
"(",
"$",
"qualCol",
",",
"\"_SortColumn$i\"",
")",
";",
"$",
"i",
"++",
";",
"}",
"}",
"}",
"$",
"query",
"->",
"setOrderBy",
"(",
"$",
"newOrderby",
")",
";",
"}",
"}"
]
| Ensure that if a query has an order by clause, those columns are present in the select.
@param SQLSelect $query
@param array $originalSelect | [
"Ensure",
"that",
"if",
"a",
"query",
"has",
"an",
"order",
"by",
"clause",
"those",
"columns",
"are",
"present",
"in",
"the",
"select",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataQuery.php#L353-L415 | train |
silverstripe/silverstripe-framework | src/ORM/DataQuery.php | DataQuery.max | public function max($field)
{
$table = DataObject::getSchema()->tableForField($this->dataClass, $field);
if (!$table) {
return $this->aggregate("MAX(\"$field\")");
}
return $this->aggregate("MAX(\"$table\".\"$field\")");
} | php | public function max($field)
{
$table = DataObject::getSchema()->tableForField($this->dataClass, $field);
if (!$table) {
return $this->aggregate("MAX(\"$field\")");
}
return $this->aggregate("MAX(\"$table\".\"$field\")");
} | [
"public",
"function",
"max",
"(",
"$",
"field",
")",
"{",
"$",
"table",
"=",
"DataObject",
"::",
"getSchema",
"(",
")",
"->",
"tableForField",
"(",
"$",
"this",
"->",
"dataClass",
",",
"$",
"field",
")",
";",
"if",
"(",
"!",
"$",
"table",
")",
"{",
"return",
"$",
"this",
"->",
"aggregate",
"(",
"\"MAX(\\\"$field\\\")\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"aggregate",
"(",
"\"MAX(\\\"$table\\\".\\\"$field\\\")\"",
")",
";",
"}"
]
| Return the maximum value of the given field in this DataList
@param string $field Unquoted database column name. Will be ANSI quoted
automatically so must not contain double quotes.
@return string | [
"Return",
"the",
"maximum",
"value",
"of",
"the",
"given",
"field",
"in",
"this",
"DataList"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataQuery.php#L457-L464 | train |
silverstripe/silverstripe-framework | src/ORM/DataQuery.php | DataQuery.selectColumnsFromTable | protected function selectColumnsFromTable(SQLSelect &$query, $tableClass, $columns = null)
{
// Add SQL for multi-value fields
$schema = DataObject::getSchema();
$databaseFields = $schema->databaseFields($tableClass, false);
$compositeFields = $schema->compositeFields($tableClass, false);
unset($databaseFields['ID']);
foreach ($databaseFields as $k => $v) {
if ((is_null($columns) || in_array($k, $columns)) && !isset($compositeFields[$k])) {
// Update $collidingFields if necessary
$expressionForField = $query->expressionForField($k);
$quotedField = $schema->sqlColumnForField($tableClass, $k);
if ($expressionForField) {
if (!isset($this->collidingFields[$k])) {
$this->collidingFields[$k] = array($expressionForField);
}
$this->collidingFields[$k][] = $quotedField;
} else {
$query->selectField($quotedField, $k);
}
}
}
foreach ($compositeFields as $k => $v) {
if ((is_null($columns) || in_array($k, $columns)) && $v) {
$tableName = $schema->tableName($tableClass);
$dbO = Injector::inst()->create($v, $k);
$dbO->setTable($tableName);
$dbO->addToQuery($query);
}
}
} | php | protected function selectColumnsFromTable(SQLSelect &$query, $tableClass, $columns = null)
{
// Add SQL for multi-value fields
$schema = DataObject::getSchema();
$databaseFields = $schema->databaseFields($tableClass, false);
$compositeFields = $schema->compositeFields($tableClass, false);
unset($databaseFields['ID']);
foreach ($databaseFields as $k => $v) {
if ((is_null($columns) || in_array($k, $columns)) && !isset($compositeFields[$k])) {
// Update $collidingFields if necessary
$expressionForField = $query->expressionForField($k);
$quotedField = $schema->sqlColumnForField($tableClass, $k);
if ($expressionForField) {
if (!isset($this->collidingFields[$k])) {
$this->collidingFields[$k] = array($expressionForField);
}
$this->collidingFields[$k][] = $quotedField;
} else {
$query->selectField($quotedField, $k);
}
}
}
foreach ($compositeFields as $k => $v) {
if ((is_null($columns) || in_array($k, $columns)) && $v) {
$tableName = $schema->tableName($tableClass);
$dbO = Injector::inst()->create($v, $k);
$dbO->setTable($tableName);
$dbO->addToQuery($query);
}
}
} | [
"protected",
"function",
"selectColumnsFromTable",
"(",
"SQLSelect",
"&",
"$",
"query",
",",
"$",
"tableClass",
",",
"$",
"columns",
"=",
"null",
")",
"{",
"// Add SQL for multi-value fields",
"$",
"schema",
"=",
"DataObject",
"::",
"getSchema",
"(",
")",
";",
"$",
"databaseFields",
"=",
"$",
"schema",
"->",
"databaseFields",
"(",
"$",
"tableClass",
",",
"false",
")",
";",
"$",
"compositeFields",
"=",
"$",
"schema",
"->",
"compositeFields",
"(",
"$",
"tableClass",
",",
"false",
")",
";",
"unset",
"(",
"$",
"databaseFields",
"[",
"'ID'",
"]",
")",
";",
"foreach",
"(",
"$",
"databaseFields",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"(",
"is_null",
"(",
"$",
"columns",
")",
"||",
"in_array",
"(",
"$",
"k",
",",
"$",
"columns",
")",
")",
"&&",
"!",
"isset",
"(",
"$",
"compositeFields",
"[",
"$",
"k",
"]",
")",
")",
"{",
"// Update $collidingFields if necessary",
"$",
"expressionForField",
"=",
"$",
"query",
"->",
"expressionForField",
"(",
"$",
"k",
")",
";",
"$",
"quotedField",
"=",
"$",
"schema",
"->",
"sqlColumnForField",
"(",
"$",
"tableClass",
",",
"$",
"k",
")",
";",
"if",
"(",
"$",
"expressionForField",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"collidingFields",
"[",
"$",
"k",
"]",
")",
")",
"{",
"$",
"this",
"->",
"collidingFields",
"[",
"$",
"k",
"]",
"=",
"array",
"(",
"$",
"expressionForField",
")",
";",
"}",
"$",
"this",
"->",
"collidingFields",
"[",
"$",
"k",
"]",
"[",
"]",
"=",
"$",
"quotedField",
";",
"}",
"else",
"{",
"$",
"query",
"->",
"selectField",
"(",
"$",
"quotedField",
",",
"$",
"k",
")",
";",
"}",
"}",
"}",
"foreach",
"(",
"$",
"compositeFields",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"(",
"is_null",
"(",
"$",
"columns",
")",
"||",
"in_array",
"(",
"$",
"k",
",",
"$",
"columns",
")",
")",
"&&",
"$",
"v",
")",
"{",
"$",
"tableName",
"=",
"$",
"schema",
"->",
"tableName",
"(",
"$",
"tableClass",
")",
";",
"$",
"dbO",
"=",
"Injector",
"::",
"inst",
"(",
")",
"->",
"create",
"(",
"$",
"v",
",",
"$",
"k",
")",
";",
"$",
"dbO",
"->",
"setTable",
"(",
"$",
"tableName",
")",
";",
"$",
"dbO",
"->",
"addToQuery",
"(",
"$",
"query",
")",
";",
"}",
"}",
"}"
]
| Update the SELECT clause of the query with the columns from the given table
@param SQLSelect $query
@param string $tableClass Class to select from
@param array $columns | [
"Update",
"the",
"SELECT",
"clause",
"of",
"the",
"query",
"with",
"the",
"columns",
"from",
"the",
"given",
"table"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataQuery.php#L555-L585 | train |
silverstripe/silverstripe-framework | src/ORM/DataQuery.php | DataQuery.sort | public function sort($sort = null, $direction = null, $clear = true)
{
if ($clear) {
$this->query->setOrderBy($sort, $direction);
} else {
$this->query->addOrderBy($sort, $direction);
}
return $this;
} | php | public function sort($sort = null, $direction = null, $clear = true)
{
if ($clear) {
$this->query->setOrderBy($sort, $direction);
} else {
$this->query->addOrderBy($sort, $direction);
}
return $this;
} | [
"public",
"function",
"sort",
"(",
"$",
"sort",
"=",
"null",
",",
"$",
"direction",
"=",
"null",
",",
"$",
"clear",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"clear",
")",
"{",
"$",
"this",
"->",
"query",
"->",
"setOrderBy",
"(",
"$",
"sort",
",",
"$",
"direction",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"query",
"->",
"addOrderBy",
"(",
"$",
"sort",
",",
"$",
"direction",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Set the ORDER BY clause of this query
@see SQLSelect::orderby()
@param string $sort Column to sort on (escaped SQL statement)
@param string $direction Direction ("ASC" or "DESC", escaped SQL statement)
@param bool $clear Clear existing values
@return $this | [
"Set",
"the",
"ORDER",
"BY",
"clause",
"of",
"this",
"query"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataQuery.php#L681-L690 | train |
silverstripe/silverstripe-framework | src/ORM/DataQuery.php | DataQuery.innerJoin | public function innerJoin($table, $onClause, $alias = null, $order = 20, $parameters = array())
{
if ($table) {
$this->query->addInnerJoin($table, $onClause, $alias, $order, $parameters);
}
return $this;
} | php | public function innerJoin($table, $onClause, $alias = null, $order = 20, $parameters = array())
{
if ($table) {
$this->query->addInnerJoin($table, $onClause, $alias, $order, $parameters);
}
return $this;
} | [
"public",
"function",
"innerJoin",
"(",
"$",
"table",
",",
"$",
"onClause",
",",
"$",
"alias",
"=",
"null",
",",
"$",
"order",
"=",
"20",
",",
"$",
"parameters",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"$",
"table",
")",
"{",
"$",
"this",
"->",
"query",
"->",
"addInnerJoin",
"(",
"$",
"table",
",",
"$",
"onClause",
",",
"$",
"alias",
",",
"$",
"order",
",",
"$",
"parameters",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Add an INNER JOIN clause to this query.
@param string $table The unquoted table name to join to.
@param string $onClause The filter for the join (escaped SQL statement)
@param string $alias An optional alias name (unquoted)
@param int $order A numerical index to control the order that joins are added to the query; lower order values
will cause the query to appear first. The default is 20, and joins created automatically by the
ORM have a value of 10.
@param array $parameters Any additional parameters if the join is a parameterised subquery
@return $this | [
"Add",
"an",
"INNER",
"JOIN",
"clause",
"to",
"this",
"query",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataQuery.php#L740-L746 | train |
silverstripe/silverstripe-framework | src/ORM/DataQuery.php | DataQuery.leftJoin | public function leftJoin($table, $onClause, $alias = null, $order = 20, $parameters = array())
{
if ($table) {
$this->query->addLeftJoin($table, $onClause, $alias, $order, $parameters);
}
return $this;
} | php | public function leftJoin($table, $onClause, $alias = null, $order = 20, $parameters = array())
{
if ($table) {
$this->query->addLeftJoin($table, $onClause, $alias, $order, $parameters);
}
return $this;
} | [
"public",
"function",
"leftJoin",
"(",
"$",
"table",
",",
"$",
"onClause",
",",
"$",
"alias",
"=",
"null",
",",
"$",
"order",
"=",
"20",
",",
"$",
"parameters",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"$",
"table",
")",
"{",
"$",
"this",
"->",
"query",
"->",
"addLeftJoin",
"(",
"$",
"table",
",",
"$",
"onClause",
",",
"$",
"alias",
",",
"$",
"order",
",",
"$",
"parameters",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Add a LEFT JOIN clause to this query.
@param string $table The unquoted table to join to.
@param string $onClause The filter for the join (escaped SQL statement).
@param string $alias An optional alias name (unquoted)
@param int $order A numerical index to control the order that joins are added to the query; lower order values
will cause the query to appear first. The default is 20, and joins created automatically by the
ORM have a value of 10.
@param array $parameters Any additional parameters if the join is a parameterised subquery
@return $this | [
"Add",
"a",
"LEFT",
"JOIN",
"clause",
"to",
"this",
"query",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataQuery.php#L760-L766 | train |
silverstripe/silverstripe-framework | src/ORM/DataQuery.php | DataQuery.joinHasManyRelation | protected function joinHasManyRelation(
$localClass,
$localField,
$foreignClass,
$localPrefix = null,
$foreignPrefix = null,
$type = 'has_many'
) {
if (!$foreignClass || $foreignClass === DataObject::class) {
throw new InvalidArgumentException("Could not find a has_many relationship {$localField} on {$localClass}");
}
$schema = DataObject::getSchema();
// Skip if already joined
// Note: don't just check base class, since we need to join on the table with the actual relation key
$foreignTable = $schema->tableName($foreignClass);
$foreignTableAliased = $foreignPrefix . $foreignTable;
if ($this->query->isJoinedTo($foreignTableAliased)) {
return;
}
// Join table with associated has_one
/** @var DataObject $model */
$foreignKey = $schema->getRemoteJoinField($localClass, $localField, $type, $polymorphic);
$localIDColumn = $schema->sqlColumnForField($localClass, 'ID', $localPrefix);
if ($polymorphic) {
$foreignKeyIDColumn = $schema->sqlColumnForField($foreignClass, "{$foreignKey}ID", $foreignPrefix);
$foreignKeyClassColumn = $schema->sqlColumnForField($foreignClass, "{$foreignKey}Class", $foreignPrefix);
$localClassColumn = $schema->sqlColumnForField($localClass, 'ClassName', $localPrefix);
$joinExpression =
"{$foreignKeyIDColumn} = {$localIDColumn} AND {$foreignKeyClassColumn} = {$localClassColumn}";
} else {
$foreignKeyIDColumn = $schema->sqlColumnForField($foreignClass, $foreignKey, $foreignPrefix);
$joinExpression = "{$foreignKeyIDColumn} = {$localIDColumn}";
}
$this->query->addLeftJoin(
$foreignTable,
$joinExpression,
$foreignTableAliased
);
// Add join clause to the component's ancestry classes so that the search filter could search on
// its ancestor fields.
$ancestry = ClassInfo::ancestry($foreignClass, true);
$ancestry = array_reverse($ancestry);
foreach ($ancestry as $ancestor) {
$ancestorTable = $schema->tableName($ancestor);
if ($ancestorTable !== $foreignTable) {
$ancestorTableAliased = $foreignPrefix . $ancestorTable;
$this->query->addLeftJoin(
$ancestorTable,
"\"{$foreignTableAliased}\".\"ID\" = \"{$ancestorTableAliased}\".\"ID\"",
$ancestorTableAliased
);
}
}
} | php | protected function joinHasManyRelation(
$localClass,
$localField,
$foreignClass,
$localPrefix = null,
$foreignPrefix = null,
$type = 'has_many'
) {
if (!$foreignClass || $foreignClass === DataObject::class) {
throw new InvalidArgumentException("Could not find a has_many relationship {$localField} on {$localClass}");
}
$schema = DataObject::getSchema();
// Skip if already joined
// Note: don't just check base class, since we need to join on the table with the actual relation key
$foreignTable = $schema->tableName($foreignClass);
$foreignTableAliased = $foreignPrefix . $foreignTable;
if ($this->query->isJoinedTo($foreignTableAliased)) {
return;
}
// Join table with associated has_one
/** @var DataObject $model */
$foreignKey = $schema->getRemoteJoinField($localClass, $localField, $type, $polymorphic);
$localIDColumn = $schema->sqlColumnForField($localClass, 'ID', $localPrefix);
if ($polymorphic) {
$foreignKeyIDColumn = $schema->sqlColumnForField($foreignClass, "{$foreignKey}ID", $foreignPrefix);
$foreignKeyClassColumn = $schema->sqlColumnForField($foreignClass, "{$foreignKey}Class", $foreignPrefix);
$localClassColumn = $schema->sqlColumnForField($localClass, 'ClassName', $localPrefix);
$joinExpression =
"{$foreignKeyIDColumn} = {$localIDColumn} AND {$foreignKeyClassColumn} = {$localClassColumn}";
} else {
$foreignKeyIDColumn = $schema->sqlColumnForField($foreignClass, $foreignKey, $foreignPrefix);
$joinExpression = "{$foreignKeyIDColumn} = {$localIDColumn}";
}
$this->query->addLeftJoin(
$foreignTable,
$joinExpression,
$foreignTableAliased
);
// Add join clause to the component's ancestry classes so that the search filter could search on
// its ancestor fields.
$ancestry = ClassInfo::ancestry($foreignClass, true);
$ancestry = array_reverse($ancestry);
foreach ($ancestry as $ancestor) {
$ancestorTable = $schema->tableName($ancestor);
if ($ancestorTable !== $foreignTable) {
$ancestorTableAliased = $foreignPrefix . $ancestorTable;
$this->query->addLeftJoin(
$ancestorTable,
"\"{$foreignTableAliased}\".\"ID\" = \"{$ancestorTableAliased}\".\"ID\"",
$ancestorTableAliased
);
}
}
} | [
"protected",
"function",
"joinHasManyRelation",
"(",
"$",
"localClass",
",",
"$",
"localField",
",",
"$",
"foreignClass",
",",
"$",
"localPrefix",
"=",
"null",
",",
"$",
"foreignPrefix",
"=",
"null",
",",
"$",
"type",
"=",
"'has_many'",
")",
"{",
"if",
"(",
"!",
"$",
"foreignClass",
"||",
"$",
"foreignClass",
"===",
"DataObject",
"::",
"class",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Could not find a has_many relationship {$localField} on {$localClass}\"",
")",
";",
"}",
"$",
"schema",
"=",
"DataObject",
"::",
"getSchema",
"(",
")",
";",
"// Skip if already joined",
"// Note: don't just check base class, since we need to join on the table with the actual relation key",
"$",
"foreignTable",
"=",
"$",
"schema",
"->",
"tableName",
"(",
"$",
"foreignClass",
")",
";",
"$",
"foreignTableAliased",
"=",
"$",
"foreignPrefix",
".",
"$",
"foreignTable",
";",
"if",
"(",
"$",
"this",
"->",
"query",
"->",
"isJoinedTo",
"(",
"$",
"foreignTableAliased",
")",
")",
"{",
"return",
";",
"}",
"// Join table with associated has_one",
"/** @var DataObject $model */",
"$",
"foreignKey",
"=",
"$",
"schema",
"->",
"getRemoteJoinField",
"(",
"$",
"localClass",
",",
"$",
"localField",
",",
"$",
"type",
",",
"$",
"polymorphic",
")",
";",
"$",
"localIDColumn",
"=",
"$",
"schema",
"->",
"sqlColumnForField",
"(",
"$",
"localClass",
",",
"'ID'",
",",
"$",
"localPrefix",
")",
";",
"if",
"(",
"$",
"polymorphic",
")",
"{",
"$",
"foreignKeyIDColumn",
"=",
"$",
"schema",
"->",
"sqlColumnForField",
"(",
"$",
"foreignClass",
",",
"\"{$foreignKey}ID\"",
",",
"$",
"foreignPrefix",
")",
";",
"$",
"foreignKeyClassColumn",
"=",
"$",
"schema",
"->",
"sqlColumnForField",
"(",
"$",
"foreignClass",
",",
"\"{$foreignKey}Class\"",
",",
"$",
"foreignPrefix",
")",
";",
"$",
"localClassColumn",
"=",
"$",
"schema",
"->",
"sqlColumnForField",
"(",
"$",
"localClass",
",",
"'ClassName'",
",",
"$",
"localPrefix",
")",
";",
"$",
"joinExpression",
"=",
"\"{$foreignKeyIDColumn} = {$localIDColumn} AND {$foreignKeyClassColumn} = {$localClassColumn}\"",
";",
"}",
"else",
"{",
"$",
"foreignKeyIDColumn",
"=",
"$",
"schema",
"->",
"sqlColumnForField",
"(",
"$",
"foreignClass",
",",
"$",
"foreignKey",
",",
"$",
"foreignPrefix",
")",
";",
"$",
"joinExpression",
"=",
"\"{$foreignKeyIDColumn} = {$localIDColumn}\"",
";",
"}",
"$",
"this",
"->",
"query",
"->",
"addLeftJoin",
"(",
"$",
"foreignTable",
",",
"$",
"joinExpression",
",",
"$",
"foreignTableAliased",
")",
";",
"// Add join clause to the component's ancestry classes so that the search filter could search on",
"// its ancestor fields.",
"$",
"ancestry",
"=",
"ClassInfo",
"::",
"ancestry",
"(",
"$",
"foreignClass",
",",
"true",
")",
";",
"$",
"ancestry",
"=",
"array_reverse",
"(",
"$",
"ancestry",
")",
";",
"foreach",
"(",
"$",
"ancestry",
"as",
"$",
"ancestor",
")",
"{",
"$",
"ancestorTable",
"=",
"$",
"schema",
"->",
"tableName",
"(",
"$",
"ancestor",
")",
";",
"if",
"(",
"$",
"ancestorTable",
"!==",
"$",
"foreignTable",
")",
"{",
"$",
"ancestorTableAliased",
"=",
"$",
"foreignPrefix",
".",
"$",
"ancestorTable",
";",
"$",
"this",
"->",
"query",
"->",
"addLeftJoin",
"(",
"$",
"ancestorTable",
",",
"\"\\\"{$foreignTableAliased}\\\".\\\"ID\\\" = \\\"{$ancestorTableAliased}\\\".\\\"ID\\\"\"",
",",
"$",
"ancestorTableAliased",
")",
";",
"}",
"}",
"}"
]
| Join the given has_many relation to this query.
Also works with belongs_to
Doesn't work with polymorphic relationships
@param string $localClass Name of class that has the has_many to the joined class
@param string $localField Name of the has_many relationship to join
@param string $foreignClass Class to join
@param string $localPrefix Table prefix for parent class
@param string $foreignPrefix Table prefix to use
@param string $type 'has_many' or 'belongs_to' | [
"Join",
"the",
"given",
"has_many",
"relation",
"to",
"this",
"query",
".",
"Also",
"works",
"with",
"belongs_to"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataQuery.php#L894-L950 | train |
silverstripe/silverstripe-framework | src/ORM/DataQuery.php | DataQuery.joinHasOneRelation | protected function joinHasOneRelation(
$localClass,
$localField,
$foreignClass,
$localPrefix = null,
$foreignPrefix = null
) {
if (!$foreignClass) {
throw new InvalidArgumentException("Could not find a has_one relationship {$localField} on {$localClass}");
}
if ($foreignClass === DataObject::class) {
throw new InvalidArgumentException(
"Could not join polymorphic has_one relationship {$localField} on {$localClass}"
);
}
$schema = DataObject::getSchema();
// Skip if already joined
$foreignBaseClass = $schema->baseDataClass($foreignClass);
$foreignBaseTable = $schema->tableName($foreignBaseClass);
if ($this->query->isJoinedTo($foreignPrefix . $foreignBaseTable)) {
return;
}
// Join base table
$foreignIDColumn = $schema->sqlColumnForField($foreignBaseClass, 'ID', $foreignPrefix);
$localColumn = $schema->sqlColumnForField($localClass, "{$localField}ID", $localPrefix);
$this->query->addLeftJoin(
$foreignBaseTable,
"{$foreignIDColumn} = {$localColumn}",
$foreignPrefix . $foreignBaseTable
);
// Add join clause to the component's ancestry classes so that the search filter could search on
// its ancestor fields.
$ancestry = ClassInfo::ancestry($foreignClass, true);
if (!empty($ancestry)) {
$ancestry = array_reverse($ancestry);
foreach ($ancestry as $ancestor) {
$ancestorTable = $schema->tableName($ancestor);
if ($ancestorTable !== $foreignBaseTable) {
$ancestorTableAliased = $foreignPrefix . $ancestorTable;
$this->query->addLeftJoin(
$ancestorTable,
"{$foreignIDColumn} = \"{$ancestorTableAliased}\".\"ID\"",
$ancestorTableAliased
);
}
}
}
} | php | protected function joinHasOneRelation(
$localClass,
$localField,
$foreignClass,
$localPrefix = null,
$foreignPrefix = null
) {
if (!$foreignClass) {
throw new InvalidArgumentException("Could not find a has_one relationship {$localField} on {$localClass}");
}
if ($foreignClass === DataObject::class) {
throw new InvalidArgumentException(
"Could not join polymorphic has_one relationship {$localField} on {$localClass}"
);
}
$schema = DataObject::getSchema();
// Skip if already joined
$foreignBaseClass = $schema->baseDataClass($foreignClass);
$foreignBaseTable = $schema->tableName($foreignBaseClass);
if ($this->query->isJoinedTo($foreignPrefix . $foreignBaseTable)) {
return;
}
// Join base table
$foreignIDColumn = $schema->sqlColumnForField($foreignBaseClass, 'ID', $foreignPrefix);
$localColumn = $schema->sqlColumnForField($localClass, "{$localField}ID", $localPrefix);
$this->query->addLeftJoin(
$foreignBaseTable,
"{$foreignIDColumn} = {$localColumn}",
$foreignPrefix . $foreignBaseTable
);
// Add join clause to the component's ancestry classes so that the search filter could search on
// its ancestor fields.
$ancestry = ClassInfo::ancestry($foreignClass, true);
if (!empty($ancestry)) {
$ancestry = array_reverse($ancestry);
foreach ($ancestry as $ancestor) {
$ancestorTable = $schema->tableName($ancestor);
if ($ancestorTable !== $foreignBaseTable) {
$ancestorTableAliased = $foreignPrefix . $ancestorTable;
$this->query->addLeftJoin(
$ancestorTable,
"{$foreignIDColumn} = \"{$ancestorTableAliased}\".\"ID\"",
$ancestorTableAliased
);
}
}
}
} | [
"protected",
"function",
"joinHasOneRelation",
"(",
"$",
"localClass",
",",
"$",
"localField",
",",
"$",
"foreignClass",
",",
"$",
"localPrefix",
"=",
"null",
",",
"$",
"foreignPrefix",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"foreignClass",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Could not find a has_one relationship {$localField} on {$localClass}\"",
")",
";",
"}",
"if",
"(",
"$",
"foreignClass",
"===",
"DataObject",
"::",
"class",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Could not join polymorphic has_one relationship {$localField} on {$localClass}\"",
")",
";",
"}",
"$",
"schema",
"=",
"DataObject",
"::",
"getSchema",
"(",
")",
";",
"// Skip if already joined",
"$",
"foreignBaseClass",
"=",
"$",
"schema",
"->",
"baseDataClass",
"(",
"$",
"foreignClass",
")",
";",
"$",
"foreignBaseTable",
"=",
"$",
"schema",
"->",
"tableName",
"(",
"$",
"foreignBaseClass",
")",
";",
"if",
"(",
"$",
"this",
"->",
"query",
"->",
"isJoinedTo",
"(",
"$",
"foreignPrefix",
".",
"$",
"foreignBaseTable",
")",
")",
"{",
"return",
";",
"}",
"// Join base table",
"$",
"foreignIDColumn",
"=",
"$",
"schema",
"->",
"sqlColumnForField",
"(",
"$",
"foreignBaseClass",
",",
"'ID'",
",",
"$",
"foreignPrefix",
")",
";",
"$",
"localColumn",
"=",
"$",
"schema",
"->",
"sqlColumnForField",
"(",
"$",
"localClass",
",",
"\"{$localField}ID\"",
",",
"$",
"localPrefix",
")",
";",
"$",
"this",
"->",
"query",
"->",
"addLeftJoin",
"(",
"$",
"foreignBaseTable",
",",
"\"{$foreignIDColumn} = {$localColumn}\"",
",",
"$",
"foreignPrefix",
".",
"$",
"foreignBaseTable",
")",
";",
"// Add join clause to the component's ancestry classes so that the search filter could search on",
"// its ancestor fields.",
"$",
"ancestry",
"=",
"ClassInfo",
"::",
"ancestry",
"(",
"$",
"foreignClass",
",",
"true",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"ancestry",
")",
")",
"{",
"$",
"ancestry",
"=",
"array_reverse",
"(",
"$",
"ancestry",
")",
";",
"foreach",
"(",
"$",
"ancestry",
"as",
"$",
"ancestor",
")",
"{",
"$",
"ancestorTable",
"=",
"$",
"schema",
"->",
"tableName",
"(",
"$",
"ancestor",
")",
";",
"if",
"(",
"$",
"ancestorTable",
"!==",
"$",
"foreignBaseTable",
")",
"{",
"$",
"ancestorTableAliased",
"=",
"$",
"foreignPrefix",
".",
"$",
"ancestorTable",
";",
"$",
"this",
"->",
"query",
"->",
"addLeftJoin",
"(",
"$",
"ancestorTable",
",",
"\"{$foreignIDColumn} = \\\"{$ancestorTableAliased}\\\".\\\"ID\\\"\"",
",",
"$",
"ancestorTableAliased",
")",
";",
"}",
"}",
"}",
"}"
]
| Join the given class to this query with the given key
@param string $localClass Name of class that has the has_one to the joined class
@param string $localField Name of the has_one relationship to joi
@param string $foreignClass Class to join
@param string $localPrefix Table prefix to use for local class
@param string $foreignPrefix Table prefix to use for joined table | [
"Join",
"the",
"given",
"class",
"to",
"this",
"query",
"with",
"the",
"given",
"key"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataQuery.php#L961-L1012 | train |
silverstripe/silverstripe-framework | src/ORM/DataQuery.php | DataQuery.joinManyManyRelationship | protected function joinManyManyRelationship(
$relationClass,
$parentClass,
$componentClass,
$parentField,
$componentField,
$relationClassOrTable,
$parentPrefix = null,
$componentPrefix = null
) {
$schema = DataObject::getSchema();
if (class_exists($relationClassOrTable)) {
$relationClassOrTable = $schema->tableName($relationClassOrTable);
}
// Check if already joined to component alias (skip join table for the check)
$componentBaseClass = $schema->baseDataClass($componentClass);
$componentBaseTable = $schema->tableName($componentBaseClass);
$componentAliasedTable = $componentPrefix . $componentBaseTable;
if ($this->query->isJoinedTo($componentAliasedTable)) {
return;
}
// Join parent class to join table
$relationAliasedTable = $componentPrefix . $relationClassOrTable;
$parentIDColumn = $schema->sqlColumnForField($parentClass, 'ID', $parentPrefix);
$this->query->addLeftJoin(
$relationClassOrTable,
"\"{$relationAliasedTable}\".\"{$parentField}\" = {$parentIDColumn}",
$relationAliasedTable
);
// Join on base table of component class
$componentIDColumn = $schema->sqlColumnForField($componentBaseClass, 'ID', $componentPrefix);
$this->query->addLeftJoin(
$componentBaseTable,
"\"{$relationAliasedTable}\".\"{$componentField}\" = {$componentIDColumn}",
$componentAliasedTable
);
// Add join clause to the component's ancestry classes so that the search filter could search on
// its ancestor fields.
$ancestry = ClassInfo::ancestry($componentClass, true);
$ancestry = array_reverse($ancestry);
foreach ($ancestry as $ancestor) {
$ancestorTable = $schema->tableName($ancestor);
if ($ancestorTable !== $componentBaseTable) {
$ancestorTableAliased = $componentPrefix . $ancestorTable;
$this->query->addLeftJoin(
$ancestorTable,
"{$componentIDColumn} = \"{$ancestorTableAliased}\".\"ID\"",
$ancestorTableAliased
);
}
}
} | php | protected function joinManyManyRelationship(
$relationClass,
$parentClass,
$componentClass,
$parentField,
$componentField,
$relationClassOrTable,
$parentPrefix = null,
$componentPrefix = null
) {
$schema = DataObject::getSchema();
if (class_exists($relationClassOrTable)) {
$relationClassOrTable = $schema->tableName($relationClassOrTable);
}
// Check if already joined to component alias (skip join table for the check)
$componentBaseClass = $schema->baseDataClass($componentClass);
$componentBaseTable = $schema->tableName($componentBaseClass);
$componentAliasedTable = $componentPrefix . $componentBaseTable;
if ($this->query->isJoinedTo($componentAliasedTable)) {
return;
}
// Join parent class to join table
$relationAliasedTable = $componentPrefix . $relationClassOrTable;
$parentIDColumn = $schema->sqlColumnForField($parentClass, 'ID', $parentPrefix);
$this->query->addLeftJoin(
$relationClassOrTable,
"\"{$relationAliasedTable}\".\"{$parentField}\" = {$parentIDColumn}",
$relationAliasedTable
);
// Join on base table of component class
$componentIDColumn = $schema->sqlColumnForField($componentBaseClass, 'ID', $componentPrefix);
$this->query->addLeftJoin(
$componentBaseTable,
"\"{$relationAliasedTable}\".\"{$componentField}\" = {$componentIDColumn}",
$componentAliasedTable
);
// Add join clause to the component's ancestry classes so that the search filter could search on
// its ancestor fields.
$ancestry = ClassInfo::ancestry($componentClass, true);
$ancestry = array_reverse($ancestry);
foreach ($ancestry as $ancestor) {
$ancestorTable = $schema->tableName($ancestor);
if ($ancestorTable !== $componentBaseTable) {
$ancestorTableAliased = $componentPrefix . $ancestorTable;
$this->query->addLeftJoin(
$ancestorTable,
"{$componentIDColumn} = \"{$ancestorTableAliased}\".\"ID\"",
$ancestorTableAliased
);
}
}
} | [
"protected",
"function",
"joinManyManyRelationship",
"(",
"$",
"relationClass",
",",
"$",
"parentClass",
",",
"$",
"componentClass",
",",
"$",
"parentField",
",",
"$",
"componentField",
",",
"$",
"relationClassOrTable",
",",
"$",
"parentPrefix",
"=",
"null",
",",
"$",
"componentPrefix",
"=",
"null",
")",
"{",
"$",
"schema",
"=",
"DataObject",
"::",
"getSchema",
"(",
")",
";",
"if",
"(",
"class_exists",
"(",
"$",
"relationClassOrTable",
")",
")",
"{",
"$",
"relationClassOrTable",
"=",
"$",
"schema",
"->",
"tableName",
"(",
"$",
"relationClassOrTable",
")",
";",
"}",
"// Check if already joined to component alias (skip join table for the check)",
"$",
"componentBaseClass",
"=",
"$",
"schema",
"->",
"baseDataClass",
"(",
"$",
"componentClass",
")",
";",
"$",
"componentBaseTable",
"=",
"$",
"schema",
"->",
"tableName",
"(",
"$",
"componentBaseClass",
")",
";",
"$",
"componentAliasedTable",
"=",
"$",
"componentPrefix",
".",
"$",
"componentBaseTable",
";",
"if",
"(",
"$",
"this",
"->",
"query",
"->",
"isJoinedTo",
"(",
"$",
"componentAliasedTable",
")",
")",
"{",
"return",
";",
"}",
"// Join parent class to join table",
"$",
"relationAliasedTable",
"=",
"$",
"componentPrefix",
".",
"$",
"relationClassOrTable",
";",
"$",
"parentIDColumn",
"=",
"$",
"schema",
"->",
"sqlColumnForField",
"(",
"$",
"parentClass",
",",
"'ID'",
",",
"$",
"parentPrefix",
")",
";",
"$",
"this",
"->",
"query",
"->",
"addLeftJoin",
"(",
"$",
"relationClassOrTable",
",",
"\"\\\"{$relationAliasedTable}\\\".\\\"{$parentField}\\\" = {$parentIDColumn}\"",
",",
"$",
"relationAliasedTable",
")",
";",
"// Join on base table of component class",
"$",
"componentIDColumn",
"=",
"$",
"schema",
"->",
"sqlColumnForField",
"(",
"$",
"componentBaseClass",
",",
"'ID'",
",",
"$",
"componentPrefix",
")",
";",
"$",
"this",
"->",
"query",
"->",
"addLeftJoin",
"(",
"$",
"componentBaseTable",
",",
"\"\\\"{$relationAliasedTable}\\\".\\\"{$componentField}\\\" = {$componentIDColumn}\"",
",",
"$",
"componentAliasedTable",
")",
";",
"// Add join clause to the component's ancestry classes so that the search filter could search on",
"// its ancestor fields.",
"$",
"ancestry",
"=",
"ClassInfo",
"::",
"ancestry",
"(",
"$",
"componentClass",
",",
"true",
")",
";",
"$",
"ancestry",
"=",
"array_reverse",
"(",
"$",
"ancestry",
")",
";",
"foreach",
"(",
"$",
"ancestry",
"as",
"$",
"ancestor",
")",
"{",
"$",
"ancestorTable",
"=",
"$",
"schema",
"->",
"tableName",
"(",
"$",
"ancestor",
")",
";",
"if",
"(",
"$",
"ancestorTable",
"!==",
"$",
"componentBaseTable",
")",
"{",
"$",
"ancestorTableAliased",
"=",
"$",
"componentPrefix",
".",
"$",
"ancestorTable",
";",
"$",
"this",
"->",
"query",
"->",
"addLeftJoin",
"(",
"$",
"ancestorTable",
",",
"\"{$componentIDColumn} = \\\"{$ancestorTableAliased}\\\".\\\"ID\\\"\"",
",",
"$",
"ancestorTableAliased",
")",
";",
"}",
"}",
"}"
]
| Join table via many_many relationship
@param string $relationClass
@param string $parentClass
@param string $componentClass
@param string $parentField
@param string $componentField
@param string $relationClassOrTable Name of relation table
@param string $parentPrefix Table prefix for parent class
@param string $componentPrefix Table prefix to use for both joined and mapping table | [
"Join",
"table",
"via",
"many_many",
"relationship"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataQuery.php#L1026-L1082 | train |
silverstripe/silverstripe-framework | src/ORM/DataQuery.php | DataQuery.subtract | public function subtract(DataQuery $subtractQuery, $field = 'ID')
{
$fieldExpression = $subtractQuery->expressionForField($field);
$subSelect = $subtractQuery->getFinalisedQuery();
$subSelect->setSelect(array());
$subSelect->selectField($fieldExpression, $field);
$subSelect->setOrderBy(null);
$subSelectSQL = $subSelect->sql($subSelectParameters);
$this->where(array($this->expressionForField($field) . " NOT IN ($subSelectSQL)" => $subSelectParameters));
return $this;
} | php | public function subtract(DataQuery $subtractQuery, $field = 'ID')
{
$fieldExpression = $subtractQuery->expressionForField($field);
$subSelect = $subtractQuery->getFinalisedQuery();
$subSelect->setSelect(array());
$subSelect->selectField($fieldExpression, $field);
$subSelect->setOrderBy(null);
$subSelectSQL = $subSelect->sql($subSelectParameters);
$this->where(array($this->expressionForField($field) . " NOT IN ($subSelectSQL)" => $subSelectParameters));
return $this;
} | [
"public",
"function",
"subtract",
"(",
"DataQuery",
"$",
"subtractQuery",
",",
"$",
"field",
"=",
"'ID'",
")",
"{",
"$",
"fieldExpression",
"=",
"$",
"subtractQuery",
"->",
"expressionForField",
"(",
"$",
"field",
")",
";",
"$",
"subSelect",
"=",
"$",
"subtractQuery",
"->",
"getFinalisedQuery",
"(",
")",
";",
"$",
"subSelect",
"->",
"setSelect",
"(",
"array",
"(",
")",
")",
";",
"$",
"subSelect",
"->",
"selectField",
"(",
"$",
"fieldExpression",
",",
"$",
"field",
")",
";",
"$",
"subSelect",
"->",
"setOrderBy",
"(",
"null",
")",
";",
"$",
"subSelectSQL",
"=",
"$",
"subSelect",
"->",
"sql",
"(",
"$",
"subSelectParameters",
")",
";",
"$",
"this",
"->",
"where",
"(",
"array",
"(",
"$",
"this",
"->",
"expressionForField",
"(",
"$",
"field",
")",
".",
"\" NOT IN ($subSelectSQL)\"",
"=>",
"$",
"subSelectParameters",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Removes the result of query from this query.
@param DataQuery $subtractQuery
@param string $field
@return $this | [
"Removes",
"the",
"result",
"of",
"query",
"from",
"this",
"query",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataQuery.php#L1091-L1102 | train |
silverstripe/silverstripe-framework | src/ORM/DataQuery.php | DataQuery.selectFromTable | public function selectFromTable($table, $fields)
{
$fieldExpressions = array_map(function ($item) use ($table) {
return Convert::symbol2sql("{$table}.{$item}");
}, $fields);
$this->query->setSelect($fieldExpressions);
return $this;
} | php | public function selectFromTable($table, $fields)
{
$fieldExpressions = array_map(function ($item) use ($table) {
return Convert::symbol2sql("{$table}.{$item}");
}, $fields);
$this->query->setSelect($fieldExpressions);
return $this;
} | [
"public",
"function",
"selectFromTable",
"(",
"$",
"table",
",",
"$",
"fields",
")",
"{",
"$",
"fieldExpressions",
"=",
"array_map",
"(",
"function",
"(",
"$",
"item",
")",
"use",
"(",
"$",
"table",
")",
"{",
"return",
"Convert",
"::",
"symbol2sql",
"(",
"\"{$table}.{$item}\"",
")",
";",
"}",
",",
"$",
"fields",
")",
";",
"$",
"this",
"->",
"query",
"->",
"setSelect",
"(",
"$",
"fieldExpressions",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Select the only given fields from the given table.
@param string $table Unquoted table name (will be escaped automatically)
@param array $fields Database column names (will be escaped automatically)
@return $this | [
"Select",
"the",
"only",
"given",
"fields",
"from",
"the",
"given",
"table",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataQuery.php#L1111-L1120 | train |
silverstripe/silverstripe-framework | src/ORM/DataQuery.php | DataQuery.addSelectFromTable | public function addSelectFromTable($table, $fields)
{
$fieldExpressions = array_map(function ($item) use ($table) {
return Convert::symbol2sql("{$table}.{$item}");
}, $fields);
$this->query->addSelect($fieldExpressions);
return $this;
} | php | public function addSelectFromTable($table, $fields)
{
$fieldExpressions = array_map(function ($item) use ($table) {
return Convert::symbol2sql("{$table}.{$item}");
}, $fields);
$this->query->addSelect($fieldExpressions);
return $this;
} | [
"public",
"function",
"addSelectFromTable",
"(",
"$",
"table",
",",
"$",
"fields",
")",
"{",
"$",
"fieldExpressions",
"=",
"array_map",
"(",
"function",
"(",
"$",
"item",
")",
"use",
"(",
"$",
"table",
")",
"{",
"return",
"Convert",
"::",
"symbol2sql",
"(",
"\"{$table}.{$item}\"",
")",
";",
"}",
",",
"$",
"fields",
")",
";",
"$",
"this",
"->",
"query",
"->",
"addSelect",
"(",
"$",
"fieldExpressions",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Add the given fields from the given table to the select statement.
@param string $table Unquoted table name (will be escaped automatically)
@param array $fields Database column names (will be escaped automatically)
@return $this | [
"Add",
"the",
"given",
"fields",
"from",
"the",
"given",
"table",
"to",
"the",
"select",
"statement",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataQuery.php#L1129-L1138 | train |
silverstripe/silverstripe-framework | src/ORM/DataQuery.php | DataQuery.column | public function column($field = 'ID')
{
$fieldExpression = $this->expressionForField($field);
$query = $this->getFinalisedQuery(array($field));
$originalSelect = $query->getSelect();
$query->setSelect(array());
$query->selectField($fieldExpression, $field);
$this->ensureSelectContainsOrderbyColumns($query, $originalSelect);
return $query->execute()->column($field);
} | php | public function column($field = 'ID')
{
$fieldExpression = $this->expressionForField($field);
$query = $this->getFinalisedQuery(array($field));
$originalSelect = $query->getSelect();
$query->setSelect(array());
$query->selectField($fieldExpression, $field);
$this->ensureSelectContainsOrderbyColumns($query, $originalSelect);
return $query->execute()->column($field);
} | [
"public",
"function",
"column",
"(",
"$",
"field",
"=",
"'ID'",
")",
"{",
"$",
"fieldExpression",
"=",
"$",
"this",
"->",
"expressionForField",
"(",
"$",
"field",
")",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"getFinalisedQuery",
"(",
"array",
"(",
"$",
"field",
")",
")",
";",
"$",
"originalSelect",
"=",
"$",
"query",
"->",
"getSelect",
"(",
")",
";",
"$",
"query",
"->",
"setSelect",
"(",
"array",
"(",
")",
")",
";",
"$",
"query",
"->",
"selectField",
"(",
"$",
"fieldExpression",
",",
"$",
"field",
")",
";",
"$",
"this",
"->",
"ensureSelectContainsOrderbyColumns",
"(",
"$",
"query",
",",
"$",
"originalSelect",
")",
";",
"return",
"$",
"query",
"->",
"execute",
"(",
")",
"->",
"column",
"(",
"$",
"field",
")",
";",
"}"
]
| Query the given field column from the database and return as an array.
@param string $field See {@link expressionForField()}.
@return array List of column values for the specified column | [
"Query",
"the",
"given",
"field",
"column",
"from",
"the",
"database",
"and",
"return",
"as",
"an",
"array",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataQuery.php#L1146-L1156 | train |
silverstripe/silverstripe-framework | src/ORM/DataQuery.php | DataQuery.getQueryParam | public function getQueryParam($key)
{
if (isset($this->queryParams[$key])) {
return $this->queryParams[$key];
}
return null;
} | php | public function getQueryParam($key)
{
if (isset($this->queryParams[$key])) {
return $this->queryParams[$key];
}
return null;
} | [
"public",
"function",
"getQueryParam",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"queryParams",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"queryParams",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"null",
";",
"}"
]
| Set an arbitrary query parameter, that can be used by decorators to add additional meta-data to the query.
@param string $key
@return string | [
"Set",
"an",
"arbitrary",
"query",
"parameter",
"that",
"can",
"be",
"used",
"by",
"decorators",
"to",
"add",
"additional",
"meta",
"-",
"data",
"to",
"the",
"query",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataQuery.php#L1219-L1225 | train |
silverstripe/silverstripe-framework | src/Control/Controller.php | Controller.doInit | public function doInit()
{
//extension hook
$this->extend('onBeforeInit');
// Safety call
$this->baseInitCalled = false;
$this->init();
if (!$this->baseInitCalled) {
$class = static::class;
user_error(
"init() method on class '{$class}' doesn't call Controller::init()."
. "Make sure that you have parent::init() included.",
E_USER_WARNING
);
}
$this->extend('onAfterInit');
} | php | public function doInit()
{
//extension hook
$this->extend('onBeforeInit');
// Safety call
$this->baseInitCalled = false;
$this->init();
if (!$this->baseInitCalled) {
$class = static::class;
user_error(
"init() method on class '{$class}' doesn't call Controller::init()."
. "Make sure that you have parent::init() included.",
E_USER_WARNING
);
}
$this->extend('onAfterInit');
} | [
"public",
"function",
"doInit",
"(",
")",
"{",
"//extension hook",
"$",
"this",
"->",
"extend",
"(",
"'onBeforeInit'",
")",
";",
"// Safety call",
"$",
"this",
"->",
"baseInitCalled",
"=",
"false",
";",
"$",
"this",
"->",
"init",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"baseInitCalled",
")",
"{",
"$",
"class",
"=",
"static",
"::",
"class",
";",
"user_error",
"(",
"\"init() method on class '{$class}' doesn't call Controller::init().\"",
".",
"\"Make sure that you have parent::init() included.\"",
",",
"E_USER_WARNING",
")",
";",
"}",
"$",
"this",
"->",
"extend",
"(",
"'onAfterInit'",
")",
";",
"}"
]
| A stand in function to protect the init function from failing to be called as well as providing before and
after hooks for the init function itself
This should be called on all controllers before handling requests | [
"A",
"stand",
"in",
"function",
"to",
"protect",
"the",
"init",
"function",
"from",
"failing",
"to",
"be",
"called",
"as",
"well",
"as",
"providing",
"before",
"and",
"after",
"hooks",
"for",
"the",
"init",
"function",
"itself"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Control/Controller.php#L120-L138 | train |
silverstripe/silverstripe-framework | src/Control/Controller.php | Controller.beforeHandleRequest | protected function beforeHandleRequest(HTTPRequest $request)
{
//Set up the internal dependencies (request, response)
$this->setRequest($request);
//Push the current controller to protect against weird session issues
$this->pushCurrent();
$this->setResponse(new HTTPResponse());
//kick off the init functionality
$this->doInit();
} | php | protected function beforeHandleRequest(HTTPRequest $request)
{
//Set up the internal dependencies (request, response)
$this->setRequest($request);
//Push the current controller to protect against weird session issues
$this->pushCurrent();
$this->setResponse(new HTTPResponse());
//kick off the init functionality
$this->doInit();
} | [
"protected",
"function",
"beforeHandleRequest",
"(",
"HTTPRequest",
"$",
"request",
")",
"{",
"//Set up the internal dependencies (request, response)",
"$",
"this",
"->",
"setRequest",
"(",
"$",
"request",
")",
";",
"//Push the current controller to protect against weird session issues",
"$",
"this",
"->",
"pushCurrent",
"(",
")",
";",
"$",
"this",
"->",
"setResponse",
"(",
"new",
"HTTPResponse",
"(",
")",
")",
";",
"//kick off the init functionality",
"$",
"this",
"->",
"doInit",
"(",
")",
";",
"}"
]
| A bootstrap for the handleRequest method
@todo setDataModel and setRequest are redundantly called in parent::handleRequest() - sort this out
@param HTTPRequest $request | [
"A",
"bootstrap",
"for",
"the",
"handleRequest",
"method"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Control/Controller.php#L160-L169 | train |
silverstripe/silverstripe-framework | src/Control/Controller.php | Controller.removeAction | public function removeAction($fullURL, $action = null)
{
if (!$action) {
$action = $this->getAction(); //default to current action
}
$returnURL = $fullURL;
if (($pos = strpos($fullURL, $action)) !== false) {
$returnURL = substr($fullURL, 0, $pos);
}
return $returnURL;
} | php | public function removeAction($fullURL, $action = null)
{
if (!$action) {
$action = $this->getAction(); //default to current action
}
$returnURL = $fullURL;
if (($pos = strpos($fullURL, $action)) !== false) {
$returnURL = substr($fullURL, 0, $pos);
}
return $returnURL;
} | [
"public",
"function",
"removeAction",
"(",
"$",
"fullURL",
",",
"$",
"action",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"action",
")",
"{",
"$",
"action",
"=",
"$",
"this",
"->",
"getAction",
"(",
")",
";",
"//default to current action",
"}",
"$",
"returnURL",
"=",
"$",
"fullURL",
";",
"if",
"(",
"(",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"fullURL",
",",
"$",
"action",
")",
")",
"!==",
"false",
")",
"{",
"$",
"returnURL",
"=",
"substr",
"(",
"$",
"fullURL",
",",
"0",
",",
"$",
"pos",
")",
";",
"}",
"return",
"$",
"returnURL",
";",
"}"
]
| Removes all the "action" part of the current URL and returns the result. If no action parameter
is present, returns the full URL.
@param string $fullURL
@param null|string $action
@return string | [
"Removes",
"all",
"the",
"action",
"part",
"of",
"the",
"current",
"URL",
"and",
"returns",
"the",
"result",
".",
"If",
"no",
"action",
"parameter",
"is",
"present",
"returns",
"the",
"full",
"URL",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Control/Controller.php#L441-L453 | train |
silverstripe/silverstripe-framework | src/Control/Controller.php | Controller.definingClassForAction | protected function definingClassForAction($action)
{
$definingClass = parent::definingClassForAction($action);
if ($definingClass) {
return $definingClass;
}
$class = static::class;
while ($class != 'SilverStripe\\Control\\RequestHandler') {
$templateName = strtok($class, '_') . '_' . $action;
if (SSViewer::hasTemplate($templateName)) {
return $class;
}
$class = get_parent_class($class);
}
return null;
} | php | protected function definingClassForAction($action)
{
$definingClass = parent::definingClassForAction($action);
if ($definingClass) {
return $definingClass;
}
$class = static::class;
while ($class != 'SilverStripe\\Control\\RequestHandler') {
$templateName = strtok($class, '_') . '_' . $action;
if (SSViewer::hasTemplate($templateName)) {
return $class;
}
$class = get_parent_class($class);
}
return null;
} | [
"protected",
"function",
"definingClassForAction",
"(",
"$",
"action",
")",
"{",
"$",
"definingClass",
"=",
"parent",
"::",
"definingClassForAction",
"(",
"$",
"action",
")",
";",
"if",
"(",
"$",
"definingClass",
")",
"{",
"return",
"$",
"definingClass",
";",
"}",
"$",
"class",
"=",
"static",
"::",
"class",
";",
"while",
"(",
"$",
"class",
"!=",
"'SilverStripe\\\\Control\\\\RequestHandler'",
")",
"{",
"$",
"templateName",
"=",
"strtok",
"(",
"$",
"class",
",",
"'_'",
")",
".",
"'_'",
".",
"$",
"action",
";",
"if",
"(",
"SSViewer",
"::",
"hasTemplate",
"(",
"$",
"templateName",
")",
")",
"{",
"return",
"$",
"class",
";",
"}",
"$",
"class",
"=",
"get_parent_class",
"(",
"$",
"class",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Return the class that defines the given action, so that we know where to check allowed_actions.
Overrides RequestHandler to also look at defined templates.
@param string $action
@return string | [
"Return",
"the",
"class",
"that",
"defines",
"the",
"given",
"action",
"so",
"that",
"we",
"know",
"where",
"to",
"check",
"allowed_actions",
".",
"Overrides",
"RequestHandler",
"to",
"also",
"look",
"at",
"defined",
"templates",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Control/Controller.php#L463-L481 | train |
silverstripe/silverstripe-framework | src/Control/Controller.php | Controller.hasActionTemplate | public function hasActionTemplate($action)
{
if (isset($this->templates[$action])) {
return true;
}
$parentClass = static::class;
$templates = array();
while ($parentClass != __CLASS__) {
$templates[] = strtok($parentClass, '_') . '_' . $action;
$parentClass = get_parent_class($parentClass);
}
return SSViewer::hasTemplate($templates);
} | php | public function hasActionTemplate($action)
{
if (isset($this->templates[$action])) {
return true;
}
$parentClass = static::class;
$templates = array();
while ($parentClass != __CLASS__) {
$templates[] = strtok($parentClass, '_') . '_' . $action;
$parentClass = get_parent_class($parentClass);
}
return SSViewer::hasTemplate($templates);
} | [
"public",
"function",
"hasActionTemplate",
"(",
"$",
"action",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"templates",
"[",
"$",
"action",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"parentClass",
"=",
"static",
"::",
"class",
";",
"$",
"templates",
"=",
"array",
"(",
")",
";",
"while",
"(",
"$",
"parentClass",
"!=",
"__CLASS__",
")",
"{",
"$",
"templates",
"[",
"]",
"=",
"strtok",
"(",
"$",
"parentClass",
",",
"'_'",
")",
".",
"'_'",
".",
"$",
"action",
";",
"$",
"parentClass",
"=",
"get_parent_class",
"(",
"$",
"parentClass",
")",
";",
"}",
"return",
"SSViewer",
"::",
"hasTemplate",
"(",
"$",
"templates",
")",
";",
"}"
]
| Returns TRUE if this controller has a template that is specifically designed to handle a
specific action.
@param string $action
@return bool | [
"Returns",
"TRUE",
"if",
"this",
"controller",
"has",
"a",
"template",
"that",
"is",
"specifically",
"designed",
"to",
"handle",
"a",
"specific",
"action",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Control/Controller.php#L491-L506 | train |
silverstripe/silverstripe-framework | src/Control/Controller.php | Controller.can | public function can($perm, $member = null)
{
if (!$member) {
$member = Security::getCurrentUser();
}
if (is_array($perm)) {
$perm = array_map(array($this, 'can'), $perm, array_fill(0, count($perm), $member));
return min($perm);
}
if ($this->hasMethod($methodName = 'can' . $perm)) {
return $this->$methodName($member);
} else {
return true;
}
} | php | public function can($perm, $member = null)
{
if (!$member) {
$member = Security::getCurrentUser();
}
if (is_array($perm)) {
$perm = array_map(array($this, 'can'), $perm, array_fill(0, count($perm), $member));
return min($perm);
}
if ($this->hasMethod($methodName = 'can' . $perm)) {
return $this->$methodName($member);
} else {
return true;
}
} | [
"public",
"function",
"can",
"(",
"$",
"perm",
",",
"$",
"member",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"member",
")",
"{",
"$",
"member",
"=",
"Security",
"::",
"getCurrentUser",
"(",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"perm",
")",
")",
"{",
"$",
"perm",
"=",
"array_map",
"(",
"array",
"(",
"$",
"this",
",",
"'can'",
")",
",",
"$",
"perm",
",",
"array_fill",
"(",
"0",
",",
"count",
"(",
"$",
"perm",
")",
",",
"$",
"member",
")",
")",
";",
"return",
"min",
"(",
"$",
"perm",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"hasMethod",
"(",
"$",
"methodName",
"=",
"'can'",
".",
"$",
"perm",
")",
")",
"{",
"return",
"$",
"this",
"->",
"$",
"methodName",
"(",
"$",
"member",
")",
";",
"}",
"else",
"{",
"return",
"true",
";",
"}",
"}"
]
| Returns true if the member is allowed to do the given action. Defaults to the currently logged
in user.
@param string $perm
@param null|member $member
@return bool | [
"Returns",
"true",
"if",
"the",
"member",
"is",
"allowed",
"to",
"do",
"the",
"given",
"action",
".",
"Defaults",
"to",
"the",
"currently",
"logged",
"in",
"user",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Control/Controller.php#L580-L594 | train |
silverstripe/silverstripe-framework | src/ORM/ValidationResult.php | ValidationResult.combineAnd | public function combineAnd(ValidationResult $other)
{
$this->isValid = $this->isValid && $other->isValid();
$this->messages = array_merge($this->messages, $other->getMessages());
return $this;
} | php | public function combineAnd(ValidationResult $other)
{
$this->isValid = $this->isValid && $other->isValid();
$this->messages = array_merge($this->messages, $other->getMessages());
return $this;
} | [
"public",
"function",
"combineAnd",
"(",
"ValidationResult",
"$",
"other",
")",
"{",
"$",
"this",
"->",
"isValid",
"=",
"$",
"this",
"->",
"isValid",
"&&",
"$",
"other",
"->",
"isValid",
"(",
")",
";",
"$",
"this",
"->",
"messages",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"messages",
",",
"$",
"other",
"->",
"getMessages",
"(",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Combine this Validation Result with the ValidationResult given in other.
It will be valid if both this and the other result are valid.
This object will be modified to contain the new validation information.
@param ValidationResult $other the validation result object to combine
@return $this | [
"Combine",
"this",
"Validation",
"Result",
"with",
"the",
"ValidationResult",
"given",
"in",
"other",
".",
"It",
"will",
"be",
"valid",
"if",
"both",
"this",
"and",
"the",
"other",
"result",
"are",
"valid",
".",
"This",
"object",
"will",
"be",
"modified",
"to",
"contain",
"the",
"new",
"validation",
"information",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/ValidationResult.php#L210-L215 | train |
silverstripe/silverstripe-framework | src/Core/Startup/ErrorControlChainMiddleware.php | ErrorControlChainMiddleware.safeReloadWithTokens | protected function safeReloadWithTokens(HTTPRequest $request, ConfirmationTokenChain $confirmationTokenChain)
{
// Safe reload requires manual boot
$this->getApplication()->getKernel()->boot(false);
// Ensure session is started
$request->getSession()->init($request);
// Request with ErrorDirector
$result = ErrorDirector::singleton()->handleRequestWithTokenChain(
$request,
$confirmationTokenChain,
$this->getApplication()->getKernel()
);
if ($result) {
return $result;
}
// Fail and redirect the user to the login page
$params = array_merge($request->getVars(), $confirmationTokenChain->params(false));
$backURL = $confirmationTokenChain->getRedirectUrlBase() . '?' . http_build_query($params);
$loginPage = Director::absoluteURL(Security::config()->get('login_url'));
$loginPage .= "?BackURL=" . urlencode($backURL);
$result = new HTTPResponse();
$result->redirect($loginPage);
return $result;
} | php | protected function safeReloadWithTokens(HTTPRequest $request, ConfirmationTokenChain $confirmationTokenChain)
{
// Safe reload requires manual boot
$this->getApplication()->getKernel()->boot(false);
// Ensure session is started
$request->getSession()->init($request);
// Request with ErrorDirector
$result = ErrorDirector::singleton()->handleRequestWithTokenChain(
$request,
$confirmationTokenChain,
$this->getApplication()->getKernel()
);
if ($result) {
return $result;
}
// Fail and redirect the user to the login page
$params = array_merge($request->getVars(), $confirmationTokenChain->params(false));
$backURL = $confirmationTokenChain->getRedirectUrlBase() . '?' . http_build_query($params);
$loginPage = Director::absoluteURL(Security::config()->get('login_url'));
$loginPage .= "?BackURL=" . urlencode($backURL);
$result = new HTTPResponse();
$result->redirect($loginPage);
return $result;
} | [
"protected",
"function",
"safeReloadWithTokens",
"(",
"HTTPRequest",
"$",
"request",
",",
"ConfirmationTokenChain",
"$",
"confirmationTokenChain",
")",
"{",
"// Safe reload requires manual boot",
"$",
"this",
"->",
"getApplication",
"(",
")",
"->",
"getKernel",
"(",
")",
"->",
"boot",
"(",
"false",
")",
";",
"// Ensure session is started",
"$",
"request",
"->",
"getSession",
"(",
")",
"->",
"init",
"(",
"$",
"request",
")",
";",
"// Request with ErrorDirector",
"$",
"result",
"=",
"ErrorDirector",
"::",
"singleton",
"(",
")",
"->",
"handleRequestWithTokenChain",
"(",
"$",
"request",
",",
"$",
"confirmationTokenChain",
",",
"$",
"this",
"->",
"getApplication",
"(",
")",
"->",
"getKernel",
"(",
")",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"return",
"$",
"result",
";",
"}",
"// Fail and redirect the user to the login page",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"request",
"->",
"getVars",
"(",
")",
",",
"$",
"confirmationTokenChain",
"->",
"params",
"(",
"false",
")",
")",
";",
"$",
"backURL",
"=",
"$",
"confirmationTokenChain",
"->",
"getRedirectUrlBase",
"(",
")",
".",
"'?'",
".",
"http_build_query",
"(",
"$",
"params",
")",
";",
"$",
"loginPage",
"=",
"Director",
"::",
"absoluteURL",
"(",
"Security",
"::",
"config",
"(",
")",
"->",
"get",
"(",
"'login_url'",
")",
")",
";",
"$",
"loginPage",
".=",
"\"?BackURL=\"",
".",
"urlencode",
"(",
"$",
"backURL",
")",
";",
"$",
"result",
"=",
"new",
"HTTPResponse",
"(",
")",
";",
"$",
"result",
"->",
"redirect",
"(",
"$",
"loginPage",
")",
";",
"return",
"$",
"result",
";",
"}"
]
| Reload application with the given token, but only if either the user is authenticated,
or authentication is impossible.
@param HTTPRequest $request
@param ConfirmationTokenChain $confirmationTokenChain
@return HTTPResponse | [
"Reload",
"application",
"with",
"the",
"given",
"token",
"but",
"only",
"if",
"either",
"the",
"user",
"is",
"authenticated",
"or",
"authentication",
"is",
"impossible",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Startup/ErrorControlChainMiddleware.php#L104-L130 | train |
silverstripe/silverstripe-framework | src/Forms/OptionsetField.php | OptionsetField.getOptionClass | protected function getOptionClass($value, $odd)
{
$oddClass = $odd ? 'odd' : 'even';
$valueClass = ' val' . Convert::raw2htmlid($value);
return $oddClass . $valueClass;
} | php | protected function getOptionClass($value, $odd)
{
$oddClass = $odd ? 'odd' : 'even';
$valueClass = ' val' . Convert::raw2htmlid($value);
return $oddClass . $valueClass;
} | [
"protected",
"function",
"getOptionClass",
"(",
"$",
"value",
",",
"$",
"odd",
")",
"{",
"$",
"oddClass",
"=",
"$",
"odd",
"?",
"'odd'",
":",
"'even'",
";",
"$",
"valueClass",
"=",
"' val'",
".",
"Convert",
"::",
"raw2htmlid",
"(",
"$",
"value",
")",
";",
"return",
"$",
"oddClass",
".",
"$",
"valueClass",
";",
"}"
]
| Get extra classes for each item in the list
@param string $value Value of this item
@param bool $odd If this item is odd numbered in the list
@return string | [
"Get",
"extra",
"classes",
"for",
"each",
"item",
"in",
"the",
"list"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Forms/OptionsetField.php#L111-L116 | train |
silverstripe/silverstripe-framework | src/Forms/FormRequestHandler.php | FormRequestHandler.Link | public function Link($action = null)
{
// Forms without parent controller have no link;
// E.g. Submission handled via graphql
$controller = $this->form->getController();
if (empty($controller)) {
return null;
}
// Respect FormObjectLink() method
if ($controller->hasMethod("FormObjectLink")) {
$base = $controller->FormObjectLink($this->form->getName());
} else {
$base = Controller::join_links($controller->Link(), $this->form->getName());
}
// Join with action and decorate
$link = Controller::join_links($base, $action, '/');
$this->extend('updateLink', $link, $action);
return $link;
} | php | public function Link($action = null)
{
// Forms without parent controller have no link;
// E.g. Submission handled via graphql
$controller = $this->form->getController();
if (empty($controller)) {
return null;
}
// Respect FormObjectLink() method
if ($controller->hasMethod("FormObjectLink")) {
$base = $controller->FormObjectLink($this->form->getName());
} else {
$base = Controller::join_links($controller->Link(), $this->form->getName());
}
// Join with action and decorate
$link = Controller::join_links($base, $action, '/');
$this->extend('updateLink', $link, $action);
return $link;
} | [
"public",
"function",
"Link",
"(",
"$",
"action",
"=",
"null",
")",
"{",
"// Forms without parent controller have no link;",
"// E.g. Submission handled via graphql",
"$",
"controller",
"=",
"$",
"this",
"->",
"form",
"->",
"getController",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"controller",
")",
")",
"{",
"return",
"null",
";",
"}",
"// Respect FormObjectLink() method",
"if",
"(",
"$",
"controller",
"->",
"hasMethod",
"(",
"\"FormObjectLink\"",
")",
")",
"{",
"$",
"base",
"=",
"$",
"controller",
"->",
"FormObjectLink",
"(",
"$",
"this",
"->",
"form",
"->",
"getName",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"base",
"=",
"Controller",
"::",
"join_links",
"(",
"$",
"controller",
"->",
"Link",
"(",
")",
",",
"$",
"this",
"->",
"form",
"->",
"getName",
"(",
")",
")",
";",
"}",
"// Join with action and decorate",
"$",
"link",
"=",
"Controller",
"::",
"join_links",
"(",
"$",
"base",
",",
"$",
"action",
",",
"'/'",
")",
";",
"$",
"this",
"->",
"extend",
"(",
"'updateLink'",
",",
"$",
"link",
",",
"$",
"action",
")",
";",
"return",
"$",
"link",
";",
"}"
]
| Get link for this form
@param string $action
@return string | [
"Get",
"link",
"for",
"this",
"form"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Forms/FormRequestHandler.php#L77-L97 | train |
silverstripe/silverstripe-framework | src/Forms/FormRequestHandler.php | FormRequestHandler.getAjaxErrorResponse | protected function getAjaxErrorResponse(ValidationResult $result)
{
// Ajax form submissions accept json encoded errors by default
$acceptType = $this->getRequest()->getHeader('Accept');
if (strpos($acceptType, 'application/json') !== false) {
// Send validation errors back as JSON with a flag at the start
$response = new HTTPResponse(json_encode($result->getMessages()));
$response->addHeader('Content-Type', 'application/json');
return $response;
}
// Send the newly rendered form tag as HTML
$this->form->loadMessagesFrom($result);
$response = new HTTPResponse($this->form->forTemplate());
$response->addHeader('Content-Type', 'text/html');
return $response;
} | php | protected function getAjaxErrorResponse(ValidationResult $result)
{
// Ajax form submissions accept json encoded errors by default
$acceptType = $this->getRequest()->getHeader('Accept');
if (strpos($acceptType, 'application/json') !== false) {
// Send validation errors back as JSON with a flag at the start
$response = new HTTPResponse(json_encode($result->getMessages()));
$response->addHeader('Content-Type', 'application/json');
return $response;
}
// Send the newly rendered form tag as HTML
$this->form->loadMessagesFrom($result);
$response = new HTTPResponse($this->form->forTemplate());
$response->addHeader('Content-Type', 'text/html');
return $response;
} | [
"protected",
"function",
"getAjaxErrorResponse",
"(",
"ValidationResult",
"$",
"result",
")",
"{",
"// Ajax form submissions accept json encoded errors by default",
"$",
"acceptType",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"getHeader",
"(",
"'Accept'",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"acceptType",
",",
"'application/json'",
")",
"!==",
"false",
")",
"{",
"// Send validation errors back as JSON with a flag at the start",
"$",
"response",
"=",
"new",
"HTTPResponse",
"(",
"json_encode",
"(",
"$",
"result",
"->",
"getMessages",
"(",
")",
")",
")",
";",
"$",
"response",
"->",
"addHeader",
"(",
"'Content-Type'",
",",
"'application/json'",
")",
";",
"return",
"$",
"response",
";",
"}",
"// Send the newly rendered form tag as HTML",
"$",
"this",
"->",
"form",
"->",
"loadMessagesFrom",
"(",
"$",
"result",
")",
";",
"$",
"response",
"=",
"new",
"HTTPResponse",
"(",
"$",
"this",
"->",
"form",
"->",
"forTemplate",
"(",
")",
")",
";",
"$",
"response",
"->",
"addHeader",
"(",
"'Content-Type'",
",",
"'text/html'",
")",
";",
"return",
"$",
"response",
";",
"}"
]
| Build HTTP error response for ajax requests
@internal called from {@see Form::getValidationErrorResponse}
@param ValidationResult $result
@return HTTPResponse | [
"Build",
"HTTP",
"error",
"response",
"for",
"ajax",
"requests"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Forms/FormRequestHandler.php#L373-L389 | train |
silverstripe/silverstripe-framework | src/Forms/FormRequestHandler.php | FormRequestHandler.buttonClicked | public function buttonClicked()
{
$actions = $this->getAllActions();
foreach ($actions as $action) {
if ($this->buttonClickedFunc === $action->actionName()) {
return $action;
}
}
return null;
} | php | public function buttonClicked()
{
$actions = $this->getAllActions();
foreach ($actions as $action) {
if ($this->buttonClickedFunc === $action->actionName()) {
return $action;
}
}
return null;
} | [
"public",
"function",
"buttonClicked",
"(",
")",
"{",
"$",
"actions",
"=",
"$",
"this",
"->",
"getAllActions",
"(",
")",
";",
"foreach",
"(",
"$",
"actions",
"as",
"$",
"action",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"buttonClickedFunc",
"===",
"$",
"action",
"->",
"actionName",
"(",
")",
")",
"{",
"return",
"$",
"action",
";",
"}",
"}",
"return",
"null",
";",
"}"
]
| Get instance of button which was clicked for this request
@return FormAction | [
"Get",
"instance",
"of",
"button",
"which",
"was",
"clicked",
"for",
"this",
"request"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Forms/FormRequestHandler.php#L453-L462 | train |
silverstripe/silverstripe-framework | src/Forms/FormRequestHandler.php | FormRequestHandler.getAllActions | protected function getAllActions()
{
$fields = $this->form->Fields()->dataFields();
$actions = $this->form->Actions()->dataFields();
$fieldsAndActions = array_merge($fields, $actions);
$actions = array_filter($fieldsAndActions, function ($fieldOrAction) {
return $fieldOrAction instanceof FormAction;
});
return $actions;
} | php | protected function getAllActions()
{
$fields = $this->form->Fields()->dataFields();
$actions = $this->form->Actions()->dataFields();
$fieldsAndActions = array_merge($fields, $actions);
$actions = array_filter($fieldsAndActions, function ($fieldOrAction) {
return $fieldOrAction instanceof FormAction;
});
return $actions;
} | [
"protected",
"function",
"getAllActions",
"(",
")",
"{",
"$",
"fields",
"=",
"$",
"this",
"->",
"form",
"->",
"Fields",
"(",
")",
"->",
"dataFields",
"(",
")",
";",
"$",
"actions",
"=",
"$",
"this",
"->",
"form",
"->",
"Actions",
"(",
")",
"->",
"dataFields",
"(",
")",
";",
"$",
"fieldsAndActions",
"=",
"array_merge",
"(",
"$",
"fields",
",",
"$",
"actions",
")",
";",
"$",
"actions",
"=",
"array_filter",
"(",
"$",
"fieldsAndActions",
",",
"function",
"(",
"$",
"fieldOrAction",
")",
"{",
"return",
"$",
"fieldOrAction",
"instanceof",
"FormAction",
";",
"}",
")",
";",
"return",
"$",
"actions",
";",
"}"
]
| Get a list of all actions, including those in the main "fields" FieldList
@return array | [
"Get",
"a",
"list",
"of",
"all",
"actions",
"including",
"those",
"in",
"the",
"main",
"fields",
"FieldList"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Forms/FormRequestHandler.php#L469-L480 | train |
silverstripe/silverstripe-framework | src/Forms/GridField/GridState_Data.php | GridState_Data.getData | public function getData($name, $default = null)
{
if (!isset($this->data[$name])) {
$this->data[$name] = $default;
} else {
if (is_array($this->data[$name])) {
$this->data[$name] = new GridState_Data($this->data[$name]);
}
}
return $this->data[$name];
} | php | public function getData($name, $default = null)
{
if (!isset($this->data[$name])) {
$this->data[$name] = $default;
} else {
if (is_array($this->data[$name])) {
$this->data[$name] = new GridState_Data($this->data[$name]);
}
}
return $this->data[$name];
} | [
"public",
"function",
"getData",
"(",
"$",
"name",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"data",
"[",
"$",
"name",
"]",
"=",
"$",
"default",
";",
"}",
"else",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"data",
"[",
"$",
"name",
"]",
"=",
"new",
"GridState_Data",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"name",
"]",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"data",
"[",
"$",
"name",
"]",
";",
"}"
]
| Retrieve the value for the given key
@param string $name The name of the value to retrieve
@param mixed $default Default value to assign if not set
@return mixed The value associated with this key, or the value specified by $default if not set | [
"Retrieve",
"the",
"value",
"for",
"the",
"given",
"key"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Forms/GridField/GridState_Data.php#L43-L54 | train |
silverstripe/silverstripe-framework | src/Control/HTTPStreamResponse.php | HTTPStreamResponse.isSeekable | protected function isSeekable()
{
$stream = $this->getStream();
if (!$stream) {
return false;
}
$metadata = stream_get_meta_data($stream);
return $metadata['seekable'];
} | php | protected function isSeekable()
{
$stream = $this->getStream();
if (!$stream) {
return false;
}
$metadata = stream_get_meta_data($stream);
return $metadata['seekable'];
} | [
"protected",
"function",
"isSeekable",
"(",
")",
"{",
"$",
"stream",
"=",
"$",
"this",
"->",
"getStream",
"(",
")",
";",
"if",
"(",
"!",
"$",
"stream",
")",
"{",
"return",
"false",
";",
"}",
"$",
"metadata",
"=",
"stream_get_meta_data",
"(",
"$",
"stream",
")",
";",
"return",
"$",
"metadata",
"[",
"'seekable'",
"]",
";",
"}"
]
| Determine if a stream is seekable
@return bool | [
"Determine",
"if",
"a",
"stream",
"is",
"seekable"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Control/HTTPStreamResponse.php#L52-L60 | train |
silverstripe/silverstripe-framework | src/Control/HTTPStreamResponse.php | HTTPStreamResponse.consumeStream | protected function consumeStream($callback)
{
// Load from stream
$stream = $this->getStream();
if (!$stream) {
return null;
}
// Check if stream must be rewound
if ($this->consumed) {
if (!$this->isSeekable()) {
throw new BadMethodCallException(
"Unseekable stream has already been consumed"
);
}
rewind($stream);
}
// Consume
$this->consumed = true;
return $callback($stream);
} | php | protected function consumeStream($callback)
{
// Load from stream
$stream = $this->getStream();
if (!$stream) {
return null;
}
// Check if stream must be rewound
if ($this->consumed) {
if (!$this->isSeekable()) {
throw new BadMethodCallException(
"Unseekable stream has already been consumed"
);
}
rewind($stream);
}
// Consume
$this->consumed = true;
return $callback($stream);
} | [
"protected",
"function",
"consumeStream",
"(",
"$",
"callback",
")",
"{",
"// Load from stream",
"$",
"stream",
"=",
"$",
"this",
"->",
"getStream",
"(",
")",
";",
"if",
"(",
"!",
"$",
"stream",
")",
"{",
"return",
"null",
";",
"}",
"// Check if stream must be rewound",
"if",
"(",
"$",
"this",
"->",
"consumed",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isSeekable",
"(",
")",
")",
"{",
"throw",
"new",
"BadMethodCallException",
"(",
"\"Unseekable stream has already been consumed\"",
")",
";",
"}",
"rewind",
"(",
"$",
"stream",
")",
";",
"}",
"// Consume",
"$",
"this",
"->",
"consumed",
"=",
"true",
";",
"return",
"$",
"callback",
"(",
"$",
"stream",
")",
";",
"}"
]
| Safely consume the stream
@param callable $callback Callback which will perform the consumable action on the stream
@return mixed Result of $callback($stream) or null if no stream available
@throws BadMethodCallException Throws exception if stream can't be re-consumed | [
"Safely",
"consume",
"the",
"stream"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Control/HTTPStreamResponse.php#L119-L140 | train |
silverstripe/silverstripe-framework | src/Forms/UploadReceiver.php | UploadReceiver.constructUploadReceiver | protected function constructUploadReceiver()
{
// Set Upload instance
$this->setUpload(Upload::create());
// filter out '' since this would be a regex problem on JS end
$this->getValidator()->setAllowedExtensions(
array_filter(File::config()->allowed_extensions)
);
// get the lower max size
$maxUpload = File::ini2bytes(ini_get('upload_max_filesize'));
$maxPost = File::ini2bytes(ini_get('post_max_size'));
$this->getValidator()->setAllowedMaxFileSize(min($maxUpload, $maxPost));
} | php | protected function constructUploadReceiver()
{
// Set Upload instance
$this->setUpload(Upload::create());
// filter out '' since this would be a regex problem on JS end
$this->getValidator()->setAllowedExtensions(
array_filter(File::config()->allowed_extensions)
);
// get the lower max size
$maxUpload = File::ini2bytes(ini_get('upload_max_filesize'));
$maxPost = File::ini2bytes(ini_get('post_max_size'));
$this->getValidator()->setAllowedMaxFileSize(min($maxUpload, $maxPost));
} | [
"protected",
"function",
"constructUploadReceiver",
"(",
")",
"{",
"// Set Upload instance",
"$",
"this",
"->",
"setUpload",
"(",
"Upload",
"::",
"create",
"(",
")",
")",
";",
"// filter out '' since this would be a regex problem on JS end",
"$",
"this",
"->",
"getValidator",
"(",
")",
"->",
"setAllowedExtensions",
"(",
"array_filter",
"(",
"File",
"::",
"config",
"(",
")",
"->",
"allowed_extensions",
")",
")",
";",
"// get the lower max size",
"$",
"maxUpload",
"=",
"File",
"::",
"ini2bytes",
"(",
"ini_get",
"(",
"'upload_max_filesize'",
")",
")",
";",
"$",
"maxPost",
"=",
"File",
"::",
"ini2bytes",
"(",
"ini_get",
"(",
"'post_max_size'",
")",
")",
";",
"$",
"this",
"->",
"getValidator",
"(",
")",
"->",
"setAllowedMaxFileSize",
"(",
"min",
"(",
"$",
"maxUpload",
",",
"$",
"maxPost",
")",
")",
";",
"}"
]
| Bootstrap Uploadable field | [
"Bootstrap",
"Uploadable",
"field"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Forms/UploadReceiver.php#L39-L53 | train |
silverstripe/silverstripe-framework | src/ORM/Map_Iterator.php | Map_Iterator.extractValue | protected function extractValue($item, $key)
{
if (is_object($item)) {
if (method_exists($item, 'hasMethod') && $item->hasMethod($key)) {
return $item->{$key}();
}
return $item->{$key};
} else {
if (array_key_exists($key, $item)) {
return $item[$key];
}
}
} | php | protected function extractValue($item, $key)
{
if (is_object($item)) {
if (method_exists($item, 'hasMethod') && $item->hasMethod($key)) {
return $item->{$key}();
}
return $item->{$key};
} else {
if (array_key_exists($key, $item)) {
return $item[$key];
}
}
} | [
"protected",
"function",
"extractValue",
"(",
"$",
"item",
",",
"$",
"key",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"item",
")",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"item",
",",
"'hasMethod'",
")",
"&&",
"$",
"item",
"->",
"hasMethod",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"item",
"->",
"{",
"$",
"key",
"}",
"(",
")",
";",
"}",
"return",
"$",
"item",
"->",
"{",
"$",
"key",
"}",
";",
"}",
"else",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"item",
")",
")",
"{",
"return",
"$",
"item",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"}"
]
| Extracts a value from an item in the list, where the item is either an
object or array.
@param array|object $item
@param string $key
@return mixed | [
"Extracts",
"a",
"value",
"from",
"an",
"item",
"in",
"the",
"list",
"where",
"the",
"item",
"is",
"either",
"an",
"object",
"or",
"array",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Map_Iterator.php#L110-L122 | train |
silverstripe/silverstripe-framework | src/ORM/Map_Iterator.php | Map_Iterator.key | public function key()
{
if (($this->endItemIdx !== null) && isset($this->lastItems[$this->endItemIdx])) {
return $this->lastItems[$this->endItemIdx][0];
} else {
if (isset($this->firstItems[$this->firstItemIdx])) {
return $this->firstItems[$this->firstItemIdx][0];
} else {
return $this->extractValue($this->items->current(), $this->keyField);
}
}
} | php | public function key()
{
if (($this->endItemIdx !== null) && isset($this->lastItems[$this->endItemIdx])) {
return $this->lastItems[$this->endItemIdx][0];
} else {
if (isset($this->firstItems[$this->firstItemIdx])) {
return $this->firstItems[$this->firstItemIdx][0];
} else {
return $this->extractValue($this->items->current(), $this->keyField);
}
}
} | [
"public",
"function",
"key",
"(",
")",
"{",
"if",
"(",
"(",
"$",
"this",
"->",
"endItemIdx",
"!==",
"null",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"lastItems",
"[",
"$",
"this",
"->",
"endItemIdx",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"lastItems",
"[",
"$",
"this",
"->",
"endItemIdx",
"]",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"firstItems",
"[",
"$",
"this",
"->",
"firstItemIdx",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"firstItems",
"[",
"$",
"this",
"->",
"firstItemIdx",
"]",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"extractValue",
"(",
"$",
"this",
"->",
"items",
"->",
"current",
"(",
")",
",",
"$",
"this",
"->",
"keyField",
")",
";",
"}",
"}",
"}"
]
| Return the key of the current element.
@return string | [
"Return",
"the",
"key",
"of",
"the",
"current",
"element",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Map_Iterator.php#L129-L140 | train |
silverstripe/silverstripe-framework | src/Forms/HTMLEditor/HTMLEditorConfig.php | HTMLEditorConfig.get | public static function get($identifier = null)
{
if (!$identifier) {
return static::get_active();
}
// Create new instance if unconfigured
if (!isset(self::$configs[$identifier])) {
self::$configs[$identifier] = static::create();
self::$configs[$identifier]->setOption('editorIdentifier', $identifier);
}
return self::$configs[$identifier];
} | php | public static function get($identifier = null)
{
if (!$identifier) {
return static::get_active();
}
// Create new instance if unconfigured
if (!isset(self::$configs[$identifier])) {
self::$configs[$identifier] = static::create();
self::$configs[$identifier]->setOption('editorIdentifier', $identifier);
}
return self::$configs[$identifier];
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"identifier",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"identifier",
")",
"{",
"return",
"static",
"::",
"get_active",
"(",
")",
";",
"}",
"// Create new instance if unconfigured",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"configs",
"[",
"$",
"identifier",
"]",
")",
")",
"{",
"self",
"::",
"$",
"configs",
"[",
"$",
"identifier",
"]",
"=",
"static",
"::",
"create",
"(",
")",
";",
"self",
"::",
"$",
"configs",
"[",
"$",
"identifier",
"]",
"->",
"setOption",
"(",
"'editorIdentifier'",
",",
"$",
"identifier",
")",
";",
"}",
"return",
"self",
"::",
"$",
"configs",
"[",
"$",
"identifier",
"]",
";",
"}"
]
| Get the HTMLEditorConfig object for the given identifier. This is a correct way to get an HTMLEditorConfig
instance - do not call 'new'
@param string $identifier The identifier for the config set. If omitted, the active config is returned.
@return static The configuration object.
This will be created if it does not yet exist for that identifier | [
"Get",
"the",
"HTMLEditorConfig",
"object",
"for",
"the",
"given",
"identifier",
".",
"This",
"is",
"a",
"correct",
"way",
"to",
"get",
"an",
"HTMLEditorConfig",
"instance",
"-",
"do",
"not",
"call",
"new"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Forms/HTMLEditor/HTMLEditorConfig.php#L78-L89 | train |
silverstripe/silverstripe-framework | src/Forms/HTMLEditor/HTMLEditorConfig.php | HTMLEditorConfig.set_config | public static function set_config($identifier, HTMLEditorConfig $config = null)
{
if ($config) {
self::$configs[$identifier] = $config;
self::$configs[$identifier]->setOption('editorIdentifier', $identifier);
} else {
unset(self::$configs[$identifier]);
}
return $config;
} | php | public static function set_config($identifier, HTMLEditorConfig $config = null)
{
if ($config) {
self::$configs[$identifier] = $config;
self::$configs[$identifier]->setOption('editorIdentifier', $identifier);
} else {
unset(self::$configs[$identifier]);
}
return $config;
} | [
"public",
"static",
"function",
"set_config",
"(",
"$",
"identifier",
",",
"HTMLEditorConfig",
"$",
"config",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"config",
")",
"{",
"self",
"::",
"$",
"configs",
"[",
"$",
"identifier",
"]",
"=",
"$",
"config",
";",
"self",
"::",
"$",
"configs",
"[",
"$",
"identifier",
"]",
"->",
"setOption",
"(",
"'editorIdentifier'",
",",
"$",
"identifier",
")",
";",
"}",
"else",
"{",
"unset",
"(",
"self",
"::",
"$",
"configs",
"[",
"$",
"identifier",
"]",
")",
";",
"}",
"return",
"$",
"config",
";",
"}"
]
| Assign a new config, or clear existing, for the given identifier
@param string $identifier A specific identifier
@param HTMLEditorConfig $config Config to set, or null to clear
@return HTMLEditorConfig The assigned config | [
"Assign",
"a",
"new",
"config",
"or",
"clear",
"existing",
"for",
"the",
"given",
"identifier"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Forms/HTMLEditor/HTMLEditorConfig.php#L98-L107 | train |
silverstripe/silverstripe-framework | src/Forms/HTMLEditor/HTMLEditorConfig.php | HTMLEditorConfig.get_available_configs_map | public static function get_available_configs_map()
{
$configs = array();
foreach (self::$configs as $identifier => $config) {
$configs[$identifier] = $config->getOption('friendly_name');
}
return $configs;
} | php | public static function get_available_configs_map()
{
$configs = array();
foreach (self::$configs as $identifier => $config) {
$configs[$identifier] = $config->getOption('friendly_name');
}
return $configs;
} | [
"public",
"static",
"function",
"get_available_configs_map",
"(",
")",
"{",
"$",
"configs",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"self",
"::",
"$",
"configs",
"as",
"$",
"identifier",
"=>",
"$",
"config",
")",
"{",
"$",
"configs",
"[",
"$",
"identifier",
"]",
"=",
"$",
"config",
"->",
"getOption",
"(",
"'friendly_name'",
")",
";",
"}",
"return",
"$",
"configs",
";",
"}"
]
| Get the available configurations as a map of friendly_name to
configuration name.
@return array | [
"Get",
"the",
"available",
"configurations",
"as",
"a",
"map",
"of",
"friendly_name",
"to",
"configuration",
"name",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Forms/HTMLEditor/HTMLEditorConfig.php#L183-L192 | train |
silverstripe/silverstripe-framework | src/Forms/TabSet.php | TabSet.FieldHolder | public function FieldHolder($properties = array())
{
$obj = $properties ? $this->customise($properties) : $this;
return $obj->renderWith($this->getTemplates());
} | php | public function FieldHolder($properties = array())
{
$obj = $properties ? $this->customise($properties) : $this;
return $obj->renderWith($this->getTemplates());
} | [
"public",
"function",
"FieldHolder",
"(",
"$",
"properties",
"=",
"array",
"(",
")",
")",
"{",
"$",
"obj",
"=",
"$",
"properties",
"?",
"$",
"this",
"->",
"customise",
"(",
"$",
"properties",
")",
":",
"$",
"this",
";",
"return",
"$",
"obj",
"->",
"renderWith",
"(",
"$",
"this",
"->",
"getTemplates",
"(",
")",
")",
";",
"}"
]
| Returns a tab-strip and the associated tabs.
The HTML is a standardised format, containing a <ul;
@param array $properties
@return DBHTMLText|string | [
"Returns",
"a",
"tab",
"-",
"strip",
"and",
"the",
"associated",
"tabs",
".",
"The",
"HTML",
"is",
"a",
"standardised",
"format",
"containing",
"a",
"<",
";",
"ul",
";"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Forms/TabSet.php#L132-L137 | train |
silverstripe/silverstripe-framework | src/Forms/TabSet.php | TabSet.push | public function push(FormField $field)
{
if ($field instanceof Tab || $field instanceof TabSet) {
$field->setTabSet($this);
}
parent::push($field);
} | php | public function push(FormField $field)
{
if ($field instanceof Tab || $field instanceof TabSet) {
$field->setTabSet($this);
}
parent::push($field);
} | [
"public",
"function",
"push",
"(",
"FormField",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"field",
"instanceof",
"Tab",
"||",
"$",
"field",
"instanceof",
"TabSet",
")",
"{",
"$",
"field",
"->",
"setTabSet",
"(",
"$",
"this",
")",
";",
"}",
"parent",
"::",
"push",
"(",
"$",
"field",
")",
";",
"}"
]
| Add a new child field to the end of the set.
@param FormField $field | [
"Add",
"a",
"new",
"child",
"field",
"to",
"the",
"end",
"of",
"the",
"set",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Forms/TabSet.php#L195-L201 | train |
silverstripe/silverstripe-framework | src/Forms/TabSet.php | TabSet.unshift | public function unshift(FormField $field)
{
if ($field instanceof Tab || $field instanceof TabSet) {
$field->setTabSet($this);
}
parent::unshift($field);
} | php | public function unshift(FormField $field)
{
if ($field instanceof Tab || $field instanceof TabSet) {
$field->setTabSet($this);
}
parent::unshift($field);
} | [
"public",
"function",
"unshift",
"(",
"FormField",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"field",
"instanceof",
"Tab",
"||",
"$",
"field",
"instanceof",
"TabSet",
")",
"{",
"$",
"field",
"->",
"setTabSet",
"(",
"$",
"this",
")",
";",
"}",
"parent",
"::",
"unshift",
"(",
"$",
"field",
")",
";",
"}"
]
| Add a new child field to the beginning of the set.
@param FormField $field | [
"Add",
"a",
"new",
"child",
"field",
"to",
"the",
"beginning",
"of",
"the",
"set",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Forms/TabSet.php#L208-L214 | train |
silverstripe/silverstripe-framework | src/Forms/TabSet.php | TabSet.insertBefore | public function insertBefore($insertBefore, $field, $appendIfMissing = true)
{
if ($field instanceof Tab || $field instanceof TabSet) {
$field->setTabSet($this);
}
return parent::insertBefore($insertBefore, $field, $appendIfMissing);
} | php | public function insertBefore($insertBefore, $field, $appendIfMissing = true)
{
if ($field instanceof Tab || $field instanceof TabSet) {
$field->setTabSet($this);
}
return parent::insertBefore($insertBefore, $field, $appendIfMissing);
} | [
"public",
"function",
"insertBefore",
"(",
"$",
"insertBefore",
",",
"$",
"field",
",",
"$",
"appendIfMissing",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"field",
"instanceof",
"Tab",
"||",
"$",
"field",
"instanceof",
"TabSet",
")",
"{",
"$",
"field",
"->",
"setTabSet",
"(",
"$",
"this",
")",
";",
"}",
"return",
"parent",
"::",
"insertBefore",
"(",
"$",
"insertBefore",
",",
"$",
"field",
",",
"$",
"appendIfMissing",
")",
";",
"}"
]
| Inserts a field before a particular field in a FieldList.
@param string $insertBefore Name of the field to insert before
@param FormField $field The form field to insert
@return FormField|null | [
"Inserts",
"a",
"field",
"before",
"a",
"particular",
"field",
"in",
"a",
"FieldList",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Forms/TabSet.php#L223-L229 | train |
silverstripe/silverstripe-framework | src/Forms/TabSet.php | TabSet.insertAfter | public function insertAfter($insertAfter, $field, $appendIfMissing = true)
{
if ($field instanceof Tab || $field instanceof TabSet) {
$field->setTabSet($this);
}
return parent::insertAfter($insertAfter, $field, $appendIfMissing);
} | php | public function insertAfter($insertAfter, $field, $appendIfMissing = true)
{
if ($field instanceof Tab || $field instanceof TabSet) {
$field->setTabSet($this);
}
return parent::insertAfter($insertAfter, $field, $appendIfMissing);
} | [
"public",
"function",
"insertAfter",
"(",
"$",
"insertAfter",
",",
"$",
"field",
",",
"$",
"appendIfMissing",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"field",
"instanceof",
"Tab",
"||",
"$",
"field",
"instanceof",
"TabSet",
")",
"{",
"$",
"field",
"->",
"setTabSet",
"(",
"$",
"this",
")",
";",
"}",
"return",
"parent",
"::",
"insertAfter",
"(",
"$",
"insertAfter",
",",
"$",
"field",
",",
"$",
"appendIfMissing",
")",
";",
"}"
]
| Inserts a field after a particular field in a FieldList.
@param string $insertAfter Name of the field to insert after
@param FormField $field The form field to insert
@return FormField|null | [
"Inserts",
"a",
"field",
"after",
"a",
"particular",
"field",
"in",
"a",
"FieldList",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Forms/TabSet.php#L238-L244 | train |
silverstripe/silverstripe-framework | src/Core/Manifest/ModuleManifest.php | ModuleManifest.addModule | public function addModule($path)
{
$module = new Module($path, $this->base);
$name = $module->getName();
// Save if not already added
if (empty($this->modules[$name])) {
$this->modules[$name] = $module;
return;
}
// Validate duplicate module
$path = $module->getPath();
$otherPath = $this->modules[$name]->getPath();
if ($otherPath !== $path) {
throw new LogicException(
"Module {$name} is in two places - {$path} and {$otherPath}"
);
}
} | php | public function addModule($path)
{
$module = new Module($path, $this->base);
$name = $module->getName();
// Save if not already added
if (empty($this->modules[$name])) {
$this->modules[$name] = $module;
return;
}
// Validate duplicate module
$path = $module->getPath();
$otherPath = $this->modules[$name]->getPath();
if ($otherPath !== $path) {
throw new LogicException(
"Module {$name} is in two places - {$path} and {$otherPath}"
);
}
} | [
"public",
"function",
"addModule",
"(",
"$",
"path",
")",
"{",
"$",
"module",
"=",
"new",
"Module",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"base",
")",
";",
"$",
"name",
"=",
"$",
"module",
"->",
"getName",
"(",
")",
";",
"// Save if not already added",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"modules",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"modules",
"[",
"$",
"name",
"]",
"=",
"$",
"module",
";",
"return",
";",
"}",
"// Validate duplicate module",
"$",
"path",
"=",
"$",
"module",
"->",
"getPath",
"(",
")",
";",
"$",
"otherPath",
"=",
"$",
"this",
"->",
"modules",
"[",
"$",
"name",
"]",
"->",
"getPath",
"(",
")",
";",
"if",
"(",
"$",
"otherPath",
"!==",
"$",
"path",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"\"Module {$name} is in two places - {$path} and {$otherPath}\"",
")",
";",
"}",
"}"
]
| Adds a path as a module
@param string $path | [
"Adds",
"a",
"path",
"as",
"a",
"module"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Manifest/ModuleManifest.php#L74-L93 | train |
silverstripe/silverstripe-framework | src/Core/Manifest/ModuleManifest.php | ModuleManifest.activateConfig | public function activateConfig()
{
$modules = $this->getModules();
// Work in reverse priority, so the higher priority modules get later execution
/** @var Module $module */
foreach (array_reverse($modules) as $module) {
$module->activate();
}
} | php | public function activateConfig()
{
$modules = $this->getModules();
// Work in reverse priority, so the higher priority modules get later execution
/** @var Module $module */
foreach (array_reverse($modules) as $module) {
$module->activate();
}
} | [
"public",
"function",
"activateConfig",
"(",
")",
"{",
"$",
"modules",
"=",
"$",
"this",
"->",
"getModules",
"(",
")",
";",
"// Work in reverse priority, so the higher priority modules get later execution",
"/** @var Module $module */",
"foreach",
"(",
"array_reverse",
"(",
"$",
"modules",
")",
"as",
"$",
"module",
")",
"{",
"$",
"module",
"->",
"activate",
"(",
")",
";",
"}",
"}"
]
| Includes all of the php _config.php files found by this manifest. | [
"Includes",
"all",
"of",
"the",
"php",
"_config",
".",
"php",
"files",
"found",
"by",
"this",
"manifest",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Manifest/ModuleManifest.php#L147-L155 | train |
silverstripe/silverstripe-framework | src/Core/Manifest/ModuleManifest.php | ModuleManifest.getModule | public function getModule($name)
{
// Optimised find
if (isset($this->modules[$name])) {
return $this->modules[$name];
}
// Fall back to lookup by shortname
if (!strstr($name, '/')) {
foreach ($this->modules as $module) {
if (strcasecmp($module->getShortName(), $name) === 0) {
return $module;
}
}
}
return null;
} | php | public function getModule($name)
{
// Optimised find
if (isset($this->modules[$name])) {
return $this->modules[$name];
}
// Fall back to lookup by shortname
if (!strstr($name, '/')) {
foreach ($this->modules as $module) {
if (strcasecmp($module->getShortName(), $name) === 0) {
return $module;
}
}
}
return null;
} | [
"public",
"function",
"getModule",
"(",
"$",
"name",
")",
"{",
"// Optimised find",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"modules",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"modules",
"[",
"$",
"name",
"]",
";",
"}",
"// Fall back to lookup by shortname",
"if",
"(",
"!",
"strstr",
"(",
"$",
"name",
",",
"'/'",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"modules",
"as",
"$",
"module",
")",
"{",
"if",
"(",
"strcasecmp",
"(",
"$",
"module",
"->",
"getShortName",
"(",
")",
",",
"$",
"name",
")",
"===",
"0",
")",
"{",
"return",
"$",
"module",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
]
| Get module by name
@param string $name
@return Module | [
"Get",
"module",
"by",
"name"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Manifest/ModuleManifest.php#L198-L215 | train |
silverstripe/silverstripe-framework | src/Core/Manifest/ModuleManifest.php | ModuleManifest.sort | public function sort()
{
$order = static::config()->uninherited('module_priority');
$project = static::config()->get('project');
/* @var PrioritySorter $sorter */
$sorter = Injector::inst()->createWithArgs(
PrioritySorter::class . '.modulesorter',
[
$this->modules,
$order ?: []
]
);
if ($project) {
$sorter->setVariable(self::PROJECT_KEY, $project);
}
$this->modules = $sorter->getSortedList();
} | php | public function sort()
{
$order = static::config()->uninherited('module_priority');
$project = static::config()->get('project');
/* @var PrioritySorter $sorter */
$sorter = Injector::inst()->createWithArgs(
PrioritySorter::class . '.modulesorter',
[
$this->modules,
$order ?: []
]
);
if ($project) {
$sorter->setVariable(self::PROJECT_KEY, $project);
}
$this->modules = $sorter->getSortedList();
} | [
"public",
"function",
"sort",
"(",
")",
"{",
"$",
"order",
"=",
"static",
"::",
"config",
"(",
")",
"->",
"uninherited",
"(",
"'module_priority'",
")",
";",
"$",
"project",
"=",
"static",
"::",
"config",
"(",
")",
"->",
"get",
"(",
"'project'",
")",
";",
"/* @var PrioritySorter $sorter */",
"$",
"sorter",
"=",
"Injector",
"::",
"inst",
"(",
")",
"->",
"createWithArgs",
"(",
"PrioritySorter",
"::",
"class",
".",
"'.modulesorter'",
",",
"[",
"$",
"this",
"->",
"modules",
",",
"$",
"order",
"?",
":",
"[",
"]",
"]",
")",
";",
"if",
"(",
"$",
"project",
")",
"{",
"$",
"sorter",
"->",
"setVariable",
"(",
"self",
"::",
"PROJECT_KEY",
",",
"$",
"project",
")",
";",
"}",
"$",
"this",
"->",
"modules",
"=",
"$",
"sorter",
"->",
"getSortedList",
"(",
")",
";",
"}"
]
| Sort modules sorted by priority
@return void | [
"Sort",
"modules",
"sorted",
"by",
"priority"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Manifest/ModuleManifest.php#L232-L251 | train |
silverstripe/silverstripe-framework | src/Core/Manifest/ModuleManifest.php | ModuleManifest.getModuleByPath | public function getModuleByPath($path)
{
// Ensure path exists
$path = realpath($path);
if (!$path) {
return null;
}
/** @var Module $rootModule */
$rootModule = null;
// Find based on loaded modules
$modules = ModuleLoader::inst()->getManifest()->getModules();
foreach ($modules as $module) {
// Check if path is in module
if (stripos($path, realpath($module->getPath())) !== 0) {
continue;
}
// If this is the root module, keep looking in case there is a more specific module later
if (empty($module->getRelativePath())) {
$rootModule = $module;
} else {
return $module;
}
}
// Fall back to top level module
return $rootModule;
} | php | public function getModuleByPath($path)
{
// Ensure path exists
$path = realpath($path);
if (!$path) {
return null;
}
/** @var Module $rootModule */
$rootModule = null;
// Find based on loaded modules
$modules = ModuleLoader::inst()->getManifest()->getModules();
foreach ($modules as $module) {
// Check if path is in module
if (stripos($path, realpath($module->getPath())) !== 0) {
continue;
}
// If this is the root module, keep looking in case there is a more specific module later
if (empty($module->getRelativePath())) {
$rootModule = $module;
} else {
return $module;
}
}
// Fall back to top level module
return $rootModule;
} | [
"public",
"function",
"getModuleByPath",
"(",
"$",
"path",
")",
"{",
"// Ensure path exists",
"$",
"path",
"=",
"realpath",
"(",
"$",
"path",
")",
";",
"if",
"(",
"!",
"$",
"path",
")",
"{",
"return",
"null",
";",
"}",
"/** @var Module $rootModule */",
"$",
"rootModule",
"=",
"null",
";",
"// Find based on loaded modules",
"$",
"modules",
"=",
"ModuleLoader",
"::",
"inst",
"(",
")",
"->",
"getManifest",
"(",
")",
"->",
"getModules",
"(",
")",
";",
"foreach",
"(",
"$",
"modules",
"as",
"$",
"module",
")",
"{",
"// Check if path is in module",
"if",
"(",
"stripos",
"(",
"$",
"path",
",",
"realpath",
"(",
"$",
"module",
"->",
"getPath",
"(",
")",
")",
")",
"!==",
"0",
")",
"{",
"continue",
";",
"}",
"// If this is the root module, keep looking in case there is a more specific module later",
"if",
"(",
"empty",
"(",
"$",
"module",
"->",
"getRelativePath",
"(",
")",
")",
")",
"{",
"$",
"rootModule",
"=",
"$",
"module",
";",
"}",
"else",
"{",
"return",
"$",
"module",
";",
"}",
"}",
"// Fall back to top level module",
"return",
"$",
"rootModule",
";",
"}"
]
| Get module that contains the given path
@param string $path Full filesystem path to the given file
@return Module The module, or null if not a path in any module | [
"Get",
"module",
"that",
"contains",
"the",
"given",
"path"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Manifest/ModuleManifest.php#L259-L288 | train |
silverstripe/silverstripe-framework | src/i18n/Data/Intl/IntlLocales.php | IntlLocales.scriptDirection | public function scriptDirection($locale = null)
{
$dirs = static::config()->get('text_direction');
if (!$locale) {
$locale = i18n::get_locale();
}
if (isset($dirs[$locale])) {
return $dirs[$locale];
}
$lang = $this->langFromLocale($locale);
if (isset($dirs[$lang])) {
return $dirs[$lang];
}
return 'ltr';
} | php | public function scriptDirection($locale = null)
{
$dirs = static::config()->get('text_direction');
if (!$locale) {
$locale = i18n::get_locale();
}
if (isset($dirs[$locale])) {
return $dirs[$locale];
}
$lang = $this->langFromLocale($locale);
if (isset($dirs[$lang])) {
return $dirs[$lang];
}
return 'ltr';
} | [
"public",
"function",
"scriptDirection",
"(",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"dirs",
"=",
"static",
"::",
"config",
"(",
")",
"->",
"get",
"(",
"'text_direction'",
")",
";",
"if",
"(",
"!",
"$",
"locale",
")",
"{",
"$",
"locale",
"=",
"i18n",
"::",
"get_locale",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"dirs",
"[",
"$",
"locale",
"]",
")",
")",
"{",
"return",
"$",
"dirs",
"[",
"$",
"locale",
"]",
";",
"}",
"$",
"lang",
"=",
"$",
"this",
"->",
"langFromLocale",
"(",
"$",
"locale",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"dirs",
"[",
"$",
"lang",
"]",
")",
")",
"{",
"return",
"$",
"dirs",
"[",
"$",
"lang",
"]",
";",
"}",
"return",
"'ltr'",
";",
"}"
]
| Returns the script direction in format compatible with the HTML "dir" attribute.
@see http://www.w3.org/International/tutorials/bidi-xhtml/
@param string $locale Optional locale incl. region (underscored)
@return string "rtl" or "ltr" | [
"Returns",
"the",
"script",
"direction",
"in",
"format",
"compatible",
"with",
"the",
"HTML",
"dir",
"attribute",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/i18n/Data/Intl/IntlLocales.php#L1373-L1387 | train |
silverstripe/silverstripe-framework | src/i18n/Data/Intl/IntlLocales.php | IntlLocales.getLocales | public function getLocales()
{
// Cache by locale
$locale = i18n::get_locale();
if (!empty(static::$cache_locales[$locale])) {
return static::$cache_locales[$locale];
}
// Localise all locales
$locales = $this->config()->get('locales');
$localised = [];
foreach ($locales as $code => $default) {
$localised[$code] = $this->localeName($code);
}
// Save cache
static::$cache_locales[$locale] = $localised;
return $localised;
} | php | public function getLocales()
{
// Cache by locale
$locale = i18n::get_locale();
if (!empty(static::$cache_locales[$locale])) {
return static::$cache_locales[$locale];
}
// Localise all locales
$locales = $this->config()->get('locales');
$localised = [];
foreach ($locales as $code => $default) {
$localised[$code] = $this->localeName($code);
}
// Save cache
static::$cache_locales[$locale] = $localised;
return $localised;
} | [
"public",
"function",
"getLocales",
"(",
")",
"{",
"// Cache by locale",
"$",
"locale",
"=",
"i18n",
"::",
"get_locale",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"static",
"::",
"$",
"cache_locales",
"[",
"$",
"locale",
"]",
")",
")",
"{",
"return",
"static",
"::",
"$",
"cache_locales",
"[",
"$",
"locale",
"]",
";",
"}",
"// Localise all locales",
"$",
"locales",
"=",
"$",
"this",
"->",
"config",
"(",
")",
"->",
"get",
"(",
"'locales'",
")",
";",
"$",
"localised",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"locales",
"as",
"$",
"code",
"=>",
"$",
"default",
")",
"{",
"$",
"localised",
"[",
"$",
"code",
"]",
"=",
"$",
"this",
"->",
"localeName",
"(",
"$",
"code",
")",
";",
"}",
"// Save cache",
"static",
"::",
"$",
"cache_locales",
"[",
"$",
"locale",
"]",
"=",
"$",
"localised",
";",
"return",
"$",
"localised",
";",
"}"
]
| Get all locale codes and names
@return array Map of locale code => name | [
"Get",
"all",
"locale",
"codes",
"and",
"names"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/i18n/Data/Intl/IntlLocales.php#L1446-L1464 | train |
silverstripe/silverstripe-framework | src/i18n/Data/Intl/IntlLocales.php | IntlLocales.getLanguages | public function getLanguages()
{
// Cache by locale
$locale = i18n::get_locale();
if (!empty(static::$cache_languages[$locale])) {
return static::$cache_languages[$locale];
}
// Localise all languages
$languages = $this->config()->get('languages');
$localised = [];
foreach ($languages as $code => $default) {
$localised[$code] = $this->languageName($code);
}
// Save cache
static::$cache_languages[$locale] = $localised;
return $localised;
} | php | public function getLanguages()
{
// Cache by locale
$locale = i18n::get_locale();
if (!empty(static::$cache_languages[$locale])) {
return static::$cache_languages[$locale];
}
// Localise all languages
$languages = $this->config()->get('languages');
$localised = [];
foreach ($languages as $code => $default) {
$localised[$code] = $this->languageName($code);
}
// Save cache
static::$cache_languages[$locale] = $localised;
return $localised;
} | [
"public",
"function",
"getLanguages",
"(",
")",
"{",
"// Cache by locale",
"$",
"locale",
"=",
"i18n",
"::",
"get_locale",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"static",
"::",
"$",
"cache_languages",
"[",
"$",
"locale",
"]",
")",
")",
"{",
"return",
"static",
"::",
"$",
"cache_languages",
"[",
"$",
"locale",
"]",
";",
"}",
"// Localise all languages",
"$",
"languages",
"=",
"$",
"this",
"->",
"config",
"(",
")",
"->",
"get",
"(",
"'languages'",
")",
";",
"$",
"localised",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"languages",
"as",
"$",
"code",
"=>",
"$",
"default",
")",
"{",
"$",
"localised",
"[",
"$",
"code",
"]",
"=",
"$",
"this",
"->",
"languageName",
"(",
"$",
"code",
")",
";",
"}",
"// Save cache",
"static",
"::",
"$",
"cache_languages",
"[",
"$",
"locale",
"]",
"=",
"$",
"localised",
";",
"return",
"$",
"localised",
";",
"}"
]
| Get all language codes and names
@return array Map of language code => name | [
"Get",
"all",
"language",
"codes",
"and",
"names"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/i18n/Data/Intl/IntlLocales.php#L1478-L1496 | train |
silverstripe/silverstripe-framework | src/i18n/Data/Intl/IntlLocales.php | IntlLocales.getCountries | public function getCountries()
{
// Cache by locale
$locale = i18n::get_locale();
if (!empty(static::$cache_countries[$locale])) {
return static::$cache_countries[$locale];
}
// Localise all countries
$countries = $this->config()->get('countries');
$localised = [];
foreach ($countries as $code => $default) {
$localised[$code] = $this->countryName($code);
}
// Always sort by localised name, not key
$collator = new Collator(i18n::get_locale());
$collator->asort($localised);
static::$cache_countries[$locale] = $localised;
return $localised;
} | php | public function getCountries()
{
// Cache by locale
$locale = i18n::get_locale();
if (!empty(static::$cache_countries[$locale])) {
return static::$cache_countries[$locale];
}
// Localise all countries
$countries = $this->config()->get('countries');
$localised = [];
foreach ($countries as $code => $default) {
$localised[$code] = $this->countryName($code);
}
// Always sort by localised name, not key
$collator = new Collator(i18n::get_locale());
$collator->asort($localised);
static::$cache_countries[$locale] = $localised;
return $localised;
} | [
"public",
"function",
"getCountries",
"(",
")",
"{",
"// Cache by locale",
"$",
"locale",
"=",
"i18n",
"::",
"get_locale",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"static",
"::",
"$",
"cache_countries",
"[",
"$",
"locale",
"]",
")",
")",
"{",
"return",
"static",
"::",
"$",
"cache_countries",
"[",
"$",
"locale",
"]",
";",
"}",
"// Localise all countries",
"$",
"countries",
"=",
"$",
"this",
"->",
"config",
"(",
")",
"->",
"get",
"(",
"'countries'",
")",
";",
"$",
"localised",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"countries",
"as",
"$",
"code",
"=>",
"$",
"default",
")",
"{",
"$",
"localised",
"[",
"$",
"code",
"]",
"=",
"$",
"this",
"->",
"countryName",
"(",
"$",
"code",
")",
";",
"}",
"// Always sort by localised name, not key",
"$",
"collator",
"=",
"new",
"Collator",
"(",
"i18n",
"::",
"get_locale",
"(",
")",
")",
";",
"$",
"collator",
"->",
"asort",
"(",
"$",
"localised",
")",
";",
"static",
"::",
"$",
"cache_countries",
"[",
"$",
"locale",
"]",
"=",
"$",
"localised",
";",
"return",
"$",
"localised",
";",
"}"
]
| Get all country codes and names
@return array Map of country code => name | [
"Get",
"all",
"country",
"codes",
"and",
"names"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/i18n/Data/Intl/IntlLocales.php#L1532-L1552 | train |
silverstripe/silverstripe-framework | src/Core/Config/ConfigLoader.php | ConfigLoader.nest | public function nest()
{
// Nest config
$manifest = clone $this->getManifest();
// Create new blank loader with new stack (top level nesting)
$newLoader = new static;
$newLoader->pushManifest($manifest);
// Activate new loader
return $newLoader->activate();
} | php | public function nest()
{
// Nest config
$manifest = clone $this->getManifest();
// Create new blank loader with new stack (top level nesting)
$newLoader = new static;
$newLoader->pushManifest($manifest);
// Activate new loader
return $newLoader->activate();
} | [
"public",
"function",
"nest",
"(",
")",
"{",
"// Nest config",
"$",
"manifest",
"=",
"clone",
"$",
"this",
"->",
"getManifest",
"(",
")",
";",
"// Create new blank loader with new stack (top level nesting)",
"$",
"newLoader",
"=",
"new",
"static",
";",
"$",
"newLoader",
"->",
"pushManifest",
"(",
"$",
"manifest",
")",
";",
"// Activate new loader",
"return",
"$",
"newLoader",
"->",
"activate",
"(",
")",
";",
"}"
]
| Nest the config loader and activates it
@return static | [
"Nest",
"the",
"config",
"loader",
"and",
"activates",
"it"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Config/ConfigLoader.php#L94-L105 | train |
silverstripe/silverstripe-framework | src/i18n/Messages/YamlWriter.php | YamlWriter.getPluralForm | protected function getPluralForm($value)
{
// Strip non-plural keys away
if (is_array($value)) {
$forms = i18n::config()->uninherited('plurals');
$forms = array_combine($forms, $forms);
return array_intersect_key($value, $forms);
}
// Parse from string
// Note: Risky outside of 'en' locale.
return i18n::parse_plurals($value);
} | php | protected function getPluralForm($value)
{
// Strip non-plural keys away
if (is_array($value)) {
$forms = i18n::config()->uninherited('plurals');
$forms = array_combine($forms, $forms);
return array_intersect_key($value, $forms);
}
// Parse from string
// Note: Risky outside of 'en' locale.
return i18n::parse_plurals($value);
} | [
"protected",
"function",
"getPluralForm",
"(",
"$",
"value",
")",
"{",
"// Strip non-plural keys away",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"forms",
"=",
"i18n",
"::",
"config",
"(",
")",
"->",
"uninherited",
"(",
"'plurals'",
")",
";",
"$",
"forms",
"=",
"array_combine",
"(",
"$",
"forms",
",",
"$",
"forms",
")",
";",
"return",
"array_intersect_key",
"(",
"$",
"value",
",",
"$",
"forms",
")",
";",
"}",
"// Parse from string",
"// Note: Risky outside of 'en' locale.",
"return",
"i18n",
"::",
"parse_plurals",
"(",
"$",
"value",
")",
";",
"}"
]
| Get array-plural form for any value
@param array|string $value
@return array List of plural forms, or empty array if not plural | [
"Get",
"array",
"-",
"plural",
"form",
"for",
"any",
"value"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/i18n/Messages/YamlWriter.php#L134-L146 | train |
silverstripe/silverstripe-framework | src/i18n/Messages/YamlWriter.php | YamlWriter.getYaml | public function getYaml($messages, $locale)
{
$entities = $this->denormaliseMessages($messages);
$content = $this->getDumper()->dump([
$locale => $entities
], 99);
return $content;
} | php | public function getYaml($messages, $locale)
{
$entities = $this->denormaliseMessages($messages);
$content = $this->getDumper()->dump([
$locale => $entities
], 99);
return $content;
} | [
"public",
"function",
"getYaml",
"(",
"$",
"messages",
",",
"$",
"locale",
")",
"{",
"$",
"entities",
"=",
"$",
"this",
"->",
"denormaliseMessages",
"(",
"$",
"messages",
")",
";",
"$",
"content",
"=",
"$",
"this",
"->",
"getDumper",
"(",
")",
"->",
"dump",
"(",
"[",
"$",
"locale",
"=>",
"$",
"entities",
"]",
",",
"99",
")",
";",
"return",
"$",
"content",
";",
"}"
]
| Convert messages to yml ready to write
@param array $messages
@param string $locale
@return string | [
"Convert",
"messages",
"to",
"yml",
"ready",
"to",
"write"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/i18n/Messages/YamlWriter.php#L155-L162 | train |
silverstripe/silverstripe-framework | src/i18n/Messages/YamlWriter.php | YamlWriter.getClassKey | protected function getClassKey($entity)
{
$parts = explode('.', $entity);
$class = array_shift($parts);
// Ensure the `.ss` suffix gets added to the top level class rather than the key
if (count($parts) > 1 && reset($parts) === 'ss') {
$class .= '.ss';
array_shift($parts);
}
$key = implode('.', $parts);
return array($class, $key);
} | php | protected function getClassKey($entity)
{
$parts = explode('.', $entity);
$class = array_shift($parts);
// Ensure the `.ss` suffix gets added to the top level class rather than the key
if (count($parts) > 1 && reset($parts) === 'ss') {
$class .= '.ss';
array_shift($parts);
}
$key = implode('.', $parts);
return array($class, $key);
} | [
"protected",
"function",
"getClassKey",
"(",
"$",
"entity",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"entity",
")",
";",
"$",
"class",
"=",
"array_shift",
"(",
"$",
"parts",
")",
";",
"// Ensure the `.ss` suffix gets added to the top level class rather than the key",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
">",
"1",
"&&",
"reset",
"(",
"$",
"parts",
")",
"===",
"'ss'",
")",
"{",
"$",
"class",
".=",
"'.ss'",
";",
"array_shift",
"(",
"$",
"parts",
")",
";",
"}",
"$",
"key",
"=",
"implode",
"(",
"'.'",
",",
"$",
"parts",
")",
";",
"return",
"array",
"(",
"$",
"class",
",",
"$",
"key",
")",
";",
"}"
]
| Determine class and key for a localisation entity
@param string $entity
@return array Two-length array with class and key as elements | [
"Determine",
"class",
"and",
"key",
"for",
"a",
"localisation",
"entity"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/i18n/Messages/YamlWriter.php#L170-L182 | train |
silverstripe/silverstripe-framework | src/Core/Injector/Injector.php | Injector.unnest | public static function unnest()
{
// Unnest unless we would be left at 0 manifests
$loader = InjectorLoader::inst();
if ($loader->countManifests() <= 1) {
user_error(
"Unable to unnest root Injector, please make sure you don't have mis-matched nest/unnest",
E_USER_WARNING
);
} else {
$loader->popManifest();
}
return static::inst();
} | php | public static function unnest()
{
// Unnest unless we would be left at 0 manifests
$loader = InjectorLoader::inst();
if ($loader->countManifests() <= 1) {
user_error(
"Unable to unnest root Injector, please make sure you don't have mis-matched nest/unnest",
E_USER_WARNING
);
} else {
$loader->popManifest();
}
return static::inst();
} | [
"public",
"static",
"function",
"unnest",
"(",
")",
"{",
"// Unnest unless we would be left at 0 manifests",
"$",
"loader",
"=",
"InjectorLoader",
"::",
"inst",
"(",
")",
";",
"if",
"(",
"$",
"loader",
"->",
"countManifests",
"(",
")",
"<=",
"1",
")",
"{",
"user_error",
"(",
"\"Unable to unnest root Injector, please make sure you don't have mis-matched nest/unnest\"",
",",
"E_USER_WARNING",
")",
";",
"}",
"else",
"{",
"$",
"loader",
"->",
"popManifest",
"(",
")",
";",
"}",
"return",
"static",
"::",
"inst",
"(",
")",
";",
"}"
]
| Change the active Injector back to the Injector instance the current active
Injector object was copied from.
@return Injector Reference to restored active Injector instance | [
"Change",
"the",
"active",
"Injector",
"back",
"to",
"the",
"Injector",
"instance",
"the",
"current",
"active",
"Injector",
"object",
"was",
"copied",
"from",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Injector/Injector.php#L278-L291 | train |
silverstripe/silverstripe-framework | src/Core/Injector/Injector.php | Injector.load | public function load($config = array())
{
foreach ($config as $specId => $spec) {
if (is_string($spec)) {
$spec = array('class' => $spec);
}
$file = isset($spec['src']) ? $spec['src'] : null;
// class is whatever's explicitly set,
$class = isset($spec['class']) ? $spec['class'] : null;
// or the specid if nothing else available.
if (!$class && is_string($specId)) {
$class = $specId;
}
// make sure the class is set...
if (empty($class)) {
throw new InvalidArgumentException('Missing spec class');
}
$spec['class'] = $class;
$id = is_string($specId)
? $specId
: (isset($spec['id']) ? $spec['id'] : $class);
$priority = isset($spec['priority']) ? $spec['priority'] : 1;
// see if we already have this defined. If so, check priority weighting
if (isset($this->specs[$id]) && isset($this->specs[$id]['priority'])) {
if ($this->specs[$id]['priority'] > $priority) {
return $this;
}
}
// okay, actually include it now we know we're going to use it
if (file_exists($file)) {
require_once $file;
}
// make sure to set the id for later when instantiating
// to ensure we get cached
$spec['id'] = $id;
// We've removed this check because new functionality means that the 'class' field doesn't need to refer
// specifically to a class anymore - it could be a compound statement, ala SilverStripe's old Object::create
// functionality
//
// if (!class_exists($class)) {
// throw new Exception("Failed to load '$class' from $file");
// }
// store the specs for now - we lazy load on demand later on.
$this->specs[$id] = $spec;
// EXCEPT when there's already an existing instance at this id.
// if so, we need to instantiate and replace immediately
if (isset($this->serviceCache[$id])) {
$this->updateSpecConstructor($spec);
$this->instantiate($spec, $id);
}
}
return $this;
} | php | public function load($config = array())
{
foreach ($config as $specId => $spec) {
if (is_string($spec)) {
$spec = array('class' => $spec);
}
$file = isset($spec['src']) ? $spec['src'] : null;
// class is whatever's explicitly set,
$class = isset($spec['class']) ? $spec['class'] : null;
// or the specid if nothing else available.
if (!$class && is_string($specId)) {
$class = $specId;
}
// make sure the class is set...
if (empty($class)) {
throw new InvalidArgumentException('Missing spec class');
}
$spec['class'] = $class;
$id = is_string($specId)
? $specId
: (isset($spec['id']) ? $spec['id'] : $class);
$priority = isset($spec['priority']) ? $spec['priority'] : 1;
// see if we already have this defined. If so, check priority weighting
if (isset($this->specs[$id]) && isset($this->specs[$id]['priority'])) {
if ($this->specs[$id]['priority'] > $priority) {
return $this;
}
}
// okay, actually include it now we know we're going to use it
if (file_exists($file)) {
require_once $file;
}
// make sure to set the id for later when instantiating
// to ensure we get cached
$spec['id'] = $id;
// We've removed this check because new functionality means that the 'class' field doesn't need to refer
// specifically to a class anymore - it could be a compound statement, ala SilverStripe's old Object::create
// functionality
//
// if (!class_exists($class)) {
// throw new Exception("Failed to load '$class' from $file");
// }
// store the specs for now - we lazy load on demand later on.
$this->specs[$id] = $spec;
// EXCEPT when there's already an existing instance at this id.
// if so, we need to instantiate and replace immediately
if (isset($this->serviceCache[$id])) {
$this->updateSpecConstructor($spec);
$this->instantiate($spec, $id);
}
}
return $this;
} | [
"public",
"function",
"load",
"(",
"$",
"config",
"=",
"array",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"config",
"as",
"$",
"specId",
"=>",
"$",
"spec",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"spec",
")",
")",
"{",
"$",
"spec",
"=",
"array",
"(",
"'class'",
"=>",
"$",
"spec",
")",
";",
"}",
"$",
"file",
"=",
"isset",
"(",
"$",
"spec",
"[",
"'src'",
"]",
")",
"?",
"$",
"spec",
"[",
"'src'",
"]",
":",
"null",
";",
"// class is whatever's explicitly set,",
"$",
"class",
"=",
"isset",
"(",
"$",
"spec",
"[",
"'class'",
"]",
")",
"?",
"$",
"spec",
"[",
"'class'",
"]",
":",
"null",
";",
"// or the specid if nothing else available.",
"if",
"(",
"!",
"$",
"class",
"&&",
"is_string",
"(",
"$",
"specId",
")",
")",
"{",
"$",
"class",
"=",
"$",
"specId",
";",
"}",
"// make sure the class is set...",
"if",
"(",
"empty",
"(",
"$",
"class",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Missing spec class'",
")",
";",
"}",
"$",
"spec",
"[",
"'class'",
"]",
"=",
"$",
"class",
";",
"$",
"id",
"=",
"is_string",
"(",
"$",
"specId",
")",
"?",
"$",
"specId",
":",
"(",
"isset",
"(",
"$",
"spec",
"[",
"'id'",
"]",
")",
"?",
"$",
"spec",
"[",
"'id'",
"]",
":",
"$",
"class",
")",
";",
"$",
"priority",
"=",
"isset",
"(",
"$",
"spec",
"[",
"'priority'",
"]",
")",
"?",
"$",
"spec",
"[",
"'priority'",
"]",
":",
"1",
";",
"// see if we already have this defined. If so, check priority weighting",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"specs",
"[",
"$",
"id",
"]",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"specs",
"[",
"$",
"id",
"]",
"[",
"'priority'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"specs",
"[",
"$",
"id",
"]",
"[",
"'priority'",
"]",
">",
"$",
"priority",
")",
"{",
"return",
"$",
"this",
";",
"}",
"}",
"// okay, actually include it now we know we're going to use it",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"require_once",
"$",
"file",
";",
"}",
"// make sure to set the id for later when instantiating",
"// to ensure we get cached",
"$",
"spec",
"[",
"'id'",
"]",
"=",
"$",
"id",
";",
"// We've removed this check because new functionality means that the 'class' field doesn't need to refer",
"// specifically to a class anymore - it could be a compound statement, ala SilverStripe's old Object::create",
"// functionality",
"//",
"// if (!class_exists($class)) {",
"// throw new Exception(\"Failed to load '$class' from $file\");",
"// }",
"// store the specs for now - we lazy load on demand later on.",
"$",
"this",
"->",
"specs",
"[",
"$",
"id",
"]",
"=",
"$",
"spec",
";",
"// EXCEPT when there's already an existing instance at this id.",
"// if so, we need to instantiate and replace immediately",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"serviceCache",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"this",
"->",
"updateSpecConstructor",
"(",
"$",
"spec",
")",
";",
"$",
"this",
"->",
"instantiate",
"(",
"$",
"spec",
",",
"$",
"id",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Load services using the passed in configuration for those services
@param array $config
@return $this | [
"Load",
"services",
"using",
"the",
"passed",
"in",
"configuration",
"for",
"those",
"services"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Injector/Injector.php#L385-L450 | train |
silverstripe/silverstripe-framework | src/Core/Injector/Injector.php | Injector.updateSpec | public function updateSpec($id, $property, $value, $append = true)
{
if (isset($this->specs[$id]['properties'][$property])) {
// by ref so we're updating the actual value
$current = &$this->specs[$id]['properties'][$property];
if (is_array($current) && $append) {
$current[] = $value;
} else {
$this->specs[$id]['properties'][$property] = $value;
}
// and reload the object; existing bindings don't get
// updated though! (for now...)
if (isset($this->serviceCache[$id])) {
$this->instantiate(array('class'=>$id), $id);
}
}
} | php | public function updateSpec($id, $property, $value, $append = true)
{
if (isset($this->specs[$id]['properties'][$property])) {
// by ref so we're updating the actual value
$current = &$this->specs[$id]['properties'][$property];
if (is_array($current) && $append) {
$current[] = $value;
} else {
$this->specs[$id]['properties'][$property] = $value;
}
// and reload the object; existing bindings don't get
// updated though! (for now...)
if (isset($this->serviceCache[$id])) {
$this->instantiate(array('class'=>$id), $id);
}
}
} | [
"public",
"function",
"updateSpec",
"(",
"$",
"id",
",",
"$",
"property",
",",
"$",
"value",
",",
"$",
"append",
"=",
"true",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"specs",
"[",
"$",
"id",
"]",
"[",
"'properties'",
"]",
"[",
"$",
"property",
"]",
")",
")",
"{",
"// by ref so we're updating the actual value",
"$",
"current",
"=",
"&",
"$",
"this",
"->",
"specs",
"[",
"$",
"id",
"]",
"[",
"'properties'",
"]",
"[",
"$",
"property",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"current",
")",
"&&",
"$",
"append",
")",
"{",
"$",
"current",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"specs",
"[",
"$",
"id",
"]",
"[",
"'properties'",
"]",
"[",
"$",
"property",
"]",
"=",
"$",
"value",
";",
"}",
"// and reload the object; existing bindings don't get",
"// updated though! (for now...)",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"serviceCache",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"this",
"->",
"instantiate",
"(",
"array",
"(",
"'class'",
"=>",
"$",
"id",
")",
",",
"$",
"id",
")",
";",
"}",
"}",
"}"
]
| Update the configuration of an already defined service
Use this if you don't want to register a complete new config, just append
to an existing configuration. Helpful to avoid overwriting someone else's changes
updateSpec('RequestProcessor', 'filters', '%$MyFilter')
@param string $id
The name of the service to update the definition for
@param string $property
The name of the property to update.
@param mixed $value
The value to set
@param boolean $append
Whether to append (the default) when the property is an array | [
"Update",
"the",
"configuration",
"of",
"an",
"already",
"defined",
"service"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Injector/Injector.php#L469-L486 | train |
silverstripe/silverstripe-framework | src/Core/Injector/Injector.php | Injector.convertServiceProperty | public function convertServiceProperty($value)
{
if (is_array($value)) {
$newVal = array();
foreach ($value as $k => $v) {
$newVal[$k] = $this->convertServiceProperty($v);
}
return $newVal;
}
// Evaluate service references
if (is_string($value) && strpos($value, '%$') === 0) {
$id = substr($value, 2);
return $this->get($id);
}
// Evaluate constants surrounded by back ticks
if (preg_match('/^`(?<name>[^`]+)`$/', $value, $matches)) {
$envValue = Environment::getEnv($matches['name']);
if ($envValue !== false) {
$value = $envValue;
} elseif (defined($matches['name'])) {
$value = constant($matches['name']);
} else {
$value = null;
}
}
return $value;
} | php | public function convertServiceProperty($value)
{
if (is_array($value)) {
$newVal = array();
foreach ($value as $k => $v) {
$newVal[$k] = $this->convertServiceProperty($v);
}
return $newVal;
}
// Evaluate service references
if (is_string($value) && strpos($value, '%$') === 0) {
$id = substr($value, 2);
return $this->get($id);
}
// Evaluate constants surrounded by back ticks
if (preg_match('/^`(?<name>[^`]+)`$/', $value, $matches)) {
$envValue = Environment::getEnv($matches['name']);
if ($envValue !== false) {
$value = $envValue;
} elseif (defined($matches['name'])) {
$value = constant($matches['name']);
} else {
$value = null;
}
}
return $value;
} | [
"public",
"function",
"convertServiceProperty",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"newVal",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"newVal",
"[",
"$",
"k",
"]",
"=",
"$",
"this",
"->",
"convertServiceProperty",
"(",
"$",
"v",
")",
";",
"}",
"return",
"$",
"newVal",
";",
"}",
"// Evaluate service references",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
"&&",
"strpos",
"(",
"$",
"value",
",",
"'%$'",
")",
"===",
"0",
")",
"{",
"$",
"id",
"=",
"substr",
"(",
"$",
"value",
",",
"2",
")",
";",
"return",
"$",
"this",
"->",
"get",
"(",
"$",
"id",
")",
";",
"}",
"// Evaluate constants surrounded by back ticks",
"if",
"(",
"preg_match",
"(",
"'/^`(?<name>[^`]+)`$/'",
",",
"$",
"value",
",",
"$",
"matches",
")",
")",
"{",
"$",
"envValue",
"=",
"Environment",
"::",
"getEnv",
"(",
"$",
"matches",
"[",
"'name'",
"]",
")",
";",
"if",
"(",
"$",
"envValue",
"!==",
"false",
")",
"{",
"$",
"value",
"=",
"$",
"envValue",
";",
"}",
"elseif",
"(",
"defined",
"(",
"$",
"matches",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"value",
"=",
"constant",
"(",
"$",
"matches",
"[",
"'name'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"null",
";",
"}",
"}",
"return",
"$",
"value",
";",
"}"
]
| Recursively convert a value into its proper representation with service references
resolved to actual objects
@param string $value
@return array|mixed|string | [
"Recursively",
"convert",
"a",
"value",
"into",
"its",
"proper",
"representation",
"with",
"service",
"references",
"resolved",
"to",
"actual",
"objects"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Injector/Injector.php#L510-L539 | train |
silverstripe/silverstripe-framework | src/Core/Injector/Injector.php | Injector.instantiate | protected function instantiate($spec, $id = null, $type = null)
{
if (is_string($spec)) {
$spec = array('class' => $spec);
}
$class = $spec['class'];
// create the object, using any constructor bindings
$constructorParams = array();
if (isset($spec['constructor']) && is_array($spec['constructor'])) {
$constructorParams = $spec['constructor'];
}
// If we're dealing with a DataObject singleton without specific constructor params, pass through Singleton
// flag as second argument
if ((!$type || $type !== self::PROTOTYPE)
&& empty($constructorParams)
&& is_subclass_of($class, DataObject::class)) {
$constructorParams = array(null, true);
}
$factory = isset($spec['factory']) ? $this->get($spec['factory']) : $this->getObjectCreator();
$object = $factory->create($class, $constructorParams);
// Handle empty factory responses
if (!$object) {
return null;
}
// figure out if we have a specific id set or not. In some cases, we might be instantiating objects
// that we don't manage directly; we don't want to store these in the service cache below
if (!$id) {
$id = isset($spec['id']) ? $spec['id'] : null;
}
// now set the service in place if needbe. This is NOT done for prototype beans, as they're
// created anew each time
if (!$type) {
$type = isset($spec['type']) ? $spec['type'] : null;
}
if ($id && (!$type || $type !== self::PROTOTYPE)) {
// this ABSOLUTELY must be set before the object is injected.
// This prevents circular reference errors down the line
$this->serviceCache[$id] = $object;
}
// now inject safely
$this->inject($object, $id);
return $object;
} | php | protected function instantiate($spec, $id = null, $type = null)
{
if (is_string($spec)) {
$spec = array('class' => $spec);
}
$class = $spec['class'];
// create the object, using any constructor bindings
$constructorParams = array();
if (isset($spec['constructor']) && is_array($spec['constructor'])) {
$constructorParams = $spec['constructor'];
}
// If we're dealing with a DataObject singleton without specific constructor params, pass through Singleton
// flag as second argument
if ((!$type || $type !== self::PROTOTYPE)
&& empty($constructorParams)
&& is_subclass_of($class, DataObject::class)) {
$constructorParams = array(null, true);
}
$factory = isset($spec['factory']) ? $this->get($spec['factory']) : $this->getObjectCreator();
$object = $factory->create($class, $constructorParams);
// Handle empty factory responses
if (!$object) {
return null;
}
// figure out if we have a specific id set or not. In some cases, we might be instantiating objects
// that we don't manage directly; we don't want to store these in the service cache below
if (!$id) {
$id = isset($spec['id']) ? $spec['id'] : null;
}
// now set the service in place if needbe. This is NOT done for prototype beans, as they're
// created anew each time
if (!$type) {
$type = isset($spec['type']) ? $spec['type'] : null;
}
if ($id && (!$type || $type !== self::PROTOTYPE)) {
// this ABSOLUTELY must be set before the object is injected.
// This prevents circular reference errors down the line
$this->serviceCache[$id] = $object;
}
// now inject safely
$this->inject($object, $id);
return $object;
} | [
"protected",
"function",
"instantiate",
"(",
"$",
"spec",
",",
"$",
"id",
"=",
"null",
",",
"$",
"type",
"=",
"null",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"spec",
")",
")",
"{",
"$",
"spec",
"=",
"array",
"(",
"'class'",
"=>",
"$",
"spec",
")",
";",
"}",
"$",
"class",
"=",
"$",
"spec",
"[",
"'class'",
"]",
";",
"// create the object, using any constructor bindings",
"$",
"constructorParams",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"spec",
"[",
"'constructor'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"spec",
"[",
"'constructor'",
"]",
")",
")",
"{",
"$",
"constructorParams",
"=",
"$",
"spec",
"[",
"'constructor'",
"]",
";",
"}",
"// If we're dealing with a DataObject singleton without specific constructor params, pass through Singleton",
"// flag as second argument",
"if",
"(",
"(",
"!",
"$",
"type",
"||",
"$",
"type",
"!==",
"self",
"::",
"PROTOTYPE",
")",
"&&",
"empty",
"(",
"$",
"constructorParams",
")",
"&&",
"is_subclass_of",
"(",
"$",
"class",
",",
"DataObject",
"::",
"class",
")",
")",
"{",
"$",
"constructorParams",
"=",
"array",
"(",
"null",
",",
"true",
")",
";",
"}",
"$",
"factory",
"=",
"isset",
"(",
"$",
"spec",
"[",
"'factory'",
"]",
")",
"?",
"$",
"this",
"->",
"get",
"(",
"$",
"spec",
"[",
"'factory'",
"]",
")",
":",
"$",
"this",
"->",
"getObjectCreator",
"(",
")",
";",
"$",
"object",
"=",
"$",
"factory",
"->",
"create",
"(",
"$",
"class",
",",
"$",
"constructorParams",
")",
";",
"// Handle empty factory responses",
"if",
"(",
"!",
"$",
"object",
")",
"{",
"return",
"null",
";",
"}",
"// figure out if we have a specific id set or not. In some cases, we might be instantiating objects",
"// that we don't manage directly; we don't want to store these in the service cache below",
"if",
"(",
"!",
"$",
"id",
")",
"{",
"$",
"id",
"=",
"isset",
"(",
"$",
"spec",
"[",
"'id'",
"]",
")",
"?",
"$",
"spec",
"[",
"'id'",
"]",
":",
"null",
";",
"}",
"// now set the service in place if needbe. This is NOT done for prototype beans, as they're",
"// created anew each time",
"if",
"(",
"!",
"$",
"type",
")",
"{",
"$",
"type",
"=",
"isset",
"(",
"$",
"spec",
"[",
"'type'",
"]",
")",
"?",
"$",
"spec",
"[",
"'type'",
"]",
":",
"null",
";",
"}",
"if",
"(",
"$",
"id",
"&&",
"(",
"!",
"$",
"type",
"||",
"$",
"type",
"!==",
"self",
"::",
"PROTOTYPE",
")",
")",
"{",
"// this ABSOLUTELY must be set before the object is injected.",
"// This prevents circular reference errors down the line",
"$",
"this",
"->",
"serviceCache",
"[",
"$",
"id",
"]",
"=",
"$",
"object",
";",
"}",
"// now inject safely",
"$",
"this",
"->",
"inject",
"(",
"$",
"object",
",",
"$",
"id",
")",
";",
"return",
"$",
"object",
";",
"}"
]
| Instantiate a managed object
Given a specification of the form
array(
'class' => 'ClassName',
'properties' => array('property' => 'scalar', 'other' => '%$BeanRef')
'id' => 'ServiceId',
'type' => 'singleton|prototype'
)
will create a new object, store it in the service registry, and
set any relevant properties
Optionally, you can pass a class name directly for creation
To access this from the outside, you should call ->get('Name') to ensure
the appropriate checks are made on the specific type.
@param array $spec
The specification of the class to instantiate
@param string $id
The name of the object being created. If not supplied, then the id will be inferred from the
object being created
@param string $type
Whether to create as a singleton or prototype object. Allows code to be explicit as to how it
wants the object to be returned
@return object | [
"Instantiate",
"a",
"managed",
"object"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Injector/Injector.php#L572-L623 | train |
silverstripe/silverstripe-framework | src/Core/Injector/Injector.php | Injector.setObjectProperty | protected function setObjectProperty($object, $name, $value)
{
if (ClassInfo::hasMethod($object, 'set' . $name)) {
$object->{'set' . $name}($value);
} else {
$object->$name = $value;
}
} | php | protected function setObjectProperty($object, $name, $value)
{
if (ClassInfo::hasMethod($object, 'set' . $name)) {
$object->{'set' . $name}($value);
} else {
$object->$name = $value;
}
} | [
"protected",
"function",
"setObjectProperty",
"(",
"$",
"object",
",",
"$",
"name",
",",
"$",
"value",
")",
"{",
"if",
"(",
"ClassInfo",
"::",
"hasMethod",
"(",
"$",
"object",
",",
"'set'",
".",
"$",
"name",
")",
")",
"{",
"$",
"object",
"->",
"{",
"'set'",
".",
"$",
"name",
"}",
"(",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"object",
"->",
"$",
"name",
"=",
"$",
"value",
";",
"}",
"}"
]
| Helper to set a property's value
@param object $object
Set an object's property to a specific value
@param string $name
The name of the property to set
@param mixed $value
The value to set | [
"Helper",
"to",
"set",
"a",
"property",
"s",
"value"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Injector/Injector.php#L804-L811 | train |
silverstripe/silverstripe-framework | src/Core/Injector/Injector.php | Injector.getServiceName | public function getServiceName($name)
{
// Lazy load in spec (disable inheritance to check exact service name)
if ($this->getServiceSpec($name, false)) {
return $name;
}
// okay, check whether we've got a compound name - don't worry about 0 index, cause that's an
// invalid name
if (!strpos($name, '.')) {
return null;
}
return $this->getServiceName(substr($name, 0, strrpos($name, '.')));
} | php | public function getServiceName($name)
{
// Lazy load in spec (disable inheritance to check exact service name)
if ($this->getServiceSpec($name, false)) {
return $name;
}
// okay, check whether we've got a compound name - don't worry about 0 index, cause that's an
// invalid name
if (!strpos($name, '.')) {
return null;
}
return $this->getServiceName(substr($name, 0, strrpos($name, '.')));
} | [
"public",
"function",
"getServiceName",
"(",
"$",
"name",
")",
"{",
"// Lazy load in spec (disable inheritance to check exact service name)",
"if",
"(",
"$",
"this",
"->",
"getServiceSpec",
"(",
"$",
"name",
",",
"false",
")",
")",
"{",
"return",
"$",
"name",
";",
"}",
"// okay, check whether we've got a compound name - don't worry about 0 index, cause that's an",
"// invalid name",
"if",
"(",
"!",
"strpos",
"(",
"$",
"name",
",",
"'.'",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"getServiceName",
"(",
"substr",
"(",
"$",
"name",
",",
"0",
",",
"strrpos",
"(",
"$",
"name",
",",
"'.'",
")",
")",
")",
";",
"}"
]
| Does the given service exist, and if so, what's the stored name for it?
We do a special check here for services that are using compound names. For example,
we might want to say that a property should be injected with Log.File or Log.Memory,
but have only registered a 'Log' service, we'll instead return that.
Will recursively call itself for each depth of dotting.
@param string $name
@return string|null The name of the service (as it might be different from the one passed in) | [
"Does",
"the",
"given",
"service",
"exist",
"and",
"if",
"so",
"what",
"s",
"the",
"stored",
"name",
"for",
"it?"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Injector/Injector.php#L854-L868 | train |
silverstripe/silverstripe-framework | src/Core/Injector/Injector.php | Injector.registerService | public function registerService($service, $replace = null)
{
$registerAt = get_class($service);
if ($replace !== null) {
$registerAt = $replace;
}
$this->specs[$registerAt] = array('class' => get_class($service));
$this->serviceCache[$registerAt] = $service;
return $this;
} | php | public function registerService($service, $replace = null)
{
$registerAt = get_class($service);
if ($replace !== null) {
$registerAt = $replace;
}
$this->specs[$registerAt] = array('class' => get_class($service));
$this->serviceCache[$registerAt] = $service;
return $this;
} | [
"public",
"function",
"registerService",
"(",
"$",
"service",
",",
"$",
"replace",
"=",
"null",
")",
"{",
"$",
"registerAt",
"=",
"get_class",
"(",
"$",
"service",
")",
";",
"if",
"(",
"$",
"replace",
"!==",
"null",
")",
"{",
"$",
"registerAt",
"=",
"$",
"replace",
";",
"}",
"$",
"this",
"->",
"specs",
"[",
"$",
"registerAt",
"]",
"=",
"array",
"(",
"'class'",
"=>",
"get_class",
"(",
"$",
"service",
")",
")",
";",
"$",
"this",
"->",
"serviceCache",
"[",
"$",
"registerAt",
"]",
"=",
"$",
"service",
";",
"return",
"$",
"this",
";",
"}"
]
| Register a service object with an optional name to register it as the
service for
@param object $service The object to register
@param string $replace The name of the object to replace (if different to the
class name of the object to register)
@return $this | [
"Register",
"a",
"service",
"object",
"with",
"an",
"optional",
"name",
"to",
"register",
"it",
"as",
"the",
"service",
"for"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Injector/Injector.php#L879-L889 | train |
silverstripe/silverstripe-framework | src/Core/Injector/Injector.php | Injector.unregisterObjects | public function unregisterObjects($types)
{
if (!is_array($types)) {
$types = [ $types ];
}
// Filter all objects
foreach ($this->serviceCache as $key => $object) {
foreach ($types as $filterClass) {
// Prevent destructive flushing
if (strcasecmp($filterClass, 'object') === 0) {
throw new InvalidArgumentException("Global unregistration is not allowed");
}
if ($object instanceof $filterClass) {
$this->unregisterNamedObject($key);
break;
}
}
}
return $this;
} | php | public function unregisterObjects($types)
{
if (!is_array($types)) {
$types = [ $types ];
}
// Filter all objects
foreach ($this->serviceCache as $key => $object) {
foreach ($types as $filterClass) {
// Prevent destructive flushing
if (strcasecmp($filterClass, 'object') === 0) {
throw new InvalidArgumentException("Global unregistration is not allowed");
}
if ($object instanceof $filterClass) {
$this->unregisterNamedObject($key);
break;
}
}
}
return $this;
} | [
"public",
"function",
"unregisterObjects",
"(",
"$",
"types",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"types",
")",
")",
"{",
"$",
"types",
"=",
"[",
"$",
"types",
"]",
";",
"}",
"// Filter all objects",
"foreach",
"(",
"$",
"this",
"->",
"serviceCache",
"as",
"$",
"key",
"=>",
"$",
"object",
")",
"{",
"foreach",
"(",
"$",
"types",
"as",
"$",
"filterClass",
")",
"{",
"// Prevent destructive flushing",
"if",
"(",
"strcasecmp",
"(",
"$",
"filterClass",
",",
"'object'",
")",
"===",
"0",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Global unregistration is not allowed\"",
")",
";",
"}",
"if",
"(",
"$",
"object",
"instanceof",
"$",
"filterClass",
")",
"{",
"$",
"this",
"->",
"unregisterNamedObject",
"(",
"$",
"key",
")",
";",
"break",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Clear out objects of one or more types that are managed by the injetor.
@param array|string $types Base class of object (not service name) to remove
@return $this | [
"Clear",
"out",
"objects",
"of",
"one",
"or",
"more",
"types",
"that",
"are",
"managed",
"by",
"the",
"injetor",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Injector/Injector.php#L911-L931 | train |
silverstripe/silverstripe-framework | src/Core/Injector/Injector.php | Injector.get | public function get($name, $asSingleton = true, $constructorArgs = [])
{
$object = $this->getNamedService($name, $asSingleton, $constructorArgs);
if (!$object) {
throw new InjectorNotFoundException("The '{$name}' service could not be found");
}
return $object;
} | php | public function get($name, $asSingleton = true, $constructorArgs = [])
{
$object = $this->getNamedService($name, $asSingleton, $constructorArgs);
if (!$object) {
throw new InjectorNotFoundException("The '{$name}' service could not be found");
}
return $object;
} | [
"public",
"function",
"get",
"(",
"$",
"name",
",",
"$",
"asSingleton",
"=",
"true",
",",
"$",
"constructorArgs",
"=",
"[",
"]",
")",
"{",
"$",
"object",
"=",
"$",
"this",
"->",
"getNamedService",
"(",
"$",
"name",
",",
"$",
"asSingleton",
",",
"$",
"constructorArgs",
")",
";",
"if",
"(",
"!",
"$",
"object",
")",
"{",
"throw",
"new",
"InjectorNotFoundException",
"(",
"\"The '{$name}' service could not be found\"",
")",
";",
"}",
"return",
"$",
"object",
";",
"}"
]
| Get a named managed object
Will first check to see if the item has been registered as a configured service/bean
and return that if so.
Next, will check to see if there's any registered configuration for the given type
and will then try and load that
Failing all of that, will just return a new instance of the specified object.
@throws NotFoundExceptionInterface No entry was found for **this** identifier.
@param string $name The name of the service to retrieve. If not a registered
service, then a class of the given name is instantiated
@param bool $asSingleton If set to false a new instance will be returned.
If true a singleton will be returned unless the spec is type=prototype'
@param array $constructorArgs Args to pass in to the constructor. Note: Ignored for singletons
@return mixed Instance of the specified object | [
"Get",
"a",
"named",
"managed",
"object"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Injector/Injector.php#L953-L962 | train |
silverstripe/silverstripe-framework | src/Core/Injector/Injector.php | Injector.getServiceNamedSpec | protected function getServiceNamedSpec($name, $constructorArgs = [])
{
$spec = $this->getServiceSpec($name);
if ($spec) {
// Resolve to exact service name (in case inherited)
$name = $this->getServiceName($name);
} else {
// Late-generate config spec for non-configured spec
$spec = [
'class' => $name,
'constructor' => $constructorArgs,
];
}
return [$name, $spec];
} | php | protected function getServiceNamedSpec($name, $constructorArgs = [])
{
$spec = $this->getServiceSpec($name);
if ($spec) {
// Resolve to exact service name (in case inherited)
$name = $this->getServiceName($name);
} else {
// Late-generate config spec for non-configured spec
$spec = [
'class' => $name,
'constructor' => $constructorArgs,
];
}
return [$name, $spec];
} | [
"protected",
"function",
"getServiceNamedSpec",
"(",
"$",
"name",
",",
"$",
"constructorArgs",
"=",
"[",
"]",
")",
"{",
"$",
"spec",
"=",
"$",
"this",
"->",
"getServiceSpec",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"spec",
")",
"{",
"// Resolve to exact service name (in case inherited)",
"$",
"name",
"=",
"$",
"this",
"->",
"getServiceName",
"(",
"$",
"name",
")",
";",
"}",
"else",
"{",
"// Late-generate config spec for non-configured spec",
"$",
"spec",
"=",
"[",
"'class'",
"=>",
"$",
"name",
",",
"'constructor'",
"=>",
"$",
"constructorArgs",
",",
"]",
";",
"}",
"return",
"[",
"$",
"name",
",",
"$",
"spec",
"]",
";",
"}"
]
| Get or build a named service and specification
@param string $name Service name
@param array $constructorArgs Optional constructor args
@return array | [
"Get",
"or",
"build",
"a",
"named",
"service",
"and",
"specification"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Injector/Injector.php#L1040-L1054 | train |
silverstripe/silverstripe-framework | src/Core/Injector/Injector.php | Injector.getServiceSpec | public function getServiceSpec($name, $inherit = true)
{
if (isset($this->specs[$name])) {
return $this->specs[$name];
}
// Lazy load
$config = $this->configLocator->locateConfigFor($name);
if ($config) {
$this->load([$name => $config]);
if (isset($this->specs[$name])) {
return $this->specs[$name];
}
}
// Fail over to parent service if allowed
if (!$inherit || !strpos($name, '.')) {
return null;
}
return $this->getServiceSpec(substr($name, 0, strrpos($name, '.')));
} | php | public function getServiceSpec($name, $inherit = true)
{
if (isset($this->specs[$name])) {
return $this->specs[$name];
}
// Lazy load
$config = $this->configLocator->locateConfigFor($name);
if ($config) {
$this->load([$name => $config]);
if (isset($this->specs[$name])) {
return $this->specs[$name];
}
}
// Fail over to parent service if allowed
if (!$inherit || !strpos($name, '.')) {
return null;
}
return $this->getServiceSpec(substr($name, 0, strrpos($name, '.')));
} | [
"public",
"function",
"getServiceSpec",
"(",
"$",
"name",
",",
"$",
"inherit",
"=",
"true",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"specs",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"specs",
"[",
"$",
"name",
"]",
";",
"}",
"// Lazy load",
"$",
"config",
"=",
"$",
"this",
"->",
"configLocator",
"->",
"locateConfigFor",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"config",
")",
"{",
"$",
"this",
"->",
"load",
"(",
"[",
"$",
"name",
"=>",
"$",
"config",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"specs",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"specs",
"[",
"$",
"name",
"]",
";",
"}",
"}",
"// Fail over to parent service if allowed",
"if",
"(",
"!",
"$",
"inherit",
"||",
"!",
"strpos",
"(",
"$",
"name",
",",
"'.'",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"getServiceSpec",
"(",
"substr",
"(",
"$",
"name",
",",
"0",
",",
"strrpos",
"(",
"$",
"name",
",",
"'.'",
")",
")",
")",
";",
"}"
]
| Search for spec, lazy-loading in from config locator.
Falls back to parent service name if unloaded
@param string $name
@param bool $inherit Set to true to inherit from parent service if `.` suffixed
E.g. 'Psr/Log/LoggerInterface.custom' would fail over to 'Psr/Log/LoggerInterface'
@return mixed|object | [
"Search",
"for",
"spec",
"lazy",
"-",
"loading",
"in",
"from",
"config",
"locator",
".",
"Falls",
"back",
"to",
"parent",
"service",
"name",
"if",
"unloaded"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Injector/Injector.php#L1065-L1086 | train |
silverstripe/silverstripe-framework | src/ORM/FieldType/DBYear.php | DBYear.getDefaultOptions | private function getDefaultOptions($start = null, $end = null)
{
if (!$start) {
$start = (int)date('Y');
}
if (!$end) {
$end = 1900;
}
$years = array();
for ($i=$start; $i>=$end; $i--) {
$years[$i] = $i;
}
return $years;
} | php | private function getDefaultOptions($start = null, $end = null)
{
if (!$start) {
$start = (int)date('Y');
}
if (!$end) {
$end = 1900;
}
$years = array();
for ($i=$start; $i>=$end; $i--) {
$years[$i] = $i;
}
return $years;
} | [
"private",
"function",
"getDefaultOptions",
"(",
"$",
"start",
"=",
"null",
",",
"$",
"end",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"start",
")",
"{",
"$",
"start",
"=",
"(",
"int",
")",
"date",
"(",
"'Y'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"end",
")",
"{",
"$",
"end",
"=",
"1900",
";",
"}",
"$",
"years",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"start",
";",
"$",
"i",
">=",
"$",
"end",
";",
"$",
"i",
"--",
")",
"{",
"$",
"years",
"[",
"$",
"i",
"]",
"=",
"$",
"i",
";",
"}",
"return",
"$",
"years",
";",
"}"
]
| Returns a list of default options that can
be used to populate a select box, or compare against
input values. Starts by default at the current year,
and counts back to 1900.
@param int|bool $start starting date to count down from
@param int|bool $end end date to count down to
@return array | [
"Returns",
"a",
"list",
"of",
"default",
"options",
"that",
"can",
"be",
"used",
"to",
"populate",
"a",
"select",
"box",
"or",
"compare",
"against",
"input",
"values",
".",
"Starts",
"by",
"default",
"at",
"the",
"current",
"year",
"and",
"counts",
"back",
"to",
"1900",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/FieldType/DBYear.php#L38-L51 | train |
silverstripe/silverstripe-framework | src/ORM/Filters/ExactMatchFilter.php | ExactMatchFilter.oneFilter | protected function oneFilter(DataQuery $query, $inclusive)
{
$this->model = $query->applyRelation($this->relation);
$field = $this->getDbName();
$value = $this->getValue();
// Null comparison check
if ($value === null) {
$where = DB::get_conn()->nullCheckClause($field, $inclusive);
return $query->where($where);
}
// Value comparison check
$where = DB::get_conn()->comparisonClause(
$field,
null,
true, // exact?
!$inclusive, // negate?
$this->getCaseSensitive(),
true
);
// for != clauses include IS NULL values, since they would otherwise be excluded
if (!$inclusive) {
$nullClause = DB::get_conn()->nullCheckClause($field, true);
$where .= " OR {$nullClause}";
}
$clause = [$where => $value];
return $this->aggregate ?
$this->applyAggregate($query, $clause) :
$query->where($clause);
} | php | protected function oneFilter(DataQuery $query, $inclusive)
{
$this->model = $query->applyRelation($this->relation);
$field = $this->getDbName();
$value = $this->getValue();
// Null comparison check
if ($value === null) {
$where = DB::get_conn()->nullCheckClause($field, $inclusive);
return $query->where($where);
}
// Value comparison check
$where = DB::get_conn()->comparisonClause(
$field,
null,
true, // exact?
!$inclusive, // negate?
$this->getCaseSensitive(),
true
);
// for != clauses include IS NULL values, since they would otherwise be excluded
if (!$inclusive) {
$nullClause = DB::get_conn()->nullCheckClause($field, true);
$where .= " OR {$nullClause}";
}
$clause = [$where => $value];
return $this->aggregate ?
$this->applyAggregate($query, $clause) :
$query->where($clause);
} | [
"protected",
"function",
"oneFilter",
"(",
"DataQuery",
"$",
"query",
",",
"$",
"inclusive",
")",
"{",
"$",
"this",
"->",
"model",
"=",
"$",
"query",
"->",
"applyRelation",
"(",
"$",
"this",
"->",
"relation",
")",
";",
"$",
"field",
"=",
"$",
"this",
"->",
"getDbName",
"(",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"getValue",
"(",
")",
";",
"// Null comparison check",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"$",
"where",
"=",
"DB",
"::",
"get_conn",
"(",
")",
"->",
"nullCheckClause",
"(",
"$",
"field",
",",
"$",
"inclusive",
")",
";",
"return",
"$",
"query",
"->",
"where",
"(",
"$",
"where",
")",
";",
"}",
"// Value comparison check",
"$",
"where",
"=",
"DB",
"::",
"get_conn",
"(",
")",
"->",
"comparisonClause",
"(",
"$",
"field",
",",
"null",
",",
"true",
",",
"// exact?",
"!",
"$",
"inclusive",
",",
"// negate?",
"$",
"this",
"->",
"getCaseSensitive",
"(",
")",
",",
"true",
")",
";",
"// for != clauses include IS NULL values, since they would otherwise be excluded",
"if",
"(",
"!",
"$",
"inclusive",
")",
"{",
"$",
"nullClause",
"=",
"DB",
"::",
"get_conn",
"(",
")",
"->",
"nullCheckClause",
"(",
"$",
"field",
",",
"true",
")",
";",
"$",
"where",
".=",
"\" OR {$nullClause}\"",
";",
"}",
"$",
"clause",
"=",
"[",
"$",
"where",
"=>",
"$",
"value",
"]",
";",
"return",
"$",
"this",
"->",
"aggregate",
"?",
"$",
"this",
"->",
"applyAggregate",
"(",
"$",
"query",
",",
"$",
"clause",
")",
":",
"$",
"query",
"->",
"where",
"(",
"$",
"clause",
")",
";",
"}"
]
| Applies a single match, either as inclusive or exclusive
@param DataQuery $query
@param bool $inclusive True if this is inclusive, or false if exclusive
@return DataQuery | [
"Applies",
"a",
"single",
"match",
"either",
"as",
"inclusive",
"or",
"exclusive"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Filters/ExactMatchFilter.php#L52-L84 | train |
silverstripe/silverstripe-framework | src/ORM/Filters/ExactMatchFilter.php | ExactMatchFilter.manyFilter | protected function manyFilter(DataQuery $query, $inclusive)
{
$this->model = $query->applyRelation($this->relation);
$caseSensitive = $this->getCaseSensitive();
// Check values for null
$field = $this->getDbName();
$values = $this->getValue();
if (empty($values)) {
throw new \InvalidArgumentException("Cannot filter {$field} against an empty set");
}
$hasNull = in_array(null, $values, true);
if ($hasNull) {
$values = array_filter($values, function ($value) {
return $value !== null;
});
}
$connective = '';
if (empty($values)) {
$predicate = '';
} elseif ($caseSensitive === null) {
// For queries using the default collation (no explicit case) we can use the WHERE .. NOT IN .. syntax,
// providing simpler SQL than many WHERE .. AND .. fragments.
$column = $this->getDbName();
$placeholders = DB::placeholders($values);
if ($inclusive) {
$predicate = "$column IN ($placeholders)";
} else {
$predicate = "$column NOT IN ($placeholders)";
}
} else {
// Generate reusable comparison clause
$comparisonClause = DB::get_conn()->comparisonClause(
$this->getDbName(),
null,
true, // exact?
!$inclusive, // negate?
$this->getCaseSensitive(),
true
);
$count = count($values);
if ($count > 1) {
$connective = $inclusive ? ' OR ' : ' AND ';
$conditions = array_fill(0, $count, $comparisonClause);
$predicate = implode($connective, $conditions);
} else {
$predicate = $comparisonClause;
}
}
// Always check for null when doing exclusive checks (either AND IS NOT NULL / OR IS NULL)
// or when including the null value explicitly (OR IS NULL)
if ($hasNull || !$inclusive) {
// If excluding values which don't include null, or including
// values which include null, we should do an `OR IS NULL`.
// Otherwise we are excluding values that do include null, so `AND IS NOT NULL`.
// Simplified from (!$inclusive && !$hasNull) || ($inclusive && $hasNull);
$isNull = !$hasNull || $inclusive;
$nullCondition = DB::get_conn()->nullCheckClause($field, $isNull);
// Determine merge strategy
if (empty($predicate)) {
$predicate = $nullCondition;
} else {
// Merge null condition with predicate
if ($isNull) {
$nullCondition = " OR {$nullCondition}";
} else {
$nullCondition = " AND {$nullCondition}";
}
// If current predicate connective doesn't match the same as the null connective
// make sure to group the prior condition
if ($connective && (($connective === ' OR ') !== $isNull)) {
$predicate = "({$predicate})";
}
$predicate .= $nullCondition;
}
}
$clause = [$predicate => $values];
return $this->aggregate ?
$this->applyAggregate($query, $clause) :
$query->where($clause);
} | php | protected function manyFilter(DataQuery $query, $inclusive)
{
$this->model = $query->applyRelation($this->relation);
$caseSensitive = $this->getCaseSensitive();
// Check values for null
$field = $this->getDbName();
$values = $this->getValue();
if (empty($values)) {
throw new \InvalidArgumentException("Cannot filter {$field} against an empty set");
}
$hasNull = in_array(null, $values, true);
if ($hasNull) {
$values = array_filter($values, function ($value) {
return $value !== null;
});
}
$connective = '';
if (empty($values)) {
$predicate = '';
} elseif ($caseSensitive === null) {
// For queries using the default collation (no explicit case) we can use the WHERE .. NOT IN .. syntax,
// providing simpler SQL than many WHERE .. AND .. fragments.
$column = $this->getDbName();
$placeholders = DB::placeholders($values);
if ($inclusive) {
$predicate = "$column IN ($placeholders)";
} else {
$predicate = "$column NOT IN ($placeholders)";
}
} else {
// Generate reusable comparison clause
$comparisonClause = DB::get_conn()->comparisonClause(
$this->getDbName(),
null,
true, // exact?
!$inclusive, // negate?
$this->getCaseSensitive(),
true
);
$count = count($values);
if ($count > 1) {
$connective = $inclusive ? ' OR ' : ' AND ';
$conditions = array_fill(0, $count, $comparisonClause);
$predicate = implode($connective, $conditions);
} else {
$predicate = $comparisonClause;
}
}
// Always check for null when doing exclusive checks (either AND IS NOT NULL / OR IS NULL)
// or when including the null value explicitly (OR IS NULL)
if ($hasNull || !$inclusive) {
// If excluding values which don't include null, or including
// values which include null, we should do an `OR IS NULL`.
// Otherwise we are excluding values that do include null, so `AND IS NOT NULL`.
// Simplified from (!$inclusive && !$hasNull) || ($inclusive && $hasNull);
$isNull = !$hasNull || $inclusive;
$nullCondition = DB::get_conn()->nullCheckClause($field, $isNull);
// Determine merge strategy
if (empty($predicate)) {
$predicate = $nullCondition;
} else {
// Merge null condition with predicate
if ($isNull) {
$nullCondition = " OR {$nullCondition}";
} else {
$nullCondition = " AND {$nullCondition}";
}
// If current predicate connective doesn't match the same as the null connective
// make sure to group the prior condition
if ($connective && (($connective === ' OR ') !== $isNull)) {
$predicate = "({$predicate})";
}
$predicate .= $nullCondition;
}
}
$clause = [$predicate => $values];
return $this->aggregate ?
$this->applyAggregate($query, $clause) :
$query->where($clause);
} | [
"protected",
"function",
"manyFilter",
"(",
"DataQuery",
"$",
"query",
",",
"$",
"inclusive",
")",
"{",
"$",
"this",
"->",
"model",
"=",
"$",
"query",
"->",
"applyRelation",
"(",
"$",
"this",
"->",
"relation",
")",
";",
"$",
"caseSensitive",
"=",
"$",
"this",
"->",
"getCaseSensitive",
"(",
")",
";",
"// Check values for null",
"$",
"field",
"=",
"$",
"this",
"->",
"getDbName",
"(",
")",
";",
"$",
"values",
"=",
"$",
"this",
"->",
"getValue",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"values",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Cannot filter {$field} against an empty set\"",
")",
";",
"}",
"$",
"hasNull",
"=",
"in_array",
"(",
"null",
",",
"$",
"values",
",",
"true",
")",
";",
"if",
"(",
"$",
"hasNull",
")",
"{",
"$",
"values",
"=",
"array_filter",
"(",
"$",
"values",
",",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"$",
"value",
"!==",
"null",
";",
"}",
")",
";",
"}",
"$",
"connective",
"=",
"''",
";",
"if",
"(",
"empty",
"(",
"$",
"values",
")",
")",
"{",
"$",
"predicate",
"=",
"''",
";",
"}",
"elseif",
"(",
"$",
"caseSensitive",
"===",
"null",
")",
"{",
"// For queries using the default collation (no explicit case) we can use the WHERE .. NOT IN .. syntax,",
"// providing simpler SQL than many WHERE .. AND .. fragments.",
"$",
"column",
"=",
"$",
"this",
"->",
"getDbName",
"(",
")",
";",
"$",
"placeholders",
"=",
"DB",
"::",
"placeholders",
"(",
"$",
"values",
")",
";",
"if",
"(",
"$",
"inclusive",
")",
"{",
"$",
"predicate",
"=",
"\"$column IN ($placeholders)\"",
";",
"}",
"else",
"{",
"$",
"predicate",
"=",
"\"$column NOT IN ($placeholders)\"",
";",
"}",
"}",
"else",
"{",
"// Generate reusable comparison clause",
"$",
"comparisonClause",
"=",
"DB",
"::",
"get_conn",
"(",
")",
"->",
"comparisonClause",
"(",
"$",
"this",
"->",
"getDbName",
"(",
")",
",",
"null",
",",
"true",
",",
"// exact?",
"!",
"$",
"inclusive",
",",
"// negate?",
"$",
"this",
"->",
"getCaseSensitive",
"(",
")",
",",
"true",
")",
";",
"$",
"count",
"=",
"count",
"(",
"$",
"values",
")",
";",
"if",
"(",
"$",
"count",
">",
"1",
")",
"{",
"$",
"connective",
"=",
"$",
"inclusive",
"?",
"' OR '",
":",
"' AND '",
";",
"$",
"conditions",
"=",
"array_fill",
"(",
"0",
",",
"$",
"count",
",",
"$",
"comparisonClause",
")",
";",
"$",
"predicate",
"=",
"implode",
"(",
"$",
"connective",
",",
"$",
"conditions",
")",
";",
"}",
"else",
"{",
"$",
"predicate",
"=",
"$",
"comparisonClause",
";",
"}",
"}",
"// Always check for null when doing exclusive checks (either AND IS NOT NULL / OR IS NULL)",
"// or when including the null value explicitly (OR IS NULL)",
"if",
"(",
"$",
"hasNull",
"||",
"!",
"$",
"inclusive",
")",
"{",
"// If excluding values which don't include null, or including",
"// values which include null, we should do an `OR IS NULL`.",
"// Otherwise we are excluding values that do include null, so `AND IS NOT NULL`.",
"// Simplified from (!$inclusive && !$hasNull) || ($inclusive && $hasNull);",
"$",
"isNull",
"=",
"!",
"$",
"hasNull",
"||",
"$",
"inclusive",
";",
"$",
"nullCondition",
"=",
"DB",
"::",
"get_conn",
"(",
")",
"->",
"nullCheckClause",
"(",
"$",
"field",
",",
"$",
"isNull",
")",
";",
"// Determine merge strategy",
"if",
"(",
"empty",
"(",
"$",
"predicate",
")",
")",
"{",
"$",
"predicate",
"=",
"$",
"nullCondition",
";",
"}",
"else",
"{",
"// Merge null condition with predicate",
"if",
"(",
"$",
"isNull",
")",
"{",
"$",
"nullCondition",
"=",
"\" OR {$nullCondition}\"",
";",
"}",
"else",
"{",
"$",
"nullCondition",
"=",
"\" AND {$nullCondition}\"",
";",
"}",
"// If current predicate connective doesn't match the same as the null connective",
"// make sure to group the prior condition",
"if",
"(",
"$",
"connective",
"&&",
"(",
"(",
"$",
"connective",
"===",
"' OR '",
")",
"!==",
"$",
"isNull",
")",
")",
"{",
"$",
"predicate",
"=",
"\"({$predicate})\"",
";",
"}",
"$",
"predicate",
".=",
"$",
"nullCondition",
";",
"}",
"}",
"$",
"clause",
"=",
"[",
"$",
"predicate",
"=>",
"$",
"values",
"]",
";",
"return",
"$",
"this",
"->",
"aggregate",
"?",
"$",
"this",
"->",
"applyAggregate",
"(",
"$",
"query",
",",
"$",
"clause",
")",
":",
"$",
"query",
"->",
"where",
"(",
"$",
"clause",
")",
";",
"}"
]
| Applies matches for several values, either as inclusive or exclusive
@param DataQuery $query
@param bool $inclusive True if this is inclusive, or false if exclusive
@return DataQuery | [
"Applies",
"matches",
"for",
"several",
"values",
"either",
"as",
"inclusive",
"or",
"exclusive"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Filters/ExactMatchFilter.php#L117-L202 | train |
silverstripe/silverstripe-framework | src/Control/Middleware/HTTPCacheControlMiddleware.php | HTTPCacheControlMiddleware.getVary | public function getVary()
{
// Explicitly set vary
if (isset($this->vary)) {
return $this->vary;
}
// Load default from config
$defaultVary = $this->config()->get('defaultVary');
return array_keys(array_filter($defaultVary));
} | php | public function getVary()
{
// Explicitly set vary
if (isset($this->vary)) {
return $this->vary;
}
// Load default from config
$defaultVary = $this->config()->get('defaultVary');
return array_keys(array_filter($defaultVary));
} | [
"public",
"function",
"getVary",
"(",
")",
"{",
"// Explicitly set vary",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"vary",
")",
")",
"{",
"return",
"$",
"this",
"->",
"vary",
";",
"}",
"// Load default from config",
"$",
"defaultVary",
"=",
"$",
"this",
"->",
"config",
"(",
")",
"->",
"get",
"(",
"'defaultVary'",
")",
";",
"return",
"array_keys",
"(",
"array_filter",
"(",
"$",
"defaultVary",
")",
")",
";",
"}"
]
| Get current vary keys
@return array | [
"Get",
"current",
"vary",
"keys"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Control/Middleware/HTTPCacheControlMiddleware.php#L201-L211 | train |
silverstripe/silverstripe-framework | src/Control/Middleware/HTTPCacheControlMiddleware.php | HTTPCacheControlMiddleware.addVary | public function addVary($vary)
{
$combied = $this->combineVary($this->getVary(), $vary);
$this->setVary($combied);
return $this;
} | php | public function addVary($vary)
{
$combied = $this->combineVary($this->getVary(), $vary);
$this->setVary($combied);
return $this;
} | [
"public",
"function",
"addVary",
"(",
"$",
"vary",
")",
"{",
"$",
"combied",
"=",
"$",
"this",
"->",
"combineVary",
"(",
"$",
"this",
"->",
"getVary",
"(",
")",
",",
"$",
"vary",
")",
";",
"$",
"this",
"->",
"setVary",
"(",
"$",
"combied",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Add a vary
@param string|array $vary
@return $this | [
"Add",
"a",
"vary"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Control/Middleware/HTTPCacheControlMiddleware.php#L219-L224 | train |
silverstripe/silverstripe-framework | src/Control/Middleware/HTTPCacheControlMiddleware.php | HTTPCacheControlMiddleware.registerModificationDate | public function registerModificationDate($date)
{
$timestamp = is_numeric($date) ? $date : strtotime($date);
if ($timestamp > $this->modificationDate) {
$this->modificationDate = $timestamp;
}
return $this;
} | php | public function registerModificationDate($date)
{
$timestamp = is_numeric($date) ? $date : strtotime($date);
if ($timestamp > $this->modificationDate) {
$this->modificationDate = $timestamp;
}
return $this;
} | [
"public",
"function",
"registerModificationDate",
"(",
"$",
"date",
")",
"{",
"$",
"timestamp",
"=",
"is_numeric",
"(",
"$",
"date",
")",
"?",
"$",
"date",
":",
"strtotime",
"(",
"$",
"date",
")",
";",
"if",
"(",
"$",
"timestamp",
">",
"$",
"this",
"->",
"modificationDate",
")",
"{",
"$",
"this",
"->",
"modificationDate",
"=",
"$",
"timestamp",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Register a modification date. Used to calculate the "Last-Modified" HTTP header.
Can be called multiple times, and will automatically retain the most recent date.
@param string|int $date Date string or timestamp
@return HTTPCacheControlMiddleware | [
"Register",
"a",
"modification",
"date",
".",
"Used",
"to",
"calculate",
"the",
"Last",
"-",
"Modified",
"HTTP",
"header",
".",
"Can",
"be",
"called",
"multiple",
"times",
"and",
"will",
"automatically",
"retain",
"the",
"most",
"recent",
"date",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Control/Middleware/HTTPCacheControlMiddleware.php#L266-L273 | train |
silverstripe/silverstripe-framework | src/Control/Middleware/HTTPCacheControlMiddleware.php | HTTPCacheControlMiddleware.setState | protected function setState($state)
{
if (!array_key_exists($state, $this->stateDirectives)) {
throw new InvalidArgumentException("Invalid state {$state}");
}
$this->state = $state;
return $this;
} | php | protected function setState($state)
{
if (!array_key_exists($state, $this->stateDirectives)) {
throw new InvalidArgumentException("Invalid state {$state}");
}
$this->state = $state;
return $this;
} | [
"protected",
"function",
"setState",
"(",
"$",
"state",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"state",
",",
"$",
"this",
"->",
"stateDirectives",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Invalid state {$state}\"",
")",
";",
"}",
"$",
"this",
"->",
"state",
"=",
"$",
"state",
";",
"return",
"$",
"this",
";",
"}"
]
| Set current state. Should only be invoked internally after processing precedence rules.
@param string $state
@return $this | [
"Set",
"current",
"state",
".",
"Should",
"only",
"be",
"invoked",
"internally",
"after",
"processing",
"precedence",
"rules",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Control/Middleware/HTTPCacheControlMiddleware.php#L281-L288 | train |
silverstripe/silverstripe-framework | src/Control/Middleware/HTTPCacheControlMiddleware.php | HTTPCacheControlMiddleware.applyChangeLevel | protected function applyChangeLevel($level, $force)
{
$forcingLevel = $level + ($force ? self::LEVEL_FORCED : 0);
if ($forcingLevel < $this->getForcingLevel()) {
return false;
}
$this->forcingLevel = $forcingLevel;
return true;
} | php | protected function applyChangeLevel($level, $force)
{
$forcingLevel = $level + ($force ? self::LEVEL_FORCED : 0);
if ($forcingLevel < $this->getForcingLevel()) {
return false;
}
$this->forcingLevel = $forcingLevel;
return true;
} | [
"protected",
"function",
"applyChangeLevel",
"(",
"$",
"level",
",",
"$",
"force",
")",
"{",
"$",
"forcingLevel",
"=",
"$",
"level",
"+",
"(",
"$",
"force",
"?",
"self",
"::",
"LEVEL_FORCED",
":",
"0",
")",
";",
"if",
"(",
"$",
"forcingLevel",
"<",
"$",
"this",
"->",
"getForcingLevel",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"forcingLevel",
"=",
"$",
"forcingLevel",
";",
"return",
"true",
";",
"}"
]
| Instruct the cache to apply a change with a given level, optionally
modifying it with a force flag to increase priority of this action.
If the apply level was successful, the change is made and the internal level
threshold is incremented.
@param int $level Priority of the given change
@param bool $force If usercode has requested this action is forced to a higher priority.
Note: Even if $force is set to true, other higher-priority forced changes can still
cause a change to be rejected if it is below the required threshold.
@return bool True if the given change is accepted, and that the internal
level threshold is updated (if necessary) to the new minimum level. | [
"Instruct",
"the",
"cache",
"to",
"apply",
"a",
"change",
"with",
"a",
"given",
"level",
"optionally",
"modifying",
"it",
"with",
"a",
"force",
"flag",
"to",
"increase",
"priority",
"of",
"this",
"action",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Control/Middleware/HTTPCacheControlMiddleware.php#L314-L322 | train |
silverstripe/silverstripe-framework | src/Control/Middleware/HTTPCacheControlMiddleware.php | HTTPCacheControlMiddleware.setStateDirectivesFromArray | public function setStateDirectivesFromArray($states, $directives)
{
foreach ($directives as $directive => $value) {
$this->setStateDirective($states, $directive, $value);
}
return $this;
} | php | public function setStateDirectivesFromArray($states, $directives)
{
foreach ($directives as $directive => $value) {
$this->setStateDirective($states, $directive, $value);
}
return $this;
} | [
"public",
"function",
"setStateDirectivesFromArray",
"(",
"$",
"states",
",",
"$",
"directives",
")",
"{",
"foreach",
"(",
"$",
"directives",
"as",
"$",
"directive",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"setStateDirective",
"(",
"$",
"states",
",",
"$",
"directive",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Low level method to set directives from an associative array
@param array|string $states State(s) to apply this directive to
@param array $directives
@return $this | [
"Low",
"level",
"method",
"to",
"set",
"directives",
"from",
"an",
"associative",
"array"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Control/Middleware/HTTPCacheControlMiddleware.php#L367-L373 | train |
silverstripe/silverstripe-framework | src/Control/Middleware/HTTPCacheControlMiddleware.php | HTTPCacheControlMiddleware.hasStateDirective | public function hasStateDirective($state, $directive)
{
$directive = strtolower($directive);
return isset($this->stateDirectives[$state][$directive]);
} | php | public function hasStateDirective($state, $directive)
{
$directive = strtolower($directive);
return isset($this->stateDirectives[$state][$directive]);
} | [
"public",
"function",
"hasStateDirective",
"(",
"$",
"state",
",",
"$",
"directive",
")",
"{",
"$",
"directive",
"=",
"strtolower",
"(",
"$",
"directive",
")",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"stateDirectives",
"[",
"$",
"state",
"]",
"[",
"$",
"directive",
"]",
")",
";",
"}"
]
| Low level method to check if a directive is currently set
@param string $state State(s) to apply this directive to
@param string $directive
@return bool | [
"Low",
"level",
"method",
"to",
"check",
"if",
"a",
"directive",
"is",
"currently",
"set"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Control/Middleware/HTTPCacheControlMiddleware.php#L395-L399 | train |
silverstripe/silverstripe-framework | src/Control/Middleware/HTTPCacheControlMiddleware.php | HTTPCacheControlMiddleware.getStateDirective | public function getStateDirective($state, $directive)
{
$directive = strtolower($directive);
if (isset($this->stateDirectives[$state][$directive])) {
return $this->stateDirectives[$state][$directive];
}
return false;
} | php | public function getStateDirective($state, $directive)
{
$directive = strtolower($directive);
if (isset($this->stateDirectives[$state][$directive])) {
return $this->stateDirectives[$state][$directive];
}
return false;
} | [
"public",
"function",
"getStateDirective",
"(",
"$",
"state",
",",
"$",
"directive",
")",
"{",
"$",
"directive",
"=",
"strtolower",
"(",
"$",
"directive",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"stateDirectives",
"[",
"$",
"state",
"]",
"[",
"$",
"directive",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"stateDirectives",
"[",
"$",
"state",
"]",
"[",
"$",
"directive",
"]",
";",
"}",
"return",
"false",
";",
"}"
]
| Low level method to get the value of a directive for a state.
Returns false if there is no directive.
True means the flag is set, otherwise the value of the directive.
@param string $state
@param string $directive
@return int|string|bool | [
"Low",
"level",
"method",
"to",
"get",
"the",
"value",
"of",
"a",
"directive",
"for",
"a",
"state",
".",
"Returns",
"false",
"if",
"there",
"is",
"no",
"directive",
".",
"True",
"means",
"the",
"flag",
"is",
"set",
"otherwise",
"the",
"value",
"of",
"the",
"directive",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Control/Middleware/HTTPCacheControlMiddleware.php#L421-L428 | train |
silverstripe/silverstripe-framework | src/Control/Middleware/HTTPCacheControlMiddleware.php | HTTPCacheControlMiddleware.applyToResponse | public function applyToResponse($response)
{
$headers = $this->generateHeadersFor($response);
foreach ($headers as $name => $value) {
if (!$response->getHeader($name)) {
$response->addHeader($name, $value);
}
}
return $this;
} | php | public function applyToResponse($response)
{
$headers = $this->generateHeadersFor($response);
foreach ($headers as $name => $value) {
if (!$response->getHeader($name)) {
$response->addHeader($name, $value);
}
}
return $this;
} | [
"public",
"function",
"applyToResponse",
"(",
"$",
"response",
")",
"{",
"$",
"headers",
"=",
"$",
"this",
"->",
"generateHeadersFor",
"(",
"$",
"response",
")",
";",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"response",
"->",
"getHeader",
"(",
"$",
"name",
")",
")",
"{",
"$",
"response",
"->",
"addHeader",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Generate all headers to add to this object
@param HTTPResponse $response
@return $this | [
"Generate",
"all",
"headers",
"to",
"add",
"to",
"this",
"object"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Control/Middleware/HTTPCacheControlMiddleware.php#L668-L677 | train |
silverstripe/silverstripe-framework | src/Control/Middleware/HTTPCacheControlMiddleware.php | HTTPCacheControlMiddleware.generateCacheHeader | protected function generateCacheHeader()
{
$cacheControl = [];
foreach ($this->getDirectives() as $directive => $value) {
if ($value === true) {
$cacheControl[] = $directive;
} else {
$cacheControl[] = $directive . '=' . $value;
}
}
return implode(', ', $cacheControl);
} | php | protected function generateCacheHeader()
{
$cacheControl = [];
foreach ($this->getDirectives() as $directive => $value) {
if ($value === true) {
$cacheControl[] = $directive;
} else {
$cacheControl[] = $directive . '=' . $value;
}
}
return implode(', ', $cacheControl);
} | [
"protected",
"function",
"generateCacheHeader",
"(",
")",
"{",
"$",
"cacheControl",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getDirectives",
"(",
")",
"as",
"$",
"directive",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"true",
")",
"{",
"$",
"cacheControl",
"[",
"]",
"=",
"$",
"directive",
";",
"}",
"else",
"{",
"$",
"cacheControl",
"[",
"]",
"=",
"$",
"directive",
".",
"'='",
".",
"$",
"value",
";",
"}",
"}",
"return",
"implode",
"(",
"', '",
",",
"$",
"cacheControl",
")",
";",
"}"
]
| Generate the cache header
@return string | [
"Generate",
"the",
"cache",
"header"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Control/Middleware/HTTPCacheControlMiddleware.php#L684-L695 | train |
silverstripe/silverstripe-framework | src/Control/Middleware/HTTPCacheControlMiddleware.php | HTTPCacheControlMiddleware.generateHeadersFor | public function generateHeadersFor(HTTPResponse $response)
{
return array_filter([
'Last-Modified' => $this->generateLastModifiedHeader(),
'Vary' => $this->generateVaryHeader($response),
'Cache-Control' => $this->generateCacheHeader(),
'Expires' => $this->generateExpiresHeader(),
]);
} | php | public function generateHeadersFor(HTTPResponse $response)
{
return array_filter([
'Last-Modified' => $this->generateLastModifiedHeader(),
'Vary' => $this->generateVaryHeader($response),
'Cache-Control' => $this->generateCacheHeader(),
'Expires' => $this->generateExpiresHeader(),
]);
} | [
"public",
"function",
"generateHeadersFor",
"(",
"HTTPResponse",
"$",
"response",
")",
"{",
"return",
"array_filter",
"(",
"[",
"'Last-Modified'",
"=>",
"$",
"this",
"->",
"generateLastModifiedHeader",
"(",
")",
",",
"'Vary'",
"=>",
"$",
"this",
"->",
"generateVaryHeader",
"(",
"$",
"response",
")",
",",
"'Cache-Control'",
"=>",
"$",
"this",
"->",
"generateCacheHeader",
"(",
")",
",",
"'Expires'",
"=>",
"$",
"this",
"->",
"generateExpiresHeader",
"(",
")",
",",
"]",
")",
";",
"}"
]
| Generate all headers to output
@param HTTPResponse $response
@return array | [
"Generate",
"all",
"headers",
"to",
"output"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Control/Middleware/HTTPCacheControlMiddleware.php#L703-L711 | train |
silverstripe/silverstripe-framework | src/Control/Middleware/HTTPCacheControlMiddleware.php | HTTPCacheControlMiddleware.generateVaryHeader | protected function generateVaryHeader(HTTPResponse $response)
{
// split the current vary header into it's parts and merge it with the config settings
// to create a list of unique vary values
$vary = $this->getVary();
if ($response->getHeader('Vary')) {
$vary = $this->combineVary($vary, $response->getHeader('Vary'));
}
if ($vary) {
return implode(', ', $vary);
}
return null;
} | php | protected function generateVaryHeader(HTTPResponse $response)
{
// split the current vary header into it's parts and merge it with the config settings
// to create a list of unique vary values
$vary = $this->getVary();
if ($response->getHeader('Vary')) {
$vary = $this->combineVary($vary, $response->getHeader('Vary'));
}
if ($vary) {
return implode(', ', $vary);
}
return null;
} | [
"protected",
"function",
"generateVaryHeader",
"(",
"HTTPResponse",
"$",
"response",
")",
"{",
"// split the current vary header into it's parts and merge it with the config settings",
"// to create a list of unique vary values",
"$",
"vary",
"=",
"$",
"this",
"->",
"getVary",
"(",
")",
";",
"if",
"(",
"$",
"response",
"->",
"getHeader",
"(",
"'Vary'",
")",
")",
"{",
"$",
"vary",
"=",
"$",
"this",
"->",
"combineVary",
"(",
"$",
"vary",
",",
"$",
"response",
"->",
"getHeader",
"(",
"'Vary'",
")",
")",
";",
"}",
"if",
"(",
"$",
"vary",
")",
"{",
"return",
"implode",
"(",
"', '",
",",
"$",
"vary",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Generate vary http header
@param HTTPResponse $response
@return string|null | [
"Generate",
"vary",
"http",
"header"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Control/Middleware/HTTPCacheControlMiddleware.php#L738-L750 | train |
silverstripe/silverstripe-framework | src/Control/Middleware/HTTPCacheControlMiddleware.php | HTTPCacheControlMiddleware.generateExpiresHeader | protected function generateExpiresHeader()
{
$maxAge = $this->getDirective('max-age');
if ($maxAge === false) {
return null;
}
// Add now to max-age to generate expires
$expires = DBDatetime::now()->getTimestamp() + $maxAge;
return gmdate('D, d M Y H:i:s', $expires) . ' GMT';
} | php | protected function generateExpiresHeader()
{
$maxAge = $this->getDirective('max-age');
if ($maxAge === false) {
return null;
}
// Add now to max-age to generate expires
$expires = DBDatetime::now()->getTimestamp() + $maxAge;
return gmdate('D, d M Y H:i:s', $expires) . ' GMT';
} | [
"protected",
"function",
"generateExpiresHeader",
"(",
")",
"{",
"$",
"maxAge",
"=",
"$",
"this",
"->",
"getDirective",
"(",
"'max-age'",
")",
";",
"if",
"(",
"$",
"maxAge",
"===",
"false",
")",
"{",
"return",
"null",
";",
"}",
"// Add now to max-age to generate expires",
"$",
"expires",
"=",
"DBDatetime",
"::",
"now",
"(",
")",
"->",
"getTimestamp",
"(",
")",
"+",
"$",
"maxAge",
";",
"return",
"gmdate",
"(",
"'D, d M Y H:i:s'",
",",
"$",
"expires",
")",
".",
"' GMT'",
";",
"}"
]
| Generate Expires http header
@return null|string | [
"Generate",
"Expires",
"http",
"header"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Control/Middleware/HTTPCacheControlMiddleware.php#L770-L780 | train |
silverstripe/silverstripe-framework | src/Control/Middleware/HTTPCacheControlMiddleware.php | HTTPCacheControlMiddleware.augmentState | protected function augmentState(HTTPRequest $request, HTTPResponse $response)
{
// Errors disable cache (unless some errors are cached intentionally by usercode)
if ($response->isError() || $response->isRedirect()) {
// Even if publicCache(true) is specified, errors will be uncacheable
$this->disableCache(true);
} elseif ($request->getSession()->getAll()) {
// If sessions exist we assume that the responses should not be cached by CDNs / proxies as we are
// likely to be supplying information relevant to the current user only
// Don't force in case user code chooses to opt in to public caching
$this->privateCache();
}
} | php | protected function augmentState(HTTPRequest $request, HTTPResponse $response)
{
// Errors disable cache (unless some errors are cached intentionally by usercode)
if ($response->isError() || $response->isRedirect()) {
// Even if publicCache(true) is specified, errors will be uncacheable
$this->disableCache(true);
} elseif ($request->getSession()->getAll()) {
// If sessions exist we assume that the responses should not be cached by CDNs / proxies as we are
// likely to be supplying information relevant to the current user only
// Don't force in case user code chooses to opt in to public caching
$this->privateCache();
}
} | [
"protected",
"function",
"augmentState",
"(",
"HTTPRequest",
"$",
"request",
",",
"HTTPResponse",
"$",
"response",
")",
"{",
"// Errors disable cache (unless some errors are cached intentionally by usercode)",
"if",
"(",
"$",
"response",
"->",
"isError",
"(",
")",
"||",
"$",
"response",
"->",
"isRedirect",
"(",
")",
")",
"{",
"// Even if publicCache(true) is specified, errors will be uncacheable",
"$",
"this",
"->",
"disableCache",
"(",
"true",
")",
";",
"}",
"elseif",
"(",
"$",
"request",
"->",
"getSession",
"(",
")",
"->",
"getAll",
"(",
")",
")",
"{",
"// If sessions exist we assume that the responses should not be cached by CDNs / proxies as we are",
"// likely to be supplying information relevant to the current user only",
"// Don't force in case user code chooses to opt in to public caching",
"$",
"this",
"->",
"privateCache",
"(",
")",
";",
"}",
"}"
]
| Update state based on current request and response objects
@param HTTPRequest $request
@param HTTPResponse $response | [
"Update",
"state",
"based",
"on",
"current",
"request",
"and",
"response",
"objects"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Control/Middleware/HTTPCacheControlMiddleware.php#L788-L801 | train |
silverstripe/silverstripe-framework | src/Control/SimpleResourceURLGenerator.php | SimpleResourceURLGenerator.resolveModuleResource | protected function resolveModuleResource(ModuleResource $resource)
{
// Load from module resource
$relativePath = $resource->getRelativePath();
$exists = $resource->exists();
$absolutePath = $resource->getPath();
// Rewrite to _resources with public directory
if (Director::publicDir()) {
// All resources mapped directly to _resources/
$relativePath = Path::join(RESOURCES_DIR, $relativePath);
} elseif (stripos($relativePath, ManifestFileFinder::VENDOR_DIR . DIRECTORY_SEPARATOR) === 0) {
// @todo Non-public dir support will be removed in 5.0, so remove this block there
// If there is no public folder, map to _resources/ but trim leading vendor/ too (4.0 compat)
$relativePath = Path::join(
RESOURCES_DIR,
substr($relativePath, strlen(ManifestFileFinder::VENDOR_DIR))
);
}
return [$exists, $absolutePath, $relativePath];
} | php | protected function resolveModuleResource(ModuleResource $resource)
{
// Load from module resource
$relativePath = $resource->getRelativePath();
$exists = $resource->exists();
$absolutePath = $resource->getPath();
// Rewrite to _resources with public directory
if (Director::publicDir()) {
// All resources mapped directly to _resources/
$relativePath = Path::join(RESOURCES_DIR, $relativePath);
} elseif (stripos($relativePath, ManifestFileFinder::VENDOR_DIR . DIRECTORY_SEPARATOR) === 0) {
// @todo Non-public dir support will be removed in 5.0, so remove this block there
// If there is no public folder, map to _resources/ but trim leading vendor/ too (4.0 compat)
$relativePath = Path::join(
RESOURCES_DIR,
substr($relativePath, strlen(ManifestFileFinder::VENDOR_DIR))
);
}
return [$exists, $absolutePath, $relativePath];
} | [
"protected",
"function",
"resolveModuleResource",
"(",
"ModuleResource",
"$",
"resource",
")",
"{",
"// Load from module resource",
"$",
"relativePath",
"=",
"$",
"resource",
"->",
"getRelativePath",
"(",
")",
";",
"$",
"exists",
"=",
"$",
"resource",
"->",
"exists",
"(",
")",
";",
"$",
"absolutePath",
"=",
"$",
"resource",
"->",
"getPath",
"(",
")",
";",
"// Rewrite to _resources with public directory",
"if",
"(",
"Director",
"::",
"publicDir",
"(",
")",
")",
"{",
"// All resources mapped directly to _resources/",
"$",
"relativePath",
"=",
"Path",
"::",
"join",
"(",
"RESOURCES_DIR",
",",
"$",
"relativePath",
")",
";",
"}",
"elseif",
"(",
"stripos",
"(",
"$",
"relativePath",
",",
"ManifestFileFinder",
"::",
"VENDOR_DIR",
".",
"DIRECTORY_SEPARATOR",
")",
"===",
"0",
")",
"{",
"// @todo Non-public dir support will be removed in 5.0, so remove this block there",
"// If there is no public folder, map to _resources/ but trim leading vendor/ too (4.0 compat)",
"$",
"relativePath",
"=",
"Path",
"::",
"join",
"(",
"RESOURCES_DIR",
",",
"substr",
"(",
"$",
"relativePath",
",",
"strlen",
"(",
"ManifestFileFinder",
"::",
"VENDOR_DIR",
")",
")",
")",
";",
"}",
"return",
"[",
"$",
"exists",
",",
"$",
"absolutePath",
",",
"$",
"relativePath",
"]",
";",
"}"
]
| Update relative path for a module resource
@param ModuleResource $resource
@return array List of [$exists, $absolutePath, $relativePath] | [
"Update",
"relative",
"path",
"for",
"a",
"module",
"resource"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Control/SimpleResourceURLGenerator.php#L129-L149 | train |
silverstripe/silverstripe-framework | src/Forms/ConfirmedPasswordField.php | ConfirmedPasswordField.setValue | public function setValue($value, $data = null)
{
// If $data is a DataObject, don't use the value, since it's a hashed value
if ($data && $data instanceof DataObject) {
$value = '';
}
//store this for later
$oldValue = $this->value;
if (is_array($value)) {
$this->value = $value['_Password'];
$this->confirmValue = $value['_ConfirmPassword'];
$this->currentPasswordValue = ($this->getRequireExistingPassword() && isset($value['_CurrentPassword']))
? $value['_CurrentPassword']
: null;
if ($this->showOnClick && isset($value['_PasswordFieldVisible'])) {
$this->getChildren()->fieldByName($this->getName() . '[_PasswordFieldVisible]')
->setValue($value['_PasswordFieldVisible']);
}
} else {
if ($value || (!$value && $this->canBeEmpty)) {
$this->value = $value;
$this->confirmValue = $value;
}
}
//looking up field by name is expensive, so lets check it needs to change
if ($oldValue != $this->value) {
$this->getChildren()->fieldByName($this->getName() . '[_Password]')
->setValue($this->value);
$this->getChildren()->fieldByName($this->getName() . '[_ConfirmPassword]')
->setValue($this->confirmValue);
}
return $this;
} | php | public function setValue($value, $data = null)
{
// If $data is a DataObject, don't use the value, since it's a hashed value
if ($data && $data instanceof DataObject) {
$value = '';
}
//store this for later
$oldValue = $this->value;
if (is_array($value)) {
$this->value = $value['_Password'];
$this->confirmValue = $value['_ConfirmPassword'];
$this->currentPasswordValue = ($this->getRequireExistingPassword() && isset($value['_CurrentPassword']))
? $value['_CurrentPassword']
: null;
if ($this->showOnClick && isset($value['_PasswordFieldVisible'])) {
$this->getChildren()->fieldByName($this->getName() . '[_PasswordFieldVisible]')
->setValue($value['_PasswordFieldVisible']);
}
} else {
if ($value || (!$value && $this->canBeEmpty)) {
$this->value = $value;
$this->confirmValue = $value;
}
}
//looking up field by name is expensive, so lets check it needs to change
if ($oldValue != $this->value) {
$this->getChildren()->fieldByName($this->getName() . '[_Password]')
->setValue($this->value);
$this->getChildren()->fieldByName($this->getName() . '[_ConfirmPassword]')
->setValue($this->confirmValue);
}
return $this;
} | [
"public",
"function",
"setValue",
"(",
"$",
"value",
",",
"$",
"data",
"=",
"null",
")",
"{",
"// If $data is a DataObject, don't use the value, since it's a hashed value",
"if",
"(",
"$",
"data",
"&&",
"$",
"data",
"instanceof",
"DataObject",
")",
"{",
"$",
"value",
"=",
"''",
";",
"}",
"//store this for later",
"$",
"oldValue",
"=",
"$",
"this",
"->",
"value",
";",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"this",
"->",
"value",
"=",
"$",
"value",
"[",
"'_Password'",
"]",
";",
"$",
"this",
"->",
"confirmValue",
"=",
"$",
"value",
"[",
"'_ConfirmPassword'",
"]",
";",
"$",
"this",
"->",
"currentPasswordValue",
"=",
"(",
"$",
"this",
"->",
"getRequireExistingPassword",
"(",
")",
"&&",
"isset",
"(",
"$",
"value",
"[",
"'_CurrentPassword'",
"]",
")",
")",
"?",
"$",
"value",
"[",
"'_CurrentPassword'",
"]",
":",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"showOnClick",
"&&",
"isset",
"(",
"$",
"value",
"[",
"'_PasswordFieldVisible'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"getChildren",
"(",
")",
"->",
"fieldByName",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
".",
"'[_PasswordFieldVisible]'",
")",
"->",
"setValue",
"(",
"$",
"value",
"[",
"'_PasswordFieldVisible'",
"]",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"value",
"||",
"(",
"!",
"$",
"value",
"&&",
"$",
"this",
"->",
"canBeEmpty",
")",
")",
"{",
"$",
"this",
"->",
"value",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"confirmValue",
"=",
"$",
"value",
";",
"}",
"}",
"//looking up field by name is expensive, so lets check it needs to change",
"if",
"(",
"$",
"oldValue",
"!=",
"$",
"this",
"->",
"value",
")",
"{",
"$",
"this",
"->",
"getChildren",
"(",
")",
"->",
"fieldByName",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
".",
"'[_Password]'",
")",
"->",
"setValue",
"(",
"$",
"this",
"->",
"value",
")",
";",
"$",
"this",
"->",
"getChildren",
"(",
")",
"->",
"fieldByName",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
".",
"'[_ConfirmPassword]'",
")",
"->",
"setValue",
"(",
"$",
"this",
"->",
"confirmValue",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Value is sometimes an array, and sometimes a single value, so we need
to handle both cases.
@param mixed $value
@param mixed $data
@return $this | [
"Value",
"is",
"sometimes",
"an",
"array",
"and",
"sometimes",
"a",
"single",
"value",
"so",
"we",
"need",
"to",
"handle",
"both",
"cases",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Forms/ConfirmedPasswordField.php#L335-L373 | train |
silverstripe/silverstripe-framework | src/Forms/ConfirmedPasswordField.php | ConfirmedPasswordField.setName | public function setName($name)
{
$this->getPasswordField()->setName($name . '[_Password]');
$this->getConfirmPasswordField()->setName($name . '[_ConfirmPassword]');
if ($this->hiddenField) {
$this->hiddenField->setName($name . '[_PasswordFieldVisible]');
}
parent::setName($name);
return $this;
} | php | public function setName($name)
{
$this->getPasswordField()->setName($name . '[_Password]');
$this->getConfirmPasswordField()->setName($name . '[_ConfirmPassword]');
if ($this->hiddenField) {
$this->hiddenField->setName($name . '[_PasswordFieldVisible]');
}
parent::setName($name);
return $this;
} | [
"public",
"function",
"setName",
"(",
"$",
"name",
")",
"{",
"$",
"this",
"->",
"getPasswordField",
"(",
")",
"->",
"setName",
"(",
"$",
"name",
".",
"'[_Password]'",
")",
";",
"$",
"this",
"->",
"getConfirmPasswordField",
"(",
")",
"->",
"setName",
"(",
"$",
"name",
".",
"'[_ConfirmPassword]'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hiddenField",
")",
"{",
"$",
"this",
"->",
"hiddenField",
"->",
"setName",
"(",
"$",
"name",
".",
"'[_PasswordFieldVisible]'",
")",
";",
"}",
"parent",
"::",
"setName",
"(",
"$",
"name",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Update the names of the child fields when updating name of field.
@param string $name new name to give to the field.
@return $this | [
"Update",
"the",
"names",
"of",
"the",
"child",
"fields",
"when",
"updating",
"name",
"of",
"field",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Forms/ConfirmedPasswordField.php#L381-L391 | train |
silverstripe/silverstripe-framework | src/Forms/ConfirmedPasswordField.php | ConfirmedPasswordField.isSaveable | public function isSaveable()
{
return !$this->showOnClick
|| ($this->showOnClick && $this->hiddenField && $this->hiddenField->Value());
} | php | public function isSaveable()
{
return !$this->showOnClick
|| ($this->showOnClick && $this->hiddenField && $this->hiddenField->Value());
} | [
"public",
"function",
"isSaveable",
"(",
")",
"{",
"return",
"!",
"$",
"this",
"->",
"showOnClick",
"||",
"(",
"$",
"this",
"->",
"showOnClick",
"&&",
"$",
"this",
"->",
"hiddenField",
"&&",
"$",
"this",
"->",
"hiddenField",
"->",
"Value",
"(",
")",
")",
";",
"}"
]
| Determines if the field was actually shown on the client side - if not,
we don't validate or save it.
@return boolean | [
"Determines",
"if",
"the",
"field",
"was",
"actually",
"shown",
"on",
"the",
"client",
"side",
"-",
"if",
"not",
"we",
"don",
"t",
"validate",
"or",
"save",
"it",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Forms/ConfirmedPasswordField.php#L399-L403 | train |
silverstripe/silverstripe-framework | src/Forms/ConfirmedPasswordField.php | ConfirmedPasswordField.saveInto | public function saveInto(DataObjectInterface $record)
{
if (!$this->isSaveable()) {
return;
}
if (!($this->canBeEmpty && !$this->value)) {
parent::saveInto($record);
}
} | php | public function saveInto(DataObjectInterface $record)
{
if (!$this->isSaveable()) {
return;
}
if (!($this->canBeEmpty && !$this->value)) {
parent::saveInto($record);
}
} | [
"public",
"function",
"saveInto",
"(",
"DataObjectInterface",
"$",
"record",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isSaveable",
"(",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"this",
"->",
"canBeEmpty",
"&&",
"!",
"$",
"this",
"->",
"value",
")",
")",
"{",
"parent",
"::",
"saveInto",
"(",
"$",
"record",
")",
";",
"}",
"}"
]
| Only save if field was shown on the client, and is not empty.
@param DataObjectInterface $record | [
"Only",
"save",
"if",
"field",
"was",
"shown",
"on",
"the",
"client",
"and",
"is",
"not",
"empty",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Forms/ConfirmedPasswordField.php#L557-L566 | train |
silverstripe/silverstripe-framework | src/Forms/ConfirmedPasswordField.php | ConfirmedPasswordField.performReadonlyTransformation | public function performReadonlyTransformation()
{
/** @var ReadonlyField $field */
$field = $this->castedCopy(ReadonlyField::class)
->setTitle($this->title ? $this->title : _t('SilverStripe\\Security\\Member.PASSWORD', 'Password'))
->setValue('*****');
return $field;
} | php | public function performReadonlyTransformation()
{
/** @var ReadonlyField $field */
$field = $this->castedCopy(ReadonlyField::class)
->setTitle($this->title ? $this->title : _t('SilverStripe\\Security\\Member.PASSWORD', 'Password'))
->setValue('*****');
return $field;
} | [
"public",
"function",
"performReadonlyTransformation",
"(",
")",
"{",
"/** @var ReadonlyField $field */",
"$",
"field",
"=",
"$",
"this",
"->",
"castedCopy",
"(",
"ReadonlyField",
"::",
"class",
")",
"->",
"setTitle",
"(",
"$",
"this",
"->",
"title",
"?",
"$",
"this",
"->",
"title",
":",
"_t",
"(",
"'SilverStripe\\\\Security\\\\Member.PASSWORD'",
",",
"'Password'",
")",
")",
"->",
"setValue",
"(",
"'*****'",
")",
";",
"return",
"$",
"field",
";",
"}"
]
| Makes a read only field with some stars in it to replace the password
@return ReadonlyField | [
"Makes",
"a",
"read",
"only",
"field",
"with",
"some",
"stars",
"in",
"it",
"to",
"replace",
"the",
"password"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Forms/ConfirmedPasswordField.php#L573-L581 | train |
silverstripe/silverstripe-framework | src/Forms/ConfirmedPasswordField.php | ConfirmedPasswordField.setRequireExistingPassword | public function setRequireExistingPassword($show)
{
// Don't modify if already added / removed
if ((bool)$show === $this->requireExistingPassword) {
return $this;
}
$this->requireExistingPassword = $show;
$name = $this->getName();
$currentName = "{$name}[_CurrentPassword]";
if ($show) {
$confirmField = PasswordField::create($currentName, _t('SilverStripe\\Security\\Member.CURRENT_PASSWORD', 'Current Password'));
$this->getChildren()->unshift($confirmField);
} else {
$this->getChildren()->removeByName($currentName, true);
}
return $this;
} | php | public function setRequireExistingPassword($show)
{
// Don't modify if already added / removed
if ((bool)$show === $this->requireExistingPassword) {
return $this;
}
$this->requireExistingPassword = $show;
$name = $this->getName();
$currentName = "{$name}[_CurrentPassword]";
if ($show) {
$confirmField = PasswordField::create($currentName, _t('SilverStripe\\Security\\Member.CURRENT_PASSWORD', 'Current Password'));
$this->getChildren()->unshift($confirmField);
} else {
$this->getChildren()->removeByName($currentName, true);
}
return $this;
} | [
"public",
"function",
"setRequireExistingPassword",
"(",
"$",
"show",
")",
"{",
"// Don't modify if already added / removed",
"if",
"(",
"(",
"bool",
")",
"$",
"show",
"===",
"$",
"this",
"->",
"requireExistingPassword",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"requireExistingPassword",
"=",
"$",
"show",
";",
"$",
"name",
"=",
"$",
"this",
"->",
"getName",
"(",
")",
";",
"$",
"currentName",
"=",
"\"{$name}[_CurrentPassword]\"",
";",
"if",
"(",
"$",
"show",
")",
"{",
"$",
"confirmField",
"=",
"PasswordField",
"::",
"create",
"(",
"$",
"currentName",
",",
"_t",
"(",
"'SilverStripe\\\\Security\\\\Member.CURRENT_PASSWORD'",
",",
"'Current Password'",
")",
")",
";",
"$",
"this",
"->",
"getChildren",
"(",
")",
"->",
"unshift",
"(",
"$",
"confirmField",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"getChildren",
"(",
")",
"->",
"removeByName",
"(",
"$",
"currentName",
",",
"true",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Set if the existing password should be required
@param bool $show Flag to show or hide this field
@return $this | [
"Set",
"if",
"the",
"existing",
"password",
"should",
"be",
"required"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Forms/ConfirmedPasswordField.php#L604-L620 | train |
silverstripe/silverstripe-framework | src/Core/Startup/ConfirmationTokenChain.php | ConfirmationTokenChain.filteredTokens | protected function filteredTokens()
{
foreach ($this->tokens as $token) {
if ($token->reloadRequired() || $token->reloadRequiredIfError()) {
yield $token;
}
}
} | php | protected function filteredTokens()
{
foreach ($this->tokens as $token) {
if ($token->reloadRequired() || $token->reloadRequiredIfError()) {
yield $token;
}
}
} | [
"protected",
"function",
"filteredTokens",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"tokens",
"as",
"$",
"token",
")",
"{",
"if",
"(",
"$",
"token",
"->",
"reloadRequired",
"(",
")",
"||",
"$",
"token",
"->",
"reloadRequiredIfError",
"(",
")",
")",
"{",
"yield",
"$",
"token",
";",
"}",
"}",
"}"
]
| Collect all tokens that require a redirect
@return \Generator | [
"Collect",
"all",
"tokens",
"that",
"require",
"a",
"redirect"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Startup/ConfirmationTokenChain.php#L36-L43 | train |
silverstripe/silverstripe-framework | src/Core/Startup/ConfirmationTokenChain.php | ConfirmationTokenChain.getRedirectUrlParams | public function getRedirectUrlParams()
{
$params = $_GET;
unset($params['url']); // CLIRequestBuilder may add this
foreach ($this->filteredTokens() as $token) {
$params = array_merge($params, $token->params());
}
return $params;
} | php | public function getRedirectUrlParams()
{
$params = $_GET;
unset($params['url']); // CLIRequestBuilder may add this
foreach ($this->filteredTokens() as $token) {
$params = array_merge($params, $token->params());
}
return $params;
} | [
"public",
"function",
"getRedirectUrlParams",
"(",
")",
"{",
"$",
"params",
"=",
"$",
"_GET",
";",
"unset",
"(",
"$",
"params",
"[",
"'url'",
"]",
")",
";",
"// CLIRequestBuilder may add this",
"foreach",
"(",
"$",
"this",
"->",
"filteredTokens",
"(",
")",
"as",
"$",
"token",
")",
"{",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"params",
",",
"$",
"token",
"->",
"params",
"(",
")",
")",
";",
"}",
"return",
"$",
"params",
";",
"}"
]
| Collate GET vars from all token providers that need to apply a token
@return array | [
"Collate",
"GET",
"vars",
"from",
"all",
"token",
"providers",
"that",
"need",
"to",
"apply",
"a",
"token"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Startup/ConfirmationTokenChain.php#L140-L149 | train |
silverstripe/silverstripe-framework | src/ORM/ArrayLib.php | ArrayLib.invert | public static function invert($arr)
{
if (!$arr) {
return [];
}
$result = array();
foreach ($arr as $columnName => $column) {
foreach ($column as $rowName => $cell) {
$result[$rowName][$columnName] = $cell;
}
}
return $result;
} | php | public static function invert($arr)
{
if (!$arr) {
return [];
}
$result = array();
foreach ($arr as $columnName => $column) {
foreach ($column as $rowName => $cell) {
$result[$rowName][$columnName] = $cell;
}
}
return $result;
} | [
"public",
"static",
"function",
"invert",
"(",
"$",
"arr",
")",
"{",
"if",
"(",
"!",
"$",
"arr",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"arr",
"as",
"$",
"columnName",
"=>",
"$",
"column",
")",
"{",
"foreach",
"(",
"$",
"column",
"as",
"$",
"rowName",
"=>",
"$",
"cell",
")",
"{",
"$",
"result",
"[",
"$",
"rowName",
"]",
"[",
"$",
"columnName",
"]",
"=",
"$",
"cell",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
]
| Inverses the first and second level keys of an associative
array, keying the result by the second level, and combines
all first level entries within them.
Before:
<example>
array(
'row1' => array(
'col1' =>'val1',
'col2' => 'val2'
),
'row2' => array(
'col1' => 'val3',
'col2' => 'val4'
)
)
</example>
After:
<example>
array(
'col1' => array(
'row1' => 'val1',
'row2' => 'val3',
),
'col2' => array(
'row1' => 'val2',
'row2' => 'val4',
),
)
</example>
@param array $arr
@return array | [
"Inverses",
"the",
"first",
"and",
"second",
"level",
"keys",
"of",
"an",
"associative",
"array",
"keying",
"the",
"result",
"by",
"the",
"second",
"level",
"and",
"combines",
"all",
"first",
"level",
"entries",
"within",
"them",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/ArrayLib.php#L49-L64 | train |
silverstripe/silverstripe-framework | src/ORM/ArrayLib.php | ArrayLib.array_map_recursive | public static function array_map_recursive($f, $array)
{
$applyOrRecurse = function ($v) use ($f) {
return is_array($v) ? ArrayLib::array_map_recursive($f, $v) : call_user_func($f, $v);
};
return array_map($applyOrRecurse, $array);
} | php | public static function array_map_recursive($f, $array)
{
$applyOrRecurse = function ($v) use ($f) {
return is_array($v) ? ArrayLib::array_map_recursive($f, $v) : call_user_func($f, $v);
};
return array_map($applyOrRecurse, $array);
} | [
"public",
"static",
"function",
"array_map_recursive",
"(",
"$",
"f",
",",
"$",
"array",
")",
"{",
"$",
"applyOrRecurse",
"=",
"function",
"(",
"$",
"v",
")",
"use",
"(",
"$",
"f",
")",
"{",
"return",
"is_array",
"(",
"$",
"v",
")",
"?",
"ArrayLib",
"::",
"array_map_recursive",
"(",
"$",
"f",
",",
"$",
"v",
")",
":",
"call_user_func",
"(",
"$",
"f",
",",
"$",
"v",
")",
";",
"}",
";",
"return",
"array_map",
"(",
"$",
"applyOrRecurse",
",",
"$",
"array",
")",
";",
"}"
]
| Similar to array_map, but recurses when arrays are encountered.
Actually only one array argument is supported.
@param $f callback to apply
@param $array array
@return array | [
"Similar",
"to",
"array_map",
"but",
"recurses",
"when",
"arrays",
"are",
"encountered",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/ArrayLib.php#L167-L174 | train |
silverstripe/silverstripe-framework | src/ORM/ArrayLib.php | ArrayLib.array_merge_recursive | public static function array_merge_recursive($array)
{
$arrays = func_get_args();
$merged = array();
if (count($arrays) == 1) {
return $array;
}
while ($arrays) {
$array = array_shift($arrays);
if (!is_array($array)) {
trigger_error(
'SilverStripe\ORM\ArrayLib::array_merge_recursive() encountered a non array argument',
E_USER_WARNING
);
return [];
}
if (!$array) {
continue;
}
foreach ($array as $key => $value) {
if (is_array($value) && array_key_exists($key, $merged) && is_array($merged[$key])) {
$merged[$key] = ArrayLib::array_merge_recursive($merged[$key], $value);
} else {
$merged[$key] = $value;
}
}
}
return $merged;
} | php | public static function array_merge_recursive($array)
{
$arrays = func_get_args();
$merged = array();
if (count($arrays) == 1) {
return $array;
}
while ($arrays) {
$array = array_shift($arrays);
if (!is_array($array)) {
trigger_error(
'SilverStripe\ORM\ArrayLib::array_merge_recursive() encountered a non array argument',
E_USER_WARNING
);
return [];
}
if (!$array) {
continue;
}
foreach ($array as $key => $value) {
if (is_array($value) && array_key_exists($key, $merged) && is_array($merged[$key])) {
$merged[$key] = ArrayLib::array_merge_recursive($merged[$key], $value);
} else {
$merged[$key] = $value;
}
}
}
return $merged;
} | [
"public",
"static",
"function",
"array_merge_recursive",
"(",
"$",
"array",
")",
"{",
"$",
"arrays",
"=",
"func_get_args",
"(",
")",
";",
"$",
"merged",
"=",
"array",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"arrays",
")",
"==",
"1",
")",
"{",
"return",
"$",
"array",
";",
"}",
"while",
"(",
"$",
"arrays",
")",
"{",
"$",
"array",
"=",
"array_shift",
"(",
"$",
"arrays",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"array",
")",
")",
"{",
"trigger_error",
"(",
"'SilverStripe\\ORM\\ArrayLib::array_merge_recursive() encountered a non array argument'",
",",
"E_USER_WARNING",
")",
";",
"return",
"[",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"array",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"merged",
")",
"&&",
"is_array",
"(",
"$",
"merged",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"merged",
"[",
"$",
"key",
"]",
"=",
"ArrayLib",
"::",
"array_merge_recursive",
"(",
"$",
"merged",
"[",
"$",
"key",
"]",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"merged",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"return",
"$",
"merged",
";",
"}"
]
| Recursively merges two or more arrays.
Behaves similar to array_merge_recursive(), however it only merges
values when both are arrays rather than creating a new array with
both values, as the PHP version does. The same behaviour also occurs
with numeric keys, to match that of what PHP does to generate $_REQUEST.
@param array $array
@return array | [
"Recursively",
"merges",
"two",
"or",
"more",
"arrays",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/ArrayLib.php#L188-L222 | train |
silverstripe/silverstripe-framework | src/ORM/ArrayLib.php | ArrayLib.flatten | public static function flatten($array, $preserveKeys = true, &$out = array())
{
array_walk_recursive(
$array,
function ($value, $key) use (&$out, $preserveKeys) {
if (!is_scalar($value)) {
// Do nothing
} elseif ($preserveKeys) {
$out[$key] = $value;
} else {
$out[] = $value;
}
}
);
return $out;
} | php | public static function flatten($array, $preserveKeys = true, &$out = array())
{
array_walk_recursive(
$array,
function ($value, $key) use (&$out, $preserveKeys) {
if (!is_scalar($value)) {
// Do nothing
} elseif ($preserveKeys) {
$out[$key] = $value;
} else {
$out[] = $value;
}
}
);
return $out;
} | [
"public",
"static",
"function",
"flatten",
"(",
"$",
"array",
",",
"$",
"preserveKeys",
"=",
"true",
",",
"&",
"$",
"out",
"=",
"array",
"(",
")",
")",
"{",
"array_walk_recursive",
"(",
"$",
"array",
",",
"function",
"(",
"$",
"value",
",",
"$",
"key",
")",
"use",
"(",
"&",
"$",
"out",
",",
"$",
"preserveKeys",
")",
"{",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"// Do nothing",
"}",
"elseif",
"(",
"$",
"preserveKeys",
")",
"{",
"$",
"out",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"out",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"}",
")",
";",
"return",
"$",
"out",
";",
"}"
]
| Takes an multi dimension array and returns the flattened version.
@param array $array
@param boolean $preserveKeys
@param array $out
@return array | [
"Takes",
"an",
"multi",
"dimension",
"array",
"and",
"returns",
"the",
"flattened",
"version",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/ArrayLib.php#L233-L249 | train |
silverstripe/silverstripe-framework | src/Control/RSS/RSSFeed_Entry.php | RSSFeed_Entry.Description | public function Description()
{
$description = $this->rssField($this->descriptionField);
// HTML fields need links re-written
if ($description instanceof DBHTMLText) {
return $description->obj('AbsoluteLinks');
}
return $description;
} | php | public function Description()
{
$description = $this->rssField($this->descriptionField);
// HTML fields need links re-written
if ($description instanceof DBHTMLText) {
return $description->obj('AbsoluteLinks');
}
return $description;
} | [
"public",
"function",
"Description",
"(",
")",
"{",
"$",
"description",
"=",
"$",
"this",
"->",
"rssField",
"(",
"$",
"this",
"->",
"descriptionField",
")",
";",
"// HTML fields need links re-written",
"if",
"(",
"$",
"description",
"instanceof",
"DBHTMLText",
")",
"{",
"return",
"$",
"description",
"->",
"obj",
"(",
"'AbsoluteLinks'",
")",
";",
"}",
"return",
"$",
"description",
";",
"}"
]
| Get the description of this entry
@return DBField Returns the description of the entry. | [
"Get",
"the",
"description",
"of",
"this",
"entry"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Control/RSS/RSSFeed_Entry.php#L80-L90 | train |
silverstripe/silverstripe-framework | src/Control/RSS/RSSFeed_Entry.php | RSSFeed_Entry.AbsoluteLink | public function AbsoluteLink()
{
if ($this->failover->hasMethod('AbsoluteLink')) {
return $this->failover->AbsoluteLink();
} else {
if ($this->failover->hasMethod('Link')) {
return Director::absoluteURL($this->failover->Link());
}
}
throw new BadMethodCallException(
get_class($this->failover) . " object has neither an AbsoluteLink nor a Link method." . " Can't put a link in the RSS feed",
E_USER_WARNING
);
} | php | public function AbsoluteLink()
{
if ($this->failover->hasMethod('AbsoluteLink')) {
return $this->failover->AbsoluteLink();
} else {
if ($this->failover->hasMethod('Link')) {
return Director::absoluteURL($this->failover->Link());
}
}
throw new BadMethodCallException(
get_class($this->failover) . " object has neither an AbsoluteLink nor a Link method." . " Can't put a link in the RSS feed",
E_USER_WARNING
);
} | [
"public",
"function",
"AbsoluteLink",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"failover",
"->",
"hasMethod",
"(",
"'AbsoluteLink'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"failover",
"->",
"AbsoluteLink",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"failover",
"->",
"hasMethod",
"(",
"'Link'",
")",
")",
"{",
"return",
"Director",
"::",
"absoluteURL",
"(",
"$",
"this",
"->",
"failover",
"->",
"Link",
"(",
")",
")",
";",
"}",
"}",
"throw",
"new",
"BadMethodCallException",
"(",
"get_class",
"(",
"$",
"this",
"->",
"failover",
")",
".",
"\" object has neither an AbsoluteLink nor a Link method.\"",
".",
"\" Can't put a link in the RSS feed\"",
",",
"E_USER_WARNING",
")",
";",
"}"
]
| Get a link to this entry
@return string Returns the URL of this entry
@throws BadMethodCallException | [
"Get",
"a",
"link",
"to",
"this",
"entry"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Control/RSS/RSSFeed_Entry.php#L122-L136 | train |
appzcoder/laravel-admin | src/Setting.php | Setting.set | public function set($key, $value)
{
$setting = SettingModel::create(
[
'key' => $key,
'value' => $value,
]
);
return $setting ? $value : false;
} | php | public function set($key, $value)
{
$setting = SettingModel::create(
[
'key' => $key,
'value' => $value,
]
);
return $setting ? $value : false;
} | [
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"setting",
"=",
"SettingModel",
"::",
"create",
"(",
"[",
"'key'",
"=>",
"$",
"key",
",",
"'value'",
"=>",
"$",
"value",
",",
"]",
")",
";",
"return",
"$",
"setting",
"?",
"$",
"value",
":",
"false",
";",
"}"
]
| Set value against a key.
@param string $key
@param mixed $value
@return mixed | [
"Set",
"value",
"against",
"a",
"key",
"."
]
| 70fcbbd82a267b5bbd462e23945dbcf13cab43b2 | https://github.com/appzcoder/laravel-admin/blob/70fcbbd82a267b5bbd462e23945dbcf13cab43b2/src/Setting.php#L18-L28 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.