id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
211,100
cakephp/cakephp
src/ORM/Association.php
Association.cascadeCallbacks
public function cascadeCallbacks($cascadeCallbacks = null) { deprecationWarning( get_called_class() . '::cascadeCallbacks() is deprecated. ' . 'Use setCascadeCallbacks()/getCascadeCallbacks() instead.' ); if ($cascadeCallbacks !== null) { $this->setCascadeCallbacks($cascadeCallbacks); } return $this->getCascadeCallbacks(); }
php
public function cascadeCallbacks($cascadeCallbacks = null) { deprecationWarning( get_called_class() . '::cascadeCallbacks() is deprecated. ' . 'Use setCascadeCallbacks()/getCascadeCallbacks() instead.' ); if ($cascadeCallbacks !== null) { $this->setCascadeCallbacks($cascadeCallbacks); } return $this->getCascadeCallbacks(); }
[ "public", "function", "cascadeCallbacks", "(", "$", "cascadeCallbacks", "=", "null", ")", "{", "deprecationWarning", "(", "get_called_class", "(", ")", ".", "'::cascadeCallbacks() is deprecated. '", ".", "'Use setCascadeCallbacks()/getCascadeCallbacks() instead.'", ")", ";", "if", "(", "$", "cascadeCallbacks", "!==", "null", ")", "{", "$", "this", "->", "setCascadeCallbacks", "(", "$", "cascadeCallbacks", ")", ";", "}", "return", "$", "this", "->", "getCascadeCallbacks", "(", ")", ";", "}" ]
Sets whether or not cascaded deletes should also fire callbacks. If no arguments are passed, the current configured value is returned @deprecated 3.4.0 Use setCascadeCallbacks()/getCascadeCallbacks() instead. @param bool|null $cascadeCallbacks cascade callbacks switch value @return bool
[ "Sets", "whether", "or", "not", "cascaded", "deletes", "should", "also", "fire", "callbacks", ".", "If", "no", "arguments", "are", "passed", "the", "current", "configured", "value", "is", "returned" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L325-L336
211,101
cakephp/cakephp
src/ORM/Association.php
Association.setClassName
public function setClassName($className) { if ($this->_targetTable !== null && get_class($this->_targetTable) !== App::className($className, 'Model/Table', 'Table') ) { throw new InvalidArgumentException( 'The class name doesn\'t match the target table\'s class name.' ); } $this->_className = $className; return $this; }
php
public function setClassName($className) { if ($this->_targetTable !== null && get_class($this->_targetTable) !== App::className($className, 'Model/Table', 'Table') ) { throw new InvalidArgumentException( 'The class name doesn\'t match the target table\'s class name.' ); } $this->_className = $className; return $this; }
[ "public", "function", "setClassName", "(", "$", "className", ")", "{", "if", "(", "$", "this", "->", "_targetTable", "!==", "null", "&&", "get_class", "(", "$", "this", "->", "_targetTable", ")", "!==", "App", "::", "className", "(", "$", "className", ",", "'Model/Table'", ",", "'Table'", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'The class name doesn\\'t match the target table\\'s class name.'", ")", ";", "}", "$", "this", "->", "_className", "=", "$", "className", ";", "return", "$", "this", ";", "}" ]
Sets the class name of the target table object. @param string $className Class name to set. @return $this @throws \InvalidArgumentException In case the class name is set after the target table has been resolved, and it doesn't match the target table's class name.
[ "Sets", "the", "class", "name", "of", "the", "target", "table", "object", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L346-L359
211,102
cakephp/cakephp
src/ORM/Association.php
Association.source
public function source(Table $table = null) { deprecationWarning( get_called_class() . '::source() is deprecated. ' . 'Use setSource()/getSource() instead.' ); if ($table === null) { return $this->_sourceTable; } return $this->_sourceTable = $table; }
php
public function source(Table $table = null) { deprecationWarning( get_called_class() . '::source() is deprecated. ' . 'Use setSource()/getSource() instead.' ); if ($table === null) { return $this->_sourceTable; } return $this->_sourceTable = $table; }
[ "public", "function", "source", "(", "Table", "$", "table", "=", "null", ")", "{", "deprecationWarning", "(", "get_called_class", "(", ")", ".", "'::source() is deprecated. '", ".", "'Use setSource()/getSource() instead.'", ")", ";", "if", "(", "$", "table", "===", "null", ")", "{", "return", "$", "this", "->", "_sourceTable", ";", "}", "return", "$", "this", "->", "_sourceTable", "=", "$", "table", ";", "}" ]
Sets the table instance for the source side of the association. If no arguments are passed, the current configured table instance is returned @deprecated 3.4.0 Use setSource()/getSource() instead. @param \Cake\ORM\Table|null $table the instance to be assigned as source side @return \Cake\ORM\Table
[ "Sets", "the", "table", "instance", "for", "the", "source", "side", "of", "the", "association", ".", "If", "no", "arguments", "are", "passed", "the", "current", "configured", "table", "instance", "is", "returned" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L418-L429
211,103
cakephp/cakephp
src/ORM/Association.php
Association.getTarget
public function getTarget() { if (!$this->_targetTable) { if (strpos($this->_className, '.')) { list($plugin) = pluginSplit($this->_className, true); $registryAlias = $plugin . $this->_name; } else { $registryAlias = $this->_name; } $tableLocator = $this->getTableLocator(); $config = []; $exists = $tableLocator->exists($registryAlias); if (!$exists) { $config = ['className' => $this->_className]; } $this->_targetTable = $tableLocator->get($registryAlias, $config); if ($exists) { $className = $this->_getClassName($registryAlias, ['className' => $this->_className]); if (!$this->_targetTable instanceof $className) { $errorMessage = '%s association "%s" of type "%s" to "%s" doesn\'t match the expected class "%s". '; $errorMessage .= 'You can\'t have an association of the same name with a different target "className" option anywhere in your app.'; throw new RuntimeException(sprintf( $errorMessage, $this->_sourceTable ? get_class($this->_sourceTable) : 'null', $this->getName(), $this->type(), $this->_targetTable ? get_class($this->_targetTable) : 'null', $className )); } } } return $this->_targetTable; }
php
public function getTarget() { if (!$this->_targetTable) { if (strpos($this->_className, '.')) { list($plugin) = pluginSplit($this->_className, true); $registryAlias = $plugin . $this->_name; } else { $registryAlias = $this->_name; } $tableLocator = $this->getTableLocator(); $config = []; $exists = $tableLocator->exists($registryAlias); if (!$exists) { $config = ['className' => $this->_className]; } $this->_targetTable = $tableLocator->get($registryAlias, $config); if ($exists) { $className = $this->_getClassName($registryAlias, ['className' => $this->_className]); if (!$this->_targetTable instanceof $className) { $errorMessage = '%s association "%s" of type "%s" to "%s" doesn\'t match the expected class "%s". '; $errorMessage .= 'You can\'t have an association of the same name with a different target "className" option anywhere in your app.'; throw new RuntimeException(sprintf( $errorMessage, $this->_sourceTable ? get_class($this->_sourceTable) : 'null', $this->getName(), $this->type(), $this->_targetTable ? get_class($this->_targetTable) : 'null', $className )); } } } return $this->_targetTable; }
[ "public", "function", "getTarget", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_targetTable", ")", "{", "if", "(", "strpos", "(", "$", "this", "->", "_className", ",", "'.'", ")", ")", "{", "list", "(", "$", "plugin", ")", "=", "pluginSplit", "(", "$", "this", "->", "_className", ",", "true", ")", ";", "$", "registryAlias", "=", "$", "plugin", ".", "$", "this", "->", "_name", ";", "}", "else", "{", "$", "registryAlias", "=", "$", "this", "->", "_name", ";", "}", "$", "tableLocator", "=", "$", "this", "->", "getTableLocator", "(", ")", ";", "$", "config", "=", "[", "]", ";", "$", "exists", "=", "$", "tableLocator", "->", "exists", "(", "$", "registryAlias", ")", ";", "if", "(", "!", "$", "exists", ")", "{", "$", "config", "=", "[", "'className'", "=>", "$", "this", "->", "_className", "]", ";", "}", "$", "this", "->", "_targetTable", "=", "$", "tableLocator", "->", "get", "(", "$", "registryAlias", ",", "$", "config", ")", ";", "if", "(", "$", "exists", ")", "{", "$", "className", "=", "$", "this", "->", "_getClassName", "(", "$", "registryAlias", ",", "[", "'className'", "=>", "$", "this", "->", "_className", "]", ")", ";", "if", "(", "!", "$", "this", "->", "_targetTable", "instanceof", "$", "className", ")", "{", "$", "errorMessage", "=", "'%s association \"%s\" of type \"%s\" to \"%s\" doesn\\'t match the expected class \"%s\". '", ";", "$", "errorMessage", ".=", "'You can\\'t have an association of the same name with a different target \"className\" option anywhere in your app.'", ";", "throw", "new", "RuntimeException", "(", "sprintf", "(", "$", "errorMessage", ",", "$", "this", "->", "_sourceTable", "?", "get_class", "(", "$", "this", "->", "_sourceTable", ")", ":", "'null'", ",", "$", "this", "->", "getName", "(", ")", ",", "$", "this", "->", "type", "(", ")", ",", "$", "this", "->", "_targetTable", "?", "get_class", "(", "$", "this", "->", "_targetTable", ")", ":", "'null'", ",", "$", "className", ")", ")", ";", "}", "}", "}", "return", "$", "this", "->", "_targetTable", ";", "}" ]
Gets the table instance for the target side of the association. @return \Cake\ORM\Table
[ "Gets", "the", "table", "instance", "for", "the", "target", "side", "of", "the", "association", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L449-L488
211,104
cakephp/cakephp
src/ORM/Association.php
Association.target
public function target(Table $table = null) { deprecationWarning( get_called_class() . '::target() is deprecated. ' . 'Use setTarget()/getTarget() instead.' ); if ($table !== null) { $this->setTarget($table); } return $this->getTarget(); }
php
public function target(Table $table = null) { deprecationWarning( get_called_class() . '::target() is deprecated. ' . 'Use setTarget()/getTarget() instead.' ); if ($table !== null) { $this->setTarget($table); } return $this->getTarget(); }
[ "public", "function", "target", "(", "Table", "$", "table", "=", "null", ")", "{", "deprecationWarning", "(", "get_called_class", "(", ")", ".", "'::target() is deprecated. '", ".", "'Use setTarget()/getTarget() instead.'", ")", ";", "if", "(", "$", "table", "!==", "null", ")", "{", "$", "this", "->", "setTarget", "(", "$", "table", ")", ";", "}", "return", "$", "this", "->", "getTarget", "(", ")", ";", "}" ]
Sets the table instance for the target side of the association. If no arguments are passed, the current configured table instance is returned @deprecated 3.4.0 Use setTarget()/getTarget() instead. @param \Cake\ORM\Table|null $table the instance to be assigned as target side @return \Cake\ORM\Table
[ "Sets", "the", "table", "instance", "for", "the", "target", "side", "of", "the", "association", ".", "If", "no", "arguments", "are", "passed", "the", "current", "configured", "table", "instance", "is", "returned" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L498-L509
211,105
cakephp/cakephp
src/ORM/Association.php
Association.conditions
public function conditions($conditions = null) { deprecationWarning( get_called_class() . '::conditions() is deprecated. ' . 'Use setConditions()/getConditions() instead.' ); if ($conditions !== null) { $this->setConditions($conditions); } return $this->getConditions(); }
php
public function conditions($conditions = null) { deprecationWarning( get_called_class() . '::conditions() is deprecated. ' . 'Use setConditions()/getConditions() instead.' ); if ($conditions !== null) { $this->setConditions($conditions); } return $this->getConditions(); }
[ "public", "function", "conditions", "(", "$", "conditions", "=", "null", ")", "{", "deprecationWarning", "(", "get_called_class", "(", ")", ".", "'::conditions() is deprecated. '", ".", "'Use setConditions()/getConditions() instead.'", ")", ";", "if", "(", "$", "conditions", "!==", "null", ")", "{", "$", "this", "->", "setConditions", "(", "$", "conditions", ")", ";", "}", "return", "$", "this", "->", "getConditions", "(", ")", ";", "}" ]
Sets a list of conditions to be always included when fetching records from the target association. If no parameters are passed the current list is returned @deprecated 3.4.0 Use setConditions()/getConditions() instead. @param array|null $conditions list of conditions to be used @see \Cake\Database\Query::where() for examples on the format of the array @return array|callable
[ "Sets", "a", "list", "of", "conditions", "to", "be", "always", "included", "when", "fetching", "records", "from", "the", "target", "association", ".", "If", "no", "parameters", "are", "passed", "the", "current", "list", "is", "returned" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L547-L558
211,106
cakephp/cakephp
src/ORM/Association.php
Association.getBindingKey
public function getBindingKey() { if ($this->_bindingKey === null) { $this->_bindingKey = $this->isOwningSide($this->getSource()) ? $this->getSource()->getPrimaryKey() : $this->getTarget()->getPrimaryKey(); } return $this->_bindingKey; }
php
public function getBindingKey() { if ($this->_bindingKey === null) { $this->_bindingKey = $this->isOwningSide($this->getSource()) ? $this->getSource()->getPrimaryKey() : $this->getTarget()->getPrimaryKey(); } return $this->_bindingKey; }
[ "public", "function", "getBindingKey", "(", ")", "{", "if", "(", "$", "this", "->", "_bindingKey", "===", "null", ")", "{", "$", "this", "->", "_bindingKey", "=", "$", "this", "->", "isOwningSide", "(", "$", "this", "->", "getSource", "(", ")", ")", "?", "$", "this", "->", "getSource", "(", ")", "->", "getPrimaryKey", "(", ")", ":", "$", "this", "->", "getTarget", "(", ")", "->", "getPrimaryKey", "(", ")", ";", "}", "return", "$", "this", "->", "_bindingKey", ";", "}" ]
Gets the name of the field representing the binding field with the target table. When not manually specified the primary key of the owning side table is used. @return string|array
[ "Gets", "the", "name", "of", "the", "field", "representing", "the", "binding", "field", "with", "the", "target", "table", ".", "When", "not", "manually", "specified", "the", "primary", "key", "of", "the", "owning", "side", "table", "is", "used", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L580-L589
211,107
cakephp/cakephp
src/ORM/Association.php
Association.bindingKey
public function bindingKey($key = null) { deprecationWarning( get_called_class() . '::bindingKey() is deprecated. ' . 'Use setBindingKey()/getBindingKey() instead.' ); if ($key !== null) { $this->setBindingKey($key); } return $this->getBindingKey(); }
php
public function bindingKey($key = null) { deprecationWarning( get_called_class() . '::bindingKey() is deprecated. ' . 'Use setBindingKey()/getBindingKey() instead.' ); if ($key !== null) { $this->setBindingKey($key); } return $this->getBindingKey(); }
[ "public", "function", "bindingKey", "(", "$", "key", "=", "null", ")", "{", "deprecationWarning", "(", "get_called_class", "(", ")", ".", "'::bindingKey() is deprecated. '", ".", "'Use setBindingKey()/getBindingKey() instead.'", ")", ";", "if", "(", "$", "key", "!==", "null", ")", "{", "$", "this", "->", "setBindingKey", "(", "$", "key", ")", ";", "}", "return", "$", "this", "->", "getBindingKey", "(", ")", ";", "}" ]
Sets the name of the field representing the binding field with the target table. When not manually specified the primary key of the owning side table is used. If no parameters are passed the current field is returned @deprecated 3.4.0 Use setBindingKey()/getBindingKey() instead. @param string|null $key the table field to be used to link both tables together @return string|array
[ "Sets", "the", "name", "of", "the", "field", "representing", "the", "binding", "field", "with", "the", "target", "table", ".", "When", "not", "manually", "specified", "the", "primary", "key", "of", "the", "owning", "side", "table", "is", "used", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L601-L612
211,108
cakephp/cakephp
src/ORM/Association.php
Association.foreignKey
public function foreignKey($key = null) { deprecationWarning( get_called_class() . '::foreignKey() is deprecated. ' . 'Use setForeignKey()/getForeignKey() instead.' ); if ($key !== null) { $this->setForeignKey($key); } return $this->getForeignKey(); }
php
public function foreignKey($key = null) { deprecationWarning( get_called_class() . '::foreignKey() is deprecated. ' . 'Use setForeignKey()/getForeignKey() instead.' ); if ($key !== null) { $this->setForeignKey($key); } return $this->getForeignKey(); }
[ "public", "function", "foreignKey", "(", "$", "key", "=", "null", ")", "{", "deprecationWarning", "(", "get_called_class", "(", ")", ".", "'::foreignKey() is deprecated. '", ".", "'Use setForeignKey()/getForeignKey() instead.'", ")", ";", "if", "(", "$", "key", "!==", "null", ")", "{", "$", "this", "->", "setForeignKey", "(", "$", "key", ")", ";", "}", "return", "$", "this", "->", "getForeignKey", "(", ")", ";", "}" ]
Sets the name of the field representing the foreign key to the target table. If no parameters are passed the current field is returned @deprecated 3.4.0 Use setForeignKey()/getForeignKey() instead. @param string|null $key the key to be used to link both tables together @return string|array
[ "Sets", "the", "name", "of", "the", "field", "representing", "the", "foreign", "key", "to", "the", "target", "table", ".", "If", "no", "parameters", "are", "passed", "the", "current", "field", "is", "returned" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L645-L656
211,109
cakephp/cakephp
src/ORM/Association.php
Association.dependent
public function dependent($dependent = null) { deprecationWarning( get_called_class() . '::dependent() is deprecated. ' . 'Use setDependent()/getDependent() instead.' ); if ($dependent !== null) { $this->setDependent($dependent); } return $this->getDependent(); }
php
public function dependent($dependent = null) { deprecationWarning( get_called_class() . '::dependent() is deprecated. ' . 'Use setDependent()/getDependent() instead.' ); if ($dependent !== null) { $this->setDependent($dependent); } return $this->getDependent(); }
[ "public", "function", "dependent", "(", "$", "dependent", "=", "null", ")", "{", "deprecationWarning", "(", "get_called_class", "(", ")", ".", "'::dependent() is deprecated. '", ".", "'Use setDependent()/getDependent() instead.'", ")", ";", "if", "(", "$", "dependent", "!==", "null", ")", "{", "$", "this", "->", "setDependent", "(", "$", "dependent", ")", ";", "}", "return", "$", "this", "->", "getDependent", "(", ")", ";", "}" ]
Sets whether the records on the target table are dependent on the source table. This is primarily used to indicate that records should be removed if the owning record in the source table is deleted. If no parameters are passed the current setting is returned. @deprecated 3.4.0 Use setDependent()/getDependent() instead. @param bool|null $dependent Set the dependent mode. Use null to read the current state. @return bool
[ "Sets", "whether", "the", "records", "on", "the", "target", "table", "are", "dependent", "on", "the", "source", "table", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L701-L712
211,110
cakephp/cakephp
src/ORM/Association.php
Association.canBeJoined
public function canBeJoined(array $options = []) { $strategy = isset($options['strategy']) ? $options['strategy'] : $this->getStrategy(); return $strategy == $this::STRATEGY_JOIN; }
php
public function canBeJoined(array $options = []) { $strategy = isset($options['strategy']) ? $options['strategy'] : $this->getStrategy(); return $strategy == $this::STRATEGY_JOIN; }
[ "public", "function", "canBeJoined", "(", "array", "$", "options", "=", "[", "]", ")", "{", "$", "strategy", "=", "isset", "(", "$", "options", "[", "'strategy'", "]", ")", "?", "$", "options", "[", "'strategy'", "]", ":", "$", "this", "->", "getStrategy", "(", ")", ";", "return", "$", "strategy", "==", "$", "this", "::", "STRATEGY_JOIN", ";", "}" ]
Whether this association can be expressed directly in a query join @param array $options custom options key that could alter the return value @return bool
[ "Whether", "this", "association", "can", "be", "expressed", "directly", "in", "a", "query", "join" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L720-L725
211,111
cakephp/cakephp
src/ORM/Association.php
Association.joinType
public function joinType($type = null) { deprecationWarning( get_called_class() . '::joinType() is deprecated. ' . 'Use setJoinType()/getJoinType() instead.' ); if ($type !== null) { $this->setJoinType($type); } return $this->getJoinType(); }
php
public function joinType($type = null) { deprecationWarning( get_called_class() . '::joinType() is deprecated. ' . 'Use setJoinType()/getJoinType() instead.' ); if ($type !== null) { $this->setJoinType($type); } return $this->getJoinType(); }
[ "public", "function", "joinType", "(", "$", "type", "=", "null", ")", "{", "deprecationWarning", "(", "get_called_class", "(", ")", ".", "'::joinType() is deprecated. '", ".", "'Use setJoinType()/getJoinType() instead.'", ")", ";", "if", "(", "$", "type", "!==", "null", ")", "{", "$", "this", "->", "setJoinType", "(", "$", "type", ")", ";", "}", "return", "$", "this", "->", "getJoinType", "(", ")", ";", "}" ]
Sets the type of join to be used when adding the association to a query. If no arguments are passed, the currently configured type is returned. @deprecated 3.4.0 Use setJoinType()/getJoinType() instead. @param string|null $type the join type to be used (e.g. INNER) @return string
[ "Sets", "the", "type", "of", "join", "to", "be", "used", "when", "adding", "the", "association", "to", "a", "query", ".", "If", "no", "arguments", "are", "passed", "the", "currently", "configured", "type", "is", "returned", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L758-L769
211,112
cakephp/cakephp
src/ORM/Association.php
Association.getProperty
public function getProperty() { if (!$this->_propertyName) { $this->_propertyName = $this->_propertyName(); if (in_array($this->_propertyName, $this->_sourceTable->getSchema()->columns())) { $msg = 'Association property name "%s" clashes with field of same name of table "%s".' . ' You should explicitly specify the "propertyName" option.'; trigger_error( sprintf($msg, $this->_propertyName, $this->_sourceTable->getTable()), E_USER_WARNING ); } } return $this->_propertyName; }
php
public function getProperty() { if (!$this->_propertyName) { $this->_propertyName = $this->_propertyName(); if (in_array($this->_propertyName, $this->_sourceTable->getSchema()->columns())) { $msg = 'Association property name "%s" clashes with field of same name of table "%s".' . ' You should explicitly specify the "propertyName" option.'; trigger_error( sprintf($msg, $this->_propertyName, $this->_sourceTable->getTable()), E_USER_WARNING ); } } return $this->_propertyName; }
[ "public", "function", "getProperty", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_propertyName", ")", "{", "$", "this", "->", "_propertyName", "=", "$", "this", "->", "_propertyName", "(", ")", ";", "if", "(", "in_array", "(", "$", "this", "->", "_propertyName", ",", "$", "this", "->", "_sourceTable", "->", "getSchema", "(", ")", "->", "columns", "(", ")", ")", ")", "{", "$", "msg", "=", "'Association property name \"%s\" clashes with field of same name of table \"%s\".'", ".", "' You should explicitly specify the \"propertyName\" option.'", ";", "trigger_error", "(", "sprintf", "(", "$", "msg", ",", "$", "this", "->", "_propertyName", ",", "$", "this", "->", "_sourceTable", "->", "getTable", "(", ")", ")", ",", "E_USER_WARNING", ")", ";", "}", "}", "return", "$", "this", "->", "_propertyName", ";", "}" ]
Gets the property name that should be filled with data from the target table in the source table record. @return string
[ "Gets", "the", "property", "name", "that", "should", "be", "filled", "with", "data", "from", "the", "target", "table", "in", "the", "source", "table", "record", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L791-L806
211,113
cakephp/cakephp
src/ORM/Association.php
Association.property
public function property($name = null) { deprecationWarning( get_called_class() . '::property() is deprecated. ' . 'Use setProperty()/getProperty() instead.' ); if ($name !== null) { $this->setProperty($name); } return $this->getProperty(); }
php
public function property($name = null) { deprecationWarning( get_called_class() . '::property() is deprecated. ' . 'Use setProperty()/getProperty() instead.' ); if ($name !== null) { $this->setProperty($name); } return $this->getProperty(); }
[ "public", "function", "property", "(", "$", "name", "=", "null", ")", "{", "deprecationWarning", "(", "get_called_class", "(", ")", ".", "'::property() is deprecated. '", ".", "'Use setProperty()/getProperty() instead.'", ")", ";", "if", "(", "$", "name", "!==", "null", ")", "{", "$", "this", "->", "setProperty", "(", "$", "name", ")", ";", "}", "return", "$", "this", "->", "getProperty", "(", ")", ";", "}" ]
Sets the property name that should be filled with data from the target table in the source table record. If no arguments are passed, the currently configured type is returned. @deprecated 3.4.0 Use setProperty()/getProperty() instead. @param string|null $name The name of the association property. Use null to read the current value. @return string
[ "Sets", "the", "property", "name", "that", "should", "be", "filled", "with", "data", "from", "the", "target", "table", "in", "the", "source", "table", "record", ".", "If", "no", "arguments", "are", "passed", "the", "currently", "configured", "type", "is", "returned", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L817-L828
211,114
cakephp/cakephp
src/ORM/Association.php
Association.setStrategy
public function setStrategy($name) { if (!in_array($name, $this->_validStrategies)) { throw new InvalidArgumentException( sprintf('Invalid strategy "%s" was provided', $name) ); } $this->_strategy = $name; return $this; }
php
public function setStrategy($name) { if (!in_array($name, $this->_validStrategies)) { throw new InvalidArgumentException( sprintf('Invalid strategy "%s" was provided', $name) ); } $this->_strategy = $name; return $this; }
[ "public", "function", "setStrategy", "(", "$", "name", ")", "{", "if", "(", "!", "in_array", "(", "$", "name", ",", "$", "this", "->", "_validStrategies", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Invalid strategy \"%s\" was provided'", ",", "$", "name", ")", ")", ";", "}", "$", "this", "->", "_strategy", "=", "$", "name", ";", "return", "$", "this", ";", "}" ]
Sets the strategy name to be used to fetch associated records. Keep in mind that some association types might not implement but a default strategy, rendering any changes to this setting void. @param string $name The strategy type. Use null to read the current value. @return $this @throws \InvalidArgumentException When an invalid strategy is provided.
[ "Sets", "the", "strategy", "name", "to", "be", "used", "to", "fetch", "associated", "records", ".", "Keep", "in", "mind", "that", "some", "association", "types", "might", "not", "implement", "but", "a", "default", "strategy", "rendering", "any", "changes", "to", "this", "setting", "void", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L851-L861
211,115
cakephp/cakephp
src/ORM/Association.php
Association.strategy
public function strategy($name = null) { deprecationWarning( get_called_class() . '::strategy() is deprecated. ' . 'Use setStrategy()/getStrategy() instead.' ); if ($name !== null) { $this->setStrategy($name); } return $this->getStrategy(); }
php
public function strategy($name = null) { deprecationWarning( get_called_class() . '::strategy() is deprecated. ' . 'Use setStrategy()/getStrategy() instead.' ); if ($name !== null) { $this->setStrategy($name); } return $this->getStrategy(); }
[ "public", "function", "strategy", "(", "$", "name", "=", "null", ")", "{", "deprecationWarning", "(", "get_called_class", "(", ")", ".", "'::strategy() is deprecated. '", ".", "'Use setStrategy()/getStrategy() instead.'", ")", ";", "if", "(", "$", "name", "!==", "null", ")", "{", "$", "this", "->", "setStrategy", "(", "$", "name", ")", ";", "}", "return", "$", "this", "->", "getStrategy", "(", ")", ";", "}" ]
Sets the strategy name to be used to fetch associated records. Keep in mind that some association types might not implement but a default strategy, rendering any changes to this setting void. If no arguments are passed, the currently configured strategy is returned. @deprecated 3.4.0 Use setStrategy()/getStrategy() instead. @param string|null $name The strategy type. Use null to read the current value. @return string @throws \InvalidArgumentException When an invalid strategy is provided.
[ "Sets", "the", "strategy", "name", "to", "be", "used", "to", "fetch", "associated", "records", ".", "Keep", "in", "mind", "that", "some", "association", "types", "might", "not", "implement", "but", "a", "default", "strategy", "rendering", "any", "changes", "to", "this", "setting", "void", ".", "If", "no", "arguments", "are", "passed", "the", "currently", "configured", "strategy", "is", "returned", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L886-L897
211,116
cakephp/cakephp
src/ORM/Association.php
Association.finder
public function finder($finder = null) { deprecationWarning( get_called_class() . '::finder() is deprecated. ' . 'Use setFinder()/getFinder() instead.' ); if ($finder !== null) { $this->setFinder($finder); } return $this->getFinder(); }
php
public function finder($finder = null) { deprecationWarning( get_called_class() . '::finder() is deprecated. ' . 'Use setFinder()/getFinder() instead.' ); if ($finder !== null) { $this->setFinder($finder); } return $this->getFinder(); }
[ "public", "function", "finder", "(", "$", "finder", "=", "null", ")", "{", "deprecationWarning", "(", "get_called_class", "(", ")", ".", "'::finder() is deprecated. '", ".", "'Use setFinder()/getFinder() instead.'", ")", ";", "if", "(", "$", "finder", "!==", "null", ")", "{", "$", "this", "->", "setFinder", "(", "$", "finder", ")", ";", "}", "return", "$", "this", "->", "getFinder", "(", ")", ";", "}" ]
Sets the default finder to use for fetching rows from the target table. If no parameters are passed, it will return the currently configured finder name. @deprecated 3.4.0 Use setFinder()/getFinder() instead. @param string|null $finder the finder name to use @return string|array
[ "Sets", "the", "default", "finder", "to", "use", "for", "fetching", "rows", "from", "the", "target", "table", ".", "If", "no", "parameters", "are", "passed", "it", "will", "return", "the", "currently", "configured", "finder", "name", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L931-L942
211,117
cakephp/cakephp
src/ORM/Association.php
Association._appendNotMatching
protected function _appendNotMatching($query, $options) { $target = $this->_targetTable; if (!empty($options['negateMatch'])) { $primaryKey = $query->aliasFields((array)$target->getPrimaryKey(), $this->_name); $query->andWhere(function ($exp) use ($primaryKey) { array_map([$exp, 'isNull'], $primaryKey); return $exp; }); } }
php
protected function _appendNotMatching($query, $options) { $target = $this->_targetTable; if (!empty($options['negateMatch'])) { $primaryKey = $query->aliasFields((array)$target->getPrimaryKey(), $this->_name); $query->andWhere(function ($exp) use ($primaryKey) { array_map([$exp, 'isNull'], $primaryKey); return $exp; }); } }
[ "protected", "function", "_appendNotMatching", "(", "$", "query", ",", "$", "options", ")", "{", "$", "target", "=", "$", "this", "->", "_targetTable", ";", "if", "(", "!", "empty", "(", "$", "options", "[", "'negateMatch'", "]", ")", ")", "{", "$", "primaryKey", "=", "$", "query", "->", "aliasFields", "(", "(", "array", ")", "$", "target", "->", "getPrimaryKey", "(", ")", ",", "$", "this", "->", "_name", ")", ";", "$", "query", "->", "andWhere", "(", "function", "(", "$", "exp", ")", "use", "(", "$", "primaryKey", ")", "{", "array_map", "(", "[", "$", "exp", ",", "'isNull'", "]", ",", "$", "primaryKey", ")", ";", "return", "$", "exp", ";", "}", ")", ";", "}", "}" ]
Conditionally adds a condition to the passed Query that will make it find records where there is no match with this association. @param \Cake\Datasource\QueryInterface $query The query to modify @param array $options Options array containing the `negateMatch` key. @return void
[ "Conditionally", "adds", "a", "condition", "to", "the", "passed", "Query", "that", "will", "make", "it", "find", "records", "where", "there", "is", "no", "match", "with", "this", "association", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L1043-L1054
211,118
cakephp/cakephp
src/ORM/Association.php
Association.transformRow
public function transformRow($row, $nestKey, $joined, $targetProperty = null) { $sourceAlias = $this->getSource()->getAlias(); $nestKey = $nestKey ?: $this->_name; $targetProperty = $targetProperty ?: $this->getProperty(); if (isset($row[$sourceAlias])) { $row[$sourceAlias][$targetProperty] = $row[$nestKey]; unset($row[$nestKey]); } return $row; }
php
public function transformRow($row, $nestKey, $joined, $targetProperty = null) { $sourceAlias = $this->getSource()->getAlias(); $nestKey = $nestKey ?: $this->_name; $targetProperty = $targetProperty ?: $this->getProperty(); if (isset($row[$sourceAlias])) { $row[$sourceAlias][$targetProperty] = $row[$nestKey]; unset($row[$nestKey]); } return $row; }
[ "public", "function", "transformRow", "(", "$", "row", ",", "$", "nestKey", ",", "$", "joined", ",", "$", "targetProperty", "=", "null", ")", "{", "$", "sourceAlias", "=", "$", "this", "->", "getSource", "(", ")", "->", "getAlias", "(", ")", ";", "$", "nestKey", "=", "$", "nestKey", "?", ":", "$", "this", "->", "_name", ";", "$", "targetProperty", "=", "$", "targetProperty", "?", ":", "$", "this", "->", "getProperty", "(", ")", ";", "if", "(", "isset", "(", "$", "row", "[", "$", "sourceAlias", "]", ")", ")", "{", "$", "row", "[", "$", "sourceAlias", "]", "[", "$", "targetProperty", "]", "=", "$", "row", "[", "$", "nestKey", "]", ";", "unset", "(", "$", "row", "[", "$", "nestKey", "]", ")", ";", "}", "return", "$", "row", ";", "}" ]
Correctly nests a result row associated values into the correct array keys inside the source results. @param array $row The row to transform @param string $nestKey The array key under which the results for this association should be found @param bool $joined Whether or not the row is a result of a direct join with this association @param string|null $targetProperty The property name in the source results where the association data shuld be nested in. Will use the default one if not provided. @return array
[ "Correctly", "nests", "a", "result", "row", "associated", "values", "into", "the", "correct", "array", "keys", "inside", "the", "source", "results", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L1069-L1080
211,119
cakephp/cakephp
src/ORM/Association.php
Association.defaultRowValue
public function defaultRowValue($row, $joined) { $sourceAlias = $this->getSource()->getAlias(); if (isset($row[$sourceAlias])) { $row[$sourceAlias][$this->getProperty()] = null; } return $row; }
php
public function defaultRowValue($row, $joined) { $sourceAlias = $this->getSource()->getAlias(); if (isset($row[$sourceAlias])) { $row[$sourceAlias][$this->getProperty()] = null; } return $row; }
[ "public", "function", "defaultRowValue", "(", "$", "row", ",", "$", "joined", ")", "{", "$", "sourceAlias", "=", "$", "this", "->", "getSource", "(", ")", "->", "getAlias", "(", ")", ";", "if", "(", "isset", "(", "$", "row", "[", "$", "sourceAlias", "]", ")", ")", "{", "$", "row", "[", "$", "sourceAlias", "]", "[", "$", "this", "->", "getProperty", "(", ")", "]", "=", "null", ";", "}", "return", "$", "row", ";", "}" ]
Returns a modified row after appending a property for this association with the default empty value according to whether the association was joined or fetched externally. @param array $row The row to set a default on. @param bool $joined Whether or not the row is a result of a direct join with this association @return array
[ "Returns", "a", "modified", "row", "after", "appending", "a", "property", "for", "this", "association", "with", "the", "default", "empty", "value", "according", "to", "whether", "the", "association", "was", "joined", "or", "fetched", "externally", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L1092-L1100
211,120
cakephp/cakephp
src/ORM/Association.php
Association.find
public function find($type = null, array $options = []) { $type = $type ?: $this->getFinder(); list($type, $opts) = $this->_extractFinder($type); return $this->getTarget() ->find($type, $options + $opts) ->where($this->getConditions()); }
php
public function find($type = null, array $options = []) { $type = $type ?: $this->getFinder(); list($type, $opts) = $this->_extractFinder($type); return $this->getTarget() ->find($type, $options + $opts) ->where($this->getConditions()); }
[ "public", "function", "find", "(", "$", "type", "=", "null", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "type", "=", "$", "type", "?", ":", "$", "this", "->", "getFinder", "(", ")", ";", "list", "(", "$", "type", ",", "$", "opts", ")", "=", "$", "this", "->", "_extractFinder", "(", "$", "type", ")", ";", "return", "$", "this", "->", "getTarget", "(", ")", "->", "find", "(", "$", "type", ",", "$", "options", "+", "$", "opts", ")", "->", "where", "(", "$", "this", "->", "getConditions", "(", ")", ")", ";", "}" ]
Proxies the finding operation to the target table's find method and modifies the query accordingly based of this association configuration @param string|array|null $type the type of query to perform, if an array is passed, it will be interpreted as the `$options` parameter @param array $options The options to for the find @see \Cake\ORM\Table::find() @return \Cake\ORM\Query
[ "Proxies", "the", "finding", "operation", "to", "the", "target", "table", "s", "find", "method", "and", "modifies", "the", "query", "accordingly", "based", "of", "this", "association", "configuration" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L1113-L1121
211,121
cakephp/cakephp
src/ORM/Association.php
Association.exists
public function exists($conditions) { if ($this->_conditions) { $conditions = $this ->find('all', ['conditions' => $conditions]) ->clause('where'); } return $this->getTarget()->exists($conditions); }
php
public function exists($conditions) { if ($this->_conditions) { $conditions = $this ->find('all', ['conditions' => $conditions]) ->clause('where'); } return $this->getTarget()->exists($conditions); }
[ "public", "function", "exists", "(", "$", "conditions", ")", "{", "if", "(", "$", "this", "->", "_conditions", ")", "{", "$", "conditions", "=", "$", "this", "->", "find", "(", "'all'", ",", "[", "'conditions'", "=>", "$", "conditions", "]", ")", "->", "clause", "(", "'where'", ")", ";", "}", "return", "$", "this", "->", "getTarget", "(", ")", "->", "exists", "(", "$", "conditions", ")", ";", "}" ]
Proxies the operation to the target table's exists method after appending the default conditions for this association @param array|callable|\Cake\Database\ExpressionInterface $conditions The conditions to use for checking if any record matches. @see \Cake\ORM\Table::exists() @return bool
[ "Proxies", "the", "operation", "to", "the", "target", "table", "s", "exists", "method", "after", "appending", "the", "default", "conditions", "for", "this", "association" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L1132-L1141
211,122
cakephp/cakephp
src/ORM/Association.php
Association.updateAll
public function updateAll($fields, $conditions) { $target = $this->getTarget(); $expression = $target->query() ->where($this->getConditions()) ->where($conditions) ->clause('where'); return $target->updateAll($fields, $expression); }
php
public function updateAll($fields, $conditions) { $target = $this->getTarget(); $expression = $target->query() ->where($this->getConditions()) ->where($conditions) ->clause('where'); return $target->updateAll($fields, $expression); }
[ "public", "function", "updateAll", "(", "$", "fields", ",", "$", "conditions", ")", "{", "$", "target", "=", "$", "this", "->", "getTarget", "(", ")", ";", "$", "expression", "=", "$", "target", "->", "query", "(", ")", "->", "where", "(", "$", "this", "->", "getConditions", "(", ")", ")", "->", "where", "(", "$", "conditions", ")", "->", "clause", "(", "'where'", ")", ";", "return", "$", "target", "->", "updateAll", "(", "$", "fields", ",", "$", "expression", ")", ";", "}" ]
Proxies the update operation to the target table's updateAll method @param array $fields A hash of field => new value. @param mixed $conditions Conditions to be used, accepts anything Query::where() can take. @see \Cake\ORM\Table::updateAll() @return int Count Returns the affected rows.
[ "Proxies", "the", "update", "operation", "to", "the", "target", "table", "s", "updateAll", "method" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L1152-L1161
211,123
cakephp/cakephp
src/ORM/Association.php
Association.deleteAll
public function deleteAll($conditions) { $target = $this->getTarget(); $expression = $target->query() ->where($this->getConditions()) ->where($conditions) ->clause('where'); return $target->deleteAll($expression); }
php
public function deleteAll($conditions) { $target = $this->getTarget(); $expression = $target->query() ->where($this->getConditions()) ->where($conditions) ->clause('where'); return $target->deleteAll($expression); }
[ "public", "function", "deleteAll", "(", "$", "conditions", ")", "{", "$", "target", "=", "$", "this", "->", "getTarget", "(", ")", ";", "$", "expression", "=", "$", "target", "->", "query", "(", ")", "->", "where", "(", "$", "this", "->", "getConditions", "(", ")", ")", "->", "where", "(", "$", "conditions", ")", "->", "clause", "(", "'where'", ")", ";", "return", "$", "target", "->", "deleteAll", "(", "$", "expression", ")", ";", "}" ]
Proxies the delete operation to the target table's deleteAll method @param mixed $conditions Conditions to be used, accepts anything Query::where() can take. @return int Returns the number of affected rows. @see \Cake\ORM\Table::deleteAll()
[ "Proxies", "the", "delete", "operation", "to", "the", "target", "table", "s", "deleteAll", "method" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L1171-L1180
211,124
cakephp/cakephp
src/ORM/Association.php
Association.requiresKeys
public function requiresKeys(array $options = []) { $strategy = isset($options['strategy']) ? $options['strategy'] : $this->getStrategy(); return $strategy === static::STRATEGY_SELECT; }
php
public function requiresKeys(array $options = []) { $strategy = isset($options['strategy']) ? $options['strategy'] : $this->getStrategy(); return $strategy === static::STRATEGY_SELECT; }
[ "public", "function", "requiresKeys", "(", "array", "$", "options", "=", "[", "]", ")", "{", "$", "strategy", "=", "isset", "(", "$", "options", "[", "'strategy'", "]", ")", "?", "$", "options", "[", "'strategy'", "]", ":", "$", "this", "->", "getStrategy", "(", ")", ";", "return", "$", "strategy", "===", "static", "::", "STRATEGY_SELECT", ";", "}" ]
Returns true if the eager loading process will require a set of the owning table's binding keys in order to use them as a filter in the finder query. @param array $options The options containing the strategy to be used. @return bool true if a list of keys will be required
[ "Returns", "true", "if", "the", "eager", "loading", "process", "will", "require", "a", "set", "of", "the", "owning", "table", "s", "binding", "keys", "in", "order", "to", "use", "them", "as", "a", "filter", "in", "the", "finder", "query", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L1189-L1194
211,125
cakephp/cakephp
src/ORM/Association.php
Association._appendFields
protected function _appendFields($query, $surrogate, $options) { if ($query->getEagerLoader()->isAutoFieldsEnabled() === false) { return; } $fields = $surrogate->clause('select') ?: $options['fields']; $target = $this->_targetTable; $autoFields = $surrogate->isAutoFieldsEnabled(); if (empty($fields) && !$autoFields) { if ($options['includeFields'] && ($fields === null || $fields !== false)) { $fields = $target->getSchema()->columns(); } } if ($autoFields === true) { $fields = array_filter((array)$fields); $fields = array_merge($fields, $target->getSchema()->columns()); } if ($fields) { $query->select($query->aliasFields($fields, $this->_name)); } $query->addDefaultTypes($target); }
php
protected function _appendFields($query, $surrogate, $options) { if ($query->getEagerLoader()->isAutoFieldsEnabled() === false) { return; } $fields = $surrogate->clause('select') ?: $options['fields']; $target = $this->_targetTable; $autoFields = $surrogate->isAutoFieldsEnabled(); if (empty($fields) && !$autoFields) { if ($options['includeFields'] && ($fields === null || $fields !== false)) { $fields = $target->getSchema()->columns(); } } if ($autoFields === true) { $fields = array_filter((array)$fields); $fields = array_merge($fields, $target->getSchema()->columns()); } if ($fields) { $query->select($query->aliasFields($fields, $this->_name)); } $query->addDefaultTypes($target); }
[ "protected", "function", "_appendFields", "(", "$", "query", ",", "$", "surrogate", ",", "$", "options", ")", "{", "if", "(", "$", "query", "->", "getEagerLoader", "(", ")", "->", "isAutoFieldsEnabled", "(", ")", "===", "false", ")", "{", "return", ";", "}", "$", "fields", "=", "$", "surrogate", "->", "clause", "(", "'select'", ")", "?", ":", "$", "options", "[", "'fields'", "]", ";", "$", "target", "=", "$", "this", "->", "_targetTable", ";", "$", "autoFields", "=", "$", "surrogate", "->", "isAutoFieldsEnabled", "(", ")", ";", "if", "(", "empty", "(", "$", "fields", ")", "&&", "!", "$", "autoFields", ")", "{", "if", "(", "$", "options", "[", "'includeFields'", "]", "&&", "(", "$", "fields", "===", "null", "||", "$", "fields", "!==", "false", ")", ")", "{", "$", "fields", "=", "$", "target", "->", "getSchema", "(", ")", "->", "columns", "(", ")", ";", "}", "}", "if", "(", "$", "autoFields", "===", "true", ")", "{", "$", "fields", "=", "array_filter", "(", "(", "array", ")", "$", "fields", ")", ";", "$", "fields", "=", "array_merge", "(", "$", "fields", ",", "$", "target", "->", "getSchema", "(", ")", "->", "columns", "(", ")", ")", ";", "}", "if", "(", "$", "fields", ")", "{", "$", "query", "->", "select", "(", "$", "query", "->", "aliasFields", "(", "$", "fields", ",", "$", "this", "->", "_name", ")", ")", ";", "}", "$", "query", "->", "addDefaultTypes", "(", "$", "target", ")", ";", "}" ]
Helper function used to conditionally append fields to the select clause of a query from the fields found in another query object. @param \Cake\ORM\Query $query the query that will get the fields appended to @param \Cake\ORM\Query $surrogate the query having the fields to be copied from @param array $options options passed to the method `attachTo` @return void
[ "Helper", "function", "used", "to", "conditionally", "append", "fields", "to", "the", "select", "clause", "of", "a", "query", "from", "the", "fields", "found", "in", "another", "query", "object", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L1217-L1242
211,126
cakephp/cakephp
src/ORM/Association.php
Association._joinCondition
protected function _joinCondition($options) { $conditions = []; $tAlias = $this->_name; $sAlias = $this->getSource()->getAlias(); $foreignKey = (array)$options['foreignKey']; $bindingKey = (array)$this->getBindingKey(); if (count($foreignKey) !== count($bindingKey)) { if (empty($bindingKey)) { $table = $this->getTarget()->getTable(); if ($this->isOwningSide($this->getSource())) { $table = $this->getSource()->getTable(); } $msg = 'The "%s" table does not define a primary key, and cannot have join conditions generated.'; throw new RuntimeException(sprintf($msg, $table)); } $msg = 'Cannot match provided foreignKey for "%s", got "(%s)" but expected foreign key for "(%s)"'; throw new RuntimeException(sprintf( $msg, $this->_name, implode(', ', $foreignKey), implode(', ', $bindingKey) )); } foreach ($foreignKey as $k => $f) { $field = sprintf('%s.%s', $sAlias, $bindingKey[$k]); $value = new IdentifierExpression(sprintf('%s.%s', $tAlias, $f)); $conditions[$field] = $value; } return $conditions; }
php
protected function _joinCondition($options) { $conditions = []; $tAlias = $this->_name; $sAlias = $this->getSource()->getAlias(); $foreignKey = (array)$options['foreignKey']; $bindingKey = (array)$this->getBindingKey(); if (count($foreignKey) !== count($bindingKey)) { if (empty($bindingKey)) { $table = $this->getTarget()->getTable(); if ($this->isOwningSide($this->getSource())) { $table = $this->getSource()->getTable(); } $msg = 'The "%s" table does not define a primary key, and cannot have join conditions generated.'; throw new RuntimeException(sprintf($msg, $table)); } $msg = 'Cannot match provided foreignKey for "%s", got "(%s)" but expected foreign key for "(%s)"'; throw new RuntimeException(sprintf( $msg, $this->_name, implode(', ', $foreignKey), implode(', ', $bindingKey) )); } foreach ($foreignKey as $k => $f) { $field = sprintf('%s.%s', $sAlias, $bindingKey[$k]); $value = new IdentifierExpression(sprintf('%s.%s', $tAlias, $f)); $conditions[$field] = $value; } return $conditions; }
[ "protected", "function", "_joinCondition", "(", "$", "options", ")", "{", "$", "conditions", "=", "[", "]", ";", "$", "tAlias", "=", "$", "this", "->", "_name", ";", "$", "sAlias", "=", "$", "this", "->", "getSource", "(", ")", "->", "getAlias", "(", ")", ";", "$", "foreignKey", "=", "(", "array", ")", "$", "options", "[", "'foreignKey'", "]", ";", "$", "bindingKey", "=", "(", "array", ")", "$", "this", "->", "getBindingKey", "(", ")", ";", "if", "(", "count", "(", "$", "foreignKey", ")", "!==", "count", "(", "$", "bindingKey", ")", ")", "{", "if", "(", "empty", "(", "$", "bindingKey", ")", ")", "{", "$", "table", "=", "$", "this", "->", "getTarget", "(", ")", "->", "getTable", "(", ")", ";", "if", "(", "$", "this", "->", "isOwningSide", "(", "$", "this", "->", "getSource", "(", ")", ")", ")", "{", "$", "table", "=", "$", "this", "->", "getSource", "(", ")", "->", "getTable", "(", ")", ";", "}", "$", "msg", "=", "'The \"%s\" table does not define a primary key, and cannot have join conditions generated.'", ";", "throw", "new", "RuntimeException", "(", "sprintf", "(", "$", "msg", ",", "$", "table", ")", ")", ";", "}", "$", "msg", "=", "'Cannot match provided foreignKey for \"%s\", got \"(%s)\" but expected foreign key for \"(%s)\"'", ";", "throw", "new", "RuntimeException", "(", "sprintf", "(", "$", "msg", ",", "$", "this", "->", "_name", ",", "implode", "(", "', '", ",", "$", "foreignKey", ")", ",", "implode", "(", "', '", ",", "$", "bindingKey", ")", ")", ")", ";", "}", "foreach", "(", "$", "foreignKey", "as", "$", "k", "=>", "$", "f", ")", "{", "$", "field", "=", "sprintf", "(", "'%s.%s'", ",", "$", "sAlias", ",", "$", "bindingKey", "[", "$", "k", "]", ")", ";", "$", "value", "=", "new", "IdentifierExpression", "(", "sprintf", "(", "'%s.%s'", ",", "$", "tAlias", ",", "$", "f", ")", ")", ";", "$", "conditions", "[", "$", "field", "]", "=", "$", "value", ";", "}", "return", "$", "conditions", ";", "}" ]
Returns a single or multiple conditions to be appended to the generated join clause for getting the results on the target table. @param array $options list of options passed to attachTo method @return array @throws \RuntimeException if the number of columns in the foreignKey do not match the number of columns in the source table primaryKey
[ "Returns", "a", "single", "or", "multiple", "conditions", "to", "be", "appended", "to", "the", "generated", "join", "clause", "for", "getting", "the", "results", "on", "the", "target", "table", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L1340-L1374
211,127
cakephp/cakephp
src/ORM/Association.php
Association._extractFinder
protected function _extractFinder($finderData) { $finderData = (array)$finderData; if (is_numeric(key($finderData))) { return [current($finderData), []]; } return [key($finderData), current($finderData)]; }
php
protected function _extractFinder($finderData) { $finderData = (array)$finderData; if (is_numeric(key($finderData))) { return [current($finderData), []]; } return [key($finderData), current($finderData)]; }
[ "protected", "function", "_extractFinder", "(", "$", "finderData", ")", "{", "$", "finderData", "=", "(", "array", ")", "$", "finderData", ";", "if", "(", "is_numeric", "(", "key", "(", "$", "finderData", ")", ")", ")", "{", "return", "[", "current", "(", "$", "finderData", ")", ",", "[", "]", "]", ";", "}", "return", "[", "key", "(", "$", "finderData", ")", ",", "current", "(", "$", "finderData", ")", "]", ";", "}" ]
Helper method to infer the requested finder and its options. Returns the inferred options from the finder $type. ### Examples: The following will call the finder 'translations' with the value of the finder as its options: $query->contain(['Comments' => ['finder' => ['translations']]]); $query->contain(['Comments' => ['finder' => ['translations' => []]]]); $query->contain(['Comments' => ['finder' => ['translations' => ['locales' => ['en_US']]]]]); @param string|array $finderData The finder name or an array having the name as key and options as value. @return array
[ "Helper", "method", "to", "infer", "the", "requested", "finder", "and", "its", "options", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L1392-L1401
211,128
cakephp/cakephp
src/Http/Middleware/CsrfProtectionMiddleware.php
CsrfProtectionMiddleware._validateAndUnsetTokenField
protected function _validateAndUnsetTokenField(ServerRequest $request) { if (in_array($request->getMethod(), ['PUT', 'POST', 'DELETE', 'PATCH']) || $request->getData()) { $this->_validateToken($request); $body = $request->getParsedBody(); if (is_array($body)) { unset($body[$this->_config['field']]); $request = $request->withParsedBody($body); } } return $request; }
php
protected function _validateAndUnsetTokenField(ServerRequest $request) { if (in_array($request->getMethod(), ['PUT', 'POST', 'DELETE', 'PATCH']) || $request->getData()) { $this->_validateToken($request); $body = $request->getParsedBody(); if (is_array($body)) { unset($body[$this->_config['field']]); $request = $request->withParsedBody($body); } } return $request; }
[ "protected", "function", "_validateAndUnsetTokenField", "(", "ServerRequest", "$", "request", ")", "{", "if", "(", "in_array", "(", "$", "request", "->", "getMethod", "(", ")", ",", "[", "'PUT'", ",", "'POST'", ",", "'DELETE'", ",", "'PATCH'", "]", ")", "||", "$", "request", "->", "getData", "(", ")", ")", "{", "$", "this", "->", "_validateToken", "(", "$", "request", ")", ";", "$", "body", "=", "$", "request", "->", "getParsedBody", "(", ")", ";", "if", "(", "is_array", "(", "$", "body", ")", ")", "{", "unset", "(", "$", "body", "[", "$", "this", "->", "_config", "[", "'field'", "]", "]", ")", ";", "$", "request", "=", "$", "request", "->", "withParsedBody", "(", "$", "body", ")", ";", "}", "}", "return", "$", "request", ";", "}" ]
Checks if the request is POST, PUT, DELETE or PATCH and validates the CSRF token @param \Cake\Http\ServerRequest $request The request object. @return \Cake\Http\ServerRequest
[ "Checks", "if", "the", "request", "is", "POST", "PUT", "DELETE", "or", "PATCH", "and", "validates", "the", "CSRF", "token" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Middleware/CsrfProtectionMiddleware.php#L117-L129
211,129
cakephp/cakephp
src/Http/Middleware/CsrfProtectionMiddleware.php
CsrfProtectionMiddleware._addTokenToRequest
protected function _addTokenToRequest($token, ServerRequest $request) { $params = $request->getAttribute('params'); $params['_csrfToken'] = $token; return $request->withAttribute('params', $params); }
php
protected function _addTokenToRequest($token, ServerRequest $request) { $params = $request->getAttribute('params'); $params['_csrfToken'] = $token; return $request->withAttribute('params', $params); }
[ "protected", "function", "_addTokenToRequest", "(", "$", "token", ",", "ServerRequest", "$", "request", ")", "{", "$", "params", "=", "$", "request", "->", "getAttribute", "(", "'params'", ")", ";", "$", "params", "[", "'_csrfToken'", "]", "=", "$", "token", ";", "return", "$", "request", "->", "withAttribute", "(", "'params'", ",", "$", "params", ")", ";", "}" ]
Add a CSRF token to the request parameters. @param string $token The token to add. @param \Cake\Http\ServerRequest $request The request to augment @return \Cake\Http\ServerRequest Modified request
[ "Add", "a", "CSRF", "token", "to", "the", "request", "parameters", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Middleware/CsrfProtectionMiddleware.php#L148-L154
211,130
cakephp/cakephp
src/Http/Middleware/CsrfProtectionMiddleware.php
CsrfProtectionMiddleware._addTokenCookie
protected function _addTokenCookie($token, ServerRequest $request, Response $response) { $expiry = new Time($this->_config['expiry']); $cookie = new Cookie( $this->_config['cookieName'], $token, $expiry, $request->getAttribute('webroot'), '', (bool)$this->_config['secure'], (bool)$this->_config['httpOnly'] ); return $response->withCookie($cookie); }
php
protected function _addTokenCookie($token, ServerRequest $request, Response $response) { $expiry = new Time($this->_config['expiry']); $cookie = new Cookie( $this->_config['cookieName'], $token, $expiry, $request->getAttribute('webroot'), '', (bool)$this->_config['secure'], (bool)$this->_config['httpOnly'] ); return $response->withCookie($cookie); }
[ "protected", "function", "_addTokenCookie", "(", "$", "token", ",", "ServerRequest", "$", "request", ",", "Response", "$", "response", ")", "{", "$", "expiry", "=", "new", "Time", "(", "$", "this", "->", "_config", "[", "'expiry'", "]", ")", ";", "$", "cookie", "=", "new", "Cookie", "(", "$", "this", "->", "_config", "[", "'cookieName'", "]", ",", "$", "token", ",", "$", "expiry", ",", "$", "request", "->", "getAttribute", "(", "'webroot'", ")", ",", "''", ",", "(", "bool", ")", "$", "this", "->", "_config", "[", "'secure'", "]", ",", "(", "bool", ")", "$", "this", "->", "_config", "[", "'httpOnly'", "]", ")", ";", "return", "$", "response", "->", "withCookie", "(", "$", "cookie", ")", ";", "}" ]
Add a CSRF token to the response cookies. @param string $token The token to add. @param \Cake\Http\ServerRequest $request The request to validate against. @param \Cake\Http\Response $response The response. @return \Cake\Http\Response $response Modified response.
[ "Add", "a", "CSRF", "token", "to", "the", "response", "cookies", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Middleware/CsrfProtectionMiddleware.php#L164-L179
211,131
cakephp/cakephp
src/Mailer/Mailer.php
Mailer.getName
public function getName() { if (!static::$name) { static::$name = str_replace( 'Mailer', '', implode('', array_slice(explode('\\', get_class($this)), -1)) ); } return static::$name; }
php
public function getName() { if (!static::$name) { static::$name = str_replace( 'Mailer', '', implode('', array_slice(explode('\\', get_class($this)), -1)) ); } return static::$name; }
[ "public", "function", "getName", "(", ")", "{", "if", "(", "!", "static", "::", "$", "name", ")", "{", "static", "::", "$", "name", "=", "str_replace", "(", "'Mailer'", ",", "''", ",", "implode", "(", "''", ",", "array_slice", "(", "explode", "(", "'\\\\'", ",", "get_class", "(", "$", "this", ")", ")", ",", "-", "1", ")", ")", ")", ";", "}", "return", "static", "::", "$", "name", ";", "}" ]
Returns the mailer's name. @return string
[ "Returns", "the", "mailer", "s", "name", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Mailer.php#L209-L220
211,132
cakephp/cakephp
src/Mailer/Mailer.php
Mailer.set
public function set($key, $value = null) { $this->_email->setViewVars(is_string($key) ? [$key => $value] : $key); return $this; }
php
public function set($key, $value = null) { $this->_email->setViewVars(is_string($key) ? [$key => $value] : $key); return $this; }
[ "public", "function", "set", "(", "$", "key", ",", "$", "value", "=", "null", ")", "{", "$", "this", "->", "_email", "->", "setViewVars", "(", "is_string", "(", "$", "key", ")", "?", "[", "$", "key", "=>", "$", "value", "]", ":", "$", "key", ")", ";", "return", "$", "this", ";", "}" ]
Sets email view vars. @param string|array $key Variable name or hash of view variables. @param mixed $value View variable value. @return $this
[ "Sets", "email", "view", "vars", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/Mailer.php#L274-L279
211,133
cakephp/cakephp
src/Http/Response.php
Response.send
public function send() { deprecationWarning('Response::send() will be removed in 4.0.0'); if ($this->hasHeader('Location') && $this->_status === 200) { $this->statusCode(302); } $this->_setContent(); $this->sendHeaders(); if ($this->_file) { $this->_sendFile($this->_file, $this->_fileRange); $this->_file = null; $this->_fileRange = []; } else { $this->_sendContent($this->body()); } if (function_exists('fastcgi_finish_request')) { fastcgi_finish_request(); } }
php
public function send() { deprecationWarning('Response::send() will be removed in 4.0.0'); if ($this->hasHeader('Location') && $this->_status === 200) { $this->statusCode(302); } $this->_setContent(); $this->sendHeaders(); if ($this->_file) { $this->_sendFile($this->_file, $this->_fileRange); $this->_file = null; $this->_fileRange = []; } else { $this->_sendContent($this->body()); } if (function_exists('fastcgi_finish_request')) { fastcgi_finish_request(); } }
[ "public", "function", "send", "(", ")", "{", "deprecationWarning", "(", "'Response::send() will be removed in 4.0.0'", ")", ";", "if", "(", "$", "this", "->", "hasHeader", "(", "'Location'", ")", "&&", "$", "this", "->", "_status", "===", "200", ")", "{", "$", "this", "->", "statusCode", "(", "302", ")", ";", "}", "$", "this", "->", "_setContent", "(", ")", ";", "$", "this", "->", "sendHeaders", "(", ")", ";", "if", "(", "$", "this", "->", "_file", ")", "{", "$", "this", "->", "_sendFile", "(", "$", "this", "->", "_file", ",", "$", "this", "->", "_fileRange", ")", ";", "$", "this", "->", "_file", "=", "null", ";", "$", "this", "->", "_fileRange", "=", "[", "]", ";", "}", "else", "{", "$", "this", "->", "_sendContent", "(", "$", "this", "->", "body", "(", ")", ")", ";", "}", "if", "(", "function_exists", "(", "'fastcgi_finish_request'", ")", ")", "{", "fastcgi_finish_request", "(", ")", ";", "}", "}" ]
Sends the complete response to the client including headers and message body. Will echo out the content in the response body. @return void @deprecated 3.4.0 Will be removed in 4.0.0
[ "Sends", "the", "complete", "response", "to", "the", "client", "including", "headers", "and", "message", "body", ".", "Will", "echo", "out", "the", "content", "in", "the", "response", "body", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L488-L510
211,134
cakephp/cakephp
src/Http/Response.php
Response.sendHeaders
public function sendHeaders() { deprecationWarning( 'Will be removed in 4.0.0' ); $file = $line = null; if (headers_sent($file, $line)) { Log::warning("Headers already sent in {$file}:{$line}"); return; } $codeMessage = $this->_statusCodes[$this->_status]; $this->_setCookies(); $this->_sendHeader("{$this->_protocol} {$this->_status} {$codeMessage}"); $this->_setContentType(); foreach ($this->headers as $header => $values) { foreach ((array)$values as $value) { $this->_sendHeader($header, $value); } } }
php
public function sendHeaders() { deprecationWarning( 'Will be removed in 4.0.0' ); $file = $line = null; if (headers_sent($file, $line)) { Log::warning("Headers already sent in {$file}:{$line}"); return; } $codeMessage = $this->_statusCodes[$this->_status]; $this->_setCookies(); $this->_sendHeader("{$this->_protocol} {$this->_status} {$codeMessage}"); $this->_setContentType(); foreach ($this->headers as $header => $values) { foreach ((array)$values as $value) { $this->_sendHeader($header, $value); } } }
[ "public", "function", "sendHeaders", "(", ")", "{", "deprecationWarning", "(", "'Will be removed in 4.0.0'", ")", ";", "$", "file", "=", "$", "line", "=", "null", ";", "if", "(", "headers_sent", "(", "$", "file", ",", "$", "line", ")", ")", "{", "Log", "::", "warning", "(", "\"Headers already sent in {$file}:{$line}\"", ")", ";", "return", ";", "}", "$", "codeMessage", "=", "$", "this", "->", "_statusCodes", "[", "$", "this", "->", "_status", "]", ";", "$", "this", "->", "_setCookies", "(", ")", ";", "$", "this", "->", "_sendHeader", "(", "\"{$this->_protocol} {$this->_status} {$codeMessage}\"", ")", ";", "$", "this", "->", "_setContentType", "(", ")", ";", "foreach", "(", "$", "this", "->", "headers", "as", "$", "header", "=>", "$", "values", ")", "{", "foreach", "(", "(", "array", ")", "$", "values", "as", "$", "value", ")", "{", "$", "this", "->", "_sendHeader", "(", "$", "header", ",", "$", "value", ")", ";", "}", "}", "}" ]
Sends the HTTP headers and cookies. @return void @deprecated 3.4.0 Will be removed in 4.0.0
[ "Sends", "the", "HTTP", "headers", "and", "cookies", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L518-L541
211,135
cakephp/cakephp
src/Http/Response.php
Response._sendHeader
protected function _sendHeader($name, $value = null) { deprecationWarning( 'Will be removed in 4.0.0' ); if ($value === null) { header($name); } else { header("{$name}: {$value}"); } }
php
protected function _sendHeader($name, $value = null) { deprecationWarning( 'Will be removed in 4.0.0' ); if ($value === null) { header($name); } else { header("{$name}: {$value}"); } }
[ "protected", "function", "_sendHeader", "(", "$", "name", ",", "$", "value", "=", "null", ")", "{", "deprecationWarning", "(", "'Will be removed in 4.0.0'", ")", ";", "if", "(", "$", "value", "===", "null", ")", "{", "header", "(", "$", "name", ")", ";", "}", "else", "{", "header", "(", "\"{$name}: {$value}\"", ")", ";", "}", "}" ]
Sends a header to the client. @param string $name the header name @param string|null $value the header value @return void @deprecated 3.4.0 Will be removed in 4.0.0
[ "Sends", "a", "header", "to", "the", "client", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L626-L637
211,136
cakephp/cakephp
src/Http/Response.php
Response._sendContent
protected function _sendContent($content) { deprecationWarning( 'Will be removed in 4.0.0' ); if (!is_string($content) && is_callable($content)) { $content = $content(); } echo $content; }
php
protected function _sendContent($content) { deprecationWarning( 'Will be removed in 4.0.0' ); if (!is_string($content) && is_callable($content)) { $content = $content(); } echo $content; }
[ "protected", "function", "_sendContent", "(", "$", "content", ")", "{", "deprecationWarning", "(", "'Will be removed in 4.0.0'", ")", ";", "if", "(", "!", "is_string", "(", "$", "content", ")", "&&", "is_callable", "(", "$", "content", ")", ")", "{", "$", "content", "=", "$", "content", "(", ")", ";", "}", "echo", "$", "content", ";", "}" ]
Sends a content string to the client. If the content is a callable, it is invoked. The callable should either return a string or output content directly and have no return value. @param string|callable $content String to send as response body or callable which returns/outputs content. @return void @deprecated 3.4.0 Will be removed in 4.0.0
[ "Sends", "a", "content", "string", "to", "the", "client", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L650-L661
211,137
cakephp/cakephp
src/Http/Response.php
Response.header
public function header($header = null, $value = null) { deprecationWarning( 'Response::header() is deprecated. ' . 'Use `withHeader()`, `getHeaderLine()` and `getHeaders()` instead.' ); if ($header === null) { return $this->getSimpleHeaders(); } $headers = is_array($header) ? $header : [$header => $value]; foreach ($headers as $header => $value) { if (is_numeric($header)) { list($header, $value) = [$value, null]; } if ($value === null) { list($header, $value) = explode(':', $header, 2); } $lower = strtolower($header); if (array_key_exists($lower, $this->headerNames)) { $header = $this->headerNames[$lower]; } else { $this->headerNames[$lower] = $header; } $this->headers[$header] = is_array($value) ? array_map('trim', $value) : [trim($value)]; } return $this->getSimpleHeaders(); }
php
public function header($header = null, $value = null) { deprecationWarning( 'Response::header() is deprecated. ' . 'Use `withHeader()`, `getHeaderLine()` and `getHeaders()` instead.' ); if ($header === null) { return $this->getSimpleHeaders(); } $headers = is_array($header) ? $header : [$header => $value]; foreach ($headers as $header => $value) { if (is_numeric($header)) { list($header, $value) = [$value, null]; } if ($value === null) { list($header, $value) = explode(':', $header, 2); } $lower = strtolower($header); if (array_key_exists($lower, $this->headerNames)) { $header = $this->headerNames[$lower]; } else { $this->headerNames[$lower] = $header; } $this->headers[$header] = is_array($value) ? array_map('trim', $value) : [trim($value)]; } return $this->getSimpleHeaders(); }
[ "public", "function", "header", "(", "$", "header", "=", "null", ",", "$", "value", "=", "null", ")", "{", "deprecationWarning", "(", "'Response::header() is deprecated. '", ".", "'Use `withHeader()`, `getHeaderLine()` and `getHeaders()` instead.'", ")", ";", "if", "(", "$", "header", "===", "null", ")", "{", "return", "$", "this", "->", "getSimpleHeaders", "(", ")", ";", "}", "$", "headers", "=", "is_array", "(", "$", "header", ")", "?", "$", "header", ":", "[", "$", "header", "=>", "$", "value", "]", ";", "foreach", "(", "$", "headers", "as", "$", "header", "=>", "$", "value", ")", "{", "if", "(", "is_numeric", "(", "$", "header", ")", ")", "{", "list", "(", "$", "header", ",", "$", "value", ")", "=", "[", "$", "value", ",", "null", "]", ";", "}", "if", "(", "$", "value", "===", "null", ")", "{", "list", "(", "$", "header", ",", "$", "value", ")", "=", "explode", "(", "':'", ",", "$", "header", ",", "2", ")", ";", "}", "$", "lower", "=", "strtolower", "(", "$", "header", ")", ";", "if", "(", "array_key_exists", "(", "$", "lower", ",", "$", "this", "->", "headerNames", ")", ")", "{", "$", "header", "=", "$", "this", "->", "headerNames", "[", "$", "lower", "]", ";", "}", "else", "{", "$", "this", "->", "headerNames", "[", "$", "lower", "]", "=", "$", "header", ";", "}", "$", "this", "->", "headers", "[", "$", "header", "]", "=", "is_array", "(", "$", "value", ")", "?", "array_map", "(", "'trim'", ",", "$", "value", ")", ":", "[", "trim", "(", "$", "value", ")", "]", ";", "}", "return", "$", "this", "->", "getSimpleHeaders", "(", ")", ";", "}" ]
Buffers a header string to be sent Returns the complete list of buffered headers ### Single header ``` header('Location', 'http://example.com'); ``` ### Multiple headers ``` header(['Location' => 'http://example.com', 'X-Extra' => 'My header']); ``` ### String header ``` header('WWW-Authenticate: Negotiate'); ``` ### Array of string headers ``` header(['WWW-Authenticate: Negotiate', 'Content-type: application/pdf']); ``` Multiple calls for setting the same header name will have the same effect as setting the header once with the last value sent for it ``` header('WWW-Authenticate: Negotiate'); header('WWW-Authenticate: Not-Negotiate'); ``` will have the same effect as only doing ``` header('WWW-Authenticate: Not-Negotiate'); ``` @param string|array|null $header An array of header strings or a single header string - an associative array of "header name" => "header value" is also accepted - an array of string headers is also accepted @param string|array|null $value The header value(s) @return array List of headers to be sent @deprecated 3.4.0 Use `withHeader()`, `getHeaderLine()` and `getHeaders()` instead.
[ "Buffers", "a", "header", "string", "to", "be", "sent", "Returns", "the", "complete", "list", "of", "buffered", "headers" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L705-L736
211,138
cakephp/cakephp
src/Http/Response.php
Response.getSimpleHeaders
protected function getSimpleHeaders() { $out = []; foreach ($this->headers as $key => $values) { $header = $this->headerNames[strtolower($key)]; if (count($values) === 1) { $values = $values[0]; } $out[$header] = $values; } return $out; }
php
protected function getSimpleHeaders() { $out = []; foreach ($this->headers as $key => $values) { $header = $this->headerNames[strtolower($key)]; if (count($values) === 1) { $values = $values[0]; } $out[$header] = $values; } return $out; }
[ "protected", "function", "getSimpleHeaders", "(", ")", "{", "$", "out", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "headers", "as", "$", "key", "=>", "$", "values", ")", "{", "$", "header", "=", "$", "this", "->", "headerNames", "[", "strtolower", "(", "$", "key", ")", "]", ";", "if", "(", "count", "(", "$", "values", ")", "===", "1", ")", "{", "$", "values", "=", "$", "values", "[", "0", "]", ";", "}", "$", "out", "[", "$", "header", "]", "=", "$", "values", ";", "}", "return", "$", "out", ";", "}" ]
Backwards compatibility helper for getting flattened headers. Previously CakePHP would store headers as a simple dictionary, now that we're supporting PSR7, the internal storage has each header as an array. @return array
[ "Backwards", "compatibility", "helper", "for", "getting", "flattened", "headers", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L746-L758
211,139
cakephp/cakephp
src/Http/Response.php
Response.location
public function location($url = null) { deprecationWarning( 'Response::location() is deprecated. ' . 'Mutable responses are deprecated. Use `withLocation()` and `getHeaderLine()` instead.' ); if ($url === null) { $result = $this->getHeaderLine('Location'); if (!$result) { return null; } return $result; } if ($this->_status === 200) { $this->_status = 302; } $this->_setHeader('Location', $url); return null; }
php
public function location($url = null) { deprecationWarning( 'Response::location() is deprecated. ' . 'Mutable responses are deprecated. Use `withLocation()` and `getHeaderLine()` instead.' ); if ($url === null) { $result = $this->getHeaderLine('Location'); if (!$result) { return null; } return $result; } if ($this->_status === 200) { $this->_status = 302; } $this->_setHeader('Location', $url); return null; }
[ "public", "function", "location", "(", "$", "url", "=", "null", ")", "{", "deprecationWarning", "(", "'Response::location() is deprecated. '", ".", "'Mutable responses are deprecated. Use `withLocation()` and `getHeaderLine()` instead.'", ")", ";", "if", "(", "$", "url", "===", "null", ")", "{", "$", "result", "=", "$", "this", "->", "getHeaderLine", "(", "'Location'", ")", ";", "if", "(", "!", "$", "result", ")", "{", "return", "null", ";", "}", "return", "$", "result", ";", "}", "if", "(", "$", "this", "->", "_status", "===", "200", ")", "{", "$", "this", "->", "_status", "=", "302", ";", "}", "$", "this", "->", "_setHeader", "(", "'Location'", ",", "$", "url", ")", ";", "return", "null", ";", "}" ]
Accessor for the location header. Get/Set the Location header value. @param null|string $url Either null to get the current location, or a string to set one. @return string|null When setting the location null will be returned. When reading the location a string of the current location header value (if any) will be returned. @deprecated 3.4.0 Mutable responses are deprecated. Use `withLocation()` and `getHeaderLine()` instead.
[ "Accessor", "for", "the", "location", "header", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L771-L792
211,140
cakephp/cakephp
src/Http/Response.php
Response._handleCallableBody
protected function _handleCallableBody(callable $content) { ob_start(); $result1 = $content(); $result2 = ob_get_contents(); ob_get_clean(); if ($result1) { return $result1; } return $result2; }
php
protected function _handleCallableBody(callable $content) { ob_start(); $result1 = $content(); $result2 = ob_get_contents(); ob_get_clean(); if ($result1) { return $result1; } return $result2; }
[ "protected", "function", "_handleCallableBody", "(", "callable", "$", "content", ")", "{", "ob_start", "(", ")", ";", "$", "result1", "=", "$", "content", "(", ")", ";", "$", "result2", "=", "ob_get_contents", "(", ")", ";", "ob_get_clean", "(", ")", ";", "if", "(", "$", "result1", ")", "{", "return", "$", "result1", ";", "}", "return", "$", "result2", ";", "}" ]
Handles the callable body for backward compatibility reasons. @param callable $content Callable content. @return string
[ "Handles", "the", "callable", "body", "for", "backward", "compatibility", "reasons", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L887-L899
211,141
cakephp/cakephp
src/Http/Response.php
Response._setStatus
protected function _setStatus($code, $reasonPhrase = '') { if (!isset($this->_statusCodes[$code])) { throw new InvalidArgumentException(sprintf( 'Invalid status code: %s. Use a valid HTTP status code in range 1xx - 5xx.', $code )); } $this->_status = $code; if (empty($reasonPhrase)) { $reasonPhrase = $this->_statusCodes[$code]; } $this->_reasonPhrase = $reasonPhrase; $this->_setContentType(); }
php
protected function _setStatus($code, $reasonPhrase = '') { if (!isset($this->_statusCodes[$code])) { throw new InvalidArgumentException(sprintf( 'Invalid status code: %s. Use a valid HTTP status code in range 1xx - 5xx.', $code )); } $this->_status = $code; if (empty($reasonPhrase)) { $reasonPhrase = $this->_statusCodes[$code]; } $this->_reasonPhrase = $reasonPhrase; $this->_setContentType(); }
[ "protected", "function", "_setStatus", "(", "$", "code", ",", "$", "reasonPhrase", "=", "''", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_statusCodes", "[", "$", "code", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Invalid status code: %s. Use a valid HTTP status code in range 1xx - 5xx.'", ",", "$", "code", ")", ")", ";", "}", "$", "this", "->", "_status", "=", "$", "code", ";", "if", "(", "empty", "(", "$", "reasonPhrase", ")", ")", "{", "$", "reasonPhrase", "=", "$", "this", "->", "_statusCodes", "[", "$", "code", "]", ";", "}", "$", "this", "->", "_reasonPhrase", "=", "$", "reasonPhrase", ";", "$", "this", "->", "_setContentType", "(", ")", ";", "}" ]
Modifier for response status @param int $code The code to set. @param string $reasonPhrase The response reason phrase. @return void @throws \InvalidArgumentException For invalid status code arguments.
[ "Modifier", "for", "response", "status" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L983-L998
211,142
cakephp/cakephp
src/Http/Response.php
Response.httpCodes
public function httpCodes($code = null) { deprecationWarning('Response::httpCodes(). Will be removed in 4.0.0'); if (empty($code)) { return $this->_statusCodes; } if (is_array($code)) { $codes = array_keys($code); $min = min($codes); if (!is_int($min) || $min < 100 || max($codes) > 999) { throw new InvalidArgumentException('Invalid status code'); } $this->_statusCodes = $code + $this->_statusCodes; return true; } if (!isset($this->_statusCodes[$code])) { return null; } return [$code => $this->_statusCodes[$code]]; }
php
public function httpCodes($code = null) { deprecationWarning('Response::httpCodes(). Will be removed in 4.0.0'); if (empty($code)) { return $this->_statusCodes; } if (is_array($code)) { $codes = array_keys($code); $min = min($codes); if (!is_int($min) || $min < 100 || max($codes) > 999) { throw new InvalidArgumentException('Invalid status code'); } $this->_statusCodes = $code + $this->_statusCodes; return true; } if (!isset($this->_statusCodes[$code])) { return null; } return [$code => $this->_statusCodes[$code]]; }
[ "public", "function", "httpCodes", "(", "$", "code", "=", "null", ")", "{", "deprecationWarning", "(", "'Response::httpCodes(). Will be removed in 4.0.0'", ")", ";", "if", "(", "empty", "(", "$", "code", ")", ")", "{", "return", "$", "this", "->", "_statusCodes", ";", "}", "if", "(", "is_array", "(", "$", "code", ")", ")", "{", "$", "codes", "=", "array_keys", "(", "$", "code", ")", ";", "$", "min", "=", "min", "(", "$", "codes", ")", ";", "if", "(", "!", "is_int", "(", "$", "min", ")", "||", "$", "min", "<", "100", "||", "max", "(", "$", "codes", ")", ">", "999", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Invalid status code'", ")", ";", "}", "$", "this", "->", "_statusCodes", "=", "$", "code", "+", "$", "this", "->", "_statusCodes", ";", "return", "true", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "_statusCodes", "[", "$", "code", "]", ")", ")", "{", "return", "null", ";", "}", "return", "[", "$", "code", "=>", "$", "this", "->", "_statusCodes", "[", "$", "code", "]", "]", ";", "}" ]
Queries & sets valid HTTP response codes & messages. @param int|array|null $code If $code is an integer, then the corresponding code/message is returned if it exists, null if it does not exist. If $code is an array, then the keys are used as codes and the values as messages to add to the default HTTP codes. The codes must be integers greater than 99 and less than 1000. Keep in mind that the HTTP specification outlines that status codes begin with a digit between 1 and 5, which defines the class of response the client is to expect. Example: httpCodes(404); // returns [404 => 'Not Found'] httpCodes([ 381 => 'Unicorn Moved', 555 => 'Unexpected Minotaur' ]); // sets these new values, and returns true httpCodes([ 0 => 'Nothing Here', -1 => 'Reverse Infinity', 12345 => 'Universal Password', 'Hello' => 'World' ]); // throws an exception due to invalid codes For more on HTTP status codes see: http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.1 @return mixed Associative array of the HTTP codes as keys, and the message strings as values, or null of the given $code does not exist. @throws \InvalidArgumentException If an attempt is made to add an invalid status code @deprecated 3.4.0 Will be removed in 4.0.0
[ "Queries", "&", "sets", "valid", "HTTP", "response", "codes", "&", "messages", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L1050-L1072
211,143
cakephp/cakephp
src/Http/Response.php
Response.withType
public function withType($contentType) { $mappedType = $this->resolveType($contentType); $new = clone $this; $new->_contentType = $mappedType; $new->_setContentType(); return $new; }
php
public function withType($contentType) { $mappedType = $this->resolveType($contentType); $new = clone $this; $new->_contentType = $mappedType; $new->_setContentType(); return $new; }
[ "public", "function", "withType", "(", "$", "contentType", ")", "{", "$", "mappedType", "=", "$", "this", "->", "resolveType", "(", "$", "contentType", ")", ";", "$", "new", "=", "clone", "$", "this", ";", "$", "new", "->", "_contentType", "=", "$", "mappedType", ";", "$", "new", "->", "_setContentType", "(", ")", ";", "return", "$", "new", ";", "}" ]
Get an updated response with the content type set. If you attempt to set the type on a 304 or 204 status code response, the content type will not take effect as these status codes do not have content-types. @param string $contentType Either a file extension which will be mapped to a mime-type or a concrete mime-type. @return static
[ "Get", "an", "updated", "response", "with", "the", "content", "type", "set", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L1176-L1184
211,144
cakephp/cakephp
src/Http/Response.php
Response.resolveType
protected function resolveType($contentType) { $mapped = $this->getMimeType($contentType); if ($mapped) { return is_array($mapped) ? current($mapped) : $mapped; } if (strpos($contentType, '/') === false) { throw new InvalidArgumentException(sprintf('"%s" is an invalid content type.', $contentType)); } return $contentType; }
php
protected function resolveType($contentType) { $mapped = $this->getMimeType($contentType); if ($mapped) { return is_array($mapped) ? current($mapped) : $mapped; } if (strpos($contentType, '/') === false) { throw new InvalidArgumentException(sprintf('"%s" is an invalid content type.', $contentType)); } return $contentType; }
[ "protected", "function", "resolveType", "(", "$", "contentType", ")", "{", "$", "mapped", "=", "$", "this", "->", "getMimeType", "(", "$", "contentType", ")", ";", "if", "(", "$", "mapped", ")", "{", "return", "is_array", "(", "$", "mapped", ")", "?", "current", "(", "$", "mapped", ")", ":", "$", "mapped", ";", "}", "if", "(", "strpos", "(", "$", "contentType", ",", "'/'", ")", "===", "false", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'\"%s\" is an invalid content type.'", ",", "$", "contentType", ")", ")", ";", "}", "return", "$", "contentType", ";", "}" ]
Translate and validate content-types. @param string $contentType The content-type or type alias. @return string The resolved content-type @throws \InvalidArgumentException When an invalid content-type or alias is used.
[ "Translate", "and", "validate", "content", "-", "types", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L1193-L1204
211,145
cakephp/cakephp
src/Http/Response.php
Response.getMimeType
public function getMimeType($alias) { if (isset($this->_mimeTypes[$alias])) { return $this->_mimeTypes[$alias]; } return false; }
php
public function getMimeType($alias) { if (isset($this->_mimeTypes[$alias])) { return $this->_mimeTypes[$alias]; } return false; }
[ "public", "function", "getMimeType", "(", "$", "alias", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_mimeTypes", "[", "$", "alias", "]", ")", ")", "{", "return", "$", "this", "->", "_mimeTypes", "[", "$", "alias", "]", ";", "}", "return", "false", ";", "}" ]
Returns the mime type definition for an alias e.g `getMimeType('pdf'); // returns 'application/pdf'` @param string $alias the content type alias to map @return mixed String mapped mime type or false if $alias is not mapped
[ "Returns", "the", "mime", "type", "definition", "for", "an", "alias" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L1214-L1221
211,146
cakephp/cakephp
src/Http/Response.php
Response.mapType
public function mapType($ctype) { if (is_array($ctype)) { return array_map([$this, 'mapType'], $ctype); } foreach ($this->_mimeTypes as $alias => $types) { if (in_array($ctype, (array)$types)) { return $alias; } } return null; }
php
public function mapType($ctype) { if (is_array($ctype)) { return array_map([$this, 'mapType'], $ctype); } foreach ($this->_mimeTypes as $alias => $types) { if (in_array($ctype, (array)$types)) { return $alias; } } return null; }
[ "public", "function", "mapType", "(", "$", "ctype", ")", "{", "if", "(", "is_array", "(", "$", "ctype", ")", ")", "{", "return", "array_map", "(", "[", "$", "this", ",", "'mapType'", "]", ",", "$", "ctype", ")", ";", "}", "foreach", "(", "$", "this", "->", "_mimeTypes", "as", "$", "alias", "=>", "$", "types", ")", "{", "if", "(", "in_array", "(", "$", "ctype", ",", "(", "array", ")", "$", "types", ")", ")", "{", "return", "$", "alias", ";", "}", "}", "return", "null", ";", "}" ]
Maps a content-type back to an alias e.g `mapType('application/pdf'); // returns 'pdf'` @param string|array $ctype Either a string content type to map, or an array of types. @return string|array|null Aliases for the types provided.
[ "Maps", "a", "content", "-", "type", "back", "to", "an", "alias" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L1231-L1244
211,147
cakephp/cakephp
src/Http/Response.php
Response.cache
public function cache($since, $time = '+1 day') { deprecationWarning( 'Response::cache() is deprecated. ' . 'Use withCache() instead.' ); if (!is_int($time)) { $time = strtotime($time); } $this->_setHeader('Date', gmdate('D, j M Y G:i:s ', time()) . 'GMT'); $this->modified($since); $this->expires($time); $this->sharable(true); $this->maxAge($time - time()); }
php
public function cache($since, $time = '+1 day') { deprecationWarning( 'Response::cache() is deprecated. ' . 'Use withCache() instead.' ); if (!is_int($time)) { $time = strtotime($time); } $this->_setHeader('Date', gmdate('D, j M Y G:i:s ', time()) . 'GMT'); $this->modified($since); $this->expires($time); $this->sharable(true); $this->maxAge($time - time()); }
[ "public", "function", "cache", "(", "$", "since", ",", "$", "time", "=", "'+1 day'", ")", "{", "deprecationWarning", "(", "'Response::cache() is deprecated. '", ".", "'Use withCache() instead.'", ")", ";", "if", "(", "!", "is_int", "(", "$", "time", ")", ")", "{", "$", "time", "=", "strtotime", "(", "$", "time", ")", ";", "}", "$", "this", "->", "_setHeader", "(", "'Date'", ",", "gmdate", "(", "'D, j M Y G:i:s '", ",", "time", "(", ")", ")", ".", "'GMT'", ")", ";", "$", "this", "->", "modified", "(", "$", "since", ")", ";", "$", "this", "->", "expires", "(", "$", "time", ")", ";", "$", "this", "->", "sharable", "(", "true", ")", ";", "$", "this", "->", "maxAge", "(", "$", "time", "-", "time", "(", ")", ")", ";", "}" ]
Sets the correct headers to instruct the client to cache the response. @param string $since a valid time since the response text has not been modified @param string $time a valid time for cache expiry @return void @deprecated 3.4.0 Use withCache() instead.
[ "Sets", "the", "correct", "headers", "to", "instruct", "the", "client", "to", "cache", "the", "response", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L1333-L1350
211,148
cakephp/cakephp
src/Http/Response.php
Response.withCache
public function withCache($since, $time = '+1 day') { if (!is_int($time)) { $time = strtotime($time); } return $this->withHeader('Date', gmdate('D, j M Y G:i:s ', time()) . 'GMT') ->withModified($since) ->withExpires($time) ->withSharable(true) ->withMaxAge($time - time()); }
php
public function withCache($since, $time = '+1 day') { if (!is_int($time)) { $time = strtotime($time); } return $this->withHeader('Date', gmdate('D, j M Y G:i:s ', time()) . 'GMT') ->withModified($since) ->withExpires($time) ->withSharable(true) ->withMaxAge($time - time()); }
[ "public", "function", "withCache", "(", "$", "since", ",", "$", "time", "=", "'+1 day'", ")", "{", "if", "(", "!", "is_int", "(", "$", "time", ")", ")", "{", "$", "time", "=", "strtotime", "(", "$", "time", ")", ";", "}", "return", "$", "this", "->", "withHeader", "(", "'Date'", ",", "gmdate", "(", "'D, j M Y G:i:s '", ",", "time", "(", ")", ")", ".", "'GMT'", ")", "->", "withModified", "(", "$", "since", ")", "->", "withExpires", "(", "$", "time", ")", "->", "withSharable", "(", "true", ")", "->", "withMaxAge", "(", "$", "time", "-", "time", "(", ")", ")", ";", "}" ]
Create a new instance with the headers to enable client caching. @param string $since a valid time since the response text has not been modified @param string $time a valid time for cache expiry @return static
[ "Create", "a", "new", "instance", "with", "the", "headers", "to", "enable", "client", "caching", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L1359-L1370
211,149
cakephp/cakephp
src/Http/Response.php
Response.sharable
public function sharable($public = null, $time = null) { deprecationWarning( 'Response::sharable() is deprecated. ' . 'Use withSharable() instead.' ); if ($public === null) { $public = array_key_exists('public', $this->_cacheDirectives); $private = array_key_exists('private', $this->_cacheDirectives); $noCache = array_key_exists('no-cache', $this->_cacheDirectives); if (!$public && !$private && !$noCache) { return null; } return $public || !($private || $noCache); } if ($public) { $this->_cacheDirectives['public'] = true; unset($this->_cacheDirectives['private']); } else { $this->_cacheDirectives['private'] = true; unset($this->_cacheDirectives['public']); } $this->maxAge($time); if (!$time) { $this->_setCacheControl(); } return (bool)$public; }
php
public function sharable($public = null, $time = null) { deprecationWarning( 'Response::sharable() is deprecated. ' . 'Use withSharable() instead.' ); if ($public === null) { $public = array_key_exists('public', $this->_cacheDirectives); $private = array_key_exists('private', $this->_cacheDirectives); $noCache = array_key_exists('no-cache', $this->_cacheDirectives); if (!$public && !$private && !$noCache) { return null; } return $public || !($private || $noCache); } if ($public) { $this->_cacheDirectives['public'] = true; unset($this->_cacheDirectives['private']); } else { $this->_cacheDirectives['private'] = true; unset($this->_cacheDirectives['public']); } $this->maxAge($time); if (!$time) { $this->_setCacheControl(); } return (bool)$public; }
[ "public", "function", "sharable", "(", "$", "public", "=", "null", ",", "$", "time", "=", "null", ")", "{", "deprecationWarning", "(", "'Response::sharable() is deprecated. '", ".", "'Use withSharable() instead.'", ")", ";", "if", "(", "$", "public", "===", "null", ")", "{", "$", "public", "=", "array_key_exists", "(", "'public'", ",", "$", "this", "->", "_cacheDirectives", ")", ";", "$", "private", "=", "array_key_exists", "(", "'private'", ",", "$", "this", "->", "_cacheDirectives", ")", ";", "$", "noCache", "=", "array_key_exists", "(", "'no-cache'", ",", "$", "this", "->", "_cacheDirectives", ")", ";", "if", "(", "!", "$", "public", "&&", "!", "$", "private", "&&", "!", "$", "noCache", ")", "{", "return", "null", ";", "}", "return", "$", "public", "||", "!", "(", "$", "private", "||", "$", "noCache", ")", ";", "}", "if", "(", "$", "public", ")", "{", "$", "this", "->", "_cacheDirectives", "[", "'public'", "]", "=", "true", ";", "unset", "(", "$", "this", "->", "_cacheDirectives", "[", "'private'", "]", ")", ";", "}", "else", "{", "$", "this", "->", "_cacheDirectives", "[", "'private'", "]", "=", "true", ";", "unset", "(", "$", "this", "->", "_cacheDirectives", "[", "'public'", "]", ")", ";", "}", "$", "this", "->", "maxAge", "(", "$", "time", ")", ";", "if", "(", "!", "$", "time", ")", "{", "$", "this", "->", "_setCacheControl", "(", ")", ";", "}", "return", "(", "bool", ")", "$", "public", ";", "}" ]
Sets whether a response is eligible to be cached by intermediate proxies This method controls the `public` or `private` directive in the Cache-Control header @param bool|null $public If set to true, the Cache-Control header will be set as public if set to false, the response will be set to private if no value is provided, it will return whether the response is sharable or not @param int|null $time time in seconds after which the response should no longer be considered fresh @return bool|null
[ "Sets", "whether", "a", "response", "is", "eligible", "to", "be", "cached", "by", "intermediate", "proxies", "This", "method", "controls", "the", "public", "or", "private", "directive", "in", "the", "Cache", "-", "Control", "header" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L1383-L1413
211,150
cakephp/cakephp
src/Http/Response.php
Response.sharedMaxAge
public function sharedMaxAge($seconds = null) { deprecationWarning( 'Response::sharedMaxAge() is deprecated. ' . 'Use withSharedMaxAge() instead.' ); if ($seconds !== null) { $this->_cacheDirectives['s-maxage'] = $seconds; $this->_setCacheControl(); } if (isset($this->_cacheDirectives['s-maxage'])) { return $this->_cacheDirectives['s-maxage']; } return null; }
php
public function sharedMaxAge($seconds = null) { deprecationWarning( 'Response::sharedMaxAge() is deprecated. ' . 'Use withSharedMaxAge() instead.' ); if ($seconds !== null) { $this->_cacheDirectives['s-maxage'] = $seconds; $this->_setCacheControl(); } if (isset($this->_cacheDirectives['s-maxage'])) { return $this->_cacheDirectives['s-maxage']; } return null; }
[ "public", "function", "sharedMaxAge", "(", "$", "seconds", "=", "null", ")", "{", "deprecationWarning", "(", "'Response::sharedMaxAge() is deprecated. '", ".", "'Use withSharedMaxAge() instead.'", ")", ";", "if", "(", "$", "seconds", "!==", "null", ")", "{", "$", "this", "->", "_cacheDirectives", "[", "'s-maxage'", "]", "=", "$", "seconds", ";", "$", "this", "->", "_setCacheControl", "(", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "_cacheDirectives", "[", "'s-maxage'", "]", ")", ")", "{", "return", "$", "this", "->", "_cacheDirectives", "[", "'s-maxage'", "]", ";", "}", "return", "null", ";", "}" ]
Sets the Cache-Control s-maxage directive. The max-age is the number of seconds after which the response should no longer be considered a good candidate to be fetched from a shared cache (like in a proxy server). If called with no parameters, this function will return the current max-age value if any @deprecated 3.6.5 Use withSharedMaxAge() instead. @param int|null $seconds if null, the method will return the current s-maxage value @return int|null
[ "Sets", "the", "Cache", "-", "Control", "s", "-", "maxage", "directive", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L1450-L1465
211,151
cakephp/cakephp
src/Http/Response.php
Response.mustRevalidate
public function mustRevalidate($enable = null) { deprecationWarning( 'Response::mustRevalidate() is deprecated. ' . 'Use withMustRevalidate() instead.' ); if ($enable !== null) { if ($enable) { $this->_cacheDirectives['must-revalidate'] = true; } else { unset($this->_cacheDirectives['must-revalidate']); } $this->_setCacheControl(); } return array_key_exists('must-revalidate', $this->_cacheDirectives); }
php
public function mustRevalidate($enable = null) { deprecationWarning( 'Response::mustRevalidate() is deprecated. ' . 'Use withMustRevalidate() instead.' ); if ($enable !== null) { if ($enable) { $this->_cacheDirectives['must-revalidate'] = true; } else { unset($this->_cacheDirectives['must-revalidate']); } $this->_setCacheControl(); } return array_key_exists('must-revalidate', $this->_cacheDirectives); }
[ "public", "function", "mustRevalidate", "(", "$", "enable", "=", "null", ")", "{", "deprecationWarning", "(", "'Response::mustRevalidate() is deprecated. '", ".", "'Use withMustRevalidate() instead.'", ")", ";", "if", "(", "$", "enable", "!==", "null", ")", "{", "if", "(", "$", "enable", ")", "{", "$", "this", "->", "_cacheDirectives", "[", "'must-revalidate'", "]", "=", "true", ";", "}", "else", "{", "unset", "(", "$", "this", "->", "_cacheDirectives", "[", "'must-revalidate'", "]", ")", ";", "}", "$", "this", "->", "_setCacheControl", "(", ")", ";", "}", "return", "array_key_exists", "(", "'must-revalidate'", ",", "$", "this", "->", "_cacheDirectives", ")", ";", "}" ]
Sets the Cache-Control must-revalidate directive. must-revalidate indicates that the response should not be served stale by a cache under any circumstance without first revalidating with the origin. If called with no parameters, this function will return whether must-revalidate is present. @param bool|null $enable if null, the method will return the current must-revalidate value. If boolean sets or unsets the directive. @return bool @deprecated 3.4.0 Use withMustRevalidate() instead.
[ "Sets", "the", "Cache", "-", "Control", "must", "-", "revalidate", "directive", ".", "must", "-", "revalidate", "indicates", "that", "the", "response", "should", "not", "be", "served", "stale", "by", "a", "cache", "under", "any", "circumstance", "without", "first", "revalidating", "with", "the", "origin", ".", "If", "called", "with", "no", "parameters", "this", "function", "will", "return", "whether", "must", "-", "revalidate", "is", "present", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L1542-L1559
211,152
cakephp/cakephp
src/Http/Response.php
Response._setCacheControl
protected function _setCacheControl() { $control = ''; foreach ($this->_cacheDirectives as $key => $val) { $control .= $val === true ? $key : sprintf('%s=%s', $key, $val); $control .= ', '; } $control = rtrim($control, ', '); $this->_setHeader('Cache-Control', $control); }
php
protected function _setCacheControl() { $control = ''; foreach ($this->_cacheDirectives as $key => $val) { $control .= $val === true ? $key : sprintf('%s=%s', $key, $val); $control .= ', '; } $control = rtrim($control, ', '); $this->_setHeader('Cache-Control', $control); }
[ "protected", "function", "_setCacheControl", "(", ")", "{", "$", "control", "=", "''", ";", "foreach", "(", "$", "this", "->", "_cacheDirectives", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "control", ".=", "$", "val", "===", "true", "?", "$", "key", ":", "sprintf", "(", "'%s=%s'", ",", "$", "key", ",", "$", "val", ")", ";", "$", "control", ".=", "', '", ";", "}", "$", "control", "=", "rtrim", "(", "$", "control", ",", "', '", ")", ";", "$", "this", "->", "_setHeader", "(", "'Cache-Control'", ",", "$", "control", ")", ";", "}" ]
Helper method to generate a valid Cache-Control header from the options set in other methods @return void
[ "Helper", "method", "to", "generate", "a", "valid", "Cache", "-", "Control", "header", "from", "the", "options", "set", "in", "other", "methods" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L1591-L1600
211,153
cakephp/cakephp
src/Http/Response.php
Response.expires
public function expires($time = null) { deprecationWarning( 'Response::expires() is deprecated. ' . 'Use withExpires() instead.' ); if ($time !== null) { $date = $this->_getUTCDate($time); $this->_setHeader('Expires', $date->format('D, j M Y H:i:s') . ' GMT'); } if ($this->hasHeader('Expires')) { return $this->getHeaderLine('Expires'); } return null; }
php
public function expires($time = null) { deprecationWarning( 'Response::expires() is deprecated. ' . 'Use withExpires() instead.' ); if ($time !== null) { $date = $this->_getUTCDate($time); $this->_setHeader('Expires', $date->format('D, j M Y H:i:s') . ' GMT'); } if ($this->hasHeader('Expires')) { return $this->getHeaderLine('Expires'); } return null; }
[ "public", "function", "expires", "(", "$", "time", "=", "null", ")", "{", "deprecationWarning", "(", "'Response::expires() is deprecated. '", ".", "'Use withExpires() instead.'", ")", ";", "if", "(", "$", "time", "!==", "null", ")", "{", "$", "date", "=", "$", "this", "->", "_getUTCDate", "(", "$", "time", ")", ";", "$", "this", "->", "_setHeader", "(", "'Expires'", ",", "$", "date", "->", "format", "(", "'D, j M Y H:i:s'", ")", ".", "' GMT'", ")", ";", "}", "if", "(", "$", "this", "->", "hasHeader", "(", "'Expires'", ")", ")", "{", "return", "$", "this", "->", "getHeaderLine", "(", "'Expires'", ")", ";", "}", "return", "null", ";", "}" ]
Sets the Expires header for the response by taking an expiration time If called with no parameters it will return the current Expires value ### Examples: `$response->expires('now')` Will Expire the response cache now `$response->expires(new DateTime('+1 day'))` Will set the expiration in next 24 hours `$response->expires()` Will return the current expiration header value @param string|\DateTimeInterface|null $time Valid time string or \DateTime instance. @return string|null @deprecated 3.4.0 Use withExpires() instead.
[ "Sets", "the", "Expires", "header", "for", "the", "response", "by", "taking", "an", "expiration", "time", "If", "called", "with", "no", "parameters", "it", "will", "return", "the", "current", "Expires", "value" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L1616-L1633
211,154
cakephp/cakephp
src/Http/Response.php
Response.withExpires
public function withExpires($time) { $date = $this->_getUTCDate($time); return $this->withHeader('Expires', $date->format('D, j M Y H:i:s') . ' GMT'); }
php
public function withExpires($time) { $date = $this->_getUTCDate($time); return $this->withHeader('Expires', $date->format('D, j M Y H:i:s') . ' GMT'); }
[ "public", "function", "withExpires", "(", "$", "time", ")", "{", "$", "date", "=", "$", "this", "->", "_getUTCDate", "(", "$", "time", ")", ";", "return", "$", "this", "->", "withHeader", "(", "'Expires'", ",", "$", "date", "->", "format", "(", "'D, j M Y H:i:s'", ")", ".", "' GMT'", ")", ";", "}" ]
Create a new instance with the Expires header set. ### Examples: ``` // Will Expire the response cache now $response->withExpires('now') // Will set the expiration in next 24 hours $response->withExpires(new DateTime('+1 day')) ``` @param string|\DateTimeInterface $time Valid time string or \DateTime instance. @return static
[ "Create", "a", "new", "instance", "with", "the", "Expires", "header", "set", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L1651-L1656
211,155
cakephp/cakephp
src/Http/Response.php
Response.withModified
public function withModified($time) { $date = $this->_getUTCDate($time); return $this->withHeader('Last-Modified', $date->format('D, j M Y H:i:s') . ' GMT'); }
php
public function withModified($time) { $date = $this->_getUTCDate($time); return $this->withHeader('Last-Modified', $date->format('D, j M Y H:i:s') . ' GMT'); }
[ "public", "function", "withModified", "(", "$", "time", ")", "{", "$", "date", "=", "$", "this", "->", "_getUTCDate", "(", "$", "time", ")", ";", "return", "$", "this", "->", "withHeader", "(", "'Last-Modified'", ",", "$", "date", "->", "format", "(", "'D, j M Y H:i:s'", ")", ".", "' GMT'", ")", ";", "}" ]
Create a new instance with the Last-Modified header set. ### Examples: ``` // Will Expire the response cache now $response->withModified('now') // Will set the expiration in next 24 hours $response->withModified(new DateTime('+1 day')) ``` @param string|\DateTimeInterface $time Valid time string or \DateTimeInterface instance. @return static
[ "Create", "a", "new", "instance", "with", "the", "Last", "-", "Modified", "header", "set", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L1707-L1712
211,156
cakephp/cakephp
src/Http/Response.php
Response.notModified
public function notModified() { $this->_createStream(); $this->_setStatus(304); $remove = [ 'Allow', 'Content-Encoding', 'Content-Language', 'Content-Length', 'Content-MD5', 'Content-Type', 'Last-Modified' ]; foreach ($remove as $header) { $this->_clearHeader($header); } }
php
public function notModified() { $this->_createStream(); $this->_setStatus(304); $remove = [ 'Allow', 'Content-Encoding', 'Content-Language', 'Content-Length', 'Content-MD5', 'Content-Type', 'Last-Modified' ]; foreach ($remove as $header) { $this->_clearHeader($header); } }
[ "public", "function", "notModified", "(", ")", "{", "$", "this", "->", "_createStream", "(", ")", ";", "$", "this", "->", "_setStatus", "(", "304", ")", ";", "$", "remove", "=", "[", "'Allow'", ",", "'Content-Encoding'", ",", "'Content-Language'", ",", "'Content-Length'", ",", "'Content-MD5'", ",", "'Content-Type'", ",", "'Last-Modified'", "]", ";", "foreach", "(", "$", "remove", "as", "$", "header", ")", "{", "$", "this", "->", "_clearHeader", "(", "$", "header", ")", ";", "}", "}" ]
Sets the response as Not Modified by removing any body contents setting the status code to "304 Not Modified" and removing all conflicting headers *Warning* This method mutates the response in-place and should be avoided. @return void
[ "Sets", "the", "response", "as", "Not", "Modified", "by", "removing", "any", "body", "contents", "setting", "the", "status", "code", "to", "304", "Not", "Modified", "and", "removing", "all", "conflicting", "headers" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L1723-L1740
211,157
cakephp/cakephp
src/Http/Response.php
Response.withNotModified
public function withNotModified() { $new = $this->withStatus(304); $new->_createStream(); $remove = [ 'Allow', 'Content-Encoding', 'Content-Language', 'Content-Length', 'Content-MD5', 'Content-Type', 'Last-Modified' ]; foreach ($remove as $header) { $new = $new->withoutHeader($header); } return $new; }
php
public function withNotModified() { $new = $this->withStatus(304); $new->_createStream(); $remove = [ 'Allow', 'Content-Encoding', 'Content-Language', 'Content-Length', 'Content-MD5', 'Content-Type', 'Last-Modified' ]; foreach ($remove as $header) { $new = $new->withoutHeader($header); } return $new; }
[ "public", "function", "withNotModified", "(", ")", "{", "$", "new", "=", "$", "this", "->", "withStatus", "(", "304", ")", ";", "$", "new", "->", "_createStream", "(", ")", ";", "$", "remove", "=", "[", "'Allow'", ",", "'Content-Encoding'", ",", "'Content-Language'", ",", "'Content-Length'", ",", "'Content-MD5'", ",", "'Content-Type'", ",", "'Last-Modified'", "]", ";", "foreach", "(", "$", "remove", "as", "$", "header", ")", "{", "$", "new", "=", "$", "new", "->", "withoutHeader", "(", "$", "header", ")", ";", "}", "return", "$", "new", ";", "}" ]
Create a new instance as 'not modified' This will remove any body contents set the status code to "304" and removing headers that describe a response body. @return static
[ "Create", "a", "new", "instance", "as", "not", "modified" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L1751-L1769
211,158
cakephp/cakephp
src/Http/Response.php
Response.vary
public function vary($cacheVariances = null) { deprecationWarning( 'Response::vary() is deprecated. ' . 'Use withVary() instead.' ); if ($cacheVariances !== null) { $cacheVariances = (array)$cacheVariances; $this->_setHeader('Vary', implode(', ', $cacheVariances)); } if ($this->hasHeader('Vary')) { return explode(', ', $this->getHeaderLine('Vary')); } return null; }
php
public function vary($cacheVariances = null) { deprecationWarning( 'Response::vary() is deprecated. ' . 'Use withVary() instead.' ); if ($cacheVariances !== null) { $cacheVariances = (array)$cacheVariances; $this->_setHeader('Vary', implode(', ', $cacheVariances)); } if ($this->hasHeader('Vary')) { return explode(', ', $this->getHeaderLine('Vary')); } return null; }
[ "public", "function", "vary", "(", "$", "cacheVariances", "=", "null", ")", "{", "deprecationWarning", "(", "'Response::vary() is deprecated. '", ".", "'Use withVary() instead.'", ")", ";", "if", "(", "$", "cacheVariances", "!==", "null", ")", "{", "$", "cacheVariances", "=", "(", "array", ")", "$", "cacheVariances", ";", "$", "this", "->", "_setHeader", "(", "'Vary'", ",", "implode", "(", "', '", ",", "$", "cacheVariances", ")", ")", ";", "}", "if", "(", "$", "this", "->", "hasHeader", "(", "'Vary'", ")", ")", "{", "return", "explode", "(", "', '", ",", "$", "this", "->", "getHeaderLine", "(", "'Vary'", ")", ")", ";", "}", "return", "null", ";", "}" ]
Sets the Vary header for the response, if an array is passed, values will be imploded into a comma separated string. If no parameters are passed, then an array with the current Vary header value is returned @param string|array|null $cacheVariances A single Vary string or an array containing the list for variances. @return array|null @deprecated 3.4.0 Use withVary() instead.
[ "Sets", "the", "Vary", "header", "for", "the", "response", "if", "an", "array", "is", "passed", "values", "will", "be", "imploded", "into", "a", "comma", "separated", "string", ".", "If", "no", "parameters", "are", "passed", "then", "an", "array", "with", "the", "current", "Vary", "header", "value", "is", "returned" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L1782-L1799
211,159
cakephp/cakephp
src/Http/Response.php
Response.etag
public function etag($hash = null, $weak = false) { deprecationWarning( 'Response::etag() is deprecated. ' . 'Use withEtag() or getHeaderLine("Etag") instead.' ); if ($hash !== null) { $this->_setHeader('Etag', sprintf('%s"%s"', $weak ? 'W/' : null, $hash)); } if ($this->hasHeader('Etag')) { return $this->getHeaderLine('Etag'); } return null; }
php
public function etag($hash = null, $weak = false) { deprecationWarning( 'Response::etag() is deprecated. ' . 'Use withEtag() or getHeaderLine("Etag") instead.' ); if ($hash !== null) { $this->_setHeader('Etag', sprintf('%s"%s"', $weak ? 'W/' : null, $hash)); } if ($this->hasHeader('Etag')) { return $this->getHeaderLine('Etag'); } return null; }
[ "public", "function", "etag", "(", "$", "hash", "=", "null", ",", "$", "weak", "=", "false", ")", "{", "deprecationWarning", "(", "'Response::etag() is deprecated. '", ".", "'Use withEtag() or getHeaderLine(\"Etag\") instead.'", ")", ";", "if", "(", "$", "hash", "!==", "null", ")", "{", "$", "this", "->", "_setHeader", "(", "'Etag'", ",", "sprintf", "(", "'%s\"%s\"'", ",", "$", "weak", "?", "'W/'", ":", "null", ",", "$", "hash", ")", ")", ";", "}", "if", "(", "$", "this", "->", "hasHeader", "(", "'Etag'", ")", ")", "{", "return", "$", "this", "->", "getHeaderLine", "(", "'Etag'", ")", ";", "}", "return", "null", ";", "}" ]
Sets the response Etag, Etags are a strong indicative that a response can be cached by a HTTP client. A bad way of generating Etags is creating a hash of the response output, instead generate a unique hash of the unique components that identifies a request, such as a modification time, a resource Id, and anything else you consider it makes it unique. Second parameter is used to instruct clients that the content has changed, but semantically, it can be used as the same thing. Think for instance of a page with a hit counter, two different page views are equivalent, but they differ by a few bytes. This leaves off to the Client the decision of using or not the cached page. If no parameters are passed, current Etag header is returned. @param string|null $hash The unique hash that identifies this response @param bool $weak Whether the response is semantically the same as other with the same hash or not @return string|null @deprecated 3.4.0 Use withEtag() instead.
[ "Sets", "the", "response", "Etag", "Etags", "are", "a", "strong", "indicative", "that", "a", "response", "can", "be", "cached", "by", "a", "HTTP", "client", ".", "A", "bad", "way", "of", "generating", "Etags", "is", "creating", "a", "hash", "of", "the", "response", "output", "instead", "generate", "a", "unique", "hash", "of", "the", "unique", "components", "that", "identifies", "a", "request", "such", "as", "a", "modification", "time", "a", "resource", "Id", "and", "anything", "else", "you", "consider", "it", "makes", "it", "unique", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L1839-L1855
211,160
cakephp/cakephp
src/Http/Response.php
Response.length
public function length($bytes = null) { deprecationWarning( 'Response::length() is deprecated. ' . 'Use withLength() instead.' ); if ($bytes !== null) { $this->_setHeader('Content-Length', $bytes); } if ($this->hasHeader('Content-Length')) { return $this->getHeaderLine('Content-Length'); } return null; }
php
public function length($bytes = null) { deprecationWarning( 'Response::length() is deprecated. ' . 'Use withLength() instead.' ); if ($bytes !== null) { $this->_setHeader('Content-Length', $bytes); } if ($this->hasHeader('Content-Length')) { return $this->getHeaderLine('Content-Length'); } return null; }
[ "public", "function", "length", "(", "$", "bytes", "=", "null", ")", "{", "deprecationWarning", "(", "'Response::length() is deprecated. '", ".", "'Use withLength() instead.'", ")", ";", "if", "(", "$", "bytes", "!==", "null", ")", "{", "$", "this", "->", "_setHeader", "(", "'Content-Length'", ",", "$", "bytes", ")", ";", "}", "if", "(", "$", "this", "->", "hasHeader", "(", "'Content-Length'", ")", ")", "{", "return", "$", "this", "->", "getHeaderLine", "(", "'Content-Length'", ")", ";", "}", "return", "null", ";", "}" ]
Sets the Content-Length header for the response If called with no arguments returns the last Content-Length set @param int|null $bytes Number of bytes @return string|null @deprecated 3.4.0 Use withLength() to set length instead.
[ "Sets", "the", "Content", "-", "Length", "header", "for", "the", "response", "If", "called", "with", "no", "arguments", "returns", "the", "last", "Content", "-", "Length", "set" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L1989-L2005
211,161
cakephp/cakephp
src/Http/Response.php
Response.withAddedLink
public function withAddedLink($url, $options = []) { $params = []; foreach ($options as $key => $option) { $params[] = $key . '="' . $option . '"'; } $param = ''; if ($params) { $param = '; ' . implode('; ', $params); } return $this->withAddedHeader('Link', '<' . $url . '>' . $param); }
php
public function withAddedLink($url, $options = []) { $params = []; foreach ($options as $key => $option) { $params[] = $key . '="' . $option . '"'; } $param = ''; if ($params) { $param = '; ' . implode('; ', $params); } return $this->withAddedHeader('Link', '<' . $url . '>' . $param); }
[ "public", "function", "withAddedLink", "(", "$", "url", ",", "$", "options", "=", "[", "]", ")", "{", "$", "params", "=", "[", "]", ";", "foreach", "(", "$", "options", "as", "$", "key", "=>", "$", "option", ")", "{", "$", "params", "[", "]", "=", "$", "key", ".", "'=\"'", ".", "$", "option", ".", "'\"'", ";", "}", "$", "param", "=", "''", ";", "if", "(", "$", "params", ")", "{", "$", "param", "=", "'; '", ".", "implode", "(", "'; '", ",", "$", "params", ")", ";", "}", "return", "$", "this", "->", "withAddedHeader", "(", "'Link'", ",", "'<'", ".", "$", "url", ".", "'>'", ".", "$", "param", ")", ";", "}" ]
Create a new response with the Link header set. ### Examples ``` $response = $response->withAddedLink('http://example.com?page=1', ['rel' => 'prev']) ->withAddedLink('http://example.com?page=3', ['rel' => 'next']); ``` Will generate: ``` Link: <http://example.com?page=1>; rel="prev" Link: <http://example.com?page=3>; rel="next" ``` @param string $url The LinkHeader url. @param array $options The LinkHeader params. @return static @since 3.6.0
[ "Create", "a", "new", "response", "with", "the", "Link", "header", "set", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L2040-L2053
211,162
cakephp/cakephp
src/Http/Response.php
Response.withCookie
public function withCookie($name, $data = '') { if ($name instanceof Cookie) { $cookie = $name; } else { deprecationWarning( get_called_class() . '::withCookie(string $name, array $data) is deprecated. ' . 'Pass an instance of \Cake\Http\Cookie\Cookie instead.' ); if (!is_array($data)) { $data = ['value' => $data]; } $data += [ 'value' => '', 'expire' => 0, 'path' => '/', 'domain' => '', 'secure' => false, 'httpOnly' => false ]; $expires = $data['expire'] ? new DateTime('@' . $data['expire']) : null; $cookie = new Cookie( $name, $data['value'], $expires, $data['path'], $data['domain'], $data['secure'], $data['httpOnly'] ); } $new = clone $this; $new->_cookies = $new->_cookies->add($cookie); return $new; }
php
public function withCookie($name, $data = '') { if ($name instanceof Cookie) { $cookie = $name; } else { deprecationWarning( get_called_class() . '::withCookie(string $name, array $data) is deprecated. ' . 'Pass an instance of \Cake\Http\Cookie\Cookie instead.' ); if (!is_array($data)) { $data = ['value' => $data]; } $data += [ 'value' => '', 'expire' => 0, 'path' => '/', 'domain' => '', 'secure' => false, 'httpOnly' => false ]; $expires = $data['expire'] ? new DateTime('@' . $data['expire']) : null; $cookie = new Cookie( $name, $data['value'], $expires, $data['path'], $data['domain'], $data['secure'], $data['httpOnly'] ); } $new = clone $this; $new->_cookies = $new->_cookies->add($cookie); return $new; }
[ "public", "function", "withCookie", "(", "$", "name", ",", "$", "data", "=", "''", ")", "{", "if", "(", "$", "name", "instanceof", "Cookie", ")", "{", "$", "cookie", "=", "$", "name", ";", "}", "else", "{", "deprecationWarning", "(", "get_called_class", "(", ")", ".", "'::withCookie(string $name, array $data) is deprecated. '", ".", "'Pass an instance of \\Cake\\Http\\Cookie\\Cookie instead.'", ")", ";", "if", "(", "!", "is_array", "(", "$", "data", ")", ")", "{", "$", "data", "=", "[", "'value'", "=>", "$", "data", "]", ";", "}", "$", "data", "+=", "[", "'value'", "=>", "''", ",", "'expire'", "=>", "0", ",", "'path'", "=>", "'/'", ",", "'domain'", "=>", "''", ",", "'secure'", "=>", "false", ",", "'httpOnly'", "=>", "false", "]", ";", "$", "expires", "=", "$", "data", "[", "'expire'", "]", "?", "new", "DateTime", "(", "'@'", ".", "$", "data", "[", "'expire'", "]", ")", ":", "null", ";", "$", "cookie", "=", "new", "Cookie", "(", "$", "name", ",", "$", "data", "[", "'value'", "]", ",", "$", "expires", ",", "$", "data", "[", "'path'", "]", ",", "$", "data", "[", "'domain'", "]", ",", "$", "data", "[", "'secure'", "]", ",", "$", "data", "[", "'httpOnly'", "]", ")", ";", "}", "$", "new", "=", "clone", "$", "this", ";", "$", "new", "->", "_cookies", "=", "$", "new", "->", "_cookies", "->", "add", "(", "$", "cookie", ")", ";", "return", "$", "new", ";", "}" ]
Create a new response with a cookie set. ### Data - `value`: Value of the cookie - `expire`: Time the cookie expires in - `path`: Path the cookie applies to - `domain`: Domain the cookie is for. - `secure`: Is the cookie https? - `httpOnly`: Is the cookie available in the client? ### Examples ``` // set scalar value with defaults $response = $response->withCookie('remember_me', 1); // customize cookie attributes $response = $response->withCookie('remember_me', ['path' => '/login']); // add a cookie object $response = $response->withCookie(new Cookie('remember_me', 1)); ``` @param string|\Cake\Http\Cookie\Cookie $name The name of the cookie to set, or a cookie object @param array|string $data Either a string value, or an array of cookie options. @return static
[ "Create", "a", "new", "response", "with", "a", "cookie", "set", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L2221-L2258
211,163
cakephp/cakephp
src/Http/Response.php
Response.withExpiredCookie
public function withExpiredCookie($name, $options = []) { if ($name instanceof CookieInterface) { $cookie = $name->withExpired(); } else { deprecationWarning( get_called_class() . '::withExpiredCookie(string $name, array $data) is deprecated. ' . 'Pass an instance of \Cake\Http\Cookie\Cookie instead.' ); $options += [ 'path' => '/', 'domain' => '', 'secure' => false, 'httpOnly' => false ]; $cookie = new Cookie( $name, '', DateTime::createFromFormat('U', 1), $options['path'], $options['domain'], $options['secure'], $options['httpOnly'] ); } $new = clone $this; $new->_cookies = $new->_cookies->add($cookie); return $new; }
php
public function withExpiredCookie($name, $options = []) { if ($name instanceof CookieInterface) { $cookie = $name->withExpired(); } else { deprecationWarning( get_called_class() . '::withExpiredCookie(string $name, array $data) is deprecated. ' . 'Pass an instance of \Cake\Http\Cookie\Cookie instead.' ); $options += [ 'path' => '/', 'domain' => '', 'secure' => false, 'httpOnly' => false ]; $cookie = new Cookie( $name, '', DateTime::createFromFormat('U', 1), $options['path'], $options['domain'], $options['secure'], $options['httpOnly'] ); } $new = clone $this; $new->_cookies = $new->_cookies->add($cookie); return $new; }
[ "public", "function", "withExpiredCookie", "(", "$", "name", ",", "$", "options", "=", "[", "]", ")", "{", "if", "(", "$", "name", "instanceof", "CookieInterface", ")", "{", "$", "cookie", "=", "$", "name", "->", "withExpired", "(", ")", ";", "}", "else", "{", "deprecationWarning", "(", "get_called_class", "(", ")", ".", "'::withExpiredCookie(string $name, array $data) is deprecated. '", ".", "'Pass an instance of \\Cake\\Http\\Cookie\\Cookie instead.'", ")", ";", "$", "options", "+=", "[", "'path'", "=>", "'/'", ",", "'domain'", "=>", "''", ",", "'secure'", "=>", "false", ",", "'httpOnly'", "=>", "false", "]", ";", "$", "cookie", "=", "new", "Cookie", "(", "$", "name", ",", "''", ",", "DateTime", "::", "createFromFormat", "(", "'U'", ",", "1", ")", ",", "$", "options", "[", "'path'", "]", ",", "$", "options", "[", "'domain'", "]", ",", "$", "options", "[", "'secure'", "]", ",", "$", "options", "[", "'httpOnly'", "]", ")", ";", "}", "$", "new", "=", "clone", "$", "this", ";", "$", "new", "->", "_cookies", "=", "$", "new", "->", "_cookies", "->", "add", "(", "$", "cookie", ")", ";", "return", "$", "new", ";", "}" ]
Create a new response with an expired cookie set. ### Options - `path`: Path the cookie applies to - `domain`: Domain the cookie is for. - `secure`: Is the cookie https? - `httpOnly`: Is the cookie available in the client? ### Examples ``` // set scalar value with defaults $response = $response->withExpiredCookie('remember_me'); // customize cookie attributes $response = $response->withExpiredCookie('remember_me', ['path' => '/login']); // add a cookie object $response = $response->withExpiredCookie(new Cookie('remember_me')); ``` @param string|\Cake\Http\Cookie\CookieInterface $name The name of the cookie to expire, or a cookie object @param array $options An array of cookie options. @return static
[ "Create", "a", "new", "response", "with", "an", "expired", "cookie", "set", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L2287-L2319
211,164
cakephp/cakephp
src/Http/Response.php
Response.getCookie
public function getCookie($name) { if (!$this->_cookies->has($name)) { return null; } $cookie = $this->_cookies->get($name); return $this->convertCookieToArray($cookie); }
php
public function getCookie($name) { if (!$this->_cookies->has($name)) { return null; } $cookie = $this->_cookies->get($name); return $this->convertCookieToArray($cookie); }
[ "public", "function", "getCookie", "(", "$", "name", ")", "{", "if", "(", "!", "$", "this", "->", "_cookies", "->", "has", "(", "$", "name", ")", ")", "{", "return", "null", ";", "}", "$", "cookie", "=", "$", "this", "->", "_cookies", "->", "get", "(", "$", "name", ")", ";", "return", "$", "this", "->", "convertCookieToArray", "(", "$", "cookie", ")", ";", "}" ]
Read a single cookie from the response. This method provides read access to pending cookies. It will not read the `Set-Cookie` header if set. @param string $name The cookie name you want to read. @return array|null Either the cookie data or null
[ "Read", "a", "single", "cookie", "from", "the", "response", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L2330-L2339
211,165
cakephp/cakephp
src/Http/Response.php
Response.getCookies
public function getCookies() { $out = []; foreach ($this->_cookies as $cookie) { $out[$cookie->getName()] = $this->convertCookieToArray($cookie); } return $out; }
php
public function getCookies() { $out = []; foreach ($this->_cookies as $cookie) { $out[$cookie->getName()] = $this->convertCookieToArray($cookie); } return $out; }
[ "public", "function", "getCookies", "(", ")", "{", "$", "out", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "_cookies", "as", "$", "cookie", ")", "{", "$", "out", "[", "$", "cookie", "->", "getName", "(", ")", "]", "=", "$", "this", "->", "convertCookieToArray", "(", "$", "cookie", ")", ";", "}", "return", "$", "out", ";", "}" ]
Get all cookies in the response. Returns an associative array of cookie name => cookie data. @return array
[ "Get", "all", "cookies", "in", "the", "response", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L2348-L2356
211,166
cakephp/cakephp
src/Http/Response.php
Response.cors
public function cors(ServerRequest $request, $allowedDomains = [], $allowedMethods = [], $allowedHeaders = []) { $origin = $request->getHeaderLine('Origin'); $ssl = $request->is('ssl'); $builder = new CorsBuilder($this, $origin, $ssl); if (!$origin) { return $builder; } if (empty($allowedDomains) && empty($allowedMethods) && empty($allowedHeaders)) { return $builder; } deprecationWarning( 'The $allowedDomains, $allowedMethods, and $allowedHeaders parameters of Response::cors() ' . 'are deprecated. Instead you should use the builder methods on the return of cors().' ); $updated = $builder->allowOrigin($allowedDomains) ->allowMethods((array)$allowedMethods) ->allowHeaders((array)$allowedHeaders) ->build(); // If $updated is a new instance, mutate this object in-place // to retain existing behavior. if ($updated !== $this) { foreach ($updated->getHeaders() as $name => $values) { if (!$this->hasHeader($name)) { $this->_setHeader($name, $values[0]); } } } return $builder; }
php
public function cors(ServerRequest $request, $allowedDomains = [], $allowedMethods = [], $allowedHeaders = []) { $origin = $request->getHeaderLine('Origin'); $ssl = $request->is('ssl'); $builder = new CorsBuilder($this, $origin, $ssl); if (!$origin) { return $builder; } if (empty($allowedDomains) && empty($allowedMethods) && empty($allowedHeaders)) { return $builder; } deprecationWarning( 'The $allowedDomains, $allowedMethods, and $allowedHeaders parameters of Response::cors() ' . 'are deprecated. Instead you should use the builder methods on the return of cors().' ); $updated = $builder->allowOrigin($allowedDomains) ->allowMethods((array)$allowedMethods) ->allowHeaders((array)$allowedHeaders) ->build(); // If $updated is a new instance, mutate this object in-place // to retain existing behavior. if ($updated !== $this) { foreach ($updated->getHeaders() as $name => $values) { if (!$this->hasHeader($name)) { $this->_setHeader($name, $values[0]); } } } return $builder; }
[ "public", "function", "cors", "(", "ServerRequest", "$", "request", ",", "$", "allowedDomains", "=", "[", "]", ",", "$", "allowedMethods", "=", "[", "]", ",", "$", "allowedHeaders", "=", "[", "]", ")", "{", "$", "origin", "=", "$", "request", "->", "getHeaderLine", "(", "'Origin'", ")", ";", "$", "ssl", "=", "$", "request", "->", "is", "(", "'ssl'", ")", ";", "$", "builder", "=", "new", "CorsBuilder", "(", "$", "this", ",", "$", "origin", ",", "$", "ssl", ")", ";", "if", "(", "!", "$", "origin", ")", "{", "return", "$", "builder", ";", "}", "if", "(", "empty", "(", "$", "allowedDomains", ")", "&&", "empty", "(", "$", "allowedMethods", ")", "&&", "empty", "(", "$", "allowedHeaders", ")", ")", "{", "return", "$", "builder", ";", "}", "deprecationWarning", "(", "'The $allowedDomains, $allowedMethods, and $allowedHeaders parameters of Response::cors() '", ".", "'are deprecated. Instead you should use the builder methods on the return of cors().'", ")", ";", "$", "updated", "=", "$", "builder", "->", "allowOrigin", "(", "$", "allowedDomains", ")", "->", "allowMethods", "(", "(", "array", ")", "$", "allowedMethods", ")", "->", "allowHeaders", "(", "(", "array", ")", "$", "allowedHeaders", ")", "->", "build", "(", ")", ";", "// If $updated is a new instance, mutate this object in-place", "// to retain existing behavior.", "if", "(", "$", "updated", "!==", "$", "this", ")", "{", "foreach", "(", "$", "updated", "->", "getHeaders", "(", ")", "as", "$", "name", "=>", "$", "values", ")", "{", "if", "(", "!", "$", "this", "->", "hasHeader", "(", "$", "name", ")", ")", "{", "$", "this", "->", "_setHeader", "(", "$", "name", ",", "$", "values", "[", "0", "]", ")", ";", "}", "}", "}", "return", "$", "builder", ";", "}" ]
Setup access for origin and methods on cross origin requests This method allow multiple ways to setup the domains, see the examples ### Full URI ``` cors($request, 'https://www.cakephp.org'); ``` ### URI with wildcard ``` cors($request, 'https://*.cakephp.org'); ``` ### Ignoring the requested protocol ``` cors($request, 'www.cakephp.org'); ``` ### Any URI ``` cors($request, '*'); ``` ### Whitelist of URIs ``` cors($request, ['http://www.cakephp.org', '*.google.com', 'https://myproject.github.io']); ``` *Note* The `$allowedDomains`, `$allowedMethods`, `$allowedHeaders` parameters are deprecated. Instead the builder object should be used. @param \Cake\Http\ServerRequest $request Request object @param string|array $allowedDomains List of allowed domains, see method description for more details @param string|array $allowedMethods List of HTTP verbs allowed @param string|array $allowedHeaders List of HTTP headers allowed @return \Cake\Http\CorsBuilder A builder object the provides a fluent interface for defining additional CORS headers.
[ "Setup", "access", "for", "origin", "and", "methods", "on", "cross", "origin", "requests" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L2430-L2462
211,167
cakephp/cakephp
src/Http/Response.php
Response.file
public function file($path, array $options = []) { deprecationWarning( 'Response::file() is deprecated. ' . 'Use withFile() instead.' ); $file = $this->validateFile($path); $options += [ 'name' => null, 'download' => null ]; $extension = strtolower($file->ext()); $download = $options['download']; if ((!$extension || $this->type($extension) === false) && $download === null) { $download = true; } $fileSize = $file->size(); if ($download) { $agent = env('HTTP_USER_AGENT'); if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent)) { $contentType = 'application/octet-stream'; } elseif (preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) { $contentType = 'application/force-download'; } if (!empty($contentType)) { $this->type($contentType); } if ($options['name'] === null) { $name = $file->name; } else { $name = $options['name']; } $this->download($name); $this->header('Content-Transfer-Encoding', 'binary'); } $this->header('Accept-Ranges', 'bytes'); $httpRange = env('HTTP_RANGE'); if (isset($httpRange)) { $this->_fileRange($file, $httpRange); } else { $this->header('Content-Length', $fileSize); } $this->_file = $file; $this->stream = new Stream($file->path, 'rb'); }
php
public function file($path, array $options = []) { deprecationWarning( 'Response::file() is deprecated. ' . 'Use withFile() instead.' ); $file = $this->validateFile($path); $options += [ 'name' => null, 'download' => null ]; $extension = strtolower($file->ext()); $download = $options['download']; if ((!$extension || $this->type($extension) === false) && $download === null) { $download = true; } $fileSize = $file->size(); if ($download) { $agent = env('HTTP_USER_AGENT'); if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent)) { $contentType = 'application/octet-stream'; } elseif (preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) { $contentType = 'application/force-download'; } if (!empty($contentType)) { $this->type($contentType); } if ($options['name'] === null) { $name = $file->name; } else { $name = $options['name']; } $this->download($name); $this->header('Content-Transfer-Encoding', 'binary'); } $this->header('Accept-Ranges', 'bytes'); $httpRange = env('HTTP_RANGE'); if (isset($httpRange)) { $this->_fileRange($file, $httpRange); } else { $this->header('Content-Length', $fileSize); } $this->_file = $file; $this->stream = new Stream($file->path, 'rb'); }
[ "public", "function", "file", "(", "$", "path", ",", "array", "$", "options", "=", "[", "]", ")", "{", "deprecationWarning", "(", "'Response::file() is deprecated. '", ".", "'Use withFile() instead.'", ")", ";", "$", "file", "=", "$", "this", "->", "validateFile", "(", "$", "path", ")", ";", "$", "options", "+=", "[", "'name'", "=>", "null", ",", "'download'", "=>", "null", "]", ";", "$", "extension", "=", "strtolower", "(", "$", "file", "->", "ext", "(", ")", ")", ";", "$", "download", "=", "$", "options", "[", "'download'", "]", ";", "if", "(", "(", "!", "$", "extension", "||", "$", "this", "->", "type", "(", "$", "extension", ")", "===", "false", ")", "&&", "$", "download", "===", "null", ")", "{", "$", "download", "=", "true", ";", "}", "$", "fileSize", "=", "$", "file", "->", "size", "(", ")", ";", "if", "(", "$", "download", ")", "{", "$", "agent", "=", "env", "(", "'HTTP_USER_AGENT'", ")", ";", "if", "(", "preg_match", "(", "'%Opera(/| )([0-9].[0-9]{1,2})%'", ",", "$", "agent", ")", ")", "{", "$", "contentType", "=", "'application/octet-stream'", ";", "}", "elseif", "(", "preg_match", "(", "'/MSIE ([0-9].[0-9]{1,2})/'", ",", "$", "agent", ")", ")", "{", "$", "contentType", "=", "'application/force-download'", ";", "}", "if", "(", "!", "empty", "(", "$", "contentType", ")", ")", "{", "$", "this", "->", "type", "(", "$", "contentType", ")", ";", "}", "if", "(", "$", "options", "[", "'name'", "]", "===", "null", ")", "{", "$", "name", "=", "$", "file", "->", "name", ";", "}", "else", "{", "$", "name", "=", "$", "options", "[", "'name'", "]", ";", "}", "$", "this", "->", "download", "(", "$", "name", ")", ";", "$", "this", "->", "header", "(", "'Content-Transfer-Encoding'", ",", "'binary'", ")", ";", "}", "$", "this", "->", "header", "(", "'Accept-Ranges'", ",", "'bytes'", ")", ";", "$", "httpRange", "=", "env", "(", "'HTTP_RANGE'", ")", ";", "if", "(", "isset", "(", "$", "httpRange", ")", ")", "{", "$", "this", "->", "_fileRange", "(", "$", "file", ",", "$", "httpRange", ")", ";", "}", "else", "{", "$", "this", "->", "header", "(", "'Content-Length'", ",", "$", "fileSize", ")", ";", "}", "$", "this", "->", "_file", "=", "$", "file", ";", "$", "this", "->", "stream", "=", "new", "Stream", "(", "$", "file", "->", "path", ",", "'rb'", ")", ";", "}" ]
Setup for display or download the given file. If $_SERVER['HTTP_RANGE'] is set a slice of the file will be returned instead of the entire file. ### Options keys - name: Alternate download name - download: If `true` sets download header and forces file to be downloaded rather than displayed in browser @param string $path Path to file. If the path is not an absolute path that resolves to a file, `APP` will be prepended to the path (this behavior is deprecated). @param array $options Options See above. @return void @throws \Cake\Http\Exception\NotFoundException @deprecated 3.4.0 Use withFile() instead.
[ "Setup", "for", "display", "or", "download", "the", "given", "file", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L2482-L2533
211,168
cakephp/cakephp
src/Http/Response.php
Response.withFile
public function withFile($path, array $options = []) { $file = $this->validateFile($path); $options += [ 'name' => null, 'download' => null ]; $extension = strtolower($file->ext()); $mapped = $this->getMimeType($extension); if ((!$extension || !$mapped) && $options['download'] === null) { $options['download'] = true; } $new = clone $this; if ($mapped) { $new = $new->withType($extension); } $fileSize = $file->size(); if ($options['download']) { $agent = env('HTTP_USER_AGENT'); if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent)) { $contentType = 'application/octet-stream'; } elseif (preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) { $contentType = 'application/force-download'; } if (isset($contentType)) { $new = $new->withType($contentType); } $name = $options['name'] ?: $file->name; $new = $new->withDownload($name) ->withHeader('Content-Transfer-Encoding', 'binary'); } $new = $new->withHeader('Accept-Ranges', 'bytes'); $httpRange = env('HTTP_RANGE'); if (isset($httpRange)) { $new->_fileRange($file, $httpRange); } else { $new = $new->withHeader('Content-Length', (string)$fileSize); } $new->_file = $file; $new->stream = new Stream($file->path, 'rb'); return $new; }
php
public function withFile($path, array $options = []) { $file = $this->validateFile($path); $options += [ 'name' => null, 'download' => null ]; $extension = strtolower($file->ext()); $mapped = $this->getMimeType($extension); if ((!$extension || !$mapped) && $options['download'] === null) { $options['download'] = true; } $new = clone $this; if ($mapped) { $new = $new->withType($extension); } $fileSize = $file->size(); if ($options['download']) { $agent = env('HTTP_USER_AGENT'); if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent)) { $contentType = 'application/octet-stream'; } elseif (preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) { $contentType = 'application/force-download'; } if (isset($contentType)) { $new = $new->withType($contentType); } $name = $options['name'] ?: $file->name; $new = $new->withDownload($name) ->withHeader('Content-Transfer-Encoding', 'binary'); } $new = $new->withHeader('Accept-Ranges', 'bytes'); $httpRange = env('HTTP_RANGE'); if (isset($httpRange)) { $new->_fileRange($file, $httpRange); } else { $new = $new->withHeader('Content-Length', (string)$fileSize); } $new->_file = $file; $new->stream = new Stream($file->path, 'rb'); return $new; }
[ "public", "function", "withFile", "(", "$", "path", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "file", "=", "$", "this", "->", "validateFile", "(", "$", "path", ")", ";", "$", "options", "+=", "[", "'name'", "=>", "null", ",", "'download'", "=>", "null", "]", ";", "$", "extension", "=", "strtolower", "(", "$", "file", "->", "ext", "(", ")", ")", ";", "$", "mapped", "=", "$", "this", "->", "getMimeType", "(", "$", "extension", ")", ";", "if", "(", "(", "!", "$", "extension", "||", "!", "$", "mapped", ")", "&&", "$", "options", "[", "'download'", "]", "===", "null", ")", "{", "$", "options", "[", "'download'", "]", "=", "true", ";", "}", "$", "new", "=", "clone", "$", "this", ";", "if", "(", "$", "mapped", ")", "{", "$", "new", "=", "$", "new", "->", "withType", "(", "$", "extension", ")", ";", "}", "$", "fileSize", "=", "$", "file", "->", "size", "(", ")", ";", "if", "(", "$", "options", "[", "'download'", "]", ")", "{", "$", "agent", "=", "env", "(", "'HTTP_USER_AGENT'", ")", ";", "if", "(", "preg_match", "(", "'%Opera(/| )([0-9].[0-9]{1,2})%'", ",", "$", "agent", ")", ")", "{", "$", "contentType", "=", "'application/octet-stream'", ";", "}", "elseif", "(", "preg_match", "(", "'/MSIE ([0-9].[0-9]{1,2})/'", ",", "$", "agent", ")", ")", "{", "$", "contentType", "=", "'application/force-download'", ";", "}", "if", "(", "isset", "(", "$", "contentType", ")", ")", "{", "$", "new", "=", "$", "new", "->", "withType", "(", "$", "contentType", ")", ";", "}", "$", "name", "=", "$", "options", "[", "'name'", "]", "?", ":", "$", "file", "->", "name", ";", "$", "new", "=", "$", "new", "->", "withDownload", "(", "$", "name", ")", "->", "withHeader", "(", "'Content-Transfer-Encoding'", ",", "'binary'", ")", ";", "}", "$", "new", "=", "$", "new", "->", "withHeader", "(", "'Accept-Ranges'", ",", "'bytes'", ")", ";", "$", "httpRange", "=", "env", "(", "'HTTP_RANGE'", ")", ";", "if", "(", "isset", "(", "$", "httpRange", ")", ")", "{", "$", "new", "->", "_fileRange", "(", "$", "file", ",", "$", "httpRange", ")", ";", "}", "else", "{", "$", "new", "=", "$", "new", "->", "withHeader", "(", "'Content-Length'", ",", "(", "string", ")", "$", "fileSize", ")", ";", "}", "$", "new", "->", "_file", "=", "$", "file", ";", "$", "new", "->", "stream", "=", "new", "Stream", "(", "$", "file", "->", "path", ",", "'rb'", ")", ";", "return", "$", "new", ";", "}" ]
Create a new instance that is based on a file. This method will augment both the body and a number of related headers. If `$_SERVER['HTTP_RANGE']` is set, a slice of the file will be returned instead of the entire file. ### Options keys - name: Alternate download name - download: If `true` sets download header and forces file to be downloaded rather than displayed inline. @param string $path Path to file. If the path is not an absolute path that resolves to a file, `APP` will be prepended to the path (this behavior is deprecated). @param array $options Options See above. @return static @throws \Cake\Http\Exception\NotFoundException
[ "Create", "a", "new", "instance", "that", "is", "based", "on", "a", "file", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L2555-L2603
211,169
cakephp/cakephp
src/Http/Response.php
Response.validateFile
protected function validateFile($path) { if (strpos($path, '../') !== false || strpos($path, '..\\') !== false) { throw new NotFoundException(__d('cake', 'The requested file contains `..` and will not be read.')); } if (!is_file($path)) { deprecationWarning( 'Automatic prefixing of paths with `APP` by `Response::file()` and `withFile()` is deprecated. ' . 'Use absolute paths instead.' ); $path = APP . $path; } if (!Folder::isAbsolute($path)) { deprecationWarning( 'Serving files via `file()` or `withFile()` using relative paths is deprecated.' . 'Use an absolute path instead.' ); } $file = new File($path); if (!$file->exists() || !$file->readable()) { if (Configure::read('debug')) { throw new NotFoundException(sprintf('The requested file %s was not found or not readable', $path)); } throw new NotFoundException(__d('cake', 'The requested file was not found')); } return $file; }
php
protected function validateFile($path) { if (strpos($path, '../') !== false || strpos($path, '..\\') !== false) { throw new NotFoundException(__d('cake', 'The requested file contains `..` and will not be read.')); } if (!is_file($path)) { deprecationWarning( 'Automatic prefixing of paths with `APP` by `Response::file()` and `withFile()` is deprecated. ' . 'Use absolute paths instead.' ); $path = APP . $path; } if (!Folder::isAbsolute($path)) { deprecationWarning( 'Serving files via `file()` or `withFile()` using relative paths is deprecated.' . 'Use an absolute path instead.' ); } $file = new File($path); if (!$file->exists() || !$file->readable()) { if (Configure::read('debug')) { throw new NotFoundException(sprintf('The requested file %s was not found or not readable', $path)); } throw new NotFoundException(__d('cake', 'The requested file was not found')); } return $file; }
[ "protected", "function", "validateFile", "(", "$", "path", ")", "{", "if", "(", "strpos", "(", "$", "path", ",", "'../'", ")", "!==", "false", "||", "strpos", "(", "$", "path", ",", "'..\\\\'", ")", "!==", "false", ")", "{", "throw", "new", "NotFoundException", "(", "__d", "(", "'cake'", ",", "'The requested file contains `..` and will not be read.'", ")", ")", ";", "}", "if", "(", "!", "is_file", "(", "$", "path", ")", ")", "{", "deprecationWarning", "(", "'Automatic prefixing of paths with `APP` by `Response::file()` and `withFile()` is deprecated. '", ".", "'Use absolute paths instead.'", ")", ";", "$", "path", "=", "APP", ".", "$", "path", ";", "}", "if", "(", "!", "Folder", "::", "isAbsolute", "(", "$", "path", ")", ")", "{", "deprecationWarning", "(", "'Serving files via `file()` or `withFile()` using relative paths is deprecated.'", ".", "'Use an absolute path instead.'", ")", ";", "}", "$", "file", "=", "new", "File", "(", "$", "path", ")", ";", "if", "(", "!", "$", "file", "->", "exists", "(", ")", "||", "!", "$", "file", "->", "readable", "(", ")", ")", "{", "if", "(", "Configure", "::", "read", "(", "'debug'", ")", ")", "{", "throw", "new", "NotFoundException", "(", "sprintf", "(", "'The requested file %s was not found or not readable'", ",", "$", "path", ")", ")", ";", "}", "throw", "new", "NotFoundException", "(", "__d", "(", "'cake'", ",", "'The requested file was not found'", ")", ")", ";", "}", "return", "$", "file", ";", "}" ]
Validate a file path is a valid response body. @param string $path The path to the file. @throws \Cake\Http\Exception\NotFoundException @return \Cake\Filesystem\File
[ "Validate", "a", "file", "path", "is", "a", "valid", "response", "body", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L2627-L2655
211,170
cakephp/cakephp
src/Http/Response.php
Response._fileRange
protected function _fileRange($file, $httpRange) { $fileSize = $file->size(); $lastByte = $fileSize - 1; $start = 0; $end = $lastByte; preg_match('/^bytes\s*=\s*(\d+)?\s*-\s*(\d+)?$/', $httpRange, $matches); if ($matches) { $start = $matches[1]; $end = isset($matches[2]) ? $matches[2] : ''; } if ($start === '') { $start = $fileSize - $end; $end = $lastByte; } if ($end === '') { $end = $lastByte; } if ($start > $end || $end > $lastByte || $start > $lastByte) { $this->_setStatus(416); $this->_setHeader('Content-Range', 'bytes 0-' . $lastByte . '/' . $fileSize); return; } $this->_setHeader('Content-Length', $end - $start + 1); $this->_setHeader('Content-Range', 'bytes ' . $start . '-' . $end . '/' . $fileSize); $this->_setStatus(206); $this->_fileRange = [$start, $end]; }
php
protected function _fileRange($file, $httpRange) { $fileSize = $file->size(); $lastByte = $fileSize - 1; $start = 0; $end = $lastByte; preg_match('/^bytes\s*=\s*(\d+)?\s*-\s*(\d+)?$/', $httpRange, $matches); if ($matches) { $start = $matches[1]; $end = isset($matches[2]) ? $matches[2] : ''; } if ($start === '') { $start = $fileSize - $end; $end = $lastByte; } if ($end === '') { $end = $lastByte; } if ($start > $end || $end > $lastByte || $start > $lastByte) { $this->_setStatus(416); $this->_setHeader('Content-Range', 'bytes 0-' . $lastByte . '/' . $fileSize); return; } $this->_setHeader('Content-Length', $end - $start + 1); $this->_setHeader('Content-Range', 'bytes ' . $start . '-' . $end . '/' . $fileSize); $this->_setStatus(206); $this->_fileRange = [$start, $end]; }
[ "protected", "function", "_fileRange", "(", "$", "file", ",", "$", "httpRange", ")", "{", "$", "fileSize", "=", "$", "file", "->", "size", "(", ")", ";", "$", "lastByte", "=", "$", "fileSize", "-", "1", ";", "$", "start", "=", "0", ";", "$", "end", "=", "$", "lastByte", ";", "preg_match", "(", "'/^bytes\\s*=\\s*(\\d+)?\\s*-\\s*(\\d+)?$/'", ",", "$", "httpRange", ",", "$", "matches", ")", ";", "if", "(", "$", "matches", ")", "{", "$", "start", "=", "$", "matches", "[", "1", "]", ";", "$", "end", "=", "isset", "(", "$", "matches", "[", "2", "]", ")", "?", "$", "matches", "[", "2", "]", ":", "''", ";", "}", "if", "(", "$", "start", "===", "''", ")", "{", "$", "start", "=", "$", "fileSize", "-", "$", "end", ";", "$", "end", "=", "$", "lastByte", ";", "}", "if", "(", "$", "end", "===", "''", ")", "{", "$", "end", "=", "$", "lastByte", ";", "}", "if", "(", "$", "start", ">", "$", "end", "||", "$", "end", ">", "$", "lastByte", "||", "$", "start", ">", "$", "lastByte", ")", "{", "$", "this", "->", "_setStatus", "(", "416", ")", ";", "$", "this", "->", "_setHeader", "(", "'Content-Range'", ",", "'bytes 0-'", ".", "$", "lastByte", ".", "'/'", ".", "$", "fileSize", ")", ";", "return", ";", "}", "$", "this", "->", "_setHeader", "(", "'Content-Length'", ",", "$", "end", "-", "$", "start", "+", "1", ")", ";", "$", "this", "->", "_setHeader", "(", "'Content-Range'", ",", "'bytes '", ".", "$", "start", ".", "'-'", ".", "$", "end", ".", "'/'", ".", "$", "fileSize", ")", ";", "$", "this", "->", "_setStatus", "(", "206", ")", ";", "$", "this", "->", "_fileRange", "=", "[", "$", "start", ",", "$", "end", "]", ";", "}" ]
Apply a file range to a file and set the end offset. If an invalid range is requested a 416 Status code will be used in the response. @param \Cake\Filesystem\File $file The file to set a range on. @param string $httpRange The range to use. @return void @deprecated 3.4.0 Long term this needs to be refactored to follow immutable paradigms. However for now, it is simpler to leave this alone.
[ "Apply", "a", "file", "range", "to", "a", "file", "and", "set", "the", "end", "offset", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L2679-L2711
211,171
cakephp/cakephp
src/Http/Response.php
Response._sendFile
protected function _sendFile($file, $range) { deprecationWarning('Will be removed in 4.0.0'); ob_implicit_flush(true); $file->open('rb'); $end = $start = false; if ($range) { list($start, $end) = $range; } if ($start !== false) { $file->offset($start); } $bufferSize = 8192; if (strpos(ini_get('disable_functions'), 'set_time_limit') === false) { set_time_limit(0); } session_write_close(); while (!feof($file->handle)) { if (!$this->_isActive()) { $file->close(); return false; } $offset = $file->offset(); if ($end && $offset >= $end) { break; } if ($end && $offset + $bufferSize >= $end) { $bufferSize = $end - $offset + 1; } echo fread($file->handle, $bufferSize); } $file->close(); return true; }
php
protected function _sendFile($file, $range) { deprecationWarning('Will be removed in 4.0.0'); ob_implicit_flush(true); $file->open('rb'); $end = $start = false; if ($range) { list($start, $end) = $range; } if ($start !== false) { $file->offset($start); } $bufferSize = 8192; if (strpos(ini_get('disable_functions'), 'set_time_limit') === false) { set_time_limit(0); } session_write_close(); while (!feof($file->handle)) { if (!$this->_isActive()) { $file->close(); return false; } $offset = $file->offset(); if ($end && $offset >= $end) { break; } if ($end && $offset + $bufferSize >= $end) { $bufferSize = $end - $offset + 1; } echo fread($file->handle, $bufferSize); } $file->close(); return true; }
[ "protected", "function", "_sendFile", "(", "$", "file", ",", "$", "range", ")", "{", "deprecationWarning", "(", "'Will be removed in 4.0.0'", ")", ";", "ob_implicit_flush", "(", "true", ")", ";", "$", "file", "->", "open", "(", "'rb'", ")", ";", "$", "end", "=", "$", "start", "=", "false", ";", "if", "(", "$", "range", ")", "{", "list", "(", "$", "start", ",", "$", "end", ")", "=", "$", "range", ";", "}", "if", "(", "$", "start", "!==", "false", ")", "{", "$", "file", "->", "offset", "(", "$", "start", ")", ";", "}", "$", "bufferSize", "=", "8192", ";", "if", "(", "strpos", "(", "ini_get", "(", "'disable_functions'", ")", ",", "'set_time_limit'", ")", "===", "false", ")", "{", "set_time_limit", "(", "0", ")", ";", "}", "session_write_close", "(", ")", ";", "while", "(", "!", "feof", "(", "$", "file", "->", "handle", ")", ")", "{", "if", "(", "!", "$", "this", "->", "_isActive", "(", ")", ")", "{", "$", "file", "->", "close", "(", ")", ";", "return", "false", ";", "}", "$", "offset", "=", "$", "file", "->", "offset", "(", ")", ";", "if", "(", "$", "end", "&&", "$", "offset", ">=", "$", "end", ")", "{", "break", ";", "}", "if", "(", "$", "end", "&&", "$", "offset", "+", "$", "bufferSize", ">=", "$", "end", ")", "{", "$", "bufferSize", "=", "$", "end", "-", "$", "offset", "+", "1", ";", "}", "echo", "fread", "(", "$", "file", "->", "handle", ",", "$", "bufferSize", ")", ";", "}", "$", "file", "->", "close", "(", ")", ";", "return", "true", ";", "}" ]
Reads out a file, and echos the content to the client. @param \Cake\Filesystem\File $file File object @param array $range The range to read out of the file. @return bool True is whole file is echoed successfully or false if client connection is lost in between @deprecated 3.4.0 Will be removed in 4.0.0
[ "Reads", "out", "a", "file", "and", "echos", "the", "content", "to", "the", "client", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Response.php#L2721-L2760
211,172
cakephp/cakephp
src/Datasource/Paginator.php
Paginator._extractFinder
protected function _extractFinder($options) { $type = !empty($options['finder']) ? $options['finder'] : 'all'; unset($options['finder'], $options['maxLimit']); if (is_array($type)) { $options = (array)current($type) + $options; $type = key($type); } return [$type, $options]; }
php
protected function _extractFinder($options) { $type = !empty($options['finder']) ? $options['finder'] : 'all'; unset($options['finder'], $options['maxLimit']); if (is_array($type)) { $options = (array)current($type) + $options; $type = key($type); } return [$type, $options]; }
[ "protected", "function", "_extractFinder", "(", "$", "options", ")", "{", "$", "type", "=", "!", "empty", "(", "$", "options", "[", "'finder'", "]", ")", "?", "$", "options", "[", "'finder'", "]", ":", "'all'", ";", "unset", "(", "$", "options", "[", "'finder'", "]", ",", "$", "options", "[", "'maxLimit'", "]", ")", ";", "if", "(", "is_array", "(", "$", "type", ")", ")", "{", "$", "options", "=", "(", "array", ")", "current", "(", "$", "type", ")", "+", "$", "options", ";", "$", "type", "=", "key", "(", "$", "type", ")", ";", "}", "return", "[", "$", "type", ",", "$", "options", "]", ";", "}" ]
Extracts the finder name and options out of the provided pagination options. @param array $options the pagination options. @return array An array containing in the first position the finder name and in the second the options to be passed to it.
[ "Extracts", "the", "finder", "name", "and", "options", "out", "of", "the", "provided", "pagination", "options", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/Paginator.php#L251-L262
211,173
cakephp/cakephp
src/Datasource/Paginator.php
Paginator._prefix
protected function _prefix(RepositoryInterface $object, $order, $whitelisted = false) { $tableAlias = $object->getAlias(); $tableOrder = []; foreach ($order as $key => $value) { if (is_numeric($key)) { $tableOrder[] = $value; continue; } $field = $key; $alias = $tableAlias; if (strpos($key, '.') !== false) { list($alias, $field) = explode('.', $key); } $correctAlias = ($tableAlias === $alias); if ($correctAlias && $whitelisted) { // Disambiguate fields in schema. As id is quite common. if ($object->hasField($field)) { $field = $alias . '.' . $field; } $tableOrder[$field] = $value; } elseif ($correctAlias && $object->hasField($field)) { $tableOrder[$tableAlias . '.' . $field] = $value; } elseif (!$correctAlias && $whitelisted) { $tableOrder[$alias . '.' . $field] = $value; } } return $tableOrder; }
php
protected function _prefix(RepositoryInterface $object, $order, $whitelisted = false) { $tableAlias = $object->getAlias(); $tableOrder = []; foreach ($order as $key => $value) { if (is_numeric($key)) { $tableOrder[] = $value; continue; } $field = $key; $alias = $tableAlias; if (strpos($key, '.') !== false) { list($alias, $field) = explode('.', $key); } $correctAlias = ($tableAlias === $alias); if ($correctAlias && $whitelisted) { // Disambiguate fields in schema. As id is quite common. if ($object->hasField($field)) { $field = $alias . '.' . $field; } $tableOrder[$field] = $value; } elseif ($correctAlias && $object->hasField($field)) { $tableOrder[$tableAlias . '.' . $field] = $value; } elseif (!$correctAlias && $whitelisted) { $tableOrder[$alias . '.' . $field] = $value; } } return $tableOrder; }
[ "protected", "function", "_prefix", "(", "RepositoryInterface", "$", "object", ",", "$", "order", ",", "$", "whitelisted", "=", "false", ")", "{", "$", "tableAlias", "=", "$", "object", "->", "getAlias", "(", ")", ";", "$", "tableOrder", "=", "[", "]", ";", "foreach", "(", "$", "order", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_numeric", "(", "$", "key", ")", ")", "{", "$", "tableOrder", "[", "]", "=", "$", "value", ";", "continue", ";", "}", "$", "field", "=", "$", "key", ";", "$", "alias", "=", "$", "tableAlias", ";", "if", "(", "strpos", "(", "$", "key", ",", "'.'", ")", "!==", "false", ")", "{", "list", "(", "$", "alias", ",", "$", "field", ")", "=", "explode", "(", "'.'", ",", "$", "key", ")", ";", "}", "$", "correctAlias", "=", "(", "$", "tableAlias", "===", "$", "alias", ")", ";", "if", "(", "$", "correctAlias", "&&", "$", "whitelisted", ")", "{", "// Disambiguate fields in schema. As id is quite common.", "if", "(", "$", "object", "->", "hasField", "(", "$", "field", ")", ")", "{", "$", "field", "=", "$", "alias", ".", "'.'", ".", "$", "field", ";", "}", "$", "tableOrder", "[", "$", "field", "]", "=", "$", "value", ";", "}", "elseif", "(", "$", "correctAlias", "&&", "$", "object", "->", "hasField", "(", "$", "field", ")", ")", "{", "$", "tableOrder", "[", "$", "tableAlias", ".", "'.'", ".", "$", "field", "]", "=", "$", "value", ";", "}", "elseif", "(", "!", "$", "correctAlias", "&&", "$", "whitelisted", ")", "{", "$", "tableOrder", "[", "$", "alias", ".", "'.'", ".", "$", "field", "]", "=", "$", "value", ";", "}", "}", "return", "$", "tableOrder", ";", "}" ]
Prefixes the field with the table alias if possible. @param \Cake\Datasource\RepositoryInterface $object Repository object. @param array $order Order array. @param bool $whitelisted Whether or not the field was whitelisted. @return array Final order array.
[ "Prefixes", "the", "field", "with", "the", "table", "alias", "if", "possible", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/Paginator.php#L446-L477
211,174
cakephp/cakephp
src/Datasource/Paginator.php
Paginator.checkLimit
public function checkLimit(array $options) { $options['limit'] = (int)$options['limit']; if (empty($options['limit']) || $options['limit'] < 1) { $options['limit'] = 1; } $options['limit'] = max(min($options['limit'], $options['maxLimit']), 1); return $options; }
php
public function checkLimit(array $options) { $options['limit'] = (int)$options['limit']; if (empty($options['limit']) || $options['limit'] < 1) { $options['limit'] = 1; } $options['limit'] = max(min($options['limit'], $options['maxLimit']), 1); return $options; }
[ "public", "function", "checkLimit", "(", "array", "$", "options", ")", "{", "$", "options", "[", "'limit'", "]", "=", "(", "int", ")", "$", "options", "[", "'limit'", "]", ";", "if", "(", "empty", "(", "$", "options", "[", "'limit'", "]", ")", "||", "$", "options", "[", "'limit'", "]", "<", "1", ")", "{", "$", "options", "[", "'limit'", "]", "=", "1", ";", "}", "$", "options", "[", "'limit'", "]", "=", "max", "(", "min", "(", "$", "options", "[", "'limit'", "]", ",", "$", "options", "[", "'maxLimit'", "]", ")", ",", "1", ")", ";", "return", "$", "options", ";", "}" ]
Check the limit parameter and ensure it's within the maxLimit bounds. @param array $options An array of options with a limit key to be checked. @return array An array of options for pagination.
[ "Check", "the", "limit", "parameter", "and", "ensure", "it", "s", "within", "the", "maxLimit", "bounds", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/Paginator.php#L485-L494
211,175
cakephp/cakephp
src/Command/HelpCommand.php
HelpCommand.execute
public function execute(Arguments $args, ConsoleIo $io) { if (!$args->getOption('xml')) { $io->out('<info>Current Paths:</info>', 2); $io->out('* app: ' . APP_DIR . DIRECTORY_SEPARATOR); $io->out('* root: ' . ROOT . DIRECTORY_SEPARATOR); $io->out('* core: ' . CORE_PATH); $io->out(''); $io->out('<info>Available Commands:</info>', 2); } $commands = $this->commands->getIterator(); $commands->ksort(); if ($args->getOption('xml')) { $this->asXml($io, $commands); return static::CODE_SUCCESS; } $this->asText($io, $commands); return static::CODE_SUCCESS; }
php
public function execute(Arguments $args, ConsoleIo $io) { if (!$args->getOption('xml')) { $io->out('<info>Current Paths:</info>', 2); $io->out('* app: ' . APP_DIR . DIRECTORY_SEPARATOR); $io->out('* root: ' . ROOT . DIRECTORY_SEPARATOR); $io->out('* core: ' . CORE_PATH); $io->out(''); $io->out('<info>Available Commands:</info>', 2); } $commands = $this->commands->getIterator(); $commands->ksort(); if ($args->getOption('xml')) { $this->asXml($io, $commands); return static::CODE_SUCCESS; } $this->asText($io, $commands); return static::CODE_SUCCESS; }
[ "public", "function", "execute", "(", "Arguments", "$", "args", ",", "ConsoleIo", "$", "io", ")", "{", "if", "(", "!", "$", "args", "->", "getOption", "(", "'xml'", ")", ")", "{", "$", "io", "->", "out", "(", "'<info>Current Paths:</info>'", ",", "2", ")", ";", "$", "io", "->", "out", "(", "'* app: '", ".", "APP_DIR", ".", "DIRECTORY_SEPARATOR", ")", ";", "$", "io", "->", "out", "(", "'* root: '", ".", "ROOT", ".", "DIRECTORY_SEPARATOR", ")", ";", "$", "io", "->", "out", "(", "'* core: '", ".", "CORE_PATH", ")", ";", "$", "io", "->", "out", "(", "''", ")", ";", "$", "io", "->", "out", "(", "'<info>Available Commands:</info>'", ",", "2", ")", ";", "}", "$", "commands", "=", "$", "this", "->", "commands", "->", "getIterator", "(", ")", ";", "$", "commands", "->", "ksort", "(", ")", ";", "if", "(", "$", "args", "->", "getOption", "(", "'xml'", ")", ")", "{", "$", "this", "->", "asXml", "(", "$", "io", ",", "$", "commands", ")", ";", "return", "static", "::", "CODE_SUCCESS", ";", "}", "$", "this", "->", "asText", "(", "$", "io", ",", "$", "commands", ")", ";", "return", "static", "::", "CODE_SUCCESS", ";", "}" ]
Main function Prints out the list of commands. @param \Cake\Console\Arguments $args The command arguments. @param \Cake\Console\ConsoleIo $io The console io @return int
[ "Main", "function", "Prints", "out", "the", "list", "of", "commands", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Command/HelpCommand.php#L53-L76
211,176
cakephp/cakephp
src/Datasource/RulesAwareTrait.php
RulesAwareTrait.checkRules
public function checkRules(EntityInterface $entity, $operation = RulesChecker::CREATE, $options = null) { $rules = $this->rulesChecker(); $options = $options ?: new ArrayObject(); $options = is_array($options) ? new ArrayObject($options) : $options; $hasEvents = ($this instanceof EventDispatcherInterface); if ($hasEvents) { $event = $this->dispatchEvent( 'Model.beforeRules', compact('entity', 'options', 'operation') ); if ($event->isStopped()) { return $event->getResult(); } } $result = $rules->check($entity, $operation, $options->getArrayCopy()); if ($hasEvents) { $event = $this->dispatchEvent( 'Model.afterRules', compact('entity', 'options', 'result', 'operation') ); if ($event->isStopped()) { return $event->getResult(); } } return $result; }
php
public function checkRules(EntityInterface $entity, $operation = RulesChecker::CREATE, $options = null) { $rules = $this->rulesChecker(); $options = $options ?: new ArrayObject(); $options = is_array($options) ? new ArrayObject($options) : $options; $hasEvents = ($this instanceof EventDispatcherInterface); if ($hasEvents) { $event = $this->dispatchEvent( 'Model.beforeRules', compact('entity', 'options', 'operation') ); if ($event->isStopped()) { return $event->getResult(); } } $result = $rules->check($entity, $operation, $options->getArrayCopy()); if ($hasEvents) { $event = $this->dispatchEvent( 'Model.afterRules', compact('entity', 'options', 'result', 'operation') ); if ($event->isStopped()) { return $event->getResult(); } } return $result; }
[ "public", "function", "checkRules", "(", "EntityInterface", "$", "entity", ",", "$", "operation", "=", "RulesChecker", "::", "CREATE", ",", "$", "options", "=", "null", ")", "{", "$", "rules", "=", "$", "this", "->", "rulesChecker", "(", ")", ";", "$", "options", "=", "$", "options", "?", ":", "new", "ArrayObject", "(", ")", ";", "$", "options", "=", "is_array", "(", "$", "options", ")", "?", "new", "ArrayObject", "(", "$", "options", ")", ":", "$", "options", ";", "$", "hasEvents", "=", "(", "$", "this", "instanceof", "EventDispatcherInterface", ")", ";", "if", "(", "$", "hasEvents", ")", "{", "$", "event", "=", "$", "this", "->", "dispatchEvent", "(", "'Model.beforeRules'", ",", "compact", "(", "'entity'", ",", "'options'", ",", "'operation'", ")", ")", ";", "if", "(", "$", "event", "->", "isStopped", "(", ")", ")", "{", "return", "$", "event", "->", "getResult", "(", ")", ";", "}", "}", "$", "result", "=", "$", "rules", "->", "check", "(", "$", "entity", ",", "$", "operation", ",", "$", "options", "->", "getArrayCopy", "(", ")", ")", ";", "if", "(", "$", "hasEvents", ")", "{", "$", "event", "=", "$", "this", "->", "dispatchEvent", "(", "'Model.afterRules'", ",", "compact", "(", "'entity'", ",", "'options'", ",", "'result'", ",", "'operation'", ")", ")", ";", "if", "(", "$", "event", "->", "isStopped", "(", ")", ")", "{", "return", "$", "event", "->", "getResult", "(", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
Returns whether or not the passed entity complies with all the rules stored in the rules checker. @param \Cake\Datasource\EntityInterface $entity The entity to check for validity. @param string $operation The operation being run. Either 'create', 'update' or 'delete'. @param \ArrayObject|array|null $options The options To be passed to the rules. @return bool
[ "Returns", "whether", "or", "not", "the", "passed", "entity", "complies", "with", "all", "the", "rules", "stored", "in", "the", "rules", "checker", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/RulesAwareTrait.php#L49-L80
211,177
cakephp/cakephp
src/Datasource/RulesAwareTrait.php
RulesAwareTrait.rulesChecker
public function rulesChecker() { if ($this->_rulesChecker !== null) { return $this->_rulesChecker; } $class = defined('static::RULES_CLASS') ? static::RULES_CLASS : 'Cake\Datasource\RulesChecker'; $this->_rulesChecker = $this->buildRules(new $class(['repository' => $this])); $this->dispatchEvent('Model.buildRules', ['rules' => $this->_rulesChecker]); return $this->_rulesChecker; }
php
public function rulesChecker() { if ($this->_rulesChecker !== null) { return $this->_rulesChecker; } $class = defined('static::RULES_CLASS') ? static::RULES_CLASS : 'Cake\Datasource\RulesChecker'; $this->_rulesChecker = $this->buildRules(new $class(['repository' => $this])); $this->dispatchEvent('Model.buildRules', ['rules' => $this->_rulesChecker]); return $this->_rulesChecker; }
[ "public", "function", "rulesChecker", "(", ")", "{", "if", "(", "$", "this", "->", "_rulesChecker", "!==", "null", ")", "{", "return", "$", "this", "->", "_rulesChecker", ";", "}", "$", "class", "=", "defined", "(", "'static::RULES_CLASS'", ")", "?", "static", "::", "RULES_CLASS", ":", "'Cake\\Datasource\\RulesChecker'", ";", "$", "this", "->", "_rulesChecker", "=", "$", "this", "->", "buildRules", "(", "new", "$", "class", "(", "[", "'repository'", "=>", "$", "this", "]", ")", ")", ";", "$", "this", "->", "dispatchEvent", "(", "'Model.buildRules'", ",", "[", "'rules'", "=>", "$", "this", "->", "_rulesChecker", "]", ")", ";", "return", "$", "this", "->", "_rulesChecker", ";", "}" ]
Returns the RulesChecker for this instance. A RulesChecker object is used to test an entity for validity on rules that may involve complex logic or data that needs to be fetched from relevant datasources. @see \Cake\Datasource\RulesChecker @return \Cake\Datasource\RulesChecker
[ "Returns", "the", "RulesChecker", "for", "this", "instance", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/RulesAwareTrait.php#L92-L102
211,178
cakephp/cakephp
src/Datasource/ModelAwareTrait.php
ModelAwareTrait.loadModel
public function loadModel($modelClass = null, $modelType = null) { if ($modelClass === null) { $modelClass = $this->modelClass; } if ($modelType === null) { $modelType = $this->getModelType(); if ($modelType === null) { throw new UnexpectedValueException('No model type has been defined'); } } list(, $alias) = pluginSplit($modelClass, true); if (isset($this->{$alias})) { return $this->{$alias}; } if (isset($this->_modelFactories[$modelType])) { $factory = $this->_modelFactories[$modelType]; } if (!isset($factory)) { $factory = FactoryLocator::get($modelType); } $this->{$alias} = $factory($modelClass); if (!$this->{$alias}) { throw new MissingModelException([$modelClass, $modelType]); } return $this->{$alias}; }
php
public function loadModel($modelClass = null, $modelType = null) { if ($modelClass === null) { $modelClass = $this->modelClass; } if ($modelType === null) { $modelType = $this->getModelType(); if ($modelType === null) { throw new UnexpectedValueException('No model type has been defined'); } } list(, $alias) = pluginSplit($modelClass, true); if (isset($this->{$alias})) { return $this->{$alias}; } if (isset($this->_modelFactories[$modelType])) { $factory = $this->_modelFactories[$modelType]; } if (!isset($factory)) { $factory = FactoryLocator::get($modelType); } $this->{$alias} = $factory($modelClass); if (!$this->{$alias}) { throw new MissingModelException([$modelClass, $modelType]); } return $this->{$alias}; }
[ "public", "function", "loadModel", "(", "$", "modelClass", "=", "null", ",", "$", "modelType", "=", "null", ")", "{", "if", "(", "$", "modelClass", "===", "null", ")", "{", "$", "modelClass", "=", "$", "this", "->", "modelClass", ";", "}", "if", "(", "$", "modelType", "===", "null", ")", "{", "$", "modelType", "=", "$", "this", "->", "getModelType", "(", ")", ";", "if", "(", "$", "modelType", "===", "null", ")", "{", "throw", "new", "UnexpectedValueException", "(", "'No model type has been defined'", ")", ";", "}", "}", "list", "(", ",", "$", "alias", ")", "=", "pluginSplit", "(", "$", "modelClass", ",", "true", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "{", "$", "alias", "}", ")", ")", "{", "return", "$", "this", "->", "{", "$", "alias", "}", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "_modelFactories", "[", "$", "modelType", "]", ")", ")", "{", "$", "factory", "=", "$", "this", "->", "_modelFactories", "[", "$", "modelType", "]", ";", "}", "if", "(", "!", "isset", "(", "$", "factory", ")", ")", "{", "$", "factory", "=", "FactoryLocator", "::", "get", "(", "$", "modelType", ")", ";", "}", "$", "this", "->", "{", "$", "alias", "}", "=", "$", "factory", "(", "$", "modelClass", ")", ";", "if", "(", "!", "$", "this", "->", "{", "$", "alias", "}", ")", "{", "throw", "new", "MissingModelException", "(", "[", "$", "modelClass", ",", "$", "modelType", "]", ")", ";", "}", "return", "$", "this", "->", "{", "$", "alias", "}", ";", "}" ]
Loads and constructs repository objects required by this object Typically used to load ORM Table objects as required. Can also be used to load other types of repository objects your application uses. If a repository provider does not return an object a MissingModelException will be thrown. @param string|null $modelClass Name of model class to load. Defaults to $this->modelClass @param string|null $modelType The type of repository to load. Defaults to the modelType() value. @return \Cake\Datasource\RepositoryInterface The model instance created. @throws \Cake\Datasource\Exception\MissingModelException If the model class cannot be found. @throws \InvalidArgumentException When using a type that has not been registered. @throws \UnexpectedValueException If no model type has been defined
[ "Loads", "and", "constructs", "repository", "objects", "required", "by", "this", "object" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/ModelAwareTrait.php#L90-L121
211,179
cakephp/cakephp
src/Datasource/ModelAwareTrait.php
ModelAwareTrait.modelType
public function modelType($modelType = null) { deprecationWarning( get_called_class() . '::modelType() is deprecated. ' . 'Use setModelType()/getModelType() instead.' ); if ($modelType === null) { return $this->_modelType; } $this->_modelType = $modelType; return $this; }
php
public function modelType($modelType = null) { deprecationWarning( get_called_class() . '::modelType() is deprecated. ' . 'Use setModelType()/getModelType() instead.' ); if ($modelType === null) { return $this->_modelType; } $this->_modelType = $modelType; return $this; }
[ "public", "function", "modelType", "(", "$", "modelType", "=", "null", ")", "{", "deprecationWarning", "(", "get_called_class", "(", ")", ".", "'::modelType() is deprecated. '", ".", "'Use setModelType()/getModelType() instead.'", ")", ";", "if", "(", "$", "modelType", "===", "null", ")", "{", "return", "$", "this", "->", "_modelType", ";", "}", "$", "this", "->", "_modelType", "=", "$", "modelType", ";", "return", "$", "this", ";", "}" ]
Set or get the model type to be used by this class @deprecated 3.5.0 Use getModelType()/setModelType() instead. @param string|null $modelType The model type or null to retrieve the current @return string|$this
[ "Set", "or", "get", "the", "model", "type", "to", "be", "used", "by", "this", "class" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Datasource/ModelAwareTrait.php#L167-L180
211,180
cakephp/cakephp
src/ORM/Association/HasOne.php
HasOne._propertyName
protected function _propertyName() { list(, $name) = pluginSplit($this->_name); return Inflector::underscore(Inflector::singularize($name)); }
php
protected function _propertyName() { list(, $name) = pluginSplit($this->_name); return Inflector::underscore(Inflector::singularize($name)); }
[ "protected", "function", "_propertyName", "(", ")", "{", "list", "(", ",", "$", "name", ")", "=", "pluginSplit", "(", "$", "this", "->", "_name", ")", ";", "return", "Inflector", "::", "underscore", "(", "Inflector", "::", "singularize", "(", "$", "name", ")", ")", ";", "}" ]
Returns default property name based on association name. @return string
[ "Returns", "default", "property", "name", "based", "on", "association", "name", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association/HasOne.php#L61-L66
211,181
cakephp/cakephp
src/Validation/Validation.php
Validation.lengthBetween
public static function lengthBetween($check, $min, $max) { if (!is_string($check)) { return false; } $length = mb_strlen($check); return ($length >= $min && $length <= $max); }
php
public static function lengthBetween($check, $min, $max) { if (!is_string($check)) { return false; } $length = mb_strlen($check); return ($length >= $min && $length <= $max); }
[ "public", "static", "function", "lengthBetween", "(", "$", "check", ",", "$", "min", ",", "$", "max", ")", "{", "if", "(", "!", "is_string", "(", "$", "check", ")", ")", "{", "return", "false", ";", "}", "$", "length", "=", "mb_strlen", "(", "$", "check", ")", ";", "return", "(", "$", "length", ">=", "$", "min", "&&", "$", "length", "<=", "$", "max", ")", ";", "}" ]
Checks that a string length is within specified range. Spaces are included in the character count. Returns true if string matches value min, max, or between min and max, @param string $check Value to check for length @param int $min Minimum value in range (inclusive) @param int $max Maximum value in range (inclusive) @return bool Success
[ "Checks", "that", "a", "string", "length", "is", "within", "specified", "range", ".", "Spaces", "are", "included", "in", "the", "character", "count", ".", "Returns", "true", "if", "string", "matches", "value", "min", "max", "or", "between", "min", "and", "max" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L160-L168
211,182
cakephp/cakephp
src/Validation/Validation.php
Validation.numElements
public static function numElements($check, $operator, $expectedCount) { if (!is_array($check) && !$check instanceof \Countable) { return false; } return self::comparison(count($check), $operator, $expectedCount); }
php
public static function numElements($check, $operator, $expectedCount) { if (!is_array($check) && !$check instanceof \Countable) { return false; } return self::comparison(count($check), $operator, $expectedCount); }
[ "public", "static", "function", "numElements", "(", "$", "check", ",", "$", "operator", ",", "$", "expectedCount", ")", "{", "if", "(", "!", "is_array", "(", "$", "check", ")", "&&", "!", "$", "check", "instanceof", "\\", "Countable", ")", "{", "return", "false", ";", "}", "return", "self", "::", "comparison", "(", "count", "(", "$", "check", ")", ",", "$", "operator", ",", "$", "expectedCount", ")", ";", "}" ]
Used to check the count of a given value of type array or Countable. @param array|\Countable $check The value to check the count on. @param string $operator Can be either a word or operand is greater >, is less <, greater or equal >= less or equal <=, is less <, equal to ==, not equal != @param int $expectedCount The expected count value. @return bool Success
[ "Used", "to", "check", "the", "count", "of", "a", "given", "value", "of", "type", "array", "or", "Countable", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L293-L300
211,183
cakephp/cakephp
src/Validation/Validation.php
Validation.comparison
public static function comparison($check1, $operator, $check2) { if ((float)$check1 != $check1) { return false; } $message = 'Operator `%s` is deprecated, use constant `Validation::%s` instead.'; $operator = str_replace([' ', "\t", "\n", "\r", "\0", "\x0B"], '', strtolower($operator)); switch ($operator) { case 'isgreater': /* * @deprecated 3.6.0 Use Validation::COMPARE_GREATER instead. */ deprecationWarning(sprintf($message, $operator, 'COMPARE_GREATER')); // no break case static::COMPARE_GREATER: if ($check1 > $check2) { return true; } break; case 'isless': /* * @deprecated 3.6.0 Use Validation::COMPARE_LESS instead. */ deprecationWarning(sprintf($message, $operator, 'COMPARE_LESS')); // no break case static::COMPARE_LESS: if ($check1 < $check2) { return true; } break; case 'greaterorequal': /* * @deprecated 3.6.0 Use Validation::COMPARE_GREATER_OR_EQUAL instead. */ deprecationWarning(sprintf($message, $operator, 'COMPARE_GREATER_OR_EQUAL')); // no break case static::COMPARE_GREATER_OR_EQUAL: if ($check1 >= $check2) { return true; } break; case 'lessorequal': /* * @deprecated 3.6.0 Use Validation::COMPARE_LESS_OR_EQUAL instead. */ deprecationWarning(sprintf($message, $operator, 'COMPARE_LESS_OR_EQUAL')); // no break case static::COMPARE_LESS_OR_EQUAL: if ($check1 <= $check2) { return true; } break; case 'equalto': /* * @deprecated 3.6.0 Use Validation::COMPARE_EQUAL instead. */ deprecationWarning(sprintf($message, $operator, 'COMPARE_EQUAL')); // no break case static::COMPARE_EQUAL: if ($check1 == $check2) { return true; } break; case 'notequal': /* * @deprecated 3.6.0 Use Validation::COMPARE_NOT_EQUAL instead. */ deprecationWarning(sprintf($message, $operator, 'COMPARE_NOT_EQUAL')); // no break case static::COMPARE_NOT_EQUAL: if ($check1 != $check2) { return true; } break; case static::COMPARE_SAME: if ($check1 === $check2) { return true; } break; case static::COMPARE_NOT_SAME: if ($check1 !== $check2) { return true; } break; default: static::$errors[] = 'You must define the $operator parameter for Validation::comparison()'; } return false; }
php
public static function comparison($check1, $operator, $check2) { if ((float)$check1 != $check1) { return false; } $message = 'Operator `%s` is deprecated, use constant `Validation::%s` instead.'; $operator = str_replace([' ', "\t", "\n", "\r", "\0", "\x0B"], '', strtolower($operator)); switch ($operator) { case 'isgreater': /* * @deprecated 3.6.0 Use Validation::COMPARE_GREATER instead. */ deprecationWarning(sprintf($message, $operator, 'COMPARE_GREATER')); // no break case static::COMPARE_GREATER: if ($check1 > $check2) { return true; } break; case 'isless': /* * @deprecated 3.6.0 Use Validation::COMPARE_LESS instead. */ deprecationWarning(sprintf($message, $operator, 'COMPARE_LESS')); // no break case static::COMPARE_LESS: if ($check1 < $check2) { return true; } break; case 'greaterorequal': /* * @deprecated 3.6.0 Use Validation::COMPARE_GREATER_OR_EQUAL instead. */ deprecationWarning(sprintf($message, $operator, 'COMPARE_GREATER_OR_EQUAL')); // no break case static::COMPARE_GREATER_OR_EQUAL: if ($check1 >= $check2) { return true; } break; case 'lessorequal': /* * @deprecated 3.6.0 Use Validation::COMPARE_LESS_OR_EQUAL instead. */ deprecationWarning(sprintf($message, $operator, 'COMPARE_LESS_OR_EQUAL')); // no break case static::COMPARE_LESS_OR_EQUAL: if ($check1 <= $check2) { return true; } break; case 'equalto': /* * @deprecated 3.6.0 Use Validation::COMPARE_EQUAL instead. */ deprecationWarning(sprintf($message, $operator, 'COMPARE_EQUAL')); // no break case static::COMPARE_EQUAL: if ($check1 == $check2) { return true; } break; case 'notequal': /* * @deprecated 3.6.0 Use Validation::COMPARE_NOT_EQUAL instead. */ deprecationWarning(sprintf($message, $operator, 'COMPARE_NOT_EQUAL')); // no break case static::COMPARE_NOT_EQUAL: if ($check1 != $check2) { return true; } break; case static::COMPARE_SAME: if ($check1 === $check2) { return true; } break; case static::COMPARE_NOT_SAME: if ($check1 !== $check2) { return true; } break; default: static::$errors[] = 'You must define the $operator parameter for Validation::comparison()'; } return false; }
[ "public", "static", "function", "comparison", "(", "$", "check1", ",", "$", "operator", ",", "$", "check2", ")", "{", "if", "(", "(", "float", ")", "$", "check1", "!=", "$", "check1", ")", "{", "return", "false", ";", "}", "$", "message", "=", "'Operator `%s` is deprecated, use constant `Validation::%s` instead.'", ";", "$", "operator", "=", "str_replace", "(", "[", "' '", ",", "\"\\t\"", ",", "\"\\n\"", ",", "\"\\r\"", ",", "\"\\0\"", ",", "\"\\x0B\"", "]", ",", "''", ",", "strtolower", "(", "$", "operator", ")", ")", ";", "switch", "(", "$", "operator", ")", "{", "case", "'isgreater'", ":", "/*\n * @deprecated 3.6.0 Use Validation::COMPARE_GREATER instead.\n */", "deprecationWarning", "(", "sprintf", "(", "$", "message", ",", "$", "operator", ",", "'COMPARE_GREATER'", ")", ")", ";", "// no break", "case", "static", "::", "COMPARE_GREATER", ":", "if", "(", "$", "check1", ">", "$", "check2", ")", "{", "return", "true", ";", "}", "break", ";", "case", "'isless'", ":", "/*\n * @deprecated 3.6.0 Use Validation::COMPARE_LESS instead.\n */", "deprecationWarning", "(", "sprintf", "(", "$", "message", ",", "$", "operator", ",", "'COMPARE_LESS'", ")", ")", ";", "// no break", "case", "static", "::", "COMPARE_LESS", ":", "if", "(", "$", "check1", "<", "$", "check2", ")", "{", "return", "true", ";", "}", "break", ";", "case", "'greaterorequal'", ":", "/*\n * @deprecated 3.6.0 Use Validation::COMPARE_GREATER_OR_EQUAL instead.\n */", "deprecationWarning", "(", "sprintf", "(", "$", "message", ",", "$", "operator", ",", "'COMPARE_GREATER_OR_EQUAL'", ")", ")", ";", "// no break", "case", "static", "::", "COMPARE_GREATER_OR_EQUAL", ":", "if", "(", "$", "check1", ">=", "$", "check2", ")", "{", "return", "true", ";", "}", "break", ";", "case", "'lessorequal'", ":", "/*\n * @deprecated 3.6.0 Use Validation::COMPARE_LESS_OR_EQUAL instead.\n */", "deprecationWarning", "(", "sprintf", "(", "$", "message", ",", "$", "operator", ",", "'COMPARE_LESS_OR_EQUAL'", ")", ")", ";", "// no break", "case", "static", "::", "COMPARE_LESS_OR_EQUAL", ":", "if", "(", "$", "check1", "<=", "$", "check2", ")", "{", "return", "true", ";", "}", "break", ";", "case", "'equalto'", ":", "/*\n * @deprecated 3.6.0 Use Validation::COMPARE_EQUAL instead.\n */", "deprecationWarning", "(", "sprintf", "(", "$", "message", ",", "$", "operator", ",", "'COMPARE_EQUAL'", ")", ")", ";", "// no break", "case", "static", "::", "COMPARE_EQUAL", ":", "if", "(", "$", "check1", "==", "$", "check2", ")", "{", "return", "true", ";", "}", "break", ";", "case", "'notequal'", ":", "/*\n * @deprecated 3.6.0 Use Validation::COMPARE_NOT_EQUAL instead.\n */", "deprecationWarning", "(", "sprintf", "(", "$", "message", ",", "$", "operator", ",", "'COMPARE_NOT_EQUAL'", ")", ")", ";", "// no break", "case", "static", "::", "COMPARE_NOT_EQUAL", ":", "if", "(", "$", "check1", "!=", "$", "check2", ")", "{", "return", "true", ";", "}", "break", ";", "case", "static", "::", "COMPARE_SAME", ":", "if", "(", "$", "check1", "===", "$", "check2", ")", "{", "return", "true", ";", "}", "break", ";", "case", "static", "::", "COMPARE_NOT_SAME", ":", "if", "(", "$", "check1", "!==", "$", "check2", ")", "{", "return", "true", ";", "}", "break", ";", "default", ":", "static", "::", "$", "errors", "[", "]", "=", "'You must define the $operator parameter for Validation::comparison()'", ";", "}", "return", "false", ";", "}" ]
Used to compare 2 numeric values. @param string $check1 The left value to compare. @param string $operator Can be either a word or operand is greater >, is less <, greater or equal >= less or equal <=, is less <, equal to ==, not equal != @param int $check2 The right value to compare. @return bool Success
[ "Used", "to", "compare", "2", "numeric", "values", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L312-L403
211,184
cakephp/cakephp
src/Validation/Validation.php
Validation.containsNonAlphaNumeric
public static function containsNonAlphaNumeric($check, $count = 1) { if (!is_scalar($check)) { return false; } $matches = preg_match_all('/[^a-zA-Z0-9]/', $check); return $matches >= $count; }
php
public static function containsNonAlphaNumeric($check, $count = 1) { if (!is_scalar($check)) { return false; } $matches = preg_match_all('/[^a-zA-Z0-9]/', $check); return $matches >= $count; }
[ "public", "static", "function", "containsNonAlphaNumeric", "(", "$", "check", ",", "$", "count", "=", "1", ")", "{", "if", "(", "!", "is_scalar", "(", "$", "check", ")", ")", "{", "return", "false", ";", "}", "$", "matches", "=", "preg_match_all", "(", "'/[^a-zA-Z0-9]/'", ",", "$", "check", ")", ";", "return", "$", "matches", ">=", "$", "count", ";", "}" ]
Checks if a string contains one or more non-alphanumeric characters. Returns true if string contains at least the specified number of non-alphanumeric characters @param string $check Value to check @param int $count Number of non-alphanumerics to check for @return bool Success
[ "Checks", "if", "a", "string", "contains", "one", "or", "more", "non", "-", "alphanumeric", "characters", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L450-L459
211,185
cakephp/cakephp
src/Validation/Validation.php
Validation.custom
public static function custom($check, $regex = null) { if ($regex === null) { static::$errors[] = 'You must define a regular expression for Validation::custom()'; return false; } return static::_check($check, $regex); }
php
public static function custom($check, $regex = null) { if ($regex === null) { static::$errors[] = 'You must define a regular expression for Validation::custom()'; return false; } return static::_check($check, $regex); }
[ "public", "static", "function", "custom", "(", "$", "check", ",", "$", "regex", "=", "null", ")", "{", "if", "(", "$", "regex", "===", "null", ")", "{", "static", "::", "$", "errors", "[", "]", "=", "'You must define a regular expression for Validation::custom()'", ";", "return", "false", ";", "}", "return", "static", "::", "_check", "(", "$", "check", ",", "$", "regex", ")", ";", "}" ]
Used when a custom regular expression is needed. @param string $check The value to check. @param string|null $regex If $check is passed as a string, $regex must also be set to valid regular expression @return bool Success
[ "Used", "when", "a", "custom", "regular", "expression", "is", "needed", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L468-L477
211,186
cakephp/cakephp
src/Validation/Validation.php
Validation.date
public static function date($check, $format = 'ymd', $regex = null) { if ($check instanceof DateTimeInterface) { return true; } if (is_object($check)) { return false; } if (is_array($check)) { $check = static::_getDateString($check); $format = 'ymd'; } if ($regex !== null) { return static::_check($check, $regex); } $month = '(0[123456789]|10|11|12)'; $separator = '([- /.])'; $fourDigitYear = '(([1][8-9][0-9][0-9])|([2][0-9][0-9][0-9]))'; $twoDigitYear = '([0-9]{2})'; $year = '(?:' . $fourDigitYear . '|' . $twoDigitYear . ')'; $regex['dmy'] = '%^(?:(?:31(\\/|-|\\.|\\x20)(?:0?[13578]|1[02]))\\1|(?:(?:29|30)' . $separator . '(?:0?[1,3-9]|1[0-2])\\2))(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$|^(?:29' . $separator . '0?2\\3(?:(?:(?:1[6-9]|[2-9]\\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\\d|2[0-8])' . $separator . '(?:(?:0?[1-9])|(?:1[0-2]))\\4(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$%'; $regex['mdy'] = '%^(?:(?:(?:0?[13578]|1[02])(\\/|-|\\.|\\x20)31)\\1|(?:(?:0?[13-9]|1[0-2])' . $separator . '(?:29|30)\\2))(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$|^(?:0?2' . $separator . '29\\3(?:(?:(?:1[6-9]|[2-9]\\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0?[1-9])|(?:1[0-2]))' . $separator . '(?:0?[1-9]|1\\d|2[0-8])\\4(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$%'; $regex['ymd'] = '%^(?:(?:(?:(?:(?:1[6-9]|[2-9]\\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))' . $separator . '(?:0?2\\1(?:29)))|(?:(?:(?:1[6-9]|[2-9]\\d)?\\d{2})' . $separator . '(?:(?:(?:0?[13578]|1[02])\\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\\2(?:0?[1-9]|1\\d|2[0-8]))))$%'; $regex['dMy'] = '/^((31(?!\\ (Feb(ruary)?|Apr(il)?|June?|(Sep(?=\\b|t)t?|Nov)(ember)?)))|((30|29)(?!\\ Feb(ruary)?))|(29(?=\\ Feb(ruary)?\\ (((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))|(0?[1-9])|1\\d|2[0-8])\\ (Jan(uary)?|Feb(ruary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep(?=\\b|t)t?|Nov|Dec)(ember)?)\\ ((1[6-9]|[2-9]\\d)\\d{2})$/'; $regex['Mdy'] = '/^(?:(((Jan(uary)?|Ma(r(ch)?|y)|Jul(y)?|Aug(ust)?|Oct(ober)?|Dec(ember)?)\\ 31)|((Jan(uary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep)(tember)?|(Nov|Dec)(ember)?)\\ (0?[1-9]|([12]\\d)|30))|(Feb(ruary)?\\ (0?[1-9]|1\\d|2[0-8]|(29(?=,?\\ ((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))))\\,?\\ ((1[6-9]|[2-9]\\d)\\d{2}))$/'; $regex['My'] = '%^(Jan(uary)?|Feb(ruary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep(?=\\b|t)t?|Nov|Dec)(ember)?)' . $separator . '((1[6-9]|[2-9]\\d)\\d{2})$%'; $regex['my'] = '%^(' . $month . $separator . $year . ')$%'; $regex['ym'] = '%^(' . $year . $separator . $month . ')$%'; $regex['y'] = '%^(' . $fourDigitYear . ')$%'; $format = is_array($format) ? array_values($format) : [$format]; foreach ($format as $key) { if (static::_check($check, $regex[$key]) === true) { return true; } } return false; }
php
public static function date($check, $format = 'ymd', $regex = null) { if ($check instanceof DateTimeInterface) { return true; } if (is_object($check)) { return false; } if (is_array($check)) { $check = static::_getDateString($check); $format = 'ymd'; } if ($regex !== null) { return static::_check($check, $regex); } $month = '(0[123456789]|10|11|12)'; $separator = '([- /.])'; $fourDigitYear = '(([1][8-9][0-9][0-9])|([2][0-9][0-9][0-9]))'; $twoDigitYear = '([0-9]{2})'; $year = '(?:' . $fourDigitYear . '|' . $twoDigitYear . ')'; $regex['dmy'] = '%^(?:(?:31(\\/|-|\\.|\\x20)(?:0?[13578]|1[02]))\\1|(?:(?:29|30)' . $separator . '(?:0?[1,3-9]|1[0-2])\\2))(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$|^(?:29' . $separator . '0?2\\3(?:(?:(?:1[6-9]|[2-9]\\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\\d|2[0-8])' . $separator . '(?:(?:0?[1-9])|(?:1[0-2]))\\4(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$%'; $regex['mdy'] = '%^(?:(?:(?:0?[13578]|1[02])(\\/|-|\\.|\\x20)31)\\1|(?:(?:0?[13-9]|1[0-2])' . $separator . '(?:29|30)\\2))(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$|^(?:0?2' . $separator . '29\\3(?:(?:(?:1[6-9]|[2-9]\\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0?[1-9])|(?:1[0-2]))' . $separator . '(?:0?[1-9]|1\\d|2[0-8])\\4(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$%'; $regex['ymd'] = '%^(?:(?:(?:(?:(?:1[6-9]|[2-9]\\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))' . $separator . '(?:0?2\\1(?:29)))|(?:(?:(?:1[6-9]|[2-9]\\d)?\\d{2})' . $separator . '(?:(?:(?:0?[13578]|1[02])\\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\\2(?:0?[1-9]|1\\d|2[0-8]))))$%'; $regex['dMy'] = '/^((31(?!\\ (Feb(ruary)?|Apr(il)?|June?|(Sep(?=\\b|t)t?|Nov)(ember)?)))|((30|29)(?!\\ Feb(ruary)?))|(29(?=\\ Feb(ruary)?\\ (((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))|(0?[1-9])|1\\d|2[0-8])\\ (Jan(uary)?|Feb(ruary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep(?=\\b|t)t?|Nov|Dec)(ember)?)\\ ((1[6-9]|[2-9]\\d)\\d{2})$/'; $regex['Mdy'] = '/^(?:(((Jan(uary)?|Ma(r(ch)?|y)|Jul(y)?|Aug(ust)?|Oct(ober)?|Dec(ember)?)\\ 31)|((Jan(uary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep)(tember)?|(Nov|Dec)(ember)?)\\ (0?[1-9]|([12]\\d)|30))|(Feb(ruary)?\\ (0?[1-9]|1\\d|2[0-8]|(29(?=,?\\ ((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))))\\,?\\ ((1[6-9]|[2-9]\\d)\\d{2}))$/'; $regex['My'] = '%^(Jan(uary)?|Feb(ruary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep(?=\\b|t)t?|Nov|Dec)(ember)?)' . $separator . '((1[6-9]|[2-9]\\d)\\d{2})$%'; $regex['my'] = '%^(' . $month . $separator . $year . ')$%'; $regex['ym'] = '%^(' . $year . $separator . $month . ')$%'; $regex['y'] = '%^(' . $fourDigitYear . ')$%'; $format = is_array($format) ? array_values($format) : [$format]; foreach ($format as $key) { if (static::_check($check, $regex[$key]) === true) { return true; } } return false; }
[ "public", "static", "function", "date", "(", "$", "check", ",", "$", "format", "=", "'ymd'", ",", "$", "regex", "=", "null", ")", "{", "if", "(", "$", "check", "instanceof", "DateTimeInterface", ")", "{", "return", "true", ";", "}", "if", "(", "is_object", "(", "$", "check", ")", ")", "{", "return", "false", ";", "}", "if", "(", "is_array", "(", "$", "check", ")", ")", "{", "$", "check", "=", "static", "::", "_getDateString", "(", "$", "check", ")", ";", "$", "format", "=", "'ymd'", ";", "}", "if", "(", "$", "regex", "!==", "null", ")", "{", "return", "static", "::", "_check", "(", "$", "check", ",", "$", "regex", ")", ";", "}", "$", "month", "=", "'(0[123456789]|10|11|12)'", ";", "$", "separator", "=", "'([- /.])'", ";", "$", "fourDigitYear", "=", "'(([1][8-9][0-9][0-9])|([2][0-9][0-9][0-9]))'", ";", "$", "twoDigitYear", "=", "'([0-9]{2})'", ";", "$", "year", "=", "'(?:'", ".", "$", "fourDigitYear", ".", "'|'", ".", "$", "twoDigitYear", ".", "')'", ";", "$", "regex", "[", "'dmy'", "]", "=", "'%^(?:(?:31(\\\\/|-|\\\\.|\\\\x20)(?:0?[13578]|1[02]))\\\\1|(?:(?:29|30)'", ".", "$", "separator", ".", "'(?:0?[1,3-9]|1[0-2])\\\\2))(?:(?:1[6-9]|[2-9]\\\\d)?\\\\d{2})$|^(?:29'", ".", "$", "separator", ".", "'0?2\\\\3(?:(?:(?:1[6-9]|[2-9]\\\\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\\\\d|2[0-8])'", ".", "$", "separator", ".", "'(?:(?:0?[1-9])|(?:1[0-2]))\\\\4(?:(?:1[6-9]|[2-9]\\\\d)?\\\\d{2})$%'", ";", "$", "regex", "[", "'mdy'", "]", "=", "'%^(?:(?:(?:0?[13578]|1[02])(\\\\/|-|\\\\.|\\\\x20)31)\\\\1|(?:(?:0?[13-9]|1[0-2])'", ".", "$", "separator", ".", "'(?:29|30)\\\\2))(?:(?:1[6-9]|[2-9]\\\\d)?\\\\d{2})$|^(?:0?2'", ".", "$", "separator", ".", "'29\\\\3(?:(?:(?:1[6-9]|[2-9]\\\\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0?[1-9])|(?:1[0-2]))'", ".", "$", "separator", ".", "'(?:0?[1-9]|1\\\\d|2[0-8])\\\\4(?:(?:1[6-9]|[2-9]\\\\d)?\\\\d{2})$%'", ";", "$", "regex", "[", "'ymd'", "]", "=", "'%^(?:(?:(?:(?:(?:1[6-9]|[2-9]\\\\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))'", ".", "$", "separator", ".", "'(?:0?2\\\\1(?:29)))|(?:(?:(?:1[6-9]|[2-9]\\\\d)?\\\\d{2})'", ".", "$", "separator", ".", "'(?:(?:(?:0?[13578]|1[02])\\\\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\\\\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\\\\2(?:0?[1-9]|1\\\\d|2[0-8]))))$%'", ";", "$", "regex", "[", "'dMy'", "]", "=", "'/^((31(?!\\\\ (Feb(ruary)?|Apr(il)?|June?|(Sep(?=\\\\b|t)t?|Nov)(ember)?)))|((30|29)(?!\\\\ Feb(ruary)?))|(29(?=\\\\ Feb(ruary)?\\\\ (((1[6-9]|[2-9]\\\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))|(0?[1-9])|1\\\\d|2[0-8])\\\\ (Jan(uary)?|Feb(ruary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep(?=\\\\b|t)t?|Nov|Dec)(ember)?)\\\\ ((1[6-9]|[2-9]\\\\d)\\\\d{2})$/'", ";", "$", "regex", "[", "'Mdy'", "]", "=", "'/^(?:(((Jan(uary)?|Ma(r(ch)?|y)|Jul(y)?|Aug(ust)?|Oct(ober)?|Dec(ember)?)\\\\ 31)|((Jan(uary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep)(tember)?|(Nov|Dec)(ember)?)\\\\ (0?[1-9]|([12]\\\\d)|30))|(Feb(ruary)?\\\\ (0?[1-9]|1\\\\d|2[0-8]|(29(?=,?\\\\ ((1[6-9]|[2-9]\\\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))))\\\\,?\\\\ ((1[6-9]|[2-9]\\\\d)\\\\d{2}))$/'", ";", "$", "regex", "[", "'My'", "]", "=", "'%^(Jan(uary)?|Feb(ruary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep(?=\\\\b|t)t?|Nov|Dec)(ember)?)'", ".", "$", "separator", ".", "'((1[6-9]|[2-9]\\\\d)\\\\d{2})$%'", ";", "$", "regex", "[", "'my'", "]", "=", "'%^('", ".", "$", "month", ".", "$", "separator", ".", "$", "year", ".", "')$%'", ";", "$", "regex", "[", "'ym'", "]", "=", "'%^('", ".", "$", "year", ".", "$", "separator", ".", "$", "month", ".", "')$%'", ";", "$", "regex", "[", "'y'", "]", "=", "'%^('", ".", "$", "fourDigitYear", ".", "')$%'", ";", "$", "format", "=", "is_array", "(", "$", "format", ")", "?", "array_values", "(", "$", "format", ")", ":", "[", "$", "format", "]", ";", "foreach", "(", "$", "format", "as", "$", "key", ")", "{", "if", "(", "static", "::", "_check", "(", "$", "check", ",", "$", "regex", "[", "$", "key", "]", ")", "===", "true", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Date validation, determines if the string passed is a valid date. keys that expect full month, day and year will validate leap years. Years are valid from 1800 to 2999. ### Formats: - `dmy` 27-12-2006 or 27-12-06 separators can be a space, period, dash, forward slash - `mdy` 12-27-2006 or 12-27-06 separators can be a space, period, dash, forward slash - `ymd` 2006-12-27 or 06-12-27 separators can be a space, period, dash, forward slash - `dMy` 27 December 2006 or 27 Dec 2006 - `Mdy` December 27, 2006 or Dec 27, 2006 comma is optional - `My` December 2006 or Dec 2006 - `my` 12/2006 or 12/06 separators can be a space, period, dash, forward slash - `ym` 2006/12 or 06/12 separators can be a space, period, dash, forward slash - `y` 2006 just the year without any separators @param string|\DateTimeInterface $check a valid date string/object @param string|array $format Use a string or an array of the keys above. Arrays should be passed as ['dmy', 'mdy', etc] @param string|null $regex If a custom regular expression is used this is the only validation that will occur. @return bool Success
[ "Date", "validation", "determines", "if", "the", "string", "passed", "is", "a", "valid", "date", ".", "keys", "that", "expect", "full", "month", "day", "and", "year", "will", "validate", "leap", "years", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L503-L557
211,187
cakephp/cakephp
src/Validation/Validation.php
Validation.datetime
public static function datetime($check, $dateFormat = 'ymd', $regex = null) { if ($check instanceof DateTimeInterface) { return true; } if (is_object($check)) { return false; } $valid = false; if (is_array($check)) { $check = static::_getDateString($check); $dateFormat = 'ymd'; } $parts = explode(' ', $check); if (!empty($parts) && count($parts) > 1) { $date = rtrim(array_shift($parts), ','); $time = implode(' ', $parts); $valid = static::date($date, $dateFormat, $regex) && static::time($time); } return $valid; }
php
public static function datetime($check, $dateFormat = 'ymd', $regex = null) { if ($check instanceof DateTimeInterface) { return true; } if (is_object($check)) { return false; } $valid = false; if (is_array($check)) { $check = static::_getDateString($check); $dateFormat = 'ymd'; } $parts = explode(' ', $check); if (!empty($parts) && count($parts) > 1) { $date = rtrim(array_shift($parts), ','); $time = implode(' ', $parts); $valid = static::date($date, $dateFormat, $regex) && static::time($time); } return $valid; }
[ "public", "static", "function", "datetime", "(", "$", "check", ",", "$", "dateFormat", "=", "'ymd'", ",", "$", "regex", "=", "null", ")", "{", "if", "(", "$", "check", "instanceof", "DateTimeInterface", ")", "{", "return", "true", ";", "}", "if", "(", "is_object", "(", "$", "check", ")", ")", "{", "return", "false", ";", "}", "$", "valid", "=", "false", ";", "if", "(", "is_array", "(", "$", "check", ")", ")", "{", "$", "check", "=", "static", "::", "_getDateString", "(", "$", "check", ")", ";", "$", "dateFormat", "=", "'ymd'", ";", "}", "$", "parts", "=", "explode", "(", "' '", ",", "$", "check", ")", ";", "if", "(", "!", "empty", "(", "$", "parts", ")", "&&", "count", "(", "$", "parts", ")", ">", "1", ")", "{", "$", "date", "=", "rtrim", "(", "array_shift", "(", "$", "parts", ")", ",", "','", ")", ";", "$", "time", "=", "implode", "(", "' '", ",", "$", "parts", ")", ";", "$", "valid", "=", "static", "::", "date", "(", "$", "date", ",", "$", "dateFormat", ",", "$", "regex", ")", "&&", "static", "::", "time", "(", "$", "time", ")", ";", "}", "return", "$", "valid", ";", "}" ]
Validates a datetime value All values matching the "date" core validation rule, and the "time" one will be valid @param string|\DateTimeInterface $check Value to check @param string|array $dateFormat Format of the date part. See Validation::date() for more information. @param string|null $regex Regex for the date part. If a custom regular expression is used this is the only validation that will occur. @return bool True if the value is valid, false otherwise @see \Cake\Validation\Validation::date() @see \Cake\Validation\Validation::time()
[ "Validates", "a", "datetime", "value" ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L571-L592
211,188
cakephp/cakephp
src/Validation/Validation.php
Validation.boolean
public static function boolean($check, array $booleanValues = []) { if (!$booleanValues) { $booleanValues = [true, false, 0, 1, '0', '1']; } return in_array($check, $booleanValues, true); }
php
public static function boolean($check, array $booleanValues = []) { if (!$booleanValues) { $booleanValues = [true, false, 0, 1, '0', '1']; } return in_array($check, $booleanValues, true); }
[ "public", "static", "function", "boolean", "(", "$", "check", ",", "array", "$", "booleanValues", "=", "[", "]", ")", "{", "if", "(", "!", "$", "booleanValues", ")", "{", "$", "booleanValues", "=", "[", "true", ",", "false", ",", "0", ",", "1", ",", "'0'", ",", "'1'", "]", ";", "}", "return", "in_array", "(", "$", "check", ",", "$", "booleanValues", ",", "true", ")", ";", "}" ]
Validates if passed value is boolean-like. The list of what is considered to be boolean values, may be set via $booleanValues. @param bool|int|string $check Value to check. @param array $booleanValues List of valid boolean values, defaults to `[true, false, 0, 1, '0', '1']`. @return bool Success.
[ "Validates", "if", "passed", "value", "is", "boolean", "-", "like", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L655-L662
211,189
cakephp/cakephp
src/Validation/Validation.php
Validation.truthy
public static function truthy($check, array $truthyValues = []) { if (!$truthyValues) { $truthyValues = [true, 1, '1']; } return in_array($check, $truthyValues, true); }
php
public static function truthy($check, array $truthyValues = []) { if (!$truthyValues) { $truthyValues = [true, 1, '1']; } return in_array($check, $truthyValues, true); }
[ "public", "static", "function", "truthy", "(", "$", "check", ",", "array", "$", "truthyValues", "=", "[", "]", ")", "{", "if", "(", "!", "$", "truthyValues", ")", "{", "$", "truthyValues", "=", "[", "true", ",", "1", ",", "'1'", "]", ";", "}", "return", "in_array", "(", "$", "check", ",", "$", "truthyValues", ",", "true", ")", ";", "}" ]
Validates if given value is truthy. The list of what is considered to be truthy values, may be set via $truthyValues. @param bool|int|string $check Value to check. @param array $truthyValues List of valid truthy values, defaults to `[true, 1, '1']`. @return bool Success.
[ "Validates", "if", "given", "value", "is", "truthy", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L673-L680
211,190
cakephp/cakephp
src/Validation/Validation.php
Validation.falsey
public static function falsey($check, array $falseyValues = []) { if (!$falseyValues) { $falseyValues = [false, 0, '0']; } return in_array($check, $falseyValues, true); }
php
public static function falsey($check, array $falseyValues = []) { if (!$falseyValues) { $falseyValues = [false, 0, '0']; } return in_array($check, $falseyValues, true); }
[ "public", "static", "function", "falsey", "(", "$", "check", ",", "array", "$", "falseyValues", "=", "[", "]", ")", "{", "if", "(", "!", "$", "falseyValues", ")", "{", "$", "falseyValues", "=", "[", "false", ",", "0", ",", "'0'", "]", ";", "}", "return", "in_array", "(", "$", "check", ",", "$", "falseyValues", ",", "true", ")", ";", "}" ]
Validates if given value is falsey. The list of what is considered to be falsey values, may be set via $falseyValues. @param bool|int|string $check Value to check. @param array $falseyValues List of valid falsey values, defaults to `[false, 0, '0']`. @return bool Success.
[ "Validates", "if", "given", "value", "is", "falsey", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L691-L698
211,191
cakephp/cakephp
src/Validation/Validation.php
Validation.decimal
public static function decimal($check, $places = null, $regex = null) { if ($regex === null) { $lnum = '[0-9]+'; $dnum = "[0-9]*[\.]{$lnum}"; $sign = '[+-]?'; $exp = "(?:[eE]{$sign}{$lnum})?"; if ($places === null) { $regex = "/^{$sign}(?:{$lnum}|{$dnum}){$exp}$/"; } elseif ($places === true) { if (is_float($check) && floor($check) === $check) { $check = sprintf('%.1f', $check); } $regex = "/^{$sign}{$dnum}{$exp}$/"; } elseif (is_numeric($places)) { $places = '[0-9]{' . $places . '}'; $dnum = "(?:[0-9]*[\.]{$places}|{$lnum}[\.]{$places})"; $regex = "/^{$sign}{$dnum}{$exp}$/"; } } // account for localized floats. $locale = ini_get('intl.default_locale') ?: static::DEFAULT_LOCALE; $formatter = new NumberFormatter($locale, NumberFormatter::DECIMAL); $decimalPoint = $formatter->getSymbol(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL); $groupingSep = $formatter->getSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL); $check = str_replace([$groupingSep, $decimalPoint], ['', '.'], $check); return static::_check($check, $regex); }
php
public static function decimal($check, $places = null, $regex = null) { if ($regex === null) { $lnum = '[0-9]+'; $dnum = "[0-9]*[\.]{$lnum}"; $sign = '[+-]?'; $exp = "(?:[eE]{$sign}{$lnum})?"; if ($places === null) { $regex = "/^{$sign}(?:{$lnum}|{$dnum}){$exp}$/"; } elseif ($places === true) { if (is_float($check) && floor($check) === $check) { $check = sprintf('%.1f', $check); } $regex = "/^{$sign}{$dnum}{$exp}$/"; } elseif (is_numeric($places)) { $places = '[0-9]{' . $places . '}'; $dnum = "(?:[0-9]*[\.]{$places}|{$lnum}[\.]{$places})"; $regex = "/^{$sign}{$dnum}{$exp}$/"; } } // account for localized floats. $locale = ini_get('intl.default_locale') ?: static::DEFAULT_LOCALE; $formatter = new NumberFormatter($locale, NumberFormatter::DECIMAL); $decimalPoint = $formatter->getSymbol(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL); $groupingSep = $formatter->getSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL); $check = str_replace([$groupingSep, $decimalPoint], ['', '.'], $check); return static::_check($check, $regex); }
[ "public", "static", "function", "decimal", "(", "$", "check", ",", "$", "places", "=", "null", ",", "$", "regex", "=", "null", ")", "{", "if", "(", "$", "regex", "===", "null", ")", "{", "$", "lnum", "=", "'[0-9]+'", ";", "$", "dnum", "=", "\"[0-9]*[\\.]{$lnum}\"", ";", "$", "sign", "=", "'[+-]?'", ";", "$", "exp", "=", "\"(?:[eE]{$sign}{$lnum})?\"", ";", "if", "(", "$", "places", "===", "null", ")", "{", "$", "regex", "=", "\"/^{$sign}(?:{$lnum}|{$dnum}){$exp}$/\"", ";", "}", "elseif", "(", "$", "places", "===", "true", ")", "{", "if", "(", "is_float", "(", "$", "check", ")", "&&", "floor", "(", "$", "check", ")", "===", "$", "check", ")", "{", "$", "check", "=", "sprintf", "(", "'%.1f'", ",", "$", "check", ")", ";", "}", "$", "regex", "=", "\"/^{$sign}{$dnum}{$exp}$/\"", ";", "}", "elseif", "(", "is_numeric", "(", "$", "places", ")", ")", "{", "$", "places", "=", "'[0-9]{'", ".", "$", "places", ".", "'}'", ";", "$", "dnum", "=", "\"(?:[0-9]*[\\.]{$places}|{$lnum}[\\.]{$places})\"", ";", "$", "regex", "=", "\"/^{$sign}{$dnum}{$exp}$/\"", ";", "}", "}", "// account for localized floats.", "$", "locale", "=", "ini_get", "(", "'intl.default_locale'", ")", "?", ":", "static", "::", "DEFAULT_LOCALE", ";", "$", "formatter", "=", "new", "NumberFormatter", "(", "$", "locale", ",", "NumberFormatter", "::", "DECIMAL", ")", ";", "$", "decimalPoint", "=", "$", "formatter", "->", "getSymbol", "(", "NumberFormatter", "::", "DECIMAL_SEPARATOR_SYMBOL", ")", ";", "$", "groupingSep", "=", "$", "formatter", "->", "getSymbol", "(", "NumberFormatter", "::", "GROUPING_SEPARATOR_SYMBOL", ")", ";", "$", "check", "=", "str_replace", "(", "[", "$", "groupingSep", ",", "$", "decimalPoint", "]", ",", "[", "''", ",", "'.'", "]", ",", "$", "check", ")", ";", "return", "static", "::", "_check", "(", "$", "check", ",", "$", "regex", ")", ";", "}" ]
Checks that a value is a valid decimal. Both the sign and exponent are optional. Valid Places: - null => Any number of decimal places, including none. The '.' is not required. - true => Any number of decimal places greater than 0, or a float|double. The '.' is required. - 1..N => Exactly that many number of decimal places. The '.' is required. @param float $check The value the test for decimal. @param int|bool|null $places Decimal places. @param string|null $regex If a custom regular expression is used, this is the only validation that will occur. @return bool Success
[ "Checks", "that", "a", "value", "is", "a", "valid", "decimal", ".", "Both", "the", "sign", "and", "exponent", "are", "optional", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L714-L745
211,192
cakephp/cakephp
src/Validation/Validation.php
Validation.extension
public static function extension($check, $extensions = ['gif', 'jpeg', 'png', 'jpg']) { if ($check instanceof UploadedFileInterface) { return static::extension($check->getClientFilename(), $extensions); } if (is_array($check)) { $check = isset($check['name']) ? $check['name'] : array_shift($check); return static::extension($check, $extensions); } $extension = strtolower(pathinfo($check, PATHINFO_EXTENSION)); foreach ($extensions as $value) { if ($extension === strtolower($value)) { return true; } } return false; }
php
public static function extension($check, $extensions = ['gif', 'jpeg', 'png', 'jpg']) { if ($check instanceof UploadedFileInterface) { return static::extension($check->getClientFilename(), $extensions); } if (is_array($check)) { $check = isset($check['name']) ? $check['name'] : array_shift($check); return static::extension($check, $extensions); } $extension = strtolower(pathinfo($check, PATHINFO_EXTENSION)); foreach ($extensions as $value) { if ($extension === strtolower($value)) { return true; } } return false; }
[ "public", "static", "function", "extension", "(", "$", "check", ",", "$", "extensions", "=", "[", "'gif'", ",", "'jpeg'", ",", "'png'", ",", "'jpg'", "]", ")", "{", "if", "(", "$", "check", "instanceof", "UploadedFileInterface", ")", "{", "return", "static", "::", "extension", "(", "$", "check", "->", "getClientFilename", "(", ")", ",", "$", "extensions", ")", ";", "}", "if", "(", "is_array", "(", "$", "check", ")", ")", "{", "$", "check", "=", "isset", "(", "$", "check", "[", "'name'", "]", ")", "?", "$", "check", "[", "'name'", "]", ":", "array_shift", "(", "$", "check", ")", ";", "return", "static", "::", "extension", "(", "$", "check", ",", "$", "extensions", ")", ";", "}", "$", "extension", "=", "strtolower", "(", "pathinfo", "(", "$", "check", ",", "PATHINFO_EXTENSION", ")", ")", ";", "foreach", "(", "$", "extensions", "as", "$", "value", ")", "{", "if", "(", "$", "extension", "===", "strtolower", "(", "$", "value", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Checks that value has a valid file extension. @param string|array|\Psr\Http\Message\UploadedFileInterface $check Value to check @param array $extensions file extensions to allow. By default extensions are 'gif', 'jpeg', 'png', 'jpg' @return bool Success
[ "Checks", "that", "value", "has", "a", "valid", "file", "extension", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L805-L823
211,193
cakephp/cakephp
src/Validation/Validation.php
Validation.ip
public static function ip($check, $type = 'both') { $type = strtolower($type); $flags = 0; if ($type === 'ipv4') { $flags = FILTER_FLAG_IPV4; } if ($type === 'ipv6') { $flags = FILTER_FLAG_IPV6; } return (bool)filter_var($check, FILTER_VALIDATE_IP, ['flags' => $flags]); }
php
public static function ip($check, $type = 'both') { $type = strtolower($type); $flags = 0; if ($type === 'ipv4') { $flags = FILTER_FLAG_IPV4; } if ($type === 'ipv6') { $flags = FILTER_FLAG_IPV6; } return (bool)filter_var($check, FILTER_VALIDATE_IP, ['flags' => $flags]); }
[ "public", "static", "function", "ip", "(", "$", "check", ",", "$", "type", "=", "'both'", ")", "{", "$", "type", "=", "strtolower", "(", "$", "type", ")", ";", "$", "flags", "=", "0", ";", "if", "(", "$", "type", "===", "'ipv4'", ")", "{", "$", "flags", "=", "FILTER_FLAG_IPV4", ";", "}", "if", "(", "$", "type", "===", "'ipv6'", ")", "{", "$", "flags", "=", "FILTER_FLAG_IPV6", ";", "}", "return", "(", "bool", ")", "filter_var", "(", "$", "check", ",", "FILTER_VALIDATE_IP", ",", "[", "'flags'", "=>", "$", "flags", "]", ")", ";", "}" ]
Validation of an IP address. @param string $check The string to test. @param string $type The IP Protocol version to validate against @return bool Success
[ "Validation", "of", "an", "IP", "address", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L832-L844
211,194
cakephp/cakephp
src/Validation/Validation.php
Validation.money
public static function money($check, $symbolPosition = 'left') { $money = '(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{1,2})?'; if ($symbolPosition === 'right') { $regex = '/^' . $money . '(?<!\x{00a2})\p{Sc}?$/u'; } else { $regex = '/^(?!\x{00a2})\p{Sc}?' . $money . '$/u'; } return static::_check($check, $regex); }
php
public static function money($check, $symbolPosition = 'left') { $money = '(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{1,2})?'; if ($symbolPosition === 'right') { $regex = '/^' . $money . '(?<!\x{00a2})\p{Sc}?$/u'; } else { $regex = '/^(?!\x{00a2})\p{Sc}?' . $money . '$/u'; } return static::_check($check, $regex); }
[ "public", "static", "function", "money", "(", "$", "check", ",", "$", "symbolPosition", "=", "'left'", ")", "{", "$", "money", "=", "'(?!0,?\\d)(?:\\d{1,3}(?:([, .])\\d{3})?(?:\\1\\d{3})*|(?:\\d+))((?!\\1)[,.]\\d{1,2})?'", ";", "if", "(", "$", "symbolPosition", "===", "'right'", ")", "{", "$", "regex", "=", "'/^'", ".", "$", "money", ".", "'(?<!\\x{00a2})\\p{Sc}?$/u'", ";", "}", "else", "{", "$", "regex", "=", "'/^(?!\\x{00a2})\\p{Sc}?'", ".", "$", "money", ".", "'$/u'", ";", "}", "return", "static", "::", "_check", "(", "$", "check", ",", "$", "regex", ")", ";", "}" ]
Checks that a value is a monetary amount. @param string $check Value to check @param string $symbolPosition Where symbol is located (left/right) @return bool Success
[ "Checks", "that", "a", "value", "is", "a", "monetary", "amount", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L901-L911
211,195
cakephp/cakephp
src/Validation/Validation.php
Validation.multiple
public static function multiple($check, array $options = [], $caseInsensitive = false) { $defaults = ['in' => null, 'max' => null, 'min' => null]; $options += $defaults; $check = array_filter((array)$check, function ($value) { return ($value || is_numeric($value)); }); if (empty($check)) { return false; } if ($options['max'] && count($check) > $options['max']) { return false; } if ($options['min'] && count($check) < $options['min']) { return false; } if ($options['in'] && is_array($options['in'])) { if ($caseInsensitive) { $options['in'] = array_map('mb_strtolower', $options['in']); } foreach ($check as $val) { $strict = !is_numeric($val); if ($caseInsensitive) { $val = mb_strtolower($val); } if (!in_array((string)$val, $options['in'], $strict)) { return false; } } } return true; }
php
public static function multiple($check, array $options = [], $caseInsensitive = false) { $defaults = ['in' => null, 'max' => null, 'min' => null]; $options += $defaults; $check = array_filter((array)$check, function ($value) { return ($value || is_numeric($value)); }); if (empty($check)) { return false; } if ($options['max'] && count($check) > $options['max']) { return false; } if ($options['min'] && count($check) < $options['min']) { return false; } if ($options['in'] && is_array($options['in'])) { if ($caseInsensitive) { $options['in'] = array_map('mb_strtolower', $options['in']); } foreach ($check as $val) { $strict = !is_numeric($val); if ($caseInsensitive) { $val = mb_strtolower($val); } if (!in_array((string)$val, $options['in'], $strict)) { return false; } } } return true; }
[ "public", "static", "function", "multiple", "(", "$", "check", ",", "array", "$", "options", "=", "[", "]", ",", "$", "caseInsensitive", "=", "false", ")", "{", "$", "defaults", "=", "[", "'in'", "=>", "null", ",", "'max'", "=>", "null", ",", "'min'", "=>", "null", "]", ";", "$", "options", "+=", "$", "defaults", ";", "$", "check", "=", "array_filter", "(", "(", "array", ")", "$", "check", ",", "function", "(", "$", "value", ")", "{", "return", "(", "$", "value", "||", "is_numeric", "(", "$", "value", ")", ")", ";", "}", ")", ";", "if", "(", "empty", "(", "$", "check", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "options", "[", "'max'", "]", "&&", "count", "(", "$", "check", ")", ">", "$", "options", "[", "'max'", "]", ")", "{", "return", "false", ";", "}", "if", "(", "$", "options", "[", "'min'", "]", "&&", "count", "(", "$", "check", ")", "<", "$", "options", "[", "'min'", "]", ")", "{", "return", "false", ";", "}", "if", "(", "$", "options", "[", "'in'", "]", "&&", "is_array", "(", "$", "options", "[", "'in'", "]", ")", ")", "{", "if", "(", "$", "caseInsensitive", ")", "{", "$", "options", "[", "'in'", "]", "=", "array_map", "(", "'mb_strtolower'", ",", "$", "options", "[", "'in'", "]", ")", ";", "}", "foreach", "(", "$", "check", "as", "$", "val", ")", "{", "$", "strict", "=", "!", "is_numeric", "(", "$", "val", ")", ";", "if", "(", "$", "caseInsensitive", ")", "{", "$", "val", "=", "mb_strtolower", "(", "$", "val", ")", ";", "}", "if", "(", "!", "in_array", "(", "(", "string", ")", "$", "val", ",", "$", "options", "[", "'in'", "]", ",", "$", "strict", ")", ")", "{", "return", "false", ";", "}", "}", "}", "return", "true", ";", "}" ]
Validates a multiple select. Comparison is case sensitive by default. Valid Options - in => provide a list of choices that selections must be made from - max => maximum number of non-zero choices that can be made - min => minimum number of non-zero choices that can be made @param array $check Value to check @param array $options Options for the check. @param bool $caseInsensitive Set to true for case insensitive comparison. @return bool Success
[ "Validates", "a", "multiple", "select", ".", "Comparison", "is", "case", "sensitive", "by", "default", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L927-L960
211,196
cakephp/cakephp
src/Validation/Validation.php
Validation.inList
public static function inList($check, array $list, $caseInsensitive = false) { if ($caseInsensitive) { $list = array_map('mb_strtolower', $list); $check = mb_strtolower($check); } else { $list = array_map('strval', $list); } return in_array((string)$check, $list, true); }
php
public static function inList($check, array $list, $caseInsensitive = false) { if ($caseInsensitive) { $list = array_map('mb_strtolower', $list); $check = mb_strtolower($check); } else { $list = array_map('strval', $list); } return in_array((string)$check, $list, true); }
[ "public", "static", "function", "inList", "(", "$", "check", ",", "array", "$", "list", ",", "$", "caseInsensitive", "=", "false", ")", "{", "if", "(", "$", "caseInsensitive", ")", "{", "$", "list", "=", "array_map", "(", "'mb_strtolower'", ",", "$", "list", ")", ";", "$", "check", "=", "mb_strtolower", "(", "$", "check", ")", ";", "}", "else", "{", "$", "list", "=", "array_map", "(", "'strval'", ",", "$", "list", ")", ";", "}", "return", "in_array", "(", "(", "string", ")", "$", "check", ",", "$", "list", ",", "true", ")", ";", "}" ]
Checks if a value is in a given list. Comparison is case sensitive by default. @param string $check Value to check. @param array $list List to check against. @param bool $caseInsensitive Set to true for case insensitive comparison. @return bool Success.
[ "Checks", "if", "a", "value", "is", "in", "a", "given", "list", ".", "Comparison", "is", "case", "sensitive", "by", "default", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L1060-L1070
211,197
cakephp/cakephp
src/Validation/Validation.php
Validation.userDefined
public static function userDefined($check, $object, $method, $args = null) { deprecationWarning( 'Validation::userDefined() is deprecated. ' . 'You can just set a callable for `rule` key when adding validators.' ); return $object->$method($check, $args); }
php
public static function userDefined($check, $object, $method, $args = null) { deprecationWarning( 'Validation::userDefined() is deprecated. ' . 'You can just set a callable for `rule` key when adding validators.' ); return $object->$method($check, $args); }
[ "public", "static", "function", "userDefined", "(", "$", "check", ",", "$", "object", ",", "$", "method", ",", "$", "args", "=", "null", ")", "{", "deprecationWarning", "(", "'Validation::userDefined() is deprecated. '", ".", "'You can just set a callable for `rule` key when adding validators.'", ")", ";", "return", "$", "object", "->", "$", "method", "(", "$", "check", ",", "$", "args", ")", ";", "}" ]
Runs an user-defined validation. @param string|array $check value that will be validated in user-defined methods. @param object $object class that holds validation method @param string $method class method name for validation to run @param array|null $args arguments to send to method @return mixed user-defined class class method returns @deprecated 3.0.2 You can just set a callable for `rule` key when adding validators.
[ "Runs", "an", "user", "-", "defined", "validation", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L1082-L1090
211,198
cakephp/cakephp
src/Validation/Validation.php
Validation.mimeType
public static function mimeType($check, $mimeTypes = []) { $file = static::getFilename($check); if ($file === false) { return false; } if (!function_exists('finfo_open')) { throw new LogicException('ext/fileinfo is required for validating file mime types'); } if (!is_file($file)) { throw new RuntimeException('Cannot validate mimetype for a missing file'); } $finfo = finfo_open(FILEINFO_MIME); $finfo = finfo_file($finfo, $file); if (!$finfo) { throw new RuntimeException('Can not determine the mimetype.'); } list($mime) = explode(';', $finfo); if (is_string($mimeTypes)) { return self::_check($mime, $mimeTypes); } foreach ($mimeTypes as $key => $val) { $mimeTypes[$key] = strtolower($val); } return in_array($mime, $mimeTypes); }
php
public static function mimeType($check, $mimeTypes = []) { $file = static::getFilename($check); if ($file === false) { return false; } if (!function_exists('finfo_open')) { throw new LogicException('ext/fileinfo is required for validating file mime types'); } if (!is_file($file)) { throw new RuntimeException('Cannot validate mimetype for a missing file'); } $finfo = finfo_open(FILEINFO_MIME); $finfo = finfo_file($finfo, $file); if (!$finfo) { throw new RuntimeException('Can not determine the mimetype.'); } list($mime) = explode(';', $finfo); if (is_string($mimeTypes)) { return self::_check($mime, $mimeTypes); } foreach ($mimeTypes as $key => $val) { $mimeTypes[$key] = strtolower($val); } return in_array($mime, $mimeTypes); }
[ "public", "static", "function", "mimeType", "(", "$", "check", ",", "$", "mimeTypes", "=", "[", "]", ")", "{", "$", "file", "=", "static", "::", "getFilename", "(", "$", "check", ")", ";", "if", "(", "$", "file", "===", "false", ")", "{", "return", "false", ";", "}", "if", "(", "!", "function_exists", "(", "'finfo_open'", ")", ")", "{", "throw", "new", "LogicException", "(", "'ext/fileinfo is required for validating file mime types'", ")", ";", "}", "if", "(", "!", "is_file", "(", "$", "file", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'Cannot validate mimetype for a missing file'", ")", ";", "}", "$", "finfo", "=", "finfo_open", "(", "FILEINFO_MIME", ")", ";", "$", "finfo", "=", "finfo_file", "(", "$", "finfo", ",", "$", "file", ")", ";", "if", "(", "!", "$", "finfo", ")", "{", "throw", "new", "RuntimeException", "(", "'Can not determine the mimetype.'", ")", ";", "}", "list", "(", "$", "mime", ")", "=", "explode", "(", "';'", ",", "$", "finfo", ")", ";", "if", "(", "is_string", "(", "$", "mimeTypes", ")", ")", "{", "return", "self", "::", "_check", "(", "$", "mime", ",", "$", "mimeTypes", ")", ";", "}", "foreach", "(", "$", "mimeTypes", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "mimeTypes", "[", "$", "key", "]", "=", "strtolower", "(", "$", "val", ")", ";", "}", "return", "in_array", "(", "$", "mime", ",", "$", "mimeTypes", ")", ";", "}" ]
Checks the mime type of a file. Will check the mimetype of files/UploadedFileInterface instances by checking the using finfo on the file, not relying on the content-type sent by the client. @param string|array|\Psr\Http\Message\UploadedFileInterface $check Value to check. @param array|string $mimeTypes Array of mime types or regex pattern to check. @return bool Success @throws \RuntimeException when mime type can not be determined. @throws \LogicException when ext/fileinfo is missing
[ "Checks", "the", "mime", "type", "of", "a", "file", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L1157-L1190
211,199
cakephp/cakephp
src/Validation/Validation.php
Validation.getFilename
protected static function getFilename($check) { if ($check instanceof UploadedFileInterface) { try { // Uploaded files throw exceptions on upload errors. return $check->getStream()->getMetadata('uri'); } catch (RuntimeException $e) { return false; } } if (is_array($check) && isset($check['tmp_name'])) { return $check['tmp_name']; } if (is_string($check)) { return $check; } return false; }
php
protected static function getFilename($check) { if ($check instanceof UploadedFileInterface) { try { // Uploaded files throw exceptions on upload errors. return $check->getStream()->getMetadata('uri'); } catch (RuntimeException $e) { return false; } } if (is_array($check) && isset($check['tmp_name'])) { return $check['tmp_name']; } if (is_string($check)) { return $check; } return false; }
[ "protected", "static", "function", "getFilename", "(", "$", "check", ")", "{", "if", "(", "$", "check", "instanceof", "UploadedFileInterface", ")", "{", "try", "{", "// Uploaded files throw exceptions on upload errors.", "return", "$", "check", "->", "getStream", "(", ")", "->", "getMetadata", "(", "'uri'", ")", ";", "}", "catch", "(", "RuntimeException", "$", "e", ")", "{", "return", "false", ";", "}", "}", "if", "(", "is_array", "(", "$", "check", ")", "&&", "isset", "(", "$", "check", "[", "'tmp_name'", "]", ")", ")", "{", "return", "$", "check", "[", "'tmp_name'", "]", ";", "}", "if", "(", "is_string", "(", "$", "check", ")", ")", "{", "return", "$", "check", ";", "}", "return", "false", ";", "}" ]
Helper for reading the file out of the various file implementations we accept. @param string|array|\Psr\Http\Message\UploadedFileInterface $check The data to read a filename out of. @return string|bool Either the filename or false on failure.
[ "Helper", "for", "reading", "the", "file", "out", "of", "the", "various", "file", "implementations", "we", "accept", "." ]
5f6c9d65dcbbfc093410d1dbbb207a17f4cde540
https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Validation/Validation.php#L1199-L1218