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,800 | cakephp/cakephp | src/ORM/Query.php | Query._transformQuery | protected function _transformQuery()
{
if (!$this->_dirty || $this->_type !== 'select') {
return;
}
/** @var \Cake\ORM\Table $repository */
$repository = $this->getRepository();
if (empty($this->_parts['from'])) {
$this->from([$repository->getAlias() => $repository->getTable()]);
}
$this->_addDefaultFields();
$this->getEagerLoader()->attachAssociations($this, $repository, !$this->_hasFields);
$this->_addDefaultSelectTypes();
} | php | protected function _transformQuery()
{
if (!$this->_dirty || $this->_type !== 'select') {
return;
}
/** @var \Cake\ORM\Table $repository */
$repository = $this->getRepository();
if (empty($this->_parts['from'])) {
$this->from([$repository->getAlias() => $repository->getTable()]);
}
$this->_addDefaultFields();
$this->getEagerLoader()->attachAssociations($this, $repository, !$this->_hasFields);
$this->_addDefaultSelectTypes();
} | [
"protected",
"function",
"_transformQuery",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_dirty",
"||",
"$",
"this",
"->",
"_type",
"!==",
"'select'",
")",
"{",
"return",
";",
"}",
"/** @var \\Cake\\ORM\\Table $repository */",
"$",
"repository",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_parts",
"[",
"'from'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"from",
"(",
"[",
"$",
"repository",
"->",
"getAlias",
"(",
")",
"=>",
"$",
"repository",
"->",
"getTable",
"(",
")",
"]",
")",
";",
"}",
"$",
"this",
"->",
"_addDefaultFields",
"(",
")",
";",
"$",
"this",
"->",
"getEagerLoader",
"(",
")",
"->",
"attachAssociations",
"(",
"$",
"this",
",",
"$",
"repository",
",",
"!",
"$",
"this",
"->",
"_hasFields",
")",
";",
"$",
"this",
"->",
"_addDefaultSelectTypes",
"(",
")",
";",
"}"
] | Applies some defaults to the query object before it is executed.
Specifically add the FROM clause, adds default table fields if none are
specified and applies the joins required to eager load associations defined
using `contain`
It also sets the default types for the columns in the select clause
@see \Cake\Database\Query::execute()
@return void | [
"Applies",
"some",
"defaults",
"to",
"the",
"query",
"object",
"before",
"it",
"is",
"executed",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Query.php#L1158-L1173 |
210,801 | cakephp/cakephp | src/ORM/Query.php | Query._addDefaultFields | protected function _addDefaultFields()
{
$select = $this->clause('select');
$this->_hasFields = true;
/** @var \Cake\ORM\Table $repository */
$repository = $this->getRepository();
if (!count($select) || $this->_autoFields === true) {
$this->_hasFields = false;
$this->select($repository->getSchema()->columns());
$select = $this->clause('select');
}
$aliased = $this->aliasFields($select, $repository->getAlias());
$this->select($aliased, true);
} | php | protected function _addDefaultFields()
{
$select = $this->clause('select');
$this->_hasFields = true;
/** @var \Cake\ORM\Table $repository */
$repository = $this->getRepository();
if (!count($select) || $this->_autoFields === true) {
$this->_hasFields = false;
$this->select($repository->getSchema()->columns());
$select = $this->clause('select');
}
$aliased = $this->aliasFields($select, $repository->getAlias());
$this->select($aliased, true);
} | [
"protected",
"function",
"_addDefaultFields",
"(",
")",
"{",
"$",
"select",
"=",
"$",
"this",
"->",
"clause",
"(",
"'select'",
")",
";",
"$",
"this",
"->",
"_hasFields",
"=",
"true",
";",
"/** @var \\Cake\\ORM\\Table $repository */",
"$",
"repository",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
";",
"if",
"(",
"!",
"count",
"(",
"$",
"select",
")",
"||",
"$",
"this",
"->",
"_autoFields",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"_hasFields",
"=",
"false",
";",
"$",
"this",
"->",
"select",
"(",
"$",
"repository",
"->",
"getSchema",
"(",
")",
"->",
"columns",
"(",
")",
")",
";",
"$",
"select",
"=",
"$",
"this",
"->",
"clause",
"(",
"'select'",
")",
";",
"}",
"$",
"aliased",
"=",
"$",
"this",
"->",
"aliasFields",
"(",
"$",
"select",
",",
"$",
"repository",
"->",
"getAlias",
"(",
")",
")",
";",
"$",
"this",
"->",
"select",
"(",
"$",
"aliased",
",",
"true",
")",
";",
"}"
] | Inspects if there are any set fields for selecting, otherwise adds all
the fields for the default table.
@return void | [
"Inspects",
"if",
"there",
"are",
"any",
"set",
"fields",
"for",
"selecting",
"otherwise",
"adds",
"all",
"the",
"fields",
"for",
"the",
"default",
"table",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Query.php#L1181-L1197 |
210,802 | cakephp/cakephp | src/ORM/Query.php | Query._addDefaultSelectTypes | protected function _addDefaultSelectTypes()
{
$typeMap = $this->getTypeMap()->getDefaults();
$select = $this->clause('select');
$types = [];
foreach ($select as $alias => $value) {
if (isset($typeMap[$alias])) {
$types[$alias] = $typeMap[$alias];
continue;
}
if (is_string($value) && isset($typeMap[$value])) {
$types[$alias] = $typeMap[$value];
}
if ($value instanceof TypedResultInterface) {
$types[$alias] = $value->getReturnType();
}
}
$this->getSelectTypeMap()->addDefaults($types);
} | php | protected function _addDefaultSelectTypes()
{
$typeMap = $this->getTypeMap()->getDefaults();
$select = $this->clause('select');
$types = [];
foreach ($select as $alias => $value) {
if (isset($typeMap[$alias])) {
$types[$alias] = $typeMap[$alias];
continue;
}
if (is_string($value) && isset($typeMap[$value])) {
$types[$alias] = $typeMap[$value];
}
if ($value instanceof TypedResultInterface) {
$types[$alias] = $value->getReturnType();
}
}
$this->getSelectTypeMap()->addDefaults($types);
} | [
"protected",
"function",
"_addDefaultSelectTypes",
"(",
")",
"{",
"$",
"typeMap",
"=",
"$",
"this",
"->",
"getTypeMap",
"(",
")",
"->",
"getDefaults",
"(",
")",
";",
"$",
"select",
"=",
"$",
"this",
"->",
"clause",
"(",
"'select'",
")",
";",
"$",
"types",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"select",
"as",
"$",
"alias",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"typeMap",
"[",
"$",
"alias",
"]",
")",
")",
"{",
"$",
"types",
"[",
"$",
"alias",
"]",
"=",
"$",
"typeMap",
"[",
"$",
"alias",
"]",
";",
"continue",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
"&&",
"isset",
"(",
"$",
"typeMap",
"[",
"$",
"value",
"]",
")",
")",
"{",
"$",
"types",
"[",
"$",
"alias",
"]",
"=",
"$",
"typeMap",
"[",
"$",
"value",
"]",
";",
"}",
"if",
"(",
"$",
"value",
"instanceof",
"TypedResultInterface",
")",
"{",
"$",
"types",
"[",
"$",
"alias",
"]",
"=",
"$",
"value",
"->",
"getReturnType",
"(",
")",
";",
"}",
"}",
"$",
"this",
"->",
"getSelectTypeMap",
"(",
")",
"->",
"addDefaults",
"(",
"$",
"types",
")",
";",
"}"
] | Sets the default types for converting the fields in the select clause
@return void | [
"Sets",
"the",
"default",
"types",
"for",
"converting",
"the",
"fields",
"in",
"the",
"select",
"clause"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Query.php#L1204-L1223 |
210,803 | cakephp/cakephp | src/Database/Type/StringType.php | StringType.toDatabase | public function toDatabase($value, Driver $driver)
{
if ($value === null || is_string($value)) {
return $value;
}
if (is_object($value) && method_exists($value, '__toString')) {
return $value->__toString();
}
if (is_scalar($value)) {
return (string)$value;
}
throw new InvalidArgumentException(sprintf(
'Cannot convert value of type `%s` to string',
getTypeName($value)
));
} | php | public function toDatabase($value, Driver $driver)
{
if ($value === null || is_string($value)) {
return $value;
}
if (is_object($value) && method_exists($value, '__toString')) {
return $value->__toString();
}
if (is_scalar($value)) {
return (string)$value;
}
throw new InvalidArgumentException(sprintf(
'Cannot convert value of type `%s` to string',
getTypeName($value)
));
} | [
"public",
"function",
"toDatabase",
"(",
"$",
"value",
",",
"Driver",
"$",
"driver",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
"||",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
"&&",
"method_exists",
"(",
"$",
"value",
",",
"'__toString'",
")",
")",
"{",
"return",
"$",
"value",
"->",
"__toString",
"(",
")",
";",
"}",
"if",
"(",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"return",
"(",
"string",
")",
"$",
"value",
";",
"}",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Cannot convert value of type `%s` to string'",
",",
"getTypeName",
"(",
"$",
"value",
")",
")",
")",
";",
"}"
] | Convert string data into the database format.
@param mixed $value The value to convert.
@param \Cake\Database\Driver $driver The driver instance to convert with.
@return string|null | [
"Convert",
"string",
"data",
"into",
"the",
"database",
"format",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Type/StringType.php#L38-L56 |
210,804 | cakephp/cakephp | src/View/Helper/BreadcrumbsHelper.php | BreadcrumbsHelper.add | public function add($title, $url = null, array $options = [])
{
if (is_array($title)) {
foreach ($title as $crumb) {
$this->crumbs[] = $crumb + ['title' => '', 'url' => null, 'options' => []];
}
return $this;
}
$this->crumbs[] = compact('title', 'url', 'options');
return $this;
} | php | public function add($title, $url = null, array $options = [])
{
if (is_array($title)) {
foreach ($title as $crumb) {
$this->crumbs[] = $crumb + ['title' => '', 'url' => null, 'options' => []];
}
return $this;
}
$this->crumbs[] = compact('title', 'url', 'options');
return $this;
} | [
"public",
"function",
"add",
"(",
"$",
"title",
",",
"$",
"url",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"title",
")",
")",
"{",
"foreach",
"(",
"$",
"title",
"as",
"$",
"crumb",
")",
"{",
"$",
"this",
"->",
"crumbs",
"[",
"]",
"=",
"$",
"crumb",
"+",
"[",
"'title'",
"=>",
"''",
",",
"'url'",
"=>",
"null",
",",
"'options'",
"=>",
"[",
"]",
"]",
";",
"}",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"crumbs",
"[",
"]",
"=",
"compact",
"(",
"'title'",
",",
"'url'",
",",
"'options'",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add a crumb to the end of the trail.
@param string|array $title If provided as a string, it represents the title of the crumb.
Alternatively, if you want to add multiple crumbs at once, you can provide an array, with each values being a
single crumb. Arrays are expected to be of this form:
- *title* The title of the crumb
- *link* The link of the crumb. If not provided, no link will be made
- *options* Options of the crumb. See description of params option of this method.
@param string|array|null $url URL of the crumb. Either a string, an array of route params to pass to
Url::build() or null / empty if the crumb does not have a link.
@param array $options Array of options. These options will be used as attributes HTML attribute the crumb will
be rendered in (a <li> tag by default). It accepts two special keys:
- *innerAttrs*: An array that allows you to define attributes for the inner element of the crumb (by default, to
the link)
- *templateVars*: Specific template vars in case you override the templates provided.
@return $this | [
"Add",
"a",
"crumb",
"to",
"the",
"end",
"of",
"the",
"trail",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/BreadcrumbsHelper.php#L77-L90 |
210,805 | cakephp/cakephp | src/View/Helper/BreadcrumbsHelper.php | BreadcrumbsHelper.prepend | public function prepend($title, $url = null, array $options = [])
{
if (is_array($title)) {
$crumbs = [];
foreach ($title as $crumb) {
$crumbs[] = $crumb + ['title' => '', 'url' => null, 'options' => []];
}
array_splice($this->crumbs, 0, 0, $crumbs);
return $this;
}
array_unshift($this->crumbs, compact('title', 'url', 'options'));
return $this;
} | php | public function prepend($title, $url = null, array $options = [])
{
if (is_array($title)) {
$crumbs = [];
foreach ($title as $crumb) {
$crumbs[] = $crumb + ['title' => '', 'url' => null, 'options' => []];
}
array_splice($this->crumbs, 0, 0, $crumbs);
return $this;
}
array_unshift($this->crumbs, compact('title', 'url', 'options'));
return $this;
} | [
"public",
"function",
"prepend",
"(",
"$",
"title",
",",
"$",
"url",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"title",
")",
")",
"{",
"$",
"crumbs",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"title",
"as",
"$",
"crumb",
")",
"{",
"$",
"crumbs",
"[",
"]",
"=",
"$",
"crumb",
"+",
"[",
"'title'",
"=>",
"''",
",",
"'url'",
"=>",
"null",
",",
"'options'",
"=>",
"[",
"]",
"]",
";",
"}",
"array_splice",
"(",
"$",
"this",
"->",
"crumbs",
",",
"0",
",",
"0",
",",
"$",
"crumbs",
")",
";",
"return",
"$",
"this",
";",
"}",
"array_unshift",
"(",
"$",
"this",
"->",
"crumbs",
",",
"compact",
"(",
"'title'",
",",
"'url'",
",",
"'options'",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Prepend a crumb to the start of the queue.
@param string $title If provided as a string, it represents the title of the crumb.
Alternatively, if you want to add multiple crumbs at once, you can provide an array, with each values being a
single crumb. Arrays are expected to be of this form:
- *title* The title of the crumb
- *link* The link of the crumb. If not provided, no link will be made
- *options* Options of the crumb. See description of params option of this method.
@param string|array|null $url URL of the crumb. Either a string, an array of route params to pass to
Url::build() or null / empty if the crumb does not have a link.
@param array $options Array of options. These options will be used as attributes HTML attribute the crumb will
be rendered in (a <li> tag by default). It accepts two special keys:
- *innerAttrs*: An array that allows you to define attributes for the inner element of the crumb (by default, to
the link)
- *templateVars*: Specific template vars in case you override the templates provided.
@return $this | [
"Prepend",
"a",
"crumb",
"to",
"the",
"start",
"of",
"the",
"queue",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/BreadcrumbsHelper.php#L110-L126 |
210,806 | cakephp/cakephp | src/View/Helper/BreadcrumbsHelper.php | BreadcrumbsHelper.insertAt | public function insertAt($index, $title, $url = null, array $options = [])
{
if (!isset($this->crumbs[$index])) {
throw new LogicException(sprintf("No crumb could be found at index '%s'", $index));
}
array_splice($this->crumbs, $index, 0, [compact('title', 'url', 'options')]);
return $this;
} | php | public function insertAt($index, $title, $url = null, array $options = [])
{
if (!isset($this->crumbs[$index])) {
throw new LogicException(sprintf("No crumb could be found at index '%s'", $index));
}
array_splice($this->crumbs, $index, 0, [compact('title', 'url', 'options')]);
return $this;
} | [
"public",
"function",
"insertAt",
"(",
"$",
"index",
",",
"$",
"title",
",",
"$",
"url",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"crumbs",
"[",
"$",
"index",
"]",
")",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"sprintf",
"(",
"\"No crumb could be found at index '%s'\"",
",",
"$",
"index",
")",
")",
";",
"}",
"array_splice",
"(",
"$",
"this",
"->",
"crumbs",
",",
"$",
"index",
",",
"0",
",",
"[",
"compact",
"(",
"'title'",
",",
"'url'",
",",
"'options'",
")",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Insert a crumb at a specific index.
If the index already exists, the new crumb will be inserted,
and the existing element will be shifted one index greater.
If the index is out of bounds, it will throw an exception.
@param int $index The index to insert at.
@param string $title Title of the crumb.
@param string|array|null $url URL of the crumb. Either a string, an array of route params to pass to
Url::build() or null / empty if the crumb does not have a link.
@param array $options Array of options. These options will be used as attributes HTML attribute the crumb will
be rendered in (a <li> tag by default). It accepts two special keys:
- *innerAttrs*: An array that allows you to define attributes for the inner element of the crumb (by default, to
the link)
- *templateVars*: Specific template vars in case you override the templates provided.
@return $this
@throws \LogicException In case the index is out of bound | [
"Insert",
"a",
"crumb",
"at",
"a",
"specific",
"index",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/BreadcrumbsHelper.php#L147-L156 |
210,807 | cakephp/cakephp | src/View/Helper/BreadcrumbsHelper.php | BreadcrumbsHelper.insertBefore | public function insertBefore($matchingTitle, $title, $url = null, array $options = [])
{
$key = $this->findCrumb($matchingTitle);
if ($key === null) {
throw new LogicException(sprintf("No crumb matching '%s' could be found.", $matchingTitle));
}
return $this->insertAt($key, $title, $url, $options);
} | php | public function insertBefore($matchingTitle, $title, $url = null, array $options = [])
{
$key = $this->findCrumb($matchingTitle);
if ($key === null) {
throw new LogicException(sprintf("No crumb matching '%s' could be found.", $matchingTitle));
}
return $this->insertAt($key, $title, $url, $options);
} | [
"public",
"function",
"insertBefore",
"(",
"$",
"matchingTitle",
",",
"$",
"title",
",",
"$",
"url",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"findCrumb",
"(",
"$",
"matchingTitle",
")",
";",
"if",
"(",
"$",
"key",
"===",
"null",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"sprintf",
"(",
"\"No crumb matching '%s' could be found.\"",
",",
"$",
"matchingTitle",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"insertAt",
"(",
"$",
"key",
",",
"$",
"title",
",",
"$",
"url",
",",
"$",
"options",
")",
";",
"}"
] | Insert a crumb before the first matching crumb with the specified title.
Finds the index of the first crumb that matches the provided class,
and inserts the supplied callable before it.
@param string $matchingTitle The title of the crumb you want to insert this one before.
@param string $title Title of the crumb.
@param string|array|null $url URL of the crumb. Either a string, an array of route params to pass to
Url::build() or null / empty if the crumb does not have a link.
@param array $options Array of options. These options will be used as attributes HTML attribute the crumb will
be rendered in (a <li> tag by default). It accepts two special keys:
- *innerAttrs*: An array that allows you to define attributes for the inner element of the crumb (by default, to
the link)
- *templateVars*: Specific template vars in case you override the templates provided.
@return $this
@throws \LogicException In case the matching crumb can not be found | [
"Insert",
"a",
"crumb",
"before",
"the",
"first",
"matching",
"crumb",
"with",
"the",
"specified",
"title",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/BreadcrumbsHelper.php#L176-L185 |
210,808 | cakephp/cakephp | src/View/Helper/BreadcrumbsHelper.php | BreadcrumbsHelper.render | public function render(array $attributes = [], array $separator = [])
{
if (!$this->crumbs) {
return '';
}
$crumbs = $this->crumbs;
$crumbsCount = count($crumbs);
$templater = $this->templater();
$separatorString = '';
if ($separator) {
if (isset($separator['innerAttrs'])) {
$separator['innerAttrs'] = $templater->formatAttributes($separator['innerAttrs']);
}
$separator['attrs'] = $templater->formatAttributes(
$separator,
['innerAttrs', 'separator']
);
$separatorString = $this->formatTemplate('separator', $separator);
}
$crumbTrail = '';
foreach ($crumbs as $key => $crumb) {
$url = $crumb['url'] ? $this->Url->build($crumb['url']) : null;
$title = $crumb['title'];
$options = $crumb['options'];
$optionsLink = [];
if (isset($options['innerAttrs'])) {
$optionsLink = $options['innerAttrs'];
unset($options['innerAttrs']);
}
$template = 'item';
$templateParams = [
'attrs' => $templater->formatAttributes($options, ['templateVars']),
'innerAttrs' => $templater->formatAttributes($optionsLink),
'title' => $title,
'url' => $url,
'separator' => '',
'templateVars' => isset($options['templateVars']) ? $options['templateVars'] : []
];
if (!$url) {
$template = 'itemWithoutLink';
}
if ($separatorString && $key !== ($crumbsCount - 1)) {
$templateParams['separator'] = $separatorString;
}
$crumbTrail .= $this->formatTemplate($template, $templateParams);
}
$crumbTrail = $this->formatTemplate('wrapper', [
'content' => $crumbTrail,
'attrs' => $templater->formatAttributes($attributes, ['templateVars']),
'templateVars' => isset($attributes['templateVars']) ? $attributes['templateVars'] : []
]);
return $crumbTrail;
} | php | public function render(array $attributes = [], array $separator = [])
{
if (!$this->crumbs) {
return '';
}
$crumbs = $this->crumbs;
$crumbsCount = count($crumbs);
$templater = $this->templater();
$separatorString = '';
if ($separator) {
if (isset($separator['innerAttrs'])) {
$separator['innerAttrs'] = $templater->formatAttributes($separator['innerAttrs']);
}
$separator['attrs'] = $templater->formatAttributes(
$separator,
['innerAttrs', 'separator']
);
$separatorString = $this->formatTemplate('separator', $separator);
}
$crumbTrail = '';
foreach ($crumbs as $key => $crumb) {
$url = $crumb['url'] ? $this->Url->build($crumb['url']) : null;
$title = $crumb['title'];
$options = $crumb['options'];
$optionsLink = [];
if (isset($options['innerAttrs'])) {
$optionsLink = $options['innerAttrs'];
unset($options['innerAttrs']);
}
$template = 'item';
$templateParams = [
'attrs' => $templater->formatAttributes($options, ['templateVars']),
'innerAttrs' => $templater->formatAttributes($optionsLink),
'title' => $title,
'url' => $url,
'separator' => '',
'templateVars' => isset($options['templateVars']) ? $options['templateVars'] : []
];
if (!$url) {
$template = 'itemWithoutLink';
}
if ($separatorString && $key !== ($crumbsCount - 1)) {
$templateParams['separator'] = $separatorString;
}
$crumbTrail .= $this->formatTemplate($template, $templateParams);
}
$crumbTrail = $this->formatTemplate('wrapper', [
'content' => $crumbTrail,
'attrs' => $templater->formatAttributes($attributes, ['templateVars']),
'templateVars' => isset($attributes['templateVars']) ? $attributes['templateVars'] : []
]);
return $crumbTrail;
} | [
"public",
"function",
"render",
"(",
"array",
"$",
"attributes",
"=",
"[",
"]",
",",
"array",
"$",
"separator",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"crumbs",
")",
"{",
"return",
"''",
";",
"}",
"$",
"crumbs",
"=",
"$",
"this",
"->",
"crumbs",
";",
"$",
"crumbsCount",
"=",
"count",
"(",
"$",
"crumbs",
")",
";",
"$",
"templater",
"=",
"$",
"this",
"->",
"templater",
"(",
")",
";",
"$",
"separatorString",
"=",
"''",
";",
"if",
"(",
"$",
"separator",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"separator",
"[",
"'innerAttrs'",
"]",
")",
")",
"{",
"$",
"separator",
"[",
"'innerAttrs'",
"]",
"=",
"$",
"templater",
"->",
"formatAttributes",
"(",
"$",
"separator",
"[",
"'innerAttrs'",
"]",
")",
";",
"}",
"$",
"separator",
"[",
"'attrs'",
"]",
"=",
"$",
"templater",
"->",
"formatAttributes",
"(",
"$",
"separator",
",",
"[",
"'innerAttrs'",
",",
"'separator'",
"]",
")",
";",
"$",
"separatorString",
"=",
"$",
"this",
"->",
"formatTemplate",
"(",
"'separator'",
",",
"$",
"separator",
")",
";",
"}",
"$",
"crumbTrail",
"=",
"''",
";",
"foreach",
"(",
"$",
"crumbs",
"as",
"$",
"key",
"=>",
"$",
"crumb",
")",
"{",
"$",
"url",
"=",
"$",
"crumb",
"[",
"'url'",
"]",
"?",
"$",
"this",
"->",
"Url",
"->",
"build",
"(",
"$",
"crumb",
"[",
"'url'",
"]",
")",
":",
"null",
";",
"$",
"title",
"=",
"$",
"crumb",
"[",
"'title'",
"]",
";",
"$",
"options",
"=",
"$",
"crumb",
"[",
"'options'",
"]",
";",
"$",
"optionsLink",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'innerAttrs'",
"]",
")",
")",
"{",
"$",
"optionsLink",
"=",
"$",
"options",
"[",
"'innerAttrs'",
"]",
";",
"unset",
"(",
"$",
"options",
"[",
"'innerAttrs'",
"]",
")",
";",
"}",
"$",
"template",
"=",
"'item'",
";",
"$",
"templateParams",
"=",
"[",
"'attrs'",
"=>",
"$",
"templater",
"->",
"formatAttributes",
"(",
"$",
"options",
",",
"[",
"'templateVars'",
"]",
")",
",",
"'innerAttrs'",
"=>",
"$",
"templater",
"->",
"formatAttributes",
"(",
"$",
"optionsLink",
")",
",",
"'title'",
"=>",
"$",
"title",
",",
"'url'",
"=>",
"$",
"url",
",",
"'separator'",
"=>",
"''",
",",
"'templateVars'",
"=>",
"isset",
"(",
"$",
"options",
"[",
"'templateVars'",
"]",
")",
"?",
"$",
"options",
"[",
"'templateVars'",
"]",
":",
"[",
"]",
"]",
";",
"if",
"(",
"!",
"$",
"url",
")",
"{",
"$",
"template",
"=",
"'itemWithoutLink'",
";",
"}",
"if",
"(",
"$",
"separatorString",
"&&",
"$",
"key",
"!==",
"(",
"$",
"crumbsCount",
"-",
"1",
")",
")",
"{",
"$",
"templateParams",
"[",
"'separator'",
"]",
"=",
"$",
"separatorString",
";",
"}",
"$",
"crumbTrail",
".=",
"$",
"this",
"->",
"formatTemplate",
"(",
"$",
"template",
",",
"$",
"templateParams",
")",
";",
"}",
"$",
"crumbTrail",
"=",
"$",
"this",
"->",
"formatTemplate",
"(",
"'wrapper'",
",",
"[",
"'content'",
"=>",
"$",
"crumbTrail",
",",
"'attrs'",
"=>",
"$",
"templater",
"->",
"formatAttributes",
"(",
"$",
"attributes",
",",
"[",
"'templateVars'",
"]",
")",
",",
"'templateVars'",
"=>",
"isset",
"(",
"$",
"attributes",
"[",
"'templateVars'",
"]",
")",
"?",
"$",
"attributes",
"[",
"'templateVars'",
"]",
":",
"[",
"]",
"]",
")",
";",
"return",
"$",
"crumbTrail",
";",
"}"
] | Renders the breadcrumbs trail.
@param array $attributes Array of attributes applied to the `wrapper` template. Accepts the `templateVars` key to
allow the insertion of custom template variable in the template.
@param array $separator Array of attributes for the `separator` template.
Possible properties are :
- *separator* The string to be displayed as a separator
- *templateVars* Allows the insertion of custom template variable in the template
- *innerAttrs* To provide attributes in case your separator is divided in two elements.
All other properties will be converted as HTML attributes and will replace the *attrs* key in the template.
If you use the default for this option (empty), it will not render a separator.
@return string The breadcrumbs trail | [
"Renders",
"the",
"breadcrumbs",
"trail",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/BreadcrumbsHelper.php#L252-L316 |
210,809 | cakephp/cakephp | src/View/Helper/BreadcrumbsHelper.php | BreadcrumbsHelper.findCrumb | protected function findCrumb($title)
{
foreach ($this->crumbs as $key => $crumb) {
if ($crumb['title'] === $title) {
return $key;
}
}
return null;
} | php | protected function findCrumb($title)
{
foreach ($this->crumbs as $key => $crumb) {
if ($crumb['title'] === $title) {
return $key;
}
}
return null;
} | [
"protected",
"function",
"findCrumb",
"(",
"$",
"title",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"crumbs",
"as",
"$",
"key",
"=>",
"$",
"crumb",
")",
"{",
"if",
"(",
"$",
"crumb",
"[",
"'title'",
"]",
"===",
"$",
"title",
")",
"{",
"return",
"$",
"key",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Search a crumb in the current stack which title matches the one provided as argument.
If found, the index of the matching crumb will be returned.
@param string $title Title to find.
@return int|null Index of the crumb found, or null if it can not be found. | [
"Search",
"a",
"crumb",
"in",
"the",
"current",
"stack",
"which",
"title",
"matches",
"the",
"one",
"provided",
"as",
"argument",
".",
"If",
"found",
"the",
"index",
"of",
"the",
"matching",
"crumb",
"will",
"be",
"returned",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/BreadcrumbsHelper.php#L325-L334 |
210,810 | cakephp/cakephp | src/Http/Session/DatabaseSession.php | DatabaseSession.read | public function read($id)
{
$result = $this->_table
->find('all')
->select(['data'])
->where([$this->_table->getPrimaryKey() => $id])
->disableHydration()
->first();
if (empty($result)) {
return '';
}
if (is_string($result['data'])) {
return $result['data'];
}
$session = stream_get_contents($result['data']);
if ($session === false) {
return '';
}
return $session;
} | php | public function read($id)
{
$result = $this->_table
->find('all')
->select(['data'])
->where([$this->_table->getPrimaryKey() => $id])
->disableHydration()
->first();
if (empty($result)) {
return '';
}
if (is_string($result['data'])) {
return $result['data'];
}
$session = stream_get_contents($result['data']);
if ($session === false) {
return '';
}
return $session;
} | [
"public",
"function",
"read",
"(",
"$",
"id",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"_table",
"->",
"find",
"(",
"'all'",
")",
"->",
"select",
"(",
"[",
"'data'",
"]",
")",
"->",
"where",
"(",
"[",
"$",
"this",
"->",
"_table",
"->",
"getPrimaryKey",
"(",
")",
"=>",
"$",
"id",
"]",
")",
"->",
"disableHydration",
"(",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"result",
"[",
"'data'",
"]",
")",
")",
"{",
"return",
"$",
"result",
"[",
"'data'",
"]",
";",
"}",
"$",
"session",
"=",
"stream_get_contents",
"(",
"$",
"result",
"[",
"'data'",
"]",
")",
";",
"if",
"(",
"$",
"session",
"===",
"false",
")",
"{",
"return",
"''",
";",
"}",
"return",
"$",
"session",
";",
"}"
] | Method used to read from a database session.
@param string|int $id ID that uniquely identifies session in database.
@return string Session data or empty string if it does not exist. | [
"Method",
"used",
"to",
"read",
"from",
"a",
"database",
"session",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Session/DatabaseSession.php#L111-L135 |
210,811 | cakephp/cakephp | src/Http/Session/DatabaseSession.php | DatabaseSession.write | public function write($id, $data)
{
if (!$id) {
return false;
}
$expires = time() + $this->_timeout;
$record = compact('data', 'expires');
$record[$this->_table->getPrimaryKey()] = $id;
$result = $this->_table->save(new Entity($record));
return (bool)$result;
} | php | public function write($id, $data)
{
if (!$id) {
return false;
}
$expires = time() + $this->_timeout;
$record = compact('data', 'expires');
$record[$this->_table->getPrimaryKey()] = $id;
$result = $this->_table->save(new Entity($record));
return (bool)$result;
} | [
"public",
"function",
"write",
"(",
"$",
"id",
",",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"$",
"id",
")",
"{",
"return",
"false",
";",
"}",
"$",
"expires",
"=",
"time",
"(",
")",
"+",
"$",
"this",
"->",
"_timeout",
";",
"$",
"record",
"=",
"compact",
"(",
"'data'",
",",
"'expires'",
")",
";",
"$",
"record",
"[",
"$",
"this",
"->",
"_table",
"->",
"getPrimaryKey",
"(",
")",
"]",
"=",
"$",
"id",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"_table",
"->",
"save",
"(",
"new",
"Entity",
"(",
"$",
"record",
")",
")",
";",
"return",
"(",
"bool",
")",
"$",
"result",
";",
"}"
] | Helper function called on write for database sessions.
@param string|int $id ID that uniquely identifies session in database.
@param mixed $data The data to be saved.
@return bool True for successful write, false otherwise. | [
"Helper",
"function",
"called",
"on",
"write",
"for",
"database",
"sessions",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Session/DatabaseSession.php#L144-L155 |
210,812 | cakephp/cakephp | src/Http/Session/DatabaseSession.php | DatabaseSession.destroy | public function destroy($id)
{
$this->_table->delete(new Entity(
[$this->_table->getPrimaryKey() => $id],
['markNew' => false]
));
return true;
} | php | public function destroy($id)
{
$this->_table->delete(new Entity(
[$this->_table->getPrimaryKey() => $id],
['markNew' => false]
));
return true;
} | [
"public",
"function",
"destroy",
"(",
"$",
"id",
")",
"{",
"$",
"this",
"->",
"_table",
"->",
"delete",
"(",
"new",
"Entity",
"(",
"[",
"$",
"this",
"->",
"_table",
"->",
"getPrimaryKey",
"(",
")",
"=>",
"$",
"id",
"]",
",",
"[",
"'markNew'",
"=>",
"false",
"]",
")",
")",
";",
"return",
"true",
";",
"}"
] | Method called on the destruction of a database session.
@param string|int $id ID that uniquely identifies session in database.
@return bool True for successful delete, false otherwise. | [
"Method",
"called",
"on",
"the",
"destruction",
"of",
"a",
"database",
"session",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Session/DatabaseSession.php#L163-L171 |
210,813 | cakephp/cakephp | src/Http/ActionDispatcher.php | ActionDispatcher.dispatch | public function dispatch(ServerRequest $request, Response $response)
{
if (Router::getRequest(true) !== $request) {
Router::pushRequest($request);
}
$beforeEvent = $this->dispatchEvent('Dispatcher.beforeDispatch', compact('request', 'response'));
$request = $beforeEvent->getData('request');
if ($beforeEvent->getResult() instanceof Response) {
return $beforeEvent->getResult();
}
// Use the controller built by an beforeDispatch
// event handler if there is one.
if ($beforeEvent->getData('controller') instanceof Controller) {
$controller = $beforeEvent->getData('controller');
} else {
$controller = $this->factory->create($request, $response);
}
$response = $this->_invoke($controller);
if ($request->getParam('return')) {
return $response;
}
$afterEvent = $this->dispatchEvent('Dispatcher.afterDispatch', compact('request', 'response'));
return $afterEvent->getData('response');
} | php | public function dispatch(ServerRequest $request, Response $response)
{
if (Router::getRequest(true) !== $request) {
Router::pushRequest($request);
}
$beforeEvent = $this->dispatchEvent('Dispatcher.beforeDispatch', compact('request', 'response'));
$request = $beforeEvent->getData('request');
if ($beforeEvent->getResult() instanceof Response) {
return $beforeEvent->getResult();
}
// Use the controller built by an beforeDispatch
// event handler if there is one.
if ($beforeEvent->getData('controller') instanceof Controller) {
$controller = $beforeEvent->getData('controller');
} else {
$controller = $this->factory->create($request, $response);
}
$response = $this->_invoke($controller);
if ($request->getParam('return')) {
return $response;
}
$afterEvent = $this->dispatchEvent('Dispatcher.afterDispatch', compact('request', 'response'));
return $afterEvent->getData('response');
} | [
"public",
"function",
"dispatch",
"(",
"ServerRequest",
"$",
"request",
",",
"Response",
"$",
"response",
")",
"{",
"if",
"(",
"Router",
"::",
"getRequest",
"(",
"true",
")",
"!==",
"$",
"request",
")",
"{",
"Router",
"::",
"pushRequest",
"(",
"$",
"request",
")",
";",
"}",
"$",
"beforeEvent",
"=",
"$",
"this",
"->",
"dispatchEvent",
"(",
"'Dispatcher.beforeDispatch'",
",",
"compact",
"(",
"'request'",
",",
"'response'",
")",
")",
";",
"$",
"request",
"=",
"$",
"beforeEvent",
"->",
"getData",
"(",
"'request'",
")",
";",
"if",
"(",
"$",
"beforeEvent",
"->",
"getResult",
"(",
")",
"instanceof",
"Response",
")",
"{",
"return",
"$",
"beforeEvent",
"->",
"getResult",
"(",
")",
";",
"}",
"// Use the controller built by an beforeDispatch",
"// event handler if there is one.",
"if",
"(",
"$",
"beforeEvent",
"->",
"getData",
"(",
"'controller'",
")",
"instanceof",
"Controller",
")",
"{",
"$",
"controller",
"=",
"$",
"beforeEvent",
"->",
"getData",
"(",
"'controller'",
")",
";",
"}",
"else",
"{",
"$",
"controller",
"=",
"$",
"this",
"->",
"factory",
"->",
"create",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"_invoke",
"(",
"$",
"controller",
")",
";",
"if",
"(",
"$",
"request",
"->",
"getParam",
"(",
"'return'",
")",
")",
"{",
"return",
"$",
"response",
";",
"}",
"$",
"afterEvent",
"=",
"$",
"this",
"->",
"dispatchEvent",
"(",
"'Dispatcher.afterDispatch'",
",",
"compact",
"(",
"'request'",
",",
"'response'",
")",
")",
";",
"return",
"$",
"afterEvent",
"->",
"getData",
"(",
"'response'",
")",
";",
"}"
] | Dispatches a Request & Response
@param \Cake\Http\ServerRequest $request The request to dispatch.
@param \Cake\Http\Response $response The response to dispatch.
@return \Cake\Http\Response A modified/replaced response.
@throws \ReflectionException | [
"Dispatches",
"a",
"Request",
"&",
"Response"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ActionDispatcher.php#L74-L102 |
210,814 | cakephp/cakephp | src/Http/ActionDispatcher.php | ActionDispatcher._invoke | protected function _invoke(Controller $controller)
{
$this->dispatchEvent('Dispatcher.invokeController', ['controller' => $controller]);
$result = $controller->startupProcess();
if ($result instanceof Response) {
return $result;
}
$response = $controller->invokeAction();
if ($response !== null && !($response instanceof Response)) {
throw new LogicException('Controller actions can only return Cake\Http\Response or null.');
}
if (!$response && $controller->isAutoRenderEnabled()) {
$controller->render();
}
$result = $controller->shutdownProcess();
if ($result instanceof Response) {
return $result;
}
if (!$response) {
$response = $controller->getResponse();
}
return $response;
} | php | protected function _invoke(Controller $controller)
{
$this->dispatchEvent('Dispatcher.invokeController', ['controller' => $controller]);
$result = $controller->startupProcess();
if ($result instanceof Response) {
return $result;
}
$response = $controller->invokeAction();
if ($response !== null && !($response instanceof Response)) {
throw new LogicException('Controller actions can only return Cake\Http\Response or null.');
}
if (!$response && $controller->isAutoRenderEnabled()) {
$controller->render();
}
$result = $controller->shutdownProcess();
if ($result instanceof Response) {
return $result;
}
if (!$response) {
$response = $controller->getResponse();
}
return $response;
} | [
"protected",
"function",
"_invoke",
"(",
"Controller",
"$",
"controller",
")",
"{",
"$",
"this",
"->",
"dispatchEvent",
"(",
"'Dispatcher.invokeController'",
",",
"[",
"'controller'",
"=>",
"$",
"controller",
"]",
")",
";",
"$",
"result",
"=",
"$",
"controller",
"->",
"startupProcess",
"(",
")",
";",
"if",
"(",
"$",
"result",
"instanceof",
"Response",
")",
"{",
"return",
"$",
"result",
";",
"}",
"$",
"response",
"=",
"$",
"controller",
"->",
"invokeAction",
"(",
")",
";",
"if",
"(",
"$",
"response",
"!==",
"null",
"&&",
"!",
"(",
"$",
"response",
"instanceof",
"Response",
")",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"'Controller actions can only return Cake\\Http\\Response or null.'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"response",
"&&",
"$",
"controller",
"->",
"isAutoRenderEnabled",
"(",
")",
")",
"{",
"$",
"controller",
"->",
"render",
"(",
")",
";",
"}",
"$",
"result",
"=",
"$",
"controller",
"->",
"shutdownProcess",
"(",
")",
";",
"if",
"(",
"$",
"result",
"instanceof",
"Response",
")",
"{",
"return",
"$",
"result",
";",
"}",
"if",
"(",
"!",
"$",
"response",
")",
"{",
"$",
"response",
"=",
"$",
"controller",
"->",
"getResponse",
"(",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Invoke a controller's action and wrapping methods.
@param \Cake\Controller\Controller $controller The controller to invoke.
@return \Cake\Http\Response The response
@throws \LogicException If the controller action returns a non-response value. | [
"Invoke",
"a",
"controller",
"s",
"action",
"and",
"wrapping",
"methods",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ActionDispatcher.php#L111-L138 |
210,815 | cakephp/cakephp | src/Http/ActionDispatcher.php | ActionDispatcher.addFilter | public function addFilter(EventListenerInterface $filter)
{
deprecationWarning(
'ActionDispatcher::addFilter() is deprecated. ' .
'This is only available for backwards compatibility with DispatchFilters'
);
$this->filters[] = $filter;
$this->getEventManager()->on($filter);
} | php | public function addFilter(EventListenerInterface $filter)
{
deprecationWarning(
'ActionDispatcher::addFilter() is deprecated. ' .
'This is only available for backwards compatibility with DispatchFilters'
);
$this->filters[] = $filter;
$this->getEventManager()->on($filter);
} | [
"public",
"function",
"addFilter",
"(",
"EventListenerInterface",
"$",
"filter",
")",
"{",
"deprecationWarning",
"(",
"'ActionDispatcher::addFilter() is deprecated. '",
".",
"'This is only available for backwards compatibility with DispatchFilters'",
")",
";",
"$",
"this",
"->",
"filters",
"[",
"]",
"=",
"$",
"filter",
";",
"$",
"this",
"->",
"getEventManager",
"(",
")",
"->",
"on",
"(",
"$",
"filter",
")",
";",
"}"
] | Add a filter to this dispatcher.
The added filter will be attached to the event manager used
by this dispatcher.
@param \Cake\Event\EventListenerInterface $filter The filter to connect. Can be
any EventListenerInterface. Typically an instance of \Cake\Routing\DispatcherFilter.
@return void
@deprecated This is only available for backwards compatibility with DispatchFilters | [
"Add",
"a",
"filter",
"to",
"this",
"dispatcher",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ActionDispatcher.php#L151-L160 |
210,816 | cakephp/cakephp | src/Database/QueryCompiler.php | QueryCompiler.compile | public function compile(Query $query, ValueBinder $generator)
{
$sql = '';
$type = $query->type();
$query->traverse(
$this->_sqlCompiler($sql, $query, $generator),
$this->{'_' . $type . 'Parts'}
);
// Propagate bound parameters from sub-queries if the
// placeholders can be found in the SQL statement.
if ($query->getValueBinder() !== $generator) {
foreach ($query->getValueBinder()->bindings() as $binding) {
$placeholder = ':' . $binding['placeholder'];
if (preg_match('/' . $placeholder . '(?:\W|$)/', $sql) > 0) {
$generator->bind($placeholder, $binding['value'], $binding['type']);
}
}
}
return $sql;
} | php | public function compile(Query $query, ValueBinder $generator)
{
$sql = '';
$type = $query->type();
$query->traverse(
$this->_sqlCompiler($sql, $query, $generator),
$this->{'_' . $type . 'Parts'}
);
// Propagate bound parameters from sub-queries if the
// placeholders can be found in the SQL statement.
if ($query->getValueBinder() !== $generator) {
foreach ($query->getValueBinder()->bindings() as $binding) {
$placeholder = ':' . $binding['placeholder'];
if (preg_match('/' . $placeholder . '(?:\W|$)/', $sql) > 0) {
$generator->bind($placeholder, $binding['value'], $binding['type']);
}
}
}
return $sql;
} | [
"public",
"function",
"compile",
"(",
"Query",
"$",
"query",
",",
"ValueBinder",
"$",
"generator",
")",
"{",
"$",
"sql",
"=",
"''",
";",
"$",
"type",
"=",
"$",
"query",
"->",
"type",
"(",
")",
";",
"$",
"query",
"->",
"traverse",
"(",
"$",
"this",
"->",
"_sqlCompiler",
"(",
"$",
"sql",
",",
"$",
"query",
",",
"$",
"generator",
")",
",",
"$",
"this",
"->",
"{",
"'_'",
".",
"$",
"type",
".",
"'Parts'",
"}",
")",
";",
"// Propagate bound parameters from sub-queries if the",
"// placeholders can be found in the SQL statement.",
"if",
"(",
"$",
"query",
"->",
"getValueBinder",
"(",
")",
"!==",
"$",
"generator",
")",
"{",
"foreach",
"(",
"$",
"query",
"->",
"getValueBinder",
"(",
")",
"->",
"bindings",
"(",
")",
"as",
"$",
"binding",
")",
"{",
"$",
"placeholder",
"=",
"':'",
".",
"$",
"binding",
"[",
"'placeholder'",
"]",
";",
"if",
"(",
"preg_match",
"(",
"'/'",
".",
"$",
"placeholder",
".",
"'(?:\\W|$)/'",
",",
"$",
"sql",
")",
">",
"0",
")",
"{",
"$",
"generator",
"->",
"bind",
"(",
"$",
"placeholder",
",",
"$",
"binding",
"[",
"'value'",
"]",
",",
"$",
"binding",
"[",
"'type'",
"]",
")",
";",
"}",
"}",
"}",
"return",
"$",
"sql",
";",
"}"
] | Returns the SQL representation of the provided query after generating
the placeholders for the bound values using the provided generator
@param \Cake\Database\Query $query The query that is being compiled
@param \Cake\Database\ValueBinder $generator the placeholder generator to be used in expressions
@return \Closure | [
"Returns",
"the",
"SQL",
"representation",
"of",
"the",
"provided",
"query",
"after",
"generating",
"the",
"placeholders",
"for",
"the",
"bound",
"values",
"using",
"the",
"provided",
"generator"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/QueryCompiler.php#L93-L114 |
210,817 | cakephp/cakephp | src/Database/QueryCompiler.php | QueryCompiler._sqlCompiler | protected function _sqlCompiler(&$sql, $query, $generator)
{
return function ($parts, $name) use (&$sql, $query, $generator) {
if (!isset($parts) ||
((is_array($parts) || $parts instanceof \Countable) && !count($parts))
) {
return;
}
if ($parts instanceof ExpressionInterface) {
$parts = [$parts->sql($generator)];
}
if (isset($this->_templates[$name])) {
$parts = $this->_stringifyExpressions((array)$parts, $generator);
return $sql .= sprintf($this->_templates[$name], implode(', ', $parts));
}
return $sql .= $this->{'_build' . ucfirst($name) . 'Part'}($parts, $query, $generator);
};
} | php | protected function _sqlCompiler(&$sql, $query, $generator)
{
return function ($parts, $name) use (&$sql, $query, $generator) {
if (!isset($parts) ||
((is_array($parts) || $parts instanceof \Countable) && !count($parts))
) {
return;
}
if ($parts instanceof ExpressionInterface) {
$parts = [$parts->sql($generator)];
}
if (isset($this->_templates[$name])) {
$parts = $this->_stringifyExpressions((array)$parts, $generator);
return $sql .= sprintf($this->_templates[$name], implode(', ', $parts));
}
return $sql .= $this->{'_build' . ucfirst($name) . 'Part'}($parts, $query, $generator);
};
} | [
"protected",
"function",
"_sqlCompiler",
"(",
"&",
"$",
"sql",
",",
"$",
"query",
",",
"$",
"generator",
")",
"{",
"return",
"function",
"(",
"$",
"parts",
",",
"$",
"name",
")",
"use",
"(",
"&",
"$",
"sql",
",",
"$",
"query",
",",
"$",
"generator",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"parts",
")",
"||",
"(",
"(",
"is_array",
"(",
"$",
"parts",
")",
"||",
"$",
"parts",
"instanceof",
"\\",
"Countable",
")",
"&&",
"!",
"count",
"(",
"$",
"parts",
")",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"parts",
"instanceof",
"ExpressionInterface",
")",
"{",
"$",
"parts",
"=",
"[",
"$",
"parts",
"->",
"sql",
"(",
"$",
"generator",
")",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_templates",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"parts",
"=",
"$",
"this",
"->",
"_stringifyExpressions",
"(",
"(",
"array",
")",
"$",
"parts",
",",
"$",
"generator",
")",
";",
"return",
"$",
"sql",
".=",
"sprintf",
"(",
"$",
"this",
"->",
"_templates",
"[",
"$",
"name",
"]",
",",
"implode",
"(",
"', '",
",",
"$",
"parts",
")",
")",
";",
"}",
"return",
"$",
"sql",
".=",
"$",
"this",
"->",
"{",
"'_build'",
".",
"ucfirst",
"(",
"$",
"name",
")",
".",
"'Part'",
"}",
"(",
"$",
"parts",
",",
"$",
"query",
",",
"$",
"generator",
")",
";",
"}",
";",
"}"
] | Returns a callable object that can be used to compile a SQL string representation
of this query.
@param string $sql initial sql string to append to
@param \Cake\Database\Query $query The query that is being compiled
@param \Cake\Database\ValueBinder $generator The placeholder and value binder object
@return \Closure | [
"Returns",
"a",
"callable",
"object",
"that",
"can",
"be",
"used",
"to",
"compile",
"a",
"SQL",
"string",
"representation",
"of",
"this",
"query",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/QueryCompiler.php#L125-L144 |
210,818 | cakephp/cakephp | src/Database/QueryCompiler.php | QueryCompiler._buildSelectPart | protected function _buildSelectPart($parts, $query, $generator)
{
$driver = $query->getConnection()->getDriver();
$select = 'SELECT%s %s%s';
if ($this->_orderedUnion && $query->clause('union')) {
$select = '(SELECT%s %s%s';
}
$distinct = $query->clause('distinct');
$modifiers = $this->_buildModifierPart($query->clause('modifier'), $query, $generator);
$normalized = [];
$parts = $this->_stringifyExpressions($parts, $generator);
foreach ($parts as $k => $p) {
if (!is_numeric($k)) {
$p = $p . ' AS ' . $driver->quoteIdentifier($k);
}
$normalized[] = $p;
}
if ($distinct === true) {
$distinct = 'DISTINCT ';
}
if (is_array($distinct)) {
$distinct = $this->_stringifyExpressions($distinct, $generator);
$distinct = sprintf('DISTINCT ON (%s) ', implode(', ', $distinct));
}
return sprintf($select, $modifiers, $distinct, implode(', ', $normalized));
} | php | protected function _buildSelectPart($parts, $query, $generator)
{
$driver = $query->getConnection()->getDriver();
$select = 'SELECT%s %s%s';
if ($this->_orderedUnion && $query->clause('union')) {
$select = '(SELECT%s %s%s';
}
$distinct = $query->clause('distinct');
$modifiers = $this->_buildModifierPart($query->clause('modifier'), $query, $generator);
$normalized = [];
$parts = $this->_stringifyExpressions($parts, $generator);
foreach ($parts as $k => $p) {
if (!is_numeric($k)) {
$p = $p . ' AS ' . $driver->quoteIdentifier($k);
}
$normalized[] = $p;
}
if ($distinct === true) {
$distinct = 'DISTINCT ';
}
if (is_array($distinct)) {
$distinct = $this->_stringifyExpressions($distinct, $generator);
$distinct = sprintf('DISTINCT ON (%s) ', implode(', ', $distinct));
}
return sprintf($select, $modifiers, $distinct, implode(', ', $normalized));
} | [
"protected",
"function",
"_buildSelectPart",
"(",
"$",
"parts",
",",
"$",
"query",
",",
"$",
"generator",
")",
"{",
"$",
"driver",
"=",
"$",
"query",
"->",
"getConnection",
"(",
")",
"->",
"getDriver",
"(",
")",
";",
"$",
"select",
"=",
"'SELECT%s %s%s'",
";",
"if",
"(",
"$",
"this",
"->",
"_orderedUnion",
"&&",
"$",
"query",
"->",
"clause",
"(",
"'union'",
")",
")",
"{",
"$",
"select",
"=",
"'(SELECT%s %s%s'",
";",
"}",
"$",
"distinct",
"=",
"$",
"query",
"->",
"clause",
"(",
"'distinct'",
")",
";",
"$",
"modifiers",
"=",
"$",
"this",
"->",
"_buildModifierPart",
"(",
"$",
"query",
"->",
"clause",
"(",
"'modifier'",
")",
",",
"$",
"query",
",",
"$",
"generator",
")",
";",
"$",
"normalized",
"=",
"[",
"]",
";",
"$",
"parts",
"=",
"$",
"this",
"->",
"_stringifyExpressions",
"(",
"$",
"parts",
",",
"$",
"generator",
")",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"k",
"=>",
"$",
"p",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"k",
")",
")",
"{",
"$",
"p",
"=",
"$",
"p",
".",
"' AS '",
".",
"$",
"driver",
"->",
"quoteIdentifier",
"(",
"$",
"k",
")",
";",
"}",
"$",
"normalized",
"[",
"]",
"=",
"$",
"p",
";",
"}",
"if",
"(",
"$",
"distinct",
"===",
"true",
")",
"{",
"$",
"distinct",
"=",
"'DISTINCT '",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"distinct",
")",
")",
"{",
"$",
"distinct",
"=",
"$",
"this",
"->",
"_stringifyExpressions",
"(",
"$",
"distinct",
",",
"$",
"generator",
")",
";",
"$",
"distinct",
"=",
"sprintf",
"(",
"'DISTINCT ON (%s) '",
",",
"implode",
"(",
"', '",
",",
"$",
"distinct",
")",
")",
";",
"}",
"return",
"sprintf",
"(",
"$",
"select",
",",
"$",
"modifiers",
",",
"$",
"distinct",
",",
"implode",
"(",
"', '",
",",
"$",
"normalized",
")",
")",
";",
"}"
] | Helper function used to build the string representation of a SELECT clause,
it constructs the field list taking care of aliasing and
converting expression objects to string. This function also constructs the
DISTINCT clause for the query.
@param array $parts list of fields to be transformed to string
@param \Cake\Database\Query $query The query that is being compiled
@param \Cake\Database\ValueBinder $generator the placeholder generator to be used in expressions
@return string | [
"Helper",
"function",
"used",
"to",
"build",
"the",
"string",
"representation",
"of",
"a",
"SELECT",
"clause",
"it",
"constructs",
"the",
"field",
"list",
"taking",
"care",
"of",
"aliasing",
"and",
"converting",
"expression",
"objects",
"to",
"string",
".",
"This",
"function",
"also",
"constructs",
"the",
"DISTINCT",
"clause",
"for",
"the",
"query",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/QueryCompiler.php#L157-L186 |
210,819 | cakephp/cakephp | src/Database/QueryCompiler.php | QueryCompiler._buildFromPart | protected function _buildFromPart($parts, $query, $generator)
{
$select = ' FROM %s';
$normalized = [];
$parts = $this->_stringifyExpressions($parts, $generator);
foreach ($parts as $k => $p) {
if (!is_numeric($k)) {
$p = $p . ' ' . $k;
}
$normalized[] = $p;
}
return sprintf($select, implode(', ', $normalized));
} | php | protected function _buildFromPart($parts, $query, $generator)
{
$select = ' FROM %s';
$normalized = [];
$parts = $this->_stringifyExpressions($parts, $generator);
foreach ($parts as $k => $p) {
if (!is_numeric($k)) {
$p = $p . ' ' . $k;
}
$normalized[] = $p;
}
return sprintf($select, implode(', ', $normalized));
} | [
"protected",
"function",
"_buildFromPart",
"(",
"$",
"parts",
",",
"$",
"query",
",",
"$",
"generator",
")",
"{",
"$",
"select",
"=",
"' FROM %s'",
";",
"$",
"normalized",
"=",
"[",
"]",
";",
"$",
"parts",
"=",
"$",
"this",
"->",
"_stringifyExpressions",
"(",
"$",
"parts",
",",
"$",
"generator",
")",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"k",
"=>",
"$",
"p",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"k",
")",
")",
"{",
"$",
"p",
"=",
"$",
"p",
".",
"' '",
".",
"$",
"k",
";",
"}",
"$",
"normalized",
"[",
"]",
"=",
"$",
"p",
";",
"}",
"return",
"sprintf",
"(",
"$",
"select",
",",
"implode",
"(",
"', '",
",",
"$",
"normalized",
")",
")",
";",
"}"
] | Helper function used to build the string representation of a FROM clause,
it constructs the tables list taking care of aliasing and
converting expression objects to string.
@param array $parts list of tables to be transformed to string
@param \Cake\Database\Query $query The query that is being compiled
@param \Cake\Database\ValueBinder $generator the placeholder generator to be used in expressions
@return string | [
"Helper",
"function",
"used",
"to",
"build",
"the",
"string",
"representation",
"of",
"a",
"FROM",
"clause",
"it",
"constructs",
"the",
"tables",
"list",
"taking",
"care",
"of",
"aliasing",
"and",
"converting",
"expression",
"objects",
"to",
"string",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/QueryCompiler.php#L198-L211 |
210,820 | cakephp/cakephp | src/Database/QueryCompiler.php | QueryCompiler._buildJoinPart | protected function _buildJoinPart($parts, $query, $generator)
{
$joins = '';
foreach ($parts as $join) {
$subquery = $join['table'] instanceof Query || $join['table'] instanceof QueryExpression;
if ($join['table'] instanceof ExpressionInterface) {
$join['table'] = $join['table']->sql($generator);
}
if ($subquery) {
$join['table'] = '(' . $join['table'] . ')';
}
$joins .= sprintf(' %s JOIN %s %s', $join['type'], $join['table'], $join['alias']);
$condition = '';
if (isset($join['conditions']) && $join['conditions'] instanceof ExpressionInterface) {
$condition = $join['conditions']->sql($generator);
}
if (strlen($condition)) {
$joins .= " ON {$condition}";
} else {
$joins .= ' ON 1 = 1';
}
}
return $joins;
} | php | protected function _buildJoinPart($parts, $query, $generator)
{
$joins = '';
foreach ($parts as $join) {
$subquery = $join['table'] instanceof Query || $join['table'] instanceof QueryExpression;
if ($join['table'] instanceof ExpressionInterface) {
$join['table'] = $join['table']->sql($generator);
}
if ($subquery) {
$join['table'] = '(' . $join['table'] . ')';
}
$joins .= sprintf(' %s JOIN %s %s', $join['type'], $join['table'], $join['alias']);
$condition = '';
if (isset($join['conditions']) && $join['conditions'] instanceof ExpressionInterface) {
$condition = $join['conditions']->sql($generator);
}
if (strlen($condition)) {
$joins .= " ON {$condition}";
} else {
$joins .= ' ON 1 = 1';
}
}
return $joins;
} | [
"protected",
"function",
"_buildJoinPart",
"(",
"$",
"parts",
",",
"$",
"query",
",",
"$",
"generator",
")",
"{",
"$",
"joins",
"=",
"''",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"join",
")",
"{",
"$",
"subquery",
"=",
"$",
"join",
"[",
"'table'",
"]",
"instanceof",
"Query",
"||",
"$",
"join",
"[",
"'table'",
"]",
"instanceof",
"QueryExpression",
";",
"if",
"(",
"$",
"join",
"[",
"'table'",
"]",
"instanceof",
"ExpressionInterface",
")",
"{",
"$",
"join",
"[",
"'table'",
"]",
"=",
"$",
"join",
"[",
"'table'",
"]",
"->",
"sql",
"(",
"$",
"generator",
")",
";",
"}",
"if",
"(",
"$",
"subquery",
")",
"{",
"$",
"join",
"[",
"'table'",
"]",
"=",
"'('",
".",
"$",
"join",
"[",
"'table'",
"]",
".",
"')'",
";",
"}",
"$",
"joins",
".=",
"sprintf",
"(",
"' %s JOIN %s %s'",
",",
"$",
"join",
"[",
"'type'",
"]",
",",
"$",
"join",
"[",
"'table'",
"]",
",",
"$",
"join",
"[",
"'alias'",
"]",
")",
";",
"$",
"condition",
"=",
"''",
";",
"if",
"(",
"isset",
"(",
"$",
"join",
"[",
"'conditions'",
"]",
")",
"&&",
"$",
"join",
"[",
"'conditions'",
"]",
"instanceof",
"ExpressionInterface",
")",
"{",
"$",
"condition",
"=",
"$",
"join",
"[",
"'conditions'",
"]",
"->",
"sql",
"(",
"$",
"generator",
")",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"condition",
")",
")",
"{",
"$",
"joins",
".=",
"\" ON {$condition}\"",
";",
"}",
"else",
"{",
"$",
"joins",
".=",
"' ON 1 = 1'",
";",
"}",
"}",
"return",
"$",
"joins",
";",
"}"
] | Helper function used to build the string representation of multiple JOIN clauses,
it constructs the joins list taking care of aliasing and converting
expression objects to string in both the table to be joined and the conditions
to be used.
@param array $parts list of joins to be transformed to string
@param \Cake\Database\Query $query The query that is being compiled
@param \Cake\Database\ValueBinder $generator the placeholder generator to be used in expressions
@return string | [
"Helper",
"function",
"used",
"to",
"build",
"the",
"string",
"representation",
"of",
"multiple",
"JOIN",
"clauses",
"it",
"constructs",
"the",
"joins",
"list",
"taking",
"care",
"of",
"aliasing",
"and",
"converting",
"expression",
"objects",
"to",
"string",
"in",
"both",
"the",
"table",
"to",
"be",
"joined",
"and",
"the",
"conditions",
"to",
"be",
"used",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/QueryCompiler.php#L224-L251 |
210,821 | cakephp/cakephp | src/Database/QueryCompiler.php | QueryCompiler._buildSetPart | protected function _buildSetPart($parts, $query, $generator)
{
$set = [];
foreach ($parts as $part) {
if ($part instanceof ExpressionInterface) {
$part = $part->sql($generator);
}
if ($part[0] === '(') {
$part = substr($part, 1, -1);
}
$set[] = $part;
}
return ' SET ' . implode('', $set);
} | php | protected function _buildSetPart($parts, $query, $generator)
{
$set = [];
foreach ($parts as $part) {
if ($part instanceof ExpressionInterface) {
$part = $part->sql($generator);
}
if ($part[0] === '(') {
$part = substr($part, 1, -1);
}
$set[] = $part;
}
return ' SET ' . implode('', $set);
} | [
"protected",
"function",
"_buildSetPart",
"(",
"$",
"parts",
",",
"$",
"query",
",",
"$",
"generator",
")",
"{",
"$",
"set",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"part",
")",
"{",
"if",
"(",
"$",
"part",
"instanceof",
"ExpressionInterface",
")",
"{",
"$",
"part",
"=",
"$",
"part",
"->",
"sql",
"(",
"$",
"generator",
")",
";",
"}",
"if",
"(",
"$",
"part",
"[",
"0",
"]",
"===",
"'('",
")",
"{",
"$",
"part",
"=",
"substr",
"(",
"$",
"part",
",",
"1",
",",
"-",
"1",
")",
";",
"}",
"$",
"set",
"[",
"]",
"=",
"$",
"part",
";",
"}",
"return",
"' SET '",
".",
"implode",
"(",
"''",
",",
"$",
"set",
")",
";",
"}"
] | Helper function to generate SQL for SET expressions.
@param array $parts List of keys & values to set.
@param \Cake\Database\Query $query The query that is being compiled
@param \Cake\Database\ValueBinder $generator the placeholder generator to be used in expressions
@return string | [
"Helper",
"function",
"to",
"generate",
"SQL",
"for",
"SET",
"expressions",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/QueryCompiler.php#L261-L275 |
210,822 | cakephp/cakephp | src/Database/QueryCompiler.php | QueryCompiler._buildUnionPart | protected function _buildUnionPart($parts, $query, $generator)
{
$parts = array_map(function ($p) use ($generator) {
$p['query'] = $p['query']->sql($generator);
$p['query'] = $p['query'][0] === '(' ? trim($p['query'], '()') : $p['query'];
$prefix = $p['all'] ? 'ALL ' : '';
if ($this->_orderedUnion) {
return "{$prefix}({$p['query']})";
}
return $prefix . $p['query'];
}, $parts);
if ($this->_orderedUnion) {
return sprintf(")\nUNION %s", implode("\nUNION ", $parts));
}
return sprintf("\nUNION %s", implode("\nUNION ", $parts));
} | php | protected function _buildUnionPart($parts, $query, $generator)
{
$parts = array_map(function ($p) use ($generator) {
$p['query'] = $p['query']->sql($generator);
$p['query'] = $p['query'][0] === '(' ? trim($p['query'], '()') : $p['query'];
$prefix = $p['all'] ? 'ALL ' : '';
if ($this->_orderedUnion) {
return "{$prefix}({$p['query']})";
}
return $prefix . $p['query'];
}, $parts);
if ($this->_orderedUnion) {
return sprintf(")\nUNION %s", implode("\nUNION ", $parts));
}
return sprintf("\nUNION %s", implode("\nUNION ", $parts));
} | [
"protected",
"function",
"_buildUnionPart",
"(",
"$",
"parts",
",",
"$",
"query",
",",
"$",
"generator",
")",
"{",
"$",
"parts",
"=",
"array_map",
"(",
"function",
"(",
"$",
"p",
")",
"use",
"(",
"$",
"generator",
")",
"{",
"$",
"p",
"[",
"'query'",
"]",
"=",
"$",
"p",
"[",
"'query'",
"]",
"->",
"sql",
"(",
"$",
"generator",
")",
";",
"$",
"p",
"[",
"'query'",
"]",
"=",
"$",
"p",
"[",
"'query'",
"]",
"[",
"0",
"]",
"===",
"'('",
"?",
"trim",
"(",
"$",
"p",
"[",
"'query'",
"]",
",",
"'()'",
")",
":",
"$",
"p",
"[",
"'query'",
"]",
";",
"$",
"prefix",
"=",
"$",
"p",
"[",
"'all'",
"]",
"?",
"'ALL '",
":",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"_orderedUnion",
")",
"{",
"return",
"\"{$prefix}({$p['query']})\"",
";",
"}",
"return",
"$",
"prefix",
".",
"$",
"p",
"[",
"'query'",
"]",
";",
"}",
",",
"$",
"parts",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_orderedUnion",
")",
"{",
"return",
"sprintf",
"(",
"\")\\nUNION %s\"",
",",
"implode",
"(",
"\"\\nUNION \"",
",",
"$",
"parts",
")",
")",
";",
"}",
"return",
"sprintf",
"(",
"\"\\nUNION %s\"",
",",
"implode",
"(",
"\"\\nUNION \"",
",",
"$",
"parts",
")",
")",
";",
"}"
] | Builds the SQL string for all the UNION clauses in this query, when dealing
with query objects it will also transform them using their configured SQL
dialect.
@param array $parts list of queries to be operated with UNION
@param \Cake\Database\Query $query The query that is being compiled
@param \Cake\Database\ValueBinder $generator the placeholder generator to be used in expressions
@return string | [
"Builds",
"the",
"SQL",
"string",
"for",
"all",
"the",
"UNION",
"clauses",
"in",
"this",
"query",
"when",
"dealing",
"with",
"query",
"objects",
"it",
"will",
"also",
"transform",
"them",
"using",
"their",
"configured",
"SQL",
"dialect",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/QueryCompiler.php#L287-L305 |
210,823 | cakephp/cakephp | src/Database/QueryCompiler.php | QueryCompiler._buildUpdatePart | protected function _buildUpdatePart($parts, $query, $generator)
{
$table = $this->_stringifyExpressions($parts, $generator);
$modifiers = $this->_buildModifierPart($query->clause('modifier'), $query, $generator);
return sprintf('UPDATE%s %s', $modifiers, implode(',', $table));
} | php | protected function _buildUpdatePart($parts, $query, $generator)
{
$table = $this->_stringifyExpressions($parts, $generator);
$modifiers = $this->_buildModifierPart($query->clause('modifier'), $query, $generator);
return sprintf('UPDATE%s %s', $modifiers, implode(',', $table));
} | [
"protected",
"function",
"_buildUpdatePart",
"(",
"$",
"parts",
",",
"$",
"query",
",",
"$",
"generator",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"_stringifyExpressions",
"(",
"$",
"parts",
",",
"$",
"generator",
")",
";",
"$",
"modifiers",
"=",
"$",
"this",
"->",
"_buildModifierPart",
"(",
"$",
"query",
"->",
"clause",
"(",
"'modifier'",
")",
",",
"$",
"query",
",",
"$",
"generator",
")",
";",
"return",
"sprintf",
"(",
"'UPDATE%s %s'",
",",
"$",
"modifiers",
",",
"implode",
"(",
"','",
",",
"$",
"table",
")",
")",
";",
"}"
] | Builds the SQL fragment for UPDATE.
@param array $parts The update parts.
@param \Cake\Database\Query $query The query that is being compiled
@param \Cake\Database\ValueBinder $generator the placeholder generator to be used in expressions
@return string SQL fragment. | [
"Builds",
"the",
"SQL",
"fragment",
"for",
"UPDATE",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/QueryCompiler.php#L345-L351 |
210,824 | cakephp/cakephp | src/Database/QueryCompiler.php | QueryCompiler._buildModifierPart | protected function _buildModifierPart($parts, $query, $generator)
{
if ($parts === []) {
return '';
}
return ' ' . implode(' ', $this->_stringifyExpressions($parts, $generator, false));
} | php | protected function _buildModifierPart($parts, $query, $generator)
{
if ($parts === []) {
return '';
}
return ' ' . implode(' ', $this->_stringifyExpressions($parts, $generator, false));
} | [
"protected",
"function",
"_buildModifierPart",
"(",
"$",
"parts",
",",
"$",
"query",
",",
"$",
"generator",
")",
"{",
"if",
"(",
"$",
"parts",
"===",
"[",
"]",
")",
"{",
"return",
"''",
";",
"}",
"return",
"' '",
".",
"implode",
"(",
"' '",
",",
"$",
"this",
"->",
"_stringifyExpressions",
"(",
"$",
"parts",
",",
"$",
"generator",
",",
"false",
")",
")",
";",
"}"
] | Builds the SQL modifier fragment
@param array $parts The query modifier parts
@param \Cake\Database\Query $query The query that is being compiled
@param \Cake\Database\ValueBinder $generator the placeholder generator to be used in expressions
@return string SQL fragment. | [
"Builds",
"the",
"SQL",
"modifier",
"fragment"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/QueryCompiler.php#L361-L368 |
210,825 | cakephp/cakephp | src/Database/QueryCompiler.php | QueryCompiler._stringifyExpressions | protected function _stringifyExpressions($expressions, $generator, $wrap = true)
{
$result = [];
foreach ($expressions as $k => $expression) {
if ($expression instanceof ExpressionInterface) {
$value = $expression->sql($generator);
$expression = $wrap ? '(' . $value . ')' : $value;
}
$result[$k] = $expression;
}
return $result;
} | php | protected function _stringifyExpressions($expressions, $generator, $wrap = true)
{
$result = [];
foreach ($expressions as $k => $expression) {
if ($expression instanceof ExpressionInterface) {
$value = $expression->sql($generator);
$expression = $wrap ? '(' . $value . ')' : $value;
}
$result[$k] = $expression;
}
return $result;
} | [
"protected",
"function",
"_stringifyExpressions",
"(",
"$",
"expressions",
",",
"$",
"generator",
",",
"$",
"wrap",
"=",
"true",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"expressions",
"as",
"$",
"k",
"=>",
"$",
"expression",
")",
"{",
"if",
"(",
"$",
"expression",
"instanceof",
"ExpressionInterface",
")",
"{",
"$",
"value",
"=",
"$",
"expression",
"->",
"sql",
"(",
"$",
"generator",
")",
";",
"$",
"expression",
"=",
"$",
"wrap",
"?",
"'('",
".",
"$",
"value",
".",
"')'",
":",
"$",
"value",
";",
"}",
"$",
"result",
"[",
"$",
"k",
"]",
"=",
"$",
"expression",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Helper function used to covert ExpressionInterface objects inside an array
into their string representation.
@param array $expressions list of strings and ExpressionInterface objects
@param \Cake\Database\ValueBinder $generator the placeholder generator to be used in expressions
@param bool $wrap Whether to wrap each expression object with parenthesis
@return array | [
"Helper",
"function",
"used",
"to",
"covert",
"ExpressionInterface",
"objects",
"inside",
"an",
"array",
"into",
"their",
"string",
"representation",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/QueryCompiler.php#L379-L391 |
210,826 | cakephp/cakephp | src/Collection/Iterator/StoppableIterator.php | StoppableIterator.valid | public function valid()
{
if (!parent::valid()) {
return false;
}
$current = $this->current();
$key = $this->key();
$condition = $this->_condition;
return !$condition($current, $key, $this->_innerIterator);
} | php | public function valid()
{
if (!parent::valid()) {
return false;
}
$current = $this->current();
$key = $this->key();
$condition = $this->_condition;
return !$condition($current, $key, $this->_innerIterator);
} | [
"public",
"function",
"valid",
"(",
")",
"{",
"if",
"(",
"!",
"parent",
"::",
"valid",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"current",
"=",
"$",
"this",
"->",
"current",
"(",
")",
";",
"$",
"key",
"=",
"$",
"this",
"->",
"key",
"(",
")",
";",
"$",
"condition",
"=",
"$",
"this",
"->",
"_condition",
";",
"return",
"!",
"$",
"condition",
"(",
"$",
"current",
",",
"$",
"key",
",",
"$",
"this",
"->",
"_innerIterator",
")",
";",
"}"
] | Evaluates the condition and returns its result, this controls
whether or not more results will be yielded.
@return bool | [
"Evaluates",
"the",
"condition",
"and",
"returns",
"its",
"result",
"this",
"controls",
"whether",
"or",
"not",
"more",
"results",
"will",
"be",
"yielded",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Collection/Iterator/StoppableIterator.php#L71-L82 |
210,827 | cakephp/cakephp | src/Database/Driver.php | Driver.connection | public function connection($connection = null)
{
deprecationWarning(
get_called_class() . '::connection() is deprecated. ' .
'Use setConnection()/getConnection() instead.'
);
if ($connection !== null) {
$this->_connection = $connection;
}
return $this->_connection;
} | php | public function connection($connection = null)
{
deprecationWarning(
get_called_class() . '::connection() is deprecated. ' .
'Use setConnection()/getConnection() instead.'
);
if ($connection !== null) {
$this->_connection = $connection;
}
return $this->_connection;
} | [
"public",
"function",
"connection",
"(",
"$",
"connection",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"get_called_class",
"(",
")",
".",
"'::connection() is deprecated. '",
".",
"'Use setConnection()/getConnection() instead.'",
")",
";",
"if",
"(",
"$",
"connection",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"_connection",
"=",
"$",
"connection",
";",
"}",
"return",
"$",
"this",
"->",
"_connection",
";",
"}"
] | Returns correct connection resource or object that is internally used
If first argument is passed, it will set internal connection object or
result to the value passed.
@param mixed $connection The PDO connection instance.
@return mixed Connection object used internally.
@deprecated 3.6.0 Use getConnection()/setConnection() instead. | [
"Returns",
"correct",
"connection",
"resource",
"or",
"object",
"that",
"is",
"internally",
"used",
"If",
"first",
"argument",
"is",
"passed",
"it",
"will",
"set",
"internal",
"connection",
"object",
"or",
"result",
"to",
"the",
"value",
"passed",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Driver.php#L121-L132 |
210,828 | cakephp/cakephp | src/Database/Driver.php | Driver.autoQuoting | public function autoQuoting($enable = null)
{
deprecationWarning(
'Driver::autoQuoting() is deprecated. ' .
'Use Driver::enableAutoQuoting()/isAutoQuotingEnabled() instead.'
);
if ($enable !== null) {
$this->enableAutoQuoting($enable);
}
return $this->isAutoQuotingEnabled();
} | php | public function autoQuoting($enable = null)
{
deprecationWarning(
'Driver::autoQuoting() is deprecated. ' .
'Use Driver::enableAutoQuoting()/isAutoQuotingEnabled() instead.'
);
if ($enable !== null) {
$this->enableAutoQuoting($enable);
}
return $this->isAutoQuotingEnabled();
} | [
"public",
"function",
"autoQuoting",
"(",
"$",
"enable",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"'Driver::autoQuoting() is deprecated. '",
".",
"'Use Driver::enableAutoQuoting()/isAutoQuotingEnabled() instead.'",
")",
";",
"if",
"(",
"$",
"enable",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"enableAutoQuoting",
"(",
"$",
"enable",
")",
";",
"}",
"return",
"$",
"this",
"->",
"isAutoQuotingEnabled",
"(",
")",
";",
"}"
] | Returns whether or not this driver should automatically quote identifiers
in queries
If called with a boolean argument, it will toggle the auto quoting setting
to the passed value
@deprecated 3.4.0 use enableAutoQuoting()/isAutoQuotingEnabled() instead.
@param bool|null $enable Whether to enable auto quoting
@return bool | [
"Returns",
"whether",
"or",
"not",
"this",
"driver",
"should",
"automatically",
"quote",
"identifiers",
"in",
"queries"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Driver.php#L396-L407 |
210,829 | cakephp/cakephp | src/View/Form/FormContext.php | FormContext._schemaDefault | protected function _schemaDefault($field)
{
$field = $this->_form->schema()->field($field);
if ($field) {
return $field['default'];
}
return null;
} | php | protected function _schemaDefault($field)
{
$field = $this->_form->schema()->field($field);
if ($field) {
return $field['default'];
}
return null;
} | [
"protected",
"function",
"_schemaDefault",
"(",
"$",
"field",
")",
"{",
"$",
"field",
"=",
"$",
"this",
"->",
"_form",
"->",
"schema",
"(",
")",
"->",
"field",
"(",
"$",
"field",
")",
";",
"if",
"(",
"$",
"field",
")",
"{",
"return",
"$",
"field",
"[",
"'default'",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Get default value from form schema for given field.
@param string $field Field name.
@return mixed | [
"Get",
"default",
"value",
"from",
"form",
"schema",
"for",
"given",
"field",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Form/FormContext.php#L115-L123 |
210,830 | cakephp/cakephp | src/View/ViewBuilder.php | ViewBuilder.setVars | public function setVars($data, $merge = true)
{
if ($merge) {
$this->_vars = $data + $this->_vars;
} else {
$this->_vars = $data;
}
return $this;
} | php | public function setVars($data, $merge = true)
{
if ($merge) {
$this->_vars = $data + $this->_vars;
} else {
$this->_vars = $data;
}
return $this;
} | [
"public",
"function",
"setVars",
"(",
"$",
"data",
",",
"$",
"merge",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"merge",
")",
"{",
"$",
"this",
"->",
"_vars",
"=",
"$",
"data",
"+",
"$",
"this",
"->",
"_vars",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_vars",
"=",
"$",
"data",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Saves view vars for use inside templates.
@param array $data Array of data.
@param bool $merge Whether to merge with existing vars, default true.
@return $this | [
"Saves",
"view",
"vars",
"for",
"use",
"inside",
"templates",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/ViewBuilder.php#L144-L153 |
210,831 | cakephp/cakephp | src/View/ViewBuilder.php | ViewBuilder.autoLayout | public function autoLayout($enable = null)
{
deprecationWarning('ViewBuilder::autoLayout() is deprecated. Use ViewBuilder::enableAutoLayout() or ViewBuilder::isAutoLayoutEnable() instead.');
if ($enable !== null) {
return $this->enableAutoLayout($enable);
}
return $this->isAutoLayoutEnabled();
} | php | public function autoLayout($enable = null)
{
deprecationWarning('ViewBuilder::autoLayout() is deprecated. Use ViewBuilder::enableAutoLayout() or ViewBuilder::isAutoLayoutEnable() instead.');
if ($enable !== null) {
return $this->enableAutoLayout($enable);
}
return $this->isAutoLayoutEnabled();
} | [
"public",
"function",
"autoLayout",
"(",
"$",
"enable",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"'ViewBuilder::autoLayout() is deprecated. Use ViewBuilder::enableAutoLayout() or ViewBuilder::isAutoLayoutEnable() instead.'",
")",
";",
"if",
"(",
"$",
"enable",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"enableAutoLayout",
"(",
"$",
"enable",
")",
";",
"}",
"return",
"$",
"this",
"->",
"isAutoLayoutEnabled",
"(",
")",
";",
"}"
] | Turns on or off CakePHP's conventional mode of applying layout files.
On by default. Setting to off means that layouts will not be
automatically applied to rendered views.
@deprecated 3.4.0 Use enableAutoLayout()/isAutoLayoutEnabled() instead.
@param bool|null $enable Boolean to turn on/off. If null returns current value.
@return bool|$this | [
"Turns",
"on",
"or",
"off",
"CakePHP",
"s",
"conventional",
"mode",
"of",
"applying",
"layout",
"files",
".",
"On",
"by",
"default",
".",
"Setting",
"to",
"off",
"means",
"that",
"layouts",
"will",
"not",
"be",
"automatically",
"applied",
"to",
"rendered",
"views",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/ViewBuilder.php#L317-L325 |
210,832 | cakephp/cakephp | src/View/ViewBuilder.php | ViewBuilder.plugin | public function plugin($name = null)
{
deprecationWarning('ViewBuilder::plugin() is deprecated. Use ViewBuilder::setPlugin() or ViewBuilder::getPlugin() instead.');
if ($name !== null) {
return $this->setPlugin($name);
}
return $this->getPlugin();
} | php | public function plugin($name = null)
{
deprecationWarning('ViewBuilder::plugin() is deprecated. Use ViewBuilder::setPlugin() or ViewBuilder::getPlugin() instead.');
if ($name !== null) {
return $this->setPlugin($name);
}
return $this->getPlugin();
} | [
"public",
"function",
"plugin",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"'ViewBuilder::plugin() is deprecated. Use ViewBuilder::setPlugin() or ViewBuilder::getPlugin() instead.'",
")",
";",
"if",
"(",
"$",
"name",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"setPlugin",
"(",
"$",
"name",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getPlugin",
"(",
")",
";",
"}"
] | The plugin name to use
@deprecated 3.4.0 Use setPlugin()/getPlugin() instead.
@param string|null|false $name Plugin name. If null returns current plugin.
Use false to remove the current plugin name.
@return string|false|null|$this | [
"The",
"plugin",
"name",
"to",
"use"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/ViewBuilder.php#L361-L369 |
210,833 | cakephp/cakephp | src/View/ViewBuilder.php | ViewBuilder.setHelpers | public function setHelpers(array $helpers, $merge = true)
{
if ($merge) {
$helpers = array_merge($this->_helpers, $helpers);
}
$this->_helpers = $helpers;
return $this;
} | php | public function setHelpers(array $helpers, $merge = true)
{
if ($merge) {
$helpers = array_merge($this->_helpers, $helpers);
}
$this->_helpers = $helpers;
return $this;
} | [
"public",
"function",
"setHelpers",
"(",
"array",
"$",
"helpers",
",",
"$",
"merge",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"merge",
")",
"{",
"$",
"helpers",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"_helpers",
",",
"$",
"helpers",
")",
";",
"}",
"$",
"this",
"->",
"_helpers",
"=",
"$",
"helpers",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the helpers to use.
@param array $helpers Helpers to use.
@param bool $merge Whether or not to merge existing data with the new data.
@return $this | [
"Sets",
"the",
"helpers",
"to",
"use",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/ViewBuilder.php#L378-L386 |
210,834 | cakephp/cakephp | src/View/ViewBuilder.php | ViewBuilder.helpers | public function helpers(array $helpers = null, $merge = true)
{
deprecationWarning('ViewBuilder::helpers() is deprecated. Use ViewBuilder::setHelpers() or ViewBuilder::getHelpers() instead.');
if ($helpers !== null) {
return $this->setHelpers($helpers, $merge);
}
return $this->getHelpers();
} | php | public function helpers(array $helpers = null, $merge = true)
{
deprecationWarning('ViewBuilder::helpers() is deprecated. Use ViewBuilder::setHelpers() or ViewBuilder::getHelpers() instead.');
if ($helpers !== null) {
return $this->setHelpers($helpers, $merge);
}
return $this->getHelpers();
} | [
"public",
"function",
"helpers",
"(",
"array",
"$",
"helpers",
"=",
"null",
",",
"$",
"merge",
"=",
"true",
")",
"{",
"deprecationWarning",
"(",
"'ViewBuilder::helpers() is deprecated. Use ViewBuilder::setHelpers() or ViewBuilder::getHelpers() instead.'",
")",
";",
"if",
"(",
"$",
"helpers",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"setHelpers",
"(",
"$",
"helpers",
",",
"$",
"merge",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getHelpers",
"(",
")",
";",
"}"
] | The helpers to use
@deprecated 3.4.0 Use setHelpers()/getHelpers() instead.
@param array|null $helpers Helpers to use.
@param bool $merge Whether or not to merge existing data with the new data.
@return array|$this | [
"The",
"helpers",
"to",
"use"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/ViewBuilder.php#L406-L414 |
210,835 | cakephp/cakephp | src/View/ViewBuilder.php | ViewBuilder.setOptions | public function setOptions(array $options, $merge = true)
{
if ($merge) {
$options = array_merge($this->_options, $options);
}
$this->_options = $options;
return $this;
} | php | public function setOptions(array $options, $merge = true)
{
if ($merge) {
$options = array_merge($this->_options, $options);
}
$this->_options = $options;
return $this;
} | [
"public",
"function",
"setOptions",
"(",
"array",
"$",
"options",
",",
"$",
"merge",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"merge",
")",
"{",
"$",
"options",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"_options",
",",
"$",
"options",
")",
";",
"}",
"$",
"this",
"->",
"_options",
"=",
"$",
"options",
";",
"return",
"$",
"this",
";",
"}"
] | Sets additional options for the view.
This lets you provide custom constructor arguments to application/plugin view classes.
@param array $options An array of options.
@param bool $merge Whether or not to merge existing data with the new data.
@return $this | [
"Sets",
"additional",
"options",
"for",
"the",
"view",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/ViewBuilder.php#L556-L564 |
210,836 | cakephp/cakephp | src/View/ViewBuilder.php | ViewBuilder.options | public function options(array $options = null, $merge = true)
{
deprecationWarning('ViewBuilder::options() is deprecated. Use ViewBuilder::setOptions() or ViewBuilder::getOptions() instead.');
if ($options !== null) {
return $this->setOptions($options, $merge);
}
return $this->getOptions();
} | php | public function options(array $options = null, $merge = true)
{
deprecationWarning('ViewBuilder::options() is deprecated. Use ViewBuilder::setOptions() or ViewBuilder::getOptions() instead.');
if ($options !== null) {
return $this->setOptions($options, $merge);
}
return $this->getOptions();
} | [
"public",
"function",
"options",
"(",
"array",
"$",
"options",
"=",
"null",
",",
"$",
"merge",
"=",
"true",
")",
"{",
"deprecationWarning",
"(",
"'ViewBuilder::options() is deprecated. Use ViewBuilder::setOptions() or ViewBuilder::getOptions() instead.'",
")",
";",
"if",
"(",
"$",
"options",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"setOptions",
"(",
"$",
"options",
",",
"$",
"merge",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getOptions",
"(",
")",
";",
"}"
] | Set additional options for the view.
This lets you provide custom constructor arguments to application/plugin view classes.
@deprecated 3.4.0 Use setOptions()/getOptions() instead.
@param array|null $options Either an array of options or null to get current options.
@param bool $merge Whether or not to merge existing data with the new data.
@return array|$this | [
"Set",
"additional",
"options",
"for",
"the",
"view",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/ViewBuilder.php#L586-L594 |
210,837 | cakephp/cakephp | src/View/ViewBuilder.php | ViewBuilder.build | public function build($vars = [], ServerRequest $request = null, Response $response = null, EventManager $events = null)
{
$className = $this->_className;
if ($className === null) {
$className = App::className('App', 'View', 'View') ?: 'Cake\View\View';
}
if ($className === 'View') {
$className = App::className($className, 'View');
} else {
$className = App::className($className, 'View', 'View');
}
if (!$className) {
throw new MissingViewException(['class' => $this->_className]);
}
$data = [
'name' => $this->_name,
'templatePath' => $this->_templatePath,
'template' => $this->_template,
'plugin' => $this->_plugin,
'theme' => $this->_theme,
'layout' => $this->_layout,
'autoLayout' => $this->_autoLayout,
'layoutPath' => $this->_layoutPath,
'helpers' => $this->_helpers,
'viewVars' => $vars + $this->_vars,
];
$data += $this->_options;
return new $className($request, $response, $events, $data);
} | php | public function build($vars = [], ServerRequest $request = null, Response $response = null, EventManager $events = null)
{
$className = $this->_className;
if ($className === null) {
$className = App::className('App', 'View', 'View') ?: 'Cake\View\View';
}
if ($className === 'View') {
$className = App::className($className, 'View');
} else {
$className = App::className($className, 'View', 'View');
}
if (!$className) {
throw new MissingViewException(['class' => $this->_className]);
}
$data = [
'name' => $this->_name,
'templatePath' => $this->_templatePath,
'template' => $this->_template,
'plugin' => $this->_plugin,
'theme' => $this->_theme,
'layout' => $this->_layout,
'autoLayout' => $this->_autoLayout,
'layoutPath' => $this->_layoutPath,
'helpers' => $this->_helpers,
'viewVars' => $vars + $this->_vars,
];
$data += $this->_options;
return new $className($request, $response, $events, $data);
} | [
"public",
"function",
"build",
"(",
"$",
"vars",
"=",
"[",
"]",
",",
"ServerRequest",
"$",
"request",
"=",
"null",
",",
"Response",
"$",
"response",
"=",
"null",
",",
"EventManager",
"$",
"events",
"=",
"null",
")",
"{",
"$",
"className",
"=",
"$",
"this",
"->",
"_className",
";",
"if",
"(",
"$",
"className",
"===",
"null",
")",
"{",
"$",
"className",
"=",
"App",
"::",
"className",
"(",
"'App'",
",",
"'View'",
",",
"'View'",
")",
"?",
":",
"'Cake\\View\\View'",
";",
"}",
"if",
"(",
"$",
"className",
"===",
"'View'",
")",
"{",
"$",
"className",
"=",
"App",
"::",
"className",
"(",
"$",
"className",
",",
"'View'",
")",
";",
"}",
"else",
"{",
"$",
"className",
"=",
"App",
"::",
"className",
"(",
"$",
"className",
",",
"'View'",
",",
"'View'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"className",
")",
"{",
"throw",
"new",
"MissingViewException",
"(",
"[",
"'class'",
"=>",
"$",
"this",
"->",
"_className",
"]",
")",
";",
"}",
"$",
"data",
"=",
"[",
"'name'",
"=>",
"$",
"this",
"->",
"_name",
",",
"'templatePath'",
"=>",
"$",
"this",
"->",
"_templatePath",
",",
"'template'",
"=>",
"$",
"this",
"->",
"_template",
",",
"'plugin'",
"=>",
"$",
"this",
"->",
"_plugin",
",",
"'theme'",
"=>",
"$",
"this",
"->",
"_theme",
",",
"'layout'",
"=>",
"$",
"this",
"->",
"_layout",
",",
"'autoLayout'",
"=>",
"$",
"this",
"->",
"_autoLayout",
",",
"'layoutPath'",
"=>",
"$",
"this",
"->",
"_layoutPath",
",",
"'helpers'",
"=>",
"$",
"this",
"->",
"_helpers",
",",
"'viewVars'",
"=>",
"$",
"vars",
"+",
"$",
"this",
"->",
"_vars",
",",
"]",
";",
"$",
"data",
"+=",
"$",
"this",
"->",
"_options",
";",
"return",
"new",
"$",
"className",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"events",
",",
"$",
"data",
")",
";",
"}"
] | Using the data in the builder, create a view instance.
If className() is null, App\View\AppView will be used.
If that class does not exist, then Cake\View\View will be used.
@param array $vars The view variables/context to use.
@param \Cake\Http\ServerRequest|null $request The request to use.
@param \Cake\Http\Response|null $response The response to use.
@param \Cake\Event\EventManager|null $events The event manager to use.
@return \Cake\View\View
@throws \Cake\View\Exception\MissingViewException | [
"Using",
"the",
"data",
"in",
"the",
"builder",
"create",
"a",
"view",
"instance",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/ViewBuilder.php#L698-L728 |
210,838 | cakephp/cakephp | src/View/ViewBuilder.php | ViewBuilder.jsonSerialize | public function jsonSerialize()
{
$properties = [
'_templatePath', '_template', '_plugin', '_theme', '_layout', '_autoLayout',
'_layoutPath', '_name', '_className', '_options', '_helpers'
];
$array = [];
foreach ($properties as $property) {
$array[$property] = $this->{$property};
}
return array_filter($array, function ($i) {
return !is_array($i) && strlen($i) || !empty($i);
});
} | php | public function jsonSerialize()
{
$properties = [
'_templatePath', '_template', '_plugin', '_theme', '_layout', '_autoLayout',
'_layoutPath', '_name', '_className', '_options', '_helpers'
];
$array = [];
foreach ($properties as $property) {
$array[$property] = $this->{$property};
}
return array_filter($array, function ($i) {
return !is_array($i) && strlen($i) || !empty($i);
});
} | [
"public",
"function",
"jsonSerialize",
"(",
")",
"{",
"$",
"properties",
"=",
"[",
"'_templatePath'",
",",
"'_template'",
",",
"'_plugin'",
",",
"'_theme'",
",",
"'_layout'",
",",
"'_autoLayout'",
",",
"'_layoutPath'",
",",
"'_name'",
",",
"'_className'",
",",
"'_options'",
",",
"'_helpers'",
"]",
";",
"$",
"array",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"property",
")",
"{",
"$",
"array",
"[",
"$",
"property",
"]",
"=",
"$",
"this",
"->",
"{",
"$",
"property",
"}",
";",
"}",
"return",
"array_filter",
"(",
"$",
"array",
",",
"function",
"(",
"$",
"i",
")",
"{",
"return",
"!",
"is_array",
"(",
"$",
"i",
")",
"&&",
"strlen",
"(",
"$",
"i",
")",
"||",
"!",
"empty",
"(",
"$",
"i",
")",
";",
"}",
")",
";",
"}"
] | Serializes the view builder object to a value that can be natively
serialized and re-used to clone this builder instance.
@return array Serializable array of configuration properties. | [
"Serializes",
"the",
"view",
"builder",
"object",
"to",
"a",
"value",
"that",
"can",
"be",
"natively",
"serialized",
"and",
"re",
"-",
"used",
"to",
"clone",
"this",
"builder",
"instance",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/ViewBuilder.php#L736-L752 |
210,839 | cakephp/cakephp | src/View/ViewBuilder.php | ViewBuilder.createFromArray | public function createFromArray($config)
{
foreach ($config as $property => $value) {
$this->{$property} = $value;
}
return $this;
} | php | public function createFromArray($config)
{
foreach ($config as $property => $value) {
$this->{$property} = $value;
}
return $this;
} | [
"public",
"function",
"createFromArray",
"(",
"$",
"config",
")",
"{",
"foreach",
"(",
"$",
"config",
"as",
"$",
"property",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"{",
"$",
"property",
"}",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Configures a view builder instance from serialized config.
@param array $config View builder configuration array.
@return $this Configured view builder instance. | [
"Configures",
"a",
"view",
"builder",
"instance",
"from",
"serialized",
"config",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/ViewBuilder.php#L760-L767 |
210,840 | cakephp/cakephp | src/Filesystem/Folder.php | Folder.find | public function find($regexpPattern = '.*', $sort = false)
{
list(, $files) = $this->read($sort);
return array_values(preg_grep('/^' . $regexpPattern . '$/i', $files));
} | php | public function find($regexpPattern = '.*', $sort = false)
{
list(, $files) = $this->read($sort);
return array_values(preg_grep('/^' . $regexpPattern . '$/i', $files));
} | [
"public",
"function",
"find",
"(",
"$",
"regexpPattern",
"=",
"'.*'",
",",
"$",
"sort",
"=",
"false",
")",
"{",
"list",
"(",
",",
"$",
"files",
")",
"=",
"$",
"this",
"->",
"read",
"(",
"$",
"sort",
")",
";",
"return",
"array_values",
"(",
"preg_grep",
"(",
"'/^'",
".",
"$",
"regexpPattern",
".",
"'$/i'",
",",
"$",
"files",
")",
")",
";",
"}"
] | Returns an array of all matching files in current directory.
@param string $regexpPattern Preg_match pattern (Defaults to: .*)
@param bool $sort Whether results should be sorted.
@return array Files that match given pattern | [
"Returns",
"an",
"array",
"of",
"all",
"matching",
"files",
"in",
"current",
"directory",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Filesystem/Folder.php#L258-L263 |
210,841 | cakephp/cakephp | src/Filesystem/Folder.php | Folder.findRecursive | public function findRecursive($pattern = '.*', $sort = false)
{
if (!$this->pwd()) {
return [];
}
$startsOn = $this->path;
$out = $this->_findRecursive($pattern, $sort);
$this->cd($startsOn);
return $out;
} | php | public function findRecursive($pattern = '.*', $sort = false)
{
if (!$this->pwd()) {
return [];
}
$startsOn = $this->path;
$out = $this->_findRecursive($pattern, $sort);
$this->cd($startsOn);
return $out;
} | [
"public",
"function",
"findRecursive",
"(",
"$",
"pattern",
"=",
"'.*'",
",",
"$",
"sort",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"pwd",
"(",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"startsOn",
"=",
"$",
"this",
"->",
"path",
";",
"$",
"out",
"=",
"$",
"this",
"->",
"_findRecursive",
"(",
"$",
"pattern",
",",
"$",
"sort",
")",
";",
"$",
"this",
"->",
"cd",
"(",
"$",
"startsOn",
")",
";",
"return",
"$",
"out",
";",
"}"
] | Returns an array of all matching files in and below current directory.
@param string $pattern Preg_match pattern (Defaults to: .*)
@param bool $sort Whether results should be sorted.
@return array Files matching $pattern | [
"Returns",
"an",
"array",
"of",
"all",
"matching",
"files",
"in",
"and",
"below",
"current",
"directory",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Filesystem/Folder.php#L272-L282 |
210,842 | cakephp/cakephp | src/Filesystem/Folder.php | Folder.inCakePath | public function inCakePath($path = '')
{
deprecationWarning('Folder::inCakePath() is deprecated. Use Folder::inPath() instead.');
$dir = substr(Folder::slashTerm(ROOT), 0, -1);
$newdir = $dir . $path;
return $this->inPath($newdir);
} | php | public function inCakePath($path = '')
{
deprecationWarning('Folder::inCakePath() is deprecated. Use Folder::inPath() instead.');
$dir = substr(Folder::slashTerm(ROOT), 0, -1);
$newdir = $dir . $path;
return $this->inPath($newdir);
} | [
"public",
"function",
"inCakePath",
"(",
"$",
"path",
"=",
"''",
")",
"{",
"deprecationWarning",
"(",
"'Folder::inCakePath() is deprecated. Use Folder::inPath() instead.'",
")",
";",
"$",
"dir",
"=",
"substr",
"(",
"Folder",
"::",
"slashTerm",
"(",
"ROOT",
")",
",",
"0",
",",
"-",
"1",
")",
";",
"$",
"newdir",
"=",
"$",
"dir",
".",
"$",
"path",
";",
"return",
"$",
"this",
"->",
"inPath",
"(",
"$",
"newdir",
")",
";",
"}"
] | Returns true if the Folder is in the given Cake path.
@param string $path The path to check.
@return bool
@deprecated 3.2.12 This method will be removed in 4.0.0. Use inPath() instead. | [
"Returns",
"true",
"if",
"the",
"Folder",
"is",
"in",
"the",
"given",
"Cake",
"path",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Filesystem/Folder.php#L429-L436 |
210,843 | cakephp/cakephp | src/Filesystem/Folder.php | Folder.subdirectories | public function subdirectories($path = null, $fullPath = true)
{
if (!$path) {
$path = $this->path;
}
$subdirectories = [];
try {
$iterator = new DirectoryIterator($path);
} catch (Exception $e) {
return [];
}
foreach ($iterator as $item) {
if (!$item->isDir() || $item->isDot()) {
continue;
}
$subdirectories[] = $fullPath ? $item->getRealPath() : $item->getFilename();
}
return $subdirectories;
} | php | public function subdirectories($path = null, $fullPath = true)
{
if (!$path) {
$path = $this->path;
}
$subdirectories = [];
try {
$iterator = new DirectoryIterator($path);
} catch (Exception $e) {
return [];
}
foreach ($iterator as $item) {
if (!$item->isDir() || $item->isDot()) {
continue;
}
$subdirectories[] = $fullPath ? $item->getRealPath() : $item->getFilename();
}
return $subdirectories;
} | [
"public",
"function",
"subdirectories",
"(",
"$",
"path",
"=",
"null",
",",
"$",
"fullPath",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"path",
";",
"}",
"$",
"subdirectories",
"=",
"[",
"]",
";",
"try",
"{",
"$",
"iterator",
"=",
"new",
"DirectoryIterator",
"(",
"$",
"path",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"[",
"]",
";",
"}",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"$",
"item",
"->",
"isDir",
"(",
")",
"||",
"$",
"item",
"->",
"isDot",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"subdirectories",
"[",
"]",
"=",
"$",
"fullPath",
"?",
"$",
"item",
"->",
"getRealPath",
"(",
")",
":",
"$",
"item",
"->",
"getFilename",
"(",
")",
";",
"}",
"return",
"$",
"subdirectories",
";",
"}"
] | Returns an array of subdirectories for the provided or current path.
@param string|null $path The directory path to get subdirectories for.
@param bool $fullPath Whether to return the full path or only the directory name.
@return array Array of subdirectories for the provided or current path. | [
"Returns",
"an",
"array",
"of",
"subdirectories",
"for",
"the",
"provided",
"or",
"current",
"path",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Filesystem/Folder.php#L530-L551 |
210,844 | cakephp/cakephp | src/Filesystem/Folder.php | Folder.create | public function create($pathname, $mode = false)
{
if (is_dir($pathname) || empty($pathname)) {
return true;
}
if (!self::isAbsolute($pathname)) {
$pathname = self::addPathElement($this->pwd(), $pathname);
}
if (!$mode) {
$mode = $this->mode;
}
if (is_file($pathname)) {
$this->_errors[] = sprintf('%s is a file', $pathname);
return false;
}
$pathname = rtrim($pathname, DIRECTORY_SEPARATOR);
$nextPathname = substr($pathname, 0, strrpos($pathname, DIRECTORY_SEPARATOR));
if ($this->create($nextPathname, $mode)) {
if (!file_exists($pathname)) {
$old = umask(0);
if (mkdir($pathname, $mode, true)) {
umask($old);
$this->_messages[] = sprintf('%s created', $pathname);
return true;
}
umask($old);
$this->_errors[] = sprintf('%s NOT created', $pathname);
return false;
}
}
return false;
} | php | public function create($pathname, $mode = false)
{
if (is_dir($pathname) || empty($pathname)) {
return true;
}
if (!self::isAbsolute($pathname)) {
$pathname = self::addPathElement($this->pwd(), $pathname);
}
if (!$mode) {
$mode = $this->mode;
}
if (is_file($pathname)) {
$this->_errors[] = sprintf('%s is a file', $pathname);
return false;
}
$pathname = rtrim($pathname, DIRECTORY_SEPARATOR);
$nextPathname = substr($pathname, 0, strrpos($pathname, DIRECTORY_SEPARATOR));
if ($this->create($nextPathname, $mode)) {
if (!file_exists($pathname)) {
$old = umask(0);
if (mkdir($pathname, $mode, true)) {
umask($old);
$this->_messages[] = sprintf('%s created', $pathname);
return true;
}
umask($old);
$this->_errors[] = sprintf('%s NOT created', $pathname);
return false;
}
}
return false;
} | [
"public",
"function",
"create",
"(",
"$",
"pathname",
",",
"$",
"mode",
"=",
"false",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"pathname",
")",
"||",
"empty",
"(",
"$",
"pathname",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"self",
"::",
"isAbsolute",
"(",
"$",
"pathname",
")",
")",
"{",
"$",
"pathname",
"=",
"self",
"::",
"addPathElement",
"(",
"$",
"this",
"->",
"pwd",
"(",
")",
",",
"$",
"pathname",
")",
";",
"}",
"if",
"(",
"!",
"$",
"mode",
")",
"{",
"$",
"mode",
"=",
"$",
"this",
"->",
"mode",
";",
"}",
"if",
"(",
"is_file",
"(",
"$",
"pathname",
")",
")",
"{",
"$",
"this",
"->",
"_errors",
"[",
"]",
"=",
"sprintf",
"(",
"'%s is a file'",
",",
"$",
"pathname",
")",
";",
"return",
"false",
";",
"}",
"$",
"pathname",
"=",
"rtrim",
"(",
"$",
"pathname",
",",
"DIRECTORY_SEPARATOR",
")",
";",
"$",
"nextPathname",
"=",
"substr",
"(",
"$",
"pathname",
",",
"0",
",",
"strrpos",
"(",
"$",
"pathname",
",",
"DIRECTORY_SEPARATOR",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"create",
"(",
"$",
"nextPathname",
",",
"$",
"mode",
")",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"pathname",
")",
")",
"{",
"$",
"old",
"=",
"umask",
"(",
"0",
")",
";",
"if",
"(",
"mkdir",
"(",
"$",
"pathname",
",",
"$",
"mode",
",",
"true",
")",
")",
"{",
"umask",
"(",
"$",
"old",
")",
";",
"$",
"this",
"->",
"_messages",
"[",
"]",
"=",
"sprintf",
"(",
"'%s created'",
",",
"$",
"pathname",
")",
";",
"return",
"true",
";",
"}",
"umask",
"(",
"$",
"old",
")",
";",
"$",
"this",
"->",
"_errors",
"[",
"]",
"=",
"sprintf",
"(",
"'%s NOT created'",
",",
"$",
"pathname",
")",
";",
"return",
"false",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Create a directory structure recursively.
Can be used to create deep path structures like `/foo/bar/baz/shoe/horn`
@param string $pathname The directory structure to create. Either an absolute or relative
path. If the path is relative and exists in the process' cwd it will not be created.
Otherwise relative paths will be prefixed with the current pwd().
@param int|bool $mode octal value 0755
@return bool Returns TRUE on success, FALSE on failure | [
"Create",
"a",
"directory",
"structure",
"recursively",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Filesystem/Folder.php#L636-L675 |
210,845 | cakephp/cakephp | src/Filesystem/Folder.php | Folder.dirsize | public function dirsize()
{
$size = 0;
$directory = Folder::slashTerm($this->path);
$stack = [$directory];
$count = count($stack);
for ($i = 0, $j = $count; $i < $j; $i++) {
if (is_file($stack[$i])) {
$size += filesize($stack[$i]);
} elseif (is_dir($stack[$i])) {
$dir = dir($stack[$i]);
if ($dir) {
while (($entry = $dir->read()) !== false) {
if ($entry === '.' || $entry === '..') {
continue;
}
$add = $stack[$i] . $entry;
if (is_dir($stack[$i] . $entry)) {
$add = Folder::slashTerm($add);
}
$stack[] = $add;
}
$dir->close();
}
}
$j = count($stack);
}
return $size;
} | php | public function dirsize()
{
$size = 0;
$directory = Folder::slashTerm($this->path);
$stack = [$directory];
$count = count($stack);
for ($i = 0, $j = $count; $i < $j; $i++) {
if (is_file($stack[$i])) {
$size += filesize($stack[$i]);
} elseif (is_dir($stack[$i])) {
$dir = dir($stack[$i]);
if ($dir) {
while (($entry = $dir->read()) !== false) {
if ($entry === '.' || $entry === '..') {
continue;
}
$add = $stack[$i] . $entry;
if (is_dir($stack[$i] . $entry)) {
$add = Folder::slashTerm($add);
}
$stack[] = $add;
}
$dir->close();
}
}
$j = count($stack);
}
return $size;
} | [
"public",
"function",
"dirsize",
"(",
")",
"{",
"$",
"size",
"=",
"0",
";",
"$",
"directory",
"=",
"Folder",
"::",
"slashTerm",
"(",
"$",
"this",
"->",
"path",
")",
";",
"$",
"stack",
"=",
"[",
"$",
"directory",
"]",
";",
"$",
"count",
"=",
"count",
"(",
"$",
"stack",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"j",
"=",
"$",
"count",
";",
"$",
"i",
"<",
"$",
"j",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"stack",
"[",
"$",
"i",
"]",
")",
")",
"{",
"$",
"size",
"+=",
"filesize",
"(",
"$",
"stack",
"[",
"$",
"i",
"]",
")",
";",
"}",
"elseif",
"(",
"is_dir",
"(",
"$",
"stack",
"[",
"$",
"i",
"]",
")",
")",
"{",
"$",
"dir",
"=",
"dir",
"(",
"$",
"stack",
"[",
"$",
"i",
"]",
")",
";",
"if",
"(",
"$",
"dir",
")",
"{",
"while",
"(",
"(",
"$",
"entry",
"=",
"$",
"dir",
"->",
"read",
"(",
")",
")",
"!==",
"false",
")",
"{",
"if",
"(",
"$",
"entry",
"===",
"'.'",
"||",
"$",
"entry",
"===",
"'..'",
")",
"{",
"continue",
";",
"}",
"$",
"add",
"=",
"$",
"stack",
"[",
"$",
"i",
"]",
".",
"$",
"entry",
";",
"if",
"(",
"is_dir",
"(",
"$",
"stack",
"[",
"$",
"i",
"]",
".",
"$",
"entry",
")",
")",
"{",
"$",
"add",
"=",
"Folder",
"::",
"slashTerm",
"(",
"$",
"add",
")",
";",
"}",
"$",
"stack",
"[",
"]",
"=",
"$",
"add",
";",
"}",
"$",
"dir",
"->",
"close",
"(",
")",
";",
"}",
"}",
"$",
"j",
"=",
"count",
"(",
"$",
"stack",
")",
";",
"}",
"return",
"$",
"size",
";",
"}"
] | Returns the size in bytes of this Folder and its contents.
@return int size in bytes of current folder | [
"Returns",
"the",
"size",
"in",
"bytes",
"of",
"this",
"Folder",
"and",
"its",
"contents",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Filesystem/Folder.php#L682-L712 |
210,846 | cakephp/cakephp | src/Filesystem/Folder.php | Folder.delete | public function delete($path = null)
{
if (!$path) {
$path = $this->pwd();
}
if (!$path) {
return false;
}
$path = Folder::slashTerm($path);
if (is_dir($path)) {
try {
$directory = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::CURRENT_AS_SELF);
$iterator = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::CHILD_FIRST);
} catch (Exception $e) {
return false;
}
foreach ($iterator as $item) {
$filePath = $item->getPathname();
if ($item->isFile() || $item->isLink()) {
//@codingStandardsIgnoreStart
if (@unlink($filePath)) {
//@codingStandardsIgnoreEnd
$this->_messages[] = sprintf('%s removed', $filePath);
} else {
$this->_errors[] = sprintf('%s NOT removed', $filePath);
}
} elseif ($item->isDir() && !$item->isDot()) {
//@codingStandardsIgnoreStart
if (@rmdir($filePath)) {
//@codingStandardsIgnoreEnd
$this->_messages[] = sprintf('%s removed', $filePath);
} else {
$this->_errors[] = sprintf('%s NOT removed', $filePath);
return false;
}
}
}
$path = rtrim($path, DIRECTORY_SEPARATOR);
//@codingStandardsIgnoreStart
if (@rmdir($path)) {
//@codingStandardsIgnoreEnd
$this->_messages[] = sprintf('%s removed', $path);
} else {
$this->_errors[] = sprintf('%s NOT removed', $path);
return false;
}
}
return true;
} | php | public function delete($path = null)
{
if (!$path) {
$path = $this->pwd();
}
if (!$path) {
return false;
}
$path = Folder::slashTerm($path);
if (is_dir($path)) {
try {
$directory = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::CURRENT_AS_SELF);
$iterator = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::CHILD_FIRST);
} catch (Exception $e) {
return false;
}
foreach ($iterator as $item) {
$filePath = $item->getPathname();
if ($item->isFile() || $item->isLink()) {
//@codingStandardsIgnoreStart
if (@unlink($filePath)) {
//@codingStandardsIgnoreEnd
$this->_messages[] = sprintf('%s removed', $filePath);
} else {
$this->_errors[] = sprintf('%s NOT removed', $filePath);
}
} elseif ($item->isDir() && !$item->isDot()) {
//@codingStandardsIgnoreStart
if (@rmdir($filePath)) {
//@codingStandardsIgnoreEnd
$this->_messages[] = sprintf('%s removed', $filePath);
} else {
$this->_errors[] = sprintf('%s NOT removed', $filePath);
return false;
}
}
}
$path = rtrim($path, DIRECTORY_SEPARATOR);
//@codingStandardsIgnoreStart
if (@rmdir($path)) {
//@codingStandardsIgnoreEnd
$this->_messages[] = sprintf('%s removed', $path);
} else {
$this->_errors[] = sprintf('%s NOT removed', $path);
return false;
}
}
return true;
} | [
"public",
"function",
"delete",
"(",
"$",
"path",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"pwd",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"path",
")",
"{",
"return",
"false",
";",
"}",
"$",
"path",
"=",
"Folder",
"::",
"slashTerm",
"(",
"$",
"path",
")",
";",
"if",
"(",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"try",
"{",
"$",
"directory",
"=",
"new",
"RecursiveDirectoryIterator",
"(",
"$",
"path",
",",
"RecursiveDirectoryIterator",
"::",
"CURRENT_AS_SELF",
")",
";",
"$",
"iterator",
"=",
"new",
"RecursiveIteratorIterator",
"(",
"$",
"directory",
",",
"RecursiveIteratorIterator",
"::",
"CHILD_FIRST",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"item",
")",
"{",
"$",
"filePath",
"=",
"$",
"item",
"->",
"getPathname",
"(",
")",
";",
"if",
"(",
"$",
"item",
"->",
"isFile",
"(",
")",
"||",
"$",
"item",
"->",
"isLink",
"(",
")",
")",
"{",
"//@codingStandardsIgnoreStart",
"if",
"(",
"@",
"unlink",
"(",
"$",
"filePath",
")",
")",
"{",
"//@codingStandardsIgnoreEnd",
"$",
"this",
"->",
"_messages",
"[",
"]",
"=",
"sprintf",
"(",
"'%s removed'",
",",
"$",
"filePath",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_errors",
"[",
"]",
"=",
"sprintf",
"(",
"'%s NOT removed'",
",",
"$",
"filePath",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"item",
"->",
"isDir",
"(",
")",
"&&",
"!",
"$",
"item",
"->",
"isDot",
"(",
")",
")",
"{",
"//@codingStandardsIgnoreStart",
"if",
"(",
"@",
"rmdir",
"(",
"$",
"filePath",
")",
")",
"{",
"//@codingStandardsIgnoreEnd",
"$",
"this",
"->",
"_messages",
"[",
"]",
"=",
"sprintf",
"(",
"'%s removed'",
",",
"$",
"filePath",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_errors",
"[",
"]",
"=",
"sprintf",
"(",
"'%s NOT removed'",
",",
"$",
"filePath",
")",
";",
"return",
"false",
";",
"}",
"}",
"}",
"$",
"path",
"=",
"rtrim",
"(",
"$",
"path",
",",
"DIRECTORY_SEPARATOR",
")",
";",
"//@codingStandardsIgnoreStart",
"if",
"(",
"@",
"rmdir",
"(",
"$",
"path",
")",
")",
"{",
"//@codingStandardsIgnoreEnd",
"$",
"this",
"->",
"_messages",
"[",
"]",
"=",
"sprintf",
"(",
"'%s removed'",
",",
"$",
"path",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_errors",
"[",
"]",
"=",
"sprintf",
"(",
"'%s NOT removed'",
",",
"$",
"path",
")",
";",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Recursively Remove directories if the system allows.
@param string|null $path Path of directory to delete
@return bool Success | [
"Recursively",
"Remove",
"directories",
"if",
"the",
"system",
"allows",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Filesystem/Folder.php#L720-L773 |
210,847 | cakephp/cakephp | src/Filesystem/Folder.php | Folder.move | public function move($options)
{
$to = null;
if (is_string($options)) {
$to = $options;
$options = (array)$options;
}
$options += ['to' => $to, 'from' => $this->path, 'mode' => $this->mode, 'skip' => [], 'recursive' => true];
if ($this->copy($options) && $this->delete($options['from'])) {
return (bool)$this->cd($options['to']);
}
return false;
} | php | public function move($options)
{
$to = null;
if (is_string($options)) {
$to = $options;
$options = (array)$options;
}
$options += ['to' => $to, 'from' => $this->path, 'mode' => $this->mode, 'skip' => [], 'recursive' => true];
if ($this->copy($options) && $this->delete($options['from'])) {
return (bool)$this->cd($options['to']);
}
return false;
} | [
"public",
"function",
"move",
"(",
"$",
"options",
")",
"{",
"$",
"to",
"=",
"null",
";",
"if",
"(",
"is_string",
"(",
"$",
"options",
")",
")",
"{",
"$",
"to",
"=",
"$",
"options",
";",
"$",
"options",
"=",
"(",
"array",
")",
"$",
"options",
";",
"}",
"$",
"options",
"+=",
"[",
"'to'",
"=>",
"$",
"to",
",",
"'from'",
"=>",
"$",
"this",
"->",
"path",
",",
"'mode'",
"=>",
"$",
"this",
"->",
"mode",
",",
"'skip'",
"=>",
"[",
"]",
",",
"'recursive'",
"=>",
"true",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"copy",
"(",
"$",
"options",
")",
"&&",
"$",
"this",
"->",
"delete",
"(",
"$",
"options",
"[",
"'from'",
"]",
")",
")",
"{",
"return",
"(",
"bool",
")",
"$",
"this",
"->",
"cd",
"(",
"$",
"options",
"[",
"'to'",
"]",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Recursive directory move.
### Options
- `to` The directory to copy to.
- `from` The directory to copy from, this will cause a cd() to occur, changing the results of pwd().
- `chmod` The mode to copy the files/directories with.
- `skip` Files/directories to skip.
- `scheme` Folder::MERGE, Folder::OVERWRITE, Folder::SKIP
- `recursive` Whether to copy recursively or not (default: true - recursive)
@param array|string $options (to, from, chmod, skip, scheme)
@return bool Success | [
"Recursive",
"directory",
"move",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Filesystem/Folder.php#L897-L911 |
210,848 | cakephp/cakephp | src/Http/ResponseEmitter.php | ResponseEmitter.flush | protected function flush($maxBufferLevel = null)
{
if (null === $maxBufferLevel) {
$maxBufferLevel = ob_get_level();
}
while (ob_get_level() > $maxBufferLevel) {
ob_end_flush();
}
} | php | protected function flush($maxBufferLevel = null)
{
if (null === $maxBufferLevel) {
$maxBufferLevel = ob_get_level();
}
while (ob_get_level() > $maxBufferLevel) {
ob_end_flush();
}
} | [
"protected",
"function",
"flush",
"(",
"$",
"maxBufferLevel",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"maxBufferLevel",
")",
"{",
"$",
"maxBufferLevel",
"=",
"ob_get_level",
"(",
")",
";",
"}",
"while",
"(",
"ob_get_level",
"(",
")",
">",
"$",
"maxBufferLevel",
")",
"{",
"ob_end_flush",
"(",
")",
";",
"}",
"}"
] | Loops through the output buffer, flushing each, before emitting
the response.
@param int|null $maxBufferLevel Flush up to this buffer level.
@return void | [
"Loops",
"through",
"the",
"output",
"buffer",
"flushing",
"each",
"before",
"emitting",
"the",
"response",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ResponseEmitter.php#L266-L275 |
210,849 | cakephp/cakephp | src/Console/ConsoleOutput.php | ConsoleOutput.write | public function write($message, $newlines = 1)
{
if (is_array($message)) {
$message = implode(static::LF, $message);
}
return $this->_write($this->styleText($message . str_repeat(static::LF, $newlines)));
} | php | public function write($message, $newlines = 1)
{
if (is_array($message)) {
$message = implode(static::LF, $message);
}
return $this->_write($this->styleText($message . str_repeat(static::LF, $newlines)));
} | [
"public",
"function",
"write",
"(",
"$",
"message",
",",
"$",
"newlines",
"=",
"1",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"message",
")",
")",
"{",
"$",
"message",
"=",
"implode",
"(",
"static",
"::",
"LF",
",",
"$",
"message",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_write",
"(",
"$",
"this",
"->",
"styleText",
"(",
"$",
"message",
".",
"str_repeat",
"(",
"static",
"::",
"LF",
",",
"$",
"newlines",
")",
")",
")",
";",
"}"
] | Outputs a single or multiple messages to stdout or stderr. If no parameters
are passed, outputs just a newline.
@param string|array $message A string or an array of strings to output
@param int $newlines Number of newlines to append
@return int|bool The number of bytes returned from writing to output. | [
"Outputs",
"a",
"single",
"or",
"multiple",
"messages",
"to",
"stdout",
"or",
"stderr",
".",
"If",
"no",
"parameters",
"are",
"passed",
"outputs",
"just",
"a",
"newline",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleOutput.php#L182-L189 |
210,850 | cakephp/cakephp | src/Console/ConsoleOutput.php | ConsoleOutput.styleText | public function styleText($text)
{
if ($this->_outputAs == static::RAW) {
return $text;
}
if ($this->_outputAs == static::PLAIN) {
$tags = implode('|', array_keys(static::$_styles));
return preg_replace('#</?(?:' . $tags . ')>#', '', $text);
}
return preg_replace_callback(
'/<(?P<tag>[a-z0-9-_]+)>(?P<text>.*?)<\/(\1)>/ims',
[$this, '_replaceTags'],
$text
);
} | php | public function styleText($text)
{
if ($this->_outputAs == static::RAW) {
return $text;
}
if ($this->_outputAs == static::PLAIN) {
$tags = implode('|', array_keys(static::$_styles));
return preg_replace('#</?(?:' . $tags . ')>#', '', $text);
}
return preg_replace_callback(
'/<(?P<tag>[a-z0-9-_]+)>(?P<text>.*?)<\/(\1)>/ims',
[$this, '_replaceTags'],
$text
);
} | [
"public",
"function",
"styleText",
"(",
"$",
"text",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_outputAs",
"==",
"static",
"::",
"RAW",
")",
"{",
"return",
"$",
"text",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_outputAs",
"==",
"static",
"::",
"PLAIN",
")",
"{",
"$",
"tags",
"=",
"implode",
"(",
"'|'",
",",
"array_keys",
"(",
"static",
"::",
"$",
"_styles",
")",
")",
";",
"return",
"preg_replace",
"(",
"'#</?(?:'",
".",
"$",
"tags",
".",
"')>#'",
",",
"''",
",",
"$",
"text",
")",
";",
"}",
"return",
"preg_replace_callback",
"(",
"'/<(?P<tag>[a-z0-9-_]+)>(?P<text>.*?)<\\/(\\1)>/ims'",
",",
"[",
"$",
"this",
",",
"'_replaceTags'",
"]",
",",
"$",
"text",
")",
";",
"}"
] | Apply styling to text.
@param string $text Text with styling tags.
@return string String with color codes added. | [
"Apply",
"styling",
"to",
"text",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleOutput.php#L197-L213 |
210,851 | cakephp/cakephp | src/Console/ConsoleOutput.php | ConsoleOutput._replaceTags | protected function _replaceTags($matches)
{
$style = $this->styles($matches['tag']);
if (empty($style)) {
return '<' . $matches['tag'] . '>' . $matches['text'] . '</' . $matches['tag'] . '>';
}
$styleInfo = [];
if (!empty($style['text']) && isset(static::$_foregroundColors[$style['text']])) {
$styleInfo[] = static::$_foregroundColors[$style['text']];
}
if (!empty($style['background']) && isset(static::$_backgroundColors[$style['background']])) {
$styleInfo[] = static::$_backgroundColors[$style['background']];
}
unset($style['text'], $style['background']);
foreach ($style as $option => $value) {
if ($value) {
$styleInfo[] = static::$_options[$option];
}
}
return "\033[" . implode($styleInfo, ';') . 'm' . $matches['text'] . "\033[0m";
} | php | protected function _replaceTags($matches)
{
$style = $this->styles($matches['tag']);
if (empty($style)) {
return '<' . $matches['tag'] . '>' . $matches['text'] . '</' . $matches['tag'] . '>';
}
$styleInfo = [];
if (!empty($style['text']) && isset(static::$_foregroundColors[$style['text']])) {
$styleInfo[] = static::$_foregroundColors[$style['text']];
}
if (!empty($style['background']) && isset(static::$_backgroundColors[$style['background']])) {
$styleInfo[] = static::$_backgroundColors[$style['background']];
}
unset($style['text'], $style['background']);
foreach ($style as $option => $value) {
if ($value) {
$styleInfo[] = static::$_options[$option];
}
}
return "\033[" . implode($styleInfo, ';') . 'm' . $matches['text'] . "\033[0m";
} | [
"protected",
"function",
"_replaceTags",
"(",
"$",
"matches",
")",
"{",
"$",
"style",
"=",
"$",
"this",
"->",
"styles",
"(",
"$",
"matches",
"[",
"'tag'",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"style",
")",
")",
"{",
"return",
"'<'",
".",
"$",
"matches",
"[",
"'tag'",
"]",
".",
"'>'",
".",
"$",
"matches",
"[",
"'text'",
"]",
".",
"'</'",
".",
"$",
"matches",
"[",
"'tag'",
"]",
".",
"'>'",
";",
"}",
"$",
"styleInfo",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"style",
"[",
"'text'",
"]",
")",
"&&",
"isset",
"(",
"static",
"::",
"$",
"_foregroundColors",
"[",
"$",
"style",
"[",
"'text'",
"]",
"]",
")",
")",
"{",
"$",
"styleInfo",
"[",
"]",
"=",
"static",
"::",
"$",
"_foregroundColors",
"[",
"$",
"style",
"[",
"'text'",
"]",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"style",
"[",
"'background'",
"]",
")",
"&&",
"isset",
"(",
"static",
"::",
"$",
"_backgroundColors",
"[",
"$",
"style",
"[",
"'background'",
"]",
"]",
")",
")",
"{",
"$",
"styleInfo",
"[",
"]",
"=",
"static",
"::",
"$",
"_backgroundColors",
"[",
"$",
"style",
"[",
"'background'",
"]",
"]",
";",
"}",
"unset",
"(",
"$",
"style",
"[",
"'text'",
"]",
",",
"$",
"style",
"[",
"'background'",
"]",
")",
";",
"foreach",
"(",
"$",
"style",
"as",
"$",
"option",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
")",
"{",
"$",
"styleInfo",
"[",
"]",
"=",
"static",
"::",
"$",
"_options",
"[",
"$",
"option",
"]",
";",
"}",
"}",
"return",
"\"\\033[\"",
".",
"implode",
"(",
"$",
"styleInfo",
",",
"';'",
")",
".",
"'m'",
".",
"$",
"matches",
"[",
"'text'",
"]",
".",
"\"\\033[0m\"",
";",
"}"
] | Replace tags with color codes.
@param array $matches An array of matches to replace.
@return string | [
"Replace",
"tags",
"with",
"color",
"codes",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleOutput.php#L221-L243 |
210,852 | cakephp/cakephp | src/Console/ConsoleOutput.php | ConsoleOutput.styles | public function styles($style = null, $definition = null)
{
if ($style === null && $definition === null) {
return static::$_styles;
}
if (is_string($style) && $definition === null) {
return isset(static::$_styles[$style]) ? static::$_styles[$style] : null;
}
if ($definition === false) {
unset(static::$_styles[$style]);
return true;
}
static::$_styles[$style] = $definition;
return true;
} | php | public function styles($style = null, $definition = null)
{
if ($style === null && $definition === null) {
return static::$_styles;
}
if (is_string($style) && $definition === null) {
return isset(static::$_styles[$style]) ? static::$_styles[$style] : null;
}
if ($definition === false) {
unset(static::$_styles[$style]);
return true;
}
static::$_styles[$style] = $definition;
return true;
} | [
"public",
"function",
"styles",
"(",
"$",
"style",
"=",
"null",
",",
"$",
"definition",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"style",
"===",
"null",
"&&",
"$",
"definition",
"===",
"null",
")",
"{",
"return",
"static",
"::",
"$",
"_styles",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"style",
")",
"&&",
"$",
"definition",
"===",
"null",
")",
"{",
"return",
"isset",
"(",
"static",
"::",
"$",
"_styles",
"[",
"$",
"style",
"]",
")",
"?",
"static",
"::",
"$",
"_styles",
"[",
"$",
"style",
"]",
":",
"null",
";",
"}",
"if",
"(",
"$",
"definition",
"===",
"false",
")",
"{",
"unset",
"(",
"static",
"::",
"$",
"_styles",
"[",
"$",
"style",
"]",
")",
";",
"return",
"true",
";",
"}",
"static",
"::",
"$",
"_styles",
"[",
"$",
"style",
"]",
"=",
"$",
"definition",
";",
"return",
"true",
";",
"}"
] | Get the current styles offered, or append new ones in.
### Get a style definition
```
$output->styles('error');
```
### Get all the style definitions
```
$output->styles();
```
### Create or modify an existing style
```
$output->styles('annoy', ['text' => 'purple', 'background' => 'yellow', 'blink' => true]);
```
### Remove a style
```
$this->output->styles('annoy', false);
```
@param string|null $style The style to get or create.
@param array|bool|null $definition The array definition of the style to change or create a style
or false to remove a style.
@return mixed If you are getting styles, the style or null will be returned. If you are creating/modifying
styles true will be returned. | [
"Get",
"the",
"current",
"styles",
"offered",
"or",
"append",
"new",
"ones",
"in",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleOutput.php#L289-L305 |
210,853 | cakephp/cakephp | src/Console/ConsoleOutput.php | ConsoleOutput.setOutputAs | public function setOutputAs($type)
{
if (!in_array($type, [self::RAW, self::PLAIN, self::COLOR], true)) {
throw new InvalidArgumentException(sprintf('Invalid output type "%s".', $type));
}
$this->_outputAs = $type;
} | php | public function setOutputAs($type)
{
if (!in_array($type, [self::RAW, self::PLAIN, self::COLOR], true)) {
throw new InvalidArgumentException(sprintf('Invalid output type "%s".', $type));
}
$this->_outputAs = $type;
} | [
"public",
"function",
"setOutputAs",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"type",
",",
"[",
"self",
"::",
"RAW",
",",
"self",
"::",
"PLAIN",
",",
"self",
"::",
"COLOR",
"]",
",",
"true",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid output type \"%s\".'",
",",
"$",
"type",
")",
")",
";",
"}",
"$",
"this",
"->",
"_outputAs",
"=",
"$",
"type",
";",
"}"
] | Set the output type on how formatting tags are treated.
@param int $type The output type to use. Should be one of the class constants.
@return void
@throws \InvalidArgumentException in case of a not supported output type. | [
"Set",
"the",
"output",
"type",
"on",
"how",
"formatting",
"tags",
"are",
"treated",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleOutput.php#L324-L331 |
210,854 | cakephp/cakephp | src/Database/Driver/Sqlserver.php | Sqlserver.connect | public function connect()
{
if ($this->_connection) {
return true;
}
$config = $this->_config;
if (isset($config['persistent']) && $config['persistent']) {
throw new \InvalidArgumentException('Config setting "persistent" cannot be set to true, as the Sqlserver PDO driver does not support PDO::ATTR_PERSISTENT');
}
$config['flags'] += [
PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
];
if (!empty($config['encoding'])) {
$config['flags'][PDO::SQLSRV_ATTR_ENCODING] = $config['encoding'];
}
$port = '';
if (strlen($config['port'])) {
$port = ',' . $config['port'];
}
$dsn = "sqlsrv:Server={$config['host']}{$port};Database={$config['database']};MultipleActiveResultSets=false";
if ($config['app'] !== null) {
$dsn .= ";APP={$config['app']}";
}
if ($config['connectionPooling'] !== null) {
$dsn .= ";ConnectionPooling={$config['connectionPooling']}";
}
if ($config['failoverPartner'] !== null) {
$dsn .= ";Failover_Partner={$config['failoverPartner']}";
}
if ($config['loginTimeout'] !== null) {
$dsn .= ";LoginTimeout={$config['loginTimeout']}";
}
if ($config['multiSubnetFailover'] !== null) {
$dsn .= ";MultiSubnetFailover={$config['multiSubnetFailover']}";
}
$this->_connect($dsn, $config);
$connection = $this->getConnection();
if (!empty($config['init'])) {
foreach ((array)$config['init'] as $command) {
$connection->exec($command);
}
}
if (!empty($config['settings']) && is_array($config['settings'])) {
foreach ($config['settings'] as $key => $value) {
$connection->exec("SET {$key} {$value}");
}
}
if (!empty($config['attributes']) && is_array($config['attributes'])) {
foreach ($config['attributes'] as $key => $value) {
$connection->setAttribute($key, $value);
}
}
return true;
} | php | public function connect()
{
if ($this->_connection) {
return true;
}
$config = $this->_config;
if (isset($config['persistent']) && $config['persistent']) {
throw new \InvalidArgumentException('Config setting "persistent" cannot be set to true, as the Sqlserver PDO driver does not support PDO::ATTR_PERSISTENT');
}
$config['flags'] += [
PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
];
if (!empty($config['encoding'])) {
$config['flags'][PDO::SQLSRV_ATTR_ENCODING] = $config['encoding'];
}
$port = '';
if (strlen($config['port'])) {
$port = ',' . $config['port'];
}
$dsn = "sqlsrv:Server={$config['host']}{$port};Database={$config['database']};MultipleActiveResultSets=false";
if ($config['app'] !== null) {
$dsn .= ";APP={$config['app']}";
}
if ($config['connectionPooling'] !== null) {
$dsn .= ";ConnectionPooling={$config['connectionPooling']}";
}
if ($config['failoverPartner'] !== null) {
$dsn .= ";Failover_Partner={$config['failoverPartner']}";
}
if ($config['loginTimeout'] !== null) {
$dsn .= ";LoginTimeout={$config['loginTimeout']}";
}
if ($config['multiSubnetFailover'] !== null) {
$dsn .= ";MultiSubnetFailover={$config['multiSubnetFailover']}";
}
$this->_connect($dsn, $config);
$connection = $this->getConnection();
if (!empty($config['init'])) {
foreach ((array)$config['init'] as $command) {
$connection->exec($command);
}
}
if (!empty($config['settings']) && is_array($config['settings'])) {
foreach ($config['settings'] as $key => $value) {
$connection->exec("SET {$key} {$value}");
}
}
if (!empty($config['attributes']) && is_array($config['attributes'])) {
foreach ($config['attributes'] as $key => $value) {
$connection->setAttribute($key, $value);
}
}
return true;
} | [
"public",
"function",
"connect",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_connection",
")",
"{",
"return",
"true",
";",
"}",
"$",
"config",
"=",
"$",
"this",
"->",
"_config",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'persistent'",
"]",
")",
"&&",
"$",
"config",
"[",
"'persistent'",
"]",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Config setting \"persistent\" cannot be set to true, as the Sqlserver PDO driver does not support PDO::ATTR_PERSISTENT'",
")",
";",
"}",
"$",
"config",
"[",
"'flags'",
"]",
"+=",
"[",
"PDO",
"::",
"ATTR_EMULATE_PREPARES",
"=>",
"false",
",",
"PDO",
"::",
"ATTR_ERRMODE",
"=>",
"PDO",
"::",
"ERRMODE_EXCEPTION",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"config",
"[",
"'encoding'",
"]",
")",
")",
"{",
"$",
"config",
"[",
"'flags'",
"]",
"[",
"PDO",
"::",
"SQLSRV_ATTR_ENCODING",
"]",
"=",
"$",
"config",
"[",
"'encoding'",
"]",
";",
"}",
"$",
"port",
"=",
"''",
";",
"if",
"(",
"strlen",
"(",
"$",
"config",
"[",
"'port'",
"]",
")",
")",
"{",
"$",
"port",
"=",
"','",
".",
"$",
"config",
"[",
"'port'",
"]",
";",
"}",
"$",
"dsn",
"=",
"\"sqlsrv:Server={$config['host']}{$port};Database={$config['database']};MultipleActiveResultSets=false\"",
";",
"if",
"(",
"$",
"config",
"[",
"'app'",
"]",
"!==",
"null",
")",
"{",
"$",
"dsn",
".=",
"\";APP={$config['app']}\"",
";",
"}",
"if",
"(",
"$",
"config",
"[",
"'connectionPooling'",
"]",
"!==",
"null",
")",
"{",
"$",
"dsn",
".=",
"\";ConnectionPooling={$config['connectionPooling']}\"",
";",
"}",
"if",
"(",
"$",
"config",
"[",
"'failoverPartner'",
"]",
"!==",
"null",
")",
"{",
"$",
"dsn",
".=",
"\";Failover_Partner={$config['failoverPartner']}\"",
";",
"}",
"if",
"(",
"$",
"config",
"[",
"'loginTimeout'",
"]",
"!==",
"null",
")",
"{",
"$",
"dsn",
".=",
"\";LoginTimeout={$config['loginTimeout']}\"",
";",
"}",
"if",
"(",
"$",
"config",
"[",
"'multiSubnetFailover'",
"]",
"!==",
"null",
")",
"{",
"$",
"dsn",
".=",
"\";MultiSubnetFailover={$config['multiSubnetFailover']}\"",
";",
"}",
"$",
"this",
"->",
"_connect",
"(",
"$",
"dsn",
",",
"$",
"config",
")",
";",
"$",
"connection",
"=",
"$",
"this",
"->",
"getConnection",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"config",
"[",
"'init'",
"]",
")",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"config",
"[",
"'init'",
"]",
"as",
"$",
"command",
")",
"{",
"$",
"connection",
"->",
"exec",
"(",
"$",
"command",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"config",
"[",
"'settings'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"config",
"[",
"'settings'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"config",
"[",
"'settings'",
"]",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"connection",
"->",
"exec",
"(",
"\"SET {$key} {$value}\"",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"config",
"[",
"'attributes'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"config",
"[",
"'attributes'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"config",
"[",
"'attributes'",
"]",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"connection",
"->",
"setAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Establishes a connection to the database server.
Please note that the PDO::ATTR_PERSISTENT attribute is not supported by
the SQL Server PHP PDO drivers. As a result you cannot use the
persistent config option when connecting to a SQL Server (for more
information see: https://github.com/Microsoft/msphpsql/issues/65).
@throws \InvalidArgumentException if an unsupported setting is in the driver config
@return bool true on success | [
"Establishes",
"a",
"connection",
"to",
"the",
"database",
"server",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Driver/Sqlserver.php#L66-L126 |
210,855 | cakephp/cakephp | src/Event/EventList.php | EventList.hasEvent | public function hasEvent($name)
{
foreach ($this->_events as $event) {
if ($event->getName() === $name) {
return true;
}
}
return false;
} | php | public function hasEvent($name)
{
foreach ($this->_events as $event) {
if ($event->getName() === $name) {
return true;
}
}
return false;
} | [
"public",
"function",
"hasEvent",
"(",
"$",
"name",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_events",
"as",
"$",
"event",
")",
"{",
"if",
"(",
"$",
"event",
"->",
"getName",
"(",
")",
"===",
"$",
"name",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks if an event is in the list.
@param string $name Event name.
@return bool | [
"Checks",
"if",
"an",
"event",
"is",
"in",
"the",
"list",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Event/EventList.php#L124-L133 |
210,856 | cakephp/cakephp | src/Error/Debugger.php | Debugger.getInstance | public static function getInstance($class = null)
{
static $instance = [];
if (!empty($class)) {
if (!$instance || strtolower($class) !== strtolower(get_class($instance[0]))) {
$instance[0] = new $class();
}
}
if (!$instance) {
$instance[0] = new Debugger();
}
return $instance[0];
} | php | public static function getInstance($class = null)
{
static $instance = [];
if (!empty($class)) {
if (!$instance || strtolower($class) !== strtolower(get_class($instance[0]))) {
$instance[0] = new $class();
}
}
if (!$instance) {
$instance[0] = new Debugger();
}
return $instance[0];
} | [
"public",
"static",
"function",
"getInstance",
"(",
"$",
"class",
"=",
"null",
")",
"{",
"static",
"$",
"instance",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"class",
")",
")",
"{",
"if",
"(",
"!",
"$",
"instance",
"||",
"strtolower",
"(",
"$",
"class",
")",
"!==",
"strtolower",
"(",
"get_class",
"(",
"$",
"instance",
"[",
"0",
"]",
")",
")",
")",
"{",
"$",
"instance",
"[",
"0",
"]",
"=",
"new",
"$",
"class",
"(",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"instance",
")",
"{",
"$",
"instance",
"[",
"0",
"]",
"=",
"new",
"Debugger",
"(",
")",
";",
"}",
"return",
"$",
"instance",
"[",
"0",
"]",
";",
"}"
] | Returns a reference to the Debugger singleton object instance.
@param string|null $class Class name.
@return \Cake\Error\Debugger | [
"Returns",
"a",
"reference",
"to",
"the",
"Debugger",
"singleton",
"object",
"instance",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Error/Debugger.php#L168-L181 |
210,857 | cakephp/cakephp | src/Error/Debugger.php | Debugger.configInstance | public static function configInstance($key = null, $value = null, $merge = true)
{
if (is_array($key) || func_num_args() >= 2) {
return static::getInstance()->setConfig($key, $value, $merge);
}
return static::getInstance()->getConfig($key);
} | php | public static function configInstance($key = null, $value = null, $merge = true)
{
if (is_array($key) || func_num_args() >= 2) {
return static::getInstance()->setConfig($key, $value, $merge);
}
return static::getInstance()->getConfig($key);
} | [
"public",
"static",
"function",
"configInstance",
"(",
"$",
"key",
"=",
"null",
",",
"$",
"value",
"=",
"null",
",",
"$",
"merge",
"=",
"true",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
"||",
"func_num_args",
"(",
")",
">=",
"2",
")",
"{",
"return",
"static",
"::",
"getInstance",
"(",
")",
"->",
"setConfig",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"merge",
")",
";",
"}",
"return",
"static",
"::",
"getInstance",
"(",
")",
"->",
"getConfig",
"(",
"$",
"key",
")",
";",
"}"
] | Read or write configuration options for the Debugger instance.
@param string|array|null $key The key to get/set, or a complete array of configs.
@param mixed|null $value The value to set.
@param bool $merge Whether to recursively merge or overwrite existing config, defaults to true.
@return mixed Config value being read, or the object itself on write operations.
@throws \Cake\Core\Exception\Exception When trying to set a key that is invalid. | [
"Read",
"or",
"write",
"configuration",
"options",
"for",
"the",
"Debugger",
"instance",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Error/Debugger.php#L192-L199 |
210,858 | cakephp/cakephp | src/Error/Debugger.php | Debugger.log | public static function log($var, $level = 'debug', $depth = 3)
{
$source = static::trace(['start' => 1]) . "\n";
Log::write($level, "\n" . $source . static::exportVar($var, $depth));
} | php | public static function log($var, $level = 'debug', $depth = 3)
{
$source = static::trace(['start' => 1]) . "\n";
Log::write($level, "\n" . $source . static::exportVar($var, $depth));
} | [
"public",
"static",
"function",
"log",
"(",
"$",
"var",
",",
"$",
"level",
"=",
"'debug'",
",",
"$",
"depth",
"=",
"3",
")",
"{",
"$",
"source",
"=",
"static",
"::",
"trace",
"(",
"[",
"'start'",
"=>",
"1",
"]",
")",
".",
"\"\\n\"",
";",
"Log",
"::",
"write",
"(",
"$",
"level",
",",
"\"\\n\"",
".",
"$",
"source",
".",
"static",
"::",
"exportVar",
"(",
"$",
"var",
",",
"$",
"depth",
")",
")",
";",
"}"
] | Creates an entry in the log file. The log entry will contain a stack trace from where it was called.
as well as export the variable using exportVar. By default the log is written to the debug log.
@param mixed $var Variable or content to log.
@param int|string $level Type of log to use. Defaults to 'debug'.
@param int $depth The depth to output to. Defaults to 3.
@return void | [
"Creates",
"an",
"entry",
"in",
"the",
"log",
"file",
".",
"The",
"log",
"entry",
"will",
"contain",
"a",
"stack",
"trace",
"from",
"where",
"it",
"was",
"called",
".",
"as",
"well",
"as",
"export",
"the",
"variable",
"using",
"exportVar",
".",
"By",
"default",
"the",
"log",
"is",
"written",
"to",
"the",
"debug",
"log",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Error/Debugger.php#L250-L254 |
210,859 | cakephp/cakephp | src/Error/Debugger.php | Debugger.trimPath | public static function trimPath($path)
{
if (defined('APP') && strpos($path, APP) === 0) {
return str_replace(APP, 'APP/', $path);
}
if (defined('CAKE_CORE_INCLUDE_PATH') && strpos($path, CAKE_CORE_INCLUDE_PATH) === 0) {
return str_replace(CAKE_CORE_INCLUDE_PATH, 'CORE', $path);
}
if (defined('ROOT') && strpos($path, ROOT) === 0) {
return str_replace(ROOT, 'ROOT', $path);
}
return $path;
} | php | public static function trimPath($path)
{
if (defined('APP') && strpos($path, APP) === 0) {
return str_replace(APP, 'APP/', $path);
}
if (defined('CAKE_CORE_INCLUDE_PATH') && strpos($path, CAKE_CORE_INCLUDE_PATH) === 0) {
return str_replace(CAKE_CORE_INCLUDE_PATH, 'CORE', $path);
}
if (defined('ROOT') && strpos($path, ROOT) === 0) {
return str_replace(ROOT, 'ROOT', $path);
}
return $path;
} | [
"public",
"static",
"function",
"trimPath",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"defined",
"(",
"'APP'",
")",
"&&",
"strpos",
"(",
"$",
"path",
",",
"APP",
")",
"===",
"0",
")",
"{",
"return",
"str_replace",
"(",
"APP",
",",
"'APP/'",
",",
"$",
"path",
")",
";",
"}",
"if",
"(",
"defined",
"(",
"'CAKE_CORE_INCLUDE_PATH'",
")",
"&&",
"strpos",
"(",
"$",
"path",
",",
"CAKE_CORE_INCLUDE_PATH",
")",
"===",
"0",
")",
"{",
"return",
"str_replace",
"(",
"CAKE_CORE_INCLUDE_PATH",
",",
"'CORE'",
",",
"$",
"path",
")",
";",
"}",
"if",
"(",
"defined",
"(",
"'ROOT'",
")",
"&&",
"strpos",
"(",
"$",
"path",
",",
"ROOT",
")",
"===",
"0",
")",
"{",
"return",
"str_replace",
"(",
"ROOT",
",",
"'ROOT'",
",",
"$",
"path",
")",
";",
"}",
"return",
"$",
"path",
";",
"}"
] | Shortens file paths by replacing the application base path with 'APP', and the CakePHP core
path with 'CORE'.
@param string $path Path to shorten.
@return string Normalized path | [
"Shortens",
"file",
"paths",
"by",
"replacing",
"the",
"application",
"base",
"path",
"with",
"APP",
"and",
"the",
"CakePHP",
"core",
"path",
"with",
"CORE",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Error/Debugger.php#L375-L388 |
210,860 | cakephp/cakephp | src/Error/Debugger.php | Debugger.excerpt | public static function excerpt($file, $line, $context = 2)
{
$lines = [];
if (!file_exists($file)) {
return [];
}
$data = file_get_contents($file);
if (empty($data)) {
return $lines;
}
if (strpos($data, "\n") !== false) {
$data = explode("\n", $data);
}
$line--;
if (!isset($data[$line])) {
return $lines;
}
for ($i = $line - $context; $i < $line + $context + 1; $i++) {
if (!isset($data[$i])) {
continue;
}
$string = str_replace(["\r\n", "\n"], '', static::_highlight($data[$i]));
if ($i == $line) {
$lines[] = '<span class="code-highlight">' . $string . '</span>';
} else {
$lines[] = $string;
}
}
return $lines;
} | php | public static function excerpt($file, $line, $context = 2)
{
$lines = [];
if (!file_exists($file)) {
return [];
}
$data = file_get_contents($file);
if (empty($data)) {
return $lines;
}
if (strpos($data, "\n") !== false) {
$data = explode("\n", $data);
}
$line--;
if (!isset($data[$line])) {
return $lines;
}
for ($i = $line - $context; $i < $line + $context + 1; $i++) {
if (!isset($data[$i])) {
continue;
}
$string = str_replace(["\r\n", "\n"], '', static::_highlight($data[$i]));
if ($i == $line) {
$lines[] = '<span class="code-highlight">' . $string . '</span>';
} else {
$lines[] = $string;
}
}
return $lines;
} | [
"public",
"static",
"function",
"excerpt",
"(",
"$",
"file",
",",
"$",
"line",
",",
"$",
"context",
"=",
"2",
")",
"{",
"$",
"lines",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"data",
"=",
"file_get_contents",
"(",
"$",
"file",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"return",
"$",
"lines",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"data",
",",
"\"\\n\"",
")",
"!==",
"false",
")",
"{",
"$",
"data",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"data",
")",
";",
"}",
"$",
"line",
"--",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"$",
"line",
"]",
")",
")",
"{",
"return",
"$",
"lines",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"$",
"line",
"-",
"$",
"context",
";",
"$",
"i",
"<",
"$",
"line",
"+",
"$",
"context",
"+",
"1",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"$",
"i",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"string",
"=",
"str_replace",
"(",
"[",
"\"\\r\\n\"",
",",
"\"\\n\"",
"]",
",",
"''",
",",
"static",
"::",
"_highlight",
"(",
"$",
"data",
"[",
"$",
"i",
"]",
")",
")",
";",
"if",
"(",
"$",
"i",
"==",
"$",
"line",
")",
"{",
"$",
"lines",
"[",
"]",
"=",
"'<span class=\"code-highlight\">'",
".",
"$",
"string",
".",
"'</span>'",
";",
"}",
"else",
"{",
"$",
"lines",
"[",
"]",
"=",
"$",
"string",
";",
"}",
"}",
"return",
"$",
"lines",
";",
"}"
] | Grabs an excerpt from a file and highlights a given line of code.
Usage:
```
Debugger::excerpt('/path/to/file', 100, 4);
```
The above would return an array of 8 items. The 4th item would be the provided line,
and would be wrapped in `<span class="code-highlight"></span>`. All of the lines
are processed with highlight_string() as well, so they have basic PHP syntax highlighting
applied.
@param string $file Absolute path to a PHP file.
@param int $line Line number to highlight.
@param int $context Number of lines of context to extract above and below $line.
@return array Set of lines highlighted
@see https://secure.php.net/highlight_string
@link https://book.cakephp.org/3.0/en/development/debugging.html#getting-an-excerpt-from-a-file | [
"Grabs",
"an",
"excerpt",
"from",
"a",
"file",
"and",
"highlights",
"a",
"given",
"line",
"of",
"code",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Error/Debugger.php#L411-L441 |
210,861 | cakephp/cakephp | src/Error/Debugger.php | Debugger._highlight | protected static function _highlight($str)
{
if (function_exists('hphp_log') || function_exists('hphp_gettid')) {
return htmlentities($str);
}
$added = false;
if (strpos($str, '<?php') === false) {
$added = true;
$str = "<?php \n" . $str;
}
$highlight = highlight_string($str, true);
if ($added) {
$highlight = str_replace(
['<?php <br/>', '<?php <br />'],
'',
$highlight
);
}
return $highlight;
} | php | protected static function _highlight($str)
{
if (function_exists('hphp_log') || function_exists('hphp_gettid')) {
return htmlentities($str);
}
$added = false;
if (strpos($str, '<?php') === false) {
$added = true;
$str = "<?php \n" . $str;
}
$highlight = highlight_string($str, true);
if ($added) {
$highlight = str_replace(
['<?php <br/>', '<?php <br />'],
'',
$highlight
);
}
return $highlight;
} | [
"protected",
"static",
"function",
"_highlight",
"(",
"$",
"str",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'hphp_log'",
")",
"||",
"function_exists",
"(",
"'hphp_gettid'",
")",
")",
"{",
"return",
"htmlentities",
"(",
"$",
"str",
")",
";",
"}",
"$",
"added",
"=",
"false",
";",
"if",
"(",
"strpos",
"(",
"$",
"str",
",",
"'<?php'",
")",
"===",
"false",
")",
"{",
"$",
"added",
"=",
"true",
";",
"$",
"str",
"=",
"\"<?php \\n\"",
".",
"$",
"str",
";",
"}",
"$",
"highlight",
"=",
"highlight_string",
"(",
"$",
"str",
",",
"true",
")",
";",
"if",
"(",
"$",
"added",
")",
"{",
"$",
"highlight",
"=",
"str_replace",
"(",
"[",
"'<?php <br/>'",
",",
"'<?php <br />'",
"]",
",",
"''",
",",
"$",
"highlight",
")",
";",
"}",
"return",
"$",
"highlight",
";",
"}"
] | Wraps the highlight_string function in case the server API does not
implement the function as it is the case of the HipHop interpreter
@param string $str The string to convert.
@return string | [
"Wraps",
"the",
"highlight_string",
"function",
"in",
"case",
"the",
"server",
"API",
"does",
"not",
"implement",
"the",
"function",
"as",
"it",
"is",
"the",
"case",
"of",
"the",
"HipHop",
"interpreter"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Error/Debugger.php#L450-L470 |
210,862 | cakephp/cakephp | src/Error/Debugger.php | Debugger._export | protected static function _export($var, $depth, $indent)
{
switch (static::getType($var)) {
case 'boolean':
return $var ? 'true' : 'false';
case 'integer':
return '(int) ' . $var;
case 'float':
return '(float) ' . $var;
case 'string':
if (trim($var) === '' && ctype_space($var) === false) {
return "''";
}
return "'" . $var . "'";
case 'array':
return static::_array($var, $depth - 1, $indent + 1);
case 'resource':
return strtolower(gettype($var));
case 'null':
return 'null';
case 'unknown':
return 'unknown';
default:
return static::_object($var, $depth - 1, $indent + 1);
}
} | php | protected static function _export($var, $depth, $indent)
{
switch (static::getType($var)) {
case 'boolean':
return $var ? 'true' : 'false';
case 'integer':
return '(int) ' . $var;
case 'float':
return '(float) ' . $var;
case 'string':
if (trim($var) === '' && ctype_space($var) === false) {
return "''";
}
return "'" . $var . "'";
case 'array':
return static::_array($var, $depth - 1, $indent + 1);
case 'resource':
return strtolower(gettype($var));
case 'null':
return 'null';
case 'unknown':
return 'unknown';
default:
return static::_object($var, $depth - 1, $indent + 1);
}
} | [
"protected",
"static",
"function",
"_export",
"(",
"$",
"var",
",",
"$",
"depth",
",",
"$",
"indent",
")",
"{",
"switch",
"(",
"static",
"::",
"getType",
"(",
"$",
"var",
")",
")",
"{",
"case",
"'boolean'",
":",
"return",
"$",
"var",
"?",
"'true'",
":",
"'false'",
";",
"case",
"'integer'",
":",
"return",
"'(int) '",
".",
"$",
"var",
";",
"case",
"'float'",
":",
"return",
"'(float) '",
".",
"$",
"var",
";",
"case",
"'string'",
":",
"if",
"(",
"trim",
"(",
"$",
"var",
")",
"===",
"''",
"&&",
"ctype_space",
"(",
"$",
"var",
")",
"===",
"false",
")",
"{",
"return",
"\"''\"",
";",
"}",
"return",
"\"'\"",
".",
"$",
"var",
".",
"\"'\"",
";",
"case",
"'array'",
":",
"return",
"static",
"::",
"_array",
"(",
"$",
"var",
",",
"$",
"depth",
"-",
"1",
",",
"$",
"indent",
"+",
"1",
")",
";",
"case",
"'resource'",
":",
"return",
"strtolower",
"(",
"gettype",
"(",
"$",
"var",
")",
")",
";",
"case",
"'null'",
":",
"return",
"'null'",
";",
"case",
"'unknown'",
":",
"return",
"'unknown'",
";",
"default",
":",
"return",
"static",
"::",
"_object",
"(",
"$",
"var",
",",
"$",
"depth",
"-",
"1",
",",
"$",
"indent",
"+",
"1",
")",
";",
"}",
"}"
] | Protected export function used to keep track of indentation and recursion.
@param mixed $var The variable to dump.
@param int $depth The remaining depth.
@param int $indent The current indentation level.
@return string The dumped variable. | [
"Protected",
"export",
"function",
"used",
"to",
"keep",
"track",
"of",
"indentation",
"and",
"recursion",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Error/Debugger.php#L506-L532 |
210,863 | cakephp/cakephp | src/Error/Debugger.php | Debugger.setOutputFormat | public static function setOutputFormat($format)
{
$self = Debugger::getInstance();
if (!isset($self->_templates[$format])) {
throw new InvalidArgumentException('Invalid Debugger output format.');
}
$self->_outputFormat = $format;
} | php | public static function setOutputFormat($format)
{
$self = Debugger::getInstance();
if (!isset($self->_templates[$format])) {
throw new InvalidArgumentException('Invalid Debugger output format.');
}
$self->_outputFormat = $format;
} | [
"public",
"static",
"function",
"setOutputFormat",
"(",
"$",
"format",
")",
"{",
"$",
"self",
"=",
"Debugger",
"::",
"getInstance",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"self",
"->",
"_templates",
"[",
"$",
"format",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Invalid Debugger output format.'",
")",
";",
"}",
"$",
"self",
"->",
"_outputFormat",
"=",
"$",
"format",
";",
"}"
] | Set the output format for Debugger error rendering.
@param string $format The format you want errors to be output as.
@return void
@throws \InvalidArgumentException When choosing a format that doesn't exist. | [
"Set",
"the",
"output",
"format",
"for",
"Debugger",
"error",
"rendering",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Error/Debugger.php#L670-L678 |
210,864 | cakephp/cakephp | src/Error/Debugger.php | Debugger.addFormat | public static function addFormat($format, array $strings)
{
$self = Debugger::getInstance();
if (isset($self->_templates[$format])) {
if (isset($strings['links'])) {
$self->_templates[$format]['links'] = array_merge(
$self->_templates[$format]['links'],
$strings['links']
);
unset($strings['links']);
}
$self->_templates[$format] = $strings + $self->_templates[$format];
} else {
$self->_templates[$format] = $strings;
}
return $self->_templates[$format];
} | php | public static function addFormat($format, array $strings)
{
$self = Debugger::getInstance();
if (isset($self->_templates[$format])) {
if (isset($strings['links'])) {
$self->_templates[$format]['links'] = array_merge(
$self->_templates[$format]['links'],
$strings['links']
);
unset($strings['links']);
}
$self->_templates[$format] = $strings + $self->_templates[$format];
} else {
$self->_templates[$format] = $strings;
}
return $self->_templates[$format];
} | [
"public",
"static",
"function",
"addFormat",
"(",
"$",
"format",
",",
"array",
"$",
"strings",
")",
"{",
"$",
"self",
"=",
"Debugger",
"::",
"getInstance",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"self",
"->",
"_templates",
"[",
"$",
"format",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"strings",
"[",
"'links'",
"]",
")",
")",
"{",
"$",
"self",
"->",
"_templates",
"[",
"$",
"format",
"]",
"[",
"'links'",
"]",
"=",
"array_merge",
"(",
"$",
"self",
"->",
"_templates",
"[",
"$",
"format",
"]",
"[",
"'links'",
"]",
",",
"$",
"strings",
"[",
"'links'",
"]",
")",
";",
"unset",
"(",
"$",
"strings",
"[",
"'links'",
"]",
")",
";",
"}",
"$",
"self",
"->",
"_templates",
"[",
"$",
"format",
"]",
"=",
"$",
"strings",
"+",
"$",
"self",
"->",
"_templates",
"[",
"$",
"format",
"]",
";",
"}",
"else",
"{",
"$",
"self",
"->",
"_templates",
"[",
"$",
"format",
"]",
"=",
"$",
"strings",
";",
"}",
"return",
"$",
"self",
"->",
"_templates",
"[",
"$",
"format",
"]",
";",
"}"
] | Add an output format or update a format in Debugger.
```
Debugger::addFormat('custom', $data);
```
Where $data is an array of strings that use Text::insert() variable
replacement. The template vars should be in a `{:id}` style.
An error formatter can have the following keys:
- 'error' - Used for the container for the error message. Gets the following template
variables: `id`, `error`, `code`, `description`, `path`, `line`, `links`, `info`
- 'info' - A combination of `code`, `context` and `trace`. Will be set with
the contents of the other template keys.
- 'trace' - The container for a stack trace. Gets the following template
variables: `trace`
- 'context' - The container element for the context variables.
Gets the following templates: `id`, `context`
- 'links' - An array of HTML links that are used for creating links to other resources.
Typically this is used to create javascript links to open other sections.
Link keys, are: `code`, `context`, `help`. See the js output format for an
example.
- 'traceLine' - Used for creating lines in the stacktrace. Gets the following
template variables: `reference`, `path`, `line`
Alternatively if you want to use a custom callback to do all the formatting, you can use
the callback key, and provide a callable:
```
Debugger::addFormat('custom', ['callback' => [$foo, 'outputError']];
```
The callback can expect two parameters. The first is an array of all
the error data. The second contains the formatted strings generated using
the other template strings. Keys like `info`, `links`, `code`, `context` and `trace`
will be present depending on the other templates in the format type.
@param string $format Format to use, including 'js' for JavaScript-enhanced HTML, 'html' for
straight HTML output, or 'txt' for unformatted text.
@param array $strings Template strings, or a callback to be used for the output format.
@return array The resulting format string set. | [
"Add",
"an",
"output",
"format",
"or",
"update",
"a",
"format",
"in",
"Debugger",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Error/Debugger.php#L750-L767 |
210,865 | cakephp/cakephp | src/Error/Debugger.php | Debugger.getType | public static function getType($var)
{
if (is_object($var)) {
return get_class($var);
}
if ($var === null) {
return 'null';
}
if (is_string($var)) {
return 'string';
}
if (is_array($var)) {
return 'array';
}
if (is_int($var)) {
return 'integer';
}
if (is_bool($var)) {
return 'boolean';
}
if (is_float($var)) {
return 'float';
}
if (is_resource($var)) {
return 'resource';
}
return 'unknown';
} | php | public static function getType($var)
{
if (is_object($var)) {
return get_class($var);
}
if ($var === null) {
return 'null';
}
if (is_string($var)) {
return 'string';
}
if (is_array($var)) {
return 'array';
}
if (is_int($var)) {
return 'integer';
}
if (is_bool($var)) {
return 'boolean';
}
if (is_float($var)) {
return 'float';
}
if (is_resource($var)) {
return 'resource';
}
return 'unknown';
} | [
"public",
"static",
"function",
"getType",
"(",
"$",
"var",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"var",
")",
")",
"{",
"return",
"get_class",
"(",
"$",
"var",
")",
";",
"}",
"if",
"(",
"$",
"var",
"===",
"null",
")",
"{",
"return",
"'null'",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"var",
")",
")",
"{",
"return",
"'string'",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"var",
")",
")",
"{",
"return",
"'array'",
";",
"}",
"if",
"(",
"is_int",
"(",
"$",
"var",
")",
")",
"{",
"return",
"'integer'",
";",
"}",
"if",
"(",
"is_bool",
"(",
"$",
"var",
")",
")",
"{",
"return",
"'boolean'",
";",
"}",
"if",
"(",
"is_float",
"(",
"$",
"var",
")",
")",
"{",
"return",
"'float'",
";",
"}",
"if",
"(",
"is_resource",
"(",
"$",
"var",
")",
")",
"{",
"return",
"'resource'",
";",
"}",
"return",
"'unknown'",
";",
"}"
] | Get the type of the given variable. Will return the class name
for objects.
@param mixed $var The variable to get the type of.
@return string The type of variable. | [
"Get",
"the",
"type",
"of",
"the",
"given",
"variable",
".",
"Will",
"return",
"the",
"class",
"name",
"for",
"objects",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Error/Debugger.php#L863-L891 |
210,866 | cakephp/cakephp | src/Error/Debugger.php | Debugger.printVar | public static function printVar($var, $location = [], $showHtml = null)
{
$location += ['file' => null, 'line' => null];
$file = $location['file'];
$line = $location['line'];
$lineInfo = '';
if ($file) {
$search = [];
if (defined('ROOT')) {
$search = [ROOT];
}
if (defined('CAKE_CORE_INCLUDE_PATH')) {
array_unshift($search, CAKE_CORE_INCLUDE_PATH);
}
$file = str_replace($search, '', $file);
}
$html = <<<HTML
<div class="cake-debug-output" style="direction:ltr">
%s
<pre class="cake-debug">
%s
</pre>
</div>
HTML;
$text = <<<TEXT
%s
########## DEBUG ##########
%s
###########################
TEXT;
$template = $html;
if ((PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') || $showHtml === false) {
$template = $text;
if ($file && $line) {
$lineInfo = sprintf('%s (line %s)', $file, $line);
}
}
if ($showHtml === null && $template !== $text) {
$showHtml = true;
}
$var = Debugger::exportVar($var, 25);
if ($showHtml) {
$template = $html;
$var = h($var);
if ($file && $line) {
$lineInfo = sprintf('<span><strong>%s</strong> (line <strong>%s</strong>)</span>', $file, $line);
}
}
printf($template, $lineInfo, $var);
} | php | public static function printVar($var, $location = [], $showHtml = null)
{
$location += ['file' => null, 'line' => null];
$file = $location['file'];
$line = $location['line'];
$lineInfo = '';
if ($file) {
$search = [];
if (defined('ROOT')) {
$search = [ROOT];
}
if (defined('CAKE_CORE_INCLUDE_PATH')) {
array_unshift($search, CAKE_CORE_INCLUDE_PATH);
}
$file = str_replace($search, '', $file);
}
$html = <<<HTML
<div class="cake-debug-output" style="direction:ltr">
%s
<pre class="cake-debug">
%s
</pre>
</div>
HTML;
$text = <<<TEXT
%s
########## DEBUG ##########
%s
###########################
TEXT;
$template = $html;
if ((PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') || $showHtml === false) {
$template = $text;
if ($file && $line) {
$lineInfo = sprintf('%s (line %s)', $file, $line);
}
}
if ($showHtml === null && $template !== $text) {
$showHtml = true;
}
$var = Debugger::exportVar($var, 25);
if ($showHtml) {
$template = $html;
$var = h($var);
if ($file && $line) {
$lineInfo = sprintf('<span><strong>%s</strong> (line <strong>%s</strong>)</span>', $file, $line);
}
}
printf($template, $lineInfo, $var);
} | [
"public",
"static",
"function",
"printVar",
"(",
"$",
"var",
",",
"$",
"location",
"=",
"[",
"]",
",",
"$",
"showHtml",
"=",
"null",
")",
"{",
"$",
"location",
"+=",
"[",
"'file'",
"=>",
"null",
",",
"'line'",
"=>",
"null",
"]",
";",
"$",
"file",
"=",
"$",
"location",
"[",
"'file'",
"]",
";",
"$",
"line",
"=",
"$",
"location",
"[",
"'line'",
"]",
";",
"$",
"lineInfo",
"=",
"''",
";",
"if",
"(",
"$",
"file",
")",
"{",
"$",
"search",
"=",
"[",
"]",
";",
"if",
"(",
"defined",
"(",
"'ROOT'",
")",
")",
"{",
"$",
"search",
"=",
"[",
"ROOT",
"]",
";",
"}",
"if",
"(",
"defined",
"(",
"'CAKE_CORE_INCLUDE_PATH'",
")",
")",
"{",
"array_unshift",
"(",
"$",
"search",
",",
"CAKE_CORE_INCLUDE_PATH",
")",
";",
"}",
"$",
"file",
"=",
"str_replace",
"(",
"$",
"search",
",",
"''",
",",
"$",
"file",
")",
";",
"}",
"$",
"html",
"=",
" <<<HTML\n<div class=\"cake-debug-output\" style=\"direction:ltr\">\n%s\n<pre class=\"cake-debug\">\n%s\n</pre>\n</div>\nHTML",
";",
"$",
"text",
"=",
" <<<TEXT\n%s\n########## DEBUG ##########\n%s\n###########################\n\nTEXT",
";",
"$",
"template",
"=",
"$",
"html",
";",
"if",
"(",
"(",
"PHP_SAPI",
"===",
"'cli'",
"||",
"PHP_SAPI",
"===",
"'phpdbg'",
")",
"||",
"$",
"showHtml",
"===",
"false",
")",
"{",
"$",
"template",
"=",
"$",
"text",
";",
"if",
"(",
"$",
"file",
"&&",
"$",
"line",
")",
"{",
"$",
"lineInfo",
"=",
"sprintf",
"(",
"'%s (line %s)'",
",",
"$",
"file",
",",
"$",
"line",
")",
";",
"}",
"}",
"if",
"(",
"$",
"showHtml",
"===",
"null",
"&&",
"$",
"template",
"!==",
"$",
"text",
")",
"{",
"$",
"showHtml",
"=",
"true",
";",
"}",
"$",
"var",
"=",
"Debugger",
"::",
"exportVar",
"(",
"$",
"var",
",",
"25",
")",
";",
"if",
"(",
"$",
"showHtml",
")",
"{",
"$",
"template",
"=",
"$",
"html",
";",
"$",
"var",
"=",
"h",
"(",
"$",
"var",
")",
";",
"if",
"(",
"$",
"file",
"&&",
"$",
"line",
")",
"{",
"$",
"lineInfo",
"=",
"sprintf",
"(",
"'<span><strong>%s</strong> (line <strong>%s</strong>)</span>'",
",",
"$",
"file",
",",
"$",
"line",
")",
";",
"}",
"}",
"printf",
"(",
"$",
"template",
",",
"$",
"lineInfo",
",",
"$",
"var",
")",
";",
"}"
] | Prints out debug information about given variable.
@param mixed $var Variable to show debug information for.
@param array $location If contains keys "file" and "line" their values will
be used to show location info.
@param bool|null $showHtml If set to true, the method prints the debug
data in a browser-friendly way.
@return void | [
"Prints",
"out",
"debug",
"information",
"about",
"given",
"variable",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Error/Debugger.php#L903-L953 |
210,867 | cakephp/cakephp | src/Mailer/AbstractTransport.php | AbstractTransport._headersToString | protected function _headersToString($headers, $eol = "\r\n")
{
$out = '';
foreach ($headers as $key => $value) {
if ($value === false || $value === null || $value === '') {
continue;
}
$out .= $key . ': ' . $value . $eol;
}
if (!empty($out)) {
$out = substr($out, 0, -1 * strlen($eol));
}
return $out;
} | php | protected function _headersToString($headers, $eol = "\r\n")
{
$out = '';
foreach ($headers as $key => $value) {
if ($value === false || $value === null || $value === '') {
continue;
}
$out .= $key . ': ' . $value . $eol;
}
if (!empty($out)) {
$out = substr($out, 0, -1 * strlen($eol));
}
return $out;
} | [
"protected",
"function",
"_headersToString",
"(",
"$",
"headers",
",",
"$",
"eol",
"=",
"\"\\r\\n\"",
")",
"{",
"$",
"out",
"=",
"''",
";",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"false",
"||",
"$",
"value",
"===",
"null",
"||",
"$",
"value",
"===",
"''",
")",
"{",
"continue",
";",
"}",
"$",
"out",
".=",
"$",
"key",
".",
"': '",
".",
"$",
"value",
".",
"$",
"eol",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"out",
")",
")",
"{",
"$",
"out",
"=",
"substr",
"(",
"$",
"out",
",",
"0",
",",
"-",
"1",
"*",
"strlen",
"(",
"$",
"eol",
")",
")",
";",
"}",
"return",
"$",
"out",
";",
"}"
] | Help to convert headers in string
@param array $headers Headers in format key => value
@param string $eol End of line string.
@return string | [
"Help",
"to",
"convert",
"headers",
"in",
"string"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/AbstractTransport.php#L58-L72 |
210,868 | cakephp/cakephp | src/Cache/Cache.php | Cache.engine | public static function engine($config)
{
if (!static::$_enabled) {
return new NullEngine();
}
$registry = static::getRegistry();
if (isset($registry->{$config})) {
return $registry->{$config};
}
static::_buildEngine($config);
return $registry->{$config};
} | php | public static function engine($config)
{
if (!static::$_enabled) {
return new NullEngine();
}
$registry = static::getRegistry();
if (isset($registry->{$config})) {
return $registry->{$config};
}
static::_buildEngine($config);
return $registry->{$config};
} | [
"public",
"static",
"function",
"engine",
"(",
"$",
"config",
")",
"{",
"if",
"(",
"!",
"static",
"::",
"$",
"_enabled",
")",
"{",
"return",
"new",
"NullEngine",
"(",
")",
";",
"}",
"$",
"registry",
"=",
"static",
"::",
"getRegistry",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"registry",
"->",
"{",
"$",
"config",
"}",
")",
")",
"{",
"return",
"$",
"registry",
"->",
"{",
"$",
"config",
"}",
";",
"}",
"static",
"::",
"_buildEngine",
"(",
"$",
"config",
")",
";",
"return",
"$",
"registry",
"->",
"{",
"$",
"config",
"}",
";",
"}"
] | Fetch the engine attached to a specific configuration name.
If the cache engine & configuration are missing an error will be
triggered.
@param string $config The configuration name you want an engine for.
@return \Cake\Cache\CacheEngine When caching is disabled a null engine will be returned.
@deprecated 3.7.0 Use Cache::pool() instead. In 4.0 all cache engines will implement the
PSR16 interface and this method does not return objects implementing that interface. | [
"Fetch",
"the",
"engine",
"attached",
"to",
"a",
"specific",
"configuration",
"name",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/Cache.php#L225-L240 |
210,869 | cakephp/cakephp | src/Cache/Cache.php | Cache.writeMany | public static function writeMany($data, $config = 'default')
{
$engine = static::engine($config);
$return = $engine->writeMany($data);
foreach ($return as $key => $success) {
if ($success === false && $data[$key] !== '') {
throw new RuntimeException(sprintf(
'%s cache was unable to write \'%s\' to %s cache',
$config,
$key,
get_class($engine)
));
}
}
return $return;
} | php | public static function writeMany($data, $config = 'default')
{
$engine = static::engine($config);
$return = $engine->writeMany($data);
foreach ($return as $key => $success) {
if ($success === false && $data[$key] !== '') {
throw new RuntimeException(sprintf(
'%s cache was unable to write \'%s\' to %s cache',
$config,
$key,
get_class($engine)
));
}
}
return $return;
} | [
"public",
"static",
"function",
"writeMany",
"(",
"$",
"data",
",",
"$",
"config",
"=",
"'default'",
")",
"{",
"$",
"engine",
"=",
"static",
"::",
"engine",
"(",
"$",
"config",
")",
";",
"$",
"return",
"=",
"$",
"engine",
"->",
"writeMany",
"(",
"$",
"data",
")",
";",
"foreach",
"(",
"$",
"return",
"as",
"$",
"key",
"=>",
"$",
"success",
")",
"{",
"if",
"(",
"$",
"success",
"===",
"false",
"&&",
"$",
"data",
"[",
"$",
"key",
"]",
"!==",
"''",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'%s cache was unable to write \\'%s\\' to %s cache'",
",",
"$",
"config",
",",
"$",
"key",
",",
"get_class",
"(",
"$",
"engine",
")",
")",
")",
";",
"}",
"}",
"return",
"$",
"return",
";",
"}"
] | Write data for many keys into cache.
### Usage:
Writing to the active cache config:
```
Cache::writeMany(['cached_data_1' => 'data 1', 'cached_data_2' => 'data 2']);
```
Writing to a specific cache config:
```
Cache::writeMany(['cached_data_1' => 'data 1', 'cached_data_2' => 'data 2'], 'long_term');
```
@param array $data An array of data to be stored in the cache
@param string $config Optional string configuration name to write to. Defaults to 'default'
@return array of bools for each key provided, indicating true for success or false for fail
@throws \RuntimeException | [
"Write",
"data",
"for",
"many",
"keys",
"into",
"cache",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/Cache.php#L336-L353 |
210,870 | cakephp/cakephp | src/Cache/Cache.php | Cache.decrement | public static function decrement($key, $offset = 1, $config = 'default')
{
$engine = static::pool($config);
if (!is_int($offset) || $offset < 0) {
return false;
}
return $engine->decrement($key, $offset);
} | php | public static function decrement($key, $offset = 1, $config = 'default')
{
$engine = static::pool($config);
if (!is_int($offset) || $offset < 0) {
return false;
}
return $engine->decrement($key, $offset);
} | [
"public",
"static",
"function",
"decrement",
"(",
"$",
"key",
",",
"$",
"offset",
"=",
"1",
",",
"$",
"config",
"=",
"'default'",
")",
"{",
"$",
"engine",
"=",
"static",
"::",
"pool",
"(",
"$",
"config",
")",
";",
"if",
"(",
"!",
"is_int",
"(",
"$",
"offset",
")",
"||",
"$",
"offset",
"<",
"0",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"engine",
"->",
"decrement",
"(",
"$",
"key",
",",
"$",
"offset",
")",
";",
"}"
] | Decrement a number under the key and return decremented value.
@param string $key Identifier for the data
@param int $offset How much to subtract
@param string $config Optional string configuration name. Defaults to 'default'
@return mixed new value, or false if the data doesn't exist, is not integer,
or if there was an error fetching it | [
"Decrement",
"a",
"number",
"under",
"the",
"key",
"and",
"return",
"decremented",
"value",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/Cache.php#L442-L450 |
210,871 | cakephp/cakephp | src/Cache/Cache.php | Cache.deleteMany | public static function deleteMany($keys, $config = 'default')
{
$backend = static::pool($config);
$return = [];
foreach ($keys as $key) {
$return[$key] = $backend->delete($key);
}
return $return;
} | php | public static function deleteMany($keys, $config = 'default')
{
$backend = static::pool($config);
$return = [];
foreach ($keys as $key) {
$return[$key] = $backend->delete($key);
}
return $return;
} | [
"public",
"static",
"function",
"deleteMany",
"(",
"$",
"keys",
",",
"$",
"config",
"=",
"'default'",
")",
"{",
"$",
"backend",
"=",
"static",
"::",
"pool",
"(",
"$",
"config",
")",
";",
"$",
"return",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"return",
"[",
"$",
"key",
"]",
"=",
"$",
"backend",
"->",
"delete",
"(",
"$",
"key",
")",
";",
"}",
"return",
"$",
"return",
";",
"}"
] | Delete many keys from the cache.
### Usage:
Deleting multiple keys from the active cache configuration.
```
Cache::deleteMany(['my_data_1', 'my_data_2']);
```
Deleting from a specific cache configuration.
```
Cache::deleteMany(['my_data_1', 'my_data_2], 'long_term');
```
@param array $keys Array of cache keys to be deleted
@param string $config name of the configuration to use. Defaults to 'default'
@return array of boolean values that are true if the value was successfully deleted,
false if it didn't exist or couldn't be removed. | [
"Delete",
"many",
"keys",
"from",
"the",
"cache",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/Cache.php#L502-L512 |
210,872 | cakephp/cakephp | src/Cache/Cache.php | Cache.clearAll | public static function clearAll($check = false)
{
$status = [];
foreach (self::configured() as $config) {
$status[$config] = self::clear($check, $config);
}
return $status;
} | php | public static function clearAll($check = false)
{
$status = [];
foreach (self::configured() as $config) {
$status[$config] = self::clear($check, $config);
}
return $status;
} | [
"public",
"static",
"function",
"clearAll",
"(",
"$",
"check",
"=",
"false",
")",
"{",
"$",
"status",
"=",
"[",
"]",
";",
"foreach",
"(",
"self",
"::",
"configured",
"(",
")",
"as",
"$",
"config",
")",
"{",
"$",
"status",
"[",
"$",
"config",
"]",
"=",
"self",
"::",
"clear",
"(",
"$",
"check",
",",
"$",
"config",
")",
";",
"}",
"return",
"$",
"status",
";",
"}"
] | Delete all keys from the cache from all configurations.
@param bool $check if true will check expiration, otherwise delete all. This parameter
will become a no-op value in 4.0 as it is deprecated.
@return array Status code. For each configuration, it reports the status of the operation | [
"Delete",
"all",
"keys",
"from",
"the",
"cache",
"from",
"all",
"configurations",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/Cache.php#L536-L545 |
210,873 | cakephp/cakephp | src/Cache/Cache.php | Cache.remember | public static function remember($key, $callable, $config = 'default')
{
$existing = self::read($key, $config);
if ($existing !== false) {
return $existing;
}
$results = call_user_func($callable);
self::write($key, $results, $config);
return $results;
} | php | public static function remember($key, $callable, $config = 'default')
{
$existing = self::read($key, $config);
if ($existing !== false) {
return $existing;
}
$results = call_user_func($callable);
self::write($key, $results, $config);
return $results;
} | [
"public",
"static",
"function",
"remember",
"(",
"$",
"key",
",",
"$",
"callable",
",",
"$",
"config",
"=",
"'default'",
")",
"{",
"$",
"existing",
"=",
"self",
"::",
"read",
"(",
"$",
"key",
",",
"$",
"config",
")",
";",
"if",
"(",
"$",
"existing",
"!==",
"false",
")",
"{",
"return",
"$",
"existing",
";",
"}",
"$",
"results",
"=",
"call_user_func",
"(",
"$",
"callable",
")",
";",
"self",
"::",
"write",
"(",
"$",
"key",
",",
"$",
"results",
",",
"$",
"config",
")",
";",
"return",
"$",
"results",
";",
"}"
] | Provides the ability to easily do read-through caching.
When called if the $key is not set in $config, the $callable function
will be invoked. The results will then be stored into the cache config
at key.
Examples:
Using a Closure to provide data, assume `$this` is a Table object:
```
$results = Cache::remember('all_articles', function () {
return $this->find('all');
});
```
@param string $key The cache key to read/store data at.
@param callable $callable The callable that provides data in the case when
the cache key is empty. Can be any callable type supported by your PHP.
@param string $config The cache configuration to use for this operation.
Defaults to default.
@return mixed If the key is found: the cached data, false if the data
missing/expired, or an error. If the key is not found: boolean of the
success of the write | [
"Provides",
"the",
"ability",
"to",
"easily",
"do",
"read",
"-",
"through",
"caching",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/Cache.php#L653-L663 |
210,874 | cakephp/cakephp | src/Cache/Cache.php | Cache.add | public static function add($key, $value, $config = 'default')
{
$pool = static::pool($config);
if (is_resource($value)) {
return false;
}
return $pool->add($key, $value);
} | php | public static function add($key, $value, $config = 'default')
{
$pool = static::pool($config);
if (is_resource($value)) {
return false;
}
return $pool->add($key, $value);
} | [
"public",
"static",
"function",
"add",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"config",
"=",
"'default'",
")",
"{",
"$",
"pool",
"=",
"static",
"::",
"pool",
"(",
"$",
"config",
")",
";",
"if",
"(",
"is_resource",
"(",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"pool",
"->",
"add",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}"
] | Write data for key into a cache engine if it doesn't exist already.
### Usage:
Writing to the active cache config:
```
Cache::add('cached_data', $data);
```
Writing to a specific cache config:
```
Cache::add('cached_data', $data, 'long_term');
```
@param string $key Identifier for the data.
@param mixed $value Data to be cached - anything except a resource.
@param string $config Optional string configuration name to write to. Defaults to 'default'.
@return bool True if the data was successfully cached, false on failure.
Or if the key existed already. | [
"Write",
"data",
"for",
"key",
"into",
"a",
"cache",
"engine",
"if",
"it",
"doesn",
"t",
"exist",
"already",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/Cache.php#L688-L696 |
210,875 | cakephp/cakephp | src/Utility/CookieCryptTrait.php | CookieCryptTrait._checkCipher | protected function _checkCipher($encrypt)
{
if (!in_array($encrypt, $this->_validCiphers)) {
$msg = sprintf(
'Invalid encryption cipher. Must be one of %s or false.',
implode(', ', $this->_validCiphers)
);
throw new RuntimeException($msg);
}
} | php | protected function _checkCipher($encrypt)
{
if (!in_array($encrypt, $this->_validCiphers)) {
$msg = sprintf(
'Invalid encryption cipher. Must be one of %s or false.',
implode(', ', $this->_validCiphers)
);
throw new RuntimeException($msg);
}
} | [
"protected",
"function",
"_checkCipher",
"(",
"$",
"encrypt",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"encrypt",
",",
"$",
"this",
"->",
"_validCiphers",
")",
")",
"{",
"$",
"msg",
"=",
"sprintf",
"(",
"'Invalid encryption cipher. Must be one of %s or false.'",
",",
"implode",
"(",
"', '",
",",
"$",
"this",
"->",
"_validCiphers",
")",
")",
";",
"throw",
"new",
"RuntimeException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Helper method for validating encryption cipher names.
@param string $encrypt The cipher name.
@return void
@throws \RuntimeException When an invalid cipher is provided. | [
"Helper",
"method",
"for",
"validating",
"encryption",
"cipher",
"names",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/CookieCryptTrait.php#L83-L92 |
210,876 | cakephp/cakephp | src/Utility/CookieCryptTrait.php | CookieCryptTrait._decode | protected function _decode($value, $encrypt, $key)
{
if (!$encrypt) {
return $this->_explode($value);
}
$this->_checkCipher($encrypt);
$prefix = 'Q2FrZQ==.';
$prefixLength = strlen($prefix);
if (strncmp($value, $prefix, $prefixLength) !== 0) {
return '';
}
$value = base64_decode(substr($value, $prefixLength), true);
if ($value === false || $value === '') {
return '';
}
if ($key === null) {
$key = $this->_getCookieEncryptionKey();
}
if ($encrypt === 'rijndael') {
$value = Security::rijndael($value, $key, 'decrypt');
}
if ($encrypt === 'aes') {
$value = Security::decrypt($value, $key);
}
if ($value === false) {
return '';
}
return $this->_explode($value);
} | php | protected function _decode($value, $encrypt, $key)
{
if (!$encrypt) {
return $this->_explode($value);
}
$this->_checkCipher($encrypt);
$prefix = 'Q2FrZQ==.';
$prefixLength = strlen($prefix);
if (strncmp($value, $prefix, $prefixLength) !== 0) {
return '';
}
$value = base64_decode(substr($value, $prefixLength), true);
if ($value === false || $value === '') {
return '';
}
if ($key === null) {
$key = $this->_getCookieEncryptionKey();
}
if ($encrypt === 'rijndael') {
$value = Security::rijndael($value, $key, 'decrypt');
}
if ($encrypt === 'aes') {
$value = Security::decrypt($value, $key);
}
if ($value === false) {
return '';
}
return $this->_explode($value);
} | [
"protected",
"function",
"_decode",
"(",
"$",
"value",
",",
"$",
"encrypt",
",",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"$",
"encrypt",
")",
"{",
"return",
"$",
"this",
"->",
"_explode",
"(",
"$",
"value",
")",
";",
"}",
"$",
"this",
"->",
"_checkCipher",
"(",
"$",
"encrypt",
")",
";",
"$",
"prefix",
"=",
"'Q2FrZQ==.'",
";",
"$",
"prefixLength",
"=",
"strlen",
"(",
"$",
"prefix",
")",
";",
"if",
"(",
"strncmp",
"(",
"$",
"value",
",",
"$",
"prefix",
",",
"$",
"prefixLength",
")",
"!==",
"0",
")",
"{",
"return",
"''",
";",
"}",
"$",
"value",
"=",
"base64_decode",
"(",
"substr",
"(",
"$",
"value",
",",
"$",
"prefixLength",
")",
",",
"true",
")",
";",
"if",
"(",
"$",
"value",
"===",
"false",
"||",
"$",
"value",
"===",
"''",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"$",
"key",
"===",
"null",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"_getCookieEncryptionKey",
"(",
")",
";",
"}",
"if",
"(",
"$",
"encrypt",
"===",
"'rijndael'",
")",
"{",
"$",
"value",
"=",
"Security",
"::",
"rijndael",
"(",
"$",
"value",
",",
"$",
"key",
",",
"'decrypt'",
")",
";",
"}",
"if",
"(",
"$",
"encrypt",
"===",
"'aes'",
")",
"{",
"$",
"value",
"=",
"Security",
"::",
"decrypt",
"(",
"$",
"value",
",",
"$",
"key",
")",
";",
"}",
"if",
"(",
"$",
"value",
"===",
"false",
")",
"{",
"return",
"''",
";",
"}",
"return",
"$",
"this",
"->",
"_explode",
"(",
"$",
"value",
")",
";",
"}"
] | Decodes and decrypts a single value.
@param string $value The value to decode & decrypt.
@param string|false $encrypt The encryption cipher to use.
@param string|null $key Used as the security salt if specified.
@return string|array Decoded values. | [
"Decodes",
"and",
"decrypts",
"a",
"single",
"value",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/CookieCryptTrait.php#L124-L158 |
210,877 | cakephp/cakephp | src/Http/ServerRequestFactory.php | ServerRequestFactory.createUri | public static function createUri(array $server = [])
{
$server += $_SERVER;
$server = static::normalizeServer($server);
$headers = static::marshalHeaders($server);
return static::marshalUriFromServer($server, $headers);
} | php | public static function createUri(array $server = [])
{
$server += $_SERVER;
$server = static::normalizeServer($server);
$headers = static::marshalHeaders($server);
return static::marshalUriFromServer($server, $headers);
} | [
"public",
"static",
"function",
"createUri",
"(",
"array",
"$",
"server",
"=",
"[",
"]",
")",
"{",
"$",
"server",
"+=",
"$",
"_SERVER",
";",
"$",
"server",
"=",
"static",
"::",
"normalizeServer",
"(",
"$",
"server",
")",
";",
"$",
"headers",
"=",
"static",
"::",
"marshalHeaders",
"(",
"$",
"server",
")",
";",
"return",
"static",
"::",
"marshalUriFromServer",
"(",
"$",
"server",
",",
"$",
"headers",
")",
";",
"}"
] | Create a new Uri instance from the provided server data.
@param array $server Array of server data to build the Uri from.
$_SERVER will be added into the $server parameter.
@return \Psr\Http\Message\UriInterface New instance. | [
"Create",
"a",
"new",
"Uri",
"instance",
"from",
"the",
"provided",
"server",
"data",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequestFactory.php#L69-L76 |
210,878 | cakephp/cakephp | src/Http/ServerRequestFactory.php | ServerRequestFactory.marshalUriFromServer | public static function marshalUriFromServer(array $server, array $headers)
{
$uri = parent::marshalUriFromServer($server, $headers);
list($base, $webroot) = static::getBase($uri, $server);
// Look in PATH_INFO first, as this is the exact value we need prepared
// by PHP.
$pathInfo = Hash::get($server, 'PATH_INFO');
if ($pathInfo) {
$uri = $uri->withPath($pathInfo);
} else {
$uri = static::updatePath($base, $uri);
}
if (!$uri->getHost()) {
$uri = $uri->withHost('localhost');
}
// Splat on some extra attributes to save
// some method calls.
$uri->base = $base;
$uri->webroot = $webroot;
return $uri;
} | php | public static function marshalUriFromServer(array $server, array $headers)
{
$uri = parent::marshalUriFromServer($server, $headers);
list($base, $webroot) = static::getBase($uri, $server);
// Look in PATH_INFO first, as this is the exact value we need prepared
// by PHP.
$pathInfo = Hash::get($server, 'PATH_INFO');
if ($pathInfo) {
$uri = $uri->withPath($pathInfo);
} else {
$uri = static::updatePath($base, $uri);
}
if (!$uri->getHost()) {
$uri = $uri->withHost('localhost');
}
// Splat on some extra attributes to save
// some method calls.
$uri->base = $base;
$uri->webroot = $webroot;
return $uri;
} | [
"public",
"static",
"function",
"marshalUriFromServer",
"(",
"array",
"$",
"server",
",",
"array",
"$",
"headers",
")",
"{",
"$",
"uri",
"=",
"parent",
"::",
"marshalUriFromServer",
"(",
"$",
"server",
",",
"$",
"headers",
")",
";",
"list",
"(",
"$",
"base",
",",
"$",
"webroot",
")",
"=",
"static",
"::",
"getBase",
"(",
"$",
"uri",
",",
"$",
"server",
")",
";",
"// Look in PATH_INFO first, as this is the exact value we need prepared",
"// by PHP.",
"$",
"pathInfo",
"=",
"Hash",
"::",
"get",
"(",
"$",
"server",
",",
"'PATH_INFO'",
")",
";",
"if",
"(",
"$",
"pathInfo",
")",
"{",
"$",
"uri",
"=",
"$",
"uri",
"->",
"withPath",
"(",
"$",
"pathInfo",
")",
";",
"}",
"else",
"{",
"$",
"uri",
"=",
"static",
"::",
"updatePath",
"(",
"$",
"base",
",",
"$",
"uri",
")",
";",
"}",
"if",
"(",
"!",
"$",
"uri",
"->",
"getHost",
"(",
")",
")",
"{",
"$",
"uri",
"=",
"$",
"uri",
"->",
"withHost",
"(",
"'localhost'",
")",
";",
"}",
"// Splat on some extra attributes to save",
"// some method calls.",
"$",
"uri",
"->",
"base",
"=",
"$",
"base",
";",
"$",
"uri",
"->",
"webroot",
"=",
"$",
"webroot",
";",
"return",
"$",
"uri",
";",
"}"
] | Build a UriInterface object.
Add in some CakePHP specific logic/properties that help
preserve backwards compatibility.
@param array $server The server parameters.
@param array $headers The normalized headers
@return \Psr\Http\Message\UriInterface a constructed Uri | [
"Build",
"a",
"UriInterface",
"object",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequestFactory.php#L88-L112 |
210,879 | cakephp/cakephp | src/Http/ServerRequestFactory.php | ServerRequestFactory.updatePath | protected static function updatePath($base, $uri)
{
$path = $uri->getPath();
if (strlen($base) > 0 && strpos($path, $base) === 0) {
$path = substr($path, strlen($base));
}
if ($path === '/index.php' && $uri->getQuery()) {
$path = $uri->getQuery();
}
if (empty($path) || $path === '/' || $path === '//' || $path === '/index.php') {
$path = '/';
}
$endsWithIndex = '/' . (Configure::read('App.webroot') ?: 'webroot') . '/index.php';
$endsWithLength = strlen($endsWithIndex);
if (strlen($path) >= $endsWithLength &&
substr($path, -$endsWithLength) === $endsWithIndex
) {
$path = '/';
}
return $uri->withPath($path);
} | php | protected static function updatePath($base, $uri)
{
$path = $uri->getPath();
if (strlen($base) > 0 && strpos($path, $base) === 0) {
$path = substr($path, strlen($base));
}
if ($path === '/index.php' && $uri->getQuery()) {
$path = $uri->getQuery();
}
if (empty($path) || $path === '/' || $path === '//' || $path === '/index.php') {
$path = '/';
}
$endsWithIndex = '/' . (Configure::read('App.webroot') ?: 'webroot') . '/index.php';
$endsWithLength = strlen($endsWithIndex);
if (strlen($path) >= $endsWithLength &&
substr($path, -$endsWithLength) === $endsWithIndex
) {
$path = '/';
}
return $uri->withPath($path);
} | [
"protected",
"static",
"function",
"updatePath",
"(",
"$",
"base",
",",
"$",
"uri",
")",
"{",
"$",
"path",
"=",
"$",
"uri",
"->",
"getPath",
"(",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"base",
")",
">",
"0",
"&&",
"strpos",
"(",
"$",
"path",
",",
"$",
"base",
")",
"===",
"0",
")",
"{",
"$",
"path",
"=",
"substr",
"(",
"$",
"path",
",",
"strlen",
"(",
"$",
"base",
")",
")",
";",
"}",
"if",
"(",
"$",
"path",
"===",
"'/index.php'",
"&&",
"$",
"uri",
"->",
"getQuery",
"(",
")",
")",
"{",
"$",
"path",
"=",
"$",
"uri",
"->",
"getQuery",
"(",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"path",
")",
"||",
"$",
"path",
"===",
"'/'",
"||",
"$",
"path",
"===",
"'//'",
"||",
"$",
"path",
"===",
"'/index.php'",
")",
"{",
"$",
"path",
"=",
"'/'",
";",
"}",
"$",
"endsWithIndex",
"=",
"'/'",
".",
"(",
"Configure",
"::",
"read",
"(",
"'App.webroot'",
")",
"?",
":",
"'webroot'",
")",
".",
"'/index.php'",
";",
"$",
"endsWithLength",
"=",
"strlen",
"(",
"$",
"endsWithIndex",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"path",
")",
">=",
"$",
"endsWithLength",
"&&",
"substr",
"(",
"$",
"path",
",",
"-",
"$",
"endsWithLength",
")",
"===",
"$",
"endsWithIndex",
")",
"{",
"$",
"path",
"=",
"'/'",
";",
"}",
"return",
"$",
"uri",
"->",
"withPath",
"(",
"$",
"path",
")",
";",
"}"
] | Updates the request URI to remove the base directory.
@param string $base The base path to remove.
@param \Psr\Http\Message\UriInterface $uri The uri to update.
@return \Psr\Http\Message\UriInterface The modified Uri instance. | [
"Updates",
"the",
"request",
"URI",
"to",
"remove",
"the",
"base",
"directory",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequestFactory.php#L121-L142 |
210,880 | cakephp/cakephp | src/Http/ServerRequestFactory.php | ServerRequestFactory.getBase | protected static function getBase($uri, $server)
{
$config = (array)Configure::read('App') + [
'base' => null,
'webroot' => null,
'baseUrl' => null
];
$base = $config['base'];
$baseUrl = $config['baseUrl'];
$webroot = $config['webroot'];
if ($base !== false && $base !== null) {
return [$base, $base . '/'];
}
if (!$baseUrl) {
$base = dirname(Hash::get($server, 'PHP_SELF'));
// Clean up additional / which cause following code to fail..
$base = preg_replace('#/+#', '/', $base);
$indexPos = strpos($base, '/' . $webroot . '/index.php');
if ($indexPos !== false) {
$base = substr($base, 0, $indexPos) . '/' . $webroot;
}
if ($webroot === basename($base)) {
$base = dirname($base);
}
if ($base === DIRECTORY_SEPARATOR || $base === '.') {
$base = '';
}
$base = implode('/', array_map('rawurlencode', explode('/', $base)));
return [$base, $base . '/'];
}
$file = '/' . basename($baseUrl);
$base = dirname($baseUrl);
if ($base === DIRECTORY_SEPARATOR || $base === '.') {
$base = '';
}
$webrootDir = $base . '/';
$docRoot = Hash::get($server, 'DOCUMENT_ROOT');
$docRootContainsWebroot = strpos($docRoot, $webroot);
if (!empty($base) || !$docRootContainsWebroot) {
if (strpos($webrootDir, '/' . $webroot . '/') === false) {
$webrootDir .= $webroot . '/';
}
}
return [$base . $file, $webrootDir];
} | php | protected static function getBase($uri, $server)
{
$config = (array)Configure::read('App') + [
'base' => null,
'webroot' => null,
'baseUrl' => null
];
$base = $config['base'];
$baseUrl = $config['baseUrl'];
$webroot = $config['webroot'];
if ($base !== false && $base !== null) {
return [$base, $base . '/'];
}
if (!$baseUrl) {
$base = dirname(Hash::get($server, 'PHP_SELF'));
// Clean up additional / which cause following code to fail..
$base = preg_replace('#/+#', '/', $base);
$indexPos = strpos($base, '/' . $webroot . '/index.php');
if ($indexPos !== false) {
$base = substr($base, 0, $indexPos) . '/' . $webroot;
}
if ($webroot === basename($base)) {
$base = dirname($base);
}
if ($base === DIRECTORY_SEPARATOR || $base === '.') {
$base = '';
}
$base = implode('/', array_map('rawurlencode', explode('/', $base)));
return [$base, $base . '/'];
}
$file = '/' . basename($baseUrl);
$base = dirname($baseUrl);
if ($base === DIRECTORY_SEPARATOR || $base === '.') {
$base = '';
}
$webrootDir = $base . '/';
$docRoot = Hash::get($server, 'DOCUMENT_ROOT');
$docRootContainsWebroot = strpos($docRoot, $webroot);
if (!empty($base) || !$docRootContainsWebroot) {
if (strpos($webrootDir, '/' . $webroot . '/') === false) {
$webrootDir .= $webroot . '/';
}
}
return [$base . $file, $webrootDir];
} | [
"protected",
"static",
"function",
"getBase",
"(",
"$",
"uri",
",",
"$",
"server",
")",
"{",
"$",
"config",
"=",
"(",
"array",
")",
"Configure",
"::",
"read",
"(",
"'App'",
")",
"+",
"[",
"'base'",
"=>",
"null",
",",
"'webroot'",
"=>",
"null",
",",
"'baseUrl'",
"=>",
"null",
"]",
";",
"$",
"base",
"=",
"$",
"config",
"[",
"'base'",
"]",
";",
"$",
"baseUrl",
"=",
"$",
"config",
"[",
"'baseUrl'",
"]",
";",
"$",
"webroot",
"=",
"$",
"config",
"[",
"'webroot'",
"]",
";",
"if",
"(",
"$",
"base",
"!==",
"false",
"&&",
"$",
"base",
"!==",
"null",
")",
"{",
"return",
"[",
"$",
"base",
",",
"$",
"base",
".",
"'/'",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"baseUrl",
")",
"{",
"$",
"base",
"=",
"dirname",
"(",
"Hash",
"::",
"get",
"(",
"$",
"server",
",",
"'PHP_SELF'",
")",
")",
";",
"// Clean up additional / which cause following code to fail..",
"$",
"base",
"=",
"preg_replace",
"(",
"'#/+#'",
",",
"'/'",
",",
"$",
"base",
")",
";",
"$",
"indexPos",
"=",
"strpos",
"(",
"$",
"base",
",",
"'/'",
".",
"$",
"webroot",
".",
"'/index.php'",
")",
";",
"if",
"(",
"$",
"indexPos",
"!==",
"false",
")",
"{",
"$",
"base",
"=",
"substr",
"(",
"$",
"base",
",",
"0",
",",
"$",
"indexPos",
")",
".",
"'/'",
".",
"$",
"webroot",
";",
"}",
"if",
"(",
"$",
"webroot",
"===",
"basename",
"(",
"$",
"base",
")",
")",
"{",
"$",
"base",
"=",
"dirname",
"(",
"$",
"base",
")",
";",
"}",
"if",
"(",
"$",
"base",
"===",
"DIRECTORY_SEPARATOR",
"||",
"$",
"base",
"===",
"'.'",
")",
"{",
"$",
"base",
"=",
"''",
";",
"}",
"$",
"base",
"=",
"implode",
"(",
"'/'",
",",
"array_map",
"(",
"'rawurlencode'",
",",
"explode",
"(",
"'/'",
",",
"$",
"base",
")",
")",
")",
";",
"return",
"[",
"$",
"base",
",",
"$",
"base",
".",
"'/'",
"]",
";",
"}",
"$",
"file",
"=",
"'/'",
".",
"basename",
"(",
"$",
"baseUrl",
")",
";",
"$",
"base",
"=",
"dirname",
"(",
"$",
"baseUrl",
")",
";",
"if",
"(",
"$",
"base",
"===",
"DIRECTORY_SEPARATOR",
"||",
"$",
"base",
"===",
"'.'",
")",
"{",
"$",
"base",
"=",
"''",
";",
"}",
"$",
"webrootDir",
"=",
"$",
"base",
".",
"'/'",
";",
"$",
"docRoot",
"=",
"Hash",
"::",
"get",
"(",
"$",
"server",
",",
"'DOCUMENT_ROOT'",
")",
";",
"$",
"docRootContainsWebroot",
"=",
"strpos",
"(",
"$",
"docRoot",
",",
"$",
"webroot",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"base",
")",
"||",
"!",
"$",
"docRootContainsWebroot",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"webrootDir",
",",
"'/'",
".",
"$",
"webroot",
".",
"'/'",
")",
"===",
"false",
")",
"{",
"$",
"webrootDir",
".=",
"$",
"webroot",
".",
"'/'",
";",
"}",
"}",
"return",
"[",
"$",
"base",
".",
"$",
"file",
",",
"$",
"webrootDir",
"]",
";",
"}"
] | Calculate the base directory and webroot directory.
@param \Psr\Http\Message\UriInterface $uri The Uri instance.
@param array $server The SERVER data to use.
@return array An array containing the [baseDir, webroot] | [
"Calculate",
"the",
"base",
"directory",
"and",
"webroot",
"directory",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ServerRequestFactory.php#L151-L205 |
210,881 | cakephp/cakephp | src/Validation/ValidatorAwareTrait.php | ValidatorAwareTrait.createValidator | protected function createValidator($name)
{
$method = 'validation' . ucfirst($name);
if (!$this->validationMethodExists($method)) {
$message = sprintf('The %s::%s() validation method does not exists.', __CLASS__, $method);
throw new RuntimeException($message);
}
$validator = new $this->_validatorClass;
$validator = $this->$method($validator);
if ($this instanceof EventDispatcherInterface) {
$event = defined(self::class . '::BUILD_VALIDATOR_EVENT') ? self::BUILD_VALIDATOR_EVENT : 'Model.buildValidator';
$this->dispatchEvent($event, compact('validator', 'name'));
}
if (!$validator instanceof Validator) {
throw new RuntimeException(sprintf('The %s::%s() validation method must return an instance of %s.', __CLASS__, $method, Validator::class));
}
return $validator;
} | php | protected function createValidator($name)
{
$method = 'validation' . ucfirst($name);
if (!$this->validationMethodExists($method)) {
$message = sprintf('The %s::%s() validation method does not exists.', __CLASS__, $method);
throw new RuntimeException($message);
}
$validator = new $this->_validatorClass;
$validator = $this->$method($validator);
if ($this instanceof EventDispatcherInterface) {
$event = defined(self::class . '::BUILD_VALIDATOR_EVENT') ? self::BUILD_VALIDATOR_EVENT : 'Model.buildValidator';
$this->dispatchEvent($event, compact('validator', 'name'));
}
if (!$validator instanceof Validator) {
throw new RuntimeException(sprintf('The %s::%s() validation method must return an instance of %s.', __CLASS__, $method, Validator::class));
}
return $validator;
} | [
"protected",
"function",
"createValidator",
"(",
"$",
"name",
")",
"{",
"$",
"method",
"=",
"'validation'",
".",
"ucfirst",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"validationMethodExists",
"(",
"$",
"method",
")",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'The %s::%s() validation method does not exists.'",
",",
"__CLASS__",
",",
"$",
"method",
")",
";",
"throw",
"new",
"RuntimeException",
"(",
"$",
"message",
")",
";",
"}",
"$",
"validator",
"=",
"new",
"$",
"this",
"->",
"_validatorClass",
";",
"$",
"validator",
"=",
"$",
"this",
"->",
"$",
"method",
"(",
"$",
"validator",
")",
";",
"if",
"(",
"$",
"this",
"instanceof",
"EventDispatcherInterface",
")",
"{",
"$",
"event",
"=",
"defined",
"(",
"self",
"::",
"class",
".",
"'::BUILD_VALIDATOR_EVENT'",
")",
"?",
"self",
"::",
"BUILD_VALIDATOR_EVENT",
":",
"'Model.buildValidator'",
";",
"$",
"this",
"->",
"dispatchEvent",
"(",
"$",
"event",
",",
"compact",
"(",
"'validator'",
",",
"'name'",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"validator",
"instanceof",
"Validator",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'The %s::%s() validation method must return an instance of %s.'",
",",
"__CLASS__",
",",
"$",
"method",
",",
"Validator",
"::",
"class",
")",
")",
";",
"}",
"return",
"$",
"validator",
";",
"}"
] | Creates a validator using a custom method inside your class.
This method is used only to build a new validator and it does not store
it in your object. If you want to build and reuse validators,
use getValidator() method instead.
@param string $name The name of the validation set to create.
@return \Cake\Validation\Validator
@throws \RuntimeException | [
"Creates",
"a",
"validator",
"using",
"a",
"custom",
"method",
"inside",
"your",
"class",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/ValidatorAwareTrait.php#L169-L189 |
210,882 | cakephp/cakephp | src/Validation/ValidatorAwareTrait.php | ValidatorAwareTrait.setValidator | public function setValidator($name, Validator $validator)
{
$validator->setProvider(self::VALIDATOR_PROVIDER_NAME, $this);
$this->_validators[$name] = $validator;
return $this;
} | php | public function setValidator($name, Validator $validator)
{
$validator->setProvider(self::VALIDATOR_PROVIDER_NAME, $this);
$this->_validators[$name] = $validator;
return $this;
} | [
"public",
"function",
"setValidator",
"(",
"$",
"name",
",",
"Validator",
"$",
"validator",
")",
"{",
"$",
"validator",
"->",
"setProvider",
"(",
"self",
"::",
"VALIDATOR_PROVIDER_NAME",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"_validators",
"[",
"$",
"name",
"]",
"=",
"$",
"validator",
";",
"return",
"$",
"this",
";",
"}"
] | This method stores a custom validator under the given name.
You can build the object by yourself and store it in your object:
```
$validator = new \Cake\Validation\Validator($table);
$validator
->add('email', 'valid-email', ['rule' => 'email'])
->add('password', 'valid', ['rule' => 'notBlank'])
->allowEmpty('bio');
$this->setValidator('forSubscription', $validator);
```
@param string $name The name of a validator to be set.
@param \Cake\Validation\Validator $validator Validator object to be set.
@return $this | [
"This",
"method",
"stores",
"a",
"custom",
"validator",
"under",
"the",
"given",
"name",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/ValidatorAwareTrait.php#L209-L215 |
210,883 | cakephp/cakephp | src/Validation/ValidatorAwareTrait.php | ValidatorAwareTrait.hasValidator | public function hasValidator($name)
{
$method = 'validation' . ucfirst($name);
if ($this->validationMethodExists($method)) {
return true;
}
return isset($this->_validators[$name]);
} | php | public function hasValidator($name)
{
$method = 'validation' . ucfirst($name);
if ($this->validationMethodExists($method)) {
return true;
}
return isset($this->_validators[$name]);
} | [
"public",
"function",
"hasValidator",
"(",
"$",
"name",
")",
"{",
"$",
"method",
"=",
"'validation'",
".",
"ucfirst",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"this",
"->",
"validationMethodExists",
"(",
"$",
"method",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"_validators",
"[",
"$",
"name",
"]",
")",
";",
"}"
] | Checks whether or not a validator has been set.
@param string $name The name of a validator.
@return bool | [
"Checks",
"whether",
"or",
"not",
"a",
"validator",
"has",
"been",
"set",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/ValidatorAwareTrait.php#L223-L231 |
210,884 | cakephp/cakephp | src/I18n/TranslatorFactory.php | TranslatorFactory.newInstance | public function newInstance(
$locale,
Package $package,
FormatterInterface $formatter,
TranslatorInterface $fallback = null
) {
$class = $this->class;
if ($fallback !== null && get_class($fallback) !== $class) {
throw new RuntimeException(sprintf(
'Translator fallback class %s does not match Cake\I18n\Translator, try clearing your _cake_core_ cache.',
get_class($fallback)
));
}
return new $class($locale, $package, $formatter, $fallback);
} | php | public function newInstance(
$locale,
Package $package,
FormatterInterface $formatter,
TranslatorInterface $fallback = null
) {
$class = $this->class;
if ($fallback !== null && get_class($fallback) !== $class) {
throw new RuntimeException(sprintf(
'Translator fallback class %s does not match Cake\I18n\Translator, try clearing your _cake_core_ cache.',
get_class($fallback)
));
}
return new $class($locale, $package, $formatter, $fallback);
} | [
"public",
"function",
"newInstance",
"(",
"$",
"locale",
",",
"Package",
"$",
"package",
",",
"FormatterInterface",
"$",
"formatter",
",",
"TranslatorInterface",
"$",
"fallback",
"=",
"null",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"class",
";",
"if",
"(",
"$",
"fallback",
"!==",
"null",
"&&",
"get_class",
"(",
"$",
"fallback",
")",
"!==",
"$",
"class",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Translator fallback class %s does not match Cake\\I18n\\Translator, try clearing your _cake_core_ cache.'",
",",
"get_class",
"(",
"$",
"fallback",
")",
")",
")",
";",
"}",
"return",
"new",
"$",
"class",
"(",
"$",
"locale",
",",
"$",
"package",
",",
"$",
"formatter",
",",
"$",
"fallback",
")",
";",
"}"
] | Returns a new Translator.
@param string $locale The locale code for the translator.
@param \Aura\Intl\Package $package The Package containing keys and translations.
@param \Aura\Intl\FormatterInterface $formatter The formatter to use for interpolating token values.
@param \Aura\Intl\TranslatorInterface $fallback A fallback translator to use, if any.
@throws \Cake\Core\Exception\Exception If fallback class does not match Cake\I18n\Translator
@return \Cake\I18n\Translator | [
"Returns",
"a",
"new",
"Translator",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/I18n/TranslatorFactory.php#L47-L62 |
210,885 | cakephp/cakephp | src/Database/SqlserverCompiler.php | SqlserverCompiler._buildInsertPart | protected function _buildInsertPart($parts, $query, $generator)
{
$table = $parts[0];
$columns = $this->_stringifyExpressions($parts[1], $generator);
$modifiers = $this->_buildModifierPart($query->clause('modifier'), $query, $generator);
return sprintf(
'INSERT%s INTO %s (%s) OUTPUT INSERTED.*',
$modifiers,
$table,
implode(', ', $columns)
);
} | php | protected function _buildInsertPart($parts, $query, $generator)
{
$table = $parts[0];
$columns = $this->_stringifyExpressions($parts[1], $generator);
$modifiers = $this->_buildModifierPart($query->clause('modifier'), $query, $generator);
return sprintf(
'INSERT%s INTO %s (%s) OUTPUT INSERTED.*',
$modifiers,
$table,
implode(', ', $columns)
);
} | [
"protected",
"function",
"_buildInsertPart",
"(",
"$",
"parts",
",",
"$",
"query",
",",
"$",
"generator",
")",
"{",
"$",
"table",
"=",
"$",
"parts",
"[",
"0",
"]",
";",
"$",
"columns",
"=",
"$",
"this",
"->",
"_stringifyExpressions",
"(",
"$",
"parts",
"[",
"1",
"]",
",",
"$",
"generator",
")",
";",
"$",
"modifiers",
"=",
"$",
"this",
"->",
"_buildModifierPart",
"(",
"$",
"query",
"->",
"clause",
"(",
"'modifier'",
")",
",",
"$",
"query",
",",
"$",
"generator",
")",
";",
"return",
"sprintf",
"(",
"'INSERT%s INTO %s (%s) OUTPUT INSERTED.*'",
",",
"$",
"modifiers",
",",
"$",
"table",
",",
"implode",
"(",
"', '",
",",
"$",
"columns",
")",
")",
";",
"}"
] | Generates the INSERT part of a SQL query
To better handle concurrency and low transaction isolation levels,
we also include an OUTPUT clause so we can ensure we get the inserted
row's data back.
@param array $parts The parts to build
@param \Cake\Database\Query $query The query that is being compiled
@param \Cake\Database\ValueBinder $generator the placeholder generator to be used in expressions
@return string | [
"Generates",
"the",
"INSERT",
"part",
"of",
"a",
"SQL",
"query"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/SqlserverCompiler.php#L66-L78 |
210,886 | cakephp/cakephp | src/Http/MiddlewareQueue.php | MiddlewareQueue.get | public function get($index)
{
if (isset($this->callables[$index])) {
return $this->callables[$index];
}
return $this->resolve($index);
} | php | public function get($index)
{
if (isset($this->callables[$index])) {
return $this->callables[$index];
}
return $this->resolve($index);
} | [
"public",
"function",
"get",
"(",
"$",
"index",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"callables",
"[",
"$",
"index",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"callables",
"[",
"$",
"index",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"resolve",
"(",
"$",
"index",
")",
";",
"}"
] | Get the middleware at the provided index.
@param int $index The index to fetch.
@return callable|null Either the callable middleware or null
if the index is undefined. | [
"Get",
"the",
"middleware",
"at",
"the",
"provided",
"index",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/MiddlewareQueue.php#L59-L66 |
210,887 | cakephp/cakephp | src/Http/MiddlewareQueue.php | MiddlewareQueue.resolve | protected function resolve($index)
{
if (!isset($this->queue[$index])) {
return null;
}
if (is_string($this->queue[$index])) {
$class = $this->queue[$index];
$className = App::className($class, 'Middleware', 'Middleware');
if (!$className || !class_exists($className)) {
throw new RuntimeException(sprintf(
'Middleware "%s" was not found.',
$class
));
}
$callable = new $className;
} else {
$callable = $this->queue[$index];
}
return $this->callables[$index] = $callable;
} | php | protected function resolve($index)
{
if (!isset($this->queue[$index])) {
return null;
}
if (is_string($this->queue[$index])) {
$class = $this->queue[$index];
$className = App::className($class, 'Middleware', 'Middleware');
if (!$className || !class_exists($className)) {
throw new RuntimeException(sprintf(
'Middleware "%s" was not found.',
$class
));
}
$callable = new $className;
} else {
$callable = $this->queue[$index];
}
return $this->callables[$index] = $callable;
} | [
"protected",
"function",
"resolve",
"(",
"$",
"index",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"queue",
"[",
"$",
"index",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"queue",
"[",
"$",
"index",
"]",
")",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"queue",
"[",
"$",
"index",
"]",
";",
"$",
"className",
"=",
"App",
"::",
"className",
"(",
"$",
"class",
",",
"'Middleware'",
",",
"'Middleware'",
")",
";",
"if",
"(",
"!",
"$",
"className",
"||",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Middleware \"%s\" was not found.'",
",",
"$",
"class",
")",
")",
";",
"}",
"$",
"callable",
"=",
"new",
"$",
"className",
";",
"}",
"else",
"{",
"$",
"callable",
"=",
"$",
"this",
"->",
"queue",
"[",
"$",
"index",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"callables",
"[",
"$",
"index",
"]",
"=",
"$",
"callable",
";",
"}"
] | Resolve middleware name to callable.
@param int $index The index to fetch.
@return callable|null Either the callable middleware or null
if the index is undefined. | [
"Resolve",
"middleware",
"name",
"to",
"callable",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/MiddlewareQueue.php#L75-L96 |
210,888 | cakephp/cakephp | src/Http/MiddlewareQueue.php | MiddlewareQueue.add | public function add($middleware)
{
if (is_array($middleware)) {
$this->queue = array_merge($this->queue, $middleware);
return $this;
}
$this->queue[] = $middleware;
return $this;
} | php | public function add($middleware)
{
if (is_array($middleware)) {
$this->queue = array_merge($this->queue, $middleware);
return $this;
}
$this->queue[] = $middleware;
return $this;
} | [
"public",
"function",
"add",
"(",
"$",
"middleware",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"middleware",
")",
")",
"{",
"$",
"this",
"->",
"queue",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"queue",
",",
"$",
"middleware",
")",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"queue",
"[",
"]",
"=",
"$",
"middleware",
";",
"return",
"$",
"this",
";",
"}"
] | Append a middleware callable to the end of the queue.
@param callable|string|array $middleware The middleware(s) to append.
@return $this | [
"Append",
"a",
"middleware",
"callable",
"to",
"the",
"end",
"of",
"the",
"queue",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/MiddlewareQueue.php#L104-L114 |
210,889 | cakephp/cakephp | src/Http/MiddlewareQueue.php | MiddlewareQueue.prepend | public function prepend($middleware)
{
if (is_array($middleware)) {
$this->queue = array_merge($middleware, $this->queue);
return $this;
}
array_unshift($this->queue, $middleware);
return $this;
} | php | public function prepend($middleware)
{
if (is_array($middleware)) {
$this->queue = array_merge($middleware, $this->queue);
return $this;
}
array_unshift($this->queue, $middleware);
return $this;
} | [
"public",
"function",
"prepend",
"(",
"$",
"middleware",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"middleware",
")",
")",
"{",
"$",
"this",
"->",
"queue",
"=",
"array_merge",
"(",
"$",
"middleware",
",",
"$",
"this",
"->",
"queue",
")",
";",
"return",
"$",
"this",
";",
"}",
"array_unshift",
"(",
"$",
"this",
"->",
"queue",
",",
"$",
"middleware",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Prepend a middleware to the start of the queue.
@param callable|string|array $middleware The middleware(s) to prepend.
@return $this | [
"Prepend",
"a",
"middleware",
"to",
"the",
"start",
"of",
"the",
"queue",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/MiddlewareQueue.php#L134-L144 |
210,890 | cakephp/cakephp | src/Http/MiddlewareQueue.php | MiddlewareQueue.insertBefore | public function insertBefore($class, $middleware)
{
$found = false;
$i = null;
foreach ($this->queue as $i => $object) {
if ((is_string($object) && $object === $class)
|| is_a($object, $class)
) {
$found = true;
break;
}
}
if ($found) {
return $this->insertAt($i, $middleware);
}
throw new LogicException(sprintf("No middleware matching '%s' could be found.", $class));
} | php | public function insertBefore($class, $middleware)
{
$found = false;
$i = null;
foreach ($this->queue as $i => $object) {
if ((is_string($object) && $object === $class)
|| is_a($object, $class)
) {
$found = true;
break;
}
}
if ($found) {
return $this->insertAt($i, $middleware);
}
throw new LogicException(sprintf("No middleware matching '%s' could be found.", $class));
} | [
"public",
"function",
"insertBefore",
"(",
"$",
"class",
",",
"$",
"middleware",
")",
"{",
"$",
"found",
"=",
"false",
";",
"$",
"i",
"=",
"null",
";",
"foreach",
"(",
"$",
"this",
"->",
"queue",
"as",
"$",
"i",
"=>",
"$",
"object",
")",
"{",
"if",
"(",
"(",
"is_string",
"(",
"$",
"object",
")",
"&&",
"$",
"object",
"===",
"$",
"class",
")",
"||",
"is_a",
"(",
"$",
"object",
",",
"$",
"class",
")",
")",
"{",
"$",
"found",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"found",
")",
"{",
"return",
"$",
"this",
"->",
"insertAt",
"(",
"$",
"i",
",",
"$",
"middleware",
")",
";",
"}",
"throw",
"new",
"LogicException",
"(",
"sprintf",
"(",
"\"No middleware matching '%s' could be found.\"",
",",
"$",
"class",
")",
")",
";",
"}"
] | Insert a middleware object before the first matching class.
Finds the index of the first middleware that matches the provided class,
and inserts the supplied callable before it.
@param string $class The classname to insert the middleware before.
@param callable|string $middleware The middleware to insert.
@return $this
@throws \LogicException If middleware to insert before is not found. | [
"Insert",
"a",
"middleware",
"object",
"before",
"the",
"first",
"matching",
"class",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/MiddlewareQueue.php#L174-L190 |
210,891 | cakephp/cakephp | src/Http/MiddlewareQueue.php | MiddlewareQueue.insertAfter | public function insertAfter($class, $middleware)
{
$found = false;
$i = null;
foreach ($this->queue as $i => $object) {
if ((is_string($object) && $object === $class)
|| is_a($object, $class)
) {
$found = true;
break;
}
}
if ($found) {
return $this->insertAt($i + 1, $middleware);
}
return $this->add($middleware);
} | php | public function insertAfter($class, $middleware)
{
$found = false;
$i = null;
foreach ($this->queue as $i => $object) {
if ((is_string($object) && $object === $class)
|| is_a($object, $class)
) {
$found = true;
break;
}
}
if ($found) {
return $this->insertAt($i + 1, $middleware);
}
return $this->add($middleware);
} | [
"public",
"function",
"insertAfter",
"(",
"$",
"class",
",",
"$",
"middleware",
")",
"{",
"$",
"found",
"=",
"false",
";",
"$",
"i",
"=",
"null",
";",
"foreach",
"(",
"$",
"this",
"->",
"queue",
"as",
"$",
"i",
"=>",
"$",
"object",
")",
"{",
"if",
"(",
"(",
"is_string",
"(",
"$",
"object",
")",
"&&",
"$",
"object",
"===",
"$",
"class",
")",
"||",
"is_a",
"(",
"$",
"object",
",",
"$",
"class",
")",
")",
"{",
"$",
"found",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"found",
")",
"{",
"return",
"$",
"this",
"->",
"insertAt",
"(",
"$",
"i",
"+",
"1",
",",
"$",
"middleware",
")",
";",
"}",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"middleware",
")",
";",
"}"
] | Insert a middleware object after the first matching class.
Finds the index of the first middleware that matches the provided class,
and inserts the supplied callable after it. If the class is not found,
this method will behave like add().
@param string $class The classname to insert the middleware before.
@param callable|string $middleware The middleware to insert.
@return $this | [
"Insert",
"a",
"middleware",
"object",
"after",
"the",
"first",
"matching",
"class",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/MiddlewareQueue.php#L203-L220 |
210,892 | cakephp/cakephp | src/Shell/CacheShell.php | CacheShell.listPrefixes | public function listPrefixes()
{
$prefixes = Cache::configured();
foreach ($prefixes as $prefix) {
$this->out($prefix);
}
} | php | public function listPrefixes()
{
$prefixes = Cache::configured();
foreach ($prefixes as $prefix) {
$this->out($prefix);
}
} | [
"public",
"function",
"listPrefixes",
"(",
")",
"{",
"$",
"prefixes",
"=",
"Cache",
"::",
"configured",
"(",
")",
";",
"foreach",
"(",
"$",
"prefixes",
"as",
"$",
"prefix",
")",
"{",
"$",
"this",
"->",
"out",
"(",
"$",
"prefix",
")",
";",
"}",
"}"
] | Show a list of all defined cache prefixes.
@return void | [
"Show",
"a",
"list",
"of",
"all",
"defined",
"cache",
"prefixes",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/CacheShell.php#L111-L117 |
210,893 | cakephp/cakephp | src/Database/Type/ExpressionTypeCasterTrait.php | ExpressionTypeCasterTrait._castToExpression | protected function _castToExpression($value, $type)
{
if (empty($type)) {
return $value;
}
$baseType = str_replace('[]', '', $type);
$converter = Type::build($baseType);
if (!$converter instanceof ExpressionTypeInterface) {
return $value;
}
$multi = $type !== $baseType;
if ($multi) {
return array_map([$converter, 'toExpression'], $value);
}
return $converter->toExpression($value);
} | php | protected function _castToExpression($value, $type)
{
if (empty($type)) {
return $value;
}
$baseType = str_replace('[]', '', $type);
$converter = Type::build($baseType);
if (!$converter instanceof ExpressionTypeInterface) {
return $value;
}
$multi = $type !== $baseType;
if ($multi) {
return array_map([$converter, 'toExpression'], $value);
}
return $converter->toExpression($value);
} | [
"protected",
"function",
"_castToExpression",
"(",
"$",
"value",
",",
"$",
"type",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"type",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"$",
"baseType",
"=",
"str_replace",
"(",
"'[]'",
",",
"''",
",",
"$",
"type",
")",
";",
"$",
"converter",
"=",
"Type",
"::",
"build",
"(",
"$",
"baseType",
")",
";",
"if",
"(",
"!",
"$",
"converter",
"instanceof",
"ExpressionTypeInterface",
")",
"{",
"return",
"$",
"value",
";",
"}",
"$",
"multi",
"=",
"$",
"type",
"!==",
"$",
"baseType",
";",
"if",
"(",
"$",
"multi",
")",
"{",
"return",
"array_map",
"(",
"[",
"$",
"converter",
",",
"'toExpression'",
"]",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"converter",
"->",
"toExpression",
"(",
"$",
"value",
")",
";",
"}"
] | Conditionally converts the passed value to an ExpressionInterface object
if the type class implements the ExpressionTypeInterface. Otherwise,
returns the value unmodified.
@param mixed $value The value to converto to ExpressionInterface
@param string $type The type name
@return mixed | [
"Conditionally",
"converts",
"the",
"passed",
"value",
"to",
"an",
"ExpressionInterface",
"object",
"if",
"the",
"type",
"class",
"implements",
"the",
"ExpressionTypeInterface",
".",
"Otherwise",
"returns",
"the",
"value",
"unmodified",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Type/ExpressionTypeCasterTrait.php#L36-L56 |
210,894 | cakephp/cakephp | src/Database/Type/ExpressionTypeCasterTrait.php | ExpressionTypeCasterTrait._requiresToExpressionCasting | protected function _requiresToExpressionCasting($types)
{
$result = [];
$types = array_filter($types);
foreach ($types as $k => $type) {
$object = Type::build($type);
if ($object instanceof ExpressionTypeInterface) {
$result[$k] = $object;
}
}
return $result;
} | php | protected function _requiresToExpressionCasting($types)
{
$result = [];
$types = array_filter($types);
foreach ($types as $k => $type) {
$object = Type::build($type);
if ($object instanceof ExpressionTypeInterface) {
$result[$k] = $object;
}
}
return $result;
} | [
"protected",
"function",
"_requiresToExpressionCasting",
"(",
"$",
"types",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"types",
"=",
"array_filter",
"(",
"$",
"types",
")",
";",
"foreach",
"(",
"$",
"types",
"as",
"$",
"k",
"=>",
"$",
"type",
")",
"{",
"$",
"object",
"=",
"Type",
"::",
"build",
"(",
"$",
"type",
")",
";",
"if",
"(",
"$",
"object",
"instanceof",
"ExpressionTypeInterface",
")",
"{",
"$",
"result",
"[",
"$",
"k",
"]",
"=",
"$",
"object",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns an array with the types that require values to
be casted to expressions, out of the list of type names
passed as parameter.
@param array $types List of type names
@return array | [
"Returns",
"an",
"array",
"with",
"the",
"types",
"that",
"require",
"values",
"to",
"be",
"casted",
"to",
"expressions",
"out",
"of",
"the",
"list",
"of",
"type",
"names",
"passed",
"as",
"parameter",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Type/ExpressionTypeCasterTrait.php#L66-L78 |
210,895 | cakephp/cakephp | src/Database/Type/BoolType.php | BoolType.toDatabase | public function toDatabase($value, Driver $driver)
{
if ($value === true || $value === false || $value === null) {
return $value;
}
if (in_array($value, [1, 0, '1', '0'], true)) {
return (bool)$value;
}
throw new InvalidArgumentException(sprintf(
'Cannot convert value of type `%s` to bool',
getTypeName($value)
));
} | php | public function toDatabase($value, Driver $driver)
{
if ($value === true || $value === false || $value === null) {
return $value;
}
if (in_array($value, [1, 0, '1', '0'], true)) {
return (bool)$value;
}
throw new InvalidArgumentException(sprintf(
'Cannot convert value of type `%s` to bool',
getTypeName($value)
));
} | [
"public",
"function",
"toDatabase",
"(",
"$",
"value",
",",
"Driver",
"$",
"driver",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"true",
"||",
"$",
"value",
"===",
"false",
"||",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"$",
"value",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"value",
",",
"[",
"1",
",",
"0",
",",
"'1'",
",",
"'0'",
"]",
",",
"true",
")",
")",
"{",
"return",
"(",
"bool",
")",
"$",
"value",
";",
"}",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Cannot convert value of type `%s` to bool'",
",",
"getTypeName",
"(",
"$",
"value",
")",
")",
")",
";",
"}"
] | Convert bool data into the database format.
@param mixed $value The value to convert.
@param \Cake\Database\Driver $driver The driver instance to convert with.
@return bool|null | [
"Convert",
"bool",
"data",
"into",
"the",
"database",
"format",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Type/BoolType.php#L61-L75 |
210,896 | cakephp/cakephp | src/Database/Type/BoolType.php | BoolType.toPHP | public function toPHP($value, Driver $driver)
{
if ($value === null || $value === true || $value === false) {
return $value;
}
if (!is_numeric($value)) {
return strtolower($value) === 'true';
}
return !empty($value);
} | php | public function toPHP($value, Driver $driver)
{
if ($value === null || $value === true || $value === false) {
return $value;
}
if (!is_numeric($value)) {
return strtolower($value) === 'true';
}
return !empty($value);
} | [
"public",
"function",
"toPHP",
"(",
"$",
"value",
",",
"Driver",
"$",
"driver",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
"||",
"$",
"value",
"===",
"true",
"||",
"$",
"value",
"===",
"false",
")",
"{",
"return",
"$",
"value",
";",
"}",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"return",
"strtolower",
"(",
"$",
"value",
")",
"===",
"'true'",
";",
"}",
"return",
"!",
"empty",
"(",
"$",
"value",
")",
";",
"}"
] | Convert bool values to PHP booleans
@param mixed $value The value to convert.
@param \Cake\Database\Driver $driver The driver instance to convert with.
@return bool|null | [
"Convert",
"bool",
"values",
"to",
"PHP",
"booleans"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Type/BoolType.php#L84-L95 |
210,897 | cakephp/cakephp | src/Database/Type/BoolType.php | BoolType.toStatement | public function toStatement($value, Driver $driver)
{
if ($value === null) {
return PDO::PARAM_NULL;
}
return PDO::PARAM_BOOL;
} | php | public function toStatement($value, Driver $driver)
{
if ($value === null) {
return PDO::PARAM_NULL;
}
return PDO::PARAM_BOOL;
} | [
"public",
"function",
"toStatement",
"(",
"$",
"value",
",",
"Driver",
"$",
"driver",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"PDO",
"::",
"PARAM_NULL",
";",
"}",
"return",
"PDO",
"::",
"PARAM_BOOL",
";",
"}"
] | Get the correct PDO binding type for bool data.
@param mixed $value The value being bound.
@param \Cake\Database\Driver $driver The driver.
@return int | [
"Get",
"the",
"correct",
"PDO",
"binding",
"type",
"for",
"bool",
"data",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Type/BoolType.php#L138-L145 |
210,898 | cakephp/cakephp | src/Database/Type/BoolType.php | BoolType.marshal | public function marshal($value)
{
if ($value === null) {
return null;
}
if ($value === 'true') {
return true;
}
if ($value === 'false') {
return false;
}
if (!is_scalar($value)) {
return null;
}
return !empty($value);
} | php | public function marshal($value)
{
if ($value === null) {
return null;
}
if ($value === 'true') {
return true;
}
if ($value === 'false') {
return false;
}
if (!is_scalar($value)) {
return null;
}
return !empty($value);
} | [
"public",
"function",
"marshal",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"value",
"===",
"'true'",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"value",
"===",
"'false'",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"!",
"empty",
"(",
"$",
"value",
")",
";",
"}"
] | Marshalls request data into PHP booleans.
@param mixed $value The value to convert.
@return bool|null Converted value. | [
"Marshalls",
"request",
"data",
"into",
"PHP",
"booleans",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Type/BoolType.php#L153-L169 |
210,899 | cakephp/cakephp | src/Controller/ComponentRegistry.php | ComponentRegistry.setController | public function setController(Controller $controller)
{
$this->_Controller = $controller;
$this->setEventManager($controller->getEventManager());
} | php | public function setController(Controller $controller)
{
$this->_Controller = $controller;
$this->setEventManager($controller->getEventManager());
} | [
"public",
"function",
"setController",
"(",
"Controller",
"$",
"controller",
")",
"{",
"$",
"this",
"->",
"_Controller",
"=",
"$",
"controller",
";",
"$",
"this",
"->",
"setEventManager",
"(",
"$",
"controller",
"->",
"getEventManager",
"(",
")",
")",
";",
"}"
] | Set the controller associated with the collection.
@param \Cake\Controller\Controller $controller Controller instance.
@return void | [
"Set",
"the",
"controller",
"associated",
"with",
"the",
"collection",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/ComponentRegistry.php#L68-L72 |
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.