id int32 0 241k | repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 |
|---|---|---|---|---|---|---|---|---|---|---|---|
210,500 | cakephp/cakephp | src/ORM/Marshaller.php | Marshaller._buildPropertyMap | protected function _buildPropertyMap($data, $options)
{
$map = [];
$schema = $this->_table->getSchema();
// Is a concrete column?
foreach (array_keys($data) as $prop) {
$columnType = $schema->getColumnType($prop);
if ($columnType) {
$map[$prop] = function ($value, $entity) use ($columnType) {
return Type::build($columnType)->marshal($value);
};
}
}
// Map associations
if (!isset($options['associated'])) {
$options['associated'] = [];
}
$include = $this->_normalizeAssociations($options['associated']);
foreach ($include as $key => $nested) {
if (is_int($key) && is_scalar($nested)) {
$key = $nested;
$nested = [];
}
// If the key is not a special field like _ids or _joinData
// it is a missing association that we should error on.
if (!$this->_table->hasAssociation($key)) {
if (substr($key, 0, 1) !== '_') {
throw new \InvalidArgumentException(sprintf(
'Cannot marshal data for "%s" association. It is not associated with "%s".',
$key,
$this->_table->getAlias()
));
}
continue;
}
$assoc = $this->_table->getAssociation($key);
if (isset($options['forceNew'])) {
$nested['forceNew'] = $options['forceNew'];
}
if (isset($options['isMerge'])) {
$callback = function ($value, $entity) use ($assoc, $nested) {
/** @var \Cake\Datasource\EntityInterface $entity */
$options = $nested + ['associated' => [], 'association' => $assoc];
return $this->_mergeAssociation($entity->get($assoc->getProperty()), $assoc, $value, $options);
};
} else {
$callback = function ($value, $entity) use ($assoc, $nested) {
$options = $nested + ['associated' => []];
return $this->_marshalAssociation($assoc, $value, $options);
};
}
$map[$assoc->getProperty()] = $callback;
}
$behaviors = $this->_table->behaviors();
foreach ($behaviors->loaded() as $name) {
$behavior = $behaviors->get($name);
if ($behavior instanceof PropertyMarshalInterface) {
$map += $behavior->buildMarshalMap($this, $map, $options);
}
}
return $map;
} | php | protected function _buildPropertyMap($data, $options)
{
$map = [];
$schema = $this->_table->getSchema();
// Is a concrete column?
foreach (array_keys($data) as $prop) {
$columnType = $schema->getColumnType($prop);
if ($columnType) {
$map[$prop] = function ($value, $entity) use ($columnType) {
return Type::build($columnType)->marshal($value);
};
}
}
// Map associations
if (!isset($options['associated'])) {
$options['associated'] = [];
}
$include = $this->_normalizeAssociations($options['associated']);
foreach ($include as $key => $nested) {
if (is_int($key) && is_scalar($nested)) {
$key = $nested;
$nested = [];
}
// If the key is not a special field like _ids or _joinData
// it is a missing association that we should error on.
if (!$this->_table->hasAssociation($key)) {
if (substr($key, 0, 1) !== '_') {
throw new \InvalidArgumentException(sprintf(
'Cannot marshal data for "%s" association. It is not associated with "%s".',
$key,
$this->_table->getAlias()
));
}
continue;
}
$assoc = $this->_table->getAssociation($key);
if (isset($options['forceNew'])) {
$nested['forceNew'] = $options['forceNew'];
}
if (isset($options['isMerge'])) {
$callback = function ($value, $entity) use ($assoc, $nested) {
/** @var \Cake\Datasource\EntityInterface $entity */
$options = $nested + ['associated' => [], 'association' => $assoc];
return $this->_mergeAssociation($entity->get($assoc->getProperty()), $assoc, $value, $options);
};
} else {
$callback = function ($value, $entity) use ($assoc, $nested) {
$options = $nested + ['associated' => []];
return $this->_marshalAssociation($assoc, $value, $options);
};
}
$map[$assoc->getProperty()] = $callback;
}
$behaviors = $this->_table->behaviors();
foreach ($behaviors->loaded() as $name) {
$behavior = $behaviors->get($name);
if ($behavior instanceof PropertyMarshalInterface) {
$map += $behavior->buildMarshalMap($this, $map, $options);
}
}
return $map;
} | [
"protected",
"function",
"_buildPropertyMap",
"(",
"$",
"data",
",",
"$",
"options",
")",
"{",
"$",
"map",
"=",
"[",
"]",
";",
"$",
"schema",
"=",
"$",
"this",
"->",
"_table",
"->",
"getSchema",
"(",
")",
";",
"// Is a concrete column?",
"foreach",
"(",
"array_keys",
"(",
"$",
"data",
")",
"as",
"$",
"prop",
")",
"{",
"$",
"columnType",
"=",
"$",
"schema",
"->",
"getColumnType",
"(",
"$",
"prop",
")",
";",
"if",
"(",
"$",
"columnType",
")",
"{",
"$",
"map",
"[",
"$",
"prop",
"]",
"=",
"function",
"(",
"$",
"value",
",",
"$",
"entity",
")",
"use",
"(",
"$",
"columnType",
")",
"{",
"return",
"Type",
"::",
"build",
"(",
"$",
"columnType",
")",
"->",
"marshal",
"(",
"$",
"value",
")",
";",
"}",
";",
"}",
"}",
"// Map associations",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'associated'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'associated'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"include",
"=",
"$",
"this",
"->",
"_normalizeAssociations",
"(",
"$",
"options",
"[",
"'associated'",
"]",
")",
";",
"foreach",
"(",
"$",
"include",
"as",
"$",
"key",
"=>",
"$",
"nested",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"key",
")",
"&&",
"is_scalar",
"(",
"$",
"nested",
")",
")",
"{",
"$",
"key",
"=",
"$",
"nested",
";",
"$",
"nested",
"=",
"[",
"]",
";",
"}",
"// If the key is not a special field like _ids or _joinData",
"// it is a missing association that we should error on.",
"if",
"(",
"!",
"$",
"this",
"->",
"_table",
"->",
"hasAssociation",
"(",
"$",
"key",
")",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"key",
",",
"0",
",",
"1",
")",
"!==",
"'_'",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Cannot marshal data for \"%s\" association. It is not associated with \"%s\".'",
",",
"$",
"key",
",",
"$",
"this",
"->",
"_table",
"->",
"getAlias",
"(",
")",
")",
")",
";",
"}",
"continue",
";",
"}",
"$",
"assoc",
"=",
"$",
"this",
"->",
"_table",
"->",
"getAssociation",
"(",
"$",
"key",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'forceNew'",
"]",
")",
")",
"{",
"$",
"nested",
"[",
"'forceNew'",
"]",
"=",
"$",
"options",
"[",
"'forceNew'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'isMerge'",
"]",
")",
")",
"{",
"$",
"callback",
"=",
"function",
"(",
"$",
"value",
",",
"$",
"entity",
")",
"use",
"(",
"$",
"assoc",
",",
"$",
"nested",
")",
"{",
"/** @var \\Cake\\Datasource\\EntityInterface $entity */",
"$",
"options",
"=",
"$",
"nested",
"+",
"[",
"'associated'",
"=>",
"[",
"]",
",",
"'association'",
"=>",
"$",
"assoc",
"]",
";",
"return",
"$",
"this",
"->",
"_mergeAssociation",
"(",
"$",
"entity",
"->",
"get",
"(",
"$",
"assoc",
"->",
"getProperty",
"(",
")",
")",
",",
"$",
"assoc",
",",
"$",
"value",
",",
"$",
"options",
")",
";",
"}",
";",
"}",
"else",
"{",
"$",
"callback",
"=",
"function",
"(",
"$",
"value",
",",
"$",
"entity",
")",
"use",
"(",
"$",
"assoc",
",",
"$",
"nested",
")",
"{",
"$",
"options",
"=",
"$",
"nested",
"+",
"[",
"'associated'",
"=>",
"[",
"]",
"]",
";",
"return",
"$",
"this",
"->",
"_marshalAssociation",
"(",
"$",
"assoc",
",",
"$",
"value",
",",
"$",
"options",
")",
";",
"}",
";",
"}",
"$",
"map",
"[",
"$",
"assoc",
"->",
"getProperty",
"(",
")",
"]",
"=",
"$",
"callback",
";",
"}",
"$",
"behaviors",
"=",
"$",
"this",
"->",
"_table",
"->",
"behaviors",
"(",
")",
";",
"foreach",
"(",
"$",
"behaviors",
"->",
"loaded",
"(",
")",
"as",
"$",
"name",
")",
"{",
"$",
"behavior",
"=",
"$",
"behaviors",
"->",
"get",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"behavior",
"instanceof",
"PropertyMarshalInterface",
")",
"{",
"$",
"map",
"+=",
"$",
"behavior",
"->",
"buildMarshalMap",
"(",
"$",
"this",
",",
"$",
"map",
",",
"$",
"options",
")",
";",
"}",
"}",
"return",
"$",
"map",
";",
"}"
] | Build the map of property => marshalling callable.
@param array $data The data being marshalled.
@param array $options List of options containing the 'associated' key.
@throws \InvalidArgumentException When associations do not exist.
@return array | [
"Build",
"the",
"map",
"of",
"property",
"=",
">",
"marshalling",
"callable",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Marshaller.php#L66-L134 |
210,501 | cakephp/cakephp | src/ORM/Marshaller.php | Marshaller.one | public function one(array $data, array $options = [])
{
list($data, $options) = $this->_prepareDataAndOptions($data, $options);
$primaryKey = (array)$this->_table->getPrimaryKey();
$entityClass = $this->_table->getEntityClass();
/** @var \Cake\Datasource\EntityInterface $entity */
$entity = new $entityClass();
$entity->setSource($this->_table->getRegistryAlias());
if (isset($options['accessibleFields'])) {
foreach ((array)$options['accessibleFields'] as $key => $value) {
$entity->setAccess($key, $value);
}
}
$errors = $this->_validate($data, $options, true);
$options['isMerge'] = false;
$propertyMap = $this->_buildPropertyMap($data, $options);
$properties = [];
foreach ($data as $key => $value) {
if (!empty($errors[$key])) {
if ($entity instanceof InvalidPropertyInterface) {
$entity->setInvalidField($key, $value);
}
continue;
}
if ($value === '' && in_array($key, $primaryKey, true)) {
// Skip marshalling '' for pk fields.
continue;
}
if (isset($propertyMap[$key])) {
$properties[$key] = $propertyMap[$key]($value, $entity);
} else {
$properties[$key] = $value;
}
}
if (isset($options['fields'])) {
foreach ((array)$options['fields'] as $field) {
if (array_key_exists($field, $properties)) {
$entity->set($field, $properties[$field]);
}
}
} else {
$entity->set($properties);
}
// Don't flag clean association entities as
// dirty so we don't persist empty records.
foreach ($properties as $field => $value) {
if ($value instanceof EntityInterface) {
$entity->setDirty($field, $value->isDirty());
}
}
$entity->setErrors($errors);
return $entity;
} | php | public function one(array $data, array $options = [])
{
list($data, $options) = $this->_prepareDataAndOptions($data, $options);
$primaryKey = (array)$this->_table->getPrimaryKey();
$entityClass = $this->_table->getEntityClass();
/** @var \Cake\Datasource\EntityInterface $entity */
$entity = new $entityClass();
$entity->setSource($this->_table->getRegistryAlias());
if (isset($options['accessibleFields'])) {
foreach ((array)$options['accessibleFields'] as $key => $value) {
$entity->setAccess($key, $value);
}
}
$errors = $this->_validate($data, $options, true);
$options['isMerge'] = false;
$propertyMap = $this->_buildPropertyMap($data, $options);
$properties = [];
foreach ($data as $key => $value) {
if (!empty($errors[$key])) {
if ($entity instanceof InvalidPropertyInterface) {
$entity->setInvalidField($key, $value);
}
continue;
}
if ($value === '' && in_array($key, $primaryKey, true)) {
// Skip marshalling '' for pk fields.
continue;
}
if (isset($propertyMap[$key])) {
$properties[$key] = $propertyMap[$key]($value, $entity);
} else {
$properties[$key] = $value;
}
}
if (isset($options['fields'])) {
foreach ((array)$options['fields'] as $field) {
if (array_key_exists($field, $properties)) {
$entity->set($field, $properties[$field]);
}
}
} else {
$entity->set($properties);
}
// Don't flag clean association entities as
// dirty so we don't persist empty records.
foreach ($properties as $field => $value) {
if ($value instanceof EntityInterface) {
$entity->setDirty($field, $value->isDirty());
}
}
$entity->setErrors($errors);
return $entity;
} | [
"public",
"function",
"one",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"list",
"(",
"$",
"data",
",",
"$",
"options",
")",
"=",
"$",
"this",
"->",
"_prepareDataAndOptions",
"(",
"$",
"data",
",",
"$",
"options",
")",
";",
"$",
"primaryKey",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"_table",
"->",
"getPrimaryKey",
"(",
")",
";",
"$",
"entityClass",
"=",
"$",
"this",
"->",
"_table",
"->",
"getEntityClass",
"(",
")",
";",
"/** @var \\Cake\\Datasource\\EntityInterface $entity */",
"$",
"entity",
"=",
"new",
"$",
"entityClass",
"(",
")",
";",
"$",
"entity",
"->",
"setSource",
"(",
"$",
"this",
"->",
"_table",
"->",
"getRegistryAlias",
"(",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'accessibleFields'",
"]",
")",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"options",
"[",
"'accessibleFields'",
"]",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"entity",
"->",
"setAccess",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}",
"$",
"errors",
"=",
"$",
"this",
"->",
"_validate",
"(",
"$",
"data",
",",
"$",
"options",
",",
"true",
")",
";",
"$",
"options",
"[",
"'isMerge'",
"]",
"=",
"false",
";",
"$",
"propertyMap",
"=",
"$",
"this",
"->",
"_buildPropertyMap",
"(",
"$",
"data",
",",
"$",
"options",
")",
";",
"$",
"properties",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"errors",
"[",
"$",
"key",
"]",
")",
")",
"{",
"if",
"(",
"$",
"entity",
"instanceof",
"InvalidPropertyInterface",
")",
"{",
"$",
"entity",
"->",
"setInvalidField",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"continue",
";",
"}",
"if",
"(",
"$",
"value",
"===",
"''",
"&&",
"in_array",
"(",
"$",
"key",
",",
"$",
"primaryKey",
",",
"true",
")",
")",
"{",
"// Skip marshalling '' for pk fields.",
"continue",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"propertyMap",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"properties",
"[",
"$",
"key",
"]",
"=",
"$",
"propertyMap",
"[",
"$",
"key",
"]",
"(",
"$",
"value",
",",
"$",
"entity",
")",
";",
"}",
"else",
"{",
"$",
"properties",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'fields'",
"]",
")",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"options",
"[",
"'fields'",
"]",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"field",
",",
"$",
"properties",
")",
")",
"{",
"$",
"entity",
"->",
"set",
"(",
"$",
"field",
",",
"$",
"properties",
"[",
"$",
"field",
"]",
")",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"entity",
"->",
"set",
"(",
"$",
"properties",
")",
";",
"}",
"// Don't flag clean association entities as",
"// dirty so we don't persist empty records.",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"EntityInterface",
")",
"{",
"$",
"entity",
"->",
"setDirty",
"(",
"$",
"field",
",",
"$",
"value",
"->",
"isDirty",
"(",
")",
")",
";",
"}",
"}",
"$",
"entity",
"->",
"setErrors",
"(",
"$",
"errors",
")",
";",
"return",
"$",
"entity",
";",
"}"
] | Hydrate one entity and its associated data.
### Options:
- validate: Set to false to disable validation. Can also be a string of the validator ruleset to be applied.
Defaults to true/default.
- associated: Associations listed here will be marshalled as well. Defaults to null.
- fieldList: (deprecated) Since 3.4.0. Use fields instead.
- fields: A whitelist of fields to be assigned to the entity. If not present,
the accessible fields list in the entity will be used. Defaults to null.
- accessibleFields: A list of fields to allow or deny in entity accessible fields. Defaults to null
- forceNew: When enabled, belongsToMany associations will have 'new' entities created
when primary key values are set, and a record does not already exist. Normally primary key
on missing entities would be ignored. Defaults to false.
The above options can be used in each nested `associated` array. In addition to the above
options you can also use the `onlyIds` option for HasMany and BelongsToMany associations.
When true this option restricts the request data to only be read from `_ids`.
```
$result = $marshaller->one($data, [
'associated' => ['Tags' => ['onlyIds' => true]]
]);
```
@param array $data The data to hydrate.
@param array $options List of options
@return \Cake\Datasource\EntityInterface
@see \Cake\ORM\Table::newEntity()
@see \Cake\ORM\Entity::$_accessible | [
"Hydrate",
"one",
"entity",
"and",
"its",
"associated",
"data",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Marshaller.php#L168-L228 |
210,502 | cakephp/cakephp | src/ORM/Marshaller.php | Marshaller._marshalAssociation | protected function _marshalAssociation($assoc, $value, $options)
{
if (!is_array($value)) {
return null;
}
$targetTable = $assoc->getTarget();
$marshaller = $targetTable->marshaller();
$types = [Association::ONE_TO_ONE, Association::MANY_TO_ONE];
if (in_array($assoc->type(), $types)) {
return $marshaller->one($value, (array)$options);
}
if ($assoc->type() === Association::ONE_TO_MANY || $assoc->type() === Association::MANY_TO_MANY) {
$hasIds = array_key_exists('_ids', $value);
$onlyIds = array_key_exists('onlyIds', $options) && $options['onlyIds'];
if ($hasIds && is_array($value['_ids'])) {
return $this->_loadAssociatedByIds($assoc, $value['_ids']);
}
if ($hasIds || $onlyIds) {
return [];
}
}
if ($assoc->type() === Association::MANY_TO_MANY) {
return $marshaller->_belongsToMany($assoc, $value, (array)$options);
}
return $marshaller->many($value, (array)$options);
} | php | protected function _marshalAssociation($assoc, $value, $options)
{
if (!is_array($value)) {
return null;
}
$targetTable = $assoc->getTarget();
$marshaller = $targetTable->marshaller();
$types = [Association::ONE_TO_ONE, Association::MANY_TO_ONE];
if (in_array($assoc->type(), $types)) {
return $marshaller->one($value, (array)$options);
}
if ($assoc->type() === Association::ONE_TO_MANY || $assoc->type() === Association::MANY_TO_MANY) {
$hasIds = array_key_exists('_ids', $value);
$onlyIds = array_key_exists('onlyIds', $options) && $options['onlyIds'];
if ($hasIds && is_array($value['_ids'])) {
return $this->_loadAssociatedByIds($assoc, $value['_ids']);
}
if ($hasIds || $onlyIds) {
return [];
}
}
if ($assoc->type() === Association::MANY_TO_MANY) {
return $marshaller->_belongsToMany($assoc, $value, (array)$options);
}
return $marshaller->many($value, (array)$options);
} | [
"protected",
"function",
"_marshalAssociation",
"(",
"$",
"assoc",
",",
"$",
"value",
",",
"$",
"options",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"targetTable",
"=",
"$",
"assoc",
"->",
"getTarget",
"(",
")",
";",
"$",
"marshaller",
"=",
"$",
"targetTable",
"->",
"marshaller",
"(",
")",
";",
"$",
"types",
"=",
"[",
"Association",
"::",
"ONE_TO_ONE",
",",
"Association",
"::",
"MANY_TO_ONE",
"]",
";",
"if",
"(",
"in_array",
"(",
"$",
"assoc",
"->",
"type",
"(",
")",
",",
"$",
"types",
")",
")",
"{",
"return",
"$",
"marshaller",
"->",
"one",
"(",
"$",
"value",
",",
"(",
"array",
")",
"$",
"options",
")",
";",
"}",
"if",
"(",
"$",
"assoc",
"->",
"type",
"(",
")",
"===",
"Association",
"::",
"ONE_TO_MANY",
"||",
"$",
"assoc",
"->",
"type",
"(",
")",
"===",
"Association",
"::",
"MANY_TO_MANY",
")",
"{",
"$",
"hasIds",
"=",
"array_key_exists",
"(",
"'_ids'",
",",
"$",
"value",
")",
";",
"$",
"onlyIds",
"=",
"array_key_exists",
"(",
"'onlyIds'",
",",
"$",
"options",
")",
"&&",
"$",
"options",
"[",
"'onlyIds'",
"]",
";",
"if",
"(",
"$",
"hasIds",
"&&",
"is_array",
"(",
"$",
"value",
"[",
"'_ids'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_loadAssociatedByIds",
"(",
"$",
"assoc",
",",
"$",
"value",
"[",
"'_ids'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"hasIds",
"||",
"$",
"onlyIds",
")",
"{",
"return",
"[",
"]",
";",
"}",
"}",
"if",
"(",
"$",
"assoc",
"->",
"type",
"(",
")",
"===",
"Association",
"::",
"MANY_TO_MANY",
")",
"{",
"return",
"$",
"marshaller",
"->",
"_belongsToMany",
"(",
"$",
"assoc",
",",
"$",
"value",
",",
"(",
"array",
")",
"$",
"options",
")",
";",
"}",
"return",
"$",
"marshaller",
"->",
"many",
"(",
"$",
"value",
",",
"(",
"array",
")",
"$",
"options",
")",
";",
"}"
] | Create a new sub-marshaller and marshal the associated data.
@param \Cake\ORM\Association $assoc The association to marshall
@param array $value The data to hydrate
@param array $options List of options.
@return \Cake\Datasource\EntityInterface|\Cake\Datasource\EntityInterface[]|null | [
"Create",
"a",
"new",
"sub",
"-",
"marshaller",
"and",
"marshal",
"the",
"associated",
"data",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Marshaller.php#L304-L331 |
210,503 | cakephp/cakephp | src/ORM/Marshaller.php | Marshaller.many | public function many(array $data, array $options = [])
{
$output = [];
foreach ($data as $record) {
if (!is_array($record)) {
continue;
}
$output[] = $this->one($record, $options);
}
return $output;
} | php | public function many(array $data, array $options = [])
{
$output = [];
foreach ($data as $record) {
if (!is_array($record)) {
continue;
}
$output[] = $this->one($record, $options);
}
return $output;
} | [
"public",
"function",
"many",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"record",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"record",
")",
")",
"{",
"continue",
";",
"}",
"$",
"output",
"[",
"]",
"=",
"$",
"this",
"->",
"one",
"(",
"$",
"record",
",",
"$",
"options",
")",
";",
"}",
"return",
"$",
"output",
";",
"}"
] | Hydrate many entities and their associated data.
### Options:
- validate: Set to false to disable validation. Can also be a string of the validator ruleset to be applied.
Defaults to true/default.
- associated: Associations listed here will be marshalled as well. Defaults to null.
- fieldList: (deprecated) Since 3.4.0. Use fields instead
- fields: A whitelist of fields to be assigned to the entity. If not present,
the accessible fields list in the entity will be used. Defaults to null.
- accessibleFields: A list of fields to allow or deny in entity accessible fields. Defaults to null
- forceNew: When enabled, belongsToMany associations will have 'new' entities created
when primary key values are set, and a record does not already exist. Normally primary key
on missing entities would be ignored. Defaults to false.
@param array $data The data to hydrate.
@param array $options List of options
@return \Cake\Datasource\EntityInterface[] An array of hydrated records.
@see \Cake\ORM\Table::newEntities()
@see \Cake\ORM\Entity::$_accessible | [
"Hydrate",
"many",
"entities",
"and",
"their",
"associated",
"data",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Marshaller.php#L355-L366 |
210,504 | cakephp/cakephp | src/ORM/Marshaller.php | Marshaller._loadAssociatedByIds | protected function _loadAssociatedByIds($assoc, $ids)
{
if (empty($ids)) {
return [];
}
$target = $assoc->getTarget();
$primaryKey = (array)$target->getPrimaryKey();
$multi = count($primaryKey) > 1;
$primaryKey = array_map([$target, 'aliasField'], $primaryKey);
if ($multi) {
$first = current($ids);
if (!is_array($first) || count($first) !== count($primaryKey)) {
return [];
}
$filter = new TupleComparison($primaryKey, $ids, [], 'IN');
} else {
$filter = [$primaryKey[0] . ' IN' => $ids];
}
return $target->find()->where($filter)->toArray();
} | php | protected function _loadAssociatedByIds($assoc, $ids)
{
if (empty($ids)) {
return [];
}
$target = $assoc->getTarget();
$primaryKey = (array)$target->getPrimaryKey();
$multi = count($primaryKey) > 1;
$primaryKey = array_map([$target, 'aliasField'], $primaryKey);
if ($multi) {
$first = current($ids);
if (!is_array($first) || count($first) !== count($primaryKey)) {
return [];
}
$filter = new TupleComparison($primaryKey, $ids, [], 'IN');
} else {
$filter = [$primaryKey[0] . ' IN' => $ids];
}
return $target->find()->where($filter)->toArray();
} | [
"protected",
"function",
"_loadAssociatedByIds",
"(",
"$",
"assoc",
",",
"$",
"ids",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"ids",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"target",
"=",
"$",
"assoc",
"->",
"getTarget",
"(",
")",
";",
"$",
"primaryKey",
"=",
"(",
"array",
")",
"$",
"target",
"->",
"getPrimaryKey",
"(",
")",
";",
"$",
"multi",
"=",
"count",
"(",
"$",
"primaryKey",
")",
">",
"1",
";",
"$",
"primaryKey",
"=",
"array_map",
"(",
"[",
"$",
"target",
",",
"'aliasField'",
"]",
",",
"$",
"primaryKey",
")",
";",
"if",
"(",
"$",
"multi",
")",
"{",
"$",
"first",
"=",
"current",
"(",
"$",
"ids",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"first",
")",
"||",
"count",
"(",
"$",
"first",
")",
"!==",
"count",
"(",
"$",
"primaryKey",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"filter",
"=",
"new",
"TupleComparison",
"(",
"$",
"primaryKey",
",",
"$",
"ids",
",",
"[",
"]",
",",
"'IN'",
")",
";",
"}",
"else",
"{",
"$",
"filter",
"=",
"[",
"$",
"primaryKey",
"[",
"0",
"]",
".",
"' IN'",
"=>",
"$",
"ids",
"]",
";",
"}",
"return",
"$",
"target",
"->",
"find",
"(",
")",
"->",
"where",
"(",
"$",
"filter",
")",
"->",
"toArray",
"(",
")",
";",
"}"
] | Loads a list of belongs to many from ids.
@param \Cake\ORM\Association $assoc The association class for the belongsToMany association.
@param array $ids The list of ids to load.
@return \Cake\Datasource\EntityInterface[] An array of entities. | [
"Loads",
"a",
"list",
"of",
"belongs",
"to",
"many",
"from",
"ids",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Marshaller.php#L474-L496 |
210,505 | cakephp/cakephp | src/ORM/Marshaller.php | Marshaller._mergeAssociation | protected function _mergeAssociation($original, $assoc, $value, $options)
{
if (!$original) {
return $this->_marshalAssociation($assoc, $value, $options);
}
if (!is_array($value)) {
return null;
}
$targetTable = $assoc->getTarget();
$marshaller = $targetTable->marshaller();
$types = [Association::ONE_TO_ONE, Association::MANY_TO_ONE];
if (in_array($assoc->type(), $types)) {
return $marshaller->merge($original, $value, (array)$options);
}
if ($assoc->type() === Association::MANY_TO_MANY) {
return $marshaller->_mergeBelongsToMany($original, $assoc, $value, (array)$options);
}
if ($assoc->type() === Association::ONE_TO_MANY) {
$hasIds = array_key_exists('_ids', $value);
$onlyIds = array_key_exists('onlyIds', $options) && $options['onlyIds'];
if ($hasIds && is_array($value['_ids'])) {
return $this->_loadAssociatedByIds($assoc, $value['_ids']);
}
if ($hasIds || $onlyIds) {
return [];
}
}
return $marshaller->mergeMany($original, $value, (array)$options);
} | php | protected function _mergeAssociation($original, $assoc, $value, $options)
{
if (!$original) {
return $this->_marshalAssociation($assoc, $value, $options);
}
if (!is_array($value)) {
return null;
}
$targetTable = $assoc->getTarget();
$marshaller = $targetTable->marshaller();
$types = [Association::ONE_TO_ONE, Association::MANY_TO_ONE];
if (in_array($assoc->type(), $types)) {
return $marshaller->merge($original, $value, (array)$options);
}
if ($assoc->type() === Association::MANY_TO_MANY) {
return $marshaller->_mergeBelongsToMany($original, $assoc, $value, (array)$options);
}
if ($assoc->type() === Association::ONE_TO_MANY) {
$hasIds = array_key_exists('_ids', $value);
$onlyIds = array_key_exists('onlyIds', $options) && $options['onlyIds'];
if ($hasIds && is_array($value['_ids'])) {
return $this->_loadAssociatedByIds($assoc, $value['_ids']);
}
if ($hasIds || $onlyIds) {
return [];
}
}
return $marshaller->mergeMany($original, $value, (array)$options);
} | [
"protected",
"function",
"_mergeAssociation",
"(",
"$",
"original",
",",
"$",
"assoc",
",",
"$",
"value",
",",
"$",
"options",
")",
"{",
"if",
"(",
"!",
"$",
"original",
")",
"{",
"return",
"$",
"this",
"->",
"_marshalAssociation",
"(",
"$",
"assoc",
",",
"$",
"value",
",",
"$",
"options",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"targetTable",
"=",
"$",
"assoc",
"->",
"getTarget",
"(",
")",
";",
"$",
"marshaller",
"=",
"$",
"targetTable",
"->",
"marshaller",
"(",
")",
";",
"$",
"types",
"=",
"[",
"Association",
"::",
"ONE_TO_ONE",
",",
"Association",
"::",
"MANY_TO_ONE",
"]",
";",
"if",
"(",
"in_array",
"(",
"$",
"assoc",
"->",
"type",
"(",
")",
",",
"$",
"types",
")",
")",
"{",
"return",
"$",
"marshaller",
"->",
"merge",
"(",
"$",
"original",
",",
"$",
"value",
",",
"(",
"array",
")",
"$",
"options",
")",
";",
"}",
"if",
"(",
"$",
"assoc",
"->",
"type",
"(",
")",
"===",
"Association",
"::",
"MANY_TO_MANY",
")",
"{",
"return",
"$",
"marshaller",
"->",
"_mergeBelongsToMany",
"(",
"$",
"original",
",",
"$",
"assoc",
",",
"$",
"value",
",",
"(",
"array",
")",
"$",
"options",
")",
";",
"}",
"if",
"(",
"$",
"assoc",
"->",
"type",
"(",
")",
"===",
"Association",
"::",
"ONE_TO_MANY",
")",
"{",
"$",
"hasIds",
"=",
"array_key_exists",
"(",
"'_ids'",
",",
"$",
"value",
")",
";",
"$",
"onlyIds",
"=",
"array_key_exists",
"(",
"'onlyIds'",
",",
"$",
"options",
")",
"&&",
"$",
"options",
"[",
"'onlyIds'",
"]",
";",
"if",
"(",
"$",
"hasIds",
"&&",
"is_array",
"(",
"$",
"value",
"[",
"'_ids'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_loadAssociatedByIds",
"(",
"$",
"assoc",
",",
"$",
"value",
"[",
"'_ids'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"hasIds",
"||",
"$",
"onlyIds",
")",
"{",
"return",
"[",
"]",
";",
"}",
"}",
"return",
"$",
"marshaller",
"->",
"mergeMany",
"(",
"$",
"original",
",",
"$",
"value",
",",
"(",
"array",
")",
"$",
"options",
")",
";",
"}"
] | Creates a new sub-marshaller and merges the associated data.
@param \Cake\Datasource\EntityInterface|\Cake\Datasource\EntityInterface[] $original The original entity
@param \Cake\ORM\Association $assoc The association to merge
@param array $value The data to hydrate
@param array $options List of options.
@return \Cake\Datasource\EntityInterface|\Cake\Datasource\EntityInterface[]|null | [
"Creates",
"a",
"new",
"sub",
"-",
"marshaller",
"and",
"merges",
"the",
"associated",
"data",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Marshaller.php#L738-L769 |
210,506 | cakephp/cakephp | src/ORM/Marshaller.php | Marshaller._mergeBelongsToMany | protected function _mergeBelongsToMany($original, $assoc, $value, $options)
{
$associated = isset($options['associated']) ? $options['associated'] : [];
$hasIds = array_key_exists('_ids', $value);
$onlyIds = array_key_exists('onlyIds', $options) && $options['onlyIds'];
if ($hasIds && is_array($value['_ids'])) {
return $this->_loadAssociatedByIds($assoc, $value['_ids']);
}
if ($hasIds || $onlyIds) {
return [];
}
if (!empty($associated) && !in_array('_joinData', $associated) && !isset($associated['_joinData'])) {
return $this->mergeMany($original, $value, $options);
}
return $this->_mergeJoinData($original, $assoc, $value, $options);
} | php | protected function _mergeBelongsToMany($original, $assoc, $value, $options)
{
$associated = isset($options['associated']) ? $options['associated'] : [];
$hasIds = array_key_exists('_ids', $value);
$onlyIds = array_key_exists('onlyIds', $options) && $options['onlyIds'];
if ($hasIds && is_array($value['_ids'])) {
return $this->_loadAssociatedByIds($assoc, $value['_ids']);
}
if ($hasIds || $onlyIds) {
return [];
}
if (!empty($associated) && !in_array('_joinData', $associated) && !isset($associated['_joinData'])) {
return $this->mergeMany($original, $value, $options);
}
return $this->_mergeJoinData($original, $assoc, $value, $options);
} | [
"protected",
"function",
"_mergeBelongsToMany",
"(",
"$",
"original",
",",
"$",
"assoc",
",",
"$",
"value",
",",
"$",
"options",
")",
"{",
"$",
"associated",
"=",
"isset",
"(",
"$",
"options",
"[",
"'associated'",
"]",
")",
"?",
"$",
"options",
"[",
"'associated'",
"]",
":",
"[",
"]",
";",
"$",
"hasIds",
"=",
"array_key_exists",
"(",
"'_ids'",
",",
"$",
"value",
")",
";",
"$",
"onlyIds",
"=",
"array_key_exists",
"(",
"'onlyIds'",
",",
"$",
"options",
")",
"&&",
"$",
"options",
"[",
"'onlyIds'",
"]",
";",
"if",
"(",
"$",
"hasIds",
"&&",
"is_array",
"(",
"$",
"value",
"[",
"'_ids'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_loadAssociatedByIds",
"(",
"$",
"assoc",
",",
"$",
"value",
"[",
"'_ids'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"hasIds",
"||",
"$",
"onlyIds",
")",
"{",
"return",
"[",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"associated",
")",
"&&",
"!",
"in_array",
"(",
"'_joinData'",
",",
"$",
"associated",
")",
"&&",
"!",
"isset",
"(",
"$",
"associated",
"[",
"'_joinData'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"mergeMany",
"(",
"$",
"original",
",",
"$",
"value",
",",
"$",
"options",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_mergeJoinData",
"(",
"$",
"original",
",",
"$",
"assoc",
",",
"$",
"value",
",",
"$",
"options",
")",
";",
"}"
] | Creates a new sub-marshaller and merges the associated data for a BelongstoMany
association.
@param \Cake\Datasource\EntityInterface $original The original entity
@param \Cake\ORM\Association $assoc The association to marshall
@param array $value The data to hydrate
@param array $options List of options.
@return \Cake\Datasource\EntityInterface[] | [
"Creates",
"a",
"new",
"sub",
"-",
"marshaller",
"and",
"merges",
"the",
"associated",
"data",
"for",
"a",
"BelongstoMany",
"association",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Marshaller.php#L781-L800 |
210,507 | cakephp/cakephp | src/ORM/Marshaller.php | Marshaller._mergeJoinData | protected function _mergeJoinData($original, $assoc, $value, $options)
{
$associated = isset($options['associated']) ? $options['associated'] : [];
$extra = [];
foreach ($original as $entity) {
// Mark joinData as accessible so we can marshal it properly.
$entity->setAccess('_joinData', true);
$joinData = $entity->get('_joinData');
if ($joinData && $joinData instanceof EntityInterface) {
$extra[spl_object_hash($entity)] = $joinData;
}
}
$joint = $assoc->junction();
$marshaller = $joint->marshaller();
$nested = [];
if (isset($associated['_joinData'])) {
$nested = (array)$associated['_joinData'];
}
$options['accessibleFields'] = ['_joinData' => true];
$records = $this->mergeMany($original, $value, $options);
foreach ($records as $record) {
$hash = spl_object_hash($record);
$value = $record->get('_joinData');
// Already an entity, no further marshalling required.
if ($value instanceof EntityInterface) {
continue;
}
// Scalar data can't be handled
if (!is_array($value)) {
$record->unsetProperty('_joinData');
continue;
}
// Marshal data into the old object, or make a new joinData object.
if (isset($extra[$hash])) {
$record->set('_joinData', $marshaller->merge($extra[$hash], $value, $nested));
} elseif (is_array($value)) {
$joinData = $marshaller->one($value, $nested);
$record->set('_joinData', $joinData);
}
}
return $records;
} | php | protected function _mergeJoinData($original, $assoc, $value, $options)
{
$associated = isset($options['associated']) ? $options['associated'] : [];
$extra = [];
foreach ($original as $entity) {
// Mark joinData as accessible so we can marshal it properly.
$entity->setAccess('_joinData', true);
$joinData = $entity->get('_joinData');
if ($joinData && $joinData instanceof EntityInterface) {
$extra[spl_object_hash($entity)] = $joinData;
}
}
$joint = $assoc->junction();
$marshaller = $joint->marshaller();
$nested = [];
if (isset($associated['_joinData'])) {
$nested = (array)$associated['_joinData'];
}
$options['accessibleFields'] = ['_joinData' => true];
$records = $this->mergeMany($original, $value, $options);
foreach ($records as $record) {
$hash = spl_object_hash($record);
$value = $record->get('_joinData');
// Already an entity, no further marshalling required.
if ($value instanceof EntityInterface) {
continue;
}
// Scalar data can't be handled
if (!is_array($value)) {
$record->unsetProperty('_joinData');
continue;
}
// Marshal data into the old object, or make a new joinData object.
if (isset($extra[$hash])) {
$record->set('_joinData', $marshaller->merge($extra[$hash], $value, $nested));
} elseif (is_array($value)) {
$joinData = $marshaller->one($value, $nested);
$record->set('_joinData', $joinData);
}
}
return $records;
} | [
"protected",
"function",
"_mergeJoinData",
"(",
"$",
"original",
",",
"$",
"assoc",
",",
"$",
"value",
",",
"$",
"options",
")",
"{",
"$",
"associated",
"=",
"isset",
"(",
"$",
"options",
"[",
"'associated'",
"]",
")",
"?",
"$",
"options",
"[",
"'associated'",
"]",
":",
"[",
"]",
";",
"$",
"extra",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"original",
"as",
"$",
"entity",
")",
"{",
"// Mark joinData as accessible so we can marshal it properly.",
"$",
"entity",
"->",
"setAccess",
"(",
"'_joinData'",
",",
"true",
")",
";",
"$",
"joinData",
"=",
"$",
"entity",
"->",
"get",
"(",
"'_joinData'",
")",
";",
"if",
"(",
"$",
"joinData",
"&&",
"$",
"joinData",
"instanceof",
"EntityInterface",
")",
"{",
"$",
"extra",
"[",
"spl_object_hash",
"(",
"$",
"entity",
")",
"]",
"=",
"$",
"joinData",
";",
"}",
"}",
"$",
"joint",
"=",
"$",
"assoc",
"->",
"junction",
"(",
")",
";",
"$",
"marshaller",
"=",
"$",
"joint",
"->",
"marshaller",
"(",
")",
";",
"$",
"nested",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"associated",
"[",
"'_joinData'",
"]",
")",
")",
"{",
"$",
"nested",
"=",
"(",
"array",
")",
"$",
"associated",
"[",
"'_joinData'",
"]",
";",
"}",
"$",
"options",
"[",
"'accessibleFields'",
"]",
"=",
"[",
"'_joinData'",
"=>",
"true",
"]",
";",
"$",
"records",
"=",
"$",
"this",
"->",
"mergeMany",
"(",
"$",
"original",
",",
"$",
"value",
",",
"$",
"options",
")",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"record",
")",
"{",
"$",
"hash",
"=",
"spl_object_hash",
"(",
"$",
"record",
")",
";",
"$",
"value",
"=",
"$",
"record",
"->",
"get",
"(",
"'_joinData'",
")",
";",
"// Already an entity, no further marshalling required.",
"if",
"(",
"$",
"value",
"instanceof",
"EntityInterface",
")",
"{",
"continue",
";",
"}",
"// Scalar data can't be handled",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"record",
"->",
"unsetProperty",
"(",
"'_joinData'",
")",
";",
"continue",
";",
"}",
"// Marshal data into the old object, or make a new joinData object.",
"if",
"(",
"isset",
"(",
"$",
"extra",
"[",
"$",
"hash",
"]",
")",
")",
"{",
"$",
"record",
"->",
"set",
"(",
"'_joinData'",
",",
"$",
"marshaller",
"->",
"merge",
"(",
"$",
"extra",
"[",
"$",
"hash",
"]",
",",
"$",
"value",
",",
"$",
"nested",
")",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"joinData",
"=",
"$",
"marshaller",
"->",
"one",
"(",
"$",
"value",
",",
"$",
"nested",
")",
";",
"$",
"record",
"->",
"set",
"(",
"'_joinData'",
",",
"$",
"joinData",
")",
";",
"}",
"}",
"return",
"$",
"records",
";",
"}"
] | Merge the special _joinData property into the entity set.
@param \Cake\Datasource\EntityInterface $original The original entity
@param \Cake\ORM\Association\BelongsToMany $assoc The association to marshall
@param array $value The data to hydrate
@param array $options List of options.
@return \Cake\Datasource\EntityInterface[] An array of entities | [
"Merge",
"the",
"special",
"_joinData",
"property",
"into",
"the",
"entity",
"set",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Marshaller.php#L811-L861 |
210,508 | cakephp/cakephp | src/Core/ConventionsTrait.php | ConventionsTrait._modelKey | protected function _modelKey($name)
{
list(, $name) = pluginSplit($name);
return Inflector::underscore(Inflector::singularize($name)) . '_id';
} | php | protected function _modelKey($name)
{
list(, $name) = pluginSplit($name);
return Inflector::underscore(Inflector::singularize($name)) . '_id';
} | [
"protected",
"function",
"_modelKey",
"(",
"$",
"name",
")",
"{",
"list",
"(",
",",
"$",
"name",
")",
"=",
"pluginSplit",
"(",
"$",
"name",
")",
";",
"return",
"Inflector",
"::",
"underscore",
"(",
"Inflector",
"::",
"singularize",
"(",
"$",
"name",
")",
")",
".",
"'_id'",
";",
"}"
] | Creates the proper underscored model key for associations
If the input contains a dot, assume that the right side is the real table name.
@param string $name Model class name
@return string Singular model key | [
"Creates",
"the",
"proper",
"underscored",
"model",
"key",
"for",
"associations"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/ConventionsTrait.php#L55-L60 |
210,509 | cakephp/cakephp | src/Core/ConventionsTrait.php | ConventionsTrait._modelNameFromKey | protected function _modelNameFromKey($key)
{
$key = str_replace('_id', '', $key);
return Inflector::camelize(Inflector::pluralize($key));
} | php | protected function _modelNameFromKey($key)
{
$key = str_replace('_id', '', $key);
return Inflector::camelize(Inflector::pluralize($key));
} | [
"protected",
"function",
"_modelNameFromKey",
"(",
"$",
"key",
")",
"{",
"$",
"key",
"=",
"str_replace",
"(",
"'_id'",
",",
"''",
",",
"$",
"key",
")",
";",
"return",
"Inflector",
"::",
"camelize",
"(",
"Inflector",
"::",
"pluralize",
"(",
"$",
"key",
")",
")",
";",
"}"
] | Creates the proper model name from a foreign key
@param string $key Foreign key
@return string Model name | [
"Creates",
"the",
"proper",
"model",
"name",
"from",
"a",
"foreign",
"key"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/ConventionsTrait.php#L68-L73 |
210,510 | cakephp/cakephp | src/Routing/RouteCollection.php | RouteCollection.parse | public function parse($url, $method = '')
{
$decoded = urldecode($url);
// Sort path segments matching longest paths first.
$paths = array_keys($this->_paths);
rsort($paths);
foreach ($paths as $path) {
if (strpos($decoded, $path) !== 0) {
continue;
}
$queryParameters = null;
if (strpos($url, '?') !== false) {
list($url, $queryParameters) = explode('?', $url, 2);
parse_str($queryParameters, $queryParameters);
}
/* @var \Cake\Routing\Route\Route $route */
foreach ($this->_paths[$path] as $route) {
$r = $route->parse($url, $method);
if ($r === false) {
continue;
}
if ($queryParameters) {
$r['?'] = $queryParameters;
}
return $r;
}
}
$exceptionProperties = ['url' => $url];
if ($method !== '') {
// Ensure that if the method is included, it is the first element of
// the array, to match the order that the strings are printed in the
// MissingRouteException error message, $_messageTemplateWithMethod.
$exceptionProperties = array_merge(['method' => $method], $exceptionProperties);
}
throw new MissingRouteException($exceptionProperties);
} | php | public function parse($url, $method = '')
{
$decoded = urldecode($url);
// Sort path segments matching longest paths first.
$paths = array_keys($this->_paths);
rsort($paths);
foreach ($paths as $path) {
if (strpos($decoded, $path) !== 0) {
continue;
}
$queryParameters = null;
if (strpos($url, '?') !== false) {
list($url, $queryParameters) = explode('?', $url, 2);
parse_str($queryParameters, $queryParameters);
}
/* @var \Cake\Routing\Route\Route $route */
foreach ($this->_paths[$path] as $route) {
$r = $route->parse($url, $method);
if ($r === false) {
continue;
}
if ($queryParameters) {
$r['?'] = $queryParameters;
}
return $r;
}
}
$exceptionProperties = ['url' => $url];
if ($method !== '') {
// Ensure that if the method is included, it is the first element of
// the array, to match the order that the strings are printed in the
// MissingRouteException error message, $_messageTemplateWithMethod.
$exceptionProperties = array_merge(['method' => $method], $exceptionProperties);
}
throw new MissingRouteException($exceptionProperties);
} | [
"public",
"function",
"parse",
"(",
"$",
"url",
",",
"$",
"method",
"=",
"''",
")",
"{",
"$",
"decoded",
"=",
"urldecode",
"(",
"$",
"url",
")",
";",
"// Sort path segments matching longest paths first.",
"$",
"paths",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"_paths",
")",
";",
"rsort",
"(",
"$",
"paths",
")",
";",
"foreach",
"(",
"$",
"paths",
"as",
"$",
"path",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"decoded",
",",
"$",
"path",
")",
"!==",
"0",
")",
"{",
"continue",
";",
"}",
"$",
"queryParameters",
"=",
"null",
";",
"if",
"(",
"strpos",
"(",
"$",
"url",
",",
"'?'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"url",
",",
"$",
"queryParameters",
")",
"=",
"explode",
"(",
"'?'",
",",
"$",
"url",
",",
"2",
")",
";",
"parse_str",
"(",
"$",
"queryParameters",
",",
"$",
"queryParameters",
")",
";",
"}",
"/* @var \\Cake\\Routing\\Route\\Route $route */",
"foreach",
"(",
"$",
"this",
"->",
"_paths",
"[",
"$",
"path",
"]",
"as",
"$",
"route",
")",
"{",
"$",
"r",
"=",
"$",
"route",
"->",
"parse",
"(",
"$",
"url",
",",
"$",
"method",
")",
";",
"if",
"(",
"$",
"r",
"===",
"false",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"queryParameters",
")",
"{",
"$",
"r",
"[",
"'?'",
"]",
"=",
"$",
"queryParameters",
";",
"}",
"return",
"$",
"r",
";",
"}",
"}",
"$",
"exceptionProperties",
"=",
"[",
"'url'",
"=>",
"$",
"url",
"]",
";",
"if",
"(",
"$",
"method",
"!==",
"''",
")",
"{",
"// Ensure that if the method is included, it is the first element of",
"// the array, to match the order that the strings are printed in the",
"// MissingRouteException error message, $_messageTemplateWithMethod.",
"$",
"exceptionProperties",
"=",
"array_merge",
"(",
"[",
"'method'",
"=>",
"$",
"method",
"]",
",",
"$",
"exceptionProperties",
")",
";",
"}",
"throw",
"new",
"MissingRouteException",
"(",
"$",
"exceptionProperties",
")",
";",
"}"
] | Takes the URL string and iterates the routes until one is able to parse the route.
@param string $url URL to parse.
@param string $method The HTTP method to use.
@return array An array of request parameters parsed from the URL.
@throws \Cake\Routing\Exception\MissingRouteException When a URL has no matching route. | [
"Takes",
"the",
"URL",
"string",
"and",
"iterates",
"the",
"routes",
"until",
"one",
"is",
"able",
"to",
"parse",
"the",
"route",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/RouteCollection.php#L140-L180 |
210,511 | cakephp/cakephp | src/Routing/RouteCollection.php | RouteCollection.parseRequest | public function parseRequest(ServerRequestInterface $request)
{
$uri = $request->getUri();
$urlPath = urldecode($uri->getPath());
// Sort path segments matching longest paths first.
$paths = array_keys($this->_paths);
rsort($paths);
foreach ($paths as $path) {
if (strpos($urlPath, $path) !== 0) {
continue;
}
/* @var \Cake\Routing\Route\Route $route */
foreach ($this->_paths[$path] as $route) {
$r = $route->parseRequest($request);
if ($r === false) {
continue;
}
if ($uri->getQuery()) {
parse_str($uri->getQuery(), $queryParameters);
$r['?'] = $queryParameters;
}
return $r;
}
}
throw new MissingRouteException(['url' => $urlPath]);
} | php | public function parseRequest(ServerRequestInterface $request)
{
$uri = $request->getUri();
$urlPath = urldecode($uri->getPath());
// Sort path segments matching longest paths first.
$paths = array_keys($this->_paths);
rsort($paths);
foreach ($paths as $path) {
if (strpos($urlPath, $path) !== 0) {
continue;
}
/* @var \Cake\Routing\Route\Route $route */
foreach ($this->_paths[$path] as $route) {
$r = $route->parseRequest($request);
if ($r === false) {
continue;
}
if ($uri->getQuery()) {
parse_str($uri->getQuery(), $queryParameters);
$r['?'] = $queryParameters;
}
return $r;
}
}
throw new MissingRouteException(['url' => $urlPath]);
} | [
"public",
"function",
"parseRequest",
"(",
"ServerRequestInterface",
"$",
"request",
")",
"{",
"$",
"uri",
"=",
"$",
"request",
"->",
"getUri",
"(",
")",
";",
"$",
"urlPath",
"=",
"urldecode",
"(",
"$",
"uri",
"->",
"getPath",
"(",
")",
")",
";",
"// Sort path segments matching longest paths first.",
"$",
"paths",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"_paths",
")",
";",
"rsort",
"(",
"$",
"paths",
")",
";",
"foreach",
"(",
"$",
"paths",
"as",
"$",
"path",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"urlPath",
",",
"$",
"path",
")",
"!==",
"0",
")",
"{",
"continue",
";",
"}",
"/* @var \\Cake\\Routing\\Route\\Route $route */",
"foreach",
"(",
"$",
"this",
"->",
"_paths",
"[",
"$",
"path",
"]",
"as",
"$",
"route",
")",
"{",
"$",
"r",
"=",
"$",
"route",
"->",
"parseRequest",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"r",
"===",
"false",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"uri",
"->",
"getQuery",
"(",
")",
")",
"{",
"parse_str",
"(",
"$",
"uri",
"->",
"getQuery",
"(",
")",
",",
"$",
"queryParameters",
")",
";",
"$",
"r",
"[",
"'?'",
"]",
"=",
"$",
"queryParameters",
";",
"}",
"return",
"$",
"r",
";",
"}",
"}",
"throw",
"new",
"MissingRouteException",
"(",
"[",
"'url'",
"=>",
"$",
"urlPath",
"]",
")",
";",
"}"
] | Takes the ServerRequestInterface, iterates the routes until one is able to parse the route.
@param \Psr\Http\Message\ServerRequestInterface $request The request to parse route data from.
@return array An array of request parameters parsed from the URL.
@throws \Cake\Routing\Exception\MissingRouteException When a URL has no matching route. | [
"Takes",
"the",
"ServerRequestInterface",
"iterates",
"the",
"routes",
"until",
"one",
"is",
"able",
"to",
"parse",
"the",
"route",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/RouteCollection.php#L189-L218 |
210,512 | cakephp/cakephp | src/Routing/RouteCollection.php | RouteCollection.setExtensions | public function setExtensions(array $extensions, $merge = true)
{
if ($merge) {
$extensions = array_unique(array_merge(
$this->_extensions,
$extensions
));
}
$this->_extensions = $extensions;
return $this;
} | php | public function setExtensions(array $extensions, $merge = true)
{
if ($merge) {
$extensions = array_unique(array_merge(
$this->_extensions,
$extensions
));
}
$this->_extensions = $extensions;
return $this;
} | [
"public",
"function",
"setExtensions",
"(",
"array",
"$",
"extensions",
",",
"$",
"merge",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"merge",
")",
"{",
"$",
"extensions",
"=",
"array_unique",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"_extensions",
",",
"$",
"extensions",
")",
")",
";",
"}",
"$",
"this",
"->",
"_extensions",
"=",
"$",
"extensions",
";",
"return",
"$",
"this",
";",
"}"
] | Set the extensions that the route collection can handle.
@param array $extensions The list of extensions to set.
@param bool $merge Whether to merge with or override existing extensions.
Defaults to `true`.
@return $this | [
"Set",
"the",
"extensions",
"that",
"the",
"route",
"collection",
"can",
"handle",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/RouteCollection.php#L411-L422 |
210,513 | cakephp/cakephp | src/Routing/RouteCollection.php | RouteCollection.middlewareGroup | public function middlewareGroup($name, array $middlewareNames)
{
if ($this->hasMiddleware($name)) {
$message = "Cannot add middleware group '$name'. A middleware by this name has already been registered.";
throw new RuntimeException($message);
}
foreach ($middlewareNames as $middlewareName) {
if (!$this->hasMiddleware($middlewareName)) {
$message = "Cannot add '$middlewareName' middleware to group '$name'. It has not been registered.";
throw new RuntimeException($message);
}
}
$this->_middlewareGroups[$name] = $middlewareNames;
return $this;
} | php | public function middlewareGroup($name, array $middlewareNames)
{
if ($this->hasMiddleware($name)) {
$message = "Cannot add middleware group '$name'. A middleware by this name has already been registered.";
throw new RuntimeException($message);
}
foreach ($middlewareNames as $middlewareName) {
if (!$this->hasMiddleware($middlewareName)) {
$message = "Cannot add '$middlewareName' middleware to group '$name'. It has not been registered.";
throw new RuntimeException($message);
}
}
$this->_middlewareGroups[$name] = $middlewareNames;
return $this;
} | [
"public",
"function",
"middlewareGroup",
"(",
"$",
"name",
",",
"array",
"$",
"middlewareNames",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasMiddleware",
"(",
"$",
"name",
")",
")",
"{",
"$",
"message",
"=",
"\"Cannot add middleware group '$name'. A middleware by this name has already been registered.\"",
";",
"throw",
"new",
"RuntimeException",
"(",
"$",
"message",
")",
";",
"}",
"foreach",
"(",
"$",
"middlewareNames",
"as",
"$",
"middlewareName",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasMiddleware",
"(",
"$",
"middlewareName",
")",
")",
"{",
"$",
"message",
"=",
"\"Cannot add '$middlewareName' middleware to group '$name'. It has not been registered.\"",
";",
"throw",
"new",
"RuntimeException",
"(",
"$",
"message",
")",
";",
"}",
"}",
"$",
"this",
"->",
"_middlewareGroups",
"[",
"$",
"name",
"]",
"=",
"$",
"middlewareNames",
";",
"return",
"$",
"this",
";",
"}"
] | Add middleware to a middleware group
@param string $name Name of the middleware group
@param array $middlewareNames Names of the middleware
@return $this | [
"Add",
"middleware",
"to",
"a",
"middleware",
"group"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/RouteCollection.php#L448-L465 |
210,514 | cakephp/cakephp | src/Routing/RouteCollection.php | RouteCollection.getMiddleware | public function getMiddleware(array $names)
{
$out = [];
foreach ($names as $name) {
if ($this->hasMiddlewareGroup($name)) {
$out = array_merge($out, $this->getMiddleware($this->_middlewareGroups[$name]));
continue;
}
if (!$this->hasMiddleware($name)) {
$message = "The middleware named '$name' has not been registered. Use registerMiddleware() to define it.";
throw new RuntimeException($message);
}
$out[] = $this->_middleware[$name];
}
return $out;
} | php | public function getMiddleware(array $names)
{
$out = [];
foreach ($names as $name) {
if ($this->hasMiddlewareGroup($name)) {
$out = array_merge($out, $this->getMiddleware($this->_middlewareGroups[$name]));
continue;
}
if (!$this->hasMiddleware($name)) {
$message = "The middleware named '$name' has not been registered. Use registerMiddleware() to define it.";
throw new RuntimeException($message);
}
$out[] = $this->_middleware[$name];
}
return $out;
} | [
"public",
"function",
"getMiddleware",
"(",
"array",
"$",
"names",
")",
"{",
"$",
"out",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"names",
"as",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasMiddlewareGroup",
"(",
"$",
"name",
")",
")",
"{",
"$",
"out",
"=",
"array_merge",
"(",
"$",
"out",
",",
"$",
"this",
"->",
"getMiddleware",
"(",
"$",
"this",
"->",
"_middlewareGroups",
"[",
"$",
"name",
"]",
")",
")",
";",
"continue",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"hasMiddleware",
"(",
"$",
"name",
")",
")",
"{",
"$",
"message",
"=",
"\"The middleware named '$name' has not been registered. Use registerMiddleware() to define it.\"",
";",
"throw",
"new",
"RuntimeException",
"(",
"$",
"message",
")",
";",
"}",
"$",
"out",
"[",
"]",
"=",
"$",
"this",
"->",
"_middleware",
"[",
"$",
"name",
"]",
";",
"}",
"return",
"$",
"out",
";",
"}"
] | Get an array of middleware given a list of names
@param array $names The names of the middleware or groups to fetch
@return array An array of middleware. If any of the passed names are groups,
the groups middleware will be flattened into the returned list.
@throws \RuntimeException when a requested middleware does not exist. | [
"Get",
"an",
"array",
"of",
"middleware",
"given",
"a",
"list",
"of",
"names"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/RouteCollection.php#L535-L551 |
210,515 | cakephp/cakephp | src/Routing/Router.php | Router.connect | public static function connect($route, $defaults = [], $options = [])
{
static::$initialized = true;
static::scope('/', function ($routes) use ($route, $defaults, $options) {
/** @var \Cake\Routing\RouteBuilder $routes */
$routes->connect($route, $defaults, $options);
});
} | php | public static function connect($route, $defaults = [], $options = [])
{
static::$initialized = true;
static::scope('/', function ($routes) use ($route, $defaults, $options) {
/** @var \Cake\Routing\RouteBuilder $routes */
$routes->connect($route, $defaults, $options);
});
} | [
"public",
"static",
"function",
"connect",
"(",
"$",
"route",
",",
"$",
"defaults",
"=",
"[",
"]",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"static",
"::",
"$",
"initialized",
"=",
"true",
";",
"static",
"::",
"scope",
"(",
"'/'",
",",
"function",
"(",
"$",
"routes",
")",
"use",
"(",
"$",
"route",
",",
"$",
"defaults",
",",
"$",
"options",
")",
"{",
"/** @var \\Cake\\Routing\\RouteBuilder $routes */",
"$",
"routes",
"->",
"connect",
"(",
"$",
"route",
",",
"$",
"defaults",
",",
"$",
"options",
")",
";",
"}",
")",
";",
"}"
] | Connects a new Route in the router.
Compatibility proxy to \Cake\Routing\RouteBuilder::connect() in the `/` scope.
@param string $route A string describing the template of the route
@param array|string $defaults An array describing the default route parameters. These parameters will be used by default
and can supply routing parameters that are not dynamic. See above.
@param array $options An array matching the named elements in the route to regular expressions which that
element should match. Also contains additional parameters such as which routed parameters should be
shifted into the passed arguments, supplying patterns for routing parameters and supplying the name of a
custom routing class.
@return void
@throws \Cake\Core\Exception\Exception
@see \Cake\Routing\RouteBuilder::connect()
@see \Cake\Routing\Router::scope() | [
"Connects",
"a",
"new",
"Route",
"in",
"the",
"router",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Router.php#L210-L217 |
210,516 | cakephp/cakephp | src/Routing/Router.php | Router.parse | public static function parse($url, $method = '')
{
deprecationWarning(
'Router::parse() is deprecated. ' .
'Use Router::parseRequest() instead. This will require adopting the Http\Server library.'
);
if (!static::$initialized) {
static::_loadRoutes();
}
if (strpos($url, '/') !== 0) {
$url = '/' . $url;
}
return static::$_collection->parse($url, $method);
} | php | public static function parse($url, $method = '')
{
deprecationWarning(
'Router::parse() is deprecated. ' .
'Use Router::parseRequest() instead. This will require adopting the Http\Server library.'
);
if (!static::$initialized) {
static::_loadRoutes();
}
if (strpos($url, '/') !== 0) {
$url = '/' . $url;
}
return static::$_collection->parse($url, $method);
} | [
"public",
"static",
"function",
"parse",
"(",
"$",
"url",
",",
"$",
"method",
"=",
"''",
")",
"{",
"deprecationWarning",
"(",
"'Router::parse() is deprecated. '",
".",
"'Use Router::parseRequest() instead. This will require adopting the Http\\Server library.'",
")",
";",
"if",
"(",
"!",
"static",
"::",
"$",
"initialized",
")",
"{",
"static",
"::",
"_loadRoutes",
"(",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"url",
",",
"'/'",
")",
"!==",
"0",
")",
"{",
"$",
"url",
"=",
"'/'",
".",
"$",
"url",
";",
"}",
"return",
"static",
"::",
"$",
"_collection",
"->",
"parse",
"(",
"$",
"url",
",",
"$",
"method",
")",
";",
"}"
] | Parses given URL string. Returns 'routing' parameters for that URL.
@param string $url URL to be parsed.
@param string $method The HTTP method being used.
@return array Parsed elements from URL.
@throws \Cake\Routing\Exception\MissingRouteException When a route cannot be handled
@deprecated 3.4.0 Use Router::parseRequest() instead. | [
"Parses",
"given",
"URL",
"string",
".",
"Returns",
"routing",
"parameters",
"for",
"that",
"URL",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Router.php#L361-L375 |
210,517 | cakephp/cakephp | src/Routing/Router.php | Router.setRequestInfo | public static function setRequestInfo($request)
{
if ($request instanceof ServerRequest) {
static::pushRequest($request);
} else {
deprecationWarning(
'Passing an array into Router::setRequestInfo() is deprecated. ' .
'Pass an instance of ServerRequest instead.'
);
$requestData = $request;
$requestData += [[], []];
$requestData[0] += [
'controller' => false,
'action' => false,
'plugin' => null
];
$request = new ServerRequest([
'params' => $requestData[0],
'url' => isset($requestData[1]['here']) ? $requestData[1]['here'] : '/',
'base' => isset($requestData[1]['base']) ? $requestData[1]['base'] : '',
'webroot' => isset($requestData[1]['webroot']) ? $requestData[1]['webroot'] : '/',
]);
static::pushRequest($request);
}
} | php | public static function setRequestInfo($request)
{
if ($request instanceof ServerRequest) {
static::pushRequest($request);
} else {
deprecationWarning(
'Passing an array into Router::setRequestInfo() is deprecated. ' .
'Pass an instance of ServerRequest instead.'
);
$requestData = $request;
$requestData += [[], []];
$requestData[0] += [
'controller' => false,
'action' => false,
'plugin' => null
];
$request = new ServerRequest([
'params' => $requestData[0],
'url' => isset($requestData[1]['here']) ? $requestData[1]['here'] : '/',
'base' => isset($requestData[1]['base']) ? $requestData[1]['base'] : '',
'webroot' => isset($requestData[1]['webroot']) ? $requestData[1]['webroot'] : '/',
]);
static::pushRequest($request);
}
} | [
"public",
"static",
"function",
"setRequestInfo",
"(",
"$",
"request",
")",
"{",
"if",
"(",
"$",
"request",
"instanceof",
"ServerRequest",
")",
"{",
"static",
"::",
"pushRequest",
"(",
"$",
"request",
")",
";",
"}",
"else",
"{",
"deprecationWarning",
"(",
"'Passing an array into Router::setRequestInfo() is deprecated. '",
".",
"'Pass an instance of ServerRequest instead.'",
")",
";",
"$",
"requestData",
"=",
"$",
"request",
";",
"$",
"requestData",
"+=",
"[",
"[",
"]",
",",
"[",
"]",
"]",
";",
"$",
"requestData",
"[",
"0",
"]",
"+=",
"[",
"'controller'",
"=>",
"false",
",",
"'action'",
"=>",
"false",
",",
"'plugin'",
"=>",
"null",
"]",
";",
"$",
"request",
"=",
"new",
"ServerRequest",
"(",
"[",
"'params'",
"=>",
"$",
"requestData",
"[",
"0",
"]",
",",
"'url'",
"=>",
"isset",
"(",
"$",
"requestData",
"[",
"1",
"]",
"[",
"'here'",
"]",
")",
"?",
"$",
"requestData",
"[",
"1",
"]",
"[",
"'here'",
"]",
":",
"'/'",
",",
"'base'",
"=>",
"isset",
"(",
"$",
"requestData",
"[",
"1",
"]",
"[",
"'base'",
"]",
")",
"?",
"$",
"requestData",
"[",
"1",
"]",
"[",
"'base'",
"]",
":",
"''",
",",
"'webroot'",
"=>",
"isset",
"(",
"$",
"requestData",
"[",
"1",
"]",
"[",
"'webroot'",
"]",
")",
"?",
"$",
"requestData",
"[",
"1",
"]",
"[",
"'webroot'",
"]",
":",
"'/'",
",",
"]",
")",
";",
"static",
"::",
"pushRequest",
"(",
"$",
"request",
")",
";",
"}",
"}"
] | Takes parameter and path information back from the Dispatcher, sets these
parameters as the current request parameters that are merged with URL arrays
created later in the request.
Nested requests will create a stack of requests. You can remove requests using
Router::popRequest(). This is done automatically when using Object::requestAction().
Will accept either a Cake\Http\ServerRequest object or an array of arrays. Support for
accepting arrays may be removed in the future.
@param \Cake\Http\ServerRequest|array $request Parameters and path information or a Cake\Http\ServerRequest object.
@return void
@deprecatd 3.6.0 Support for arrays will be removed in 4.0.0 | [
"Takes",
"parameter",
"and",
"path",
"information",
"back",
"from",
"the",
"Dispatcher",
"sets",
"these",
"parameters",
"as",
"the",
"current",
"request",
"parameters",
"that",
"are",
"merged",
"with",
"URL",
"arrays",
"created",
"later",
"in",
"the",
"request",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Router.php#L408-L433 |
210,518 | cakephp/cakephp | src/Routing/Router.php | Router.setRequestContext | public static function setRequestContext(ServerRequestInterface $request)
{
$uri = $request->getUri();
static::$_requestContext = [
'_base' => $request->getAttribute('base'),
'_port' => $uri->getPort(),
'_scheme' => $uri->getScheme(),
'_host' => $uri->getHost(),
];
} | php | public static function setRequestContext(ServerRequestInterface $request)
{
$uri = $request->getUri();
static::$_requestContext = [
'_base' => $request->getAttribute('base'),
'_port' => $uri->getPort(),
'_scheme' => $uri->getScheme(),
'_host' => $uri->getHost(),
];
} | [
"public",
"static",
"function",
"setRequestContext",
"(",
"ServerRequestInterface",
"$",
"request",
")",
"{",
"$",
"uri",
"=",
"$",
"request",
"->",
"getUri",
"(",
")",
";",
"static",
"::",
"$",
"_requestContext",
"=",
"[",
"'_base'",
"=>",
"$",
"request",
"->",
"getAttribute",
"(",
"'base'",
")",
",",
"'_port'",
"=>",
"$",
"uri",
"->",
"getPort",
"(",
")",
",",
"'_scheme'",
"=>",
"$",
"uri",
"->",
"getScheme",
"(",
")",
",",
"'_host'",
"=>",
"$",
"uri",
"->",
"getHost",
"(",
")",
",",
"]",
";",
"}"
] | Store the request context for a given request.
@param \Psr\Http\Message\ServerRequestInterface $request The request instance.
@return void
@throws \InvalidArgumentException When parameter is an incorrect type. | [
"Store",
"the",
"request",
"context",
"for",
"a",
"given",
"request",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Router.php#L455-L464 |
210,519 | cakephp/cakephp | src/Routing/Router.php | Router.popRequest | public static function popRequest()
{
$removed = array_pop(static::$_requests);
$last = end(static::$_requests);
if ($last) {
static::setRequestContext($last);
reset(static::$_requests);
}
return $removed;
} | php | public static function popRequest()
{
$removed = array_pop(static::$_requests);
$last = end(static::$_requests);
if ($last) {
static::setRequestContext($last);
reset(static::$_requests);
}
return $removed;
} | [
"public",
"static",
"function",
"popRequest",
"(",
")",
"{",
"$",
"removed",
"=",
"array_pop",
"(",
"static",
"::",
"$",
"_requests",
")",
";",
"$",
"last",
"=",
"end",
"(",
"static",
"::",
"$",
"_requests",
")",
";",
"if",
"(",
"$",
"last",
")",
"{",
"static",
"::",
"setRequestContext",
"(",
"$",
"last",
")",
";",
"reset",
"(",
"static",
"::",
"$",
"_requests",
")",
";",
"}",
"return",
"$",
"removed",
";",
"}"
] | Pops a request off of the request stack. Used when doing requestAction
@return \Cake\Http\ServerRequest The request removed from the stack.
@see \Cake\Routing\Router::pushRequest()
@see \Cake\Routing\RequestActionTrait::requestAction() | [
"Pops",
"a",
"request",
"off",
"of",
"the",
"request",
"stack",
".",
"Used",
"when",
"doing",
"requestAction"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Router.php#L473-L483 |
210,520 | cakephp/cakephp | src/Routing/Router.php | Router.getRequest | public static function getRequest($current = false)
{
if ($current) {
$request = end(static::$_requests);
return $request ?: null;
}
return isset(static::$_requests[0]) ? static::$_requests[0] : null;
} | php | public static function getRequest($current = false)
{
if ($current) {
$request = end(static::$_requests);
return $request ?: null;
}
return isset(static::$_requests[0]) ? static::$_requests[0] : null;
} | [
"public",
"static",
"function",
"getRequest",
"(",
"$",
"current",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"current",
")",
"{",
"$",
"request",
"=",
"end",
"(",
"static",
"::",
"$",
"_requests",
")",
";",
"return",
"$",
"request",
"?",
":",
"null",
";",
"}",
"return",
"isset",
"(",
"static",
"::",
"$",
"_requests",
"[",
"0",
"]",
")",
"?",
"static",
"::",
"$",
"_requests",
"[",
"0",
"]",
":",
"null",
";",
"}"
] | Get the current request object, or the first one.
@param bool $current True to get the current request, or false to get the first one.
@return \Cake\Http\ServerRequest|null | [
"Get",
"the",
"current",
"request",
"object",
"or",
"the",
"first",
"one",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Router.php#L491-L500 |
210,521 | cakephp/cakephp | src/Routing/Router.php | Router.reload | public static function reload()
{
if (empty(static::$_initialState)) {
static::$_collection = new RouteCollection();
static::$_initialState = get_class_vars(get_called_class());
return;
}
foreach (static::$_initialState as $key => $val) {
if ($key !== '_initialState') {
static::${$key} = $val;
}
}
static::$_collection = new RouteCollection();
} | php | public static function reload()
{
if (empty(static::$_initialState)) {
static::$_collection = new RouteCollection();
static::$_initialState = get_class_vars(get_called_class());
return;
}
foreach (static::$_initialState as $key => $val) {
if ($key !== '_initialState') {
static::${$key} = $val;
}
}
static::$_collection = new RouteCollection();
} | [
"public",
"static",
"function",
"reload",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"static",
"::",
"$",
"_initialState",
")",
")",
"{",
"static",
"::",
"$",
"_collection",
"=",
"new",
"RouteCollection",
"(",
")",
";",
"static",
"::",
"$",
"_initialState",
"=",
"get_class_vars",
"(",
"get_called_class",
"(",
")",
")",
";",
"return",
";",
"}",
"foreach",
"(",
"static",
"::",
"$",
"_initialState",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"key",
"!==",
"'_initialState'",
")",
"{",
"static",
"::",
"$",
"{",
"$",
"key",
"}",
"=",
"$",
"val",
";",
"}",
"}",
"static",
"::",
"$",
"_collection",
"=",
"new",
"RouteCollection",
"(",
")",
";",
"}"
] | Reloads default Router settings. Resets all class variables and
removes all connected routes.
@return void | [
"Reloads",
"default",
"Router",
"settings",
".",
"Resets",
"all",
"class",
"variables",
"and",
"removes",
"all",
"connected",
"routes",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Router.php#L508-L522 |
210,522 | cakephp/cakephp | src/Routing/Router.php | Router._applyUrlFilters | protected static function _applyUrlFilters($url)
{
$request = static::getRequest(true);
$e = null;
foreach (static::$_urlFilters as $filter) {
try {
$url = $filter($url, $request);
} catch (Exception $e) {
// fall through
} catch (Throwable $e) {
// fall through
}
if ($e !== null) {
if (is_array($filter)) {
$ref = new ReflectionMethod($filter[0], $filter[1]);
} else {
$ref = new ReflectionFunction($filter);
}
$message = sprintf(
'URL filter defined in %s on line %s could not be applied. The filter failed with: %s',
$ref->getFileName(),
$ref->getStartLine(),
$e->getMessage()
);
throw new RuntimeException($message, $e->getCode(), $e);
}
}
return $url;
} | php | protected static function _applyUrlFilters($url)
{
$request = static::getRequest(true);
$e = null;
foreach (static::$_urlFilters as $filter) {
try {
$url = $filter($url, $request);
} catch (Exception $e) {
// fall through
} catch (Throwable $e) {
// fall through
}
if ($e !== null) {
if (is_array($filter)) {
$ref = new ReflectionMethod($filter[0], $filter[1]);
} else {
$ref = new ReflectionFunction($filter);
}
$message = sprintf(
'URL filter defined in %s on line %s could not be applied. The filter failed with: %s',
$ref->getFileName(),
$ref->getStartLine(),
$e->getMessage()
);
throw new RuntimeException($message, $e->getCode(), $e);
}
}
return $url;
} | [
"protected",
"static",
"function",
"_applyUrlFilters",
"(",
"$",
"url",
")",
"{",
"$",
"request",
"=",
"static",
"::",
"getRequest",
"(",
"true",
")",
";",
"$",
"e",
"=",
"null",
";",
"foreach",
"(",
"static",
"::",
"$",
"_urlFilters",
"as",
"$",
"filter",
")",
"{",
"try",
"{",
"$",
"url",
"=",
"$",
"filter",
"(",
"$",
"url",
",",
"$",
"request",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"// fall through",
"}",
"catch",
"(",
"Throwable",
"$",
"e",
")",
"{",
"// fall through",
"}",
"if",
"(",
"$",
"e",
"!==",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"filter",
")",
")",
"{",
"$",
"ref",
"=",
"new",
"ReflectionMethod",
"(",
"$",
"filter",
"[",
"0",
"]",
",",
"$",
"filter",
"[",
"1",
"]",
")",
";",
"}",
"else",
"{",
"$",
"ref",
"=",
"new",
"ReflectionFunction",
"(",
"$",
"filter",
")",
";",
"}",
"$",
"message",
"=",
"sprintf",
"(",
"'URL filter defined in %s on line %s could not be applied. The filter failed with: %s'",
",",
"$",
"ref",
"->",
"getFileName",
"(",
")",
",",
"$",
"ref",
"->",
"getStartLine",
"(",
")",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"throw",
"new",
"RuntimeException",
"(",
"$",
"message",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
";",
"}",
"}",
"return",
"$",
"url",
";",
"}"
] | Applies all the connected URL filters to the URL.
@param array $url The URL array being modified.
@return array The modified URL.
@see \Cake\Routing\Router::url()
@see \Cake\Routing\Router::addUrlFilter() | [
"Applies",
"all",
"the",
"connected",
"URL",
"filters",
"to",
"the",
"URL",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Router.php#L590-L619 |
210,523 | cakephp/cakephp | src/Routing/Router.php | Router.fullBaseUrl | public static function fullBaseUrl($base = null)
{
if ($base !== null) {
static::$_fullBaseUrl = $base;
Configure::write('App.fullBaseUrl', $base);
}
if (empty(static::$_fullBaseUrl)) {
static::$_fullBaseUrl = Configure::read('App.fullBaseUrl');
}
return static::$_fullBaseUrl;
} | php | public static function fullBaseUrl($base = null)
{
if ($base !== null) {
static::$_fullBaseUrl = $base;
Configure::write('App.fullBaseUrl', $base);
}
if (empty(static::$_fullBaseUrl)) {
static::$_fullBaseUrl = Configure::read('App.fullBaseUrl');
}
return static::$_fullBaseUrl;
} | [
"public",
"static",
"function",
"fullBaseUrl",
"(",
"$",
"base",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"base",
"!==",
"null",
")",
"{",
"static",
"::",
"$",
"_fullBaseUrl",
"=",
"$",
"base",
";",
"Configure",
"::",
"write",
"(",
"'App.fullBaseUrl'",
",",
"$",
"base",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"static",
"::",
"$",
"_fullBaseUrl",
")",
")",
"{",
"static",
"::",
"$",
"_fullBaseUrl",
"=",
"Configure",
"::",
"read",
"(",
"'App.fullBaseUrl'",
")",
";",
"}",
"return",
"static",
"::",
"$",
"_fullBaseUrl",
";",
"}"
] | Sets the full base URL that will be used as a prefix for generating
fully qualified URLs for this application. If no parameters are passed,
the currently configured value is returned.
### Note:
If you change the configuration value `App.fullBaseUrl` during runtime
and expect the router to produce links using the new setting, you are
required to call this method passing such value again.
@param string|null $base the prefix for URLs generated containing the domain.
For example: `http://example.com`
@return string | [
"Sets",
"the",
"full",
"base",
"URL",
"that",
"will",
"be",
"used",
"as",
"a",
"prefix",
"for",
"generating",
"fully",
"qualified",
"URLs",
"for",
"this",
"application",
".",
"If",
"no",
"parameters",
"are",
"passed",
"the",
"currently",
"configured",
"value",
"is",
"returned",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Router.php#L807-L818 |
210,524 | cakephp/cakephp | src/Routing/Router.php | Router.reverseToArray | public static function reverseToArray($params)
{
$url = [];
if ($params instanceof ServerRequest) {
$url = $params->getQueryParams();
$params = $params->getAttribute('params');
} elseif (isset($params['url'])) {
$url = $params['url'];
}
$pass = isset($params['pass']) ? $params['pass'] : [];
unset(
$params['pass'],
$params['paging'],
$params['models'],
$params['url'],
$url['url'],
$params['autoRender'],
$params['bare'],
$params['requested'],
$params['return'],
$params['_Token'],
$params['_matchedRoute'],
$params['_name']
);
$params = array_merge($params, $pass);
if (!empty($url)) {
$params['?'] = $url;
}
return $params;
} | php | public static function reverseToArray($params)
{
$url = [];
if ($params instanceof ServerRequest) {
$url = $params->getQueryParams();
$params = $params->getAttribute('params');
} elseif (isset($params['url'])) {
$url = $params['url'];
}
$pass = isset($params['pass']) ? $params['pass'] : [];
unset(
$params['pass'],
$params['paging'],
$params['models'],
$params['url'],
$url['url'],
$params['autoRender'],
$params['bare'],
$params['requested'],
$params['return'],
$params['_Token'],
$params['_matchedRoute'],
$params['_name']
);
$params = array_merge($params, $pass);
if (!empty($url)) {
$params['?'] = $url;
}
return $params;
} | [
"public",
"static",
"function",
"reverseToArray",
"(",
"$",
"params",
")",
"{",
"$",
"url",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"params",
"instanceof",
"ServerRequest",
")",
"{",
"$",
"url",
"=",
"$",
"params",
"->",
"getQueryParams",
"(",
")",
";",
"$",
"params",
"=",
"$",
"params",
"->",
"getAttribute",
"(",
"'params'",
")",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"params",
"[",
"'url'",
"]",
")",
")",
"{",
"$",
"url",
"=",
"$",
"params",
"[",
"'url'",
"]",
";",
"}",
"$",
"pass",
"=",
"isset",
"(",
"$",
"params",
"[",
"'pass'",
"]",
")",
"?",
"$",
"params",
"[",
"'pass'",
"]",
":",
"[",
"]",
";",
"unset",
"(",
"$",
"params",
"[",
"'pass'",
"]",
",",
"$",
"params",
"[",
"'paging'",
"]",
",",
"$",
"params",
"[",
"'models'",
"]",
",",
"$",
"params",
"[",
"'url'",
"]",
",",
"$",
"url",
"[",
"'url'",
"]",
",",
"$",
"params",
"[",
"'autoRender'",
"]",
",",
"$",
"params",
"[",
"'bare'",
"]",
",",
"$",
"params",
"[",
"'requested'",
"]",
",",
"$",
"params",
"[",
"'return'",
"]",
",",
"$",
"params",
"[",
"'_Token'",
"]",
",",
"$",
"params",
"[",
"'_matchedRoute'",
"]",
",",
"$",
"params",
"[",
"'_name'",
"]",
")",
";",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"params",
",",
"$",
"pass",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"url",
")",
")",
"{",
"$",
"params",
"[",
"'?'",
"]",
"=",
"$",
"url",
";",
"}",
"return",
"$",
"params",
";",
"}"
] | Reverses a parsed parameter array into an array.
Works similarly to Router::url(), but since parsed URL's contain additional
'pass' as well as 'url.url' keys. Those keys need to be specially
handled in order to reverse a params array into a string URL.
This will strip out 'autoRender', 'bare', 'requested', and 'return' param names as those
are used for CakePHP internals and should not normally be part of an output URL.
@param \Cake\Http\ServerRequest|array $params The params array or
Cake\Http\ServerRequest object that needs to be reversed.
@return array The URL array ready to be used for redirect or HTML link. | [
"Reverses",
"a",
"parsed",
"parameter",
"array",
"into",
"an",
"array",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Router.php#L834-L865 |
210,525 | cakephp/cakephp | src/Routing/Router.php | Router.reverse | public static function reverse($params, $full = false)
{
$params = static::reverseToArray($params);
return static::url($params, $full);
} | php | public static function reverse($params, $full = false)
{
$params = static::reverseToArray($params);
return static::url($params, $full);
} | [
"public",
"static",
"function",
"reverse",
"(",
"$",
"params",
",",
"$",
"full",
"=",
"false",
")",
"{",
"$",
"params",
"=",
"static",
"::",
"reverseToArray",
"(",
"$",
"params",
")",
";",
"return",
"static",
"::",
"url",
"(",
"$",
"params",
",",
"$",
"full",
")",
";",
"}"
] | Reverses a parsed parameter array into a string.
Works similarly to Router::url(), but since parsed URL's contain additional
'pass' as well as 'url.url' keys. Those keys need to be specially
handled in order to reverse a params array into a string URL.
This will strip out 'autoRender', 'bare', 'requested', and 'return' param names as those
are used for CakePHP internals and should not normally be part of an output URL.
@param \Cake\Http\ServerRequest|array $params The params array or
Cake\Http\ServerRequest object that needs to be reversed.
@param bool $full Set to true to include the full URL including the
protocol when reversing the URL.
@return string The string that is the reversed result of the array | [
"Reverses",
"a",
"parsed",
"parameter",
"array",
"into",
"a",
"string",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Router.php#L883-L888 |
210,526 | cakephp/cakephp | src/Routing/Router.php | Router.normalize | public static function normalize($url = '/')
{
if (is_array($url)) {
$url = static::url($url);
}
if (preg_match('/^[a-z\-]+:\/\//', $url)) {
return $url;
}
$request = static::getRequest();
if ($request) {
$base = $request->getAttribute('base');
if (strlen($base) && stristr($url, $base)) {
$url = preg_replace('/^' . preg_quote($base, '/') . '/', '', $url, 1);
}
}
$url = '/' . $url;
while (strpos($url, '//') !== false) {
$url = str_replace('//', '/', $url);
}
$url = preg_replace('/(?:(\/$))/', '', $url);
if (empty($url)) {
return '/';
}
return $url;
} | php | public static function normalize($url = '/')
{
if (is_array($url)) {
$url = static::url($url);
}
if (preg_match('/^[a-z\-]+:\/\//', $url)) {
return $url;
}
$request = static::getRequest();
if ($request) {
$base = $request->getAttribute('base');
if (strlen($base) && stristr($url, $base)) {
$url = preg_replace('/^' . preg_quote($base, '/') . '/', '', $url, 1);
}
}
$url = '/' . $url;
while (strpos($url, '//') !== false) {
$url = str_replace('//', '/', $url);
}
$url = preg_replace('/(?:(\/$))/', '', $url);
if (empty($url)) {
return '/';
}
return $url;
} | [
"public",
"static",
"function",
"normalize",
"(",
"$",
"url",
"=",
"'/'",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"url",
")",
")",
"{",
"$",
"url",
"=",
"static",
"::",
"url",
"(",
"$",
"url",
")",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'/^[a-z\\-]+:\\/\\//'",
",",
"$",
"url",
")",
")",
"{",
"return",
"$",
"url",
";",
"}",
"$",
"request",
"=",
"static",
"::",
"getRequest",
"(",
")",
";",
"if",
"(",
"$",
"request",
")",
"{",
"$",
"base",
"=",
"$",
"request",
"->",
"getAttribute",
"(",
"'base'",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"base",
")",
"&&",
"stristr",
"(",
"$",
"url",
",",
"$",
"base",
")",
")",
"{",
"$",
"url",
"=",
"preg_replace",
"(",
"'/^'",
".",
"preg_quote",
"(",
"$",
"base",
",",
"'/'",
")",
".",
"'/'",
",",
"''",
",",
"$",
"url",
",",
"1",
")",
";",
"}",
"}",
"$",
"url",
"=",
"'/'",
".",
"$",
"url",
";",
"while",
"(",
"strpos",
"(",
"$",
"url",
",",
"'//'",
")",
"!==",
"false",
")",
"{",
"$",
"url",
"=",
"str_replace",
"(",
"'//'",
",",
"'/'",
",",
"$",
"url",
")",
";",
"}",
"$",
"url",
"=",
"preg_replace",
"(",
"'/(?:(\\/$))/'",
",",
"''",
",",
"$",
"url",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"url",
")",
")",
"{",
"return",
"'/'",
";",
"}",
"return",
"$",
"url",
";",
"}"
] | Normalizes a URL for purposes of comparison.
Will strip the base path off and replace any double /'s.
It will not unify the casing and underscoring of the input value.
@param array|string $url URL to normalize Either an array or a string URL.
@return string Normalized URL | [
"Normalizes",
"a",
"URL",
"for",
"purposes",
"of",
"comparison",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Router.php#L899-L927 |
210,527 | cakephp/cakephp | src/Routing/Router.php | Router.extensions | public static function extensions($extensions = null, $merge = true)
{
$collection = static::$_collection;
if ($extensions === null) {
if (!static::$initialized) {
static::_loadRoutes();
}
return array_unique(array_merge(static::$_defaultExtensions, $collection->getExtensions()));
}
$extensions = (array)$extensions;
if ($merge) {
$extensions = array_unique(array_merge(static::$_defaultExtensions, $extensions));
}
return static::$_defaultExtensions = $extensions;
} | php | public static function extensions($extensions = null, $merge = true)
{
$collection = static::$_collection;
if ($extensions === null) {
if (!static::$initialized) {
static::_loadRoutes();
}
return array_unique(array_merge(static::$_defaultExtensions, $collection->getExtensions()));
}
$extensions = (array)$extensions;
if ($merge) {
$extensions = array_unique(array_merge(static::$_defaultExtensions, $extensions));
}
return static::$_defaultExtensions = $extensions;
} | [
"public",
"static",
"function",
"extensions",
"(",
"$",
"extensions",
"=",
"null",
",",
"$",
"merge",
"=",
"true",
")",
"{",
"$",
"collection",
"=",
"static",
"::",
"$",
"_collection",
";",
"if",
"(",
"$",
"extensions",
"===",
"null",
")",
"{",
"if",
"(",
"!",
"static",
"::",
"$",
"initialized",
")",
"{",
"static",
"::",
"_loadRoutes",
"(",
")",
";",
"}",
"return",
"array_unique",
"(",
"array_merge",
"(",
"static",
"::",
"$",
"_defaultExtensions",
",",
"$",
"collection",
"->",
"getExtensions",
"(",
")",
")",
")",
";",
"}",
"$",
"extensions",
"=",
"(",
"array",
")",
"$",
"extensions",
";",
"if",
"(",
"$",
"merge",
")",
"{",
"$",
"extensions",
"=",
"array_unique",
"(",
"array_merge",
"(",
"static",
"::",
"$",
"_defaultExtensions",
",",
"$",
"extensions",
")",
")",
";",
"}",
"return",
"static",
"::",
"$",
"_defaultExtensions",
"=",
"$",
"extensions",
";",
"}"
] | Get or set valid extensions for all routes connected later.
Instructs the router to parse out file extensions
from the URL. For example, http://example.com/posts.rss would yield a file
extension of "rss". The file extension itself is made available in the
controller as `$this->request->getParam('_ext')`, and is used by the RequestHandler
component to automatically switch to alternate layouts and templates, and
load helpers corresponding to the given content, i.e. RssHelper. Switching
layouts and helpers requires that the chosen extension has a defined mime type
in `Cake\Http\Response`.
A string or an array of valid extensions can be passed to this method.
If called without any parameters it will return current list of set extensions.
@param array|string|null $extensions List of extensions to be added.
@param bool $merge Whether to merge with or override existing extensions.
Defaults to `true`.
@return array Array of extensions Router is configured to parse. | [
"Get",
"or",
"set",
"valid",
"extensions",
"for",
"all",
"routes",
"connected",
"later",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Router.php#L949-L965 |
210,528 | cakephp/cakephp | src/Routing/Router.php | Router.parseNamedParams | public static function parseNamedParams(ServerRequest $request, array $options = [])
{
deprecationWarning(
'Router::parseNamedParams() is deprecated. ' .
'2.x backwards compatible named parameter support will be removed in 4.0'
);
$options += ['separator' => ':'];
if (!$request->getParam('pass')) {
return $request->withParam('named', []);
}
$named = [];
$pass = $request->getParam('pass');
foreach ((array)$pass as $key => $value) {
if (strpos($value, $options['separator']) === false) {
continue;
}
unset($pass[$key]);
list($key, $value) = explode($options['separator'], $value, 2);
if (preg_match_all('/\[([A-Za-z0-9_-]+)?\]/', $key, $matches, PREG_SET_ORDER)) {
$matches = array_reverse($matches);
$parts = explode('[', $key);
$key = array_shift($parts);
$arr = $value;
foreach ($matches as $match) {
if (empty($match[1])) {
$arr = [$arr];
} else {
$arr = [
$match[1] => $arr
];
}
}
$value = $arr;
}
$named = array_merge_recursive($named, [$key => $value]);
}
return $request
->withParam('pass', $pass)
->withParam('named', $named);
} | php | public static function parseNamedParams(ServerRequest $request, array $options = [])
{
deprecationWarning(
'Router::parseNamedParams() is deprecated. ' .
'2.x backwards compatible named parameter support will be removed in 4.0'
);
$options += ['separator' => ':'];
if (!$request->getParam('pass')) {
return $request->withParam('named', []);
}
$named = [];
$pass = $request->getParam('pass');
foreach ((array)$pass as $key => $value) {
if (strpos($value, $options['separator']) === false) {
continue;
}
unset($pass[$key]);
list($key, $value) = explode($options['separator'], $value, 2);
if (preg_match_all('/\[([A-Za-z0-9_-]+)?\]/', $key, $matches, PREG_SET_ORDER)) {
$matches = array_reverse($matches);
$parts = explode('[', $key);
$key = array_shift($parts);
$arr = $value;
foreach ($matches as $match) {
if (empty($match[1])) {
$arr = [$arr];
} else {
$arr = [
$match[1] => $arr
];
}
}
$value = $arr;
}
$named = array_merge_recursive($named, [$key => $value]);
}
return $request
->withParam('pass', $pass)
->withParam('named', $named);
} | [
"public",
"static",
"function",
"parseNamedParams",
"(",
"ServerRequest",
"$",
"request",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"deprecationWarning",
"(",
"'Router::parseNamedParams() is deprecated. '",
".",
"'2.x backwards compatible named parameter support will be removed in 4.0'",
")",
";",
"$",
"options",
"+=",
"[",
"'separator'",
"=>",
"':'",
"]",
";",
"if",
"(",
"!",
"$",
"request",
"->",
"getParam",
"(",
"'pass'",
")",
")",
"{",
"return",
"$",
"request",
"->",
"withParam",
"(",
"'named'",
",",
"[",
"]",
")",
";",
"}",
"$",
"named",
"=",
"[",
"]",
";",
"$",
"pass",
"=",
"$",
"request",
"->",
"getParam",
"(",
"'pass'",
")",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"pass",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"value",
",",
"$",
"options",
"[",
"'separator'",
"]",
")",
"===",
"false",
")",
"{",
"continue",
";",
"}",
"unset",
"(",
"$",
"pass",
"[",
"$",
"key",
"]",
")",
";",
"list",
"(",
"$",
"key",
",",
"$",
"value",
")",
"=",
"explode",
"(",
"$",
"options",
"[",
"'separator'",
"]",
",",
"$",
"value",
",",
"2",
")",
";",
"if",
"(",
"preg_match_all",
"(",
"'/\\[([A-Za-z0-9_-]+)?\\]/'",
",",
"$",
"key",
",",
"$",
"matches",
",",
"PREG_SET_ORDER",
")",
")",
"{",
"$",
"matches",
"=",
"array_reverse",
"(",
"$",
"matches",
")",
";",
"$",
"parts",
"=",
"explode",
"(",
"'['",
",",
"$",
"key",
")",
";",
"$",
"key",
"=",
"array_shift",
"(",
"$",
"parts",
")",
";",
"$",
"arr",
"=",
"$",
"value",
";",
"foreach",
"(",
"$",
"matches",
"as",
"$",
"match",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"match",
"[",
"1",
"]",
")",
")",
"{",
"$",
"arr",
"=",
"[",
"$",
"arr",
"]",
";",
"}",
"else",
"{",
"$",
"arr",
"=",
"[",
"$",
"match",
"[",
"1",
"]",
"=>",
"$",
"arr",
"]",
";",
"}",
"}",
"$",
"value",
"=",
"$",
"arr",
";",
"}",
"$",
"named",
"=",
"array_merge_recursive",
"(",
"$",
"named",
",",
"[",
"$",
"key",
"=>",
"$",
"value",
"]",
")",
";",
"}",
"return",
"$",
"request",
"->",
"withParam",
"(",
"'pass'",
",",
"$",
"pass",
")",
"->",
"withParam",
"(",
"'named'",
",",
"$",
"named",
")",
";",
"}"
] | Provides legacy support for named parameters on incoming URLs.
Checks the passed parameters for elements containing `$options['separator']`
Those parameters are split and parsed as if they were old style named parameters.
The parsed parameters will be moved from params['pass'] to params['named'].
### Options
- `separator` The string to use as a separator. Defaults to `:`.
@param \Cake\Http\ServerRequest $request The request object to modify.
@param array $options The array of options.
@return \Cake\Http\ServerRequest The modified request
@deprecated 3.3.0 Named parameter backwards compatibility will be removed in 4.0. | [
"Provides",
"legacy",
"support",
"for",
"named",
"parameters",
"on",
"incoming",
"URLs",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Router.php#L984-L1025 |
210,529 | cakephp/cakephp | src/Routing/Router.php | Router.createRouteBuilder | public static function createRouteBuilder($path, array $options = [])
{
$defaults = [
'routeClass' => static::defaultRouteClass(),
'extensions' => static::$_defaultExtensions,
];
$options += $defaults;
return new RouteBuilder(static::$_collection, $path, [], [
'routeClass' => $options['routeClass'],
'extensions' => $options['extensions'],
]);
} | php | public static function createRouteBuilder($path, array $options = [])
{
$defaults = [
'routeClass' => static::defaultRouteClass(),
'extensions' => static::$_defaultExtensions,
];
$options += $defaults;
return new RouteBuilder(static::$_collection, $path, [], [
'routeClass' => $options['routeClass'],
'extensions' => $options['extensions'],
]);
} | [
"public",
"static",
"function",
"createRouteBuilder",
"(",
"$",
"path",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'routeClass'",
"=>",
"static",
"::",
"defaultRouteClass",
"(",
")",
",",
"'extensions'",
"=>",
"static",
"::",
"$",
"_defaultExtensions",
",",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"return",
"new",
"RouteBuilder",
"(",
"static",
"::",
"$",
"_collection",
",",
"$",
"path",
",",
"[",
"]",
",",
"[",
"'routeClass'",
"=>",
"$",
"options",
"[",
"'routeClass'",
"]",
",",
"'extensions'",
"=>",
"$",
"options",
"[",
"'extensions'",
"]",
",",
"]",
")",
";",
"}"
] | Create a RouteBuilder for the provided path.
@param string $path The path to set the builder to.
@param array $options The options for the builder
@return \Cake\Routing\RouteBuilder | [
"Create",
"a",
"RouteBuilder",
"for",
"the",
"provided",
"path",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Router.php#L1034-L1046 |
210,530 | cakephp/cakephp | src/Routing/Router.php | Router.scope | public static function scope($path, $params = [], $callback = null)
{
$options = [];
if (is_array($params)) {
$options = $params;
unset($params['routeClass'], $params['extensions']);
}
$builder = static::createRouteBuilder('/', $options);
$builder->scope($path, $params, $callback);
} | php | public static function scope($path, $params = [], $callback = null)
{
$options = [];
if (is_array($params)) {
$options = $params;
unset($params['routeClass'], $params['extensions']);
}
$builder = static::createRouteBuilder('/', $options);
$builder->scope($path, $params, $callback);
} | [
"public",
"static",
"function",
"scope",
"(",
"$",
"path",
",",
"$",
"params",
"=",
"[",
"]",
",",
"$",
"callback",
"=",
"null",
")",
"{",
"$",
"options",
"=",
"[",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"params",
")",
")",
"{",
"$",
"options",
"=",
"$",
"params",
";",
"unset",
"(",
"$",
"params",
"[",
"'routeClass'",
"]",
",",
"$",
"params",
"[",
"'extensions'",
"]",
")",
";",
"}",
"$",
"builder",
"=",
"static",
"::",
"createRouteBuilder",
"(",
"'/'",
",",
"$",
"options",
")",
";",
"$",
"builder",
"->",
"scope",
"(",
"$",
"path",
",",
"$",
"params",
",",
"$",
"callback",
")",
";",
"}"
] | Create a routing scope.
Routing scopes allow you to keep your routes DRY and avoid repeating
common path prefixes, and or parameter sets.
Scoped collections will be indexed by path for faster route parsing. If you
re-open or re-use a scope the connected routes will be merged with the
existing ones.
### Options
The `$params` array allows you to define options for the routing scope.
The options listed below *are not* available to be used as routing defaults
- `routeClass` The route class to use in this scope. Defaults to
`Router::defaultRouteClass()`
- `extensions` The extensions to enable in this scope. Defaults to the globally
enabled extensions set with `Router::extensions()`
### Example
```
Router::scope('/blog', ['plugin' => 'Blog'], function ($routes) {
$routes->connect('/', ['controller' => 'Articles']);
});
```
The above would result in a `/blog/` route being created, with both the
plugin & controller default parameters set.
You can use `Router::plugin()` and `Router::prefix()` as shortcuts to creating
specific kinds of scopes.
@param string $path The path prefix for the scope. This path will be prepended
to all routes connected in the scoped collection.
@param array|callable $params An array of routing defaults to add to each connected route.
If you have no parameters, this argument can be a callable.
@param callable|null $callback The callback to invoke with the scoped collection.
@throws \InvalidArgumentException When an invalid callable is provided.
@return void | [
"Create",
"a",
"routing",
"scope",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Router.php#L1090-L1099 |
210,531 | cakephp/cakephp | src/Routing/Router.php | Router.prefix | public static function prefix($name, $params = [], $callback = null)
{
if ($callback === null) {
$callback = $params;
$params = [];
}
$name = Inflector::underscore($name);
if (empty($params['path'])) {
$path = '/' . $name;
} else {
$path = $params['path'];
unset($params['path']);
}
$params = array_merge($params, ['prefix' => $name]);
static::scope($path, $params, $callback);
} | php | public static function prefix($name, $params = [], $callback = null)
{
if ($callback === null) {
$callback = $params;
$params = [];
}
$name = Inflector::underscore($name);
if (empty($params['path'])) {
$path = '/' . $name;
} else {
$path = $params['path'];
unset($params['path']);
}
$params = array_merge($params, ['prefix' => $name]);
static::scope($path, $params, $callback);
} | [
"public",
"static",
"function",
"prefix",
"(",
"$",
"name",
",",
"$",
"params",
"=",
"[",
"]",
",",
"$",
"callback",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"callback",
"===",
"null",
")",
"{",
"$",
"callback",
"=",
"$",
"params",
";",
"$",
"params",
"=",
"[",
"]",
";",
"}",
"$",
"name",
"=",
"Inflector",
"::",
"underscore",
"(",
"$",
"name",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
"[",
"'path'",
"]",
")",
")",
"{",
"$",
"path",
"=",
"'/'",
".",
"$",
"name",
";",
"}",
"else",
"{",
"$",
"path",
"=",
"$",
"params",
"[",
"'path'",
"]",
";",
"unset",
"(",
"$",
"params",
"[",
"'path'",
"]",
")",
";",
"}",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"params",
",",
"[",
"'prefix'",
"=>",
"$",
"name",
"]",
")",
";",
"static",
"::",
"scope",
"(",
"$",
"path",
",",
"$",
"params",
",",
"$",
"callback",
")",
";",
"}"
] | Create prefixed routes.
This method creates a scoped route collection that includes
relevant prefix information.
The path parameter is used to generate the routing parameter name.
For example a path of `admin` would result in `'prefix' => 'admin'` being
applied to all connected routes.
The prefix name will be inflected to the underscore version to create
the routing path. If you want a custom path name, use the `path` option.
You can re-open a prefix as many times as necessary, as well as nest prefixes.
Nested prefixes will result in prefix values like `admin/api` which translates
to the `Controller\Admin\Api\` namespace.
@param string $name The prefix name to use.
@param array|callable $params An array of routing defaults to add to each connected route.
If you have no parameters, this argument can be a callable.
@param callable|null $callback The callback to invoke that builds the prefixed routes.
@return void | [
"Create",
"prefixed",
"routes",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Router.php#L1124-L1141 |
210,532 | cakephp/cakephp | src/View/Form/EntityContext.php | EntityContext._prepare | protected function _prepare()
{
$table = $this->_context['table'];
$entity = $this->_context['entity'];
if (empty($table)) {
if (is_array($entity) || $entity instanceof Traversable) {
foreach ($entity as $e) {
$entity = $e;
break;
}
}
$isEntity = $entity instanceof EntityInterface;
if ($isEntity) {
$table = $entity->getSource();
}
if (!$table && $isEntity && get_class($entity) !== 'Cake\ORM\Entity') {
list(, $entityClass) = namespaceSplit(get_class($entity));
$table = Inflector::pluralize($entityClass);
}
}
if (is_string($table)) {
$table = $this->getTableLocator()->get($table);
}
if (!($table instanceof RepositoryInterface)) {
throw new RuntimeException(
'Unable to find table class for current entity'
);
}
$this->_isCollection = (
is_array($entity) ||
$entity instanceof Traversable
);
$alias = $this->_rootName = $table->getAlias();
$this->_tables[$alias] = $table;
} | php | protected function _prepare()
{
$table = $this->_context['table'];
$entity = $this->_context['entity'];
if (empty($table)) {
if (is_array($entity) || $entity instanceof Traversable) {
foreach ($entity as $e) {
$entity = $e;
break;
}
}
$isEntity = $entity instanceof EntityInterface;
if ($isEntity) {
$table = $entity->getSource();
}
if (!$table && $isEntity && get_class($entity) !== 'Cake\ORM\Entity') {
list(, $entityClass) = namespaceSplit(get_class($entity));
$table = Inflector::pluralize($entityClass);
}
}
if (is_string($table)) {
$table = $this->getTableLocator()->get($table);
}
if (!($table instanceof RepositoryInterface)) {
throw new RuntimeException(
'Unable to find table class for current entity'
);
}
$this->_isCollection = (
is_array($entity) ||
$entity instanceof Traversable
);
$alias = $this->_rootName = $table->getAlias();
$this->_tables[$alias] = $table;
} | [
"protected",
"function",
"_prepare",
"(",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"_context",
"[",
"'table'",
"]",
";",
"$",
"entity",
"=",
"$",
"this",
"->",
"_context",
"[",
"'entity'",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"table",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"entity",
")",
"||",
"$",
"entity",
"instanceof",
"Traversable",
")",
"{",
"foreach",
"(",
"$",
"entity",
"as",
"$",
"e",
")",
"{",
"$",
"entity",
"=",
"$",
"e",
";",
"break",
";",
"}",
"}",
"$",
"isEntity",
"=",
"$",
"entity",
"instanceof",
"EntityInterface",
";",
"if",
"(",
"$",
"isEntity",
")",
"{",
"$",
"table",
"=",
"$",
"entity",
"->",
"getSource",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"table",
"&&",
"$",
"isEntity",
"&&",
"get_class",
"(",
"$",
"entity",
")",
"!==",
"'Cake\\ORM\\Entity'",
")",
"{",
"list",
"(",
",",
"$",
"entityClass",
")",
"=",
"namespaceSplit",
"(",
"get_class",
"(",
"$",
"entity",
")",
")",
";",
"$",
"table",
"=",
"Inflector",
"::",
"pluralize",
"(",
"$",
"entityClass",
")",
";",
"}",
"}",
"if",
"(",
"is_string",
"(",
"$",
"table",
")",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTableLocator",
"(",
")",
"->",
"get",
"(",
"$",
"table",
")",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"table",
"instanceof",
"RepositoryInterface",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Unable to find table class for current entity'",
")",
";",
"}",
"$",
"this",
"->",
"_isCollection",
"=",
"(",
"is_array",
"(",
"$",
"entity",
")",
"||",
"$",
"entity",
"instanceof",
"Traversable",
")",
";",
"$",
"alias",
"=",
"$",
"this",
"->",
"_rootName",
"=",
"$",
"table",
"->",
"getAlias",
"(",
")",
";",
"$",
"this",
"->",
"_tables",
"[",
"$",
"alias",
"]",
"=",
"$",
"table",
";",
"}"
] | Prepare some additional data from the context.
If the table option was provided to the constructor and it
was a string, TableLocator will be used to get the correct table instance.
If an object is provided as the table option, it will be used as is.
If no table option is provided, the table name will be derived based on
naming conventions. This inference will work with a number of common objects
like arrays, Collection objects and ResultSets.
@return void
@throws \RuntimeException When a table object cannot be located/inferred. | [
"Prepare",
"some",
"additional",
"data",
"from",
"the",
"context",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Form/EntityContext.php#L127-L164 |
210,533 | cakephp/cakephp | src/View/Form/EntityContext.php | EntityContext.isCreate | public function isCreate()
{
$entity = $this->_context['entity'];
if (is_array($entity) || $entity instanceof Traversable) {
foreach ($entity as $e) {
$entity = $e;
break;
}
}
if ($entity instanceof EntityInterface) {
return $entity->isNew() !== false;
}
return true;
} | php | public function isCreate()
{
$entity = $this->_context['entity'];
if (is_array($entity) || $entity instanceof Traversable) {
foreach ($entity as $e) {
$entity = $e;
break;
}
}
if ($entity instanceof EntityInterface) {
return $entity->isNew() !== false;
}
return true;
} | [
"public",
"function",
"isCreate",
"(",
")",
"{",
"$",
"entity",
"=",
"$",
"this",
"->",
"_context",
"[",
"'entity'",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"entity",
")",
"||",
"$",
"entity",
"instanceof",
"Traversable",
")",
"{",
"foreach",
"(",
"$",
"entity",
"as",
"$",
"e",
")",
"{",
"$",
"entity",
"=",
"$",
"e",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"entity",
"instanceof",
"EntityInterface",
")",
"{",
"return",
"$",
"entity",
"->",
"isNew",
"(",
")",
"!==",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Check whether or not this form is a create or update.
If the context is for a single entity, the entity's isNew() method will
be used. If isNew() returns null, a create operation will be assumed.
If the context is for a collection or array the first object in the
collection will be used.
@return bool | [
"Check",
"whether",
"or",
"not",
"this",
"form",
"is",
"a",
"create",
"or",
"update",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Form/EntityContext.php#L201-L215 |
210,534 | cakephp/cakephp | src/View/Form/EntityContext.php | EntityContext._schemaDefault | protected function _schemaDefault($parts)
{
$table = $this->_getTable($parts);
if ($table === false) {
return null;
}
$field = end($parts);
$defaults = $table->getSchema()->defaultValues();
if (!array_key_exists($field, $defaults)) {
return null;
}
return $defaults[$field];
} | php | protected function _schemaDefault($parts)
{
$table = $this->_getTable($parts);
if ($table === false) {
return null;
}
$field = end($parts);
$defaults = $table->getSchema()->defaultValues();
if (!array_key_exists($field, $defaults)) {
return null;
}
return $defaults[$field];
} | [
"protected",
"function",
"_schemaDefault",
"(",
"$",
"parts",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"_getTable",
"(",
"$",
"parts",
")",
";",
"if",
"(",
"$",
"table",
"===",
"false",
")",
"{",
"return",
"null",
";",
"}",
"$",
"field",
"=",
"end",
"(",
"$",
"parts",
")",
";",
"$",
"defaults",
"=",
"$",
"table",
"->",
"getSchema",
"(",
")",
"->",
"defaultValues",
"(",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"field",
",",
"$",
"defaults",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"defaults",
"[",
"$",
"field",
"]",
";",
"}"
] | Get default value from table schema for given entity field.
@param array $parts Each one of the parts in a path for a field name
@return mixed | [
"Get",
"default",
"value",
"from",
"table",
"schema",
"for",
"given",
"entity",
"field",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Form/EntityContext.php#L281-L294 |
210,535 | cakephp/cakephp | src/View/Form/EntityContext.php | EntityContext.entity | public function entity($path = null)
{
if ($path === null) {
return $this->_context['entity'];
}
$oneElement = count($path) === 1;
if ($oneElement && $this->_isCollection) {
return false;
}
$entity = $this->_context['entity'];
if ($oneElement) {
return $entity;
}
if ($path[0] === $this->_rootName) {
$path = array_slice($path, 1);
}
$len = count($path);
$last = $len - 1;
for ($i = 0; $i < $len; $i++) {
$prop = $path[$i];
$next = $this->_getProp($entity, $prop);
$isLast = ($i === $last);
if (!$isLast && $next === null && $prop !== '_ids') {
$table = $this->_getTable($path);
return $table->newEntity();
}
$isTraversable = (
is_array($next) ||
$next instanceof Traversable ||
$next instanceof EntityInterface
);
if ($isLast || !$isTraversable) {
return $entity;
}
$entity = $next;
}
throw new RuntimeException(sprintf(
'Unable to fetch property "%s"',
implode('.', $path)
));
} | php | public function entity($path = null)
{
if ($path === null) {
return $this->_context['entity'];
}
$oneElement = count($path) === 1;
if ($oneElement && $this->_isCollection) {
return false;
}
$entity = $this->_context['entity'];
if ($oneElement) {
return $entity;
}
if ($path[0] === $this->_rootName) {
$path = array_slice($path, 1);
}
$len = count($path);
$last = $len - 1;
for ($i = 0; $i < $len; $i++) {
$prop = $path[$i];
$next = $this->_getProp($entity, $prop);
$isLast = ($i === $last);
if (!$isLast && $next === null && $prop !== '_ids') {
$table = $this->_getTable($path);
return $table->newEntity();
}
$isTraversable = (
is_array($next) ||
$next instanceof Traversable ||
$next instanceof EntityInterface
);
if ($isLast || !$isTraversable) {
return $entity;
}
$entity = $next;
}
throw new RuntimeException(sprintf(
'Unable to fetch property "%s"',
implode('.', $path)
));
} | [
"public",
"function",
"entity",
"(",
"$",
"path",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"path",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_context",
"[",
"'entity'",
"]",
";",
"}",
"$",
"oneElement",
"=",
"count",
"(",
"$",
"path",
")",
"===",
"1",
";",
"if",
"(",
"$",
"oneElement",
"&&",
"$",
"this",
"->",
"_isCollection",
")",
"{",
"return",
"false",
";",
"}",
"$",
"entity",
"=",
"$",
"this",
"->",
"_context",
"[",
"'entity'",
"]",
";",
"if",
"(",
"$",
"oneElement",
")",
"{",
"return",
"$",
"entity",
";",
"}",
"if",
"(",
"$",
"path",
"[",
"0",
"]",
"===",
"$",
"this",
"->",
"_rootName",
")",
"{",
"$",
"path",
"=",
"array_slice",
"(",
"$",
"path",
",",
"1",
")",
";",
"}",
"$",
"len",
"=",
"count",
"(",
"$",
"path",
")",
";",
"$",
"last",
"=",
"$",
"len",
"-",
"1",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"len",
";",
"$",
"i",
"++",
")",
"{",
"$",
"prop",
"=",
"$",
"path",
"[",
"$",
"i",
"]",
";",
"$",
"next",
"=",
"$",
"this",
"->",
"_getProp",
"(",
"$",
"entity",
",",
"$",
"prop",
")",
";",
"$",
"isLast",
"=",
"(",
"$",
"i",
"===",
"$",
"last",
")",
";",
"if",
"(",
"!",
"$",
"isLast",
"&&",
"$",
"next",
"===",
"null",
"&&",
"$",
"prop",
"!==",
"'_ids'",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"_getTable",
"(",
"$",
"path",
")",
";",
"return",
"$",
"table",
"->",
"newEntity",
"(",
")",
";",
"}",
"$",
"isTraversable",
"=",
"(",
"is_array",
"(",
"$",
"next",
")",
"||",
"$",
"next",
"instanceof",
"Traversable",
"||",
"$",
"next",
"instanceof",
"EntityInterface",
")",
";",
"if",
"(",
"$",
"isLast",
"||",
"!",
"$",
"isTraversable",
")",
"{",
"return",
"$",
"entity",
";",
"}",
"$",
"entity",
"=",
"$",
"next",
";",
"}",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Unable to fetch property \"%s\"'",
",",
"implode",
"(",
"'.'",
",",
"$",
"path",
")",
")",
")",
";",
"}"
] | Fetch the leaf entity for the given path.
This method will traverse the given path and find the leaf
entity. If the path does not contain a leaf entity false
will be returned.
@param array|null $path Each one of the parts in a path for a field name
or null to get the entity passed in constructor context.
@return \Cake\Datasource\EntityInterface|\Traversable|array|bool
@throws \RuntimeException When properties cannot be read. | [
"Fetch",
"the",
"leaf",
"entity",
"for",
"the",
"given",
"path",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Form/EntityContext.php#L327-L373 |
210,536 | cakephp/cakephp | src/View/Form/EntityContext.php | EntityContext.isRequired | public function isRequired($field)
{
$parts = explode('.', $field);
$entity = $this->entity($parts);
$isNew = true;
if ($entity instanceof EntityInterface) {
$isNew = $entity->isNew();
}
$validator = $this->_getValidator($parts);
$fieldName = array_pop($parts);
if (!$validator->hasField($fieldName)) {
return false;
}
if ($this->type($field) !== 'boolean') {
return $validator->isEmptyAllowed($fieldName, $isNew) === false;
}
return false;
} | php | public function isRequired($field)
{
$parts = explode('.', $field);
$entity = $this->entity($parts);
$isNew = true;
if ($entity instanceof EntityInterface) {
$isNew = $entity->isNew();
}
$validator = $this->_getValidator($parts);
$fieldName = array_pop($parts);
if (!$validator->hasField($fieldName)) {
return false;
}
if ($this->type($field) !== 'boolean') {
return $validator->isEmptyAllowed($fieldName, $isNew) === false;
}
return false;
} | [
"public",
"function",
"isRequired",
"(",
"$",
"field",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"field",
")",
";",
"$",
"entity",
"=",
"$",
"this",
"->",
"entity",
"(",
"$",
"parts",
")",
";",
"$",
"isNew",
"=",
"true",
";",
"if",
"(",
"$",
"entity",
"instanceof",
"EntityInterface",
")",
"{",
"$",
"isNew",
"=",
"$",
"entity",
"->",
"isNew",
"(",
")",
";",
"}",
"$",
"validator",
"=",
"$",
"this",
"->",
"_getValidator",
"(",
"$",
"parts",
")",
";",
"$",
"fieldName",
"=",
"array_pop",
"(",
"$",
"parts",
")",
";",
"if",
"(",
"!",
"$",
"validator",
"->",
"hasField",
"(",
"$",
"fieldName",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"type",
"(",
"$",
"field",
")",
"!==",
"'boolean'",
")",
"{",
"return",
"$",
"validator",
"->",
"isEmptyAllowed",
"(",
"$",
"fieldName",
",",
"$",
"isNew",
")",
"===",
"false",
";",
"}",
"return",
"false",
";",
"}"
] | Check if a field should be marked as required.
@param string $field The dot separated path to the field you want to check.
@return bool | [
"Check",
"if",
"a",
"field",
"should",
"be",
"marked",
"as",
"required",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Form/EntityContext.php#L407-L427 |
210,537 | cakephp/cakephp | src/View/Form/EntityContext.php | EntityContext._getValidator | protected function _getValidator($parts)
{
$keyParts = array_filter(array_slice($parts, 0, -1), function ($part) {
return !is_numeric($part);
});
$key = implode('.', $keyParts);
$entity = $this->entity($parts) ?: null;
if (isset($this->_validator[$key])) {
$this->_validator[$key]->setProvider('entity', $entity);
return $this->_validator[$key];
}
$table = $this->_getTable($parts);
$alias = $table->getAlias();
$method = 'default';
if (is_string($this->_context['validator'])) {
$method = $this->_context['validator'];
} elseif (isset($this->_context['validator'][$alias])) {
$method = $this->_context['validator'][$alias];
}
$validator = $table->getValidator($method);
$validator->setProvider('entity', $entity);
return $this->_validator[$key] = $validator;
} | php | protected function _getValidator($parts)
{
$keyParts = array_filter(array_slice($parts, 0, -1), function ($part) {
return !is_numeric($part);
});
$key = implode('.', $keyParts);
$entity = $this->entity($parts) ?: null;
if (isset($this->_validator[$key])) {
$this->_validator[$key]->setProvider('entity', $entity);
return $this->_validator[$key];
}
$table = $this->_getTable($parts);
$alias = $table->getAlias();
$method = 'default';
if (is_string($this->_context['validator'])) {
$method = $this->_context['validator'];
} elseif (isset($this->_context['validator'][$alias])) {
$method = $this->_context['validator'][$alias];
}
$validator = $table->getValidator($method);
$validator->setProvider('entity', $entity);
return $this->_validator[$key] = $validator;
} | [
"protected",
"function",
"_getValidator",
"(",
"$",
"parts",
")",
"{",
"$",
"keyParts",
"=",
"array_filter",
"(",
"array_slice",
"(",
"$",
"parts",
",",
"0",
",",
"-",
"1",
")",
",",
"function",
"(",
"$",
"part",
")",
"{",
"return",
"!",
"is_numeric",
"(",
"$",
"part",
")",
";",
"}",
")",
";",
"$",
"key",
"=",
"implode",
"(",
"'.'",
",",
"$",
"keyParts",
")",
";",
"$",
"entity",
"=",
"$",
"this",
"->",
"entity",
"(",
"$",
"parts",
")",
"?",
":",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_validator",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_validator",
"[",
"$",
"key",
"]",
"->",
"setProvider",
"(",
"'entity'",
",",
"$",
"entity",
")",
";",
"return",
"$",
"this",
"->",
"_validator",
"[",
"$",
"key",
"]",
";",
"}",
"$",
"table",
"=",
"$",
"this",
"->",
"_getTable",
"(",
"$",
"parts",
")",
";",
"$",
"alias",
"=",
"$",
"table",
"->",
"getAlias",
"(",
")",
";",
"$",
"method",
"=",
"'default'",
";",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"_context",
"[",
"'validator'",
"]",
")",
")",
"{",
"$",
"method",
"=",
"$",
"this",
"->",
"_context",
"[",
"'validator'",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"this",
"->",
"_context",
"[",
"'validator'",
"]",
"[",
"$",
"alias",
"]",
")",
")",
"{",
"$",
"method",
"=",
"$",
"this",
"->",
"_context",
"[",
"'validator'",
"]",
"[",
"$",
"alias",
"]",
";",
"}",
"$",
"validator",
"=",
"$",
"table",
"->",
"getValidator",
"(",
"$",
"method",
")",
";",
"$",
"validator",
"->",
"setProvider",
"(",
"'entity'",
",",
"$",
"entity",
")",
";",
"return",
"$",
"this",
"->",
"_validator",
"[",
"$",
"key",
"]",
"=",
"$",
"validator",
";",
"}"
] | Get the validator associated to an entity based on naming
conventions.
@param array $parts Each one of the parts in a path for a field name
@return \Cake\Validation\Validator | [
"Get",
"the",
"validator",
"associated",
"to",
"an",
"entity",
"based",
"on",
"naming",
"conventions",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Form/EntityContext.php#L501-L529 |
210,538 | cakephp/cakephp | src/View/Form/EntityContext.php | EntityContext._getTable | protected function _getTable($parts, $fallback = true)
{
if (!is_array($parts) || count($parts) === 1) {
return $this->_tables[$this->_rootName];
}
$normalized = array_slice(array_filter($parts, function ($part) {
return !is_numeric($part);
}), 0, -1);
$path = implode('.', $normalized);
if (isset($this->_tables[$path])) {
return $this->_tables[$path];
}
if (current($normalized) === $this->_rootName) {
$normalized = array_slice($normalized, 1);
}
$table = $this->_tables[$this->_rootName];
$assoc = null;
foreach ($normalized as $part) {
if ($part === '_joinData') {
if ($assoc) {
$table = $assoc->junction();
$assoc = null;
continue;
}
} else {
$assoc = $table->associations()->getByProperty($part);
}
if (!$assoc && $fallback) {
break;
}
if (!$assoc && !$fallback) {
return false;
}
$table = $assoc->getTarget();
}
return $this->_tables[$path] = $table;
} | php | protected function _getTable($parts, $fallback = true)
{
if (!is_array($parts) || count($parts) === 1) {
return $this->_tables[$this->_rootName];
}
$normalized = array_slice(array_filter($parts, function ($part) {
return !is_numeric($part);
}), 0, -1);
$path = implode('.', $normalized);
if (isset($this->_tables[$path])) {
return $this->_tables[$path];
}
if (current($normalized) === $this->_rootName) {
$normalized = array_slice($normalized, 1);
}
$table = $this->_tables[$this->_rootName];
$assoc = null;
foreach ($normalized as $part) {
if ($part === '_joinData') {
if ($assoc) {
$table = $assoc->junction();
$assoc = null;
continue;
}
} else {
$assoc = $table->associations()->getByProperty($part);
}
if (!$assoc && $fallback) {
break;
}
if (!$assoc && !$fallback) {
return false;
}
$table = $assoc->getTarget();
}
return $this->_tables[$path] = $table;
} | [
"protected",
"function",
"_getTable",
"(",
"$",
"parts",
",",
"$",
"fallback",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"parts",
")",
"||",
"count",
"(",
"$",
"parts",
")",
"===",
"1",
")",
"{",
"return",
"$",
"this",
"->",
"_tables",
"[",
"$",
"this",
"->",
"_rootName",
"]",
";",
"}",
"$",
"normalized",
"=",
"array_slice",
"(",
"array_filter",
"(",
"$",
"parts",
",",
"function",
"(",
"$",
"part",
")",
"{",
"return",
"!",
"is_numeric",
"(",
"$",
"part",
")",
";",
"}",
")",
",",
"0",
",",
"-",
"1",
")",
";",
"$",
"path",
"=",
"implode",
"(",
"'.'",
",",
"$",
"normalized",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_tables",
"[",
"$",
"path",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_tables",
"[",
"$",
"path",
"]",
";",
"}",
"if",
"(",
"current",
"(",
"$",
"normalized",
")",
"===",
"$",
"this",
"->",
"_rootName",
")",
"{",
"$",
"normalized",
"=",
"array_slice",
"(",
"$",
"normalized",
",",
"1",
")",
";",
"}",
"$",
"table",
"=",
"$",
"this",
"->",
"_tables",
"[",
"$",
"this",
"->",
"_rootName",
"]",
";",
"$",
"assoc",
"=",
"null",
";",
"foreach",
"(",
"$",
"normalized",
"as",
"$",
"part",
")",
"{",
"if",
"(",
"$",
"part",
"===",
"'_joinData'",
")",
"{",
"if",
"(",
"$",
"assoc",
")",
"{",
"$",
"table",
"=",
"$",
"assoc",
"->",
"junction",
"(",
")",
";",
"$",
"assoc",
"=",
"null",
";",
"continue",
";",
"}",
"}",
"else",
"{",
"$",
"assoc",
"=",
"$",
"table",
"->",
"associations",
"(",
")",
"->",
"getByProperty",
"(",
"$",
"part",
")",
";",
"}",
"if",
"(",
"!",
"$",
"assoc",
"&&",
"$",
"fallback",
")",
"{",
"break",
";",
"}",
"if",
"(",
"!",
"$",
"assoc",
"&&",
"!",
"$",
"fallback",
")",
"{",
"return",
"false",
";",
"}",
"$",
"table",
"=",
"$",
"assoc",
"->",
"getTarget",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_tables",
"[",
"$",
"path",
"]",
"=",
"$",
"table",
";",
"}"
] | Get the table instance from a property path
@param array $parts Each one of the parts in a path for a field name
@param bool $fallback Whether or not to fallback to the last found table
when a non-existent field/property is being encountered.
@return \Cake\ORM\Table|bool Table instance or false | [
"Get",
"the",
"table",
"instance",
"from",
"a",
"property",
"path"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Form/EntityContext.php#L539-L582 |
210,539 | cakephp/cakephp | src/Database/Retry/ReconnectStrategy.php | ReconnectStrategy.shouldRetry | public function shouldRetry(Exception $exception, $retryCount)
{
$message = $exception->getMessage();
foreach (static::$causes as $cause) {
if (strstr($message, $cause) !== false) {
return $this->reconnect();
}
}
return false;
} | php | public function shouldRetry(Exception $exception, $retryCount)
{
$message = $exception->getMessage();
foreach (static::$causes as $cause) {
if (strstr($message, $cause) !== false) {
return $this->reconnect();
}
}
return false;
} | [
"public",
"function",
"shouldRetry",
"(",
"Exception",
"$",
"exception",
",",
"$",
"retryCount",
")",
"{",
"$",
"message",
"=",
"$",
"exception",
"->",
"getMessage",
"(",
")",
";",
"foreach",
"(",
"static",
"::",
"$",
"causes",
"as",
"$",
"cause",
")",
"{",
"if",
"(",
"strstr",
"(",
"$",
"message",
",",
"$",
"cause",
")",
"!==",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"reconnect",
"(",
")",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks whether or not the exception was caused by a lost connection,
and returns true if it was able to successfully reconnect.
@param Exception $exception The exception to check for its message
@param int $retryCount The number of times the action has been already called
@return bool Whether or not it is OK to retry the action | [
"Checks",
"whether",
"or",
"not",
"the",
"exception",
"was",
"caused",
"by",
"a",
"lost",
"connection",
"and",
"returns",
"true",
"if",
"it",
"was",
"able",
"to",
"successfully",
"reconnect",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Retry/ReconnectStrategy.php#L80-L91 |
210,540 | cakephp/cakephp | src/Database/Retry/ReconnectStrategy.php | ReconnectStrategy.reconnect | protected function reconnect()
{
if ($this->connection->inTransaction()) {
// It is not safe to blindly reconnect in the middle of a transaction
return false;
}
try {
// Make sure we free any resources associated with the old connection
$this->connection->disconnect();
} catch (Exception $e) {
}
try {
$this->connection->connect();
$this->connection->log('[RECONNECT]');
return true;
} catch (Exception $e) {
// If there was an error connecting again, don't report it back,
// let the retry handler do it.
return false;
}
} | php | protected function reconnect()
{
if ($this->connection->inTransaction()) {
// It is not safe to blindly reconnect in the middle of a transaction
return false;
}
try {
// Make sure we free any resources associated with the old connection
$this->connection->disconnect();
} catch (Exception $e) {
}
try {
$this->connection->connect();
$this->connection->log('[RECONNECT]');
return true;
} catch (Exception $e) {
// If there was an error connecting again, don't report it back,
// let the retry handler do it.
return false;
}
} | [
"protected",
"function",
"reconnect",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"connection",
"->",
"inTransaction",
"(",
")",
")",
"{",
"// It is not safe to blindly reconnect in the middle of a transaction",
"return",
"false",
";",
"}",
"try",
"{",
"// Make sure we free any resources associated with the old connection",
"$",
"this",
"->",
"connection",
"->",
"disconnect",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"}",
"try",
"{",
"$",
"this",
"->",
"connection",
"->",
"connect",
"(",
")",
";",
"$",
"this",
"->",
"connection",
"->",
"log",
"(",
"'[RECONNECT]'",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"// If there was an error connecting again, don't report it back,",
"// let the retry handler do it.",
"return",
"false",
";",
"}",
"}"
] | Tries to re-establish the connection to the server, if it is safe to do so
@return bool Whether or not the connection was re-established | [
"Tries",
"to",
"re",
"-",
"establish",
"the",
"connection",
"to",
"the",
"server",
"if",
"it",
"is",
"safe",
"to",
"do",
"so"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Retry/ReconnectStrategy.php#L98-L121 |
210,541 | cakephp/cakephp | src/Shell/ServerShell.php | ServerShell.startup | public function startup()
{
if ($this->param('host')) {
$this->_host = $this->param('host');
}
if ($this->param('port')) {
$this->_port = (int)$this->param('port');
}
if ($this->param('document_root')) {
$this->_documentRoot = $this->param('document_root');
}
if ($this->param('ini_path')) {
$this->_iniPath = $this->param('ini_path');
}
// For Windows
if (substr($this->_documentRoot, -1, 1) === DIRECTORY_SEPARATOR) {
$this->_documentRoot = substr($this->_documentRoot, 0, strlen($this->_documentRoot) - 1);
}
if (preg_match("/^([a-z]:)[\\\]+(.+)$/i", $this->_documentRoot, $m)) {
$this->_documentRoot = $m[1] . '\\' . $m[2];
}
$this->_iniPath = rtrim($this->_iniPath, DIRECTORY_SEPARATOR);
if (preg_match("/^([a-z]:)[\\\]+(.+)$/i", $this->_iniPath, $m)) {
$this->_iniPath = $m[1] . '\\' . $m[2];
}
parent::startup();
} | php | public function startup()
{
if ($this->param('host')) {
$this->_host = $this->param('host');
}
if ($this->param('port')) {
$this->_port = (int)$this->param('port');
}
if ($this->param('document_root')) {
$this->_documentRoot = $this->param('document_root');
}
if ($this->param('ini_path')) {
$this->_iniPath = $this->param('ini_path');
}
// For Windows
if (substr($this->_documentRoot, -1, 1) === DIRECTORY_SEPARATOR) {
$this->_documentRoot = substr($this->_documentRoot, 0, strlen($this->_documentRoot) - 1);
}
if (preg_match("/^([a-z]:)[\\\]+(.+)$/i", $this->_documentRoot, $m)) {
$this->_documentRoot = $m[1] . '\\' . $m[2];
}
$this->_iniPath = rtrim($this->_iniPath, DIRECTORY_SEPARATOR);
if (preg_match("/^([a-z]:)[\\\]+(.+)$/i", $this->_iniPath, $m)) {
$this->_iniPath = $m[1] . '\\' . $m[2];
}
parent::startup();
} | [
"public",
"function",
"startup",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"param",
"(",
"'host'",
")",
")",
"{",
"$",
"this",
"->",
"_host",
"=",
"$",
"this",
"->",
"param",
"(",
"'host'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"param",
"(",
"'port'",
")",
")",
"{",
"$",
"this",
"->",
"_port",
"=",
"(",
"int",
")",
"$",
"this",
"->",
"param",
"(",
"'port'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"param",
"(",
"'document_root'",
")",
")",
"{",
"$",
"this",
"->",
"_documentRoot",
"=",
"$",
"this",
"->",
"param",
"(",
"'document_root'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"param",
"(",
"'ini_path'",
")",
")",
"{",
"$",
"this",
"->",
"_iniPath",
"=",
"$",
"this",
"->",
"param",
"(",
"'ini_path'",
")",
";",
"}",
"// For Windows",
"if",
"(",
"substr",
"(",
"$",
"this",
"->",
"_documentRoot",
",",
"-",
"1",
",",
"1",
")",
"===",
"DIRECTORY_SEPARATOR",
")",
"{",
"$",
"this",
"->",
"_documentRoot",
"=",
"substr",
"(",
"$",
"this",
"->",
"_documentRoot",
",",
"0",
",",
"strlen",
"(",
"$",
"this",
"->",
"_documentRoot",
")",
"-",
"1",
")",
";",
"}",
"if",
"(",
"preg_match",
"(",
"\"/^([a-z]:)[\\\\\\]+(.+)$/i\"",
",",
"$",
"this",
"->",
"_documentRoot",
",",
"$",
"m",
")",
")",
"{",
"$",
"this",
"->",
"_documentRoot",
"=",
"$",
"m",
"[",
"1",
"]",
".",
"'\\\\'",
".",
"$",
"m",
"[",
"2",
"]",
";",
"}",
"$",
"this",
"->",
"_iniPath",
"=",
"rtrim",
"(",
"$",
"this",
"->",
"_iniPath",
",",
"DIRECTORY_SEPARATOR",
")",
";",
"if",
"(",
"preg_match",
"(",
"\"/^([a-z]:)[\\\\\\]+(.+)$/i\"",
",",
"$",
"this",
"->",
"_iniPath",
",",
"$",
"m",
")",
")",
"{",
"$",
"this",
"->",
"_iniPath",
"=",
"$",
"m",
"[",
"1",
"]",
".",
"'\\\\'",
".",
"$",
"m",
"[",
"2",
"]",
";",
"}",
"parent",
"::",
"startup",
"(",
")",
";",
"}"
] | Starts up the Shell and displays the welcome message.
Allows for checking and configuring prior to command or main execution
Override this method if you want to remove the welcome information,
or otherwise modify the pre-command flow.
@return void
@link https://book.cakephp.org/3.0/en/console-and-shells.html#hook-methods | [
"Starts",
"up",
"the",
"Shell",
"and",
"displays",
"the",
"welcome",
"message",
".",
"Allows",
"for",
"checking",
"and",
"configuring",
"prior",
"to",
"command",
"or",
"main",
"execution"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/ServerShell.php#L79-L108 |
210,542 | cakephp/cakephp | src/Error/Middleware/ErrorHandlerMiddleware.php | ErrorHandlerMiddleware.handleException | public function handleException($exception, $request, $response)
{
$renderer = $this->getRenderer($exception, $request);
try {
$res = $renderer->render();
$this->logException($request, $exception);
return $res;
} catch (Throwable $exception) {
$this->logException($request, $exception);
$response = $this->handleInternalError($response);
} catch (Exception $exception) {
$this->logException($request, $exception);
$response = $this->handleInternalError($response);
}
return $response;
} | php | public function handleException($exception, $request, $response)
{
$renderer = $this->getRenderer($exception, $request);
try {
$res = $renderer->render();
$this->logException($request, $exception);
return $res;
} catch (Throwable $exception) {
$this->logException($request, $exception);
$response = $this->handleInternalError($response);
} catch (Exception $exception) {
$this->logException($request, $exception);
$response = $this->handleInternalError($response);
}
return $response;
} | [
"public",
"function",
"handleException",
"(",
"$",
"exception",
",",
"$",
"request",
",",
"$",
"response",
")",
"{",
"$",
"renderer",
"=",
"$",
"this",
"->",
"getRenderer",
"(",
"$",
"exception",
",",
"$",
"request",
")",
";",
"try",
"{",
"$",
"res",
"=",
"$",
"renderer",
"->",
"render",
"(",
")",
";",
"$",
"this",
"->",
"logException",
"(",
"$",
"request",
",",
"$",
"exception",
")",
";",
"return",
"$",
"res",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"logException",
"(",
"$",
"request",
",",
"$",
"exception",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"handleInternalError",
"(",
"$",
"response",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"logException",
"(",
"$",
"request",
",",
"$",
"exception",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"handleInternalError",
"(",
"$",
"response",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Handle an exception and generate an error response
@param \Exception $exception The exception to handle.
@param \Psr\Http\Message\ServerRequestInterface $request The request.
@param \Psr\Http\Message\ResponseInterface $response The response.
@return \Psr\Http\Message\ResponseInterface A response | [
"Handle",
"an",
"exception",
"and",
"generate",
"an",
"error",
"response"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Error/Middleware/ErrorHandlerMiddleware.php#L112-L129 |
210,543 | cakephp/cakephp | src/Error/Middleware/ErrorHandlerMiddleware.php | ErrorHandlerMiddleware.getRenderer | protected function getRenderer($exception, $request)
{
if (!$this->exceptionRenderer) {
$this->exceptionRenderer = $this->getConfig('exceptionRenderer') ?: ExceptionRenderer::class;
}
// For PHP5 backwards compatibility
if ($exception instanceof Error) {
$exception = new PHP7ErrorException($exception);
}
if (is_string($this->exceptionRenderer)) {
$class = App::className($this->exceptionRenderer, 'Error');
if (!$class) {
throw new Exception(sprintf(
"The '%s' renderer class could not be found.",
$this->exceptionRenderer
));
}
return new $class($exception, $request);
}
$factory = $this->exceptionRenderer;
return $factory($exception, $request);
} | php | protected function getRenderer($exception, $request)
{
if (!$this->exceptionRenderer) {
$this->exceptionRenderer = $this->getConfig('exceptionRenderer') ?: ExceptionRenderer::class;
}
// For PHP5 backwards compatibility
if ($exception instanceof Error) {
$exception = new PHP7ErrorException($exception);
}
if (is_string($this->exceptionRenderer)) {
$class = App::className($this->exceptionRenderer, 'Error');
if (!$class) {
throw new Exception(sprintf(
"The '%s' renderer class could not be found.",
$this->exceptionRenderer
));
}
return new $class($exception, $request);
}
$factory = $this->exceptionRenderer;
return $factory($exception, $request);
} | [
"protected",
"function",
"getRenderer",
"(",
"$",
"exception",
",",
"$",
"request",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"exceptionRenderer",
")",
"{",
"$",
"this",
"->",
"exceptionRenderer",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'exceptionRenderer'",
")",
"?",
":",
"ExceptionRenderer",
"::",
"class",
";",
"}",
"// For PHP5 backwards compatibility",
"if",
"(",
"$",
"exception",
"instanceof",
"Error",
")",
"{",
"$",
"exception",
"=",
"new",
"PHP7ErrorException",
"(",
"$",
"exception",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"exceptionRenderer",
")",
")",
"{",
"$",
"class",
"=",
"App",
"::",
"className",
"(",
"$",
"this",
"->",
"exceptionRenderer",
",",
"'Error'",
")",
";",
"if",
"(",
"!",
"$",
"class",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"\"The '%s' renderer class could not be found.\"",
",",
"$",
"this",
"->",
"exceptionRenderer",
")",
")",
";",
"}",
"return",
"new",
"$",
"class",
"(",
"$",
"exception",
",",
"$",
"request",
")",
";",
"}",
"$",
"factory",
"=",
"$",
"this",
"->",
"exceptionRenderer",
";",
"return",
"$",
"factory",
"(",
"$",
"exception",
",",
"$",
"request",
")",
";",
"}"
] | Get a renderer instance
@param \Exception $exception The exception being rendered.
@param \Psr\Http\Message\ServerRequestInterface $request The request.
@return \Cake\Error\ExceptionRendererInterface The exception renderer.
@throws \Exception When the renderer class cannot be found. | [
"Get",
"a",
"renderer",
"instance"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Error/Middleware/ErrorHandlerMiddleware.php#L153-L178 |
210,544 | cakephp/cakephp | src/Core/InstanceConfigTrait.php | InstanceConfigTrait.getConfig | public function getConfig($key = null, $default = null)
{
if (!$this->_configInitialized) {
$this->_config = $this->_defaultConfig;
$this->_configInitialized = true;
}
$return = $this->_configRead($key);
return $return === null ? $default : $return;
} | php | public function getConfig($key = null, $default = null)
{
if (!$this->_configInitialized) {
$this->_config = $this->_defaultConfig;
$this->_configInitialized = true;
}
$return = $this->_configRead($key);
return $return === null ? $default : $return;
} | [
"public",
"function",
"getConfig",
"(",
"$",
"key",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_configInitialized",
")",
"{",
"$",
"this",
"->",
"_config",
"=",
"$",
"this",
"->",
"_defaultConfig",
";",
"$",
"this",
"->",
"_configInitialized",
"=",
"true",
";",
"}",
"$",
"return",
"=",
"$",
"this",
"->",
"_configRead",
"(",
"$",
"key",
")",
";",
"return",
"$",
"return",
"===",
"null",
"?",
"$",
"default",
":",
"$",
"return",
";",
"}"
] | Returns the config.
### Usage
Reading the whole config:
```
$this->getConfig();
```
Reading a specific value:
```
$this->getConfig('key');
```
Reading a nested value:
```
$this->getConfig('some.nested.key');
```
Reading with default value:
```
$this->getConfig('some-key', 'default-value');
```
@param string|null $key The key to get or null for the whole config.
@param mixed $default The return value when the key does not exist.
@return mixed Config value being read. | [
"Returns",
"the",
"config",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/InstanceConfigTrait.php#L116-L126 |
210,545 | cakephp/cakephp | src/Core/InstanceConfigTrait.php | InstanceConfigTrait._configRead | protected function _configRead($key)
{
if ($key === null) {
return $this->_config;
}
if (strpos($key, '.') === false) {
return isset($this->_config[$key]) ? $this->_config[$key] : null;
}
$return = $this->_config;
foreach (explode('.', $key) as $k) {
if (!is_array($return) || !isset($return[$k])) {
$return = null;
break;
}
$return = $return[$k];
}
return $return;
} | php | protected function _configRead($key)
{
if ($key === null) {
return $this->_config;
}
if (strpos($key, '.') === false) {
return isset($this->_config[$key]) ? $this->_config[$key] : null;
}
$return = $this->_config;
foreach (explode('.', $key) as $k) {
if (!is_array($return) || !isset($return[$k])) {
$return = null;
break;
}
$return = $return[$k];
}
return $return;
} | [
"protected",
"function",
"_configRead",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_config",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"key",
",",
"'.'",
")",
"===",
"false",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"_config",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"this",
"->",
"_config",
"[",
"$",
"key",
"]",
":",
"null",
";",
"}",
"$",
"return",
"=",
"$",
"this",
"->",
"_config",
";",
"foreach",
"(",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
"as",
"$",
"k",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"return",
")",
"||",
"!",
"isset",
"(",
"$",
"return",
"[",
"$",
"k",
"]",
")",
")",
"{",
"$",
"return",
"=",
"null",
";",
"break",
";",
"}",
"$",
"return",
"=",
"$",
"return",
"[",
"$",
"k",
"]",
";",
"}",
"return",
"$",
"return",
";",
"}"
] | Reads a config key.
@param string|null $key Key to read.
@return mixed | [
"Reads",
"a",
"config",
"key",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/InstanceConfigTrait.php#L234-L256 |
210,546 | cakephp/cakephp | src/Core/InstanceConfigTrait.php | InstanceConfigTrait._configWrite | protected function _configWrite($key, $value, $merge = false)
{
if (is_string($key) && $value === null) {
$this->_configDelete($key);
return;
}
if ($merge) {
$update = is_array($key) ? $key : [$key => $value];
if ($merge === 'shallow') {
$this->_config = array_merge($this->_config, Hash::expand($update));
} else {
$this->_config = Hash::merge($this->_config, Hash::expand($update));
}
return;
}
if (is_array($key)) {
foreach ($key as $k => $val) {
$this->_configWrite($k, $val);
}
return;
}
if (strpos($key, '.') === false) {
$this->_config[$key] = $value;
return;
}
$update =& $this->_config;
$stack = explode('.', $key);
foreach ($stack as $k) {
if (!is_array($update)) {
throw new Exception(sprintf('Cannot set %s value', $key));
}
if (!isset($update[$k])) {
$update[$k] = [];
}
$update =& $update[$k];
}
$update = $value;
} | php | protected function _configWrite($key, $value, $merge = false)
{
if (is_string($key) && $value === null) {
$this->_configDelete($key);
return;
}
if ($merge) {
$update = is_array($key) ? $key : [$key => $value];
if ($merge === 'shallow') {
$this->_config = array_merge($this->_config, Hash::expand($update));
} else {
$this->_config = Hash::merge($this->_config, Hash::expand($update));
}
return;
}
if (is_array($key)) {
foreach ($key as $k => $val) {
$this->_configWrite($k, $val);
}
return;
}
if (strpos($key, '.') === false) {
$this->_config[$key] = $value;
return;
}
$update =& $this->_config;
$stack = explode('.', $key);
foreach ($stack as $k) {
if (!is_array($update)) {
throw new Exception(sprintf('Cannot set %s value', $key));
}
if (!isset($update[$k])) {
$update[$k] = [];
}
$update =& $update[$k];
}
$update = $value;
} | [
"protected",
"function",
"_configWrite",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"merge",
"=",
"false",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"key",
")",
"&&",
"$",
"value",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_configDelete",
"(",
"$",
"key",
")",
";",
"return",
";",
"}",
"if",
"(",
"$",
"merge",
")",
"{",
"$",
"update",
"=",
"is_array",
"(",
"$",
"key",
")",
"?",
"$",
"key",
":",
"[",
"$",
"key",
"=>",
"$",
"value",
"]",
";",
"if",
"(",
"$",
"merge",
"===",
"'shallow'",
")",
"{",
"$",
"this",
"->",
"_config",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"_config",
",",
"Hash",
"::",
"expand",
"(",
"$",
"update",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_config",
"=",
"Hash",
"::",
"merge",
"(",
"$",
"this",
"->",
"_config",
",",
"Hash",
"::",
"expand",
"(",
"$",
"update",
")",
")",
";",
"}",
"return",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"foreach",
"(",
"$",
"key",
"as",
"$",
"k",
"=>",
"$",
"val",
")",
"{",
"$",
"this",
"->",
"_configWrite",
"(",
"$",
"k",
",",
"$",
"val",
")",
";",
"}",
"return",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"key",
",",
"'.'",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"_config",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"return",
";",
"}",
"$",
"update",
"=",
"&",
"$",
"this",
"->",
"_config",
";",
"$",
"stack",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"foreach",
"(",
"$",
"stack",
"as",
"$",
"k",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"update",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'Cannot set %s value'",
",",
"$",
"key",
")",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"update",
"[",
"$",
"k",
"]",
")",
")",
"{",
"$",
"update",
"[",
"$",
"k",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"update",
"=",
"&",
"$",
"update",
"[",
"$",
"k",
"]",
";",
"}",
"$",
"update",
"=",
"$",
"value",
";",
"}"
] | Writes a config key.
@param string|array $key Key to write to.
@param mixed $value Value to write.
@param bool|string $merge True to merge recursively, 'shallow' for simple merge,
false to overwrite, defaults to false.
@return void
@throws \Cake\Core\Exception\Exception if attempting to clobber existing config | [
"Writes",
"a",
"config",
"key",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/InstanceConfigTrait.php#L268-L317 |
210,547 | cakephp/cakephp | src/Core/InstanceConfigTrait.php | InstanceConfigTrait._configDelete | protected function _configDelete($key)
{
if (strpos($key, '.') === false) {
unset($this->_config[$key]);
return;
}
$update =& $this->_config;
$stack = explode('.', $key);
$length = count($stack);
foreach ($stack as $i => $k) {
if (!is_array($update)) {
throw new Exception(sprintf('Cannot unset %s value', $key));
}
if (!isset($update[$k])) {
break;
}
if ($i === $length - 1) {
unset($update[$k]);
break;
}
$update =& $update[$k];
}
} | php | protected function _configDelete($key)
{
if (strpos($key, '.') === false) {
unset($this->_config[$key]);
return;
}
$update =& $this->_config;
$stack = explode('.', $key);
$length = count($stack);
foreach ($stack as $i => $k) {
if (!is_array($update)) {
throw new Exception(sprintf('Cannot unset %s value', $key));
}
if (!isset($update[$k])) {
break;
}
if ($i === $length - 1) {
unset($update[$k]);
break;
}
$update =& $update[$k];
}
} | [
"protected",
"function",
"_configDelete",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"key",
",",
"'.'",
")",
"===",
"false",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"_config",
"[",
"$",
"key",
"]",
")",
";",
"return",
";",
"}",
"$",
"update",
"=",
"&",
"$",
"this",
"->",
"_config",
";",
"$",
"stack",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"$",
"length",
"=",
"count",
"(",
"$",
"stack",
")",
";",
"foreach",
"(",
"$",
"stack",
"as",
"$",
"i",
"=>",
"$",
"k",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"update",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'Cannot unset %s value'",
",",
"$",
"key",
")",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"update",
"[",
"$",
"k",
"]",
")",
")",
"{",
"break",
";",
"}",
"if",
"(",
"$",
"i",
"===",
"$",
"length",
"-",
"1",
")",
"{",
"unset",
"(",
"$",
"update",
"[",
"$",
"k",
"]",
")",
";",
"break",
";",
"}",
"$",
"update",
"=",
"&",
"$",
"update",
"[",
"$",
"k",
"]",
";",
"}",
"}"
] | Deletes a single config key.
@param string $key Key to delete.
@return void
@throws \Cake\Core\Exception\Exception if attempting to clobber existing config | [
"Deletes",
"a",
"single",
"config",
"key",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Core/InstanceConfigTrait.php#L326-L354 |
210,548 | cakephp/cakephp | src/Error/ErrorHandler.php | ErrorHandler._displayException | protected function _displayException($exception)
{
$rendererClassName = App::className($this->_options['exceptionRenderer'], 'Error');
try {
if (!$rendererClassName) {
throw new Exception("$rendererClassName is an invalid class.");
}
/** @var \Cake\Error\ExceptionRendererInterface $renderer */
$renderer = new $rendererClassName($exception);
$response = $renderer->render();
$this->_clearOutput();
$this->_sendResponse($response);
} catch (Throwable $exception) {
$this->_logInternalError($exception);
} catch (Exception $exception) {
$this->_logInternalError($exception);
}
} | php | protected function _displayException($exception)
{
$rendererClassName = App::className($this->_options['exceptionRenderer'], 'Error');
try {
if (!$rendererClassName) {
throw new Exception("$rendererClassName is an invalid class.");
}
/** @var \Cake\Error\ExceptionRendererInterface $renderer */
$renderer = new $rendererClassName($exception);
$response = $renderer->render();
$this->_clearOutput();
$this->_sendResponse($response);
} catch (Throwable $exception) {
$this->_logInternalError($exception);
} catch (Exception $exception) {
$this->_logInternalError($exception);
}
} | [
"protected",
"function",
"_displayException",
"(",
"$",
"exception",
")",
"{",
"$",
"rendererClassName",
"=",
"App",
"::",
"className",
"(",
"$",
"this",
"->",
"_options",
"[",
"'exceptionRenderer'",
"]",
",",
"'Error'",
")",
";",
"try",
"{",
"if",
"(",
"!",
"$",
"rendererClassName",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"$rendererClassName is an invalid class.\"",
")",
";",
"}",
"/** @var \\Cake\\Error\\ExceptionRendererInterface $renderer */",
"$",
"renderer",
"=",
"new",
"$",
"rendererClassName",
"(",
"$",
"exception",
")",
";",
"$",
"response",
"=",
"$",
"renderer",
"->",
"render",
"(",
")",
";",
"$",
"this",
"->",
"_clearOutput",
"(",
")",
";",
"$",
"this",
"->",
"_sendResponse",
"(",
"$",
"response",
")",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"_logInternalError",
"(",
"$",
"exception",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"_logInternalError",
"(",
"$",
"exception",
")",
";",
"}",
"}"
] | Displays an exception response body.
@param \Exception $exception The exception to display.
@return void
@throws \Exception When the chosen exception renderer is invalid. | [
"Displays",
"an",
"exception",
"response",
"body",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Error/ErrorHandler.php#L128-L145 |
210,549 | cakephp/cakephp | src/Error/ErrorHandler.php | ErrorHandler._logInternalError | protected function _logInternalError($exception)
{
// Disable trace for internal errors.
$this->_options['trace'] = false;
$message = sprintf(
"[%s] %s\n%s", // Keeping same message format
get_class($exception),
$exception->getMessage(),
$exception->getTraceAsString()
);
trigger_error($message, E_USER_ERROR);
} | php | protected function _logInternalError($exception)
{
// Disable trace for internal errors.
$this->_options['trace'] = false;
$message = sprintf(
"[%s] %s\n%s", // Keeping same message format
get_class($exception),
$exception->getMessage(),
$exception->getTraceAsString()
);
trigger_error($message, E_USER_ERROR);
} | [
"protected",
"function",
"_logInternalError",
"(",
"$",
"exception",
")",
"{",
"// Disable trace for internal errors.",
"$",
"this",
"->",
"_options",
"[",
"'trace'",
"]",
"=",
"false",
";",
"$",
"message",
"=",
"sprintf",
"(",
"\"[%s] %s\\n%s\"",
",",
"// Keeping same message format",
"get_class",
"(",
"$",
"exception",
")",
",",
"$",
"exception",
"->",
"getMessage",
"(",
")",
",",
"$",
"exception",
"->",
"getTraceAsString",
"(",
")",
")",
";",
"trigger_error",
"(",
"$",
"message",
",",
"E_USER_ERROR",
")",
";",
"}"
] | Logs both PHP5 and PHP7 errors.
The PHP5 part will be removed with 4.0.
@param \Throwable|\Exception $exception Exception.
@return void | [
"Logs",
"both",
"PHP5",
"and",
"PHP7",
"errors",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Error/ErrorHandler.php#L170-L181 |
210,550 | cakephp/cakephp | src/Error/ErrorHandler.php | ErrorHandler._sendResponse | protected function _sendResponse($response)
{
if (is_string($response)) {
echo $response;
return;
}
$emitter = new ResponseEmitter();
$emitter->emit($response);
} | php | protected function _sendResponse($response)
{
if (is_string($response)) {
echo $response;
return;
}
$emitter = new ResponseEmitter();
$emitter->emit($response);
} | [
"protected",
"function",
"_sendResponse",
"(",
"$",
"response",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"response",
")",
")",
"{",
"echo",
"$",
"response",
";",
"return",
";",
"}",
"$",
"emitter",
"=",
"new",
"ResponseEmitter",
"(",
")",
";",
"$",
"emitter",
"->",
"emit",
"(",
"$",
"response",
")",
";",
"}"
] | Method that can be easily stubbed in testing.
@param string|\Cake\Http\Response $response Either the message or response object.
@return void | [
"Method",
"that",
"can",
"be",
"easily",
"stubbed",
"in",
"testing",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Error/ErrorHandler.php#L189-L199 |
210,551 | cakephp/cakephp | src/Http/Client/Response.php | Response._decodeGzipBody | protected function _decodeGzipBody($body)
{
if (!function_exists('gzinflate')) {
throw new RuntimeException('Cannot decompress gzip response body without gzinflate()');
}
$offset = 0;
// Look for gzip 'signature'
if (substr($body, 0, 2) === "\x1f\x8b") {
$offset = 2;
}
// Check the format byte
if (substr($body, $offset, 1) === "\x08") {
return gzinflate(substr($body, $offset + 8));
}
} | php | protected function _decodeGzipBody($body)
{
if (!function_exists('gzinflate')) {
throw new RuntimeException('Cannot decompress gzip response body without gzinflate()');
}
$offset = 0;
// Look for gzip 'signature'
if (substr($body, 0, 2) === "\x1f\x8b") {
$offset = 2;
}
// Check the format byte
if (substr($body, $offset, 1) === "\x08") {
return gzinflate(substr($body, $offset + 8));
}
} | [
"protected",
"function",
"_decodeGzipBody",
"(",
"$",
"body",
")",
"{",
"if",
"(",
"!",
"function_exists",
"(",
"'gzinflate'",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Cannot decompress gzip response body without gzinflate()'",
")",
";",
"}",
"$",
"offset",
"=",
"0",
";",
"// Look for gzip 'signature'",
"if",
"(",
"substr",
"(",
"$",
"body",
",",
"0",
",",
"2",
")",
"===",
"\"\\x1f\\x8b\"",
")",
"{",
"$",
"offset",
"=",
"2",
";",
"}",
"// Check the format byte",
"if",
"(",
"substr",
"(",
"$",
"body",
",",
"$",
"offset",
",",
"1",
")",
"===",
"\"\\x08\"",
")",
"{",
"return",
"gzinflate",
"(",
"substr",
"(",
"$",
"body",
",",
"$",
"offset",
"+",
"8",
")",
")",
";",
"}",
"}"
] | Uncompress a gzip response.
Looks for gzip signatures, and if gzinflate() exists,
the body will be decompressed.
@param string $body Gzip encoded body.
@return string
@throws \RuntimeException When attempting to decode gzip content without gzinflate. | [
"Uncompress",
"a",
"gzip",
"response",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Response.php#L178-L192 |
210,552 | cakephp/cakephp | src/Http/Client/Response.php | Response._parseHeaders | protected function _parseHeaders($headers)
{
foreach ($headers as $key => $value) {
if (substr($value, 0, 5) === 'HTTP/') {
preg_match('/HTTP\/([\d.]+) ([0-9]+)(.*)/i', $value, $matches);
$this->protocol = $matches[1];
$this->code = (int)$matches[2];
$this->reasonPhrase = trim($matches[3]);
continue;
}
if (strpos($value, ':') === false) {
continue;
}
list($name, $value) = explode(':', $value, 2);
$value = trim($value);
$name = trim($name);
$normalized = strtolower($name);
if (isset($this->headers[$name])) {
$this->headers[$name][] = $value;
} else {
$this->headers[$name] = (array)$value;
$this->headerNames[$normalized] = $name;
}
}
} | php | protected function _parseHeaders($headers)
{
foreach ($headers as $key => $value) {
if (substr($value, 0, 5) === 'HTTP/') {
preg_match('/HTTP\/([\d.]+) ([0-9]+)(.*)/i', $value, $matches);
$this->protocol = $matches[1];
$this->code = (int)$matches[2];
$this->reasonPhrase = trim($matches[3]);
continue;
}
if (strpos($value, ':') === false) {
continue;
}
list($name, $value) = explode(':', $value, 2);
$value = trim($value);
$name = trim($name);
$normalized = strtolower($name);
if (isset($this->headers[$name])) {
$this->headers[$name][] = $value;
} else {
$this->headers[$name] = (array)$value;
$this->headerNames[$normalized] = $name;
}
}
} | [
"protected",
"function",
"_parseHeaders",
"(",
"$",
"headers",
")",
"{",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"value",
",",
"0",
",",
"5",
")",
"===",
"'HTTP/'",
")",
"{",
"preg_match",
"(",
"'/HTTP\\/([\\d.]+) ([0-9]+)(.*)/i'",
",",
"$",
"value",
",",
"$",
"matches",
")",
";",
"$",
"this",
"->",
"protocol",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"$",
"this",
"->",
"code",
"=",
"(",
"int",
")",
"$",
"matches",
"[",
"2",
"]",
";",
"$",
"this",
"->",
"reasonPhrase",
"=",
"trim",
"(",
"$",
"matches",
"[",
"3",
"]",
")",
";",
"continue",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"value",
",",
"':'",
")",
"===",
"false",
")",
"{",
"continue",
";",
"}",
"list",
"(",
"$",
"name",
",",
"$",
"value",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"value",
",",
"2",
")",
";",
"$",
"value",
"=",
"trim",
"(",
"$",
"value",
")",
";",
"$",
"name",
"=",
"trim",
"(",
"$",
"name",
")",
";",
"$",
"normalized",
"=",
"strtolower",
"(",
"$",
"name",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"headers",
"[",
"$",
"name",
"]",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"headers",
"[",
"$",
"name",
"]",
"=",
"(",
"array",
")",
"$",
"value",
";",
"$",
"this",
"->",
"headerNames",
"[",
"$",
"normalized",
"]",
"=",
"$",
"name",
";",
"}",
"}",
"}"
] | Parses headers if necessary.
- Decodes the status code and reasonphrase.
- Parses and normalizes header names + values.
@param array $headers Headers to parse.
@return void | [
"Parses",
"headers",
"if",
"necessary",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Response.php#L203-L229 |
210,553 | cakephp/cakephp | src/Http/Client/Response.php | Response.isOk | public function isOk()
{
$codes = [
static::STATUS_OK,
static::STATUS_CREATED,
static::STATUS_ACCEPTED,
static::STATUS_NON_AUTHORITATIVE_INFORMATION,
static::STATUS_NO_CONTENT
];
return in_array($this->code, $codes);
} | php | public function isOk()
{
$codes = [
static::STATUS_OK,
static::STATUS_CREATED,
static::STATUS_ACCEPTED,
static::STATUS_NON_AUTHORITATIVE_INFORMATION,
static::STATUS_NO_CONTENT
];
return in_array($this->code, $codes);
} | [
"public",
"function",
"isOk",
"(",
")",
"{",
"$",
"codes",
"=",
"[",
"static",
"::",
"STATUS_OK",
",",
"static",
"::",
"STATUS_CREATED",
",",
"static",
"::",
"STATUS_ACCEPTED",
",",
"static",
"::",
"STATUS_NON_AUTHORITATIVE_INFORMATION",
",",
"static",
"::",
"STATUS_NO_CONTENT",
"]",
";",
"return",
"in_array",
"(",
"$",
"this",
"->",
"code",
",",
"$",
"codes",
")",
";",
"}"
] | Check if the response was OK
@return bool | [
"Check",
"if",
"the",
"response",
"was",
"OK"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Response.php#L236-L247 |
210,554 | cakephp/cakephp | src/Http/Client/Response.php | Response.isRedirect | public function isRedirect()
{
$codes = [
static::STATUS_MOVED_PERMANENTLY,
static::STATUS_FOUND,
static::STATUS_SEE_OTHER,
static::STATUS_TEMPORARY_REDIRECT,
];
return (
in_array($this->code, $codes) &&
$this->getHeaderLine('Location')
);
} | php | public function isRedirect()
{
$codes = [
static::STATUS_MOVED_PERMANENTLY,
static::STATUS_FOUND,
static::STATUS_SEE_OTHER,
static::STATUS_TEMPORARY_REDIRECT,
];
return (
in_array($this->code, $codes) &&
$this->getHeaderLine('Location')
);
} | [
"public",
"function",
"isRedirect",
"(",
")",
"{",
"$",
"codes",
"=",
"[",
"static",
"::",
"STATUS_MOVED_PERMANENTLY",
",",
"static",
"::",
"STATUS_FOUND",
",",
"static",
"::",
"STATUS_SEE_OTHER",
",",
"static",
"::",
"STATUS_TEMPORARY_REDIRECT",
",",
"]",
";",
"return",
"(",
"in_array",
"(",
"$",
"this",
"->",
"code",
",",
"$",
"codes",
")",
"&&",
"$",
"this",
"->",
"getHeaderLine",
"(",
"'Location'",
")",
")",
";",
"}"
] | Check if the response had a redirect status code.
@return bool | [
"Check",
"if",
"the",
"response",
"had",
"a",
"redirect",
"status",
"code",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Response.php#L254-L267 |
210,555 | cakephp/cakephp | src/Http/Client/Response.php | Response.getEncoding | public function getEncoding()
{
$content = $this->getHeaderLine('content-type');
if (!$content) {
return null;
}
preg_match('/charset\s?=\s?[\'"]?([a-z0-9-_]+)[\'"]?/i', $content, $matches);
if (empty($matches[1])) {
return null;
}
return $matches[1];
} | php | public function getEncoding()
{
$content = $this->getHeaderLine('content-type');
if (!$content) {
return null;
}
preg_match('/charset\s?=\s?[\'"]?([a-z0-9-_]+)[\'"]?/i', $content, $matches);
if (empty($matches[1])) {
return null;
}
return $matches[1];
} | [
"public",
"function",
"getEncoding",
"(",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"getHeaderLine",
"(",
"'content-type'",
")",
";",
"if",
"(",
"!",
"$",
"content",
")",
"{",
"return",
"null",
";",
"}",
"preg_match",
"(",
"'/charset\\s?=\\s?[\\'\"]?([a-z0-9-_]+)[\\'\"]?/i'",
",",
"$",
"content",
",",
"$",
"matches",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"matches",
"[",
"1",
"]",
";",
"}"
] | Get the encoding if it was set.
@return string|null | [
"Get",
"the",
"encoding",
"if",
"it",
"was",
"set",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Response.php#L342-L354 |
210,556 | cakephp/cakephp | src/Http/Client/Response.php | Response.getCookie | public function getCookie($name)
{
$this->buildCookieCollection();
if (!$this->cookies->has($name)) {
return null;
}
return $this->cookies->get($name)->getValue();
} | php | public function getCookie($name)
{
$this->buildCookieCollection();
if (!$this->cookies->has($name)) {
return null;
}
return $this->cookies->get($name)->getValue();
} | [
"public",
"function",
"getCookie",
"(",
"$",
"name",
")",
"{",
"$",
"this",
"->",
"buildCookieCollection",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"cookies",
"->",
"has",
"(",
"$",
"name",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"cookies",
"->",
"get",
"(",
"$",
"name",
")",
"->",
"getValue",
"(",
")",
";",
"}"
] | Get the value of a single cookie.
@param string $name The name of the cookie value.
@return string|array|null Either the cookie's value or null when the cookie is undefined. | [
"Get",
"the",
"value",
"of",
"a",
"single",
"cookie",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Response.php#L447-L455 |
210,557 | cakephp/cakephp | src/Http/Client/Response.php | Response.getCookieData | public function getCookieData($name)
{
$this->buildCookieCollection();
if (!$this->cookies->has($name)) {
return null;
}
$cookie = $this->cookies->get($name);
return $this->convertCookieToArray($cookie);
} | php | public function getCookieData($name)
{
$this->buildCookieCollection();
if (!$this->cookies->has($name)) {
return null;
}
$cookie = $this->cookies->get($name);
return $this->convertCookieToArray($cookie);
} | [
"public",
"function",
"getCookieData",
"(",
"$",
"name",
")",
"{",
"$",
"this",
"->",
"buildCookieCollection",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"cookies",
"->",
"has",
"(",
"$",
"name",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"cookie",
"=",
"$",
"this",
"->",
"cookies",
"->",
"get",
"(",
"$",
"name",
")",
";",
"return",
"$",
"this",
"->",
"convertCookieToArray",
"(",
"$",
"cookie",
")",
";",
"}"
] | Get the full data for a single cookie.
@param string $name The name of the cookie value.
@return array|null Either the cookie's data or null when the cookie is undefined. | [
"Get",
"the",
"full",
"data",
"for",
"a",
"single",
"cookie",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Response.php#L463-L474 |
210,558 | cakephp/cakephp | src/Http/Client/Response.php | Response.convertCookieToArray | protected function convertCookieToArray(CookieInterface $cookie)
{
return [
'name' => $cookie->getName(),
'value' => $cookie->getValue(),
'path' => $cookie->getPath(),
'domain' => $cookie->getDomain(),
'secure' => $cookie->isSecure(),
'httponly' => $cookie->isHttpOnly(),
'expires' => $cookie->getFormattedExpires()
];
} | php | protected function convertCookieToArray(CookieInterface $cookie)
{
return [
'name' => $cookie->getName(),
'value' => $cookie->getValue(),
'path' => $cookie->getPath(),
'domain' => $cookie->getDomain(),
'secure' => $cookie->isSecure(),
'httponly' => $cookie->isHttpOnly(),
'expires' => $cookie->getFormattedExpires()
];
} | [
"protected",
"function",
"convertCookieToArray",
"(",
"CookieInterface",
"$",
"cookie",
")",
"{",
"return",
"[",
"'name'",
"=>",
"$",
"cookie",
"->",
"getName",
"(",
")",
",",
"'value'",
"=>",
"$",
"cookie",
"->",
"getValue",
"(",
")",
",",
"'path'",
"=>",
"$",
"cookie",
"->",
"getPath",
"(",
")",
",",
"'domain'",
"=>",
"$",
"cookie",
"->",
"getDomain",
"(",
")",
",",
"'secure'",
"=>",
"$",
"cookie",
"->",
"isSecure",
"(",
")",
",",
"'httponly'",
"=>",
"$",
"cookie",
"->",
"isHttpOnly",
"(",
")",
",",
"'expires'",
"=>",
"$",
"cookie",
"->",
"getFormattedExpires",
"(",
")",
"]",
";",
"}"
] | Convert the cookie into an array of its properties.
This method is compatible with older client code that
expects date strings instead of timestamps.
@param \Cake\Http\Cookie\CookieInterface $cookie Cookie object.
@return array | [
"Convert",
"the",
"cookie",
"into",
"an",
"array",
"of",
"its",
"properties",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Response.php#L485-L496 |
210,559 | cakephp/cakephp | src/Http/Client/Response.php | Response.body | public function body($parser = null)
{
deprecationWarning(
'Response::body() is deprecated. Use getStringBody()/getJson()/getXml() instead.'
);
$stream = $this->stream;
$stream->rewind();
if ($parser) {
return $parser($stream->getContents());
}
return $stream->getContents();
} | php | public function body($parser = null)
{
deprecationWarning(
'Response::body() is deprecated. Use getStringBody()/getJson()/getXml() instead.'
);
$stream = $this->stream;
$stream->rewind();
if ($parser) {
return $parser($stream->getContents());
}
return $stream->getContents();
} | [
"public",
"function",
"body",
"(",
"$",
"parser",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"'Response::body() is deprecated. Use getStringBody()/getJson()/getXml() instead.'",
")",
";",
"$",
"stream",
"=",
"$",
"this",
"->",
"stream",
";",
"$",
"stream",
"->",
"rewind",
"(",
")",
";",
"if",
"(",
"$",
"parser",
")",
"{",
"return",
"$",
"parser",
"(",
"$",
"stream",
"->",
"getContents",
"(",
")",
")",
";",
"}",
"return",
"$",
"stream",
"->",
"getContents",
"(",
")",
";",
"}"
] | Get the response body.
By passing in a $parser callable, you can get the decoded
response content back.
For example to get the json data as an object:
```
$body = $response->body('json_decode');
```
@param callable|null $parser The callback to use to decode
the response body.
@return mixed The response body.
@deprecated 3.7.0 Use getStringBody()/getJson()/getXml() instead. | [
"Get",
"the",
"response",
"body",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Response.php#L561-L574 |
210,560 | cakephp/cakephp | src/Http/Client/Response.php | Response._getJson | protected function _getJson()
{
if ($this->_json) {
return $this->_json;
}
return $this->_json = json_decode($this->_getBody(), true);
} | php | protected function _getJson()
{
if ($this->_json) {
return $this->_json;
}
return $this->_json = json_decode($this->_getBody(), true);
} | [
"protected",
"function",
"_getJson",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_json",
")",
"{",
"return",
"$",
"this",
"->",
"_json",
";",
"}",
"return",
"$",
"this",
"->",
"_json",
"=",
"json_decode",
"(",
"$",
"this",
"->",
"_getBody",
"(",
")",
",",
"true",
")",
";",
"}"
] | Get the response body as JSON decoded data.
@return array|null | [
"Get",
"the",
"response",
"body",
"as",
"JSON",
"decoded",
"data",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Response.php#L601-L608 |
210,561 | cakephp/cakephp | src/Http/Client/Response.php | Response._getXml | protected function _getXml()
{
if ($this->_xml) {
return $this->_xml;
}
libxml_use_internal_errors();
$data = simplexml_load_string($this->_getBody());
if ($data) {
$this->_xml = $data;
return $this->_xml;
}
return null;
} | php | protected function _getXml()
{
if ($this->_xml) {
return $this->_xml;
}
libxml_use_internal_errors();
$data = simplexml_load_string($this->_getBody());
if ($data) {
$this->_xml = $data;
return $this->_xml;
}
return null;
} | [
"protected",
"function",
"_getXml",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_xml",
")",
"{",
"return",
"$",
"this",
"->",
"_xml",
";",
"}",
"libxml_use_internal_errors",
"(",
")",
";",
"$",
"data",
"=",
"simplexml_load_string",
"(",
"$",
"this",
"->",
"_getBody",
"(",
")",
")",
";",
"if",
"(",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"_xml",
"=",
"$",
"data",
";",
"return",
"$",
"this",
"->",
"_xml",
";",
"}",
"return",
"null",
";",
"}"
] | Get the response body as XML decoded data.
@return null|\SimpleXMLElement | [
"Get",
"the",
"response",
"body",
"as",
"XML",
"decoded",
"data",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Http/Client/Response.php#L625-L639 |
210,562 | cakephp/cakephp | src/Database/Statement/CallbackStatement.php | CallbackStatement.fetch | public function fetch($type = parent::FETCH_TYPE_NUM)
{
$callback = $this->_callback;
$row = $this->_statement->fetch($type);
return $row === false ? $row : $callback($row);
} | php | public function fetch($type = parent::FETCH_TYPE_NUM)
{
$callback = $this->_callback;
$row = $this->_statement->fetch($type);
return $row === false ? $row : $callback($row);
} | [
"public",
"function",
"fetch",
"(",
"$",
"type",
"=",
"parent",
"::",
"FETCH_TYPE_NUM",
")",
"{",
"$",
"callback",
"=",
"$",
"this",
"->",
"_callback",
";",
"$",
"row",
"=",
"$",
"this",
"->",
"_statement",
"->",
"fetch",
"(",
"$",
"type",
")",
";",
"return",
"$",
"row",
"===",
"false",
"?",
"$",
"row",
":",
"$",
"callback",
"(",
"$",
"row",
")",
";",
"}"
] | Fetch a row from the statement.
The result will be processed by the callback when it is not `false`.
@param string $type Either 'num' or 'assoc' to indicate the result format you would like.
@return array|false | [
"Fetch",
"a",
"row",
"from",
"the",
"statement",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Statement/CallbackStatement.php#L54-L60 |
210,563 | cakephp/cakephp | src/Database/Statement/CallbackStatement.php | CallbackStatement.fetchAll | public function fetchAll($type = parent::FETCH_TYPE_NUM)
{
return array_map($this->_callback, $this->_statement->fetchAll($type));
} | php | public function fetchAll($type = parent::FETCH_TYPE_NUM)
{
return array_map($this->_callback, $this->_statement->fetchAll($type));
} | [
"public",
"function",
"fetchAll",
"(",
"$",
"type",
"=",
"parent",
"::",
"FETCH_TYPE_NUM",
")",
"{",
"return",
"array_map",
"(",
"$",
"this",
"->",
"_callback",
",",
"$",
"this",
"->",
"_statement",
"->",
"fetchAll",
"(",
"$",
"type",
")",
")",
";",
"}"
] | Fetch all rows from the statement.
Each row in the result will be processed by the callback when it is not `false.
@param string $type Either 'num' or 'assoc' to indicate the result format you would like.
@return array | [
"Fetch",
"all",
"rows",
"from",
"the",
"statement",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Statement/CallbackStatement.php#L70-L73 |
210,564 | cakephp/cakephp | src/Database/Driver/PDODriverTrait.php | PDODriverTrait.connection | public function connection($connection = null)
{
if ($connection !== null) {
$this->_connection = $connection;
}
return $this->_connection;
} | php | public function connection($connection = null)
{
if ($connection !== null) {
$this->_connection = $connection;
}
return $this->_connection;
} | [
"public",
"function",
"connection",
"(",
"$",
"connection",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"connection",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"_connection",
"=",
"$",
"connection",
";",
"}",
"return",
"$",
"this",
"->",
"_connection",
";",
"}"
] | Returns correct connection resource or object that is internally used
If first argument is passed, it will set internal connection object or
result to the value passed
@param null|\PDO $connection The PDO connection instance.
@return \PDO connection object used internally | [
"Returns",
"correct",
"connection",
"resource",
"or",
"object",
"that",
"is",
"internally",
"used",
"If",
"first",
"argument",
"is",
"passed",
"it",
"will",
"set",
"internal",
"connection",
"object",
"or",
"result",
"to",
"the",
"value",
"passed"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Driver/PDODriverTrait.php#L65-L72 |
210,565 | cakephp/cakephp | src/Database/Driver/PDODriverTrait.php | PDODriverTrait.isConnected | public function isConnected()
{
if ($this->_connection === null) {
$connected = false;
} else {
try {
$connected = $this->_connection->query('SELECT 1');
} catch (PDOException $e) {
$connected = false;
}
}
return (bool)$connected;
} | php | public function isConnected()
{
if ($this->_connection === null) {
$connected = false;
} else {
try {
$connected = $this->_connection->query('SELECT 1');
} catch (PDOException $e) {
$connected = false;
}
}
return (bool)$connected;
} | [
"public",
"function",
"isConnected",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_connection",
"===",
"null",
")",
"{",
"$",
"connected",
"=",
"false",
";",
"}",
"else",
"{",
"try",
"{",
"$",
"connected",
"=",
"$",
"this",
"->",
"_connection",
"->",
"query",
"(",
"'SELECT 1'",
")",
";",
"}",
"catch",
"(",
"PDOException",
"$",
"e",
")",
"{",
"$",
"connected",
"=",
"false",
";",
"}",
"}",
"return",
"(",
"bool",
")",
"$",
"connected",
";",
"}"
] | Checks whether or not the driver is connected.
@return bool | [
"Checks",
"whether",
"or",
"not",
"the",
"driver",
"is",
"connected",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Driver/PDODriverTrait.php#L89-L102 |
210,566 | cakephp/cakephp | src/Database/Driver/PDODriverTrait.php | PDODriverTrait.beginTransaction | public function beginTransaction()
{
$this->connect();
if ($this->_connection->inTransaction()) {
return true;
}
return $this->_connection->beginTransaction();
} | php | public function beginTransaction()
{
$this->connect();
if ($this->_connection->inTransaction()) {
return true;
}
return $this->_connection->beginTransaction();
} | [
"public",
"function",
"beginTransaction",
"(",
")",
"{",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_connection",
"->",
"inTransaction",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"$",
"this",
"->",
"_connection",
"->",
"beginTransaction",
"(",
")",
";",
"}"
] | Starts a transaction
@return bool true on success, false otherwise | [
"Starts",
"a",
"transaction"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Driver/PDODriverTrait.php#L124-L132 |
210,567 | cakephp/cakephp | src/Database/Driver/PDODriverTrait.php | PDODriverTrait.quote | public function quote($value, $type)
{
$this->connect();
return $this->_connection->quote($value, $type);
} | php | public function quote($value, $type)
{
$this->connect();
return $this->_connection->quote($value, $type);
} | [
"public",
"function",
"quote",
"(",
"$",
"value",
",",
"$",
"type",
")",
"{",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"return",
"$",
"this",
"->",
"_connection",
"->",
"quote",
"(",
"$",
"value",
",",
"$",
"type",
")",
";",
"}"
] | Returns a value in a safe representation to be used in a query string
@param mixed $value The value to quote.
@param string $type Type to be used for determining kind of quoting to perform
@return string | [
"Returns",
"a",
"value",
"in",
"a",
"safe",
"representation",
"to",
"be",
"used",
"in",
"a",
"query",
"string"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Driver/PDODriverTrait.php#L171-L176 |
210,568 | cakephp/cakephp | src/Database/Driver/PDODriverTrait.php | PDODriverTrait.lastInsertId | public function lastInsertId($table = null, $column = null)
{
$this->connect();
return $this->_connection->lastInsertId($table);
} | php | public function lastInsertId($table = null, $column = null)
{
$this->connect();
return $this->_connection->lastInsertId($table);
} | [
"public",
"function",
"lastInsertId",
"(",
"$",
"table",
"=",
"null",
",",
"$",
"column",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"return",
"$",
"this",
"->",
"_connection",
"->",
"lastInsertId",
"(",
"$",
"table",
")",
";",
"}"
] | Returns last id generated for a table or sequence in database
@param string|null $table table name or sequence to get last insert value from
@param string|null $column the name of the column representing the primary key
@return string|int | [
"Returns",
"last",
"id",
"generated",
"for",
"a",
"table",
"or",
"sequence",
"in",
"database"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Driver/PDODriverTrait.php#L185-L190 |
210,569 | cakephp/cakephp | src/Log/Log.php | Log._loadConfig | protected static function _loadConfig()
{
foreach (static::$_config as $name => $properties) {
if (isset($properties['engine'])) {
$properties['className'] = $properties['engine'];
}
if (!static::$_registry->has($name)) {
static::$_registry->load($name, $properties);
}
}
} | php | protected static function _loadConfig()
{
foreach (static::$_config as $name => $properties) {
if (isset($properties['engine'])) {
$properties['className'] = $properties['engine'];
}
if (!static::$_registry->has($name)) {
static::$_registry->load($name, $properties);
}
}
} | [
"protected",
"static",
"function",
"_loadConfig",
"(",
")",
"{",
"foreach",
"(",
"static",
"::",
"$",
"_config",
"as",
"$",
"name",
"=>",
"$",
"properties",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"properties",
"[",
"'engine'",
"]",
")",
")",
"{",
"$",
"properties",
"[",
"'className'",
"]",
"=",
"$",
"properties",
"[",
"'engine'",
"]",
";",
"}",
"if",
"(",
"!",
"static",
"::",
"$",
"_registry",
"->",
"has",
"(",
"$",
"name",
")",
")",
"{",
"static",
"::",
"$",
"_registry",
"->",
"load",
"(",
"$",
"name",
",",
"$",
"properties",
")",
";",
"}",
"}",
"}"
] | Load the defined configuration and create all the defined logging
adapters.
@return void | [
"Load",
"the",
"defined",
"configuration",
"and",
"create",
"all",
"the",
"defined",
"logging",
"adapters",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Log/Log.php#L191-L201 |
210,570 | cakephp/cakephp | src/Database/Log/QueryLogger.php | QueryLogger.log | public function log(LoggedQuery $query)
{
if (!empty($query->params)) {
$query->query = $this->_interpolate($query);
}
$this->_log($query);
} | php | public function log(LoggedQuery $query)
{
if (!empty($query->params)) {
$query->query = $this->_interpolate($query);
}
$this->_log($query);
} | [
"public",
"function",
"log",
"(",
"LoggedQuery",
"$",
"query",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"query",
"->",
"params",
")",
")",
"{",
"$",
"query",
"->",
"query",
"=",
"$",
"this",
"->",
"_interpolate",
"(",
"$",
"query",
")",
";",
"}",
"$",
"this",
"->",
"_log",
"(",
"$",
"query",
")",
";",
"}"
] | Writes a LoggedQuery into a log
@param \Cake\Database\Log\LoggedQuery $query to be written in log
@return void | [
"Writes",
"a",
"LoggedQuery",
"into",
"a",
"log"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Log/QueryLogger.php#L34-L40 |
210,571 | cakephp/cakephp | src/Database/Log/QueryLogger.php | QueryLogger._interpolate | protected function _interpolate($query)
{
$params = array_map(function ($p) {
if ($p === null) {
return 'NULL';
}
if (is_bool($p)) {
return $p ? '1' : '0';
}
if (is_string($p)) {
$replacements = [
'$' => '\\$',
'\\' => '\\\\\\\\',
"'" => "''",
];
$p = strtr($p, $replacements);
return "'$p'";
}
return $p;
}, $query->params);
$keys = [];
$limit = is_int(key($params)) ? 1 : -1;
foreach ($params as $key => $param) {
$keys[] = is_string($key) ? "/:$key\b/" : '/[?]/';
}
return preg_replace($keys, $params, $query->query, $limit);
} | php | protected function _interpolate($query)
{
$params = array_map(function ($p) {
if ($p === null) {
return 'NULL';
}
if (is_bool($p)) {
return $p ? '1' : '0';
}
if (is_string($p)) {
$replacements = [
'$' => '\\$',
'\\' => '\\\\\\\\',
"'" => "''",
];
$p = strtr($p, $replacements);
return "'$p'";
}
return $p;
}, $query->params);
$keys = [];
$limit = is_int(key($params)) ? 1 : -1;
foreach ($params as $key => $param) {
$keys[] = is_string($key) ? "/:$key\b/" : '/[?]/';
}
return preg_replace($keys, $params, $query->query, $limit);
} | [
"protected",
"function",
"_interpolate",
"(",
"$",
"query",
")",
"{",
"$",
"params",
"=",
"array_map",
"(",
"function",
"(",
"$",
"p",
")",
"{",
"if",
"(",
"$",
"p",
"===",
"null",
")",
"{",
"return",
"'NULL'",
";",
"}",
"if",
"(",
"is_bool",
"(",
"$",
"p",
")",
")",
"{",
"return",
"$",
"p",
"?",
"'1'",
":",
"'0'",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"p",
")",
")",
"{",
"$",
"replacements",
"=",
"[",
"'$'",
"=>",
"'\\\\$'",
",",
"'\\\\'",
"=>",
"'\\\\\\\\\\\\\\\\'",
",",
"\"'\"",
"=>",
"\"''\"",
",",
"]",
";",
"$",
"p",
"=",
"strtr",
"(",
"$",
"p",
",",
"$",
"replacements",
")",
";",
"return",
"\"'$p'\"",
";",
"}",
"return",
"$",
"p",
";",
"}",
",",
"$",
"query",
"->",
"params",
")",
";",
"$",
"keys",
"=",
"[",
"]",
";",
"$",
"limit",
"=",
"is_int",
"(",
"key",
"(",
"$",
"params",
")",
")",
"?",
"1",
":",
"-",
"1",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"key",
"=>",
"$",
"param",
")",
"{",
"$",
"keys",
"[",
"]",
"=",
"is_string",
"(",
"$",
"key",
")",
"?",
"\"/:$key\\b/\"",
":",
"'/[?]/'",
";",
"}",
"return",
"preg_replace",
"(",
"$",
"keys",
",",
"$",
"params",
",",
"$",
"query",
"->",
"query",
",",
"$",
"limit",
")",
";",
"}"
] | Helper function used to replace query placeholders by the real
params used to execute the query
@param \Cake\Database\Log\LoggedQuery $query The query to log
@return string | [
"Helper",
"function",
"used",
"to",
"replace",
"query",
"placeholders",
"by",
"the",
"real",
"params",
"used",
"to",
"execute",
"the",
"query"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Log/QueryLogger.php#L61-L93 |
210,572 | cakephp/cakephp | src/View/StringTemplateTrait.php | StringTemplateTrait.templater | public function templater()
{
if ($this->_templater === null) {
$class = $this->getConfig('templateClass') ?: 'Cake\View\StringTemplate';
$this->_templater = new $class();
$templates = $this->getConfig('templates');
if ($templates) {
if (is_string($templates)) {
$this->_templater->add($this->_defaultConfig['templates']);
$this->_templater->load($templates);
} else {
$this->_templater->add($templates);
}
}
}
return $this->_templater;
} | php | public function templater()
{
if ($this->_templater === null) {
$class = $this->getConfig('templateClass') ?: 'Cake\View\StringTemplate';
$this->_templater = new $class();
$templates = $this->getConfig('templates');
if ($templates) {
if (is_string($templates)) {
$this->_templater->add($this->_defaultConfig['templates']);
$this->_templater->load($templates);
} else {
$this->_templater->add($templates);
}
}
}
return $this->_templater;
} | [
"public",
"function",
"templater",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_templater",
"===",
"null",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'templateClass'",
")",
"?",
":",
"'Cake\\View\\StringTemplate'",
";",
"$",
"this",
"->",
"_templater",
"=",
"new",
"$",
"class",
"(",
")",
";",
"$",
"templates",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'templates'",
")",
";",
"if",
"(",
"$",
"templates",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"templates",
")",
")",
"{",
"$",
"this",
"->",
"_templater",
"->",
"add",
"(",
"$",
"this",
"->",
"_defaultConfig",
"[",
"'templates'",
"]",
")",
";",
"$",
"this",
"->",
"_templater",
"->",
"load",
"(",
"$",
"templates",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_templater",
"->",
"add",
"(",
"$",
"templates",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"_templater",
";",
"}"
] | Returns the templater instance.
@return \Cake\View\StringTemplate | [
"Returns",
"the",
"templater",
"instance",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/StringTemplateTrait.php#L100-L118 |
210,573 | cakephp/cakephp | src/Cache/Engine/WincacheEngine.php | WincacheEngine.clear | public function clear($check)
{
if ($check) {
return true;
}
$info = wincache_ucache_info();
$cacheKeys = $info['ucache_entries'];
unset($info);
foreach ($cacheKeys as $key) {
if (strpos($key['key_name'], $this->_config['prefix']) === 0) {
wincache_ucache_delete($key['key_name']);
}
}
return true;
} | php | public function clear($check)
{
if ($check) {
return true;
}
$info = wincache_ucache_info();
$cacheKeys = $info['ucache_entries'];
unset($info);
foreach ($cacheKeys as $key) {
if (strpos($key['key_name'], $this->_config['prefix']) === 0) {
wincache_ucache_delete($key['key_name']);
}
}
return true;
} | [
"public",
"function",
"clear",
"(",
"$",
"check",
")",
"{",
"if",
"(",
"$",
"check",
")",
"{",
"return",
"true",
";",
"}",
"$",
"info",
"=",
"wincache_ucache_info",
"(",
")",
";",
"$",
"cacheKeys",
"=",
"$",
"info",
"[",
"'ucache_entries'",
"]",
";",
"unset",
"(",
"$",
"info",
")",
";",
"foreach",
"(",
"$",
"cacheKeys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"key",
"[",
"'key_name'",
"]",
",",
"$",
"this",
"->",
"_config",
"[",
"'prefix'",
"]",
")",
"===",
"0",
")",
"{",
"wincache_ucache_delete",
"(",
"$",
"key",
"[",
"'key_name'",
"]",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Delete all keys from the cache. This will clear every
item in the cache matching the cache config prefix.
@param bool $check If true, nothing will be cleared, as entries will
naturally expire in wincache..
@return bool True Returns true. | [
"Delete",
"all",
"keys",
"from",
"the",
"cache",
".",
"This",
"will",
"clear",
"every",
"item",
"in",
"the",
"cache",
"matching",
"the",
"cache",
"config",
"prefix",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/Engine/WincacheEngine.php#L132-L147 |
210,574 | cakephp/cakephp | src/Database/Expression/ValuesExpression.php | ValuesExpression.add | public function add($data)
{
if ((count($this->_values) && $data instanceof Query) ||
($this->_query && is_array($data))
) {
throw new Exception(
'You cannot mix subqueries and array data in inserts.'
);
}
if ($data instanceof Query) {
$this->setQuery($data);
return;
}
$this->_values[] = $data;
$this->_castedExpressions = false;
} | php | public function add($data)
{
if ((count($this->_values) && $data instanceof Query) ||
($this->_query && is_array($data))
) {
throw new Exception(
'You cannot mix subqueries and array data in inserts.'
);
}
if ($data instanceof Query) {
$this->setQuery($data);
return;
}
$this->_values[] = $data;
$this->_castedExpressions = false;
} | [
"public",
"function",
"add",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"(",
"count",
"(",
"$",
"this",
"->",
"_values",
")",
"&&",
"$",
"data",
"instanceof",
"Query",
")",
"||",
"(",
"$",
"this",
"->",
"_query",
"&&",
"is_array",
"(",
"$",
"data",
")",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'You cannot mix subqueries and array data in inserts.'",
")",
";",
"}",
"if",
"(",
"$",
"data",
"instanceof",
"Query",
")",
"{",
"$",
"this",
"->",
"setQuery",
"(",
"$",
"data",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"_values",
"[",
"]",
"=",
"$",
"data",
";",
"$",
"this",
"->",
"_castedExpressions",
"=",
"false",
";",
"}"
] | Add a row of data to be inserted.
@param array|\Cake\Database\Query $data Array of data to append into the insert, or
a query for doing INSERT INTO .. SELECT style commands
@return void
@throws \Cake\Database\Exception When mixing array + Query data types. | [
"Add",
"a",
"row",
"of",
"data",
"to",
"be",
"inserted",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/ValuesExpression.php#L85-L101 |
210,575 | cakephp/cakephp | src/Database/Expression/ValuesExpression.php | ValuesExpression.columns | public function columns($cols = null)
{
deprecationWarning(
'ValuesExpression::columns() is deprecated. ' .
'Use ValuesExpression::setColumns()/getColumns() instead.'
);
if ($cols !== null) {
return $this->setColumns($cols);
}
return $this->getColumns();
} | php | public function columns($cols = null)
{
deprecationWarning(
'ValuesExpression::columns() is deprecated. ' .
'Use ValuesExpression::setColumns()/getColumns() instead.'
);
if ($cols !== null) {
return $this->setColumns($cols);
}
return $this->getColumns();
} | [
"public",
"function",
"columns",
"(",
"$",
"cols",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"'ValuesExpression::columns() is deprecated. '",
".",
"'Use ValuesExpression::setColumns()/getColumns() instead.'",
")",
";",
"if",
"(",
"$",
"cols",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"setColumns",
"(",
"$",
"cols",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getColumns",
"(",
")",
";",
"}"
] | Sets the columns to be inserted. If no params are passed, then it returns
the currently stored columns.
@deprecated 3.4.0 Use setColumns()/getColumns() instead.
@param array|null $cols Array with columns to be inserted.
@return array|$this | [
"Sets",
"the",
"columns",
"to",
"be",
"inserted",
".",
"If",
"no",
"params",
"are",
"passed",
"then",
"it",
"returns",
"the",
"currently",
"stored",
"columns",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/ValuesExpression.php#L135-L146 |
210,576 | cakephp/cakephp | src/Database/Expression/ValuesExpression.php | ValuesExpression._columnNames | protected function _columnNames()
{
$columns = [];
foreach ($this->_columns as $col) {
if (is_string($col)) {
$col = trim($col, '`[]"');
}
$columns[] = $col;
}
return $columns;
} | php | protected function _columnNames()
{
$columns = [];
foreach ($this->_columns as $col) {
if (is_string($col)) {
$col = trim($col, '`[]"');
}
$columns[] = $col;
}
return $columns;
} | [
"protected",
"function",
"_columnNames",
"(",
")",
"{",
"$",
"columns",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_columns",
"as",
"$",
"col",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"col",
")",
")",
"{",
"$",
"col",
"=",
"trim",
"(",
"$",
"col",
",",
"'`[]\"'",
")",
";",
"}",
"$",
"columns",
"[",
"]",
"=",
"$",
"col",
";",
"}",
"return",
"$",
"columns",
";",
"}"
] | Get the bare column names.
Because column names could be identifier quoted, we
need to strip the identifiers off of the columns.
@return array | [
"Get",
"the",
"bare",
"column",
"names",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/ValuesExpression.php#L156-L167 |
210,577 | cakephp/cakephp | src/Database/Expression/ValuesExpression.php | ValuesExpression.values | public function values($values = null)
{
deprecationWarning(
'ValuesExpression::values() is deprecated. ' .
'Use ValuesExpression::setValues()/getValues() instead.'
);
if ($values !== null) {
return $this->setValues($values);
}
return $this->getValues();
} | php | public function values($values = null)
{
deprecationWarning(
'ValuesExpression::values() is deprecated. ' .
'Use ValuesExpression::setValues()/getValues() instead.'
);
if ($values !== null) {
return $this->setValues($values);
}
return $this->getValues();
} | [
"public",
"function",
"values",
"(",
"$",
"values",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"'ValuesExpression::values() is deprecated. '",
".",
"'Use ValuesExpression::setValues()/getValues() instead.'",
")",
";",
"if",
"(",
"$",
"values",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"setValues",
"(",
"$",
"values",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getValues",
"(",
")",
";",
"}"
] | Sets the values to be inserted. If no params are passed, then it returns
the currently stored values
@deprecated 3.4.0 Use setValues()/getValues() instead.
@param array|null $values Array with values to be inserted.
@return array|$this | [
"Sets",
"the",
"values",
"to",
"be",
"inserted",
".",
"If",
"no",
"params",
"are",
"passed",
"then",
"it",
"returns",
"the",
"currently",
"stored",
"values"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/ValuesExpression.php#L205-L216 |
210,578 | cakephp/cakephp | src/Database/Expression/ValuesExpression.php | ValuesExpression.query | public function query(Query $query = null)
{
deprecationWarning(
'ValuesExpression::query() is deprecated. ' .
'Use ValuesExpression::setQuery()/getQuery() instead.'
);
if ($query !== null) {
return $this->setQuery($query);
}
return $this->getQuery();
} | php | public function query(Query $query = null)
{
deprecationWarning(
'ValuesExpression::query() is deprecated. ' .
'Use ValuesExpression::setQuery()/getQuery() instead.'
);
if ($query !== null) {
return $this->setQuery($query);
}
return $this->getQuery();
} | [
"public",
"function",
"query",
"(",
"Query",
"$",
"query",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"'ValuesExpression::query() is deprecated. '",
".",
"'Use ValuesExpression::setQuery()/getQuery() instead.'",
")",
";",
"if",
"(",
"$",
"query",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"setQuery",
"(",
"$",
"query",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getQuery",
"(",
")",
";",
"}"
] | Sets the query object to be used as the values expression to be evaluated
to insert records in the table. If no params are passed, then it returns
the currently stored query
@deprecated 3.4.0 Use setQuery()/getQuery() instead.
@param \Cake\Database\Query|null $query The query to set
@return \Cake\Database\Query|null|$this | [
"Sets",
"the",
"query",
"object",
"to",
"be",
"used",
"as",
"the",
"values",
"expression",
"to",
"be",
"evaluated",
"to",
"insert",
"records",
"in",
"the",
"table",
".",
"If",
"no",
"params",
"are",
"passed",
"then",
"it",
"returns",
"the",
"currently",
"stored",
"query"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/ValuesExpression.php#L252-L263 |
210,579 | cakephp/cakephp | src/Database/Expression/ValuesExpression.php | ValuesExpression.sql | public function sql(ValueBinder $generator)
{
if (empty($this->_values) && empty($this->_query)) {
return '';
}
if (!$this->_castedExpressions) {
$this->_processExpressions();
}
$columns = $this->_columnNames();
$defaults = array_fill_keys($columns, null);
$placeholders = [];
$types = [];
$typeMap = $this->getTypeMap();
foreach ($defaults as $col => $v) {
$types[$col] = $typeMap->type($col);
}
foreach ($this->_values as $row) {
$row += $defaults;
$rowPlaceholders = [];
foreach ($columns as $column) {
$value = $row[$column];
if ($value instanceof ExpressionInterface) {
$rowPlaceholders[] = '(' . $value->sql($generator) . ')';
continue;
}
$placeholder = $generator->placeholder('c');
$rowPlaceholders[] = $placeholder;
$generator->bind($placeholder, $value, $types[$column]);
}
$placeholders[] = implode(', ', $rowPlaceholders);
}
if ($this->getQuery()) {
return ' ' . $this->getQuery()->sql($generator);
}
return sprintf(' VALUES (%s)', implode('), (', $placeholders));
} | php | public function sql(ValueBinder $generator)
{
if (empty($this->_values) && empty($this->_query)) {
return '';
}
if (!$this->_castedExpressions) {
$this->_processExpressions();
}
$columns = $this->_columnNames();
$defaults = array_fill_keys($columns, null);
$placeholders = [];
$types = [];
$typeMap = $this->getTypeMap();
foreach ($defaults as $col => $v) {
$types[$col] = $typeMap->type($col);
}
foreach ($this->_values as $row) {
$row += $defaults;
$rowPlaceholders = [];
foreach ($columns as $column) {
$value = $row[$column];
if ($value instanceof ExpressionInterface) {
$rowPlaceholders[] = '(' . $value->sql($generator) . ')';
continue;
}
$placeholder = $generator->placeholder('c');
$rowPlaceholders[] = $placeholder;
$generator->bind($placeholder, $value, $types[$column]);
}
$placeholders[] = implode(', ', $rowPlaceholders);
}
if ($this->getQuery()) {
return ' ' . $this->getQuery()->sql($generator);
}
return sprintf(' VALUES (%s)', implode('), (', $placeholders));
} | [
"public",
"function",
"sql",
"(",
"ValueBinder",
"$",
"generator",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_values",
")",
"&&",
"empty",
"(",
"$",
"this",
"->",
"_query",
")",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"_castedExpressions",
")",
"{",
"$",
"this",
"->",
"_processExpressions",
"(",
")",
";",
"}",
"$",
"columns",
"=",
"$",
"this",
"->",
"_columnNames",
"(",
")",
";",
"$",
"defaults",
"=",
"array_fill_keys",
"(",
"$",
"columns",
",",
"null",
")",
";",
"$",
"placeholders",
"=",
"[",
"]",
";",
"$",
"types",
"=",
"[",
"]",
";",
"$",
"typeMap",
"=",
"$",
"this",
"->",
"getTypeMap",
"(",
")",
";",
"foreach",
"(",
"$",
"defaults",
"as",
"$",
"col",
"=>",
"$",
"v",
")",
"{",
"$",
"types",
"[",
"$",
"col",
"]",
"=",
"$",
"typeMap",
"->",
"type",
"(",
"$",
"col",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"_values",
"as",
"$",
"row",
")",
"{",
"$",
"row",
"+=",
"$",
"defaults",
";",
"$",
"rowPlaceholders",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"column",
")",
"{",
"$",
"value",
"=",
"$",
"row",
"[",
"$",
"column",
"]",
";",
"if",
"(",
"$",
"value",
"instanceof",
"ExpressionInterface",
")",
"{",
"$",
"rowPlaceholders",
"[",
"]",
"=",
"'('",
".",
"$",
"value",
"->",
"sql",
"(",
"$",
"generator",
")",
".",
"')'",
";",
"continue",
";",
"}",
"$",
"placeholder",
"=",
"$",
"generator",
"->",
"placeholder",
"(",
"'c'",
")",
";",
"$",
"rowPlaceholders",
"[",
"]",
"=",
"$",
"placeholder",
";",
"$",
"generator",
"->",
"bind",
"(",
"$",
"placeholder",
",",
"$",
"value",
",",
"$",
"types",
"[",
"$",
"column",
"]",
")",
";",
"}",
"$",
"placeholders",
"[",
"]",
"=",
"implode",
"(",
"', '",
",",
"$",
"rowPlaceholders",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getQuery",
"(",
")",
")",
"{",
"return",
"' '",
".",
"$",
"this",
"->",
"getQuery",
"(",
")",
"->",
"sql",
"(",
"$",
"generator",
")",
";",
"}",
"return",
"sprintf",
"(",
"' VALUES (%s)'",
",",
"implode",
"(",
"'), ('",
",",
"$",
"placeholders",
")",
")",
";",
"}"
] | Convert the values into a SQL string with placeholders.
@param \Cake\Database\ValueBinder $generator Placeholder generator object
@return string | [
"Convert",
"the",
"values",
"into",
"a",
"SQL",
"string",
"with",
"placeholders",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/ValuesExpression.php#L271-L316 |
210,580 | cakephp/cakephp | src/Database/Expression/ValuesExpression.php | ValuesExpression.traverse | public function traverse(callable $visitor)
{
if ($this->_query) {
return;
}
if (!$this->_castedExpressions) {
$this->_processExpressions();
}
foreach ($this->_values as $v) {
if ($v instanceof ExpressionInterface) {
$v->traverse($visitor);
}
if (!is_array($v)) {
continue;
}
foreach ($v as $column => $field) {
if ($field instanceof ExpressionInterface) {
$visitor($field);
$field->traverse($visitor);
}
}
}
} | php | public function traverse(callable $visitor)
{
if ($this->_query) {
return;
}
if (!$this->_castedExpressions) {
$this->_processExpressions();
}
foreach ($this->_values as $v) {
if ($v instanceof ExpressionInterface) {
$v->traverse($visitor);
}
if (!is_array($v)) {
continue;
}
foreach ($v as $column => $field) {
if ($field instanceof ExpressionInterface) {
$visitor($field);
$field->traverse($visitor);
}
}
}
} | [
"public",
"function",
"traverse",
"(",
"callable",
"$",
"visitor",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_query",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"_castedExpressions",
")",
"{",
"$",
"this",
"->",
"_processExpressions",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"_values",
"as",
"$",
"v",
")",
"{",
"if",
"(",
"$",
"v",
"instanceof",
"ExpressionInterface",
")",
"{",
"$",
"v",
"->",
"traverse",
"(",
"$",
"visitor",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"v",
")",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"v",
"as",
"$",
"column",
"=>",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"field",
"instanceof",
"ExpressionInterface",
")",
"{",
"$",
"visitor",
"(",
"$",
"field",
")",
";",
"$",
"field",
"->",
"traverse",
"(",
"$",
"visitor",
")",
";",
"}",
"}",
"}",
"}"
] | Traverse the values expression.
This method will also traverse any queries that are to be used in the INSERT
values.
@param callable $visitor The visitor to traverse the expression with.
@return void | [
"Traverse",
"the",
"values",
"expression",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/ValuesExpression.php#L327-L351 |
210,581 | cakephp/cakephp | src/Database/Expression/ValuesExpression.php | ValuesExpression._processExpressions | protected function _processExpressions()
{
$types = [];
$typeMap = $this->getTypeMap();
$columns = $this->_columnNames();
foreach ($columns as $c) {
if (!is_scalar($c)) {
continue;
}
$types[$c] = $typeMap->type($c);
}
$types = $this->_requiresToExpressionCasting($types);
if (empty($types)) {
return;
}
foreach ($this->_values as $row => $values) {
foreach ($types as $col => $type) {
/* @var \Cake\Database\Type\ExpressionTypeInterface $type */
$this->_values[$row][$col] = $type->toExpression($values[$col]);
}
}
$this->_castedExpressions = true;
} | php | protected function _processExpressions()
{
$types = [];
$typeMap = $this->getTypeMap();
$columns = $this->_columnNames();
foreach ($columns as $c) {
if (!is_scalar($c)) {
continue;
}
$types[$c] = $typeMap->type($c);
}
$types = $this->_requiresToExpressionCasting($types);
if (empty($types)) {
return;
}
foreach ($this->_values as $row => $values) {
foreach ($types as $col => $type) {
/* @var \Cake\Database\Type\ExpressionTypeInterface $type */
$this->_values[$row][$col] = $type->toExpression($values[$col]);
}
}
$this->_castedExpressions = true;
} | [
"protected",
"function",
"_processExpressions",
"(",
")",
"{",
"$",
"types",
"=",
"[",
"]",
";",
"$",
"typeMap",
"=",
"$",
"this",
"->",
"getTypeMap",
"(",
")",
";",
"$",
"columns",
"=",
"$",
"this",
"->",
"_columnNames",
"(",
")",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"c",
")",
"{",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"c",
")",
")",
"{",
"continue",
";",
"}",
"$",
"types",
"[",
"$",
"c",
"]",
"=",
"$",
"typeMap",
"->",
"type",
"(",
"$",
"c",
")",
";",
"}",
"$",
"types",
"=",
"$",
"this",
"->",
"_requiresToExpressionCasting",
"(",
"$",
"types",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"types",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"_values",
"as",
"$",
"row",
"=>",
"$",
"values",
")",
"{",
"foreach",
"(",
"$",
"types",
"as",
"$",
"col",
"=>",
"$",
"type",
")",
"{",
"/* @var \\Cake\\Database\\Type\\ExpressionTypeInterface $type */",
"$",
"this",
"->",
"_values",
"[",
"$",
"row",
"]",
"[",
"$",
"col",
"]",
"=",
"$",
"type",
"->",
"toExpression",
"(",
"$",
"values",
"[",
"$",
"col",
"]",
")",
";",
"}",
"}",
"$",
"this",
"->",
"_castedExpressions",
"=",
"true",
";",
"}"
] | Converts values that need to be casted to expressions
@return void | [
"Converts",
"values",
"that",
"need",
"to",
"be",
"casted",
"to",
"expressions"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Expression/ValuesExpression.php#L358-L384 |
210,582 | cakephp/cakephp | src/I18n/RelativeTimeFormatter.php | RelativeTimeFormatter._options | protected function _options($options, $class)
{
$options += [
'from' => $class::now(),
'timezone' => null,
'format' => $class::$wordFormat,
'accuracy' => $class::$wordAccuracy,
'end' => $class::$wordEnd,
'relativeString' => __d('cake', '%s ago'),
'absoluteString' => __d('cake', 'on %s'),
];
if (is_string($options['accuracy'])) {
$accuracy = $options['accuracy'];
$options['accuracy'] = [];
foreach ($class::$wordAccuracy as $key => $level) {
$options['accuracy'][$key] = $accuracy;
}
} else {
$options['accuracy'] += $class::$wordAccuracy;
}
return $options;
} | php | protected function _options($options, $class)
{
$options += [
'from' => $class::now(),
'timezone' => null,
'format' => $class::$wordFormat,
'accuracy' => $class::$wordAccuracy,
'end' => $class::$wordEnd,
'relativeString' => __d('cake', '%s ago'),
'absoluteString' => __d('cake', 'on %s'),
];
if (is_string($options['accuracy'])) {
$accuracy = $options['accuracy'];
$options['accuracy'] = [];
foreach ($class::$wordAccuracy as $key => $level) {
$options['accuracy'][$key] = $accuracy;
}
} else {
$options['accuracy'] += $class::$wordAccuracy;
}
return $options;
} | [
"protected",
"function",
"_options",
"(",
"$",
"options",
",",
"$",
"class",
")",
"{",
"$",
"options",
"+=",
"[",
"'from'",
"=>",
"$",
"class",
"::",
"now",
"(",
")",
",",
"'timezone'",
"=>",
"null",
",",
"'format'",
"=>",
"$",
"class",
"::",
"$",
"wordFormat",
",",
"'accuracy'",
"=>",
"$",
"class",
"::",
"$",
"wordAccuracy",
",",
"'end'",
"=>",
"$",
"class",
"::",
"$",
"wordEnd",
",",
"'relativeString'",
"=>",
"__d",
"(",
"'cake'",
",",
"'%s ago'",
")",
",",
"'absoluteString'",
"=>",
"__d",
"(",
"'cake'",
",",
"'on %s'",
")",
",",
"]",
";",
"if",
"(",
"is_string",
"(",
"$",
"options",
"[",
"'accuracy'",
"]",
")",
")",
"{",
"$",
"accuracy",
"=",
"$",
"options",
"[",
"'accuracy'",
"]",
";",
"$",
"options",
"[",
"'accuracy'",
"]",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"class",
"::",
"$",
"wordAccuracy",
"as",
"$",
"key",
"=>",
"$",
"level",
")",
"{",
"$",
"options",
"[",
"'accuracy'",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"accuracy",
";",
"}",
"}",
"else",
"{",
"$",
"options",
"[",
"'accuracy'",
"]",
"+=",
"$",
"class",
"::",
"$",
"wordAccuracy",
";",
"}",
"return",
"$",
"options",
";",
"}"
] | Build the options for relative date formatting.
@param array $options The options provided by the user.
@param string $class The class name to use for defaults.
@return array Options with defaults applied. | [
"Build",
"the",
"options",
"for",
"relative",
"date",
"formatting",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/I18n/RelativeTimeFormatter.php#L362-L384 |
210,583 | cakephp/cakephp | src/View/Helper/IdGeneratorTrait.php | IdGeneratorTrait._id | protected function _id($name, $val)
{
$name = $this->_domId($name);
$idSuffix = mb_strtolower(str_replace(['/', '@', '<', '>', ' ', '"', '\''], '-', $val));
$count = 1;
$check = $idSuffix;
while (in_array($check, $this->_idSuffixes)) {
$check = $idSuffix . $count++;
}
$this->_idSuffixes[] = $check;
return trim($name . '-' . $check, '-');
} | php | protected function _id($name, $val)
{
$name = $this->_domId($name);
$idSuffix = mb_strtolower(str_replace(['/', '@', '<', '>', ' ', '"', '\''], '-', $val));
$count = 1;
$check = $idSuffix;
while (in_array($check, $this->_idSuffixes)) {
$check = $idSuffix . $count++;
}
$this->_idSuffixes[] = $check;
return trim($name . '-' . $check, '-');
} | [
"protected",
"function",
"_id",
"(",
"$",
"name",
",",
"$",
"val",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"_domId",
"(",
"$",
"name",
")",
";",
"$",
"idSuffix",
"=",
"mb_strtolower",
"(",
"str_replace",
"(",
"[",
"'/'",
",",
"'@'",
",",
"'<'",
",",
"'>'",
",",
"' '",
",",
"'\"'",
",",
"'\\''",
"]",
",",
"'-'",
",",
"$",
"val",
")",
")",
";",
"$",
"count",
"=",
"1",
";",
"$",
"check",
"=",
"$",
"idSuffix",
";",
"while",
"(",
"in_array",
"(",
"$",
"check",
",",
"$",
"this",
"->",
"_idSuffixes",
")",
")",
"{",
"$",
"check",
"=",
"$",
"idSuffix",
".",
"$",
"count",
"++",
";",
"}",
"$",
"this",
"->",
"_idSuffixes",
"[",
"]",
"=",
"$",
"check",
";",
"return",
"trim",
"(",
"$",
"name",
".",
"'-'",
".",
"$",
"check",
",",
"'-'",
")",
";",
"}"
] | Generate an ID attribute for an element.
Ensures that id's for a given set of fields are unique.
@param string $name The ID attribute name.
@param string $val The ID attribute value.
@return string Generated id. | [
"Generate",
"an",
"ID",
"attribute",
"for",
"an",
"element",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/IdGeneratorTrait.php#L59-L72 |
210,584 | cakephp/cakephp | src/View/Helper/IdGeneratorTrait.php | IdGeneratorTrait._domId | protected function _domId($value)
{
$domId = mb_strtolower(Text::slug($value, '-'));
if ($this->_idPrefix) {
$domId = $this->_idPrefix . '-' . $domId;
}
return $domId;
} | php | protected function _domId($value)
{
$domId = mb_strtolower(Text::slug($value, '-'));
if ($this->_idPrefix) {
$domId = $this->_idPrefix . '-' . $domId;
}
return $domId;
} | [
"protected",
"function",
"_domId",
"(",
"$",
"value",
")",
"{",
"$",
"domId",
"=",
"mb_strtolower",
"(",
"Text",
"::",
"slug",
"(",
"$",
"value",
",",
"'-'",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_idPrefix",
")",
"{",
"$",
"domId",
"=",
"$",
"this",
"->",
"_idPrefix",
".",
"'-'",
".",
"$",
"domId",
";",
"}",
"return",
"$",
"domId",
";",
"}"
] | Generate an ID suitable for use in an ID attribute.
@param string $value The value to convert into an ID.
@return string The generated id. | [
"Generate",
"an",
"ID",
"suitable",
"for",
"use",
"in",
"an",
"ID",
"attribute",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/IdGeneratorTrait.php#L80-L88 |
210,585 | cakephp/cakephp | src/View/Widget/WidgetLocator.php | WidgetLocator.load | public function load($file)
{
$loader = new PhpConfig();
$widgets = $loader->read($file);
$this->add($widgets);
} | php | public function load($file)
{
$loader = new PhpConfig();
$widgets = $loader->read($file);
$this->add($widgets);
} | [
"public",
"function",
"load",
"(",
"$",
"file",
")",
"{",
"$",
"loader",
"=",
"new",
"PhpConfig",
"(",
")",
";",
"$",
"widgets",
"=",
"$",
"loader",
"->",
"read",
"(",
"$",
"file",
")",
";",
"$",
"this",
"->",
"add",
"(",
"$",
"widgets",
")",
";",
"}"
] | Load a config file containing widgets.
Widget files should define a `$config` variable containing
all the widgets to load. Loaded widgets will be merged with existing
widgets.
@param string $file The file to load
@return void | [
"Load",
"a",
"config",
"file",
"containing",
"widgets",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Widget/WidgetLocator.php#L88-L93 |
210,586 | cakephp/cakephp | src/View/Widget/WidgetLocator.php | WidgetLocator._resolveWidget | protected function _resolveWidget($widget)
{
$type = gettype($widget);
if ($type === 'object') {
return $widget;
}
if ($type === 'string') {
$widget = [$widget];
}
$class = array_shift($widget);
$className = App::className($class, 'View/Widget', 'Widget');
if ($className === false || !class_exists($className)) {
throw new RuntimeException(sprintf('Unable to locate widget class "%s"', $class));
}
if ($type === 'array' && count($widget)) {
$reflection = new ReflectionClass($className);
$arguments = [$this->_templates];
foreach ($widget as $requirement) {
$arguments[] = $this->get($requirement);
}
$instance = $reflection->newInstanceArgs($arguments);
} else {
$instance = new $className($this->_templates);
}
if (!($instance instanceof WidgetInterface)) {
throw new RuntimeException(sprintf('"%s" does not implement the WidgetInterface', $className));
}
return $instance;
} | php | protected function _resolveWidget($widget)
{
$type = gettype($widget);
if ($type === 'object') {
return $widget;
}
if ($type === 'string') {
$widget = [$widget];
}
$class = array_shift($widget);
$className = App::className($class, 'View/Widget', 'Widget');
if ($className === false || !class_exists($className)) {
throw new RuntimeException(sprintf('Unable to locate widget class "%s"', $class));
}
if ($type === 'array' && count($widget)) {
$reflection = new ReflectionClass($className);
$arguments = [$this->_templates];
foreach ($widget as $requirement) {
$arguments[] = $this->get($requirement);
}
$instance = $reflection->newInstanceArgs($arguments);
} else {
$instance = new $className($this->_templates);
}
if (!($instance instanceof WidgetInterface)) {
throw new RuntimeException(sprintf('"%s" does not implement the WidgetInterface', $className));
}
return $instance;
} | [
"protected",
"function",
"_resolveWidget",
"(",
"$",
"widget",
")",
"{",
"$",
"type",
"=",
"gettype",
"(",
"$",
"widget",
")",
";",
"if",
"(",
"$",
"type",
"===",
"'object'",
")",
"{",
"return",
"$",
"widget",
";",
"}",
"if",
"(",
"$",
"type",
"===",
"'string'",
")",
"{",
"$",
"widget",
"=",
"[",
"$",
"widget",
"]",
";",
"}",
"$",
"class",
"=",
"array_shift",
"(",
"$",
"widget",
")",
";",
"$",
"className",
"=",
"App",
"::",
"className",
"(",
"$",
"class",
",",
"'View/Widget'",
",",
"'Widget'",
")",
";",
"if",
"(",
"$",
"className",
"===",
"false",
"||",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Unable to locate widget class \"%s\"'",
",",
"$",
"class",
")",
")",
";",
"}",
"if",
"(",
"$",
"type",
"===",
"'array'",
"&&",
"count",
"(",
"$",
"widget",
")",
")",
"{",
"$",
"reflection",
"=",
"new",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"$",
"arguments",
"=",
"[",
"$",
"this",
"->",
"_templates",
"]",
";",
"foreach",
"(",
"$",
"widget",
"as",
"$",
"requirement",
")",
"{",
"$",
"arguments",
"[",
"]",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"requirement",
")",
";",
"}",
"$",
"instance",
"=",
"$",
"reflection",
"->",
"newInstanceArgs",
"(",
"$",
"arguments",
")",
";",
"}",
"else",
"{",
"$",
"instance",
"=",
"new",
"$",
"className",
"(",
"$",
"this",
"->",
"_templates",
")",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"instance",
"instanceof",
"WidgetInterface",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'\"%s\" does not implement the WidgetInterface'",
",",
"$",
"className",
")",
")",
";",
"}",
"return",
"$",
"instance",
";",
"}"
] | Resolves a widget spec into an instance.
@param mixed $widget The widget to get
@return \Cake\View\Widget\WidgetInterface
@throws \RuntimeException when class cannot be loaded or does not implement WidgetInterface.
@throws \ReflectionException | [
"Resolves",
"a",
"widget",
"spec",
"into",
"an",
"instance",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Widget/WidgetLocator.php#L173-L204 |
210,587 | cakephp/cakephp | src/Mailer/TransportFactory.php | TransportFactory._buildTransport | protected static function _buildTransport($name)
{
if (!isset(static::$_config[$name])) {
throw new InvalidArgumentException(
sprintf('The "%s" transport configuration does not exist', $name)
);
}
if (is_array(static::$_config[$name]) && empty(static::$_config[$name]['className'])) {
throw new InvalidArgumentException(
sprintf('Transport config "%s" is invalid, the required `className` option is missing', $name)
);
}
static::getRegistry()->load($name, static::$_config[$name]);
} | php | protected static function _buildTransport($name)
{
if (!isset(static::$_config[$name])) {
throw new InvalidArgumentException(
sprintf('The "%s" transport configuration does not exist', $name)
);
}
if (is_array(static::$_config[$name]) && empty(static::$_config[$name]['className'])) {
throw new InvalidArgumentException(
sprintf('Transport config "%s" is invalid, the required `className` option is missing', $name)
);
}
static::getRegistry()->load($name, static::$_config[$name]);
} | [
"protected",
"static",
"function",
"_buildTransport",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"_config",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The \"%s\" transport configuration does not exist'",
",",
"$",
"name",
")",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"static",
"::",
"$",
"_config",
"[",
"$",
"name",
"]",
")",
"&&",
"empty",
"(",
"static",
"::",
"$",
"_config",
"[",
"$",
"name",
"]",
"[",
"'className'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Transport config \"%s\" is invalid, the required `className` option is missing'",
",",
"$",
"name",
")",
")",
";",
"}",
"static",
"::",
"getRegistry",
"(",
")",
"->",
"load",
"(",
"$",
"name",
",",
"static",
"::",
"$",
"_config",
"[",
"$",
"name",
"]",
")",
";",
"}"
] | Finds and builds the instance of the required tranport class.
@param string $name Name of the config array that needs a tranport instance built
@return void
@throws \InvalidArgumentException When a tranport cannot be created. | [
"Finds",
"and",
"builds",
"the",
"instance",
"of",
"the",
"required",
"tranport",
"class",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/TransportFactory.php#L79-L94 |
210,588 | cakephp/cakephp | src/Mailer/TransportFactory.php | TransportFactory.get | public static function get($name)
{
$registry = static::getRegistry();
if (isset($registry->{$name})) {
return $registry->{$name};
}
static::_buildTransport($name);
return $registry->{$name};
} | php | public static function get($name)
{
$registry = static::getRegistry();
if (isset($registry->{$name})) {
return $registry->{$name};
}
static::_buildTransport($name);
return $registry->{$name};
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"name",
")",
"{",
"$",
"registry",
"=",
"static",
"::",
"getRegistry",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"registry",
"->",
"{",
"$",
"name",
"}",
")",
")",
"{",
"return",
"$",
"registry",
"->",
"{",
"$",
"name",
"}",
";",
"}",
"static",
"::",
"_buildTransport",
"(",
"$",
"name",
")",
";",
"return",
"$",
"registry",
"->",
"{",
"$",
"name",
"}",
";",
"}"
] | Get transport instance.
@param string $name Config name.
@return \Cake\Mailer\AbstractTransport | [
"Get",
"transport",
"instance",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/TransportFactory.php#L102-L113 |
210,589 | cakephp/cakephp | src/Auth/DigestAuthenticate.php | DigestAuthenticate.parseAuthData | public function parseAuthData($digest)
{
if (substr($digest, 0, 7) === 'Digest ') {
$digest = substr($digest, 7);
}
$keys = $match = [];
$req = ['nonce' => 1, 'nc' => 1, 'cnonce' => 1, 'qop' => 1, 'username' => 1, 'uri' => 1, 'response' => 1];
preg_match_all('/(\w+)=([\'"]?)([a-zA-Z0-9\:\#\%\?\&@=\.\/_-]+)\2/', $digest, $match, PREG_SET_ORDER);
foreach ($match as $i) {
$keys[$i[1]] = $i[3];
unset($req[$i[1]]);
}
if (empty($req)) {
return $keys;
}
return null;
} | php | public function parseAuthData($digest)
{
if (substr($digest, 0, 7) === 'Digest ') {
$digest = substr($digest, 7);
}
$keys = $match = [];
$req = ['nonce' => 1, 'nc' => 1, 'cnonce' => 1, 'qop' => 1, 'username' => 1, 'uri' => 1, 'response' => 1];
preg_match_all('/(\w+)=([\'"]?)([a-zA-Z0-9\:\#\%\?\&@=\.\/_-]+)\2/', $digest, $match, PREG_SET_ORDER);
foreach ($match as $i) {
$keys[$i[1]] = $i[3];
unset($req[$i[1]]);
}
if (empty($req)) {
return $keys;
}
return null;
} | [
"public",
"function",
"parseAuthData",
"(",
"$",
"digest",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"digest",
",",
"0",
",",
"7",
")",
"===",
"'Digest '",
")",
"{",
"$",
"digest",
"=",
"substr",
"(",
"$",
"digest",
",",
"7",
")",
";",
"}",
"$",
"keys",
"=",
"$",
"match",
"=",
"[",
"]",
";",
"$",
"req",
"=",
"[",
"'nonce'",
"=>",
"1",
",",
"'nc'",
"=>",
"1",
",",
"'cnonce'",
"=>",
"1",
",",
"'qop'",
"=>",
"1",
",",
"'username'",
"=>",
"1",
",",
"'uri'",
"=>",
"1",
",",
"'response'",
"=>",
"1",
"]",
";",
"preg_match_all",
"(",
"'/(\\w+)=([\\'\"]?)([a-zA-Z0-9\\:\\#\\%\\?\\&@=\\.\\/_-]+)\\2/'",
",",
"$",
"digest",
",",
"$",
"match",
",",
"PREG_SET_ORDER",
")",
";",
"foreach",
"(",
"$",
"match",
"as",
"$",
"i",
")",
"{",
"$",
"keys",
"[",
"$",
"i",
"[",
"1",
"]",
"]",
"=",
"$",
"i",
"[",
"3",
"]",
";",
"unset",
"(",
"$",
"req",
"[",
"$",
"i",
"[",
"1",
"]",
"]",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"req",
")",
")",
"{",
"return",
"$",
"keys",
";",
"}",
"return",
"null",
";",
"}"
] | Parse the digest authentication headers and split them up.
@param string $digest The raw digest authentication headers.
@return array|null An array of digest authentication headers | [
"Parse",
"the",
"digest",
"authentication",
"headers",
"and",
"split",
"them",
"up",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Auth/DigestAuthenticate.php#L161-L180 |
210,590 | cakephp/cakephp | src/Auth/DigestAuthenticate.php | DigestAuthenticate.generateResponseHash | public function generateResponseHash($digest, $password, $method)
{
return md5(
$password .
':' . $digest['nonce'] . ':' . $digest['nc'] . ':' . $digest['cnonce'] . ':' . $digest['qop'] . ':' .
md5($method . ':' . $digest['uri'])
);
} | php | public function generateResponseHash($digest, $password, $method)
{
return md5(
$password .
':' . $digest['nonce'] . ':' . $digest['nc'] . ':' . $digest['cnonce'] . ':' . $digest['qop'] . ':' .
md5($method . ':' . $digest['uri'])
);
} | [
"public",
"function",
"generateResponseHash",
"(",
"$",
"digest",
",",
"$",
"password",
",",
"$",
"method",
")",
"{",
"return",
"md5",
"(",
"$",
"password",
".",
"':'",
".",
"$",
"digest",
"[",
"'nonce'",
"]",
".",
"':'",
".",
"$",
"digest",
"[",
"'nc'",
"]",
".",
"':'",
".",
"$",
"digest",
"[",
"'cnonce'",
"]",
".",
"':'",
".",
"$",
"digest",
"[",
"'qop'",
"]",
".",
"':'",
".",
"md5",
"(",
"$",
"method",
".",
"':'",
".",
"$",
"digest",
"[",
"'uri'",
"]",
")",
")",
";",
"}"
] | Generate the response hash for a given digest array.
@param array $digest Digest information containing data from DigestAuthenticate::parseAuthData().
@param string $password The digest hash password generated with DigestAuthenticate::password()
@param string $method Request method
@return string Response hash | [
"Generate",
"the",
"response",
"hash",
"for",
"a",
"given",
"digest",
"array",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Auth/DigestAuthenticate.php#L190-L197 |
210,591 | cakephp/cakephp | src/View/StringTemplate.php | StringTemplate.pop | public function pop()
{
if (empty($this->_configStack)) {
return;
}
list($this->_config, $this->_compiled) = array_pop($this->_configStack);
} | php | public function pop()
{
if (empty($this->_configStack)) {
return;
}
list($this->_config, $this->_compiled) = array_pop($this->_configStack);
} | [
"public",
"function",
"pop",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_configStack",
")",
")",
"{",
"return",
";",
"}",
"list",
"(",
"$",
"this",
"->",
"_config",
",",
"$",
"this",
"->",
"_compiled",
")",
"=",
"array_pop",
"(",
"$",
"this",
"->",
"_configStack",
")",
";",
"}"
] | Restore the most recently pushed set of templates.
@return void | [
"Restore",
"the",
"most",
"recently",
"pushed",
"set",
"of",
"templates",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/StringTemplate.php#L134-L140 |
210,592 | cakephp/cakephp | src/View/StringTemplate.php | StringTemplate.add | public function add(array $templates)
{
$this->setConfig($templates);
$this->_compileTemplates(array_keys($templates));
return $this;
} | php | public function add(array $templates)
{
$this->setConfig($templates);
$this->_compileTemplates(array_keys($templates));
return $this;
} | [
"public",
"function",
"add",
"(",
"array",
"$",
"templates",
")",
"{",
"$",
"this",
"->",
"setConfig",
"(",
"$",
"templates",
")",
";",
"$",
"this",
"->",
"_compileTemplates",
"(",
"array_keys",
"(",
"$",
"templates",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Registers a list of templates by name
### Example:
```
$templater->add([
'link' => '<a href="{{url}}">{{title}}</a>'
'button' => '<button>{{text}}</button>'
]);
```
@param array $templates An associative list of named templates.
@return $this | [
"Registers",
"a",
"list",
"of",
"templates",
"by",
"name"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/StringTemplate.php#L157-L163 |
210,593 | cakephp/cakephp | src/View/StringTemplate.php | StringTemplate.load | public function load($file)
{
$loader = new PhpConfig();
$templates = $loader->read($file);
$this->add($templates);
} | php | public function load($file)
{
$loader = new PhpConfig();
$templates = $loader->read($file);
$this->add($templates);
} | [
"public",
"function",
"load",
"(",
"$",
"file",
")",
"{",
"$",
"loader",
"=",
"new",
"PhpConfig",
"(",
")",
";",
"$",
"templates",
"=",
"$",
"loader",
"->",
"read",
"(",
"$",
"file",
")",
";",
"$",
"this",
"->",
"add",
"(",
"$",
"templates",
")",
";",
"}"
] | Load a config file containing templates.
Template files should define a `$config` variable containing
all the templates to load. Loaded templates will be merged with existing
templates.
@param string $file The file to load
@return void | [
"Load",
"a",
"config",
"file",
"containing",
"templates",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/StringTemplate.php#L201-L206 |
210,594 | cakephp/cakephp | src/View/StringTemplate.php | StringTemplate._formatAttribute | protected function _formatAttribute($key, $value, $escape = true)
{
if (is_array($value)) {
$value = implode(' ', $value);
}
if (is_numeric($key)) {
return "$value=\"$value\"";
}
$truthy = [1, '1', true, 'true', $key];
$isMinimized = isset($this->_compactAttributes[$key]);
if (!preg_match('/\A(\w|[.-])+\z/', $key)) {
$key = h($key);
}
if ($isMinimized && in_array($value, $truthy, true)) {
return "$key=\"$key\"";
}
if ($isMinimized) {
return '';
}
return $key . '="' . ($escape ? h($value) : $value) . '"';
} | php | protected function _formatAttribute($key, $value, $escape = true)
{
if (is_array($value)) {
$value = implode(' ', $value);
}
if (is_numeric($key)) {
return "$value=\"$value\"";
}
$truthy = [1, '1', true, 'true', $key];
$isMinimized = isset($this->_compactAttributes[$key]);
if (!preg_match('/\A(\w|[.-])+\z/', $key)) {
$key = h($key);
}
if ($isMinimized && in_array($value, $truthy, true)) {
return "$key=\"$key\"";
}
if ($isMinimized) {
return '';
}
return $key . '="' . ($escape ? h($value) : $value) . '"';
} | [
"protected",
"function",
"_formatAttribute",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"escape",
"=",
"true",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"implode",
"(",
"' '",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"key",
")",
")",
"{",
"return",
"\"$value=\\\"$value\\\"\"",
";",
"}",
"$",
"truthy",
"=",
"[",
"1",
",",
"'1'",
",",
"true",
",",
"'true'",
",",
"$",
"key",
"]",
";",
"$",
"isMinimized",
"=",
"isset",
"(",
"$",
"this",
"->",
"_compactAttributes",
"[",
"$",
"key",
"]",
")",
";",
"if",
"(",
"!",
"preg_match",
"(",
"'/\\A(\\w|[.-])+\\z/'",
",",
"$",
"key",
")",
")",
"{",
"$",
"key",
"=",
"h",
"(",
"$",
"key",
")",
";",
"}",
"if",
"(",
"$",
"isMinimized",
"&&",
"in_array",
"(",
"$",
"value",
",",
"$",
"truthy",
",",
"true",
")",
")",
"{",
"return",
"\"$key=\\\"$key\\\"\"",
";",
"}",
"if",
"(",
"$",
"isMinimized",
")",
"{",
"return",
"''",
";",
"}",
"return",
"$",
"key",
".",
"'=\"'",
".",
"(",
"$",
"escape",
"?",
"h",
"(",
"$",
"value",
")",
":",
"$",
"value",
")",
".",
"'\"'",
";",
"}"
] | Formats an individual attribute, and returns the string value of the composed attribute.
Works with minimized attributes that have the same value as their name such as 'disabled' and 'checked'
@param string $key The name of the attribute to create
@param string|array $value The value of the attribute to create.
@param bool $escape Define if the value must be escaped
@return string The composed attribute. | [
"Formats",
"an",
"individual",
"attribute",
"and",
"returns",
"the",
"string",
"value",
"of",
"the",
"composed",
"attribute",
".",
"Works",
"with",
"minimized",
"attributes",
"that",
"have",
"the",
"same",
"value",
"as",
"their",
"name",
"such",
"as",
"disabled",
"and",
"checked"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/StringTemplate.php#L308-L329 |
210,595 | cakephp/cakephp | src/Utility/Xml.php | Xml.build | public static function build($input, array $options = [])
{
$defaults = [
'return' => 'simplexml',
'loadEntities' => false,
'readFile' => true,
'parseHuge' => false,
];
$options += $defaults;
if (is_array($input) || is_object($input)) {
return static::fromArray($input, $options);
}
if (strpos($input, '<') !== false) {
return static::_loadXml($input, $options);
}
if ($options['readFile'] && file_exists($input)) {
return static::_loadXml(file_get_contents($input), $options);
}
if (!is_string($input)) {
throw new XmlException('Invalid input.');
}
throw new XmlException('XML cannot be read.');
} | php | public static function build($input, array $options = [])
{
$defaults = [
'return' => 'simplexml',
'loadEntities' => false,
'readFile' => true,
'parseHuge' => false,
];
$options += $defaults;
if (is_array($input) || is_object($input)) {
return static::fromArray($input, $options);
}
if (strpos($input, '<') !== false) {
return static::_loadXml($input, $options);
}
if ($options['readFile'] && file_exists($input)) {
return static::_loadXml(file_get_contents($input), $options);
}
if (!is_string($input)) {
throw new XmlException('Invalid input.');
}
throw new XmlException('XML cannot be read.');
} | [
"public",
"static",
"function",
"build",
"(",
"$",
"input",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'return'",
"=>",
"'simplexml'",
",",
"'loadEntities'",
"=>",
"false",
",",
"'readFile'",
"=>",
"true",
",",
"'parseHuge'",
"=>",
"false",
",",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"if",
"(",
"is_array",
"(",
"$",
"input",
")",
"||",
"is_object",
"(",
"$",
"input",
")",
")",
"{",
"return",
"static",
"::",
"fromArray",
"(",
"$",
"input",
",",
"$",
"options",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"input",
",",
"'<'",
")",
"!==",
"false",
")",
"{",
"return",
"static",
"::",
"_loadXml",
"(",
"$",
"input",
",",
"$",
"options",
")",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'readFile'",
"]",
"&&",
"file_exists",
"(",
"$",
"input",
")",
")",
"{",
"return",
"static",
"::",
"_loadXml",
"(",
"file_get_contents",
"(",
"$",
"input",
")",
",",
"$",
"options",
")",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"input",
")",
")",
"{",
"throw",
"new",
"XmlException",
"(",
"'Invalid input.'",
")",
";",
"}",
"throw",
"new",
"XmlException",
"(",
"'XML cannot be read.'",
")",
";",
"}"
] | Initialize SimpleXMLElement or DOMDocument from a given XML string, file path, URL or array.
### Usage:
Building XML from a string:
```
$xml = Xml::build('<example>text</example>');
```
Building XML from string (output DOMDocument):
```
$xml = Xml::build('<example>text</example>', ['return' => 'domdocument']);
```
Building XML from a file path:
```
$xml = Xml::build('/path/to/an/xml/file.xml');
```
Building XML from a remote URL:
```
use Cake\Http\Client;
$http = new Client();
$response = $http->get('http://example.com/example.xml');
$xml = Xml::build($response->body());
```
Building from an array:
```
$value = [
'tags' => [
'tag' => [
[
'id' => '1',
'name' => 'defect'
],
[
'id' => '2',
'name' => 'enhancement'
]
]
]
];
$xml = Xml::build($value);
```
When building XML from an array ensure that there is only one top level element.
### Options
- `return` Can be 'simplexml' to return object of SimpleXMLElement or 'domdocument' to return DOMDocument.
- `loadEntities` Defaults to false. Set to true to enable loading of `<!ENTITY` definitions. This
is disabled by default for security reasons.
- `readFile` Set to false to disable file reading. This is important to disable when
putting user data into Xml::build(). If enabled local files will be read if they exist.
Defaults to true for backwards compatibility reasons.
- `parseHuge` Enable the `LIBXML_PARSEHUGE` flag.
If using array as input, you can pass `options` from Xml::fromArray.
@param string|array $input XML string, a path to a file, a URL or an array
@param array $options The options to use
@return \SimpleXMLElement|\DOMDocument SimpleXMLElement or DOMDocument
@throws \Cake\Utility\Exception\XmlException | [
"Initialize",
"SimpleXMLElement",
"or",
"DOMDocument",
"from",
"a",
"given",
"XML",
"string",
"file",
"path",
"URL",
"or",
"array",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/Xml.php#L104-L131 |
210,596 | cakephp/cakephp | src/Utility/Xml.php | Xml._loadXml | protected static function _loadXml($input, $options)
{
$hasDisable = function_exists('libxml_disable_entity_loader');
$internalErrors = libxml_use_internal_errors(true);
if ($hasDisable && !$options['loadEntities']) {
libxml_disable_entity_loader(true);
}
$flags = 0;
if (!empty($options['parseHuge'])) {
$flags |= LIBXML_PARSEHUGE;
}
try {
if ($options['return'] === 'simplexml' || $options['return'] === 'simplexmlelement') {
$flags |= LIBXML_NOCDATA;
$xml = new SimpleXMLElement($input, $flags);
} else {
$xml = new DOMDocument();
$xml->loadXML($input, $flags);
}
return $xml;
} catch (Exception $e) {
throw new XmlException('Xml cannot be read. ' . $e->getMessage(), null, $e);
} finally {
if ($hasDisable && !$options['loadEntities']) {
libxml_disable_entity_loader(false);
}
libxml_use_internal_errors($internalErrors);
}
} | php | protected static function _loadXml($input, $options)
{
$hasDisable = function_exists('libxml_disable_entity_loader');
$internalErrors = libxml_use_internal_errors(true);
if ($hasDisable && !$options['loadEntities']) {
libxml_disable_entity_loader(true);
}
$flags = 0;
if (!empty($options['parseHuge'])) {
$flags |= LIBXML_PARSEHUGE;
}
try {
if ($options['return'] === 'simplexml' || $options['return'] === 'simplexmlelement') {
$flags |= LIBXML_NOCDATA;
$xml = new SimpleXMLElement($input, $flags);
} else {
$xml = new DOMDocument();
$xml->loadXML($input, $flags);
}
return $xml;
} catch (Exception $e) {
throw new XmlException('Xml cannot be read. ' . $e->getMessage(), null, $e);
} finally {
if ($hasDisable && !$options['loadEntities']) {
libxml_disable_entity_loader(false);
}
libxml_use_internal_errors($internalErrors);
}
} | [
"protected",
"static",
"function",
"_loadXml",
"(",
"$",
"input",
",",
"$",
"options",
")",
"{",
"$",
"hasDisable",
"=",
"function_exists",
"(",
"'libxml_disable_entity_loader'",
")",
";",
"$",
"internalErrors",
"=",
"libxml_use_internal_errors",
"(",
"true",
")",
";",
"if",
"(",
"$",
"hasDisable",
"&&",
"!",
"$",
"options",
"[",
"'loadEntities'",
"]",
")",
"{",
"libxml_disable_entity_loader",
"(",
"true",
")",
";",
"}",
"$",
"flags",
"=",
"0",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'parseHuge'",
"]",
")",
")",
"{",
"$",
"flags",
"|=",
"LIBXML_PARSEHUGE",
";",
"}",
"try",
"{",
"if",
"(",
"$",
"options",
"[",
"'return'",
"]",
"===",
"'simplexml'",
"||",
"$",
"options",
"[",
"'return'",
"]",
"===",
"'simplexmlelement'",
")",
"{",
"$",
"flags",
"|=",
"LIBXML_NOCDATA",
";",
"$",
"xml",
"=",
"new",
"SimpleXMLElement",
"(",
"$",
"input",
",",
"$",
"flags",
")",
";",
"}",
"else",
"{",
"$",
"xml",
"=",
"new",
"DOMDocument",
"(",
")",
";",
"$",
"xml",
"->",
"loadXML",
"(",
"$",
"input",
",",
"$",
"flags",
")",
";",
"}",
"return",
"$",
"xml",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"XmlException",
"(",
"'Xml cannot be read. '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"null",
",",
"$",
"e",
")",
";",
"}",
"finally",
"{",
"if",
"(",
"$",
"hasDisable",
"&&",
"!",
"$",
"options",
"[",
"'loadEntities'",
"]",
")",
"{",
"libxml_disable_entity_loader",
"(",
"false",
")",
";",
"}",
"libxml_use_internal_errors",
"(",
"$",
"internalErrors",
")",
";",
"}",
"}"
] | Parse the input data and create either a SimpleXmlElement object or a DOMDocument.
@param string $input The input to load.
@param array $options The options to use. See Xml::build()
@return \SimpleXMLElement|\DOMDocument
@throws \Cake\Utility\Exception\XmlException | [
"Parse",
"the",
"input",
"data",
"and",
"create",
"either",
"a",
"SimpleXmlElement",
"object",
"or",
"a",
"DOMDocument",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/Xml.php#L141-L170 |
210,597 | cakephp/cakephp | src/Utility/Xml.php | Xml.loadHtml | public static function loadHtml($input, $options = [])
{
$defaults = [
'return' => 'simplexml',
'loadEntities' => false,
];
$options += $defaults;
$hasDisable = function_exists('libxml_disable_entity_loader');
$internalErrors = libxml_use_internal_errors(true);
if ($hasDisable && !$options['loadEntities']) {
libxml_disable_entity_loader(true);
}
$flags = 0;
if (!empty($options['parseHuge'])) {
$flags |= LIBXML_PARSEHUGE;
}
try {
$xml = new DOMDocument();
$xml->loadHTML($input, $flags);
if ($options['return'] === 'simplexml' || $options['return'] === 'simplexmlelement') {
$flags |= LIBXML_NOCDATA;
$xml = simplexml_import_dom($xml);
}
return $xml;
} catch (Exception $e) {
throw new XmlException('Xml cannot be read. ' . $e->getMessage(), null, $e);
} finally {
if ($hasDisable && !$options['loadEntities']) {
libxml_disable_entity_loader(false);
}
libxml_use_internal_errors($internalErrors);
}
} | php | public static function loadHtml($input, $options = [])
{
$defaults = [
'return' => 'simplexml',
'loadEntities' => false,
];
$options += $defaults;
$hasDisable = function_exists('libxml_disable_entity_loader');
$internalErrors = libxml_use_internal_errors(true);
if ($hasDisable && !$options['loadEntities']) {
libxml_disable_entity_loader(true);
}
$flags = 0;
if (!empty($options['parseHuge'])) {
$flags |= LIBXML_PARSEHUGE;
}
try {
$xml = new DOMDocument();
$xml->loadHTML($input, $flags);
if ($options['return'] === 'simplexml' || $options['return'] === 'simplexmlelement') {
$flags |= LIBXML_NOCDATA;
$xml = simplexml_import_dom($xml);
}
return $xml;
} catch (Exception $e) {
throw new XmlException('Xml cannot be read. ' . $e->getMessage(), null, $e);
} finally {
if ($hasDisable && !$options['loadEntities']) {
libxml_disable_entity_loader(false);
}
libxml_use_internal_errors($internalErrors);
}
} | [
"public",
"static",
"function",
"loadHtml",
"(",
"$",
"input",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'return'",
"=>",
"'simplexml'",
",",
"'loadEntities'",
"=>",
"false",
",",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"$",
"hasDisable",
"=",
"function_exists",
"(",
"'libxml_disable_entity_loader'",
")",
";",
"$",
"internalErrors",
"=",
"libxml_use_internal_errors",
"(",
"true",
")",
";",
"if",
"(",
"$",
"hasDisable",
"&&",
"!",
"$",
"options",
"[",
"'loadEntities'",
"]",
")",
"{",
"libxml_disable_entity_loader",
"(",
"true",
")",
";",
"}",
"$",
"flags",
"=",
"0",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'parseHuge'",
"]",
")",
")",
"{",
"$",
"flags",
"|=",
"LIBXML_PARSEHUGE",
";",
"}",
"try",
"{",
"$",
"xml",
"=",
"new",
"DOMDocument",
"(",
")",
";",
"$",
"xml",
"->",
"loadHTML",
"(",
"$",
"input",
",",
"$",
"flags",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'return'",
"]",
"===",
"'simplexml'",
"||",
"$",
"options",
"[",
"'return'",
"]",
"===",
"'simplexmlelement'",
")",
"{",
"$",
"flags",
"|=",
"LIBXML_NOCDATA",
";",
"$",
"xml",
"=",
"simplexml_import_dom",
"(",
"$",
"xml",
")",
";",
"}",
"return",
"$",
"xml",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"XmlException",
"(",
"'Xml cannot be read. '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"null",
",",
"$",
"e",
")",
";",
"}",
"finally",
"{",
"if",
"(",
"$",
"hasDisable",
"&&",
"!",
"$",
"options",
"[",
"'loadEntities'",
"]",
")",
"{",
"libxml_disable_entity_loader",
"(",
"false",
")",
";",
"}",
"libxml_use_internal_errors",
"(",
"$",
"internalErrors",
")",
";",
"}",
"}"
] | Parse the input html string and create either a SimpleXmlElement object or a DOMDocument.
@param string $input The input html string to load.
@param array $options The options to use. See Xml::build()
@return \SimpleXMLElement|\DOMDocument
@throws \Cake\Utility\Exception\XmlException | [
"Parse",
"the",
"input",
"html",
"string",
"and",
"create",
"either",
"a",
"SimpleXmlElement",
"object",
"or",
"a",
"DOMDocument",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/Xml.php#L180-L215 |
210,598 | cakephp/cakephp | src/Utility/Xml.php | Xml.fromArray | public static function fromArray($input, $options = [])
{
if (is_object($input) && method_exists($input, 'toArray') && is_callable([$input, 'toArray'])) {
$input = call_user_func([$input, 'toArray']);
}
if (!is_array($input) || count($input) !== 1) {
throw new XmlException('Invalid input.');
}
$key = key($input);
if (is_int($key)) {
throw new XmlException('The key of input must be alphanumeric');
}
if (!is_array($options)) {
$options = ['format' => (string)$options];
}
$defaults = [
'format' => 'tags',
'version' => '1.0',
'encoding' => mb_internal_encoding(),
'return' => 'simplexml',
'pretty' => false
];
$options += $defaults;
$dom = new DOMDocument($options['version'], $options['encoding']);
if ($options['pretty']) {
$dom->formatOutput = true;
}
self::_fromArray($dom, $dom, $input, $options['format']);
$options['return'] = strtolower($options['return']);
if ($options['return'] === 'simplexml' || $options['return'] === 'simplexmlelement') {
return new SimpleXMLElement($dom->saveXML());
}
return $dom;
} | php | public static function fromArray($input, $options = [])
{
if (is_object($input) && method_exists($input, 'toArray') && is_callable([$input, 'toArray'])) {
$input = call_user_func([$input, 'toArray']);
}
if (!is_array($input) || count($input) !== 1) {
throw new XmlException('Invalid input.');
}
$key = key($input);
if (is_int($key)) {
throw new XmlException('The key of input must be alphanumeric');
}
if (!is_array($options)) {
$options = ['format' => (string)$options];
}
$defaults = [
'format' => 'tags',
'version' => '1.0',
'encoding' => mb_internal_encoding(),
'return' => 'simplexml',
'pretty' => false
];
$options += $defaults;
$dom = new DOMDocument($options['version'], $options['encoding']);
if ($options['pretty']) {
$dom->formatOutput = true;
}
self::_fromArray($dom, $dom, $input, $options['format']);
$options['return'] = strtolower($options['return']);
if ($options['return'] === 'simplexml' || $options['return'] === 'simplexmlelement') {
return new SimpleXMLElement($dom->saveXML());
}
return $dom;
} | [
"public",
"static",
"function",
"fromArray",
"(",
"$",
"input",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"input",
")",
"&&",
"method_exists",
"(",
"$",
"input",
",",
"'toArray'",
")",
"&&",
"is_callable",
"(",
"[",
"$",
"input",
",",
"'toArray'",
"]",
")",
")",
"{",
"$",
"input",
"=",
"call_user_func",
"(",
"[",
"$",
"input",
",",
"'toArray'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"input",
")",
"||",
"count",
"(",
"$",
"input",
")",
"!==",
"1",
")",
"{",
"throw",
"new",
"XmlException",
"(",
"'Invalid input.'",
")",
";",
"}",
"$",
"key",
"=",
"key",
"(",
"$",
"input",
")",
";",
"if",
"(",
"is_int",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"XmlException",
"(",
"'The key of input must be alphanumeric'",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"=",
"[",
"'format'",
"=>",
"(",
"string",
")",
"$",
"options",
"]",
";",
"}",
"$",
"defaults",
"=",
"[",
"'format'",
"=>",
"'tags'",
",",
"'version'",
"=>",
"'1.0'",
",",
"'encoding'",
"=>",
"mb_internal_encoding",
"(",
")",
",",
"'return'",
"=>",
"'simplexml'",
",",
"'pretty'",
"=>",
"false",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"$",
"dom",
"=",
"new",
"DOMDocument",
"(",
"$",
"options",
"[",
"'version'",
"]",
",",
"$",
"options",
"[",
"'encoding'",
"]",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'pretty'",
"]",
")",
"{",
"$",
"dom",
"->",
"formatOutput",
"=",
"true",
";",
"}",
"self",
"::",
"_fromArray",
"(",
"$",
"dom",
",",
"$",
"dom",
",",
"$",
"input",
",",
"$",
"options",
"[",
"'format'",
"]",
")",
";",
"$",
"options",
"[",
"'return'",
"]",
"=",
"strtolower",
"(",
"$",
"options",
"[",
"'return'",
"]",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'return'",
"]",
"===",
"'simplexml'",
"||",
"$",
"options",
"[",
"'return'",
"]",
"===",
"'simplexmlelement'",
")",
"{",
"return",
"new",
"SimpleXMLElement",
"(",
"$",
"dom",
"->",
"saveXML",
"(",
")",
")",
";",
"}",
"return",
"$",
"dom",
";",
"}"
] | Transform an array into a SimpleXMLElement
### Options
- `format` If create childs ('tags') or attributes ('attributes').
- `pretty` Returns formatted Xml when set to `true`. Defaults to `false`
- `version` Version of XML document. Default is 1.0.
- `encoding` Encoding of XML document. If null remove from XML header. Default is the some of application.
- `return` If return object of SimpleXMLElement ('simplexml') or DOMDocument ('domdocument'). Default is SimpleXMLElement.
Using the following data:
```
$value = [
'root' => [
'tag' => [
'id' => 1,
'value' => 'defect',
'@' => 'description'
]
]
];
```
Calling `Xml::fromArray($value, 'tags');` Will generate:
`<root><tag><id>1</id><value>defect</value>description</tag></root>`
And calling `Xml::fromArray($value, 'attributes');` Will generate:
`<root><tag id="1" value="defect">description</tag></root>`
@param array|\Cake\Collection\Collection $input Array with data or a collection instance.
@param string|array $options The options to use or a string to use as format.
@return \SimpleXMLElement|\DOMDocument SimpleXMLElement or DOMDocument
@throws \Cake\Utility\Exception\XmlException | [
"Transform",
"an",
"array",
"into",
"a",
"SimpleXMLElement"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/Xml.php#L255-L292 |
210,599 | cakephp/cakephp | src/Utility/Xml.php | Xml._fromArray | protected static function _fromArray($dom, $node, &$data, $format)
{
if (empty($data) || !is_array($data)) {
return;
}
foreach ($data as $key => $value) {
if (is_string($key)) {
if (is_object($value) && method_exists($value, 'toArray') && is_callable([$value, 'toArray'])) {
$value = call_user_func([$value, 'toArray']);
}
if (!is_array($value)) {
if (is_bool($value)) {
$value = (int)$value;
} elseif ($value === null) {
$value = '';
}
$isNamespace = strpos($key, 'xmlns:');
if ($isNamespace !== false) {
$node->setAttributeNS('http://www.w3.org/2000/xmlns/', $key, $value);
continue;
}
if ($key[0] !== '@' && $format === 'tags') {
if (!is_numeric($value)) {
// Escape special characters
// https://www.w3.org/TR/REC-xml/#syntax
// https://bugs.php.net/bug.php?id=36795
$child = $dom->createElement($key, '');
$child->appendChild(new DOMText($value));
} else {
$child = $dom->createElement($key, $value);
}
$node->appendChild($child);
} else {
if ($key[0] === '@') {
$key = substr($key, 1);
}
$attribute = $dom->createAttribute($key);
$attribute->appendChild($dom->createTextNode($value));
$node->appendChild($attribute);
}
} else {
if ($key[0] === '@') {
throw new XmlException('Invalid array');
}
if (is_numeric(implode('', array_keys($value)))) {
// List
foreach ($value as $item) {
$itemData = compact('dom', 'node', 'key', 'format');
$itemData['value'] = $item;
static::_createChild($itemData);
}
} else {
// Struct
static::_createChild(compact('dom', 'node', 'key', 'value', 'format'));
}
}
} else {
throw new XmlException('Invalid array');
}
}
} | php | protected static function _fromArray($dom, $node, &$data, $format)
{
if (empty($data) || !is_array($data)) {
return;
}
foreach ($data as $key => $value) {
if (is_string($key)) {
if (is_object($value) && method_exists($value, 'toArray') && is_callable([$value, 'toArray'])) {
$value = call_user_func([$value, 'toArray']);
}
if (!is_array($value)) {
if (is_bool($value)) {
$value = (int)$value;
} elseif ($value === null) {
$value = '';
}
$isNamespace = strpos($key, 'xmlns:');
if ($isNamespace !== false) {
$node->setAttributeNS('http://www.w3.org/2000/xmlns/', $key, $value);
continue;
}
if ($key[0] !== '@' && $format === 'tags') {
if (!is_numeric($value)) {
// Escape special characters
// https://www.w3.org/TR/REC-xml/#syntax
// https://bugs.php.net/bug.php?id=36795
$child = $dom->createElement($key, '');
$child->appendChild(new DOMText($value));
} else {
$child = $dom->createElement($key, $value);
}
$node->appendChild($child);
} else {
if ($key[0] === '@') {
$key = substr($key, 1);
}
$attribute = $dom->createAttribute($key);
$attribute->appendChild($dom->createTextNode($value));
$node->appendChild($attribute);
}
} else {
if ($key[0] === '@') {
throw new XmlException('Invalid array');
}
if (is_numeric(implode('', array_keys($value)))) {
// List
foreach ($value as $item) {
$itemData = compact('dom', 'node', 'key', 'format');
$itemData['value'] = $item;
static::_createChild($itemData);
}
} else {
// Struct
static::_createChild(compact('dom', 'node', 'key', 'value', 'format'));
}
}
} else {
throw new XmlException('Invalid array');
}
}
} | [
"protected",
"static",
"function",
"_fromArray",
"(",
"$",
"dom",
",",
"$",
"node",
",",
"&",
"$",
"data",
",",
"$",
"format",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"data",
")",
"||",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
"&&",
"method_exists",
"(",
"$",
"value",
",",
"'toArray'",
")",
"&&",
"is_callable",
"(",
"[",
"$",
"value",
",",
"'toArray'",
"]",
")",
")",
"{",
"$",
"value",
"=",
"call_user_func",
"(",
"[",
"$",
"value",
",",
"'toArray'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"(",
"int",
")",
"$",
"value",
";",
"}",
"elseif",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"$",
"value",
"=",
"''",
";",
"}",
"$",
"isNamespace",
"=",
"strpos",
"(",
"$",
"key",
",",
"'xmlns:'",
")",
";",
"if",
"(",
"$",
"isNamespace",
"!==",
"false",
")",
"{",
"$",
"node",
"->",
"setAttributeNS",
"(",
"'http://www.w3.org/2000/xmlns/'",
",",
"$",
"key",
",",
"$",
"value",
")",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"key",
"[",
"0",
"]",
"!==",
"'@'",
"&&",
"$",
"format",
"===",
"'tags'",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"// Escape special characters",
"// https://www.w3.org/TR/REC-xml/#syntax",
"// https://bugs.php.net/bug.php?id=36795",
"$",
"child",
"=",
"$",
"dom",
"->",
"createElement",
"(",
"$",
"key",
",",
"''",
")",
";",
"$",
"child",
"->",
"appendChild",
"(",
"new",
"DOMText",
"(",
"$",
"value",
")",
")",
";",
"}",
"else",
"{",
"$",
"child",
"=",
"$",
"dom",
"->",
"createElement",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"$",
"node",
"->",
"appendChild",
"(",
"$",
"child",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"key",
"[",
"0",
"]",
"===",
"'@'",
")",
"{",
"$",
"key",
"=",
"substr",
"(",
"$",
"key",
",",
"1",
")",
";",
"}",
"$",
"attribute",
"=",
"$",
"dom",
"->",
"createAttribute",
"(",
"$",
"key",
")",
";",
"$",
"attribute",
"->",
"appendChild",
"(",
"$",
"dom",
"->",
"createTextNode",
"(",
"$",
"value",
")",
")",
";",
"$",
"node",
"->",
"appendChild",
"(",
"$",
"attribute",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"key",
"[",
"0",
"]",
"===",
"'@'",
")",
"{",
"throw",
"new",
"XmlException",
"(",
"'Invalid array'",
")",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"implode",
"(",
"''",
",",
"array_keys",
"(",
"$",
"value",
")",
")",
")",
")",
"{",
"// List",
"foreach",
"(",
"$",
"value",
"as",
"$",
"item",
")",
"{",
"$",
"itemData",
"=",
"compact",
"(",
"'dom'",
",",
"'node'",
",",
"'key'",
",",
"'format'",
")",
";",
"$",
"itemData",
"[",
"'value'",
"]",
"=",
"$",
"item",
";",
"static",
"::",
"_createChild",
"(",
"$",
"itemData",
")",
";",
"}",
"}",
"else",
"{",
"// Struct",
"static",
"::",
"_createChild",
"(",
"compact",
"(",
"'dom'",
",",
"'node'",
",",
"'key'",
",",
"'value'",
",",
"'format'",
")",
")",
";",
"}",
"}",
"}",
"else",
"{",
"throw",
"new",
"XmlException",
"(",
"'Invalid array'",
")",
";",
"}",
"}",
"}"
] | Recursive method to create childs from array
@param \DOMDocument $dom Handler to DOMDocument
@param \DOMElement $node Handler to DOMElement (child)
@param array $data Array of data to append to the $node.
@param string $format Either 'attributes' or 'tags'. This determines where nested keys go.
@return void
@throws \Cake\Utility\Exception\XmlException | [
"Recursive",
"method",
"to",
"create",
"childs",
"from",
"array"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Utility/Xml.php#L304-L365 |
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.