id int32 0 241k | repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 |
|---|---|---|---|---|---|---|---|---|---|---|---|
210,600 | cakephp/cakephp | src/Utility/Xml.php | Xml.toArray | public static function toArray($obj)
{
if ($obj instanceof DOMNode) {
$obj = simplexml_import_dom($obj);
}
if (!($obj instanceof SimpleXMLElement)) {
throw new XmlException('The input is not instance of SimpleXMLElement, DOMDocument or DOMNode.');
}
$result = [];
$namespaces = array_merge(['' => ''], $obj->getNamespaces(true));
static::_toArray($obj, $result, '', array_keys($namespaces));
return $result;
} | php | public static function toArray($obj)
{
if ($obj instanceof DOMNode) {
$obj = simplexml_import_dom($obj);
}
if (!($obj instanceof SimpleXMLElement)) {
throw new XmlException('The input is not instance of SimpleXMLElement, DOMDocument or DOMNode.');
}
$result = [];
$namespaces = array_merge(['' => ''], $obj->getNamespaces(true));
static::_toArray($obj, $result, '', array_keys($namespaces));
return $result;
} | [
"public",
"static",
"function",
"toArray",
"(",
"$",
"obj",
")",
"{",
"if",
"(",
"$",
"obj",
"instanceof",
"DOMNode",
")",
"{",
"$",
"obj",
"=",
"simplexml_import_dom",
"(",
"$",
"obj",
")",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"obj",
"instanceof",
"SimpleXMLElement",
")",
")",
"{",
"throw",
"new",
"XmlException",
"(",
"'The input is not instance of SimpleXMLElement, DOMDocument or DOMNode.'",
")",
";",
"}",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"namespaces",
"=",
"array_merge",
"(",
"[",
"''",
"=>",
"''",
"]",
",",
"$",
"obj",
"->",
"getNamespaces",
"(",
"true",
")",
")",
";",
"static",
"::",
"_toArray",
"(",
"$",
"obj",
",",
"$",
"result",
",",
"''",
",",
"array_keys",
"(",
"$",
"namespaces",
")",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Returns this XML structure as an array.
@param \SimpleXMLElement|\DOMDocument|\DOMNode $obj SimpleXMLElement, DOMDocument or DOMNode instance
@return array Array representation of the XML structure.
@throws \Cake\Utility\Exception\XmlException | [
"Returns",
"this",
"XML",
"structure",
"as",
"an",
"array",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/Xml.php#L425-L438 |
210,601 | cakephp/cakephp | src/Utility/Xml.php | Xml._toArray | protected static function _toArray($xml, &$parentData, $ns, $namespaces)
{
$data = [];
foreach ($namespaces as $namespace) {
foreach ($xml->attributes($namespace, true) as $key => $value) {
if (!empty($namespace)) {
$key = $namespace . ':' . $key;
}
$data['@' . $key] = (string)$value;
}
foreach ($xml->children($namespace, true) as $child) {
static::_toArray($child, $data, $namespace, $namespaces);
}
}
$asString = trim((string)$xml);
if (empty($data)) {
$data = $asString;
} elseif (strlen($asString) > 0) {
$data['@'] = $asString;
}
if (!empty($ns)) {
$ns .= ':';
}
$name = $ns . $xml->getName();
if (isset($parentData[$name])) {
if (!is_array($parentData[$name]) || !isset($parentData[$name][0])) {
$parentData[$name] = [$parentData[$name]];
}
$parentData[$name][] = $data;
} else {
$parentData[$name] = $data;
}
} | php | protected static function _toArray($xml, &$parentData, $ns, $namespaces)
{
$data = [];
foreach ($namespaces as $namespace) {
foreach ($xml->attributes($namespace, true) as $key => $value) {
if (!empty($namespace)) {
$key = $namespace . ':' . $key;
}
$data['@' . $key] = (string)$value;
}
foreach ($xml->children($namespace, true) as $child) {
static::_toArray($child, $data, $namespace, $namespaces);
}
}
$asString = trim((string)$xml);
if (empty($data)) {
$data = $asString;
} elseif (strlen($asString) > 0) {
$data['@'] = $asString;
}
if (!empty($ns)) {
$ns .= ':';
}
$name = $ns . $xml->getName();
if (isset($parentData[$name])) {
if (!is_array($parentData[$name]) || !isset($parentData[$name][0])) {
$parentData[$name] = [$parentData[$name]];
}
$parentData[$name][] = $data;
} else {
$parentData[$name] = $data;
}
} | [
"protected",
"static",
"function",
"_toArray",
"(",
"$",
"xml",
",",
"&",
"$",
"parentData",
",",
"$",
"ns",
",",
"$",
"namespaces",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"namespaces",
"as",
"$",
"namespace",
")",
"{",
"foreach",
"(",
"$",
"xml",
"->",
"attributes",
"(",
"$",
"namespace",
",",
"true",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"namespace",
")",
")",
"{",
"$",
"key",
"=",
"$",
"namespace",
".",
"':'",
".",
"$",
"key",
";",
"}",
"$",
"data",
"[",
"'@'",
".",
"$",
"key",
"]",
"=",
"(",
"string",
")",
"$",
"value",
";",
"}",
"foreach",
"(",
"$",
"xml",
"->",
"children",
"(",
"$",
"namespace",
",",
"true",
")",
"as",
"$",
"child",
")",
"{",
"static",
"::",
"_toArray",
"(",
"$",
"child",
",",
"$",
"data",
",",
"$",
"namespace",
",",
"$",
"namespaces",
")",
";",
"}",
"}",
"$",
"asString",
"=",
"trim",
"(",
"(",
"string",
")",
"$",
"xml",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"$",
"asString",
";",
"}",
"elseif",
"(",
"strlen",
"(",
"$",
"asString",
")",
">",
"0",
")",
"{",
"$",
"data",
"[",
"'@'",
"]",
"=",
"$",
"asString",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"ns",
")",
")",
"{",
"$",
"ns",
".=",
"':'",
";",
"}",
"$",
"name",
"=",
"$",
"ns",
".",
"$",
"xml",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"parentData",
"[",
"$",
"name",
"]",
")",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"parentData",
"[",
"$",
"name",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"parentData",
"[",
"$",
"name",
"]",
"[",
"0",
"]",
")",
")",
"{",
"$",
"parentData",
"[",
"$",
"name",
"]",
"=",
"[",
"$",
"parentData",
"[",
"$",
"name",
"]",
"]",
";",
"}",
"$",
"parentData",
"[",
"$",
"name",
"]",
"[",
"]",
"=",
"$",
"data",
";",
"}",
"else",
"{",
"$",
"parentData",
"[",
"$",
"name",
"]",
"=",
"$",
"data",
";",
"}",
"}"
] | Recursive method to toArray
@param \SimpleXMLElement $xml SimpleXMLElement object
@param array $parentData Parent array with data
@param string $ns Namespace of current child
@param array $namespaces List of namespaces in XML
@return void | [
"Recursive",
"method",
"to",
"toArray"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/Xml.php#L449-L485 |
210,602 | cakephp/cakephp | src/Collection/Iterator/TreeIterator.php | TreeIterator.printer | public function printer($valuePath, $keyPath = null, $spacer = '__')
{
if (!$keyPath) {
$counter = 0;
$keyPath = function () use (&$counter) {
return $counter++;
};
}
return new TreePrinter(
$this->getInnerIterator(),
$valuePath,
$keyPath,
$spacer,
$this->_mode
);
} | php | public function printer($valuePath, $keyPath = null, $spacer = '__')
{
if (!$keyPath) {
$counter = 0;
$keyPath = function () use (&$counter) {
return $counter++;
};
}
return new TreePrinter(
$this->getInnerIterator(),
$valuePath,
$keyPath,
$spacer,
$this->_mode
);
} | [
"public",
"function",
"printer",
"(",
"$",
"valuePath",
",",
"$",
"keyPath",
"=",
"null",
",",
"$",
"spacer",
"=",
"'__'",
")",
"{",
"if",
"(",
"!",
"$",
"keyPath",
")",
"{",
"$",
"counter",
"=",
"0",
";",
"$",
"keyPath",
"=",
"function",
"(",
")",
"use",
"(",
"&",
"$",
"counter",
")",
"{",
"return",
"$",
"counter",
"++",
";",
"}",
";",
"}",
"return",
"new",
"TreePrinter",
"(",
"$",
"this",
"->",
"getInnerIterator",
"(",
")",
",",
"$",
"valuePath",
",",
"$",
"keyPath",
",",
"$",
"spacer",
",",
"$",
"this",
"->",
"_mode",
")",
";",
"}"
] | Returns another iterator which will return the values ready to be displayed
to a user. It does so by extracting one property from each of the elements
and prefixing it with a spacer so that the relative position in the tree
can be visualized.
Both $valuePath and $keyPath can be a string with a property name to extract
or a dot separated path of properties that should be followed to get the last
one in the path.
Alternatively, $valuePath and $keyPath can be callable functions. They will get
the current element as first parameter, the current iteration key as second
parameter, and the iterator instance as third argument.
### Example
```
$printer = (new Collection($treeStructure))->listNested()->printer('name');
```
Using a closure:
```
$printer = (new Collection($treeStructure))
->listNested()
->printer(function ($item, $key, $iterator) {
return $item->name;
});
```
@param string|callable $valuePath The property to extract or a callable to return
the display value
@param string|callable|null $keyPath The property to use as iteration key or a
callable returning the key value.
@param string $spacer The string to use for prefixing the values according to
their depth in the tree
@return \Cake\Collection\Iterator\TreePrinter | [
"Returns",
"another",
"iterator",
"which",
"will",
"return",
"the",
"values",
"ready",
"to",
"be",
"displayed",
"to",
"a",
"user",
".",
"It",
"does",
"so",
"by",
"extracting",
"one",
"property",
"from",
"each",
"of",
"the",
"elements",
"and",
"prefixing",
"it",
"with",
"a",
"spacer",
"so",
"that",
"the",
"relative",
"position",
"in",
"the",
"tree",
"can",
"be",
"visualized",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Collection/Iterator/TreeIterator.php#L88-L104 |
210,603 | cakephp/cakephp | src/Validation/Validator.php | Validator.errors | public function errors(array $data, $newRecord = true)
{
$errors = [];
foreach ($this->_fields as $name => $field) {
$keyPresent = array_key_exists($name, $data);
$providers = $this->_providers;
$context = compact('data', 'newRecord', 'field', 'providers');
if (!$keyPresent && !$this->_checkPresence($field, $context)) {
$errors[$name]['_required'] = $this->getRequiredMessage($name);
continue;
}
if (!$keyPresent) {
continue;
}
$canBeEmpty = $this->_canBeEmpty($field, $context);
$flags = static::EMPTY_ALL;
if (isset($this->_allowEmptyFlags[$name])) {
$flags = $this->_allowEmptyFlags[$name];
}
$isEmpty = $this->isEmpty($data[$name], $flags);
if (!$canBeEmpty && $isEmpty) {
$errors[$name]['_empty'] = $this->getNotEmptyMessage($name);
continue;
}
if ($isEmpty) {
continue;
}
$result = $this->_processRules($name, $field, $data, $newRecord);
if ($result) {
$errors[$name] = $result;
}
}
return $errors;
} | php | public function errors(array $data, $newRecord = true)
{
$errors = [];
foreach ($this->_fields as $name => $field) {
$keyPresent = array_key_exists($name, $data);
$providers = $this->_providers;
$context = compact('data', 'newRecord', 'field', 'providers');
if (!$keyPresent && !$this->_checkPresence($field, $context)) {
$errors[$name]['_required'] = $this->getRequiredMessage($name);
continue;
}
if (!$keyPresent) {
continue;
}
$canBeEmpty = $this->_canBeEmpty($field, $context);
$flags = static::EMPTY_ALL;
if (isset($this->_allowEmptyFlags[$name])) {
$flags = $this->_allowEmptyFlags[$name];
}
$isEmpty = $this->isEmpty($data[$name], $flags);
if (!$canBeEmpty && $isEmpty) {
$errors[$name]['_empty'] = $this->getNotEmptyMessage($name);
continue;
}
if ($isEmpty) {
continue;
}
$result = $this->_processRules($name, $field, $data, $newRecord);
if ($result) {
$errors[$name] = $result;
}
}
return $errors;
} | [
"public",
"function",
"errors",
"(",
"array",
"$",
"data",
",",
"$",
"newRecord",
"=",
"true",
")",
"{",
"$",
"errors",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_fields",
"as",
"$",
"name",
"=>",
"$",
"field",
")",
"{",
"$",
"keyPresent",
"=",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"data",
")",
";",
"$",
"providers",
"=",
"$",
"this",
"->",
"_providers",
";",
"$",
"context",
"=",
"compact",
"(",
"'data'",
",",
"'newRecord'",
",",
"'field'",
",",
"'providers'",
")",
";",
"if",
"(",
"!",
"$",
"keyPresent",
"&&",
"!",
"$",
"this",
"->",
"_checkPresence",
"(",
"$",
"field",
",",
"$",
"context",
")",
")",
"{",
"$",
"errors",
"[",
"$",
"name",
"]",
"[",
"'_required'",
"]",
"=",
"$",
"this",
"->",
"getRequiredMessage",
"(",
"$",
"name",
")",
";",
"continue",
";",
"}",
"if",
"(",
"!",
"$",
"keyPresent",
")",
"{",
"continue",
";",
"}",
"$",
"canBeEmpty",
"=",
"$",
"this",
"->",
"_canBeEmpty",
"(",
"$",
"field",
",",
"$",
"context",
")",
";",
"$",
"flags",
"=",
"static",
"::",
"EMPTY_ALL",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_allowEmptyFlags",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"flags",
"=",
"$",
"this",
"->",
"_allowEmptyFlags",
"[",
"$",
"name",
"]",
";",
"}",
"$",
"isEmpty",
"=",
"$",
"this",
"->",
"isEmpty",
"(",
"$",
"data",
"[",
"$",
"name",
"]",
",",
"$",
"flags",
")",
";",
"if",
"(",
"!",
"$",
"canBeEmpty",
"&&",
"$",
"isEmpty",
")",
"{",
"$",
"errors",
"[",
"$",
"name",
"]",
"[",
"'_empty'",
"]",
"=",
"$",
"this",
"->",
"getNotEmptyMessage",
"(",
"$",
"name",
")",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"isEmpty",
")",
"{",
"continue",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"_processRules",
"(",
"$",
"name",
",",
"$",
"field",
",",
"$",
"data",
",",
"$",
"newRecord",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"$",
"errors",
"[",
"$",
"name",
"]",
"=",
"$",
"result",
";",
"}",
"}",
"return",
"$",
"errors",
";",
"}"
] | Returns an array of fields that have failed validation. On the current model. This method will
actually run validation rules over data, not just return the messages.
@param array $data The data to be checked for errors
@param bool $newRecord whether the data to be validated is new or to be updated.
@return array Array of invalid fields | [
"Returns",
"an",
"array",
"of",
"fields",
"that",
"have",
"failed",
"validation",
".",
"On",
"the",
"current",
"model",
".",
"This",
"method",
"will",
"actually",
"run",
"validation",
"rules",
"over",
"data",
"not",
"just",
"return",
"the",
"messages",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L166-L209 |
210,604 | cakephp/cakephp | src/Validation/Validator.php | Validator.field | public function field($name, ValidationSet $set = null)
{
if (empty($this->_fields[$name])) {
$set = $set ?: new ValidationSet();
$this->_fields[$name] = $set;
}
return $this->_fields[$name];
} | php | public function field($name, ValidationSet $set = null)
{
if (empty($this->_fields[$name])) {
$set = $set ?: new ValidationSet();
$this->_fields[$name] = $set;
}
return $this->_fields[$name];
} | [
"public",
"function",
"field",
"(",
"$",
"name",
",",
"ValidationSet",
"$",
"set",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_fields",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"set",
"=",
"$",
"set",
"?",
":",
"new",
"ValidationSet",
"(",
")",
";",
"$",
"this",
"->",
"_fields",
"[",
"$",
"name",
"]",
"=",
"$",
"set",
";",
"}",
"return",
"$",
"this",
"->",
"_fields",
"[",
"$",
"name",
"]",
";",
"}"
] | Returns a ValidationSet object containing all validation rules for a field, if
passed a ValidationSet as second argument, it will replace any other rule set defined
before
@param string $name [optional] The fieldname to fetch.
@param \Cake\Validation\ValidationSet|null $set The set of rules for field
@return \Cake\Validation\ValidationSet | [
"Returns",
"a",
"ValidationSet",
"object",
"containing",
"all",
"validation",
"rules",
"for",
"a",
"field",
"if",
"passed",
"a",
"ValidationSet",
"as",
"second",
"argument",
"it",
"will",
"replace",
"any",
"other",
"rule",
"set",
"defined",
"before"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L220-L228 |
210,605 | cakephp/cakephp | src/Validation/Validator.php | Validator.getProvider | public function getProvider($name)
{
if (isset($this->_providers[$name])) {
return $this->_providers[$name];
}
if ($name !== 'default') {
return null;
}
$this->_providers[$name] = new RulesProvider();
return $this->_providers[$name];
} | php | public function getProvider($name)
{
if (isset($this->_providers[$name])) {
return $this->_providers[$name];
}
if ($name !== 'default') {
return null;
}
$this->_providers[$name] = new RulesProvider();
return $this->_providers[$name];
} | [
"public",
"function",
"getProvider",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_providers",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_providers",
"[",
"$",
"name",
"]",
";",
"}",
"if",
"(",
"$",
"name",
"!==",
"'default'",
")",
"{",
"return",
"null",
";",
"}",
"$",
"this",
"->",
"_providers",
"[",
"$",
"name",
"]",
"=",
"new",
"RulesProvider",
"(",
")",
";",
"return",
"$",
"this",
"->",
"_providers",
"[",
"$",
"name",
"]",
";",
"}"
] | Returns the provider stored under that name if it exists.
@param string $name The name under which the provider should be set.
@return object|string|null
@throws \ReflectionException | [
"Returns",
"the",
"provider",
"stored",
"under",
"that",
"name",
"if",
"it",
"exists",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L265-L277 |
210,606 | cakephp/cakephp | src/Validation/Validator.php | Validator.getDefaultProvider | public static function getDefaultProvider($name)
{
if (!isset(self::$_defaultProviders[$name])) {
return null;
}
return self::$_defaultProviders[$name];
} | php | public static function getDefaultProvider($name)
{
if (!isset(self::$_defaultProviders[$name])) {
return null;
}
return self::$_defaultProviders[$name];
} | [
"public",
"static",
"function",
"getDefaultProvider",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"_defaultProviders",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"self",
"::",
"$",
"_defaultProviders",
"[",
"$",
"name",
"]",
";",
"}"
] | Returns the default provider stored under that name if it exists.
@param string $name The name under which the provider should be retrieved.
@return object|string|null | [
"Returns",
"the",
"default",
"provider",
"stored",
"under",
"that",
"name",
"if",
"it",
"exists",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L285-L292 |
210,607 | cakephp/cakephp | src/Validation/Validator.php | Validator.provider | public function provider($name, $object = null)
{
deprecationWarning(
'Validator::provider() is deprecated. ' .
'Use Validator::setProvider()/getProvider() instead.'
);
if ($object !== null) {
return $this->setProvider($name, $object);
}
return $this->getProvider($name);
} | php | public function provider($name, $object = null)
{
deprecationWarning(
'Validator::provider() is deprecated. ' .
'Use Validator::setProvider()/getProvider() instead.'
);
if ($object !== null) {
return $this->setProvider($name, $object);
}
return $this->getProvider($name);
} | [
"public",
"function",
"provider",
"(",
"$",
"name",
",",
"$",
"object",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"'Validator::provider() is deprecated. '",
".",
"'Use Validator::setProvider()/getProvider() instead.'",
")",
";",
"if",
"(",
"$",
"object",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"setProvider",
"(",
"$",
"name",
",",
"$",
"object",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getProvider",
"(",
"$",
"name",
")",
";",
"}"
] | Associates an object to a name so it can be used as a provider. Providers are
objects or class names that can contain methods used during validation of for
deciding whether a validation rule can be applied. All validation methods,
when called will receive the full list of providers stored in this validator.
If called with no arguments, it will return the provider stored under that name if
it exists, otherwise it returns this instance of chaining.
@deprecated 3.4.0 Use setProvider()/getProvider() instead.
@param string $name The name under which the provider should be set.
@param null|object|string $object Provider object or class name.
@return $this|object|string|null | [
"Associates",
"an",
"object",
"to",
"a",
"name",
"so",
"it",
"can",
"be",
"used",
"as",
"a",
"provider",
".",
"Providers",
"are",
"objects",
"or",
"class",
"names",
"that",
"can",
"contain",
"methods",
"used",
"during",
"validation",
"of",
"for",
"deciding",
"whether",
"a",
"validation",
"rule",
"can",
"be",
"applied",
".",
"All",
"validation",
"methods",
"when",
"called",
"will",
"receive",
"the",
"full",
"list",
"of",
"providers",
"stored",
"in",
"this",
"validator",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L330-L341 |
210,608 | cakephp/cakephp | src/Validation/Validator.php | Validator.offsetSet | public function offsetSet($field, $rules)
{
if (!$rules instanceof ValidationSet) {
$set = new ValidationSet();
foreach ((array)$rules as $name => $rule) {
$set->add($name, $rule);
}
}
$this->_fields[$field] = $rules;
} | php | public function offsetSet($field, $rules)
{
if (!$rules instanceof ValidationSet) {
$set = new ValidationSet();
foreach ((array)$rules as $name => $rule) {
$set->add($name, $rule);
}
}
$this->_fields[$field] = $rules;
} | [
"public",
"function",
"offsetSet",
"(",
"$",
"field",
",",
"$",
"rules",
")",
"{",
"if",
"(",
"!",
"$",
"rules",
"instanceof",
"ValidationSet",
")",
"{",
"$",
"set",
"=",
"new",
"ValidationSet",
"(",
")",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"rules",
"as",
"$",
"name",
"=>",
"$",
"rule",
")",
"{",
"$",
"set",
"->",
"add",
"(",
"$",
"name",
",",
"$",
"rule",
")",
";",
"}",
"}",
"$",
"this",
"->",
"_fields",
"[",
"$",
"field",
"]",
"=",
"$",
"rules",
";",
"}"
] | Sets the rule set for a field
@param string $field name of the field to set
@param array|\Cake\Validation\ValidationSet $rules set of rules to apply to field
@return void | [
"Sets",
"the",
"rule",
"set",
"for",
"a",
"field"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L382-L391 |
210,609 | cakephp/cakephp | src/Validation/Validator.php | Validator.add | public function add($field, $name, $rule = [])
{
$validationSet = $this->field($field);
if (!is_array($name)) {
$rules = [$name => $rule];
} else {
$rules = $name;
}
foreach ($rules as $name => $rule) {
if (is_array($rule)) {
$rule += ['rule' => $name];
}
$validationSet->add($name, $rule);
}
return $this;
} | php | public function add($field, $name, $rule = [])
{
$validationSet = $this->field($field);
if (!is_array($name)) {
$rules = [$name => $rule];
} else {
$rules = $name;
}
foreach ($rules as $name => $rule) {
if (is_array($rule)) {
$rule += ['rule' => $name];
}
$validationSet->add($name, $rule);
}
return $this;
} | [
"public",
"function",
"add",
"(",
"$",
"field",
",",
"$",
"name",
",",
"$",
"rule",
"=",
"[",
"]",
")",
"{",
"$",
"validationSet",
"=",
"$",
"this",
"->",
"field",
"(",
"$",
"field",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"name",
")",
")",
"{",
"$",
"rules",
"=",
"[",
"$",
"name",
"=>",
"$",
"rule",
"]",
";",
"}",
"else",
"{",
"$",
"rules",
"=",
"$",
"name",
";",
"}",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"name",
"=>",
"$",
"rule",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"rule",
")",
")",
"{",
"$",
"rule",
"+=",
"[",
"'rule'",
"=>",
"$",
"name",
"]",
";",
"}",
"$",
"validationSet",
"->",
"add",
"(",
"$",
"name",
",",
"$",
"rule",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Adds a new rule to a field's rule set. If second argument is an array
then rules list for the field will be replaced with second argument and
third argument will be ignored.
### Example:
```
$validator
->add('title', 'required', ['rule' => 'notBlank'])
->add('user_id', 'valid', ['rule' => 'numeric', 'message' => 'Invalid User'])
$validator->add('password', [
'size' => ['rule' => ['lengthBetween', 8, 20]],
'hasSpecialCharacter' => ['rule' => 'validateSpecialchar', 'message' => 'not valid']
]);
```
@param string $field The name of the field from which the rule will be added
@param array|string $name The alias for a single rule or multiple rules array
@param array|\Cake\Validation\ValidationRule $rule the rule to add
@return $this | [
"Adds",
"a",
"new",
"rule",
"to",
"a",
"field",
"s",
"rule",
"set",
".",
"If",
"second",
"argument",
"is",
"an",
"array",
"then",
"rules",
"list",
"for",
"the",
"field",
"will",
"be",
"replaced",
"with",
"second",
"argument",
"and",
"third",
"argument",
"will",
"be",
"ignored",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L447-L465 |
210,610 | cakephp/cakephp | src/Validation/Validator.php | Validator.addNested | public function addNested($field, Validator $validator, $message = null, $when = null)
{
$extra = array_filter(['message' => $message, 'on' => $when]);
$validationSet = $this->field($field);
$validationSet->add(static::NESTED, $extra + ['rule' => function ($value, $context) use ($validator, $message) {
if (!is_array($value)) {
return false;
}
foreach ($this->providers() as $provider) {
$validator->setProvider($provider, $this->getProvider($provider));
}
$errors = $validator->errors($value, $context['newRecord']);
$message = $message ? [static::NESTED => $message] : [];
return empty($errors) ? true : $errors + $message;
}]);
return $this;
} | php | public function addNested($field, Validator $validator, $message = null, $when = null)
{
$extra = array_filter(['message' => $message, 'on' => $when]);
$validationSet = $this->field($field);
$validationSet->add(static::NESTED, $extra + ['rule' => function ($value, $context) use ($validator, $message) {
if (!is_array($value)) {
return false;
}
foreach ($this->providers() as $provider) {
$validator->setProvider($provider, $this->getProvider($provider));
}
$errors = $validator->errors($value, $context['newRecord']);
$message = $message ? [static::NESTED => $message] : [];
return empty($errors) ? true : $errors + $message;
}]);
return $this;
} | [
"public",
"function",
"addNested",
"(",
"$",
"field",
",",
"Validator",
"$",
"validator",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'message'",
"=>",
"$",
"message",
",",
"'on'",
"=>",
"$",
"when",
"]",
")",
";",
"$",
"validationSet",
"=",
"$",
"this",
"->",
"field",
"(",
"$",
"field",
")",
";",
"$",
"validationSet",
"->",
"add",
"(",
"static",
"::",
"NESTED",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"function",
"(",
"$",
"value",
",",
"$",
"context",
")",
"use",
"(",
"$",
"validator",
",",
"$",
"message",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"providers",
"(",
")",
"as",
"$",
"provider",
")",
"{",
"$",
"validator",
"->",
"setProvider",
"(",
"$",
"provider",
",",
"$",
"this",
"->",
"getProvider",
"(",
"$",
"provider",
")",
")",
";",
"}",
"$",
"errors",
"=",
"$",
"validator",
"->",
"errors",
"(",
"$",
"value",
",",
"$",
"context",
"[",
"'newRecord'",
"]",
")",
";",
"$",
"message",
"=",
"$",
"message",
"?",
"[",
"static",
"::",
"NESTED",
"=>",
"$",
"message",
"]",
":",
"[",
"]",
";",
"return",
"empty",
"(",
"$",
"errors",
")",
"?",
"true",
":",
"$",
"errors",
"+",
"$",
"message",
";",
"}",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Adds a nested validator.
Nesting validators allows you to define validators for array
types. For example, nested validators are ideal when you want to validate a
sub-document, or complex array type.
This method assumes that the sub-document has a 1:1 relationship with the parent.
The providers of the parent validator will be synced into the nested validator, when
errors are checked. This ensures that any validation rule providers connected
in the parent will have the same values in the nested validator when rules are evaluated.
@param string $field The root field for the nested validator.
@param \Cake\Validation\Validator $validator The nested validator.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@return $this | [
"Adds",
"a",
"nested",
"validator",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L487-L507 |
210,611 | cakephp/cakephp | src/Validation/Validator.php | Validator.remove | public function remove($field, $rule = null)
{
if ($rule === null) {
unset($this->_fields[$field]);
} else {
$this->field($field)->remove($rule);
}
return $this;
} | php | public function remove($field, $rule = null)
{
if ($rule === null) {
unset($this->_fields[$field]);
} else {
$this->field($field)->remove($rule);
}
return $this;
} | [
"public",
"function",
"remove",
"(",
"$",
"field",
",",
"$",
"rule",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"rule",
"===",
"null",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"_fields",
"[",
"$",
"field",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"field",
"(",
"$",
"field",
")",
"->",
"remove",
"(",
"$",
"rule",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Removes a rule from the set by its name
### Example:
```
$validator
->remove('title', 'required')
->remove('user_id')
```
@param string $field The name of the field from which the rule will be removed
@param string|null $rule the name of the rule to be removed
@return $this | [
"Removes",
"a",
"rule",
"from",
"the",
"set",
"by",
"its",
"name"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L575-L584 |
210,612 | cakephp/cakephp | src/Validation/Validator.php | Validator.allowEmptyFor | public function allowEmptyFor($field, $flags, $when = true, $message = null)
{
$this->field($field)->allowEmpty($when);
if ($message) {
$this->_allowEmptyMessages[$field] = $message;
}
if ($flags !== null) {
$this->_allowEmptyFlags[$field] = $flags;
}
return $this;
} | php | public function allowEmptyFor($field, $flags, $when = true, $message = null)
{
$this->field($field)->allowEmpty($when);
if ($message) {
$this->_allowEmptyMessages[$field] = $message;
}
if ($flags !== null) {
$this->_allowEmptyFlags[$field] = $flags;
}
return $this;
} | [
"public",
"function",
"allowEmptyFor",
"(",
"$",
"field",
",",
"$",
"flags",
",",
"$",
"when",
"=",
"true",
",",
"$",
"message",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"field",
"(",
"$",
"field",
")",
"->",
"allowEmpty",
"(",
"$",
"when",
")",
";",
"if",
"(",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"_allowEmptyMessages",
"[",
"$",
"field",
"]",
"=",
"$",
"message",
";",
"}",
"if",
"(",
"$",
"flags",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"_allowEmptyFlags",
"[",
"$",
"field",
"]",
"=",
"$",
"flags",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Indicate that a field can be empty.
Using an array will let you provide the following keys:
- `flags` individual flags for field
- `when` individual when condition for field
- `message` individual message for field
You can also set flags, when and message for all passed fields, the individual
setting takes precedence over group settings.
### Example:
```
// Email can be empty
$validator->allowEmptyFor('email', Validator::EMPTY_STRING);
// Email can be empty on create
$validator->allowEmptyFor('email', Validator::EMPTY_STRING, 'create');
// Email can be empty on update
$validator->allowEmptyFor('email', Validator::EMPTY_STRING, 'update');
```
It is possible to conditionally allow emptiness on a field by passing a callback
as a second argument. The callback will receive the validation context array as
argument:
```
$validator->allowEmpty('email', Validator::EMPTY_STRING, function ($context) {
return !$context['newRecord'] || $context['data']['role'] === 'admin';
});
```
If you want to allow other kind of empty data on a field, you need to pass other
flags:
```
$validator->allowEmptyFor('photo', Validator::EMPTY_FILE);
$validator->allowEmptyFor('published', Validator::EMPTY_STRING | Validator::EMPTY_DATE | Validator::EMPTY_TIME);
$validator->allowEmptyFor('items', Validator::EMPTY_STRING | Validator::EMPTY_ARRAY);
```
You can also use convenience wrappers of this method. The following calls are the
same as above:
```
$validator->allowEmptyFile('photo');
$validator->allowEmptyDateTime('published');
$validator->allowEmptyArray('items');
```
@param string $field The name of the field.
@param int|null $flags A bitmask of EMPTY_* flags which specify what is empty
@param bool|string|callable $when Indicates when the field is allowed to be empty
Valid values are true, false, 'create', 'update'. If a callable is passed then
the field will allowed to be empty only when the callback returns true.
@param string|null $message The message to show if the field is not
@since 3.7.0
@return $this | [
"Indicate",
"that",
"a",
"field",
"can",
"be",
"empty",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L777-L788 |
210,613 | cakephp/cakephp | src/Validation/Validator.php | Validator.allowEmptyString | public function allowEmptyString($field, $when = true, $message = null)
{
return $this->allowEmptyFor($field, self::EMPTY_STRING, $when, $message);
} | php | public function allowEmptyString($field, $when = true, $message = null)
{
return $this->allowEmptyFor($field, self::EMPTY_STRING, $when, $message);
} | [
"public",
"function",
"allowEmptyString",
"(",
"$",
"field",
",",
"$",
"when",
"=",
"true",
",",
"$",
"message",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"allowEmptyFor",
"(",
"$",
"field",
",",
"self",
"::",
"EMPTY_STRING",
",",
"$",
"when",
",",
"$",
"message",
")",
";",
"}"
] | Allows a field to be an empty string.
This method is equivalent to calling allowEmptyFor() with EMPTY_STRING flag.
@param string $field The name of the field.
@param bool|string|callable $when Indicates when the field is allowed to be empty
Valid values are true, false, 'create', 'update'. If a callable is passed then
the field will allowed to be empty only when the callback returns true.
@param string|null $message The message to show if the field is not
@return $this
@since 3.7.0
@see \Cake\Validation\Validator::allowEmptyFor() For detail usage | [
"Allows",
"a",
"field",
"to",
"be",
"an",
"empty",
"string",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L804-L807 |
210,614 | cakephp/cakephp | src/Validation/Validator.php | Validator.allowEmptyArray | public function allowEmptyArray($field, $when = true, $message = null)
{
return $this->allowEmptyFor($field, self::EMPTY_STRING | self::EMPTY_ARRAY, $when, $message);
} | php | public function allowEmptyArray($field, $when = true, $message = null)
{
return $this->allowEmptyFor($field, self::EMPTY_STRING | self::EMPTY_ARRAY, $when, $message);
} | [
"public",
"function",
"allowEmptyArray",
"(",
"$",
"field",
",",
"$",
"when",
"=",
"true",
",",
"$",
"message",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"allowEmptyFor",
"(",
"$",
"field",
",",
"self",
"::",
"EMPTY_STRING",
"|",
"self",
"::",
"EMPTY_ARRAY",
",",
"$",
"when",
",",
"$",
"message",
")",
";",
"}"
] | Allows a field to be an empty array.
This method is equivalent to calling allowEmptyFor() with EMPTY_STRING +
EMPTY_ARRAY flags.
@param string $field The name of the field.
@param bool|string|callable $when Indicates when the field is allowed to be empty
Valid values are true, false, 'create', 'update'. If a callable is passed then
the field will allowed to be empty only when the callback returns true.
@param string|null $message The message to show if the field is not
@return $this
@since 3.7.0
@see \Cake\Validation\Validator::allowEmptyFor() For detail usage | [
"Allows",
"a",
"field",
"to",
"be",
"an",
"empty",
"array",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L824-L827 |
210,615 | cakephp/cakephp | src/Validation/Validator.php | Validator.allowEmptyFile | public function allowEmptyFile($field, $when = true, $message = null)
{
return $this->allowEmptyFor($field, self::EMPTY_FILE, $when, $message);
} | php | public function allowEmptyFile($field, $when = true, $message = null)
{
return $this->allowEmptyFor($field, self::EMPTY_FILE, $when, $message);
} | [
"public",
"function",
"allowEmptyFile",
"(",
"$",
"field",
",",
"$",
"when",
"=",
"true",
",",
"$",
"message",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"allowEmptyFor",
"(",
"$",
"field",
",",
"self",
"::",
"EMPTY_FILE",
",",
"$",
"when",
",",
"$",
"message",
")",
";",
"}"
] | Allows a field to be an empty file.
This method is equivalent to calling allowEmptyFor() with EMPTY_FILE flag.
@param string $field The name of the field.
@param bool|string|callable $when Indicates when the field is allowed to be empty
Valid values are true, false, 'create', 'update'. If a callable is passed then
the field will allowed to be empty only when the callback returns true.
@param string|null $message The message to show if the field is not
@return $this
@since 3.7.0
@see \Cake\Validation\Validator::allowEmptyFor() For detail usage | [
"Allows",
"a",
"field",
"to",
"be",
"an",
"empty",
"file",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L843-L846 |
210,616 | cakephp/cakephp | src/Validation/Validator.php | Validator.allowEmptyDate | public function allowEmptyDate($field, $when = true, $message = null)
{
return $this->allowEmptyFor($field, self::EMPTY_STRING | self::EMPTY_DATE, $when, $message);
} | php | public function allowEmptyDate($field, $when = true, $message = null)
{
return $this->allowEmptyFor($field, self::EMPTY_STRING | self::EMPTY_DATE, $when, $message);
} | [
"public",
"function",
"allowEmptyDate",
"(",
"$",
"field",
",",
"$",
"when",
"=",
"true",
",",
"$",
"message",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"allowEmptyFor",
"(",
"$",
"field",
",",
"self",
"::",
"EMPTY_STRING",
"|",
"self",
"::",
"EMPTY_DATE",
",",
"$",
"when",
",",
"$",
"message",
")",
";",
"}"
] | Allows a field to be an empty date.
This method is equivalent to calling allowEmptyFor() with EMPTY_STRING +
EMPTY_DATE flags.
@param string $field The name of the field.
@param bool|string|callable $when Indicates when the field is allowed to be empty
Valid values are true, false, 'create', 'update'. If a callable is passed then
the field will allowed to be empty only when the callback returns true.
@param string|null $message The message to show if the field is not
@return $this
@since 3.7.0
@see \Cake\Validation\Validator::allowEmptyFor() For detail usage | [
"Allows",
"a",
"field",
"to",
"be",
"an",
"empty",
"date",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L863-L866 |
210,617 | cakephp/cakephp | src/Validation/Validator.php | Validator.allowEmptyTime | public function allowEmptyTime($field, $when = true, $message = null)
{
return $this->allowEmptyFor($field, self::EMPTY_STRING | self::EMPTY_TIME, $when, $message);
} | php | public function allowEmptyTime($field, $when = true, $message = null)
{
return $this->allowEmptyFor($field, self::EMPTY_STRING | self::EMPTY_TIME, $when, $message);
} | [
"public",
"function",
"allowEmptyTime",
"(",
"$",
"field",
",",
"$",
"when",
"=",
"true",
",",
"$",
"message",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"allowEmptyFor",
"(",
"$",
"field",
",",
"self",
"::",
"EMPTY_STRING",
"|",
"self",
"::",
"EMPTY_TIME",
",",
"$",
"when",
",",
"$",
"message",
")",
";",
"}"
] | Allows a field to be an empty time.
This method is equivalent to calling allowEmptyFor() with EMPTY_STRING +
EMPTY_TIME flags.
@param string $field The name of the field.
@param bool|string|callable $when Indicates when the field is allowed to be empty
Valid values are true, false, 'create', 'update'. If a callable is passed then
the field will allowed to be empty only when the callback returns true.
@param string|null $message The message to show if the field is not
@return $this
@since 3.7.0
@see \Cake\Validation\Validator::allowEmptyFor() For detail usage | [
"Allows",
"a",
"field",
"to",
"be",
"an",
"empty",
"time",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L883-L886 |
210,618 | cakephp/cakephp | src/Validation/Validator.php | Validator.lengthBetween | public function lengthBetween($field, array $range, $message = null, $when = null)
{
if (count($range) !== 2) {
throw new InvalidArgumentException('The $range argument requires 2 numbers');
}
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'lengthBetween', $extra + [
'rule' => ['lengthBetween', array_shift($range), array_shift($range)],
]);
} | php | public function lengthBetween($field, array $range, $message = null, $when = null)
{
if (count($range) !== 2) {
throw new InvalidArgumentException('The $range argument requires 2 numbers');
}
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'lengthBetween', $extra + [
'rule' => ['lengthBetween', array_shift($range), array_shift($range)],
]);
} | [
"public",
"function",
"lengthBetween",
"(",
"$",
"field",
",",
"array",
"$",
"range",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"range",
")",
"!==",
"2",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The $range argument requires 2 numbers'",
")",
";",
"}",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'lengthBetween'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"[",
"'lengthBetween'",
",",
"array_shift",
"(",
"$",
"range",
")",
",",
"array_shift",
"(",
"$",
"range",
")",
"]",
",",
"]",
")",
";",
"}"
] | Add an rule that ensures a string length is within a range.
@param string $field The field you want to apply the rule to.
@param array $range The inclusive minimum and maximum length you want permitted.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::alphaNumeric()
@return $this | [
"Add",
"an",
"rule",
"that",
"ensures",
"a",
"string",
"length",
"is",
"within",
"a",
"range",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L1083-L1093 |
210,619 | cakephp/cakephp | src/Validation/Validator.php | Validator.creditCard | public function creditCard($field, $type = 'all', $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'creditCard', $extra + [
'rule' => ['creditCard', $type, true],
]);
} | php | public function creditCard($field, $type = 'all', $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'creditCard', $extra + [
'rule' => ['creditCard', $type, true],
]);
} | [
"public",
"function",
"creditCard",
"(",
"$",
"field",
",",
"$",
"type",
"=",
"'all'",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'creditCard'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"[",
"'creditCard'",
",",
"$",
"type",
",",
"true",
"]",
",",
"]",
")",
";",
"}"
] | Add a credit card rule to a field.
@param string $field The field you want to apply the rule to.
@param string $type The type of cards you want to allow. Defaults to 'all'.
You can also supply an array of accepted card types. e.g `['mastercard', 'visa', 'amex']`
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::creditCard()
@return $this | [
"Add",
"a",
"credit",
"card",
"rule",
"to",
"a",
"field",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L1107-L1114 |
210,620 | cakephp/cakephp | src/Validation/Validator.php | Validator.greaterThan | public function greaterThan($field, $value, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'greaterThan', $extra + [
'rule' => ['comparison', Validation::COMPARE_GREATER, $value]
]);
} | php | public function greaterThan($field, $value, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'greaterThan', $extra + [
'rule' => ['comparison', Validation::COMPARE_GREATER, $value]
]);
} | [
"public",
"function",
"greaterThan",
"(",
"$",
"field",
",",
"$",
"value",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'greaterThan'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"[",
"'comparison'",
",",
"Validation",
"::",
"COMPARE_GREATER",
",",
"$",
"value",
"]",
"]",
")",
";",
"}"
] | Add a greater than comparison rule to a field.
@param string $field The field you want to apply the rule to.
@param int|float $value The value user data must be greater than.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::comparison()
@return $this | [
"Add",
"a",
"greater",
"than",
"comparison",
"rule",
"to",
"a",
"field",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L1127-L1134 |
210,621 | cakephp/cakephp | src/Validation/Validator.php | Validator.greaterThanOrEqual | public function greaterThanOrEqual($field, $value, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'greaterThanOrEqual', $extra + [
'rule' => ['comparison', Validation::COMPARE_GREATER_OR_EQUAL, $value]
]);
} | php | public function greaterThanOrEqual($field, $value, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'greaterThanOrEqual', $extra + [
'rule' => ['comparison', Validation::COMPARE_GREATER_OR_EQUAL, $value]
]);
} | [
"public",
"function",
"greaterThanOrEqual",
"(",
"$",
"field",
",",
"$",
"value",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'greaterThanOrEqual'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"[",
"'comparison'",
",",
"Validation",
"::",
"COMPARE_GREATER_OR_EQUAL",
",",
"$",
"value",
"]",
"]",
")",
";",
"}"
] | Add a greater than or equal to comparison rule to a field.
@param string $field The field you want to apply the rule to.
@param int|float $value The value user data must be greater than or equal to.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::comparison()
@return $this | [
"Add",
"a",
"greater",
"than",
"or",
"equal",
"to",
"comparison",
"rule",
"to",
"a",
"field",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L1147-L1154 |
210,622 | cakephp/cakephp | src/Validation/Validator.php | Validator.lessThan | public function lessThan($field, $value, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'lessThan', $extra + [
'rule' => ['comparison', Validation::COMPARE_LESS, $value]
]);
} | php | public function lessThan($field, $value, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'lessThan', $extra + [
'rule' => ['comparison', Validation::COMPARE_LESS, $value]
]);
} | [
"public",
"function",
"lessThan",
"(",
"$",
"field",
",",
"$",
"value",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'lessThan'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"[",
"'comparison'",
",",
"Validation",
"::",
"COMPARE_LESS",
",",
"$",
"value",
"]",
"]",
")",
";",
"}"
] | Add a less than comparison rule to a field.
@param string $field The field you want to apply the rule to.
@param int|float $value The value user data must be less than.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::comparison()
@return $this | [
"Add",
"a",
"less",
"than",
"comparison",
"rule",
"to",
"a",
"field",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L1167-L1174 |
210,623 | cakephp/cakephp | src/Validation/Validator.php | Validator.lessThanOrEqual | public function lessThanOrEqual($field, $value, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'lessThanOrEqual', $extra + [
'rule' => ['comparison', Validation::COMPARE_LESS_OR_EQUAL, $value]
]);
} | php | public function lessThanOrEqual($field, $value, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'lessThanOrEqual', $extra + [
'rule' => ['comparison', Validation::COMPARE_LESS_OR_EQUAL, $value]
]);
} | [
"public",
"function",
"lessThanOrEqual",
"(",
"$",
"field",
",",
"$",
"value",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'lessThanOrEqual'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"[",
"'comparison'",
",",
"Validation",
"::",
"COMPARE_LESS_OR_EQUAL",
",",
"$",
"value",
"]",
"]",
")",
";",
"}"
] | Add a less than or equal comparison rule to a field.
@param string $field The field you want to apply the rule to.
@param int|float $value The value user data must be less than or equal to.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::comparison()
@return $this | [
"Add",
"a",
"less",
"than",
"or",
"equal",
"comparison",
"rule",
"to",
"a",
"field",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L1187-L1194 |
210,624 | cakephp/cakephp | src/Validation/Validator.php | Validator.equals | public function equals($field, $value, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'equals', $extra + [
'rule' => ['comparison', Validation::COMPARE_EQUAL, $value]
]);
} | php | public function equals($field, $value, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'equals', $extra + [
'rule' => ['comparison', Validation::COMPARE_EQUAL, $value]
]);
} | [
"public",
"function",
"equals",
"(",
"$",
"field",
",",
"$",
"value",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'equals'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"[",
"'comparison'",
",",
"Validation",
"::",
"COMPARE_EQUAL",
",",
"$",
"value",
"]",
"]",
")",
";",
"}"
] | Add a equal to comparison rule to a field.
@param string $field The field you want to apply the rule to.
@param int|float $value The value user data must be equal to.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::comparison()
@return $this | [
"Add",
"a",
"equal",
"to",
"comparison",
"rule",
"to",
"a",
"field",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L1207-L1214 |
210,625 | cakephp/cakephp | src/Validation/Validator.php | Validator.notEquals | public function notEquals($field, $value, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'notEquals', $extra + [
'rule' => ['comparison', Validation::COMPARE_NOT_EQUAL, $value]
]);
} | php | public function notEquals($field, $value, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'notEquals', $extra + [
'rule' => ['comparison', Validation::COMPARE_NOT_EQUAL, $value]
]);
} | [
"public",
"function",
"notEquals",
"(",
"$",
"field",
",",
"$",
"value",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'notEquals'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"[",
"'comparison'",
",",
"Validation",
"::",
"COMPARE_NOT_EQUAL",
",",
"$",
"value",
"]",
"]",
")",
";",
"}"
] | Add a not equal to comparison rule to a field.
@param string $field The field you want to apply the rule to.
@param int|float $value The value user data must be not be equal to.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::comparison()
@return $this | [
"Add",
"a",
"not",
"equal",
"to",
"comparison",
"rule",
"to",
"a",
"field",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L1227-L1234 |
210,626 | cakephp/cakephp | src/Validation/Validator.php | Validator.sameAs | public function sameAs($field, $secondField, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'sameAs', $extra + [
'rule' => ['compareFields', $secondField, Validation::COMPARE_SAME]
]);
} | php | public function sameAs($field, $secondField, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'sameAs', $extra + [
'rule' => ['compareFields', $secondField, Validation::COMPARE_SAME]
]);
} | [
"public",
"function",
"sameAs",
"(",
"$",
"field",
",",
"$",
"secondField",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'sameAs'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"[",
"'compareFields'",
",",
"$",
"secondField",
",",
"Validation",
"::",
"COMPARE_SAME",
"]",
"]",
")",
";",
"}"
] | Add a rule to compare two fields to each other.
If both fields have the exact same value the rule will pass.
@param string $field The field you want to apply the rule to.
@param string $secondField The field you want to compare against.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::compareFields()
@return $this | [
"Add",
"a",
"rule",
"to",
"compare",
"two",
"fields",
"to",
"each",
"other",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L1249-L1256 |
210,627 | cakephp/cakephp | src/Validation/Validator.php | Validator.notSameAs | public function notSameAs($field, $secondField, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'notSameAs', $extra + [
'rule' => ['compareFields', $secondField, Validation::COMPARE_NOT_SAME]
]);
} | php | public function notSameAs($field, $secondField, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'notSameAs', $extra + [
'rule' => ['compareFields', $secondField, Validation::COMPARE_NOT_SAME]
]);
} | [
"public",
"function",
"notSameAs",
"(",
"$",
"field",
",",
"$",
"secondField",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'notSameAs'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"[",
"'compareFields'",
",",
"$",
"secondField",
",",
"Validation",
"::",
"COMPARE_NOT_SAME",
"]",
"]",
")",
";",
"}"
] | Add a rule to compare that two fields have different values.
@param string $field The field you want to apply the rule to.
@param string $secondField The field you want to compare against.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::compareFields()
@return $this
@since 3.6.0 | [
"Add",
"a",
"rule",
"to",
"compare",
"that",
"two",
"fields",
"have",
"different",
"values",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L1270-L1277 |
210,628 | cakephp/cakephp | src/Validation/Validator.php | Validator.equalToField | public function equalToField($field, $secondField, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'equalToField', $extra + [
'rule' => ['compareFields', $secondField, Validation::COMPARE_EQUAL]
]);
} | php | public function equalToField($field, $secondField, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'equalToField', $extra + [
'rule' => ['compareFields', $secondField, Validation::COMPARE_EQUAL]
]);
} | [
"public",
"function",
"equalToField",
"(",
"$",
"field",
",",
"$",
"secondField",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'equalToField'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"[",
"'compareFields'",
",",
"$",
"secondField",
",",
"Validation",
"::",
"COMPARE_EQUAL",
"]",
"]",
")",
";",
"}"
] | Add a rule to compare one field is equal to another.
@param string $field The field you want to apply the rule to.
@param string $secondField The field you want to compare against.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::compareFields()
@return $this
@since 3.6.0 | [
"Add",
"a",
"rule",
"to",
"compare",
"one",
"field",
"is",
"equal",
"to",
"another",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L1291-L1298 |
210,629 | cakephp/cakephp | src/Validation/Validator.php | Validator.notEqualToField | public function notEqualToField($field, $secondField, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'notEqualToField', $extra + [
'rule' => ['compareFields', $secondField, Validation::COMPARE_NOT_EQUAL]
]);
} | php | public function notEqualToField($field, $secondField, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'notEqualToField', $extra + [
'rule' => ['compareFields', $secondField, Validation::COMPARE_NOT_EQUAL]
]);
} | [
"public",
"function",
"notEqualToField",
"(",
"$",
"field",
",",
"$",
"secondField",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'notEqualToField'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"[",
"'compareFields'",
",",
"$",
"secondField",
",",
"Validation",
"::",
"COMPARE_NOT_EQUAL",
"]",
"]",
")",
";",
"}"
] | Add a rule to compare one field is not equal to another.
@param string $field The field you want to apply the rule to.
@param string $secondField The field you want to compare against.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::compareFields()
@return $this
@since 3.6.0 | [
"Add",
"a",
"rule",
"to",
"compare",
"one",
"field",
"is",
"not",
"equal",
"to",
"another",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L1312-L1319 |
210,630 | cakephp/cakephp | src/Validation/Validator.php | Validator.greaterThanField | public function greaterThanField($field, $secondField, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'greaterThanField', $extra + [
'rule' => ['compareFields', $secondField, Validation::COMPARE_GREATER]
]);
} | php | public function greaterThanField($field, $secondField, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'greaterThanField', $extra + [
'rule' => ['compareFields', $secondField, Validation::COMPARE_GREATER]
]);
} | [
"public",
"function",
"greaterThanField",
"(",
"$",
"field",
",",
"$",
"secondField",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'greaterThanField'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"[",
"'compareFields'",
",",
"$",
"secondField",
",",
"Validation",
"::",
"COMPARE_GREATER",
"]",
"]",
")",
";",
"}"
] | Add a rule to compare one field is greater than another.
@param string $field The field you want to apply the rule to.
@param string $secondField The field you want to compare against.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::compareFields()
@return $this
@since 3.6.0 | [
"Add",
"a",
"rule",
"to",
"compare",
"one",
"field",
"is",
"greater",
"than",
"another",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L1333-L1340 |
210,631 | cakephp/cakephp | src/Validation/Validator.php | Validator.greaterThanOrEqualToField | public function greaterThanOrEqualToField($field, $secondField, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'greaterThanOrEqualToField', $extra + [
'rule' => ['compareFields', $secondField, Validation::COMPARE_GREATER_OR_EQUAL]
]);
} | php | public function greaterThanOrEqualToField($field, $secondField, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'greaterThanOrEqualToField', $extra + [
'rule' => ['compareFields', $secondField, Validation::COMPARE_GREATER_OR_EQUAL]
]);
} | [
"public",
"function",
"greaterThanOrEqualToField",
"(",
"$",
"field",
",",
"$",
"secondField",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'greaterThanOrEqualToField'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"[",
"'compareFields'",
",",
"$",
"secondField",
",",
"Validation",
"::",
"COMPARE_GREATER_OR_EQUAL",
"]",
"]",
")",
";",
"}"
] | Add a rule to compare one field is greater than or equal to another.
@param string $field The field you want to apply the rule to.
@param string $secondField The field you want to compare against.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::compareFields()
@return $this
@since 3.6.0 | [
"Add",
"a",
"rule",
"to",
"compare",
"one",
"field",
"is",
"greater",
"than",
"or",
"equal",
"to",
"another",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L1354-L1361 |
210,632 | cakephp/cakephp | src/Validation/Validator.php | Validator.lessThanField | public function lessThanField($field, $secondField, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'lessThanField', $extra + [
'rule' => ['compareFields', $secondField, Validation::COMPARE_LESS]
]);
} | php | public function lessThanField($field, $secondField, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'lessThanField', $extra + [
'rule' => ['compareFields', $secondField, Validation::COMPARE_LESS]
]);
} | [
"public",
"function",
"lessThanField",
"(",
"$",
"field",
",",
"$",
"secondField",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'lessThanField'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"[",
"'compareFields'",
",",
"$",
"secondField",
",",
"Validation",
"::",
"COMPARE_LESS",
"]",
"]",
")",
";",
"}"
] | Add a rule to compare one field is less than another.
@param string $field The field you want to apply the rule to.
@param string $secondField The field you want to compare against.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::compareFields()
@return $this
@since 3.6.0 | [
"Add",
"a",
"rule",
"to",
"compare",
"one",
"field",
"is",
"less",
"than",
"another",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L1375-L1382 |
210,633 | cakephp/cakephp | src/Validation/Validator.php | Validator.lessThanOrEqualToField | public function lessThanOrEqualToField($field, $secondField, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'lessThanOrEqualToField', $extra + [
'rule' => ['compareFields', $secondField, Validation::COMPARE_LESS_OR_EQUAL]
]);
} | php | public function lessThanOrEqualToField($field, $secondField, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'lessThanOrEqualToField', $extra + [
'rule' => ['compareFields', $secondField, Validation::COMPARE_LESS_OR_EQUAL]
]);
} | [
"public",
"function",
"lessThanOrEqualToField",
"(",
"$",
"field",
",",
"$",
"secondField",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'lessThanOrEqualToField'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"[",
"'compareFields'",
",",
"$",
"secondField",
",",
"Validation",
"::",
"COMPARE_LESS_OR_EQUAL",
"]",
"]",
")",
";",
"}"
] | Add a rule to compare one field is less than or equal to another.
@param string $field The field you want to apply the rule to.
@param string $secondField The field you want to compare against.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::compareFields()
@return $this
@since 3.6.0 | [
"Add",
"a",
"rule",
"to",
"compare",
"one",
"field",
"is",
"less",
"than",
"or",
"equal",
"to",
"another",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L1396-L1403 |
210,634 | cakephp/cakephp | src/Validation/Validator.php | Validator.containsNonAlphaNumeric | public function containsNonAlphaNumeric($field, $limit = 1, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'containsNonAlphaNumeric', $extra + [
'rule' => ['containsNonAlphaNumeric', $limit]
]);
} | php | public function containsNonAlphaNumeric($field, $limit = 1, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'containsNonAlphaNumeric', $extra + [
'rule' => ['containsNonAlphaNumeric', $limit]
]);
} | [
"public",
"function",
"containsNonAlphaNumeric",
"(",
"$",
"field",
",",
"$",
"limit",
"=",
"1",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'containsNonAlphaNumeric'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"[",
"'containsNonAlphaNumeric'",
",",
"$",
"limit",
"]",
"]",
")",
";",
"}"
] | Add a rule to check if a field contains non alpha numeric characters.
@param string $field The field you want to apply the rule to.
@param int $limit The minimum number of non-alphanumeric fields required.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::containsNonAlphaNumeric()
@return $this | [
"Add",
"a",
"rule",
"to",
"check",
"if",
"a",
"field",
"contains",
"non",
"alpha",
"numeric",
"characters",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L1416-L1423 |
210,635 | cakephp/cakephp | src/Validation/Validator.php | Validator.date | public function date($field, $formats = ['ymd'], $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'date', $extra + [
'rule' => ['date', $formats]
]);
} | php | public function date($field, $formats = ['ymd'], $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'date', $extra + [
'rule' => ['date', $formats]
]);
} | [
"public",
"function",
"date",
"(",
"$",
"field",
",",
"$",
"formats",
"=",
"[",
"'ymd'",
"]",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'date'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"[",
"'date'",
",",
"$",
"formats",
"]",
"]",
")",
";",
"}"
] | Add a date format validation rule to a field.
@param string $field The field you want to apply the rule to.
@param array $formats A list of accepted date formats.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::date()
@return $this | [
"Add",
"a",
"date",
"format",
"validation",
"rule",
"to",
"a",
"field",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L1436-L1443 |
210,636 | cakephp/cakephp | src/Validation/Validator.php | Validator.localizedTime | public function localizedTime($field, $type = 'datetime', $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'localizedTime', $extra + [
'rule' => ['localizedTime', $type]
]);
} | php | public function localizedTime($field, $type = 'datetime', $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'localizedTime', $extra + [
'rule' => ['localizedTime', $type]
]);
} | [
"public",
"function",
"localizedTime",
"(",
"$",
"field",
",",
"$",
"type",
"=",
"'datetime'",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'localizedTime'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"[",
"'localizedTime'",
",",
"$",
"type",
"]",
"]",
")",
";",
"}"
] | Add a localized time, date or datetime format validation rule to a field.
@param string $field The field you want to apply the rule to.
@param string $type Parser type, one out of 'date', 'time', and 'datetime'
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::localizedTime()
@return $this | [
"Add",
"a",
"localized",
"time",
"date",
"or",
"datetime",
"format",
"validation",
"rule",
"to",
"a",
"field",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L1495-L1502 |
210,637 | cakephp/cakephp | src/Validation/Validator.php | Validator.boolean | public function boolean($field, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'boolean', $extra + [
'rule' => 'boolean'
]);
} | php | public function boolean($field, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'boolean', $extra + [
'rule' => 'boolean'
]);
} | [
"public",
"function",
"boolean",
"(",
"$",
"field",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'boolean'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"'boolean'",
"]",
")",
";",
"}"
] | Add a boolean validation rule to a field.
@param string $field The field you want to apply the rule to.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::boolean()
@return $this | [
"Add",
"a",
"boolean",
"validation",
"rule",
"to",
"a",
"field",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L1514-L1521 |
210,638 | cakephp/cakephp | src/Validation/Validator.php | Validator.decimal | public function decimal($field, $places = null, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'decimal', $extra + [
'rule' => ['decimal', $places]
]);
} | php | public function decimal($field, $places = null, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'decimal', $extra + [
'rule' => ['decimal', $places]
]);
} | [
"public",
"function",
"decimal",
"(",
"$",
"field",
",",
"$",
"places",
"=",
"null",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'decimal'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"[",
"'decimal'",
",",
"$",
"places",
"]",
"]",
")",
";",
"}"
] | Add a decimal validation rule to a field.
@param string $field The field you want to apply the rule to.
@param int|null $places The number of decimal places to require.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::decimal()
@return $this | [
"Add",
"a",
"decimal",
"validation",
"rule",
"to",
"a",
"field",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L1534-L1541 |
210,639 | cakephp/cakephp | src/Validation/Validator.php | Validator.email | public function email($field, $checkMX = false, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'email', $extra + [
'rule' => ['email', $checkMX]
]);
} | php | public function email($field, $checkMX = false, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'email', $extra + [
'rule' => ['email', $checkMX]
]);
} | [
"public",
"function",
"email",
"(",
"$",
"field",
",",
"$",
"checkMX",
"=",
"false",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'email'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"[",
"'email'",
",",
"$",
"checkMX",
"]",
"]",
")",
";",
"}"
] | Add an email validation rule to a field.
@param string $field The field you want to apply the rule to.
@param bool $checkMX Whether or not to check the MX records.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::email()
@return $this | [
"Add",
"an",
"email",
"validation",
"rule",
"to",
"a",
"field",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L1554-L1561 |
210,640 | cakephp/cakephp | src/Validation/Validator.php | Validator.urlWithProtocol | public function urlWithProtocol($field, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'urlWithProtocol', $extra + [
'rule' => ['url', true]
]);
} | php | public function urlWithProtocol($field, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'urlWithProtocol', $extra + [
'rule' => ['url', true]
]);
} | [
"public",
"function",
"urlWithProtocol",
"(",
"$",
"field",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'urlWithProtocol'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"[",
"'url'",
",",
"true",
"]",
"]",
")",
";",
"}"
] | Add a validation rule to ensure a field is a URL.
This validator requires the URL to have a protocol.
@param string $field The field you want to apply the rule to.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::url()
@return $this | [
"Add",
"a",
"validation",
"rule",
"to",
"ensure",
"a",
"field",
"is",
"a",
"URL",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L1815-L1822 |
210,641 | cakephp/cakephp | src/Validation/Validator.php | Validator.inList | public function inList($field, array $list, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'inList', $extra + [
'rule' => ['inList', $list]
]);
} | php | public function inList($field, array $list, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'inList', $extra + [
'rule' => ['inList', $list]
]);
} | [
"public",
"function",
"inList",
"(",
"$",
"field",
",",
"array",
"$",
"list",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'inList'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"[",
"'inList'",
",",
"$",
"list",
"]",
"]",
")",
";",
"}"
] | Add a validation rule to ensure the field value is within a whitelist.
@param string $field The field you want to apply the rule to.
@param array $list The list of valid options.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::inList()
@return $this | [
"Add",
"a",
"validation",
"rule",
"to",
"ensure",
"the",
"field",
"value",
"is",
"within",
"a",
"whitelist",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L1835-L1842 |
210,642 | cakephp/cakephp | src/Validation/Validator.php | Validator.uploadedFile | public function uploadedFile($field, array $options, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'uploadedFile', $extra + [
'rule' => ['uploadedFile', $options]
]);
} | php | public function uploadedFile($field, array $options, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'uploadedFile', $extra + [
'rule' => ['uploadedFile', $options]
]);
} | [
"public",
"function",
"uploadedFile",
"(",
"$",
"field",
",",
"array",
"$",
"options",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'uploadedFile'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"[",
"'uploadedFile'",
",",
"$",
"options",
"]",
"]",
")",
";",
"}"
] | Add a validation rule to ensure the field is an uploaded file
For options see Cake\Validation\Validation::uploadedFile()
@param string $field The field you want to apply the rule to.
@param array $options An array of options.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::uploadedFile()
@return $this | [
"Add",
"a",
"validation",
"rule",
"to",
"ensure",
"the",
"field",
"is",
"an",
"uploaded",
"file"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L1876-L1883 |
210,643 | cakephp/cakephp | src/Validation/Validator.php | Validator.utf8 | public function utf8($field, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'utf8', $extra + [
'rule' => ['utf8', ['extended' => false]]
]);
} | php | public function utf8($field, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'utf8', $extra + [
'rule' => ['utf8', ['extended' => false]]
]);
} | [
"public",
"function",
"utf8",
"(",
"$",
"field",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'utf8'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"[",
"'utf8'",
",",
"[",
"'extended'",
"=>",
"false",
"]",
"]",
"]",
")",
";",
"}"
] | Add a validation rule to ensure a field contains only BMP utf8 bytes
@param string $field The field you want to apply the rule to.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::utf8()
@return $this | [
"Add",
"a",
"validation",
"rule",
"to",
"ensure",
"a",
"field",
"contains",
"only",
"BMP",
"utf8",
"bytes"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L1973-L1980 |
210,644 | cakephp/cakephp | src/Validation/Validator.php | Validator.multipleOptions | public function multipleOptions($field, array $options = [], $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
$caseInsensitive = isset($options['caseInsensitive']) ? $options['caseInsensitive'] : false;
unset($options['caseInsensitive']);
return $this->add($field, 'multipleOptions', $extra + [
'rule' => ['multiple', $options, $caseInsensitive]
]);
} | php | public function multipleOptions($field, array $options = [], $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
$caseInsensitive = isset($options['caseInsensitive']) ? $options['caseInsensitive'] : false;
unset($options['caseInsensitive']);
return $this->add($field, 'multipleOptions', $extra + [
'rule' => ['multiple', $options, $caseInsensitive]
]);
} | [
"public",
"function",
"multipleOptions",
"(",
"$",
"field",
",",
"array",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"$",
"caseInsensitive",
"=",
"isset",
"(",
"$",
"options",
"[",
"'caseInsensitive'",
"]",
")",
"?",
"$",
"options",
"[",
"'caseInsensitive'",
"]",
":",
"false",
";",
"unset",
"(",
"$",
"options",
"[",
"'caseInsensitive'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'multipleOptions'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"[",
"'multiple'",
",",
"$",
"options",
",",
"$",
"caseInsensitive",
"]",
"]",
")",
";",
"}"
] | Add a validation rule for a multiple select. Comparison is case sensitive by default.
@param string $field The field you want to apply the rule to.
@param array $options The options for the validator. Includes the options defined in
\Cake\Validation\Validation::multiple() and the `caseInsensitive` parameter.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::multiple()
@return $this | [
"Add",
"a",
"validation",
"rule",
"for",
"a",
"multiple",
"select",
".",
"Comparison",
"is",
"case",
"sensitive",
"by",
"default",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L2091-L2100 |
210,645 | cakephp/cakephp | src/Validation/Validator.php | Validator.hasAtLeast | public function hasAtLeast($field, $count, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'hasAtLeast', $extra + [
'rule' => function ($value) use ($count) {
if (is_array($value) && isset($value['_ids'])) {
$value = $value['_ids'];
}
return Validation::numElements($value, Validation::COMPARE_GREATER_OR_EQUAL, $count);
}
]);
} | php | public function hasAtLeast($field, $count, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'hasAtLeast', $extra + [
'rule' => function ($value) use ($count) {
if (is_array($value) && isset($value['_ids'])) {
$value = $value['_ids'];
}
return Validation::numElements($value, Validation::COMPARE_GREATER_OR_EQUAL, $count);
}
]);
} | [
"public",
"function",
"hasAtLeast",
"(",
"$",
"field",
",",
"$",
"count",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'hasAtLeast'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"$",
"count",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"isset",
"(",
"$",
"value",
"[",
"'_ids'",
"]",
")",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"[",
"'_ids'",
"]",
";",
"}",
"return",
"Validation",
"::",
"numElements",
"(",
"$",
"value",
",",
"Validation",
"::",
"COMPARE_GREATER_OR_EQUAL",
",",
"$",
"count",
")",
";",
"}",
"]",
")",
";",
"}"
] | Add a validation rule to ensure that a field is an array containing at least
the specified amount of elements
@param string $field The field you want to apply the rule to.
@param int $count The number of elements the array should at least have
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::numElements()
@return $this | [
"Add",
"a",
"validation",
"rule",
"to",
"ensure",
"that",
"a",
"field",
"is",
"an",
"array",
"containing",
"at",
"least",
"the",
"specified",
"amount",
"of",
"elements"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L2114-L2127 |
210,646 | cakephp/cakephp | src/Validation/Validator.php | Validator.hasAtMost | public function hasAtMost($field, $count, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'hasAtMost', $extra + [
'rule' => function ($value) use ($count) {
if (is_array($value) && isset($value['_ids'])) {
$value = $value['_ids'];
}
return Validation::numElements($value, Validation::COMPARE_LESS_OR_EQUAL, $count);
}
]);
} | php | public function hasAtMost($field, $count, $message = null, $when = null)
{
$extra = array_filter(['on' => $when, 'message' => $message]);
return $this->add($field, 'hasAtMost', $extra + [
'rule' => function ($value) use ($count) {
if (is_array($value) && isset($value['_ids'])) {
$value = $value['_ids'];
}
return Validation::numElements($value, Validation::COMPARE_LESS_OR_EQUAL, $count);
}
]);
} | [
"public",
"function",
"hasAtMost",
"(",
"$",
"field",
",",
"$",
"count",
",",
"$",
"message",
"=",
"null",
",",
"$",
"when",
"=",
"null",
")",
"{",
"$",
"extra",
"=",
"array_filter",
"(",
"[",
"'on'",
"=>",
"$",
"when",
",",
"'message'",
"=>",
"$",
"message",
"]",
")",
";",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"field",
",",
"'hasAtMost'",
",",
"$",
"extra",
"+",
"[",
"'rule'",
"=>",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"$",
"count",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"isset",
"(",
"$",
"value",
"[",
"'_ids'",
"]",
")",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"[",
"'_ids'",
"]",
";",
"}",
"return",
"Validation",
"::",
"numElements",
"(",
"$",
"value",
",",
"Validation",
"::",
"COMPARE_LESS_OR_EQUAL",
",",
"$",
"count",
")",
";",
"}",
"]",
")",
";",
"}"
] | Add a validation rule to ensure that a field is an array containing at most
the specified amount of elements
@param string $field The field you want to apply the rule to.
@param int $count The number maximum amount of elements the field should have
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::numElements()
@return $this | [
"Add",
"a",
"validation",
"rule",
"to",
"ensure",
"that",
"a",
"field",
"is",
"an",
"array",
"containing",
"at",
"most",
"the",
"specified",
"amount",
"of",
"elements"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L2141-L2154 |
210,647 | cakephp/cakephp | src/Validation/Validator.php | Validator.isEmptyAllowed | public function isEmptyAllowed($field, $newRecord)
{
$providers = $this->_providers;
$data = [];
$context = compact('data', 'newRecord', 'field', 'providers');
return $this->_canBeEmpty($this->field($field), $context);
} | php | public function isEmptyAllowed($field, $newRecord)
{
$providers = $this->_providers;
$data = [];
$context = compact('data', 'newRecord', 'field', 'providers');
return $this->_canBeEmpty($this->field($field), $context);
} | [
"public",
"function",
"isEmptyAllowed",
"(",
"$",
"field",
",",
"$",
"newRecord",
")",
"{",
"$",
"providers",
"=",
"$",
"this",
"->",
"_providers",
";",
"$",
"data",
"=",
"[",
"]",
";",
"$",
"context",
"=",
"compact",
"(",
"'data'",
",",
"'newRecord'",
",",
"'field'",
",",
"'providers'",
")",
";",
"return",
"$",
"this",
"->",
"_canBeEmpty",
"(",
"$",
"this",
"->",
"field",
"(",
"$",
"field",
")",
",",
"$",
"context",
")",
";",
"}"
] | Returns whether or not a field can be left empty for a new or already existing
record.
@param string $field Field name.
@param bool $newRecord whether the data to be validated is new or to be updated.
@return bool | [
"Returns",
"whether",
"or",
"not",
"a",
"field",
"can",
"be",
"left",
"empty",
"for",
"a",
"new",
"or",
"already",
"existing",
"record",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L2164-L2171 |
210,648 | cakephp/cakephp | src/Validation/Validator.php | Validator.isPresenceRequired | public function isPresenceRequired($field, $newRecord)
{
$providers = $this->_providers;
$data = [];
$context = compact('data', 'newRecord', 'field', 'providers');
return !$this->_checkPresence($this->field($field), $context);
} | php | public function isPresenceRequired($field, $newRecord)
{
$providers = $this->_providers;
$data = [];
$context = compact('data', 'newRecord', 'field', 'providers');
return !$this->_checkPresence($this->field($field), $context);
} | [
"public",
"function",
"isPresenceRequired",
"(",
"$",
"field",
",",
"$",
"newRecord",
")",
"{",
"$",
"providers",
"=",
"$",
"this",
"->",
"_providers",
";",
"$",
"data",
"=",
"[",
"]",
";",
"$",
"context",
"=",
"compact",
"(",
"'data'",
",",
"'newRecord'",
",",
"'field'",
",",
"'providers'",
")",
";",
"return",
"!",
"$",
"this",
"->",
"_checkPresence",
"(",
"$",
"this",
"->",
"field",
"(",
"$",
"field",
")",
",",
"$",
"context",
")",
";",
"}"
] | Returns whether or not a field can be left out for a new or already existing
record.
@param string $field Field name.
@param bool $newRecord Whether the data to be validated is new or to be updated.
@return bool | [
"Returns",
"whether",
"or",
"not",
"a",
"field",
"can",
"be",
"left",
"out",
"for",
"a",
"new",
"or",
"already",
"existing",
"record",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L2181-L2188 |
210,649 | cakephp/cakephp | src/Validation/Validator.php | Validator.getRequiredMessage | public function getRequiredMessage($field)
{
if (!isset($this->_fields[$field])) {
return null;
}
$defaultMessage = 'This field is required';
if ($this->_useI18n) {
$defaultMessage = __d('cake', 'This field is required');
}
return isset($this->_presenceMessages[$field])
? $this->_presenceMessages[$field]
: $defaultMessage;
} | php | public function getRequiredMessage($field)
{
if (!isset($this->_fields[$field])) {
return null;
}
$defaultMessage = 'This field is required';
if ($this->_useI18n) {
$defaultMessage = __d('cake', 'This field is required');
}
return isset($this->_presenceMessages[$field])
? $this->_presenceMessages[$field]
: $defaultMessage;
} | [
"public",
"function",
"getRequiredMessage",
"(",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_fields",
"[",
"$",
"field",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"defaultMessage",
"=",
"'This field is required'",
";",
"if",
"(",
"$",
"this",
"->",
"_useI18n",
")",
"{",
"$",
"defaultMessage",
"=",
"__d",
"(",
"'cake'",
",",
"'This field is required'",
")",
";",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"_presenceMessages",
"[",
"$",
"field",
"]",
")",
"?",
"$",
"this",
"->",
"_presenceMessages",
"[",
"$",
"field",
"]",
":",
"$",
"defaultMessage",
";",
"}"
] | Gets the required message for a field
@param string $field Field name
@return string|null | [
"Gets",
"the",
"required",
"message",
"for",
"a",
"field"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L2215-L2229 |
210,650 | cakephp/cakephp | src/Validation/Validator.php | Validator.getNotEmptyMessage | public function getNotEmptyMessage($field)
{
if (!isset($this->_fields[$field])) {
return null;
}
$defaultMessage = 'This field cannot be left empty';
if ($this->_useI18n) {
$defaultMessage = __d('cake', 'This field cannot be left empty');
}
$notBlankMessage = null;
foreach ($this->_fields[$field] as $rule) {
if ($rule->get('rule') === 'notBlank' && $rule->get('message')) {
return $rule->get('message');
}
}
return isset($this->_allowEmptyMessages[$field])
? $this->_allowEmptyMessages[$field]
: $defaultMessage;
} | php | public function getNotEmptyMessage($field)
{
if (!isset($this->_fields[$field])) {
return null;
}
$defaultMessage = 'This field cannot be left empty';
if ($this->_useI18n) {
$defaultMessage = __d('cake', 'This field cannot be left empty');
}
$notBlankMessage = null;
foreach ($this->_fields[$field] as $rule) {
if ($rule->get('rule') === 'notBlank' && $rule->get('message')) {
return $rule->get('message');
}
}
return isset($this->_allowEmptyMessages[$field])
? $this->_allowEmptyMessages[$field]
: $defaultMessage;
} | [
"public",
"function",
"getNotEmptyMessage",
"(",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_fields",
"[",
"$",
"field",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"defaultMessage",
"=",
"'This field cannot be left empty'",
";",
"if",
"(",
"$",
"this",
"->",
"_useI18n",
")",
"{",
"$",
"defaultMessage",
"=",
"__d",
"(",
"'cake'",
",",
"'This field cannot be left empty'",
")",
";",
"}",
"$",
"notBlankMessage",
"=",
"null",
";",
"foreach",
"(",
"$",
"this",
"->",
"_fields",
"[",
"$",
"field",
"]",
"as",
"$",
"rule",
")",
"{",
"if",
"(",
"$",
"rule",
"->",
"get",
"(",
"'rule'",
")",
"===",
"'notBlank'",
"&&",
"$",
"rule",
"->",
"get",
"(",
"'message'",
")",
")",
"{",
"return",
"$",
"rule",
"->",
"get",
"(",
"'message'",
")",
";",
"}",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"_allowEmptyMessages",
"[",
"$",
"field",
"]",
")",
"?",
"$",
"this",
"->",
"_allowEmptyMessages",
"[",
"$",
"field",
"]",
":",
"$",
"defaultMessage",
";",
"}"
] | Gets the notEmpty message for a field
@param string $field Field name
@return string|null | [
"Gets",
"the",
"notEmpty",
"message",
"for",
"a",
"field"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L2237-L2258 |
210,651 | cakephp/cakephp | src/Validation/Validator.php | Validator._checkPresence | protected function _checkPresence($field, $context)
{
$required = $field->isPresenceRequired();
if (!is_string($required) && is_callable($required)) {
return !$required($context);
}
$newRecord = $context['newRecord'];
if (in_array($required, ['create', 'update'], true)) {
return (
($required === 'create' && !$newRecord) ||
($required === 'update' && $newRecord)
);
}
return !$required;
} | php | protected function _checkPresence($field, $context)
{
$required = $field->isPresenceRequired();
if (!is_string($required) && is_callable($required)) {
return !$required($context);
}
$newRecord = $context['newRecord'];
if (in_array($required, ['create', 'update'], true)) {
return (
($required === 'create' && !$newRecord) ||
($required === 'update' && $newRecord)
);
}
return !$required;
} | [
"protected",
"function",
"_checkPresence",
"(",
"$",
"field",
",",
"$",
"context",
")",
"{",
"$",
"required",
"=",
"$",
"field",
"->",
"isPresenceRequired",
"(",
")",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"required",
")",
"&&",
"is_callable",
"(",
"$",
"required",
")",
")",
"{",
"return",
"!",
"$",
"required",
"(",
"$",
"context",
")",
";",
"}",
"$",
"newRecord",
"=",
"$",
"context",
"[",
"'newRecord'",
"]",
";",
"if",
"(",
"in_array",
"(",
"$",
"required",
",",
"[",
"'create'",
",",
"'update'",
"]",
",",
"true",
")",
")",
"{",
"return",
"(",
"(",
"$",
"required",
"===",
"'create'",
"&&",
"!",
"$",
"newRecord",
")",
"||",
"(",
"$",
"required",
"===",
"'update'",
"&&",
"$",
"newRecord",
")",
")",
";",
"}",
"return",
"!",
"$",
"required",
";",
"}"
] | Returns false if any validation for the passed rule set should be stopped
due to the field missing in the data array
@param \Cake\Validation\ValidationSet $field The set of rules for a field.
@param array $context A key value list of data containing the validation context.
@return bool | [
"Returns",
"false",
"if",
"any",
"validation",
"for",
"the",
"passed",
"rule",
"set",
"should",
"be",
"stopped",
"due",
"to",
"the",
"field",
"missing",
"in",
"the",
"data",
"array"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L2268-L2285 |
210,652 | cakephp/cakephp | src/Validation/Validator.php | Validator._canBeEmpty | protected function _canBeEmpty($field, $context)
{
$allowed = $field->isEmptyAllowed();
if (!is_string($allowed) && is_callable($allowed)) {
return $allowed($context);
}
$newRecord = $context['newRecord'];
if (in_array($allowed, ['create', 'update'], true)) {
$allowed = (
($allowed === 'create' && $newRecord) ||
($allowed === 'update' && !$newRecord)
);
}
return $allowed;
} | php | protected function _canBeEmpty($field, $context)
{
$allowed = $field->isEmptyAllowed();
if (!is_string($allowed) && is_callable($allowed)) {
return $allowed($context);
}
$newRecord = $context['newRecord'];
if (in_array($allowed, ['create', 'update'], true)) {
$allowed = (
($allowed === 'create' && $newRecord) ||
($allowed === 'update' && !$newRecord)
);
}
return $allowed;
} | [
"protected",
"function",
"_canBeEmpty",
"(",
"$",
"field",
",",
"$",
"context",
")",
"{",
"$",
"allowed",
"=",
"$",
"field",
"->",
"isEmptyAllowed",
"(",
")",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"allowed",
")",
"&&",
"is_callable",
"(",
"$",
"allowed",
")",
")",
"{",
"return",
"$",
"allowed",
"(",
"$",
"context",
")",
";",
"}",
"$",
"newRecord",
"=",
"$",
"context",
"[",
"'newRecord'",
"]",
";",
"if",
"(",
"in_array",
"(",
"$",
"allowed",
",",
"[",
"'create'",
",",
"'update'",
"]",
",",
"true",
")",
")",
"{",
"$",
"allowed",
"=",
"(",
"(",
"$",
"allowed",
"===",
"'create'",
"&&",
"$",
"newRecord",
")",
"||",
"(",
"$",
"allowed",
"===",
"'update'",
"&&",
"!",
"$",
"newRecord",
")",
")",
";",
"}",
"return",
"$",
"allowed",
";",
"}"
] | Returns whether the field can be left blank according to `allowEmpty`
@param \Cake\Validation\ValidationSet $field the set of rules for a field
@param array $context a key value list of data containing the validation context.
@return bool | [
"Returns",
"whether",
"the",
"field",
"can",
"be",
"left",
"blank",
"according",
"to",
"allowEmpty"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L2294-L2311 |
210,653 | cakephp/cakephp | src/Validation/Validator.php | Validator.isEmpty | protected function isEmpty($data, $flags)
{
if ($data === null) {
return true;
}
if ($data === '' && ($flags & self::EMPTY_STRING)) {
return true;
}
$arrayTypes = self::EMPTY_ARRAY | self::EMPTY_DATE | self::EMPTY_TIME;
if ($data === [] && ($flags & $arrayTypes)) {
return true;
}
if (is_array($data)) {
if (($flags & self::EMPTY_FILE)
&& isset($data['name'], $data['type'], $data['tmp_name'], $data['error'])
&& (int)$data['error'] === UPLOAD_ERR_NO_FILE
) {
return true;
}
$allFieldsAreEmpty = true;
foreach ($data as $field) {
if ($field !== null && $field !== '') {
$allFieldsAreEmpty = false;
break;
}
}
if ($allFieldsAreEmpty) {
if (($flags & self::EMPTY_DATE) && isset($data['year'])) {
return true;
}
if (($flags & self::EMPTY_TIME) && isset($data['hour'])) {
return true;
}
}
}
return false;
} | php | protected function isEmpty($data, $flags)
{
if ($data === null) {
return true;
}
if ($data === '' && ($flags & self::EMPTY_STRING)) {
return true;
}
$arrayTypes = self::EMPTY_ARRAY | self::EMPTY_DATE | self::EMPTY_TIME;
if ($data === [] && ($flags & $arrayTypes)) {
return true;
}
if (is_array($data)) {
if (($flags & self::EMPTY_FILE)
&& isset($data['name'], $data['type'], $data['tmp_name'], $data['error'])
&& (int)$data['error'] === UPLOAD_ERR_NO_FILE
) {
return true;
}
$allFieldsAreEmpty = true;
foreach ($data as $field) {
if ($field !== null && $field !== '') {
$allFieldsAreEmpty = false;
break;
}
}
if ($allFieldsAreEmpty) {
if (($flags & self::EMPTY_DATE) && isset($data['year'])) {
return true;
}
if (($flags & self::EMPTY_TIME) && isset($data['hour'])) {
return true;
}
}
}
return false;
} | [
"protected",
"function",
"isEmpty",
"(",
"$",
"data",
",",
"$",
"flags",
")",
"{",
"if",
"(",
"$",
"data",
"===",
"null",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"data",
"===",
"''",
"&&",
"(",
"$",
"flags",
"&",
"self",
"::",
"EMPTY_STRING",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"arrayTypes",
"=",
"self",
"::",
"EMPTY_ARRAY",
"|",
"self",
"::",
"EMPTY_DATE",
"|",
"self",
"::",
"EMPTY_TIME",
";",
"if",
"(",
"$",
"data",
"===",
"[",
"]",
"&&",
"(",
"$",
"flags",
"&",
"$",
"arrayTypes",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"if",
"(",
"(",
"$",
"flags",
"&",
"self",
"::",
"EMPTY_FILE",
")",
"&&",
"isset",
"(",
"$",
"data",
"[",
"'name'",
"]",
",",
"$",
"data",
"[",
"'type'",
"]",
",",
"$",
"data",
"[",
"'tmp_name'",
"]",
",",
"$",
"data",
"[",
"'error'",
"]",
")",
"&&",
"(",
"int",
")",
"$",
"data",
"[",
"'error'",
"]",
"===",
"UPLOAD_ERR_NO_FILE",
")",
"{",
"return",
"true",
";",
"}",
"$",
"allFieldsAreEmpty",
"=",
"true",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"field",
"!==",
"null",
"&&",
"$",
"field",
"!==",
"''",
")",
"{",
"$",
"allFieldsAreEmpty",
"=",
"false",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"allFieldsAreEmpty",
")",
"{",
"if",
"(",
"(",
"$",
"flags",
"&",
"self",
"::",
"EMPTY_DATE",
")",
"&&",
"isset",
"(",
"$",
"data",
"[",
"'year'",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"(",
"$",
"flags",
"&",
"self",
"::",
"EMPTY_TIME",
")",
"&&",
"isset",
"(",
"$",
"data",
"[",
"'hour'",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Returns true if the field is empty in the passed data array
@param mixed $data Value to check against.
@param int $flags A bitmask of EMPTY_* flags which specify what is empty
@return bool | [
"Returns",
"true",
"if",
"the",
"field",
"is",
"empty",
"in",
"the",
"passed",
"data",
"array"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L2332-L2375 |
210,654 | cakephp/cakephp | src/Validation/Validator.php | Validator._processRules | protected function _processRules($field, ValidationSet $rules, $data, $newRecord)
{
$errors = [];
// Loading default provider in case there is none
$this->getProvider('default');
$message = 'The provided value is invalid';
if ($this->_useI18n) {
$message = __d('cake', 'The provided value is invalid');
}
foreach ($rules as $name => $rule) {
$result = $rule->process($data[$field], $this->_providers, compact('newRecord', 'data', 'field'));
if ($result === true) {
continue;
}
$errors[$name] = $message;
if (is_array($result) && $name === static::NESTED) {
$errors = $result;
}
if (is_string($result)) {
$errors[$name] = $result;
}
if ($rule->isLast()) {
break;
}
}
return $errors;
} | php | protected function _processRules($field, ValidationSet $rules, $data, $newRecord)
{
$errors = [];
// Loading default provider in case there is none
$this->getProvider('default');
$message = 'The provided value is invalid';
if ($this->_useI18n) {
$message = __d('cake', 'The provided value is invalid');
}
foreach ($rules as $name => $rule) {
$result = $rule->process($data[$field], $this->_providers, compact('newRecord', 'data', 'field'));
if ($result === true) {
continue;
}
$errors[$name] = $message;
if (is_array($result) && $name === static::NESTED) {
$errors = $result;
}
if (is_string($result)) {
$errors[$name] = $result;
}
if ($rule->isLast()) {
break;
}
}
return $errors;
} | [
"protected",
"function",
"_processRules",
"(",
"$",
"field",
",",
"ValidationSet",
"$",
"rules",
",",
"$",
"data",
",",
"$",
"newRecord",
")",
"{",
"$",
"errors",
"=",
"[",
"]",
";",
"// Loading default provider in case there is none",
"$",
"this",
"->",
"getProvider",
"(",
"'default'",
")",
";",
"$",
"message",
"=",
"'The provided value is invalid'",
";",
"if",
"(",
"$",
"this",
"->",
"_useI18n",
")",
"{",
"$",
"message",
"=",
"__d",
"(",
"'cake'",
",",
"'The provided value is invalid'",
")",
";",
"}",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"name",
"=>",
"$",
"rule",
")",
"{",
"$",
"result",
"=",
"$",
"rule",
"->",
"process",
"(",
"$",
"data",
"[",
"$",
"field",
"]",
",",
"$",
"this",
"->",
"_providers",
",",
"compact",
"(",
"'newRecord'",
",",
"'data'",
",",
"'field'",
")",
")",
";",
"if",
"(",
"$",
"result",
"===",
"true",
")",
"{",
"continue",
";",
"}",
"$",
"errors",
"[",
"$",
"name",
"]",
"=",
"$",
"message",
";",
"if",
"(",
"is_array",
"(",
"$",
"result",
")",
"&&",
"$",
"name",
"===",
"static",
"::",
"NESTED",
")",
"{",
"$",
"errors",
"=",
"$",
"result",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"result",
")",
")",
"{",
"$",
"errors",
"[",
"$",
"name",
"]",
"=",
"$",
"result",
";",
"}",
"if",
"(",
"$",
"rule",
"->",
"isLast",
"(",
")",
")",
"{",
"break",
";",
"}",
"}",
"return",
"$",
"errors",
";",
"}"
] | Iterates over each rule in the validation set and collects the errors resulting
from executing them
@param string $field The name of the field that is being processed
@param \Cake\Validation\ValidationSet $rules the list of rules for a field
@param array $data the full data passed to the validator
@param bool $newRecord whether is it a new record or an existing one
@return array | [
"Iterates",
"over",
"each",
"rule",
"in",
"the",
"validation",
"set",
"and",
"collects",
"the",
"errors",
"resulting",
"from",
"executing",
"them"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validator.php#L2387-L2418 |
210,655 | cakephp/cakephp | src/I18n/I18n.php | I18n.translators | public static function translators()
{
if (static::$_collection !== null) {
return static::$_collection;
}
static::$_collection = new TranslatorRegistry(
new PackageLocator,
new FormatterLocator([
'sprintf' => function () {
return new SprintfFormatter();
},
'default' => function () {
return new IcuFormatter();
},
]),
new TranslatorFactory,
static::getLocale()
);
if (class_exists('Cake\Cache\Cache')) {
static::$_collection->setCacher(Cache::engine('_cake_core_'));
}
return static::$_collection;
} | php | public static function translators()
{
if (static::$_collection !== null) {
return static::$_collection;
}
static::$_collection = new TranslatorRegistry(
new PackageLocator,
new FormatterLocator([
'sprintf' => function () {
return new SprintfFormatter();
},
'default' => function () {
return new IcuFormatter();
},
]),
new TranslatorFactory,
static::getLocale()
);
if (class_exists('Cake\Cache\Cache')) {
static::$_collection->setCacher(Cache::engine('_cake_core_'));
}
return static::$_collection;
} | [
"public",
"static",
"function",
"translators",
"(",
")",
"{",
"if",
"(",
"static",
"::",
"$",
"_collection",
"!==",
"null",
")",
"{",
"return",
"static",
"::",
"$",
"_collection",
";",
"}",
"static",
"::",
"$",
"_collection",
"=",
"new",
"TranslatorRegistry",
"(",
"new",
"PackageLocator",
",",
"new",
"FormatterLocator",
"(",
"[",
"'sprintf'",
"=>",
"function",
"(",
")",
"{",
"return",
"new",
"SprintfFormatter",
"(",
")",
";",
"}",
",",
"'default'",
"=>",
"function",
"(",
")",
"{",
"return",
"new",
"IcuFormatter",
"(",
")",
";",
"}",
",",
"]",
")",
",",
"new",
"TranslatorFactory",
",",
"static",
"::",
"getLocale",
"(",
")",
")",
";",
"if",
"(",
"class_exists",
"(",
"'Cake\\Cache\\Cache'",
")",
")",
"{",
"static",
"::",
"$",
"_collection",
"->",
"setCacher",
"(",
"Cache",
"::",
"engine",
"(",
"'_cake_core_'",
")",
")",
";",
"}",
"return",
"static",
"::",
"$",
"_collection",
";",
"}"
] | Returns the translators collection instance. It can be used
for getting specific translators based of their name and locale
or to configure some aspect of future translations that are not yet constructed.
@return \Cake\I18n\TranslatorRegistry The translators collection. | [
"Returns",
"the",
"translators",
"collection",
"instance",
".",
"It",
"can",
"be",
"used",
"for",
"getting",
"specific",
"translators",
"based",
"of",
"their",
"name",
"and",
"locale",
"or",
"to",
"configure",
"some",
"aspect",
"of",
"future",
"translations",
"that",
"are",
"not",
"yet",
"constructed",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/I18n/I18n.php#L58-L83 |
210,656 | cakephp/cakephp | src/I18n/I18n.php | I18n.setTranslator | public static function setTranslator($name, callable $loader, $locale = null)
{
$locale = $locale ?: static::getLocale();
$translators = static::translators();
$loader = $translators->setLoaderFallback($name, $loader);
$packages = $translators->getPackages();
$packages->set($name, $locale, $loader);
} | php | public static function setTranslator($name, callable $loader, $locale = null)
{
$locale = $locale ?: static::getLocale();
$translators = static::translators();
$loader = $translators->setLoaderFallback($name, $loader);
$packages = $translators->getPackages();
$packages->set($name, $locale, $loader);
} | [
"public",
"static",
"function",
"setTranslator",
"(",
"$",
"name",
",",
"callable",
"$",
"loader",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"locale",
"=",
"$",
"locale",
"?",
":",
"static",
"::",
"getLocale",
"(",
")",
";",
"$",
"translators",
"=",
"static",
"::",
"translators",
"(",
")",
";",
"$",
"loader",
"=",
"$",
"translators",
"->",
"setLoaderFallback",
"(",
"$",
"name",
",",
"$",
"loader",
")",
";",
"$",
"packages",
"=",
"$",
"translators",
"->",
"getPackages",
"(",
")",
";",
"$",
"packages",
"->",
"set",
"(",
"$",
"name",
",",
"$",
"locale",
",",
"$",
"loader",
")",
";",
"}"
] | Sets a translator.
Configures future translators, this is achieved by passing a callable
as the last argument of this function.
### Example:
```
I18n::setTranslator('default', function () {
$package = new \Aura\Intl\Package();
$package->setMessages([
'Cake' => 'Gâteau'
]);
return $package;
}, 'fr_FR');
$translator = I18n::getTranslator('default', 'fr_FR');
echo $translator->translate('Cake');
```
You can also use the `Cake\I18n\MessagesFileLoader` class to load a specific
file from a folder. For example for loading a `my_translations.po` file from
the `src/Locale/custom` folder, you would do:
```
I18n::setTranslator(
'default',
new MessagesFileLoader('my_translations', 'custom', 'po'),
'fr_FR'
);
```
@param string $name The domain of the translation messages.
@param callable $loader A callback function or callable class responsible for
constructing a translations package instance.
@param string|null $locale The locale for the translator.
@return void | [
"Sets",
"a",
"translator",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/I18n/I18n.php#L181-L189 |
210,657 | cakephp/cakephp | src/I18n/I18n.php | I18n.getTranslator | public static function getTranslator($name = 'default', $locale = null)
{
$translators = static::translators();
if ($locale) {
$currentLocale = $translators->getLocale();
$translators->setLocale($locale);
}
$translator = $translators->get($name);
if (isset($currentLocale)) {
$translators->setLocale($currentLocale);
}
return $translator;
} | php | public static function getTranslator($name = 'default', $locale = null)
{
$translators = static::translators();
if ($locale) {
$currentLocale = $translators->getLocale();
$translators->setLocale($locale);
}
$translator = $translators->get($name);
if (isset($currentLocale)) {
$translators->setLocale($currentLocale);
}
return $translator;
} | [
"public",
"static",
"function",
"getTranslator",
"(",
"$",
"name",
"=",
"'default'",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"translators",
"=",
"static",
"::",
"translators",
"(",
")",
";",
"if",
"(",
"$",
"locale",
")",
"{",
"$",
"currentLocale",
"=",
"$",
"translators",
"->",
"getLocale",
"(",
")",
";",
"$",
"translators",
"->",
"setLocale",
"(",
"$",
"locale",
")",
";",
"}",
"$",
"translator",
"=",
"$",
"translators",
"->",
"get",
"(",
"$",
"name",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"currentLocale",
")",
")",
"{",
"$",
"translators",
"->",
"setLocale",
"(",
"$",
"currentLocale",
")",
";",
"}",
"return",
"$",
"translator",
";",
"}"
] | Returns an instance of a translator that was configured for the name and locale.
If no locale is passed then it takes the value returned by the `getLocale()` method.
@param string $name The domain of the translation messages.
@param string|null $locale The locale for the translator.
@return \Aura\Intl\TranslatorInterface The configured translator.
@throws \Aura\Intl\Exception | [
"Returns",
"an",
"instance",
"of",
"a",
"translator",
"that",
"was",
"configured",
"for",
"the",
"name",
"and",
"locale",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/I18n/I18n.php#L201-L217 |
210,658 | cakephp/cakephp | src/I18n/I18n.php | I18n.getLocale | public static function getLocale()
{
static::getDefaultLocale();
$current = Locale::getDefault();
if ($current === '') {
$current = static::DEFAULT_LOCALE;
Locale::setDefault($current);
}
return $current;
} | php | public static function getLocale()
{
static::getDefaultLocale();
$current = Locale::getDefault();
if ($current === '') {
$current = static::DEFAULT_LOCALE;
Locale::setDefault($current);
}
return $current;
} | [
"public",
"static",
"function",
"getLocale",
"(",
")",
"{",
"static",
"::",
"getDefaultLocale",
"(",
")",
";",
"$",
"current",
"=",
"Locale",
"::",
"getDefault",
"(",
")",
";",
"if",
"(",
"$",
"current",
"===",
"''",
")",
"{",
"$",
"current",
"=",
"static",
"::",
"DEFAULT_LOCALE",
";",
"Locale",
"::",
"setDefault",
"(",
"$",
"current",
")",
";",
"}",
"return",
"$",
"current",
";",
"}"
] | Will return the currently configure locale as stored in the
`intl.default_locale` PHP setting.
@return string The name of the default locale. | [
"Will",
"return",
"the",
"currently",
"configure",
"locale",
"as",
"stored",
"in",
"the",
"intl",
".",
"default_locale",
"PHP",
"setting",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/I18n/I18n.php#L315-L325 |
210,659 | cakephp/cakephp | src/Controller/Component/RequestHandlerComponent.php | RequestHandlerComponent.convertXml | public function convertXml($xml)
{
try {
$xml = Xml::build($xml, ['return' => 'domdocument', 'readFile' => false]);
// We might not get child nodes if there are nested inline entities.
if ((int)$xml->childNodes->length > 0) {
return Xml::toArray($xml);
}
return [];
} catch (XmlException $e) {
return [];
}
} | php | public function convertXml($xml)
{
try {
$xml = Xml::build($xml, ['return' => 'domdocument', 'readFile' => false]);
// We might not get child nodes if there are nested inline entities.
if ((int)$xml->childNodes->length > 0) {
return Xml::toArray($xml);
}
return [];
} catch (XmlException $e) {
return [];
}
} | [
"public",
"function",
"convertXml",
"(",
"$",
"xml",
")",
"{",
"try",
"{",
"$",
"xml",
"=",
"Xml",
"::",
"build",
"(",
"$",
"xml",
",",
"[",
"'return'",
"=>",
"'domdocument'",
",",
"'readFile'",
"=>",
"false",
"]",
")",
";",
"// We might not get child nodes if there are nested inline entities.",
"if",
"(",
"(",
"int",
")",
"$",
"xml",
"->",
"childNodes",
"->",
"length",
">",
"0",
")",
"{",
"return",
"Xml",
"::",
"toArray",
"(",
"$",
"xml",
")",
";",
"}",
"return",
"[",
"]",
";",
"}",
"catch",
"(",
"XmlException",
"$",
"e",
")",
"{",
"return",
"[",
"]",
";",
"}",
"}"
] | Helper method to parse xml input data, due to lack of anonymous functions
this lives here.
@param string $xml XML string.
@return array Xml array data | [
"Helper",
"method",
"to",
"parse",
"xml",
"input",
"data",
"due",
"to",
"lack",
"of",
"anonymous",
"functions",
"this",
"lives",
"here",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/RequestHandlerComponent.php#L239-L252 |
210,660 | cakephp/cakephp | src/Controller/Component/RequestHandlerComponent.php | RequestHandlerComponent.beforeRender | public function beforeRender(Event $event)
{
/** @var \Cake\Controller\Controller $controller */
$controller = $event->getSubject();
$response = $controller->getResponse();
$request = $controller->getRequest();
if ($this->ext && !in_array($this->ext, ['html', 'htm'])) {
if (!$response->getMimeType($this->ext)) {
throw new NotFoundException('Invoked extension not recognized/configured: ' . $this->ext);
}
$this->renderAs($controller, $this->ext);
$response = $controller->response;
} else {
$response = $response->withCharset(Configure::read('App.encoding'));
}
if ($this->_config['checkHttpCache'] &&
$response->checkNotModified($request)
) {
$controller->setResponse($response);
return false;
}
$controller->setResponse($response);
} | php | public function beforeRender(Event $event)
{
/** @var \Cake\Controller\Controller $controller */
$controller = $event->getSubject();
$response = $controller->getResponse();
$request = $controller->getRequest();
if ($this->ext && !in_array($this->ext, ['html', 'htm'])) {
if (!$response->getMimeType($this->ext)) {
throw new NotFoundException('Invoked extension not recognized/configured: ' . $this->ext);
}
$this->renderAs($controller, $this->ext);
$response = $controller->response;
} else {
$response = $response->withCharset(Configure::read('App.encoding'));
}
if ($this->_config['checkHttpCache'] &&
$response->checkNotModified($request)
) {
$controller->setResponse($response);
return false;
}
$controller->setResponse($response);
} | [
"public",
"function",
"beforeRender",
"(",
"Event",
"$",
"event",
")",
"{",
"/** @var \\Cake\\Controller\\Controller $controller */",
"$",
"controller",
"=",
"$",
"event",
"->",
"getSubject",
"(",
")",
";",
"$",
"response",
"=",
"$",
"controller",
"->",
"getResponse",
"(",
")",
";",
"$",
"request",
"=",
"$",
"controller",
"->",
"getRequest",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"ext",
"&&",
"!",
"in_array",
"(",
"$",
"this",
"->",
"ext",
",",
"[",
"'html'",
",",
"'htm'",
"]",
")",
")",
"{",
"if",
"(",
"!",
"$",
"response",
"->",
"getMimeType",
"(",
"$",
"this",
"->",
"ext",
")",
")",
"{",
"throw",
"new",
"NotFoundException",
"(",
"'Invoked extension not recognized/configured: '",
".",
"$",
"this",
"->",
"ext",
")",
";",
"}",
"$",
"this",
"->",
"renderAs",
"(",
"$",
"controller",
",",
"$",
"this",
"->",
"ext",
")",
";",
"$",
"response",
"=",
"$",
"controller",
"->",
"response",
";",
"}",
"else",
"{",
"$",
"response",
"=",
"$",
"response",
"->",
"withCharset",
"(",
"Configure",
"::",
"read",
"(",
"'App.encoding'",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_config",
"[",
"'checkHttpCache'",
"]",
"&&",
"$",
"response",
"->",
"checkNotModified",
"(",
"$",
"request",
")",
")",
"{",
"$",
"controller",
"->",
"setResponse",
"(",
"$",
"response",
")",
";",
"return",
"false",
";",
"}",
"$",
"controller",
"->",
"setResponse",
"(",
"$",
"response",
")",
";",
"}"
] | Checks if the response can be considered different according to the request
headers, and the caching response headers. If it was not modified, then the
render process is skipped. And the client will get a blank response with a
"304 Not Modified" header.
- If Router::extensions() is enabled, the layout and template type are
switched based on the parsed extension or `Accept` header. For example,
if `controller/action.xml` is requested, the view path becomes
`app/View/Controller/xml/action.ctp`. Also if `controller/action` is
requested with `Accept: application/xml` in the headers the view
path will become `app/View/Controller/xml/action.ctp`. Layout and template
types will only switch to mime-types recognized by Cake\Http\Response.
If you need to declare additional mime-types, you can do so using
Cake\Http\Response::type() in your controller's beforeFilter() method.
- If a helper with the same name as the extension exists, it is added to
the controller.
- If the extension is of a type that RequestHandler understands, it will
set that Content-type in the response header.
@param \Cake\Event\Event $event The Controller.beforeRender event.
@return bool false if the render process should be aborted
@throws \Cake\Http\Exception\NotFoundException If invoked extension is not configured. | [
"Checks",
"if",
"the",
"response",
"can",
"be",
"considered",
"different",
"according",
"to",
"the",
"request",
"headers",
"and",
"the",
"caching",
"response",
"headers",
".",
"If",
"it",
"was",
"not",
"modified",
"then",
"the",
"render",
"process",
"is",
"skipped",
".",
"And",
"the",
"client",
"will",
"get",
"a",
"blank",
"response",
"with",
"a",
"304",
"Not",
"Modified",
"header",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/RequestHandlerComponent.php#L328-L354 |
210,661 | cakephp/cakephp | src/Controller/Component/RequestHandlerComponent.php | RequestHandlerComponent.isMobile | public function isMobile()
{
deprecationWarning(
'RequestHandlerComponent::isMobile() is deprecated. Use ServerRequest::is(\'mobile\') instead.'
);
$request = $this->getController()->getRequest();
return $request->is('mobile') || $this->accepts('wap');
} | php | public function isMobile()
{
deprecationWarning(
'RequestHandlerComponent::isMobile() is deprecated. Use ServerRequest::is(\'mobile\') instead.'
);
$request = $this->getController()->getRequest();
return $request->is('mobile') || $this->accepts('wap');
} | [
"public",
"function",
"isMobile",
"(",
")",
"{",
"deprecationWarning",
"(",
"'RequestHandlerComponent::isMobile() is deprecated. Use ServerRequest::is(\\'mobile\\') instead.'",
")",
";",
"$",
"request",
"=",
"$",
"this",
"->",
"getController",
"(",
")",
"->",
"getRequest",
"(",
")",
";",
"return",
"$",
"request",
"->",
"is",
"(",
"'mobile'",
")",
"||",
"$",
"this",
"->",
"accepts",
"(",
"'wap'",
")",
";",
"}"
] | Returns true if user agent string matches a mobile web browser, or if the
client accepts WAP content.
@return bool True if user agent is a mobile web browser
@deprecated 3.7.0 Use ServerRequest::is('mobile') instead. | [
"Returns",
"true",
"if",
"user",
"agent",
"string",
"matches",
"a",
"mobile",
"web",
"browser",
"or",
"if",
"the",
"client",
"accepts",
"WAP",
"content",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/RequestHandlerComponent.php#L408-L417 |
210,662 | cakephp/cakephp | src/Controller/Component/RequestHandlerComponent.php | RequestHandlerComponent.respondAs | public function respondAs($type, array $options = [])
{
$defaults = ['index' => null, 'charset' => null, 'attachment' => false];
$options += $defaults;
$cType = $type;
$controller = $this->getController();
$response = $controller->getResponse();
$request = $controller->getRequest();
if (strpos($type, '/') === false) {
$cType = $response->getMimeType($type);
}
if (is_array($cType)) {
if (isset($cType[$options['index']])) {
$cType = $cType[$options['index']];
}
if ($this->prefers($cType)) {
$cType = $this->prefers($cType);
} else {
$cType = $cType[0];
}
}
if (!$type) {
return false;
}
if (!$request->getParam('requested')) {
$response = $response->withType($cType);
}
if (!empty($options['charset'])) {
$response = $response->withCharset($options['charset']);
}
if (!empty($options['attachment'])) {
$response = $response->withDownload($options['attachment']);
}
$controller->setResponse($response);
return true;
} | php | public function respondAs($type, array $options = [])
{
$defaults = ['index' => null, 'charset' => null, 'attachment' => false];
$options += $defaults;
$cType = $type;
$controller = $this->getController();
$response = $controller->getResponse();
$request = $controller->getRequest();
if (strpos($type, '/') === false) {
$cType = $response->getMimeType($type);
}
if (is_array($cType)) {
if (isset($cType[$options['index']])) {
$cType = $cType[$options['index']];
}
if ($this->prefers($cType)) {
$cType = $this->prefers($cType);
} else {
$cType = $cType[0];
}
}
if (!$type) {
return false;
}
if (!$request->getParam('requested')) {
$response = $response->withType($cType);
}
if (!empty($options['charset'])) {
$response = $response->withCharset($options['charset']);
}
if (!empty($options['attachment'])) {
$response = $response->withDownload($options['attachment']);
}
$controller->setResponse($response);
return true;
} | [
"public",
"function",
"respondAs",
"(",
"$",
"type",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'index'",
"=>",
"null",
",",
"'charset'",
"=>",
"null",
",",
"'attachment'",
"=>",
"false",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"$",
"cType",
"=",
"$",
"type",
";",
"$",
"controller",
"=",
"$",
"this",
"->",
"getController",
"(",
")",
";",
"$",
"response",
"=",
"$",
"controller",
"->",
"getResponse",
"(",
")",
";",
"$",
"request",
"=",
"$",
"controller",
"->",
"getRequest",
"(",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"type",
",",
"'/'",
")",
"===",
"false",
")",
"{",
"$",
"cType",
"=",
"$",
"response",
"->",
"getMimeType",
"(",
"$",
"type",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"cType",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"cType",
"[",
"$",
"options",
"[",
"'index'",
"]",
"]",
")",
")",
"{",
"$",
"cType",
"=",
"$",
"cType",
"[",
"$",
"options",
"[",
"'index'",
"]",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"prefers",
"(",
"$",
"cType",
")",
")",
"{",
"$",
"cType",
"=",
"$",
"this",
"->",
"prefers",
"(",
"$",
"cType",
")",
";",
"}",
"else",
"{",
"$",
"cType",
"=",
"$",
"cType",
"[",
"0",
"]",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"type",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"request",
"->",
"getParam",
"(",
"'requested'",
")",
")",
"{",
"$",
"response",
"=",
"$",
"response",
"->",
"withType",
"(",
"$",
"cType",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'charset'",
"]",
")",
")",
"{",
"$",
"response",
"=",
"$",
"response",
"->",
"withCharset",
"(",
"$",
"options",
"[",
"'charset'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'attachment'",
"]",
")",
")",
"{",
"$",
"response",
"=",
"$",
"response",
"->",
"withDownload",
"(",
"$",
"options",
"[",
"'attachment'",
"]",
")",
";",
"}",
"$",
"controller",
"->",
"setResponse",
"(",
"$",
"response",
")",
";",
"return",
"true",
";",
"}"
] | Sets the response header based on type map index name. This wraps several methods
available on Cake\Http\Response. It also allows you to use Content-Type aliases.
@param string|array $type Friendly type name, i.e. 'html' or 'xml', or a full content-type,
like 'application/x-shockwave'.
@param array $options If $type is a friendly type name that is associated with
more than one type of content, $index is used to select which content-type to use.
@return bool Returns false if the friendly type name given in $type does
not exist in the type map, or if the Content-type header has
already been set by this method. | [
"Sets",
"the",
"response",
"header",
"based",
"on",
"type",
"map",
"index",
"name",
".",
"This",
"wraps",
"several",
"methods",
"available",
"on",
"Cake",
"\\",
"Http",
"\\",
"Response",
".",
"It",
"also",
"allows",
"you",
"to",
"use",
"Content",
"-",
"Type",
"aliases",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Controller/Component/RequestHandlerComponent.php#L663-L703 |
210,663 | cakephp/cakephp | src/I18n/Parser/PoFileParser.php | PoFileParser._addMessage | protected function _addMessage(array &$messages, array $item)
{
if (empty($item['ids']['singular']) && empty($item['ids']['plural'])) {
return;
}
$singular = stripcslashes($item['ids']['singular']);
$context = isset($item['context']) ? $item['context'] : null;
$translation = $item['translated'];
if (is_array($translation)) {
$translation = $translation[0];
}
$translation = stripcslashes($translation);
if ($context !== null && !isset($messages[$singular]['_context'][$context])) {
$messages[$singular]['_context'][$context] = $translation;
} elseif (!isset($messages[$singular]['_context'][''])) {
$messages[$singular]['_context'][''] = $translation;
}
if (isset($item['ids']['plural'])) {
$plurals = $item['translated'];
// PO are by definition indexed so sort by index.
ksort($plurals);
// Make sure every index is filled.
end($plurals);
$count = key($plurals);
// Fill missing spots with an empty string.
$empties = array_fill(0, $count + 1, '');
$plurals += $empties;
ksort($plurals);
$plurals = array_map('stripcslashes', $plurals);
$key = stripcslashes($item['ids']['plural']);
if ($context !== null) {
$messages[Translator::PLURAL_PREFIX . $key]['_context'][$context] = $plurals;
} else {
$messages[Translator::PLURAL_PREFIX . $key]['_context'][''] = $plurals;
}
}
} | php | protected function _addMessage(array &$messages, array $item)
{
if (empty($item['ids']['singular']) && empty($item['ids']['plural'])) {
return;
}
$singular = stripcslashes($item['ids']['singular']);
$context = isset($item['context']) ? $item['context'] : null;
$translation = $item['translated'];
if (is_array($translation)) {
$translation = $translation[0];
}
$translation = stripcslashes($translation);
if ($context !== null && !isset($messages[$singular]['_context'][$context])) {
$messages[$singular]['_context'][$context] = $translation;
} elseif (!isset($messages[$singular]['_context'][''])) {
$messages[$singular]['_context'][''] = $translation;
}
if (isset($item['ids']['plural'])) {
$plurals = $item['translated'];
// PO are by definition indexed so sort by index.
ksort($plurals);
// Make sure every index is filled.
end($plurals);
$count = key($plurals);
// Fill missing spots with an empty string.
$empties = array_fill(0, $count + 1, '');
$plurals += $empties;
ksort($plurals);
$plurals = array_map('stripcslashes', $plurals);
$key = stripcslashes($item['ids']['plural']);
if ($context !== null) {
$messages[Translator::PLURAL_PREFIX . $key]['_context'][$context] = $plurals;
} else {
$messages[Translator::PLURAL_PREFIX . $key]['_context'][''] = $plurals;
}
}
} | [
"protected",
"function",
"_addMessage",
"(",
"array",
"&",
"$",
"messages",
",",
"array",
"$",
"item",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"item",
"[",
"'ids'",
"]",
"[",
"'singular'",
"]",
")",
"&&",
"empty",
"(",
"$",
"item",
"[",
"'ids'",
"]",
"[",
"'plural'",
"]",
")",
")",
"{",
"return",
";",
"}",
"$",
"singular",
"=",
"stripcslashes",
"(",
"$",
"item",
"[",
"'ids'",
"]",
"[",
"'singular'",
"]",
")",
";",
"$",
"context",
"=",
"isset",
"(",
"$",
"item",
"[",
"'context'",
"]",
")",
"?",
"$",
"item",
"[",
"'context'",
"]",
":",
"null",
";",
"$",
"translation",
"=",
"$",
"item",
"[",
"'translated'",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"translation",
")",
")",
"{",
"$",
"translation",
"=",
"$",
"translation",
"[",
"0",
"]",
";",
"}",
"$",
"translation",
"=",
"stripcslashes",
"(",
"$",
"translation",
")",
";",
"if",
"(",
"$",
"context",
"!==",
"null",
"&&",
"!",
"isset",
"(",
"$",
"messages",
"[",
"$",
"singular",
"]",
"[",
"'_context'",
"]",
"[",
"$",
"context",
"]",
")",
")",
"{",
"$",
"messages",
"[",
"$",
"singular",
"]",
"[",
"'_context'",
"]",
"[",
"$",
"context",
"]",
"=",
"$",
"translation",
";",
"}",
"elseif",
"(",
"!",
"isset",
"(",
"$",
"messages",
"[",
"$",
"singular",
"]",
"[",
"'_context'",
"]",
"[",
"''",
"]",
")",
")",
"{",
"$",
"messages",
"[",
"$",
"singular",
"]",
"[",
"'_context'",
"]",
"[",
"''",
"]",
"=",
"$",
"translation",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"item",
"[",
"'ids'",
"]",
"[",
"'plural'",
"]",
")",
")",
"{",
"$",
"plurals",
"=",
"$",
"item",
"[",
"'translated'",
"]",
";",
"// PO are by definition indexed so sort by index.",
"ksort",
"(",
"$",
"plurals",
")",
";",
"// Make sure every index is filled.",
"end",
"(",
"$",
"plurals",
")",
";",
"$",
"count",
"=",
"key",
"(",
"$",
"plurals",
")",
";",
"// Fill missing spots with an empty string.",
"$",
"empties",
"=",
"array_fill",
"(",
"0",
",",
"$",
"count",
"+",
"1",
",",
"''",
")",
";",
"$",
"plurals",
"+=",
"$",
"empties",
";",
"ksort",
"(",
"$",
"plurals",
")",
";",
"$",
"plurals",
"=",
"array_map",
"(",
"'stripcslashes'",
",",
"$",
"plurals",
")",
";",
"$",
"key",
"=",
"stripcslashes",
"(",
"$",
"item",
"[",
"'ids'",
"]",
"[",
"'plural'",
"]",
")",
";",
"if",
"(",
"$",
"context",
"!==",
"null",
")",
"{",
"$",
"messages",
"[",
"Translator",
"::",
"PLURAL_PREFIX",
".",
"$",
"key",
"]",
"[",
"'_context'",
"]",
"[",
"$",
"context",
"]",
"=",
"$",
"plurals",
";",
"}",
"else",
"{",
"$",
"messages",
"[",
"Translator",
"::",
"PLURAL_PREFIX",
".",
"$",
"key",
"]",
"[",
"'_context'",
"]",
"[",
"''",
"]",
"=",
"$",
"plurals",
";",
"}",
"}",
"}"
] | Saves a translation item to the messages.
@param array $messages The messages array being collected from the file
@param array $item The current item being inspected
@return void | [
"Saves",
"a",
"translation",
"item",
"to",
"the",
"messages",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/I18n/Parser/PoFileParser.php#L138-L183 |
210,664 | cakephp/cakephp | src/Database/Log/LoggingStatement.php | LoggingStatement.execute | public function execute($params = null)
{
$t = microtime(true);
$query = new LoggedQuery();
try {
$result = parent::execute($params);
} catch (Exception $e) {
$e->queryString = $this->queryString;
$query->error = $e;
$this->_log($query, $params, $t);
throw $e;
}
$query->numRows = $this->rowCount();
$this->_log($query, $params, $t);
return $result;
} | php | public function execute($params = null)
{
$t = microtime(true);
$query = new LoggedQuery();
try {
$result = parent::execute($params);
} catch (Exception $e) {
$e->queryString = $this->queryString;
$query->error = $e;
$this->_log($query, $params, $t);
throw $e;
}
$query->numRows = $this->rowCount();
$this->_log($query, $params, $t);
return $result;
} | [
"public",
"function",
"execute",
"(",
"$",
"params",
"=",
"null",
")",
"{",
"$",
"t",
"=",
"microtime",
"(",
"true",
")",
";",
"$",
"query",
"=",
"new",
"LoggedQuery",
"(",
")",
";",
"try",
"{",
"$",
"result",
"=",
"parent",
"::",
"execute",
"(",
"$",
"params",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"e",
"->",
"queryString",
"=",
"$",
"this",
"->",
"queryString",
";",
"$",
"query",
"->",
"error",
"=",
"$",
"e",
";",
"$",
"this",
"->",
"_log",
"(",
"$",
"query",
",",
"$",
"params",
",",
"$",
"t",
")",
";",
"throw",
"$",
"e",
";",
"}",
"$",
"query",
"->",
"numRows",
"=",
"$",
"this",
"->",
"rowCount",
"(",
")",
";",
"$",
"this",
"->",
"_log",
"(",
"$",
"query",
",",
"$",
"params",
",",
"$",
"t",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Wrapper for the execute function to calculate time spent
and log the query afterwards.
@param array|null $params List of values to be bound to query
@return bool True on success, false otherwise
@throws \Exception Re-throws any exception raised during query execution. | [
"Wrapper",
"for",
"the",
"execute",
"function",
"to",
"calculate",
"time",
"spent",
"and",
"log",
"the",
"query",
"afterwards",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Log/LoggingStatement.php#L50-L68 |
210,665 | cakephp/cakephp | src/Database/Log/LoggingStatement.php | LoggingStatement._log | protected function _log($query, $params, $startTime)
{
$query->took = (int)round((microtime(true) - $startTime) * 1000, 0);
$query->params = $params ?: $this->_compiledParams;
$query->query = $this->queryString;
$this->getLogger()->log($query);
} | php | protected function _log($query, $params, $startTime)
{
$query->took = (int)round((microtime(true) - $startTime) * 1000, 0);
$query->params = $params ?: $this->_compiledParams;
$query->query = $this->queryString;
$this->getLogger()->log($query);
} | [
"protected",
"function",
"_log",
"(",
"$",
"query",
",",
"$",
"params",
",",
"$",
"startTime",
")",
"{",
"$",
"query",
"->",
"took",
"=",
"(",
"int",
")",
"round",
"(",
"(",
"microtime",
"(",
"true",
")",
"-",
"$",
"startTime",
")",
"*",
"1000",
",",
"0",
")",
";",
"$",
"query",
"->",
"params",
"=",
"$",
"params",
"?",
":",
"$",
"this",
"->",
"_compiledParams",
";",
"$",
"query",
"->",
"query",
"=",
"$",
"this",
"->",
"queryString",
";",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"log",
"(",
"$",
"query",
")",
";",
"}"
] | Copies the logging data to the passed LoggedQuery and sends it
to the logging system.
@param \Cake\Database\Log\LoggedQuery $query The query to log.
@param array $params List of values to be bound to query.
@param float $startTime The microtime when the query was executed.
@return void | [
"Copies",
"the",
"logging",
"data",
"to",
"the",
"passed",
"LoggedQuery",
"and",
"sends",
"it",
"to",
"the",
"logging",
"system",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Log/LoggingStatement.php#L79-L85 |
210,666 | cakephp/cakephp | src/Database/Log/LoggingStatement.php | LoggingStatement.bindValue | public function bindValue($column, $value, $type = 'string')
{
parent::bindValue($column, $value, $type);
if ($type === null) {
$type = 'string';
}
if (!ctype_digit($type)) {
$value = $this->cast($value, $type)[0];
}
$this->_compiledParams[$column] = $value;
} | php | public function bindValue($column, $value, $type = 'string')
{
parent::bindValue($column, $value, $type);
if ($type === null) {
$type = 'string';
}
if (!ctype_digit($type)) {
$value = $this->cast($value, $type)[0];
}
$this->_compiledParams[$column] = $value;
} | [
"public",
"function",
"bindValue",
"(",
"$",
"column",
",",
"$",
"value",
",",
"$",
"type",
"=",
"'string'",
")",
"{",
"parent",
"::",
"bindValue",
"(",
"$",
"column",
",",
"$",
"value",
",",
"$",
"type",
")",
";",
"if",
"(",
"$",
"type",
"===",
"null",
")",
"{",
"$",
"type",
"=",
"'string'",
";",
"}",
"if",
"(",
"!",
"ctype_digit",
"(",
"$",
"type",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"cast",
"(",
"$",
"value",
",",
"$",
"type",
")",
"[",
"0",
"]",
";",
"}",
"$",
"this",
"->",
"_compiledParams",
"[",
"$",
"column",
"]",
"=",
"$",
"value",
";",
"}"
] | Wrapper for bindValue function to gather each parameter to be later used
in the logger function.
@param string|int $column Name or param position to be bound
@param mixed $value The value to bind to variable in query
@param string|int|null $type PDO type or name of configured Type class
@return void | [
"Wrapper",
"for",
"bindValue",
"function",
"to",
"gather",
"each",
"parameter",
"to",
"be",
"later",
"used",
"in",
"the",
"logger",
"function",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Log/LoggingStatement.php#L96-L106 |
210,667 | cakephp/cakephp | src/Database/Log/LoggingStatement.php | LoggingStatement.logger | public function logger($instance = null)
{
deprecationWarning(
'LoggingStatement::logger() is deprecated. ' .
'Use LoggingStatement::setLogger()/getLogger() instead.'
);
if ($instance === null) {
return $this->getLogger();
}
return $this->_logger = $instance;
} | php | public function logger($instance = null)
{
deprecationWarning(
'LoggingStatement::logger() is deprecated. ' .
'Use LoggingStatement::setLogger()/getLogger() instead.'
);
if ($instance === null) {
return $this->getLogger();
}
return $this->_logger = $instance;
} | [
"public",
"function",
"logger",
"(",
"$",
"instance",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"'LoggingStatement::logger() is deprecated. '",
".",
"'Use LoggingStatement::setLogger()/getLogger() instead.'",
")",
";",
"if",
"(",
"$",
"instance",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getLogger",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_logger",
"=",
"$",
"instance",
";",
"}"
] | Sets the logger object instance. When called with no arguments
it returns the currently setup logger instance
@deprecated 3.5.0 Use getLogger() and setLogger() instead.
@param \Cake\Database\Log\QueryLogger|null $instance Logger object instance.
@return \Cake\Database\Log\QueryLogger|null Logger instance | [
"Sets",
"the",
"logger",
"object",
"instance",
".",
"When",
"called",
"with",
"no",
"arguments",
"it",
"returns",
"the",
"currently",
"setup",
"logger",
"instance"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Log/LoggingStatement.php#L116-L127 |
210,668 | cakephp/cakephp | src/ORM/Behavior/TimestampBehavior.php | TimestampBehavior.timestamp | public function timestamp(DateTime $ts = null, $refreshTimestamp = false)
{
if ($ts) {
if ($this->_config['refreshTimestamp']) {
$this->_config['refreshTimestamp'] = false;
}
$this->_ts = new Time($ts);
} elseif ($this->_ts === null || $refreshTimestamp) {
$this->_ts = new Time();
}
return $this->_ts;
} | php | public function timestamp(DateTime $ts = null, $refreshTimestamp = false)
{
if ($ts) {
if ($this->_config['refreshTimestamp']) {
$this->_config['refreshTimestamp'] = false;
}
$this->_ts = new Time($ts);
} elseif ($this->_ts === null || $refreshTimestamp) {
$this->_ts = new Time();
}
return $this->_ts;
} | [
"public",
"function",
"timestamp",
"(",
"DateTime",
"$",
"ts",
"=",
"null",
",",
"$",
"refreshTimestamp",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"ts",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_config",
"[",
"'refreshTimestamp'",
"]",
")",
"{",
"$",
"this",
"->",
"_config",
"[",
"'refreshTimestamp'",
"]",
"=",
"false",
";",
"}",
"$",
"this",
"->",
"_ts",
"=",
"new",
"Time",
"(",
"$",
"ts",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"_ts",
"===",
"null",
"||",
"$",
"refreshTimestamp",
")",
"{",
"$",
"this",
"->",
"_ts",
"=",
"new",
"Time",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_ts",
";",
"}"
] | Get or set the timestamp to be used
Set the timestamp to the given DateTime object, or if not passed a new DateTime object
If an explicit date time is passed, the config option `refreshTimestamp` is
automatically set to false.
@param \DateTime|null $ts Timestamp
@param bool $refreshTimestamp If true timestamp is refreshed.
@return \Cake\I18n\Time | [
"Get",
"or",
"set",
"the",
"timestamp",
"to",
"be",
"used"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TimestampBehavior.php#L141-L153 |
210,669 | cakephp/cakephp | src/ORM/Behavior/TimestampBehavior.php | TimestampBehavior.touch | public function touch(EntityInterface $entity, $eventName = 'Model.beforeSave')
{
$events = $this->_config['events'];
if (empty($events[$eventName])) {
return false;
}
$return = false;
$refresh = $this->_config['refreshTimestamp'];
foreach ($events[$eventName] as $field => $when) {
if (in_array($when, ['always', 'existing'])) {
$return = true;
$entity->setDirty($field, false);
$this->_updateField($entity, $field, $refresh);
}
}
return $return;
} | php | public function touch(EntityInterface $entity, $eventName = 'Model.beforeSave')
{
$events = $this->_config['events'];
if (empty($events[$eventName])) {
return false;
}
$return = false;
$refresh = $this->_config['refreshTimestamp'];
foreach ($events[$eventName] as $field => $when) {
if (in_array($when, ['always', 'existing'])) {
$return = true;
$entity->setDirty($field, false);
$this->_updateField($entity, $field, $refresh);
}
}
return $return;
} | [
"public",
"function",
"touch",
"(",
"EntityInterface",
"$",
"entity",
",",
"$",
"eventName",
"=",
"'Model.beforeSave'",
")",
"{",
"$",
"events",
"=",
"$",
"this",
"->",
"_config",
"[",
"'events'",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"events",
"[",
"$",
"eventName",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"return",
"=",
"false",
";",
"$",
"refresh",
"=",
"$",
"this",
"->",
"_config",
"[",
"'refreshTimestamp'",
"]",
";",
"foreach",
"(",
"$",
"events",
"[",
"$",
"eventName",
"]",
"as",
"$",
"field",
"=>",
"$",
"when",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"when",
",",
"[",
"'always'",
",",
"'existing'",
"]",
")",
")",
"{",
"$",
"return",
"=",
"true",
";",
"$",
"entity",
"->",
"setDirty",
"(",
"$",
"field",
",",
"false",
")",
";",
"$",
"this",
"->",
"_updateField",
"(",
"$",
"entity",
",",
"$",
"field",
",",
"$",
"refresh",
")",
";",
"}",
"}",
"return",
"$",
"return",
";",
"}"
] | Touch an entity
Bumps timestamp fields for an entity. For any fields configured to be updated
"always" or "existing", update the timestamp value. This method will overwrite
any pre-existing value.
@param \Cake\Datasource\EntityInterface $entity Entity instance.
@param string $eventName Event name.
@return bool true if a field is updated, false if no action performed | [
"Touch",
"an",
"entity"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TimestampBehavior.php#L166-L185 |
210,670 | cakephp/cakephp | src/Collection/Iterator/UnfoldIterator.php | UnfoldIterator.getChildren | public function getChildren()
{
$current = $this->current();
$key = $this->key();
$unfolder = $this->_unfolder;
return new NoChildrenIterator($unfolder($current, $key, $this->_innerIterator));
} | php | public function getChildren()
{
$current = $this->current();
$key = $this->key();
$unfolder = $this->_unfolder;
return new NoChildrenIterator($unfolder($current, $key, $this->_innerIterator));
} | [
"public",
"function",
"getChildren",
"(",
")",
"{",
"$",
"current",
"=",
"$",
"this",
"->",
"current",
"(",
")",
";",
"$",
"key",
"=",
"$",
"this",
"->",
"key",
"(",
")",
";",
"$",
"unfolder",
"=",
"$",
"this",
"->",
"_unfolder",
";",
"return",
"new",
"NoChildrenIterator",
"(",
"$",
"unfolder",
"(",
"$",
"current",
",",
"$",
"key",
",",
"$",
"this",
"->",
"_innerIterator",
")",
")",
";",
"}"
] | Returns an iterator containing the items generated by transforming
the current value with the callable function.
@return \RecursiveIterator | [
"Returns",
"an",
"iterator",
"containing",
"the",
"items",
"generated",
"by",
"transforming",
"the",
"current",
"value",
"with",
"the",
"callable",
"function",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Collection/Iterator/UnfoldIterator.php#L78-L85 |
210,671 | cakephp/cakephp | src/View/CellTrait.php | CellTrait.cell | protected function cell($cell, array $data = [], array $options = [])
{
$parts = explode('::', $cell);
if (count($parts) === 2) {
list($pluginAndCell, $action) = [$parts[0], $parts[1]];
} else {
list($pluginAndCell, $action) = [$parts[0], 'display'];
}
list($plugin) = pluginSplit($pluginAndCell);
$className = App::className($pluginAndCell, 'View/Cell', 'Cell');
if (!$className) {
throw new MissingCellException(['className' => $pluginAndCell . 'Cell']);
}
if (!empty($data)) {
$data = array_values($data);
}
$options = ['action' => $action, 'args' => $data] + $options;
$cell = $this->_createCell($className, $action, $plugin, $options);
return $cell;
} | php | protected function cell($cell, array $data = [], array $options = [])
{
$parts = explode('::', $cell);
if (count($parts) === 2) {
list($pluginAndCell, $action) = [$parts[0], $parts[1]];
} else {
list($pluginAndCell, $action) = [$parts[0], 'display'];
}
list($plugin) = pluginSplit($pluginAndCell);
$className = App::className($pluginAndCell, 'View/Cell', 'Cell');
if (!$className) {
throw new MissingCellException(['className' => $pluginAndCell . 'Cell']);
}
if (!empty($data)) {
$data = array_values($data);
}
$options = ['action' => $action, 'args' => $data] + $options;
$cell = $this->_createCell($className, $action, $plugin, $options);
return $cell;
} | [
"protected",
"function",
"cell",
"(",
"$",
"cell",
",",
"array",
"$",
"data",
"=",
"[",
"]",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'::'",
",",
"$",
"cell",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
"===",
"2",
")",
"{",
"list",
"(",
"$",
"pluginAndCell",
",",
"$",
"action",
")",
"=",
"[",
"$",
"parts",
"[",
"0",
"]",
",",
"$",
"parts",
"[",
"1",
"]",
"]",
";",
"}",
"else",
"{",
"list",
"(",
"$",
"pluginAndCell",
",",
"$",
"action",
")",
"=",
"[",
"$",
"parts",
"[",
"0",
"]",
",",
"'display'",
"]",
";",
"}",
"list",
"(",
"$",
"plugin",
")",
"=",
"pluginSplit",
"(",
"$",
"pluginAndCell",
")",
";",
"$",
"className",
"=",
"App",
"::",
"className",
"(",
"$",
"pluginAndCell",
",",
"'View/Cell'",
",",
"'Cell'",
")",
";",
"if",
"(",
"!",
"$",
"className",
")",
"{",
"throw",
"new",
"MissingCellException",
"(",
"[",
"'className'",
"=>",
"$",
"pluginAndCell",
".",
"'Cell'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"array_values",
"(",
"$",
"data",
")",
";",
"}",
"$",
"options",
"=",
"[",
"'action'",
"=>",
"$",
"action",
",",
"'args'",
"=>",
"$",
"data",
"]",
"+",
"$",
"options",
";",
"$",
"cell",
"=",
"$",
"this",
"->",
"_createCell",
"(",
"$",
"className",
",",
"$",
"action",
",",
"$",
"plugin",
",",
"$",
"options",
")",
";",
"return",
"$",
"cell",
";",
"}"
] | Renders the given cell.
Example:
```
// Taxonomy\View\Cell\TagCloudCell::smallList()
$cell = $this->cell('Taxonomy.TagCloud::smallList', ['limit' => 10]);
// App\View\Cell\TagCloudCell::smallList()
$cell = $this->cell('TagCloud::smallList', ['limit' => 10]);
```
The `display` action will be used by default when no action is provided:
```
// Taxonomy\View\Cell\TagCloudCell::display()
$cell = $this->cell('Taxonomy.TagCloud');
```
Cells are not rendered until they are echoed.
@param string $cell You must indicate cell name, and optionally a cell action. e.g.: `TagCloud::smallList`
will invoke `View\Cell\TagCloudCell::smallList()`, `display` action will be invoked by default when none is provided.
@param array $data Additional arguments for cell method. e.g.:
`cell('TagCloud::smallList', ['a1' => 'v1', 'a2' => 'v2'])` maps to `View\Cell\TagCloud::smallList(v1, v2)`
@param array $options Options for Cell's constructor
@return \Cake\View\Cell The cell instance
@throws \Cake\View\Exception\MissingCellException If Cell class was not found.
@throws \BadMethodCallException If Cell class does not specified cell action. | [
"Renders",
"the",
"given",
"cell",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/CellTrait.php#L58-L82 |
210,672 | cakephp/cakephp | src/View/CellTrait.php | CellTrait._createCell | protected function _createCell($className, $action, $plugin, $options)
{
/* @var \Cake\View\Cell $instance */
$instance = new $className($this->request, $this->response, $this->getEventManager(), $options);
$builder = $instance->viewBuilder();
$builder->setTemplate(Inflector::underscore($action));
if (!empty($plugin)) {
$builder->setPlugin($plugin);
}
if (!empty($this->helpers)) {
$builder->setHelpers($this->helpers);
}
if ($this instanceof View) {
if (!empty($this->theme)) {
$builder->setTheme($this->theme);
}
$class = get_class($this);
$builder->setClassName($class);
$instance->viewClass = $class;
return $instance;
}
if (method_exists($this, 'viewBuilder')) {
$builder->setTheme($this->viewBuilder()->getTheme());
}
if (isset($this->viewClass)) {
$builder->setClassName($this->viewClass);
$instance->viewClass = $this->viewClass;
}
return $instance;
} | php | protected function _createCell($className, $action, $plugin, $options)
{
/* @var \Cake\View\Cell $instance */
$instance = new $className($this->request, $this->response, $this->getEventManager(), $options);
$builder = $instance->viewBuilder();
$builder->setTemplate(Inflector::underscore($action));
if (!empty($plugin)) {
$builder->setPlugin($plugin);
}
if (!empty($this->helpers)) {
$builder->setHelpers($this->helpers);
}
if ($this instanceof View) {
if (!empty($this->theme)) {
$builder->setTheme($this->theme);
}
$class = get_class($this);
$builder->setClassName($class);
$instance->viewClass = $class;
return $instance;
}
if (method_exists($this, 'viewBuilder')) {
$builder->setTheme($this->viewBuilder()->getTheme());
}
if (isset($this->viewClass)) {
$builder->setClassName($this->viewClass);
$instance->viewClass = $this->viewClass;
}
return $instance;
} | [
"protected",
"function",
"_createCell",
"(",
"$",
"className",
",",
"$",
"action",
",",
"$",
"plugin",
",",
"$",
"options",
")",
"{",
"/* @var \\Cake\\View\\Cell $instance */",
"$",
"instance",
"=",
"new",
"$",
"className",
"(",
"$",
"this",
"->",
"request",
",",
"$",
"this",
"->",
"response",
",",
"$",
"this",
"->",
"getEventManager",
"(",
")",
",",
"$",
"options",
")",
";",
"$",
"builder",
"=",
"$",
"instance",
"->",
"viewBuilder",
"(",
")",
";",
"$",
"builder",
"->",
"setTemplate",
"(",
"Inflector",
"::",
"underscore",
"(",
"$",
"action",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"plugin",
")",
")",
"{",
"$",
"builder",
"->",
"setPlugin",
"(",
"$",
"plugin",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"helpers",
")",
")",
"{",
"$",
"builder",
"->",
"setHelpers",
"(",
"$",
"this",
"->",
"helpers",
")",
";",
"}",
"if",
"(",
"$",
"this",
"instanceof",
"View",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"theme",
")",
")",
"{",
"$",
"builder",
"->",
"setTheme",
"(",
"$",
"this",
"->",
"theme",
")",
";",
"}",
"$",
"class",
"=",
"get_class",
"(",
"$",
"this",
")",
";",
"$",
"builder",
"->",
"setClassName",
"(",
"$",
"class",
")",
";",
"$",
"instance",
"->",
"viewClass",
"=",
"$",
"class",
";",
"return",
"$",
"instance",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"'viewBuilder'",
")",
")",
"{",
"$",
"builder",
"->",
"setTheme",
"(",
"$",
"this",
"->",
"viewBuilder",
"(",
")",
"->",
"getTheme",
"(",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"viewClass",
")",
")",
"{",
"$",
"builder",
"->",
"setClassName",
"(",
"$",
"this",
"->",
"viewClass",
")",
";",
"$",
"instance",
"->",
"viewClass",
"=",
"$",
"this",
"->",
"viewClass",
";",
"}",
"return",
"$",
"instance",
";",
"}"
] | Create and configure the cell instance.
@param string $className The cell classname.
@param string $action The action name.
@param string $plugin The plugin name.
@param array $options The constructor options for the cell.
@return \Cake\View\Cell | [
"Create",
"and",
"configure",
"the",
"cell",
"instance",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/CellTrait.php#L93-L130 |
210,673 | cakephp/cakephp | src/Http/Client/Auth/Digest.php | Digest._getServerInfo | protected function _getServerInfo(Request $request, $credentials)
{
$response = $this->_client->get(
$request->getUri(),
[],
['auth' => ['type' => null]]
);
if (!$response->getHeader('WWW-Authenticate')) {
return [];
}
preg_match_all(
'@(\w+)=(?:(?:")([^"]+)"|([^\s,$]+))@',
$response->getHeaderLine('WWW-Authenticate'),
$matches,
PREG_SET_ORDER
);
foreach ($matches as $match) {
$credentials[$match[1]] = $match[2];
}
if (!empty($credentials['qop']) && empty($credentials['nc'])) {
$credentials['nc'] = 1;
}
return $credentials;
} | php | protected function _getServerInfo(Request $request, $credentials)
{
$response = $this->_client->get(
$request->getUri(),
[],
['auth' => ['type' => null]]
);
if (!$response->getHeader('WWW-Authenticate')) {
return [];
}
preg_match_all(
'@(\w+)=(?:(?:")([^"]+)"|([^\s,$]+))@',
$response->getHeaderLine('WWW-Authenticate'),
$matches,
PREG_SET_ORDER
);
foreach ($matches as $match) {
$credentials[$match[1]] = $match[2];
}
if (!empty($credentials['qop']) && empty($credentials['nc'])) {
$credentials['nc'] = 1;
}
return $credentials;
} | [
"protected",
"function",
"_getServerInfo",
"(",
"Request",
"$",
"request",
",",
"$",
"credentials",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"_client",
"->",
"get",
"(",
"$",
"request",
"->",
"getUri",
"(",
")",
",",
"[",
"]",
",",
"[",
"'auth'",
"=>",
"[",
"'type'",
"=>",
"null",
"]",
"]",
")",
";",
"if",
"(",
"!",
"$",
"response",
"->",
"getHeader",
"(",
"'WWW-Authenticate'",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"preg_match_all",
"(",
"'@(\\w+)=(?:(?:\")([^\"]+)\"|([^\\s,$]+))@'",
",",
"$",
"response",
"->",
"getHeaderLine",
"(",
"'WWW-Authenticate'",
")",
",",
"$",
"matches",
",",
"PREG_SET_ORDER",
")",
";",
"foreach",
"(",
"$",
"matches",
"as",
"$",
"match",
")",
"{",
"$",
"credentials",
"[",
"$",
"match",
"[",
"1",
"]",
"]",
"=",
"$",
"match",
"[",
"2",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"credentials",
"[",
"'qop'",
"]",
")",
"&&",
"empty",
"(",
"$",
"credentials",
"[",
"'nc'",
"]",
")",
")",
"{",
"$",
"credentials",
"[",
"'nc'",
"]",
"=",
"1",
";",
"}",
"return",
"$",
"credentials",
";",
"}"
] | Retrieve information about the authentication
Will get the realm and other tokens by performing
another request without authentication to get authentication
challenge.
@param \Cake\Http\Client\Request $request The request object.
@param array $credentials Authentication credentials.
@return array modified credentials. | [
"Retrieve",
"information",
"about",
"the",
"authentication"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Auth/Digest.php#L81-L106 |
210,674 | cakephp/cakephp | src/Http/Client/Auth/Digest.php | Digest._generateHeader | protected function _generateHeader(Request $request, $credentials)
{
$path = $request->getUri()->getPath();
$a1 = md5($credentials['username'] . ':' . $credentials['realm'] . ':' . $credentials['password']);
$a2 = md5($request->getMethod() . ':' . $path);
$nc = null;
if (empty($credentials['qop'])) {
$response = md5($a1 . ':' . $credentials['nonce'] . ':' . $a2);
} else {
$credentials['cnonce'] = uniqid();
$nc = sprintf('%08x', $credentials['nc']++);
$response = md5($a1 . ':' . $credentials['nonce'] . ':' . $nc . ':' . $credentials['cnonce'] . ':auth:' . $a2);
}
$authHeader = 'Digest ';
$authHeader .= 'username="' . str_replace(['\\', '"'], ['\\\\', '\\"'], $credentials['username']) . '", ';
$authHeader .= 'realm="' . $credentials['realm'] . '", ';
$authHeader .= 'nonce="' . $credentials['nonce'] . '", ';
$authHeader .= 'uri="' . $path . '", ';
$authHeader .= 'response="' . $response . '"';
if (!empty($credentials['opaque'])) {
$authHeader .= ', opaque="' . $credentials['opaque'] . '"';
}
if (!empty($credentials['qop'])) {
$authHeader .= ', qop="auth", nc=' . $nc . ', cnonce="' . $credentials['cnonce'] . '"';
}
return $authHeader;
} | php | protected function _generateHeader(Request $request, $credentials)
{
$path = $request->getUri()->getPath();
$a1 = md5($credentials['username'] . ':' . $credentials['realm'] . ':' . $credentials['password']);
$a2 = md5($request->getMethod() . ':' . $path);
$nc = null;
if (empty($credentials['qop'])) {
$response = md5($a1 . ':' . $credentials['nonce'] . ':' . $a2);
} else {
$credentials['cnonce'] = uniqid();
$nc = sprintf('%08x', $credentials['nc']++);
$response = md5($a1 . ':' . $credentials['nonce'] . ':' . $nc . ':' . $credentials['cnonce'] . ':auth:' . $a2);
}
$authHeader = 'Digest ';
$authHeader .= 'username="' . str_replace(['\\', '"'], ['\\\\', '\\"'], $credentials['username']) . '", ';
$authHeader .= 'realm="' . $credentials['realm'] . '", ';
$authHeader .= 'nonce="' . $credentials['nonce'] . '", ';
$authHeader .= 'uri="' . $path . '", ';
$authHeader .= 'response="' . $response . '"';
if (!empty($credentials['opaque'])) {
$authHeader .= ', opaque="' . $credentials['opaque'] . '"';
}
if (!empty($credentials['qop'])) {
$authHeader .= ', qop="auth", nc=' . $nc . ', cnonce="' . $credentials['cnonce'] . '"';
}
return $authHeader;
} | [
"protected",
"function",
"_generateHeader",
"(",
"Request",
"$",
"request",
",",
"$",
"credentials",
")",
"{",
"$",
"path",
"=",
"$",
"request",
"->",
"getUri",
"(",
")",
"->",
"getPath",
"(",
")",
";",
"$",
"a1",
"=",
"md5",
"(",
"$",
"credentials",
"[",
"'username'",
"]",
".",
"':'",
".",
"$",
"credentials",
"[",
"'realm'",
"]",
".",
"':'",
".",
"$",
"credentials",
"[",
"'password'",
"]",
")",
";",
"$",
"a2",
"=",
"md5",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
".",
"':'",
".",
"$",
"path",
")",
";",
"$",
"nc",
"=",
"null",
";",
"if",
"(",
"empty",
"(",
"$",
"credentials",
"[",
"'qop'",
"]",
")",
")",
"{",
"$",
"response",
"=",
"md5",
"(",
"$",
"a1",
".",
"':'",
".",
"$",
"credentials",
"[",
"'nonce'",
"]",
".",
"':'",
".",
"$",
"a2",
")",
";",
"}",
"else",
"{",
"$",
"credentials",
"[",
"'cnonce'",
"]",
"=",
"uniqid",
"(",
")",
";",
"$",
"nc",
"=",
"sprintf",
"(",
"'%08x'",
",",
"$",
"credentials",
"[",
"'nc'",
"]",
"++",
")",
";",
"$",
"response",
"=",
"md5",
"(",
"$",
"a1",
".",
"':'",
".",
"$",
"credentials",
"[",
"'nonce'",
"]",
".",
"':'",
".",
"$",
"nc",
".",
"':'",
".",
"$",
"credentials",
"[",
"'cnonce'",
"]",
".",
"':auth:'",
".",
"$",
"a2",
")",
";",
"}",
"$",
"authHeader",
"=",
"'Digest '",
";",
"$",
"authHeader",
".=",
"'username=\"'",
".",
"str_replace",
"(",
"[",
"'\\\\'",
",",
"'\"'",
"]",
",",
"[",
"'\\\\\\\\'",
",",
"'\\\\\"'",
"]",
",",
"$",
"credentials",
"[",
"'username'",
"]",
")",
".",
"'\", '",
";",
"$",
"authHeader",
".=",
"'realm=\"'",
".",
"$",
"credentials",
"[",
"'realm'",
"]",
".",
"'\", '",
";",
"$",
"authHeader",
".=",
"'nonce=\"'",
".",
"$",
"credentials",
"[",
"'nonce'",
"]",
".",
"'\", '",
";",
"$",
"authHeader",
".=",
"'uri=\"'",
".",
"$",
"path",
".",
"'\", '",
";",
"$",
"authHeader",
".=",
"'response=\"'",
".",
"$",
"response",
".",
"'\"'",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"credentials",
"[",
"'opaque'",
"]",
")",
")",
"{",
"$",
"authHeader",
".=",
"', opaque=\"'",
".",
"$",
"credentials",
"[",
"'opaque'",
"]",
".",
"'\"'",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"credentials",
"[",
"'qop'",
"]",
")",
")",
"{",
"$",
"authHeader",
".=",
"', qop=\"auth\", nc='",
".",
"$",
"nc",
".",
"', cnonce=\"'",
".",
"$",
"credentials",
"[",
"'cnonce'",
"]",
".",
"'\"'",
";",
"}",
"return",
"$",
"authHeader",
";",
"}"
] | Generate the header Authorization
@param \Cake\Http\Client\Request $request The request object.
@param array $credentials Authentication credentials.
@return string | [
"Generate",
"the",
"header",
"Authorization"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Auth/Digest.php#L115-L144 |
210,675 | cakephp/cakephp | src/Collection/Iterator/BufferedIterator.php | BufferedIterator.rewind | public function rewind()
{
if ($this->_index === 0 && !$this->_started) {
$this->_started = true;
parent::rewind();
return;
}
$this->_index = 0;
} | php | public function rewind()
{
if ($this->_index === 0 && !$this->_started) {
$this->_started = true;
parent::rewind();
return;
}
$this->_index = 0;
} | [
"public",
"function",
"rewind",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_index",
"===",
"0",
"&&",
"!",
"$",
"this",
"->",
"_started",
")",
"{",
"$",
"this",
"->",
"_started",
"=",
"true",
";",
"parent",
"::",
"rewind",
"(",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"_index",
"=",
"0",
";",
"}"
] | Rewinds the collection
@return void | [
"Rewinds",
"the",
"collection"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Collection/Iterator/BufferedIterator.php#L109-L119 |
210,676 | cakephp/cakephp | src/Collection/Iterator/BufferedIterator.php | BufferedIterator.count | public function count()
{
if (!$this->_started) {
$this->rewind();
}
while ($this->valid()) {
$this->next();
}
return $this->_buffer->count();
} | php | public function count()
{
if (!$this->_started) {
$this->rewind();
}
while ($this->valid()) {
$this->next();
}
return $this->_buffer->count();
} | [
"public",
"function",
"count",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_started",
")",
"{",
"$",
"this",
"->",
"rewind",
"(",
")",
";",
"}",
"while",
"(",
"$",
"this",
"->",
"valid",
"(",
")",
")",
"{",
"$",
"this",
"->",
"next",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_buffer",
"->",
"count",
"(",
")",
";",
"}"
] | Returns the number or items in this collection
@return int | [
"Returns",
"the",
"number",
"or",
"items",
"in",
"this",
"collection"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Collection/Iterator/BufferedIterator.php#L171-L182 |
210,677 | cakephp/cakephp | src/Collection/Iterator/BufferedIterator.php | BufferedIterator.unserialize | public function unserialize($buffer)
{
$this->__construct([]);
$this->_buffer = unserialize($buffer);
$this->_started = true;
$this->_finished = true;
} | php | public function unserialize($buffer)
{
$this->__construct([]);
$this->_buffer = unserialize($buffer);
$this->_started = true;
$this->_finished = true;
} | [
"public",
"function",
"unserialize",
"(",
"$",
"buffer",
")",
"{",
"$",
"this",
"->",
"__construct",
"(",
"[",
"]",
")",
";",
"$",
"this",
"->",
"_buffer",
"=",
"unserialize",
"(",
"$",
"buffer",
")",
";",
"$",
"this",
"->",
"_started",
"=",
"true",
";",
"$",
"this",
"->",
"_finished",
"=",
"true",
";",
"}"
] | Unserializes the passed string and rebuilds the BufferedIterator instance
@param string $buffer The serialized buffer iterator
@return void | [
"Unserializes",
"the",
"passed",
"string",
"and",
"rebuilds",
"the",
"BufferedIterator",
"instance"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Collection/Iterator/BufferedIterator.php#L205-L211 |
210,678 | cakephp/cakephp | src/Database/TypeConverterTrait.php | TypeConverterTrait.cast | public function cast($value, $type)
{
if (is_string($type)) {
$type = Type::build($type);
}
if ($type instanceof TypeInterface) {
$value = $type->toDatabase($value, $this->_driver);
$type = $type->toStatement($value, $this->_driver);
}
return [$value, $type];
} | php | public function cast($value, $type)
{
if (is_string($type)) {
$type = Type::build($type);
}
if ($type instanceof TypeInterface) {
$value = $type->toDatabase($value, $this->_driver);
$type = $type->toStatement($value, $this->_driver);
}
return [$value, $type];
} | [
"public",
"function",
"cast",
"(",
"$",
"value",
",",
"$",
"type",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"type",
")",
")",
"{",
"$",
"type",
"=",
"Type",
"::",
"build",
"(",
"$",
"type",
")",
";",
"}",
"if",
"(",
"$",
"type",
"instanceof",
"TypeInterface",
")",
"{",
"$",
"value",
"=",
"$",
"type",
"->",
"toDatabase",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"_driver",
")",
";",
"$",
"type",
"=",
"$",
"type",
"->",
"toStatement",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"_driver",
")",
";",
"}",
"return",
"[",
"$",
"value",
",",
"$",
"type",
"]",
";",
"}"
] | Converts a give value to a suitable database value based on type
and return relevant internal statement type
@param mixed $value The value to cast
@param \Cake\Database\Type|string $type The type name or type instance to use.
@return array list containing converted value and internal type | [
"Converts",
"a",
"give",
"value",
"to",
"a",
"suitable",
"database",
"value",
"based",
"on",
"type",
"and",
"return",
"relevant",
"internal",
"statement",
"type"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/TypeConverterTrait.php#L31-L42 |
210,679 | cakephp/cakephp | src/Database/TypeConverterTrait.php | TypeConverterTrait.matchTypes | public function matchTypes($columns, $types)
{
if (!is_int(key($types))) {
$positions = array_intersect_key(array_flip($columns), $types);
$types = array_intersect_key($types, $positions);
$types = array_combine($positions, $types);
}
return $types;
} | php | public function matchTypes($columns, $types)
{
if (!is_int(key($types))) {
$positions = array_intersect_key(array_flip($columns), $types);
$types = array_intersect_key($types, $positions);
$types = array_combine($positions, $types);
}
return $types;
} | [
"public",
"function",
"matchTypes",
"(",
"$",
"columns",
",",
"$",
"types",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"key",
"(",
"$",
"types",
")",
")",
")",
"{",
"$",
"positions",
"=",
"array_intersect_key",
"(",
"array_flip",
"(",
"$",
"columns",
")",
",",
"$",
"types",
")",
";",
"$",
"types",
"=",
"array_intersect_key",
"(",
"$",
"types",
",",
"$",
"positions",
")",
";",
"$",
"types",
"=",
"array_combine",
"(",
"$",
"positions",
",",
"$",
"types",
")",
";",
"}",
"return",
"$",
"types",
";",
"}"
] | Matches columns to corresponding types
Both $columns and $types should either be numeric based or string key based at
the same time.
@param array $columns list or associative array of columns and parameters to be bound with types
@param array $types list or associative array of types
@return array | [
"Matches",
"columns",
"to",
"corresponding",
"types"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/TypeConverterTrait.php#L54-L63 |
210,680 | cakephp/cakephp | src/Console/ConsoleInputArgument.php | ConsoleInputArgument.help | public function help($width = 0)
{
$name = $this->_name;
if (strlen($name) < $width) {
$name = str_pad($name, $width, ' ');
}
$optional = '';
if (!$this->isRequired()) {
$optional = ' <comment>(optional)</comment>';
}
if ($this->_choices) {
$optional .= sprintf(' <comment>(choices: %s)</comment>', implode('|', $this->_choices));
}
return sprintf('%s%s%s', $name, $this->_help, $optional);
} | php | public function help($width = 0)
{
$name = $this->_name;
if (strlen($name) < $width) {
$name = str_pad($name, $width, ' ');
}
$optional = '';
if (!$this->isRequired()) {
$optional = ' <comment>(optional)</comment>';
}
if ($this->_choices) {
$optional .= sprintf(' <comment>(choices: %s)</comment>', implode('|', $this->_choices));
}
return sprintf('%s%s%s', $name, $this->_help, $optional);
} | [
"public",
"function",
"help",
"(",
"$",
"width",
"=",
"0",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"_name",
";",
"if",
"(",
"strlen",
"(",
"$",
"name",
")",
"<",
"$",
"width",
")",
"{",
"$",
"name",
"=",
"str_pad",
"(",
"$",
"name",
",",
"$",
"width",
",",
"' '",
")",
";",
"}",
"$",
"optional",
"=",
"''",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isRequired",
"(",
")",
")",
"{",
"$",
"optional",
"=",
"' <comment>(optional)</comment>'",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_choices",
")",
"{",
"$",
"optional",
".=",
"sprintf",
"(",
"' <comment>(choices: %s)</comment>'",
",",
"implode",
"(",
"'|'",
",",
"$",
"this",
"->",
"_choices",
")",
")",
";",
"}",
"return",
"sprintf",
"(",
"'%s%s%s'",
",",
"$",
"name",
",",
"$",
"this",
"->",
"_help",
",",
"$",
"optional",
")",
";",
"}"
] | Generate the help for this argument.
@param int $width The width to make the name of the option.
@return string | [
"Generate",
"the",
"help",
"for",
"this",
"argument",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleInputArgument.php#L106-L121 |
210,681 | cakephp/cakephp | src/Console/ConsoleInputArgument.php | ConsoleInputArgument.usage | public function usage()
{
$name = $this->_name;
if ($this->_choices) {
$name = implode('|', $this->_choices);
}
$name = '<' . $name . '>';
if (!$this->isRequired()) {
$name = '[' . $name . ']';
}
return $name;
} | php | public function usage()
{
$name = $this->_name;
if ($this->_choices) {
$name = implode('|', $this->_choices);
}
$name = '<' . $name . '>';
if (!$this->isRequired()) {
$name = '[' . $name . ']';
}
return $name;
} | [
"public",
"function",
"usage",
"(",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"_name",
";",
"if",
"(",
"$",
"this",
"->",
"_choices",
")",
"{",
"$",
"name",
"=",
"implode",
"(",
"'|'",
",",
"$",
"this",
"->",
"_choices",
")",
";",
"}",
"$",
"name",
"=",
"'<'",
".",
"$",
"name",
".",
"'>'",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isRequired",
"(",
")",
")",
"{",
"$",
"name",
"=",
"'['",
".",
"$",
"name",
".",
"']'",
";",
"}",
"return",
"$",
"name",
";",
"}"
] | Get the usage value for this argument
@return string | [
"Get",
"the",
"usage",
"value",
"for",
"this",
"argument"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleInputArgument.php#L128-L140 |
210,682 | cakephp/cakephp | src/Console/ConsoleInputArgument.php | ConsoleInputArgument.xml | public function xml(SimpleXMLElement $parent)
{
$option = $parent->addChild('argument');
$option->addAttribute('name', $this->_name);
$option->addAttribute('help', $this->_help);
$option->addAttribute('required', (int)$this->isRequired());
$choices = $option->addChild('choices');
foreach ($this->_choices as $valid) {
$choices->addChild('choice', $valid);
}
return $parent;
} | php | public function xml(SimpleXMLElement $parent)
{
$option = $parent->addChild('argument');
$option->addAttribute('name', $this->_name);
$option->addAttribute('help', $this->_help);
$option->addAttribute('required', (int)$this->isRequired());
$choices = $option->addChild('choices');
foreach ($this->_choices as $valid) {
$choices->addChild('choice', $valid);
}
return $parent;
} | [
"public",
"function",
"xml",
"(",
"SimpleXMLElement",
"$",
"parent",
")",
"{",
"$",
"option",
"=",
"$",
"parent",
"->",
"addChild",
"(",
"'argument'",
")",
";",
"$",
"option",
"->",
"addAttribute",
"(",
"'name'",
",",
"$",
"this",
"->",
"_name",
")",
";",
"$",
"option",
"->",
"addAttribute",
"(",
"'help'",
",",
"$",
"this",
"->",
"_help",
")",
";",
"$",
"option",
"->",
"addAttribute",
"(",
"'required'",
",",
"(",
"int",
")",
"$",
"this",
"->",
"isRequired",
"(",
")",
")",
";",
"$",
"choices",
"=",
"$",
"option",
"->",
"addChild",
"(",
"'choices'",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"_choices",
"as",
"$",
"valid",
")",
"{",
"$",
"choices",
"->",
"addChild",
"(",
"'choice'",
",",
"$",
"valid",
")",
";",
"}",
"return",
"$",
"parent",
";",
"}"
] | Append this arguments XML representation to the passed in SimpleXml object.
@param \SimpleXMLElement $parent The parent element.
@return \SimpleXMLElement The parent with this argument appended. | [
"Append",
"this",
"arguments",
"XML",
"representation",
"to",
"the",
"passed",
"in",
"SimpleXml",
"object",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleInputArgument.php#L184-L196 |
210,683 | cakephp/cakephp | src/Event/EventDispatcherTrait.php | EventDispatcherTrait.eventManager | public function eventManager(EventManager $eventManager = null)
{
deprecationWarning(
'EventDispatcherTrait::eventManager() is deprecated. ' .
'Use EventDispatcherTrait::setEventManager()/getEventManager() instead.'
);
if ($eventManager !== null) {
$this->setEventManager($eventManager);
}
return $this->getEventManager();
} | php | public function eventManager(EventManager $eventManager = null)
{
deprecationWarning(
'EventDispatcherTrait::eventManager() is deprecated. ' .
'Use EventDispatcherTrait::setEventManager()/getEventManager() instead.'
);
if ($eventManager !== null) {
$this->setEventManager($eventManager);
}
return $this->getEventManager();
} | [
"public",
"function",
"eventManager",
"(",
"EventManager",
"$",
"eventManager",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"'EventDispatcherTrait::eventManager() is deprecated. '",
".",
"'Use EventDispatcherTrait::setEventManager()/getEventManager() instead.'",
")",
";",
"if",
"(",
"$",
"eventManager",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"setEventManager",
"(",
"$",
"eventManager",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getEventManager",
"(",
")",
";",
"}"
] | Returns the Cake\Event\EventManager manager instance for this object.
You can use this instance to register any new listeners or callbacks to the
object events, or create your own events and trigger them at will.
@param \Cake\Event\EventManager|null $eventManager the eventManager to set
@return \Cake\Event\EventManager
@deprecated 3.5.0 Use getEventManager()/setEventManager() instead. | [
"Returns",
"the",
"Cake",
"\\",
"Event",
"\\",
"EventManager",
"manager",
"instance",
"for",
"this",
"object",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Event/EventDispatcherTrait.php#L48-L59 |
210,684 | cakephp/cakephp | src/ORM/Behavior.php | Behavior._resolveMethodAliases | protected function _resolveMethodAliases($key, $defaults, $config)
{
if (!isset($defaults[$key], $config[$key])) {
return $config;
}
if (isset($config[$key]) && $config[$key] === []) {
$this->setConfig($key, [], false);
unset($config[$key]);
return $config;
}
$indexed = array_flip($defaults[$key]);
$indexedCustom = array_flip($config[$key]);
foreach ($indexed as $method => $alias) {
if (!isset($indexedCustom[$method])) {
$indexedCustom[$method] = $alias;
}
}
$this->setConfig($key, array_flip($indexedCustom), false);
unset($config[$key]);
return $config;
} | php | protected function _resolveMethodAliases($key, $defaults, $config)
{
if (!isset($defaults[$key], $config[$key])) {
return $config;
}
if (isset($config[$key]) && $config[$key] === []) {
$this->setConfig($key, [], false);
unset($config[$key]);
return $config;
}
$indexed = array_flip($defaults[$key]);
$indexedCustom = array_flip($config[$key]);
foreach ($indexed as $method => $alias) {
if (!isset($indexedCustom[$method])) {
$indexedCustom[$method] = $alias;
}
}
$this->setConfig($key, array_flip($indexedCustom), false);
unset($config[$key]);
return $config;
} | [
"protected",
"function",
"_resolveMethodAliases",
"(",
"$",
"key",
",",
"$",
"defaults",
",",
"$",
"config",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"defaults",
"[",
"$",
"key",
"]",
",",
"$",
"config",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"config",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"$",
"key",
"]",
")",
"&&",
"$",
"config",
"[",
"$",
"key",
"]",
"===",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"setConfig",
"(",
"$",
"key",
",",
"[",
"]",
",",
"false",
")",
";",
"unset",
"(",
"$",
"config",
"[",
"$",
"key",
"]",
")",
";",
"return",
"$",
"config",
";",
"}",
"$",
"indexed",
"=",
"array_flip",
"(",
"$",
"defaults",
"[",
"$",
"key",
"]",
")",
";",
"$",
"indexedCustom",
"=",
"array_flip",
"(",
"$",
"config",
"[",
"$",
"key",
"]",
")",
";",
"foreach",
"(",
"$",
"indexed",
"as",
"$",
"method",
"=>",
"$",
"alias",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"indexedCustom",
"[",
"$",
"method",
"]",
")",
")",
"{",
"$",
"indexedCustom",
"[",
"$",
"method",
"]",
"=",
"$",
"alias",
";",
"}",
"}",
"$",
"this",
"->",
"setConfig",
"(",
"$",
"key",
",",
"array_flip",
"(",
"$",
"indexedCustom",
")",
",",
"false",
")",
";",
"unset",
"(",
"$",
"config",
"[",
"$",
"key",
"]",
")",
";",
"return",
"$",
"config",
";",
"}"
] | Removes aliased methods that would otherwise be duplicated by userland configuration.
@param string $key The key to filter.
@param array $defaults The default method mappings.
@param array $config The customized method mappings.
@return array A de-duped list of config data. | [
"Removes",
"aliased",
"methods",
"that",
"would",
"otherwise",
"be",
"duplicated",
"by",
"userland",
"configuration",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior.php#L200-L223 |
210,685 | cakephp/cakephp | src/ORM/Behavior.php | Behavior.implementedEvents | public function implementedEvents()
{
$eventMap = [
'Model.beforeMarshal' => 'beforeMarshal',
'Model.beforeFind' => 'beforeFind',
'Model.beforeSave' => 'beforeSave',
'Model.afterSave' => 'afterSave',
'Model.afterSaveCommit' => 'afterSaveCommit',
'Model.beforeDelete' => 'beforeDelete',
'Model.afterDelete' => 'afterDelete',
'Model.afterDeleteCommit' => 'afterDeleteCommit',
'Model.buildValidator' => 'buildValidator',
'Model.buildRules' => 'buildRules',
'Model.beforeRules' => 'beforeRules',
'Model.afterRules' => 'afterRules',
];
$config = $this->getConfig();
$priority = isset($config['priority']) ? $config['priority'] : null;
$events = [];
foreach ($eventMap as $event => $method) {
if (!method_exists($this, $method)) {
continue;
}
if ($priority === null) {
$events[$event] = $method;
} else {
$events[$event] = [
'callable' => $method,
'priority' => $priority
];
}
}
return $events;
} | php | public function implementedEvents()
{
$eventMap = [
'Model.beforeMarshal' => 'beforeMarshal',
'Model.beforeFind' => 'beforeFind',
'Model.beforeSave' => 'beforeSave',
'Model.afterSave' => 'afterSave',
'Model.afterSaveCommit' => 'afterSaveCommit',
'Model.beforeDelete' => 'beforeDelete',
'Model.afterDelete' => 'afterDelete',
'Model.afterDeleteCommit' => 'afterDeleteCommit',
'Model.buildValidator' => 'buildValidator',
'Model.buildRules' => 'buildRules',
'Model.beforeRules' => 'beforeRules',
'Model.afterRules' => 'afterRules',
];
$config = $this->getConfig();
$priority = isset($config['priority']) ? $config['priority'] : null;
$events = [];
foreach ($eventMap as $event => $method) {
if (!method_exists($this, $method)) {
continue;
}
if ($priority === null) {
$events[$event] = $method;
} else {
$events[$event] = [
'callable' => $method,
'priority' => $priority
];
}
}
return $events;
} | [
"public",
"function",
"implementedEvents",
"(",
")",
"{",
"$",
"eventMap",
"=",
"[",
"'Model.beforeMarshal'",
"=>",
"'beforeMarshal'",
",",
"'Model.beforeFind'",
"=>",
"'beforeFind'",
",",
"'Model.beforeSave'",
"=>",
"'beforeSave'",
",",
"'Model.afterSave'",
"=>",
"'afterSave'",
",",
"'Model.afterSaveCommit'",
"=>",
"'afterSaveCommit'",
",",
"'Model.beforeDelete'",
"=>",
"'beforeDelete'",
",",
"'Model.afterDelete'",
"=>",
"'afterDelete'",
",",
"'Model.afterDeleteCommit'",
"=>",
"'afterDeleteCommit'",
",",
"'Model.buildValidator'",
"=>",
"'buildValidator'",
",",
"'Model.buildRules'",
"=>",
"'buildRules'",
",",
"'Model.beforeRules'",
"=>",
"'beforeRules'",
",",
"'Model.afterRules'",
"=>",
"'afterRules'",
",",
"]",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
";",
"$",
"priority",
"=",
"isset",
"(",
"$",
"config",
"[",
"'priority'",
"]",
")",
"?",
"$",
"config",
"[",
"'priority'",
"]",
":",
"null",
";",
"$",
"events",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"eventMap",
"as",
"$",
"event",
"=>",
"$",
"method",
")",
"{",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"priority",
"===",
"null",
")",
"{",
"$",
"events",
"[",
"$",
"event",
"]",
"=",
"$",
"method",
";",
"}",
"else",
"{",
"$",
"events",
"[",
"$",
"event",
"]",
"=",
"[",
"'callable'",
"=>",
"$",
"method",
",",
"'priority'",
"=>",
"$",
"priority",
"]",
";",
"}",
"}",
"return",
"$",
"events",
";",
"}"
] | Gets the Model callbacks this behavior is interested in.
By defining one of the callback methods a behavior is assumed
to be interested in the related event.
Override this method if you need to add non-conventional event listeners.
Or if you want your behavior to listen to non-standard events.
@return array | [
"Gets",
"the",
"Model",
"callbacks",
"this",
"behavior",
"is",
"interested",
"in",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior.php#L260-L295 |
210,686 | cakephp/cakephp | src/ORM/Behavior.php | Behavior._reflectionCache | protected function _reflectionCache()
{
$class = get_class($this);
if (isset(self::$_reflectionCache[$class])) {
return self::$_reflectionCache[$class];
}
$events = $this->implementedEvents();
$eventMethods = [];
foreach ($events as $e => $binding) {
if (is_array($binding) && isset($binding['callable'])) {
/* @var string $callable */
$callable = $binding['callable'];
$binding = $callable;
}
$eventMethods[$binding] = true;
}
$baseClass = 'Cake\ORM\Behavior';
if (isset(self::$_reflectionCache[$baseClass])) {
$baseMethods = self::$_reflectionCache[$baseClass];
} else {
$baseMethods = get_class_methods($baseClass);
self::$_reflectionCache[$baseClass] = $baseMethods;
}
$return = [
'finders' => [],
'methods' => []
];
$reflection = new ReflectionClass($class);
foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
$methodName = $method->getName();
if (in_array($methodName, $baseMethods) ||
isset($eventMethods[$methodName])
) {
continue;
}
if (substr($methodName, 0, 4) === 'find') {
$return['finders'][lcfirst(substr($methodName, 4))] = $methodName;
} else {
$return['methods'][$methodName] = $methodName;
}
}
return self::$_reflectionCache[$class] = $return;
} | php | protected function _reflectionCache()
{
$class = get_class($this);
if (isset(self::$_reflectionCache[$class])) {
return self::$_reflectionCache[$class];
}
$events = $this->implementedEvents();
$eventMethods = [];
foreach ($events as $e => $binding) {
if (is_array($binding) && isset($binding['callable'])) {
/* @var string $callable */
$callable = $binding['callable'];
$binding = $callable;
}
$eventMethods[$binding] = true;
}
$baseClass = 'Cake\ORM\Behavior';
if (isset(self::$_reflectionCache[$baseClass])) {
$baseMethods = self::$_reflectionCache[$baseClass];
} else {
$baseMethods = get_class_methods($baseClass);
self::$_reflectionCache[$baseClass] = $baseMethods;
}
$return = [
'finders' => [],
'methods' => []
];
$reflection = new ReflectionClass($class);
foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
$methodName = $method->getName();
if (in_array($methodName, $baseMethods) ||
isset($eventMethods[$methodName])
) {
continue;
}
if (substr($methodName, 0, 4) === 'find') {
$return['finders'][lcfirst(substr($methodName, 4))] = $methodName;
} else {
$return['methods'][$methodName] = $methodName;
}
}
return self::$_reflectionCache[$class] = $return;
} | [
"protected",
"function",
"_reflectionCache",
"(",
")",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"this",
")",
";",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"_reflectionCache",
"[",
"$",
"class",
"]",
")",
")",
"{",
"return",
"self",
"::",
"$",
"_reflectionCache",
"[",
"$",
"class",
"]",
";",
"}",
"$",
"events",
"=",
"$",
"this",
"->",
"implementedEvents",
"(",
")",
";",
"$",
"eventMethods",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"events",
"as",
"$",
"e",
"=>",
"$",
"binding",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"binding",
")",
"&&",
"isset",
"(",
"$",
"binding",
"[",
"'callable'",
"]",
")",
")",
"{",
"/* @var string $callable */",
"$",
"callable",
"=",
"$",
"binding",
"[",
"'callable'",
"]",
";",
"$",
"binding",
"=",
"$",
"callable",
";",
"}",
"$",
"eventMethods",
"[",
"$",
"binding",
"]",
"=",
"true",
";",
"}",
"$",
"baseClass",
"=",
"'Cake\\ORM\\Behavior'",
";",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"_reflectionCache",
"[",
"$",
"baseClass",
"]",
")",
")",
"{",
"$",
"baseMethods",
"=",
"self",
"::",
"$",
"_reflectionCache",
"[",
"$",
"baseClass",
"]",
";",
"}",
"else",
"{",
"$",
"baseMethods",
"=",
"get_class_methods",
"(",
"$",
"baseClass",
")",
";",
"self",
"::",
"$",
"_reflectionCache",
"[",
"$",
"baseClass",
"]",
"=",
"$",
"baseMethods",
";",
"}",
"$",
"return",
"=",
"[",
"'finders'",
"=>",
"[",
"]",
",",
"'methods'",
"=>",
"[",
"]",
"]",
";",
"$",
"reflection",
"=",
"new",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"foreach",
"(",
"$",
"reflection",
"->",
"getMethods",
"(",
"ReflectionMethod",
"::",
"IS_PUBLIC",
")",
"as",
"$",
"method",
")",
"{",
"$",
"methodName",
"=",
"$",
"method",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"methodName",
",",
"$",
"baseMethods",
")",
"||",
"isset",
"(",
"$",
"eventMethods",
"[",
"$",
"methodName",
"]",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"methodName",
",",
"0",
",",
"4",
")",
"===",
"'find'",
")",
"{",
"$",
"return",
"[",
"'finders'",
"]",
"[",
"lcfirst",
"(",
"substr",
"(",
"$",
"methodName",
",",
"4",
")",
")",
"]",
"=",
"$",
"methodName",
";",
"}",
"else",
"{",
"$",
"return",
"[",
"'methods'",
"]",
"[",
"$",
"methodName",
"]",
"=",
"$",
"methodName",
";",
"}",
"}",
"return",
"self",
"::",
"$",
"_reflectionCache",
"[",
"$",
"class",
"]",
"=",
"$",
"return",
";",
"}"
] | Gets the methods implemented by this behavior
Uses the implementedEvents() method to exclude callback methods.
Methods starting with `_` will be ignored, as will methods
declared on Cake\ORM\Behavior
@return array
@throws \ReflectionException | [
"Gets",
"the",
"methods",
"implemented",
"by",
"this",
"behavior"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior.php#L371-L420 |
210,687 | cakephp/cakephp | src/Console/CommandCollection.php | CommandCollection.add | public function add($name, $command)
{
// Once we have a new Command class this should check
// against that interface.
if (!is_subclass_of($command, Shell::class) && !is_subclass_of($command, Command::class)) {
$class = is_string($command) ? $command : get_class($command);
throw new InvalidArgumentException(
"Cannot use '$class' for command '$name' it is not a subclass of Cake\Console\Shell or Cake\Console\Command."
);
}
if (!preg_match('/^[^\s]+(?:(?: [^\s]+){1,2})?$/ui', $name)) {
throw new InvalidArgumentException(
"The command name `{$name}` is invalid. Names can only be a maximum of three words."
);
}
$this->commands[$name] = $command;
return $this;
} | php | public function add($name, $command)
{
// Once we have a new Command class this should check
// against that interface.
if (!is_subclass_of($command, Shell::class) && !is_subclass_of($command, Command::class)) {
$class = is_string($command) ? $command : get_class($command);
throw new InvalidArgumentException(
"Cannot use '$class' for command '$name' it is not a subclass of Cake\Console\Shell or Cake\Console\Command."
);
}
if (!preg_match('/^[^\s]+(?:(?: [^\s]+){1,2})?$/ui', $name)) {
throw new InvalidArgumentException(
"The command name `{$name}` is invalid. Names can only be a maximum of three words."
);
}
$this->commands[$name] = $command;
return $this;
} | [
"public",
"function",
"add",
"(",
"$",
"name",
",",
"$",
"command",
")",
"{",
"// Once we have a new Command class this should check",
"// against that interface.",
"if",
"(",
"!",
"is_subclass_of",
"(",
"$",
"command",
",",
"Shell",
"::",
"class",
")",
"&&",
"!",
"is_subclass_of",
"(",
"$",
"command",
",",
"Command",
"::",
"class",
")",
")",
"{",
"$",
"class",
"=",
"is_string",
"(",
"$",
"command",
")",
"?",
"$",
"command",
":",
"get_class",
"(",
"$",
"command",
")",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Cannot use '$class' for command '$name' it is not a subclass of Cake\\Console\\Shell or Cake\\Console\\Command.\"",
")",
";",
"}",
"if",
"(",
"!",
"preg_match",
"(",
"'/^[^\\s]+(?:(?: [^\\s]+){1,2})?$/ui'",
",",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"The command name `{$name}` is invalid. Names can only be a maximum of three words.\"",
")",
";",
"}",
"$",
"this",
"->",
"commands",
"[",
"$",
"name",
"]",
"=",
"$",
"command",
";",
"return",
"$",
"this",
";",
"}"
] | Add a command to the collection
@param string $name The name of the command you want to map.
@param string|\Cake\Console\Shell|\Cake\Console\Command $command The command to map.
@return $this | [
"Add",
"a",
"command",
"to",
"the",
"collection"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/CommandCollection.php#L57-L76 |
210,688 | cakephp/cakephp | src/Console/CommandCollection.php | CommandCollection.discoverPlugin | public function discoverPlugin($plugin)
{
$scanner = new CommandScanner();
$shells = $scanner->scanPlugin($plugin);
return $this->resolveNames($shells);
} | php | public function discoverPlugin($plugin)
{
$scanner = new CommandScanner();
$shells = $scanner->scanPlugin($plugin);
return $this->resolveNames($shells);
} | [
"public",
"function",
"discoverPlugin",
"(",
"$",
"plugin",
")",
"{",
"$",
"scanner",
"=",
"new",
"CommandScanner",
"(",
")",
";",
"$",
"shells",
"=",
"$",
"scanner",
"->",
"scanPlugin",
"(",
"$",
"plugin",
")",
";",
"return",
"$",
"this",
"->",
"resolveNames",
"(",
"$",
"shells",
")",
";",
"}"
] | Auto-discover shell & commands from the named plugin.
Discovered commands will have their names de-duplicated with
existing commands in the collection. If a command is already
defined in the collection and discovered in a plugin, only
the long name (`plugin.command`) will be returned.
@param string $plugin The plugin to scan.
@return string[] Discovered plugin commands. | [
"Auto",
"-",
"discover",
"shell",
"&",
"commands",
"from",
"the",
"named",
"plugin",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/CommandCollection.php#L167-L173 |
210,689 | cakephp/cakephp | src/Console/CommandCollection.php | CommandCollection.resolveNames | protected function resolveNames(array $input)
{
$out = [];
foreach ($input as $info) {
$name = $info['name'];
$addLong = $name !== $info['fullName'];
// If the short name has been used, use the full name.
// This allows app shells to have name preference.
// and app shells to overwrite core shells.
if ($this->has($name) && $addLong) {
$name = $info['fullName'];
}
$out[$name] = $info['class'];
if ($addLong) {
$out[$info['fullName']] = $info['class'];
}
}
return $out;
} | php | protected function resolveNames(array $input)
{
$out = [];
foreach ($input as $info) {
$name = $info['name'];
$addLong = $name !== $info['fullName'];
// If the short name has been used, use the full name.
// This allows app shells to have name preference.
// and app shells to overwrite core shells.
if ($this->has($name) && $addLong) {
$name = $info['fullName'];
}
$out[$name] = $info['class'];
if ($addLong) {
$out[$info['fullName']] = $info['class'];
}
}
return $out;
} | [
"protected",
"function",
"resolveNames",
"(",
"array",
"$",
"input",
")",
"{",
"$",
"out",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"input",
"as",
"$",
"info",
")",
"{",
"$",
"name",
"=",
"$",
"info",
"[",
"'name'",
"]",
";",
"$",
"addLong",
"=",
"$",
"name",
"!==",
"$",
"info",
"[",
"'fullName'",
"]",
";",
"// If the short name has been used, use the full name.",
"// This allows app shells to have name preference.",
"// and app shells to overwrite core shells.",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"$",
"name",
")",
"&&",
"$",
"addLong",
")",
"{",
"$",
"name",
"=",
"$",
"info",
"[",
"'fullName'",
"]",
";",
"}",
"$",
"out",
"[",
"$",
"name",
"]",
"=",
"$",
"info",
"[",
"'class'",
"]",
";",
"if",
"(",
"$",
"addLong",
")",
"{",
"$",
"out",
"[",
"$",
"info",
"[",
"'fullName'",
"]",
"]",
"=",
"$",
"info",
"[",
"'class'",
"]",
";",
"}",
"}",
"return",
"$",
"out",
";",
"}"
] | Resolve names based on existing commands
@param array $input The results of a CommandScanner operation.
@return string[] A flat map of command names => class names. | [
"Resolve",
"names",
"based",
"on",
"existing",
"commands"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/CommandCollection.php#L181-L202 |
210,690 | cakephp/cakephp | src/Console/CommandCollection.php | CommandCollection.autoDiscover | public function autoDiscover()
{
$scanner = new CommandScanner();
$core = $this->resolveNames($scanner->scanCore());
$app = $this->resolveNames($scanner->scanApp());
return array_merge($core, $app);
} | php | public function autoDiscover()
{
$scanner = new CommandScanner();
$core = $this->resolveNames($scanner->scanCore());
$app = $this->resolveNames($scanner->scanApp());
return array_merge($core, $app);
} | [
"public",
"function",
"autoDiscover",
"(",
")",
"{",
"$",
"scanner",
"=",
"new",
"CommandScanner",
"(",
")",
";",
"$",
"core",
"=",
"$",
"this",
"->",
"resolveNames",
"(",
"$",
"scanner",
"->",
"scanCore",
"(",
")",
")",
";",
"$",
"app",
"=",
"$",
"this",
"->",
"resolveNames",
"(",
"$",
"scanner",
"->",
"scanApp",
"(",
")",
")",
";",
"return",
"array_merge",
"(",
"$",
"core",
",",
"$",
"app",
")",
";",
"}"
] | Automatically discover shell commands in CakePHP, the application and all plugins.
Commands will be located using filesystem conventions. Commands are
discovered in the following order:
- CakePHP provided commands
- Application commands
Commands defined in the application will ovewrite commands with
the same name provided by CakePHP.
@return string[] An array of command names and their classes. | [
"Automatically",
"discover",
"shell",
"commands",
"in",
"CakePHP",
"the",
"application",
"and",
"all",
"plugins",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/CommandCollection.php#L218-L226 |
210,691 | cakephp/cakephp | src/ORM/SaveOptionsBuilder.php | SaveOptionsBuilder.associated | public function associated($associated)
{
$associated = $this->_normalizeAssociations($associated);
$this->_associated($this->_table, $associated);
$this->_options['associated'] = $associated;
return $this;
} | php | public function associated($associated)
{
$associated = $this->_normalizeAssociations($associated);
$this->_associated($this->_table, $associated);
$this->_options['associated'] = $associated;
return $this;
} | [
"public",
"function",
"associated",
"(",
"$",
"associated",
")",
"{",
"$",
"associated",
"=",
"$",
"this",
"->",
"_normalizeAssociations",
"(",
"$",
"associated",
")",
";",
"$",
"this",
"->",
"_associated",
"(",
"$",
"this",
"->",
"_table",
",",
"$",
"associated",
")",
";",
"$",
"this",
"->",
"_options",
"[",
"'associated'",
"]",
"=",
"$",
"associated",
";",
"return",
"$",
"this",
";",
"}"
] | Set associated options.
@param string|array $associated String or array of associations.
@return \Cake\ORM\SaveOptionsBuilder | [
"Set",
"associated",
"options",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/SaveOptionsBuilder.php#L85-L92 |
210,692 | cakephp/cakephp | src/ORM/SaveOptionsBuilder.php | SaveOptionsBuilder._associated | protected function _associated(Table $table, array $associations)
{
foreach ($associations as $key => $associated) {
if (is_int($key)) {
$this->_checkAssociation($table, $associated);
continue;
}
$this->_checkAssociation($table, $key);
if (isset($associated['associated'])) {
$this->_associated($table->getAssociation($key)->getTarget(), $associated['associated']);
continue;
}
}
} | php | protected function _associated(Table $table, array $associations)
{
foreach ($associations as $key => $associated) {
if (is_int($key)) {
$this->_checkAssociation($table, $associated);
continue;
}
$this->_checkAssociation($table, $key);
if (isset($associated['associated'])) {
$this->_associated($table->getAssociation($key)->getTarget(), $associated['associated']);
continue;
}
}
} | [
"protected",
"function",
"_associated",
"(",
"Table",
"$",
"table",
",",
"array",
"$",
"associations",
")",
"{",
"foreach",
"(",
"$",
"associations",
"as",
"$",
"key",
"=>",
"$",
"associated",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"key",
")",
")",
"{",
"$",
"this",
"->",
"_checkAssociation",
"(",
"$",
"table",
",",
"$",
"associated",
")",
";",
"continue",
";",
"}",
"$",
"this",
"->",
"_checkAssociation",
"(",
"$",
"table",
",",
"$",
"key",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"associated",
"[",
"'associated'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_associated",
"(",
"$",
"table",
"->",
"getAssociation",
"(",
"$",
"key",
")",
"->",
"getTarget",
"(",
")",
",",
"$",
"associated",
"[",
"'associated'",
"]",
")",
";",
"continue",
";",
"}",
"}",
"}"
] | Checks that the associations exists recursively.
@param \Cake\ORM\Table $table Table object.
@param array $associations An associations array.
@return void | [
"Checks",
"that",
"the",
"associations",
"exists",
"recursively",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/SaveOptionsBuilder.php#L101-L114 |
210,693 | cakephp/cakephp | src/ORM/SaveOptionsBuilder.php | SaveOptionsBuilder._checkAssociation | protected function _checkAssociation(Table $table, $association)
{
if (!$table->associations()->has($association)) {
throw new RuntimeException(sprintf('Table `%s` is not associated with `%s`', get_class($table), $association));
}
} | php | protected function _checkAssociation(Table $table, $association)
{
if (!$table->associations()->has($association)) {
throw new RuntimeException(sprintf('Table `%s` is not associated with `%s`', get_class($table), $association));
}
} | [
"protected",
"function",
"_checkAssociation",
"(",
"Table",
"$",
"table",
",",
"$",
"association",
")",
"{",
"if",
"(",
"!",
"$",
"table",
"->",
"associations",
"(",
")",
"->",
"has",
"(",
"$",
"association",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Table `%s` is not associated with `%s`'",
",",
"get_class",
"(",
"$",
"table",
")",
",",
"$",
"association",
")",
")",
";",
"}",
"}"
] | Checks if an association exists.
@throws \RuntimeException If no such association exists for the given table.
@param \Cake\ORM\Table $table Table object.
@param string $association Association name.
@return void | [
"Checks",
"if",
"an",
"association",
"exists",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/SaveOptionsBuilder.php#L124-L129 |
210,694 | cakephp/cakephp | src/ORM/SaveOptionsBuilder.php | SaveOptionsBuilder.validate | public function validate($validate)
{
$this->_table->getValidator($validate);
$this->_options['validate'] = $validate;
return $this;
} | php | public function validate($validate)
{
$this->_table->getValidator($validate);
$this->_options['validate'] = $validate;
return $this;
} | [
"public",
"function",
"validate",
"(",
"$",
"validate",
")",
"{",
"$",
"this",
"->",
"_table",
"->",
"getValidator",
"(",
"$",
"validate",
")",
";",
"$",
"this",
"->",
"_options",
"[",
"'validate'",
"]",
"=",
"$",
"validate",
";",
"return",
"$",
"this",
";",
"}"
] | Set the validation rule set to use.
@param string $validate Name of the validation rule set to use.
@return \Cake\ORM\SaveOptionsBuilder | [
"Set",
"the",
"validation",
"rule",
"set",
"to",
"use",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/SaveOptionsBuilder.php#L150-L156 |
210,695 | cakephp/cakephp | src/ORM/SaveOptionsBuilder.php | SaveOptionsBuilder.set | public function set($option, $value)
{
if (method_exists($this, $option)) {
return $this->{$option}($value);
}
$this->_options[$option] = $value;
return $this;
} | php | public function set($option, $value)
{
if (method_exists($this, $option)) {
return $this->{$option}($value);
}
$this->_options[$option] = $value;
return $this;
} | [
"public",
"function",
"set",
"(",
"$",
"option",
",",
"$",
"value",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"option",
")",
")",
"{",
"return",
"$",
"this",
"->",
"{",
"$",
"option",
"}",
"(",
"$",
"value",
")",
";",
"}",
"$",
"this",
"->",
"_options",
"[",
"$",
"option",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Setting custom options.
@param string $option Option key.
@param mixed $value Option value.
@return \Cake\ORM\SaveOptionsBuilder | [
"Setting",
"custom",
"options",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/SaveOptionsBuilder.php#L212-L220 |
210,696 | cakephp/cakephp | src/Core/StaticConfigTrait.php | StaticConfigTrait.setConfig | public static function setConfig($key, $config = null)
{
if ($config === null) {
if (!is_array($key)) {
throw new LogicException('If config is null, key must be an array.');
}
foreach ($key as $name => $settings) {
static::setConfig($name, $settings);
}
return;
}
if (isset(static::$_config[$key])) {
throw new BadMethodCallException(sprintf('Cannot reconfigure existing key "%s"', $key));
}
if (is_object($config)) {
$config = ['className' => $config];
}
if (isset($config['url'])) {
$parsed = static::parseDsn($config['url']);
unset($config['url']);
$config = $parsed + $config;
}
if (isset($config['engine']) && empty($config['className'])) {
$config['className'] = $config['engine'];
unset($config['engine']);
}
static::$_config[$key] = $config;
} | php | public static function setConfig($key, $config = null)
{
if ($config === null) {
if (!is_array($key)) {
throw new LogicException('If config is null, key must be an array.');
}
foreach ($key as $name => $settings) {
static::setConfig($name, $settings);
}
return;
}
if (isset(static::$_config[$key])) {
throw new BadMethodCallException(sprintf('Cannot reconfigure existing key "%s"', $key));
}
if (is_object($config)) {
$config = ['className' => $config];
}
if (isset($config['url'])) {
$parsed = static::parseDsn($config['url']);
unset($config['url']);
$config = $parsed + $config;
}
if (isset($config['engine']) && empty($config['className'])) {
$config['className'] = $config['engine'];
unset($config['engine']);
}
static::$_config[$key] = $config;
} | [
"public",
"static",
"function",
"setConfig",
"(",
"$",
"key",
",",
"$",
"config",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"config",
"===",
"null",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"'If config is null, key must be an array.'",
")",
";",
"}",
"foreach",
"(",
"$",
"key",
"as",
"$",
"name",
"=>",
"$",
"settings",
")",
"{",
"static",
"::",
"setConfig",
"(",
"$",
"name",
",",
"$",
"settings",
")",
";",
"}",
"return",
";",
"}",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"_config",
"[",
"$",
"key",
"]",
")",
")",
"{",
"throw",
"new",
"BadMethodCallException",
"(",
"sprintf",
"(",
"'Cannot reconfigure existing key \"%s\"'",
",",
"$",
"key",
")",
")",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"config",
")",
")",
"{",
"$",
"config",
"=",
"[",
"'className'",
"=>",
"$",
"config",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'url'",
"]",
")",
")",
"{",
"$",
"parsed",
"=",
"static",
"::",
"parseDsn",
"(",
"$",
"config",
"[",
"'url'",
"]",
")",
";",
"unset",
"(",
"$",
"config",
"[",
"'url'",
"]",
")",
";",
"$",
"config",
"=",
"$",
"parsed",
"+",
"$",
"config",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'engine'",
"]",
")",
"&&",
"empty",
"(",
"$",
"config",
"[",
"'className'",
"]",
")",
")",
"{",
"$",
"config",
"[",
"'className'",
"]",
"=",
"$",
"config",
"[",
"'engine'",
"]",
";",
"unset",
"(",
"$",
"config",
"[",
"'engine'",
"]",
")",
";",
"}",
"static",
"::",
"$",
"_config",
"[",
"$",
"key",
"]",
"=",
"$",
"config",
";",
"}"
] | This method can be used to define configuration adapters for an application.
To change an adapter's configuration at runtime, first drop the adapter and then
reconfigure it.
Adapters will not be constructed until the first operation is done.
### Usage
Assuming that the class' name is `Cache` the following scenarios
are supported:
Setting a cache engine up.
```
Cache::setConfig('default', $settings);
```
Injecting a constructed adapter in:
```
Cache::setConfig('default', $instance);
```
Configure multiple adapters at once:
```
Cache::setConfig($arrayOfConfig);
```
@param string|array $key The name of the configuration, or an array of multiple configs.
@param array $config An array of name => configuration data for adapter.
@throws \BadMethodCallException When trying to modify an existing config.
@throws \LogicException When trying to store an invalid structured config array.
@return void | [
"This",
"method",
"can",
"be",
"used",
"to",
"define",
"configuration",
"adapters",
"for",
"an",
"application",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/StaticConfigTrait.php#L75-L107 |
210,697 | cakephp/cakephp | src/Core/StaticConfigTrait.php | StaticConfigTrait.config | public static function config($key, $config = null)
{
deprecationWarning(
get_called_class() . '::config() is deprecated. ' .
'Use setConfig()/getConfig() instead.'
);
if ($config !== null || is_array($key)) {
static::setConfig($key, $config);
return null;
}
return static::getConfig($key);
} | php | public static function config($key, $config = null)
{
deprecationWarning(
get_called_class() . '::config() is deprecated. ' .
'Use setConfig()/getConfig() instead.'
);
if ($config !== null || is_array($key)) {
static::setConfig($key, $config);
return null;
}
return static::getConfig($key);
} | [
"public",
"static",
"function",
"config",
"(",
"$",
"key",
",",
"$",
"config",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"get_called_class",
"(",
")",
".",
"'::config() is deprecated. '",
".",
"'Use setConfig()/getConfig() instead.'",
")",
";",
"if",
"(",
"$",
"config",
"!==",
"null",
"||",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"static",
"::",
"setConfig",
"(",
"$",
"key",
",",
"$",
"config",
")",
";",
"return",
"null",
";",
"}",
"return",
"static",
"::",
"getConfig",
"(",
"$",
"key",
")",
";",
"}"
] | This method can be used to define configuration adapters for an application
or read existing configuration.
To change an adapter's configuration at runtime, first drop the adapter and then
reconfigure it.
Adapters will not be constructed until the first operation is done.
### Usage
Assuming that the class' name is `Cache` the following scenarios
are supported:
Reading config data back:
```
Cache::config('default');
```
Setting a cache engine up.
```
Cache::config('default', $settings);
```
Injecting a constructed adapter in:
```
Cache::config('default', $instance);
```
Configure multiple adapters at once:
```
Cache::config($arrayOfConfig);
```
@deprecated 3.4.0 Use setConfig()/getConfig() instead.
@param string|array $key The name of the configuration, or an array of multiple configs.
@param array|null $config An array of name => configuration data for adapter.
@return array|null Null when adding configuration or an array of configuration data when reading.
@throws \BadMethodCallException When trying to modify an existing config. | [
"This",
"method",
"can",
"be",
"used",
"to",
"define",
"configuration",
"adapters",
"for",
"an",
"application",
"or",
"read",
"existing",
"configuration",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/StaticConfigTrait.php#L164-L178 |
210,698 | cakephp/cakephp | src/Core/StaticConfigTrait.php | StaticConfigTrait.drop | public static function drop($config)
{
if (!isset(static::$_config[$config])) {
return false;
}
if (isset(static::$_registry)) {
static::$_registry->unload($config);
}
unset(static::$_config[$config]);
return true;
} | php | public static function drop($config)
{
if (!isset(static::$_config[$config])) {
return false;
}
if (isset(static::$_registry)) {
static::$_registry->unload($config);
}
unset(static::$_config[$config]);
return true;
} | [
"public",
"static",
"function",
"drop",
"(",
"$",
"config",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"_config",
"[",
"$",
"config",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"_registry",
")",
")",
"{",
"static",
"::",
"$",
"_registry",
"->",
"unload",
"(",
"$",
"config",
")",
";",
"}",
"unset",
"(",
"static",
"::",
"$",
"_config",
"[",
"$",
"config",
"]",
")",
";",
"return",
"true",
";",
"}"
] | Drops a constructed adapter.
If you wish to modify an existing configuration, you should drop it,
change configuration and then re-add it.
If the implementing objects supports a `$_registry` object the named configuration
will also be unloaded from the registry.
@param string $config An existing configuration you wish to remove.
@return bool Success of the removal, returns false when the config does not exist. | [
"Drops",
"a",
"constructed",
"adapter",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/StaticConfigTrait.php#L192-L203 |
210,699 | cakephp/cakephp | src/Core/StaticConfigTrait.php | StaticConfigTrait.dsnClassMap | public static function dsnClassMap(array $map = null)
{
deprecationWarning(
get_called_class() . '::setDsnClassMap() is deprecated. ' .
'Use setDsnClassMap()/getDsnClassMap() instead.'
);
if ($map !== null) {
static::setDsnClassMap($map);
}
return static::getDsnClassMap();
} | php | public static function dsnClassMap(array $map = null)
{
deprecationWarning(
get_called_class() . '::setDsnClassMap() is deprecated. ' .
'Use setDsnClassMap()/getDsnClassMap() instead.'
);
if ($map !== null) {
static::setDsnClassMap($map);
}
return static::getDsnClassMap();
} | [
"public",
"static",
"function",
"dsnClassMap",
"(",
"array",
"$",
"map",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"get_called_class",
"(",
")",
".",
"'::setDsnClassMap() is deprecated. '",
".",
"'Use setDsnClassMap()/getDsnClassMap() instead.'",
")",
";",
"if",
"(",
"$",
"map",
"!==",
"null",
")",
"{",
"static",
"::",
"setDsnClassMap",
"(",
"$",
"map",
")",
";",
"}",
"return",
"static",
"::",
"getDsnClassMap",
"(",
")",
";",
"}"
] | Returns or updates the DSN class map for this class.
@deprecated 3.4.0 Use setDsnClassMap()/getDsnClassMap() instead.
@param array|null $map Additions/edits to the class map to apply.
@return array | [
"Returns",
"or",
"updates",
"the",
"DSN",
"class",
"map",
"for",
"this",
"class",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/StaticConfigTrait.php#L368-L380 |
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.