id int32 0 241k | repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 |
|---|---|---|---|---|---|---|---|---|---|---|---|
211,400 | cakephp/cakephp | src/View/Helper/PaginatorHelper.php | PaginatorHelper.counter | public function counter($options = [])
{
if (is_string($options)) {
$options = ['format' => $options];
}
$options += [
'model' => $this->defaultModel(),
'format' => 'pages',
];
$paging = $this->params($options['model']);
if (!$paging['pageCount']) {
$paging['pageCount'] = 1;
}
switch ($options['format']) {
case 'range':
case 'pages':
$template = 'counter' . ucfirst($options['format']);
break;
default:
$template = 'counterCustom';
$this->templater()->add([$template => $options['format']]);
}
$map = array_map([$this->Number, 'format'], [
'page' => $paging['page'],
'pages' => $paging['pageCount'],
'current' => $paging['current'],
'count' => $paging['count'],
'start' => $paging['start'],
'end' => $paging['end']
]);
$map += [
'model' => strtolower(Inflector::humanize(Inflector::tableize($options['model'])))
];
return $this->templater()->format($template, $map);
} | php | public function counter($options = [])
{
if (is_string($options)) {
$options = ['format' => $options];
}
$options += [
'model' => $this->defaultModel(),
'format' => 'pages',
];
$paging = $this->params($options['model']);
if (!$paging['pageCount']) {
$paging['pageCount'] = 1;
}
switch ($options['format']) {
case 'range':
case 'pages':
$template = 'counter' . ucfirst($options['format']);
break;
default:
$template = 'counterCustom';
$this->templater()->add([$template => $options['format']]);
}
$map = array_map([$this->Number, 'format'], [
'page' => $paging['page'],
'pages' => $paging['pageCount'],
'current' => $paging['current'],
'count' => $paging['count'],
'start' => $paging['start'],
'end' => $paging['end']
]);
$map += [
'model' => strtolower(Inflector::humanize(Inflector::tableize($options['model'])))
];
return $this->templater()->format($template, $map);
} | [
"public",
"function",
"counter",
"(",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"=",
"[",
"'format'",
"=>",
"$",
"options",
"]",
";",
"}",
"$",
"options",
"+=",
"[",
"'model'",
"=>",
"$",
"this",
"->",
"defaultModel",
"(",
")",
",",
"'format'",
"=>",
"'pages'",
",",
"]",
";",
"$",
"paging",
"=",
"$",
"this",
"->",
"params",
"(",
"$",
"options",
"[",
"'model'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"paging",
"[",
"'pageCount'",
"]",
")",
"{",
"$",
"paging",
"[",
"'pageCount'",
"]",
"=",
"1",
";",
"}",
"switch",
"(",
"$",
"options",
"[",
"'format'",
"]",
")",
"{",
"case",
"'range'",
":",
"case",
"'pages'",
":",
"$",
"template",
"=",
"'counter'",
".",
"ucfirst",
"(",
"$",
"options",
"[",
"'format'",
"]",
")",
";",
"break",
";",
"default",
":",
"$",
"template",
"=",
"'counterCustom'",
";",
"$",
"this",
"->",
"templater",
"(",
")",
"->",
"add",
"(",
"[",
"$",
"template",
"=>",
"$",
"options",
"[",
"'format'",
"]",
"]",
")",
";",
"}",
"$",
"map",
"=",
"array_map",
"(",
"[",
"$",
"this",
"->",
"Number",
",",
"'format'",
"]",
",",
"[",
"'page'",
"=>",
"$",
"paging",
"[",
"'page'",
"]",
",",
"'pages'",
"=>",
"$",
"paging",
"[",
"'pageCount'",
"]",
",",
"'current'",
"=>",
"$",
"paging",
"[",
"'current'",
"]",
",",
"'count'",
"=>",
"$",
"paging",
"[",
"'count'",
"]",
",",
"'start'",
"=>",
"$",
"paging",
"[",
"'start'",
"]",
",",
"'end'",
"=>",
"$",
"paging",
"[",
"'end'",
"]",
"]",
")",
";",
"$",
"map",
"+=",
"[",
"'model'",
"=>",
"strtolower",
"(",
"Inflector",
"::",
"humanize",
"(",
"Inflector",
"::",
"tableize",
"(",
"$",
"options",
"[",
"'model'",
"]",
")",
")",
")",
"]",
";",
"return",
"$",
"this",
"->",
"templater",
"(",
")",
"->",
"format",
"(",
"$",
"template",
",",
"$",
"map",
")",
";",
"}"
] | Returns a counter string for the paged result set
### Options
- `model` The model to use, defaults to PaginatorHelper::defaultModel();
- `format` The format string you want to use, defaults to 'pages' Which generates output like '1 of 5'
set to 'range' to generate output like '1 - 3 of 13'. Can also be set to a custom string, containing
the following placeholders `{{page}}`, `{{pages}}`, `{{current}}`, `{{count}}`, `{{model}}`, `{{start}}`, `{{end}}` and any
custom content you would like.
@param string|array $options Options for the counter string. See #options for list of keys.
If string it will be used as format.
@return string Counter string.
@link https://book.cakephp.org/3.0/en/views/helpers/paginator.html#creating-a-page-counter | [
"Returns",
"a",
"counter",
"string",
"for",
"the",
"paged",
"result",
"set"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/PaginatorHelper.php#L720-L759 |
211,401 | cakephp/cakephp | src/View/Helper/PaginatorHelper.php | PaginatorHelper._getNumbersStartAndEnd | protected function _getNumbersStartAndEnd($params, $options)
{
$half = (int)($options['modulus'] / 2);
$end = max(1 + $options['modulus'], $params['page'] + $half);
$start = min($params['pageCount'] - $options['modulus'], $params['page'] - $half - $options['modulus'] % 2);
if ($options['first']) {
$first = is_int($options['first']) ? $options['first'] : 1;
if ($start <= $first + 2) {
$start = 1;
}
}
if ($options['last']) {
$last = is_int($options['last']) ? $options['last'] : 1;
if ($end >= $params['pageCount'] - $last - 1) {
$end = $params['pageCount'];
}
}
$end = min($params['pageCount'], $end);
$start = max(1, $start);
return [$start, $end];
} | php | protected function _getNumbersStartAndEnd($params, $options)
{
$half = (int)($options['modulus'] / 2);
$end = max(1 + $options['modulus'], $params['page'] + $half);
$start = min($params['pageCount'] - $options['modulus'], $params['page'] - $half - $options['modulus'] % 2);
if ($options['first']) {
$first = is_int($options['first']) ? $options['first'] : 1;
if ($start <= $first + 2) {
$start = 1;
}
}
if ($options['last']) {
$last = is_int($options['last']) ? $options['last'] : 1;
if ($end >= $params['pageCount'] - $last - 1) {
$end = $params['pageCount'];
}
}
$end = min($params['pageCount'], $end);
$start = max(1, $start);
return [$start, $end];
} | [
"protected",
"function",
"_getNumbersStartAndEnd",
"(",
"$",
"params",
",",
"$",
"options",
")",
"{",
"$",
"half",
"=",
"(",
"int",
")",
"(",
"$",
"options",
"[",
"'modulus'",
"]",
"/",
"2",
")",
";",
"$",
"end",
"=",
"max",
"(",
"1",
"+",
"$",
"options",
"[",
"'modulus'",
"]",
",",
"$",
"params",
"[",
"'page'",
"]",
"+",
"$",
"half",
")",
";",
"$",
"start",
"=",
"min",
"(",
"$",
"params",
"[",
"'pageCount'",
"]",
"-",
"$",
"options",
"[",
"'modulus'",
"]",
",",
"$",
"params",
"[",
"'page'",
"]",
"-",
"$",
"half",
"-",
"$",
"options",
"[",
"'modulus'",
"]",
"%",
"2",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'first'",
"]",
")",
"{",
"$",
"first",
"=",
"is_int",
"(",
"$",
"options",
"[",
"'first'",
"]",
")",
"?",
"$",
"options",
"[",
"'first'",
"]",
":",
"1",
";",
"if",
"(",
"$",
"start",
"<=",
"$",
"first",
"+",
"2",
")",
"{",
"$",
"start",
"=",
"1",
";",
"}",
"}",
"if",
"(",
"$",
"options",
"[",
"'last'",
"]",
")",
"{",
"$",
"last",
"=",
"is_int",
"(",
"$",
"options",
"[",
"'last'",
"]",
")",
"?",
"$",
"options",
"[",
"'last'",
"]",
":",
"1",
";",
"if",
"(",
"$",
"end",
">=",
"$",
"params",
"[",
"'pageCount'",
"]",
"-",
"$",
"last",
"-",
"1",
")",
"{",
"$",
"end",
"=",
"$",
"params",
"[",
"'pageCount'",
"]",
";",
"}",
"}",
"$",
"end",
"=",
"min",
"(",
"$",
"params",
"[",
"'pageCount'",
"]",
",",
"$",
"end",
")",
";",
"$",
"start",
"=",
"max",
"(",
"1",
",",
"$",
"start",
")",
";",
"return",
"[",
"$",
"start",
",",
"$",
"end",
"]",
";",
"}"
] | Calculates the start and end for the pagination numbers.
@param array $params Params from the numbers() method.
@param array $options Options from the numbers() method.
@return array An array with the start and end numbers. | [
"Calculates",
"the",
"start",
"and",
"end",
"for",
"the",
"pagination",
"numbers",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/PaginatorHelper.php#L837-L863 |
211,402 | cakephp/cakephp | src/View/Helper/PaginatorHelper.php | PaginatorHelper._formatNumber | protected function _formatNumber($templater, $options)
{
$url = array_merge($options['url'], ['page' => $options['page']]);
$vars = [
'text' => $options['text'],
'url' => $this->generateUrl($url, $options['model']),
];
return $templater->format('number', $vars);
} | php | protected function _formatNumber($templater, $options)
{
$url = array_merge($options['url'], ['page' => $options['page']]);
$vars = [
'text' => $options['text'],
'url' => $this->generateUrl($url, $options['model']),
];
return $templater->format('number', $vars);
} | [
"protected",
"function",
"_formatNumber",
"(",
"$",
"templater",
",",
"$",
"options",
")",
"{",
"$",
"url",
"=",
"array_merge",
"(",
"$",
"options",
"[",
"'url'",
"]",
",",
"[",
"'page'",
"=>",
"$",
"options",
"[",
"'page'",
"]",
"]",
")",
";",
"$",
"vars",
"=",
"[",
"'text'",
"=>",
"$",
"options",
"[",
"'text'",
"]",
",",
"'url'",
"=>",
"$",
"this",
"->",
"generateUrl",
"(",
"$",
"url",
",",
"$",
"options",
"[",
"'model'",
"]",
")",
",",
"]",
";",
"return",
"$",
"templater",
"->",
"format",
"(",
"'number'",
",",
"$",
"vars",
")",
";",
"}"
] | Formats a number for the paginator number output.
@param \Cake\View\StringTemplate $templater StringTemplate instance.
@param array $options Options from the numbers() method.
@return string | [
"Formats",
"a",
"number",
"for",
"the",
"paginator",
"number",
"output",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/PaginatorHelper.php#L872-L881 |
211,403 | cakephp/cakephp | src/View/Helper/PaginatorHelper.php | PaginatorHelper.meta | public function meta(array $options = [])
{
$options += [
'model' => null,
'block' => false,
'prev' => true,
'next' => true,
'first' => false,
'last' => false
];
$model = isset($options['model']) ? $options['model'] : null;
$params = $this->params($model);
$links = [];
if ($options['prev'] && $this->hasPrev()) {
$links[] = $this->Html->meta('prev', $this->generateUrl(['page' => $params['page'] - 1], null, ['fullBase' => true]));
}
if ($options['next'] && $this->hasNext()) {
$links[] = $this->Html->meta('next', $this->generateUrl(['page' => $params['page'] + 1], null, ['fullBase' => true]));
}
if ($options['first']) {
$links[] = $this->Html->meta('first', $this->generateUrl(['page' => 1], null, ['fullBase' => true]));
}
if ($options['last']) {
$links[] = $this->Html->meta('last', $this->generateUrl(['page' => $params['pageCount']], null, ['fullBase' => true]));
}
$out = implode($links);
if ($options['block'] === true) {
$options['block'] = __FUNCTION__;
}
if ($options['block']) {
$this->_View->append($options['block'], $out);
return null;
}
return $out;
} | php | public function meta(array $options = [])
{
$options += [
'model' => null,
'block' => false,
'prev' => true,
'next' => true,
'first' => false,
'last' => false
];
$model = isset($options['model']) ? $options['model'] : null;
$params = $this->params($model);
$links = [];
if ($options['prev'] && $this->hasPrev()) {
$links[] = $this->Html->meta('prev', $this->generateUrl(['page' => $params['page'] - 1], null, ['fullBase' => true]));
}
if ($options['next'] && $this->hasNext()) {
$links[] = $this->Html->meta('next', $this->generateUrl(['page' => $params['page'] + 1], null, ['fullBase' => true]));
}
if ($options['first']) {
$links[] = $this->Html->meta('first', $this->generateUrl(['page' => 1], null, ['fullBase' => true]));
}
if ($options['last']) {
$links[] = $this->Html->meta('last', $this->generateUrl(['page' => $params['pageCount']], null, ['fullBase' => true]));
}
$out = implode($links);
if ($options['block'] === true) {
$options['block'] = __FUNCTION__;
}
if ($options['block']) {
$this->_View->append($options['block'], $out);
return null;
}
return $out;
} | [
"public",
"function",
"meta",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"+=",
"[",
"'model'",
"=>",
"null",
",",
"'block'",
"=>",
"false",
",",
"'prev'",
"=>",
"true",
",",
"'next'",
"=>",
"true",
",",
"'first'",
"=>",
"false",
",",
"'last'",
"=>",
"false",
"]",
";",
"$",
"model",
"=",
"isset",
"(",
"$",
"options",
"[",
"'model'",
"]",
")",
"?",
"$",
"options",
"[",
"'model'",
"]",
":",
"null",
";",
"$",
"params",
"=",
"$",
"this",
"->",
"params",
"(",
"$",
"model",
")",
";",
"$",
"links",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"options",
"[",
"'prev'",
"]",
"&&",
"$",
"this",
"->",
"hasPrev",
"(",
")",
")",
"{",
"$",
"links",
"[",
"]",
"=",
"$",
"this",
"->",
"Html",
"->",
"meta",
"(",
"'prev'",
",",
"$",
"this",
"->",
"generateUrl",
"(",
"[",
"'page'",
"=>",
"$",
"params",
"[",
"'page'",
"]",
"-",
"1",
"]",
",",
"null",
",",
"[",
"'fullBase'",
"=>",
"true",
"]",
")",
")",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'next'",
"]",
"&&",
"$",
"this",
"->",
"hasNext",
"(",
")",
")",
"{",
"$",
"links",
"[",
"]",
"=",
"$",
"this",
"->",
"Html",
"->",
"meta",
"(",
"'next'",
",",
"$",
"this",
"->",
"generateUrl",
"(",
"[",
"'page'",
"=>",
"$",
"params",
"[",
"'page'",
"]",
"+",
"1",
"]",
",",
"null",
",",
"[",
"'fullBase'",
"=>",
"true",
"]",
")",
")",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'first'",
"]",
")",
"{",
"$",
"links",
"[",
"]",
"=",
"$",
"this",
"->",
"Html",
"->",
"meta",
"(",
"'first'",
",",
"$",
"this",
"->",
"generateUrl",
"(",
"[",
"'page'",
"=>",
"1",
"]",
",",
"null",
",",
"[",
"'fullBase'",
"=>",
"true",
"]",
")",
")",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'last'",
"]",
")",
"{",
"$",
"links",
"[",
"]",
"=",
"$",
"this",
"->",
"Html",
"->",
"meta",
"(",
"'last'",
",",
"$",
"this",
"->",
"generateUrl",
"(",
"[",
"'page'",
"=>",
"$",
"params",
"[",
"'pageCount'",
"]",
"]",
",",
"null",
",",
"[",
"'fullBase'",
"=>",
"true",
"]",
")",
")",
";",
"}",
"$",
"out",
"=",
"implode",
"(",
"$",
"links",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'block'",
"]",
"===",
"true",
")",
"{",
"$",
"options",
"[",
"'block'",
"]",
"=",
"__FUNCTION__",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'block'",
"]",
")",
"{",
"$",
"this",
"->",
"_View",
"->",
"append",
"(",
"$",
"options",
"[",
"'block'",
"]",
",",
"$",
"out",
")",
";",
"return",
"null",
";",
"}",
"return",
"$",
"out",
";",
"}"
] | Returns the meta-links for a paginated result set.
```
echo $this->Paginator->meta();
```
Echos the links directly, will output nothing if there is neither a previous nor next page.
```
$this->Paginator->meta(['block' => true]);
```
Will append the output of the meta function to the named block - if true is passed the "meta"
block is used.
### Options:
- `model` The model to use defaults to PaginatorHelper::defaultModel()
- `block` The block name to append the output to, or false/absent to return as a string
- `prev` (default True) True to generate meta for previous page
- `next` (default True) True to generate meta for next page
- `first` (default False) True to generate meta for first page
- `last` (default False) True to generate meta for last page
@param array $options Array of options
@return string|null Meta links | [
"Returns",
"the",
"meta",
"-",
"links",
"for",
"a",
"paginated",
"result",
"set",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/PaginatorHelper.php#L1175-L1219 |
211,404 | cakephp/cakephp | src/View/Helper/PaginatorHelper.php | PaginatorHelper.limitControl | public function limitControl(array $limits = [], $default = null, array $options = [])
{
$out = $this->Form->create(null, ['type' => 'get']);
if (empty($default) || !is_numeric($default)) {
$default = $this->param('perPage');
}
if (empty($limits)) {
$limits = [
'20' => '20',
'50' => '50',
'100' => '100'
];
}
$out .= $this->Form->control('limit', $options + [
'type' => 'select',
'label' => __('View'),
'value' => $default,
'options' => $limits,
'onChange' => 'this.form.submit()'
]);
$out .= $this->Form->end();
return $out;
} | php | public function limitControl(array $limits = [], $default = null, array $options = [])
{
$out = $this->Form->create(null, ['type' => 'get']);
if (empty($default) || !is_numeric($default)) {
$default = $this->param('perPage');
}
if (empty($limits)) {
$limits = [
'20' => '20',
'50' => '50',
'100' => '100'
];
}
$out .= $this->Form->control('limit', $options + [
'type' => 'select',
'label' => __('View'),
'value' => $default,
'options' => $limits,
'onChange' => 'this.form.submit()'
]);
$out .= $this->Form->end();
return $out;
} | [
"public",
"function",
"limitControl",
"(",
"array",
"$",
"limits",
"=",
"[",
"]",
",",
"$",
"default",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"out",
"=",
"$",
"this",
"->",
"Form",
"->",
"create",
"(",
"null",
",",
"[",
"'type'",
"=>",
"'get'",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"default",
")",
"||",
"!",
"is_numeric",
"(",
"$",
"default",
")",
")",
"{",
"$",
"default",
"=",
"$",
"this",
"->",
"param",
"(",
"'perPage'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"limits",
")",
")",
"{",
"$",
"limits",
"=",
"[",
"'20'",
"=>",
"'20'",
",",
"'50'",
"=>",
"'50'",
",",
"'100'",
"=>",
"'100'",
"]",
";",
"}",
"$",
"out",
".=",
"$",
"this",
"->",
"Form",
"->",
"control",
"(",
"'limit'",
",",
"$",
"options",
"+",
"[",
"'type'",
"=>",
"'select'",
",",
"'label'",
"=>",
"__",
"(",
"'View'",
")",
",",
"'value'",
"=>",
"$",
"default",
",",
"'options'",
"=>",
"$",
"limits",
",",
"'onChange'",
"=>",
"'this.form.submit()'",
"]",
")",
";",
"$",
"out",
".=",
"$",
"this",
"->",
"Form",
"->",
"end",
"(",
")",
";",
"return",
"$",
"out",
";",
"}"
] | Dropdown select for pagination limit.
This will generate a wrapping form.
@param array $limits The options array.
@param int|null $default Default option for pagination limit. Defaults to `$this->param('perPage')`.
@param array $options Options for Select tag attributes like class, id or event
@return string html output. | [
"Dropdown",
"select",
"for",
"pagination",
"limit",
".",
"This",
"will",
"generate",
"a",
"wrapping",
"form",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/PaginatorHelper.php#L1240-L1266 |
211,405 | cakephp/cakephp | src/Database/SqlDialectTrait.php | SqlDialectTrait.queryTranslator | public function queryTranslator($type)
{
return function ($query) use ($type) {
if ($this->isAutoQuotingEnabled()) {
$query = (new IdentifierQuoter($this))->quote($query);
}
/** @var \Cake\ORM\Query $query */
$query = $this->{'_' . $type . 'QueryTranslator'}($query);
$translators = $this->_expressionTranslators();
if (!$translators) {
return $query;
}
$query->traverseExpressions(function ($expression) use ($translators, $query) {
foreach ($translators as $class => $method) {
if ($expression instanceof $class) {
$this->{$method}($expression, $query);
}
}
});
return $query;
};
} | php | public function queryTranslator($type)
{
return function ($query) use ($type) {
if ($this->isAutoQuotingEnabled()) {
$query = (new IdentifierQuoter($this))->quote($query);
}
/** @var \Cake\ORM\Query $query */
$query = $this->{'_' . $type . 'QueryTranslator'}($query);
$translators = $this->_expressionTranslators();
if (!$translators) {
return $query;
}
$query->traverseExpressions(function ($expression) use ($translators, $query) {
foreach ($translators as $class => $method) {
if ($expression instanceof $class) {
$this->{$method}($expression, $query);
}
}
});
return $query;
};
} | [
"public",
"function",
"queryTranslator",
"(",
"$",
"type",
")",
"{",
"return",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isAutoQuotingEnabled",
"(",
")",
")",
"{",
"$",
"query",
"=",
"(",
"new",
"IdentifierQuoter",
"(",
"$",
"this",
")",
")",
"->",
"quote",
"(",
"$",
"query",
")",
";",
"}",
"/** @var \\Cake\\ORM\\Query $query */",
"$",
"query",
"=",
"$",
"this",
"->",
"{",
"'_'",
".",
"$",
"type",
".",
"'QueryTranslator'",
"}",
"(",
"$",
"query",
")",
";",
"$",
"translators",
"=",
"$",
"this",
"->",
"_expressionTranslators",
"(",
")",
";",
"if",
"(",
"!",
"$",
"translators",
")",
"{",
"return",
"$",
"query",
";",
"}",
"$",
"query",
"->",
"traverseExpressions",
"(",
"function",
"(",
"$",
"expression",
")",
"use",
"(",
"$",
"translators",
",",
"$",
"query",
")",
"{",
"foreach",
"(",
"$",
"translators",
"as",
"$",
"class",
"=>",
"$",
"method",
")",
"{",
"if",
"(",
"$",
"expression",
"instanceof",
"$",
"class",
")",
"{",
"$",
"this",
"->",
"{",
"$",
"method",
"}",
"(",
"$",
"expression",
",",
"$",
"query",
")",
";",
"}",
"}",
"}",
")",
";",
"return",
"$",
"query",
";",
"}",
";",
"}"
] | Returns a callable function that will be used to transform a passed Query object.
This function, in turn, will return an instance of a Query object that has been
transformed to accommodate any specificities of the SQL dialect in use.
@param string $type the type of query to be transformed
(select, insert, update, delete)
@return callable | [
"Returns",
"a",
"callable",
"function",
"that",
"will",
"be",
"used",
"to",
"transform",
"a",
"passed",
"Query",
"object",
".",
"This",
"function",
"in",
"turn",
"will",
"return",
"an",
"instance",
"of",
"a",
"Query",
"object",
"that",
"has",
"been",
"transformed",
"to",
"accommodate",
"any",
"specificities",
"of",
"the",
"SQL",
"dialect",
"in",
"use",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/SqlDialectTrait.php#L91-L115 |
211,406 | cakephp/cakephp | src/Database/SqlDialectTrait.php | SqlDialectTrait._deleteQueryTranslator | protected function _deleteQueryTranslator($query)
{
$hadAlias = false;
$tables = [];
foreach ($query->clause('from') as $alias => $table) {
if (is_string($alias)) {
$hadAlias = true;
}
$tables[] = $table;
}
if ($hadAlias) {
$query->from($tables, true);
}
if (!$hadAlias) {
return $query;
}
return $this->_removeAliasesFromConditions($query);
} | php | protected function _deleteQueryTranslator($query)
{
$hadAlias = false;
$tables = [];
foreach ($query->clause('from') as $alias => $table) {
if (is_string($alias)) {
$hadAlias = true;
}
$tables[] = $table;
}
if ($hadAlias) {
$query->from($tables, true);
}
if (!$hadAlias) {
return $query;
}
return $this->_removeAliasesFromConditions($query);
} | [
"protected",
"function",
"_deleteQueryTranslator",
"(",
"$",
"query",
")",
"{",
"$",
"hadAlias",
"=",
"false",
";",
"$",
"tables",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"query",
"->",
"clause",
"(",
"'from'",
")",
"as",
"$",
"alias",
"=>",
"$",
"table",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"alias",
")",
")",
"{",
"$",
"hadAlias",
"=",
"true",
";",
"}",
"$",
"tables",
"[",
"]",
"=",
"$",
"table",
";",
"}",
"if",
"(",
"$",
"hadAlias",
")",
"{",
"$",
"query",
"->",
"from",
"(",
"$",
"tables",
",",
"true",
")",
";",
"}",
"if",
"(",
"!",
"$",
"hadAlias",
")",
"{",
"return",
"$",
"query",
";",
"}",
"return",
"$",
"this",
"->",
"_removeAliasesFromConditions",
"(",
"$",
"query",
")",
";",
"}"
] | Apply translation steps to delete queries.
Chops out aliases on delete query conditions as most database dialects do not
support aliases in delete queries. This also removes aliases
in table names as they frequently don't work either.
We are intentionally not supporting deletes with joins as they have even poorer support.
@param \Cake\Database\Query $query The query to translate
@return \Cake\Database\Query The modified query | [
"Apply",
"translation",
"steps",
"to",
"delete",
"queries",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/SqlDialectTrait.php#L169-L188 |
211,407 | cakephp/cakephp | src/Database/SqlDialectTrait.php | SqlDialectTrait._removeAliasesFromConditions | protected function _removeAliasesFromConditions($query)
{
if ($query->clause('join')) {
throw new \RuntimeException(
'Aliases are being removed from conditions for UPDATE/DELETE queries, ' .
'this can break references to joined tables.'
);
}
$conditions = $query->clause('where');
if ($conditions) {
$conditions->traverse(function ($condition) {
if (!($condition instanceof Comparison)) {
return $condition;
}
$field = $condition->getField();
if ($field instanceof ExpressionInterface || strpos($field, '.') === false) {
return $condition;
}
list(, $field) = explode('.', $field);
$condition->setField($field);
return $condition;
});
}
return $query;
} | php | protected function _removeAliasesFromConditions($query)
{
if ($query->clause('join')) {
throw new \RuntimeException(
'Aliases are being removed from conditions for UPDATE/DELETE queries, ' .
'this can break references to joined tables.'
);
}
$conditions = $query->clause('where');
if ($conditions) {
$conditions->traverse(function ($condition) {
if (!($condition instanceof Comparison)) {
return $condition;
}
$field = $condition->getField();
if ($field instanceof ExpressionInterface || strpos($field, '.') === false) {
return $condition;
}
list(, $field) = explode('.', $field);
$condition->setField($field);
return $condition;
});
}
return $query;
} | [
"protected",
"function",
"_removeAliasesFromConditions",
"(",
"$",
"query",
")",
"{",
"if",
"(",
"$",
"query",
"->",
"clause",
"(",
"'join'",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Aliases are being removed from conditions for UPDATE/DELETE queries, '",
".",
"'this can break references to joined tables.'",
")",
";",
"}",
"$",
"conditions",
"=",
"$",
"query",
"->",
"clause",
"(",
"'where'",
")",
";",
"if",
"(",
"$",
"conditions",
")",
"{",
"$",
"conditions",
"->",
"traverse",
"(",
"function",
"(",
"$",
"condition",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"condition",
"instanceof",
"Comparison",
")",
")",
"{",
"return",
"$",
"condition",
";",
"}",
"$",
"field",
"=",
"$",
"condition",
"->",
"getField",
"(",
")",
";",
"if",
"(",
"$",
"field",
"instanceof",
"ExpressionInterface",
"||",
"strpos",
"(",
"$",
"field",
",",
"'.'",
")",
"===",
"false",
")",
"{",
"return",
"$",
"condition",
";",
"}",
"list",
"(",
",",
"$",
"field",
")",
"=",
"explode",
"(",
"'.'",
",",
"$",
"field",
")",
";",
"$",
"condition",
"->",
"setField",
"(",
"$",
"field",
")",
";",
"return",
"$",
"condition",
";",
"}",
")",
";",
"}",
"return",
"$",
"query",
";",
"}"
] | Removes aliases from the `WHERE` clause of a query.
@param \Cake\Database\Query $query The query to process.
@return \Cake\Database\Query The modified query.
@throws \RuntimeException In case the processed query contains any joins, as removing
aliases from the conditions can break references to the joined tables. | [
"Removes",
"aliases",
"from",
"the",
"WHERE",
"clause",
"of",
"a",
"query",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/SqlDialectTrait.php#L214-L243 |
211,408 | cakephp/cakephp | src/ORM/AssociationCollection.php | AssociationCollection.add | public function add($alias, Association $association)
{
list(, $alias) = pluginSplit($alias);
return $this->_items[strtolower($alias)] = $association;
} | php | public function add($alias, Association $association)
{
list(, $alias) = pluginSplit($alias);
return $this->_items[strtolower($alias)] = $association;
} | [
"public",
"function",
"add",
"(",
"$",
"alias",
",",
"Association",
"$",
"association",
")",
"{",
"list",
"(",
",",
"$",
"alias",
")",
"=",
"pluginSplit",
"(",
"$",
"alias",
")",
";",
"return",
"$",
"this",
"->",
"_items",
"[",
"strtolower",
"(",
"$",
"alias",
")",
"]",
"=",
"$",
"association",
";",
"}"
] | Add an association to the collection
If the alias added contains a `.` the part preceding the `.` will be dropped.
This makes using plugins simpler as the Plugin.Class syntax is frequently used.
@param string $alias The association alias
@param \Cake\ORM\Association $association The association to add.
@return \Cake\ORM\Association The association object being added. | [
"Add",
"an",
"association",
"to",
"the",
"collection"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/AssociationCollection.php#L68-L73 |
211,409 | cakephp/cakephp | src/ORM/AssociationCollection.php | AssociationCollection.load | public function load($className, $associated, array $options = [])
{
$options += [
'tableLocator' => $this->getTableLocator()
];
$association = new $className($associated, $options);
if (!$association instanceof Association) {
$message = sprintf('The association must extend `%s` class, `%s` given.', Association::class, get_class($association));
throw new InvalidArgumentException($message);
}
return $this->add($association->getName(), $association);
} | php | public function load($className, $associated, array $options = [])
{
$options += [
'tableLocator' => $this->getTableLocator()
];
$association = new $className($associated, $options);
if (!$association instanceof Association) {
$message = sprintf('The association must extend `%s` class, `%s` given.', Association::class, get_class($association));
throw new InvalidArgumentException($message);
}
return $this->add($association->getName(), $association);
} | [
"public",
"function",
"load",
"(",
"$",
"className",
",",
"$",
"associated",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"+=",
"[",
"'tableLocator'",
"=>",
"$",
"this",
"->",
"getTableLocator",
"(",
")",
"]",
";",
"$",
"association",
"=",
"new",
"$",
"className",
"(",
"$",
"associated",
",",
"$",
"options",
")",
";",
"if",
"(",
"!",
"$",
"association",
"instanceof",
"Association",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'The association must extend `%s` class, `%s` given.'",
",",
"Association",
"::",
"class",
",",
"get_class",
"(",
"$",
"association",
")",
")",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"message",
")",
";",
"}",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"association",
"->",
"getName",
"(",
")",
",",
"$",
"association",
")",
";",
"}"
] | Creates and adds the Association object to this collection.
@param string $className The name of association class.
@param string $associated The alias for the target table.
@param array $options List of options to configure the association definition.
@return \Cake\ORM\Association
@throws \InvalidArgumentException | [
"Creates",
"and",
"adds",
"the",
"Association",
"object",
"to",
"this",
"collection",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/AssociationCollection.php#L84-L97 |
211,410 | cakephp/cakephp | src/ORM/AssociationCollection.php | AssociationCollection.get | public function get($alias)
{
$alias = strtolower($alias);
if (isset($this->_items[$alias])) {
return $this->_items[$alias];
}
return null;
} | php | public function get($alias)
{
$alias = strtolower($alias);
if (isset($this->_items[$alias])) {
return $this->_items[$alias];
}
return null;
} | [
"public",
"function",
"get",
"(",
"$",
"alias",
")",
"{",
"$",
"alias",
"=",
"strtolower",
"(",
"$",
"alias",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_items",
"[",
"$",
"alias",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_items",
"[",
"$",
"alias",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Fetch an attached association by name.
@param string $alias The association alias to get.
@return \Cake\ORM\Association|null Either the association or null. | [
"Fetch",
"an",
"attached",
"association",
"by",
"name",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/AssociationCollection.php#L105-L113 |
211,411 | cakephp/cakephp | src/ORM/AssociationCollection.php | AssociationCollection.getByProperty | public function getByProperty($prop)
{
foreach ($this->_items as $assoc) {
if ($assoc->getProperty() === $prop) {
return $assoc;
}
}
return null;
} | php | public function getByProperty($prop)
{
foreach ($this->_items as $assoc) {
if ($assoc->getProperty() === $prop) {
return $assoc;
}
}
return null;
} | [
"public",
"function",
"getByProperty",
"(",
"$",
"prop",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_items",
"as",
"$",
"assoc",
")",
"{",
"if",
"(",
"$",
"assoc",
"->",
"getProperty",
"(",
")",
"===",
"$",
"prop",
")",
"{",
"return",
"$",
"assoc",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Fetch an association by property name.
@param string $prop The property to find an association by.
@return \Cake\ORM\Association|null Either the association or null. | [
"Fetch",
"an",
"association",
"by",
"property",
"name",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/AssociationCollection.php#L121-L130 |
211,412 | cakephp/cakephp | src/ORM/AssociationCollection.php | AssociationCollection.getByType | public function getByType($class)
{
$class = array_map('strtolower', (array)$class);
$out = array_filter($this->_items, function ($assoc) use ($class) {
list(, $name) = namespaceSplit(get_class($assoc));
return in_array(strtolower($name), $class, true);
});
return array_values($out);
} | php | public function getByType($class)
{
$class = array_map('strtolower', (array)$class);
$out = array_filter($this->_items, function ($assoc) use ($class) {
list(, $name) = namespaceSplit(get_class($assoc));
return in_array(strtolower($name), $class, true);
});
return array_values($out);
} | [
"public",
"function",
"getByType",
"(",
"$",
"class",
")",
"{",
"$",
"class",
"=",
"array_map",
"(",
"'strtolower'",
",",
"(",
"array",
")",
"$",
"class",
")",
";",
"$",
"out",
"=",
"array_filter",
"(",
"$",
"this",
"->",
"_items",
",",
"function",
"(",
"$",
"assoc",
")",
"use",
"(",
"$",
"class",
")",
"{",
"list",
"(",
",",
"$",
"name",
")",
"=",
"namespaceSplit",
"(",
"get_class",
"(",
"$",
"assoc",
")",
")",
";",
"return",
"in_array",
"(",
"strtolower",
"(",
"$",
"name",
")",
",",
"$",
"class",
",",
"true",
")",
";",
"}",
")",
";",
"return",
"array_values",
"(",
"$",
"out",
")",
";",
"}"
] | Get an array of associations matching a specific type.
@param string|array $class The type of associations you want.
For example 'BelongsTo' or array like ['BelongsTo', 'HasOne']
@return array An array of Association objects.
@since 3.5.3 | [
"Get",
"an",
"array",
"of",
"associations",
"matching",
"a",
"specific",
"type",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/AssociationCollection.php#L179-L190 |
211,413 | cakephp/cakephp | src/ORM/AssociationCollection.php | AssociationCollection.saveParents | public function saveParents(Table $table, EntityInterface $entity, $associations, array $options = [])
{
if (empty($associations)) {
return true;
}
return $this->_saveAssociations($table, $entity, $associations, $options, false);
} | php | public function saveParents(Table $table, EntityInterface $entity, $associations, array $options = [])
{
if (empty($associations)) {
return true;
}
return $this->_saveAssociations($table, $entity, $associations, $options, false);
} | [
"public",
"function",
"saveParents",
"(",
"Table",
"$",
"table",
",",
"EntityInterface",
"$",
"entity",
",",
"$",
"associations",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"associations",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"$",
"this",
"->",
"_saveAssociations",
"(",
"$",
"table",
",",
"$",
"entity",
",",
"$",
"associations",
",",
"$",
"options",
",",
"false",
")",
";",
"}"
] | Save all the associations that are parents of the given entity.
Parent associations include any association where the given table
is the owning side.
@param \Cake\ORM\Table $table The table entity is for.
@param \Cake\Datasource\EntityInterface $entity The entity to save associated data for.
@param array $associations The list of associations to save parents from.
associations not in this list will not be saved.
@param array $options The options for the save operation.
@return bool Success | [
"Save",
"all",
"the",
"associations",
"that",
"are",
"parents",
"of",
"the",
"given",
"entity",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/AssociationCollection.php#L232-L239 |
211,414 | cakephp/cakephp | src/ORM/AssociationCollection.php | AssociationCollection.saveChildren | public function saveChildren(Table $table, EntityInterface $entity, array $associations, array $options)
{
if (empty($associations)) {
return true;
}
return $this->_saveAssociations($table, $entity, $associations, $options, true);
} | php | public function saveChildren(Table $table, EntityInterface $entity, array $associations, array $options)
{
if (empty($associations)) {
return true;
}
return $this->_saveAssociations($table, $entity, $associations, $options, true);
} | [
"public",
"function",
"saveChildren",
"(",
"Table",
"$",
"table",
",",
"EntityInterface",
"$",
"entity",
",",
"array",
"$",
"associations",
",",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"associations",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"$",
"this",
"->",
"_saveAssociations",
"(",
"$",
"table",
",",
"$",
"entity",
",",
"$",
"associations",
",",
"$",
"options",
",",
"true",
")",
";",
"}"
] | Save all the associations that are children of the given entity.
Child associations include any association where the given table
is not the owning side.
@param \Cake\ORM\Table $table The table entity is for.
@param \Cake\Datasource\EntityInterface $entity The entity to save associated data for.
@param array $associations The list of associations to save children from.
associations not in this list will not be saved.
@param array $options The options for the save operation.
@return bool Success | [
"Save",
"all",
"the",
"associations",
"that",
"are",
"children",
"of",
"the",
"given",
"entity",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/AssociationCollection.php#L254-L261 |
211,415 | cakephp/cakephp | src/ORM/AssociationCollection.php | AssociationCollection.cascadeDelete | public function cascadeDelete(EntityInterface $entity, array $options)
{
$noCascade = $this->_getNoCascadeItems($entity, $options);
foreach ($noCascade as $assoc) {
$assoc->cascadeDelete($entity, $options);
}
} | php | public function cascadeDelete(EntityInterface $entity, array $options)
{
$noCascade = $this->_getNoCascadeItems($entity, $options);
foreach ($noCascade as $assoc) {
$assoc->cascadeDelete($entity, $options);
}
} | [
"public",
"function",
"cascadeDelete",
"(",
"EntityInterface",
"$",
"entity",
",",
"array",
"$",
"options",
")",
"{",
"$",
"noCascade",
"=",
"$",
"this",
"->",
"_getNoCascadeItems",
"(",
"$",
"entity",
",",
"$",
"options",
")",
";",
"foreach",
"(",
"$",
"noCascade",
"as",
"$",
"assoc",
")",
"{",
"$",
"assoc",
"->",
"cascadeDelete",
"(",
"$",
"entity",
",",
"$",
"options",
")",
";",
"}",
"}"
] | Cascade a delete across the various associations.
Cascade first across associations for which cascadeCallbacks is true.
@param \Cake\Datasource\EntityInterface $entity The entity to delete associations for.
@param array $options The options used in the delete operation.
@return void | [
"Cascade",
"a",
"delete",
"across",
"the",
"various",
"associations",
".",
"Cascade",
"first",
"across",
"associations",
"for",
"which",
"cascadeCallbacks",
"is",
"true",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/AssociationCollection.php#L332-L338 |
211,416 | cakephp/cakephp | src/ORM/AssociationCollection.php | AssociationCollection._getNoCascadeItems | protected function _getNoCascadeItems($entity, $options)
{
$noCascade = [];
foreach ($this->_items as $assoc) {
if (!$assoc->getCascadeCallbacks()) {
$noCascade[] = $assoc;
continue;
}
$assoc->cascadeDelete($entity, $options);
}
return $noCascade;
} | php | protected function _getNoCascadeItems($entity, $options)
{
$noCascade = [];
foreach ($this->_items as $assoc) {
if (!$assoc->getCascadeCallbacks()) {
$noCascade[] = $assoc;
continue;
}
$assoc->cascadeDelete($entity, $options);
}
return $noCascade;
} | [
"protected",
"function",
"_getNoCascadeItems",
"(",
"$",
"entity",
",",
"$",
"options",
")",
"{",
"$",
"noCascade",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_items",
"as",
"$",
"assoc",
")",
"{",
"if",
"(",
"!",
"$",
"assoc",
"->",
"getCascadeCallbacks",
"(",
")",
")",
"{",
"$",
"noCascade",
"[",
"]",
"=",
"$",
"assoc",
";",
"continue",
";",
"}",
"$",
"assoc",
"->",
"cascadeDelete",
"(",
"$",
"entity",
",",
"$",
"options",
")",
";",
"}",
"return",
"$",
"noCascade",
";",
"}"
] | Returns items that have no cascade callback.
@param \Cake\Datasource\EntityInterface $entity The entity to delete associations for.
@param array $options The options used in the delete operation.
@return \Cake\ORM\Association[] | [
"Returns",
"items",
"that",
"have",
"no",
"cascade",
"callback",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/AssociationCollection.php#L347-L359 |
211,417 | cakephp/cakephp | src/ORM/AssociationCollection.php | AssociationCollection.normalizeKeys | public function normalizeKeys($keys)
{
if ($keys === true) {
$keys = $this->keys();
}
if (empty($keys)) {
return [];
}
return $this->_normalizeAssociations($keys);
} | php | public function normalizeKeys($keys)
{
if ($keys === true) {
$keys = $this->keys();
}
if (empty($keys)) {
return [];
}
return $this->_normalizeAssociations($keys);
} | [
"public",
"function",
"normalizeKeys",
"(",
"$",
"keys",
")",
"{",
"if",
"(",
"$",
"keys",
"===",
"true",
")",
"{",
"$",
"keys",
"=",
"$",
"this",
"->",
"keys",
"(",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"keys",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"_normalizeAssociations",
"(",
"$",
"keys",
")",
";",
"}"
] | Returns an associative array of association names out a mixed
array. If true is passed, then it returns all association names
in this collection.
@param bool|array $keys the list of association names to normalize
@return array | [
"Returns",
"an",
"associative",
"array",
"of",
"association",
"names",
"out",
"a",
"mixed",
"array",
".",
"If",
"true",
"is",
"passed",
"then",
"it",
"returns",
"all",
"association",
"names",
"in",
"this",
"collection",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/AssociationCollection.php#L369-L380 |
211,418 | cakephp/cakephp | src/Database/Driver/Postgres.php | Postgres.setEncoding | public function setEncoding($encoding)
{
$this->connect();
$this->_connection->exec('SET NAMES ' . $this->_connection->quote($encoding));
} | php | public function setEncoding($encoding)
{
$this->connect();
$this->_connection->exec('SET NAMES ' . $this->_connection->quote($encoding));
} | [
"public",
"function",
"setEncoding",
"(",
"$",
"encoding",
")",
"{",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"$",
"this",
"->",
"_connection",
"->",
"exec",
"(",
"'SET NAMES '",
".",
"$",
"this",
"->",
"_connection",
"->",
"quote",
"(",
"$",
"encoding",
")",
")",
";",
"}"
] | Sets connection encoding
@param string $encoding The encoding to use.
@return void | [
"Sets",
"connection",
"encoding"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Driver/Postgres.php#L107-L111 |
211,419 | cakephp/cakephp | src/Database/Driver/Postgres.php | Postgres.setSchema | public function setSchema($schema)
{
$this->connect();
$this->_connection->exec('SET search_path TO ' . $this->_connection->quote($schema));
} | php | public function setSchema($schema)
{
$this->connect();
$this->_connection->exec('SET search_path TO ' . $this->_connection->quote($schema));
} | [
"public",
"function",
"setSchema",
"(",
"$",
"schema",
")",
"{",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"$",
"this",
"->",
"_connection",
"->",
"exec",
"(",
"'SET search_path TO '",
".",
"$",
"this",
"->",
"_connection",
"->",
"quote",
"(",
"$",
"schema",
")",
")",
";",
"}"
] | Sets connection default schema, if any relation defined in a query is not fully qualified
postgres will fallback to looking the relation into defined default schema
@param string $schema The schema names to set `search_path` to.
@return void | [
"Sets",
"connection",
"default",
"schema",
"if",
"any",
"relation",
"defined",
"in",
"a",
"query",
"is",
"not",
"fully",
"qualified",
"postgres",
"will",
"fallback",
"to",
"looking",
"the",
"relation",
"into",
"defined",
"default",
"schema"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Driver/Postgres.php#L120-L124 |
211,420 | cakephp/cakephp | src/Http/Middleware/EncryptedCookieMiddleware.php | EncryptedCookieMiddleware.decodeCookies | protected function decodeCookies(ServerRequestInterface $request)
{
$cookies = $request->getCookieParams();
foreach ($this->cookieNames as $name) {
if (isset($cookies[$name])) {
$cookies[$name] = $this->_decrypt($cookies[$name], $this->cipherType, $this->key);
}
}
return $request->withCookieParams($cookies);
} | php | protected function decodeCookies(ServerRequestInterface $request)
{
$cookies = $request->getCookieParams();
foreach ($this->cookieNames as $name) {
if (isset($cookies[$name])) {
$cookies[$name] = $this->_decrypt($cookies[$name], $this->cipherType, $this->key);
}
}
return $request->withCookieParams($cookies);
} | [
"protected",
"function",
"decodeCookies",
"(",
"ServerRequestInterface",
"$",
"request",
")",
"{",
"$",
"cookies",
"=",
"$",
"request",
"->",
"getCookieParams",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"cookieNames",
"as",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"cookies",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"cookies",
"[",
"$",
"name",
"]",
"=",
"$",
"this",
"->",
"_decrypt",
"(",
"$",
"cookies",
"[",
"$",
"name",
"]",
",",
"$",
"this",
"->",
"cipherType",
",",
"$",
"this",
"->",
"key",
")",
";",
"}",
"}",
"return",
"$",
"request",
"->",
"withCookieParams",
"(",
"$",
"cookies",
")",
";",
"}"
] | Decode cookies from the request.
@param \Psr\Http\Message\ServerRequestInterface $request The request to decode cookies from.
@return \Psr\Http\Message\ServerRequestInterface Updated request with decoded cookies. | [
"Decode",
"cookies",
"from",
"the",
"request",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Middleware/EncryptedCookieMiddleware.php#L118-L128 |
211,421 | cakephp/cakephp | src/Http/Middleware/EncryptedCookieMiddleware.php | EncryptedCookieMiddleware.encodeCookies | protected function encodeCookies(Response $response)
{
$cookies = $response->getCookieCollection();
foreach ($cookies as $cookie) {
if (in_array($cookie->getName(), $this->cookieNames, true)) {
$value = $this->_encrypt($cookie->getValue(), $this->cipherType);
$response = $response->withCookie($cookie->withValue($value));
}
}
return $response;
} | php | protected function encodeCookies(Response $response)
{
$cookies = $response->getCookieCollection();
foreach ($cookies as $cookie) {
if (in_array($cookie->getName(), $this->cookieNames, true)) {
$value = $this->_encrypt($cookie->getValue(), $this->cipherType);
$response = $response->withCookie($cookie->withValue($value));
}
}
return $response;
} | [
"protected",
"function",
"encodeCookies",
"(",
"Response",
"$",
"response",
")",
"{",
"$",
"cookies",
"=",
"$",
"response",
"->",
"getCookieCollection",
"(",
")",
";",
"foreach",
"(",
"$",
"cookies",
"as",
"$",
"cookie",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"cookie",
"->",
"getName",
"(",
")",
",",
"$",
"this",
"->",
"cookieNames",
",",
"true",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"_encrypt",
"(",
"$",
"cookie",
"->",
"getValue",
"(",
")",
",",
"$",
"this",
"->",
"cipherType",
")",
";",
"$",
"response",
"=",
"$",
"response",
"->",
"withCookie",
"(",
"$",
"cookie",
"->",
"withValue",
"(",
"$",
"value",
")",
")",
";",
"}",
"}",
"return",
"$",
"response",
";",
"}"
] | Encode cookies from a response's CookieCollection.
@param \Cake\Http\Response $response The response to encode cookies in.
@return \Cake\Http\Response Updated response with encoded cookies. | [
"Encode",
"cookies",
"from",
"a",
"response",
"s",
"CookieCollection",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Middleware/EncryptedCookieMiddleware.php#L136-L147 |
211,422 | cakephp/cakephp | src/Http/Middleware/EncryptedCookieMiddleware.php | EncryptedCookieMiddleware.encodeSetCookieHeader | protected function encodeSetCookieHeader(ResponseInterface $response)
{
$cookies = CookieCollection::createFromHeader($response->getHeader('Set-Cookie'));
$header = [];
foreach ($cookies as $cookie) {
if (in_array($cookie->getName(), $this->cookieNames, true)) {
$value = $this->_encrypt($cookie->getValue(), $this->cipherType);
$cookie = $cookie->withValue($value);
}
$header[] = $cookie->toHeaderValue();
}
return $response->withHeader('Set-Cookie', $header);
} | php | protected function encodeSetCookieHeader(ResponseInterface $response)
{
$cookies = CookieCollection::createFromHeader($response->getHeader('Set-Cookie'));
$header = [];
foreach ($cookies as $cookie) {
if (in_array($cookie->getName(), $this->cookieNames, true)) {
$value = $this->_encrypt($cookie->getValue(), $this->cipherType);
$cookie = $cookie->withValue($value);
}
$header[] = $cookie->toHeaderValue();
}
return $response->withHeader('Set-Cookie', $header);
} | [
"protected",
"function",
"encodeSetCookieHeader",
"(",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"cookies",
"=",
"CookieCollection",
"::",
"createFromHeader",
"(",
"$",
"response",
"->",
"getHeader",
"(",
"'Set-Cookie'",
")",
")",
";",
"$",
"header",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"cookies",
"as",
"$",
"cookie",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"cookie",
"->",
"getName",
"(",
")",
",",
"$",
"this",
"->",
"cookieNames",
",",
"true",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"_encrypt",
"(",
"$",
"cookie",
"->",
"getValue",
"(",
")",
",",
"$",
"this",
"->",
"cipherType",
")",
";",
"$",
"cookie",
"=",
"$",
"cookie",
"->",
"withValue",
"(",
"$",
"value",
")",
";",
"}",
"$",
"header",
"[",
"]",
"=",
"$",
"cookie",
"->",
"toHeaderValue",
"(",
")",
";",
"}",
"return",
"$",
"response",
"->",
"withHeader",
"(",
"'Set-Cookie'",
",",
"$",
"header",
")",
";",
"}"
] | Encode cookies from a response's Set-Cookie header
@param \Psr\Http\Message\ResponseInterface $response The response to encode cookies in.
@return \Psr\Http\Message\ResponseInterface Updated response with encoded cookies. | [
"Encode",
"cookies",
"from",
"a",
"response",
"s",
"Set",
"-",
"Cookie",
"header"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Middleware/EncryptedCookieMiddleware.php#L155-L168 |
211,423 | cakephp/cakephp | src/Console/ShellDispatcher.php | ShellDispatcher.alias | public static function alias($short, $original = null)
{
$short = Inflector::camelize($short);
if ($original) {
static::$_aliases[$short] = $original;
}
return isset(static::$_aliases[$short]) ? static::$_aliases[$short] : false;
} | php | public static function alias($short, $original = null)
{
$short = Inflector::camelize($short);
if ($original) {
static::$_aliases[$short] = $original;
}
return isset(static::$_aliases[$short]) ? static::$_aliases[$short] : false;
} | [
"public",
"static",
"function",
"alias",
"(",
"$",
"short",
",",
"$",
"original",
"=",
"null",
")",
"{",
"$",
"short",
"=",
"Inflector",
"::",
"camelize",
"(",
"$",
"short",
")",
";",
"if",
"(",
"$",
"original",
")",
"{",
"static",
"::",
"$",
"_aliases",
"[",
"$",
"short",
"]",
"=",
"$",
"original",
";",
"}",
"return",
"isset",
"(",
"static",
"::",
"$",
"_aliases",
"[",
"$",
"short",
"]",
")",
"?",
"static",
"::",
"$",
"_aliases",
"[",
"$",
"short",
"]",
":",
"false",
";",
"}"
] | Add an alias for a shell command.
Aliases allow you to call shells by alternate names. This is most
useful when dealing with plugin shells that you want to have shorter
names for.
If you re-use an alias the last alias set will be the one available.
### Usage
Aliasing a shell named ClassName:
```
$this->alias('alias', 'ClassName');
```
Getting the original name for a given alias:
```
$this->alias('alias');
```
@param string $short The new short name for the shell.
@param string|null $original The original full name for the shell.
@return string|false The aliased class name, or false if the alias does not exist | [
"Add",
"an",
"alias",
"for",
"a",
"shell",
"command",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ShellDispatcher.php#L97-L105 |
211,424 | cakephp/cakephp | src/Console/ShellDispatcher.php | ShellDispatcher._initEnvironment | protected function _initEnvironment()
{
if (!$this->_bootstrap()) {
$message = "Unable to load CakePHP core.\nMake sure Cake exists in " . CAKE_CORE_INCLUDE_PATH;
throw new Exception($message);
}
if (function_exists('ini_set')) {
ini_set('html_errors', '0');
ini_set('implicit_flush', '1');
ini_set('max_execution_time', '0');
}
$this->shiftArgs();
} | php | protected function _initEnvironment()
{
if (!$this->_bootstrap()) {
$message = "Unable to load CakePHP core.\nMake sure Cake exists in " . CAKE_CORE_INCLUDE_PATH;
throw new Exception($message);
}
if (function_exists('ini_set')) {
ini_set('html_errors', '0');
ini_set('implicit_flush', '1');
ini_set('max_execution_time', '0');
}
$this->shiftArgs();
} | [
"protected",
"function",
"_initEnvironment",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_bootstrap",
"(",
")",
")",
"{",
"$",
"message",
"=",
"\"Unable to load CakePHP core.\\nMake sure Cake exists in \"",
".",
"CAKE_CORE_INCLUDE_PATH",
";",
"throw",
"new",
"Exception",
"(",
"$",
"message",
")",
";",
"}",
"if",
"(",
"function_exists",
"(",
"'ini_set'",
")",
")",
"{",
"ini_set",
"(",
"'html_errors'",
",",
"'0'",
")",
";",
"ini_set",
"(",
"'implicit_flush'",
",",
"'1'",
")",
";",
"ini_set",
"(",
"'max_execution_time'",
",",
"'0'",
")",
";",
"}",
"$",
"this",
"->",
"shiftArgs",
"(",
")",
";",
"}"
] | Defines current working environment.
@return void
@throws \Cake\Core\Exception\Exception | [
"Defines",
"current",
"working",
"environment",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ShellDispatcher.php#L137-L151 |
211,425 | cakephp/cakephp | src/Console/ShellDispatcher.php | ShellDispatcher.dispatch | public function dispatch($extra = [])
{
try {
$result = $this->_dispatch($extra);
} catch (StopException $e) {
return $e->getCode();
}
if ($result === null || $result === true) {
return Shell::CODE_SUCCESS;
}
if (is_int($result)) {
return $result;
}
return Shell::CODE_ERROR;
} | php | public function dispatch($extra = [])
{
try {
$result = $this->_dispatch($extra);
} catch (StopException $e) {
return $e->getCode();
}
if ($result === null || $result === true) {
return Shell::CODE_SUCCESS;
}
if (is_int($result)) {
return $result;
}
return Shell::CODE_ERROR;
} | [
"public",
"function",
"dispatch",
"(",
"$",
"extra",
"=",
"[",
"]",
")",
"{",
"try",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"_dispatch",
"(",
"$",
"extra",
")",
";",
"}",
"catch",
"(",
"StopException",
"$",
"e",
")",
"{",
"return",
"$",
"e",
"->",
"getCode",
"(",
")",
";",
"}",
"if",
"(",
"$",
"result",
"===",
"null",
"||",
"$",
"result",
"===",
"true",
")",
"{",
"return",
"Shell",
"::",
"CODE_SUCCESS",
";",
"}",
"if",
"(",
"is_int",
"(",
"$",
"result",
")",
")",
"{",
"return",
"$",
"result",
";",
"}",
"return",
"Shell",
"::",
"CODE_ERROR",
";",
"}"
] | Dispatches a CLI request
Converts a shell command result into an exit code. Null/True
are treated as success. All other return values are an error.
@param array $extra Extra parameters that you can manually pass to the Shell
to be dispatched.
Built-in extra parameter is :
- `requested` : if used, will prevent the Shell welcome message to be displayed
@return int The cli command exit code. 0 is success. | [
"Dispatches",
"a",
"CLI",
"request"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ShellDispatcher.php#L179-L194 |
211,426 | cakephp/cakephp | src/Console/ShellDispatcher.php | ShellDispatcher.addShortPluginAliases | public function addShortPluginAliases()
{
$plugins = Plugin::loaded();
$io = new ConsoleIo();
$task = new CommandTask($io);
$io->setLoggers(false);
$list = $task->getShellList() + ['app' => []];
$fixed = array_flip($list['app']) + array_flip($list['CORE']);
$aliases = $others = [];
foreach ($plugins as $plugin) {
if (!isset($list[$plugin])) {
continue;
}
foreach ($list[$plugin] as $shell) {
$aliases += [$shell => $plugin];
if (!isset($others[$shell])) {
$others[$shell] = [$plugin];
} else {
$others[$shell] = array_merge($others[$shell], [$plugin]);
}
}
}
foreach ($aliases as $shell => $plugin) {
if (isset($fixed[$shell])) {
Log::write(
'debug',
"command '$shell' in plugin '$plugin' was not aliased, conflicts with another shell",
['shell-dispatcher']
);
continue;
}
$other = static::alias($shell);
if ($other) {
$other = $aliases[$shell];
if ($other !== $plugin) {
Log::write(
'debug',
"command '$shell' in plugin '$plugin' was not aliased, conflicts with '$other'",
['shell-dispatcher']
);
}
continue;
}
if (isset($others[$shell])) {
$conflicts = array_diff($others[$shell], [$plugin]);
if (count($conflicts) > 0) {
$conflictList = implode("', '", $conflicts);
Log::write(
'debug',
"command '$shell' in plugin '$plugin' was not aliased, conflicts with '$conflictList'",
['shell-dispatcher']
);
}
}
static::alias($shell, "$plugin.$shell");
}
return static::$_aliases;
} | php | public function addShortPluginAliases()
{
$plugins = Plugin::loaded();
$io = new ConsoleIo();
$task = new CommandTask($io);
$io->setLoggers(false);
$list = $task->getShellList() + ['app' => []];
$fixed = array_flip($list['app']) + array_flip($list['CORE']);
$aliases = $others = [];
foreach ($plugins as $plugin) {
if (!isset($list[$plugin])) {
continue;
}
foreach ($list[$plugin] as $shell) {
$aliases += [$shell => $plugin];
if (!isset($others[$shell])) {
$others[$shell] = [$plugin];
} else {
$others[$shell] = array_merge($others[$shell], [$plugin]);
}
}
}
foreach ($aliases as $shell => $plugin) {
if (isset($fixed[$shell])) {
Log::write(
'debug',
"command '$shell' in plugin '$plugin' was not aliased, conflicts with another shell",
['shell-dispatcher']
);
continue;
}
$other = static::alias($shell);
if ($other) {
$other = $aliases[$shell];
if ($other !== $plugin) {
Log::write(
'debug',
"command '$shell' in plugin '$plugin' was not aliased, conflicts with '$other'",
['shell-dispatcher']
);
}
continue;
}
if (isset($others[$shell])) {
$conflicts = array_diff($others[$shell], [$plugin]);
if (count($conflicts) > 0) {
$conflictList = implode("', '", $conflicts);
Log::write(
'debug',
"command '$shell' in plugin '$plugin' was not aliased, conflicts with '$conflictList'",
['shell-dispatcher']
);
}
}
static::alias($shell, "$plugin.$shell");
}
return static::$_aliases;
} | [
"public",
"function",
"addShortPluginAliases",
"(",
")",
"{",
"$",
"plugins",
"=",
"Plugin",
"::",
"loaded",
"(",
")",
";",
"$",
"io",
"=",
"new",
"ConsoleIo",
"(",
")",
";",
"$",
"task",
"=",
"new",
"CommandTask",
"(",
"$",
"io",
")",
";",
"$",
"io",
"->",
"setLoggers",
"(",
"false",
")",
";",
"$",
"list",
"=",
"$",
"task",
"->",
"getShellList",
"(",
")",
"+",
"[",
"'app'",
"=>",
"[",
"]",
"]",
";",
"$",
"fixed",
"=",
"array_flip",
"(",
"$",
"list",
"[",
"'app'",
"]",
")",
"+",
"array_flip",
"(",
"$",
"list",
"[",
"'CORE'",
"]",
")",
";",
"$",
"aliases",
"=",
"$",
"others",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"plugins",
"as",
"$",
"plugin",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"list",
"[",
"$",
"plugin",
"]",
")",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"list",
"[",
"$",
"plugin",
"]",
"as",
"$",
"shell",
")",
"{",
"$",
"aliases",
"+=",
"[",
"$",
"shell",
"=>",
"$",
"plugin",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"others",
"[",
"$",
"shell",
"]",
")",
")",
"{",
"$",
"others",
"[",
"$",
"shell",
"]",
"=",
"[",
"$",
"plugin",
"]",
";",
"}",
"else",
"{",
"$",
"others",
"[",
"$",
"shell",
"]",
"=",
"array_merge",
"(",
"$",
"others",
"[",
"$",
"shell",
"]",
",",
"[",
"$",
"plugin",
"]",
")",
";",
"}",
"}",
"}",
"foreach",
"(",
"$",
"aliases",
"as",
"$",
"shell",
"=>",
"$",
"plugin",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"fixed",
"[",
"$",
"shell",
"]",
")",
")",
"{",
"Log",
"::",
"write",
"(",
"'debug'",
",",
"\"command '$shell' in plugin '$plugin' was not aliased, conflicts with another shell\"",
",",
"[",
"'shell-dispatcher'",
"]",
")",
";",
"continue",
";",
"}",
"$",
"other",
"=",
"static",
"::",
"alias",
"(",
"$",
"shell",
")",
";",
"if",
"(",
"$",
"other",
")",
"{",
"$",
"other",
"=",
"$",
"aliases",
"[",
"$",
"shell",
"]",
";",
"if",
"(",
"$",
"other",
"!==",
"$",
"plugin",
")",
"{",
"Log",
"::",
"write",
"(",
"'debug'",
",",
"\"command '$shell' in plugin '$plugin' was not aliased, conflicts with '$other'\"",
",",
"[",
"'shell-dispatcher'",
"]",
")",
";",
"}",
"continue",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"others",
"[",
"$",
"shell",
"]",
")",
")",
"{",
"$",
"conflicts",
"=",
"array_diff",
"(",
"$",
"others",
"[",
"$",
"shell",
"]",
",",
"[",
"$",
"plugin",
"]",
")",
";",
"if",
"(",
"count",
"(",
"$",
"conflicts",
")",
">",
"0",
")",
"{",
"$",
"conflictList",
"=",
"implode",
"(",
"\"', '\"",
",",
"$",
"conflicts",
")",
";",
"Log",
"::",
"write",
"(",
"'debug'",
",",
"\"command '$shell' in plugin '$plugin' was not aliased, conflicts with '$conflictList'\"",
",",
"[",
"'shell-dispatcher'",
"]",
")",
";",
"}",
"}",
"static",
"::",
"alias",
"(",
"$",
"shell",
",",
"\"$plugin.$shell\"",
")",
";",
"}",
"return",
"static",
"::",
"$",
"_aliases",
";",
"}"
] | For all loaded plugins, add a short alias
This permits a plugin which implements a shell of the same name to be accessed
Using the shell name alone
@return array the resultant list of aliases | [
"For",
"all",
"loaded",
"plugins",
"add",
"a",
"short",
"alias"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ShellDispatcher.php#L241-L306 |
211,427 | cakephp/cakephp | src/Console/ShellDispatcher.php | ShellDispatcher.findShell | public function findShell($shell)
{
$className = $this->_shellExists($shell);
if (!$className) {
$shell = $this->_handleAlias($shell);
$className = $this->_shellExists($shell);
}
if (!$className) {
throw new MissingShellException([
'class' => $shell,
]);
}
return $this->_createShell($className, $shell);
} | php | public function findShell($shell)
{
$className = $this->_shellExists($shell);
if (!$className) {
$shell = $this->_handleAlias($shell);
$className = $this->_shellExists($shell);
}
if (!$className) {
throw new MissingShellException([
'class' => $shell,
]);
}
return $this->_createShell($className, $shell);
} | [
"public",
"function",
"findShell",
"(",
"$",
"shell",
")",
"{",
"$",
"className",
"=",
"$",
"this",
"->",
"_shellExists",
"(",
"$",
"shell",
")",
";",
"if",
"(",
"!",
"$",
"className",
")",
"{",
"$",
"shell",
"=",
"$",
"this",
"->",
"_handleAlias",
"(",
"$",
"shell",
")",
";",
"$",
"className",
"=",
"$",
"this",
"->",
"_shellExists",
"(",
"$",
"shell",
")",
";",
"}",
"if",
"(",
"!",
"$",
"className",
")",
"{",
"throw",
"new",
"MissingShellException",
"(",
"[",
"'class'",
"=>",
"$",
"shell",
",",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_createShell",
"(",
"$",
"className",
",",
"$",
"shell",
")",
";",
"}"
] | Get shell to use, either plugin shell or application shell
All paths in the loaded shell paths are searched, handles alias
dereferencing
@param string $shell Optionally the name of a plugin
@return \Cake\Console\Shell A shell instance.
@throws \Cake\Console\Exception\MissingShellException when errors are encountered. | [
"Get",
"shell",
"to",
"use",
"either",
"plugin",
"shell",
"or",
"application",
"shell"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ShellDispatcher.php#L318-L333 |
211,428 | cakephp/cakephp | src/Console/ShellDispatcher.php | ShellDispatcher._handleAlias | protected function _handleAlias($shell)
{
$aliased = static::alias($shell);
if ($aliased) {
$shell = $aliased;
}
$class = array_map('Cake\Utility\Inflector::camelize', explode('.', $shell));
return implode('.', $class);
} | php | protected function _handleAlias($shell)
{
$aliased = static::alias($shell);
if ($aliased) {
$shell = $aliased;
}
$class = array_map('Cake\Utility\Inflector::camelize', explode('.', $shell));
return implode('.', $class);
} | [
"protected",
"function",
"_handleAlias",
"(",
"$",
"shell",
")",
"{",
"$",
"aliased",
"=",
"static",
"::",
"alias",
"(",
"$",
"shell",
")",
";",
"if",
"(",
"$",
"aliased",
")",
"{",
"$",
"shell",
"=",
"$",
"aliased",
";",
"}",
"$",
"class",
"=",
"array_map",
"(",
"'Cake\\Utility\\Inflector::camelize'",
",",
"explode",
"(",
"'.'",
",",
"$",
"shell",
")",
")",
";",
"return",
"implode",
"(",
"'.'",
",",
"$",
"class",
")",
";",
"}"
] | If the input matches an alias, return the aliased shell name
@param string $shell Optionally the name of a plugin or alias
@return string Shell name with plugin prefix | [
"If",
"the",
"input",
"matches",
"an",
"alias",
"return",
"the",
"aliased",
"shell",
"name"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ShellDispatcher.php#L341-L351 |
211,429 | cakephp/cakephp | src/Console/ShellDispatcher.php | ShellDispatcher._createShell | protected function _createShell($className, $shortName)
{
list($plugin) = pluginSplit($shortName);
$instance = new $className();
$instance->plugin = trim($plugin, '.');
return $instance;
} | php | protected function _createShell($className, $shortName)
{
list($plugin) = pluginSplit($shortName);
$instance = new $className();
$instance->plugin = trim($plugin, '.');
return $instance;
} | [
"protected",
"function",
"_createShell",
"(",
"$",
"className",
",",
"$",
"shortName",
")",
"{",
"list",
"(",
"$",
"plugin",
")",
"=",
"pluginSplit",
"(",
"$",
"shortName",
")",
";",
"$",
"instance",
"=",
"new",
"$",
"className",
"(",
")",
";",
"$",
"instance",
"->",
"plugin",
"=",
"trim",
"(",
"$",
"plugin",
",",
"'.'",
")",
";",
"return",
"$",
"instance",
";",
"}"
] | Create the given shell name, and set the plugin property
@param string $className The class name to instantiate
@param string $shortName The plugin-prefixed shell name
@return \Cake\Console\Shell A shell instance. | [
"Create",
"the",
"given",
"shell",
"name",
"and",
"set",
"the",
"plugin",
"property"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ShellDispatcher.php#L376-L383 |
211,430 | cakephp/cakephp | src/Cache/Engine/ApcuEngine.php | ApcuEngine.clear | public function clear($check)
{
if ($check) {
return true;
}
if (class_exists('APCuIterator', false)) {
$iterator = new APCuIterator(
'/^' . preg_quote($this->_config['prefix'], '/') . '/',
APC_ITER_NONE
);
apcu_delete($iterator);
return true;
}
$cache = apcu_cache_info(); // Raises warning by itself already
foreach ($cache['cache_list'] as $key) {
if (strpos($key['info'], $this->_config['prefix']) === 0) {
apcu_delete($key['info']);
}
}
return true;
} | php | public function clear($check)
{
if ($check) {
return true;
}
if (class_exists('APCuIterator', false)) {
$iterator = new APCuIterator(
'/^' . preg_quote($this->_config['prefix'], '/') . '/',
APC_ITER_NONE
);
apcu_delete($iterator);
return true;
}
$cache = apcu_cache_info(); // Raises warning by itself already
foreach ($cache['cache_list'] as $key) {
if (strpos($key['info'], $this->_config['prefix']) === 0) {
apcu_delete($key['info']);
}
}
return true;
} | [
"public",
"function",
"clear",
"(",
"$",
"check",
")",
"{",
"if",
"(",
"$",
"check",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"class_exists",
"(",
"'APCuIterator'",
",",
"false",
")",
")",
"{",
"$",
"iterator",
"=",
"new",
"APCuIterator",
"(",
"'/^'",
".",
"preg_quote",
"(",
"$",
"this",
"->",
"_config",
"[",
"'prefix'",
"]",
",",
"'/'",
")",
".",
"'/'",
",",
"APC_ITER_NONE",
")",
";",
"apcu_delete",
"(",
"$",
"iterator",
")",
";",
"return",
"true",
";",
"}",
"$",
"cache",
"=",
"apcu_cache_info",
"(",
")",
";",
"// Raises warning by itself already",
"foreach",
"(",
"$",
"cache",
"[",
"'cache_list'",
"]",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"key",
"[",
"'info'",
"]",
",",
"$",
"this",
"->",
"_config",
"[",
"'prefix'",
"]",
")",
"===",
"0",
")",
"{",
"apcu_delete",
"(",
"$",
"key",
"[",
"'info'",
"]",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Delete all keys from the cache. This will clear every cache config using APC.
@param bool $check If true, nothing will be cleared, as entries are removed
from APC as they expired. This flag is really only used by FileEngine.
@return bool True Returns true.
@link https://secure.php.net/manual/en/function.apcu-cache-info.php
@link https://secure.php.net/manual/en/function.apcu-delete.php | [
"Delete",
"all",
"keys",
"from",
"the",
"cache",
".",
"This",
"will",
"clear",
"every",
"cache",
"config",
"using",
"APC",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/Engine/ApcuEngine.php#L135-L158 |
211,431 | cakephp/cakephp | src/Database/TypeMap.php | TypeMap.types | public function types(array $types = null)
{
deprecationWarning(
'TypeMap::types() is deprecated. ' .
'Use TypeMap::setTypes()/getTypes() instead.'
);
if ($types !== null) {
return $this->setTypes($types);
}
return $this->getTypes();
} | php | public function types(array $types = null)
{
deprecationWarning(
'TypeMap::types() is deprecated. ' .
'Use TypeMap::setTypes()/getTypes() instead.'
);
if ($types !== null) {
return $this->setTypes($types);
}
return $this->getTypes();
} | [
"public",
"function",
"types",
"(",
"array",
"$",
"types",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"'TypeMap::types() is deprecated. '",
".",
"'Use TypeMap::setTypes()/getTypes() instead.'",
")",
";",
"if",
"(",
"$",
"types",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"setTypes",
"(",
"$",
"types",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getTypes",
"(",
")",
";",
"}"
] | Sets a map of fields and their associated types for single-use.
If called with no arguments it will return the currently configured types.
### Example
```
$query->types(['created' => 'time']);
```
This method will replace all the existing type maps with the ones provided.
@deprecated 3.4.0 Use setTypes()/getTypes() instead.
@param array|null $types associative array where keys are field names and values
are the correspondent type.
@return $this|array | [
"Sets",
"a",
"map",
"of",
"fields",
"and",
"their",
"associated",
"types",
"for",
"single",
"-",
"use",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/TypeMap.php#L185-L196 |
211,432 | cakephp/cakephp | src/Database/TypeMap.php | TypeMap.type | public function type($column)
{
if (isset($this->_types[$column])) {
return $this->_types[$column];
}
if (isset($this->_defaults[$column])) {
return $this->_defaults[$column];
}
return null;
} | php | public function type($column)
{
if (isset($this->_types[$column])) {
return $this->_types[$column];
}
if (isset($this->_defaults[$column])) {
return $this->_defaults[$column];
}
return null;
} | [
"public",
"function",
"type",
"(",
"$",
"column",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_types",
"[",
"$",
"column",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_types",
"[",
"$",
"column",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_defaults",
"[",
"$",
"column",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_defaults",
"[",
"$",
"column",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Returns the type of the given column. If there is no single use type is configured,
the column type will be looked for inside the default mapping. If neither exist,
null will be returned.
@param string $column The type for a given column
@return null|string | [
"Returns",
"the",
"type",
"of",
"the",
"given",
"column",
".",
"If",
"there",
"is",
"no",
"single",
"use",
"type",
"is",
"configured",
"the",
"column",
"type",
"will",
"be",
"looked",
"for",
"inside",
"the",
"default",
"mapping",
".",
"If",
"neither",
"exist",
"null",
"will",
"be",
"returned",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/TypeMap.php#L206-L216 |
211,433 | cakephp/cakephp | src/ORM/Association/DependentDeleteHelper.php | DependentDeleteHelper.cascadeDelete | public function cascadeDelete(Association $association, EntityInterface $entity, array $options = [])
{
if (!$association->getDependent()) {
return true;
}
$table = $association->getTarget();
$foreignKey = array_map([$association, 'aliasField'], (array)$association->getForeignKey());
$bindingKey = (array)$association->getBindingKey();
$conditions = array_combine($foreignKey, $entity->extract($bindingKey));
if ($association->getCascadeCallbacks()) {
foreach ($association->find()->where($conditions)->all()->toList() as $related) {
$table->delete($related, $options);
}
return true;
}
$conditions = array_merge($conditions, $association->getConditions());
return (bool)$table->deleteAll($conditions);
} | php | public function cascadeDelete(Association $association, EntityInterface $entity, array $options = [])
{
if (!$association->getDependent()) {
return true;
}
$table = $association->getTarget();
$foreignKey = array_map([$association, 'aliasField'], (array)$association->getForeignKey());
$bindingKey = (array)$association->getBindingKey();
$conditions = array_combine($foreignKey, $entity->extract($bindingKey));
if ($association->getCascadeCallbacks()) {
foreach ($association->find()->where($conditions)->all()->toList() as $related) {
$table->delete($related, $options);
}
return true;
}
$conditions = array_merge($conditions, $association->getConditions());
return (bool)$table->deleteAll($conditions);
} | [
"public",
"function",
"cascadeDelete",
"(",
"Association",
"$",
"association",
",",
"EntityInterface",
"$",
"entity",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"association",
"->",
"getDependent",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"table",
"=",
"$",
"association",
"->",
"getTarget",
"(",
")",
";",
"$",
"foreignKey",
"=",
"array_map",
"(",
"[",
"$",
"association",
",",
"'aliasField'",
"]",
",",
"(",
"array",
")",
"$",
"association",
"->",
"getForeignKey",
"(",
")",
")",
";",
"$",
"bindingKey",
"=",
"(",
"array",
")",
"$",
"association",
"->",
"getBindingKey",
"(",
")",
";",
"$",
"conditions",
"=",
"array_combine",
"(",
"$",
"foreignKey",
",",
"$",
"entity",
"->",
"extract",
"(",
"$",
"bindingKey",
")",
")",
";",
"if",
"(",
"$",
"association",
"->",
"getCascadeCallbacks",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"association",
"->",
"find",
"(",
")",
"->",
"where",
"(",
"$",
"conditions",
")",
"->",
"all",
"(",
")",
"->",
"toList",
"(",
")",
"as",
"$",
"related",
")",
"{",
"$",
"table",
"->",
"delete",
"(",
"$",
"related",
",",
"$",
"options",
")",
";",
"}",
"return",
"true",
";",
"}",
"$",
"conditions",
"=",
"array_merge",
"(",
"$",
"conditions",
",",
"$",
"association",
"->",
"getConditions",
"(",
")",
")",
";",
"return",
"(",
"bool",
")",
"$",
"table",
"->",
"deleteAll",
"(",
"$",
"conditions",
")",
";",
"}"
] | Cascade a delete to remove dependent records.
This method does nothing if the association is not dependent.
@param \Cake\ORM\Association $association The association callbacks are being cascaded on.
@param \Cake\Datasource\EntityInterface $entity The entity that started the cascaded delete.
@param array $options The options for the original delete.
@return bool Success. | [
"Cascade",
"a",
"delete",
"to",
"remove",
"dependent",
"records",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/DependentDeleteHelper.php#L38-L58 |
211,434 | cakephp/cakephp | src/ORM/Association/Loader/SelectLoader.php | SelectLoader._assertFieldsPresent | protected function _assertFieldsPresent($fetchQuery, $key)
{
$select = $fetchQuery->aliasFields($fetchQuery->clause('select'));
if (empty($select)) {
return;
}
$missingKey = function ($fieldList, $key) {
foreach ($key as $keyField) {
if (!in_array($keyField, $fieldList, true)) {
return true;
}
}
return false;
};
$missingFields = $missingKey($select, $key);
if ($missingFields) {
$driver = $fetchQuery->getConnection()->getDriver();
$quoted = array_map([$driver, 'quoteIdentifier'], $key);
$missingFields = $missingKey($select, $quoted);
}
if ($missingFields) {
throw new InvalidArgumentException(
sprintf(
'You are required to select the "%s" field(s)',
implode(', ', (array)$key)
)
);
}
} | php | protected function _assertFieldsPresent($fetchQuery, $key)
{
$select = $fetchQuery->aliasFields($fetchQuery->clause('select'));
if (empty($select)) {
return;
}
$missingKey = function ($fieldList, $key) {
foreach ($key as $keyField) {
if (!in_array($keyField, $fieldList, true)) {
return true;
}
}
return false;
};
$missingFields = $missingKey($select, $key);
if ($missingFields) {
$driver = $fetchQuery->getConnection()->getDriver();
$quoted = array_map([$driver, 'quoteIdentifier'], $key);
$missingFields = $missingKey($select, $quoted);
}
if ($missingFields) {
throw new InvalidArgumentException(
sprintf(
'You are required to select the "%s" field(s)',
implode(', ', (array)$key)
)
);
}
} | [
"protected",
"function",
"_assertFieldsPresent",
"(",
"$",
"fetchQuery",
",",
"$",
"key",
")",
"{",
"$",
"select",
"=",
"$",
"fetchQuery",
"->",
"aliasFields",
"(",
"$",
"fetchQuery",
"->",
"clause",
"(",
"'select'",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"select",
")",
")",
"{",
"return",
";",
"}",
"$",
"missingKey",
"=",
"function",
"(",
"$",
"fieldList",
",",
"$",
"key",
")",
"{",
"foreach",
"(",
"$",
"key",
"as",
"$",
"keyField",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"keyField",
",",
"$",
"fieldList",
",",
"true",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}",
";",
"$",
"missingFields",
"=",
"$",
"missingKey",
"(",
"$",
"select",
",",
"$",
"key",
")",
";",
"if",
"(",
"$",
"missingFields",
")",
"{",
"$",
"driver",
"=",
"$",
"fetchQuery",
"->",
"getConnection",
"(",
")",
"->",
"getDriver",
"(",
")",
";",
"$",
"quoted",
"=",
"array_map",
"(",
"[",
"$",
"driver",
",",
"'quoteIdentifier'",
"]",
",",
"$",
"key",
")",
";",
"$",
"missingFields",
"=",
"$",
"missingKey",
"(",
"$",
"select",
",",
"$",
"quoted",
")",
";",
"}",
"if",
"(",
"$",
"missingFields",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'You are required to select the \"%s\" field(s)'",
",",
"implode",
"(",
"', '",
",",
"(",
"array",
")",
"$",
"key",
")",
")",
")",
";",
"}",
"}"
] | Checks that the fetching query either has auto fields on or
has the foreignKey fields selected.
If the required fields are missing, throws an exception.
@param \Cake\ORM\Query $fetchQuery The association fetching query
@param array $key The foreign key fields to check
@return void
@throws \InvalidArgumentException | [
"Checks",
"that",
"the",
"fetching",
"query",
"either",
"has",
"auto",
"fields",
"on",
"or",
"has",
"the",
"foreignKey",
"fields",
"selected",
".",
"If",
"the",
"required",
"fields",
"are",
"missing",
"throws",
"an",
"exception",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/Loader/SelectLoader.php#L240-L271 |
211,435 | cakephp/cakephp | src/ORM/Association/Loader/SelectLoader.php | SelectLoader._addFilteringJoin | protected function _addFilteringJoin($query, $key, $subquery)
{
$filter = [];
$aliasedTable = $this->sourceAlias;
foreach ($subquery->clause('select') as $aliasedField => $field) {
if (is_int($aliasedField)) {
$filter[] = new IdentifierExpression($field);
} else {
$filter[$aliasedField] = $field;
}
}
$subquery->select($filter, true);
$conditions = null;
if (is_array($key)) {
$conditions = $this->_createTupleCondition($query, $key, $filter, '=');
} else {
$filter = current($filter);
}
$conditions = $conditions ?: $query->newExpr([$key => $filter]);
return $query->innerJoin(
[$aliasedTable => $subquery],
$conditions
);
} | php | protected function _addFilteringJoin($query, $key, $subquery)
{
$filter = [];
$aliasedTable = $this->sourceAlias;
foreach ($subquery->clause('select') as $aliasedField => $field) {
if (is_int($aliasedField)) {
$filter[] = new IdentifierExpression($field);
} else {
$filter[$aliasedField] = $field;
}
}
$subquery->select($filter, true);
$conditions = null;
if (is_array($key)) {
$conditions = $this->_createTupleCondition($query, $key, $filter, '=');
} else {
$filter = current($filter);
}
$conditions = $conditions ?: $query->newExpr([$key => $filter]);
return $query->innerJoin(
[$aliasedTable => $subquery],
$conditions
);
} | [
"protected",
"function",
"_addFilteringJoin",
"(",
"$",
"query",
",",
"$",
"key",
",",
"$",
"subquery",
")",
"{",
"$",
"filter",
"=",
"[",
"]",
";",
"$",
"aliasedTable",
"=",
"$",
"this",
"->",
"sourceAlias",
";",
"foreach",
"(",
"$",
"subquery",
"->",
"clause",
"(",
"'select'",
")",
"as",
"$",
"aliasedField",
"=>",
"$",
"field",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"aliasedField",
")",
")",
"{",
"$",
"filter",
"[",
"]",
"=",
"new",
"IdentifierExpression",
"(",
"$",
"field",
")",
";",
"}",
"else",
"{",
"$",
"filter",
"[",
"$",
"aliasedField",
"]",
"=",
"$",
"field",
";",
"}",
"}",
"$",
"subquery",
"->",
"select",
"(",
"$",
"filter",
",",
"true",
")",
";",
"$",
"conditions",
"=",
"null",
";",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"$",
"conditions",
"=",
"$",
"this",
"->",
"_createTupleCondition",
"(",
"$",
"query",
",",
"$",
"key",
",",
"$",
"filter",
",",
"'='",
")",
";",
"}",
"else",
"{",
"$",
"filter",
"=",
"current",
"(",
"$",
"filter",
")",
";",
"}",
"$",
"conditions",
"=",
"$",
"conditions",
"?",
":",
"$",
"query",
"->",
"newExpr",
"(",
"[",
"$",
"key",
"=>",
"$",
"filter",
"]",
")",
";",
"return",
"$",
"query",
"->",
"innerJoin",
"(",
"[",
"$",
"aliasedTable",
"=>",
"$",
"subquery",
"]",
",",
"$",
"conditions",
")",
";",
"}"
] | Appends any conditions required to load the relevant set of records in the
target table query given a filter key and some filtering values when the
filtering needs to be done using a subquery.
@param \Cake\ORM\Query $query Target table's query
@param string|array $key the fields that should be used for filtering
@param \Cake\ORM\Query $subquery The Subquery to use for filtering
@return \Cake\ORM\Query | [
"Appends",
"any",
"conditions",
"required",
"to",
"load",
"the",
"relevant",
"set",
"of",
"records",
"in",
"the",
"target",
"table",
"query",
"given",
"a",
"filter",
"key",
"and",
"some",
"filtering",
"values",
"when",
"the",
"filtering",
"needs",
"to",
"be",
"done",
"using",
"a",
"subquery",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/Loader/SelectLoader.php#L283-L310 |
211,436 | cakephp/cakephp | src/ORM/Association/Loader/SelectLoader.php | SelectLoader._addFilteringCondition | protected function _addFilteringCondition($query, $key, $filter)
{
if (is_array($key)) {
$conditions = $this->_createTupleCondition($query, $key, $filter, 'IN');
}
$conditions = isset($conditions) ? $conditions : [$key . ' IN' => $filter];
return $query->andWhere($conditions);
} | php | protected function _addFilteringCondition($query, $key, $filter)
{
if (is_array($key)) {
$conditions = $this->_createTupleCondition($query, $key, $filter, 'IN');
}
$conditions = isset($conditions) ? $conditions : [$key . ' IN' => $filter];
return $query->andWhere($conditions);
} | [
"protected",
"function",
"_addFilteringCondition",
"(",
"$",
"query",
",",
"$",
"key",
",",
"$",
"filter",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"$",
"conditions",
"=",
"$",
"this",
"->",
"_createTupleCondition",
"(",
"$",
"query",
",",
"$",
"key",
",",
"$",
"filter",
",",
"'IN'",
")",
";",
"}",
"$",
"conditions",
"=",
"isset",
"(",
"$",
"conditions",
")",
"?",
"$",
"conditions",
":",
"[",
"$",
"key",
".",
"' IN'",
"=>",
"$",
"filter",
"]",
";",
"return",
"$",
"query",
"->",
"andWhere",
"(",
"$",
"conditions",
")",
";",
"}"
] | Appends any conditions required to load the relevant set of records in the
target table query given a filter key and some filtering values.
@param \Cake\ORM\Query $query Target table's query
@param string|array $key The fields that should be used for filtering
@param mixed $filter The value that should be used to match for $key
@return \Cake\ORM\Query | [
"Appends",
"any",
"conditions",
"required",
"to",
"load",
"the",
"relevant",
"set",
"of",
"records",
"in",
"the",
"target",
"table",
"query",
"given",
"a",
"filter",
"key",
"and",
"some",
"filtering",
"values",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/Loader/SelectLoader.php#L321-L330 |
211,437 | cakephp/cakephp | src/ORM/Association/Loader/SelectLoader.php | SelectLoader._buildSubquery | protected function _buildSubquery($query)
{
$filterQuery = clone $query;
$filterQuery->disableAutoFields();
$filterQuery->mapReduce(null, null, true);
$filterQuery->formatResults(null, true);
$filterQuery->contain([], true);
$filterQuery->setValueBinder(new ValueBinder());
if (!$filterQuery->clause('limit')) {
$filterQuery->limit(null);
$filterQuery->order([], true);
$filterQuery->offset(null);
}
$fields = $this->_subqueryFields($query);
$filterQuery->select($fields['select'], true)->group($fields['group']);
return $filterQuery;
} | php | protected function _buildSubquery($query)
{
$filterQuery = clone $query;
$filterQuery->disableAutoFields();
$filterQuery->mapReduce(null, null, true);
$filterQuery->formatResults(null, true);
$filterQuery->contain([], true);
$filterQuery->setValueBinder(new ValueBinder());
if (!$filterQuery->clause('limit')) {
$filterQuery->limit(null);
$filterQuery->order([], true);
$filterQuery->offset(null);
}
$fields = $this->_subqueryFields($query);
$filterQuery->select($fields['select'], true)->group($fields['group']);
return $filterQuery;
} | [
"protected",
"function",
"_buildSubquery",
"(",
"$",
"query",
")",
"{",
"$",
"filterQuery",
"=",
"clone",
"$",
"query",
";",
"$",
"filterQuery",
"->",
"disableAutoFields",
"(",
")",
";",
"$",
"filterQuery",
"->",
"mapReduce",
"(",
"null",
",",
"null",
",",
"true",
")",
";",
"$",
"filterQuery",
"->",
"formatResults",
"(",
"null",
",",
"true",
")",
";",
"$",
"filterQuery",
"->",
"contain",
"(",
"[",
"]",
",",
"true",
")",
";",
"$",
"filterQuery",
"->",
"setValueBinder",
"(",
"new",
"ValueBinder",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"filterQuery",
"->",
"clause",
"(",
"'limit'",
")",
")",
"{",
"$",
"filterQuery",
"->",
"limit",
"(",
"null",
")",
";",
"$",
"filterQuery",
"->",
"order",
"(",
"[",
"]",
",",
"true",
")",
";",
"$",
"filterQuery",
"->",
"offset",
"(",
"null",
")",
";",
"}",
"$",
"fields",
"=",
"$",
"this",
"->",
"_subqueryFields",
"(",
"$",
"query",
")",
";",
"$",
"filterQuery",
"->",
"select",
"(",
"$",
"fields",
"[",
"'select'",
"]",
",",
"true",
")",
"->",
"group",
"(",
"$",
"fields",
"[",
"'group'",
"]",
")",
";",
"return",
"$",
"filterQuery",
";",
"}"
] | Builds a query to be used as a condition for filtering records in the
target table, it is constructed by cloning the original query that was used
to load records in the source table.
@param \Cake\ORM\Query $query the original query used to load source records
@return \Cake\ORM\Query | [
"Builds",
"a",
"query",
"to",
"be",
"used",
"as",
"a",
"condition",
"for",
"filtering",
"records",
"in",
"the",
"target",
"table",
"it",
"is",
"constructed",
"by",
"cloning",
"the",
"original",
"query",
"that",
"was",
"used",
"to",
"load",
"records",
"in",
"the",
"source",
"table",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/Loader/SelectLoader.php#L396-L415 |
211,438 | cakephp/cakephp | src/ORM/Association/Loader/SelectLoader.php | SelectLoader._subqueryFields | protected function _subqueryFields($query)
{
$keys = (array)$this->bindingKey;
if ($this->associationType === Association::MANY_TO_ONE) {
$keys = (array)$this->foreignKey;
}
$fields = $query->aliasFields($keys, $this->sourceAlias);
$group = $fields = array_values($fields);
$order = $query->clause('order');
if ($order) {
$columns = $query->clause('select');
$order->iterateParts(function ($direction, $field) use (&$fields, $columns) {
if (isset($columns[$field])) {
$fields[$field] = $columns[$field];
}
});
}
return ['select' => $fields, 'group' => $group];
} | php | protected function _subqueryFields($query)
{
$keys = (array)$this->bindingKey;
if ($this->associationType === Association::MANY_TO_ONE) {
$keys = (array)$this->foreignKey;
}
$fields = $query->aliasFields($keys, $this->sourceAlias);
$group = $fields = array_values($fields);
$order = $query->clause('order');
if ($order) {
$columns = $query->clause('select');
$order->iterateParts(function ($direction, $field) use (&$fields, $columns) {
if (isset($columns[$field])) {
$fields[$field] = $columns[$field];
}
});
}
return ['select' => $fields, 'group' => $group];
} | [
"protected",
"function",
"_subqueryFields",
"(",
"$",
"query",
")",
"{",
"$",
"keys",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"bindingKey",
";",
"if",
"(",
"$",
"this",
"->",
"associationType",
"===",
"Association",
"::",
"MANY_TO_ONE",
")",
"{",
"$",
"keys",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"foreignKey",
";",
"}",
"$",
"fields",
"=",
"$",
"query",
"->",
"aliasFields",
"(",
"$",
"keys",
",",
"$",
"this",
"->",
"sourceAlias",
")",
";",
"$",
"group",
"=",
"$",
"fields",
"=",
"array_values",
"(",
"$",
"fields",
")",
";",
"$",
"order",
"=",
"$",
"query",
"->",
"clause",
"(",
"'order'",
")",
";",
"if",
"(",
"$",
"order",
")",
"{",
"$",
"columns",
"=",
"$",
"query",
"->",
"clause",
"(",
"'select'",
")",
";",
"$",
"order",
"->",
"iterateParts",
"(",
"function",
"(",
"$",
"direction",
",",
"$",
"field",
")",
"use",
"(",
"&",
"$",
"fields",
",",
"$",
"columns",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"columns",
"[",
"$",
"field",
"]",
")",
")",
"{",
"$",
"fields",
"[",
"$",
"field",
"]",
"=",
"$",
"columns",
"[",
"$",
"field",
"]",
";",
"}",
"}",
")",
";",
"}",
"return",
"[",
"'select'",
"=>",
"$",
"fields",
",",
"'group'",
"=>",
"$",
"group",
"]",
";",
"}"
] | Calculate the fields that need to participate in a subquery.
Normally this includes the binding key columns. If there is a an ORDER BY,
those columns are also included as the fields may be calculated or constant values,
that need to be present to ensure the correct association data is loaded.
@param \Cake\ORM\Query $query The query to get fields from.
@return array The list of fields for the subquery. | [
"Calculate",
"the",
"fields",
"that",
"need",
"to",
"participate",
"in",
"a",
"subquery",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/Loader/SelectLoader.php#L427-L449 |
211,439 | cakephp/cakephp | src/ORM/Association/Loader/SelectLoader.php | SelectLoader._resultInjector | protected function _resultInjector($fetchQuery, $resultMap, $options)
{
$keys = $this->associationType === Association::MANY_TO_ONE ?
$this->foreignKey :
$this->bindingKey;
$sourceKeys = [];
foreach ((array)$keys as $key) {
$f = $fetchQuery->aliasField($key, $this->sourceAlias);
$sourceKeys[] = key($f);
}
$nestKey = $options['nestKey'];
if (count($sourceKeys) > 1) {
return $this->_multiKeysInjector($resultMap, $sourceKeys, $nestKey);
}
$sourceKey = $sourceKeys[0];
return function ($row) use ($resultMap, $sourceKey, $nestKey) {
if (isset($row[$sourceKey], $resultMap[$row[$sourceKey]])) {
$row[$nestKey] = $resultMap[$row[$sourceKey]];
}
return $row;
};
} | php | protected function _resultInjector($fetchQuery, $resultMap, $options)
{
$keys = $this->associationType === Association::MANY_TO_ONE ?
$this->foreignKey :
$this->bindingKey;
$sourceKeys = [];
foreach ((array)$keys as $key) {
$f = $fetchQuery->aliasField($key, $this->sourceAlias);
$sourceKeys[] = key($f);
}
$nestKey = $options['nestKey'];
if (count($sourceKeys) > 1) {
return $this->_multiKeysInjector($resultMap, $sourceKeys, $nestKey);
}
$sourceKey = $sourceKeys[0];
return function ($row) use ($resultMap, $sourceKey, $nestKey) {
if (isset($row[$sourceKey], $resultMap[$row[$sourceKey]])) {
$row[$nestKey] = $resultMap[$row[$sourceKey]];
}
return $row;
};
} | [
"protected",
"function",
"_resultInjector",
"(",
"$",
"fetchQuery",
",",
"$",
"resultMap",
",",
"$",
"options",
")",
"{",
"$",
"keys",
"=",
"$",
"this",
"->",
"associationType",
"===",
"Association",
"::",
"MANY_TO_ONE",
"?",
"$",
"this",
"->",
"foreignKey",
":",
"$",
"this",
"->",
"bindingKey",
";",
"$",
"sourceKeys",
"=",
"[",
"]",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"f",
"=",
"$",
"fetchQuery",
"->",
"aliasField",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"sourceAlias",
")",
";",
"$",
"sourceKeys",
"[",
"]",
"=",
"key",
"(",
"$",
"f",
")",
";",
"}",
"$",
"nestKey",
"=",
"$",
"options",
"[",
"'nestKey'",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"sourceKeys",
")",
">",
"1",
")",
"{",
"return",
"$",
"this",
"->",
"_multiKeysInjector",
"(",
"$",
"resultMap",
",",
"$",
"sourceKeys",
",",
"$",
"nestKey",
")",
";",
"}",
"$",
"sourceKey",
"=",
"$",
"sourceKeys",
"[",
"0",
"]",
";",
"return",
"function",
"(",
"$",
"row",
")",
"use",
"(",
"$",
"resultMap",
",",
"$",
"sourceKey",
",",
"$",
"nestKey",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"$",
"sourceKey",
"]",
",",
"$",
"resultMap",
"[",
"$",
"row",
"[",
"$",
"sourceKey",
"]",
"]",
")",
")",
"{",
"$",
"row",
"[",
"$",
"nestKey",
"]",
"=",
"$",
"resultMap",
"[",
"$",
"row",
"[",
"$",
"sourceKey",
"]",
"]",
";",
"}",
"return",
"$",
"row",
";",
"}",
";",
"}"
] | Returns a callable to be used for each row in a query result set
for injecting the eager loaded rows
@param \Cake\ORM\Query $fetchQuery the Query used to fetch results
@param array $resultMap an array with the foreignKey as keys and
the corresponding target table results as value.
@param array $options The options passed to the eagerLoader method
@return \Closure | [
"Returns",
"a",
"callable",
"to",
"be",
"used",
"for",
"each",
"row",
"in",
"a",
"query",
"result",
"set",
"for",
"injecting",
"the",
"eager",
"loaded",
"rows"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/Loader/SelectLoader.php#L493-L519 |
211,440 | cakephp/cakephp | src/ORM/Association/Loader/SelectLoader.php | SelectLoader._multiKeysInjector | protected function _multiKeysInjector($resultMap, $sourceKeys, $nestKey)
{
return function ($row) use ($resultMap, $sourceKeys, $nestKey) {
$values = [];
foreach ($sourceKeys as $key) {
$values[] = $row[$key];
}
$key = implode(';', $values);
if (isset($resultMap[$key])) {
$row[$nestKey] = $resultMap[$key];
}
return $row;
};
} | php | protected function _multiKeysInjector($resultMap, $sourceKeys, $nestKey)
{
return function ($row) use ($resultMap, $sourceKeys, $nestKey) {
$values = [];
foreach ($sourceKeys as $key) {
$values[] = $row[$key];
}
$key = implode(';', $values);
if (isset($resultMap[$key])) {
$row[$nestKey] = $resultMap[$key];
}
return $row;
};
} | [
"protected",
"function",
"_multiKeysInjector",
"(",
"$",
"resultMap",
",",
"$",
"sourceKeys",
",",
"$",
"nestKey",
")",
"{",
"return",
"function",
"(",
"$",
"row",
")",
"use",
"(",
"$",
"resultMap",
",",
"$",
"sourceKeys",
",",
"$",
"nestKey",
")",
"{",
"$",
"values",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"sourceKeys",
"as",
"$",
"key",
")",
"{",
"$",
"values",
"[",
"]",
"=",
"$",
"row",
"[",
"$",
"key",
"]",
";",
"}",
"$",
"key",
"=",
"implode",
"(",
"';'",
",",
"$",
"values",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"resultMap",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"row",
"[",
"$",
"nestKey",
"]",
"=",
"$",
"resultMap",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"row",
";",
"}",
";",
"}"
] | Returns a callable to be used for each row in a query result set
for injecting the eager loaded rows when the matching needs to
be done with multiple foreign keys
@param array $resultMap A keyed arrays containing the target table
@param array $sourceKeys An array with aliased keys to match
@param string $nestKey The key under which results should be nested
@return \Closure | [
"Returns",
"a",
"callable",
"to",
"be",
"used",
"for",
"each",
"row",
"in",
"a",
"query",
"result",
"set",
"for",
"injecting",
"the",
"eager",
"loaded",
"rows",
"when",
"the",
"matching",
"needs",
"to",
"be",
"done",
"with",
"multiple",
"foreign",
"keys"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/Loader/SelectLoader.php#L531-L546 |
211,441 | cakephp/cakephp | src/Http/Session.php | Session._defaultConfig | protected static function _defaultConfig($name)
{
$defaults = [
'php' => [
'cookie' => 'CAKEPHP',
'ini' => [
'session.use_trans_sid' => 0,
]
],
'cake' => [
'cookie' => 'CAKEPHP',
'ini' => [
'session.use_trans_sid' => 0,
'session.serialize_handler' => 'php',
'session.use_cookies' => 1,
'session.save_path' => TMP . 'sessions',
'session.save_handler' => 'files'
]
],
'cache' => [
'cookie' => 'CAKEPHP',
'ini' => [
'session.use_trans_sid' => 0,
'session.use_cookies' => 1,
'session.save_handler' => 'user',
],
'handler' => [
'engine' => 'CacheSession',
'config' => 'default'
]
],
'database' => [
'cookie' => 'CAKEPHP',
'ini' => [
'session.use_trans_sid' => 0,
'session.use_cookies' => 1,
'session.save_handler' => 'user',
'session.serialize_handler' => 'php',
],
'handler' => [
'engine' => 'DatabaseSession'
]
]
];
if (isset($defaults[$name])) {
return $defaults[$name];
}
return false;
} | php | protected static function _defaultConfig($name)
{
$defaults = [
'php' => [
'cookie' => 'CAKEPHP',
'ini' => [
'session.use_trans_sid' => 0,
]
],
'cake' => [
'cookie' => 'CAKEPHP',
'ini' => [
'session.use_trans_sid' => 0,
'session.serialize_handler' => 'php',
'session.use_cookies' => 1,
'session.save_path' => TMP . 'sessions',
'session.save_handler' => 'files'
]
],
'cache' => [
'cookie' => 'CAKEPHP',
'ini' => [
'session.use_trans_sid' => 0,
'session.use_cookies' => 1,
'session.save_handler' => 'user',
],
'handler' => [
'engine' => 'CacheSession',
'config' => 'default'
]
],
'database' => [
'cookie' => 'CAKEPHP',
'ini' => [
'session.use_trans_sid' => 0,
'session.use_cookies' => 1,
'session.save_handler' => 'user',
'session.serialize_handler' => 'php',
],
'handler' => [
'engine' => 'DatabaseSession'
]
]
];
if (isset($defaults[$name])) {
return $defaults[$name];
}
return false;
} | [
"protected",
"static",
"function",
"_defaultConfig",
"(",
"$",
"name",
")",
"{",
"$",
"defaults",
"=",
"[",
"'php'",
"=>",
"[",
"'cookie'",
"=>",
"'CAKEPHP'",
",",
"'ini'",
"=>",
"[",
"'session.use_trans_sid'",
"=>",
"0",
",",
"]",
"]",
",",
"'cake'",
"=>",
"[",
"'cookie'",
"=>",
"'CAKEPHP'",
",",
"'ini'",
"=>",
"[",
"'session.use_trans_sid'",
"=>",
"0",
",",
"'session.serialize_handler'",
"=>",
"'php'",
",",
"'session.use_cookies'",
"=>",
"1",
",",
"'session.save_path'",
"=>",
"TMP",
".",
"'sessions'",
",",
"'session.save_handler'",
"=>",
"'files'",
"]",
"]",
",",
"'cache'",
"=>",
"[",
"'cookie'",
"=>",
"'CAKEPHP'",
",",
"'ini'",
"=>",
"[",
"'session.use_trans_sid'",
"=>",
"0",
",",
"'session.use_cookies'",
"=>",
"1",
",",
"'session.save_handler'",
"=>",
"'user'",
",",
"]",
",",
"'handler'",
"=>",
"[",
"'engine'",
"=>",
"'CacheSession'",
",",
"'config'",
"=>",
"'default'",
"]",
"]",
",",
"'database'",
"=>",
"[",
"'cookie'",
"=>",
"'CAKEPHP'",
",",
"'ini'",
"=>",
"[",
"'session.use_trans_sid'",
"=>",
"0",
",",
"'session.use_cookies'",
"=>",
"1",
",",
"'session.save_handler'",
"=>",
"'user'",
",",
"'session.serialize_handler'",
"=>",
"'php'",
",",
"]",
",",
"'handler'",
"=>",
"[",
"'engine'",
"=>",
"'DatabaseSession'",
"]",
"]",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"defaults",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"defaults",
"[",
"$",
"name",
"]",
";",
"}",
"return",
"false",
";",
"}"
] | Get one of the prebaked default session configurations.
@param string $name Config name.
@return bool|array | [
"Get",
"one",
"of",
"the",
"prebaked",
"default",
"session",
"configurations",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Session.php#L138-L188 |
211,442 | cakephp/cakephp | src/Http/Session.php | Session.engine | public function engine($class = null, array $options = [])
{
if ($class === null) {
return $this->_engine;
}
if ($class instanceof SessionHandlerInterface) {
return $this->setEngine($class);
}
$className = App::className($class, 'Http/Session');
if (!$className) {
$className = App::className($class, 'Network/Session');
if ($className) {
deprecationWarning('Session adapters should be moved to the Http/Session namespace.');
}
}
if (!$className) {
throw new InvalidArgumentException(
sprintf('The class "%s" does not exist and cannot be used as a session engine', $class)
);
}
$handler = new $className($options);
if (!($handler instanceof SessionHandlerInterface)) {
throw new InvalidArgumentException(
'The chosen SessionHandler does not implement SessionHandlerInterface, it cannot be used as an engine.'
);
}
return $this->setEngine($handler);
} | php | public function engine($class = null, array $options = [])
{
if ($class === null) {
return $this->_engine;
}
if ($class instanceof SessionHandlerInterface) {
return $this->setEngine($class);
}
$className = App::className($class, 'Http/Session');
if (!$className) {
$className = App::className($class, 'Network/Session');
if ($className) {
deprecationWarning('Session adapters should be moved to the Http/Session namespace.');
}
}
if (!$className) {
throw new InvalidArgumentException(
sprintf('The class "%s" does not exist and cannot be used as a session engine', $class)
);
}
$handler = new $className($options);
if (!($handler instanceof SessionHandlerInterface)) {
throw new InvalidArgumentException(
'The chosen SessionHandler does not implement SessionHandlerInterface, it cannot be used as an engine.'
);
}
return $this->setEngine($handler);
} | [
"public",
"function",
"engine",
"(",
"$",
"class",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"class",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_engine",
";",
"}",
"if",
"(",
"$",
"class",
"instanceof",
"SessionHandlerInterface",
")",
"{",
"return",
"$",
"this",
"->",
"setEngine",
"(",
"$",
"class",
")",
";",
"}",
"$",
"className",
"=",
"App",
"::",
"className",
"(",
"$",
"class",
",",
"'Http/Session'",
")",
";",
"if",
"(",
"!",
"$",
"className",
")",
"{",
"$",
"className",
"=",
"App",
"::",
"className",
"(",
"$",
"class",
",",
"'Network/Session'",
")",
";",
"if",
"(",
"$",
"className",
")",
"{",
"deprecationWarning",
"(",
"'Session adapters should be moved to the Http/Session namespace.'",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"className",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The class \"%s\" does not exist and cannot be used as a session engine'",
",",
"$",
"class",
")",
")",
";",
"}",
"$",
"handler",
"=",
"new",
"$",
"className",
"(",
"$",
"options",
")",
";",
"if",
"(",
"!",
"(",
"$",
"handler",
"instanceof",
"SessionHandlerInterface",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The chosen SessionHandler does not implement SessionHandlerInterface, it cannot be used as an engine.'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"setEngine",
"(",
"$",
"handler",
")",
";",
"}"
] | Sets the session handler instance to use for this session.
If a string is passed for the first argument, it will be treated as the
class name and the second argument will be passed as the first argument
in the constructor.
If an instance of a SessionHandlerInterface is provided as the first argument,
the handler will be set to it.
If no arguments are passed it will return the currently configured handler instance
or null if none exists.
@param string|\SessionHandlerInterface|null $class The session handler to use
@param array $options the options to pass to the SessionHandler constructor
@return \SessionHandlerInterface|null
@throws \InvalidArgumentException | [
"Sets",
"the",
"session",
"handler",
"instance",
"to",
"use",
"for",
"this",
"session",
".",
"If",
"a",
"string",
"is",
"passed",
"for",
"the",
"first",
"argument",
"it",
"will",
"be",
"treated",
"as",
"the",
"class",
"name",
"and",
"the",
"second",
"argument",
"will",
"be",
"passed",
"as",
"the",
"first",
"argument",
"in",
"the",
"constructor",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Session.php#L253-L283 |
211,443 | cakephp/cakephp | src/Http/Session.php | Session.setEngine | protected function setEngine(SessionHandlerInterface $handler)
{
if (!headers_sent() && session_status() !== \PHP_SESSION_ACTIVE) {
session_set_save_handler($handler, false);
}
return $this->_engine = $handler;
} | php | protected function setEngine(SessionHandlerInterface $handler)
{
if (!headers_sent() && session_status() !== \PHP_SESSION_ACTIVE) {
session_set_save_handler($handler, false);
}
return $this->_engine = $handler;
} | [
"protected",
"function",
"setEngine",
"(",
"SessionHandlerInterface",
"$",
"handler",
")",
"{",
"if",
"(",
"!",
"headers_sent",
"(",
")",
"&&",
"session_status",
"(",
")",
"!==",
"\\",
"PHP_SESSION_ACTIVE",
")",
"{",
"session_set_save_handler",
"(",
"$",
"handler",
",",
"false",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_engine",
"=",
"$",
"handler",
";",
"}"
] | Set the engine property and update the session handler in PHP.
@param \SessionHandlerInterface $handler The handler to set
@return \SessionHandlerInterface | [
"Set",
"the",
"engine",
"property",
"and",
"update",
"the",
"session",
"handler",
"in",
"PHP",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Session.php#L291-L298 |
211,444 | cakephp/cakephp | src/Http/Session.php | Session.close | public function close()
{
if (!$this->_started) {
return true;
}
if (!session_write_close()) {
throw new RuntimeException('Could not close the session');
}
$this->_started = false;
return true;
} | php | public function close()
{
if (!$this->_started) {
return true;
}
if (!session_write_close()) {
throw new RuntimeException('Could not close the session');
}
$this->_started = false;
return true;
} | [
"public",
"function",
"close",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_started",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"session_write_close",
"(",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Could not close the session'",
")",
";",
"}",
"$",
"this",
"->",
"_started",
"=",
"false",
";",
"return",
"true",
";",
"}"
] | Write data and close the session
@return bool True if session was started | [
"Write",
"data",
"and",
"close",
"the",
"session"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Session.php#L376-L389 |
211,445 | cakephp/cakephp | src/Http/Session.php | Session.check | public function check($name = null)
{
if ($this->_hasSession() && !$this->started()) {
$this->start();
}
if (!isset($_SESSION)) {
return false;
}
return Hash::get($_SESSION, $name) !== null;
} | php | public function check($name = null)
{
if ($this->_hasSession() && !$this->started()) {
$this->start();
}
if (!isset($_SESSION)) {
return false;
}
return Hash::get($_SESSION, $name) !== null;
} | [
"public",
"function",
"check",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_hasSession",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"started",
"(",
")",
")",
"{",
"$",
"this",
"->",
"start",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"_SESSION",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"Hash",
"::",
"get",
"(",
"$",
"_SESSION",
",",
"$",
"name",
")",
"!==",
"null",
";",
"}"
] | Returns true if given variable name is set in session.
@param string|null $name Variable name to check for
@return bool True if variable is there | [
"Returns",
"true",
"if",
"given",
"variable",
"name",
"is",
"set",
"in",
"session",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Session.php#L407-L418 |
211,446 | cakephp/cakephp | src/Http/Session.php | Session.consume | public function consume($name)
{
if (empty($name)) {
return null;
}
$value = $this->read($name);
if ($value !== null) {
$this->_overwrite($_SESSION, Hash::remove($_SESSION, $name));
}
return $value;
} | php | public function consume($name)
{
if (empty($name)) {
return null;
}
$value = $this->read($name);
if ($value !== null) {
$this->_overwrite($_SESSION, Hash::remove($_SESSION, $name));
}
return $value;
} | [
"public",
"function",
"consume",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"value",
"=",
"$",
"this",
"->",
"read",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"value",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"_overwrite",
"(",
"$",
"_SESSION",
",",
"Hash",
"::",
"remove",
"(",
"$",
"_SESSION",
",",
"$",
"name",
")",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Reads and deletes a variable from session.
@param string $name The key to read and remove (or a path as sent to Hash.extract).
@return mixed The value of the session variable, null if session not available,
session not started, or provided name not found in the session. | [
"Reads",
"and",
"deletes",
"a",
"variable",
"from",
"session",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Session.php#L451-L462 |
211,447 | cakephp/cakephp | src/Http/Session.php | Session.write | public function write($name, $value = null)
{
if (!$this->started()) {
$this->start();
}
$write = $name;
if (!is_array($name)) {
$write = [$name => $value];
}
$data = isset($_SESSION) ? $_SESSION : [];
foreach ($write as $key => $val) {
$data = Hash::insert($data, $key, $val);
}
$this->_overwrite($_SESSION, $data);
} | php | public function write($name, $value = null)
{
if (!$this->started()) {
$this->start();
}
$write = $name;
if (!is_array($name)) {
$write = [$name => $value];
}
$data = isset($_SESSION) ? $_SESSION : [];
foreach ($write as $key => $val) {
$data = Hash::insert($data, $key, $val);
}
$this->_overwrite($_SESSION, $data);
} | [
"public",
"function",
"write",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"started",
"(",
")",
")",
"{",
"$",
"this",
"->",
"start",
"(",
")",
";",
"}",
"$",
"write",
"=",
"$",
"name",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"name",
")",
")",
"{",
"$",
"write",
"=",
"[",
"$",
"name",
"=>",
"$",
"value",
"]",
";",
"}",
"$",
"data",
"=",
"isset",
"(",
"$",
"_SESSION",
")",
"?",
"$",
"_SESSION",
":",
"[",
"]",
";",
"foreach",
"(",
"$",
"write",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"data",
"=",
"Hash",
"::",
"insert",
"(",
"$",
"data",
",",
"$",
"key",
",",
"$",
"val",
")",
";",
"}",
"$",
"this",
"->",
"_overwrite",
"(",
"$",
"_SESSION",
",",
"$",
"data",
")",
";",
"}"
] | Writes value to given session variable name.
@param string|array $name Name of variable
@param mixed $value Value to write
@return void | [
"Writes",
"value",
"to",
"given",
"session",
"variable",
"name",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Session.php#L471-L488 |
211,448 | cakephp/cakephp | src/Http/Session.php | Session.delete | public function delete($name)
{
if ($this->check($name)) {
$this->_overwrite($_SESSION, Hash::remove($_SESSION, $name));
}
} | php | public function delete($name)
{
if ($this->check($name)) {
$this->_overwrite($_SESSION, Hash::remove($_SESSION, $name));
}
} | [
"public",
"function",
"delete",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"check",
"(",
"$",
"name",
")",
")",
"{",
"$",
"this",
"->",
"_overwrite",
"(",
"$",
"_SESSION",
",",
"Hash",
"::",
"remove",
"(",
"$",
"_SESSION",
",",
"$",
"name",
")",
")",
";",
"}",
"}"
] | Removes a variable from session.
@param string $name Session variable to remove
@return void | [
"Removes",
"a",
"variable",
"from",
"session",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Session.php#L519-L524 |
211,449 | cakephp/cakephp | src/Http/Session.php | Session._overwrite | protected function _overwrite(&$old, $new)
{
if (!empty($old)) {
foreach ($old as $key => $var) {
if (!isset($new[$key])) {
unset($old[$key]);
}
}
}
foreach ($new as $key => $var) {
$old[$key] = $var;
}
} | php | protected function _overwrite(&$old, $new)
{
if (!empty($old)) {
foreach ($old as $key => $var) {
if (!isset($new[$key])) {
unset($old[$key]);
}
}
}
foreach ($new as $key => $var) {
$old[$key] = $var;
}
} | [
"protected",
"function",
"_overwrite",
"(",
"&",
"$",
"old",
",",
"$",
"new",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"old",
")",
")",
"{",
"foreach",
"(",
"$",
"old",
"as",
"$",
"key",
"=>",
"$",
"var",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"new",
"[",
"$",
"key",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"old",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"}",
"foreach",
"(",
"$",
"new",
"as",
"$",
"key",
"=>",
"$",
"var",
")",
"{",
"$",
"old",
"[",
"$",
"key",
"]",
"=",
"$",
"var",
";",
"}",
"}"
] | Used to write new data to _SESSION, since PHP doesn't like us setting the _SESSION var itself.
@param array $old Set of old variables => values
@param array $new New set of variable => value
@return void | [
"Used",
"to",
"write",
"new",
"data",
"to",
"_SESSION",
"since",
"PHP",
"doesn",
"t",
"like",
"us",
"setting",
"the",
"_SESSION",
"var",
"itself",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Session.php#L533-L545 |
211,450 | cakephp/cakephp | src/Http/Session.php | Session.destroy | public function destroy()
{
if ($this->_hasSession() && !$this->started()) {
$this->start();
}
if (!$this->_isCLI && session_status() === \PHP_SESSION_ACTIVE) {
session_destroy();
}
$_SESSION = [];
$this->_started = false;
} | php | public function destroy()
{
if ($this->_hasSession() && !$this->started()) {
$this->start();
}
if (!$this->_isCLI && session_status() === \PHP_SESSION_ACTIVE) {
session_destroy();
}
$_SESSION = [];
$this->_started = false;
} | [
"public",
"function",
"destroy",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_hasSession",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"started",
"(",
")",
")",
"{",
"$",
"this",
"->",
"start",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"_isCLI",
"&&",
"session_status",
"(",
")",
"===",
"\\",
"PHP_SESSION_ACTIVE",
")",
"{",
"session_destroy",
"(",
")",
";",
"}",
"$",
"_SESSION",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"_started",
"=",
"false",
";",
"}"
] | Helper method to destroy invalid sessions.
@return void | [
"Helper",
"method",
"to",
"destroy",
"invalid",
"sessions",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Session.php#L552-L564 |
211,451 | cakephp/cakephp | src/Http/Session.php | Session._hasSession | protected function _hasSession()
{
return !ini_get('session.use_cookies')
|| isset($_COOKIE[session_name()])
|| $this->_isCLI
|| (ini_get('session.use_trans_sid') && isset($_GET[session_name()]));
} | php | protected function _hasSession()
{
return !ini_get('session.use_cookies')
|| isset($_COOKIE[session_name()])
|| $this->_isCLI
|| (ini_get('session.use_trans_sid') && isset($_GET[session_name()]));
} | [
"protected",
"function",
"_hasSession",
"(",
")",
"{",
"return",
"!",
"ini_get",
"(",
"'session.use_cookies'",
")",
"||",
"isset",
"(",
"$",
"_COOKIE",
"[",
"session_name",
"(",
")",
"]",
")",
"||",
"$",
"this",
"->",
"_isCLI",
"||",
"(",
"ini_get",
"(",
"'session.use_trans_sid'",
")",
"&&",
"isset",
"(",
"$",
"_GET",
"[",
"session_name",
"(",
")",
"]",
")",
")",
";",
"}"
] | Returns whether a session exists
@return bool | [
"Returns",
"whether",
"a",
"session",
"exists"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Session.php#L587-L593 |
211,452 | cakephp/cakephp | src/Http/Session.php | Session.renew | public function renew()
{
if (!$this->_hasSession() || $this->_isCLI) {
return;
}
$this->start();
$params = session_get_cookie_params();
setcookie(
session_name(),
'',
time() - 42000,
$params['path'],
$params['domain'],
$params['secure'],
$params['httponly']
);
if (session_id()) {
session_regenerate_id(true);
}
} | php | public function renew()
{
if (!$this->_hasSession() || $this->_isCLI) {
return;
}
$this->start();
$params = session_get_cookie_params();
setcookie(
session_name(),
'',
time() - 42000,
$params['path'],
$params['domain'],
$params['secure'],
$params['httponly']
);
if (session_id()) {
session_regenerate_id(true);
}
} | [
"public",
"function",
"renew",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_hasSession",
"(",
")",
"||",
"$",
"this",
"->",
"_isCLI",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"start",
"(",
")",
";",
"$",
"params",
"=",
"session_get_cookie_params",
"(",
")",
";",
"setcookie",
"(",
"session_name",
"(",
")",
",",
"''",
",",
"time",
"(",
")",
"-",
"42000",
",",
"$",
"params",
"[",
"'path'",
"]",
",",
"$",
"params",
"[",
"'domain'",
"]",
",",
"$",
"params",
"[",
"'secure'",
"]",
",",
"$",
"params",
"[",
"'httponly'",
"]",
")",
";",
"if",
"(",
"session_id",
"(",
")",
")",
"{",
"session_regenerate_id",
"(",
"true",
")",
";",
"}",
"}"
] | Restarts this session.
@return void | [
"Restarts",
"this",
"session",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Session.php#L600-L621 |
211,453 | cakephp/cakephp | src/Http/Session.php | Session._timedOut | protected function _timedOut()
{
$time = $this->read('Config.time');
$result = false;
$checkTime = $time !== null && $this->_lifetime > 0;
if ($checkTime && (time() - (int)$time > $this->_lifetime)) {
$result = true;
}
$this->write('Config.time', time());
return $result;
} | php | protected function _timedOut()
{
$time = $this->read('Config.time');
$result = false;
$checkTime = $time !== null && $this->_lifetime > 0;
if ($checkTime && (time() - (int)$time > $this->_lifetime)) {
$result = true;
}
$this->write('Config.time', time());
return $result;
} | [
"protected",
"function",
"_timedOut",
"(",
")",
"{",
"$",
"time",
"=",
"$",
"this",
"->",
"read",
"(",
"'Config.time'",
")",
";",
"$",
"result",
"=",
"false",
";",
"$",
"checkTime",
"=",
"$",
"time",
"!==",
"null",
"&&",
"$",
"this",
"->",
"_lifetime",
">",
"0",
";",
"if",
"(",
"$",
"checkTime",
"&&",
"(",
"time",
"(",
")",
"-",
"(",
"int",
")",
"$",
"time",
">",
"$",
"this",
"->",
"_lifetime",
")",
")",
"{",
"$",
"result",
"=",
"true",
";",
"}",
"$",
"this",
"->",
"write",
"(",
"'Config.time'",
",",
"time",
"(",
")",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Returns true if the session is no longer valid because the last time it was
accessed was after the configured timeout.
@return bool | [
"Returns",
"true",
"if",
"the",
"session",
"is",
"no",
"longer",
"valid",
"because",
"the",
"last",
"time",
"it",
"was",
"accessed",
"was",
"after",
"the",
"configured",
"timeout",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Session.php#L629-L642 |
211,454 | cakephp/cakephp | src/View/Helper/HtmlHelper.php | HtmlHelper.addCrumb | public function addCrumb($name, $link = null, array $options = [])
{
deprecationWarning(
'HtmlHelper::addCrumb() is deprecated. ' .
'Use the BreadcrumbsHelper instead.'
);
$this->_crumbs[] = [$name, $link, $options];
return $this;
} | php | public function addCrumb($name, $link = null, array $options = [])
{
deprecationWarning(
'HtmlHelper::addCrumb() is deprecated. ' .
'Use the BreadcrumbsHelper instead.'
);
$this->_crumbs[] = [$name, $link, $options];
return $this;
} | [
"public",
"function",
"addCrumb",
"(",
"$",
"name",
",",
"$",
"link",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"deprecationWarning",
"(",
"'HtmlHelper::addCrumb() is deprecated. '",
".",
"'Use the BreadcrumbsHelper instead.'",
")",
";",
"$",
"this",
"->",
"_crumbs",
"[",
"]",
"=",
"[",
"$",
"name",
",",
"$",
"link",
",",
"$",
"options",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Adds a link to the breadcrumbs array.
@param string $name Text for link
@param string|array|null $link URL for link (if empty it won't be a link)
@param array $options Link attributes e.g. ['id' => 'selected']
@return $this
@see \Cake\View\Helper\HtmlHelper::link() for details on $options that can be used.
@link https://book.cakephp.org/3.0/en/views/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper
@deprecated 3.3.6 Use the BreadcrumbsHelper instead | [
"Adds",
"a",
"link",
"to",
"the",
"breadcrumbs",
"array",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/HtmlHelper.php#L160-L170 |
211,455 | cakephp/cakephp | src/View/Helper/HtmlHelper.php | HtmlHelper.docType | public function docType($type = 'html5')
{
if (isset($this->_docTypes[$type])) {
return $this->_docTypes[$type];
}
return null;
} | php | public function docType($type = 'html5')
{
if (isset($this->_docTypes[$type])) {
return $this->_docTypes[$type];
}
return null;
} | [
"public",
"function",
"docType",
"(",
"$",
"type",
"=",
"'html5'",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_docTypes",
"[",
"$",
"type",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_docTypes",
"[",
"$",
"type",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Returns a doctype string.
Possible doctypes:
- html4-strict: HTML4 Strict.
- html4-trans: HTML4 Transitional.
- html4-frame: HTML4 Frameset.
- html5: HTML5. Default value.
- xhtml-strict: XHTML1 Strict.
- xhtml-trans: XHTML1 Transitional.
- xhtml-frame: XHTML1 Frameset.
- xhtml11: XHTML1.1.
@param string $type Doctype to use.
@return string|null Doctype string
@link https://book.cakephp.org/3.0/en/views/helpers/html.html#creating-doctype-tags | [
"Returns",
"a",
"doctype",
"string",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/HtmlHelper.php#L190-L197 |
211,456 | cakephp/cakephp | src/View/Helper/HtmlHelper.php | HtmlHelper.charset | public function charset($charset = null)
{
if (empty($charset)) {
$charset = strtolower(Configure::read('App.encoding'));
}
return $this->formatTemplate('charset', [
'charset' => !empty($charset) ? $charset : 'utf-8'
]);
} | php | public function charset($charset = null)
{
if (empty($charset)) {
$charset = strtolower(Configure::read('App.encoding'));
}
return $this->formatTemplate('charset', [
'charset' => !empty($charset) ? $charset : 'utf-8'
]);
} | [
"public",
"function",
"charset",
"(",
"$",
"charset",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"charset",
")",
")",
"{",
"$",
"charset",
"=",
"strtolower",
"(",
"Configure",
"::",
"read",
"(",
"'App.encoding'",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"formatTemplate",
"(",
"'charset'",
",",
"[",
"'charset'",
"=>",
"!",
"empty",
"(",
"$",
"charset",
")",
"?",
"$",
"charset",
":",
"'utf-8'",
"]",
")",
";",
"}"
] | Returns a charset META-tag.
@param string|null $charset The character set to be used in the meta tag. If empty,
The App.encoding value will be used. Example: "utf-8".
@return string A meta tag containing the specified character set.
@link https://book.cakephp.org/3.0/en/views/helpers/html.html#creating-charset-tags | [
"Returns",
"a",
"charset",
"META",
"-",
"tag",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/HtmlHelper.php#L316-L325 |
211,457 | cakephp/cakephp | src/View/Helper/HtmlHelper.php | HtmlHelper.css | public function css($path, array $options = [])
{
$options += ['once' => true, 'block' => null, 'rel' => 'stylesheet'];
if (is_array($path)) {
$out = '';
foreach ($path as $i) {
$out .= "\n\t" . $this->css($i, $options);
}
if (empty($options['block'])) {
return $out . "\n";
}
return null;
}
if (strpos($path, '//') !== false) {
$url = $path;
} else {
$url = $this->Url->css($path, $options);
$options = array_diff_key($options, ['fullBase' => null, 'pathPrefix' => null]);
}
if ($options['once'] && isset($this->_includedAssets[__METHOD__][$path])) {
return null;
}
unset($options['once']);
$this->_includedAssets[__METHOD__][$path] = true;
$templater = $this->templater();
if ($options['rel'] === 'import') {
$out = $templater->format('style', [
'attrs' => $templater->formatAttributes($options, ['rel', 'block']),
'content' => '@import url(' . $url . ');',
]);
} else {
$out = $templater->format('css', [
'rel' => $options['rel'],
'url' => $url,
'attrs' => $templater->formatAttributes($options, ['rel', 'block']),
]);
}
if (empty($options['block'])) {
return $out;
}
if ($options['block'] === true) {
$options['block'] = __FUNCTION__;
}
$this->_View->append($options['block'], $out);
} | php | public function css($path, array $options = [])
{
$options += ['once' => true, 'block' => null, 'rel' => 'stylesheet'];
if (is_array($path)) {
$out = '';
foreach ($path as $i) {
$out .= "\n\t" . $this->css($i, $options);
}
if (empty($options['block'])) {
return $out . "\n";
}
return null;
}
if (strpos($path, '//') !== false) {
$url = $path;
} else {
$url = $this->Url->css($path, $options);
$options = array_diff_key($options, ['fullBase' => null, 'pathPrefix' => null]);
}
if ($options['once'] && isset($this->_includedAssets[__METHOD__][$path])) {
return null;
}
unset($options['once']);
$this->_includedAssets[__METHOD__][$path] = true;
$templater = $this->templater();
if ($options['rel'] === 'import') {
$out = $templater->format('style', [
'attrs' => $templater->formatAttributes($options, ['rel', 'block']),
'content' => '@import url(' . $url . ');',
]);
} else {
$out = $templater->format('css', [
'rel' => $options['rel'],
'url' => $url,
'attrs' => $templater->formatAttributes($options, ['rel', 'block']),
]);
}
if (empty($options['block'])) {
return $out;
}
if ($options['block'] === true) {
$options['block'] = __FUNCTION__;
}
$this->_View->append($options['block'], $out);
} | [
"public",
"function",
"css",
"(",
"$",
"path",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"+=",
"[",
"'once'",
"=>",
"true",
",",
"'block'",
"=>",
"null",
",",
"'rel'",
"=>",
"'stylesheet'",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"path",
")",
")",
"{",
"$",
"out",
"=",
"''",
";",
"foreach",
"(",
"$",
"path",
"as",
"$",
"i",
")",
"{",
"$",
"out",
".=",
"\"\\n\\t\"",
".",
"$",
"this",
"->",
"css",
"(",
"$",
"i",
",",
"$",
"options",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'block'",
"]",
")",
")",
"{",
"return",
"$",
"out",
".",
"\"\\n\"",
";",
"}",
"return",
"null",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"path",
",",
"'//'",
")",
"!==",
"false",
")",
"{",
"$",
"url",
"=",
"$",
"path",
";",
"}",
"else",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"Url",
"->",
"css",
"(",
"$",
"path",
",",
"$",
"options",
")",
";",
"$",
"options",
"=",
"array_diff_key",
"(",
"$",
"options",
",",
"[",
"'fullBase'",
"=>",
"null",
",",
"'pathPrefix'",
"=>",
"null",
"]",
")",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'once'",
"]",
"&&",
"isset",
"(",
"$",
"this",
"->",
"_includedAssets",
"[",
"__METHOD__",
"]",
"[",
"$",
"path",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"unset",
"(",
"$",
"options",
"[",
"'once'",
"]",
")",
";",
"$",
"this",
"->",
"_includedAssets",
"[",
"__METHOD__",
"]",
"[",
"$",
"path",
"]",
"=",
"true",
";",
"$",
"templater",
"=",
"$",
"this",
"->",
"templater",
"(",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'rel'",
"]",
"===",
"'import'",
")",
"{",
"$",
"out",
"=",
"$",
"templater",
"->",
"format",
"(",
"'style'",
",",
"[",
"'attrs'",
"=>",
"$",
"templater",
"->",
"formatAttributes",
"(",
"$",
"options",
",",
"[",
"'rel'",
",",
"'block'",
"]",
")",
",",
"'content'",
"=>",
"'@import url('",
".",
"$",
"url",
".",
"');'",
",",
"]",
")",
";",
"}",
"else",
"{",
"$",
"out",
"=",
"$",
"templater",
"->",
"format",
"(",
"'css'",
",",
"[",
"'rel'",
"=>",
"$",
"options",
"[",
"'rel'",
"]",
",",
"'url'",
"=>",
"$",
"url",
",",
"'attrs'",
"=>",
"$",
"templater",
"->",
"formatAttributes",
"(",
"$",
"options",
",",
"[",
"'rel'",
",",
"'block'",
"]",
")",
",",
"]",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'block'",
"]",
")",
")",
"{",
"return",
"$",
"out",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'block'",
"]",
"===",
"true",
")",
"{",
"$",
"options",
"[",
"'block'",
"]",
"=",
"__FUNCTION__",
";",
"}",
"$",
"this",
"->",
"_View",
"->",
"append",
"(",
"$",
"options",
"[",
"'block'",
"]",
",",
"$",
"out",
")",
";",
"}"
] | Creates a link element for CSS stylesheets.
### Usage
Include one CSS file:
```
echo $this->Html->css('styles.css');
```
Include multiple CSS files:
```
echo $this->Html->css(['one.css', 'two.css']);
```
Add the stylesheet to view block "css":
```
$this->Html->css('styles.css', ['block' => true]);
```
Add the stylesheet to a custom block:
```
$this->Html->css('styles.css', ['block' => 'layoutCss']);
```
### Options
- `block` Set to true to append output to view block "css" or provide
custom block name.
- `once` Whether or not the css file should be checked for uniqueness. If true css
files will only be included once, use false to allow the same
css to be included more than once per request.
- `plugin` False value will prevent parsing path as a plugin
- `rel` Defaults to 'stylesheet'. If equal to 'import' the stylesheet will be imported.
- `fullBase` If true the URL will get a full address for the css file.
@param string|array $path The name of a CSS style sheet or an array containing names of
CSS stylesheets. If `$path` is prefixed with '/', the path will be relative to the webroot
of your application. Otherwise, the path will be relative to your CSS path, usually webroot/css.
@param array $options Array of options and HTML arguments.
@return string|null CSS `<link />` or `<style />` tag, depending on the type of link.
@link https://book.cakephp.org/3.0/en/views/helpers/html.html#linking-to-css-files | [
"Creates",
"a",
"link",
"element",
"for",
"CSS",
"stylesheets",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/HtmlHelper.php#L445-L495 |
211,458 | cakephp/cakephp | src/View/Helper/HtmlHelper.php | HtmlHelper.scriptEnd | public function scriptEnd()
{
$buffer = ob_get_clean();
$options = $this->_scriptBlockOptions;
$this->_scriptBlockOptions = [];
return $this->scriptBlock($buffer, $options);
} | php | public function scriptEnd()
{
$buffer = ob_get_clean();
$options = $this->_scriptBlockOptions;
$this->_scriptBlockOptions = [];
return $this->scriptBlock($buffer, $options);
} | [
"public",
"function",
"scriptEnd",
"(",
")",
"{",
"$",
"buffer",
"=",
"ob_get_clean",
"(",
")",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"_scriptBlockOptions",
";",
"$",
"this",
"->",
"_scriptBlockOptions",
"=",
"[",
"]",
";",
"return",
"$",
"this",
"->",
"scriptBlock",
"(",
"$",
"buffer",
",",
"$",
"options",
")",
";",
"}"
] | End a Buffered section of JavaScript capturing.
Generates a script tag inline or appends to specified view block depending on
the settings used when the scriptBlock was started
@return string|null Depending on the settings of scriptStart() either a script tag or null
@link https://book.cakephp.org/3.0/en/views/helpers/html.html#creating-inline-javascript-blocks | [
"End",
"a",
"Buffered",
"section",
"of",
"JavaScript",
"capturing",
".",
"Generates",
"a",
"script",
"tag",
"inline",
"or",
"appends",
"to",
"specified",
"view",
"block",
"depending",
"on",
"the",
"settings",
"used",
"when",
"the",
"scriptBlock",
"was",
"started"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/HtmlHelper.php#L646-L653 |
211,459 | cakephp/cakephp | src/View/Helper/HtmlHelper.php | HtmlHelper.style | public function style(array $data, $oneLine = true)
{
$out = [];
foreach ($data as $key => $value) {
$out[] = $key . ':' . $value . ';';
}
if ($oneLine) {
return implode(' ', $out);
}
return implode("\n", $out);
} | php | public function style(array $data, $oneLine = true)
{
$out = [];
foreach ($data as $key => $value) {
$out[] = $key . ':' . $value . ';';
}
if ($oneLine) {
return implode(' ', $out);
}
return implode("\n", $out);
} | [
"public",
"function",
"style",
"(",
"array",
"$",
"data",
",",
"$",
"oneLine",
"=",
"true",
")",
"{",
"$",
"out",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"out",
"[",
"]",
"=",
"$",
"key",
".",
"':'",
".",
"$",
"value",
".",
"';'",
";",
"}",
"if",
"(",
"$",
"oneLine",
")",
"{",
"return",
"implode",
"(",
"' '",
",",
"$",
"out",
")",
";",
"}",
"return",
"implode",
"(",
"\"\\n\"",
",",
"$",
"out",
")",
";",
"}"
] | Builds CSS style data from an array of CSS properties
### Usage:
```
echo $this->Html->style(['margin' => '10px', 'padding' => '10px'], true);
// creates
'margin:10px;padding:10px;'
```
@param array $data Style data array, keys will be used as property names, values as property values.
@param bool $oneLine Whether or not the style block should be displayed on one line.
@return string CSS styling data
@link https://book.cakephp.org/3.0/en/views/helpers/html.html#creating-css-programatically | [
"Builds",
"CSS",
"style",
"data",
"from",
"an",
"array",
"of",
"CSS",
"properties"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/HtmlHelper.php#L672-L683 |
211,460 | cakephp/cakephp | src/View/Helper/HtmlHelper.php | HtmlHelper.getCrumbs | public function getCrumbs($separator = '»', $startText = false)
{
deprecationWarning(
'HtmlHelper::getCrumbs() is deprecated. ' .
'Use the BreadcrumbsHelper instead.'
);
$crumbs = $this->_prepareCrumbs($startText);
if (!empty($crumbs)) {
$out = [];
foreach ($crumbs as $crumb) {
if (!empty($crumb[1])) {
$out[] = $this->link($crumb[0], $crumb[1], $crumb[2]);
} else {
$out[] = $crumb[0];
}
}
return implode($separator, $out);
}
return null;
} | php | public function getCrumbs($separator = '»', $startText = false)
{
deprecationWarning(
'HtmlHelper::getCrumbs() is deprecated. ' .
'Use the BreadcrumbsHelper instead.'
);
$crumbs = $this->_prepareCrumbs($startText);
if (!empty($crumbs)) {
$out = [];
foreach ($crumbs as $crumb) {
if (!empty($crumb[1])) {
$out[] = $this->link($crumb[0], $crumb[1], $crumb[2]);
} else {
$out[] = $crumb[0];
}
}
return implode($separator, $out);
}
return null;
} | [
"public",
"function",
"getCrumbs",
"(",
"$",
"separator",
"=",
"'»'",
",",
"$",
"startText",
"=",
"false",
")",
"{",
"deprecationWarning",
"(",
"'HtmlHelper::getCrumbs() is deprecated. '",
".",
"'Use the BreadcrumbsHelper instead.'",
")",
";",
"$",
"crumbs",
"=",
"$",
"this",
"->",
"_prepareCrumbs",
"(",
"$",
"startText",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"crumbs",
")",
")",
"{",
"$",
"out",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"crumbs",
"as",
"$",
"crumb",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"crumb",
"[",
"1",
"]",
")",
")",
"{",
"$",
"out",
"[",
"]",
"=",
"$",
"this",
"->",
"link",
"(",
"$",
"crumb",
"[",
"0",
"]",
",",
"$",
"crumb",
"[",
"1",
"]",
",",
"$",
"crumb",
"[",
"2",
"]",
")",
";",
"}",
"else",
"{",
"$",
"out",
"[",
"]",
"=",
"$",
"crumb",
"[",
"0",
"]",
";",
"}",
"}",
"return",
"implode",
"(",
"$",
"separator",
",",
"$",
"out",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Returns the breadcrumb trail as a sequence of »-separated links.
If `$startText` is an array, the accepted keys are:
- `text` Define the text/content for the link.
- `url` Define the target of the created link.
All other keys will be passed to HtmlHelper::link() as the `$options` parameter.
@param string $separator Text to separate crumbs.
@param string|array|bool $startText This will be the first crumb, if false it defaults to first crumb in array. Can
also be an array, see above for details.
@return string|null Composed bread crumbs
@link https://book.cakephp.org/3.0/en/views/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper
@deprecated 3.3.6 Use the BreadcrumbsHelper instead | [
"Returns",
"the",
"breadcrumb",
"trail",
"as",
"a",
"sequence",
"of",
"»",
";",
"-",
"separated",
"links",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/HtmlHelper.php#L702-L724 |
211,461 | cakephp/cakephp | src/View/Helper/HtmlHelper.php | HtmlHelper._prepareCrumbs | protected function _prepareCrumbs($startText, $escape = true)
{
deprecationWarning(
'HtmlHelper::_prepareCrumbs() is deprecated. ' .
'Use the BreadcrumbsHelper instead.'
);
$crumbs = $this->_crumbs;
if ($startText) {
if (!is_array($startText)) {
$startText = [
'url' => '/',
'text' => $startText
];
}
$startText += ['url' => '/', 'text' => __d('cake', 'Home')];
list($url, $text) = [$startText['url'], $startText['text']];
unset($startText['url'], $startText['text']);
array_unshift($crumbs, [$text, $url, $startText + ['escape' => $escape]]);
}
return $crumbs;
} | php | protected function _prepareCrumbs($startText, $escape = true)
{
deprecationWarning(
'HtmlHelper::_prepareCrumbs() is deprecated. ' .
'Use the BreadcrumbsHelper instead.'
);
$crumbs = $this->_crumbs;
if ($startText) {
if (!is_array($startText)) {
$startText = [
'url' => '/',
'text' => $startText
];
}
$startText += ['url' => '/', 'text' => __d('cake', 'Home')];
list($url, $text) = [$startText['url'], $startText['text']];
unset($startText['url'], $startText['text']);
array_unshift($crumbs, [$text, $url, $startText + ['escape' => $escape]]);
}
return $crumbs;
} | [
"protected",
"function",
"_prepareCrumbs",
"(",
"$",
"startText",
",",
"$",
"escape",
"=",
"true",
")",
"{",
"deprecationWarning",
"(",
"'HtmlHelper::_prepareCrumbs() is deprecated. '",
".",
"'Use the BreadcrumbsHelper instead.'",
")",
";",
"$",
"crumbs",
"=",
"$",
"this",
"->",
"_crumbs",
";",
"if",
"(",
"$",
"startText",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"startText",
")",
")",
"{",
"$",
"startText",
"=",
"[",
"'url'",
"=>",
"'/'",
",",
"'text'",
"=>",
"$",
"startText",
"]",
";",
"}",
"$",
"startText",
"+=",
"[",
"'url'",
"=>",
"'/'",
",",
"'text'",
"=>",
"__d",
"(",
"'cake'",
",",
"'Home'",
")",
"]",
";",
"list",
"(",
"$",
"url",
",",
"$",
"text",
")",
"=",
"[",
"$",
"startText",
"[",
"'url'",
"]",
",",
"$",
"startText",
"[",
"'text'",
"]",
"]",
";",
"unset",
"(",
"$",
"startText",
"[",
"'url'",
"]",
",",
"$",
"startText",
"[",
"'text'",
"]",
")",
";",
"array_unshift",
"(",
"$",
"crumbs",
",",
"[",
"$",
"text",
",",
"$",
"url",
",",
"$",
"startText",
"+",
"[",
"'escape'",
"=>",
"$",
"escape",
"]",
"]",
")",
";",
"}",
"return",
"$",
"crumbs",
";",
"}"
] | Prepends startText to crumbs array if set
@param string|array|bool $startText Text to prepend
@param bool $escape If the output should be escaped or not
@return array Crumb list including startText (if provided)
@deprecated 3.3.6 Use the BreadcrumbsHelper instead | [
"Prepends",
"startText",
"to",
"crumbs",
"array",
"if",
"set"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/HtmlHelper.php#L804-L826 |
211,462 | cakephp/cakephp | src/View/Helper/HtmlHelper.php | HtmlHelper.tableHeaders | public function tableHeaders(array $names, array $trOptions = null, array $thOptions = null)
{
$out = [];
foreach ($names as $arg) {
if (!is_array($arg)) {
$out[] = $this->formatTemplate('tableheader', [
'attrs' => $this->templater()->formatAttributes($thOptions),
'content' => $arg
]);
} else {
$out[] = $this->formatTemplate('tableheader', [
'attrs' => $this->templater()->formatAttributes(current($arg)),
'content' => key($arg)
]);
}
}
return $this->tableRow(implode(' ', $out), (array)$trOptions);
} | php | public function tableHeaders(array $names, array $trOptions = null, array $thOptions = null)
{
$out = [];
foreach ($names as $arg) {
if (!is_array($arg)) {
$out[] = $this->formatTemplate('tableheader', [
'attrs' => $this->templater()->formatAttributes($thOptions),
'content' => $arg
]);
} else {
$out[] = $this->formatTemplate('tableheader', [
'attrs' => $this->templater()->formatAttributes(current($arg)),
'content' => key($arg)
]);
}
}
return $this->tableRow(implode(' ', $out), (array)$trOptions);
} | [
"public",
"function",
"tableHeaders",
"(",
"array",
"$",
"names",
",",
"array",
"$",
"trOptions",
"=",
"null",
",",
"array",
"$",
"thOptions",
"=",
"null",
")",
"{",
"$",
"out",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"names",
"as",
"$",
"arg",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"arg",
")",
")",
"{",
"$",
"out",
"[",
"]",
"=",
"$",
"this",
"->",
"formatTemplate",
"(",
"'tableheader'",
",",
"[",
"'attrs'",
"=>",
"$",
"this",
"->",
"templater",
"(",
")",
"->",
"formatAttributes",
"(",
"$",
"thOptions",
")",
",",
"'content'",
"=>",
"$",
"arg",
"]",
")",
";",
"}",
"else",
"{",
"$",
"out",
"[",
"]",
"=",
"$",
"this",
"->",
"formatTemplate",
"(",
"'tableheader'",
",",
"[",
"'attrs'",
"=>",
"$",
"this",
"->",
"templater",
"(",
")",
"->",
"formatAttributes",
"(",
"current",
"(",
"$",
"arg",
")",
")",
",",
"'content'",
"=>",
"key",
"(",
"$",
"arg",
")",
"]",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"tableRow",
"(",
"implode",
"(",
"' '",
",",
"$",
"out",
")",
",",
"(",
"array",
")",
"$",
"trOptions",
")",
";",
"}"
] | Returns a row of formatted and named TABLE headers.
@param array $names Array of tablenames. Each tablename also can be a key that points to an array with a set
of attributes to its specific tag
@param array|null $trOptions HTML options for TR elements.
@param array|null $thOptions HTML options for TH elements.
@return string Completed table headers
@link https://book.cakephp.org/3.0/en/views/helpers/html.html#creating-table-headings | [
"Returns",
"a",
"row",
"of",
"formatted",
"and",
"named",
"TABLE",
"headers",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/HtmlHelper.php#L901-L919 |
211,463 | cakephp/cakephp | src/View/Helper/HtmlHelper.php | HtmlHelper._renderCells | protected function _renderCells($line, $useCount = false)
{
$i = 0;
$cellsOut = [];
foreach ($line as $cell) {
$cellOptions = [];
if (is_array($cell)) {
$cellOptions = $cell[1];
$cell = $cell[0];
}
if ($useCount) {
$i += 1;
if (isset($cellOptions['class'])) {
$cellOptions['class'] .= ' column-' . $i;
} else {
$cellOptions['class'] = 'column-' . $i;
}
}
$cellsOut[] = $this->tableCell($cell, $cellOptions);
}
return $cellsOut;
} | php | protected function _renderCells($line, $useCount = false)
{
$i = 0;
$cellsOut = [];
foreach ($line as $cell) {
$cellOptions = [];
if (is_array($cell)) {
$cellOptions = $cell[1];
$cell = $cell[0];
}
if ($useCount) {
$i += 1;
if (isset($cellOptions['class'])) {
$cellOptions['class'] .= ' column-' . $i;
} else {
$cellOptions['class'] = 'column-' . $i;
}
}
$cellsOut[] = $this->tableCell($cell, $cellOptions);
}
return $cellsOut;
} | [
"protected",
"function",
"_renderCells",
"(",
"$",
"line",
",",
"$",
"useCount",
"=",
"false",
")",
"{",
"$",
"i",
"=",
"0",
";",
"$",
"cellsOut",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"line",
"as",
"$",
"cell",
")",
"{",
"$",
"cellOptions",
"=",
"[",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"cell",
")",
")",
"{",
"$",
"cellOptions",
"=",
"$",
"cell",
"[",
"1",
"]",
";",
"$",
"cell",
"=",
"$",
"cell",
"[",
"0",
"]",
";",
"}",
"if",
"(",
"$",
"useCount",
")",
"{",
"$",
"i",
"+=",
"1",
";",
"if",
"(",
"isset",
"(",
"$",
"cellOptions",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"cellOptions",
"[",
"'class'",
"]",
".=",
"' column-'",
".",
"$",
"i",
";",
"}",
"else",
"{",
"$",
"cellOptions",
"[",
"'class'",
"]",
"=",
"'column-'",
".",
"$",
"i",
";",
"}",
"}",
"$",
"cellsOut",
"[",
"]",
"=",
"$",
"this",
"->",
"tableCell",
"(",
"$",
"cell",
",",
"$",
"cellOptions",
")",
";",
"}",
"return",
"$",
"cellsOut",
";",
"}"
] | Renders cells for a row of a table.
This is a helper method for tableCells(). Overload this method as you
need to change the behavior of the cell rendering.
@param array $line Line data to render.
@param bool $useCount Renders the count into the row. Default is false.
@return string[] | [
"Renders",
"cells",
"for",
"a",
"row",
"of",
"a",
"table",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/HtmlHelper.php#L976-L1001 |
211,464 | cakephp/cakephp | src/View/Helper/HtmlHelper.php | HtmlHelper.div | public function div($class = null, $text = null, array $options = [])
{
if (!empty($class)) {
$options['class'] = $class;
}
return $this->tag('div', $text, $options);
} | php | public function div($class = null, $text = null, array $options = [])
{
if (!empty($class)) {
$options['class'] = $class;
}
return $this->tag('div', $text, $options);
} | [
"public",
"function",
"div",
"(",
"$",
"class",
"=",
"null",
",",
"$",
"text",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"class",
")",
")",
"{",
"$",
"options",
"[",
"'class'",
"]",
"=",
"$",
"class",
";",
"}",
"return",
"$",
"this",
"->",
"tag",
"(",
"'div'",
",",
"$",
"text",
",",
"$",
"options",
")",
";",
"}"
] | Returns a formatted DIV tag for HTML FORMs.
### Options
- `escape` Whether or not the contents should be html_entity escaped.
@param string|null $class CSS class name of the div element.
@param string|null $text String content that will appear inside the div element.
If null, only a start tag will be printed
@param array $options Additional HTML attributes of the DIV tag
@return string The formatted DIV element | [
"Returns",
"a",
"formatted",
"DIV",
"tag",
"for",
"HTML",
"FORMs",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/HtmlHelper.php#L1081-L1088 |
211,465 | cakephp/cakephp | src/View/Helper/HtmlHelper.php | HtmlHelper.para | public function para($class, $text, array $options = [])
{
if (!empty($options['escape'])) {
$text = h($text);
}
if ($class && !empty($class)) {
$options['class'] = $class;
}
$tag = 'para';
if ($text === null) {
$tag = 'parastart';
}
return $this->formatTemplate($tag, [
'attrs' => $this->templater()->formatAttributes($options),
'content' => $text,
]);
} | php | public function para($class, $text, array $options = [])
{
if (!empty($options['escape'])) {
$text = h($text);
}
if ($class && !empty($class)) {
$options['class'] = $class;
}
$tag = 'para';
if ($text === null) {
$tag = 'parastart';
}
return $this->formatTemplate($tag, [
'attrs' => $this->templater()->formatAttributes($options),
'content' => $text,
]);
} | [
"public",
"function",
"para",
"(",
"$",
"class",
",",
"$",
"text",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'escape'",
"]",
")",
")",
"{",
"$",
"text",
"=",
"h",
"(",
"$",
"text",
")",
";",
"}",
"if",
"(",
"$",
"class",
"&&",
"!",
"empty",
"(",
"$",
"class",
")",
")",
"{",
"$",
"options",
"[",
"'class'",
"]",
"=",
"$",
"class",
";",
"}",
"$",
"tag",
"=",
"'para'",
";",
"if",
"(",
"$",
"text",
"===",
"null",
")",
"{",
"$",
"tag",
"=",
"'parastart'",
";",
"}",
"return",
"$",
"this",
"->",
"formatTemplate",
"(",
"$",
"tag",
",",
"[",
"'attrs'",
"=>",
"$",
"this",
"->",
"templater",
"(",
")",
"->",
"formatAttributes",
"(",
"$",
"options",
")",
",",
"'content'",
"=>",
"$",
"text",
",",
"]",
")",
";",
"}"
] | Returns a formatted P tag.
### Options
- `escape` Whether or not the contents should be html_entity escaped.
@param string $class CSS class name of the p element.
@param string $text String content that will appear inside the p element.
@param array $options Additional HTML attributes of the P tag
@return string The formatted P element | [
"Returns",
"a",
"formatted",
"P",
"tag",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/HtmlHelper.php#L1102-L1119 |
211,466 | cakephp/cakephp | src/View/View.php | View.autoLayout | public function autoLayout($autoLayout = null)
{
deprecationWarning(
'View::autoLayout() is deprecated. ' .
'Use isAutoLayoutEnabled()/enableAutoLayout() instead.'
);
if ($autoLayout === null) {
return $this->autoLayout;
}
$this->autoLayout = $autoLayout;
} | php | public function autoLayout($autoLayout = null)
{
deprecationWarning(
'View::autoLayout() is deprecated. ' .
'Use isAutoLayoutEnabled()/enableAutoLayout() instead.'
);
if ($autoLayout === null) {
return $this->autoLayout;
}
$this->autoLayout = $autoLayout;
} | [
"public",
"function",
"autoLayout",
"(",
"$",
"autoLayout",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"'View::autoLayout() is deprecated. '",
".",
"'Use isAutoLayoutEnabled()/enableAutoLayout() instead.'",
")",
";",
"if",
"(",
"$",
"autoLayout",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"autoLayout",
";",
"}",
"$",
"this",
"->",
"autoLayout",
"=",
"$",
"autoLayout",
";",
"}"
] | 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 templates.
@deprecated 3.5.0 Use isAutoLayoutEnabled()/enableAutoLayout() instead.
@param bool|null $autoLayout Boolean to turn on/off. If null returns current value.
@return bool|null | [
"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",
"templates",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/View.php#L589-L601 |
211,467 | cakephp/cakephp | src/View/View.php | View.theme | public function theme($theme = null)
{
deprecationWarning(
'View::theme() is deprecated. ' .
'Use getTheme()/setTheme() instead.'
);
if ($theme === null) {
return $this->theme;
}
$this->theme = $theme;
} | php | public function theme($theme = null)
{
deprecationWarning(
'View::theme() is deprecated. ' .
'Use getTheme()/setTheme() instead.'
);
if ($theme === null) {
return $this->theme;
}
$this->theme = $theme;
} | [
"public",
"function",
"theme",
"(",
"$",
"theme",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"'View::theme() is deprecated. '",
".",
"'Use getTheme()/setTheme() instead.'",
")",
";",
"if",
"(",
"$",
"theme",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"theme",
";",
"}",
"$",
"this",
"->",
"theme",
"=",
"$",
"theme",
";",
"}"
] | The view theme to use.
@deprecated 3.5.0 Use getTheme()/setTheme() instead.
@param string|null $theme Theme name. If null returns current theme.
@return string|null | [
"The",
"view",
"theme",
"to",
"use",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/View.php#L633-L645 |
211,468 | cakephp/cakephp | src/View/View.php | View.element | public function element($name, array $data = [], array $options = [])
{
$options += ['callbacks' => false, 'cache' => null, 'plugin' => null];
if (isset($options['cache'])) {
$options['cache'] = $this->_elementCache($name, $data, $options);
}
$pluginCheck = $options['plugin'] !== false;
$file = $this->_getElementFileName($name, $pluginCheck);
if ($file && $options['cache']) {
return $this->cache(function () use ($file, $data, $options) {
echo $this->_renderElement($file, $data, $options);
}, $options['cache']);
}
if ($file) {
return $this->_renderElement($file, $data, $options);
}
if (empty($options['ignoreMissing'])) {
list ($plugin, $name) = pluginSplit($name, true);
$name = str_replace('/', DIRECTORY_SEPARATOR, $name);
$file = $plugin . static::NAME_ELEMENT . DIRECTORY_SEPARATOR . $name . $this->_ext;
throw new MissingElementException([$file]);
}
} | php | public function element($name, array $data = [], array $options = [])
{
$options += ['callbacks' => false, 'cache' => null, 'plugin' => null];
if (isset($options['cache'])) {
$options['cache'] = $this->_elementCache($name, $data, $options);
}
$pluginCheck = $options['plugin'] !== false;
$file = $this->_getElementFileName($name, $pluginCheck);
if ($file && $options['cache']) {
return $this->cache(function () use ($file, $data, $options) {
echo $this->_renderElement($file, $data, $options);
}, $options['cache']);
}
if ($file) {
return $this->_renderElement($file, $data, $options);
}
if (empty($options['ignoreMissing'])) {
list ($plugin, $name) = pluginSplit($name, true);
$name = str_replace('/', DIRECTORY_SEPARATOR, $name);
$file = $plugin . static::NAME_ELEMENT . DIRECTORY_SEPARATOR . $name . $this->_ext;
throw new MissingElementException([$file]);
}
} | [
"public",
"function",
"element",
"(",
"$",
"name",
",",
"array",
"$",
"data",
"=",
"[",
"]",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"+=",
"[",
"'callbacks'",
"=>",
"false",
",",
"'cache'",
"=>",
"null",
",",
"'plugin'",
"=>",
"null",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'cache'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'cache'",
"]",
"=",
"$",
"this",
"->",
"_elementCache",
"(",
"$",
"name",
",",
"$",
"data",
",",
"$",
"options",
")",
";",
"}",
"$",
"pluginCheck",
"=",
"$",
"options",
"[",
"'plugin'",
"]",
"!==",
"false",
";",
"$",
"file",
"=",
"$",
"this",
"->",
"_getElementFileName",
"(",
"$",
"name",
",",
"$",
"pluginCheck",
")",
";",
"if",
"(",
"$",
"file",
"&&",
"$",
"options",
"[",
"'cache'",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"cache",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"file",
",",
"$",
"data",
",",
"$",
"options",
")",
"{",
"echo",
"$",
"this",
"->",
"_renderElement",
"(",
"$",
"file",
",",
"$",
"data",
",",
"$",
"options",
")",
";",
"}",
",",
"$",
"options",
"[",
"'cache'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"file",
")",
"{",
"return",
"$",
"this",
"->",
"_renderElement",
"(",
"$",
"file",
",",
"$",
"data",
",",
"$",
"options",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'ignoreMissing'",
"]",
")",
")",
"{",
"list",
"(",
"$",
"plugin",
",",
"$",
"name",
")",
"=",
"pluginSplit",
"(",
"$",
"name",
",",
"true",
")",
";",
"$",
"name",
"=",
"str_replace",
"(",
"'/'",
",",
"DIRECTORY_SEPARATOR",
",",
"$",
"name",
")",
";",
"$",
"file",
"=",
"$",
"plugin",
".",
"static",
"::",
"NAME_ELEMENT",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"name",
".",
"$",
"this",
"->",
"_ext",
";",
"throw",
"new",
"MissingElementException",
"(",
"[",
"$",
"file",
"]",
")",
";",
"}",
"}"
] | Renders a piece of PHP with provided parameters and returns HTML, XML, or any other string.
This realizes the concept of Elements, (or "partial layouts") and the $params array is used to send
data to be used in the element. Elements can be cached improving performance by using the `cache` option.
@param string $name Name of template file in the /src/Template/Element/ folder,
or `MyPlugin.template` to use the template element from MyPlugin. If the element
is not found in the plugin, the normal view path cascade will be searched.
@param array $data Array of data to be made available to the rendered view (i.e. the Element)
@param array $options Array of options. Possible keys are:
- `cache` - Can either be `true`, to enable caching using the config in View::$elementCache. Or an array
If an array, the following keys can be used:
- `config` - Used to store the cached element in a custom cache configuration.
- `key` - Used to define the key used in the Cache::write(). It will be prefixed with `element_`
- `callbacks` - Set to true to fire beforeRender and afterRender helper callbacks for this element.
Defaults to false.
- `ignoreMissing` - Used to allow missing elements. Set to true to not throw exceptions.
- `plugin` - setting to false will force to use the application's element from plugin templates, when the
plugin has element with same name. Defaults to true
@return string Rendered Element
@throws \Cake\View\Exception\MissingElementException When an element is missing and `ignoreMissing`
is false. | [
"Renders",
"a",
"piece",
"of",
"PHP",
"with",
"provided",
"parameters",
"and",
"returns",
"HTML",
"XML",
"or",
"any",
"other",
"string",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/View.php#L768-L792 |
211,469 | cakephp/cakephp | src/View/View.php | View.cache | public function cache(callable $block, array $options = [])
{
$options += ['key' => '', 'config' => $this->elementCache];
if (empty($options['key'])) {
throw new RuntimeException('Cannot cache content with an empty key');
}
$result = Cache::read($options['key'], $options['config']);
if ($result) {
return $result;
}
ob_start();
$block();
$result = ob_get_clean();
Cache::write($options['key'], $result, $options['config']);
return $result;
} | php | public function cache(callable $block, array $options = [])
{
$options += ['key' => '', 'config' => $this->elementCache];
if (empty($options['key'])) {
throw new RuntimeException('Cannot cache content with an empty key');
}
$result = Cache::read($options['key'], $options['config']);
if ($result) {
return $result;
}
ob_start();
$block();
$result = ob_get_clean();
Cache::write($options['key'], $result, $options['config']);
return $result;
} | [
"public",
"function",
"cache",
"(",
"callable",
"$",
"block",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"+=",
"[",
"'key'",
"=>",
"''",
",",
"'config'",
"=>",
"$",
"this",
"->",
"elementCache",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'key'",
"]",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Cannot cache content with an empty key'",
")",
";",
"}",
"$",
"result",
"=",
"Cache",
"::",
"read",
"(",
"$",
"options",
"[",
"'key'",
"]",
",",
"$",
"options",
"[",
"'config'",
"]",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"return",
"$",
"result",
";",
"}",
"ob_start",
"(",
")",
";",
"$",
"block",
"(",
")",
";",
"$",
"result",
"=",
"ob_get_clean",
"(",
")",
";",
"Cache",
"::",
"write",
"(",
"$",
"options",
"[",
"'key'",
"]",
",",
"$",
"result",
",",
"$",
"options",
"[",
"'config'",
"]",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Create a cached block of view logic.
This allows you to cache a block of view output into the cache
defined in `elementCache`.
This method will attempt to read the cache first. If the cache
is empty, the $block will be run and the output stored.
@param callable $block The block of code that you want to cache the output of.
@param array $options The options defining the cache key etc.
@return string The rendered content.
@throws \RuntimeException When $options is lacking a 'key' option. | [
"Create",
"a",
"cached",
"block",
"of",
"view",
"logic",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/View.php#L808-L825 |
211,470 | cakephp/cakephp | src/View/View.php | View.append | public function append($name, $value = null)
{
$this->Blocks->concat($name, $value);
return $this;
} | php | public function append($name, $value = null)
{
$this->Blocks->concat($name, $value);
return $this;
} | [
"public",
"function",
"append",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"Blocks",
"->",
"concat",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Append to an existing or new block.
Appending to a new block will create the block.
@param string $name Name of the block
@param mixed $value The content for the block. Value will be type cast
to string.
@return $this
@see \Cake\View\ViewBlock::concat() | [
"Append",
"to",
"an",
"existing",
"or",
"new",
"block",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/View.php#L1013-L1018 |
211,471 | cakephp/cakephp | src/View/View.php | View.prepend | public function prepend($name, $value)
{
$this->Blocks->concat($name, $value, ViewBlock::PREPEND);
return $this;
} | php | public function prepend($name, $value)
{
$this->Blocks->concat($name, $value, ViewBlock::PREPEND);
return $this;
} | [
"public",
"function",
"prepend",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"Blocks",
"->",
"concat",
"(",
"$",
"name",
",",
"$",
"value",
",",
"ViewBlock",
"::",
"PREPEND",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Prepend to an existing or new block.
Prepending to a new block will create the block.
@param string $name Name of the block
@param mixed $value The content for the block. Value will be type cast
to string.
@return $this
@see \Cake\View\ViewBlock::concat() | [
"Prepend",
"to",
"an",
"existing",
"or",
"new",
"block",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/View.php#L1031-L1036 |
211,472 | cakephp/cakephp | src/View/View.php | View.uuid | public function uuid($object, $url)
{
deprecationWarning('View::uuid() is deprecated and will be removed in 4.0.0.');
$c = 1;
$url = Router::url($url);
$hash = $object . substr(md5($object . $url), 0, 10);
while (in_array($hash, $this->uuids)) {
$hash = $object . substr(md5($object . $url . $c), 0, 10);
$c++;
}
$this->uuids[] = $hash;
return $hash;
} | php | public function uuid($object, $url)
{
deprecationWarning('View::uuid() is deprecated and will be removed in 4.0.0.');
$c = 1;
$url = Router::url($url);
$hash = $object . substr(md5($object . $url), 0, 10);
while (in_array($hash, $this->uuids)) {
$hash = $object . substr(md5($object . $url . $c), 0, 10);
$c++;
}
$this->uuids[] = $hash;
return $hash;
} | [
"public",
"function",
"uuid",
"(",
"$",
"object",
",",
"$",
"url",
")",
"{",
"deprecationWarning",
"(",
"'View::uuid() is deprecated and will be removed in 4.0.0.'",
")",
";",
"$",
"c",
"=",
"1",
";",
"$",
"url",
"=",
"Router",
"::",
"url",
"(",
"$",
"url",
")",
";",
"$",
"hash",
"=",
"$",
"object",
".",
"substr",
"(",
"md5",
"(",
"$",
"object",
".",
"$",
"url",
")",
",",
"0",
",",
"10",
")",
";",
"while",
"(",
"in_array",
"(",
"$",
"hash",
",",
"$",
"this",
"->",
"uuids",
")",
")",
"{",
"$",
"hash",
"=",
"$",
"object",
".",
"substr",
"(",
"md5",
"(",
"$",
"object",
".",
"$",
"url",
".",
"$",
"c",
")",
",",
"0",
",",
"10",
")",
";",
"$",
"c",
"++",
";",
"}",
"$",
"this",
"->",
"uuids",
"[",
"]",
"=",
"$",
"hash",
";",
"return",
"$",
"hash",
";",
"}"
] | Generates a unique, non-random DOM ID for an object, based on the object type and the target URL.
@param string $object Type of object, i.e. 'form' or 'link'
@param string $url The object's target URL
@return string
@deprecated 3.7.0 This method is deprecated and will be removed in 4.0.0. | [
"Generates",
"a",
"unique",
"non",
"-",
"random",
"DOM",
"ID",
"for",
"an",
"object",
"based",
"on",
"the",
"object",
"type",
"and",
"the",
"target",
"URL",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/View.php#L1163-L1177 |
211,473 | cakephp/cakephp | src/View/View.php | View.loadHelpers | public function loadHelpers()
{
$registry = $this->helpers();
$helpers = $registry->normalizeArray($this->helpers);
foreach ($helpers as $properties) {
$this->loadHelper($properties['class'], $properties['config']);
}
return $this;
} | php | public function loadHelpers()
{
$registry = $this->helpers();
$helpers = $registry->normalizeArray($this->helpers);
foreach ($helpers as $properties) {
$this->loadHelper($properties['class'], $properties['config']);
}
return $this;
} | [
"public",
"function",
"loadHelpers",
"(",
")",
"{",
"$",
"registry",
"=",
"$",
"this",
"->",
"helpers",
"(",
")",
";",
"$",
"helpers",
"=",
"$",
"registry",
"->",
"normalizeArray",
"(",
"$",
"this",
"->",
"helpers",
")",
";",
"foreach",
"(",
"$",
"helpers",
"as",
"$",
"properties",
")",
"{",
"$",
"this",
"->",
"loadHelper",
"(",
"$",
"properties",
"[",
"'class'",
"]",
",",
"$",
"properties",
"[",
"'config'",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Interact with the HelperRegistry to load all the helpers.
@return $this | [
"Interact",
"with",
"the",
"HelperRegistry",
"to",
"load",
"all",
"the",
"helpers",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/View.php#L1347-L1356 |
211,474 | cakephp/cakephp | src/View/View.php | View.helpers | public function helpers()
{
if ($this->_helpers === null) {
$this->_helpers = new HelperRegistry($this);
}
return $this->_helpers;
} | php | public function helpers()
{
if ($this->_helpers === null) {
$this->_helpers = new HelperRegistry($this);
}
return $this->_helpers;
} | [
"public",
"function",
"helpers",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_helpers",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_helpers",
"=",
"new",
"HelperRegistry",
"(",
"$",
"this",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_helpers",
";",
"}"
] | Get the helper registry in use by this View class.
@return \Cake\View\HelperRegistry | [
"Get",
"the",
"helper",
"registry",
"in",
"use",
"by",
"this",
"View",
"class",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/View.php#L1429-L1436 |
211,475 | cakephp/cakephp | src/View/View.php | View._checkFilePath | protected function _checkFilePath($file, $path)
{
if (strpos($file, '..') === false) {
return $file;
}
$absolute = realpath($file);
if (strpos($absolute, $path) !== 0) {
throw new InvalidArgumentException(sprintf(
'Cannot use "%s" as a template, it is not within any view template path.',
$file
));
}
return $absolute;
} | php | protected function _checkFilePath($file, $path)
{
if (strpos($file, '..') === false) {
return $file;
}
$absolute = realpath($file);
if (strpos($absolute, $path) !== 0) {
throw new InvalidArgumentException(sprintf(
'Cannot use "%s" as a template, it is not within any view template path.',
$file
));
}
return $absolute;
} | [
"protected",
"function",
"_checkFilePath",
"(",
"$",
"file",
",",
"$",
"path",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"file",
",",
"'..'",
")",
"===",
"false",
")",
"{",
"return",
"$",
"file",
";",
"}",
"$",
"absolute",
"=",
"realpath",
"(",
"$",
"file",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"absolute",
",",
"$",
"path",
")",
"!==",
"0",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Cannot use \"%s\" as a template, it is not within any view template path.'",
",",
"$",
"file",
")",
")",
";",
"}",
"return",
"$",
"absolute",
";",
"}"
] | Check that a view file path does not go outside of the defined template paths.
Only paths that contain `..` will be checked, as they are the ones most likely to
have the ability to resolve to files outside of the template paths.
@param string $file The path to the template file.
@param string $path Base path that $file should be inside of.
@return string The file path
@throws \InvalidArgumentException | [
"Check",
"that",
"a",
"view",
"file",
"path",
"does",
"not",
"go",
"outside",
"of",
"the",
"defined",
"template",
"paths",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/View.php#L1607-L1621 |
211,476 | cakephp/cakephp | src/View/View.php | View._getLayoutFileName | protected function _getLayoutFileName($name = null)
{
if ($name === null) {
$name = $this->layout;
}
$subDir = null;
if ($this->layoutPath) {
$subDir = $this->layoutPath . DIRECTORY_SEPARATOR;
}
list($plugin, $name) = $this->pluginSplit($name);
$layoutPaths = $this->_getSubPaths('Layout' . DIRECTORY_SEPARATOR . $subDir);
foreach ($this->_paths($plugin) as $path) {
foreach ($layoutPaths as $layoutPath) {
$currentPath = $path . $layoutPath;
if (file_exists($currentPath . $name . $this->_ext)) {
return $this->_checkFilePath($currentPath . $name . $this->_ext, $currentPath);
}
}
}
throw new MissingLayoutException([
'file' => $layoutPaths[0] . $name . $this->_ext
]);
} | php | protected function _getLayoutFileName($name = null)
{
if ($name === null) {
$name = $this->layout;
}
$subDir = null;
if ($this->layoutPath) {
$subDir = $this->layoutPath . DIRECTORY_SEPARATOR;
}
list($plugin, $name) = $this->pluginSplit($name);
$layoutPaths = $this->_getSubPaths('Layout' . DIRECTORY_SEPARATOR . $subDir);
foreach ($this->_paths($plugin) as $path) {
foreach ($layoutPaths as $layoutPath) {
$currentPath = $path . $layoutPath;
if (file_exists($currentPath . $name . $this->_ext)) {
return $this->_checkFilePath($currentPath . $name . $this->_ext, $currentPath);
}
}
}
throw new MissingLayoutException([
'file' => $layoutPaths[0] . $name . $this->_ext
]);
} | [
"protected",
"function",
"_getLayoutFileName",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"name",
"===",
"null",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"layout",
";",
"}",
"$",
"subDir",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"layoutPath",
")",
"{",
"$",
"subDir",
"=",
"$",
"this",
"->",
"layoutPath",
".",
"DIRECTORY_SEPARATOR",
";",
"}",
"list",
"(",
"$",
"plugin",
",",
"$",
"name",
")",
"=",
"$",
"this",
"->",
"pluginSplit",
"(",
"$",
"name",
")",
";",
"$",
"layoutPaths",
"=",
"$",
"this",
"->",
"_getSubPaths",
"(",
"'Layout'",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"subDir",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"_paths",
"(",
"$",
"plugin",
")",
"as",
"$",
"path",
")",
"{",
"foreach",
"(",
"$",
"layoutPaths",
"as",
"$",
"layoutPath",
")",
"{",
"$",
"currentPath",
"=",
"$",
"path",
".",
"$",
"layoutPath",
";",
"if",
"(",
"file_exists",
"(",
"$",
"currentPath",
".",
"$",
"name",
".",
"$",
"this",
"->",
"_ext",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_checkFilePath",
"(",
"$",
"currentPath",
".",
"$",
"name",
".",
"$",
"this",
"->",
"_ext",
",",
"$",
"currentPath",
")",
";",
"}",
"}",
"}",
"throw",
"new",
"MissingLayoutException",
"(",
"[",
"'file'",
"=>",
"$",
"layoutPaths",
"[",
"0",
"]",
".",
"$",
"name",
".",
"$",
"this",
"->",
"_ext",
"]",
")",
";",
"}"
] | Returns layout filename for this template as a string.
@param string|null $name The name of the layout to find.
@return string Filename for layout file (.ctp).
@throws \Cake\View\Exception\MissingLayoutException when a layout cannot be located | [
"Returns",
"layout",
"filename",
"for",
"this",
"template",
"as",
"a",
"string",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/View.php#L1654-L1679 |
211,477 | cakephp/cakephp | src/View/View.php | View._getElementFileName | protected function _getElementFileName($name, $pluginCheck = true)
{
list($plugin, $name) = $this->pluginSplit($name, $pluginCheck);
$paths = $this->_paths($plugin);
$elementPaths = $this->_getSubPaths(static::NAME_ELEMENT);
foreach ($paths as $path) {
foreach ($elementPaths as $elementPath) {
if (file_exists($path . $elementPath . DIRECTORY_SEPARATOR . $name . $this->_ext)) {
return $path . $elementPath . DIRECTORY_SEPARATOR . $name . $this->_ext;
}
}
}
return false;
} | php | protected function _getElementFileName($name, $pluginCheck = true)
{
list($plugin, $name) = $this->pluginSplit($name, $pluginCheck);
$paths = $this->_paths($plugin);
$elementPaths = $this->_getSubPaths(static::NAME_ELEMENT);
foreach ($paths as $path) {
foreach ($elementPaths as $elementPath) {
if (file_exists($path . $elementPath . DIRECTORY_SEPARATOR . $name . $this->_ext)) {
return $path . $elementPath . DIRECTORY_SEPARATOR . $name . $this->_ext;
}
}
}
return false;
} | [
"protected",
"function",
"_getElementFileName",
"(",
"$",
"name",
",",
"$",
"pluginCheck",
"=",
"true",
")",
"{",
"list",
"(",
"$",
"plugin",
",",
"$",
"name",
")",
"=",
"$",
"this",
"->",
"pluginSplit",
"(",
"$",
"name",
",",
"$",
"pluginCheck",
")",
";",
"$",
"paths",
"=",
"$",
"this",
"->",
"_paths",
"(",
"$",
"plugin",
")",
";",
"$",
"elementPaths",
"=",
"$",
"this",
"->",
"_getSubPaths",
"(",
"static",
"::",
"NAME_ELEMENT",
")",
";",
"foreach",
"(",
"$",
"paths",
"as",
"$",
"path",
")",
"{",
"foreach",
"(",
"$",
"elementPaths",
"as",
"$",
"elementPath",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"path",
".",
"$",
"elementPath",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"name",
".",
"$",
"this",
"->",
"_ext",
")",
")",
"{",
"return",
"$",
"path",
".",
"$",
"elementPath",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"name",
".",
"$",
"this",
"->",
"_ext",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Finds an element filename, returns false on failure.
@param string $name The name of the element to find.
@param bool $pluginCheck - if false will ignore the request's plugin if parsed plugin is not loaded
@return string|false Either a string to the element filename or false when one can't be found. | [
"Finds",
"an",
"element",
"filename",
"returns",
"false",
"on",
"failure",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/View.php#L1688-L1704 |
211,478 | cakephp/cakephp | src/View/View.php | View._paths | protected function _paths($plugin = null, $cached = true)
{
if ($cached === true) {
if ($plugin === null && !empty($this->_paths)) {
return $this->_paths;
}
if ($plugin !== null && isset($this->_pathsForPlugin[$plugin])) {
return $this->_pathsForPlugin[$plugin];
}
}
$templatePaths = App::path(static::NAME_TEMPLATE);
$pluginPaths = $themePaths = [];
if (!empty($plugin)) {
for ($i = 0, $count = count($templatePaths); $i < $count; $i++) {
$pluginPaths[] = $templatePaths[$i] . 'Plugin' . DIRECTORY_SEPARATOR . $plugin . DIRECTORY_SEPARATOR;
}
$pluginPaths = array_merge($pluginPaths, App::path(static::NAME_TEMPLATE, $plugin));
}
if (!empty($this->theme)) {
$themePaths = App::path(static::NAME_TEMPLATE, Inflector::camelize($this->theme));
if ($plugin) {
for ($i = 0, $count = count($themePaths); $i < $count; $i++) {
array_unshift($themePaths, $themePaths[$i] . 'Plugin' . DIRECTORY_SEPARATOR . $plugin . DIRECTORY_SEPARATOR);
}
}
}
$paths = array_merge(
$themePaths,
$pluginPaths,
$templatePaths,
[dirname(__DIR__) . DIRECTORY_SEPARATOR . static::NAME_TEMPLATE . DIRECTORY_SEPARATOR]
);
if ($plugin !== null) {
return $this->_pathsForPlugin[$plugin] = $paths;
}
return $this->_paths = $paths;
} | php | protected function _paths($plugin = null, $cached = true)
{
if ($cached === true) {
if ($plugin === null && !empty($this->_paths)) {
return $this->_paths;
}
if ($plugin !== null && isset($this->_pathsForPlugin[$plugin])) {
return $this->_pathsForPlugin[$plugin];
}
}
$templatePaths = App::path(static::NAME_TEMPLATE);
$pluginPaths = $themePaths = [];
if (!empty($plugin)) {
for ($i = 0, $count = count($templatePaths); $i < $count; $i++) {
$pluginPaths[] = $templatePaths[$i] . 'Plugin' . DIRECTORY_SEPARATOR . $plugin . DIRECTORY_SEPARATOR;
}
$pluginPaths = array_merge($pluginPaths, App::path(static::NAME_TEMPLATE, $plugin));
}
if (!empty($this->theme)) {
$themePaths = App::path(static::NAME_TEMPLATE, Inflector::camelize($this->theme));
if ($plugin) {
for ($i = 0, $count = count($themePaths); $i < $count; $i++) {
array_unshift($themePaths, $themePaths[$i] . 'Plugin' . DIRECTORY_SEPARATOR . $plugin . DIRECTORY_SEPARATOR);
}
}
}
$paths = array_merge(
$themePaths,
$pluginPaths,
$templatePaths,
[dirname(__DIR__) . DIRECTORY_SEPARATOR . static::NAME_TEMPLATE . DIRECTORY_SEPARATOR]
);
if ($plugin !== null) {
return $this->_pathsForPlugin[$plugin] = $paths;
}
return $this->_paths = $paths;
} | [
"protected",
"function",
"_paths",
"(",
"$",
"plugin",
"=",
"null",
",",
"$",
"cached",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"cached",
"===",
"true",
")",
"{",
"if",
"(",
"$",
"plugin",
"===",
"null",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"_paths",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_paths",
";",
"}",
"if",
"(",
"$",
"plugin",
"!==",
"null",
"&&",
"isset",
"(",
"$",
"this",
"->",
"_pathsForPlugin",
"[",
"$",
"plugin",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_pathsForPlugin",
"[",
"$",
"plugin",
"]",
";",
"}",
"}",
"$",
"templatePaths",
"=",
"App",
"::",
"path",
"(",
"static",
"::",
"NAME_TEMPLATE",
")",
";",
"$",
"pluginPaths",
"=",
"$",
"themePaths",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"plugin",
")",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"count",
"=",
"count",
"(",
"$",
"templatePaths",
")",
";",
"$",
"i",
"<",
"$",
"count",
";",
"$",
"i",
"++",
")",
"{",
"$",
"pluginPaths",
"[",
"]",
"=",
"$",
"templatePaths",
"[",
"$",
"i",
"]",
".",
"'Plugin'",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"plugin",
".",
"DIRECTORY_SEPARATOR",
";",
"}",
"$",
"pluginPaths",
"=",
"array_merge",
"(",
"$",
"pluginPaths",
",",
"App",
"::",
"path",
"(",
"static",
"::",
"NAME_TEMPLATE",
",",
"$",
"plugin",
")",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"theme",
")",
")",
"{",
"$",
"themePaths",
"=",
"App",
"::",
"path",
"(",
"static",
"::",
"NAME_TEMPLATE",
",",
"Inflector",
"::",
"camelize",
"(",
"$",
"this",
"->",
"theme",
")",
")",
";",
"if",
"(",
"$",
"plugin",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"count",
"=",
"count",
"(",
"$",
"themePaths",
")",
";",
"$",
"i",
"<",
"$",
"count",
";",
"$",
"i",
"++",
")",
"{",
"array_unshift",
"(",
"$",
"themePaths",
",",
"$",
"themePaths",
"[",
"$",
"i",
"]",
".",
"'Plugin'",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"plugin",
".",
"DIRECTORY_SEPARATOR",
")",
";",
"}",
"}",
"}",
"$",
"paths",
"=",
"array_merge",
"(",
"$",
"themePaths",
",",
"$",
"pluginPaths",
",",
"$",
"templatePaths",
",",
"[",
"dirname",
"(",
"__DIR__",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"static",
"::",
"NAME_TEMPLATE",
".",
"DIRECTORY_SEPARATOR",
"]",
")",
";",
"if",
"(",
"$",
"plugin",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_pathsForPlugin",
"[",
"$",
"plugin",
"]",
"=",
"$",
"paths",
";",
"}",
"return",
"$",
"this",
"->",
"_paths",
"=",
"$",
"paths",
";",
"}"
] | Return all possible paths to find view files in order
@param string|null $plugin Optional plugin name to scan for view files.
@param bool $cached Set to false to force a refresh of view paths. Default true.
@return array paths | [
"Return",
"all",
"possible",
"paths",
"to",
"find",
"view",
"files",
"in",
"order"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/View.php#L1743-L1784 |
211,479 | cakephp/cakephp | src/View/View.php | View._elementCache | protected function _elementCache($name, $data, $options)
{
if (isset($options['cache']['key'], $options['cache']['config'])) {
$cache = $options['cache'];
$cache['key'] = 'element_' . $cache['key'];
return $cache;
}
$plugin = null;
list($plugin, $name) = $this->pluginSplit($name);
$underscored = null;
if ($plugin) {
$underscored = Inflector::underscore($plugin);
}
$cache = $options['cache'];
unset($options['cache'], $options['callbacks'], $options['plugin']);
$keys = array_merge(
[$underscored, $name],
array_keys($options),
array_keys($data)
);
$config = [
'config' => $this->elementCache,
'key' => implode('_', $keys)
];
if (is_array($cache)) {
$defaults = [
'config' => $this->elementCache,
'key' => $config['key']
];
$config = $cache + $defaults;
}
$config['key'] = 'element_' . $config['key'];
return $config;
} | php | protected function _elementCache($name, $data, $options)
{
if (isset($options['cache']['key'], $options['cache']['config'])) {
$cache = $options['cache'];
$cache['key'] = 'element_' . $cache['key'];
return $cache;
}
$plugin = null;
list($plugin, $name) = $this->pluginSplit($name);
$underscored = null;
if ($plugin) {
$underscored = Inflector::underscore($plugin);
}
$cache = $options['cache'];
unset($options['cache'], $options['callbacks'], $options['plugin']);
$keys = array_merge(
[$underscored, $name],
array_keys($options),
array_keys($data)
);
$config = [
'config' => $this->elementCache,
'key' => implode('_', $keys)
];
if (is_array($cache)) {
$defaults = [
'config' => $this->elementCache,
'key' => $config['key']
];
$config = $cache + $defaults;
}
$config['key'] = 'element_' . $config['key'];
return $config;
} | [
"protected",
"function",
"_elementCache",
"(",
"$",
"name",
",",
"$",
"data",
",",
"$",
"options",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'cache'",
"]",
"[",
"'key'",
"]",
",",
"$",
"options",
"[",
"'cache'",
"]",
"[",
"'config'",
"]",
")",
")",
"{",
"$",
"cache",
"=",
"$",
"options",
"[",
"'cache'",
"]",
";",
"$",
"cache",
"[",
"'key'",
"]",
"=",
"'element_'",
".",
"$",
"cache",
"[",
"'key'",
"]",
";",
"return",
"$",
"cache",
";",
"}",
"$",
"plugin",
"=",
"null",
";",
"list",
"(",
"$",
"plugin",
",",
"$",
"name",
")",
"=",
"$",
"this",
"->",
"pluginSplit",
"(",
"$",
"name",
")",
";",
"$",
"underscored",
"=",
"null",
";",
"if",
"(",
"$",
"plugin",
")",
"{",
"$",
"underscored",
"=",
"Inflector",
"::",
"underscore",
"(",
"$",
"plugin",
")",
";",
"}",
"$",
"cache",
"=",
"$",
"options",
"[",
"'cache'",
"]",
";",
"unset",
"(",
"$",
"options",
"[",
"'cache'",
"]",
",",
"$",
"options",
"[",
"'callbacks'",
"]",
",",
"$",
"options",
"[",
"'plugin'",
"]",
")",
";",
"$",
"keys",
"=",
"array_merge",
"(",
"[",
"$",
"underscored",
",",
"$",
"name",
"]",
",",
"array_keys",
"(",
"$",
"options",
")",
",",
"array_keys",
"(",
"$",
"data",
")",
")",
";",
"$",
"config",
"=",
"[",
"'config'",
"=>",
"$",
"this",
"->",
"elementCache",
",",
"'key'",
"=>",
"implode",
"(",
"'_'",
",",
"$",
"keys",
")",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"cache",
")",
")",
"{",
"$",
"defaults",
"=",
"[",
"'config'",
"=>",
"$",
"this",
"->",
"elementCache",
",",
"'key'",
"=>",
"$",
"config",
"[",
"'key'",
"]",
"]",
";",
"$",
"config",
"=",
"$",
"cache",
"+",
"$",
"defaults",
";",
"}",
"$",
"config",
"[",
"'key'",
"]",
"=",
"'element_'",
".",
"$",
"config",
"[",
"'key'",
"]",
";",
"return",
"$",
"config",
";",
"}"
] | Generate the cache configuration options for an element.
@param string $name Element name
@param array $data Data
@param array $options Element options
@return array Element Cache configuration. | [
"Generate",
"the",
"cache",
"configuration",
"options",
"for",
"an",
"element",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/View.php#L1794-L1832 |
211,480 | cakephp/cakephp | src/View/View.php | View._renderElement | protected function _renderElement($file, $data, $options)
{
$current = $this->_current;
$restore = $this->_currentType;
$this->_currentType = static::TYPE_ELEMENT;
if ($options['callbacks']) {
$this->dispatchEvent('View.beforeRender', [$file]);
}
$element = $this->_render($file, array_merge($this->viewVars, $data));
if ($options['callbacks']) {
$this->dispatchEvent('View.afterRender', [$file, $element]);
}
$this->_currentType = $restore;
$this->_current = $current;
return $element;
} | php | protected function _renderElement($file, $data, $options)
{
$current = $this->_current;
$restore = $this->_currentType;
$this->_currentType = static::TYPE_ELEMENT;
if ($options['callbacks']) {
$this->dispatchEvent('View.beforeRender', [$file]);
}
$element = $this->_render($file, array_merge($this->viewVars, $data));
if ($options['callbacks']) {
$this->dispatchEvent('View.afterRender', [$file, $element]);
}
$this->_currentType = $restore;
$this->_current = $current;
return $element;
} | [
"protected",
"function",
"_renderElement",
"(",
"$",
"file",
",",
"$",
"data",
",",
"$",
"options",
")",
"{",
"$",
"current",
"=",
"$",
"this",
"->",
"_current",
";",
"$",
"restore",
"=",
"$",
"this",
"->",
"_currentType",
";",
"$",
"this",
"->",
"_currentType",
"=",
"static",
"::",
"TYPE_ELEMENT",
";",
"if",
"(",
"$",
"options",
"[",
"'callbacks'",
"]",
")",
"{",
"$",
"this",
"->",
"dispatchEvent",
"(",
"'View.beforeRender'",
",",
"[",
"$",
"file",
"]",
")",
";",
"}",
"$",
"element",
"=",
"$",
"this",
"->",
"_render",
"(",
"$",
"file",
",",
"array_merge",
"(",
"$",
"this",
"->",
"viewVars",
",",
"$",
"data",
")",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'callbacks'",
"]",
")",
"{",
"$",
"this",
"->",
"dispatchEvent",
"(",
"'View.afterRender'",
",",
"[",
"$",
"file",
",",
"$",
"element",
"]",
")",
";",
"}",
"$",
"this",
"->",
"_currentType",
"=",
"$",
"restore",
";",
"$",
"this",
"->",
"_current",
"=",
"$",
"current",
";",
"return",
"$",
"element",
";",
"}"
] | Renders an element and fires the before and afterRender callbacks for it
and writes to the cache if a cache is used
@param string $file Element file path
@param array $data Data to render
@param array $options Element options
@return string
@triggers View.beforeRender $this, [$file]
@triggers View.afterRender $this, [$file, $element] | [
"Renders",
"an",
"element",
"and",
"fires",
"the",
"before",
"and",
"afterRender",
"callbacks",
"for",
"it",
"and",
"writes",
"to",
"the",
"cache",
"if",
"a",
"cache",
"is",
"used"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/View.php#L1845-L1865 |
211,481 | cakephp/cakephp | src/View/Form/ContextFactory.php | ContextFactory.createWithDefaults | public static function createWithDefaults(array $providers = [])
{
$providers = [
[
'type' => 'orm',
'callable' => function ($request, $data) {
if (is_array($data['entity']) || $data['entity'] instanceof Traversable) {
$pass = (new Collection($data['entity']))->first() !== null;
if ($pass) {
return new EntityContext($request, $data);
}
}
if ($data['entity'] instanceof EntityInterface) {
return new EntityContext($request, $data);
}
if (is_array($data['entity']) && empty($data['entity']['schema'])) {
return new EntityContext($request, $data);
}
}
],
[
'type' => 'array',
'callable' => function ($request, $data) {
if (is_array($data['entity']) && isset($data['entity']['schema'])) {
return new ArrayContext($request, $data['entity']);
}
}
],
[
'type' => 'form',
'callable' => function ($request, $data) {
if ($data['entity'] instanceof Form) {
return new FormContext($request, $data);
}
}
],
] + $providers;
return new static($providers);
} | php | public static function createWithDefaults(array $providers = [])
{
$providers = [
[
'type' => 'orm',
'callable' => function ($request, $data) {
if (is_array($data['entity']) || $data['entity'] instanceof Traversable) {
$pass = (new Collection($data['entity']))->first() !== null;
if ($pass) {
return new EntityContext($request, $data);
}
}
if ($data['entity'] instanceof EntityInterface) {
return new EntityContext($request, $data);
}
if (is_array($data['entity']) && empty($data['entity']['schema'])) {
return new EntityContext($request, $data);
}
}
],
[
'type' => 'array',
'callable' => function ($request, $data) {
if (is_array($data['entity']) && isset($data['entity']['schema'])) {
return new ArrayContext($request, $data['entity']);
}
}
],
[
'type' => 'form',
'callable' => function ($request, $data) {
if ($data['entity'] instanceof Form) {
return new FormContext($request, $data);
}
}
],
] + $providers;
return new static($providers);
} | [
"public",
"static",
"function",
"createWithDefaults",
"(",
"array",
"$",
"providers",
"=",
"[",
"]",
")",
"{",
"$",
"providers",
"=",
"[",
"[",
"'type'",
"=>",
"'orm'",
",",
"'callable'",
"=>",
"function",
"(",
"$",
"request",
",",
"$",
"data",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"data",
"[",
"'entity'",
"]",
")",
"||",
"$",
"data",
"[",
"'entity'",
"]",
"instanceof",
"Traversable",
")",
"{",
"$",
"pass",
"=",
"(",
"new",
"Collection",
"(",
"$",
"data",
"[",
"'entity'",
"]",
")",
")",
"->",
"first",
"(",
")",
"!==",
"null",
";",
"if",
"(",
"$",
"pass",
")",
"{",
"return",
"new",
"EntityContext",
"(",
"$",
"request",
",",
"$",
"data",
")",
";",
"}",
"}",
"if",
"(",
"$",
"data",
"[",
"'entity'",
"]",
"instanceof",
"EntityInterface",
")",
"{",
"return",
"new",
"EntityContext",
"(",
"$",
"request",
",",
"$",
"data",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"data",
"[",
"'entity'",
"]",
")",
"&&",
"empty",
"(",
"$",
"data",
"[",
"'entity'",
"]",
"[",
"'schema'",
"]",
")",
")",
"{",
"return",
"new",
"EntityContext",
"(",
"$",
"request",
",",
"$",
"data",
")",
";",
"}",
"}",
"]",
",",
"[",
"'type'",
"=>",
"'array'",
",",
"'callable'",
"=>",
"function",
"(",
"$",
"request",
",",
"$",
"data",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"data",
"[",
"'entity'",
"]",
")",
"&&",
"isset",
"(",
"$",
"data",
"[",
"'entity'",
"]",
"[",
"'schema'",
"]",
")",
")",
"{",
"return",
"new",
"ArrayContext",
"(",
"$",
"request",
",",
"$",
"data",
"[",
"'entity'",
"]",
")",
";",
"}",
"}",
"]",
",",
"[",
"'type'",
"=>",
"'form'",
",",
"'callable'",
"=>",
"function",
"(",
"$",
"request",
",",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"data",
"[",
"'entity'",
"]",
"instanceof",
"Form",
")",
"{",
"return",
"new",
"FormContext",
"(",
"$",
"request",
",",
"$",
"data",
")",
";",
"}",
"}",
"]",
",",
"]",
"+",
"$",
"providers",
";",
"return",
"new",
"static",
"(",
"$",
"providers",
")",
";",
"}"
] | Create factory instance with providers "array", "form" and "orm".
@param array $providers Array of provider callables. Each element should
be of form `['type' => 'a-string', 'callable' => ..]`
@return \Cake\View\Form\ContextFactory | [
"Create",
"factory",
"instance",
"with",
"providers",
"array",
"form",
"and",
"orm",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Form/ContextFactory.php#L56-L95 |
211,482 | cakephp/cakephp | src/View/Form/ContextFactory.php | ContextFactory.addProvider | public function addProvider($type, callable $check)
{
$this->providers = [$type => ['type' => $type, 'callable' => $check]]
+ $this->providers;
return $this;
} | php | public function addProvider($type, callable $check)
{
$this->providers = [$type => ['type' => $type, 'callable' => $check]]
+ $this->providers;
return $this;
} | [
"public",
"function",
"addProvider",
"(",
"$",
"type",
",",
"callable",
"$",
"check",
")",
"{",
"$",
"this",
"->",
"providers",
"=",
"[",
"$",
"type",
"=>",
"[",
"'type'",
"=>",
"$",
"type",
",",
"'callable'",
"=>",
"$",
"check",
"]",
"]",
"+",
"$",
"this",
"->",
"providers",
";",
"return",
"$",
"this",
";",
"}"
] | Add a new context type.
Form context types allow FormHelper to interact with
data providers that come from outside CakePHP. For example
if you wanted to use an alternative ORM like Doctrine you could
create and connect a new context class to allow FormHelper to
read metadata from doctrine.
@param string $type The type of context. This key
can be used to overwrite existing providers.
@param callable $check A callable that returns an object
when the form context is the correct type.
@return $this | [
"Add",
"a",
"new",
"context",
"type",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Form/ContextFactory.php#L112-L118 |
211,483 | cakephp/cakephp | src/View/Form/ContextFactory.php | ContextFactory.get | public function get(ServerRequest $request, array $data = [])
{
$data += ['entity' => null];
foreach ($this->providers as $provider) {
$check = $provider['callable'];
$context = $check($request, $data);
if ($context) {
break;
}
}
if (!isset($context)) {
$context = new NullContext($request, $data);
}
if (!($context instanceof ContextInterface)) {
throw new RuntimeException(sprintf(
'Context providers must return object implementing %s. Got "%s" instead.',
ContextInterface::class,
getTypeName($context)
));
}
return $context;
} | php | public function get(ServerRequest $request, array $data = [])
{
$data += ['entity' => null];
foreach ($this->providers as $provider) {
$check = $provider['callable'];
$context = $check($request, $data);
if ($context) {
break;
}
}
if (!isset($context)) {
$context = new NullContext($request, $data);
}
if (!($context instanceof ContextInterface)) {
throw new RuntimeException(sprintf(
'Context providers must return object implementing %s. Got "%s" instead.',
ContextInterface::class,
getTypeName($context)
));
}
return $context;
} | [
"public",
"function",
"get",
"(",
"ServerRequest",
"$",
"request",
",",
"array",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"data",
"+=",
"[",
"'entity'",
"=>",
"null",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"providers",
"as",
"$",
"provider",
")",
"{",
"$",
"check",
"=",
"$",
"provider",
"[",
"'callable'",
"]",
";",
"$",
"context",
"=",
"$",
"check",
"(",
"$",
"request",
",",
"$",
"data",
")",
";",
"if",
"(",
"$",
"context",
")",
"{",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"context",
")",
")",
"{",
"$",
"context",
"=",
"new",
"NullContext",
"(",
"$",
"request",
",",
"$",
"data",
")",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"context",
"instanceof",
"ContextInterface",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Context providers must return object implementing %s. Got \"%s\" instead.'",
",",
"ContextInterface",
"::",
"class",
",",
"getTypeName",
"(",
"$",
"context",
")",
")",
")",
";",
"}",
"return",
"$",
"context",
";",
"}"
] | Find the matching context for the data.
If no type can be matched a NullContext will be returned.
@param \Cake\Http\ServerRequest $request Request instance.
@param array $data The data to get a context provider for.
@return \Cake\View\Form\ContextInterface Context provider.
@throws \RuntimeException when the context class does not implement the
ContextInterface. | [
"Find",
"the",
"matching",
"context",
"for",
"the",
"data",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Form/ContextFactory.php#L131-L154 |
211,484 | cakephp/cakephp | src/Database/Schema/TableSchema.php | TableSchema.hasAutoincrement | public function hasAutoincrement()
{
foreach ($this->_columns as $column) {
if (isset($column['autoIncrement']) && $column['autoIncrement']) {
return true;
}
}
return false;
} | php | public function hasAutoincrement()
{
foreach ($this->_columns as $column) {
if (isset($column['autoIncrement']) && $column['autoIncrement']) {
return true;
}
}
return false;
} | [
"public",
"function",
"hasAutoincrement",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_columns",
"as",
"$",
"column",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"column",
"[",
"'autoIncrement'",
"]",
")",
"&&",
"$",
"column",
"[",
"'autoIncrement'",
"]",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Check whether or not a table has an autoIncrement column defined.
@return bool | [
"Check",
"whether",
"or",
"not",
"a",
"table",
"has",
"an",
"autoIncrement",
"column",
"defined",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Schema/TableSchema.php#L648-L657 |
211,485 | cakephp/cakephp | src/Shell/SchemaCacheShell.php | SchemaCacheShell._getSchemaCache | protected function _getSchemaCache()
{
try {
$connection = ConnectionManager::get($this->params['connection']);
return new SchemaCache($connection);
} catch (RuntimeException $e) {
$this->abort($e->getMessage());
}
} | php | protected function _getSchemaCache()
{
try {
$connection = ConnectionManager::get($this->params['connection']);
return new SchemaCache($connection);
} catch (RuntimeException $e) {
$this->abort($e->getMessage());
}
} | [
"protected",
"function",
"_getSchemaCache",
"(",
")",
"{",
"try",
"{",
"$",
"connection",
"=",
"ConnectionManager",
"::",
"get",
"(",
"$",
"this",
"->",
"params",
"[",
"'connection'",
"]",
")",
";",
"return",
"new",
"SchemaCache",
"(",
"$",
"connection",
")",
";",
"}",
"catch",
"(",
"RuntimeException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"abort",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | Gets the Schema Cache instance
@return \Cake\Database\SchemaCache | [
"Gets",
"the",
"Schema",
"Cache",
"instance"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/SchemaCacheShell.php#L79-L88 |
211,486 | cakephp/cakephp | src/Cache/CacheEngine.php | CacheEngine.init | public function init(array $config = [])
{
$this->setConfig($config);
if (!empty($this->_config['groups'])) {
sort($this->_config['groups']);
$this->_groupPrefix = str_repeat('%s_', count($this->_config['groups']));
}
if (!is_numeric($this->_config['duration'])) {
$this->_config['duration'] = strtotime($this->_config['duration']) - time();
}
return true;
} | php | public function init(array $config = [])
{
$this->setConfig($config);
if (!empty($this->_config['groups'])) {
sort($this->_config['groups']);
$this->_groupPrefix = str_repeat('%s_', count($this->_config['groups']));
}
if (!is_numeric($this->_config['duration'])) {
$this->_config['duration'] = strtotime($this->_config['duration']) - time();
}
return true;
} | [
"public",
"function",
"init",
"(",
"array",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"setConfig",
"(",
"$",
"config",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_config",
"[",
"'groups'",
"]",
")",
")",
"{",
"sort",
"(",
"$",
"this",
"->",
"_config",
"[",
"'groups'",
"]",
")",
";",
"$",
"this",
"->",
"_groupPrefix",
"=",
"str_repeat",
"(",
"'%s_'",
",",
"count",
"(",
"$",
"this",
"->",
"_config",
"[",
"'groups'",
"]",
")",
")",
";",
"}",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"this",
"->",
"_config",
"[",
"'duration'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_config",
"[",
"'duration'",
"]",
"=",
"strtotime",
"(",
"$",
"this",
"->",
"_config",
"[",
"'duration'",
"]",
")",
"-",
"time",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Initialize the cache engine
Called automatically by the cache frontend. Merge the runtime config with the defaults
before use.
@param array $config Associative array of parameters for the engine
@return bool True if the engine has been successfully initialized, false if not | [
"Initialize",
"the",
"cache",
"engine"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/CacheEngine.php#L68-L81 |
211,487 | cakephp/cakephp | src/Cache/CacheEngine.php | CacheEngine.writeMany | public function writeMany($data)
{
$return = [];
foreach ($data as $key => $value) {
$return[$key] = $this->write($key, $value);
}
return $return;
} | php | public function writeMany($data)
{
$return = [];
foreach ($data as $key => $value) {
$return[$key] = $this->write($key, $value);
}
return $return;
} | [
"public",
"function",
"writeMany",
"(",
"$",
"data",
")",
"{",
"$",
"return",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"return",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"write",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"return",
";",
"}"
] | Write data for many keys into cache
@param array $data An array of data to be stored in the cache
@return array of bools for each key provided, true if the data was successfully cached, false on failure | [
"Write",
"data",
"for",
"many",
"keys",
"into",
"cache"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/CacheEngine.php#L110-L118 |
211,488 | cakephp/cakephp | src/Cache/CacheEngine.php | CacheEngine._key | protected function _key($key)
{
$key = $this->key($key);
if ($key === false) {
throw new InvalidArgumentException('An empty value is not valid as a cache key');
}
return $this->_config['prefix'] . $key;
} | php | protected function _key($key)
{
$key = $this->key($key);
if ($key === false) {
throw new InvalidArgumentException('An empty value is not valid as a cache key');
}
return $this->_config['prefix'] . $key;
} | [
"protected",
"function",
"_key",
"(",
"$",
"key",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"key",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"key",
"===",
"false",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'An empty value is not valid as a cache key'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_config",
"[",
"'prefix'",
"]",
".",
"$",
"key",
";",
"}"
] | Generates a safe key, taking account of the configured key prefix
@param string $key the key passed over
@return mixed string $key or false
@throws \InvalidArgumentException If key's value is empty | [
"Generates",
"a",
"safe",
"key",
"taking",
"account",
"of",
"the",
"configured",
"key",
"prefix"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/CacheEngine.php#L270-L278 |
211,489 | cakephp/cakephp | src/Shell/I18nShell.php | I18nShell.init | public function init($language = null)
{
if (!$language) {
$language = $this->in('Please specify language code, e.g. `en`, `eng`, `en_US` etc.');
}
if (strlen($language) < 2) {
$this->abort('Invalid language code. Valid is `en`, `eng`, `en_US` etc.');
}
$this->_paths = App::path('Locale');
if ($this->param('plugin')) {
$plugin = Inflector::camelize($this->param('plugin'));
$this->_paths = App::path('Locale', $plugin);
}
$response = $this->in('What folder?', null, rtrim($this->_paths[0], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR);
$sourceFolder = rtrim($response, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
$targetFolder = $sourceFolder . $language . DIRECTORY_SEPARATOR;
if (!is_dir($targetFolder)) {
mkdir($targetFolder, 0775, true);
}
$count = 0;
$iterator = new DirectoryIterator($sourceFolder);
foreach ($iterator as $fileinfo) {
if (!$fileinfo->isFile()) {
continue;
}
$filename = $fileinfo->getFilename();
$newFilename = $fileinfo->getBasename('.pot');
$newFilename .= '.po';
$this->createFile($targetFolder . $newFilename, file_get_contents($sourceFolder . $filename));
$count++;
}
$this->out('Generated ' . $count . ' PO files in ' . $targetFolder);
} | php | public function init($language = null)
{
if (!$language) {
$language = $this->in('Please specify language code, e.g. `en`, `eng`, `en_US` etc.');
}
if (strlen($language) < 2) {
$this->abort('Invalid language code. Valid is `en`, `eng`, `en_US` etc.');
}
$this->_paths = App::path('Locale');
if ($this->param('plugin')) {
$plugin = Inflector::camelize($this->param('plugin'));
$this->_paths = App::path('Locale', $plugin);
}
$response = $this->in('What folder?', null, rtrim($this->_paths[0], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR);
$sourceFolder = rtrim($response, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
$targetFolder = $sourceFolder . $language . DIRECTORY_SEPARATOR;
if (!is_dir($targetFolder)) {
mkdir($targetFolder, 0775, true);
}
$count = 0;
$iterator = new DirectoryIterator($sourceFolder);
foreach ($iterator as $fileinfo) {
if (!$fileinfo->isFile()) {
continue;
}
$filename = $fileinfo->getFilename();
$newFilename = $fileinfo->getBasename('.pot');
$newFilename .= '.po';
$this->createFile($targetFolder . $newFilename, file_get_contents($sourceFolder . $filename));
$count++;
}
$this->out('Generated ' . $count . ' PO files in ' . $targetFolder);
} | [
"public",
"function",
"init",
"(",
"$",
"language",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"language",
")",
"{",
"$",
"language",
"=",
"$",
"this",
"->",
"in",
"(",
"'Please specify language code, e.g. `en`, `eng`, `en_US` etc.'",
")",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"language",
")",
"<",
"2",
")",
"{",
"$",
"this",
"->",
"abort",
"(",
"'Invalid language code. Valid is `en`, `eng`, `en_US` etc.'",
")",
";",
"}",
"$",
"this",
"->",
"_paths",
"=",
"App",
"::",
"path",
"(",
"'Locale'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"param",
"(",
"'plugin'",
")",
")",
"{",
"$",
"plugin",
"=",
"Inflector",
"::",
"camelize",
"(",
"$",
"this",
"->",
"param",
"(",
"'plugin'",
")",
")",
";",
"$",
"this",
"->",
"_paths",
"=",
"App",
"::",
"path",
"(",
"'Locale'",
",",
"$",
"plugin",
")",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"in",
"(",
"'What folder?'",
",",
"null",
",",
"rtrim",
"(",
"$",
"this",
"->",
"_paths",
"[",
"0",
"]",
",",
"DIRECTORY_SEPARATOR",
")",
".",
"DIRECTORY_SEPARATOR",
")",
";",
"$",
"sourceFolder",
"=",
"rtrim",
"(",
"$",
"response",
",",
"DIRECTORY_SEPARATOR",
")",
".",
"DIRECTORY_SEPARATOR",
";",
"$",
"targetFolder",
"=",
"$",
"sourceFolder",
".",
"$",
"language",
".",
"DIRECTORY_SEPARATOR",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"targetFolder",
")",
")",
"{",
"mkdir",
"(",
"$",
"targetFolder",
",",
"0775",
",",
"true",
")",
";",
"}",
"$",
"count",
"=",
"0",
";",
"$",
"iterator",
"=",
"new",
"DirectoryIterator",
"(",
"$",
"sourceFolder",
")",
";",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"fileinfo",
")",
"{",
"if",
"(",
"!",
"$",
"fileinfo",
"->",
"isFile",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"filename",
"=",
"$",
"fileinfo",
"->",
"getFilename",
"(",
")",
";",
"$",
"newFilename",
"=",
"$",
"fileinfo",
"->",
"getBasename",
"(",
"'.pot'",
")",
";",
"$",
"newFilename",
".=",
"'.po'",
";",
"$",
"this",
"->",
"createFile",
"(",
"$",
"targetFolder",
".",
"$",
"newFilename",
",",
"file_get_contents",
"(",
"$",
"sourceFolder",
".",
"$",
"filename",
")",
")",
";",
"$",
"count",
"++",
";",
"}",
"$",
"this",
"->",
"out",
"(",
"'Generated '",
".",
"$",
"count",
".",
"' PO files in '",
".",
"$",
"targetFolder",
")",
";",
"}"
] | Inits PO file from POT file.
@param string|null $language Language code to use.
@return void
@throws \Cake\Console\Exception\StopException | [
"Inits",
"PO",
"file",
"from",
"POT",
"file",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/I18nShell.php#L89-L126 |
211,490 | cakephp/cakephp | src/Http/Client/Adapter/Stream.php | Stream.createResponses | public function createResponses($headers, $content)
{
$indexes = $responses = [];
foreach ($headers as $i => $header) {
if (strtoupper(substr($header, 0, 5)) === 'HTTP/') {
$indexes[] = $i;
}
}
$last = count($indexes) - 1;
foreach ($indexes as $i => $start) {
$end = isset($indexes[$i + 1]) ? $indexes[$i + 1] - $start : null;
$headerSlice = array_slice($headers, $start, $end);
$body = $i == $last ? $content : '';
$responses[] = $this->_buildResponse($headerSlice, $body);
}
return $responses;
} | php | public function createResponses($headers, $content)
{
$indexes = $responses = [];
foreach ($headers as $i => $header) {
if (strtoupper(substr($header, 0, 5)) === 'HTTP/') {
$indexes[] = $i;
}
}
$last = count($indexes) - 1;
foreach ($indexes as $i => $start) {
$end = isset($indexes[$i + 1]) ? $indexes[$i + 1] - $start : null;
$headerSlice = array_slice($headers, $start, $end);
$body = $i == $last ? $content : '';
$responses[] = $this->_buildResponse($headerSlice, $body);
}
return $responses;
} | [
"public",
"function",
"createResponses",
"(",
"$",
"headers",
",",
"$",
"content",
")",
"{",
"$",
"indexes",
"=",
"$",
"responses",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"i",
"=>",
"$",
"header",
")",
"{",
"if",
"(",
"strtoupper",
"(",
"substr",
"(",
"$",
"header",
",",
"0",
",",
"5",
")",
")",
"===",
"'HTTP/'",
")",
"{",
"$",
"indexes",
"[",
"]",
"=",
"$",
"i",
";",
"}",
"}",
"$",
"last",
"=",
"count",
"(",
"$",
"indexes",
")",
"-",
"1",
";",
"foreach",
"(",
"$",
"indexes",
"as",
"$",
"i",
"=>",
"$",
"start",
")",
"{",
"$",
"end",
"=",
"isset",
"(",
"$",
"indexes",
"[",
"$",
"i",
"+",
"1",
"]",
")",
"?",
"$",
"indexes",
"[",
"$",
"i",
"+",
"1",
"]",
"-",
"$",
"start",
":",
"null",
";",
"$",
"headerSlice",
"=",
"array_slice",
"(",
"$",
"headers",
",",
"$",
"start",
",",
"$",
"end",
")",
";",
"$",
"body",
"=",
"$",
"i",
"==",
"$",
"last",
"?",
"$",
"content",
":",
"''",
";",
"$",
"responses",
"[",
"]",
"=",
"$",
"this",
"->",
"_buildResponse",
"(",
"$",
"headerSlice",
",",
"$",
"body",
")",
";",
"}",
"return",
"$",
"responses",
";",
"}"
] | Create the response list based on the headers & content
Creates one or many response objects based on the number
of redirects that occurred.
@param array $headers The list of headers from the request(s)
@param string $content The response content.
@return \Cake\Http\Client\Response[] The list of responses from the request(s) | [
"Create",
"the",
"response",
"list",
"based",
"on",
"the",
"headers",
"&",
"content"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Adapter/Stream.php#L92-L109 |
211,491 | cakephp/cakephp | src/Http/Client/Adapter/Stream.php | Stream._buildContext | protected function _buildContext(Request $request, $options)
{
$this->_buildContent($request, $options);
$this->_buildHeaders($request, $options);
$this->_buildOptions($request, $options);
$url = $request->getUri();
$scheme = parse_url($url, PHP_URL_SCHEME);
if ($scheme === 'https') {
$this->_buildSslContext($request, $options);
}
$this->_context = stream_context_create([
'http' => $this->_contextOptions,
'ssl' => $this->_sslContextOptions,
]);
} | php | protected function _buildContext(Request $request, $options)
{
$this->_buildContent($request, $options);
$this->_buildHeaders($request, $options);
$this->_buildOptions($request, $options);
$url = $request->getUri();
$scheme = parse_url($url, PHP_URL_SCHEME);
if ($scheme === 'https') {
$this->_buildSslContext($request, $options);
}
$this->_context = stream_context_create([
'http' => $this->_contextOptions,
'ssl' => $this->_sslContextOptions,
]);
} | [
"protected",
"function",
"_buildContext",
"(",
"Request",
"$",
"request",
",",
"$",
"options",
")",
"{",
"$",
"this",
"->",
"_buildContent",
"(",
"$",
"request",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"_buildHeaders",
"(",
"$",
"request",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"_buildOptions",
"(",
"$",
"request",
",",
"$",
"options",
")",
";",
"$",
"url",
"=",
"$",
"request",
"->",
"getUri",
"(",
")",
";",
"$",
"scheme",
"=",
"parse_url",
"(",
"$",
"url",
",",
"PHP_URL_SCHEME",
")",
";",
"if",
"(",
"$",
"scheme",
"===",
"'https'",
")",
"{",
"$",
"this",
"->",
"_buildSslContext",
"(",
"$",
"request",
",",
"$",
"options",
")",
";",
"}",
"$",
"this",
"->",
"_context",
"=",
"stream_context_create",
"(",
"[",
"'http'",
"=>",
"$",
"this",
"->",
"_contextOptions",
",",
"'ssl'",
"=>",
"$",
"this",
"->",
"_sslContextOptions",
",",
"]",
")",
";",
"}"
] | Build the stream context out of the request object.
@param \Cake\Http\Client\Request $request The request to build context from.
@param array $options Additional request options.
@return void | [
"Build",
"the",
"stream",
"context",
"out",
"of",
"the",
"request",
"object",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Adapter/Stream.php#L118-L133 |
211,492 | cakephp/cakephp | src/Http/Client/Adapter/Stream.php | Stream._buildHeaders | protected function _buildHeaders(Request $request, $options)
{
$headers = [];
foreach ($request->getHeaders() as $name => $values) {
$headers[] = sprintf('%s: %s', $name, implode(', ', $values));
}
$this->_contextOptions['header'] = implode("\r\n", $headers);
} | php | protected function _buildHeaders(Request $request, $options)
{
$headers = [];
foreach ($request->getHeaders() as $name => $values) {
$headers[] = sprintf('%s: %s', $name, implode(', ', $values));
}
$this->_contextOptions['header'] = implode("\r\n", $headers);
} | [
"protected",
"function",
"_buildHeaders",
"(",
"Request",
"$",
"request",
",",
"$",
"options",
")",
"{",
"$",
"headers",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"request",
"->",
"getHeaders",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"values",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"sprintf",
"(",
"'%s: %s'",
",",
"$",
"name",
",",
"implode",
"(",
"', '",
",",
"$",
"values",
")",
")",
";",
"}",
"$",
"this",
"->",
"_contextOptions",
"[",
"'header'",
"]",
"=",
"implode",
"(",
"\"\\r\\n\"",
",",
"$",
"headers",
")",
";",
"}"
] | Build the header context for the request.
Creates cookies & headers.
@param \Cake\Http\Client\Request $request The request being sent.
@param array $options Array of options to use.
@return void | [
"Build",
"the",
"header",
"context",
"for",
"the",
"request",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Adapter/Stream.php#L144-L151 |
211,493 | cakephp/cakephp | src/Http/Client/Adapter/Stream.php | Stream._buildContent | protected function _buildContent(Request $request, $options)
{
$body = $request->getBody();
if (empty($body)) {
$this->_contextOptions['content'] = '';
return;
}
$body->rewind();
$this->_contextOptions['content'] = $body->getContents();
} | php | protected function _buildContent(Request $request, $options)
{
$body = $request->getBody();
if (empty($body)) {
$this->_contextOptions['content'] = '';
return;
}
$body->rewind();
$this->_contextOptions['content'] = $body->getContents();
} | [
"protected",
"function",
"_buildContent",
"(",
"Request",
"$",
"request",
",",
"$",
"options",
")",
"{",
"$",
"body",
"=",
"$",
"request",
"->",
"getBody",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"body",
")",
")",
"{",
"$",
"this",
"->",
"_contextOptions",
"[",
"'content'",
"]",
"=",
"''",
";",
"return",
";",
"}",
"$",
"body",
"->",
"rewind",
"(",
")",
";",
"$",
"this",
"->",
"_contextOptions",
"[",
"'content'",
"]",
"=",
"$",
"body",
"->",
"getContents",
"(",
")",
";",
"}"
] | Builds the request content based on the request object.
If the $request->body() is a string, it will be used as is.
Array data will be processed with Cake\Http\Client\FormData
@param \Cake\Http\Client\Request $request The request being sent.
@param array $options Array of options to use.
@return void | [
"Builds",
"the",
"request",
"content",
"based",
"on",
"the",
"request",
"object",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Adapter/Stream.php#L163-L173 |
211,494 | cakephp/cakephp | src/Http/Client/Adapter/Stream.php | Stream._buildOptions | protected function _buildOptions(Request $request, $options)
{
$this->_contextOptions['method'] = $request->getMethod();
$this->_contextOptions['protocol_version'] = $request->getProtocolVersion();
$this->_contextOptions['ignore_errors'] = true;
if (isset($options['timeout'])) {
$this->_contextOptions['timeout'] = $options['timeout'];
}
// Redirects are handled in the client layer because of cookie handling issues.
$this->_contextOptions['max_redirects'] = 0;
if (isset($options['proxy']['proxy'])) {
$this->_contextOptions['request_fulluri'] = true;
$this->_contextOptions['proxy'] = $options['proxy']['proxy'];
}
} | php | protected function _buildOptions(Request $request, $options)
{
$this->_contextOptions['method'] = $request->getMethod();
$this->_contextOptions['protocol_version'] = $request->getProtocolVersion();
$this->_contextOptions['ignore_errors'] = true;
if (isset($options['timeout'])) {
$this->_contextOptions['timeout'] = $options['timeout'];
}
// Redirects are handled in the client layer because of cookie handling issues.
$this->_contextOptions['max_redirects'] = 0;
if (isset($options['proxy']['proxy'])) {
$this->_contextOptions['request_fulluri'] = true;
$this->_contextOptions['proxy'] = $options['proxy']['proxy'];
}
} | [
"protected",
"function",
"_buildOptions",
"(",
"Request",
"$",
"request",
",",
"$",
"options",
")",
"{",
"$",
"this",
"->",
"_contextOptions",
"[",
"'method'",
"]",
"=",
"$",
"request",
"->",
"getMethod",
"(",
")",
";",
"$",
"this",
"->",
"_contextOptions",
"[",
"'protocol_version'",
"]",
"=",
"$",
"request",
"->",
"getProtocolVersion",
"(",
")",
";",
"$",
"this",
"->",
"_contextOptions",
"[",
"'ignore_errors'",
"]",
"=",
"true",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'timeout'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_contextOptions",
"[",
"'timeout'",
"]",
"=",
"$",
"options",
"[",
"'timeout'",
"]",
";",
"}",
"// Redirects are handled in the client layer because of cookie handling issues.",
"$",
"this",
"->",
"_contextOptions",
"[",
"'max_redirects'",
"]",
"=",
"0",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'proxy'",
"]",
"[",
"'proxy'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_contextOptions",
"[",
"'request_fulluri'",
"]",
"=",
"true",
";",
"$",
"this",
"->",
"_contextOptions",
"[",
"'proxy'",
"]",
"=",
"$",
"options",
"[",
"'proxy'",
"]",
"[",
"'proxy'",
"]",
";",
"}",
"}"
] | Build miscellaneous options for the request.
@param \Cake\Http\Client\Request $request The request being sent.
@param array $options Array of options to use.
@return void | [
"Build",
"miscellaneous",
"options",
"for",
"the",
"request",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Adapter/Stream.php#L182-L198 |
211,495 | cakephp/cakephp | src/Http/Client/Adapter/Stream.php | Stream._buildSslContext | protected function _buildSslContext(Request $request, $options)
{
$sslOptions = [
'ssl_verify_peer',
'ssl_verify_peer_name',
'ssl_verify_depth',
'ssl_allow_self_signed',
'ssl_cafile',
'ssl_local_cert',
'ssl_passphrase',
];
if (empty($options['ssl_cafile'])) {
$options['ssl_cafile'] = CORE_PATH . 'config' . DIRECTORY_SEPARATOR . 'cacert.pem';
}
if (!empty($options['ssl_verify_host'])) {
$url = $request->getUri();
$host = parse_url($url, PHP_URL_HOST);
$this->_sslContextOptions['peer_name'] = $host;
}
foreach ($sslOptions as $key) {
if (isset($options[$key])) {
$name = substr($key, 4);
$this->_sslContextOptions[$name] = $options[$key];
}
}
} | php | protected function _buildSslContext(Request $request, $options)
{
$sslOptions = [
'ssl_verify_peer',
'ssl_verify_peer_name',
'ssl_verify_depth',
'ssl_allow_self_signed',
'ssl_cafile',
'ssl_local_cert',
'ssl_passphrase',
];
if (empty($options['ssl_cafile'])) {
$options['ssl_cafile'] = CORE_PATH . 'config' . DIRECTORY_SEPARATOR . 'cacert.pem';
}
if (!empty($options['ssl_verify_host'])) {
$url = $request->getUri();
$host = parse_url($url, PHP_URL_HOST);
$this->_sslContextOptions['peer_name'] = $host;
}
foreach ($sslOptions as $key) {
if (isset($options[$key])) {
$name = substr($key, 4);
$this->_sslContextOptions[$name] = $options[$key];
}
}
} | [
"protected",
"function",
"_buildSslContext",
"(",
"Request",
"$",
"request",
",",
"$",
"options",
")",
"{",
"$",
"sslOptions",
"=",
"[",
"'ssl_verify_peer'",
",",
"'ssl_verify_peer_name'",
",",
"'ssl_verify_depth'",
",",
"'ssl_allow_self_signed'",
",",
"'ssl_cafile'",
",",
"'ssl_local_cert'",
",",
"'ssl_passphrase'",
",",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'ssl_cafile'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'ssl_cafile'",
"]",
"=",
"CORE_PATH",
".",
"'config'",
".",
"DIRECTORY_SEPARATOR",
".",
"'cacert.pem'",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'ssl_verify_host'",
"]",
")",
")",
"{",
"$",
"url",
"=",
"$",
"request",
"->",
"getUri",
"(",
")",
";",
"$",
"host",
"=",
"parse_url",
"(",
"$",
"url",
",",
"PHP_URL_HOST",
")",
";",
"$",
"this",
"->",
"_sslContextOptions",
"[",
"'peer_name'",
"]",
"=",
"$",
"host",
";",
"}",
"foreach",
"(",
"$",
"sslOptions",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"name",
"=",
"substr",
"(",
"$",
"key",
",",
"4",
")",
";",
"$",
"this",
"->",
"_sslContextOptions",
"[",
"$",
"name",
"]",
"=",
"$",
"options",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"}"
] | Build SSL options for the request.
@param \Cake\Http\Client\Request $request The request being sent.
@param array $options Array of options to use.
@return void | [
"Build",
"SSL",
"options",
"for",
"the",
"request",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Adapter/Stream.php#L207-L232 |
211,496 | cakephp/cakephp | src/Http/Client/Adapter/Stream.php | Stream._send | protected function _send(Request $request)
{
$deadline = false;
if (isset($this->_contextOptions['timeout']) && $this->_contextOptions['timeout'] > 0) {
$deadline = time() + $this->_contextOptions['timeout'];
}
$url = $request->getUri();
$this->_open($url);
$content = '';
$timedOut = false;
while (!feof($this->_stream)) {
if ($deadline !== false) {
stream_set_timeout($this->_stream, max($deadline - time(), 1));
}
$content .= fread($this->_stream, 8192);
$meta = stream_get_meta_data($this->_stream);
if ($meta['timed_out'] || ($deadline !== false && time() > $deadline)) {
$timedOut = true;
break;
}
}
$meta = stream_get_meta_data($this->_stream);
fclose($this->_stream);
if ($timedOut) {
throw new HttpException('Connection timed out ' . $url, 504);
}
$headers = $meta['wrapper_data'];
if (isset($headers['headers']) && is_array($headers['headers'])) {
$headers = $headers['headers'];
}
return $this->createResponses($headers, $content);
} | php | protected function _send(Request $request)
{
$deadline = false;
if (isset($this->_contextOptions['timeout']) && $this->_contextOptions['timeout'] > 0) {
$deadline = time() + $this->_contextOptions['timeout'];
}
$url = $request->getUri();
$this->_open($url);
$content = '';
$timedOut = false;
while (!feof($this->_stream)) {
if ($deadline !== false) {
stream_set_timeout($this->_stream, max($deadline - time(), 1));
}
$content .= fread($this->_stream, 8192);
$meta = stream_get_meta_data($this->_stream);
if ($meta['timed_out'] || ($deadline !== false && time() > $deadline)) {
$timedOut = true;
break;
}
}
$meta = stream_get_meta_data($this->_stream);
fclose($this->_stream);
if ($timedOut) {
throw new HttpException('Connection timed out ' . $url, 504);
}
$headers = $meta['wrapper_data'];
if (isset($headers['headers']) && is_array($headers['headers'])) {
$headers = $headers['headers'];
}
return $this->createResponses($headers, $content);
} | [
"protected",
"function",
"_send",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"deadline",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_contextOptions",
"[",
"'timeout'",
"]",
")",
"&&",
"$",
"this",
"->",
"_contextOptions",
"[",
"'timeout'",
"]",
">",
"0",
")",
"{",
"$",
"deadline",
"=",
"time",
"(",
")",
"+",
"$",
"this",
"->",
"_contextOptions",
"[",
"'timeout'",
"]",
";",
"}",
"$",
"url",
"=",
"$",
"request",
"->",
"getUri",
"(",
")",
";",
"$",
"this",
"->",
"_open",
"(",
"$",
"url",
")",
";",
"$",
"content",
"=",
"''",
";",
"$",
"timedOut",
"=",
"false",
";",
"while",
"(",
"!",
"feof",
"(",
"$",
"this",
"->",
"_stream",
")",
")",
"{",
"if",
"(",
"$",
"deadline",
"!==",
"false",
")",
"{",
"stream_set_timeout",
"(",
"$",
"this",
"->",
"_stream",
",",
"max",
"(",
"$",
"deadline",
"-",
"time",
"(",
")",
",",
"1",
")",
")",
";",
"}",
"$",
"content",
".=",
"fread",
"(",
"$",
"this",
"->",
"_stream",
",",
"8192",
")",
";",
"$",
"meta",
"=",
"stream_get_meta_data",
"(",
"$",
"this",
"->",
"_stream",
")",
";",
"if",
"(",
"$",
"meta",
"[",
"'timed_out'",
"]",
"||",
"(",
"$",
"deadline",
"!==",
"false",
"&&",
"time",
"(",
")",
">",
"$",
"deadline",
")",
")",
"{",
"$",
"timedOut",
"=",
"true",
";",
"break",
";",
"}",
"}",
"$",
"meta",
"=",
"stream_get_meta_data",
"(",
"$",
"this",
"->",
"_stream",
")",
";",
"fclose",
"(",
"$",
"this",
"->",
"_stream",
")",
";",
"if",
"(",
"$",
"timedOut",
")",
"{",
"throw",
"new",
"HttpException",
"(",
"'Connection timed out '",
".",
"$",
"url",
",",
"504",
")",
";",
"}",
"$",
"headers",
"=",
"$",
"meta",
"[",
"'wrapper_data'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"headers",
"[",
"'headers'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"headers",
"[",
"'headers'",
"]",
")",
")",
"{",
"$",
"headers",
"=",
"$",
"headers",
"[",
"'headers'",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"createResponses",
"(",
"$",
"headers",
",",
"$",
"content",
")",
";",
"}"
] | Open the stream and send the request.
@param \Cake\Http\Client\Request $request The request object.
@return array Array of populated Response objects
@throws \Cake\Http\Exception\HttpException | [
"Open",
"the",
"stream",
"and",
"send",
"the",
"request",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Adapter/Stream.php#L241-L279 |
211,497 | cakephp/cakephp | src/Http/Client/Adapter/Stream.php | Stream._open | protected function _open($url)
{
set_error_handler(function ($code, $message) {
$this->_connectionErrors[] = $message;
});
try {
$this->_stream = fopen($url, 'rb', false, $this->_context);
} finally {
restore_error_handler();
}
if (!$this->_stream || !empty($this->_connectionErrors)) {
throw new Exception(implode("\n", $this->_connectionErrors));
}
} | php | protected function _open($url)
{
set_error_handler(function ($code, $message) {
$this->_connectionErrors[] = $message;
});
try {
$this->_stream = fopen($url, 'rb', false, $this->_context);
} finally {
restore_error_handler();
}
if (!$this->_stream || !empty($this->_connectionErrors)) {
throw new Exception(implode("\n", $this->_connectionErrors));
}
} | [
"protected",
"function",
"_open",
"(",
"$",
"url",
")",
"{",
"set_error_handler",
"(",
"function",
"(",
"$",
"code",
",",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"_connectionErrors",
"[",
"]",
"=",
"$",
"message",
";",
"}",
")",
";",
"try",
"{",
"$",
"this",
"->",
"_stream",
"=",
"fopen",
"(",
"$",
"url",
",",
"'rb'",
",",
"false",
",",
"$",
"this",
"->",
"_context",
")",
";",
"}",
"finally",
"{",
"restore_error_handler",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"_stream",
"||",
"!",
"empty",
"(",
"$",
"this",
"->",
"_connectionErrors",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"implode",
"(",
"\"\\n\"",
",",
"$",
"this",
"->",
"_connectionErrors",
")",
")",
";",
"}",
"}"
] | Open the socket and handle any connection errors.
@param string $url The url to connect to.
@return void
@throws \Cake\Core\Exception\Exception | [
"Open",
"the",
"socket",
"and",
"handle",
"any",
"connection",
"errors",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Adapter/Stream.php#L301-L315 |
211,498 | cakephp/cakephp | src/View/SerializedView.php | SerializedView.render | public function render($view = null, $layout = null)
{
$serialize = false;
if (isset($this->viewVars['_serialize'])) {
$serialize = $this->viewVars['_serialize'];
}
if ($serialize !== false) {
$result = $this->_serialize($serialize);
if ($result === false) {
throw new RuntimeException('Serialization of View data failed.');
}
return (string)$result;
}
if ($view !== false && $this->_getViewFileName($view)) {
return parent::render($view, false);
}
} | php | public function render($view = null, $layout = null)
{
$serialize = false;
if (isset($this->viewVars['_serialize'])) {
$serialize = $this->viewVars['_serialize'];
}
if ($serialize !== false) {
$result = $this->_serialize($serialize);
if ($result === false) {
throw new RuntimeException('Serialization of View data failed.');
}
return (string)$result;
}
if ($view !== false && $this->_getViewFileName($view)) {
return parent::render($view, false);
}
} | [
"public",
"function",
"render",
"(",
"$",
"view",
"=",
"null",
",",
"$",
"layout",
"=",
"null",
")",
"{",
"$",
"serialize",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"viewVars",
"[",
"'_serialize'",
"]",
")",
")",
"{",
"$",
"serialize",
"=",
"$",
"this",
"->",
"viewVars",
"[",
"'_serialize'",
"]",
";",
"}",
"if",
"(",
"$",
"serialize",
"!==",
"false",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"_serialize",
"(",
"$",
"serialize",
")",
";",
"if",
"(",
"$",
"result",
"===",
"false",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Serialization of View data failed.'",
")",
";",
"}",
"return",
"(",
"string",
")",
"$",
"result",
";",
"}",
"if",
"(",
"$",
"view",
"!==",
"false",
"&&",
"$",
"this",
"->",
"_getViewFileName",
"(",
"$",
"view",
")",
")",
"{",
"return",
"parent",
"::",
"render",
"(",
"$",
"view",
",",
"false",
")",
";",
"}",
"}"
] | Render view template or return serialized data.
### Special parameters
`_serialize` To convert a set of view variables into a serialized form.
Its value can be a string for single variable name or array for multiple
names. If true all view variables will be serialized. If unset normal
view template will be rendered.
@param string|bool|null $view The view being rendered.
@param string|null $layout The layout being rendered.
@return string|null The rendered view. | [
"Render",
"view",
"template",
"or",
"return",
"serialized",
"data",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/SerializedView.php#L89-L107 |
211,499 | cakephp/cakephp | src/Cache/Engine/XcacheEngine.php | XcacheEngine.increment | public function increment($key, $offset = 1)
{
$key = $this->_key($key);
return xcache_inc($key, $offset);
} | php | public function increment($key, $offset = 1)
{
$key = $this->_key($key);
return xcache_inc($key, $offset);
} | [
"public",
"function",
"increment",
"(",
"$",
"key",
",",
"$",
"offset",
"=",
"1",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"_key",
"(",
"$",
"key",
")",
";",
"return",
"xcache_inc",
"(",
"$",
"key",
",",
"$",
"offset",
")",
";",
"}"
] | Increments the value of an integer cached key
If the cache key is not an integer it will be treated as 0
@param string $key Identifier for the data
@param int $offset How much to increment
@return bool|int New incremented value, false otherwise | [
"Increments",
"the",
"value",
"of",
"an",
"integer",
"cached",
"key",
"If",
"the",
"cache",
"key",
"is",
"not",
"an",
"integer",
"it",
"will",
"be",
"treated",
"as",
"0"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/Engine/XcacheEngine.php#L130-L135 |
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.