id int32 0 241k | repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 |
|---|---|---|---|---|---|---|---|---|---|---|---|
211,500 | cakephp/cakephp | src/Cache/Engine/XcacheEngine.php | XcacheEngine.decrement | public function decrement($key, $offset = 1)
{
$key = $this->_key($key);
return xcache_dec($key, $offset);
} | php | public function decrement($key, $offset = 1)
{
$key = $this->_key($key);
return xcache_dec($key, $offset);
} | [
"public",
"function",
"decrement",
"(",
"$",
"key",
",",
"$",
"offset",
"=",
"1",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"_key",
"(",
"$",
"key",
")",
";",
"return",
"xcache_dec",
"(",
"$",
"key",
",",
"$",
"offset",
")",
";",
"}"
] | Decrements the value of an integer cached key.
If the cache key is not an integer it will be treated as 0
@param string $key Identifier for the data
@param int $offset How much to subtract
@return bool|int New decremented value, false otherwise | [
"Decrements",
"the",
"value",
"of",
"an",
"integer",
"cached",
"key",
".",
"If",
"the",
"cache",
"key",
"is",
"not",
"an",
"integer",
"it",
"will",
"be",
"treated",
"as",
"0"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/Engine/XcacheEngine.php#L145-L150 |
211,501 | cakephp/cakephp | src/View/Form/ArrayContext.php | ArrayContext.primaryKey | public function primaryKey()
{
if (empty($this->_context['schema']['_constraints']) ||
!is_array($this->_context['schema']['_constraints'])
) {
return [];
}
foreach ($this->_context['schema']['_constraints'] as $data) {
if (isset($data['type']) && $data['type'] === 'primary') {
return isset($data['columns']) ? (array)$data['columns'] : [];
}
}
return [];
} | php | public function primaryKey()
{
if (empty($this->_context['schema']['_constraints']) ||
!is_array($this->_context['schema']['_constraints'])
) {
return [];
}
foreach ($this->_context['schema']['_constraints'] as $data) {
if (isset($data['type']) && $data['type'] === 'primary') {
return isset($data['columns']) ? (array)$data['columns'] : [];
}
}
return [];
} | [
"public",
"function",
"primaryKey",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_context",
"[",
"'schema'",
"]",
"[",
"'_constraints'",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"this",
"->",
"_context",
"[",
"'schema'",
"]",
"[",
"'_constraints'",
"]",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"_context",
"[",
"'schema'",
"]",
"[",
"'_constraints'",
"]",
"as",
"$",
"data",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'type'",
"]",
")",
"&&",
"$",
"data",
"[",
"'type'",
"]",
"===",
"'primary'",
")",
"{",
"return",
"isset",
"(",
"$",
"data",
"[",
"'columns'",
"]",
")",
"?",
"(",
"array",
")",
"$",
"data",
"[",
"'columns'",
"]",
":",
"[",
"]",
";",
"}",
"}",
"return",
"[",
"]",
";",
"}"
] | Get the fields used in the context as a primary key.
@return array | [
"Get",
"the",
"fields",
"used",
"in",
"the",
"context",
"as",
"a",
"primary",
"key",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Form/ArrayContext.php#L107-L121 |
211,502 | cakephp/cakephp | src/View/Form/ArrayContext.php | ArrayContext.isCreate | public function isCreate()
{
$primary = $this->primaryKey();
foreach ($primary as $column) {
if (!empty($this->_context['defaults'][$column])) {
return false;
}
}
return true;
} | php | public function isCreate()
{
$primary = $this->primaryKey();
foreach ($primary as $column) {
if (!empty($this->_context['defaults'][$column])) {
return false;
}
}
return true;
} | [
"public",
"function",
"isCreate",
"(",
")",
"{",
"$",
"primary",
"=",
"$",
"this",
"->",
"primaryKey",
"(",
")",
";",
"foreach",
"(",
"$",
"primary",
"as",
"$",
"column",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_context",
"[",
"'defaults'",
"]",
"[",
"$",
"column",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Returns whether or not this form is for a create operation.
For this method to return true, both the primary key constraint
must be defined in the 'schema' data, and the 'defaults' data must
contain a value for all fields in the key.
@return bool | [
"Returns",
"whether",
"or",
"not",
"this",
"form",
"is",
"for",
"a",
"create",
"operation",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Form/ArrayContext.php#L142-L152 |
211,503 | cakephp/cakephp | src/View/Form/ArrayContext.php | ArrayContext.val | public function val($field, $options = [])
{
$options += [
'default' => null,
'schemaDefault' => true
];
$val = $this->_request->getData($field);
if ($val !== null) {
return $val;
}
if ($options['default'] !== null || !$options['schemaDefault']) {
return $options['default'];
}
if (empty($this->_context['defaults']) || !is_array($this->_context['defaults'])) {
return null;
}
// Using Hash::check here incase the default value is actually null
if (Hash::check($this->_context['defaults'], $field)) {
return Hash::get($this->_context['defaults'], $field);
}
return Hash::get($this->_context['defaults'], $this->stripNesting($field));
} | php | public function val($field, $options = [])
{
$options += [
'default' => null,
'schemaDefault' => true
];
$val = $this->_request->getData($field);
if ($val !== null) {
return $val;
}
if ($options['default'] !== null || !$options['schemaDefault']) {
return $options['default'];
}
if (empty($this->_context['defaults']) || !is_array($this->_context['defaults'])) {
return null;
}
// Using Hash::check here incase the default value is actually null
if (Hash::check($this->_context['defaults'], $field)) {
return Hash::get($this->_context['defaults'], $field);
}
return Hash::get($this->_context['defaults'], $this->stripNesting($field));
} | [
"public",
"function",
"val",
"(",
"$",
"field",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"+=",
"[",
"'default'",
"=>",
"null",
",",
"'schemaDefault'",
"=>",
"true",
"]",
";",
"$",
"val",
"=",
"$",
"this",
"->",
"_request",
"->",
"getData",
"(",
"$",
"field",
")",
";",
"if",
"(",
"$",
"val",
"!==",
"null",
")",
"{",
"return",
"$",
"val",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'default'",
"]",
"!==",
"null",
"||",
"!",
"$",
"options",
"[",
"'schemaDefault'",
"]",
")",
"{",
"return",
"$",
"options",
"[",
"'default'",
"]",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_context",
"[",
"'defaults'",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"this",
"->",
"_context",
"[",
"'defaults'",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"// Using Hash::check here incase the default value is actually null",
"if",
"(",
"Hash",
"::",
"check",
"(",
"$",
"this",
"->",
"_context",
"[",
"'defaults'",
"]",
",",
"$",
"field",
")",
")",
"{",
"return",
"Hash",
"::",
"get",
"(",
"$",
"this",
"->",
"_context",
"[",
"'defaults'",
"]",
",",
"$",
"field",
")",
";",
"}",
"return",
"Hash",
"::",
"get",
"(",
"$",
"this",
"->",
"_context",
"[",
"'defaults'",
"]",
",",
"$",
"this",
"->",
"stripNesting",
"(",
"$",
"field",
")",
")",
";",
"}"
] | Get the current value for a given field.
This method will coalesce the current request data and the 'defaults'
array.
@param string $field A dot separated path to the field a value
is needed for.
@param array $options Options:
- `default`: Default value to return if no value found in request
data or context record.
- `schemaDefault`: Boolean indicating whether default value from
context's schema should be used if it's not explicitly provided.
@return mixed | [
"Get",
"the",
"current",
"value",
"for",
"a",
"given",
"field",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Form/ArrayContext.php#L169-L193 |
211,504 | cakephp/cakephp | src/View/Form/ArrayContext.php | ArrayContext.hasError | public function hasError($field)
{
if (empty($this->_context['errors'])) {
return false;
}
return (bool)Hash::check($this->_context['errors'], $field);
} | php | public function hasError($field)
{
if (empty($this->_context['errors'])) {
return false;
}
return (bool)Hash::check($this->_context['errors'], $field);
} | [
"public",
"function",
"hasError",
"(",
"$",
"field",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_context",
"[",
"'errors'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
"bool",
")",
"Hash",
"::",
"check",
"(",
"$",
"this",
"->",
"_context",
"[",
"'errors'",
"]",
",",
"$",
"field",
")",
";",
"}"
] | Check whether or not a field has an error attached to it
@param string $field A dot separated path to check errors on.
@return bool Returns true if the errors for the field are not empty. | [
"Check",
"whether",
"or",
"not",
"a",
"field",
"has",
"an",
"error",
"attached",
"to",
"it"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Form/ArrayContext.php#L307-L314 |
211,505 | cakephp/cakephp | src/Core/App.php | App.shortName | public static function shortName($class, $type, $suffix = '')
{
$class = str_replace('\\', '/', $class);
$type = '/' . $type . '/';
$pos = strrpos($class, $type);
$pluginName = substr($class, 0, $pos);
$name = substr($class, $pos + strlen($type));
if ($suffix) {
$name = substr($name, 0, -strlen($suffix));
}
$nonPluginNamespaces = [
'Cake',
str_replace('\\', '/', Configure::read('App.namespace'))
];
if (in_array($pluginName, $nonPluginNamespaces)) {
return $name;
}
return $pluginName . '.' . $name;
} | php | public static function shortName($class, $type, $suffix = '')
{
$class = str_replace('\\', '/', $class);
$type = '/' . $type . '/';
$pos = strrpos($class, $type);
$pluginName = substr($class, 0, $pos);
$name = substr($class, $pos + strlen($type));
if ($suffix) {
$name = substr($name, 0, -strlen($suffix));
}
$nonPluginNamespaces = [
'Cake',
str_replace('\\', '/', Configure::read('App.namespace'))
];
if (in_array($pluginName, $nonPluginNamespaces)) {
return $name;
}
return $pluginName . '.' . $name;
} | [
"public",
"static",
"function",
"shortName",
"(",
"$",
"class",
",",
"$",
"type",
",",
"$",
"suffix",
"=",
"''",
")",
"{",
"$",
"class",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"class",
")",
";",
"$",
"type",
"=",
"'/'",
".",
"$",
"type",
".",
"'/'",
";",
"$",
"pos",
"=",
"strrpos",
"(",
"$",
"class",
",",
"$",
"type",
")",
";",
"$",
"pluginName",
"=",
"substr",
"(",
"$",
"class",
",",
"0",
",",
"$",
"pos",
")",
";",
"$",
"name",
"=",
"substr",
"(",
"$",
"class",
",",
"$",
"pos",
"+",
"strlen",
"(",
"$",
"type",
")",
")",
";",
"if",
"(",
"$",
"suffix",
")",
"{",
"$",
"name",
"=",
"substr",
"(",
"$",
"name",
",",
"0",
",",
"-",
"strlen",
"(",
"$",
"suffix",
")",
")",
";",
"}",
"$",
"nonPluginNamespaces",
"=",
"[",
"'Cake'",
",",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"Configure",
"::",
"read",
"(",
"'App.namespace'",
")",
")",
"]",
";",
"if",
"(",
"in_array",
"(",
"$",
"pluginName",
",",
"$",
"nonPluginNamespaces",
")",
")",
"{",
"return",
"$",
"name",
";",
"}",
"return",
"$",
"pluginName",
".",
"'.'",
".",
"$",
"name",
";",
"}"
] | Returns the plugin split name of a class
Examples:
```
App::shortName(
'SomeVendor\SomePlugin\Controller\Component\TestComponent',
'Controller/Component',
'Component'
)
```
Returns: SomeVendor/SomePlugin.Test
```
App::shortName(
'SomeVendor\SomePlugin\Controller\Component\Subfolder\TestComponent',
'Controller/Component',
'Component'
)
```
Returns: SomeVendor/SomePlugin.Subfolder/Test
```
App::shortName(
'Cake\Controller\Component\AuthComponent',
'Controller/Component',
'Component'
)
```
Returns: Auth
@param string $class Class name
@param string $type Type of class
@param string $suffix Class name suffix
@return string Plugin split name of class | [
"Returns",
"the",
"plugin",
"split",
"name",
"of",
"a",
"class"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/App.php#L117-L139 |
211,506 | cakephp/cakephp | src/Core/App.php | App.path | public static function path($type, $plugin = null)
{
if ($type === 'Plugin') {
return (array)Configure::read('App.paths.plugins');
}
if (empty($plugin) && $type === 'Locale') {
return (array)Configure::read('App.paths.locales');
}
if (empty($plugin) && $type === 'Template') {
return (array)Configure::read('App.paths.templates');
}
if (!empty($plugin)) {
return [Plugin::classPath($plugin) . $type . DIRECTORY_SEPARATOR];
}
return [APP . $type . DIRECTORY_SEPARATOR];
} | php | public static function path($type, $plugin = null)
{
if ($type === 'Plugin') {
return (array)Configure::read('App.paths.plugins');
}
if (empty($plugin) && $type === 'Locale') {
return (array)Configure::read('App.paths.locales');
}
if (empty($plugin) && $type === 'Template') {
return (array)Configure::read('App.paths.templates');
}
if (!empty($plugin)) {
return [Plugin::classPath($plugin) . $type . DIRECTORY_SEPARATOR];
}
return [APP . $type . DIRECTORY_SEPARATOR];
} | [
"public",
"static",
"function",
"path",
"(",
"$",
"type",
",",
"$",
"plugin",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"type",
"===",
"'Plugin'",
")",
"{",
"return",
"(",
"array",
")",
"Configure",
"::",
"read",
"(",
"'App.paths.plugins'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"plugin",
")",
"&&",
"$",
"type",
"===",
"'Locale'",
")",
"{",
"return",
"(",
"array",
")",
"Configure",
"::",
"read",
"(",
"'App.paths.locales'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"plugin",
")",
"&&",
"$",
"type",
"===",
"'Template'",
")",
"{",
"return",
"(",
"array",
")",
"Configure",
"::",
"read",
"(",
"'App.paths.templates'",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"plugin",
")",
")",
"{",
"return",
"[",
"Plugin",
"::",
"classPath",
"(",
"$",
"plugin",
")",
".",
"$",
"type",
".",
"DIRECTORY_SEPARATOR",
"]",
";",
"}",
"return",
"[",
"APP",
".",
"$",
"type",
".",
"DIRECTORY_SEPARATOR",
"]",
";",
"}"
] | Used to read information stored path
Usage:
```
App::path('Plugin');
```
Will return the configured paths for plugins. This is a simpler way to access
the `App.paths.plugins` configure variable.
```
App::path('Model/Datasource', 'MyPlugin');
```
Will return the path for datasources under the 'MyPlugin' plugin.
@param string $type type of path
@param string|null $plugin name of plugin
@return array
@link https://book.cakephp.org/3.0/en/core-libraries/app.html#finding-paths-to-namespaces | [
"Used",
"to",
"read",
"information",
"stored",
"path"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/App.php#L178-L194 |
211,507 | cakephp/cakephp | src/Datasource/QueryCacher.php | QueryCacher.fetch | public function fetch($query)
{
$key = $this->_resolveKey($query);
$storage = $this->_resolveCacher();
$result = $storage->read($key);
if (empty($result)) {
return null;
}
return $result;
} | php | public function fetch($query)
{
$key = $this->_resolveKey($query);
$storage = $this->_resolveCacher();
$result = $storage->read($key);
if (empty($result)) {
return null;
}
return $result;
} | [
"public",
"function",
"fetch",
"(",
"$",
"query",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"_resolveKey",
"(",
"$",
"query",
")",
";",
"$",
"storage",
"=",
"$",
"this",
"->",
"_resolveCacher",
"(",
")",
";",
"$",
"result",
"=",
"$",
"storage",
"->",
"read",
"(",
"$",
"key",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Load the cached results from the cache or run the query.
@param object $query The query the cache read is for.
@return \Cake\Datasource\ResultSetInterface|null Either the cached results or null. | [
"Load",
"the",
"cached",
"results",
"from",
"the",
"cache",
"or",
"run",
"the",
"query",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/QueryCacher.php#L72-L82 |
211,508 | cakephp/cakephp | src/Datasource/QueryCacher.php | QueryCacher.store | public function store($query, Traversable $results)
{
$key = $this->_resolveKey($query);
$storage = $this->_resolveCacher();
return $storage->write($key, $results);
} | php | public function store($query, Traversable $results)
{
$key = $this->_resolveKey($query);
$storage = $this->_resolveCacher();
return $storage->write($key, $results);
} | [
"public",
"function",
"store",
"(",
"$",
"query",
",",
"Traversable",
"$",
"results",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"_resolveKey",
"(",
"$",
"query",
")",
";",
"$",
"storage",
"=",
"$",
"this",
"->",
"_resolveCacher",
"(",
")",
";",
"return",
"$",
"storage",
"->",
"write",
"(",
"$",
"key",
",",
"$",
"results",
")",
";",
"}"
] | Store the result set into the cache.
@param object $query The query the cache read is for.
@param \Traversable $results The result set to store.
@return bool True if the data was successfully cached, false on failure | [
"Store",
"the",
"result",
"set",
"into",
"the",
"cache",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/QueryCacher.php#L91-L97 |
211,509 | cakephp/cakephp | src/Datasource/QueryCacher.php | QueryCacher._resolveCacher | protected function _resolveCacher()
{
if (is_string($this->_config)) {
return Cache::engine($this->_config);
}
return $this->_config;
} | php | protected function _resolveCacher()
{
if (is_string($this->_config)) {
return Cache::engine($this->_config);
}
return $this->_config;
} | [
"protected",
"function",
"_resolveCacher",
"(",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"_config",
")",
")",
"{",
"return",
"Cache",
"::",
"engine",
"(",
"$",
"this",
"->",
"_config",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_config",
";",
"}"
] | Get the cache engine.
@return \Cake\Cache\CacheEngine | [
"Get",
"the",
"cache",
"engine",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/QueryCacher.php#L126-L133 |
211,510 | cakephp/cakephp | src/ORM/Table.php | Table.getTable | public function getTable()
{
if ($this->_table === null) {
$table = namespaceSplit(get_class($this));
$table = substr(end($table), 0, -5);
if (!$table) {
$table = $this->getAlias();
}
$this->_table = Inflector::underscore($table);
}
return $this->_table;
} | php | public function getTable()
{
if ($this->_table === null) {
$table = namespaceSplit(get_class($this));
$table = substr(end($table), 0, -5);
if (!$table) {
$table = $this->getAlias();
}
$this->_table = Inflector::underscore($table);
}
return $this->_table;
} | [
"public",
"function",
"getTable",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_table",
"===",
"null",
")",
"{",
"$",
"table",
"=",
"namespaceSplit",
"(",
"get_class",
"(",
"$",
"this",
")",
")",
";",
"$",
"table",
"=",
"substr",
"(",
"end",
"(",
"$",
"table",
")",
",",
"0",
",",
"-",
"5",
")",
";",
"if",
"(",
"!",
"$",
"table",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getAlias",
"(",
")",
";",
"}",
"$",
"this",
"->",
"_table",
"=",
"Inflector",
"::",
"underscore",
"(",
"$",
"table",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_table",
";",
"}"
] | Returns the database table name.
@return string | [
"Returns",
"the",
"database",
"table",
"name",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L357-L369 |
211,511 | cakephp/cakephp | src/ORM/Table.php | Table.table | public function table($table = null)
{
deprecationWarning(
get_called_class() . '::table() is deprecated. ' .
'Use setTable()/getTable() instead.'
);
if ($table !== null) {
$this->setTable($table);
}
return $this->getTable();
} | php | public function table($table = null)
{
deprecationWarning(
get_called_class() . '::table() is deprecated. ' .
'Use setTable()/getTable() instead.'
);
if ($table !== null) {
$this->setTable($table);
}
return $this->getTable();
} | [
"public",
"function",
"table",
"(",
"$",
"table",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"get_called_class",
"(",
")",
".",
"'::table() is deprecated. '",
".",
"'Use setTable()/getTable() instead.'",
")",
";",
"if",
"(",
"$",
"table",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"setTable",
"(",
"$",
"table",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"}"
] | Returns the database table name or sets a new one.
@deprecated 3.4.0 Use setTable()/getTable() instead.
@param string|null $table the new table name
@return string | [
"Returns",
"the",
"database",
"table",
"name",
"or",
"sets",
"a",
"new",
"one",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L378-L389 |
211,512 | cakephp/cakephp | src/ORM/Table.php | Table.getAlias | public function getAlias()
{
if ($this->_alias === null) {
$alias = namespaceSplit(get_class($this));
$alias = substr(end($alias), 0, -5) ?: $this->_table;
$this->_alias = $alias;
}
return $this->_alias;
} | php | public function getAlias()
{
if ($this->_alias === null) {
$alias = namespaceSplit(get_class($this));
$alias = substr(end($alias), 0, -5) ?: $this->_table;
$this->_alias = $alias;
}
return $this->_alias;
} | [
"public",
"function",
"getAlias",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_alias",
"===",
"null",
")",
"{",
"$",
"alias",
"=",
"namespaceSplit",
"(",
"get_class",
"(",
"$",
"this",
")",
")",
";",
"$",
"alias",
"=",
"substr",
"(",
"end",
"(",
"$",
"alias",
")",
",",
"0",
",",
"-",
"5",
")",
"?",
":",
"$",
"this",
"->",
"_table",
";",
"$",
"this",
"->",
"_alias",
"=",
"$",
"alias",
";",
"}",
"return",
"$",
"this",
"->",
"_alias",
";",
"}"
] | Returns the table alias.
@return string | [
"Returns",
"the",
"table",
"alias",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L409-L418 |
211,513 | cakephp/cakephp | src/ORM/Table.php | Table.getRegistryAlias | public function getRegistryAlias()
{
if ($this->_registryAlias === null) {
$this->_registryAlias = $this->getAlias();
}
return $this->_registryAlias;
} | php | public function getRegistryAlias()
{
if ($this->_registryAlias === null) {
$this->_registryAlias = $this->getAlias();
}
return $this->_registryAlias;
} | [
"public",
"function",
"getRegistryAlias",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_registryAlias",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_registryAlias",
"=",
"$",
"this",
"->",
"getAlias",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_registryAlias",
";",
"}"
] | Returns the table registry key used to create this table instance.
@return string | [
"Returns",
"the",
"table",
"registry",
"key",
"used",
"to",
"create",
"this",
"table",
"instance",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L472-L479 |
211,514 | cakephp/cakephp | src/ORM/Table.php | Table.registryAlias | public function registryAlias($registryAlias = null)
{
deprecationWarning(
get_called_class() . '::registryAlias() is deprecated. ' .
'Use setRegistryAlias()/getRegistryAlias() instead.'
);
if ($registryAlias !== null) {
$this->setRegistryAlias($registryAlias);
}
return $this->getRegistryAlias();
} | php | public function registryAlias($registryAlias = null)
{
deprecationWarning(
get_called_class() . '::registryAlias() is deprecated. ' .
'Use setRegistryAlias()/getRegistryAlias() instead.'
);
if ($registryAlias !== null) {
$this->setRegistryAlias($registryAlias);
}
return $this->getRegistryAlias();
} | [
"public",
"function",
"registryAlias",
"(",
"$",
"registryAlias",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"get_called_class",
"(",
")",
".",
"'::registryAlias() is deprecated. '",
".",
"'Use setRegistryAlias()/getRegistryAlias() instead.'",
")",
";",
"if",
"(",
"$",
"registryAlias",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"setRegistryAlias",
"(",
"$",
"registryAlias",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getRegistryAlias",
"(",
")",
";",
"}"
] | Returns the table registry key used to create this table instance or sets one.
@deprecated 3.4.0 Use setRegistryAlias()/getRegistryAlias() instead.
@param string|null $registryAlias the key used to access this object
@return string | [
"Returns",
"the",
"table",
"registry",
"key",
"used",
"to",
"create",
"this",
"table",
"instance",
"or",
"sets",
"one",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L488-L499 |
211,515 | cakephp/cakephp | src/ORM/Table.php | Table.connection | public function connection(ConnectionInterface $connection = null)
{
deprecationWarning(
get_called_class() . '::connection() is deprecated. ' .
'Use setConnection()/getConnection() instead.'
);
if ($connection !== null) {
$this->setConnection($connection);
}
return $this->getConnection();
} | php | public function connection(ConnectionInterface $connection = null)
{
deprecationWarning(
get_called_class() . '::connection() is deprecated. ' .
'Use setConnection()/getConnection() instead.'
);
if ($connection !== null) {
$this->setConnection($connection);
}
return $this->getConnection();
} | [
"public",
"function",
"connection",
"(",
"ConnectionInterface",
"$",
"connection",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"get_called_class",
"(",
")",
".",
"'::connection() is deprecated. '",
".",
"'Use setConnection()/getConnection() instead.'",
")",
";",
"if",
"(",
"$",
"connection",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"setConnection",
"(",
"$",
"connection",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getConnection",
"(",
")",
";",
"}"
] | Returns the connection instance or sets a new one
@deprecated 3.4.0 Use setConnection()/getConnection() instead.
@param \Cake\Datasource\ConnectionInterface|null $connection The new connection instance
@return \Cake\Datasource\ConnectionInterface | [
"Returns",
"the",
"connection",
"instance",
"or",
"sets",
"a",
"new",
"one"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L531-L542 |
211,516 | cakephp/cakephp | src/ORM/Table.php | Table.setSchema | public function setSchema($schema)
{
if (is_array($schema)) {
$constraints = [];
if (isset($schema['_constraints'])) {
$constraints = $schema['_constraints'];
unset($schema['_constraints']);
}
$schema = new TableSchema($this->getTable(), $schema);
foreach ($constraints as $name => $value) {
$schema->addConstraint($name, $value);
}
}
$this->_schema = $schema;
return $this;
} | php | public function setSchema($schema)
{
if (is_array($schema)) {
$constraints = [];
if (isset($schema['_constraints'])) {
$constraints = $schema['_constraints'];
unset($schema['_constraints']);
}
$schema = new TableSchema($this->getTable(), $schema);
foreach ($constraints as $name => $value) {
$schema->addConstraint($name, $value);
}
}
$this->_schema = $schema;
return $this;
} | [
"public",
"function",
"setSchema",
"(",
"$",
"schema",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"schema",
")",
")",
"{",
"$",
"constraints",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"schema",
"[",
"'_constraints'",
"]",
")",
")",
"{",
"$",
"constraints",
"=",
"$",
"schema",
"[",
"'_constraints'",
"]",
";",
"unset",
"(",
"$",
"schema",
"[",
"'_constraints'",
"]",
")",
";",
"}",
"$",
"schema",
"=",
"new",
"TableSchema",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
",",
"$",
"schema",
")",
";",
"foreach",
"(",
"$",
"constraints",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"schema",
"->",
"addConstraint",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"}",
"$",
"this",
"->",
"_schema",
"=",
"$",
"schema",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the schema table object describing this table's properties.
If an array is passed, a new TableSchema will be constructed
out of it and used as the schema for this table.
@param array|\Cake\Database\Schema\TableSchema $schema Schema to be used for this table
@return $this | [
"Sets",
"the",
"schema",
"table",
"object",
"describing",
"this",
"table",
"s",
"properties",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L571-L591 |
211,517 | cakephp/cakephp | src/ORM/Table.php | Table.getPrimaryKey | public function getPrimaryKey()
{
if ($this->_primaryKey === null) {
$key = (array)$this->getSchema()->primaryKey();
if (count($key) === 1) {
$key = $key[0];
}
$this->_primaryKey = $key;
}
return $this->_primaryKey;
} | php | public function getPrimaryKey()
{
if ($this->_primaryKey === null) {
$key = (array)$this->getSchema()->primaryKey();
if (count($key) === 1) {
$key = $key[0];
}
$this->_primaryKey = $key;
}
return $this->_primaryKey;
} | [
"public",
"function",
"getPrimaryKey",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_primaryKey",
"===",
"null",
")",
"{",
"$",
"key",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"getSchema",
"(",
")",
"->",
"primaryKey",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"key",
")",
"===",
"1",
")",
"{",
"$",
"key",
"=",
"$",
"key",
"[",
"0",
"]",
";",
"}",
"$",
"this",
"->",
"_primaryKey",
"=",
"$",
"key",
";",
"}",
"return",
"$",
"this",
"->",
"_primaryKey",
";",
"}"
] | Returns the primary key field name.
@return string|array | [
"Returns",
"the",
"primary",
"key",
"field",
"name",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L677-L688 |
211,518 | cakephp/cakephp | src/ORM/Table.php | Table.getDisplayField | public function getDisplayField()
{
if ($this->_displayField === null) {
$schema = $this->getSchema();
$primary = (array)$this->getPrimaryKey();
$this->_displayField = array_shift($primary);
if ($schema->getColumn('title')) {
$this->_displayField = 'title';
}
if ($schema->getColumn('name')) {
$this->_displayField = 'name';
}
}
return $this->_displayField;
} | php | public function getDisplayField()
{
if ($this->_displayField === null) {
$schema = $this->getSchema();
$primary = (array)$this->getPrimaryKey();
$this->_displayField = array_shift($primary);
if ($schema->getColumn('title')) {
$this->_displayField = 'title';
}
if ($schema->getColumn('name')) {
$this->_displayField = 'name';
}
}
return $this->_displayField;
} | [
"public",
"function",
"getDisplayField",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_displayField",
"===",
"null",
")",
"{",
"$",
"schema",
"=",
"$",
"this",
"->",
"getSchema",
"(",
")",
";",
"$",
"primary",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"getPrimaryKey",
"(",
")",
";",
"$",
"this",
"->",
"_displayField",
"=",
"array_shift",
"(",
"$",
"primary",
")",
";",
"if",
"(",
"$",
"schema",
"->",
"getColumn",
"(",
"'title'",
")",
")",
"{",
"$",
"this",
"->",
"_displayField",
"=",
"'title'",
";",
"}",
"if",
"(",
"$",
"schema",
"->",
"getColumn",
"(",
"'name'",
")",
")",
"{",
"$",
"this",
"->",
"_displayField",
"=",
"'name'",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"_displayField",
";",
"}"
] | Returns the display field.
@return string | [
"Returns",
"the",
"display",
"field",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L728-L743 |
211,519 | cakephp/cakephp | src/ORM/Table.php | Table.getEntityClass | public function getEntityClass()
{
if (!$this->_entityClass) {
$default = Entity::class;
$self = get_called_class();
$parts = explode('\\', $self);
if ($self === __CLASS__ || count($parts) < 3) {
return $this->_entityClass = $default;
}
$alias = Inflector::classify(Inflector::underscore(substr(array_pop($parts), 0, -5)));
$name = implode('\\', array_slice($parts, 0, -1)) . '\\Entity\\' . $alias;
if (!class_exists($name)) {
return $this->_entityClass = $default;
}
$class = App::className($name, 'Model/Entity');
if (!$class) {
throw new MissingEntityException([$name]);
}
$this->_entityClass = $class;
}
return $this->_entityClass;
} | php | public function getEntityClass()
{
if (!$this->_entityClass) {
$default = Entity::class;
$self = get_called_class();
$parts = explode('\\', $self);
if ($self === __CLASS__ || count($parts) < 3) {
return $this->_entityClass = $default;
}
$alias = Inflector::classify(Inflector::underscore(substr(array_pop($parts), 0, -5)));
$name = implode('\\', array_slice($parts, 0, -1)) . '\\Entity\\' . $alias;
if (!class_exists($name)) {
return $this->_entityClass = $default;
}
$class = App::className($name, 'Model/Entity');
if (!$class) {
throw new MissingEntityException([$name]);
}
$this->_entityClass = $class;
}
return $this->_entityClass;
} | [
"public",
"function",
"getEntityClass",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_entityClass",
")",
"{",
"$",
"default",
"=",
"Entity",
"::",
"class",
";",
"$",
"self",
"=",
"get_called_class",
"(",
")",
";",
"$",
"parts",
"=",
"explode",
"(",
"'\\\\'",
",",
"$",
"self",
")",
";",
"if",
"(",
"$",
"self",
"===",
"__CLASS__",
"||",
"count",
"(",
"$",
"parts",
")",
"<",
"3",
")",
"{",
"return",
"$",
"this",
"->",
"_entityClass",
"=",
"$",
"default",
";",
"}",
"$",
"alias",
"=",
"Inflector",
"::",
"classify",
"(",
"Inflector",
"::",
"underscore",
"(",
"substr",
"(",
"array_pop",
"(",
"$",
"parts",
")",
",",
"0",
",",
"-",
"5",
")",
")",
")",
";",
"$",
"name",
"=",
"implode",
"(",
"'\\\\'",
",",
"array_slice",
"(",
"$",
"parts",
",",
"0",
",",
"-",
"1",
")",
")",
".",
"'\\\\Entity\\\\'",
".",
"$",
"alias",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_entityClass",
"=",
"$",
"default",
";",
"}",
"$",
"class",
"=",
"App",
"::",
"className",
"(",
"$",
"name",
",",
"'Model/Entity'",
")",
";",
"if",
"(",
"!",
"$",
"class",
")",
"{",
"throw",
"new",
"MissingEntityException",
"(",
"[",
"$",
"name",
"]",
")",
";",
"}",
"$",
"this",
"->",
"_entityClass",
"=",
"$",
"class",
";",
"}",
"return",
"$",
"this",
"->",
"_entityClass",
";",
"}"
] | Returns the class used to hydrate rows for this table.
@return string | [
"Returns",
"the",
"class",
"used",
"to",
"hydrate",
"rows",
"for",
"this",
"table",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L772-L798 |
211,520 | cakephp/cakephp | src/ORM/Table.php | Table.setEntityClass | public function setEntityClass($name)
{
$class = App::className($name, 'Model/Entity');
if (!$class) {
throw new MissingEntityException([$name]);
}
$this->_entityClass = $class;
return $this;
} | php | public function setEntityClass($name)
{
$class = App::className($name, 'Model/Entity');
if (!$class) {
throw new MissingEntityException([$name]);
}
$this->_entityClass = $class;
return $this;
} | [
"public",
"function",
"setEntityClass",
"(",
"$",
"name",
")",
"{",
"$",
"class",
"=",
"App",
"::",
"className",
"(",
"$",
"name",
",",
"'Model/Entity'",
")",
";",
"if",
"(",
"!",
"$",
"class",
")",
"{",
"throw",
"new",
"MissingEntityException",
"(",
"[",
"$",
"name",
"]",
")",
";",
"}",
"$",
"this",
"->",
"_entityClass",
"=",
"$",
"class",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the class used to hydrate rows for this table.
@param string $name The name of the class to use
@throws \Cake\ORM\Exception\MissingEntityException when the entity class cannot be found
@return $this | [
"Sets",
"the",
"class",
"used",
"to",
"hydrate",
"rows",
"for",
"this",
"table",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L807-L817 |
211,521 | cakephp/cakephp | src/ORM/Table.php | Table.entityClass | public function entityClass($name = null)
{
deprecationWarning(
get_called_class() . '::entityClass() is deprecated. ' .
'Use setEntityClass()/getEntityClass() instead.'
);
if ($name !== null) {
$this->setEntityClass($name);
}
return $this->getEntityClass();
} | php | public function entityClass($name = null)
{
deprecationWarning(
get_called_class() . '::entityClass() is deprecated. ' .
'Use setEntityClass()/getEntityClass() instead.'
);
if ($name !== null) {
$this->setEntityClass($name);
}
return $this->getEntityClass();
} | [
"public",
"function",
"entityClass",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"get_called_class",
"(",
")",
".",
"'::entityClass() is deprecated. '",
".",
"'Use setEntityClass()/getEntityClass() instead.'",
")",
";",
"if",
"(",
"$",
"name",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"setEntityClass",
"(",
"$",
"name",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getEntityClass",
"(",
")",
";",
"}"
] | Returns the class used to hydrate rows for this table or sets
a new one
@deprecated 3.4.0 Use setEntityClass()/getEntityClass() instead.
@param string|null $name The name of the class to use
@throws \Cake\ORM\Exception\MissingEntityException when the entity class cannot be found
@return string | [
"Returns",
"the",
"class",
"used",
"to",
"hydrate",
"rows",
"for",
"this",
"table",
"or",
"sets",
"a",
"new",
"one"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L828-L839 |
211,522 | cakephp/cakephp | src/ORM/Table.php | Table.addBehaviors | public function addBehaviors(array $behaviors)
{
foreach ($behaviors as $name => $options) {
if (is_int($name)) {
$name = $options;
$options = [];
}
$this->addBehavior($name, $options);
}
return $this;
} | php | public function addBehaviors(array $behaviors)
{
foreach ($behaviors as $name => $options) {
if (is_int($name)) {
$name = $options;
$options = [];
}
$this->addBehavior($name, $options);
}
return $this;
} | [
"public",
"function",
"addBehaviors",
"(",
"array",
"$",
"behaviors",
")",
"{",
"foreach",
"(",
"$",
"behaviors",
"as",
"$",
"name",
"=>",
"$",
"options",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"name",
")",
")",
"{",
"$",
"name",
"=",
"$",
"options",
";",
"$",
"options",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"addBehavior",
"(",
"$",
"name",
",",
"$",
"options",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Adds an array of behaviors to the table's behavior collection.
Example:
```
$this->addBehaviors([
'Timestamp',
'Tree' => ['level' => 'level'],
]);
```
@param array $behaviors All of the behaviors to load.
@return $this
@throws \RuntimeException If a behavior is being reloaded. | [
"Adds",
"an",
"array",
"of",
"behaviors",
"to",
"the",
"table",
"s",
"behavior",
"collection",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L888-L900 |
211,523 | cakephp/cakephp | src/ORM/Table.php | Table.getBehavior | public function getBehavior($name)
{
/** @var \Cake\ORM\Behavior $behavior */
$behavior = $this->_behaviors->get($name);
if ($behavior === null) {
throw new InvalidArgumentException(sprintf(
'The %s behavior is not defined on %s.',
$name,
get_class($this)
));
}
return $behavior;
} | php | public function getBehavior($name)
{
/** @var \Cake\ORM\Behavior $behavior */
$behavior = $this->_behaviors->get($name);
if ($behavior === null) {
throw new InvalidArgumentException(sprintf(
'The %s behavior is not defined on %s.',
$name,
get_class($this)
));
}
return $behavior;
} | [
"public",
"function",
"getBehavior",
"(",
"$",
"name",
")",
"{",
"/** @var \\Cake\\ORM\\Behavior $behavior */",
"$",
"behavior",
"=",
"$",
"this",
"->",
"_behaviors",
"->",
"get",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"behavior",
"===",
"null",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The %s behavior is not defined on %s.'",
",",
"$",
"name",
",",
"get_class",
"(",
"$",
"this",
")",
")",
")",
";",
"}",
"return",
"$",
"behavior",
";",
"}"
] | Get a behavior from the registry.
@param string $name The behavior alias to get from the registry.
@return \Cake\ORM\Behavior
@throws \InvalidArgumentException If the behavior does not exist. | [
"Get",
"a",
"behavior",
"from",
"the",
"registry",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L941-L954 |
211,524 | cakephp/cakephp | src/ORM/Table.php | Table.findAssociation | protected function findAssociation($name)
{
if (strpos($name, '.') === false) {
return $this->_associations->get($name);
}
list($name, $next) = array_pad(explode('.', $name, 2), 2, null);
$result = $this->_associations->get($name);
if ($result !== null && $next !== null) {
$result = $result->getTarget()->getAssociation($next);
}
return $result;
} | php | protected function findAssociation($name)
{
if (strpos($name, '.') === false) {
return $this->_associations->get($name);
}
list($name, $next) = array_pad(explode('.', $name, 2), 2, null);
$result = $this->_associations->get($name);
if ($result !== null && $next !== null) {
$result = $result->getTarget()->getAssociation($next);
}
return $result;
} | [
"protected",
"function",
"findAssociation",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"name",
",",
"'.'",
")",
"===",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"_associations",
"->",
"get",
"(",
"$",
"name",
")",
";",
"}",
"list",
"(",
"$",
"name",
",",
"$",
"next",
")",
"=",
"array_pad",
"(",
"explode",
"(",
"'.'",
",",
"$",
"name",
",",
"2",
")",
",",
"2",
",",
"null",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"_associations",
"->",
"get",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"result",
"!==",
"null",
"&&",
"$",
"next",
"!==",
"null",
")",
"{",
"$",
"result",
"=",
"$",
"result",
"->",
"getTarget",
"(",
")",
"->",
"getAssociation",
"(",
"$",
"next",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns an association object configured for the specified alias if any.
The name argument also supports dot syntax to access deeper associations.
```
$users = $this->getAssociation('Articles.Comments.Users');
```
@param string $name The alias used for the association.
@return \Cake\ORM\Association|null Either the association or null. | [
"Returns",
"an",
"association",
"object",
"configured",
"for",
"the",
"specified",
"alias",
"if",
"any",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L1037-L1051 |
211,525 | cakephp/cakephp | src/ORM/Table.php | Table.addAssociations | public function addAssociations(array $params)
{
foreach ($params as $assocType => $tables) {
foreach ($tables as $associated => $options) {
if (is_numeric($associated)) {
$associated = $options;
$options = [];
}
$this->{$assocType}($associated, $options);
}
}
return $this;
} | php | public function addAssociations(array $params)
{
foreach ($params as $assocType => $tables) {
foreach ($tables as $associated => $options) {
if (is_numeric($associated)) {
$associated = $options;
$options = [];
}
$this->{$assocType}($associated, $options);
}
}
return $this;
} | [
"public",
"function",
"addAssociations",
"(",
"array",
"$",
"params",
")",
"{",
"foreach",
"(",
"$",
"params",
"as",
"$",
"assocType",
"=>",
"$",
"tables",
")",
"{",
"foreach",
"(",
"$",
"tables",
"as",
"$",
"associated",
"=>",
"$",
"options",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"associated",
")",
")",
"{",
"$",
"associated",
"=",
"$",
"options",
";",
"$",
"options",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"{",
"$",
"assocType",
"}",
"(",
"$",
"associated",
",",
"$",
"options",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Setup multiple associations.
It takes an array containing set of table names indexed by association type
as argument:
```
$this->Posts->addAssociations([
'belongsTo' => [
'Users' => ['className' => 'App\Model\Table\UsersTable']
],
'hasMany' => ['Comments'],
'belongsToMany' => ['Tags']
]);
```
Each association type accepts multiple associations where the keys
are the aliases, and the values are association config data. If numeric
keys are used the values will be treated as association aliases.
@param array $params Set of associations to bind (indexed by association type)
@return $this
@see \Cake\ORM\Table::belongsTo()
@see \Cake\ORM\Table::hasOne()
@see \Cake\ORM\Table::hasMany()
@see \Cake\ORM\Table::belongsToMany() | [
"Setup",
"multiple",
"associations",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L1090-L1103 |
211,526 | cakephp/cakephp | src/ORM/Table.php | Table.belongsTo | public function belongsTo($associated, array $options = [])
{
$options += ['sourceTable' => $this];
/** @var \Cake\ORM\Association\BelongsTo $association */
$association = $this->_associations->load(BelongsTo::class, $associated, $options);
return $association;
} | php | public function belongsTo($associated, array $options = [])
{
$options += ['sourceTable' => $this];
/** @var \Cake\ORM\Association\BelongsTo $association */
$association = $this->_associations->load(BelongsTo::class, $associated, $options);
return $association;
} | [
"public",
"function",
"belongsTo",
"(",
"$",
"associated",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"+=",
"[",
"'sourceTable'",
"=>",
"$",
"this",
"]",
";",
"/** @var \\Cake\\ORM\\Association\\BelongsTo $association */",
"$",
"association",
"=",
"$",
"this",
"->",
"_associations",
"->",
"load",
"(",
"BelongsTo",
"::",
"class",
",",
"$",
"associated",
",",
"$",
"options",
")",
";",
"return",
"$",
"association",
";",
"}"
] | Creates a new BelongsTo association between this table and a target
table. A "belongs to" association is a N-1 relationship where this table
is the N side, and where there is a single associated record in the target
table for each one in this table.
Target table can be inferred by its name, which is provided in the
first argument, or you can either pass the to be instantiated or
an instance of it directly.
The options array accept the following keys:
- className: The class name of the target table object
- targetTable: An instance of a table object to be used as the target table
- foreignKey: The name of the field to use as foreign key, if false none
will be used
- conditions: array with a list of conditions to filter the join with
- joinType: The type of join to be used (e.g. INNER)
- strategy: The loading strategy to use. 'join' and 'select' are supported.
- finder: The finder method to use when loading records from this association.
Defaults to 'all'. When the strategy is 'join', only the fields, containments,
and where conditions will be used from the finder.
This method will return the association object that was built.
@param string $associated the alias for the target table. This is used to
uniquely identify the association
@param array $options list of options to configure the association definition
@return \Cake\ORM\Association\BelongsTo | [
"Creates",
"a",
"new",
"BelongsTo",
"association",
"between",
"this",
"table",
"and",
"a",
"target",
"table",
".",
"A",
"belongs",
"to",
"association",
"is",
"a",
"N",
"-",
"1",
"relationship",
"where",
"this",
"table",
"is",
"the",
"N",
"side",
"and",
"where",
"there",
"is",
"a",
"single",
"associated",
"record",
"in",
"the",
"target",
"table",
"for",
"each",
"one",
"in",
"this",
"table",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L1135-L1143 |
211,527 | cakephp/cakephp | src/ORM/Table.php | Table.hasOne | public function hasOne($associated, array $options = [])
{
$options += ['sourceTable' => $this];
/** @var \Cake\ORM\Association\HasOne $association */
$association = $this->_associations->load(HasOne::class, $associated, $options);
return $association;
} | php | public function hasOne($associated, array $options = [])
{
$options += ['sourceTable' => $this];
/** @var \Cake\ORM\Association\HasOne $association */
$association = $this->_associations->load(HasOne::class, $associated, $options);
return $association;
} | [
"public",
"function",
"hasOne",
"(",
"$",
"associated",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"+=",
"[",
"'sourceTable'",
"=>",
"$",
"this",
"]",
";",
"/** @var \\Cake\\ORM\\Association\\HasOne $association */",
"$",
"association",
"=",
"$",
"this",
"->",
"_associations",
"->",
"load",
"(",
"HasOne",
"::",
"class",
",",
"$",
"associated",
",",
"$",
"options",
")",
";",
"return",
"$",
"association",
";",
"}"
] | Creates a new HasOne association between this table and a target
table. A "has one" association is a 1-1 relationship.
Target table can be inferred by its name, which is provided in the
first argument, or you can either pass the class name to be instantiated or
an instance of it directly.
The options array accept the following keys:
- className: The class name of the target table object
- targetTable: An instance of a table object to be used as the target table
- foreignKey: The name of the field to use as foreign key, if false none
will be used
- dependent: Set to true if you want CakePHP to cascade deletes to the
associated table when an entity is removed on this table. The delete operation
on the associated table will not cascade further. To get recursive cascades enable
`cascadeCallbacks` as well. Set to false if you don't want CakePHP to remove
associated data, or when you are using database constraints.
- cascadeCallbacks: Set to true if you want CakePHP to fire callbacks on
cascaded deletes. If false the ORM will use deleteAll() to remove data.
When true records will be loaded and then deleted.
- conditions: array with a list of conditions to filter the join with
- joinType: The type of join to be used (e.g. LEFT)
- strategy: The loading strategy to use. 'join' and 'select' are supported.
- finder: The finder method to use when loading records from this association.
Defaults to 'all'. When the strategy is 'join', only the fields, containments,
and where conditions will be used from the finder.
This method will return the association object that was built.
@param string $associated the alias for the target table. This is used to
uniquely identify the association
@param array $options list of options to configure the association definition
@return \Cake\ORM\Association\HasOne | [
"Creates",
"a",
"new",
"HasOne",
"association",
"between",
"this",
"table",
"and",
"a",
"target",
"table",
".",
"A",
"has",
"one",
"association",
"is",
"a",
"1",
"-",
"1",
"relationship",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L1181-L1189 |
211,528 | cakephp/cakephp | src/ORM/Table.php | Table.hasMany | public function hasMany($associated, array $options = [])
{
$options += ['sourceTable' => $this];
/** @var \Cake\ORM\Association\HasMany $association */
$association = $this->_associations->load(HasMany::class, $associated, $options);
return $association;
} | php | public function hasMany($associated, array $options = [])
{
$options += ['sourceTable' => $this];
/** @var \Cake\ORM\Association\HasMany $association */
$association = $this->_associations->load(HasMany::class, $associated, $options);
return $association;
} | [
"public",
"function",
"hasMany",
"(",
"$",
"associated",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"+=",
"[",
"'sourceTable'",
"=>",
"$",
"this",
"]",
";",
"/** @var \\Cake\\ORM\\Association\\HasMany $association */",
"$",
"association",
"=",
"$",
"this",
"->",
"_associations",
"->",
"load",
"(",
"HasMany",
"::",
"class",
",",
"$",
"associated",
",",
"$",
"options",
")",
";",
"return",
"$",
"association",
";",
"}"
] | Creates a new HasMany association between this table and a target
table. A "has many" association is a 1-N relationship.
Target table can be inferred by its name, which is provided in the
first argument, or you can either pass the class name to be instantiated or
an instance of it directly.
The options array accept the following keys:
- className: The class name of the target table object
- targetTable: An instance of a table object to be used as the target table
- foreignKey: The name of the field to use as foreign key, if false none
will be used
- dependent: Set to true if you want CakePHP to cascade deletes to the
associated table when an entity is removed on this table. The delete operation
on the associated table will not cascade further. To get recursive cascades enable
`cascadeCallbacks` as well. Set to false if you don't want CakePHP to remove
associated data, or when you are using database constraints.
- cascadeCallbacks: Set to true if you want CakePHP to fire callbacks on
cascaded deletes. If false the ORM will use deleteAll() to remove data.
When true records will be loaded and then deleted.
- conditions: array with a list of conditions to filter the join with
- sort: The order in which results for this association should be returned
- saveStrategy: Either 'append' or 'replace'. When 'append' the current records
are appended to any records in the database. When 'replace' associated records
not in the current set will be removed. If the foreign key is a null able column
or if `dependent` is true records will be orphaned.
- strategy: The strategy to be used for selecting results Either 'select'
or 'subquery'. If subquery is selected the query used to return results
in the source table will be used as conditions for getting rows in the
target table.
- finder: The finder method to use when loading records from this association.
Defaults to 'all'.
This method will return the association object that was built.
@param string $associated the alias for the target table. This is used to
uniquely identify the association
@param array $options list of options to configure the association definition
@return \Cake\ORM\Association\HasMany | [
"Creates",
"a",
"new",
"HasMany",
"association",
"between",
"this",
"table",
"and",
"a",
"target",
"table",
".",
"A",
"has",
"many",
"association",
"is",
"a",
"1",
"-",
"N",
"relationship",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L1233-L1241 |
211,529 | cakephp/cakephp | src/ORM/Table.php | Table.belongsToMany | public function belongsToMany($associated, array $options = [])
{
$options += ['sourceTable' => $this];
/** @var \Cake\ORM\Association\BelongsToMany $association */
$association = $this->_associations->load(BelongsToMany::class, $associated, $options);
return $association;
} | php | public function belongsToMany($associated, array $options = [])
{
$options += ['sourceTable' => $this];
/** @var \Cake\ORM\Association\BelongsToMany $association */
$association = $this->_associations->load(BelongsToMany::class, $associated, $options);
return $association;
} | [
"public",
"function",
"belongsToMany",
"(",
"$",
"associated",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"+=",
"[",
"'sourceTable'",
"=>",
"$",
"this",
"]",
";",
"/** @var \\Cake\\ORM\\Association\\BelongsToMany $association */",
"$",
"association",
"=",
"$",
"this",
"->",
"_associations",
"->",
"load",
"(",
"BelongsToMany",
"::",
"class",
",",
"$",
"associated",
",",
"$",
"options",
")",
";",
"return",
"$",
"association",
";",
"}"
] | Creates a new BelongsToMany association between this table and a target
table. A "belongs to many" association is a M-N relationship.
Target table can be inferred by its name, which is provided in the
first argument, or you can either pass the class name to be instantiated or
an instance of it directly.
The options array accept the following keys:
- className: The class name of the target table object.
- targetTable: An instance of a table object to be used as the target table.
- foreignKey: The name of the field to use as foreign key.
- targetForeignKey: The name of the field to use as the target foreign key.
- joinTable: The name of the table representing the link between the two
- through: If you choose to use an already instantiated link table, set this
key to a configured Table instance containing associations to both the source
and target tables in this association.
- dependent: Set to false, if you do not want junction table records removed
when an owning record is removed.
- cascadeCallbacks: Set to true if you want CakePHP to fire callbacks on
cascaded deletes. If false the ORM will use deleteAll() to remove data.
When true join/junction table records will be loaded and then deleted.
- conditions: array with a list of conditions to filter the join with.
- sort: The order in which results for this association should be returned.
- strategy: The strategy to be used for selecting results Either 'select'
or 'subquery'. If subquery is selected the query used to return results
in the source table will be used as conditions for getting rows in the
target table.
- saveStrategy: Either 'append' or 'replace'. Indicates the mode to be used
for saving associated entities. The former will only create new links
between both side of the relation and the latter will do a wipe and
replace to create the links between the passed entities when saving.
- strategy: The loading strategy to use. 'select' and 'subquery' are supported.
- finder: The finder method to use when loading records from this association.
Defaults to 'all'.
This method will return the association object that was built.
@param string $associated the alias for the target table. This is used to
uniquely identify the association
@param array $options list of options to configure the association definition
@return \Cake\ORM\Association\BelongsToMany | [
"Creates",
"a",
"new",
"BelongsToMany",
"association",
"between",
"this",
"table",
"and",
"a",
"target",
"table",
".",
"A",
"belongs",
"to",
"many",
"association",
"is",
"a",
"M",
"-",
"N",
"relationship",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L1287-L1295 |
211,530 | cakephp/cakephp | src/ORM/Table.php | Table.findThreaded | public function findThreaded(Query $query, array $options)
{
$options += [
'keyField' => $this->getPrimaryKey(),
'parentField' => 'parent_id',
'nestingKey' => 'children'
];
if (isset($options['idField'])) {
$options['keyField'] = $options['idField'];
unset($options['idField']);
deprecationWarning('Option "idField" is deprecated, use "keyField" instead.');
}
$options = $this->_setFieldMatchers($options, ['keyField', 'parentField']);
return $query->formatResults(function ($results) use ($options) {
/** @var \Cake\Collection\CollectionInterface $results */
return $results->nest($options['keyField'], $options['parentField'], $options['nestingKey']);
});
} | php | public function findThreaded(Query $query, array $options)
{
$options += [
'keyField' => $this->getPrimaryKey(),
'parentField' => 'parent_id',
'nestingKey' => 'children'
];
if (isset($options['idField'])) {
$options['keyField'] = $options['idField'];
unset($options['idField']);
deprecationWarning('Option "idField" is deprecated, use "keyField" instead.');
}
$options = $this->_setFieldMatchers($options, ['keyField', 'parentField']);
return $query->formatResults(function ($results) use ($options) {
/** @var \Cake\Collection\CollectionInterface $results */
return $results->nest($options['keyField'], $options['parentField'], $options['nestingKey']);
});
} | [
"public",
"function",
"findThreaded",
"(",
"Query",
"$",
"query",
",",
"array",
"$",
"options",
")",
"{",
"$",
"options",
"+=",
"[",
"'keyField'",
"=>",
"$",
"this",
"->",
"getPrimaryKey",
"(",
")",
",",
"'parentField'",
"=>",
"'parent_id'",
",",
"'nestingKey'",
"=>",
"'children'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'idField'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'keyField'",
"]",
"=",
"$",
"options",
"[",
"'idField'",
"]",
";",
"unset",
"(",
"$",
"options",
"[",
"'idField'",
"]",
")",
";",
"deprecationWarning",
"(",
"'Option \"idField\" is deprecated, use \"keyField\" instead.'",
")",
";",
"}",
"$",
"options",
"=",
"$",
"this",
"->",
"_setFieldMatchers",
"(",
"$",
"options",
",",
"[",
"'keyField'",
",",
"'parentField'",
"]",
")",
";",
"return",
"$",
"query",
"->",
"formatResults",
"(",
"function",
"(",
"$",
"results",
")",
"use",
"(",
"$",
"options",
")",
"{",
"/** @var \\Cake\\Collection\\CollectionInterface $results */",
"return",
"$",
"results",
"->",
"nest",
"(",
"$",
"options",
"[",
"'keyField'",
"]",
",",
"$",
"options",
"[",
"'parentField'",
"]",
",",
"$",
"options",
"[",
"'nestingKey'",
"]",
")",
";",
"}",
")",
";",
"}"
] | Results for this finder will be a nested array, and is appropriate if you want
to use the parent_id field of your model data to build nested results.
Values belonging to a parent row based on their parent_id value will be
recursively nested inside the parent row values using the `children` property
You can customize what fields are used for nesting results, by default the
primary key and the `parent_id` fields are used. If you wish to change
these defaults you need to provide the keys `keyField`, `parentField` or `nestingKey` in
`$options`:
```
$table->find('threaded', [
'keyField' => 'id',
'parentField' => 'ancestor_id'
'nestingKey' => 'children'
]);
```
@param \Cake\ORM\Query $query The query to find with
@param array $options The options to find with
@return \Cake\ORM\Query The query builder | [
"Results",
"for",
"this",
"finder",
"will",
"be",
"a",
"nested",
"array",
"and",
"is",
"appropriate",
"if",
"you",
"want",
"to",
"use",
"the",
"parent_id",
"field",
"of",
"your",
"model",
"data",
"to",
"build",
"nested",
"results",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L1504-L1524 |
211,531 | cakephp/cakephp | src/ORM/Table.php | Table._executeTransaction | protected function _executeTransaction(callable $worker, $atomic = true)
{
if ($atomic) {
return $this->getConnection()->transactional(function () use ($worker) {
return $worker();
});
}
return $worker();
} | php | protected function _executeTransaction(callable $worker, $atomic = true)
{
if ($atomic) {
return $this->getConnection()->transactional(function () use ($worker) {
return $worker();
});
}
return $worker();
} | [
"protected",
"function",
"_executeTransaction",
"(",
"callable",
"$",
"worker",
",",
"$",
"atomic",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"atomic",
")",
"{",
"return",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"transactional",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"worker",
")",
"{",
"return",
"$",
"worker",
"(",
")",
";",
"}",
")",
";",
"}",
"return",
"$",
"worker",
"(",
")",
";",
"}"
] | Handles the logic executing of a worker inside a transaction.
@param callable $worker The worker that will run inside the transaction.
@param bool $atomic Whether to execute the worker inside a database transaction.
@return mixed | [
"Handles",
"the",
"logic",
"executing",
"of",
"a",
"worker",
"inside",
"a",
"transaction",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L1630-L1639 |
211,532 | cakephp/cakephp | src/ORM/Table.php | Table.saveOrFail | public function saveOrFail(EntityInterface $entity, $options = [])
{
$saved = $this->save($entity, $options);
if ($saved === false) {
throw new PersistenceFailedException($entity, ['save']);
}
return $saved;
} | php | public function saveOrFail(EntityInterface $entity, $options = [])
{
$saved = $this->save($entity, $options);
if ($saved === false) {
throw new PersistenceFailedException($entity, ['save']);
}
return $saved;
} | [
"public",
"function",
"saveOrFail",
"(",
"EntityInterface",
"$",
"entity",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"saved",
"=",
"$",
"this",
"->",
"save",
"(",
"$",
"entity",
",",
"$",
"options",
")",
";",
"if",
"(",
"$",
"saved",
"===",
"false",
")",
"{",
"throw",
"new",
"PersistenceFailedException",
"(",
"$",
"entity",
",",
"[",
"'save'",
"]",
")",
";",
"}",
"return",
"$",
"saved",
";",
"}"
] | Try to save an entity or throw a PersistenceFailedException if the application rules checks failed,
the entity contains errors or the save was aborted by a callback.
@param \Cake\Datasource\EntityInterface $entity the entity to be saved
@param array|\ArrayAccess $options The options to use when saving.
@return \Cake\Datasource\EntityInterface
@throws \Cake\ORM\Exception\PersistenceFailedException When the entity couldn't be saved
@see \Cake\ORM\Table::save() | [
"Try",
"to",
"save",
"an",
"entity",
"or",
"throw",
"a",
"PersistenceFailedException",
"if",
"the",
"application",
"rules",
"checks",
"failed",
"the",
"entity",
"contains",
"errors",
"or",
"the",
"save",
"was",
"aborted",
"by",
"a",
"callback",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L1947-L1955 |
211,533 | cakephp/cakephp | src/ORM/Table.php | Table._processSave | protected function _processSave($entity, $options)
{
$primaryColumns = (array)$this->getPrimaryKey();
if ($options['checkExisting'] && $primaryColumns && $entity->isNew() && $entity->has($primaryColumns)) {
$alias = $this->getAlias();
$conditions = [];
foreach ($entity->extract($primaryColumns) as $k => $v) {
$conditions["$alias.$k"] = $v;
}
$entity->isNew(!$this->exists($conditions));
}
$mode = $entity->isNew() ? RulesChecker::CREATE : RulesChecker::UPDATE;
if ($options['checkRules'] && !$this->checkRules($entity, $mode, $options)) {
return false;
}
$options['associated'] = $this->_associations->normalizeKeys($options['associated']);
$event = $this->dispatchEvent('Model.beforeSave', compact('entity', 'options'));
if ($event->isStopped()) {
return $event->getResult();
}
$saved = $this->_associations->saveParents(
$this,
$entity,
$options['associated'],
['_primary' => false] + $options->getArrayCopy()
);
if (!$saved && $options['atomic']) {
return false;
}
$data = $entity->extract($this->getSchema()->columns(), true);
$isNew = $entity->isNew();
if ($isNew) {
$success = $this->_insert($entity, $data);
} else {
$success = $this->_update($entity, $data);
}
if ($success) {
$success = $this->_onSaveSuccess($entity, $options);
}
if (!$success && $isNew) {
$entity->unsetProperty($this->getPrimaryKey());
$entity->isNew(true);
}
return $success ? $entity : false;
} | php | protected function _processSave($entity, $options)
{
$primaryColumns = (array)$this->getPrimaryKey();
if ($options['checkExisting'] && $primaryColumns && $entity->isNew() && $entity->has($primaryColumns)) {
$alias = $this->getAlias();
$conditions = [];
foreach ($entity->extract($primaryColumns) as $k => $v) {
$conditions["$alias.$k"] = $v;
}
$entity->isNew(!$this->exists($conditions));
}
$mode = $entity->isNew() ? RulesChecker::CREATE : RulesChecker::UPDATE;
if ($options['checkRules'] && !$this->checkRules($entity, $mode, $options)) {
return false;
}
$options['associated'] = $this->_associations->normalizeKeys($options['associated']);
$event = $this->dispatchEvent('Model.beforeSave', compact('entity', 'options'));
if ($event->isStopped()) {
return $event->getResult();
}
$saved = $this->_associations->saveParents(
$this,
$entity,
$options['associated'],
['_primary' => false] + $options->getArrayCopy()
);
if (!$saved && $options['atomic']) {
return false;
}
$data = $entity->extract($this->getSchema()->columns(), true);
$isNew = $entity->isNew();
if ($isNew) {
$success = $this->_insert($entity, $data);
} else {
$success = $this->_update($entity, $data);
}
if ($success) {
$success = $this->_onSaveSuccess($entity, $options);
}
if (!$success && $isNew) {
$entity->unsetProperty($this->getPrimaryKey());
$entity->isNew(true);
}
return $success ? $entity : false;
} | [
"protected",
"function",
"_processSave",
"(",
"$",
"entity",
",",
"$",
"options",
")",
"{",
"$",
"primaryColumns",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"getPrimaryKey",
"(",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'checkExisting'",
"]",
"&&",
"$",
"primaryColumns",
"&&",
"$",
"entity",
"->",
"isNew",
"(",
")",
"&&",
"$",
"entity",
"->",
"has",
"(",
"$",
"primaryColumns",
")",
")",
"{",
"$",
"alias",
"=",
"$",
"this",
"->",
"getAlias",
"(",
")",
";",
"$",
"conditions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"entity",
"->",
"extract",
"(",
"$",
"primaryColumns",
")",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"conditions",
"[",
"\"$alias.$k\"",
"]",
"=",
"$",
"v",
";",
"}",
"$",
"entity",
"->",
"isNew",
"(",
"!",
"$",
"this",
"->",
"exists",
"(",
"$",
"conditions",
")",
")",
";",
"}",
"$",
"mode",
"=",
"$",
"entity",
"->",
"isNew",
"(",
")",
"?",
"RulesChecker",
"::",
"CREATE",
":",
"RulesChecker",
"::",
"UPDATE",
";",
"if",
"(",
"$",
"options",
"[",
"'checkRules'",
"]",
"&&",
"!",
"$",
"this",
"->",
"checkRules",
"(",
"$",
"entity",
",",
"$",
"mode",
",",
"$",
"options",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"options",
"[",
"'associated'",
"]",
"=",
"$",
"this",
"->",
"_associations",
"->",
"normalizeKeys",
"(",
"$",
"options",
"[",
"'associated'",
"]",
")",
";",
"$",
"event",
"=",
"$",
"this",
"->",
"dispatchEvent",
"(",
"'Model.beforeSave'",
",",
"compact",
"(",
"'entity'",
",",
"'options'",
")",
")",
";",
"if",
"(",
"$",
"event",
"->",
"isStopped",
"(",
")",
")",
"{",
"return",
"$",
"event",
"->",
"getResult",
"(",
")",
";",
"}",
"$",
"saved",
"=",
"$",
"this",
"->",
"_associations",
"->",
"saveParents",
"(",
"$",
"this",
",",
"$",
"entity",
",",
"$",
"options",
"[",
"'associated'",
"]",
",",
"[",
"'_primary'",
"=>",
"false",
"]",
"+",
"$",
"options",
"->",
"getArrayCopy",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"saved",
"&&",
"$",
"options",
"[",
"'atomic'",
"]",
")",
"{",
"return",
"false",
";",
"}",
"$",
"data",
"=",
"$",
"entity",
"->",
"extract",
"(",
"$",
"this",
"->",
"getSchema",
"(",
")",
"->",
"columns",
"(",
")",
",",
"true",
")",
";",
"$",
"isNew",
"=",
"$",
"entity",
"->",
"isNew",
"(",
")",
";",
"if",
"(",
"$",
"isNew",
")",
"{",
"$",
"success",
"=",
"$",
"this",
"->",
"_insert",
"(",
"$",
"entity",
",",
"$",
"data",
")",
";",
"}",
"else",
"{",
"$",
"success",
"=",
"$",
"this",
"->",
"_update",
"(",
"$",
"entity",
",",
"$",
"data",
")",
";",
"}",
"if",
"(",
"$",
"success",
")",
"{",
"$",
"success",
"=",
"$",
"this",
"->",
"_onSaveSuccess",
"(",
"$",
"entity",
",",
"$",
"options",
")",
";",
"}",
"if",
"(",
"!",
"$",
"success",
"&&",
"$",
"isNew",
")",
"{",
"$",
"entity",
"->",
"unsetProperty",
"(",
"$",
"this",
"->",
"getPrimaryKey",
"(",
")",
")",
";",
"$",
"entity",
"->",
"isNew",
"(",
"true",
")",
";",
"}",
"return",
"$",
"success",
"?",
"$",
"entity",
":",
"false",
";",
"}"
] | Performs the actual saving of an entity based on the passed options.
@param \Cake\Datasource\EntityInterface $entity the entity to be saved
@param \ArrayObject $options the options to use for the save operation
@return \Cake\Datasource\EntityInterface|bool
@throws \RuntimeException When an entity is missing some of the primary keys.
@throws \Cake\ORM\Exception\RolledbackTransactionException If the transaction
is aborted in the afterSave event. | [
"Performs",
"the",
"actual",
"saving",
"of",
"an",
"entity",
"based",
"on",
"the",
"passed",
"options",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L1967-L2022 |
211,534 | cakephp/cakephp | src/ORM/Table.php | Table._onSaveSuccess | protected function _onSaveSuccess($entity, $options)
{
$success = $this->_associations->saveChildren(
$this,
$entity,
$options['associated'],
['_primary' => false] + $options->getArrayCopy()
);
if (!$success && $options['atomic']) {
return false;
}
$this->dispatchEvent('Model.afterSave', compact('entity', 'options'));
if ($options['atomic'] && !$this->getConnection()->inTransaction()) {
throw new RolledbackTransactionException(['table' => get_class($this)]);
}
if (!$options['atomic'] && !$options['_primary']) {
$entity->clean();
$entity->isNew(false);
$entity->setSource($this->getRegistryAlias());
}
return true;
} | php | protected function _onSaveSuccess($entity, $options)
{
$success = $this->_associations->saveChildren(
$this,
$entity,
$options['associated'],
['_primary' => false] + $options->getArrayCopy()
);
if (!$success && $options['atomic']) {
return false;
}
$this->dispatchEvent('Model.afterSave', compact('entity', 'options'));
if ($options['atomic'] && !$this->getConnection()->inTransaction()) {
throw new RolledbackTransactionException(['table' => get_class($this)]);
}
if (!$options['atomic'] && !$options['_primary']) {
$entity->clean();
$entity->isNew(false);
$entity->setSource($this->getRegistryAlias());
}
return true;
} | [
"protected",
"function",
"_onSaveSuccess",
"(",
"$",
"entity",
",",
"$",
"options",
")",
"{",
"$",
"success",
"=",
"$",
"this",
"->",
"_associations",
"->",
"saveChildren",
"(",
"$",
"this",
",",
"$",
"entity",
",",
"$",
"options",
"[",
"'associated'",
"]",
",",
"[",
"'_primary'",
"=>",
"false",
"]",
"+",
"$",
"options",
"->",
"getArrayCopy",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"success",
"&&",
"$",
"options",
"[",
"'atomic'",
"]",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"dispatchEvent",
"(",
"'Model.afterSave'",
",",
"compact",
"(",
"'entity'",
",",
"'options'",
")",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'atomic'",
"]",
"&&",
"!",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"inTransaction",
"(",
")",
")",
"{",
"throw",
"new",
"RolledbackTransactionException",
"(",
"[",
"'table'",
"=>",
"get_class",
"(",
"$",
"this",
")",
"]",
")",
";",
"}",
"if",
"(",
"!",
"$",
"options",
"[",
"'atomic'",
"]",
"&&",
"!",
"$",
"options",
"[",
"'_primary'",
"]",
")",
"{",
"$",
"entity",
"->",
"clean",
"(",
")",
";",
"$",
"entity",
"->",
"isNew",
"(",
"false",
")",
";",
"$",
"entity",
"->",
"setSource",
"(",
"$",
"this",
"->",
"getRegistryAlias",
"(",
")",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Handles the saving of children associations and executing the afterSave logic
once the entity for this table has been saved successfully.
@param \Cake\Datasource\EntityInterface $entity the entity to be saved
@param \ArrayObject $options the options to use for the save operation
@return bool True on success
@throws \Cake\ORM\Exception\RolledbackTransactionException If the transaction
is aborted in the afterSave event. | [
"Handles",
"the",
"saving",
"of",
"children",
"associations",
"and",
"executing",
"the",
"afterSave",
"logic",
"once",
"the",
"entity",
"for",
"this",
"table",
"has",
"been",
"saved",
"successfully",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L2034-L2060 |
211,535 | cakephp/cakephp | src/ORM/Table.php | Table._insert | protected function _insert($entity, $data)
{
$primary = (array)$this->getPrimaryKey();
if (empty($primary)) {
$msg = sprintf(
'Cannot insert row in "%s" table, it has no primary key.',
$this->getTable()
);
throw new RuntimeException($msg);
}
$keys = array_fill(0, count($primary), null);
$id = (array)$this->_newId($primary) + $keys;
// Generate primary keys preferring values in $data.
$primary = array_combine($primary, $id);
$primary = array_intersect_key($data, $primary) + $primary;
$filteredKeys = array_filter($primary, function ($v) {
return $v !== null;
});
$data += $filteredKeys;
if (count($primary) > 1) {
$schema = $this->getSchema();
foreach ($primary as $k => $v) {
if (!isset($data[$k]) && empty($schema->getColumn($k)['autoIncrement'])) {
$msg = 'Cannot insert row, some of the primary key values are missing. ';
$msg .= sprintf(
'Got (%s), expecting (%s)',
implode(', ', $filteredKeys + $entity->extract(array_keys($primary))),
implode(', ', array_keys($primary))
);
throw new RuntimeException($msg);
}
}
}
$success = false;
if (empty($data)) {
return $success;
}
$statement = $this->query()->insert(array_keys($data))
->values($data)
->execute();
if ($statement->rowCount() !== 0) {
$success = $entity;
$entity->set($filteredKeys, ['guard' => false]);
$schema = $this->getSchema();
$driver = $this->getConnection()->getDriver();
foreach ($primary as $key => $v) {
if (!isset($data[$key])) {
$id = $statement->lastInsertId($this->getTable(), $key);
$type = $schema->getColumnType($key);
$entity->set($key, Type::build($type)->toPHP($id, $driver));
break;
}
}
}
$statement->closeCursor();
return $success;
} | php | protected function _insert($entity, $data)
{
$primary = (array)$this->getPrimaryKey();
if (empty($primary)) {
$msg = sprintf(
'Cannot insert row in "%s" table, it has no primary key.',
$this->getTable()
);
throw new RuntimeException($msg);
}
$keys = array_fill(0, count($primary), null);
$id = (array)$this->_newId($primary) + $keys;
// Generate primary keys preferring values in $data.
$primary = array_combine($primary, $id);
$primary = array_intersect_key($data, $primary) + $primary;
$filteredKeys = array_filter($primary, function ($v) {
return $v !== null;
});
$data += $filteredKeys;
if (count($primary) > 1) {
$schema = $this->getSchema();
foreach ($primary as $k => $v) {
if (!isset($data[$k]) && empty($schema->getColumn($k)['autoIncrement'])) {
$msg = 'Cannot insert row, some of the primary key values are missing. ';
$msg .= sprintf(
'Got (%s), expecting (%s)',
implode(', ', $filteredKeys + $entity->extract(array_keys($primary))),
implode(', ', array_keys($primary))
);
throw new RuntimeException($msg);
}
}
}
$success = false;
if (empty($data)) {
return $success;
}
$statement = $this->query()->insert(array_keys($data))
->values($data)
->execute();
if ($statement->rowCount() !== 0) {
$success = $entity;
$entity->set($filteredKeys, ['guard' => false]);
$schema = $this->getSchema();
$driver = $this->getConnection()->getDriver();
foreach ($primary as $key => $v) {
if (!isset($data[$key])) {
$id = $statement->lastInsertId($this->getTable(), $key);
$type = $schema->getColumnType($key);
$entity->set($key, Type::build($type)->toPHP($id, $driver));
break;
}
}
}
$statement->closeCursor();
return $success;
} | [
"protected",
"function",
"_insert",
"(",
"$",
"entity",
",",
"$",
"data",
")",
"{",
"$",
"primary",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"getPrimaryKey",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"primary",
")",
")",
"{",
"$",
"msg",
"=",
"sprintf",
"(",
"'Cannot insert row in \"%s\" table, it has no primary key.'",
",",
"$",
"this",
"->",
"getTable",
"(",
")",
")",
";",
"throw",
"new",
"RuntimeException",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"keys",
"=",
"array_fill",
"(",
"0",
",",
"count",
"(",
"$",
"primary",
")",
",",
"null",
")",
";",
"$",
"id",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"_newId",
"(",
"$",
"primary",
")",
"+",
"$",
"keys",
";",
"// Generate primary keys preferring values in $data.",
"$",
"primary",
"=",
"array_combine",
"(",
"$",
"primary",
",",
"$",
"id",
")",
";",
"$",
"primary",
"=",
"array_intersect_key",
"(",
"$",
"data",
",",
"$",
"primary",
")",
"+",
"$",
"primary",
";",
"$",
"filteredKeys",
"=",
"array_filter",
"(",
"$",
"primary",
",",
"function",
"(",
"$",
"v",
")",
"{",
"return",
"$",
"v",
"!==",
"null",
";",
"}",
")",
";",
"$",
"data",
"+=",
"$",
"filteredKeys",
";",
"if",
"(",
"count",
"(",
"$",
"primary",
")",
">",
"1",
")",
"{",
"$",
"schema",
"=",
"$",
"this",
"->",
"getSchema",
"(",
")",
";",
"foreach",
"(",
"$",
"primary",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"$",
"k",
"]",
")",
"&&",
"empty",
"(",
"$",
"schema",
"->",
"getColumn",
"(",
"$",
"k",
")",
"[",
"'autoIncrement'",
"]",
")",
")",
"{",
"$",
"msg",
"=",
"'Cannot insert row, some of the primary key values are missing. '",
";",
"$",
"msg",
".=",
"sprintf",
"(",
"'Got (%s), expecting (%s)'",
",",
"implode",
"(",
"', '",
",",
"$",
"filteredKeys",
"+",
"$",
"entity",
"->",
"extract",
"(",
"array_keys",
"(",
"$",
"primary",
")",
")",
")",
",",
"implode",
"(",
"', '",
",",
"array_keys",
"(",
"$",
"primary",
")",
")",
")",
";",
"throw",
"new",
"RuntimeException",
"(",
"$",
"msg",
")",
";",
"}",
"}",
"}",
"$",
"success",
"=",
"false",
";",
"if",
"(",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"return",
"$",
"success",
";",
"}",
"$",
"statement",
"=",
"$",
"this",
"->",
"query",
"(",
")",
"->",
"insert",
"(",
"array_keys",
"(",
"$",
"data",
")",
")",
"->",
"values",
"(",
"$",
"data",
")",
"->",
"execute",
"(",
")",
";",
"if",
"(",
"$",
"statement",
"->",
"rowCount",
"(",
")",
"!==",
"0",
")",
"{",
"$",
"success",
"=",
"$",
"entity",
";",
"$",
"entity",
"->",
"set",
"(",
"$",
"filteredKeys",
",",
"[",
"'guard'",
"=>",
"false",
"]",
")",
";",
"$",
"schema",
"=",
"$",
"this",
"->",
"getSchema",
"(",
")",
";",
"$",
"driver",
"=",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"getDriver",
"(",
")",
";",
"foreach",
"(",
"$",
"primary",
"as",
"$",
"key",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"id",
"=",
"$",
"statement",
"->",
"lastInsertId",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
",",
"$",
"key",
")",
";",
"$",
"type",
"=",
"$",
"schema",
"->",
"getColumnType",
"(",
"$",
"key",
")",
";",
"$",
"entity",
"->",
"set",
"(",
"$",
"key",
",",
"Type",
"::",
"build",
"(",
"$",
"type",
")",
"->",
"toPHP",
"(",
"$",
"id",
",",
"$",
"driver",
")",
")",
";",
"break",
";",
"}",
"}",
"}",
"$",
"statement",
"->",
"closeCursor",
"(",
")",
";",
"return",
"$",
"success",
";",
"}"
] | Auxiliary function to handle the insert of an entity's data in the table
@param \Cake\Datasource\EntityInterface $entity the subject entity from were $data was extracted
@param array $data The actual data that needs to be saved
@return \Cake\Datasource\EntityInterface|bool
@throws \RuntimeException if not all the primary keys where supplied or could
be generated when the table has composite primary keys. Or when the table has no primary key. | [
"Auxiliary",
"function",
"to",
"handle",
"the",
"insert",
"of",
"an",
"entity",
"s",
"data",
"in",
"the",
"table"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L2071-L2134 |
211,536 | cakephp/cakephp | src/ORM/Table.php | Table._newId | protected function _newId($primary)
{
if (!$primary || count((array)$primary) > 1) {
return null;
}
$typeName = $this->getSchema()->getColumnType($primary[0]);
$type = Type::build($typeName);
return $type->newId();
} | php | protected function _newId($primary)
{
if (!$primary || count((array)$primary) > 1) {
return null;
}
$typeName = $this->getSchema()->getColumnType($primary[0]);
$type = Type::build($typeName);
return $type->newId();
} | [
"protected",
"function",
"_newId",
"(",
"$",
"primary",
")",
"{",
"if",
"(",
"!",
"$",
"primary",
"||",
"count",
"(",
"(",
"array",
")",
"$",
"primary",
")",
">",
"1",
")",
"{",
"return",
"null",
";",
"}",
"$",
"typeName",
"=",
"$",
"this",
"->",
"getSchema",
"(",
")",
"->",
"getColumnType",
"(",
"$",
"primary",
"[",
"0",
"]",
")",
";",
"$",
"type",
"=",
"Type",
"::",
"build",
"(",
"$",
"typeName",
")",
";",
"return",
"$",
"type",
"->",
"newId",
"(",
")",
";",
"}"
] | Generate a primary key value for a new record.
By default, this uses the type system to generate a new primary key
value if possible. You can override this method if you have specific requirements
for id generation.
Note: The ORM will not generate primary key values for composite primary keys.
You can overwrite _newId() in your table class.
@param array $primary The primary key columns to get a new ID for.
@return null|string|array Either null or the primary key value or a list of primary key values. | [
"Generate",
"a",
"primary",
"key",
"value",
"for",
"a",
"new",
"record",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L2149-L2158 |
211,537 | cakephp/cakephp | src/ORM/Table.php | Table._update | protected function _update($entity, $data)
{
$primaryColumns = (array)$this->getPrimaryKey();
$primaryKey = $entity->extract($primaryColumns);
$data = array_diff_key($data, $primaryKey);
if (empty($data)) {
return $entity;
}
if (count($primaryColumns) === 0) {
$entityClass = get_class($entity);
$table = $this->getTable();
$message = "Cannot update `$entityClass`. The `$table` has no primary key.";
throw new InvalidArgumentException($message);
}
if (!$entity->has($primaryColumns)) {
$message = 'All primary key value(s) are needed for updating, ';
$message .= get_class($entity) . ' is missing ' . implode(', ', $primaryColumns);
throw new InvalidArgumentException($message);
}
$query = $this->query();
$statement = $query->update()
->set($data)
->where($primaryKey)
->execute();
$success = false;
if ($statement->errorCode() === '00000') {
$success = $entity;
}
$statement->closeCursor();
return $success;
} | php | protected function _update($entity, $data)
{
$primaryColumns = (array)$this->getPrimaryKey();
$primaryKey = $entity->extract($primaryColumns);
$data = array_diff_key($data, $primaryKey);
if (empty($data)) {
return $entity;
}
if (count($primaryColumns) === 0) {
$entityClass = get_class($entity);
$table = $this->getTable();
$message = "Cannot update `$entityClass`. The `$table` has no primary key.";
throw new InvalidArgumentException($message);
}
if (!$entity->has($primaryColumns)) {
$message = 'All primary key value(s) are needed for updating, ';
$message .= get_class($entity) . ' is missing ' . implode(', ', $primaryColumns);
throw new InvalidArgumentException($message);
}
$query = $this->query();
$statement = $query->update()
->set($data)
->where($primaryKey)
->execute();
$success = false;
if ($statement->errorCode() === '00000') {
$success = $entity;
}
$statement->closeCursor();
return $success;
} | [
"protected",
"function",
"_update",
"(",
"$",
"entity",
",",
"$",
"data",
")",
"{",
"$",
"primaryColumns",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"getPrimaryKey",
"(",
")",
";",
"$",
"primaryKey",
"=",
"$",
"entity",
"->",
"extract",
"(",
"$",
"primaryColumns",
")",
";",
"$",
"data",
"=",
"array_diff_key",
"(",
"$",
"data",
",",
"$",
"primaryKey",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"return",
"$",
"entity",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"primaryColumns",
")",
"===",
"0",
")",
"{",
"$",
"entityClass",
"=",
"get_class",
"(",
"$",
"entity",
")",
";",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"message",
"=",
"\"Cannot update `$entityClass`. The `$table` has no primary key.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"message",
")",
";",
"}",
"if",
"(",
"!",
"$",
"entity",
"->",
"has",
"(",
"$",
"primaryColumns",
")",
")",
"{",
"$",
"message",
"=",
"'All primary key value(s) are needed for updating, '",
";",
"$",
"message",
".=",
"get_class",
"(",
"$",
"entity",
")",
".",
"' is missing '",
".",
"implode",
"(",
"', '",
",",
"$",
"primaryColumns",
")",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"message",
")",
";",
"}",
"$",
"query",
"=",
"$",
"this",
"->",
"query",
"(",
")",
";",
"$",
"statement",
"=",
"$",
"query",
"->",
"update",
"(",
")",
"->",
"set",
"(",
"$",
"data",
")",
"->",
"where",
"(",
"$",
"primaryKey",
")",
"->",
"execute",
"(",
")",
";",
"$",
"success",
"=",
"false",
";",
"if",
"(",
"$",
"statement",
"->",
"errorCode",
"(",
")",
"===",
"'00000'",
")",
"{",
"$",
"success",
"=",
"$",
"entity",
";",
"}",
"$",
"statement",
"->",
"closeCursor",
"(",
")",
";",
"return",
"$",
"success",
";",
"}"
] | Auxiliary function to handle the update of an entity's data in the table
@param \Cake\Datasource\EntityInterface $entity the subject entity from were $data was extracted
@param array $data The actual data that needs to be saved
@return \Cake\Datasource\EntityInterface|bool
@throws \InvalidArgumentException When primary key data is missing. | [
"Auxiliary",
"function",
"to",
"handle",
"the",
"update",
"of",
"an",
"entity",
"s",
"data",
"in",
"the",
"table"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L2168-L2204 |
211,538 | cakephp/cakephp | src/ORM/Table.php | Table.saveMany | public function saveMany($entities, $options = [])
{
$isNew = [];
$cleanup = function ($entities) use (&$isNew) {
foreach ($entities as $key => $entity) {
if (isset($isNew[$key]) && $isNew[$key]) {
$entity->unsetProperty($this->getPrimaryKey());
$entity->isNew(true);
}
}
};
try {
$return = $this->getConnection()
->transactional(function () use ($entities, $options, &$isNew) {
foreach ($entities as $key => $entity) {
$isNew[$key] = $entity->isNew();
if ($this->save($entity, $options) === false) {
return false;
}
}
});
} catch (\Exception $e) {
$cleanup($entities);
throw $e;
}
if ($return === false) {
$cleanup($entities);
return false;
}
return $entities;
} | php | public function saveMany($entities, $options = [])
{
$isNew = [];
$cleanup = function ($entities) use (&$isNew) {
foreach ($entities as $key => $entity) {
if (isset($isNew[$key]) && $isNew[$key]) {
$entity->unsetProperty($this->getPrimaryKey());
$entity->isNew(true);
}
}
};
try {
$return = $this->getConnection()
->transactional(function () use ($entities, $options, &$isNew) {
foreach ($entities as $key => $entity) {
$isNew[$key] = $entity->isNew();
if ($this->save($entity, $options) === false) {
return false;
}
}
});
} catch (\Exception $e) {
$cleanup($entities);
throw $e;
}
if ($return === false) {
$cleanup($entities);
return false;
}
return $entities;
} | [
"public",
"function",
"saveMany",
"(",
"$",
"entities",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"isNew",
"=",
"[",
"]",
";",
"$",
"cleanup",
"=",
"function",
"(",
"$",
"entities",
")",
"use",
"(",
"&",
"$",
"isNew",
")",
"{",
"foreach",
"(",
"$",
"entities",
"as",
"$",
"key",
"=>",
"$",
"entity",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"isNew",
"[",
"$",
"key",
"]",
")",
"&&",
"$",
"isNew",
"[",
"$",
"key",
"]",
")",
"{",
"$",
"entity",
"->",
"unsetProperty",
"(",
"$",
"this",
"->",
"getPrimaryKey",
"(",
")",
")",
";",
"$",
"entity",
"->",
"isNew",
"(",
"true",
")",
";",
"}",
"}",
"}",
";",
"try",
"{",
"$",
"return",
"=",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"transactional",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"entities",
",",
"$",
"options",
",",
"&",
"$",
"isNew",
")",
"{",
"foreach",
"(",
"$",
"entities",
"as",
"$",
"key",
"=>",
"$",
"entity",
")",
"{",
"$",
"isNew",
"[",
"$",
"key",
"]",
"=",
"$",
"entity",
"->",
"isNew",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"save",
"(",
"$",
"entity",
",",
"$",
"options",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"cleanup",
"(",
"$",
"entities",
")",
";",
"throw",
"$",
"e",
";",
"}",
"if",
"(",
"$",
"return",
"===",
"false",
")",
"{",
"$",
"cleanup",
"(",
"$",
"entities",
")",
";",
"return",
"false",
";",
"}",
"return",
"$",
"entities",
";",
"}"
] | Persists multiple entities of a table.
The records will be saved in a transaction which will be rolled back if
any one of the records fails to save due to failed validation or database
error.
@param \Cake\Datasource\EntityInterface[]|\Cake\Datasource\ResultSetInterface $entities Entities to save.
@param array|\ArrayAccess $options Options used when calling Table::save() for each entity.
@return bool|\Cake\Datasource\EntityInterface[]|\Cake\Datasource\ResultSetInterface False on failure, entities list on success.
@throws \Exception | [
"Persists",
"multiple",
"entities",
"of",
"a",
"table",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L2218-L2253 |
211,539 | cakephp/cakephp | src/ORM/Table.php | Table.deleteOrFail | public function deleteOrFail(EntityInterface $entity, $options = [])
{
$deleted = $this->delete($entity, $options);
if ($deleted === false) {
throw new PersistenceFailedException($entity, ['delete']);
}
return $deleted;
} | php | public function deleteOrFail(EntityInterface $entity, $options = [])
{
$deleted = $this->delete($entity, $options);
if ($deleted === false) {
throw new PersistenceFailedException($entity, ['delete']);
}
return $deleted;
} | [
"public",
"function",
"deleteOrFail",
"(",
"EntityInterface",
"$",
"entity",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"deleted",
"=",
"$",
"this",
"->",
"delete",
"(",
"$",
"entity",
",",
"$",
"options",
")",
";",
"if",
"(",
"$",
"deleted",
"===",
"false",
")",
"{",
"throw",
"new",
"PersistenceFailedException",
"(",
"$",
"entity",
",",
"[",
"'delete'",
"]",
")",
";",
"}",
"return",
"$",
"deleted",
";",
"}"
] | Try to delete an entity or throw a PersistenceFailedException if the entity is new,
has no primary key value, application rules checks failed or the delete was aborted by a callback.
@param \Cake\Datasource\EntityInterface $entity The entity to remove.
@param array|\ArrayAccess $options The options for the delete.
@return bool success
@throws \Cake\ORM\Exception\PersistenceFailedException
@see \Cake\ORM\Table::delete() | [
"Try",
"to",
"delete",
"an",
"entity",
"or",
"throw",
"a",
"PersistenceFailedException",
"if",
"the",
"entity",
"is",
"new",
"has",
"no",
"primary",
"key",
"value",
"application",
"rules",
"checks",
"failed",
"or",
"the",
"delete",
"was",
"aborted",
"by",
"a",
"callback",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L2314-L2322 |
211,540 | cakephp/cakephp | src/ORM/Table.php | Table._processDelete | protected function _processDelete($entity, $options)
{
if ($entity->isNew()) {
return false;
}
$primaryKey = (array)$this->getPrimaryKey();
if (!$entity->has($primaryKey)) {
$msg = 'Deleting requires all primary key values.';
throw new InvalidArgumentException($msg);
}
if ($options['checkRules'] && !$this->checkRules($entity, RulesChecker::DELETE, $options)) {
return false;
}
$event = $this->dispatchEvent('Model.beforeDelete', [
'entity' => $entity,
'options' => $options
]);
if ($event->isStopped()) {
return $event->getResult();
}
$this->_associations->cascadeDelete(
$entity,
['_primary' => false] + $options->getArrayCopy()
);
$query = $this->query();
$conditions = (array)$entity->extract($primaryKey);
$statement = $query->delete()
->where($conditions)
->execute();
$success = $statement->rowCount() > 0;
if (!$success) {
return $success;
}
$this->dispatchEvent('Model.afterDelete', [
'entity' => $entity,
'options' => $options
]);
return $success;
} | php | protected function _processDelete($entity, $options)
{
if ($entity->isNew()) {
return false;
}
$primaryKey = (array)$this->getPrimaryKey();
if (!$entity->has($primaryKey)) {
$msg = 'Deleting requires all primary key values.';
throw new InvalidArgumentException($msg);
}
if ($options['checkRules'] && !$this->checkRules($entity, RulesChecker::DELETE, $options)) {
return false;
}
$event = $this->dispatchEvent('Model.beforeDelete', [
'entity' => $entity,
'options' => $options
]);
if ($event->isStopped()) {
return $event->getResult();
}
$this->_associations->cascadeDelete(
$entity,
['_primary' => false] + $options->getArrayCopy()
);
$query = $this->query();
$conditions = (array)$entity->extract($primaryKey);
$statement = $query->delete()
->where($conditions)
->execute();
$success = $statement->rowCount() > 0;
if (!$success) {
return $success;
}
$this->dispatchEvent('Model.afterDelete', [
'entity' => $entity,
'options' => $options
]);
return $success;
} | [
"protected",
"function",
"_processDelete",
"(",
"$",
"entity",
",",
"$",
"options",
")",
"{",
"if",
"(",
"$",
"entity",
"->",
"isNew",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"primaryKey",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"getPrimaryKey",
"(",
")",
";",
"if",
"(",
"!",
"$",
"entity",
"->",
"has",
"(",
"$",
"primaryKey",
")",
")",
"{",
"$",
"msg",
"=",
"'Deleting requires all primary key values.'",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'checkRules'",
"]",
"&&",
"!",
"$",
"this",
"->",
"checkRules",
"(",
"$",
"entity",
",",
"RulesChecker",
"::",
"DELETE",
",",
"$",
"options",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"event",
"=",
"$",
"this",
"->",
"dispatchEvent",
"(",
"'Model.beforeDelete'",
",",
"[",
"'entity'",
"=>",
"$",
"entity",
",",
"'options'",
"=>",
"$",
"options",
"]",
")",
";",
"if",
"(",
"$",
"event",
"->",
"isStopped",
"(",
")",
")",
"{",
"return",
"$",
"event",
"->",
"getResult",
"(",
")",
";",
"}",
"$",
"this",
"->",
"_associations",
"->",
"cascadeDelete",
"(",
"$",
"entity",
",",
"[",
"'_primary'",
"=>",
"false",
"]",
"+",
"$",
"options",
"->",
"getArrayCopy",
"(",
")",
")",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"query",
"(",
")",
";",
"$",
"conditions",
"=",
"(",
"array",
")",
"$",
"entity",
"->",
"extract",
"(",
"$",
"primaryKey",
")",
";",
"$",
"statement",
"=",
"$",
"query",
"->",
"delete",
"(",
")",
"->",
"where",
"(",
"$",
"conditions",
")",
"->",
"execute",
"(",
")",
";",
"$",
"success",
"=",
"$",
"statement",
"->",
"rowCount",
"(",
")",
">",
"0",
";",
"if",
"(",
"!",
"$",
"success",
")",
"{",
"return",
"$",
"success",
";",
"}",
"$",
"this",
"->",
"dispatchEvent",
"(",
"'Model.afterDelete'",
",",
"[",
"'entity'",
"=>",
"$",
"entity",
",",
"'options'",
"=>",
"$",
"options",
"]",
")",
";",
"return",
"$",
"success",
";",
"}"
] | Perform the delete operation.
Will delete the entity provided. Will remove rows from any
dependent associations, and clear out join tables for BelongsToMany associations.
@param \Cake\Datasource\EntityInterface $entity The entity to delete.
@param \ArrayObject $options The options for the delete.
@throws \InvalidArgumentException if there are no primary key values of the
passed entity
@return bool success | [
"Perform",
"the",
"delete",
"operation",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L2336-L2383 |
211,541 | cakephp/cakephp | src/ORM/Table.php | Table.hasFinder | public function hasFinder($type)
{
$finder = 'find' . $type;
return method_exists($this, $finder) || ($this->_behaviors && $this->_behaviors->hasFinder($type));
} | php | public function hasFinder($type)
{
$finder = 'find' . $type;
return method_exists($this, $finder) || ($this->_behaviors && $this->_behaviors->hasFinder($type));
} | [
"public",
"function",
"hasFinder",
"(",
"$",
"type",
")",
"{",
"$",
"finder",
"=",
"'find'",
".",
"$",
"type",
";",
"return",
"method_exists",
"(",
"$",
"this",
",",
"$",
"finder",
")",
"||",
"(",
"$",
"this",
"->",
"_behaviors",
"&&",
"$",
"this",
"->",
"_behaviors",
"->",
"hasFinder",
"(",
"$",
"type",
")",
")",
";",
"}"
] | Returns true if the finder exists for the table
@param string $type name of finder to check
@return bool | [
"Returns",
"true",
"if",
"the",
"finder",
"exists",
"for",
"the",
"table"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L2392-L2397 |
211,542 | cakephp/cakephp | src/ORM/Table.php | Table._dynamicFinder | protected function _dynamicFinder($method, $args)
{
$method = Inflector::underscore($method);
preg_match('/^find_([\w]+)_by_/', $method, $matches);
if (empty($matches)) {
// find_by_ is 8 characters.
$fields = substr($method, 8);
$findType = 'all';
} else {
$fields = substr($method, strlen($matches[0]));
$findType = Inflector::variable($matches[1]);
}
$hasOr = strpos($fields, '_or_');
$hasAnd = strpos($fields, '_and_');
$makeConditions = function ($fields, $args) {
$conditions = [];
if (count($args) < count($fields)) {
throw new BadMethodCallException(sprintf(
'Not enough arguments for magic finder. Got %s required %s',
count($args),
count($fields)
));
}
foreach ($fields as $field) {
$conditions[$this->aliasField($field)] = array_shift($args);
}
return $conditions;
};
if ($hasOr !== false && $hasAnd !== false) {
throw new BadMethodCallException(
'Cannot mix "and" & "or" in a magic finder. Use find() instead.'
);
}
$conditions = [];
if ($hasOr === false && $hasAnd === false) {
$conditions = $makeConditions([$fields], $args);
} elseif ($hasOr !== false) {
$fields = explode('_or_', $fields);
$conditions = [
'OR' => $makeConditions($fields, $args)
];
} elseif ($hasAnd !== false) {
$fields = explode('_and_', $fields);
$conditions = $makeConditions($fields, $args);
}
return $this->find($findType, [
'conditions' => $conditions,
]);
} | php | protected function _dynamicFinder($method, $args)
{
$method = Inflector::underscore($method);
preg_match('/^find_([\w]+)_by_/', $method, $matches);
if (empty($matches)) {
// find_by_ is 8 characters.
$fields = substr($method, 8);
$findType = 'all';
} else {
$fields = substr($method, strlen($matches[0]));
$findType = Inflector::variable($matches[1]);
}
$hasOr = strpos($fields, '_or_');
$hasAnd = strpos($fields, '_and_');
$makeConditions = function ($fields, $args) {
$conditions = [];
if (count($args) < count($fields)) {
throw new BadMethodCallException(sprintf(
'Not enough arguments for magic finder. Got %s required %s',
count($args),
count($fields)
));
}
foreach ($fields as $field) {
$conditions[$this->aliasField($field)] = array_shift($args);
}
return $conditions;
};
if ($hasOr !== false && $hasAnd !== false) {
throw new BadMethodCallException(
'Cannot mix "and" & "or" in a magic finder. Use find() instead.'
);
}
$conditions = [];
if ($hasOr === false && $hasAnd === false) {
$conditions = $makeConditions([$fields], $args);
} elseif ($hasOr !== false) {
$fields = explode('_or_', $fields);
$conditions = [
'OR' => $makeConditions($fields, $args)
];
} elseif ($hasAnd !== false) {
$fields = explode('_and_', $fields);
$conditions = $makeConditions($fields, $args);
}
return $this->find($findType, [
'conditions' => $conditions,
]);
} | [
"protected",
"function",
"_dynamicFinder",
"(",
"$",
"method",
",",
"$",
"args",
")",
"{",
"$",
"method",
"=",
"Inflector",
"::",
"underscore",
"(",
"$",
"method",
")",
";",
"preg_match",
"(",
"'/^find_([\\w]+)_by_/'",
",",
"$",
"method",
",",
"$",
"matches",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"matches",
")",
")",
"{",
"// find_by_ is 8 characters.",
"$",
"fields",
"=",
"substr",
"(",
"$",
"method",
",",
"8",
")",
";",
"$",
"findType",
"=",
"'all'",
";",
"}",
"else",
"{",
"$",
"fields",
"=",
"substr",
"(",
"$",
"method",
",",
"strlen",
"(",
"$",
"matches",
"[",
"0",
"]",
")",
")",
";",
"$",
"findType",
"=",
"Inflector",
"::",
"variable",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"}",
"$",
"hasOr",
"=",
"strpos",
"(",
"$",
"fields",
",",
"'_or_'",
")",
";",
"$",
"hasAnd",
"=",
"strpos",
"(",
"$",
"fields",
",",
"'_and_'",
")",
";",
"$",
"makeConditions",
"=",
"function",
"(",
"$",
"fields",
",",
"$",
"args",
")",
"{",
"$",
"conditions",
"=",
"[",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"args",
")",
"<",
"count",
"(",
"$",
"fields",
")",
")",
"{",
"throw",
"new",
"BadMethodCallException",
"(",
"sprintf",
"(",
"'Not enough arguments for magic finder. Got %s required %s'",
",",
"count",
"(",
"$",
"args",
")",
",",
"count",
"(",
"$",
"fields",
")",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"$",
"conditions",
"[",
"$",
"this",
"->",
"aliasField",
"(",
"$",
"field",
")",
"]",
"=",
"array_shift",
"(",
"$",
"args",
")",
";",
"}",
"return",
"$",
"conditions",
";",
"}",
";",
"if",
"(",
"$",
"hasOr",
"!==",
"false",
"&&",
"$",
"hasAnd",
"!==",
"false",
")",
"{",
"throw",
"new",
"BadMethodCallException",
"(",
"'Cannot mix \"and\" & \"or\" in a magic finder. Use find() instead.'",
")",
";",
"}",
"$",
"conditions",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"hasOr",
"===",
"false",
"&&",
"$",
"hasAnd",
"===",
"false",
")",
"{",
"$",
"conditions",
"=",
"$",
"makeConditions",
"(",
"[",
"$",
"fields",
"]",
",",
"$",
"args",
")",
";",
"}",
"elseif",
"(",
"$",
"hasOr",
"!==",
"false",
")",
"{",
"$",
"fields",
"=",
"explode",
"(",
"'_or_'",
",",
"$",
"fields",
")",
";",
"$",
"conditions",
"=",
"[",
"'OR'",
"=>",
"$",
"makeConditions",
"(",
"$",
"fields",
",",
"$",
"args",
")",
"]",
";",
"}",
"elseif",
"(",
"$",
"hasAnd",
"!==",
"false",
")",
"{",
"$",
"fields",
"=",
"explode",
"(",
"'_and_'",
",",
"$",
"fields",
")",
";",
"$",
"conditions",
"=",
"$",
"makeConditions",
"(",
"$",
"fields",
",",
"$",
"args",
")",
";",
"}",
"return",
"$",
"this",
"->",
"find",
"(",
"$",
"findType",
",",
"[",
"'conditions'",
"=>",
"$",
"conditions",
",",
"]",
")",
";",
"}"
] | Provides the dynamic findBy and findByAll methods.
@param string $method The method name that was fired.
@param array $args List of arguments passed to the function.
@return mixed
@throws \BadMethodCallException when there are missing arguments, or when
and & or are combined. | [
"Provides",
"the",
"dynamic",
"findBy",
"and",
"findByAll",
"methods",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L2436-L2489 |
211,543 | cakephp/cakephp | src/ORM/Table.php | Table.implementedEvents | public function implementedEvents()
{
$eventMap = [
'Model.beforeMarshal' => 'beforeMarshal',
'Model.buildValidator' => 'buildValidator',
'Model.beforeFind' => 'beforeFind',
'Model.beforeSave' => 'beforeSave',
'Model.afterSave' => 'afterSave',
'Model.afterSaveCommit' => 'afterSaveCommit',
'Model.beforeDelete' => 'beforeDelete',
'Model.afterDelete' => 'afterDelete',
'Model.afterDeleteCommit' => 'afterDeleteCommit',
'Model.beforeRules' => 'beforeRules',
'Model.afterRules' => 'afterRules',
];
$events = [];
foreach ($eventMap as $event => $method) {
if (!method_exists($this, $method)) {
continue;
}
$events[$event] = $method;
}
return $events;
} | php | public function implementedEvents()
{
$eventMap = [
'Model.beforeMarshal' => 'beforeMarshal',
'Model.buildValidator' => 'buildValidator',
'Model.beforeFind' => 'beforeFind',
'Model.beforeSave' => 'beforeSave',
'Model.afterSave' => 'afterSave',
'Model.afterSaveCommit' => 'afterSaveCommit',
'Model.beforeDelete' => 'beforeDelete',
'Model.afterDelete' => 'afterDelete',
'Model.afterDeleteCommit' => 'afterDeleteCommit',
'Model.beforeRules' => 'beforeRules',
'Model.afterRules' => 'afterRules',
];
$events = [];
foreach ($eventMap as $event => $method) {
if (!method_exists($this, $method)) {
continue;
}
$events[$event] = $method;
}
return $events;
} | [
"public",
"function",
"implementedEvents",
"(",
")",
"{",
"$",
"eventMap",
"=",
"[",
"'Model.beforeMarshal'",
"=>",
"'beforeMarshal'",
",",
"'Model.buildValidator'",
"=>",
"'buildValidator'",
",",
"'Model.beforeFind'",
"=>",
"'beforeFind'",
",",
"'Model.beforeSave'",
"=>",
"'beforeSave'",
",",
"'Model.afterSave'",
"=>",
"'afterSave'",
",",
"'Model.afterSaveCommit'",
"=>",
"'afterSaveCommit'",
",",
"'Model.beforeDelete'",
"=>",
"'beforeDelete'",
",",
"'Model.afterDelete'",
"=>",
"'afterDelete'",
",",
"'Model.afterDeleteCommit'",
"=>",
"'afterDeleteCommit'",
",",
"'Model.beforeRules'",
"=>",
"'beforeRules'",
",",
"'Model.afterRules'",
"=>",
"'afterRules'",
",",
"]",
";",
"$",
"events",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"eventMap",
"as",
"$",
"event",
"=>",
"$",
"method",
")",
"{",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
"{",
"continue",
";",
"}",
"$",
"events",
"[",
"$",
"event",
"]",
"=",
"$",
"method",
";",
"}",
"return",
"$",
"events",
";",
"}"
] | Get the Model callbacks this table is interested in.
By implementing the conventional methods a table class is assumed
to be interested in the related event.
Override this method if you need to add non-conventional event listeners.
Or if you want you table to listen to non-standard events.
The conventional method map is:
- Model.beforeMarshal => beforeMarshal
- Model.buildValidator => buildValidator
- Model.beforeFind => beforeFind
- Model.beforeSave => beforeSave
- Model.afterSave => afterSave
- Model.afterSaveCommit => afterSaveCommit
- Model.beforeDelete => beforeDelete
- Model.afterDelete => afterDelete
- Model.afterDeleteCommit => afterDeleteCommit
- Model.beforeRules => beforeRules
- Model.afterRules => afterRules
@return array | [
"Get",
"the",
"Model",
"callbacks",
"this",
"table",
"is",
"interested",
"in",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Table.php#L2840-L2865 |
211,544 | cakephp/cakephp | src/View/Helper/SecureFieldTokenTrait.php | SecureFieldTokenTrait._buildFieldToken | protected function _buildFieldToken($url, $fields, $unlockedFields = [])
{
$locked = [];
foreach ($fields as $key => $value) {
if (is_numeric($value)) {
$value = (string)$value;
}
if (!is_int($key)) {
$locked[$key] = $value;
unset($fields[$key]);
}
}
sort($unlockedFields, SORT_STRING);
sort($fields, SORT_STRING);
ksort($locked, SORT_STRING);
$fields += $locked;
$locked = implode(array_keys($locked), '|');
$unlocked = implode($unlockedFields, '|');
$hashParts = [
$url,
serialize($fields),
$unlocked,
session_id(),
];
$fields = hash_hmac('sha1', implode('', $hashParts), Security::getSalt());
return [
'fields' => urlencode($fields . ':' . $locked),
'unlocked' => urlencode($unlocked),
];
} | php | protected function _buildFieldToken($url, $fields, $unlockedFields = [])
{
$locked = [];
foreach ($fields as $key => $value) {
if (is_numeric($value)) {
$value = (string)$value;
}
if (!is_int($key)) {
$locked[$key] = $value;
unset($fields[$key]);
}
}
sort($unlockedFields, SORT_STRING);
sort($fields, SORT_STRING);
ksort($locked, SORT_STRING);
$fields += $locked;
$locked = implode(array_keys($locked), '|');
$unlocked = implode($unlockedFields, '|');
$hashParts = [
$url,
serialize($fields),
$unlocked,
session_id(),
];
$fields = hash_hmac('sha1', implode('', $hashParts), Security::getSalt());
return [
'fields' => urlencode($fields . ':' . $locked),
'unlocked' => urlencode($unlocked),
];
} | [
"protected",
"function",
"_buildFieldToken",
"(",
"$",
"url",
",",
"$",
"fields",
",",
"$",
"unlockedFields",
"=",
"[",
"]",
")",
"{",
"$",
"locked",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"(",
"string",
")",
"$",
"value",
";",
"}",
"if",
"(",
"!",
"is_int",
"(",
"$",
"key",
")",
")",
"{",
"$",
"locked",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"unset",
"(",
"$",
"fields",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"sort",
"(",
"$",
"unlockedFields",
",",
"SORT_STRING",
")",
";",
"sort",
"(",
"$",
"fields",
",",
"SORT_STRING",
")",
";",
"ksort",
"(",
"$",
"locked",
",",
"SORT_STRING",
")",
";",
"$",
"fields",
"+=",
"$",
"locked",
";",
"$",
"locked",
"=",
"implode",
"(",
"array_keys",
"(",
"$",
"locked",
")",
",",
"'|'",
")",
";",
"$",
"unlocked",
"=",
"implode",
"(",
"$",
"unlockedFields",
",",
"'|'",
")",
";",
"$",
"hashParts",
"=",
"[",
"$",
"url",
",",
"serialize",
"(",
"$",
"fields",
")",
",",
"$",
"unlocked",
",",
"session_id",
"(",
")",
",",
"]",
";",
"$",
"fields",
"=",
"hash_hmac",
"(",
"'sha1'",
",",
"implode",
"(",
"''",
",",
"$",
"hashParts",
")",
",",
"Security",
"::",
"getSalt",
"(",
")",
")",
";",
"return",
"[",
"'fields'",
"=>",
"urlencode",
"(",
"$",
"fields",
".",
"':'",
".",
"$",
"locked",
")",
",",
"'unlocked'",
"=>",
"urlencode",
"(",
"$",
"unlocked",
")",
",",
"]",
";",
"}"
] | Generate the token data for the provided inputs.
@param string $url The URL the form is being submitted to.
@param array $fields If set specifies the list of fields to use when
generating the hash.
@param array $unlockedFields The list of fields that are excluded from
field validation.
@return array The token data. | [
"Generate",
"the",
"token",
"data",
"for",
"the",
"provided",
"inputs",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/SecureFieldTokenTrait.php#L35-L67 |
211,545 | cakephp/cakephp | src/Datasource/FactoryLocator.php | FactoryLocator.get | public static function get($type)
{
if (!isset(static::$_modelFactories['Table'])) {
static::$_modelFactories['Table'] = [TableRegistry::getTableLocator(), 'get'];
}
if (!isset(static::$_modelFactories[$type])) {
throw new InvalidArgumentException(sprintf(
'Unknown repository type "%s". Make sure you register a type before trying to use it.',
$type
));
}
return static::$_modelFactories[$type];
} | php | public static function get($type)
{
if (!isset(static::$_modelFactories['Table'])) {
static::$_modelFactories['Table'] = [TableRegistry::getTableLocator(), 'get'];
}
if (!isset(static::$_modelFactories[$type])) {
throw new InvalidArgumentException(sprintf(
'Unknown repository type "%s". Make sure you register a type before trying to use it.',
$type
));
}
return static::$_modelFactories[$type];
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"_modelFactories",
"[",
"'Table'",
"]",
")",
")",
"{",
"static",
"::",
"$",
"_modelFactories",
"[",
"'Table'",
"]",
"=",
"[",
"TableRegistry",
"::",
"getTableLocator",
"(",
")",
",",
"'get'",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"_modelFactories",
"[",
"$",
"type",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Unknown repository type \"%s\". Make sure you register a type before trying to use it.'",
",",
"$",
"type",
")",
")",
";",
"}",
"return",
"static",
"::",
"$",
"_modelFactories",
"[",
"$",
"type",
"]",
";",
"}"
] | Get the factory for the specified repository type.
@param string $type The repository type to get the factory for.
@throws \InvalidArgumentException If the specified repository type has no factory.
@return callable The factory for the repository type. | [
"Get",
"the",
"factory",
"for",
"the",
"specified",
"repository",
"type",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/FactoryLocator.php#L62-L76 |
211,546 | cakephp/cakephp | src/Utility/Security.php | Security.hash | public static function hash($string, $algorithm = null, $salt = false)
{
if (empty($algorithm)) {
$algorithm = static::$hashType;
}
$algorithm = strtolower($algorithm);
$availableAlgorithms = hash_algos();
if (!in_array($algorithm, $availableAlgorithms)) {
throw new RuntimeException(sprintf(
'The hash type `%s` was not found. Available algorithms are: %s',
$algorithm,
implode(', ', $availableAlgorithms)
));
}
if ($salt) {
if (!is_string($salt)) {
$salt = static::$_salt;
}
$string = $salt . $string;
}
return hash($algorithm, $string);
} | php | public static function hash($string, $algorithm = null, $salt = false)
{
if (empty($algorithm)) {
$algorithm = static::$hashType;
}
$algorithm = strtolower($algorithm);
$availableAlgorithms = hash_algos();
if (!in_array($algorithm, $availableAlgorithms)) {
throw new RuntimeException(sprintf(
'The hash type `%s` was not found. Available algorithms are: %s',
$algorithm,
implode(', ', $availableAlgorithms)
));
}
if ($salt) {
if (!is_string($salt)) {
$salt = static::$_salt;
}
$string = $salt . $string;
}
return hash($algorithm, $string);
} | [
"public",
"static",
"function",
"hash",
"(",
"$",
"string",
",",
"$",
"algorithm",
"=",
"null",
",",
"$",
"salt",
"=",
"false",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"algorithm",
")",
")",
"{",
"$",
"algorithm",
"=",
"static",
"::",
"$",
"hashType",
";",
"}",
"$",
"algorithm",
"=",
"strtolower",
"(",
"$",
"algorithm",
")",
";",
"$",
"availableAlgorithms",
"=",
"hash_algos",
"(",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"algorithm",
",",
"$",
"availableAlgorithms",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'The hash type `%s` was not found. Available algorithms are: %s'",
",",
"$",
"algorithm",
",",
"implode",
"(",
"', '",
",",
"$",
"availableAlgorithms",
")",
")",
")",
";",
"}",
"if",
"(",
"$",
"salt",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"salt",
")",
")",
"{",
"$",
"salt",
"=",
"static",
"::",
"$",
"_salt",
";",
"}",
"$",
"string",
"=",
"$",
"salt",
".",
"$",
"string",
";",
"}",
"return",
"hash",
"(",
"$",
"algorithm",
",",
"$",
"string",
")",
";",
"}"
] | Create a hash from string using given method.
@param string $string String to hash
@param string|null $algorithm Hashing algo to use (i.e. sha1, sha256 etc.).
Can be any valid algo included in list returned by hash_algos().
If no value is passed the type specified by `Security::$hashType` is used.
@param mixed $salt If true, automatically prepends the application's salt
value to $string (Security.salt).
@return string Hash
@link https://book.cakephp.org/3.0/en/core-libraries/security.html#hashing-data | [
"Create",
"a",
"hash",
"from",
"string",
"using",
"given",
"method",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/Security.php#L62-L86 |
211,547 | cakephp/cakephp | src/Utility/Security.php | Security.randomBytes | public static function randomBytes($length)
{
if (function_exists('random_bytes')) {
return random_bytes($length);
}
if (!function_exists('openssl_random_pseudo_bytes')) {
throw new RuntimeException(
'You do not have a safe source of random data available. ' .
'Install either the openssl extension, or paragonie/random_compat. ' .
'Or use Security::insecureRandomBytes() alternatively.'
);
}
$bytes = openssl_random_pseudo_bytes($length, $strongSource);
if (!$strongSource) {
trigger_error(
'openssl was unable to use a strong source of entropy. ' .
'Consider updating your system libraries, or ensuring ' .
'you have more available entropy.',
E_USER_WARNING
);
}
return $bytes;
} | php | public static function randomBytes($length)
{
if (function_exists('random_bytes')) {
return random_bytes($length);
}
if (!function_exists('openssl_random_pseudo_bytes')) {
throw new RuntimeException(
'You do not have a safe source of random data available. ' .
'Install either the openssl extension, or paragonie/random_compat. ' .
'Or use Security::insecureRandomBytes() alternatively.'
);
}
$bytes = openssl_random_pseudo_bytes($length, $strongSource);
if (!$strongSource) {
trigger_error(
'openssl was unable to use a strong source of entropy. ' .
'Consider updating your system libraries, or ensuring ' .
'you have more available entropy.',
E_USER_WARNING
);
}
return $bytes;
} | [
"public",
"static",
"function",
"randomBytes",
"(",
"$",
"length",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'random_bytes'",
")",
")",
"{",
"return",
"random_bytes",
"(",
"$",
"length",
")",
";",
"}",
"if",
"(",
"!",
"function_exists",
"(",
"'openssl_random_pseudo_bytes'",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'You do not have a safe source of random data available. '",
".",
"'Install either the openssl extension, or paragonie/random_compat. '",
".",
"'Or use Security::insecureRandomBytes() alternatively.'",
")",
";",
"}",
"$",
"bytes",
"=",
"openssl_random_pseudo_bytes",
"(",
"$",
"length",
",",
"$",
"strongSource",
")",
";",
"if",
"(",
"!",
"$",
"strongSource",
")",
"{",
"trigger_error",
"(",
"'openssl was unable to use a strong source of entropy. '",
".",
"'Consider updating your system libraries, or ensuring '",
".",
"'you have more available entropy.'",
",",
"E_USER_WARNING",
")",
";",
"}",
"return",
"$",
"bytes",
";",
"}"
] | Get random bytes from a secure source.
This method will fall back to an insecure source an trigger a warning
if it cannot find a secure source of random data.
@param int $length The number of bytes you want.
@return string Random bytes in binary. | [
"Get",
"random",
"bytes",
"from",
"a",
"secure",
"source",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/Security.php#L110-L134 |
211,548 | cakephp/cakephp | src/Utility/Security.php | Security.engine | public static function engine($instance = null)
{
if ($instance === null && static::$_instance === null) {
if (extension_loaded('openssl')) {
$instance = new OpenSsl();
} elseif (extension_loaded('mcrypt')) {
$instance = new Mcrypt();
}
}
if ($instance) {
static::$_instance = $instance;
}
if (isset(static::$_instance)) {
return static::$_instance;
}
throw new InvalidArgumentException(
'No compatible crypto engine available. ' .
'Load either the openssl or mcrypt extensions'
);
} | php | public static function engine($instance = null)
{
if ($instance === null && static::$_instance === null) {
if (extension_loaded('openssl')) {
$instance = new OpenSsl();
} elseif (extension_loaded('mcrypt')) {
$instance = new Mcrypt();
}
}
if ($instance) {
static::$_instance = $instance;
}
if (isset(static::$_instance)) {
return static::$_instance;
}
throw new InvalidArgumentException(
'No compatible crypto engine available. ' .
'Load either the openssl or mcrypt extensions'
);
} | [
"public",
"static",
"function",
"engine",
"(",
"$",
"instance",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"instance",
"===",
"null",
"&&",
"static",
"::",
"$",
"_instance",
"===",
"null",
")",
"{",
"if",
"(",
"extension_loaded",
"(",
"'openssl'",
")",
")",
"{",
"$",
"instance",
"=",
"new",
"OpenSsl",
"(",
")",
";",
"}",
"elseif",
"(",
"extension_loaded",
"(",
"'mcrypt'",
")",
")",
"{",
"$",
"instance",
"=",
"new",
"Mcrypt",
"(",
")",
";",
"}",
"}",
"if",
"(",
"$",
"instance",
")",
"{",
"static",
"::",
"$",
"_instance",
"=",
"$",
"instance",
";",
"}",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"_instance",
")",
")",
"{",
"return",
"static",
"::",
"$",
"_instance",
";",
"}",
"throw",
"new",
"InvalidArgumentException",
"(",
"'No compatible crypto engine available. '",
".",
"'Load either the openssl or mcrypt extensions'",
")",
";",
"}"
] | Get the crypto implementation based on the loaded extensions.
You can use this method to forcibly decide between mcrypt/openssl/custom implementations.
@param \Cake\Utility\Crypto\OpenSsl|\Cake\Utility\Crypto\Mcrypt|null $instance The crypto instance to use.
@return \Cake\Utility\Crypto\OpenSsl|\Cake\Utility\Crypto\Mcrypt Crypto instance.
@throws \InvalidArgumentException When no compatible crypto extension is available. | [
"Get",
"the",
"crypto",
"implementation",
"based",
"on",
"the",
"loaded",
"extensions",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/Security.php#L183-L202 |
211,549 | cakephp/cakephp | src/Utility/Security.php | Security.constantEquals | public static function constantEquals($original, $compare)
{
if (!is_string($original) || !is_string($compare)) {
return false;
}
if (function_exists('hash_equals')) {
return hash_equals($original, $compare);
}
$originalLength = mb_strlen($original, '8bit');
$compareLength = mb_strlen($compare, '8bit');
if ($originalLength !== $compareLength) {
return false;
}
$result = 0;
for ($i = 0; $i < $originalLength; $i++) {
$result |= (ord($original[$i]) ^ ord($compare[$i]));
}
return $result === 0;
} | php | public static function constantEquals($original, $compare)
{
if (!is_string($original) || !is_string($compare)) {
return false;
}
if (function_exists('hash_equals')) {
return hash_equals($original, $compare);
}
$originalLength = mb_strlen($original, '8bit');
$compareLength = mb_strlen($compare, '8bit');
if ($originalLength !== $compareLength) {
return false;
}
$result = 0;
for ($i = 0; $i < $originalLength; $i++) {
$result |= (ord($original[$i]) ^ ord($compare[$i]));
}
return $result === 0;
} | [
"public",
"static",
"function",
"constantEquals",
"(",
"$",
"original",
",",
"$",
"compare",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"original",
")",
"||",
"!",
"is_string",
"(",
"$",
"compare",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"function_exists",
"(",
"'hash_equals'",
")",
")",
"{",
"return",
"hash_equals",
"(",
"$",
"original",
",",
"$",
"compare",
")",
";",
"}",
"$",
"originalLength",
"=",
"mb_strlen",
"(",
"$",
"original",
",",
"'8bit'",
")",
";",
"$",
"compareLength",
"=",
"mb_strlen",
"(",
"$",
"compare",
",",
"'8bit'",
")",
";",
"if",
"(",
"$",
"originalLength",
"!==",
"$",
"compareLength",
")",
"{",
"return",
"false",
";",
"}",
"$",
"result",
"=",
"0",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"originalLength",
";",
"$",
"i",
"++",
")",
"{",
"$",
"result",
"|=",
"(",
"ord",
"(",
"$",
"original",
"[",
"$",
"i",
"]",
")",
"^",
"ord",
"(",
"$",
"compare",
"[",
"$",
"i",
"]",
")",
")",
";",
"}",
"return",
"$",
"result",
"===",
"0",
";",
"}"
] | A timing attack resistant comparison that prefers native PHP implementations.
@param string $original The original value.
@param string $compare The comparison value.
@return bool
@see https://github.com/resonantcore/php-future/
@since 3.6.2 | [
"A",
"timing",
"attack",
"resistant",
"comparison",
"that",
"prefers",
"native",
"PHP",
"implementations",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/Security.php#L327-L346 |
211,550 | cakephp/cakephp | src/ORM/Association/HasMany.php | HasMany._foreignKeyAcceptsNull | protected function _foreignKeyAcceptsNull(Table $table, array $properties)
{
return !in_array(
false,
array_map(
function ($prop) use ($table) {
return $table->getSchema()->isNullable($prop);
},
$properties
)
);
} | php | protected function _foreignKeyAcceptsNull(Table $table, array $properties)
{
return !in_array(
false,
array_map(
function ($prop) use ($table) {
return $table->getSchema()->isNullable($prop);
},
$properties
)
);
} | [
"protected",
"function",
"_foreignKeyAcceptsNull",
"(",
"Table",
"$",
"table",
",",
"array",
"$",
"properties",
")",
"{",
"return",
"!",
"in_array",
"(",
"false",
",",
"array_map",
"(",
"function",
"(",
"$",
"prop",
")",
"use",
"(",
"$",
"table",
")",
"{",
"return",
"$",
"table",
"->",
"getSchema",
"(",
")",
"->",
"isNullable",
"(",
"$",
"prop",
")",
";",
"}",
",",
"$",
"properties",
")",
")",
";",
"}"
] | Checks the nullable flag of the foreign key
@param \Cake\ORM\Table $table the table containing the foreign key
@param array $properties the list of fields that compose the foreign key
@return bool | [
"Checks",
"the",
"nullable",
"flag",
"of",
"the",
"foreign",
"key"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/HasMany.php#L554-L565 |
211,551 | cakephp/cakephp | src/ORM/Locator/LocatorAwareTrait.php | LocatorAwareTrait.tableLocator | public function tableLocator(LocatorInterface $tableLocator = null)
{
deprecationWarning(
get_called_class() . '::tableLocator() is deprecated. ' .
'Use getTableLocator()/setTableLocator() instead.'
);
if ($tableLocator !== null) {
$this->setTableLocator($tableLocator);
}
return $this->getTableLocator();
} | php | public function tableLocator(LocatorInterface $tableLocator = null)
{
deprecationWarning(
get_called_class() . '::tableLocator() is deprecated. ' .
'Use getTableLocator()/setTableLocator() instead.'
);
if ($tableLocator !== null) {
$this->setTableLocator($tableLocator);
}
return $this->getTableLocator();
} | [
"public",
"function",
"tableLocator",
"(",
"LocatorInterface",
"$",
"tableLocator",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"get_called_class",
"(",
")",
".",
"'::tableLocator() is deprecated. '",
".",
"'Use getTableLocator()/setTableLocator() instead.'",
")",
";",
"if",
"(",
"$",
"tableLocator",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"setTableLocator",
"(",
"$",
"tableLocator",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getTableLocator",
"(",
")",
";",
"}"
] | Sets the table locator.
If no parameters are passed, it will return the currently used locator.
@param \Cake\ORM\Locator\LocatorInterface|null $tableLocator LocatorInterface instance.
@return \Cake\ORM\Locator\LocatorInterface
@deprecated 3.5.0 Use getTableLocator()/setTableLocator() instead. | [
"Sets",
"the",
"table",
"locator",
".",
"If",
"no",
"parameters",
"are",
"passed",
"it",
"will",
"return",
"the",
"currently",
"used",
"locator",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Locator/LocatorAwareTrait.php#L40-L51 |
211,552 | cakephp/cakephp | src/I18n/Translator.php | Translator.translate | public function translate($key, array $tokensValues = [])
{
if (isset($tokensValues['_count'])) {
$message = $this->getMessage(static::PLURAL_PREFIX . $key);
if (!$message) {
$message = $this->getMessage($key);
}
} else {
$message = $this->getMessage($key);
if (!$message) {
$message = $this->getMessage(static::PLURAL_PREFIX . $key);
}
}
if (!$message) {
// Fallback to the message key
$message = $key;
}
// Check for missing/invalid context
if (isset($message['_context'])) {
$message = $this->resolveContext($key, $message, $tokensValues);
unset($tokensValues['_context']);
}
if (!$tokensValues) {
// Fallback for plurals that were using the singular key
if (is_array($message)) {
return array_values($message + [''])[0];
}
return $message;
}
// Singular message, but plural call
if (is_string($message) && isset($tokensValues['_singular'])) {
$message = [$tokensValues['_singular'], $message];
}
// Resolve plural form.
if (is_array($message)) {
$count = isset($tokensValues['_count']) ? $tokensValues['_count'] : 0;
$form = PluralRules::calculate($this->locale, $count);
$message = isset($message[$form]) ? $message[$form] : (string)end($message);
}
if (strlen($message) === 0) {
$message = $key;
}
return $this->formatter->format($this->locale, $message, $tokensValues);
} | php | public function translate($key, array $tokensValues = [])
{
if (isset($tokensValues['_count'])) {
$message = $this->getMessage(static::PLURAL_PREFIX . $key);
if (!$message) {
$message = $this->getMessage($key);
}
} else {
$message = $this->getMessage($key);
if (!$message) {
$message = $this->getMessage(static::PLURAL_PREFIX . $key);
}
}
if (!$message) {
// Fallback to the message key
$message = $key;
}
// Check for missing/invalid context
if (isset($message['_context'])) {
$message = $this->resolveContext($key, $message, $tokensValues);
unset($tokensValues['_context']);
}
if (!$tokensValues) {
// Fallback for plurals that were using the singular key
if (is_array($message)) {
return array_values($message + [''])[0];
}
return $message;
}
// Singular message, but plural call
if (is_string($message) && isset($tokensValues['_singular'])) {
$message = [$tokensValues['_singular'], $message];
}
// Resolve plural form.
if (is_array($message)) {
$count = isset($tokensValues['_count']) ? $tokensValues['_count'] : 0;
$form = PluralRules::calculate($this->locale, $count);
$message = isset($message[$form]) ? $message[$form] : (string)end($message);
}
if (strlen($message) === 0) {
$message = $key;
}
return $this->formatter->format($this->locale, $message, $tokensValues);
} | [
"public",
"function",
"translate",
"(",
"$",
"key",
",",
"array",
"$",
"tokensValues",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"tokensValues",
"[",
"'_count'",
"]",
")",
")",
"{",
"$",
"message",
"=",
"$",
"this",
"->",
"getMessage",
"(",
"static",
"::",
"PLURAL_PREFIX",
".",
"$",
"key",
")",
";",
"if",
"(",
"!",
"$",
"message",
")",
"{",
"$",
"message",
"=",
"$",
"this",
"->",
"getMessage",
"(",
"$",
"key",
")",
";",
"}",
"}",
"else",
"{",
"$",
"message",
"=",
"$",
"this",
"->",
"getMessage",
"(",
"$",
"key",
")",
";",
"if",
"(",
"!",
"$",
"message",
")",
"{",
"$",
"message",
"=",
"$",
"this",
"->",
"getMessage",
"(",
"static",
"::",
"PLURAL_PREFIX",
".",
"$",
"key",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"message",
")",
"{",
"// Fallback to the message key",
"$",
"message",
"=",
"$",
"key",
";",
"}",
"// Check for missing/invalid context",
"if",
"(",
"isset",
"(",
"$",
"message",
"[",
"'_context'",
"]",
")",
")",
"{",
"$",
"message",
"=",
"$",
"this",
"->",
"resolveContext",
"(",
"$",
"key",
",",
"$",
"message",
",",
"$",
"tokensValues",
")",
";",
"unset",
"(",
"$",
"tokensValues",
"[",
"'_context'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"$",
"tokensValues",
")",
"{",
"// Fallback for plurals that were using the singular key",
"if",
"(",
"is_array",
"(",
"$",
"message",
")",
")",
"{",
"return",
"array_values",
"(",
"$",
"message",
"+",
"[",
"''",
"]",
")",
"[",
"0",
"]",
";",
"}",
"return",
"$",
"message",
";",
"}",
"// Singular message, but plural call",
"if",
"(",
"is_string",
"(",
"$",
"message",
")",
"&&",
"isset",
"(",
"$",
"tokensValues",
"[",
"'_singular'",
"]",
")",
")",
"{",
"$",
"message",
"=",
"[",
"$",
"tokensValues",
"[",
"'_singular'",
"]",
",",
"$",
"message",
"]",
";",
"}",
"// Resolve plural form.",
"if",
"(",
"is_array",
"(",
"$",
"message",
")",
")",
"{",
"$",
"count",
"=",
"isset",
"(",
"$",
"tokensValues",
"[",
"'_count'",
"]",
")",
"?",
"$",
"tokensValues",
"[",
"'_count'",
"]",
":",
"0",
";",
"$",
"form",
"=",
"PluralRules",
"::",
"calculate",
"(",
"$",
"this",
"->",
"locale",
",",
"$",
"count",
")",
";",
"$",
"message",
"=",
"isset",
"(",
"$",
"message",
"[",
"$",
"form",
"]",
")",
"?",
"$",
"message",
"[",
"$",
"form",
"]",
":",
"(",
"string",
")",
"end",
"(",
"$",
"message",
")",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"message",
")",
"===",
"0",
")",
"{",
"$",
"message",
"=",
"$",
"key",
";",
"}",
"return",
"$",
"this",
"->",
"formatter",
"->",
"format",
"(",
"$",
"this",
"->",
"locale",
",",
"$",
"message",
",",
"$",
"tokensValues",
")",
";",
"}"
] | Translates the message formatting any placeholders
@param string $key The message key.
@param array $tokensValues Token values to interpolate into the
message.
@return string The translated message with tokens replaced. | [
"Translates",
"the",
"message",
"formatting",
"any",
"placeholders"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/I18n/Translator.php#L36-L87 |
211,553 | cakephp/cakephp | src/I18n/Translator.php | Translator.resolveContext | protected function resolveContext($key, $message, array $vars)
{
$context = isset($vars['_context']) ? $vars['_context'] : null;
// No or missing context, fallback to the key/first message
if ($context === null) {
if (isset($message['_context'][''])) {
return $message['_context'][''] === '' ? $key : $message['_context'][''];
}
return current($message['_context']);
}
if (!isset($message['_context'][$context])) {
return $key;
}
if ($message['_context'][$context] === '') {
return $key;
}
return $message['_context'][$context];
} | php | protected function resolveContext($key, $message, array $vars)
{
$context = isset($vars['_context']) ? $vars['_context'] : null;
// No or missing context, fallback to the key/first message
if ($context === null) {
if (isset($message['_context'][''])) {
return $message['_context'][''] === '' ? $key : $message['_context'][''];
}
return current($message['_context']);
}
if (!isset($message['_context'][$context])) {
return $key;
}
if ($message['_context'][$context] === '') {
return $key;
}
return $message['_context'][$context];
} | [
"protected",
"function",
"resolveContext",
"(",
"$",
"key",
",",
"$",
"message",
",",
"array",
"$",
"vars",
")",
"{",
"$",
"context",
"=",
"isset",
"(",
"$",
"vars",
"[",
"'_context'",
"]",
")",
"?",
"$",
"vars",
"[",
"'_context'",
"]",
":",
"null",
";",
"// No or missing context, fallback to the key/first message",
"if",
"(",
"$",
"context",
"===",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"message",
"[",
"'_context'",
"]",
"[",
"''",
"]",
")",
")",
"{",
"return",
"$",
"message",
"[",
"'_context'",
"]",
"[",
"''",
"]",
"===",
"''",
"?",
"$",
"key",
":",
"$",
"message",
"[",
"'_context'",
"]",
"[",
"''",
"]",
";",
"}",
"return",
"current",
"(",
"$",
"message",
"[",
"'_context'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"message",
"[",
"'_context'",
"]",
"[",
"$",
"context",
"]",
")",
")",
"{",
"return",
"$",
"key",
";",
"}",
"if",
"(",
"$",
"message",
"[",
"'_context'",
"]",
"[",
"$",
"context",
"]",
"===",
"''",
")",
"{",
"return",
"$",
"key",
";",
"}",
"return",
"$",
"message",
"[",
"'_context'",
"]",
"[",
"$",
"context",
"]",
";",
"}"
] | Resolve a message's context structure.
@param string $key The message key being handled.
@param string|array $message The message content.
@param array $vars The variables containing the `_context` key.
@return string | [
"Resolve",
"a",
"message",
"s",
"context",
"structure",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/I18n/Translator.php#L97-L117 |
211,554 | cakephp/cakephp | src/Routing/RouteBuilder.php | RouteBuilder.routeClass | public function routeClass($routeClass = null)
{
deprecationWarning(
'RouteBuilder::routeClass() is deprecated. ' .
'Use RouteBuilder::setRouteClass()/getRouteClass() instead.'
);
if ($routeClass === null) {
return $this->getRouteClass();
}
$this->setRouteClass($routeClass);
} | php | public function routeClass($routeClass = null)
{
deprecationWarning(
'RouteBuilder::routeClass() is deprecated. ' .
'Use RouteBuilder::setRouteClass()/getRouteClass() instead.'
);
if ($routeClass === null) {
return $this->getRouteClass();
}
$this->setRouteClass($routeClass);
} | [
"public",
"function",
"routeClass",
"(",
"$",
"routeClass",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"'RouteBuilder::routeClass() is deprecated. '",
".",
"'Use RouteBuilder::setRouteClass()/getRouteClass() instead.'",
")",
";",
"if",
"(",
"$",
"routeClass",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getRouteClass",
"(",
")",
";",
"}",
"$",
"this",
"->",
"setRouteClass",
"(",
"$",
"routeClass",
")",
";",
"}"
] | Get or set default route class.
@deprecated 3.5.0 Use getRouteClass/setRouteClass instead.
@param string|null $routeClass Class name.
@return string|null | [
"Get",
"or",
"set",
"default",
"route",
"class",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/RouteBuilder.php#L153-L163 |
211,555 | cakephp/cakephp | src/Routing/RouteBuilder.php | RouteBuilder.extensions | public function extensions($extensions = null)
{
deprecationWarning(
'RouteBuilder::extensions() is deprecated. ' .
'Use RouteBuilder::setExtensions()/getExtensions() instead.'
);
if ($extensions === null) {
return $this->getExtensions();
}
$this->setExtensions($extensions);
} | php | public function extensions($extensions = null)
{
deprecationWarning(
'RouteBuilder::extensions() is deprecated. ' .
'Use RouteBuilder::setExtensions()/getExtensions() instead.'
);
if ($extensions === null) {
return $this->getExtensions();
}
$this->setExtensions($extensions);
} | [
"public",
"function",
"extensions",
"(",
"$",
"extensions",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"'RouteBuilder::extensions() is deprecated. '",
".",
"'Use RouteBuilder::setExtensions()/getExtensions() instead.'",
")",
";",
"if",
"(",
"$",
"extensions",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getExtensions",
"(",
")",
";",
"}",
"$",
"this",
"->",
"setExtensions",
"(",
"$",
"extensions",
")",
";",
"}"
] | Get or set the extensions in this route builder's scope.
Future routes connected in through this builder will have the connected
extensions applied. However, setting extensions does not modify existing routes.
@deprecated 3.5.0 Use getExtensions/setExtensions instead.
@param null|string|array $extensions Either the extensions to use or null.
@return array|null | [
"Get",
"or",
"set",
"the",
"extensions",
"in",
"this",
"route",
"builder",
"s",
"scope",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/RouteBuilder.php#L198-L208 |
211,556 | cakephp/cakephp | src/Routing/RouteBuilder.php | RouteBuilder.addExtensions | public function addExtensions($extensions)
{
$extensions = array_merge($this->_extensions, (array)$extensions);
$this->_extensions = array_unique($extensions);
} | php | public function addExtensions($extensions)
{
$extensions = array_merge($this->_extensions, (array)$extensions);
$this->_extensions = array_unique($extensions);
} | [
"public",
"function",
"addExtensions",
"(",
"$",
"extensions",
")",
"{",
"$",
"extensions",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"_extensions",
",",
"(",
"array",
")",
"$",
"extensions",
")",
";",
"$",
"this",
"->",
"_extensions",
"=",
"array_unique",
"(",
"$",
"extensions",
")",
";",
"}"
] | Add additional extensions to what is already in current scope
@param string|array $extensions One or more extensions to add
@return void | [
"Add",
"additional",
"extensions",
"to",
"what",
"is",
"already",
"in",
"current",
"scope"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/RouteBuilder.php#L242-L246 |
211,557 | cakephp/cakephp | src/Routing/RouteBuilder.php | RouteBuilder.path | public function path()
{
$routeKey = strpos($this->_path, ':');
if ($routeKey !== false) {
return substr($this->_path, 0, $routeKey);
}
return $this->_path;
} | php | public function path()
{
$routeKey = strpos($this->_path, ':');
if ($routeKey !== false) {
return substr($this->_path, 0, $routeKey);
}
return $this->_path;
} | [
"public",
"function",
"path",
"(",
")",
"{",
"$",
"routeKey",
"=",
"strpos",
"(",
"$",
"this",
"->",
"_path",
",",
"':'",
")",
";",
"if",
"(",
"$",
"routeKey",
"!==",
"false",
")",
"{",
"return",
"substr",
"(",
"$",
"this",
"->",
"_path",
",",
"0",
",",
"$",
"routeKey",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_path",
";",
"}"
] | Get the path this scope is for.
@return string | [
"Get",
"the",
"path",
"this",
"scope",
"is",
"for",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/RouteBuilder.php#L253-L261 |
211,558 | cakephp/cakephp | src/Routing/RouteBuilder.php | RouteBuilder.get | public function get($template, $target, $name = null)
{
return $this->_methodRoute('GET', $template, $target, $name);
} | php | public function get($template, $target, $name = null)
{
return $this->_methodRoute('GET', $template, $target, $name);
} | [
"public",
"function",
"get",
"(",
"$",
"template",
",",
"$",
"target",
",",
"$",
"name",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_methodRoute",
"(",
"'GET'",
",",
"$",
"template",
",",
"$",
"target",
",",
"$",
"name",
")",
";",
"}"
] | Create a route that only responds to GET requests.
@param string $template The URL template to use.
@param array $target An array describing the target route parameters. These parameters
should indicate the plugin, prefix, controller, and action that this route points to.
@param string $name The name of the route.
@return \Cake\Routing\Route\Route | [
"Create",
"a",
"route",
"that",
"only",
"responds",
"to",
"GET",
"requests",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/RouteBuilder.php#L478-L481 |
211,559 | cakephp/cakephp | src/Routing/RouteBuilder.php | RouteBuilder.post | public function post($template, $target, $name = null)
{
return $this->_methodRoute('POST', $template, $target, $name);
} | php | public function post($template, $target, $name = null)
{
return $this->_methodRoute('POST', $template, $target, $name);
} | [
"public",
"function",
"post",
"(",
"$",
"template",
",",
"$",
"target",
",",
"$",
"name",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_methodRoute",
"(",
"'POST'",
",",
"$",
"template",
",",
"$",
"target",
",",
"$",
"name",
")",
";",
"}"
] | Create a route that only responds to POST requests.
@param string $template The URL template to use.
@param array $target An array describing the target route parameters. These parameters
should indicate the plugin, prefix, controller, and action that this route points to.
@param string $name The name of the route.
@return \Cake\Routing\Route\Route | [
"Create",
"a",
"route",
"that",
"only",
"responds",
"to",
"POST",
"requests",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/RouteBuilder.php#L492-L495 |
211,560 | cakephp/cakephp | src/Routing/RouteBuilder.php | RouteBuilder.put | public function put($template, $target, $name = null)
{
return $this->_methodRoute('PUT', $template, $target, $name);
} | php | public function put($template, $target, $name = null)
{
return $this->_methodRoute('PUT', $template, $target, $name);
} | [
"public",
"function",
"put",
"(",
"$",
"template",
",",
"$",
"target",
",",
"$",
"name",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_methodRoute",
"(",
"'PUT'",
",",
"$",
"template",
",",
"$",
"target",
",",
"$",
"name",
")",
";",
"}"
] | Create a route that only responds to PUT requests.
@param string $template The URL template to use.
@param array $target An array describing the target route parameters. These parameters
should indicate the plugin, prefix, controller, and action that this route points to.
@param string $name The name of the route.
@return \Cake\Routing\Route\Route | [
"Create",
"a",
"route",
"that",
"only",
"responds",
"to",
"PUT",
"requests",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/RouteBuilder.php#L506-L509 |
211,561 | cakephp/cakephp | src/Routing/RouteBuilder.php | RouteBuilder.patch | public function patch($template, $target, $name = null)
{
return $this->_methodRoute('PATCH', $template, $target, $name);
} | php | public function patch($template, $target, $name = null)
{
return $this->_methodRoute('PATCH', $template, $target, $name);
} | [
"public",
"function",
"patch",
"(",
"$",
"template",
",",
"$",
"target",
",",
"$",
"name",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_methodRoute",
"(",
"'PATCH'",
",",
"$",
"template",
",",
"$",
"target",
",",
"$",
"name",
")",
";",
"}"
] | Create a route that only responds to PATCH requests.
@param string $template The URL template to use.
@param array $target An array describing the target route parameters. These parameters
should indicate the plugin, prefix, controller, and action that this route points to.
@param string $name The name of the route.
@return \Cake\Routing\Route\Route | [
"Create",
"a",
"route",
"that",
"only",
"responds",
"to",
"PATCH",
"requests",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/RouteBuilder.php#L520-L523 |
211,562 | cakephp/cakephp | src/Routing/RouteBuilder.php | RouteBuilder.delete | public function delete($template, $target, $name = null)
{
return $this->_methodRoute('DELETE', $template, $target, $name);
} | php | public function delete($template, $target, $name = null)
{
return $this->_methodRoute('DELETE', $template, $target, $name);
} | [
"public",
"function",
"delete",
"(",
"$",
"template",
",",
"$",
"target",
",",
"$",
"name",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_methodRoute",
"(",
"'DELETE'",
",",
"$",
"template",
",",
"$",
"target",
",",
"$",
"name",
")",
";",
"}"
] | Create a route that only responds to DELETE requests.
@param string $template The URL template to use.
@param array $target An array describing the target route parameters. These parameters
should indicate the plugin, prefix, controller, and action that this route points to.
@param string $name The name of the route.
@return \Cake\Routing\Route\Route | [
"Create",
"a",
"route",
"that",
"only",
"responds",
"to",
"DELETE",
"requests",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/RouteBuilder.php#L534-L537 |
211,563 | cakephp/cakephp | src/Routing/RouteBuilder.php | RouteBuilder.head | public function head($template, $target, $name = null)
{
return $this->_methodRoute('HEAD', $template, $target, $name);
} | php | public function head($template, $target, $name = null)
{
return $this->_methodRoute('HEAD', $template, $target, $name);
} | [
"public",
"function",
"head",
"(",
"$",
"template",
",",
"$",
"target",
",",
"$",
"name",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_methodRoute",
"(",
"'HEAD'",
",",
"$",
"template",
",",
"$",
"target",
",",
"$",
"name",
")",
";",
"}"
] | Create a route that only responds to HEAD requests.
@param string $template The URL template to use.
@param array $target An array describing the target route parameters. These parameters
should indicate the plugin, prefix, controller, and action that this route points to.
@param string $name The name of the route.
@return \Cake\Routing\Route\Route | [
"Create",
"a",
"route",
"that",
"only",
"responds",
"to",
"HEAD",
"requests",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/RouteBuilder.php#L548-L551 |
211,564 | cakephp/cakephp | src/Routing/RouteBuilder.php | RouteBuilder.options | public function options($template, $target, $name = null)
{
return $this->_methodRoute('OPTIONS', $template, $target, $name);
} | php | public function options($template, $target, $name = null)
{
return $this->_methodRoute('OPTIONS', $template, $target, $name);
} | [
"public",
"function",
"options",
"(",
"$",
"template",
",",
"$",
"target",
",",
"$",
"name",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_methodRoute",
"(",
"'OPTIONS'",
",",
"$",
"template",
",",
"$",
"target",
",",
"$",
"name",
")",
";",
"}"
] | Create a route that only responds to OPTIONS requests.
@param string $template The URL template to use.
@param array $target An array describing the target route parameters. These parameters
should indicate the plugin, prefix, controller, and action that this route points to.
@param string $name The name of the route.
@return \Cake\Routing\Route\Route | [
"Create",
"a",
"route",
"that",
"only",
"responds",
"to",
"OPTIONS",
"requests",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/RouteBuilder.php#L562-L565 |
211,565 | cakephp/cakephp | src/Routing/RouteBuilder.php | RouteBuilder._methodRoute | protected function _methodRoute($method, $template, $target, $name)
{
if ($name !== null) {
$name = $this->_namePrefix . $name;
}
$options = [
'_name' => $name,
'_ext' => $this->_extensions,
'_middleware' => $this->middleware,
'routeClass' => $this->_routeClass,
];
$target = $this->parseDefaults($target);
$target['_method'] = $method;
$route = $this->_makeRoute($template, $target, $options);
$this->_collection->add($route, $options);
return $route;
} | php | protected function _methodRoute($method, $template, $target, $name)
{
if ($name !== null) {
$name = $this->_namePrefix . $name;
}
$options = [
'_name' => $name,
'_ext' => $this->_extensions,
'_middleware' => $this->middleware,
'routeClass' => $this->_routeClass,
];
$target = $this->parseDefaults($target);
$target['_method'] = $method;
$route = $this->_makeRoute($template, $target, $options);
$this->_collection->add($route, $options);
return $route;
} | [
"protected",
"function",
"_methodRoute",
"(",
"$",
"method",
",",
"$",
"template",
",",
"$",
"target",
",",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"name",
"!==",
"null",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"_namePrefix",
".",
"$",
"name",
";",
"}",
"$",
"options",
"=",
"[",
"'_name'",
"=>",
"$",
"name",
",",
"'_ext'",
"=>",
"$",
"this",
"->",
"_extensions",
",",
"'_middleware'",
"=>",
"$",
"this",
"->",
"middleware",
",",
"'routeClass'",
"=>",
"$",
"this",
"->",
"_routeClass",
",",
"]",
";",
"$",
"target",
"=",
"$",
"this",
"->",
"parseDefaults",
"(",
"$",
"target",
")",
";",
"$",
"target",
"[",
"'_method'",
"]",
"=",
"$",
"method",
";",
"$",
"route",
"=",
"$",
"this",
"->",
"_makeRoute",
"(",
"$",
"template",
",",
"$",
"target",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"_collection",
"->",
"add",
"(",
"$",
"route",
",",
"$",
"options",
")",
";",
"return",
"$",
"route",
";",
"}"
] | Helper to create routes that only respond to a single HTTP method.
@param string $method The HTTP method name to match.
@param string $template The URL template to use.
@param array $target An array describing the target route parameters. These parameters
should indicate the plugin, prefix, controller, and action that this route points to.
@param string $name The name of the route.
@return \Cake\Routing\Route\Route | [
"Helper",
"to",
"create",
"routes",
"that",
"only",
"respond",
"to",
"a",
"single",
"HTTP",
"method",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/RouteBuilder.php#L577-L596 |
211,566 | cakephp/cakephp | src/Routing/RouteBuilder.php | RouteBuilder.loadPlugin | public function loadPlugin($name, $file = 'routes.php')
{
$plugins = Plugin::getCollection();
if (!$plugins->has($name)) {
throw new MissingPluginException(['plugin' => $name]);
}
$plugin = $plugins->get($name);
// @deprecated This block should be removed in 4.0
if ($file !== 'routes.php') {
deprecationWarning(
'Loading plugin routes now uses the routes() hook method on the plugin class. ' .
'Loading non-standard files will be removed in 4.0'
);
$path = $plugin->getConfigPath() . DIRECTORY_SEPARATOR . $file;
if (!file_exists($path)) {
throw new InvalidArgumentException(sprintf(
'Cannot load routes for the plugin named %s. The %s file does not exist.',
$name,
$path
));
}
$routes = $this;
include $path;
return;
}
$plugin->routes($this);
// Disable the routes hook to prevent duplicate route issues.
$plugin->disable('routes');
} | php | public function loadPlugin($name, $file = 'routes.php')
{
$plugins = Plugin::getCollection();
if (!$plugins->has($name)) {
throw new MissingPluginException(['plugin' => $name]);
}
$plugin = $plugins->get($name);
// @deprecated This block should be removed in 4.0
if ($file !== 'routes.php') {
deprecationWarning(
'Loading plugin routes now uses the routes() hook method on the plugin class. ' .
'Loading non-standard files will be removed in 4.0'
);
$path = $plugin->getConfigPath() . DIRECTORY_SEPARATOR . $file;
if (!file_exists($path)) {
throw new InvalidArgumentException(sprintf(
'Cannot load routes for the plugin named %s. The %s file does not exist.',
$name,
$path
));
}
$routes = $this;
include $path;
return;
}
$plugin->routes($this);
// Disable the routes hook to prevent duplicate route issues.
$plugin->disable('routes');
} | [
"public",
"function",
"loadPlugin",
"(",
"$",
"name",
",",
"$",
"file",
"=",
"'routes.php'",
")",
"{",
"$",
"plugins",
"=",
"Plugin",
"::",
"getCollection",
"(",
")",
";",
"if",
"(",
"!",
"$",
"plugins",
"->",
"has",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"MissingPluginException",
"(",
"[",
"'plugin'",
"=>",
"$",
"name",
"]",
")",
";",
"}",
"$",
"plugin",
"=",
"$",
"plugins",
"->",
"get",
"(",
"$",
"name",
")",
";",
"// @deprecated This block should be removed in 4.0",
"if",
"(",
"$",
"file",
"!==",
"'routes.php'",
")",
"{",
"deprecationWarning",
"(",
"'Loading plugin routes now uses the routes() hook method on the plugin class. '",
".",
"'Loading non-standard files will be removed in 4.0'",
")",
";",
"$",
"path",
"=",
"$",
"plugin",
"->",
"getConfigPath",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Cannot load routes for the plugin named %s. The %s file does not exist.'",
",",
"$",
"name",
",",
"$",
"path",
")",
")",
";",
"}",
"$",
"routes",
"=",
"$",
"this",
";",
"include",
"$",
"path",
";",
"return",
";",
"}",
"$",
"plugin",
"->",
"routes",
"(",
"$",
"this",
")",
";",
"// Disable the routes hook to prevent duplicate route issues.",
"$",
"plugin",
"->",
"disable",
"(",
"'routes'",
")",
";",
"}"
] | Load routes from a plugin.
The routes file will have a local variable named `$routes` made available which contains
the current RouteBuilder instance.
@param string $name The plugin name
@param string $file The routes file to load. Defaults to `routes.php`. This parameter
is deprecated and will be removed in 4.0
@return void
@throws \Cake\Core\Exception\MissingPluginException When the plugin has not been loaded.
@throws \InvalidArgumentException When the plugin does not have a routes file. | [
"Load",
"routes",
"from",
"a",
"plugin",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/RouteBuilder.php#L611-L644 |
211,567 | cakephp/cakephp | src/Routing/RouteBuilder.php | RouteBuilder.connect | public function connect($route, $defaults = [], array $options = [])
{
$defaults = $this->parseDefaults($defaults);
if (empty($options['_ext'])) {
$options['_ext'] = $this->_extensions;
}
if (empty($options['routeClass'])) {
$options['routeClass'] = $this->_routeClass;
}
if (isset($options['_name']) && $this->_namePrefix) {
$options['_name'] = $this->_namePrefix . $options['_name'];
}
if (empty($options['_middleware'])) {
$options['_middleware'] = $this->middleware;
}
$route = $this->_makeRoute($route, $defaults, $options);
$this->_collection->add($route, $options);
return $route;
} | php | public function connect($route, $defaults = [], array $options = [])
{
$defaults = $this->parseDefaults($defaults);
if (empty($options['_ext'])) {
$options['_ext'] = $this->_extensions;
}
if (empty($options['routeClass'])) {
$options['routeClass'] = $this->_routeClass;
}
if (isset($options['_name']) && $this->_namePrefix) {
$options['_name'] = $this->_namePrefix . $options['_name'];
}
if (empty($options['_middleware'])) {
$options['_middleware'] = $this->middleware;
}
$route = $this->_makeRoute($route, $defaults, $options);
$this->_collection->add($route, $options);
return $route;
} | [
"public",
"function",
"connect",
"(",
"$",
"route",
",",
"$",
"defaults",
"=",
"[",
"]",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"$",
"this",
"->",
"parseDefaults",
"(",
"$",
"defaults",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'_ext'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'_ext'",
"]",
"=",
"$",
"this",
"->",
"_extensions",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'routeClass'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'routeClass'",
"]",
"=",
"$",
"this",
"->",
"_routeClass",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'_name'",
"]",
")",
"&&",
"$",
"this",
"->",
"_namePrefix",
")",
"{",
"$",
"options",
"[",
"'_name'",
"]",
"=",
"$",
"this",
"->",
"_namePrefix",
".",
"$",
"options",
"[",
"'_name'",
"]",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'_middleware'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'_middleware'",
"]",
"=",
"$",
"this",
"->",
"middleware",
";",
"}",
"$",
"route",
"=",
"$",
"this",
"->",
"_makeRoute",
"(",
"$",
"route",
",",
"$",
"defaults",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"_collection",
"->",
"add",
"(",
"$",
"route",
",",
"$",
"options",
")",
";",
"return",
"$",
"route",
";",
"}"
] | Connects a new Route.
Routes are a way of connecting request URLs to objects in your application.
At their core routes are a set or regular expressions that are used to
match requests to destinations.
Examples:
```
$routes->connect('/:controller/:action/*');
```
The first parameter will be used as a controller name while the second is
used as the action name. The '/*' syntax makes this route greedy in that
it will match requests like `/posts/index` as well as requests
like `/posts/edit/1/foo/bar`.
```
$routes->connect('/home-page', ['controller' => 'Pages', 'action' => 'display', 'home']);
```
The above shows the use of route parameter defaults. And providing routing
parameters for a static route.
```
$routes->connect(
'/:lang/:controller/:action/:id',
[],
['id' => '[0-9]+', 'lang' => '[a-z]{3}']
);
```
Shows connecting a route with custom route parameters as well as
providing patterns for those parameters. Patterns for routing parameters
do not need capturing groups, as one will be added for each route params.
$options offers several 'special' keys that have special meaning
in the $options array.
- `routeClass` is used to extend and change how individual routes parse requests
and handle reverse routing, via a custom routing class.
Ex. `'routeClass' => 'SlugRoute'`
- `pass` is used to define which of the routed parameters should be shifted
into the pass array. Adding a parameter to pass will remove it from the
regular route array. Ex. `'pass' => ['slug']`.
- `persist` is used to define which route parameters should be automatically
included when generating new URLs. You can override persistent parameters
by redefining them in a URL or remove them by setting the parameter to `false`.
Ex. `'persist' => ['lang']`
- `multibytePattern` Set to true to enable multibyte pattern support in route
parameter patterns.
- `_name` is used to define a specific name for routes. This can be used to optimize
reverse routing lookups. If undefined a name will be generated for each
connected route.
- `_ext` is an array of filename extensions that will be parsed out of the url if present.
See {@link \Cake\Routing\RouteCollection::setExtensions()}.
- `_method` Only match requests with specific HTTP verbs.
Example of using the `_method` condition:
```
$routes->connect('/tasks', ['controller' => 'Tasks', 'action' => 'index', '_method' => 'GET']);
```
The above route will only be matched for GET requests. POST requests will fail to match this route.
@param string $route A string describing the template of the route
@param array|string $defaults An array describing the default route parameters. These parameters will be used by default
and can supply routing parameters that are not dynamic. See above.
@param array $options An array matching the named elements in the route to regular expressions which that
element should match. Also contains additional parameters such as which routed parameters should be
shifted into the passed arguments, supplying patterns for routing parameters and supplying the name of a
custom routing class.
@return \Cake\Routing\Route\Route
@throws \InvalidArgumentException
@throws \BadMethodCallException | [
"Connects",
"a",
"new",
"Route",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/RouteBuilder.php#L724-L744 |
211,568 | cakephp/cakephp | src/Routing/RouteBuilder.php | RouteBuilder.parseDefaults | protected static function parseDefaults($defaults)
{
if (!is_string($defaults)) {
return $defaults;
}
$regex = '/(?:(?<plugin>[a-zA-Z0-9\/]*)\.)?(?<prefix>[a-zA-Z0-9\/]*?)' .
'(?:\/)?(?<controller>[a-zA-Z0-9]*):{2}(?<action>[a-zA-Z0-9_]*)/i';
if (preg_match($regex, $defaults, $matches)) {
foreach ($matches as $key => $value) {
// Remove numeric keys and empty values.
if (is_int($key) || $value === '' || $value === '::') {
unset($matches[$key]);
}
}
$length = count($matches);
if (isset($matches['prefix'])) {
$matches['prefix'] = strtolower($matches['prefix']);
}
if ($length >= 2 || $length <= 4) {
return $matches;
}
}
throw new RuntimeException("Could not parse `{$defaults}` route destination string.");
} | php | protected static function parseDefaults($defaults)
{
if (!is_string($defaults)) {
return $defaults;
}
$regex = '/(?:(?<plugin>[a-zA-Z0-9\/]*)\.)?(?<prefix>[a-zA-Z0-9\/]*?)' .
'(?:\/)?(?<controller>[a-zA-Z0-9]*):{2}(?<action>[a-zA-Z0-9_]*)/i';
if (preg_match($regex, $defaults, $matches)) {
foreach ($matches as $key => $value) {
// Remove numeric keys and empty values.
if (is_int($key) || $value === '' || $value === '::') {
unset($matches[$key]);
}
}
$length = count($matches);
if (isset($matches['prefix'])) {
$matches['prefix'] = strtolower($matches['prefix']);
}
if ($length >= 2 || $length <= 4) {
return $matches;
}
}
throw new RuntimeException("Could not parse `{$defaults}` route destination string.");
} | [
"protected",
"static",
"function",
"parseDefaults",
"(",
"$",
"defaults",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"defaults",
")",
")",
"{",
"return",
"$",
"defaults",
";",
"}",
"$",
"regex",
"=",
"'/(?:(?<plugin>[a-zA-Z0-9\\/]*)\\.)?(?<prefix>[a-zA-Z0-9\\/]*?)'",
".",
"'(?:\\/)?(?<controller>[a-zA-Z0-9]*):{2}(?<action>[a-zA-Z0-9_]*)/i'",
";",
"if",
"(",
"preg_match",
"(",
"$",
"regex",
",",
"$",
"defaults",
",",
"$",
"matches",
")",
")",
"{",
"foreach",
"(",
"$",
"matches",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"// Remove numeric keys and empty values.",
"if",
"(",
"is_int",
"(",
"$",
"key",
")",
"||",
"$",
"value",
"===",
"''",
"||",
"$",
"value",
"===",
"'::'",
")",
"{",
"unset",
"(",
"$",
"matches",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"$",
"length",
"=",
"count",
"(",
"$",
"matches",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"matches",
"[",
"'prefix'",
"]",
")",
")",
"{",
"$",
"matches",
"[",
"'prefix'",
"]",
"=",
"strtolower",
"(",
"$",
"matches",
"[",
"'prefix'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"length",
">=",
"2",
"||",
"$",
"length",
"<=",
"4",
")",
"{",
"return",
"$",
"matches",
";",
"}",
"}",
"throw",
"new",
"RuntimeException",
"(",
"\"Could not parse `{$defaults}` route destination string.\"",
")",
";",
"}"
] | Parse the defaults if they're a string
@param string|array $defaults Defaults array from the connect() method.
@return string|array | [
"Parse",
"the",
"defaults",
"if",
"they",
"re",
"a",
"string"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/RouteBuilder.php#L752-L779 |
211,569 | cakephp/cakephp | src/Routing/RouteBuilder.php | RouteBuilder._makeRoute | protected function _makeRoute($route, $defaults, $options)
{
if (is_string($route)) {
$routeClass = App::className($options['routeClass'], 'Routing/Route');
if ($routeClass === false) {
throw new InvalidArgumentException(sprintf(
'Cannot find route class %s',
$options['routeClass']
));
}
$route = str_replace('//', '/', $this->_path . $route);
if ($route !== '/') {
$route = rtrim($route, '/');
}
foreach ($this->_params as $param => $val) {
if (isset($defaults[$param]) && $param !== 'prefix' && $defaults[$param] !== $val) {
$msg = 'You cannot define routes that conflict with the scope. ' .
'Scope had %s = %s, while route had %s = %s';
throw new BadMethodCallException(sprintf(
$msg,
$param,
$val,
$param,
$defaults[$param]
));
}
}
$defaults += $this->_params + ['plugin' => null];
if (!isset($defaults['action']) && !isset($options['action'])) {
$defaults['action'] = 'index';
}
$route = new $routeClass($route, $defaults, $options);
}
if ($route instanceof Route) {
return $route;
}
throw new InvalidArgumentException(
'Route class not found, or route class is not a subclass of Cake\Routing\Route\Route'
);
} | php | protected function _makeRoute($route, $defaults, $options)
{
if (is_string($route)) {
$routeClass = App::className($options['routeClass'], 'Routing/Route');
if ($routeClass === false) {
throw new InvalidArgumentException(sprintf(
'Cannot find route class %s',
$options['routeClass']
));
}
$route = str_replace('//', '/', $this->_path . $route);
if ($route !== '/') {
$route = rtrim($route, '/');
}
foreach ($this->_params as $param => $val) {
if (isset($defaults[$param]) && $param !== 'prefix' && $defaults[$param] !== $val) {
$msg = 'You cannot define routes that conflict with the scope. ' .
'Scope had %s = %s, while route had %s = %s';
throw new BadMethodCallException(sprintf(
$msg,
$param,
$val,
$param,
$defaults[$param]
));
}
}
$defaults += $this->_params + ['plugin' => null];
if (!isset($defaults['action']) && !isset($options['action'])) {
$defaults['action'] = 'index';
}
$route = new $routeClass($route, $defaults, $options);
}
if ($route instanceof Route) {
return $route;
}
throw new InvalidArgumentException(
'Route class not found, or route class is not a subclass of Cake\Routing\Route\Route'
);
} | [
"protected",
"function",
"_makeRoute",
"(",
"$",
"route",
",",
"$",
"defaults",
",",
"$",
"options",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"route",
")",
")",
"{",
"$",
"routeClass",
"=",
"App",
"::",
"className",
"(",
"$",
"options",
"[",
"'routeClass'",
"]",
",",
"'Routing/Route'",
")",
";",
"if",
"(",
"$",
"routeClass",
"===",
"false",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Cannot find route class %s'",
",",
"$",
"options",
"[",
"'routeClass'",
"]",
")",
")",
";",
"}",
"$",
"route",
"=",
"str_replace",
"(",
"'//'",
",",
"'/'",
",",
"$",
"this",
"->",
"_path",
".",
"$",
"route",
")",
";",
"if",
"(",
"$",
"route",
"!==",
"'/'",
")",
"{",
"$",
"route",
"=",
"rtrim",
"(",
"$",
"route",
",",
"'/'",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"_params",
"as",
"$",
"param",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"defaults",
"[",
"$",
"param",
"]",
")",
"&&",
"$",
"param",
"!==",
"'prefix'",
"&&",
"$",
"defaults",
"[",
"$",
"param",
"]",
"!==",
"$",
"val",
")",
"{",
"$",
"msg",
"=",
"'You cannot define routes that conflict with the scope. '",
".",
"'Scope had %s = %s, while route had %s = %s'",
";",
"throw",
"new",
"BadMethodCallException",
"(",
"sprintf",
"(",
"$",
"msg",
",",
"$",
"param",
",",
"$",
"val",
",",
"$",
"param",
",",
"$",
"defaults",
"[",
"$",
"param",
"]",
")",
")",
";",
"}",
"}",
"$",
"defaults",
"+=",
"$",
"this",
"->",
"_params",
"+",
"[",
"'plugin'",
"=>",
"null",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"defaults",
"[",
"'action'",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"options",
"[",
"'action'",
"]",
")",
")",
"{",
"$",
"defaults",
"[",
"'action'",
"]",
"=",
"'index'",
";",
"}",
"$",
"route",
"=",
"new",
"$",
"routeClass",
"(",
"$",
"route",
",",
"$",
"defaults",
",",
"$",
"options",
")",
";",
"}",
"if",
"(",
"$",
"route",
"instanceof",
"Route",
")",
"{",
"return",
"$",
"route",
";",
"}",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Route class not found, or route class is not a subclass of Cake\\Routing\\Route\\Route'",
")",
";",
"}"
] | Create a route object, or return the provided object.
@param string|\Cake\Routing\Route\Route $route The route template or route object.
@param array $defaults Default parameters.
@param array $options Additional options parameters.
@return \Cake\Routing\Route\Route
@throws \InvalidArgumentException when route class or route object is invalid.
@throws \BadMethodCallException when the route to make conflicts with the current scope | [
"Create",
"a",
"route",
"object",
"or",
"return",
"the",
"provided",
"object",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/RouteBuilder.php#L791-L834 |
211,570 | cakephp/cakephp | src/Routing/RouteBuilder.php | RouteBuilder.prefix | public function prefix($name, $params = [], callable $callback = null)
{
if ($callback === null) {
if (!is_callable($params)) {
throw new InvalidArgumentException('A valid callback is expected');
}
$callback = $params;
$params = [];
}
$name = Inflector::underscore($name);
$path = '/' . $name;
if (isset($params['path'])) {
$path = $params['path'];
unset($params['path']);
}
if (isset($this->_params['prefix'])) {
$name = $this->_params['prefix'] . '/' . $name;
}
$params = array_merge($params, ['prefix' => $name]);
$this->scope($path, $params, $callback);
} | php | public function prefix($name, $params = [], callable $callback = null)
{
if ($callback === null) {
if (!is_callable($params)) {
throw new InvalidArgumentException('A valid callback is expected');
}
$callback = $params;
$params = [];
}
$name = Inflector::underscore($name);
$path = '/' . $name;
if (isset($params['path'])) {
$path = $params['path'];
unset($params['path']);
}
if (isset($this->_params['prefix'])) {
$name = $this->_params['prefix'] . '/' . $name;
}
$params = array_merge($params, ['prefix' => $name]);
$this->scope($path, $params, $callback);
} | [
"public",
"function",
"prefix",
"(",
"$",
"name",
",",
"$",
"params",
"=",
"[",
"]",
",",
"callable",
"$",
"callback",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"callback",
"===",
"null",
")",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"params",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'A valid callback is expected'",
")",
";",
"}",
"$",
"callback",
"=",
"$",
"params",
";",
"$",
"params",
"=",
"[",
"]",
";",
"}",
"$",
"name",
"=",
"Inflector",
"::",
"underscore",
"(",
"$",
"name",
")",
";",
"$",
"path",
"=",
"'/'",
".",
"$",
"name",
";",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'path'",
"]",
")",
")",
"{",
"$",
"path",
"=",
"$",
"params",
"[",
"'path'",
"]",
";",
"unset",
"(",
"$",
"params",
"[",
"'path'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_params",
"[",
"'prefix'",
"]",
")",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"_params",
"[",
"'prefix'",
"]",
".",
"'/'",
".",
"$",
"name",
";",
"}",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"params",
",",
"[",
"'prefix'",
"=>",
"$",
"name",
"]",
")",
";",
"$",
"this",
"->",
"scope",
"(",
"$",
"path",
",",
"$",
"params",
",",
"$",
"callback",
")",
";",
"}"
] | Add prefixed routes.
This method creates a scoped route collection that includes
relevant prefix information.
The $name parameter is used to generate the routing parameter name.
For example a path of `admin` would result in `'prefix' => 'admin'` being
applied to all connected routes.
You can re-open a prefix as many times as necessary, as well as nest prefixes.
Nested prefixes will result in prefix values like `admin/api` which translates
to the `Controller\Admin\Api\` namespace.
If you need to have prefix with dots, eg: '/api/v1.0', use 'path' key
for $params argument:
```
$route->prefix('api', function($route) {
$route->prefix('v10', ['path' => '/v1.0'], function($route) {
// Translates to `Controller\Api\V10\` namespace
});
});
```
@param string $name The prefix name to use.
@param array|callable $params An array of routing defaults to add to each connected route.
If you have no parameters, this argument can be a callable.
@param callable|null $callback The callback to invoke that builds the prefixed routes.
@return void
@throws \InvalidArgumentException If a valid callback is not passed | [
"Add",
"prefixed",
"routes",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/RouteBuilder.php#L915-L935 |
211,571 | cakephp/cakephp | src/Routing/RouteBuilder.php | RouteBuilder.scope | public function scope($path, $params, $callback = null)
{
if (is_callable($params)) {
$callback = $params;
$params = [];
}
if (!is_callable($callback)) {
$msg = 'Need a callable function/object to connect routes.';
throw new InvalidArgumentException($msg);
}
if ($this->_path !== '/') {
$path = $this->_path . $path;
}
$namePrefix = $this->_namePrefix;
if (isset($params['_namePrefix'])) {
$namePrefix .= $params['_namePrefix'];
}
unset($params['_namePrefix']);
$params += $this->_params;
$builder = new static($this->_collection, $path, $params, [
'routeClass' => $this->_routeClass,
'extensions' => $this->_extensions,
'namePrefix' => $namePrefix,
'middleware' => $this->middleware,
]);
$callback($builder);
} | php | public function scope($path, $params, $callback = null)
{
if (is_callable($params)) {
$callback = $params;
$params = [];
}
if (!is_callable($callback)) {
$msg = 'Need a callable function/object to connect routes.';
throw new InvalidArgumentException($msg);
}
if ($this->_path !== '/') {
$path = $this->_path . $path;
}
$namePrefix = $this->_namePrefix;
if (isset($params['_namePrefix'])) {
$namePrefix .= $params['_namePrefix'];
}
unset($params['_namePrefix']);
$params += $this->_params;
$builder = new static($this->_collection, $path, $params, [
'routeClass' => $this->_routeClass,
'extensions' => $this->_extensions,
'namePrefix' => $namePrefix,
'middleware' => $this->middleware,
]);
$callback($builder);
} | [
"public",
"function",
"scope",
"(",
"$",
"path",
",",
"$",
"params",
",",
"$",
"callback",
"=",
"null",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"params",
")",
")",
"{",
"$",
"callback",
"=",
"$",
"params",
";",
"$",
"params",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"callback",
")",
")",
"{",
"$",
"msg",
"=",
"'Need a callable function/object to connect routes.'",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_path",
"!==",
"'/'",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"_path",
".",
"$",
"path",
";",
"}",
"$",
"namePrefix",
"=",
"$",
"this",
"->",
"_namePrefix",
";",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'_namePrefix'",
"]",
")",
")",
"{",
"$",
"namePrefix",
".=",
"$",
"params",
"[",
"'_namePrefix'",
"]",
";",
"}",
"unset",
"(",
"$",
"params",
"[",
"'_namePrefix'",
"]",
")",
";",
"$",
"params",
"+=",
"$",
"this",
"->",
"_params",
";",
"$",
"builder",
"=",
"new",
"static",
"(",
"$",
"this",
"->",
"_collection",
",",
"$",
"path",
",",
"$",
"params",
",",
"[",
"'routeClass'",
"=>",
"$",
"this",
"->",
"_routeClass",
",",
"'extensions'",
"=>",
"$",
"this",
"->",
"_extensions",
",",
"'namePrefix'",
"=>",
"$",
"namePrefix",
",",
"'middleware'",
"=>",
"$",
"this",
"->",
"middleware",
",",
"]",
")",
";",
"$",
"callback",
"(",
"$",
"builder",
")",
";",
"}"
] | Create a new routing scope.
Scopes created with this method will inherit the properties of the scope they are
added to. This means that both the current path and parameters will be appended
to the supplied parameters.
@param string $path The path to create a scope for.
@param array|callable $params Either the parameters to add to routes, or a callback.
@param callable|null $callback The callback to invoke that builds the plugin routes.
Only required when $params is defined.
@return void
@throws \InvalidArgumentException when there is no callable parameter. | [
"Create",
"a",
"new",
"routing",
"scope",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/RouteBuilder.php#L982-L1010 |
211,572 | cakephp/cakephp | src/Routing/RouteBuilder.php | RouteBuilder.applyMiddleware | public function applyMiddleware(...$names)
{
foreach ($names as $name) {
if (!$this->_collection->middlewareExists($name)) {
$message = "Cannot apply '$name' middleware or middleware group. " .
'Use registerMiddleware() to register middleware.';
throw new RuntimeException($message);
}
}
$this->middleware = array_unique(array_merge($this->middleware, $names));
return $this;
} | php | public function applyMiddleware(...$names)
{
foreach ($names as $name) {
if (!$this->_collection->middlewareExists($name)) {
$message = "Cannot apply '$name' middleware or middleware group. " .
'Use registerMiddleware() to register middleware.';
throw new RuntimeException($message);
}
}
$this->middleware = array_unique(array_merge($this->middleware, $names));
return $this;
} | [
"public",
"function",
"applyMiddleware",
"(",
"...",
"$",
"names",
")",
"{",
"foreach",
"(",
"$",
"names",
"as",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_collection",
"->",
"middlewareExists",
"(",
"$",
"name",
")",
")",
"{",
"$",
"message",
"=",
"\"Cannot apply '$name' middleware or middleware group. \"",
".",
"'Use registerMiddleware() to register middleware.'",
";",
"throw",
"new",
"RuntimeException",
"(",
"$",
"message",
")",
";",
"}",
"}",
"$",
"this",
"->",
"middleware",
"=",
"array_unique",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"middleware",
",",
"$",
"names",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Apply a middleware to the current route scope.
Requires middleware to be registered via `registerMiddleware()`
@param string ...$names The names of the middleware to apply to the current scope.
@return $this
@see \Cake\Routing\RouteCollection::addMiddlewareToScope() | [
"Apply",
"a",
"middleware",
"to",
"the",
"current",
"route",
"scope",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/RouteBuilder.php#L1055-L1067 |
211,573 | cakephp/cakephp | src/I18n/TranslatorRegistry.php | TranslatorRegistry.defaultFormatter | public function defaultFormatter($name = null)
{
if ($name === null) {
return $this->_defaultFormatter;
}
return $this->_defaultFormatter = $name;
} | php | public function defaultFormatter($name = null)
{
if ($name === null) {
return $this->_defaultFormatter;
}
return $this->_defaultFormatter = $name;
} | [
"public",
"function",
"defaultFormatter",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"name",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_defaultFormatter",
";",
"}",
"return",
"$",
"this",
"->",
"_defaultFormatter",
"=",
"$",
"name",
";",
"}"
] | Sets the name of the default messages formatter to use for future
translator instances.
If called with no arguments, it will return the currently configured value.
@param string|null $name The name of the formatter to use.
@return string The name of the formatter. | [
"Sets",
"the",
"name",
"of",
"the",
"default",
"messages",
"formatter",
"to",
"use",
"for",
"future",
"translator",
"instances",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/I18n/TranslatorRegistry.php#L204-L211 |
211,574 | cakephp/cakephp | src/I18n/TranslatorRegistry.php | TranslatorRegistry._getFromLoader | protected function _getFromLoader($name, $locale)
{
$loader = $this->_loaders[$name]($name, $locale);
$package = $loader;
if (!is_callable($loader)) {
$loader = function () use ($package) {
return $package;
};
}
$loader = $this->setLoaderFallback($name, $loader);
$this->packages->set($name, $locale, $loader);
return parent::get($name, $locale);
} | php | protected function _getFromLoader($name, $locale)
{
$loader = $this->_loaders[$name]($name, $locale);
$package = $loader;
if (!is_callable($loader)) {
$loader = function () use ($package) {
return $package;
};
}
$loader = $this->setLoaderFallback($name, $loader);
$this->packages->set($name, $locale, $loader);
return parent::get($name, $locale);
} | [
"protected",
"function",
"_getFromLoader",
"(",
"$",
"name",
",",
"$",
"locale",
")",
"{",
"$",
"loader",
"=",
"$",
"this",
"->",
"_loaders",
"[",
"$",
"name",
"]",
"(",
"$",
"name",
",",
"$",
"locale",
")",
";",
"$",
"package",
"=",
"$",
"loader",
";",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"loader",
")",
")",
"{",
"$",
"loader",
"=",
"function",
"(",
")",
"use",
"(",
"$",
"package",
")",
"{",
"return",
"$",
"package",
";",
"}",
";",
"}",
"$",
"loader",
"=",
"$",
"this",
"->",
"setLoaderFallback",
"(",
"$",
"name",
",",
"$",
"loader",
")",
";",
"$",
"this",
"->",
"packages",
"->",
"set",
"(",
"$",
"name",
",",
"$",
"locale",
",",
"$",
"loader",
")",
";",
"return",
"parent",
"::",
"get",
"(",
"$",
"name",
",",
"$",
"locale",
")",
";",
"}"
] | Registers a new package by passing the register loaded function for the
package name.
@param string $name The name of the translator package
@param string $locale The locale that should be built the package for
@return \Aura\Intl\TranslatorInterface A translator object. | [
"Registers",
"a",
"new",
"package",
"by",
"passing",
"the",
"register",
"loaded",
"function",
"for",
"the",
"package",
"name",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/I18n/TranslatorRegistry.php#L257-L273 |
211,575 | cakephp/cakephp | src/I18n/TranslatorRegistry.php | TranslatorRegistry.setLoaderFallback | public function setLoaderFallback($name, callable $loader)
{
$fallbackDomain = 'default';
if (!$this->_useFallback || $name === $fallbackDomain) {
return $loader;
}
$loader = function () use ($loader, $fallbackDomain) {
/* @var \Aura\Intl\Package $package */
$package = $loader();
if (!$package->getFallback()) {
$package->setFallback($fallbackDomain);
}
return $package;
};
return $loader;
} | php | public function setLoaderFallback($name, callable $loader)
{
$fallbackDomain = 'default';
if (!$this->_useFallback || $name === $fallbackDomain) {
return $loader;
}
$loader = function () use ($loader, $fallbackDomain) {
/* @var \Aura\Intl\Package $package */
$package = $loader();
if (!$package->getFallback()) {
$package->setFallback($fallbackDomain);
}
return $package;
};
return $loader;
} | [
"public",
"function",
"setLoaderFallback",
"(",
"$",
"name",
",",
"callable",
"$",
"loader",
")",
"{",
"$",
"fallbackDomain",
"=",
"'default'",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"_useFallback",
"||",
"$",
"name",
"===",
"$",
"fallbackDomain",
")",
"{",
"return",
"$",
"loader",
";",
"}",
"$",
"loader",
"=",
"function",
"(",
")",
"use",
"(",
"$",
"loader",
",",
"$",
"fallbackDomain",
")",
"{",
"/* @var \\Aura\\Intl\\Package $package */",
"$",
"package",
"=",
"$",
"loader",
"(",
")",
";",
"if",
"(",
"!",
"$",
"package",
"->",
"getFallback",
"(",
")",
")",
"{",
"$",
"package",
"->",
"setFallback",
"(",
"$",
"fallbackDomain",
")",
";",
"}",
"return",
"$",
"package",
";",
"}",
";",
"return",
"$",
"loader",
";",
"}"
] | Set domain fallback for loader.
@param string $name The name of the loader domain
@param callable $loader invokable loader
@return callable loader | [
"Set",
"domain",
"fallback",
"for",
"loader",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/I18n/TranslatorRegistry.php#L282-L299 |
211,576 | cakephp/cakephp | src/Utility/Text.php | Text.uuid | public static function uuid()
{
$random = function_exists('random_int') ? 'random_int' : 'mt_rand';
return sprintf(
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// 32 bits for "time_low"
$random(0, 65535),
$random(0, 65535),
// 16 bits for "time_mid"
$random(0, 65535),
// 12 bits before the 0100 of (version) 4 for "time_hi_and_version"
$random(0, 4095) | 0x4000,
// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
$random(0, 0x3fff) | 0x8000,
// 48 bits for "node"
$random(0, 65535),
$random(0, 65535),
$random(0, 65535)
);
} | php | public static function uuid()
{
$random = function_exists('random_int') ? 'random_int' : 'mt_rand';
return sprintf(
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// 32 bits for "time_low"
$random(0, 65535),
$random(0, 65535),
// 16 bits for "time_mid"
$random(0, 65535),
// 12 bits before the 0100 of (version) 4 for "time_hi_and_version"
$random(0, 4095) | 0x4000,
// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
$random(0, 0x3fff) | 0x8000,
// 48 bits for "node"
$random(0, 65535),
$random(0, 65535),
$random(0, 65535)
);
} | [
"public",
"static",
"function",
"uuid",
"(",
")",
"{",
"$",
"random",
"=",
"function_exists",
"(",
"'random_int'",
")",
"?",
"'random_int'",
":",
"'mt_rand'",
";",
"return",
"sprintf",
"(",
"'%04x%04x-%04x-%04x-%04x-%04x%04x%04x'",
",",
"// 32 bits for \"time_low\"",
"$",
"random",
"(",
"0",
",",
"65535",
")",
",",
"$",
"random",
"(",
"0",
",",
"65535",
")",
",",
"// 16 bits for \"time_mid\"",
"$",
"random",
"(",
"0",
",",
"65535",
")",
",",
"// 12 bits before the 0100 of (version) 4 for \"time_hi_and_version\"",
"$",
"random",
"(",
"0",
",",
"4095",
")",
"|",
"0x4000",
",",
"// 16 bits, 8 bits for \"clk_seq_hi_res\",",
"// 8 bits for \"clk_seq_low\",",
"// two most significant bits holds zero and one for variant DCE1.1",
"$",
"random",
"(",
"0",
",",
"0x3fff",
")",
"|",
"0x8000",
",",
"// 48 bits for \"node\"",
"$",
"random",
"(",
"0",
",",
"65535",
")",
",",
"$",
"random",
"(",
"0",
",",
"65535",
")",
",",
"$",
"random",
"(",
"0",
",",
"65535",
")",
")",
";",
"}"
] | Generate a random UUID version 4
Warning: This method should not be used as a random seed for any cryptographic operations.
Instead you should use the openssl or mcrypt extensions.
It should also not be used to create identifiers that have security implications, such as
'unguessable' URL identifiers. Instead you should use `Security::randomBytes()` for that.
@see https://www.ietf.org/rfc/rfc4122.txt
@return string RFC 4122 UUID
@copyright Matt Farina MIT License https://github.com/lootils/uuid/blob/master/LICENSE | [
"Generate",
"a",
"random",
"UUID",
"version",
"4"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/Text.php#L62-L84 |
211,577 | cakephp/cakephp | src/Utility/Text.php | Text.wrapBlock | public static function wrapBlock($text, $options = [])
{
if (is_numeric($options)) {
$options = ['width' => $options];
}
$options += ['width' => 72, 'wordWrap' => true, 'indent' => null, 'indentAt' => 0];
if (!empty($options['indentAt']) && $options['indentAt'] === 0) {
$indentLength = !empty($options['indent']) ? strlen($options['indent']) : 0;
$options['width'] -= $indentLength;
return self::wrap($text, $options);
}
$wrapped = self::wrap($text, $options);
if (!empty($options['indent'])) {
$indentationLength = mb_strlen($options['indent']);
$chunks = explode("\n", $wrapped);
$count = count($chunks);
if ($count < 2) {
return $wrapped;
}
$toRewrap = '';
for ($i = $options['indentAt']; $i < $count; $i++) {
$toRewrap .= mb_substr($chunks[$i], $indentationLength) . ' ';
unset($chunks[$i]);
}
$options['width'] -= $indentationLength;
$options['indentAt'] = 0;
$rewrapped = self::wrap($toRewrap, $options);
$newChunks = explode("\n", $rewrapped);
$chunks = array_merge($chunks, $newChunks);
$wrapped = implode("\n", $chunks);
}
return $wrapped;
} | php | public static function wrapBlock($text, $options = [])
{
if (is_numeric($options)) {
$options = ['width' => $options];
}
$options += ['width' => 72, 'wordWrap' => true, 'indent' => null, 'indentAt' => 0];
if (!empty($options['indentAt']) && $options['indentAt'] === 0) {
$indentLength = !empty($options['indent']) ? strlen($options['indent']) : 0;
$options['width'] -= $indentLength;
return self::wrap($text, $options);
}
$wrapped = self::wrap($text, $options);
if (!empty($options['indent'])) {
$indentationLength = mb_strlen($options['indent']);
$chunks = explode("\n", $wrapped);
$count = count($chunks);
if ($count < 2) {
return $wrapped;
}
$toRewrap = '';
for ($i = $options['indentAt']; $i < $count; $i++) {
$toRewrap .= mb_substr($chunks[$i], $indentationLength) . ' ';
unset($chunks[$i]);
}
$options['width'] -= $indentationLength;
$options['indentAt'] = 0;
$rewrapped = self::wrap($toRewrap, $options);
$newChunks = explode("\n", $rewrapped);
$chunks = array_merge($chunks, $newChunks);
$wrapped = implode("\n", $chunks);
}
return $wrapped;
} | [
"public",
"static",
"function",
"wrapBlock",
"(",
"$",
"text",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"=",
"[",
"'width'",
"=>",
"$",
"options",
"]",
";",
"}",
"$",
"options",
"+=",
"[",
"'width'",
"=>",
"72",
",",
"'wordWrap'",
"=>",
"true",
",",
"'indent'",
"=>",
"null",
",",
"'indentAt'",
"=>",
"0",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'indentAt'",
"]",
")",
"&&",
"$",
"options",
"[",
"'indentAt'",
"]",
"===",
"0",
")",
"{",
"$",
"indentLength",
"=",
"!",
"empty",
"(",
"$",
"options",
"[",
"'indent'",
"]",
")",
"?",
"strlen",
"(",
"$",
"options",
"[",
"'indent'",
"]",
")",
":",
"0",
";",
"$",
"options",
"[",
"'width'",
"]",
"-=",
"$",
"indentLength",
";",
"return",
"self",
"::",
"wrap",
"(",
"$",
"text",
",",
"$",
"options",
")",
";",
"}",
"$",
"wrapped",
"=",
"self",
"::",
"wrap",
"(",
"$",
"text",
",",
"$",
"options",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'indent'",
"]",
")",
")",
"{",
"$",
"indentationLength",
"=",
"mb_strlen",
"(",
"$",
"options",
"[",
"'indent'",
"]",
")",
";",
"$",
"chunks",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"wrapped",
")",
";",
"$",
"count",
"=",
"count",
"(",
"$",
"chunks",
")",
";",
"if",
"(",
"$",
"count",
"<",
"2",
")",
"{",
"return",
"$",
"wrapped",
";",
"}",
"$",
"toRewrap",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"options",
"[",
"'indentAt'",
"]",
";",
"$",
"i",
"<",
"$",
"count",
";",
"$",
"i",
"++",
")",
"{",
"$",
"toRewrap",
".=",
"mb_substr",
"(",
"$",
"chunks",
"[",
"$",
"i",
"]",
",",
"$",
"indentationLength",
")",
".",
"' '",
";",
"unset",
"(",
"$",
"chunks",
"[",
"$",
"i",
"]",
")",
";",
"}",
"$",
"options",
"[",
"'width'",
"]",
"-=",
"$",
"indentationLength",
";",
"$",
"options",
"[",
"'indentAt'",
"]",
"=",
"0",
";",
"$",
"rewrapped",
"=",
"self",
"::",
"wrap",
"(",
"$",
"toRewrap",
",",
"$",
"options",
")",
";",
"$",
"newChunks",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"rewrapped",
")",
";",
"$",
"chunks",
"=",
"array_merge",
"(",
"$",
"chunks",
",",
"$",
"newChunks",
")",
";",
"$",
"wrapped",
"=",
"implode",
"(",
"\"\\n\"",
",",
"$",
"chunks",
")",
";",
"}",
"return",
"$",
"wrapped",
";",
"}"
] | Wraps a complete block of text to a specific width, can optionally wrap
at word breaks.
### Options
- `width` The width to wrap to. Defaults to 72.
- `wordWrap` Only wrap on words breaks (spaces) Defaults to true.
- `indent` String to indent with. Defaults to null.
- `indentAt` 0 based index to start indenting at. Defaults to 0.
@param string $text The text to format.
@param array|int $options Array of options to use, or an integer to wrap the text to.
@return string Formatted text. | [
"Wraps",
"a",
"complete",
"block",
"of",
"text",
"to",
"a",
"specific",
"width",
"can",
"optionally",
"wrap",
"at",
"word",
"breaks",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/Text.php#L362-L400 |
211,578 | cakephp/cakephp | src/Utility/Text.php | Text.wordWrap | public static function wordWrap($text, $width = 72, $break = "\n", $cut = false)
{
$paragraphs = explode($break, $text);
foreach ($paragraphs as &$paragraph) {
$paragraph = static::_wordWrap($paragraph, $width, $break, $cut);
}
return implode($break, $paragraphs);
} | php | public static function wordWrap($text, $width = 72, $break = "\n", $cut = false)
{
$paragraphs = explode($break, $text);
foreach ($paragraphs as &$paragraph) {
$paragraph = static::_wordWrap($paragraph, $width, $break, $cut);
}
return implode($break, $paragraphs);
} | [
"public",
"static",
"function",
"wordWrap",
"(",
"$",
"text",
",",
"$",
"width",
"=",
"72",
",",
"$",
"break",
"=",
"\"\\n\"",
",",
"$",
"cut",
"=",
"false",
")",
"{",
"$",
"paragraphs",
"=",
"explode",
"(",
"$",
"break",
",",
"$",
"text",
")",
";",
"foreach",
"(",
"$",
"paragraphs",
"as",
"&",
"$",
"paragraph",
")",
"{",
"$",
"paragraph",
"=",
"static",
"::",
"_wordWrap",
"(",
"$",
"paragraph",
",",
"$",
"width",
",",
"$",
"break",
",",
"$",
"cut",
")",
";",
"}",
"return",
"implode",
"(",
"$",
"break",
",",
"$",
"paragraphs",
")",
";",
"}"
] | Unicode and newline aware version of wordwrap.
@param string $text The text to format.
@param int $width The width to wrap to. Defaults to 72.
@param string $break The line is broken using the optional break parameter. Defaults to '\n'.
@param bool $cut If the cut is set to true, the string is always wrapped at the specified width.
@return string Formatted text. | [
"Unicode",
"and",
"newline",
"aware",
"version",
"of",
"wordwrap",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/Text.php#L411-L419 |
211,579 | cakephp/cakephp | src/Utility/Text.php | Text._strlen | protected static function _strlen($text, array $options)
{
if (empty($options['trimWidth'])) {
$strlen = 'mb_strlen';
} else {
$strlen = 'mb_strwidth';
}
if (empty($options['html'])) {
return $strlen($text);
}
$pattern = '/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i';
$replace = preg_replace_callback(
$pattern,
function ($match) use ($strlen) {
$utf8 = html_entity_decode($match[0], ENT_HTML5 | ENT_QUOTES, 'UTF-8');
return str_repeat(' ', $strlen($utf8, 'UTF-8'));
},
$text
);
return $strlen($replace);
} | php | protected static function _strlen($text, array $options)
{
if (empty($options['trimWidth'])) {
$strlen = 'mb_strlen';
} else {
$strlen = 'mb_strwidth';
}
if (empty($options['html'])) {
return $strlen($text);
}
$pattern = '/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i';
$replace = preg_replace_callback(
$pattern,
function ($match) use ($strlen) {
$utf8 = html_entity_decode($match[0], ENT_HTML5 | ENT_QUOTES, 'UTF-8');
return str_repeat(' ', $strlen($utf8, 'UTF-8'));
},
$text
);
return $strlen($replace);
} | [
"protected",
"static",
"function",
"_strlen",
"(",
"$",
"text",
",",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'trimWidth'",
"]",
")",
")",
"{",
"$",
"strlen",
"=",
"'mb_strlen'",
";",
"}",
"else",
"{",
"$",
"strlen",
"=",
"'mb_strwidth'",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'html'",
"]",
")",
")",
"{",
"return",
"$",
"strlen",
"(",
"$",
"text",
")",
";",
"}",
"$",
"pattern",
"=",
"'/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i'",
";",
"$",
"replace",
"=",
"preg_replace_callback",
"(",
"$",
"pattern",
",",
"function",
"(",
"$",
"match",
")",
"use",
"(",
"$",
"strlen",
")",
"{",
"$",
"utf8",
"=",
"html_entity_decode",
"(",
"$",
"match",
"[",
"0",
"]",
",",
"ENT_HTML5",
"|",
"ENT_QUOTES",
",",
"'UTF-8'",
")",
";",
"return",
"str_repeat",
"(",
"' '",
",",
"$",
"strlen",
"(",
"$",
"utf8",
",",
"'UTF-8'",
")",
")",
";",
"}",
",",
"$",
"text",
")",
";",
"return",
"$",
"strlen",
"(",
"$",
"replace",
")",
";",
"}"
] | Get string length.
### Options:
- `html` If true, HTML entities will be handled as decoded characters.
- `trimWidth` If true, the width will return.
@param string $text The string being checked for length
@param array $options An array of options.
@return int | [
"Get",
"string",
"length",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/Text.php#L732-L756 |
211,580 | cakephp/cakephp | src/Utility/Text.php | Text._substr | protected static function _substr($text, $start, $length, array $options)
{
if (empty($options['trimWidth'])) {
$substr = 'mb_substr';
} else {
$substr = 'mb_strimwidth';
}
$maxPosition = self::_strlen($text, ['trimWidth' => false] + $options);
if ($start < 0) {
$start += $maxPosition;
if ($start < 0) {
$start = 0;
}
}
if ($start >= $maxPosition) {
return '';
}
if ($length === null) {
$length = self::_strlen($text, $options);
}
if ($length < 0) {
$text = self::_substr($text, $start, null, $options);
$start = 0;
$length += self::_strlen($text, $options);
}
if ($length <= 0) {
return '';
}
if (empty($options['html'])) {
return (string)$substr($text, $start, $length);
}
$totalOffset = 0;
$totalLength = 0;
$result = '';
$pattern = '/(&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};)/i';
$parts = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
foreach ($parts as $part) {
$offset = 0;
if ($totalOffset < $start) {
$len = self::_strlen($part, ['trimWidth' => false] + $options);
if ($totalOffset + $len <= $start) {
$totalOffset += $len;
continue;
}
$offset = $start - $totalOffset;
$totalOffset = $start;
}
$len = self::_strlen($part, $options);
if ($offset !== 0 || $totalLength + $len > $length) {
if (strpos($part, '&') === 0 && preg_match($pattern, $part)
&& $part !== html_entity_decode($part, ENT_HTML5 | ENT_QUOTES, 'UTF-8')
) {
// Entities cannot be passed substr.
continue;
}
$part = $substr($part, $offset, $length - $totalLength);
$len = self::_strlen($part, $options);
}
$result .= $part;
$totalLength += $len;
if ($totalLength >= $length) {
break;
}
}
return $result;
} | php | protected static function _substr($text, $start, $length, array $options)
{
if (empty($options['trimWidth'])) {
$substr = 'mb_substr';
} else {
$substr = 'mb_strimwidth';
}
$maxPosition = self::_strlen($text, ['trimWidth' => false] + $options);
if ($start < 0) {
$start += $maxPosition;
if ($start < 0) {
$start = 0;
}
}
if ($start >= $maxPosition) {
return '';
}
if ($length === null) {
$length = self::_strlen($text, $options);
}
if ($length < 0) {
$text = self::_substr($text, $start, null, $options);
$start = 0;
$length += self::_strlen($text, $options);
}
if ($length <= 0) {
return '';
}
if (empty($options['html'])) {
return (string)$substr($text, $start, $length);
}
$totalOffset = 0;
$totalLength = 0;
$result = '';
$pattern = '/(&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};)/i';
$parts = preg_split($pattern, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
foreach ($parts as $part) {
$offset = 0;
if ($totalOffset < $start) {
$len = self::_strlen($part, ['trimWidth' => false] + $options);
if ($totalOffset + $len <= $start) {
$totalOffset += $len;
continue;
}
$offset = $start - $totalOffset;
$totalOffset = $start;
}
$len = self::_strlen($part, $options);
if ($offset !== 0 || $totalLength + $len > $length) {
if (strpos($part, '&') === 0 && preg_match($pattern, $part)
&& $part !== html_entity_decode($part, ENT_HTML5 | ENT_QUOTES, 'UTF-8')
) {
// Entities cannot be passed substr.
continue;
}
$part = $substr($part, $offset, $length - $totalLength);
$len = self::_strlen($part, $options);
}
$result .= $part;
$totalLength += $len;
if ($totalLength >= $length) {
break;
}
}
return $result;
} | [
"protected",
"static",
"function",
"_substr",
"(",
"$",
"text",
",",
"$",
"start",
",",
"$",
"length",
",",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'trimWidth'",
"]",
")",
")",
"{",
"$",
"substr",
"=",
"'mb_substr'",
";",
"}",
"else",
"{",
"$",
"substr",
"=",
"'mb_strimwidth'",
";",
"}",
"$",
"maxPosition",
"=",
"self",
"::",
"_strlen",
"(",
"$",
"text",
",",
"[",
"'trimWidth'",
"=>",
"false",
"]",
"+",
"$",
"options",
")",
";",
"if",
"(",
"$",
"start",
"<",
"0",
")",
"{",
"$",
"start",
"+=",
"$",
"maxPosition",
";",
"if",
"(",
"$",
"start",
"<",
"0",
")",
"{",
"$",
"start",
"=",
"0",
";",
"}",
"}",
"if",
"(",
"$",
"start",
">=",
"$",
"maxPosition",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"$",
"length",
"===",
"null",
")",
"{",
"$",
"length",
"=",
"self",
"::",
"_strlen",
"(",
"$",
"text",
",",
"$",
"options",
")",
";",
"}",
"if",
"(",
"$",
"length",
"<",
"0",
")",
"{",
"$",
"text",
"=",
"self",
"::",
"_substr",
"(",
"$",
"text",
",",
"$",
"start",
",",
"null",
",",
"$",
"options",
")",
";",
"$",
"start",
"=",
"0",
";",
"$",
"length",
"+=",
"self",
"::",
"_strlen",
"(",
"$",
"text",
",",
"$",
"options",
")",
";",
"}",
"if",
"(",
"$",
"length",
"<=",
"0",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'html'",
"]",
")",
")",
"{",
"return",
"(",
"string",
")",
"$",
"substr",
"(",
"$",
"text",
",",
"$",
"start",
",",
"$",
"length",
")",
";",
"}",
"$",
"totalOffset",
"=",
"0",
";",
"$",
"totalLength",
"=",
"0",
";",
"$",
"result",
"=",
"''",
";",
"$",
"pattern",
"=",
"'/(&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};)/i'",
";",
"$",
"parts",
"=",
"preg_split",
"(",
"$",
"pattern",
",",
"$",
"text",
",",
"-",
"1",
",",
"PREG_SPLIT_DELIM_CAPTURE",
"|",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"part",
")",
"{",
"$",
"offset",
"=",
"0",
";",
"if",
"(",
"$",
"totalOffset",
"<",
"$",
"start",
")",
"{",
"$",
"len",
"=",
"self",
"::",
"_strlen",
"(",
"$",
"part",
",",
"[",
"'trimWidth'",
"=>",
"false",
"]",
"+",
"$",
"options",
")",
";",
"if",
"(",
"$",
"totalOffset",
"+",
"$",
"len",
"<=",
"$",
"start",
")",
"{",
"$",
"totalOffset",
"+=",
"$",
"len",
";",
"continue",
";",
"}",
"$",
"offset",
"=",
"$",
"start",
"-",
"$",
"totalOffset",
";",
"$",
"totalOffset",
"=",
"$",
"start",
";",
"}",
"$",
"len",
"=",
"self",
"::",
"_strlen",
"(",
"$",
"part",
",",
"$",
"options",
")",
";",
"if",
"(",
"$",
"offset",
"!==",
"0",
"||",
"$",
"totalLength",
"+",
"$",
"len",
">",
"$",
"length",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"part",
",",
"'&'",
")",
"===",
"0",
"&&",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"part",
")",
"&&",
"$",
"part",
"!==",
"html_entity_decode",
"(",
"$",
"part",
",",
"ENT_HTML5",
"|",
"ENT_QUOTES",
",",
"'UTF-8'",
")",
")",
"{",
"// Entities cannot be passed substr.",
"continue",
";",
"}",
"$",
"part",
"=",
"$",
"substr",
"(",
"$",
"part",
",",
"$",
"offset",
",",
"$",
"length",
"-",
"$",
"totalLength",
")",
";",
"$",
"len",
"=",
"self",
"::",
"_strlen",
"(",
"$",
"part",
",",
"$",
"options",
")",
";",
"}",
"$",
"result",
".=",
"$",
"part",
";",
"$",
"totalLength",
"+=",
"$",
"len",
";",
"if",
"(",
"$",
"totalLength",
">=",
"$",
"length",
")",
"{",
"break",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Return part of a string.
### Options:
- `html` If true, HTML entities will be handled as decoded characters.
- `trimWidth` If true, will be truncated with specified width.
@param string $text The input string.
@param int $start The position to begin extracting.
@param int $length The desired length.
@param array $options An array of options.
@return string | [
"Return",
"part",
"of",
"a",
"string",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/Text.php#L772-L850 |
211,581 | cakephp/cakephp | src/Utility/Text.php | Text._removeLastWord | protected static function _removeLastWord($text)
{
$spacepos = mb_strrpos($text, ' ');
if ($spacepos !== false) {
$lastWord = mb_strrpos($text, $spacepos);
// Some languages are written without word separation.
// We recognize a string as a word if it doesn't contain any full-width characters.
if (mb_strwidth($lastWord) === mb_strlen($lastWord)) {
$text = mb_substr($text, 0, $spacepos);
}
return $text;
}
return '';
} | php | protected static function _removeLastWord($text)
{
$spacepos = mb_strrpos($text, ' ');
if ($spacepos !== false) {
$lastWord = mb_strrpos($text, $spacepos);
// Some languages are written without word separation.
// We recognize a string as a word if it doesn't contain any full-width characters.
if (mb_strwidth($lastWord) === mb_strlen($lastWord)) {
$text = mb_substr($text, 0, $spacepos);
}
return $text;
}
return '';
} | [
"protected",
"static",
"function",
"_removeLastWord",
"(",
"$",
"text",
")",
"{",
"$",
"spacepos",
"=",
"mb_strrpos",
"(",
"$",
"text",
",",
"' '",
")",
";",
"if",
"(",
"$",
"spacepos",
"!==",
"false",
")",
"{",
"$",
"lastWord",
"=",
"mb_strrpos",
"(",
"$",
"text",
",",
"$",
"spacepos",
")",
";",
"// Some languages are written without word separation.",
"// We recognize a string as a word if it doesn't contain any full-width characters.",
"if",
"(",
"mb_strwidth",
"(",
"$",
"lastWord",
")",
"===",
"mb_strlen",
"(",
"$",
"lastWord",
")",
")",
"{",
"$",
"text",
"=",
"mb_substr",
"(",
"$",
"text",
",",
"0",
",",
"$",
"spacepos",
")",
";",
"}",
"return",
"$",
"text",
";",
"}",
"return",
"''",
";",
"}"
] | Removes the last word from the input text.
@param string $text The input text
@return string | [
"Removes",
"the",
"last",
"word",
"from",
"the",
"input",
"text",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/Text.php#L858-L875 |
211,582 | cakephp/cakephp | src/Utility/Text.php | Text.toList | public static function toList(array $list, $and = null, $separator = ', ')
{
if ($and === null) {
$and = __d('cake', 'and');
}
if (count($list) > 1) {
return implode($separator, array_slice($list, null, -1)) . ' ' . $and . ' ' . array_pop($list);
}
return array_pop($list);
} | php | public static function toList(array $list, $and = null, $separator = ', ')
{
if ($and === null) {
$and = __d('cake', 'and');
}
if (count($list) > 1) {
return implode($separator, array_slice($list, null, -1)) . ' ' . $and . ' ' . array_pop($list);
}
return array_pop($list);
} | [
"public",
"static",
"function",
"toList",
"(",
"array",
"$",
"list",
",",
"$",
"and",
"=",
"null",
",",
"$",
"separator",
"=",
"', '",
")",
"{",
"if",
"(",
"$",
"and",
"===",
"null",
")",
"{",
"$",
"and",
"=",
"__d",
"(",
"'cake'",
",",
"'and'",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"list",
")",
">",
"1",
")",
"{",
"return",
"implode",
"(",
"$",
"separator",
",",
"array_slice",
"(",
"$",
"list",
",",
"null",
",",
"-",
"1",
")",
")",
".",
"' '",
".",
"$",
"and",
".",
"' '",
".",
"array_pop",
"(",
"$",
"list",
")",
";",
"}",
"return",
"array_pop",
"(",
"$",
"list",
")",
";",
"}"
] | Creates a comma separated list where the last two items are joined with 'and', forming natural language.
@param array $list The list to be joined.
@param string|null $and The word used to join the last and second last items together with. Defaults to 'and'.
@param string $separator The separator used to join all the other items together. Defaults to ', '.
@return string The glued together string.
@link https://book.cakephp.org/3.0/en/core-libraries/text.html#converting-an-array-to-sentence-form | [
"Creates",
"a",
"comma",
"separated",
"list",
"where",
"the",
"last",
"two",
"items",
"are",
"joined",
"with",
"and",
"forming",
"natural",
"language",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/Text.php#L931-L941 |
211,583 | cakephp/cakephp | src/Utility/Text.php | Text.isMultibyte | public static function isMultibyte($string)
{
$length = strlen($string);
for ($i = 0; $i < $length; $i++) {
$value = ord($string[$i]);
if ($value > 128) {
return true;
}
}
return false;
} | php | public static function isMultibyte($string)
{
$length = strlen($string);
for ($i = 0; $i < $length; $i++) {
$value = ord($string[$i]);
if ($value > 128) {
return true;
}
}
return false;
} | [
"public",
"static",
"function",
"isMultibyte",
"(",
"$",
"string",
")",
"{",
"$",
"length",
"=",
"strlen",
"(",
"$",
"string",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"value",
"=",
"ord",
"(",
"$",
"string",
"[",
"$",
"i",
"]",
")",
";",
"if",
"(",
"$",
"value",
">",
"128",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Check if the string contain multibyte characters
@param string $string value to test
@return bool | [
"Check",
"if",
"the",
"string",
"contain",
"multibyte",
"characters"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/Text.php#L949-L961 |
211,584 | cakephp/cakephp | src/Utility/Text.php | Text.transliterate | public static function transliterate($string, $transliterator = null)
{
if (!$transliterator) {
$transliterator = static::$_defaultTransliterator ?: static::$_defaultTransliteratorId;
}
return transliterator_transliterate($transliterator, $string);
} | php | public static function transliterate($string, $transliterator = null)
{
if (!$transliterator) {
$transliterator = static::$_defaultTransliterator ?: static::$_defaultTransliteratorId;
}
return transliterator_transliterate($transliterator, $string);
} | [
"public",
"static",
"function",
"transliterate",
"(",
"$",
"string",
",",
"$",
"transliterator",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"transliterator",
")",
"{",
"$",
"transliterator",
"=",
"static",
"::",
"$",
"_defaultTransliterator",
"?",
":",
"static",
"::",
"$",
"_defaultTransliteratorId",
";",
"}",
"return",
"transliterator_transliterate",
"(",
"$",
"transliterator",
",",
"$",
"string",
")",
";",
"}"
] | Transliterate string.
@param string $string String to transliterate.
@param \Transliterator|string|null $transliterator Either a Transliterator
instance, or a transliterator identifier string. If `null`, the default
transliterator (identifier) set via `setTransliteratorId()` or
`setTransliterator()` will be used.
@return string
@see https://secure.php.net/manual/en/transliterator.transliterate.php | [
"Transliterate",
"string",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/Text.php#L1128-L1135 |
211,585 | cakephp/cakephp | src/Shell/RoutesShell.php | RoutesShell.check | public function check($url)
{
try {
$request = new ServerRequest(['url' => $url]);
$route = Router::parseRequest($request);
$name = null;
foreach (Router::routes() as $r) {
if ($r->match($route)) {
$name = isset($r->options['_name']) ? $r->options['_name'] : $r->getName();
break;
}
}
unset($route['_matchedRoute']);
ksort($route);
$output = [
['Route name', 'URI template', 'Defaults'],
[$name, $url, json_encode($route)]
];
$this->helper('table')->output($output);
$this->out();
} catch (MissingRouteException $e) {
$this->warn("'$url' did not match any routes.");
$this->out();
return false;
}
return true;
} | php | public function check($url)
{
try {
$request = new ServerRequest(['url' => $url]);
$route = Router::parseRequest($request);
$name = null;
foreach (Router::routes() as $r) {
if ($r->match($route)) {
$name = isset($r->options['_name']) ? $r->options['_name'] : $r->getName();
break;
}
}
unset($route['_matchedRoute']);
ksort($route);
$output = [
['Route name', 'URI template', 'Defaults'],
[$name, $url, json_encode($route)]
];
$this->helper('table')->output($output);
$this->out();
} catch (MissingRouteException $e) {
$this->warn("'$url' did not match any routes.");
$this->out();
return false;
}
return true;
} | [
"public",
"function",
"check",
"(",
"$",
"url",
")",
"{",
"try",
"{",
"$",
"request",
"=",
"new",
"ServerRequest",
"(",
"[",
"'url'",
"=>",
"$",
"url",
"]",
")",
";",
"$",
"route",
"=",
"Router",
"::",
"parseRequest",
"(",
"$",
"request",
")",
";",
"$",
"name",
"=",
"null",
";",
"foreach",
"(",
"Router",
"::",
"routes",
"(",
")",
"as",
"$",
"r",
")",
"{",
"if",
"(",
"$",
"r",
"->",
"match",
"(",
"$",
"route",
")",
")",
"{",
"$",
"name",
"=",
"isset",
"(",
"$",
"r",
"->",
"options",
"[",
"'_name'",
"]",
")",
"?",
"$",
"r",
"->",
"options",
"[",
"'_name'",
"]",
":",
"$",
"r",
"->",
"getName",
"(",
")",
";",
"break",
";",
"}",
"}",
"unset",
"(",
"$",
"route",
"[",
"'_matchedRoute'",
"]",
")",
";",
"ksort",
"(",
"$",
"route",
")",
";",
"$",
"output",
"=",
"[",
"[",
"'Route name'",
",",
"'URI template'",
",",
"'Defaults'",
"]",
",",
"[",
"$",
"name",
",",
"$",
"url",
",",
"json_encode",
"(",
"$",
"route",
")",
"]",
"]",
";",
"$",
"this",
"->",
"helper",
"(",
"'table'",
")",
"->",
"output",
"(",
"$",
"output",
")",
";",
"$",
"this",
"->",
"out",
"(",
")",
";",
"}",
"catch",
"(",
"MissingRouteException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"warn",
"(",
"\"'$url' did not match any routes.\"",
")",
";",
"$",
"this",
"->",
"out",
"(",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Checks a url for the route that will be applied.
@param string $url The URL to parse
@return bool Success | [
"Checks",
"a",
"url",
"for",
"the",
"route",
"that",
"will",
"be",
"applied",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/RoutesShell.php#L54-L84 |
211,586 | cakephp/cakephp | src/Shell/RoutesShell.php | RoutesShell.generate | public function generate()
{
try {
$args = $this->_splitArgs($this->args);
$url = Router::url($args);
$this->out("> $url");
$this->out();
} catch (MissingRouteException $e) {
$this->err('<warning>The provided parameters do not match any routes.</warning>');
$this->out();
return false;
}
return true;
} | php | public function generate()
{
try {
$args = $this->_splitArgs($this->args);
$url = Router::url($args);
$this->out("> $url");
$this->out();
} catch (MissingRouteException $e) {
$this->err('<warning>The provided parameters do not match any routes.</warning>');
$this->out();
return false;
}
return true;
} | [
"public",
"function",
"generate",
"(",
")",
"{",
"try",
"{",
"$",
"args",
"=",
"$",
"this",
"->",
"_splitArgs",
"(",
"$",
"this",
"->",
"args",
")",
";",
"$",
"url",
"=",
"Router",
"::",
"url",
"(",
"$",
"args",
")",
";",
"$",
"this",
"->",
"out",
"(",
"\"> $url\"",
")",
";",
"$",
"this",
"->",
"out",
"(",
")",
";",
"}",
"catch",
"(",
"MissingRouteException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"err",
"(",
"'<warning>The provided parameters do not match any routes.</warning>'",
")",
";",
"$",
"this",
"->",
"out",
"(",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Generate a URL based on a set of parameters
Takes variadic arguments of key/value pairs.
@return bool Success | [
"Generate",
"a",
"URL",
"based",
"on",
"a",
"set",
"of",
"parameters"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/RoutesShell.php#L92-L107 |
211,587 | cakephp/cakephp | src/Shell/RoutesShell.php | RoutesShell._splitArgs | protected function _splitArgs($args)
{
$out = [];
foreach ($args as $arg) {
if (strpos($arg, ':') !== false) {
list($key, $value) = explode(':', $arg);
if (in_array($value, ['true', 'false'])) {
$value = $value === 'true';
}
$out[$key] = $value;
} else {
$out[] = $arg;
}
}
return $out;
} | php | protected function _splitArgs($args)
{
$out = [];
foreach ($args as $arg) {
if (strpos($arg, ':') !== false) {
list($key, $value) = explode(':', $arg);
if (in_array($value, ['true', 'false'])) {
$value = $value === 'true';
}
$out[$key] = $value;
} else {
$out[] = $arg;
}
}
return $out;
} | [
"protected",
"function",
"_splitArgs",
"(",
"$",
"args",
")",
"{",
"$",
"out",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"arg",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"arg",
",",
"':'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"key",
",",
"$",
"value",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"arg",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"value",
",",
"[",
"'true'",
",",
"'false'",
"]",
")",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"===",
"'true'",
";",
"}",
"$",
"out",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"out",
"[",
"]",
"=",
"$",
"arg",
";",
"}",
"}",
"return",
"$",
"out",
";",
"}"
] | Split the CLI arguments into a hash.
@param array $args The arguments to split.
@return array | [
"Split",
"the",
"CLI",
"arguments",
"into",
"a",
"hash",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/RoutesShell.php#L139-L155 |
211,588 | cakephp/cakephp | src/Database/Type.php | Type.build | public static function build($name)
{
if (isset(static::$_builtTypes[$name])) {
return static::$_builtTypes[$name];
}
if (!isset(static::$_types[$name])) {
throw new InvalidArgumentException(sprintf('Unknown type "%s"', $name));
}
if (is_string(static::$_types[$name])) {
return static::$_builtTypes[$name] = new static::$_types[$name]($name);
}
return static::$_builtTypes[$name] = static::$_types[$name];
} | php | public static function build($name)
{
if (isset(static::$_builtTypes[$name])) {
return static::$_builtTypes[$name];
}
if (!isset(static::$_types[$name])) {
throw new InvalidArgumentException(sprintf('Unknown type "%s"', $name));
}
if (is_string(static::$_types[$name])) {
return static::$_builtTypes[$name] = new static::$_types[$name]($name);
}
return static::$_builtTypes[$name] = static::$_types[$name];
} | [
"public",
"static",
"function",
"build",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"_builtTypes",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"static",
"::",
"$",
"_builtTypes",
"[",
"$",
"name",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"_types",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Unknown type \"%s\"'",
",",
"$",
"name",
")",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"static",
"::",
"$",
"_types",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"static",
"::",
"$",
"_builtTypes",
"[",
"$",
"name",
"]",
"=",
"new",
"static",
"::",
"$",
"_types",
"[",
"$",
"name",
"]",
"(",
"$",
"name",
")",
";",
"}",
"return",
"static",
"::",
"$",
"_builtTypes",
"[",
"$",
"name",
"]",
"=",
"static",
"::",
"$",
"_types",
"[",
"$",
"name",
"]",
";",
"}"
] | Returns a Type object capable of converting a type identified by name.
@param string $name type identifier
@throws \InvalidArgumentException If type identifier is unknown
@return \Cake\Database\Type | [
"Returns",
"a",
"Type",
"object",
"capable",
"of",
"converting",
"a",
"type",
"identified",
"by",
"name",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Type.php#L101-L114 |
211,589 | cakephp/cakephp | src/Database/Type.php | Type.buildAll | public static function buildAll()
{
$result = [];
foreach (static::$_types as $name => $type) {
$result[$name] = isset(static::$_builtTypes[$name]) ? static::$_builtTypes[$name] : static::build($name);
}
return $result;
} | php | public static function buildAll()
{
$result = [];
foreach (static::$_types as $name => $type) {
$result[$name] = isset(static::$_builtTypes[$name]) ? static::$_builtTypes[$name] : static::build($name);
}
return $result;
} | [
"public",
"static",
"function",
"buildAll",
"(",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"static",
"::",
"$",
"_types",
"as",
"$",
"name",
"=>",
"$",
"type",
")",
"{",
"$",
"result",
"[",
"$",
"name",
"]",
"=",
"isset",
"(",
"static",
"::",
"$",
"_builtTypes",
"[",
"$",
"name",
"]",
")",
"?",
"static",
"::",
"$",
"_builtTypes",
"[",
"$",
"name",
"]",
":",
"static",
"::",
"build",
"(",
"$",
"name",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns an arrays with all the mapped type objects, indexed by name.
@return array | [
"Returns",
"an",
"arrays",
"with",
"all",
"the",
"mapped",
"type",
"objects",
"indexed",
"by",
"name",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Type.php#L121-L129 |
211,590 | cakephp/cakephp | src/Database/Type.php | Type._basicTypeCast | protected function _basicTypeCast($value)
{
deprecationWarning(
'Using Type::_basicTypeCast() is deprecated. ' .
"The '{$this->_name}' type needs to be updated to implement `TypeInterface`."
);
if ($value === null) {
return null;
}
if (!empty(static::$_basicTypes[$this->_name])) {
$typeInfo = static::$_basicTypes[$this->_name];
if (isset($typeInfo['callback'])) {
return $typeInfo['callback']($value);
}
}
return $value;
} | php | protected function _basicTypeCast($value)
{
deprecationWarning(
'Using Type::_basicTypeCast() is deprecated. ' .
"The '{$this->_name}' type needs to be updated to implement `TypeInterface`."
);
if ($value === null) {
return null;
}
if (!empty(static::$_basicTypes[$this->_name])) {
$typeInfo = static::$_basicTypes[$this->_name];
if (isset($typeInfo['callback'])) {
return $typeInfo['callback']($value);
}
}
return $value;
} | [
"protected",
"function",
"_basicTypeCast",
"(",
"$",
"value",
")",
"{",
"deprecationWarning",
"(",
"'Using Type::_basicTypeCast() is deprecated. '",
".",
"\"The '{$this->_name}' type needs to be updated to implement `TypeInterface`.\"",
")",
";",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"static",
"::",
"$",
"_basicTypes",
"[",
"$",
"this",
"->",
"_name",
"]",
")",
")",
"{",
"$",
"typeInfo",
"=",
"static",
"::",
"$",
"_basicTypes",
"[",
"$",
"this",
"->",
"_name",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"typeInfo",
"[",
"'callback'",
"]",
")",
")",
"{",
"return",
"$",
"typeInfo",
"[",
"'callback'",
"]",
"(",
"$",
"value",
")",
";",
"}",
"}",
"return",
"$",
"value",
";",
"}"
] | Checks whether this type is a basic one and can be converted using a callback
If it is, returns converted value
@param mixed $value Value to be converted to PHP equivalent
@return mixed
@deprecated 3.1 All types should now be a specific class | [
"Checks",
"whether",
"this",
"type",
"is",
"a",
"basic",
"one",
"and",
"can",
"be",
"converted",
"using",
"a",
"callback",
"If",
"it",
"is",
"returns",
"converted",
"value"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Type.php#L284-L301 |
211,591 | cakephp/cakephp | src/Database/Type.php | Type.boolval | public static function boolval($value)
{
deprecationWarning('Type::boolval() is deprecated.');
if (is_string($value) && !is_numeric($value)) {
return strtolower($value) === 'true';
}
return !empty($value);
} | php | public static function boolval($value)
{
deprecationWarning('Type::boolval() is deprecated.');
if (is_string($value) && !is_numeric($value)) {
return strtolower($value) === 'true';
}
return !empty($value);
} | [
"public",
"static",
"function",
"boolval",
"(",
"$",
"value",
")",
"{",
"deprecationWarning",
"(",
"'Type::boolval() is deprecated.'",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
"&&",
"!",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"return",
"strtolower",
"(",
"$",
"value",
")",
"===",
"'true'",
";",
"}",
"return",
"!",
"empty",
"(",
"$",
"value",
")",
";",
"}"
] | Type converter for boolean values.
Will convert string true/false into booleans.
@param mixed $value The value to convert to a boolean.
@return bool
@deprecated 3.1.8 This method is now unused. | [
"Type",
"converter",
"for",
"boolean",
"values",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Type.php#L324-L332 |
211,592 | cakephp/cakephp | src/Database/Type/DateTimeType.php | DateTimeType.toDatabase | public function toDatabase($value, Driver $driver)
{
if ($value === null || is_string($value)) {
return $value;
}
if (is_int($value)) {
$class = $this->_className;
$value = new $class('@' . $value);
}
$format = (array)$this->_format;
if ($this->dbTimezone !== null
&& $this->dbTimezone->getName() !== $value->getTimezone()->getName()
) {
if (!$value instanceof DateTimeImmutable) {
$value = clone $value;
}
$value = $value->setTimezone($this->dbTimezone);
}
return $value->format(array_shift($format));
} | php | public function toDatabase($value, Driver $driver)
{
if ($value === null || is_string($value)) {
return $value;
}
if (is_int($value)) {
$class = $this->_className;
$value = new $class('@' . $value);
}
$format = (array)$this->_format;
if ($this->dbTimezone !== null
&& $this->dbTimezone->getName() !== $value->getTimezone()->getName()
) {
if (!$value instanceof DateTimeImmutable) {
$value = clone $value;
}
$value = $value->setTimezone($this->dbTimezone);
}
return $value->format(array_shift($format));
} | [
"public",
"function",
"toDatabase",
"(",
"$",
"value",
",",
"Driver",
"$",
"driver",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
"||",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"if",
"(",
"is_int",
"(",
"$",
"value",
")",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"_className",
";",
"$",
"value",
"=",
"new",
"$",
"class",
"(",
"'@'",
".",
"$",
"value",
")",
";",
"}",
"$",
"format",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"_format",
";",
"if",
"(",
"$",
"this",
"->",
"dbTimezone",
"!==",
"null",
"&&",
"$",
"this",
"->",
"dbTimezone",
"->",
"getName",
"(",
")",
"!==",
"$",
"value",
"->",
"getTimezone",
"(",
")",
"->",
"getName",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"value",
"instanceof",
"DateTimeImmutable",
")",
"{",
"$",
"value",
"=",
"clone",
"$",
"value",
";",
"}",
"$",
"value",
"=",
"$",
"value",
"->",
"setTimezone",
"(",
"$",
"this",
"->",
"dbTimezone",
")",
";",
"}",
"return",
"$",
"value",
"->",
"format",
"(",
"array_shift",
"(",
"$",
"format",
")",
")",
";",
"}"
] | Convert DateTime instance into strings.
@param string|int|\DateTime|\DateTimeImmutable $value The value to convert.
@param \Cake\Database\Driver $driver The driver instance to convert with.
@return string|null | [
"Convert",
"DateTime",
"instance",
"into",
"strings",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Type/DateTimeType.php#L130-L152 |
211,593 | cakephp/cakephp | src/Database/Type/DateTimeType.php | DateTimeType.setTimezone | public function setTimezone($timezone)
{
if (is_string($timezone)) {
$timezone = new DateTimeZone($timezone);
}
$this->dbTimezone = $timezone;
return $this;
} | php | public function setTimezone($timezone)
{
if (is_string($timezone)) {
$timezone = new DateTimeZone($timezone);
}
$this->dbTimezone = $timezone;
return $this;
} | [
"public",
"function",
"setTimezone",
"(",
"$",
"timezone",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"timezone",
")",
")",
"{",
"$",
"timezone",
"=",
"new",
"DateTimeZone",
"(",
"$",
"timezone",
")",
";",
"}",
"$",
"this",
"->",
"dbTimezone",
"=",
"$",
"timezone",
";",
"return",
"$",
"this",
";",
"}"
] | Set database timezone.
Specified timezone will be set for DateTime objects before generating
datetime string for saving to database. If `null` no timezone conversion
will be done.
@param string|\DateTimeZone|null $timezone Database timezone.
@return $this | [
"Set",
"database",
"timezone",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Type/DateTimeType.php#L164-L172 |
211,594 | cakephp/cakephp | src/Database/Type/DateTimeType.php | DateTimeType.toPHP | public function toPHP($value, Driver $driver)
{
if ($value === null || strpos($value, '0000-00-00') === 0) {
return null;
}
$instance = clone $this->_datetimeInstance;
$instance = $instance->modify($value);
if ($this->setToDateStart) {
$instance = $instance->setTime(0, 0, 0);
}
return $instance;
} | php | public function toPHP($value, Driver $driver)
{
if ($value === null || strpos($value, '0000-00-00') === 0) {
return null;
}
$instance = clone $this->_datetimeInstance;
$instance = $instance->modify($value);
if ($this->setToDateStart) {
$instance = $instance->setTime(0, 0, 0);
}
return $instance;
} | [
"public",
"function",
"toPHP",
"(",
"$",
"value",
",",
"Driver",
"$",
"driver",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
"||",
"strpos",
"(",
"$",
"value",
",",
"'0000-00-00'",
")",
"===",
"0",
")",
"{",
"return",
"null",
";",
"}",
"$",
"instance",
"=",
"clone",
"$",
"this",
"->",
"_datetimeInstance",
";",
"$",
"instance",
"=",
"$",
"instance",
"->",
"modify",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"this",
"->",
"setToDateStart",
")",
"{",
"$",
"instance",
"=",
"$",
"instance",
"->",
"setTime",
"(",
"0",
",",
"0",
",",
"0",
")",
";",
"}",
"return",
"$",
"instance",
";",
"}"
] | Convert strings into DateTime instances.
@param string $value The value to convert.
@param \Cake\Database\Driver $driver The driver instance to convert with.
@return \Cake\I18n\Time|\DateTime|null | [
"Convert",
"strings",
"into",
"DateTime",
"instances",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Type/DateTimeType.php#L181-L195 |
211,595 | cakephp/cakephp | src/Database/Type/DateTimeType.php | DateTimeType._setClassName | protected function _setClassName($class, $fallback)
{
if (!class_exists($class)) {
$class = $fallback;
}
$this->_className = $class;
$this->_datetimeInstance = new $this->_className;
} | php | protected function _setClassName($class, $fallback)
{
if (!class_exists($class)) {
$class = $fallback;
}
$this->_className = $class;
$this->_datetimeInstance = new $this->_className;
} | [
"protected",
"function",
"_setClassName",
"(",
"$",
"class",
",",
"$",
"fallback",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class",
"=",
"$",
"fallback",
";",
"}",
"$",
"this",
"->",
"_className",
"=",
"$",
"class",
";",
"$",
"this",
"->",
"_datetimeInstance",
"=",
"new",
"$",
"this",
"->",
"_className",
";",
"}"
] | Set the classname to use when building objects.
@param string $class The classname to use.
@param string $fallback The classname to use when the preferred class does not exist.
@return void | [
"Set",
"the",
"classname",
"to",
"use",
"when",
"building",
"objects",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Type/DateTimeType.php#L369-L376 |
211,596 | cakephp/cakephp | src/Http/CorsBuilder.php | CorsBuilder.build | public function build()
{
$response = $this->_response;
if (empty($this->_origin)) {
return $response;
}
if (isset($this->_headers['Access-Control-Allow-Origin'])) {
foreach ($this->_headers as $key => $value) {
$response = $response->withHeader($key, $value);
}
}
return $response;
} | php | public function build()
{
$response = $this->_response;
if (empty($this->_origin)) {
return $response;
}
if (isset($this->_headers['Access-Control-Allow-Origin'])) {
foreach ($this->_headers as $key => $value) {
$response = $response->withHeader($key, $value);
}
}
return $response;
} | [
"public",
"function",
"build",
"(",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"_response",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_origin",
")",
")",
"{",
"return",
"$",
"response",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_headers",
"[",
"'Access-Control-Allow-Origin'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_headers",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"response",
"=",
"$",
"response",
"->",
"withHeader",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}",
"return",
"$",
"response",
";",
"}"
] | Apply the queued headers to the response.
If the builder has no Origin, or if there are no allowed domains,
or if the allowed domains do not match the Origin header no headers will be applied.
@return \Psr\Http\Message\MessageInterface A new instance of the response with new headers. | [
"Apply",
"the",
"queued",
"headers",
"to",
"the",
"response",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/CorsBuilder.php#L84-L98 |
211,597 | cakephp/cakephp | src/Http/CorsBuilder.php | CorsBuilder.allowOrigin | public function allowOrigin($domain)
{
$allowed = $this->_normalizeDomains((array)$domain);
foreach ($allowed as $domain) {
if (!preg_match($domain['preg'], $this->_origin)) {
continue;
}
$value = $domain['original'] === '*' ? '*' : $this->_origin;
$this->_headers['Access-Control-Allow-Origin'] = $value;
break;
}
return $this;
} | php | public function allowOrigin($domain)
{
$allowed = $this->_normalizeDomains((array)$domain);
foreach ($allowed as $domain) {
if (!preg_match($domain['preg'], $this->_origin)) {
continue;
}
$value = $domain['original'] === '*' ? '*' : $this->_origin;
$this->_headers['Access-Control-Allow-Origin'] = $value;
break;
}
return $this;
} | [
"public",
"function",
"allowOrigin",
"(",
"$",
"domain",
")",
"{",
"$",
"allowed",
"=",
"$",
"this",
"->",
"_normalizeDomains",
"(",
"(",
"array",
")",
"$",
"domain",
")",
";",
"foreach",
"(",
"$",
"allowed",
"as",
"$",
"domain",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"$",
"domain",
"[",
"'preg'",
"]",
",",
"$",
"this",
"->",
"_origin",
")",
")",
"{",
"continue",
";",
"}",
"$",
"value",
"=",
"$",
"domain",
"[",
"'original'",
"]",
"===",
"'*'",
"?",
"'*'",
":",
"$",
"this",
"->",
"_origin",
";",
"$",
"this",
"->",
"_headers",
"[",
"'Access-Control-Allow-Origin'",
"]",
"=",
"$",
"value",
";",
"break",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set the list of allowed domains.
Accepts a string or an array of domains that have CORS enabled.
You can use `*.example.com` wildcards to accept subdomains, or `*` to allow all domains
@param string|array $domain The allowed domains
@return $this | [
"Set",
"the",
"list",
"of",
"allowed",
"domains",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/CorsBuilder.php#L109-L122 |
211,598 | cakephp/cakephp | src/Http/CorsBuilder.php | CorsBuilder._normalizeDomains | protected function _normalizeDomains($domains)
{
$result = [];
foreach ($domains as $domain) {
if ($domain === '*') {
$result[] = ['preg' => '@.@', 'original' => '*'];
continue;
}
$original = $preg = $domain;
if (strpos($domain, '://') === false) {
$preg = ($this->_isSsl ? 'https://' : 'http://') . $domain;
}
$preg = '@^' . str_replace('\*', '.*', preg_quote($preg, '@')) . '$@';
$result[] = compact('original', 'preg');
}
return $result;
} | php | protected function _normalizeDomains($domains)
{
$result = [];
foreach ($domains as $domain) {
if ($domain === '*') {
$result[] = ['preg' => '@.@', 'original' => '*'];
continue;
}
$original = $preg = $domain;
if (strpos($domain, '://') === false) {
$preg = ($this->_isSsl ? 'https://' : 'http://') . $domain;
}
$preg = '@^' . str_replace('\*', '.*', preg_quote($preg, '@')) . '$@';
$result[] = compact('original', 'preg');
}
return $result;
} | [
"protected",
"function",
"_normalizeDomains",
"(",
"$",
"domains",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"domains",
"as",
"$",
"domain",
")",
"{",
"if",
"(",
"$",
"domain",
"===",
"'*'",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"[",
"'preg'",
"=>",
"'@.@'",
",",
"'original'",
"=>",
"'*'",
"]",
";",
"continue",
";",
"}",
"$",
"original",
"=",
"$",
"preg",
"=",
"$",
"domain",
";",
"if",
"(",
"strpos",
"(",
"$",
"domain",
",",
"'://'",
")",
"===",
"false",
")",
"{",
"$",
"preg",
"=",
"(",
"$",
"this",
"->",
"_isSsl",
"?",
"'https://'",
":",
"'http://'",
")",
".",
"$",
"domain",
";",
"}",
"$",
"preg",
"=",
"'@^'",
".",
"str_replace",
"(",
"'\\*'",
",",
"'.*'",
",",
"preg_quote",
"(",
"$",
"preg",
",",
"'@'",
")",
")",
".",
"'$@'",
";",
"$",
"result",
"[",
"]",
"=",
"compact",
"(",
"'original'",
",",
"'preg'",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Normalize the origin to regular expressions and put in an array format
@param array $domains Domain names to normalize.
@return array | [
"Normalize",
"the",
"origin",
"to",
"regular",
"expressions",
"and",
"put",
"in",
"an",
"array",
"format"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/CorsBuilder.php#L130-L148 |
211,599 | cakephp/cakephp | src/Controller/Controller.php | Controller.components | public function components($components = null)
{
if ($components === null && $this->_components === null) {
$this->_components = new ComponentRegistry($this);
}
if ($components !== null) {
$components->setController($this);
$this->_components = $components;
}
return $this->_components;
} | php | public function components($components = null)
{
if ($components === null && $this->_components === null) {
$this->_components = new ComponentRegistry($this);
}
if ($components !== null) {
$components->setController($this);
$this->_components = $components;
}
return $this->_components;
} | [
"public",
"function",
"components",
"(",
"$",
"components",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"components",
"===",
"null",
"&&",
"$",
"this",
"->",
"_components",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_components",
"=",
"new",
"ComponentRegistry",
"(",
"$",
"this",
")",
";",
"}",
"if",
"(",
"$",
"components",
"!==",
"null",
")",
"{",
"$",
"components",
"->",
"setController",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"_components",
"=",
"$",
"components",
";",
"}",
"return",
"$",
"this",
"->",
"_components",
";",
"}"
] | Get the component registry for this controller.
If called with the first parameter, it will be set as the controller $this->_components property
@param \Cake\Controller\ComponentRegistry|null $components Component registry.
@return \Cake\Controller\ComponentRegistry | [
"Get",
"the",
"component",
"registry",
"for",
"this",
"controller",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Controller.php#L301-L312 |
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.