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/model/Query.php | Query._exportData | protected function _exportData() {
$data = $this->_entity ? $this->_entity->export() : $this->_data;
if (!$list = $this->_config['whitelist']) {
return $data;
}
$list = array_combine($list, $list);
if (!$this->_entity) {
return array_intersect_key($data, $list);
}
foreach ($data as $type => $values) {
if (!is_array($values)) {
continue;
}
$data[$type] = array_intersect_key($values, $list);
}
return $data;
} | php | protected function _exportData() {
$data = $this->_entity ? $this->_entity->export() : $this->_data;
if (!$list = $this->_config['whitelist']) {
return $data;
}
$list = array_combine($list, $list);
if (!$this->_entity) {
return array_intersect_key($data, $list);
}
foreach ($data as $type => $values) {
if (!is_array($values)) {
continue;
}
$data[$type] = array_intersect_key($values, $list);
}
return $data;
} | [
"protected",
"function",
"_exportData",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"_entity",
"?",
"$",
"this",
"->",
"_entity",
"->",
"export",
"(",
")",
":",
"$",
"this",
"->",
"_data",
";",
"if",
"(",
"!",
"$",
"list",
"=",
"$",
"this... | Helper method used by `export()` to extract the data either from a bound entity, or from
passed configuration, and filter it through a configured whitelist, if present.
@return array | [
"Helper",
"method",
"used",
"by",
"export",
"()",
"to",
"extract",
"the",
"data",
"either",
"from",
"a",
"bound",
"entity",
"or",
"from",
"passed",
"configuration",
"and",
"filter",
"it",
"through",
"a",
"configured",
"whitelist",
"if",
"present",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/model/Query.php#L619-L638 |
UnionOfRAD/lithium | data/model/Query.php | Query.alias | public function alias($alias = true, $relpath = null) {
if ($alias === true) {
if (!$relpath) {
return $this->_config['alias'];
}
$return = array_search($relpath, $this->_paths);
return $return ?: null;
}
if ($relpath === null) {
$this->_config['alias'] = $alias;
}
if ($relpath === null && ($model = $this->_config['model'])) {
$this->_models[$alias] = $model;
}
$relpath = (string) $relpath;
unset($this->_paths[array_search($relpath, $this->_paths)]);
if (!$alias && $relpath) {
$last = strrpos($relpath, '.');
$alias = $last ? substr($relpath, $last + 1) : $relpath;
}
if (isset($this->_alias[$alias])) {
$this->_alias[$alias]++;
$alias .= '__' . $this->_alias[$alias];
} else {
$this->_alias[$alias] = 1;
}
$this->_paths[$alias] = $relpath;
return $alias;
} | php | public function alias($alias = true, $relpath = null) {
if ($alias === true) {
if (!$relpath) {
return $this->_config['alias'];
}
$return = array_search($relpath, $this->_paths);
return $return ?: null;
}
if ($relpath === null) {
$this->_config['alias'] = $alias;
}
if ($relpath === null && ($model = $this->_config['model'])) {
$this->_models[$alias] = $model;
}
$relpath = (string) $relpath;
unset($this->_paths[array_search($relpath, $this->_paths)]);
if (!$alias && $relpath) {
$last = strrpos($relpath, '.');
$alias = $last ? substr($relpath, $last + 1) : $relpath;
}
if (isset($this->_alias[$alias])) {
$this->_alias[$alias]++;
$alias .= '__' . $this->_alias[$alias];
} else {
$this->_alias[$alias] = 1;
}
$this->_paths[$alias] = $relpath;
return $alias;
} | [
"public",
"function",
"alias",
"(",
"$",
"alias",
"=",
"true",
",",
"$",
"relpath",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"alias",
"===",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"relpath",
")",
"{",
"return",
"$",
"this",
"->",
"_config",
"[",
... | Get or Set a unique alias for the query or a query's relation if `$relpath` is set.
@param mixed $alias The value of the alias to set for the passed `$relpath`. For getting an
alias value set alias to `true`.
@param string $relpath A dotted relation name or `null` for identifying the query's model.
@return string An alias value or `null` for an unexisting `$relpath` alias. | [
"Get",
"or",
"Set",
"a",
"unique",
"alias",
"for",
"the",
"query",
"or",
"a",
"query",
"s",
"relation",
"if",
"$relpath",
"is",
"set",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/model/Query.php#L663-L697 |
UnionOfRAD/lithium | data/model/Query.php | Query.paths | public function paths(Source $source = null) {
if ($source) {
$this->applyStrategy($source);
}
return $this->_paths;
} | php | public function paths(Source $source = null) {
if ($source) {
$this->applyStrategy($source);
}
return $this->_paths;
} | [
"public",
"function",
"paths",
"(",
"Source",
"$",
"source",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"source",
")",
"{",
"$",
"this",
"->",
"applyStrategy",
"(",
"$",
"source",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_paths",
";",
"}"
] | Return the generated aliases mapped to their relation path
@param \lithium\data\Source $source Instance of the data source to use for conversion.
@return array Map between aliases and their corresponding dotted relation paths. | [
"Return",
"the",
"generated",
"aliases",
"mapped",
"to",
"their",
"relation",
"path"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/model/Query.php#L705-L710 |
UnionOfRAD/lithium | data/model/Query.php | Query.models | public function models(Source $source = null) {
if ($source) {
$this->applyStrategy($source);
}
return $this->_models;
} | php | public function models(Source $source = null) {
if ($source) {
$this->applyStrategy($source);
}
return $this->_models;
} | [
"public",
"function",
"models",
"(",
"Source",
"$",
"source",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"source",
")",
"{",
"$",
"this",
"->",
"applyStrategy",
"(",
"$",
"source",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_models",
";",
"}"
] | Return the generated aliases mapped to their corresponding model
@param \lithium\data\Source $source Instance of the data source to use for conversion.
@return array Map between aliases and their corresponding fully-namespaced model names. | [
"Return",
"the",
"generated",
"aliases",
"mapped",
"to",
"their",
"corresponding",
"model"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/model/Query.php#L718-L723 |
UnionOfRAD/lithium | data/model/Query.php | Query.respondsTo | public function respondsTo($method, $internal = false) {
return isset($this->_config[$method]) || parent::respondsTo($method, $internal);
} | php | public function respondsTo($method, $internal = false) {
return isset($this->_config[$method]) || parent::respondsTo($method, $internal);
} | [
"public",
"function",
"respondsTo",
"(",
"$",
"method",
",",
"$",
"internal",
"=",
"false",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"_config",
"[",
"$",
"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/data/model/Query.php#L749-L751 |
UnionOfRAD/lithium | data/model/Query.php | Query._entityConditions | protected function _entityConditions() {
if (!$this->_entity || !($model = $this->_config['model'])) {
return [];
}
$key = $model::key($this->_entity->data());
if (!$key && $this->type() !== 'create') {
throw new ConfigException('No matching primary key found.');
}
if (is_array($key)) {
return $key;
}
$key = $model::meta('key');
$val = $this->_entity->{$key};
return $val ? [$key => $val] : [];
} | php | protected function _entityConditions() {
if (!$this->_entity || !($model = $this->_config['model'])) {
return [];
}
$key = $model::key($this->_entity->data());
if (!$key && $this->type() !== 'create') {
throw new ConfigException('No matching primary key found.');
}
if (is_array($key)) {
return $key;
}
$key = $model::meta('key');
$val = $this->_entity->{$key};
return $val ? [$key => $val] : [];
} | [
"protected",
"function",
"_entityConditions",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_entity",
"||",
"!",
"(",
"$",
"model",
"=",
"$",
"this",
"->",
"_config",
"[",
"'model'",
"]",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"ke... | Will return a find first condition on the associated model if a record is connected.
Called by conditions when it is called as a get and no condition is set.
@return array Returns an array in the following format:
`([model's primary key'] => [that key set in the record])`. | [
"Will",
"return",
"a",
"find",
"first",
"condition",
"on",
"the",
"associated",
"model",
"if",
"a",
"record",
"is",
"connected",
".",
"Called",
"by",
"conditions",
"when",
"it",
"is",
"called",
"as",
"a",
"get",
"and",
"no",
"condition",
"is",
"set",
"."... | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/model/Query.php#L760-L776 |
UnionOfRAD/lithium | data/model/Query.php | Query.childs | public function childs($relpath = null, $query = null) {
if (!$model = $this->model()) {
throw new ConfigException("No binded model.");
}
if ($query) {
$this->_childs[$relpath] = $query;
return $this;
}
return $this->_childs;
} | php | public function childs($relpath = null, $query = null) {
if (!$model = $this->model()) {
throw new ConfigException("No binded model.");
}
if ($query) {
$this->_childs[$relpath] = $query;
return $this;
}
return $this->_childs;
} | [
"public",
"function",
"childs",
"(",
"$",
"relpath",
"=",
"null",
",",
"$",
"query",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"model",
"=",
"$",
"this",
"->",
"model",
"(",
")",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"\"No binded model.... | Get/set sub queries for the query.
The getter must be called after an export since the sub queries are built
during the export according the export's `mode` option and the query `with` option.
@see lithium\data\model\Query::export()
@param string $relpath a dotted relation path
@param string $query a query instance
@return mixed | [
"Get",
"/",
"set",
"sub",
"queries",
"for",
"the",
"query",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/model/Query.php#L789-L798 |
UnionOfRAD/lithium | data/collection/MultiKeyRecordSet.php | MultiKeyRecordSet.offsetExists | public function offsetExists($offset) {
$offset = (!$offset || $offset === true) ? 0 : $offset;
$this->offsetGet($offset);
if (in_array($offset, $this->_index)) {
return true;
}
return false;
} | php | public function offsetExists($offset) {
$offset = (!$offset || $offset === true) ? 0 : $offset;
$this->offsetGet($offset);
if (in_array($offset, $this->_index)) {
return true;
}
return false;
} | [
"public",
"function",
"offsetExists",
"(",
"$",
"offset",
")",
"{",
"$",
"offset",
"=",
"(",
"!",
"$",
"offset",
"||",
"$",
"offset",
"===",
"true",
")",
"?",
"0",
":",
"$",
"offset",
";",
"$",
"this",
"->",
"offsetGet",
"(",
"$",
"offset",
")",
... | Checks to see if a record with the given index key is in the record set. If the record
cannot be found, and not all records have been loaded into the set, it will continue loading
records until either all available records have been loaded, or a matching key has been
found.
@see lithium\data\collection\RecordSet::offsetGet()
@param mixed $offset The ID of the record to check for.
@return boolean Returns true if the record's ID is found in the set, otherwise false. | [
"Checks",
"to",
"see",
"if",
"a",
"record",
"with",
"the",
"given",
"index",
"key",
"is",
"in",
"the",
"record",
"set",
".",
"If",
"the",
"record",
"cannot",
"be",
"found",
"and",
"not",
"all",
"records",
"have",
"been",
"loaded",
"into",
"the",
"set",... | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/collection/MultiKeyRecordSet.php#L60-L67 |
UnionOfRAD/lithium | data/collection/MultiKeyRecordSet.php | MultiKeyRecordSet.offsetGet | public function offsetGet($offset) {
$offset = (!$offset || $offset === true) ? 0 : $offset;
if (in_array($offset, $this->_index)) {
return $this->_data[array_search($offset, $this->_index)];
}
if ($this->closed()) {
return null;
}
if ($model = $this->_model) {
$offsetKey = $model::key($offset);
while ($record = $this->_populate()) {
$curKey = $model::key($record);
$keySet = $offsetKey == $curKey;
if (!is_null($offset) && $keySet) {
return $record;
}
}
}
$this->close();
} | php | public function offsetGet($offset) {
$offset = (!$offset || $offset === true) ? 0 : $offset;
if (in_array($offset, $this->_index)) {
return $this->_data[array_search($offset, $this->_index)];
}
if ($this->closed()) {
return null;
}
if ($model = $this->_model) {
$offsetKey = $model::key($offset);
while ($record = $this->_populate()) {
$curKey = $model::key($record);
$keySet = $offsetKey == $curKey;
if (!is_null($offset) && $keySet) {
return $record;
}
}
}
$this->close();
} | [
"public",
"function",
"offsetGet",
"(",
"$",
"offset",
")",
"{",
"$",
"offset",
"=",
"(",
"!",
"$",
"offset",
"||",
"$",
"offset",
"===",
"true",
")",
"?",
"0",
":",
"$",
"offset",
";",
"if",
"(",
"in_array",
"(",
"$",
"offset",
",",
"$",
"this",... | Gets a record from the record set using PHP's array syntax, i.e. `$records[5]`. Using loose
typing, integer keys can be accessed using strings and vice-versa. For record sets with
composite keys, records may be accessed using arrays as array keys. Note that the order of
the keys in the array does not matter.
Because record data in `RecordSet` is lazy-loaded from the database, new records are fetched
until one with a matching key is found.
@see lithium\data\collection\RecordSet::$_index
@param mixed $offset The offset, or ID (index) of the record you wish to load. If
`$offset` is `null`, all records are loaded into the record set, and
`offsetGet` returns `null`.
@return object Returns a `Record` object if a record is found with a key that matches the
value of `$offset`, otheriwse returns `null`. | [
"Gets",
"a",
"record",
"from",
"the",
"record",
"set",
"using",
"PHP",
"s",
"array",
"syntax",
"i",
".",
"e",
".",
"$records",
"[",
"5",
"]",
".",
"Using",
"loose",
"typing",
"integer",
"keys",
"can",
"be",
"accessed",
"using",
"strings",
"and",
"vice"... | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/collection/MultiKeyRecordSet.php#L85-L106 |
UnionOfRAD/lithium | data/collection/MultiKeyRecordSet.php | MultiKeyRecordSet.offsetUnset | public function offsetUnset($offset) {
$offset = (!$offset || $offset === true) ? 0 : $offset;
$this->offsetGet($offset);
unset($this->_index[$index = array_search($offset, $this->_index)]);
prev($this->_data);
if (key($this->_data) === null) {
$this->rewind();
}
unset($this->_data[$index]);
} | php | public function offsetUnset($offset) {
$offset = (!$offset || $offset === true) ? 0 : $offset;
$this->offsetGet($offset);
unset($this->_index[$index = array_search($offset, $this->_index)]);
prev($this->_data);
if (key($this->_data) === null) {
$this->rewind();
}
unset($this->_data[$index]);
} | [
"public",
"function",
"offsetUnset",
"(",
"$",
"offset",
")",
"{",
"$",
"offset",
"=",
"(",
"!",
"$",
"offset",
"||",
"$",
"offset",
"===",
"true",
")",
"?",
"0",
":",
"$",
"offset",
";",
"$",
"this",
"->",
"offsetGet",
"(",
"$",
"offset",
")",
"... | Assigns a value to the specified offset.
@param integer $offset The offset to assign the value to.
@param mixed $data The value to set.
@return mixed The value which was set. | [
"Assigns",
"a",
"value",
"to",
"the",
"specified",
"offset",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/collection/MultiKeyRecordSet.php#L115-L124 |
UnionOfRAD/lithium | data/collection/MultiKeyRecordSet.php | MultiKeyRecordSet.to | public function to($format, array $options = []) {
$default = ['indexed' => true];
$options += $default;
$options['internal'] = !$options['indexed'];
unset($options['indexed']);
$this->offsetGet(null);
if (!$options['internal'] && !is_scalar(current($this->_index))) {
$options['internal'] = true;
}
return parent::to($format, $options);
} | php | public function to($format, array $options = []) {
$default = ['indexed' => true];
$options += $default;
$options['internal'] = !$options['indexed'];
unset($options['indexed']);
$this->offsetGet(null);
if (!$options['internal'] && !is_scalar(current($this->_index))) {
$options['internal'] = true;
}
return parent::to($format, $options);
} | [
"public",
"function",
"to",
"(",
"$",
"format",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"default",
"=",
"[",
"'indexed'",
"=>",
"true",
"]",
";",
"$",
"options",
"+=",
"$",
"default",
";",
"$",
"options",
"[",
"'internal'",
"]",... | Converts the data in the record set to a different format, i.e. an array.
@param string $format
@param array $options
@return mixed | [
"Converts",
"the",
"data",
"in",
"the",
"record",
"set",
"to",
"a",
"different",
"format",
"i",
".",
"e",
".",
"an",
"array",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/collection/MultiKeyRecordSet.php#L160-L171 |
UnionOfRAD/lithium | data/collection/MultiKeyRecordSet.php | MultiKeyRecordSet.find | public function find($filter, array $options = []) {
$this->offsetGet(null);
return parent::find($filter, $options);
} | php | public function find($filter, array $options = []) {
$this->offsetGet(null);
return parent::find($filter, $options);
} | [
"public",
"function",
"find",
"(",
"$",
"filter",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"offsetGet",
"(",
"null",
")",
";",
"return",
"parent",
"::",
"find",
"(",
"$",
"filter",
",",
"$",
"options",
")",
";",
"... | Filters a copy of the items in the collection.
Overridden to load any data that has not yet been loaded.
@param callback $filter Callback to use for filtering.
@param array $options The available options are:
- `'collect'`: If `true`, the results will be returned wrapped
in a new `Collection` object or subclass.
@return mixed The filtered items. Will be an array unless `'collect'` is defined in the
`$options` argument, then an instance of this class will be returned. | [
"Filters",
"a",
"copy",
"of",
"the",
"items",
"in",
"the",
"collection",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/collection/MultiKeyRecordSet.php#L198-L201 |
UnionOfRAD/lithium | data/collection/MultiKeyRecordSet.php | MultiKeyRecordSet.map | public function map($filter, array $options = []) {
$this->offsetGet(null);
return parent::map($filter, $options);
} | php | public function map($filter, array $options = []) {
$this->offsetGet(null);
return parent::map($filter, $options);
} | [
"public",
"function",
"map",
"(",
"$",
"filter",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"offsetGet",
"(",
"null",
")",
";",
"return",
"parent",
"::",
"map",
"(",
"$",
"filter",
",",
"$",
"options",
")",
";",
"}"... | Applies a callback to a copy of all data in the collection
and returns the result.
Overriden to load any data that has not yet been loaded.
@param callback $filter The filter to apply.
@param array $options The available options are:
- `'collect'`: If `true`, the results will be returned wrapped
in a new `Collection` object or subclass.
@return object The filtered data. | [
"Applies",
"a",
"callback",
"to",
"a",
"copy",
"of",
"all",
"data",
"in",
"the",
"collection",
"and",
"returns",
"the",
"result",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/collection/MultiKeyRecordSet.php#L215-L218 |
UnionOfRAD/lithium | data/collection/MultiKeyRecordSet.php | MultiKeyRecordSet._keyIndex | protected function _keyIndex() {
if (!($model = $this->_model) || !isset($this->_columns[''])) {
return [];
}
$index = 0;
foreach ($this->_columns as $name => $fields) {
if ($name === '') {
$flip = array_flip($fields);
$keys = array_flip($model::meta('key'));
$keys = array_intersect_key($flip, $keys);
foreach ($keys as &$key) {
$key += $index;
}
return array_flip($keys);
}
$index += count($fields);
}
return [];
} | php | protected function _keyIndex() {
if (!($model = $this->_model) || !isset($this->_columns[''])) {
return [];
}
$index = 0;
foreach ($this->_columns as $name => $fields) {
if ($name === '') {
$flip = array_flip($fields);
$keys = array_flip($model::meta('key'));
$keys = array_intersect_key($flip, $keys);
foreach ($keys as &$key) {
$key += $index;
}
return array_flip($keys);
}
$index += count($fields);
}
return [];
} | [
"protected",
"function",
"_keyIndex",
"(",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"model",
"=",
"$",
"this",
"->",
"_model",
")",
"||",
"!",
"isset",
"(",
"$",
"this",
"->",
"_columns",
"[",
"''",
"]",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
... | Extracts the numerical indices of the primary keys in numerical indexed row data.
Works only for the main row data and not for relationship rows.
This method will also correctly detect primary keys which don't come
first or are in sequential order.
@return array An array where key are index and value are primary key fieldname. | [
"Extracts",
"the",
"numerical",
"indices",
"of",
"the",
"primary",
"keys",
"in",
"numerical",
"indexed",
"row",
"data",
".",
"Works",
"only",
"for",
"the",
"main",
"row",
"data",
"and",
"not",
"for",
"relationship",
"rows",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/collection/MultiKeyRecordSet.php#L256-L277 |
UnionOfRAD/lithium | analysis/Parser.php | Parser.token | public static function token($string, array $options = []) {
$defaults = ['id' => false];
$options += $defaults;
if (empty($string) && $string !== '0') {
return false;
}
list($token) = static::tokenize($string);
return $token[($options['id']) ? 'id' : 'name'];
} | php | public static function token($string, array $options = []) {
$defaults = ['id' => false];
$options += $defaults;
if (empty($string) && $string !== '0') {
return false;
}
list($token) = static::tokenize($string);
return $token[($options['id']) ? 'id' : 'name'];
} | [
"public",
"static",
"function",
"token",
"(",
"$",
"string",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'id'",
"=>",
"false",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"if",
"(",
"empty",
"(",
"... | Convenience method to get the token name of a PHP code string. If multiple tokens are
present in the string, only the first is returned.
@param string $string String of PHP code to get the token name of, i.e. `'=>'` or `'static'`.
@param array $options
@return mixed | [
"Convenience",
"method",
"to",
"get",
"the",
"token",
"name",
"of",
"a",
"PHP",
"code",
"string",
".",
"If",
"multiple",
"tokens",
"are",
"present",
"in",
"the",
"string",
"only",
"the",
"first",
"is",
"returned",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/Parser.php#L29-L38 |
UnionOfRAD/lithium | analysis/Parser.php | Parser.tokenize | public static function tokenize($code, array $options = []) {
$defaults = ['wrap' => true, 'ignore' => [], 'include' => []];
$options += $defaults;
$tokens = [];
$line = 1;
if ($options['wrap']) {
$code = "<?php {$code}?>";
}
foreach (token_get_all($code) as $token) {
$token = (isset($token[1])) ? $token : [null, $token, $line];
list($id, $content, $line) = $token;
$name = $id ? token_name($id) : $content;
if (!empty($options['include'])) {
if (!in_array($name, $options['include']) && !in_array($id, $options['include'])) {
continue;
}
}
if (!empty($options['ignore'])) {
if (in_array($name, $options['ignore']) || in_array($id, $options['ignore'])) {
continue;
}
}
$tokens[] = ['id' => $id, 'name' => $name, 'content' => $content, 'line' => $line];
$line += count(preg_split('/\r\n|\r|\n/', $content)) - 1;
}
if ($options['wrap'] && empty($options['include'])) {
$tokens = array_slice($tokens, 1, count($tokens) - 2);
}
return $tokens;
} | php | public static function tokenize($code, array $options = []) {
$defaults = ['wrap' => true, 'ignore' => [], 'include' => []];
$options += $defaults;
$tokens = [];
$line = 1;
if ($options['wrap']) {
$code = "<?php {$code}?>";
}
foreach (token_get_all($code) as $token) {
$token = (isset($token[1])) ? $token : [null, $token, $line];
list($id, $content, $line) = $token;
$name = $id ? token_name($id) : $content;
if (!empty($options['include'])) {
if (!in_array($name, $options['include']) && !in_array($id, $options['include'])) {
continue;
}
}
if (!empty($options['ignore'])) {
if (in_array($name, $options['ignore']) || in_array($id, $options['ignore'])) {
continue;
}
}
$tokens[] = ['id' => $id, 'name' => $name, 'content' => $content, 'line' => $line];
$line += count(preg_split('/\r\n|\r|\n/', $content)) - 1;
}
if ($options['wrap'] && empty($options['include'])) {
$tokens = array_slice($tokens, 1, count($tokens) - 2);
}
return $tokens;
} | [
"public",
"static",
"function",
"tokenize",
"(",
"$",
"code",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'wrap'",
"=>",
"true",
",",
"'ignore'",
"=>",
"[",
"]",
",",
"'include'",
"=>",
"[",
"]",
"]",
";",
"... | Splits the provided `$code` into PHP language tokens.
@param string $code Source code to be tokenized.
@param array $options Options consists of:
-'wrap': Boolean indicating whether or not to wrap the supplied
code in PHP tags.
-'ignore': An array containing PHP language tokens to ignore.
-'include': If supplied, an array of the only language tokens
to include in the output.
@return array An array of tokens in the supplied source code. | [
"Splits",
"the",
"provided",
"$code",
"into",
"PHP",
"language",
"tokens",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/Parser.php#L52-L86 |
UnionOfRAD/lithium | analysis/Parser.php | Parser.find | public static function find($code, $pattern, array $options = []) {
$defaults = [
'all' => true, 'capture' => [], 'ignore' => ['T_WHITESPACE'],
'return' => true, 'lineBreaks' => false, 'startOfLine' => false
];
$options += $defaults;
$results = [];
$matches = [];
$patternMatch = [];
$ret = $options['return'];
$tokens = new Collection(['data' => static::tokenize($code, $options)]);
$pattern = new Collection(['data' => static::tokenize($pattern, $options)]);
$breaks = function($token) use (&$tokens, &$matches, &$patternMatch, $options) {
if (!$options['lineBreaks']) {
return true;
}
if (empty($patternMatch) && !$options['startOfLine']) {
return true;
}
if (empty($patternMatch)) {
$prev = $tokens->prev();
$tokens->next();
} else {
$prev = reset($patternMatch);
}
if (empty($patternMatch) && $options['startOfLine']) {
return ($token['line'] > $prev['line']);
}
return ($token['line'] === $prev['line']);
};
$capture = function($token) use (&$matches, &$patternMatch, $tokens, $breaks, $options) {
if ($token === null) {
$matches = $patternMatch = [];
return false;
}
if (empty($patternMatch)) {
$prev = $tokens->prev();
$tokens->next();
if ($options['startOfLine'] && $token['line'] === $prev['line']) {
$patternMatch = $matches = [];
return false;
}
}
$patternMatch[] = $token;
if (empty($options['capture']) || !in_array($token['name'], $options['capture'])) {
return true;
}
if (!$breaks($token)) {
$matches = [];
return true;
}
$matches[] = $token;
return true;
};
$executors = [
'*' => function(&$tokens, &$pattern) use ($options, $capture) {
$closing = $pattern->next();
$tokens->prev();
while (($t = $tokens->next()) && !Parser::matchToken($closing, $t)) {
$capture($t);
}
$pattern->next();
}
];
$tokens->rewind();
$pattern->rewind();
while ($tokens->valid()) {
if (!$pattern->valid()) {
$pattern->rewind();
if (!empty($matches)) {
$results[] = array_map(
function($i) use ($ret) { return isset($i[$ret]) ? $i[$ret] : $i; },
$matches
);
}
$capture(null);
}
$p = $pattern->current();
$t = $tokens->current();
switch (true) {
case (static::matchToken($p, $t)):
$capture($t) ? $pattern->next() : $pattern->rewind();
break;
case (isset($executors[$p['name']])):
$exec = $executors[$p['name']];
$exec($tokens, $pattern);
break;
default:
$capture(null);
$pattern->rewind();
break;
}
$tokens->next();
}
return $results;
} | php | public static function find($code, $pattern, array $options = []) {
$defaults = [
'all' => true, 'capture' => [], 'ignore' => ['T_WHITESPACE'],
'return' => true, 'lineBreaks' => false, 'startOfLine' => false
];
$options += $defaults;
$results = [];
$matches = [];
$patternMatch = [];
$ret = $options['return'];
$tokens = new Collection(['data' => static::tokenize($code, $options)]);
$pattern = new Collection(['data' => static::tokenize($pattern, $options)]);
$breaks = function($token) use (&$tokens, &$matches, &$patternMatch, $options) {
if (!$options['lineBreaks']) {
return true;
}
if (empty($patternMatch) && !$options['startOfLine']) {
return true;
}
if (empty($patternMatch)) {
$prev = $tokens->prev();
$tokens->next();
} else {
$prev = reset($patternMatch);
}
if (empty($patternMatch) && $options['startOfLine']) {
return ($token['line'] > $prev['line']);
}
return ($token['line'] === $prev['line']);
};
$capture = function($token) use (&$matches, &$patternMatch, $tokens, $breaks, $options) {
if ($token === null) {
$matches = $patternMatch = [];
return false;
}
if (empty($patternMatch)) {
$prev = $tokens->prev();
$tokens->next();
if ($options['startOfLine'] && $token['line'] === $prev['line']) {
$patternMatch = $matches = [];
return false;
}
}
$patternMatch[] = $token;
if (empty($options['capture']) || !in_array($token['name'], $options['capture'])) {
return true;
}
if (!$breaks($token)) {
$matches = [];
return true;
}
$matches[] = $token;
return true;
};
$executors = [
'*' => function(&$tokens, &$pattern) use ($options, $capture) {
$closing = $pattern->next();
$tokens->prev();
while (($t = $tokens->next()) && !Parser::matchToken($closing, $t)) {
$capture($t);
}
$pattern->next();
}
];
$tokens->rewind();
$pattern->rewind();
while ($tokens->valid()) {
if (!$pattern->valid()) {
$pattern->rewind();
if (!empty($matches)) {
$results[] = array_map(
function($i) use ($ret) { return isset($i[$ret]) ? $i[$ret] : $i; },
$matches
);
}
$capture(null);
}
$p = $pattern->current();
$t = $tokens->current();
switch (true) {
case (static::matchToken($p, $t)):
$capture($t) ? $pattern->next() : $pattern->rewind();
break;
case (isset($executors[$p['name']])):
$exec = $executors[$p['name']];
$exec($tokens, $pattern);
break;
default:
$capture(null);
$pattern->rewind();
break;
}
$tokens->next();
}
return $results;
} | [
"public",
"static",
"function",
"find",
"(",
"$",
"code",
",",
"$",
"pattern",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'all'",
"=>",
"true",
",",
"'capture'",
"=>",
"[",
"]",
",",
"'ignore'",
"=>",
"[",
... | Finds a pattern in a block of code.
@param string $code
@param string $pattern
@param array $options The list of options to be used when parsing / matching `$code`:
- 'ignore': An array of token names to ignore while parsing, defaults to
`array('T_WHITESPACE')`
- 'lineBreaks': If true, all tokens in a single pattern match must appear on the
same line of code, defaults to false
- 'startOfLine': If true, the pattern must match starting with the beginning of
the line of code to be matched, defaults to false
@return array | [
"Finds",
"a",
"pattern",
"in",
"a",
"block",
"of",
"code",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/Parser.php#L102-L211 |
UnionOfRAD/lithium | analysis/Parser.php | Parser.match | public static function match($code, $parameters, array $options = []) {
$defaults = ['ignore' => ['T_WHITESPACE'], 'return' => true];
$options += $defaults;
$parameters = static::_prepareMatchParams($parameters);
$tokens = is_array($code) ? $code : static::tokenize($code, $options);
$results = [];
foreach ($tokens as $i => $token) {
if (!array_key_exists($token['name'], $parameters)) {
if (!in_array('*', $parameters)) {
continue;
}
}
$param = $parameters[$token['name']];
if (isset($param['before']) && $i > 0) {
if (!in_array($tokens[$i - 1]['name'], (array) $param['before'])) {
continue;
}
}
if (isset($param['after']) && $i + 1 < count($tokens)) {
if (!in_array($tokens[$i + 1]['name'], (array) $param['after'])) {
continue;
}
}
$results[] = isset($token[$options['return']]) ? $token[$options['return']] : $token;
}
return $results;
} | php | public static function match($code, $parameters, array $options = []) {
$defaults = ['ignore' => ['T_WHITESPACE'], 'return' => true];
$options += $defaults;
$parameters = static::_prepareMatchParams($parameters);
$tokens = is_array($code) ? $code : static::tokenize($code, $options);
$results = [];
foreach ($tokens as $i => $token) {
if (!array_key_exists($token['name'], $parameters)) {
if (!in_array('*', $parameters)) {
continue;
}
}
$param = $parameters[$token['name']];
if (isset($param['before']) && $i > 0) {
if (!in_array($tokens[$i - 1]['name'], (array) $param['before'])) {
continue;
}
}
if (isset($param['after']) && $i + 1 < count($tokens)) {
if (!in_array($tokens[$i + 1]['name'], (array) $param['after'])) {
continue;
}
}
$results[] = isset($token[$options['return']]) ? $token[$options['return']] : $token;
}
return $results;
} | [
"public",
"static",
"function",
"match",
"(",
"$",
"code",
",",
"$",
"parameters",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'ignore'",
"=>",
"[",
"'T_WHITESPACE'",
"]",
",",
"'return'",
"=>",
"true",
"]",
";"... | Token pattern matching.
@param string $code Source code to be analyzed.
@param string $parameters An array containing token patterns to be matched.
@param array $options The list of options to be used when matching `$code`:
- 'ignore': An array of language tokens to ignore.
- 'return': If set to 'content' returns an array of matching tokens.
@return array Array of matching tokens. | [
"Token",
"pattern",
"matching",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/Parser.php#L223-L253 |
UnionOfRAD/lithium | analysis/Parser.php | Parser.matchToken | public static function matchToken($pattern, $token) {
if ($pattern['name'] !== $token['name']) {
return false;
}
if (!isset($pattern['content'])) {
return true;
}
$match = $pattern['content'];
$content = $token['content'];
if ($pattern['name'] === 'T_VARIABLE') {
$match = substr($match, 1);
$content = substr($content, 1);
}
switch (true) {
case ($match === '_' || $match === $content):
return true;
}
return false;
} | php | public static function matchToken($pattern, $token) {
if ($pattern['name'] !== $token['name']) {
return false;
}
if (!isset($pattern['content'])) {
return true;
}
$match = $pattern['content'];
$content = $token['content'];
if ($pattern['name'] === 'T_VARIABLE') {
$match = substr($match, 1);
$content = substr($content, 1);
}
switch (true) {
case ($match === '_' || $match === $content):
return true;
}
return false;
} | [
"public",
"static",
"function",
"matchToken",
"(",
"$",
"pattern",
",",
"$",
"token",
")",
"{",
"if",
"(",
"$",
"pattern",
"[",
"'name'",
"]",
"!==",
"$",
"token",
"[",
"'name'",
"]",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"isset",
... | Compares two PHP language tokens.
@param array $pattern Pattern token.
@param array $token Token to be compared.
@return boolean Match result. | [
"Compares",
"two",
"PHP",
"language",
"tokens",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/Parser.php#L262-L284 |
UnionOfRAD/lithium | analysis/Parser.php | Parser._prepareMatchParams | protected static function _prepareMatchParams($parameters) {
foreach (Set::normalize($parameters) as $token => $scope) {
if (strpos($token, 'T_') !== 0) {
unset($parameters[$token]);
foreach (['before', 'after'] as $key) {
if (!isset($scope[$key])) {
continue;
}
$items = [];
foreach ((array) $scope[$key] as $item) {
$items[] = (strpos($item, 'T_') !== 0) ? static::token($item) : $item;
}
$scope[$key] = $items;
}
$parameters[static::token($token)] = $scope;
}
}
return $parameters;
} | php | protected static function _prepareMatchParams($parameters) {
foreach (Set::normalize($parameters) as $token => $scope) {
if (strpos($token, 'T_') !== 0) {
unset($parameters[$token]);
foreach (['before', 'after'] as $key) {
if (!isset($scope[$key])) {
continue;
}
$items = [];
foreach ((array) $scope[$key] as $item) {
$items[] = (strpos($item, 'T_') !== 0) ? static::token($item) : $item;
}
$scope[$key] = $items;
}
$parameters[static::token($token)] = $scope;
}
}
return $parameters;
} | [
"protected",
"static",
"function",
"_prepareMatchParams",
"(",
"$",
"parameters",
")",
"{",
"foreach",
"(",
"Set",
"::",
"normalize",
"(",
"$",
"parameters",
")",
"as",
"$",
"token",
"=>",
"$",
"scope",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"token",
... | Helper function to normalize parameters for token matching.
@see lithium\analysis\Parser::match()
@param array|string $parameters Params to be normalized.
@return array Normalized parameters. | [
"Helper",
"function",
"to",
"normalize",
"parameters",
"for",
"token",
"matching",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/Parser.php#L293-L313 |
UnionOfRAD/lithium | analysis/Inspector.php | Inspector.isCallable | public static function isCallable($object, $method, $internal = false) {
$methodExists = method_exists($object, $method);
return $internal ? $methodExists : $methodExists && is_callable([$object, $method]);
} | php | public static function isCallable($object, $method, $internal = false) {
$methodExists = method_exists($object, $method);
return $internal ? $methodExists : $methodExists && is_callable([$object, $method]);
} | [
"public",
"static",
"function",
"isCallable",
"(",
"$",
"object",
",",
"$",
"method",
",",
"$",
"internal",
"=",
"false",
")",
"{",
"$",
"methodExists",
"=",
"method_exists",
"(",
"$",
"object",
",",
"$",
"method",
")",
";",
"return",
"$",
"internal",
... | Determines if a given method can be called on an object/class.
@param string|object $object Class or instance to inspect.
@param string $method Name of the method.
@param boolean $internal Should be `true` if you want to check from inside the
class/object. When `false` will also check 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",
"on",
"an",
"object",
"/",
"class",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/Inspector.php#L64-L67 |
UnionOfRAD/lithium | analysis/Inspector.php | Inspector.type | public static function type($identifier) {
$identifier = ltrim($identifier, '\\');
if (strpos($identifier, '::')) {
return (strpos($identifier, '$') !== false) ? 'property' : 'method';
}
if (is_readable(Libraries::path($identifier))) {
if (class_exists($identifier) && in_array($identifier, get_declared_classes())) {
return 'class';
}
}
return 'namespace';
} | php | public static function type($identifier) {
$identifier = ltrim($identifier, '\\');
if (strpos($identifier, '::')) {
return (strpos($identifier, '$') !== false) ? 'property' : 'method';
}
if (is_readable(Libraries::path($identifier))) {
if (class_exists($identifier) && in_array($identifier, get_declared_classes())) {
return 'class';
}
}
return 'namespace';
} | [
"public",
"static",
"function",
"type",
"(",
"$",
"identifier",
")",
"{",
"$",
"identifier",
"=",
"ltrim",
"(",
"$",
"identifier",
",",
"'\\\\'",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"identifier",
",",
"'::'",
")",
")",
"{",
"return",
"(",
"strpo... | Determines if a given $identifier is a class property, a class method, a class itself,
or a namespace identifier.
@param string $identifier The identifier to be analyzed
@return string Identifier type. One of `property`, `method`, `class` or `namespace`. | [
"Determines",
"if",
"a",
"given",
"$identifier",
"is",
"a",
"class",
"property",
"a",
"class",
"method",
"a",
"class",
"itself",
"or",
"a",
"namespace",
"identifier",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/Inspector.php#L76-L88 |
UnionOfRAD/lithium | analysis/Inspector.php | Inspector.info | public static function info($identifier, $info = []) {
$info = $info ?: array_keys(static::$_methodMap);
$type = static::type($identifier);
$result = [];
$class = null;
if ($type === 'method' || $type === 'property') {
list($class, $identifier) = explode('::', $identifier);
try {
$classInspector = new ReflectionClass($class);
} catch (Exception $e) {
return null;
}
if ($type === 'property') {
$identifier = substr($identifier, 1);
$accessor = 'getProperty';
} else {
$identifier = str_replace('()', '', $identifier);
$accessor = 'getMethod';
}
try {
$inspector = $classInspector->{$accessor}($identifier);
} catch (Exception $e) {
return null;
}
$result['modifiers'] = static::_modifiers($inspector);
} elseif ($type === 'class') {
$inspector = new ReflectionClass($identifier);
$classInspector = null;
} else {
return null;
}
foreach ($info as $key) {
if (!isset(static::$_methodMap[$key])) {
continue;
}
if (method_exists($inspector, static::$_methodMap[$key])) {
$setAccess = (
($type === 'method' || $type === 'property') &&
array_intersect($result['modifiers'], ['private', 'protected']) !== [] &&
method_exists($inspector, 'setAccessible')
);
if ($setAccess) {
$inspector->setAccessible(true);
}
$result[$key] = $inspector->{static::$_methodMap[$key]}();
if ($setAccess) {
$inspector->setAccessible(false);
}
}
}
if ($type === 'property' && $classInspector && !$classInspector->isAbstract()) {
$inspector->setAccessible(true);
try {
$result['value'] = $inspector->getValue(static::_class($class));
} catch (Exception $e) {
return null;
}
}
if (isset($result['start']) && isset($result['end'])) {
$result['length'] = $result['end'] - $result['start'];
}
if (isset($result['comment'])) {
$result += Docblock::comment($result['comment']);
}
return $result;
} | php | public static function info($identifier, $info = []) {
$info = $info ?: array_keys(static::$_methodMap);
$type = static::type($identifier);
$result = [];
$class = null;
if ($type === 'method' || $type === 'property') {
list($class, $identifier) = explode('::', $identifier);
try {
$classInspector = new ReflectionClass($class);
} catch (Exception $e) {
return null;
}
if ($type === 'property') {
$identifier = substr($identifier, 1);
$accessor = 'getProperty';
} else {
$identifier = str_replace('()', '', $identifier);
$accessor = 'getMethod';
}
try {
$inspector = $classInspector->{$accessor}($identifier);
} catch (Exception $e) {
return null;
}
$result['modifiers'] = static::_modifiers($inspector);
} elseif ($type === 'class') {
$inspector = new ReflectionClass($identifier);
$classInspector = null;
} else {
return null;
}
foreach ($info as $key) {
if (!isset(static::$_methodMap[$key])) {
continue;
}
if (method_exists($inspector, static::$_methodMap[$key])) {
$setAccess = (
($type === 'method' || $type === 'property') &&
array_intersect($result['modifiers'], ['private', 'protected']) !== [] &&
method_exists($inspector, 'setAccessible')
);
if ($setAccess) {
$inspector->setAccessible(true);
}
$result[$key] = $inspector->{static::$_methodMap[$key]}();
if ($setAccess) {
$inspector->setAccessible(false);
}
}
}
if ($type === 'property' && $classInspector && !$classInspector->isAbstract()) {
$inspector->setAccessible(true);
try {
$result['value'] = $inspector->getValue(static::_class($class));
} catch (Exception $e) {
return null;
}
}
if (isset($result['start']) && isset($result['end'])) {
$result['length'] = $result['end'] - $result['start'];
}
if (isset($result['comment'])) {
$result += Docblock::comment($result['comment']);
}
return $result;
} | [
"public",
"static",
"function",
"info",
"(",
"$",
"identifier",
",",
"$",
"info",
"=",
"[",
"]",
")",
"{",
"$",
"info",
"=",
"$",
"info",
"?",
":",
"array_keys",
"(",
"static",
"::",
"$",
"_methodMap",
")",
";",
"$",
"type",
"=",
"static",
"::",
... | Detailed source code identifier analysis.
Analyzes a passed $identifier for more detailed information such
as method/property modifiers (e.g. `public`, `private`, `abstract`)
@param string $identifier The identifier to be analyzed
@param array $info Optionally restrict or expand the default information
returned from the `info` method. By default, the information returned
is the same as the array keys contained in the `$_methodMap` property of
Inspector.
@return array An array of the parsed meta-data information of the given identifier. | [
"Detailed",
"source",
"code",
"identifier",
"analysis",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/Inspector.php#L103-L178 |
UnionOfRAD/lithium | analysis/Inspector.php | Inspector.executable | public static function executable($class, array $options = []) {
$defaults = [
'self' => true,
'filter' => true,
'methods' => [],
'empty' => [' ', "\t", '}', ')', ';'],
'pattern' => null,
'blockOpeners' => ['switch (', 'try {', '} else {', 'do {', '} while']
];
$options += $defaults;
if (empty($options['pattern']) && $options['filter']) {
$pattern = str_replace(' ', '\s*', join('|', array_map(
function($str) { return preg_quote($str, '/'); },
$options['blockOpeners']
)));
$pattern = join('|', [
"({$pattern})",
"\\$(.+)\($",
"\s*['\"]\w+['\"]\s*=>\s*.+[\{\(]$",
"\s*['\"]\w+['\"]\s*=>\s*['\"]*.+['\"]*\s*"
]);
$options['pattern'] = "/^({$pattern})/";
}
if (!$class instanceof ReflectionClass) {
$class = new ReflectionClass(is_object($class) ? get_class($class) : $class);
}
$options += ['group' => false];
$result = array_filter(static::methods($class, 'ranges', $options));
if ($options['filter'] && $class->getFileName() && $result) {
$lines = static::lines($class->getFileName(), $result);
$start = key($lines);
$code = implode("\n", $lines);
$tokens = token_get_all('<' . '?php' . $code);
$tmp = [];
foreach ($tokens as $token) {
if (is_array($token)) {
if (!in_array($token[0], [T_COMMENT, T_DOC_COMMENT, T_WHITESPACE])) {
$tmp[] = $token[2];
}
}
}
$filteredLines = array_values(array_map(
function($ln) use ($start) { return $ln + $start - 1; },
array_unique($tmp))
);
$lines = array_intersect_key($lines, array_flip($filteredLines));
$result = array_keys(array_filter($lines, function($line) use ($options) {
$line = trim($line);
$empty = preg_match($options['pattern'], $line);
return $empty ? false : (str_replace($options['empty'], '', $line) !== '');
}));
}
return $result;
} | php | public static function executable($class, array $options = []) {
$defaults = [
'self' => true,
'filter' => true,
'methods' => [],
'empty' => [' ', "\t", '}', ')', ';'],
'pattern' => null,
'blockOpeners' => ['switch (', 'try {', '} else {', 'do {', '} while']
];
$options += $defaults;
if (empty($options['pattern']) && $options['filter']) {
$pattern = str_replace(' ', '\s*', join('|', array_map(
function($str) { return preg_quote($str, '/'); },
$options['blockOpeners']
)));
$pattern = join('|', [
"({$pattern})",
"\\$(.+)\($",
"\s*['\"]\w+['\"]\s*=>\s*.+[\{\(]$",
"\s*['\"]\w+['\"]\s*=>\s*['\"]*.+['\"]*\s*"
]);
$options['pattern'] = "/^({$pattern})/";
}
if (!$class instanceof ReflectionClass) {
$class = new ReflectionClass(is_object($class) ? get_class($class) : $class);
}
$options += ['group' => false];
$result = array_filter(static::methods($class, 'ranges', $options));
if ($options['filter'] && $class->getFileName() && $result) {
$lines = static::lines($class->getFileName(), $result);
$start = key($lines);
$code = implode("\n", $lines);
$tokens = token_get_all('<' . '?php' . $code);
$tmp = [];
foreach ($tokens as $token) {
if (is_array($token)) {
if (!in_array($token[0], [T_COMMENT, T_DOC_COMMENT, T_WHITESPACE])) {
$tmp[] = $token[2];
}
}
}
$filteredLines = array_values(array_map(
function($ln) use ($start) { return $ln + $start - 1; },
array_unique($tmp))
);
$lines = array_intersect_key($lines, array_flip($filteredLines));
$result = array_keys(array_filter($lines, function($line) use ($options) {
$line = trim($line);
$empty = preg_match($options['pattern'], $line);
return $empty ? false : (str_replace($options['empty'], '', $line) !== '');
}));
}
return $result;
} | [
"public",
"static",
"function",
"executable",
"(",
"$",
"class",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'self'",
"=>",
"true",
",",
"'filter'",
"=>",
"true",
",",
"'methods'",
"=>",
"[",
"]",
",",
"'empty'"... | Gets the executable lines of a class, by examining the start and end lines of each method.
@param mixed $class Class name as a string or object instance.
@param array $options Set of options:
- `'self'` _boolean_: If `true` (default), only returns lines of methods defined in
`$class`, excluding methods from inherited classes.
- `'methods'` _array_: An arbitrary list of methods to search, as a string (single
method name) or array of method names.
- `'filter'` _boolean_: If `true`, filters out lines containing only whitespace or
braces. Note: for some reason, the Zend engine does not report `switch` and `try`
statements as executable lines, as well as parts of multi-line assignment
statements, so they are filtered out as well.
@return array Returns an array of the executable line numbers of the class. | [
"Gets",
"the",
"executable",
"lines",
"of",
"a",
"class",
"by",
"examining",
"the",
"start",
"and",
"end",
"lines",
"of",
"each",
"method",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/Inspector.php#L195-L256 |
UnionOfRAD/lithium | analysis/Inspector.php | Inspector.methods | public static function methods($class, $format = null, array $options = []) {
$defaults = ['methods' => [], 'group' => true, 'self' => true];
$options += $defaults;
if (!(is_object($class) && $class instanceof ReflectionClass)) {
try {
$class = new ReflectionClass($class);
} catch (ReflectionException $e) {
return null;
}
}
$options += ['names' => $options['methods']];
$methods = static::_items($class, 'getMethods', $options);
$result = [];
switch ($format) {
case null:
return $methods;
case 'extents':
if ($methods->getName() === []) {
return [];
}
$extents = function($start, $end) { return [$start, $end]; };
$result = array_combine($methods->getName(), array_map(
$extents, $methods->getStartLine(), $methods->getEndLine()
));
break;
case 'ranges':
$ranges = function($lines) {
list($start, $end) = $lines;
return ($end <= $start + 1) ? [] : range($start + 1, $end - 1);
};
$result = array_map($ranges, static::methods(
$class, 'extents', ['group' => true] + $options
));
break;
}
if ($options['group']) {
return $result;
}
$tmp = $result;
$result = [];
array_map(function($ln) use (&$result) { $result = array_merge($result, $ln); }, $tmp);
return $result;
} | php | public static function methods($class, $format = null, array $options = []) {
$defaults = ['methods' => [], 'group' => true, 'self' => true];
$options += $defaults;
if (!(is_object($class) && $class instanceof ReflectionClass)) {
try {
$class = new ReflectionClass($class);
} catch (ReflectionException $e) {
return null;
}
}
$options += ['names' => $options['methods']];
$methods = static::_items($class, 'getMethods', $options);
$result = [];
switch ($format) {
case null:
return $methods;
case 'extents':
if ($methods->getName() === []) {
return [];
}
$extents = function($start, $end) { return [$start, $end]; };
$result = array_combine($methods->getName(), array_map(
$extents, $methods->getStartLine(), $methods->getEndLine()
));
break;
case 'ranges':
$ranges = function($lines) {
list($start, $end) = $lines;
return ($end <= $start + 1) ? [] : range($start + 1, $end - 1);
};
$result = array_map($ranges, static::methods(
$class, 'extents', ['group' => true] + $options
));
break;
}
if ($options['group']) {
return $result;
}
$tmp = $result;
$result = [];
array_map(function($ln) use (&$result) { $result = array_merge($result, $ln); }, $tmp);
return $result;
} | [
"public",
"static",
"function",
"methods",
"(",
"$",
"class",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'methods'",
"=>",
"[",
"]",
",",
"'group'",
"=>",
"true",
",",
"'self'... | Returns various information on the methods of an object, in different formats.
@param string|object $class A string class name for purely static classes or an object
instance, from which to get methods.
@param string $format The type and format of data to return. Available options are:
- `null`: Returns a `Collection` object containing a `ReflectionMethod` instance
for each method.
- `'extents'`: Returns a two-dimensional array with method names as keys, and
an array with starting and ending line numbers as values.
- `'ranges'`: Returns a two-dimensional array where each key is a method name,
and each value is an array of line numbers which are contained in the method.
@param array $options Set of options applied directly (check `_items()` for more options):
- `'methods'` _array_: An arbitrary list of methods to search, as a string (single
method name) or array of method names.
- `'group'`: If true (default) the array is grouped by context (ex.: method name), if
false the results are sequentially appended to an array.
-'self': If true (default), only returns properties defined in `$class`,
excluding properties from inherited classes.
@return mixed Return value depends on the $format given:
- `null` on failure.
- `lithium\util\Collection` if $format is `null`
- `array` if $format is either `'extends'` or `'ranges'`. | [
"Returns",
"various",
"information",
"on",
"the",
"methods",
"of",
"an",
"object",
"in",
"different",
"formats",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/Inspector.php#L282-L329 |
UnionOfRAD/lithium | analysis/Inspector.php | Inspector.properties | public static function properties($class, array $options = []) {
$defaults = ['properties' => [], 'self' => true];
$options += $defaults;
try {
$reflClass = new ReflectionClass($class);
} catch (ReflectionException $e) {
return null;
}
$options += ['names' => $options['properties']];
return static::_items($reflClass, 'getProperties', $options)->map(function($item) use ($class) {
$modifiers = array_values(Inspector::invokeMethod('_modifiers', [$item]));
$setAccess = (
array_intersect($modifiers, ['private', 'protected']) !== []
);
if ($setAccess) {
$item->setAccessible(true);
}
if (is_string($class)) {
if (!$item->isStatic()) {
$message = 'Must provide an object instance for non-static properties.';
throw new InvalidArgumentException($message);
}
$value = $item->getValue($item->getDeclaringClass());
} else {
$value = $item->getValue($class);
}
$result = compact('modifiers', 'value') + [
'docComment' => $item->getDocComment(),
'name' => $item->getName()
];
if ($setAccess) {
$item->setAccessible(false);
}
return $result;
}, ['collect' => false]);
} | php | public static function properties($class, array $options = []) {
$defaults = ['properties' => [], 'self' => true];
$options += $defaults;
try {
$reflClass = new ReflectionClass($class);
} catch (ReflectionException $e) {
return null;
}
$options += ['names' => $options['properties']];
return static::_items($reflClass, 'getProperties', $options)->map(function($item) use ($class) {
$modifiers = array_values(Inspector::invokeMethod('_modifiers', [$item]));
$setAccess = (
array_intersect($modifiers, ['private', 'protected']) !== []
);
if ($setAccess) {
$item->setAccessible(true);
}
if (is_string($class)) {
if (!$item->isStatic()) {
$message = 'Must provide an object instance for non-static properties.';
throw new InvalidArgumentException($message);
}
$value = $item->getValue($item->getDeclaringClass());
} else {
$value = $item->getValue($class);
}
$result = compact('modifiers', 'value') + [
'docComment' => $item->getDocComment(),
'name' => $item->getName()
];
if ($setAccess) {
$item->setAccessible(false);
}
return $result;
}, ['collect' => false]);
} | [
"public",
"static",
"function",
"properties",
"(",
"$",
"class",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'properties'",
"=>",
"[",
"]",
",",
"'self'",
"=>",
"true",
"]",
";",
"$",
"options",
"+=",
"$",
"de... | Returns various information on the properties of an object.
@param string|object $class A string class name for purely static classes or an object
instance, from which to get properties.
@param array $options Set of options applied directly (check `_items()` for more options):
- `'properties'`: array of properties to gather information from.
- `'self'`: If true (default), only returns properties defined in `$class`,
excluding properties from inherited classes.
@return mixed Returns an array with information about the properties from the class given in
$class or null on error. | [
"Returns",
"various",
"information",
"on",
"the",
"properties",
"of",
"an",
"object",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/Inspector.php#L343-L380 |
UnionOfRAD/lithium | analysis/Inspector.php | Inspector.lines | public static function lines($data, $lines) {
$c = [];
if (strpos($data, PHP_EOL) !== false) {
$c = explode(PHP_EOL, PHP_EOL . $data);
} else {
if (!file_exists($data)) {
$data = Libraries::path($data);
if (!file_exists($data)) {
return null;
}
}
$file = new SplFileObject($data);
foreach ($file as $current) {
$c[$file->key() + 1] = rtrim($file->current());
}
}
if (!count($c) || !count($lines)) {
return null;
}
return array_intersect_key($c, array_combine($lines, array_fill(0, count($lines), null)));
} | php | public static function lines($data, $lines) {
$c = [];
if (strpos($data, PHP_EOL) !== false) {
$c = explode(PHP_EOL, PHP_EOL . $data);
} else {
if (!file_exists($data)) {
$data = Libraries::path($data);
if (!file_exists($data)) {
return null;
}
}
$file = new SplFileObject($data);
foreach ($file as $current) {
$c[$file->key() + 1] = rtrim($file->current());
}
}
if (!count($c) || !count($lines)) {
return null;
}
return array_intersect_key($c, array_combine($lines, array_fill(0, count($lines), null)));
} | [
"public",
"static",
"function",
"lines",
"(",
"$",
"data",
",",
"$",
"lines",
")",
"{",
"$",
"c",
"=",
"[",
"]",
";",
"if",
"(",
"strpos",
"(",
"$",
"data",
",",
"PHP_EOL",
")",
"!==",
"false",
")",
"{",
"$",
"c",
"=",
"explode",
"(",
"PHP_EOL"... | Returns an array of lines from a file, class, or arbitrary string, where $data is the data
to read the lines from and $lines is an array of line numbers specifying which lines should
be read.
@param string $data If `$data` contains newlines, it will be read from directly, and have
its own lines returned. If `$data` is a physical file path, that file will be
read and have its lines returned. If `$data` is a class name, it will be
converted into a physical file path and read.
@param array $lines The array of lines to read. If a given line is not present in the data,
it will be silently ignored.
@return array Returns an array where the keys are matching `$lines`, and the values are the
corresponding line numbers in `$data`.
@todo Add an $options parameter with a 'context' flag, to pull in n lines of context. | [
"Returns",
"an",
"array",
"of",
"lines",
"from",
"a",
"file",
"class",
"or",
"arbitrary",
"string",
"where",
"$data",
"is",
"the",
"data",
"to",
"read",
"the",
"lines",
"from",
"and",
"$lines",
"is",
"an",
"array",
"of",
"line",
"numbers",
"specifying",
... | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/Inspector.php#L397-L420 |
UnionOfRAD/lithium | analysis/Inspector.php | Inspector.parents | public static function parents($class, array $options = []) {
$defaults = ['autoLoad' => false];
$options += $defaults;
$class = is_object($class) ? get_class($class) : $class;
if (!class_exists($class, $options['autoLoad'])) {
return false;
}
return class_parents($class);
} | php | public static function parents($class, array $options = []) {
$defaults = ['autoLoad' => false];
$options += $defaults;
$class = is_object($class) ? get_class($class) : $class;
if (!class_exists($class, $options['autoLoad'])) {
return false;
}
return class_parents($class);
} | [
"public",
"static",
"function",
"parents",
"(",
"$",
"class",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'autoLoad'",
"=>",
"false",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"$",
"class",
"=",
"i... | Gets the full inheritance list for the given class.
@param string $class Class whose inheritance chain will be returned
@param array $options Option consists of:
- `'autoLoad'` _boolean_: Whether or not to call `__autoload` by default. Defaults
to `true`.
@return array An array of the name of the parent classes of the passed `$class` parameter,
or `false` on error.
@link http://php.net/function.class-parents.php PHP Manual: `class_parents()`. | [
"Gets",
"the",
"full",
"inheritance",
"list",
"for",
"the",
"given",
"class",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/Inspector.php#L433-L442 |
UnionOfRAD/lithium | analysis/Inspector.php | Inspector.classes | public static function classes(array $options = []) {
$defaults = ['group' => 'classes', 'file' => null];
$options += $defaults;
$list = get_declared_classes();
$files = get_included_files();
$classes = [];
if ($file = $options['file']) {
$loaded = static::_instance('collection', ['data' => array_map(
function($class) { return new ReflectionClass($class); }, $list
)]);
$classFiles = $loaded->getFileName();
if (in_array($file, $files) && !in_array($file, $classFiles)) {
return [];
}
if (!in_array($file, $classFiles)) {
include $file;
$list = array_diff(get_declared_classes(), $list);
} else {
$filter = function($class) use ($file) { return $class->getFileName() === $file; };
$list = $loaded->find($filter)->map(function ($class) {
return $class->getName() ?: $class->name;
}, ['collect' => false]);
}
}
foreach ($list as $class) {
$inspector = new ReflectionClass($class);
if ($options['group'] === 'classes') {
$inspector->getFileName() ? $classes[$class] = $inspector->getFileName() : null;
} elseif ($options['group'] === 'files') {
$classes[$inspector->getFileName()][] = $inspector;
}
}
return $classes;
} | php | public static function classes(array $options = []) {
$defaults = ['group' => 'classes', 'file' => null];
$options += $defaults;
$list = get_declared_classes();
$files = get_included_files();
$classes = [];
if ($file = $options['file']) {
$loaded = static::_instance('collection', ['data' => array_map(
function($class) { return new ReflectionClass($class); }, $list
)]);
$classFiles = $loaded->getFileName();
if (in_array($file, $files) && !in_array($file, $classFiles)) {
return [];
}
if (!in_array($file, $classFiles)) {
include $file;
$list = array_diff(get_declared_classes(), $list);
} else {
$filter = function($class) use ($file) { return $class->getFileName() === $file; };
$list = $loaded->find($filter)->map(function ($class) {
return $class->getName() ?: $class->name;
}, ['collect' => false]);
}
}
foreach ($list as $class) {
$inspector = new ReflectionClass($class);
if ($options['group'] === 'classes') {
$inspector->getFileName() ? $classes[$class] = $inspector->getFileName() : null;
} elseif ($options['group'] === 'files') {
$classes[$inspector->getFileName()][] = $inspector;
}
}
return $classes;
} | [
"public",
"static",
"function",
"classes",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'group'",
"=>",
"'classes'",
",",
"'file'",
"=>",
"null",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"$",
"list",... | Gets an array of classes and their corresponding definition files, or examines a file and
returns the classes it defines.
@param array $options Option consists of:
- `'group'`: Can be `classes` for grouping by class name or `files` for grouping by
filename.
- `'file': Valid file path for inspecting the containing classes.
@return array Associative of classes and their corresponding definition files | [
"Gets",
"an",
"array",
"of",
"classes",
"and",
"their",
"corresponding",
"definition",
"files",
"or",
"examines",
"a",
"file",
"and",
"returns",
"the",
"classes",
"it",
"defines",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/Inspector.php#L454-L492 |
UnionOfRAD/lithium | analysis/Inspector.php | Inspector.dependencies | public static function dependencies($classes, array $options = []) {
$defaults = ['type' => null];
$options += $defaults;
$static = $dynamic = [];
$trim = function($c) { return trim(trim($c, '\\')); };
$join = function($i) { return join('', $i); };
foreach ((array) $classes as $class) {
$data = explode("\n", file_get_contents(Libraries::path($class)));
$data = "<?php \n" . join("\n", preg_grep('/^\s*use /', $data)) . "\n ?>";
$classes = array_map($join, Parser::find($data, 'use *;', [
'return' => 'content',
'lineBreaks' => true,
'startOfLine' => true,
'capture' => ['T_STRING', 'T_NS_SEPARATOR']
]));
if ($classes) {
$static = array_unique(array_merge($static, array_map($trim, $classes)));
}
$classes = static::info($class . '::$_classes', ['value']);
if (isset($classes['value'])) {
$dynamic = array_merge($dynamic, array_map($trim, array_values($classes['value'])));
}
}
if (empty($options['type'])) {
return array_unique(array_merge($static, $dynamic));
}
$type = $options['type'];
return isset(${$type}) ? ${$type} : null;
} | php | public static function dependencies($classes, array $options = []) {
$defaults = ['type' => null];
$options += $defaults;
$static = $dynamic = [];
$trim = function($c) { return trim(trim($c, '\\')); };
$join = function($i) { return join('', $i); };
foreach ((array) $classes as $class) {
$data = explode("\n", file_get_contents(Libraries::path($class)));
$data = "<?php \n" . join("\n", preg_grep('/^\s*use /', $data)) . "\n ?>";
$classes = array_map($join, Parser::find($data, 'use *;', [
'return' => 'content',
'lineBreaks' => true,
'startOfLine' => true,
'capture' => ['T_STRING', 'T_NS_SEPARATOR']
]));
if ($classes) {
$static = array_unique(array_merge($static, array_map($trim, $classes)));
}
$classes = static::info($class . '::$_classes', ['value']);
if (isset($classes['value'])) {
$dynamic = array_merge($dynamic, array_map($trim, array_values($classes['value'])));
}
}
if (empty($options['type'])) {
return array_unique(array_merge($static, $dynamic));
}
$type = $options['type'];
return isset(${$type}) ? ${$type} : null;
} | [
"public",
"static",
"function",
"dependencies",
"(",
"$",
"classes",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'type'",
"=>",
"null",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"$",
"static",
"=",
... | Gets the static and dynamic dependencies for a class or group of classes.
@param mixed $classes Either a string specifying a class, or a numerically indexed array
of classes
@param array $options Option consists of:
- `'type'`: The type of dependency to check: `static` for static dependencies,
`dynamic`for dynamic dependencies or `null` for both merged in the same array.
Defaults to `null`.
@return array An array of the static and dynamic class dependencies or each if `type` is
defined in $options. | [
"Gets",
"the",
"static",
"and",
"dynamic",
"dependencies",
"for",
"a",
"class",
"or",
"group",
"of",
"classes",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/Inspector.php#L506-L539 |
UnionOfRAD/lithium | analysis/Inspector.php | Inspector._items | protected static function _items($class, $method, $options) {
$defaults = ['names' => [], 'self' => true, 'public' => true];
$options += $defaults;
$params = [
'getProperties' => ReflectionProperty::IS_PUBLIC | (
$options['public'] ? 0 : ReflectionProperty::IS_PROTECTED
)
];
$data = isset($params[$method]) ? $class->{$method}($params[$method]) : $class->{$method}();
if (!empty($options['names'])) {
$data = array_filter($data, function($item) use ($options) {
return in_array($item->getName(), (array) $options['names']);
});
}
if ($options['self']) {
$data = array_filter($data, function($item) use ($class) {
return ($item->getDeclaringClass()->getName() === $class->getName());
});
}
if ($options['public']) {
$data = array_filter($data, function($item) { return $item->isPublic(); });
}
return static::_instance('collection', compact('data'));
} | php | protected static function _items($class, $method, $options) {
$defaults = ['names' => [], 'self' => true, 'public' => true];
$options += $defaults;
$params = [
'getProperties' => ReflectionProperty::IS_PUBLIC | (
$options['public'] ? 0 : ReflectionProperty::IS_PROTECTED
)
];
$data = isset($params[$method]) ? $class->{$method}($params[$method]) : $class->{$method}();
if (!empty($options['names'])) {
$data = array_filter($data, function($item) use ($options) {
return in_array($item->getName(), (array) $options['names']);
});
}
if ($options['self']) {
$data = array_filter($data, function($item) use ($class) {
return ($item->getDeclaringClass()->getName() === $class->getName());
});
}
if ($options['public']) {
$data = array_filter($data, function($item) { return $item->isPublic(); });
}
return static::_instance('collection', compact('data'));
} | [
"protected",
"static",
"function",
"_items",
"(",
"$",
"class",
",",
"$",
"method",
",",
"$",
"options",
")",
"{",
"$",
"defaults",
"=",
"[",
"'names'",
"=>",
"[",
"]",
",",
"'self'",
"=>",
"true",
",",
"'public'",
"=>",
"true",
"]",
";",
"$",
"opt... | Helper method to get an array of `ReflectionMethod` or `ReflectionProperty` objects, wrapped
in a `Collection` object, and filtered based on a set of options.
@param ReflectionClass $class A reflection class instance from which to fetch.
@param string $method A getter method to call on the `ReflectionClass` instance, which will
return an array of items, i.e. `'getProperties'` or `'getMethods'`.
@param array $options The options used to filter the resulting method list.
- `'names'`: array of properties for filtering the result.
- `'self'`: If true (default), only returns properties defined in `$class`,
excluding properties from inherited classes.
- `'public'`: If true (default) forces the property to be recognized as public.
@return object Returns a `Collection` object instance containing the results of the items
returned from the call to the method specified in `$method`, after being passed
through the filters specified in `$options`. | [
"Helper",
"method",
"to",
"get",
"an",
"array",
"of",
"ReflectionMethod",
"or",
"ReflectionProperty",
"objects",
"wrapped",
"in",
"a",
"Collection",
"object",
"and",
"filtered",
"based",
"on",
"a",
"set",
"of",
"options",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/Inspector.php#L574-L601 |
UnionOfRAD/lithium | analysis/Inspector.php | Inspector._modifiers | protected static function _modifiers($inspector, $list = []) {
$list = $list ?: ['public', 'private', 'protected', 'abstract', 'final', 'static'];
return array_filter($list, function($modifier) use ($inspector) {
$method = 'is' . ucfirst($modifier);
return (method_exists($inspector, $method) && $inspector->{$method}());
});
} | php | protected static function _modifiers($inspector, $list = []) {
$list = $list ?: ['public', 'private', 'protected', 'abstract', 'final', 'static'];
return array_filter($list, function($modifier) use ($inspector) {
$method = 'is' . ucfirst($modifier);
return (method_exists($inspector, $method) && $inspector->{$method}());
});
} | [
"protected",
"static",
"function",
"_modifiers",
"(",
"$",
"inspector",
",",
"$",
"list",
"=",
"[",
"]",
")",
"{",
"$",
"list",
"=",
"$",
"list",
"?",
":",
"[",
"'public'",
",",
"'private'",
",",
"'protected'",
",",
"'abstract'",
",",
"'final'",
",",
... | Helper method to determine if a class applies to a list of modifiers.
@param string $inspector ReflectionClass instance.
@param array|string $list List of modifiers to test.
@return boolean Test result. | [
"Helper",
"method",
"to",
"determine",
"if",
"a",
"class",
"applies",
"to",
"a",
"list",
"of",
"modifiers",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/Inspector.php#L610-L616 |
UnionOfRAD/lithium | g11n/Catalog.php | Catalog.config | public static function config($config = null) {
$defaults = ['scope' => null];
if (is_array($config)) {
foreach ($config as $i => $item) {
$config[$i] += $defaults;
}
}
return parent::config($config);
} | php | public static function config($config = null) {
$defaults = ['scope' => null];
if (is_array($config)) {
foreach ($config as $i => $item) {
$config[$i] += $defaults;
}
}
return parent::config($config);
} | [
"public",
"static",
"function",
"config",
"(",
"$",
"config",
"=",
"null",
")",
"{",
"$",
"defaults",
"=",
"[",
"'scope'",
"=>",
"null",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"config",
")",
")",
"{",
"foreach",
"(",
"$",
"config",
"as",
"$",
... | Sets configurations for this Adaptable implementation.
@param array $config Configurations, indexed by name.
@return array `Collection` of configurations or void if setting configurations. | [
"Sets",
"configurations",
"for",
"this",
"Adaptable",
"implementation",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/g11n/Catalog.php#L43-L52 |
UnionOfRAD/lithium | g11n/Catalog.php | Catalog.read | public static function read($name, $category, $locale, array $options = []) {
$defaults = ['scope' => null, 'lossy' => true];
$options += $defaults;
$category = strtok($category, '.');
$id = strtok('.');
$names = $name === true ? array_keys(static::$_configurations) : (array) $name;
$results = [];
foreach (Locale::cascade($locale) as $cascaded) {
foreach ($names as $name) {
$adapter = static::adapter($name);
if ($result = $adapter->read($category, $cascaded, $options['scope'])) {
$results += $result;
}
}
}
if ($options['lossy']) {
array_walk($results, function(&$value) {
$value = $value['translated'];
});
}
if ($id) {
return isset($results[$id]) ? $results[$id] : null;
}
return $results ?: null;
} | php | public static function read($name, $category, $locale, array $options = []) {
$defaults = ['scope' => null, 'lossy' => true];
$options += $defaults;
$category = strtok($category, '.');
$id = strtok('.');
$names = $name === true ? array_keys(static::$_configurations) : (array) $name;
$results = [];
foreach (Locale::cascade($locale) as $cascaded) {
foreach ($names as $name) {
$adapter = static::adapter($name);
if ($result = $adapter->read($category, $cascaded, $options['scope'])) {
$results += $result;
}
}
}
if ($options['lossy']) {
array_walk($results, function(&$value) {
$value = $value['translated'];
});
}
if ($id) {
return isset($results[$id]) ? $results[$id] : null;
}
return $results ?: null;
} | [
"public",
"static",
"function",
"read",
"(",
"$",
"name",
",",
"$",
"category",
",",
"$",
"locale",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'scope'",
"=>",
"null",
",",
"'lossy'",
"=>",
"true",
"]",
";",
... | Reads data.
Results are aggregated by querying all requested configurations for the requested
locale then repeating this process for all locales down the locale cascade. This
allows for sparse data which is complemented by data from other sources or for more
generic locales. Aggregation can be controlled by either specifying the configurations
or a scope to use.
Usage:
```
Catalog::read(true, 'message', 'zh');
Catalog::read('default', 'message', 'zh');
Catalog::read('default', 'validation.postalCode', 'en_US');
```
@param mixed $name Provide a single configuration name as a string or multiple ones as
an array which will be used to read from. Pass `true` to use all configurations.
@param string $category A (dot-delimeted) category.
@param string $locale A locale identifier.
@param array $options Valid options are:
- `'scope'`: The scope to use.
- `'lossy'`: Whether or not to use the compact and lossy format, defaults to `true`.
@return array If available the requested data, else `null`. | [
"Reads",
"data",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/g11n/Catalog.php#L79-L108 |
UnionOfRAD/lithium | g11n/Catalog.php | Catalog.write | public static function write($name, $category, $locale, $data, array $options = []) {
$defaults = ['scope' => null];
$options += $defaults;
$category = strtok($category, '.');
$id = strtok('.');
if ($id) {
$data = [$id => $data];
}
array_walk($data, function(&$value, $key) {
if (!is_array($value) || !array_key_exists('translated', $value)) {
$value = ['id' => $key, 'translated' => $value];
}
});
$adapter = static::adapter($name);
return $adapter->write($category, $locale, $options['scope'], $data);
} | php | public static function write($name, $category, $locale, $data, array $options = []) {
$defaults = ['scope' => null];
$options += $defaults;
$category = strtok($category, '.');
$id = strtok('.');
if ($id) {
$data = [$id => $data];
}
array_walk($data, function(&$value, $key) {
if (!is_array($value) || !array_key_exists('translated', $value)) {
$value = ['id' => $key, 'translated' => $value];
}
});
$adapter = static::adapter($name);
return $adapter->write($category, $locale, $options['scope'], $data);
} | [
"public",
"static",
"function",
"write",
"(",
"$",
"name",
",",
"$",
"category",
",",
"$",
"locale",
",",
"$",
"data",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'scope'",
"=>",
"null",
"]",
";",
"$",
"opti... | Writes data.
Usage:
```
$data = [
'color' => '色'
];
Catalog::write('runtime', 'message', 'ja', $data);
```
@param string $name Provide a configuration name to use for writing.
@param string $category A (dot-delimited) category.
@param string $locale A locale identifier.
@param mixed $data If method is used without specifying an id must be an array.
@param array $options Valid options are:
- `'scope'`: The scope to use.
@return boolean Success. | [
"Writes",
"data",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/g11n/Catalog.php#L129-L148 |
UnionOfRAD/lithium | g11n/Multibyte.php | Multibyte.is | public static function is($string, array $options = []) {
$defaults = ['quick' => false];
$options += $defaults;
if ($options['quick']) {
$regex = '/[^\x09\x0A\x0D\x20-\x7E]/m';
} else {
$regex = '/\A(';
$regex .= '[\x09\x0A\x0D\x20-\x7E]';
$regex .= '|[\xC2-\xDF][\x80-\xBF]';
$regex .= '|\xE0[\xA0-\xBF][\x80-\xBF]';
$regex .= '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}';
$regex .= '|\xED[\x80-\x9F][\x80-\xBF]';
$regex .= '|\xF0[\x90-\xBF][\x80-\xBF]{2}';
$regex .= '|[\xF1-\xF3][\x80-\xBF]{3}';
$regex .= '|\xF4[\x80-\x8F][\x80-\xBF]{2}';
$regex .= ')*\z/m';
}
return (boolean) preg_match($regex, $string);
} | php | public static function is($string, array $options = []) {
$defaults = ['quick' => false];
$options += $defaults;
if ($options['quick']) {
$regex = '/[^\x09\x0A\x0D\x20-\x7E]/m';
} else {
$regex = '/\A(';
$regex .= '[\x09\x0A\x0D\x20-\x7E]';
$regex .= '|[\xC2-\xDF][\x80-\xBF]';
$regex .= '|\xE0[\xA0-\xBF][\x80-\xBF]';
$regex .= '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}';
$regex .= '|\xED[\x80-\x9F][\x80-\xBF]';
$regex .= '|\xF0[\x90-\xBF][\x80-\xBF]{2}';
$regex .= '|[\xF1-\xF3][\x80-\xBF]{3}';
$regex .= '|\xF4[\x80-\x8F][\x80-\xBF]{2}';
$regex .= ')*\z/m';
}
return (boolean) preg_match($regex, $string);
} | [
"public",
"static",
"function",
"is",
"(",
"$",
"string",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'quick'",
"=>",
"false",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"if",
"(",
"$",
"options",
... | Checks if a given string is UTF-8 encoded and is valid UTF-8.
In _quick_ mode it will check only for non ASCII characters being used
indicating any multibyte encoding. Don't use quick mode for integrity
validation of UTF-8 encoded strings.
Meaning of RegExp:
```
'[\x09\x0A\x0D\x20-\x7E]'; // ASCII
'|[\xC2-\xDF][\x80-\xBF]'; // non-overlong 2-byte
'|\xE0[\xA0-\xBF][\x80-\xBF]'; // excluding overlongs
'|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'; // straight 3-byte
'|\xED[\x80-\x9F][\x80-\xBF]'; // excluding surrogates
'|\xF0[\x90-\xBF][\x80-\xBF]{2}'; // planes 1-3
'|[\xF1-\xF3][\x80-\xBF]{3}'; // planes 4-15
'|\xF4[\x80-\x8F][\x80-\xBF]{2}'; // plane 16
```
@link http://www.w3.org/International/questions/qa-forms-utf-8.en
@param string $string The string to analyze.
@param array $options Allows to toggle mode via the `'quick'` option, defaults to `false`.
@return boolean Returns `true` if the string is UTF-8. | [
"Checks",
"if",
"a",
"given",
"string",
"is",
"UTF",
"-",
"8",
"encoded",
"and",
"is",
"valid",
"UTF",
"-",
"8",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/g11n/Multibyte.php#L76-L95 |
UnionOfRAD/lithium | g11n/Multibyte.php | Multibyte.strlen | public static function strlen($string, array $options = []) {
$defaults = ['name' => 'default'];
$options += $defaults;
return static::adapter($options['name'])->strlen($string);
} | php | public static function strlen($string, array $options = []) {
$defaults = ['name' => 'default'];
$options += $defaults;
return static::adapter($options['name'])->strlen($string);
} | [
"public",
"static",
"function",
"strlen",
"(",
"$",
"string",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'name'",
"=>",
"'default'",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"return",
"static",
"::... | Gets the string length. Multibyte enabled version of `strlen()`.
@link http://php.net/function.strlen.php
@param string $string The string being measured for length.
@param array $options Allows for selecting the adapter to use via the
`name` options. Will use the `'default'` adapter by default.
@return integer The length of the string on success. | [
"Gets",
"the",
"string",
"length",
".",
"Multibyte",
"enabled",
"version",
"of",
"strlen",
"()",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/g11n/Multibyte.php#L106-L110 |
UnionOfRAD/lithium | g11n/Multibyte.php | Multibyte.strpos | public static function strpos($haystack, $needle, $offset = 0, array $options = []) {
$defaults = ['name' => 'default'];
$options += $defaults;
return static::adapter($options['name'])->strpos($haystack, $needle, $offset);
} | php | public static function strpos($haystack, $needle, $offset = 0, array $options = []) {
$defaults = ['name' => 'default'];
$options += $defaults;
return static::adapter($options['name'])->strpos($haystack, $needle, $offset);
} | [
"public",
"static",
"function",
"strpos",
"(",
"$",
"haystack",
",",
"$",
"needle",
",",
"$",
"offset",
"=",
"0",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'name'",
"=>",
"'default'",
"]",
";",
"$",
"options... | Finds the position of the _first_ occurrence of a string within a string.
Multibyte enabled version of `strpos()`.
Not all adapters must support interpreting - thus applying - passed
numeric values as ordinal values of a character.
@link http://php.net/function.strpos.php
@param string $haystack The string being checked.
@param string $needle The string to find in the haystack.
@param integer $offset If specified, search will start this number of
characters counted from the beginning of the string. The
offset cannot be negative.
@param array $options Allows for selecting the adapter to use via the
`name` options. Will use the `'default'` adapter by default.
@return integer Returns the numeric position of the first occurrence of
the needle in the haystack string. If needle is not found,
it returns `false`. | [
"Finds",
"the",
"position",
"of",
"the",
"_first_",
"occurrence",
"of",
"a",
"string",
"within",
"a",
"string",
".",
"Multibyte",
"enabled",
"version",
"of",
"strpos",
"()",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/g11n/Multibyte.php#L131-L135 |
UnionOfRAD/lithium | g11n/Multibyte.php | Multibyte.strrpos | public static function strrpos($haystack, $needle, array $options = []) {
$defaults = ['name' => 'default'];
$options += $defaults;
return static::adapter($options['name'])->strrpos($haystack, $needle);
} | php | public static function strrpos($haystack, $needle, array $options = []) {
$defaults = ['name' => 'default'];
$options += $defaults;
return static::adapter($options['name'])->strrpos($haystack, $needle);
} | [
"public",
"static",
"function",
"strrpos",
"(",
"$",
"haystack",
",",
"$",
"needle",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'name'",
"=>",
"'default'",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
... | Finds the position of the _last_ occurrence of a string within a string.
Multibyte enabled version of `strrpos()`.
Not all adapters must support interpreting - thus applying - passed
numeric values as ordinal values of a character. The `Iconv` adapter
doesn't support an offset as `strpos()` does - this constitutes the
lowest common denominator here.
@link http://php.net/function.strrpos.php
@param string $haystack The string being checked.
@param string $needle The string to find in the haystack.
@param array $options Allows for selecting the adapter to use via the
`name` options. Will use the `'default'` adapter by default.
@return integer Returns the numeric position of the last occurrence of
the needle in the haystack string. If needle is not found,
it returns `false`. | [
"Finds",
"the",
"position",
"of",
"the",
"_last_",
"occurrence",
"of",
"a",
"string",
"within",
"a",
"string",
".",
"Multibyte",
"enabled",
"version",
"of",
"strrpos",
"()",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/g11n/Multibyte.php#L155-L159 |
UnionOfRAD/lithium | g11n/Multibyte.php | Multibyte.substr | public static function substr($string, $start, $length = null, array $options = []) {
$defaults = ['name' => 'default'];
$options += $defaults;
return static::adapter($options['name'])->substr($string, $start, $length);
} | php | public static function substr($string, $start, $length = null, array $options = []) {
$defaults = ['name' => 'default'];
$options += $defaults;
return static::adapter($options['name'])->substr($string, $start, $length);
} | [
"public",
"static",
"function",
"substr",
"(",
"$",
"string",
",",
"$",
"start",
",",
"$",
"length",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'name'",
"=>",
"'default'",
"]",
";",
"$",
"options... | Returns the portion of string specified by the start and length parameters.
Multibyte enabled version of `substr()`.
@link http://php.net/function.substr.php
@param string $string The string to extract the substring from.
@param integer $start Position of first character in string (offset).
@param integer $length Maximum numbers of characters to use from string.
@param array $options Allows for selecting the adapter to use via the
`name` options. Will use the `'default'` adapter by default.
@return string The substring extracted from given string. | [
"Returns",
"the",
"portion",
"of",
"string",
"specified",
"by",
"the",
"start",
"and",
"length",
"parameters",
".",
"Multibyte",
"enabled",
"version",
"of",
"substr",
"()",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/g11n/Multibyte.php#L173-L177 |
UnionOfRAD/lithium | data/Collection.php | Collection.assignTo | public function assignTo($parent, array $config = []) {
foreach ($config as $key => $val) {
$this->{'_' . $key} = $val;
}
$this->_parent =& $parent;
} | php | public function assignTo($parent, array $config = []) {
foreach ($config as $key => $val) {
$this->{'_' . $key} = $val;
}
$this->_parent =& $parent;
} | [
"public",
"function",
"assignTo",
"(",
"$",
"parent",
",",
"array",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"config",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"this",
"->",
"{",
"'_'",
".",
"$",
"key",
"}",
"=",
... | Configures protected properties of a `Collection` so that it is parented to `$parent`.
@param object $parent
@param array $config
@return void | [
"Configures",
"protected",
"properties",
"of",
"a",
"Collection",
"so",
"that",
"it",
"is",
"parented",
"to",
"$parent",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/Collection.php#L159-L164 |
UnionOfRAD/lithium | data/Collection.php | Collection.offsetGet | public function offsetGet($offset) {
while (!array_key_exists($offset, $this->_data) && $this->_populate()) {}
if (array_key_exists($offset, $this->_data)) {
return $this->_data[$offset];
}
return null;
} | php | public function offsetGet($offset) {
while (!array_key_exists($offset, $this->_data) && $this->_populate()) {}
if (array_key_exists($offset, $this->_data)) {
return $this->_data[$offset];
}
return null;
} | [
"public",
"function",
"offsetGet",
"(",
"$",
"offset",
")",
"{",
"while",
"(",
"!",
"array_key_exists",
"(",
"$",
"offset",
",",
"$",
"this",
"->",
"_data",
")",
"&&",
"$",
"this",
"->",
"_populate",
"(",
")",
")",
"{",
"}",
"if",
"(",
"array_key_exi... | Gets an `Entity` object using PHP's array syntax, i.e. `$documents[3]` or `$records[5]`.
@param mixed $offset The offset.
@return mixed Returns an `Entity` object if exists otherwise returns `null`. | [
"Gets",
"an",
"Entity",
"object",
"using",
"PHP",
"s",
"array",
"syntax",
"i",
".",
"e",
".",
"$documents",
"[",
"3",
"]",
"or",
"$records",
"[",
"5",
"]",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/Collection.php#L248-L255 |
UnionOfRAD/lithium | data/Collection.php | Collection.offsetSet | public function offsetSet($offset, $data) {
$this->offsetGet($offset);
return $this->_set($data, $offset);
} | php | public function offsetSet($offset, $data) {
$this->offsetGet($offset);
return $this->_set($data, $offset);
} | [
"public",
"function",
"offsetSet",
"(",
"$",
"offset",
",",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"offsetGet",
"(",
"$",
"offset",
")",
";",
"return",
"$",
"this",
"->",
"_set",
"(",
"$",
"data",
",",
"$",
"offset",
")",
";",
"}"
] | Adds the specified object to the `Collection` instance, and assigns associated metadata to
the added object.
@param string $offset The offset to assign the value to.
@param mixed $data The entity object to add.
@return mixed Returns the set `Entity` object. | [
"Adds",
"the",
"specified",
"object",
"to",
"the",
"Collection",
"instance",
"and",
"assigns",
"associated",
"metadata",
"to",
"the",
"added",
"object",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/Collection.php#L265-L268 |
UnionOfRAD/lithium | data/Collection.php | Collection.rewind | public function rewind() {
$this->_started = true;
reset($this->_data);
$this->_valid = !empty($this->_data) || $this->_populate() !== null;
return current($this->_data);
} | php | public function rewind() {
$this->_started = true;
reset($this->_data);
$this->_valid = !empty($this->_data) || $this->_populate() !== null;
return current($this->_data);
} | [
"public",
"function",
"rewind",
"(",
")",
"{",
"$",
"this",
"->",
"_started",
"=",
"true",
";",
"reset",
"(",
"$",
"this",
"->",
"_data",
")",
";",
"$",
"this",
"->",
"_valid",
"=",
"!",
"empty",
"(",
"$",
"this",
"->",
"_data",
")",
"||",
"$",
... | Rewinds the collection to the beginning. | [
"Rewinds",
"the",
"collection",
"to",
"the",
"beginning",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/Collection.php#L287-L292 |
UnionOfRAD/lithium | data/Collection.php | Collection.key | public function key($full = false) {
if ($this->_started === false) {
$this->current();
}
if ($this->_valid) {
$key = key($this->_data);
return (is_array($key) && !$full) ? reset($key) : $key;
}
return null;
} | php | public function key($full = false) {
if ($this->_started === false) {
$this->current();
}
if ($this->_valid) {
$key = key($this->_data);
return (is_array($key) && !$full) ? reset($key) : $key;
}
return null;
} | [
"public",
"function",
"key",
"(",
"$",
"full",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_started",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"current",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_valid",
")",
"{",
"$",
... | Returns the currently pointed to record's unique key.
@param boolean $full If true, returns the complete key.
@return mixed | [
"Returns",
"the",
"currently",
"pointed",
"to",
"record",
"s",
"unique",
"key",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/Collection.php#L300-L309 |
UnionOfRAD/lithium | data/Collection.php | Collection.current | public function current() {
if (!$this->_started) {
$this->rewind();
}
if (!$this->_valid) {
return false;
}
return current($this->_data);
} | php | public function current() {
if (!$this->_started) {
$this->rewind();
}
if (!$this->_valid) {
return false;
}
return current($this->_data);
} | [
"public",
"function",
"current",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_started",
")",
"{",
"$",
"this",
"->",
"rewind",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"_valid",
")",
"{",
"return",
"false",
";",
"}",
"retur... | Returns the currently pointed to record in the set.
@return object|boolean An instance of `Record` or `false` if there is no current valid one. | [
"Returns",
"the",
"currently",
"pointed",
"to",
"record",
"in",
"the",
"set",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/Collection.php#L326-L334 |
UnionOfRAD/lithium | data/Collection.php | Collection.next | public function next() {
if (!$this->_started) {
$this->rewind();
}
next($this->_data);
$this->_valid = key($this->_data) !== null;
if (!$this->_valid) {
$this->_valid = $this->_populate() !== null;
}
return current($this->_data);
} | php | public function next() {
if (!$this->_started) {
$this->rewind();
}
next($this->_data);
$this->_valid = key($this->_data) !== null;
if (!$this->_valid) {
$this->_valid = $this->_populate() !== null;
}
return current($this->_data);
} | [
"public",
"function",
"next",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_started",
")",
"{",
"$",
"this",
"->",
"rewind",
"(",
")",
";",
"}",
"next",
"(",
"$",
"this",
"->",
"_data",
")",
";",
"$",
"this",
"->",
"_valid",
"=",
"key",
... | Returns the next document in the set, and advances the object's internal pointer. If the end
of the set is reached, a new document will be fetched from the data source connection handle
If no more documents can be fetched, returns `null`.
@return mixed Returns the next document in the set, or `false`, if no more documents are
available. | [
"Returns",
"the",
"next",
"document",
"in",
"the",
"set",
"and",
"advances",
"the",
"object",
"s",
"internal",
"pointer",
".",
"If",
"the",
"end",
"of",
"the",
"set",
"is",
"reached",
"a",
"new",
"document",
"will",
"be",
"fetched",
"from",
"the",
"data"... | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/Collection.php#L344-L355 |
UnionOfRAD/lithium | data/Collection.php | Collection.find | public function find($filter, array $options = []) {
$this->offsetGet(null);
if (is_array($filter)) {
$filter = $this->_filterFromArray($filter);
}
return parent::find($filter, $options);
} | php | public function find($filter, array $options = []) {
$this->offsetGet(null);
if (is_array($filter)) {
$filter = $this->_filterFromArray($filter);
}
return parent::find($filter, $options);
} | [
"public",
"function",
"find",
"(",
"$",
"filter",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"offsetGet",
"(",
"null",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"filter",
")",
")",
"{",
"$",
"filter",
"=",
"$",
"... | Overrides parent `find()` implementation to enable key/value-based filtering of entity
objects contained in this collection.
@param mixed $filter Callback to use for filtering, or array of key/value pairs which entity
properties will be matched against.
@param array $options Options to modify the behavior of this method. See the documentation
for the `$options` parameter of `lithium\util\Collection::find()`.
@return mixed The filtered items. Will be an array unless `'collect'` is defined in the
`$options` argument, then an instance of this class will be returned. | [
"Overrides",
"parent",
"find",
"()",
"implementation",
"to",
"enable",
"key",
"/",
"value",
"-",
"based",
"filtering",
"of",
"entity",
"objects",
"contained",
"in",
"this",
"collection",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/Collection.php#L380-L386 |
UnionOfRAD/lithium | data/Collection.php | Collection.first | public function first($filter = null) {
return parent::first(is_array($filter) ? $this->_filterFromArray($filter) : $filter);
} | php | public function first($filter = null) {
return parent::first(is_array($filter) ? $this->_filterFromArray($filter) : $filter);
} | [
"public",
"function",
"first",
"(",
"$",
"filter",
"=",
"null",
")",
"{",
"return",
"parent",
"::",
"first",
"(",
"is_array",
"(",
"$",
"filter",
")",
"?",
"$",
"this",
"->",
"_filterFromArray",
"(",
"$",
"filter",
")",
":",
"$",
"filter",
")",
";",
... | Overrides parent `first()` implementation to enable key/value-based filtering.
@param mixed $filter In addition to a callback (see parent), can also be an array where the
keys and values must match the property values of the objects being inspected.
@return object Returns the first object found matching the filter criteria. | [
"Overrides",
"parent",
"first",
"()",
"implementation",
"to",
"enable",
"key",
"/",
"value",
"-",
"based",
"filtering",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/Collection.php#L395-L397 |
UnionOfRAD/lithium | data/Collection.php | Collection._filterFromArray | protected function _filterFromArray(array $filter) {
return function($item) use ($filter) {
foreach ($filter as $key => $val) {
if ($item->{$key} != $val) {
return false;
}
}
return true;
};
} | php | protected function _filterFromArray(array $filter) {
return function($item) use ($filter) {
foreach ($filter as $key => $val) {
if ($item->{$key} != $val) {
return false;
}
}
return true;
};
} | [
"protected",
"function",
"_filterFromArray",
"(",
"array",
"$",
"filter",
")",
"{",
"return",
"function",
"(",
"$",
"item",
")",
"use",
"(",
"$",
"filter",
")",
"{",
"foreach",
"(",
"$",
"filter",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
... | Creates a filter based on an array of key/value pairs that must match the items in a
`Collection`.
@param array $filter An array of key/value pairs used to filter `Collection` items.
@return \Closure Returns a closure that wraps the array and attempts to match each value
against `Collection` item properties. | [
"Creates",
"a",
"filter",
"based",
"on",
"an",
"array",
"of",
"key",
"/",
"value",
"pairs",
"that",
"must",
"match",
"the",
"items",
"in",
"a",
"Collection",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/Collection.php#L407-L416 |
UnionOfRAD/lithium | data/Collection.php | Collection.map | public function map($filter, array $options = []) {
$defaults = ['collect' => true];
$options += $defaults;
$this->offsetGet(null);
$data = parent::map($filter, $options);
if ($options['collect']) {
foreach (['_model', '_schema', '_pathKey'] as $key) {
$data->{$key} = $this->{$key};
}
}
return $data;
} | php | public function map($filter, array $options = []) {
$defaults = ['collect' => true];
$options += $defaults;
$this->offsetGet(null);
$data = parent::map($filter, $options);
if ($options['collect']) {
foreach (['_model', '_schema', '_pathKey'] as $key) {
$data->{$key} = $this->{$key};
}
}
return $data;
} | [
"public",
"function",
"map",
"(",
"$",
"filter",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'collect'",
"=>",
"true",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"$",
"this",
"->",
"offsetGet",
"(",... | Applies a callback to a copy of all data in the collection
and returns the result.
Overriden to load any data that has not yet been loaded.
@param callback $filter The filter to apply.
@param array $options The available options are:
- `'collect'`: If `true`, the results will be returned wrapped
in a new `Collection` object or subclass.
@return object The filtered data. | [
"Applies",
"a",
"callback",
"to",
"a",
"copy",
"of",
"all",
"data",
"in",
"the",
"collection",
"and",
"returns",
"the",
"result",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/Collection.php#L452-L465 |
UnionOfRAD/lithium | data/Collection.php | Collection.reduce | public function reduce($filter, $initial = false) {
if (!$this->closed()) {
while ($this->next()) {}
}
return parent::reduce($filter, $initial);
} | php | public function reduce($filter, $initial = false) {
if (!$this->closed()) {
while ($this->next()) {}
}
return parent::reduce($filter, $initial);
} | [
"public",
"function",
"reduce",
"(",
"$",
"filter",
",",
"$",
"initial",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"closed",
"(",
")",
")",
"{",
"while",
"(",
"$",
"this",
"->",
"next",
"(",
")",
")",
"{",
"}",
"}",
"return",
... | Reduce, or fold, a collection down to a single value
Overridden to load any data that has not yet been loaded.
@param callback $filter The filter to apply.
@param mixed $initial Initial value
@return mixed A single reduced value | [
"Reduce",
"or",
"fold",
"a",
"collection",
"down",
"to",
"a",
"single",
"value"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/Collection.php#L476-L481 |
UnionOfRAD/lithium | data/Collection.php | Collection.sort | public function sort($field = 'id', array $options = []) {
$this->offsetGet(null);
if (is_string($field)) {
$sorter = function ($a, $b) use ($field) {
if (is_array($a)) {
$a = (object) $a;
}
if (is_array($b)) {
$b = (object) $b;
}
return strcmp($a->$field, $b->$field);
};
} elseif (is_callable($field)) {
$sorter = $field;
} else {
return $this;
}
return parent::sort($sorter, $options);
} | php | public function sort($field = 'id', array $options = []) {
$this->offsetGet(null);
if (is_string($field)) {
$sorter = function ($a, $b) use ($field) {
if (is_array($a)) {
$a = (object) $a;
}
if (is_array($b)) {
$b = (object) $b;
}
return strcmp($a->$field, $b->$field);
};
} elseif (is_callable($field)) {
$sorter = $field;
} else {
return $this;
}
return parent::sort($sorter, $options);
} | [
"public",
"function",
"sort",
"(",
"$",
"field",
"=",
"'id'",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"offsetGet",
"(",
"null",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"field",
")",
")",
"{",
"$",
"sorter",
... | Sorts the objects in the collection, useful in situations where
you are already using the underlying datastore to sort results.
Overriden to load any data that has not yet been loaded.
@see lithium\util\Collection::sort()
@param string|callable $field The field to sort the data on, can also be a callback
to a custom sort function.
@param array $options Reserved for future use.
@return lithium\data\Collection Returns itself. | [
"Sorts",
"the",
"objects",
"in",
"the",
"collection",
"useful",
"in",
"situations",
"where",
"you",
"are",
"already",
"using",
"the",
"underlying",
"datastore",
"to",
"sort",
"results",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/Collection.php#L495-L514 |
UnionOfRAD/lithium | data/Collection.php | Collection.to | public function to($format, array $options = []) {
$defaults = ['internal' => false, 'indexed' => true, 'handlers' => []];
$options += $defaults;
$options['handlers'] += $this->_handlers;
$this->offsetGet(null);
$index = $options['indexed'] || ($options['indexed'] === null && $this->_parent === null);
if (!$index) {
$data = array_values($this->_data);
} else {
$data = $options['internal'] ? $this->_data : $this;
}
return $this->_to($format, $data, $options);
} | php | public function to($format, array $options = []) {
$defaults = ['internal' => false, 'indexed' => true, 'handlers' => []];
$options += $defaults;
$options['handlers'] += $this->_handlers;
$this->offsetGet(null);
$index = $options['indexed'] || ($options['indexed'] === null && $this->_parent === null);
if (!$index) {
$data = array_values($this->_data);
} else {
$data = $options['internal'] ? $this->_data : $this;
}
return $this->_to($format, $data, $options);
} | [
"public",
"function",
"to",
"(",
"$",
"format",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'internal'",
"=>",
"false",
",",
"'indexed'",
"=>",
"true",
",",
"'handlers'",
"=>",
"[",
"]",
"]",
";",
"$",
"option... | Converts a `Collection` object to another type of object, or a simple type such as an array.
The supported values of `$format` depend on the format handlers registered in the static
property `Collection::$_formats`. The `Collection` class comes with built-in support for
array conversion, but other formats may be registered.
Once the appropriate handlers are registered, a `Collection` instance can be converted into
any handler-supported format, i.e.:
```
$collection->to('json'); // returns a JSON string
$collection->to('xml'); // returns an XML string
```
_Please note that Lithium does not ship with a default XML handler, but one can be
configured easily._
@see lithium\util\Collection::toArray()
@see lithium\util\Collection::formats()
@see lithium\util\Collection::$_formats
@param string $format By default the only supported value is `'array'`. However, additional
format handlers can be registered using the `formats()` method.
@param array $options Options for converting this collection:
- `'internal'` _boolean_: Indicates whether the current internal representation of the
collection should be exported. Defaults to `false`, which uses the standard iterator
interfaces. This is useful for exporting record sets, where records are lazy-loaded,
and the collection must be iterated in order to fetch all objects.
- `'indexed'` _boolean|null_: Allows to control how converted data is keyed. When set
to `true` will force indexed conversion of the collection (the default) even if the
collection has a parent. When `false` will convert without indexing. Provide `null`
as a value to this option to only index when the collection has no parent.
@return mixed The object converted to the value specified in `$format`; usually an array or
string. | [
"Converts",
"a",
"Collection",
"object",
"to",
"another",
"type",
"of",
"object",
"or",
"a",
"simple",
"type",
"such",
"as",
"an",
"array",
".",
"The",
"supported",
"values",
"of",
"$format",
"depend",
"on",
"the",
"format",
"handlers",
"registered",
"in",
... | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/Collection.php#L558-L572 |
UnionOfRAD/lithium | data/Collection.php | Collection.stats | public function stats($name = null) {
if ($name) {
return isset($this->_stats[$name]) ? $this->_stats[$name] : null;
}
return $this->_stats;
} | php | public function stats($name = null) {
if ($name) {
return isset($this->_stats[$name]) ? $this->_stats[$name] : null;
}
return $this->_stats;
} | [
"public",
"function",
"stats",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"name",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"_stats",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"this",
"->",
"_stats",
"[",
"$",
"name",
"]",
... | Gets the stat or stats associated with this `Collection`.
@param string $name Stat name.
@return mixed Single stat if `$name` supplied, else all stats for this
`Collection`. | [
"Gets",
"the",
"stat",
"or",
"stats",
"associated",
"with",
"this",
"Collection",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/Collection.php#L592-L597 |
UnionOfRAD/lithium | data/Collection.php | Collection.serialize | public function serialize() {
$this->offsetGet(null);
static::__destruct();
$vars = get_object_vars($this);
unset($vars['_result']);
unset($vars['_handlers']);
return serialize($vars);
} | php | public function serialize() {
$this->offsetGet(null);
static::__destruct();
$vars = get_object_vars($this);
unset($vars['_result']);
unset($vars['_handlers']);
return serialize($vars);
} | [
"public",
"function",
"serialize",
"(",
")",
"{",
"$",
"this",
"->",
"offsetGet",
"(",
"null",
")",
";",
"static",
"::",
"__destruct",
"(",
")",
";",
"$",
"vars",
"=",
"get_object_vars",
"(",
"$",
"this",
")",
";",
"unset",
"(",
"$",
"vars",
"[",
"... | Prepares, enables and executes serialization of the object.
Note: because of the limitations outlined below custom
handlers are ignored with serialized objects.
Pulls all results to entirely populate `_data` and closes the object
freeing the associated result resource. This allows for skipping
the `_result` property which may hold unserializable `PDOStatement`s.
Properties that hold anonymous functions are also skipped. Some of these
can almost be reconstructed (`_handlers`).
@return string Serialized properties of the object. | [
"Prepares",
"enables",
"and",
"executes",
"serialization",
"of",
"the",
"object",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/Collection.php#L645-L654 |
UnionOfRAD/lithium | data/Collection.php | Collection.unserialize | public function unserialize($data) {
$vars = unserialize($data);
parent::_init();
foreach ($vars as $key => $value) {
$this->{$key} = $value;
}
} | php | public function unserialize($data) {
$vars = unserialize($data);
parent::_init();
foreach ($vars as $key => $value) {
$this->{$key} = $value;
}
} | [
"public",
"function",
"unserialize",
"(",
"$",
"data",
")",
"{",
"$",
"vars",
"=",
"unserialize",
"(",
"$",
"data",
")",
";",
"parent",
"::",
"_init",
"(",
")",
";",
"foreach",
"(",
"$",
"vars",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$"... | Prepares, enables and executes unserialization of the object.
Restores state of the object including pulled results. Tries
to restore `_handlers` by calling into `_init()`.
@param string $data Serialized properties of the object.
@return void | [
"Prepares",
"enables",
"and",
"executes",
"unserialization",
"of",
"the",
"object",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/Collection.php#L665-L672 |
UnionOfRAD/lithium | console/command/create/Mock.php | Mock._namespace | protected function _namespace($request, $options = []) {
$request->params['command'] = $request->action;
return parent::_namespace($request, ['prepend' => 'tests.mocks.']);
} | php | protected function _namespace($request, $options = []) {
$request->params['command'] = $request->action;
return parent::_namespace($request, ['prepend' => 'tests.mocks.']);
} | [
"protected",
"function",
"_namespace",
"(",
"$",
"request",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"request",
"->",
"params",
"[",
"'command'",
"]",
"=",
"$",
"request",
"->",
"action",
";",
"return",
"parent",
"::",
"_namespace",
"(",
"$",... | Get the namespace for the mock.
@param string $request
@param array|string $options
@return string | [
"Get",
"the",
"namespace",
"for",
"the",
"mock",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/console/command/create/Mock.php#L30-L33 |
UnionOfRAD/lithium | console/command/create/Mock.php | Mock._class | protected function _class($request) {
$type = $request->action;
$name = $request->args();
if ($command = $this->_instance($type)) {
$request->params['action'] = $name;
$name = $command->invokeMethod('_class', [$request]);
}
return "Mock{$name}";
} | php | protected function _class($request) {
$type = $request->action;
$name = $request->args();
if ($command = $this->_instance($type)) {
$request->params['action'] = $name;
$name = $command->invokeMethod('_class', [$request]);
}
return "Mock{$name}";
} | [
"protected",
"function",
"_class",
"(",
"$",
"request",
")",
"{",
"$",
"type",
"=",
"$",
"request",
"->",
"action",
";",
"$",
"name",
"=",
"$",
"request",
"->",
"args",
"(",
")",
";",
"if",
"(",
"$",
"command",
"=",
"$",
"this",
"->",
"_instance",
... | Get the class name for the mock.
@param string $request
@return string | [
"Get",
"the",
"class",
"name",
"for",
"the",
"mock",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/console/command/create/Mock.php#L53-L62 |
UnionOfRAD/lithium | analysis/logger/adapter/Growl.php | Growl.write | public function write($priority, $message, array $options = []) {
return function($params) {
$priority = 0;
$options = $params['options'];
if (isset($options['priority']) && isset($this->_priorities[$options['priority']])) {
$priority = $this->_priorities[$options['priority']];
}
return $this->notify($params['message'], compact('priority') + $options);
};
} | php | public function write($priority, $message, array $options = []) {
return function($params) {
$priority = 0;
$options = $params['options'];
if (isset($options['priority']) && isset($this->_priorities[$options['priority']])) {
$priority = $this->_priorities[$options['priority']];
}
return $this->notify($params['message'], compact('priority') + $options);
};
} | [
"public",
"function",
"write",
"(",
"$",
"priority",
",",
"$",
"message",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"return",
"function",
"(",
"$",
"params",
")",
"{",
"$",
"priority",
"=",
"0",
";",
"$",
"options",
"=",
"$",
"params",... | Writes `$message` to a new Growl notification.
@param string $priority The `Logger`-based priority of the message. This value is mapped
to a Growl-specific priority value if possible.
@param string $message Message to be shown.
@param array $options Any options that are passed to the `notify()` method. See the
`$options` parameter of `notify()`.
@return \Closure Function returning boolean `true` on successful write, `false` otherwise. | [
"Writes",
"$message",
"to",
"a",
"new",
"Growl",
"notification",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/logger/adapter/Growl.php#L130-L140 |
UnionOfRAD/lithium | analysis/logger/adapter/Growl.php | Growl.notify | public function notify($description = '', $options = []) {
$this->_register();
$defaults = ['sticky' => false, 'priority' => 0, 'type' => 'Messages'];
$options += $defaults + ['title' => $this->_config['title']];
$type = $options['type'];
$title = $options['title'];
$message = compact('type', 'title', 'description') + ['app' => $this->_config['name']];
$message = array_map('utf8_encode', $message);
$flags = ($options['priority'] & 7) * 2;
$flags = ($options['priority'] < 0) ? $flags |= 8 : $flags;
$flags = ($options['sticky']) ? $flags | 256 : $flags;
$params = ['c2n5', static::PROTOCOL_VERSION, static::TYPE_NOTIFY, $flags];
$lengths = array_map('strlen', $message);
$data = call_user_func_array('pack', array_merge($params, $lengths));
$data .= join('', $message);
$data .= pack('H32', md5($data . $this->_config['password']));
$this->_send($data);
return true;
} | php | public function notify($description = '', $options = []) {
$this->_register();
$defaults = ['sticky' => false, 'priority' => 0, 'type' => 'Messages'];
$options += $defaults + ['title' => $this->_config['title']];
$type = $options['type'];
$title = $options['title'];
$message = compact('type', 'title', 'description') + ['app' => $this->_config['name']];
$message = array_map('utf8_encode', $message);
$flags = ($options['priority'] & 7) * 2;
$flags = ($options['priority'] < 0) ? $flags |= 8 : $flags;
$flags = ($options['sticky']) ? $flags | 256 : $flags;
$params = ['c2n5', static::PROTOCOL_VERSION, static::TYPE_NOTIFY, $flags];
$lengths = array_map('strlen', $message);
$data = call_user_func_array('pack', array_merge($params, $lengths));
$data .= join('', $message);
$data .= pack('H32', md5($data . $this->_config['password']));
$this->_send($data);
return true;
} | [
"public",
"function",
"notify",
"(",
"$",
"description",
"=",
"''",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"_register",
"(",
")",
";",
"$",
"defaults",
"=",
"[",
"'sticky'",
"=>",
"false",
",",
"'priority'",
"=>",
"0",
","... | Posts a new notification to the Growl server.
@param string $description Message to be displayed.
@param array $options Options consists of:
-'title': The title of the displayed notification. Displays the
name of the application's parent folder by default.
@return boolean Always returns `true`. | [
"Posts",
"a",
"new",
"notification",
"to",
"the",
"Growl",
"server",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/logger/adapter/Growl.php#L151-L175 |
UnionOfRAD/lithium | analysis/logger/adapter/Growl.php | Growl._register | protected function _register() {
if ($this->_registered) {
return true;
}
$ct = count($this->_config['notifications']);
$app = utf8_encode($this->_config['name']);
$nameEnc = $defaultEnc = '';
foreach ($this->_config['notifications'] as $i => $name) {
$name = utf8_encode($name);
$nameEnc .= pack('n', strlen($name)) . $name;
$defaultEnc .= pack('c', $i);
}
$data = pack('c2nc2', static::PROTOCOL_VERSION, static::TYPE_REG, strlen($app), $ct, $ct);
$data .= $app . $nameEnc . $defaultEnc;
$checksum = pack('H32', md5($data . $this->_config['password']));
$data .= $checksum;
$this->_send($data);
return $this->_registered = true;
} | php | protected function _register() {
if ($this->_registered) {
return true;
}
$ct = count($this->_config['notifications']);
$app = utf8_encode($this->_config['name']);
$nameEnc = $defaultEnc = '';
foreach ($this->_config['notifications'] as $i => $name) {
$name = utf8_encode($name);
$nameEnc .= pack('n', strlen($name)) . $name;
$defaultEnc .= pack('c', $i);
}
$data = pack('c2nc2', static::PROTOCOL_VERSION, static::TYPE_REG, strlen($app), $ct, $ct);
$data .= $app . $nameEnc . $defaultEnc;
$checksum = pack('H32', md5($data . $this->_config['password']));
$data .= $checksum;
$this->_send($data);
return $this->_registered = true;
} | [
"protected",
"function",
"_register",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_registered",
")",
"{",
"return",
"true",
";",
"}",
"$",
"ct",
"=",
"count",
"(",
"$",
"this",
"->",
"_config",
"[",
"'notifications'",
"]",
")",
";",
"$",
"app",
"... | Growl server connection registration and initialization.
@return boolean True | [
"Growl",
"server",
"connection",
"registration",
"and",
"initialization",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/logger/adapter/Growl.php#L182-L202 |
UnionOfRAD/lithium | analysis/logger/adapter/Growl.php | Growl._connection | protected function _connection() {
if ($this->_connection) {
return $this->_connection;
}
$host = "{$this->_config['protocol']}://{$this->_config['host']}";
if ($this->_connection = fsockopen($host, $this->_config['port'], $message, $code)) {
return $this->_connection;
}
throw new NetworkException("Growl connection failed: (`{$code}`) `{$message}`.");
} | php | protected function _connection() {
if ($this->_connection) {
return $this->_connection;
}
$host = "{$this->_config['protocol']}://{$this->_config['host']}";
if ($this->_connection = fsockopen($host, $this->_config['port'], $message, $code)) {
return $this->_connection;
}
throw new NetworkException("Growl connection failed: (`{$code}`) `{$message}`.");
} | [
"protected",
"function",
"_connection",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_connection",
")",
"{",
"return",
"$",
"this",
"->",
"_connection",
";",
"}",
"$",
"host",
"=",
"\"{$this->_config['protocol']}://{$this->_config['host']}\"",
";",
"if",
"(",
... | Creates a connection to the Growl server using the protocol, host and port configurations
specified in the constructor.
@return resource Returns a connection resource created by `fsockopen()`. | [
"Creates",
"a",
"connection",
"to",
"the",
"Growl",
"server",
"using",
"the",
"protocol",
"host",
"and",
"port",
"configurations",
"specified",
"in",
"the",
"constructor",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/logger/adapter/Growl.php#L210-L220 |
UnionOfRAD/lithium | analysis/logger/adapter/Growl.php | Growl._send | protected function _send($data) {
if (fwrite($this->_connection(), $data, strlen($data)) === false) {
throw new NetworkException('Could not send registration to Growl Server.');
}
return true;
} | php | protected function _send($data) {
if (fwrite($this->_connection(), $data, strlen($data)) === false) {
throw new NetworkException('Could not send registration to Growl Server.');
}
return true;
} | [
"protected",
"function",
"_send",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"fwrite",
"(",
"$",
"this",
"->",
"_connection",
"(",
")",
",",
"$",
"data",
",",
"strlen",
"(",
"$",
"data",
")",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"NetworkExcep... | Sends binary data to the Growl server.
@throws NetworkException Throws an exception if the server connection could not be written
to.
@param string $data The raw binary data to send to the Growl server.
@return boolean Always returns `true`. | [
"Sends",
"binary",
"data",
"to",
"the",
"Growl",
"server",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/logger/adapter/Growl.php#L230-L235 |
UnionOfRAD/lithium | net/socket/Curl.php | Curl.open | public function open(array $options = []) {
$this->options = [];
parent::open($options);
$config = $this->_config;
if (empty($config['scheme']) || empty($config['host'])) {
return false;
}
if (!empty($config['options'])) {
$this->set($config['options']);
}
$url = "{$config['scheme']}://{$config['host']}";
$this->_resource = curl_init($url);
$this->set([
CURLOPT_PORT => $config['port'],
CURLOPT_HEADER => true,
CURLOPT_RETURNTRANSFER => true
]);
if (!is_resource($this->_resource)) {
return false;
}
$this->_isConnected = true;
$this->timeout($config['timeout']);
if (isset($config['encoding'])) {
$this->encoding($config['encoding']);
}
return $this->_resource;
} | php | public function open(array $options = []) {
$this->options = [];
parent::open($options);
$config = $this->_config;
if (empty($config['scheme']) || empty($config['host'])) {
return false;
}
if (!empty($config['options'])) {
$this->set($config['options']);
}
$url = "{$config['scheme']}://{$config['host']}";
$this->_resource = curl_init($url);
$this->set([
CURLOPT_PORT => $config['port'],
CURLOPT_HEADER => true,
CURLOPT_RETURNTRANSFER => true
]);
if (!is_resource($this->_resource)) {
return false;
}
$this->_isConnected = true;
$this->timeout($config['timeout']);
if (isset($config['encoding'])) {
$this->encoding($config['encoding']);
}
return $this->_resource;
} | [
"public",
"function",
"open",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"options",
"=",
"[",
"]",
";",
"parent",
"::",
"open",
"(",
"$",
"options",
")",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"_config",
";",
... | Opens a curl connection and initializes the internal resource handle.
@param array $options update the config settings
if $options['options'] exists, will be passed to $this->set()
@return mixed Returns `false` if the socket configuration does not contain the
`'scheme'` or `'host'` settings, or if configuration fails, otherwise returns a
resource stream. | [
"Opens",
"a",
"curl",
"connection",
"and",
"initializes",
"the",
"internal",
"resource",
"handle",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/net/socket/Curl.php#L60-L90 |
UnionOfRAD/lithium | net/socket/Curl.php | Curl.close | public function close() {
if (!is_resource($this->_resource)) {
return true;
}
curl_close($this->_resource);
return !is_resource($this->_resource);
} | php | public function close() {
if (!is_resource($this->_resource)) {
return true;
}
curl_close($this->_resource);
return !is_resource($this->_resource);
} | [
"public",
"function",
"close",
"(",
")",
"{",
"if",
"(",
"!",
"is_resource",
"(",
"$",
"this",
"->",
"_resource",
")",
")",
"{",
"return",
"true",
";",
"}",
"curl_close",
"(",
"$",
"this",
"->",
"_resource",
")",
";",
"return",
"!",
"is_resource",
"(... | Closes the curl connection.
@return boolean True on closed connection | [
"Closes",
"the",
"curl",
"connection",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/net/socket/Curl.php#L97-L103 |
UnionOfRAD/lithium | net/socket/Curl.php | Curl.write | public function write($data = null) {
if (!is_resource($this->_resource)) {
return false;
}
if (!is_object($data)) {
$data = $this->_instance($this->_classes['request'], (array) $data + $this->_config);
}
$this->set(CURLOPT_URL, $data->to('url'));
if ($data instanceof Message) {
if (!empty($this->_config['ignoreExpect'])) {
$data->headers('Expect', ' ');
}
if (isset($data->headers)) {
$this->set(CURLOPT_HTTPHEADER, $data->headers());
}
if (isset($data->method) && $data->method === 'POST') {
$this->set([CURLOPT_POST => true, CURLOPT_POSTFIELDS => $data->body()]);
}
if (isset($data->method) && in_array($data->method,['PUT','PATCH','DELETE'])) {
$this->set([
CURLOPT_CUSTOMREQUEST => $data->method,
CURLOPT_POSTFIELDS => $data->body()
]);
}
}
return (boolean) curl_setopt_array($this->_resource, $this->options);
} | php | public function write($data = null) {
if (!is_resource($this->_resource)) {
return false;
}
if (!is_object($data)) {
$data = $this->_instance($this->_classes['request'], (array) $data + $this->_config);
}
$this->set(CURLOPT_URL, $data->to('url'));
if ($data instanceof Message) {
if (!empty($this->_config['ignoreExpect'])) {
$data->headers('Expect', ' ');
}
if (isset($data->headers)) {
$this->set(CURLOPT_HTTPHEADER, $data->headers());
}
if (isset($data->method) && $data->method === 'POST') {
$this->set([CURLOPT_POST => true, CURLOPT_POSTFIELDS => $data->body()]);
}
if (isset($data->method) && in_array($data->method,['PUT','PATCH','DELETE'])) {
$this->set([
CURLOPT_CUSTOMREQUEST => $data->method,
CURLOPT_POSTFIELDS => $data->body()
]);
}
}
return (boolean) curl_setopt_array($this->_resource, $this->options);
} | [
"public",
"function",
"write",
"(",
"$",
"data",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_resource",
"(",
"$",
"this",
"->",
"_resource",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"is_object",
"(",
"$",
"data",
")",
")",
"{",
... | Writes data to curl options
@param array|\lithium\net\Message $data
@return boolean | [
"Writes",
"data",
"to",
"curl",
"options"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/net/socket/Curl.php#L135-L162 |
UnionOfRAD/lithium | net/socket/Curl.php | Curl.timeout | public function timeout($time) {
if (!is_resource($this->_resource)) {
return false;
}
return curl_setopt($this->_resource, CURLOPT_CONNECTTIMEOUT, $time);
} | php | public function timeout($time) {
if (!is_resource($this->_resource)) {
return false;
}
return curl_setopt($this->_resource, CURLOPT_CONNECTTIMEOUT, $time);
} | [
"public",
"function",
"timeout",
"(",
"$",
"time",
")",
"{",
"if",
"(",
"!",
"is_resource",
"(",
"$",
"this",
"->",
"_resource",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"curl_setopt",
"(",
"$",
"this",
"->",
"_resource",
",",
"CURLOPT_CON... | A convenience method to set the curl `CURLOPT_CONNECTTIMEOUT`
setting for the current connection. This determines the number
of seconds to wait while trying to connect.
Note: A value of 0 may be used to specify an indefinite wait time.
@param integer $time The timeout value in seconds
@return boolean False if the resource handle is unavailable or the
option could not be set, true otherwise. | [
"A",
"convenience",
"method",
"to",
"set",
"the",
"curl",
"CURLOPT_CONNECTTIMEOUT",
"setting",
"for",
"the",
"current",
"connection",
".",
"This",
"determines",
"the",
"number",
"of",
"seconds",
"to",
"wait",
"while",
"trying",
"to",
"connect",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/net/socket/Curl.php#L175-L180 |
UnionOfRAD/lithium | net/socket/Curl.php | Curl.set | public function set($flags, $value = null) {
if ($value !== null) {
$flags = [$flags => $value];
}
$this->options = $flags + $this->options;
} | php | public function set($flags, $value = null) {
if ($value !== null) {
$flags = [$flags => $value];
}
$this->options = $flags + $this->options;
} | [
"public",
"function",
"set",
"(",
"$",
"flags",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"value",
"!==",
"null",
")",
"{",
"$",
"flags",
"=",
"[",
"$",
"flags",
"=>",
"$",
"value",
"]",
";",
"}",
"$",
"this",
"->",
"options",
... | Sets the options to be used in subsequent curl requests.
@link http://php.net/curl.constants.php PHP Manual: cURL Constants
@param array $flags If $values is an array, $flags will be used as the
keys to an associative array of curl options. If $values is not set,
then $flags will be used as the associative array.
@param array $value If set, this array becomes the values for the
associative array of curl options.
@return void | [
"Sets",
"the",
"options",
"to",
"be",
"used",
"in",
"subsequent",
"curl",
"requests",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/net/socket/Curl.php#L201-L206 |
UnionOfRAD/lithium | data/source/database/adapter/MySql.php | MySql._init | protected function _init() {
if (!$this->_config['host']) {
throw new ConfigException('No host configured.');
}
if (HostString::isSocket($this->_config['host'])) {
$this->_config['dsn'] = sprintf(
'mysql:unix_socket=%s;dbname=%s',
$this->_config['host'],
$this->_config['database']
);
} else {
$host = HostString::parse($this->_config['host']) + [
'host' => static::DEFAULT_HOST,
'port' => static::DEFAULT_PORT
];
$this->_config['dsn'] = sprintf(
'mysql:host=%s;port=%s;dbname=%s',
$host['host'],
$host['port'],
$this->_config['database']
);
}
parent::_init();
$this->_operators += [
'REGEXP' => [],
'NOT REGEXP' => [],
'SOUNDS LIKE' => []
];
} | php | protected function _init() {
if (!$this->_config['host']) {
throw new ConfigException('No host configured.');
}
if (HostString::isSocket($this->_config['host'])) {
$this->_config['dsn'] = sprintf(
'mysql:unix_socket=%s;dbname=%s',
$this->_config['host'],
$this->_config['database']
);
} else {
$host = HostString::parse($this->_config['host']) + [
'host' => static::DEFAULT_HOST,
'port' => static::DEFAULT_PORT
];
$this->_config['dsn'] = sprintf(
'mysql:host=%s;port=%s;dbname=%s',
$host['host'],
$host['port'],
$this->_config['database']
);
}
parent::_init();
$this->_operators += [
'REGEXP' => [],
'NOT REGEXP' => [],
'SOUNDS LIKE' => []
];
} | [
"protected",
"function",
"_init",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_config",
"[",
"'host'",
"]",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"'No host configured.'",
")",
";",
"}",
"if",
"(",
"HostString",
"::",
"isSocket",
"(",
... | Initializer. Adds MySQL-specific operators to `$_operators`. Constructs
a DSN from configuration.
@see lithium\data\source\database\adapter\MySql::$_operators
@see lithium\data\source\Database::$_operators
@return void | [
"Initializer",
".",
"Adds",
"MySQL",
"-",
"specific",
"operators",
"to",
"$_operators",
".",
"Constructs",
"a",
"DSN",
"from",
"configuration",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/database/adapter/MySql.php#L169-L199 |
UnionOfRAD/lithium | data/source/database/adapter/MySql.php | MySql.connect | public function connect() {
if (!parent::connect()) {
return false;
}
if ($this->_config['strict'] !== null && !$this->strict($this->_config['strict'])) {
return false;
}
return true;
} | php | public function connect() {
if (!parent::connect()) {
return false;
}
if ($this->_config['strict'] !== null && !$this->strict($this->_config['strict'])) {
return false;
}
return true;
} | [
"public",
"function",
"connect",
"(",
")",
"{",
"if",
"(",
"!",
"parent",
"::",
"connect",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_config",
"[",
"'strict'",
"]",
"!==",
"null",
"&&",
"!",
"$",
"this",
"->"... | Connects to the database by creating a PDO intance using the constructed DSN string.
Will set specific options on the connection as provided.
@return boolean Returns `true` if a database connection could be established,
otherwise `false`. | [
"Connects",
"to",
"the",
"database",
"by",
"creating",
"a",
"PDO",
"intance",
"using",
"the",
"constructed",
"DSN",
"string",
".",
"Will",
"set",
"specific",
"options",
"on",
"the",
"connection",
"as",
"provided",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/database/adapter/MySql.php#L208-L216 |
UnionOfRAD/lithium | data/source/database/adapter/MySql.php | MySql.strict | public function strict($value = null) {
if ($value === null) {
return strpos(
$this->connection->query('SELECT @@SESSION.sql_mode')->fetchColumn(),
'STRICT_ALL_TABLES'
) !== false;
}
if ($value) {
$sql = "SET SESSION sql_mode = 'STRICT_ALL_TABLES'";
} else {
$sql = "SET SESSION sql_mode = ''";
}
return $this->connection->exec($sql) !== false;
} | php | public function strict($value = null) {
if ($value === null) {
return strpos(
$this->connection->query('SELECT @@SESSION.sql_mode')->fetchColumn(),
'STRICT_ALL_TABLES'
) !== false;
}
if ($value) {
$sql = "SET SESSION sql_mode = 'STRICT_ALL_TABLES'";
} else {
$sql = "SET SESSION sql_mode = ''";
}
return $this->connection->exec($sql) !== false;
} | [
"public",
"function",
"strict",
"(",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"strpos",
"(",
"$",
"this",
"->",
"connection",
"->",
"query",
"(",
"'SELECT @@SESSION.sql_mode'",
")",
"->",
"fetchColu... | Enables/disables or retrieves strictness setting.
This method will only operate on _session_ level, it will not check/set
_global_ settings. `STRICT_ALL_TABLES` mode is used to enable strict mode.
@link http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sql-mode-strict
@param boolean|null $value `true` to enable strict mode, `false` to disable or `null`
to retrieve the current setting.
@return boolean When setting, returns `true` on success, else `false`. When $value was
`null` return either `true` or `false` indicating whether strict mode is enabled
or disabled. | [
"Enables",
"/",
"disables",
"or",
"retrieves",
"strictness",
"setting",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/database/adapter/MySql.php#L332-L345 |
UnionOfRAD/lithium | data/source/database/adapter/MySql.php | MySql._execute | protected function _execute($sql, array $options = []) {
$defaults = ['buffered' => true];
$options += $defaults;
$params = compact('sql', 'options');
return Filters::run($this, __FUNCTION__, $params, function($params) {
$this->connection->setAttribute(
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,
$params['options']['buffered']
);
try {
$resource = $this->connection->query($params['sql']);
} catch (PDOException $e) {
$this->_error($params['sql']);
};
return $this->_instance('result', compact('resource'));
});
} | php | protected function _execute($sql, array $options = []) {
$defaults = ['buffered' => true];
$options += $defaults;
$params = compact('sql', 'options');
return Filters::run($this, __FUNCTION__, $params, function($params) {
$this->connection->setAttribute(
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,
$params['options']['buffered']
);
try {
$resource = $this->connection->query($params['sql']);
} catch (PDOException $e) {
$this->_error($params['sql']);
};
return $this->_instance('result', compact('resource'));
});
} | [
"protected",
"function",
"_execute",
"(",
"$",
"sql",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'buffered'",
"=>",
"true",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"$",
"params",
"=",
"compact",
... | Execute a given query.
@see lithium\data\source\Database::renderCommand()
@param string $sql The sql string to execute
@param array $options Available options:
- 'buffered': If set to `false` uses mysql_unbuffered_query which
sends the SQL query query to MySQL without automatically fetching and buffering the
result rows as `mysql_query()` does (for less memory usage).
@return \lithium\data\source\Result Returns a result object if the query was successful.
@filter | [
"Execute",
"a",
"given",
"query",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/database/adapter/MySql.php#L392-L410 |
UnionOfRAD/lithium | data/source/database/adapter/MySql.php | MySql._insertId | protected function _insertId($query) {
$row = $this->_execute('SELECT LAST_INSERT_ID() AS insertID')->current();
return ($row[0] && $row[0] !== '0') ? $row[0] : null;
} | php | protected function _insertId($query) {
$row = $this->_execute('SELECT LAST_INSERT_ID() AS insertID')->current();
return ($row[0] && $row[0] !== '0') ? $row[0] : null;
} | [
"protected",
"function",
"_insertId",
"(",
"$",
"query",
")",
"{",
"$",
"row",
"=",
"$",
"this",
"->",
"_execute",
"(",
"'SELECT LAST_INSERT_ID() AS insertID'",
")",
"->",
"current",
"(",
")",
";",
"return",
"(",
"$",
"row",
"[",
"0",
"]",
"&&",
"$",
"... | Gets the last auto-generated ID from the query that inserted a new record.
@param object $query The `Query` object associated with the query which generated
@return mixed Returns the last inserted ID key for an auto-increment column or a column
bound to a sequence. | [
"Gets",
"the",
"last",
"auto",
"-",
"generated",
"ID",
"from",
"the",
"query",
"that",
"inserted",
"a",
"new",
"record",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/database/adapter/MySql.php#L419-L422 |
UnionOfRAD/lithium | data/source/database/adapter/MySql.php | MySql._column | protected function _column($real) {
if (is_array($real)) {
return $real['type'] . (isset($real['length']) ? "({$real['length']})" : '');
}
if (!preg_match('/(?P<type>\w+)(?:\((?P<length>[\d,]+)\))?/', $real, $column)) {
return $real;
}
$column = array_intersect_key($column, ['type' => null, 'length' => null]);
if (isset($column['length']) && $column['length']) {
$length = explode(',', $column['length']) + [null, null];
$column['length'] = $length[0] ? (integer) $length[0] : null;
$length[1] ? $column['precision'] = (integer) $length[1] : null;
}
switch (true) {
case in_array($column['type'], ['date', 'time', 'datetime', 'timestamp']):
return $column;
case ($column['type'] === 'tinyint' && $column['length'] == '1'):
case ($column['type'] === 'boolean'):
return ['type' => 'boolean'];
break;
case (strpos($column['type'], 'int') !== false):
$column['type'] = 'integer';
break;
case (strpos($column['type'], 'char') !== false || $column['type'] === 'tinytext'):
$column['type'] = 'string';
break;
case (strpos($column['type'], 'text') !== false):
$column['type'] = 'text';
break;
case (strpos($column['type'], 'blob') !== false || $column['type'] === 'binary'):
$column['type'] = 'binary';
break;
case preg_match('/float|double|decimal/', $column['type']):
$column['type'] = 'float';
break;
default:
$column['type'] = 'text';
break;
}
return $column;
} | php | protected function _column($real) {
if (is_array($real)) {
return $real['type'] . (isset($real['length']) ? "({$real['length']})" : '');
}
if (!preg_match('/(?P<type>\w+)(?:\((?P<length>[\d,]+)\))?/', $real, $column)) {
return $real;
}
$column = array_intersect_key($column, ['type' => null, 'length' => null]);
if (isset($column['length']) && $column['length']) {
$length = explode(',', $column['length']) + [null, null];
$column['length'] = $length[0] ? (integer) $length[0] : null;
$length[1] ? $column['precision'] = (integer) $length[1] : null;
}
switch (true) {
case in_array($column['type'], ['date', 'time', 'datetime', 'timestamp']):
return $column;
case ($column['type'] === 'tinyint' && $column['length'] == '1'):
case ($column['type'] === 'boolean'):
return ['type' => 'boolean'];
break;
case (strpos($column['type'], 'int') !== false):
$column['type'] = 'integer';
break;
case (strpos($column['type'], 'char') !== false || $column['type'] === 'tinytext'):
$column['type'] = 'string';
break;
case (strpos($column['type'], 'text') !== false):
$column['type'] = 'text';
break;
case (strpos($column['type'], 'blob') !== false || $column['type'] === 'binary'):
$column['type'] = 'binary';
break;
case preg_match('/float|double|decimal/', $column['type']):
$column['type'] = 'float';
break;
default:
$column['type'] = 'text';
break;
}
return $column;
} | [
"protected",
"function",
"_column",
"(",
"$",
"real",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"real",
")",
")",
"{",
"return",
"$",
"real",
"[",
"'type'",
"]",
".",
"(",
"isset",
"(",
"$",
"real",
"[",
"'length'",
"]",
")",
"?",
"\"({$real['leng... | Converts database-layer column types to basic types.
@param string $real Real database-layer column type (i.e. `"varchar(255)"`)
@return array Column type (i.e. "string") plus 'length' when appropriate. | [
"Converts",
"database",
"-",
"layer",
"column",
"types",
"to",
"basic",
"types",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/database/adapter/MySql.php#L430-L473 |
UnionOfRAD/lithium | data/source/database/adapter/MySql.php | MySql._buildColumn | protected function _buildColumn($field) {
extract($field);
if ($type === 'float' && $precision) {
$use = 'decimal';
}
$out = $this->name($name) . ' ' . $use;
$allowPrecision = preg_match('/^(decimal|float|double|real|numeric)$/',$use);
$precision = ($precision && $allowPrecision) ? ",{$precision}" : '';
if ($length && ($allowPrecision || preg_match('/(char|binary|int|year)/',$use))) {
$out .= "({$length}{$precision})";
}
$out .= $this->_buildMetas('column', $field, ['charset', 'collate']);
if (isset($increment) && $increment) {
$out .= ' NOT NULL AUTO_INCREMENT';
} else {
$out .= is_bool($null) ? ($null ? ' NULL' : ' NOT NULL') : '' ;
$out .= $default ? ' DEFAULT ' . $this->value($default, $field) : '';
}
return $out . $this->_buildMetas('column', $field, ['comment']);
} | php | protected function _buildColumn($field) {
extract($field);
if ($type === 'float' && $precision) {
$use = 'decimal';
}
$out = $this->name($name) . ' ' . $use;
$allowPrecision = preg_match('/^(decimal|float|double|real|numeric)$/',$use);
$precision = ($precision && $allowPrecision) ? ",{$precision}" : '';
if ($length && ($allowPrecision || preg_match('/(char|binary|int|year)/',$use))) {
$out .= "({$length}{$precision})";
}
$out .= $this->_buildMetas('column', $field, ['charset', 'collate']);
if (isset($increment) && $increment) {
$out .= ' NOT NULL AUTO_INCREMENT';
} else {
$out .= is_bool($null) ? ($null ? ' NULL' : ' NOT NULL') : '' ;
$out .= $default ? ' DEFAULT ' . $this->value($default, $field) : '';
}
return $out . $this->_buildMetas('column', $field, ['comment']);
} | [
"protected",
"function",
"_buildColumn",
"(",
"$",
"field",
")",
"{",
"extract",
"(",
"$",
"field",
")",
";",
"if",
"(",
"$",
"type",
"===",
"'float'",
"&&",
"$",
"precision",
")",
"{",
"$",
"use",
"=",
"'decimal'",
";",
"}",
"$",
"out",
"=",
"$",
... | Helper for `Database::column()`
@see lithium\data\Database::column()
@param array $field A field array.
@return string The SQL column string. | [
"Helper",
"for",
"Database",
"::",
"column",
"()"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/database/adapter/MySql.php#L482-L508 |
UnionOfRAD/lithium | storage/cache/Adapter.php | Adapter._addScopePrefix | protected function _addScopePrefix($scope, array $keys, $separator = ':') {
$results = [];
$isMapped = !is_int(key($keys));
foreach ($keys as $key => $value) {
if ($isMapped) {
$results["{$scope}{$separator}{$key}"] = $value;
} else {
$results[$key] = "{$scope}{$separator}{$value}";
}
}
return $results;
} | php | protected function _addScopePrefix($scope, array $keys, $separator = ':') {
$results = [];
$isMapped = !is_int(key($keys));
foreach ($keys as $key => $value) {
if ($isMapped) {
$results["{$scope}{$separator}{$key}"] = $value;
} else {
$results[$key] = "{$scope}{$separator}{$value}";
}
}
return $results;
} | [
"protected",
"function",
"_addScopePrefix",
"(",
"$",
"scope",
",",
"array",
"$",
"keys",
",",
"$",
"separator",
"=",
"':'",
")",
"{",
"$",
"results",
"=",
"[",
"]",
";",
"$",
"isMapped",
"=",
"!",
"is_int",
"(",
"key",
"(",
"$",
"keys",
")",
")",
... | Adds scope prefix to keys using separator.
@param string $scope Scope to use when prefixing.
@param array $keys Array of keys either with or without mapping to values.
@param string $separator String to use when separating scope from key.
@return array Prefixed keys array. | [
"Adds",
"scope",
"prefix",
"to",
"keys",
"using",
"separator",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/storage/cache/Adapter.php#L124-L136 |
UnionOfRAD/lithium | storage/cache/Adapter.php | Adapter._removeScopePrefix | protected function _removeScopePrefix($scope, array $data, $separator = ':') {
$results = [];
$prefix = strlen("{$scope}{$separator}");
foreach ($data as $key => $value) {
$results[substr($key, $prefix)] = $value;
}
return $results;
} | php | protected function _removeScopePrefix($scope, array $data, $separator = ':') {
$results = [];
$prefix = strlen("{$scope}{$separator}");
foreach ($data as $key => $value) {
$results[substr($key, $prefix)] = $value;
}
return $results;
} | [
"protected",
"function",
"_removeScopePrefix",
"(",
"$",
"scope",
",",
"array",
"$",
"data",
",",
"$",
"separator",
"=",
"':'",
")",
"{",
"$",
"results",
"=",
"[",
"]",
";",
"$",
"prefix",
"=",
"strlen",
"(",
"\"{$scope}{$separator}\"",
")",
";",
"foreac... | Removes scope prefix from keys.
@param string $scope Scope initially used when prefixing.
@param array $keys Array of keys mapping to values.
@param string $separator Separator used when prefix keys initially.
@return array Keys array with prefix removed from each key. | [
"Removes",
"scope",
"prefix",
"from",
"keys",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/storage/cache/Adapter.php#L146-L154 |
UnionOfRAD/lithium | console/command/Help.php | Help.run | public function run($command = null) {
if (!$command) {
$this->_renderCommands();
return true;
}
if (!preg_match('/\\\\/', $command)) {
$command = Inflector::camelize($command);
}
if (!$class = Libraries::locate('command', $command)) {
$this->error("Command `{$command}` not found");
return false;
}
if (strpos($command, '\\') !== false) {
$command = join('', array_slice(explode("\\", $command), -1));
}
$command = strtolower(Inflector::slug($command));
$run = null;
$methods = $this->_methods($class);
$properties = $this->_properties($class);
$info = Inspector::info($class);
$this->out('USAGE', 'heading');
if (isset($methods['run'])) {
$run = $methods['run'];
unset($methods['run']);
$this->_renderUsage($command, $run, $properties);
}
foreach ($methods as $method) {
$this->_renderUsage($command, $method);
}
$this->out();
if (!empty($info['description'])) {
$this->nl();
$this->_renderDescription($info);
$this->nl();
}
if ($properties || $methods) {
$this->out('OPTIONS', 'heading');
}
if ($run) {
$this->_render($run['args']);
}
if ($methods) {
$this->_render($methods);
}
if ($properties) {
$this->_render($properties);
}
$this->out();
return true;
} | php | public function run($command = null) {
if (!$command) {
$this->_renderCommands();
return true;
}
if (!preg_match('/\\\\/', $command)) {
$command = Inflector::camelize($command);
}
if (!$class = Libraries::locate('command', $command)) {
$this->error("Command `{$command}` not found");
return false;
}
if (strpos($command, '\\') !== false) {
$command = join('', array_slice(explode("\\", $command), -1));
}
$command = strtolower(Inflector::slug($command));
$run = null;
$methods = $this->_methods($class);
$properties = $this->_properties($class);
$info = Inspector::info($class);
$this->out('USAGE', 'heading');
if (isset($methods['run'])) {
$run = $methods['run'];
unset($methods['run']);
$this->_renderUsage($command, $run, $properties);
}
foreach ($methods as $method) {
$this->_renderUsage($command, $method);
}
$this->out();
if (!empty($info['description'])) {
$this->nl();
$this->_renderDescription($info);
$this->nl();
}
if ($properties || $methods) {
$this->out('OPTIONS', 'heading');
}
if ($run) {
$this->_render($run['args']);
}
if ($methods) {
$this->_render($methods);
}
if ($properties) {
$this->_render($properties);
}
$this->out();
return true;
} | [
"public",
"function",
"run",
"(",
"$",
"command",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"command",
")",
"{",
"$",
"this",
"->",
"_renderCommands",
"(",
")",
";",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"preg_match",
"(",
"'/\\\\\\\\/'",
"... | Auto run the help command.
@param string $command Name of the command to return help about.
@return boolean | [
"Auto",
"run",
"the",
"help",
"command",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/console/command/Help.php#L30-L87 |
UnionOfRAD/lithium | console/command/Help.php | Help.api | public function api($class = null, $type = null, $name = null) {
$class = str_replace(".", "\\", $class);
switch ($type) {
default:
$info = Inspector::info($class);
$result = ['class' => [
'name' => $info['shortName'],
'description' => trim($info['description'] . PHP_EOL . PHP_EOL . $info['text'])
]];
break;
case 'method':
$result = $this->_methods($class, compact('name'));
break;
case 'property':
$result = $this->_properties($class, compact('name'));
break;
}
$this->_render($result);
} | php | public function api($class = null, $type = null, $name = null) {
$class = str_replace(".", "\\", $class);
switch ($type) {
default:
$info = Inspector::info($class);
$result = ['class' => [
'name' => $info['shortName'],
'description' => trim($info['description'] . PHP_EOL . PHP_EOL . $info['text'])
]];
break;
case 'method':
$result = $this->_methods($class, compact('name'));
break;
case 'property':
$result = $this->_properties($class, compact('name'));
break;
}
$this->_render($result);
} | [
"public",
"function",
"api",
"(",
"$",
"class",
"=",
"null",
",",
"$",
"type",
"=",
"null",
",",
"$",
"name",
"=",
"null",
")",
"{",
"$",
"class",
"=",
"str_replace",
"(",
"\".\"",
",",
"\"\\\\\"",
",",
"$",
"class",
")",
";",
"switch",
"(",
"$",... | Gets the API for the class.
@param string $class fully namespaced class in dot notation.
@param string $type method|property
@param string $name the name of the method or property.
@return array | [
"Gets",
"the",
"API",
"for",
"the",
"class",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/console/command/Help.php#L97-L116 |
UnionOfRAD/lithium | console/command/Help.php | Help._methods | protected function _methods($class, $options = []) {
$defaults = ['name' => null];
$options += $defaults;
$map = function($item) {
if ($item->name[0] === '_') {
return;
}
$modifiers = array_values(Inspector::invokeMethod('_modifiers', [$item]));
$setAccess = array_intersect($modifiers, ['private', 'protected']) != [];
if ($setAccess) {
$item->setAccessible(true);
}
$args = [];
foreach ($item->getParameters() as $arg) {
$args[] = [
'name' => $arg->getName(),
'optional' => $arg->isOptional(),
'description' => null
];
}
$result = compact('modifiers', 'args') + [
'docComment' => $item->getDocComment(),
'name' => $item->getName()
];
if ($setAccess) {
$item->setAccessible(false);
}
return $result;
};
$methods = Inspector::methods($class)->map($map, ['collect' => false]);
$results = [];
foreach (array_filter($methods) as $method) {
$comment = Docblock::comment($method['docComment']);
$name = $method['name'];
$description = trim($comment['description'] . PHP_EOL . $comment['text']);
$args = $method['args'];
$return = null;
foreach ($args as &$arg) {
if (isset($comment['tags']['params']['$' . $arg['name']])) {
$arg['description'] = $comment['tags']['params']['$' . $arg['name']]['text'];
}
$arg['usage'] = $arg['optional'] ? "[<{$arg['name']}>]" : "<{$arg['name']}>";
}
if (isset($comment['tags']['return'])) {
$return = trim(strtok($comment['tags']['return'], ' '));
}
$results[$name] = compact('name', 'description', 'return', 'args');
if ($name && $name == $options['name']) {
return [$name => $results[$name]];
}
}
return $results;
} | php | protected function _methods($class, $options = []) {
$defaults = ['name' => null];
$options += $defaults;
$map = function($item) {
if ($item->name[0] === '_') {
return;
}
$modifiers = array_values(Inspector::invokeMethod('_modifiers', [$item]));
$setAccess = array_intersect($modifiers, ['private', 'protected']) != [];
if ($setAccess) {
$item->setAccessible(true);
}
$args = [];
foreach ($item->getParameters() as $arg) {
$args[] = [
'name' => $arg->getName(),
'optional' => $arg->isOptional(),
'description' => null
];
}
$result = compact('modifiers', 'args') + [
'docComment' => $item->getDocComment(),
'name' => $item->getName()
];
if ($setAccess) {
$item->setAccessible(false);
}
return $result;
};
$methods = Inspector::methods($class)->map($map, ['collect' => false]);
$results = [];
foreach (array_filter($methods) as $method) {
$comment = Docblock::comment($method['docComment']);
$name = $method['name'];
$description = trim($comment['description'] . PHP_EOL . $comment['text']);
$args = $method['args'];
$return = null;
foreach ($args as &$arg) {
if (isset($comment['tags']['params']['$' . $arg['name']])) {
$arg['description'] = $comment['tags']['params']['$' . $arg['name']]['text'];
}
$arg['usage'] = $arg['optional'] ? "[<{$arg['name']}>]" : "<{$arg['name']}>";
}
if (isset($comment['tags']['return'])) {
$return = trim(strtok($comment['tags']['return'], ' '));
}
$results[$name] = compact('name', 'description', 'return', 'args');
if ($name && $name == $options['name']) {
return [$name => $results[$name]];
}
}
return $results;
} | [
"protected",
"function",
"_methods",
"(",
"$",
"class",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'name'",
"=>",
"null",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"$",
"map",
"=",
"function",
"(",
"$",
... | Get the methods for the class.
@param string $class
@param array $options
@return array | [
"Get",
"the",
"methods",
"for",
"the",
"class",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/console/command/Help.php#L125-L185 |
UnionOfRAD/lithium | console/command/Help.php | Help._properties | protected function _properties($class, $options = []) {
$defaults = ['name' => null];
$options += $defaults;
$properties = Inspector::properties(new $class(['init' => false]), ['self' => false]);
$results = [];
foreach ($properties as &$property) {
if ($property['name'] === 'request' || $property['name'] === 'response') {
continue;
}
$name = str_replace('_', '-', Inflector::underscore($property['name']));
$comment = Docblock::comment($property['docComment']);
$description = trim($comment['description']);
$type = isset($comment['tags']['var']) ? strtok($comment['tags']['var'], ' ') : null;
$usage = strlen($name) == 1 ? "-{$name}" : "--{$name}";
if ($type != 'boolean') {
$usage .= "=<{$type}>";
}
$usage = "[{$usage}]";
$results[$name] = compact('name', 'description', 'type', 'usage');
if ($name == $options['name']) {
return [$name => $results[$name]];
}
}
return $results;
} | php | protected function _properties($class, $options = []) {
$defaults = ['name' => null];
$options += $defaults;
$properties = Inspector::properties(new $class(['init' => false]), ['self' => false]);
$results = [];
foreach ($properties as &$property) {
if ($property['name'] === 'request' || $property['name'] === 'response') {
continue;
}
$name = str_replace('_', '-', Inflector::underscore($property['name']));
$comment = Docblock::comment($property['docComment']);
$description = trim($comment['description']);
$type = isset($comment['tags']['var']) ? strtok($comment['tags']['var'], ' ') : null;
$usage = strlen($name) == 1 ? "-{$name}" : "--{$name}";
if ($type != 'boolean') {
$usage .= "=<{$type}>";
}
$usage = "[{$usage}]";
$results[$name] = compact('name', 'description', 'type', 'usage');
if ($name == $options['name']) {
return [$name => $results[$name]];
}
}
return $results;
} | [
"protected",
"function",
"_properties",
"(",
"$",
"class",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'name'",
"=>",
"null",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"$",
"properties",
"=",
"Inspector",
"::... | Get the properties for the class.
@param string $class
@param array $options
@return array | [
"Get",
"the",
"properties",
"for",
"the",
"class",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/console/command/Help.php#L194-L225 |
UnionOfRAD/lithium | console/command/Help.php | Help._render | protected function _render($params) {
foreach ($params as $name => $param) {
if ($name === 'run' || empty($param['name'])) {
continue;
}
$usage = (!empty($param['usage'])) ? trim($param['usage'], ' []') : $param['name'];
$this->out($this->_pad($usage), 'option');
if ($param['description']) {
$this->out($this->_pad($param['description'], 2));
}
$this->nl();
}
} | php | protected function _render($params) {
foreach ($params as $name => $param) {
if ($name === 'run' || empty($param['name'])) {
continue;
}
$usage = (!empty($param['usage'])) ? trim($param['usage'], ' []') : $param['name'];
$this->out($this->_pad($usage), 'option');
if ($param['description']) {
$this->out($this->_pad($param['description'], 2));
}
$this->nl();
}
} | [
"protected",
"function",
"_render",
"(",
"$",
"params",
")",
"{",
"foreach",
"(",
"$",
"params",
"as",
"$",
"name",
"=>",
"$",
"param",
")",
"{",
"if",
"(",
"$",
"name",
"===",
"'run'",
"||",
"empty",
"(",
"$",
"param",
"[",
"'name'",
"]",
")",
"... | Output the formatted properties or methods.
@see lithium\console\command\Help::_properties()
@see lithium\console\command\Help::_methods()
@param array $params From `_properties()` or `_methods()`.
@return void | [
"Output",
"the",
"formatted",
"properties",
"or",
"methods",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/console/command/Help.php#L235-L248 |
UnionOfRAD/lithium | console/command/Help.php | Help._renderCommands | protected function _renderCommands() {
$commands = Libraries::locate('command', null, ['recursive' => false]);
foreach ($commands as $key => $command) {
$library = strtok($command, '\\');
if (!$key || strtok($commands[$key - 1] , '\\') != $library) {
$this->out("{:heading}COMMANDS{:end} {:blue}via {$library}{:end}");
}
$info = Inspector::info($command);
$name = strtolower(Inflector::slug($info['shortName']));
$this->out($this->_pad($name) , 'heading');
$this->out($this->_pad($info['description']), 2);
}
$message = 'See `{:command}li3 help COMMAND{:end}`';
$message .= ' for more information on a specific command.';
$this->out($message, 2);
} | php | protected function _renderCommands() {
$commands = Libraries::locate('command', null, ['recursive' => false]);
foreach ($commands as $key => $command) {
$library = strtok($command, '\\');
if (!$key || strtok($commands[$key - 1] , '\\') != $library) {
$this->out("{:heading}COMMANDS{:end} {:blue}via {$library}{:end}");
}
$info = Inspector::info($command);
$name = strtolower(Inflector::slug($info['shortName']));
$this->out($this->_pad($name) , 'heading');
$this->out($this->_pad($info['description']), 2);
}
$message = 'See `{:command}li3 help COMMAND{:end}`';
$message .= ' for more information on a specific command.';
$this->out($message, 2);
} | [
"protected",
"function",
"_renderCommands",
"(",
")",
"{",
"$",
"commands",
"=",
"Libraries",
"::",
"locate",
"(",
"'command'",
",",
"null",
",",
"[",
"'recursive'",
"=>",
"false",
"]",
")",
";",
"foreach",
"(",
"$",
"commands",
"as",
"$",
"key",
"=>",
... | Output the formatted available commands.
@return void | [
"Output",
"the",
"formatted",
"available",
"commands",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/console/command/Help.php#L255-L274 |
UnionOfRAD/lithium | console/command/Help.php | Help._renderUsage | protected function _renderUsage($command, $method, $properties = []) {
$params = array_reduce($properties, function($a, $b) {
return "{$a} {$b['usage']}";
});
$args = array_reduce($method['args'], function($a, $b) {
return "{$a} {$b['usage']}";
});
$format = "{:command}li3 %s%s{:end}{:command}%s{:end}{:option}%s{:end}";
$name = $method['name'] == 'run' ? '' : " {$method['name']}";
$this->out($this->_pad(sprintf($format, $command ?: 'COMMAND', $name, $params, $args)));
} | php | protected function _renderUsage($command, $method, $properties = []) {
$params = array_reduce($properties, function($a, $b) {
return "{$a} {$b['usage']}";
});
$args = array_reduce($method['args'], function($a, $b) {
return "{$a} {$b['usage']}";
});
$format = "{:command}li3 %s%s{:end}{:command}%s{:end}{:option}%s{:end}";
$name = $method['name'] == 'run' ? '' : " {$method['name']}";
$this->out($this->_pad(sprintf($format, $command ?: 'COMMAND', $name, $params, $args)));
} | [
"protected",
"function",
"_renderUsage",
"(",
"$",
"command",
",",
"$",
"method",
",",
"$",
"properties",
"=",
"[",
"]",
")",
"{",
"$",
"params",
"=",
"array_reduce",
"(",
"$",
"properties",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
... | Output the formatted usage.
@see lithium\console\command\Help::_methods()
@see lithium\console\command\Help::_properties()
@param string $command The name of the command.
@param array $method Information about the method of the command to render usage for.
@param array $properties From `_properties()`.
@return void | [
"Output",
"the",
"formatted",
"usage",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/console/command/Help.php#L286-L296 |
UnionOfRAD/lithium | console/command/Help.php | Help._renderDescription | protected function _renderDescription($info) {
$this->out('DESCRIPTION', 'heading');
$break = PHP_EOL . PHP_EOL;
$description = trim("{$info['description']}{$break}{$info['text']}");
$this->out($this->_pad($description), 2);
} | php | protected function _renderDescription($info) {
$this->out('DESCRIPTION', 'heading');
$break = PHP_EOL . PHP_EOL;
$description = trim("{$info['description']}{$break}{$info['text']}");
$this->out($this->_pad($description), 2);
} | [
"protected",
"function",
"_renderDescription",
"(",
"$",
"info",
")",
"{",
"$",
"this",
"->",
"out",
"(",
"'DESCRIPTION'",
",",
"'heading'",
")",
";",
"$",
"break",
"=",
"PHP_EOL",
".",
"PHP_EOL",
";",
"$",
"description",
"=",
"trim",
"(",
"\"{$info['descr... | Output the formatted command description.
@param array $info Info from inspecting the class of the command.
@return void | [
"Output",
"the",
"formatted",
"command",
"description",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/console/command/Help.php#L304-L309 |
UnionOfRAD/lithium | storage/session/adapter/Memory.php | Memory.read | public function read($key = null, array $options = []) {
return function($params) {
if (!$params['key']) {
return $this->_session;
}
return isset($this->_session[$params['key']]) ? $this->_session[$params['key']] : null;
};
} | php | public function read($key = null, array $options = []) {
return function($params) {
if (!$params['key']) {
return $this->_session;
}
return isset($this->_session[$params['key']]) ? $this->_session[$params['key']] : null;
};
} | [
"public",
"function",
"read",
"(",
"$",
"key",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"return",
"function",
"(",
"$",
"params",
")",
"{",
"if",
"(",
"!",
"$",
"params",
"[",
"'key'",
"]",
")",
"{",
"return",
"$",
"t... | Read a value from the session.
@param null|string $key Key of the entry to be read. If no key is passed, all
current session data is returned.
@param array $options Options array. Not used for this adapter method.
@return \Closure Function returning data in the session if successful, `false` otherwise. | [
"Read",
"a",
"value",
"from",
"the",
"session",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/storage/session/adapter/Memory.php#L67-L74 |
UnionOfRAD/lithium | storage/session/adapter/Memory.php | Memory.write | public function write($key, $value, array $options = []) {
return function($params) {
return (boolean) ($this->_session[$params['key']] = $params['value']);
};
} | php | public function write($key, $value, array $options = []) {
return function($params) {
return (boolean) ($this->_session[$params['key']] = $params['value']);
};
} | [
"public",
"function",
"write",
"(",
"$",
"key",
",",
"$",
"value",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"return",
"function",
"(",
"$",
"params",
")",
"{",
"return",
"(",
"boolean",
")",
"(",
"$",
"this",
"->",
"_session",
"[",
... | Write a value to the session.
@param string $key Key of the item to be stored.
@param mixed $value The value to be stored.
@param array $options Options array. Not used for this adapter method.
@return \Closure Function returning boolean `true` on successful write, `false` otherwise. | [
"Write",
"a",
"value",
"to",
"the",
"session",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/storage/session/adapter/Memory.php#L84-L88 |
UnionOfRAD/lithium | storage/session/adapter/Memory.php | Memory.delete | public function delete($key, array $options = []) {
return function($params) {
unset($this->_session[$params['key']]);
return !isset($this->_session[$params['key']]);
};
} | php | public function delete($key, array $options = []) {
return function($params) {
unset($this->_session[$params['key']]);
return !isset($this->_session[$params['key']]);
};
} | [
"public",
"function",
"delete",
"(",
"$",
"key",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"return",
"function",
"(",
"$",
"params",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"_session",
"[",
"$",
"params",
"[",
"'key'",
"]",
"]",
"... | Delete value from the session
@param string $key The key to be deleted
@param array $options Options array. Not used for this adapter method.
@return \Closure Function returning boolean `true` on successful delete, `false` otherwise | [
"Delete",
"value",
"from",
"the",
"session"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/storage/session/adapter/Memory.php#L97-L102 |
UnionOfRAD/lithium | data/collection/RecordSet.php | RecordSet._init | protected function _init() {
parent::_init();
if (!$this->_result) {
return;
}
$this->_columns = $this->_columnMap();
if (!$this->_query) {
return;
}
$this->_keyIndex = $this->_keyIndex();
$this->_dependencies = Set::expand(Set::normalize(
array_filter(array_keys($this->_columns))
));
$this->_relationships = $this->_query->relationships();
} | php | protected function _init() {
parent::_init();
if (!$this->_result) {
return;
}
$this->_columns = $this->_columnMap();
if (!$this->_query) {
return;
}
$this->_keyIndex = $this->_keyIndex();
$this->_dependencies = Set::expand(Set::normalize(
array_filter(array_keys($this->_columns))
));
$this->_relationships = $this->_query->relationships();
} | [
"protected",
"function",
"_init",
"(",
")",
"{",
"parent",
"::",
"_init",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"_result",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"_columns",
"=",
"$",
"this",
"->",
"_columnMap",
"(",
")",
";... | Initializes the record set and uses the database connection to get the column list contained
in the query that created this object.
@see lithium\data\collection\RecordSet::$_columns
@return void
@todo The part that uses _handle->schema() should be rewritten so that the column list
is coming from the query object. | [
"Initializes",
"the",
"record",
"set",
"and",
"uses",
"the",
"database",
"connection",
"to",
"get",
"the",
"column",
"list",
"contained",
"in",
"the",
"query",
"that",
"created",
"this",
"object",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/collection/RecordSet.php#L64-L81 |
UnionOfRAD/lithium | data/collection/RecordSet.php | RecordSet._mapRecord | protected function _mapRecord($row) {
$main = array_intersect_key($row, $this->_keyIndex);
if ($main) {
if (in_array($main, $this->_seen)) {
$message = 'Associated records hydrated out of order: ';
$message .= var_export($this->_seen, true);
throw new RuntimeException($message);
}
$this->_seen[] = $main;
}
$i = 0;
$record = [];
do {
$offset = 0;
foreach ($this->_columns as $name => $fields) {
$record[$i][$name] = array_combine(
$fields, array_slice($row, $offset, ($count = count($fields)))
);
$offset += $count;
}
$i++;
if (!$peek = $this->_result->peek()) {
break;
}
if ($main !== array_intersect_key($peek, $this->_keyIndex)) {
break;
}
} while ($main && ($row = $this->_result->next()));
return $this->_hydrateRecord($this->_dependencies, $this->_model, $record, 0, $i, '');
} | php | protected function _mapRecord($row) {
$main = array_intersect_key($row, $this->_keyIndex);
if ($main) {
if (in_array($main, $this->_seen)) {
$message = 'Associated records hydrated out of order: ';
$message .= var_export($this->_seen, true);
throw new RuntimeException($message);
}
$this->_seen[] = $main;
}
$i = 0;
$record = [];
do {
$offset = 0;
foreach ($this->_columns as $name => $fields) {
$record[$i][$name] = array_combine(
$fields, array_slice($row, $offset, ($count = count($fields)))
);
$offset += $count;
}
$i++;
if (!$peek = $this->_result->peek()) {
break;
}
if ($main !== array_intersect_key($peek, $this->_keyIndex)) {
break;
}
} while ($main && ($row = $this->_result->next()));
return $this->_hydrateRecord($this->_dependencies, $this->_model, $record, 0, $i, '');
} | [
"protected",
"function",
"_mapRecord",
"(",
"$",
"row",
")",
"{",
"$",
"main",
"=",
"array_intersect_key",
"(",
"$",
"row",
",",
"$",
"this",
"->",
"_keyIndex",
")",
";",
"if",
"(",
"$",
"main",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"main",
",... | Converts a PDO `Result` array to a nested `Record` object.
1. Builds an associative array with data from the row, with joined row data
nested under the relationships name. Joined row data is added and new
results consumed from the result cursor under the relationships name until
the value of the main primary key changes.
2. The built array is then hydrated and returned.
Note: Joined records must appear sequentially, when non-sequential records
are detected an exception is thrown.
@throws RuntimeException
@param array $row 2 dimensional PDO `Result` array
@return object Returns a `Record` object | [
"Converts",
"a",
"PDO",
"Result",
"array",
"to",
"a",
"nested",
"Record",
"object",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/collection/RecordSet.php#L134-L169 |
UnionOfRAD/lithium | data/collection/RecordSet.php | RecordSet._hydrateRecord | protected function _hydrateRecord(array $relations, $primary, array $record, $min, $max, $name) {
$options = ['exists' => true, 'defaults' => false];
foreach ($relations as $relation => $subrelations) {
$relName = $name ? "{$name}.{$relation}" : $relation;
$relModel = $this->_relationships[$relName]['model'];
$relField = $this->_relationships[$relName]['fieldName'];
$relType = $this->_relationships[$relName]['type'];
if ($relType !== 'hasMany') {
$record[$min][$name][$relField] = $this->_hydrateRecord(
$subrelations ?: [], $relModel, $record, $min, $max, $relName
);
continue;
}
$rel = [];
$main = $relModel::key($record[$min][$relName]);
$i = $min;
$j = $i + 1;
while ($j < $max) {
$keys = $relModel::key($record[$j][$relName]);
if ($main != $keys) {
$rel[] = $this->_hydrateRecord(
$subrelations ?: [], $relModel, $record, $i, $j, $relName
);
$main = $keys;
$i = $j;
}
$j++;
}
if (array_filter($record[$i][$relName])) {
$rel[] = $this->_hydrateRecord(
$subrelations ?: [], $relModel, $record, $i, $j, $relName
);
}
$record[$min][$name][$relField] = $relModel::create($rel, [
'class' => 'set'
] + $options);
}
return $primary::create(
isset($record[$min][$name]) ? $record[$min][$name] : [], $options
);
} | php | protected function _hydrateRecord(array $relations, $primary, array $record, $min, $max, $name) {
$options = ['exists' => true, 'defaults' => false];
foreach ($relations as $relation => $subrelations) {
$relName = $name ? "{$name}.{$relation}" : $relation;
$relModel = $this->_relationships[$relName]['model'];
$relField = $this->_relationships[$relName]['fieldName'];
$relType = $this->_relationships[$relName]['type'];
if ($relType !== 'hasMany') {
$record[$min][$name][$relField] = $this->_hydrateRecord(
$subrelations ?: [], $relModel, $record, $min, $max, $relName
);
continue;
}
$rel = [];
$main = $relModel::key($record[$min][$relName]);
$i = $min;
$j = $i + 1;
while ($j < $max) {
$keys = $relModel::key($record[$j][$relName]);
if ($main != $keys) {
$rel[] = $this->_hydrateRecord(
$subrelations ?: [], $relModel, $record, $i, $j, $relName
);
$main = $keys;
$i = $j;
}
$j++;
}
if (array_filter($record[$i][$relName])) {
$rel[] = $this->_hydrateRecord(
$subrelations ?: [], $relModel, $record, $i, $j, $relName
);
}
$record[$min][$name][$relField] = $relModel::create($rel, [
'class' => 'set'
] + $options);
}
return $primary::create(
isset($record[$min][$name]) ? $record[$min][$name] : [], $options
);
} | [
"protected",
"function",
"_hydrateRecord",
"(",
"array",
"$",
"relations",
",",
"$",
"primary",
",",
"array",
"$",
"record",
",",
"$",
"min",
",",
"$",
"max",
",",
"$",
"name",
")",
"{",
"$",
"options",
"=",
"[",
"'exists'",
"=>",
"true",
",",
"'defa... | Hydrates a 2 dimensional PDO row `Result` array recursively.
@param array $relations The cascading with relation
@param string $primary Model classname
@param array $record Loaded Records
@param integer $min
@param integer $max
@param string $name Alias name
@return \lithium\data\entity\Record Returns a `Record` object as created by the model. | [
"Hydrates",
"a",
"2",
"dimensional",
"PDO",
"row",
"Result",
"array",
"recursively",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/collection/RecordSet.php#L182-L228 |
UnionOfRAD/lithium | data/collection/RecordSet.php | RecordSet._keyIndex | protected function _keyIndex() {
if (!($model = $this->_model) || !isset($this->_columns[''])) {
return [];
}
$index = 0;
foreach ($this->_columns as $name => $fields) {
if ($name === '') {
if (($offset = array_search($model::meta('key'), $fields)) === false) {
return [];
}
return [$index + $offset => $model::meta('key')];
}
$index += count($fields);
}
return [];
} | php | protected function _keyIndex() {
if (!($model = $this->_model) || !isset($this->_columns[''])) {
return [];
}
$index = 0;
foreach ($this->_columns as $name => $fields) {
if ($name === '') {
if (($offset = array_search($model::meta('key'), $fields)) === false) {
return [];
}
return [$index + $offset => $model::meta('key')];
}
$index += count($fields);
}
return [];
} | [
"protected",
"function",
"_keyIndex",
"(",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"model",
"=",
"$",
"this",
"->",
"_model",
")",
"||",
"!",
"isset",
"(",
"$",
"this",
"->",
"_columns",
"[",
"''",
"]",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
... | Extracts the numerical index of the primary key in numerical indexed row data.
Works only for the main row data and not for relationship rows.
This method will also correctly detect a primary key which doesn't come
first.
@return array An array where key are index and value are primary key fieldname. | [
"Extracts",
"the",
"numerical",
"index",
"of",
"the",
"primary",
"key",
"in",
"numerical",
"indexed",
"row",
"data",
".",
"Works",
"only",
"for",
"the",
"main",
"row",
"data",
"and",
"not",
"for",
"relationship",
"rows",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/collection/RecordSet.php#L253-L269 |
UnionOfRAD/lithium | storage/session/strategy/Hmac.php | Hmac.write | public function write($data, array $options = []) {
$class = $options['class'];
$futureData = $class::read(null, ['strategies' => false]);
$futureData = [$options['key'] => $data] + $futureData;
unset($futureData['__signature']);
$signature = static::_signature($futureData);
$class::write('__signature', $signature, ['strategies' => false] + $options);
return $data;
} | php | public function write($data, array $options = []) {
$class = $options['class'];
$futureData = $class::read(null, ['strategies' => false]);
$futureData = [$options['key'] => $data] + $futureData;
unset($futureData['__signature']);
$signature = static::_signature($futureData);
$class::write('__signature', $signature, ['strategies' => false] + $options);
return $data;
} | [
"public",
"function",
"write",
"(",
"$",
"data",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"class",
"=",
"$",
"options",
"[",
"'class'",
"]",
";",
"$",
"futureData",
"=",
"$",
"class",
"::",
"read",
"(",
"null",
",",
"[",
"'stra... | Write strategy method.
Adds an HMAC signature to the data. Note that this will transform the
passed `$data` to an array, and add a `__signature` key with the HMAC-calculated
value.
@see lithium\storage\Session
@see lithium\core\Adaptable::config()
@link http://php.net/function.hash-hmac.php PHP Manual: hash_hmac()
@param mixed $data The data to be signed.
@param array $options Options for this method.
@return array Data & signature. | [
"Write",
"strategy",
"method",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/storage/session/strategy/Hmac.php#L80-L90 |
UnionOfRAD/lithium | storage/session/strategy/Hmac.php | Hmac.read | public function read($data, array $options = []) {
if ($data === null) {
return $data;
}
$class = $options['class'];
$currentData = $class::read(null, ['strategies' => false]);
if (!isset($currentData['__signature'])) {
throw new MissingSignatureException('HMAC signature not found.');
}
if (Hash::compare($currentData['__signature'], static::_signature($currentData))) {
return $data;
}
throw new RuntimeException('Possible data tampering: HMAC signature does not match data.');
} | php | public function read($data, array $options = []) {
if ($data === null) {
return $data;
}
$class = $options['class'];
$currentData = $class::read(null, ['strategies' => false]);
if (!isset($currentData['__signature'])) {
throw new MissingSignatureException('HMAC signature not found.');
}
if (Hash::compare($currentData['__signature'], static::_signature($currentData))) {
return $data;
}
throw new RuntimeException('Possible data tampering: HMAC signature does not match data.');
} | [
"public",
"function",
"read",
"(",
"$",
"data",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"data",
"===",
"null",
")",
"{",
"return",
"$",
"data",
";",
"}",
"$",
"class",
"=",
"$",
"options",
"[",
"'class'",
"]",
";"... | Read strategy method.
Validates the HMAC signature of the stored data. If the signatures match, then the data
is safe and will be passed through as-is.
If the stored data being read does not contain a `__signature` field, a
`MissingSignatureException` is thrown. When catching this exception, you may choose
to handle it by either writing out a signature (e.g. in cases where you know that no
pre-existing signature may exist), or you can blackhole it as a possible tampering
attempt.
@throws RuntimeException On possible data tampering.
@throws lithium\storage\session\strategy\MissingSignatureException On missing singature.
@param array $data The data being read.
@param array $options Options for this method.
@return array Validated data. | [
"Read",
"strategy",
"method",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/storage/session/strategy/Hmac.php#L110-L125 |
UnionOfRAD/lithium | storage/session/strategy/Hmac.php | Hmac._signature | protected static function _signature($data, $secret = null) {
unset($data['__signature']);
$secret = ($secret) ?: static::$_secret;
return hash_hmac('sha1', serialize($data), $secret);
} | php | protected static function _signature($data, $secret = null) {
unset($data['__signature']);
$secret = ($secret) ?: static::$_secret;
return hash_hmac('sha1', serialize($data), $secret);
} | [
"protected",
"static",
"function",
"_signature",
"(",
"$",
"data",
",",
"$",
"secret",
"=",
"null",
")",
"{",
"unset",
"(",
"$",
"data",
"[",
"'__signature'",
"]",
")",
";",
"$",
"secret",
"=",
"(",
"$",
"secret",
")",
"?",
":",
"static",
"::",
"$"... | Calculate the HMAC signature based on the data and a secret key.
@param mixed $data
@param null|string $secret Secret key for HMAC signature creation.
@return string HMAC signature. | [
"Calculate",
"the",
"HMAC",
"signature",
"based",
"on",
"the",
"data",
"and",
"a",
"secret",
"key",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/storage/session/strategy/Hmac.php#L155-L159 |
UnionOfRAD/lithium | storage/Session.php | Session.key | public static function key($name = null, $sessionId = null) {
return is_object($adapter = static::adapter($name)) ? $adapter->key($sessionId) : null;
} | php | public static function key($name = null, $sessionId = null) {
return is_object($adapter = static::adapter($name)) ? $adapter->key($sessionId) : null;
} | [
"public",
"static",
"function",
"key",
"(",
"$",
"name",
"=",
"null",
",",
"$",
"sessionId",
"=",
"null",
")",
"{",
"return",
"is_object",
"(",
"$",
"adapter",
"=",
"static",
"::",
"adapter",
"(",
"$",
"name",
")",
")",
"?",
"$",
"adapter",
"->",
"... | Returns (and Sets) the key used to identify the session.
@param mixed $name Optional named session configuration.
@param mixed $session_id Optional session id to use for this session.
@return string Returns the value of the session identifier key, or `null` if no named
configuration exists, no session id has been set or no session has been started. | [
"Returns",
"(",
"and",
"Sets",
")",
"the",
"key",
"used",
"to",
"identify",
"the",
"session",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/storage/Session.php#L66-L68 |
UnionOfRAD/lithium | storage/Session.php | Session.isStarted | public static function isStarted($name = null) {
return is_object($adapter = static::adapter($name)) ? $adapter->isStarted() : false;
} | php | public static function isStarted($name = null) {
return is_object($adapter = static::adapter($name)) ? $adapter->isStarted() : false;
} | [
"public",
"static",
"function",
"isStarted",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"return",
"is_object",
"(",
"$",
"adapter",
"=",
"static",
"::",
"adapter",
"(",
"$",
"name",
")",
")",
"?",
"$",
"adapter",
"->",
"isStarted",
"(",
")",
":",
"fals... | Indicates whether the the current request includes information on a previously started
session.
@param string $name Optional named session configuration.
@return boolean Returns `true` if a the request includes a key from a previously created
session. | [
"Indicates",
"whether",
"the",
"the",
"current",
"request",
"includes",
"information",
"on",
"a",
"previously",
"started",
"session",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/storage/Session.php#L78-L80 |
UnionOfRAD/lithium | storage/Session.php | Session.read | public static function read($key = null, array $options = []) {
$defaults = ['name' => null, 'strategies' => true];
$options += $defaults;
$method = ($name = $options['name']) ? static::adapter($name)->read($key, $options) : null;
$settings = static::_config($name);
if (!$method) {
foreach (array_keys(static::$_configurations) as $name) {
if ($method = static::adapter($name)->read($key, $options)) {
break;
}
}
if (!$method || !$name) {
return null;
}
}
$params = compact('key', 'options');
if (!empty($settings['filters'])) {
$message = 'Per adapter filters have been deprecated. Please ';
$message .= "filter the manager class' static methods instead.";
trigger_error($message, E_USER_DEPRECATED);
$result = Filters::bcRun(
get_called_class(), __FUNCTION__, $params, $method, $settings['filters']
);
} else {
$result = Filters::run(get_called_class(), __FUNCTION__, $params, $method);
}
if ($options['strategies']) {
$options += ['key' => $key, 'mode' => 'LIFO', 'class' => __CLASS__];
return static::applyStrategies(__FUNCTION__, $name, $result, $options);
}
return $result;
} | php | public static function read($key = null, array $options = []) {
$defaults = ['name' => null, 'strategies' => true];
$options += $defaults;
$method = ($name = $options['name']) ? static::adapter($name)->read($key, $options) : null;
$settings = static::_config($name);
if (!$method) {
foreach (array_keys(static::$_configurations) as $name) {
if ($method = static::adapter($name)->read($key, $options)) {
break;
}
}
if (!$method || !$name) {
return null;
}
}
$params = compact('key', 'options');
if (!empty($settings['filters'])) {
$message = 'Per adapter filters have been deprecated. Please ';
$message .= "filter the manager class' static methods instead.";
trigger_error($message, E_USER_DEPRECATED);
$result = Filters::bcRun(
get_called_class(), __FUNCTION__, $params, $method, $settings['filters']
);
} else {
$result = Filters::run(get_called_class(), __FUNCTION__, $params, $method);
}
if ($options['strategies']) {
$options += ['key' => $key, 'mode' => 'LIFO', 'class' => __CLASS__];
return static::applyStrategies(__FUNCTION__, $name, $result, $options);
}
return $result;
} | [
"public",
"static",
"function",
"read",
"(",
"$",
"key",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'name'",
"=>",
"null",
",",
"'strategies'",
"=>",
"true",
"]",
";",
"$",
"options",
"+=",
"$",
... | Reads a value from a persistent session store.
@param string $key Key to be read.
@param array $options Optional parameters that this method accepts:
- `'name'` _string_: To force the read from a specific adapter, specify the name
of the configuration (i.e. `'default'`) here.
- `'strategies'` _boolean_: Indicates whether or not a configuration's applied
strategy classes should be enabled for this operation. Defaults to `true`.
@return mixed Read result on successful session read, `null` otherwise.
@filter | [
"Reads",
"a",
"value",
"from",
"a",
"persistent",
"session",
"store",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/storage/Session.php#L94-L129 |
UnionOfRAD/lithium | storage/Session.php | Session.adapter | public static function adapter($name = null) {
if (!$name) {
if (!$names = array_keys(static::$_configurations)) {
return;
}
$name = end($names);
}
return parent::adapter($name);
} | php | public static function adapter($name = null) {
if (!$name) {
if (!$names = array_keys(static::$_configurations)) {
return;
}
$name = end($names);
}
return parent::adapter($name);
} | [
"public",
"static",
"function",
"adapter",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"$",
"names",
"=",
"array_keys",
"(",
"static",
"::",
"$",
"_configurations",
")",
")",
"{",
"return",
";",
... | Returns the adapter object instance of the named configuration.
@param string $name Named configuration. If not set, the last configured
adapter object instance will be returned.
@return object Adapter instance. | [
"Returns",
"the",
"adapter",
"object",
"instance",
"of",
"the",
"named",
"configuration",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/storage/Session.php#L351-L359 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.