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 | template/view/adapter/File.php | File.render | public function render($template, $data = [], array $options = []) {
$defaults = ['context' => []];
$options += $defaults;
$this->_context = $options['context'] + $this->_context;
$this->_data = (array) $data + $this->_vars;
$this->_options = $options;
$template__ = $template;
unset($options, $template, $defaults, $data);
if ($this->_config['extract']) {
extract($this->_data, EXTR_OVERWRITE);
} elseif ($this->_view) {
extract((array) $this->_view->outputFilters, EXTR_OVERWRITE);
}
ob_start();
include $template__;
return ob_get_clean();
} | php | public function render($template, $data = [], array $options = []) {
$defaults = ['context' => []];
$options += $defaults;
$this->_context = $options['context'] + $this->_context;
$this->_data = (array) $data + $this->_vars;
$this->_options = $options;
$template__ = $template;
unset($options, $template, $defaults, $data);
if ($this->_config['extract']) {
extract($this->_data, EXTR_OVERWRITE);
} elseif ($this->_view) {
extract((array) $this->_view->outputFilters, EXTR_OVERWRITE);
}
ob_start();
include $template__;
return ob_get_clean();
} | [
"public",
"function",
"render",
"(",
"$",
"template",
",",
"$",
"data",
"=",
"[",
"]",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'context'",
"=>",
"[",
"]",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",... | Renders content from a template file provided by `template()`.
@param string $template
@param array|string $data
@param array $options
@return string | [
"Renders",
"content",
"from",
"a",
"template",
"file",
"provided",
"by",
"template",
"()",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/template/view/adapter/File.php#L106-L125 |
UnionOfRAD/lithium | template/view/adapter/File.php | File.template | public function template($type, array $params) {
$library = Libraries::get(isset($params['library']) ? $params['library'] : true);
$params['library'] = $library['path'];
$path = $this->_paths($type, $params);
if ($this->_compile) {
$compiler = $this->_classes['compiler'];
$path = $compiler::template($path, $this->_config['compiler']);
}
return $path;
} | php | public function template($type, array $params) {
$library = Libraries::get(isset($params['library']) ? $params['library'] : true);
$params['library'] = $library['path'];
$path = $this->_paths($type, $params);
if ($this->_compile) {
$compiler = $this->_classes['compiler'];
$path = $compiler::template($path, $this->_config['compiler']);
}
return $path;
} | [
"public",
"function",
"template",
"(",
"$",
"type",
",",
"array",
"$",
"params",
")",
"{",
"$",
"library",
"=",
"Libraries",
"::",
"get",
"(",
"isset",
"(",
"$",
"params",
"[",
"'library'",
"]",
")",
"?",
"$",
"params",
"[",
"'library'",
"]",
":",
... | Returns a template file name
@param string $type
@param array $params
@return string | [
"Returns",
"a",
"template",
"file",
"name"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/template/view/adapter/File.php#L134-L144 |
UnionOfRAD/lithium | template/view/adapter/File.php | File._paths | protected function _paths($type, array $params) {
if (!isset($this->_paths[$type])) {
throw new TemplateException("Invalid template type '{$type}'.");
}
foreach ((array) $this->_paths[$type] as $path) {
if (!file_exists($path = Text::insert($path, $params))) {
continue;
}
return $path;
}
throw new TemplateException("Template not found at path `{$path}`.");
} | php | protected function _paths($type, array $params) {
if (!isset($this->_paths[$type])) {
throw new TemplateException("Invalid template type '{$type}'.");
}
foreach ((array) $this->_paths[$type] as $path) {
if (!file_exists($path = Text::insert($path, $params))) {
continue;
}
return $path;
}
throw new TemplateException("Template not found at path `{$path}`.");
} | [
"protected",
"function",
"_paths",
"(",
"$",
"type",
",",
"array",
"$",
"params",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_paths",
"[",
"$",
"type",
"]",
")",
")",
"{",
"throw",
"new",
"TemplateException",
"(",
"\"Invalid template t... | Searches one or more path templates for a matching template file, and returns the file name.
@param string $type
@param array $params The set of options keys to be interpolated into the path templates
when searching for the correct file to load.
@return string Returns the first template file found. Throws an exception if no templates
are available. | [
"Searches",
"one",
"or",
"more",
"path",
"templates",
"for",
"a",
"matching",
"template",
"file",
"and",
"returns",
"the",
"file",
"name",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/template/view/adapter/File.php#L224-L236 |
UnionOfRAD/lithium | data/source/database/adapter/Sqlite3.php | Sqlite3.enabled | public static function enabled($feature = null) {
if (!$feature) {
return extension_loaded('pdo_sqlite');
}
$features = [
'arrays' => false,
'transactions' => false,
'booleans' => true,
'schema' => true,
'relationships' => true,
'sources' => true
];
return isset($features[$feature]) ? $features[$feature] : null;
} | php | public static function enabled($feature = null) {
if (!$feature) {
return extension_loaded('pdo_sqlite');
}
$features = [
'arrays' => false,
'transactions' => false,
'booleans' => true,
'schema' => true,
'relationships' => true,
'sources' => true
];
return isset($features[$feature]) ? $features[$feature] : null;
} | [
"public",
"static",
"function",
"enabled",
"(",
"$",
"feature",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"feature",
")",
"{",
"return",
"extension_loaded",
"(",
"'pdo_sqlite'",
")",
";",
"}",
"$",
"features",
"=",
"[",
"'arrays'",
"=>",
"false",
","... | Check for required PHP extension, or supported database feature.
@param string $feature Test for support for a specific feature, i.e. `'transactions'`.
@return boolean Returns `true` if the particular feature (or if Sqlite) support is enabled,
otherwise `false`. | [
"Check",
"for",
"required",
"PHP",
"extension",
"or",
"supported",
"database",
"feature",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/database/adapter/Sqlite3.php#L101-L114 |
UnionOfRAD/lithium | data/source/database/adapter/Sqlite3.php | Sqlite3.sources | public function sources($model = null) {
$params = compact('model');
return Filters::run($this, __FUNCTION__, $params, function($params) {
$sql = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;";
$result = $this->_execute($sql);
$sources = [];
foreach ($result as $row) {
$sources[] = $row[0];
}
return $sources;
});
} | php | public function sources($model = null) {
$params = compact('model');
return Filters::run($this, __FUNCTION__, $params, function($params) {
$sql = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;";
$result = $this->_execute($sql);
$sources = [];
foreach ($result as $row) {
$sources[] = $row[0];
}
return $sources;
});
} | [
"public",
"function",
"sources",
"(",
"$",
"model",
"=",
"null",
")",
"{",
"$",
"params",
"=",
"compact",
"(",
"'model'",
")",
";",
"return",
"Filters",
"::",
"run",
"(",
"$",
"this",
",",
"__FUNCTION__",
",",
"$",
"params",
",",
"function",
"(",
"$"... | Returns the list of tables in the currently-connected database.
@param string $model The fully-name-spaced class name of the model object making the request.
@return array Returns an array of objects to which models can connect.
@filter | [
"Returns",
"the",
"list",
"of",
"tables",
"in",
"the",
"currently",
"-",
"connected",
"database",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/database/adapter/Sqlite3.php#L165-L178 |
UnionOfRAD/lithium | data/source/database/adapter/Sqlite3.php | Sqlite3.describe | public function describe($entity, $fields = [], array $meta = []) {
$params = compact('entity', 'meta', 'fields');
return Filters::run($this, __FUNCTION__, $params, function($params) {
extract($params);
if ($fields) {
return $this->_instance('schema', compact('fields'));
}
$name = $this->_entityName($entity, ['quoted' => true]);
$columns = $this->read("PRAGMA table_info({$name})", ['return' => 'array']);
$fields = [];
foreach ($columns as $column) {
$schema = $this->_column($column['type']);
$default = $column['dflt_value'];
if (preg_match("/^'(.*)'/", $default, $match)) {
$default = $match[1];
} elseif ($schema['type'] === 'boolean') {
$default = !!$default;
} else {
$default = null;
}
$fields[$column['name']] = $schema + [
'null' => $column['notnull'] === '1',
'default' => $default
];
}
return $this->_instance('schema', compact('fields'));
});
} | php | public function describe($entity, $fields = [], array $meta = []) {
$params = compact('entity', 'meta', 'fields');
return Filters::run($this, __FUNCTION__, $params, function($params) {
extract($params);
if ($fields) {
return $this->_instance('schema', compact('fields'));
}
$name = $this->_entityName($entity, ['quoted' => true]);
$columns = $this->read("PRAGMA table_info({$name})", ['return' => 'array']);
$fields = [];
foreach ($columns as $column) {
$schema = $this->_column($column['type']);
$default = $column['dflt_value'];
if (preg_match("/^'(.*)'/", $default, $match)) {
$default = $match[1];
} elseif ($schema['type'] === 'boolean') {
$default = !!$default;
} else {
$default = null;
}
$fields[$column['name']] = $schema + [
'null' => $column['notnull'] === '1',
'default' => $default
];
}
return $this->_instance('schema', compact('fields'));
});
} | [
"public",
"function",
"describe",
"(",
"$",
"entity",
",",
"$",
"fields",
"=",
"[",
"]",
",",
"array",
"$",
"meta",
"=",
"[",
"]",
")",
"{",
"$",
"params",
"=",
"compact",
"(",
"'entity'",
",",
"'meta'",
",",
"'fields'",
")",
";",
"return",
"Filter... | Gets the column schema for a given Sqlite3 table.
A column type may not always be available, i.e. when during creation of
the column no type was declared. Those columns are internally treated
by SQLite3 as having a `NONE` affinity. The final schema will contain no
information about type and length of such columns (both values will be
`null`).
@param mixed $entity Specifies the table name for which the schema should be returned, or
the class name of the model object requesting the schema, in which case the model
class will be queried for the correct table name.
@param array $fields Any schema data pre-defined by the model.
@param array $meta
@return array Returns an associative array describing the given table's schema, where the
array keys are the available fields, and the values are arrays describing each
field, containing the following keys:
- `'type'`: The field type name
@filter | [
"Gets",
"the",
"column",
"schema",
"for",
"a",
"given",
"Sqlite3",
"table",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/database/adapter/Sqlite3.php#L200-L231 |
UnionOfRAD/lithium | data/source/database/adapter/Sqlite3.php | Sqlite3.encoding | public function encoding($encoding = null) {
if ($encoding === null) {
$encoding = $this->connection
->query('PRAGMA encoding')
->fetchColumn();
return $encoding === 'utf8' ? 'UTF-8' : $encoding;
}
if (strcasecmp($encoding, 'utf-8') === 0 || strcasecmp($encoding, 'utf8') === 0) {
$encoding = 'utf8';
}
return $this->connection->exec("PRAGMA encoding = \"{$encoding}\"") !== false;
} | php | public function encoding($encoding = null) {
if ($encoding === null) {
$encoding = $this->connection
->query('PRAGMA encoding')
->fetchColumn();
return $encoding === 'utf8' ? 'UTF-8' : $encoding;
}
if (strcasecmp($encoding, 'utf-8') === 0 || strcasecmp($encoding, 'utf8') === 0) {
$encoding = 'utf8';
}
return $this->connection->exec("PRAGMA encoding = \"{$encoding}\"") !== false;
} | [
"public",
"function",
"encoding",
"(",
"$",
"encoding",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"encoding",
"===",
"null",
")",
"{",
"$",
"encoding",
"=",
"$",
"this",
"->",
"connection",
"->",
"query",
"(",
"'PRAGMA encoding'",
")",
"->",
"fetchColumn",
... | Getter/Setter for the connection's encoding.
Sqlite uses the string `utf8` to identify the UTF-8 encoding. In general `UTF-8` is used
to identify that encoding. This methods allows both strings to be used for _setting_ the
encoding (in lower and uppercase, with or without dash) and will transparently convert
to Sqlite native format. When _getting_ the encoding, it is converted back into `UTF-8`.
So that this method should ever only return `UTF-8` when the encoding is used.
@param null|string $encoding Either `null` to retrieve the current encoding, or
a string to set the current encoding to. For UTF-8 accepts any permutation.
@return string|boolean When $encoding is `null` returns the current encoding
in effect, otherwise a boolean indicating if setting the encoding
succeeded or failed. Returns `'UTF-8'` when this encoding is used. | [
"Getter",
"/",
"Setter",
"for",
"the",
"connection",
"s",
"encoding",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/database/adapter/Sqlite3.php#L259-L271 |
UnionOfRAD/lithium | data/source/mongo_db/Result.php | Result._fetch | protected function _fetch() {
if (!$this->_resource) {
return false;
}
if (!$this->_resource->hasNext()) {
return null;
}
$result = $this->_resource->getNext();
if ($result instanceof MongoGridFSFile) {
$result = ['file' => $result] + $result->file;
}
return [$this->_iterator, $result];
} | php | protected function _fetch() {
if (!$this->_resource) {
return false;
}
if (!$this->_resource->hasNext()) {
return null;
}
$result = $this->_resource->getNext();
if ($result instanceof MongoGridFSFile) {
$result = ['file' => $result] + $result->file;
}
return [$this->_iterator, $result];
} | [
"protected",
"function",
"_fetch",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_resource",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"_resource",
"->",
"hasNext",
"(",
")",
")",
"{",
"return",
"null",
";",
"... | Fetches the next result from the resource.
@return array|boolean|null Returns a key/value pair for the next result,
`null` if there is none, `false` if something bad happened. | [
"Fetches",
"the",
"next",
"result",
"from",
"the",
"resource",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/source/mongo_db/Result.php#L28-L41 |
UnionOfRAD/lithium | g11n/catalog/adapter/Gettext.php | Gettext.read | public function read($category, $locale, $scope) {
$files = $this->_files($category, $locale, $scope);
foreach ($files as $file) {
$method = '_parse' . ucfirst(pathinfo($file, PATHINFO_EXTENSION));
if (!file_exists($file) || !is_readable($file)) {
continue;
}
$stream = fopen($file, 'rb');
$data = $this->{$method}($stream);
fclose($stream);
if ($data) {
$data['pluralRule'] = [
'id' => 'pluralRule',
'translated' => function($count) {
return $count !== 1;
}
];
return $data;
}
}
} | php | public function read($category, $locale, $scope) {
$files = $this->_files($category, $locale, $scope);
foreach ($files as $file) {
$method = '_parse' . ucfirst(pathinfo($file, PATHINFO_EXTENSION));
if (!file_exists($file) || !is_readable($file)) {
continue;
}
$stream = fopen($file, 'rb');
$data = $this->{$method}($stream);
fclose($stream);
if ($data) {
$data['pluralRule'] = [
'id' => 'pluralRule',
'translated' => function($count) {
return $count !== 1;
}
];
return $data;
}
}
} | [
"public",
"function",
"read",
"(",
"$",
"category",
",",
"$",
"locale",
",",
"$",
"scope",
")",
"{",
"$",
"files",
"=",
"$",
"this",
"->",
"_files",
"(",
"$",
"category",
",",
"$",
"locale",
",",
"$",
"scope",
")",
";",
"foreach",
"(",
"$",
"file... | Reads data.
MO files are preferred over PO files when existent.
@see lithium\g11n\catalog\adapter\Gettext::_files()
@param string $category A category.
@param string $locale A locale identifier.
@param string $scope The scope for the current operation.
@return array | [
"Reads",
"data",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/g11n/catalog/adapter/Gettext.php#L115-L138 |
UnionOfRAD/lithium | g11n/catalog/adapter/Gettext.php | Gettext.write | public function write($category, $locale, $scope, array $data) {
$files = $this->_files($category, $locale, $scope);
foreach ($files as $file) {
$method = '_compile' . ucfirst(pathinfo($file, PATHINFO_EXTENSION));
if (!$stream = fopen($file, 'wb')) {
return false;
}
$this->{$method}($stream, $data);
fclose($stream);
}
return true;
} | php | public function write($category, $locale, $scope, array $data) {
$files = $this->_files($category, $locale, $scope);
foreach ($files as $file) {
$method = '_compile' . ucfirst(pathinfo($file, PATHINFO_EXTENSION));
if (!$stream = fopen($file, 'wb')) {
return false;
}
$this->{$method}($stream, $data);
fclose($stream);
}
return true;
} | [
"public",
"function",
"write",
"(",
"$",
"category",
",",
"$",
"locale",
",",
"$",
"scope",
",",
"array",
"$",
"data",
")",
"{",
"$",
"files",
"=",
"$",
"this",
"->",
"_files",
"(",
"$",
"category",
",",
"$",
"locale",
",",
"$",
"scope",
")",
";"... | Writes data.
@param string $category A category.
@param string $locale A locale identifier.
@param string $scope The scope for the current operation.
@param array $data The data to write.
@return boolean | [
"Writes",
"data",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/g11n/catalog/adapter/Gettext.php#L149-L162 |
UnionOfRAD/lithium | g11n/catalog/adapter/Gettext.php | Gettext._files | protected function _files($category, $locale, $scope) {
$path = $this->_config['path'];
$scope = $scope ?: 'default';
if (($pos = strpos($category, 'Template')) !== false) {
$category = substr($category, 0, $pos);
return ["{$path}/{$category}_{$scope}.pot"];
}
if ($category === 'message') {
$category = 'messages';
}
$category = strtoupper($category);
return [
"{$path}/{$locale}/LC_{$category}/{$scope}.mo",
"{$path}/{$locale}/LC_{$category}/{$scope}.po"
];
} | php | protected function _files($category, $locale, $scope) {
$path = $this->_config['path'];
$scope = $scope ?: 'default';
if (($pos = strpos($category, 'Template')) !== false) {
$category = substr($category, 0, $pos);
return ["{$path}/{$category}_{$scope}.pot"];
}
if ($category === 'message') {
$category = 'messages';
}
$category = strtoupper($category);
return [
"{$path}/{$locale}/LC_{$category}/{$scope}.mo",
"{$path}/{$locale}/LC_{$category}/{$scope}.po"
];
} | [
"protected",
"function",
"_files",
"(",
"$",
"category",
",",
"$",
"locale",
",",
"$",
"scope",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"_config",
"[",
"'path'",
"]",
";",
"$",
"scope",
"=",
"$",
"scope",
"?",
":",
"'default'",
";",
"if",
... | Returns absolute paths to files according to configuration.
@param string $category
@param string $locale
@param string $scope
@return array | [
"Returns",
"absolute",
"paths",
"to",
"files",
"according",
"to",
"configuration",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/g11n/catalog/adapter/Gettext.php#L172-L190 |
UnionOfRAD/lithium | g11n/catalog/adapter/Gettext.php | Gettext._parsePo | protected function _parsePo($stream) {
$defaults = [
'ids' => [],
'translated' => null,
'flags' => [],
'comments' => [],
'occurrences' => [],
'context' => null
];
$data = [];
$item = $defaults;
while ($line = fgets($stream)) {
$line = trim($line);
if ($line === '') {
$data = $this->_merge($data, $item);
$item = $defaults;
} elseif (substr($line, 0, 3) === '#~ ') {
$item['flags']['obsolete'] = true;
} elseif (substr($line, 0, 3) === '#, ') {
$item['flags'][substr($line, 3)] = true;
} elseif (substr($line, 0, 3) === '#: ') {
$item['occurrences'][] = [
'file' => strtok(substr($line, 3), ':'),
'line' => strtok(':')
];
} elseif (substr($line, 0, 3) === '#. ') {
$item['comments'][] = substr($line, 3);
} elseif ($line[0] === '#') {
$item['comments'][] = ltrim(substr($line, 1));
} elseif (substr($line, 0, 7) === 'msgid "') {
$item['ids']['singular'] = substr($line, 7, -1);
} elseif (substr($line, 0, 9) === 'msgctxt "') {
$item['context'] = substr($line, 9, -1);
} elseif (substr($line, 0, 8) === 'msgstr "') {
$item['translated'] = substr($line, 8, -1);
} elseif ($line[0] === '"') {
$continues = isset($item['translated']) ? 'translated' : 'ids';
if (is_array($item[$continues])) {
end($item[$continues]);
$item[$continues][key($item[$continues])] .= substr($line, 1, -1);
} else {
$item[$continues] .= substr($line, 1, -1);
}
} elseif (substr($line, 0, 14) === 'msgid_plural "') {
$item['ids']['plural'] = substr($line, 14, -1);
} elseif (substr($line, 0, 7) === 'msgstr[') {
$item['translated'][(integer) substr($line, 7, 1)] = substr($line, 11, -1);
}
}
return $this->_merge($data, $item);
} | php | protected function _parsePo($stream) {
$defaults = [
'ids' => [],
'translated' => null,
'flags' => [],
'comments' => [],
'occurrences' => [],
'context' => null
];
$data = [];
$item = $defaults;
while ($line = fgets($stream)) {
$line = trim($line);
if ($line === '') {
$data = $this->_merge($data, $item);
$item = $defaults;
} elseif (substr($line, 0, 3) === '#~ ') {
$item['flags']['obsolete'] = true;
} elseif (substr($line, 0, 3) === '#, ') {
$item['flags'][substr($line, 3)] = true;
} elseif (substr($line, 0, 3) === '#: ') {
$item['occurrences'][] = [
'file' => strtok(substr($line, 3), ':'),
'line' => strtok(':')
];
} elseif (substr($line, 0, 3) === '#. ') {
$item['comments'][] = substr($line, 3);
} elseif ($line[0] === '#') {
$item['comments'][] = ltrim(substr($line, 1));
} elseif (substr($line, 0, 7) === 'msgid "') {
$item['ids']['singular'] = substr($line, 7, -1);
} elseif (substr($line, 0, 9) === 'msgctxt "') {
$item['context'] = substr($line, 9, -1);
} elseif (substr($line, 0, 8) === 'msgstr "') {
$item['translated'] = substr($line, 8, -1);
} elseif ($line[0] === '"') {
$continues = isset($item['translated']) ? 'translated' : 'ids';
if (is_array($item[$continues])) {
end($item[$continues]);
$item[$continues][key($item[$continues])] .= substr($line, 1, -1);
} else {
$item[$continues] .= substr($line, 1, -1);
}
} elseif (substr($line, 0, 14) === 'msgid_plural "') {
$item['ids']['plural'] = substr($line, 14, -1);
} elseif (substr($line, 0, 7) === 'msgstr[') {
$item['translated'][(integer) substr($line, 7, 1)] = substr($line, 11, -1);
}
}
return $this->_merge($data, $item);
} | [
"protected",
"function",
"_parsePo",
"(",
"$",
"stream",
")",
"{",
"$",
"defaults",
"=",
"[",
"'ids'",
"=>",
"[",
"]",
",",
"'translated'",
"=>",
"null",
",",
"'flags'",
"=>",
"[",
"]",
",",
"'comments'",
"=>",
"[",
"]",
",",
"'occurrences'",
"=>",
"... | Parses portable object (PO) format.
This parser sacrifices some features of the reference implementation the
differences to that implementation are as follows.
- No support for comments spanning multiple lines.
- Translator and extracted comments are treated as being the same type.
- Message IDs are allowed to have other encodings as just US-ASCII.
Items with an empty id are ignored. For more information see `_merge()`.
@param resource $stream
@return array | [
"Parses",
"portable",
"object",
"(",
"PO",
")",
"format",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/g11n/catalog/adapter/Gettext.php#L206-L259 |
UnionOfRAD/lithium | g11n/catalog/adapter/Gettext.php | Gettext._parseMo | protected function _parseMo($stream) {
$stat = fstat($stream);
if ($stat['size'] < static::MO_HEADER_SIZE) {
throw new RangeException("MO stream content has an invalid format.");
}
$magic = unpack('V1', fread($stream, 4));
$magic = hexdec(substr(dechex(current($magic)), -8));
if ($magic == static::MO_LITTLE_ENDIAN_MAGIC) {
$isBigEndian = false;
} elseif ($magic == static::MO_BIG_ENDIAN_MAGIC) {
$isBigEndian = true;
} else {
throw new RangeException("MO stream content has an invalid format.");
}
$header = [
'formatRevision' => null,
'count' => null,
'offsetId' => null,
'offsetTranslated' => null,
'sizeHashes' => null,
'offsetHashes' => null
];
foreach ($header as &$value) {
$value = $this->_readLong($stream, $isBigEndian);
}
extract($header);
$data = [];
for ($i = 0; $i < $count; $i++) {
$singularId = $pluralId = null;
$translated = null;
$context = null;
fseek($stream, $offsetId + $i * 8);
$length = $this->_readLong($stream, $isBigEndian);
$offset = $this->_readLong($stream, $isBigEndian);
if ($length < 1) {
continue;
}
fseek($stream, $offset);
$singularId = fread($stream, $length);
if (strpos($singularId, "\000") !== false) {
list($singularId, $pluralId) = explode("\000", $singularId);
}
if (strpos($singularId, "\004") !== false) {
list($context, $singularId) = explode("\004", $singularId);
}
fseek($stream, $offsetTranslated + $i * 8);
$length = $this->_readLong($stream, $isBigEndian);
$offset = $this->_readLong($stream, $isBigEndian);
fseek($stream, $offset);
$translated = fread($stream, $length);
if (strpos($translated, "\000") !== false) {
$translated = explode("\000", $translated);
}
$ids = ['singular' => $singularId, 'plural' => $pluralId];
$data = $this->_merge($data, compact('ids', 'translated', 'context'));
}
return $data;
} | php | protected function _parseMo($stream) {
$stat = fstat($stream);
if ($stat['size'] < static::MO_HEADER_SIZE) {
throw new RangeException("MO stream content has an invalid format.");
}
$magic = unpack('V1', fread($stream, 4));
$magic = hexdec(substr(dechex(current($magic)), -8));
if ($magic == static::MO_LITTLE_ENDIAN_MAGIC) {
$isBigEndian = false;
} elseif ($magic == static::MO_BIG_ENDIAN_MAGIC) {
$isBigEndian = true;
} else {
throw new RangeException("MO stream content has an invalid format.");
}
$header = [
'formatRevision' => null,
'count' => null,
'offsetId' => null,
'offsetTranslated' => null,
'sizeHashes' => null,
'offsetHashes' => null
];
foreach ($header as &$value) {
$value = $this->_readLong($stream, $isBigEndian);
}
extract($header);
$data = [];
for ($i = 0; $i < $count; $i++) {
$singularId = $pluralId = null;
$translated = null;
$context = null;
fseek($stream, $offsetId + $i * 8);
$length = $this->_readLong($stream, $isBigEndian);
$offset = $this->_readLong($stream, $isBigEndian);
if ($length < 1) {
continue;
}
fseek($stream, $offset);
$singularId = fread($stream, $length);
if (strpos($singularId, "\000") !== false) {
list($singularId, $pluralId) = explode("\000", $singularId);
}
if (strpos($singularId, "\004") !== false) {
list($context, $singularId) = explode("\004", $singularId);
}
fseek($stream, $offsetTranslated + $i * 8);
$length = $this->_readLong($stream, $isBigEndian);
$offset = $this->_readLong($stream, $isBigEndian);
fseek($stream, $offset);
$translated = fread($stream, $length);
if (strpos($translated, "\000") !== false) {
$translated = explode("\000", $translated);
}
$ids = ['singular' => $singularId, 'plural' => $pluralId];
$data = $this->_merge($data, compact('ids', 'translated', 'context'));
}
return $data;
} | [
"protected",
"function",
"_parseMo",
"(",
"$",
"stream",
")",
"{",
"$",
"stat",
"=",
"fstat",
"(",
"$",
"stream",
")",
";",
"if",
"(",
"$",
"stat",
"[",
"'size'",
"]",
"<",
"static",
"::",
"MO_HEADER_SIZE",
")",
"{",
"throw",
"new",
"RangeException",
... | Parses machine object (MO) format, independent of the machine's endian it
was created on. Both 32bit and 64bit systems are supported.
@link https://www.gnu.org/software/gettext/manual/html_node/MO-Files.html
@param resource $stream
@return array
@throws RangeException If stream content has an invalid format. | [
"Parses",
"machine",
"object",
"(",
"MO",
")",
"format",
"independent",
"of",
"the",
"machine",
"s",
"endian",
"it",
"was",
"created",
"on",
".",
"Both",
"32bit",
"and",
"64bit",
"systems",
"are",
"supported",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/g11n/catalog/adapter/Gettext.php#L280-L351 |
UnionOfRAD/lithium | g11n/catalog/adapter/Gettext.php | Gettext._compilePo | protected function _compilePo($stream, array $data) {
$output[] = '# This file is distributed under the same license as the PACKAGE package.';
$output[] = '#';
$output[] = 'msgctxt ""';
$output[] = 'msgid ""';
$output[] = 'msgstr ""';
$output[] = '"Project-Id-Version: PACKAGE VERSION\n"';
$output[] = '"POT-Creation-Date: YEAR-MO-DA HO:MI+ZONE\n"';
$output[] = '"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"';
$output[] = '"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"';
$output[] = '"Language-Team: LANGUAGE <EMAIL@ADDRESS>\n"';
$output[] = '"MIME-Version: 1.0\n"';
$output[] = '"Content-Type: text/plain; charset=UTF-8\n"';
$output[] = '"Content-Transfer-Encoding: 8bit\n"';
$output[] = '"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"';
$output[] = '';
$output = implode("\n", $output) . "\n";
fwrite($stream, $output);
foreach ($data as $key => $item) {
$output = [];
$item = $this->_prepareForWrite($item);
foreach ($item['occurrences'] as $occurrence) {
$output[] = "#: {$occurrence['file']}:{$occurrence['line']}";
}
foreach ($item['comments'] as $comment) {
$output[] = "#. {$comment}";
}
foreach ($item['flags'] as $flag => $value) {
$output[] = "#, {$flag}";
}
if (isset($item['context'])) {
$output[] = "msgctxt \"{$item['context']}\"";
}
$output[] = "msgid \"{$item['ids']['singular']}\"";
if (isset($item['ids']['plural'])) {
$output[] = "msgid_plural \"{$item['ids']['plural']}\"";
foreach ((array) $item['translated'] ?: [null, null] as $key => $value) {
$output[] = "msgstr[{$key}] \"{$value}\"";
}
} else {
if (is_array($item['translated'])) {
$item['translated'] = array_pop($item['translated']);
}
$output[] = "msgstr \"{$item['translated']}\"";
}
$output[] = '';
$output = implode("\n", $output) . "\n";
fwrite($stream, $output);
}
return true;
} | php | protected function _compilePo($stream, array $data) {
$output[] = '# This file is distributed under the same license as the PACKAGE package.';
$output[] = '#';
$output[] = 'msgctxt ""';
$output[] = 'msgid ""';
$output[] = 'msgstr ""';
$output[] = '"Project-Id-Version: PACKAGE VERSION\n"';
$output[] = '"POT-Creation-Date: YEAR-MO-DA HO:MI+ZONE\n"';
$output[] = '"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"';
$output[] = '"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"';
$output[] = '"Language-Team: LANGUAGE <EMAIL@ADDRESS>\n"';
$output[] = '"MIME-Version: 1.0\n"';
$output[] = '"Content-Type: text/plain; charset=UTF-8\n"';
$output[] = '"Content-Transfer-Encoding: 8bit\n"';
$output[] = '"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"';
$output[] = '';
$output = implode("\n", $output) . "\n";
fwrite($stream, $output);
foreach ($data as $key => $item) {
$output = [];
$item = $this->_prepareForWrite($item);
foreach ($item['occurrences'] as $occurrence) {
$output[] = "#: {$occurrence['file']}:{$occurrence['line']}";
}
foreach ($item['comments'] as $comment) {
$output[] = "#. {$comment}";
}
foreach ($item['flags'] as $flag => $value) {
$output[] = "#, {$flag}";
}
if (isset($item['context'])) {
$output[] = "msgctxt \"{$item['context']}\"";
}
$output[] = "msgid \"{$item['ids']['singular']}\"";
if (isset($item['ids']['plural'])) {
$output[] = "msgid_plural \"{$item['ids']['plural']}\"";
foreach ((array) $item['translated'] ?: [null, null] as $key => $value) {
$output[] = "msgstr[{$key}] \"{$value}\"";
}
} else {
if (is_array($item['translated'])) {
$item['translated'] = array_pop($item['translated']);
}
$output[] = "msgstr \"{$item['translated']}\"";
}
$output[] = '';
$output = implode("\n", $output) . "\n";
fwrite($stream, $output);
}
return true;
} | [
"protected",
"function",
"_compilePo",
"(",
"$",
"stream",
",",
"array",
"$",
"data",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"'# This file is distributed under the same license as the PACKAGE package.'",
";",
"$",
"output",
"[",
"]",
"=",
"'#'",
";",
"$",
"outp... | Compiles data into portable object (PO) format.
To improve portability accross libraries the header is generated according
to the format of the output of `xgettext`. This means using the same names for
placeholders as well as including an empty entry. The empty entry at the
beginning aids in parsing the file as it _attracts_ the preceding comments and
following metadata when parsed which could otherwise be mistaken as a continued
translation. The only difference in the header format is the initial header which
just features one line of text.
@param resource $stream
@param array $data
@return boolean | [
"Compiles",
"data",
"into",
"portable",
"object",
"(",
"PO",
")",
"format",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/g11n/catalog/adapter/Gettext.php#L381-L436 |
UnionOfRAD/lithium | g11n/catalog/adapter/Gettext.php | Gettext._prepareForWrite | protected function _prepareForWrite(array $item) {
$filter = function ($value) use (&$filter) {
if (is_array($value)) {
return array_map($filter, $value);
}
$value = strtr($value, ["\\'" => "'", "\\\\" => "\\", "\r\n" => "\n"]);
$value = addcslashes($value, "\0..\37\\\"");
return $value;
};
$fields = ['id', 'ids', 'translated', 'context'];
foreach ($fields as $field) {
if (isset($item[$field])) {
$item[$field] = $filter($item[$field]);
}
}
if (!isset($item['ids']['singular'])) {
$item['ids']['singular'] = $item['id'];
}
$path = Libraries::get(true, 'path');
if (isset($item['occurrences'])) {
foreach ($item['occurrences'] as &$occurrence) {
$occurrence['file'] = str_replace($path, '', $occurrence['file']);
}
}
return parent::_prepareForWrite($item);
} | php | protected function _prepareForWrite(array $item) {
$filter = function ($value) use (&$filter) {
if (is_array($value)) {
return array_map($filter, $value);
}
$value = strtr($value, ["\\'" => "'", "\\\\" => "\\", "\r\n" => "\n"]);
$value = addcslashes($value, "\0..\37\\\"");
return $value;
};
$fields = ['id', 'ids', 'translated', 'context'];
foreach ($fields as $field) {
if (isset($item[$field])) {
$item[$field] = $filter($item[$field]);
}
}
if (!isset($item['ids']['singular'])) {
$item['ids']['singular'] = $item['id'];
}
$path = Libraries::get(true, 'path');
if (isset($item['occurrences'])) {
foreach ($item['occurrences'] as &$occurrence) {
$occurrence['file'] = str_replace($path, '', $occurrence['file']);
}
}
return parent::_prepareForWrite($item);
} | [
"protected",
"function",
"_prepareForWrite",
"(",
"array",
"$",
"item",
")",
"{",
"$",
"filter",
"=",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"&",
"$",
"filter",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"... | Prepares an item before it is being written and escapes fields.
All characters from \000 to \037 (this includes new line and tab characters)
as well as the backslash (`\`) and the double quote (`"`) are escaped.
Literal Windows CRLFs (`\r\n`) are converted to LFs (`\n`) to improve cross platform
compatibility. Escaped single quotes (`'`) are unescaped as they should not need to be.
Double escaped characters are maintained and not escaped once again.
@link http://www.asciitable.com
@see lithium\g11n\catalog\Adapter::_prepareForWrite()
@param array $item
@return array | [
"Prepares",
"an",
"item",
"before",
"it",
"is",
"being",
"written",
"and",
"escapes",
"fields",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/g11n/catalog/adapter/Gettext.php#L474-L500 |
UnionOfRAD/lithium | g11n/catalog/adapter/Gettext.php | Gettext._merge | protected function _merge(array $data, array $item) {
$filter = function ($value) use (&$filter) {
if (is_array($value)) {
return array_map($filter, $value);
}
return stripcslashes($value);
};
$fields = ['id', 'ids', 'translated', 'context'];
foreach ($fields as $field) {
if (isset($item[$field])) {
$item[$field] = $filter($item[$field]);
}
}
if (isset($item['ids']['singular'])) {
$item['id'] = $item['ids']['singular'];
}
if (empty($item['id']) || ctype_space($item['id'])) {
return $data;
}
return parent::_merge($data, $item);
} | php | protected function _merge(array $data, array $item) {
$filter = function ($value) use (&$filter) {
if (is_array($value)) {
return array_map($filter, $value);
}
return stripcslashes($value);
};
$fields = ['id', 'ids', 'translated', 'context'];
foreach ($fields as $field) {
if (isset($item[$field])) {
$item[$field] = $filter($item[$field]);
}
}
if (isset($item['ids']['singular'])) {
$item['id'] = $item['ids']['singular'];
}
if (empty($item['id']) || ctype_space($item['id'])) {
return $data;
}
return parent::_merge($data, $item);
} | [
"protected",
"function",
"_merge",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"item",
")",
"{",
"$",
"filter",
"=",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"&",
"$",
"filter",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")... | Merges an item into given data and unescapes fields.
Please note that items with an id containing exclusively whitespace characters
or are empty are **not** being merged. Whitespace characters are space, tab, vertical
tab, line feed, carriage return and form feed.
@see lithium\g11n\catalog\Adapter::_merge()
@param array $data Data to merge item into.
@param array $item Item to merge into $data.
@return array The merged data. | [
"Merges",
"an",
"item",
"into",
"given",
"data",
"and",
"unescapes",
"fields",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/g11n/catalog/adapter/Gettext.php#L514-L535 |
UnionOfRAD/lithium | storage/cache/adapter/XCache.php | XCache.read | public function read(array $keys) {
if ($this->_config['scope']) {
$keys = $this->_addScopePrefix($this->_config['scope'], $keys);
}
$results = [];
foreach ($keys as $key) {
$result = xcache_get($key);
if ($result === null && !xcache_isset($key)) {
continue;
}
$results[$key] = $result;
}
if ($this->_config['scope']) {
$results = $this->_removeScopePrefix($this->_config['scope'], $results);
}
return $results;
} | php | public function read(array $keys) {
if ($this->_config['scope']) {
$keys = $this->_addScopePrefix($this->_config['scope'], $keys);
}
$results = [];
foreach ($keys as $key) {
$result = xcache_get($key);
if ($result === null && !xcache_isset($key)) {
continue;
}
$results[$key] = $result;
}
if ($this->_config['scope']) {
$results = $this->_removeScopePrefix($this->_config['scope'], $results);
}
return $results;
} | [
"public",
"function",
"read",
"(",
"array",
"$",
"keys",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_config",
"[",
"'scope'",
"]",
")",
"{",
"$",
"keys",
"=",
"$",
"this",
"->",
"_addScopePrefix",
"(",
"$",
"this",
"->",
"_config",
"[",
"'scope'",
"]... | Read values from the cache. Will attempt to return an array of data
containing key/value pairs of the requested data.
Note that this is not an atomic operation when using multiple keys.
@param array $keys Keys to uniquely identify the cached items.
@return array Cached values keyed by cache keys on successful read,
keys which could not be read will not be included in
the results array. | [
"Read",
"values",
"from",
"the",
"cache",
".",
"Will",
"attempt",
"to",
"return",
"an",
"array",
"of",
"data",
"containing",
"key",
"/",
"value",
"pairs",
"of",
"the",
"requested",
"data",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/storage/cache/adapter/XCache.php#L120-L138 |
UnionOfRAD/lithium | storage/cache/adapter/XCache.php | XCache.delete | public function delete(array $keys) {
if ($this->_config['scope']) {
$keys = $this->_addScopePrefix($this->_config['scope'], $keys);
}
foreach ($keys as $key) {
if (!xcache_unset($key)) {
return false;
}
}
return true;
} | php | public function delete(array $keys) {
if ($this->_config['scope']) {
$keys = $this->_addScopePrefix($this->_config['scope'], $keys);
}
foreach ($keys as $key) {
if (!xcache_unset($key)) {
return false;
}
}
return true;
} | [
"public",
"function",
"delete",
"(",
"array",
"$",
"keys",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_config",
"[",
"'scope'",
"]",
")",
"{",
"$",
"keys",
"=",
"$",
"this",
"->",
"_addScopePrefix",
"(",
"$",
"this",
"->",
"_config",
"[",
"'scope'",
... | Will attempt to remove specified keys from the user space cache.
Note that this is not an atomic operation when using multiple keys.
@param array $keys Keys to uniquely identify the cached items.
@return boolean `true` on successful delete, `false` otherwise. | [
"Will",
"attempt",
"to",
"remove",
"specified",
"keys",
"from",
"the",
"user",
"space",
"cache",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/storage/cache/adapter/XCache.php#L148-L158 |
UnionOfRAD/lithium | storage/cache/adapter/XCache.php | XCache.clear | public function clear() {
$admin = (ini_get('xcache.admin.enable_auth') === "On");
if ($admin && (!isset($this->_config['username']) || !isset($this->_config['password']))) {
return false;
}
$credentials = [];
if (isset($_SERVER['PHP_AUTH_USER'])) {
$credentials['username'] = $_SERVER['PHP_AUTH_USER'];
$_SERVER['PHP_AUTH_USER'] = $this->_config['username'];
}
if (isset($_SERVER['PHP_AUTH_PW'])) {
$credentials['password'] = $_SERVER['PHP_AUTH_PW'];
$_SERVER['PHP_AUTH_PW'] = $this->_config['pass'];
}
for ($i = 0, $max = xcache_count(XC_TYPE_VAR); $i < $max; $i++) {
if (xcache_clear_cache(XC_TYPE_VAR, $i) === false) {
return false;
}
}
if (isset($_SERVER['PHP_AUTH_USER'])) {
$_SERVER['PHP_AUTH_USER'] = $credentials['username'];
}
if (isset($_SERVER['PHP_AUTH_PW'])) {
$_SERVER['PHP_AUTH_PW'] = $credentials['password'];
}
return true;
} | php | public function clear() {
$admin = (ini_get('xcache.admin.enable_auth') === "On");
if ($admin && (!isset($this->_config['username']) || !isset($this->_config['password']))) {
return false;
}
$credentials = [];
if (isset($_SERVER['PHP_AUTH_USER'])) {
$credentials['username'] = $_SERVER['PHP_AUTH_USER'];
$_SERVER['PHP_AUTH_USER'] = $this->_config['username'];
}
if (isset($_SERVER['PHP_AUTH_PW'])) {
$credentials['password'] = $_SERVER['PHP_AUTH_PW'];
$_SERVER['PHP_AUTH_PW'] = $this->_config['pass'];
}
for ($i = 0, $max = xcache_count(XC_TYPE_VAR); $i < $max; $i++) {
if (xcache_clear_cache(XC_TYPE_VAR, $i) === false) {
return false;
}
}
if (isset($_SERVER['PHP_AUTH_USER'])) {
$_SERVER['PHP_AUTH_USER'] = $credentials['username'];
}
if (isset($_SERVER['PHP_AUTH_PW'])) {
$_SERVER['PHP_AUTH_PW'] = $credentials['password'];
}
return true;
} | [
"public",
"function",
"clear",
"(",
")",
"{",
"$",
"admin",
"=",
"(",
"ini_get",
"(",
"'xcache.admin.enable_auth'",
")",
"===",
"\"On\"",
")",
";",
"if",
"(",
"$",
"admin",
"&&",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_config",
"[",
"'username'",
... | Clears entire user-space cache by flushing it. All cache keys
using the configuration but *without* honoring the scope are removed.
This method requires valid XCache admin credentials to be set when the adapter
was configured, due to the use of the xcache_clear_cache admin method. If the
`xcache.admin.enable_auth` ini setting is set to `Off`, no credentials required.
The behavior and result when removing a single key
during this process fails is unknown.
@return boolean `true` on successful clearing, `false` otherwise. | [
"Clears",
"entire",
"user",
"-",
"space",
"cache",
"by",
"flushing",
"it",
".",
"All",
"cache",
"keys",
"using",
"the",
"configuration",
"but",
"*",
"without",
"*",
"honoring",
"the",
"scope",
"are",
"removed",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/storage/cache/adapter/XCache.php#L206-L235 |
UnionOfRAD/lithium | net/http/Route.php | Route.parse | public function parse($request, array $options = []) {
$defaults = ['url' => $request->url];
$options += $defaults;
$url = '/' . trim($options['url'], '/');
$pattern = $this->_pattern;
if (!preg_match($pattern, $url, $match)) {
return false;
}
foreach ($this->_meta as $key => $compare) {
$value = $request->get($key);
if (!($compare == $value || (is_array($compare) && in_array($value, $compare)))) {
return false;
}
}
foreach ($this->_config['modifiers'] as $key => $modifier) {
if (isset($match[$key])) {
$match[$key] = $modifier($match[$key]);
}
}
$result = array_intersect_key($match + ['args' => []], $this->_keys);
foreach ($result as $key => $value) {
if ($value === '') {
unset($result[$key]);
}
}
$result += $this->_params + $this->_defaults;
$request->params = $result + (array) $request->params;
$request->persist = array_unique(array_merge($request->persist, $this->_persist));
if ($this->_handler) {
$handler = $this->_handler;
return $handler($request);
}
return $request;
} | php | public function parse($request, array $options = []) {
$defaults = ['url' => $request->url];
$options += $defaults;
$url = '/' . trim($options['url'], '/');
$pattern = $this->_pattern;
if (!preg_match($pattern, $url, $match)) {
return false;
}
foreach ($this->_meta as $key => $compare) {
$value = $request->get($key);
if (!($compare == $value || (is_array($compare) && in_array($value, $compare)))) {
return false;
}
}
foreach ($this->_config['modifiers'] as $key => $modifier) {
if (isset($match[$key])) {
$match[$key] = $modifier($match[$key]);
}
}
$result = array_intersect_key($match + ['args' => []], $this->_keys);
foreach ($result as $key => $value) {
if ($value === '') {
unset($result[$key]);
}
}
$result += $this->_params + $this->_defaults;
$request->params = $result + (array) $request->params;
$request->persist = array_unique(array_merge($request->persist, $this->_persist));
if ($this->_handler) {
$handler = $this->_handler;
return $handler($request);
}
return $request;
} | [
"public",
"function",
"parse",
"(",
"$",
"request",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'url'",
"=>",
"$",
"request",
"->",
"url",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"$",
"url",
"=... | Attempts to parse a request object and determine its execution details.
@see lithium\net\http\Request
@see lithium\net\http\Request::$params
@see lithium\net\http\Route::$_handler
@param \lithium\net\http\Request $request A request object containing the details of
the request to be routed.
@param array $options Used to determine the operation of the method, and override certain
values in the `Request` object:
- `'url'` _string_: If present, will be used to match in place of the `$url`
property of `$request`.
@return object|boolean If this route matches `$request`, returns the request with
execution details attached to it (inside `Request::$params`). Alternatively when
a route handler function was used, returns the result of its invocation. Returns
`false` if the route never matched. | [
"Attempts",
"to",
"parse",
"a",
"request",
"object",
"and",
"determine",
"its",
"execution",
"details",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/net/http/Route.php#L261-L298 |
UnionOfRAD/lithium | net/http/Route.php | Route.match | public function match(array $options = []) {
$defaults = ['action' => 'index', 'http:method' => 'GET'];
$query = null;
if (!$this->_config['continue']) {
$options += $defaults;
if (isset($options['?'])) {
$query = $options['?'];
$query = '?' . (is_array($query) ? http_build_query($query) : $query);
unset($options['?']);
}
}
if (!$options = $this->_matchMethod($options)) {
return false;
}
if (!$options = $this->_matchKeys($options)) {
return false;
}
foreach ($options as $key => $value) {
if (isset($this->_config['formatters'][$key])) {
$options[$key] = $this->_config['formatters'][$key]($value);
}
}
foreach ($this->_subPatterns as $key => $pattern) {
if (isset($options[$key]) && !preg_match("/^{$pattern}$/", $options[$key])) {
return false;
}
}
$defaults = $this->_defaults + $defaults;
if ($this->_config['continue']) {
return $this->_write(['args' => '{:args}'] + $options, $this->_defaults);
}
return $this->_write($options, $defaults + ['args' => '']) . $query;
} | php | public function match(array $options = []) {
$defaults = ['action' => 'index', 'http:method' => 'GET'];
$query = null;
if (!$this->_config['continue']) {
$options += $defaults;
if (isset($options['?'])) {
$query = $options['?'];
$query = '?' . (is_array($query) ? http_build_query($query) : $query);
unset($options['?']);
}
}
if (!$options = $this->_matchMethod($options)) {
return false;
}
if (!$options = $this->_matchKeys($options)) {
return false;
}
foreach ($options as $key => $value) {
if (isset($this->_config['formatters'][$key])) {
$options[$key] = $this->_config['formatters'][$key]($value);
}
}
foreach ($this->_subPatterns as $key => $pattern) {
if (isset($options[$key]) && !preg_match("/^{$pattern}$/", $options[$key])) {
return false;
}
}
$defaults = $this->_defaults + $defaults;
if ($this->_config['continue']) {
return $this->_write(['args' => '{:args}'] + $options, $this->_defaults);
}
return $this->_write($options, $defaults + ['args' => '']) . $query;
} | [
"public",
"function",
"match",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'action'",
"=>",
"'index'",
",",
"'http:method'",
"=>",
"'GET'",
"]",
";",
"$",
"query",
"=",
"null",
";",
"if",
"(",
"!",
"$",
"this"... | Matches a set of parameters against the route, and returns a URL string
if the route matches the parameters.
@param array $options An array of parameters.
@return string|boolean URL string on success, else `false` if the route didn't match. | [
"Matches",
"a",
"set",
"of",
"parameters",
"against",
"the",
"route",
"and",
"returns",
"a",
"URL",
"string",
"if",
"the",
"route",
"matches",
"the",
"parameters",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/net/http/Route.php#L307-L342 |
UnionOfRAD/lithium | net/http/Route.php | Route._matchMethod | protected function _matchMethod($options) {
$isMatch = (
!isset($this->_meta['http:method']) ||
$options['http:method'] === $this->_meta['http:method']
);
if (!$isMatch) {
return false;
}
unset($options['http:method']);
return $options;
} | php | protected function _matchMethod($options) {
$isMatch = (
!isset($this->_meta['http:method']) ||
$options['http:method'] === $this->_meta['http:method']
);
if (!$isMatch) {
return false;
}
unset($options['http:method']);
return $options;
} | [
"protected",
"function",
"_matchMethod",
"(",
"$",
"options",
")",
"{",
"$",
"isMatch",
"=",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_meta",
"[",
"'http:method'",
"]",
")",
"||",
"$",
"options",
"[",
"'http:method'",
"]",
"===",
"$",
"this",
"->",
... | Helper used by `Route::match()` which check if the required http method is compatible
with the route.
@see lithium\net\http\Route::match()
@param array $options An array of URL parameters.
@return mixed On success, returns an updated array of options, On failure, returns `false`. | [
"Helper",
"used",
"by",
"Route",
"::",
"match",
"()",
"which",
"check",
"if",
"the",
"required",
"http",
"method",
"is",
"compatible",
"with",
"the",
"route",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/net/http/Route.php#L363-L373 |
UnionOfRAD/lithium | net/http/Route.php | Route._matchKeys | protected function _matchKeys($options) {
$args = ['args' => 'args'];
$scope = [];
if (!empty($options['scope'])) {
$scope = (array) $options['scope'] + ['params' => []];
$scope = array_flip($scope['params']);
}
unset($options['scope']);
if (array_intersect_key($options, $this->_match) != $this->_match) {
return false;
}
if ($this->_config['continue']) {
if (array_intersect_key($this->_keys, $options + $args) != $this->_keys) {
return false;
}
} else {
if (array_diff_key($options, $this->_match + $this->_keys + $scope)) {
return false;
}
}
$options += $this->_defaults;
$base = $this->_keys + $args;
$match = array_intersect_key($this->_keys, $options) + $args;
sort($base);
sort($match);
if ($base !== $match) {
return false;
}
return $options;
} | php | protected function _matchKeys($options) {
$args = ['args' => 'args'];
$scope = [];
if (!empty($options['scope'])) {
$scope = (array) $options['scope'] + ['params' => []];
$scope = array_flip($scope['params']);
}
unset($options['scope']);
if (array_intersect_key($options, $this->_match) != $this->_match) {
return false;
}
if ($this->_config['continue']) {
if (array_intersect_key($this->_keys, $options + $args) != $this->_keys) {
return false;
}
} else {
if (array_diff_key($options, $this->_match + $this->_keys + $scope)) {
return false;
}
}
$options += $this->_defaults;
$base = $this->_keys + $args;
$match = array_intersect_key($this->_keys, $options) + $args;
sort($base);
sort($match);
if ($base !== $match) {
return false;
}
return $options;
} | [
"protected",
"function",
"_matchKeys",
"(",
"$",
"options",
")",
"{",
"$",
"args",
"=",
"[",
"'args'",
"=>",
"'args'",
"]",
";",
"$",
"scope",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'scope'",
"]",
")",
")",
"{",
... | A helper method used by `match()` to verify that options required to match this route are
present in a URL array.
@see lithium\net\http\Route::match()
@param array $options An array of URL parameters.
@return mixed On success, returns an updated array of options, merged with defaults. On
failure, returns `false`. | [
"A",
"helper",
"method",
"used",
"by",
"match",
"()",
"to",
"verify",
"that",
"options",
"required",
"to",
"match",
"this",
"route",
"are",
"present",
"in",
"a",
"URL",
"array",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/net/http/Route.php#L384-L416 |
UnionOfRAD/lithium | net/http/Route.php | Route._write | protected function _write($options, $defaults) {
$template = $this->_template;
$trimmed = true;
$options += ['args' => ''];
foreach (array_reverse($this->_keys, true) as $key) {
$value =& $options[$key];
$pattern = isset($this->_subPatterns[$key]) ? ":{$this->_subPatterns[$key]}" : '';
$rpl = "{:{$key}{$pattern}}";
$len = strlen($rpl) * -1;
if ($trimmed && isset($defaults[$key]) && $value == $defaults[$key]) {
if (substr($template, $len) == $rpl) {
$template = rtrim(substr($template, 0, $len), '/');
continue;
}
}
if ($value === null) {
$template = str_replace("/{$rpl}", '', $template);
continue;
}
if ($key !== 'args') {
$trimmed = false;
}
$template = str_replace($rpl, $value, $template);
}
return $template ?: '/';
} | php | protected function _write($options, $defaults) {
$template = $this->_template;
$trimmed = true;
$options += ['args' => ''];
foreach (array_reverse($this->_keys, true) as $key) {
$value =& $options[$key];
$pattern = isset($this->_subPatterns[$key]) ? ":{$this->_subPatterns[$key]}" : '';
$rpl = "{:{$key}{$pattern}}";
$len = strlen($rpl) * -1;
if ($trimmed && isset($defaults[$key]) && $value == $defaults[$key]) {
if (substr($template, $len) == $rpl) {
$template = rtrim(substr($template, 0, $len), '/');
continue;
}
}
if ($value === null) {
$template = str_replace("/{$rpl}", '', $template);
continue;
}
if ($key !== 'args') {
$trimmed = false;
}
$template = str_replace($rpl, $value, $template);
}
return $template ?: '/';
} | [
"protected",
"function",
"_write",
"(",
"$",
"options",
",",
"$",
"defaults",
")",
"{",
"$",
"template",
"=",
"$",
"this",
"->",
"_template",
";",
"$",
"trimmed",
"=",
"true",
";",
"$",
"options",
"+=",
"[",
"'args'",
"=>",
"''",
"]",
";",
"foreach",... | Writes a set of URL options to this route's template string.
@param array $options The options to write to this route, with defaults pre-merged.
@param array $defaults The default template options for this route (contains hard-coded
default values).
@return string Returns the route template string with option values inserted. | [
"Writes",
"a",
"set",
"of",
"URL",
"options",
"to",
"this",
"route",
"s",
"template",
"string",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/net/http/Route.php#L426-L453 |
UnionOfRAD/lithium | net/http/Route.php | Route.export | public function export() {
$result = [];
foreach ($this->_autoConfig as $key) {
if ($key === 'formatters') {
continue;
}
$result[$key] = $this->{'_' . $key};
}
return $result;
} | php | public function export() {
$result = [];
foreach ($this->_autoConfig as $key) {
if ($key === 'formatters') {
continue;
}
$result[$key] = $this->{'_' . $key};
}
return $result;
} | [
"public",
"function",
"export",
"(",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_autoConfig",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"'formatters'",
")",
"{",
"continue",
";",
"}",
"$",
"re... | Exports the properties that make up the route to an array, for debugging, caching or
introspection purposes.
@return array An array containing the properties of the route object, such as URL templates
and parameter lists. | [
"Exports",
"the",
"properties",
"that",
"make",
"up",
"the",
"route",
"to",
"an",
"array",
"for",
"debugging",
"caching",
"or",
"introspection",
"purposes",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/net/http/Route.php#L462-L472 |
UnionOfRAD/lithium | net/http/Route.php | Route.compile | public function compile() {
foreach ($this->_params as $key => $value) {
if (!strpos($key, ':')) {
continue;
}
unset($this->_params[$key]);
$this->_meta[$key] = $value;
}
$this->_match = $this->_params;
if ($this->_template === '/' || $this->_template === '') {
$this->_pattern = '@^/*$@';
return;
}
$this->_pattern = "@^{$this->_template}\$@";
$match = '@([/.])?\{:([^:}]+):?((?:[^{]+?(?:\{[0-9,]+\})?)*?)\}@S';
if ($this->_config['unicode']) {
$this->_pattern .= 'u';
}
preg_match_all($match, $this->_pattern, $m);
if (!$tokens = $m[0]) {
return;
}
$slashes = $m[1];
$params = $m[2];
$regexs = $m[3];
unset($m);
$this->_keys = [];
foreach ($params as $i => $param) {
$this->_keys[$param] = $param;
$this->_pattern = $this->_regex($regexs[$i], $param, $tokens[$i], $slashes[$i]);
}
$this->_defaults += array_intersect_key($this->_params, $this->_keys);
$this->_match = array_diff_key($this->_params, $this->_defaults);
} | php | public function compile() {
foreach ($this->_params as $key => $value) {
if (!strpos($key, ':')) {
continue;
}
unset($this->_params[$key]);
$this->_meta[$key] = $value;
}
$this->_match = $this->_params;
if ($this->_template === '/' || $this->_template === '') {
$this->_pattern = '@^/*$@';
return;
}
$this->_pattern = "@^{$this->_template}\$@";
$match = '@([/.])?\{:([^:}]+):?((?:[^{]+?(?:\{[0-9,]+\})?)*?)\}@S';
if ($this->_config['unicode']) {
$this->_pattern .= 'u';
}
preg_match_all($match, $this->_pattern, $m);
if (!$tokens = $m[0]) {
return;
}
$slashes = $m[1];
$params = $m[2];
$regexs = $m[3];
unset($m);
$this->_keys = [];
foreach ($params as $i => $param) {
$this->_keys[$param] = $param;
$this->_pattern = $this->_regex($regexs[$i], $param, $tokens[$i], $slashes[$i]);
}
$this->_defaults += array_intersect_key($this->_params, $this->_keys);
$this->_match = array_diff_key($this->_params, $this->_defaults);
} | [
"public",
"function",
"compile",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_params",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"strpos",
"(",
"$",
"key",
",",
"':'",
")",
")",
"{",
"continue",
";",
"}",
"unset",
"... | Compiles URL templates into regular expression patterns for matching against request URLs,
and extracts template parameters into match-parameter arrays.
@return void | [
"Compiles",
"URL",
"templates",
"into",
"regular",
"expression",
"patterns",
"for",
"matching",
"against",
"request",
"URLs",
"and",
"extracts",
"template",
"parameters",
"into",
"match",
"-",
"parameter",
"arrays",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/net/http/Route.php#L480-L518 |
UnionOfRAD/lithium | net/http/Route.php | Route._regex | protected function _regex($regex, $param, $token, $prefix) {
if ($regex) {
$this->_subPatterns[$param] = $regex;
} elseif ($param == 'args') {
$regex = '.*';
} else {
$regex = '[^\/]+';
}
$req = $param === 'args' || array_key_exists($param, $this->_params) ? '?' : '';
if ($prefix === '/') {
$pattern = "(?:/(?P<{$param}>{$regex}){$req}){$req}";
} elseif ($prefix === '.') {
$pattern = "\\.(?P<{$param}>{$regex}){$req}";
} else {
$pattern = "(?P<{$param}>{$regex}){$req}";
}
return str_replace($token, $pattern, $this->_pattern);
} | php | protected function _regex($regex, $param, $token, $prefix) {
if ($regex) {
$this->_subPatterns[$param] = $regex;
} elseif ($param == 'args') {
$regex = '.*';
} else {
$regex = '[^\/]+';
}
$req = $param === 'args' || array_key_exists($param, $this->_params) ? '?' : '';
if ($prefix === '/') {
$pattern = "(?:/(?P<{$param}>{$regex}){$req}){$req}";
} elseif ($prefix === '.') {
$pattern = "\\.(?P<{$param}>{$regex}){$req}";
} else {
$pattern = "(?P<{$param}>{$regex}){$req}";
}
return str_replace($token, $pattern, $this->_pattern);
} | [
"protected",
"function",
"_regex",
"(",
"$",
"regex",
",",
"$",
"param",
",",
"$",
"token",
",",
"$",
"prefix",
")",
"{",
"if",
"(",
"$",
"regex",
")",
"{",
"$",
"this",
"->",
"_subPatterns",
"[",
"$",
"param",
"]",
"=",
"$",
"regex",
";",
"}",
... | Generates a sub-expression capture group for a route regex, using an optional user-supplied
matching pattern.
@param string $regex An optional user-supplied match pattern. If a route is defined like
`"/{:id:\d+}"`, then the value will be `"\d+"`.
@param string $param The parameter name which the capture group is assigned to, i.e.
`'controller'`, `'id'` or `'args'`.
@param string $token The full token representing a matched element in a route template, i.e.
`'/{:action}'`, `'/{:path:js|css}'`, or `'.{:type}'`.
@param string $prefix The prefix character that separates the parameter from the other
elements of the route. Usually `'.'` or `'/'`.
@return string Returns the full route template, with the value of `$token` replaced with a
generated regex capture group. | [
"Generates",
"a",
"sub",
"-",
"expression",
"capture",
"group",
"for",
"a",
"route",
"regex",
"using",
"an",
"optional",
"user",
"-",
"supplied",
"matching",
"pattern",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/net/http/Route.php#L535-L554 |
UnionOfRAD/lithium | console/Router.php | Router.parse | public static function parse($request = null) {
$defaults = ['command' => null, 'action' => 'run', 'args' => []];
$params = $request ? (array) $request->params + $defaults : $defaults;
if (!empty($request->argv)) {
$args = $request->argv;
while ($args) {
$arg = array_shift($args);
if (preg_match('/^-(?P<key>[a-zA-Z0-9])$/i', $arg, $match)) {
$key = Inflector::camelize($match['key'], false);
$params[$key] = $params[$match['key']] = true;
continue;
}
if (preg_match('/^--(?P<key>[a-z0-9-]+)(?:=(?P<val>.+))?$/i', $arg, $match)) {
$key = Inflector::camelize($match['key'], false);
$params[$key] = $params[$match['key']] = !isset($match['val']) ? true : $match['val'];
continue;
}
$params['args'][] = $arg;
}
}
foreach (['command', 'action'] as $param) {
if (!empty($params['args'])) {
$params[$param] = array_shift($params['args']);
}
}
return $params;
} | php | public static function parse($request = null) {
$defaults = ['command' => null, 'action' => 'run', 'args' => []];
$params = $request ? (array) $request->params + $defaults : $defaults;
if (!empty($request->argv)) {
$args = $request->argv;
while ($args) {
$arg = array_shift($args);
if (preg_match('/^-(?P<key>[a-zA-Z0-9])$/i', $arg, $match)) {
$key = Inflector::camelize($match['key'], false);
$params[$key] = $params[$match['key']] = true;
continue;
}
if (preg_match('/^--(?P<key>[a-z0-9-]+)(?:=(?P<val>.+))?$/i', $arg, $match)) {
$key = Inflector::camelize($match['key'], false);
$params[$key] = $params[$match['key']] = !isset($match['val']) ? true : $match['val'];
continue;
}
$params['args'][] = $arg;
}
}
foreach (['command', 'action'] as $param) {
if (!empty($params['args'])) {
$params[$param] = array_shift($params['args']);
}
}
return $params;
} | [
"public",
"static",
"function",
"parse",
"(",
"$",
"request",
"=",
"null",
")",
"{",
"$",
"defaults",
"=",
"[",
"'command'",
"=>",
"null",
",",
"'action'",
"=>",
"'run'",
",",
"'args'",
"=>",
"[",
"]",
"]",
";",
"$",
"params",
"=",
"$",
"request",
... | Parse incoming request from console. Short and long (GNU-style) options
in the form of `-f`, `--foo`, `--foo-bar` and `--foo=bar` are parsed.
XF68-style long options (i.e. `-foo`) are not supported but support
can be added by extending this class.
If passing through `--foo-bar` this previously (pre 1.1) resulted in
the option `foo-bar` being available. This has been deprecated in favor
of `fooBar` being created.
@param \lithium\console\Request $request
@return array $params | [
"Parse",
"incoming",
"request",
"from",
"console",
".",
"Short",
"and",
"long",
"(",
"GNU",
"-",
"style",
")",
"options",
"in",
"the",
"form",
"of",
"-",
"f",
"--",
"foo",
"--",
"foo",
"-",
"bar",
"and",
"--",
"foo",
"=",
"bar",
"are",
"parsed",
".... | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/console/Router.php#L34-L62 |
UnionOfRAD/lithium | security/auth/adapter/Http.php | Http._basic | protected function _basic($request) {
$users = $this->_config['users'];
$username = $request->env('PHP_AUTH_USER');
$auth = $this->_classes['auth'];
$basic = $auth::encode($username, $request->env('PHP_AUTH_PW'));
$encoded = ['response' => null];
if (isset($users[$username])) {
$encoded = $auth::encode($username, $users[$username]);
}
if ($basic['response'] !== $encoded['response']) {
$this->_writeHeader("WWW-Authenticate: Basic realm=\"{$this->_config['realm']}\"");
return;
}
return compact('username', 'password');
} | php | protected function _basic($request) {
$users = $this->_config['users'];
$username = $request->env('PHP_AUTH_USER');
$auth = $this->_classes['auth'];
$basic = $auth::encode($username, $request->env('PHP_AUTH_PW'));
$encoded = ['response' => null];
if (isset($users[$username])) {
$encoded = $auth::encode($username, $users[$username]);
}
if ($basic['response'] !== $encoded['response']) {
$this->_writeHeader("WWW-Authenticate: Basic realm=\"{$this->_config['realm']}\"");
return;
}
return compact('username', 'password');
} | [
"protected",
"function",
"_basic",
"(",
"$",
"request",
")",
"{",
"$",
"users",
"=",
"$",
"this",
"->",
"_config",
"[",
"'users'",
"]",
";",
"$",
"username",
"=",
"$",
"request",
"->",
"env",
"(",
"'PHP_AUTH_USER'",
")",
";",
"$",
"auth",
"=",
"$",
... | Handler for HTTP Basic Authentication
@param \lithium\action\Request $request
@return void|array | [
"Handler",
"for",
"HTTP",
"Basic",
"Authentication"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/security/auth/adapter/Http.php#L114-L129 |
UnionOfRAD/lithium | security/auth/adapter/Http.php | Http._digest | protected function _digest($request) {
$username = $password = null;
$auth = $this->_classes['auth'];
$data = $auth::decode($request->env('PHP_AUTH_DIGEST'));
$data['realm'] = $this->_config['realm'];
$data['method'] = $request->method;
$users = $this->_config['users'];
if (!empty($data['username']) && !empty($users[$data['username']])) {
$username = $data['username'];
$password = $users[$data['username']];
}
$encoded = $auth::encode($username, $password, $data);
if ($encoded['response'] !== $data['response']) {
$nonce = uniqid();
$opaque = md5($data['realm']);
$message = "WWW-Authenticate: Digest realm=\"{$data['realm']}\",qop=\"auth\",";
$message .= "nonce=\"{$nonce}\",opaque=\"{$opaque}\"";
$this->_writeHeader($message);
return false;
}
return compact('username', 'password');
} | php | protected function _digest($request) {
$username = $password = null;
$auth = $this->_classes['auth'];
$data = $auth::decode($request->env('PHP_AUTH_DIGEST'));
$data['realm'] = $this->_config['realm'];
$data['method'] = $request->method;
$users = $this->_config['users'];
if (!empty($data['username']) && !empty($users[$data['username']])) {
$username = $data['username'];
$password = $users[$data['username']];
}
$encoded = $auth::encode($username, $password, $data);
if ($encoded['response'] !== $data['response']) {
$nonce = uniqid();
$opaque = md5($data['realm']);
$message = "WWW-Authenticate: Digest realm=\"{$data['realm']}\",qop=\"auth\",";
$message .= "nonce=\"{$nonce}\",opaque=\"{$opaque}\"";
$this->_writeHeader($message);
return false;
}
return compact('username', 'password');
} | [
"protected",
"function",
"_digest",
"(",
"$",
"request",
")",
"{",
"$",
"username",
"=",
"$",
"password",
"=",
"null",
";",
"$",
"auth",
"=",
"$",
"this",
"->",
"_classes",
"[",
"'auth'",
"]",
";",
"$",
"data",
"=",
"$",
"auth",
"::",
"decode",
"("... | Handler for HTTP Digest Authentication
@param \lithium\action\Request $request
@return boolean|array | [
"Handler",
"for",
"HTTP",
"Digest",
"Authentication"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/security/auth/adapter/Http.php#L137-L160 |
UnionOfRAD/lithium | util/Collection.php | Collection.invoke | public function invoke($method, array $params = [], array $options = []) {
$class = get_class($this);
$defaults = ['merge' => false, 'collect' => false];
$options += $defaults;
$data = [];
foreach ($this as $object) {
$value = call_user_func_array([&$object, $method], $params);
($options['merge']) ? $data = array_merge($data, $value) : $data[$this->key()] = $value;
}
return ($options['collect']) ? new $class(compact('data')) : $data;
} | php | public function invoke($method, array $params = [], array $options = []) {
$class = get_class($this);
$defaults = ['merge' => false, 'collect' => false];
$options += $defaults;
$data = [];
foreach ($this as $object) {
$value = call_user_func_array([&$object, $method], $params);
($options['merge']) ? $data = array_merge($data, $value) : $data[$this->key()] = $value;
}
return ($options['collect']) ? new $class(compact('data')) : $data;
} | [
"public",
"function",
"invoke",
"(",
"$",
"method",
",",
"array",
"$",
"params",
"=",
"[",
"]",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"this",
")",
";",
"$",
"defaults",
"=",
"[",
"'merge'... | Handles dispatching of methods against all items in the collection.
@param string $method The name of the method to call on each instance in the collection.
@param array $params The parameters to pass on each method call.
@param array $options Specifies options for how to run the given method against the object
collection. The available options are:
- `'collect'`: If `true`, the results of this method call will be returned
wrapped in a new `Collection` object or subclass.
- `'merge'`: Used primarily if the method being invoked returns an array. If
set to `true`, merges all results arrays into one.
@todo Implement filtering.
@return mixed Returns either an array of the return values of the methods, or the return
values wrapped in a `Collection` instance. | [
"Handles",
"dispatching",
"of",
"methods",
"against",
"all",
"items",
"in",
"the",
"collection",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Collection.php#L187-L198 |
UnionOfRAD/lithium | util/Collection.php | Collection.respondsTo | public function respondsTo($method, $internal = false) {
$magicMethod = count($this->_data) > 0 && $this->_data[0]->respondsTo($method, $internal);
return $magicMethod || parent::respondsTo($method, $internal);
} | php | public function respondsTo($method, $internal = false) {
$magicMethod = count($this->_data) > 0 && $this->_data[0]->respondsTo($method, $internal);
return $magicMethod || parent::respondsTo($method, $internal);
} | [
"public",
"function",
"respondsTo",
"(",
"$",
"method",
",",
"$",
"internal",
"=",
"false",
")",
"{",
"$",
"magicMethod",
"=",
"count",
"(",
"$",
"this",
"->",
"_data",
")",
">",
"0",
"&&",
"$",
"this",
"->",
"_data",
"[",
"0",
"]",
"->",
"responds... | 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/util/Collection.php#L220-L223 |
UnionOfRAD/lithium | util/Collection.php | Collection.to | public function to($format, array $options = []) {
$defaults = ['internal' => false];
$options += $defaults;
$data = $options['internal'] ? $this->_data : $this;
return $this->_to($format, $data, $options);
} | php | public function to($format, array $options = []) {
$defaults = ['internal' => false];
$options += $defaults;
$data = $options['internal'] ? $this->_data : $this;
return $this->_to($format, $data, $options);
} | [
"public",
"function",
"to",
"(",
"$",
"format",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'internal'",
"=>",
"false",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"$",
"data",
"=",
"$",
"options",
... | 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::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.
@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/util/Collection.php#L253-L258 |
UnionOfRAD/lithium | util/Collection.php | Collection.find | public function find($filter, array $options = []) {
$defaults = ['collect' => true];
$options += $defaults;
$data = array_filter($this->_data, $filter);
if ($options['collect']) {
$class = get_class($this);
$data = new $class(compact('data'));
}
return $data;
} | php | public function find($filter, array $options = []) {
$defaults = ['collect' => true];
$options += $defaults;
$data = array_filter($this->_data, $filter);
if ($options['collect']) {
$class = get_class($this);
$data = new $class(compact('data'));
}
return $data;
} | [
"public",
"function",
"find",
"(",
"$",
"filter",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'collect'",
"=>",
"true",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"$",
"data",
"=",
"array_filter",
"... | Filters a copy of the items in the collection.
@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. Defaults to `true`.
@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/util/Collection.php#L296-L306 |
UnionOfRAD/lithium | util/Collection.php | Collection.first | public function first($filter = null) {
if (!$filter) {
return $this->rewind();
}
foreach ($this as $item) {
if ($filter($item)) {
return $item;
}
}
} | php | public function first($filter = null) {
if (!$filter) {
return $this->rewind();
}
foreach ($this as $item) {
if ($filter($item)) {
return $item;
}
}
} | [
"public",
"function",
"first",
"(",
"$",
"filter",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"filter",
")",
"{",
"return",
"$",
"this",
"->",
"rewind",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"as",
"$",
"item",
")",
"{",
"if",
"(",
... | Rewinds the collection and returns the first item or when a filter is used,
returns the first non-empty item after the filter is applied.
@see lithium\util\Collection::rewind()
@param callable $filter An optional callable through which items will be passed.
If the return value of this function is trueish, it will be returned as
the result of the method call. An example filter function may look like:
`function($item) { return $item->year < 2005; }`.
@return mixed Returns the first item in the collection or when `$filter` is used,
the first item where `$filter` returned a trueish result. | [
"Rewinds",
"the",
"collection",
"and",
"returns",
"the",
"first",
"item",
"or",
"when",
"a",
"filter",
"is",
"used",
"returns",
"the",
"first",
"non",
"-",
"empty",
"item",
"after",
"the",
"filter",
"is",
"applied",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Collection.php#L320-L329 |
UnionOfRAD/lithium | util/Collection.php | Collection.map | public function map($filter, array $options = []) {
$defaults = ['collect' => true];
$options += $defaults;
$data = array_map($filter, $this->_data);
if ($options['collect']) {
$class = get_class($this);
return new $class(compact('data'));
}
return $data;
} | php | public function map($filter, array $options = []) {
$defaults = ['collect' => true];
$options += $defaults;
$data = array_map($filter, $this->_data);
if ($options['collect']) {
$class = get_class($this);
return new $class(compact('data'));
}
return $data;
} | [
"public",
"function",
"map",
"(",
"$",
"filter",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'collect'",
"=>",
"true",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"$",
"data",
"=",
"array_map",
"(",
... | Applies a callback to a copy of all data in the collection
and returns the result.
@link http://php.net/array_map
@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 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. | [
"Applies",
"a",
"callback",
"to",
"a",
"copy",
"of",
"all",
"data",
"in",
"the",
"collection",
"and",
"returns",
"the",
"result",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Collection.php#L355-L365 |
UnionOfRAD/lithium | util/Collection.php | Collection.sort | public function sort($sorter = 'sort', array $options = []) {
if (is_string($sorter) && strpos($sorter, 'sort') !== false && is_callable($sorter)) {
call_user_func_array($sorter, [&$this->_data]);
} elseif (is_callable($sorter)) {
usort($this->_data, $sorter);
}
return $this;
} | php | public function sort($sorter = 'sort', array $options = []) {
if (is_string($sorter) && strpos($sorter, 'sort') !== false && is_callable($sorter)) {
call_user_func_array($sorter, [&$this->_data]);
} elseif (is_callable($sorter)) {
usort($this->_data, $sorter);
}
return $this;
} | [
"public",
"function",
"sort",
"(",
"$",
"sorter",
"=",
"'sort'",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"sorter",
")",
"&&",
"strpos",
"(",
"$",
"sorter",
",",
"'sort'",
")",
"!==",
"false",
"&&",
... | Sorts the objects in the collection.
@link http://php.net/sort
@link http://php.net/usort
@link http://php.net/strcmp
@param string|callable $sorter The sorter for the data. Either a callable to use
as the sort function or a string with the name of a well-known sort function like
`'natsort'` or a compare function like `'strcmp'`. Defaults to `'sort'`.
@param array $options Reserved for future use.
@return Collection Returns itself. | [
"Sorts",
"the",
"objects",
"in",
"the",
"collection",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Collection.php#L392-L399 |
UnionOfRAD/lithium | util/Collection.php | Collection.offsetUnset | public function offsetUnset($offset) {
prev($this->_data);
if (key($this->_data) === null) {
$this->rewind();
}
unset($this->_data[$offset]);
} | php | public function offsetUnset($offset) {
prev($this->_data);
if (key($this->_data) === null) {
$this->rewind();
}
unset($this->_data[$offset]);
} | [
"public",
"function",
"offsetUnset",
"(",
"$",
"offset",
")",
"{",
"prev",
"(",
"$",
"this",
"->",
"_data",
")",
";",
"if",
"(",
"key",
"(",
"$",
"this",
"->",
"_data",
")",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"rewind",
"(",
")",
";",
"... | Unsets an offset.
@param string $offset The offset to unset. | [
"Unsets",
"an",
"offset",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Collection.php#L440-L446 |
UnionOfRAD/lithium | util/Collection.php | Collection.next | public function next() {
$value = next($this->_data);
return key($this->_data) !== null ? $value : false;
} | php | public function next() {
$value = next($this->_data);
return key($this->_data) !== null ? $value : false;
} | [
"public",
"function",
"next",
"(",
")",
"{",
"$",
"value",
"=",
"next",
"(",
"$",
"this",
"->",
"_data",
")",
";",
"return",
"key",
"(",
"$",
"this",
"->",
"_data",
")",
"!==",
"null",
"?",
"$",
"value",
":",
"false",
";",
"}"
] | Moves forward to the next item.
@return mixed The next item or `false`, in case there's no next item or the collection
is empty. | [
"Moves",
"forward",
"to",
"the",
"next",
"item",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Collection.php#L512-L515 |
UnionOfRAD/lithium | util/Collection.php | Collection.append | public function append($value) {
is_object($value) ? $this->_data[] =& $value : $this->_data[] = $value;
} | php | public function append($value) {
is_object($value) ? $this->_data[] =& $value : $this->_data[] = $value;
} | [
"public",
"function",
"append",
"(",
"$",
"value",
")",
"{",
"is_object",
"(",
"$",
"value",
")",
"?",
"$",
"this",
"->",
"_data",
"[",
"]",
"=",
"&",
"$",
"value",
":",
"$",
"this",
"->",
"_data",
"[",
"]",
"=",
"$",
"value",
";",
"}"
] | Appends an item.
@param mixed $value The item to append. | [
"Appends",
"an",
"item",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Collection.php#L522-L524 |
UnionOfRAD/lithium | util/Collection.php | Collection.toArray | public static function toArray($data, array $options = []) {
$defaults = ['handlers' => []];
$options += $defaults;
$result = [];
foreach ($data as $key => $item) {
switch (true) {
case is_array($item):
$result[$key] = static::toArray($item, $options);
break;
case (!is_object($item)):
$result[$key] = $item;
break;
case (isset($options['handlers'][$class = get_class($item)])):
$result[$key] = $options['handlers'][$class]($item);
break;
case (method_exists($item, 'to')):
$result[$key] = $item->to('array', $options);
break;
case ($vars = get_object_vars($item)):
$result[$key] = static::toArray($vars, $options);
break;
case (method_exists($item, '__toString')):
$result[$key] = (string) $item;
break;
default:
$result[$key] = $item;
break;
}
}
return $result;
} | php | public static function toArray($data, array $options = []) {
$defaults = ['handlers' => []];
$options += $defaults;
$result = [];
foreach ($data as $key => $item) {
switch (true) {
case is_array($item):
$result[$key] = static::toArray($item, $options);
break;
case (!is_object($item)):
$result[$key] = $item;
break;
case (isset($options['handlers'][$class = get_class($item)])):
$result[$key] = $options['handlers'][$class]($item);
break;
case (method_exists($item, 'to')):
$result[$key] = $item->to('array', $options);
break;
case ($vars = get_object_vars($item)):
$result[$key] = static::toArray($vars, $options);
break;
case (method_exists($item, '__toString')):
$result[$key] = (string) $item;
break;
default:
$result[$key] = $item;
break;
}
}
return $result;
} | [
"public",
"static",
"function",
"toArray",
"(",
"$",
"data",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'handlers'",
"=>",
"[",
"]",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"$",
"result",
"=",
... | Exports a `Collection` instance to an array. Used by `Collection::to()`.
@param mixed $data Either a `Collection` instance, or an array representing a `Collection`'s
internal state.
@param array $options Options used when converting `$data` to an array:
- `'handlers'` _array_: An array where the keys are fully-namespaced class
names, and the values are closures that take an instance of the class as a
parameter, and return an array or scalar value that the instance represents.
@return array Returns the value of `$data` as a pure PHP array, recursively converting all
sub-objects and other values to their closest array or scalar equivalents. | [
"Exports",
"a",
"Collection",
"instance",
"to",
"an",
"array",
".",
"Used",
"by",
"Collection",
"::",
"to",
"()",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Collection.php#L558-L589 |
UnionOfRAD/lithium | analysis/logger/adapter/FirePhp.php | FirePhp.bind | public function bind($response) {
$this->_response = $response;
$this->_response->headers += $this->_headers;
foreach ($this->_queue as $message) {
$this->_write($message);
}
} | php | public function bind($response) {
$this->_response = $response;
$this->_response->headers += $this->_headers;
foreach ($this->_queue as $message) {
$this->_write($message);
}
} | [
"public",
"function",
"bind",
"(",
"$",
"response",
")",
"{",
"$",
"this",
"->",
"_response",
"=",
"$",
"response",
";",
"$",
"this",
"->",
"_response",
"->",
"headers",
"+=",
"$",
"this",
"->",
"_headers",
";",
"foreach",
"(",
"$",
"this",
"->",
"_q... | Binds the response object to the logger and sets the required Wildfire
protocol headers.
@param object $response An instance of a response object (usually `lithium\action\Response`)
with HTTP request information.
@return void | [
"Binds",
"the",
"response",
"object",
"to",
"the",
"logger",
"and",
"sets",
"the",
"required",
"Wildfire",
"protocol",
"headers",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/logger/adapter/FirePhp.php#L136-L143 |
UnionOfRAD/lithium | analysis/logger/adapter/FirePhp.php | FirePhp.write | public function write($priority, $message) {
return function($params) {
$priority = $params['priority'];
$message = $params['message'];
$message = $this->_format($priority, $message);
$this->_write($message);
return true;
};
} | php | public function write($priority, $message) {
return function($params) {
$priority = $params['priority'];
$message = $params['message'];
$message = $this->_format($priority, $message);
$this->_write($message);
return true;
};
} | [
"public",
"function",
"write",
"(",
"$",
"priority",
",",
"$",
"message",
")",
"{",
"return",
"function",
"(",
"$",
"params",
")",
"{",
"$",
"priority",
"=",
"$",
"params",
"[",
"'priority'",
"]",
";",
"$",
"message",
"=",
"$",
"params",
"[",
"'messa... | Appends a log message to the response header for FirePHP.
@param string $priority Represents the message priority.
@param string $message Contains the actual message to store.
@return boolean Always returns `true`. Note that in order for message-writing to take effect,
the adapter must be bound to the `Response` object instance associated with
the current request. See the `bind()` method. | [
"Appends",
"a",
"log",
"message",
"to",
"the",
"response",
"header",
"for",
"FirePHP",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/logger/adapter/FirePhp.php#L154-L162 |
UnionOfRAD/lithium | analysis/logger/adapter/FirePhp.php | FirePhp._write | protected function _write($message) {
if (!$this->_response) {
return $this->_queue[] = $message;
}
$this->_response->headers[$message['key']] = $message['content'];
} | php | protected function _write($message) {
if (!$this->_response) {
return $this->_queue[] = $message;
}
$this->_response->headers[$message['key']] = $message['content'];
} | [
"protected",
"function",
"_write",
"(",
"$",
"message",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_response",
")",
"{",
"return",
"$",
"this",
"->",
"_queue",
"[",
"]",
"=",
"$",
"message",
";",
"}",
"$",
"this",
"->",
"_response",
"->",
"heade... | Helper method that writes the message to the header of a bound `Response` object. If no
`Response` object is bound when this method is called, it is stored in a message queue.
@see lithium\analysis\logger\adapter\FirePhp::_format()
@param array $message A message containing the key and the content to store.
@return array|void The queued message when no `Response` object was bound. | [
"Helper",
"method",
"that",
"writes",
"the",
"message",
"to",
"the",
"header",
"of",
"a",
"bound",
"Response",
"object",
".",
"If",
"no",
"Response",
"object",
"is",
"bound",
"when",
"this",
"method",
"is",
"called",
"it",
"is",
"stored",
"in",
"a",
"mes... | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/logger/adapter/FirePhp.php#L172-L177 |
UnionOfRAD/lithium | analysis/logger/adapter/FirePhp.php | FirePhp._format | protected function _format($type, $message) {
$key = 'X-Wf-1-1-1-' . $this->_counter++;
$content = [['Type' => $this->_levels[$type]], $message];
$content = json_encode($content);
$content = strlen($content) . '|' . $content . '|';
return compact('key', 'content');
} | php | protected function _format($type, $message) {
$key = 'X-Wf-1-1-1-' . $this->_counter++;
$content = [['Type' => $this->_levels[$type]], $message];
$content = json_encode($content);
$content = strlen($content) . '|' . $content . '|';
return compact('key', 'content');
} | [
"protected",
"function",
"_format",
"(",
"$",
"type",
",",
"$",
"message",
")",
"{",
"$",
"key",
"=",
"'X-Wf-1-1-1-'",
".",
"$",
"this",
"->",
"_counter",
"++",
";",
"$",
"content",
"=",
"[",
"[",
"'Type'",
"=>",
"$",
"this",
"->",
"_levels",
"[",
... | Generates a string representation of the type and message, suitable for FirePHP.
@param string $type Represents the message priority.
@param string $message Contains the actual message to store.
@return array Returns the encoded string representations of the priority and message, in the
`'key'` and `'content'` keys, respectively. | [
"Generates",
"a",
"string",
"representation",
"of",
"the",
"type",
"and",
"message",
"suitable",
"for",
"FirePHP",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/analysis/logger/adapter/FirePhp.php#L187-L195 |
UnionOfRAD/lithium | util/Set.php | Set.append | public static function append(array $array, array $array2) {
$arrays = func_get_args();
$array = array_shift($arrays);
foreach ($arrays as $array2) {
if (!$array && $array2) {
$array = $array2;
continue;
}
foreach ($array2 as $key => $value) {
if (!array_key_exists($key, $array)) {
$array[$key] = $value;
} elseif (is_array($value)) {
$array[$key] = static::append($array[$key], $array2[$key]);
}
}
}
return $array;
} | php | public static function append(array $array, array $array2) {
$arrays = func_get_args();
$array = array_shift($arrays);
foreach ($arrays as $array2) {
if (!$array && $array2) {
$array = $array2;
continue;
}
foreach ($array2 as $key => $value) {
if (!array_key_exists($key, $array)) {
$array[$key] = $value;
} elseif (is_array($value)) {
$array[$key] = static::append($array[$key], $array2[$key]);
}
}
}
return $array;
} | [
"public",
"static",
"function",
"append",
"(",
"array",
"$",
"array",
",",
"array",
"$",
"array2",
")",
"{",
"$",
"arrays",
"=",
"func_get_args",
"(",
")",
";",
"$",
"array",
"=",
"array_shift",
"(",
"$",
"arrays",
")",
";",
"foreach",
"(",
"$",
"arr... | Add the keys/values in `$array2` that are not found in `$array` onto the end of `$array`.
@param mixed $array Original array.
@param mixed $array2 Second array to add onto the original.
@return array An array containing all the keys of the second array not already present in the
first. | [
"Add",
"the",
"keys",
"/",
"values",
"in",
"$array2",
"that",
"are",
"not",
"found",
"in",
"$array",
"onto",
"the",
"end",
"of",
"$array",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Set.php#L40-L57 |
UnionOfRAD/lithium | util/Set.php | Set.check | public static function check($data, $path = null) {
if (!$path) {
return $data;
}
$path = is_array($path) ? $path : explode('.', $path);
foreach ($path as $i => $key) {
if (is_numeric($key) && (integer) $key > 0 || $key === '0') {
$key = (integer) $key;
}
if ($i === count($path) - 1) {
return (is_array($data) && isset($data[$key]));
} else {
if (!is_array($data) || !isset($data[$key])) {
return false;
}
$data =& $data[$key];
}
}
} | php | public static function check($data, $path = null) {
if (!$path) {
return $data;
}
$path = is_array($path) ? $path : explode('.', $path);
foreach ($path as $i => $key) {
if (is_numeric($key) && (integer) $key > 0 || $key === '0') {
$key = (integer) $key;
}
if ($i === count($path) - 1) {
return (is_array($data) && isset($data[$key]));
} else {
if (!is_array($data) || !isset($data[$key])) {
return false;
}
$data =& $data[$key];
}
}
} | [
"public",
"static",
"function",
"check",
"(",
"$",
"data",
",",
"$",
"path",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"path",
")",
"{",
"return",
"$",
"data",
";",
"}",
"$",
"path",
"=",
"is_array",
"(",
"$",
"path",
")",
"?",
"$",
"path",
... | Checks if a particular path is set in an array. Tests by key name, or dot-delimited key
name, i.e.:
``` embed:lithium\tests\cases\util\SetTest::testCheck(1-4) ```
@param mixed $data Data to check on.
@param mixed $path A dot-delimited string.
@return boolean `true` if path is found, `false` otherwise. | [
"Checks",
"if",
"a",
"particular",
"path",
"is",
"set",
"in",
"an",
"array",
".",
"Tests",
"by",
"key",
"name",
"or",
"dot",
"-",
"delimited",
"key",
"name",
"i",
".",
"e",
".",
":"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Set.php#L69-L88 |
UnionOfRAD/lithium | util/Set.php | Set.combine | public static function combine($data, $path1 = null, $path2 = null, $groupPath = null) {
if (!$data) {
return [];
}
if (is_object($data)) {
$data = get_object_vars($data);
}
if (is_array($path1)) {
$format = array_shift($path1);
$keys = static::format($data, $format, $path1);
} else {
$keys = static::extract($data, $path1);
}
$vals = [];
if (!empty($path2) && is_array($path2)) {
$format = array_shift($path2);
$vals = static::format($data, $format, $path2);
} elseif (!empty($path2)) {
$vals = static::extract($data, $path2);
}
$valCount = count($vals);
$count = count($keys);
for ($i = $valCount; $i < $count; $i++) {
$vals[$i] = null;
}
if ($groupPath) {
$group = static::extract($data, $groupPath);
if (!empty($group)) {
$c = count($keys);
for ($i = 0; $i < $c; $i++) {
if (!isset($group[$i])) {
$group[$i] = 0;
}
if (!isset($out[$group[$i]])) {
$out[$group[$i]] = [];
}
$out[$group[$i]][$keys[$i]] = $vals[$i];
}
return $out;
}
}
return array_combine($keys, $vals);
} | php | public static function combine($data, $path1 = null, $path2 = null, $groupPath = null) {
if (!$data) {
return [];
}
if (is_object($data)) {
$data = get_object_vars($data);
}
if (is_array($path1)) {
$format = array_shift($path1);
$keys = static::format($data, $format, $path1);
} else {
$keys = static::extract($data, $path1);
}
$vals = [];
if (!empty($path2) && is_array($path2)) {
$format = array_shift($path2);
$vals = static::format($data, $format, $path2);
} elseif (!empty($path2)) {
$vals = static::extract($data, $path2);
}
$valCount = count($vals);
$count = count($keys);
for ($i = $valCount; $i < $count; $i++) {
$vals[$i] = null;
}
if ($groupPath) {
$group = static::extract($data, $groupPath);
if (!empty($group)) {
$c = count($keys);
for ($i = 0; $i < $c; $i++) {
if (!isset($group[$i])) {
$group[$i] = 0;
}
if (!isset($out[$group[$i]])) {
$out[$group[$i]] = [];
}
$out[$group[$i]][$keys[$i]] = $vals[$i];
}
return $out;
}
}
return array_combine($keys, $vals);
} | [
"public",
"static",
"function",
"combine",
"(",
"$",
"data",
",",
"$",
"path1",
"=",
"null",
",",
"$",
"path2",
"=",
"null",
",",
"$",
"groupPath",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"data",
")",
"{",
"return",
"[",
"]",
";",
"}",
"if"... | Creates an associative array using a `$path1` as the path to build its keys, and optionally
`$path2` as path to get the values. If `$path2` is not specified, all values will be
initialized to `null` (useful for `Set::merge()`). You can optionally group the values by
what is obtained when following the path specified in `$groupPath`.
@param array $data Array from where to extract keys and values.
@param mixed $path1 As an array, or as a dot-delimited string.
@param mixed $path2 As an array, or as a dot-delimited string.
@param string $groupPath As an array, or as a dot-delimited string.
@return array Combined array. | [
"Creates",
"an",
"associative",
"array",
"using",
"a",
"$path1",
"as",
"the",
"path",
"to",
"build",
"its",
"keys",
"and",
"optionally",
"$path2",
"as",
"path",
"to",
"get",
"the",
"values",
".",
"If",
"$path2",
"is",
"not",
"specified",
"all",
"values",
... | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Set.php#L102-L145 |
UnionOfRAD/lithium | util/Set.php | Set.contains | public static function contains(array $array1, array $array2) {
if (!$array1 || !$array2) {
return false;
}
foreach ($array2 as $key => $val) {
if (!isset($array1[$key]) || $array1[$key] !== $val) {
return false;
}
if (is_array($val) && !static::contains($array1[$key], $val)) {
return false;
}
}
return true;
} | php | public static function contains(array $array1, array $array2) {
if (!$array1 || !$array2) {
return false;
}
foreach ($array2 as $key => $val) {
if (!isset($array1[$key]) || $array1[$key] !== $val) {
return false;
}
if (is_array($val) && !static::contains($array1[$key], $val)) {
return false;
}
}
return true;
} | [
"public",
"static",
"function",
"contains",
"(",
"array",
"$",
"array1",
",",
"array",
"$",
"array2",
")",
"{",
"if",
"(",
"!",
"$",
"array1",
"||",
"!",
"$",
"array2",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"array2",
"as",
"$"... | Determines if the array elements in `$array2` are wholly contained within `$array1`. Works
recursively.
@param array $array1 First value.
@param array $array2 Second value.
@return boolean Returns `true` if `$array1` wholly contains the keys and values of `$array2`,
otherwise, returns `false`. Returns `false` if either array is empty. | [
"Determines",
"if",
"the",
"array",
"elements",
"in",
"$array2",
"are",
"wholly",
"contained",
"within",
"$array1",
".",
"Works",
"recursively",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Set.php#L156-L169 |
UnionOfRAD/lithium | util/Set.php | Set.depth | public static function depth($data, array $options = []) {
$defaults = ['all' => false, 'count' => 0];
$options += $defaults;
if (!$data) {
return 0;
}
if (!$options['all']) {
return (is_array(reset($data))) ? static::depth(reset($data)) + 1 : 1;
}
$depth = [$options['count']];
if (is_array($data) && reset($data) !== false) {
foreach ($data as $value) {
$depth[] = static::depth($value, [
'all' => $options['all'],
'count' => $options['count'] + 1
]);
}
}
return max($depth);
} | php | public static function depth($data, array $options = []) {
$defaults = ['all' => false, 'count' => 0];
$options += $defaults;
if (!$data) {
return 0;
}
if (!$options['all']) {
return (is_array(reset($data))) ? static::depth(reset($data)) + 1 : 1;
}
$depth = [$options['count']];
if (is_array($data) && reset($data) !== false) {
foreach ($data as $value) {
$depth[] = static::depth($value, [
'all' => $options['all'],
'count' => $options['count'] + 1
]);
}
}
return max($depth);
} | [
"public",
"static",
"function",
"depth",
"(",
"$",
"data",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'all'",
"=>",
"false",
",",
"'count'",
"=>",
"0",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
... | Counts the dimensions of an array. If `$all` is set to `false` (which is the default) it will
only consider the dimension of the first element in the array.
@param array $data Array to count dimensions on.
@param array $options
@return integer The number of dimensions in `$array`. | [
"Counts",
"the",
"dimensions",
"of",
"an",
"array",
".",
"If",
"$all",
"is",
"set",
"to",
"false",
"(",
"which",
"is",
"the",
"default",
")",
"it",
"will",
"only",
"consider",
"the",
"dimension",
"of",
"the",
"first",
"element",
"in",
"the",
"array",
"... | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Set.php#L179-L201 |
UnionOfRAD/lithium | util/Set.php | Set.diff | public static function diff(array $val1, array $val2) {
if (!$val1 || !$val2) {
return $val2 ?: $val1;
}
$out = [];
foreach ($val1 as $key => $val) {
$exists = isset($val2[$key]);
if (($exists && $val2[$key] !== $val) || !$exists) {
$out[$key] = $val;
}
unset($val2[$key]);
}
foreach ($val2 as $key => $val) {
if (!isset($out[$key])) {
$out[$key] = $val;
}
}
return $out;
} | php | public static function diff(array $val1, array $val2) {
if (!$val1 || !$val2) {
return $val2 ?: $val1;
}
$out = [];
foreach ($val1 as $key => $val) {
$exists = isset($val2[$key]);
if (($exists && $val2[$key] !== $val) || !$exists) {
$out[$key] = $val;
}
unset($val2[$key]);
}
foreach ($val2 as $key => $val) {
if (!isset($out[$key])) {
$out[$key] = $val;
}
}
return $out;
} | [
"public",
"static",
"function",
"diff",
"(",
"array",
"$",
"val1",
",",
"array",
"$",
"val2",
")",
"{",
"if",
"(",
"!",
"$",
"val1",
"||",
"!",
"$",
"val2",
")",
"{",
"return",
"$",
"val2",
"?",
":",
"$",
"val1",
";",
"}",
"$",
"out",
"=",
"[... | Computes the difference between two arrays.
@param array $val1 First value.
@param array $val2 Second value.
@return array Computed difference. | [
"Computes",
"the",
"difference",
"between",
"two",
"arrays",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Set.php#L210-L231 |
UnionOfRAD/lithium | util/Set.php | Set.extract | public static function extract(array $data, $path = null, array $options = []) {
$defaults = ['flatten' => true];
$options += $defaults;
if (!$data) {
return [];
}
if ($path === '/') {
return array_filter($data, function($data) {
return ($data === 0 || $data === '0' || !empty($data));
});
}
$contexts = $data;
if (!isset($contexts[0])) {
$contexts = [$data];
}
$tokens = array_slice(preg_split('/(?<!=)\/(?![a-z-]*\])/', $path), 1);
do {
$token = array_shift($tokens);
$conditions = false;
if (preg_match_all('/\[([^=]+=\/[^\/]+\/|[^\]]+)\]/', $token, $m)) {
$conditions = $m[1];
$token = substr($token, 0, strpos($token, '['));
}
$matches = [];
foreach ($contexts as $key => $context) {
if (!isset($context['trace'])) {
$context = ['trace' => [null], 'item' => $context, 'key' => $key];
}
if ($token === '..') {
if (count($context['trace']) === 1) {
$context['trace'][] = $context['key'];
}
array_pop($context['trace']);
$parent = join('/', $context['trace']);
$context['item'] = static::extract($data, $parent);
array_pop($context['trace']);
$context['item'] = array_shift($context['item']);
$matches[] = $context;
continue;
}
$match = false;
if ($token === '@*' && is_array($context['item'])) {
$matches[] = [
'trace' => array_merge($context['trace'], (array) $key),
'key' => $key,
'item' => array_keys($context['item'])
];
} elseif (is_array($context['item']) && isset($context['item'][$token])) {
$items = $context['item'][$token];
if (!is_array($items)) {
$items = [$items];
} elseif (!isset($items[0])) {
$current = current($items);
if ((is_array($current) && count($items) <= 1) || !is_array($current)) {
$items = [$items];
}
}
foreach ($items as $key => $item) {
$ctext = [$context['key']];
if (!is_numeric($key)) {
$ctext[] = $token;
$token = array_shift($tokens);
if (isset($items[$token])) {
$ctext[] = $token;
$item = $items[$token];
$matches[] = [
'trace' => array_merge($context['trace'], $ctext),
'key' => $key,
'item' => $item
];
break;
} else {
array_unshift($tokens, $token);
}
} else {
$ctext[] = $token;
}
$matches[] = [
'trace' => array_merge($context['trace'], $ctext),
'key' => $key,
'item' => $item
];
}
} elseif (
$key === $token || (is_numeric($token) && $key == $token) || $token === '.'
) {
$context['trace'][] = $key;
$matches[] = [
'trace' => $context['trace'],
'key' => $key,
'item' => $context['item']
];
}
}
if ($conditions) {
foreach ($conditions as $condition) {
$filtered = [];
$length = count($matches);
foreach ($matches as $i => $match) {
if (static::matches($match['item'], [$condition], $i + 1, $length)) {
$filtered[] = $match;
}
}
$matches = $filtered;
}
}
$contexts = $matches;
if (empty($tokens)) {
break;
}
} while (true);
$r = [];
foreach ($matches as $match) {
$key = array_pop($match['trace']);
$condition = (!is_int($key) && $key !== null);
if ((!$options['flatten'] || is_array($match['item'])) && $condition) {
$r[] = [$key => $match['item']];
} else {
$r[] = $match['item'];
}
}
return $r;
} | php | public static function extract(array $data, $path = null, array $options = []) {
$defaults = ['flatten' => true];
$options += $defaults;
if (!$data) {
return [];
}
if ($path === '/') {
return array_filter($data, function($data) {
return ($data === 0 || $data === '0' || !empty($data));
});
}
$contexts = $data;
if (!isset($contexts[0])) {
$contexts = [$data];
}
$tokens = array_slice(preg_split('/(?<!=)\/(?![a-z-]*\])/', $path), 1);
do {
$token = array_shift($tokens);
$conditions = false;
if (preg_match_all('/\[([^=]+=\/[^\/]+\/|[^\]]+)\]/', $token, $m)) {
$conditions = $m[1];
$token = substr($token, 0, strpos($token, '['));
}
$matches = [];
foreach ($contexts as $key => $context) {
if (!isset($context['trace'])) {
$context = ['trace' => [null], 'item' => $context, 'key' => $key];
}
if ($token === '..') {
if (count($context['trace']) === 1) {
$context['trace'][] = $context['key'];
}
array_pop($context['trace']);
$parent = join('/', $context['trace']);
$context['item'] = static::extract($data, $parent);
array_pop($context['trace']);
$context['item'] = array_shift($context['item']);
$matches[] = $context;
continue;
}
$match = false;
if ($token === '@*' && is_array($context['item'])) {
$matches[] = [
'trace' => array_merge($context['trace'], (array) $key),
'key' => $key,
'item' => array_keys($context['item'])
];
} elseif (is_array($context['item']) && isset($context['item'][$token])) {
$items = $context['item'][$token];
if (!is_array($items)) {
$items = [$items];
} elseif (!isset($items[0])) {
$current = current($items);
if ((is_array($current) && count($items) <= 1) || !is_array($current)) {
$items = [$items];
}
}
foreach ($items as $key => $item) {
$ctext = [$context['key']];
if (!is_numeric($key)) {
$ctext[] = $token;
$token = array_shift($tokens);
if (isset($items[$token])) {
$ctext[] = $token;
$item = $items[$token];
$matches[] = [
'trace' => array_merge($context['trace'], $ctext),
'key' => $key,
'item' => $item
];
break;
} else {
array_unshift($tokens, $token);
}
} else {
$ctext[] = $token;
}
$matches[] = [
'trace' => array_merge($context['trace'], $ctext),
'key' => $key,
'item' => $item
];
}
} elseif (
$key === $token || (is_numeric($token) && $key == $token) || $token === '.'
) {
$context['trace'][] = $key;
$matches[] = [
'trace' => $context['trace'],
'key' => $key,
'item' => $context['item']
];
}
}
if ($conditions) {
foreach ($conditions as $condition) {
$filtered = [];
$length = count($matches);
foreach ($matches as $i => $match) {
if (static::matches($match['item'], [$condition], $i + 1, $length)) {
$filtered[] = $match;
}
}
$matches = $filtered;
}
}
$contexts = $matches;
if (empty($tokens)) {
break;
}
} while (true);
$r = [];
foreach ($matches as $match) {
$key = array_pop($match['trace']);
$condition = (!is_int($key) && $key !== null);
if ((!$options['flatten'] || is_array($match['item'])) && $condition) {
$r[] = [$key => $match['item']];
} else {
$r[] = $match['item'];
}
}
return $r;
} | [
"public",
"static",
"function",
"extract",
"(",
"array",
"$",
"data",
",",
"$",
"path",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'flatten'",
"=>",
"true",
"]",
";",
"$",
"options",
"+=",
"$",
... | Implements partial support for XPath 2.0.
@param array $data An array of data to extract from.
@param string $path An absolute XPath 2.0 path. Only absolute paths starting with a
single slash are supported right now. Implemented selectors:
- `'/User/id'`: Similar to the classic {n}.User.id.
- `'/User[2]/name'`: Selects the name of the second User.
- `'/User[id>2]'`: Selects all Users with an id > 2.
- `'/User[id>2][<5]'`: Selects all Users with an id > 2 but < 5.
- `'/Post/Comment[author_name=John]/../name'`: Selects the name of
all posts that have at least one comment written by John.
- `'/Posts[name]'`: Selects all Posts that have a `'name'` key.
- `'/Comment/.[1]'`: Selects the contents of the first comment.
- `'/Comment/.[:last]'`: Selects the last comment.
- `'/Comment/.[:first]'`: Selects the first comment.
- `'/Comment[text=/lithium/i]`': Selects the all comments that have
a text matching the regex `/lithium/i`.
- `'/Comment/@*'`: Selects all key names of all comments.
@param array $options Currently only supports `'flatten'` which can be
disabled for higher XPath-ness.
@return array An array of matched items. | [
"Implements",
"partial",
"support",
"for",
"XPath",
"2",
".",
"0",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Set.php#L256-L392 |
UnionOfRAD/lithium | util/Set.php | Set.flatten | public static function flatten($data, array $options = []) {
$defaults = ['separator' => '.', 'path' => null];
$options += $defaults;
$result = [];
if ($options['path'] !== null) {
$options['path'] .= $options['separator'];
}
foreach ($data as $key => $val) {
if (!is_array($val)) {
$result[$options['path'] . $key] = $val;
continue;
}
$opts = ['separator' => $options['separator'], 'path' => $options['path'] . $key];
$result += (array) static::flatten($val, $opts);
}
return $result;
} | php | public static function flatten($data, array $options = []) {
$defaults = ['separator' => '.', 'path' => null];
$options += $defaults;
$result = [];
if ($options['path'] !== null) {
$options['path'] .= $options['separator'];
}
foreach ($data as $key => $val) {
if (!is_array($val)) {
$result[$options['path'] . $key] = $val;
continue;
}
$opts = ['separator' => $options['separator'], 'path' => $options['path'] . $key];
$result += (array) static::flatten($val, $opts);
}
return $result;
} | [
"public",
"static",
"function",
"flatten",
"(",
"$",
"data",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'separator'",
"=>",
"'.'",
",",
"'path'",
"=>",
"null",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
... | Collapses a multi-dimensional array into a single dimension, using a delimited array path
for each array element's key, i.e. [array('Foo' => ['Bar' => 'Far'])] becomes
['0.Foo.Bar' => 'Far'].
@param array $data array to flatten
@param array $options Available options are:
- `'separator'`: String to separate array keys in path (defaults to `'.'`).
- `'path'`: Starting point (defaults to null).
@return array | [
"Collapses",
"a",
"multi",
"-",
"dimensional",
"array",
"into",
"a",
"single",
"dimension",
"using",
"a",
"delimited",
"array",
"path",
"for",
"each",
"array",
"element",
"s",
"key",
"i",
".",
"e",
".",
"[",
"array",
"(",
"Foo",
"=",
">",
"[",
"Bar",
... | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Set.php#L405-L422 |
UnionOfRAD/lithium | util/Set.php | Set.expand | public static function expand(array $data, array $options = []) {
$defaults = ['separator' => '.'];
$options += $defaults;
$result = [];
foreach ($data as $key => $val) {
if (strpos($key, $options['separator']) === false) {
if (!isset($result[$key])) {
$result[$key] = $val;
}
continue;
}
list($path, $key) = explode($options['separator'], $key, 2);
$path = is_numeric($path) ? (integer) $path : $path;
$result[$path][$key] = $val;
}
foreach ($result as $key => $value) {
if (is_array($value)) {
$result[$key] = static::expand($value, $options);
}
}
return $result;
} | php | public static function expand(array $data, array $options = []) {
$defaults = ['separator' => '.'];
$options += $defaults;
$result = [];
foreach ($data as $key => $val) {
if (strpos($key, $options['separator']) === false) {
if (!isset($result[$key])) {
$result[$key] = $val;
}
continue;
}
list($path, $key) = explode($options['separator'], $key, 2);
$path = is_numeric($path) ? (integer) $path : $path;
$result[$path][$key] = $val;
}
foreach ($result as $key => $value) {
if (is_array($value)) {
$result[$key] = static::expand($value, $options);
}
}
return $result;
} | [
"public",
"static",
"function",
"expand",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'separator'",
"=>",
"'.'",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"$",
"result",
... | Accepts a one-dimensional array where the keys are separated by a delimiter.
@param array $data The one-dimensional array to expand.
@param array $options The options used when expanding the array:
- `'separator'` _string_: The delimiter to use when separating keys. Defaults
to `'.'`.
@return array Returns a multi-dimensional array expanded from a one dimensional
dot-separated array. | [
"Accepts",
"a",
"one",
"-",
"dimensional",
"array",
"where",
"the",
"keys",
"are",
"separated",
"by",
"a",
"delimiter",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Set.php#L434-L456 |
UnionOfRAD/lithium | util/Set.php | Set.format | public static function format($data, $format, $keys) {
$extracted = [];
$count = count($keys);
if (!$count) {
return;
}
for ($i = 0; $i < $count; $i++) {
$extracted[] = static::extract($data, $keys[$i]);
}
$out = [];
$data = $extracted;
$count = count($data[0]);
if (preg_match_all('/\{([0-9]+)\}/msi', $format, $keys2) && isset($keys2[1])) {
$keys = $keys2[1];
$format = preg_split('/\{([0-9]+)\}/msi', $format);
$count2 = count($format);
for ($j = 0; $j < $count; $j++) {
$formatted = '';
for ($i = 0; $i <= $count2; $i++) {
if (isset($format[$i])) {
$formatted .= $format[$i];
}
if (isset($keys[$i]) && isset($data[$keys[$i]][$j])) {
$formatted .= $data[$keys[$i]][$j];
}
}
$out[] = $formatted;
}
return $out;
}
$count2 = count($data);
for ($j = 0; $j < $count; $j++) {
$args = [];
for ($i = 0; $i < $count2; $i++) {
if (isset($data[$i][$j])) {
$args[] = $data[$i][$j];
}
}
$out[] = vsprintf($format, $args);
}
return $out;
} | php | public static function format($data, $format, $keys) {
$extracted = [];
$count = count($keys);
if (!$count) {
return;
}
for ($i = 0; $i < $count; $i++) {
$extracted[] = static::extract($data, $keys[$i]);
}
$out = [];
$data = $extracted;
$count = count($data[0]);
if (preg_match_all('/\{([0-9]+)\}/msi', $format, $keys2) && isset($keys2[1])) {
$keys = $keys2[1];
$format = preg_split('/\{([0-9]+)\}/msi', $format);
$count2 = count($format);
for ($j = 0; $j < $count; $j++) {
$formatted = '';
for ($i = 0; $i <= $count2; $i++) {
if (isset($format[$i])) {
$formatted .= $format[$i];
}
if (isset($keys[$i]) && isset($data[$keys[$i]][$j])) {
$formatted .= $data[$keys[$i]][$j];
}
}
$out[] = $formatted;
}
return $out;
}
$count2 = count($data);
for ($j = 0; $j < $count; $j++) {
$args = [];
for ($i = 0; $i < $count2; $i++) {
if (isset($data[$i][$j])) {
$args[] = $data[$i][$j];
}
}
$out[] = vsprintf($format, $args);
}
return $out;
} | [
"public",
"static",
"function",
"format",
"(",
"$",
"data",
",",
"$",
"format",
",",
"$",
"keys",
")",
"{",
"$",
"extracted",
"=",
"[",
"]",
";",
"$",
"count",
"=",
"count",
"(",
"$",
"keys",
")",
";",
"if",
"(",
"!",
"$",
"count",
")",
"{",
... | Returns a series of values extracted from an array, formatted in a format string.
@param array $data Source array from which to extract the data.
@param string $format Format string into which values will be inserted using `sprintf()`.
@param array $keys An array containing one or more `Set::extract()`-style key paths.
@return array An array of strings extracted from `$keys` and formatted with `$format`.
@link http://php.net/sprintf | [
"Returns",
"a",
"series",
"of",
"values",
"extracted",
"from",
"an",
"array",
"formatted",
"in",
"a",
"format",
"string",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Set.php#L467-L513 |
UnionOfRAD/lithium | util/Set.php | Set.insert | public static function insert($list, $path, $data = []) {
if (!is_array($path)) {
$path = explode('.', $path);
}
$_list =& $list;
foreach ($path as $i => $key) {
if (is_numeric($key) && (integer) $key > 0 || $key === '0') {
$key = (integer) $key;
}
if ($i === count($path) - 1) {
$_list[$key] = $data;
} else {
if (!isset($_list[$key])) {
$_list[$key] = [];
}
$_list =& $_list[$key];
}
}
return $list;
} | php | public static function insert($list, $path, $data = []) {
if (!is_array($path)) {
$path = explode('.', $path);
}
$_list =& $list;
foreach ($path as $i => $key) {
if (is_numeric($key) && (integer) $key > 0 || $key === '0') {
$key = (integer) $key;
}
if ($i === count($path) - 1) {
$_list[$key] = $data;
} else {
if (!isset($_list[$key])) {
$_list[$key] = [];
}
$_list =& $_list[$key];
}
}
return $list;
} | [
"public",
"static",
"function",
"insert",
"(",
"$",
"list",
",",
"$",
"path",
",",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"path",
")",
")",
"{",
"$",
"path",
"=",
"explode",
"(",
"'.'",
",",
"$",
"path",
"... | Inserts `$data` into an array as defined by `$path`.
@param mixed $list Where to insert into.
@param mixed $path A dot-delimited string.
@param array $data Data to insert.
@return array | [
"Inserts",
"$data",
"into",
"an",
"array",
"as",
"defined",
"by",
"$path",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Set.php#L523-L543 |
UnionOfRAD/lithium | util/Set.php | Set.isNumeric | public static function isNumeric($array = null) {
if (empty($array)) {
return null;
}
if ($array === range(0, count($array) - 1)) {
return true;
}
$numeric = true;
$keys = array_keys($array);
$count = count($keys);
for ($i = 0; $i < $count; $i++) {
if (!is_numeric($array[$keys[$i]])) {
$numeric = false;
break;
}
}
return $numeric;
} | php | public static function isNumeric($array = null) {
if (empty($array)) {
return null;
}
if ($array === range(0, count($array) - 1)) {
return true;
}
$numeric = true;
$keys = array_keys($array);
$count = count($keys);
for ($i = 0; $i < $count; $i++) {
if (!is_numeric($array[$keys[$i]])) {
$numeric = false;
break;
}
}
return $numeric;
} | [
"public",
"static",
"function",
"isNumeric",
"(",
"$",
"array",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"array",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"array",
"===",
"range",
"(",
"0",
",",
"count",
"(",
"$",
... | Checks to see if all the values in the array are numeric.
@param array $array The array to check. If null, the value of the current Set object.
@return mixed `true` if values are numeric, `false` if not and `null` if the array to
check is empty. | [
"Checks",
"to",
"see",
"if",
"all",
"the",
"values",
"in",
"the",
"array",
"are",
"numeric",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Set.php#L552-L570 |
UnionOfRAD/lithium | util/Set.php | Set.matches | public static function matches($data, $conditions, $i = null, $length = null) {
if (!$conditions) {
return true;
}
if (is_string($conditions)) {
return (boolean) static::extract($data, $conditions);
}
foreach ($conditions as $condition) {
if ($condition === ':last') {
if ($i !== $length) {
return false;
}
continue;
} elseif ($condition === ':first') {
if ($i !== 1) {
return false;
}
continue;
}
if (!preg_match('/(.+?)([><!]?[=]|[><])(.*)/', $condition, $match)) {
if (ctype_digit($condition)) {
if ($i !== (int) $condition) {
return false;
}
} elseif (preg_match_all('/(?:^[0-9]+|(?<=,)[0-9]+)/', $condition, $matches)) {
return in_array($i, $matches[0]);
} elseif (!isset($data[$condition])) {
return false;
}
continue;
}
list(,$key,$op,$expected) = $match;
if (!isset($data[$key])) {
return false;
}
$val = $data[$key];
if ($op === '=' && $expected && $expected[0] === '/') {
return preg_match($expected, $val);
} elseif ($op === '=' && $val != $expected) {
return false;
} elseif ($op === '!=' && $val == $expected) {
return false;
} elseif ($op === '>' && $val <= $expected) {
return false;
} elseif ($op === '<' && $val >= $expected) {
return false;
} elseif ($op === '<=' && $val > $expected) {
return false;
} elseif ($op === '>=' && $val < $expected) {
return false;
}
}
return true;
} | php | public static function matches($data, $conditions, $i = null, $length = null) {
if (!$conditions) {
return true;
}
if (is_string($conditions)) {
return (boolean) static::extract($data, $conditions);
}
foreach ($conditions as $condition) {
if ($condition === ':last') {
if ($i !== $length) {
return false;
}
continue;
} elseif ($condition === ':first') {
if ($i !== 1) {
return false;
}
continue;
}
if (!preg_match('/(.+?)([><!]?[=]|[><])(.*)/', $condition, $match)) {
if (ctype_digit($condition)) {
if ($i !== (int) $condition) {
return false;
}
} elseif (preg_match_all('/(?:^[0-9]+|(?<=,)[0-9]+)/', $condition, $matches)) {
return in_array($i, $matches[0]);
} elseif (!isset($data[$condition])) {
return false;
}
continue;
}
list(,$key,$op,$expected) = $match;
if (!isset($data[$key])) {
return false;
}
$val = $data[$key];
if ($op === '=' && $expected && $expected[0] === '/') {
return preg_match($expected, $val);
} elseif ($op === '=' && $val != $expected) {
return false;
} elseif ($op === '!=' && $val == $expected) {
return false;
} elseif ($op === '>' && $val <= $expected) {
return false;
} elseif ($op === '<' && $val >= $expected) {
return false;
} elseif ($op === '<=' && $val > $expected) {
return false;
} elseif ($op === '>=' && $val < $expected) {
return false;
}
}
return true;
} | [
"public",
"static",
"function",
"matches",
"(",
"$",
"data",
",",
"$",
"conditions",
",",
"$",
"i",
"=",
"null",
",",
"$",
"length",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"conditions",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"is_st... | This function can be used to see if a single item or a given XPath
match certain conditions.
@param array $data An array of data to execute the match on.
@param mixed $conditions An array of condition strings or an XPath expression.
@param integer $i Optional: The 'nth'-number of the item being matched.
@param integer $length
@return boolean | [
"This",
"function",
"can",
"be",
"used",
"to",
"see",
"if",
"a",
"single",
"item",
"or",
"a",
"given",
"XPath",
"match",
"certain",
"conditions",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Set.php#L582-L637 |
UnionOfRAD/lithium | util/Set.php | Set.merge | public static function merge(array $array1, array $array2) {
$args = [$array1, $array2];
if (!$array1 || !$array2) {
return $array1 ?: $array2;
}
$result = (array) current($args);
while (($arg = next($args)) !== false) {
foreach ((array) $arg as $key => $val) {
if (is_array($val) && isset($result[$key]) && is_array($result[$key])) {
$result[$key] = static::merge($result[$key], $val);
} elseif (is_int($key)) {
$result[] = $val;
} else {
$result[$key] = $val;
}
}
}
return $result;
} | php | public static function merge(array $array1, array $array2) {
$args = [$array1, $array2];
if (!$array1 || !$array2) {
return $array1 ?: $array2;
}
$result = (array) current($args);
while (($arg = next($args)) !== false) {
foreach ((array) $arg as $key => $val) {
if (is_array($val) && isset($result[$key]) && is_array($result[$key])) {
$result[$key] = static::merge($result[$key], $val);
} elseif (is_int($key)) {
$result[] = $val;
} else {
$result[$key] = $val;
}
}
}
return $result;
} | [
"public",
"static",
"function",
"merge",
"(",
"array",
"$",
"array1",
",",
"array",
"$",
"array2",
")",
"{",
"$",
"args",
"=",
"[",
"$",
"array1",
",",
"$",
"array2",
"]",
";",
"if",
"(",
"!",
"$",
"array1",
"||",
"!",
"$",
"array2",
")",
"{",
... | This method can be thought of as a hybrid between PHP's `array_merge()`
and `array_merge_recursive()`. The difference to the two is that if an
array key contains another array then the function behaves recursive
(unlike `array_merge()`) but does not do if for keys containing strings
(unlike `array_merge_recursive()`). Please note: This function will work
with an unlimited amount of arguments and typecasts non-array parameters
into arrays.
@param array $array1 The base array.
@param array $array2 The array to be merged on top of the base array.
@return array Merged array of all passed params. | [
"This",
"method",
"can",
"be",
"thought",
"of",
"as",
"a",
"hybrid",
"between",
"PHP",
"s",
"array_merge",
"()",
"and",
"array_merge_recursive",
"()",
".",
"The",
"difference",
"to",
"the",
"two",
"is",
"that",
"if",
"an",
"array",
"key",
"contains",
"anot... | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Set.php#L652-L672 |
UnionOfRAD/lithium | util/Set.php | Set.normalize | public static function normalize($list, $assoc = true, $sep = ',', $trim = true) {
if (is_string($list)) {
$list = explode($sep, $list);
$list = ($trim) ? array_map('trim', $list) : $list;
return ($assoc) ? static::normalize($list) : $list;
}
if (!is_array($list)) {
return $list;
}
$keys = array_keys($list);
$count = count($keys);
$numeric = true;
if (!$assoc) {
for ($i = 0; $i < $count; $i++) {
if (!is_int($keys[$i])) {
$numeric = false;
break;
}
}
}
if (!$numeric || $assoc) {
$newList = [];
for ($i = 0; $i < $count; $i++) {
if (is_int($keys[$i]) && is_scalar($list[$keys[$i]])) {
$newList[$list[$keys[$i]]] = null;
} else {
$newList[$keys[$i]] = $list[$keys[$i]];
}
}
$list = $newList;
}
return $list;
} | php | public static function normalize($list, $assoc = true, $sep = ',', $trim = true) {
if (is_string($list)) {
$list = explode($sep, $list);
$list = ($trim) ? array_map('trim', $list) : $list;
return ($assoc) ? static::normalize($list) : $list;
}
if (!is_array($list)) {
return $list;
}
$keys = array_keys($list);
$count = count($keys);
$numeric = true;
if (!$assoc) {
for ($i = 0; $i < $count; $i++) {
if (!is_int($keys[$i])) {
$numeric = false;
break;
}
}
}
if (!$numeric || $assoc) {
$newList = [];
for ($i = 0; $i < $count; $i++) {
if (is_int($keys[$i]) && is_scalar($list[$keys[$i]])) {
$newList[$list[$keys[$i]]] = null;
} else {
$newList[$keys[$i]] = $list[$keys[$i]];
}
}
$list = $newList;
}
return $list;
} | [
"public",
"static",
"function",
"normalize",
"(",
"$",
"list",
",",
"$",
"assoc",
"=",
"true",
",",
"$",
"sep",
"=",
"','",
",",
"$",
"trim",
"=",
"true",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"list",
")",
")",
"{",
"$",
"list",
"=",
"exp... | Normalizes a string or array list.
```
Set::normalize('foo,bar'); // returns ['foo' => null, 'bar' => null];
Set::normalize(['foo', 'bar' => 'baz']; // returns ['foo' => null, 'bar' => 'baz'];
```
@param string|array $list List to normalize.
@param boolean $assoc If `true`, `$list` will be converted to an associative array.
@param string $sep If `$list` is a string, it will be split into an array with `$sep`.
@param boolean $trim If `true`, separated strings will be trimmed.
@return array | [
"Normalizes",
"a",
"string",
"or",
"array",
"list",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Set.php#L688-L724 |
UnionOfRAD/lithium | util/Set.php | Set.remove | public static function remove($list, $path = null) {
if (empty($path)) {
return $list;
}
if (!is_array($path)) {
$path = explode('.', $path);
}
$_list =& $list;
foreach ($path as $i => $key) {
if (is_numeric($key) && (integer) $key > 0 || $key === '0') {
$key = (integer) $key;
}
if ($i === count($path) - 1) {
unset($_list[$key]);
} else {
if (!isset($_list[$key])) {
return $list;
}
$_list =& $_list[$key];
}
}
return $list;
} | php | public static function remove($list, $path = null) {
if (empty($path)) {
return $list;
}
if (!is_array($path)) {
$path = explode('.', $path);
}
$_list =& $list;
foreach ($path as $i => $key) {
if (is_numeric($key) && (integer) $key > 0 || $key === '0') {
$key = (integer) $key;
}
if ($i === count($path) - 1) {
unset($_list[$key]);
} else {
if (!isset($_list[$key])) {
return $list;
}
$_list =& $_list[$key];
}
}
return $list;
} | [
"public",
"static",
"function",
"remove",
"(",
"$",
"list",
",",
"$",
"path",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"path",
")",
")",
"{",
"return",
"$",
"list",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"path",
")",
")",
... | Removes an element from an array as defined by `$path`.
@param mixed $list From where to remove.
@param mixed $path A dot-delimited string.
@return array Array with `$path` removed from its value. | [
"Removes",
"an",
"element",
"from",
"an",
"array",
"as",
"defined",
"by",
"$path",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Set.php#L733-L756 |
UnionOfRAD/lithium | util/Set.php | Set.sort | public static function sort($data, $path, $dir = 'asc') {
$flatten = function($flatten, $results, $key = null) {
$stack = [];
foreach ((array) $results as $k => $r) {
$id = $k;
if ($key !== null) {
$id = $key;
}
if (is_array($r)) {
$stack = array_merge($stack, $flatten($flatten, $r, $id));
} else {
$stack[] = ['id' => $id, 'value' => $r];
}
}
return $stack;
};
$extract = static::extract($data, $path);
$result = $flatten($flatten, $extract);
$keys = static::extract($result, '/id');
$values = static::extract($result, '/value');
$dir = ($dir === 'desc') ? SORT_DESC : SORT_ASC;
array_multisort($values, $dir, $keys, $dir);
$sorted = [];
$keys = array_unique($keys);
foreach ($keys as $k) {
$sorted[] = $data[$k];
}
return $sorted;
} | php | public static function sort($data, $path, $dir = 'asc') {
$flatten = function($flatten, $results, $key = null) {
$stack = [];
foreach ((array) $results as $k => $r) {
$id = $k;
if ($key !== null) {
$id = $key;
}
if (is_array($r)) {
$stack = array_merge($stack, $flatten($flatten, $r, $id));
} else {
$stack[] = ['id' => $id, 'value' => $r];
}
}
return $stack;
};
$extract = static::extract($data, $path);
$result = $flatten($flatten, $extract);
$keys = static::extract($result, '/id');
$values = static::extract($result, '/value');
$dir = ($dir === 'desc') ? SORT_DESC : SORT_ASC;
array_multisort($values, $dir, $keys, $dir);
$sorted = [];
$keys = array_unique($keys);
foreach ($keys as $k) {
$sorted[] = $data[$k];
}
return $sorted;
} | [
"public",
"static",
"function",
"sort",
"(",
"$",
"data",
",",
"$",
"path",
",",
"$",
"dir",
"=",
"'asc'",
")",
"{",
"$",
"flatten",
"=",
"function",
"(",
"$",
"flatten",
",",
"$",
"results",
",",
"$",
"key",
"=",
"null",
")",
"{",
"$",
"stack",
... | Sorts an array by any value, determined by a `Set`-compatible path.
@param array $data
@param string $path A `Set`-compatible path to the array value.
@param string $dir Either `'asc'` (the default) or `'desc'`.
@return array | [
"Sorts",
"an",
"array",
"by",
"any",
"value",
"determined",
"by",
"a",
"Set",
"-",
"compatible",
"path",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/util/Set.php#L766-L797 |
UnionOfRAD/lithium | net/socket/Stream.php | Stream.open | public function open(array $options = []) {
parent::open($options);
$config = $this->_config;
if (!$config['scheme'] || !$config['host']) {
return false;
}
$scheme = ($config['scheme'] !== 'udp') ? 'tcp' : 'udp';
$port = $config['port'] ?: 80;
$host = "{$scheme}://{$config['host']}:{$port}";
$flags = STREAM_CLIENT_CONNECT;
if ($config['persistent']) {
$flags = STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT;
}
$errorCode = $errorMessage = null;
$this->_resource = stream_socket_client(
$host, $errorCode, $errorMessage, $config['timeout'], $flags
);
if ($errorCode || $errorMessage) {
throw new NetworkException($errorMessage);
}
$this->timeout($config['timeout']);
if (!empty($config['encoding'])) {
$this->encoding($config['encoding']);
}
return $this->_resource;
} | php | public function open(array $options = []) {
parent::open($options);
$config = $this->_config;
if (!$config['scheme'] || !$config['host']) {
return false;
}
$scheme = ($config['scheme'] !== 'udp') ? 'tcp' : 'udp';
$port = $config['port'] ?: 80;
$host = "{$scheme}://{$config['host']}:{$port}";
$flags = STREAM_CLIENT_CONNECT;
if ($config['persistent']) {
$flags = STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT;
}
$errorCode = $errorMessage = null;
$this->_resource = stream_socket_client(
$host, $errorCode, $errorMessage, $config['timeout'], $flags
);
if ($errorCode || $errorMessage) {
throw new NetworkException($errorMessage);
}
$this->timeout($config['timeout']);
if (!empty($config['encoding'])) {
$this->encoding($config['encoding']);
}
return $this->_resource;
} | [
"public",
"function",
"open",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"parent",
"::",
"open",
"(",
"$",
"options",
")",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"_config",
";",
"if",
"(",
"!",
"$",
"config",
"[",
"'scheme'",
"]"... | Opens a socket and initializes the internal resource handle.
@param array $options update the config settings
@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. Throws exception if there is a network error. | [
"Opens",
"a",
"socket",
"and",
"initializes",
"the",
"internal",
"resource",
"handle",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/net/socket/Stream.php#L33-L61 |
UnionOfRAD/lithium | net/socket/Stream.php | Stream.read | public function read($length = null, $offset = null) {
if (!is_resource($this->_resource)) {
return false;
}
if (!$length) {
return stream_get_contents($this->_resource);
}
return stream_get_contents($this->_resource, $length, $offset);
} | php | public function read($length = null, $offset = null) {
if (!is_resource($this->_resource)) {
return false;
}
if (!$length) {
return stream_get_contents($this->_resource);
}
return stream_get_contents($this->_resource, $length, $offset);
} | [
"public",
"function",
"read",
"(",
"$",
"length",
"=",
"null",
",",
"$",
"offset",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_resource",
"(",
"$",
"this",
"->",
"_resource",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"length... | Reads data from the stream resource
@param integer $length If specified, will read up to $length bytes from the stream.
If no value is specified, all remaining bytes in the buffer will be read.
@param integer $offset Seek to the specified byte offset before reading.
@return string Returns string read from stream resource on success, false otherwise. | [
"Reads",
"data",
"from",
"the",
"stream",
"resource"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/net/socket/Stream.php#L89-L97 |
UnionOfRAD/lithium | net/socket/Stream.php | Stream.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);
}
return fwrite($this->_resource, (string) $data, strlen((string) $data));
} | 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);
}
return fwrite($this->_resource, (string) $data, strlen((string) $data));
} | [
"public",
"function",
"write",
"(",
"$",
"data",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_resource",
"(",
"$",
"this",
"->",
"_resource",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"is_object",
"(",
"$",
"data",
")",
")",
"{",
... | writes data to the stream resource
@param string $data The string to be written.
@return mixed False on error, number of bytes written otherwise. | [
"writes",
"data",
"to",
"the",
"stream",
"resource"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/net/socket/Stream.php#L105-L113 |
UnionOfRAD/lithium | net/socket/Stream.php | Stream.timeout | public function timeout($time) {
if (!is_resource($this->_resource)) {
return false;
}
return stream_set_timeout($this->_resource, $time);
} | php | public function timeout($time) {
if (!is_resource($this->_resource)) {
return false;
}
return stream_set_timeout($this->_resource, $time);
} | [
"public",
"function",
"timeout",
"(",
"$",
"time",
")",
"{",
"if",
"(",
"!",
"is_resource",
"(",
"$",
"this",
"->",
"_resource",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"stream_set_timeout",
"(",
"$",
"this",
"->",
"_resource",
",",
"$",
... | Set timeout period on a stream.
@link http://php.net/function.stream-set-timeout.php
PHP Manual: stream_set_timeout()
@param integer $time The timeout value in seconds.
@return boolean | [
"Set",
"timeout",
"period",
"on",
"a",
"stream",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/net/socket/Stream.php#L123-L128 |
UnionOfRAD/lithium | net/socket/Stream.php | Stream.encoding | public function encoding($charset) {
if (!function_exists('stream_encoding')) {
return false;
}
return is_resource($this->_resource) ? stream_encoding($this->_resource, $charset) : false;
} | php | public function encoding($charset) {
if (!function_exists('stream_encoding')) {
return false;
}
return is_resource($this->_resource) ? stream_encoding($this->_resource, $charset) : false;
} | [
"public",
"function",
"encoding",
"(",
"$",
"charset",
")",
"{",
"if",
"(",
"!",
"function_exists",
"(",
"'stream_encoding'",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"is_resource",
"(",
"$",
"this",
"->",
"_resource",
")",
"?",
"stream_encodi... | Sets the character set for stream encoding if possible. The `stream_encoding`
function is not guaranteed to be available as it is seems as if it's experimental
or just not officially documented. If the function is not available returns `false`.
@link http://php.net/function.stream-encoding.php stream_encoding()
@param string $charset
@return boolean Returns `false` if `stream_encoding()` function does not exist, boolean
result of `stream_encoding()` otherwise. | [
"Sets",
"the",
"character",
"set",
"for",
"stream",
"encoding",
"if",
"possible",
".",
"The",
"stream_encoding",
"function",
"is",
"not",
"guaranteed",
"to",
"be",
"available",
"as",
"it",
"is",
"seems",
"as",
"if",
"it",
"s",
"experimental",
"or",
"just",
... | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/net/socket/Stream.php#L140-L145 |
UnionOfRAD/lithium | data/entity/Document.php | Document.& | public function &__get($name) {
if (strpos($name, '.')) {
return $this->_getNested($name);
}
if (isset($this->_embedded[$name]) && !isset($this->_relationships[$name])) {
throw new RuntimeException("Not implemented.");
}
$result =& parent::__get($name);
if ($result !== null || array_key_exists($name, $this->_updated)) {
return $result;
}
if ($field = $this->schema($name)) {
if (isset($field['default'])) {
$this->set([$name => $field['default']]);
return $this->_updated[$name];
}
if (isset($field['array']) && $field['array'] && ($model = $this->_model)) {
$this->_updated[$name] = $model::create([], [
'class' => 'set',
'schema' => $this->schema(),
'pathKey' => $this->_pathKey ? $this->_pathKey . '.' . $name : $name,
'parent' => $this,
'model' => $this->_model,
'defaults' => false
]);
return $this->_updated[$name];
}
}
$null = null;
return $null;
} | php | public function &__get($name) {
if (strpos($name, '.')) {
return $this->_getNested($name);
}
if (isset($this->_embedded[$name]) && !isset($this->_relationships[$name])) {
throw new RuntimeException("Not implemented.");
}
$result =& parent::__get($name);
if ($result !== null || array_key_exists($name, $this->_updated)) {
return $result;
}
if ($field = $this->schema($name)) {
if (isset($field['default'])) {
$this->set([$name => $field['default']]);
return $this->_updated[$name];
}
if (isset($field['array']) && $field['array'] && ($model = $this->_model)) {
$this->_updated[$name] = $model::create([], [
'class' => 'set',
'schema' => $this->schema(),
'pathKey' => $this->_pathKey ? $this->_pathKey . '.' . $name : $name,
'parent' => $this,
'model' => $this->_model,
'defaults' => false
]);
return $this->_updated[$name];
}
}
$null = null;
return $null;
} | [
"public",
"function",
"&",
"__get",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"name",
",",
"'.'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_getNested",
"(",
"$",
"name",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
... | PHP magic method used when accessing fields as document properties, i.e. `$document->_id`.
@param $name The field name, as specified with an object property.
@return mixed Returns the value of the field specified in `$name`, and wraps complex data
types in sub-`Document` objects. | [
"PHP",
"magic",
"method",
"used",
"when",
"accessing",
"fields",
"as",
"document",
"properties",
"i",
".",
"e",
".",
"$document",
"-",
">",
"_id",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/entity/Document.php#L126-L159 |
UnionOfRAD/lithium | data/entity/Document.php | Document.sync | public function sync($id = null, array $data = [], array $options = []) {
$defaults = ['recursive' => true];
$options += $defaults;
if (!$options['recursive']) {
return parent::sync($id, $data, $options);
}
foreach ($this->_updated as $key => $val) {
if (is_object($val) && method_exists($val, 'sync')) {
$nested = isset($data[$key]) ? $data[$key] : [];
$this->_updated[$key]->sync(null, $nested, $options);
}
}
parent::sync($id, $data, $options);
} | php | public function sync($id = null, array $data = [], array $options = []) {
$defaults = ['recursive' => true];
$options += $defaults;
if (!$options['recursive']) {
return parent::sync($id, $data, $options);
}
foreach ($this->_updated as $key => $val) {
if (is_object($val) && method_exists($val, 'sync')) {
$nested = isset($data[$key]) ? $data[$key] : [];
$this->_updated[$key]->sync(null, $nested, $options);
}
}
parent::sync($id, $data, $options);
} | [
"public",
"function",
"sync",
"(",
"$",
"id",
"=",
"null",
",",
"array",
"$",
"data",
"=",
"[",
"]",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'recursive'",
"=>",
"true",
"]",
";",
"$",
"options",
"+=",
... | Extends the parent implementation to ensure that child documents are properly synced as well.
@param mixed $id
@param array $data
@param array $options Options when calling this method:
- `'recursive'` _boolean_: If `true` attempts to sync nested objects as well.
Otherwise, only syncs the current object. Defaults to `true`.
@return void | [
"Extends",
"the",
"parent",
"implementation",
"to",
"ensure",
"that",
"child",
"documents",
"are",
"properly",
"synced",
"as",
"well",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/entity/Document.php#L184-L199 |
UnionOfRAD/lithium | data/entity/Document.php | Document._relation | protected function _relation($classType, $key, $data, $options = []) {
return parent::_relation($classType, $key, $data, ['exists' => false] + $options);
} | php | protected function _relation($classType, $key, $data, $options = []) {
return parent::_relation($classType, $key, $data, ['exists' => false] + $options);
} | [
"protected",
"function",
"_relation",
"(",
"$",
"classType",
",",
"$",
"key",
",",
"$",
"data",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"return",
"parent",
"::",
"_relation",
"(",
"$",
"classType",
",",
"$",
"key",
",",
"$",
"data",
",",
"[",... | Instantiates a new `Document` object as a descendant of the current object, and sets all
default values and internal state.
@param string $classType The type of class to create, either `'entity'` or `'set'`.
@param string $key The key name to which the related object is assigned.
@param array $data The internal data of the related object.
@param array $options Any other options to pass when instantiating the related object.
@return object Returns a new `Document` object instance. | [
"Instantiates",
"a",
"new",
"Document",
"object",
"as",
"a",
"descendant",
"of",
"the",
"current",
"object",
"and",
"sets",
"all",
"default",
"values",
"and",
"internal",
"state",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/entity/Document.php#L211-L213 |
UnionOfRAD/lithium | data/entity/Document.php | Document.__isset | public function __isset($name) {
if (strpos($name, '.')) {
return $this->_getNested($name) !== null;
}
return isset($this->_updated[$name]);
} | php | public function __isset($name) {
if (strpos($name, '.')) {
return $this->_getNested($name) !== null;
}
return isset($this->_updated[$name]);
} | [
"public",
"function",
"__isset",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"name",
",",
"'.'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_getNested",
"(",
"$",
"name",
")",
"!==",
"null",
";",
"}",
"return",
"isset",
"(",
"$",... | PHP magic method used to check the presence of a field as document properties, i.e.
`$document->_id`.
@param $name The field name, as specified with an object property.
@return boolean True if the field specified in `$name` exists, false otherwise. | [
"PHP",
"magic",
"method",
"used",
"to",
"check",
"the",
"presence",
"of",
"a",
"field",
"as",
"document",
"properties",
"i",
".",
"e",
".",
"$document",
"-",
">",
"_id",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/entity/Document.php#L281-L286 |
UnionOfRAD/lithium | data/entity/Document.php | Document.set | public function set(array $data, array $options = []) {
$defaults = ['init' => false];
$options += $defaults;
$cast = ($schema = $this->schema());
foreach ($data as $key => $val) {
unset($this->_increment[$key]);
if (strpos($key, '.')) {
$this->_setNested($key, $val);
continue;
}
if ($cast) {
$pathKey = $this->_pathKey;
$model = $this->_model;
$parent = $this;
$val = $schema->cast($this, $key, $val, compact('pathKey', 'model', 'parent'));
}
if ($val instanceof self) {
$val->_exists = $options['init'] && $this->_exists;
$val->_pathKey = ($this->_pathKey ? "{$this->_pathKey}." : '') . $key;
$val->_model = $val->_model ?: $this->_model;
$val->_schema = $val->_schema ?: $this->_schema;
}
$this->_updated[$key] = $val;
}
} | php | public function set(array $data, array $options = []) {
$defaults = ['init' => false];
$options += $defaults;
$cast = ($schema = $this->schema());
foreach ($data as $key => $val) {
unset($this->_increment[$key]);
if (strpos($key, '.')) {
$this->_setNested($key, $val);
continue;
}
if ($cast) {
$pathKey = $this->_pathKey;
$model = $this->_model;
$parent = $this;
$val = $schema->cast($this, $key, $val, compact('pathKey', 'model', 'parent'));
}
if ($val instanceof self) {
$val->_exists = $options['init'] && $this->_exists;
$val->_pathKey = ($this->_pathKey ? "{$this->_pathKey}." : '') . $key;
$val->_model = $val->_model ?: $this->_model;
$val->_schema = $val->_schema ?: $this->_schema;
}
$this->_updated[$key] = $val;
}
} | [
"public",
"function",
"set",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'init'",
"=>",
"false",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"$",
"cast",
"=",
"(",
"$",
... | Allows several properties to be assigned at once.
For example:
```
$doc->set(['title' => 'Lorem Ipsum', 'value' => 42]);
```
@param array $data An associative array of fields and values to assign to the `Document`.
@param array $options
@return void | [
"Allows",
"several",
"properties",
"to",
"be",
"assigned",
"at",
"once",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/entity/Document.php#L324-L350 |
UnionOfRAD/lithium | data/entity/Document.php | Document.rewind | public function rewind() {
reset($this->_data);
reset($this->_updated);
$this->_valid = (count($this->_updated) > 0);
return current($this->_updated);
} | php | public function rewind() {
reset($this->_data);
reset($this->_updated);
$this->_valid = (count($this->_updated) > 0);
return current($this->_updated);
} | [
"public",
"function",
"rewind",
"(",
")",
"{",
"reset",
"(",
"$",
"this",
"->",
"_data",
")",
";",
"reset",
"(",
"$",
"this",
"->",
"_updated",
")",
";",
"$",
"this",
"->",
"_valid",
"=",
"(",
"count",
"(",
"$",
"this",
"->",
"_updated",
")",
">"... | Rewinds to the first item.
@return mixed The current item after rewinding. | [
"Rewinds",
"to",
"the",
"first",
"item",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/entity/Document.php#L401-L406 |
UnionOfRAD/lithium | data/entity/Document.php | Document.next | public function next() {
$prev = key($this->_data);
$this->_valid = (next($this->_data) !== false);
$cur = key($this->_data);
if (isset($this->_removed[$cur])) {
return $this->next();
}
if (!$this->_valid && $cur !== $prev && $cur !== null) {
$this->_valid = true;
}
return $this->_valid ? $this->__get(key($this->_data)) : null;
} | php | public function next() {
$prev = key($this->_data);
$this->_valid = (next($this->_data) !== false);
$cur = key($this->_data);
if (isset($this->_removed[$cur])) {
return $this->next();
}
if (!$this->_valid && $cur !== $prev && $cur !== null) {
$this->_valid = true;
}
return $this->_valid ? $this->__get(key($this->_data)) : null;
} | [
"public",
"function",
"next",
"(",
")",
"{",
"$",
"prev",
"=",
"key",
"(",
"$",
"this",
"->",
"_data",
")",
";",
"$",
"this",
"->",
"_valid",
"=",
"(",
"next",
"(",
"$",
"this",
"->",
"_data",
")",
"!==",
"false",
")",
";",
"$",
"cur",
"=",
"... | 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 (`$_handle`). If no more records can be fetched, returns `null`.
@return mixed Returns the next record in the set, or `null`, if no more records 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/entity/Document.php#L448-L460 |
UnionOfRAD/lithium | console/command/Create.php | Create._init | protected function _init() {
parent::_init();
$this->library = $this->library ?: true;
$defaults = ['prefix' => null, 'path' => null];
$this->_library = (array) Libraries::get($this->library) + $defaults;
} | php | protected function _init() {
parent::_init();
$this->library = $this->library ?: true;
$defaults = ['prefix' => null, 'path' => null];
$this->_library = (array) Libraries::get($this->library) + $defaults;
} | [
"protected",
"function",
"_init",
"(",
")",
"{",
"parent",
"::",
"_init",
"(",
")",
";",
"$",
"this",
"->",
"library",
"=",
"$",
"this",
"->",
"library",
"?",
":",
"true",
";",
"$",
"defaults",
"=",
"[",
"'prefix'",
"=>",
"null",
",",
"'path'",
"=>... | Class initializer. Parses template and sets up params that need to be filled.
@return void | [
"Class",
"initializer",
".",
"Parses",
"template",
"and",
"sets",
"up",
"params",
"that",
"need",
"to",
"be",
"filled",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/console/command/Create.php#L82-L87 |
UnionOfRAD/lithium | console/command/Create.php | Create.run | public function run($command = null) {
if ($command && !$this->request->args()) {
return $this->_default($command);
}
$this->request->shift();
$this->template = $this->template ?: $command;
if (!$command) {
return false;
}
if ($this->_execute($command)) {
return true;
}
$this->error("{$command} could not be created.");
return false;
} | php | public function run($command = null) {
if ($command && !$this->request->args()) {
return $this->_default($command);
}
$this->request->shift();
$this->template = $this->template ?: $command;
if (!$command) {
return false;
}
if ($this->_execute($command)) {
return true;
}
$this->error("{$command} could not be created.");
return false;
} | [
"public",
"function",
"run",
"(",
"$",
"command",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"command",
"&&",
"!",
"$",
"this",
"->",
"request",
"->",
"args",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_default",
"(",
"$",
"command",
")",
";",... | Run the create command. Takes `$command` and delegates to `$command::$method`
@param string $command
@return boolean | [
"Run",
"the",
"create",
"command",
".",
"Takes",
"$command",
"and",
"delegates",
"to",
"$command",
"::",
"$method"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/console/command/Create.php#L95-L110 |
UnionOfRAD/lithium | console/command/Create.php | Create._execute | protected function _execute($command) {
try {
if (!$class = $this->_instance($command)) {
return false;
}
} catch (ClassNotFoundException $e) {
return false;
}
$data = [];
$params = $class->invokeMethod('_params');
foreach ($params as $param) {
$data[$param] = $class->invokeMethod("_{$param}", [$this->request]);
}
if ($message = $class->invokeMethod('_save', [$data])) {
$this->out($message);
return true;
}
return false;
} | php | protected function _execute($command) {
try {
if (!$class = $this->_instance($command)) {
return false;
}
} catch (ClassNotFoundException $e) {
return false;
}
$data = [];
$params = $class->invokeMethod('_params');
foreach ($params as $param) {
$data[$param] = $class->invokeMethod("_{$param}", [$this->request]);
}
if ($message = $class->invokeMethod('_save', [$data])) {
$this->out($message);
return true;
}
return false;
} | [
"protected",
"function",
"_execute",
"(",
"$",
"command",
")",
"{",
"try",
"{",
"if",
"(",
"!",
"$",
"class",
"=",
"$",
"this",
"->",
"_instance",
"(",
"$",
"command",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"catch",
"(",
"ClassNotFoundExcep... | Execute the given sub-command for the current request.
@param string $command The sub-command name. example: Model, Controller, Test
@return boolean | [
"Execute",
"the",
"given",
"sub",
"-",
"command",
"for",
"the",
"current",
"request",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/console/command/Create.php#L118-L138 |
UnionOfRAD/lithium | console/command/Create.php | Create._default | protected function _default($name) {
$commands = [
['model', $name],
['controller', $name],
['test', 'model', $name],
['test', 'controller', $name]
];
foreach ($commands as $args) {
$command = $this->template = $this->request->params['command'] = array_shift($args);
$this->request->params['action'] = array_shift($args);
$this->request->params['args'] = $args;
if (!$this->_execute($command)) {
return false;
}
}
return true;
} | php | protected function _default($name) {
$commands = [
['model', $name],
['controller', $name],
['test', 'model', $name],
['test', 'controller', $name]
];
foreach ($commands as $args) {
$command = $this->template = $this->request->params['command'] = array_shift($args);
$this->request->params['action'] = array_shift($args);
$this->request->params['args'] = $args;
if (!$this->_execute($command)) {
return false;
}
}
return true;
} | [
"protected",
"function",
"_default",
"(",
"$",
"name",
")",
"{",
"$",
"commands",
"=",
"[",
"[",
"'model'",
",",
"$",
"name",
"]",
",",
"[",
"'controller'",
",",
"$",
"name",
"]",
",",
"[",
"'test'",
",",
"'model'",
",",
"$",
"name",
"]",
",",
"[... | Run through the default set. model, controller, test model, test controller
@param string $name class name to create
@return boolean | [
"Run",
"through",
"the",
"default",
"set",
".",
"model",
"controller",
"test",
"model",
"test",
"controller"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/console/command/Create.php#L146-L163 |
UnionOfRAD/lithium | console/command/Create.php | Create._namespace | protected function _namespace($request, $options = []) {
$name = $request->command;
$defaults = [
'prefix' => $this->_library['prefix'],
'prepend' => null,
'spaces' => [
'model' => 'models', 'view' => 'views', 'controller' => 'controllers',
'command' => 'extensions.command', 'adapter' => 'extensions.adapter',
'helper' => 'extensions.helper'
]
];
$options += $defaults;
if (isset($options['spaces'][$name])) {
$name = $options['spaces'][$name];
}
return str_replace('.', '\\', $options['prefix'] . $options['prepend'] . $name);
} | php | protected function _namespace($request, $options = []) {
$name = $request->command;
$defaults = [
'prefix' => $this->_library['prefix'],
'prepend' => null,
'spaces' => [
'model' => 'models', 'view' => 'views', 'controller' => 'controllers',
'command' => 'extensions.command', 'adapter' => 'extensions.adapter',
'helper' => 'extensions.helper'
]
];
$options += $defaults;
if (isset($options['spaces'][$name])) {
$name = $options['spaces'][$name];
}
return str_replace('.', '\\', $options['prefix'] . $options['prepend'] . $name);
} | [
"protected",
"function",
"_namespace",
"(",
"$",
"request",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"name",
"=",
"$",
"request",
"->",
"command",
";",
"$",
"defaults",
"=",
"[",
"'prefix'",
"=>",
"$",
"this",
"->",
"_library",
"[",
"'prefi... | Get the namespace.
@param string $request
@param array $options
@return string | [
"Get",
"the",
"namespace",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/console/command/Create.php#L172-L189 |
UnionOfRAD/lithium | console/command/Create.php | Create._params | protected function _params() {
$contents = $this->_template();
if (empty($contents)) {
return [];
}
preg_match_all('/(?:\{:(?P<params>[^}]+)\})/', $contents, $keys);
if (!empty($keys['params'])) {
return array_values(array_unique($keys['params']));
}
return [];
} | php | protected function _params() {
$contents = $this->_template();
if (empty($contents)) {
return [];
}
preg_match_all('/(?:\{:(?P<params>[^}]+)\})/', $contents, $keys);
if (!empty($keys['params'])) {
return array_values(array_unique($keys['params']));
}
return [];
} | [
"protected",
"function",
"_params",
"(",
")",
"{",
"$",
"contents",
"=",
"$",
"this",
"->",
"_template",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"contents",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"preg_match_all",
"(",
"'/(?:\\{:(?P<params>[... | Parse a template to find available variables specified in `{:name}` format. Each variable
corresponds to a method in the sub command. For example, a `{:namespace}` variable will
call the namespace method in the model command when `li3 create model Post` is called.
@return array | [
"Parse",
"a",
"template",
"to",
"find",
"available",
"variables",
"specified",
"in",
"{",
":",
"name",
"}",
"format",
".",
"Each",
"variable",
"corresponds",
"to",
"a",
"method",
"in",
"the",
"sub",
"command",
".",
"For",
"example",
"a",
"{",
":",
"names... | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/console/command/Create.php#L198-L210 |
UnionOfRAD/lithium | console/command/Create.php | Create._template | protected function _template() {
$file = Libraries::locate('command.create.template', $this->template, [
'filter' => false, 'type' => 'file', 'suffix' => '.txt.php'
]);
if (!$file || is_array($file)) {
return false;
}
return file_get_contents($file);
} | php | protected function _template() {
$file = Libraries::locate('command.create.template', $this->template, [
'filter' => false, 'type' => 'file', 'suffix' => '.txt.php'
]);
if (!$file || is_array($file)) {
return false;
}
return file_get_contents($file);
} | [
"protected",
"function",
"_template",
"(",
")",
"{",
"$",
"file",
"=",
"Libraries",
"::",
"locate",
"(",
"'command.create.template'",
",",
"$",
"this",
"->",
"template",
",",
"[",
"'filter'",
"=>",
"false",
",",
"'type'",
"=>",
"'file'",
",",
"'suffix'",
"... | Returns the contents of the template.
@return string | [
"Returns",
"the",
"contents",
"of",
"the",
"template",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/console/command/Create.php#L217-L225 |
UnionOfRAD/lithium | console/command/Create.php | Create._instance | protected function _instance($name, array $config = []) {
if ($class = Libraries::locate('command.create', Inflector::camelize($name))) {
$this->request->params['template'] = $this->template;
return new $class([
'request' => $this->request,
'classes' => $this->_classes
]);
}
return parent::_instance($name, $config);
} | php | protected function _instance($name, array $config = []) {
if ($class = Libraries::locate('command.create', Inflector::camelize($name))) {
$this->request->params['template'] = $this->template;
return new $class([
'request' => $this->request,
'classes' => $this->_classes
]);
}
return parent::_instance($name, $config);
} | [
"protected",
"function",
"_instance",
"(",
"$",
"name",
",",
"array",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"class",
"=",
"Libraries",
"::",
"locate",
"(",
"'command.create'",
",",
"Inflector",
"::",
"camelize",
"(",
"$",
"name",
")",... | Get an instance of a sub-command
@param string $name the name of the sub-command to instantiate
@param array $config
@return object | [
"Get",
"an",
"instance",
"of",
"a",
"sub",
"-",
"command"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/console/command/Create.php#L234-L244 |
UnionOfRAD/lithium | console/command/Create.php | Create._save | protected function _save(array $params = []) {
$defaults = ['namespace' => null, 'class' => null];
$params += $defaults;
if (empty($params['class']) || empty($this->_library['path'])) {
return false;
}
$contents = $this->_template();
$result = Text::insert($contents, $params);
$namespace = str_replace($this->_library['prefix'], '\\', $params['namespace']);
$path = str_replace('\\', '/', "{$namespace}\\{$params['class']}");
$path = $this->_library['path'] . stristr($path, '/');
$file = str_replace('//', '/', "{$path}.php");
$directory = dirname($file);
$relative = str_replace($this->_library['path'] . '/', "", $file);
if ((!is_dir($directory)) && !mkdir($directory, 0755, true)) {
return false;
}
if (file_exists($file)) {
$prompt = "{$relative} already exists. Overwrite?";
$choices = ['y', 'n'];
if ($this->in($prompt, compact('choices')) !== 'y') {
return "{$params['class']} skipped.";
}
}
if (file_put_contents($file, "<?php\n\n{$result}\n\n?>")) {
return "{$params['class']} created in {$relative}.";
}
return false;
} | php | protected function _save(array $params = []) {
$defaults = ['namespace' => null, 'class' => null];
$params += $defaults;
if (empty($params['class']) || empty($this->_library['path'])) {
return false;
}
$contents = $this->_template();
$result = Text::insert($contents, $params);
$namespace = str_replace($this->_library['prefix'], '\\', $params['namespace']);
$path = str_replace('\\', '/', "{$namespace}\\{$params['class']}");
$path = $this->_library['path'] . stristr($path, '/');
$file = str_replace('//', '/', "{$path}.php");
$directory = dirname($file);
$relative = str_replace($this->_library['path'] . '/', "", $file);
if ((!is_dir($directory)) && !mkdir($directory, 0755, true)) {
return false;
}
if (file_exists($file)) {
$prompt = "{$relative} already exists. Overwrite?";
$choices = ['y', 'n'];
if ($this->in($prompt, compact('choices')) !== 'y') {
return "{$params['class']} skipped.";
}
}
if (file_put_contents($file, "<?php\n\n{$result}\n\n?>")) {
return "{$params['class']} created in {$relative}.";
}
return false;
} | [
"protected",
"function",
"_save",
"(",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'namespace'",
"=>",
"null",
",",
"'class'",
"=>",
"null",
"]",
";",
"$",
"params",
"+=",
"$",
"defaults",
";",
"if",
"(",
"empty",
"... | Save a template with the current params. Writes file to `Create::$path`.
@param array $params
@return string|boolean A result string on success of writing the file. If any errors
occur along the way such as missing information boolean false is returned. | [
"Save",
"a",
"template",
"with",
"the",
"current",
"params",
".",
"Writes",
"file",
"to",
"Create",
"::",
"$path",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/console/command/Create.php#L253-L284 |
UnionOfRAD/lithium | data/model/Query.php | Query.map | public function map($map = null) {
if ($map !== null) {
$this->_map = $map;
return $this;
}
return $this->_map;
} | php | public function map($map = null) {
if ($map !== null) {
$this->_map = $map;
return $this;
}
return $this->_map;
} | [
"public",
"function",
"map",
"(",
"$",
"map",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"map",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"_map",
"=",
"$",
"map",
";",
"return",
"$",
"this",
";",
"}",
"return",
"$",
"this",
"->",
"_map",
";",
"... | Generates a schema map of the query's result set, where the keys are aliases, and the values
are arrays of field names.
@param array $map
@return array | [
"Generates",
"a",
"schema",
"map",
"of",
"the",
"query",
"s",
"result",
"set",
"where",
"the",
"keys",
"are",
"aliases",
"and",
"the",
"values",
"are",
"arrays",
"of",
"field",
"names",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/model/Query.php#L236-L242 |
UnionOfRAD/lithium | data/model/Query.php | Query.calculate | public function calculate($calculate = null) {
if ($calculate) {
$this->_config['calculate'] = $calculate;
return $this;
}
return $this->_config['calculate'];
} | php | public function calculate($calculate = null) {
if ($calculate) {
$this->_config['calculate'] = $calculate;
return $this;
}
return $this->_config['calculate'];
} | [
"public",
"function",
"calculate",
"(",
"$",
"calculate",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"calculate",
")",
"{",
"$",
"this",
"->",
"_config",
"[",
"'calculate'",
"]",
"=",
"$",
"calculate",
";",
"return",
"$",
"this",
";",
"}",
"return",
"$",... | Accessor method for `Query` calculate values.
@param string $calculate Value for calculate config setting.
@return mixed Current calculate config value. | [
"Accessor",
"method",
"for",
"Query",
"calculate",
"values",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/model/Query.php#L250-L256 |
UnionOfRAD/lithium | data/model/Query.php | Query.model | public function model($model = null) {
if (!$model) {
return $this->_config['model'];
}
$this->_config['model'] = $model;
$this->_config['source'] = $this->_config['source'] ?: $model::meta('source');
return $this;
} | php | public function model($model = null) {
if (!$model) {
return $this->_config['model'];
}
$this->_config['model'] = $model;
$this->_config['source'] = $this->_config['source'] ?: $model::meta('source');
return $this;
} | [
"public",
"function",
"model",
"(",
"$",
"model",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"model",
")",
"{",
"return",
"$",
"this",
"->",
"_config",
"[",
"'model'",
"]",
";",
"}",
"$",
"this",
"->",
"_config",
"[",
"'model'",
"]",
"=",
"$",
... | Set or get the associated model.
Will also set the source table, i.e. `$this->_config['source']` when setting the model.
@param string|null $model Name of model to use, or `null` to retrieve current one.
@return string|Query Either the current model name in use when $model is `null`,
or the query itself when setting the model name. | [
"Set",
"or",
"get",
"the",
"associated",
"model",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/model/Query.php#L267-L275 |
UnionOfRAD/lithium | data/model/Query.php | Query.conditions | public function conditions($conditions = null) {
if (!$conditions) {
return $this->_config['conditions'] ?: $this->_entityConditions();
}
$this->_config['conditions'] = array_merge(
(array) $this->_config['conditions'], (array) $conditions
);
return $this;
} | php | public function conditions($conditions = null) {
if (!$conditions) {
return $this->_config['conditions'] ?: $this->_entityConditions();
}
$this->_config['conditions'] = array_merge(
(array) $this->_config['conditions'], (array) $conditions
);
return $this;
} | [
"public",
"function",
"conditions",
"(",
"$",
"conditions",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"conditions",
")",
"{",
"return",
"$",
"this",
"->",
"_config",
"[",
"'conditions'",
"]",
"?",
":",
"$",
"this",
"->",
"_entityConditions",
"(",
")"... | Set or append to existing conditions, or get current conditions.
When getting current conditions and none are configured for the query,
will ask the bound entity for its conditions instead.
@param string|array|null $conditions Condition/s to append to existing conditions.
Provide `null` to get current conditions.
@return string|Query Either the currrent conditions when $conditions is
`null` or the query itself when setting the conditions. | [
"Set",
"or",
"append",
"to",
"existing",
"conditions",
"or",
"get",
"current",
"conditions",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/model/Query.php#L288-L296 |
UnionOfRAD/lithium | data/model/Query.php | Query.having | public function having($having = null) {
if (!$having) {
return $this->_config['having'];
}
$this->_config['having'] = array_merge(
(array) $this->_config['having'], (array) $having
);
return $this;
} | php | public function having($having = null) {
if (!$having) {
return $this->_config['having'];
}
$this->_config['having'] = array_merge(
(array) $this->_config['having'], (array) $having
);
return $this;
} | [
"public",
"function",
"having",
"(",
"$",
"having",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"having",
")",
"{",
"return",
"$",
"this",
"->",
"_config",
"[",
"'having'",
"]",
";",
"}",
"$",
"this",
"->",
"_config",
"[",
"'having'",
"]",
"=",
"... | Set and get _having_.
@param mixed $having String or array to append to existing having.
@return string|Query Either the currrent _having_ when $having is
`null` or the query itself when setting _having_. | [
"Set",
"and",
"get",
"_having_",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/model/Query.php#L305-L313 |
UnionOfRAD/lithium | data/model/Query.php | Query.fields | public function fields($fields = null, $overwrite = false) {
if ($fields === false || $overwrite) {
$this->_fields = [0 => [], 1 => []];
}
if ($fields === null) {
return array_merge(array_keys($this->_fields[1]), $this->_fields[0]);
}
if (!$fields) {
return $this;
}
foreach ((array) $fields as $key => $field) {
if (is_string($field)) {
$this->_fields[1][$field] = true;
} elseif (is_array($field) && !is_numeric($key)) {
foreach ($field as &$value) {
$value = "{$key}.{$value}";
}
$this->fields($field);
} else {
$this->_fields[0][] = $field;
}
}
return $this;
} | php | public function fields($fields = null, $overwrite = false) {
if ($fields === false || $overwrite) {
$this->_fields = [0 => [], 1 => []];
}
if ($fields === null) {
return array_merge(array_keys($this->_fields[1]), $this->_fields[0]);
}
if (!$fields) {
return $this;
}
foreach ((array) $fields as $key => $field) {
if (is_string($field)) {
$this->_fields[1][$field] = true;
} elseif (is_array($field) && !is_numeric($key)) {
foreach ($field as &$value) {
$value = "{$key}.{$value}";
}
$this->fields($field);
} else {
$this->_fields[0][] = $field;
}
}
return $this;
} | [
"public",
"function",
"fields",
"(",
"$",
"fields",
"=",
"null",
",",
"$",
"overwrite",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"fields",
"===",
"false",
"||",
"$",
"overwrite",
")",
"{",
"$",
"this",
"->",
"_fields",
"=",
"[",
"0",
"=>",
"[",
"]... | Set, get or reset fields option for query.
Usage:
```
// to add a field
$query->fields('created');
// to add several fields
$query->fields(['title','body','modified']);
// to reset fields to none
$query->fields(false);
// should be followed by a 2nd call to fields with required fields
```
@param mixed $fields string, array or `false`
@param boolean $overwrite If `true`, existing fields will be removed before adding `$fields`.
@return array Returns an array containing all fields added to the query. | [
"Set",
"get",
"or",
"reset",
"fields",
"option",
"for",
"query",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/model/Query.php#L335-L358 |
UnionOfRAD/lithium | data/model/Query.php | Query.limit | public function limit($limit = null) {
if ($limit) {
$this->_config['limit'] = (integer) $limit;
return $this;
}
if ($limit === false) {
$this->_config['limit'] = null;
return $this;
}
return $this->_config['limit'];
} | php | public function limit($limit = null) {
if ($limit) {
$this->_config['limit'] = (integer) $limit;
return $this;
}
if ($limit === false) {
$this->_config['limit'] = null;
return $this;
}
return $this->_config['limit'];
} | [
"public",
"function",
"limit",
"(",
"$",
"limit",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"limit",
")",
"{",
"$",
"this",
"->",
"_config",
"[",
"'limit'",
"]",
"=",
"(",
"integer",
")",
"$",
"limit",
";",
"return",
"$",
"this",
";",
"}",
"if",
"... | Set or get the limit for the amount of results to return.
@param integer|boolean $limit An integer indicating the number of results to limit or
`false` to employ no limit at all. Or `null` to retrieve the current limit.
@return integer|null|Query Either the currrent limit when $limit is
`null` or the query itself when setting the limit or providing `false`. | [
"Set",
"or",
"get",
"the",
"limit",
"for",
"the",
"amount",
"of",
"results",
"to",
"return",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/model/Query.php#L368-L378 |
UnionOfRAD/lithium | data/model/Query.php | Query.offset | public function offset($offset = null) {
if ($offset !== null) {
$this->_config['offset'] = (integer) $offset;
return $this;
}
return $this->_config['offset'];
} | php | public function offset($offset = null) {
if ($offset !== null) {
$this->_config['offset'] = (integer) $offset;
return $this;
}
return $this->_config['offset'];
} | [
"public",
"function",
"offset",
"(",
"$",
"offset",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"offset",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"_config",
"[",
"'offset'",
"]",
"=",
"(",
"integer",
")",
"$",
"offset",
";",
"return",
"$",
"this",
... | Set and get method for query's offset, i.e. which records to get
@param integer|null $offset
@return integer|\lithium\data\Query | [
"Set",
"and",
"get",
"method",
"for",
"query",
"s",
"offset",
"i",
".",
"e",
".",
"which",
"records",
"to",
"get"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/model/Query.php#L386-L392 |
UnionOfRAD/lithium | data/model/Query.php | Query.page | public function page($page = null) {
if ($page) {
$this->_config['page'] = $page = ((integer) $page ?: 1);
$this->offset(($page - 1) * $this->_config['limit']);
return $this;
}
return $this->_config['page'];
} | php | public function page($page = null) {
if ($page) {
$this->_config['page'] = $page = ((integer) $page ?: 1);
$this->offset(($page - 1) * $this->_config['limit']);
return $this;
}
return $this->_config['page'];
} | [
"public",
"function",
"page",
"(",
"$",
"page",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"page",
")",
"{",
"$",
"this",
"->",
"_config",
"[",
"'page'",
"]",
"=",
"$",
"page",
"=",
"(",
"(",
"integer",
")",
"$",
"page",
"?",
":",
"1",
")",
";",
... | Set and get method for page, in relation to limit, of which records to get
@param integer|null $page
@return integer|\lithium\data\Query | [
"Set",
"and",
"get",
"method",
"for",
"page",
"in",
"relation",
"to",
"limit",
"of",
"which",
"records",
"to",
"get"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/model/Query.php#L400-L407 |
UnionOfRAD/lithium | data/model/Query.php | Query.order | public function order($order = null) {
if ($order) {
$this->_config['order'] = $order;
return $this;
}
return $this->_config['order'];
} | php | public function order($order = null) {
if ($order) {
$this->_config['order'] = $order;
return $this;
}
return $this->_config['order'];
} | [
"public",
"function",
"order",
"(",
"$",
"order",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"order",
")",
"{",
"$",
"this",
"->",
"_config",
"[",
"'order'",
"]",
"=",
"$",
"order",
";",
"return",
"$",
"this",
";",
"}",
"return",
"$",
"this",
"->",
... | Set and get method for the query's order specification.
@param array|string|null $order
@return array|\lithium\data\Query | [
"Set",
"and",
"get",
"method",
"for",
"the",
"query",
"s",
"order",
"specification",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/model/Query.php#L415-L421 |
UnionOfRAD/lithium | data/model/Query.php | Query.group | public function group($group = null) {
if ($group) {
$this->_config['group'] = $group;
return $this;
}
if ($group === false) {
$this->_config['group'] = null;
return $this;
}
return $this->_config['group'];
} | php | public function group($group = null) {
if ($group) {
$this->_config['group'] = $group;
return $this;
}
if ($group === false) {
$this->_config['group'] = null;
return $this;
}
return $this->_config['group'];
} | [
"public",
"function",
"group",
"(",
"$",
"group",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"group",
")",
"{",
"$",
"this",
"->",
"_config",
"[",
"'group'",
"]",
"=",
"$",
"group",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"$",
"group",
"==... | Set and get method for the `Query` group config setting.
@param string|array|null $group
@return array|null|\lithium\data\Query | [
"Set",
"and",
"get",
"method",
"for",
"the",
"Query",
"group",
"config",
"setting",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/model/Query.php#L429-L439 |
UnionOfRAD/lithium | data/model/Query.php | Query.comment | public function comment($comment = null) {
if ($comment) {
$this->_config['comment'] = $comment;
return $this;
}
return $this->_config['comment'];
} | php | public function comment($comment = null) {
if ($comment) {
$this->_config['comment'] = $comment;
return $this;
}
return $this->_config['comment'];
} | [
"public",
"function",
"comment",
"(",
"$",
"comment",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"comment",
")",
"{",
"$",
"this",
"->",
"_config",
"[",
"'comment'",
"]",
"=",
"$",
"comment",
";",
"return",
"$",
"this",
";",
"}",
"return",
"$",
"this",... | Set and get method for current query's comment.
Comment will have no effect on query, but will be passed along so data source can log it.
@param string|null $comment
@return string|\lithium\data\Query | [
"Set",
"and",
"get",
"method",
"for",
"current",
"query",
"s",
"comment",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/model/Query.php#L449-L455 |
UnionOfRAD/lithium | data/model/Query.php | Query.data | public function data($data = []) {
$bind =& $this->_entity;
if ($data) {
$bind ? $bind->set($data) : $this->_data = array_merge($this->_data, $data);
return $this;
}
$data = $bind ? $bind->data() : $this->_data;
return ($list = $this->_config['whitelist']) ? array_intersect_key($data, $list) : $data;
} | php | public function data($data = []) {
$bind =& $this->_entity;
if ($data) {
$bind ? $bind->set($data) : $this->_data = array_merge($this->_data, $data);
return $this;
}
$data = $bind ? $bind->data() : $this->_data;
return ($list = $this->_config['whitelist']) ? array_intersect_key($data, $list) : $data;
} | [
"public",
"function",
"data",
"(",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"bind",
"=",
"&",
"$",
"this",
"->",
"_entity",
";",
"if",
"(",
"$",
"data",
")",
"{",
"$",
"bind",
"?",
"$",
"bind",
"->",
"set",
"(",
"$",
"data",
")",
":",
"$"... | Set and get method for the query's record's data.
@param array $data if set, will set given array.
@return array Empty array if no data, array of data if the record has it. | [
"Set",
"and",
"get",
"method",
"for",
"the",
"query",
"s",
"record",
"s",
"data",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/model/Query.php#L477-L486 |
UnionOfRAD/lithium | data/model/Query.php | Query.relationships | public function relationships($relpath = null, $config = null) {
if ($config) {
if (!$relpath) {
throw new InvalidArgumentException("The relation dotted path is empty.");
}
if (isset($config['model']) && isset($config['alias'])) {
$this->_models[$config['alias']] = $config['model'];
}
$this->_config['relationships'][$relpath] = $config;
return $this;
}
if (!$relpath) {
return $this->_config['relationships'];
}
if (isset($this->_config['relationships'][$relpath])) {
return $this->_config['relationships'][$relpath];
}
} | php | public function relationships($relpath = null, $config = null) {
if ($config) {
if (!$relpath) {
throw new InvalidArgumentException("The relation dotted path is empty.");
}
if (isset($config['model']) && isset($config['alias'])) {
$this->_models[$config['alias']] = $config['model'];
}
$this->_config['relationships'][$relpath] = $config;
return $this;
}
if (!$relpath) {
return $this->_config['relationships'];
}
if (isset($this->_config['relationships'][$relpath])) {
return $this->_config['relationships'][$relpath];
}
} | [
"public",
"function",
"relationships",
"(",
"$",
"relpath",
"=",
"null",
",",
"$",
"config",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"config",
")",
"{",
"if",
"(",
"!",
"$",
"relpath",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"The re... | Set and get the relationships.
@param string $relpath A dotted path.
@param array $config the config array to set.
@return mixed The relationships array or a relationship array if `$relpath` is set. Returns
`null` if a join doesn't exist.
@throws InvalidArgumentException | [
"Set",
"and",
"get",
"the",
"relationships",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/model/Query.php#L497-L514 |
UnionOfRAD/lithium | data/model/Query.php | Query.joins | public function joins($name = null, $join = null) {
if (is_array($name)) {
$join = $name;
$name = null;
}
if ($join) {
if (!$name) {
$this->_config['joins'][] = $join;
} else {
$this->_config['joins'][$name] = $join;
}
return $this;
}
if (!$name) {
return $this->_config['joins'];
}
if (isset($this->_config['joins'][$name])) {
return $this->_config['joins'][$name];
}
} | php | public function joins($name = null, $join = null) {
if (is_array($name)) {
$join = $name;
$name = null;
}
if ($join) {
if (!$name) {
$this->_config['joins'][] = $join;
} else {
$this->_config['joins'][$name] = $join;
}
return $this;
}
if (!$name) {
return $this->_config['joins'];
}
if (isset($this->_config['joins'][$name])) {
return $this->_config['joins'][$name];
}
} | [
"public",
"function",
"joins",
"(",
"$",
"name",
"=",
"null",
",",
"$",
"join",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"name",
")",
")",
"{",
"$",
"join",
"=",
"$",
"name",
";",
"$",
"name",
"=",
"null",
";",
"}",
"if",
"(",
... | Set and get the joins
@param string $name Optional name of join. Unless two parameters are passed, this parameter
is regonized as `$join`.
@param object|string $join A single query object or an array of query objects
@return mixed The joins array or a join array if `$name` is set. Returns `null` if a join
doesn't exist. | [
"Set",
"and",
"get",
"the",
"joins"
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/model/Query.php#L525-L544 |
UnionOfRAD/lithium | data/model/Query.php | Query.export | public function export(Source $source, array $options = []) {
$defaults = ['keys' => []];
$options += $defaults;
if ($options['keys']) {
$keys = array_flip($options['keys']);
} else {
$keys =& $this->_config;
}
list($copy, $apply) = Set::slice($keys, $source->methods());
if (isset($keys['with'])) {
$this->applyStrategy($source);
}
foreach ($apply as $item => $value) {
$results[$item] = $source->{$item}($this->{$item}(), $this);
}
foreach ($copy as $item => $value) {
$results[$item] = $this->_config[$item];
}
if (array_key_exists('data', $keys)) {
$results['data'] = $this->_exportData();
}
if (array_key_exists('source', $keys)) {
$results['source'] = $source->name($results['source']);
}
if (!isset($results['fields'])) {
return $results;
}
$created = ['fields', 'values'];
if (is_array($results['fields']) && array_keys($results['fields']) == $created) {
$results = $results['fields'] + $results;
}
return $results;
} | php | public function export(Source $source, array $options = []) {
$defaults = ['keys' => []];
$options += $defaults;
if ($options['keys']) {
$keys = array_flip($options['keys']);
} else {
$keys =& $this->_config;
}
list($copy, $apply) = Set::slice($keys, $source->methods());
if (isset($keys['with'])) {
$this->applyStrategy($source);
}
foreach ($apply as $item => $value) {
$results[$item] = $source->{$item}($this->{$item}(), $this);
}
foreach ($copy as $item => $value) {
$results[$item] = $this->_config[$item];
}
if (array_key_exists('data', $keys)) {
$results['data'] = $this->_exportData();
}
if (array_key_exists('source', $keys)) {
$results['source'] = $source->name($results['source']);
}
if (!isset($results['fields'])) {
return $results;
}
$created = ['fields', 'values'];
if (is_array($results['fields']) && array_keys($results['fields']) == $created) {
$results = $results['fields'] + $results;
}
return $results;
} | [
"public",
"function",
"export",
"(",
"Source",
"$",
"source",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'keys'",
"=>",
"[",
"]",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"if",
"(",
"$",
"optio... | Convert the query's properties to the data sources' syntax and return it as an array.
@param \lithium\data\Source $source Instance of the data source to use for conversion.
@param array $options Options to use when exporting the data.
@return array Returns an array containing a data source-specific representation of a query. | [
"Convert",
"the",
"query",
"s",
"properties",
"to",
"the",
"data",
"sources",
"syntax",
"and",
"return",
"it",
"as",
"an",
"array",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/model/Query.php#L553-L591 |
UnionOfRAD/lithium | data/model/Query.php | Query.applyStrategy | public function applyStrategy(Source $source) {
if ($this->_built) {
return;
}
$this->_built = true;
if (!$this->_config['with']) {
return;
}
$options = [];
if (isset($this->_config['strategy'])) {
$options['strategy'] = $this->_config['strategy'];
}
$source->applyStrategy($options, $this);
} | php | public function applyStrategy(Source $source) {
if ($this->_built) {
return;
}
$this->_built = true;
if (!$this->_config['with']) {
return;
}
$options = [];
if (isset($this->_config['strategy'])) {
$options['strategy'] = $this->_config['strategy'];
}
$source->applyStrategy($options, $this);
} | [
"public",
"function",
"applyStrategy",
"(",
"Source",
"$",
"source",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_built",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"_built",
"=",
"true",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"_config",
"[",
... | Helper method used by `export()` which delegate the query generation to the data source.
@param \lithium\data\Source $source Instance of the data source to use for conversion. | [
"Helper",
"method",
"used",
"by",
"export",
"()",
"which",
"delegate",
"the",
"query",
"generation",
"to",
"the",
"data",
"source",
"."
] | train | https://github.com/UnionOfRAD/lithium/blob/bec3f4fdf61ea5002904754f43941ad1430ecec7/data/model/Query.php#L598-L611 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.