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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
210,700 | cakephp/cakephp | src/Event/Decorator/ConditionDecorator.php | ConditionDecorator._evaluateCondition | protected function _evaluateCondition($condition, Event $event)
{
if (!isset($this->_options[$condition])) {
return $condition !== 'unless';
}
if (!is_callable($this->_options[$condition])) {
throw new RuntimeException(self::class . ' the `' . $condition . '` condition is not a callable!');
}
return $this->_options[$condition]($event);
} | php | protected function _evaluateCondition($condition, Event $event)
{
if (!isset($this->_options[$condition])) {
return $condition !== 'unless';
}
if (!is_callable($this->_options[$condition])) {
throw new RuntimeException(self::class . ' the `' . $condition . '` condition is not a callable!');
}
return $this->_options[$condition]($event);
} | [
"protected",
"function",
"_evaluateCondition",
"(",
"$",
"condition",
",",
"Event",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_options",
"[",
"$",
"condition",
"]",
")",
")",
"{",
"return",
"$",
"condition",
"!==",
"'unless'",
";",
"}",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"this",
"->",
"_options",
"[",
"$",
"condition",
"]",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"self",
"::",
"class",
".",
"' the `'",
".",
"$",
"condition",
".",
"'` condition is not a callable!'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_options",
"[",
"$",
"condition",
"]",
"(",
"$",
"event",
")",
";",
"}"
] | Evaluates the filter conditions
@param string $condition Condition type
@param \Cake\Event\Event $event Event object
@return bool | [
"Evaluates",
"the",
"filter",
"conditions"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Event/Decorator/ConditionDecorator.php#L63-L73 |
210,701 | cakephp/cakephp | src/Auth/Storage/SessionStorage.php | SessionStorage.read | public function read()
{
if ($this->_user !== null) {
return $this->_user ?: null;
}
$this->_user = $this->_session->read($this->_config['key']) ?: false;
return $this->_user ?: null;
} | php | public function read()
{
if ($this->_user !== null) {
return $this->_user ?: null;
}
$this->_user = $this->_session->read($this->_config['key']) ?: false;
return $this->_user ?: null;
} | [
"public",
"function",
"read",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_user",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_user",
"?",
":",
"null",
";",
"}",
"$",
"this",
"->",
"_user",
"=",
"$",
"this",
"->",
"_session",
"->",
"read",
"(",
"$",
"this",
"->",
"_config",
"[",
"'key'",
"]",
")",
"?",
":",
"false",
";",
"return",
"$",
"this",
"->",
"_user",
"?",
":",
"null",
";",
"}"
] | Read user record from session.
@return array|null User record if available else null. | [
"Read",
"user",
"record",
"from",
"session",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Auth/Storage/SessionStorage.php#L78-L87 |
210,702 | cakephp/cakephp | src/Auth/Storage/SessionStorage.php | SessionStorage.write | public function write($user)
{
$this->_user = $user;
$this->_session->renew();
$this->_session->write($this->_config['key'], $user);
} | php | public function write($user)
{
$this->_user = $user;
$this->_session->renew();
$this->_session->write($this->_config['key'], $user);
} | [
"public",
"function",
"write",
"(",
"$",
"user",
")",
"{",
"$",
"this",
"->",
"_user",
"=",
"$",
"user",
";",
"$",
"this",
"->",
"_session",
"->",
"renew",
"(",
")",
";",
"$",
"this",
"->",
"_session",
"->",
"write",
"(",
"$",
"this",
"->",
"_config",
"[",
"'key'",
"]",
",",
"$",
"user",
")",
";",
"}"
] | Write user record to session.
The session id is also renewed to help mitigate issues with session replays.
@param array|\ArrayAccess $user User record.
@return void | [
"Write",
"user",
"record",
"to",
"session",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Auth/Storage/SessionStorage.php#L97-L103 |
210,703 | cakephp/cakephp | src/Auth/Storage/SessionStorage.php | SessionStorage.delete | public function delete()
{
$this->_user = false;
$this->_session->delete($this->_config['key']);
$this->_session->renew();
} | php | public function delete()
{
$this->_user = false;
$this->_session->delete($this->_config['key']);
$this->_session->renew();
} | [
"public",
"function",
"delete",
"(",
")",
"{",
"$",
"this",
"->",
"_user",
"=",
"false",
";",
"$",
"this",
"->",
"_session",
"->",
"delete",
"(",
"$",
"this",
"->",
"_config",
"[",
"'key'",
"]",
")",
";",
"$",
"this",
"->",
"_session",
"->",
"renew",
"(",
")",
";",
"}"
] | Delete user record from session.
The session id is also renewed to help mitigate issues with session replays.
@return void | [
"Delete",
"user",
"record",
"from",
"session",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Auth/Storage/SessionStorage.php#L112-L118 |
210,704 | cakephp/cakephp | src/Routing/DispatcherFactory.php | DispatcherFactory.add | public static function add($filter, array $options = [])
{
if (is_string($filter)) {
$filter = static::_createFilter($filter, $options);
}
static::$_stack[] = $filter;
return $filter;
} | php | public static function add($filter, array $options = [])
{
if (is_string($filter)) {
$filter = static::_createFilter($filter, $options);
}
static::$_stack[] = $filter;
return $filter;
} | [
"public",
"static",
"function",
"add",
"(",
"$",
"filter",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"filter",
")",
")",
"{",
"$",
"filter",
"=",
"static",
"::",
"_createFilter",
"(",
"$",
"filter",
",",
"$",
"options",
")",
";",
"}",
"static",
"::",
"$",
"_stack",
"[",
"]",
"=",
"$",
"filter",
";",
"return",
"$",
"filter",
";",
"}"
] | Add a new middleware object to the stack of middleware
that will be executed.
Instances of filters will be re-used across all sub-requests
in a request.
@param string|\Cake\Routing\DispatcherFilter $filter Either the classname of the filter
or an instance to use.
@param array $options Constructor arguments/options for the filter if you are using a string name.
If you are passing an instance, this argument will be ignored.
@return \Cake\Routing\DispatcherFilter | [
"Add",
"a",
"new",
"middleware",
"object",
"to",
"the",
"stack",
"of",
"middleware",
"that",
"will",
"be",
"executed",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/DispatcherFactory.php#L50-L58 |
210,705 | cakephp/cakephp | src/Routing/DispatcherFactory.php | DispatcherFactory._createFilter | protected static function _createFilter($name, $options)
{
$className = App::className($name, 'Routing/Filter', 'Filter');
if (!$className) {
$msg = sprintf('Cannot locate dispatcher filter named "%s".', $name);
throw new MissingDispatcherFilterException($msg);
}
return new $className($options);
} | php | protected static function _createFilter($name, $options)
{
$className = App::className($name, 'Routing/Filter', 'Filter');
if (!$className) {
$msg = sprintf('Cannot locate dispatcher filter named "%s".', $name);
throw new MissingDispatcherFilterException($msg);
}
return new $className($options);
} | [
"protected",
"static",
"function",
"_createFilter",
"(",
"$",
"name",
",",
"$",
"options",
")",
"{",
"$",
"className",
"=",
"App",
"::",
"className",
"(",
"$",
"name",
",",
"'Routing/Filter'",
",",
"'Filter'",
")",
";",
"if",
"(",
"!",
"$",
"className",
")",
"{",
"$",
"msg",
"=",
"sprintf",
"(",
"'Cannot locate dispatcher filter named \"%s\".'",
",",
"$",
"name",
")",
";",
"throw",
"new",
"MissingDispatcherFilterException",
"(",
"$",
"msg",
")",
";",
"}",
"return",
"new",
"$",
"className",
"(",
"$",
"options",
")",
";",
"}"
] | Create an instance of a filter.
@param string $name The name of the filter to build.
@param array $options Constructor arguments/options for the filter.
@return \Cake\Routing\DispatcherFilter
@throws \Cake\Routing\Exception\MissingDispatcherFilterException When filters cannot be found. | [
"Create",
"an",
"instance",
"of",
"a",
"filter",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/DispatcherFactory.php#L68-L77 |
210,706 | cakephp/cakephp | src/Routing/DispatcherFactory.php | DispatcherFactory.create | public static function create()
{
$dispatcher = new Dispatcher();
foreach (static::$_stack as $middleware) {
$dispatcher->addFilter($middleware);
}
return $dispatcher;
} | php | public static function create()
{
$dispatcher = new Dispatcher();
foreach (static::$_stack as $middleware) {
$dispatcher->addFilter($middleware);
}
return $dispatcher;
} | [
"public",
"static",
"function",
"create",
"(",
")",
"{",
"$",
"dispatcher",
"=",
"new",
"Dispatcher",
"(",
")",
";",
"foreach",
"(",
"static",
"::",
"$",
"_stack",
"as",
"$",
"middleware",
")",
"{",
"$",
"dispatcher",
"->",
"addFilter",
"(",
"$",
"middleware",
")",
";",
"}",
"return",
"$",
"dispatcher",
";",
"}"
] | Create a dispatcher that has all the configured middleware applied.
@return \Cake\Routing\Dispatcher | [
"Create",
"a",
"dispatcher",
"that",
"has",
"all",
"the",
"configured",
"middleware",
"applied",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/DispatcherFactory.php#L84-L92 |
210,707 | cakephp/cakephp | src/Http/Cookie/Cookie.php | Cookie.toHeaderValue | public function toHeaderValue()
{
$value = $this->value;
if ($this->isExpanded) {
$value = $this->_flatten($this->value);
}
$headerValue[] = sprintf('%s=%s', $this->name, rawurlencode($value));
if ($this->expiresAt) {
$headerValue[] = sprintf('expires=%s', $this->getFormattedExpires());
}
if ($this->path !== '') {
$headerValue[] = sprintf('path=%s', $this->path);
}
if ($this->domain !== '') {
$headerValue[] = sprintf('domain=%s', $this->domain);
}
if ($this->secure) {
$headerValue[] = 'secure';
}
if ($this->httpOnly) {
$headerValue[] = 'httponly';
}
return implode('; ', $headerValue);
} | php | public function toHeaderValue()
{
$value = $this->value;
if ($this->isExpanded) {
$value = $this->_flatten($this->value);
}
$headerValue[] = sprintf('%s=%s', $this->name, rawurlencode($value));
if ($this->expiresAt) {
$headerValue[] = sprintf('expires=%s', $this->getFormattedExpires());
}
if ($this->path !== '') {
$headerValue[] = sprintf('path=%s', $this->path);
}
if ($this->domain !== '') {
$headerValue[] = sprintf('domain=%s', $this->domain);
}
if ($this->secure) {
$headerValue[] = 'secure';
}
if ($this->httpOnly) {
$headerValue[] = 'httponly';
}
return implode('; ', $headerValue);
} | [
"public",
"function",
"toHeaderValue",
"(",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"value",
";",
"if",
"(",
"$",
"this",
"->",
"isExpanded",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"_flatten",
"(",
"$",
"this",
"->",
"value",
")",
";",
"}",
"$",
"headerValue",
"[",
"]",
"=",
"sprintf",
"(",
"'%s=%s'",
",",
"$",
"this",
"->",
"name",
",",
"rawurlencode",
"(",
"$",
"value",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"expiresAt",
")",
"{",
"$",
"headerValue",
"[",
"]",
"=",
"sprintf",
"(",
"'expires=%s'",
",",
"$",
"this",
"->",
"getFormattedExpires",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"path",
"!==",
"''",
")",
"{",
"$",
"headerValue",
"[",
"]",
"=",
"sprintf",
"(",
"'path=%s'",
",",
"$",
"this",
"->",
"path",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"domain",
"!==",
"''",
")",
"{",
"$",
"headerValue",
"[",
"]",
"=",
"sprintf",
"(",
"'domain=%s'",
",",
"$",
"this",
"->",
"domain",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"secure",
")",
"{",
"$",
"headerValue",
"[",
"]",
"=",
"'secure'",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"httpOnly",
")",
"{",
"$",
"headerValue",
"[",
"]",
"=",
"'httponly'",
";",
"}",
"return",
"implode",
"(",
"'; '",
",",
"$",
"headerValue",
")",
";",
"}"
] | Returns a header value as string
@return string | [
"Returns",
"a",
"header",
"value",
"as",
"string"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Cookie/Cookie.php#L159-L184 |
210,708 | cakephp/cakephp | src/Http/Cookie/Cookie.php | Cookie.validateName | protected function validateName($name)
{
if (preg_match("/[=,;\t\r\n\013\014]/", $name)) {
throw new InvalidArgumentException(
sprintf('The cookie name `%s` contains invalid characters.', $name)
);
}
if (empty($name)) {
throw new InvalidArgumentException('The cookie name cannot be empty.');
}
} | php | protected function validateName($name)
{
if (preg_match("/[=,;\t\r\n\013\014]/", $name)) {
throw new InvalidArgumentException(
sprintf('The cookie name `%s` contains invalid characters.', $name)
);
}
if (empty($name)) {
throw new InvalidArgumentException('The cookie name cannot be empty.');
}
} | [
"protected",
"function",
"validateName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"preg_match",
"(",
"\"/[=,;\\t\\r\\n\\013\\014]/\"",
",",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The cookie name `%s` contains invalid characters.'",
",",
"$",
"name",
")",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The cookie name cannot be empty.'",
")",
";",
"}",
"}"
] | Validates the cookie name
@param string $name Name of the cookie
@return void
@throws \InvalidArgumentException
@link https://tools.ietf.org/html/rfc2616#section-2.2 Rules for naming cookies. | [
"Validates",
"the",
"cookie",
"name"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Cookie/Cookie.php#L222-L233 |
210,709 | cakephp/cakephp | src/Http/Cookie/Cookie.php | Cookie.check | public function check($path)
{
if ($this->isExpanded === false) {
$this->value = $this->_expand($this->value);
}
return Hash::check($this->value, $path);
} | php | public function check($path)
{
if ($this->isExpanded === false) {
$this->value = $this->_expand($this->value);
}
return Hash::check($this->value, $path);
} | [
"public",
"function",
"check",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isExpanded",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"value",
"=",
"$",
"this",
"->",
"_expand",
"(",
"$",
"this",
"->",
"value",
")",
";",
"}",
"return",
"Hash",
"::",
"check",
"(",
"$",
"this",
"->",
"value",
",",
"$",
"path",
")",
";",
"}"
] | Checks if a value exists in the cookie data.
This method will expand serialized complex data,
on first use.
@param string $path Path to check
@return bool | [
"Checks",
"if",
"a",
"value",
"exists",
"in",
"the",
"cookie",
"data",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Cookie/Cookie.php#L479-L486 |
210,710 | cakephp/cakephp | src/Http/Cookie/Cookie.php | Cookie.withAddedValue | public function withAddedValue($path, $value)
{
$new = clone $this;
if ($new->isExpanded === false) {
$new->value = $new->_expand($new->value);
}
$new->value = Hash::insert($new->value, $path, $value);
return $new;
} | php | public function withAddedValue($path, $value)
{
$new = clone $this;
if ($new->isExpanded === false) {
$new->value = $new->_expand($new->value);
}
$new->value = Hash::insert($new->value, $path, $value);
return $new;
} | [
"public",
"function",
"withAddedValue",
"(",
"$",
"path",
",",
"$",
"value",
")",
"{",
"$",
"new",
"=",
"clone",
"$",
"this",
";",
"if",
"(",
"$",
"new",
"->",
"isExpanded",
"===",
"false",
")",
"{",
"$",
"new",
"->",
"value",
"=",
"$",
"new",
"->",
"_expand",
"(",
"$",
"new",
"->",
"value",
")",
";",
"}",
"$",
"new",
"->",
"value",
"=",
"Hash",
"::",
"insert",
"(",
"$",
"new",
"->",
"value",
",",
"$",
"path",
",",
"$",
"value",
")",
";",
"return",
"$",
"new",
";",
"}"
] | Create a new cookie with updated data.
@param string $path Path to write to
@param mixed $value Value to write
@return static | [
"Create",
"a",
"new",
"cookie",
"with",
"updated",
"data",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Cookie/Cookie.php#L495-L504 |
210,711 | cakephp/cakephp | src/Http/Cookie/Cookie.php | Cookie.withoutAddedValue | public function withoutAddedValue($path)
{
$new = clone $this;
if ($new->isExpanded === false) {
$new->value = $new->_expand($new->value);
}
$new->value = Hash::remove($new->value, $path);
return $new;
} | php | public function withoutAddedValue($path)
{
$new = clone $this;
if ($new->isExpanded === false) {
$new->value = $new->_expand($new->value);
}
$new->value = Hash::remove($new->value, $path);
return $new;
} | [
"public",
"function",
"withoutAddedValue",
"(",
"$",
"path",
")",
"{",
"$",
"new",
"=",
"clone",
"$",
"this",
";",
"if",
"(",
"$",
"new",
"->",
"isExpanded",
"===",
"false",
")",
"{",
"$",
"new",
"->",
"value",
"=",
"$",
"new",
"->",
"_expand",
"(",
"$",
"new",
"->",
"value",
")",
";",
"}",
"$",
"new",
"->",
"value",
"=",
"Hash",
"::",
"remove",
"(",
"$",
"new",
"->",
"value",
",",
"$",
"path",
")",
";",
"return",
"$",
"new",
";",
"}"
] | Create a new cookie without a specific path
@param string $path Path to remove
@return static | [
"Create",
"a",
"new",
"cookie",
"without",
"a",
"specific",
"path"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Cookie/Cookie.php#L512-L521 |
210,712 | cakephp/cakephp | src/Http/Cookie/Cookie.php | Cookie.read | public function read($path = null)
{
if ($this->isExpanded === false) {
$this->value = $this->_expand($this->value);
}
if ($path === null) {
return $this->value;
}
return Hash::get($this->value, $path);
} | php | public function read($path = null)
{
if ($this->isExpanded === false) {
$this->value = $this->_expand($this->value);
}
if ($path === null) {
return $this->value;
}
return Hash::get($this->value, $path);
} | [
"public",
"function",
"read",
"(",
"$",
"path",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isExpanded",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"value",
"=",
"$",
"this",
"->",
"_expand",
"(",
"$",
"this",
"->",
"value",
")",
";",
"}",
"if",
"(",
"$",
"path",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"value",
";",
"}",
"return",
"Hash",
"::",
"get",
"(",
"$",
"this",
"->",
"value",
",",
"$",
"path",
")",
";",
"}"
] | Read data from the cookie
This method will expand serialized complex data,
on first use.
@param string $path Path to read the data from
@return mixed | [
"Read",
"data",
"from",
"the",
"cookie"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Cookie/Cookie.php#L532-L543 |
210,713 | cakephp/cakephp | src/View/Widget/DateTimeWidget.php | DateTimeWidget._yearSelect | protected function _yearSelect($options, $context)
{
$options += [
'name' => '',
'val' => null,
'start' => date('Y', strtotime('-5 years')),
'end' => date('Y', strtotime('+5 years')),
'order' => 'desc',
'templateVars' => [],
'options' => []
];
if (!empty($options['val'])) {
$options['start'] = min($options['val'], $options['start']);
$options['end'] = max($options['val'], $options['end']);
}
if (empty($options['options'])) {
$options['options'] = $this->_generateNumbers($options['start'], $options['end']);
}
if ($options['order'] === 'desc') {
$options['options'] = array_reverse($options['options'], true);
}
unset($options['start'], $options['end'], $options['order']);
return $this->_select->render($options, $context);
} | php | protected function _yearSelect($options, $context)
{
$options += [
'name' => '',
'val' => null,
'start' => date('Y', strtotime('-5 years')),
'end' => date('Y', strtotime('+5 years')),
'order' => 'desc',
'templateVars' => [],
'options' => []
];
if (!empty($options['val'])) {
$options['start'] = min($options['val'], $options['start']);
$options['end'] = max($options['val'], $options['end']);
}
if (empty($options['options'])) {
$options['options'] = $this->_generateNumbers($options['start'], $options['end']);
}
if ($options['order'] === 'desc') {
$options['options'] = array_reverse($options['options'], true);
}
unset($options['start'], $options['end'], $options['order']);
return $this->_select->render($options, $context);
} | [
"protected",
"function",
"_yearSelect",
"(",
"$",
"options",
",",
"$",
"context",
")",
"{",
"$",
"options",
"+=",
"[",
"'name'",
"=>",
"''",
",",
"'val'",
"=>",
"null",
",",
"'start'",
"=>",
"date",
"(",
"'Y'",
",",
"strtotime",
"(",
"'-5 years'",
")",
")",
",",
"'end'",
"=>",
"date",
"(",
"'Y'",
",",
"strtotime",
"(",
"'+5 years'",
")",
")",
",",
"'order'",
"=>",
"'desc'",
",",
"'templateVars'",
"=>",
"[",
"]",
",",
"'options'",
"=>",
"[",
"]",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'val'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'start'",
"]",
"=",
"min",
"(",
"$",
"options",
"[",
"'val'",
"]",
",",
"$",
"options",
"[",
"'start'",
"]",
")",
";",
"$",
"options",
"[",
"'end'",
"]",
"=",
"max",
"(",
"$",
"options",
"[",
"'val'",
"]",
",",
"$",
"options",
"[",
"'end'",
"]",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'options'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'options'",
"]",
"=",
"$",
"this",
"->",
"_generateNumbers",
"(",
"$",
"options",
"[",
"'start'",
"]",
",",
"$",
"options",
"[",
"'end'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'order'",
"]",
"===",
"'desc'",
")",
"{",
"$",
"options",
"[",
"'options'",
"]",
"=",
"array_reverse",
"(",
"$",
"options",
"[",
"'options'",
"]",
",",
"true",
")",
";",
"}",
"unset",
"(",
"$",
"options",
"[",
"'start'",
"]",
",",
"$",
"options",
"[",
"'end'",
"]",
",",
"$",
"options",
"[",
"'order'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"_select",
"->",
"render",
"(",
"$",
"options",
",",
"$",
"context",
")",
";",
"}"
] | Generates a year select
@param array $options Options list.
@param \Cake\View\Form\ContextInterface $context The current form context.
@return string | [
"Generates",
"a",
"year",
"select"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Widget/DateTimeWidget.php#L317-L342 |
210,714 | cakephp/cakephp | src/View/Widget/DateTimeWidget.php | DateTimeWidget._monthSelect | protected function _monthSelect($options, $context)
{
$options += [
'name' => '',
'names' => false,
'val' => null,
'leadingZeroKey' => true,
'leadingZeroValue' => false,
'templateVars' => [],
];
if (empty($options['options'])) {
if ($options['names'] === true) {
$options['options'] = $this->_getMonthNames($options['leadingZeroKey']);
} elseif (is_array($options['names'])) {
$options['options'] = $options['names'];
} else {
$options['options'] = $this->_generateNumbers(1, 12, $options);
}
}
unset($options['leadingZeroKey'], $options['leadingZeroValue'], $options['names']);
return $this->_select->render($options, $context);
} | php | protected function _monthSelect($options, $context)
{
$options += [
'name' => '',
'names' => false,
'val' => null,
'leadingZeroKey' => true,
'leadingZeroValue' => false,
'templateVars' => [],
];
if (empty($options['options'])) {
if ($options['names'] === true) {
$options['options'] = $this->_getMonthNames($options['leadingZeroKey']);
} elseif (is_array($options['names'])) {
$options['options'] = $options['names'];
} else {
$options['options'] = $this->_generateNumbers(1, 12, $options);
}
}
unset($options['leadingZeroKey'], $options['leadingZeroValue'], $options['names']);
return $this->_select->render($options, $context);
} | [
"protected",
"function",
"_monthSelect",
"(",
"$",
"options",
",",
"$",
"context",
")",
"{",
"$",
"options",
"+=",
"[",
"'name'",
"=>",
"''",
",",
"'names'",
"=>",
"false",
",",
"'val'",
"=>",
"null",
",",
"'leadingZeroKey'",
"=>",
"true",
",",
"'leadingZeroValue'",
"=>",
"false",
",",
"'templateVars'",
"=>",
"[",
"]",
",",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'options'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"options",
"[",
"'names'",
"]",
"===",
"true",
")",
"{",
"$",
"options",
"[",
"'options'",
"]",
"=",
"$",
"this",
"->",
"_getMonthNames",
"(",
"$",
"options",
"[",
"'leadingZeroKey'",
"]",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"options",
"[",
"'names'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'options'",
"]",
"=",
"$",
"options",
"[",
"'names'",
"]",
";",
"}",
"else",
"{",
"$",
"options",
"[",
"'options'",
"]",
"=",
"$",
"this",
"->",
"_generateNumbers",
"(",
"1",
",",
"12",
",",
"$",
"options",
")",
";",
"}",
"}",
"unset",
"(",
"$",
"options",
"[",
"'leadingZeroKey'",
"]",
",",
"$",
"options",
"[",
"'leadingZeroValue'",
"]",
",",
"$",
"options",
"[",
"'names'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"_select",
"->",
"render",
"(",
"$",
"options",
",",
"$",
"context",
")",
";",
"}"
] | Generates a month select
@param array $options The options to build the month select with
@param \Cake\View\Form\ContextInterface $context The current form context.
@return string | [
"Generates",
"a",
"month",
"select"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Widget/DateTimeWidget.php#L351-L375 |
210,715 | cakephp/cakephp | src/View/Widget/DateTimeWidget.php | DateTimeWidget._daySelect | protected function _daySelect($options, $context)
{
$options += [
'name' => '',
'val' => null,
'leadingZeroKey' => true,
'leadingZeroValue' => false,
'templateVars' => [],
];
$options['options'] = $this->_generateNumbers(1, 31, $options);
unset($options['names'], $options['leadingZeroKey'], $options['leadingZeroValue']);
return $this->_select->render($options, $context);
} | php | protected function _daySelect($options, $context)
{
$options += [
'name' => '',
'val' => null,
'leadingZeroKey' => true,
'leadingZeroValue' => false,
'templateVars' => [],
];
$options['options'] = $this->_generateNumbers(1, 31, $options);
unset($options['names'], $options['leadingZeroKey'], $options['leadingZeroValue']);
return $this->_select->render($options, $context);
} | [
"protected",
"function",
"_daySelect",
"(",
"$",
"options",
",",
"$",
"context",
")",
"{",
"$",
"options",
"+=",
"[",
"'name'",
"=>",
"''",
",",
"'val'",
"=>",
"null",
",",
"'leadingZeroKey'",
"=>",
"true",
",",
"'leadingZeroValue'",
"=>",
"false",
",",
"'templateVars'",
"=>",
"[",
"]",
",",
"]",
";",
"$",
"options",
"[",
"'options'",
"]",
"=",
"$",
"this",
"->",
"_generateNumbers",
"(",
"1",
",",
"31",
",",
"$",
"options",
")",
";",
"unset",
"(",
"$",
"options",
"[",
"'names'",
"]",
",",
"$",
"options",
"[",
"'leadingZeroKey'",
"]",
",",
"$",
"options",
"[",
"'leadingZeroValue'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"_select",
"->",
"render",
"(",
"$",
"options",
",",
"$",
"context",
")",
";",
"}"
] | Generates a day select
@param array $options The options to generate a day select with.
@param \Cake\View\Form\ContextInterface $context The current form context.
@return string | [
"Generates",
"a",
"day",
"select"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Widget/DateTimeWidget.php#L384-L398 |
210,716 | cakephp/cakephp | src/View/Widget/DateTimeWidget.php | DateTimeWidget._hourSelect | protected function _hourSelect($options, $context)
{
$options += [
'name' => '',
'val' => null,
'format' => 24,
'start' => null,
'end' => null,
'leadingZeroKey' => true,
'leadingZeroValue' => false,
'templateVars' => [],
];
$is24 = $options['format'] == 24;
$defaultStart = $is24 ? 0 : 1;
$defaultEnd = $is24 ? 23 : 12;
$options['start'] = max($defaultStart, $options['start']);
$options['end'] = min($defaultEnd, $options['end']);
if ($options['end'] === null) {
$options['end'] = $defaultEnd;
}
if (!$is24 && $options['val'] > 12) {
$options['val'] = sprintf('%02d', $options['val'] - 12);
}
if (!$is24 && in_array($options['val'], ['00', '0', 0], true)) {
$options['val'] = 12;
}
if (empty($options['options'])) {
$options['options'] = $this->_generateNumbers(
$options['start'],
$options['end'],
$options
);
}
unset(
$options['end'],
$options['start'],
$options['format'],
$options['leadingZeroKey'],
$options['leadingZeroValue']
);
return $this->_select->render($options, $context);
} | php | protected function _hourSelect($options, $context)
{
$options += [
'name' => '',
'val' => null,
'format' => 24,
'start' => null,
'end' => null,
'leadingZeroKey' => true,
'leadingZeroValue' => false,
'templateVars' => [],
];
$is24 = $options['format'] == 24;
$defaultStart = $is24 ? 0 : 1;
$defaultEnd = $is24 ? 23 : 12;
$options['start'] = max($defaultStart, $options['start']);
$options['end'] = min($defaultEnd, $options['end']);
if ($options['end'] === null) {
$options['end'] = $defaultEnd;
}
if (!$is24 && $options['val'] > 12) {
$options['val'] = sprintf('%02d', $options['val'] - 12);
}
if (!$is24 && in_array($options['val'], ['00', '0', 0], true)) {
$options['val'] = 12;
}
if (empty($options['options'])) {
$options['options'] = $this->_generateNumbers(
$options['start'],
$options['end'],
$options
);
}
unset(
$options['end'],
$options['start'],
$options['format'],
$options['leadingZeroKey'],
$options['leadingZeroValue']
);
return $this->_select->render($options, $context);
} | [
"protected",
"function",
"_hourSelect",
"(",
"$",
"options",
",",
"$",
"context",
")",
"{",
"$",
"options",
"+=",
"[",
"'name'",
"=>",
"''",
",",
"'val'",
"=>",
"null",
",",
"'format'",
"=>",
"24",
",",
"'start'",
"=>",
"null",
",",
"'end'",
"=>",
"null",
",",
"'leadingZeroKey'",
"=>",
"true",
",",
"'leadingZeroValue'",
"=>",
"false",
",",
"'templateVars'",
"=>",
"[",
"]",
",",
"]",
";",
"$",
"is24",
"=",
"$",
"options",
"[",
"'format'",
"]",
"==",
"24",
";",
"$",
"defaultStart",
"=",
"$",
"is24",
"?",
"0",
":",
"1",
";",
"$",
"defaultEnd",
"=",
"$",
"is24",
"?",
"23",
":",
"12",
";",
"$",
"options",
"[",
"'start'",
"]",
"=",
"max",
"(",
"$",
"defaultStart",
",",
"$",
"options",
"[",
"'start'",
"]",
")",
";",
"$",
"options",
"[",
"'end'",
"]",
"=",
"min",
"(",
"$",
"defaultEnd",
",",
"$",
"options",
"[",
"'end'",
"]",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'end'",
"]",
"===",
"null",
")",
"{",
"$",
"options",
"[",
"'end'",
"]",
"=",
"$",
"defaultEnd",
";",
"}",
"if",
"(",
"!",
"$",
"is24",
"&&",
"$",
"options",
"[",
"'val'",
"]",
">",
"12",
")",
"{",
"$",
"options",
"[",
"'val'",
"]",
"=",
"sprintf",
"(",
"'%02d'",
",",
"$",
"options",
"[",
"'val'",
"]",
"-",
"12",
")",
";",
"}",
"if",
"(",
"!",
"$",
"is24",
"&&",
"in_array",
"(",
"$",
"options",
"[",
"'val'",
"]",
",",
"[",
"'00'",
",",
"'0'",
",",
"0",
"]",
",",
"true",
")",
")",
"{",
"$",
"options",
"[",
"'val'",
"]",
"=",
"12",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'options'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'options'",
"]",
"=",
"$",
"this",
"->",
"_generateNumbers",
"(",
"$",
"options",
"[",
"'start'",
"]",
",",
"$",
"options",
"[",
"'end'",
"]",
",",
"$",
"options",
")",
";",
"}",
"unset",
"(",
"$",
"options",
"[",
"'end'",
"]",
",",
"$",
"options",
"[",
"'start'",
"]",
",",
"$",
"options",
"[",
"'format'",
"]",
",",
"$",
"options",
"[",
"'leadingZeroKey'",
"]",
",",
"$",
"options",
"[",
"'leadingZeroValue'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"_select",
"->",
"render",
"(",
"$",
"options",
",",
"$",
"context",
")",
";",
"}"
] | Generates a hour select
@param array $options The options to generate an hour select with
@param \Cake\View\Form\ContextInterface $context The current form context.
@return string | [
"Generates",
"a",
"hour",
"select"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Widget/DateTimeWidget.php#L407-L454 |
210,717 | cakephp/cakephp | src/View/Widget/DateTimeWidget.php | DateTimeWidget._minuteSelect | protected function _minuteSelect($options, $context)
{
$options += [
'name' => '',
'val' => null,
'interval' => 1,
'round' => 'up',
'leadingZeroKey' => true,
'leadingZeroValue' => true,
'templateVars' => [],
];
$options['interval'] = max($options['interval'], 1);
if (empty($options['options'])) {
$options['options'] = $this->_generateNumbers(0, 59, $options);
}
unset(
$options['leadingZeroKey'],
$options['leadingZeroValue'],
$options['interval'],
$options['round']
);
return $this->_select->render($options, $context);
} | php | protected function _minuteSelect($options, $context)
{
$options += [
'name' => '',
'val' => null,
'interval' => 1,
'round' => 'up',
'leadingZeroKey' => true,
'leadingZeroValue' => true,
'templateVars' => [],
];
$options['interval'] = max($options['interval'], 1);
if (empty($options['options'])) {
$options['options'] = $this->_generateNumbers(0, 59, $options);
}
unset(
$options['leadingZeroKey'],
$options['leadingZeroValue'],
$options['interval'],
$options['round']
);
return $this->_select->render($options, $context);
} | [
"protected",
"function",
"_minuteSelect",
"(",
"$",
"options",
",",
"$",
"context",
")",
"{",
"$",
"options",
"+=",
"[",
"'name'",
"=>",
"''",
",",
"'val'",
"=>",
"null",
",",
"'interval'",
"=>",
"1",
",",
"'round'",
"=>",
"'up'",
",",
"'leadingZeroKey'",
"=>",
"true",
",",
"'leadingZeroValue'",
"=>",
"true",
",",
"'templateVars'",
"=>",
"[",
"]",
",",
"]",
";",
"$",
"options",
"[",
"'interval'",
"]",
"=",
"max",
"(",
"$",
"options",
"[",
"'interval'",
"]",
",",
"1",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'options'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'options'",
"]",
"=",
"$",
"this",
"->",
"_generateNumbers",
"(",
"0",
",",
"59",
",",
"$",
"options",
")",
";",
"}",
"unset",
"(",
"$",
"options",
"[",
"'leadingZeroKey'",
"]",
",",
"$",
"options",
"[",
"'leadingZeroValue'",
"]",
",",
"$",
"options",
"[",
"'interval'",
"]",
",",
"$",
"options",
"[",
"'round'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"_select",
"->",
"render",
"(",
"$",
"options",
",",
"$",
"context",
")",
";",
"}"
] | Generates a minute select
@param array $options The options to generate a minute select with.
@param \Cake\View\Form\ContextInterface $context The current form context.
@return string | [
"Generates",
"a",
"minute",
"select"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Widget/DateTimeWidget.php#L463-L487 |
210,718 | cakephp/cakephp | src/View/Widget/DateTimeWidget.php | DateTimeWidget._secondSelect | protected function _secondSelect($options, $context)
{
$options += [
'name' => '',
'val' => null,
'leadingZeroKey' => true,
'leadingZeroValue' => true,
'options' => $this->_generateNumbers(0, 59),
'templateVars' => [],
];
unset($options['leadingZeroKey'], $options['leadingZeroValue']);
return $this->_select->render($options, $context);
} | php | protected function _secondSelect($options, $context)
{
$options += [
'name' => '',
'val' => null,
'leadingZeroKey' => true,
'leadingZeroValue' => true,
'options' => $this->_generateNumbers(0, 59),
'templateVars' => [],
];
unset($options['leadingZeroKey'], $options['leadingZeroValue']);
return $this->_select->render($options, $context);
} | [
"protected",
"function",
"_secondSelect",
"(",
"$",
"options",
",",
"$",
"context",
")",
"{",
"$",
"options",
"+=",
"[",
"'name'",
"=>",
"''",
",",
"'val'",
"=>",
"null",
",",
"'leadingZeroKey'",
"=>",
"true",
",",
"'leadingZeroValue'",
"=>",
"true",
",",
"'options'",
"=>",
"$",
"this",
"->",
"_generateNumbers",
"(",
"0",
",",
"59",
")",
",",
"'templateVars'",
"=>",
"[",
"]",
",",
"]",
";",
"unset",
"(",
"$",
"options",
"[",
"'leadingZeroKey'",
"]",
",",
"$",
"options",
"[",
"'leadingZeroValue'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"_select",
"->",
"render",
"(",
"$",
"options",
",",
"$",
"context",
")",
";",
"}"
] | Generates a second select
@param array $options The options to generate a second select with
@param \Cake\View\Form\ContextInterface $context The current form context.
@return string | [
"Generates",
"a",
"second",
"select"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Widget/DateTimeWidget.php#L496-L510 |
210,719 | cakephp/cakephp | src/View/Widget/DateTimeWidget.php | DateTimeWidget._meridianSelect | protected function _meridianSelect($options, $context)
{
$options += [
'name' => '',
'val' => null,
'options' => ['am' => 'am', 'pm' => 'pm'],
'templateVars' => [],
];
return $this->_select->render($options, $context);
} | php | protected function _meridianSelect($options, $context)
{
$options += [
'name' => '',
'val' => null,
'options' => ['am' => 'am', 'pm' => 'pm'],
'templateVars' => [],
];
return $this->_select->render($options, $context);
} | [
"protected",
"function",
"_meridianSelect",
"(",
"$",
"options",
",",
"$",
"context",
")",
"{",
"$",
"options",
"+=",
"[",
"'name'",
"=>",
"''",
",",
"'val'",
"=>",
"null",
",",
"'options'",
"=>",
"[",
"'am'",
"=>",
"'am'",
",",
"'pm'",
"=>",
"'pm'",
"]",
",",
"'templateVars'",
"=>",
"[",
"]",
",",
"]",
";",
"return",
"$",
"this",
"->",
"_select",
"->",
"render",
"(",
"$",
"options",
",",
"$",
"context",
")",
";",
"}"
] | Generates a meridian select
@param array $options The options to generate a meridian select with.
@param \Cake\View\Form\ContextInterface $context The current form context.
@return string | [
"Generates",
"a",
"meridian",
"select"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Widget/DateTimeWidget.php#L519-L529 |
210,720 | cakephp/cakephp | src/View/Widget/DateTimeWidget.php | DateTimeWidget._getMonthNames | protected function _getMonthNames($leadingZero = false)
{
$months = [
'01' => __d('cake', 'January'),
'02' => __d('cake', 'February'),
'03' => __d('cake', 'March'),
'04' => __d('cake', 'April'),
'05' => __d('cake', 'May'),
'06' => __d('cake', 'June'),
'07' => __d('cake', 'July'),
'08' => __d('cake', 'August'),
'09' => __d('cake', 'September'),
'10' => __d('cake', 'October'),
'11' => __d('cake', 'November'),
'12' => __d('cake', 'December'),
];
if ($leadingZero === false) {
$i = 1;
foreach ($months as $key => $name) {
unset($months[$key]);
$months[$i++] = $name;
}
}
return $months;
} | php | protected function _getMonthNames($leadingZero = false)
{
$months = [
'01' => __d('cake', 'January'),
'02' => __d('cake', 'February'),
'03' => __d('cake', 'March'),
'04' => __d('cake', 'April'),
'05' => __d('cake', 'May'),
'06' => __d('cake', 'June'),
'07' => __d('cake', 'July'),
'08' => __d('cake', 'August'),
'09' => __d('cake', 'September'),
'10' => __d('cake', 'October'),
'11' => __d('cake', 'November'),
'12' => __d('cake', 'December'),
];
if ($leadingZero === false) {
$i = 1;
foreach ($months as $key => $name) {
unset($months[$key]);
$months[$i++] = $name;
}
}
return $months;
} | [
"protected",
"function",
"_getMonthNames",
"(",
"$",
"leadingZero",
"=",
"false",
")",
"{",
"$",
"months",
"=",
"[",
"'01'",
"=>",
"__d",
"(",
"'cake'",
",",
"'January'",
")",
",",
"'02'",
"=>",
"__d",
"(",
"'cake'",
",",
"'February'",
")",
",",
"'03'",
"=>",
"__d",
"(",
"'cake'",
",",
"'March'",
")",
",",
"'04'",
"=>",
"__d",
"(",
"'cake'",
",",
"'April'",
")",
",",
"'05'",
"=>",
"__d",
"(",
"'cake'",
",",
"'May'",
")",
",",
"'06'",
"=>",
"__d",
"(",
"'cake'",
",",
"'June'",
")",
",",
"'07'",
"=>",
"__d",
"(",
"'cake'",
",",
"'July'",
")",
",",
"'08'",
"=>",
"__d",
"(",
"'cake'",
",",
"'August'",
")",
",",
"'09'",
"=>",
"__d",
"(",
"'cake'",
",",
"'September'",
")",
",",
"'10'",
"=>",
"__d",
"(",
"'cake'",
",",
"'October'",
")",
",",
"'11'",
"=>",
"__d",
"(",
"'cake'",
",",
"'November'",
")",
",",
"'12'",
"=>",
"__d",
"(",
"'cake'",
",",
"'December'",
")",
",",
"]",
";",
"if",
"(",
"$",
"leadingZero",
"===",
"false",
")",
"{",
"$",
"i",
"=",
"1",
";",
"foreach",
"(",
"$",
"months",
"as",
"$",
"key",
"=>",
"$",
"name",
")",
"{",
"unset",
"(",
"$",
"months",
"[",
"$",
"key",
"]",
")",
";",
"$",
"months",
"[",
"$",
"i",
"++",
"]",
"=",
"$",
"name",
";",
"}",
"}",
"return",
"$",
"months",
";",
"}"
] | Returns a translated list of month names
@param bool $leadingZero Whether to generate month keys with leading zero.
@return array | [
"Returns",
"a",
"translated",
"list",
"of",
"month",
"names"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Widget/DateTimeWidget.php#L537-L563 |
210,721 | cakephp/cakephp | src/View/Widget/DateTimeWidget.php | DateTimeWidget._generateNumbers | protected function _generateNumbers($start, $end, $options = [])
{
$options += [
'leadingZeroKey' => true,
'leadingZeroValue' => true,
'interval' => 1
];
$numbers = [];
$i = $start;
while ($i <= $end) {
$key = (string)$i;
$value = (string)$i;
if ($options['leadingZeroKey'] === true) {
$key = sprintf('%02d', $key);
}
if ($options['leadingZeroValue'] === true) {
$value = sprintf('%02d', $value);
}
$numbers[$key] = $value;
$i += $options['interval'];
}
return $numbers;
} | php | protected function _generateNumbers($start, $end, $options = [])
{
$options += [
'leadingZeroKey' => true,
'leadingZeroValue' => true,
'interval' => 1
];
$numbers = [];
$i = $start;
while ($i <= $end) {
$key = (string)$i;
$value = (string)$i;
if ($options['leadingZeroKey'] === true) {
$key = sprintf('%02d', $key);
}
if ($options['leadingZeroValue'] === true) {
$value = sprintf('%02d', $value);
}
$numbers[$key] = $value;
$i += $options['interval'];
}
return $numbers;
} | [
"protected",
"function",
"_generateNumbers",
"(",
"$",
"start",
",",
"$",
"end",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"+=",
"[",
"'leadingZeroKey'",
"=>",
"true",
",",
"'leadingZeroValue'",
"=>",
"true",
",",
"'interval'",
"=>",
"1",
"]",
";",
"$",
"numbers",
"=",
"[",
"]",
";",
"$",
"i",
"=",
"$",
"start",
";",
"while",
"(",
"$",
"i",
"<=",
"$",
"end",
")",
"{",
"$",
"key",
"=",
"(",
"string",
")",
"$",
"i",
";",
"$",
"value",
"=",
"(",
"string",
")",
"$",
"i",
";",
"if",
"(",
"$",
"options",
"[",
"'leadingZeroKey'",
"]",
"===",
"true",
")",
"{",
"$",
"key",
"=",
"sprintf",
"(",
"'%02d'",
",",
"$",
"key",
")",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'leadingZeroValue'",
"]",
"===",
"true",
")",
"{",
"$",
"value",
"=",
"sprintf",
"(",
"'%02d'",
",",
"$",
"value",
")",
";",
"}",
"$",
"numbers",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"$",
"i",
"+=",
"$",
"options",
"[",
"'interval'",
"]",
";",
"}",
"return",
"$",
"numbers",
";",
"}"
] | Generates a range of numbers
### Options
- leadingZeroKey - Set to true to add a leading 0 to single digit keys.
- leadingZeroValue - Set to true to add a leading 0 to single digit values.
- interval - The interval to generate numbers for. Defaults to 1.
@param int $start Start of the range of numbers to generate
@param int $end End of the range of numbers to generate
@param array $options Options list.
@return array | [
"Generates",
"a",
"range",
"of",
"numbers"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Widget/DateTimeWidget.php#L579-L603 |
210,722 | cakephp/cakephp | src/View/Widget/DateTimeWidget.php | DateTimeWidget.secureFields | public function secureFields(array $data)
{
$data = $this->_normalizeData($data);
$fields = [];
foreach ($this->_selects as $select) {
if ($data[$select] === false || $data[$select] === null) {
continue;
}
$fields[] = $data['name'] . '[' . $select . ']';
}
return $fields;
} | php | public function secureFields(array $data)
{
$data = $this->_normalizeData($data);
$fields = [];
foreach ($this->_selects as $select) {
if ($data[$select] === false || $data[$select] === null) {
continue;
}
$fields[] = $data['name'] . '[' . $select . ']';
}
return $fields;
} | [
"public",
"function",
"secureFields",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"_normalizeData",
"(",
"$",
"data",
")",
";",
"$",
"fields",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_selects",
"as",
"$",
"select",
")",
"{",
"if",
"(",
"$",
"data",
"[",
"$",
"select",
"]",
"===",
"false",
"||",
"$",
"data",
"[",
"$",
"select",
"]",
"===",
"null",
")",
"{",
"continue",
";",
"}",
"$",
"fields",
"[",
"]",
"=",
"$",
"data",
"[",
"'name'",
"]",
".",
"'['",
".",
"$",
"select",
".",
"']'",
";",
"}",
"return",
"$",
"fields",
";",
"}"
] | Returns a list of fields that need to be secured for this widget.
When the hour picker is in 24hr mode (null or format=24) the meridian
picker will be omitted.
@param array $data The data to render.
@return array Array of fields to secure. | [
"Returns",
"a",
"list",
"of",
"fields",
"that",
"need",
"to",
"be",
"secured",
"for",
"this",
"widget",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Widget/DateTimeWidget.php#L614-L628 |
210,723 | cakephp/cakephp | src/View/Widget/MultiCheckboxWidget.php | MultiCheckboxWidget.render | public function render(array $data, ContextInterface $context)
{
$data += [
'name' => '',
'escape' => true,
'options' => [],
'disabled' => null,
'val' => null,
'idPrefix' => null,
'templateVars' => [],
'label' => true
];
$this->_idPrefix = $data['idPrefix'];
$this->_clearIds();
return implode('', $this->_renderInputs($data, $context));
} | php | public function render(array $data, ContextInterface $context)
{
$data += [
'name' => '',
'escape' => true,
'options' => [],
'disabled' => null,
'val' => null,
'idPrefix' => null,
'templateVars' => [],
'label' => true
];
$this->_idPrefix = $data['idPrefix'];
$this->_clearIds();
return implode('', $this->_renderInputs($data, $context));
} | [
"public",
"function",
"render",
"(",
"array",
"$",
"data",
",",
"ContextInterface",
"$",
"context",
")",
"{",
"$",
"data",
"+=",
"[",
"'name'",
"=>",
"''",
",",
"'escape'",
"=>",
"true",
",",
"'options'",
"=>",
"[",
"]",
",",
"'disabled'",
"=>",
"null",
",",
"'val'",
"=>",
"null",
",",
"'idPrefix'",
"=>",
"null",
",",
"'templateVars'",
"=>",
"[",
"]",
",",
"'label'",
"=>",
"true",
"]",
";",
"$",
"this",
"->",
"_idPrefix",
"=",
"$",
"data",
"[",
"'idPrefix'",
"]",
";",
"$",
"this",
"->",
"_clearIds",
"(",
")",
";",
"return",
"implode",
"(",
"''",
",",
"$",
"this",
"->",
"_renderInputs",
"(",
"$",
"data",
",",
"$",
"context",
")",
")",
";",
"}"
] | Render multi-checkbox widget.
Data supports the following options.
- `name` The name attribute of the inputs to create.
`[]` will be appended to the name.
- `options` An array of options to create checkboxes out of.
- `val` Either a string/integer or array of values that should be
checked. Can also be a complex options set.
- `disabled` Either a boolean or an array of checkboxes to disable.
- `escape` Set to false to disable HTML escaping.
- `options` An associative array of value=>labels to generate options for.
- `idPrefix` Prefix for generated ID attributes.
### Options format
The options option can take a variety of data format depending on
the complexity of HTML you want generated.
You can generate simple options using a basic associative array:
```
'options' => ['elk' => 'Elk', 'beaver' => 'Beaver']
```
If you need to define additional attributes on your option elements
you can use the complex form for options:
```
'options' => [
['value' => 'elk', 'text' => 'Elk', 'data-foo' => 'bar'],
]
```
This form **requires** that both the `value` and `text` keys be defined.
If either is not set options will not be generated correctly.
@param array $data The data to generate a checkbox set with.
@param \Cake\View\Form\ContextInterface $context The current form context.
@return string | [
"Render",
"multi",
"-",
"checkbox",
"widget",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Widget/MultiCheckboxWidget.php#L106-L122 |
210,724 | cakephp/cakephp | src/View/Widget/MultiCheckboxWidget.php | MultiCheckboxWidget._renderInputs | protected function _renderInputs($data, $context)
{
$out = [];
foreach ($data['options'] as $key => $val) {
// Grouped inputs in a fieldset.
if (is_string($key) && is_array($val) && !isset($val['text'], $val['value'])) {
$inputs = $this->_renderInputs(['options' => $val] + $data, $context);
$title = $this->_templates->format('multicheckboxTitle', ['text' => $key]);
$out[] = $this->_templates->format('multicheckboxWrapper', [
'content' => $title . implode('', $inputs)
]);
continue;
}
// Standard inputs.
$checkbox = [
'value' => $key,
'text' => $val,
];
if (is_array($val) && isset($val['text'], $val['value'])) {
$checkbox = $val;
}
if (!isset($checkbox['templateVars'])) {
$checkbox['templateVars'] = $data['templateVars'];
}
if (!isset($checkbox['label'])) {
$checkbox['label'] = $data['label'];
}
if (!empty($data['templateVars'])) {
$checkbox['templateVars'] = array_merge($data['templateVars'], $checkbox['templateVars']);
}
$checkbox['name'] = $data['name'];
$checkbox['escape'] = $data['escape'];
$checkbox['checked'] = $this->_isSelected($checkbox['value'], $data['val']);
$checkbox['disabled'] = $this->_isDisabled($checkbox['value'], $data['disabled']);
if (empty($checkbox['id'])) {
$checkbox['id'] = $this->_id($checkbox['name'], $checkbox['value']);
}
$out[] = $this->_renderInput($checkbox + $data, $context);
}
return $out;
} | php | protected function _renderInputs($data, $context)
{
$out = [];
foreach ($data['options'] as $key => $val) {
// Grouped inputs in a fieldset.
if (is_string($key) && is_array($val) && !isset($val['text'], $val['value'])) {
$inputs = $this->_renderInputs(['options' => $val] + $data, $context);
$title = $this->_templates->format('multicheckboxTitle', ['text' => $key]);
$out[] = $this->_templates->format('multicheckboxWrapper', [
'content' => $title . implode('', $inputs)
]);
continue;
}
// Standard inputs.
$checkbox = [
'value' => $key,
'text' => $val,
];
if (is_array($val) && isset($val['text'], $val['value'])) {
$checkbox = $val;
}
if (!isset($checkbox['templateVars'])) {
$checkbox['templateVars'] = $data['templateVars'];
}
if (!isset($checkbox['label'])) {
$checkbox['label'] = $data['label'];
}
if (!empty($data['templateVars'])) {
$checkbox['templateVars'] = array_merge($data['templateVars'], $checkbox['templateVars']);
}
$checkbox['name'] = $data['name'];
$checkbox['escape'] = $data['escape'];
$checkbox['checked'] = $this->_isSelected($checkbox['value'], $data['val']);
$checkbox['disabled'] = $this->_isDisabled($checkbox['value'], $data['disabled']);
if (empty($checkbox['id'])) {
$checkbox['id'] = $this->_id($checkbox['name'], $checkbox['value']);
}
$out[] = $this->_renderInput($checkbox + $data, $context);
}
return $out;
} | [
"protected",
"function",
"_renderInputs",
"(",
"$",
"data",
",",
"$",
"context",
")",
"{",
"$",
"out",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"[",
"'options'",
"]",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"// Grouped inputs in a fieldset.",
"if",
"(",
"is_string",
"(",
"$",
"key",
")",
"&&",
"is_array",
"(",
"$",
"val",
")",
"&&",
"!",
"isset",
"(",
"$",
"val",
"[",
"'text'",
"]",
",",
"$",
"val",
"[",
"'value'",
"]",
")",
")",
"{",
"$",
"inputs",
"=",
"$",
"this",
"->",
"_renderInputs",
"(",
"[",
"'options'",
"=>",
"$",
"val",
"]",
"+",
"$",
"data",
",",
"$",
"context",
")",
";",
"$",
"title",
"=",
"$",
"this",
"->",
"_templates",
"->",
"format",
"(",
"'multicheckboxTitle'",
",",
"[",
"'text'",
"=>",
"$",
"key",
"]",
")",
";",
"$",
"out",
"[",
"]",
"=",
"$",
"this",
"->",
"_templates",
"->",
"format",
"(",
"'multicheckboxWrapper'",
",",
"[",
"'content'",
"=>",
"$",
"title",
".",
"implode",
"(",
"''",
",",
"$",
"inputs",
")",
"]",
")",
";",
"continue",
";",
"}",
"// Standard inputs.",
"$",
"checkbox",
"=",
"[",
"'value'",
"=>",
"$",
"key",
",",
"'text'",
"=>",
"$",
"val",
",",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"val",
")",
"&&",
"isset",
"(",
"$",
"val",
"[",
"'text'",
"]",
",",
"$",
"val",
"[",
"'value'",
"]",
")",
")",
"{",
"$",
"checkbox",
"=",
"$",
"val",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"checkbox",
"[",
"'templateVars'",
"]",
")",
")",
"{",
"$",
"checkbox",
"[",
"'templateVars'",
"]",
"=",
"$",
"data",
"[",
"'templateVars'",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"checkbox",
"[",
"'label'",
"]",
")",
")",
"{",
"$",
"checkbox",
"[",
"'label'",
"]",
"=",
"$",
"data",
"[",
"'label'",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"'templateVars'",
"]",
")",
")",
"{",
"$",
"checkbox",
"[",
"'templateVars'",
"]",
"=",
"array_merge",
"(",
"$",
"data",
"[",
"'templateVars'",
"]",
",",
"$",
"checkbox",
"[",
"'templateVars'",
"]",
")",
";",
"}",
"$",
"checkbox",
"[",
"'name'",
"]",
"=",
"$",
"data",
"[",
"'name'",
"]",
";",
"$",
"checkbox",
"[",
"'escape'",
"]",
"=",
"$",
"data",
"[",
"'escape'",
"]",
";",
"$",
"checkbox",
"[",
"'checked'",
"]",
"=",
"$",
"this",
"->",
"_isSelected",
"(",
"$",
"checkbox",
"[",
"'value'",
"]",
",",
"$",
"data",
"[",
"'val'",
"]",
")",
";",
"$",
"checkbox",
"[",
"'disabled'",
"]",
"=",
"$",
"this",
"->",
"_isDisabled",
"(",
"$",
"checkbox",
"[",
"'value'",
"]",
",",
"$",
"data",
"[",
"'disabled'",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"checkbox",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"checkbox",
"[",
"'id'",
"]",
"=",
"$",
"this",
"->",
"_id",
"(",
"$",
"checkbox",
"[",
"'name'",
"]",
",",
"$",
"checkbox",
"[",
"'value'",
"]",
")",
";",
"}",
"$",
"out",
"[",
"]",
"=",
"$",
"this",
"->",
"_renderInput",
"(",
"$",
"checkbox",
"+",
"$",
"data",
",",
"$",
"context",
")",
";",
"}",
"return",
"$",
"out",
";",
"}"
] | Render the checkbox inputs.
@param array $data The data array defining the checkboxes.
@param \Cake\View\Form\ContextInterface $context The current form context.
@return array An array of rendered inputs. | [
"Render",
"the",
"checkbox",
"inputs",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Widget/MultiCheckboxWidget.php#L131-L173 |
210,725 | cakephp/cakephp | src/View/Widget/MultiCheckboxWidget.php | MultiCheckboxWidget._renderInput | protected function _renderInput($checkbox, $context)
{
$input = $this->_templates->format('checkbox', [
'name' => $checkbox['name'] . '[]',
'value' => $checkbox['escape'] ? h($checkbox['value']) : $checkbox['value'],
'templateVars' => $checkbox['templateVars'],
'attrs' => $this->_templates->formatAttributes(
$checkbox,
['name', 'value', 'text', 'options', 'label', 'val', 'type']
)
]);
if ($checkbox['label'] === false && strpos($this->_templates->get('checkboxWrapper'), '{{input}}') === false) {
$label = $input;
} else {
$labelAttrs = is_array($checkbox['label']) ? $checkbox['label'] : [];
$labelAttrs += [
'for' => $checkbox['id'],
'escape' => $checkbox['escape'],
'text' => $checkbox['text'],
'templateVars' => $checkbox['templateVars'],
'input' => $input
];
if ($checkbox['checked']) {
$labelAttrs = $this->_templates->addClass($labelAttrs, 'selected');
}
$label = $this->_label->render($labelAttrs, $context);
}
return $this->_templates->format('checkboxWrapper', [
'templateVars' => $checkbox['templateVars'],
'label' => $label,
'input' => $input
]);
} | php | protected function _renderInput($checkbox, $context)
{
$input = $this->_templates->format('checkbox', [
'name' => $checkbox['name'] . '[]',
'value' => $checkbox['escape'] ? h($checkbox['value']) : $checkbox['value'],
'templateVars' => $checkbox['templateVars'],
'attrs' => $this->_templates->formatAttributes(
$checkbox,
['name', 'value', 'text', 'options', 'label', 'val', 'type']
)
]);
if ($checkbox['label'] === false && strpos($this->_templates->get('checkboxWrapper'), '{{input}}') === false) {
$label = $input;
} else {
$labelAttrs = is_array($checkbox['label']) ? $checkbox['label'] : [];
$labelAttrs += [
'for' => $checkbox['id'],
'escape' => $checkbox['escape'],
'text' => $checkbox['text'],
'templateVars' => $checkbox['templateVars'],
'input' => $input
];
if ($checkbox['checked']) {
$labelAttrs = $this->_templates->addClass($labelAttrs, 'selected');
}
$label = $this->_label->render($labelAttrs, $context);
}
return $this->_templates->format('checkboxWrapper', [
'templateVars' => $checkbox['templateVars'],
'label' => $label,
'input' => $input
]);
} | [
"protected",
"function",
"_renderInput",
"(",
"$",
"checkbox",
",",
"$",
"context",
")",
"{",
"$",
"input",
"=",
"$",
"this",
"->",
"_templates",
"->",
"format",
"(",
"'checkbox'",
",",
"[",
"'name'",
"=>",
"$",
"checkbox",
"[",
"'name'",
"]",
".",
"'[]'",
",",
"'value'",
"=>",
"$",
"checkbox",
"[",
"'escape'",
"]",
"?",
"h",
"(",
"$",
"checkbox",
"[",
"'value'",
"]",
")",
":",
"$",
"checkbox",
"[",
"'value'",
"]",
",",
"'templateVars'",
"=>",
"$",
"checkbox",
"[",
"'templateVars'",
"]",
",",
"'attrs'",
"=>",
"$",
"this",
"->",
"_templates",
"->",
"formatAttributes",
"(",
"$",
"checkbox",
",",
"[",
"'name'",
",",
"'value'",
",",
"'text'",
",",
"'options'",
",",
"'label'",
",",
"'val'",
",",
"'type'",
"]",
")",
"]",
")",
";",
"if",
"(",
"$",
"checkbox",
"[",
"'label'",
"]",
"===",
"false",
"&&",
"strpos",
"(",
"$",
"this",
"->",
"_templates",
"->",
"get",
"(",
"'checkboxWrapper'",
")",
",",
"'{{input}}'",
")",
"===",
"false",
")",
"{",
"$",
"label",
"=",
"$",
"input",
";",
"}",
"else",
"{",
"$",
"labelAttrs",
"=",
"is_array",
"(",
"$",
"checkbox",
"[",
"'label'",
"]",
")",
"?",
"$",
"checkbox",
"[",
"'label'",
"]",
":",
"[",
"]",
";",
"$",
"labelAttrs",
"+=",
"[",
"'for'",
"=>",
"$",
"checkbox",
"[",
"'id'",
"]",
",",
"'escape'",
"=>",
"$",
"checkbox",
"[",
"'escape'",
"]",
",",
"'text'",
"=>",
"$",
"checkbox",
"[",
"'text'",
"]",
",",
"'templateVars'",
"=>",
"$",
"checkbox",
"[",
"'templateVars'",
"]",
",",
"'input'",
"=>",
"$",
"input",
"]",
";",
"if",
"(",
"$",
"checkbox",
"[",
"'checked'",
"]",
")",
"{",
"$",
"labelAttrs",
"=",
"$",
"this",
"->",
"_templates",
"->",
"addClass",
"(",
"$",
"labelAttrs",
",",
"'selected'",
")",
";",
"}",
"$",
"label",
"=",
"$",
"this",
"->",
"_label",
"->",
"render",
"(",
"$",
"labelAttrs",
",",
"$",
"context",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_templates",
"->",
"format",
"(",
"'checkboxWrapper'",
",",
"[",
"'templateVars'",
"=>",
"$",
"checkbox",
"[",
"'templateVars'",
"]",
",",
"'label'",
"=>",
"$",
"label",
",",
"'input'",
"=>",
"$",
"input",
"]",
")",
";",
"}"
] | Render a single checkbox & wrapper.
@param array $checkbox An array containing checkbox key/value option pairs
@param \Cake\View\Form\ContextInterface $context Context object.
@return string | [
"Render",
"a",
"single",
"checkbox",
"&",
"wrapper",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Widget/MultiCheckboxWidget.php#L182-L218 |
210,726 | cakephp/cakephp | src/Error/BaseErrorHandler.php | BaseErrorHandler.increaseMemoryLimit | public function increaseMemoryLimit($additionalKb)
{
$limit = ini_get('memory_limit');
if (!strlen($limit) || $limit === '-1') {
return;
}
$limit = trim($limit);
$units = strtoupper(substr($limit, -1));
$current = (int)substr($limit, 0, strlen($limit) - 1);
if ($units === 'M') {
$current *= 1024;
$units = 'K';
}
if ($units === 'G') {
$current = $current * 1024 * 1024;
$units = 'K';
}
if ($units === 'K') {
ini_set('memory_limit', ceil($current + $additionalKb) . 'K');
}
} | php | public function increaseMemoryLimit($additionalKb)
{
$limit = ini_get('memory_limit');
if (!strlen($limit) || $limit === '-1') {
return;
}
$limit = trim($limit);
$units = strtoupper(substr($limit, -1));
$current = (int)substr($limit, 0, strlen($limit) - 1);
if ($units === 'M') {
$current *= 1024;
$units = 'K';
}
if ($units === 'G') {
$current = $current * 1024 * 1024;
$units = 'K';
}
if ($units === 'K') {
ini_set('memory_limit', ceil($current + $additionalKb) . 'K');
}
} | [
"public",
"function",
"increaseMemoryLimit",
"(",
"$",
"additionalKb",
")",
"{",
"$",
"limit",
"=",
"ini_get",
"(",
"'memory_limit'",
")",
";",
"if",
"(",
"!",
"strlen",
"(",
"$",
"limit",
")",
"||",
"$",
"limit",
"===",
"'-1'",
")",
"{",
"return",
";",
"}",
"$",
"limit",
"=",
"trim",
"(",
"$",
"limit",
")",
";",
"$",
"units",
"=",
"strtoupper",
"(",
"substr",
"(",
"$",
"limit",
",",
"-",
"1",
")",
")",
";",
"$",
"current",
"=",
"(",
"int",
")",
"substr",
"(",
"$",
"limit",
",",
"0",
",",
"strlen",
"(",
"$",
"limit",
")",
"-",
"1",
")",
";",
"if",
"(",
"$",
"units",
"===",
"'M'",
")",
"{",
"$",
"current",
"*=",
"1024",
";",
"$",
"units",
"=",
"'K'",
";",
"}",
"if",
"(",
"$",
"units",
"===",
"'G'",
")",
"{",
"$",
"current",
"=",
"$",
"current",
"*",
"1024",
"*",
"1024",
";",
"$",
"units",
"=",
"'K'",
";",
"}",
"if",
"(",
"$",
"units",
"===",
"'K'",
")",
"{",
"ini_set",
"(",
"'memory_limit'",
",",
"ceil",
"(",
"$",
"current",
"+",
"$",
"additionalKb",
")",
".",
"'K'",
")",
";",
"}",
"}"
] | Increases the PHP "memory_limit" ini setting by the specified amount
in kilobytes
@param int $additionalKb Number in kilobytes
@return void | [
"Increases",
"the",
"PHP",
"memory_limit",
"ini",
"setting",
"by",
"the",
"specified",
"amount",
"in",
"kilobytes"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Error/BaseErrorHandler.php#L243-L264 |
210,727 | cakephp/cakephp | src/Error/BaseErrorHandler.php | BaseErrorHandler._getMessage | protected function _getMessage(Exception $exception)
{
$message = $this->getMessageForException($exception);
$request = Router::getRequest();
if ($request) {
$message .= $this->_requestContext($request);
}
return $message;
} | php | protected function _getMessage(Exception $exception)
{
$message = $this->getMessageForException($exception);
$request = Router::getRequest();
if ($request) {
$message .= $this->_requestContext($request);
}
return $message;
} | [
"protected",
"function",
"_getMessage",
"(",
"Exception",
"$",
"exception",
")",
"{",
"$",
"message",
"=",
"$",
"this",
"->",
"getMessageForException",
"(",
"$",
"exception",
")",
";",
"$",
"request",
"=",
"Router",
"::",
"getRequest",
"(",
")",
";",
"if",
"(",
"$",
"request",
")",
"{",
"$",
"message",
".=",
"$",
"this",
"->",
"_requestContext",
"(",
"$",
"request",
")",
";",
"}",
"return",
"$",
"message",
";",
"}"
] | Generates a formatted error message
@param \Exception $exception Exception instance
@return string Formatted message | [
"Generates",
"a",
"formatted",
"error",
"message"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Error/BaseErrorHandler.php#L356-L366 |
210,728 | cakephp/cakephp | src/Error/BaseErrorHandler.php | BaseErrorHandler.mapErrorCode | public static function mapErrorCode($code)
{
$levelMap = [
E_PARSE => 'error',
E_ERROR => 'error',
E_CORE_ERROR => 'error',
E_COMPILE_ERROR => 'error',
E_USER_ERROR => 'error',
E_WARNING => 'warning',
E_USER_WARNING => 'warning',
E_COMPILE_WARNING => 'warning',
E_RECOVERABLE_ERROR => 'warning',
E_NOTICE => 'notice',
E_USER_NOTICE => 'notice',
E_STRICT => 'strict',
E_DEPRECATED => 'deprecated',
E_USER_DEPRECATED => 'deprecated',
];
$logMap = [
'error' => LOG_ERR,
'warning' => LOG_WARNING,
'notice' => LOG_NOTICE,
'strict' => LOG_NOTICE,
'deprecated' => LOG_NOTICE,
];
$error = $levelMap[$code];
$log = $logMap[$error];
return [ucfirst($error), $log];
} | php | public static function mapErrorCode($code)
{
$levelMap = [
E_PARSE => 'error',
E_ERROR => 'error',
E_CORE_ERROR => 'error',
E_COMPILE_ERROR => 'error',
E_USER_ERROR => 'error',
E_WARNING => 'warning',
E_USER_WARNING => 'warning',
E_COMPILE_WARNING => 'warning',
E_RECOVERABLE_ERROR => 'warning',
E_NOTICE => 'notice',
E_USER_NOTICE => 'notice',
E_STRICT => 'strict',
E_DEPRECATED => 'deprecated',
E_USER_DEPRECATED => 'deprecated',
];
$logMap = [
'error' => LOG_ERR,
'warning' => LOG_WARNING,
'notice' => LOG_NOTICE,
'strict' => LOG_NOTICE,
'deprecated' => LOG_NOTICE,
];
$error = $levelMap[$code];
$log = $logMap[$error];
return [ucfirst($error), $log];
} | [
"public",
"static",
"function",
"mapErrorCode",
"(",
"$",
"code",
")",
"{",
"$",
"levelMap",
"=",
"[",
"E_PARSE",
"=>",
"'error'",
",",
"E_ERROR",
"=>",
"'error'",
",",
"E_CORE_ERROR",
"=>",
"'error'",
",",
"E_COMPILE_ERROR",
"=>",
"'error'",
",",
"E_USER_ERROR",
"=>",
"'error'",
",",
"E_WARNING",
"=>",
"'warning'",
",",
"E_USER_WARNING",
"=>",
"'warning'",
",",
"E_COMPILE_WARNING",
"=>",
"'warning'",
",",
"E_RECOVERABLE_ERROR",
"=>",
"'warning'",
",",
"E_NOTICE",
"=>",
"'notice'",
",",
"E_USER_NOTICE",
"=>",
"'notice'",
",",
"E_STRICT",
"=>",
"'strict'",
",",
"E_DEPRECATED",
"=>",
"'deprecated'",
",",
"E_USER_DEPRECATED",
"=>",
"'deprecated'",
",",
"]",
";",
"$",
"logMap",
"=",
"[",
"'error'",
"=>",
"LOG_ERR",
",",
"'warning'",
"=>",
"LOG_WARNING",
",",
"'notice'",
"=>",
"LOG_NOTICE",
",",
"'strict'",
"=>",
"LOG_NOTICE",
",",
"'deprecated'",
"=>",
"LOG_NOTICE",
",",
"]",
";",
"$",
"error",
"=",
"$",
"levelMap",
"[",
"$",
"code",
"]",
";",
"$",
"log",
"=",
"$",
"logMap",
"[",
"$",
"error",
"]",
";",
"return",
"[",
"ucfirst",
"(",
"$",
"error",
")",
",",
"$",
"log",
"]",
";",
"}"
] | Map an error code into an Error word, and log location.
@param int $code Error code to map
@return array Array of error word, and log location. | [
"Map",
"an",
"error",
"code",
"into",
"an",
"Error",
"word",
"and",
"log",
"location",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Error/BaseErrorHandler.php#L417-L447 |
210,729 | cakephp/cakephp | src/Database/Expression/BetweenExpression.php | BetweenExpression._bindValue | protected function _bindValue($value, $generator, $type)
{
$placeholder = $generator->placeholder('c');
$generator->bind($placeholder, $value, $type);
return $placeholder;
} | php | protected function _bindValue($value, $generator, $type)
{
$placeholder = $generator->placeholder('c');
$generator->bind($placeholder, $value, $type);
return $placeholder;
} | [
"protected",
"function",
"_bindValue",
"(",
"$",
"value",
",",
"$",
"generator",
",",
"$",
"type",
")",
"{",
"$",
"placeholder",
"=",
"$",
"generator",
"->",
"placeholder",
"(",
"'c'",
")",
";",
"$",
"generator",
"->",
"bind",
"(",
"$",
"placeholder",
",",
"$",
"value",
",",
"$",
"type",
")",
";",
"return",
"$",
"placeholder",
";",
"}"
] | Registers a value in the placeholder generator and returns the generated placeholder
@param mixed $value The value to bind
@param \Cake\Database\ValueBinder $generator The value binder to use
@param string $type The type of $value
@return string generated placeholder | [
"Registers",
"a",
"value",
"in",
"the",
"placeholder",
"generator",
"and",
"returns",
"the",
"generated",
"placeholder"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/BetweenExpression.php#L122-L128 |
210,730 | cakephp/cakephp | src/Http/Server.php | Server.bootstrap | protected function bootstrap()
{
$this->app->bootstrap();
if ($this->app instanceof PluginApplicationInterface) {
$this->app->pluginBootstrap();
}
} | php | protected function bootstrap()
{
$this->app->bootstrap();
if ($this->app instanceof PluginApplicationInterface) {
$this->app->pluginBootstrap();
}
} | [
"protected",
"function",
"bootstrap",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"bootstrap",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"app",
"instanceof",
"PluginApplicationInterface",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"pluginBootstrap",
"(",
")",
";",
"}",
"}"
] | Application bootstrap wrapper.
Calls `bootstrap()` and `events()` if application implements `EventApplicationInterface`.
After the application is bootstrapped and events are attached, plugins are bootstrapped
and have their events attached.
@return void | [
"Application",
"bootstrap",
"wrapper",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Server.php#L119-L126 |
210,731 | cakephp/cakephp | src/Http/Server.php | Server.emit | public function emit(ResponseInterface $response, EmitterInterface $emitter = null)
{
if (!$emitter) {
$emitter = new ResponseEmitter();
}
$emitter->emit($response);
} | php | public function emit(ResponseInterface $response, EmitterInterface $emitter = null)
{
if (!$emitter) {
$emitter = new ResponseEmitter();
}
$emitter->emit($response);
} | [
"public",
"function",
"emit",
"(",
"ResponseInterface",
"$",
"response",
",",
"EmitterInterface",
"$",
"emitter",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"emitter",
")",
"{",
"$",
"emitter",
"=",
"new",
"ResponseEmitter",
"(",
")",
";",
"}",
"$",
"emitter",
"->",
"emit",
"(",
"$",
"response",
")",
";",
"}"
] | Emit the response using the PHP SAPI.
@param \Psr\Http\Message\ResponseInterface $response The response to emit
@param \Zend\Diactoros\Response\EmitterInterface|null $emitter The emitter to use.
When null, a SAPI Stream Emitter will be used.
@return void | [
"Emit",
"the",
"response",
"using",
"the",
"PHP",
"SAPI",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Server.php#L136-L142 |
210,732 | cakephp/cakephp | src/Auth/BaseAuthenticate.php | BaseAuthenticate._findUser | protected function _findUser($username, $password = null)
{
$result = $this->_query($username)->first();
if (empty($result)) {
// Waste time hashing the password, to prevent
// timing side-channels. However, don't hash
// null passwords as authentication systems
// like digest auth don't use passwords
// and hashing *could* create a timing side-channel.
if ($password !== null) {
$hasher = $this->passwordHasher();
$hasher->hash($password);
}
return false;
}
$passwordField = $this->_config['fields']['password'];
if ($password !== null) {
$hasher = $this->passwordHasher();
$hashedPassword = $result->get($passwordField);
if (!$hasher->check($password, $hashedPassword)) {
return false;
}
$this->_needsPasswordRehash = $hasher->needsRehash($hashedPassword);
$result->unsetProperty($passwordField);
}
$hidden = $result->getHidden();
if ($password === null && in_array($passwordField, $hidden)) {
$key = array_search($passwordField, $hidden);
unset($hidden[$key]);
$result->setHidden($hidden);
}
return $result->toArray();
} | php | protected function _findUser($username, $password = null)
{
$result = $this->_query($username)->first();
if (empty($result)) {
// Waste time hashing the password, to prevent
// timing side-channels. However, don't hash
// null passwords as authentication systems
// like digest auth don't use passwords
// and hashing *could* create a timing side-channel.
if ($password !== null) {
$hasher = $this->passwordHasher();
$hasher->hash($password);
}
return false;
}
$passwordField = $this->_config['fields']['password'];
if ($password !== null) {
$hasher = $this->passwordHasher();
$hashedPassword = $result->get($passwordField);
if (!$hasher->check($password, $hashedPassword)) {
return false;
}
$this->_needsPasswordRehash = $hasher->needsRehash($hashedPassword);
$result->unsetProperty($passwordField);
}
$hidden = $result->getHidden();
if ($password === null && in_array($passwordField, $hidden)) {
$key = array_search($passwordField, $hidden);
unset($hidden[$key]);
$result->setHidden($hidden);
}
return $result->toArray();
} | [
"protected",
"function",
"_findUser",
"(",
"$",
"username",
",",
"$",
"password",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"_query",
"(",
"$",
"username",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"// Waste time hashing the password, to prevent",
"// timing side-channels. However, don't hash",
"// null passwords as authentication systems",
"// like digest auth don't use passwords",
"// and hashing *could* create a timing side-channel.",
"if",
"(",
"$",
"password",
"!==",
"null",
")",
"{",
"$",
"hasher",
"=",
"$",
"this",
"->",
"passwordHasher",
"(",
")",
";",
"$",
"hasher",
"->",
"hash",
"(",
"$",
"password",
")",
";",
"}",
"return",
"false",
";",
"}",
"$",
"passwordField",
"=",
"$",
"this",
"->",
"_config",
"[",
"'fields'",
"]",
"[",
"'password'",
"]",
";",
"if",
"(",
"$",
"password",
"!==",
"null",
")",
"{",
"$",
"hasher",
"=",
"$",
"this",
"->",
"passwordHasher",
"(",
")",
";",
"$",
"hashedPassword",
"=",
"$",
"result",
"->",
"get",
"(",
"$",
"passwordField",
")",
";",
"if",
"(",
"!",
"$",
"hasher",
"->",
"check",
"(",
"$",
"password",
",",
"$",
"hashedPassword",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"_needsPasswordRehash",
"=",
"$",
"hasher",
"->",
"needsRehash",
"(",
"$",
"hashedPassword",
")",
";",
"$",
"result",
"->",
"unsetProperty",
"(",
"$",
"passwordField",
")",
";",
"}",
"$",
"hidden",
"=",
"$",
"result",
"->",
"getHidden",
"(",
")",
";",
"if",
"(",
"$",
"password",
"===",
"null",
"&&",
"in_array",
"(",
"$",
"passwordField",
",",
"$",
"hidden",
")",
")",
"{",
"$",
"key",
"=",
"array_search",
"(",
"$",
"passwordField",
",",
"$",
"hidden",
")",
";",
"unset",
"(",
"$",
"hidden",
"[",
"$",
"key",
"]",
")",
";",
"$",
"result",
"->",
"setHidden",
"(",
"$",
"hidden",
")",
";",
"}",
"return",
"$",
"result",
"->",
"toArray",
"(",
")",
";",
"}"
] | Find a user record using the username and password provided.
Input passwords will be hashed even when a user doesn't exist. This
helps mitigate timing attacks that are attempting to find valid usernames.
@param string $username The username/identifier.
@param string|null $password The password, if not provided password checking is skipped
and result of find is returned.
@return bool|array Either false on failure, or an array of user data. | [
"Find",
"a",
"user",
"record",
"using",
"the",
"username",
"and",
"password",
"provided",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Auth/BaseAuthenticate.php#L112-L149 |
210,733 | cakephp/cakephp | src/Core/Plugin.php | Plugin.load | public static function load($plugin, array $config = [])
{
deprecationWarning(
'Plugin::load() is deprecated. ' .
'Use Application::addPlugin() instead. ' .
'This method will be removed in 4.0.0.'
);
if (is_array($plugin)) {
foreach ($plugin as $name => $conf) {
list($name, $conf) = is_numeric($name) ? [$conf, $config] : [$name, $conf];
static::load($name, $conf);
}
return;
}
$config += [
'autoload' => false,
'bootstrap' => false,
'routes' => false,
'console' => true,
'classBase' => 'src',
'ignoreMissing' => false,
'name' => $plugin
];
if (!isset($config['path'])) {
$config['path'] = static::getCollection()->findPath($plugin);
}
$config['classPath'] = $config['path'] . $config['classBase'] . DIRECTORY_SEPARATOR;
if (!isset($config['configPath'])) {
$config['configPath'] = $config['path'] . 'config' . DIRECTORY_SEPARATOR;
}
$pluginClass = str_replace('/', '\\', $plugin) . '\\Plugin';
if (class_exists($pluginClass)) {
$instance = new $pluginClass($config);
} else {
// Use stub plugin as this method will be removed long term.
$instance = new BasePlugin($config);
}
static::getCollection()->add($instance);
if ($config['autoload'] === true) {
if (empty(static::$_loader)) {
static::$_loader = new ClassLoader();
static::$_loader->register();
}
static::$_loader->addNamespace(
str_replace('/', '\\', $plugin),
$config['path'] . $config['classBase'] . DIRECTORY_SEPARATOR
);
static::$_loader->addNamespace(
str_replace('/', '\\', $plugin) . '\Test',
$config['path'] . 'tests' . DIRECTORY_SEPARATOR
);
}
if ($config['bootstrap'] === true) {
static::bootstrap($plugin);
}
} | php | public static function load($plugin, array $config = [])
{
deprecationWarning(
'Plugin::load() is deprecated. ' .
'Use Application::addPlugin() instead. ' .
'This method will be removed in 4.0.0.'
);
if (is_array($plugin)) {
foreach ($plugin as $name => $conf) {
list($name, $conf) = is_numeric($name) ? [$conf, $config] : [$name, $conf];
static::load($name, $conf);
}
return;
}
$config += [
'autoload' => false,
'bootstrap' => false,
'routes' => false,
'console' => true,
'classBase' => 'src',
'ignoreMissing' => false,
'name' => $plugin
];
if (!isset($config['path'])) {
$config['path'] = static::getCollection()->findPath($plugin);
}
$config['classPath'] = $config['path'] . $config['classBase'] . DIRECTORY_SEPARATOR;
if (!isset($config['configPath'])) {
$config['configPath'] = $config['path'] . 'config' . DIRECTORY_SEPARATOR;
}
$pluginClass = str_replace('/', '\\', $plugin) . '\\Plugin';
if (class_exists($pluginClass)) {
$instance = new $pluginClass($config);
} else {
// Use stub plugin as this method will be removed long term.
$instance = new BasePlugin($config);
}
static::getCollection()->add($instance);
if ($config['autoload'] === true) {
if (empty(static::$_loader)) {
static::$_loader = new ClassLoader();
static::$_loader->register();
}
static::$_loader->addNamespace(
str_replace('/', '\\', $plugin),
$config['path'] . $config['classBase'] . DIRECTORY_SEPARATOR
);
static::$_loader->addNamespace(
str_replace('/', '\\', $plugin) . '\Test',
$config['path'] . 'tests' . DIRECTORY_SEPARATOR
);
}
if ($config['bootstrap'] === true) {
static::bootstrap($plugin);
}
} | [
"public",
"static",
"function",
"load",
"(",
"$",
"plugin",
",",
"array",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"deprecationWarning",
"(",
"'Plugin::load() is deprecated. '",
".",
"'Use Application::addPlugin() instead. '",
".",
"'This method will be removed in 4.0.0.'",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"plugin",
")",
")",
"{",
"foreach",
"(",
"$",
"plugin",
"as",
"$",
"name",
"=>",
"$",
"conf",
")",
"{",
"list",
"(",
"$",
"name",
",",
"$",
"conf",
")",
"=",
"is_numeric",
"(",
"$",
"name",
")",
"?",
"[",
"$",
"conf",
",",
"$",
"config",
"]",
":",
"[",
"$",
"name",
",",
"$",
"conf",
"]",
";",
"static",
"::",
"load",
"(",
"$",
"name",
",",
"$",
"conf",
")",
";",
"}",
"return",
";",
"}",
"$",
"config",
"+=",
"[",
"'autoload'",
"=>",
"false",
",",
"'bootstrap'",
"=>",
"false",
",",
"'routes'",
"=>",
"false",
",",
"'console'",
"=>",
"true",
",",
"'classBase'",
"=>",
"'src'",
",",
"'ignoreMissing'",
"=>",
"false",
",",
"'name'",
"=>",
"$",
"plugin",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'path'",
"]",
")",
")",
"{",
"$",
"config",
"[",
"'path'",
"]",
"=",
"static",
"::",
"getCollection",
"(",
")",
"->",
"findPath",
"(",
"$",
"plugin",
")",
";",
"}",
"$",
"config",
"[",
"'classPath'",
"]",
"=",
"$",
"config",
"[",
"'path'",
"]",
".",
"$",
"config",
"[",
"'classBase'",
"]",
".",
"DIRECTORY_SEPARATOR",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'configPath'",
"]",
")",
")",
"{",
"$",
"config",
"[",
"'configPath'",
"]",
"=",
"$",
"config",
"[",
"'path'",
"]",
".",
"'config'",
".",
"DIRECTORY_SEPARATOR",
";",
"}",
"$",
"pluginClass",
"=",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"plugin",
")",
".",
"'\\\\Plugin'",
";",
"if",
"(",
"class_exists",
"(",
"$",
"pluginClass",
")",
")",
"{",
"$",
"instance",
"=",
"new",
"$",
"pluginClass",
"(",
"$",
"config",
")",
";",
"}",
"else",
"{",
"// Use stub plugin as this method will be removed long term.",
"$",
"instance",
"=",
"new",
"BasePlugin",
"(",
"$",
"config",
")",
";",
"}",
"static",
"::",
"getCollection",
"(",
")",
"->",
"add",
"(",
"$",
"instance",
")",
";",
"if",
"(",
"$",
"config",
"[",
"'autoload'",
"]",
"===",
"true",
")",
"{",
"if",
"(",
"empty",
"(",
"static",
"::",
"$",
"_loader",
")",
")",
"{",
"static",
"::",
"$",
"_loader",
"=",
"new",
"ClassLoader",
"(",
")",
";",
"static",
"::",
"$",
"_loader",
"->",
"register",
"(",
")",
";",
"}",
"static",
"::",
"$",
"_loader",
"->",
"addNamespace",
"(",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"plugin",
")",
",",
"$",
"config",
"[",
"'path'",
"]",
".",
"$",
"config",
"[",
"'classBase'",
"]",
".",
"DIRECTORY_SEPARATOR",
")",
";",
"static",
"::",
"$",
"_loader",
"->",
"addNamespace",
"(",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"plugin",
")",
".",
"'\\Test'",
",",
"$",
"config",
"[",
"'path'",
"]",
".",
"'tests'",
".",
"DIRECTORY_SEPARATOR",
")",
";",
"}",
"if",
"(",
"$",
"config",
"[",
"'bootstrap'",
"]",
"===",
"true",
")",
"{",
"static",
"::",
"bootstrap",
"(",
"$",
"plugin",
")",
";",
"}",
"}"
] | Loads a plugin and optionally loads bootstrapping,
routing files or runs an initialization function.
Plugins only need to be loaded if you want bootstrapping/routes/cli commands to
be exposed. If your plugin does not expose any of these features you do not need
to load them.
This method does not configure any autoloaders. That must be done separately either
through composer, or your own code during config/bootstrap.php.
### Examples:
`Plugin::load('DebugKit')`
Will load the DebugKit plugin and will not load any bootstrap nor route files.
However, the plugin will be part of the framework default routes, and have its
CLI tools (if any) available for use.
`Plugin::load('DebugKit', ['bootstrap' => true, 'routes' => true])`
Will load the bootstrap.php and routes.php files.
`Plugin::load('DebugKit', ['bootstrap' => false, 'routes' => true])`
Will load routes.php file but not bootstrap.php
`Plugin::load('FOC/Authenticate')`
Will load plugin from `plugins/FOC/Authenticate`.
It is also possible to load multiple plugins at once. Examples:
`Plugin::load(['DebugKit', 'ApiGenerator'])`
Will load the DebugKit and ApiGenerator plugins.
`Plugin::load(['DebugKit', 'ApiGenerator'], ['bootstrap' => true])`
Will load bootstrap file for both plugins
```
Plugin::load([
'DebugKit' => ['routes' => true],
'ApiGenerator'
],
['bootstrap' => true])
```
Will only load the bootstrap for ApiGenerator and only the routes for DebugKit
### Configuration options
- `bootstrap` - array - Whether or not you want the $plugin/config/bootstrap.php file loaded.
- `routes` - boolean - Whether or not you want to load the $plugin/config/routes.php file.
- `ignoreMissing` - boolean - Set to true to ignore missing bootstrap/routes files.
- `path` - string - The path the plugin can be found on. If empty the default plugin path (App.pluginPaths) will be used.
- `classBase` - The path relative to `path` which contains the folders with class files.
Defaults to "src".
- `autoload` - boolean - Whether or not you want an autoloader registered. This defaults to false. The framework
assumes you have configured autoloaders using composer. However, if your application source tree is made up of
plugins, this can be a useful option.
@param string|array $plugin name of the plugin to be loaded in CamelCase format or array or plugins to load
@param array $config configuration options for the plugin
@throws \Cake\Core\Exception\MissingPluginException if the folder for the plugin to be loaded is not found
@return void
@deprecated 3.7.0 This method will be removed in 4.0.0. Use Application::addPlugin() instead. | [
"Loads",
"a",
"plugin",
"and",
"optionally",
"loads",
"bootstrapping",
"routing",
"files",
"or",
"runs",
"an",
"initialization",
"function",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/Plugin.php#L113-L175 |
210,734 | cakephp/cakephp | src/Core/Plugin.php | Plugin.loadAll | public static function loadAll(array $options = [])
{
$plugins = [];
foreach (App::path('Plugin') as $path) {
if (!is_dir($path)) {
continue;
}
$dir = new DirectoryIterator($path);
foreach ($dir as $dirPath) {
if ($dirPath->isDir() && !$dirPath->isDot()) {
$plugins[] = $dirPath->getBasename();
}
}
}
if (Configure::check('plugins')) {
$plugins = array_merge($plugins, array_keys(Configure::read('plugins')));
$plugins = array_unique($plugins);
}
$collection = static::getCollection();
foreach ($plugins as $p) {
$opts = isset($options[$p]) ? $options[$p] : null;
if ($opts === null && isset($options[0])) {
$opts = $options[0];
}
if ($collection->has($p)) {
continue;
}
static::load($p, (array)$opts);
}
} | php | public static function loadAll(array $options = [])
{
$plugins = [];
foreach (App::path('Plugin') as $path) {
if (!is_dir($path)) {
continue;
}
$dir = new DirectoryIterator($path);
foreach ($dir as $dirPath) {
if ($dirPath->isDir() && !$dirPath->isDot()) {
$plugins[] = $dirPath->getBasename();
}
}
}
if (Configure::check('plugins')) {
$plugins = array_merge($plugins, array_keys(Configure::read('plugins')));
$plugins = array_unique($plugins);
}
$collection = static::getCollection();
foreach ($plugins as $p) {
$opts = isset($options[$p]) ? $options[$p] : null;
if ($opts === null && isset($options[0])) {
$opts = $options[0];
}
if ($collection->has($p)) {
continue;
}
static::load($p, (array)$opts);
}
} | [
"public",
"static",
"function",
"loadAll",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"plugins",
"=",
"[",
"]",
";",
"foreach",
"(",
"App",
"::",
"path",
"(",
"'Plugin'",
")",
"as",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"continue",
";",
"}",
"$",
"dir",
"=",
"new",
"DirectoryIterator",
"(",
"$",
"path",
")",
";",
"foreach",
"(",
"$",
"dir",
"as",
"$",
"dirPath",
")",
"{",
"if",
"(",
"$",
"dirPath",
"->",
"isDir",
"(",
")",
"&&",
"!",
"$",
"dirPath",
"->",
"isDot",
"(",
")",
")",
"{",
"$",
"plugins",
"[",
"]",
"=",
"$",
"dirPath",
"->",
"getBasename",
"(",
")",
";",
"}",
"}",
"}",
"if",
"(",
"Configure",
"::",
"check",
"(",
"'plugins'",
")",
")",
"{",
"$",
"plugins",
"=",
"array_merge",
"(",
"$",
"plugins",
",",
"array_keys",
"(",
"Configure",
"::",
"read",
"(",
"'plugins'",
")",
")",
")",
";",
"$",
"plugins",
"=",
"array_unique",
"(",
"$",
"plugins",
")",
";",
"}",
"$",
"collection",
"=",
"static",
"::",
"getCollection",
"(",
")",
";",
"foreach",
"(",
"$",
"plugins",
"as",
"$",
"p",
")",
"{",
"$",
"opts",
"=",
"isset",
"(",
"$",
"options",
"[",
"$",
"p",
"]",
")",
"?",
"$",
"options",
"[",
"$",
"p",
"]",
":",
"null",
";",
"if",
"(",
"$",
"opts",
"===",
"null",
"&&",
"isset",
"(",
"$",
"options",
"[",
"0",
"]",
")",
")",
"{",
"$",
"opts",
"=",
"$",
"options",
"[",
"0",
"]",
";",
"}",
"if",
"(",
"$",
"collection",
"->",
"has",
"(",
"$",
"p",
")",
")",
"{",
"continue",
";",
"}",
"static",
"::",
"load",
"(",
"$",
"p",
",",
"(",
"array",
")",
"$",
"opts",
")",
";",
"}",
"}"
] | Will load all the plugins located in the default plugin folder.
If passed an options array, it will be used as a common default for all plugins to be loaded
It is possible to set specific defaults for each plugins in the options array. Examples:
```
Plugin::loadAll([
['bootstrap' => true],
'DebugKit' => ['routes' => true],
]);
```
The above example will load the bootstrap file for all plugins, but for DebugKit it will only load the routes file
and will not look for any bootstrap script.
If a plugin has been loaded already, it will not be reloaded by loadAll().
@param array $options Options.
@return void
@throws \Cake\Core\Exception\MissingPluginException
@deprecated 3.7.0 This method will be removed in 4.0.0. | [
"Will",
"load",
"all",
"the",
"plugins",
"located",
"in",
"the",
"default",
"plugin",
"folder",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/Plugin.php#L200-L230 |
210,735 | cakephp/cakephp | src/Core/Plugin.php | Plugin.bootstrap | public static function bootstrap($name)
{
deprecationWarning(
'Plugin::bootstrap() is deprecated. ' .
'This method will be removed in 4.0.0.'
);
$plugin = static::getCollection()->get($name);
if (!$plugin->isEnabled('bootstrap')) {
return false;
}
// Disable bootstrapping for this plugin as it will have
// been bootstrapped.
$plugin->disable('bootstrap');
return static::_includeFile(
$plugin->getConfigPath() . 'bootstrap.php',
true
);
} | php | public static function bootstrap($name)
{
deprecationWarning(
'Plugin::bootstrap() is deprecated. ' .
'This method will be removed in 4.0.0.'
);
$plugin = static::getCollection()->get($name);
if (!$plugin->isEnabled('bootstrap')) {
return false;
}
// Disable bootstrapping for this plugin as it will have
// been bootstrapped.
$plugin->disable('bootstrap');
return static::_includeFile(
$plugin->getConfigPath() . 'bootstrap.php',
true
);
} | [
"public",
"static",
"function",
"bootstrap",
"(",
"$",
"name",
")",
"{",
"deprecationWarning",
"(",
"'Plugin::bootstrap() is deprecated. '",
".",
"'This method will be removed in 4.0.0.'",
")",
";",
"$",
"plugin",
"=",
"static",
"::",
"getCollection",
"(",
")",
"->",
"get",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"$",
"plugin",
"->",
"isEnabled",
"(",
"'bootstrap'",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Disable bootstrapping for this plugin as it will have",
"// been bootstrapped.",
"$",
"plugin",
"->",
"disable",
"(",
"'bootstrap'",
")",
";",
"return",
"static",
"::",
"_includeFile",
"(",
"$",
"plugin",
"->",
"getConfigPath",
"(",
")",
".",
"'bootstrap.php'",
",",
"true",
")",
";",
"}"
] | Loads the bootstrapping files for a plugin, or calls the initialization setup in the configuration
@param string $name name of the plugin
@return mixed
@see \Cake\Core\Plugin::load() for examples of bootstrap configuration
@deprecated 3.7.0 This method will be removed in 4.0.0. | [
"Loads",
"the",
"bootstrapping",
"files",
"for",
"a",
"plugin",
"or",
"calls",
"the",
"initialization",
"setup",
"in",
"the",
"configuration"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/Plugin.php#L282-L300 |
210,736 | cakephp/cakephp | src/Core/Plugin.php | Plugin.routes | public static function routes($name = null)
{
deprecationWarning(
'You no longer need to call `Plugin::routes()` after upgrading to use Http\Server. ' .
'See https://book.cakephp.org/3.0/en/development/application.html#adding-the-new-http-stack-to-an-existing-application ' .
'for upgrade information.'
);
if ($name === null) {
foreach (static::loaded() as $p) {
static::routes($p);
}
return true;
}
$plugin = static::getCollection()->get($name);
if (!$plugin->isEnabled('routes')) {
return false;
}
return (bool)static::_includeFile(
$plugin->getConfigPath() . 'routes.php',
true
);
} | php | public static function routes($name = null)
{
deprecationWarning(
'You no longer need to call `Plugin::routes()` after upgrading to use Http\Server. ' .
'See https://book.cakephp.org/3.0/en/development/application.html#adding-the-new-http-stack-to-an-existing-application ' .
'for upgrade information.'
);
if ($name === null) {
foreach (static::loaded() as $p) {
static::routes($p);
}
return true;
}
$plugin = static::getCollection()->get($name);
if (!$plugin->isEnabled('routes')) {
return false;
}
return (bool)static::_includeFile(
$plugin->getConfigPath() . 'routes.php',
true
);
} | [
"public",
"static",
"function",
"routes",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"'You no longer need to call `Plugin::routes()` after upgrading to use Http\\Server. '",
".",
"'See https://book.cakephp.org/3.0/en/development/application.html#adding-the-new-http-stack-to-an-existing-application '",
".",
"'for upgrade information.'",
")",
";",
"if",
"(",
"$",
"name",
"===",
"null",
")",
"{",
"foreach",
"(",
"static",
"::",
"loaded",
"(",
")",
"as",
"$",
"p",
")",
"{",
"static",
"::",
"routes",
"(",
"$",
"p",
")",
";",
"}",
"return",
"true",
";",
"}",
"$",
"plugin",
"=",
"static",
"::",
"getCollection",
"(",
")",
"->",
"get",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"$",
"plugin",
"->",
"isEnabled",
"(",
"'routes'",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
"bool",
")",
"static",
"::",
"_includeFile",
"(",
"$",
"plugin",
"->",
"getConfigPath",
"(",
")",
".",
"'routes.php'",
",",
"true",
")",
";",
"}"
] | Loads the routes file for a plugin, or all plugins configured to load their respective routes file.
If you need fine grained control over how routes are loaded for plugins, you
can use {@see Cake\Routing\RouteBuilder::loadPlugin()}
@param string|null $name name of the plugin, if null will operate on all
plugins having enabled the loading of routes files.
@return bool
@deprecated 3.6.5 This method is no longer needed when using HttpApplicationInterface based applications.
This method will be removed in 4.0.0 | [
"Loads",
"the",
"routes",
"file",
"for",
"a",
"plugin",
"or",
"all",
"plugins",
"configured",
"to",
"load",
"their",
"respective",
"routes",
"file",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/Plugin.php#L314-L337 |
210,737 | cakephp/cakephp | src/Core/Plugin.php | Plugin.loaded | public static function loaded($plugin = null)
{
if ($plugin !== null) {
deprecationWarning(
'Checking a single plugin with Plugin::loaded() is deprecated. ' .
'Use Plugin::isLoaded() instead.'
);
return static::getCollection()->has($plugin);
}
$names = [];
foreach (static::getCollection() as $plugin) {
$names[] = $plugin->getName();
}
sort($names);
return $names;
} | php | public static function loaded($plugin = null)
{
if ($plugin !== null) {
deprecationWarning(
'Checking a single plugin with Plugin::loaded() is deprecated. ' .
'Use Plugin::isLoaded() instead.'
);
return static::getCollection()->has($plugin);
}
$names = [];
foreach (static::getCollection() as $plugin) {
$names[] = $plugin->getName();
}
sort($names);
return $names;
} | [
"public",
"static",
"function",
"loaded",
"(",
"$",
"plugin",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"plugin",
"!==",
"null",
")",
"{",
"deprecationWarning",
"(",
"'Checking a single plugin with Plugin::loaded() is deprecated. '",
".",
"'Use Plugin::isLoaded() instead.'",
")",
";",
"return",
"static",
"::",
"getCollection",
"(",
")",
"->",
"has",
"(",
"$",
"plugin",
")",
";",
"}",
"$",
"names",
"=",
"[",
"]",
";",
"foreach",
"(",
"static",
"::",
"getCollection",
"(",
")",
"as",
"$",
"plugin",
")",
"{",
"$",
"names",
"[",
"]",
"=",
"$",
"plugin",
"->",
"getName",
"(",
")",
";",
"}",
"sort",
"(",
"$",
"names",
")",
";",
"return",
"$",
"names",
";",
"}"
] | Return a list of loaded plugins.
If a plugin name is provided, the return value will be a bool
indicating whether or not the named plugin is loaded. This usage
is deprecated. Instead you should use Plugin::isLoaded($name)
@param string|null $plugin Plugin name.
@return bool|array Boolean true if $plugin is already loaded.
If $plugin is null, returns a list of plugins that have been loaded | [
"Return",
"a",
"list",
"of",
"loaded",
"plugins",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/Plugin.php#L362-L379 |
210,738 | cakephp/cakephp | src/Core/Plugin.php | Plugin.unload | public static function unload($plugin = null)
{
deprecationWarning('Plugin::unload() will be removed in 4.0. Use PluginCollection::remove() or clear()');
if ($plugin === null) {
static::getCollection()->clear();
} else {
static::getCollection()->remove($plugin);
}
} | php | public static function unload($plugin = null)
{
deprecationWarning('Plugin::unload() will be removed in 4.0. Use PluginCollection::remove() or clear()');
if ($plugin === null) {
static::getCollection()->clear();
} else {
static::getCollection()->remove($plugin);
}
} | [
"public",
"static",
"function",
"unload",
"(",
"$",
"plugin",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"'Plugin::unload() will be removed in 4.0. Use PluginCollection::remove() or clear()'",
")",
";",
"if",
"(",
"$",
"plugin",
"===",
"null",
")",
"{",
"static",
"::",
"getCollection",
"(",
")",
"->",
"clear",
"(",
")",
";",
"}",
"else",
"{",
"static",
"::",
"getCollection",
"(",
")",
"->",
"remove",
"(",
"$",
"plugin",
")",
";",
"}",
"}"
] | Forgets a loaded plugin or all of them if first parameter is null
@param string|null $plugin name of the plugin to forget
@deprecated 3.7.0 This method will be removed in 4.0.0. Use PluginCollection::remove() or clear() instead.
@return void | [
"Forgets",
"a",
"loaded",
"plugin",
"or",
"all",
"of",
"them",
"if",
"first",
"parameter",
"is",
"null"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/Plugin.php#L388-L396 |
210,739 | cakephp/cakephp | src/Routing/Middleware/RoutingMiddleware.php | RoutingMiddleware.buildRouteCollection | protected function buildRouteCollection()
{
if (Cache::enabled() && $this->cacheConfig !== null) {
return Cache::remember(static::ROUTE_COLLECTION_CACHE_KEY, function () {
return $this->prepareRouteCollection();
}, $this->cacheConfig);
}
return $this->prepareRouteCollection();
} | php | protected function buildRouteCollection()
{
if (Cache::enabled() && $this->cacheConfig !== null) {
return Cache::remember(static::ROUTE_COLLECTION_CACHE_KEY, function () {
return $this->prepareRouteCollection();
}, $this->cacheConfig);
}
return $this->prepareRouteCollection();
} | [
"protected",
"function",
"buildRouteCollection",
"(",
")",
"{",
"if",
"(",
"Cache",
"::",
"enabled",
"(",
")",
"&&",
"$",
"this",
"->",
"cacheConfig",
"!==",
"null",
")",
"{",
"return",
"Cache",
"::",
"remember",
"(",
"static",
"::",
"ROUTE_COLLECTION_CACHE_KEY",
",",
"function",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"prepareRouteCollection",
"(",
")",
";",
"}",
",",
"$",
"this",
"->",
"cacheConfig",
")",
";",
"}",
"return",
"$",
"this",
"->",
"prepareRouteCollection",
"(",
")",
";",
"}"
] | Check if route cache is enabled and use the configured Cache to 'remember' the route collection
@return \Cake\Routing\RouteCollection | [
"Check",
"if",
"route",
"cache",
"is",
"enabled",
"and",
"use",
"the",
"configured",
"Cache",
"to",
"remember",
"the",
"route",
"collection"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Middleware/RoutingMiddleware.php#L96-L105 |
210,740 | cakephp/cakephp | src/Routing/Middleware/RoutingMiddleware.php | RoutingMiddleware.prepareRouteCollection | protected function prepareRouteCollection()
{
$builder = Router::createRouteBuilder('/');
$this->app->routes($builder);
if ($this->app instanceof PluginApplicationInterface) {
$this->app->pluginRoutes($builder);
}
return Router::getRouteCollection();
} | php | protected function prepareRouteCollection()
{
$builder = Router::createRouteBuilder('/');
$this->app->routes($builder);
if ($this->app instanceof PluginApplicationInterface) {
$this->app->pluginRoutes($builder);
}
return Router::getRouteCollection();
} | [
"protected",
"function",
"prepareRouteCollection",
"(",
")",
"{",
"$",
"builder",
"=",
"Router",
"::",
"createRouteBuilder",
"(",
"'/'",
")",
";",
"$",
"this",
"->",
"app",
"->",
"routes",
"(",
"$",
"builder",
")",
";",
"if",
"(",
"$",
"this",
"->",
"app",
"instanceof",
"PluginApplicationInterface",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"pluginRoutes",
"(",
"$",
"builder",
")",
";",
"}",
"return",
"Router",
"::",
"getRouteCollection",
"(",
")",
";",
"}"
] | Generate the route collection using the builder
@return \Cake\Routing\RouteCollection | [
"Generate",
"the",
"route",
"collection",
"using",
"the",
"builder"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Middleware/RoutingMiddleware.php#L112-L121 |
210,741 | cakephp/cakephp | src/Collection/Iterator/NestIterator.php | NestIterator.getChildren | public function getChildren()
{
$property = $this->_propertyExtractor($this->_nestKey);
return new static($property($this->current()), $this->_nestKey);
} | php | public function getChildren()
{
$property = $this->_propertyExtractor($this->_nestKey);
return new static($property($this->current()), $this->_nestKey);
} | [
"public",
"function",
"getChildren",
"(",
")",
"{",
"$",
"property",
"=",
"$",
"this",
"->",
"_propertyExtractor",
"(",
"$",
"this",
"->",
"_nestKey",
")",
";",
"return",
"new",
"static",
"(",
"$",
"property",
"(",
"$",
"this",
"->",
"current",
"(",
")",
")",
",",
"$",
"this",
"->",
"_nestKey",
")",
";",
"}"
] | Returns a traversable containing the children for the current item
@return \Traversable | [
"Returns",
"a",
"traversable",
"containing",
"the",
"children",
"for",
"the",
"current",
"item"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Collection/Iterator/NestIterator.php#L53-L58 |
210,742 | cakephp/cakephp | src/Collection/Iterator/NestIterator.php | NestIterator.hasChildren | public function hasChildren()
{
$property = $this->_propertyExtractor($this->_nestKey);
$children = $property($this->current());
if (is_array($children)) {
return !empty($children);
}
return $children instanceof Traversable;
} | php | public function hasChildren()
{
$property = $this->_propertyExtractor($this->_nestKey);
$children = $property($this->current());
if (is_array($children)) {
return !empty($children);
}
return $children instanceof Traversable;
} | [
"public",
"function",
"hasChildren",
"(",
")",
"{",
"$",
"property",
"=",
"$",
"this",
"->",
"_propertyExtractor",
"(",
"$",
"this",
"->",
"_nestKey",
")",
";",
"$",
"children",
"=",
"$",
"property",
"(",
"$",
"this",
"->",
"current",
"(",
")",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"children",
")",
")",
"{",
"return",
"!",
"empty",
"(",
"$",
"children",
")",
";",
"}",
"return",
"$",
"children",
"instanceof",
"Traversable",
";",
"}"
] | Returns true if there is an array or a traversable object stored under the
configured nestKey for the current item
@return bool | [
"Returns",
"true",
"if",
"there",
"is",
"an",
"array",
"or",
"a",
"traversable",
"object",
"stored",
"under",
"the",
"configured",
"nestKey",
"for",
"the",
"current",
"item"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Collection/Iterator/NestIterator.php#L66-L76 |
210,743 | cakephp/cakephp | src/Http/BaseApplication.php | BaseApplication.makePlugin | protected function makePlugin($name, array $config)
{
$className = $name;
if (strpos($className, '\\') === false) {
$className = str_replace('/', '\\', $className) . '\\' . 'Plugin';
}
if (class_exists($className)) {
return new $className($config);
}
if (!isset($config['path'])) {
$config['path'] = $this->plugins->findPath($name);
}
$config['name'] = $name;
return new BasePlugin($config);
} | php | protected function makePlugin($name, array $config)
{
$className = $name;
if (strpos($className, '\\') === false) {
$className = str_replace('/', '\\', $className) . '\\' . 'Plugin';
}
if (class_exists($className)) {
return new $className($config);
}
if (!isset($config['path'])) {
$config['path'] = $this->plugins->findPath($name);
}
$config['name'] = $name;
return new BasePlugin($config);
} | [
"protected",
"function",
"makePlugin",
"(",
"$",
"name",
",",
"array",
"$",
"config",
")",
"{",
"$",
"className",
"=",
"$",
"name",
";",
"if",
"(",
"strpos",
"(",
"$",
"className",
",",
"'\\\\'",
")",
"===",
"false",
")",
"{",
"$",
"className",
"=",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"className",
")",
".",
"'\\\\'",
".",
"'Plugin'",
";",
"}",
"if",
"(",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"return",
"new",
"$",
"className",
"(",
"$",
"config",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'path'",
"]",
")",
")",
"{",
"$",
"config",
"[",
"'path'",
"]",
"=",
"$",
"this",
"->",
"plugins",
"->",
"findPath",
"(",
"$",
"name",
")",
";",
"}",
"$",
"config",
"[",
"'name'",
"]",
"=",
"$",
"name",
";",
"return",
"new",
"BasePlugin",
"(",
"$",
"config",
")",
";",
"}"
] | Create a plugin instance from a classname and configuration
@param string $name The plugin classname
@param array $config Configuration options for the plugin
@return \Cake\Core\PluginInterface | [
"Create",
"a",
"plugin",
"instance",
"from",
"a",
"classname",
"and",
"configuration"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/BaseApplication.php#L129-L145 |
210,744 | cakephp/cakephp | src/Http/Middleware/BodyParserMiddleware.php | BodyParserMiddleware.addParser | public function addParser(array $types, callable $parser)
{
foreach ($types as $type) {
$type = strtolower($type);
$this->parsers[$type] = $parser;
}
return $this;
} | php | public function addParser(array $types, callable $parser)
{
foreach ($types as $type) {
$type = strtolower($type);
$this->parsers[$type] = $parser;
}
return $this;
} | [
"public",
"function",
"addParser",
"(",
"array",
"$",
"types",
",",
"callable",
"$",
"parser",
")",
"{",
"foreach",
"(",
"$",
"types",
"as",
"$",
"type",
")",
"{",
"$",
"type",
"=",
"strtolower",
"(",
"$",
"type",
")",
";",
"$",
"this",
"->",
"parsers",
"[",
"$",
"type",
"]",
"=",
"$",
"parser",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Add a parser.
Map a set of content-type header values to be parsed by the $parser.
### Example
An naive CSV request body parser could be built like so:
```
$parser->addParser(['text/csv'], function ($body) {
return str_getcsv($body);
});
```
@param array $types An array of content-type header values to match. eg. application/json
@param callable $parser The parser function. Must return an array of data to be inserted
into the request.
@return $this | [
"Add",
"a",
"parser",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Middleware/BodyParserMiddleware.php#L112-L120 |
210,745 | cakephp/cakephp | src/Http/Middleware/BodyParserMiddleware.php | BodyParserMiddleware.decodeXml | protected function decodeXml($body)
{
try {
$xml = Xml::build($body, ['return' => 'domdocument', 'readFile' => false]);
// We might not get child nodes if there are nested inline entities.
if ((int)$xml->childNodes->length > 0) {
return Xml::toArray($xml);
}
return [];
} catch (XmlException $e) {
return [];
}
} | php | protected function decodeXml($body)
{
try {
$xml = Xml::build($body, ['return' => 'domdocument', 'readFile' => false]);
// We might not get child nodes if there are nested inline entities.
if ((int)$xml->childNodes->length > 0) {
return Xml::toArray($xml);
}
return [];
} catch (XmlException $e) {
return [];
}
} | [
"protected",
"function",
"decodeXml",
"(",
"$",
"body",
")",
"{",
"try",
"{",
"$",
"xml",
"=",
"Xml",
"::",
"build",
"(",
"$",
"body",
",",
"[",
"'return'",
"=>",
"'domdocument'",
",",
"'readFile'",
"=>",
"false",
"]",
")",
";",
"// We might not get child nodes if there are nested inline entities.",
"if",
"(",
"(",
"int",
")",
"$",
"xml",
"->",
"childNodes",
"->",
"length",
">",
"0",
")",
"{",
"return",
"Xml",
"::",
"toArray",
"(",
"$",
"xml",
")",
";",
"}",
"return",
"[",
"]",
";",
"}",
"catch",
"(",
"XmlException",
"$",
"e",
")",
"{",
"return",
"[",
"]",
";",
"}",
"}"
] | Decode XML into an array.
@param string $body The request body to decode
@return array | [
"Decode",
"XML",
"into",
"an",
"array",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Middleware/BodyParserMiddleware.php#L170-L183 |
210,746 | cakephp/cakephp | src/Log/Engine/FileLog.php | FileLog._rotateFile | protected function _rotateFile($filename)
{
$filePath = $this->_path . $filename;
clearstatcache(true, $filePath);
if (!file_exists($filePath) ||
filesize($filePath) < $this->_size
) {
return null;
}
$rotate = $this->_config['rotate'];
if ($rotate === 0) {
$result = unlink($filePath);
} else {
$result = rename($filePath, $filePath . '.' . time());
}
$files = glob($filePath . '.*');
if ($files) {
$filesToDelete = count($files) - $rotate;
while ($filesToDelete > 0) {
unlink(array_shift($files));
$filesToDelete--;
}
}
return $result;
} | php | protected function _rotateFile($filename)
{
$filePath = $this->_path . $filename;
clearstatcache(true, $filePath);
if (!file_exists($filePath) ||
filesize($filePath) < $this->_size
) {
return null;
}
$rotate = $this->_config['rotate'];
if ($rotate === 0) {
$result = unlink($filePath);
} else {
$result = rename($filePath, $filePath . '.' . time());
}
$files = glob($filePath . '.*');
if ($files) {
$filesToDelete = count($files) - $rotate;
while ($filesToDelete > 0) {
unlink(array_shift($files));
$filesToDelete--;
}
}
return $result;
} | [
"protected",
"function",
"_rotateFile",
"(",
"$",
"filename",
")",
"{",
"$",
"filePath",
"=",
"$",
"this",
"->",
"_path",
".",
"$",
"filename",
";",
"clearstatcache",
"(",
"true",
",",
"$",
"filePath",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"filePath",
")",
"||",
"filesize",
"(",
"$",
"filePath",
")",
"<",
"$",
"this",
"->",
"_size",
")",
"{",
"return",
"null",
";",
"}",
"$",
"rotate",
"=",
"$",
"this",
"->",
"_config",
"[",
"'rotate'",
"]",
";",
"if",
"(",
"$",
"rotate",
"===",
"0",
")",
"{",
"$",
"result",
"=",
"unlink",
"(",
"$",
"filePath",
")",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"rename",
"(",
"$",
"filePath",
",",
"$",
"filePath",
".",
"'.'",
".",
"time",
"(",
")",
")",
";",
"}",
"$",
"files",
"=",
"glob",
"(",
"$",
"filePath",
".",
"'.*'",
")",
";",
"if",
"(",
"$",
"files",
")",
"{",
"$",
"filesToDelete",
"=",
"count",
"(",
"$",
"files",
")",
"-",
"$",
"rotate",
";",
"while",
"(",
"$",
"filesToDelete",
">",
"0",
")",
"{",
"unlink",
"(",
"array_shift",
"(",
"$",
"files",
")",
")",
";",
"$",
"filesToDelete",
"--",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Rotate log file if size specified in config is reached.
Also if `rotate` count is reached oldest file is removed.
@param string $filename Log file name
@return bool|null True if rotated successfully or false in case of error.
Null if file doesn't need to be rotated. | [
"Rotate",
"log",
"file",
"if",
"size",
"specified",
"in",
"config",
"is",
"reached",
".",
"Also",
"if",
"rotate",
"count",
"is",
"reached",
"oldest",
"file",
"is",
"removed",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Log/Engine/FileLog.php#L183-L211 |
210,747 | cakephp/cakephp | src/ORM/EagerLoader.php | EagerLoader.contain | public function contain($associations = [], callable $queryBuilder = null)
{
if (empty($associations)) {
deprecationWarning(
'Using EagerLoader::contain() as getter is deprecated. ' .
'Use getContain() instead.'
);
return $this->getContain();
}
if ($queryBuilder) {
if (!is_string($associations)) {
throw new InvalidArgumentException(
sprintf('Cannot set containments. To use $queryBuilder, $associations must be a string')
);
}
$associations = [
$associations => [
'queryBuilder' => $queryBuilder
]
];
}
$associations = (array)$associations;
$associations = $this->_reformatContain($associations, $this->_containments);
$this->_normalized = null;
$this->_loadExternal = [];
$this->_aliasList = [];
return $this->_containments = $associations;
} | php | public function contain($associations = [], callable $queryBuilder = null)
{
if (empty($associations)) {
deprecationWarning(
'Using EagerLoader::contain() as getter is deprecated. ' .
'Use getContain() instead.'
);
return $this->getContain();
}
if ($queryBuilder) {
if (!is_string($associations)) {
throw new InvalidArgumentException(
sprintf('Cannot set containments. To use $queryBuilder, $associations must be a string')
);
}
$associations = [
$associations => [
'queryBuilder' => $queryBuilder
]
];
}
$associations = (array)$associations;
$associations = $this->_reformatContain($associations, $this->_containments);
$this->_normalized = null;
$this->_loadExternal = [];
$this->_aliasList = [];
return $this->_containments = $associations;
} | [
"public",
"function",
"contain",
"(",
"$",
"associations",
"=",
"[",
"]",
",",
"callable",
"$",
"queryBuilder",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"associations",
")",
")",
"{",
"deprecationWarning",
"(",
"'Using EagerLoader::contain() as getter is deprecated. '",
".",
"'Use getContain() instead.'",
")",
";",
"return",
"$",
"this",
"->",
"getContain",
"(",
")",
";",
"}",
"if",
"(",
"$",
"queryBuilder",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"associations",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Cannot set containments. To use $queryBuilder, $associations must be a string'",
")",
")",
";",
"}",
"$",
"associations",
"=",
"[",
"$",
"associations",
"=>",
"[",
"'queryBuilder'",
"=>",
"$",
"queryBuilder",
"]",
"]",
";",
"}",
"$",
"associations",
"=",
"(",
"array",
")",
"$",
"associations",
";",
"$",
"associations",
"=",
"$",
"this",
"->",
"_reformatContain",
"(",
"$",
"associations",
",",
"$",
"this",
"->",
"_containments",
")",
";",
"$",
"this",
"->",
"_normalized",
"=",
"null",
";",
"$",
"this",
"->",
"_loadExternal",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"_aliasList",
"=",
"[",
"]",
";",
"return",
"$",
"this",
"->",
"_containments",
"=",
"$",
"associations",
";",
"}"
] | Sets the list of associations that should be eagerly loaded along for a
specific table using when a query is provided. The list of associated tables
passed to this method must have been previously set as associations using the
Table API.
Associations can be arbitrarily nested using dot notation or nested arrays,
this allows this object to calculate joins or any additional queries that
must be executed to bring the required associated data.
The getter part is deprecated as of 3.6.0. Use getContain() instead.
Accepted options per passed association:
- foreignKey: Used to set a different field to match both tables, if set to false
no join conditions will be generated automatically
- fields: An array with the fields that should be fetched from the association
- queryBuilder: Equivalent to passing a callable instead of an options array
- matching: Whether to inform the association class that it should filter the
main query by the results fetched by that class.
- joinType: For joinable associations, the SQL join type to use.
- strategy: The loading strategy to use (join, select, subquery)
@param array|string $associations list of table aliases to be queried.
When this method is called multiple times it will merge previous list with
the new one.
@param callable|null $queryBuilder The query builder callable
@return array Containments.
@throws \InvalidArgumentException When using $queryBuilder with an array of $associations | [
"Sets",
"the",
"list",
"of",
"associations",
"that",
"should",
"be",
"eagerly",
"loaded",
"along",
"for",
"a",
"specific",
"table",
"using",
"when",
"a",
"query",
"is",
"provided",
".",
"The",
"list",
"of",
"associated",
"tables",
"passed",
"to",
"this",
"method",
"must",
"have",
"been",
"previously",
"set",
"as",
"associations",
"using",
"the",
"Table",
"API",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/EagerLoader.php#L136-L168 |
210,748 | cakephp/cakephp | src/ORM/EagerLoader.php | EagerLoader.clearContain | public function clearContain()
{
$this->_containments = [];
$this->_normalized = null;
$this->_loadExternal = [];
$this->_aliasList = [];
} | php | public function clearContain()
{
$this->_containments = [];
$this->_normalized = null;
$this->_loadExternal = [];
$this->_aliasList = [];
} | [
"public",
"function",
"clearContain",
"(",
")",
"{",
"$",
"this",
"->",
"_containments",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"_normalized",
"=",
"null",
";",
"$",
"this",
"->",
"_loadExternal",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"_aliasList",
"=",
"[",
"]",
";",
"}"
] | Remove any existing non-matching based containments.
This will reset/clear out any contained associations that were not
added via matching().
@return void | [
"Remove",
"any",
"existing",
"non",
"-",
"matching",
"based",
"containments",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/EagerLoader.php#L191-L197 |
210,749 | cakephp/cakephp | src/ORM/EagerLoader.php | EagerLoader.normalized | public function normalized(Table $repository)
{
if ($this->_normalized !== null || empty($this->_containments)) {
return (array)$this->_normalized;
}
$contain = [];
foreach ($this->_containments as $alias => $options) {
if (!empty($options['instance'])) {
$contain = (array)$this->_containments;
break;
}
$contain[$alias] = $this->_normalizeContain(
$repository,
$alias,
$options,
['root' => null]
);
}
return $this->_normalized = $contain;
} | php | public function normalized(Table $repository)
{
if ($this->_normalized !== null || empty($this->_containments)) {
return (array)$this->_normalized;
}
$contain = [];
foreach ($this->_containments as $alias => $options) {
if (!empty($options['instance'])) {
$contain = (array)$this->_containments;
break;
}
$contain[$alias] = $this->_normalizeContain(
$repository,
$alias,
$options,
['root' => null]
);
}
return $this->_normalized = $contain;
} | [
"public",
"function",
"normalized",
"(",
"Table",
"$",
"repository",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_normalized",
"!==",
"null",
"||",
"empty",
"(",
"$",
"this",
"->",
"_containments",
")",
")",
"{",
"return",
"(",
"array",
")",
"$",
"this",
"->",
"_normalized",
";",
"}",
"$",
"contain",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_containments",
"as",
"$",
"alias",
"=>",
"$",
"options",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'instance'",
"]",
")",
")",
"{",
"$",
"contain",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"_containments",
";",
"break",
";",
"}",
"$",
"contain",
"[",
"$",
"alias",
"]",
"=",
"$",
"this",
"->",
"_normalizeContain",
"(",
"$",
"repository",
",",
"$",
"alias",
",",
"$",
"options",
",",
"[",
"'root'",
"=>",
"null",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_normalized",
"=",
"$",
"contain",
";",
"}"
] | Returns the fully normalized array of associations that should be eagerly
loaded for a table. The normalized array will restructure the original array
by sorting all associations under one key and special options under another.
Each of the levels of the associations tree will converted to a Cake\ORM\EagerLoadable
object, that contains all the information required for the association objects
to load the information from the database.
Additionally it will set an 'instance' key per association containing the
association instance from the corresponding source table
@param \Cake\ORM\Table $repository The table containing the association that
will be normalized
@return array | [
"Returns",
"the",
"fully",
"normalized",
"array",
"of",
"associations",
"that",
"should",
"be",
"eagerly",
"loaded",
"for",
"a",
"table",
".",
"The",
"normalized",
"array",
"will",
"restructure",
"the",
"original",
"array",
"by",
"sorting",
"all",
"associations",
"under",
"one",
"key",
"and",
"special",
"options",
"under",
"another",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/EagerLoader.php#L361-L382 |
210,750 | cakephp/cakephp | src/ORM/EagerLoader.php | EagerLoader._reformatContain | protected function _reformatContain($associations, $original)
{
$result = $original;
foreach ((array)$associations as $table => $options) {
$pointer =& $result;
if (is_int($table)) {
$table = $options;
$options = [];
}
if ($options instanceof EagerLoadable) {
$options = $options->asContainArray();
$table = key($options);
$options = current($options);
}
if (isset($this->_containOptions[$table])) {
$pointer[$table] = $options;
continue;
}
if (strpos($table, '.')) {
$path = explode('.', $table);
$table = array_pop($path);
foreach ($path as $t) {
$pointer += [$t => []];
$pointer =& $pointer[$t];
}
}
if (is_array($options)) {
$options = isset($options['config']) ?
$options['config'] + $options['associations'] :
$options;
$options = $this->_reformatContain(
$options,
isset($pointer[$table]) ? $pointer[$table] : []
);
}
if ($options instanceof Closure) {
$options = ['queryBuilder' => $options];
}
$pointer += [$table => []];
if (isset($options['queryBuilder'], $pointer[$table]['queryBuilder'])) {
$first = $pointer[$table]['queryBuilder'];
$second = $options['queryBuilder'];
$options['queryBuilder'] = function ($query) use ($first, $second) {
return $second($first($query));
};
}
if (!is_array($options)) {
$options = [$options => []];
}
$pointer[$table] = $options + $pointer[$table];
}
return $result;
} | php | protected function _reformatContain($associations, $original)
{
$result = $original;
foreach ((array)$associations as $table => $options) {
$pointer =& $result;
if (is_int($table)) {
$table = $options;
$options = [];
}
if ($options instanceof EagerLoadable) {
$options = $options->asContainArray();
$table = key($options);
$options = current($options);
}
if (isset($this->_containOptions[$table])) {
$pointer[$table] = $options;
continue;
}
if (strpos($table, '.')) {
$path = explode('.', $table);
$table = array_pop($path);
foreach ($path as $t) {
$pointer += [$t => []];
$pointer =& $pointer[$t];
}
}
if (is_array($options)) {
$options = isset($options['config']) ?
$options['config'] + $options['associations'] :
$options;
$options = $this->_reformatContain(
$options,
isset($pointer[$table]) ? $pointer[$table] : []
);
}
if ($options instanceof Closure) {
$options = ['queryBuilder' => $options];
}
$pointer += [$table => []];
if (isset($options['queryBuilder'], $pointer[$table]['queryBuilder'])) {
$first = $pointer[$table]['queryBuilder'];
$second = $options['queryBuilder'];
$options['queryBuilder'] = function ($query) use ($first, $second) {
return $second($first($query));
};
}
if (!is_array($options)) {
$options = [$options => []];
}
$pointer[$table] = $options + $pointer[$table];
}
return $result;
} | [
"protected",
"function",
"_reformatContain",
"(",
"$",
"associations",
",",
"$",
"original",
")",
"{",
"$",
"result",
"=",
"$",
"original",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"associations",
"as",
"$",
"table",
"=>",
"$",
"options",
")",
"{",
"$",
"pointer",
"=",
"&",
"$",
"result",
";",
"if",
"(",
"is_int",
"(",
"$",
"table",
")",
")",
"{",
"$",
"table",
"=",
"$",
"options",
";",
"$",
"options",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"$",
"options",
"instanceof",
"EagerLoadable",
")",
"{",
"$",
"options",
"=",
"$",
"options",
"->",
"asContainArray",
"(",
")",
";",
"$",
"table",
"=",
"key",
"(",
"$",
"options",
")",
";",
"$",
"options",
"=",
"current",
"(",
"$",
"options",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_containOptions",
"[",
"$",
"table",
"]",
")",
")",
"{",
"$",
"pointer",
"[",
"$",
"table",
"]",
"=",
"$",
"options",
";",
"continue",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"table",
",",
"'.'",
")",
")",
"{",
"$",
"path",
"=",
"explode",
"(",
"'.'",
",",
"$",
"table",
")",
";",
"$",
"table",
"=",
"array_pop",
"(",
"$",
"path",
")",
";",
"foreach",
"(",
"$",
"path",
"as",
"$",
"t",
")",
"{",
"$",
"pointer",
"+=",
"[",
"$",
"t",
"=>",
"[",
"]",
"]",
";",
"$",
"pointer",
"=",
"&",
"$",
"pointer",
"[",
"$",
"t",
"]",
";",
"}",
"}",
"if",
"(",
"is_array",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"=",
"isset",
"(",
"$",
"options",
"[",
"'config'",
"]",
")",
"?",
"$",
"options",
"[",
"'config'",
"]",
"+",
"$",
"options",
"[",
"'associations'",
"]",
":",
"$",
"options",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"_reformatContain",
"(",
"$",
"options",
",",
"isset",
"(",
"$",
"pointer",
"[",
"$",
"table",
"]",
")",
"?",
"$",
"pointer",
"[",
"$",
"table",
"]",
":",
"[",
"]",
")",
";",
"}",
"if",
"(",
"$",
"options",
"instanceof",
"Closure",
")",
"{",
"$",
"options",
"=",
"[",
"'queryBuilder'",
"=>",
"$",
"options",
"]",
";",
"}",
"$",
"pointer",
"+=",
"[",
"$",
"table",
"=>",
"[",
"]",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'queryBuilder'",
"]",
",",
"$",
"pointer",
"[",
"$",
"table",
"]",
"[",
"'queryBuilder'",
"]",
")",
")",
"{",
"$",
"first",
"=",
"$",
"pointer",
"[",
"$",
"table",
"]",
"[",
"'queryBuilder'",
"]",
";",
"$",
"second",
"=",
"$",
"options",
"[",
"'queryBuilder'",
"]",
";",
"$",
"options",
"[",
"'queryBuilder'",
"]",
"=",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"first",
",",
"$",
"second",
")",
"{",
"return",
"$",
"second",
"(",
"$",
"first",
"(",
"$",
"query",
")",
")",
";",
"}",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"=",
"[",
"$",
"options",
"=>",
"[",
"]",
"]",
";",
"}",
"$",
"pointer",
"[",
"$",
"table",
"]",
"=",
"$",
"options",
"+",
"$",
"pointer",
"[",
"$",
"table",
"]",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Formats the containments array so that associations are always set as keys
in the array. This function merges the original associations array with
the new associations provided
@param array $associations user provided containments array
@param array $original The original containments array to merge
with the new one
@return array | [
"Formats",
"the",
"containments",
"array",
"so",
"that",
"associations",
"are",
"always",
"set",
"as",
"keys",
"in",
"the",
"array",
".",
"This",
"function",
"merges",
"the",
"original",
"associations",
"array",
"with",
"the",
"new",
"associations",
"provided"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/EagerLoader.php#L394-L457 |
210,751 | cakephp/cakephp | src/ORM/EagerLoader.php | EagerLoader.attachAssociations | public function attachAssociations(Query $query, Table $repository, $includeFields)
{
if (empty($this->_containments) && $this->_matching === null) {
return;
}
$attachable = $this->attachableAssociations($repository);
$processed = [];
do {
foreach ($attachable as $alias => $loadable) {
$config = $loadable->getConfig() + [
'aliasPath' => $loadable->aliasPath(),
'propertyPath' => $loadable->propertyPath(),
'includeFields' => $includeFields,
];
$loadable->instance()->attachTo($query, $config);
$processed[$alias] = true;
}
$newAttachable = $this->attachableAssociations($repository);
$attachable = array_diff_key($newAttachable, $processed);
} while (!empty($attachable));
} | php | public function attachAssociations(Query $query, Table $repository, $includeFields)
{
if (empty($this->_containments) && $this->_matching === null) {
return;
}
$attachable = $this->attachableAssociations($repository);
$processed = [];
do {
foreach ($attachable as $alias => $loadable) {
$config = $loadable->getConfig() + [
'aliasPath' => $loadable->aliasPath(),
'propertyPath' => $loadable->propertyPath(),
'includeFields' => $includeFields,
];
$loadable->instance()->attachTo($query, $config);
$processed[$alias] = true;
}
$newAttachable = $this->attachableAssociations($repository);
$attachable = array_diff_key($newAttachable, $processed);
} while (!empty($attachable));
} | [
"public",
"function",
"attachAssociations",
"(",
"Query",
"$",
"query",
",",
"Table",
"$",
"repository",
",",
"$",
"includeFields",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_containments",
")",
"&&",
"$",
"this",
"->",
"_matching",
"===",
"null",
")",
"{",
"return",
";",
"}",
"$",
"attachable",
"=",
"$",
"this",
"->",
"attachableAssociations",
"(",
"$",
"repository",
")",
";",
"$",
"processed",
"=",
"[",
"]",
";",
"do",
"{",
"foreach",
"(",
"$",
"attachable",
"as",
"$",
"alias",
"=>",
"$",
"loadable",
")",
"{",
"$",
"config",
"=",
"$",
"loadable",
"->",
"getConfig",
"(",
")",
"+",
"[",
"'aliasPath'",
"=>",
"$",
"loadable",
"->",
"aliasPath",
"(",
")",
",",
"'propertyPath'",
"=>",
"$",
"loadable",
"->",
"propertyPath",
"(",
")",
",",
"'includeFields'",
"=>",
"$",
"includeFields",
",",
"]",
";",
"$",
"loadable",
"->",
"instance",
"(",
")",
"->",
"attachTo",
"(",
"$",
"query",
",",
"$",
"config",
")",
";",
"$",
"processed",
"[",
"$",
"alias",
"]",
"=",
"true",
";",
"}",
"$",
"newAttachable",
"=",
"$",
"this",
"->",
"attachableAssociations",
"(",
"$",
"repository",
")",
";",
"$",
"attachable",
"=",
"array_diff_key",
"(",
"$",
"newAttachable",
",",
"$",
"processed",
")",
";",
"}",
"while",
"(",
"!",
"empty",
"(",
"$",
"attachable",
")",
")",
";",
"}"
] | Modifies the passed query to apply joins or any other transformation required
in order to eager load the associations described in the `contain` array.
This method will not modify the query for loading external associations, i.e.
those that cannot be loaded without executing a separate query.
@param \Cake\ORM\Query $query The query to be modified
@param \Cake\ORM\Table $repository The repository containing the associations
@param bool $includeFields whether to append all fields from the associations
to the passed query. This can be overridden according to the settings defined
per association in the containments array
@return void | [
"Modifies",
"the",
"passed",
"query",
"to",
"apply",
"joins",
"or",
"any",
"other",
"transformation",
"required",
"in",
"order",
"to",
"eager",
"load",
"the",
"associations",
"described",
"in",
"the",
"contain",
"array",
".",
"This",
"method",
"will",
"not",
"modify",
"the",
"query",
"for",
"loading",
"external",
"associations",
"i",
".",
"e",
".",
"those",
"that",
"cannot",
"be",
"loaded",
"without",
"executing",
"a",
"separate",
"query",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/EagerLoader.php#L472-L494 |
210,752 | cakephp/cakephp | src/ORM/EagerLoader.php | EagerLoader.attachableAssociations | public function attachableAssociations(Table $repository)
{
$contain = $this->normalized($repository);
$matching = $this->_matching ? $this->_matching->normalized($repository) : [];
$this->_fixStrategies();
$this->_loadExternal = [];
return $this->_resolveJoins($contain, $matching);
} | php | public function attachableAssociations(Table $repository)
{
$contain = $this->normalized($repository);
$matching = $this->_matching ? $this->_matching->normalized($repository) : [];
$this->_fixStrategies();
$this->_loadExternal = [];
return $this->_resolveJoins($contain, $matching);
} | [
"public",
"function",
"attachableAssociations",
"(",
"Table",
"$",
"repository",
")",
"{",
"$",
"contain",
"=",
"$",
"this",
"->",
"normalized",
"(",
"$",
"repository",
")",
";",
"$",
"matching",
"=",
"$",
"this",
"->",
"_matching",
"?",
"$",
"this",
"->",
"_matching",
"->",
"normalized",
"(",
"$",
"repository",
")",
":",
"[",
"]",
";",
"$",
"this",
"->",
"_fixStrategies",
"(",
")",
";",
"$",
"this",
"->",
"_loadExternal",
"=",
"[",
"]",
";",
"return",
"$",
"this",
"->",
"_resolveJoins",
"(",
"$",
"contain",
",",
"$",
"matching",
")",
";",
"}"
] | Returns an array with the associations that can be fetched using a single query,
the array keys are the association aliases and the values will contain an array
with Cake\ORM\EagerLoadable objects.
@param \Cake\ORM\Table $repository The table containing the associations to be
attached
@return array | [
"Returns",
"an",
"array",
"with",
"the",
"associations",
"that",
"can",
"be",
"fetched",
"using",
"a",
"single",
"query",
"the",
"array",
"keys",
"are",
"the",
"association",
"aliases",
"and",
"the",
"values",
"will",
"contain",
"an",
"array",
"with",
"Cake",
"\\",
"ORM",
"\\",
"EagerLoadable",
"objects",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/EagerLoader.php#L505-L513 |
210,753 | cakephp/cakephp | src/ORM/EagerLoader.php | EagerLoader.externalAssociations | public function externalAssociations(Table $repository)
{
if ($this->_loadExternal) {
return $this->_loadExternal;
}
$this->attachableAssociations($repository);
return $this->_loadExternal;
} | php | public function externalAssociations(Table $repository)
{
if ($this->_loadExternal) {
return $this->_loadExternal;
}
$this->attachableAssociations($repository);
return $this->_loadExternal;
} | [
"public",
"function",
"externalAssociations",
"(",
"Table",
"$",
"repository",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_loadExternal",
")",
"{",
"return",
"$",
"this",
"->",
"_loadExternal",
";",
"}",
"$",
"this",
"->",
"attachableAssociations",
"(",
"$",
"repository",
")",
";",
"return",
"$",
"this",
"->",
"_loadExternal",
";",
"}"
] | Returns an array with the associations that need to be fetched using a
separate query, each array value will contain a Cake\ORM\EagerLoadable object.
@param \Cake\ORM\Table $repository The table containing the associations
to be loaded
@return \Cake\ORM\EagerLoadable[] | [
"Returns",
"an",
"array",
"with",
"the",
"associations",
"that",
"need",
"to",
"be",
"fetched",
"using",
"a",
"separate",
"query",
"each",
"array",
"value",
"will",
"contain",
"a",
"Cake",
"\\",
"ORM",
"\\",
"EagerLoadable",
"object",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/EagerLoader.php#L523-L532 |
210,754 | cakephp/cakephp | src/ORM/EagerLoader.php | EagerLoader._fixStrategies | protected function _fixStrategies()
{
foreach ($this->_aliasList as $aliases) {
foreach ($aliases as $configs) {
if (count($configs) < 2) {
continue;
}
/* @var \Cake\ORM\EagerLoadable $loadable */
foreach ($configs as $loadable) {
if (strpos($loadable->aliasPath(), '.')) {
$this->_correctStrategy($loadable);
}
}
}
}
} | php | protected function _fixStrategies()
{
foreach ($this->_aliasList as $aliases) {
foreach ($aliases as $configs) {
if (count($configs) < 2) {
continue;
}
/* @var \Cake\ORM\EagerLoadable $loadable */
foreach ($configs as $loadable) {
if (strpos($loadable->aliasPath(), '.')) {
$this->_correctStrategy($loadable);
}
}
}
}
} | [
"protected",
"function",
"_fixStrategies",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_aliasList",
"as",
"$",
"aliases",
")",
"{",
"foreach",
"(",
"$",
"aliases",
"as",
"$",
"configs",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"configs",
")",
"<",
"2",
")",
"{",
"continue",
";",
"}",
"/* @var \\Cake\\ORM\\EagerLoadable $loadable */",
"foreach",
"(",
"$",
"configs",
"as",
"$",
"loadable",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"loadable",
"->",
"aliasPath",
"(",
")",
",",
"'.'",
")",
")",
"{",
"$",
"this",
"->",
"_correctStrategy",
"(",
"$",
"loadable",
")",
";",
"}",
"}",
"}",
"}",
"}"
] | Iterates over the joinable aliases list and corrects the fetching strategies
in order to avoid aliases collision in the generated queries.
This function operates on the array references that were generated by the
_normalizeContain() function.
@return void | [
"Iterates",
"over",
"the",
"joinable",
"aliases",
"list",
"and",
"corrects",
"the",
"fetching",
"strategies",
"in",
"order",
"to",
"avoid",
"aliases",
"collision",
"in",
"the",
"generated",
"queries",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/EagerLoader.php#L601-L616 |
210,755 | cakephp/cakephp | src/ORM/EagerLoader.php | EagerLoader._correctStrategy | protected function _correctStrategy($loadable)
{
$config = $loadable->getConfig();
$currentStrategy = isset($config['strategy']) ?
$config['strategy'] :
'join';
if (!$loadable->canBeJoined() || $currentStrategy !== 'join') {
return;
}
$config['strategy'] = Association::STRATEGY_SELECT;
$loadable->setConfig($config);
$loadable->setCanBeJoined(false);
} | php | protected function _correctStrategy($loadable)
{
$config = $loadable->getConfig();
$currentStrategy = isset($config['strategy']) ?
$config['strategy'] :
'join';
if (!$loadable->canBeJoined() || $currentStrategy !== 'join') {
return;
}
$config['strategy'] = Association::STRATEGY_SELECT;
$loadable->setConfig($config);
$loadable->setCanBeJoined(false);
} | [
"protected",
"function",
"_correctStrategy",
"(",
"$",
"loadable",
")",
"{",
"$",
"config",
"=",
"$",
"loadable",
"->",
"getConfig",
"(",
")",
";",
"$",
"currentStrategy",
"=",
"isset",
"(",
"$",
"config",
"[",
"'strategy'",
"]",
")",
"?",
"$",
"config",
"[",
"'strategy'",
"]",
":",
"'join'",
";",
"if",
"(",
"!",
"$",
"loadable",
"->",
"canBeJoined",
"(",
")",
"||",
"$",
"currentStrategy",
"!==",
"'join'",
")",
"{",
"return",
";",
"}",
"$",
"config",
"[",
"'strategy'",
"]",
"=",
"Association",
"::",
"STRATEGY_SELECT",
";",
"$",
"loadable",
"->",
"setConfig",
"(",
"$",
"config",
")",
";",
"$",
"loadable",
"->",
"setCanBeJoined",
"(",
"false",
")",
";",
"}"
] | Changes the association fetching strategy if required because of duplicate
under the same direct associations chain
@param \Cake\ORM\EagerLoadable $loadable The association config
@return void | [
"Changes",
"the",
"association",
"fetching",
"strategy",
"if",
"required",
"because",
"of",
"duplicate",
"under",
"the",
"same",
"direct",
"associations",
"chain"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/EagerLoader.php#L625-L639 |
210,756 | cakephp/cakephp | src/ORM/EagerLoader.php | EagerLoader._resolveJoins | protected function _resolveJoins($associations, $matching = [])
{
$result = [];
foreach ($matching as $table => $loadable) {
$result[$table] = $loadable;
$result += $this->_resolveJoins($loadable->associations(), []);
}
foreach ($associations as $table => $loadable) {
$inMatching = isset($matching[$table]);
if (!$inMatching && $loadable->canBeJoined()) {
$result[$table] = $loadable;
$result += $this->_resolveJoins($loadable->associations(), []);
continue;
}
if ($inMatching) {
$this->_correctStrategy($loadable);
}
$loadable->setCanBeJoined(false);
$this->_loadExternal[] = $loadable;
}
return $result;
} | php | protected function _resolveJoins($associations, $matching = [])
{
$result = [];
foreach ($matching as $table => $loadable) {
$result[$table] = $loadable;
$result += $this->_resolveJoins($loadable->associations(), []);
}
foreach ($associations as $table => $loadable) {
$inMatching = isset($matching[$table]);
if (!$inMatching && $loadable->canBeJoined()) {
$result[$table] = $loadable;
$result += $this->_resolveJoins($loadable->associations(), []);
continue;
}
if ($inMatching) {
$this->_correctStrategy($loadable);
}
$loadable->setCanBeJoined(false);
$this->_loadExternal[] = $loadable;
}
return $result;
} | [
"protected",
"function",
"_resolveJoins",
"(",
"$",
"associations",
",",
"$",
"matching",
"=",
"[",
"]",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"matching",
"as",
"$",
"table",
"=>",
"$",
"loadable",
")",
"{",
"$",
"result",
"[",
"$",
"table",
"]",
"=",
"$",
"loadable",
";",
"$",
"result",
"+=",
"$",
"this",
"->",
"_resolveJoins",
"(",
"$",
"loadable",
"->",
"associations",
"(",
")",
",",
"[",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"associations",
"as",
"$",
"table",
"=>",
"$",
"loadable",
")",
"{",
"$",
"inMatching",
"=",
"isset",
"(",
"$",
"matching",
"[",
"$",
"table",
"]",
")",
";",
"if",
"(",
"!",
"$",
"inMatching",
"&&",
"$",
"loadable",
"->",
"canBeJoined",
"(",
")",
")",
"{",
"$",
"result",
"[",
"$",
"table",
"]",
"=",
"$",
"loadable",
";",
"$",
"result",
"+=",
"$",
"this",
"->",
"_resolveJoins",
"(",
"$",
"loadable",
"->",
"associations",
"(",
")",
",",
"[",
"]",
")",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"inMatching",
")",
"{",
"$",
"this",
"->",
"_correctStrategy",
"(",
"$",
"loadable",
")",
";",
"}",
"$",
"loadable",
"->",
"setCanBeJoined",
"(",
"false",
")",
";",
"$",
"this",
"->",
"_loadExternal",
"[",
"]",
"=",
"$",
"loadable",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Helper function used to compile a list of all associations that can be
joined in the query.
@param array $associations list of associations from which to obtain joins.
@param array $matching list of associations that should be forcibly joined.
@return array | [
"Helper",
"function",
"used",
"to",
"compile",
"a",
"list",
"of",
"all",
"associations",
"that",
"can",
"be",
"joined",
"in",
"the",
"query",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/EagerLoader.php#L649-L673 |
210,757 | cakephp/cakephp | src/ORM/EagerLoader.php | EagerLoader.loadExternal | public function loadExternal($query, $statement)
{
$external = $this->externalAssociations($query->getRepository());
if (empty($external)) {
return $statement;
}
$driver = $query->getConnection()->getDriver();
list($collected, $statement) = $this->_collectKeys($external, $query, $statement);
foreach ($external as $meta) {
$contain = $meta->associations();
$instance = $meta->instance();
$config = $meta->getConfig();
$alias = $instance->getSource()->getAlias();
$path = $meta->aliasPath();
$requiresKeys = $instance->requiresKeys($config);
if ($requiresKeys && empty($collected[$path][$alias])) {
continue;
}
$keys = isset($collected[$path][$alias]) ? $collected[$path][$alias] : null;
$f = $instance->eagerLoader(
$config + [
'query' => $query,
'contain' => $contain,
'keys' => $keys,
'nestKey' => $meta->aliasPath()
]
);
$statement = new CallbackStatement($statement, $driver, $f);
}
return $statement;
} | php | public function loadExternal($query, $statement)
{
$external = $this->externalAssociations($query->getRepository());
if (empty($external)) {
return $statement;
}
$driver = $query->getConnection()->getDriver();
list($collected, $statement) = $this->_collectKeys($external, $query, $statement);
foreach ($external as $meta) {
$contain = $meta->associations();
$instance = $meta->instance();
$config = $meta->getConfig();
$alias = $instance->getSource()->getAlias();
$path = $meta->aliasPath();
$requiresKeys = $instance->requiresKeys($config);
if ($requiresKeys && empty($collected[$path][$alias])) {
continue;
}
$keys = isset($collected[$path][$alias]) ? $collected[$path][$alias] : null;
$f = $instance->eagerLoader(
$config + [
'query' => $query,
'contain' => $contain,
'keys' => $keys,
'nestKey' => $meta->aliasPath()
]
);
$statement = new CallbackStatement($statement, $driver, $f);
}
return $statement;
} | [
"public",
"function",
"loadExternal",
"(",
"$",
"query",
",",
"$",
"statement",
")",
"{",
"$",
"external",
"=",
"$",
"this",
"->",
"externalAssociations",
"(",
"$",
"query",
"->",
"getRepository",
"(",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"external",
")",
")",
"{",
"return",
"$",
"statement",
";",
"}",
"$",
"driver",
"=",
"$",
"query",
"->",
"getConnection",
"(",
")",
"->",
"getDriver",
"(",
")",
";",
"list",
"(",
"$",
"collected",
",",
"$",
"statement",
")",
"=",
"$",
"this",
"->",
"_collectKeys",
"(",
"$",
"external",
",",
"$",
"query",
",",
"$",
"statement",
")",
";",
"foreach",
"(",
"$",
"external",
"as",
"$",
"meta",
")",
"{",
"$",
"contain",
"=",
"$",
"meta",
"->",
"associations",
"(",
")",
";",
"$",
"instance",
"=",
"$",
"meta",
"->",
"instance",
"(",
")",
";",
"$",
"config",
"=",
"$",
"meta",
"->",
"getConfig",
"(",
")",
";",
"$",
"alias",
"=",
"$",
"instance",
"->",
"getSource",
"(",
")",
"->",
"getAlias",
"(",
")",
";",
"$",
"path",
"=",
"$",
"meta",
"->",
"aliasPath",
"(",
")",
";",
"$",
"requiresKeys",
"=",
"$",
"instance",
"->",
"requiresKeys",
"(",
"$",
"config",
")",
";",
"if",
"(",
"$",
"requiresKeys",
"&&",
"empty",
"(",
"$",
"collected",
"[",
"$",
"path",
"]",
"[",
"$",
"alias",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"keys",
"=",
"isset",
"(",
"$",
"collected",
"[",
"$",
"path",
"]",
"[",
"$",
"alias",
"]",
")",
"?",
"$",
"collected",
"[",
"$",
"path",
"]",
"[",
"$",
"alias",
"]",
":",
"null",
";",
"$",
"f",
"=",
"$",
"instance",
"->",
"eagerLoader",
"(",
"$",
"config",
"+",
"[",
"'query'",
"=>",
"$",
"query",
",",
"'contain'",
"=>",
"$",
"contain",
",",
"'keys'",
"=>",
"$",
"keys",
",",
"'nestKey'",
"=>",
"$",
"meta",
"->",
"aliasPath",
"(",
")",
"]",
")",
";",
"$",
"statement",
"=",
"new",
"CallbackStatement",
"(",
"$",
"statement",
",",
"$",
"driver",
",",
"$",
"f",
")",
";",
"}",
"return",
"$",
"statement",
";",
"}"
] | Decorates the passed statement object in order to inject data from associations
that cannot be joined directly.
@param \Cake\ORM\Query $query The query for which to eager load external
associations
@param \Cake\Database\StatementInterface $statement The statement created after executing the $query
@return \Cake\Database\StatementInterface statement modified statement with extra loaders | [
"Decorates",
"the",
"passed",
"statement",
"object",
"in",
"order",
"to",
"inject",
"data",
"from",
"associations",
"that",
"cannot",
"be",
"joined",
"directly",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/EagerLoader.php#L684-L719 |
210,758 | cakephp/cakephp | src/ORM/EagerLoader.php | EagerLoader.associationsMap | public function associationsMap($table)
{
$map = [];
if (!$this->getMatching() && !$this->getContain() && empty($this->_joinsMap)) {
return $map;
}
$map = $this->_buildAssociationsMap($map, $this->_matching->normalized($table), true);
$map = $this->_buildAssociationsMap($map, $this->normalized($table));
$map = $this->_buildAssociationsMap($map, $this->_joinsMap);
return $map;
} | php | public function associationsMap($table)
{
$map = [];
if (!$this->getMatching() && !$this->getContain() && empty($this->_joinsMap)) {
return $map;
}
$map = $this->_buildAssociationsMap($map, $this->_matching->normalized($table), true);
$map = $this->_buildAssociationsMap($map, $this->normalized($table));
$map = $this->_buildAssociationsMap($map, $this->_joinsMap);
return $map;
} | [
"public",
"function",
"associationsMap",
"(",
"$",
"table",
")",
"{",
"$",
"map",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"getMatching",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"getContain",
"(",
")",
"&&",
"empty",
"(",
"$",
"this",
"->",
"_joinsMap",
")",
")",
"{",
"return",
"$",
"map",
";",
"}",
"$",
"map",
"=",
"$",
"this",
"->",
"_buildAssociationsMap",
"(",
"$",
"map",
",",
"$",
"this",
"->",
"_matching",
"->",
"normalized",
"(",
"$",
"table",
")",
",",
"true",
")",
";",
"$",
"map",
"=",
"$",
"this",
"->",
"_buildAssociationsMap",
"(",
"$",
"map",
",",
"$",
"this",
"->",
"normalized",
"(",
"$",
"table",
")",
")",
";",
"$",
"map",
"=",
"$",
"this",
"->",
"_buildAssociationsMap",
"(",
"$",
"map",
",",
"$",
"this",
"->",
"_joinsMap",
")",
";",
"return",
"$",
"map",
";",
"}"
] | Returns an array having as keys a dotted path of associations that participate
in this eager loader. The values of the array will contain the following keys
- alias: The association alias
- instance: The association instance
- canBeJoined: Whether or not the association will be loaded using a JOIN
- entityClass: The entity that should be used for hydrating the results
- nestKey: A dotted path that can be used to correctly insert the data into the results.
- matching: Whether or not it is an association loaded through `matching()`.
@param \Cake\ORM\Table $table The table containing the association that
will be normalized
@return array | [
"Returns",
"an",
"array",
"having",
"as",
"keys",
"a",
"dotted",
"path",
"of",
"associations",
"that",
"participate",
"in",
"this",
"eager",
"loader",
".",
"The",
"values",
"of",
"the",
"array",
"will",
"contain",
"the",
"following",
"keys"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/EagerLoader.php#L736-L749 |
210,759 | cakephp/cakephp | src/ORM/EagerLoader.php | EagerLoader.addToJoinsMap | public function addToJoinsMap($alias, Association $assoc, $asMatching = false, $targetProperty = null)
{
$this->_joinsMap[$alias] = new EagerLoadable($alias, [
'aliasPath' => $alias,
'instance' => $assoc,
'canBeJoined' => true,
'forMatching' => $asMatching,
'targetProperty' => $targetProperty ?: $assoc->getProperty()
]);
} | php | public function addToJoinsMap($alias, Association $assoc, $asMatching = false, $targetProperty = null)
{
$this->_joinsMap[$alias] = new EagerLoadable($alias, [
'aliasPath' => $alias,
'instance' => $assoc,
'canBeJoined' => true,
'forMatching' => $asMatching,
'targetProperty' => $targetProperty ?: $assoc->getProperty()
]);
} | [
"public",
"function",
"addToJoinsMap",
"(",
"$",
"alias",
",",
"Association",
"$",
"assoc",
",",
"$",
"asMatching",
"=",
"false",
",",
"$",
"targetProperty",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"_joinsMap",
"[",
"$",
"alias",
"]",
"=",
"new",
"EagerLoadable",
"(",
"$",
"alias",
",",
"[",
"'aliasPath'",
"=>",
"$",
"alias",
",",
"'instance'",
"=>",
"$",
"assoc",
",",
"'canBeJoined'",
"=>",
"true",
",",
"'forMatching'",
"=>",
"$",
"asMatching",
",",
"'targetProperty'",
"=>",
"$",
"targetProperty",
"?",
":",
"$",
"assoc",
"->",
"getProperty",
"(",
")",
"]",
")",
";",
"}"
] | Registers a table alias, typically loaded as a join in a query, as belonging to
an association. This helps hydrators know what to do with the columns coming
from such joined table.
@param string $alias The table alias as it appears in the query.
@param \Cake\ORM\Association $assoc The association object the alias represents;
will be normalized
@param bool $asMatching Whether or not this join results should be treated as a
'matching' association.
@param string $targetProperty The property name where the results of the join should be nested at.
If not passed, the default property for the association will be used.
@return void | [
"Registers",
"a",
"table",
"alias",
"typically",
"loaded",
"as",
"a",
"join",
"in",
"a",
"query",
"as",
"belonging",
"to",
"an",
"association",
".",
"This",
"helps",
"hydrators",
"know",
"what",
"to",
"do",
"with",
"the",
"columns",
"coming",
"from",
"such",
"joined",
"table",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/EagerLoader.php#L799-L808 |
210,760 | cakephp/cakephp | src/ORM/EagerLoader.php | EagerLoader._collectKeys | protected function _collectKeys($external, $query, $statement)
{
$collectKeys = [];
/* @var \Cake\ORM\EagerLoadable $meta */
foreach ($external as $meta) {
$instance = $meta->instance();
if (!$instance->requiresKeys($meta->getConfig())) {
continue;
}
$source = $instance->getSource();
$keys = $instance->type() === Association::MANY_TO_ONE ?
(array)$instance->getForeignKey() :
(array)$instance->getBindingKey();
$alias = $source->getAlias();
$pkFields = [];
foreach ($keys as $key) {
$pkFields[] = key($query->aliasField($key, $alias));
}
$collectKeys[$meta->aliasPath()] = [$alias, $pkFields, count($pkFields) === 1];
}
if (empty($collectKeys)) {
return [[], $statement];
}
if (!($statement instanceof BufferedStatement)) {
$statement = new BufferedStatement($statement, $query->getConnection()->getDriver());
}
return [$this->_groupKeys($statement, $collectKeys), $statement];
} | php | protected function _collectKeys($external, $query, $statement)
{
$collectKeys = [];
/* @var \Cake\ORM\EagerLoadable $meta */
foreach ($external as $meta) {
$instance = $meta->instance();
if (!$instance->requiresKeys($meta->getConfig())) {
continue;
}
$source = $instance->getSource();
$keys = $instance->type() === Association::MANY_TO_ONE ?
(array)$instance->getForeignKey() :
(array)$instance->getBindingKey();
$alias = $source->getAlias();
$pkFields = [];
foreach ($keys as $key) {
$pkFields[] = key($query->aliasField($key, $alias));
}
$collectKeys[$meta->aliasPath()] = [$alias, $pkFields, count($pkFields) === 1];
}
if (empty($collectKeys)) {
return [[], $statement];
}
if (!($statement instanceof BufferedStatement)) {
$statement = new BufferedStatement($statement, $query->getConnection()->getDriver());
}
return [$this->_groupKeys($statement, $collectKeys), $statement];
} | [
"protected",
"function",
"_collectKeys",
"(",
"$",
"external",
",",
"$",
"query",
",",
"$",
"statement",
")",
"{",
"$",
"collectKeys",
"=",
"[",
"]",
";",
"/* @var \\Cake\\ORM\\EagerLoadable $meta */",
"foreach",
"(",
"$",
"external",
"as",
"$",
"meta",
")",
"{",
"$",
"instance",
"=",
"$",
"meta",
"->",
"instance",
"(",
")",
";",
"if",
"(",
"!",
"$",
"instance",
"->",
"requiresKeys",
"(",
"$",
"meta",
"->",
"getConfig",
"(",
")",
")",
")",
"{",
"continue",
";",
"}",
"$",
"source",
"=",
"$",
"instance",
"->",
"getSource",
"(",
")",
";",
"$",
"keys",
"=",
"$",
"instance",
"->",
"type",
"(",
")",
"===",
"Association",
"::",
"MANY_TO_ONE",
"?",
"(",
"array",
")",
"$",
"instance",
"->",
"getForeignKey",
"(",
")",
":",
"(",
"array",
")",
"$",
"instance",
"->",
"getBindingKey",
"(",
")",
";",
"$",
"alias",
"=",
"$",
"source",
"->",
"getAlias",
"(",
")",
";",
"$",
"pkFields",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"pkFields",
"[",
"]",
"=",
"key",
"(",
"$",
"query",
"->",
"aliasField",
"(",
"$",
"key",
",",
"$",
"alias",
")",
")",
";",
"}",
"$",
"collectKeys",
"[",
"$",
"meta",
"->",
"aliasPath",
"(",
")",
"]",
"=",
"[",
"$",
"alias",
",",
"$",
"pkFields",
",",
"count",
"(",
"$",
"pkFields",
")",
"===",
"1",
"]",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"collectKeys",
")",
")",
"{",
"return",
"[",
"[",
"]",
",",
"$",
"statement",
"]",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"statement",
"instanceof",
"BufferedStatement",
")",
")",
"{",
"$",
"statement",
"=",
"new",
"BufferedStatement",
"(",
"$",
"statement",
",",
"$",
"query",
"->",
"getConnection",
"(",
")",
"->",
"getDriver",
"(",
")",
")",
";",
"}",
"return",
"[",
"$",
"this",
"->",
"_groupKeys",
"(",
"$",
"statement",
",",
"$",
"collectKeys",
")",
",",
"$",
"statement",
"]",
";",
"}"
] | Helper function used to return the keys from the query records that will be used
to eagerly load associations.
@param array $external the list of external associations to be loaded
@param \Cake\ORM\Query $query The query from which the results where generated
@param \Cake\Database\Statement\BufferedStatement $statement The statement to work on
@return array | [
"Helper",
"function",
"used",
"to",
"return",
"the",
"keys",
"from",
"the",
"query",
"records",
"that",
"will",
"be",
"used",
"to",
"eagerly",
"load",
"associations",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/EagerLoader.php#L819-L851 |
210,761 | cakephp/cakephp | src/Datasource/QueryTrait.php | QueryTrait.repository | public function repository(RepositoryInterface $table = null)
{
if ($table === null) {
deprecationWarning(
'Using Query::repository() as getter is deprecated. ' .
'Use getRepository() instead.'
);
return $this->getRepository();
}
$this->_repository = $table;
return $this;
} | php | public function repository(RepositoryInterface $table = null)
{
if ($table === null) {
deprecationWarning(
'Using Query::repository() as getter is deprecated. ' .
'Use getRepository() instead.'
);
return $this->getRepository();
}
$this->_repository = $table;
return $this;
} | [
"public",
"function",
"repository",
"(",
"RepositoryInterface",
"$",
"table",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"table",
"===",
"null",
")",
"{",
"deprecationWarning",
"(",
"'Using Query::repository() as getter is deprecated. '",
".",
"'Use getRepository() instead.'",
")",
";",
"return",
"$",
"this",
"->",
"getRepository",
"(",
")",
";",
"}",
"$",
"this",
"->",
"_repository",
"=",
"$",
"table",
";",
"return",
"$",
"this",
";",
"}"
] | Returns the default table object that will be used by this query,
that is, the table that will appear in the from clause.
When called with a Table argument, the default table object will be set
and this query object will be returned for chaining.
@param \Cake\Datasource\RepositoryInterface|null $table The default table object to use
@return \Cake\Datasource\RepositoryInterface|$this | [
"Returns",
"the",
"default",
"table",
"object",
"that",
"will",
"be",
"used",
"by",
"this",
"query",
"that",
"is",
"the",
"table",
"that",
"will",
"appear",
"in",
"the",
"from",
"clause",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/QueryTrait.php#L93-L107 |
210,762 | cakephp/cakephp | src/Datasource/QueryTrait.php | QueryTrait.cache | public function cache($key, $config = 'default')
{
if ($key === false) {
$this->_cache = null;
return $this;
}
$this->_cache = new QueryCacher($key, $config);
return $this;
} | php | public function cache($key, $config = 'default')
{
if ($key === false) {
$this->_cache = null;
return $this;
}
$this->_cache = new QueryCacher($key, $config);
return $this;
} | [
"public",
"function",
"cache",
"(",
"$",
"key",
",",
"$",
"config",
"=",
"'default'",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"_cache",
"=",
"null",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"_cache",
"=",
"new",
"QueryCacher",
"(",
"$",
"key",
",",
"$",
"config",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Enable result caching for this query.
If a query has caching enabled, it will do the following when executed:
- Check the cache for $key. If there are results no SQL will be executed.
Instead the cached results will be returned.
- When the cached data is stale/missing the result set will be cached as the query
is executed.
### Usage
```
// Simple string key + config
$query->cache('my_key', 'db_results');
// Function to generate key.
$query->cache(function ($q) {
$key = serialize($q->clause('select'));
$key .= serialize($q->clause('where'));
return md5($key);
});
// Using a pre-built cache engine.
$query->cache('my_key', $engine);
// Disable caching
$query->cache(false);
```
@param false|string|\Closure $key Either the cache key or a function to generate the cache key.
When using a function, this query instance will be supplied as an argument.
@param string|\Cake\Cache\CacheEngine $config Either the name of the cache config to use, or
a cache config instance.
@return $this | [
"Enable",
"result",
"caching",
"for",
"this",
"query",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/QueryTrait.php#L188-L198 |
210,763 | cakephp/cakephp | src/Datasource/QueryTrait.php | QueryTrait.eagerLoaded | public function eagerLoaded($value = null)
{
if ($value === null) {
deprecationWarning(
'Using ' . get_called_class() . '::eagerLoaded() as a getter is deprecated. ' .
'Use isEagerLoaded() instead.'
);
return $this->_eagerLoaded;
}
$this->_eagerLoaded = $value;
return $this;
} | php | public function eagerLoaded($value = null)
{
if ($value === null) {
deprecationWarning(
'Using ' . get_called_class() . '::eagerLoaded() as a getter is deprecated. ' .
'Use isEagerLoaded() instead.'
);
return $this->_eagerLoaded;
}
$this->_eagerLoaded = $value;
return $this;
} | [
"public",
"function",
"eagerLoaded",
"(",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"deprecationWarning",
"(",
"'Using '",
".",
"get_called_class",
"(",
")",
".",
"'::eagerLoaded() as a getter is deprecated. '",
".",
"'Use isEagerLoaded() instead.'",
")",
";",
"return",
"$",
"this",
"->",
"_eagerLoaded",
";",
"}",
"$",
"this",
"->",
"_eagerLoaded",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the query instance to be an eager loaded query. If no argument is
passed, the current configured query `_eagerLoaded` value is returned.
@deprecated 3.5.0 Use isEagerLoaded() for the getter part instead.
@param bool|null $value Whether or not to eager load.
@return $this|bool | [
"Sets",
"the",
"query",
"instance",
"to",
"be",
"an",
"eager",
"loaded",
"query",
".",
"If",
"no",
"argument",
"is",
"passed",
"the",
"current",
"configured",
"query",
"_eagerLoaded",
"value",
"is",
"returned",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/QueryTrait.php#L218-L231 |
210,764 | cakephp/cakephp | src/Datasource/QueryTrait.php | QueryTrait.all | public function all()
{
if ($this->_results !== null) {
return $this->_results;
}
if ($this->_cache) {
$results = $this->_cache->fetch($this);
}
if (!isset($results)) {
$results = $this->_decorateResults($this->_execute());
if ($this->_cache) {
$this->_cache->store($this, $results);
}
}
$this->_results = $results;
return $this->_results;
} | php | public function all()
{
if ($this->_results !== null) {
return $this->_results;
}
if ($this->_cache) {
$results = $this->_cache->fetch($this);
}
if (!isset($results)) {
$results = $this->_decorateResults($this->_execute());
if ($this->_cache) {
$this->_cache->store($this, $results);
}
}
$this->_results = $results;
return $this->_results;
} | [
"public",
"function",
"all",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_results",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_results",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_cache",
")",
"{",
"$",
"results",
"=",
"$",
"this",
"->",
"_cache",
"->",
"fetch",
"(",
"$",
"this",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"results",
")",
")",
"{",
"$",
"results",
"=",
"$",
"this",
"->",
"_decorateResults",
"(",
"$",
"this",
"->",
"_execute",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_cache",
")",
"{",
"$",
"this",
"->",
"_cache",
"->",
"store",
"(",
"$",
"this",
",",
"$",
"results",
")",
";",
"}",
"}",
"$",
"this",
"->",
"_results",
"=",
"$",
"results",
";",
"return",
"$",
"this",
"->",
"_results",
";",
"}"
] | Fetch the results for this query.
Will return either the results set through setResult(), or execute this query
and return the ResultSetDecorator object ready for streaming of results.
ResultSetDecorator is a traversable object that implements the methods found
on Cake\Collection\Collection.
@return \Cake\Datasource\ResultSetInterface | [
"Fetch",
"the",
"results",
"for",
"this",
"query",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/QueryTrait.php#L299-L317 |
210,765 | cakephp/cakephp | src/Datasource/QueryTrait.php | QueryTrait.mapReduce | public function mapReduce(callable $mapper = null, callable $reducer = null, $overwrite = false)
{
if ($overwrite) {
$this->_mapReduce = [];
}
if ($mapper === null) {
if (!$overwrite) {
deprecationWarning(
'Using QueryTrait::mapReduce() as a getter is deprecated. ' .
'Use getMapReducers() instead.'
);
}
return $this->_mapReduce;
}
$this->_mapReduce[] = compact('mapper', 'reducer');
return $this;
} | php | public function mapReduce(callable $mapper = null, callable $reducer = null, $overwrite = false)
{
if ($overwrite) {
$this->_mapReduce = [];
}
if ($mapper === null) {
if (!$overwrite) {
deprecationWarning(
'Using QueryTrait::mapReduce() as a getter is deprecated. ' .
'Use getMapReducers() instead.'
);
}
return $this->_mapReduce;
}
$this->_mapReduce[] = compact('mapper', 'reducer');
return $this;
} | [
"public",
"function",
"mapReduce",
"(",
"callable",
"$",
"mapper",
"=",
"null",
",",
"callable",
"$",
"reducer",
"=",
"null",
",",
"$",
"overwrite",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"overwrite",
")",
"{",
"$",
"this",
"->",
"_mapReduce",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"$",
"mapper",
"===",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"overwrite",
")",
"{",
"deprecationWarning",
"(",
"'Using QueryTrait::mapReduce() as a getter is deprecated. '",
".",
"'Use getMapReducers() instead.'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_mapReduce",
";",
"}",
"$",
"this",
"->",
"_mapReduce",
"[",
"]",
"=",
"compact",
"(",
"'mapper'",
",",
"'reducer'",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Register a new MapReduce routine to be executed on top of the database results
Both the mapper and caller callable should be invokable objects.
The MapReduce routing will only be run when the query is executed and the first
result is attempted to be fetched.
If the first argument is set to null, it will return the list of previously
registered map reduce routines. This is deprecated as of 3.6.0 - use getMapReducers() instead.
If the third argument is set to true, it will erase previous map reducers
and replace it with the arguments passed.
@param callable|null $mapper The mapper callable.
@param callable|null $reducer The reducing function.
@param bool $overwrite Set to true to overwrite existing map + reduce functions.
@return $this|array
@see \Cake\Collection\Iterator\MapReduce for details on how to use emit data to the map reducer. | [
"Register",
"a",
"new",
"MapReduce",
"routine",
"to",
"be",
"executed",
"on",
"top",
"of",
"the",
"database",
"results",
"Both",
"the",
"mapper",
"and",
"caller",
"callable",
"should",
"be",
"invokable",
"objects",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/QueryTrait.php#L348-L366 |
210,766 | cakephp/cakephp | src/Datasource/QueryTrait.php | QueryTrait.formatResults | public function formatResults(callable $formatter = null, $mode = 0)
{
if ($mode === self::OVERWRITE) {
$this->_formatters = [];
}
if ($formatter === null) {
if ($mode !== self::OVERWRITE) {
deprecationWarning(
'Using QueryTrait::formatResults() as a getter is deprecated. ' .
'Use getResultFormatters() instead.'
);
}
return $this->_formatters;
}
if ($mode === self::PREPEND) {
array_unshift($this->_formatters, $formatter);
return $this;
}
$this->_formatters[] = $formatter;
return $this;
} | php | public function formatResults(callable $formatter = null, $mode = 0)
{
if ($mode === self::OVERWRITE) {
$this->_formatters = [];
}
if ($formatter === null) {
if ($mode !== self::OVERWRITE) {
deprecationWarning(
'Using QueryTrait::formatResults() as a getter is deprecated. ' .
'Use getResultFormatters() instead.'
);
}
return $this->_formatters;
}
if ($mode === self::PREPEND) {
array_unshift($this->_formatters, $formatter);
return $this;
}
$this->_formatters[] = $formatter;
return $this;
} | [
"public",
"function",
"formatResults",
"(",
"callable",
"$",
"formatter",
"=",
"null",
",",
"$",
"mode",
"=",
"0",
")",
"{",
"if",
"(",
"$",
"mode",
"===",
"self",
"::",
"OVERWRITE",
")",
"{",
"$",
"this",
"->",
"_formatters",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"$",
"formatter",
"===",
"null",
")",
"{",
"if",
"(",
"$",
"mode",
"!==",
"self",
"::",
"OVERWRITE",
")",
"{",
"deprecationWarning",
"(",
"'Using QueryTrait::formatResults() as a getter is deprecated. '",
".",
"'Use getResultFormatters() instead.'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_formatters",
";",
"}",
"if",
"(",
"$",
"mode",
"===",
"self",
"::",
"PREPEND",
")",
"{",
"array_unshift",
"(",
"$",
"this",
"->",
"_formatters",
",",
"$",
"formatter",
")",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"_formatters",
"[",
"]",
"=",
"$",
"formatter",
";",
"return",
"$",
"this",
";",
"}"
] | Registers a new formatter callback function that is to be executed when trying
to fetch the results from the database.
Formatting callbacks will get a first parameter, an object implementing
`\Cake\Collection\CollectionInterface`, that can be traversed and modified at will.
Callbacks are required to return an iterator object, which will be used as
the return value for this query's result. Formatter functions are applied
after all the `MapReduce` routines for this query have been executed.
If the first argument is set to null, it will return the list of previously
registered format routines. This is deprecated as of 3.6.0 - use getResultFormatters() instead.
If the second argument is set to true, it will erase previous formatters
and replace them with the passed first argument.
### Example:
```
// Return all results from the table indexed by id
$query->select(['id', 'name'])->formatResults(function ($results) {
return $results->indexBy('id');
});
// Add a new column to the ResultSet
$query->select(['name', 'birth_date'])->formatResults(function ($results) {
return $results->map(function ($row) {
$row['age'] = $row['birth_date']->diff(new DateTime)->y;
return $row;
});
});
```
@param callable|null $formatter The formatting callable.
@param bool|int $mode Whether or not to overwrite, append or prepend the formatter.
@return $this|array | [
"Registers",
"a",
"new",
"formatter",
"callback",
"function",
"that",
"is",
"to",
"be",
"executed",
"when",
"trying",
"to",
"fetch",
"the",
"results",
"from",
"the",
"database",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/QueryTrait.php#L416-L441 |
210,767 | cakephp/cakephp | src/I18n/Time.php | Time.nice | public function nice($timezone = null, $locale = null)
{
return $this->i18nFormat(static::$niceFormat, $timezone, $locale);
} | php | public function nice($timezone = null, $locale = null)
{
return $this->i18nFormat(static::$niceFormat, $timezone, $locale);
} | [
"public",
"function",
"nice",
"(",
"$",
"timezone",
"=",
"null",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"i18nFormat",
"(",
"static",
"::",
"$",
"niceFormat",
",",
"$",
"timezone",
",",
"$",
"locale",
")",
";",
"}"
] | Returns a nicely formatted date string for this object.
The format to be used is stored in the static property `Time::niceFormat`.
@param string|\DateTimeZone|null $timezone Timezone string or DateTimeZone object
in which the date will be displayed. The timezone stored for this object will not
be changed.
@param string|null $locale The locale name in which the date should be displayed (e.g. pt-BR)
@return string Formatted date string | [
"Returns",
"a",
"nicely",
"formatted",
"date",
"string",
"for",
"this",
"object",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/I18n/Time.php#L132-L135 |
210,768 | cakephp/cakephp | src/I18n/Time.php | Time.listTimezones | public static function listTimezones($filter = null, $country = null, $options = [])
{
if (is_bool($options)) {
$options = [
'group' => $options,
];
}
$defaults = [
'group' => true,
'abbr' => false,
'before' => ' - ',
'after' => null,
];
$options += $defaults;
$group = $options['group'];
$regex = null;
if (is_string($filter)) {
$regex = $filter;
$filter = null;
}
if ($filter === null) {
$filter = DateTimeZone::ALL;
}
$identifiers = DateTimeZone::listIdentifiers($filter, $country);
if ($regex) {
foreach ($identifiers as $key => $tz) {
if (!preg_match($regex, $tz)) {
unset($identifiers[$key]);
}
}
}
if ($group) {
$groupedIdentifiers = [];
$now = time();
$before = $options['before'];
$after = $options['after'];
foreach ($identifiers as $key => $tz) {
$abbr = null;
if ($options['abbr']) {
$dateTimeZone = new DateTimeZone($tz);
$trans = $dateTimeZone->getTransitions($now, $now);
$abbr = isset($trans[0]['abbr']) ?
$before . $trans[0]['abbr'] . $after :
null;
}
$item = explode('/', $tz, 2);
if (isset($item[1])) {
$groupedIdentifiers[$item[0]][$tz] = $item[1] . $abbr;
} else {
$groupedIdentifiers[$item[0]] = [$tz => $item[0] . $abbr];
}
}
return $groupedIdentifiers;
}
return array_combine($identifiers, $identifiers);
} | php | public static function listTimezones($filter = null, $country = null, $options = [])
{
if (is_bool($options)) {
$options = [
'group' => $options,
];
}
$defaults = [
'group' => true,
'abbr' => false,
'before' => ' - ',
'after' => null,
];
$options += $defaults;
$group = $options['group'];
$regex = null;
if (is_string($filter)) {
$regex = $filter;
$filter = null;
}
if ($filter === null) {
$filter = DateTimeZone::ALL;
}
$identifiers = DateTimeZone::listIdentifiers($filter, $country);
if ($regex) {
foreach ($identifiers as $key => $tz) {
if (!preg_match($regex, $tz)) {
unset($identifiers[$key]);
}
}
}
if ($group) {
$groupedIdentifiers = [];
$now = time();
$before = $options['before'];
$after = $options['after'];
foreach ($identifiers as $key => $tz) {
$abbr = null;
if ($options['abbr']) {
$dateTimeZone = new DateTimeZone($tz);
$trans = $dateTimeZone->getTransitions($now, $now);
$abbr = isset($trans[0]['abbr']) ?
$before . $trans[0]['abbr'] . $after :
null;
}
$item = explode('/', $tz, 2);
if (isset($item[1])) {
$groupedIdentifiers[$item[0]][$tz] = $item[1] . $abbr;
} else {
$groupedIdentifiers[$item[0]] = [$tz => $item[0] . $abbr];
}
}
return $groupedIdentifiers;
}
return array_combine($identifiers, $identifiers);
} | [
"public",
"static",
"function",
"listTimezones",
"(",
"$",
"filter",
"=",
"null",
",",
"$",
"country",
"=",
"null",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"=",
"[",
"'group'",
"=>",
"$",
"options",
",",
"]",
";",
"}",
"$",
"defaults",
"=",
"[",
"'group'",
"=>",
"true",
",",
"'abbr'",
"=>",
"false",
",",
"'before'",
"=>",
"' - '",
",",
"'after'",
"=>",
"null",
",",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"$",
"group",
"=",
"$",
"options",
"[",
"'group'",
"]",
";",
"$",
"regex",
"=",
"null",
";",
"if",
"(",
"is_string",
"(",
"$",
"filter",
")",
")",
"{",
"$",
"regex",
"=",
"$",
"filter",
";",
"$",
"filter",
"=",
"null",
";",
"}",
"if",
"(",
"$",
"filter",
"===",
"null",
")",
"{",
"$",
"filter",
"=",
"DateTimeZone",
"::",
"ALL",
";",
"}",
"$",
"identifiers",
"=",
"DateTimeZone",
"::",
"listIdentifiers",
"(",
"$",
"filter",
",",
"$",
"country",
")",
";",
"if",
"(",
"$",
"regex",
")",
"{",
"foreach",
"(",
"$",
"identifiers",
"as",
"$",
"key",
"=>",
"$",
"tz",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"$",
"regex",
",",
"$",
"tz",
")",
")",
"{",
"unset",
"(",
"$",
"identifiers",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"group",
")",
"{",
"$",
"groupedIdentifiers",
"=",
"[",
"]",
";",
"$",
"now",
"=",
"time",
"(",
")",
";",
"$",
"before",
"=",
"$",
"options",
"[",
"'before'",
"]",
";",
"$",
"after",
"=",
"$",
"options",
"[",
"'after'",
"]",
";",
"foreach",
"(",
"$",
"identifiers",
"as",
"$",
"key",
"=>",
"$",
"tz",
")",
"{",
"$",
"abbr",
"=",
"null",
";",
"if",
"(",
"$",
"options",
"[",
"'abbr'",
"]",
")",
"{",
"$",
"dateTimeZone",
"=",
"new",
"DateTimeZone",
"(",
"$",
"tz",
")",
";",
"$",
"trans",
"=",
"$",
"dateTimeZone",
"->",
"getTransitions",
"(",
"$",
"now",
",",
"$",
"now",
")",
";",
"$",
"abbr",
"=",
"isset",
"(",
"$",
"trans",
"[",
"0",
"]",
"[",
"'abbr'",
"]",
")",
"?",
"$",
"before",
".",
"$",
"trans",
"[",
"0",
"]",
"[",
"'abbr'",
"]",
".",
"$",
"after",
":",
"null",
";",
"}",
"$",
"item",
"=",
"explode",
"(",
"'/'",
",",
"$",
"tz",
",",
"2",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"item",
"[",
"1",
"]",
")",
")",
"{",
"$",
"groupedIdentifiers",
"[",
"$",
"item",
"[",
"0",
"]",
"]",
"[",
"$",
"tz",
"]",
"=",
"$",
"item",
"[",
"1",
"]",
".",
"$",
"abbr",
";",
"}",
"else",
"{",
"$",
"groupedIdentifiers",
"[",
"$",
"item",
"[",
"0",
"]",
"]",
"=",
"[",
"$",
"tz",
"=>",
"$",
"item",
"[",
"0",
"]",
".",
"$",
"abbr",
"]",
";",
"}",
"}",
"return",
"$",
"groupedIdentifiers",
";",
"}",
"return",
"array_combine",
"(",
"$",
"identifiers",
",",
"$",
"identifiers",
")",
";",
"}"
] | Get list of timezone identifiers
@param int|string|null $filter A regex to filter identifier
Or one of DateTimeZone class constants
@param string|null $country A two-letter ISO 3166-1 compatible country code.
This option is only used when $filter is set to DateTimeZone::PER_COUNTRY
@param bool|array $options If true (default value) groups the identifiers list by primary region.
Otherwise, an array containing `group`, `abbr`, `before`, and `after`
keys. Setting `group` and `abbr` to true will group results and append
timezone abbreviation in the display value. Set `before` and `after`
to customize the abbreviation wrapper.
@return array List of timezone identifiers
@since 2.2 | [
"Get",
"list",
"of",
"timezone",
"identifiers"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/I18n/Time.php#L260-L320 |
210,769 | cakephp/cakephp | src/I18n/Time.php | Time.wasWithinLast | public function wasWithinLast($timeInterval)
{
$tmp = trim($timeInterval);
if (is_numeric($tmp)) {
deprecationWarning(
'Passing int/numeric string into Time::wasWithinLast() is deprecated. ' .
'Pass strings including interval eg. "6 days"'
);
$timeInterval = $tmp . ' days';
}
return parent::wasWithinLast($timeInterval);
} | php | public function wasWithinLast($timeInterval)
{
$tmp = trim($timeInterval);
if (is_numeric($tmp)) {
deprecationWarning(
'Passing int/numeric string into Time::wasWithinLast() is deprecated. ' .
'Pass strings including interval eg. "6 days"'
);
$timeInterval = $tmp . ' days';
}
return parent::wasWithinLast($timeInterval);
} | [
"public",
"function",
"wasWithinLast",
"(",
"$",
"timeInterval",
")",
"{",
"$",
"tmp",
"=",
"trim",
"(",
"$",
"timeInterval",
")",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"tmp",
")",
")",
"{",
"deprecationWarning",
"(",
"'Passing int/numeric string into Time::wasWithinLast() is deprecated. '",
".",
"'Pass strings including interval eg. \"6 days\"'",
")",
";",
"$",
"timeInterval",
"=",
"$",
"tmp",
".",
"' days'",
";",
"}",
"return",
"parent",
"::",
"wasWithinLast",
"(",
"$",
"timeInterval",
")",
";",
"}"
] | Returns true this instance will happen within the specified interval
This overridden method provides backwards compatible behavior for integers,
or strings with trailing spaces. This behavior is *deprecated* and will be
removed in future versions of CakePHP.
@param string|int $timeInterval the numeric value with space then time type.
Example of valid types: 6 hours, 2 days, 1 minute.
@return bool | [
"Returns",
"true",
"this",
"instance",
"will",
"happen",
"within",
"the",
"specified",
"interval"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/I18n/Time.php#L333-L345 |
210,770 | cakephp/cakephp | src/ORM/Behavior/TranslateBehavior.php | TranslateBehavior.locale | public function locale($locale = null)
{
deprecationWarning(
get_called_class() . '::locale() is deprecated. ' .
'Use setLocale()/getLocale() instead.'
);
if ($locale !== null) {
$this->setLocale($locale);
}
return $this->getLocale();
} | php | public function locale($locale = null)
{
deprecationWarning(
get_called_class() . '::locale() is deprecated. ' .
'Use setLocale()/getLocale() instead.'
);
if ($locale !== null) {
$this->setLocale($locale);
}
return $this->getLocale();
} | [
"public",
"function",
"locale",
"(",
"$",
"locale",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"get_called_class",
"(",
")",
".",
"'::locale() is deprecated. '",
".",
"'Use setLocale()/getLocale() instead.'",
")",
";",
"if",
"(",
"$",
"locale",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"setLocale",
"(",
"$",
"locale",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getLocale",
"(",
")",
";",
"}"
] | Sets all future finds for the bound table to also fetch translated fields for
the passed locale. If no value is passed, it returns the currently configured
locale
@deprecated 3.6.0 Use setLocale()/getLocale() instead.
@param string|null $locale The locale to use for fetching translated records
@return string | [
"Sets",
"all",
"future",
"finds",
"for",
"the",
"bound",
"table",
"to",
"also",
"fetch",
"translated",
"fields",
"for",
"the",
"passed",
"locale",
".",
"If",
"no",
"value",
"is",
"passed",
"it",
"returns",
"the",
"currently",
"configured",
"locale"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TranslateBehavior.php#L469-L481 |
210,771 | cakephp/cakephp | src/ORM/Behavior/TranslateBehavior.php | TranslateBehavior.findTranslations | public function findTranslations(Query $query, array $options)
{
$locales = isset($options['locales']) ? $options['locales'] : [];
$targetAlias = $this->_translationTable->getAlias();
return $query
->contain([$targetAlias => function ($query) use ($locales, $targetAlias) {
if ($locales) {
/* @var \Cake\Datasource\QueryInterface $query */
$query->where(["$targetAlias.locale IN" => $locales]);
}
return $query;
}])
->formatResults([$this, 'groupTranslations'], $query::PREPEND);
} | php | public function findTranslations(Query $query, array $options)
{
$locales = isset($options['locales']) ? $options['locales'] : [];
$targetAlias = $this->_translationTable->getAlias();
return $query
->contain([$targetAlias => function ($query) use ($locales, $targetAlias) {
if ($locales) {
/* @var \Cake\Datasource\QueryInterface $query */
$query->where(["$targetAlias.locale IN" => $locales]);
}
return $query;
}])
->formatResults([$this, 'groupTranslations'], $query::PREPEND);
} | [
"public",
"function",
"findTranslations",
"(",
"Query",
"$",
"query",
",",
"array",
"$",
"options",
")",
"{",
"$",
"locales",
"=",
"isset",
"(",
"$",
"options",
"[",
"'locales'",
"]",
")",
"?",
"$",
"options",
"[",
"'locales'",
"]",
":",
"[",
"]",
";",
"$",
"targetAlias",
"=",
"$",
"this",
"->",
"_translationTable",
"->",
"getAlias",
"(",
")",
";",
"return",
"$",
"query",
"->",
"contain",
"(",
"[",
"$",
"targetAlias",
"=>",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"locales",
",",
"$",
"targetAlias",
")",
"{",
"if",
"(",
"$",
"locales",
")",
"{",
"/* @var \\Cake\\Datasource\\QueryInterface $query */",
"$",
"query",
"->",
"where",
"(",
"[",
"\"$targetAlias.locale IN\"",
"=>",
"$",
"locales",
"]",
")",
";",
"}",
"return",
"$",
"query",
";",
"}",
"]",
")",
"->",
"formatResults",
"(",
"[",
"$",
"this",
",",
"'groupTranslations'",
"]",
",",
"$",
"query",
"::",
"PREPEND",
")",
";",
"}"
] | Custom finder method used to retrieve all translations for the found records.
Fetched translations can be filtered by locale by passing the `locales` key
in the options array.
Translated values will be found for each entity under the property `_translations`,
containing an array indexed by locale name.
### Example:
```
$article = $articles->find('translations', ['locales' => ['eng', 'deu'])->first();
$englishTranslatedFields = $article->get('_translations')['eng'];
```
If the `locales` array is not passed, it will bring all translations found
for each record.
@param \Cake\ORM\Query $query The original query to modify
@param array $options Options
@return \Cake\ORM\Query | [
"Custom",
"finder",
"method",
"used",
"to",
"retrieve",
"all",
"translations",
"for",
"the",
"found",
"records",
".",
"Fetched",
"translations",
"can",
"be",
"filtered",
"by",
"locale",
"by",
"passing",
"the",
"locales",
"key",
"in",
"the",
"options",
"array",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TranslateBehavior.php#L530-L545 |
210,772 | cakephp/cakephp | src/ORM/Behavior/TranslateBehavior.php | TranslateBehavior._unsetEmptyFields | protected function _unsetEmptyFields(EntityInterface $entity)
{
$translations = (array)$entity->get('_translations');
foreach ($translations as $locale => $translation) {
$fields = $translation->extract($this->_config['fields'], false);
foreach ($fields as $field => $value) {
if (strlen($value) === 0) {
$translation->unsetProperty($field);
}
}
$translation = $translation->extract($this->_config['fields']);
// If now, the current locale property is empty,
// unset it completely.
if (empty(array_filter($translation))) {
unset($entity->get('_translations')[$locale]);
}
}
// If now, the whole _translations property is empty,
// unset it completely and return
if (empty($entity->get('_translations'))) {
$entity->unsetProperty('_translations');
}
} | php | protected function _unsetEmptyFields(EntityInterface $entity)
{
$translations = (array)$entity->get('_translations');
foreach ($translations as $locale => $translation) {
$fields = $translation->extract($this->_config['fields'], false);
foreach ($fields as $field => $value) {
if (strlen($value) === 0) {
$translation->unsetProperty($field);
}
}
$translation = $translation->extract($this->_config['fields']);
// If now, the current locale property is empty,
// unset it completely.
if (empty(array_filter($translation))) {
unset($entity->get('_translations')[$locale]);
}
}
// If now, the whole _translations property is empty,
// unset it completely and return
if (empty($entity->get('_translations'))) {
$entity->unsetProperty('_translations');
}
} | [
"protected",
"function",
"_unsetEmptyFields",
"(",
"EntityInterface",
"$",
"entity",
")",
"{",
"$",
"translations",
"=",
"(",
"array",
")",
"$",
"entity",
"->",
"get",
"(",
"'_translations'",
")",
";",
"foreach",
"(",
"$",
"translations",
"as",
"$",
"locale",
"=>",
"$",
"translation",
")",
"{",
"$",
"fields",
"=",
"$",
"translation",
"->",
"extract",
"(",
"$",
"this",
"->",
"_config",
"[",
"'fields'",
"]",
",",
"false",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"value",
")",
"===",
"0",
")",
"{",
"$",
"translation",
"->",
"unsetProperty",
"(",
"$",
"field",
")",
";",
"}",
"}",
"$",
"translation",
"=",
"$",
"translation",
"->",
"extract",
"(",
"$",
"this",
"->",
"_config",
"[",
"'fields'",
"]",
")",
";",
"// If now, the current locale property is empty,",
"// unset it completely.",
"if",
"(",
"empty",
"(",
"array_filter",
"(",
"$",
"translation",
")",
")",
")",
"{",
"unset",
"(",
"$",
"entity",
"->",
"get",
"(",
"'_translations'",
")",
"[",
"$",
"locale",
"]",
")",
";",
"}",
"}",
"// If now, the whole _translations property is empty,",
"// unset it completely and return",
"if",
"(",
"empty",
"(",
"$",
"entity",
"->",
"get",
"(",
"'_translations'",
")",
")",
")",
"{",
"$",
"entity",
"->",
"unsetProperty",
"(",
"'_translations'",
")",
";",
"}",
"}"
] | Unset empty translations to avoid persistence.
Should only be called if $this->_config['allowEmptyTranslations'] is false.
@param \Cake\Datasource\EntityInterface $entity The entity to check for empty translations fields inside.
@return void | [
"Unset",
"empty",
"translations",
"to",
"avoid",
"persistence",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TranslateBehavior.php#L714-L739 |
210,773 | cakephp/cakephp | src/ORM/Behavior/TranslateBehavior.php | TranslateBehavior._findExistingTranslations | protected function _findExistingTranslations($ruleSet)
{
$association = $this->_table->getAssociation($this->_translationTable->getAlias());
$query = $association->find()
->select(['id', 'num' => 0])
->where(current($ruleSet))
->disableHydration()
->disableBufferedResults();
unset($ruleSet[0]);
foreach ($ruleSet as $i => $conditions) {
$q = $association->find()
->select(['id', 'num' => $i])
->where($conditions);
$query->unionAll($q);
}
return $query->all()->combine('num', 'id')->toArray();
} | php | protected function _findExistingTranslations($ruleSet)
{
$association = $this->_table->getAssociation($this->_translationTable->getAlias());
$query = $association->find()
->select(['id', 'num' => 0])
->where(current($ruleSet))
->disableHydration()
->disableBufferedResults();
unset($ruleSet[0]);
foreach ($ruleSet as $i => $conditions) {
$q = $association->find()
->select(['id', 'num' => $i])
->where($conditions);
$query->unionAll($q);
}
return $query->all()->combine('num', 'id')->toArray();
} | [
"protected",
"function",
"_findExistingTranslations",
"(",
"$",
"ruleSet",
")",
"{",
"$",
"association",
"=",
"$",
"this",
"->",
"_table",
"->",
"getAssociation",
"(",
"$",
"this",
"->",
"_translationTable",
"->",
"getAlias",
"(",
")",
")",
";",
"$",
"query",
"=",
"$",
"association",
"->",
"find",
"(",
")",
"->",
"select",
"(",
"[",
"'id'",
",",
"'num'",
"=>",
"0",
"]",
")",
"->",
"where",
"(",
"current",
"(",
"$",
"ruleSet",
")",
")",
"->",
"disableHydration",
"(",
")",
"->",
"disableBufferedResults",
"(",
")",
";",
"unset",
"(",
"$",
"ruleSet",
"[",
"0",
"]",
")",
";",
"foreach",
"(",
"$",
"ruleSet",
"as",
"$",
"i",
"=>",
"$",
"conditions",
")",
"{",
"$",
"q",
"=",
"$",
"association",
"->",
"find",
"(",
")",
"->",
"select",
"(",
"[",
"'id'",
",",
"'num'",
"=>",
"$",
"i",
"]",
")",
"->",
"where",
"(",
"$",
"conditions",
")",
";",
"$",
"query",
"->",
"unionAll",
"(",
"$",
"q",
")",
";",
"}",
"return",
"$",
"query",
"->",
"all",
"(",
")",
"->",
"combine",
"(",
"'num'",
",",
"'id'",
")",
"->",
"toArray",
"(",
")",
";",
"}"
] | Returns the ids found for each of the condition arrays passed for the translations
table. Each records is indexed by the corresponding position to the conditions array
@param array $ruleSet an array of arary of conditions to be used for finding each
@return array | [
"Returns",
"the",
"ids",
"found",
"for",
"each",
"of",
"the",
"condition",
"arrays",
"passed",
"for",
"the",
"translations",
"table",
".",
"Each",
"records",
"is",
"indexed",
"by",
"the",
"corresponding",
"position",
"to",
"the",
"conditions",
"array"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TranslateBehavior.php#L748-L767 |
210,774 | cakephp/cakephp | src/Cache/SimpleCacheEngine.php | SimpleCacheEngine.ensureValidKeys | protected function ensureValidKeys($keys)
{
if (!is_array($keys) && !($keys instanceof \Traversable)) {
throw new InvalidArgumentException('A cache key set must be either an array or a Traversable.');
}
foreach ($keys as $key) {
$this->ensureValidKey($key);
}
} | php | protected function ensureValidKeys($keys)
{
if (!is_array($keys) && !($keys instanceof \Traversable)) {
throw new InvalidArgumentException('A cache key set must be either an array or a Traversable.');
}
foreach ($keys as $key) {
$this->ensureValidKey($key);
}
} | [
"protected",
"function",
"ensureValidKeys",
"(",
"$",
"keys",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"keys",
")",
"&&",
"!",
"(",
"$",
"keys",
"instanceof",
"\\",
"Traversable",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'A cache key set must be either an array or a Traversable.'",
")",
";",
"}",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"ensureValidKey",
"(",
"$",
"key",
")",
";",
"}",
"}"
] | Ensure the validity of the given cache keys.
@param mixed $keys The keys to check.
@return void
@throws \Cake\Cache\InvalidArgumentException When the keys are not valid. | [
"Ensure",
"the",
"validity",
"of",
"the",
"given",
"cache",
"keys",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/SimpleCacheEngine.php#L68-L77 |
210,775 | cakephp/cakephp | src/Cache/SimpleCacheEngine.php | SimpleCacheEngine.get | public function get($key, $default = null)
{
$this->ensureValidKey($key);
$result = $this->innerEngine->read($key);
if ($result === false) {
return $default;
}
return $result;
} | php | public function get($key, $default = null)
{
$this->ensureValidKey($key);
$result = $this->innerEngine->read($key);
if ($result === false) {
return $default;
}
return $result;
} | [
"public",
"function",
"get",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"ensureValidKey",
"(",
"$",
"key",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"innerEngine",
"->",
"read",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"result",
"===",
"false",
")",
"{",
"return",
"$",
"default",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Fetches the value for a given key from the cache.
@param string $key The unique key of this item in the cache.
@param mixed $default Default value to return if the key does not exist.
@return mixed The value of the item from the cache, or $default in case of cache miss.
@throws \Cake\Cache\InvalidArgumentException If the $key string is not a legal value. | [
"Fetches",
"the",
"value",
"for",
"a",
"given",
"key",
"from",
"the",
"cache",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/SimpleCacheEngine.php#L87-L96 |
210,776 | cakephp/cakephp | src/Cache/SimpleCacheEngine.php | SimpleCacheEngine.set | public function set($key, $value, $ttl = null)
{
$this->ensureValidKey($key);
if ($ttl !== null) {
$restore = $this->innerEngine->getConfig('duration');
$this->innerEngine->setConfig('duration', $ttl);
}
try {
$result = $this->innerEngine->write($key, $value);
return (bool)$result;
} finally {
if (isset($restore)) {
$this->innerEngine->setConfig('duration', $restore);
}
}
} | php | public function set($key, $value, $ttl = null)
{
$this->ensureValidKey($key);
if ($ttl !== null) {
$restore = $this->innerEngine->getConfig('duration');
$this->innerEngine->setConfig('duration', $ttl);
}
try {
$result = $this->innerEngine->write($key, $value);
return (bool)$result;
} finally {
if (isset($restore)) {
$this->innerEngine->setConfig('duration', $restore);
}
}
} | [
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"ttl",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"ensureValidKey",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"ttl",
"!==",
"null",
")",
"{",
"$",
"restore",
"=",
"$",
"this",
"->",
"innerEngine",
"->",
"getConfig",
"(",
"'duration'",
")",
";",
"$",
"this",
"->",
"innerEngine",
"->",
"setConfig",
"(",
"'duration'",
",",
"$",
"ttl",
")",
";",
"}",
"try",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"innerEngine",
"->",
"write",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"return",
"(",
"bool",
")",
"$",
"result",
";",
"}",
"finally",
"{",
"if",
"(",
"isset",
"(",
"$",
"restore",
")",
")",
"{",
"$",
"this",
"->",
"innerEngine",
"->",
"setConfig",
"(",
"'duration'",
",",
"$",
"restore",
")",
";",
"}",
"}",
"}"
] | Persists data in the cache, uniquely referenced by the given key with an optional expiration TTL time.
@param string $key The key of the item to store.
@param mixed $value The value of the item to store, must be serializable.
@param null|int|\DateInterval $ttl Optional. The TTL value of this item. If no value is sent and
the driver supports TTL then the library may set a default value
for it or let the driver take care of that.
@return bool True on success and false on failure.
@throws \Cake\Cache\InvalidArgumentException
MUST be thrown if the $key string is not a legal value. | [
"Persists",
"data",
"in",
"the",
"cache",
"uniquely",
"referenced",
"by",
"the",
"given",
"key",
"with",
"an",
"optional",
"expiration",
"TTL",
"time",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/SimpleCacheEngine.php#L110-L126 |
210,777 | cakephp/cakephp | src/Filesystem/File.php | File.create | public function create()
{
$dir = $this->Folder->pwd();
if (is_dir($dir) && is_writable($dir) && !$this->exists() && touch($this->path)) {
return true;
}
return false;
} | php | public function create()
{
$dir = $this->Folder->pwd();
if (is_dir($dir) && is_writable($dir) && !$this->exists() && touch($this->path)) {
return true;
}
return false;
} | [
"public",
"function",
"create",
"(",
")",
"{",
"$",
"dir",
"=",
"$",
"this",
"->",
"Folder",
"->",
"pwd",
"(",
")",
";",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
")",
"&&",
"is_writable",
"(",
"$",
"dir",
")",
"&&",
"!",
"$",
"this",
"->",
"exists",
"(",
")",
"&&",
"touch",
"(",
"$",
"this",
"->",
"path",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Creates the file.
@return bool Success | [
"Creates",
"the",
"file",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Filesystem/File.php#L108-L117 |
210,778 | cakephp/cakephp | src/Filesystem/File.php | File.read | public function read($bytes = false, $mode = 'rb', $force = false)
{
if ($bytes === false && $this->lock === null) {
return file_get_contents($this->path);
}
if ($this->open($mode, $force) === false) {
return false;
}
if ($this->lock !== null && flock($this->handle, LOCK_SH) === false) {
return false;
}
if (is_int($bytes)) {
return fread($this->handle, $bytes);
}
$data = '';
while (!feof($this->handle)) {
$data .= fgets($this->handle, 4096);
}
if ($this->lock !== null) {
flock($this->handle, LOCK_UN);
}
if ($bytes === false) {
$this->close();
}
return trim($data);
} | php | public function read($bytes = false, $mode = 'rb', $force = false)
{
if ($bytes === false && $this->lock === null) {
return file_get_contents($this->path);
}
if ($this->open($mode, $force) === false) {
return false;
}
if ($this->lock !== null && flock($this->handle, LOCK_SH) === false) {
return false;
}
if (is_int($bytes)) {
return fread($this->handle, $bytes);
}
$data = '';
while (!feof($this->handle)) {
$data .= fgets($this->handle, 4096);
}
if ($this->lock !== null) {
flock($this->handle, LOCK_UN);
}
if ($bytes === false) {
$this->close();
}
return trim($data);
} | [
"public",
"function",
"read",
"(",
"$",
"bytes",
"=",
"false",
",",
"$",
"mode",
"=",
"'rb'",
",",
"$",
"force",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"bytes",
"===",
"false",
"&&",
"$",
"this",
"->",
"lock",
"===",
"null",
")",
"{",
"return",
"file_get_contents",
"(",
"$",
"this",
"->",
"path",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"open",
"(",
"$",
"mode",
",",
"$",
"force",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"lock",
"!==",
"null",
"&&",
"flock",
"(",
"$",
"this",
"->",
"handle",
",",
"LOCK_SH",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"is_int",
"(",
"$",
"bytes",
")",
")",
"{",
"return",
"fread",
"(",
"$",
"this",
"->",
"handle",
",",
"$",
"bytes",
")",
";",
"}",
"$",
"data",
"=",
"''",
";",
"while",
"(",
"!",
"feof",
"(",
"$",
"this",
"->",
"handle",
")",
")",
"{",
"$",
"data",
".=",
"fgets",
"(",
"$",
"this",
"->",
"handle",
",",
"4096",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"lock",
"!==",
"null",
")",
"{",
"flock",
"(",
"$",
"this",
"->",
"handle",
",",
"LOCK_UN",
")",
";",
"}",
"if",
"(",
"$",
"bytes",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"close",
"(",
")",
";",
"}",
"return",
"trim",
"(",
"$",
"data",
")",
";",
"}"
] | Return the contents of this file as a string.
@param string|bool $bytes where to start
@param string $mode A `fread` compatible mode.
@param bool $force If true then the file will be re-opened even if its already opened, otherwise it won't
@return string|false string on success, false on failure | [
"Return",
"the",
"contents",
"of",
"this",
"file",
"as",
"a",
"string",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Filesystem/File.php#L148-L176 |
210,779 | cakephp/cakephp | src/Filesystem/File.php | File.offset | public function offset($offset = false, $seek = SEEK_SET)
{
if ($offset === false) {
if (is_resource($this->handle)) {
return ftell($this->handle);
}
} elseif ($this->open() === true) {
return fseek($this->handle, $offset, $seek) === 0;
}
return false;
} | php | public function offset($offset = false, $seek = SEEK_SET)
{
if ($offset === false) {
if (is_resource($this->handle)) {
return ftell($this->handle);
}
} elseif ($this->open() === true) {
return fseek($this->handle, $offset, $seek) === 0;
}
return false;
} | [
"public",
"function",
"offset",
"(",
"$",
"offset",
"=",
"false",
",",
"$",
"seek",
"=",
"SEEK_SET",
")",
"{",
"if",
"(",
"$",
"offset",
"===",
"false",
")",
"{",
"if",
"(",
"is_resource",
"(",
"$",
"this",
"->",
"handle",
")",
")",
"{",
"return",
"ftell",
"(",
"$",
"this",
"->",
"handle",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"this",
"->",
"open",
"(",
")",
"===",
"true",
")",
"{",
"return",
"fseek",
"(",
"$",
"this",
"->",
"handle",
",",
"$",
"offset",
",",
"$",
"seek",
")",
"===",
"0",
";",
"}",
"return",
"false",
";",
"}"
] | Sets or gets the offset for the currently opened file.
@param int|bool $offset The $offset in bytes to seek. If set to false then the current offset is returned.
@param int $seek PHP Constant SEEK_SET | SEEK_CUR | SEEK_END determining what the $offset is relative to
@return int|bool True on success, false on failure (set mode), false on failure or integer offset on success (get mode) | [
"Sets",
"or",
"gets",
"the",
"offset",
"for",
"the",
"currently",
"opened",
"file",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Filesystem/File.php#L185-L196 |
210,780 | cakephp/cakephp | src/Filesystem/File.php | File.prepare | public static function prepare($data, $forceWindows = false)
{
$lineBreak = "\n";
if (DIRECTORY_SEPARATOR === '\\' || $forceWindows === true) {
$lineBreak = "\r\n";
}
return strtr($data, ["\r\n" => $lineBreak, "\n" => $lineBreak, "\r" => $lineBreak]);
} | php | public static function prepare($data, $forceWindows = false)
{
$lineBreak = "\n";
if (DIRECTORY_SEPARATOR === '\\' || $forceWindows === true) {
$lineBreak = "\r\n";
}
return strtr($data, ["\r\n" => $lineBreak, "\n" => $lineBreak, "\r" => $lineBreak]);
} | [
"public",
"static",
"function",
"prepare",
"(",
"$",
"data",
",",
"$",
"forceWindows",
"=",
"false",
")",
"{",
"$",
"lineBreak",
"=",
"\"\\n\"",
";",
"if",
"(",
"DIRECTORY_SEPARATOR",
"===",
"'\\\\'",
"||",
"$",
"forceWindows",
"===",
"true",
")",
"{",
"$",
"lineBreak",
"=",
"\"\\r\\n\"",
";",
"}",
"return",
"strtr",
"(",
"$",
"data",
",",
"[",
"\"\\r\\n\"",
"=>",
"$",
"lineBreak",
",",
"\"\\n\"",
"=>",
"$",
"lineBreak",
",",
"\"\\r\"",
"=>",
"$",
"lineBreak",
"]",
")",
";",
"}"
] | Prepares an ASCII string for writing. Converts line endings to the
correct terminator for the current platform. If Windows, "\r\n" will be used,
all other platforms will use "\n"
@param string $data Data to prepare for writing.
@param bool $forceWindows If true forces Windows new line string.
@return string The with converted line endings. | [
"Prepares",
"an",
"ASCII",
"string",
"for",
"writing",
".",
"Converts",
"line",
"endings",
"to",
"the",
"correct",
"terminator",
"for",
"the",
"current",
"platform",
".",
"If",
"Windows",
"\\",
"r",
"\\",
"n",
"will",
"be",
"used",
"all",
"other",
"platforms",
"will",
"use",
"\\",
"n"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Filesystem/File.php#L207-L215 |
210,781 | cakephp/cakephp | src/Filesystem/File.php | File.write | public function write($data, $mode = 'w', $force = false)
{
$success = false;
if ($this->open($mode, $force) === true) {
if ($this->lock !== null && flock($this->handle, LOCK_EX) === false) {
return false;
}
if (fwrite($this->handle, $data) !== false) {
$success = true;
}
if ($this->lock !== null) {
flock($this->handle, LOCK_UN);
}
}
return $success;
} | php | public function write($data, $mode = 'w', $force = false)
{
$success = false;
if ($this->open($mode, $force) === true) {
if ($this->lock !== null && flock($this->handle, LOCK_EX) === false) {
return false;
}
if (fwrite($this->handle, $data) !== false) {
$success = true;
}
if ($this->lock !== null) {
flock($this->handle, LOCK_UN);
}
}
return $success;
} | [
"public",
"function",
"write",
"(",
"$",
"data",
",",
"$",
"mode",
"=",
"'w'",
",",
"$",
"force",
"=",
"false",
")",
"{",
"$",
"success",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"open",
"(",
"$",
"mode",
",",
"$",
"force",
")",
"===",
"true",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"lock",
"!==",
"null",
"&&",
"flock",
"(",
"$",
"this",
"->",
"handle",
",",
"LOCK_EX",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"fwrite",
"(",
"$",
"this",
"->",
"handle",
",",
"$",
"data",
")",
"!==",
"false",
")",
"{",
"$",
"success",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"lock",
"!==",
"null",
")",
"{",
"flock",
"(",
"$",
"this",
"->",
"handle",
",",
"LOCK_UN",
")",
";",
"}",
"}",
"return",
"$",
"success",
";",
"}"
] | Write given data to this file.
@param string $data Data to write to this File.
@param string $mode Mode of writing. {@link https://secure.php.net/fwrite See fwrite()}.
@param bool $force Force the file to open
@return bool Success | [
"Write",
"given",
"data",
"to",
"this",
"file",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Filesystem/File.php#L225-L242 |
210,782 | cakephp/cakephp | src/Filesystem/File.php | File.md5 | public function md5($maxsize = 5)
{
if ($maxsize === true) {
return md5_file($this->path);
}
$size = $this->size();
if ($size && $size < ($maxsize * 1024) * 1024) {
return md5_file($this->path);
}
return false;
} | php | public function md5($maxsize = 5)
{
if ($maxsize === true) {
return md5_file($this->path);
}
$size = $this->size();
if ($size && $size < ($maxsize * 1024) * 1024) {
return md5_file($this->path);
}
return false;
} | [
"public",
"function",
"md5",
"(",
"$",
"maxsize",
"=",
"5",
")",
"{",
"if",
"(",
"$",
"maxsize",
"===",
"true",
")",
"{",
"return",
"md5_file",
"(",
"$",
"this",
"->",
"path",
")",
";",
"}",
"$",
"size",
"=",
"$",
"this",
"->",
"size",
"(",
")",
";",
"if",
"(",
"$",
"size",
"&&",
"$",
"size",
"<",
"(",
"$",
"maxsize",
"*",
"1024",
")",
"*",
"1024",
")",
"{",
"return",
"md5_file",
"(",
"$",
"this",
"->",
"path",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Get md5 Checksum of file with previous check of Filesize
@param int|bool $maxsize in MB or true to force
@return string|false md5 Checksum {@link https://secure.php.net/md5_file See md5_file()}, or false in case of an error | [
"Get",
"md5",
"Checksum",
"of",
"file",
"with",
"previous",
"check",
"of",
"Filesize"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Filesystem/File.php#L407-L419 |
210,783 | cakephp/cakephp | src/Filesystem/File.php | File.replaceText | public function replaceText($search, $replace)
{
if (!$this->open('r+')) {
return false;
}
if ($this->lock !== null && flock($this->handle, LOCK_EX) === false) {
return false;
}
$replaced = $this->write(str_replace($search, $replace, $this->read()), 'w', true);
if ($this->lock !== null) {
flock($this->handle, LOCK_UN);
}
$this->close();
return $replaced;
} | php | public function replaceText($search, $replace)
{
if (!$this->open('r+')) {
return false;
}
if ($this->lock !== null && flock($this->handle, LOCK_EX) === false) {
return false;
}
$replaced = $this->write(str_replace($search, $replace, $this->read()), 'w', true);
if ($this->lock !== null) {
flock($this->handle, LOCK_UN);
}
$this->close();
return $replaced;
} | [
"public",
"function",
"replaceText",
"(",
"$",
"search",
",",
"$",
"replace",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"open",
"(",
"'r+'",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"lock",
"!==",
"null",
"&&",
"flock",
"(",
"$",
"this",
"->",
"handle",
",",
"LOCK_EX",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"$",
"replaced",
"=",
"$",
"this",
"->",
"write",
"(",
"str_replace",
"(",
"$",
"search",
",",
"$",
"replace",
",",
"$",
"this",
"->",
"read",
"(",
")",
")",
",",
"'w'",
",",
"true",
")",
";",
"if",
"(",
"$",
"this",
"->",
"lock",
"!==",
"null",
")",
"{",
"flock",
"(",
"$",
"this",
"->",
"handle",
",",
"LOCK_UN",
")",
";",
"}",
"$",
"this",
"->",
"close",
"(",
")",
";",
"return",
"$",
"replaced",
";",
"}"
] | Searches for a given text and replaces the text if found.
@param string|array $search Text(s) to search for.
@param string|array $replace Text(s) to replace with.
@return bool Success | [
"Searches",
"for",
"a",
"given",
"text",
"and",
"replaces",
"the",
"text",
"if",
"found",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Filesystem/File.php#L641-L659 |
210,784 | cakephp/cakephp | src/ORM/Behavior/CounterCacheBehavior.php | CounterCacheBehavior.beforeSave | public function beforeSave(Event $event, EntityInterface $entity, $options)
{
if (isset($options['ignoreCounterCache']) && $options['ignoreCounterCache'] === true) {
return;
}
foreach ($this->_config as $assoc => $settings) {
$assoc = $this->_table->getAssociation($assoc);
foreach ($settings as $field => $config) {
if (is_int($field)) {
continue;
}
$registryAlias = $assoc->getTarget()->getRegistryAlias();
$entityAlias = $assoc->getProperty();
if (!is_callable($config) &&
isset($config['ignoreDirty']) &&
$config['ignoreDirty'] === true &&
$entity->$entityAlias->isDirty($field)
) {
$this->_ignoreDirty[$registryAlias][$field] = true;
}
}
}
} | php | public function beforeSave(Event $event, EntityInterface $entity, $options)
{
if (isset($options['ignoreCounterCache']) && $options['ignoreCounterCache'] === true) {
return;
}
foreach ($this->_config as $assoc => $settings) {
$assoc = $this->_table->getAssociation($assoc);
foreach ($settings as $field => $config) {
if (is_int($field)) {
continue;
}
$registryAlias = $assoc->getTarget()->getRegistryAlias();
$entityAlias = $assoc->getProperty();
if (!is_callable($config) &&
isset($config['ignoreDirty']) &&
$config['ignoreDirty'] === true &&
$entity->$entityAlias->isDirty($field)
) {
$this->_ignoreDirty[$registryAlias][$field] = true;
}
}
}
} | [
"public",
"function",
"beforeSave",
"(",
"Event",
"$",
"event",
",",
"EntityInterface",
"$",
"entity",
",",
"$",
"options",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'ignoreCounterCache'",
"]",
")",
"&&",
"$",
"options",
"[",
"'ignoreCounterCache'",
"]",
"===",
"true",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"_config",
"as",
"$",
"assoc",
"=>",
"$",
"settings",
")",
"{",
"$",
"assoc",
"=",
"$",
"this",
"->",
"_table",
"->",
"getAssociation",
"(",
"$",
"assoc",
")",
";",
"foreach",
"(",
"$",
"settings",
"as",
"$",
"field",
"=>",
"$",
"config",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"field",
")",
")",
"{",
"continue",
";",
"}",
"$",
"registryAlias",
"=",
"$",
"assoc",
"->",
"getTarget",
"(",
")",
"->",
"getRegistryAlias",
"(",
")",
";",
"$",
"entityAlias",
"=",
"$",
"assoc",
"->",
"getProperty",
"(",
")",
";",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"config",
")",
"&&",
"isset",
"(",
"$",
"config",
"[",
"'ignoreDirty'",
"]",
")",
"&&",
"$",
"config",
"[",
"'ignoreDirty'",
"]",
"===",
"true",
"&&",
"$",
"entity",
"->",
"$",
"entityAlias",
"->",
"isDirty",
"(",
"$",
"field",
")",
")",
"{",
"$",
"this",
"->",
"_ignoreDirty",
"[",
"$",
"registryAlias",
"]",
"[",
"$",
"field",
"]",
"=",
"true",
";",
"}",
"}",
"}",
"}"
] | beforeSave callback.
Check if a field, which should be ignored, is dirty
@param \Cake\Event\Event $event The beforeSave event that was fired
@param \Cake\Datasource\EntityInterface $entity The entity that is going to be saved
@param \ArrayObject $options The options for the query
@return void | [
"beforeSave",
"callback",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/CounterCacheBehavior.php#L121-L146 |
210,785 | cakephp/cakephp | src/ORM/Behavior/CounterCacheBehavior.php | CounterCacheBehavior.afterSave | public function afterSave(Event $event, EntityInterface $entity, $options)
{
if (isset($options['ignoreCounterCache']) && $options['ignoreCounterCache'] === true) {
return;
}
$this->_processAssociations($event, $entity);
$this->_ignoreDirty = [];
} | php | public function afterSave(Event $event, EntityInterface $entity, $options)
{
if (isset($options['ignoreCounterCache']) && $options['ignoreCounterCache'] === true) {
return;
}
$this->_processAssociations($event, $entity);
$this->_ignoreDirty = [];
} | [
"public",
"function",
"afterSave",
"(",
"Event",
"$",
"event",
",",
"EntityInterface",
"$",
"entity",
",",
"$",
"options",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'ignoreCounterCache'",
"]",
")",
"&&",
"$",
"options",
"[",
"'ignoreCounterCache'",
"]",
"===",
"true",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"_processAssociations",
"(",
"$",
"event",
",",
"$",
"entity",
")",
";",
"$",
"this",
"->",
"_ignoreDirty",
"=",
"[",
"]",
";",
"}"
] | afterSave callback.
Makes sure to update counter cache when a new record is created or updated.
@param \Cake\Event\Event $event The afterSave event that was fired.
@param \Cake\Datasource\EntityInterface $entity The entity that was saved.
@param \ArrayObject $options The options for the query
@return void | [
"afterSave",
"callback",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/CounterCacheBehavior.php#L158-L166 |
210,786 | cakephp/cakephp | src/ORM/Behavior/CounterCacheBehavior.php | CounterCacheBehavior.afterDelete | public function afterDelete(Event $event, EntityInterface $entity, $options)
{
if (isset($options['ignoreCounterCache']) && $options['ignoreCounterCache'] === true) {
return;
}
$this->_processAssociations($event, $entity);
} | php | public function afterDelete(Event $event, EntityInterface $entity, $options)
{
if (isset($options['ignoreCounterCache']) && $options['ignoreCounterCache'] === true) {
return;
}
$this->_processAssociations($event, $entity);
} | [
"public",
"function",
"afterDelete",
"(",
"Event",
"$",
"event",
",",
"EntityInterface",
"$",
"entity",
",",
"$",
"options",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'ignoreCounterCache'",
"]",
")",
"&&",
"$",
"options",
"[",
"'ignoreCounterCache'",
"]",
"===",
"true",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"_processAssociations",
"(",
"$",
"event",
",",
"$",
"entity",
")",
";",
"}"
] | afterDelete callback.
Makes sure to update counter cache when a record is deleted.
@param \Cake\Event\Event $event The afterDelete event that was fired.
@param \Cake\Datasource\EntityInterface $entity The entity that was deleted.
@param \ArrayObject $options The options for the query
@return void | [
"afterDelete",
"callback",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/CounterCacheBehavior.php#L178-L185 |
210,787 | cakephp/cakephp | src/ORM/Behavior/CounterCacheBehavior.php | CounterCacheBehavior._processAssociations | protected function _processAssociations(Event $event, EntityInterface $entity)
{
foreach ($this->_config as $assoc => $settings) {
$assoc = $this->_table->getAssociation($assoc);
$this->_processAssociation($event, $entity, $assoc, $settings);
}
} | php | protected function _processAssociations(Event $event, EntityInterface $entity)
{
foreach ($this->_config as $assoc => $settings) {
$assoc = $this->_table->getAssociation($assoc);
$this->_processAssociation($event, $entity, $assoc, $settings);
}
} | [
"protected",
"function",
"_processAssociations",
"(",
"Event",
"$",
"event",
",",
"EntityInterface",
"$",
"entity",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_config",
"as",
"$",
"assoc",
"=>",
"$",
"settings",
")",
"{",
"$",
"assoc",
"=",
"$",
"this",
"->",
"_table",
"->",
"getAssociation",
"(",
"$",
"assoc",
")",
";",
"$",
"this",
"->",
"_processAssociation",
"(",
"$",
"event",
",",
"$",
"entity",
",",
"$",
"assoc",
",",
"$",
"settings",
")",
";",
"}",
"}"
] | Iterate all associations and update counter caches.
@param \Cake\Event\Event $event Event instance.
@param \Cake\Datasource\EntityInterface $entity Entity.
@return void | [
"Iterate",
"all",
"associations",
"and",
"update",
"counter",
"caches",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/CounterCacheBehavior.php#L194-L200 |
210,788 | cakephp/cakephp | src/ORM/Behavior/CounterCacheBehavior.php | CounterCacheBehavior._processAssociation | protected function _processAssociation(Event $event, EntityInterface $entity, Association $assoc, array $settings)
{
$foreignKeys = (array)$assoc->getForeignKey();
$primaryKeys = (array)$assoc->getBindingKey();
$countConditions = $entity->extract($foreignKeys);
$updateConditions = array_combine($primaryKeys, $countConditions);
$countOriginalConditions = $entity->extractOriginalChanged($foreignKeys);
if ($countOriginalConditions !== []) {
$updateOriginalConditions = array_combine($primaryKeys, $countOriginalConditions);
}
foreach ($settings as $field => $config) {
if (is_int($field)) {
$field = $config;
$config = [];
}
if (isset($this->_ignoreDirty[$assoc->getTarget()->getRegistryAlias()][$field]) &&
$this->_ignoreDirty[$assoc->getTarget()->getRegistryAlias()][$field] === true
) {
continue;
}
if (is_callable($config)) {
if (is_string($config)) {
throw new RuntimeException('You must not use a string as callable.');
}
$count = $config($event, $entity, $this->_table, false);
} else {
$count = $this->_getCount($config, $countConditions);
}
if ($count !== false) {
$assoc->getTarget()->updateAll([$field => $count], $updateConditions);
}
if (isset($updateOriginalConditions)) {
if (is_callable($config)) {
if (is_string($config)) {
throw new RuntimeException('You must not use a string as callable.');
}
$count = $config($event, $entity, $this->_table, true);
} else {
$count = $this->_getCount($config, $countOriginalConditions);
}
if ($count !== false) {
$assoc->getTarget()->updateAll([$field => $count], $updateOriginalConditions);
}
}
}
} | php | protected function _processAssociation(Event $event, EntityInterface $entity, Association $assoc, array $settings)
{
$foreignKeys = (array)$assoc->getForeignKey();
$primaryKeys = (array)$assoc->getBindingKey();
$countConditions = $entity->extract($foreignKeys);
$updateConditions = array_combine($primaryKeys, $countConditions);
$countOriginalConditions = $entity->extractOriginalChanged($foreignKeys);
if ($countOriginalConditions !== []) {
$updateOriginalConditions = array_combine($primaryKeys, $countOriginalConditions);
}
foreach ($settings as $field => $config) {
if (is_int($field)) {
$field = $config;
$config = [];
}
if (isset($this->_ignoreDirty[$assoc->getTarget()->getRegistryAlias()][$field]) &&
$this->_ignoreDirty[$assoc->getTarget()->getRegistryAlias()][$field] === true
) {
continue;
}
if (is_callable($config)) {
if (is_string($config)) {
throw new RuntimeException('You must not use a string as callable.');
}
$count = $config($event, $entity, $this->_table, false);
} else {
$count = $this->_getCount($config, $countConditions);
}
if ($count !== false) {
$assoc->getTarget()->updateAll([$field => $count], $updateConditions);
}
if (isset($updateOriginalConditions)) {
if (is_callable($config)) {
if (is_string($config)) {
throw new RuntimeException('You must not use a string as callable.');
}
$count = $config($event, $entity, $this->_table, true);
} else {
$count = $this->_getCount($config, $countOriginalConditions);
}
if ($count !== false) {
$assoc->getTarget()->updateAll([$field => $count], $updateOriginalConditions);
}
}
}
} | [
"protected",
"function",
"_processAssociation",
"(",
"Event",
"$",
"event",
",",
"EntityInterface",
"$",
"entity",
",",
"Association",
"$",
"assoc",
",",
"array",
"$",
"settings",
")",
"{",
"$",
"foreignKeys",
"=",
"(",
"array",
")",
"$",
"assoc",
"->",
"getForeignKey",
"(",
")",
";",
"$",
"primaryKeys",
"=",
"(",
"array",
")",
"$",
"assoc",
"->",
"getBindingKey",
"(",
")",
";",
"$",
"countConditions",
"=",
"$",
"entity",
"->",
"extract",
"(",
"$",
"foreignKeys",
")",
";",
"$",
"updateConditions",
"=",
"array_combine",
"(",
"$",
"primaryKeys",
",",
"$",
"countConditions",
")",
";",
"$",
"countOriginalConditions",
"=",
"$",
"entity",
"->",
"extractOriginalChanged",
"(",
"$",
"foreignKeys",
")",
";",
"if",
"(",
"$",
"countOriginalConditions",
"!==",
"[",
"]",
")",
"{",
"$",
"updateOriginalConditions",
"=",
"array_combine",
"(",
"$",
"primaryKeys",
",",
"$",
"countOriginalConditions",
")",
";",
"}",
"foreach",
"(",
"$",
"settings",
"as",
"$",
"field",
"=>",
"$",
"config",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"field",
")",
")",
"{",
"$",
"field",
"=",
"$",
"config",
";",
"$",
"config",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_ignoreDirty",
"[",
"$",
"assoc",
"->",
"getTarget",
"(",
")",
"->",
"getRegistryAlias",
"(",
")",
"]",
"[",
"$",
"field",
"]",
")",
"&&",
"$",
"this",
"->",
"_ignoreDirty",
"[",
"$",
"assoc",
"->",
"getTarget",
"(",
")",
"->",
"getRegistryAlias",
"(",
")",
"]",
"[",
"$",
"field",
"]",
"===",
"true",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"is_callable",
"(",
"$",
"config",
")",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"config",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'You must not use a string as callable.'",
")",
";",
"}",
"$",
"count",
"=",
"$",
"config",
"(",
"$",
"event",
",",
"$",
"entity",
",",
"$",
"this",
"->",
"_table",
",",
"false",
")",
";",
"}",
"else",
"{",
"$",
"count",
"=",
"$",
"this",
"->",
"_getCount",
"(",
"$",
"config",
",",
"$",
"countConditions",
")",
";",
"}",
"if",
"(",
"$",
"count",
"!==",
"false",
")",
"{",
"$",
"assoc",
"->",
"getTarget",
"(",
")",
"->",
"updateAll",
"(",
"[",
"$",
"field",
"=>",
"$",
"count",
"]",
",",
"$",
"updateConditions",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"updateOriginalConditions",
")",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"config",
")",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"config",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'You must not use a string as callable.'",
")",
";",
"}",
"$",
"count",
"=",
"$",
"config",
"(",
"$",
"event",
",",
"$",
"entity",
",",
"$",
"this",
"->",
"_table",
",",
"true",
")",
";",
"}",
"else",
"{",
"$",
"count",
"=",
"$",
"this",
"->",
"_getCount",
"(",
"$",
"config",
",",
"$",
"countOriginalConditions",
")",
";",
"}",
"if",
"(",
"$",
"count",
"!==",
"false",
")",
"{",
"$",
"assoc",
"->",
"getTarget",
"(",
")",
"->",
"updateAll",
"(",
"[",
"$",
"field",
"=>",
"$",
"count",
"]",
",",
"$",
"updateOriginalConditions",
")",
";",
"}",
"}",
"}",
"}"
] | Updates counter cache for a single association
@param \Cake\Event\Event $event Event instance.
@param \Cake\Datasource\EntityInterface $entity Entity
@param \Cake\ORM\Association $assoc The association object
@param array $settings The settings for for counter cache for this association
@return void
@throws \RuntimeException If invalid callable is passed. | [
"Updates",
"counter",
"cache",
"for",
"a",
"single",
"association"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/CounterCacheBehavior.php#L212-L262 |
210,789 | cakephp/cakephp | src/ORM/Behavior/CounterCacheBehavior.php | CounterCacheBehavior._getCount | protected function _getCount(array $config, array $conditions)
{
$finder = 'all';
if (!empty($config['finder'])) {
$finder = $config['finder'];
unset($config['finder']);
}
if (!isset($config['conditions'])) {
$config['conditions'] = [];
}
$config['conditions'] = array_merge($conditions, $config['conditions']);
$query = $this->_table->find($finder, $config);
return $query->count();
} | php | protected function _getCount(array $config, array $conditions)
{
$finder = 'all';
if (!empty($config['finder'])) {
$finder = $config['finder'];
unset($config['finder']);
}
if (!isset($config['conditions'])) {
$config['conditions'] = [];
}
$config['conditions'] = array_merge($conditions, $config['conditions']);
$query = $this->_table->find($finder, $config);
return $query->count();
} | [
"protected",
"function",
"_getCount",
"(",
"array",
"$",
"config",
",",
"array",
"$",
"conditions",
")",
"{",
"$",
"finder",
"=",
"'all'",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"config",
"[",
"'finder'",
"]",
")",
")",
"{",
"$",
"finder",
"=",
"$",
"config",
"[",
"'finder'",
"]",
";",
"unset",
"(",
"$",
"config",
"[",
"'finder'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'conditions'",
"]",
")",
")",
"{",
"$",
"config",
"[",
"'conditions'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"config",
"[",
"'conditions'",
"]",
"=",
"array_merge",
"(",
"$",
"conditions",
",",
"$",
"config",
"[",
"'conditions'",
"]",
")",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"_table",
"->",
"find",
"(",
"$",
"finder",
",",
"$",
"config",
")",
";",
"return",
"$",
"query",
"->",
"count",
"(",
")",
";",
"}"
] | Fetches and returns the count for a single field in an association
@param array $config The counter cache configuration for a single field
@param array $conditions Additional conditions given to the query
@return int The number of relations matching the given config and conditions | [
"Fetches",
"and",
"returns",
"the",
"count",
"for",
"a",
"single",
"field",
"in",
"an",
"association"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/CounterCacheBehavior.php#L271-L286 |
210,790 | cakephp/cakephp | src/ORM/Query.php | Query.selectAllExcept | public function selectAllExcept($table, array $excludedFields, $overwrite = false)
{
if ($table instanceof Association) {
$table = $table->getTarget();
}
if (!($table instanceof Table)) {
throw new \InvalidArgumentException('You must provide either an Association or a Table object');
}
$fields = array_diff($table->getSchema()->columns(), $excludedFields);
$aliasedFields = $this->aliasFields($fields);
return $this->select($aliasedFields, $overwrite);
} | php | public function selectAllExcept($table, array $excludedFields, $overwrite = false)
{
if ($table instanceof Association) {
$table = $table->getTarget();
}
if (!($table instanceof Table)) {
throw new \InvalidArgumentException('You must provide either an Association or a Table object');
}
$fields = array_diff($table->getSchema()->columns(), $excludedFields);
$aliasedFields = $this->aliasFields($fields);
return $this->select($aliasedFields, $overwrite);
} | [
"public",
"function",
"selectAllExcept",
"(",
"$",
"table",
",",
"array",
"$",
"excludedFields",
",",
"$",
"overwrite",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"table",
"instanceof",
"Association",
")",
"{",
"$",
"table",
"=",
"$",
"table",
"->",
"getTarget",
"(",
")",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"table",
"instanceof",
"Table",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'You must provide either an Association or a Table object'",
")",
";",
"}",
"$",
"fields",
"=",
"array_diff",
"(",
"$",
"table",
"->",
"getSchema",
"(",
")",
"->",
"columns",
"(",
")",
",",
"$",
"excludedFields",
")",
";",
"$",
"aliasedFields",
"=",
"$",
"this",
"->",
"aliasFields",
"(",
"$",
"fields",
")",
";",
"return",
"$",
"this",
"->",
"select",
"(",
"$",
"aliasedFields",
",",
"$",
"overwrite",
")",
";",
"}"
] | All the fields associated with the passed table except the excluded
fields will be added to the select clause of the query. Passed excluded fields should not be aliased.
After the first call to this method, a second call cannot be used to remove fields that have already
been added to the query by the first. If you need to change the list after the first call,
pass overwrite boolean true which will reset the select clause removing all previous additions.
@param \Cake\ORM\Table|\Cake\ORM\Association $table The table to use to get an array of columns
@param array $excludedFields The un-aliased column names you do not want selected from $table
@param bool $overwrite Whether to reset/remove previous selected fields
@return Query
@throws \InvalidArgumentException If Association|Table is not passed in first argument | [
"All",
"the",
"fields",
"associated",
"with",
"the",
"passed",
"table",
"except",
"the",
"excluded",
"fields",
"will",
"be",
"added",
"to",
"the",
"select",
"clause",
"of",
"the",
"query",
".",
"Passed",
"excluded",
"fields",
"should",
"not",
"be",
"aliased",
".",
"After",
"the",
"first",
"call",
"to",
"this",
"method",
"a",
"second",
"call",
"cannot",
"be",
"used",
"to",
"remove",
"fields",
"that",
"have",
"already",
"been",
"added",
"to",
"the",
"query",
"by",
"the",
"first",
".",
"If",
"you",
"need",
"to",
"change",
"the",
"list",
"after",
"the",
"first",
"call",
"pass",
"overwrite",
"boolean",
"true",
"which",
"will",
"reset",
"the",
"select",
"clause",
"removing",
"all",
"previous",
"additions",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Query.php#L239-L253 |
210,791 | cakephp/cakephp | src/ORM/Query.php | Query.addDefaultTypes | public function addDefaultTypes(Table $table)
{
$alias = $table->getAlias();
$map = $table->getSchema()->typeMap();
$fields = [];
foreach ($map as $f => $type) {
$fields[$f] = $fields[$alias . '.' . $f] = $fields[$alias . '__' . $f] = $type;
}
$this->getTypeMap()->addDefaults($fields);
return $this;
} | php | public function addDefaultTypes(Table $table)
{
$alias = $table->getAlias();
$map = $table->getSchema()->typeMap();
$fields = [];
foreach ($map as $f => $type) {
$fields[$f] = $fields[$alias . '.' . $f] = $fields[$alias . '__' . $f] = $type;
}
$this->getTypeMap()->addDefaults($fields);
return $this;
} | [
"public",
"function",
"addDefaultTypes",
"(",
"Table",
"$",
"table",
")",
"{",
"$",
"alias",
"=",
"$",
"table",
"->",
"getAlias",
"(",
")",
";",
"$",
"map",
"=",
"$",
"table",
"->",
"getSchema",
"(",
")",
"->",
"typeMap",
"(",
")",
";",
"$",
"fields",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"map",
"as",
"$",
"f",
"=>",
"$",
"type",
")",
"{",
"$",
"fields",
"[",
"$",
"f",
"]",
"=",
"$",
"fields",
"[",
"$",
"alias",
".",
"'.'",
".",
"$",
"f",
"]",
"=",
"$",
"fields",
"[",
"$",
"alias",
".",
"'__'",
".",
"$",
"f",
"]",
"=",
"$",
"type",
";",
"}",
"$",
"this",
"->",
"getTypeMap",
"(",
")",
"->",
"addDefaults",
"(",
"$",
"fields",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Hints this object to associate the correct types when casting conditions
for the database. This is done by extracting the field types from the schema
associated to the passed table object. This prevents the user from repeating
themselves when specifying conditions.
This method returns the same query object for chaining.
@param \Cake\ORM\Table $table The table to pull types from
@return $this | [
"Hints",
"this",
"object",
"to",
"associate",
"the",
"correct",
"types",
"when",
"casting",
"conditions",
"for",
"the",
"database",
".",
"This",
"is",
"done",
"by",
"extracting",
"the",
"field",
"types",
"from",
"the",
"schema",
"associated",
"to",
"the",
"passed",
"table",
"object",
".",
"This",
"prevents",
"the",
"user",
"from",
"repeating",
"themselves",
"when",
"specifying",
"conditions",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Query.php#L266-L277 |
210,792 | cakephp/cakephp | src/ORM/Query.php | Query.eagerLoader | public function eagerLoader(EagerLoader $instance = null)
{
deprecationWarning(
'Query::eagerLoader() is deprecated. ' .
'Use setEagerLoader()/getEagerLoader() instead.'
);
if ($instance !== null) {
return $this->setEagerLoader($instance);
}
return $this->getEagerLoader();
} | php | public function eagerLoader(EagerLoader $instance = null)
{
deprecationWarning(
'Query::eagerLoader() is deprecated. ' .
'Use setEagerLoader()/getEagerLoader() instead.'
);
if ($instance !== null) {
return $this->setEagerLoader($instance);
}
return $this->getEagerLoader();
} | [
"public",
"function",
"eagerLoader",
"(",
"EagerLoader",
"$",
"instance",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"'Query::eagerLoader() is deprecated. '",
".",
"'Use setEagerLoader()/getEagerLoader() instead.'",
")",
";",
"if",
"(",
"$",
"instance",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"setEagerLoader",
"(",
"$",
"instance",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getEagerLoader",
"(",
")",
";",
"}"
] | Sets the instance of the eager loader class to use for loading associations
and storing containments. If called with no arguments, it will return the
currently configured instance.
@deprecated 3.4.0 Use setEagerLoader()/getEagerLoader() instead.
@param \Cake\ORM\EagerLoader|null $instance The eager loader to use. Pass null
to get the current eagerloader.
@return \Cake\ORM\EagerLoader|$this | [
"Sets",
"the",
"instance",
"of",
"the",
"eager",
"loader",
"class",
"to",
"use",
"for",
"loading",
"associations",
"and",
"storing",
"containments",
".",
"If",
"called",
"with",
"no",
"arguments",
"it",
"will",
"return",
"the",
"currently",
"configured",
"instance",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Query.php#L317-L328 |
210,793 | cakephp/cakephp | src/ORM/Query.php | Query.contain | public function contain($associations = null, $override = false)
{
$loader = $this->getEagerLoader();
if ($override === true) {
$this->clearContain();
}
if ($associations === null) {
deprecationWarning(
'Using Query::contain() as getter is deprecated. ' .
'Use getContain() instead.'
);
return $loader->getContain();
}
$queryBuilder = null;
if (is_callable($override)) {
$queryBuilder = $override;
}
if ($associations) {
$loader->contain($associations, $queryBuilder);
}
$this->_addAssociationsToTypeMap(
$this->getRepository(),
$this->getTypeMap(),
$loader->getContain()
);
return $this;
} | php | public function contain($associations = null, $override = false)
{
$loader = $this->getEagerLoader();
if ($override === true) {
$this->clearContain();
}
if ($associations === null) {
deprecationWarning(
'Using Query::contain() as getter is deprecated. ' .
'Use getContain() instead.'
);
return $loader->getContain();
}
$queryBuilder = null;
if (is_callable($override)) {
$queryBuilder = $override;
}
if ($associations) {
$loader->contain($associations, $queryBuilder);
}
$this->_addAssociationsToTypeMap(
$this->getRepository(),
$this->getTypeMap(),
$loader->getContain()
);
return $this;
} | [
"public",
"function",
"contain",
"(",
"$",
"associations",
"=",
"null",
",",
"$",
"override",
"=",
"false",
")",
"{",
"$",
"loader",
"=",
"$",
"this",
"->",
"getEagerLoader",
"(",
")",
";",
"if",
"(",
"$",
"override",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"clearContain",
"(",
")",
";",
"}",
"if",
"(",
"$",
"associations",
"===",
"null",
")",
"{",
"deprecationWarning",
"(",
"'Using Query::contain() as getter is deprecated. '",
".",
"'Use getContain() instead.'",
")",
";",
"return",
"$",
"loader",
"->",
"getContain",
"(",
")",
";",
"}",
"$",
"queryBuilder",
"=",
"null",
";",
"if",
"(",
"is_callable",
"(",
"$",
"override",
")",
")",
"{",
"$",
"queryBuilder",
"=",
"$",
"override",
";",
"}",
"if",
"(",
"$",
"associations",
")",
"{",
"$",
"loader",
"->",
"contain",
"(",
"$",
"associations",
",",
"$",
"queryBuilder",
")",
";",
"}",
"$",
"this",
"->",
"_addAssociationsToTypeMap",
"(",
"$",
"this",
"->",
"getRepository",
"(",
")",
",",
"$",
"this",
"->",
"getTypeMap",
"(",
")",
",",
"$",
"loader",
"->",
"getContain",
"(",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the list of associations that should be eagerly loaded along with this
query. The list of associated tables passed must have been previously set as
associations using the Table API.
### Example:
```
// Bring articles' author information
$query->contain('Author');
// Also bring the category and tags associated to each article
$query->contain(['Category', 'Tag']);
```
Associations can be arbitrarily nested using dot notation or nested arrays,
this allows this object to calculate joins or any additional queries that
must be executed to bring the required associated data.
### Example:
```
// Eager load the product info, and for each product load other 2 associations
$query->contain(['Product' => ['Manufacturer', 'Distributor']);
// Which is equivalent to calling
$query->contain(['Products.Manufactures', 'Products.Distributors']);
// For an author query, load his region, state and country
$query->contain('Regions.States.Countries');
```
It is possible to control the conditions and fields selected for each of the
contained associations:
### Example:
```
$query->contain(['Tags' => function ($q) {
return $q->where(['Tags.is_popular' => true]);
}]);
$query->contain(['Products.Manufactures' => function ($q) {
return $q->select(['name'])->where(['Manufactures.active' => true]);
}]);
```
Each association might define special options when eager loaded, the allowed
options that can be set per association are:
- `foreignKey`: Used to set a different field to match both tables, if set to false
no join conditions will be generated automatically. `false` can only be used on
joinable associations and cannot be used with hasMany or belongsToMany associations.
- `fields`: An array with the fields that should be fetched from the association.
- `finder`: The finder to use when loading associated records. Either the name of the
finder as a string, or an array to define options to pass to the finder.
- `queryBuilder`: Equivalent to passing a callable instead of an options array.
### Example:
```
// Set options for the hasMany articles that will be eagerly loaded for an author
$query->contain([
'Articles' => [
'fields' => ['title', 'author_id']
]
]);
```
Finders can be configured to use options.
```
// Retrieve translations for the articles, but only those for the `en` and `es` locales
$query->contain([
'Articles' => [
'finder' => [
'translations' => [
'locales' => ['en', 'es']
]
]
]
]);
```
When containing associations, it is important to include foreign key columns.
Failing to do so will trigger exceptions.
```
// Use a query builder to add conditions to the containment
$query->contain('Authors', function ($q) {
return $q->where(...); // add conditions
});
// Use special join conditions for multiple containments in the same method call
$query->contain([
'Authors' => [
'foreignKey' => false,
'queryBuilder' => function ($q) {
return $q->where(...); // Add full filtering conditions
}
],
'Tags' => function ($q) {
return $q->where(...); // add conditions
}
]);
```
If called with no arguments, this function will return an array with
with the list of previously configured associations to be contained in the
result. This getter part is deprecated as of 3.6.0. Use getContain() instead.
If called with an empty first argument and `$override` is set to true, the
previous list will be emptied.
@param array|string|null $associations List of table aliases to be queried.
@param callable|bool $override The query builder for the association, or
if associations is an array, a bool on whether to override previous list
with the one passed
defaults to merging previous list with the new one.
@return array|$this | [
"Sets",
"the",
"list",
"of",
"associations",
"that",
"should",
"be",
"eagerly",
"loaded",
"along",
"with",
"this",
"query",
".",
"The",
"list",
"of",
"associated",
"tables",
"passed",
"must",
"have",
"been",
"previously",
"set",
"as",
"associations",
"using",
"the",
"Table",
"API",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Query.php#L450-L481 |
210,794 | cakephp/cakephp | src/ORM/Query.php | Query._addAssociationsToTypeMap | protected function _addAssociationsToTypeMap($table, $typeMap, $associations)
{
foreach ($associations as $name => $nested) {
if (!$table->hasAssociation($name)) {
continue;
}
$association = $table->getAssociation($name);
$target = $association->getTarget();
$primary = (array)$target->getPrimaryKey();
if (empty($primary) || $typeMap->type($target->aliasField($primary[0])) === null) {
$this->addDefaultTypes($target);
}
if (!empty($nested)) {
$this->_addAssociationsToTypeMap($target, $typeMap, $nested);
}
}
} | php | protected function _addAssociationsToTypeMap($table, $typeMap, $associations)
{
foreach ($associations as $name => $nested) {
if (!$table->hasAssociation($name)) {
continue;
}
$association = $table->getAssociation($name);
$target = $association->getTarget();
$primary = (array)$target->getPrimaryKey();
if (empty($primary) || $typeMap->type($target->aliasField($primary[0])) === null) {
$this->addDefaultTypes($target);
}
if (!empty($nested)) {
$this->_addAssociationsToTypeMap($target, $typeMap, $nested);
}
}
} | [
"protected",
"function",
"_addAssociationsToTypeMap",
"(",
"$",
"table",
",",
"$",
"typeMap",
",",
"$",
"associations",
")",
"{",
"foreach",
"(",
"$",
"associations",
"as",
"$",
"name",
"=>",
"$",
"nested",
")",
"{",
"if",
"(",
"!",
"$",
"table",
"->",
"hasAssociation",
"(",
"$",
"name",
")",
")",
"{",
"continue",
";",
"}",
"$",
"association",
"=",
"$",
"table",
"->",
"getAssociation",
"(",
"$",
"name",
")",
";",
"$",
"target",
"=",
"$",
"association",
"->",
"getTarget",
"(",
")",
";",
"$",
"primary",
"=",
"(",
"array",
")",
"$",
"target",
"->",
"getPrimaryKey",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"primary",
")",
"||",
"$",
"typeMap",
"->",
"type",
"(",
"$",
"target",
"->",
"aliasField",
"(",
"$",
"primary",
"[",
"0",
"]",
")",
")",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"addDefaultTypes",
"(",
"$",
"target",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"nested",
")",
")",
"{",
"$",
"this",
"->",
"_addAssociationsToTypeMap",
"(",
"$",
"target",
",",
"$",
"typeMap",
",",
"$",
"nested",
")",
";",
"}",
"}",
"}"
] | Used to recursively add contained association column types to
the query.
@param \Cake\ORM\Table $table The table instance to pluck associations from.
@param \Cake\Database\TypeMap $typeMap The typemap to check for columns in.
This typemap is indirectly mutated via Cake\ORM\Query::addDefaultTypes()
@param array $associations The nested tree of associations to walk.
@return void | [
"Used",
"to",
"recursively",
"add",
"contained",
"association",
"column",
"types",
"to",
"the",
"query",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Query.php#L514-L530 |
210,795 | cakephp/cakephp | src/ORM/Query.php | Query.matching | public function matching($assoc, callable $builder = null)
{
$result = $this->getEagerLoader()->setMatching($assoc, $builder)->getMatching();
$this->_addAssociationsToTypeMap($this->getRepository(), $this->getTypeMap(), $result);
$this->_dirty();
return $this;
} | php | public function matching($assoc, callable $builder = null)
{
$result = $this->getEagerLoader()->setMatching($assoc, $builder)->getMatching();
$this->_addAssociationsToTypeMap($this->getRepository(), $this->getTypeMap(), $result);
$this->_dirty();
return $this;
} | [
"public",
"function",
"matching",
"(",
"$",
"assoc",
",",
"callable",
"$",
"builder",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getEagerLoader",
"(",
")",
"->",
"setMatching",
"(",
"$",
"assoc",
",",
"$",
"builder",
")",
"->",
"getMatching",
"(",
")",
";",
"$",
"this",
"->",
"_addAssociationsToTypeMap",
"(",
"$",
"this",
"->",
"getRepository",
"(",
")",
",",
"$",
"this",
"->",
"getTypeMap",
"(",
")",
",",
"$",
"result",
")",
";",
"$",
"this",
"->",
"_dirty",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Adds filtering conditions to this query to only bring rows that have a relation
to another from an associated table, based on conditions in the associated table.
This function will add entries in the `contain` graph.
### Example:
```
// Bring only articles that were tagged with 'cake'
$query->matching('Tags', function ($q) {
return $q->where(['name' => 'cake']);
);
```
It is possible to filter by deep associations by using dot notation:
### Example:
```
// Bring only articles that were commented by 'markstory'
$query->matching('Comments.Users', function ($q) {
return $q->where(['username' => 'markstory']);
);
```
As this function will create `INNER JOIN`, you might want to consider
calling `distinct` on this query as you might get duplicate rows if
your conditions don't filter them already. This might be the case, for example,
of the same user commenting more than once in the same article.
### Example:
```
// Bring unique articles that were commented by 'markstory'
$query->distinct(['Articles.id'])
->matching('Comments.Users', function ($q) {
return $q->where(['username' => 'markstory']);
);
```
Please note that the query passed to the closure will only accept calling
`select`, `where`, `andWhere` and `orWhere` on it. If you wish to
add more complex clauses you can do it directly in the main query.
@param string $assoc The association to filter by
@param callable|null $builder a function that will receive a pre-made query object
that can be used to add custom conditions or selecting some fields
@return $this | [
"Adds",
"filtering",
"conditions",
"to",
"this",
"query",
"to",
"only",
"bring",
"rows",
"that",
"have",
"a",
"relation",
"to",
"another",
"from",
"an",
"associated",
"table",
"based",
"on",
"conditions",
"in",
"the",
"associated",
"table",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Query.php#L582-L589 |
210,796 | cakephp/cakephp | src/ORM/Query.php | Query.leftJoinWith | public function leftJoinWith($assoc, callable $builder = null)
{
$result = $this->getEagerLoader()
->setMatching($assoc, $builder, [
'joinType' => QueryInterface::JOIN_TYPE_LEFT,
'fields' => false
])
->getMatching();
$this->_addAssociationsToTypeMap($this->getRepository(), $this->getTypeMap(), $result);
$this->_dirty();
return $this;
} | php | public function leftJoinWith($assoc, callable $builder = null)
{
$result = $this->getEagerLoader()
->setMatching($assoc, $builder, [
'joinType' => QueryInterface::JOIN_TYPE_LEFT,
'fields' => false
])
->getMatching();
$this->_addAssociationsToTypeMap($this->getRepository(), $this->getTypeMap(), $result);
$this->_dirty();
return $this;
} | [
"public",
"function",
"leftJoinWith",
"(",
"$",
"assoc",
",",
"callable",
"$",
"builder",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getEagerLoader",
"(",
")",
"->",
"setMatching",
"(",
"$",
"assoc",
",",
"$",
"builder",
",",
"[",
"'joinType'",
"=>",
"QueryInterface",
"::",
"JOIN_TYPE_LEFT",
",",
"'fields'",
"=>",
"false",
"]",
")",
"->",
"getMatching",
"(",
")",
";",
"$",
"this",
"->",
"_addAssociationsToTypeMap",
"(",
"$",
"this",
"->",
"getRepository",
"(",
")",
",",
"$",
"this",
"->",
"getTypeMap",
"(",
")",
",",
"$",
"result",
")",
";",
"$",
"this",
"->",
"_dirty",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Creates a LEFT JOIN with the passed association table while preserving
the foreign key matching and the custom conditions that were originally set
for it.
This function will add entries in the `contain` graph.
### Example:
```
// Get the count of articles per user
$usersQuery
->select(['total_articles' => $query->func()->count('Articles.id')])
->leftJoinWith('Articles')
->group(['Users.id'])
->enableAutoFields(true);
```
You can also customize the conditions passed to the LEFT JOIN:
```
// Get the count of articles per user with at least 5 votes
$usersQuery
->select(['total_articles' => $query->func()->count('Articles.id')])
->leftJoinWith('Articles', function ($q) {
return $q->where(['Articles.votes >=' => 5]);
})
->group(['Users.id'])
->enableAutoFields(true);
```
This will create the following SQL:
```
SELECT COUNT(Articles.id) AS total_articles, Users.*
FROM users Users
LEFT JOIN articles Articles ON Articles.user_id = Users.id AND Articles.votes >= 5
GROUP BY USers.id
```
It is possible to left join deep associations by using dot notation
### Example:
```
// Total comments in articles by 'markstory'
$query
->select(['total_comments' => $query->func()->count('Comments.id')])
->leftJoinWith('Comments.Users', function ($q) {
return $q->where(['username' => 'markstory']);
)
->group(['Users.id']);
```
Please note that the query passed to the closure will only accept calling
`select`, `where`, `andWhere` and `orWhere` on it. If you wish to
add more complex clauses you can do it directly in the main query.
@param string $assoc The association to join with
@param callable|null $builder a function that will receive a pre-made query object
that can be used to add custom conditions or selecting some fields
@return $this | [
"Creates",
"a",
"LEFT",
"JOIN",
"with",
"the",
"passed",
"association",
"table",
"while",
"preserving",
"the",
"foreign",
"key",
"matching",
"and",
"the",
"custom",
"conditions",
"that",
"were",
"originally",
"set",
"for",
"it",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Query.php#L654-L666 |
210,797 | cakephp/cakephp | src/ORM/Query.php | Query.innerJoinWith | public function innerJoinWith($assoc, callable $builder = null)
{
$result = $this->getEagerLoader()
->setMatching($assoc, $builder, [
'joinType' => QueryInterface::JOIN_TYPE_INNER,
'fields' => false
])
->getMatching();
$this->_addAssociationsToTypeMap($this->getRepository(), $this->getTypeMap(), $result);
$this->_dirty();
return $this;
} | php | public function innerJoinWith($assoc, callable $builder = null)
{
$result = $this->getEagerLoader()
->setMatching($assoc, $builder, [
'joinType' => QueryInterface::JOIN_TYPE_INNER,
'fields' => false
])
->getMatching();
$this->_addAssociationsToTypeMap($this->getRepository(), $this->getTypeMap(), $result);
$this->_dirty();
return $this;
} | [
"public",
"function",
"innerJoinWith",
"(",
"$",
"assoc",
",",
"callable",
"$",
"builder",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getEagerLoader",
"(",
")",
"->",
"setMatching",
"(",
"$",
"assoc",
",",
"$",
"builder",
",",
"[",
"'joinType'",
"=>",
"QueryInterface",
"::",
"JOIN_TYPE_INNER",
",",
"'fields'",
"=>",
"false",
"]",
")",
"->",
"getMatching",
"(",
")",
";",
"$",
"this",
"->",
"_addAssociationsToTypeMap",
"(",
"$",
"this",
"->",
"getRepository",
"(",
")",
",",
"$",
"this",
"->",
"getTypeMap",
"(",
")",
",",
"$",
"result",
")",
";",
"$",
"this",
"->",
"_dirty",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Creates an INNER JOIN with the passed association table while preserving
the foreign key matching and the custom conditions that were originally set
for it.
This function will add entries in the `contain` graph.
### Example:
```
// Bring only articles that were tagged with 'cake'
$query->innerJoinWith('Tags', function ($q) {
return $q->where(['name' => 'cake']);
);
```
This will create the following SQL:
```
SELECT Articles.*
FROM articles Articles
INNER JOIN tags Tags ON Tags.name = 'cake'
INNER JOIN articles_tags ArticlesTags ON ArticlesTags.tag_id = Tags.id
AND ArticlesTags.articles_id = Articles.id
```
This function works the same as `matching()` with the difference that it
will select no fields from the association.
@param string $assoc The association to join with
@param callable|null $builder a function that will receive a pre-made query object
that can be used to add custom conditions or selecting some fields
@return $this
@see \Cake\ORM\Query::matching() | [
"Creates",
"an",
"INNER",
"JOIN",
"with",
"the",
"passed",
"association",
"table",
"while",
"preserving",
"the",
"foreign",
"key",
"matching",
"and",
"the",
"custom",
"conditions",
"that",
"were",
"originally",
"set",
"for",
"it",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Query.php#L703-L715 |
210,798 | cakephp/cakephp | src/ORM/Query.php | Query.cleanCopy | public function cleanCopy()
{
$clone = clone $this;
$clone->setEagerLoader(clone $this->getEagerLoader());
$clone->triggerBeforeFind();
$clone->enableAutoFields(false);
$clone->limit(null);
$clone->order([], true);
$clone->offset(null);
$clone->mapReduce(null, null, true);
$clone->formatResults(null, true);
$clone->setSelectTypeMap(new TypeMap());
$clone->decorateResults(null, true);
return $clone;
} | php | public function cleanCopy()
{
$clone = clone $this;
$clone->setEagerLoader(clone $this->getEagerLoader());
$clone->triggerBeforeFind();
$clone->enableAutoFields(false);
$clone->limit(null);
$clone->order([], true);
$clone->offset(null);
$clone->mapReduce(null, null, true);
$clone->formatResults(null, true);
$clone->setSelectTypeMap(new TypeMap());
$clone->decorateResults(null, true);
return $clone;
} | [
"public",
"function",
"cleanCopy",
"(",
")",
"{",
"$",
"clone",
"=",
"clone",
"$",
"this",
";",
"$",
"clone",
"->",
"setEagerLoader",
"(",
"clone",
"$",
"this",
"->",
"getEagerLoader",
"(",
")",
")",
";",
"$",
"clone",
"->",
"triggerBeforeFind",
"(",
")",
";",
"$",
"clone",
"->",
"enableAutoFields",
"(",
"false",
")",
";",
"$",
"clone",
"->",
"limit",
"(",
"null",
")",
";",
"$",
"clone",
"->",
"order",
"(",
"[",
"]",
",",
"true",
")",
";",
"$",
"clone",
"->",
"offset",
"(",
"null",
")",
";",
"$",
"clone",
"->",
"mapReduce",
"(",
"null",
",",
"null",
",",
"true",
")",
";",
"$",
"clone",
"->",
"formatResults",
"(",
"null",
",",
"true",
")",
";",
"$",
"clone",
"->",
"setSelectTypeMap",
"(",
"new",
"TypeMap",
"(",
")",
")",
";",
"$",
"clone",
"->",
"decorateResults",
"(",
"null",
",",
"true",
")",
";",
"return",
"$",
"clone",
";",
"}"
] | Creates a copy of this current query, triggers beforeFind and resets some state.
The following state will be cleared:
- autoFields
- limit
- offset
- map/reduce functions
- result formatters
- order
- containments
This method creates query clones that are useful when working with subqueries.
@return \Cake\ORM\Query | [
"Creates",
"a",
"copy",
"of",
"this",
"current",
"query",
"triggers",
"beforeFind",
"and",
"resets",
"some",
"state",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Query.php#L864-L879 |
210,799 | cakephp/cakephp | src/ORM/Query.php | Query._execute | protected function _execute()
{
$this->triggerBeforeFind();
if ($this->_results) {
$decorator = $this->_decoratorClass();
return new $decorator($this->_results);
}
$statement = $this->getEagerLoader()->loadExternal($this, $this->execute());
return new ResultSet($this, $statement);
} | php | protected function _execute()
{
$this->triggerBeforeFind();
if ($this->_results) {
$decorator = $this->_decoratorClass();
return new $decorator($this->_results);
}
$statement = $this->getEagerLoader()->loadExternal($this, $this->execute());
return new ResultSet($this, $statement);
} | [
"protected",
"function",
"_execute",
"(",
")",
"{",
"$",
"this",
"->",
"triggerBeforeFind",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_results",
")",
"{",
"$",
"decorator",
"=",
"$",
"this",
"->",
"_decoratorClass",
"(",
")",
";",
"return",
"new",
"$",
"decorator",
"(",
"$",
"this",
"->",
"_results",
")",
";",
"}",
"$",
"statement",
"=",
"$",
"this",
"->",
"getEagerLoader",
"(",
")",
"->",
"loadExternal",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"execute",
"(",
")",
")",
";",
"return",
"new",
"ResultSet",
"(",
"$",
"this",
",",
"$",
"statement",
")",
";",
"}"
] | Executes this query and returns a ResultSet object containing the results.
This will also setup the correct statement class in order to eager load deep
associations.
@return \Cake\ORM\ResultSet | [
"Executes",
"this",
"query",
"and",
"returns",
"a",
"ResultSet",
"object",
"containing",
"the",
"results",
".",
"This",
"will",
"also",
"setup",
"the",
"correct",
"statement",
"class",
"in",
"order",
"to",
"eager",
"load",
"deep",
"associations",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Query.php#L1132-L1144 |
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.