id int32 0 241k | repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 |
|---|---|---|---|---|---|---|---|---|---|---|---|
211,000 | cakephp/cakephp | src/ORM/Behavior/TreeBehavior.php | TreeBehavior._recoverTree | protected function _recoverTree($counter = 0, $parentId = null, $level = -1)
{
$config = $this->getConfig();
list($parent, $left, $right) = [$config['parent'], $config['left'], $config['right']];
$primaryKey = $this->_getPrimaryKey();
$aliasedPrimaryKey = $this->_table->aliasField($primaryKey);
$order = $config['recoverOrder'] ?: $aliasedPrimaryKey;
$query = $this->_scope($this->_table->query())
->select([$aliasedPrimaryKey])
->where([$this->_table->aliasField($parent) . ' IS' => $parentId])
->order($order)
->disableHydration();
$leftCounter = $counter;
$nextLevel = $level + 1;
foreach ($query as $row) {
$counter++;
$counter = $this->_recoverTree($counter, $row[$primaryKey], $nextLevel);
}
if ($parentId === null) {
return $counter;
}
$fields = [$left => $leftCounter, $right => $counter + 1];
if ($config['level']) {
$fields[$config['level']] = $level;
}
$this->_table->updateAll(
$fields,
[$primaryKey => $parentId]
);
return $counter + 1;
} | php | protected function _recoverTree($counter = 0, $parentId = null, $level = -1)
{
$config = $this->getConfig();
list($parent, $left, $right) = [$config['parent'], $config['left'], $config['right']];
$primaryKey = $this->_getPrimaryKey();
$aliasedPrimaryKey = $this->_table->aliasField($primaryKey);
$order = $config['recoverOrder'] ?: $aliasedPrimaryKey;
$query = $this->_scope($this->_table->query())
->select([$aliasedPrimaryKey])
->where([$this->_table->aliasField($parent) . ' IS' => $parentId])
->order($order)
->disableHydration();
$leftCounter = $counter;
$nextLevel = $level + 1;
foreach ($query as $row) {
$counter++;
$counter = $this->_recoverTree($counter, $row[$primaryKey], $nextLevel);
}
if ($parentId === null) {
return $counter;
}
$fields = [$left => $leftCounter, $right => $counter + 1];
if ($config['level']) {
$fields[$config['level']] = $level;
}
$this->_table->updateAll(
$fields,
[$primaryKey => $parentId]
);
return $counter + 1;
} | [
"protected",
"function",
"_recoverTree",
"(",
"$",
"counter",
"=",
"0",
",",
"$",
"parentId",
"=",
"null",
",",
"$",
"level",
"=",
"-",
"1",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
";",
"list",
"(",
"$",
"parent",
",",
"$",
"left",
",",
"$",
"right",
")",
"=",
"[",
"$",
"config",
"[",
"'parent'",
"]",
",",
"$",
"config",
"[",
"'left'",
"]",
",",
"$",
"config",
"[",
"'right'",
"]",
"]",
";",
"$",
"primaryKey",
"=",
"$",
"this",
"->",
"_getPrimaryKey",
"(",
")",
";",
"$",
"aliasedPrimaryKey",
"=",
"$",
"this",
"->",
"_table",
"->",
"aliasField",
"(",
"$",
"primaryKey",
")",
";",
"$",
"order",
"=",
"$",
"config",
"[",
"'recoverOrder'",
"]",
"?",
":",
"$",
"aliasedPrimaryKey",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"_scope",
"(",
"$",
"this",
"->",
"_table",
"->",
"query",
"(",
")",
")",
"->",
"select",
"(",
"[",
"$",
"aliasedPrimaryKey",
"]",
")",
"->",
"where",
"(",
"[",
"$",
"this",
"->",
"_table",
"->",
"aliasField",
"(",
"$",
"parent",
")",
".",
"' IS'",
"=>",
"$",
"parentId",
"]",
")",
"->",
"order",
"(",
"$",
"order",
")",
"->",
"disableHydration",
"(",
")",
";",
"$",
"leftCounter",
"=",
"$",
"counter",
";",
"$",
"nextLevel",
"=",
"$",
"level",
"+",
"1",
";",
"foreach",
"(",
"$",
"query",
"as",
"$",
"row",
")",
"{",
"$",
"counter",
"++",
";",
"$",
"counter",
"=",
"$",
"this",
"->",
"_recoverTree",
"(",
"$",
"counter",
",",
"$",
"row",
"[",
"$",
"primaryKey",
"]",
",",
"$",
"nextLevel",
")",
";",
"}",
"if",
"(",
"$",
"parentId",
"===",
"null",
")",
"{",
"return",
"$",
"counter",
";",
"}",
"$",
"fields",
"=",
"[",
"$",
"left",
"=>",
"$",
"leftCounter",
",",
"$",
"right",
"=>",
"$",
"counter",
"+",
"1",
"]",
";",
"if",
"(",
"$",
"config",
"[",
"'level'",
"]",
")",
"{",
"$",
"fields",
"[",
"$",
"config",
"[",
"'level'",
"]",
"]",
"=",
"$",
"level",
";",
"}",
"$",
"this",
"->",
"_table",
"->",
"updateAll",
"(",
"$",
"fields",
",",
"[",
"$",
"primaryKey",
"=>",
"$",
"parentId",
"]",
")",
";",
"return",
"$",
"counter",
"+",
"1",
";",
"}"
] | Recursive method used to recover a single level of the tree
@param int $counter The Last left column value that was assigned
@param mixed $parentId the parent id of the level to be recovered
@param int $level Node level
@return int The next value to use for the left column | [
"Recursive",
"method",
"used",
"to",
"recover",
"a",
"single",
"level",
"of",
"the",
"tree"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TreeBehavior.php#L828-L864 |
211,001 | cakephp/cakephp | src/ORM/Behavior/TreeBehavior.php | TreeBehavior._getMax | protected function _getMax()
{
$field = $this->_config['right'];
$rightField = $this->_config['rightField'];
$edge = $this->_scope($this->_table->find())
->select([$field])
->orderDesc($rightField)
->first();
if (empty($edge->{$field})) {
return 0;
}
return $edge->{$field};
} | php | protected function _getMax()
{
$field = $this->_config['right'];
$rightField = $this->_config['rightField'];
$edge = $this->_scope($this->_table->find())
->select([$field])
->orderDesc($rightField)
->first();
if (empty($edge->{$field})) {
return 0;
}
return $edge->{$field};
} | [
"protected",
"function",
"_getMax",
"(",
")",
"{",
"$",
"field",
"=",
"$",
"this",
"->",
"_config",
"[",
"'right'",
"]",
";",
"$",
"rightField",
"=",
"$",
"this",
"->",
"_config",
"[",
"'rightField'",
"]",
";",
"$",
"edge",
"=",
"$",
"this",
"->",
"_scope",
"(",
"$",
"this",
"->",
"_table",
"->",
"find",
"(",
")",
")",
"->",
"select",
"(",
"[",
"$",
"field",
"]",
")",
"->",
"orderDesc",
"(",
"$",
"rightField",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"edge",
"->",
"{",
"$",
"field",
"}",
")",
")",
"{",
"return",
"0",
";",
"}",
"return",
"$",
"edge",
"->",
"{",
"$",
"field",
"}",
";",
"}"
] | Returns the maximum index value in the table.
@return int | [
"Returns",
"the",
"maximum",
"index",
"value",
"in",
"the",
"table",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TreeBehavior.php#L871-L885 |
211,002 | cakephp/cakephp | src/ORM/Behavior/TreeBehavior.php | TreeBehavior._sync | protected function _sync($shift, $dir, $conditions, $mark = false)
{
$config = $this->_config;
foreach ([$config['leftField'], $config['rightField']] as $field) {
$query = $this->_scope($this->_table->query());
$exp = $query->newExpr();
$movement = clone $exp;
$movement->add($field)->add((string)$shift)->setConjunction($dir);
$inverse = clone $exp;
$movement = $mark ?
$inverse->add($movement)->setConjunction('*')->add('-1') :
$movement;
$where = clone $exp;
$where->add($field)->add($conditions)->setConjunction('');
$query->update()
->set($exp->eq($field, $movement))
->where($where);
$query->execute()->closeCursor();
}
} | php | protected function _sync($shift, $dir, $conditions, $mark = false)
{
$config = $this->_config;
foreach ([$config['leftField'], $config['rightField']] as $field) {
$query = $this->_scope($this->_table->query());
$exp = $query->newExpr();
$movement = clone $exp;
$movement->add($field)->add((string)$shift)->setConjunction($dir);
$inverse = clone $exp;
$movement = $mark ?
$inverse->add($movement)->setConjunction('*')->add('-1') :
$movement;
$where = clone $exp;
$where->add($field)->add($conditions)->setConjunction('');
$query->update()
->set($exp->eq($field, $movement))
->where($where);
$query->execute()->closeCursor();
}
} | [
"protected",
"function",
"_sync",
"(",
"$",
"shift",
",",
"$",
"dir",
",",
"$",
"conditions",
",",
"$",
"mark",
"=",
"false",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"_config",
";",
"foreach",
"(",
"[",
"$",
"config",
"[",
"'leftField'",
"]",
",",
"$",
"config",
"[",
"'rightField'",
"]",
"]",
"as",
"$",
"field",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"_scope",
"(",
"$",
"this",
"->",
"_table",
"->",
"query",
"(",
")",
")",
";",
"$",
"exp",
"=",
"$",
"query",
"->",
"newExpr",
"(",
")",
";",
"$",
"movement",
"=",
"clone",
"$",
"exp",
";",
"$",
"movement",
"->",
"add",
"(",
"$",
"field",
")",
"->",
"add",
"(",
"(",
"string",
")",
"$",
"shift",
")",
"->",
"setConjunction",
"(",
"$",
"dir",
")",
";",
"$",
"inverse",
"=",
"clone",
"$",
"exp",
";",
"$",
"movement",
"=",
"$",
"mark",
"?",
"$",
"inverse",
"->",
"add",
"(",
"$",
"movement",
")",
"->",
"setConjunction",
"(",
"'*'",
")",
"->",
"add",
"(",
"'-1'",
")",
":",
"$",
"movement",
";",
"$",
"where",
"=",
"clone",
"$",
"exp",
";",
"$",
"where",
"->",
"add",
"(",
"$",
"field",
")",
"->",
"add",
"(",
"$",
"conditions",
")",
"->",
"setConjunction",
"(",
"''",
")",
";",
"$",
"query",
"->",
"update",
"(",
")",
"->",
"set",
"(",
"$",
"exp",
"->",
"eq",
"(",
"$",
"field",
",",
"$",
"movement",
")",
")",
"->",
"where",
"(",
"$",
"where",
")",
";",
"$",
"query",
"->",
"execute",
"(",
")",
"->",
"closeCursor",
"(",
")",
";",
"}",
"}"
] | Auxiliary function used to automatically alter the value of both the left and
right columns by a certain amount that match the passed conditions
@param int $shift the value to use for operating the left and right columns
@param string $dir The operator to use for shifting the value (+/-)
@param string $conditions a SQL snipped to be used for comparing left or right
against it.
@param bool $mark whether to mark the updated values so that they can not be
modified by future calls to this function.
@return void | [
"Auxiliary",
"function",
"used",
"to",
"automatically",
"alter",
"the",
"value",
"of",
"both",
"the",
"left",
"and",
"right",
"columns",
"by",
"a",
"certain",
"amount",
"that",
"match",
"the",
"passed",
"conditions"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TreeBehavior.php#L899-L924 |
211,003 | cakephp/cakephp | src/ORM/Behavior/TreeBehavior.php | TreeBehavior._scope | protected function _scope($query)
{
$scope = $this->getConfig('scope');
if (is_array($scope)) {
return $query->where($scope);
}
if (is_callable($scope)) {
return $scope($query);
}
return $query;
} | php | protected function _scope($query)
{
$scope = $this->getConfig('scope');
if (is_array($scope)) {
return $query->where($scope);
}
if (is_callable($scope)) {
return $scope($query);
}
return $query;
} | [
"protected",
"function",
"_scope",
"(",
"$",
"query",
")",
"{",
"$",
"scope",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'scope'",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"scope",
")",
")",
"{",
"return",
"$",
"query",
"->",
"where",
"(",
"$",
"scope",
")",
";",
"}",
"if",
"(",
"is_callable",
"(",
"$",
"scope",
")",
")",
"{",
"return",
"$",
"scope",
"(",
"$",
"query",
")",
";",
"}",
"return",
"$",
"query",
";",
"}"
] | Alters the passed query so that it only returns scoped records as defined
in the tree configuration.
@param \Cake\ORM\Query $query the Query to modify
@return \Cake\ORM\Query | [
"Alters",
"the",
"passed",
"query",
"so",
"that",
"it",
"only",
"returns",
"scoped",
"records",
"as",
"defined",
"in",
"the",
"tree",
"configuration",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TreeBehavior.php#L933-L945 |
211,004 | cakephp/cakephp | src/ORM/Behavior/TreeBehavior.php | TreeBehavior._ensureFields | protected function _ensureFields($entity)
{
$config = $this->getConfig();
$fields = [$config['left'], $config['right']];
$values = array_filter($entity->extract($fields));
if (count($values) === count($fields)) {
return;
}
$fresh = $this->_table->get($entity->get($this->_getPrimaryKey()), $fields);
$entity->set($fresh->extract($fields), ['guard' => false]);
foreach ($fields as $field) {
$entity->setDirty($field, false);
}
} | php | protected function _ensureFields($entity)
{
$config = $this->getConfig();
$fields = [$config['left'], $config['right']];
$values = array_filter($entity->extract($fields));
if (count($values) === count($fields)) {
return;
}
$fresh = $this->_table->get($entity->get($this->_getPrimaryKey()), $fields);
$entity->set($fresh->extract($fields), ['guard' => false]);
foreach ($fields as $field) {
$entity->setDirty($field, false);
}
} | [
"protected",
"function",
"_ensureFields",
"(",
"$",
"entity",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
";",
"$",
"fields",
"=",
"[",
"$",
"config",
"[",
"'left'",
"]",
",",
"$",
"config",
"[",
"'right'",
"]",
"]",
";",
"$",
"values",
"=",
"array_filter",
"(",
"$",
"entity",
"->",
"extract",
"(",
"$",
"fields",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"values",
")",
"===",
"count",
"(",
"$",
"fields",
")",
")",
"{",
"return",
";",
"}",
"$",
"fresh",
"=",
"$",
"this",
"->",
"_table",
"->",
"get",
"(",
"$",
"entity",
"->",
"get",
"(",
"$",
"this",
"->",
"_getPrimaryKey",
"(",
")",
")",
",",
"$",
"fields",
")",
";",
"$",
"entity",
"->",
"set",
"(",
"$",
"fresh",
"->",
"extract",
"(",
"$",
"fields",
")",
",",
"[",
"'guard'",
"=>",
"false",
"]",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"$",
"entity",
"->",
"setDirty",
"(",
"$",
"field",
",",
"false",
")",
";",
"}",
"}"
] | Ensures that the provided entity contains non-empty values for the left and
right fields
@param \Cake\Datasource\EntityInterface $entity The entity to ensure fields for
@return void | [
"Ensures",
"that",
"the",
"provided",
"entity",
"contains",
"non",
"-",
"empty",
"values",
"for",
"the",
"left",
"and",
"right",
"fields"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TreeBehavior.php#L954-L969 |
211,005 | cakephp/cakephp | src/ORM/Behavior/TreeBehavior.php | TreeBehavior._getPrimaryKey | protected function _getPrimaryKey()
{
if (!$this->_primaryKey) {
$primaryKey = (array)$this->_table->getPrimaryKey();
$this->_primaryKey = $primaryKey[0];
}
return $this->_primaryKey;
} | php | protected function _getPrimaryKey()
{
if (!$this->_primaryKey) {
$primaryKey = (array)$this->_table->getPrimaryKey();
$this->_primaryKey = $primaryKey[0];
}
return $this->_primaryKey;
} | [
"protected",
"function",
"_getPrimaryKey",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_primaryKey",
")",
"{",
"$",
"primaryKey",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"_table",
"->",
"getPrimaryKey",
"(",
")",
";",
"$",
"this",
"->",
"_primaryKey",
"=",
"$",
"primaryKey",
"[",
"0",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"_primaryKey",
";",
"}"
] | Returns a single string value representing the primary key of the attached table
@return string | [
"Returns",
"a",
"single",
"string",
"value",
"representing",
"the",
"primary",
"key",
"of",
"the",
"attached",
"table"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TreeBehavior.php#L976-L984 |
211,006 | cakephp/cakephp | src/ORM/Behavior/TreeBehavior.php | TreeBehavior.getLevel | public function getLevel($entity)
{
$primaryKey = $this->_getPrimaryKey();
$id = $entity;
if ($entity instanceof EntityInterface) {
$id = $entity->get($primaryKey);
}
$config = $this->getConfig();
$entity = $this->_table->find('all')
->select([$config['left'], $config['right']])
->where([$primaryKey => $id])
->first();
if ($entity === null) {
return false;
}
$query = $this->_table->find('all')->where([
$config['left'] . ' <' => $entity[$config['left']],
$config['right'] . ' >' => $entity[$config['right']],
]);
return $this->_scope($query)->count();
} | php | public function getLevel($entity)
{
$primaryKey = $this->_getPrimaryKey();
$id = $entity;
if ($entity instanceof EntityInterface) {
$id = $entity->get($primaryKey);
}
$config = $this->getConfig();
$entity = $this->_table->find('all')
->select([$config['left'], $config['right']])
->where([$primaryKey => $id])
->first();
if ($entity === null) {
return false;
}
$query = $this->_table->find('all')->where([
$config['left'] . ' <' => $entity[$config['left']],
$config['right'] . ' >' => $entity[$config['right']],
]);
return $this->_scope($query)->count();
} | [
"public",
"function",
"getLevel",
"(",
"$",
"entity",
")",
"{",
"$",
"primaryKey",
"=",
"$",
"this",
"->",
"_getPrimaryKey",
"(",
")",
";",
"$",
"id",
"=",
"$",
"entity",
";",
"if",
"(",
"$",
"entity",
"instanceof",
"EntityInterface",
")",
"{",
"$",
"id",
"=",
"$",
"entity",
"->",
"get",
"(",
"$",
"primaryKey",
")",
";",
"}",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
";",
"$",
"entity",
"=",
"$",
"this",
"->",
"_table",
"->",
"find",
"(",
"'all'",
")",
"->",
"select",
"(",
"[",
"$",
"config",
"[",
"'left'",
"]",
",",
"$",
"config",
"[",
"'right'",
"]",
"]",
")",
"->",
"where",
"(",
"[",
"$",
"primaryKey",
"=>",
"$",
"id",
"]",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"$",
"entity",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"$",
"query",
"=",
"$",
"this",
"->",
"_table",
"->",
"find",
"(",
"'all'",
")",
"->",
"where",
"(",
"[",
"$",
"config",
"[",
"'left'",
"]",
".",
"' <'",
"=>",
"$",
"entity",
"[",
"$",
"config",
"[",
"'left'",
"]",
"]",
",",
"$",
"config",
"[",
"'right'",
"]",
".",
"' >'",
"=>",
"$",
"entity",
"[",
"$",
"config",
"[",
"'right'",
"]",
"]",
",",
"]",
")",
";",
"return",
"$",
"this",
"->",
"_scope",
"(",
"$",
"query",
")",
"->",
"count",
"(",
")",
";",
"}"
] | Returns the depth level of a node in the tree.
@param int|string|\Cake\Datasource\EntityInterface $entity The entity or primary key get the level of.
@return int|bool Integer of the level or false if the node does not exist. | [
"Returns",
"the",
"depth",
"level",
"of",
"a",
"node",
"in",
"the",
"tree",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Behavior/TreeBehavior.php#L992-L1015 |
211,007 | cakephp/cakephp | src/Database/Query.php | Query.connection | public function connection($connection = null)
{
deprecationWarning(
'Query::connection() is deprecated. ' .
'Use Query::setConnection()/getConnection() instead.'
);
if ($connection !== null) {
return $this->setConnection($connection);
}
return $this->getConnection();
} | php | public function connection($connection = null)
{
deprecationWarning(
'Query::connection() is deprecated. ' .
'Use Query::setConnection()/getConnection() instead.'
);
if ($connection !== null) {
return $this->setConnection($connection);
}
return $this->getConnection();
} | [
"public",
"function",
"connection",
"(",
"$",
"connection",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"'Query::connection() is deprecated. '",
".",
"'Use Query::setConnection()/getConnection() instead.'",
")",
";",
"if",
"(",
"$",
"connection",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"setConnection",
"(",
"$",
"connection",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getConnection",
"(",
")",
";",
"}"
] | Sets the connection instance to be used for executing and transforming this query
When called with a null argument, it will return the current connection instance.
@deprecated 3.4.0 Use setConnection()/getConnection() instead.
@param \Cake\Database\Connection|null $connection Connection instance
@return $this|\Cake\Database\Connection | [
"Sets",
"the",
"connection",
"instance",
"to",
"be",
"used",
"for",
"executing",
"and",
"transforming",
"this",
"query",
"When",
"called",
"with",
"a",
"null",
"argument",
"it",
"will",
"return",
"the",
"current",
"connection",
"instance",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L184-L195 |
211,008 | cakephp/cakephp | src/Database/Query.php | Query.execute | public function execute()
{
$statement = $this->_connection->run($this);
$this->_iterator = $this->_decorateStatement($statement);
$this->_dirty = false;
return $this->_iterator;
} | php | public function execute()
{
$statement = $this->_connection->run($this);
$this->_iterator = $this->_decorateStatement($statement);
$this->_dirty = false;
return $this->_iterator;
} | [
"public",
"function",
"execute",
"(",
")",
"{",
"$",
"statement",
"=",
"$",
"this",
"->",
"_connection",
"->",
"run",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"_iterator",
"=",
"$",
"this",
"->",
"_decorateStatement",
"(",
"$",
"statement",
")",
";",
"$",
"this",
"->",
"_dirty",
"=",
"false",
";",
"return",
"$",
"this",
"->",
"_iterator",
";",
"}"
] | Compiles the SQL representation of this query and executes it using the
configured connection object. Returns the resulting statement object.
Executing a query internally executes several steps, the first one is
letting the connection transform this object to fit its particular dialect,
this might result in generating a different Query object that will be the one
to actually be executed. Immediately after, literal values are passed to the
connection so they are bound to the query in a safe way. Finally, the resulting
statement is decorated with custom objects to execute callbacks for each row
retrieved if necessary.
Resulting statement is traversable, so it can be used in any loop as you would
with an array.
This method can be overridden in query subclasses to decorate behavior
around query execution.
@return \Cake\Database\StatementInterface | [
"Compiles",
"the",
"SQL",
"representation",
"of",
"this",
"query",
"and",
"executes",
"it",
"using",
"the",
"configured",
"connection",
"object",
".",
"Returns",
"the",
"resulting",
"statement",
"object",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L217-L224 |
211,009 | cakephp/cakephp | src/Database/Query.php | Query.sql | public function sql(ValueBinder $generator = null)
{
if (!$generator) {
$generator = $this->getValueBinder();
$generator->resetCount();
}
return $this->getConnection()->compileQuery($this, $generator);
} | php | public function sql(ValueBinder $generator = null)
{
if (!$generator) {
$generator = $this->getValueBinder();
$generator->resetCount();
}
return $this->getConnection()->compileQuery($this, $generator);
} | [
"public",
"function",
"sql",
"(",
"ValueBinder",
"$",
"generator",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"generator",
")",
"{",
"$",
"generator",
"=",
"$",
"this",
"->",
"getValueBinder",
"(",
")",
";",
"$",
"generator",
"->",
"resetCount",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"compileQuery",
"(",
"$",
"this",
",",
"$",
"generator",
")",
";",
"}"
] | Returns the SQL representation of this object.
This function will compile this query to make it compatible
with the SQL dialect that is used by the connection, This process might
add, remove or alter any query part or internal expression to make it
executable in the target platform.
The resulting query may have placeholders that will be replaced with the actual
values when the query is executed, hence it is most suitable to use with
prepared statements.
@param \Cake\Database\ValueBinder|null $generator A placeholder object that will hold
associated values for expressions
@return string | [
"Returns",
"the",
"SQL",
"representation",
"of",
"this",
"object",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L273-L281 |
211,010 | cakephp/cakephp | src/Database/Query.php | Query.traverse | public function traverse(callable $visitor, array $parts = [])
{
$parts = $parts ?: array_keys($this->_parts);
foreach ($parts as $name) {
$visitor($this->_parts[$name], $name);
}
return $this;
} | php | public function traverse(callable $visitor, array $parts = [])
{
$parts = $parts ?: array_keys($this->_parts);
foreach ($parts as $name) {
$visitor($this->_parts[$name], $name);
}
return $this;
} | [
"public",
"function",
"traverse",
"(",
"callable",
"$",
"visitor",
",",
"array",
"$",
"parts",
"=",
"[",
"]",
")",
"{",
"$",
"parts",
"=",
"$",
"parts",
"?",
":",
"array_keys",
"(",
"$",
"this",
"->",
"_parts",
")",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"name",
")",
"{",
"$",
"visitor",
"(",
"$",
"this",
"->",
"_parts",
"[",
"$",
"name",
"]",
",",
"$",
"name",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Will iterate over every specified part. Traversing functions can aggregate
results using variables in the closure or instance variables. This function
is commonly used as a way for traversing all query parts that
are going to be used for constructing a query.
The callback will receive 2 parameters, the first one is the value of the query
part that is being iterated and the second the name of such part.
### Example:
```
$query->select(['title'])->from('articles')->traverse(function ($value, $clause) {
if ($clause === 'select') {
var_dump($value);
}
}, ['select', 'from']);
```
@param callable $visitor A function or callable to be executed for each part
@param string[] $parts The query clauses to traverse
@return $this | [
"Will",
"iterate",
"over",
"every",
"specified",
"part",
".",
"Traversing",
"functions",
"can",
"aggregate",
"results",
"using",
"variables",
"in",
"the",
"closure",
"or",
"instance",
"variables",
".",
"This",
"function",
"is",
"commonly",
"used",
"as",
"a",
"way",
"for",
"traversing",
"all",
"query",
"parts",
"that",
"are",
"going",
"to",
"be",
"used",
"for",
"constructing",
"a",
"query",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L305-L313 |
211,011 | cakephp/cakephp | src/Database/Query.php | Query.distinct | public function distinct($on = [], $overwrite = false)
{
if ($on === []) {
$on = true;
} elseif (is_string($on)) {
$on = [$on];
}
if (is_array($on)) {
$merge = [];
if (is_array($this->_parts['distinct'])) {
$merge = $this->_parts['distinct'];
}
$on = $overwrite ? array_values($on) : array_merge($merge, array_values($on));
}
$this->_parts['distinct'] = $on;
$this->_dirty();
return $this;
} | php | public function distinct($on = [], $overwrite = false)
{
if ($on === []) {
$on = true;
} elseif (is_string($on)) {
$on = [$on];
}
if (is_array($on)) {
$merge = [];
if (is_array($this->_parts['distinct'])) {
$merge = $this->_parts['distinct'];
}
$on = $overwrite ? array_values($on) : array_merge($merge, array_values($on));
}
$this->_parts['distinct'] = $on;
$this->_dirty();
return $this;
} | [
"public",
"function",
"distinct",
"(",
"$",
"on",
"=",
"[",
"]",
",",
"$",
"overwrite",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"on",
"===",
"[",
"]",
")",
"{",
"$",
"on",
"=",
"true",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"on",
")",
")",
"{",
"$",
"on",
"=",
"[",
"$",
"on",
"]",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"on",
")",
")",
"{",
"$",
"merge",
"=",
"[",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"_parts",
"[",
"'distinct'",
"]",
")",
")",
"{",
"$",
"merge",
"=",
"$",
"this",
"->",
"_parts",
"[",
"'distinct'",
"]",
";",
"}",
"$",
"on",
"=",
"$",
"overwrite",
"?",
"array_values",
"(",
"$",
"on",
")",
":",
"array_merge",
"(",
"$",
"merge",
",",
"array_values",
"(",
"$",
"on",
")",
")",
";",
"}",
"$",
"this",
"->",
"_parts",
"[",
"'distinct'",
"]",
"=",
"$",
"on",
";",
"$",
"this",
"->",
"_dirty",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Adds a `DISTINCT` clause to the query to remove duplicates from the result set.
This clause can only be used for select statements.
If you wish to filter duplicates based of those rows sharing a particular field
or set of fields, you may pass an array of fields to filter on. Beware that
this option might not be fully supported in all database systems.
### Examples:
```
// Filters products with the same name and city
$query->select(['name', 'city'])->from('products')->distinct();
// Filters products in the same city
$query->distinct(['city']);
$query->distinct('city');
// Filter products with the same name
$query->distinct(['name'], true);
$query->distinct('name', true);
```
@param array|\Cake\Database\ExpressionInterface|string|bool $on Enable/disable distinct class
or list of fields to be filtered on
@param bool $overwrite whether to reset fields with passed list or not
@return $this | [
"Adds",
"a",
"DISTINCT",
"clause",
"to",
"the",
"query",
"to",
"remove",
"duplicates",
"from",
"the",
"result",
"set",
".",
"This",
"clause",
"can",
"only",
"be",
"used",
"for",
"select",
"statements",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L400-L420 |
211,012 | cakephp/cakephp | src/Database/Query.php | Query.modifier | public function modifier($modifiers, $overwrite = false)
{
$this->_dirty();
if ($overwrite) {
$this->_parts['modifier'] = [];
}
$this->_parts['modifier'] = array_merge($this->_parts['modifier'], (array)$modifiers);
return $this;
} | php | public function modifier($modifiers, $overwrite = false)
{
$this->_dirty();
if ($overwrite) {
$this->_parts['modifier'] = [];
}
$this->_parts['modifier'] = array_merge($this->_parts['modifier'], (array)$modifiers);
return $this;
} | [
"public",
"function",
"modifier",
"(",
"$",
"modifiers",
",",
"$",
"overwrite",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"_dirty",
"(",
")",
";",
"if",
"(",
"$",
"overwrite",
")",
"{",
"$",
"this",
"->",
"_parts",
"[",
"'modifier'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"_parts",
"[",
"'modifier'",
"]",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"_parts",
"[",
"'modifier'",
"]",
",",
"(",
"array",
")",
"$",
"modifiers",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Adds a single or multiple `SELECT` modifiers to be used in the `SELECT`.
By default this function will append any passed argument to the list of modifiers
to be applied, unless the second argument is set to true.
### Example:
```
// Ignore cache query in MySQL
$query->select(['name', 'city'])->from('products')->modifier('SQL_NO_CACHE');
// It will produce the SQL: SELECT SQL_NO_CACHE name, city FROM products
// Or with multiple modifiers
$query->select(['name', 'city'])->from('products')->modifier(['HIGH_PRIORITY', 'SQL_NO_CACHE']);
// It will produce the SQL: SELECT HIGH_PRIORITY SQL_NO_CACHE name, city FROM products
```
@param array|\Cake\Database\ExpressionInterface|string $modifiers modifiers to be applied to the query
@param bool $overwrite whether to reset order with field list or not
@return $this | [
"Adds",
"a",
"single",
"or",
"multiple",
"SELECT",
"modifiers",
"to",
"be",
"used",
"in",
"the",
"SELECT",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L444-L453 |
211,013 | cakephp/cakephp | src/Database/Query.php | Query.from | public function from($tables = [], $overwrite = false)
{
if (empty($tables)) {
deprecationWarning('Using Query::from() to read state is deprecated. Use clause("from") instead.');
return $this->_parts['from'];
}
$tables = (array)$tables;
if ($overwrite) {
$this->_parts['from'] = $tables;
} else {
$this->_parts['from'] = array_merge($this->_parts['from'], $tables);
}
$this->_dirty();
return $this;
} | php | public function from($tables = [], $overwrite = false)
{
if (empty($tables)) {
deprecationWarning('Using Query::from() to read state is deprecated. Use clause("from") instead.');
return $this->_parts['from'];
}
$tables = (array)$tables;
if ($overwrite) {
$this->_parts['from'] = $tables;
} else {
$this->_parts['from'] = array_merge($this->_parts['from'], $tables);
}
$this->_dirty();
return $this;
} | [
"public",
"function",
"from",
"(",
"$",
"tables",
"=",
"[",
"]",
",",
"$",
"overwrite",
"=",
"false",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"tables",
")",
")",
"{",
"deprecationWarning",
"(",
"'Using Query::from() to read state is deprecated. Use clause(\"from\") instead.'",
")",
";",
"return",
"$",
"this",
"->",
"_parts",
"[",
"'from'",
"]",
";",
"}",
"$",
"tables",
"=",
"(",
"array",
")",
"$",
"tables",
";",
"if",
"(",
"$",
"overwrite",
")",
"{",
"$",
"this",
"->",
"_parts",
"[",
"'from'",
"]",
"=",
"$",
"tables",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_parts",
"[",
"'from'",
"]",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"_parts",
"[",
"'from'",
"]",
",",
"$",
"tables",
")",
";",
"}",
"$",
"this",
"->",
"_dirty",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Adds a single or multiple tables to be used in the FROM clause for this query.
Tables can be passed as an array of strings, array of expression
objects, a single expression or a single string.
If an array is passed, keys will be used to alias tables using the value as the
real field to be aliased. It is possible to alias strings, ExpressionInterface objects or
even other Query objects.
By default this function will append any passed argument to the list of tables
to be selected from, unless the second argument is set to true.
This method can be used for select, update and delete statements.
### Examples:
```
$query->from(['p' => 'posts']); // Produces FROM posts p
$query->from('authors'); // Appends authors: FROM posts p, authors
$query->from(['products'], true); // Resets the list: FROM products
$query->from(['sub' => $countQuery]); // FROM (SELECT ...) sub
```
@param array|string $tables tables to be added to the list. This argument, can be
passed as an array of strings, array of expression objects, or a single string. See
the examples above for the valid call types.
@param bool $overwrite whether to reset tables with passed list or not
@return $this|array | [
"Adds",
"a",
"single",
"or",
"multiple",
"tables",
"to",
"be",
"used",
"in",
"the",
"FROM",
"clause",
"for",
"this",
"query",
".",
"Tables",
"can",
"be",
"passed",
"as",
"an",
"array",
"of",
"strings",
"array",
"of",
"expression",
"objects",
"a",
"single",
"expression",
"or",
"a",
"single",
"string",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L484-L503 |
211,014 | cakephp/cakephp | src/Database/Query.php | Query.join | public function join($tables = null, $types = [], $overwrite = false)
{
if ($tables === null) {
deprecationWarning('Using Query::join() to read state is deprecated. Use clause("join") instead.');
return $this->_parts['join'];
}
if (is_string($tables) || isset($tables['table'])) {
$tables = [$tables];
}
$joins = [];
$i = count($this->_parts['join']);
foreach ($tables as $alias => $t) {
if (!is_array($t)) {
$t = ['table' => $t, 'conditions' => $this->newExpr()];
}
if (!is_string($t['conditions']) && is_callable($t['conditions'])) {
$t['conditions'] = $t['conditions']($this->newExpr(), $this);
}
if (!($t['conditions'] instanceof ExpressionInterface)) {
$t['conditions'] = $this->newExpr()->add($t['conditions'], $types);
}
$alias = is_string($alias) ? $alias : null;
$joins[$alias ?: $i++] = $t + ['type' => QueryInterface::JOIN_TYPE_INNER, 'alias' => $alias];
}
if ($overwrite) {
$this->_parts['join'] = $joins;
} else {
$this->_parts['join'] = array_merge($this->_parts['join'], $joins);
}
$this->_dirty();
return $this;
} | php | public function join($tables = null, $types = [], $overwrite = false)
{
if ($tables === null) {
deprecationWarning('Using Query::join() to read state is deprecated. Use clause("join") instead.');
return $this->_parts['join'];
}
if (is_string($tables) || isset($tables['table'])) {
$tables = [$tables];
}
$joins = [];
$i = count($this->_parts['join']);
foreach ($tables as $alias => $t) {
if (!is_array($t)) {
$t = ['table' => $t, 'conditions' => $this->newExpr()];
}
if (!is_string($t['conditions']) && is_callable($t['conditions'])) {
$t['conditions'] = $t['conditions']($this->newExpr(), $this);
}
if (!($t['conditions'] instanceof ExpressionInterface)) {
$t['conditions'] = $this->newExpr()->add($t['conditions'], $types);
}
$alias = is_string($alias) ? $alias : null;
$joins[$alias ?: $i++] = $t + ['type' => QueryInterface::JOIN_TYPE_INNER, 'alias' => $alias];
}
if ($overwrite) {
$this->_parts['join'] = $joins;
} else {
$this->_parts['join'] = array_merge($this->_parts['join'], $joins);
}
$this->_dirty();
return $this;
} | [
"public",
"function",
"join",
"(",
"$",
"tables",
"=",
"null",
",",
"$",
"types",
"=",
"[",
"]",
",",
"$",
"overwrite",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"tables",
"===",
"null",
")",
"{",
"deprecationWarning",
"(",
"'Using Query::join() to read state is deprecated. Use clause(\"join\") instead.'",
")",
";",
"return",
"$",
"this",
"->",
"_parts",
"[",
"'join'",
"]",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"tables",
")",
"||",
"isset",
"(",
"$",
"tables",
"[",
"'table'",
"]",
")",
")",
"{",
"$",
"tables",
"=",
"[",
"$",
"tables",
"]",
";",
"}",
"$",
"joins",
"=",
"[",
"]",
";",
"$",
"i",
"=",
"count",
"(",
"$",
"this",
"->",
"_parts",
"[",
"'join'",
"]",
")",
";",
"foreach",
"(",
"$",
"tables",
"as",
"$",
"alias",
"=>",
"$",
"t",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"t",
")",
")",
"{",
"$",
"t",
"=",
"[",
"'table'",
"=>",
"$",
"t",
",",
"'conditions'",
"=>",
"$",
"this",
"->",
"newExpr",
"(",
")",
"]",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"t",
"[",
"'conditions'",
"]",
")",
"&&",
"is_callable",
"(",
"$",
"t",
"[",
"'conditions'",
"]",
")",
")",
"{",
"$",
"t",
"[",
"'conditions'",
"]",
"=",
"$",
"t",
"[",
"'conditions'",
"]",
"(",
"$",
"this",
"->",
"newExpr",
"(",
")",
",",
"$",
"this",
")",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"t",
"[",
"'conditions'",
"]",
"instanceof",
"ExpressionInterface",
")",
")",
"{",
"$",
"t",
"[",
"'conditions'",
"]",
"=",
"$",
"this",
"->",
"newExpr",
"(",
")",
"->",
"add",
"(",
"$",
"t",
"[",
"'conditions'",
"]",
",",
"$",
"types",
")",
";",
"}",
"$",
"alias",
"=",
"is_string",
"(",
"$",
"alias",
")",
"?",
"$",
"alias",
":",
"null",
";",
"$",
"joins",
"[",
"$",
"alias",
"?",
":",
"$",
"i",
"++",
"]",
"=",
"$",
"t",
"+",
"[",
"'type'",
"=>",
"QueryInterface",
"::",
"JOIN_TYPE_INNER",
",",
"'alias'",
"=>",
"$",
"alias",
"]",
";",
"}",
"if",
"(",
"$",
"overwrite",
")",
"{",
"$",
"this",
"->",
"_parts",
"[",
"'join'",
"]",
"=",
"$",
"joins",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_parts",
"[",
"'join'",
"]",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"_parts",
"[",
"'join'",
"]",
",",
"$",
"joins",
")",
";",
"}",
"$",
"this",
"->",
"_dirty",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Adds a single or multiple tables to be used as JOIN clauses to this query.
Tables can be passed as an array of strings, an array describing the
join parts, an array with multiple join descriptions, or a single string.
By default this function will append any passed argument to the list of tables
to be joined, unless the third argument is set to true.
When no join type is specified an `INNER JOIN` is used by default:
`$query->join(['authors'])` will produce `INNER JOIN authors ON 1 = 1`
It is also possible to alias joins using the array key:
`$query->join(['a' => 'authors'])` will produce `INNER JOIN authors a ON 1 = 1`
A join can be fully described and aliased using the array notation:
```
$query->join([
'a' => [
'table' => 'authors',
'type' => 'LEFT',
'conditions' => 'a.id = b.author_id'
]
]);
// Produces LEFT JOIN authors a ON a.id = b.author_id
```
You can even specify multiple joins in an array, including the full description:
```
$query->join([
'a' => [
'table' => 'authors',
'type' => 'LEFT',
'conditions' => 'a.id = b.author_id'
],
'p' => [
'table' => 'publishers',
'type' => 'INNER',
'conditions' => 'p.id = b.publisher_id AND p.name = "Cake Software Foundation"'
]
]);
// LEFT JOIN authors a ON a.id = b.author_id
// INNER JOIN publishers p ON p.id = b.publisher_id AND p.name = "Cake Software Foundation"
```
### Using conditions and types
Conditions can be expressed, as in the examples above, using a string for comparing
columns, or string with already quoted literal values. Additionally it is
possible to use conditions expressed in arrays or expression objects.
When using arrays for expressing conditions, it is often desirable to convert
the literal values to the correct database representation. This is achieved
using the second parameter of this function.
```
$query->join(['a' => [
'table' => 'articles',
'conditions' => [
'a.posted >=' => new DateTime('-3 days'),
'a.published' => true,
'a.author_id = authors.id'
]
]], ['a.posted' => 'datetime', 'a.published' => 'boolean'])
```
### Overwriting joins
When creating aliased joins using the array notation, you can override
previous join definitions by using the same alias in consequent
calls to this function or you can replace all previously defined joins
with another list if the third parameter for this function is set to true.
```
$query->join(['alias' => 'table']); // joins table with as alias
$query->join(['alias' => 'another_table']); // joins another_table with as alias
$query->join(['something' => 'different_table'], [], true); // resets joins list
```
@param array|string|null $tables list of tables to be joined in the query
@param array $types associative array of type names used to bind values to query
@param bool $overwrite whether to reset joins with passed list or not
@see \Cake\Database\Type
@return $this|array | [
"Adds",
"a",
"single",
"or",
"multiple",
"tables",
"to",
"be",
"used",
"as",
"JOIN",
"clauses",
"to",
"this",
"query",
".",
"Tables",
"can",
"be",
"passed",
"as",
"an",
"array",
"of",
"strings",
"an",
"array",
"describing",
"the",
"join",
"parts",
"an",
"array",
"with",
"multiple",
"join",
"descriptions",
"or",
"a",
"single",
"string",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L591-L630 |
211,015 | cakephp/cakephp | src/Database/Query.php | Query.leftJoin | public function leftJoin($table, $conditions = [], $types = [])
{
return $this->join($this->_makeJoin($table, $conditions, QueryInterface::JOIN_TYPE_LEFT), $types);
} | php | public function leftJoin($table, $conditions = [], $types = [])
{
return $this->join($this->_makeJoin($table, $conditions, QueryInterface::JOIN_TYPE_LEFT), $types);
} | [
"public",
"function",
"leftJoin",
"(",
"$",
"table",
",",
"$",
"conditions",
"=",
"[",
"]",
",",
"$",
"types",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"join",
"(",
"$",
"this",
"->",
"_makeJoin",
"(",
"$",
"table",
",",
"$",
"conditions",
",",
"QueryInterface",
"::",
"JOIN_TYPE_LEFT",
")",
",",
"$",
"types",
")",
";",
"}"
] | Adds a single `LEFT JOIN` clause to the query.
This is a shorthand method for building joins via `join()`.
The table name can be passed as a string, or as an array in case it needs to
be aliased:
```
// LEFT JOIN authors ON authors.id = posts.author_id
$query->leftJoin('authors', 'authors.id = posts.author_id');
// LEFT JOIN authors a ON a.id = posts.author_id
$query->leftJoin(['a' => 'authors'], 'a.id = posts.author_id');
```
Conditions can be passed as strings, arrays, or expression objects. When
using arrays it is possible to combine them with the `$types` parameter
in order to define how to convert the values:
```
$query->leftJoin(['a' => 'articles'], [
'a.posted >=' => new DateTime('-3 days'),
'a.published' => true,
'a.author_id = authors.id'
], ['a.posted' => 'datetime', 'a.published' => 'boolean']);
```
See `join()` for further details on conditions and types.
@param string|array $table The table to join with
@param string|array|\Cake\Database\ExpressionInterface $conditions The conditions
to use for joining.
@param array $types a list of types associated to the conditions used for converting
values to the corresponding database representation.
@return $this | [
"Adds",
"a",
"single",
"LEFT",
"JOIN",
"clause",
"to",
"the",
"query",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L686-L689 |
211,016 | cakephp/cakephp | src/Database/Query.php | Query.rightJoin | public function rightJoin($table, $conditions = [], $types = [])
{
return $this->join($this->_makeJoin($table, $conditions, QueryInterface::JOIN_TYPE_RIGHT), $types);
} | php | public function rightJoin($table, $conditions = [], $types = [])
{
return $this->join($this->_makeJoin($table, $conditions, QueryInterface::JOIN_TYPE_RIGHT), $types);
} | [
"public",
"function",
"rightJoin",
"(",
"$",
"table",
",",
"$",
"conditions",
"=",
"[",
"]",
",",
"$",
"types",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"join",
"(",
"$",
"this",
"->",
"_makeJoin",
"(",
"$",
"table",
",",
"$",
"conditions",
",",
"QueryInterface",
"::",
"JOIN_TYPE_RIGHT",
")",
",",
"$",
"types",
")",
";",
"}"
] | Adds a single `RIGHT JOIN` clause to the query.
This is a shorthand method for building joins via `join()`.
The arguments of this method are identical to the `leftJoin()` shorthand, please refer
to that methods description for further details.
@param string|array $table The table to join with
@param string|array|\Cake\Database\ExpressionInterface $conditions The conditions
to use for joining.
@param array $types a list of types associated to the conditions used for converting
values to the corresponding database representation.
@return $this | [
"Adds",
"a",
"single",
"RIGHT",
"JOIN",
"clause",
"to",
"the",
"query",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L706-L709 |
211,017 | cakephp/cakephp | src/Database/Query.php | Query.innerJoin | public function innerJoin($table, $conditions = [], $types = [])
{
return $this->join($this->_makeJoin($table, $conditions, QueryInterface::JOIN_TYPE_INNER), $types);
} | php | public function innerJoin($table, $conditions = [], $types = [])
{
return $this->join($this->_makeJoin($table, $conditions, QueryInterface::JOIN_TYPE_INNER), $types);
} | [
"public",
"function",
"innerJoin",
"(",
"$",
"table",
",",
"$",
"conditions",
"=",
"[",
"]",
",",
"$",
"types",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"join",
"(",
"$",
"this",
"->",
"_makeJoin",
"(",
"$",
"table",
",",
"$",
"conditions",
",",
"QueryInterface",
"::",
"JOIN_TYPE_INNER",
")",
",",
"$",
"types",
")",
";",
"}"
] | Adds a single `INNER JOIN` clause to the query.
This is a shorthand method for building joins via `join()`.
The arguments of this method are identical to the `leftJoin()` shorthand, please refer
to that methods description for further details.
@param string|array $table The table to join with
@param string|array|\Cake\Database\ExpressionInterface $conditions The conditions
to use for joining.
@param array $types a list of types associated to the conditions used for converting
values to the corresponding database representation.
@return $this | [
"Adds",
"a",
"single",
"INNER",
"JOIN",
"clause",
"to",
"the",
"query",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L726-L729 |
211,018 | cakephp/cakephp | src/Database/Query.php | Query._makeJoin | protected function _makeJoin($table, $conditions, $type)
{
$alias = $table;
if (is_array($table)) {
$alias = key($table);
$table = current($table);
}
return [
$alias => [
'table' => $table,
'conditions' => $conditions,
'type' => $type
]
];
} | php | protected function _makeJoin($table, $conditions, $type)
{
$alias = $table;
if (is_array($table)) {
$alias = key($table);
$table = current($table);
}
return [
$alias => [
'table' => $table,
'conditions' => $conditions,
'type' => $type
]
];
} | [
"protected",
"function",
"_makeJoin",
"(",
"$",
"table",
",",
"$",
"conditions",
",",
"$",
"type",
")",
"{",
"$",
"alias",
"=",
"$",
"table",
";",
"if",
"(",
"is_array",
"(",
"$",
"table",
")",
")",
"{",
"$",
"alias",
"=",
"key",
"(",
"$",
"table",
")",
";",
"$",
"table",
"=",
"current",
"(",
"$",
"table",
")",
";",
"}",
"return",
"[",
"$",
"alias",
"=>",
"[",
"'table'",
"=>",
"$",
"table",
",",
"'conditions'",
"=>",
"$",
"conditions",
",",
"'type'",
"=>",
"$",
"type",
"]",
"]",
";",
"}"
] | Returns an array that can be passed to the join method describing a single join clause
@param string|array $table The table to join with
@param string|array|\Cake\Database\ExpressionInterface $conditions The conditions
to use for joining.
@param string $type the join type to use
@return array | [
"Returns",
"an",
"array",
"that",
"can",
"be",
"passed",
"to",
"the",
"join",
"method",
"describing",
"a",
"single",
"join",
"clause"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L740-L756 |
211,019 | cakephp/cakephp | src/Database/Query.php | Query.whereNotNull | public function whereNotNull($fields)
{
if (!is_array($fields)) {
$fields = [$fields];
}
$exp = $this->newExpr();
foreach ($fields as $field) {
$exp->isNotNull($field);
}
return $this->where($exp);
} | php | public function whereNotNull($fields)
{
if (!is_array($fields)) {
$fields = [$fields];
}
$exp = $this->newExpr();
foreach ($fields as $field) {
$exp->isNotNull($field);
}
return $this->where($exp);
} | [
"public",
"function",
"whereNotNull",
"(",
"$",
"fields",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"fields",
"=",
"[",
"$",
"fields",
"]",
";",
"}",
"$",
"exp",
"=",
"$",
"this",
"->",
"newExpr",
"(",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"$",
"exp",
"->",
"isNotNull",
"(",
"$",
"field",
")",
";",
"}",
"return",
"$",
"this",
"->",
"where",
"(",
"$",
"exp",
")",
";",
"}"
] | Convenience method that adds a NOT NULL condition to the query
@param array|string|\Cake\Database\ExpressionInterface $fields A single field or expressions or a list of them that should be not null
@return $this | [
"Convenience",
"method",
"that",
"adds",
"a",
"NOT",
"NULL",
"condition",
"to",
"the",
"query"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L894-L907 |
211,020 | cakephp/cakephp | src/Database/Query.php | Query.whereNull | public function whereNull($fields)
{
if (!is_array($fields)) {
$fields = [$fields];
}
$exp = $this->newExpr();
foreach ($fields as $field) {
$exp->isNull($field);
}
return $this->where($exp);
} | php | public function whereNull($fields)
{
if (!is_array($fields)) {
$fields = [$fields];
}
$exp = $this->newExpr();
foreach ($fields as $field) {
$exp->isNull($field);
}
return $this->where($exp);
} | [
"public",
"function",
"whereNull",
"(",
"$",
"fields",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"fields",
"=",
"[",
"$",
"fields",
"]",
";",
"}",
"$",
"exp",
"=",
"$",
"this",
"->",
"newExpr",
"(",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"$",
"exp",
"->",
"isNull",
"(",
"$",
"field",
")",
";",
"}",
"return",
"$",
"this",
"->",
"where",
"(",
"$",
"exp",
")",
";",
"}"
] | Convenience method that adds a IS NULL condition to the query
@param array|string|\Cake\Database\ExpressionInterface $fields A single field or expressions or a list of them that should be null
@return $this | [
"Convenience",
"method",
"that",
"adds",
"a",
"IS",
"NULL",
"condition",
"to",
"the",
"query"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L915-L928 |
211,021 | cakephp/cakephp | src/Database/Query.php | Query.whereInList | public function whereInList($field, array $values, array $options = [])
{
$options += [
'types' => [],
'allowEmpty' => false,
];
if ($options['allowEmpty'] && !$values) {
return $this->where('1=0');
}
return $this->where([$field . ' IN' => $values], $options['types']);
} | php | public function whereInList($field, array $values, array $options = [])
{
$options += [
'types' => [],
'allowEmpty' => false,
];
if ($options['allowEmpty'] && !$values) {
return $this->where('1=0');
}
return $this->where([$field . ' IN' => $values], $options['types']);
} | [
"public",
"function",
"whereInList",
"(",
"$",
"field",
",",
"array",
"$",
"values",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"+=",
"[",
"'types'",
"=>",
"[",
"]",
",",
"'allowEmpty'",
"=>",
"false",
",",
"]",
";",
"if",
"(",
"$",
"options",
"[",
"'allowEmpty'",
"]",
"&&",
"!",
"$",
"values",
")",
"{",
"return",
"$",
"this",
"->",
"where",
"(",
"'1=0'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"where",
"(",
"[",
"$",
"field",
".",
"' IN'",
"=>",
"$",
"values",
"]",
",",
"$",
"options",
"[",
"'types'",
"]",
")",
";",
"}"
] | Adds an IN condition or set of conditions to be used in the WHERE clause for this
query.
This method does allow empty inputs in contrast to where() if you set
'allowEmpty' to true.
Be careful about using it without proper sanity checks.
Options:
- `types` - Associative array of type names used to bind values to query
- `allowEmpty` - Allow empty array.
@param string $field Field
@param array $values Array of values
@param array $options Options
@return $this | [
"Adds",
"an",
"IN",
"condition",
"or",
"set",
"of",
"conditions",
"to",
"be",
"used",
"in",
"the",
"WHERE",
"clause",
"for",
"this",
"query",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L947-L959 |
211,022 | cakephp/cakephp | src/Database/Query.php | Query.whereNotInList | public function whereNotInList($field, array $values, array $options = [])
{
$options += [
'types' => [],
'allowEmpty' => false,
];
if ($options['allowEmpty'] && !$values) {
return $this->where([$field . ' IS NOT' => null]);
}
return $this->where([$field . ' NOT IN' => $values], $options['types']);
} | php | public function whereNotInList($field, array $values, array $options = [])
{
$options += [
'types' => [],
'allowEmpty' => false,
];
if ($options['allowEmpty'] && !$values) {
return $this->where([$field . ' IS NOT' => null]);
}
return $this->where([$field . ' NOT IN' => $values], $options['types']);
} | [
"public",
"function",
"whereNotInList",
"(",
"$",
"field",
",",
"array",
"$",
"values",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"+=",
"[",
"'types'",
"=>",
"[",
"]",
",",
"'allowEmpty'",
"=>",
"false",
",",
"]",
";",
"if",
"(",
"$",
"options",
"[",
"'allowEmpty'",
"]",
"&&",
"!",
"$",
"values",
")",
"{",
"return",
"$",
"this",
"->",
"where",
"(",
"[",
"$",
"field",
".",
"' IS NOT'",
"=>",
"null",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"where",
"(",
"[",
"$",
"field",
".",
"' NOT IN'",
"=>",
"$",
"values",
"]",
",",
"$",
"options",
"[",
"'types'",
"]",
")",
";",
"}"
] | Adds a NOT IN condition or set of conditions to be used in the WHERE clause for this
query.
This method does allow empty inputs in contrast to where() if you set
'allowEmpty' to true.
Be careful about using it without proper sanity checks.
@param string $field Field
@param array $values Array of values
@param array $options Options
@return $this | [
"Adds",
"a",
"NOT",
"IN",
"condition",
"or",
"set",
"of",
"conditions",
"to",
"be",
"used",
"in",
"the",
"WHERE",
"clause",
"for",
"this",
"query",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L974-L986 |
211,023 | cakephp/cakephp | src/Database/Query.php | Query.orderDesc | public function orderDesc($field, $overwrite = false)
{
if ($overwrite) {
$this->_parts['order'] = null;
}
if (!$field) {
return $this;
}
if (!$this->_parts['order']) {
$this->_parts['order'] = new OrderByExpression();
}
$this->_parts['order']->add(new OrderClauseExpression($field, 'DESC'));
return $this;
} | php | public function orderDesc($field, $overwrite = false)
{
if ($overwrite) {
$this->_parts['order'] = null;
}
if (!$field) {
return $this;
}
if (!$this->_parts['order']) {
$this->_parts['order'] = new OrderByExpression();
}
$this->_parts['order']->add(new OrderClauseExpression($field, 'DESC'));
return $this;
} | [
"public",
"function",
"orderDesc",
"(",
"$",
"field",
",",
"$",
"overwrite",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"overwrite",
")",
"{",
"$",
"this",
"->",
"_parts",
"[",
"'order'",
"]",
"=",
"null",
";",
"}",
"if",
"(",
"!",
"$",
"field",
")",
"{",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"_parts",
"[",
"'order'",
"]",
")",
"{",
"$",
"this",
"->",
"_parts",
"[",
"'order'",
"]",
"=",
"new",
"OrderByExpression",
"(",
")",
";",
"}",
"$",
"this",
"->",
"_parts",
"[",
"'order'",
"]",
"->",
"add",
"(",
"new",
"OrderClauseExpression",
"(",
"$",
"field",
",",
"'DESC'",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add an ORDER BY clause with a DESC direction.
This method allows you to set complex expressions
as order conditions unlike order()
Order fields are not suitable for use with user supplied data as they are
not sanitized by the query builder.
@param string|\Cake\Database\Expression\QueryExpression $field The field to order on.
@param bool $overwrite Whether or not to reset the order clauses.
@return $this | [
"Add",
"an",
"ORDER",
"BY",
"clause",
"with",
"a",
"DESC",
"direction",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L1240-L1255 |
211,024 | cakephp/cakephp | src/Database/Query.php | Query.group | public function group($fields, $overwrite = false)
{
if ($overwrite) {
$this->_parts['group'] = [];
}
if (!is_array($fields)) {
$fields = [$fields];
}
$this->_parts['group'] = array_merge($this->_parts['group'], array_values($fields));
$this->_dirty();
return $this;
} | php | public function group($fields, $overwrite = false)
{
if ($overwrite) {
$this->_parts['group'] = [];
}
if (!is_array($fields)) {
$fields = [$fields];
}
$this->_parts['group'] = array_merge($this->_parts['group'], array_values($fields));
$this->_dirty();
return $this;
} | [
"public",
"function",
"group",
"(",
"$",
"fields",
",",
"$",
"overwrite",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"overwrite",
")",
"{",
"$",
"this",
"->",
"_parts",
"[",
"'group'",
"]",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"fields",
"=",
"[",
"$",
"fields",
"]",
";",
"}",
"$",
"this",
"->",
"_parts",
"[",
"'group'",
"]",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"_parts",
"[",
"'group'",
"]",
",",
"array_values",
"(",
"$",
"fields",
")",
")",
";",
"$",
"this",
"->",
"_dirty",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Adds a single or multiple fields to be used in the GROUP BY clause for this query.
Fields can be passed as an array of strings, array of expression
objects, a single expression or a single string.
By default this function will append any passed argument to the list of fields
to be grouped, unless the second argument is set to true.
### Examples:
```
// Produces GROUP BY id, title
$query->group(['id', 'title']);
// Produces GROUP BY title
$query->group('title');
```
Group fields are not suitable for use with user supplied data as they are
not sanitized by the query builder.
@param array|\Cake\Database\ExpressionInterface|string $fields fields to be added to the list
@param bool $overwrite whether to reset fields with passed list or not
@return $this | [
"Adds",
"a",
"single",
"or",
"multiple",
"fields",
"to",
"be",
"used",
"in",
"the",
"GROUP",
"BY",
"clause",
"for",
"this",
"query",
".",
"Fields",
"can",
"be",
"passed",
"as",
"an",
"array",
"of",
"strings",
"array",
"of",
"expression",
"objects",
"a",
"single",
"expression",
"or",
"a",
"single",
"string",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L1282-L1296 |
211,025 | cakephp/cakephp | src/Database/Query.php | Query.limit | public function limit($num)
{
$this->_dirty();
if ($num !== null && !is_object($num)) {
$num = (int)$num;
}
$this->_parts['limit'] = $num;
return $this;
} | php | public function limit($num)
{
$this->_dirty();
if ($num !== null && !is_object($num)) {
$num = (int)$num;
}
$this->_parts['limit'] = $num;
return $this;
} | [
"public",
"function",
"limit",
"(",
"$",
"num",
")",
"{",
"$",
"this",
"->",
"_dirty",
"(",
")",
";",
"if",
"(",
"$",
"num",
"!==",
"null",
"&&",
"!",
"is_object",
"(",
"$",
"num",
")",
")",
"{",
"$",
"num",
"=",
"(",
"int",
")",
"$",
"num",
";",
"}",
"$",
"this",
"->",
"_parts",
"[",
"'limit'",
"]",
"=",
"$",
"num",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the number of records that should be retrieved from database,
accepts an integer or an expression object that evaluates to an integer.
In some databases, this operation might not be supported or will require
the query to be transformed in order to limit the result set size.
### Examples
```
$query->limit(10) // generates LIMIT 10
$query->limit($query->newExpr()->add(['1 + 1'])); // LIMIT (1 + 1)
```
@param int|\Cake\Database\ExpressionInterface $num number of records to be returned
@return $this | [
"Sets",
"the",
"number",
"of",
"records",
"that",
"should",
"be",
"retrieved",
"from",
"database",
"accepts",
"an",
"integer",
"or",
"an",
"expression",
"object",
"that",
"evaluates",
"to",
"an",
"integer",
".",
"In",
"some",
"databases",
"this",
"operation",
"might",
"not",
"be",
"supported",
"or",
"will",
"require",
"the",
"query",
"to",
"be",
"transformed",
"in",
"order",
"to",
"limit",
"the",
"result",
"set",
"size",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L1421-L1430 |
211,026 | cakephp/cakephp | src/Database/Query.php | Query.offset | public function offset($num)
{
$this->_dirty();
if ($num !== null && !is_object($num)) {
$num = (int)$num;
}
$this->_parts['offset'] = $num;
return $this;
} | php | public function offset($num)
{
$this->_dirty();
if ($num !== null && !is_object($num)) {
$num = (int)$num;
}
$this->_parts['offset'] = $num;
return $this;
} | [
"public",
"function",
"offset",
"(",
"$",
"num",
")",
"{",
"$",
"this",
"->",
"_dirty",
"(",
")",
";",
"if",
"(",
"$",
"num",
"!==",
"null",
"&&",
"!",
"is_object",
"(",
"$",
"num",
")",
")",
"{",
"$",
"num",
"=",
"(",
"int",
")",
"$",
"num",
";",
"}",
"$",
"this",
"->",
"_parts",
"[",
"'offset'",
"]",
"=",
"$",
"num",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the number of records that should be skipped from the original result set
This is commonly used for paginating large results. Accepts an integer or an
expression object that evaluates to an integer.
In some databases, this operation might not be supported or will require
the query to be transformed in order to limit the result set size.
### Examples
```
$query->offset(10) // generates OFFSET 10
$query->offset($query->newExpr()->add(['1 + 1'])); // OFFSET (1 + 1)
```
@param int|\Cake\Database\ExpressionInterface $num number of records to be skipped
@return $this | [
"Sets",
"the",
"number",
"of",
"records",
"that",
"should",
"be",
"skipped",
"from",
"the",
"original",
"result",
"set",
"This",
"is",
"commonly",
"used",
"for",
"paginating",
"large",
"results",
".",
"Accepts",
"an",
"integer",
"or",
"an",
"expression",
"object",
"that",
"evaluates",
"to",
"an",
"integer",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L1450-L1459 |
211,027 | cakephp/cakephp | src/Database/Query.php | Query.union | public function union($query, $overwrite = false)
{
if ($overwrite) {
$this->_parts['union'] = [];
}
$this->_parts['union'][] = [
'all' => false,
'query' => $query
];
$this->_dirty();
return $this;
} | php | public function union($query, $overwrite = false)
{
if ($overwrite) {
$this->_parts['union'] = [];
}
$this->_parts['union'][] = [
'all' => false,
'query' => $query
];
$this->_dirty();
return $this;
} | [
"public",
"function",
"union",
"(",
"$",
"query",
",",
"$",
"overwrite",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"overwrite",
")",
"{",
"$",
"this",
"->",
"_parts",
"[",
"'union'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"_parts",
"[",
"'union'",
"]",
"[",
"]",
"=",
"[",
"'all'",
"=>",
"false",
",",
"'query'",
"=>",
"$",
"query",
"]",
";",
"$",
"this",
"->",
"_dirty",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Adds a complete query to be used in conjunction with an UNION operator with
this query. This is used to combine the result set of this query with the one
that will be returned by the passed query. You can add as many queries as you
required by calling multiple times this method with different queries.
By default, the UNION operator will remove duplicate rows, if you wish to include
every row for all queries, use unionAll().
### Examples
```
$union = (new Query($conn))->select(['id', 'title'])->from(['a' => 'articles']);
$query->select(['id', 'name'])->from(['d' => 'things'])->union($union);
```
Will produce:
`SELECT id, name FROM things d UNION SELECT id, title FROM articles a`
@param string|\Cake\Database\Query $query full SQL query to be used in UNION operator
@param bool $overwrite whether to reset the list of queries to be operated or not
@return $this | [
"Adds",
"a",
"complete",
"query",
"to",
"be",
"used",
"in",
"conjunction",
"with",
"an",
"UNION",
"operator",
"with",
"this",
"query",
".",
"This",
"is",
"used",
"to",
"combine",
"the",
"result",
"set",
"of",
"this",
"query",
"with",
"the",
"one",
"that",
"will",
"be",
"returned",
"by",
"the",
"passed",
"query",
".",
"You",
"can",
"add",
"as",
"many",
"queries",
"as",
"you",
"required",
"by",
"calling",
"multiple",
"times",
"this",
"method",
"with",
"different",
"queries",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L1485-L1497 |
211,028 | cakephp/cakephp | src/Database/Query.php | Query.unionAll | public function unionAll($query, $overwrite = false)
{
if ($overwrite) {
$this->_parts['union'] = [];
}
$this->_parts['union'][] = [
'all' => true,
'query' => $query
];
$this->_dirty();
return $this;
} | php | public function unionAll($query, $overwrite = false)
{
if ($overwrite) {
$this->_parts['union'] = [];
}
$this->_parts['union'][] = [
'all' => true,
'query' => $query
];
$this->_dirty();
return $this;
} | [
"public",
"function",
"unionAll",
"(",
"$",
"query",
",",
"$",
"overwrite",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"overwrite",
")",
"{",
"$",
"this",
"->",
"_parts",
"[",
"'union'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"_parts",
"[",
"'union'",
"]",
"[",
"]",
"=",
"[",
"'all'",
"=>",
"true",
",",
"'query'",
"=>",
"$",
"query",
"]",
";",
"$",
"this",
"->",
"_dirty",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Adds a complete query to be used in conjunction with the UNION ALL operator with
this query. This is used to combine the result set of this query with the one
that will be returned by the passed query. You can add as many queries as you
required by calling multiple times this method with different queries.
Unlike UNION, UNION ALL will not remove duplicate rows.
```
$union = (new Query($conn))->select(['id', 'title'])->from(['a' => 'articles']);
$query->select(['id', 'name'])->from(['d' => 'things'])->unionAll($union);
```
Will produce:
`SELECT id, name FROM things d UNION ALL SELECT id, title FROM articles a`
@param string|\Cake\Database\Query $query full SQL query to be used in UNION operator
@param bool $overwrite whether to reset the list of queries to be operated or not
@return $this | [
"Adds",
"a",
"complete",
"query",
"to",
"be",
"used",
"in",
"conjunction",
"with",
"the",
"UNION",
"ALL",
"operator",
"with",
"this",
"query",
".",
"This",
"is",
"used",
"to",
"combine",
"the",
"result",
"set",
"of",
"this",
"query",
"with",
"the",
"one",
"that",
"will",
"be",
"returned",
"by",
"the",
"passed",
"query",
".",
"You",
"can",
"add",
"as",
"many",
"queries",
"as",
"you",
"required",
"by",
"calling",
"multiple",
"times",
"this",
"method",
"with",
"different",
"queries",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L1520-L1532 |
211,029 | cakephp/cakephp | src/Database/Query.php | Query.into | public function into($table)
{
$this->_dirty();
$this->_type = 'insert';
$this->_parts['insert'][0] = $table;
return $this;
} | php | public function into($table)
{
$this->_dirty();
$this->_type = 'insert';
$this->_parts['insert'][0] = $table;
return $this;
} | [
"public",
"function",
"into",
"(",
"$",
"table",
")",
"{",
"$",
"this",
"->",
"_dirty",
"(",
")",
";",
"$",
"this",
"->",
"_type",
"=",
"'insert'",
";",
"$",
"this",
"->",
"_parts",
"[",
"'insert'",
"]",
"[",
"0",
"]",
"=",
"$",
"table",
";",
"return",
"$",
"this",
";",
"}"
] | Set the table name for insert queries.
@param string $table The table name to insert into.
@return $this | [
"Set",
"the",
"table",
"name",
"for",
"insert",
"queries",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L1568-L1575 |
211,030 | cakephp/cakephp | src/Database/Query.php | Query.values | public function values($data)
{
if ($this->_type !== 'insert') {
throw new Exception(
'You cannot add values before defining columns to use.'
);
}
if (empty($this->_parts['insert'])) {
throw new Exception(
'You cannot add values before defining columns to use.'
);
}
$this->_dirty();
if ($data instanceof ValuesExpression) {
$this->_parts['values'] = $data;
return $this;
}
$this->_parts['values']->add($data);
return $this;
} | php | public function values($data)
{
if ($this->_type !== 'insert') {
throw new Exception(
'You cannot add values before defining columns to use.'
);
}
if (empty($this->_parts['insert'])) {
throw new Exception(
'You cannot add values before defining columns to use.'
);
}
$this->_dirty();
if ($data instanceof ValuesExpression) {
$this->_parts['values'] = $data;
return $this;
}
$this->_parts['values']->add($data);
return $this;
} | [
"public",
"function",
"values",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_type",
"!==",
"'insert'",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'You cannot add values before defining columns to use.'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_parts",
"[",
"'insert'",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'You cannot add values before defining columns to use.'",
")",
";",
"}",
"$",
"this",
"->",
"_dirty",
"(",
")",
";",
"if",
"(",
"$",
"data",
"instanceof",
"ValuesExpression",
")",
"{",
"$",
"this",
"->",
"_parts",
"[",
"'values'",
"]",
"=",
"$",
"data",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"_parts",
"[",
"'values'",
"]",
"->",
"add",
"(",
"$",
"data",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the values for an insert query.
Multi inserts can be performed by calling values() more than one time,
or by providing an array of value sets. Additionally $data can be a Query
instance to insert data from another SELECT statement.
@param array|\Cake\Database\Query $data The data to insert.
@return $this
@throws \Cake\Database\Exception if you try to set values before declaring columns.
Or if you try to set values on non-insert queries. | [
"Set",
"the",
"values",
"for",
"an",
"insert",
"query",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L1610-L1633 |
211,031 | cakephp/cakephp | src/Database/Query.php | Query.set | public function set($key, $value = null, $types = [])
{
if (empty($this->_parts['set'])) {
$this->_parts['set'] = $this->newExpr()->setConjunction(',');
}
if ($this->_parts['set']->isCallable($key)) {
$exp = $this->newExpr()->setConjunction(',');
$this->_parts['set']->add($key($exp));
return $this;
}
if (is_array($key) || $key instanceof ExpressionInterface) {
$types = (array)$value;
$this->_parts['set']->add($key, $types);
return $this;
}
if (is_string($types) && is_string($key)) {
$types = [$key => $types];
}
$this->_parts['set']->eq($key, $value, $types);
return $this;
} | php | public function set($key, $value = null, $types = [])
{
if (empty($this->_parts['set'])) {
$this->_parts['set'] = $this->newExpr()->setConjunction(',');
}
if ($this->_parts['set']->isCallable($key)) {
$exp = $this->newExpr()->setConjunction(',');
$this->_parts['set']->add($key($exp));
return $this;
}
if (is_array($key) || $key instanceof ExpressionInterface) {
$types = (array)$value;
$this->_parts['set']->add($key, $types);
return $this;
}
if (is_string($types) && is_string($key)) {
$types = [$key => $types];
}
$this->_parts['set']->eq($key, $value, $types);
return $this;
} | [
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
"=",
"null",
",",
"$",
"types",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_parts",
"[",
"'set'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_parts",
"[",
"'set'",
"]",
"=",
"$",
"this",
"->",
"newExpr",
"(",
")",
"->",
"setConjunction",
"(",
"','",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_parts",
"[",
"'set'",
"]",
"->",
"isCallable",
"(",
"$",
"key",
")",
")",
"{",
"$",
"exp",
"=",
"$",
"this",
"->",
"newExpr",
"(",
")",
"->",
"setConjunction",
"(",
"','",
")",
";",
"$",
"this",
"->",
"_parts",
"[",
"'set'",
"]",
"->",
"add",
"(",
"$",
"key",
"(",
"$",
"exp",
")",
")",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
"||",
"$",
"key",
"instanceof",
"ExpressionInterface",
")",
"{",
"$",
"types",
"=",
"(",
"array",
")",
"$",
"value",
";",
"$",
"this",
"->",
"_parts",
"[",
"'set'",
"]",
"->",
"add",
"(",
"$",
"key",
",",
"$",
"types",
")",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"types",
")",
"&&",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"$",
"types",
"=",
"[",
"$",
"key",
"=>",
"$",
"types",
"]",
";",
"}",
"$",
"this",
"->",
"_parts",
"[",
"'set'",
"]",
"->",
"eq",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"types",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set one or many fields to update.
### Examples
Passing a string:
```
$query->update('articles')->set('title', 'The Title');
```
Passing an array:
```
$query->update('articles')->set(['title' => 'The Title'], ['title' => 'string']);
```
Passing a callable:
```
$query->update('articles')->set(function ($exp) {
return $exp->eq('title', 'The title', 'string');
});
```
@param string|array|callable|\Cake\Database\Expression\QueryExpression $key The column name or array of keys
+ values to set. This can also be a QueryExpression containing a SQL fragment.
It can also be a callable, that is required to return an expression object.
@param mixed $value The value to update $key to. Can be null if $key is an
array or QueryExpression. When $key is an array, this parameter will be
used as $types instead.
@param array $types The column types to treat data as.
@return $this | [
"Set",
"one",
"or",
"many",
"fields",
"to",
"update",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L1692-L1718 |
211,032 | cakephp/cakephp | src/Database/Query.php | Query.newExpr | public function newExpr($rawExpression = null)
{
$expression = new QueryExpression([], $this->getTypeMap());
if ($rawExpression !== null) {
$expression->add($rawExpression);
}
return $expression;
} | php | public function newExpr($rawExpression = null)
{
$expression = new QueryExpression([], $this->getTypeMap());
if ($rawExpression !== null) {
$expression->add($rawExpression);
}
return $expression;
} | [
"public",
"function",
"newExpr",
"(",
"$",
"rawExpression",
"=",
"null",
")",
"{",
"$",
"expression",
"=",
"new",
"QueryExpression",
"(",
"[",
"]",
",",
"$",
"this",
"->",
"getTypeMap",
"(",
")",
")",
";",
"if",
"(",
"$",
"rawExpression",
"!==",
"null",
")",
"{",
"$",
"expression",
"->",
"add",
"(",
"$",
"rawExpression",
")",
";",
"}",
"return",
"$",
"expression",
";",
"}"
] | Returns a new QueryExpression object. This is a handy function when
building complex queries using a fluent interface. You can also override
this function in subclasses to use a more specialized QueryExpression class
if required.
You can optionally pass a single raw SQL string or an array or expressions in
any format accepted by \Cake\Database\Expression\QueryExpression:
```
$expression = $query->newExpr(); // Returns an empty expression object
$expression = $query->newExpr('Table.column = Table2.column'); // Return a raw SQL expression
```
@param mixed $rawExpression A string, array or anything you want wrapped in an expression object
@return \Cake\Database\Expression\QueryExpression | [
"Returns",
"a",
"new",
"QueryExpression",
"object",
".",
"This",
"is",
"a",
"handy",
"function",
"when",
"building",
"complex",
"queries",
"using",
"a",
"fluent",
"interface",
".",
"You",
"can",
"also",
"override",
"this",
"function",
"in",
"subclasses",
"to",
"use",
"a",
"more",
"specialized",
"QueryExpression",
"class",
"if",
"required",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L1792-L1801 |
211,033 | cakephp/cakephp | src/Database/Query.php | Query.decorateResults | public function decorateResults($callback, $overwrite = false)
{
if ($overwrite) {
$this->_resultDecorators = [];
}
if ($callback !== null) {
$this->_resultDecorators[] = $callback;
}
return $this;
} | php | public function decorateResults($callback, $overwrite = false)
{
if ($overwrite) {
$this->_resultDecorators = [];
}
if ($callback !== null) {
$this->_resultDecorators[] = $callback;
}
return $this;
} | [
"public",
"function",
"decorateResults",
"(",
"$",
"callback",
",",
"$",
"overwrite",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"overwrite",
")",
"{",
"$",
"this",
"->",
"_resultDecorators",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"$",
"callback",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"_resultDecorators",
"[",
"]",
"=",
"$",
"callback",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Registers a callback to be executed for each result that is fetched from the
result set, the callback function will receive as first parameter an array with
the raw data from the database for every row that is fetched and must return the
row with any possible modifications.
Callbacks will be executed lazily, if only 3 rows are fetched for database it will
called 3 times, event though there might be more rows to be fetched in the cursor.
Callbacks are stacked in the order they are registered, if you wish to reset the stack
the call this function with the second parameter set to true.
If you wish to remove all decorators from the stack, set the first parameter
to null and the second to true.
### Example
```
$query->decorateResults(function ($row) {
$row['order_total'] = $row['subtotal'] + ($row['subtotal'] * $row['tax']);
return $row;
});
```
@param callable|null $callback The callback to invoke when results are fetched.
@param bool $overwrite Whether or not this should append or replace all existing decorators.
@return $this | [
"Registers",
"a",
"callback",
"to",
"be",
"executed",
"for",
"each",
"result",
"that",
"is",
"fetched",
"from",
"the",
"result",
"set",
"the",
"callback",
"function",
"will",
"receive",
"as",
"first",
"parameter",
"an",
"array",
"with",
"the",
"raw",
"data",
"from",
"the",
"database",
"for",
"every",
"row",
"that",
"is",
"fetched",
"and",
"must",
"return",
"the",
"row",
"with",
"any",
"possible",
"modifications",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L1912-L1923 |
211,034 | cakephp/cakephp | src/Database/Query.php | Query.bind | public function bind($param, $value, $type = 'string')
{
$this->getValueBinder()->bind($param, $value, $type);
return $this;
} | php | public function bind($param, $value, $type = 'string')
{
$this->getValueBinder()->bind($param, $value, $type);
return $this;
} | [
"public",
"function",
"bind",
"(",
"$",
"param",
",",
"$",
"value",
",",
"$",
"type",
"=",
"'string'",
")",
"{",
"$",
"this",
"->",
"getValueBinder",
"(",
")",
"->",
"bind",
"(",
"$",
"param",
",",
"$",
"value",
",",
"$",
"type",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Associates a query placeholder to a value and a type.
If type is expressed as "atype[]" (note braces) then it will cause the
placeholder to be re-written dynamically so if the value is an array, it
will create as many placeholders as values are in it. For example:
```
$query->bind(':id', [1, 2, 3], 'int[]');
```
Will create 3 int placeholders. When using named placeholders, this method
requires that the placeholders include `:` e.g. `:value`.
@param string|int $param placeholder to be replaced with quoted version
of $value
@param mixed $value The value to be bound
@param string|int $type the mapped type name, used for casting when sending
to database
@return $this | [
"Associates",
"a",
"query",
"placeholder",
"to",
"a",
"value",
"and",
"a",
"type",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L1981-L1986 |
211,035 | cakephp/cakephp | src/Database/Query.php | Query.valueBinder | public function valueBinder($binder = null)
{
deprecationWarning('Query::valueBinder() is deprecated. Use Query::getValueBinder()/setValueBinder() instead.');
if ($binder === null) {
if ($this->_valueBinder === null) {
$this->_valueBinder = new ValueBinder();
}
return $this->_valueBinder;
}
$this->_valueBinder = $binder;
return $this;
} | php | public function valueBinder($binder = null)
{
deprecationWarning('Query::valueBinder() is deprecated. Use Query::getValueBinder()/setValueBinder() instead.');
if ($binder === null) {
if ($this->_valueBinder === null) {
$this->_valueBinder = new ValueBinder();
}
return $this->_valueBinder;
}
$this->_valueBinder = $binder;
return $this;
} | [
"public",
"function",
"valueBinder",
"(",
"$",
"binder",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"'Query::valueBinder() is deprecated. Use Query::getValueBinder()/setValueBinder() instead.'",
")",
";",
"if",
"(",
"$",
"binder",
"===",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_valueBinder",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_valueBinder",
"=",
"new",
"ValueBinder",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_valueBinder",
";",
"}",
"$",
"this",
"->",
"_valueBinder",
"=",
"$",
"binder",
";",
"return",
"$",
"this",
";",
"}"
] | Returns the currently used ValueBinder instance. If a value is passed,
it will be set as the new instance to be used.
A ValueBinder is responsible for generating query placeholders and temporarily
associate values to those placeholders so that they can be passed correctly
to the statement object.
@deprecated 3.5.0 Use setValueBinder()/getValueBinder() instead.
@param \Cake\Database\ValueBinder|false|null $binder new instance to be set. If no value is passed the
default one will be returned
@return $this|\Cake\Database\ValueBinder | [
"Returns",
"the",
"currently",
"used",
"ValueBinder",
"instance",
".",
"If",
"a",
"value",
"is",
"passed",
"it",
"will",
"be",
"set",
"as",
"the",
"new",
"instance",
"to",
"be",
"used",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L2036-L2049 |
211,036 | cakephp/cakephp | src/Database/Query.php | Query.selectTypeMap | public function selectTypeMap(TypeMap $typeMap = null)
{
deprecationWarning(
'Query::selectTypeMap() is deprecated. ' .
'Use Query::setSelectTypeMap()/getSelectTypeMap() instead.'
);
if ($typeMap !== null) {
return $this->setSelectTypeMap($typeMap);
}
return $this->getSelectTypeMap();
} | php | public function selectTypeMap(TypeMap $typeMap = null)
{
deprecationWarning(
'Query::selectTypeMap() is deprecated. ' .
'Use Query::setSelectTypeMap()/getSelectTypeMap() instead.'
);
if ($typeMap !== null) {
return $this->setSelectTypeMap($typeMap);
}
return $this->getSelectTypeMap();
} | [
"public",
"function",
"selectTypeMap",
"(",
"TypeMap",
"$",
"typeMap",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"'Query::selectTypeMap() is deprecated. '",
".",
"'Use Query::setSelectTypeMap()/getSelectTypeMap() instead.'",
")",
";",
"if",
"(",
"$",
"typeMap",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"setSelectTypeMap",
"(",
"$",
"typeMap",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getSelectTypeMap",
"(",
")",
";",
"}"
] | Sets the TypeMap class where the types for each of the fields in the
select clause are stored.
When called with no arguments, the current TypeMap object is returned.
@deprecated 3.4.0 Use setSelectTypeMap()/getSelectTypeMap() instead.
@param \Cake\Database\TypeMap|null $typeMap The map object to use
@return $this|\Cake\Database\TypeMap | [
"Sets",
"the",
"TypeMap",
"class",
"where",
"the",
"types",
"for",
"each",
"of",
"the",
"fields",
"in",
"the",
"select",
"clause",
"are",
"stored",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L2199-L2210 |
211,037 | cakephp/cakephp | src/Database/Query.php | Query._decorateStatement | protected function _decorateStatement($statement)
{
$typeMap = $this->getSelectTypeMap();
$driver = $this->getConnection()->getDriver();
if ($this->typeCastEnabled && $typeMap->toArray()) {
$statement = new CallbackStatement($statement, $driver, new FieldTypeConverter($typeMap, $driver));
}
foreach ($this->_resultDecorators as $f) {
$statement = new CallbackStatement($statement, $driver, $f);
}
return $statement;
} | php | protected function _decorateStatement($statement)
{
$typeMap = $this->getSelectTypeMap();
$driver = $this->getConnection()->getDriver();
if ($this->typeCastEnabled && $typeMap->toArray()) {
$statement = new CallbackStatement($statement, $driver, new FieldTypeConverter($typeMap, $driver));
}
foreach ($this->_resultDecorators as $f) {
$statement = new CallbackStatement($statement, $driver, $f);
}
return $statement;
} | [
"protected",
"function",
"_decorateStatement",
"(",
"$",
"statement",
")",
"{",
"$",
"typeMap",
"=",
"$",
"this",
"->",
"getSelectTypeMap",
"(",
")",
";",
"$",
"driver",
"=",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"getDriver",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"typeCastEnabled",
"&&",
"$",
"typeMap",
"->",
"toArray",
"(",
")",
")",
"{",
"$",
"statement",
"=",
"new",
"CallbackStatement",
"(",
"$",
"statement",
",",
"$",
"driver",
",",
"new",
"FieldTypeConverter",
"(",
"$",
"typeMap",
",",
"$",
"driver",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"_resultDecorators",
"as",
"$",
"f",
")",
"{",
"$",
"statement",
"=",
"new",
"CallbackStatement",
"(",
"$",
"statement",
",",
"$",
"driver",
",",
"$",
"f",
")",
";",
"}",
"return",
"$",
"statement",
";",
"}"
] | Auxiliary function used to wrap the original statement from the driver with
any registered callbacks.
@param \Cake\Database\StatementInterface $statement to be decorated
@return \Cake\Database\Statement\CallbackStatement | [
"Auxiliary",
"function",
"used",
"to",
"wrap",
"the",
"original",
"statement",
"from",
"the",
"driver",
"with",
"any",
"registered",
"callbacks",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L2219-L2233 |
211,038 | cakephp/cakephp | src/Database/Query.php | Query._conjugate | protected function _conjugate($part, $append, $conjunction, $types)
{
$expression = $this->_parts[$part] ?: $this->newExpr();
if (empty($append)) {
$this->_parts[$part] = $expression;
return;
}
if ($expression->isCallable($append)) {
$append = $append($this->newExpr(), $this);
}
if ($expression->getConjunction() === $conjunction) {
$expression->add($append, $types);
} else {
$expression = $this->newExpr()
->setConjunction($conjunction)
->add([$expression, $append], $types);
}
$this->_parts[$part] = $expression;
$this->_dirty();
} | php | protected function _conjugate($part, $append, $conjunction, $types)
{
$expression = $this->_parts[$part] ?: $this->newExpr();
if (empty($append)) {
$this->_parts[$part] = $expression;
return;
}
if ($expression->isCallable($append)) {
$append = $append($this->newExpr(), $this);
}
if ($expression->getConjunction() === $conjunction) {
$expression->add($append, $types);
} else {
$expression = $this->newExpr()
->setConjunction($conjunction)
->add([$expression, $append], $types);
}
$this->_parts[$part] = $expression;
$this->_dirty();
} | [
"protected",
"function",
"_conjugate",
"(",
"$",
"part",
",",
"$",
"append",
",",
"$",
"conjunction",
",",
"$",
"types",
")",
"{",
"$",
"expression",
"=",
"$",
"this",
"->",
"_parts",
"[",
"$",
"part",
"]",
"?",
":",
"$",
"this",
"->",
"newExpr",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"append",
")",
")",
"{",
"$",
"this",
"->",
"_parts",
"[",
"$",
"part",
"]",
"=",
"$",
"expression",
";",
"return",
";",
"}",
"if",
"(",
"$",
"expression",
"->",
"isCallable",
"(",
"$",
"append",
")",
")",
"{",
"$",
"append",
"=",
"$",
"append",
"(",
"$",
"this",
"->",
"newExpr",
"(",
")",
",",
"$",
"this",
")",
";",
"}",
"if",
"(",
"$",
"expression",
"->",
"getConjunction",
"(",
")",
"===",
"$",
"conjunction",
")",
"{",
"$",
"expression",
"->",
"add",
"(",
"$",
"append",
",",
"$",
"types",
")",
";",
"}",
"else",
"{",
"$",
"expression",
"=",
"$",
"this",
"->",
"newExpr",
"(",
")",
"->",
"setConjunction",
"(",
"$",
"conjunction",
")",
"->",
"add",
"(",
"[",
"$",
"expression",
",",
"$",
"append",
"]",
",",
"$",
"types",
")",
";",
"}",
"$",
"this",
"->",
"_parts",
"[",
"$",
"part",
"]",
"=",
"$",
"expression",
";",
"$",
"this",
"->",
"_dirty",
"(",
")",
";",
"}"
] | Helper function used to build conditions by composing QueryExpression objects.
@param string $part Name of the query part to append the new part to
@param string|null|array|\Cake\Database\ExpressionInterface|callable $append Expression or builder function to append.
@param string $conjunction type of conjunction to be used to operate part
@param array $types associative array of type names used to bind values to query
@return void | [
"Helper",
"function",
"used",
"to",
"build",
"conditions",
"by",
"composing",
"QueryExpression",
"objects",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L2244-L2267 |
211,039 | cakephp/cakephp | src/Database/Query.php | Query._dirty | protected function _dirty()
{
$this->_dirty = true;
if ($this->_iterator && $this->_valueBinder) {
$this->getValueBinder()->reset();
}
} | php | protected function _dirty()
{
$this->_dirty = true;
if ($this->_iterator && $this->_valueBinder) {
$this->getValueBinder()->reset();
}
} | [
"protected",
"function",
"_dirty",
"(",
")",
"{",
"$",
"this",
"->",
"_dirty",
"=",
"true",
";",
"if",
"(",
"$",
"this",
"->",
"_iterator",
"&&",
"$",
"this",
"->",
"_valueBinder",
")",
"{",
"$",
"this",
"->",
"getValueBinder",
"(",
")",
"->",
"reset",
"(",
")",
";",
"}",
"}"
] | Marks a query as dirty, removing any preprocessed information
from in memory caching.
@return void | [
"Marks",
"a",
"query",
"as",
"dirty",
"removing",
"any",
"preprocessed",
"information",
"from",
"in",
"memory",
"caching",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Query.php#L2275-L2282 |
211,040 | cakephp/cakephp | src/Console/ConsoleErrorHandler.php | ConsoleErrorHandler._displayException | protected function _displayException($exception)
{
$errorName = 'Exception:';
if ($exception instanceof FatalErrorException) {
$errorName = 'Fatal Error:';
}
if ($exception instanceof PHP7ErrorException) {
$exception = $exception->getError();
}
$message = sprintf(
'<error>%s</error> %s in [%s, line %s]',
$errorName,
$exception->getMessage(),
$exception->getFile(),
$exception->getLine()
);
$this->_stderr->write($message);
} | php | protected function _displayException($exception)
{
$errorName = 'Exception:';
if ($exception instanceof FatalErrorException) {
$errorName = 'Fatal Error:';
}
if ($exception instanceof PHP7ErrorException) {
$exception = $exception->getError();
}
$message = sprintf(
'<error>%s</error> %s in [%s, line %s]',
$errorName,
$exception->getMessage(),
$exception->getFile(),
$exception->getLine()
);
$this->_stderr->write($message);
} | [
"protected",
"function",
"_displayException",
"(",
"$",
"exception",
")",
"{",
"$",
"errorName",
"=",
"'Exception:'",
";",
"if",
"(",
"$",
"exception",
"instanceof",
"FatalErrorException",
")",
"{",
"$",
"errorName",
"=",
"'Fatal Error:'",
";",
"}",
"if",
"(",
"$",
"exception",
"instanceof",
"PHP7ErrorException",
")",
"{",
"$",
"exception",
"=",
"$",
"exception",
"->",
"getError",
"(",
")",
";",
"}",
"$",
"message",
"=",
"sprintf",
"(",
"'<error>%s</error> %s in [%s, line %s]'",
",",
"$",
"errorName",
",",
"$",
"exception",
"->",
"getMessage",
"(",
")",
",",
"$",
"exception",
"->",
"getFile",
"(",
")",
",",
"$",
"exception",
"->",
"getLine",
"(",
")",
")",
";",
"$",
"this",
"->",
"_stderr",
"->",
"write",
"(",
"$",
"message",
")",
";",
"}"
] | Prints an exception to stderr.
@param \Exception $exception The exception to handle
@return void | [
"Prints",
"an",
"exception",
"to",
"stderr",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleErrorHandler.php#L81-L100 |
211,041 | cakephp/cakephp | src/Console/ConsoleErrorHandler.php | ConsoleErrorHandler._displayError | protected function _displayError($error, $debug)
{
$message = sprintf(
'%s in [%s, line %s]',
$error['description'],
$error['file'],
$error['line']
);
$message = sprintf(
"<error>%s Error:</error> %s\n",
$error['error'],
$message
);
$this->_stderr->write($message);
} | php | protected function _displayError($error, $debug)
{
$message = sprintf(
'%s in [%s, line %s]',
$error['description'],
$error['file'],
$error['line']
);
$message = sprintf(
"<error>%s Error:</error> %s\n",
$error['error'],
$message
);
$this->_stderr->write($message);
} | [
"protected",
"function",
"_displayError",
"(",
"$",
"error",
",",
"$",
"debug",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'%s in [%s, line %s]'",
",",
"$",
"error",
"[",
"'description'",
"]",
",",
"$",
"error",
"[",
"'file'",
"]",
",",
"$",
"error",
"[",
"'line'",
"]",
")",
";",
"$",
"message",
"=",
"sprintf",
"(",
"\"<error>%s Error:</error> %s\\n\"",
",",
"$",
"error",
"[",
"'error'",
"]",
",",
"$",
"message",
")",
";",
"$",
"this",
"->",
"_stderr",
"->",
"write",
"(",
"$",
"message",
")",
";",
"}"
] | Prints an error to stderr.
Template method of BaseErrorHandler.
@param array $error An array of error data.
@param bool $debug Whether or not the app is in debug mode.
@return void | [
"Prints",
"an",
"error",
"to",
"stderr",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/ConsoleErrorHandler.php#L111-L125 |
211,042 | cakephp/cakephp | src/Database/Schema/SqliteSchema.php | SqliteSchema.hasSequences | public function hasSequences()
{
$result = $this->_driver->prepare(
'SELECT 1 FROM sqlite_master WHERE name = "sqlite_sequence"'
);
$result->execute();
$this->_hasSequences = (bool)$result->rowCount();
$result->closeCursor();
return $this->_hasSequences;
} | php | public function hasSequences()
{
$result = $this->_driver->prepare(
'SELECT 1 FROM sqlite_master WHERE name = "sqlite_sequence"'
);
$result->execute();
$this->_hasSequences = (bool)$result->rowCount();
$result->closeCursor();
return $this->_hasSequences;
} | [
"public",
"function",
"hasSequences",
"(",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"_driver",
"->",
"prepare",
"(",
"'SELECT 1 FROM sqlite_master WHERE name = \"sqlite_sequence\"'",
")",
";",
"$",
"result",
"->",
"execute",
"(",
")",
";",
"$",
"this",
"->",
"_hasSequences",
"=",
"(",
"bool",
")",
"$",
"result",
"->",
"rowCount",
"(",
")",
";",
"$",
"result",
"->",
"closeCursor",
"(",
")",
";",
"return",
"$",
"this",
"->",
"_hasSequences",
";",
"}"
] | Returns whether there is any table in this connection to SQLite containing
sequences
@return bool | [
"Returns",
"whether",
"there",
"is",
"any",
"table",
"in",
"this",
"connection",
"to",
"SQLite",
"containing",
"sequences"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Schema/SqliteSchema.php#L515-L525 |
211,043 | cakephp/cakephp | src/View/Helper/UrlHelper.php | UrlHelper.image | public function image($path, array $options = [])
{
$pathPrefix = Configure::read('App.imageBaseUrl');
return $this->assetUrl($path, $options + compact('pathPrefix'));
} | php | public function image($path, array $options = [])
{
$pathPrefix = Configure::read('App.imageBaseUrl');
return $this->assetUrl($path, $options + compact('pathPrefix'));
} | [
"public",
"function",
"image",
"(",
"$",
"path",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"pathPrefix",
"=",
"Configure",
"::",
"read",
"(",
"'App.imageBaseUrl'",
")",
";",
"return",
"$",
"this",
"->",
"assetUrl",
"(",
"$",
"path",
",",
"$",
"options",
"+",
"compact",
"(",
"'pathPrefix'",
")",
")",
";",
"}"
] | Generates URL for given image file.
Depending on options passed provides full URL with domain name. Also calls
`Helper::assetTimestamp()` to add timestamp to local files.
@param string|array $path Path string or URL array
@param array $options Options array. Possible keys:
`fullBase` Return full URL with domain name
`pathPrefix` Path prefix for relative URLs
`plugin` False value will prevent parsing path as a plugin
`timestamp` Overrides the value of `Asset.timestamp` in Configure.
Set to false to skip timestamp generation.
Set to true to apply timestamps when debug is true. Set to 'force' to always
enable timestamping regardless of debug value.
@return string Generated URL | [
"Generates",
"URL",
"for",
"given",
"image",
"file",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/UrlHelper.php#L82-L87 |
211,044 | cakephp/cakephp | src/View/Helper/UrlHelper.php | UrlHelper.script | public function script($path, array $options = [])
{
$pathPrefix = Configure::read('App.jsBaseUrl');
$ext = '.js';
return $this->assetUrl($path, $options + compact('pathPrefix', 'ext'));
} | php | public function script($path, array $options = [])
{
$pathPrefix = Configure::read('App.jsBaseUrl');
$ext = '.js';
return $this->assetUrl($path, $options + compact('pathPrefix', 'ext'));
} | [
"public",
"function",
"script",
"(",
"$",
"path",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"pathPrefix",
"=",
"Configure",
"::",
"read",
"(",
"'App.jsBaseUrl'",
")",
";",
"$",
"ext",
"=",
"'.js'",
";",
"return",
"$",
"this",
"->",
"assetUrl",
"(",
"$",
"path",
",",
"$",
"options",
"+",
"compact",
"(",
"'pathPrefix'",
",",
"'ext'",
")",
")",
";",
"}"
] | Generates URL for given javascript file.
Depending on options passed provides full URL with domain name. Also calls
`Helper::assetTimestamp()` to add timestamp to local files.
@param string|array $path Path string or URL array
@param array $options Options array. Possible keys:
`fullBase` Return full URL with domain name
`pathPrefix` Path prefix for relative URLs
`ext` Asset extension to append
`plugin` False value will prevent parsing path as a plugin
`timestamp` Overrides the value of `Asset.timestamp` in Configure.
Set to false to skip timestamp generation.
Set to true to apply timestamps when debug is true. Set to 'force' to always
enable timestamping regardless of debug value.
@return string Generated URL | [
"Generates",
"URL",
"for",
"given",
"javascript",
"file",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/UrlHelper.php#L133-L139 |
211,045 | cakephp/cakephp | src/View/Helper/UrlHelper.php | UrlHelper.assetUrl | public function assetUrl($path, array $options = [])
{
if (is_array($path)) {
return $this->build($path, !empty($options['fullBase']));
}
// data URIs only require HTML escaping
if (preg_match('/^data:[a-z]+\/[a-z]+;/', $path)) {
return h($path);
}
if (strpos($path, '://') !== false || preg_match('/^[a-z]+:/i', $path)) {
return ltrim($this->build($path), '/');
}
if (!array_key_exists('plugin', $options) || $options['plugin'] !== false) {
list($plugin, $path) = $this->_View->pluginSplit($path, false);
}
if (!empty($options['pathPrefix']) && $path[0] !== '/') {
$path = $options['pathPrefix'] . $path;
}
if (!empty($options['ext']) &&
strpos($path, '?') === false &&
substr($path, -strlen($options['ext'])) !== $options['ext']
) {
$path .= $options['ext'];
}
if (preg_match('|^([a-z0-9]+:)?//|', $path)) {
return $this->build($path);
}
if (isset($plugin)) {
$path = Inflector::underscore($plugin) . '/' . $path;
}
$optionTimestamp = null;
if (array_key_exists('timestamp', $options)) {
$optionTimestamp = $options['timestamp'];
}
$webPath = $this->assetTimestamp($this->webroot($path), $optionTimestamp);
$path = $this->_encodeUrl($webPath);
if (!empty($options['fullBase'])) {
$fullBaseUrl = is_string($options['fullBase']) ? $options['fullBase'] : Router::fullBaseUrl();
$path = rtrim($fullBaseUrl, '/') . '/' . ltrim($path, '/');
}
return $path;
} | php | public function assetUrl($path, array $options = [])
{
if (is_array($path)) {
return $this->build($path, !empty($options['fullBase']));
}
// data URIs only require HTML escaping
if (preg_match('/^data:[a-z]+\/[a-z]+;/', $path)) {
return h($path);
}
if (strpos($path, '://') !== false || preg_match('/^[a-z]+:/i', $path)) {
return ltrim($this->build($path), '/');
}
if (!array_key_exists('plugin', $options) || $options['plugin'] !== false) {
list($plugin, $path) = $this->_View->pluginSplit($path, false);
}
if (!empty($options['pathPrefix']) && $path[0] !== '/') {
$path = $options['pathPrefix'] . $path;
}
if (!empty($options['ext']) &&
strpos($path, '?') === false &&
substr($path, -strlen($options['ext'])) !== $options['ext']
) {
$path .= $options['ext'];
}
if (preg_match('|^([a-z0-9]+:)?//|', $path)) {
return $this->build($path);
}
if (isset($plugin)) {
$path = Inflector::underscore($plugin) . '/' . $path;
}
$optionTimestamp = null;
if (array_key_exists('timestamp', $options)) {
$optionTimestamp = $options['timestamp'];
}
$webPath = $this->assetTimestamp($this->webroot($path), $optionTimestamp);
$path = $this->_encodeUrl($webPath);
if (!empty($options['fullBase'])) {
$fullBaseUrl = is_string($options['fullBase']) ? $options['fullBase'] : Router::fullBaseUrl();
$path = rtrim($fullBaseUrl, '/') . '/' . ltrim($path, '/');
}
return $path;
} | [
"public",
"function",
"assetUrl",
"(",
"$",
"path",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"path",
")",
")",
"{",
"return",
"$",
"this",
"->",
"build",
"(",
"$",
"path",
",",
"!",
"empty",
"(",
"$",
"options",
"[",
"'fullBase'",
"]",
")",
")",
";",
"}",
"// data URIs only require HTML escaping",
"if",
"(",
"preg_match",
"(",
"'/^data:[a-z]+\\/[a-z]+;/'",
",",
"$",
"path",
")",
")",
"{",
"return",
"h",
"(",
"$",
"path",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"path",
",",
"'://'",
")",
"!==",
"false",
"||",
"preg_match",
"(",
"'/^[a-z]+:/i'",
",",
"$",
"path",
")",
")",
"{",
"return",
"ltrim",
"(",
"$",
"this",
"->",
"build",
"(",
"$",
"path",
")",
",",
"'/'",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'plugin'",
",",
"$",
"options",
")",
"||",
"$",
"options",
"[",
"'plugin'",
"]",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"plugin",
",",
"$",
"path",
")",
"=",
"$",
"this",
"->",
"_View",
"->",
"pluginSplit",
"(",
"$",
"path",
",",
"false",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'pathPrefix'",
"]",
")",
"&&",
"$",
"path",
"[",
"0",
"]",
"!==",
"'/'",
")",
"{",
"$",
"path",
"=",
"$",
"options",
"[",
"'pathPrefix'",
"]",
".",
"$",
"path",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'ext'",
"]",
")",
"&&",
"strpos",
"(",
"$",
"path",
",",
"'?'",
")",
"===",
"false",
"&&",
"substr",
"(",
"$",
"path",
",",
"-",
"strlen",
"(",
"$",
"options",
"[",
"'ext'",
"]",
")",
")",
"!==",
"$",
"options",
"[",
"'ext'",
"]",
")",
"{",
"$",
"path",
".=",
"$",
"options",
"[",
"'ext'",
"]",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'|^([a-z0-9]+:)?//|'",
",",
"$",
"path",
")",
")",
"{",
"return",
"$",
"this",
"->",
"build",
"(",
"$",
"path",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"plugin",
")",
")",
"{",
"$",
"path",
"=",
"Inflector",
"::",
"underscore",
"(",
"$",
"plugin",
")",
".",
"'/'",
".",
"$",
"path",
";",
"}",
"$",
"optionTimestamp",
"=",
"null",
";",
"if",
"(",
"array_key_exists",
"(",
"'timestamp'",
",",
"$",
"options",
")",
")",
"{",
"$",
"optionTimestamp",
"=",
"$",
"options",
"[",
"'timestamp'",
"]",
";",
"}",
"$",
"webPath",
"=",
"$",
"this",
"->",
"assetTimestamp",
"(",
"$",
"this",
"->",
"webroot",
"(",
"$",
"path",
")",
",",
"$",
"optionTimestamp",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"_encodeUrl",
"(",
"$",
"webPath",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'fullBase'",
"]",
")",
")",
"{",
"$",
"fullBaseUrl",
"=",
"is_string",
"(",
"$",
"options",
"[",
"'fullBase'",
"]",
")",
"?",
"$",
"options",
"[",
"'fullBase'",
"]",
":",
"Router",
"::",
"fullBaseUrl",
"(",
")",
";",
"$",
"path",
"=",
"rtrim",
"(",
"$",
"fullBaseUrl",
",",
"'/'",
")",
".",
"'/'",
".",
"ltrim",
"(",
"$",
"path",
",",
"'/'",
")",
";",
"}",
"return",
"$",
"path",
";",
"}"
] | Generates URL for given asset file.
Depending on options passed provides full URL with domain name. Also calls
`Helper::assetTimestamp()` to add timestamp to local files.
### Options:
- `fullBase` Boolean true or a string (e.g. https://example) to
return full URL with protocol and domain name.
- `pathPrefix` Path prefix for relative URLs
- `ext` Asset extension to append
- `plugin` False value will prevent parsing path as a plugin
- `timestamp` Overrides the value of `Asset.timestamp` in Configure.
Set to false to skip timestamp generation.
Set to true to apply timestamps when debug is true. Set to 'force' to always
enable timestamping regardless of debug value.
@param string|array $path Path string or URL array
@param array $options Options array.
@return string Generated URL | [
"Generates",
"URL",
"for",
"given",
"asset",
"file",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/UrlHelper.php#L163-L208 |
211,046 | cakephp/cakephp | src/View/Helper/UrlHelper.php | UrlHelper._encodeUrl | protected function _encodeUrl($url)
{
$path = parse_url($url, PHP_URL_PATH);
$parts = array_map('rawurldecode', explode('/', $path));
$parts = array_map('rawurlencode', $parts);
$encoded = implode('/', $parts);
/** @var string $url */
$url = h(str_replace($path, $encoded, $url));
return $url;
} | php | protected function _encodeUrl($url)
{
$path = parse_url($url, PHP_URL_PATH);
$parts = array_map('rawurldecode', explode('/', $path));
$parts = array_map('rawurlencode', $parts);
$encoded = implode('/', $parts);
/** @var string $url */
$url = h(str_replace($path, $encoded, $url));
return $url;
} | [
"protected",
"function",
"_encodeUrl",
"(",
"$",
"url",
")",
"{",
"$",
"path",
"=",
"parse_url",
"(",
"$",
"url",
",",
"PHP_URL_PATH",
")",
";",
"$",
"parts",
"=",
"array_map",
"(",
"'rawurldecode'",
",",
"explode",
"(",
"'/'",
",",
"$",
"path",
")",
")",
";",
"$",
"parts",
"=",
"array_map",
"(",
"'rawurlencode'",
",",
"$",
"parts",
")",
";",
"$",
"encoded",
"=",
"implode",
"(",
"'/'",
",",
"$",
"parts",
")",
";",
"/** @var string $url */",
"$",
"url",
"=",
"h",
"(",
"str_replace",
"(",
"$",
"path",
",",
"$",
"encoded",
",",
"$",
"url",
")",
")",
";",
"return",
"$",
"url",
";",
"}"
] | Encodes a URL for use in HTML attributes.
@param string $url The URL to encode.
@return string The URL encoded for both URL & HTML contexts. | [
"Encodes",
"a",
"URL",
"for",
"use",
"in",
"HTML",
"attributes",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/UrlHelper.php#L216-L227 |
211,047 | cakephp/cakephp | src/View/Helper/UrlHelper.php | UrlHelper.webroot | public function webroot($file)
{
$request = $this->_View->getRequest();
$asset = explode('?', $file);
$asset[1] = isset($asset[1]) ? '?' . $asset[1] : null;
$webPath = $request->getAttribute('webroot') . $asset[0];
$file = $asset[0];
if (!empty($this->_View->getTheme())) {
$file = trim($file, '/');
$theme = $this->_inflectThemeName($this->_View->getTheme()) . '/';
if (DIRECTORY_SEPARATOR === '\\') {
$file = str_replace('/', '\\', $file);
}
if (file_exists(Configure::read('App.wwwRoot') . $theme . $file)) {
$webPath = $request->getAttribute('webroot') . $theme . $asset[0];
} else {
$themePath = Plugin::path($this->_View->getTheme());
$path = $themePath . 'webroot/' . $file;
if (file_exists($path)) {
$webPath = $request->getAttribute('webroot') . $theme . $asset[0];
}
}
}
if (strpos($webPath, '//') !== false) {
return str_replace('//', '/', $webPath . $asset[1]);
}
return $webPath . $asset[1];
} | php | public function webroot($file)
{
$request = $this->_View->getRequest();
$asset = explode('?', $file);
$asset[1] = isset($asset[1]) ? '?' . $asset[1] : null;
$webPath = $request->getAttribute('webroot') . $asset[0];
$file = $asset[0];
if (!empty($this->_View->getTheme())) {
$file = trim($file, '/');
$theme = $this->_inflectThemeName($this->_View->getTheme()) . '/';
if (DIRECTORY_SEPARATOR === '\\') {
$file = str_replace('/', '\\', $file);
}
if (file_exists(Configure::read('App.wwwRoot') . $theme . $file)) {
$webPath = $request->getAttribute('webroot') . $theme . $asset[0];
} else {
$themePath = Plugin::path($this->_View->getTheme());
$path = $themePath . 'webroot/' . $file;
if (file_exists($path)) {
$webPath = $request->getAttribute('webroot') . $theme . $asset[0];
}
}
}
if (strpos($webPath, '//') !== false) {
return str_replace('//', '/', $webPath . $asset[1]);
}
return $webPath . $asset[1];
} | [
"public",
"function",
"webroot",
"(",
"$",
"file",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"_View",
"->",
"getRequest",
"(",
")",
";",
"$",
"asset",
"=",
"explode",
"(",
"'?'",
",",
"$",
"file",
")",
";",
"$",
"asset",
"[",
"1",
"]",
"=",
"isset",
"(",
"$",
"asset",
"[",
"1",
"]",
")",
"?",
"'?'",
".",
"$",
"asset",
"[",
"1",
"]",
":",
"null",
";",
"$",
"webPath",
"=",
"$",
"request",
"->",
"getAttribute",
"(",
"'webroot'",
")",
".",
"$",
"asset",
"[",
"0",
"]",
";",
"$",
"file",
"=",
"$",
"asset",
"[",
"0",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_View",
"->",
"getTheme",
"(",
")",
")",
")",
"{",
"$",
"file",
"=",
"trim",
"(",
"$",
"file",
",",
"'/'",
")",
";",
"$",
"theme",
"=",
"$",
"this",
"->",
"_inflectThemeName",
"(",
"$",
"this",
"->",
"_View",
"->",
"getTheme",
"(",
")",
")",
".",
"'/'",
";",
"if",
"(",
"DIRECTORY_SEPARATOR",
"===",
"'\\\\'",
")",
"{",
"$",
"file",
"=",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"file",
")",
";",
"}",
"if",
"(",
"file_exists",
"(",
"Configure",
"::",
"read",
"(",
"'App.wwwRoot'",
")",
".",
"$",
"theme",
".",
"$",
"file",
")",
")",
"{",
"$",
"webPath",
"=",
"$",
"request",
"->",
"getAttribute",
"(",
"'webroot'",
")",
".",
"$",
"theme",
".",
"$",
"asset",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"$",
"themePath",
"=",
"Plugin",
"::",
"path",
"(",
"$",
"this",
"->",
"_View",
"->",
"getTheme",
"(",
")",
")",
";",
"$",
"path",
"=",
"$",
"themePath",
".",
"'webroot/'",
".",
"$",
"file",
";",
"if",
"(",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"$",
"webPath",
"=",
"$",
"request",
"->",
"getAttribute",
"(",
"'webroot'",
")",
".",
"$",
"theme",
".",
"$",
"asset",
"[",
"0",
"]",
";",
"}",
"}",
"}",
"if",
"(",
"strpos",
"(",
"$",
"webPath",
",",
"'//'",
")",
"!==",
"false",
")",
"{",
"return",
"str_replace",
"(",
"'//'",
",",
"'/'",
",",
"$",
"webPath",
".",
"$",
"asset",
"[",
"1",
"]",
")",
";",
"}",
"return",
"$",
"webPath",
".",
"$",
"asset",
"[",
"1",
"]",
";",
"}"
] | Checks if a file exists when theme is used, if no file is found default location is returned
@param string $file The file to create a webroot path to.
@return string Web accessible path to file. | [
"Checks",
"if",
"a",
"file",
"exists",
"when",
"theme",
"is",
"used",
"if",
"no",
"file",
"is",
"found",
"default",
"location",
"is",
"returned"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/UrlHelper.php#L274-L306 |
211,048 | cakephp/cakephp | src/Log/Engine/BaseLog.php | BaseLog._format | protected function _format($data, array $context = [])
{
if (is_string($data)) {
return $data;
}
$isObject = is_object($data);
if ($isObject && $data instanceof EntityInterface) {
return json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
}
if ($isObject && method_exists($data, '__toString')) {
return (string)$data;
}
if ($isObject && $data instanceof JsonSerializable) {
return json_encode($data, JSON_UNESCAPED_UNICODE);
}
return print_r($data, true);
} | php | protected function _format($data, array $context = [])
{
if (is_string($data)) {
return $data;
}
$isObject = is_object($data);
if ($isObject && $data instanceof EntityInterface) {
return json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
}
if ($isObject && method_exists($data, '__toString')) {
return (string)$data;
}
if ($isObject && $data instanceof JsonSerializable) {
return json_encode($data, JSON_UNESCAPED_UNICODE);
}
return print_r($data, true);
} | [
"protected",
"function",
"_format",
"(",
"$",
"data",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"data",
")",
")",
"{",
"return",
"$",
"data",
";",
"}",
"$",
"isObject",
"=",
"is_object",
"(",
"$",
"data",
")",
";",
"if",
"(",
"$",
"isObject",
"&&",
"$",
"data",
"instanceof",
"EntityInterface",
")",
"{",
"return",
"json_encode",
"(",
"$",
"data",
",",
"JSON_UNESCAPED_UNICODE",
"|",
"JSON_PRETTY_PRINT",
")",
";",
"}",
"if",
"(",
"$",
"isObject",
"&&",
"method_exists",
"(",
"$",
"data",
",",
"'__toString'",
")",
")",
"{",
"return",
"(",
"string",
")",
"$",
"data",
";",
"}",
"if",
"(",
"$",
"isObject",
"&&",
"$",
"data",
"instanceof",
"JsonSerializable",
")",
"{",
"return",
"json_encode",
"(",
"$",
"data",
",",
"JSON_UNESCAPED_UNICODE",
")",
";",
"}",
"return",
"print_r",
"(",
"$",
"data",
",",
"true",
")",
";",
"}"
] | Converts to string the provided data so it can be logged. The context
can optionally be used by log engines to interpolate variables
or add additional info to the logged message.
@param mixed $data The data to be converted to string and logged.
@param array $context Additional logging information for the message.
@return string | [
"Converts",
"to",
"string",
"the",
"provided",
"data",
"so",
"it",
"can",
"be",
"logged",
".",
"The",
"context",
"can",
"optionally",
"be",
"used",
"by",
"log",
"engines",
"to",
"interpolate",
"variables",
"or",
"add",
"additional",
"info",
"to",
"the",
"logged",
"message",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Log/Engine/BaseLog.php#L90-L111 |
211,049 | cakephp/cakephp | src/Mailer/MailerAwareTrait.php | MailerAwareTrait.getMailer | protected function getMailer($name, Email $email = null)
{
if ($email === null) {
$email = new Email();
}
$className = App::className($name, 'Mailer', 'Mailer');
if (empty($className)) {
throw new MissingMailerException(compact('name'));
}
return new $className($email);
} | php | protected function getMailer($name, Email $email = null)
{
if ($email === null) {
$email = new Email();
}
$className = App::className($name, 'Mailer', 'Mailer');
if (empty($className)) {
throw new MissingMailerException(compact('name'));
}
return new $className($email);
} | [
"protected",
"function",
"getMailer",
"(",
"$",
"name",
",",
"Email",
"$",
"email",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"email",
"===",
"null",
")",
"{",
"$",
"email",
"=",
"new",
"Email",
"(",
")",
";",
"}",
"$",
"className",
"=",
"App",
"::",
"className",
"(",
"$",
"name",
",",
"'Mailer'",
",",
"'Mailer'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"className",
")",
")",
"{",
"throw",
"new",
"MissingMailerException",
"(",
"compact",
"(",
"'name'",
")",
")",
";",
"}",
"return",
"new",
"$",
"className",
"(",
"$",
"email",
")",
";",
"}"
] | Returns a mailer instance.
@param string $name Mailer's name.
@param \Cake\Mailer\Email|null $email Email instance.
@return \Cake\Mailer\Mailer
@throws \Cake\Mailer\Exception\MissingMailerException if undefined mailer class. | [
"Returns",
"a",
"mailer",
"instance",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Mailer/MailerAwareTrait.php#L38-L51 |
211,050 | cakephp/cakephp | src/Cache/Engine/MemcachedEngine.php | MemcachedEngine._setOptions | protected function _setOptions()
{
$this->_Memcached->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
$serializer = strtolower($this->_config['serialize']);
if (!isset($this->_serializers[$serializer])) {
throw new InvalidArgumentException(
sprintf('%s is not a valid serializer engine for Memcached', $serializer)
);
}
if ($serializer !== 'php' &&
!constant('Memcached::HAVE_' . strtoupper($serializer))
) {
throw new InvalidArgumentException(
sprintf('Memcached extension is not compiled with %s support', $serializer)
);
}
$this->_Memcached->setOption(
Memcached::OPT_SERIALIZER,
$this->_serializers[$serializer]
);
// Check for Amazon ElastiCache instance
if (defined('Memcached::OPT_CLIENT_MODE') &&
defined('Memcached::DYNAMIC_CLIENT_MODE')
) {
$this->_Memcached->setOption(
Memcached::OPT_CLIENT_MODE,
Memcached::DYNAMIC_CLIENT_MODE
);
}
$this->_Memcached->setOption(
Memcached::OPT_COMPRESSION,
(bool)$this->_config['compress']
);
} | php | protected function _setOptions()
{
$this->_Memcached->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
$serializer = strtolower($this->_config['serialize']);
if (!isset($this->_serializers[$serializer])) {
throw new InvalidArgumentException(
sprintf('%s is not a valid serializer engine for Memcached', $serializer)
);
}
if ($serializer !== 'php' &&
!constant('Memcached::HAVE_' . strtoupper($serializer))
) {
throw new InvalidArgumentException(
sprintf('Memcached extension is not compiled with %s support', $serializer)
);
}
$this->_Memcached->setOption(
Memcached::OPT_SERIALIZER,
$this->_serializers[$serializer]
);
// Check for Amazon ElastiCache instance
if (defined('Memcached::OPT_CLIENT_MODE') &&
defined('Memcached::DYNAMIC_CLIENT_MODE')
) {
$this->_Memcached->setOption(
Memcached::OPT_CLIENT_MODE,
Memcached::DYNAMIC_CLIENT_MODE
);
}
$this->_Memcached->setOption(
Memcached::OPT_COMPRESSION,
(bool)$this->_config['compress']
);
} | [
"protected",
"function",
"_setOptions",
"(",
")",
"{",
"$",
"this",
"->",
"_Memcached",
"->",
"setOption",
"(",
"Memcached",
"::",
"OPT_LIBKETAMA_COMPATIBLE",
",",
"true",
")",
";",
"$",
"serializer",
"=",
"strtolower",
"(",
"$",
"this",
"->",
"_config",
"[",
"'serialize'",
"]",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_serializers",
"[",
"$",
"serializer",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'%s is not a valid serializer engine for Memcached'",
",",
"$",
"serializer",
")",
")",
";",
"}",
"if",
"(",
"$",
"serializer",
"!==",
"'php'",
"&&",
"!",
"constant",
"(",
"'Memcached::HAVE_'",
".",
"strtoupper",
"(",
"$",
"serializer",
")",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Memcached extension is not compiled with %s support'",
",",
"$",
"serializer",
")",
")",
";",
"}",
"$",
"this",
"->",
"_Memcached",
"->",
"setOption",
"(",
"Memcached",
"::",
"OPT_SERIALIZER",
",",
"$",
"this",
"->",
"_serializers",
"[",
"$",
"serializer",
"]",
")",
";",
"// Check for Amazon ElastiCache instance",
"if",
"(",
"defined",
"(",
"'Memcached::OPT_CLIENT_MODE'",
")",
"&&",
"defined",
"(",
"'Memcached::DYNAMIC_CLIENT_MODE'",
")",
")",
"{",
"$",
"this",
"->",
"_Memcached",
"->",
"setOption",
"(",
"Memcached",
"::",
"OPT_CLIENT_MODE",
",",
"Memcached",
"::",
"DYNAMIC_CLIENT_MODE",
")",
";",
"}",
"$",
"this",
"->",
"_Memcached",
"->",
"setOption",
"(",
"Memcached",
"::",
"OPT_COMPRESSION",
",",
"(",
"bool",
")",
"$",
"this",
"->",
"_config",
"[",
"'compress'",
"]",
")",
";",
"}"
] | Settings the memcached instance
@return void
@throws \InvalidArgumentException When the Memcached extension is not built
with the desired serializer engine. | [
"Settings",
"the",
"memcached",
"instance"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/Engine/MemcachedEngine.php#L197-L235 |
211,051 | cakephp/cakephp | src/Cache/Engine/MemcachedEngine.php | MemcachedEngine.write | public function write($key, $value)
{
$duration = $this->_config['duration'];
if ($duration > 30 * DAY) {
$duration = 0;
}
$key = $this->_key($key);
return $this->_Memcached->set($key, $value, $duration);
} | php | public function write($key, $value)
{
$duration = $this->_config['duration'];
if ($duration > 30 * DAY) {
$duration = 0;
}
$key = $this->_key($key);
return $this->_Memcached->set($key, $value, $duration);
} | [
"public",
"function",
"write",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"duration",
"=",
"$",
"this",
"->",
"_config",
"[",
"'duration'",
"]",
";",
"if",
"(",
"$",
"duration",
">",
"30",
"*",
"DAY",
")",
"{",
"$",
"duration",
"=",
"0",
";",
"}",
"$",
"key",
"=",
"$",
"this",
"->",
"_key",
"(",
"$",
"key",
")",
";",
"return",
"$",
"this",
"->",
"_Memcached",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"duration",
")",
";",
"}"
] | Write data for key into cache. When using memcached as your cache engine
remember that the Memcached pecl extension does not support cache expiry
times greater than 30 days in the future. Any duration greater than 30 days
will be treated as never expiring.
@param string $key Identifier for the data
@param mixed $value Data to be cached
@return bool True if the data was successfully cached, false on failure
@see https://secure.php.net/manual/en/memcache.set.php | [
"Write",
"data",
"for",
"key",
"into",
"cache",
".",
"When",
"using",
"memcached",
"as",
"your",
"cache",
"engine",
"remember",
"that",
"the",
"Memcached",
"pecl",
"extension",
"does",
"not",
"support",
"cache",
"expiry",
"times",
"greater",
"than",
"30",
"days",
"in",
"the",
"future",
".",
"Any",
"duration",
"greater",
"than",
"30",
"days",
"will",
"be",
"treated",
"as",
"never",
"expiring",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/Engine/MemcachedEngine.php#L302-L312 |
211,052 | cakephp/cakephp | src/Cache/Engine/MemcachedEngine.php | MemcachedEngine.writeMany | public function writeMany($data)
{
$cacheData = [];
foreach ($data as $key => $value) {
$cacheData[$this->_key($key)] = $value;
}
$success = $this->_Memcached->setMulti($cacheData);
$return = [];
foreach (array_keys($data) as $key) {
$return[$key] = $success;
}
return $return;
} | php | public function writeMany($data)
{
$cacheData = [];
foreach ($data as $key => $value) {
$cacheData[$this->_key($key)] = $value;
}
$success = $this->_Memcached->setMulti($cacheData);
$return = [];
foreach (array_keys($data) as $key) {
$return[$key] = $success;
}
return $return;
} | [
"public",
"function",
"writeMany",
"(",
"$",
"data",
")",
"{",
"$",
"cacheData",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"cacheData",
"[",
"$",
"this",
"->",
"_key",
"(",
"$",
"key",
")",
"]",
"=",
"$",
"value",
";",
"}",
"$",
"success",
"=",
"$",
"this",
"->",
"_Memcached",
"->",
"setMulti",
"(",
"$",
"cacheData",
")",
";",
"$",
"return",
"=",
"[",
"]",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"data",
")",
"as",
"$",
"key",
")",
"{",
"$",
"return",
"[",
"$",
"key",
"]",
"=",
"$",
"success",
";",
"}",
"return",
"$",
"return",
";",
"}"
] | Write many cache entries to the cache at once
@param array $data An array of data to be stored in the cache
@return array of bools for each key provided, true if the data was
successfully cached, false on failure | [
"Write",
"many",
"cache",
"entries",
"to",
"the",
"cache",
"at",
"once"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/Engine/MemcachedEngine.php#L321-L336 |
211,053 | cakephp/cakephp | src/Cache/Engine/MemcachedEngine.php | MemcachedEngine.readMany | public function readMany($keys)
{
$cacheKeys = [];
foreach ($keys as $key) {
$cacheKeys[] = $this->_key($key);
}
$values = $this->_Memcached->getMulti($cacheKeys);
$return = [];
foreach ($keys as &$key) {
$return[$key] = array_key_exists($this->_key($key), $values) ?
$values[$this->_key($key)] : false;
}
return $return;
} | php | public function readMany($keys)
{
$cacheKeys = [];
foreach ($keys as $key) {
$cacheKeys[] = $this->_key($key);
}
$values = $this->_Memcached->getMulti($cacheKeys);
$return = [];
foreach ($keys as &$key) {
$return[$key] = array_key_exists($this->_key($key), $values) ?
$values[$this->_key($key)] : false;
}
return $return;
} | [
"public",
"function",
"readMany",
"(",
"$",
"keys",
")",
"{",
"$",
"cacheKeys",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"cacheKeys",
"[",
"]",
"=",
"$",
"this",
"->",
"_key",
"(",
"$",
"key",
")",
";",
"}",
"$",
"values",
"=",
"$",
"this",
"->",
"_Memcached",
"->",
"getMulti",
"(",
"$",
"cacheKeys",
")",
";",
"$",
"return",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"keys",
"as",
"&",
"$",
"key",
")",
"{",
"$",
"return",
"[",
"$",
"key",
"]",
"=",
"array_key_exists",
"(",
"$",
"this",
"->",
"_key",
"(",
"$",
"key",
")",
",",
"$",
"values",
")",
"?",
"$",
"values",
"[",
"$",
"this",
"->",
"_key",
"(",
"$",
"key",
")",
"]",
":",
"false",
";",
"}",
"return",
"$",
"return",
";",
"}"
] | Read many keys from the cache at once
@param array $keys An array of identifiers for the data
@return array An array containing, for each of the given $keys, the cached data or
false if cached data could not be retrieved. | [
"Read",
"many",
"keys",
"from",
"the",
"cache",
"at",
"once"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/Engine/MemcachedEngine.php#L359-L374 |
211,054 | cakephp/cakephp | src/Cache/Engine/MemcachedEngine.php | MemcachedEngine.deleteMany | public function deleteMany($keys)
{
$cacheKeys = [];
foreach ($keys as $key) {
$cacheKeys[] = $this->_key($key);
}
$success = $this->_Memcached->deleteMulti($cacheKeys);
$return = [];
foreach ($keys as $key) {
$return[$key] = $success;
}
return $return;
} | php | public function deleteMany($keys)
{
$cacheKeys = [];
foreach ($keys as $key) {
$cacheKeys[] = $this->_key($key);
}
$success = $this->_Memcached->deleteMulti($cacheKeys);
$return = [];
foreach ($keys as $key) {
$return[$key] = $success;
}
return $return;
} | [
"public",
"function",
"deleteMany",
"(",
"$",
"keys",
")",
"{",
"$",
"cacheKeys",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"cacheKeys",
"[",
"]",
"=",
"$",
"this",
"->",
"_key",
"(",
"$",
"key",
")",
";",
"}",
"$",
"success",
"=",
"$",
"this",
"->",
"_Memcached",
"->",
"deleteMulti",
"(",
"$",
"cacheKeys",
")",
";",
"$",
"return",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"return",
"[",
"$",
"key",
"]",
"=",
"$",
"success",
";",
"}",
"return",
"$",
"return",
";",
"}"
] | Delete many keys from the cache at once
@param array $keys An array of identifiers for the data
@return array of boolean values that are true if the key was successfully
deleted, false if it didn't exist or couldn't be removed. | [
"Delete",
"many",
"keys",
"from",
"the",
"cache",
"at",
"once"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Cache/Engine/MemcachedEngine.php#L425-L440 |
211,055 | cakephp/cakephp | src/Console/CommandRunner.php | CommandRunner.getShell | protected function getShell(ConsoleIo $io, CommandCollection $commands, $name)
{
$instance = $commands->get($name);
if (is_string($instance)) {
$instance = $this->createShell($instance, $io);
}
if ($instance instanceof Shell) {
$instance->setRootName($this->root);
}
if ($instance instanceof Command) {
$instance->setName("{$this->root} {$name}");
}
if ($instance instanceof CommandCollectionAwareInterface) {
$instance->setCommandCollection($commands);
}
return $instance;
} | php | protected function getShell(ConsoleIo $io, CommandCollection $commands, $name)
{
$instance = $commands->get($name);
if (is_string($instance)) {
$instance = $this->createShell($instance, $io);
}
if ($instance instanceof Shell) {
$instance->setRootName($this->root);
}
if ($instance instanceof Command) {
$instance->setName("{$this->root} {$name}");
}
if ($instance instanceof CommandCollectionAwareInterface) {
$instance->setCommandCollection($commands);
}
return $instance;
} | [
"protected",
"function",
"getShell",
"(",
"ConsoleIo",
"$",
"io",
",",
"CommandCollection",
"$",
"commands",
",",
"$",
"name",
")",
"{",
"$",
"instance",
"=",
"$",
"commands",
"->",
"get",
"(",
"$",
"name",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"instance",
")",
")",
"{",
"$",
"instance",
"=",
"$",
"this",
"->",
"createShell",
"(",
"$",
"instance",
",",
"$",
"io",
")",
";",
"}",
"if",
"(",
"$",
"instance",
"instanceof",
"Shell",
")",
"{",
"$",
"instance",
"->",
"setRootName",
"(",
"$",
"this",
"->",
"root",
")",
";",
"}",
"if",
"(",
"$",
"instance",
"instanceof",
"Command",
")",
"{",
"$",
"instance",
"->",
"setName",
"(",
"\"{$this->root} {$name}\"",
")",
";",
"}",
"if",
"(",
"$",
"instance",
"instanceof",
"CommandCollectionAwareInterface",
")",
"{",
"$",
"instance",
"->",
"setCommandCollection",
"(",
"$",
"commands",
")",
";",
"}",
"return",
"$",
"instance",
";",
"}"
] | Get the shell instance for a given command name
@param \Cake\Console\ConsoleIo $io The IO wrapper for the created shell class.
@param \Cake\Console\CommandCollection $commands The command collection to find the shell in.
@param string $name The command name to find
@return \Cake\Console\Shell|\Cake\Console\Command | [
"Get",
"the",
"shell",
"instance",
"for",
"a",
"given",
"command",
"name"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/CommandRunner.php#L277-L294 |
211,056 | cakephp/cakephp | src/Console/CommandRunner.php | CommandRunner.longestCommandName | protected function longestCommandName($commands, $argv)
{
for ($i = 3; $i > 1; $i--) {
$parts = array_slice($argv, 0, $i);
$name = implode(' ', $parts);
if ($commands->has($name)) {
return [$name, array_slice($argv, $i)];
}
}
$name = array_shift($argv);
return [$name, $argv];
} | php | protected function longestCommandName($commands, $argv)
{
for ($i = 3; $i > 1; $i--) {
$parts = array_slice($argv, 0, $i);
$name = implode(' ', $parts);
if ($commands->has($name)) {
return [$name, array_slice($argv, $i)];
}
}
$name = array_shift($argv);
return [$name, $argv];
} | [
"protected",
"function",
"longestCommandName",
"(",
"$",
"commands",
",",
"$",
"argv",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"3",
";",
"$",
"i",
">",
"1",
";",
"$",
"i",
"--",
")",
"{",
"$",
"parts",
"=",
"array_slice",
"(",
"$",
"argv",
",",
"0",
",",
"$",
"i",
")",
";",
"$",
"name",
"=",
"implode",
"(",
"' '",
",",
"$",
"parts",
")",
";",
"if",
"(",
"$",
"commands",
"->",
"has",
"(",
"$",
"name",
")",
")",
"{",
"return",
"[",
"$",
"name",
",",
"array_slice",
"(",
"$",
"argv",
",",
"$",
"i",
")",
"]",
";",
"}",
"}",
"$",
"name",
"=",
"array_shift",
"(",
"$",
"argv",
")",
";",
"return",
"[",
"$",
"name",
",",
"$",
"argv",
"]",
";",
"}"
] | Build the longest command name that exists in the collection
Build the longest command name that matches a
defined command. This will traverse a maximum of 3 tokens.
@param \Cake\Console\CommandCollection $commands The command collection to check.
@param array $argv The CLI arguments.
@return array An array of the resolved name and modified argv. | [
"Build",
"the",
"longest",
"command",
"name",
"that",
"exists",
"in",
"the",
"collection"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/CommandRunner.php#L306-L318 |
211,057 | cakephp/cakephp | src/Console/CommandRunner.php | CommandRunner.resolveName | protected function resolveName($commands, $io, $name)
{
if (!$name) {
$io->err('<error>No command provided. Choose one of the available commands.</error>', 2);
$name = 'help';
}
if (isset($this->aliases[$name])) {
$name = $this->aliases[$name];
}
if (!$commands->has($name)) {
$name = Inflector::underscore($name);
}
if (!$commands->has($name)) {
throw new RuntimeException(
"Unknown command `{$this->root} {$name}`." .
" Run `{$this->root} --help` to get the list of valid commands."
);
}
return $name;
} | php | protected function resolveName($commands, $io, $name)
{
if (!$name) {
$io->err('<error>No command provided. Choose one of the available commands.</error>', 2);
$name = 'help';
}
if (isset($this->aliases[$name])) {
$name = $this->aliases[$name];
}
if (!$commands->has($name)) {
$name = Inflector::underscore($name);
}
if (!$commands->has($name)) {
throw new RuntimeException(
"Unknown command `{$this->root} {$name}`." .
" Run `{$this->root} --help` to get the list of valid commands."
);
}
return $name;
} | [
"protected",
"function",
"resolveName",
"(",
"$",
"commands",
",",
"$",
"io",
",",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"$",
"name",
")",
"{",
"$",
"io",
"->",
"err",
"(",
"'<error>No command provided. Choose one of the available commands.</error>'",
",",
"2",
")",
";",
"$",
"name",
"=",
"'help'",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"aliases",
"[",
"$",
"name",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"commands",
"->",
"has",
"(",
"$",
"name",
")",
")",
"{",
"$",
"name",
"=",
"Inflector",
"::",
"underscore",
"(",
"$",
"name",
")",
";",
"}",
"if",
"(",
"!",
"$",
"commands",
"->",
"has",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Unknown command `{$this->root} {$name}`.\"",
".",
"\" Run `{$this->root} --help` to get the list of valid commands.\"",
")",
";",
"}",
"return",
"$",
"name",
";",
"}"
] | Resolve the command name into a name that exists in the collection.
Apply backwards compatible inflections and aliases.
Will step forward up to 3 tokens in $argv to generate
a command name in the CommandCollection. More specific
command names take precedence over less specific ones.
@param \Cake\Console\CommandCollection $commands The command collection to check.
@param \Cake\Console\ConsoleIo $io ConsoleIo object for errors.
@param string $name The name
@return string The resolved class name | [
"Resolve",
"the",
"command",
"name",
"into",
"a",
"name",
"that",
"exists",
"in",
"the",
"collection",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/CommandRunner.php#L333-L353 |
211,058 | cakephp/cakephp | src/Console/CommandRunner.php | CommandRunner.runCommand | protected function runCommand(Command $command, array $argv, ConsoleIo $io)
{
try {
return $command->run($argv, $io);
} catch (StopException $e) {
return $e->getCode();
}
} | php | protected function runCommand(Command $command, array $argv, ConsoleIo $io)
{
try {
return $command->run($argv, $io);
} catch (StopException $e) {
return $e->getCode();
}
} | [
"protected",
"function",
"runCommand",
"(",
"Command",
"$",
"command",
",",
"array",
"$",
"argv",
",",
"ConsoleIo",
"$",
"io",
")",
"{",
"try",
"{",
"return",
"$",
"command",
"->",
"run",
"(",
"$",
"argv",
",",
"$",
"io",
")",
";",
"}",
"catch",
"(",
"StopException",
"$",
"e",
")",
"{",
"return",
"$",
"e",
"->",
"getCode",
"(",
")",
";",
"}",
"}"
] | Execute a Command class.
@param \Cake\Console\Command $command The command to run.
@param array $argv The CLI arguments to invoke.
@param \Cake\Console\ConsoleIo $io The console io
@return int Exit code | [
"Execute",
"a",
"Command",
"class",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/CommandRunner.php#L363-L370 |
211,059 | cakephp/cakephp | src/Console/CommandRunner.php | CommandRunner.runShell | protected function runShell(Shell $shell, array $argv)
{
try {
$shell->initialize();
return $shell->runCommand($argv, true);
} catch (StopException $e) {
return $e->getCode();
}
} | php | protected function runShell(Shell $shell, array $argv)
{
try {
$shell->initialize();
return $shell->runCommand($argv, true);
} catch (StopException $e) {
return $e->getCode();
}
} | [
"protected",
"function",
"runShell",
"(",
"Shell",
"$",
"shell",
",",
"array",
"$",
"argv",
")",
"{",
"try",
"{",
"$",
"shell",
"->",
"initialize",
"(",
")",
";",
"return",
"$",
"shell",
"->",
"runCommand",
"(",
"$",
"argv",
",",
"true",
")",
";",
"}",
"catch",
"(",
"StopException",
"$",
"e",
")",
"{",
"return",
"$",
"e",
"->",
"getCode",
"(",
")",
";",
"}",
"}"
] | Execute a Shell class.
@param \Cake\Console\Shell $shell The shell to run.
@param array $argv The CLI arguments to invoke.
@return int Exit code | [
"Execute",
"a",
"Shell",
"class",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/CommandRunner.php#L379-L388 |
211,060 | cakephp/cakephp | src/Console/CommandRunner.php | CommandRunner.createShell | protected function createShell($className, ConsoleIo $io)
{
$shell = $this->factory->create($className);
if ($shell instanceof Shell) {
$shell->setIo($io);
}
return $shell;
} | php | protected function createShell($className, ConsoleIo $io)
{
$shell = $this->factory->create($className);
if ($shell instanceof Shell) {
$shell->setIo($io);
}
return $shell;
} | [
"protected",
"function",
"createShell",
"(",
"$",
"className",
",",
"ConsoleIo",
"$",
"io",
")",
"{",
"$",
"shell",
"=",
"$",
"this",
"->",
"factory",
"->",
"create",
"(",
"$",
"className",
")",
";",
"if",
"(",
"$",
"shell",
"instanceof",
"Shell",
")",
"{",
"$",
"shell",
"->",
"setIo",
"(",
"$",
"io",
")",
";",
"}",
"return",
"$",
"shell",
";",
"}"
] | The wrapper for creating shell instances.
@param string $className Shell class name.
@param \Cake\Console\ConsoleIo $io The IO wrapper for the created shell class.
@return \Cake\Console\Shell|\Cake\Console\Command | [
"The",
"wrapper",
"for",
"creating",
"shell",
"instances",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/CommandRunner.php#L397-L405 |
211,061 | cakephp/cakephp | src/Console/CommandRunner.php | CommandRunner.loadRoutes | protected function loadRoutes()
{
$builder = Router::createRouteBuilder('/');
if ($this->app instanceof HttpApplicationInterface) {
$this->app->routes($builder);
}
if ($this->app instanceof PluginApplicationInterface) {
$this->app->pluginRoutes($builder);
}
} | php | protected function loadRoutes()
{
$builder = Router::createRouteBuilder('/');
if ($this->app instanceof HttpApplicationInterface) {
$this->app->routes($builder);
}
if ($this->app instanceof PluginApplicationInterface) {
$this->app->pluginRoutes($builder);
}
} | [
"protected",
"function",
"loadRoutes",
"(",
")",
"{",
"$",
"builder",
"=",
"Router",
"::",
"createRouteBuilder",
"(",
"'/'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"app",
"instanceof",
"HttpApplicationInterface",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"routes",
"(",
"$",
"builder",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"app",
"instanceof",
"PluginApplicationInterface",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"pluginRoutes",
"(",
"$",
"builder",
")",
";",
"}",
"}"
] | Ensure that the application's routes are loaded.
Console commands and shells often need to generate URLs.
@return void | [
"Ensure",
"that",
"the",
"application",
"s",
"routes",
"are",
"loaded",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Console/CommandRunner.php#L414-L424 |
211,062 | cakephp/cakephp | src/Collection/Iterator/ReplaceIterator.php | ReplaceIterator.current | public function current()
{
$callback = $this->_callback;
return $callback(parent::current(), $this->key(), $this->_innerIterator);
} | php | public function current()
{
$callback = $this->_callback;
return $callback(parent::current(), $this->key(), $this->_innerIterator);
} | [
"public",
"function",
"current",
"(",
")",
"{",
"$",
"callback",
"=",
"$",
"this",
"->",
"_callback",
";",
"return",
"$",
"callback",
"(",
"parent",
"::",
"current",
"(",
")",
",",
"$",
"this",
"->",
"key",
"(",
")",
",",
"$",
"this",
"->",
"_innerIterator",
")",
";",
"}"
] | Returns the value returned by the callback after passing the current value in
the iteration
@return mixed | [
"Returns",
"the",
"value",
"returned",
"by",
"the",
"callback",
"after",
"passing",
"the",
"current",
"value",
"in",
"the",
"iteration"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Collection/Iterator/ReplaceIterator.php#L66-L71 |
211,063 | cakephp/cakephp | src/Database/ValueBinder.php | ValueBinder.bind | public function bind($param, $value, $type = 'string')
{
$this->_bindings[$param] = compact('value', 'type') + [
'placeholder' => is_int($param) ? $param : substr($param, 1)
];
} | php | public function bind($param, $value, $type = 'string')
{
$this->_bindings[$param] = compact('value', 'type') + [
'placeholder' => is_int($param) ? $param : substr($param, 1)
];
} | [
"public",
"function",
"bind",
"(",
"$",
"param",
",",
"$",
"value",
",",
"$",
"type",
"=",
"'string'",
")",
"{",
"$",
"this",
"->",
"_bindings",
"[",
"$",
"param",
"]",
"=",
"compact",
"(",
"'value'",
",",
"'type'",
")",
"+",
"[",
"'placeholder'",
"=>",
"is_int",
"(",
"$",
"param",
")",
"?",
"$",
"param",
":",
"substr",
"(",
"$",
"param",
",",
"1",
")",
"]",
";",
"}"
] | Associates a query placeholder to a value and a type
@param string|int $param placeholder to be replaced with quoted version
of $value
@param mixed $value The value to be bound
@param string|int $type the mapped type name, used for casting when sending
to database
@return void | [
"Associates",
"a",
"query",
"placeholder",
"to",
"a",
"value",
"and",
"a",
"type"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/ValueBinder.php#L51-L56 |
211,064 | cakephp/cakephp | src/Database/ValueBinder.php | ValueBinder.generateManyNamed | public function generateManyNamed($values, $type = 'string')
{
$placeholders = [];
foreach ($values as $k => $value) {
$param = $this->placeholder('c');
$this->_bindings[$param] = [
'value' => $value,
'type' => $type,
'placeholder' => substr($param, 1),
];
$placeholders[$k] = $param;
}
return $placeholders;
} | php | public function generateManyNamed($values, $type = 'string')
{
$placeholders = [];
foreach ($values as $k => $value) {
$param = $this->placeholder('c');
$this->_bindings[$param] = [
'value' => $value,
'type' => $type,
'placeholder' => substr($param, 1),
];
$placeholders[$k] = $param;
}
return $placeholders;
} | [
"public",
"function",
"generateManyNamed",
"(",
"$",
"values",
",",
"$",
"type",
"=",
"'string'",
")",
"{",
"$",
"placeholders",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"k",
"=>",
"$",
"value",
")",
"{",
"$",
"param",
"=",
"$",
"this",
"->",
"placeholder",
"(",
"'c'",
")",
";",
"$",
"this",
"->",
"_bindings",
"[",
"$",
"param",
"]",
"=",
"[",
"'value'",
"=>",
"$",
"value",
",",
"'type'",
"=>",
"$",
"type",
",",
"'placeholder'",
"=>",
"substr",
"(",
"$",
"param",
",",
"1",
")",
",",
"]",
";",
"$",
"placeholders",
"[",
"$",
"k",
"]",
"=",
"$",
"param",
";",
"}",
"return",
"$",
"placeholders",
";",
"}"
] | Creates unique named placeholders for each of the passed values
and binds them with the specified type.
@param array|\Traversable $values The list of values to be bound
@param string $type The type with which all values will be bound
@return array with the placeholders to insert in the query | [
"Creates",
"unique",
"named",
"placeholders",
"for",
"each",
"of",
"the",
"passed",
"values",
"and",
"binds",
"them",
"with",
"the",
"specified",
"type",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/ValueBinder.php#L85-L99 |
211,065 | cakephp/cakephp | src/Database/ValueBinder.php | ValueBinder.attachTo | public function attachTo($statement)
{
$bindings = $this->bindings();
if (empty($bindings)) {
return;
}
foreach ($bindings as $b) {
$statement->bindValue($b['placeholder'], $b['value'], $b['type']);
}
} | php | public function attachTo($statement)
{
$bindings = $this->bindings();
if (empty($bindings)) {
return;
}
foreach ($bindings as $b) {
$statement->bindValue($b['placeholder'], $b['value'], $b['type']);
}
} | [
"public",
"function",
"attachTo",
"(",
"$",
"statement",
")",
"{",
"$",
"bindings",
"=",
"$",
"this",
"->",
"bindings",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"bindings",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"bindings",
"as",
"$",
"b",
")",
"{",
"$",
"statement",
"->",
"bindValue",
"(",
"$",
"b",
"[",
"'placeholder'",
"]",
",",
"$",
"b",
"[",
"'value'",
"]",
",",
"$",
"b",
"[",
"'type'",
"]",
")",
";",
"}",
"}"
] | Binds all the stored values in this object to the passed statement.
@param \Cake\Database\StatementInterface $statement The statement to add parameters to.
@return void | [
"Binds",
"all",
"the",
"stored",
"values",
"in",
"this",
"object",
"to",
"the",
"passed",
"statement",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/ValueBinder.php#L139-L149 |
211,066 | cakephp/cakephp | src/Routing/Route/PluginShortRoute.php | PluginShortRoute.parse | public function parse($url, $method = '')
{
$params = parent::parse($url, $method);
if (!$params) {
return false;
}
$params['controller'] = $params['plugin'];
return $params;
} | php | public function parse($url, $method = '')
{
$params = parent::parse($url, $method);
if (!$params) {
return false;
}
$params['controller'] = $params['plugin'];
return $params;
} | [
"public",
"function",
"parse",
"(",
"$",
"url",
",",
"$",
"method",
"=",
"''",
")",
"{",
"$",
"params",
"=",
"parent",
"::",
"parse",
"(",
"$",
"url",
",",
"$",
"method",
")",
";",
"if",
"(",
"!",
"$",
"params",
")",
"{",
"return",
"false",
";",
"}",
"$",
"params",
"[",
"'controller'",
"]",
"=",
"$",
"params",
"[",
"'plugin'",
"]",
";",
"return",
"$",
"params",
";",
"}"
] | Parses a string URL into an array. If a plugin key is found, it will be copied to the
controller parameter.
@param string $url The URL to parse
@param string $method The HTTP method
@return array|false An array of request parameters, or boolean false on failure. | [
"Parses",
"a",
"string",
"URL",
"into",
"an",
"array",
".",
"If",
"a",
"plugin",
"key",
"is",
"found",
"it",
"will",
"be",
"copied",
"to",
"the",
"controller",
"parameter",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Route/PluginShortRoute.php#L32-L41 |
211,067 | cakephp/cakephp | src/Routing/Route/PluginShortRoute.php | PluginShortRoute.match | public function match(array $url, array $context = [])
{
if (isset($url['controller'], $url['plugin']) && $url['plugin'] !== $url['controller']) {
return false;
}
$this->defaults['controller'] = $url['controller'];
$result = parent::match($url, $context);
unset($this->defaults['controller']);
return $result;
} | php | public function match(array $url, array $context = [])
{
if (isset($url['controller'], $url['plugin']) && $url['plugin'] !== $url['controller']) {
return false;
}
$this->defaults['controller'] = $url['controller'];
$result = parent::match($url, $context);
unset($this->defaults['controller']);
return $result;
} | [
"public",
"function",
"match",
"(",
"array",
"$",
"url",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"url",
"[",
"'controller'",
"]",
",",
"$",
"url",
"[",
"'plugin'",
"]",
")",
"&&",
"$",
"url",
"[",
"'plugin'",
"]",
"!==",
"$",
"url",
"[",
"'controller'",
"]",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"defaults",
"[",
"'controller'",
"]",
"=",
"$",
"url",
"[",
"'controller'",
"]",
";",
"$",
"result",
"=",
"parent",
"::",
"match",
"(",
"$",
"url",
",",
"$",
"context",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"defaults",
"[",
"'controller'",
"]",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Reverses route plugin shortcut URLs. If the plugin and controller
are not the same the match is an auto fail.
@param array $url Array of parameters to convert to a string.
@param array $context An array of the current request context.
Contains information such as the current host, scheme, port, and base
directory.
@return string|false Either a string URL for the parameters if they match or false. | [
"Reverses",
"route",
"plugin",
"shortcut",
"URLs",
".",
"If",
"the",
"plugin",
"and",
"controller",
"are",
"not",
"the",
"same",
"the",
"match",
"is",
"an",
"auto",
"fail",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Routing/Route/PluginShortRoute.php#L53-L63 |
211,068 | cakephp/cakephp | src/ORM/Locator/TableLocator.php | TableLocator.getConfig | public function getConfig($alias = null)
{
if ($alias === null) {
return $this->_config;
}
return isset($this->_config[$alias]) ? $this->_config[$alias] : [];
} | php | public function getConfig($alias = null)
{
if ($alias === null) {
return $this->_config;
}
return isset($this->_config[$alias]) ? $this->_config[$alias] : [];
} | [
"public",
"function",
"getConfig",
"(",
"$",
"alias",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"alias",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_config",
";",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"_config",
"[",
"$",
"alias",
"]",
")",
"?",
"$",
"this",
"->",
"_config",
"[",
"$",
"alias",
"]",
":",
"[",
"]",
";",
"}"
] | Returns configuration for an alias or the full configuration array for all aliases.
@param string|null $alias Alias to get config for, null for complete config.
@return array The config data. | [
"Returns",
"configuration",
"for",
"an",
"alias",
"or",
"the",
"full",
"configuration",
"array",
"for",
"all",
"aliases",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Locator/TableLocator.php#L94-L101 |
211,069 | cakephp/cakephp | src/ORM/Locator/TableLocator.php | TableLocator.get | public function get($alias, array $options = [])
{
if (isset($this->_instances[$alias])) {
if (!empty($options) && $this->_options[$alias] !== $options) {
throw new RuntimeException(sprintf(
'You cannot configure "%s", it already exists in the registry.',
$alias
));
}
return $this->_instances[$alias];
}
$this->_options[$alias] = $options;
list(, $classAlias) = pluginSplit($alias);
$options = ['alias' => $classAlias] + $options;
if (isset($this->_config[$alias])) {
$options += $this->_config[$alias];
}
$className = $this->_getClassName($alias, $options);
if ($className) {
$options['className'] = $className;
} else {
if (empty($options['className'])) {
$options['className'] = Inflector::camelize($alias);
}
if (!isset($options['table']) && strpos($options['className'], '\\') === false) {
list(, $table) = pluginSplit($options['className']);
$options['table'] = Inflector::underscore($table);
}
$options['className'] = 'Cake\ORM\Table';
}
if (empty($options['connection'])) {
if (!empty($options['connectionName'])) {
$connectionName = $options['connectionName'];
} else {
/* @var \Cake\ORM\Table $className */
$className = $options['className'];
$connectionName = $className::defaultConnectionName();
}
$options['connection'] = ConnectionManager::get($connectionName);
}
if (empty($options['associations'])) {
$associations = new AssociationCollection($this);
$options['associations'] = $associations;
}
$options['registryAlias'] = $alias;
$this->_instances[$alias] = $this->_create($options);
if ($options['className'] === 'Cake\ORM\Table') {
$this->_fallbacked[$alias] = $this->_instances[$alias];
}
return $this->_instances[$alias];
} | php | public function get($alias, array $options = [])
{
if (isset($this->_instances[$alias])) {
if (!empty($options) && $this->_options[$alias] !== $options) {
throw new RuntimeException(sprintf(
'You cannot configure "%s", it already exists in the registry.',
$alias
));
}
return $this->_instances[$alias];
}
$this->_options[$alias] = $options;
list(, $classAlias) = pluginSplit($alias);
$options = ['alias' => $classAlias] + $options;
if (isset($this->_config[$alias])) {
$options += $this->_config[$alias];
}
$className = $this->_getClassName($alias, $options);
if ($className) {
$options['className'] = $className;
} else {
if (empty($options['className'])) {
$options['className'] = Inflector::camelize($alias);
}
if (!isset($options['table']) && strpos($options['className'], '\\') === false) {
list(, $table) = pluginSplit($options['className']);
$options['table'] = Inflector::underscore($table);
}
$options['className'] = 'Cake\ORM\Table';
}
if (empty($options['connection'])) {
if (!empty($options['connectionName'])) {
$connectionName = $options['connectionName'];
} else {
/* @var \Cake\ORM\Table $className */
$className = $options['className'];
$connectionName = $className::defaultConnectionName();
}
$options['connection'] = ConnectionManager::get($connectionName);
}
if (empty($options['associations'])) {
$associations = new AssociationCollection($this);
$options['associations'] = $associations;
}
$options['registryAlias'] = $alias;
$this->_instances[$alias] = $this->_create($options);
if ($options['className'] === 'Cake\ORM\Table') {
$this->_fallbacked[$alias] = $this->_instances[$alias];
}
return $this->_instances[$alias];
} | [
"public",
"function",
"get",
"(",
"$",
"alias",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_instances",
"[",
"$",
"alias",
"]",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
")",
"&&",
"$",
"this",
"->",
"_options",
"[",
"$",
"alias",
"]",
"!==",
"$",
"options",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'You cannot configure \"%s\", it already exists in the registry.'",
",",
"$",
"alias",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_instances",
"[",
"$",
"alias",
"]",
";",
"}",
"$",
"this",
"->",
"_options",
"[",
"$",
"alias",
"]",
"=",
"$",
"options",
";",
"list",
"(",
",",
"$",
"classAlias",
")",
"=",
"pluginSplit",
"(",
"$",
"alias",
")",
";",
"$",
"options",
"=",
"[",
"'alias'",
"=>",
"$",
"classAlias",
"]",
"+",
"$",
"options",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_config",
"[",
"$",
"alias",
"]",
")",
")",
"{",
"$",
"options",
"+=",
"$",
"this",
"->",
"_config",
"[",
"$",
"alias",
"]",
";",
"}",
"$",
"className",
"=",
"$",
"this",
"->",
"_getClassName",
"(",
"$",
"alias",
",",
"$",
"options",
")",
";",
"if",
"(",
"$",
"className",
")",
"{",
"$",
"options",
"[",
"'className'",
"]",
"=",
"$",
"className",
";",
"}",
"else",
"{",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'className'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'className'",
"]",
"=",
"Inflector",
"::",
"camelize",
"(",
"$",
"alias",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'table'",
"]",
")",
"&&",
"strpos",
"(",
"$",
"options",
"[",
"'className'",
"]",
",",
"'\\\\'",
")",
"===",
"false",
")",
"{",
"list",
"(",
",",
"$",
"table",
")",
"=",
"pluginSplit",
"(",
"$",
"options",
"[",
"'className'",
"]",
")",
";",
"$",
"options",
"[",
"'table'",
"]",
"=",
"Inflector",
"::",
"underscore",
"(",
"$",
"table",
")",
";",
"}",
"$",
"options",
"[",
"'className'",
"]",
"=",
"'Cake\\ORM\\Table'",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'connection'",
"]",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'connectionName'",
"]",
")",
")",
"{",
"$",
"connectionName",
"=",
"$",
"options",
"[",
"'connectionName'",
"]",
";",
"}",
"else",
"{",
"/* @var \\Cake\\ORM\\Table $className */",
"$",
"className",
"=",
"$",
"options",
"[",
"'className'",
"]",
";",
"$",
"connectionName",
"=",
"$",
"className",
"::",
"defaultConnectionName",
"(",
")",
";",
"}",
"$",
"options",
"[",
"'connection'",
"]",
"=",
"ConnectionManager",
"::",
"get",
"(",
"$",
"connectionName",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'associations'",
"]",
")",
")",
"{",
"$",
"associations",
"=",
"new",
"AssociationCollection",
"(",
"$",
"this",
")",
";",
"$",
"options",
"[",
"'associations'",
"]",
"=",
"$",
"associations",
";",
"}",
"$",
"options",
"[",
"'registryAlias'",
"]",
"=",
"$",
"alias",
";",
"$",
"this",
"->",
"_instances",
"[",
"$",
"alias",
"]",
"=",
"$",
"this",
"->",
"_create",
"(",
"$",
"options",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'className'",
"]",
"===",
"'Cake\\ORM\\Table'",
")",
"{",
"$",
"this",
"->",
"_fallbacked",
"[",
"$",
"alias",
"]",
"=",
"$",
"this",
"->",
"_instances",
"[",
"$",
"alias",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"_instances",
"[",
"$",
"alias",
"]",
";",
"}"
] | Get a table instance from the registry.
Tables are only created once until the registry is flushed.
This means that aliases must be unique across your application.
This is important because table associations are resolved at runtime
and cyclic references need to be handled correctly.
The options that can be passed are the same as in Cake\ORM\Table::__construct(), but the
`className` key is also recognized.
### Options
- `className` Define the specific class name to use. If undefined, CakePHP will generate the
class name based on the alias. For example 'Users' would result in
`App\Model\Table\UsersTable` being used. If this class does not exist,
then the default `Cake\ORM\Table` class will be used. By setting the `className`
option you can define the specific class to use. The className option supports
plugin short class references {@link Cake\Core\App::shortName()}.
- `table` Define the table name to use. If undefined, this option will default to the underscored
version of the alias name.
- `connection` Inject the specific connection object to use. If this option and `connectionName` are undefined,
The table class' `defaultConnectionName()` method will be invoked to fetch the connection name.
- `connectionName` Define the connection name to use. The named connection will be fetched from
Cake\Datasource\ConnectionManager.
*Note* If your `$alias` uses plugin syntax only the name part will be used as
key in the registry. This means that if two plugins, or a plugin and app provide
the same alias, the registry will only store the first instance.
@param string $alias The alias name you want to get.
@param array $options The options you want to build the table with.
If a table has already been loaded the options will be ignored.
@return \Cake\ORM\Table
@throws \RuntimeException When you try to configure an alias that already exists. | [
"Get",
"a",
"table",
"instance",
"from",
"the",
"registry",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Locator/TableLocator.php#L173-L231 |
211,070 | cakephp/cakephp | src/ORM/Locator/TableLocator.php | TableLocator._getClassName | protected function _getClassName($alias, array $options = [])
{
if (empty($options['className'])) {
$options['className'] = Inflector::camelize($alias);
}
return App::className($options['className'], 'Model/Table', 'Table');
} | php | protected function _getClassName($alias, array $options = [])
{
if (empty($options['className'])) {
$options['className'] = Inflector::camelize($alias);
}
return App::className($options['className'], 'Model/Table', 'Table');
} | [
"protected",
"function",
"_getClassName",
"(",
"$",
"alias",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'className'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'className'",
"]",
"=",
"Inflector",
"::",
"camelize",
"(",
"$",
"alias",
")",
";",
"}",
"return",
"App",
"::",
"className",
"(",
"$",
"options",
"[",
"'className'",
"]",
",",
"'Model/Table'",
",",
"'Table'",
")",
";",
"}"
] | Gets the table class name.
@param string $alias The alias name you want to get.
@param array $options Table options array.
@return string|false | [
"Gets",
"the",
"table",
"class",
"name",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Locator/TableLocator.php#L240-L247 |
211,071 | cakephp/cakephp | src/View/Helper/TextHelper.php | TextHelper._insertPlaceHolder | protected function _insertPlaceHolder($matches)
{
$match = $matches[0];
$envelope = ['', ''];
if (isset($matches['url'])) {
$match = $matches['url'];
$envelope = [$matches['left'], $matches['right']];
}
if (isset($matches['url_bare'])) {
$match = $matches['url_bare'];
}
$key = hash_hmac('sha1', $match, Security::getSalt());
$this->_placeholders[$key] = [
'content' => $match,
'envelope' => $envelope
];
return $key;
} | php | protected function _insertPlaceHolder($matches)
{
$match = $matches[0];
$envelope = ['', ''];
if (isset($matches['url'])) {
$match = $matches['url'];
$envelope = [$matches['left'], $matches['right']];
}
if (isset($matches['url_bare'])) {
$match = $matches['url_bare'];
}
$key = hash_hmac('sha1', $match, Security::getSalt());
$this->_placeholders[$key] = [
'content' => $match,
'envelope' => $envelope
];
return $key;
} | [
"protected",
"function",
"_insertPlaceHolder",
"(",
"$",
"matches",
")",
"{",
"$",
"match",
"=",
"$",
"matches",
"[",
"0",
"]",
";",
"$",
"envelope",
"=",
"[",
"''",
",",
"''",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"matches",
"[",
"'url'",
"]",
")",
")",
"{",
"$",
"match",
"=",
"$",
"matches",
"[",
"'url'",
"]",
";",
"$",
"envelope",
"=",
"[",
"$",
"matches",
"[",
"'left'",
"]",
",",
"$",
"matches",
"[",
"'right'",
"]",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"matches",
"[",
"'url_bare'",
"]",
")",
")",
"{",
"$",
"match",
"=",
"$",
"matches",
"[",
"'url_bare'",
"]",
";",
"}",
"$",
"key",
"=",
"hash_hmac",
"(",
"'sha1'",
",",
"$",
"match",
",",
"Security",
"::",
"getSalt",
"(",
")",
")",
";",
"$",
"this",
"->",
"_placeholders",
"[",
"$",
"key",
"]",
"=",
"[",
"'content'",
"=>",
"$",
"match",
",",
"'envelope'",
"=>",
"$",
"envelope",
"]",
";",
"return",
"$",
"key",
";",
"}"
] | Saves the placeholder for a string, for later use. This gets around double
escaping content in URL's.
@param array $matches An array of regexp matches.
@return string Replaced values. | [
"Saves",
"the",
"placeholder",
"for",
"a",
"string",
"for",
"later",
"use",
".",
"This",
"gets",
"around",
"double",
"escaping",
"content",
"in",
"URL",
"s",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/TextHelper.php#L160-L178 |
211,072 | cakephp/cakephp | src/View/Helper/TextHelper.php | TextHelper._linkUrls | protected function _linkUrls($text, $htmlOptions)
{
$replace = [];
foreach ($this->_placeholders as $hash => $content) {
$link = $url = $content['content'];
$envelope = $content['envelope'];
if (!preg_match('#^[a-z]+\://#i', $url)) {
$url = 'http://' . $url;
}
$replace[$hash] = $envelope[0] . $this->Html->link($link, $url, $htmlOptions) . $envelope[1];
}
return strtr($text, $replace);
} | php | protected function _linkUrls($text, $htmlOptions)
{
$replace = [];
foreach ($this->_placeholders as $hash => $content) {
$link = $url = $content['content'];
$envelope = $content['envelope'];
if (!preg_match('#^[a-z]+\://#i', $url)) {
$url = 'http://' . $url;
}
$replace[$hash] = $envelope[0] . $this->Html->link($link, $url, $htmlOptions) . $envelope[1];
}
return strtr($text, $replace);
} | [
"protected",
"function",
"_linkUrls",
"(",
"$",
"text",
",",
"$",
"htmlOptions",
")",
"{",
"$",
"replace",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_placeholders",
"as",
"$",
"hash",
"=>",
"$",
"content",
")",
"{",
"$",
"link",
"=",
"$",
"url",
"=",
"$",
"content",
"[",
"'content'",
"]",
";",
"$",
"envelope",
"=",
"$",
"content",
"[",
"'envelope'",
"]",
";",
"if",
"(",
"!",
"preg_match",
"(",
"'#^[a-z]+\\://#i'",
",",
"$",
"url",
")",
")",
"{",
"$",
"url",
"=",
"'http://'",
".",
"$",
"url",
";",
"}",
"$",
"replace",
"[",
"$",
"hash",
"]",
"=",
"$",
"envelope",
"[",
"0",
"]",
".",
"$",
"this",
"->",
"Html",
"->",
"link",
"(",
"$",
"link",
",",
"$",
"url",
",",
"$",
"htmlOptions",
")",
".",
"$",
"envelope",
"[",
"1",
"]",
";",
"}",
"return",
"strtr",
"(",
"$",
"text",
",",
"$",
"replace",
")",
";",
"}"
] | Replace placeholders with links.
@param string $text The text to operate on.
@param array $htmlOptions The options for the generated links.
@return string The text with links inserted. | [
"Replace",
"placeholders",
"with",
"links",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/TextHelper.php#L187-L200 |
211,073 | cakephp/cakephp | src/View/Helper/TextHelper.php | TextHelper._linkEmails | protected function _linkEmails($text, $options)
{
$replace = [];
foreach ($this->_placeholders as $hash => $content) {
$url = $content['content'];
$envelope = $content['envelope'];
$replace[$hash] = $envelope[0] . $this->Html->link($url, 'mailto:' . $url, $options) . $envelope[1];
}
return strtr($text, $replace);
} | php | protected function _linkEmails($text, $options)
{
$replace = [];
foreach ($this->_placeholders as $hash => $content) {
$url = $content['content'];
$envelope = $content['envelope'];
$replace[$hash] = $envelope[0] . $this->Html->link($url, 'mailto:' . $url, $options) . $envelope[1];
}
return strtr($text, $replace);
} | [
"protected",
"function",
"_linkEmails",
"(",
"$",
"text",
",",
"$",
"options",
")",
"{",
"$",
"replace",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_placeholders",
"as",
"$",
"hash",
"=>",
"$",
"content",
")",
"{",
"$",
"url",
"=",
"$",
"content",
"[",
"'content'",
"]",
";",
"$",
"envelope",
"=",
"$",
"content",
"[",
"'envelope'",
"]",
";",
"$",
"replace",
"[",
"$",
"hash",
"]",
"=",
"$",
"envelope",
"[",
"0",
"]",
".",
"$",
"this",
"->",
"Html",
"->",
"link",
"(",
"$",
"url",
",",
"'mailto:'",
".",
"$",
"url",
",",
"$",
"options",
")",
".",
"$",
"envelope",
"[",
"1",
"]",
";",
"}",
"return",
"strtr",
"(",
"$",
"text",
",",
"$",
"replace",
")",
";",
"}"
] | Links email addresses
@param string $text The text to operate on
@param array $options An array of options to use for the HTML.
@return string
@see \Cake\View\Helper\TextHelper::autoLinkEmails() | [
"Links",
"email",
"addresses"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/TextHelper.php#L210-L220 |
211,074 | cakephp/cakephp | src/View/Helper/TextHelper.php | TextHelper.autoLink | public function autoLink($text, array $options = [])
{
$text = $this->autoLinkUrls($text, $options);
return $this->autoLinkEmails($text, ['escape' => false] + $options);
} | php | public function autoLink($text, array $options = [])
{
$text = $this->autoLinkUrls($text, $options);
return $this->autoLinkEmails($text, ['escape' => false] + $options);
} | [
"public",
"function",
"autoLink",
"(",
"$",
"text",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"text",
"=",
"$",
"this",
"->",
"autoLinkUrls",
"(",
"$",
"text",
",",
"$",
"options",
")",
";",
"return",
"$",
"this",
"->",
"autoLinkEmails",
"(",
"$",
"text",
",",
"[",
"'escape'",
"=>",
"false",
"]",
"+",
"$",
"options",
")",
";",
"}"
] | Convert all links and email addresses to HTML links.
### Options
- `escape` Control HTML escaping of input. Defaults to true.
@param string $text Text
@param array $options Array of HTML options, and options listed above.
@return string The text with links
@link https://book.cakephp.org/3.0/en/views/helpers/text.html#linking-both-urls-and-email-addresses | [
"Convert",
"all",
"links",
"and",
"email",
"addresses",
"to",
"HTML",
"links",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/Helper/TextHelper.php#L264-L269 |
211,075 | cakephp/cakephp | src/I18n/DateFormatTrait.php | DateFormatTrait.i18nFormat | public function i18nFormat($format = null, $timezone = null, $locale = null)
{
if ($format === Time::UNIX_TIMESTAMP_FORMAT) {
return $this->getTimestamp();
}
$time = $this;
if ($timezone) {
// Handle the immutable and mutable object cases.
$time = clone $this;
$time = $time->timezone($timezone);
}
$format = $format !== null ? $format : static::$_toStringFormat;
$locale = $locale ?: static::$defaultLocale;
return $this->_formatObject($time, $format, $locale);
} | php | public function i18nFormat($format = null, $timezone = null, $locale = null)
{
if ($format === Time::UNIX_TIMESTAMP_FORMAT) {
return $this->getTimestamp();
}
$time = $this;
if ($timezone) {
// Handle the immutable and mutable object cases.
$time = clone $this;
$time = $time->timezone($timezone);
}
$format = $format !== null ? $format : static::$_toStringFormat;
$locale = $locale ?: static::$defaultLocale;
return $this->_formatObject($time, $format, $locale);
} | [
"public",
"function",
"i18nFormat",
"(",
"$",
"format",
"=",
"null",
",",
"$",
"timezone",
"=",
"null",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"format",
"===",
"Time",
"::",
"UNIX_TIMESTAMP_FORMAT",
")",
"{",
"return",
"$",
"this",
"->",
"getTimestamp",
"(",
")",
";",
"}",
"$",
"time",
"=",
"$",
"this",
";",
"if",
"(",
"$",
"timezone",
")",
"{",
"// Handle the immutable and mutable object cases.",
"$",
"time",
"=",
"clone",
"$",
"this",
";",
"$",
"time",
"=",
"$",
"time",
"->",
"timezone",
"(",
"$",
"timezone",
")",
";",
"}",
"$",
"format",
"=",
"$",
"format",
"!==",
"null",
"?",
"$",
"format",
":",
"static",
"::",
"$",
"_toStringFormat",
";",
"$",
"locale",
"=",
"$",
"locale",
"?",
":",
"static",
"::",
"$",
"defaultLocale",
";",
"return",
"$",
"this",
"->",
"_formatObject",
"(",
"$",
"time",
",",
"$",
"format",
",",
"$",
"locale",
")",
";",
"}"
] | Returns a formatted string for this time object using the preferred format and
language for the specified locale.
It is possible to specify the desired format for the string to be displayed.
You can either pass `IntlDateFormatter` constants as the first argument of this
function, or pass a full ICU date formatting string as specified in the following
resource: http://www.icu-project.org/apiref/icu4c/classSimpleDateFormat.html#details.
Additional to `IntlDateFormatter` constants and date formatting string you can use
Time::UNIX_TIMESTAMP_FORMAT to get a unix timestamp
### Examples
```
$time = new Time('2014-04-20 22:10');
$time->i18nFormat(); // outputs '4/20/14, 10:10 PM' for the en-US locale
$time->i18nFormat(\IntlDateFormatter::FULL); // Use the full date and time format
$time->i18nFormat([\IntlDateFormatter::FULL, \IntlDateFormatter::SHORT]); // Use full date but short time format
$time->i18nFormat('yyyy-MM-dd HH:mm:ss'); // outputs '2014-04-20 22:10'
$time->i18nFormat(Time::UNIX_TIMESTAMP_FORMAT); // outputs '1398031800'
```
If you wish to control the default format to be used for this method, you can alter
the value of the static `Time::$defaultLocale` variable and set it to one of the
possible formats accepted by this function.
You can read about the available IntlDateFormatter constants at
https://secure.php.net/manual/en/class.intldateformatter.php
If you need to display the date in a different timezone than the one being used for
this Time object without altering its internal state, you can pass a timezone
string or object as the second parameter.
Finally, should you need to use a different locale for displaying this time object,
pass a locale string as the third parameter to this function.
### Examples
```
$time = new Time('2014-04-20 22:10');
$time->i18nFormat(null, null, 'de-DE');
$time->i18nFormat(\IntlDateFormatter::FULL, 'Europe/Berlin', 'de-DE');
```
You can control the default locale to be used by setting the static variable
`Time::$defaultLocale` to a valid locale string. If empty, the default will be
taken from the `intl.default_locale` ini config.
@param string|int|null $format Format string.
@param string|\DateTimeZone|null $timezone Timezone string or DateTimeZone object
in which the date will be displayed. The timezone stored for this object will not
be changed.
@param string|null $locale The locale name in which the date should be displayed (e.g. pt-BR)
@return string|int Formatted and translated date string | [
"Returns",
"a",
"formatted",
"string",
"for",
"this",
"time",
"object",
"using",
"the",
"preferred",
"format",
"and",
"language",
"for",
"the",
"specified",
"locale",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/I18n/DateFormatTrait.php#L161-L179 |
211,076 | cakephp/cakephp | src/I18n/DateFormatTrait.php | DateFormatTrait.parseDateTime | public static function parseDateTime($time, $format = null)
{
$dateFormat = $format ?: static::$_toStringFormat;
$timeFormat = $pattern = null;
if (is_array($dateFormat)) {
list($newDateFormat, $timeFormat) = $dateFormat;
$dateFormat = $newDateFormat;
} else {
$pattern = $dateFormat;
$dateFormat = null;
}
if (static::$_isDateInstance === null) {
static::$_isDateInstance =
is_subclass_of(static::class, ChronosDate::class) ||
is_subclass_of(static::class, MutableDate::class);
}
$defaultTimezone = static::$_isDateInstance ? 'UTC' : date_default_timezone_get();
$formatter = datefmt_create(
static::$defaultLocale,
$dateFormat,
$timeFormat,
$defaultTimezone,
null,
$pattern
);
$time = $formatter->parse($time);
if ($time !== false) {
$result = new static('@' . $time);
return static::$_isDateInstance ? $result : $result->setTimezone($defaultTimezone);
}
return null;
} | php | public static function parseDateTime($time, $format = null)
{
$dateFormat = $format ?: static::$_toStringFormat;
$timeFormat = $pattern = null;
if (is_array($dateFormat)) {
list($newDateFormat, $timeFormat) = $dateFormat;
$dateFormat = $newDateFormat;
} else {
$pattern = $dateFormat;
$dateFormat = null;
}
if (static::$_isDateInstance === null) {
static::$_isDateInstance =
is_subclass_of(static::class, ChronosDate::class) ||
is_subclass_of(static::class, MutableDate::class);
}
$defaultTimezone = static::$_isDateInstance ? 'UTC' : date_default_timezone_get();
$formatter = datefmt_create(
static::$defaultLocale,
$dateFormat,
$timeFormat,
$defaultTimezone,
null,
$pattern
);
$time = $formatter->parse($time);
if ($time !== false) {
$result = new static('@' . $time);
return static::$_isDateInstance ? $result : $result->setTimezone($defaultTimezone);
}
return null;
} | [
"public",
"static",
"function",
"parseDateTime",
"(",
"$",
"time",
",",
"$",
"format",
"=",
"null",
")",
"{",
"$",
"dateFormat",
"=",
"$",
"format",
"?",
":",
"static",
"::",
"$",
"_toStringFormat",
";",
"$",
"timeFormat",
"=",
"$",
"pattern",
"=",
"null",
";",
"if",
"(",
"is_array",
"(",
"$",
"dateFormat",
")",
")",
"{",
"list",
"(",
"$",
"newDateFormat",
",",
"$",
"timeFormat",
")",
"=",
"$",
"dateFormat",
";",
"$",
"dateFormat",
"=",
"$",
"newDateFormat",
";",
"}",
"else",
"{",
"$",
"pattern",
"=",
"$",
"dateFormat",
";",
"$",
"dateFormat",
"=",
"null",
";",
"}",
"if",
"(",
"static",
"::",
"$",
"_isDateInstance",
"===",
"null",
")",
"{",
"static",
"::",
"$",
"_isDateInstance",
"=",
"is_subclass_of",
"(",
"static",
"::",
"class",
",",
"ChronosDate",
"::",
"class",
")",
"||",
"is_subclass_of",
"(",
"static",
"::",
"class",
",",
"MutableDate",
"::",
"class",
")",
";",
"}",
"$",
"defaultTimezone",
"=",
"static",
"::",
"$",
"_isDateInstance",
"?",
"'UTC'",
":",
"date_default_timezone_get",
"(",
")",
";",
"$",
"formatter",
"=",
"datefmt_create",
"(",
"static",
"::",
"$",
"defaultLocale",
",",
"$",
"dateFormat",
",",
"$",
"timeFormat",
",",
"$",
"defaultTimezone",
",",
"null",
",",
"$",
"pattern",
")",
";",
"$",
"time",
"=",
"$",
"formatter",
"->",
"parse",
"(",
"$",
"time",
")",
";",
"if",
"(",
"$",
"time",
"!==",
"false",
")",
"{",
"$",
"result",
"=",
"new",
"static",
"(",
"'@'",
".",
"$",
"time",
")",
";",
"return",
"static",
"::",
"$",
"_isDateInstance",
"?",
"$",
"result",
":",
"$",
"result",
"->",
"setTimezone",
"(",
"$",
"defaultTimezone",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Returns a new Time object after parsing the provided time string based on
the passed or configured date time format. This method is locale dependent,
Any string that is passed to this function will be interpreted as a locale
dependent string.
When no $format is provided, the `toString` format will be used.
If it was impossible to parse the provided time, null will be returned.
Example:
```
$time = Time::parseDateTime('10/13/2013 12:54am');
$time = Time::parseDateTime('13 Oct, 2013 13:54', 'dd MMM, y H:mm');
$time = Time::parseDateTime('10/10/2015', [IntlDateFormatter::SHORT, -1]);
```
@param string $time The time string to parse.
@param string|array|null $format Any format accepted by IntlDateFormatter.
@return static|null | [
"Returns",
"a",
"new",
"Time",
"object",
"after",
"parsing",
"the",
"provided",
"time",
"string",
"based",
"on",
"the",
"passed",
"or",
"configured",
"date",
"time",
"format",
".",
"This",
"method",
"is",
"locale",
"dependent",
"Any",
"string",
"that",
"is",
"passed",
"to",
"this",
"function",
"will",
"be",
"interpreted",
"as",
"a",
"locale",
"dependent",
"string",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/I18n/DateFormatTrait.php#L305-L341 |
211,077 | cakephp/cakephp | src/Database/Schema/Collection.php | Collection.listTables | public function listTables()
{
list($sql, $params) = $this->_dialect->listTablesSql($this->_connection->config());
$result = [];
$statement = $this->_connection->execute($sql, $params);
while ($row = $statement->fetch()) {
$result[] = $row[0];
}
$statement->closeCursor();
return $result;
} | php | public function listTables()
{
list($sql, $params) = $this->_dialect->listTablesSql($this->_connection->config());
$result = [];
$statement = $this->_connection->execute($sql, $params);
while ($row = $statement->fetch()) {
$result[] = $row[0];
}
$statement->closeCursor();
return $result;
} | [
"public",
"function",
"listTables",
"(",
")",
"{",
"list",
"(",
"$",
"sql",
",",
"$",
"params",
")",
"=",
"$",
"this",
"->",
"_dialect",
"->",
"listTablesSql",
"(",
"$",
"this",
"->",
"_connection",
"->",
"config",
"(",
")",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"statement",
"=",
"$",
"this",
"->",
"_connection",
"->",
"execute",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"statement",
"->",
"fetch",
"(",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"row",
"[",
"0",
"]",
";",
"}",
"$",
"statement",
"->",
"closeCursor",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Get the list of tables available in the current connection.
@return array The list of tables in the connected database/schema. | [
"Get",
"the",
"list",
"of",
"tables",
"available",
"in",
"the",
"current",
"connection",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Schema/Collection.php#L60-L71 |
211,078 | cakephp/cakephp | src/Database/Schema/Collection.php | Collection.describe | public function describe($name, array $options = [])
{
$config = $this->_connection->config();
if (strpos($name, '.')) {
list($config['schema'], $name) = explode('.', $name);
}
$table = new TableSchema($name);
$this->_reflect('Column', $name, $config, $table);
if (count($table->columns()) === 0) {
throw new Exception(sprintf('Cannot describe %s. It has 0 columns.', $name));
}
$this->_reflect('Index', $name, $config, $table);
$this->_reflect('ForeignKey', $name, $config, $table);
$this->_reflect('Options', $name, $config, $table);
return $table;
} | php | public function describe($name, array $options = [])
{
$config = $this->_connection->config();
if (strpos($name, '.')) {
list($config['schema'], $name) = explode('.', $name);
}
$table = new TableSchema($name);
$this->_reflect('Column', $name, $config, $table);
if (count($table->columns()) === 0) {
throw new Exception(sprintf('Cannot describe %s. It has 0 columns.', $name));
}
$this->_reflect('Index', $name, $config, $table);
$this->_reflect('ForeignKey', $name, $config, $table);
$this->_reflect('Options', $name, $config, $table);
return $table;
} | [
"public",
"function",
"describe",
"(",
"$",
"name",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"_connection",
"->",
"config",
"(",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"name",
",",
"'.'",
")",
")",
"{",
"list",
"(",
"$",
"config",
"[",
"'schema'",
"]",
",",
"$",
"name",
")",
"=",
"explode",
"(",
"'.'",
",",
"$",
"name",
")",
";",
"}",
"$",
"table",
"=",
"new",
"TableSchema",
"(",
"$",
"name",
")",
";",
"$",
"this",
"->",
"_reflect",
"(",
"'Column'",
",",
"$",
"name",
",",
"$",
"config",
",",
"$",
"table",
")",
";",
"if",
"(",
"count",
"(",
"$",
"table",
"->",
"columns",
"(",
")",
")",
"===",
"0",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'Cannot describe %s. It has 0 columns.'",
",",
"$",
"name",
")",
")",
";",
"}",
"$",
"this",
"->",
"_reflect",
"(",
"'Index'",
",",
"$",
"name",
",",
"$",
"config",
",",
"$",
"table",
")",
";",
"$",
"this",
"->",
"_reflect",
"(",
"'ForeignKey'",
",",
"$",
"name",
",",
"$",
"config",
",",
"$",
"table",
")",
";",
"$",
"this",
"->",
"_reflect",
"(",
"'Options'",
",",
"$",
"name",
",",
"$",
"config",
",",
"$",
"table",
")",
";",
"return",
"$",
"table",
";",
"}"
] | Get the column metadata for a table.
Caching will be applied if `cacheMetadata` key is present in the Connection
configuration options. Defaults to _cake_model_ when true.
### Options
- `forceRefresh` - Set to true to force rebuilding the cached metadata.
Defaults to false.
@param string $name The name of the table to describe.
@param array $options The options to use, see above.
@return \Cake\Database\Schema\TableSchema Object with column metadata.
@throws \Cake\Database\Exception when table cannot be described. | [
"Get",
"the",
"column",
"metadata",
"for",
"a",
"table",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Schema/Collection.php#L89-L107 |
211,079 | cakephp/cakephp | src/Database/Schema/Collection.php | Collection._reflect | protected function _reflect($stage, $name, $config, $schema)
{
$describeMethod = "describe{$stage}Sql";
$convertMethod = "convert{$stage}Description";
list($sql, $params) = $this->_dialect->{$describeMethod}($name, $config);
if (empty($sql)) {
return;
}
try {
$statement = $this->_connection->execute($sql, $params);
} catch (PDOException $e) {
throw new Exception($e->getMessage(), 500, $e);
}
foreach ($statement->fetchAll('assoc') as $row) {
$this->_dialect->{$convertMethod}($schema, $row);
}
$statement->closeCursor();
} | php | protected function _reflect($stage, $name, $config, $schema)
{
$describeMethod = "describe{$stage}Sql";
$convertMethod = "convert{$stage}Description";
list($sql, $params) = $this->_dialect->{$describeMethod}($name, $config);
if (empty($sql)) {
return;
}
try {
$statement = $this->_connection->execute($sql, $params);
} catch (PDOException $e) {
throw new Exception($e->getMessage(), 500, $e);
}
foreach ($statement->fetchAll('assoc') as $row) {
$this->_dialect->{$convertMethod}($schema, $row);
}
$statement->closeCursor();
} | [
"protected",
"function",
"_reflect",
"(",
"$",
"stage",
",",
"$",
"name",
",",
"$",
"config",
",",
"$",
"schema",
")",
"{",
"$",
"describeMethod",
"=",
"\"describe{$stage}Sql\"",
";",
"$",
"convertMethod",
"=",
"\"convert{$stage}Description\"",
";",
"list",
"(",
"$",
"sql",
",",
"$",
"params",
")",
"=",
"$",
"this",
"->",
"_dialect",
"->",
"{",
"$",
"describeMethod",
"}",
"(",
"$",
"name",
",",
"$",
"config",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"sql",
")",
")",
"{",
"return",
";",
"}",
"try",
"{",
"$",
"statement",
"=",
"$",
"this",
"->",
"_connection",
"->",
"execute",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}",
"catch",
"(",
"PDOException",
"$",
"e",
")",
"{",
"throw",
"new",
"Exception",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"500",
",",
"$",
"e",
")",
";",
"}",
"foreach",
"(",
"$",
"statement",
"->",
"fetchAll",
"(",
"'assoc'",
")",
"as",
"$",
"row",
")",
"{",
"$",
"this",
"->",
"_dialect",
"->",
"{",
"$",
"convertMethod",
"}",
"(",
"$",
"schema",
",",
"$",
"row",
")",
";",
"}",
"$",
"statement",
"->",
"closeCursor",
"(",
")",
";",
"}"
] | Helper method for running each step of the reflection process.
@param string $stage The stage name.
@param string $name The table name.
@param array $config The config data.
@param \Cake\Database\Schema\TableSchema $schema The table instance
@return void
@throws \Cake\Database\Exception on query failure. | [
"Helper",
"method",
"for",
"running",
"each",
"step",
"of",
"the",
"reflection",
"process",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/Schema/Collection.php#L119-L137 |
211,080 | cakephp/cakephp | src/Database/TypeMapTrait.php | TypeMapTrait.defaultTypes | public function defaultTypes(array $types = null)
{
deprecationWarning(
'TypeMapTrait::defaultTypes() is deprecated. ' .
'Use TypeMapTrait::setDefaultTypes()/getDefaultTypes() instead.'
);
if ($types !== null) {
return $this->setDefaultTypes($types);
}
return $this->getDefaultTypes();
} | php | public function defaultTypes(array $types = null)
{
deprecationWarning(
'TypeMapTrait::defaultTypes() is deprecated. ' .
'Use TypeMapTrait::setDefaultTypes()/getDefaultTypes() instead.'
);
if ($types !== null) {
return $this->setDefaultTypes($types);
}
return $this->getDefaultTypes();
} | [
"public",
"function",
"defaultTypes",
"(",
"array",
"$",
"types",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"'TypeMapTrait::defaultTypes() is deprecated. '",
".",
"'Use TypeMapTrait::setDefaultTypes()/getDefaultTypes() instead.'",
")",
";",
"if",
"(",
"$",
"types",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"setDefaultTypes",
"(",
"$",
"types",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getDefaultTypes",
"(",
")",
";",
"}"
] | Allows setting default types when chaining query
@deprecated 3.4.0 Use setDefaultTypes()/getDefaultTypes() instead.
@param array|null $types The array of types to set.
@return $this|array | [
"Allows",
"setting",
"default",
"types",
"when",
"chaining",
"query"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Database/TypeMapTrait.php#L109-L120 |
211,081 | cakephp/cakephp | src/View/HelperRegistry.php | HelperRegistry.__isset | public function __isset($helper)
{
if (isset($this->_loaded[$helper])) {
return true;
}
try {
$this->load($helper);
} catch (Exception\MissingHelperException $exception) {
if ($this->_View->getPlugin()) {
$this->load($this->_View->getPlugin() . '.' . $helper);
return true;
}
}
if (!empty($exception)) {
throw $exception;
}
return true;
} | php | public function __isset($helper)
{
if (isset($this->_loaded[$helper])) {
return true;
}
try {
$this->load($helper);
} catch (Exception\MissingHelperException $exception) {
if ($this->_View->getPlugin()) {
$this->load($this->_View->getPlugin() . '.' . $helper);
return true;
}
}
if (!empty($exception)) {
throw $exception;
}
return true;
} | [
"public",
"function",
"__isset",
"(",
"$",
"helper",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_loaded",
"[",
"$",
"helper",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"load",
"(",
"$",
"helper",
")",
";",
"}",
"catch",
"(",
"Exception",
"\\",
"MissingHelperException",
"$",
"exception",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_View",
"->",
"getPlugin",
"(",
")",
")",
"{",
"$",
"this",
"->",
"load",
"(",
"$",
"this",
"->",
"_View",
"->",
"getPlugin",
"(",
")",
".",
"'.'",
".",
"$",
"helper",
")",
";",
"return",
"true",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"exception",
")",
")",
"{",
"throw",
"$",
"exception",
";",
"}",
"return",
"true",
";",
"}"
] | Tries to lazy load a helper based on its name, if it cannot be found
in the application folder, then it tries looking under the current plugin
if any
@param string $helper The helper name to be loaded
@return bool whether the helper could be loaded or not
@throws \Cake\View\Exception\MissingHelperException When a helper could not be found.
App helpers are searched, and then plugin helpers. | [
"Tries",
"to",
"lazy",
"load",
"a",
"helper",
"based",
"on",
"its",
"name",
"if",
"it",
"cannot",
"be",
"found",
"in",
"the",
"application",
"folder",
"then",
"it",
"tries",
"looking",
"under",
"the",
"current",
"plugin",
"if",
"any"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/HelperRegistry.php#L60-L81 |
211,082 | cakephp/cakephp | src/View/HelperRegistry.php | HelperRegistry._create | protected function _create($class, $alias, $settings)
{
$instance = new $class($this->_View, $settings);
$enable = isset($settings['enabled']) ? $settings['enabled'] : true;
if ($enable) {
$this->getEventManager()->on($instance);
}
return $instance;
} | php | protected function _create($class, $alias, $settings)
{
$instance = new $class($this->_View, $settings);
$enable = isset($settings['enabled']) ? $settings['enabled'] : true;
if ($enable) {
$this->getEventManager()->on($instance);
}
return $instance;
} | [
"protected",
"function",
"_create",
"(",
"$",
"class",
",",
"$",
"alias",
",",
"$",
"settings",
")",
"{",
"$",
"instance",
"=",
"new",
"$",
"class",
"(",
"$",
"this",
"->",
"_View",
",",
"$",
"settings",
")",
";",
"$",
"enable",
"=",
"isset",
"(",
"$",
"settings",
"[",
"'enabled'",
"]",
")",
"?",
"$",
"settings",
"[",
"'enabled'",
"]",
":",
"true",
";",
"if",
"(",
"$",
"enable",
")",
"{",
"$",
"this",
"->",
"getEventManager",
"(",
")",
"->",
"on",
"(",
"$",
"instance",
")",
";",
"}",
"return",
"$",
"instance",
";",
"}"
] | Create the helper instance.
Part of the template method for Cake\Core\ObjectRegistry::load()
Enabled helpers will be registered with the event manager.
@param string $class The class to create.
@param string $alias The alias of the loaded helper.
@param array $settings An array of settings to use for the helper.
@return \Cake\View\Helper The constructed helper class. | [
"Create",
"the",
"helper",
"instance",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/View/HelperRegistry.php#L144-L154 |
211,083 | cakephp/cakephp | src/Shell/Task/ExtractTask.php | ExtractTask._getPaths | protected function _getPaths()
{
$defaultPath = APP;
while (true) {
$currentPaths = count($this->_paths) > 0 ? $this->_paths : ['None'];
$message = sprintf(
"Current paths: %s\nWhat is the path you would like to extract?\n[Q]uit [D]one",
implode(', ', $currentPaths)
);
$response = $this->in($message, null, $defaultPath);
if (strtoupper($response) === 'Q') {
$this->err('Extract Aborted');
$this->_stop();
return;
}
if (strtoupper($response) === 'D' && count($this->_paths)) {
$this->out();
return;
}
if (strtoupper($response) === 'D') {
$this->warn('No directories selected. Please choose a directory.');
} elseif (is_dir($response)) {
$this->_paths[] = $response;
$defaultPath = 'D';
} else {
$this->err('The directory path you supplied was not found. Please try again.');
}
$this->out();
}
} | php | protected function _getPaths()
{
$defaultPath = APP;
while (true) {
$currentPaths = count($this->_paths) > 0 ? $this->_paths : ['None'];
$message = sprintf(
"Current paths: %s\nWhat is the path you would like to extract?\n[Q]uit [D]one",
implode(', ', $currentPaths)
);
$response = $this->in($message, null, $defaultPath);
if (strtoupper($response) === 'Q') {
$this->err('Extract Aborted');
$this->_stop();
return;
}
if (strtoupper($response) === 'D' && count($this->_paths)) {
$this->out();
return;
}
if (strtoupper($response) === 'D') {
$this->warn('No directories selected. Please choose a directory.');
} elseif (is_dir($response)) {
$this->_paths[] = $response;
$defaultPath = 'D';
} else {
$this->err('The directory path you supplied was not found. Please try again.');
}
$this->out();
}
} | [
"protected",
"function",
"_getPaths",
"(",
")",
"{",
"$",
"defaultPath",
"=",
"APP",
";",
"while",
"(",
"true",
")",
"{",
"$",
"currentPaths",
"=",
"count",
"(",
"$",
"this",
"->",
"_paths",
")",
">",
"0",
"?",
"$",
"this",
"->",
"_paths",
":",
"[",
"'None'",
"]",
";",
"$",
"message",
"=",
"sprintf",
"(",
"\"Current paths: %s\\nWhat is the path you would like to extract?\\n[Q]uit [D]one\"",
",",
"implode",
"(",
"', '",
",",
"$",
"currentPaths",
")",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"in",
"(",
"$",
"message",
",",
"null",
",",
"$",
"defaultPath",
")",
";",
"if",
"(",
"strtoupper",
"(",
"$",
"response",
")",
"===",
"'Q'",
")",
"{",
"$",
"this",
"->",
"err",
"(",
"'Extract Aborted'",
")",
";",
"$",
"this",
"->",
"_stop",
"(",
")",
";",
"return",
";",
"}",
"if",
"(",
"strtoupper",
"(",
"$",
"response",
")",
"===",
"'D'",
"&&",
"count",
"(",
"$",
"this",
"->",
"_paths",
")",
")",
"{",
"$",
"this",
"->",
"out",
"(",
")",
";",
"return",
";",
"}",
"if",
"(",
"strtoupper",
"(",
"$",
"response",
")",
"===",
"'D'",
")",
"{",
"$",
"this",
"->",
"warn",
"(",
"'No directories selected. Please choose a directory.'",
")",
";",
"}",
"elseif",
"(",
"is_dir",
"(",
"$",
"response",
")",
")",
"{",
"$",
"this",
"->",
"_paths",
"[",
"]",
"=",
"$",
"response",
";",
"$",
"defaultPath",
"=",
"'D'",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"err",
"(",
"'The directory path you supplied was not found. Please try again.'",
")",
";",
"}",
"$",
"this",
"->",
"out",
"(",
")",
";",
"}",
"}"
] | Method to interact with the User and get path selections.
@return void | [
"Method",
"to",
"interact",
"with",
"the",
"User",
"and",
"get",
"path",
"selections",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Task/ExtractTask.php#L141-L172 |
211,084 | cakephp/cakephp | src/Shell/Task/ExtractTask.php | ExtractTask._addTranslation | protected function _addTranslation($domain, $msgid, $details = [])
{
$context = isset($details['msgctxt']) ? $details['msgctxt'] : '';
if (empty($this->_translations[$domain][$msgid][$context])) {
$this->_translations[$domain][$msgid][$context] = [
'msgid_plural' => false
];
}
if (isset($details['msgid_plural'])) {
$this->_translations[$domain][$msgid][$context]['msgid_plural'] = $details['msgid_plural'];
}
if (isset($details['file'])) {
$line = isset($details['line']) ? $details['line'] : 0;
$this->_translations[$domain][$msgid][$context]['references'][$details['file']][] = $line;
}
} | php | protected function _addTranslation($domain, $msgid, $details = [])
{
$context = isset($details['msgctxt']) ? $details['msgctxt'] : '';
if (empty($this->_translations[$domain][$msgid][$context])) {
$this->_translations[$domain][$msgid][$context] = [
'msgid_plural' => false
];
}
if (isset($details['msgid_plural'])) {
$this->_translations[$domain][$msgid][$context]['msgid_plural'] = $details['msgid_plural'];
}
if (isset($details['file'])) {
$line = isset($details['line']) ? $details['line'] : 0;
$this->_translations[$domain][$msgid][$context]['references'][$details['file']][] = $line;
}
} | [
"protected",
"function",
"_addTranslation",
"(",
"$",
"domain",
",",
"$",
"msgid",
",",
"$",
"details",
"=",
"[",
"]",
")",
"{",
"$",
"context",
"=",
"isset",
"(",
"$",
"details",
"[",
"'msgctxt'",
"]",
")",
"?",
"$",
"details",
"[",
"'msgctxt'",
"]",
":",
"''",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_translations",
"[",
"$",
"domain",
"]",
"[",
"$",
"msgid",
"]",
"[",
"$",
"context",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_translations",
"[",
"$",
"domain",
"]",
"[",
"$",
"msgid",
"]",
"[",
"$",
"context",
"]",
"=",
"[",
"'msgid_plural'",
"=>",
"false",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"details",
"[",
"'msgid_plural'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_translations",
"[",
"$",
"domain",
"]",
"[",
"$",
"msgid",
"]",
"[",
"$",
"context",
"]",
"[",
"'msgid_plural'",
"]",
"=",
"$",
"details",
"[",
"'msgid_plural'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"details",
"[",
"'file'",
"]",
")",
")",
"{",
"$",
"line",
"=",
"isset",
"(",
"$",
"details",
"[",
"'line'",
"]",
")",
"?",
"$",
"details",
"[",
"'line'",
"]",
":",
"0",
";",
"$",
"this",
"->",
"_translations",
"[",
"$",
"domain",
"]",
"[",
"$",
"msgid",
"]",
"[",
"$",
"context",
"]",
"[",
"'references'",
"]",
"[",
"$",
"details",
"[",
"'file'",
"]",
"]",
"[",
"]",
"=",
"$",
"line",
";",
"}",
"}"
] | Add a translation to the internal translations property
Takes care of duplicate translations
@param string $domain The domain
@param string $msgid The message string
@param array $details Context and plural form if any, file and line references
@return void | [
"Add",
"a",
"translation",
"to",
"the",
"internal",
"translations",
"property"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Task/ExtractTask.php#L283-L301 |
211,085 | cakephp/cakephp | src/Shell/Task/ExtractTask.php | ExtractTask._extractTokens | protected function _extractTokens()
{
/** @var \Cake\Shell\Helper\ProgressHelper $progress */
$progress = $this->helper('progress');
$progress->init(['total' => count($this->_files)]);
$isVerbose = $this->param('verbose');
$functions = [
'__' => ['singular'],
'__n' => ['singular', 'plural'],
'__d' => ['domain', 'singular'],
'__dn' => ['domain', 'singular', 'plural'],
'__x' => ['context', 'singular'],
'__xn' => ['context', 'singular', 'plural'],
'__dx' => ['domain', 'context', 'singular'],
'__dxn' => ['domain', 'context', 'singular', 'plural'],
];
$pattern = '/(' . implode('|', array_keys($functions)) . ')\s*\(/';
foreach ($this->_files as $file) {
$this->_file = $file;
if ($isVerbose) {
$this->out(sprintf('Processing %s...', $file), 1, Shell::VERBOSE);
}
$code = file_get_contents($file);
if (preg_match($pattern, $code) === 1) {
$allTokens = token_get_all($code);
$this->_tokens = [];
foreach ($allTokens as $token) {
if (!is_array($token) || ($token[0] !== T_WHITESPACE && $token[0] !== T_INLINE_HTML)) {
$this->_tokens[] = $token;
}
}
unset($allTokens);
foreach ($functions as $functionName => $map) {
$this->_parse($functionName, $map);
}
}
if (!$isVerbose) {
$progress->increment(1);
$progress->draw();
}
}
} | php | protected function _extractTokens()
{
/** @var \Cake\Shell\Helper\ProgressHelper $progress */
$progress = $this->helper('progress');
$progress->init(['total' => count($this->_files)]);
$isVerbose = $this->param('verbose');
$functions = [
'__' => ['singular'],
'__n' => ['singular', 'plural'],
'__d' => ['domain', 'singular'],
'__dn' => ['domain', 'singular', 'plural'],
'__x' => ['context', 'singular'],
'__xn' => ['context', 'singular', 'plural'],
'__dx' => ['domain', 'context', 'singular'],
'__dxn' => ['domain', 'context', 'singular', 'plural'],
];
$pattern = '/(' . implode('|', array_keys($functions)) . ')\s*\(/';
foreach ($this->_files as $file) {
$this->_file = $file;
if ($isVerbose) {
$this->out(sprintf('Processing %s...', $file), 1, Shell::VERBOSE);
}
$code = file_get_contents($file);
if (preg_match($pattern, $code) === 1) {
$allTokens = token_get_all($code);
$this->_tokens = [];
foreach ($allTokens as $token) {
if (!is_array($token) || ($token[0] !== T_WHITESPACE && $token[0] !== T_INLINE_HTML)) {
$this->_tokens[] = $token;
}
}
unset($allTokens);
foreach ($functions as $functionName => $map) {
$this->_parse($functionName, $map);
}
}
if (!$isVerbose) {
$progress->increment(1);
$progress->draw();
}
}
} | [
"protected",
"function",
"_extractTokens",
"(",
")",
"{",
"/** @var \\Cake\\Shell\\Helper\\ProgressHelper $progress */",
"$",
"progress",
"=",
"$",
"this",
"->",
"helper",
"(",
"'progress'",
")",
";",
"$",
"progress",
"->",
"init",
"(",
"[",
"'total'",
"=>",
"count",
"(",
"$",
"this",
"->",
"_files",
")",
"]",
")",
";",
"$",
"isVerbose",
"=",
"$",
"this",
"->",
"param",
"(",
"'verbose'",
")",
";",
"$",
"functions",
"=",
"[",
"'__'",
"=>",
"[",
"'singular'",
"]",
",",
"'__n'",
"=>",
"[",
"'singular'",
",",
"'plural'",
"]",
",",
"'__d'",
"=>",
"[",
"'domain'",
",",
"'singular'",
"]",
",",
"'__dn'",
"=>",
"[",
"'domain'",
",",
"'singular'",
",",
"'plural'",
"]",
",",
"'__x'",
"=>",
"[",
"'context'",
",",
"'singular'",
"]",
",",
"'__xn'",
"=>",
"[",
"'context'",
",",
"'singular'",
",",
"'plural'",
"]",
",",
"'__dx'",
"=>",
"[",
"'domain'",
",",
"'context'",
",",
"'singular'",
"]",
",",
"'__dxn'",
"=>",
"[",
"'domain'",
",",
"'context'",
",",
"'singular'",
",",
"'plural'",
"]",
",",
"]",
";",
"$",
"pattern",
"=",
"'/('",
".",
"implode",
"(",
"'|'",
",",
"array_keys",
"(",
"$",
"functions",
")",
")",
".",
"')\\s*\\(/'",
";",
"foreach",
"(",
"$",
"this",
"->",
"_files",
"as",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"_file",
"=",
"$",
"file",
";",
"if",
"(",
"$",
"isVerbose",
")",
"{",
"$",
"this",
"->",
"out",
"(",
"sprintf",
"(",
"'Processing %s...'",
",",
"$",
"file",
")",
",",
"1",
",",
"Shell",
"::",
"VERBOSE",
")",
";",
"}",
"$",
"code",
"=",
"file_get_contents",
"(",
"$",
"file",
")",
";",
"if",
"(",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"code",
")",
"===",
"1",
")",
"{",
"$",
"allTokens",
"=",
"token_get_all",
"(",
"$",
"code",
")",
";",
"$",
"this",
"->",
"_tokens",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"allTokens",
"as",
"$",
"token",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"token",
")",
"||",
"(",
"$",
"token",
"[",
"0",
"]",
"!==",
"T_WHITESPACE",
"&&",
"$",
"token",
"[",
"0",
"]",
"!==",
"T_INLINE_HTML",
")",
")",
"{",
"$",
"this",
"->",
"_tokens",
"[",
"]",
"=",
"$",
"token",
";",
"}",
"}",
"unset",
"(",
"$",
"allTokens",
")",
";",
"foreach",
"(",
"$",
"functions",
"as",
"$",
"functionName",
"=>",
"$",
"map",
")",
"{",
"$",
"this",
"->",
"_parse",
"(",
"$",
"functionName",
",",
"$",
"map",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"isVerbose",
")",
"{",
"$",
"progress",
"->",
"increment",
"(",
"1",
")",
";",
"$",
"progress",
"->",
"draw",
"(",
")",
";",
"}",
"}",
"}"
] | Extract tokens out of all files to be processed
@return void | [
"Extract",
"tokens",
"out",
"of",
"all",
"files",
"to",
"be",
"processed"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Task/ExtractTask.php#L401-L449 |
211,086 | cakephp/cakephp | src/Shell/Task/ExtractTask.php | ExtractTask._buildFiles | protected function _buildFiles()
{
$paths = $this->_paths;
$paths[] = realpath(APP) . DIRECTORY_SEPARATOR;
usort($paths, function ($a, $b) {
return strlen($a) - strlen($b);
});
foreach ($this->_translations as $domain => $translations) {
foreach ($translations as $msgid => $contexts) {
foreach ($contexts as $context => $details) {
$plural = $details['msgid_plural'];
$files = $details['references'];
$occurrences = [];
foreach ($files as $file => $lines) {
$lines = array_unique($lines);
$occurrences[] = $file . ':' . implode(';', $lines);
}
$occurrences = implode("\n#: ", $occurrences);
$header = '';
if (!$this->param('no-location')) {
$header = '#: ' . str_replace(DIRECTORY_SEPARATOR, '/', str_replace($paths, '', $occurrences)) . "\n";
}
$sentence = '';
if ($context !== '') {
$sentence .= "msgctxt \"{$context}\"\n";
}
if ($plural === false) {
$sentence .= "msgid \"{$msgid}\"\n";
$sentence .= "msgstr \"\"\n\n";
} else {
$sentence .= "msgid \"{$msgid}\"\n";
$sentence .= "msgid_plural \"{$plural}\"\n";
$sentence .= "msgstr[0] \"\"\n";
$sentence .= "msgstr[1] \"\"\n\n";
}
if ($domain !== 'default' && $this->_merge) {
$this->_store('default', $header, $sentence);
} else {
$this->_store($domain, $header, $sentence);
}
}
}
}
} | php | protected function _buildFiles()
{
$paths = $this->_paths;
$paths[] = realpath(APP) . DIRECTORY_SEPARATOR;
usort($paths, function ($a, $b) {
return strlen($a) - strlen($b);
});
foreach ($this->_translations as $domain => $translations) {
foreach ($translations as $msgid => $contexts) {
foreach ($contexts as $context => $details) {
$plural = $details['msgid_plural'];
$files = $details['references'];
$occurrences = [];
foreach ($files as $file => $lines) {
$lines = array_unique($lines);
$occurrences[] = $file . ':' . implode(';', $lines);
}
$occurrences = implode("\n#: ", $occurrences);
$header = '';
if (!$this->param('no-location')) {
$header = '#: ' . str_replace(DIRECTORY_SEPARATOR, '/', str_replace($paths, '', $occurrences)) . "\n";
}
$sentence = '';
if ($context !== '') {
$sentence .= "msgctxt \"{$context}\"\n";
}
if ($plural === false) {
$sentence .= "msgid \"{$msgid}\"\n";
$sentence .= "msgstr \"\"\n\n";
} else {
$sentence .= "msgid \"{$msgid}\"\n";
$sentence .= "msgid_plural \"{$plural}\"\n";
$sentence .= "msgstr[0] \"\"\n";
$sentence .= "msgstr[1] \"\"\n\n";
}
if ($domain !== 'default' && $this->_merge) {
$this->_store('default', $header, $sentence);
} else {
$this->_store($domain, $header, $sentence);
}
}
}
}
} | [
"protected",
"function",
"_buildFiles",
"(",
")",
"{",
"$",
"paths",
"=",
"$",
"this",
"->",
"_paths",
";",
"$",
"paths",
"[",
"]",
"=",
"realpath",
"(",
"APP",
")",
".",
"DIRECTORY_SEPARATOR",
";",
"usort",
"(",
"$",
"paths",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"return",
"strlen",
"(",
"$",
"a",
")",
"-",
"strlen",
"(",
"$",
"b",
")",
";",
"}",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"_translations",
"as",
"$",
"domain",
"=>",
"$",
"translations",
")",
"{",
"foreach",
"(",
"$",
"translations",
"as",
"$",
"msgid",
"=>",
"$",
"contexts",
")",
"{",
"foreach",
"(",
"$",
"contexts",
"as",
"$",
"context",
"=>",
"$",
"details",
")",
"{",
"$",
"plural",
"=",
"$",
"details",
"[",
"'msgid_plural'",
"]",
";",
"$",
"files",
"=",
"$",
"details",
"[",
"'references'",
"]",
";",
"$",
"occurrences",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
"=>",
"$",
"lines",
")",
"{",
"$",
"lines",
"=",
"array_unique",
"(",
"$",
"lines",
")",
";",
"$",
"occurrences",
"[",
"]",
"=",
"$",
"file",
".",
"':'",
".",
"implode",
"(",
"';'",
",",
"$",
"lines",
")",
";",
"}",
"$",
"occurrences",
"=",
"implode",
"(",
"\"\\n#: \"",
",",
"$",
"occurrences",
")",
";",
"$",
"header",
"=",
"''",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"param",
"(",
"'no-location'",
")",
")",
"{",
"$",
"header",
"=",
"'#: '",
".",
"str_replace",
"(",
"DIRECTORY_SEPARATOR",
",",
"'/'",
",",
"str_replace",
"(",
"$",
"paths",
",",
"''",
",",
"$",
"occurrences",
")",
")",
".",
"\"\\n\"",
";",
"}",
"$",
"sentence",
"=",
"''",
";",
"if",
"(",
"$",
"context",
"!==",
"''",
")",
"{",
"$",
"sentence",
".=",
"\"msgctxt \\\"{$context}\\\"\\n\"",
";",
"}",
"if",
"(",
"$",
"plural",
"===",
"false",
")",
"{",
"$",
"sentence",
".=",
"\"msgid \\\"{$msgid}\\\"\\n\"",
";",
"$",
"sentence",
".=",
"\"msgstr \\\"\\\"\\n\\n\"",
";",
"}",
"else",
"{",
"$",
"sentence",
".=",
"\"msgid \\\"{$msgid}\\\"\\n\"",
";",
"$",
"sentence",
".=",
"\"msgid_plural \\\"{$plural}\\\"\\n\"",
";",
"$",
"sentence",
".=",
"\"msgstr[0] \\\"\\\"\\n\"",
";",
"$",
"sentence",
".=",
"\"msgstr[1] \\\"\\\"\\n\\n\"",
";",
"}",
"if",
"(",
"$",
"domain",
"!==",
"'default'",
"&&",
"$",
"this",
"->",
"_merge",
")",
"{",
"$",
"this",
"->",
"_store",
"(",
"'default'",
",",
"$",
"header",
",",
"$",
"sentence",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_store",
"(",
"$",
"domain",
",",
"$",
"header",
",",
"$",
"sentence",
")",
";",
"}",
"}",
"}",
"}",
"}"
] | Build the translate template file contents out of obtained strings
@return void | [
"Build",
"the",
"translate",
"template",
"file",
"contents",
"out",
"of",
"obtained",
"strings"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Task/ExtractTask.php#L524-L571 |
211,087 | cakephp/cakephp | src/Shell/Task/ExtractTask.php | ExtractTask._store | protected function _store($domain, $header, $sentence)
{
if (!isset($this->_storage[$domain])) {
$this->_storage[$domain] = [];
}
if (!isset($this->_storage[$domain][$sentence])) {
$this->_storage[$domain][$sentence] = $header;
} else {
$this->_storage[$domain][$sentence] .= $header;
}
} | php | protected function _store($domain, $header, $sentence)
{
if (!isset($this->_storage[$domain])) {
$this->_storage[$domain] = [];
}
if (!isset($this->_storage[$domain][$sentence])) {
$this->_storage[$domain][$sentence] = $header;
} else {
$this->_storage[$domain][$sentence] .= $header;
}
} | [
"protected",
"function",
"_store",
"(",
"$",
"domain",
",",
"$",
"header",
",",
"$",
"sentence",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_storage",
"[",
"$",
"domain",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_storage",
"[",
"$",
"domain",
"]",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_storage",
"[",
"$",
"domain",
"]",
"[",
"$",
"sentence",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_storage",
"[",
"$",
"domain",
"]",
"[",
"$",
"sentence",
"]",
"=",
"$",
"header",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_storage",
"[",
"$",
"domain",
"]",
"[",
"$",
"sentence",
"]",
".=",
"$",
"header",
";",
"}",
"}"
] | Prepare a file to be stored
@param string $domain The domain
@param string $header The header content.
@param string $sentence The sentence to store.
@return void | [
"Prepare",
"a",
"file",
"to",
"be",
"stored"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Task/ExtractTask.php#L581-L591 |
211,088 | cakephp/cakephp | src/Shell/Task/ExtractTask.php | ExtractTask._writeFiles | protected function _writeFiles()
{
$overwriteAll = false;
if (!empty($this->params['overwrite'])) {
$overwriteAll = true;
}
foreach ($this->_storage as $domain => $sentences) {
$output = $this->_writeHeader();
foreach ($sentences as $sentence => $header) {
$output .= $header . $sentence;
}
// Remove vendor prefix if present.
$slashPosition = strpos($domain, '/');
if ($slashPosition !== false) {
$domain = substr($domain, $slashPosition + 1);
}
$filename = str_replace('/', '_', $domain) . '.pot';
$File = new File($this->_output . $filename);
$response = '';
while ($overwriteAll === false && $File->exists() && strtoupper($response) !== 'Y') {
$this->out();
$response = $this->in(
sprintf('Error: %s already exists in this location. Overwrite? [Y]es, [N]o, [A]ll', $filename),
['y', 'n', 'a'],
'y'
);
if (strtoupper($response) === 'N') {
$response = '';
while (!$response) {
$response = $this->in('What would you like to name this file?', null, 'new_' . $filename);
$File = new File($this->_output . $response);
$filename = $response;
}
} elseif (strtoupper($response) === 'A') {
$overwriteAll = true;
}
}
$File->write($output);
$File->close();
}
} | php | protected function _writeFiles()
{
$overwriteAll = false;
if (!empty($this->params['overwrite'])) {
$overwriteAll = true;
}
foreach ($this->_storage as $domain => $sentences) {
$output = $this->_writeHeader();
foreach ($sentences as $sentence => $header) {
$output .= $header . $sentence;
}
// Remove vendor prefix if present.
$slashPosition = strpos($domain, '/');
if ($slashPosition !== false) {
$domain = substr($domain, $slashPosition + 1);
}
$filename = str_replace('/', '_', $domain) . '.pot';
$File = new File($this->_output . $filename);
$response = '';
while ($overwriteAll === false && $File->exists() && strtoupper($response) !== 'Y') {
$this->out();
$response = $this->in(
sprintf('Error: %s already exists in this location. Overwrite? [Y]es, [N]o, [A]ll', $filename),
['y', 'n', 'a'],
'y'
);
if (strtoupper($response) === 'N') {
$response = '';
while (!$response) {
$response = $this->in('What would you like to name this file?', null, 'new_' . $filename);
$File = new File($this->_output . $response);
$filename = $response;
}
} elseif (strtoupper($response) === 'A') {
$overwriteAll = true;
}
}
$File->write($output);
$File->close();
}
} | [
"protected",
"function",
"_writeFiles",
"(",
")",
"{",
"$",
"overwriteAll",
"=",
"false",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"params",
"[",
"'overwrite'",
"]",
")",
")",
"{",
"$",
"overwriteAll",
"=",
"true",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"_storage",
"as",
"$",
"domain",
"=>",
"$",
"sentences",
")",
"{",
"$",
"output",
"=",
"$",
"this",
"->",
"_writeHeader",
"(",
")",
";",
"foreach",
"(",
"$",
"sentences",
"as",
"$",
"sentence",
"=>",
"$",
"header",
")",
"{",
"$",
"output",
".=",
"$",
"header",
".",
"$",
"sentence",
";",
"}",
"// Remove vendor prefix if present.",
"$",
"slashPosition",
"=",
"strpos",
"(",
"$",
"domain",
",",
"'/'",
")",
";",
"if",
"(",
"$",
"slashPosition",
"!==",
"false",
")",
"{",
"$",
"domain",
"=",
"substr",
"(",
"$",
"domain",
",",
"$",
"slashPosition",
"+",
"1",
")",
";",
"}",
"$",
"filename",
"=",
"str_replace",
"(",
"'/'",
",",
"'_'",
",",
"$",
"domain",
")",
".",
"'.pot'",
";",
"$",
"File",
"=",
"new",
"File",
"(",
"$",
"this",
"->",
"_output",
".",
"$",
"filename",
")",
";",
"$",
"response",
"=",
"''",
";",
"while",
"(",
"$",
"overwriteAll",
"===",
"false",
"&&",
"$",
"File",
"->",
"exists",
"(",
")",
"&&",
"strtoupper",
"(",
"$",
"response",
")",
"!==",
"'Y'",
")",
"{",
"$",
"this",
"->",
"out",
"(",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"in",
"(",
"sprintf",
"(",
"'Error: %s already exists in this location. Overwrite? [Y]es, [N]o, [A]ll'",
",",
"$",
"filename",
")",
",",
"[",
"'y'",
",",
"'n'",
",",
"'a'",
"]",
",",
"'y'",
")",
";",
"if",
"(",
"strtoupper",
"(",
"$",
"response",
")",
"===",
"'N'",
")",
"{",
"$",
"response",
"=",
"''",
";",
"while",
"(",
"!",
"$",
"response",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"in",
"(",
"'What would you like to name this file?'",
",",
"null",
",",
"'new_'",
".",
"$",
"filename",
")",
";",
"$",
"File",
"=",
"new",
"File",
"(",
"$",
"this",
"->",
"_output",
".",
"$",
"response",
")",
";",
"$",
"filename",
"=",
"$",
"response",
";",
"}",
"}",
"elseif",
"(",
"strtoupper",
"(",
"$",
"response",
")",
"===",
"'A'",
")",
"{",
"$",
"overwriteAll",
"=",
"true",
";",
"}",
"}",
"$",
"File",
"->",
"write",
"(",
"$",
"output",
")",
";",
"$",
"File",
"->",
"close",
"(",
")",
";",
"}",
"}"
] | Write the files that need to be stored
@return void | [
"Write",
"the",
"files",
"that",
"need",
"to",
"be",
"stored"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Task/ExtractTask.php#L598-L640 |
211,089 | cakephp/cakephp | src/Shell/Task/ExtractTask.php | ExtractTask._writeHeader | protected function _writeHeader()
{
$output = "# LANGUAGE translation of CakePHP Application\n";
$output .= "# Copyright YEAR NAME <EMAIL@ADDRESS>\n";
$output .= "#\n";
$output .= "#, fuzzy\n";
$output .= "msgid \"\"\n";
$output .= "msgstr \"\"\n";
$output .= "\"Project-Id-Version: PROJECT VERSION\\n\"\n";
$output .= '"POT-Creation-Date: ' . date('Y-m-d H:iO') . "\\n\"\n";
$output .= "\"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\\n\"\n";
$output .= "\"Last-Translator: NAME <EMAIL@ADDRESS>\\n\"\n";
$output .= "\"Language-Team: LANGUAGE <EMAIL@ADDRESS>\\n\"\n";
$output .= "\"MIME-Version: 1.0\\n\"\n";
$output .= "\"Content-Type: text/plain; charset=utf-8\\n\"\n";
$output .= "\"Content-Transfer-Encoding: 8bit\\n\"\n";
$output .= "\"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\\n\"\n\n";
return $output;
} | php | protected function _writeHeader()
{
$output = "# LANGUAGE translation of CakePHP Application\n";
$output .= "# Copyright YEAR NAME <EMAIL@ADDRESS>\n";
$output .= "#\n";
$output .= "#, fuzzy\n";
$output .= "msgid \"\"\n";
$output .= "msgstr \"\"\n";
$output .= "\"Project-Id-Version: PROJECT VERSION\\n\"\n";
$output .= '"POT-Creation-Date: ' . date('Y-m-d H:iO') . "\\n\"\n";
$output .= "\"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\\n\"\n";
$output .= "\"Last-Translator: NAME <EMAIL@ADDRESS>\\n\"\n";
$output .= "\"Language-Team: LANGUAGE <EMAIL@ADDRESS>\\n\"\n";
$output .= "\"MIME-Version: 1.0\\n\"\n";
$output .= "\"Content-Type: text/plain; charset=utf-8\\n\"\n";
$output .= "\"Content-Transfer-Encoding: 8bit\\n\"\n";
$output .= "\"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\\n\"\n\n";
return $output;
} | [
"protected",
"function",
"_writeHeader",
"(",
")",
"{",
"$",
"output",
"=",
"\"# LANGUAGE translation of CakePHP Application\\n\"",
";",
"$",
"output",
".=",
"\"# Copyright YEAR NAME <EMAIL@ADDRESS>\\n\"",
";",
"$",
"output",
".=",
"\"#\\n\"",
";",
"$",
"output",
".=",
"\"#, fuzzy\\n\"",
";",
"$",
"output",
".=",
"\"msgid \\\"\\\"\\n\"",
";",
"$",
"output",
".=",
"\"msgstr \\\"\\\"\\n\"",
";",
"$",
"output",
".=",
"\"\\\"Project-Id-Version: PROJECT VERSION\\\\n\\\"\\n\"",
";",
"$",
"output",
".=",
"'\"POT-Creation-Date: '",
".",
"date",
"(",
"'Y-m-d H:iO'",
")",
".",
"\"\\\\n\\\"\\n\"",
";",
"$",
"output",
".=",
"\"\\\"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\\\\n\\\"\\n\"",
";",
"$",
"output",
".=",
"\"\\\"Last-Translator: NAME <EMAIL@ADDRESS>\\\\n\\\"\\n\"",
";",
"$",
"output",
".=",
"\"\\\"Language-Team: LANGUAGE <EMAIL@ADDRESS>\\\\n\\\"\\n\"",
";",
"$",
"output",
".=",
"\"\\\"MIME-Version: 1.0\\\\n\\\"\\n\"",
";",
"$",
"output",
".=",
"\"\\\"Content-Type: text/plain; charset=utf-8\\\\n\\\"\\n\"",
";",
"$",
"output",
".=",
"\"\\\"Content-Transfer-Encoding: 8bit\\\\n\\\"\\n\"",
";",
"$",
"output",
".=",
"\"\\\"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\\\\n\\\"\\n\\n\"",
";",
"return",
"$",
"output",
";",
"}"
] | Build the translation template header
@return string Translation template header | [
"Build",
"the",
"translation",
"template",
"header"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Task/ExtractTask.php#L647-L666 |
211,090 | cakephp/cakephp | src/Shell/Task/ExtractTask.php | ExtractTask._getStrings | protected function _getStrings(&$position, $target)
{
$strings = [];
$count = count($strings);
while ($count < $target && ($this->_tokens[$position] === ',' || $this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING || $this->_tokens[$position][0] == T_LNUMBER)) {
$count = count($strings);
if ($this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING && $this->_tokens[$position + 1] === '.') {
$string = '';
while ($this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING || $this->_tokens[$position] === '.') {
if ($this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING) {
$string .= $this->_formatString($this->_tokens[$position][1]);
}
$position++;
}
$strings[] = $string;
} elseif ($this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING) {
$strings[] = $this->_formatString($this->_tokens[$position][1]);
} elseif ($this->_tokens[$position][0] == T_LNUMBER) {
$strings[] = $this->_tokens[$position][1];
}
$position++;
}
return $strings;
} | php | protected function _getStrings(&$position, $target)
{
$strings = [];
$count = count($strings);
while ($count < $target && ($this->_tokens[$position] === ',' || $this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING || $this->_tokens[$position][0] == T_LNUMBER)) {
$count = count($strings);
if ($this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING && $this->_tokens[$position + 1] === '.') {
$string = '';
while ($this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING || $this->_tokens[$position] === '.') {
if ($this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING) {
$string .= $this->_formatString($this->_tokens[$position][1]);
}
$position++;
}
$strings[] = $string;
} elseif ($this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING) {
$strings[] = $this->_formatString($this->_tokens[$position][1]);
} elseif ($this->_tokens[$position][0] == T_LNUMBER) {
$strings[] = $this->_tokens[$position][1];
}
$position++;
}
return $strings;
} | [
"protected",
"function",
"_getStrings",
"(",
"&",
"$",
"position",
",",
"$",
"target",
")",
"{",
"$",
"strings",
"=",
"[",
"]",
";",
"$",
"count",
"=",
"count",
"(",
"$",
"strings",
")",
";",
"while",
"(",
"$",
"count",
"<",
"$",
"target",
"&&",
"(",
"$",
"this",
"->",
"_tokens",
"[",
"$",
"position",
"]",
"===",
"','",
"||",
"$",
"this",
"->",
"_tokens",
"[",
"$",
"position",
"]",
"[",
"0",
"]",
"==",
"T_CONSTANT_ENCAPSED_STRING",
"||",
"$",
"this",
"->",
"_tokens",
"[",
"$",
"position",
"]",
"[",
"0",
"]",
"==",
"T_LNUMBER",
")",
")",
"{",
"$",
"count",
"=",
"count",
"(",
"$",
"strings",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_tokens",
"[",
"$",
"position",
"]",
"[",
"0",
"]",
"==",
"T_CONSTANT_ENCAPSED_STRING",
"&&",
"$",
"this",
"->",
"_tokens",
"[",
"$",
"position",
"+",
"1",
"]",
"===",
"'.'",
")",
"{",
"$",
"string",
"=",
"''",
";",
"while",
"(",
"$",
"this",
"->",
"_tokens",
"[",
"$",
"position",
"]",
"[",
"0",
"]",
"==",
"T_CONSTANT_ENCAPSED_STRING",
"||",
"$",
"this",
"->",
"_tokens",
"[",
"$",
"position",
"]",
"===",
"'.'",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_tokens",
"[",
"$",
"position",
"]",
"[",
"0",
"]",
"==",
"T_CONSTANT_ENCAPSED_STRING",
")",
"{",
"$",
"string",
".=",
"$",
"this",
"->",
"_formatString",
"(",
"$",
"this",
"->",
"_tokens",
"[",
"$",
"position",
"]",
"[",
"1",
"]",
")",
";",
"}",
"$",
"position",
"++",
";",
"}",
"$",
"strings",
"[",
"]",
"=",
"$",
"string",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"_tokens",
"[",
"$",
"position",
"]",
"[",
"0",
"]",
"==",
"T_CONSTANT_ENCAPSED_STRING",
")",
"{",
"$",
"strings",
"[",
"]",
"=",
"$",
"this",
"->",
"_formatString",
"(",
"$",
"this",
"->",
"_tokens",
"[",
"$",
"position",
"]",
"[",
"1",
"]",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"_tokens",
"[",
"$",
"position",
"]",
"[",
"0",
"]",
"==",
"T_LNUMBER",
")",
"{",
"$",
"strings",
"[",
"]",
"=",
"$",
"this",
"->",
"_tokens",
"[",
"$",
"position",
"]",
"[",
"1",
"]",
";",
"}",
"$",
"position",
"++",
";",
"}",
"return",
"$",
"strings",
";",
"}"
] | Get the strings from the position forward
@param int $position Actual position on tokens array
@param int $target Number of strings to extract
@return array Strings extracted | [
"Get",
"the",
"strings",
"from",
"the",
"position",
"forward"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Task/ExtractTask.php#L675-L699 |
211,091 | cakephp/cakephp | src/Shell/Task/ExtractTask.php | ExtractTask._formatString | protected function _formatString($string)
{
$quote = substr($string, 0, 1);
$string = substr($string, 1, -1);
if ($quote === '"') {
$string = stripcslashes($string);
} else {
$string = strtr($string, ["\\'" => "'", '\\\\' => '\\']);
}
$string = str_replace("\r\n", "\n", $string);
return addcslashes($string, "\0..\37\\\"");
} | php | protected function _formatString($string)
{
$quote = substr($string, 0, 1);
$string = substr($string, 1, -1);
if ($quote === '"') {
$string = stripcslashes($string);
} else {
$string = strtr($string, ["\\'" => "'", '\\\\' => '\\']);
}
$string = str_replace("\r\n", "\n", $string);
return addcslashes($string, "\0..\37\\\"");
} | [
"protected",
"function",
"_formatString",
"(",
"$",
"string",
")",
"{",
"$",
"quote",
"=",
"substr",
"(",
"$",
"string",
",",
"0",
",",
"1",
")",
";",
"$",
"string",
"=",
"substr",
"(",
"$",
"string",
",",
"1",
",",
"-",
"1",
")",
";",
"if",
"(",
"$",
"quote",
"===",
"'\"'",
")",
"{",
"$",
"string",
"=",
"stripcslashes",
"(",
"$",
"string",
")",
";",
"}",
"else",
"{",
"$",
"string",
"=",
"strtr",
"(",
"$",
"string",
",",
"[",
"\"\\\\'\"",
"=>",
"\"'\"",
",",
"'\\\\\\\\'",
"=>",
"'\\\\'",
"]",
")",
";",
"}",
"$",
"string",
"=",
"str_replace",
"(",
"\"\\r\\n\"",
",",
"\"\\n\"",
",",
"$",
"string",
")",
";",
"return",
"addcslashes",
"(",
"$",
"string",
",",
"\"\\0..\\37\\\\\\\"\"",
")",
";",
"}"
] | Format a string to be added as a translatable string
@param string $string String to format
@return string Formatted string | [
"Format",
"a",
"string",
"to",
"be",
"added",
"as",
"a",
"translatable",
"string"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Task/ExtractTask.php#L707-L719 |
211,092 | cakephp/cakephp | src/Shell/Task/ExtractTask.php | ExtractTask._markerError | protected function _markerError($file, $line, $marker, $count)
{
if (strpos($this->_file, CAKE_CORE_INCLUDE_PATH) === false) {
$this->_countMarkerError++;
}
if (!$this->_markerError) {
return;
}
$this->err(sprintf("Invalid marker content in %s:%s\n* %s(", $file, $line, $marker));
$count += 2;
$tokenCount = count($this->_tokens);
$parenthesis = 1;
while ((($tokenCount - $count) > 0) && $parenthesis) {
if (is_array($this->_tokens[$count])) {
$this->err($this->_tokens[$count][1], false);
} else {
$this->err($this->_tokens[$count], false);
if ($this->_tokens[$count] === '(') {
$parenthesis++;
}
if ($this->_tokens[$count] === ')') {
$parenthesis--;
}
}
$count++;
}
$this->err("\n", true);
} | php | protected function _markerError($file, $line, $marker, $count)
{
if (strpos($this->_file, CAKE_CORE_INCLUDE_PATH) === false) {
$this->_countMarkerError++;
}
if (!$this->_markerError) {
return;
}
$this->err(sprintf("Invalid marker content in %s:%s\n* %s(", $file, $line, $marker));
$count += 2;
$tokenCount = count($this->_tokens);
$parenthesis = 1;
while ((($tokenCount - $count) > 0) && $parenthesis) {
if (is_array($this->_tokens[$count])) {
$this->err($this->_tokens[$count][1], false);
} else {
$this->err($this->_tokens[$count], false);
if ($this->_tokens[$count] === '(') {
$parenthesis++;
}
if ($this->_tokens[$count] === ')') {
$parenthesis--;
}
}
$count++;
}
$this->err("\n", true);
} | [
"protected",
"function",
"_markerError",
"(",
"$",
"file",
",",
"$",
"line",
",",
"$",
"marker",
",",
"$",
"count",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"this",
"->",
"_file",
",",
"CAKE_CORE_INCLUDE_PATH",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"_countMarkerError",
"++",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"_markerError",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"err",
"(",
"sprintf",
"(",
"\"Invalid marker content in %s:%s\\n* %s(\"",
",",
"$",
"file",
",",
"$",
"line",
",",
"$",
"marker",
")",
")",
";",
"$",
"count",
"+=",
"2",
";",
"$",
"tokenCount",
"=",
"count",
"(",
"$",
"this",
"->",
"_tokens",
")",
";",
"$",
"parenthesis",
"=",
"1",
";",
"while",
"(",
"(",
"(",
"$",
"tokenCount",
"-",
"$",
"count",
")",
">",
"0",
")",
"&&",
"$",
"parenthesis",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"_tokens",
"[",
"$",
"count",
"]",
")",
")",
"{",
"$",
"this",
"->",
"err",
"(",
"$",
"this",
"->",
"_tokens",
"[",
"$",
"count",
"]",
"[",
"1",
"]",
",",
"false",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"err",
"(",
"$",
"this",
"->",
"_tokens",
"[",
"$",
"count",
"]",
",",
"false",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_tokens",
"[",
"$",
"count",
"]",
"===",
"'('",
")",
"{",
"$",
"parenthesis",
"++",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_tokens",
"[",
"$",
"count",
"]",
"===",
"')'",
")",
"{",
"$",
"parenthesis",
"--",
";",
"}",
"}",
"$",
"count",
"++",
";",
"}",
"$",
"this",
"->",
"err",
"(",
"\"\\n\"",
",",
"true",
")",
";",
"}"
] | Indicate an invalid marker on a processed file
@param string $file File where invalid marker resides
@param int $line Line number
@param string $marker Marker found
@param int $count Count
@return void | [
"Indicate",
"an",
"invalid",
"marker",
"on",
"a",
"processed",
"file"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Task/ExtractTask.php#L730-L761 |
211,093 | cakephp/cakephp | src/Shell/Task/ExtractTask.php | ExtractTask._searchFiles | protected function _searchFiles()
{
$pattern = false;
if (!empty($this->_exclude)) {
$exclude = [];
foreach ($this->_exclude as $e) {
if (DIRECTORY_SEPARATOR !== '\\' && $e[0] !== DIRECTORY_SEPARATOR) {
$e = DIRECTORY_SEPARATOR . $e;
}
$exclude[] = preg_quote($e, '/');
}
$pattern = '/' . implode('|', $exclude) . '/';
}
foreach ($this->_paths as $path) {
$path = realpath($path) . DIRECTORY_SEPARATOR;
$Folder = new Folder($path);
$files = $Folder->findRecursive('.*\.(php|ctp|thtml|inc|tpl)', true);
if (!empty($pattern)) {
$files = preg_grep($pattern, $files, PREG_GREP_INVERT);
$files = array_values($files);
}
$this->_files = array_merge($this->_files, $files);
}
$this->_files = array_unique($this->_files);
} | php | protected function _searchFiles()
{
$pattern = false;
if (!empty($this->_exclude)) {
$exclude = [];
foreach ($this->_exclude as $e) {
if (DIRECTORY_SEPARATOR !== '\\' && $e[0] !== DIRECTORY_SEPARATOR) {
$e = DIRECTORY_SEPARATOR . $e;
}
$exclude[] = preg_quote($e, '/');
}
$pattern = '/' . implode('|', $exclude) . '/';
}
foreach ($this->_paths as $path) {
$path = realpath($path) . DIRECTORY_SEPARATOR;
$Folder = new Folder($path);
$files = $Folder->findRecursive('.*\.(php|ctp|thtml|inc|tpl)', true);
if (!empty($pattern)) {
$files = preg_grep($pattern, $files, PREG_GREP_INVERT);
$files = array_values($files);
}
$this->_files = array_merge($this->_files, $files);
}
$this->_files = array_unique($this->_files);
} | [
"protected",
"function",
"_searchFiles",
"(",
")",
"{",
"$",
"pattern",
"=",
"false",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_exclude",
")",
")",
"{",
"$",
"exclude",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_exclude",
"as",
"$",
"e",
")",
"{",
"if",
"(",
"DIRECTORY_SEPARATOR",
"!==",
"'\\\\'",
"&&",
"$",
"e",
"[",
"0",
"]",
"!==",
"DIRECTORY_SEPARATOR",
")",
"{",
"$",
"e",
"=",
"DIRECTORY_SEPARATOR",
".",
"$",
"e",
";",
"}",
"$",
"exclude",
"[",
"]",
"=",
"preg_quote",
"(",
"$",
"e",
",",
"'/'",
")",
";",
"}",
"$",
"pattern",
"=",
"'/'",
".",
"implode",
"(",
"'|'",
",",
"$",
"exclude",
")",
".",
"'/'",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"_paths",
"as",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"realpath",
"(",
"$",
"path",
")",
".",
"DIRECTORY_SEPARATOR",
";",
"$",
"Folder",
"=",
"new",
"Folder",
"(",
"$",
"path",
")",
";",
"$",
"files",
"=",
"$",
"Folder",
"->",
"findRecursive",
"(",
"'.*\\.(php|ctp|thtml|inc|tpl)'",
",",
"true",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"pattern",
")",
")",
"{",
"$",
"files",
"=",
"preg_grep",
"(",
"$",
"pattern",
",",
"$",
"files",
",",
"PREG_GREP_INVERT",
")",
";",
"$",
"files",
"=",
"array_values",
"(",
"$",
"files",
")",
";",
"}",
"$",
"this",
"->",
"_files",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"_files",
",",
"$",
"files",
")",
";",
"}",
"$",
"this",
"->",
"_files",
"=",
"array_unique",
"(",
"$",
"this",
"->",
"_files",
")",
";",
"}"
] | Search files that may contain translatable strings
@return void | [
"Search",
"files",
"that",
"may",
"contain",
"translatable",
"strings"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Task/ExtractTask.php#L768-L792 |
211,094 | cakephp/cakephp | src/Shell/Task/ExtractTask.php | ExtractTask._isPathUsable | protected function _isPathUsable($path)
{
if (!is_dir($path)) {
mkdir($path, 0770, true);
}
return is_dir($path) && is_writable($path);
} | php | protected function _isPathUsable($path)
{
if (!is_dir($path)) {
mkdir($path, 0770, true);
}
return is_dir($path) && is_writable($path);
} | [
"protected",
"function",
"_isPathUsable",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"mkdir",
"(",
"$",
"path",
",",
"0770",
",",
"true",
")",
";",
"}",
"return",
"is_dir",
"(",
"$",
"path",
")",
"&&",
"is_writable",
"(",
"$",
"path",
")",
";",
"}"
] | Checks whether or not a given path is usable for writing.
@param string $path Path to folder
@return bool true if it exists and is writable, false otherwise | [
"Checks",
"whether",
"or",
"not",
"a",
"given",
"path",
"is",
"usable",
"for",
"writing",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Shell/Task/ExtractTask.php#L811-L818 |
211,095 | cakephp/cakephp | src/I18n/Formatter/IcuFormatter.php | IcuFormatter.format | public function format($locale, $message, array $vars)
{
unset($vars['_singular'], $vars['_count']);
return $this->_formatMessage($locale, $message, $vars);
} | php | public function format($locale, $message, array $vars)
{
unset($vars['_singular'], $vars['_count']);
return $this->_formatMessage($locale, $message, $vars);
} | [
"public",
"function",
"format",
"(",
"$",
"locale",
",",
"$",
"message",
",",
"array",
"$",
"vars",
")",
"{",
"unset",
"(",
"$",
"vars",
"[",
"'_singular'",
"]",
",",
"$",
"vars",
"[",
"'_count'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"_formatMessage",
"(",
"$",
"locale",
",",
"$",
"message",
",",
"$",
"vars",
")",
";",
"}"
] | Returns a string with all passed variables interpolated into the original
message. Variables are interpolated using the MessageFormatter class.
@param string $locale The locale in which the message is presented.
@param string|array $message The message to be translated
@param array $vars The list of values to interpolate in the message
@return string The formatted message
@throws \Aura\Intl\Exception\CannotFormat
@throws \Aura\Intl\Exception\CannotInstantiateFormatter | [
"Returns",
"a",
"string",
"with",
"all",
"passed",
"variables",
"interpolated",
"into",
"the",
"original",
"message",
".",
"Variables",
"are",
"interpolated",
"using",
"the",
"MessageFormatter",
"class",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/I18n/Formatter/IcuFormatter.php#L39-L44 |
211,096 | cakephp/cakephp | src/I18n/Formatter/IcuFormatter.php | IcuFormatter._formatMessage | protected function _formatMessage($locale, $message, $vars)
{
if ($message === '') {
return $message;
}
// Using procedural style as it showed twice as fast as
// its counterpart in PHP 5.5
$result = MessageFormatter::formatMessage($locale, $message, $vars);
if ($result === false) {
// The user might be interested in what went wrong, so replay the
// previous action using the object oriented style to figure out
$formatter = new MessageFormatter($locale, $message);
if (!$formatter) {
throw new CannotInstantiateFormatter(intl_get_error_message(), intl_get_error_code());
}
$formatter->format($vars);
throw new CannotFormat($formatter->getErrorMessage(), $formatter->getErrorCode());
}
return $result;
} | php | protected function _formatMessage($locale, $message, $vars)
{
if ($message === '') {
return $message;
}
// Using procedural style as it showed twice as fast as
// its counterpart in PHP 5.5
$result = MessageFormatter::formatMessage($locale, $message, $vars);
if ($result === false) {
// The user might be interested in what went wrong, so replay the
// previous action using the object oriented style to figure out
$formatter = new MessageFormatter($locale, $message);
if (!$formatter) {
throw new CannotInstantiateFormatter(intl_get_error_message(), intl_get_error_code());
}
$formatter->format($vars);
throw new CannotFormat($formatter->getErrorMessage(), $formatter->getErrorCode());
}
return $result;
} | [
"protected",
"function",
"_formatMessage",
"(",
"$",
"locale",
",",
"$",
"message",
",",
"$",
"vars",
")",
"{",
"if",
"(",
"$",
"message",
"===",
"''",
")",
"{",
"return",
"$",
"message",
";",
"}",
"// Using procedural style as it showed twice as fast as",
"// its counterpart in PHP 5.5",
"$",
"result",
"=",
"MessageFormatter",
"::",
"formatMessage",
"(",
"$",
"locale",
",",
"$",
"message",
",",
"$",
"vars",
")",
";",
"if",
"(",
"$",
"result",
"===",
"false",
")",
"{",
"// The user might be interested in what went wrong, so replay the",
"// previous action using the object oriented style to figure out",
"$",
"formatter",
"=",
"new",
"MessageFormatter",
"(",
"$",
"locale",
",",
"$",
"message",
")",
";",
"if",
"(",
"!",
"$",
"formatter",
")",
"{",
"throw",
"new",
"CannotInstantiateFormatter",
"(",
"intl_get_error_message",
"(",
")",
",",
"intl_get_error_code",
"(",
")",
")",
";",
"}",
"$",
"formatter",
"->",
"format",
"(",
"$",
"vars",
")",
";",
"throw",
"new",
"CannotFormat",
"(",
"$",
"formatter",
"->",
"getErrorMessage",
"(",
")",
",",
"$",
"formatter",
"->",
"getErrorCode",
"(",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Does the actual formatting using the MessageFormatter class
@param string $locale The locale in which the message is presented.
@param string|array $message The message to be translated
@param array $vars The list of values to interpolate in the message
@return string The formatted message
@throws \Aura\Intl\Exception\CannotInstantiateFormatter if any error occurred
while parsing the message
@throws \Aura\Intl\Exception\CannotFormat If any error related to the passed
variables is found | [
"Does",
"the",
"actual",
"formatting",
"using",
"the",
"MessageFormatter",
"class"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/I18n/Formatter/IcuFormatter.php#L58-L80 |
211,097 | cakephp/cakephp | src/Log/Engine/ConsoleLog.php | ConsoleLog.log | public function log($level, $message, array $context = [])
{
$message = $this->_format($message, $context);
$output = date('Y-m-d H:i:s') . ' ' . ucfirst($level) . ': ' . $message;
return (bool)$this->_output->write(sprintf('<%s>%s</%s>', $level, $output, $level));
} | php | public function log($level, $message, array $context = [])
{
$message = $this->_format($message, $context);
$output = date('Y-m-d H:i:s') . ' ' . ucfirst($level) . ': ' . $message;
return (bool)$this->_output->write(sprintf('<%s>%s</%s>', $level, $output, $level));
} | [
"public",
"function",
"log",
"(",
"$",
"level",
",",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"$",
"message",
"=",
"$",
"this",
"->",
"_format",
"(",
"$",
"message",
",",
"$",
"context",
")",
";",
"$",
"output",
"=",
"date",
"(",
"'Y-m-d H:i:s'",
")",
".",
"' '",
".",
"ucfirst",
"(",
"$",
"level",
")",
".",
"': '",
".",
"$",
"message",
";",
"return",
"(",
"bool",
")",
"$",
"this",
"->",
"_output",
"->",
"write",
"(",
"sprintf",
"(",
"'<%s>%s</%s>'",
",",
"$",
"level",
",",
"$",
"output",
",",
"$",
"level",
")",
")",
";",
"}"
] | Implements writing to console.
@param string $level The severity level of log you are making.
@param string $message The message you want to log.
@param array $context Additional information about the logged message
@return bool success of write. | [
"Implements",
"writing",
"to",
"console",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/Log/Engine/ConsoleLog.php#L89-L95 |
211,098 | cakephp/cakephp | src/ORM/Association.php | Association.setName | public function setName($name)
{
if ($this->_targetTable !== null) {
$alias = $this->_targetTable->getAlias();
if ($alias !== $name) {
throw new InvalidArgumentException('Association name does not match target table alias.');
}
}
$this->_name = $name;
return $this;
} | php | public function setName($name)
{
if ($this->_targetTable !== null) {
$alias = $this->_targetTable->getAlias();
if ($alias !== $name) {
throw new InvalidArgumentException('Association name does not match target table alias.');
}
}
$this->_name = $name;
return $this;
} | [
"public",
"function",
"setName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_targetTable",
"!==",
"null",
")",
"{",
"$",
"alias",
"=",
"$",
"this",
"->",
"_targetTable",
"->",
"getAlias",
"(",
")",
";",
"if",
"(",
"$",
"alias",
"!==",
"$",
"name",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Association name does not match target table alias.'",
")",
";",
"}",
"}",
"$",
"this",
"->",
"_name",
"=",
"$",
"name",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the name for this association, usually the alias
assigned to the target associated table
@param string $name Name to be assigned
@return $this | [
"Sets",
"the",
"name",
"for",
"this",
"association",
"usually",
"the",
"alias",
"assigned",
"to",
"the",
"target",
"associated",
"table"
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L249-L261 |
211,099 | cakephp/cakephp | src/ORM/Association.php | Association.name | public function name($name = null)
{
deprecationWarning(
get_called_class() . '::name() is deprecated. ' .
'Use setName()/getName() instead.'
);
if ($name !== null) {
$this->setName($name);
}
return $this->getName();
} | php | public function name($name = null)
{
deprecationWarning(
get_called_class() . '::name() is deprecated. ' .
'Use setName()/getName() instead.'
);
if ($name !== null) {
$this->setName($name);
}
return $this->getName();
} | [
"public",
"function",
"name",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"deprecationWarning",
"(",
"get_called_class",
"(",
")",
".",
"'::name() is deprecated. '",
".",
"'Use setName()/getName() instead.'",
")",
";",
"if",
"(",
"$",
"name",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"setName",
"(",
"$",
"name",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getName",
"(",
")",
";",
"}"
] | Sets the name for this association.
@deprecated 3.4.0 Use setName()/getName() instead.
@param string|null $name Name to be assigned
@return string | [
"Sets",
"the",
"name",
"for",
"this",
"association",
"."
] | 5f6c9d65dcbbfc093410d1dbbb207a17f4cde540 | https://github.com/cakephp/cakephp/blob/5f6c9d65dcbbfc093410d1dbbb207a17f4cde540/src/ORM/Association.php#L281-L292 |
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.