repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
UnionOfRAD/lithium | data/source/Database.php | Database.read | public function read($query, array $options = []) {
$defaults = [
'return' => is_string($query) ? 'array' : 'item',
'schema' => null,
'quotes' => $this->_quotes
];
$options += $defaults;
$params = compact('query', 'options');
return Filters::run($this, __FUNCTION__, $params, function($params) {
... | php | public function read($query, array $options = []) {
$defaults = [
'return' => is_string($query) ? 'array' : 'item',
'schema' => null,
'quotes' => $this->_quotes
];
$options += $defaults;
$params = compact('query', 'options');
return Filters::run($this, __FUNCTION__, $params, function($params) {
... | [
"public",
"function",
"read",
"(",
"$",
"query",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'return'",
"=>",
"is_string",
"(",
"$",
"query",
")",
"?",
"'array'",
":",
"'item'",
",",
"'schema'",
"=>",
"null",
... | Reads records from a database using a `lithium\data\model\Query` object or raw SQL string.
@param string|object $query `lithium\data\model\Query` object or SQL string.
@param array $options If `$query` is a raw string, contains the values that will be escaped
and quoted. Other options:
- `'return'` _string_: switch re... | [
"Reads",
"records",
"from",
"a",
"database",
"using",
"a",
"lithium",
"\\",
"data",
"\\",
"model",
"\\",
"Query",
"object",
"or",
"raw",
"SQL",
"string",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L573-L632 |
UnionOfRAD/lithium | data/source/Database.php | Database.& | protected function &_queryExport($query) {
$data = $query->export($this);
if (!$query->limit() || !($model = $query->model())) {
return $data;
}
foreach ($query->relationships() as $relation) {
if ($relation['type'] !== 'hasMany') {
continue;
}
$pk = $this->name($model::meta('name') . '.' . $mo... | php | protected function &_queryExport($query) {
$data = $query->export($this);
if (!$query->limit() || !($model = $query->model())) {
return $data;
}
foreach ($query->relationships() as $relation) {
if ($relation['type'] !== 'hasMany') {
continue;
}
$pk = $this->name($model::meta('name') . '.' . $mo... | [
"protected",
"function",
"&",
"_queryExport",
"(",
"$",
"query",
")",
"{",
"$",
"data",
"=",
"$",
"query",
"->",
"export",
"(",
"$",
"this",
")",
";",
"if",
"(",
"!",
"$",
"query",
"->",
"limit",
"(",
")",
"||",
"!",
"(",
"$",
"model",
"=",
"$"... | Helper method for `Database::read()` to export query while handling additional joins
when using relationships and limited result sets. Filters conditions on subsequent
queries to just the ones applying to the relation.
@see lithium\data\source\Database::read()
@param object $query The query object.
@return array The e... | [
"Helper",
"method",
"for",
"Database",
"::",
"read",
"()",
"to",
"export",
"query",
"while",
"handling",
"additional",
"joins",
"when",
"using",
"relationships",
"and",
"limited",
"result",
"sets",
".",
"Filters",
"conditions",
"on",
"subsequent",
"queries",
"to... | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L643-L685 |
UnionOfRAD/lithium | data/source/Database.php | Database.update | public function update($query, array $options = []) {
$params = compact('query', 'options');
return Filters::run($this, __FUNCTION__, $params, function($params) {
$query = $params['query'];
$exportedQuery = $query->export($this);
if ($exportedQuery['fields'] === null) {
return true;
}
$sql = $... | php | public function update($query, array $options = []) {
$params = compact('query', 'options');
return Filters::run($this, __FUNCTION__, $params, function($params) {
$query = $params['query'];
$exportedQuery = $query->export($this);
if ($exportedQuery['fields'] === null) {
return true;
}
$sql = $... | [
"public",
"function",
"update",
"(",
"$",
"query",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"params",
"=",
"compact",
"(",
"'query'",
",",
"'options'",
")",
";",
"return",
"Filters",
"::",
"run",
"(",
"$",
"this",
",",
"__FUNCTION_... | Updates a record in the database based on the given `Query`.
@param object $query A `lithium\data\model\Query` object
@param array $options none
@return boolean
@filter | [
"Updates",
"a",
"record",
"in",
"the",
"database",
"based",
"on",
"the",
"given",
"Query",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L695-L714 |
UnionOfRAD/lithium | data/source/Database.php | Database.delete | public function delete($query, array $options = []) {
$params = compact('query', 'options');
return Filters::run($this, __FUNCTION__, $params, function($params) {
$query = $params['query'];
$isObject = is_object($query);
if ($isObject) {
$sql = $this->renderCommand('delete', $query->export($this), $q... | php | public function delete($query, array $options = []) {
$params = compact('query', 'options');
return Filters::run($this, __FUNCTION__, $params, function($params) {
$query = $params['query'];
$isObject = is_object($query);
if ($isObject) {
$sql = $this->renderCommand('delete', $query->export($this), $q... | [
"public",
"function",
"delete",
"(",
"$",
"query",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"params",
"=",
"compact",
"(",
"'query'",
",",
"'options'",
")",
";",
"return",
"Filters",
"::",
"run",
"(",
"$",
"this",
",",
"__FUNCTION_... | Deletes a record in the database based on the given `Query`.
@param object $query An SQL string, or `lithium\data\model\Query` object instance.
@param array $options If `$query` is a string, `$options` is the array of quoted/escaped
parameter values to be inserted into the query.
@return boolean Returns `true` on succ... | [
"Deletes",
"a",
"record",
"in",
"the",
"database",
"based",
"on",
"the",
"given",
"Query",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L726-L745 |
UnionOfRAD/lithium | data/source/Database.php | Database.calculation | public function calculation($type, $query, array $options = []) {
$query->calculate($type);
switch ($type) {
case 'count':
if (strpos($fields = $this->fields($query->fields(), $query), ',') !== false) {
$fields = "*";
}
$query->fields("COUNT({$fields}) as count", true);
$query->map([$query-... | php | public function calculation($type, $query, array $options = []) {
$query->calculate($type);
switch ($type) {
case 'count':
if (strpos($fields = $this->fields($query->fields(), $query), ',') !== false) {
$fields = "*";
}
$query->fields("COUNT({$fields}) as count", true);
$query->map([$query-... | [
"public",
"function",
"calculation",
"(",
"$",
"type",
",",
"$",
"query",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"query",
"->",
"calculate",
"(",
"$",
"type",
")",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'count'",
... | Executes calculation-related queries, such as those required for `count` and other
aggregates.
When building `count` queries and a single field is given, will use that to build
the `COUNT()` fragment. When multiple fields are given forces a `COUNT(*)`.
@param string $type Only accepts `count`.
@param mixed $query The... | [
"Executes",
"calculation",
"-",
"related",
"queries",
"such",
"as",
"those",
"required",
"for",
"count",
"and",
"other",
"aggregates",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L760-L778 |
UnionOfRAD/lithium | data/source/Database.php | Database.relationship | public function relationship($class, $type, $name, array $config = []) {
$primary = $class::meta('key');
if (is_array($primary)) {
$key = array_combine($primary, $primary);
} elseif ($type === 'hasMany' || $type === 'hasOne') {
$secondary = Inflector::underscore(Inflector::singularize($class::meta('name'))... | php | public function relationship($class, $type, $name, array $config = []) {
$primary = $class::meta('key');
if (is_array($primary)) {
$key = array_combine($primary, $primary);
} elseif ($type === 'hasMany' || $type === 'hasOne') {
$secondary = Inflector::underscore(Inflector::singularize($class::meta('name'))... | [
"public",
"function",
"relationship",
"(",
"$",
"class",
",",
"$",
"type",
",",
"$",
"name",
",",
"array",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"$",
"primary",
"=",
"$",
"class",
"::",
"meta",
"(",
"'key'",
")",
";",
"if",
"(",
"is_array",
"("... | Defines or modifies the default settings of a relationship between two models.
@param string $class the primary model of the relationship
@param string $type the type of the relationship (hasMany, hasOne, belongsTo)
@param string $name the name of the relationship
@param array $config relationship options
@return arra... | [
"Defines",
"or",
"modifies",
"the",
"default",
"settings",
"of",
"a",
"relationship",
"between",
"two",
"models",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L789-L805 |
UnionOfRAD/lithium | data/source/Database.php | Database.renderCommand | public function renderCommand($type, $data = null, $context = null) {
if (is_object($type)) {
$context = $type;
$data = $context->export($this);
$type = $context->type();
}
if (!isset($this->_strings[$type])) {
throw new InvalidArgumentException("Invalid query type `{$type}`.");
}
$template = $thi... | php | public function renderCommand($type, $data = null, $context = null) {
if (is_object($type)) {
$context = $type;
$data = $context->export($this);
$type = $context->type();
}
if (!isset($this->_strings[$type])) {
throw new InvalidArgumentException("Invalid query type `{$type}`.");
}
$template = $thi... | [
"public",
"function",
"renderCommand",
"(",
"$",
"type",
",",
"$",
"data",
"=",
"null",
",",
"$",
"context",
"=",
"null",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"type",
")",
")",
"{",
"$",
"context",
"=",
"$",
"type",
";",
"$",
"data",
"=",
... | Returns a given `type` statement for the given data, rendered from `Database::$_strings`.
@param string $type One of `'create'`, `'read'`, `'update'`, `'delete'` or `'join'`.
@param string $data The data to replace in the string.
@param string $context
@return string | [
"Returns",
"a",
"given",
"type",
"statement",
"for",
"the",
"given",
"data",
"rendered",
"from",
"Database",
"::",
"$_strings",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L827-L844 |
UnionOfRAD/lithium | data/source/Database.php | Database.schema | public function schema($query, $resource = null, $context = null) {
if (is_object($query)) {
$query->applyStrategy($this);
return $this->_schema($query, $this->_fields($query->fields(), $query));
}
$result = [];
if (!$resource || !$resource->resource()) {
return $result;
}
$count = $resource->reso... | php | public function schema($query, $resource = null, $context = null) {
if (is_object($query)) {
$query->applyStrategy($this);
return $this->_schema($query, $this->_fields($query->fields(), $query));
}
$result = [];
if (!$resource || !$resource->resource()) {
return $result;
}
$count = $resource->reso... | [
"public",
"function",
"schema",
"(",
"$",
"query",
",",
"$",
"resource",
"=",
"null",
",",
"$",
"context",
"=",
"null",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"query",
")",
")",
"{",
"$",
"query",
"->",
"applyStrategy",
"(",
"$",
"this",
")",
... | Builds an array of keyed on the fully-namespaced `Model` with array of fields as values
for the given `Query`
@param \lithium\data\model\Query $query A Query instance.
@param \lithium\data\source\Result|null $resource An optional a result resource.
@param object|null $context
@return array | [
"Builds",
"an",
"array",
"of",
"keyed",
"on",
"the",
"fully",
"-",
"namespaced",
"Model",
"with",
"array",
"of",
"fields",
"as",
"values",
"for",
"the",
"given",
"Query"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L855-L872 |
UnionOfRAD/lithium | data/source/Database.php | Database._schema | protected function _schema($query, $fields = null) {
$model = $query->model();
$paths = $query->paths($this);
$models = $query->models($this);
$alias = $query->alias();
$result = [];
if (!$model) {
foreach ($fields as $field => $value) {
if (is_array($value)) {
$result[$field] = array_keys($val... | php | protected function _schema($query, $fields = null) {
$model = $query->model();
$paths = $query->paths($this);
$models = $query->models($this);
$alias = $query->alias();
$result = [];
if (!$model) {
foreach ($fields as $field => $value) {
if (is_array($value)) {
$result[$field] = array_keys($val... | [
"protected",
"function",
"_schema",
"(",
"$",
"query",
",",
"$",
"fields",
"=",
"null",
")",
"{",
"$",
"model",
"=",
"$",
"query",
"->",
"model",
"(",
")",
";",
"$",
"paths",
"=",
"$",
"query",
"->",
"paths",
"(",
"$",
"this",
")",
";",
"$",
"m... | Helper method for `data\model\Database::shema()`
@param \lithium\data\model\Query $query A Query instance.
@param array|null $fields Array of formatted fields.
@return array | [
"Helper",
"method",
"for",
"data",
"\\",
"model",
"\\",
"Database",
"::",
"shema",
"()"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L881-L936 |
UnionOfRAD/lithium | data/source/Database.php | Database.conditions | public function conditions($conditions, $context, array $options = []) {
$defaults = ['prepend' => 'WHERE'];
$options += $defaults;
return $this->_conditions($conditions, $context, $options);
} | php | public function conditions($conditions, $context, array $options = []) {
$defaults = ['prepend' => 'WHERE'];
$options += $defaults;
return $this->_conditions($conditions, $context, $options);
} | [
"public",
"function",
"conditions",
"(",
"$",
"conditions",
",",
"$",
"context",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'prepend'",
"=>",
"'WHERE'",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"re... | Returns a string of formatted conditions to be inserted into the query statement. If the
query conditions are defined as an array, key pairs are converted to SQL strings.
Conversion rules are as follows:
- If `$key` is numeric and `$value` is a string, `$value` is treated as a literal SQL
fragment and returned.
@par... | [
"Returns",
"a",
"string",
"of",
"formatted",
"conditions",
"to",
"be",
"inserted",
"into",
"the",
"query",
"statement",
".",
"If",
"the",
"query",
"conditions",
"are",
"defined",
"as",
"an",
"array",
"key",
"pairs",
"are",
"converted",
"to",
"SQL",
"strings"... | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L954-L958 |
UnionOfRAD/lithium | data/source/Database.php | Database._conditions | protected function _conditions($conditions, $context, array $options = []) {
$defaults = ['prepend' => false];
$options += $defaults;
switch (true) {
case empty($conditions):
return '';
case is_string($conditions):
return $options['prepend'] ? $options['prepend'] . " {$conditions}" : $conditions;
... | php | protected function _conditions($conditions, $context, array $options = []) {
$defaults = ['prepend' => false];
$options += $defaults;
switch (true) {
case empty($conditions):
return '';
case is_string($conditions):
return $options['prepend'] ? $options['prepend'] . " {$conditions}" : $conditions;
... | [
"protected",
"function",
"_conditions",
"(",
"$",
"conditions",
",",
"$",
"context",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'prepend'",
"=>",
"false",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"... | Returns a string of formatted conditions to be inserted into the query statement.
If the query conditions are defined as an array, key pairs are converted to SQL strings.
If `$key` is numeric and `$value` is a string, `$value` is treated as a literal SQL
fragment and returned.
@param string|array $conditions The cond... | [
"Returns",
"a",
"string",
"of",
"formatted",
"conditions",
"to",
"be",
"inserted",
"into",
"the",
"query",
"statement",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L996-L1019 |
UnionOfRAD/lithium | data/source/Database.php | Database._processOperator | protected function _processOperator($key, $value, $fieldMeta, $glue) {
if (!is_string($key) || !is_array($value)) {
return false;
}
$operator = strtoupper(key($value));
if (!is_numeric($operator)) {
if (!isset($this->_operators[$operator])) {
throw new QueryException("Unsupported operator `{$operator}... | php | protected function _processOperator($key, $value, $fieldMeta, $glue) {
if (!is_string($key) || !is_array($value)) {
return false;
}
$operator = strtoupper(key($value));
if (!is_numeric($operator)) {
if (!isset($this->_operators[$operator])) {
throw new QueryException("Unsupported operator `{$operator}... | [
"protected",
"function",
"_processOperator",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"fieldMeta",
",",
"$",
"glue",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"key",
")",
"||",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return"... | Helper method used by `_processConditions`.
@param string The field name string.
@param array The operator to parse.
@param array The schema of the field.
@param string The glue operator (e.g `'AND'` or '`OR`'.
@return mixed Returns the operator expression string or `false` if no operator
is applicable.
@throws A `Que... | [
"Helper",
"method",
"used",
"by",
"_processConditions",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1085-L1100 |
UnionOfRAD/lithium | data/source/Database.php | Database.fields | public function fields($fields, $context) {
$type = $context->type();
$schema = $context->schema()->fields();
$alias = $context->alias();
if (!is_array($fields)) {
return $this->_fieldsReturn($type, $context, $fields, $schema);
}
$context->applyStrategy($this);
$fields = $this->_fields($fields ? : $c... | php | public function fields($fields, $context) {
$type = $context->type();
$schema = $context->schema()->fields();
$alias = $context->alias();
if (!is_array($fields)) {
return $this->_fieldsReturn($type, $context, $fields, $schema);
}
$context->applyStrategy($this);
$fields = $this->_fields($fields ? : $c... | [
"public",
"function",
"fields",
"(",
"$",
"fields",
",",
"$",
"context",
")",
"{",
"$",
"type",
"=",
"$",
"context",
"->",
"type",
"(",
")",
";",
"$",
"schema",
"=",
"$",
"context",
"->",
"schema",
"(",
")",
"->",
"fields",
"(",
")",
";",
"$",
... | Returns a string of formatted fields to be inserted into the query statement.
@param array $fields Array of fields.
@param object $context Generally a `data\model\Query` instance.
@return string A SQL formatted string | [
"Returns",
"a",
"string",
"of",
"formatted",
"fields",
"to",
"be",
"inserted",
"into",
"the",
"query",
"statement",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1109-L1145 |
UnionOfRAD/lithium | data/source/Database.php | Database._fields | protected function _fields($fields, $context) {
$alias = $context->alias();
$models = $context->models($this);
$list = [];
foreach ($fields as $key => $field) {
if (!is_string($field)) {
if (isset($models[$key])) {
$field = array_fill_keys($field, true);
$list[$key] = isset($list[$key]) ? arra... | php | protected function _fields($fields, $context) {
$alias = $context->alias();
$models = $context->models($this);
$list = [];
foreach ($fields as $key => $field) {
if (!is_string($field)) {
if (isset($models[$key])) {
$field = array_fill_keys($field, true);
$list[$key] = isset($list[$key]) ? arra... | [
"protected",
"function",
"_fields",
"(",
"$",
"fields",
",",
"$",
"context",
")",
"{",
"$",
"alias",
"=",
"$",
"context",
"->",
"alias",
"(",
")",
";",
"$",
"models",
"=",
"$",
"context",
"->",
"models",
"(",
"$",
"this",
")",
";",
"$",
"list",
"... | Reformats fields to be alias based.
@see lithium\data\source\Database::fields()
@see lithium\data\source\Database::schema()
@param array $fields Array of fields.
@param object $context Generally a `data\model\Query` instance.
@return array Reformatted fields | [
"Reformats",
"fields",
"to",
"be",
"alias",
"based",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1156-L1180 |
UnionOfRAD/lithium | data/source/Database.php | Database._fieldsQuote | protected function _fieldsQuote($alias, $field) {
list($open, $close) = $this->_quotes;
$aliasing = preg_split("/\s+as\s+/i", $field);
if (isset($aliasing[1])) {
list($aliasname, $fieldname) = $this->_splitFieldname($aliasing[0]);
$alias = $aliasname ? : $alias;
return "{$open}{$alias}{$close}.{$open}{$... | php | protected function _fieldsQuote($alias, $field) {
list($open, $close) = $this->_quotes;
$aliasing = preg_split("/\s+as\s+/i", $field);
if (isset($aliasing[1])) {
list($aliasname, $fieldname) = $this->_splitFieldname($aliasing[0]);
$alias = $aliasname ? : $alias;
return "{$open}{$alias}{$close}.{$open}{$... | [
"protected",
"function",
"_fieldsQuote",
"(",
"$",
"alias",
",",
"$",
"field",
")",
"{",
"list",
"(",
"$",
"open",
",",
"$",
"close",
")",
"=",
"$",
"this",
"->",
"_quotes",
";",
"$",
"aliasing",
"=",
"preg_split",
"(",
"\"/\\s+as\\s+/i\"",
",",
"$",
... | Quotes fields, also handles aliased fields.
@see lithium\data\source\Database::fields()
@param string $alias
@param string $field
@return string The quoted field. | [
"Quotes",
"fields",
"also",
"handles",
"aliased",
"fields",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1190-L1203 |
UnionOfRAD/lithium | data/source/Database.php | Database._fieldsReturn | protected function _fieldsReturn($type, $context, $fields, $schema) {
if ($type === 'create' || $type === 'update') {
$data = $context->data();
if (isset($data['data']) && is_array($data['data']) && count($data) === 1) {
$data = $data['data'];
}
if ($fields && is_array($fields) && is_int(key($fields)... | php | protected function _fieldsReturn($type, $context, $fields, $schema) {
if ($type === 'create' || $type === 'update') {
$data = $context->data();
if (isset($data['data']) && is_array($data['data']) && count($data) === 1) {
$data = $data['data'];
}
if ($fields && is_array($fields) && is_int(key($fields)... | [
"protected",
"function",
"_fieldsReturn",
"(",
"$",
"type",
",",
"$",
"context",
",",
"$",
"fields",
",",
"$",
"schema",
")",
"{",
"if",
"(",
"$",
"type",
"===",
"'create'",
"||",
"$",
"type",
"===",
"'update'",
")",
"{",
"$",
"data",
"=",
"$",
"co... | Renders the fields SQL fragment for queries.
@see lithium\data\source\Database::fields()
@param string $type Type of query i.e. `'create'` or `'update'`.
@param object $context Generally a `data\model\Query` instance.
@param array $fields
@param array $schema An array defining the schema of the fields used in the crit... | [
"Renders",
"the",
"fields",
"SQL",
"fragment",
"for",
"queries",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1215-L1229 |
UnionOfRAD/lithium | data/source/Database.php | Database._createFields | protected function _createFields($data, $schema, $context) {
$fields = [];
$values = [];
foreach ($data as $field => $value) {
$fields[] = $this->name($field);
$values[] = $this->value($value, isset($schema[$field]) ? $schema[$field] : []);
}
return [
'fields' => join(', ', $fields),
'values' => ... | php | protected function _createFields($data, $schema, $context) {
$fields = [];
$values = [];
foreach ($data as $field => $value) {
$fields[] = $this->name($field);
$values[] = $this->value($value, isset($schema[$field]) ? $schema[$field] : []);
}
return [
'fields' => join(', ', $fields),
'values' => ... | [
"protected",
"function",
"_createFields",
"(",
"$",
"data",
",",
"$",
"schema",
",",
"$",
"context",
")",
"{",
"$",
"fields",
"=",
"[",
"]",
";",
"$",
"values",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"field",
"=>",
"$",
"valu... | Renders the fields part for _create_ queries.
@see lithium\data\source\Database::_fieldsReturn()
@param array $data
@param array $schema An array defining the schema of the fields used in the criteria.
@param object $context Generally a `data\model\Query` instance.
@return array Array with `fields` and `values` keys w... | [
"Renders",
"the",
"fields",
"part",
"for",
"_create_",
"queries",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1241-L1253 |
UnionOfRAD/lithium | data/source/Database.php | Database._updateFields | protected function _updateFields($data, $schema, $context) {
$fields = [];
$increment = [];
if ($entity = $context->entity()) {
$export = $entity->export();
$increment = $export['increment'];
array_map(function($key) use (&$data, $export){
if (!empty($data[$key]) && $export['data'][$key] === $data[... | php | protected function _updateFields($data, $schema, $context) {
$fields = [];
$increment = [];
if ($entity = $context->entity()) {
$export = $entity->export();
$increment = $export['increment'];
array_map(function($key) use (&$data, $export){
if (!empty($data[$key]) && $export['data'][$key] === $data[... | [
"protected",
"function",
"_updateFields",
"(",
"$",
"data",
",",
"$",
"schema",
",",
"$",
"context",
")",
"{",
"$",
"fields",
"=",
"[",
"]",
";",
"$",
"increment",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"entity",
"=",
"$",
"context",
"->",
"entity",
... | Renders the fields part for _update_ queries.
Will only include fields if they have been updated in the entity of the context. Also
handles correct incremented/decremented fields.
@see lithium\data\Entity::increment()
@see lithium\data\source\Database::_fieldsReturn()
@param array $data
@param array $schema An array ... | [
"Renders",
"the",
"fields",
"part",
"for",
"_update_",
"queries",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1269-L1299 |
UnionOfRAD/lithium | data/source/Database.php | Database.joins | public function joins(array $joins, $context) {
$result = null;
foreach ($joins as $key => $join) {
if ($result) {
$result .= ' ';
}
$join = is_array($join) ? $this->_instance('query', $join) : $join;
$options['keys'] = ['mode', 'source', 'alias', 'constraints'];
$result .= $this->renderCommand(... | php | public function joins(array $joins, $context) {
$result = null;
foreach ($joins as $key => $join) {
if ($result) {
$result .= ' ';
}
$join = is_array($join) ? $this->_instance('query', $join) : $join;
$options['keys'] = ['mode', 'source', 'alias', 'constraints'];
$result .= $this->renderCommand(... | [
"public",
"function",
"joins",
"(",
"array",
"$",
"joins",
",",
"$",
"context",
")",
"{",
"$",
"result",
"=",
"null",
";",
"foreach",
"(",
"$",
"joins",
"as",
"$",
"key",
"=>",
"$",
"join",
")",
"{",
"if",
"(",
"$",
"result",
")",
"{",
"$",
"re... | Returns a join statement for given array of query objects
@param object|array $joins A single or array of `lithium\data\model\Query` objects
@param \lithium\data\model\Query $context
@return string | [
"Returns",
"a",
"join",
"statement",
"for",
"given",
"array",
"of",
"query",
"objects"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1325-L1337 |
UnionOfRAD/lithium | data/source/Database.php | Database.constraints | public function constraints($constraints, $context, array $options = []) {
$defaults = ['prepend' => 'ON'];
$options += $defaults;
if (is_array($constraints)) {
$constraints = $this->_constraints($constraints);
}
return $this->_conditions($constraints, $context, $options);
} | php | public function constraints($constraints, $context, array $options = []) {
$defaults = ['prepend' => 'ON'];
$options += $defaults;
if (is_array($constraints)) {
$constraints = $this->_constraints($constraints);
}
return $this->_conditions($constraints, $context, $options);
} | [
"public",
"function",
"constraints",
"(",
"$",
"constraints",
",",
"$",
"context",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'prepend'",
"=>",
"'ON'",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"if"... | Returns a string of formatted constraints to be inserted into the query statement.
If the query constraints are defined as an array, key pairs are converted to SQL
strings. If `$key` is numeric and `$value` is a string, `$value` is treated as a literal
SQL fragment and returned.
@param string|array $constraints The c... | [
"Returns",
"a",
"string",
"of",
"formatted",
"constraints",
"to",
"be",
"inserted",
"into",
"the",
"query",
"statement",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1353-L1361 |
UnionOfRAD/lithium | data/source/Database.php | Database._constraints | protected function _constraints(array $constraints) {
foreach ($constraints as &$value) {
if (is_string($value)) {
$value = (object) $this->name($value);
} elseif (is_array($value)) {
$value = $this->_constraints($value);
}
}
return $constraints;
} | php | protected function _constraints(array $constraints) {
foreach ($constraints as &$value) {
if (is_string($value)) {
$value = (object) $this->name($value);
} elseif (is_array($value)) {
$value = $this->_constraints($value);
}
}
return $constraints;
} | [
"protected",
"function",
"_constraints",
"(",
"array",
"$",
"constraints",
")",
"{",
"foreach",
"(",
"$",
"constraints",
"as",
"&",
"$",
"value",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"(",
"object",
")... | Auto escape string value to a field name value
@param array $constraints The constraints array
@return array The escaped constraints array | [
"Auto",
"escape",
"string",
"value",
"to",
"a",
"field",
"name",
"value"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1369-L1378 |
UnionOfRAD/lithium | data/source/Database.php | Database.order | public function order($order, $context) {
if (!$order) {
return null;
}
$model = $context->model();
$alias = $context->alias();
$normalized = [];
if (is_string($order)) {
if (preg_match('/^(.*?)\s+((?:A|DE)SC)$/i', $order, $match)) {
$normalized[$match[1]] = strtoupper($match[2]);
} else {
... | php | public function order($order, $context) {
if (!$order) {
return null;
}
$model = $context->model();
$alias = $context->alias();
$normalized = [];
if (is_string($order)) {
if (preg_match('/^(.*?)\s+((?:A|DE)SC)$/i', $order, $match)) {
$normalized[$match[1]] = strtoupper($match[2]);
} else {
... | [
"public",
"function",
"order",
"(",
"$",
"order",
",",
"$",
"context",
")",
"{",
"if",
"(",
"!",
"$",
"order",
")",
"{",
"return",
"null",
";",
"}",
"$",
"model",
"=",
"$",
"context",
"->",
"model",
"(",
")",
";",
"$",
"alias",
"=",
"$",
"conte... | Return formatted clause for `ORDER BY` with known fields escaped and
directions normalized to uppercase. When order direction is missing or
unrecognized defaults to `ASC`.
@param string|array $order The clause to be formatted.
@param object $context
@return string|null Formatted clause, `null` if there is nothing to f... | [
"Return",
"formatted",
"clause",
"for",
"ORDER",
"BY",
"with",
"known",
"fields",
"escaped",
"and",
"directions",
"normalized",
"to",
"uppercase",
".",
"When",
"order",
"direction",
"is",
"missing",
"or",
"unrecognized",
"defaults",
"to",
"ASC",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1389-L1426 |
UnionOfRAD/lithium | data/source/Database.php | Database.group | public function group($group, $context) {
if (!$group) {
return null;
}
$self = $this;
$model = $context->model();
$alias = $context->alias();
$escaped = array_map(function($field) use ($self, $model, $alias) {
if (!$model || !$model::schema($field)) {
return $self->name($field);
}
return $... | php | public function group($group, $context) {
if (!$group) {
return null;
}
$self = $this;
$model = $context->model();
$alias = $context->alias();
$escaped = array_map(function($field) use ($self, $model, $alias) {
if (!$model || !$model::schema($field)) {
return $self->name($field);
}
return $... | [
"public",
"function",
"group",
"(",
"$",
"group",
",",
"$",
"context",
")",
"{",
"if",
"(",
"!",
"$",
"group",
")",
"{",
"return",
"null",
";",
"}",
"$",
"self",
"=",
"$",
"this",
";",
"$",
"model",
"=",
"$",
"context",
"->",
"model",
"(",
")",... | Return formatted clause for `GROUP BY` with known fields escaped.
@param string|array $group The clause to be formatted.
@param object $context
@return string|null Formatted clause, `null` if there is nothing to format. | [
"Return",
"formatted",
"clause",
"for",
"GROUP",
"BY",
"with",
"known",
"fields",
"escaped",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1435-L1451 |
UnionOfRAD/lithium | data/source/Database.php | Database._operator | protected function _operator($key, $value, array $schema = [], array $options = []) {
$defaults = ['boolean' => 'AND'];
$options += $defaults;
$op = strtoupper(key($value));
$value = current($value);
$config = $this->_operators[$op];
$key = $this->name($key);
$values = [];
if (!is_object($value)) {
... | php | protected function _operator($key, $value, array $schema = [], array $options = []) {
$defaults = ['boolean' => 'AND'];
$options += $defaults;
$op = strtoupper(key($value));
$value = current($value);
$config = $this->_operators[$op];
$key = $this->name($key);
$values = [];
if (!is_object($value)) {
... | [
"protected",
"function",
"_operator",
"(",
"$",
"key",
",",
"$",
"value",
",",
"array",
"$",
"schema",
"=",
"[",
"]",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'boolean'",
"=>",
"'AND'",
"]",
";",
"$",
"op... | Handles conversion of SQL operator keys to SQL statements.
@param string $key Key in a conditions array. Usually a field name.
@param mixed $value An SQL operator or comparison value.
@param array $schema An array defining the schema of the field used in the criteria.
@param array $options
@return string Returns an SQ... | [
"Handles",
"conversion",
"of",
"SQL",
"operator",
"keys",
"to",
"SQL",
"statements",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1483-L1522 |
UnionOfRAD/lithium | data/source/Database.php | Database._entityName | protected function _entityName($entity, array $options = []) {
$defaults = ['quoted' => false];
$options += $defaults;
if (class_exists($entity, false) && method_exists($entity, 'meta')) {
$entity = $entity::meta('source');
}
return $options['quoted'] ? $this->name($entity) : $entity;
} | php | protected function _entityName($entity, array $options = []) {
$defaults = ['quoted' => false];
$options += $defaults;
if (class_exists($entity, false) && method_exists($entity, 'meta')) {
$entity = $entity::meta('source');
}
return $options['quoted'] ? $this->name($entity) : $entity;
} | [
"protected",
"function",
"_entityName",
"(",
"$",
"entity",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'quoted'",
"=>",
"false",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"if",
"(",
"class_exists",
... | Returns a fully-qualified table name (i.e. with prefix), quoted.
@param string $entity A table name or fully-namespaced model class name.
@param array $options Available options:
- `'quoted'` _boolean_: Indicates whether the name should be quoted.
@return string Returns a quoted table name. | [
"Returns",
"a",
"fully",
"-",
"qualified",
"table",
"name",
"(",
"i",
".",
"e",
".",
"with",
"prefix",
")",
"quoted",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1532-L1540 |
UnionOfRAD/lithium | data/source/Database.php | Database._introspectType | protected function _introspectType($value) {
switch (true) {
case (is_bool($value)):
return 'boolean';
case (is_float($value) || preg_match('/^\d+\.\d+$/', $value)):
return 'float';
case (is_int($value) || preg_match('/^\d+$/', $value)):
return 'integer';
case (is_string($value) && strlen($val... | php | protected function _introspectType($value) {
switch (true) {
case (is_bool($value)):
return 'boolean';
case (is_float($value) || preg_match('/^\d+\.\d+$/', $value)):
return 'float';
case (is_int($value) || preg_match('/^\d+$/', $value)):
return 'integer';
case (is_string($value) && strlen($val... | [
"protected",
"function",
"_introspectType",
"(",
"$",
"value",
")",
"{",
"switch",
"(",
"true",
")",
"{",
"case",
"(",
"is_bool",
"(",
"$",
"value",
")",
")",
":",
"return",
"'boolean'",
";",
"case",
"(",
"is_float",
"(",
"$",
"value",
")",
"||",
"pr... | Attempts to automatically determine the column type of a value. Used by the `value()` method
of various database adapters to determine how to prepare a value if the schema is not
specified.
@param mixed $value The value to be prepared for an SQL query.
@return string Returns the name of the column type which `$value` ... | [
"Attempts",
"to",
"automatically",
"determine",
"the",
"column",
"type",
"of",
"a",
"value",
".",
"Used",
"by",
"the",
"value",
"()",
"method",
"of",
"various",
"database",
"adapters",
"to",
"determine",
"how",
"to",
"prepare",
"a",
"value",
"if",
"the",
"... | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1550-L1563 |
UnionOfRAD/lithium | data/source/Database.php | Database._toBoolean | protected function _toBoolean($value) {
if (is_bool($value)) {
return $value;
}
if (is_int($value) || is_float($value)) {
return ($value !== 0);
}
if (is_string($value)) {
return ($value === 't' || $value === 'T' || $value === 'true');
}
return (boolean) $value;
} | php | protected function _toBoolean($value) {
if (is_bool($value)) {
return $value;
}
if (is_int($value) || is_float($value)) {
return ($value !== 0);
}
if (is_string($value)) {
return ($value === 't' || $value === 'T' || $value === 'true');
}
return (boolean) $value;
} | [
"protected",
"function",
"_toBoolean",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"if",
"(",
"is_int",
"(",
"$",
"value",
")",
"||",
"is_float",
"(",
"$",
"value",
")",
"... | Casts a value which is being written or compared to a boolean-type database column.
@param mixed $value A value of unknown type to be cast to boolean. Numeric values not equal
to zero evaluate to `true`, otherwise `false`. String values equal to `'true'`,
`'t'` or `'T'` evaluate to `true`, all others to `false`. In al... | [
"Casts",
"a",
"value",
"which",
"is",
"being",
"written",
"or",
"compared",
"to",
"a",
"boolean",
"-",
"type",
"database",
"column",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1576-L1587 |
UnionOfRAD/lithium | data/source/Database.php | Database._error | protected function _error($sql){
$params = compact('sql');
return Filters::run($this, __FUNCTION__, $params, function($params) {
list($code, $error) = $this->error();
throw new QueryException("{$params['sql']}: {$error}", $code);
});
} | php | protected function _error($sql){
$params = compact('sql');
return Filters::run($this, __FUNCTION__, $params, function($params) {
list($code, $error) = $this->error();
throw new QueryException("{$params['sql']}: {$error}", $code);
});
} | [
"protected",
"function",
"_error",
"(",
"$",
"sql",
")",
"{",
"$",
"params",
"=",
"compact",
"(",
"'sql'",
")",
";",
"return",
"Filters",
"::",
"run",
"(",
"$",
"this",
",",
"__FUNCTION__",
",",
"$",
"params",
",",
"function",
"(",
"$",
"params",
")"... | Throw a `QueryException` error
@param string $sql The offending SQL string
@filter | [
"Throw",
"a",
"QueryException",
"error"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1595-L1602 |
UnionOfRAD/lithium | data/source/Database.php | Database.applyStrategy | public function applyStrategy($options, $context) {
if ($context->type() !== 'read') {
return;
}
$options += ['strategy' => 'joined'];
if (!$model = $context->model()) {
throw new ConfigException('The `\'with\'` option need a valid `\'model\'` option.');
}
$strategy = $options['strategy'];
if (iss... | php | public function applyStrategy($options, $context) {
if ($context->type() !== 'read') {
return;
}
$options += ['strategy' => 'joined'];
if (!$model = $context->model()) {
throw new ConfigException('The `\'with\'` option need a valid `\'model\'` option.');
}
$strategy = $options['strategy'];
if (iss... | [
"public",
"function",
"applyStrategy",
"(",
"$",
"options",
",",
"$",
"context",
")",
"{",
"if",
"(",
"$",
"context",
"->",
"type",
"(",
")",
"!==",
"'read'",
")",
"{",
"return",
";",
"}",
"$",
"options",
"+=",
"[",
"'strategy'",
"=>",
"'joined'",
"]... | Applying a strategy to a `lithium\data\model\Query` object
@param array $options The option array
@param object $context A find query object to configure | [
"Applying",
"a",
"strategy",
"to",
"a",
"lithium",
"\\",
"data",
"\\",
"model",
"\\",
"Query",
"object"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1610-L1627 |
UnionOfRAD/lithium | data/source/Database.php | Database.join | public function join($context, $rel, $fromAlias = null, $toAlias = null, $constraints = []) {
$model = $rel->to();
if ($fromAlias === null) {
$fromAlias = $context->alias();
}
if ($toAlias === null) {
$toAlias = $context->alias(null, $rel->name());
}
if (!is_object($constraints)) {
$constraints = ... | php | public function join($context, $rel, $fromAlias = null, $toAlias = null, $constraints = []) {
$model = $rel->to();
if ($fromAlias === null) {
$fromAlias = $context->alias();
}
if ($toAlias === null) {
$toAlias = $context->alias(null, $rel->name());
}
if (!is_object($constraints)) {
$constraints = ... | [
"public",
"function",
"join",
"(",
"$",
"context",
",",
"$",
"rel",
",",
"$",
"fromAlias",
"=",
"null",
",",
"$",
"toAlias",
"=",
"null",
",",
"$",
"constraints",
"=",
"[",
"]",
")",
"{",
"$",
"model",
"=",
"$",
"rel",
"->",
"to",
"(",
")",
";"... | Set a query's join according a Relationship.
@param object $context A Query instance
@param object $rel A Relationship instance
@param string $fromAlias Set a specific alias for the `'from'` `Model`.
@param string $toAlias Set a specific alias for `'to'` `Model`.
@param mixed $constraints If `$constraints` is an array... | [
"Set",
"a",
"query",
"s",
"join",
"according",
"a",
"Relationship",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1639-L1658 |
UnionOfRAD/lithium | data/source/Database.php | Database._aliasing | protected function _aliasing($name, $alias, $map = []) {
list($first, $second) = $this->_splitFieldname($name);
if (!$first && preg_match('/^[a-z0-9_-]+$/i', $second)) {
return $alias . "." . $second;
} elseif (isset($map[$first])) {
return $map[$first] . "." . $second;
}
return $name;
} | php | protected function _aliasing($name, $alias, $map = []) {
list($first, $second) = $this->_splitFieldname($name);
if (!$first && preg_match('/^[a-z0-9_-]+$/i', $second)) {
return $alias . "." . $second;
} elseif (isset($map[$first])) {
return $map[$first] . "." . $second;
}
return $name;
} | [
"protected",
"function",
"_aliasing",
"(",
"$",
"name",
",",
"$",
"alias",
",",
"$",
"map",
"=",
"[",
"]",
")",
"{",
"list",
"(",
"$",
"first",
",",
"$",
"second",
")",
"=",
"$",
"this",
"->",
"_splitFieldname",
"(",
"$",
"name",
")",
";",
"if",
... | Helper which add an alias basename to a field name if necessary
@param string $name The field name.
@param string $alias The alias name
@param array $map An array of `'modelname' => 'aliasname'` mapping
@return string | [
"Helper",
"which",
"add",
"an",
"alias",
"basename",
"to",
"a",
"field",
"name",
"if",
"necessary"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1668-L1676 |
UnionOfRAD/lithium | data/source/Database.php | Database.on | public function on($rel, $aliasFrom = null, $aliasTo = null, $constraints = []) {
$model = $rel->from();
$aliasFrom = $aliasFrom ?: $model::meta('name');
$aliasTo = $aliasTo ?: $rel->name();
$keyConstraints = [];
foreach ($rel->key() as $from => $to) {
$keyConstraints["{$aliasFrom}.{$from}"] = "{$aliasTo... | php | public function on($rel, $aliasFrom = null, $aliasTo = null, $constraints = []) {
$model = $rel->from();
$aliasFrom = $aliasFrom ?: $model::meta('name');
$aliasTo = $aliasTo ?: $rel->name();
$keyConstraints = [];
foreach ($rel->key() as $from => $to) {
$keyConstraints["{$aliasFrom}.{$from}"] = "{$aliasTo... | [
"public",
"function",
"on",
"(",
"$",
"rel",
",",
"$",
"aliasFrom",
"=",
"null",
",",
"$",
"aliasTo",
"=",
"null",
",",
"$",
"constraints",
"=",
"[",
"]",
")",
"{",
"$",
"model",
"=",
"$",
"rel",
"->",
"from",
"(",
")",
";",
"$",
"aliasFrom",
"... | Build the `ON` constraints from a `Relationship` instance
@param object $rel A Relationship instance
@param string $fromAlias Set a specific alias for the `'from'` `Model`.
@param string $toAlias Set a specific alias for `'to'` `Model`.
@param array $constraints Array of additionnal $constraints.
@return array A const... | [
"Build",
"the",
"ON",
"constraints",
"from",
"a",
"Relationship",
"instance"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1687-L1704 |
UnionOfRAD/lithium | data/source/Database.php | Database._meta | protected function _meta($type, $name, $value) {
$meta = isset($this->_metas[$type][$name]) ? $this->_metas[$type][$name] : null;
if (!$meta || (isset($meta['options']) && !in_array($value, $meta['options']))) {
return;
}
$meta += ['keyword' => '', 'escape' => false, 'join' => ' '];
if ($meta['escape'] =... | php | protected function _meta($type, $name, $value) {
$meta = isset($this->_metas[$type][$name]) ? $this->_metas[$type][$name] : null;
if (!$meta || (isset($meta['options']) && !in_array($value, $meta['options']))) {
return;
}
$meta += ['keyword' => '', 'escape' => false, 'join' => ' '];
if ($meta['escape'] =... | [
"protected",
"function",
"_meta",
"(",
"$",
"type",
",",
"$",
"name",
",",
"$",
"value",
")",
"{",
"$",
"meta",
"=",
"isset",
"(",
"$",
"this",
"->",
"_metas",
"[",
"$",
"type",
"]",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"this",
"->",
"_metas",... | Build a SQL column/table meta.
@param string $type The type of the meta to build (possible values: `'table'` or `'column'`).
@param string $name The name of the meta to build.
@param mixed $value The value used for building the meta.
@return string The SQL meta string. | [
"Build",
"a",
"SQL",
"column",
"/",
"table",
"meta",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1736-L1748 |
UnionOfRAD/lithium | data/source/Database.php | Database._constraint | protected function _constraint($name, $value, $schema = null) {
$value += ['options' => []];
$meta = isset($this->_constraints[$name]) ? $this->_constraints[$name] : null;
$template = isset($meta['template']) ? $meta['template'] : null;
if (!$template) {
return;
}
$data = [];
foreach ($value as $name ... | php | protected function _constraint($name, $value, $schema = null) {
$value += ['options' => []];
$meta = isset($this->_constraints[$name]) ? $this->_constraints[$name] : null;
$template = isset($meta['template']) ? $meta['template'] : null;
if (!$template) {
return;
}
$data = [];
foreach ($value as $name ... | [
"protected",
"function",
"_constraint",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"schema",
"=",
"null",
")",
"{",
"$",
"value",
"+=",
"[",
"'options'",
"=>",
"[",
"]",
"]",
";",
"$",
"meta",
"=",
"isset",
"(",
"$",
"this",
"->",
"_constraints... | Build a SQL column constraint
@param string $name The name of the meta to build
@param mixed $value The value used for building the meta
@param object $schema A `Schema` instance.
@return string The SQL meta string | [
"Build",
"a",
"SQL",
"column",
"constraint"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1758-L1804 |
UnionOfRAD/lithium | data/source/Database.php | Database.createSchema | public function createSchema($source, $schema) {
if (!$schema instanceof $this->_classes['schema']) {
throw new InvalidArgumentException("Passed schema is not a valid `{$class}` instance.");
}
$columns = [];
$primary = null;
$source = $this->name($source);
foreach ($schema->fields() as $name => $field... | php | public function createSchema($source, $schema) {
if (!$schema instanceof $this->_classes['schema']) {
throw new InvalidArgumentException("Passed schema is not a valid `{$class}` instance.");
}
$columns = [];
$primary = null;
$source = $this->name($source);
foreach ($schema->fields() as $name => $field... | [
"public",
"function",
"createSchema",
"(",
"$",
"source",
",",
"$",
"schema",
")",
"{",
"if",
"(",
"!",
"$",
"schema",
"instanceof",
"$",
"this",
"->",
"_classes",
"[",
"'schema'",
"]",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Passed s... | Create a database-native schema
@param string $source A table name.
@param object $schema A `Schema` instance.
@return boolean `true` on success, `true` otherwise | [
"Create",
"a",
"database",
"-",
"native",
"schema"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1813-L1839 |
UnionOfRAD/lithium | data/source/Database.php | Database._buildMetas | protected function _buildMetas($type, array $metas, $names = null, $joiner = ' ') {
$result = '';
$names = $names ? (array) $names : array_keys($metas);
foreach ($names as $name) {
$value = isset($metas[$name]) ? $metas[$name] : null;
if ($value && $meta = $this->_meta($type, $name, $value)) {
$result .... | php | protected function _buildMetas($type, array $metas, $names = null, $joiner = ' ') {
$result = '';
$names = $names ? (array) $names : array_keys($metas);
foreach ($names as $name) {
$value = isset($metas[$name]) ? $metas[$name] : null;
if ($value && $meta = $this->_meta($type, $name, $value)) {
$result .... | [
"protected",
"function",
"_buildMetas",
"(",
"$",
"type",
",",
"array",
"$",
"metas",
",",
"$",
"names",
"=",
"null",
",",
"$",
"joiner",
"=",
"' '",
")",
"{",
"$",
"result",
"=",
"''",
";",
"$",
"names",
"=",
"$",
"names",
"?",
"(",
"array",
")"... | Helper for building columns metas
@see lithium\data\soure\Database::createSchema()
@see lithium\data\soure\Database::column()
@param array $metas The array of column metas.
@param array $names If `$names` is not `null` only build meta present in `$names`
@param type $joiner The join character
@return string The SQL co... | [
"Helper",
"for",
"building",
"columns",
"metas"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1851-L1861 |
UnionOfRAD/lithium | data/source/Database.php | Database._buildConstraints | protected function _buildConstraints(array $constraints, $schema = null, $joiner = ' ', $primary = false) {
$result = '';
foreach ($constraints as $constraint) {
if (isset($constraint['type'])) {
$name = $constraint['type'];
if ($meta = $this->_constraint($name, $constraint, $schema)) {
$result .= $... | php | protected function _buildConstraints(array $constraints, $schema = null, $joiner = ' ', $primary = false) {
$result = '';
foreach ($constraints as $constraint) {
if (isset($constraint['type'])) {
$name = $constraint['type'];
if ($meta = $this->_constraint($name, $constraint, $schema)) {
$result .= $... | [
"protected",
"function",
"_buildConstraints",
"(",
"array",
"$",
"constraints",
",",
"$",
"schema",
"=",
"null",
",",
"$",
"joiner",
"=",
"' '",
",",
"$",
"primary",
"=",
"false",
")",
"{",
"$",
"result",
"=",
"''",
";",
"foreach",
"(",
"$",
"constrain... | Helper for building columns constraints
@see lithium\data\soure\Database::createSchema()
@param array $constraints The array of constraints
@param type $schema The schema of the table
@param type $joiner The join character
@return string The SQL constraints | [
"Helper",
"for",
"building",
"columns",
"constraints"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1872-L1889 |
UnionOfRAD/lithium | data/source/Database.php | Database.dropSchema | public function dropSchema($source, $soft = true) {
if ($source) {
$source = $this->name($source);
$exists = $soft ? 'IF EXISTS ' : '';
return $this->_execute($this->renderCommand('drop', compact('exists', 'source')));
}
return false;
} | php | public function dropSchema($source, $soft = true) {
if ($source) {
$source = $this->name($source);
$exists = $soft ? 'IF EXISTS ' : '';
return $this->_execute($this->renderCommand('drop', compact('exists', 'source')));
}
return false;
} | [
"public",
"function",
"dropSchema",
"(",
"$",
"source",
",",
"$",
"soft",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"source",
")",
"{",
"$",
"source",
"=",
"$",
"this",
"->",
"name",
"(",
"$",
"source",
")",
";",
"$",
"exists",
"=",
"$",
"soft",
"... | Drops a table.
@param string $source The table name to drop.
@param boolean $soft With "soft dropping", the function will retrun `true` even if the
table doesn't exists.
@return boolean `true` on success, `false` otherwise | [
"Drops",
"a",
"table",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1899-L1906 |
UnionOfRAD/lithium | data/source/Database.php | Database.column | public function column($field) {
if (!isset($field['type'])) {
$field['type'] = 'string';
}
if (!isset($field['name'])) {
throw new InvalidArgumentException("Column name not defined.");
}
if (!isset($this->_columns[$field['type']])) {
throw new UnexpectedValueException("Column type `{$field['type']}`... | php | public function column($field) {
if (!isset($field['type'])) {
$field['type'] = 'string';
}
if (!isset($field['name'])) {
throw new InvalidArgumentException("Column name not defined.");
}
if (!isset($this->_columns[$field['type']])) {
throw new UnexpectedValueException("Column type `{$field['type']}`... | [
"public",
"function",
"column",
"(",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"field",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"field",
"[",
"'type'",
"]",
"=",
"'string'",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"field",... | Generate a database-native column schema string
@param array $column A field array structured like the following:
`array('name' => 'value', 'type' => 'value' [, options])`, where options can
be `'default'`, `'null'`, `'length'` or `'precision'`.
@return string SQL string | [
"Generate",
"a",
"database",
"-",
"native",
"column",
"schema",
"string"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/Database.php#L1916-L1942 |
UnionOfRAD/lithium | data/source/MongoDb.php | MongoDb._init | protected function _init() {
$hosts = [];
foreach ((array) $this->_config['host'] as $host) {
$host = HostString::parse($host) + [
'host' => static::DEFAULT_HOST,
'port' => static::DEFAULT_PORT
];
$hosts[] = "{$host['host']}:{$host['port']}";
}
if ($this->_config['login']) {
$this->_config['... | php | protected function _init() {
$hosts = [];
foreach ((array) $this->_config['host'] as $host) {
$host = HostString::parse($host) + [
'host' => static::DEFAULT_HOST,
'port' => static::DEFAULT_PORT
];
$hosts[] = "{$host['host']}:{$host['port']}";
}
if ($this->_config['login']) {
$this->_config['... | [
"protected",
"function",
"_init",
"(",
")",
"{",
"$",
"hosts",
"=",
"[",
"]",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"_config",
"[",
"'host'",
"]",
"as",
"$",
"host",
")",
"{",
"$",
"host",
"=",
"HostString",
"::",
"parse",
"(... | Initializer. Adds operator handlers which will later allow to correctly cast any
values. Constructs a DSN from configuration.
@see lithium\data\source\MongoDb::$_operators
@see lithium\data\source\MongoDb::_operators()
@return void | [
"Initializer",
".",
"Adds",
"operator",
"handlers",
"which",
"will",
"later",
"allow",
"to",
"correctly",
"cast",
"any",
"values",
".",
"Constructs",
"a",
"DSN",
"from",
"configuration",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/MongoDb.php#L272-L333 |
UnionOfRAD/lithium | data/source/MongoDb.php | MongoDb.connect | public function connect() {
$server = $this->_classes['server'];
if ($this->server && $this->server->getConnections() && $this->connection) {
return $this->_isConnected = true;
}
$this->_isConnected = false;
$options = [
'connect' => true,
'connectTimeoutMS' => $this->_config['timeout'],
'replic... | php | public function connect() {
$server = $this->_classes['server'];
if ($this->server && $this->server->getConnections() && $this->connection) {
return $this->_isConnected = true;
}
$this->_isConnected = false;
$options = [
'connect' => true,
'connectTimeoutMS' => $this->_config['timeout'],
'replic... | [
"public",
"function",
"connect",
"(",
")",
"{",
"$",
"server",
"=",
"$",
"this",
"->",
"_classes",
"[",
"'server'",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"server",
"&&",
"$",
"this",
"->",
"server",
"->",
"getConnections",
"(",
")",
"&&",
"$",
"t... | Connects to the Mongo server. Matches up parameters from the constructor to create a Mongo
database connection.
@see lithium\data\source\MongoDb::__construct()
@link http://php.net/mongo.construct.php PHP Manual: Mongo::__construct()
@return boolean Returns `true` the connection attempt was successful, otherwise `fals... | [
"Connects",
"to",
"the",
"Mongo",
"server",
".",
"Matches",
"up",
"parameters",
"from",
"the",
"constructor",
"to",
"create",
"a",
"Mongo",
"database",
"connection",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/MongoDb.php#L373-L402 |
UnionOfRAD/lithium | data/source/MongoDb.php | MongoDb.disconnect | public function disconnect() {
if ($this->server && $this->server->getConnections()) {
$this->_isConnected = false;
unset($this->connection, $this->server);
}
return true;
} | php | public function disconnect() {
if ($this->server && $this->server->getConnections()) {
$this->_isConnected = false;
unset($this->connection, $this->server);
}
return true;
} | [
"public",
"function",
"disconnect",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"server",
"&&",
"$",
"this",
"->",
"server",
"->",
"getConnections",
"(",
")",
")",
"{",
"$",
"this",
"->",
"_isConnected",
"=",
"false",
";",
"unset",
"(",
"$",
"this",... | Disconnect from the Mongo server.
Don't call the Mongo->close() method. The driver documentation states this should not
be necessary since it auto disconnects when out of scope.
With version 1.2.7, when using replica sets, close() can cause a segmentation fault.
@return boolean True | [
"Disconnect",
"from",
"the",
"Mongo",
"server",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/MongoDb.php#L413-L419 |
UnionOfRAD/lithium | data/source/MongoDb.php | MongoDb.sources | public function sources($class = null) {
$this->_checkConnection();
$conn = $this->connection;
return array_map(function($col) { return $col->getName(); }, $conn->listCollections());
} | php | public function sources($class = null) {
$this->_checkConnection();
$conn = $this->connection;
return array_map(function($col) { return $col->getName(); }, $conn->listCollections());
} | [
"public",
"function",
"sources",
"(",
"$",
"class",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"_checkConnection",
"(",
")",
";",
"$",
"conn",
"=",
"$",
"this",
"->",
"connection",
";",
"return",
"array_map",
"(",
"function",
"(",
"$",
"col",
")",
"{"... | Returns the list of collections in the currently-connected database.
@param string $class The fully-name-spaced class name of the model object making the request.
@return array Returns an array of objects to which models can connect. | [
"Returns",
"the",
"list",
"of",
"collections",
"in",
"the",
"currently",
"-",
"connected",
"database",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/MongoDb.php#L427-L431 |
UnionOfRAD/lithium | data/source/MongoDb.php | MongoDb.describe | public function describe($collection, $fields = [], array $meta = []) {
if (!$fields && ($func = $this->_schema)) {
$fields = $func($this, $collection, $meta);
}
return $this->_instance('schema', compact('fields'));
} | php | public function describe($collection, $fields = [], array $meta = []) {
if (!$fields && ($func = $this->_schema)) {
$fields = $func($this, $collection, $meta);
}
return $this->_instance('schema', compact('fields'));
} | [
"public",
"function",
"describe",
"(",
"$",
"collection",
",",
"$",
"fields",
"=",
"[",
"]",
",",
"array",
"$",
"meta",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"fields",
"&&",
"(",
"$",
"func",
"=",
"$",
"this",
"->",
"_schema",
")",
")",... | Gets the column 'schema' for a given MongoDB collection. Only returns a schema if the
`'schema'` configuration flag has been set in the constructor.
@see lithium\data\source\MongoDb::$_schema
@param mixed $collection Specifies a collection name for which the schema should be queried.
@param mixed $fields Any schema da... | [
"Gets",
"the",
"column",
"schema",
"for",
"a",
"given",
"MongoDB",
"collection",
".",
"Only",
"returns",
"a",
"schema",
"if",
"the",
"schema",
"configuration",
"flag",
"has",
"been",
"set",
"in",
"the",
"constructor",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/MongoDb.php#L443-L448 |
UnionOfRAD/lithium | data/source/MongoDb.php | MongoDb.respondsTo | public function respondsTo($method, $internal = false) {
$childRespondsTo = is_object($this->server) && is_callable([$this->server, $method]);
return parent::respondsTo($method, $internal) || $childRespondsTo;
} | php | public function respondsTo($method, $internal = false) {
$childRespondsTo = is_object($this->server) && is_callable([$this->server, $method]);
return parent::respondsTo($method, $internal) || $childRespondsTo;
} | [
"public",
"function",
"respondsTo",
"(",
"$",
"method",
",",
"$",
"internal",
"=",
"false",
")",
"{",
"$",
"childRespondsTo",
"=",
"is_object",
"(",
"$",
"this",
"->",
"server",
")",
"&&",
"is_callable",
"(",
"[",
"$",
"this",
"->",
"server",
",",
"$",... | Determines if a given method can be called.
@param string $method Name of the method.
@param boolean $internal Provide `true` to perform check from inside the
class/object. When `false` checks also for public visibility;
defaults to `false`.
@return boolean Returns `true` if the method can be called, `false` otherwise... | [
"Determines",
"if",
"a",
"given",
"method",
"can",
"be",
"called",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/MongoDb.php#L493-L496 |
UnionOfRAD/lithium | data/source/MongoDb.php | MongoDb.create | public function create($query, array $options = []) {
$this->_checkConnection();
$defaults = [
'w' => $this->_config['w'],
'wTimeoutMS' => $this->_config['wTimeoutMS'],
'fsync' => false
];
$options += $defaults;
$params = compact('query', 'options');
return Filters::run($this, __FUNCTION__, $par... | php | public function create($query, array $options = []) {
$this->_checkConnection();
$defaults = [
'w' => $this->_config['w'],
'wTimeoutMS' => $this->_config['wTimeoutMS'],
'fsync' => false
];
$options += $defaults;
$params = compact('query', 'options');
return Filters::run($this, __FUNCTION__, $par... | [
"public",
"function",
"create",
"(",
"$",
"query",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"_checkConnection",
"(",
")",
";",
"$",
"defaults",
"=",
"[",
"'w'",
"=>",
"$",
"this",
"->",
"_config",
"[",
"'w'",
"]",
... | Create new document
@param string $query
@param array $options
@return boolean
@filter | [
"Create",
"new",
"document"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/MongoDb.php#L520-L559 |
UnionOfRAD/lithium | data/source/MongoDb.php | MongoDb.read | public function read($query, array $options = []) {
$this->_checkConnection();
$defaults = ['return' => 'resource'];
$options += $defaults;
$params = compact('query', 'options');
return Filters::run($this, __FUNCTION__, $params, function($params) {
$prefix = $this->_config['gridPrefix'];
$query = $p... | php | public function read($query, array $options = []) {
$this->_checkConnection();
$defaults = ['return' => 'resource'];
$options += $defaults;
$params = compact('query', 'options');
return Filters::run($this, __FUNCTION__, $params, function($params) {
$prefix = $this->_config['gridPrefix'];
$query = $p... | [
"public",
"function",
"read",
"(",
"$",
"query",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"_checkConnection",
"(",
")",
";",
"$",
"defaults",
"=",
"[",
"'return'",
"=>",
"'resource'",
"]",
";",
"$",
"options",
"+=",
... | Read from document
@param string $query
@param array $options
@return object
@filter | [
"Read",
"from",
"document"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/MongoDb.php#L601-L639 |
UnionOfRAD/lithium | data/source/MongoDb.php | MongoDb.update | public function update($query, array $options = []) {
$this->_checkConnection();
$defaults = [
'upsert' => false,
'multiple' => true,
'w' => $this->_config['w'],
'wTimeoutMS' => $this->_config['wTimeoutMS'],
'fsync' => false
];
$options += $defaults;
$params = compact('query', 'options');
... | php | public function update($query, array $options = []) {
$this->_checkConnection();
$defaults = [
'upsert' => false,
'multiple' => true,
'w' => $this->_config['w'],
'wTimeoutMS' => $this->_config['wTimeoutMS'],
'fsync' => false
];
$options += $defaults;
$params = compact('query', 'options');
... | [
"public",
"function",
"update",
"(",
"$",
"query",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"_checkConnection",
"(",
")",
";",
"$",
"defaults",
"=",
"[",
"'upsert'",
"=>",
"false",
",",
"'multiple'",
"=>",
"true",
","... | Update document
@param string $query
@param array $options
@return boolean
@filter | [
"Update",
"document"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/MongoDb.php#L660-L707 |
UnionOfRAD/lithium | data/source/MongoDb.php | MongoDb.delete | public function delete($query, array $options = []) {
$this->_checkConnection();
$defaults = [
'justOne' => false,
'w' => $this->_config['w'],
'wTimeoutMS' => $this->_config['wTimeoutMS'],
'fsync' => false
];
$options = array_intersect_key($options + $defaults, $defaults);
$params = compact('quer... | php | public function delete($query, array $options = []) {
$this->_checkConnection();
$defaults = [
'justOne' => false,
'w' => $this->_config['w'],
'wTimeoutMS' => $this->_config['wTimeoutMS'],
'fsync' => false
];
$options = array_intersect_key($options + $defaults, $defaults);
$params = compact('quer... | [
"public",
"function",
"delete",
"(",
"$",
"query",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"_checkConnection",
"(",
")",
";",
"$",
"defaults",
"=",
"[",
"'justOne'",
"=>",
"false",
",",
"'w'",
"=>",
"$",
"this",
"-... | Delete document
@param string $query
@param array $options
@return boolean
@filter | [
"Delete",
"document"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/MongoDb.php#L717-L749 |
UnionOfRAD/lithium | data/source/MongoDb.php | MongoDb.calculation | public function calculation($type, $query, array $options = []) {
$query->calculate($type);
switch ($type) {
case 'count':
return $this->read($query, $options)->count();
}
} | php | public function calculation($type, $query, array $options = []) {
$query->calculate($type);
switch ($type) {
case 'count':
return $this->read($query, $options)->count();
}
} | [
"public",
"function",
"calculation",
"(",
"$",
"type",
",",
"$",
"query",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"query",
"->",
"calculate",
"(",
"$",
"type",
")",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'count'",
... | Executes calculation-related queries, such as those required for `count`.
@param string $type Only accepts `count`.
@param mixed $query The query to be executed.
@param array $options Optional arguments for the `read()` query that will be executed
to obtain the calculation result.
@return integer Result of the calcula... | [
"Executes",
"calculation",
"-",
"related",
"queries",
"such",
"as",
"those",
"required",
"for",
"count",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/MongoDb.php#L780-L787 |
UnionOfRAD/lithium | data/source/MongoDb.php | MongoDb.relationship | public function relationship($class, $type, $name, array $config = []) {
$fieldName = $this->relationFieldName($type, $name);
$config += compact('name', 'type', 'key', 'fieldName');
$config['from'] = $class;
return $this->_instance('relationship', $config + [
'strategy' => function($rel) use ($config, $clas... | php | public function relationship($class, $type, $name, array $config = []) {
$fieldName = $this->relationFieldName($type, $name);
$config += compact('name', 'type', 'key', 'fieldName');
$config['from'] = $class;
return $this->_instance('relationship', $config + [
'strategy' => function($rel) use ($config, $clas... | [
"public",
"function",
"relationship",
"(",
"$",
"class",
",",
"$",
"type",
",",
"$",
"name",
",",
"array",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"$",
"fieldName",
"=",
"$",
"this",
"->",
"relationFieldName",
"(",
"$",
"type",
",",
"$",
"name",
")... | Document relationships.
@param string $class
@param string $type Relationship type, e.g. `belongsTo`.
@param string $name
@param array $config
@return array | [
"Document",
"relationships",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/MongoDb.php#L798-L849 |
UnionOfRAD/lithium | data/source/MongoDb.php | MongoDb.group | public function group($group, $context) {
if (!$group) {
return;
}
if (is_string($group) && strpos($group, 'function') === 0) {
return ['$keyf' => new MongoCode($group)];
}
$group = (array) $group;
foreach ($group as $i => $field) {
if (is_int($i)) {
$group[$field] = true;
unset($group[$i]... | php | public function group($group, $context) {
if (!$group) {
return;
}
if (is_string($group) && strpos($group, 'function') === 0) {
return ['$keyf' => new MongoCode($group)];
}
$group = (array) $group;
foreach ($group as $i => $field) {
if (is_int($i)) {
$group[$field] = true;
unset($group[$i]... | [
"public",
"function",
"group",
"(",
"$",
"group",
",",
"$",
"context",
")",
"{",
"if",
"(",
"!",
"$",
"group",
")",
"{",
"return",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"group",
")",
"&&",
"strpos",
"(",
"$",
"group",
",",
"'function'",
")"... | Formats `group` clauses for MongoDB.
@param string|array $group The group clause.
@param object $context
@return array Formatted `group` clause. | [
"Formats",
"group",
"clauses",
"for",
"MongoDB",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/MongoDb.php#L858-L874 |
UnionOfRAD/lithium | data/source/MongoDb.php | MongoDb.conditions | public function conditions($conditions, $context) {
if (!$conditions) {
return [];
}
if ($code = $this->_isMongoCode($conditions)) {
return $code;
}
$schema = null;
$model = null;
if ($context) {
$schema = $context->schema();
$model = $context->model();
}
return $this->_conditions($condit... | php | public function conditions($conditions, $context) {
if (!$conditions) {
return [];
}
if ($code = $this->_isMongoCode($conditions)) {
return $code;
}
$schema = null;
$model = null;
if ($context) {
$schema = $context->schema();
$model = $context->model();
}
return $this->_conditions($condit... | [
"public",
"function",
"conditions",
"(",
"$",
"conditions",
",",
"$",
"context",
")",
"{",
"if",
"(",
"!",
"$",
"conditions",
")",
"{",
"return",
"[",
"]",
";",
"}",
"if",
"(",
"$",
"code",
"=",
"$",
"this",
"->",
"_isMongoCode",
"(",
"$",
"conditi... | Maps incoming conditions with their corresponding MongoDB-native operators.
@param array $conditions Array of conditions
@param object $context Context with which this method was called; currently
inspects the return value of `$context->type()`.
@return array Transformed conditions | [
"Maps",
"incoming",
"conditions",
"with",
"their",
"corresponding",
"MongoDB",
"-",
"native",
"operators",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/MongoDb.php#L884-L899 |
UnionOfRAD/lithium | data/source/MongoDb.php | MongoDb._conditions | protected function _conditions(array $conditions, $model, $schema, $context) {
$ops = $this->_operators;
$castOpts = [
'first' => true, 'database' => $this, 'wrap' => false, 'asContent' => true
];
$cast = function($key, $value) use (&$schema, &$castOpts) {
return $schema ? $schema->cast(null, $key, $valu... | php | protected function _conditions(array $conditions, $model, $schema, $context) {
$ops = $this->_operators;
$castOpts = [
'first' => true, 'database' => $this, 'wrap' => false, 'asContent' => true
];
$cast = function($key, $value) use (&$schema, &$castOpts) {
return $schema ? $schema->cast(null, $key, $valu... | [
"protected",
"function",
"_conditions",
"(",
"array",
"$",
"conditions",
",",
"$",
"model",
",",
"$",
"schema",
",",
"$",
"context",
")",
"{",
"$",
"ops",
"=",
"$",
"this",
"->",
"_operators",
";",
"$",
"castOpts",
"=",
"[",
"'first'",
"=>",
"true",
... | Protected helper method used to format conditions.
@todo Catch Document/Array objects used in conditions and extract their values.
@param array $conditions The conditions array to be processed.
@param string $model The name of the model class used in the query.
@param object $schema The object containing the schema de... | [
"Protected",
"helper",
"method",
"used",
"to",
"format",
"conditions",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/MongoDb.php#L911-L948 |
UnionOfRAD/lithium | data/source/MongoDb.php | MongoDb.order | public function order($order, $context) {
if (!$order) {
return [];
}
if (is_string($order)) {
return [$order => 1];
}
if (!is_array($order)) {
return [];
}
foreach ($order as $key => $value) {
if (!is_string($key)) {
unset($order[$key]);
$order[$value] = 1;
continue;
}
if (i... | php | public function order($order, $context) {
if (!$order) {
return [];
}
if (is_string($order)) {
return [$order => 1];
}
if (!is_array($order)) {
return [];
}
foreach ($order as $key => $value) {
if (!is_string($key)) {
unset($order[$key]);
$order[$value] = 1;
continue;
}
if (i... | [
"public",
"function",
"order",
"(",
"$",
"order",
",",
"$",
"context",
")",
"{",
"if",
"(",
"!",
"$",
"order",
")",
"{",
"return",
"[",
"]",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"order",
")",
")",
"{",
"return",
"[",
"$",
"order",
"=>",
... | Return formatted clause for order.
@param mixed $order The `order` clause to be formatted
@param object $context
@return mixed Formatted `order` clause. | [
"Return",
"formatted",
"clause",
"for",
"order",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/MongoDb.php#L1021-L1042 |
UnionOfRAD/lithium | data/source/MongoDb.php | MongoDb.relationFieldName | public function relationFieldName($type, $name) {
$fieldName = Inflector::camelize($name, false);
if (preg_match('/Many$/', $type)) {
$fieldName = Inflector::pluralize($fieldName);
} else {
$fieldName = Inflector::singularize($fieldName);
}
return $fieldName;
} | php | public function relationFieldName($type, $name) {
$fieldName = Inflector::camelize($name, false);
if (preg_match('/Many$/', $type)) {
$fieldName = Inflector::pluralize($fieldName);
} else {
$fieldName = Inflector::singularize($fieldName);
}
return $fieldName;
} | [
"public",
"function",
"relationFieldName",
"(",
"$",
"type",
",",
"$",
"name",
")",
"{",
"$",
"fieldName",
"=",
"Inflector",
"::",
"camelize",
"(",
"$",
"name",
",",
"false",
")",
";",
"if",
"(",
"preg_match",
"(",
"'/Many$/'",
",",
"$",
"type",
")",
... | Returns the field name of a relation name (camelBack).
@param string The type of the relation.
@param string The name of the relation.
@return string | [
"Returns",
"the",
"field",
"name",
"of",
"a",
"relation",
"name",
"(",
"camelBack",
")",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/MongoDb.php#L1057-L1065 |
UnionOfRAD/lithium | g11n/Locale.php | Locale.respondsTo | public static function respondsTo($method, $internal = false) {
return isset(static::$_tags[$method]) || parent::respondsTo($method, $internal);
} | php | public static function respondsTo($method, $internal = false) {
return isset(static::$_tags[$method]) || parent::respondsTo($method, $internal);
} | [
"public",
"static",
"function",
"respondsTo",
"(",
"$",
"method",
",",
"$",
"internal",
"=",
"false",
")",
"{",
"return",
"isset",
"(",
"static",
"::",
"$",
"_tags",
"[",
"$",
"method",
"]",
")",
"||",
"parent",
"::",
"respondsTo",
"(",
"$",
"method",
... | Determines if a given method can be called.
@param string $method Name of the method.
@param boolean $internal Provide `true` to perform check from inside the
class/object. When `false` checks also for public visibility;
defaults to `false`.
@return boolean Returns `true` if the method can be called, `false` otherwise... | [
"Determines",
"if",
"a",
"given",
"method",
"can",
"be",
"called",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/g11n/Locale.php#L94-L96 |
UnionOfRAD/lithium | g11n/Locale.php | Locale.compose | public static function compose($tags) {
$result = [];
foreach (static::$_tags as $name => $tag) {
if (isset($tags[$name])) {
$result[] = $tags[$name];
}
}
if ($result) {
return implode('_', $result);
}
} | php | public static function compose($tags) {
$result = [];
foreach (static::$_tags as $name => $tag) {
if (isset($tags[$name])) {
$result[] = $tags[$name];
}
}
if ($result) {
return implode('_', $result);
}
} | [
"public",
"static",
"function",
"compose",
"(",
"$",
"tags",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"static",
"::",
"$",
"_tags",
"as",
"$",
"name",
"=>",
"$",
"tag",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"tags",
"[",
"$... | Composes a locale from locale tags. This is the pendant to `Locale::decompose()`.
@param array $tags An array as obtained from `Locale::decompose()`.
@return string A locale with tags separated by underscores or `null`
if none of the passed tags could be used to compose a locale. | [
"Composes",
"a",
"locale",
"from",
"locale",
"tags",
".",
"This",
"is",
"the",
"pendant",
"to",
"Locale",
"::",
"decompose",
"()",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/g11n/Locale.php#L105-L116 |
UnionOfRAD/lithium | g11n/Locale.php | Locale.decompose | public static function decompose($locale) {
$regex = '(?P<language>[a-z]{2,3})';
$regex .= '(?:[_-](?P<script>[a-z]{4}))?';
$regex .= '(?:[_-](?P<territory>[a-z]{2}))?';
$regex .= '(?:[_-](?P<variant>[a-z]{5,}))?';
if (!preg_match("/^{$regex}$/i", $locale, $matches)) {
throw new InvalidArgumentException(... | php | public static function decompose($locale) {
$regex = '(?P<language>[a-z]{2,3})';
$regex .= '(?:[_-](?P<script>[a-z]{4}))?';
$regex .= '(?:[_-](?P<territory>[a-z]{2}))?';
$regex .= '(?:[_-](?P<variant>[a-z]{5,}))?';
if (!preg_match("/^{$regex}$/i", $locale, $matches)) {
throw new InvalidArgumentException(... | [
"public",
"static",
"function",
"decompose",
"(",
"$",
"locale",
")",
"{",
"$",
"regex",
"=",
"'(?P<language>[a-z]{2,3})'",
";",
"$",
"regex",
".=",
"'(?:[_-](?P<script>[a-z]{4}))?'",
";",
"$",
"regex",
".=",
"'(?:[_-](?P<territory>[a-z]{2}))?'",
";",
"$",
"regex",
... | Parses a locale into locale tags. This is the pendant to `Locale::compose()``.
@param string $locale A locale in an arbitrary form (i.e. `'en_US'` or `'EN-US'`).
@return array Parsed language, script, territory and variant tags.
@throws InvalidArgumentException | [
"Parses",
"a",
"locale",
"into",
"locale",
"tags",
".",
"This",
"is",
"the",
"pendant",
"to",
"Locale",
"::",
"compose",
"()",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/g11n/Locale.php#L125-L135 |
UnionOfRAD/lithium | g11n/Locale.php | Locale.canonicalize | public static function canonicalize($locale) {
$tags = static::decompose($locale);
foreach ($tags as $name => &$tag) {
foreach ((array) static::$_tags[$name]['formatter'] as $formatter) {
$tag = $formatter($tag);
}
}
return static::compose($tags);
} | php | public static function canonicalize($locale) {
$tags = static::decompose($locale);
foreach ($tags as $name => &$tag) {
foreach ((array) static::$_tags[$name]['formatter'] as $formatter) {
$tag = $formatter($tag);
}
}
return static::compose($tags);
} | [
"public",
"static",
"function",
"canonicalize",
"(",
"$",
"locale",
")",
"{",
"$",
"tags",
"=",
"static",
"::",
"decompose",
"(",
"$",
"locale",
")",
";",
"foreach",
"(",
"$",
"tags",
"as",
"$",
"name",
"=>",
"&",
"$",
"tag",
")",
"{",
"foreach",
"... | Returns a locale in its canonical form with tags formatted properly.
@param string $locale A locale in an arbitrary form (i.e. `'ZH-HANS-HK_REVISED'`).
@return string A locale in its canonical form (i.e. `'zh_Hans_HK_REVISED'`). | [
"Returns",
"a",
"locale",
"in",
"its",
"canonical",
"form",
"with",
"tags",
"formatted",
"properly",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/g11n/Locale.php#L143-L152 |
UnionOfRAD/lithium | g11n/Locale.php | Locale.cascade | public static function cascade($locale) {
$locales[] = $locale;
if ($locale === 'root') {
return $locales;
}
$tags = static::decompose($locale);
while (count($tags) > 1) {
array_pop($tags);
$locales[] = static::compose($tags);
}
$locales[] = 'root';
return $locales;
} | php | public static function cascade($locale) {
$locales[] = $locale;
if ($locale === 'root') {
return $locales;
}
$tags = static::decompose($locale);
while (count($tags) > 1) {
array_pop($tags);
$locales[] = static::compose($tags);
}
$locales[] = 'root';
return $locales;
} | [
"public",
"static",
"function",
"cascade",
"(",
"$",
"locale",
")",
"{",
"$",
"locales",
"[",
"]",
"=",
"$",
"locale",
";",
"if",
"(",
"$",
"locale",
"===",
"'root'",
")",
"{",
"return",
"$",
"locales",
";",
"}",
"$",
"tags",
"=",
"static",
"::",
... | Cascades a locale.
Usage:
```
Locale::cascade('en_US');
// returns ['en_US', 'en', 'root']
Locale::cascade('zh_Hans_HK_REVISED');
// returns ['zh_Hans_HK_REVISED', 'zh_Hans_HK', 'zh_Hans', 'zh', 'root']
```
@link http://www.unicode.org/reports/tr35/tr35-13.html#Locale_Inheritance
@param string $locale A locale in an... | [
"Cascades",
"a",
"locale",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/g11n/Locale.php#L170-L184 |
UnionOfRAD/lithium | g11n/Locale.php | Locale.lookup | public static function lookup($locales, $locale) {
$tags = static::decompose($locale);
while (($count = count($tags)) > 0) {
if (($key = array_search(static::compose($tags), $locales)) !== false) {
return $locales[$key];
}
if ($count === 1) {
foreach ($locales as $current) {
if (strpos($curre... | php | public static function lookup($locales, $locale) {
$tags = static::decompose($locale);
while (($count = count($tags)) > 0) {
if (($key = array_search(static::compose($tags), $locales)) !== false) {
return $locales[$key];
}
if ($count === 1) {
foreach ($locales as $current) {
if (strpos($curre... | [
"public",
"static",
"function",
"lookup",
"(",
"$",
"locales",
",",
"$",
"locale",
")",
"{",
"$",
"tags",
"=",
"static",
"::",
"decompose",
"(",
"$",
"locale",
")",
";",
"while",
"(",
"(",
"$",
"count",
"=",
"count",
"(",
"$",
"tags",
")",
")",
"... | Searches an array of locales for the best match to a locale. The locale
is iteratively simplified until either it matches one of the locales
in the list or the locale can't be further simplified.
This method partially implements the lookup matching scheme as described
in RFC 4647, section 3.4 and thus does not strictl... | [
"Searches",
"an",
"array",
"of",
"locales",
"for",
"the",
"best",
"match",
"to",
"a",
"locale",
".",
"The",
"locale",
"is",
"iteratively",
"simplified",
"until",
"either",
"it",
"matches",
"one",
"of",
"the",
"locales",
"in",
"the",
"list",
"or",
"the",
... | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/g11n/Locale.php#L206-L225 |
UnionOfRAD/lithium | g11n/Locale.php | Locale.preferred | public static function preferred($request, $available = null) {
if (is_array($request)) {
$result = $request;
} elseif ($request instanceof ActionRequest) {
$result = static::_preferredAction($request);
} elseif ($request instanceof ConsoleRequest) {
$result = static::_preferredConsole($request);
} els... | php | public static function preferred($request, $available = null) {
if (is_array($request)) {
$result = $request;
} elseif ($request instanceof ActionRequest) {
$result = static::_preferredAction($request);
} elseif ($request instanceof ConsoleRequest) {
$result = static::_preferredConsole($request);
} els... | [
"public",
"static",
"function",
"preferred",
"(",
"$",
"request",
",",
"$",
"available",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"request",
")",
")",
"{",
"$",
"result",
"=",
"$",
"request",
";",
"}",
"elseif",
"(",
"$",
"request",
... | Determines the preferred locale from a request or array. Optionally negotiates
the preferred locale with available locales.
@see lithium\g11n\Locale::_preferredAction()
@see lithium\g11n\Locale::_preferredConsole()
@see lithium\g11n\Locale::lookup()
@param object|array $request An action or console request object or a... | [
"Determines",
"the",
"preferred",
"locale",
"from",
"a",
"request",
"or",
"array",
".",
"Optionally",
"negotiates",
"the",
"preferred",
"locale",
"with",
"available",
"locales",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/g11n/Locale.php#L239-L257 |
UnionOfRAD/lithium | g11n/Locale.php | Locale._preferredAction | protected static function _preferredAction($request) {
$result = [];
$regex = "/^\s*(?P<locale>\w\w(?:[-]\w\w)?)(?:;q=(?P<quality>(0|1|0\.\d+)))?\s*$/";
foreach (explode(',', $request->env('HTTP_ACCEPT_LANGUAGE')) as $part) {
if (preg_match($regex, $part, $matches)) {
$locale = static::canonicalize($matc... | php | protected static function _preferredAction($request) {
$result = [];
$regex = "/^\s*(?P<locale>\w\w(?:[-]\w\w)?)(?:;q=(?P<quality>(0|1|0\.\d+)))?\s*$/";
foreach (explode(',', $request->env('HTTP_ACCEPT_LANGUAGE')) as $part) {
if (preg_match($regex, $part, $matches)) {
$locale = static::canonicalize($matc... | [
"protected",
"static",
"function",
"_preferredAction",
"(",
"$",
"request",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"regex",
"=",
"\"/^\\s*(?P<locale>\\w\\w(?:[-]\\w\\w)?)(?:;q=(?P<quality>(0|1|0\\.\\d+)))?\\s*$/\"",
";",
"foreach",
"(",
"explode",
"(",
"','... | Detects preferred locales from an action request by looking at the
`'Accept-Language'` header as described by RFC 2616, section 14.4.
@link http://www.ietf.org/rfc/rfc2616.txt
@param \lithium\action\Request $request
@return array Preferred locales in their canonical form (i.e. `'fr_CA'`). | [
"Detects",
"preferred",
"locales",
"from",
"an",
"action",
"request",
"by",
"looking",
"at",
"the",
"Accept",
"-",
"Language",
"header",
"as",
"described",
"by",
"RFC",
"2616",
"section",
"14",
".",
"4",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/g11n/Locale.php#L267-L283 |
UnionOfRAD/lithium | g11n/Locale.php | Locale._preferredConsole | protected static function _preferredConsole($request) {
$regex = '(?P<locale>[\w\_]+)(\.|@|$)+';
$result = [];
if ($value = $request->env('LANGUAGE')) {
return explode(':', $value);
}
foreach (['LC_ALL', 'LANG'] as $variable) {
$value = $request->env($variable);
if (!$value || $value === 'C' || $va... | php | protected static function _preferredConsole($request) {
$regex = '(?P<locale>[\w\_]+)(\.|@|$)+';
$result = [];
if ($value = $request->env('LANGUAGE')) {
return explode(':', $value);
}
foreach (['LC_ALL', 'LANG'] as $variable) {
$value = $request->env($variable);
if (!$value || $value === 'C' || $va... | [
"protected",
"static",
"function",
"_preferredConsole",
"(",
"$",
"request",
")",
"{",
"$",
"regex",
"=",
"'(?P<locale>[\\w\\_]+)(\\.|@|$)+'",
";",
"$",
"result",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"value",
"=",
"$",
"request",
"->",
"env",
"(",
"'LANGUAG... | Detects preferred locales from a console request by looking at certain
environment variables. The environment variables may be present or not
depending on your system. If multiple variables are present the following
hierarchy is used: `'LANGUAGE'`, `'LC_ALL'`, `'LANG'`.
The locales of the `'LC_ALL'` and the `'LANG'` ... | [
"Detects",
"preferred",
"locales",
"from",
"a",
"console",
"request",
"by",
"looking",
"at",
"certain",
"environment",
"variables",
".",
"The",
"environment",
"variables",
"may",
"be",
"present",
"or",
"not",
"depending",
"on",
"your",
"system",
".",
"If",
"mu... | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/g11n/Locale.php#L300-L318 |
UnionOfRAD/lithium | security/Hash.php | Hash.calculate | public static function calculate($data, array $options = []) {
if (!is_scalar($data)) {
$data = ($data instanceof Closure) ? spl_object_hash($data) : serialize($data);
}
$defaults = [
'type' => 'sha512',
'salt' => false,
'key' => false,
'raw' => false
];
$options += $defaults;
if ($options['... | php | public static function calculate($data, array $options = []) {
if (!is_scalar($data)) {
$data = ($data instanceof Closure) ? spl_object_hash($data) : serialize($data);
}
$defaults = [
'type' => 'sha512',
'salt' => false,
'key' => false,
'raw' => false
];
$options += $defaults;
if ($options['... | [
"public",
"static",
"function",
"calculate",
"(",
"$",
"data",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"(",
"$",
"data",
"instanceof",
"Closure",
")",
... | Uses PHP's hashing functions to calculate a hash over the data provided, using the options
specified. The default hash algorithm is SHA-512.
Examples:
```
// Calculates a secure hash over string `'foo'`.
Hash::calculate('foo');
// It is possible to hash non-scalar data, too.
Hash::calculate(['foo' => 'bar']); ... | [
"Uses",
"PHP",
"s",
"hashing",
"functions",
"to",
"calculate",
"a",
"hash",
"over",
"the",
"data",
"provided",
"using",
"the",
"options",
"specified",
".",
"The",
"default",
"hash",
"algorithm",
"is",
"SHA",
"-",
"512",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/security/Hash.php#L54-L73 |
UnionOfRAD/lithium | security/Hash.php | Hash.compare | public static function compare($known, $user) {
if (function_exists('hash_equals')) {
return hash_equals($known, $user);
}
if (!is_string($known) || !is_string($user)) {
trigger_error('Expected `$known` & `$user` parameters to be strings.', E_USER_WARNING);
return false;
}
if (($length = strlen($kno... | php | public static function compare($known, $user) {
if (function_exists('hash_equals')) {
return hash_equals($known, $user);
}
if (!is_string($known) || !is_string($user)) {
trigger_error('Expected `$known` & `$user` parameters to be strings.', E_USER_WARNING);
return false;
}
if (($length = strlen($kno... | [
"public",
"static",
"function",
"compare",
"(",
"$",
"known",
",",
"$",
"user",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'hash_equals'",
")",
")",
"{",
"return",
"hash_equals",
"(",
"$",
"known",
",",
"$",
"user",
")",
";",
"}",
"if",
"(",
"!",
... | Compares two hashes in constant time to prevent timing attacks.
To successfully mitigate timing attacks and not leak the actual length of the known
hash, it is important that _both provided hash strings have the same length_ and that
the _user-supplied hash string is passed as a second parameter_ rather than first.
... | [
"Compares",
"two",
"hashes",
"in",
"constant",
"time",
"to",
"prevent",
"timing",
"attacks",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/security/Hash.php#L93-L109 |
UnionOfRAD/lithium | util/Text.php | Text.uuid | public static function uuid() {
$uuid = Random::generate(16);
$uuid[6] = chr(ord($uuid[6]) & static::UUID_CLEAR_VER | static::UUID_VERSION_4);
$uuid[8] = chr(ord($uuid[8]) & static::UUID_CLEAR_VAR | static::UUID_VAR_RFC);
return join('-', [
bin2hex(substr($uuid, 0, 4)),
bin2hex(substr($uuid, 4, 2)),
b... | php | public static function uuid() {
$uuid = Random::generate(16);
$uuid[6] = chr(ord($uuid[6]) & static::UUID_CLEAR_VER | static::UUID_VERSION_4);
$uuid[8] = chr(ord($uuid[8]) & static::UUID_CLEAR_VAR | static::UUID_VAR_RFC);
return join('-', [
bin2hex(substr($uuid, 0, 4)),
bin2hex(substr($uuid, 4, 2)),
b... | [
"public",
"static",
"function",
"uuid",
"(",
")",
"{",
"$",
"uuid",
"=",
"Random",
"::",
"generate",
"(",
"16",
")",
";",
"$",
"uuid",
"[",
"6",
"]",
"=",
"chr",
"(",
"ord",
"(",
"$",
"uuid",
"[",
"6",
"]",
")",
"&",
"static",
"::",
"UUID_CLEAR... | Generates an RFC 4122-compliant version 4 UUID.
@return string The string representation of an RFC 4122-compliant, version 4 UUID.
@link http://www.ietf.org/rfc/rfc4122.txt RFC 4122: UUID URN Namespace | [
"Generates",
"an",
"RFC",
"4122",
"-",
"compliant",
"version",
"4",
"UUID",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Text.php#L46-L58 |
UnionOfRAD/lithium | util/Text.php | Text.insert | public static function insert($str, array $data, array $options = []) {
$defaults = [
'before' => '{:',
'after' => '}',
'escape' => null,
'format' => null,
'clean' => false
];
$options += $defaults;
$format = $options['format'];
if ($format === 'regex' || (!$format && $options['escape'])) {
... | php | public static function insert($str, array $data, array $options = []) {
$defaults = [
'before' => '{:',
'after' => '}',
'escape' => null,
'format' => null,
'clean' => false
];
$options += $defaults;
$format = $options['format'];
if ($format === 'regex' || (!$format && $options['escape'])) {
... | [
"public",
"static",
"function",
"insert",
"(",
"$",
"str",
",",
"array",
"$",
"data",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'before'",
"=>",
"'{:'",
",",
"'after'",
"=>",
"'}'",
",",
"'escape'",
"=>",
"n... | Replaces variable placeholders inside a string with any given data. Each key
in the `$data` array corresponds to a variable placeholder name in `$str`.
Usage:
```
Text::insert(
'My name is {:name} and I am {:age} years old.',
['name' => 'Bob', 'age' => '65']
); // returns 'My name is Bob and I am 65 years old.'
```
P... | [
"Replaces",
"variable",
"placeholders",
"inside",
"a",
"string",
"with",
"any",
"given",
"data",
".",
"Each",
"key",
"in",
"the",
"$data",
"array",
"corresponds",
"to",
"a",
"variable",
"placeholder",
"name",
"in",
"$str",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Text.php#L92-L154 |
UnionOfRAD/lithium | util/Text.php | Text.clean | public static function clean($str, array $options = []) {
if (is_array($options['clean'])) {
$clean = $options['clean'];
} else {
$clean = [
'method' => is_bool($options['clean']) ? 'text' : $options['clean']
];
}
switch ($clean['method']) {
case 'text':
$clean += [
'word' => '[\w,.]+'... | php | public static function clean($str, array $options = []) {
if (is_array($options['clean'])) {
$clean = $options['clean'];
} else {
$clean = [
'method' => is_bool($options['clean']) ? 'text' : $options['clean']
];
}
switch ($clean['method']) {
case 'text':
$clean += [
'word' => '[\w,.]+'... | [
"public",
"static",
"function",
"clean",
"(",
"$",
"str",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"options",
"[",
"'clean'",
"]",
")",
")",
"{",
"$",
"clean",
"=",
"$",
"options",
"[",
"'clean'",
"]... | Cleans up a `Text::insert()` formatted string with given `$options` depending
on the `'clean'` option. The goal of this function is to replace all whitespace
and unneeded mark-up around place-holders that did not get replaced by `Text::insert()`.
@param string $str The string to clean.
@param array $options Available ... | [
"Cleans",
"up",
"a",
"Text",
"::",
"insert",
"()",
"formatted",
"string",
"with",
"given",
"$options",
"depending",
"on",
"the",
"clean",
"option",
".",
"The",
"goal",
"of",
"this",
"function",
"is",
"to",
"replace",
"all",
"whitespace",
"and",
"unneeded",
... | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Text.php#L173-L222 |
UnionOfRAD/lithium | util/Text.php | Text.extract | public static function extract($regex, $str, $index = 0) {
if (!preg_match($regex, $str, $match)) {
return false;
}
return isset($match[$index]) ? $match[$index] : null;
} | php | public static function extract($regex, $str, $index = 0) {
if (!preg_match($regex, $str, $match)) {
return false;
}
return isset($match[$index]) ? $match[$index] : null;
} | [
"public",
"static",
"function",
"extract",
"(",
"$",
"regex",
",",
"$",
"str",
",",
"$",
"index",
"=",
"0",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"$",
"regex",
",",
"$",
"str",
",",
"$",
"match",
")",
")",
"{",
"return",
"false",
";",
"}... | Extract a part of a string based on a regular expression `$regex`.
@param string $regex The regular expression to use.
@param string $str The string to run the extraction on.
@param integer $index The number of the part to return based on the regex.
@return mixed | [
"Extract",
"a",
"part",
"of",
"a",
"string",
"based",
"on",
"a",
"regular",
"expression",
"$regex",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Text.php#L232-L237 |
UnionOfRAD/lithium | util/Text.php | Text.tokenize | public static function tokenize($data, array $options = []) {
$options += ['separator' => ',', 'leftBound' => '(', 'rightBound' => ')'];
if (!$data || is_array($data)) {
return $data;
}
$depth = 0;
$offset = 0;
$buffer = '';
$results = [];
$length = strlen($data);
$open = false;
while ($offset... | php | public static function tokenize($data, array $options = []) {
$options += ['separator' => ',', 'leftBound' => '(', 'rightBound' => ')'];
if (!$data || is_array($data)) {
return $data;
}
$depth = 0;
$offset = 0;
$buffer = '';
$results = [];
$length = strlen($data);
$open = false;
while ($offset... | [
"public",
"static",
"function",
"tokenize",
"(",
"$",
"data",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"+=",
"[",
"'separator'",
"=>",
"','",
",",
"'leftBound'",
"=>",
"'('",
",",
"'rightBound'",
"=>",
"')'",
"]",
";",
"... | Tokenizes a string using `$options['separator']`, ignoring any instances of
`$options['separator']` that appear between `$options['leftBound']` and
`$options['rightBound']`.
@param string $data The data to tokenize.
@param array $options Options to use when tokenizing:
-`'separator'` _string_: The token to split the d... | [
"Tokenizes",
"a",
"string",
"using",
"$options",
"[",
"separator",
"]",
"ignoring",
"any",
"instances",
"of",
"$options",
"[",
"separator",
"]",
"that",
"appear",
"between",
"$options",
"[",
"leftBound",
"]",
"and",
"$options",
"[",
"rightBound",
"]",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Text.php#L251-L315 |
UnionOfRAD/lithium | analysis/logger/adapter/File.php | File.write | public function write($priority, $message) {
return function($params) {
$path = $this->_config['path'] . '/' . $this->_config['file']($params, $this->_config);
$params['timestamp'] = date($this->_config['timestamp']);
$message = Text::insert($this->_config['format'], $params);
return file_put_contents($pa... | php | public function write($priority, $message) {
return function($params) {
$path = $this->_config['path'] . '/' . $this->_config['file']($params, $this->_config);
$params['timestamp'] = date($this->_config['timestamp']);
$message = Text::insert($this->_config['format'], $params);
return file_put_contents($pa... | [
"public",
"function",
"write",
"(",
"$",
"priority",
",",
"$",
"message",
")",
"{",
"return",
"function",
"(",
"$",
"params",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"_config",
"[",
"'path'",
"]",
".",
"'/'",
".",
"$",
"this",
"->",
"_config... | Appends a message to a log file.
@see lithium\analysis\Logger::$_priorities
@param string $priority The message priority. See `Logger::$_priorities`.
@param string $message The message to write to the log.
@return \Closure Function returning boolean `true` on successful write, `false` otherwise. | [
"Appends",
"a",
"message",
"to",
"a",
"log",
"file",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/logger/adapter/File.php#L73-L80 |
UnionOfRAD/lithium | aop/Chain.php | Chain.run | public function run(array $params, $implementation) {
$this->_implementation = $implementation;
$filter = reset($this->_filters);
$result = $filter($params, $this);
$this->_implementation = null;
return $result;
} | php | public function run(array $params, $implementation) {
$this->_implementation = $implementation;
$filter = reset($this->_filters);
$result = $filter($params, $this);
$this->_implementation = null;
return $result;
} | [
"public",
"function",
"run",
"(",
"array",
"$",
"params",
",",
"$",
"implementation",
")",
"{",
"$",
"this",
"->",
"_implementation",
"=",
"$",
"implementation",
";",
"$",
"filter",
"=",
"reset",
"(",
"$",
"this",
"->",
"_filters",
")",
";",
"$",
"resu... | Runs the chain causing any queued callables and finally the
implementation to be executed.
Before each run the implementation is made available to
`Chain::__invoke()` and the chain rewinded, after each run the
implementation is unset.
An example implementation which is bound to an instance receives exactly
one argume... | [
"Runs",
"the",
"chain",
"causing",
"any",
"queued",
"callables",
"and",
"finally",
"the",
"implementation",
"to",
"be",
"executed",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/aop/Chain.php#L119-L127 |
UnionOfRAD/lithium | aop/Chain.php | Chain.next | public function next(/* array */ $params) {
$message = '`$chain->next()` has been deprecated in favor of `$chain($params)`.';
trigger_error($message, E_USER_DEPRECATED);
return $this($this->_bcNext(func_get_args()));
} | php | public function next(/* array */ $params) {
$message = '`$chain->next()` has been deprecated in favor of `$chain($params)`.';
trigger_error($message, E_USER_DEPRECATED);
return $this($this->_bcNext(func_get_args()));
} | [
"public",
"function",
"next",
"(",
"/* array */",
"$",
"params",
")",
"{",
"$",
"message",
"=",
"'`$chain->next()` has been deprecated in favor of `$chain($params)`.'",
";",
"trigger_error",
"(",
"$",
"message",
",",
"E_USER_DEPRECATED",
")",
";",
"return",
"$",
"this... | Advances the chain by one and executes the next filter in line.
This method is usually accessed from within a filter function.
```
function($params, $chain) {
return $chain->next($params);
}
```
@deprecated
@param array $params An array of named parameters.
@return mixed The return value of the next filter. If there ... | [
"Advances",
"the",
"chain",
"by",
"one",
"and",
"executes",
"the",
"next",
"filter",
"in",
"line",
".",
"This",
"method",
"is",
"usually",
"accessed",
"from",
"within",
"a",
"filter",
"function",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/aop/Chain.php#L195-L200 |
UnionOfRAD/lithium | aop/Chain.php | Chain.method | public function method($full = false) {
$message = '`$chain->method()` has been deprecated.';
trigger_error($message, E_USER_DEPRECATED);
$class = is_string($this->_class) ? $this->_class : get_class($this->_class);
return $full ? $class . '::' . $this->_method : $this->_method;
} | php | public function method($full = false) {
$message = '`$chain->method()` has been deprecated.';
trigger_error($message, E_USER_DEPRECATED);
$class = is_string($this->_class) ? $this->_class : get_class($this->_class);
return $full ? $class . '::' . $this->_method : $this->_method;
} | [
"public",
"function",
"method",
"(",
"$",
"full",
"=",
"false",
")",
"{",
"$",
"message",
"=",
"'`$chain->method()` has been deprecated.'",
";",
"trigger_error",
"(",
"$",
"message",
",",
"E_USER_DEPRECATED",
")",
";",
"$",
"class",
"=",
"is_string",
"(",
"$",... | Gets the method name associated with this filter chain. This is
the method being filtered.
@deprecated
@param boolean $full Whether to include the class name, defaults to `false`.
@return string When $full is `true` returns a string with pattern
`<CLASS>::<METHOD>`, else returns just the method name. | [
"Gets",
"the",
"method",
"name",
"associated",
"with",
"this",
"filter",
"chain",
".",
"This",
"is",
"the",
"method",
"being",
"filtered",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/aop/Chain.php#L211-L217 |
UnionOfRAD/lithium | storage/cache/adapter/Apc.php | Apc.write | public function write(array $keys, $expiry = null) {
$expiry = $expiry || $expiry === Cache::PERSIST ? $expiry : $this->_config['expiry'];
if (!$expiry || $expiry === Cache::PERSIST) {
$ttl = 0;
} elseif (is_int($expiry)) {
$ttl = $expiry;
} else {
$ttl = strtotime($expiry) - time();
}
if ($this->... | php | public function write(array $keys, $expiry = null) {
$expiry = $expiry || $expiry === Cache::PERSIST ? $expiry : $this->_config['expiry'];
if (!$expiry || $expiry === Cache::PERSIST) {
$ttl = 0;
} elseif (is_int($expiry)) {
$ttl = $expiry;
} else {
$ttl = strtotime($expiry) - time();
}
if ($this->... | [
"public",
"function",
"write",
"(",
"array",
"$",
"keys",
",",
"$",
"expiry",
"=",
"null",
")",
"{",
"$",
"expiry",
"=",
"$",
"expiry",
"||",
"$",
"expiry",
"===",
"Cache",
"::",
"PERSIST",
"?",
"$",
"expiry",
":",
"$",
"this",
"->",
"_config",
"["... | Write values to the cache. All items to be cached will receive an
expiration time of `$expiry`.
@param array $keys Key/value pairs with keys to uniquely identify the to-be-cached item.
@param string|integer $expiry A `strtotime()` compatible cache time or TTL in seconds.
To persist an item use `\lithium\storage\Cache:... | [
"Write",
"values",
"to",
"the",
"cache",
".",
"All",
"items",
"to",
"be",
"cached",
"will",
"receive",
"an",
"expiration",
"time",
"of",
"$expiry",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/storage/cache/adapter/Apc.php#L86-L100 |
UnionOfRAD/lithium | storage/cache/adapter/Apc.php | Apc.read | public function read(array $keys) {
if ($this->_config['scope']) {
$keys = $this->_addScopePrefix($this->_config['scope'], $keys);
}
$results = apc_fetch($keys);
if ($this->_config['scope']) {
$results = $this->_removeScopePrefix($this->_config['scope'], $results);
}
return $results;
} | php | public function read(array $keys) {
if ($this->_config['scope']) {
$keys = $this->_addScopePrefix($this->_config['scope'], $keys);
}
$results = apc_fetch($keys);
if ($this->_config['scope']) {
$results = $this->_removeScopePrefix($this->_config['scope'], $results);
}
return $results;
} | [
"public",
"function",
"read",
"(",
"array",
"$",
"keys",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_config",
"[",
"'scope'",
"]",
")",
"{",
"$",
"keys",
"=",
"$",
"this",
"->",
"_addScopePrefix",
"(",
"$",
"this",
"->",
"_config",
"[",
"'scope'",
"]... | Read values from the cache. Will attempt to return an array of data
containing key/value pairs of the requested data.
@param array $keys Keys to uniquely identify the cached items.
@return array Cached values keyed by cache keys on successful read,
keys which could not be read will not be included in
the results array... | [
"Read",
"values",
"from",
"the",
"cache",
".",
"Will",
"attempt",
"to",
"return",
"an",
"array",
"of",
"data",
"containing",
"key",
"/",
"value",
"pairs",
"of",
"the",
"requested",
"data",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/storage/cache/adapter/Apc.php#L111-L121 |
UnionOfRAD/lithium | storage/cache/adapter/Apc.php | Apc.delete | public function delete(array $keys) {
if ($this->_config['scope']) {
$keys = $this->_addScopePrefix($this->_config['scope'], $keys);
}
return apc_delete($keys) === [];
} | php | public function delete(array $keys) {
if ($this->_config['scope']) {
$keys = $this->_addScopePrefix($this->_config['scope'], $keys);
}
return apc_delete($keys) === [];
} | [
"public",
"function",
"delete",
"(",
"array",
"$",
"keys",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_config",
"[",
"'scope'",
"]",
")",
"{",
"$",
"keys",
"=",
"$",
"this",
"->",
"_addScopePrefix",
"(",
"$",
"this",
"->",
"_config",
"[",
"'scope'",
... | Will attempt to remove specified keys from the user space cache.
@param array $keys Keys to uniquely identify the cached items.
@return boolean `true` on successful delete, `false` otherwise. | [
"Will",
"attempt",
"to",
"remove",
"specified",
"keys",
"from",
"the",
"user",
"space",
"cache",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/storage/cache/adapter/Apc.php#L129-L134 |
UnionOfRAD/lithium | storage/cache/adapter/Apc.php | Apc.enabled | public static function enabled() {
$loaded = extension_loaded('apc');
$isCli = (php_sapi_name() === 'cli');
$enabled = (!$isCli && ini_get('apc.enabled')) || ($isCli && ini_get('apc.enable_cli'));
return ($loaded && $enabled);
} | php | public static function enabled() {
$loaded = extension_loaded('apc');
$isCli = (php_sapi_name() === 'cli');
$enabled = (!$isCli && ini_get('apc.enabled')) || ($isCli && ini_get('apc.enable_cli'));
return ($loaded && $enabled);
} | [
"public",
"static",
"function",
"enabled",
"(",
")",
"{",
"$",
"loaded",
"=",
"extension_loaded",
"(",
"'apc'",
")",
";",
"$",
"isCli",
"=",
"(",
"php_sapi_name",
"(",
")",
"===",
"'cli'",
")",
";",
"$",
"enabled",
"=",
"(",
"!",
"$",
"isCli",
"&&",
... | Determines if the APC extension has been installed and
if the userspace cache is available.
@return boolean `true` if enabled, `false` otherwise. | [
"Determines",
"if",
"the",
"APC",
"extension",
"has",
"been",
"installed",
"and",
"if",
"the",
"userspace",
"cache",
"is",
"available",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/storage/cache/adapter/Apc.php#L189-L194 |
UnionOfRAD/lithium | template/helper/Form.php | Form.config | public function config(array $config = []) {
if (!$config) {
$keys = ['base' => '', 'text' => '', 'textarea' => '', 'attributes' => ''];
return ['templates' => $this->_templateMap] + array_intersect_key(
$this->_config, $keys
);
}
if (isset($config['templates'])) {
$this->_templateMap = $config['t... | php | public function config(array $config = []) {
if (!$config) {
$keys = ['base' => '', 'text' => '', 'textarea' => '', 'attributes' => ''];
return ['templates' => $this->_templateMap] + array_intersect_key(
$this->_config, $keys
);
}
if (isset($config['templates'])) {
$this->_templateMap = $config['t... | [
"public",
"function",
"config",
"(",
"array",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"config",
")",
"{",
"$",
"keys",
"=",
"[",
"'base'",
"=>",
"''",
",",
"'text'",
"=>",
"''",
",",
"'textarea'",
"=>",
"''",
",",
"'attribute... | Allows you to configure a default set of options which are included on a per-method basis,
and configure method template overrides.
To force all `<label />` elements to have a default `class` attribute value of `"foo"`,
simply do the following:
```
$this->form->config(['label' => ['class' => 'foo']]);
```
Note that ... | [
"Allows",
"you",
"to",
"configure",
"a",
"default",
"set",
"of",
"options",
"which",
"are",
"included",
"on",
"a",
"per",
"-",
"method",
"basis",
"and",
"configure",
"method",
"template",
"overrides",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/template/helper/Form.php#L236-L250 |
UnionOfRAD/lithium | template/helper/Form.php | Form.create | public function create($bindings = null, array $options = []) {
$request = $this->_context ? $this->_context->request() : null;
$binding = is_array($bindings) ? reset($bindings) : $bindings;
$defaults = [
'url' => $request ? $request->params : [],
'type' => null,
'action' => null,
'method' => $bindin... | php | public function create($bindings = null, array $options = []) {
$request = $this->_context ? $this->_context->request() : null;
$binding = is_array($bindings) ? reset($bindings) : $bindings;
$defaults = [
'url' => $request ? $request->params : [],
'type' => null,
'action' => null,
'method' => $bindin... | [
"public",
"function",
"create",
"(",
"$",
"bindings",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"_context",
"?",
"$",
"this",
"->",
"_context",
"->",
"request",
"(",
")",
":",
"null"... | Creates an HTML form, and optionally binds it to a data object which contains information on
how to render form fields, any data to pre-populate the form with, and any validation errors.
Typically, a data object will be a `Record` object returned from a `Model`, but you can
define your own custom objects as well. For m... | [
"Creates",
"an",
"HTML",
"form",
"and",
"optionally",
"binds",
"it",
"to",
"a",
"data",
"object",
"which",
"contains",
"information",
"on",
"how",
"to",
"render",
"form",
"fields",
"any",
"data",
"to",
"pre",
"-",
"populate",
"the",
"form",
"with",
"and",
... | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/template/helper/Form.php#L282-L326 |
UnionOfRAD/lithium | template/helper/Form.php | Form.end | public function end() {
list(, $options, $template) = $this->_defaults(__FUNCTION__, null, []);
$params = compact('options', 'template');
$result = Filters::run($this, __FUNCTION__, $params, function($params) {
$this->_bindingOptions = [];
return $this->_render('end', $params['template'], []);
});
unse... | php | public function end() {
list(, $options, $template) = $this->_defaults(__FUNCTION__, null, []);
$params = compact('options', 'template');
$result = Filters::run($this, __FUNCTION__, $params, function($params) {
$this->_bindingOptions = [];
return $this->_render('end', $params['template'], []);
});
unse... | [
"public",
"function",
"end",
"(",
")",
"{",
"list",
"(",
",",
"$",
"options",
",",
"$",
"template",
")",
"=",
"$",
"this",
"->",
"_defaults",
"(",
"__FUNCTION__",
",",
"null",
",",
"[",
"]",
")",
";",
"$",
"params",
"=",
"compact",
"(",
"'options'"... | Echoes a closing `</form>` tag and unbinds the `Form` helper from any `Record` or `Document`
object used to generate the corresponding form.
@return string Returns a closing `</form>` tag.
@filter | [
"Echoes",
"a",
"closing",
"<",
"/",
"form",
">",
"tag",
"and",
"unbinds",
"the",
"Form",
"helper",
"from",
"any",
"Record",
"or",
"Document",
"object",
"used",
"to",
"generate",
"the",
"corresponding",
"form",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/template/helper/Form.php#L335-L346 |
UnionOfRAD/lithium | template/helper/Form.php | Form.binding | public function binding($name = null) {
if (!$this->_binding) {
return $this->_config['binding'](null, $name);
}
$binding = $this->_binding;
$model = null;
$key = $name;
if (is_array($binding)) {
switch (true) {
case strpos($name, '.'):
list($model, $key) = explode('.', $name, 2);
$bin... | php | public function binding($name = null) {
if (!$this->_binding) {
return $this->_config['binding'](null, $name);
}
$binding = $this->_binding;
$model = null;
$key = $name;
if (is_array($binding)) {
switch (true) {
case strpos($name, '.'):
list($model, $key) = explode('.', $name, 2);
$bin... | [
"public",
"function",
"binding",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_binding",
")",
"{",
"return",
"$",
"this",
"->",
"_config",
"[",
"'binding'",
"]",
"(",
"null",
",",
"$",
"name",
")",
";",
"}",
"$",
... | Returns the entity that the `Form` helper is currently bound to.
@see lithium\template\helper\Form::$_binding
@param string $name If specified, match this field name against the list of bindings
@param string $key If $name specified, where to store relevant $_binding key
@return object Returns an object, usually an in... | [
"Returns",
"the",
"entity",
"that",
"the",
"Form",
"helper",
"is",
"currently",
"bound",
"to",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/template/helper/Form.php#L356-L381 |
UnionOfRAD/lithium | template/helper/Form.php | Form.field | public function field($name, array $options = []) {
if (is_array($name)) {
return $this->_fields($name, $options);
}
$method = __FUNCTION__;
if (isset($options['type']) && !empty($this->_config['field-' . $options['type']])) {
$method = 'field-' . $options['type'];
}
list(, $options, $template) = $thi... | php | public function field($name, array $options = []) {
if (is_array($name)) {
return $this->_fields($name, $options);
}
$method = __FUNCTION__;
if (isset($options['type']) && !empty($this->_config['field-' . $options['type']])) {
$method = 'field-' . $options['type'];
}
list(, $options, $template) = $thi... | [
"public",
"function",
"field",
"(",
"$",
"name",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_fields",
"(",
"$",
"name",
",",
"$",
"options",
")",
... | Generates a form field with a label, input, and error message (if applicable), all contained
within a wrapping element.
```
echo $this->form->field('name');
echo $this->form->field('present', ['type' => 'checkbox']);
echo $this->form->field(['email' => 'Enter a valid email']);
echo $this->form->field(['name','email','... | [
"Generates",
"a",
"form",
"field",
"with",
"a",
"label",
"input",
"and",
"error",
"message",
"(",
"if",
"applicable",
")",
"all",
"contained",
"within",
"a",
"wrapping",
"element",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/template/helper/Form.php#L465-L522 |
UnionOfRAD/lithium | template/helper/Form.php | Form._fields | protected function _fields(array $fields, array $options = []) {
$result = [];
foreach ($fields as $field => $label) {
if (is_numeric($field)) {
$field = $label;
unset($label);
}
$result[] = $this->field($field, compact('label') + $options);
}
return join("\n", $result);
} | php | protected function _fields(array $fields, array $options = []) {
$result = [];
foreach ($fields as $field => $label) {
if (is_numeric($field)) {
$field = $label;
unset($label);
}
$result[] = $this->field($field, compact('label') + $options);
}
return join("\n", $result);
} | [
"protected",
"function",
"_fields",
"(",
"array",
"$",
"fields",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
"=>",
"$",
"label",
")",
"{",
"if",
"(",... | Helper method used by `Form::field()` for iterating over an array of multiple fields.
@see lithium\template\helper\Form::field()
@param array $fields An array of fields to render.
@param array $options The array of options to apply to all fields in the `$fields` array. See
the `$options` parameter of the `field` metho... | [
"Helper",
"method",
"used",
"by",
"Form",
"::",
"field",
"()",
"for",
"iterating",
"over",
"an",
"array",
"of",
"multiple",
"fields",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/template/helper/Form.php#L533-L544 |
UnionOfRAD/lithium | template/helper/Form.php | Form.button | public function button($title = null, array $options = []) {
$defaults = ['escape' => true];
list($scope, $options) = $this->_options($defaults, $options);
list($title, $options, $template) = $this->_defaults(__METHOD__, $title, $options);
$arguments = compact('type', 'title', 'options', 'value');
return $th... | php | public function button($title = null, array $options = []) {
$defaults = ['escape' => true];
list($scope, $options) = $this->_options($defaults, $options);
list($title, $options, $template) = $this->_defaults(__METHOD__, $title, $options);
$arguments = compact('type', 'title', 'options', 'value');
return $th... | [
"public",
"function",
"button",
"(",
"$",
"title",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'escape'",
"=>",
"true",
"]",
";",
"list",
"(",
"$",
"scope",
",",
"$",
"options",
")",
"=",
"$",
... | Generates an HTML button `<button></button>`.
@param string $title The title of the button.
@param array $options Any options passed are converted to HTML attributes within the
`<button></button>` tag.
@return string Returns a `<button></button>` tag with the given title and HTML attributes. | [
"Generates",
"an",
"HTML",
"button",
"<button",
">",
"<",
"/",
"button",
">",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/template/helper/Form.php#L554-L561 |
UnionOfRAD/lithium | template/helper/Form.php | Form.submit | public function submit($title = null, array $options = []) {
list($name, $options, $template) = $this->_defaults(__FUNCTION__, null, $options);
return $this->_render(__METHOD__, $template, compact('title', 'options'));
} | php | public function submit($title = null, array $options = []) {
list($name, $options, $template) = $this->_defaults(__FUNCTION__, null, $options);
return $this->_render(__METHOD__, $template, compact('title', 'options'));
} | [
"public",
"function",
"submit",
"(",
"$",
"title",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"list",
"(",
"$",
"name",
",",
"$",
"options",
",",
"$",
"template",
")",
"=",
"$",
"this",
"->",
"_defaults",
"(",
"__FUNCTION__... | Generates an HTML `<input type="submit" />` object.
@param string $title The title of the submit button.
@param array $options Any options passed are converted to HTML attributes within the
`<input />` tag.
@return string Returns a submit `<input />` tag with the given title and HTML attributes. | [
"Generates",
"an",
"HTML",
"<input",
"type",
"=",
"submit",
"/",
">",
"object",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/template/helper/Form.php#L571-L574 |
UnionOfRAD/lithium | template/helper/Form.php | Form.textarea | public function textarea($name, array $options = []) {
list($name, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
list($scope, $options) = $this->_options(['value' => null], $options);
$value = isset($scope['value']) ? $scope['value'] : '';
return $this->_render(__METHOD__, $template, c... | php | public function textarea($name, array $options = []) {
list($name, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
list($scope, $options) = $this->_options(['value' => null], $options);
$value = isset($scope['value']) ? $scope['value'] : '';
return $this->_render(__METHOD__, $template, c... | [
"public",
"function",
"textarea",
"(",
"$",
"name",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"list",
"(",
"$",
"name",
",",
"$",
"options",
",",
"$",
"template",
")",
"=",
"$",
"this",
"->",
"_defaults",
"(",
"__FUNCTION__",
",",
"$",... | Generates an HTML `<textarea>...</textarea>` object.
@param string $name The name of the field.
@param array $options The options to be used when generating the `<textarea />` tag pair,
which are as follows:
- `'value'` _string_: The content value of the field.
- Any other options specified are rendered as HTML attrib... | [
"Generates",
"an",
"HTML",
"<textarea",
">",
"...",
"<",
"/",
"textarea",
">",
"object",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/template/helper/Form.php#L586-L591 |
UnionOfRAD/lithium | template/helper/Form.php | Form._datalist | protected function _datalist(array $list, array $scope) {
$options = [];
if (isset($scope['id'])) {
$id = $options['id'] = $scope['id'] . 'List';
}
$raw = array_reduce($list, function($carry, $value) {
return $carry .= $this->_render(__METHOD__, 'datalist-option', compact('value'));
}, '');
return [... | php | protected function _datalist(array $list, array $scope) {
$options = [];
if (isset($scope['id'])) {
$id = $options['id'] = $scope['id'] . 'List';
}
$raw = array_reduce($list, function($carry, $value) {
return $carry .= $this->_render(__METHOD__, 'datalist-option', compact('value'));
}, '');
return [... | [
"protected",
"function",
"_datalist",
"(",
"array",
"$",
"list",
",",
"array",
"$",
"scope",
")",
"{",
"$",
"options",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"scope",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"id",
"=",
"$",
"options",
"... | Generates an HTML `<datalist></datalist>` object with `<option>` elements.
@link https://www.w3.org/wiki/HTML/Elements/datalist
@param array $list Valuues, which will be used to render the options of the datalist.
@param array $scope An array of options passed to the parent scope.
@return string Returns a `<datalist>`... | [
"Generates",
"an",
"HTML",
"<datalist",
">",
"<",
"/",
"datalist",
">",
"object",
"with",
"<option",
">",
"elements",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/template/helper/Form.php#L613-L627 |
UnionOfRAD/lithium | template/helper/Form.php | Form.select | public function select($name, $list = [], array $options = []) {
$defaults = ['empty' => false, 'value' => null];
list($name, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
list($scope, $options) = $this->_options($defaults, $options);
if ($scope['empty']) {
$list = ['' => ($scope['... | php | public function select($name, $list = [], array $options = []) {
$defaults = ['empty' => false, 'value' => null];
list($name, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
list($scope, $options) = $this->_options($defaults, $options);
if ($scope['empty']) {
$list = ['' => ($scope['... | [
"public",
"function",
"select",
"(",
"$",
"name",
",",
"$",
"list",
"=",
"[",
"]",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'empty'",
"=>",
"false",
",",
"'value'",
"=>",
"null",
"]",
";",
"list",
"(",
... | Generates a `<select />` list using the `$list` parameter for the `<option />` tags. The
default selection will be set to the value of `$options['value']`, if specified.
For example:
```
$this->form->select('colors', [1 => 'red', 2 => 'green', 3 => 'blue'], [
'id' => 'Colors', 'value' => 2
]);
// Renders a '<select />... | [
"Generates",
"a",
"<select",
"/",
">",
"list",
"using",
"the",
"$list",
"parameter",
"for",
"the",
"<option",
"/",
">",
"tags",
".",
"The",
"default",
"selection",
"will",
"be",
"set",
"to",
"the",
"value",
"of",
"$options",
"[",
"value",
"]",
"if",
"s... | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/template/helper/Form.php#L650-L663 |
UnionOfRAD/lithium | template/helper/Form.php | Form._selectOptions | protected function _selectOptions(array $list, array $scope) {
$result = "";
foreach ($list as $value => $title) {
if (is_array($title)) {
$label = $value;
$options = [];
$raw = $this->_selectOptions($title, $scope);
$params = compact('label', 'options', 'raw');
$result .= $this->_render('s... | php | protected function _selectOptions(array $list, array $scope) {
$result = "";
foreach ($list as $value => $title) {
if (is_array($title)) {
$label = $value;
$options = [];
$raw = $this->_selectOptions($title, $scope);
$params = compact('label', 'options', 'raw');
$result .= $this->_render('s... | [
"protected",
"function",
"_selectOptions",
"(",
"array",
"$",
"list",
",",
"array",
"$",
"scope",
")",
"{",
"$",
"result",
"=",
"\"\"",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"value",
"=>",
"$",
"title",
")",
"{",
"if",
"(",
"is_array",
"(",
... | Generator method used by `select()` to produce `<option />` and `<optgroup />` elements.
Generally, this method should not need to be called directly, but through `select()`.
@param array $list Either a flat key/value array of select menu options, or an array which
contains key/value elements and/or elements where the... | [
"Generator",
"method",
"used",
"by",
"select",
"()",
"to",
"produce",
"<option",
"/",
">",
"and",
"<optgroup",
"/",
">",
"elements",
".",
"Generally",
"this",
"method",
"should",
"not",
"need",
"to",
"be",
"called",
"directly",
"but",
"through",
"select",
... | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/template/helper/Form.php#L678-L701 |
UnionOfRAD/lithium | template/helper/Form.php | Form.checkbox | public function checkbox($name, array $options = []) {
$defaults = ['value' => '1', 'hidden' => true];
$options += $defaults;
$default = $options['value'];
$key = $name;
$out = '';
list($name, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
list($scope, $options) = $this->_options... | php | public function checkbox($name, array $options = []) {
$defaults = ['value' => '1', 'hidden' => true];
$options += $defaults;
$default = $options['value'];
$key = $name;
$out = '';
list($name, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
list($scope, $options) = $this->_options... | [
"public",
"function",
"checkbox",
"(",
"$",
"name",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'value'",
"=>",
"'1'",
",",
"'hidden'",
"=>",
"true",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"$",
... | Generates an HTML `<input type="checkbox" />` object.
@param string $name The name of the field.
@param array $options Options to be used when generating the checkbox `<input />` element:
- `'checked'` _boolean_: Whether or not the field should be checked by default.
- `'value'` _mixed_: if specified, it will be used ... | [
"Generates",
"an",
"HTML",
"<input",
"type",
"=",
"checkbox",
"/",
">",
"object",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/template/helper/Form.php#L714-L732 |
UnionOfRAD/lithium | template/helper/Form.php | Form.radio | public function radio($name, array $options = []) {
$defaults = ['value' => '1'];
$options += $defaults;
$default = $options['value'];
$key = $name;
list($name, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
list($scope, $options) = $this->_options($defaults, $options);
if (!iss... | php | public function radio($name, array $options = []) {
$defaults = ['value' => '1'];
$options += $defaults;
$default = $options['value'];
$key = $name;
list($name, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
list($scope, $options) = $this->_options($defaults, $options);
if (!iss... | [
"public",
"function",
"radio",
"(",
"$",
"name",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'value'",
"=>",
"'1'",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"$",
"default",
"=",
"$",
"options",
... | Generates an HTML `<input type="radio" />` object.
@param string $name The name of the field
@param array $options All options to be used when generating the radio `<input />` element:
- `'checked'` _boolean_: Whether or not the field should be selected by default.
- `'value'` _mixed_: if specified, it will be used as... | [
"Generates",
"an",
"HTML",
"<input",
"type",
"=",
"radio",
"/",
">",
"object",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/template/helper/Form.php#L745-L760 |
UnionOfRAD/lithium | template/helper/Form.php | Form.password | public function password($name, array $options = []) {
list($name, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
unset($options['value']);
return $this->_render(__METHOD__, $template, compact('name', 'options'));
} | php | public function password($name, array $options = []) {
list($name, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
unset($options['value']);
return $this->_render(__METHOD__, $template, compact('name', 'options'));
} | [
"public",
"function",
"password",
"(",
"$",
"name",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"list",
"(",
"$",
"name",
",",
"$",
"options",
",",
"$",
"template",
")",
"=",
"$",
"this",
"->",
"_defaults",
"(",
"__FUNCTION__",
",",
"$",... | Generates an HTML `<input type="password" />` object.
@param string $name The name of the field.
@param array $options An array of HTML attributes with which the field should be rendered.
@return string Returns a `<input />` tag with the given name and HTML attributes. | [
"Generates",
"an",
"HTML",
"<input",
"type",
"=",
"password",
"/",
">",
"object",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/template/helper/Form.php#L769-L773 |
UnionOfRAD/lithium | template/helper/Form.php | Form.label | public function label($id, $title = null, array $options = []) {
$defaults = ['escape' => true];
if (is_array($title)) {
$options = current($title);
$title = key($title);
}
$title = $title ?: Inflector::humanize(str_replace('.', '_', $id));
list($name, $options, $template) = $this->_defaults(__FUNCTIO... | php | public function label($id, $title = null, array $options = []) {
$defaults = ['escape' => true];
if (is_array($title)) {
$options = current($title);
$title = key($title);
}
$title = $title ?: Inflector::humanize(str_replace('.', '_', $id));
list($name, $options, $template) = $this->_defaults(__FUNCTIO... | [
"public",
"function",
"label",
"(",
"$",
"id",
",",
"$",
"title",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'escape'",
"=>",
"true",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"title",
")",
... | Generates an HTML `<label></label>` object.
@param string $id The DOM ID of the field that the label is for.
@param string $title The content inside the `<label></label>` object.
@param array $options Besides HTML attributes, this parameter allows one additional flag:
- `'escape'` _boolean_: Defaults to `true`. Indica... | [
"Generates",
"an",
"HTML",
"<label",
">",
"<",
"/",
"label",
">",
"object",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/template/helper/Form.php#L797-L814 |
UnionOfRAD/lithium | template/helper/Form.php | Form.error | public function error($name, $key = null, array $options = []) {
$defaults = ['class' => 'error', 'messages' => []];
list(, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
$options += $defaults;
if (is_array($options['messages'])) {
$messages = $options['messages'] + ['default' => nu... | php | public function error($name, $key = null, array $options = []) {
$defaults = ['class' => 'error', 'messages' => []];
list(, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
$options += $defaults;
if (is_array($options['messages'])) {
$messages = $options['messages'] + ['default' => nu... | [
"public",
"function",
"error",
"(",
"$",
"name",
",",
"$",
"key",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'class'",
"=>",
"'error'",
",",
"'messages'",
"=>",
"[",
"]",
"]",
";",
"list",
"(",... | Generates an error message for a field which is part of an object bound to a form in
`create()`.
@param string $name The name of the field for which to render an error.
@param mixed $key If more than one error is present for `$name`, a key may be specified.
If `$key` is not set in the array of errors, or if `$key` is ... | [
"Generates",
"an",
"error",
"message",
"for",
"a",
"field",
"which",
"is",
"part",
"of",
"an",
"object",
"bound",
"to",
"a",
"form",
"in",
"create",
"()",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/template/helper/Form.php#L828-L876 |
UnionOfRAD/lithium | template/helper/Form.php | Form._defaults | protected function _defaults($method, $name, $options) {
$params = compact('method', 'name', 'options');
return Filters::run($this, __FUNCTION__, $params, function($params) {
$method = $params['method'];
$name = $params['name'];
$options = $params['options'];
$methodConfig = isset($this->_config[$meth... | php | protected function _defaults($method, $name, $options) {
$params = compact('method', 'name', 'options');
return Filters::run($this, __FUNCTION__, $params, function($params) {
$method = $params['method'];
$name = $params['name'];
$options = $params['options'];
$methodConfig = isset($this->_config[$meth... | [
"protected",
"function",
"_defaults",
"(",
"$",
"method",
",",
"$",
"name",
",",
"$",
"options",
")",
"{",
"$",
"params",
"=",
"compact",
"(",
"'method'",
",",
"'name'",
",",
"'options'",
")",
";",
"return",
"Filters",
"::",
"run",
"(",
"$",
"this",
... | Builds the defaults array for a method by name, according to the config.
@param string $method The name of the method to create defaults for.
@param string $name The `$name` supplied to the original method.
@param string $options `$options` from the original method.
@return array Defaults array contents. | [
"Builds",
"the",
"defaults",
"array",
"for",
"a",
"method",
"by",
"name",
"according",
"to",
"the",
"config",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/template/helper/Form.php#L886-L922 |
UnionOfRAD/lithium | template/helper/Form.php | Form._generators | protected function _generators($method, $name, $options) {
foreach ($this->_config['attributes'] as $key => $generator) {
if ($key === 'name') {
continue;
}
if ($generator && !isset($options[$key])) {
if (($attr = $generator($method, $name, $options)) !== null) {
$options[$key] = $attr;
}
... | php | protected function _generators($method, $name, $options) {
foreach ($this->_config['attributes'] as $key => $generator) {
if ($key === 'name') {
continue;
}
if ($generator && !isset($options[$key])) {
if (($attr = $generator($method, $name, $options)) !== null) {
$options[$key] = $attr;
}
... | [
"protected",
"function",
"_generators",
"(",
"$",
"method",
",",
"$",
"name",
",",
"$",
"options",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_config",
"[",
"'attributes'",
"]",
"as",
"$",
"key",
"=>",
"$",
"generator",
")",
"{",
"if",
"(",
"$",
... | Iterates over the configured attribute generators, and modifies the settings for a tag.
@param string $method The name of the helper method which was called, i.e. `'text'`,
`'select'`, etc.
@param string $name The name of the field whose attributes are being generated. Some helper
methods, such as `create()` and `end(... | [
"Iterates",
"over",
"the",
"configured",
"attribute",
"generators",
"and",
"modifies",
"the",
"settings",
"for",
"a",
"tag",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/template/helper/Form.php#L939-L955 |
UnionOfRAD/lithium | template/View.php | View._init | protected function _init() {
parent::_init();
$encoding = 'UTF-8';
if ($this->_response) {
$encoding =& $this->_response->encoding;
}
$h = function($data) use (&$encoding) {
return htmlspecialchars((string) $data, ENT_QUOTES, $encoding);
};
$this->outputFilters += compact('h') + $this->_config['ou... | php | protected function _init() {
parent::_init();
$encoding = 'UTF-8';
if ($this->_response) {
$encoding =& $this->_response->encoding;
}
$h = function($data) use (&$encoding) {
return htmlspecialchars((string) $data, ENT_QUOTES, $encoding);
};
$this->outputFilters += compact('h') + $this->_config['ou... | [
"protected",
"function",
"_init",
"(",
")",
"{",
"parent",
"::",
"_init",
"(",
")",
";",
"$",
"encoding",
"=",
"'UTF-8'",
";",
"if",
"(",
"$",
"this",
"->",
"_response",
")",
"{",
"$",
"encoding",
"=",
"&",
"$",
"this",
"->",
"_response",
"->",
"en... | Perform initialization of the View.
Looks up and initializes loader and renderer classes, and initializes the output escape
handler, matching the encoding from the `Response` object.
@return void | [
"Perform",
"initialization",
"of",
"the",
"View",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/template/View.php#L246-L268 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.