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,700 | cakephp/cakephp | src/View/Helper/FormHelper.php | FormHelper.secure | public function secure(array $fields = [], array $secureAttributes = [])
{
if (!$this->_View->getRequest()->getParam('_Token')) {
return '';
}
$debugSecurity = Configure::read('debug');
if (isset($secureAttributes['debugSecurity'])) {
$debugSecurity = $debugSecurity && $secureAttributes['debugSecurity'];
unset($secureAttributes['debugSecurity']);
}
$secureAttributes['secure'] = static::SECURE_SKIP;
$secureAttributes['autocomplete'] = 'off';
$tokenData = $this->_buildFieldToken(
$this->_lastAction,
$fields,
$this->_unlockedFields
);
$tokenFields = array_merge($secureAttributes, [
'value' => $tokenData['fields'],
]);
$out = $this->hidden('_Token.fields', $tokenFields);
$tokenUnlocked = array_merge($secureAttributes, [
'value' => $tokenData['unlocked'],
]);
$out .= $this->hidden('_Token.unlocked', $tokenUnlocked);
if ($debugSecurity) {
$tokenDebug = array_merge($secureAttributes, [
'value' => urlencode(json_encode([
$this->_lastAction,
$fields,
$this->_unlockedFields
])),
]);
$out .= $this->hidden('_Token.debug', $tokenDebug);
}
return $this->formatTemplate('hiddenBlock', ['content' => $out]);
} | php | public function secure(array $fields = [], array $secureAttributes = [])
{
if (!$this->_View->getRequest()->getParam('_Token')) {
return '';
}
$debugSecurity = Configure::read('debug');
if (isset($secureAttributes['debugSecurity'])) {
$debugSecurity = $debugSecurity && $secureAttributes['debugSecurity'];
unset($secureAttributes['debugSecurity']);
}
$secureAttributes['secure'] = static::SECURE_SKIP;
$secureAttributes['autocomplete'] = 'off';
$tokenData = $this->_buildFieldToken(
$this->_lastAction,
$fields,
$this->_unlockedFields
);
$tokenFields = array_merge($secureAttributes, [
'value' => $tokenData['fields'],
]);
$out = $this->hidden('_Token.fields', $tokenFields);
$tokenUnlocked = array_merge($secureAttributes, [
'value' => $tokenData['unlocked'],
]);
$out .= $this->hidden('_Token.unlocked', $tokenUnlocked);
if ($debugSecurity) {
$tokenDebug = array_merge($secureAttributes, [
'value' => urlencode(json_encode([
$this->_lastAction,
$fields,
$this->_unlockedFields
])),
]);
$out .= $this->hidden('_Token.debug', $tokenDebug);
}
return $this->formatTemplate('hiddenBlock', ['content' => $out]);
} | [
"public",
"function",
"secure",
"(",
"array",
"$",
"fields",
"=",
"[",
"]",
",",
"array",
"$",
"secureAttributes",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_View",
"->",
"getRequest",
"(",
")",
"->",
"getParam",
"(",
"'_Token'",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"debugSecurity",
"=",
"Configure",
"::",
"read",
"(",
"'debug'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"secureAttributes",
"[",
"'debugSecurity'",
"]",
")",
")",
"{",
"$",
"debugSecurity",
"=",
"$",
"debugSecurity",
"&&",
"$",
"secureAttributes",
"[",
"'debugSecurity'",
"]",
";",
"unset",
"(",
"$",
"secureAttributes",
"[",
"'debugSecurity'",
"]",
")",
";",
"}",
"$",
"secureAttributes",
"[",
"'secure'",
"]",
"=",
"static",
"::",
"SECURE_SKIP",
";",
"$",
"secureAttributes",
"[",
"'autocomplete'",
"]",
"=",
"'off'",
";",
"$",
"tokenData",
"=",
"$",
"this",
"->",
"_buildFieldToken",
"(",
"$",
"this",
"->",
"_lastAction",
",",
"$",
"fields",
",",
"$",
"this",
"->",
"_unlockedFields",
")",
";",
"$",
"tokenFields",
"=",
"array_merge",
"(",
"$",
"secureAttributes",
",",
"[",
"'value'",
"=>",
"$",
"tokenData",
"[",
"'fields'",
"]",
",",
"]",
")",
";",
"$",
"out",
"=",
"$",
"this",
"->",
"hidden",
"(",
"'_Token.fields'",
",",
"$",
"tokenFields",
")",
";",
"$",
"tokenUnlocked",
"=",
"array_merge",
"(",
"$",
"secureAttributes",
",",
"[",
"'value'",
"=>",
"$",
"tokenData",
"[",
"'unlocked'",
"]",
",",
"]",
")",
";",
"$",
"out",
".=",
"$",
"this",
"->",
"hidden",
"(",
"'_Token.unlocked'",
",",
"$",
"tokenUnlocked",
")",
";",
"if",
"(",
"$",
"debugSecurity",
")",
"{",
"$",
"tokenDebug",
"=",
"array_merge",
"(",
"$",
"secureAttributes",
",",
"[",
"'value'",
"=>",
"urlencode",
"(",
"json_encode",
"(",
"[",
"$",
"this",
"->",
"_lastAction",
",",
"$",
"fields",
",",
"$",
"this",
"->",
"_unlockedFields",
"]",
")",
")",
",",
"]",
")",
";",
"$",
"out",
".=",
"$",
"this",
"->",
"hidden",
"(",
"'_Token.debug'",
",",
"$",
"tokenDebug",
")",
";",
"}",
"return",
"$",
"this",
"->",
"formatTemplate",
"(",
"'hiddenBlock'",
",",
"[",
"'content'",
"=>",
"$",
"out",
"]",
")",
";",
"}"
] | Generates a hidden field with a security hash based on the fields used in
the form.
If $secureAttributes is set, these HTML attributes will be merged into
the hidden input tags generated for the Security Component. This is
especially useful to set HTML5 attributes like 'form'.
@param array $fields If set specifies the list of fields to use when
generating the hash, else $this->fields is being used.
@param array $secureAttributes will be passed as HTML attributes into the hidden
input elements generated for the Security Component.
@return string A hidden input field with a security hash, or empty string when
secured forms are not in use. | [
"Generates",
"a",
"hidden",
"field",
"with",
"a",
"security",
"hash",
"based",
"on",
"the",
"fields",
"used",
"in",
"the",
"form",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L654-L692 |
211,701 | cakephp/cakephp | src/View/Helper/FormHelper.php | FormHelper.unlockField | public function unlockField($name = null)
{
if ($name === null) {
return $this->_unlockedFields;
}
if (!in_array($name, $this->_unlockedFields)) {
$this->_unlockedFields[] = $name;
}
$index = array_search($name, $this->fields);
if ($index !== false) {
unset($this->fields[$index]);
}
unset($this->fields[$name]);
} | php | public function unlockField($name = null)
{
if ($name === null) {
return $this->_unlockedFields;
}
if (!in_array($name, $this->_unlockedFields)) {
$this->_unlockedFields[] = $name;
}
$index = array_search($name, $this->fields);
if ($index !== false) {
unset($this->fields[$index]);
}
unset($this->fields[$name]);
} | [
"public",
"function",
"unlockField",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"name",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_unlockedFields",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"_unlockedFields",
")",
")",
"{",
"$",
"this",
"->",
"_unlockedFields",
"[",
"]",
"=",
"$",
"name",
";",
"}",
"$",
"index",
"=",
"array_search",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"fields",
")",
";",
"if",
"(",
"$",
"index",
"!==",
"false",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"fields",
"[",
"$",
"index",
"]",
")",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"fields",
"[",
"$",
"name",
"]",
")",
";",
"}"
] | Add to or get the list of fields that are currently unlocked.
Unlocked fields are not included in the field hash used by SecurityComponent
unlocking a field once its been added to the list of secured fields will remove
it from the list of fields.
@param string|null $name The dot separated name for the field.
@return array|null Either null, or the list of fields.
@link https://book.cakephp.org/3.0/en/views/helpers/form.html#working-with-securitycomponent | [
"Add",
"to",
"or",
"get",
"the",
"list",
"of",
"fields",
"that",
"are",
"currently",
"unlocked",
".",
"Unlocked",
"fields",
"are",
"not",
"included",
"in",
"the",
"field",
"hash",
"used",
"by",
"SecurityComponent",
"unlocking",
"a",
"field",
"once",
"its",
"been",
"added",
"to",
"the",
"list",
"of",
"secured",
"fields",
"will",
"remove",
"it",
"from",
"the",
"list",
"of",
"fields",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L704-L717 |
211,702 | cakephp/cakephp | src/View/Helper/FormHelper.php | FormHelper.error | public function error($field, $text = null, array $options = [])
{
if (substr($field, -5) === '._ids') {
$field = substr($field, 0, -5);
}
$options += ['escape' => true];
$context = $this->_getContext();
if (!$context->hasError($field)) {
return '';
}
$error = $context->error($field);
if (is_array($text)) {
$tmp = [];
foreach ($error as $k => $e) {
if (isset($text[$k])) {
$tmp[] = $text[$k];
} elseif (isset($text[$e])) {
$tmp[] = $text[$e];
} else {
$tmp[] = $e;
}
}
$text = $tmp;
}
if ($text !== null) {
$error = $text;
}
if ($options['escape']) {
$error = h($error);
unset($options['escape']);
}
if (is_array($error)) {
if (count($error) > 1) {
$errorText = [];
foreach ($error as $err) {
$errorText[] = $this->formatTemplate('errorItem', ['text' => $err]);
}
$error = $this->formatTemplate('errorList', [
'content' => implode('', $errorText)
]);
} else {
$error = array_pop($error);
}
}
return $this->formatTemplate('error', ['content' => $error]);
} | php | public function error($field, $text = null, array $options = [])
{
if (substr($field, -5) === '._ids') {
$field = substr($field, 0, -5);
}
$options += ['escape' => true];
$context = $this->_getContext();
if (!$context->hasError($field)) {
return '';
}
$error = $context->error($field);
if (is_array($text)) {
$tmp = [];
foreach ($error as $k => $e) {
if (isset($text[$k])) {
$tmp[] = $text[$k];
} elseif (isset($text[$e])) {
$tmp[] = $text[$e];
} else {
$tmp[] = $e;
}
}
$text = $tmp;
}
if ($text !== null) {
$error = $text;
}
if ($options['escape']) {
$error = h($error);
unset($options['escape']);
}
if (is_array($error)) {
if (count($error) > 1) {
$errorText = [];
foreach ($error as $err) {
$errorText[] = $this->formatTemplate('errorItem', ['text' => $err]);
}
$error = $this->formatTemplate('errorList', [
'content' => implode('', $errorText)
]);
} else {
$error = array_pop($error);
}
}
return $this->formatTemplate('error', ['content' => $error]);
} | [
"public",
"function",
"error",
"(",
"$",
"field",
",",
"$",
"text",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"field",
",",
"-",
"5",
")",
"===",
"'._ids'",
")",
"{",
"$",
"field",
"=",
"substr",
"(",
"$",
"field",
",",
"0",
",",
"-",
"5",
")",
";",
"}",
"$",
"options",
"+=",
"[",
"'escape'",
"=>",
"true",
"]",
";",
"$",
"context",
"=",
"$",
"this",
"->",
"_getContext",
"(",
")",
";",
"if",
"(",
"!",
"$",
"context",
"->",
"hasError",
"(",
"$",
"field",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"error",
"=",
"$",
"context",
"->",
"error",
"(",
"$",
"field",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"text",
")",
")",
"{",
"$",
"tmp",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"error",
"as",
"$",
"k",
"=>",
"$",
"e",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"text",
"[",
"$",
"k",
"]",
")",
")",
"{",
"$",
"tmp",
"[",
"]",
"=",
"$",
"text",
"[",
"$",
"k",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"text",
"[",
"$",
"e",
"]",
")",
")",
"{",
"$",
"tmp",
"[",
"]",
"=",
"$",
"text",
"[",
"$",
"e",
"]",
";",
"}",
"else",
"{",
"$",
"tmp",
"[",
"]",
"=",
"$",
"e",
";",
"}",
"}",
"$",
"text",
"=",
"$",
"tmp",
";",
"}",
"if",
"(",
"$",
"text",
"!==",
"null",
")",
"{",
"$",
"error",
"=",
"$",
"text",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'escape'",
"]",
")",
"{",
"$",
"error",
"=",
"h",
"(",
"$",
"error",
")",
";",
"unset",
"(",
"$",
"options",
"[",
"'escape'",
"]",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"error",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"error",
")",
">",
"1",
")",
"{",
"$",
"errorText",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"error",
"as",
"$",
"err",
")",
"{",
"$",
"errorText",
"[",
"]",
"=",
"$",
"this",
"->",
"formatTemplate",
"(",
"'errorItem'",
",",
"[",
"'text'",
"=>",
"$",
"err",
"]",
")",
";",
"}",
"$",
"error",
"=",
"$",
"this",
"->",
"formatTemplate",
"(",
"'errorList'",
",",
"[",
"'content'",
"=>",
"implode",
"(",
"''",
",",
"$",
"errorText",
")",
"]",
")",
";",
"}",
"else",
"{",
"$",
"error",
"=",
"array_pop",
"(",
"$",
"error",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"formatTemplate",
"(",
"'error'",
",",
"[",
"'content'",
"=>",
"$",
"error",
"]",
")",
";",
"}"
] | Returns a formatted error message for given form field, '' if no errors.
Uses the `error`, `errorList` and `errorItem` templates. The `errorList` and
`errorItem` templates are used to format multiple error messages per field.
### Options:
- `escape` boolean - Whether or not to html escape the contents of the error.
@param string $field A field name, like "modelname.fieldname"
@param string|array|null $text Error message as string or array of messages. If an array,
it should be a hash of key names => messages.
@param array $options See above.
@return string Formatted errors or ''.
@link https://book.cakephp.org/3.0/en/views/helpers/form.html#displaying-and-checking-errors | [
"Returns",
"a",
"formatted",
"error",
"message",
"for",
"given",
"form",
"field",
"if",
"no",
"errors",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L796-L847 |
211,703 | cakephp/cakephp | src/View/Helper/FormHelper.php | FormHelper.label | public function label($fieldName, $text = null, array $options = [])
{
if ($text === null) {
$text = $fieldName;
if (substr($text, -5) === '._ids') {
$text = substr($text, 0, -5);
}
if (strpos($text, '.') !== false) {
$fieldElements = explode('.', $text);
$text = array_pop($fieldElements);
}
if (substr($text, -3) === '_id') {
$text = substr($text, 0, -3);
}
$text = __(Inflector::humanize(Inflector::underscore($text)));
}
if (isset($options['for'])) {
$labelFor = $options['for'];
unset($options['for']);
} else {
$labelFor = $this->_domId($fieldName);
}
$attrs = $options + [
'for' => $labelFor,
'text' => $text,
];
if (isset($options['input'])) {
if (is_array($options['input'])) {
$attrs = $options['input'] + $attrs;
}
return $this->widget('nestingLabel', $attrs);
}
return $this->widget('label', $attrs);
} | php | public function label($fieldName, $text = null, array $options = [])
{
if ($text === null) {
$text = $fieldName;
if (substr($text, -5) === '._ids') {
$text = substr($text, 0, -5);
}
if (strpos($text, '.') !== false) {
$fieldElements = explode('.', $text);
$text = array_pop($fieldElements);
}
if (substr($text, -3) === '_id') {
$text = substr($text, 0, -3);
}
$text = __(Inflector::humanize(Inflector::underscore($text)));
}
if (isset($options['for'])) {
$labelFor = $options['for'];
unset($options['for']);
} else {
$labelFor = $this->_domId($fieldName);
}
$attrs = $options + [
'for' => $labelFor,
'text' => $text,
];
if (isset($options['input'])) {
if (is_array($options['input'])) {
$attrs = $options['input'] + $attrs;
}
return $this->widget('nestingLabel', $attrs);
}
return $this->widget('label', $attrs);
} | [
"public",
"function",
"label",
"(",
"$",
"fieldName",
",",
"$",
"text",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"text",
"===",
"null",
")",
"{",
"$",
"text",
"=",
"$",
"fieldName",
";",
"if",
"(",
"substr",
"(",
"$",
"text",
",",
"-",
"5",
")",
"===",
"'._ids'",
")",
"{",
"$",
"text",
"=",
"substr",
"(",
"$",
"text",
",",
"0",
",",
"-",
"5",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"text",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"$",
"fieldElements",
"=",
"explode",
"(",
"'.'",
",",
"$",
"text",
")",
";",
"$",
"text",
"=",
"array_pop",
"(",
"$",
"fieldElements",
")",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"text",
",",
"-",
"3",
")",
"===",
"'_id'",
")",
"{",
"$",
"text",
"=",
"substr",
"(",
"$",
"text",
",",
"0",
",",
"-",
"3",
")",
";",
"}",
"$",
"text",
"=",
"__",
"(",
"Inflector",
"::",
"humanize",
"(",
"Inflector",
"::",
"underscore",
"(",
"$",
"text",
")",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'for'",
"]",
")",
")",
"{",
"$",
"labelFor",
"=",
"$",
"options",
"[",
"'for'",
"]",
";",
"unset",
"(",
"$",
"options",
"[",
"'for'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"labelFor",
"=",
"$",
"this",
"->",
"_domId",
"(",
"$",
"fieldName",
")",
";",
"}",
"$",
"attrs",
"=",
"$",
"options",
"+",
"[",
"'for'",
"=>",
"$",
"labelFor",
",",
"'text'",
"=>",
"$",
"text",
",",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'input'",
"]",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"options",
"[",
"'input'",
"]",
")",
")",
"{",
"$",
"attrs",
"=",
"$",
"options",
"[",
"'input'",
"]",
"+",
"$",
"attrs",
";",
"}",
"return",
"$",
"this",
"->",
"widget",
"(",
"'nestingLabel'",
",",
"$",
"attrs",
")",
";",
"}",
"return",
"$",
"this",
"->",
"widget",
"(",
"'label'",
",",
"$",
"attrs",
")",
";",
"}"
] | Returns a formatted LABEL element for HTML forms.
Will automatically generate a `for` attribute if one is not provided.
### Options
- `for` - Set the for attribute, if its not defined the for attribute
will be generated from the $fieldName parameter using
FormHelper::_domId().
- `escape` - Set to `false` to turn off escaping of label text.
Defaults to `true`.
Examples:
The text and for attribute are generated off of the fieldname
```
echo $this->Form->label('published');
<label for="PostPublished">Published</label>
```
Custom text:
```
echo $this->Form->label('published', 'Publish');
<label for="published">Publish</label>
```
Custom attributes:
```
echo $this->Form->label('published', 'Publish', [
'for' => 'post-publish'
]);
<label for="post-publish">Publish</label>
```
Nesting an input tag:
```
echo $this->Form->label('published', 'Publish', [
'for' => 'published',
'input' => $this->text('published'),
]);
<label for="post-publish">Publish <input type="text" name="published"></label>
```
If you want to nest inputs in the labels, you will need to modify the default templates.
@param string $fieldName This should be "modelname.fieldname"
@param string|null $text Text that will appear in the label field. If
$text is left undefined the text will be inflected from the
fieldName.
@param array $options An array of HTML attributes.
@return string The formatted LABEL element
@link https://book.cakephp.org/3.0/en/views/helpers/form.html#creating-labels | [
"Returns",
"a",
"formatted",
"LABEL",
"element",
"for",
"HTML",
"forms",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L907-L943 |
211,704 | cakephp/cakephp | src/View/Helper/FormHelper.php | FormHelper.fieldset | public function fieldset($fields = '', array $options = [])
{
$fieldset = $legend = true;
$context = $this->_getContext();
$out = $fields;
if (isset($options['legend'])) {
$legend = $options['legend'];
}
if (isset($options['fieldset'])) {
$fieldset = $options['fieldset'];
}
if ($legend === true) {
$isCreate = $context->isCreate();
$modelName = Inflector::humanize(Inflector::singularize($this->_View->getRequest()->getParam('controller')));
if (!$isCreate) {
$legend = __d('cake', 'Edit {0}', $modelName);
} else {
$legend = __d('cake', 'New {0}', $modelName);
}
}
if ($fieldset !== false) {
if ($legend) {
$out = $this->formatTemplate('legend', ['text' => $legend]) . $out;
}
$fieldsetParams = ['content' => $out, 'attrs' => ''];
if (is_array($fieldset) && !empty($fieldset)) {
$fieldsetParams['attrs'] = $this->templater()->formatAttributes($fieldset);
}
$out = $this->formatTemplate('fieldset', $fieldsetParams);
}
return $out;
} | php | public function fieldset($fields = '', array $options = [])
{
$fieldset = $legend = true;
$context = $this->_getContext();
$out = $fields;
if (isset($options['legend'])) {
$legend = $options['legend'];
}
if (isset($options['fieldset'])) {
$fieldset = $options['fieldset'];
}
if ($legend === true) {
$isCreate = $context->isCreate();
$modelName = Inflector::humanize(Inflector::singularize($this->_View->getRequest()->getParam('controller')));
if (!$isCreate) {
$legend = __d('cake', 'Edit {0}', $modelName);
} else {
$legend = __d('cake', 'New {0}', $modelName);
}
}
if ($fieldset !== false) {
if ($legend) {
$out = $this->formatTemplate('legend', ['text' => $legend]) . $out;
}
$fieldsetParams = ['content' => $out, 'attrs' => ''];
if (is_array($fieldset) && !empty($fieldset)) {
$fieldsetParams['attrs'] = $this->templater()->formatAttributes($fieldset);
}
$out = $this->formatTemplate('fieldset', $fieldsetParams);
}
return $out;
} | [
"public",
"function",
"fieldset",
"(",
"$",
"fields",
"=",
"''",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"fieldset",
"=",
"$",
"legend",
"=",
"true",
";",
"$",
"context",
"=",
"$",
"this",
"->",
"_getContext",
"(",
")",
";",
"$",
"out",
"=",
"$",
"fields",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'legend'",
"]",
")",
")",
"{",
"$",
"legend",
"=",
"$",
"options",
"[",
"'legend'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'fieldset'",
"]",
")",
")",
"{",
"$",
"fieldset",
"=",
"$",
"options",
"[",
"'fieldset'",
"]",
";",
"}",
"if",
"(",
"$",
"legend",
"===",
"true",
")",
"{",
"$",
"isCreate",
"=",
"$",
"context",
"->",
"isCreate",
"(",
")",
";",
"$",
"modelName",
"=",
"Inflector",
"::",
"humanize",
"(",
"Inflector",
"::",
"singularize",
"(",
"$",
"this",
"->",
"_View",
"->",
"getRequest",
"(",
")",
"->",
"getParam",
"(",
"'controller'",
")",
")",
")",
";",
"if",
"(",
"!",
"$",
"isCreate",
")",
"{",
"$",
"legend",
"=",
"__d",
"(",
"'cake'",
",",
"'Edit {0}'",
",",
"$",
"modelName",
")",
";",
"}",
"else",
"{",
"$",
"legend",
"=",
"__d",
"(",
"'cake'",
",",
"'New {0}'",
",",
"$",
"modelName",
")",
";",
"}",
"}",
"if",
"(",
"$",
"fieldset",
"!==",
"false",
")",
"{",
"if",
"(",
"$",
"legend",
")",
"{",
"$",
"out",
"=",
"$",
"this",
"->",
"formatTemplate",
"(",
"'legend'",
",",
"[",
"'text'",
"=>",
"$",
"legend",
"]",
")",
".",
"$",
"out",
";",
"}",
"$",
"fieldsetParams",
"=",
"[",
"'content'",
"=>",
"$",
"out",
",",
"'attrs'",
"=>",
"''",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"fieldset",
")",
"&&",
"!",
"empty",
"(",
"$",
"fieldset",
")",
")",
"{",
"$",
"fieldsetParams",
"[",
"'attrs'",
"]",
"=",
"$",
"this",
"->",
"templater",
"(",
")",
"->",
"formatAttributes",
"(",
"$",
"fieldset",
")",
";",
"}",
"$",
"out",
"=",
"$",
"this",
"->",
"formatTemplate",
"(",
"'fieldset'",
",",
"$",
"fieldsetParams",
")",
";",
"}",
"return",
"$",
"out",
";",
"}"
] | Wrap a set of inputs in a fieldset
@param string $fields the form inputs to wrap in a fieldset
@param array $options Options array. Valid keys are:
- `fieldset` Set to false to disable the fieldset. You can also pass an array of params to be
applied as HTML attributes to the fieldset tag. If you pass an empty array, the fieldset will
be enabled
- `legend` Set to false to disable the legend for the generated input set. Or supply a string
to customize the legend text.
@return string Completed form inputs. | [
"Wrap",
"a",
"set",
"of",
"inputs",
"in",
"a",
"fieldset"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L1090-L1126 |
211,705 | cakephp/cakephp | src/View/Helper/FormHelper.php | FormHelper._getInput | protected function _getInput($fieldName, $options)
{
$label = $options['labelOptions'];
unset($options['labelOptions']);
switch (strtolower($options['type'])) {
case 'select':
$opts = $options['options'];
unset($options['options']);
return $this->select($fieldName, $opts, $options + ['label' => $label]);
case 'radio':
$opts = $options['options'];
unset($options['options']);
return $this->radio($fieldName, $opts, $options + ['label' => $label]);
case 'multicheckbox':
$opts = $options['options'];
unset($options['options']);
return $this->multiCheckbox($fieldName, $opts, $options + ['label' => $label]);
case 'input':
throw new RuntimeException("Invalid type 'input' used for field '$fieldName'");
default:
return $this->{$options['type']}($fieldName, $options);
}
} | php | protected function _getInput($fieldName, $options)
{
$label = $options['labelOptions'];
unset($options['labelOptions']);
switch (strtolower($options['type'])) {
case 'select':
$opts = $options['options'];
unset($options['options']);
return $this->select($fieldName, $opts, $options + ['label' => $label]);
case 'radio':
$opts = $options['options'];
unset($options['options']);
return $this->radio($fieldName, $opts, $options + ['label' => $label]);
case 'multicheckbox':
$opts = $options['options'];
unset($options['options']);
return $this->multiCheckbox($fieldName, $opts, $options + ['label' => $label]);
case 'input':
throw new RuntimeException("Invalid type 'input' used for field '$fieldName'");
default:
return $this->{$options['type']}($fieldName, $options);
}
} | [
"protected",
"function",
"_getInput",
"(",
"$",
"fieldName",
",",
"$",
"options",
")",
"{",
"$",
"label",
"=",
"$",
"options",
"[",
"'labelOptions'",
"]",
";",
"unset",
"(",
"$",
"options",
"[",
"'labelOptions'",
"]",
")",
";",
"switch",
"(",
"strtolower",
"(",
"$",
"options",
"[",
"'type'",
"]",
")",
")",
"{",
"case",
"'select'",
":",
"$",
"opts",
"=",
"$",
"options",
"[",
"'options'",
"]",
";",
"unset",
"(",
"$",
"options",
"[",
"'options'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"select",
"(",
"$",
"fieldName",
",",
"$",
"opts",
",",
"$",
"options",
"+",
"[",
"'label'",
"=>",
"$",
"label",
"]",
")",
";",
"case",
"'radio'",
":",
"$",
"opts",
"=",
"$",
"options",
"[",
"'options'",
"]",
";",
"unset",
"(",
"$",
"options",
"[",
"'options'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"radio",
"(",
"$",
"fieldName",
",",
"$",
"opts",
",",
"$",
"options",
"+",
"[",
"'label'",
"=>",
"$",
"label",
"]",
")",
";",
"case",
"'multicheckbox'",
":",
"$",
"opts",
"=",
"$",
"options",
"[",
"'options'",
"]",
";",
"unset",
"(",
"$",
"options",
"[",
"'options'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"multiCheckbox",
"(",
"$",
"fieldName",
",",
"$",
"opts",
",",
"$",
"options",
"+",
"[",
"'label'",
"=>",
"$",
"label",
"]",
")",
";",
"case",
"'input'",
":",
"throw",
"new",
"RuntimeException",
"(",
"\"Invalid type 'input' used for field '$fieldName'\"",
")",
";",
"default",
":",
"return",
"$",
"this",
"->",
"{",
"$",
"options",
"[",
"'type'",
"]",
"}",
"(",
"$",
"fieldName",
",",
"$",
"options",
")",
";",
"}",
"}"
] | Generates an input element
@param string $fieldName the field name
@param array $options The options for the input element
@return string The generated input element | [
"Generates",
"an",
"input",
"element"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L1311-L1337 |
211,706 | cakephp/cakephp | src/View/Helper/FormHelper.php | FormHelper._inputType | protected function _inputType($fieldName, $options)
{
$context = $this->_getContext();
if ($context->isPrimaryKey($fieldName)) {
return 'hidden';
}
if (substr($fieldName, -3) === '_id') {
return 'select';
}
$internalType = $context->type($fieldName);
$map = $this->_config['typeMap'];
$type = isset($map[$internalType]) ? $map[$internalType] : 'text';
$fieldName = array_slice(explode('.', $fieldName), -1)[0];
switch (true) {
case isset($options['checked']):
return 'checkbox';
case isset($options['options']):
return 'select';
case in_array($fieldName, ['passwd', 'password']):
return 'password';
case in_array($fieldName, ['tel', 'telephone', 'phone']):
return 'tel';
case $fieldName === 'email':
return 'email';
case isset($options['rows']) || isset($options['cols']):
return 'textarea';
}
return $type;
} | php | protected function _inputType($fieldName, $options)
{
$context = $this->_getContext();
if ($context->isPrimaryKey($fieldName)) {
return 'hidden';
}
if (substr($fieldName, -3) === '_id') {
return 'select';
}
$internalType = $context->type($fieldName);
$map = $this->_config['typeMap'];
$type = isset($map[$internalType]) ? $map[$internalType] : 'text';
$fieldName = array_slice(explode('.', $fieldName), -1)[0];
switch (true) {
case isset($options['checked']):
return 'checkbox';
case isset($options['options']):
return 'select';
case in_array($fieldName, ['passwd', 'password']):
return 'password';
case in_array($fieldName, ['tel', 'telephone', 'phone']):
return 'tel';
case $fieldName === 'email':
return 'email';
case isset($options['rows']) || isset($options['cols']):
return 'textarea';
}
return $type;
} | [
"protected",
"function",
"_inputType",
"(",
"$",
"fieldName",
",",
"$",
"options",
")",
"{",
"$",
"context",
"=",
"$",
"this",
"->",
"_getContext",
"(",
")",
";",
"if",
"(",
"$",
"context",
"->",
"isPrimaryKey",
"(",
"$",
"fieldName",
")",
")",
"{",
"return",
"'hidden'",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"fieldName",
",",
"-",
"3",
")",
"===",
"'_id'",
")",
"{",
"return",
"'select'",
";",
"}",
"$",
"internalType",
"=",
"$",
"context",
"->",
"type",
"(",
"$",
"fieldName",
")",
";",
"$",
"map",
"=",
"$",
"this",
"->",
"_config",
"[",
"'typeMap'",
"]",
";",
"$",
"type",
"=",
"isset",
"(",
"$",
"map",
"[",
"$",
"internalType",
"]",
")",
"?",
"$",
"map",
"[",
"$",
"internalType",
"]",
":",
"'text'",
";",
"$",
"fieldName",
"=",
"array_slice",
"(",
"explode",
"(",
"'.'",
",",
"$",
"fieldName",
")",
",",
"-",
"1",
")",
"[",
"0",
"]",
";",
"switch",
"(",
"true",
")",
"{",
"case",
"isset",
"(",
"$",
"options",
"[",
"'checked'",
"]",
")",
":",
"return",
"'checkbox'",
";",
"case",
"isset",
"(",
"$",
"options",
"[",
"'options'",
"]",
")",
":",
"return",
"'select'",
";",
"case",
"in_array",
"(",
"$",
"fieldName",
",",
"[",
"'passwd'",
",",
"'password'",
"]",
")",
":",
"return",
"'password'",
";",
"case",
"in_array",
"(",
"$",
"fieldName",
",",
"[",
"'tel'",
",",
"'telephone'",
",",
"'phone'",
"]",
")",
":",
"return",
"'tel'",
";",
"case",
"$",
"fieldName",
"===",
"'email'",
":",
"return",
"'email'",
";",
"case",
"isset",
"(",
"$",
"options",
"[",
"'rows'",
"]",
")",
"||",
"isset",
"(",
"$",
"options",
"[",
"'cols'",
"]",
")",
":",
"return",
"'textarea'",
";",
"}",
"return",
"$",
"type",
";",
"}"
] | Returns the input type that was guessed for the provided fieldName,
based on the internal type it is associated too, its name and the
variables that can be found in the view template
@param string $fieldName the name of the field to guess a type for
@param array $options the options passed to the input method
@return string | [
"Returns",
"the",
"input",
"type",
"that",
"was",
"guessed",
"for",
"the",
"provided",
"fieldName",
"based",
"on",
"the",
"internal",
"type",
"it",
"is",
"associated",
"too",
"its",
"name",
"and",
"the",
"variables",
"that",
"can",
"be",
"found",
"in",
"the",
"view",
"template"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L1368-L1401 |
211,707 | cakephp/cakephp | src/View/Helper/FormHelper.php | FormHelper._optionsOptions | protected function _optionsOptions($fieldName, $options)
{
if (isset($options['options'])) {
return $options;
}
$pluralize = true;
if (substr($fieldName, -5) === '._ids') {
$fieldName = substr($fieldName, 0, -5);
$pluralize = false;
} elseif (substr($fieldName, -3) === '_id') {
$fieldName = substr($fieldName, 0, -3);
}
$fieldName = array_slice(explode('.', $fieldName), -1)[0];
$varName = Inflector::variable(
$pluralize ? Inflector::pluralize($fieldName) : $fieldName
);
$varOptions = $this->_View->get($varName);
if (!is_array($varOptions) && !($varOptions instanceof Traversable)) {
return $options;
}
if ($options['type'] !== 'radio') {
$options['type'] = 'select';
}
$options['options'] = $varOptions;
return $options;
} | php | protected function _optionsOptions($fieldName, $options)
{
if (isset($options['options'])) {
return $options;
}
$pluralize = true;
if (substr($fieldName, -5) === '._ids') {
$fieldName = substr($fieldName, 0, -5);
$pluralize = false;
} elseif (substr($fieldName, -3) === '_id') {
$fieldName = substr($fieldName, 0, -3);
}
$fieldName = array_slice(explode('.', $fieldName), -1)[0];
$varName = Inflector::variable(
$pluralize ? Inflector::pluralize($fieldName) : $fieldName
);
$varOptions = $this->_View->get($varName);
if (!is_array($varOptions) && !($varOptions instanceof Traversable)) {
return $options;
}
if ($options['type'] !== 'radio') {
$options['type'] = 'select';
}
$options['options'] = $varOptions;
return $options;
} | [
"protected",
"function",
"_optionsOptions",
"(",
"$",
"fieldName",
",",
"$",
"options",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'options'",
"]",
")",
")",
"{",
"return",
"$",
"options",
";",
"}",
"$",
"pluralize",
"=",
"true",
";",
"if",
"(",
"substr",
"(",
"$",
"fieldName",
",",
"-",
"5",
")",
"===",
"'._ids'",
")",
"{",
"$",
"fieldName",
"=",
"substr",
"(",
"$",
"fieldName",
",",
"0",
",",
"-",
"5",
")",
";",
"$",
"pluralize",
"=",
"false",
";",
"}",
"elseif",
"(",
"substr",
"(",
"$",
"fieldName",
",",
"-",
"3",
")",
"===",
"'_id'",
")",
"{",
"$",
"fieldName",
"=",
"substr",
"(",
"$",
"fieldName",
",",
"0",
",",
"-",
"3",
")",
";",
"}",
"$",
"fieldName",
"=",
"array_slice",
"(",
"explode",
"(",
"'.'",
",",
"$",
"fieldName",
")",
",",
"-",
"1",
")",
"[",
"0",
"]",
";",
"$",
"varName",
"=",
"Inflector",
"::",
"variable",
"(",
"$",
"pluralize",
"?",
"Inflector",
"::",
"pluralize",
"(",
"$",
"fieldName",
")",
":",
"$",
"fieldName",
")",
";",
"$",
"varOptions",
"=",
"$",
"this",
"->",
"_View",
"->",
"get",
"(",
"$",
"varName",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"varOptions",
")",
"&&",
"!",
"(",
"$",
"varOptions",
"instanceof",
"Traversable",
")",
")",
"{",
"return",
"$",
"options",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'type'",
"]",
"!==",
"'radio'",
")",
"{",
"$",
"options",
"[",
"'type'",
"]",
"=",
"'select'",
";",
"}",
"$",
"options",
"[",
"'options'",
"]",
"=",
"$",
"varOptions",
";",
"return",
"$",
"options",
";",
"}"
] | Selects the variable containing the options for a select field if present,
and sets the value to the 'options' key in the options array.
@param string $fieldName The name of the field to find options for.
@param array $options Options list.
@return array | [
"Selects",
"the",
"variable",
"containing",
"the",
"options",
"for",
"a",
"select",
"field",
"if",
"present",
"and",
"sets",
"the",
"value",
"to",
"the",
"options",
"key",
"in",
"the",
"options",
"array",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L1411-L1439 |
211,708 | cakephp/cakephp | src/View/Helper/FormHelper.php | FormHelper.radio | public function radio($fieldName, $options = [], array $attributes = [])
{
$attributes['options'] = $options;
$attributes['idPrefix'] = $this->_idPrefix;
$attributes = $this->_initInputField($fieldName, $attributes);
$hiddenField = isset($attributes['hiddenField']) ? $attributes['hiddenField'] : true;
unset($attributes['hiddenField']);
$radio = $this->widget('radio', $attributes);
$hidden = '';
if ($hiddenField) {
$hidden = $this->hidden($fieldName, [
'value' => $hiddenField === true ? '' : $hiddenField,
'form' => isset($attributes['form']) ? $attributes['form'] : null,
'name' => $attributes['name'],
]);
}
return $hidden . $radio;
} | php | public function radio($fieldName, $options = [], array $attributes = [])
{
$attributes['options'] = $options;
$attributes['idPrefix'] = $this->_idPrefix;
$attributes = $this->_initInputField($fieldName, $attributes);
$hiddenField = isset($attributes['hiddenField']) ? $attributes['hiddenField'] : true;
unset($attributes['hiddenField']);
$radio = $this->widget('radio', $attributes);
$hidden = '';
if ($hiddenField) {
$hidden = $this->hidden($fieldName, [
'value' => $hiddenField === true ? '' : $hiddenField,
'form' => isset($attributes['form']) ? $attributes['form'] : null,
'name' => $attributes['name'],
]);
}
return $hidden . $radio;
} | [
"public",
"function",
"radio",
"(",
"$",
"fieldName",
",",
"$",
"options",
"=",
"[",
"]",
",",
"array",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"$",
"attributes",
"[",
"'options'",
"]",
"=",
"$",
"options",
";",
"$",
"attributes",
"[",
"'idPrefix'",
"]",
"=",
"$",
"this",
"->",
"_idPrefix",
";",
"$",
"attributes",
"=",
"$",
"this",
"->",
"_initInputField",
"(",
"$",
"fieldName",
",",
"$",
"attributes",
")",
";",
"$",
"hiddenField",
"=",
"isset",
"(",
"$",
"attributes",
"[",
"'hiddenField'",
"]",
")",
"?",
"$",
"attributes",
"[",
"'hiddenField'",
"]",
":",
"true",
";",
"unset",
"(",
"$",
"attributes",
"[",
"'hiddenField'",
"]",
")",
";",
"$",
"radio",
"=",
"$",
"this",
"->",
"widget",
"(",
"'radio'",
",",
"$",
"attributes",
")",
";",
"$",
"hidden",
"=",
"''",
";",
"if",
"(",
"$",
"hiddenField",
")",
"{",
"$",
"hidden",
"=",
"$",
"this",
"->",
"hidden",
"(",
"$",
"fieldName",
",",
"[",
"'value'",
"=>",
"$",
"hiddenField",
"===",
"true",
"?",
"''",
":",
"$",
"hiddenField",
",",
"'form'",
"=>",
"isset",
"(",
"$",
"attributes",
"[",
"'form'",
"]",
")",
"?",
"$",
"attributes",
"[",
"'form'",
"]",
":",
"null",
",",
"'name'",
"=>",
"$",
"attributes",
"[",
"'name'",
"]",
",",
"]",
")",
";",
"}",
"return",
"$",
"hidden",
".",
"$",
"radio",
";",
"}"
] | Creates a set of radio widgets.
### Attributes:
- `value` - Indicates the value when this radio button is checked.
- `label` - Either `false` to disable label around the widget or an array of attributes for
the label tag. `selected` will be added to any classes e.g. `'class' => 'myclass'` where widget
is checked
- `hiddenField` - boolean to indicate if you want the results of radio() to include
a hidden input with a value of ''. This is useful for creating radio sets that are non-continuous.
- `disabled` - Set to `true` or `disabled` to disable all the radio buttons. Use an array of
values to disable specific radio buttons.
- `empty` - Set to `true` to create an input with the value '' as the first option. When `true`
the radio label will be 'empty'. Set this option to a string to control the label value.
@param string $fieldName Name of a field, like this "modelname.fieldname"
@param array|\Traversable $options Radio button options array.
@param array $attributes Array of attributes.
@return string Completed radio widget set.
@link https://book.cakephp.org/3.0/en/views/helpers/form.html#creating-radio-buttons | [
"Creates",
"a",
"set",
"of",
"radio",
"widgets",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L1690-L1711 |
211,709 | cakephp/cakephp | src/View/Helper/FormHelper.php | FormHelper.textarea | public function textarea($fieldName, array $options = [])
{
$options = $this->_initInputField($fieldName, $options);
unset($options['type']);
return $this->widget('textarea', $options);
} | php | public function textarea($fieldName, array $options = [])
{
$options = $this->_initInputField($fieldName, $options);
unset($options['type']);
return $this->widget('textarea', $options);
} | [
"public",
"function",
"textarea",
"(",
"$",
"fieldName",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"_initInputField",
"(",
"$",
"fieldName",
",",
"$",
"options",
")",
";",
"unset",
"(",
"$",
"options",
"[",
"'type'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"widget",
"(",
"'textarea'",
",",
"$",
"options",
")",
";",
"}"
] | Creates a textarea widget.
### Options:
- `escape` - Whether or not the contents of the textarea should be escaped. Defaults to true.
@param string $fieldName Name of a field, in the form "modelname.fieldname"
@param array $options Array of HTML attributes, and special options above.
@return string A generated HTML text input element
@link https://book.cakephp.org/3.0/en/views/helpers/form.html#creating-textareas | [
"Creates",
"a",
"textarea",
"widget",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L1765-L1771 |
211,710 | cakephp/cakephp | src/View/Helper/FormHelper.php | FormHelper.hidden | public function hidden($fieldName, array $options = [])
{
$options += ['required' => false, 'secure' => true];
$secure = $options['secure'];
unset($options['secure']);
$options = $this->_initInputField($fieldName, array_merge(
$options,
['secure' => static::SECURE_SKIP]
));
if ($secure === true) {
$this->_secure(true, $this->_secureFieldName($options['name']), (string)$options['val']);
}
$options['type'] = 'hidden';
return $this->widget('hidden', $options);
} | php | public function hidden($fieldName, array $options = [])
{
$options += ['required' => false, 'secure' => true];
$secure = $options['secure'];
unset($options['secure']);
$options = $this->_initInputField($fieldName, array_merge(
$options,
['secure' => static::SECURE_SKIP]
));
if ($secure === true) {
$this->_secure(true, $this->_secureFieldName($options['name']), (string)$options['val']);
}
$options['type'] = 'hidden';
return $this->widget('hidden', $options);
} | [
"public",
"function",
"hidden",
"(",
"$",
"fieldName",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"+=",
"[",
"'required'",
"=>",
"false",
",",
"'secure'",
"=>",
"true",
"]",
";",
"$",
"secure",
"=",
"$",
"options",
"[",
"'secure'",
"]",
";",
"unset",
"(",
"$",
"options",
"[",
"'secure'",
"]",
")",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"_initInputField",
"(",
"$",
"fieldName",
",",
"array_merge",
"(",
"$",
"options",
",",
"[",
"'secure'",
"=>",
"static",
"::",
"SECURE_SKIP",
"]",
")",
")",
";",
"if",
"(",
"$",
"secure",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"_secure",
"(",
"true",
",",
"$",
"this",
"->",
"_secureFieldName",
"(",
"$",
"options",
"[",
"'name'",
"]",
")",
",",
"(",
"string",
")",
"$",
"options",
"[",
"'val'",
"]",
")",
";",
"}",
"$",
"options",
"[",
"'type'",
"]",
"=",
"'hidden'",
";",
"return",
"$",
"this",
"->",
"widget",
"(",
"'hidden'",
",",
"$",
"options",
")",
";",
"}"
] | Creates a hidden input field.
@param string $fieldName Name of a field, in the form of "modelname.fieldname"
@param array $options Array of HTML attributes.
@return string A generated hidden input
@link https://book.cakephp.org/3.0/en/views/helpers/form.html#creating-hidden-inputs | [
"Creates",
"a",
"hidden",
"input",
"field",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L1781-L1800 |
211,711 | cakephp/cakephp | src/View/Helper/FormHelper.php | FormHelper.multiCheckbox | public function multiCheckbox($fieldName, $options, array $attributes = [])
{
$attributes += [
'disabled' => null,
'escape' => true,
'hiddenField' => true,
'secure' => true,
];
$attributes = $this->_initInputField($fieldName, $attributes);
$attributes['options'] = $options;
$attributes['idPrefix'] = $this->_idPrefix;
$hidden = '';
if ($attributes['hiddenField']) {
$hiddenAttributes = [
'name' => $attributes['name'],
'value' => '',
'secure' => false,
'disabled' => $attributes['disabled'] === true || $attributes['disabled'] === 'disabled',
];
$hidden = $this->hidden($fieldName, $hiddenAttributes);
}
unset($attributes['hiddenField']);
return $hidden . $this->widget('multicheckbox', $attributes);
} | php | public function multiCheckbox($fieldName, $options, array $attributes = [])
{
$attributes += [
'disabled' => null,
'escape' => true,
'hiddenField' => true,
'secure' => true,
];
$attributes = $this->_initInputField($fieldName, $attributes);
$attributes['options'] = $options;
$attributes['idPrefix'] = $this->_idPrefix;
$hidden = '';
if ($attributes['hiddenField']) {
$hiddenAttributes = [
'name' => $attributes['name'],
'value' => '',
'secure' => false,
'disabled' => $attributes['disabled'] === true || $attributes['disabled'] === 'disabled',
];
$hidden = $this->hidden($fieldName, $hiddenAttributes);
}
unset($attributes['hiddenField']);
return $hidden . $this->widget('multicheckbox', $attributes);
} | [
"public",
"function",
"multiCheckbox",
"(",
"$",
"fieldName",
",",
"$",
"options",
",",
"array",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"$",
"attributes",
"+=",
"[",
"'disabled'",
"=>",
"null",
",",
"'escape'",
"=>",
"true",
",",
"'hiddenField'",
"=>",
"true",
",",
"'secure'",
"=>",
"true",
",",
"]",
";",
"$",
"attributes",
"=",
"$",
"this",
"->",
"_initInputField",
"(",
"$",
"fieldName",
",",
"$",
"attributes",
")",
";",
"$",
"attributes",
"[",
"'options'",
"]",
"=",
"$",
"options",
";",
"$",
"attributes",
"[",
"'idPrefix'",
"]",
"=",
"$",
"this",
"->",
"_idPrefix",
";",
"$",
"hidden",
"=",
"''",
";",
"if",
"(",
"$",
"attributes",
"[",
"'hiddenField'",
"]",
")",
"{",
"$",
"hiddenAttributes",
"=",
"[",
"'name'",
"=>",
"$",
"attributes",
"[",
"'name'",
"]",
",",
"'value'",
"=>",
"''",
",",
"'secure'",
"=>",
"false",
",",
"'disabled'",
"=>",
"$",
"attributes",
"[",
"'disabled'",
"]",
"===",
"true",
"||",
"$",
"attributes",
"[",
"'disabled'",
"]",
"===",
"'disabled'",
",",
"]",
";",
"$",
"hidden",
"=",
"$",
"this",
"->",
"hidden",
"(",
"$",
"fieldName",
",",
"$",
"hiddenAttributes",
")",
";",
"}",
"unset",
"(",
"$",
"attributes",
"[",
"'hiddenField'",
"]",
")",
";",
"return",
"$",
"hidden",
".",
"$",
"this",
"->",
"widget",
"(",
"'multicheckbox'",
",",
"$",
"attributes",
")",
";",
"}"
] | Creates a set of checkboxes out of options.
### Options
- `escape` - If true contents of options will be HTML entity encoded. Defaults to true.
- `val` The selected value of the input.
- `class` - When using multiple = checkbox the class name to apply to the divs. Defaults to 'checkbox'.
- `disabled` - Control the disabled attribute. When creating checkboxes, `true` will disable all checkboxes.
You can also set disabled to a list of values you want to disable when creating checkboxes.
- `hiddenField` - Set to false to remove the hidden field that ensures a value
is always submitted.
- `label` - Either `false` to disable label around the widget or an array of attributes for
the label tag. `selected` will be added to any classes e.g. `'class' => 'myclass'` where
widget is checked
Can be used in place of a select box with the multiple attribute.
@param string $fieldName Name attribute of the SELECT
@param array|\Traversable $options Array of the OPTION elements
(as 'value'=>'Text' pairs) to be used in the checkboxes element.
@param array $attributes The HTML attributes of the select element.
@return string Formatted SELECT element
@see \Cake\View\Helper\FormHelper::select() for supported option formats. | [
"Creates",
"a",
"set",
"of",
"checkboxes",
"out",
"of",
"options",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L2212-L2237 |
211,712 | cakephp/cakephp | src/View/Helper/FormHelper.php | FormHelper._singleDatetime | protected function _singleDatetime($options, $keep)
{
$off = array_diff($this->_datetimeParts, [$keep]);
$off = array_combine(
$off,
array_fill(0, count($off), false)
);
$attributes = array_diff_key(
$options,
array_flip(array_merge($this->_datetimeOptions, ['value', 'empty']))
);
$options = $options + $off + [$keep => $attributes];
if (isset($options['value'])) {
$options['val'] = $options['value'];
}
return $options;
} | php | protected function _singleDatetime($options, $keep)
{
$off = array_diff($this->_datetimeParts, [$keep]);
$off = array_combine(
$off,
array_fill(0, count($off), false)
);
$attributes = array_diff_key(
$options,
array_flip(array_merge($this->_datetimeOptions, ['value', 'empty']))
);
$options = $options + $off + [$keep => $attributes];
if (isset($options['value'])) {
$options['val'] = $options['value'];
}
return $options;
} | [
"protected",
"function",
"_singleDatetime",
"(",
"$",
"options",
",",
"$",
"keep",
")",
"{",
"$",
"off",
"=",
"array_diff",
"(",
"$",
"this",
"->",
"_datetimeParts",
",",
"[",
"$",
"keep",
"]",
")",
";",
"$",
"off",
"=",
"array_combine",
"(",
"$",
"off",
",",
"array_fill",
"(",
"0",
",",
"count",
"(",
"$",
"off",
")",
",",
"false",
")",
")",
";",
"$",
"attributes",
"=",
"array_diff_key",
"(",
"$",
"options",
",",
"array_flip",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"_datetimeOptions",
",",
"[",
"'value'",
",",
"'empty'",
"]",
")",
")",
")",
";",
"$",
"options",
"=",
"$",
"options",
"+",
"$",
"off",
"+",
"[",
"$",
"keep",
"=>",
"$",
"attributes",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'value'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'val'",
"]",
"=",
"$",
"options",
"[",
"'value'",
"]",
";",
"}",
"return",
"$",
"options",
";",
"}"
] | Helper method for the various single datetime component methods.
@param array $options The options array.
@param string $keep The option to not disable.
@return array | [
"Helper",
"method",
"for",
"the",
"various",
"single",
"datetime",
"component",
"methods",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L2246-L2265 |
211,713 | cakephp/cakephp | src/View/Helper/FormHelper.php | FormHelper.day | public function day($fieldName = null, array $options = [])
{
$options = $this->_singleDatetime($options, 'day');
if (isset($options['val']) && $options['val'] > 0 && $options['val'] <= 31) {
$options['val'] = [
'year' => date('Y'),
'month' => date('m'),
'day' => (int)$options['val']
];
}
return $this->dateTime($fieldName, $options);
} | php | public function day($fieldName = null, array $options = [])
{
$options = $this->_singleDatetime($options, 'day');
if (isset($options['val']) && $options['val'] > 0 && $options['val'] <= 31) {
$options['val'] = [
'year' => date('Y'),
'month' => date('m'),
'day' => (int)$options['val']
];
}
return $this->dateTime($fieldName, $options);
} | [
"public",
"function",
"day",
"(",
"$",
"fieldName",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"_singleDatetime",
"(",
"$",
"options",
",",
"'day'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'val'",
"]",
")",
"&&",
"$",
"options",
"[",
"'val'",
"]",
">",
"0",
"&&",
"$",
"options",
"[",
"'val'",
"]",
"<=",
"31",
")",
"{",
"$",
"options",
"[",
"'val'",
"]",
"=",
"[",
"'year'",
"=>",
"date",
"(",
"'Y'",
")",
",",
"'month'",
"=>",
"date",
"(",
"'m'",
")",
",",
"'day'",
"=>",
"(",
"int",
")",
"$",
"options",
"[",
"'val'",
"]",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"dateTime",
"(",
"$",
"fieldName",
",",
"$",
"options",
")",
";",
"}"
] | Returns a SELECT element for days.
### Options:
- `empty` - If true, the empty select option is shown. If a string,
that string is displayed as the empty element.
- `value` The selected value of the input.
@param string|null $fieldName Prefix name for the SELECT element
@param array $options Options & HTML attributes for the select element
@return string A generated day select box.
@link https://book.cakephp.org/3.0/en/views/helpers/form.html#creating-day-inputs | [
"Returns",
"a",
"SELECT",
"element",
"for",
"days",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L2281-L2294 |
211,714 | cakephp/cakephp | src/View/Helper/FormHelper.php | FormHelper.year | public function year($fieldName, array $options = [])
{
$options = $this->_singleDatetime($options, 'year');
$len = isset($options['val']) ? strlen($options['val']) : 0;
if (isset($options['val']) && $len > 0 && $len < 5) {
$options['val'] = [
'year' => (int)$options['val'],
'month' => date('m'),
'day' => date('d')
];
}
return $this->dateTime($fieldName, $options);
} | php | public function year($fieldName, array $options = [])
{
$options = $this->_singleDatetime($options, 'year');
$len = isset($options['val']) ? strlen($options['val']) : 0;
if (isset($options['val']) && $len > 0 && $len < 5) {
$options['val'] = [
'year' => (int)$options['val'],
'month' => date('m'),
'day' => date('d')
];
}
return $this->dateTime($fieldName, $options);
} | [
"public",
"function",
"year",
"(",
"$",
"fieldName",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"_singleDatetime",
"(",
"$",
"options",
",",
"'year'",
")",
";",
"$",
"len",
"=",
"isset",
"(",
"$",
"options",
"[",
"'val'",
"]",
")",
"?",
"strlen",
"(",
"$",
"options",
"[",
"'val'",
"]",
")",
":",
"0",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'val'",
"]",
")",
"&&",
"$",
"len",
">",
"0",
"&&",
"$",
"len",
"<",
"5",
")",
"{",
"$",
"options",
"[",
"'val'",
"]",
"=",
"[",
"'year'",
"=>",
"(",
"int",
")",
"$",
"options",
"[",
"'val'",
"]",
",",
"'month'",
"=>",
"date",
"(",
"'m'",
")",
",",
"'day'",
"=>",
"date",
"(",
"'d'",
")",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"dateTime",
"(",
"$",
"fieldName",
",",
"$",
"options",
")",
";",
"}"
] | Returns a SELECT element for years
### Attributes:
- `empty` - If true, the empty select option is shown. If a string,
that string is displayed as the empty element.
- `orderYear` - Ordering of year values in select options.
Possible values 'asc', 'desc'. Default 'desc'
- `value` The selected value of the input.
- `maxYear` The max year to appear in the select element.
- `minYear` The min year to appear in the select element.
@param string $fieldName Prefix name for the SELECT element
@param array $options Options & attributes for the select elements.
@return string Completed year select input
@link https://book.cakephp.org/3.0/en/views/helpers/form.html#creating-year-inputs | [
"Returns",
"a",
"SELECT",
"element",
"for",
"years"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L2314-L2328 |
211,715 | cakephp/cakephp | src/View/Helper/FormHelper.php | FormHelper.month | public function month($fieldName, array $options = [])
{
$options = $this->_singleDatetime($options, 'month');
if (isset($options['val']) && $options['val'] > 0 && $options['val'] <= 12) {
$options['val'] = [
'year' => date('Y'),
'month' => (int)$options['val'],
'day' => date('d')
];
}
return $this->dateTime($fieldName, $options);
} | php | public function month($fieldName, array $options = [])
{
$options = $this->_singleDatetime($options, 'month');
if (isset($options['val']) && $options['val'] > 0 && $options['val'] <= 12) {
$options['val'] = [
'year' => date('Y'),
'month' => (int)$options['val'],
'day' => date('d')
];
}
return $this->dateTime($fieldName, $options);
} | [
"public",
"function",
"month",
"(",
"$",
"fieldName",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"_singleDatetime",
"(",
"$",
"options",
",",
"'month'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'val'",
"]",
")",
"&&",
"$",
"options",
"[",
"'val'",
"]",
">",
"0",
"&&",
"$",
"options",
"[",
"'val'",
"]",
"<=",
"12",
")",
"{",
"$",
"options",
"[",
"'val'",
"]",
"=",
"[",
"'year'",
"=>",
"date",
"(",
"'Y'",
")",
",",
"'month'",
"=>",
"(",
"int",
")",
"$",
"options",
"[",
"'val'",
"]",
",",
"'day'",
"=>",
"date",
"(",
"'d'",
")",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"dateTime",
"(",
"$",
"fieldName",
",",
"$",
"options",
")",
";",
"}"
] | Returns a SELECT element for months.
### Options:
- `monthNames` - If false, 2 digit numbers will be used instead of text.
If an array, the given array will be used.
- `empty` - If true, the empty select option is shown. If a string,
that string is displayed as the empty element.
- `value` The selected value of the input.
@param string $fieldName Prefix name for the SELECT element
@param array $options Attributes for the select element
@return string A generated month select dropdown.
@link https://book.cakephp.org/3.0/en/views/helpers/form.html#creating-month-inputs | [
"Returns",
"a",
"SELECT",
"element",
"for",
"months",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L2346-L2359 |
211,716 | cakephp/cakephp | src/View/Helper/FormHelper.php | FormHelper.meridian | public function meridian($fieldName, array $options = [])
{
$options = $this->_singleDatetime($options, 'meridian');
if (isset($options['val'])) {
$hour = date('H');
$options['val'] = [
'hour' => $hour,
'minute' => (int)$options['val'],
'meridian' => $hour > 11 ? 'pm' : 'am',
];
}
return $this->dateTime($fieldName, $options);
} | php | public function meridian($fieldName, array $options = [])
{
$options = $this->_singleDatetime($options, 'meridian');
if (isset($options['val'])) {
$hour = date('H');
$options['val'] = [
'hour' => $hour,
'minute' => (int)$options['val'],
'meridian' => $hour > 11 ? 'pm' : 'am',
];
}
return $this->dateTime($fieldName, $options);
} | [
"public",
"function",
"meridian",
"(",
"$",
"fieldName",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"_singleDatetime",
"(",
"$",
"options",
",",
"'meridian'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'val'",
"]",
")",
")",
"{",
"$",
"hour",
"=",
"date",
"(",
"'H'",
")",
";",
"$",
"options",
"[",
"'val'",
"]",
"=",
"[",
"'hour'",
"=>",
"$",
"hour",
",",
"'minute'",
"=>",
"(",
"int",
")",
"$",
"options",
"[",
"'val'",
"]",
",",
"'meridian'",
"=>",
"$",
"hour",
">",
"11",
"?",
"'pm'",
":",
"'am'",
",",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"dateTime",
"(",
"$",
"fieldName",
",",
"$",
"options",
")",
";",
"}"
] | Returns a SELECT element for AM or PM.
### Attributes:
- `empty` - If true, the empty select option is shown. If a string,
that string is displayed as the empty element.
- `value` The selected value of the input.
@param string $fieldName Prefix name for the SELECT element
@param array $options Array of options
@return string Completed meridian select input
@link https://book.cakephp.org/3.0/en/views/helpers/form.html#creating-meridian-inputs | [
"Returns",
"a",
"SELECT",
"element",
"for",
"AM",
"or",
"PM",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L2439-L2453 |
211,717 | cakephp/cakephp | src/View/Helper/FormHelper.php | FormHelper._isDisabled | protected function _isDisabled(array $options)
{
if (!isset($options['disabled'])) {
return false;
}
if (is_scalar($options['disabled'])) {
return ($options['disabled'] === true || $options['disabled'] === 'disabled');
}
if (!isset($options['options'])) {
return false;
}
if (is_array($options['options'])) {
// Simple list options
$first = $options['options'][array_keys($options['options'])[0]];
if (is_scalar($first)) {
return array_diff($options['options'], $options['disabled']) === [];
}
// Complex option types
if (is_array($first)) {
$disabled = array_filter($options['options'], function ($i) use ($options) {
return in_array($i['value'], $options['disabled']);
});
return count($disabled) > 0;
}
}
return false;
} | php | protected function _isDisabled(array $options)
{
if (!isset($options['disabled'])) {
return false;
}
if (is_scalar($options['disabled'])) {
return ($options['disabled'] === true || $options['disabled'] === 'disabled');
}
if (!isset($options['options'])) {
return false;
}
if (is_array($options['options'])) {
// Simple list options
$first = $options['options'][array_keys($options['options'])[0]];
if (is_scalar($first)) {
return array_diff($options['options'], $options['disabled']) === [];
}
// Complex option types
if (is_array($first)) {
$disabled = array_filter($options['options'], function ($i) use ($options) {
return in_array($i['value'], $options['disabled']);
});
return count($disabled) > 0;
}
}
return false;
} | [
"protected",
"function",
"_isDisabled",
"(",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'disabled'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"is_scalar",
"(",
"$",
"options",
"[",
"'disabled'",
"]",
")",
")",
"{",
"return",
"(",
"$",
"options",
"[",
"'disabled'",
"]",
"===",
"true",
"||",
"$",
"options",
"[",
"'disabled'",
"]",
"===",
"'disabled'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'options'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"options",
"[",
"'options'",
"]",
")",
")",
"{",
"// Simple list options",
"$",
"first",
"=",
"$",
"options",
"[",
"'options'",
"]",
"[",
"array_keys",
"(",
"$",
"options",
"[",
"'options'",
"]",
")",
"[",
"0",
"]",
"]",
";",
"if",
"(",
"is_scalar",
"(",
"$",
"first",
")",
")",
"{",
"return",
"array_diff",
"(",
"$",
"options",
"[",
"'options'",
"]",
",",
"$",
"options",
"[",
"'disabled'",
"]",
")",
"===",
"[",
"]",
";",
"}",
"// Complex option types",
"if",
"(",
"is_array",
"(",
"$",
"first",
")",
")",
"{",
"$",
"disabled",
"=",
"array_filter",
"(",
"$",
"options",
"[",
"'options'",
"]",
",",
"function",
"(",
"$",
"i",
")",
"use",
"(",
"$",
"options",
")",
"{",
"return",
"in_array",
"(",
"$",
"i",
"[",
"'value'",
"]",
",",
"$",
"options",
"[",
"'disabled'",
"]",
")",
";",
"}",
")",
";",
"return",
"count",
"(",
"$",
"disabled",
")",
">",
"0",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Determine if a field is disabled.
@param array $options The option set.
@return bool Whether or not the field is disabled. | [
"Determine",
"if",
"a",
"field",
"is",
"disabled",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L2736-L2764 |
211,718 | cakephp/cakephp | src/View/Helper/FormHelper.php | FormHelper.context | public function context($context = null)
{
if ($context instanceof ContextInterface) {
$this->_context = $context;
}
return $this->_getContext();
} | php | public function context($context = null)
{
if ($context instanceof ContextInterface) {
$this->_context = $context;
}
return $this->_getContext();
} | [
"public",
"function",
"context",
"(",
"$",
"context",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"context",
"instanceof",
"ContextInterface",
")",
"{",
"$",
"this",
"->",
"_context",
"=",
"$",
"context",
";",
"}",
"return",
"$",
"this",
"->",
"_getContext",
"(",
")",
";",
"}"
] | Get the context instance for the current form set.
If there is no active form null will be returned.
@param \Cake\View\Form\ContextInterface|null $context Either the new context when setting, or null to get.
@return \Cake\View\Form\ContextInterface The context for the form. | [
"Get",
"the",
"context",
"instance",
"for",
"the",
"current",
"form",
"set",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L2822-L2829 |
211,719 | cakephp/cakephp | src/View/Helper/FormHelper.php | FormHelper._getContext | protected function _getContext($data = [])
{
if (isset($this->_context) && empty($data)) {
return $this->_context;
}
$data += ['entity' => null];
return $this->_context = $this->contextFactory()
->get($this->_View->getRequest(), $data);
} | php | protected function _getContext($data = [])
{
if (isset($this->_context) && empty($data)) {
return $this->_context;
}
$data += ['entity' => null];
return $this->_context = $this->contextFactory()
->get($this->_View->getRequest(), $data);
} | [
"protected",
"function",
"_getContext",
"(",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_context",
")",
"&&",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_context",
";",
"}",
"$",
"data",
"+=",
"[",
"'entity'",
"=>",
"null",
"]",
";",
"return",
"$",
"this",
"->",
"_context",
"=",
"$",
"this",
"->",
"contextFactory",
"(",
")",
"->",
"get",
"(",
"$",
"this",
"->",
"_View",
"->",
"getRequest",
"(",
")",
",",
"$",
"data",
")",
";",
"}"
] | Find the matching context provider for the data.
If no type can be matched a NullContext will be returned.
@param mixed $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",
"provider",
"for",
"the",
"data",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L2841-L2850 |
211,720 | cakephp/cakephp | src/View/Helper/FormHelper.php | FormHelper.widget | public function widget($name, array $data = [])
{
$secure = null;
if (isset($data['secure'])) {
$secure = $data['secure'];
unset($data['secure']);
}
$widget = $this->_locator->get($name);
$out = $widget->render($data, $this->context());
if (isset($data['name']) && $secure !== null && $secure !== self::SECURE_SKIP) {
foreach ($widget->secureFields($data) as $field) {
$this->_secure($secure, $this->_secureFieldName($field));
}
}
return $out;
} | php | public function widget($name, array $data = [])
{
$secure = null;
if (isset($data['secure'])) {
$secure = $data['secure'];
unset($data['secure']);
}
$widget = $this->_locator->get($name);
$out = $widget->render($data, $this->context());
if (isset($data['name']) && $secure !== null && $secure !== self::SECURE_SKIP) {
foreach ($widget->secureFields($data) as $field) {
$this->_secure($secure, $this->_secureFieldName($field));
}
}
return $out;
} | [
"public",
"function",
"widget",
"(",
"$",
"name",
",",
"array",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"secure",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'secure'",
"]",
")",
")",
"{",
"$",
"secure",
"=",
"$",
"data",
"[",
"'secure'",
"]",
";",
"unset",
"(",
"$",
"data",
"[",
"'secure'",
"]",
")",
";",
"}",
"$",
"widget",
"=",
"$",
"this",
"->",
"_locator",
"->",
"get",
"(",
"$",
"name",
")",
";",
"$",
"out",
"=",
"$",
"widget",
"->",
"render",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"context",
"(",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'name'",
"]",
")",
"&&",
"$",
"secure",
"!==",
"null",
"&&",
"$",
"secure",
"!==",
"self",
"::",
"SECURE_SKIP",
")",
"{",
"foreach",
"(",
"$",
"widget",
"->",
"secureFields",
"(",
"$",
"data",
")",
"as",
"$",
"field",
")",
"{",
"$",
"this",
"->",
"_secure",
"(",
"$",
"secure",
",",
"$",
"this",
"->",
"_secureFieldName",
"(",
"$",
"field",
")",
")",
";",
"}",
"}",
"return",
"$",
"out",
";",
"}"
] | Render a named widget.
This is a lower level method. For built-in widgets, you should be using
methods like `text`, `hidden`, and `radio`. If you are using additional
widgets you should use this method render the widget without the label
or wrapping div.
@param string $name The name of the widget. e.g. 'text'.
@param array $data The data to render.
@return string | [
"Render",
"a",
"named",
"widget",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L2879-L2895 |
211,721 | cakephp/cakephp | src/View/Helper/FormHelper.php | FormHelper.getSourceValue | public function getSourceValue($fieldname, $options = [])
{
$valueMap = [
'data' => 'getData',
'query' => 'getQuery'
];
foreach ($this->getValueSources() as $valuesSource) {
if ($valuesSource === 'context') {
$val = $this->_getContext()->val($fieldname, $options);
if ($val !== null) {
return $val;
}
}
if (isset($valueMap[$valuesSource])) {
$method = $valueMap[$valuesSource];
$value = $this->_View->getRequest()->{$method}($fieldname);
if ($value !== null) {
return $value;
}
}
}
return null;
} | php | public function getSourceValue($fieldname, $options = [])
{
$valueMap = [
'data' => 'getData',
'query' => 'getQuery'
];
foreach ($this->getValueSources() as $valuesSource) {
if ($valuesSource === 'context') {
$val = $this->_getContext()->val($fieldname, $options);
if ($val !== null) {
return $val;
}
}
if (isset($valueMap[$valuesSource])) {
$method = $valueMap[$valuesSource];
$value = $this->_View->getRequest()->{$method}($fieldname);
if ($value !== null) {
return $value;
}
}
}
return null;
} | [
"public",
"function",
"getSourceValue",
"(",
"$",
"fieldname",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"valueMap",
"=",
"[",
"'data'",
"=>",
"'getData'",
",",
"'query'",
"=>",
"'getQuery'",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getValueSources",
"(",
")",
"as",
"$",
"valuesSource",
")",
"{",
"if",
"(",
"$",
"valuesSource",
"===",
"'context'",
")",
"{",
"$",
"val",
"=",
"$",
"this",
"->",
"_getContext",
"(",
")",
"->",
"val",
"(",
"$",
"fieldname",
",",
"$",
"options",
")",
";",
"if",
"(",
"$",
"val",
"!==",
"null",
")",
"{",
"return",
"$",
"val",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"valueMap",
"[",
"$",
"valuesSource",
"]",
")",
")",
"{",
"$",
"method",
"=",
"$",
"valueMap",
"[",
"$",
"valuesSource",
"]",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"_View",
"->",
"getRequest",
"(",
")",
"->",
"{",
"$",
"method",
"}",
"(",
"$",
"fieldname",
")",
";",
"if",
"(",
"$",
"value",
"!==",
"null",
")",
"{",
"return",
"$",
"value",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] | Gets a single field value from the sources available.
@param string $fieldname The fieldname to fetch the value for.
@param array|null $options The options containing default values.
@return string|null Field value derived from sources or defaults. | [
"Gets",
"a",
"single",
"field",
"value",
"from",
"the",
"sources",
"available",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/FormHelper.php#L2954-L2977 |
211,722 | cakephp/cakephp | src/Shell/Task/CommandTask.php | CommandTask.getShellList | public function getShellList()
{
$skipFiles = ['app'];
$hiddenCommands = ['command_list', 'completion'];
$plugins = Plugin::loaded();
$shellList = array_fill_keys($plugins, null) + ['CORE' => null, 'app' => null];
$appPath = App::path('Shell');
$shellList = $this->_findShells($shellList, $appPath[0], 'app', $skipFiles);
$appPath = App::path('Command');
$shellList = $this->_findShells($shellList, $appPath[0], 'app', $skipFiles);
$skipCore = array_merge($skipFiles, $hiddenCommands, $shellList['app']);
$corePath = dirname(__DIR__);
$shellList = $this->_findShells($shellList, $corePath, 'CORE', $skipCore);
$corePath = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Command';
$shellList = $this->_findShells($shellList, $corePath, 'CORE', $skipCore);
foreach ($plugins as $plugin) {
$pluginPath = Plugin::classPath($plugin) . 'Shell';
$shellList = $this->_findShells($shellList, $pluginPath, $plugin, []);
}
return array_filter($shellList);
} | php | public function getShellList()
{
$skipFiles = ['app'];
$hiddenCommands = ['command_list', 'completion'];
$plugins = Plugin::loaded();
$shellList = array_fill_keys($plugins, null) + ['CORE' => null, 'app' => null];
$appPath = App::path('Shell');
$shellList = $this->_findShells($shellList, $appPath[0], 'app', $skipFiles);
$appPath = App::path('Command');
$shellList = $this->_findShells($shellList, $appPath[0], 'app', $skipFiles);
$skipCore = array_merge($skipFiles, $hiddenCommands, $shellList['app']);
$corePath = dirname(__DIR__);
$shellList = $this->_findShells($shellList, $corePath, 'CORE', $skipCore);
$corePath = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Command';
$shellList = $this->_findShells($shellList, $corePath, 'CORE', $skipCore);
foreach ($plugins as $plugin) {
$pluginPath = Plugin::classPath($plugin) . 'Shell';
$shellList = $this->_findShells($shellList, $pluginPath, $plugin, []);
}
return array_filter($shellList);
} | [
"public",
"function",
"getShellList",
"(",
")",
"{",
"$",
"skipFiles",
"=",
"[",
"'app'",
"]",
";",
"$",
"hiddenCommands",
"=",
"[",
"'command_list'",
",",
"'completion'",
"]",
";",
"$",
"plugins",
"=",
"Plugin",
"::",
"loaded",
"(",
")",
";",
"$",
"shellList",
"=",
"array_fill_keys",
"(",
"$",
"plugins",
",",
"null",
")",
"+",
"[",
"'CORE'",
"=>",
"null",
",",
"'app'",
"=>",
"null",
"]",
";",
"$",
"appPath",
"=",
"App",
"::",
"path",
"(",
"'Shell'",
")",
";",
"$",
"shellList",
"=",
"$",
"this",
"->",
"_findShells",
"(",
"$",
"shellList",
",",
"$",
"appPath",
"[",
"0",
"]",
",",
"'app'",
",",
"$",
"skipFiles",
")",
";",
"$",
"appPath",
"=",
"App",
"::",
"path",
"(",
"'Command'",
")",
";",
"$",
"shellList",
"=",
"$",
"this",
"->",
"_findShells",
"(",
"$",
"shellList",
",",
"$",
"appPath",
"[",
"0",
"]",
",",
"'app'",
",",
"$",
"skipFiles",
")",
";",
"$",
"skipCore",
"=",
"array_merge",
"(",
"$",
"skipFiles",
",",
"$",
"hiddenCommands",
",",
"$",
"shellList",
"[",
"'app'",
"]",
")",
";",
"$",
"corePath",
"=",
"dirname",
"(",
"__DIR__",
")",
";",
"$",
"shellList",
"=",
"$",
"this",
"->",
"_findShells",
"(",
"$",
"shellList",
",",
"$",
"corePath",
",",
"'CORE'",
",",
"$",
"skipCore",
")",
";",
"$",
"corePath",
"=",
"dirname",
"(",
"dirname",
"(",
"__DIR__",
")",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"'Command'",
";",
"$",
"shellList",
"=",
"$",
"this",
"->",
"_findShells",
"(",
"$",
"shellList",
",",
"$",
"corePath",
",",
"'CORE'",
",",
"$",
"skipCore",
")",
";",
"foreach",
"(",
"$",
"plugins",
"as",
"$",
"plugin",
")",
"{",
"$",
"pluginPath",
"=",
"Plugin",
"::",
"classPath",
"(",
"$",
"plugin",
")",
".",
"'Shell'",
";",
"$",
"shellList",
"=",
"$",
"this",
"->",
"_findShells",
"(",
"$",
"shellList",
",",
"$",
"pluginPath",
",",
"$",
"plugin",
",",
"[",
"]",
")",
";",
"}",
"return",
"array_filter",
"(",
"$",
"shellList",
")",
";",
"}"
] | Gets the shell command listing.
@return array | [
"Gets",
"the",
"shell",
"command",
"listing",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Task/CommandTask.php#L37-L63 |
211,723 | cakephp/cakephp | src/Shell/Task/CommandTask.php | CommandTask.commands | public function commands()
{
$shellList = $this->getShellList();
$flatten = Hash::flatten($shellList);
$duplicates = array_intersect($flatten, array_unique(array_diff_key($flatten, array_unique($flatten))));
$duplicates = Hash::expand($duplicates);
$options = [];
foreach ($shellList as $type => $commands) {
foreach ($commands as $shell) {
$prefix = '';
if (!in_array(strtolower($type), ['app', 'core']) &&
isset($duplicates[$type]) &&
in_array($shell, $duplicates[$type])
) {
$prefix = $type . '.';
}
$options[] = $prefix . $shell;
}
}
return $options;
} | php | public function commands()
{
$shellList = $this->getShellList();
$flatten = Hash::flatten($shellList);
$duplicates = array_intersect($flatten, array_unique(array_diff_key($flatten, array_unique($flatten))));
$duplicates = Hash::expand($duplicates);
$options = [];
foreach ($shellList as $type => $commands) {
foreach ($commands as $shell) {
$prefix = '';
if (!in_array(strtolower($type), ['app', 'core']) &&
isset($duplicates[$type]) &&
in_array($shell, $duplicates[$type])
) {
$prefix = $type . '.';
}
$options[] = $prefix . $shell;
}
}
return $options;
} | [
"public",
"function",
"commands",
"(",
")",
"{",
"$",
"shellList",
"=",
"$",
"this",
"->",
"getShellList",
"(",
")",
";",
"$",
"flatten",
"=",
"Hash",
"::",
"flatten",
"(",
"$",
"shellList",
")",
";",
"$",
"duplicates",
"=",
"array_intersect",
"(",
"$",
"flatten",
",",
"array_unique",
"(",
"array_diff_key",
"(",
"$",
"flatten",
",",
"array_unique",
"(",
"$",
"flatten",
")",
")",
")",
")",
";",
"$",
"duplicates",
"=",
"Hash",
"::",
"expand",
"(",
"$",
"duplicates",
")",
";",
"$",
"options",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"shellList",
"as",
"$",
"type",
"=>",
"$",
"commands",
")",
"{",
"foreach",
"(",
"$",
"commands",
"as",
"$",
"shell",
")",
"{",
"$",
"prefix",
"=",
"''",
";",
"if",
"(",
"!",
"in_array",
"(",
"strtolower",
"(",
"$",
"type",
")",
",",
"[",
"'app'",
",",
"'core'",
"]",
")",
"&&",
"isset",
"(",
"$",
"duplicates",
"[",
"$",
"type",
"]",
")",
"&&",
"in_array",
"(",
"$",
"shell",
",",
"$",
"duplicates",
"[",
"$",
"type",
"]",
")",
")",
"{",
"$",
"prefix",
"=",
"$",
"type",
".",
"'.'",
";",
"}",
"$",
"options",
"[",
"]",
"=",
"$",
"prefix",
".",
"$",
"shell",
";",
"}",
"}",
"return",
"$",
"options",
";",
"}"
] | Return a list of all commands
@return array | [
"Return",
"a",
"list",
"of",
"all",
"commands"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Task/CommandTask.php#L137-L160 |
211,724 | cakephp/cakephp | src/Shell/Task/CommandTask.php | CommandTask.subCommands | public function subCommands($commandName)
{
$Shell = $this->getShell($commandName);
if (!$Shell) {
return [];
}
$taskMap = $this->Tasks->normalizeArray((array)$Shell->tasks);
$return = array_keys($taskMap);
$return = array_map('Cake\Utility\Inflector::underscore', $return);
$shellMethodNames = ['main', 'help', 'getOptionParser', 'initialize', 'runCommand'];
$baseClasses = ['Object', 'Shell', 'AppShell'];
$Reflection = new ReflectionClass($Shell);
$methods = $Reflection->getMethods(ReflectionMethod::IS_PUBLIC);
$methodNames = [];
foreach ($methods as $method) {
$declaringClass = $method->getDeclaringClass()->getShortName();
if (!in_array($declaringClass, $baseClasses)) {
$methodNames[] = $method->getName();
}
}
$return = array_merge($return, array_diff($methodNames, $shellMethodNames));
sort($return);
return $return;
} | php | public function subCommands($commandName)
{
$Shell = $this->getShell($commandName);
if (!$Shell) {
return [];
}
$taskMap = $this->Tasks->normalizeArray((array)$Shell->tasks);
$return = array_keys($taskMap);
$return = array_map('Cake\Utility\Inflector::underscore', $return);
$shellMethodNames = ['main', 'help', 'getOptionParser', 'initialize', 'runCommand'];
$baseClasses = ['Object', 'Shell', 'AppShell'];
$Reflection = new ReflectionClass($Shell);
$methods = $Reflection->getMethods(ReflectionMethod::IS_PUBLIC);
$methodNames = [];
foreach ($methods as $method) {
$declaringClass = $method->getDeclaringClass()->getShortName();
if (!in_array($declaringClass, $baseClasses)) {
$methodNames[] = $method->getName();
}
}
$return = array_merge($return, array_diff($methodNames, $shellMethodNames));
sort($return);
return $return;
} | [
"public",
"function",
"subCommands",
"(",
"$",
"commandName",
")",
"{",
"$",
"Shell",
"=",
"$",
"this",
"->",
"getShell",
"(",
"$",
"commandName",
")",
";",
"if",
"(",
"!",
"$",
"Shell",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"taskMap",
"=",
"$",
"this",
"->",
"Tasks",
"->",
"normalizeArray",
"(",
"(",
"array",
")",
"$",
"Shell",
"->",
"tasks",
")",
";",
"$",
"return",
"=",
"array_keys",
"(",
"$",
"taskMap",
")",
";",
"$",
"return",
"=",
"array_map",
"(",
"'Cake\\Utility\\Inflector::underscore'",
",",
"$",
"return",
")",
";",
"$",
"shellMethodNames",
"=",
"[",
"'main'",
",",
"'help'",
",",
"'getOptionParser'",
",",
"'initialize'",
",",
"'runCommand'",
"]",
";",
"$",
"baseClasses",
"=",
"[",
"'Object'",
",",
"'Shell'",
",",
"'AppShell'",
"]",
";",
"$",
"Reflection",
"=",
"new",
"ReflectionClass",
"(",
"$",
"Shell",
")",
";",
"$",
"methods",
"=",
"$",
"Reflection",
"->",
"getMethods",
"(",
"ReflectionMethod",
"::",
"IS_PUBLIC",
")",
";",
"$",
"methodNames",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"methods",
"as",
"$",
"method",
")",
"{",
"$",
"declaringClass",
"=",
"$",
"method",
"->",
"getDeclaringClass",
"(",
")",
"->",
"getShortName",
"(",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"declaringClass",
",",
"$",
"baseClasses",
")",
")",
"{",
"$",
"methodNames",
"[",
"]",
"=",
"$",
"method",
"->",
"getName",
"(",
")",
";",
"}",
"}",
"$",
"return",
"=",
"array_merge",
"(",
"$",
"return",
",",
"array_diff",
"(",
"$",
"methodNames",
",",
"$",
"shellMethodNames",
")",
")",
";",
"sort",
"(",
"$",
"return",
")",
";",
"return",
"$",
"return",
";",
"}"
] | Return a list of subcommands for a given command
@param string $commandName The command you want subcommands from.
@return string[]
@throws \ReflectionException | [
"Return",
"a",
"list",
"of",
"subcommands",
"for",
"a",
"given",
"command"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Task/CommandTask.php#L169-L199 |
211,725 | cakephp/cakephp | src/Shell/Task/CommandTask.php | CommandTask.getShell | public function getShell($commandName)
{
list($pluginDot, $name) = pluginSplit($commandName, true);
if (in_array(strtolower($pluginDot), ['app.', 'core.'])) {
$commandName = $name;
$pluginDot = '';
}
if (!in_array($commandName, $this->commands()) && (empty($pluginDot) && !in_array($name, $this->commands()))) {
return false;
}
if (empty($pluginDot)) {
$shellList = $this->getShellList();
if (!in_array($commandName, $shellList['app']) && !in_array($commandName, $shellList['CORE'])) {
unset($shellList['CORE'], $shellList['app']);
foreach ($shellList as $plugin => $commands) {
if (in_array($commandName, $commands)) {
$pluginDot = $plugin . '.';
break;
}
}
}
}
$name = Inflector::camelize($name);
$pluginDot = Inflector::camelize($pluginDot);
$class = App::className($pluginDot . $name, 'Shell', 'Shell');
if (!$class) {
return false;
}
/* @var \Cake\Console\Shell $Shell */
$Shell = new $class();
$Shell->plugin = trim($pluginDot, '.');
$Shell->initialize();
return $Shell;
} | php | public function getShell($commandName)
{
list($pluginDot, $name) = pluginSplit($commandName, true);
if (in_array(strtolower($pluginDot), ['app.', 'core.'])) {
$commandName = $name;
$pluginDot = '';
}
if (!in_array($commandName, $this->commands()) && (empty($pluginDot) && !in_array($name, $this->commands()))) {
return false;
}
if (empty($pluginDot)) {
$shellList = $this->getShellList();
if (!in_array($commandName, $shellList['app']) && !in_array($commandName, $shellList['CORE'])) {
unset($shellList['CORE'], $shellList['app']);
foreach ($shellList as $plugin => $commands) {
if (in_array($commandName, $commands)) {
$pluginDot = $plugin . '.';
break;
}
}
}
}
$name = Inflector::camelize($name);
$pluginDot = Inflector::camelize($pluginDot);
$class = App::className($pluginDot . $name, 'Shell', 'Shell');
if (!$class) {
return false;
}
/* @var \Cake\Console\Shell $Shell */
$Shell = new $class();
$Shell->plugin = trim($pluginDot, '.');
$Shell->initialize();
return $Shell;
} | [
"public",
"function",
"getShell",
"(",
"$",
"commandName",
")",
"{",
"list",
"(",
"$",
"pluginDot",
",",
"$",
"name",
")",
"=",
"pluginSplit",
"(",
"$",
"commandName",
",",
"true",
")",
";",
"if",
"(",
"in_array",
"(",
"strtolower",
"(",
"$",
"pluginDot",
")",
",",
"[",
"'app.'",
",",
"'core.'",
"]",
")",
")",
"{",
"$",
"commandName",
"=",
"$",
"name",
";",
"$",
"pluginDot",
"=",
"''",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"commandName",
",",
"$",
"this",
"->",
"commands",
"(",
")",
")",
"&&",
"(",
"empty",
"(",
"$",
"pluginDot",
")",
"&&",
"!",
"in_array",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"commands",
"(",
")",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"pluginDot",
")",
")",
"{",
"$",
"shellList",
"=",
"$",
"this",
"->",
"getShellList",
"(",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"commandName",
",",
"$",
"shellList",
"[",
"'app'",
"]",
")",
"&&",
"!",
"in_array",
"(",
"$",
"commandName",
",",
"$",
"shellList",
"[",
"'CORE'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"shellList",
"[",
"'CORE'",
"]",
",",
"$",
"shellList",
"[",
"'app'",
"]",
")",
";",
"foreach",
"(",
"$",
"shellList",
"as",
"$",
"plugin",
"=>",
"$",
"commands",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"commandName",
",",
"$",
"commands",
")",
")",
"{",
"$",
"pluginDot",
"=",
"$",
"plugin",
".",
"'.'",
";",
"break",
";",
"}",
"}",
"}",
"}",
"$",
"name",
"=",
"Inflector",
"::",
"camelize",
"(",
"$",
"name",
")",
";",
"$",
"pluginDot",
"=",
"Inflector",
"::",
"camelize",
"(",
"$",
"pluginDot",
")",
";",
"$",
"class",
"=",
"App",
"::",
"className",
"(",
"$",
"pluginDot",
".",
"$",
"name",
",",
"'Shell'",
",",
"'Shell'",
")",
";",
"if",
"(",
"!",
"$",
"class",
")",
"{",
"return",
"false",
";",
"}",
"/* @var \\Cake\\Console\\Shell $Shell */",
"$",
"Shell",
"=",
"new",
"$",
"class",
"(",
")",
";",
"$",
"Shell",
"->",
"plugin",
"=",
"trim",
"(",
"$",
"pluginDot",
",",
"'.'",
")",
";",
"$",
"Shell",
"->",
"initialize",
"(",
")",
";",
"return",
"$",
"Shell",
";",
"}"
] | Get Shell instance for the given command
@param string $commandName The command you want.
@return \Cake\Console\Shell|bool Shell instance if the command can be found, false otherwise. | [
"Get",
"Shell",
"instance",
"for",
"the",
"given",
"command"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Task/CommandTask.php#L207-L247 |
211,726 | cakephp/cakephp | src/Shell/Task/CommandTask.php | CommandTask.options | public function options($commandName, $subCommandName = '')
{
$Shell = $this->getShell($commandName);
if (!$Shell) {
return [];
}
$parser = $Shell->getOptionParser();
if (!empty($subCommandName)) {
$subCommandName = Inflector::camelize($subCommandName);
if ($Shell->hasTask($subCommandName)) {
$parser = $Shell->{$subCommandName}->getOptionParser();
} else {
return [];
}
}
$options = [];
$array = $parser->options();
/* @var \Cake\Console\ConsoleInputOption $obj */
foreach ($array as $name => $obj) {
$options[] = "--$name";
$short = $obj->short();
if ($short) {
$options[] = "-$short";
}
}
return $options;
} | php | public function options($commandName, $subCommandName = '')
{
$Shell = $this->getShell($commandName);
if (!$Shell) {
return [];
}
$parser = $Shell->getOptionParser();
if (!empty($subCommandName)) {
$subCommandName = Inflector::camelize($subCommandName);
if ($Shell->hasTask($subCommandName)) {
$parser = $Shell->{$subCommandName}->getOptionParser();
} else {
return [];
}
}
$options = [];
$array = $parser->options();
/* @var \Cake\Console\ConsoleInputOption $obj */
foreach ($array as $name => $obj) {
$options[] = "--$name";
$short = $obj->short();
if ($short) {
$options[] = "-$short";
}
}
return $options;
} | [
"public",
"function",
"options",
"(",
"$",
"commandName",
",",
"$",
"subCommandName",
"=",
"''",
")",
"{",
"$",
"Shell",
"=",
"$",
"this",
"->",
"getShell",
"(",
"$",
"commandName",
")",
";",
"if",
"(",
"!",
"$",
"Shell",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"parser",
"=",
"$",
"Shell",
"->",
"getOptionParser",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"subCommandName",
")",
")",
"{",
"$",
"subCommandName",
"=",
"Inflector",
"::",
"camelize",
"(",
"$",
"subCommandName",
")",
";",
"if",
"(",
"$",
"Shell",
"->",
"hasTask",
"(",
"$",
"subCommandName",
")",
")",
"{",
"$",
"parser",
"=",
"$",
"Shell",
"->",
"{",
"$",
"subCommandName",
"}",
"->",
"getOptionParser",
"(",
")",
";",
"}",
"else",
"{",
"return",
"[",
"]",
";",
"}",
"}",
"$",
"options",
"=",
"[",
"]",
";",
"$",
"array",
"=",
"$",
"parser",
"->",
"options",
"(",
")",
";",
"/* @var \\Cake\\Console\\ConsoleInputOption $obj */",
"foreach",
"(",
"$",
"array",
"as",
"$",
"name",
"=>",
"$",
"obj",
")",
"{",
"$",
"options",
"[",
"]",
"=",
"\"--$name\"",
";",
"$",
"short",
"=",
"$",
"obj",
"->",
"short",
"(",
")",
";",
"if",
"(",
"$",
"short",
")",
"{",
"$",
"options",
"[",
"]",
"=",
"\"-$short\"",
";",
"}",
"}",
"return",
"$",
"options",
";",
"}"
] | Get options list for the given command or subcommand
@param string $commandName The command to get options for.
@param string $subCommandName The subcommand to get options for. Can be empty to get options for the command.
If this parameter is used, the subcommand must be a valid subcommand of the command passed
@return array Options list for the given command or subcommand | [
"Get",
"options",
"list",
"for",
"the",
"given",
"command",
"or",
"subcommand"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Task/CommandTask.php#L257-L288 |
211,727 | cakephp/cakephp | src/Utility/Inflector.php | Inflector.delimit | public static function delimit($string, $delimiter = '_')
{
$cacheKey = __FUNCTION__ . $delimiter;
$result = static::_cache($cacheKey, $string);
if ($result === false) {
$result = mb_strtolower(preg_replace('/(?<=\\w)([A-Z])/', $delimiter . '\\1', $string));
static::_cache($cacheKey, $string, $result);
}
return $result;
} | php | public static function delimit($string, $delimiter = '_')
{
$cacheKey = __FUNCTION__ . $delimiter;
$result = static::_cache($cacheKey, $string);
if ($result === false) {
$result = mb_strtolower(preg_replace('/(?<=\\w)([A-Z])/', $delimiter . '\\1', $string));
static::_cache($cacheKey, $string, $result);
}
return $result;
} | [
"public",
"static",
"function",
"delimit",
"(",
"$",
"string",
",",
"$",
"delimiter",
"=",
"'_'",
")",
"{",
"$",
"cacheKey",
"=",
"__FUNCTION__",
".",
"$",
"delimiter",
";",
"$",
"result",
"=",
"static",
"::",
"_cache",
"(",
"$",
"cacheKey",
",",
"$",
"string",
")",
";",
"if",
"(",
"$",
"result",
"===",
"false",
")",
"{",
"$",
"result",
"=",
"mb_strtolower",
"(",
"preg_replace",
"(",
"'/(?<=\\\\w)([A-Z])/'",
",",
"$",
"delimiter",
".",
"'\\\\1'",
",",
"$",
"string",
")",
")",
";",
"static",
"::",
"_cache",
"(",
"$",
"cacheKey",
",",
"$",
"string",
",",
"$",
"result",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Expects a CamelCasedInputString, and produces a lower_case_delimited_string
@param string $string String to delimit
@param string $delimiter the character to use as a delimiter
@return string delimited string | [
"Expects",
"a",
"CamelCasedInputString",
"and",
"produces",
"a",
"lower_case_delimited_string"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/Inflector.php#L669-L681 |
211,728 | cakephp/cakephp | src/Routing/Route/EntityRoute.php | EntityRoute.match | public function match(array $url, array $context = [])
{
if (empty($this->_compiledRoute)) {
$this->compile();
}
if (isset($url['_entity'])) {
$entity = $url['_entity'];
$this->_checkEntity($entity);
foreach ($this->keys as $field) {
if (!isset($url[$field]) && isset($entity[$field])) {
$url[$field] = $entity[$field];
}
}
}
return parent::match($url, $context);
} | php | public function match(array $url, array $context = [])
{
if (empty($this->_compiledRoute)) {
$this->compile();
}
if (isset($url['_entity'])) {
$entity = $url['_entity'];
$this->_checkEntity($entity);
foreach ($this->keys as $field) {
if (!isset($url[$field]) && isset($entity[$field])) {
$url[$field] = $entity[$field];
}
}
}
return parent::match($url, $context);
} | [
"public",
"function",
"match",
"(",
"array",
"$",
"url",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_compiledRoute",
")",
")",
"{",
"$",
"this",
"->",
"compile",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"url",
"[",
"'_entity'",
"]",
")",
")",
"{",
"$",
"entity",
"=",
"$",
"url",
"[",
"'_entity'",
"]",
";",
"$",
"this",
"->",
"_checkEntity",
"(",
"$",
"entity",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"keys",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"url",
"[",
"$",
"field",
"]",
")",
"&&",
"isset",
"(",
"$",
"entity",
"[",
"$",
"field",
"]",
")",
")",
"{",
"$",
"url",
"[",
"$",
"field",
"]",
"=",
"$",
"entity",
"[",
"$",
"field",
"]",
";",
"}",
"}",
"}",
"return",
"parent",
"::",
"match",
"(",
"$",
"url",
",",
"$",
"context",
")",
";",
"}"
] | Match by entity and map its fields to the URL pattern by comparing the
field names with the template vars.
If a routing key is defined in both `$url` and the entity, the value defined
in `$url` will be preferred.
@param array $url Array of parameters to convert to a string.
@param array $context An array of the current request context.
Contains information such as the current host, scheme, port, and base
directory.
@return bool|string Either false or a string URL. | [
"Match",
"by",
"entity",
"and",
"map",
"its",
"fields",
"to",
"the",
"URL",
"pattern",
"by",
"comparing",
"the",
"field",
"names",
"with",
"the",
"template",
"vars",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Route/EntityRoute.php#L42-L60 |
211,729 | cakephp/cakephp | src/Routing/Route/EntityRoute.php | EntityRoute._checkEntity | protected function _checkEntity($entity)
{
if (!$entity instanceof ArrayAccess && !is_array($entity)) {
throw new RuntimeException(sprintf(
'Route `%s` expects the URL option `_entity` to be an array or object implementing \ArrayAccess, but `%s` passed.',
$this->template,
getTypeName($entity)
));
}
} | php | protected function _checkEntity($entity)
{
if (!$entity instanceof ArrayAccess && !is_array($entity)) {
throw new RuntimeException(sprintf(
'Route `%s` expects the URL option `_entity` to be an array or object implementing \ArrayAccess, but `%s` passed.',
$this->template,
getTypeName($entity)
));
}
} | [
"protected",
"function",
"_checkEntity",
"(",
"$",
"entity",
")",
"{",
"if",
"(",
"!",
"$",
"entity",
"instanceof",
"ArrayAccess",
"&&",
"!",
"is_array",
"(",
"$",
"entity",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Route `%s` expects the URL option `_entity` to be an array or object implementing \\ArrayAccess, but `%s` passed.'",
",",
"$",
"this",
"->",
"template",
",",
"getTypeName",
"(",
"$",
"entity",
")",
")",
")",
";",
"}",
"}"
] | Checks that we really deal with an entity object
@throws \RuntimeException
@param \ArrayAccess|array $entity Entity value from the URL options
@return void | [
"Checks",
"that",
"we",
"really",
"deal",
"with",
"an",
"entity",
"object"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Route/EntityRoute.php#L69-L78 |
211,730 | cakephp/cakephp | src/Shell/CompletionShell.php | CompletionShell.options | public function options()
{
$commandName = $subCommandName = '';
if (!empty($this->args[0])) {
$commandName = $this->args[0];
}
if (!empty($this->args[1])) {
$subCommandName = $this->args[1];
}
$options = $this->Command->options($commandName, $subCommandName);
return $this->_output($options);
} | php | public function options()
{
$commandName = $subCommandName = '';
if (!empty($this->args[0])) {
$commandName = $this->args[0];
}
if (!empty($this->args[1])) {
$subCommandName = $this->args[1];
}
$options = $this->Command->options($commandName, $subCommandName);
return $this->_output($options);
} | [
"public",
"function",
"options",
"(",
")",
"{",
"$",
"commandName",
"=",
"$",
"subCommandName",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"args",
"[",
"0",
"]",
")",
")",
"{",
"$",
"commandName",
"=",
"$",
"this",
"->",
"args",
"[",
"0",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"args",
"[",
"1",
"]",
")",
")",
"{",
"$",
"subCommandName",
"=",
"$",
"this",
"->",
"args",
"[",
"1",
"]",
";",
"}",
"$",
"options",
"=",
"$",
"this",
"->",
"Command",
"->",
"options",
"(",
"$",
"commandName",
",",
"$",
"subCommandName",
")",
";",
"return",
"$",
"this",
"->",
"_output",
"(",
"$",
"options",
")",
";",
"}"
] | list options for the named command
@return int|bool|null Returns the number of bytes returned from writing to stdout. | [
"list",
"options",
"for",
"the",
"named",
"command"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/CompletionShell.php#L70-L82 |
211,731 | cakephp/cakephp | src/Shell/CompletionShell.php | CompletionShell.subcommands | public function subcommands()
{
if (!$this->args) {
return $this->_output();
}
$options = $this->Command->subCommands($this->args[0]);
return $this->_output($options);
} | php | public function subcommands()
{
if (!$this->args) {
return $this->_output();
}
$options = $this->Command->subCommands($this->args[0]);
return $this->_output($options);
} | [
"public",
"function",
"subcommands",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"args",
")",
"{",
"return",
"$",
"this",
"->",
"_output",
"(",
")",
";",
"}",
"$",
"options",
"=",
"$",
"this",
"->",
"Command",
"->",
"subCommands",
"(",
"$",
"this",
"->",
"args",
"[",
"0",
"]",
")",
";",
"return",
"$",
"this",
"->",
"_output",
"(",
"$",
"options",
")",
";",
"}"
] | list subcommands for the named command
@return int|bool|null Returns the number of bytes returned from writing to stdout.
@throws \ReflectionException | [
"list",
"subcommands",
"for",
"the",
"named",
"command"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/CompletionShell.php#L90-L99 |
211,732 | cakephp/cakephp | src/Routing/Filter/LocaleSelectorFilter.php | LocaleSelectorFilter.beforeDispatch | public function beforeDispatch(Event $event)
{
/* @var \Cake\Http\ServerRequest $request */
$request = $event->getData('request');
$locale = Locale::acceptFromHttp($request->getHeaderLine('Accept-Language'));
if (!$locale || (!empty($this->_locales) && !in_array($locale, $this->_locales))) {
return;
}
I18n::setLocale($locale);
} | php | public function beforeDispatch(Event $event)
{
/* @var \Cake\Http\ServerRequest $request */
$request = $event->getData('request');
$locale = Locale::acceptFromHttp($request->getHeaderLine('Accept-Language'));
if (!$locale || (!empty($this->_locales) && !in_array($locale, $this->_locales))) {
return;
}
I18n::setLocale($locale);
} | [
"public",
"function",
"beforeDispatch",
"(",
"Event",
"$",
"event",
")",
"{",
"/* @var \\Cake\\Http\\ServerRequest $request */",
"$",
"request",
"=",
"$",
"event",
"->",
"getData",
"(",
"'request'",
")",
";",
"$",
"locale",
"=",
"Locale",
"::",
"acceptFromHttp",
"(",
"$",
"request",
"->",
"getHeaderLine",
"(",
"'Accept-Language'",
")",
")",
";",
"if",
"(",
"!",
"$",
"locale",
"||",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_locales",
")",
"&&",
"!",
"in_array",
"(",
"$",
"locale",
",",
"$",
"this",
"->",
"_locales",
")",
")",
")",
"{",
"return",
";",
"}",
"I18n",
"::",
"setLocale",
"(",
"$",
"locale",
")",
";",
"}"
] | Inspects the request for the Accept-Language header and sets the
Locale for the current runtime if it matches the list of valid locales
as passed in the configuration.
@param \Cake\Event\Event $event The event instance.
@return void | [
"Inspects",
"the",
"request",
"for",
"the",
"Accept",
"-",
"Language",
"header",
"and",
"sets",
"the",
"Locale",
"for",
"the",
"current",
"runtime",
"if",
"it",
"matches",
"the",
"list",
"of",
"valid",
"locales",
"as",
"passed",
"in",
"the",
"configuration",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Filter/LocaleSelectorFilter.php#L59-L70 |
211,733 | cakephp/cakephp | src/View/Helper/TimeHelper.php | TimeHelper.toAtom | public function toAtom($dateString, $timezone = null)
{
$timezone = $this->_getTimezone($timezone) ?: date_default_timezone_get();
return (new Time($dateString))->timezone($timezone)->toAtomString();
} | php | public function toAtom($dateString, $timezone = null)
{
$timezone = $this->_getTimezone($timezone) ?: date_default_timezone_get();
return (new Time($dateString))->timezone($timezone)->toAtomString();
} | [
"public",
"function",
"toAtom",
"(",
"$",
"dateString",
",",
"$",
"timezone",
"=",
"null",
")",
"{",
"$",
"timezone",
"=",
"$",
"this",
"->",
"_getTimezone",
"(",
"$",
"timezone",
")",
"?",
":",
"date_default_timezone_get",
"(",
")",
";",
"return",
"(",
"new",
"Time",
"(",
"$",
"dateString",
")",
")",
"->",
"timezone",
"(",
"$",
"timezone",
")",
"->",
"toAtomString",
"(",
")",
";",
"}"
] | Returns a date formatted for Atom RSS feeds.
@param int|string|\DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
@param string|\DateTimeZone|null $timezone User's timezone string or DateTimeZone object
@return string Formatted date string
@see \Cake\I18n\Time::toAtom() | [
"Returns",
"a",
"date",
"formatted",
"for",
"Atom",
"RSS",
"feeds",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/TimeHelper.php#L219-L224 |
211,734 | cakephp/cakephp | src/View/Helper/TimeHelper.php | TimeHelper.toRss | public function toRss($dateString, $timezone = null)
{
$timezone = $this->_getTimezone($timezone) ?: date_default_timezone_get();
return (new Time($dateString))->timezone($timezone)->toRssString();
} | php | public function toRss($dateString, $timezone = null)
{
$timezone = $this->_getTimezone($timezone) ?: date_default_timezone_get();
return (new Time($dateString))->timezone($timezone)->toRssString();
} | [
"public",
"function",
"toRss",
"(",
"$",
"dateString",
",",
"$",
"timezone",
"=",
"null",
")",
"{",
"$",
"timezone",
"=",
"$",
"this",
"->",
"_getTimezone",
"(",
"$",
"timezone",
")",
"?",
":",
"date_default_timezone_get",
"(",
")",
";",
"return",
"(",
"new",
"Time",
"(",
"$",
"dateString",
")",
")",
"->",
"timezone",
"(",
"$",
"timezone",
")",
"->",
"toRssString",
"(",
")",
";",
"}"
] | Formats date for RSS feeds
@param int|string|\DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
@param string|\DateTimeZone|null $timezone User's timezone string or DateTimeZone object
@return string Formatted date string | [
"Formats",
"date",
"for",
"RSS",
"feeds"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/TimeHelper.php#L233-L238 |
211,735 | cakephp/cakephp | src/View/Helper/TimeHelper.php | TimeHelper.timeAgoInWords | public function timeAgoInWords($dateTime, array $options = [])
{
$element = null;
$options += [
'element' => null,
'timezone' => null
];
$options['timezone'] = $this->_getTimezone($options['timezone']);
if ($options['timezone']) {
$dateTime = $dateTime->timezone($options['timezone']);
unset($options['timezone']);
}
if (!empty($options['element'])) {
$element = [
'tag' => 'span',
'class' => 'time-ago-in-words',
'title' => $dateTime
];
if (is_array($options['element'])) {
$element = $options['element'] + $element;
} else {
$element['tag'] = $options['element'];
}
unset($options['element']);
}
$relativeDate = (new Time($dateTime))->timeAgoInWords($options);
if ($element) {
$relativeDate = sprintf(
'<%s%s>%s</%s>',
$element['tag'],
$this->templater()->formatAttributes($element, ['tag']),
$relativeDate,
$element['tag']
);
}
return $relativeDate;
} | php | public function timeAgoInWords($dateTime, array $options = [])
{
$element = null;
$options += [
'element' => null,
'timezone' => null
];
$options['timezone'] = $this->_getTimezone($options['timezone']);
if ($options['timezone']) {
$dateTime = $dateTime->timezone($options['timezone']);
unset($options['timezone']);
}
if (!empty($options['element'])) {
$element = [
'tag' => 'span',
'class' => 'time-ago-in-words',
'title' => $dateTime
];
if (is_array($options['element'])) {
$element = $options['element'] + $element;
} else {
$element['tag'] = $options['element'];
}
unset($options['element']);
}
$relativeDate = (new Time($dateTime))->timeAgoInWords($options);
if ($element) {
$relativeDate = sprintf(
'<%s%s>%s</%s>',
$element['tag'],
$this->templater()->formatAttributes($element, ['tag']),
$relativeDate,
$element['tag']
);
}
return $relativeDate;
} | [
"public",
"function",
"timeAgoInWords",
"(",
"$",
"dateTime",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"element",
"=",
"null",
";",
"$",
"options",
"+=",
"[",
"'element'",
"=>",
"null",
",",
"'timezone'",
"=>",
"null",
"]",
";",
"$",
"options",
"[",
"'timezone'",
"]",
"=",
"$",
"this",
"->",
"_getTimezone",
"(",
"$",
"options",
"[",
"'timezone'",
"]",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'timezone'",
"]",
")",
"{",
"$",
"dateTime",
"=",
"$",
"dateTime",
"->",
"timezone",
"(",
"$",
"options",
"[",
"'timezone'",
"]",
")",
";",
"unset",
"(",
"$",
"options",
"[",
"'timezone'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'element'",
"]",
")",
")",
"{",
"$",
"element",
"=",
"[",
"'tag'",
"=>",
"'span'",
",",
"'class'",
"=>",
"'time-ago-in-words'",
",",
"'title'",
"=>",
"$",
"dateTime",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"options",
"[",
"'element'",
"]",
")",
")",
"{",
"$",
"element",
"=",
"$",
"options",
"[",
"'element'",
"]",
"+",
"$",
"element",
";",
"}",
"else",
"{",
"$",
"element",
"[",
"'tag'",
"]",
"=",
"$",
"options",
"[",
"'element'",
"]",
";",
"}",
"unset",
"(",
"$",
"options",
"[",
"'element'",
"]",
")",
";",
"}",
"$",
"relativeDate",
"=",
"(",
"new",
"Time",
"(",
"$",
"dateTime",
")",
")",
"->",
"timeAgoInWords",
"(",
"$",
"options",
")",
";",
"if",
"(",
"$",
"element",
")",
"{",
"$",
"relativeDate",
"=",
"sprintf",
"(",
"'<%s%s>%s</%s>'",
",",
"$",
"element",
"[",
"'tag'",
"]",
",",
"$",
"this",
"->",
"templater",
"(",
")",
"->",
"formatAttributes",
"(",
"$",
"element",
",",
"[",
"'tag'",
"]",
")",
",",
"$",
"relativeDate",
",",
"$",
"element",
"[",
"'tag'",
"]",
")",
";",
"}",
"return",
"$",
"relativeDate",
";",
"}"
] | Formats a date into a phrase expressing the relative time.
### Additional options
- `element` - The element to wrap the formatted time in.
Has a few additional options:
- `tag` - The tag to use, defaults to 'span'.
- `class` - The class name to use, defaults to `time-ago-in-words`.
- `title` - Defaults to the $dateTime input.
@param int|string|\DateTime|\Cake\Chronos\ChronosInterface $dateTime UNIX timestamp, strtotime() valid string or DateTime object
@param array $options Default format if timestamp is used in $dateString
@return string Relative time string.
@see \Cake\I18n\Time::timeAgoInWords() | [
"Formats",
"a",
"date",
"into",
"a",
"phrase",
"expressing",
"the",
"relative",
"time",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/TimeHelper.php#L256-L296 |
211,736 | cakephp/cakephp | src/View/Helper/TimeHelper.php | TimeHelper.wasWithinLast | public function wasWithinLast($timeInterval, $dateString, $timezone = null)
{
return (new Time($dateString, $timezone))->wasWithinLast($timeInterval);
} | php | public function wasWithinLast($timeInterval, $dateString, $timezone = null)
{
return (new Time($dateString, $timezone))->wasWithinLast($timeInterval);
} | [
"public",
"function",
"wasWithinLast",
"(",
"$",
"timeInterval",
",",
"$",
"dateString",
",",
"$",
"timezone",
"=",
"null",
")",
"{",
"return",
"(",
"new",
"Time",
"(",
"$",
"dateString",
",",
"$",
"timezone",
")",
")",
"->",
"wasWithinLast",
"(",
"$",
"timeInterval",
")",
";",
"}"
] | Returns true if specified datetime was within the interval specified, else false.
@param string|int $timeInterval the numeric value with space then time type.
Example of valid types: 6 hours, 2 days, 1 minute.
Integer input values are deprecated and support will be removed in 4.0.0
@param int|string|\DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
@param string|\DateTimeZone|null $timezone User's timezone string or DateTimeZone object
@return bool
@see \Cake\I18n\Time::wasWithinLast() | [
"Returns",
"true",
"if",
"specified",
"datetime",
"was",
"within",
"the",
"interval",
"specified",
"else",
"false",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/TimeHelper.php#L309-L312 |
211,737 | cakephp/cakephp | src/View/Helper/TimeHelper.php | TimeHelper.isWithinNext | public function isWithinNext($timeInterval, $dateString, $timezone = null)
{
return (new Time($dateString, $timezone))->isWithinNext($timeInterval);
} | php | public function isWithinNext($timeInterval, $dateString, $timezone = null)
{
return (new Time($dateString, $timezone))->isWithinNext($timeInterval);
} | [
"public",
"function",
"isWithinNext",
"(",
"$",
"timeInterval",
",",
"$",
"dateString",
",",
"$",
"timezone",
"=",
"null",
")",
"{",
"return",
"(",
"new",
"Time",
"(",
"$",
"dateString",
",",
"$",
"timezone",
")",
")",
"->",
"isWithinNext",
"(",
"$",
"timeInterval",
")",
";",
"}"
] | Returns true if specified datetime is within the interval specified, else false.
@param string|int $timeInterval the numeric value with space then time type.
Example of valid types: 6 hours, 2 days, 1 minute.
Integer input values are deprecated and support will be removed in 4.0.0
@param int|string|\DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
@param string|\DateTimeZone|null $timezone User's timezone string or DateTimeZone object
@return bool
@see \Cake\I18n\Time::wasWithinLast() | [
"Returns",
"true",
"if",
"specified",
"datetime",
"is",
"within",
"the",
"interval",
"specified",
"else",
"false",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/TimeHelper.php#L325-L328 |
211,738 | cakephp/cakephp | src/Core/Configure/Engine/IniConfig.php | IniConfig.read | public function read($key)
{
$file = $this->_getFilePath($key, true);
$contents = parse_ini_file($file, true);
if ($this->_section && isset($contents[$this->_section])) {
$values = $this->_parseNestedValues($contents[$this->_section]);
} else {
$values = [];
foreach ($contents as $section => $attribs) {
if (is_array($attribs)) {
$values[$section] = $this->_parseNestedValues($attribs);
} else {
$parse = $this->_parseNestedValues([$attribs]);
$values[$section] = array_shift($parse);
}
}
}
return $values;
} | php | public function read($key)
{
$file = $this->_getFilePath($key, true);
$contents = parse_ini_file($file, true);
if ($this->_section && isset($contents[$this->_section])) {
$values = $this->_parseNestedValues($contents[$this->_section]);
} else {
$values = [];
foreach ($contents as $section => $attribs) {
if (is_array($attribs)) {
$values[$section] = $this->_parseNestedValues($attribs);
} else {
$parse = $this->_parseNestedValues([$attribs]);
$values[$section] = array_shift($parse);
}
}
}
return $values;
} | [
"public",
"function",
"read",
"(",
"$",
"key",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"_getFilePath",
"(",
"$",
"key",
",",
"true",
")",
";",
"$",
"contents",
"=",
"parse_ini_file",
"(",
"$",
"file",
",",
"true",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_section",
"&&",
"isset",
"(",
"$",
"contents",
"[",
"$",
"this",
"->",
"_section",
"]",
")",
")",
"{",
"$",
"values",
"=",
"$",
"this",
"->",
"_parseNestedValues",
"(",
"$",
"contents",
"[",
"$",
"this",
"->",
"_section",
"]",
")",
";",
"}",
"else",
"{",
"$",
"values",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"contents",
"as",
"$",
"section",
"=>",
"$",
"attribs",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"attribs",
")",
")",
"{",
"$",
"values",
"[",
"$",
"section",
"]",
"=",
"$",
"this",
"->",
"_parseNestedValues",
"(",
"$",
"attribs",
")",
";",
"}",
"else",
"{",
"$",
"parse",
"=",
"$",
"this",
"->",
"_parseNestedValues",
"(",
"[",
"$",
"attribs",
"]",
")",
";",
"$",
"values",
"[",
"$",
"section",
"]",
"=",
"array_shift",
"(",
"$",
"parse",
")",
";",
"}",
"}",
"}",
"return",
"$",
"values",
";",
"}"
] | Read an ini file and return the results as an array.
@param string $key The identifier to read from. If the key has a . it will be treated
as a plugin prefix. The chosen file must be on the engine's path.
@return array Parsed configuration values.
@throws \Cake\Core\Exception\Exception when files don't exist.
Or when files contain '..' as this could lead to abusive reads. | [
"Read",
"an",
"ini",
"file",
"and",
"return",
"the",
"results",
"as",
"an",
"array",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/Configure/Engine/IniConfig.php#L99-L119 |
211,739 | cakephp/cakephp | src/Core/Configure/Engine/IniConfig.php | IniConfig._parseNestedValues | protected function _parseNestedValues($values)
{
foreach ($values as $key => $value) {
if ($value === '1') {
$value = true;
}
if ($value === '') {
$value = false;
}
unset($values[$key]);
if (strpos($key, '.') !== false) {
$values = Hash::insert($values, $key, $value);
} else {
$values[$key] = $value;
}
}
return $values;
} | php | protected function _parseNestedValues($values)
{
foreach ($values as $key => $value) {
if ($value === '1') {
$value = true;
}
if ($value === '') {
$value = false;
}
unset($values[$key]);
if (strpos($key, '.') !== false) {
$values = Hash::insert($values, $key, $value);
} else {
$values[$key] = $value;
}
}
return $values;
} | [
"protected",
"function",
"_parseNestedValues",
"(",
"$",
"values",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"'1'",
")",
"{",
"$",
"value",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"value",
"===",
"''",
")",
"{",
"$",
"value",
"=",
"false",
";",
"}",
"unset",
"(",
"$",
"values",
"[",
"$",
"key",
"]",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"key",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"$",
"values",
"=",
"Hash",
"::",
"insert",
"(",
"$",
"values",
",",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"values",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"values",
";",
"}"
] | parses nested values out of keys.
@param array $values Values to be exploded.
@return array Array of values exploded | [
"parses",
"nested",
"values",
"out",
"of",
"keys",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/Configure/Engine/IniConfig.php#L127-L145 |
211,740 | cakephp/cakephp | src/Core/Configure/Engine/IniConfig.php | IniConfig.dump | public function dump($key, array $data)
{
$result = [];
foreach ($data as $k => $value) {
$isSection = false;
if ($k[0] !== '[') {
$result[] = "[$k]";
$isSection = true;
}
if (is_array($value)) {
$kValues = Hash::flatten($value, '.');
foreach ($kValues as $k2 => $v) {
$result[] = "$k2 = " . $this->_value($v);
}
}
if ($isSection) {
$result[] = '';
}
}
$contents = trim(implode("\n", $result));
$filename = $this->_getFilePath($key);
return file_put_contents($filename, $contents) > 0;
} | php | public function dump($key, array $data)
{
$result = [];
foreach ($data as $k => $value) {
$isSection = false;
if ($k[0] !== '[') {
$result[] = "[$k]";
$isSection = true;
}
if (is_array($value)) {
$kValues = Hash::flatten($value, '.');
foreach ($kValues as $k2 => $v) {
$result[] = "$k2 = " . $this->_value($v);
}
}
if ($isSection) {
$result[] = '';
}
}
$contents = trim(implode("\n", $result));
$filename = $this->_getFilePath($key);
return file_put_contents($filename, $contents) > 0;
} | [
"public",
"function",
"dump",
"(",
"$",
"key",
",",
"array",
"$",
"data",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"k",
"=>",
"$",
"value",
")",
"{",
"$",
"isSection",
"=",
"false",
";",
"if",
"(",
"$",
"k",
"[",
"0",
"]",
"!==",
"'['",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"\"[$k]\"",
";",
"$",
"isSection",
"=",
"true",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"kValues",
"=",
"Hash",
"::",
"flatten",
"(",
"$",
"value",
",",
"'.'",
")",
";",
"foreach",
"(",
"$",
"kValues",
"as",
"$",
"k2",
"=>",
"$",
"v",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"\"$k2 = \"",
".",
"$",
"this",
"->",
"_value",
"(",
"$",
"v",
")",
";",
"}",
"}",
"if",
"(",
"$",
"isSection",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"''",
";",
"}",
"}",
"$",
"contents",
"=",
"trim",
"(",
"implode",
"(",
"\"\\n\"",
",",
"$",
"result",
")",
")",
";",
"$",
"filename",
"=",
"$",
"this",
"->",
"_getFilePath",
"(",
"$",
"key",
")",
";",
"return",
"file_put_contents",
"(",
"$",
"filename",
",",
"$",
"contents",
")",
">",
"0",
";",
"}"
] | Dumps the state of Configure data into an ini formatted string.
@param string $key The identifier to write to. If the key has a . it will be treated
as a plugin prefix.
@param array $data The data to convert to ini file.
@return bool Success. | [
"Dumps",
"the",
"state",
"of",
"Configure",
"data",
"into",
"an",
"ini",
"formatted",
"string",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/Configure/Engine/IniConfig.php#L155-L179 |
211,741 | cakephp/cakephp | src/Core/Configure/Engine/IniConfig.php | IniConfig._value | protected function _value($value)
{
if ($value === null) {
return 'null';
}
if ($value === true) {
return 'true';
}
if ($value === false) {
return 'false';
}
return (string)$value;
} | php | protected function _value($value)
{
if ($value === null) {
return 'null';
}
if ($value === true) {
return 'true';
}
if ($value === false) {
return 'false';
}
return (string)$value;
} | [
"protected",
"function",
"_value",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"'null'",
";",
"}",
"if",
"(",
"$",
"value",
"===",
"true",
")",
"{",
"return",
"'true'",
";",
"}",
"if",
"(",
"$",
"value",
"===",
"false",
")",
"{",
"return",
"'false'",
";",
"}",
"return",
"(",
"string",
")",
"$",
"value",
";",
"}"
] | Converts a value into the ini equivalent
@param mixed $value Value to export.
@return string String value for ini file. | [
"Converts",
"a",
"value",
"into",
"the",
"ini",
"equivalent"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/Configure/Engine/IniConfig.php#L187-L200 |
211,742 | cakephp/cakephp | src/View/Widget/RadioWidget.php | RadioWidget._isDisabled | protected function _isDisabled($radio, $disabled)
{
if (!$disabled) {
return false;
}
if ($disabled === true) {
return true;
}
$isNumeric = is_numeric($radio['value']);
return (!is_array($disabled) || in_array((string)$radio['value'], $disabled, !$isNumeric));
} | php | protected function _isDisabled($radio, $disabled)
{
if (!$disabled) {
return false;
}
if ($disabled === true) {
return true;
}
$isNumeric = is_numeric($radio['value']);
return (!is_array($disabled) || in_array((string)$radio['value'], $disabled, !$isNumeric));
} | [
"protected",
"function",
"_isDisabled",
"(",
"$",
"radio",
",",
"$",
"disabled",
")",
"{",
"if",
"(",
"!",
"$",
"disabled",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"disabled",
"===",
"true",
")",
"{",
"return",
"true",
";",
"}",
"$",
"isNumeric",
"=",
"is_numeric",
"(",
"$",
"radio",
"[",
"'value'",
"]",
")",
";",
"return",
"(",
"!",
"is_array",
"(",
"$",
"disabled",
")",
"||",
"in_array",
"(",
"(",
"string",
")",
"$",
"radio",
"[",
"'value'",
"]",
",",
"$",
"disabled",
",",
"!",
"$",
"isNumeric",
")",
")",
";",
"}"
] | Disabled attribute detection.
@param array $radio Radio info.
@param array|null|true $disabled The disabled values.
@return bool | [
"Disabled",
"attribute",
"detection",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Widget/RadioWidget.php#L128-L139 |
211,743 | cakephp/cakephp | src/Database/Expression/FunctionExpression.php | FunctionExpression.add | public function add($params, $types = [], $prepend = false)
{
$put = $prepend ? 'array_unshift' : 'array_push';
$typeMap = $this->getTypeMap()->setTypes($types);
foreach ($params as $k => $p) {
if ($p === 'literal') {
$put($this->_conditions, $k);
continue;
}
if ($p === 'identifier') {
$put($this->_conditions, new IdentifierExpression($k));
continue;
}
$type = $typeMap->type($k);
if ($type !== null && !$p instanceof ExpressionInterface) {
$p = $this->_castToExpression($p, $type);
}
if ($p instanceof ExpressionInterface) {
$put($this->_conditions, $p);
continue;
}
$put($this->_conditions, ['value' => $p, 'type' => $type]);
}
return $this;
} | php | public function add($params, $types = [], $prepend = false)
{
$put = $prepend ? 'array_unshift' : 'array_push';
$typeMap = $this->getTypeMap()->setTypes($types);
foreach ($params as $k => $p) {
if ($p === 'literal') {
$put($this->_conditions, $k);
continue;
}
if ($p === 'identifier') {
$put($this->_conditions, new IdentifierExpression($k));
continue;
}
$type = $typeMap->type($k);
if ($type !== null && !$p instanceof ExpressionInterface) {
$p = $this->_castToExpression($p, $type);
}
if ($p instanceof ExpressionInterface) {
$put($this->_conditions, $p);
continue;
}
$put($this->_conditions, ['value' => $p, 'type' => $type]);
}
return $this;
} | [
"public",
"function",
"add",
"(",
"$",
"params",
",",
"$",
"types",
"=",
"[",
"]",
",",
"$",
"prepend",
"=",
"false",
")",
"{",
"$",
"put",
"=",
"$",
"prepend",
"?",
"'array_unshift'",
":",
"'array_push'",
";",
"$",
"typeMap",
"=",
"$",
"this",
"->",
"getTypeMap",
"(",
")",
"->",
"setTypes",
"(",
"$",
"types",
")",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"k",
"=>",
"$",
"p",
")",
"{",
"if",
"(",
"$",
"p",
"===",
"'literal'",
")",
"{",
"$",
"put",
"(",
"$",
"this",
"->",
"_conditions",
",",
"$",
"k",
")",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"p",
"===",
"'identifier'",
")",
"{",
"$",
"put",
"(",
"$",
"this",
"->",
"_conditions",
",",
"new",
"IdentifierExpression",
"(",
"$",
"k",
")",
")",
";",
"continue",
";",
"}",
"$",
"type",
"=",
"$",
"typeMap",
"->",
"type",
"(",
"$",
"k",
")",
";",
"if",
"(",
"$",
"type",
"!==",
"null",
"&&",
"!",
"$",
"p",
"instanceof",
"ExpressionInterface",
")",
"{",
"$",
"p",
"=",
"$",
"this",
"->",
"_castToExpression",
"(",
"$",
"p",
",",
"$",
"type",
")",
";",
"}",
"if",
"(",
"$",
"p",
"instanceof",
"ExpressionInterface",
")",
"{",
"$",
"put",
"(",
"$",
"this",
"->",
"_conditions",
",",
"$",
"p",
")",
";",
"continue",
";",
"}",
"$",
"put",
"(",
"$",
"this",
"->",
"_conditions",
",",
"[",
"'value'",
"=>",
"$",
"p",
",",
"'type'",
"=>",
"$",
"type",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Adds one or more arguments for the function call.
@param array $params list of arguments to be passed to the function
If associative the key would be used as argument when value is 'literal'
@param array $types associative array of types to be associated with the
passed arguments
@param bool $prepend Whether to prepend or append to the list of arguments
@see \Cake\Database\Expression\FunctionExpression::__construct() for more details.
@return $this | [
"Adds",
"one",
"or",
"more",
"arguments",
"for",
"the",
"function",
"call",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/FunctionExpression.php#L129-L159 |
211,744 | cakephp/cakephp | src/Console/Command.php | Command.getOptionParser | public function getOptionParser()
{
list($root, $name) = explode(' ', $this->name, 2);
$parser = new ConsoleOptionParser($name);
$parser->setRootName($root);
$parser = $this->buildOptionParser($parser);
if (!($parser instanceof ConsoleOptionParser)) {
throw new RuntimeException(sprintf(
"Invalid option parser returned from buildOptionParser(). Expected %s, got %s",
ConsoleOptionParser::class,
getTypeName($parser)
));
}
return $parser;
} | php | public function getOptionParser()
{
list($root, $name) = explode(' ', $this->name, 2);
$parser = new ConsoleOptionParser($name);
$parser->setRootName($root);
$parser = $this->buildOptionParser($parser);
if (!($parser instanceof ConsoleOptionParser)) {
throw new RuntimeException(sprintf(
"Invalid option parser returned from buildOptionParser(). Expected %s, got %s",
ConsoleOptionParser::class,
getTypeName($parser)
));
}
return $parser;
} | [
"public",
"function",
"getOptionParser",
"(",
")",
"{",
"list",
"(",
"$",
"root",
",",
"$",
"name",
")",
"=",
"explode",
"(",
"' '",
",",
"$",
"this",
"->",
"name",
",",
"2",
")",
";",
"$",
"parser",
"=",
"new",
"ConsoleOptionParser",
"(",
"$",
"name",
")",
";",
"$",
"parser",
"->",
"setRootName",
"(",
"$",
"root",
")",
";",
"$",
"parser",
"=",
"$",
"this",
"->",
"buildOptionParser",
"(",
"$",
"parser",
")",
";",
"if",
"(",
"!",
"(",
"$",
"parser",
"instanceof",
"ConsoleOptionParser",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"\"Invalid option parser returned from buildOptionParser(). Expected %s, got %s\"",
",",
"ConsoleOptionParser",
"::",
"class",
",",
"getTypeName",
"(",
"$",
"parser",
")",
")",
")",
";",
"}",
"return",
"$",
"parser",
";",
"}"
] | Get the option parser.
You can override buildOptionParser() to define your options & arguments.
@return \Cake\Console\ConsoleOptionParser
@throws \RuntimeException When the parser is invalid | [
"Get",
"the",
"option",
"parser",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/Command.php#L109-L125 |
211,745 | cakephp/cakephp | src/Console/Command.php | Command.displayHelp | protected function displayHelp(ConsoleOptionParser $parser, Arguments $args, ConsoleIo $io)
{
$format = 'text';
if ($args->getArgumentAt(0) === 'xml') {
$format = 'xml';
$io->setOutputAs(ConsoleOutput::RAW);
}
$io->out($parser->help(null, $format));
} | php | protected function displayHelp(ConsoleOptionParser $parser, Arguments $args, ConsoleIo $io)
{
$format = 'text';
if ($args->getArgumentAt(0) === 'xml') {
$format = 'xml';
$io->setOutputAs(ConsoleOutput::RAW);
}
$io->out($parser->help(null, $format));
} | [
"protected",
"function",
"displayHelp",
"(",
"ConsoleOptionParser",
"$",
"parser",
",",
"Arguments",
"$",
"args",
",",
"ConsoleIo",
"$",
"io",
")",
"{",
"$",
"format",
"=",
"'text'",
";",
"if",
"(",
"$",
"args",
"->",
"getArgumentAt",
"(",
"0",
")",
"===",
"'xml'",
")",
"{",
"$",
"format",
"=",
"'xml'",
";",
"$",
"io",
"->",
"setOutputAs",
"(",
"ConsoleOutput",
"::",
"RAW",
")",
";",
"}",
"$",
"io",
"->",
"out",
"(",
"$",
"parser",
"->",
"help",
"(",
"null",
",",
"$",
"format",
")",
")",
";",
"}"
] | Output help content
@param \Cake\Console\ConsoleOptionParser $parser The option parser.
@param \Cake\Console\Arguments $args The command arguments.
@param \Cake\Console\ConsoleIo $io The console io
@return void | [
"Output",
"help",
"content"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/Command.php#L194-L203 |
211,746 | cakephp/cakephp | src/Console/Command.php | Command.setOutputLevel | protected function setOutputLevel(Arguments $args, ConsoleIo $io)
{
$io->setLoggers(ConsoleIo::NORMAL);
if ($args->getOption('quiet')) {
$io->level(ConsoleIo::QUIET);
$io->setLoggers(ConsoleIo::QUIET);
}
if ($args->getOption('verbose')) {
$io->level(ConsoleIo::VERBOSE);
$io->setLoggers(ConsoleIo::VERBOSE);
}
} | php | protected function setOutputLevel(Arguments $args, ConsoleIo $io)
{
$io->setLoggers(ConsoleIo::NORMAL);
if ($args->getOption('quiet')) {
$io->level(ConsoleIo::QUIET);
$io->setLoggers(ConsoleIo::QUIET);
}
if ($args->getOption('verbose')) {
$io->level(ConsoleIo::VERBOSE);
$io->setLoggers(ConsoleIo::VERBOSE);
}
} | [
"protected",
"function",
"setOutputLevel",
"(",
"Arguments",
"$",
"args",
",",
"ConsoleIo",
"$",
"io",
")",
"{",
"$",
"io",
"->",
"setLoggers",
"(",
"ConsoleIo",
"::",
"NORMAL",
")",
";",
"if",
"(",
"$",
"args",
"->",
"getOption",
"(",
"'quiet'",
")",
")",
"{",
"$",
"io",
"->",
"level",
"(",
"ConsoleIo",
"::",
"QUIET",
")",
";",
"$",
"io",
"->",
"setLoggers",
"(",
"ConsoleIo",
"::",
"QUIET",
")",
";",
"}",
"if",
"(",
"$",
"args",
"->",
"getOption",
"(",
"'verbose'",
")",
")",
"{",
"$",
"io",
"->",
"level",
"(",
"ConsoleIo",
"::",
"VERBOSE",
")",
";",
"$",
"io",
"->",
"setLoggers",
"(",
"ConsoleIo",
"::",
"VERBOSE",
")",
";",
"}",
"}"
] | Set the output level based on the Arguments.
@param \Cake\Console\Arguments $args The command arguments.
@param \Cake\Console\ConsoleIo $io The console io
@return void | [
"Set",
"the",
"output",
"level",
"based",
"on",
"the",
"Arguments",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/Command.php#L212-L223 |
211,747 | cakephp/cakephp | src/Utility/MergeVariablesTrait.php | MergeVariablesTrait._mergeProperty | protected function _mergeProperty($property, $parentClasses, $options)
{
$thisValue = $this->{$property};
$isAssoc = false;
if (isset($options['associative']) &&
in_array($property, (array)$options['associative'])
) {
$isAssoc = true;
}
if ($isAssoc) {
$thisValue = Hash::normalize($thisValue);
}
foreach ($parentClasses as $class) {
$parentProperties = get_class_vars($class);
if (empty($parentProperties[$property])) {
continue;
}
$parentProperty = $parentProperties[$property];
if (!is_array($parentProperty)) {
continue;
}
$thisValue = $this->_mergePropertyData($thisValue, $parentProperty, $isAssoc);
}
$this->{$property} = $thisValue;
} | php | protected function _mergeProperty($property, $parentClasses, $options)
{
$thisValue = $this->{$property};
$isAssoc = false;
if (isset($options['associative']) &&
in_array($property, (array)$options['associative'])
) {
$isAssoc = true;
}
if ($isAssoc) {
$thisValue = Hash::normalize($thisValue);
}
foreach ($parentClasses as $class) {
$parentProperties = get_class_vars($class);
if (empty($parentProperties[$property])) {
continue;
}
$parentProperty = $parentProperties[$property];
if (!is_array($parentProperty)) {
continue;
}
$thisValue = $this->_mergePropertyData($thisValue, $parentProperty, $isAssoc);
}
$this->{$property} = $thisValue;
} | [
"protected",
"function",
"_mergeProperty",
"(",
"$",
"property",
",",
"$",
"parentClasses",
",",
"$",
"options",
")",
"{",
"$",
"thisValue",
"=",
"$",
"this",
"->",
"{",
"$",
"property",
"}",
";",
"$",
"isAssoc",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'associative'",
"]",
")",
"&&",
"in_array",
"(",
"$",
"property",
",",
"(",
"array",
")",
"$",
"options",
"[",
"'associative'",
"]",
")",
")",
"{",
"$",
"isAssoc",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"isAssoc",
")",
"{",
"$",
"thisValue",
"=",
"Hash",
"::",
"normalize",
"(",
"$",
"thisValue",
")",
";",
"}",
"foreach",
"(",
"$",
"parentClasses",
"as",
"$",
"class",
")",
"{",
"$",
"parentProperties",
"=",
"get_class_vars",
"(",
"$",
"class",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"parentProperties",
"[",
"$",
"property",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"parentProperty",
"=",
"$",
"parentProperties",
"[",
"$",
"property",
"]",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"parentProperty",
")",
")",
"{",
"continue",
";",
"}",
"$",
"thisValue",
"=",
"$",
"this",
"->",
"_mergePropertyData",
"(",
"$",
"thisValue",
",",
"$",
"parentProperty",
",",
"$",
"isAssoc",
")",
";",
"}",
"$",
"this",
"->",
"{",
"$",
"property",
"}",
"=",
"$",
"thisValue",
";",
"}"
] | Merge a single property with the values declared in all parent classes.
@param string $property The name of the property being merged.
@param array $parentClasses An array of classes you want to merge with.
@param array $options Options for merging the property, see _mergeVars()
@return void | [
"Merge",
"a",
"single",
"property",
"with",
"the",
"values",
"declared",
"in",
"all",
"parent",
"classes",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/MergeVariablesTrait.php#L67-L92 |
211,748 | cakephp/cakephp | src/Utility/MergeVariablesTrait.php | MergeVariablesTrait._mergePropertyData | protected function _mergePropertyData($current, $parent, $isAssoc)
{
if (!$isAssoc) {
return array_merge($parent, $current);
}
$parent = Hash::normalize($parent);
foreach ($parent as $key => $value) {
if (!isset($current[$key])) {
$current[$key] = $value;
}
}
return $current;
} | php | protected function _mergePropertyData($current, $parent, $isAssoc)
{
if (!$isAssoc) {
return array_merge($parent, $current);
}
$parent = Hash::normalize($parent);
foreach ($parent as $key => $value) {
if (!isset($current[$key])) {
$current[$key] = $value;
}
}
return $current;
} | [
"protected",
"function",
"_mergePropertyData",
"(",
"$",
"current",
",",
"$",
"parent",
",",
"$",
"isAssoc",
")",
"{",
"if",
"(",
"!",
"$",
"isAssoc",
")",
"{",
"return",
"array_merge",
"(",
"$",
"parent",
",",
"$",
"current",
")",
";",
"}",
"$",
"parent",
"=",
"Hash",
"::",
"normalize",
"(",
"$",
"parent",
")",
";",
"foreach",
"(",
"$",
"parent",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"current",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"current",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"current",
";",
"}"
] | Merge each of the keys in a property together.
@param array $current The current merged value.
@param array $parent The parent class' value.
@param bool $isAssoc Whether or not the merging should be done in associative mode.
@return mixed The updated value. | [
"Merge",
"each",
"of",
"the",
"keys",
"in",
"a",
"property",
"together",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/MergeVariablesTrait.php#L102-L115 |
211,749 | cakephp/cakephp | src/Http/Middleware/SecurityHeadersMiddleware.php | SecurityHeadersMiddleware.setReferrerPolicy | public function setReferrerPolicy($policy = self::SAME_ORIGIN)
{
$available = [
self::NO_REFERRER,
self::NO_REFERRER_WHEN_DOWNGRADE,
self::ORIGIN,
self::ORIGIN_WHEN_CROSS_ORIGIN,
self::SAME_ORIGIN,
self::STRICT_ORIGIN,
self::STRICT_ORIGIN_WHEN_CROSS_ORIGIN,
self::UNSAFE_URL,
];
$this->checkValues($policy, $available);
$this->headers['referrer-policy'] = $policy;
return $this;
} | php | public function setReferrerPolicy($policy = self::SAME_ORIGIN)
{
$available = [
self::NO_REFERRER,
self::NO_REFERRER_WHEN_DOWNGRADE,
self::ORIGIN,
self::ORIGIN_WHEN_CROSS_ORIGIN,
self::SAME_ORIGIN,
self::STRICT_ORIGIN,
self::STRICT_ORIGIN_WHEN_CROSS_ORIGIN,
self::UNSAFE_URL,
];
$this->checkValues($policy, $available);
$this->headers['referrer-policy'] = $policy;
return $this;
} | [
"public",
"function",
"setReferrerPolicy",
"(",
"$",
"policy",
"=",
"self",
"::",
"SAME_ORIGIN",
")",
"{",
"$",
"available",
"=",
"[",
"self",
"::",
"NO_REFERRER",
",",
"self",
"::",
"NO_REFERRER_WHEN_DOWNGRADE",
",",
"self",
"::",
"ORIGIN",
",",
"self",
"::",
"ORIGIN_WHEN_CROSS_ORIGIN",
",",
"self",
"::",
"SAME_ORIGIN",
",",
"self",
"::",
"STRICT_ORIGIN",
",",
"self",
"::",
"STRICT_ORIGIN_WHEN_CROSS_ORIGIN",
",",
"self",
"::",
"UNSAFE_URL",
",",
"]",
";",
"$",
"this",
"->",
"checkValues",
"(",
"$",
"policy",
",",
"$",
"available",
")",
";",
"$",
"this",
"->",
"headers",
"[",
"'referrer-policy'",
"]",
"=",
"$",
"policy",
";",
"return",
"$",
"this",
";",
"}"
] | Referrer-Policy
@link https://w3c.github.io/webappsec-referrer-policy
@param string $policy Policy value. Available Value: 'no-referrer', 'no-referrer-when-downgrade', 'origin',
'origin-when-cross-origin', 'same-origin', 'strict-origin', 'strict-origin-when-cross-origin', 'unsafe-url'
@return $this | [
"Referrer",
"-",
"Policy"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Middleware/SecurityHeadersMiddleware.php#L139-L156 |
211,750 | cakephp/cakephp | src/Http/Middleware/SecurityHeadersMiddleware.php | SecurityHeadersMiddleware.setXFrameOptions | public function setXFrameOptions($option = self::SAMEORIGIN, $url = null)
{
$this->checkValues($option, [self::DENY, self::SAMEORIGIN, self::ALLOW_FROM]);
if ($option === self::ALLOW_FROM) {
if (empty($url)) {
throw new InvalidArgumentException('The 2nd arg $url can not be empty when `allow-from` is used');
}
$option .= ' ' . $url;
}
$this->headers['x-frame-options'] = $option;
return $this;
} | php | public function setXFrameOptions($option = self::SAMEORIGIN, $url = null)
{
$this->checkValues($option, [self::DENY, self::SAMEORIGIN, self::ALLOW_FROM]);
if ($option === self::ALLOW_FROM) {
if (empty($url)) {
throw new InvalidArgumentException('The 2nd arg $url can not be empty when `allow-from` is used');
}
$option .= ' ' . $url;
}
$this->headers['x-frame-options'] = $option;
return $this;
} | [
"public",
"function",
"setXFrameOptions",
"(",
"$",
"option",
"=",
"self",
"::",
"SAMEORIGIN",
",",
"$",
"url",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"checkValues",
"(",
"$",
"option",
",",
"[",
"self",
"::",
"DENY",
",",
"self",
"::",
"SAMEORIGIN",
",",
"self",
"::",
"ALLOW_FROM",
"]",
")",
";",
"if",
"(",
"$",
"option",
"===",
"self",
"::",
"ALLOW_FROM",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"url",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The 2nd arg $url can not be empty when `allow-from` is used'",
")",
";",
"}",
"$",
"option",
".=",
"' '",
".",
"$",
"url",
";",
"}",
"$",
"this",
"->",
"headers",
"[",
"'x-frame-options'",
"]",
"=",
"$",
"option",
";",
"return",
"$",
"this",
";",
"}"
] | X-Frame-Options
@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
@param string $option Option value. Available Values: 'deny', 'sameorigin', 'allow-from <uri>'
@param string $url URL if mode is `allow-from`
@return $this | [
"X",
"-",
"Frame",
"-",
"Options"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Middleware/SecurityHeadersMiddleware.php#L166-L180 |
211,751 | cakephp/cakephp | src/Http/Middleware/SecurityHeadersMiddleware.php | SecurityHeadersMiddleware.setXssProtection | public function setXssProtection($mode = self::XSS_BLOCK)
{
$mode = (string)$mode;
if ($mode === self::XSS_BLOCK) {
$mode = self::XSS_ENABLED_BLOCK;
}
$this->checkValues($mode, [self::XSS_ENABLED, self::XSS_DISABLED, self::XSS_ENABLED_BLOCK]);
$this->headers['x-xss-protection'] = $mode;
return $this;
} | php | public function setXssProtection($mode = self::XSS_BLOCK)
{
$mode = (string)$mode;
if ($mode === self::XSS_BLOCK) {
$mode = self::XSS_ENABLED_BLOCK;
}
$this->checkValues($mode, [self::XSS_ENABLED, self::XSS_DISABLED, self::XSS_ENABLED_BLOCK]);
$this->headers['x-xss-protection'] = $mode;
return $this;
} | [
"public",
"function",
"setXssProtection",
"(",
"$",
"mode",
"=",
"self",
"::",
"XSS_BLOCK",
")",
"{",
"$",
"mode",
"=",
"(",
"string",
")",
"$",
"mode",
";",
"if",
"(",
"$",
"mode",
"===",
"self",
"::",
"XSS_BLOCK",
")",
"{",
"$",
"mode",
"=",
"self",
"::",
"XSS_ENABLED_BLOCK",
";",
"}",
"$",
"this",
"->",
"checkValues",
"(",
"$",
"mode",
",",
"[",
"self",
"::",
"XSS_ENABLED",
",",
"self",
"::",
"XSS_DISABLED",
",",
"self",
"::",
"XSS_ENABLED_BLOCK",
"]",
")",
";",
"$",
"this",
"->",
"headers",
"[",
"'x-xss-protection'",
"]",
"=",
"$",
"mode",
";",
"return",
"$",
"this",
";",
"}"
] | X-XSS-Protection
@link https://blogs.msdn.microsoft.com/ieinternals/2011/01/31/controlling-the-xss-filter
@param string $mode Mode value. Available Values: '1', '0', 'block'
@return $this | [
"X",
"-",
"XSS",
"-",
"Protection"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Middleware/SecurityHeadersMiddleware.php#L189-L201 |
211,752 | cakephp/cakephp | src/Http/Middleware/SecurityHeadersMiddleware.php | SecurityHeadersMiddleware.setCrossDomainPolicy | public function setCrossDomainPolicy($policy = self::ALL)
{
$this->checkValues($policy, [
self::ALL,
self::NONE,
self::MASTER_ONLY,
self::BY_CONTENT_TYPE,
self::BY_FTP_FILENAME,
]);
$this->headers['x-permitted-cross-domain-policies'] = $policy;
return $this;
} | php | public function setCrossDomainPolicy($policy = self::ALL)
{
$this->checkValues($policy, [
self::ALL,
self::NONE,
self::MASTER_ONLY,
self::BY_CONTENT_TYPE,
self::BY_FTP_FILENAME,
]);
$this->headers['x-permitted-cross-domain-policies'] = $policy;
return $this;
} | [
"public",
"function",
"setCrossDomainPolicy",
"(",
"$",
"policy",
"=",
"self",
"::",
"ALL",
")",
"{",
"$",
"this",
"->",
"checkValues",
"(",
"$",
"policy",
",",
"[",
"self",
"::",
"ALL",
",",
"self",
"::",
"NONE",
",",
"self",
"::",
"MASTER_ONLY",
",",
"self",
"::",
"BY_CONTENT_TYPE",
",",
"self",
"::",
"BY_FTP_FILENAME",
",",
"]",
")",
";",
"$",
"this",
"->",
"headers",
"[",
"'x-permitted-cross-domain-policies'",
"]",
"=",
"$",
"policy",
";",
"return",
"$",
"this",
";",
"}"
] | X-Permitted-Cross-Domain-Policies
@link https://www.adobe.com/devnet/adobe-media-server/articles/cross-domain-xml-for-streaming.html
@param string $policy Policy value. Available Values: 'all', 'none', 'master-only', 'by-content-type',
'by-ftp-filename'
@return $this | [
"X",
"-",
"Permitted",
"-",
"Cross",
"-",
"Domain",
"-",
"Policies"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Middleware/SecurityHeadersMiddleware.php#L211-L223 |
211,753 | cakephp/cakephp | src/Http/Middleware/SecurityHeadersMiddleware.php | SecurityHeadersMiddleware.checkValues | protected function checkValues($value, array $allowed)
{
if (!in_array($value, $allowed)) {
throw new InvalidArgumentException(sprintf(
'Invalid arg `%s`, use one of these: %s',
$value,
implode(', ', $allowed)
));
}
} | php | protected function checkValues($value, array $allowed)
{
if (!in_array($value, $allowed)) {
throw new InvalidArgumentException(sprintf(
'Invalid arg `%s`, use one of these: %s',
$value,
implode(', ', $allowed)
));
}
} | [
"protected",
"function",
"checkValues",
"(",
"$",
"value",
",",
"array",
"$",
"allowed",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"value",
",",
"$",
"allowed",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid arg `%s`, use one of these: %s'",
",",
"$",
"value",
",",
"implode",
"(",
"', '",
",",
"$",
"allowed",
")",
")",
")",
";",
"}",
"}"
] | Convenience method to check if a value is in the list of allowed args
@throws \InvalidArgumentException Thrown when a value is invalid.
@param string $value Value to check
@param array $allowed List of allowed values
@return void | [
"Convenience",
"method",
"to",
"check",
"if",
"a",
"value",
"is",
"in",
"the",
"list",
"of",
"allowed",
"args"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Middleware/SecurityHeadersMiddleware.php#L233-L242 |
211,754 | cakephp/cakephp | src/View/Helper/RssHelper.php | RssHelper.elem | public function elem($name, $attrib = [], $content = null, $endTag = true)
{
$namespace = null;
if (isset($attrib['namespace'])) {
$namespace = $attrib['namespace'];
unset($attrib['namespace']);
}
$cdata = false;
if (is_array($content) && isset($content['cdata'])) {
$cdata = true;
unset($content['cdata']);
}
if (is_array($content) && array_key_exists('value', $content)) {
$content = $content['value'];
}
$children = [];
if (is_array($content)) {
$children = $content;
$content = null;
}
$xml = '<' . $name;
if (!empty($namespace)) {
$xml .= ' xmlns';
if (is_array($namespace)) {
$xml .= ':' . $namespace['prefix'];
$namespace = $namespace['url'];
}
$xml .= '="' . $namespace . '"';
}
$bareName = $name;
if (strpos($name, ':') !== false) {
list($prefix, $bareName) = explode(':', $name, 2);
switch ($prefix) {
case 'atom':
$xml .= ' xmlns:atom="http://www.w3.org/2005/Atom"';
break;
}
}
if ($cdata && !empty($content)) {
$content = '<![CDATA[' . $content . ']]>';
}
$xml .= '>' . $content . '</' . $name . '>';
$elem = Xml::build($xml, ['return' => 'domdocument']);
$nodes = $elem->getElementsByTagName($bareName);
if ($attrib) {
foreach ($attrib as $key => $value) {
$nodes->item(0)->setAttribute($key, $value);
}
}
foreach ($children as $child) {
$child = $elem->createElement($name, $child);
$nodes->item(0)->appendChild($child);
}
$xml = $elem->saveXml();
$xml = trim(substr($xml, strpos($xml, '?>') + 2));
return $xml;
} | php | public function elem($name, $attrib = [], $content = null, $endTag = true)
{
$namespace = null;
if (isset($attrib['namespace'])) {
$namespace = $attrib['namespace'];
unset($attrib['namespace']);
}
$cdata = false;
if (is_array($content) && isset($content['cdata'])) {
$cdata = true;
unset($content['cdata']);
}
if (is_array($content) && array_key_exists('value', $content)) {
$content = $content['value'];
}
$children = [];
if (is_array($content)) {
$children = $content;
$content = null;
}
$xml = '<' . $name;
if (!empty($namespace)) {
$xml .= ' xmlns';
if (is_array($namespace)) {
$xml .= ':' . $namespace['prefix'];
$namespace = $namespace['url'];
}
$xml .= '="' . $namespace . '"';
}
$bareName = $name;
if (strpos($name, ':') !== false) {
list($prefix, $bareName) = explode(':', $name, 2);
switch ($prefix) {
case 'atom':
$xml .= ' xmlns:atom="http://www.w3.org/2005/Atom"';
break;
}
}
if ($cdata && !empty($content)) {
$content = '<![CDATA[' . $content . ']]>';
}
$xml .= '>' . $content . '</' . $name . '>';
$elem = Xml::build($xml, ['return' => 'domdocument']);
$nodes = $elem->getElementsByTagName($bareName);
if ($attrib) {
foreach ($attrib as $key => $value) {
$nodes->item(0)->setAttribute($key, $value);
}
}
foreach ($children as $child) {
$child = $elem->createElement($name, $child);
$nodes->item(0)->appendChild($child);
}
$xml = $elem->saveXml();
$xml = trim(substr($xml, strpos($xml, '?>') + 2));
return $xml;
} | [
"public",
"function",
"elem",
"(",
"$",
"name",
",",
"$",
"attrib",
"=",
"[",
"]",
",",
"$",
"content",
"=",
"null",
",",
"$",
"endTag",
"=",
"true",
")",
"{",
"$",
"namespace",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"attrib",
"[",
"'namespace'",
"]",
")",
")",
"{",
"$",
"namespace",
"=",
"$",
"attrib",
"[",
"'namespace'",
"]",
";",
"unset",
"(",
"$",
"attrib",
"[",
"'namespace'",
"]",
")",
";",
"}",
"$",
"cdata",
"=",
"false",
";",
"if",
"(",
"is_array",
"(",
"$",
"content",
")",
"&&",
"isset",
"(",
"$",
"content",
"[",
"'cdata'",
"]",
")",
")",
"{",
"$",
"cdata",
"=",
"true",
";",
"unset",
"(",
"$",
"content",
"[",
"'cdata'",
"]",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"content",
")",
"&&",
"array_key_exists",
"(",
"'value'",
",",
"$",
"content",
")",
")",
"{",
"$",
"content",
"=",
"$",
"content",
"[",
"'value'",
"]",
";",
"}",
"$",
"children",
"=",
"[",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"content",
")",
")",
"{",
"$",
"children",
"=",
"$",
"content",
";",
"$",
"content",
"=",
"null",
";",
"}",
"$",
"xml",
"=",
"'<'",
".",
"$",
"name",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"namespace",
")",
")",
"{",
"$",
"xml",
".=",
"' xmlns'",
";",
"if",
"(",
"is_array",
"(",
"$",
"namespace",
")",
")",
"{",
"$",
"xml",
".=",
"':'",
".",
"$",
"namespace",
"[",
"'prefix'",
"]",
";",
"$",
"namespace",
"=",
"$",
"namespace",
"[",
"'url'",
"]",
";",
"}",
"$",
"xml",
".=",
"'=\"'",
".",
"$",
"namespace",
".",
"'\"'",
";",
"}",
"$",
"bareName",
"=",
"$",
"name",
";",
"if",
"(",
"strpos",
"(",
"$",
"name",
",",
"':'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"prefix",
",",
"$",
"bareName",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"name",
",",
"2",
")",
";",
"switch",
"(",
"$",
"prefix",
")",
"{",
"case",
"'atom'",
":",
"$",
"xml",
".=",
"' xmlns:atom=\"http://www.w3.org/2005/Atom\"'",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"cdata",
"&&",
"!",
"empty",
"(",
"$",
"content",
")",
")",
"{",
"$",
"content",
"=",
"'<![CDATA['",
".",
"$",
"content",
".",
"']]>'",
";",
"}",
"$",
"xml",
".=",
"'>'",
".",
"$",
"content",
".",
"'</'",
".",
"$",
"name",
".",
"'>'",
";",
"$",
"elem",
"=",
"Xml",
"::",
"build",
"(",
"$",
"xml",
",",
"[",
"'return'",
"=>",
"'domdocument'",
"]",
")",
";",
"$",
"nodes",
"=",
"$",
"elem",
"->",
"getElementsByTagName",
"(",
"$",
"bareName",
")",
";",
"if",
"(",
"$",
"attrib",
")",
"{",
"foreach",
"(",
"$",
"attrib",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"nodes",
"->",
"item",
"(",
"0",
")",
"->",
"setAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"children",
"as",
"$",
"child",
")",
"{",
"$",
"child",
"=",
"$",
"elem",
"->",
"createElement",
"(",
"$",
"name",
",",
"$",
"child",
")",
";",
"$",
"nodes",
"->",
"item",
"(",
"0",
")",
"->",
"appendChild",
"(",
"$",
"child",
")",
";",
"}",
"$",
"xml",
"=",
"$",
"elem",
"->",
"saveXml",
"(",
")",
";",
"$",
"xml",
"=",
"trim",
"(",
"substr",
"(",
"$",
"xml",
",",
"strpos",
"(",
"$",
"xml",
",",
"'?>'",
")",
"+",
"2",
")",
")",
";",
"return",
"$",
"xml",
";",
"}"
] | Generates an XML element
@param string $name The name of the XML element
@param array $attrib The attributes of the XML element
@param string|array|null $content XML element content
@param bool $endTag Whether the end tag of the element should be printed
@return string XML | [
"Generates",
"an",
"XML",
"element"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/RssHelper.php#L308-L367 |
211,755 | cakephp/cakephp | src/ORM/ResultSet.php | ResultSet.rewind | public function rewind()
{
if ($this->_index == 0) {
return;
}
if (!$this->_useBuffering) {
$msg = 'You cannot rewind an un-buffered ResultSet. Use Query::bufferResults() to get a buffered ResultSet.';
throw new Exception($msg);
}
$this->_index = 0;
} | php | public function rewind()
{
if ($this->_index == 0) {
return;
}
if (!$this->_useBuffering) {
$msg = 'You cannot rewind an un-buffered ResultSet. Use Query::bufferResults() to get a buffered ResultSet.';
throw new Exception($msg);
}
$this->_index = 0;
} | [
"public",
"function",
"rewind",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_index",
"==",
"0",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"_useBuffering",
")",
"{",
"$",
"msg",
"=",
"'You cannot rewind an un-buffered ResultSet. Use Query::bufferResults() to get a buffered ResultSet.'",
";",
"throw",
"new",
"Exception",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"this",
"->",
"_index",
"=",
"0",
";",
"}"
] | Rewinds a ResultSet.
Part of Iterator interface.
@throws \Cake\Database\Exception
@return void | [
"Rewinds",
"a",
"ResultSet",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/ResultSet.php#L241-L253 |
211,756 | cakephp/cakephp | src/ORM/ResultSet.php | ResultSet.first | public function first()
{
foreach ($this as $result) {
if ($this->_statement && !$this->_useBuffering) {
$this->_statement->closeCursor();
}
return $result;
}
} | php | public function first()
{
foreach ($this as $result) {
if ($this->_statement && !$this->_useBuffering) {
$this->_statement->closeCursor();
}
return $result;
}
} | [
"public",
"function",
"first",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"as",
"$",
"result",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_statement",
"&&",
"!",
"$",
"this",
"->",
"_useBuffering",
")",
"{",
"$",
"this",
"->",
"_statement",
"->",
"closeCursor",
"(",
")",
";",
"}",
"return",
"$",
"result",
";",
"}",
"}"
] | Get the first record from a result set.
This method will also close the underlying statement cursor.
@return array|object | [
"Get",
"the",
"first",
"record",
"from",
"a",
"result",
"set",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/ResultSet.php#L296-L305 |
211,757 | cakephp/cakephp | src/ORM/ResultSet.php | ResultSet.serialize | public function serialize()
{
if (!$this->_useBuffering) {
$msg = 'You cannot serialize an un-buffered ResultSet. Use Query::bufferResults() to get a buffered ResultSet.';
throw new Exception($msg);
}
while ($this->valid()) {
$this->next();
}
if ($this->_results instanceof SplFixedArray) {
return serialize($this->_results->toArray());
}
return serialize($this->_results);
} | php | public function serialize()
{
if (!$this->_useBuffering) {
$msg = 'You cannot serialize an un-buffered ResultSet. Use Query::bufferResults() to get a buffered ResultSet.';
throw new Exception($msg);
}
while ($this->valid()) {
$this->next();
}
if ($this->_results instanceof SplFixedArray) {
return serialize($this->_results->toArray());
}
return serialize($this->_results);
} | [
"public",
"function",
"serialize",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_useBuffering",
")",
"{",
"$",
"msg",
"=",
"'You cannot serialize an un-buffered ResultSet. Use Query::bufferResults() to get a buffered ResultSet.'",
";",
"throw",
"new",
"Exception",
"(",
"$",
"msg",
")",
";",
"}",
"while",
"(",
"$",
"this",
"->",
"valid",
"(",
")",
")",
"{",
"$",
"this",
"->",
"next",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_results",
"instanceof",
"SplFixedArray",
")",
"{",
"return",
"serialize",
"(",
"$",
"this",
"->",
"_results",
"->",
"toArray",
"(",
")",
")",
";",
"}",
"return",
"serialize",
"(",
"$",
"this",
"->",
"_results",
")",
";",
"}"
] | Serializes a resultset.
Part of Serializable interface.
@return string Serialized object | [
"Serializes",
"a",
"resultset",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/ResultSet.php#L314-L330 |
211,758 | cakephp/cakephp | src/ORM/ResultSet.php | ResultSet.unserialize | public function unserialize($serialized)
{
$results = (array)(unserialize($serialized) ?: []);
$this->_results = SplFixedArray::fromArray($results);
$this->_useBuffering = true;
$this->_count = $this->_results->count();
} | php | public function unserialize($serialized)
{
$results = (array)(unserialize($serialized) ?: []);
$this->_results = SplFixedArray::fromArray($results);
$this->_useBuffering = true;
$this->_count = $this->_results->count();
} | [
"public",
"function",
"unserialize",
"(",
"$",
"serialized",
")",
"{",
"$",
"results",
"=",
"(",
"array",
")",
"(",
"unserialize",
"(",
"$",
"serialized",
")",
"?",
":",
"[",
"]",
")",
";",
"$",
"this",
"->",
"_results",
"=",
"SplFixedArray",
"::",
"fromArray",
"(",
"$",
"results",
")",
";",
"$",
"this",
"->",
"_useBuffering",
"=",
"true",
";",
"$",
"this",
"->",
"_count",
"=",
"$",
"this",
"->",
"_results",
"->",
"count",
"(",
")",
";",
"}"
] | Unserializes a resultset.
Part of Serializable interface.
@param string $serialized Serialized object
@return void | [
"Unserializes",
"a",
"resultset",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/ResultSet.php#L340-L346 |
211,759 | cakephp/cakephp | src/ORM/ResultSet.php | ResultSet.count | public function count()
{
if ($this->_count !== null) {
return $this->_count;
}
if ($this->_statement) {
return $this->_count = $this->_statement->rowCount();
}
if ($this->_results instanceof SplFixedArray) {
$this->_count = $this->_results->count();
} else {
$this->_count = count($this->_results);
}
return $this->_count;
} | php | public function count()
{
if ($this->_count !== null) {
return $this->_count;
}
if ($this->_statement) {
return $this->_count = $this->_statement->rowCount();
}
if ($this->_results instanceof SplFixedArray) {
$this->_count = $this->_results->count();
} else {
$this->_count = count($this->_results);
}
return $this->_count;
} | [
"public",
"function",
"count",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_count",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_count",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_statement",
")",
"{",
"return",
"$",
"this",
"->",
"_count",
"=",
"$",
"this",
"->",
"_statement",
"->",
"rowCount",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_results",
"instanceof",
"SplFixedArray",
")",
"{",
"$",
"this",
"->",
"_count",
"=",
"$",
"this",
"->",
"_results",
"->",
"count",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_count",
"=",
"count",
"(",
"$",
"this",
"->",
"_results",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_count",
";",
"}"
] | Gives the number of rows in the result set.
Part of the Countable interface.
@return int | [
"Gives",
"the",
"number",
"of",
"rows",
"in",
"the",
"result",
"set",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/ResultSet.php#L355-L371 |
211,760 | cakephp/cakephp | src/ORM/ResultSet.php | ResultSet._calculateAssociationMap | protected function _calculateAssociationMap($query)
{
$map = $query->getEagerLoader()->associationsMap($this->_defaultTable);
$this->_matchingMap = (new Collection($map))
->match(['matching' => true])
->indexBy('alias')
->toArray();
$this->_containMap = (new Collection(array_reverse($map)))
->match(['matching' => false])
->indexBy('nestKey')
->toArray();
} | php | protected function _calculateAssociationMap($query)
{
$map = $query->getEagerLoader()->associationsMap($this->_defaultTable);
$this->_matchingMap = (new Collection($map))
->match(['matching' => true])
->indexBy('alias')
->toArray();
$this->_containMap = (new Collection(array_reverse($map)))
->match(['matching' => false])
->indexBy('nestKey')
->toArray();
} | [
"protected",
"function",
"_calculateAssociationMap",
"(",
"$",
"query",
")",
"{",
"$",
"map",
"=",
"$",
"query",
"->",
"getEagerLoader",
"(",
")",
"->",
"associationsMap",
"(",
"$",
"this",
"->",
"_defaultTable",
")",
";",
"$",
"this",
"->",
"_matchingMap",
"=",
"(",
"new",
"Collection",
"(",
"$",
"map",
")",
")",
"->",
"match",
"(",
"[",
"'matching'",
"=>",
"true",
"]",
")",
"->",
"indexBy",
"(",
"'alias'",
")",
"->",
"toArray",
"(",
")",
";",
"$",
"this",
"->",
"_containMap",
"=",
"(",
"new",
"Collection",
"(",
"array_reverse",
"(",
"$",
"map",
")",
")",
")",
"->",
"match",
"(",
"[",
"'matching'",
"=>",
"false",
"]",
")",
"->",
"indexBy",
"(",
"'nestKey'",
")",
"->",
"toArray",
"(",
")",
";",
"}"
] | Calculates the list of associations that should get eager loaded
when fetching each record
@param \Cake\ORM\Query $query The query from where to derive the associations
@return void | [
"Calculates",
"the",
"list",
"of",
"associations",
"that",
"should",
"get",
"eager",
"loaded",
"when",
"fetching",
"each",
"record"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/ResultSet.php#L380-L392 |
211,761 | cakephp/cakephp | src/ORM/ResultSet.php | ResultSet._calculateColumnMap | protected function _calculateColumnMap($query)
{
$map = [];
foreach ($query->clause('select') as $key => $field) {
$key = trim($key, '"`[]');
if (strpos($key, '__') <= 0) {
$map[$this->_defaultAlias][$key] = $key;
continue;
}
$parts = explode('__', $key, 2);
$map[$parts[0]][$key] = $parts[1];
}
foreach ($this->_matchingMap as $alias => $assoc) {
if (!isset($map[$alias])) {
continue;
}
$this->_matchingMapColumns[$alias] = $map[$alias];
unset($map[$alias]);
}
$this->_map = $map;
} | php | protected function _calculateColumnMap($query)
{
$map = [];
foreach ($query->clause('select') as $key => $field) {
$key = trim($key, '"`[]');
if (strpos($key, '__') <= 0) {
$map[$this->_defaultAlias][$key] = $key;
continue;
}
$parts = explode('__', $key, 2);
$map[$parts[0]][$key] = $parts[1];
}
foreach ($this->_matchingMap as $alias => $assoc) {
if (!isset($map[$alias])) {
continue;
}
$this->_matchingMapColumns[$alias] = $map[$alias];
unset($map[$alias]);
}
$this->_map = $map;
} | [
"protected",
"function",
"_calculateColumnMap",
"(",
"$",
"query",
")",
"{",
"$",
"map",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"query",
"->",
"clause",
"(",
"'select'",
")",
"as",
"$",
"key",
"=>",
"$",
"field",
")",
"{",
"$",
"key",
"=",
"trim",
"(",
"$",
"key",
",",
"'\"`[]'",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"key",
",",
"'__'",
")",
"<=",
"0",
")",
"{",
"$",
"map",
"[",
"$",
"this",
"->",
"_defaultAlias",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"key",
";",
"continue",
";",
"}",
"$",
"parts",
"=",
"explode",
"(",
"'__'",
",",
"$",
"key",
",",
"2",
")",
";",
"$",
"map",
"[",
"$",
"parts",
"[",
"0",
"]",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"parts",
"[",
"1",
"]",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"_matchingMap",
"as",
"$",
"alias",
"=>",
"$",
"assoc",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"map",
"[",
"$",
"alias",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"_matchingMapColumns",
"[",
"$",
"alias",
"]",
"=",
"$",
"map",
"[",
"$",
"alias",
"]",
";",
"unset",
"(",
"$",
"map",
"[",
"$",
"alias",
"]",
")",
";",
"}",
"$",
"this",
"->",
"_map",
"=",
"$",
"map",
";",
"}"
] | Creates a map of row keys out of the query select clause that can be
used to hydrate nested result sets more quickly.
@param \Cake\ORM\Query $query The query from where to derive the column map
@return void | [
"Creates",
"a",
"map",
"of",
"row",
"keys",
"out",
"of",
"the",
"query",
"select",
"clause",
"that",
"can",
"be",
"used",
"to",
"hydrate",
"nested",
"result",
"sets",
"more",
"quickly",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/ResultSet.php#L401-L425 |
211,762 | cakephp/cakephp | src/ORM/ResultSet.php | ResultSet._getTypes | protected function _getTypes($table, $fields)
{
$types = [];
$schema = $table->getSchema();
$map = array_keys((array)Type::getMap() + ['string' => 1, 'text' => 1, 'boolean' => 1]);
$typeMap = array_combine(
$map,
array_map(['Cake\Database\Type', 'build'], $map)
);
foreach (['string', 'text'] as $t) {
if (get_class($typeMap[$t]) === 'Cake\Database\Type') {
unset($typeMap[$t]);
}
}
foreach (array_intersect($fields, $schema->columns()) as $col) {
$typeName = $schema->getColumnType($col);
if (isset($typeMap[$typeName])) {
$types[$col] = $typeMap[$typeName];
}
}
return $types;
} | php | protected function _getTypes($table, $fields)
{
$types = [];
$schema = $table->getSchema();
$map = array_keys((array)Type::getMap() + ['string' => 1, 'text' => 1, 'boolean' => 1]);
$typeMap = array_combine(
$map,
array_map(['Cake\Database\Type', 'build'], $map)
);
foreach (['string', 'text'] as $t) {
if (get_class($typeMap[$t]) === 'Cake\Database\Type') {
unset($typeMap[$t]);
}
}
foreach (array_intersect($fields, $schema->columns()) as $col) {
$typeName = $schema->getColumnType($col);
if (isset($typeMap[$typeName])) {
$types[$col] = $typeMap[$typeName];
}
}
return $types;
} | [
"protected",
"function",
"_getTypes",
"(",
"$",
"table",
",",
"$",
"fields",
")",
"{",
"$",
"types",
"=",
"[",
"]",
";",
"$",
"schema",
"=",
"$",
"table",
"->",
"getSchema",
"(",
")",
";",
"$",
"map",
"=",
"array_keys",
"(",
"(",
"array",
")",
"Type",
"::",
"getMap",
"(",
")",
"+",
"[",
"'string'",
"=>",
"1",
",",
"'text'",
"=>",
"1",
",",
"'boolean'",
"=>",
"1",
"]",
")",
";",
"$",
"typeMap",
"=",
"array_combine",
"(",
"$",
"map",
",",
"array_map",
"(",
"[",
"'Cake\\Database\\Type'",
",",
"'build'",
"]",
",",
"$",
"map",
")",
")",
";",
"foreach",
"(",
"[",
"'string'",
",",
"'text'",
"]",
"as",
"$",
"t",
")",
"{",
"if",
"(",
"get_class",
"(",
"$",
"typeMap",
"[",
"$",
"t",
"]",
")",
"===",
"'Cake\\Database\\Type'",
")",
"{",
"unset",
"(",
"$",
"typeMap",
"[",
"$",
"t",
"]",
")",
";",
"}",
"}",
"foreach",
"(",
"array_intersect",
"(",
"$",
"fields",
",",
"$",
"schema",
"->",
"columns",
"(",
")",
")",
"as",
"$",
"col",
")",
"{",
"$",
"typeName",
"=",
"$",
"schema",
"->",
"getColumnType",
"(",
"$",
"col",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"typeMap",
"[",
"$",
"typeName",
"]",
")",
")",
"{",
"$",
"types",
"[",
"$",
"col",
"]",
"=",
"$",
"typeMap",
"[",
"$",
"typeName",
"]",
";",
"}",
"}",
"return",
"$",
"types",
";",
"}"
] | Returns the Type classes for each of the passed fields belonging to the
table.
@param \Cake\ORM\Table $table The table from which to get the schema
@param array $fields The fields whitelist to use for fields in the schema.
@return array | [
"Returns",
"the",
"Type",
"classes",
"for",
"each",
"of",
"the",
"passed",
"fields",
"belonging",
"to",
"the",
"table",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/ResultSet.php#L447-L471 |
211,763 | cakephp/cakephp | src/ORM/ResultSet.php | ResultSet._fetchResult | protected function _fetchResult()
{
if (!$this->_statement) {
return false;
}
$row = $this->_statement->fetch('assoc');
if ($row === false) {
return $row;
}
return $this->_groupResult($row);
} | php | protected function _fetchResult()
{
if (!$this->_statement) {
return false;
}
$row = $this->_statement->fetch('assoc');
if ($row === false) {
return $row;
}
return $this->_groupResult($row);
} | [
"protected",
"function",
"_fetchResult",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_statement",
")",
"{",
"return",
"false",
";",
"}",
"$",
"row",
"=",
"$",
"this",
"->",
"_statement",
"->",
"fetch",
"(",
"'assoc'",
")",
";",
"if",
"(",
"$",
"row",
"===",
"false",
")",
"{",
"return",
"$",
"row",
";",
"}",
"return",
"$",
"this",
"->",
"_groupResult",
"(",
"$",
"row",
")",
";",
"}"
] | Helper function to fetch the next result from the statement or
seeded results.
@return mixed | [
"Helper",
"function",
"to",
"fetch",
"the",
"next",
"result",
"from",
"the",
"statement",
"or",
"seeded",
"results",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/ResultSet.php#L479-L491 |
211,764 | cakephp/cakephp | src/Database/TypedResultTrait.php | TypedResultTrait.returnType | public function returnType($type = null)
{
deprecationWarning(
'TypedResultTrait::returnType() is deprecated. ' .
'Use TypedResultTrait::setReturnType()/getReturnType() instead.'
);
if ($type !== null) {
$this->_returnType = $type;
return $this;
}
return $this->_returnType;
} | php | public function returnType($type = null)
{
deprecationWarning(
'TypedResultTrait::returnType() is deprecated. ' .
'Use TypedResultTrait::setReturnType()/getReturnType() instead.'
);
if ($type !== null) {
$this->_returnType = $type;
return $this;
}
return $this->_returnType;
} | [
"public",
"function",
"returnType",
"(",
"$",
"type",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"'TypedResultTrait::returnType() is deprecated. '",
".",
"'Use TypedResultTrait::setReturnType()/getReturnType() instead.'",
")",
";",
"if",
"(",
"$",
"type",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"_returnType",
"=",
"$",
"type",
";",
"return",
"$",
"this",
";",
"}",
"return",
"$",
"this",
"->",
"_returnType",
";",
"}"
] | Sets the type of the value this object will generate.
If called without arguments, returns the current known type
@deprecated 3.5.0 Use getReturnType()/setReturnType() instead.
@param string|null $type The name of the type that is to be returned
@return string|$this | [
"Sets",
"the",
"type",
"of",
"the",
"value",
"this",
"object",
"will",
"generate",
".",
"If",
"called",
"without",
"arguments",
"returns",
"the",
"current",
"known",
"type"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/TypedResultTrait.php#L61-L74 |
211,765 | cakephp/cakephp | src/View/JsonView.php | JsonView.render | public function render($view = null, $layout = null)
{
$return = parent::render($view, $layout);
if (!empty($this->viewVars['_jsonp'])) {
$jsonpParam = $this->viewVars['_jsonp'];
if ($this->viewVars['_jsonp'] === true) {
$jsonpParam = 'callback';
}
if ($this->request->getQuery($jsonpParam)) {
$return = sprintf('%s(%s)', h($this->request->getQuery($jsonpParam)), $return);
$this->response = $this->response->withType('js');
}
}
return $return;
} | php | public function render($view = null, $layout = null)
{
$return = parent::render($view, $layout);
if (!empty($this->viewVars['_jsonp'])) {
$jsonpParam = $this->viewVars['_jsonp'];
if ($this->viewVars['_jsonp'] === true) {
$jsonpParam = 'callback';
}
if ($this->request->getQuery($jsonpParam)) {
$return = sprintf('%s(%s)', h($this->request->getQuery($jsonpParam)), $return);
$this->response = $this->response->withType('js');
}
}
return $return;
} | [
"public",
"function",
"render",
"(",
"$",
"view",
"=",
"null",
",",
"$",
"layout",
"=",
"null",
")",
"{",
"$",
"return",
"=",
"parent",
"::",
"render",
"(",
"$",
"view",
",",
"$",
"layout",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"viewVars",
"[",
"'_jsonp'",
"]",
")",
")",
"{",
"$",
"jsonpParam",
"=",
"$",
"this",
"->",
"viewVars",
"[",
"'_jsonp'",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"viewVars",
"[",
"'_jsonp'",
"]",
"===",
"true",
")",
"{",
"$",
"jsonpParam",
"=",
"'callback'",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"request",
"->",
"getQuery",
"(",
"$",
"jsonpParam",
")",
")",
"{",
"$",
"return",
"=",
"sprintf",
"(",
"'%s(%s)'",
",",
"h",
"(",
"$",
"this",
"->",
"request",
"->",
"getQuery",
"(",
"$",
"jsonpParam",
")",
")",
",",
"$",
"return",
")",
";",
"$",
"this",
"->",
"response",
"=",
"$",
"this",
"->",
"response",
"->",
"withType",
"(",
"'js'",
")",
";",
"}",
"}",
"return",
"$",
"return",
";",
"}"
] | Render a JSON view.
### Special parameters
`_serialize` To convert a set of view variables into a JSON response.
Its value can be a string for single variable name or array for multiple
names. If true all view variables will be serialized. It unset normal
view template will be rendered.
`_jsonp` Enables JSONP support and wraps response in callback function
provided in query string.
- Setting it to true enables the default query string parameter "callback".
- Setting it to a string value, uses the provided query string parameter
for finding the JSONP callback name.
@param string|null $view The view being rendered.
@param string|null $layout The layout being rendered.
@return string|null The rendered view. | [
"Render",
"a",
"JSON",
"view",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/JsonView.php#L105-L121 |
211,766 | cakephp/cakephp | src/View/JsonView.php | JsonView._serialize | protected function _serialize($serialize)
{
$data = $this->_dataToSerialize($serialize);
$jsonOptions = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT |
JSON_PARTIAL_OUTPUT_ON_ERROR;
if (isset($this->viewVars['_jsonOptions'])) {
if ($this->viewVars['_jsonOptions'] === false) {
$jsonOptions = 0;
} else {
$jsonOptions = $this->viewVars['_jsonOptions'];
}
}
if (Configure::read('debug')) {
$jsonOptions |= JSON_PRETTY_PRINT;
}
return json_encode($data, $jsonOptions);
} | php | protected function _serialize($serialize)
{
$data = $this->_dataToSerialize($serialize);
$jsonOptions = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT |
JSON_PARTIAL_OUTPUT_ON_ERROR;
if (isset($this->viewVars['_jsonOptions'])) {
if ($this->viewVars['_jsonOptions'] === false) {
$jsonOptions = 0;
} else {
$jsonOptions = $this->viewVars['_jsonOptions'];
}
}
if (Configure::read('debug')) {
$jsonOptions |= JSON_PRETTY_PRINT;
}
return json_encode($data, $jsonOptions);
} | [
"protected",
"function",
"_serialize",
"(",
"$",
"serialize",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"_dataToSerialize",
"(",
"$",
"serialize",
")",
";",
"$",
"jsonOptions",
"=",
"JSON_HEX_TAG",
"|",
"JSON_HEX_APOS",
"|",
"JSON_HEX_AMP",
"|",
"JSON_HEX_QUOT",
"|",
"JSON_PARTIAL_OUTPUT_ON_ERROR",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"viewVars",
"[",
"'_jsonOptions'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"viewVars",
"[",
"'_jsonOptions'",
"]",
"===",
"false",
")",
"{",
"$",
"jsonOptions",
"=",
"0",
";",
"}",
"else",
"{",
"$",
"jsonOptions",
"=",
"$",
"this",
"->",
"viewVars",
"[",
"'_jsonOptions'",
"]",
";",
"}",
"}",
"if",
"(",
"Configure",
"::",
"read",
"(",
"'debug'",
")",
")",
"{",
"$",
"jsonOptions",
"|=",
"JSON_PRETTY_PRINT",
";",
"}",
"return",
"json_encode",
"(",
"$",
"data",
",",
"$",
"jsonOptions",
")",
";",
"}"
] | Serialize view vars
### Special parameters
`_jsonOptions` You can set custom options for json_encode() this way,
e.g. `JSON_HEX_TAG | JSON_HEX_APOS`.
@param array|string|bool $serialize The name(s) of the view variable(s)
that need(s) to be serialized. If true all available view variables.
@return string|false The serialized data, or boolean false if not serializable. | [
"Serialize",
"view",
"vars"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/JsonView.php#L134-L154 |
211,767 | cakephp/cakephp | src/Database/FunctionsBuilder.php | FunctionsBuilder._literalArgumentFunction | protected function _literalArgumentFunction($name, $expression, $types = [], $return = 'string')
{
if (!is_string($expression)) {
$expression = [$expression];
} else {
$expression = [$expression => 'literal'];
}
return $this->_build($name, $expression, $types, $return);
} | php | protected function _literalArgumentFunction($name, $expression, $types = [], $return = 'string')
{
if (!is_string($expression)) {
$expression = [$expression];
} else {
$expression = [$expression => 'literal'];
}
return $this->_build($name, $expression, $types, $return);
} | [
"protected",
"function",
"_literalArgumentFunction",
"(",
"$",
"name",
",",
"$",
"expression",
",",
"$",
"types",
"=",
"[",
"]",
",",
"$",
"return",
"=",
"'string'",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"expression",
")",
")",
"{",
"$",
"expression",
"=",
"[",
"$",
"expression",
"]",
";",
"}",
"else",
"{",
"$",
"expression",
"=",
"[",
"$",
"expression",
"=>",
"'literal'",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"_build",
"(",
"$",
"name",
",",
"$",
"expression",
",",
"$",
"types",
",",
"$",
"return",
")",
";",
"}"
] | Helper function to build a function expression that only takes one literal
argument.
@param string $name name of the function to build
@param mixed $expression the function argument
@param array $types list of types to bind to the arguments
@param string $return The return type for the function
@return \Cake\Database\Expression\FunctionExpression | [
"Helper",
"function",
"to",
"build",
"a",
"function",
"expression",
"that",
"only",
"takes",
"one",
"literal",
"argument",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/FunctionsBuilder.php#L52-L61 |
211,768 | cakephp/cakephp | src/Database/FunctionsBuilder.php | FunctionsBuilder.sum | public function sum($expression, $types = [])
{
$returnType = 'float';
if (current($types) === 'integer') {
$returnType = 'integer';
}
return $this->_literalArgumentFunction('SUM', $expression, $types, $returnType);
} | php | public function sum($expression, $types = [])
{
$returnType = 'float';
if (current($types) === 'integer') {
$returnType = 'integer';
}
return $this->_literalArgumentFunction('SUM', $expression, $types, $returnType);
} | [
"public",
"function",
"sum",
"(",
"$",
"expression",
",",
"$",
"types",
"=",
"[",
"]",
")",
"{",
"$",
"returnType",
"=",
"'float'",
";",
"if",
"(",
"current",
"(",
"$",
"types",
")",
"===",
"'integer'",
")",
"{",
"$",
"returnType",
"=",
"'integer'",
";",
"}",
"return",
"$",
"this",
"->",
"_literalArgumentFunction",
"(",
"'SUM'",
",",
"$",
"expression",
",",
"$",
"types",
",",
"$",
"returnType",
")",
";",
"}"
] | Returns a FunctionExpression representing a call to SQL SUM function.
@param mixed $expression the function argument
@param array $types list of types to bind to the arguments
@return \Cake\Database\Expression\FunctionExpression | [
"Returns",
"a",
"FunctionExpression",
"representing",
"a",
"call",
"to",
"SQL",
"SUM",
"function",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/FunctionsBuilder.php#L80-L88 |
211,769 | cakephp/cakephp | src/Database/FunctionsBuilder.php | FunctionsBuilder.extract | public function extract($part, $expression, $types = [])
{
$expression = $this->_literalArgumentFunction('EXTRACT', $expression, $types, 'integer');
$expression->setConjunction(' FROM')->add([$part => 'literal'], [], true);
return $expression;
} | php | public function extract($part, $expression, $types = [])
{
$expression = $this->_literalArgumentFunction('EXTRACT', $expression, $types, 'integer');
$expression->setConjunction(' FROM')->add([$part => 'literal'], [], true);
return $expression;
} | [
"public",
"function",
"extract",
"(",
"$",
"part",
",",
"$",
"expression",
",",
"$",
"types",
"=",
"[",
"]",
")",
"{",
"$",
"expression",
"=",
"$",
"this",
"->",
"_literalArgumentFunction",
"(",
"'EXTRACT'",
",",
"$",
"expression",
",",
"$",
"types",
",",
"'integer'",
")",
";",
"$",
"expression",
"->",
"setConjunction",
"(",
"' FROM'",
")",
"->",
"add",
"(",
"[",
"$",
"part",
"=>",
"'literal'",
"]",
",",
"[",
"]",
",",
"true",
")",
";",
"return",
"$",
"expression",
";",
"}"
] | Returns the specified date part from the SQL expression.
@param string $part Part of the date to return.
@param string $expression Expression to obtain the date part from.
@param array $types list of types to bind to the arguments
@return \Cake\Database\Expression\FunctionExpression | [
"Returns",
"the",
"specified",
"date",
"part",
"from",
"the",
"SQL",
"expression",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/FunctionsBuilder.php#L196-L202 |
211,770 | cakephp/cakephp | src/Database/FunctionsBuilder.php | FunctionsBuilder.dateAdd | public function dateAdd($expression, $value, $unit, $types = [])
{
if (!is_numeric($value)) {
$value = 0;
}
$interval = $value . ' ' . $unit;
$expression = $this->_literalArgumentFunction('DATE_ADD', $expression, $types, 'datetime');
$expression->setConjunction(', INTERVAL')->add([$interval => 'literal']);
return $expression;
} | php | public function dateAdd($expression, $value, $unit, $types = [])
{
if (!is_numeric($value)) {
$value = 0;
}
$interval = $value . ' ' . $unit;
$expression = $this->_literalArgumentFunction('DATE_ADD', $expression, $types, 'datetime');
$expression->setConjunction(', INTERVAL')->add([$interval => 'literal']);
return $expression;
} | [
"public",
"function",
"dateAdd",
"(",
"$",
"expression",
",",
"$",
"value",
",",
"$",
"unit",
",",
"$",
"types",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"0",
";",
"}",
"$",
"interval",
"=",
"$",
"value",
".",
"' '",
".",
"$",
"unit",
";",
"$",
"expression",
"=",
"$",
"this",
"->",
"_literalArgumentFunction",
"(",
"'DATE_ADD'",
",",
"$",
"expression",
",",
"$",
"types",
",",
"'datetime'",
")",
";",
"$",
"expression",
"->",
"setConjunction",
"(",
"', INTERVAL'",
")",
"->",
"add",
"(",
"[",
"$",
"interval",
"=>",
"'literal'",
"]",
")",
";",
"return",
"$",
"expression",
";",
"}"
] | Add the time unit to the date expression
@param string $expression Expression to obtain the date part from.
@param string $value Value to be added. Use negative to subtract.
@param string $unit Unit of the value e.g. hour or day.
@param array $types list of types to bind to the arguments
@return \Cake\Database\Expression\FunctionExpression | [
"Add",
"the",
"time",
"unit",
"to",
"the",
"date",
"expression"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/FunctionsBuilder.php#L213-L223 |
211,771 | cakephp/cakephp | src/Database/FunctionsBuilder.php | FunctionsBuilder.now | public function now($type = 'datetime')
{
if ($type === 'datetime') {
return $this->_build('NOW')->setReturnType('datetime');
}
if ($type === 'date') {
return $this->_build('CURRENT_DATE')->setReturnType('date');
}
if ($type === 'time') {
return $this->_build('CURRENT_TIME')->setReturnType('time');
}
} | php | public function now($type = 'datetime')
{
if ($type === 'datetime') {
return $this->_build('NOW')->setReturnType('datetime');
}
if ($type === 'date') {
return $this->_build('CURRENT_DATE')->setReturnType('date');
}
if ($type === 'time') {
return $this->_build('CURRENT_TIME')->setReturnType('time');
}
} | [
"public",
"function",
"now",
"(",
"$",
"type",
"=",
"'datetime'",
")",
"{",
"if",
"(",
"$",
"type",
"===",
"'datetime'",
")",
"{",
"return",
"$",
"this",
"->",
"_build",
"(",
"'NOW'",
")",
"->",
"setReturnType",
"(",
"'datetime'",
")",
";",
"}",
"if",
"(",
"$",
"type",
"===",
"'date'",
")",
"{",
"return",
"$",
"this",
"->",
"_build",
"(",
"'CURRENT_DATE'",
")",
"->",
"setReturnType",
"(",
"'date'",
")",
";",
"}",
"if",
"(",
"$",
"type",
"===",
"'time'",
")",
"{",
"return",
"$",
"this",
"->",
"_build",
"(",
"'CURRENT_TIME'",
")",
"->",
"setReturnType",
"(",
"'time'",
")",
";",
"}",
"}"
] | Returns a FunctionExpression representing a call that will return the current
date and time. By default it returns both date and time, but you can also
make it generate only the date or only the time.
@param string $type (datetime|date|time)
@return \Cake\Database\Expression\FunctionExpression | [
"Returns",
"a",
"FunctionExpression",
"representing",
"a",
"call",
"that",
"will",
"return",
"the",
"current",
"date",
"and",
"time",
".",
"By",
"default",
"it",
"returns",
"both",
"date",
"and",
"time",
"but",
"you",
"can",
"also",
"make",
"it",
"generate",
"only",
"the",
"date",
"or",
"only",
"the",
"time",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/FunctionsBuilder.php#L259-L270 |
211,772 | cakephp/cakephp | src/Routing/Filter/ControllerFactoryFilter.php | ControllerFactoryFilter.beforeDispatch | public function beforeDispatch(Event $event)
{
$request = $event->getData('request');
$response = $event->getData('response');
$event->setData('controller', $this->_getController($request, $response));
} | php | public function beforeDispatch(Event $event)
{
$request = $event->getData('request');
$response = $event->getData('response');
$event->setData('controller', $this->_getController($request, $response));
} | [
"public",
"function",
"beforeDispatch",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"request",
"=",
"$",
"event",
"->",
"getData",
"(",
"'request'",
")",
";",
"$",
"response",
"=",
"$",
"event",
"->",
"getData",
"(",
"'response'",
")",
";",
"$",
"event",
"->",
"setData",
"(",
"'controller'",
",",
"$",
"this",
"->",
"_getController",
"(",
"$",
"request",
",",
"$",
"response",
")",
")",
";",
"}"
] | Resolve the request parameters into a controller and attach the controller
to the event object.
@param \Cake\Event\Event $event The event instance.
@return void | [
"Resolve",
"the",
"request",
"parameters",
"into",
"a",
"controller",
"and",
"attach",
"the",
"controller",
"to",
"the",
"event",
"object",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Filter/ControllerFactoryFilter.php#L45-L50 |
211,773 | cakephp/cakephp | src/Http/Client/Request.php | Request.addHeaders | protected function addHeaders(array $headers)
{
foreach ($headers as $key => $val) {
$normalized = strtolower($key);
$this->headers[$key] = (array)$val;
$this->headerNames[$normalized] = $key;
}
} | php | protected function addHeaders(array $headers)
{
foreach ($headers as $key => $val) {
$normalized = strtolower($key);
$this->headers[$key] = (array)$val;
$this->headerNames[$normalized] = $key;
}
} | [
"protected",
"function",
"addHeaders",
"(",
"array",
"$",
"headers",
")",
"{",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"normalized",
"=",
"strtolower",
"(",
"$",
"key",
")",
";",
"$",
"this",
"->",
"headers",
"[",
"$",
"key",
"]",
"=",
"(",
"array",
")",
"$",
"val",
";",
"$",
"this",
"->",
"headerNames",
"[",
"$",
"normalized",
"]",
"=",
"$",
"key",
";",
"}",
"}"
] | Add an array of headers to the request.
@param array $headers The headers to add.
@return void | [
"Add",
"an",
"array",
"of",
"headers",
"to",
"the",
"request",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Request.php#L171-L178 |
211,774 | cakephp/cakephp | src/ORM/RulesChecker.php | RulesChecker.isUnique | public function isUnique(array $fields, $message = null)
{
$options = [];
if (is_array($message)) {
$options = $message + ['message' => null];
$message = $options['message'];
unset($options['message']);
}
if (!$message) {
if ($this->_useI18n) {
$message = __d('cake', 'This value is already in use');
} else {
$message = 'This value is already in use';
}
}
$errorField = current($fields);
return $this->_addError(new IsUnique($fields, $options), '_isUnique', compact('errorField', 'message'));
} | php | public function isUnique(array $fields, $message = null)
{
$options = [];
if (is_array($message)) {
$options = $message + ['message' => null];
$message = $options['message'];
unset($options['message']);
}
if (!$message) {
if ($this->_useI18n) {
$message = __d('cake', 'This value is already in use');
} else {
$message = 'This value is already in use';
}
}
$errorField = current($fields);
return $this->_addError(new IsUnique($fields, $options), '_isUnique', compact('errorField', 'message'));
} | [
"public",
"function",
"isUnique",
"(",
"array",
"$",
"fields",
",",
"$",
"message",
"=",
"null",
")",
"{",
"$",
"options",
"=",
"[",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"message",
")",
")",
"{",
"$",
"options",
"=",
"$",
"message",
"+",
"[",
"'message'",
"=>",
"null",
"]",
";",
"$",
"message",
"=",
"$",
"options",
"[",
"'message'",
"]",
";",
"unset",
"(",
"$",
"options",
"[",
"'message'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"$",
"message",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_useI18n",
")",
"{",
"$",
"message",
"=",
"__d",
"(",
"'cake'",
",",
"'This value is already in use'",
")",
";",
"}",
"else",
"{",
"$",
"message",
"=",
"'This value is already in use'",
";",
"}",
"}",
"$",
"errorField",
"=",
"current",
"(",
"$",
"fields",
")",
";",
"return",
"$",
"this",
"->",
"_addError",
"(",
"new",
"IsUnique",
"(",
"$",
"fields",
",",
"$",
"options",
")",
",",
"'_isUnique'",
",",
"compact",
"(",
"'errorField'",
",",
"'message'",
")",
")",
";",
"}"
] | Returns a callable that can be used as a rule for checking the uniqueness of a value
in the table.
### Example:
```
$rules->add($rules->isUnique(['email'], 'The email should be unique'));
```
@param array $fields The list of fields to check for uniqueness.
@param string|array|null $message The error message to show in case the rule does not pass. Can
also be an array of options. When an array, the 'message' key can be used to provide a message.
@return callable | [
"Returns",
"a",
"callable",
"that",
"can",
"be",
"used",
"as",
"a",
"rule",
"for",
"checking",
"the",
"uniqueness",
"of",
"a",
"value",
"in",
"the",
"table",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/RulesChecker.php#L47-L66 |
211,775 | cakephp/cakephp | src/ORM/RulesChecker.php | RulesChecker.existsIn | public function existsIn($field, $table, $message = null)
{
$options = [];
if (is_array($message)) {
$options = $message + ['message' => null];
$message = $options['message'];
unset($options['message']);
}
if (!$message) {
if ($this->_useI18n) {
$message = __d('cake', 'This value does not exist');
} else {
$message = 'This value does not exist';
}
}
$errorField = is_string($field) ? $field : current($field);
return $this->_addError(new ExistsIn($field, $table, $options), '_existsIn', compact('errorField', 'message'));
} | php | public function existsIn($field, $table, $message = null)
{
$options = [];
if (is_array($message)) {
$options = $message + ['message' => null];
$message = $options['message'];
unset($options['message']);
}
if (!$message) {
if ($this->_useI18n) {
$message = __d('cake', 'This value does not exist');
} else {
$message = 'This value does not exist';
}
}
$errorField = is_string($field) ? $field : current($field);
return $this->_addError(new ExistsIn($field, $table, $options), '_existsIn', compact('errorField', 'message'));
} | [
"public",
"function",
"existsIn",
"(",
"$",
"field",
",",
"$",
"table",
",",
"$",
"message",
"=",
"null",
")",
"{",
"$",
"options",
"=",
"[",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"message",
")",
")",
"{",
"$",
"options",
"=",
"$",
"message",
"+",
"[",
"'message'",
"=>",
"null",
"]",
";",
"$",
"message",
"=",
"$",
"options",
"[",
"'message'",
"]",
";",
"unset",
"(",
"$",
"options",
"[",
"'message'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"$",
"message",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_useI18n",
")",
"{",
"$",
"message",
"=",
"__d",
"(",
"'cake'",
",",
"'This value does not exist'",
")",
";",
"}",
"else",
"{",
"$",
"message",
"=",
"'This value does not exist'",
";",
"}",
"}",
"$",
"errorField",
"=",
"is_string",
"(",
"$",
"field",
")",
"?",
"$",
"field",
":",
"current",
"(",
"$",
"field",
")",
";",
"return",
"$",
"this",
"->",
"_addError",
"(",
"new",
"ExistsIn",
"(",
"$",
"field",
",",
"$",
"table",
",",
"$",
"options",
")",
",",
"'_existsIn'",
",",
"compact",
"(",
"'errorField'",
",",
"'message'",
")",
")",
";",
"}"
] | Returns a callable that can be used as a rule for checking that the values
extracted from the entity to check exist as the primary key in another table.
This is useful for enforcing foreign key integrity checks.
### Example:
```
$rules->add($rules->existsIn('author_id', 'Authors', 'Invalid Author'));
$rules->add($rules->existsIn('site_id', new SitesTable(), 'Invalid Site'));
```
Available $options are error 'message' and 'allowNullableNulls' flag.
'message' sets a custom error message.
Set 'allowNullableNulls' to true to accept composite foreign keys where one or more nullable columns are null.
@param string|array $field The field or list of fields to check for existence by
primary key lookup in the other table.
@param object|string $table The table name where the fields existence will be checked.
@param string|array|null $message The error message to show in case the rule does not pass. Can
also be an array of options. When an array, the 'message' key can be used to provide a message.
@return callable | [
"Returns",
"a",
"callable",
"that",
"can",
"be",
"used",
"as",
"a",
"rule",
"for",
"checking",
"that",
"the",
"values",
"extracted",
"from",
"the",
"entity",
"to",
"check",
"exist",
"as",
"the",
"primary",
"key",
"in",
"another",
"table",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/RulesChecker.php#L93-L113 |
211,776 | cakephp/cakephp | src/ORM/RulesChecker.php | RulesChecker.validCount | public function validCount($field, $count = 0, $operator = '>', $message = null)
{
if (!$message) {
if ($this->_useI18n) {
$message = __d('cake', 'The count does not match {0}{1}', [$operator, $count]);
} else {
$message = sprintf('The count does not match %s%d', $operator, $count);
}
}
$errorField = $field;
return $this->_addError(
new ValidCount($field),
'_validCount',
compact('count', 'operator', 'errorField', 'message')
);
} | php | public function validCount($field, $count = 0, $operator = '>', $message = null)
{
if (!$message) {
if ($this->_useI18n) {
$message = __d('cake', 'The count does not match {0}{1}', [$operator, $count]);
} else {
$message = sprintf('The count does not match %s%d', $operator, $count);
}
}
$errorField = $field;
return $this->_addError(
new ValidCount($field),
'_validCount',
compact('count', 'operator', 'errorField', 'message')
);
} | [
"public",
"function",
"validCount",
"(",
"$",
"field",
",",
"$",
"count",
"=",
"0",
",",
"$",
"operator",
"=",
"'>'",
",",
"$",
"message",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"message",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_useI18n",
")",
"{",
"$",
"message",
"=",
"__d",
"(",
"'cake'",
",",
"'The count does not match {0}{1}'",
",",
"[",
"$",
"operator",
",",
"$",
"count",
"]",
")",
";",
"}",
"else",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'The count does not match %s%d'",
",",
"$",
"operator",
",",
"$",
"count",
")",
";",
"}",
"}",
"$",
"errorField",
"=",
"$",
"field",
";",
"return",
"$",
"this",
"->",
"_addError",
"(",
"new",
"ValidCount",
"(",
"$",
"field",
")",
",",
"'_validCount'",
",",
"compact",
"(",
"'count'",
",",
"'operator'",
",",
"'errorField'",
",",
"'message'",
")",
")",
";",
"}"
] | Validates the count of associated records.
@param string $field The field to check the count on.
@param int $count The expected count.
@param string $operator The operator for the count comparison.
@param string|null $message The error message to show in case the rule does not pass.
@return callable | [
"Validates",
"the",
"count",
"of",
"associated",
"records",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/RulesChecker.php#L124-L141 |
211,777 | cakephp/cakephp | src/ORM/EagerLoadable.php | EagerLoadable.canBeJoined | public function canBeJoined($possible = null)
{
if ($possible !== null) {
deprecationWarning(
'Using EagerLoadable::canBeJoined() as a setter is deprecated. ' .
'Use setCanBeJoined() instead.'
);
$this->setCanBeJoined($possible);
}
return $this->_canBeJoined;
} | php | public function canBeJoined($possible = null)
{
if ($possible !== null) {
deprecationWarning(
'Using EagerLoadable::canBeJoined() as a setter is deprecated. ' .
'Use setCanBeJoined() instead.'
);
$this->setCanBeJoined($possible);
}
return $this->_canBeJoined;
} | [
"public",
"function",
"canBeJoined",
"(",
"$",
"possible",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"possible",
"!==",
"null",
")",
"{",
"deprecationWarning",
"(",
"'Using EagerLoadable::canBeJoined() as a setter is deprecated. '",
".",
"'Use setCanBeJoined() instead.'",
")",
";",
"$",
"this",
"->",
"setCanBeJoined",
"(",
"$",
"possible",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_canBeJoined",
";",
"}"
] | Gets whether or not this level can be fetched using a join.
If called with arguments it sets the value.
As of 3.4.0 the setter part is deprecated, use setCanBeJoined() instead.
@param bool|null $possible The value to set.
@return bool | [
"Gets",
"whether",
"or",
"not",
"this",
"level",
"can",
"be",
"fetched",
"using",
"a",
"join",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/EagerLoadable.php#L228-L239 |
211,778 | cakephp/cakephp | src/ORM/EagerLoadable.php | EagerLoadable.config | public function config(array $config = null)
{
deprecationWarning(
'EagerLoadable::config() is deprecated. ' .
'Use setConfig()/getConfig() instead.'
);
if ($config !== null) {
$this->setConfig($config);
}
return $this->getConfig();
} | php | public function config(array $config = null)
{
deprecationWarning(
'EagerLoadable::config() is deprecated. ' .
'Use setConfig()/getConfig() instead.'
);
if ($config !== null) {
$this->setConfig($config);
}
return $this->getConfig();
} | [
"public",
"function",
"config",
"(",
"array",
"$",
"config",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"'EagerLoadable::config() is deprecated. '",
".",
"'Use setConfig()/getConfig() instead.'",
")",
";",
"if",
"(",
"$",
"config",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"setConfig",
"(",
"$",
"config",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getConfig",
"(",
")",
";",
"}"
] | Sets the list of options to pass to the association object for loading
the records.
If called with no arguments it returns the current
value.
@deprecated 3.4.0 Use setConfig()/getConfig() instead.
@param array|null $config The value to set.
@return array | [
"Sets",
"the",
"list",
"of",
"options",
"to",
"pass",
"to",
"the",
"association",
"object",
"for",
"loading",
"the",
"records",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/EagerLoadable.php#L277-L288 |
211,779 | cakephp/cakephp | src/Database/Expression/CaseExpression.php | CaseExpression.add | public function add($conditions = [], $values = [], $types = [])
{
if (!is_array($conditions)) {
$conditions = [$conditions];
}
if (!is_array($values)) {
$values = [$values];
}
if (!is_array($types)) {
$types = [$types];
}
$this->_addExpressions($conditions, $values, $types);
return $this;
} | php | public function add($conditions = [], $values = [], $types = [])
{
if (!is_array($conditions)) {
$conditions = [$conditions];
}
if (!is_array($values)) {
$values = [$values];
}
if (!is_array($types)) {
$types = [$types];
}
$this->_addExpressions($conditions, $values, $types);
return $this;
} | [
"public",
"function",
"add",
"(",
"$",
"conditions",
"=",
"[",
"]",
",",
"$",
"values",
"=",
"[",
"]",
",",
"$",
"types",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"conditions",
")",
")",
"{",
"$",
"conditions",
"=",
"[",
"$",
"conditions",
"]",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"values",
")",
")",
"{",
"$",
"values",
"=",
"[",
"$",
"values",
"]",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"types",
")",
")",
"{",
"$",
"types",
"=",
"[",
"$",
"types",
"]",
";",
"}",
"$",
"this",
"->",
"_addExpressions",
"(",
"$",
"conditions",
",",
"$",
"values",
",",
"$",
"types",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Adds one or more conditions and their respective true values to the case object.
Conditions must be a one dimensional array or a QueryExpression.
The trueValues must be a similar structure, but may contain a string value.
@param array|\Cake\Database\ExpressionInterface $conditions Must be a ExpressionInterface instance, or an array of ExpressionInterface instances.
@param array|\Cake\Database\ExpressionInterface $values associative array of values of each condition
@param array $types associative array of types to be associated with the values
@return $this | [
"Adds",
"one",
"or",
"more",
"conditions",
"and",
"their",
"respective",
"true",
"values",
"to",
"the",
"case",
"object",
".",
"Conditions",
"must",
"be",
"a",
"one",
"dimensional",
"array",
"or",
"a",
"QueryExpression",
".",
"The",
"trueValues",
"must",
"be",
"a",
"similar",
"structure",
"but",
"may",
"contain",
"a",
"string",
"value",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/CaseExpression.php#L86-L101 |
211,780 | cakephp/cakephp | src/Database/Expression/CaseExpression.php | CaseExpression._addExpressions | protected function _addExpressions($conditions, $values, $types)
{
$rawValues = array_values($values);
$keyValues = array_keys($values);
foreach ($conditions as $k => $c) {
$numericKey = is_numeric($k);
if ($numericKey && empty($c)) {
continue;
}
if (!$c instanceof ExpressionInterface) {
continue;
}
$this->_conditions[] = $c;
$value = isset($rawValues[$k]) ? $rawValues[$k] : 1;
if ($value === 'literal') {
$value = $keyValues[$k];
$this->_values[] = $value;
continue;
}
if ($value === 'identifier') {
$value = new IdentifierExpression($keyValues[$k]);
$this->_values[] = $value;
continue;
}
$type = isset($types[$k]) ? $types[$k] : null;
if ($type !== null && !$value instanceof ExpressionInterface) {
$value = $this->_castToExpression($value, $type);
}
if ($value instanceof ExpressionInterface) {
$this->_values[] = $value;
continue;
}
$this->_values[] = ['value' => $value, 'type' => $type];
}
} | php | protected function _addExpressions($conditions, $values, $types)
{
$rawValues = array_values($values);
$keyValues = array_keys($values);
foreach ($conditions as $k => $c) {
$numericKey = is_numeric($k);
if ($numericKey && empty($c)) {
continue;
}
if (!$c instanceof ExpressionInterface) {
continue;
}
$this->_conditions[] = $c;
$value = isset($rawValues[$k]) ? $rawValues[$k] : 1;
if ($value === 'literal') {
$value = $keyValues[$k];
$this->_values[] = $value;
continue;
}
if ($value === 'identifier') {
$value = new IdentifierExpression($keyValues[$k]);
$this->_values[] = $value;
continue;
}
$type = isset($types[$k]) ? $types[$k] : null;
if ($type !== null && !$value instanceof ExpressionInterface) {
$value = $this->_castToExpression($value, $type);
}
if ($value instanceof ExpressionInterface) {
$this->_values[] = $value;
continue;
}
$this->_values[] = ['value' => $value, 'type' => $type];
}
} | [
"protected",
"function",
"_addExpressions",
"(",
"$",
"conditions",
",",
"$",
"values",
",",
"$",
"types",
")",
"{",
"$",
"rawValues",
"=",
"array_values",
"(",
"$",
"values",
")",
";",
"$",
"keyValues",
"=",
"array_keys",
"(",
"$",
"values",
")",
";",
"foreach",
"(",
"$",
"conditions",
"as",
"$",
"k",
"=>",
"$",
"c",
")",
"{",
"$",
"numericKey",
"=",
"is_numeric",
"(",
"$",
"k",
")",
";",
"if",
"(",
"$",
"numericKey",
"&&",
"empty",
"(",
"$",
"c",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"$",
"c",
"instanceof",
"ExpressionInterface",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"_conditions",
"[",
"]",
"=",
"$",
"c",
";",
"$",
"value",
"=",
"isset",
"(",
"$",
"rawValues",
"[",
"$",
"k",
"]",
")",
"?",
"$",
"rawValues",
"[",
"$",
"k",
"]",
":",
"1",
";",
"if",
"(",
"$",
"value",
"===",
"'literal'",
")",
"{",
"$",
"value",
"=",
"$",
"keyValues",
"[",
"$",
"k",
"]",
";",
"$",
"this",
"->",
"_values",
"[",
"]",
"=",
"$",
"value",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"value",
"===",
"'identifier'",
")",
"{",
"$",
"value",
"=",
"new",
"IdentifierExpression",
"(",
"$",
"keyValues",
"[",
"$",
"k",
"]",
")",
";",
"$",
"this",
"->",
"_values",
"[",
"]",
"=",
"$",
"value",
";",
"continue",
";",
"}",
"$",
"type",
"=",
"isset",
"(",
"$",
"types",
"[",
"$",
"k",
"]",
")",
"?",
"$",
"types",
"[",
"$",
"k",
"]",
":",
"null",
";",
"if",
"(",
"$",
"type",
"!==",
"null",
"&&",
"!",
"$",
"value",
"instanceof",
"ExpressionInterface",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"_castToExpression",
"(",
"$",
"value",
",",
"$",
"type",
")",
";",
"}",
"if",
"(",
"$",
"value",
"instanceof",
"ExpressionInterface",
")",
"{",
"$",
"this",
"->",
"_values",
"[",
"]",
"=",
"$",
"value",
";",
"continue",
";",
"}",
"$",
"this",
"->",
"_values",
"[",
"]",
"=",
"[",
"'value'",
"=>",
"$",
"value",
",",
"'type'",
"=>",
"$",
"type",
"]",
";",
"}",
"}"
] | Iterates over the passed in conditions and ensures that there is a matching true value for each.
If no matching true value, then it is defaulted to '1'.
@param array|\Cake\Database\ExpressionInterface $conditions Must be a ExpressionInterface instance, or an array of ExpressionInterface instances.
@param array|\Cake\Database\ExpressionInterface $values associative array of values of each condition
@param array $types associative array of types to be associated with the values
@return void | [
"Iterates",
"over",
"the",
"passed",
"in",
"conditions",
"and",
"ensures",
"that",
"there",
"is",
"a",
"matching",
"true",
"value",
"for",
"each",
".",
"If",
"no",
"matching",
"true",
"value",
"then",
"it",
"is",
"defaulted",
"to",
"1",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/CaseExpression.php#L113-L157 |
211,781 | cakephp/cakephp | src/Database/Expression/CaseExpression.php | CaseExpression._compile | protected function _compile($part, ValueBinder $generator)
{
if ($part instanceof ExpressionInterface) {
$part = $part->sql($generator);
} elseif (is_array($part)) {
$placeholder = $generator->placeholder('param');
$generator->bind($placeholder, $part['value'], $part['type']);
$part = $placeholder;
}
return $part;
} | php | protected function _compile($part, ValueBinder $generator)
{
if ($part instanceof ExpressionInterface) {
$part = $part->sql($generator);
} elseif (is_array($part)) {
$placeholder = $generator->placeholder('param');
$generator->bind($placeholder, $part['value'], $part['type']);
$part = $placeholder;
}
return $part;
} | [
"protected",
"function",
"_compile",
"(",
"$",
"part",
",",
"ValueBinder",
"$",
"generator",
")",
"{",
"if",
"(",
"$",
"part",
"instanceof",
"ExpressionInterface",
")",
"{",
"$",
"part",
"=",
"$",
"part",
"->",
"sql",
"(",
"$",
"generator",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"part",
")",
")",
"{",
"$",
"placeholder",
"=",
"$",
"generator",
"->",
"placeholder",
"(",
"'param'",
")",
";",
"$",
"generator",
"->",
"bind",
"(",
"$",
"placeholder",
",",
"$",
"part",
"[",
"'value'",
"]",
",",
"$",
"part",
"[",
"'type'",
"]",
")",
";",
"$",
"part",
"=",
"$",
"placeholder",
";",
"}",
"return",
"$",
"part",
";",
"}"
] | Compiles the relevant parts into sql
@param array|string|\Cake\Database\ExpressionInterface $part The part to compile
@param \Cake\Database\ValueBinder $generator Sql generator
@return string | [
"Compiles",
"the",
"relevant",
"parts",
"into",
"sql"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/CaseExpression.php#L193-L204 |
211,782 | cakephp/cakephp | src/Database/Expression/CaseExpression.php | CaseExpression.sql | public function sql(ValueBinder $generator)
{
$parts = [];
$parts[] = 'CASE';
foreach ($this->_conditions as $k => $part) {
$value = $this->_values[$k];
$parts[] = 'WHEN ' . $this->_compile($part, $generator) . ' THEN ' . $this->_compile($value, $generator);
}
if ($this->_elseValue !== null) {
$parts[] = 'ELSE';
$parts[] = $this->_compile($this->_elseValue, $generator);
}
$parts[] = 'END';
return implode(' ', $parts);
} | php | public function sql(ValueBinder $generator)
{
$parts = [];
$parts[] = 'CASE';
foreach ($this->_conditions as $k => $part) {
$value = $this->_values[$k];
$parts[] = 'WHEN ' . $this->_compile($part, $generator) . ' THEN ' . $this->_compile($value, $generator);
}
if ($this->_elseValue !== null) {
$parts[] = 'ELSE';
$parts[] = $this->_compile($this->_elseValue, $generator);
}
$parts[] = 'END';
return implode(' ', $parts);
} | [
"public",
"function",
"sql",
"(",
"ValueBinder",
"$",
"generator",
")",
"{",
"$",
"parts",
"=",
"[",
"]",
";",
"$",
"parts",
"[",
"]",
"=",
"'CASE'",
";",
"foreach",
"(",
"$",
"this",
"->",
"_conditions",
"as",
"$",
"k",
"=>",
"$",
"part",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"_values",
"[",
"$",
"k",
"]",
";",
"$",
"parts",
"[",
"]",
"=",
"'WHEN '",
".",
"$",
"this",
"->",
"_compile",
"(",
"$",
"part",
",",
"$",
"generator",
")",
".",
"' THEN '",
".",
"$",
"this",
"->",
"_compile",
"(",
"$",
"value",
",",
"$",
"generator",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_elseValue",
"!==",
"null",
")",
"{",
"$",
"parts",
"[",
"]",
"=",
"'ELSE'",
";",
"$",
"parts",
"[",
"]",
"=",
"$",
"this",
"->",
"_compile",
"(",
"$",
"this",
"->",
"_elseValue",
",",
"$",
"generator",
")",
";",
"}",
"$",
"parts",
"[",
"]",
"=",
"'END'",
";",
"return",
"implode",
"(",
"' '",
",",
"$",
"parts",
")",
";",
"}"
] | Converts the Node into a SQL string fragment.
@param \Cake\Database\ValueBinder $generator Placeholder generator object
@return string | [
"Converts",
"the",
"Node",
"into",
"a",
"SQL",
"string",
"fragment",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/CaseExpression.php#L213-L228 |
211,783 | cakephp/cakephp | src/Log/LogEngineRegistry.php | LogEngineRegistry._create | protected function _create($class, $alias, $settings)
{
if (is_callable($class)) {
$class = $class($alias);
}
if (is_object($class)) {
$instance = $class;
}
if (!isset($instance)) {
$instance = new $class($settings);
}
if ($instance instanceof LoggerInterface) {
return $instance;
}
throw new RuntimeException(
'Loggers must implement Psr\Log\LoggerInterface.'
);
} | php | protected function _create($class, $alias, $settings)
{
if (is_callable($class)) {
$class = $class($alias);
}
if (is_object($class)) {
$instance = $class;
}
if (!isset($instance)) {
$instance = new $class($settings);
}
if ($instance instanceof LoggerInterface) {
return $instance;
}
throw new RuntimeException(
'Loggers must implement Psr\Log\LoggerInterface.'
);
} | [
"protected",
"function",
"_create",
"(",
"$",
"class",
",",
"$",
"alias",
",",
"$",
"settings",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class",
"=",
"$",
"class",
"(",
"$",
"alias",
")",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"class",
")",
")",
"{",
"$",
"instance",
"=",
"$",
"class",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"instance",
")",
")",
"{",
"$",
"instance",
"=",
"new",
"$",
"class",
"(",
"$",
"settings",
")",
";",
"}",
"if",
"(",
"$",
"instance",
"instanceof",
"LoggerInterface",
")",
"{",
"return",
"$",
"instance",
";",
"}",
"throw",
"new",
"RuntimeException",
"(",
"'Loggers must implement Psr\\Log\\LoggerInterface.'",
")",
";",
"}"
] | Create the logger instance.
Part of the template method for Cake\Core\ObjectRegistry::load()
@param string|\Psr\Log\LoggerInterface $class The classname or object to make.
@param string $alias The alias of the object.
@param array $settings An array of settings to use for the logger.
@return \Psr\Log\LoggerInterface The constructed logger class.
@throws \RuntimeException when an object doesn't implement the correct interface. | [
"Create",
"the",
"logger",
"instance",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Log/LogEngineRegistry.php#L71-L92 |
211,784 | cakephp/cakephp | src/Console/HelpFormatter.php | HelpFormatter.text | public function text($width = 72)
{
$parser = $this->_parser;
$out = [];
$description = $parser->getDescription();
if (!empty($description)) {
$out[] = Text::wrap($description, $width);
$out[] = '';
}
$out[] = '<info>Usage:</info>';
$out[] = $this->_generateUsage();
$out[] = '';
$subcommands = $parser->subcommands();
if (!empty($subcommands)) {
$out[] = '<info>Subcommands:</info>';
$out[] = '';
$max = $this->_getMaxLength($subcommands) + 2;
foreach ($subcommands as $command) {
$out[] = Text::wrapBlock($command->help($max), [
'width' => $width,
'indent' => str_repeat(' ', $max),
'indentAt' => 1
]);
}
$out[] = '';
$out[] = sprintf('To see help on a subcommand use <info>`' . $this->_alias . ' %s [subcommand] --help`</info>', $parser->getCommand());
$out[] = '';
}
$options = $parser->options();
if (!empty($options)) {
$max = $this->_getMaxLength($options) + 8;
$out[] = '<info>Options:</info>';
$out[] = '';
foreach ($options as $option) {
$out[] = Text::wrapBlock($option->help($max), [
'width' => $width,
'indent' => str_repeat(' ', $max),
'indentAt' => 1
]);
}
$out[] = '';
}
$arguments = $parser->arguments();
if (!empty($arguments)) {
$max = $this->_getMaxLength($arguments) + 2;
$out[] = '<info>Arguments:</info>';
$out[] = '';
foreach ($arguments as $argument) {
$out[] = Text::wrapBlock($argument->help($max), [
'width' => $width,
'indent' => str_repeat(' ', $max),
'indentAt' => 1
]);
}
$out[] = '';
}
$epilog = $parser->getEpilog();
if (!empty($epilog)) {
$out[] = Text::wrap($epilog, $width);
$out[] = '';
}
return implode("\n", $out);
} | php | public function text($width = 72)
{
$parser = $this->_parser;
$out = [];
$description = $parser->getDescription();
if (!empty($description)) {
$out[] = Text::wrap($description, $width);
$out[] = '';
}
$out[] = '<info>Usage:</info>';
$out[] = $this->_generateUsage();
$out[] = '';
$subcommands = $parser->subcommands();
if (!empty($subcommands)) {
$out[] = '<info>Subcommands:</info>';
$out[] = '';
$max = $this->_getMaxLength($subcommands) + 2;
foreach ($subcommands as $command) {
$out[] = Text::wrapBlock($command->help($max), [
'width' => $width,
'indent' => str_repeat(' ', $max),
'indentAt' => 1
]);
}
$out[] = '';
$out[] = sprintf('To see help on a subcommand use <info>`' . $this->_alias . ' %s [subcommand] --help`</info>', $parser->getCommand());
$out[] = '';
}
$options = $parser->options();
if (!empty($options)) {
$max = $this->_getMaxLength($options) + 8;
$out[] = '<info>Options:</info>';
$out[] = '';
foreach ($options as $option) {
$out[] = Text::wrapBlock($option->help($max), [
'width' => $width,
'indent' => str_repeat(' ', $max),
'indentAt' => 1
]);
}
$out[] = '';
}
$arguments = $parser->arguments();
if (!empty($arguments)) {
$max = $this->_getMaxLength($arguments) + 2;
$out[] = '<info>Arguments:</info>';
$out[] = '';
foreach ($arguments as $argument) {
$out[] = Text::wrapBlock($argument->help($max), [
'width' => $width,
'indent' => str_repeat(' ', $max),
'indentAt' => 1
]);
}
$out[] = '';
}
$epilog = $parser->getEpilog();
if (!empty($epilog)) {
$out[] = Text::wrap($epilog, $width);
$out[] = '';
}
return implode("\n", $out);
} | [
"public",
"function",
"text",
"(",
"$",
"width",
"=",
"72",
")",
"{",
"$",
"parser",
"=",
"$",
"this",
"->",
"_parser",
";",
"$",
"out",
"=",
"[",
"]",
";",
"$",
"description",
"=",
"$",
"parser",
"->",
"getDescription",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"description",
")",
")",
"{",
"$",
"out",
"[",
"]",
"=",
"Text",
"::",
"wrap",
"(",
"$",
"description",
",",
"$",
"width",
")",
";",
"$",
"out",
"[",
"]",
"=",
"''",
";",
"}",
"$",
"out",
"[",
"]",
"=",
"'<info>Usage:</info>'",
";",
"$",
"out",
"[",
"]",
"=",
"$",
"this",
"->",
"_generateUsage",
"(",
")",
";",
"$",
"out",
"[",
"]",
"=",
"''",
";",
"$",
"subcommands",
"=",
"$",
"parser",
"->",
"subcommands",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"subcommands",
")",
")",
"{",
"$",
"out",
"[",
"]",
"=",
"'<info>Subcommands:</info>'",
";",
"$",
"out",
"[",
"]",
"=",
"''",
";",
"$",
"max",
"=",
"$",
"this",
"->",
"_getMaxLength",
"(",
"$",
"subcommands",
")",
"+",
"2",
";",
"foreach",
"(",
"$",
"subcommands",
"as",
"$",
"command",
")",
"{",
"$",
"out",
"[",
"]",
"=",
"Text",
"::",
"wrapBlock",
"(",
"$",
"command",
"->",
"help",
"(",
"$",
"max",
")",
",",
"[",
"'width'",
"=>",
"$",
"width",
",",
"'indent'",
"=>",
"str_repeat",
"(",
"' '",
",",
"$",
"max",
")",
",",
"'indentAt'",
"=>",
"1",
"]",
")",
";",
"}",
"$",
"out",
"[",
"]",
"=",
"''",
";",
"$",
"out",
"[",
"]",
"=",
"sprintf",
"(",
"'To see help on a subcommand use <info>`'",
".",
"$",
"this",
"->",
"_alias",
".",
"' %s [subcommand] --help`</info>'",
",",
"$",
"parser",
"->",
"getCommand",
"(",
")",
")",
";",
"$",
"out",
"[",
"]",
"=",
"''",
";",
"}",
"$",
"options",
"=",
"$",
"parser",
"->",
"options",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
")",
")",
"{",
"$",
"max",
"=",
"$",
"this",
"->",
"_getMaxLength",
"(",
"$",
"options",
")",
"+",
"8",
";",
"$",
"out",
"[",
"]",
"=",
"'<info>Options:</info>'",
";",
"$",
"out",
"[",
"]",
"=",
"''",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"option",
")",
"{",
"$",
"out",
"[",
"]",
"=",
"Text",
"::",
"wrapBlock",
"(",
"$",
"option",
"->",
"help",
"(",
"$",
"max",
")",
",",
"[",
"'width'",
"=>",
"$",
"width",
",",
"'indent'",
"=>",
"str_repeat",
"(",
"' '",
",",
"$",
"max",
")",
",",
"'indentAt'",
"=>",
"1",
"]",
")",
";",
"}",
"$",
"out",
"[",
"]",
"=",
"''",
";",
"}",
"$",
"arguments",
"=",
"$",
"parser",
"->",
"arguments",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"arguments",
")",
")",
"{",
"$",
"max",
"=",
"$",
"this",
"->",
"_getMaxLength",
"(",
"$",
"arguments",
")",
"+",
"2",
";",
"$",
"out",
"[",
"]",
"=",
"'<info>Arguments:</info>'",
";",
"$",
"out",
"[",
"]",
"=",
"''",
";",
"foreach",
"(",
"$",
"arguments",
"as",
"$",
"argument",
")",
"{",
"$",
"out",
"[",
"]",
"=",
"Text",
"::",
"wrapBlock",
"(",
"$",
"argument",
"->",
"help",
"(",
"$",
"max",
")",
",",
"[",
"'width'",
"=>",
"$",
"width",
",",
"'indent'",
"=>",
"str_repeat",
"(",
"' '",
",",
"$",
"max",
")",
",",
"'indentAt'",
"=>",
"1",
"]",
")",
";",
"}",
"$",
"out",
"[",
"]",
"=",
"''",
";",
"}",
"$",
"epilog",
"=",
"$",
"parser",
"->",
"getEpilog",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"epilog",
")",
")",
"{",
"$",
"out",
"[",
"]",
"=",
"Text",
"::",
"wrap",
"(",
"$",
"epilog",
",",
"$",
"width",
")",
";",
"$",
"out",
"[",
"]",
"=",
"''",
";",
"}",
"return",
"implode",
"(",
"\"\\n\"",
",",
"$",
"out",
")",
";",
"}"
] | Get the help as formatted text suitable for output on the command line.
@param int $width The width of the help output.
@return string | [
"Get",
"the",
"help",
"as",
"formatted",
"text",
"suitable",
"for",
"output",
"on",
"the",
"command",
"line",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/HelpFormatter.php#L93-L158 |
211,785 | cakephp/cakephp | src/Console/HelpFormatter.php | HelpFormatter._getMaxLength | protected function _getMaxLength($collection)
{
$max = 0;
foreach ($collection as $item) {
$max = (strlen($item->name()) > $max) ? strlen($item->name()) : $max;
}
return $max;
} | php | protected function _getMaxLength($collection)
{
$max = 0;
foreach ($collection as $item) {
$max = (strlen($item->name()) > $max) ? strlen($item->name()) : $max;
}
return $max;
} | [
"protected",
"function",
"_getMaxLength",
"(",
"$",
"collection",
")",
"{",
"$",
"max",
"=",
"0",
";",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"item",
")",
"{",
"$",
"max",
"=",
"(",
"strlen",
"(",
"$",
"item",
"->",
"name",
"(",
")",
")",
">",
"$",
"max",
")",
"?",
"strlen",
"(",
"$",
"item",
"->",
"name",
"(",
")",
")",
":",
"$",
"max",
";",
"}",
"return",
"$",
"max",
";",
"}"
] | Iterate over a collection and find the longest named thing.
@param array $collection The collection to find a max length of.
@return int | [
"Iterate",
"over",
"a",
"collection",
"and",
"find",
"the",
"longest",
"named",
"thing",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/HelpFormatter.php#L200-L208 |
211,786 | cakephp/cakephp | src/Console/HelpFormatter.php | HelpFormatter.xml | public function xml($string = true)
{
$parser = $this->_parser;
$xml = new SimpleXMLElement('<shell></shell>');
$xml->addChild('command', $parser->getCommand());
$xml->addChild('description', $parser->getDescription());
$subcommands = $xml->addChild('subcommands');
foreach ($parser->subcommands() as $command) {
$command->xml($subcommands);
}
$options = $xml->addChild('options');
foreach ($parser->options() as $option) {
$option->xml($options);
}
$arguments = $xml->addChild('arguments');
foreach ($parser->arguments() as $argument) {
$argument->xml($arguments);
}
$xml->addChild('epilog', $parser->getEpilog());
return $string ? $xml->asXML() : $xml;
} | php | public function xml($string = true)
{
$parser = $this->_parser;
$xml = new SimpleXMLElement('<shell></shell>');
$xml->addChild('command', $parser->getCommand());
$xml->addChild('description', $parser->getDescription());
$subcommands = $xml->addChild('subcommands');
foreach ($parser->subcommands() as $command) {
$command->xml($subcommands);
}
$options = $xml->addChild('options');
foreach ($parser->options() as $option) {
$option->xml($options);
}
$arguments = $xml->addChild('arguments');
foreach ($parser->arguments() as $argument) {
$argument->xml($arguments);
}
$xml->addChild('epilog', $parser->getEpilog());
return $string ? $xml->asXML() : $xml;
} | [
"public",
"function",
"xml",
"(",
"$",
"string",
"=",
"true",
")",
"{",
"$",
"parser",
"=",
"$",
"this",
"->",
"_parser",
";",
"$",
"xml",
"=",
"new",
"SimpleXMLElement",
"(",
"'<shell></shell>'",
")",
";",
"$",
"xml",
"->",
"addChild",
"(",
"'command'",
",",
"$",
"parser",
"->",
"getCommand",
"(",
")",
")",
";",
"$",
"xml",
"->",
"addChild",
"(",
"'description'",
",",
"$",
"parser",
"->",
"getDescription",
"(",
")",
")",
";",
"$",
"subcommands",
"=",
"$",
"xml",
"->",
"addChild",
"(",
"'subcommands'",
")",
";",
"foreach",
"(",
"$",
"parser",
"->",
"subcommands",
"(",
")",
"as",
"$",
"command",
")",
"{",
"$",
"command",
"->",
"xml",
"(",
"$",
"subcommands",
")",
";",
"}",
"$",
"options",
"=",
"$",
"xml",
"->",
"addChild",
"(",
"'options'",
")",
";",
"foreach",
"(",
"$",
"parser",
"->",
"options",
"(",
")",
"as",
"$",
"option",
")",
"{",
"$",
"option",
"->",
"xml",
"(",
"$",
"options",
")",
";",
"}",
"$",
"arguments",
"=",
"$",
"xml",
"->",
"addChild",
"(",
"'arguments'",
")",
";",
"foreach",
"(",
"$",
"parser",
"->",
"arguments",
"(",
")",
"as",
"$",
"argument",
")",
"{",
"$",
"argument",
"->",
"xml",
"(",
"$",
"arguments",
")",
";",
"}",
"$",
"xml",
"->",
"addChild",
"(",
"'epilog'",
",",
"$",
"parser",
"->",
"getEpilog",
"(",
")",
")",
";",
"return",
"$",
"string",
"?",
"$",
"xml",
"->",
"asXML",
"(",
")",
":",
"$",
"xml",
";",
"}"
] | Get the help as an xml string.
@param bool $string Return the SimpleXml object or a string. Defaults to true.
@return string|\SimpleXMLElement See $string | [
"Get",
"the",
"help",
"as",
"an",
"xml",
"string",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/HelpFormatter.php#L216-L238 |
211,787 | cakephp/cakephp | src/Shell/Task/LoadTask.php | LoadTask.makeOptions | protected function makeOptions()
{
$autoloadString = $this->param('autoload') ? "'autoload' => true" : '';
$bootstrapString = $this->param('bootstrap') ? "'bootstrap' => true" : '';
$routesString = $this->param('routes') ? "'routes' => true" : '';
return implode(', ', array_filter([$autoloadString, $bootstrapString, $routesString]));
} | php | protected function makeOptions()
{
$autoloadString = $this->param('autoload') ? "'autoload' => true" : '';
$bootstrapString = $this->param('bootstrap') ? "'bootstrap' => true" : '';
$routesString = $this->param('routes') ? "'routes' => true" : '';
return implode(', ', array_filter([$autoloadString, $bootstrapString, $routesString]));
} | [
"protected",
"function",
"makeOptions",
"(",
")",
"{",
"$",
"autoloadString",
"=",
"$",
"this",
"->",
"param",
"(",
"'autoload'",
")",
"?",
"\"'autoload' => true\"",
":",
"''",
";",
"$",
"bootstrapString",
"=",
"$",
"this",
"->",
"param",
"(",
"'bootstrap'",
")",
"?",
"\"'bootstrap' => true\"",
":",
"''",
";",
"$",
"routesString",
"=",
"$",
"this",
"->",
"param",
"(",
"'routes'",
")",
"?",
"\"'routes' => true\"",
":",
"''",
";",
"return",
"implode",
"(",
"', '",
",",
"array_filter",
"(",
"[",
"$",
"autoloadString",
",",
"$",
"bootstrapString",
",",
"$",
"routesString",
"]",
")",
")",
";",
"}"
] | Create options string for the load call.
@return string | [
"Create",
"options",
"string",
"for",
"the",
"load",
"call",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Task/LoadTask.php#L72-L79 |
211,788 | cakephp/cakephp | src/Shell/Task/LoadTask.php | LoadTask.modifyApplication | protected function modifyApplication($app, $plugin, $options)
{
$file = new File($app, false);
$contents = $file->read();
$append = "\n \$this->addPlugin('%s', [%s]);\n";
$insert = str_replace(', []', '', sprintf($append, $plugin, $options));
if (!preg_match('/function bootstrap\(\)/m', $contents)) {
$this->abort('Your Application class does not have a bootstrap() method. Please add one.');
} else {
$contents = preg_replace('/(function bootstrap\(\)(?:\s+)\{)/m', '$1' . $insert, $contents);
}
$file->write($contents);
$this->out('');
$this->out(sprintf('%s modified', $app));
} | php | protected function modifyApplication($app, $plugin, $options)
{
$file = new File($app, false);
$contents = $file->read();
$append = "\n \$this->addPlugin('%s', [%s]);\n";
$insert = str_replace(', []', '', sprintf($append, $plugin, $options));
if (!preg_match('/function bootstrap\(\)/m', $contents)) {
$this->abort('Your Application class does not have a bootstrap() method. Please add one.');
} else {
$contents = preg_replace('/(function bootstrap\(\)(?:\s+)\{)/m', '$1' . $insert, $contents);
}
$file->write($contents);
$this->out('');
$this->out(sprintf('%s modified', $app));
} | [
"protected",
"function",
"modifyApplication",
"(",
"$",
"app",
",",
"$",
"plugin",
",",
"$",
"options",
")",
"{",
"$",
"file",
"=",
"new",
"File",
"(",
"$",
"app",
",",
"false",
")",
";",
"$",
"contents",
"=",
"$",
"file",
"->",
"read",
"(",
")",
";",
"$",
"append",
"=",
"\"\\n \\$this->addPlugin('%s', [%s]);\\n\"",
";",
"$",
"insert",
"=",
"str_replace",
"(",
"', []'",
",",
"''",
",",
"sprintf",
"(",
"$",
"append",
",",
"$",
"plugin",
",",
"$",
"options",
")",
")",
";",
"if",
"(",
"!",
"preg_match",
"(",
"'/function bootstrap\\(\\)/m'",
",",
"$",
"contents",
")",
")",
"{",
"$",
"this",
"->",
"abort",
"(",
"'Your Application class does not have a bootstrap() method. Please add one.'",
")",
";",
"}",
"else",
"{",
"$",
"contents",
"=",
"preg_replace",
"(",
"'/(function bootstrap\\(\\)(?:\\s+)\\{)/m'",
",",
"'$1'",
".",
"$",
"insert",
",",
"$",
"contents",
")",
";",
"}",
"$",
"file",
"->",
"write",
"(",
"$",
"contents",
")",
";",
"$",
"this",
"->",
"out",
"(",
"''",
")",
";",
"$",
"this",
"->",
"out",
"(",
"sprintf",
"(",
"'%s modified'",
",",
"$",
"app",
")",
")",
";",
"}"
] | Modify the application class
@param string $app The Application file to modify.
@param string $plugin The plugin name to add.
@param string $options The plugin options to add
@return void | [
"Modify",
"the",
"application",
"class"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Task/LoadTask.php#L89-L106 |
211,789 | cakephp/cakephp | src/Console/ConsoleInputOption.php | ConsoleInputOption.help | public function help($width = 0)
{
$default = $short = '';
if ($this->_default && $this->_default !== true) {
$default = sprintf(' <comment>(default: %s)</comment>', $this->_default);
}
if ($this->_choices) {
$default .= sprintf(' <comment>(choices: %s)</comment>', implode('|', $this->_choices));
}
if (strlen($this->_short) > 0) {
$short = ', -' . $this->_short;
}
$name = sprintf('--%s%s', $this->_name, $short);
if (strlen($name) < $width) {
$name = str_pad($name, $width, ' ');
}
return sprintf('%s%s%s', $name, $this->_help, $default);
} | php | public function help($width = 0)
{
$default = $short = '';
if ($this->_default && $this->_default !== true) {
$default = sprintf(' <comment>(default: %s)</comment>', $this->_default);
}
if ($this->_choices) {
$default .= sprintf(' <comment>(choices: %s)</comment>', implode('|', $this->_choices));
}
if (strlen($this->_short) > 0) {
$short = ', -' . $this->_short;
}
$name = sprintf('--%s%s', $this->_name, $short);
if (strlen($name) < $width) {
$name = str_pad($name, $width, ' ');
}
return sprintf('%s%s%s', $name, $this->_help, $default);
} | [
"public",
"function",
"help",
"(",
"$",
"width",
"=",
"0",
")",
"{",
"$",
"default",
"=",
"$",
"short",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"_default",
"&&",
"$",
"this",
"->",
"_default",
"!==",
"true",
")",
"{",
"$",
"default",
"=",
"sprintf",
"(",
"' <comment>(default: %s)</comment>'",
",",
"$",
"this",
"->",
"_default",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_choices",
")",
"{",
"$",
"default",
".=",
"sprintf",
"(",
"' <comment>(choices: %s)</comment>'",
",",
"implode",
"(",
"'|'",
",",
"$",
"this",
"->",
"_choices",
")",
")",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"this",
"->",
"_short",
")",
">",
"0",
")",
"{",
"$",
"short",
"=",
"', -'",
".",
"$",
"this",
"->",
"_short",
";",
"}",
"$",
"name",
"=",
"sprintf",
"(",
"'--%s%s'",
",",
"$",
"this",
"->",
"_name",
",",
"$",
"short",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"name",
")",
"<",
"$",
"width",
")",
"{",
"$",
"name",
"=",
"str_pad",
"(",
"$",
"name",
",",
"$",
"width",
",",
"' '",
")",
";",
"}",
"return",
"sprintf",
"(",
"'%s%s%s'",
",",
"$",
"name",
",",
"$",
"this",
"->",
"_help",
",",
"$",
"default",
")",
";",
"}"
] | Generate the help for this this option.
@param int $width The width to make the name of the option.
@return string | [
"Generate",
"the",
"help",
"for",
"this",
"this",
"option",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleInputOption.php#L145-L163 |
211,790 | cakephp/cakephp | src/Console/ConsoleInputOption.php | ConsoleInputOption.usage | public function usage()
{
$name = (strlen($this->_short) > 0) ? ('-' . $this->_short) : ('--' . $this->_name);
$default = '';
if (strlen($this->_default) > 0 && $this->_default !== true) {
$default = ' ' . $this->_default;
}
if ($this->_choices) {
$default = ' ' . implode('|', $this->_choices);
}
return sprintf('[%s%s]', $name, $default);
} | php | public function usage()
{
$name = (strlen($this->_short) > 0) ? ('-' . $this->_short) : ('--' . $this->_name);
$default = '';
if (strlen($this->_default) > 0 && $this->_default !== true) {
$default = ' ' . $this->_default;
}
if ($this->_choices) {
$default = ' ' . implode('|', $this->_choices);
}
return sprintf('[%s%s]', $name, $default);
} | [
"public",
"function",
"usage",
"(",
")",
"{",
"$",
"name",
"=",
"(",
"strlen",
"(",
"$",
"this",
"->",
"_short",
")",
">",
"0",
")",
"?",
"(",
"'-'",
".",
"$",
"this",
"->",
"_short",
")",
":",
"(",
"'--'",
".",
"$",
"this",
"->",
"_name",
")",
";",
"$",
"default",
"=",
"''",
";",
"if",
"(",
"strlen",
"(",
"$",
"this",
"->",
"_default",
")",
">",
"0",
"&&",
"$",
"this",
"->",
"_default",
"!==",
"true",
")",
"{",
"$",
"default",
"=",
"' '",
".",
"$",
"this",
"->",
"_default",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_choices",
")",
"{",
"$",
"default",
"=",
"' '",
".",
"implode",
"(",
"'|'",
",",
"$",
"this",
"->",
"_choices",
")",
";",
"}",
"return",
"sprintf",
"(",
"'[%s%s]'",
",",
"$",
"name",
",",
"$",
"default",
")",
";",
"}"
] | Get the usage value for this option
@return string | [
"Get",
"the",
"usage",
"value",
"for",
"this",
"option"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleInputOption.php#L170-L182 |
211,791 | cakephp/cakephp | src/Console/ConsoleInputOption.php | ConsoleInputOption.xml | public function xml(SimpleXMLElement $parent)
{
$option = $parent->addChild('option');
$option->addAttribute('name', '--' . $this->_name);
$short = '';
if (strlen($this->_short) > 0) {
$short = '-' . $this->_short;
}
$option->addAttribute('short', $short);
$option->addAttribute('help', $this->_help);
$option->addAttribute('boolean', (int)$this->_boolean);
$option->addChild('default', $this->_default);
$choices = $option->addChild('choices');
foreach ($this->_choices as $valid) {
$choices->addChild('choice', $valid);
}
return $parent;
} | php | public function xml(SimpleXMLElement $parent)
{
$option = $parent->addChild('option');
$option->addAttribute('name', '--' . $this->_name);
$short = '';
if (strlen($this->_short) > 0) {
$short = '-' . $this->_short;
}
$option->addAttribute('short', $short);
$option->addAttribute('help', $this->_help);
$option->addAttribute('boolean', (int)$this->_boolean);
$option->addChild('default', $this->_default);
$choices = $option->addChild('choices');
foreach ($this->_choices as $valid) {
$choices->addChild('choice', $valid);
}
return $parent;
} | [
"public",
"function",
"xml",
"(",
"SimpleXMLElement",
"$",
"parent",
")",
"{",
"$",
"option",
"=",
"$",
"parent",
"->",
"addChild",
"(",
"'option'",
")",
";",
"$",
"option",
"->",
"addAttribute",
"(",
"'name'",
",",
"'--'",
".",
"$",
"this",
"->",
"_name",
")",
";",
"$",
"short",
"=",
"''",
";",
"if",
"(",
"strlen",
"(",
"$",
"this",
"->",
"_short",
")",
">",
"0",
")",
"{",
"$",
"short",
"=",
"'-'",
".",
"$",
"this",
"->",
"_short",
";",
"}",
"$",
"option",
"->",
"addAttribute",
"(",
"'short'",
",",
"$",
"short",
")",
";",
"$",
"option",
"->",
"addAttribute",
"(",
"'help'",
",",
"$",
"this",
"->",
"_help",
")",
";",
"$",
"option",
"->",
"addAttribute",
"(",
"'boolean'",
",",
"(",
"int",
")",
"$",
"this",
"->",
"_boolean",
")",
";",
"$",
"option",
"->",
"addChild",
"(",
"'default'",
",",
"$",
"this",
"->",
"_default",
")",
";",
"$",
"choices",
"=",
"$",
"option",
"->",
"addChild",
"(",
"'choices'",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"_choices",
"as",
"$",
"valid",
")",
"{",
"$",
"choices",
"->",
"addChild",
"(",
"'choice'",
",",
"$",
"valid",
")",
";",
"}",
"return",
"$",
"parent",
";",
"}"
] | Append the option's xml into the parent.
@param \SimpleXMLElement $parent The parent element.
@return \SimpleXMLElement The parent with this option appended. | [
"Append",
"the",
"option",
"s",
"xml",
"into",
"the",
"parent",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleInputOption.php#L246-L264 |
211,792 | cakephp/cakephp | src/Database/Expression/TupleComparison.php | TupleComparison._stringifyValues | protected function _stringifyValues($generator)
{
$values = [];
$parts = $this->getValue();
if ($parts instanceof ExpressionInterface) {
return $parts->sql($generator);
}
foreach ($parts as $i => $value) {
if ($value instanceof ExpressionInterface) {
$values[] = $value->sql($generator);
continue;
}
$type = $this->_type;
$multiType = is_array($type);
$isMulti = $this->isMulti();
$type = $multiType ? $type : str_replace('[]', '', $type);
$type = $type ?: null;
if ($isMulti) {
$bound = [];
foreach ($value as $k => $val) {
$valType = $multiType ? $type[$k] : $type;
$bound[] = $this->_bindValue($generator, $val, $valType);
}
$values[] = sprintf('(%s)', implode(',', $bound));
continue;
}
$valType = $multiType && isset($type[$i]) ? $type[$i] : $type;
$values[] = $this->_bindValue($generator, $value, $valType);
}
return implode(', ', $values);
} | php | protected function _stringifyValues($generator)
{
$values = [];
$parts = $this->getValue();
if ($parts instanceof ExpressionInterface) {
return $parts->sql($generator);
}
foreach ($parts as $i => $value) {
if ($value instanceof ExpressionInterface) {
$values[] = $value->sql($generator);
continue;
}
$type = $this->_type;
$multiType = is_array($type);
$isMulti = $this->isMulti();
$type = $multiType ? $type : str_replace('[]', '', $type);
$type = $type ?: null;
if ($isMulti) {
$bound = [];
foreach ($value as $k => $val) {
$valType = $multiType ? $type[$k] : $type;
$bound[] = $this->_bindValue($generator, $val, $valType);
}
$values[] = sprintf('(%s)', implode(',', $bound));
continue;
}
$valType = $multiType && isset($type[$i]) ? $type[$i] : $type;
$values[] = $this->_bindValue($generator, $value, $valType);
}
return implode(', ', $values);
} | [
"protected",
"function",
"_stringifyValues",
"(",
"$",
"generator",
")",
"{",
"$",
"values",
"=",
"[",
"]",
";",
"$",
"parts",
"=",
"$",
"this",
"->",
"getValue",
"(",
")",
";",
"if",
"(",
"$",
"parts",
"instanceof",
"ExpressionInterface",
")",
"{",
"return",
"$",
"parts",
"->",
"sql",
"(",
"$",
"generator",
")",
";",
"}",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"i",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"ExpressionInterface",
")",
"{",
"$",
"values",
"[",
"]",
"=",
"$",
"value",
"->",
"sql",
"(",
"$",
"generator",
")",
";",
"continue",
";",
"}",
"$",
"type",
"=",
"$",
"this",
"->",
"_type",
";",
"$",
"multiType",
"=",
"is_array",
"(",
"$",
"type",
")",
";",
"$",
"isMulti",
"=",
"$",
"this",
"->",
"isMulti",
"(",
")",
";",
"$",
"type",
"=",
"$",
"multiType",
"?",
"$",
"type",
":",
"str_replace",
"(",
"'[]'",
",",
"''",
",",
"$",
"type",
")",
";",
"$",
"type",
"=",
"$",
"type",
"?",
":",
"null",
";",
"if",
"(",
"$",
"isMulti",
")",
"{",
"$",
"bound",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"k",
"=>",
"$",
"val",
")",
"{",
"$",
"valType",
"=",
"$",
"multiType",
"?",
"$",
"type",
"[",
"$",
"k",
"]",
":",
"$",
"type",
";",
"$",
"bound",
"[",
"]",
"=",
"$",
"this",
"->",
"_bindValue",
"(",
"$",
"generator",
",",
"$",
"val",
",",
"$",
"valType",
")",
";",
"}",
"$",
"values",
"[",
"]",
"=",
"sprintf",
"(",
"'(%s)'",
",",
"implode",
"(",
"','",
",",
"$",
"bound",
")",
")",
";",
"continue",
";",
"}",
"$",
"valType",
"=",
"$",
"multiType",
"&&",
"isset",
"(",
"$",
"type",
"[",
"$",
"i",
"]",
")",
"?",
"$",
"type",
"[",
"$",
"i",
"]",
":",
"$",
"type",
";",
"$",
"values",
"[",
"]",
"=",
"$",
"this",
"->",
"_bindValue",
"(",
"$",
"generator",
",",
"$",
"value",
",",
"$",
"valType",
")",
";",
"}",
"return",
"implode",
"(",
"', '",
",",
"$",
"values",
")",
";",
"}"
] | Returns a string with the values as placeholders in a string to be used
for the SQL version of this expression
@param \Cake\Database\ValueBinder $generator The value binder to convert expressions with.
@return string | [
"Returns",
"a",
"string",
"with",
"the",
"values",
"as",
"placeholders",
"in",
"a",
"string",
"to",
"be",
"used",
"for",
"the",
"SQL",
"version",
"of",
"this",
"expression"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/TupleComparison.php#L76-L113 |
211,793 | cakephp/cakephp | src/Database/Expression/TupleComparison.php | TupleComparison.traverse | public function traverse(callable $callable)
{
foreach ($this->getField() as $field) {
$this->_traverseValue($field, $callable);
}
$value = $this->getValue();
if ($value instanceof ExpressionInterface) {
$callable($value);
$value->traverse($callable);
return;
}
foreach ($value as $i => $val) {
if ($this->isMulti()) {
foreach ($val as $v) {
$this->_traverseValue($v, $callable);
}
} else {
$this->_traverseValue($val, $callable);
}
}
} | php | public function traverse(callable $callable)
{
foreach ($this->getField() as $field) {
$this->_traverseValue($field, $callable);
}
$value = $this->getValue();
if ($value instanceof ExpressionInterface) {
$callable($value);
$value->traverse($callable);
return;
}
foreach ($value as $i => $val) {
if ($this->isMulti()) {
foreach ($val as $v) {
$this->_traverseValue($v, $callable);
}
} else {
$this->_traverseValue($val, $callable);
}
}
} | [
"public",
"function",
"traverse",
"(",
"callable",
"$",
"callable",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getField",
"(",
")",
"as",
"$",
"field",
")",
"{",
"$",
"this",
"->",
"_traverseValue",
"(",
"$",
"field",
",",
"$",
"callable",
")",
";",
"}",
"$",
"value",
"=",
"$",
"this",
"->",
"getValue",
"(",
")",
";",
"if",
"(",
"$",
"value",
"instanceof",
"ExpressionInterface",
")",
"{",
"$",
"callable",
"(",
"$",
"value",
")",
";",
"$",
"value",
"->",
"traverse",
"(",
"$",
"callable",
")",
";",
"return",
";",
"}",
"foreach",
"(",
"$",
"value",
"as",
"$",
"i",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isMulti",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"val",
"as",
"$",
"v",
")",
"{",
"$",
"this",
"->",
"_traverseValue",
"(",
"$",
"v",
",",
"$",
"callable",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"_traverseValue",
"(",
"$",
"val",
",",
"$",
"callable",
")",
";",
"}",
"}",
"}"
] | Traverses the tree of expressions stored in this object, visiting first
expressions in the left hand side and then the rest.
Callback function receives as its only argument an instance of an ExpressionInterface
@param callable $callable The callable to apply to sub-expressions
@return void | [
"Traverses",
"the",
"tree",
"of",
"expressions",
"stored",
"in",
"this",
"object",
"visiting",
"first",
"expressions",
"in",
"the",
"left",
"hand",
"side",
"and",
"then",
"the",
"rest",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/TupleComparison.php#L141-L164 |
211,794 | cakephp/cakephp | src/Http/ControllerFactory.php | ControllerFactory.getControllerClass | public function getControllerClass(ServerRequest $request)
{
$pluginPath = $controller = null;
$namespace = 'Controller';
if ($request->getParam('controller')) {
$controller = $request->getParam('controller');
}
if ($request->getParam('plugin')) {
$pluginPath = $request->getParam('plugin') . '.';
}
if ($request->getParam('prefix')) {
if (strpos($request->getParam('prefix'), '/') === false) {
$namespace .= '/' . Inflector::camelize($request->getParam('prefix'));
} else {
$prefixes = array_map(
'Cake\Utility\Inflector::camelize',
explode('/', $request->getParam('prefix'))
);
$namespace .= '/' . implode('/', $prefixes);
}
}
$firstChar = substr($controller, 0, 1);
// Disallow plugin short forms, / and \\ from
// controller names as they allow direct references to
// be created.
if (strpos($controller, '\\') !== false ||
strpos($controller, '/') !== false ||
strpos($controller, '.') !== false ||
$firstChar === strtolower($firstChar)
) {
$this->missingController($request);
}
return App::className($pluginPath . $controller, $namespace, 'Controller') ?: null;
} | php | public function getControllerClass(ServerRequest $request)
{
$pluginPath = $controller = null;
$namespace = 'Controller';
if ($request->getParam('controller')) {
$controller = $request->getParam('controller');
}
if ($request->getParam('plugin')) {
$pluginPath = $request->getParam('plugin') . '.';
}
if ($request->getParam('prefix')) {
if (strpos($request->getParam('prefix'), '/') === false) {
$namespace .= '/' . Inflector::camelize($request->getParam('prefix'));
} else {
$prefixes = array_map(
'Cake\Utility\Inflector::camelize',
explode('/', $request->getParam('prefix'))
);
$namespace .= '/' . implode('/', $prefixes);
}
}
$firstChar = substr($controller, 0, 1);
// Disallow plugin short forms, / and \\ from
// controller names as they allow direct references to
// be created.
if (strpos($controller, '\\') !== false ||
strpos($controller, '/') !== false ||
strpos($controller, '.') !== false ||
$firstChar === strtolower($firstChar)
) {
$this->missingController($request);
}
return App::className($pluginPath . $controller, $namespace, 'Controller') ?: null;
} | [
"public",
"function",
"getControllerClass",
"(",
"ServerRequest",
"$",
"request",
")",
"{",
"$",
"pluginPath",
"=",
"$",
"controller",
"=",
"null",
";",
"$",
"namespace",
"=",
"'Controller'",
";",
"if",
"(",
"$",
"request",
"->",
"getParam",
"(",
"'controller'",
")",
")",
"{",
"$",
"controller",
"=",
"$",
"request",
"->",
"getParam",
"(",
"'controller'",
")",
";",
"}",
"if",
"(",
"$",
"request",
"->",
"getParam",
"(",
"'plugin'",
")",
")",
"{",
"$",
"pluginPath",
"=",
"$",
"request",
"->",
"getParam",
"(",
"'plugin'",
")",
".",
"'.'",
";",
"}",
"if",
"(",
"$",
"request",
"->",
"getParam",
"(",
"'prefix'",
")",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"request",
"->",
"getParam",
"(",
"'prefix'",
")",
",",
"'/'",
")",
"===",
"false",
")",
"{",
"$",
"namespace",
".=",
"'/'",
".",
"Inflector",
"::",
"camelize",
"(",
"$",
"request",
"->",
"getParam",
"(",
"'prefix'",
")",
")",
";",
"}",
"else",
"{",
"$",
"prefixes",
"=",
"array_map",
"(",
"'Cake\\Utility\\Inflector::camelize'",
",",
"explode",
"(",
"'/'",
",",
"$",
"request",
"->",
"getParam",
"(",
"'prefix'",
")",
")",
")",
";",
"$",
"namespace",
".=",
"'/'",
".",
"implode",
"(",
"'/'",
",",
"$",
"prefixes",
")",
";",
"}",
"}",
"$",
"firstChar",
"=",
"substr",
"(",
"$",
"controller",
",",
"0",
",",
"1",
")",
";",
"// Disallow plugin short forms, / and \\\\ from",
"// controller names as they allow direct references to",
"// be created.",
"if",
"(",
"strpos",
"(",
"$",
"controller",
",",
"'\\\\'",
")",
"!==",
"false",
"||",
"strpos",
"(",
"$",
"controller",
",",
"'/'",
")",
"!==",
"false",
"||",
"strpos",
"(",
"$",
"controller",
",",
"'.'",
")",
"!==",
"false",
"||",
"$",
"firstChar",
"===",
"strtolower",
"(",
"$",
"firstChar",
")",
")",
"{",
"$",
"this",
"->",
"missingController",
"(",
"$",
"request",
")",
";",
"}",
"return",
"App",
"::",
"className",
"(",
"$",
"pluginPath",
".",
"$",
"controller",
",",
"$",
"namespace",
",",
"'Controller'",
")",
"?",
":",
"null",
";",
"}"
] | Determine the controller class name based on current request and controller param
@param \Cake\Http\ServerRequest $request The request to build a controller for.
@return string|null | [
"Determine",
"the",
"controller",
"class",
"name",
"based",
"on",
"current",
"request",
"and",
"controller",
"param"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ControllerFactory.php#L58-L93 |
211,795 | cakephp/cakephp | src/Http/ControllerFactory.php | ControllerFactory.missingController | protected function missingController($request)
{
throw new MissingControllerException([
'class' => $request->getParam('controller'),
'plugin' => $request->getParam('plugin'),
'prefix' => $request->getParam('prefix'),
'_ext' => $request->getParam('_ext')
]);
} | php | protected function missingController($request)
{
throw new MissingControllerException([
'class' => $request->getParam('controller'),
'plugin' => $request->getParam('plugin'),
'prefix' => $request->getParam('prefix'),
'_ext' => $request->getParam('_ext')
]);
} | [
"protected",
"function",
"missingController",
"(",
"$",
"request",
")",
"{",
"throw",
"new",
"MissingControllerException",
"(",
"[",
"'class'",
"=>",
"$",
"request",
"->",
"getParam",
"(",
"'controller'",
")",
",",
"'plugin'",
"=>",
"$",
"request",
"->",
"getParam",
"(",
"'plugin'",
")",
",",
"'prefix'",
"=>",
"$",
"request",
"->",
"getParam",
"(",
"'prefix'",
")",
",",
"'_ext'",
"=>",
"$",
"request",
"->",
"getParam",
"(",
"'_ext'",
")",
"]",
")",
";",
"}"
] | Throws an exception when a controller is missing.
@param \Cake\Http\ServerRequest $request The request.
@throws \Cake\Routing\Exception\MissingControllerException
@return void | [
"Throws",
"an",
"exception",
"when",
"a",
"controller",
"is",
"missing",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/ControllerFactory.php#L102-L110 |
211,796 | moodle/moodle | admin/tool/usertours/classes/local/filter/course.php | course.add_filter_to_form | public static function add_filter_to_form(\MoodleQuickForm &$mform) {
$options = ['multiple' => true];
$filtername = self::get_filter_name();
$key = "filter_{$filtername}";
$mform->addElement('course', $key, get_string($key, 'tool_usertours'), $options);
$mform->setDefault($key, '0');
$mform->addHelpButton($key, $key, 'tool_usertours');
} | php | public static function add_filter_to_form(\MoodleQuickForm &$mform) {
$options = ['multiple' => true];
$filtername = self::get_filter_name();
$key = "filter_{$filtername}";
$mform->addElement('course', $key, get_string($key, 'tool_usertours'), $options);
$mform->setDefault($key, '0');
$mform->addHelpButton($key, $key, 'tool_usertours');
} | [
"public",
"static",
"function",
"add_filter_to_form",
"(",
"\\",
"MoodleQuickForm",
"&",
"$",
"mform",
")",
"{",
"$",
"options",
"=",
"[",
"'multiple'",
"=>",
"true",
"]",
";",
"$",
"filtername",
"=",
"self",
"::",
"get_filter_name",
"(",
")",
";",
"$",
"key",
"=",
"\"filter_{$filtername}\"",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'course'",
",",
"$",
"key",
",",
"get_string",
"(",
"$",
"key",
",",
"'tool_usertours'",
")",
",",
"$",
"options",
")",
";",
"$",
"mform",
"->",
"setDefault",
"(",
"$",
"key",
",",
"'0'",
")",
";",
"$",
"mform",
"->",
"addHelpButton",
"(",
"$",
"key",
",",
"$",
"key",
",",
"'tool_usertours'",
")",
";",
"}"
] | Overrides the base add form element with a course selector.
@param \MoodleQuickForm $mform | [
"Overrides",
"the",
"base",
"add",
"form",
"element",
"with",
"a",
"course",
"selector",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/local/filter/course.php#L53-L62 |
211,797 | moodle/moodle | admin/tool/usertours/classes/local/filter/course.php | course.prepare_filter_values_for_form | public static function prepare_filter_values_for_form(tour $tour, \stdClass $data) {
$filtername = static::get_filter_name();
$key = "filter_{$filtername}";
$values = $tour->get_filter_values($filtername);
if (empty($values)) {
$values = 0;
}
$data->$key = $values;
return $data;
} | php | public static function prepare_filter_values_for_form(tour $tour, \stdClass $data) {
$filtername = static::get_filter_name();
$key = "filter_{$filtername}";
$values = $tour->get_filter_values($filtername);
if (empty($values)) {
$values = 0;
}
$data->$key = $values;
return $data;
} | [
"public",
"static",
"function",
"prepare_filter_values_for_form",
"(",
"tour",
"$",
"tour",
",",
"\\",
"stdClass",
"$",
"data",
")",
"{",
"$",
"filtername",
"=",
"static",
"::",
"get_filter_name",
"(",
")",
";",
"$",
"key",
"=",
"\"filter_{$filtername}\"",
";",
"$",
"values",
"=",
"$",
"tour",
"->",
"get_filter_values",
"(",
"$",
"filtername",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"values",
")",
")",
"{",
"$",
"values",
"=",
"0",
";",
"}",
"$",
"data",
"->",
"$",
"key",
"=",
"$",
"values",
";",
"return",
"$",
"data",
";",
"}"
] | Overrides the base prepare the filter values for the form with an integer value.
@param tour $tour The tour to prepare values from
@param stdClass $data The data value
@return stdClass | [
"Overrides",
"the",
"base",
"prepare",
"the",
"filter",
"values",
"for",
"the",
"form",
"with",
"an",
"integer",
"value",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/local/filter/course.php#L91-L100 |
211,798 | moodle/moodle | admin/tool/usertours/classes/local/filter/course.php | course.save_filter_values_from_form | public static function save_filter_values_from_form(tour $tour, \stdClass $data) {
$filtername = static::get_filter_name();
$key = "filter_{$filtername}";
$newvalue = $data->$key;
if (empty($data->$key)) {
$newvalue = [];
}
$tour->set_filter_values($filtername, $newvalue);
} | php | public static function save_filter_values_from_form(tour $tour, \stdClass $data) {
$filtername = static::get_filter_name();
$key = "filter_{$filtername}";
$newvalue = $data->$key;
if (empty($data->$key)) {
$newvalue = [];
}
$tour->set_filter_values($filtername, $newvalue);
} | [
"public",
"static",
"function",
"save_filter_values_from_form",
"(",
"tour",
"$",
"tour",
",",
"\\",
"stdClass",
"$",
"data",
")",
"{",
"$",
"filtername",
"=",
"static",
"::",
"get_filter_name",
"(",
")",
";",
"$",
"key",
"=",
"\"filter_{$filtername}\"",
";",
"$",
"newvalue",
"=",
"$",
"data",
"->",
"$",
"key",
";",
"if",
"(",
"empty",
"(",
"$",
"data",
"->",
"$",
"key",
")",
")",
"{",
"$",
"newvalue",
"=",
"[",
"]",
";",
"}",
"$",
"tour",
"->",
"set_filter_values",
"(",
"$",
"filtername",
",",
"$",
"newvalue",
")",
";",
"}"
] | Overrides the base save the filter values from the form to the tour.
@param tour $tour The tour to save values to
@param stdClass $data The data submitted in the form | [
"Overrides",
"the",
"base",
"save",
"the",
"filter",
"values",
"from",
"the",
"form",
"to",
"the",
"tour",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/local/filter/course.php#L108-L116 |
211,799 | moodle/moodle | mod/forum/locallib.php | forum_portfolio_caller.prepare_package | function prepare_package() {
global $CFG;
// set up the leap2a writer if we need it
$writingleap = false;
if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) {
$leapwriter = $this->exporter->get('format')->leap2a_writer();
$writingleap = true;
}
if ($this->attachment) { // simplest case first - single file attachment
$this->copy_files(array($this->singlefile), $this->attachment);
if ($writingleap) { // if we're writing leap, make the manifest to go along with the file
$entry = new portfolio_format_leap2a_file($this->singlefile->get_filename(), $this->singlefile);
$leapwriter->add_entry($entry);
return $this->exporter->write_new_file($leapwriter->to_xml(), $this->exporter->get('format')->manifest_name(), true);
}
} else if (empty($this->post)) { // exporting whole discussion
$content = ''; // if we're just writing HTML, start a string to add each post to
$ids = array(); // if we're writing leap2a, keep track of all entryids so we can add a selection element
foreach ($this->posts as $post) {
$posthtml = $this->prepare_post($post);
if ($writingleap) {
$ids[] = $this->prepare_post_leap2a($leapwriter, $post, $posthtml);
} else {
$content .= $posthtml . '<br /><br />';
}
}
$this->copy_files($this->multifiles);
$name = 'discussion.html';
$manifest = ($this->exporter->get('format') instanceof PORTFOLIO_FORMAT_RICH);
if ($writingleap) {
// add on an extra 'selection' entry
$selection = new portfolio_format_leap2a_entry('forumdiscussion' . $this->discussionid,
get_string('discussion', 'forum') . ': ' . $this->discussion->name, 'selection');
$leapwriter->add_entry($selection);
$leapwriter->make_selection($selection, $ids, 'Grouping');
$content = $leapwriter->to_xml();
$name = $this->get('exporter')->get('format')->manifest_name();
}
$this->get('exporter')->write_new_file($content, $name, $manifest);
} else { // exporting a single post
$posthtml = $this->prepare_post($this->post);
$content = $posthtml;
$name = 'post.html';
$manifest = ($this->exporter->get('format') instanceof PORTFOLIO_FORMAT_RICH);
if ($writingleap) {
$this->prepare_post_leap2a($leapwriter, $this->post, $posthtml);
$content = $leapwriter->to_xml();
$name = $this->exporter->get('format')->manifest_name();
}
$this->copy_files($this->multifiles);
$this->get('exporter')->write_new_file($content, $name, $manifest);
}
} | php | function prepare_package() {
global $CFG;
// set up the leap2a writer if we need it
$writingleap = false;
if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) {
$leapwriter = $this->exporter->get('format')->leap2a_writer();
$writingleap = true;
}
if ($this->attachment) { // simplest case first - single file attachment
$this->copy_files(array($this->singlefile), $this->attachment);
if ($writingleap) { // if we're writing leap, make the manifest to go along with the file
$entry = new portfolio_format_leap2a_file($this->singlefile->get_filename(), $this->singlefile);
$leapwriter->add_entry($entry);
return $this->exporter->write_new_file($leapwriter->to_xml(), $this->exporter->get('format')->manifest_name(), true);
}
} else if (empty($this->post)) { // exporting whole discussion
$content = ''; // if we're just writing HTML, start a string to add each post to
$ids = array(); // if we're writing leap2a, keep track of all entryids so we can add a selection element
foreach ($this->posts as $post) {
$posthtml = $this->prepare_post($post);
if ($writingleap) {
$ids[] = $this->prepare_post_leap2a($leapwriter, $post, $posthtml);
} else {
$content .= $posthtml . '<br /><br />';
}
}
$this->copy_files($this->multifiles);
$name = 'discussion.html';
$manifest = ($this->exporter->get('format') instanceof PORTFOLIO_FORMAT_RICH);
if ($writingleap) {
// add on an extra 'selection' entry
$selection = new portfolio_format_leap2a_entry('forumdiscussion' . $this->discussionid,
get_string('discussion', 'forum') . ': ' . $this->discussion->name, 'selection');
$leapwriter->add_entry($selection);
$leapwriter->make_selection($selection, $ids, 'Grouping');
$content = $leapwriter->to_xml();
$name = $this->get('exporter')->get('format')->manifest_name();
}
$this->get('exporter')->write_new_file($content, $name, $manifest);
} else { // exporting a single post
$posthtml = $this->prepare_post($this->post);
$content = $posthtml;
$name = 'post.html';
$manifest = ($this->exporter->get('format') instanceof PORTFOLIO_FORMAT_RICH);
if ($writingleap) {
$this->prepare_post_leap2a($leapwriter, $this->post, $posthtml);
$content = $leapwriter->to_xml();
$name = $this->exporter->get('format')->manifest_name();
}
$this->copy_files($this->multifiles);
$this->get('exporter')->write_new_file($content, $name, $manifest);
}
} | [
"function",
"prepare_package",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"// set up the leap2a writer if we need it",
"$",
"writingleap",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"exporter",
"->",
"get",
"(",
"'formatclass'",
")",
"==",
"PORTFOLIO_FORMAT_LEAP2A",
")",
"{",
"$",
"leapwriter",
"=",
"$",
"this",
"->",
"exporter",
"->",
"get",
"(",
"'format'",
")",
"->",
"leap2a_writer",
"(",
")",
";",
"$",
"writingleap",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"attachment",
")",
"{",
"// simplest case first - single file attachment",
"$",
"this",
"->",
"copy_files",
"(",
"array",
"(",
"$",
"this",
"->",
"singlefile",
")",
",",
"$",
"this",
"->",
"attachment",
")",
";",
"if",
"(",
"$",
"writingleap",
")",
"{",
"// if we're writing leap, make the manifest to go along with the file",
"$",
"entry",
"=",
"new",
"portfolio_format_leap2a_file",
"(",
"$",
"this",
"->",
"singlefile",
"->",
"get_filename",
"(",
")",
",",
"$",
"this",
"->",
"singlefile",
")",
";",
"$",
"leapwriter",
"->",
"add_entry",
"(",
"$",
"entry",
")",
";",
"return",
"$",
"this",
"->",
"exporter",
"->",
"write_new_file",
"(",
"$",
"leapwriter",
"->",
"to_xml",
"(",
")",
",",
"$",
"this",
"->",
"exporter",
"->",
"get",
"(",
"'format'",
")",
"->",
"manifest_name",
"(",
")",
",",
"true",
")",
";",
"}",
"}",
"else",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"post",
")",
")",
"{",
"// exporting whole discussion",
"$",
"content",
"=",
"''",
";",
"// if we're just writing HTML, start a string to add each post to",
"$",
"ids",
"=",
"array",
"(",
")",
";",
"// if we're writing leap2a, keep track of all entryids so we can add a selection element",
"foreach",
"(",
"$",
"this",
"->",
"posts",
"as",
"$",
"post",
")",
"{",
"$",
"posthtml",
"=",
"$",
"this",
"->",
"prepare_post",
"(",
"$",
"post",
")",
";",
"if",
"(",
"$",
"writingleap",
")",
"{",
"$",
"ids",
"[",
"]",
"=",
"$",
"this",
"->",
"prepare_post_leap2a",
"(",
"$",
"leapwriter",
",",
"$",
"post",
",",
"$",
"posthtml",
")",
";",
"}",
"else",
"{",
"$",
"content",
".=",
"$",
"posthtml",
".",
"'<br /><br />'",
";",
"}",
"}",
"$",
"this",
"->",
"copy_files",
"(",
"$",
"this",
"->",
"multifiles",
")",
";",
"$",
"name",
"=",
"'discussion.html'",
";",
"$",
"manifest",
"=",
"(",
"$",
"this",
"->",
"exporter",
"->",
"get",
"(",
"'format'",
")",
"instanceof",
"PORTFOLIO_FORMAT_RICH",
")",
";",
"if",
"(",
"$",
"writingleap",
")",
"{",
"// add on an extra 'selection' entry",
"$",
"selection",
"=",
"new",
"portfolio_format_leap2a_entry",
"(",
"'forumdiscussion'",
".",
"$",
"this",
"->",
"discussionid",
",",
"get_string",
"(",
"'discussion'",
",",
"'forum'",
")",
".",
"': '",
".",
"$",
"this",
"->",
"discussion",
"->",
"name",
",",
"'selection'",
")",
";",
"$",
"leapwriter",
"->",
"add_entry",
"(",
"$",
"selection",
")",
";",
"$",
"leapwriter",
"->",
"make_selection",
"(",
"$",
"selection",
",",
"$",
"ids",
",",
"'Grouping'",
")",
";",
"$",
"content",
"=",
"$",
"leapwriter",
"->",
"to_xml",
"(",
")",
";",
"$",
"name",
"=",
"$",
"this",
"->",
"get",
"(",
"'exporter'",
")",
"->",
"get",
"(",
"'format'",
")",
"->",
"manifest_name",
"(",
")",
";",
"}",
"$",
"this",
"->",
"get",
"(",
"'exporter'",
")",
"->",
"write_new_file",
"(",
"$",
"content",
",",
"$",
"name",
",",
"$",
"manifest",
")",
";",
"}",
"else",
"{",
"// exporting a single post",
"$",
"posthtml",
"=",
"$",
"this",
"->",
"prepare_post",
"(",
"$",
"this",
"->",
"post",
")",
";",
"$",
"content",
"=",
"$",
"posthtml",
";",
"$",
"name",
"=",
"'post.html'",
";",
"$",
"manifest",
"=",
"(",
"$",
"this",
"->",
"exporter",
"->",
"get",
"(",
"'format'",
")",
"instanceof",
"PORTFOLIO_FORMAT_RICH",
")",
";",
"if",
"(",
"$",
"writingleap",
")",
"{",
"$",
"this",
"->",
"prepare_post_leap2a",
"(",
"$",
"leapwriter",
",",
"$",
"this",
"->",
"post",
",",
"$",
"posthtml",
")",
";",
"$",
"content",
"=",
"$",
"leapwriter",
"->",
"to_xml",
"(",
")",
";",
"$",
"name",
"=",
"$",
"this",
"->",
"exporter",
"->",
"get",
"(",
"'format'",
")",
"->",
"manifest_name",
"(",
")",
";",
"}",
"$",
"this",
"->",
"copy_files",
"(",
"$",
"this",
"->",
"multifiles",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'exporter'",
")",
"->",
"write_new_file",
"(",
"$",
"content",
",",
"$",
"name",
",",
"$",
"manifest",
")",
";",
"}",
"}"
] | either a whole discussion
a single post, with or without attachment
or just an attachment with no post
@global object
@global object
@uses PORTFOLIO_FORMAT_RICH
@return mixed | [
"either",
"a",
"whole",
"discussion",
"a",
"single",
"post",
"with",
"or",
"without",
"attachment",
"or",
"just",
"an",
"attachment",
"with",
"no",
"post"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/locallib.php#L184-L241 |
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.