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
| partition
stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
horntell/php-sdk
|
lib/guzzle/GuzzleHttp/QueryParser.php
|
QueryParser.parseInto
|
public function parseInto(Query $query, $str, $urlEncoding = true)
{
if ($str === '') {
return;
}
$result = [];
$this->duplicates = false;
$this->numericIndices = true;
$decoder = self::getDecoder($urlEncoding);
foreach (explode('&', $str) as $kvp) {
$parts = explode('=', $kvp, 2);
$key = $decoder($parts[0]);
$value = isset($parts[1]) ? $decoder($parts[1]) : null;
// Special handling needs to be taken for PHP nested array syntax
if (strpos($key, '[') !== false) {
$this->parsePhpValue($key, $value, $result);
continue;
}
if (!isset($result[$key])) {
$result[$key] = $value;
} else {
$this->duplicates = true;
if (!is_array($result[$key])) {
$result[$key] = [$result[$key]];
}
$result[$key][] = $value;
}
}
$query->replace($result);
if (!$this->numericIndices) {
$query->setAggregator(Query::phpAggregator(false));
} elseif ($this->duplicates) {
$query->setAggregator(Query::duplicateAggregator());
}
}
|
php
|
public function parseInto(Query $query, $str, $urlEncoding = true)
{
if ($str === '') {
return;
}
$result = [];
$this->duplicates = false;
$this->numericIndices = true;
$decoder = self::getDecoder($urlEncoding);
foreach (explode('&', $str) as $kvp) {
$parts = explode('=', $kvp, 2);
$key = $decoder($parts[0]);
$value = isset($parts[1]) ? $decoder($parts[1]) : null;
// Special handling needs to be taken for PHP nested array syntax
if (strpos($key, '[') !== false) {
$this->parsePhpValue($key, $value, $result);
continue;
}
if (!isset($result[$key])) {
$result[$key] = $value;
} else {
$this->duplicates = true;
if (!is_array($result[$key])) {
$result[$key] = [$result[$key]];
}
$result[$key][] = $value;
}
}
$query->replace($result);
if (!$this->numericIndices) {
$query->setAggregator(Query::phpAggregator(false));
} elseif ($this->duplicates) {
$query->setAggregator(Query::duplicateAggregator());
}
}
|
[
"public",
"function",
"parseInto",
"(",
"Query",
"$",
"query",
",",
"$",
"str",
",",
"$",
"urlEncoding",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"str",
"===",
"''",
")",
"{",
"return",
";",
"}",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"duplicates",
"=",
"false",
";",
"$",
"this",
"->",
"numericIndices",
"=",
"true",
";",
"$",
"decoder",
"=",
"self",
"::",
"getDecoder",
"(",
"$",
"urlEncoding",
")",
";",
"foreach",
"(",
"explode",
"(",
"'&'",
",",
"$",
"str",
")",
"as",
"$",
"kvp",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'='",
",",
"$",
"kvp",
",",
"2",
")",
";",
"$",
"key",
"=",
"$",
"decoder",
"(",
"$",
"parts",
"[",
"0",
"]",
")",
";",
"$",
"value",
"=",
"isset",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
"?",
"$",
"decoder",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
":",
"null",
";",
"// Special handling needs to be taken for PHP nested array syntax",
"if",
"(",
"strpos",
"(",
"$",
"key",
",",
"'['",
")",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"parsePhpValue",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"result",
")",
";",
"continue",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"result",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"result",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"duplicates",
"=",
"true",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"result",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"result",
"[",
"$",
"key",
"]",
"=",
"[",
"$",
"result",
"[",
"$",
"key",
"]",
"]",
";",
"}",
"$",
"result",
"[",
"$",
"key",
"]",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"$",
"query",
"->",
"replace",
"(",
"$",
"result",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"numericIndices",
")",
"{",
"$",
"query",
"->",
"setAggregator",
"(",
"Query",
"::",
"phpAggregator",
"(",
"false",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"duplicates",
")",
"{",
"$",
"query",
"->",
"setAggregator",
"(",
"Query",
"::",
"duplicateAggregator",
"(",
")",
")",
";",
"}",
"}"
] |
Parse a query string into a Query object.
@param Query $query Query object to populate
@param string $str Query string to parse
@param bool|string $urlEncoding How the query string is encoded
|
[
"Parse",
"a",
"query",
"string",
"into",
"a",
"Query",
"object",
"."
] |
e5205e9396a21b754d5651a8aa5898da5922a1b7
|
https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/QueryParser.php#L26-L67
|
train
|
horntell/php-sdk
|
lib/guzzle/GuzzleHttp/QueryParser.php
|
QueryParser.getDecoder
|
private static function getDecoder($type)
{
if ($type === true) {
return function ($value) {
return rawurldecode(str_replace('+', ' ', $value));
};
} elseif ($type == Query::RFC3986) {
return 'rawurldecode';
} elseif ($type == Query::RFC1738) {
return 'urldecode';
} else {
return function ($str) { return $str; };
}
}
|
php
|
private static function getDecoder($type)
{
if ($type === true) {
return function ($value) {
return rawurldecode(str_replace('+', ' ', $value));
};
} elseif ($type == Query::RFC3986) {
return 'rawurldecode';
} elseif ($type == Query::RFC1738) {
return 'urldecode';
} else {
return function ($str) { return $str; };
}
}
|
[
"private",
"static",
"function",
"getDecoder",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"type",
"===",
"true",
")",
"{",
"return",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"rawurldecode",
"(",
"str_replace",
"(",
"'+'",
",",
"' '",
",",
"$",
"value",
")",
")",
";",
"}",
";",
"}",
"elseif",
"(",
"$",
"type",
"==",
"Query",
"::",
"RFC3986",
")",
"{",
"return",
"'rawurldecode'",
";",
"}",
"elseif",
"(",
"$",
"type",
"==",
"Query",
"::",
"RFC1738",
")",
"{",
"return",
"'urldecode'",
";",
"}",
"else",
"{",
"return",
"function",
"(",
"$",
"str",
")",
"{",
"return",
"$",
"str",
";",
"}",
";",
"}",
"}"
] |
Returns a callable that is used to URL decode query keys and values.
@param string|bool $type One of true, false, RFC3986, and RFC1738
@return callable|string
|
[
"Returns",
"a",
"callable",
"that",
"is",
"used",
"to",
"URL",
"decode",
"query",
"keys",
"and",
"values",
"."
] |
e5205e9396a21b754d5651a8aa5898da5922a1b7
|
https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/QueryParser.php#L76-L89
|
train
|
horntell/php-sdk
|
lib/guzzle/GuzzleHttp/QueryParser.php
|
QueryParser.parsePhpValue
|
private function parsePhpValue($key, $value, array &$result)
{
$node =& $result;
$keyBuffer = '';
for ($i = 0, $t = strlen($key); $i < $t; $i++) {
switch ($key[$i]) {
case '[':
if ($keyBuffer) {
$this->prepareNode($node, $keyBuffer);
$node =& $node[$keyBuffer];
$keyBuffer = '';
}
break;
case ']':
$k = $this->cleanKey($node, $keyBuffer);
$this->prepareNode($node, $k);
$node =& $node[$k];
$keyBuffer = '';
break;
default:
$keyBuffer .= $key[$i];
break;
}
}
if (isset($node)) {
$this->duplicates = true;
$node[] = $value;
} else {
$node = $value;
}
}
|
php
|
private function parsePhpValue($key, $value, array &$result)
{
$node =& $result;
$keyBuffer = '';
for ($i = 0, $t = strlen($key); $i < $t; $i++) {
switch ($key[$i]) {
case '[':
if ($keyBuffer) {
$this->prepareNode($node, $keyBuffer);
$node =& $node[$keyBuffer];
$keyBuffer = '';
}
break;
case ']':
$k = $this->cleanKey($node, $keyBuffer);
$this->prepareNode($node, $k);
$node =& $node[$k];
$keyBuffer = '';
break;
default:
$keyBuffer .= $key[$i];
break;
}
}
if (isset($node)) {
$this->duplicates = true;
$node[] = $value;
} else {
$node = $value;
}
}
|
[
"private",
"function",
"parsePhpValue",
"(",
"$",
"key",
",",
"$",
"value",
",",
"array",
"&",
"$",
"result",
")",
"{",
"$",
"node",
"=",
"&",
"$",
"result",
";",
"$",
"keyBuffer",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"t",
"=",
"strlen",
"(",
"$",
"key",
")",
";",
"$",
"i",
"<",
"$",
"t",
";",
"$",
"i",
"++",
")",
"{",
"switch",
"(",
"$",
"key",
"[",
"$",
"i",
"]",
")",
"{",
"case",
"'['",
":",
"if",
"(",
"$",
"keyBuffer",
")",
"{",
"$",
"this",
"->",
"prepareNode",
"(",
"$",
"node",
",",
"$",
"keyBuffer",
")",
";",
"$",
"node",
"=",
"&",
"$",
"node",
"[",
"$",
"keyBuffer",
"]",
";",
"$",
"keyBuffer",
"=",
"''",
";",
"}",
"break",
";",
"case",
"']'",
":",
"$",
"k",
"=",
"$",
"this",
"->",
"cleanKey",
"(",
"$",
"node",
",",
"$",
"keyBuffer",
")",
";",
"$",
"this",
"->",
"prepareNode",
"(",
"$",
"node",
",",
"$",
"k",
")",
";",
"$",
"node",
"=",
"&",
"$",
"node",
"[",
"$",
"k",
"]",
";",
"$",
"keyBuffer",
"=",
"''",
";",
"break",
";",
"default",
":",
"$",
"keyBuffer",
".=",
"$",
"key",
"[",
"$",
"i",
"]",
";",
"break",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"node",
")",
")",
"{",
"$",
"this",
"->",
"duplicates",
"=",
"true",
";",
"$",
"node",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"node",
"=",
"$",
"value",
";",
"}",
"}"
] |
Parses a PHP style key value pair.
@param string $key Key to parse (e.g., "foo[a][b]")
@param string|null $value Value to set
@param array $result Result to modify by reference
|
[
"Parses",
"a",
"PHP",
"style",
"key",
"value",
"pair",
"."
] |
e5205e9396a21b754d5651a8aa5898da5922a1b7
|
https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/QueryParser.php#L98-L130
|
train
|
horntell/php-sdk
|
lib/guzzle/GuzzleHttp/QueryParser.php
|
QueryParser.prepareNode
|
private function prepareNode(&$node, $key)
{
if (!isset($node[$key])) {
$node[$key] = null;
} elseif (!is_array($node[$key])) {
$node[$key] = [$node[$key]];
}
}
|
php
|
private function prepareNode(&$node, $key)
{
if (!isset($node[$key])) {
$node[$key] = null;
} elseif (!is_array($node[$key])) {
$node[$key] = [$node[$key]];
}
}
|
[
"private",
"function",
"prepareNode",
"(",
"&",
"$",
"node",
",",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"node",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"node",
"[",
"$",
"key",
"]",
"=",
"null",
";",
"}",
"elseif",
"(",
"!",
"is_array",
"(",
"$",
"node",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"node",
"[",
"$",
"key",
"]",
"=",
"[",
"$",
"node",
"[",
"$",
"key",
"]",
"]",
";",
"}",
"}"
] |
Prepares a value in the array at the given key.
If the key already exists, the key value is converted into an array.
@param array $node Result node to modify
@param string $key Key to add or modify in the node
|
[
"Prepares",
"a",
"value",
"in",
"the",
"array",
"at",
"the",
"given",
"key",
"."
] |
e5205e9396a21b754d5651a8aa5898da5922a1b7
|
https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/QueryParser.php#L140-L147
|
train
|
horntell/php-sdk
|
lib/guzzle/GuzzleHttp/QueryParser.php
|
QueryParser.cleanKey
|
private function cleanKey($node, $key)
{
if ($key === '') {
$key = $node ? (string) count($node) : 0;
// Found a [] key, so track this to ensure that we disable numeric
// indexing of keys in the resolved query aggregator.
$this->numericIndices = false;
}
return $key;
}
|
php
|
private function cleanKey($node, $key)
{
if ($key === '') {
$key = $node ? (string) count($node) : 0;
// Found a [] key, so track this to ensure that we disable numeric
// indexing of keys in the resolved query aggregator.
$this->numericIndices = false;
}
return $key;
}
|
[
"private",
"function",
"cleanKey",
"(",
"$",
"node",
",",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"''",
")",
"{",
"$",
"key",
"=",
"$",
"node",
"?",
"(",
"string",
")",
"count",
"(",
"$",
"node",
")",
":",
"0",
";",
"// Found a [] key, so track this to ensure that we disable numeric",
"// indexing of keys in the resolved query aggregator.",
"$",
"this",
"->",
"numericIndices",
"=",
"false",
";",
"}",
"return",
"$",
"key",
";",
"}"
] |
Returns the appropriate key based on the node and key.
|
[
"Returns",
"the",
"appropriate",
"key",
"based",
"on",
"the",
"node",
"and",
"key",
"."
] |
e5205e9396a21b754d5651a8aa5898da5922a1b7
|
https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/QueryParser.php#L152-L162
|
train
|
zhaoxianfang/tools
|
src/Symfony/Component/Config/Definition/Builder/NodeBuilder.php
|
NodeBuilder.append
|
public function append(NodeDefinition $node)
{
if ($node instanceof ParentNodeDefinitionInterface) {
$builder = clone $this;
$builder->setParent(null);
$node->setBuilder($builder);
}
if (null !== $this->parent) {
$this->parent->append($node);
// Make this builder the node parent to allow for a fluid interface
$node->setParent($this);
}
return $this;
}
|
php
|
public function append(NodeDefinition $node)
{
if ($node instanceof ParentNodeDefinitionInterface) {
$builder = clone $this;
$builder->setParent(null);
$node->setBuilder($builder);
}
if (null !== $this->parent) {
$this->parent->append($node);
// Make this builder the node parent to allow for a fluid interface
$node->setParent($this);
}
return $this;
}
|
[
"public",
"function",
"append",
"(",
"NodeDefinition",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"instanceof",
"ParentNodeDefinitionInterface",
")",
"{",
"$",
"builder",
"=",
"clone",
"$",
"this",
";",
"$",
"builder",
"->",
"setParent",
"(",
"null",
")",
";",
"$",
"node",
"->",
"setBuilder",
"(",
"$",
"builder",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"parent",
")",
"{",
"$",
"this",
"->",
"parent",
"->",
"append",
"(",
"$",
"node",
")",
";",
"// Make this builder the node parent to allow for a fluid interface",
"$",
"node",
"->",
"setParent",
"(",
"$",
"this",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Appends a node definition.
Usage:
$node = new ArrayNodeDefinition('name')
->children()
->scalarNode('foo')->end()
->scalarNode('baz')->end()
->append($this->getBarNodeDefinition())
->end()
;
@return $this
|
[
"Appends",
"a",
"node",
"definition",
"."
] |
d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7
|
https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/Config/Definition/Builder/NodeBuilder.php#L180-L195
|
train
|
anime-db/catalog-bundle
|
src/Form/Type/Entity/Item.php
|
Item.getRefillAttr
|
protected function getRefillAttr($field, ItemEntity $item = null)
{
// item exists and can be refilled
if ($item instanceof ItemEntity && $item->getName() &&
($plugins = $this->chain->getPluginsThatCanFillItem($item, $field))
) {
/* @var $plugin RefillerInterface */
foreach ($plugins as $key => $plugin) {
$plugins[$key] = [
'name' => $plugin->getName(),
'title' => $plugin->getTitle(),
'can_refill' => $plugin->isCanRefill($item, $field), // can refill or can search
];
}
return [
'data-type' => 'refill',
'data-plugins' => $this->templating->render(
'AnimeDbCatalogBundle:Form:refillers.html.twig',
[
'item' => $item,
'field' => $field,
'plugins' => $plugins,
]
),
];
}
return [];
}
|
php
|
protected function getRefillAttr($field, ItemEntity $item = null)
{
// item exists and can be refilled
if ($item instanceof ItemEntity && $item->getName() &&
($plugins = $this->chain->getPluginsThatCanFillItem($item, $field))
) {
/* @var $plugin RefillerInterface */
foreach ($plugins as $key => $plugin) {
$plugins[$key] = [
'name' => $plugin->getName(),
'title' => $plugin->getTitle(),
'can_refill' => $plugin->isCanRefill($item, $field), // can refill or can search
];
}
return [
'data-type' => 'refill',
'data-plugins' => $this->templating->render(
'AnimeDbCatalogBundle:Form:refillers.html.twig',
[
'item' => $item,
'field' => $field,
'plugins' => $plugins,
]
),
];
}
return [];
}
|
[
"protected",
"function",
"getRefillAttr",
"(",
"$",
"field",
",",
"ItemEntity",
"$",
"item",
"=",
"null",
")",
"{",
"// item exists and can be refilled",
"if",
"(",
"$",
"item",
"instanceof",
"ItemEntity",
"&&",
"$",
"item",
"->",
"getName",
"(",
")",
"&&",
"(",
"$",
"plugins",
"=",
"$",
"this",
"->",
"chain",
"->",
"getPluginsThatCanFillItem",
"(",
"$",
"item",
",",
"$",
"field",
")",
")",
")",
"{",
"/* @var $plugin RefillerInterface */",
"foreach",
"(",
"$",
"plugins",
"as",
"$",
"key",
"=>",
"$",
"plugin",
")",
"{",
"$",
"plugins",
"[",
"$",
"key",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"plugin",
"->",
"getName",
"(",
")",
",",
"'title'",
"=>",
"$",
"plugin",
"->",
"getTitle",
"(",
")",
",",
"'can_refill'",
"=>",
"$",
"plugin",
"->",
"isCanRefill",
"(",
"$",
"item",
",",
"$",
"field",
")",
",",
"// can refill or can search",
"]",
";",
"}",
"return",
"[",
"'data-type'",
"=>",
"'refill'",
",",
"'data-plugins'",
"=>",
"$",
"this",
"->",
"templating",
"->",
"render",
"(",
"'AnimeDbCatalogBundle:Form:refillers.html.twig'",
",",
"[",
"'item'",
"=>",
"$",
"item",
",",
"'field'",
"=>",
"$",
"field",
",",
"'plugins'",
"=>",
"$",
"plugins",
",",
"]",
")",
",",
"]",
";",
"}",
"return",
"[",
"]",
";",
"}"
] |
Get the field refill attributes.
@param string $field
@param ItemEntity|null $item
@return array
|
[
"Get",
"the",
"field",
"refill",
"attributes",
"."
] |
631b6f92a654e91bee84f46218c52cf42bdb8606
|
https://github.com/anime-db/catalog-bundle/blob/631b6f92a654e91bee84f46218c52cf42bdb8606/src/Form/Type/Entity/Item.php#L259-L288
|
train
|
romm/configuration_object
|
Classes/Validation/Validator/IconExistsValidator.php
|
IconExistsValidator.isValid
|
public function isValid($value)
{
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '7.6.0', '<')) {
throw new UnsupportedVersionException(
'The validator "' . self::class . '" cannot be used in TYPO3 versions anterior to `7.6.0`.',
1506281412
);
}
$value = (string)$value;
if (false === $this->getIconRegistry()->isRegistered($value)) {
$errorMessage = $this->translateErrorMessage('validator.icon_exists.not_valid', 'configuration_object', [$value]);
$this->addError($errorMessage, 1506272737);
}
}
|
php
|
public function isValid($value)
{
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '7.6.0', '<')) {
throw new UnsupportedVersionException(
'The validator "' . self::class . '" cannot be used in TYPO3 versions anterior to `7.6.0`.',
1506281412
);
}
$value = (string)$value;
if (false === $this->getIconRegistry()->isRegistered($value)) {
$errorMessage = $this->translateErrorMessage('validator.icon_exists.not_valid', 'configuration_object', [$value]);
$this->addError($errorMessage, 1506272737);
}
}
|
[
"public",
"function",
"isValid",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"version_compare",
"(",
"VersionNumberUtility",
"::",
"getCurrentTypo3Version",
"(",
")",
",",
"'7.6.0'",
",",
"'<'",
")",
")",
"{",
"throw",
"new",
"UnsupportedVersionException",
"(",
"'The validator \"'",
".",
"self",
"::",
"class",
".",
"'\" cannot be used in TYPO3 versions anterior to `7.6.0`.'",
",",
"1506281412",
")",
";",
"}",
"$",
"value",
"=",
"(",
"string",
")",
"$",
"value",
";",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"getIconRegistry",
"(",
")",
"->",
"isRegistered",
"(",
"$",
"value",
")",
")",
"{",
"$",
"errorMessage",
"=",
"$",
"this",
"->",
"translateErrorMessage",
"(",
"'validator.icon_exists.not_valid'",
",",
"'configuration_object'",
",",
"[",
"$",
"value",
"]",
")",
";",
"$",
"this",
"->",
"addError",
"(",
"$",
"errorMessage",
",",
"1506272737",
")",
";",
"}",
"}"
] |
Checks that the given icon identifier exists in the TYPO3 icon registry.
@param mixed $value
@throws UnsupportedVersionException
|
[
"Checks",
"that",
"the",
"given",
"icon",
"identifier",
"exists",
"in",
"the",
"TYPO3",
"icon",
"registry",
"."
] |
d3a40903386c2e0766bd8279337fe6da45cf5ce3
|
https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Validation/Validator/IconExistsValidator.php#L30-L45
|
train
|
ekyna/MediaBundle
|
Controller/MediaController.php
|
MediaController.findMedia
|
private function findMedia($path)
{
/** @var \Ekyna\Bundle\MediaBundle\Model\MediaInterface $media */
$media = $this
->get('ekyna_media.media.repository')
->findOneBy(['path' => $path])
;
if (null === $media) {
throw new NotFoundHttpException('Media not found');
}
$fs = $this->get('local_media_filesystem');
if (!$fs->has($media->getPath())) {
throw new NotFoundHttpException('Media not found');
}
$file = $fs->get($media->getPath());
return [$media, $file];
}
|
php
|
private function findMedia($path)
{
/** @var \Ekyna\Bundle\MediaBundle\Model\MediaInterface $media */
$media = $this
->get('ekyna_media.media.repository')
->findOneBy(['path' => $path])
;
if (null === $media) {
throw new NotFoundHttpException('Media not found');
}
$fs = $this->get('local_media_filesystem');
if (!$fs->has($media->getPath())) {
throw new NotFoundHttpException('Media not found');
}
$file = $fs->get($media->getPath());
return [$media, $file];
}
|
[
"private",
"function",
"findMedia",
"(",
"$",
"path",
")",
"{",
"/** @var \\Ekyna\\Bundle\\MediaBundle\\Model\\MediaInterface $media */",
"$",
"media",
"=",
"$",
"this",
"->",
"get",
"(",
"'ekyna_media.media.repository'",
")",
"->",
"findOneBy",
"(",
"[",
"'path'",
"=>",
"$",
"path",
"]",
")",
";",
"if",
"(",
"null",
"===",
"$",
"media",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
"'Media not found'",
")",
";",
"}",
"$",
"fs",
"=",
"$",
"this",
"->",
"get",
"(",
"'local_media_filesystem'",
")",
";",
"if",
"(",
"!",
"$",
"fs",
"->",
"has",
"(",
"$",
"media",
"->",
"getPath",
"(",
")",
")",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
"'Media not found'",
")",
";",
"}",
"$",
"file",
"=",
"$",
"fs",
"->",
"get",
"(",
"$",
"media",
"->",
"getPath",
"(",
")",
")",
";",
"return",
"[",
"$",
"media",
",",
"$",
"file",
"]",
";",
"}"
] |
Finds the media by his path.
@param string $path
@return array
@throws NotFoundHttpException
|
[
"Finds",
"the",
"media",
"by",
"his",
"path",
"."
] |
512cf86c801a130a9f17eba8b48d646d23acdbab
|
https://github.com/ekyna/MediaBundle/blob/512cf86c801a130a9f17eba8b48d646d23acdbab/Controller/MediaController.php#L123-L141
|
train
|
lightwerk/SurfCaptain
|
Classes/Lightwerk/SurfCaptain/Package.php
|
Package.boot
|
public function boot(\TYPO3\Flow\Core\Bootstrap $bootstrap)
{
$dispatcher = $bootstrap->getSignalSlotDispatcher();
$dispatcher->connect(
'Lightwerk\SurfCaptain\GitApi\ApiRequest',
'apiCall',
'Lightwerk\SurfCaptain\GitApi\RequestListener',
'saveApiCall'
);
$dispatcher->connect(
'Lightwerk\SurfCaptain\GitApi\ApiRequest',
'apiCall',
'Lightwerk\SurfCaptain\GitApi\RequestListener',
'logApiCall'
);
$dispatcher->connect(
'Lightwerk\SurfCaptain\GitApi\ApiRequest',
'beforeApiCall',
'Lightwerk\SurfCaptain\GitApi\RequestListener',
'logBeforeApiCall'
);
}
|
php
|
public function boot(\TYPO3\Flow\Core\Bootstrap $bootstrap)
{
$dispatcher = $bootstrap->getSignalSlotDispatcher();
$dispatcher->connect(
'Lightwerk\SurfCaptain\GitApi\ApiRequest',
'apiCall',
'Lightwerk\SurfCaptain\GitApi\RequestListener',
'saveApiCall'
);
$dispatcher->connect(
'Lightwerk\SurfCaptain\GitApi\ApiRequest',
'apiCall',
'Lightwerk\SurfCaptain\GitApi\RequestListener',
'logApiCall'
);
$dispatcher->connect(
'Lightwerk\SurfCaptain\GitApi\ApiRequest',
'beforeApiCall',
'Lightwerk\SurfCaptain\GitApi\RequestListener',
'logBeforeApiCall'
);
}
|
[
"public",
"function",
"boot",
"(",
"\\",
"TYPO3",
"\\",
"Flow",
"\\",
"Core",
"\\",
"Bootstrap",
"$",
"bootstrap",
")",
"{",
"$",
"dispatcher",
"=",
"$",
"bootstrap",
"->",
"getSignalSlotDispatcher",
"(",
")",
";",
"$",
"dispatcher",
"->",
"connect",
"(",
"'Lightwerk\\SurfCaptain\\GitApi\\ApiRequest'",
",",
"'apiCall'",
",",
"'Lightwerk\\SurfCaptain\\GitApi\\RequestListener'",
",",
"'saveApiCall'",
")",
";",
"$",
"dispatcher",
"->",
"connect",
"(",
"'Lightwerk\\SurfCaptain\\GitApi\\ApiRequest'",
",",
"'apiCall'",
",",
"'Lightwerk\\SurfCaptain\\GitApi\\RequestListener'",
",",
"'logApiCall'",
")",
";",
"$",
"dispatcher",
"->",
"connect",
"(",
"'Lightwerk\\SurfCaptain\\GitApi\\ApiRequest'",
",",
"'beforeApiCall'",
",",
"'Lightwerk\\SurfCaptain\\GitApi\\RequestListener'",
",",
"'logBeforeApiCall'",
")",
";",
"}"
] |
Boot the package. We wire some signals to slots here.
@param \TYPO3\Flow\Core\Bootstrap $bootstrap The current bootstrap
@return void
|
[
"Boot",
"the",
"package",
".",
"We",
"wire",
"some",
"signals",
"to",
"slots",
"here",
"."
] |
2865e963fd634504d8923902cf422873749a0940
|
https://github.com/lightwerk/SurfCaptain/blob/2865e963fd634504d8923902cf422873749a0940/Classes/Lightwerk/SurfCaptain/Package.php#L24-L45
|
train
|
TeknooSoftware/east-foundation
|
src/symfony/Listener/KernelListener.php
|
KernelListener.getPsrRequest
|
private function getPsrRequest(Request $symfonyRequest): ServerRequestInterface
{
$psrRequest = $this->diactorosFactory->createRequest($symfonyRequest);
$psrRequest = $psrRequest->withAttribute('request', $symfonyRequest);
return $psrRequest;
}
|
php
|
private function getPsrRequest(Request $symfonyRequest): ServerRequestInterface
{
$psrRequest = $this->diactorosFactory->createRequest($symfonyRequest);
$psrRequest = $psrRequest->withAttribute('request', $symfonyRequest);
return $psrRequest;
}
|
[
"private",
"function",
"getPsrRequest",
"(",
"Request",
"$",
"symfonyRequest",
")",
":",
"ServerRequestInterface",
"{",
"$",
"psrRequest",
"=",
"$",
"this",
"->",
"diactorosFactory",
"->",
"createRequest",
"(",
"$",
"symfonyRequest",
")",
";",
"$",
"psrRequest",
"=",
"$",
"psrRequest",
"->",
"withAttribute",
"(",
"'request'",
",",
"$",
"symfonyRequest",
")",
";",
"return",
"$",
"psrRequest",
";",
"}"
] |
To transform a symfony request as a psr request and inject the symfony request as attribute if the endpoint need
the symfony request.
@param Request $symfonyRequest
@return ServerRequestInterface
|
[
"To",
"transform",
"a",
"symfony",
"request",
"as",
"a",
"psr",
"request",
"and",
"inject",
"the",
"symfony",
"request",
"as",
"attribute",
"if",
"the",
"endpoint",
"need",
"the",
"symfony",
"request",
"."
] |
45ca97c83ba08b973877a472c731f27ca1e82cdf
|
https://github.com/TeknooSoftware/east-foundation/blob/45ca97c83ba08b973877a472c731f27ca1e82cdf/src/symfony/Listener/KernelListener.php#L88-L94
|
train
|
wb-crowdfusion/crowdfusion
|
system/core/classes/mvc/deployment/AbstractFileDeploymentService.php
|
AbstractFileDeploymentService.deploy
|
public function deploy()
{
if (empty($this->context) || empty($this->siteDomain) || empty($this->deviceView) || empty($this->design))
return;
$files = null;
$md5 = null;
$contents = null;
$aggregatePath = $this->getAggregatePath();
$this->Logger->debug("Aggregate Path: {$aggregatePath}");
if ($this->isDevelopmentMode || $this->isOneOffRedeploy || !$this->deploymentCacheExists($aggregatePath)) {
$this->Logger->debug("Retrieving file list...");
list($files,$md5) = $this->getFiles();
}
if ($this->deploymentCacheExists($aggregatePath)) {
//if this is NOT development mode, the only way to force a refresh is to delete the .json file
if($this->isDevelopmentMode === false && $this->isOneOffRedeploy === false)
return;
$this->Logger->debug("Checking cache JSON...");
$this->getDeployedFiles();
//if this IS development mode, a refresh is performed everytime the md5's dont' match
if (($this->isDevelopmentMode === true || $this->isOneOffRedeploy === true) && $md5 === $this->deployedFiles['md5']) {
//files haven't changed
return;
}
}
$this->Logger->debug("Rebuilding...");
//rebuild file
$this->aggregateFiles($md5, $files, $aggregatePath);
}
|
php
|
public function deploy()
{
if (empty($this->context) || empty($this->siteDomain) || empty($this->deviceView) || empty($this->design))
return;
$files = null;
$md5 = null;
$contents = null;
$aggregatePath = $this->getAggregatePath();
$this->Logger->debug("Aggregate Path: {$aggregatePath}");
if ($this->isDevelopmentMode || $this->isOneOffRedeploy || !$this->deploymentCacheExists($aggregatePath)) {
$this->Logger->debug("Retrieving file list...");
list($files,$md5) = $this->getFiles();
}
if ($this->deploymentCacheExists($aggregatePath)) {
//if this is NOT development mode, the only way to force a refresh is to delete the .json file
if($this->isDevelopmentMode === false && $this->isOneOffRedeploy === false)
return;
$this->Logger->debug("Checking cache JSON...");
$this->getDeployedFiles();
//if this IS development mode, a refresh is performed everytime the md5's dont' match
if (($this->isDevelopmentMode === true || $this->isOneOffRedeploy === true) && $md5 === $this->deployedFiles['md5']) {
//files haven't changed
return;
}
}
$this->Logger->debug("Rebuilding...");
//rebuild file
$this->aggregateFiles($md5, $files, $aggregatePath);
}
|
[
"public",
"function",
"deploy",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"context",
")",
"||",
"empty",
"(",
"$",
"this",
"->",
"siteDomain",
")",
"||",
"empty",
"(",
"$",
"this",
"->",
"deviceView",
")",
"||",
"empty",
"(",
"$",
"this",
"->",
"design",
")",
")",
"return",
";",
"$",
"files",
"=",
"null",
";",
"$",
"md5",
"=",
"null",
";",
"$",
"contents",
"=",
"null",
";",
"$",
"aggregatePath",
"=",
"$",
"this",
"->",
"getAggregatePath",
"(",
")",
";",
"$",
"this",
"->",
"Logger",
"->",
"debug",
"(",
"\"Aggregate Path: {$aggregatePath}\"",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isDevelopmentMode",
"||",
"$",
"this",
"->",
"isOneOffRedeploy",
"||",
"!",
"$",
"this",
"->",
"deploymentCacheExists",
"(",
"$",
"aggregatePath",
")",
")",
"{",
"$",
"this",
"->",
"Logger",
"->",
"debug",
"(",
"\"Retrieving file list...\"",
")",
";",
"list",
"(",
"$",
"files",
",",
"$",
"md5",
")",
"=",
"$",
"this",
"->",
"getFiles",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"deploymentCacheExists",
"(",
"$",
"aggregatePath",
")",
")",
"{",
"//if this is NOT development mode, the only way to force a refresh is to delete the .json file",
"if",
"(",
"$",
"this",
"->",
"isDevelopmentMode",
"===",
"false",
"&&",
"$",
"this",
"->",
"isOneOffRedeploy",
"===",
"false",
")",
"return",
";",
"$",
"this",
"->",
"Logger",
"->",
"debug",
"(",
"\"Checking cache JSON...\"",
")",
";",
"$",
"this",
"->",
"getDeployedFiles",
"(",
")",
";",
"//if this IS development mode, a refresh is performed everytime the md5's dont' match",
"if",
"(",
"(",
"$",
"this",
"->",
"isDevelopmentMode",
"===",
"true",
"||",
"$",
"this",
"->",
"isOneOffRedeploy",
"===",
"true",
")",
"&&",
"$",
"md5",
"===",
"$",
"this",
"->",
"deployedFiles",
"[",
"'md5'",
"]",
")",
"{",
"//files haven't changed",
"return",
";",
"}",
"}",
"$",
"this",
"->",
"Logger",
"->",
"debug",
"(",
"\"Rebuilding...\"",
")",
";",
"//rebuild file",
"$",
"this",
"->",
"aggregateFiles",
"(",
"$",
"md5",
",",
"$",
"files",
",",
"$",
"aggregatePath",
")",
";",
"}"
] |
Aggregates the files if necessary.
@return void
|
[
"Aggregates",
"the",
"files",
"if",
"necessary",
"."
] |
8cad7988f046a6fefbed07d026cb4ae6706c1217
|
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/deployment/AbstractFileDeploymentService.php#L47-L85
|
train
|
wb-crowdfusion/crowdfusion
|
system/core/classes/mvc/deployment/AbstractFileDeploymentService.php
|
AbstractFileDeploymentService.resolveFile
|
public function resolveFile($name)
{
$resolvedFilename = $this->getBaseDeployDirectory().$this->subject.'/'.ltrim($name, '/');
return new StorageFacilityFile('/'.ltrim($name, '/'), $resolvedFilename);
}
|
php
|
public function resolveFile($name)
{
$resolvedFilename = $this->getBaseDeployDirectory().$this->subject.'/'.ltrim($name, '/');
return new StorageFacilityFile('/'.ltrim($name, '/'), $resolvedFilename);
}
|
[
"public",
"function",
"resolveFile",
"(",
"$",
"name",
")",
"{",
"$",
"resolvedFilename",
"=",
"$",
"this",
"->",
"getBaseDeployDirectory",
"(",
")",
".",
"$",
"this",
"->",
"subject",
".",
"'/'",
".",
"ltrim",
"(",
"$",
"name",
",",
"'/'",
")",
";",
"return",
"new",
"StorageFacilityFile",
"(",
"'/'",
".",
"ltrim",
"(",
"$",
"name",
",",
"'/'",
")",
",",
"$",
"resolvedFilename",
")",
";",
"}"
] |
Returns the full filename of an existing deployed file with the name specified.
If the file does not exist, it returns null.
@param string $name The filename to expand (full path)
@return StorageFacilityFile
|
[
"Returns",
"the",
"full",
"filename",
"of",
"an",
"existing",
"deployed",
"file",
"with",
"the",
"name",
"specified",
"."
] |
8cad7988f046a6fefbed07d026cb4ae6706c1217
|
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/deployment/AbstractFileDeploymentService.php#L208-L212
|
train
|
wb-crowdfusion/crowdfusion
|
system/core/classes/mvc/deployment/AbstractFileDeploymentService.php
|
AbstractFileDeploymentService.getFiles
|
protected function getFiles()
{
if ($this->isSiteDeployment) {
if ($this->deviceView != 'main' && !is_dir("{$this->viewDirectory}/{$this->context}/{$this->siteDomain}/{$this->deviceView}")) {
$this->deviceView = 'main';
}
if ($this->design != 'default' && !is_dir("{$this->viewDirectory}/{$this->context}/{$this->siteDomain}/{$this->deviceView}/{$this->design}")) {
$this->design = 'default';
}
}
$list = array();
if (!empty($this->viewDirectory))
$list[] = $this->viewDirectory;
// Build the list from all the plugin directorys, and the theme directory
$list = array_merge($this->ApplicationContext->getEnabledPluginDirectories(),$list);
if (count($list) > 0) {
$files = array();
foreach ($list as $tp) {
if (is_dir($tp)) {
$paths = $this->getPathsToCheck($tp, $this->subject);
foreach ($paths as $basepath) {
if(!is_dir($basepath))
continue;
$cutoffDepth = null;
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($basepath),
RecursiveIteratorIterator::SELF_FIRST);
foreach ($objects as $name => $object) {
if($cutoffDepth !== null && $objects->getDepth() > $cutoffDepth)
continue;
else
$cutoffDepth = null;
if ($cutoffDepth === null && $object->isDir() && substr($object->getBasename(), 0, 1) == '.') {
$cutoffDepth = $objects->getDepth();
continue;
}
if (!$object->isFile() || substr($object->getBasename(), 0, 1) == '.')
continue;
$files[substr($name, strlen($basepath))] = $name;
}
}
} else {
$this->Logger->warn('Directory does not exist: '.$tp);
}
}
if(empty($files))
return array(array(),null);
$timestamps = array();
foreach ($files as $relpath => $filename) {
$timestamps[] = filemtime($filename);
}
$md5 = md5(serialize(array($files,$timestamps/*, $this->VersionService->getSystemVersion(), $this->VersionService->getDeploymentRevision()*/)));
return array($files, $md5);
}
throw new Exception('No active themes or plugins.');
}
|
php
|
protected function getFiles()
{
if ($this->isSiteDeployment) {
if ($this->deviceView != 'main' && !is_dir("{$this->viewDirectory}/{$this->context}/{$this->siteDomain}/{$this->deviceView}")) {
$this->deviceView = 'main';
}
if ($this->design != 'default' && !is_dir("{$this->viewDirectory}/{$this->context}/{$this->siteDomain}/{$this->deviceView}/{$this->design}")) {
$this->design = 'default';
}
}
$list = array();
if (!empty($this->viewDirectory))
$list[] = $this->viewDirectory;
// Build the list from all the plugin directorys, and the theme directory
$list = array_merge($this->ApplicationContext->getEnabledPluginDirectories(),$list);
if (count($list) > 0) {
$files = array();
foreach ($list as $tp) {
if (is_dir($tp)) {
$paths = $this->getPathsToCheck($tp, $this->subject);
foreach ($paths as $basepath) {
if(!is_dir($basepath))
continue;
$cutoffDepth = null;
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($basepath),
RecursiveIteratorIterator::SELF_FIRST);
foreach ($objects as $name => $object) {
if($cutoffDepth !== null && $objects->getDepth() > $cutoffDepth)
continue;
else
$cutoffDepth = null;
if ($cutoffDepth === null && $object->isDir() && substr($object->getBasename(), 0, 1) == '.') {
$cutoffDepth = $objects->getDepth();
continue;
}
if (!$object->isFile() || substr($object->getBasename(), 0, 1) == '.')
continue;
$files[substr($name, strlen($basepath))] = $name;
}
}
} else {
$this->Logger->warn('Directory does not exist: '.$tp);
}
}
if(empty($files))
return array(array(),null);
$timestamps = array();
foreach ($files as $relpath => $filename) {
$timestamps[] = filemtime($filename);
}
$md5 = md5(serialize(array($files,$timestamps/*, $this->VersionService->getSystemVersion(), $this->VersionService->getDeploymentRevision()*/)));
return array($files, $md5);
}
throw new Exception('No active themes or plugins.');
}
|
[
"protected",
"function",
"getFiles",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isSiteDeployment",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"deviceView",
"!=",
"'main'",
"&&",
"!",
"is_dir",
"(",
"\"{$this->viewDirectory}/{$this->context}/{$this->siteDomain}/{$this->deviceView}\"",
")",
")",
"{",
"$",
"this",
"->",
"deviceView",
"=",
"'main'",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"design",
"!=",
"'default'",
"&&",
"!",
"is_dir",
"(",
"\"{$this->viewDirectory}/{$this->context}/{$this->siteDomain}/{$this->deviceView}/{$this->design}\"",
")",
")",
"{",
"$",
"this",
"->",
"design",
"=",
"'default'",
";",
"}",
"}",
"$",
"list",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"viewDirectory",
")",
")",
"$",
"list",
"[",
"]",
"=",
"$",
"this",
"->",
"viewDirectory",
";",
"// Build the list from all the plugin directorys, and the theme directory",
"$",
"list",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"ApplicationContext",
"->",
"getEnabledPluginDirectories",
"(",
")",
",",
"$",
"list",
")",
";",
"if",
"(",
"count",
"(",
"$",
"list",
")",
">",
"0",
")",
"{",
"$",
"files",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"tp",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"tp",
")",
")",
"{",
"$",
"paths",
"=",
"$",
"this",
"->",
"getPathsToCheck",
"(",
"$",
"tp",
",",
"$",
"this",
"->",
"subject",
")",
";",
"foreach",
"(",
"$",
"paths",
"as",
"$",
"basepath",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"basepath",
")",
")",
"continue",
";",
"$",
"cutoffDepth",
"=",
"null",
";",
"$",
"objects",
"=",
"new",
"RecursiveIteratorIterator",
"(",
"new",
"RecursiveDirectoryIterator",
"(",
"$",
"basepath",
")",
",",
"RecursiveIteratorIterator",
"::",
"SELF_FIRST",
")",
";",
"foreach",
"(",
"$",
"objects",
"as",
"$",
"name",
"=>",
"$",
"object",
")",
"{",
"if",
"(",
"$",
"cutoffDepth",
"!==",
"null",
"&&",
"$",
"objects",
"->",
"getDepth",
"(",
")",
">",
"$",
"cutoffDepth",
")",
"continue",
";",
"else",
"$",
"cutoffDepth",
"=",
"null",
";",
"if",
"(",
"$",
"cutoffDepth",
"===",
"null",
"&&",
"$",
"object",
"->",
"isDir",
"(",
")",
"&&",
"substr",
"(",
"$",
"object",
"->",
"getBasename",
"(",
")",
",",
"0",
",",
"1",
")",
"==",
"'.'",
")",
"{",
"$",
"cutoffDepth",
"=",
"$",
"objects",
"->",
"getDepth",
"(",
")",
";",
"continue",
";",
"}",
"if",
"(",
"!",
"$",
"object",
"->",
"isFile",
"(",
")",
"||",
"substr",
"(",
"$",
"object",
"->",
"getBasename",
"(",
")",
",",
"0",
",",
"1",
")",
"==",
"'.'",
")",
"continue",
";",
"$",
"files",
"[",
"substr",
"(",
"$",
"name",
",",
"strlen",
"(",
"$",
"basepath",
")",
")",
"]",
"=",
"$",
"name",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"Logger",
"->",
"warn",
"(",
"'Directory does not exist: '",
".",
"$",
"tp",
")",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"files",
")",
")",
"return",
"array",
"(",
"array",
"(",
")",
",",
"null",
")",
";",
"$",
"timestamps",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"relpath",
"=>",
"$",
"filename",
")",
"{",
"$",
"timestamps",
"[",
"]",
"=",
"filemtime",
"(",
"$",
"filename",
")",
";",
"}",
"$",
"md5",
"=",
"md5",
"(",
"serialize",
"(",
"array",
"(",
"$",
"files",
",",
"$",
"timestamps",
"/*, $this->VersionService->getSystemVersion(), $this->VersionService->getDeploymentRevision()*/",
")",
")",
")",
";",
"return",
"array",
"(",
"$",
"files",
",",
"$",
"md5",
")",
";",
"}",
"throw",
"new",
"Exception",
"(",
"'No active themes or plugins.'",
")",
";",
"}"
] |
Returns a list of all the files in the theme directory combined with all the asset files of all installed plugins
@return array Contains 2 items, the first being an array of all the files, the second is a unique md5 identifier of the fileset
|
[
"Returns",
"a",
"list",
"of",
"all",
"the",
"files",
"in",
"the",
"theme",
"directory",
"combined",
"with",
"all",
"the",
"asset",
"files",
"of",
"all",
"installed",
"plugins"
] |
8cad7988f046a6fefbed07d026cb4ae6706c1217
|
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/deployment/AbstractFileDeploymentService.php#L257-L326
|
train
|
bseddon/XPath20
|
DOM/DOMSchemaAttribute.php
|
DOMSchemaAttribute.fromQName
|
public static function fromQName( $name )
{
if ( $name instanceof QName )
{
$name = "{$name->prefix}:{$name->localName}";
}
if ( ! is_string( $name ) )
{
throw new \InvalidArgumentException( "$name must be string or a QName instanxe" );
}
$types = SchemaTypes::getInstance();
$attribute = $types->getElement( $name );
if ( ! $attribute )
{
return null;
}
$result = new DOMSchemaAttribute();
error_log( __CLASS__ . " need to populate the DOMSchemaAttribute instance" );
return $result;
}
|
php
|
public static function fromQName( $name )
{
if ( $name instanceof QName )
{
$name = "{$name->prefix}:{$name->localName}";
}
if ( ! is_string( $name ) )
{
throw new \InvalidArgumentException( "$name must be string or a QName instanxe" );
}
$types = SchemaTypes::getInstance();
$attribute = $types->getElement( $name );
if ( ! $attribute )
{
return null;
}
$result = new DOMSchemaAttribute();
error_log( __CLASS__ . " need to populate the DOMSchemaAttribute instance" );
return $result;
}
|
[
"public",
"static",
"function",
"fromQName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"name",
"instanceof",
"QName",
")",
"{",
"$",
"name",
"=",
"\"{$name->prefix}:{$name->localName}\"",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"$name must be string or a QName instanxe\"",
")",
";",
"}",
"$",
"types",
"=",
"SchemaTypes",
"::",
"getInstance",
"(",
")",
";",
"$",
"attribute",
"=",
"$",
"types",
"->",
"getElement",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"$",
"attribute",
")",
"{",
"return",
"null",
";",
"}",
"$",
"result",
"=",
"new",
"DOMSchemaAttribute",
"(",
")",
";",
"error_log",
"(",
"__CLASS__",
".",
"\" need to populate the DOMSchemaAttribute instance\"",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
The qualified name of the attribute
@param QName|string $name
|
[
"The",
"qualified",
"name",
"of",
"the",
"attribute"
] |
69882b6efffaa5470a819d5fdd2f6473ddeb046d
|
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/DOM/DOMSchemaAttribute.php#L51-L73
|
train
|
AdamB7586/menu-builder
|
src/Helpers/URI.php
|
URI.setURI
|
protected static function setURI($uri){
if(!is_string($uri)){
throw new InvalidArgumentException(
'$uri must be a string or null'
);
}
self::$uri = filter_var($uri, FILTER_SANITIZE_URL);
}
|
php
|
protected static function setURI($uri){
if(!is_string($uri)){
throw new InvalidArgumentException(
'$uri must be a string or null'
);
}
self::$uri = filter_var($uri, FILTER_SANITIZE_URL);
}
|
[
"protected",
"static",
"function",
"setURI",
"(",
"$",
"uri",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"uri",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'$uri must be a string or null'",
")",
";",
"}",
"self",
"::",
"$",
"uri",
"=",
"filter_var",
"(",
"$",
"uri",
",",
"FILTER_SANITIZE_URL",
")",
";",
"}"
] |
Sets the link URI
@param string $uri This should be the link string
@throws InvalidArgumentException
|
[
"Sets",
"the",
"link",
"URI"
] |
dbc192bca7d59475068c19d1a07a039e5f997ee4
|
https://github.com/AdamB7586/menu-builder/blob/dbc192bca7d59475068c19d1a07a039e5f997ee4/src/Helpers/URI.php#L16-L23
|
train
|
AdamB7586/menu-builder
|
src/Helpers/URI.php
|
URI.setAnchorPoint
|
protected static function setAnchorPoint($anchor){
if(is_string($anchor) && !empty(trim($anchor))){
self::$anchor = '#'.trim($anchor, '#');
}
else{
self::$anchor = false;
}
}
|
php
|
protected static function setAnchorPoint($anchor){
if(is_string($anchor) && !empty(trim($anchor))){
self::$anchor = '#'.trim($anchor, '#');
}
else{
self::$anchor = false;
}
}
|
[
"protected",
"static",
"function",
"setAnchorPoint",
"(",
"$",
"anchor",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"anchor",
")",
"&&",
"!",
"empty",
"(",
"trim",
"(",
"$",
"anchor",
")",
")",
")",
"{",
"self",
"::",
"$",
"anchor",
"=",
"'#'",
".",
"trim",
"(",
"$",
"anchor",
",",
"'#'",
")",
";",
"}",
"else",
"{",
"self",
"::",
"$",
"anchor",
"=",
"false",
";",
"}",
"}"
] |
Sets the anchor point for the link
@param mixed $anchor If the anchor point exists set to the string here
|
[
"Sets",
"the",
"anchor",
"point",
"for",
"the",
"link"
] |
dbc192bca7d59475068c19d1a07a039e5f997ee4
|
https://github.com/AdamB7586/menu-builder/blob/dbc192bca7d59475068c19d1a07a039e5f997ee4/src/Helpers/URI.php#L37-L44
|
train
|
AdamB7586/menu-builder
|
src/Helpers/URI.php
|
URI.getHref
|
public static function getHref($link) {
self::setURI($link['uri']);
self::setAnchorPoint($link['fragment']);
return self::getURI().self::getAnchorPoint();
}
|
php
|
public static function getHref($link) {
self::setURI($link['uri']);
self::setAnchorPoint($link['fragment']);
return self::getURI().self::getAnchorPoint();
}
|
[
"public",
"static",
"function",
"getHref",
"(",
"$",
"link",
")",
"{",
"self",
"::",
"setURI",
"(",
"$",
"link",
"[",
"'uri'",
"]",
")",
";",
"self",
"::",
"setAnchorPoint",
"(",
"$",
"link",
"[",
"'fragment'",
"]",
")",
";",
"return",
"self",
"::",
"getURI",
"(",
")",
".",
"self",
"::",
"getAnchorPoint",
"(",
")",
";",
"}"
] |
Returns the correctly formatted link string
@param array $link This should be the link information
@return mixed Will return the link string if it exists else will return false
|
[
"Returns",
"the",
"correctly",
"formatted",
"link",
"string"
] |
dbc192bca7d59475068c19d1a07a039e5f997ee4
|
https://github.com/AdamB7586/menu-builder/blob/dbc192bca7d59475068c19d1a07a039e5f997ee4/src/Helpers/URI.php#L59-L63
|
train
|
codeblanche/Entity
|
src/Entity/Definition/PropertyDefinition.php
|
PropertyDefinition.extractGeneric
|
protected function extractGeneric($type)
{
if (empty($type)) {
return null;
}
$generic = null;
if (substr($type, -2) === '[]') {
$generic = substr($type, 0, -2);
}
elseif (strtolower(substr($type, 0, 6)) === 'array<' && substr($type, -1) === '>') {
$generic = substr($type, 6, -1);
}
return $generic;
}
|
php
|
protected function extractGeneric($type)
{
if (empty($type)) {
return null;
}
$generic = null;
if (substr($type, -2) === '[]') {
$generic = substr($type, 0, -2);
}
elseif (strtolower(substr($type, 0, 6)) === 'array<' && substr($type, -1) === '>') {
$generic = substr($type, 6, -1);
}
return $generic;
}
|
[
"protected",
"function",
"extractGeneric",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"type",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"generic",
"=",
"null",
";",
"if",
"(",
"substr",
"(",
"$",
"type",
",",
"-",
"2",
")",
"===",
"'[]'",
")",
"{",
"$",
"generic",
"=",
"substr",
"(",
"$",
"type",
",",
"0",
",",
"-",
"2",
")",
";",
"}",
"elseif",
"(",
"strtolower",
"(",
"substr",
"(",
"$",
"type",
",",
"0",
",",
"6",
")",
")",
"===",
"'array<'",
"&&",
"substr",
"(",
"$",
"type",
",",
"-",
"1",
")",
"===",
"'>'",
")",
"{",
"$",
"generic",
"=",
"substr",
"(",
"$",
"type",
",",
"6",
",",
"-",
"1",
")",
";",
"}",
"return",
"$",
"generic",
";",
"}"
] |
Extract the generic subtype from the specified type if there is one.
@param string $type
@return string|null
|
[
"Extract",
"the",
"generic",
"subtype",
"from",
"the",
"specified",
"type",
"if",
"there",
"is",
"one",
"."
] |
1d3839c09d7639ae8bbfc9d2721223202f3a5cdd
|
https://github.com/codeblanche/Entity/blob/1d3839c09d7639ae8bbfc9d2721223202f3a5cdd/src/Entity/Definition/PropertyDefinition.php#L107-L123
|
train
|
devlabmtl/haven-core
|
Lib/NestedSet/Config.php
|
Config.setClass
|
public function setClass($clazz)
{
if($clazz instanceof ClassMetadata)
{
$classMetadata = $clazz;
$classname = $clazz->getReflectionClass()->getName();
}
else if (class_exists($clazz))
{
$classname = $clazz;
$classMetadata = $this->getEntityManager()->getClassMetadata($clazz);
} else
{
$parts = explode(':', $clazz);
$alias = array_shift($parts);
$rest = implode('\\', $parts);
try
{
$namespace = $this->getEntityManager()->getConfiguration()->getEntityNamespace($alias);
}
catch (\Doctrine\ORM\ORMException $e) {
throw new \InvalidArgumentException("Can't find class: $clazz'");
}
$classname = $namespace.'\\'.$rest;
$classMetadata = $this->getEntityManager()->getClassMetadata($classname);
}
$reflectionClass = $classMetadata->getReflectionClass();
if(!$reflectionClass->implementsInterface('Haven\CoreBundle\Lib\NestedSet\Node'))
{
throw new \InvalidArgumentException('Class must implement Node interface: ' . $classname);
}
$this->hasManyRoots = $reflectionClass->implementsInterface('Haven\CoreBundle\Lib\NestedSet\MultipleRootNode');
$this->classMetadata = $classMetadata;
$this->classname = $classname;
return $this;
}
|
php
|
public function setClass($clazz)
{
if($clazz instanceof ClassMetadata)
{
$classMetadata = $clazz;
$classname = $clazz->getReflectionClass()->getName();
}
else if (class_exists($clazz))
{
$classname = $clazz;
$classMetadata = $this->getEntityManager()->getClassMetadata($clazz);
} else
{
$parts = explode(':', $clazz);
$alias = array_shift($parts);
$rest = implode('\\', $parts);
try
{
$namespace = $this->getEntityManager()->getConfiguration()->getEntityNamespace($alias);
}
catch (\Doctrine\ORM\ORMException $e) {
throw new \InvalidArgumentException("Can't find class: $clazz'");
}
$classname = $namespace.'\\'.$rest;
$classMetadata = $this->getEntityManager()->getClassMetadata($classname);
}
$reflectionClass = $classMetadata->getReflectionClass();
if(!$reflectionClass->implementsInterface('Haven\CoreBundle\Lib\NestedSet\Node'))
{
throw new \InvalidArgumentException('Class must implement Node interface: ' . $classname);
}
$this->hasManyRoots = $reflectionClass->implementsInterface('Haven\CoreBundle\Lib\NestedSet\MultipleRootNode');
$this->classMetadata = $classMetadata;
$this->classname = $classname;
return $this;
}
|
[
"public",
"function",
"setClass",
"(",
"$",
"clazz",
")",
"{",
"if",
"(",
"$",
"clazz",
"instanceof",
"ClassMetadata",
")",
"{",
"$",
"classMetadata",
"=",
"$",
"clazz",
";",
"$",
"classname",
"=",
"$",
"clazz",
"->",
"getReflectionClass",
"(",
")",
"->",
"getName",
"(",
")",
";",
"}",
"else",
"if",
"(",
"class_exists",
"(",
"$",
"clazz",
")",
")",
"{",
"$",
"classname",
"=",
"$",
"clazz",
";",
"$",
"classMetadata",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"getClassMetadata",
"(",
"$",
"clazz",
")",
";",
"}",
"else",
"{",
"$",
"parts",
"=",
"explode",
"(",
"':'",
",",
"$",
"clazz",
")",
";",
"$",
"alias",
"=",
"array_shift",
"(",
"$",
"parts",
")",
";",
"$",
"rest",
"=",
"implode",
"(",
"'\\\\'",
",",
"$",
"parts",
")",
";",
"try",
"{",
"$",
"namespace",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"getConfiguration",
"(",
")",
"->",
"getEntityNamespace",
"(",
"$",
"alias",
")",
";",
"}",
"catch",
"(",
"\\",
"Doctrine",
"\\",
"ORM",
"\\",
"ORMException",
"$",
"e",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Can't find class: $clazz'\"",
")",
";",
"}",
"$",
"classname",
"=",
"$",
"namespace",
".",
"'\\\\'",
".",
"$",
"rest",
";",
"$",
"classMetadata",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"getClassMetadata",
"(",
"$",
"classname",
")",
";",
"}",
"$",
"reflectionClass",
"=",
"$",
"classMetadata",
"->",
"getReflectionClass",
"(",
")",
";",
"if",
"(",
"!",
"$",
"reflectionClass",
"->",
"implementsInterface",
"(",
"'Haven\\CoreBundle\\Lib\\NestedSet\\Node'",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Class must implement Node interface: '",
".",
"$",
"classname",
")",
";",
"}",
"$",
"this",
"->",
"hasManyRoots",
"=",
"$",
"reflectionClass",
"->",
"implementsInterface",
"(",
"'Haven\\CoreBundle\\Lib\\NestedSet\\MultipleRootNode'",
")",
";",
"$",
"this",
"->",
"classMetadata",
"=",
"$",
"classMetadata",
";",
"$",
"this",
"->",
"classname",
"=",
"$",
"classname",
";",
"return",
"$",
"this",
";",
"}"
] |
Sets the class associated with this configuration
@param mixed $clazz a class name or ClassMetadata object representing
the entity class associated with this configuration
@return Config $this for fluent API
|
[
"Sets",
"the",
"class",
"associated",
"with",
"this",
"configuration"
] |
f13410f996fd4002efafe482b927adadb211dec8
|
https://github.com/devlabmtl/haven-core/blob/f13410f996fd4002efafe482b927adadb211dec8/Lib/NestedSet/Config.php#L81-L121
|
train
|
devlabmtl/haven-core
|
Lib/NestedSet/Config.php
|
Config.setBaseQueryBuilder
|
public function setBaseQueryBuilder(QueryBuilder $baseQueryBuilder=null)
{
if($baseQueryBuilder === null)
{
$this->baseQueryBuilder = $this->getDefaultQueryBuilder();
}
else
{
$this->baseQueryBuilder = $baseQueryBuilder;
}
}
|
php
|
public function setBaseQueryBuilder(QueryBuilder $baseQueryBuilder=null)
{
if($baseQueryBuilder === null)
{
$this->baseQueryBuilder = $this->getDefaultQueryBuilder();
}
else
{
$this->baseQueryBuilder = $baseQueryBuilder;
}
}
|
[
"public",
"function",
"setBaseQueryBuilder",
"(",
"QueryBuilder",
"$",
"baseQueryBuilder",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"baseQueryBuilder",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"baseQueryBuilder",
"=",
"$",
"this",
"->",
"getDefaultQueryBuilder",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"baseQueryBuilder",
"=",
"$",
"baseQueryBuilder",
";",
"}",
"}"
] |
sets the base query builder
@param Query $baseQueryBuilder or null to reset the base query builder
|
[
"sets",
"the",
"base",
"query",
"builder"
] |
f13410f996fd4002efafe482b927adadb211dec8
|
https://github.com/devlabmtl/haven-core/blob/f13410f996fd4002efafe482b927adadb211dec8/Lib/NestedSet/Config.php#L260-L270
|
train
|
devlabmtl/haven-core
|
Lib/NestedSet/Config.php
|
Config.getDefaultQueryBuilder
|
public function getDefaultQueryBuilder()
{
$em = $this->getEntityManager();
return $em->createQueryBuilder()
->select('n')
->from($this->getClassname(), 'n');
}
|
php
|
public function getDefaultQueryBuilder()
{
$em = $this->getEntityManager();
return $em->createQueryBuilder()
->select('n')
->from($this->getClassname(), 'n');
}
|
[
"public",
"function",
"getDefaultQueryBuilder",
"(",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
";",
"return",
"$",
"em",
"->",
"createQueryBuilder",
"(",
")",
"->",
"select",
"(",
"'n'",
")",
"->",
"from",
"(",
"$",
"this",
"->",
"getClassname",
"(",
")",
",",
"'n'",
")",
";",
"}"
] |
gets the default query builder
@return QueryBuilder
|
[
"gets",
"the",
"default",
"query",
"builder"
] |
f13410f996fd4002efafe482b927adadb211dec8
|
https://github.com/devlabmtl/haven-core/blob/f13410f996fd4002efafe482b927adadb211dec8/Lib/NestedSet/Config.php#L287-L293
|
train
|
cloudtek/dynamodm
|
lib/Cloudtek/DynamoDM/Schema/Identifier/CompositeIdentifier.php
|
CompositeIdentifier.addToDocument
|
protected function addToDocument($document)
{
parent::addToDocument($document);
$this->getRangeKey()->getPropertyMetadata()->setValue(
$document,
$this->getRangeValue()
);
}
|
php
|
protected function addToDocument($document)
{
parent::addToDocument($document);
$this->getRangeKey()->getPropertyMetadata()->setValue(
$document,
$this->getRangeValue()
);
}
|
[
"protected",
"function",
"addToDocument",
"(",
"$",
"document",
")",
"{",
"parent",
"::",
"addToDocument",
"(",
"$",
"document",
")",
";",
"$",
"this",
"->",
"getRangeKey",
"(",
")",
"->",
"getPropertyMetadata",
"(",
")",
"->",
"setValue",
"(",
"$",
"document",
",",
"$",
"this",
"->",
"getRangeValue",
"(",
")",
")",
";",
"}"
] |
Set this identifier's values on the provided document instance.
@param object $document
@return void
|
[
"Set",
"this",
"identifier",
"s",
"values",
"on",
"the",
"provided",
"document",
"instance",
"."
] |
119d355e2c5cbaef1f867970349b4432f5704fcd
|
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Schema/Identifier/CompositeIdentifier.php#L62-L70
|
train
|
cloudtek/dynamodm
|
lib/Cloudtek/DynamoDM/Schema/Identifier/CompositeIdentifier.php
|
CompositeIdentifier.getArray
|
protected function getArray()
{
$key = $this->getRangeKey()->getPropertyMetadata()->name;
$array = parent::getArray();
$array[$key] = $this->getRangeValue();
return $array;
}
|
php
|
protected function getArray()
{
$key = $this->getRangeKey()->getPropertyMetadata()->name;
$array = parent::getArray();
$array[$key] = $this->getRangeValue();
return $array;
}
|
[
"protected",
"function",
"getArray",
"(",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"getRangeKey",
"(",
")",
"->",
"getPropertyMetadata",
"(",
")",
"->",
"name",
";",
"$",
"array",
"=",
"parent",
"::",
"getArray",
"(",
")",
";",
"$",
"array",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"getRangeValue",
"(",
")",
";",
"return",
"$",
"array",
";",
"}"
] |
Return this identifier's key names and values.
Useful for compatibility with Doctrine\Common interfaces.
@return array
|
[
"Return",
"this",
"identifier",
"s",
"key",
"names",
"and",
"values",
"."
] |
119d355e2c5cbaef1f867970349b4432f5704fcd
|
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Schema/Identifier/CompositeIdentifier.php#L79-L86
|
train
|
ItalyStrap/config
|
src/Config/Config.php
|
Config.push
|
public function push( string $key, $value ) : self {
$this->offsetSet( $key, $value );
return $this;
}
|
php
|
public function push( string $key, $value ) : self {
$this->offsetSet( $key, $value );
return $this;
}
|
[
"public",
"function",
"push",
"(",
"string",
"$",
"key",
",",
"$",
"value",
")",
":",
"self",
"{",
"$",
"this",
"->",
"offsetSet",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Push a configuration in via the key
@since 1.0.0
@param string $key Key to be assigned, which also becomes the property
@param mixed $value Value to be assigned to the parameter key
@return self
|
[
"Push",
"a",
"configuration",
"in",
"via",
"the",
"key"
] |
cb4c163e124a98e0b4af67b10bbbdae6469f7113
|
https://github.com/ItalyStrap/config/blob/cb4c163e124a98e0b4af67b10bbbdae6469f7113/src/Config/Config.php#L73-L76
|
train
|
ItalyStrap/config
|
src/Config/Config.php
|
Config.remove
|
public function remove( ...$with_keys ) : self {
foreach ( $with_keys as $keys ) {
foreach ( (array) $keys as $k ) {
$this->offsetUnset( $k );
}
}
return $this;
}
|
php
|
public function remove( ...$with_keys ) : self {
foreach ( $with_keys as $keys ) {
foreach ( (array) $keys as $k ) {
$this->offsetUnset( $k );
}
}
return $this;
}
|
[
"public",
"function",
"remove",
"(",
"...",
"$",
"with_keys",
")",
":",
"self",
"{",
"foreach",
"(",
"$",
"with_keys",
"as",
"$",
"keys",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"keys",
"as",
"$",
"k",
")",
"{",
"$",
"this",
"->",
"offsetUnset",
"(",
"$",
"k",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Removes an item or multiple items.
@since 2.0.0
@param mixed ...$with_keys
@return self
|
[
"Removes",
"an",
"item",
"or",
"multiple",
"items",
"."
] |
cb4c163e124a98e0b4af67b10bbbdae6469f7113
|
https://github.com/ItalyStrap/config/blob/cb4c163e124a98e0b4af67b10bbbdae6469f7113/src/Config/Config.php#L86-L95
|
train
|
Stinger-Soft/TwigExtensions
|
src/StingerSoft/TwigExtensions/ArrayExtensions.php
|
ArrayExtensions.unsetFilter
|
public function unsetFilter($array, $keys) {
if(is_array($array)) {
if(!is_array($keys)) {
$keys = array(
$keys
);
}
foreach($keys as $key) {
if(array_key_exists($key, $array)) {
unset($array[$key]);
}
}
}
return $array;
}
|
php
|
public function unsetFilter($array, $keys) {
if(is_array($array)) {
if(!is_array($keys)) {
$keys = array(
$keys
);
}
foreach($keys as $key) {
if(array_key_exists($key, $array)) {
unset($array[$key]);
}
}
}
return $array;
}
|
[
"public",
"function",
"unsetFilter",
"(",
"$",
"array",
",",
"$",
"keys",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"array",
")",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"keys",
")",
")",
"{",
"$",
"keys",
"=",
"array",
"(",
"$",
"keys",
")",
";",
"}",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"array",
")",
")",
"{",
"unset",
"(",
"$",
"array",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"}",
"return",
"$",
"array",
";",
"}"
] |
Removes an element from the given array
@param array $array
@param array|string $keys
@return array
|
[
"Removes",
"an",
"element",
"from",
"the",
"given",
"array"
] |
7bfce337b0dd33106e22f80b221338451a02d7c5
|
https://github.com/Stinger-Soft/TwigExtensions/blob/7bfce337b0dd33106e22f80b221338451a02d7c5/src/StingerSoft/TwigExtensions/ArrayExtensions.php#L41-L55
|
train
|
fridge-project/dbal
|
src/Fridge/DBAL/Driver/Statement/StatementRewriter.php
|
StatementRewriter.getRewritedParameters
|
public function getRewritedParameters($parameter)
{
if (is_int($parameter)) {
return array($parameter);
}
if (!isset($this->parameters[$parameter])) {
throw StatementRewriterException::parameterDoesNotExist($parameter);
}
return $this->parameters[$parameter];
}
|
php
|
public function getRewritedParameters($parameter)
{
if (is_int($parameter)) {
return array($parameter);
}
if (!isset($this->parameters[$parameter])) {
throw StatementRewriterException::parameterDoesNotExist($parameter);
}
return $this->parameters[$parameter];
}
|
[
"public",
"function",
"getRewritedParameters",
"(",
"$",
"parameter",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"parameter",
")",
")",
"{",
"return",
"array",
"(",
"$",
"parameter",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"parameters",
"[",
"$",
"parameter",
"]",
")",
")",
"{",
"throw",
"StatementRewriterException",
"::",
"parameterDoesNotExist",
"(",
"$",
"parameter",
")",
";",
"}",
"return",
"$",
"this",
"->",
"parameters",
"[",
"$",
"parameter",
"]",
";",
"}"
] |
Gets the rewrited positional statement parameters according to the named parameter.
The metod returns an array because a named parameter can be used multiple times in the statement.
@param string $parameter The named parameter.
@throws \Fridge\DBAL\Exception\StatementRewriterException If the parameter does not exist.
@return array The rewrited positional parameters.
|
[
"Gets",
"the",
"rewrited",
"positional",
"statement",
"parameters",
"according",
"to",
"the",
"named",
"parameter",
"."
] |
d0b8c3551922d696836487aa0eb1bd74014edcd4
|
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Driver/Statement/StatementRewriter.php#L67-L78
|
train
|
fridge-project/dbal
|
src/Fridge/DBAL/Driver/Statement/StatementRewriter.php
|
StatementRewriter.rewrite
|
private function rewrite()
{
// Current positional parameter.
$positionalParameter = 1;
// TRUE if we are in a literal section else FALSE.
$literal = false;
// The statement length.
$statementLength = strlen($this->statement);
// Iterate each statement char.
for ($placeholderPos = 0; $placeholderPos < $statementLength; $placeholderPos++) {
// Switch the literal flag if the current statement char is a literal delimiter.
if (in_array($this->statement[$placeholderPos], array('\'', '"'))) {
$literal = !$literal;
}
// Check if we are not in a literal section and the current statement char is a double colon.
if (!$literal && $this->statement[$placeholderPos] === ':') {
// Determine placeholder length.
$placeholderLength = 1;
while (isset($this->statement[$placeholderPos + $placeholderLength])
&& $this->isValidPlaceholderCharacter($this->statement[$placeholderPos + $placeholderLength])) {
$placeholderLength++;
}
// Extract placeholder from the statement.
$placeholder = substr($this->statement, $placeholderPos, $placeholderLength);
// Initialize rewrites parameters.
if (!isset($this->parameters[$placeholder])) {
$this->parameters[$placeholder] = array();
}
// Rewrites parameter.
$this->parameters[$placeholder][] = $positionalParameter;
// Rewrite statement.
$this->statement = substr($this->statement, 0, $placeholderPos).
'?'.
substr($this->statement, $placeholderPos + $placeholderLength);
// Decrement statement length.
$statementLength = $statementLength - $placeholderLength + 1;
// Increment position parameter.
$positionalParameter++;
}
}
}
|
php
|
private function rewrite()
{
// Current positional parameter.
$positionalParameter = 1;
// TRUE if we are in a literal section else FALSE.
$literal = false;
// The statement length.
$statementLength = strlen($this->statement);
// Iterate each statement char.
for ($placeholderPos = 0; $placeholderPos < $statementLength; $placeholderPos++) {
// Switch the literal flag if the current statement char is a literal delimiter.
if (in_array($this->statement[$placeholderPos], array('\'', '"'))) {
$literal = !$literal;
}
// Check if we are not in a literal section and the current statement char is a double colon.
if (!$literal && $this->statement[$placeholderPos] === ':') {
// Determine placeholder length.
$placeholderLength = 1;
while (isset($this->statement[$placeholderPos + $placeholderLength])
&& $this->isValidPlaceholderCharacter($this->statement[$placeholderPos + $placeholderLength])) {
$placeholderLength++;
}
// Extract placeholder from the statement.
$placeholder = substr($this->statement, $placeholderPos, $placeholderLength);
// Initialize rewrites parameters.
if (!isset($this->parameters[$placeholder])) {
$this->parameters[$placeholder] = array();
}
// Rewrites parameter.
$this->parameters[$placeholder][] = $positionalParameter;
// Rewrite statement.
$this->statement = substr($this->statement, 0, $placeholderPos).
'?'.
substr($this->statement, $placeholderPos + $placeholderLength);
// Decrement statement length.
$statementLength = $statementLength - $placeholderLength + 1;
// Increment position parameter.
$positionalParameter++;
}
}
}
|
[
"private",
"function",
"rewrite",
"(",
")",
"{",
"// Current positional parameter.",
"$",
"positionalParameter",
"=",
"1",
";",
"// TRUE if we are in a literal section else FALSE.",
"$",
"literal",
"=",
"false",
";",
"// The statement length.",
"$",
"statementLength",
"=",
"strlen",
"(",
"$",
"this",
"->",
"statement",
")",
";",
"// Iterate each statement char.",
"for",
"(",
"$",
"placeholderPos",
"=",
"0",
";",
"$",
"placeholderPos",
"<",
"$",
"statementLength",
";",
"$",
"placeholderPos",
"++",
")",
"{",
"// Switch the literal flag if the current statement char is a literal delimiter.",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"statement",
"[",
"$",
"placeholderPos",
"]",
",",
"array",
"(",
"'\\''",
",",
"'\"'",
")",
")",
")",
"{",
"$",
"literal",
"=",
"!",
"$",
"literal",
";",
"}",
"// Check if we are not in a literal section and the current statement char is a double colon.",
"if",
"(",
"!",
"$",
"literal",
"&&",
"$",
"this",
"->",
"statement",
"[",
"$",
"placeholderPos",
"]",
"===",
"':'",
")",
"{",
"// Determine placeholder length.",
"$",
"placeholderLength",
"=",
"1",
";",
"while",
"(",
"isset",
"(",
"$",
"this",
"->",
"statement",
"[",
"$",
"placeholderPos",
"+",
"$",
"placeholderLength",
"]",
")",
"&&",
"$",
"this",
"->",
"isValidPlaceholderCharacter",
"(",
"$",
"this",
"->",
"statement",
"[",
"$",
"placeholderPos",
"+",
"$",
"placeholderLength",
"]",
")",
")",
"{",
"$",
"placeholderLength",
"++",
";",
"}",
"// Extract placeholder from the statement.",
"$",
"placeholder",
"=",
"substr",
"(",
"$",
"this",
"->",
"statement",
",",
"$",
"placeholderPos",
",",
"$",
"placeholderLength",
")",
";",
"// Initialize rewrites parameters.",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"parameters",
"[",
"$",
"placeholder",
"]",
")",
")",
"{",
"$",
"this",
"->",
"parameters",
"[",
"$",
"placeholder",
"]",
"=",
"array",
"(",
")",
";",
"}",
"// Rewrites parameter.",
"$",
"this",
"->",
"parameters",
"[",
"$",
"placeholder",
"]",
"[",
"]",
"=",
"$",
"positionalParameter",
";",
"// Rewrite statement.",
"$",
"this",
"->",
"statement",
"=",
"substr",
"(",
"$",
"this",
"->",
"statement",
",",
"0",
",",
"$",
"placeholderPos",
")",
".",
"'?'",
".",
"substr",
"(",
"$",
"this",
"->",
"statement",
",",
"$",
"placeholderPos",
"+",
"$",
"placeholderLength",
")",
";",
"// Decrement statement length.",
"$",
"statementLength",
"=",
"$",
"statementLength",
"-",
"$",
"placeholderLength",
"+",
"1",
";",
"// Increment position parameter.",
"$",
"positionalParameter",
"++",
";",
"}",
"}",
"}"
] |
Rewrite the named statement and parameters to positional.
Example:
- before:
- statement: SELECT * FROM foo WHERE bar = :bar
- parameters: array()
- after:
- statement: SELECT * FROM foo WHERE bar = ?
- parameters: array(':bar' => array(1))
|
[
"Rewrite",
"the",
"named",
"statement",
"and",
"parameters",
"to",
"positional",
"."
] |
d0b8c3551922d696836487aa0eb1bd74014edcd4
|
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Driver/Statement/StatementRewriter.php#L91-L143
|
train
|
fridge-project/dbal
|
src/Fridge/DBAL/Driver/Statement/StatementRewriter.php
|
StatementRewriter.isValidPlaceholderCharacter
|
private function isValidPlaceholderCharacter($character)
{
$asciiCode = ord($character);
return (($asciiCode >= 48) && ($asciiCode <= 57))
|| (($asciiCode >= 65) && ($asciiCode <= 90))
|| (($asciiCode >= 97) && ($asciiCode <= 122));
}
|
php
|
private function isValidPlaceholderCharacter($character)
{
$asciiCode = ord($character);
return (($asciiCode >= 48) && ($asciiCode <= 57))
|| (($asciiCode >= 65) && ($asciiCode <= 90))
|| (($asciiCode >= 97) && ($asciiCode <= 122));
}
|
[
"private",
"function",
"isValidPlaceholderCharacter",
"(",
"$",
"character",
")",
"{",
"$",
"asciiCode",
"=",
"ord",
"(",
"$",
"character",
")",
";",
"return",
"(",
"(",
"$",
"asciiCode",
">=",
"48",
")",
"&&",
"(",
"$",
"asciiCode",
"<=",
"57",
")",
")",
"||",
"(",
"(",
"$",
"asciiCode",
">=",
"65",
")",
"&&",
"(",
"$",
"asciiCode",
"<=",
"90",
")",
")",
"||",
"(",
"(",
"$",
"asciiCode",
">=",
"97",
")",
"&&",
"(",
"$",
"asciiCode",
"<=",
"122",
")",
")",
";",
"}"
] |
Checks if the character is a valid placeholder character.
@param string $character The character to check.
@return boolean TRUE if the character is a valid placeholder character else FALSE.
|
[
"Checks",
"if",
"the",
"character",
"is",
"a",
"valid",
"placeholder",
"character",
"."
] |
d0b8c3551922d696836487aa0eb1bd74014edcd4
|
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Driver/Statement/StatementRewriter.php#L152-L159
|
train
|
porkchopsandwiches/silex-utilities
|
lib/src/PorkChopSandwiches/Silex/Utilities/Arrays.php
|
Arrays.deepMerge
|
public function deepMerge (array $mergee, array $merger) {
$merged = $mergee;
foreach ($merger as $key => &$value) {
# If key exists an an array on both sides, deep merge
if (array_key_exists($key, $merged) && is_array($value) && is_array($merged[$key])) {
$merged[$key] = $this -> deepMerge($merged[$key], $value);
# Otherwise, simply replace
} else {
$merged[$key] = $value;
}
}
return $merged;
}
|
php
|
public function deepMerge (array $mergee, array $merger) {
$merged = $mergee;
foreach ($merger as $key => &$value) {
# If key exists an an array on both sides, deep merge
if (array_key_exists($key, $merged) && is_array($value) && is_array($merged[$key])) {
$merged[$key] = $this -> deepMerge($merged[$key], $value);
# Otherwise, simply replace
} else {
$merged[$key] = $value;
}
}
return $merged;
}
|
[
"public",
"function",
"deepMerge",
"(",
"array",
"$",
"mergee",
",",
"array",
"$",
"merger",
")",
"{",
"$",
"merged",
"=",
"$",
"mergee",
";",
"foreach",
"(",
"$",
"merger",
"as",
"$",
"key",
"=>",
"&",
"$",
"value",
")",
"{",
"# If key exists an an array on both sides, deep merge",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"merged",
")",
"&&",
"is_array",
"(",
"$",
"value",
")",
"&&",
"is_array",
"(",
"$",
"merged",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"merged",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"deepMerge",
"(",
"$",
"merged",
"[",
"$",
"key",
"]",
",",
"$",
"value",
")",
";",
"# Otherwise, simply replace",
"}",
"else",
"{",
"$",
"merged",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"merged",
";",
"}"
] |
Performs an array merge, but when both values for a key are arrays, a deep merge will occur, retaining the unique keys of both without changing the value types.
@example
$a = array(1 => 2, 3 => array(4 => 5, 6 => 7));
$b = array(3 => array(4 => "Four"));
deepMerge($a, $b) == array(1 => 2, 3 => array(4 => "Four", 6 => 7));
@param array &$mergee The array whose values will be overridden during merging.
@param array &$merger The array whose values will override during merging.
@return array
|
[
"Performs",
"an",
"array",
"merge",
"but",
"when",
"both",
"values",
"for",
"a",
"key",
"are",
"arrays",
"a",
"deep",
"merge",
"will",
"occur",
"retaining",
"the",
"unique",
"keys",
"of",
"both",
"without",
"changing",
"the",
"value",
"types",
"."
] |
756d041f40c7980b1763c08004f1f405bfc74af6
|
https://github.com/porkchopsandwiches/silex-utilities/blob/756d041f40c7980b1763c08004f1f405bfc74af6/lib/src/PorkChopSandwiches/Silex/Utilities/Arrays.php#L121-L137
|
train
|
erenmustafaozdal/laravel-modules-base
|
src/Controllers/BaseController.php
|
BaseController.changeOptions
|
protected function changeOptions($category)
{
$thumbnails = $category->ancestorsAndSelf()->with('thumbnails')->get()->map(function($item)
{
return $item->thumbnails->keyBy('slug')->map(function($item)
{
return [ 'width' => $item->photo_width, 'height' => $item->photo_height ];
});
})->reduce(function($carry,$item)
{
return $carry->merge($item);
},collect())->toArray();
Config::set('laravel-document-module.document.uploads.photo.aspect_ratio', $category->aspect_ratio);
Config::set('laravel-document-module.document.uploads.photo.thumbnails', $thumbnails);
}
|
php
|
protected function changeOptions($category)
{
$thumbnails = $category->ancestorsAndSelf()->with('thumbnails')->get()->map(function($item)
{
return $item->thumbnails->keyBy('slug')->map(function($item)
{
return [ 'width' => $item->photo_width, 'height' => $item->photo_height ];
});
})->reduce(function($carry,$item)
{
return $carry->merge($item);
},collect())->toArray();
Config::set('laravel-document-module.document.uploads.photo.aspect_ratio', $category->aspect_ratio);
Config::set('laravel-document-module.document.uploads.photo.thumbnails', $thumbnails);
}
|
[
"protected",
"function",
"changeOptions",
"(",
"$",
"category",
")",
"{",
"$",
"thumbnails",
"=",
"$",
"category",
"->",
"ancestorsAndSelf",
"(",
")",
"->",
"with",
"(",
"'thumbnails'",
")",
"->",
"get",
"(",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"item",
")",
"{",
"return",
"$",
"item",
"->",
"thumbnails",
"->",
"keyBy",
"(",
"'slug'",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"item",
")",
"{",
"return",
"[",
"'width'",
"=>",
"$",
"item",
"->",
"photo_width",
",",
"'height'",
"=>",
"$",
"item",
"->",
"photo_height",
"]",
";",
"}",
")",
";",
"}",
")",
"->",
"reduce",
"(",
"function",
"(",
"$",
"carry",
",",
"$",
"item",
")",
"{",
"return",
"$",
"carry",
"->",
"merge",
"(",
"$",
"item",
")",
";",
"}",
",",
"collect",
"(",
")",
")",
"->",
"toArray",
"(",
")",
";",
"Config",
"::",
"set",
"(",
"'laravel-document-module.document.uploads.photo.aspect_ratio'",
",",
"$",
"category",
"->",
"aspect_ratio",
")",
";",
"Config",
"::",
"set",
"(",
"'laravel-document-module.document.uploads.photo.thumbnails'",
",",
"$",
"thumbnails",
")",
";",
"}"
] |
change options with model category
@param $category
@return void
|
[
"change",
"options",
"with",
"model",
"category"
] |
c26600543817642926bcf16ada84009e00d784e0
|
https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Controllers/BaseController.php#L87-L101
|
train
|
t3v/t3v_core
|
Classes/Service/FileService.php
|
FileService.saveFile
|
public static function saveFile($file, string $uploadsFolderPath) {
if (!empty($file) && is_array($file) && !empty($uploadsFolderPath)) {
$fileName = $file['name'];
$temporaryFileName = $file['tmp_name'];
if (GeneralUtility::verifyFilenameAgainstDenyPattern($fileName)) {
$uploadsFolderPath = GeneralUtility::getFileAbsFileName($uploadsFolderPath);
$fileName = self::cleanFileName($fileName);
$newFileName = self::getUniqueFileName($fileName, $uploadsFolderPath);
$fileCouldBeUploaded = GeneralUtility::upload_copy_move($temporaryFileName, $newFileName);
if ($fileCouldBeUploaded) {
return $newFileName;
}
} else {
throw new InvalidFileNameException('File name could not be verified against deny pattern.', 1496958715);
}
}
return null;
}
|
php
|
public static function saveFile($file, string $uploadsFolderPath) {
if (!empty($file) && is_array($file) && !empty($uploadsFolderPath)) {
$fileName = $file['name'];
$temporaryFileName = $file['tmp_name'];
if (GeneralUtility::verifyFilenameAgainstDenyPattern($fileName)) {
$uploadsFolderPath = GeneralUtility::getFileAbsFileName($uploadsFolderPath);
$fileName = self::cleanFileName($fileName);
$newFileName = self::getUniqueFileName($fileName, $uploadsFolderPath);
$fileCouldBeUploaded = GeneralUtility::upload_copy_move($temporaryFileName, $newFileName);
if ($fileCouldBeUploaded) {
return $newFileName;
}
} else {
throw new InvalidFileNameException('File name could not be verified against deny pattern.', 1496958715);
}
}
return null;
}
|
[
"public",
"static",
"function",
"saveFile",
"(",
"$",
"file",
",",
"string",
"$",
"uploadsFolderPath",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"file",
")",
"&&",
"is_array",
"(",
"$",
"file",
")",
"&&",
"!",
"empty",
"(",
"$",
"uploadsFolderPath",
")",
")",
"{",
"$",
"fileName",
"=",
"$",
"file",
"[",
"'name'",
"]",
";",
"$",
"temporaryFileName",
"=",
"$",
"file",
"[",
"'tmp_name'",
"]",
";",
"if",
"(",
"GeneralUtility",
"::",
"verifyFilenameAgainstDenyPattern",
"(",
"$",
"fileName",
")",
")",
"{",
"$",
"uploadsFolderPath",
"=",
"GeneralUtility",
"::",
"getFileAbsFileName",
"(",
"$",
"uploadsFolderPath",
")",
";",
"$",
"fileName",
"=",
"self",
"::",
"cleanFileName",
"(",
"$",
"fileName",
")",
";",
"$",
"newFileName",
"=",
"self",
"::",
"getUniqueFileName",
"(",
"$",
"fileName",
",",
"$",
"uploadsFolderPath",
")",
";",
"$",
"fileCouldBeUploaded",
"=",
"GeneralUtility",
"::",
"upload_copy_move",
"(",
"$",
"temporaryFileName",
",",
"$",
"newFileName",
")",
";",
"if",
"(",
"$",
"fileCouldBeUploaded",
")",
"{",
"return",
"$",
"newFileName",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"InvalidFileNameException",
"(",
"'File name could not be verified against deny pattern.'",
",",
"1496958715",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Saves a file to an uploads folder.
@param object $file The file object
@param string $uploadsFolderPath The uploads folder path
@return string|null The file name of the saved file or null if the file could not be saved
@throws \TYPO3\CMS\Core\Resource\Exception\InvalidFileNameException
|
[
"Saves",
"a",
"file",
"to",
"an",
"uploads",
"folder",
"."
] |
8c04b7688cc2773f11fcc87fda3f7cd53d80a980
|
https://github.com/t3v/t3v_core/blob/8c04b7688cc2773f11fcc87fda3f7cd53d80a980/Classes/Service/FileService.php#L56-L76
|
train
|
t3v/t3v_core
|
Classes/Service/FileService.php
|
FileService.cleanFileName
|
public static function cleanFileName(string $fileName, array $rulesets = self::FILE_NAME_RULESETS, string $separator = '-'): string {
$slugify = new Slugify(['rulesets' => $rulesets, 'separator' => $separator]);
$name = $slugify->slugify(pathinfo($fileName, PATHINFO_FILENAME));
$extension = pathinfo($fileName, PATHINFO_EXTENSION);
if (empty($name)) {
$name = uniqid(self::EMPTY_FILE_NAME_PREFIX, true);
}
return mb_strtolower($name . '.' . $extension);
}
|
php
|
public static function cleanFileName(string $fileName, array $rulesets = self::FILE_NAME_RULESETS, string $separator = '-'): string {
$slugify = new Slugify(['rulesets' => $rulesets, 'separator' => $separator]);
$name = $slugify->slugify(pathinfo($fileName, PATHINFO_FILENAME));
$extension = pathinfo($fileName, PATHINFO_EXTENSION);
if (empty($name)) {
$name = uniqid(self::EMPTY_FILE_NAME_PREFIX, true);
}
return mb_strtolower($name . '.' . $extension);
}
|
[
"public",
"static",
"function",
"cleanFileName",
"(",
"string",
"$",
"fileName",
",",
"array",
"$",
"rulesets",
"=",
"self",
"::",
"FILE_NAME_RULESETS",
",",
"string",
"$",
"separator",
"=",
"'-'",
")",
":",
"string",
"{",
"$",
"slugify",
"=",
"new",
"Slugify",
"(",
"[",
"'rulesets'",
"=>",
"$",
"rulesets",
",",
"'separator'",
"=>",
"$",
"separator",
"]",
")",
";",
"$",
"name",
"=",
"$",
"slugify",
"->",
"slugify",
"(",
"pathinfo",
"(",
"$",
"fileName",
",",
"PATHINFO_FILENAME",
")",
")",
";",
"$",
"extension",
"=",
"pathinfo",
"(",
"$",
"fileName",
",",
"PATHINFO_EXTENSION",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"$",
"name",
"=",
"uniqid",
"(",
"self",
"::",
"EMPTY_FILE_NAME_PREFIX",
",",
"true",
")",
";",
"}",
"return",
"mb_strtolower",
"(",
"$",
"name",
".",
"'.'",
".",
"$",
"extension",
")",
";",
"}"
] |
Cleans a file name.
@param string $fileName The file name
@param array $rulesets The optional rulesets, defaults to `FileService::FILE_NAME_RULESETS`
@param string $separator The optional separator, defaults to `-`
@return string The cleaned file name
|
[
"Cleans",
"a",
"file",
"name",
"."
] |
8c04b7688cc2773f11fcc87fda3f7cd53d80a980
|
https://github.com/t3v/t3v_core/blob/8c04b7688cc2773f11fcc87fda3f7cd53d80a980/Classes/Service/FileService.php#L96-L106
|
train
|
t3v/t3v_core
|
Classes/Service/FileService.php
|
FileService.normalizeFileName
|
public static function normalizeFileName(string $fileName, array $rulesets = self::FILE_NAME_RULESETS, string $separator = '-'): string {
return self::cleanFileName($fileName, $rulesets, $separator);
}
|
php
|
public static function normalizeFileName(string $fileName, array $rulesets = self::FILE_NAME_RULESETS, string $separator = '-'): string {
return self::cleanFileName($fileName, $rulesets, $separator);
}
|
[
"public",
"static",
"function",
"normalizeFileName",
"(",
"string",
"$",
"fileName",
",",
"array",
"$",
"rulesets",
"=",
"self",
"::",
"FILE_NAME_RULESETS",
",",
"string",
"$",
"separator",
"=",
"'-'",
")",
":",
"string",
"{",
"return",
"self",
"::",
"cleanFileName",
"(",
"$",
"fileName",
",",
"$",
"rulesets",
",",
"$",
"separator",
")",
";",
"}"
] |
Normalizes a file name, alias for `cleanFileName`.
@param string $fileName The file name
@param array $rulesets The optional rulesets, defaults to `FileService::FILE_NAME_RULESETS`
@param string $separator The optional separator, defaults to `-`
@return string The normalized file name
|
[
"Normalizes",
"a",
"file",
"name",
"alias",
"for",
"cleanFileName",
"."
] |
8c04b7688cc2773f11fcc87fda3f7cd53d80a980
|
https://github.com/t3v/t3v_core/blob/8c04b7688cc2773f11fcc87fda3f7cd53d80a980/Classes/Service/FileService.php#L116-L118
|
train
|
t3v/t3v_core
|
Classes/Service/FileService.php
|
FileService.getUniqueFileName
|
public static function getUniqueFileName(string $fileName, string $directory): string {
$basicFileUtility = GeneralUtility::makeInstance(BasicFileUtility::class);
return $basicFileUtility->getUniqueName($fileName, $directory);
}
|
php
|
public static function getUniqueFileName(string $fileName, string $directory): string {
$basicFileUtility = GeneralUtility::makeInstance(BasicFileUtility::class);
return $basicFileUtility->getUniqueName($fileName, $directory);
}
|
[
"public",
"static",
"function",
"getUniqueFileName",
"(",
"string",
"$",
"fileName",
",",
"string",
"$",
"directory",
")",
":",
"string",
"{",
"$",
"basicFileUtility",
"=",
"GeneralUtility",
"::",
"makeInstance",
"(",
"BasicFileUtility",
"::",
"class",
")",
";",
"return",
"$",
"basicFileUtility",
"->",
"getUniqueName",
"(",
"$",
"fileName",
",",
"$",
"directory",
")",
";",
"}"
] |
Gets an unique file name.
@param string $fileName The file name
@param string $directory The directory for which to return a unique file name for, MUST be a valid directory and should be absolute
@return string The unique file name
|
[
"Gets",
"an",
"unique",
"file",
"name",
"."
] |
8c04b7688cc2773f11fcc87fda3f7cd53d80a980
|
https://github.com/t3v/t3v_core/blob/8c04b7688cc2773f11fcc87fda3f7cd53d80a980/Classes/Service/FileService.php#L127-L131
|
train
|
sil-project/VarietyBundle
|
src/Entity/Family.php
|
Family.addGenus
|
public function addGenus(\Librinfo\VarietiesBundle\Entity\Genus $genus)
{
$genus->setFamily($this);
$this->genuses->add($genus);
return $this;
}
|
php
|
public function addGenus(\Librinfo\VarietiesBundle\Entity\Genus $genus)
{
$genus->setFamily($this);
$this->genuses->add($genus);
return $this;
}
|
[
"public",
"function",
"addGenus",
"(",
"\\",
"Librinfo",
"\\",
"VarietiesBundle",
"\\",
"Entity",
"\\",
"Genus",
"$",
"genus",
")",
"{",
"$",
"genus",
"->",
"setFamily",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"genuses",
"->",
"add",
"(",
"$",
"genus",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Add genus.
@param \Librinfo\VarietiesBundle\Entity\Genus $genus
@return Family
|
[
"Add",
"genus",
"."
] |
e9508ce13a4bb277d10bdcd925fdb84bc01f453f
|
https://github.com/sil-project/VarietyBundle/blob/e9508ce13a4bb277d10bdcd925fdb84bc01f453f/src/Entity/Family.php#L124-L130
|
train
|
sil-project/VarietyBundle
|
src/Entity/Family.php
|
Family.removeGenus
|
public function removeGenus(\Librinfo\VarietiesBundle\Entity\Genus $genus)
{
return $this->genuses->removeElement($genus);
}
|
php
|
public function removeGenus(\Librinfo\VarietiesBundle\Entity\Genus $genus)
{
return $this->genuses->removeElement($genus);
}
|
[
"public",
"function",
"removeGenus",
"(",
"\\",
"Librinfo",
"\\",
"VarietiesBundle",
"\\",
"Entity",
"\\",
"Genus",
"$",
"genus",
")",
"{",
"return",
"$",
"this",
"->",
"genuses",
"->",
"removeElement",
"(",
"$",
"genus",
")",
";",
"}"
] |
Remove genus.
@param \Librinfo\VarietiesBundle\Entity\Genus $genus
@return bool tRUE if this collection contained the specified element, FALSE otherwise
|
[
"Remove",
"genus",
"."
] |
e9508ce13a4bb277d10bdcd925fdb84bc01f453f
|
https://github.com/sil-project/VarietyBundle/blob/e9508ce13a4bb277d10bdcd925fdb84bc01f453f/src/Entity/Family.php#L139-L142
|
train
|
ringoteam/RingoPhpRedmonBundle
|
Command/LoggerCommand.php
|
LoggerCommand.execute
|
protected function execute(InputInterface $input, OutputInterface $output)
{
$logger = $this->getContainer()->get('ringo_php_redmon.instance_logger');
$manager = $this->getContainer()->get('ringo_php_redmon.instance_manager');
$instances = $manager->findAll();
if(is_array($instances)) {
foreach($instances as $instance) {
$logger
->setInstance($instance)
->execute();
}
}
}
|
php
|
protected function execute(InputInterface $input, OutputInterface $output)
{
$logger = $this->getContainer()->get('ringo_php_redmon.instance_logger');
$manager = $this->getContainer()->get('ringo_php_redmon.instance_manager');
$instances = $manager->findAll();
if(is_array($instances)) {
foreach($instances as $instance) {
$logger
->setInstance($instance)
->execute();
}
}
}
|
[
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"logger",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'ringo_php_redmon.instance_logger'",
")",
";",
"$",
"manager",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'ringo_php_redmon.instance_manager'",
")",
";",
"$",
"instances",
"=",
"$",
"manager",
"->",
"findAll",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"instances",
")",
")",
"{",
"foreach",
"(",
"$",
"instances",
"as",
"$",
"instance",
")",
"{",
"$",
"logger",
"->",
"setInstance",
"(",
"$",
"instance",
")",
"->",
"execute",
"(",
")",
";",
"}",
"}",
"}"
] |
Execute task
Get all redis instances and log some of infos
@param \Symfony\Component\Console\Input\InputInterface $input
@param \Symfony\Component\Console\Output\OutputInterface $output
|
[
"Execute",
"task",
"Get",
"all",
"redis",
"instances",
"and",
"log",
"some",
"of",
"infos"
] |
9aab989a9bee9e6152ec19f8a30bc24f3bde6012
|
https://github.com/ringoteam/RingoPhpRedmonBundle/blob/9aab989a9bee9e6152ec19f8a30bc24f3bde6012/Command/LoggerCommand.php#L45-L58
|
train
|
wb-crowdfusion/crowdfusion
|
system/core/classes/libraries/utils/FileSystemUtils.php
|
FileSystemUtils.createWorkingDirectory
|
public static function createWorkingDirectory()
{
$workdir = sys_get_temp_dir() . '/tmp-' . session_id() . '/';
self::recursiveMkdir($workdir, 0777);
//@chmod($workdir,0777);
if (!is_dir($workdir)) {
throw new Exception("cannot create directory: " . $workdir);
}
return $workdir;
}
|
php
|
public static function createWorkingDirectory()
{
$workdir = sys_get_temp_dir() . '/tmp-' . session_id() . '/';
self::recursiveMkdir($workdir, 0777);
//@chmod($workdir,0777);
if (!is_dir($workdir)) {
throw new Exception("cannot create directory: " . $workdir);
}
return $workdir;
}
|
[
"public",
"static",
"function",
"createWorkingDirectory",
"(",
")",
"{",
"$",
"workdir",
"=",
"sys_get_temp_dir",
"(",
")",
".",
"'/tmp-'",
".",
"session_id",
"(",
")",
".",
"'/'",
";",
"self",
"::",
"recursiveMkdir",
"(",
"$",
"workdir",
",",
"0777",
")",
";",
"//@chmod($workdir,0777);",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"workdir",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"cannot create directory: \"",
".",
"$",
"workdir",
")",
";",
"}",
"return",
"$",
"workdir",
";",
"}"
] |
Creates a unique temporary directory and returns the absolute path
@return string the absolute path to the temporary directory
|
[
"Creates",
"a",
"unique",
"temporary",
"directory",
"and",
"returns",
"the",
"absolute",
"path"
] |
8cad7988f046a6fefbed07d026cb4ae6706c1217
|
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/utils/FileSystemUtils.php#L973-L985
|
train
|
wb-crowdfusion/crowdfusion
|
system/core/classes/libraries/utils/FileSystemUtils.php
|
FileSystemUtils.recursiveRmdir
|
public static function recursiveRmdir($path, $removeParent = true)
{
if (!file_exists($path))
return true;
if (!is_dir($path))
return @unlink($path);
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::CHILD_FIRST);
foreach ($objects as $item) {
if ($item == '.' || $item == '..')
continue;
if(!is_dir($item))
{
if (!@unlink($item))
return false;
} else {
if(!@rmdir($item))
return false;
}
}
return $removeParent ? rmdir($path) : true;
}
|
php
|
public static function recursiveRmdir($path, $removeParent = true)
{
if (!file_exists($path))
return true;
if (!is_dir($path))
return @unlink($path);
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::CHILD_FIRST);
foreach ($objects as $item) {
if ($item == '.' || $item == '..')
continue;
if(!is_dir($item))
{
if (!@unlink($item))
return false;
} else {
if(!@rmdir($item))
return false;
}
}
return $removeParent ? rmdir($path) : true;
}
|
[
"public",
"static",
"function",
"recursiveRmdir",
"(",
"$",
"path",
",",
"$",
"removeParent",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"return",
"true",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"path",
")",
")",
"return",
"@",
"unlink",
"(",
"$",
"path",
")",
";",
"$",
"objects",
"=",
"new",
"RecursiveIteratorIterator",
"(",
"new",
"RecursiveDirectoryIterator",
"(",
"$",
"path",
")",
",",
"RecursiveIteratorIterator",
"::",
"CHILD_FIRST",
")",
";",
"foreach",
"(",
"$",
"objects",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"==",
"'.'",
"||",
"$",
"item",
"==",
"'..'",
")",
"continue",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"item",
")",
")",
"{",
"if",
"(",
"!",
"@",
"unlink",
"(",
"$",
"item",
")",
")",
"return",
"false",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"@",
"rmdir",
"(",
"$",
"item",
")",
")",
"return",
"false",
";",
"}",
"}",
"return",
"$",
"removeParent",
"?",
"rmdir",
"(",
"$",
"path",
")",
":",
"true",
";",
"}"
] |
Recursively remove a directory and its contents.
@param string $path The directory to remove
@param boolean $removeParent If false, then remove only the contents of the directory at $path.
Default: true
@return boolean true on success
|
[
"Recursively",
"remove",
"a",
"directory",
"and",
"its",
"contents",
"."
] |
8cad7988f046a6fefbed07d026cb4ae6706c1217
|
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/utils/FileSystemUtils.php#L1089-L1112
|
train
|
wb-crowdfusion/crowdfusion
|
system/core/classes/libraries/utils/FileSystemUtils.php
|
FileSystemUtils.secureTmpname
|
public static function secureTmpname($dir = null, $prefix = 'tmp', $postfix = '.tmp')
{
// validate arguments
if (!(isset ($postfix) && is_string($postfix)))
return false;
if (!(isset ($prefix) && is_string($prefix)))
return false;
if (!isset ($dir))
$dir = getcwd();
// find a temporary name
$tries = 1;
do {
// get a known, unique temporary file name
$sysFileName = tempnam($dir, $prefix);
if ($sysFileName === false)
return false;
// tack on the extension
$newFileName = $sysFileName . $postfix;
if ($sysFileName == $newFileName)
return $sysFileName;
// move or point the created temporary file to the new filename
// NOTE: these fail if the new file name exist
$newFileCreated = @rename($sysFileName, $newFileName);
if ($newFileCreated)
return $newFileName;
unlink($sysFileName);
$tries++;
} while ($tries <= 5);
return false;
}
|
php
|
public static function secureTmpname($dir = null, $prefix = 'tmp', $postfix = '.tmp')
{
// validate arguments
if (!(isset ($postfix) && is_string($postfix)))
return false;
if (!(isset ($prefix) && is_string($prefix)))
return false;
if (!isset ($dir))
$dir = getcwd();
// find a temporary name
$tries = 1;
do {
// get a known, unique temporary file name
$sysFileName = tempnam($dir, $prefix);
if ($sysFileName === false)
return false;
// tack on the extension
$newFileName = $sysFileName . $postfix;
if ($sysFileName == $newFileName)
return $sysFileName;
// move or point the created temporary file to the new filename
// NOTE: these fail if the new file name exist
$newFileCreated = @rename($sysFileName, $newFileName);
if ($newFileCreated)
return $newFileName;
unlink($sysFileName);
$tries++;
} while ($tries <= 5);
return false;
}
|
[
"public",
"static",
"function",
"secureTmpname",
"(",
"$",
"dir",
"=",
"null",
",",
"$",
"prefix",
"=",
"'tmp'",
",",
"$",
"postfix",
"=",
"'.tmp'",
")",
"{",
"// validate arguments",
"if",
"(",
"!",
"(",
"isset",
"(",
"$",
"postfix",
")",
"&&",
"is_string",
"(",
"$",
"postfix",
")",
")",
")",
"return",
"false",
";",
"if",
"(",
"!",
"(",
"isset",
"(",
"$",
"prefix",
")",
"&&",
"is_string",
"(",
"$",
"prefix",
")",
")",
")",
"return",
"false",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"dir",
")",
")",
"$",
"dir",
"=",
"getcwd",
"(",
")",
";",
"// find a temporary name",
"$",
"tries",
"=",
"1",
";",
"do",
"{",
"// get a known, unique temporary file name",
"$",
"sysFileName",
"=",
"tempnam",
"(",
"$",
"dir",
",",
"$",
"prefix",
")",
";",
"if",
"(",
"$",
"sysFileName",
"===",
"false",
")",
"return",
"false",
";",
"// tack on the extension",
"$",
"newFileName",
"=",
"$",
"sysFileName",
".",
"$",
"postfix",
";",
"if",
"(",
"$",
"sysFileName",
"==",
"$",
"newFileName",
")",
"return",
"$",
"sysFileName",
";",
"// move or point the created temporary file to the new filename",
"// NOTE: these fail if the new file name exist",
"$",
"newFileCreated",
"=",
"@",
"rename",
"(",
"$",
"sysFileName",
",",
"$",
"newFileName",
")",
";",
"if",
"(",
"$",
"newFileCreated",
")",
"return",
"$",
"newFileName",
";",
"unlink",
"(",
"$",
"sysFileName",
")",
";",
"$",
"tries",
"++",
";",
"}",
"while",
"(",
"$",
"tries",
"<=",
"5",
")",
";",
"return",
"false",
";",
"}"
] |
Creates a temp file with a specific extension.
Creating a temporary file with a specific extension is a common
requirement on dynamic websites. Largely this need arises from
Microsoft browsers that identify a downloaded file's mimetype based
on the file's extension.
No single PHP function creates a temporary filename with a specific
extension, and, as has been shown, there are race conditions involved
unless you use the PHP atomic primitives.
I use only primitives below and exploit OS dependent behaviour to
securely create a file with a specific postfix, prefix, and directory.
@param string $dir Optional. The directory in which to create the new file
@param string $prefix Default 'tmp'. The prefix of the generated temporary filename.
@param string $postfix Default '.tmp'. The extension or postfix for the generated filename.
@see http://us.php.net/manual/en/function.tempnam.php#42052
@author bishop
@return string the filename of the new file
|
[
"Creates",
"a",
"temp",
"file",
"with",
"a",
"specific",
"extension",
"."
] |
8cad7988f046a6fefbed07d026cb4ae6706c1217
|
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/utils/FileSystemUtils.php#L1138-L1174
|
train
|
niels-nijens/protocol-stream
|
src/StreamManager.php
|
StreamManager.registerStream
|
public function registerStream(StreamInterface $stream, $replaceWrapper = false)
{
$protocol = $stream->getProtocol();
if ($replaceWrapper === true && in_array($protocol, stream_get_wrappers())) {
stream_wrapper_unregister($protocol);
}
if (stream_wrapper_register($protocol, $stream->getStreamWrapperClass())) {
self::$streams[$protocol] = $stream;
}
return $this;
}
|
php
|
public function registerStream(StreamInterface $stream, $replaceWrapper = false)
{
$protocol = $stream->getProtocol();
if ($replaceWrapper === true && in_array($protocol, stream_get_wrappers())) {
stream_wrapper_unregister($protocol);
}
if (stream_wrapper_register($protocol, $stream->getStreamWrapperClass())) {
self::$streams[$protocol] = $stream;
}
return $this;
}
|
[
"public",
"function",
"registerStream",
"(",
"StreamInterface",
"$",
"stream",
",",
"$",
"replaceWrapper",
"=",
"false",
")",
"{",
"$",
"protocol",
"=",
"$",
"stream",
"->",
"getProtocol",
"(",
")",
";",
"if",
"(",
"$",
"replaceWrapper",
"===",
"true",
"&&",
"in_array",
"(",
"$",
"protocol",
",",
"stream_get_wrappers",
"(",
")",
")",
")",
"{",
"stream_wrapper_unregister",
"(",
"$",
"protocol",
")",
";",
"}",
"if",
"(",
"stream_wrapper_register",
"(",
"$",
"protocol",
",",
"$",
"stream",
"->",
"getStreamWrapperClass",
"(",
")",
")",
")",
"{",
"self",
"::",
"$",
"streams",
"[",
"$",
"protocol",
"]",
"=",
"$",
"stream",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Registers stream instance for a protocol.
@param StreamInterface $stream
@param bool $replaceWrapper
@return self
|
[
"Registers",
"stream",
"instance",
"for",
"a",
"protocol",
"."
] |
c45b8d282bbb83f2a3d17adeb1d66500c14a868c
|
https://github.com/niels-nijens/protocol-stream/blob/c45b8d282bbb83f2a3d17adeb1d66500c14a868c/src/StreamManager.php#L39-L51
|
train
|
niels-nijens/protocol-stream
|
src/StreamManager.php
|
StreamManager.unregisterStream
|
public function unregisterStream($protocol)
{
if (isset(self::$streams[$protocol])) {
$result = stream_wrapper_unregister($protocol);
if ($result === true) {
unset(self::$streams[$protocol]);
}
}
return $this;
}
|
php
|
public function unregisterStream($protocol)
{
if (isset(self::$streams[$protocol])) {
$result = stream_wrapper_unregister($protocol);
if ($result === true) {
unset(self::$streams[$protocol]);
}
}
return $this;
}
|
[
"public",
"function",
"unregisterStream",
"(",
"$",
"protocol",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"streams",
"[",
"$",
"protocol",
"]",
")",
")",
"{",
"$",
"result",
"=",
"stream_wrapper_unregister",
"(",
"$",
"protocol",
")",
";",
"if",
"(",
"$",
"result",
"===",
"true",
")",
"{",
"unset",
"(",
"self",
"::",
"$",
"streams",
"[",
"$",
"protocol",
"]",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Unregisters a stream instance by protocol.
@param string $protocol
@return self
|
[
"Unregisters",
"a",
"stream",
"instance",
"by",
"protocol",
"."
] |
c45b8d282bbb83f2a3d17adeb1d66500c14a868c
|
https://github.com/niels-nijens/protocol-stream/blob/c45b8d282bbb83f2a3d17adeb1d66500c14a868c/src/StreamManager.php#L60-L70
|
train
|
kkthek/diqa-util
|
src/Util/FileLinkUtils.php
|
FileLinkUtils.ImageOverlayLinkBegin
|
public static function ImageOverlayLinkBegin($dummy, \Title $target, &$text, &$customAttribs, &$query, &$options, &$ret) {
global $wgDIQAImageOverlayWhitelist;
global $wgDIQADownloadWhitelist;
if (!self::isImage($target->mNamespace)) {
// don't rewrite links not pointing to images
return true;
}
$file = wfFindFile($target);
if ( !$file ) {
// don't rewrite links to non-existing files
return true;
}
$ext = $file->getExtension();
if ( in_array( $ext, $wgDIQAImageOverlayWhitelist )) {
// open in overlay
$ret = Html::rawElement (
'a',
array ( 'href' => $file->getFullURL(), 'class' => 'imageOverlay' ),
self::getDisplayTitle($target) );
return false;
}
if ( in_array( $ext, $wgDIQADownloadWhitelist )) {
// download
$ret = Html::rawElement (
'a',
array ( 'href' => $file->getFullURL() ),
self::getDisplayTitle($target) );
return false;
}
// don't rewrite links to files with inappropriate extensions
return true;
}
|
php
|
public static function ImageOverlayLinkBegin($dummy, \Title $target, &$text, &$customAttribs, &$query, &$options, &$ret) {
global $wgDIQAImageOverlayWhitelist;
global $wgDIQADownloadWhitelist;
if (!self::isImage($target->mNamespace)) {
// don't rewrite links not pointing to images
return true;
}
$file = wfFindFile($target);
if ( !$file ) {
// don't rewrite links to non-existing files
return true;
}
$ext = $file->getExtension();
if ( in_array( $ext, $wgDIQAImageOverlayWhitelist )) {
// open in overlay
$ret = Html::rawElement (
'a',
array ( 'href' => $file->getFullURL(), 'class' => 'imageOverlay' ),
self::getDisplayTitle($target) );
return false;
}
if ( in_array( $ext, $wgDIQADownloadWhitelist )) {
// download
$ret = Html::rawElement (
'a',
array ( 'href' => $file->getFullURL() ),
self::getDisplayTitle($target) );
return false;
}
// don't rewrite links to files with inappropriate extensions
return true;
}
|
[
"public",
"static",
"function",
"ImageOverlayLinkBegin",
"(",
"$",
"dummy",
",",
"\\",
"Title",
"$",
"target",
",",
"&",
"$",
"text",
",",
"&",
"$",
"customAttribs",
",",
"&",
"$",
"query",
",",
"&",
"$",
"options",
",",
"&",
"$",
"ret",
")",
"{",
"global",
"$",
"wgDIQAImageOverlayWhitelist",
";",
"global",
"$",
"wgDIQADownloadWhitelist",
";",
"if",
"(",
"!",
"self",
"::",
"isImage",
"(",
"$",
"target",
"->",
"mNamespace",
")",
")",
"{",
"// don't rewrite links not pointing to images",
"return",
"true",
";",
"}",
"$",
"file",
"=",
"wfFindFile",
"(",
"$",
"target",
")",
";",
"if",
"(",
"!",
"$",
"file",
")",
"{",
"// don't rewrite links to non-existing files",
"return",
"true",
";",
"}",
"$",
"ext",
"=",
"$",
"file",
"->",
"getExtension",
"(",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"ext",
",",
"$",
"wgDIQAImageOverlayWhitelist",
")",
")",
"{",
"// open in overlay",
"$",
"ret",
"=",
"Html",
"::",
"rawElement",
"(",
"'a'",
",",
"array",
"(",
"'href'",
"=>",
"$",
"file",
"->",
"getFullURL",
"(",
")",
",",
"'class'",
"=>",
"'imageOverlay'",
")",
",",
"self",
"::",
"getDisplayTitle",
"(",
"$",
"target",
")",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"ext",
",",
"$",
"wgDIQADownloadWhitelist",
")",
")",
"{",
"// download",
"$",
"ret",
"=",
"Html",
"::",
"rawElement",
"(",
"'a'",
",",
"array",
"(",
"'href'",
"=>",
"$",
"file",
"->",
"getFullURL",
"(",
")",
")",
",",
"self",
"::",
"getDisplayTitle",
"(",
"$",
"target",
")",
")",
";",
"return",
"false",
";",
"}",
"// don't rewrite links to files with inappropriate extensions",
"return",
"true",
";",
"}"
] |
Rewrites links to images in order to open them into a overlay
@param unknown $dummy
@param \Title $target
@param unknown $text
@param unknown $customAttribs
@param unknown $query
@param unknown $options
@param unknown $ret
@return boolean
|
[
"Rewrites",
"links",
"to",
"images",
"in",
"order",
"to",
"open",
"them",
"into",
"a",
"overlay"
] |
df35d16403b5dbf0f7570daded6cfa26814ae7e0
|
https://github.com/kkthek/diqa-util/blob/df35d16403b5dbf0f7570daded6cfa26814ae7e0/src/Util/FileLinkUtils.php#L29-L65
|
train
|
story75/Raptor
|
src/CommandProxyGenerator.php
|
CommandProxyGenerator.generateCommandProxy
|
public function generateCommandProxy($className)
{
$classMeta = $this->reflectionService->getClassMetaReflection($className);
$proxies = [];
$cachePath = $this->getRaptorCachePath();
$this->createDirectory($cachePath);
$thisNode = new Variable('this');
foreach ($classMeta->getMethods() as $methodMeta) {
// skip if method is not a command or an inherited command
if (!stristr($methodMeta->getName(), self::COMMAND_SUFFIX) ||
$methodMeta->getDeclaringClass() !== $classMeta) {
continue;
}
$proxies[] = $this->generateProxyForMethod($cachePath, $thisNode, $methodMeta, $classMeta);
}
return $proxies;
}
|
php
|
public function generateCommandProxy($className)
{
$classMeta = $this->reflectionService->getClassMetaReflection($className);
$proxies = [];
$cachePath = $this->getRaptorCachePath();
$this->createDirectory($cachePath);
$thisNode = new Variable('this');
foreach ($classMeta->getMethods() as $methodMeta) {
// skip if method is not a command or an inherited command
if (!stristr($methodMeta->getName(), self::COMMAND_SUFFIX) ||
$methodMeta->getDeclaringClass() !== $classMeta) {
continue;
}
$proxies[] = $this->generateProxyForMethod($cachePath, $thisNode, $methodMeta, $classMeta);
}
return $proxies;
}
|
[
"public",
"function",
"generateCommandProxy",
"(",
"$",
"className",
")",
"{",
"$",
"classMeta",
"=",
"$",
"this",
"->",
"reflectionService",
"->",
"getClassMetaReflection",
"(",
"$",
"className",
")",
";",
"$",
"proxies",
"=",
"[",
"]",
";",
"$",
"cachePath",
"=",
"$",
"this",
"->",
"getRaptorCachePath",
"(",
")",
";",
"$",
"this",
"->",
"createDirectory",
"(",
"$",
"cachePath",
")",
";",
"$",
"thisNode",
"=",
"new",
"Variable",
"(",
"'this'",
")",
";",
"foreach",
"(",
"$",
"classMeta",
"->",
"getMethods",
"(",
")",
"as",
"$",
"methodMeta",
")",
"{",
"// skip if method is not a command or an inherited command",
"if",
"(",
"!",
"stristr",
"(",
"$",
"methodMeta",
"->",
"getName",
"(",
")",
",",
"self",
"::",
"COMMAND_SUFFIX",
")",
"||",
"$",
"methodMeta",
"->",
"getDeclaringClass",
"(",
")",
"!==",
"$",
"classMeta",
")",
"{",
"continue",
";",
"}",
"$",
"proxies",
"[",
"]",
"=",
"$",
"this",
"->",
"generateProxyForMethod",
"(",
"$",
"cachePath",
",",
"$",
"thisNode",
",",
"$",
"methodMeta",
",",
"$",
"classMeta",
")",
";",
"}",
"return",
"$",
"proxies",
";",
"}"
] |
Entry point to create proxies of a bonefish command class
@param string $className
@return array
|
[
"Entry",
"point",
"to",
"create",
"proxies",
"of",
"a",
"bonefish",
"command",
"class"
] |
e62e9e56be9d7b8ad16971b628c4c77ff4448d77
|
https://github.com/story75/Raptor/blob/e62e9e56be9d7b8ad16971b628c4c77ff4448d77/src/CommandProxyGenerator.php#L95-L116
|
train
|
story75/Raptor
|
src/CommandProxyGenerator.php
|
CommandProxyGenerator.getCommandName
|
protected function getCommandName($methodMeta, $classMeta)
{
$nameSpaceParts = explode('\\', $classMeta->getNamespace());
$vendor = $nameSpaceParts[0];
$package = $nameSpaceParts[1];
return strtolower($vendor . ':' . $package . ':' . str_replace(self::COMMAND_SUFFIX, '', $methodMeta->getName()));
}
|
php
|
protected function getCommandName($methodMeta, $classMeta)
{
$nameSpaceParts = explode('\\', $classMeta->getNamespace());
$vendor = $nameSpaceParts[0];
$package = $nameSpaceParts[1];
return strtolower($vendor . ':' . $package . ':' . str_replace(self::COMMAND_SUFFIX, '', $methodMeta->getName()));
}
|
[
"protected",
"function",
"getCommandName",
"(",
"$",
"methodMeta",
",",
"$",
"classMeta",
")",
"{",
"$",
"nameSpaceParts",
"=",
"explode",
"(",
"'\\\\'",
",",
"$",
"classMeta",
"->",
"getNamespace",
"(",
")",
")",
";",
"$",
"vendor",
"=",
"$",
"nameSpaceParts",
"[",
"0",
"]",
";",
"$",
"package",
"=",
"$",
"nameSpaceParts",
"[",
"1",
"]",
";",
"return",
"strtolower",
"(",
"$",
"vendor",
".",
"':'",
".",
"$",
"package",
".",
"':'",
".",
"str_replace",
"(",
"self",
"::",
"COMMAND_SUFFIX",
",",
"''",
",",
"$",
"methodMeta",
"->",
"getName",
"(",
")",
")",
")",
";",
"}"
] |
Create a unique command name
@param MethodMeta $methodMeta
@param ClassMeta $classMeta
@return string
|
[
"Create",
"a",
"unique",
"command",
"name"
] |
e62e9e56be9d7b8ad16971b628c4c77ff4448d77
|
https://github.com/story75/Raptor/blob/e62e9e56be9d7b8ad16971b628c4c77ff4448d77/src/CommandProxyGenerator.php#L125-L132
|
train
|
naucon/Utility
|
src/IteratorReverseAbstract.php
|
IteratorReverseAbstract.next
|
public function next()
{
$this->_itemValid = true;
if (!prev($this->_items)) {
// no next item
$this->_itemValid = false;
} else {
$this->_itemPosition--;
}
}
|
php
|
public function next()
{
$this->_itemValid = true;
if (!prev($this->_items)) {
// no next item
$this->_itemValid = false;
} else {
$this->_itemPosition--;
}
}
|
[
"public",
"function",
"next",
"(",
")",
"{",
"$",
"this",
"->",
"_itemValid",
"=",
"true",
";",
"if",
"(",
"!",
"prev",
"(",
"$",
"this",
"->",
"_items",
")",
")",
"{",
"// no next item",
"$",
"this",
"->",
"_itemValid",
"=",
"false",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_itemPosition",
"--",
";",
"}",
"}"
] |
set next item to current item
@return void
|
[
"set",
"next",
"item",
"to",
"current",
"item"
] |
d225bb5d09d82400917f710c9d502949a66442c4
|
https://github.com/naucon/Utility/blob/d225bb5d09d82400917f710c9d502949a66442c4/src/IteratorReverseAbstract.php#L74-L84
|
train
|
Weblab-nl/restclient
|
src/Adapters/OAuth.php
|
OAuth.fetchAccessToken
|
private function fetchAccessToken() {
// Setup the params
$params = [
'client_id' => $this->clientID,
'client_secret' => $this->secret,
'grant_type' => 'authorization_code',
'code' => $this->requestToken
];
if (isset($this->redirectURI)) {
$params['redirect_uri'] = $this->redirectURI;
}
// Parse the cURL result
$this->parseAccessToken(CURL::post($this->url, $params));
}
|
php
|
private function fetchAccessToken() {
// Setup the params
$params = [
'client_id' => $this->clientID,
'client_secret' => $this->secret,
'grant_type' => 'authorization_code',
'code' => $this->requestToken
];
if (isset($this->redirectURI)) {
$params['redirect_uri'] = $this->redirectURI;
}
// Parse the cURL result
$this->parseAccessToken(CURL::post($this->url, $params));
}
|
[
"private",
"function",
"fetchAccessToken",
"(",
")",
"{",
"// Setup the params",
"$",
"params",
"=",
"[",
"'client_id'",
"=>",
"$",
"this",
"->",
"clientID",
",",
"'client_secret'",
"=>",
"$",
"this",
"->",
"secret",
",",
"'grant_type'",
"=>",
"'authorization_code'",
",",
"'code'",
"=>",
"$",
"this",
"->",
"requestToken",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"redirectURI",
")",
")",
"{",
"$",
"params",
"[",
"'redirect_uri'",
"]",
"=",
"$",
"this",
"->",
"redirectURI",
";",
"}",
"// Parse the cURL result",
"$",
"this",
"->",
"parseAccessToken",
"(",
"CURL",
"::",
"post",
"(",
"$",
"this",
"->",
"url",
",",
"$",
"params",
")",
")",
";",
"}"
] |
Does a cURL to request a new access token
@throws \Exception
|
[
"Does",
"a",
"cURL",
"to",
"request",
"a",
"new",
"access",
"token"
] |
6bc4e7890580b7b31e78032e40be5a67122b0dd0
|
https://github.com/Weblab-nl/restclient/blob/6bc4e7890580b7b31e78032e40be5a67122b0dd0/src/Adapters/OAuth.php#L223-L238
|
train
|
Weblab-nl/restclient
|
src/Adapters/OAuth.php
|
OAuth.refreshAccessToken
|
private function refreshAccessToken() {
// Setup the params
$params = [
'client_id' => $this->clientID,
'client_secret' => $this->secret,
'grant_type' => 'refresh_token',
'refresh_token' => $this->refreshToken
];
// Parse the cURL result
$this->parseAccessToken(CURL::post($this->url, $params));
}
|
php
|
private function refreshAccessToken() {
// Setup the params
$params = [
'client_id' => $this->clientID,
'client_secret' => $this->secret,
'grant_type' => 'refresh_token',
'refresh_token' => $this->refreshToken
];
// Parse the cURL result
$this->parseAccessToken(CURL::post($this->url, $params));
}
|
[
"private",
"function",
"refreshAccessToken",
"(",
")",
"{",
"// Setup the params",
"$",
"params",
"=",
"[",
"'client_id'",
"=>",
"$",
"this",
"->",
"clientID",
",",
"'client_secret'",
"=>",
"$",
"this",
"->",
"secret",
",",
"'grant_type'",
"=>",
"'refresh_token'",
",",
"'refresh_token'",
"=>",
"$",
"this",
"->",
"refreshToken",
"]",
";",
"// Parse the cURL result",
"$",
"this",
"->",
"parseAccessToken",
"(",
"CURL",
"::",
"post",
"(",
"$",
"this",
"->",
"url",
",",
"$",
"params",
")",
")",
";",
"}"
] |
Refreshes the access token
@throws \Exception
|
[
"Refreshes",
"the",
"access",
"token"
] |
6bc4e7890580b7b31e78032e40be5a67122b0dd0
|
https://github.com/Weblab-nl/restclient/blob/6bc4e7890580b7b31e78032e40be5a67122b0dd0/src/Adapters/OAuth.php#L245-L256
|
train
|
Weblab-nl/restclient
|
src/Adapters/OAuth.php
|
OAuth.processRequestToken
|
public function processRequestToken($token) {
// Setup the params
$params = [
'client_id' => $this->clientID,
'client_secret' => $this->secret,
'code' => $token,
'grant_type' => 'authorization_code',
'redirect_uri' => $this->redirectURI
];
// Parse the cURL result
return CURL::post($this->url, $params);
}
|
php
|
public function processRequestToken($token) {
// Setup the params
$params = [
'client_id' => $this->clientID,
'client_secret' => $this->secret,
'code' => $token,
'grant_type' => 'authorization_code',
'redirect_uri' => $this->redirectURI
];
// Parse the cURL result
return CURL::post($this->url, $params);
}
|
[
"public",
"function",
"processRequestToken",
"(",
"$",
"token",
")",
"{",
"// Setup the params",
"$",
"params",
"=",
"[",
"'client_id'",
"=>",
"$",
"this",
"->",
"clientID",
",",
"'client_secret'",
"=>",
"$",
"this",
"->",
"secret",
",",
"'code'",
"=>",
"$",
"token",
",",
"'grant_type'",
"=>",
"'authorization_code'",
",",
"'redirect_uri'",
"=>",
"$",
"this",
"->",
"redirectURI",
"]",
";",
"// Parse the cURL result",
"return",
"CURL",
"::",
"post",
"(",
"$",
"this",
"->",
"url",
",",
"$",
"params",
")",
";",
"}"
] |
Convert a request token to an access token
@param string $token
@return mixed
|
[
"Convert",
"a",
"request",
"token",
"to",
"an",
"access",
"token"
] |
6bc4e7890580b7b31e78032e40be5a67122b0dd0
|
https://github.com/Weblab-nl/restclient/blob/6bc4e7890580b7b31e78032e40be5a67122b0dd0/src/Adapters/OAuth.php#L291-L303
|
train
|
Dev4Media/ngnfeed-ebay
|
src/D4m/NgnFeed/Ebay/Serializer/Normalizer/GetSetMethodNormalizer.php
|
GetSetMethodNormalizer.setCallbacks
|
public function setCallbacks(array $callbacks)
{
foreach ($callbacks as $attribute => $callback) {
if (!is_callable($callback)) {
throw new \InvalidArgumentException(sprintf('The given callback for attribute "%s" is not callable.', $attribute));
}
}
$this->callbacks = $callbacks;
}
|
php
|
public function setCallbacks(array $callbacks)
{
foreach ($callbacks as $attribute => $callback) {
if (!is_callable($callback)) {
throw new \InvalidArgumentException(sprintf('The given callback for attribute "%s" is not callable.', $attribute));
}
}
$this->callbacks = $callbacks;
}
|
[
"public",
"function",
"setCallbacks",
"(",
"array",
"$",
"callbacks",
")",
"{",
"foreach",
"(",
"$",
"callbacks",
"as",
"$",
"attribute",
"=>",
"$",
"callback",
")",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"callback",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The given callback for attribute \"%s\" is not callable.'",
",",
"$",
"attribute",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"callbacks",
"=",
"$",
"callbacks",
";",
"}"
] |
Set normalization callbacks
@param array $callbacks help normalize the result
@throws InvalidArgumentException if a non-callable callback is set
|
[
"Set",
"normalization",
"callbacks"
] |
fb9652e30c7e4823a4e4dd571f41c8839953e72c
|
https://github.com/Dev4Media/ngnfeed-ebay/blob/fb9652e30c7e4823a4e4dd571f41c8839953e72c/src/D4m/NgnFeed/Ebay/Serializer/Normalizer/GetSetMethodNormalizer.php#L30-L38
|
train
|
Dev4Media/ngnfeed-ebay
|
src/D4m/NgnFeed/Ebay/Serializer/Normalizer/GetSetMethodNormalizer.php
|
GetSetMethodNormalizer.formatAttribute
|
protected function formatAttribute($attributeName)
{
if (in_array($attributeName, $this->camelizedAttributes)) {
return preg_replace_callback(
'/(^|_|\.)+(.)/', function ($match) {
return ('.' === $match[1] ? '_' : '').strtoupper($match[2]);
}, $attributeName
);
}
return $attributeName;
}
|
php
|
protected function formatAttribute($attributeName)
{
if (in_array($attributeName, $this->camelizedAttributes)) {
return preg_replace_callback(
'/(^|_|\.)+(.)/', function ($match) {
return ('.' === $match[1] ? '_' : '').strtoupper($match[2]);
}, $attributeName
);
}
return $attributeName;
}
|
[
"protected",
"function",
"formatAttribute",
"(",
"$",
"attributeName",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"attributeName",
",",
"$",
"this",
"->",
"camelizedAttributes",
")",
")",
"{",
"return",
"preg_replace_callback",
"(",
"'/(^|_|\\.)+(.)/'",
",",
"function",
"(",
"$",
"match",
")",
"{",
"return",
"(",
"'.'",
"===",
"$",
"match",
"[",
"1",
"]",
"?",
"'_'",
":",
"''",
")",
".",
"strtoupper",
"(",
"$",
"match",
"[",
"2",
"]",
")",
";",
"}",
",",
"$",
"attributeName",
")",
";",
"}",
"return",
"$",
"attributeName",
";",
"}"
] |
Format attribute name to access parameters or methods
As option, if attribute name is found on camelizedAttributes array
returns attribute name in camelcase format
@param string $attributeName
@return string
|
[
"Format",
"attribute",
"name",
"to",
"access",
"parameters",
"or",
"methods",
"As",
"option",
"if",
"attribute",
"name",
"is",
"found",
"on",
"camelizedAttributes",
"array",
"returns",
"attribute",
"name",
"in",
"camelcase",
"format"
] |
fb9652e30c7e4823a4e4dd571f41c8839953e72c
|
https://github.com/Dev4Media/ngnfeed-ebay/blob/fb9652e30c7e4823a4e4dd571f41c8839953e72c/src/D4m/NgnFeed/Ebay/Serializer/Normalizer/GetSetMethodNormalizer.php#L174-L185
|
train
|
realboard/DBInstance
|
src/Realboard/Component/Database/DBInstance/Service/RestServiceHandler.php
|
RestServiceHandler.getServerVersion
|
public function getServerVersion()
{
$di = new DBInstance($this->rawConfig);
$version = $di->getServerVersion();
unset($di);
return array(
'version' => $version,
);
}
|
php
|
public function getServerVersion()
{
$di = new DBInstance($this->rawConfig);
$version = $di->getServerVersion();
unset($di);
return array(
'version' => $version,
);
}
|
[
"public",
"function",
"getServerVersion",
"(",
")",
"{",
"$",
"di",
"=",
"new",
"DBInstance",
"(",
"$",
"this",
"->",
"rawConfig",
")",
";",
"$",
"version",
"=",
"$",
"di",
"->",
"getServerVersion",
"(",
")",
";",
"unset",
"(",
"$",
"di",
")",
";",
"return",
"array",
"(",
"'version'",
"=>",
"$",
"version",
",",
")",
";",
"}"
] |
Get DBInstance database version.
@return array
|
[
"Get",
"DBInstance",
"database",
"version",
"."
] |
f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35
|
https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/Service/RestServiceHandler.php#L132-L141
|
train
|
nilstr/Flash-Messages-for-Anax-MVC
|
src/FlashMessages/FlashMessages.php
|
FlashMessages.message
|
public function message($type, $message)
{
if ( $this->session->has('flashMessages') ) {
$flashMessages = $this->session->get('flashMessages');
$flashMessages[] = ['type' => $type, 'message' => $message];
$this->session->set('flashMessages', $flashMessages);
} else {
$this->session->set('flashMessages', [['type' => $type, 'message' => $message]]);
}
}
|
php
|
public function message($type, $message)
{
if ( $this->session->has('flashMessages') ) {
$flashMessages = $this->session->get('flashMessages');
$flashMessages[] = ['type' => $type, 'message' => $message];
$this->session->set('flashMessages', $flashMessages);
} else {
$this->session->set('flashMessages', [['type' => $type, 'message' => $message]]);
}
}
|
[
"public",
"function",
"message",
"(",
"$",
"type",
",",
"$",
"message",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"session",
"->",
"has",
"(",
"'flashMessages'",
")",
")",
"{",
"$",
"flashMessages",
"=",
"$",
"this",
"->",
"session",
"->",
"get",
"(",
"'flashMessages'",
")",
";",
"$",
"flashMessages",
"[",
"]",
"=",
"[",
"'type'",
"=>",
"$",
"type",
",",
"'message'",
"=>",
"$",
"message",
"]",
";",
"$",
"this",
"->",
"session",
"->",
"set",
"(",
"'flashMessages'",
",",
"$",
"flashMessages",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"session",
"->",
"set",
"(",
"'flashMessages'",
",",
"[",
"[",
"'type'",
"=>",
"$",
"type",
",",
"'message'",
"=>",
"$",
"message",
"]",
"]",
")",
";",
"}",
"}"
] |
Saves the message in the session.
@param string $type The type of flash message. Will be the class of the output div.
@param string $message The message to output.
@return void
|
[
"Saves",
"the",
"message",
"in",
"the",
"session",
"."
] |
7129241dd72a91eb0fcfe0e1d25144692334230c
|
https://github.com/nilstr/Flash-Messages-for-Anax-MVC/blob/7129241dd72a91eb0fcfe0e1d25144692334230c/src/FlashMessages/FlashMessages.php#L66-L75
|
train
|
nilstr/Flash-Messages-for-Anax-MVC
|
src/FlashMessages/FlashMessages.php
|
FlashMessages.output
|
public function output()
{
if ( $this->session->has('flashMessages') ) {
$flashMessages = $this->session->get('flashMessages');
$this->session->set('flashMessages', []);
$html = null;
foreach ($flashMessages as $message) {
$html .= "<div class='". $message['type'] . "'>" . $message['message'] . "</div>";
}
return $html;
}
}
|
php
|
public function output()
{
if ( $this->session->has('flashMessages') ) {
$flashMessages = $this->session->get('flashMessages');
$this->session->set('flashMessages', []);
$html = null;
foreach ($flashMessages as $message) {
$html .= "<div class='". $message['type'] . "'>" . $message['message'] . "</div>";
}
return $html;
}
}
|
[
"public",
"function",
"output",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"session",
"->",
"has",
"(",
"'flashMessages'",
")",
")",
"{",
"$",
"flashMessages",
"=",
"$",
"this",
"->",
"session",
"->",
"get",
"(",
"'flashMessages'",
")",
";",
"$",
"this",
"->",
"session",
"->",
"set",
"(",
"'flashMessages'",
",",
"[",
"]",
")",
";",
"$",
"html",
"=",
"null",
";",
"foreach",
"(",
"$",
"flashMessages",
"as",
"$",
"message",
")",
"{",
"$",
"html",
".=",
"\"<div class='\"",
".",
"$",
"message",
"[",
"'type'",
"]",
".",
"\"'>\"",
".",
"$",
"message",
"[",
"'message'",
"]",
".",
"\"</div>\"",
";",
"}",
"return",
"$",
"html",
";",
"}",
"}"
] |
Gets and resets the flash messages from session and building html.
@return string The html for the output.
|
[
"Gets",
"and",
"resets",
"the",
"flash",
"messages",
"from",
"session",
"and",
"building",
"html",
"."
] |
7129241dd72a91eb0fcfe0e1d25144692334230c
|
https://github.com/nilstr/Flash-Messages-for-Anax-MVC/blob/7129241dd72a91eb0fcfe0e1d25144692334230c/src/FlashMessages/FlashMessages.php#L83-L94
|
train
|
mamasu/mama-log
|
src/log/Log.php
|
Log.elapsedTime
|
public function elapsedTime() {
$currentTime = microtime(true);
if ($this->startTime === null) {
$this->startTime = $currentTime;
$this->finishTime = $currentTime;
} else {
$this->finishTime = $currentTime;
$this->elapsedTimeFromStart = $currentTime - $this->startTime;
}
}
|
php
|
public function elapsedTime() {
$currentTime = microtime(true);
if ($this->startTime === null) {
$this->startTime = $currentTime;
$this->finishTime = $currentTime;
} else {
$this->finishTime = $currentTime;
$this->elapsedTimeFromStart = $currentTime - $this->startTime;
}
}
|
[
"public",
"function",
"elapsedTime",
"(",
")",
"{",
"$",
"currentTime",
"=",
"microtime",
"(",
"true",
")",
";",
"if",
"(",
"$",
"this",
"->",
"startTime",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"startTime",
"=",
"$",
"currentTime",
";",
"$",
"this",
"->",
"finishTime",
"=",
"$",
"currentTime",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"finishTime",
"=",
"$",
"currentTime",
";",
"$",
"this",
"->",
"elapsedTimeFromStart",
"=",
"$",
"currentTime",
"-",
"$",
"this",
"->",
"startTime",
";",
"}",
"}"
] |
Calculated the different time of the log line.
|
[
"Calculated",
"the",
"different",
"time",
"of",
"the",
"log",
"line",
"."
] |
86431258fc42a3f364af2d959382d43c2a2dd3a0
|
https://github.com/mamasu/mama-log/blob/86431258fc42a3f364af2d959382d43c2a2dd3a0/src/log/Log.php#L54-L63
|
train
|
jmfeurprier/perf-caching
|
lib/perf/Caching/CacheClient.php
|
CacheClient.store
|
public function store($id, $data, $maxLifetimeSeconds = null)
{
$creationTimestamp = time();
if (null === $maxLifetimeSeconds) {
$expirationTimestamp = null;
} else {
$expirationTimestamp = ($creationTimestamp + (int) $maxLifetimeSeconds);
}
$entry = new CacheEntry($id, $data, $creationTimestamp, $expirationTimestamp);
$this->storage->store($entry);
return $this;
}
|
php
|
public function store($id, $data, $maxLifetimeSeconds = null)
{
$creationTimestamp = time();
if (null === $maxLifetimeSeconds) {
$expirationTimestamp = null;
} else {
$expirationTimestamp = ($creationTimestamp + (int) $maxLifetimeSeconds);
}
$entry = new CacheEntry($id, $data, $creationTimestamp, $expirationTimestamp);
$this->storage->store($entry);
return $this;
}
|
[
"public",
"function",
"store",
"(",
"$",
"id",
",",
"$",
"data",
",",
"$",
"maxLifetimeSeconds",
"=",
"null",
")",
"{",
"$",
"creationTimestamp",
"=",
"time",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"maxLifetimeSeconds",
")",
"{",
"$",
"expirationTimestamp",
"=",
"null",
";",
"}",
"else",
"{",
"$",
"expirationTimestamp",
"=",
"(",
"$",
"creationTimestamp",
"+",
"(",
"int",
")",
"$",
"maxLifetimeSeconds",
")",
";",
"}",
"$",
"entry",
"=",
"new",
"CacheEntry",
"(",
"$",
"id",
",",
"$",
"data",
",",
"$",
"creationTimestamp",
",",
"$",
"expirationTimestamp",
")",
";",
"$",
"this",
"->",
"storage",
"->",
"store",
"(",
"$",
"entry",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Attempts to store provided content into cache. Cache file will hold creation and expiration timestamps,
and provided content.
@param mixed $id Cache item unique identifier (ex: 123).
@param mixed $data Content to be added to cache.
@param null|int $maxLifetimeSeconds (Optional) duration in seconds after which cache file will be
considered expired.
@return CacheClient Fluent return.
@throws \RuntimeException
|
[
"Attempts",
"to",
"store",
"provided",
"content",
"into",
"cache",
".",
"Cache",
"file",
"will",
"hold",
"creation",
"and",
"expiration",
"timestamps",
"and",
"provided",
"content",
"."
] |
16cf61dae3aa4d6dcb8722e14760934457087173
|
https://github.com/jmfeurprier/perf-caching/blob/16cf61dae3aa4d6dcb8722e14760934457087173/lib/perf/Caching/CacheClient.php#L62-L77
|
train
|
jmfeurprier/perf-caching
|
lib/perf/Caching/CacheClient.php
|
CacheClient.tryFetch
|
public function tryFetch($id, $maxLifetimeSeconds = null)
{
$entry = $this->storage->tryFetch($id);
if (null === $entry) {
return null;
}
if (null !== $maxLifetimeSeconds) {
if (($this->nowTimestamp - $entry->creationTimestamp()) > $maxLifetimeSeconds) {
return null;
}
}
if (null !== $entry->expirationTimestamp()) {
if ($this->nowTimestamp > $entry->expirationTimestamp()) {
return null;
}
}
return $entry->data();
}
|
php
|
public function tryFetch($id, $maxLifetimeSeconds = null)
{
$entry = $this->storage->tryFetch($id);
if (null === $entry) {
return null;
}
if (null !== $maxLifetimeSeconds) {
if (($this->nowTimestamp - $entry->creationTimestamp()) > $maxLifetimeSeconds) {
return null;
}
}
if (null !== $entry->expirationTimestamp()) {
if ($this->nowTimestamp > $entry->expirationTimestamp()) {
return null;
}
}
return $entry->data();
}
|
[
"public",
"function",
"tryFetch",
"(",
"$",
"id",
",",
"$",
"maxLifetimeSeconds",
"=",
"null",
")",
"{",
"$",
"entry",
"=",
"$",
"this",
"->",
"storage",
"->",
"tryFetch",
"(",
"$",
"id",
")",
";",
"if",
"(",
"null",
"===",
"$",
"entry",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"maxLifetimeSeconds",
")",
"{",
"if",
"(",
"(",
"$",
"this",
"->",
"nowTimestamp",
"-",
"$",
"entry",
"->",
"creationTimestamp",
"(",
")",
")",
">",
"$",
"maxLifetimeSeconds",
")",
"{",
"return",
"null",
";",
"}",
"}",
"if",
"(",
"null",
"!==",
"$",
"entry",
"->",
"expirationTimestamp",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"nowTimestamp",
">",
"$",
"entry",
"->",
"expirationTimestamp",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"}",
"return",
"$",
"entry",
"->",
"data",
"(",
")",
";",
"}"
] |
Attempts to retrieve data from cache.
@param mixed $id Cache entry unique identifier (ex: "123").
@param null|int $maxLifetimeSeconds Duration in seconds. If provided, will bypass expiration timestamp
in cache file, using creation timestamp + provided duration to check whether cached content has
expired or not.
@return null|mixed
|
[
"Attempts",
"to",
"retrieve",
"data",
"from",
"cache",
"."
] |
16cf61dae3aa4d6dcb8722e14760934457087173
|
https://github.com/jmfeurprier/perf-caching/blob/16cf61dae3aa4d6dcb8722e14760934457087173/lib/perf/Caching/CacheClient.php#L88-L109
|
train
|
silverorange/Concentrate
|
Concentrate/Concentrator.php
|
Concentrate_Concentrator.getDependsInfo
|
public function getDependsInfo()
{
$dependsInfo = $this->getCachedValue('dependsInfo');
if ($dependsInfo === false) {
$data = $this->dataProvider->getData();
$dependsInfo = array();
foreach ($this->getPackageSortOrder() as $packageId => $order) {
if (!isset($data[$packageId])) {
continue;
}
$provides = $this->getProvidesForPackage($packageId);
foreach ($provides as $file => $fileInfo) {
if (!isset($dependsInfo[$file])) {
$dependsInfo[$file] = array();
}
if (isset($fileInfo['Depends'])) {
$dependsInfo[$file] = array_merge(
$dependsInfo[$file],
$fileInfo['Depends']
);
}
// TODO: some day we could treat optional-depends
// differently
if (isset($fileInfo['OptionalDepends'])) {
$dependsInfo[$file] = array_merge(
$dependsInfo[$file],
$fileInfo['OptionalDepends']
);
}
}
}
$this->setCachedValue('dependsInfo', $dependsInfo);
}
return $dependsInfo;
}
|
php
|
public function getDependsInfo()
{
$dependsInfo = $this->getCachedValue('dependsInfo');
if ($dependsInfo === false) {
$data = $this->dataProvider->getData();
$dependsInfo = array();
foreach ($this->getPackageSortOrder() as $packageId => $order) {
if (!isset($data[$packageId])) {
continue;
}
$provides = $this->getProvidesForPackage($packageId);
foreach ($provides as $file => $fileInfo) {
if (!isset($dependsInfo[$file])) {
$dependsInfo[$file] = array();
}
if (isset($fileInfo['Depends'])) {
$dependsInfo[$file] = array_merge(
$dependsInfo[$file],
$fileInfo['Depends']
);
}
// TODO: some day we could treat optional-depends
// differently
if (isset($fileInfo['OptionalDepends'])) {
$dependsInfo[$file] = array_merge(
$dependsInfo[$file],
$fileInfo['OptionalDepends']
);
}
}
}
$this->setCachedValue('dependsInfo', $dependsInfo);
}
return $dependsInfo;
}
|
[
"public",
"function",
"getDependsInfo",
"(",
")",
"{",
"$",
"dependsInfo",
"=",
"$",
"this",
"->",
"getCachedValue",
"(",
"'dependsInfo'",
")",
";",
"if",
"(",
"$",
"dependsInfo",
"===",
"false",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"dataProvider",
"->",
"getData",
"(",
")",
";",
"$",
"dependsInfo",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getPackageSortOrder",
"(",
")",
"as",
"$",
"packageId",
"=>",
"$",
"order",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"$",
"packageId",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"provides",
"=",
"$",
"this",
"->",
"getProvidesForPackage",
"(",
"$",
"packageId",
")",
";",
"foreach",
"(",
"$",
"provides",
"as",
"$",
"file",
"=>",
"$",
"fileInfo",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"dependsInfo",
"[",
"$",
"file",
"]",
")",
")",
"{",
"$",
"dependsInfo",
"[",
"$",
"file",
"]",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"fileInfo",
"[",
"'Depends'",
"]",
")",
")",
"{",
"$",
"dependsInfo",
"[",
"$",
"file",
"]",
"=",
"array_merge",
"(",
"$",
"dependsInfo",
"[",
"$",
"file",
"]",
",",
"$",
"fileInfo",
"[",
"'Depends'",
"]",
")",
";",
"}",
"// TODO: some day we could treat optional-depends",
"// differently",
"if",
"(",
"isset",
"(",
"$",
"fileInfo",
"[",
"'OptionalDepends'",
"]",
")",
")",
"{",
"$",
"dependsInfo",
"[",
"$",
"file",
"]",
"=",
"array_merge",
"(",
"$",
"dependsInfo",
"[",
"$",
"file",
"]",
",",
"$",
"fileInfo",
"[",
"'OptionalDepends'",
"]",
")",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"setCachedValue",
"(",
"'dependsInfo'",
",",
"$",
"dependsInfo",
")",
";",
"}",
"return",
"$",
"dependsInfo",
";",
"}"
] |
Gets a flat list of file dependencies for each file
@return array
|
[
"Gets",
"a",
"flat",
"list",
"of",
"file",
"dependencies",
"for",
"each",
"file"
] |
e0b679bedc105dc4280bb68a233c31246d20e6c5
|
https://github.com/silverorange/Concentrate/blob/e0b679bedc105dc4280bb68a233c31246d20e6c5/Concentrate/Concentrator.php#L454-L494
|
train
|
freialib/freia.autoloader
|
src/SymbolLoader.php
|
SymbolLoader.instance
|
static function instance($syspath, $conf) {
$i = new static;
$i->env = $i->environementInstance($syspath, $conf);
return $i;
}
|
php
|
static function instance($syspath, $conf) {
$i = new static;
$i->env = $i->environementInstance($syspath, $conf);
return $i;
}
|
[
"static",
"function",
"instance",
"(",
"$",
"syspath",
",",
"$",
"conf",
")",
"{",
"$",
"i",
"=",
"new",
"static",
";",
"$",
"i",
"->",
"env",
"=",
"$",
"i",
"->",
"environementInstance",
"(",
"$",
"syspath",
",",
"$",
"conf",
")",
";",
"return",
"$",
"i",
";",
"}"
] |
You may set debugMode to true to use debug modules, otherwise if modules
with a debug type in the autoload rules section are found they will be
ignored.
@return static
|
[
"You",
"may",
"set",
"debugMode",
"to",
"true",
"to",
"use",
"debug",
"modules",
"otherwise",
"if",
"modules",
"with",
"a",
"debug",
"type",
"in",
"the",
"autoload",
"rules",
"section",
"are",
"found",
"they",
"will",
"be",
"ignored",
"."
] |
45e0dfcd56d55cf533f12255db647e8a05fcd494
|
https://github.com/freialib/freia.autoloader/blob/45e0dfcd56d55cf533f12255db647e8a05fcd494/src/SymbolLoader.php#L24-L29
|
train
|
freialib/freia.autoloader
|
src/SymbolLoader.php
|
SymbolLoader.exists
|
function exists($symbol, $autoload = false) {
return class_exists($symbol, $autoload)
|| interface_exists($symbol, $autoload)
|| trait_exists($symbol, $autoload);
}
|
php
|
function exists($symbol, $autoload = false) {
return class_exists($symbol, $autoload)
|| interface_exists($symbol, $autoload)
|| trait_exists($symbol, $autoload);
}
|
[
"function",
"exists",
"(",
"$",
"symbol",
",",
"$",
"autoload",
"=",
"false",
")",
"{",
"return",
"class_exists",
"(",
"$",
"symbol",
",",
"$",
"autoload",
")",
"||",
"interface_exists",
"(",
"$",
"symbol",
",",
"$",
"autoload",
")",
"||",
"trait_exists",
"(",
"$",
"symbol",
",",
"$",
"autoload",
")",
";",
"}"
] |
Maintained for backwards comaptibility.
@param string symbol (class, interface, traits, etc)
@param boolean autoload while checking?
@return boolean symbol exists
|
[
"Maintained",
"for",
"backwards",
"comaptibility",
"."
] |
45e0dfcd56d55cf533f12255db647e8a05fcd494
|
https://github.com/freialib/freia.autoloader/blob/45e0dfcd56d55cf533f12255db647e8a05fcd494/src/SymbolLoader.php#L48-L52
|
train
|
freialib/freia.autoloader
|
src/SymbolLoader.php
|
SymbolLoader.load
|
function load($symbol) {
if ($this->env->knownUnknown($symbol)) {
return false;
}
if ($this->env->autoresolve($symbol)) {
return true;
}
$ns_pos = \strripos($symbol, '\\');
if ($ns_pos !== false && $ns_pos != 0) {
$ns = \substr($symbol, 0, $ns_pos + 1);
// Validate Main Segment
// =====================
$mainsegment = null;
$firstslash = \strpos($ns, '\\');
if ($firstslash !== false || $firstslash == 0) {
$mainsegment = \substr($ns, 0, $firstslash);
}
else { // no \ in namespace
// the namespace is the main segment itself
$mainsegment = $ns;
}
if ( ! $this->env->knownSegment($mainsegment)) {
$this->env->unknownSymbol($symbol);
$this->env->save();
return false;
}
// Continue Loading Process
// ========================
$name = \substr($symbol, $ns_pos + 1);
$filename = \str_replace('_', '/', $name);
$dirbreak = \strlen($name) - \strcspn(strrev($name), 'ABCDEFGHJIJKLMNOPQRSTUVWXYZ') - 1;
if ($dirbreak > 0 && $dirbreak != \strlen($name) - 1) {
$filename = \substr($name, $dirbreak).'/'.\substr($name, 0, $dirbreak);
}
else { // dirbreak == 0
$filename = $name;
}
$nextPtr = \strrpos($ns, '\\next\\');
$resolution = null;
if ($nextPtr === false) {
$resolution = $this->env->findFirstFileMatching($ns, $name, $filename);
}
else { // "\next\" is present in string
$resolution = $this->env->findFirstFileMatchingAfterNext($ns, $name, $filename);
}
if ($resolution != null) {
list($targetfile, $targetns, $target) = $resolution;
if ( ! $this->env->isLoadedSymbol($target)) {
$this->env->loadSymbol($target, $targetfile);
}
if ($targetns != $ns) {
$this->env->aliasSymbol($target, $symbol);
}
$this->env->save();
return true;
}
}
# else: symbol belongs to global namespace
$this->env->unknownSymbol($symbol);
$this->env->save();
return false; // failed to resolve symbol; pass to next autoloader
}
|
php
|
function load($symbol) {
if ($this->env->knownUnknown($symbol)) {
return false;
}
if ($this->env->autoresolve($symbol)) {
return true;
}
$ns_pos = \strripos($symbol, '\\');
if ($ns_pos !== false && $ns_pos != 0) {
$ns = \substr($symbol, 0, $ns_pos + 1);
// Validate Main Segment
// =====================
$mainsegment = null;
$firstslash = \strpos($ns, '\\');
if ($firstslash !== false || $firstslash == 0) {
$mainsegment = \substr($ns, 0, $firstslash);
}
else { // no \ in namespace
// the namespace is the main segment itself
$mainsegment = $ns;
}
if ( ! $this->env->knownSegment($mainsegment)) {
$this->env->unknownSymbol($symbol);
$this->env->save();
return false;
}
// Continue Loading Process
// ========================
$name = \substr($symbol, $ns_pos + 1);
$filename = \str_replace('_', '/', $name);
$dirbreak = \strlen($name) - \strcspn(strrev($name), 'ABCDEFGHJIJKLMNOPQRSTUVWXYZ') - 1;
if ($dirbreak > 0 && $dirbreak != \strlen($name) - 1) {
$filename = \substr($name, $dirbreak).'/'.\substr($name, 0, $dirbreak);
}
else { // dirbreak == 0
$filename = $name;
}
$nextPtr = \strrpos($ns, '\\next\\');
$resolution = null;
if ($nextPtr === false) {
$resolution = $this->env->findFirstFileMatching($ns, $name, $filename);
}
else { // "\next\" is present in string
$resolution = $this->env->findFirstFileMatchingAfterNext($ns, $name, $filename);
}
if ($resolution != null) {
list($targetfile, $targetns, $target) = $resolution;
if ( ! $this->env->isLoadedSymbol($target)) {
$this->env->loadSymbol($target, $targetfile);
}
if ($targetns != $ns) {
$this->env->aliasSymbol($target, $symbol);
}
$this->env->save();
return true;
}
}
# else: symbol belongs to global namespace
$this->env->unknownSymbol($symbol);
$this->env->save();
return false; // failed to resolve symbol; pass to next autoloader
}
|
[
"function",
"load",
"(",
"$",
"symbol",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"env",
"->",
"knownUnknown",
"(",
"$",
"symbol",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"env",
"->",
"autoresolve",
"(",
"$",
"symbol",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"ns_pos",
"=",
"\\",
"strripos",
"(",
"$",
"symbol",
",",
"'\\\\'",
")",
";",
"if",
"(",
"$",
"ns_pos",
"!==",
"false",
"&&",
"$",
"ns_pos",
"!=",
"0",
")",
"{",
"$",
"ns",
"=",
"\\",
"substr",
"(",
"$",
"symbol",
",",
"0",
",",
"$",
"ns_pos",
"+",
"1",
")",
";",
"// Validate Main Segment",
"// =====================",
"$",
"mainsegment",
"=",
"null",
";",
"$",
"firstslash",
"=",
"\\",
"strpos",
"(",
"$",
"ns",
",",
"'\\\\'",
")",
";",
"if",
"(",
"$",
"firstslash",
"!==",
"false",
"||",
"$",
"firstslash",
"==",
"0",
")",
"{",
"$",
"mainsegment",
"=",
"\\",
"substr",
"(",
"$",
"ns",
",",
"0",
",",
"$",
"firstslash",
")",
";",
"}",
"else",
"{",
"// no \\ in namespace",
"// the namespace is the main segment itself",
"$",
"mainsegment",
"=",
"$",
"ns",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"env",
"->",
"knownSegment",
"(",
"$",
"mainsegment",
")",
")",
"{",
"$",
"this",
"->",
"env",
"->",
"unknownSymbol",
"(",
"$",
"symbol",
")",
";",
"$",
"this",
"->",
"env",
"->",
"save",
"(",
")",
";",
"return",
"false",
";",
"}",
"// Continue Loading Process",
"// ========================",
"$",
"name",
"=",
"\\",
"substr",
"(",
"$",
"symbol",
",",
"$",
"ns_pos",
"+",
"1",
")",
";",
"$",
"filename",
"=",
"\\",
"str_replace",
"(",
"'_'",
",",
"'/'",
",",
"$",
"name",
")",
";",
"$",
"dirbreak",
"=",
"\\",
"strlen",
"(",
"$",
"name",
")",
"-",
"\\",
"strcspn",
"(",
"strrev",
"(",
"$",
"name",
")",
",",
"'ABCDEFGHJIJKLMNOPQRSTUVWXYZ'",
")",
"-",
"1",
";",
"if",
"(",
"$",
"dirbreak",
">",
"0",
"&&",
"$",
"dirbreak",
"!=",
"\\",
"strlen",
"(",
"$",
"name",
")",
"-",
"1",
")",
"{",
"$",
"filename",
"=",
"\\",
"substr",
"(",
"$",
"name",
",",
"$",
"dirbreak",
")",
".",
"'/'",
".",
"\\",
"substr",
"(",
"$",
"name",
",",
"0",
",",
"$",
"dirbreak",
")",
";",
"}",
"else",
"{",
"// dirbreak == 0",
"$",
"filename",
"=",
"$",
"name",
";",
"}",
"$",
"nextPtr",
"=",
"\\",
"strrpos",
"(",
"$",
"ns",
",",
"'\\\\next\\\\'",
")",
";",
"$",
"resolution",
"=",
"null",
";",
"if",
"(",
"$",
"nextPtr",
"===",
"false",
")",
"{",
"$",
"resolution",
"=",
"$",
"this",
"->",
"env",
"->",
"findFirstFileMatching",
"(",
"$",
"ns",
",",
"$",
"name",
",",
"$",
"filename",
")",
";",
"}",
"else",
"{",
"// \"\\next\\\" is present in string",
"$",
"resolution",
"=",
"$",
"this",
"->",
"env",
"->",
"findFirstFileMatchingAfterNext",
"(",
"$",
"ns",
",",
"$",
"name",
",",
"$",
"filename",
")",
";",
"}",
"if",
"(",
"$",
"resolution",
"!=",
"null",
")",
"{",
"list",
"(",
"$",
"targetfile",
",",
"$",
"targetns",
",",
"$",
"target",
")",
"=",
"$",
"resolution",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"env",
"->",
"isLoadedSymbol",
"(",
"$",
"target",
")",
")",
"{",
"$",
"this",
"->",
"env",
"->",
"loadSymbol",
"(",
"$",
"target",
",",
"$",
"targetfile",
")",
";",
"}",
"if",
"(",
"$",
"targetns",
"!=",
"$",
"ns",
")",
"{",
"$",
"this",
"->",
"env",
"->",
"aliasSymbol",
"(",
"$",
"target",
",",
"$",
"symbol",
")",
";",
"}",
"$",
"this",
"->",
"env",
"->",
"save",
"(",
")",
";",
"return",
"true",
";",
"}",
"}",
"# else: symbol belongs to global namespace",
"$",
"this",
"->",
"env",
"->",
"unknownSymbol",
"(",
"$",
"symbol",
")",
";",
"$",
"this",
"->",
"env",
"->",
"save",
"(",
")",
";",
"return",
"false",
";",
"// failed to resolve symbol; pass to next autoloader",
"}"
] |
Load given symbol
@return boolean
|
[
"Load",
"given",
"symbol"
] |
45e0dfcd56d55cf533f12255db647e8a05fcd494
|
https://github.com/freialib/freia.autoloader/blob/45e0dfcd56d55cf533f12255db647e8a05fcd494/src/SymbolLoader.php#L59-L141
|
train
|
Wedeto/HTTP
|
src/CachePolicy.php
|
CachePolicy.setExpireDate
|
public function setExpireDate(DateTimeInterface $dt)
{
$this->expire_time = (int)$dt->format('U') - time();
return $this;
}
|
php
|
public function setExpireDate(DateTimeInterface $dt)
{
$this->expire_time = (int)$dt->format('U') - time();
return $this;
}
|
[
"public",
"function",
"setExpireDate",
"(",
"DateTimeInterface",
"$",
"dt",
")",
"{",
"$",
"this",
"->",
"expire_time",
"=",
"(",
"int",
")",
"$",
"dt",
"->",
"format",
"(",
"'U'",
")",
"-",
"time",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Set the exact moment when the cache should expire.
@param DateTimeInterface $dt When the cache should expire
@return CachePolicy Provides fluent interface
|
[
"Set",
"the",
"exact",
"moment",
"when",
"the",
"cache",
"should",
"expire",
"."
] |
7318eff1b81a3c103c4263466d09b7f3593b70b9
|
https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/CachePolicy.php#L58-L62
|
train
|
Wedeto/HTTP
|
src/CachePolicy.php
|
CachePolicy.setExpiresIn
|
public function setExpiresIn(DateInterval $interval)
{
$now = new DateTimeImmutable();
$expire = $now->add($interval);
$this->setExpiresInSeconds($expire->getTimestamp() - $now->getTimestamp());
return $this;
}
|
php
|
public function setExpiresIn(DateInterval $interval)
{
$now = new DateTimeImmutable();
$expire = $now->add($interval);
$this->setExpiresInSeconds($expire->getTimestamp() - $now->getTimestamp());
return $this;
}
|
[
"public",
"function",
"setExpiresIn",
"(",
"DateInterval",
"$",
"interval",
")",
"{",
"$",
"now",
"=",
"new",
"DateTimeImmutable",
"(",
")",
";",
"$",
"expire",
"=",
"$",
"now",
"->",
"add",
"(",
"$",
"interval",
")",
";",
"$",
"this",
"->",
"setExpiresInSeconds",
"(",
"$",
"expire",
"->",
"getTimestamp",
"(",
")",
"-",
"$",
"now",
"->",
"getTimestamp",
"(",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Set the time until the cache should expire.
@param DateInterval $interval In what time the cache should expire.
@return CachePolicy Provides fluent interface
|
[
"Set",
"the",
"time",
"until",
"the",
"cache",
"should",
"expire",
"."
] |
7318eff1b81a3c103c4263466d09b7f3593b70b9
|
https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/CachePolicy.php#L80-L86
|
train
|
Wedeto/HTTP
|
src/CachePolicy.php
|
CachePolicy.setExpires
|
public function setExpires($period)
{
if (is_int($period))
return $this->setExpiresInSeconds($period);
if ($period instanceof DateTimeInterface)
return $this->setExpireDate($period);
if ($period instanceof DateInterval)
return $this->setExpiresIn($period);
throw new \InvalidArgumentException("A DateTime, DateInterval or int number of seconds is required");
}
|
php
|
public function setExpires($period)
{
if (is_int($period))
return $this->setExpiresInSeconds($period);
if ($period instanceof DateTimeInterface)
return $this->setExpireDate($period);
if ($period instanceof DateInterval)
return $this->setExpiresIn($period);
throw new \InvalidArgumentException("A DateTime, DateInterval or int number of seconds is required");
}
|
[
"public",
"function",
"setExpires",
"(",
"$",
"period",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"period",
")",
")",
"return",
"$",
"this",
"->",
"setExpiresInSeconds",
"(",
"$",
"period",
")",
";",
"if",
"(",
"$",
"period",
"instanceof",
"DateTimeInterface",
")",
"return",
"$",
"this",
"->",
"setExpireDate",
"(",
"$",
"period",
")",
";",
"if",
"(",
"$",
"period",
"instanceof",
"DateInterval",
")",
"return",
"$",
"this",
"->",
"setExpiresIn",
"(",
"$",
"period",
")",
";",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"A DateTime, DateInterval or int number of seconds is required\"",
")",
";",
"}"
] |
Set the when the cache should expire. Wrapper for setExpiresIn,
setExpiresInSeconds and setExpireDate, with type detection.
@param mixed $period Can be int (seconds), DateTimeInterface or DateInterval.
@return CachePolicy Provides fluent interface
|
[
"Set",
"the",
"when",
"the",
"cache",
"should",
"expire",
".",
"Wrapper",
"for",
"setExpiresIn",
"setExpiresInSeconds",
"and",
"setExpireDate",
"with",
"type",
"detection",
"."
] |
7318eff1b81a3c103c4263466d09b7f3593b70b9
|
https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/CachePolicy.php#L95-L105
|
train
|
Wedeto/HTTP
|
src/CachePolicy.php
|
CachePolicy.setCachePolicy
|
public function setCachePolicy(string $policy)
{
if ($policy !== self::CACHE_DISABLE && $policy !== self::CACHE_PUBLIC && $policy !== self::CACHE_PRIVATE)
throw new \InvalidArgumentException("Invalid cache policy: " . $policy);
$this->cache_policy = $policy;
return $this;
}
|
php
|
public function setCachePolicy(string $policy)
{
if ($policy !== self::CACHE_DISABLE && $policy !== self::CACHE_PUBLIC && $policy !== self::CACHE_PRIVATE)
throw new \InvalidArgumentException("Invalid cache policy: " . $policy);
$this->cache_policy = $policy;
return $this;
}
|
[
"public",
"function",
"setCachePolicy",
"(",
"string",
"$",
"policy",
")",
"{",
"if",
"(",
"$",
"policy",
"!==",
"self",
"::",
"CACHE_DISABLE",
"&&",
"$",
"policy",
"!==",
"self",
"::",
"CACHE_PUBLIC",
"&&",
"$",
"policy",
"!==",
"self",
"::",
"CACHE_PRIVATE",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid cache policy: \"",
".",
"$",
"policy",
")",
";",
"$",
"this",
"->",
"cache_policy",
"=",
"$",
"policy",
";",
"return",
"$",
"this",
";",
"}"
] |
Set the cache policy for this response.
@param string $policy One of CachePolicy::CACHE_PUBLIC, CACHE_PRIVATE or CACHE_DISABLED.
@return CachePolicy Provides fluent interface
|
[
"Set",
"the",
"cache",
"policy",
"for",
"this",
"response",
"."
] |
7318eff1b81a3c103c4263466d09b7f3593b70b9
|
https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/CachePolicy.php#L120-L127
|
train
|
Vectrex/vxPHP
|
src/Form/FormElement/LabelElement.php
|
LabelElement.setAttribute
|
public function setAttribute($attr, $value)
{
$attr = strtolower($attr);
if(is_null($value)) {
unset($this->attributes[$attr]);
}
else {
$this->attributes[$attr] = $value;
}
return $this;
}
|
php
|
public function setAttribute($attr, $value)
{
$attr = strtolower($attr);
if(is_null($value)) {
unset($this->attributes[$attr]);
}
else {
$this->attributes[$attr] = $value;
}
return $this;
}
|
[
"public",
"function",
"setAttribute",
"(",
"$",
"attr",
",",
"$",
"value",
")",
"{",
"$",
"attr",
"=",
"strtolower",
"(",
"$",
"attr",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"attributes",
"[",
"$",
"attr",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"attributes",
"[",
"$",
"attr",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
sets attributes of form label
@param string $attr
@param string $value
@return LabelElement
|
[
"sets",
"attributes",
"of",
"form",
"label"
] |
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
|
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Form/FormElement/LabelElement.php#L80-L94
|
train
|
Vectrex/vxPHP
|
src/Form/FormElement/LabelElement.php
|
LabelElement.render
|
public function render()
{
$attr = [];
foreach($this->attributes as $k => $v) {
$attr[] = sprintf('%s="%s"', $k, $v);
}
return sprintf('<label %s>%s</label>',
implode(' ', $attr),
trim($this->labelText)
);
}
|
php
|
public function render()
{
$attr = [];
foreach($this->attributes as $k => $v) {
$attr[] = sprintf('%s="%s"', $k, $v);
}
return sprintf('<label %s>%s</label>',
implode(' ', $attr),
trim($this->labelText)
);
}
|
[
"public",
"function",
"render",
"(",
")",
"{",
"$",
"attr",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"attributes",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"attr",
"[",
"]",
"=",
"sprintf",
"(",
"'%s=\"%s\"'",
",",
"$",
"k",
",",
"$",
"v",
")",
";",
"}",
"return",
"sprintf",
"(",
"'<label %s>%s</label>'",
",",
"implode",
"(",
"' '",
",",
"$",
"attr",
")",
",",
"trim",
"(",
"$",
"this",
"->",
"labelText",
")",
")",
";",
"}"
] |
render the label element
if a form element was assigned a
matching "for" attribute can be generated
@return string
|
[
"render",
"the",
"label",
"element",
"if",
"a",
"form",
"element",
"was",
"assigned",
"a",
"matching",
"for",
"attribute",
"can",
"be",
"generated"
] |
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
|
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Form/FormElement/LabelElement.php#L119-L133
|
train
|
DeimosProject/Helper
|
src/Helper/Helpers/Str/Str.php
|
Str.translit
|
public function translit($string)
{
$string = \strtr($string, $this->transliterationTable);
return \iconv(\mb_internal_encoding(), 'ASCII//TRANSLIT', $string);
}
|
php
|
public function translit($string)
{
$string = \strtr($string, $this->transliterationTable);
return \iconv(\mb_internal_encoding(), 'ASCII//TRANSLIT', $string);
}
|
[
"public",
"function",
"translit",
"(",
"$",
"string",
")",
"{",
"$",
"string",
"=",
"\\",
"strtr",
"(",
"$",
"string",
",",
"$",
"this",
"->",
"transliterationTable",
")",
";",
"return",
"\\",
"iconv",
"(",
"\\",
"mb_internal_encoding",
"(",
")",
",",
"'ASCII//TRANSLIT'",
",",
"$",
"string",
")",
";",
"}"
] |
transliteration cyr->lat
@param $string
@return string
|
[
"transliteration",
"cyr",
"-",
">",
"lat"
] |
39c67de21a87c7c6391b2f98416063f41c94e26f
|
https://github.com/DeimosProject/Helper/blob/39c67de21a87c7c6391b2f98416063f41c94e26f/src/Helper/Helpers/Str/Str.php#L231-L236
|
train
|
eureka-framework/component-template
|
src/Template/Block.php
|
Block.end
|
public function end($name, $append = true)
{
$content = trim(ob_get_contents());
ob_end_clean();
$hash = md5($content);
if (isset($this->hashCache[$hash])) {
return;
}
$this->hashCache[$hash] = true;
if (isset($this->blocks[$name]) && $append) {
$this->blocks[$name] .= $content;
} else {
$this->blocks[$name] = $content;
}
}
|
php
|
public function end($name, $append = true)
{
$content = trim(ob_get_contents());
ob_end_clean();
$hash = md5($content);
if (isset($this->hashCache[$hash])) {
return;
}
$this->hashCache[$hash] = true;
if (isset($this->blocks[$name]) && $append) {
$this->blocks[$name] .= $content;
} else {
$this->blocks[$name] = $content;
}
}
|
[
"public",
"function",
"end",
"(",
"$",
"name",
",",
"$",
"append",
"=",
"true",
")",
"{",
"$",
"content",
"=",
"trim",
"(",
"ob_get_contents",
"(",
")",
")",
";",
"ob_end_clean",
"(",
")",
";",
"$",
"hash",
"=",
"md5",
"(",
"$",
"content",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"hashCache",
"[",
"$",
"hash",
"]",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"hashCache",
"[",
"$",
"hash",
"]",
"=",
"true",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"blocks",
"[",
"$",
"name",
"]",
")",
"&&",
"$",
"append",
")",
"{",
"$",
"this",
"->",
"blocks",
"[",
"$",
"name",
"]",
".=",
"$",
"content",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"blocks",
"[",
"$",
"name",
"]",
"=",
"$",
"content",
";",
"}",
"}"
] |
End to catch block and save it.
@param string $name
@param bool $append Append content to previous block. Otherwise, reset content.
@return void
|
[
"End",
"to",
"catch",
"block",
"and",
"save",
"it",
"."
] |
42e9b3954b79892ba340ba7ca909f03ee99c36fe
|
https://github.com/eureka-framework/component-template/blob/42e9b3954b79892ba340ba7ca909f03ee99c36fe/src/Template/Block.php#L94-L112
|
train
|
praxigento/mobi_mod_downline
|
Plugin/Magento/Framework/App/FrontControllerInterface.php
|
FrontControllerInterface.beforeDispatch
|
public function beforeDispatch(
\Magento\Framework\App\FrontControllerInterface $subject,
\Magento\Framework\App\RequestInterface $request
) {
$code = $request->getParam(static::REQ_REFERRAL);
if (!empty($code)) {
$this->session->logout();
}
$this->hlpRefCode->processHttpRequest($code);
}
|
php
|
public function beforeDispatch(
\Magento\Framework\App\FrontControllerInterface $subject,
\Magento\Framework\App\RequestInterface $request
) {
$code = $request->getParam(static::REQ_REFERRAL);
if (!empty($code)) {
$this->session->logout();
}
$this->hlpRefCode->processHttpRequest($code);
}
|
[
"public",
"function",
"beforeDispatch",
"(",
"\\",
"Magento",
"\\",
"Framework",
"\\",
"App",
"\\",
"FrontControllerInterface",
"$",
"subject",
",",
"\\",
"Magento",
"\\",
"Framework",
"\\",
"App",
"\\",
"RequestInterface",
"$",
"request",
")",
"{",
"$",
"code",
"=",
"$",
"request",
"->",
"getParam",
"(",
"static",
"::",
"REQ_REFERRAL",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"code",
")",
")",
"{",
"$",
"this",
"->",
"session",
"->",
"logout",
"(",
")",
";",
"}",
"$",
"this",
"->",
"hlpRefCode",
"->",
"processHttpRequest",
"(",
"$",
"code",
")",
";",
"}"
] |
Extract referral code from GET-variable or cookie and save it into registry.
@param \Magento\Framework\App\FrontControllerInterface $subject
@param \Magento\Framework\App\RequestInterface $request
|
[
"Extract",
"referral",
"code",
"from",
"GET",
"-",
"variable",
"or",
"cookie",
"and",
"save",
"it",
"into",
"registry",
"."
] |
0f3c276dfff1aa029f9fd205ccfc56f207a2e75b
|
https://github.com/praxigento/mobi_mod_downline/blob/0f3c276dfff1aa029f9fd205ccfc56f207a2e75b/Plugin/Magento/Framework/App/FrontControllerInterface.php#L34-L43
|
train
|
jabernardo/lollipop-php
|
Library/Utils/Vars.php
|
Vars.fuse
|
static function fuse(&$opt1, $opt2) {
return isset($opt1) ? $opt1 : (isset($opt2) ? $opt2 : null);
}
|
php
|
static function fuse(&$opt1, $opt2) {
return isset($opt1) ? $opt1 : (isset($opt2) ? $opt2 : null);
}
|
[
"static",
"function",
"fuse",
"(",
"&",
"$",
"opt1",
",",
"$",
"opt2",
")",
"{",
"return",
"isset",
"(",
"$",
"opt1",
")",
"?",
"$",
"opt1",
":",
"(",
"isset",
"(",
"$",
"opt2",
")",
"?",
"$",
"opt2",
":",
"null",
")",
";",
"}"
] |
Alternate a value to undefined variable
@param reference &$opt1 Variable
@param mixed $opt2 Alternative value
@return mixed
|
[
"Alternate",
"a",
"value",
"to",
"undefined",
"variable"
] |
004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5
|
https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/Utils/Vars.php#L23-L25
|
train
|
Vectrex/vxPHP
|
src/Template/TemplateBuffer.php
|
TemplateBuffer.includeFile
|
public function includeFile($templateFilename) {
/* @deprecated use $this when accessing assigned variables */
$tpl = $this;
eval('?>' .
file_get_contents(Application::getInstance()->getRootPath() .
(defined('TPL_PATH') ? str_replace('/', DIRECTORY_SEPARATOR, ltrim(TPL_PATH, '/')) : '') .
$templateFilename
));
}
|
php
|
public function includeFile($templateFilename) {
/* @deprecated use $this when accessing assigned variables */
$tpl = $this;
eval('?>' .
file_get_contents(Application::getInstance()->getRootPath() .
(defined('TPL_PATH') ? str_replace('/', DIRECTORY_SEPARATOR, ltrim(TPL_PATH, '/')) : '') .
$templateFilename
));
}
|
[
"public",
"function",
"includeFile",
"(",
"$",
"templateFilename",
")",
"{",
"/* @deprecated use $this when accessing assigned variables */",
"$",
"tpl",
"=",
"$",
"this",
";",
"eval",
"(",
"'?>'",
".",
"file_get_contents",
"(",
"Application",
"::",
"getInstance",
"(",
")",
"->",
"getRootPath",
"(",
")",
".",
"(",
"defined",
"(",
"'TPL_PATH'",
")",
"?",
"str_replace",
"(",
"'/'",
",",
"DIRECTORY_SEPARATOR",
",",
"ltrim",
"(",
"TPL_PATH",
",",
"'/'",
")",
")",
":",
"''",
")",
".",
"$",
"templateFilename",
")",
")",
";",
"}"
] |
include another template file
does only path handling
included files are within the same scope as the including file
@param string $templateFilename
@throws \vxPHP\Application\Exception\ApplicationException
|
[
"include",
"another",
"template",
"file",
"does",
"only",
"path",
"handling",
"included",
"files",
"are",
"within",
"the",
"same",
"scope",
"as",
"the",
"including",
"file"
] |
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
|
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Template/TemplateBuffer.php#L44-L56
|
train
|
n2n/n2n-io
|
src/app/n2n/io/fs/FsPath.php
|
FsPath.createFile
|
public function createFile($perm) {
if ($this->isFile()) return false;
IoUtils::touch($this->path);
IoUtils::chmod($this->path, $perm);
return true;
}
|
php
|
public function createFile($perm) {
if ($this->isFile()) return false;
IoUtils::touch($this->path);
IoUtils::chmod($this->path, $perm);
return true;
}
|
[
"public",
"function",
"createFile",
"(",
"$",
"perm",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isFile",
"(",
")",
")",
"return",
"false",
";",
"IoUtils",
"::",
"touch",
"(",
"$",
"this",
"->",
"path",
")",
";",
"IoUtils",
"::",
"chmod",
"(",
"$",
"this",
"->",
"path",
",",
"$",
"perm",
")",
";",
"return",
"true",
";",
"}"
] |
Atomically creates a new, empty file named by this abstract path if and only if a file with this name does not yet exist.
@return bool true if the named file does not exist and was successfully created; false if the named file already exists
|
[
"Atomically",
"creates",
"a",
"new",
"empty",
"file",
"named",
"by",
"this",
"abstract",
"path",
"if",
"and",
"only",
"if",
"a",
"file",
"with",
"this",
"name",
"does",
"not",
"yet",
"exist",
"."
] |
ff642e195f0c0db1273b6c067eff1192cf2cd987
|
https://github.com/n2n/n2n-io/blob/ff642e195f0c0db1273b6c067eff1192cf2cd987/src/app/n2n/io/fs/FsPath.php#L158-L165
|
train
|
phpffcms/ffcms-core
|
src/Helper/Mailer.php
|
Mailer.tpl
|
public function tpl(string $tpl, ?array $params = [], ?string $dir = null)
{
try {
$this->message = App::$View->render($tpl, $params, $dir);
} catch (SyntaxException $e) {
}
return $this;
}
|
php
|
public function tpl(string $tpl, ?array $params = [], ?string $dir = null)
{
try {
$this->message = App::$View->render($tpl, $params, $dir);
} catch (SyntaxException $e) {
}
return $this;
}
|
[
"public",
"function",
"tpl",
"(",
"string",
"$",
"tpl",
",",
"?",
"array",
"$",
"params",
"=",
"[",
"]",
",",
"?",
"string",
"$",
"dir",
"=",
"null",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"message",
"=",
"App",
"::",
"$",
"View",
"->",
"render",
"(",
"$",
"tpl",
",",
"$",
"params",
",",
"$",
"dir",
")",
";",
"}",
"catch",
"(",
"SyntaxException",
"$",
"e",
")",
"{",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set tpl file
@param string $tpl
@param array|null $params
@param null|string $dir
@return $this
|
[
"Set",
"tpl",
"file"
] |
44a309553ef9f115ccfcfd71f2ac6e381c612082
|
https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Helper/Mailer.php#L49-L56
|
train
|
phpffcms/ffcms-core
|
src/Helper/Mailer.php
|
Mailer.send
|
public function send(string $address, string $subject, ?string $message = null): bool
{
// try to get message from global if not passed direct
if ($message === null) {
$message = $this->message;
}
try {
if ($message === null) {
throw new \Exception('Message body is empty!');
}
// try to build message and send it
$message = (new \Swift_Message($subject))
->setFrom($this->from)
->setTo($address)
->setBody($message, 'text/html');
$this->swift->send($message);
return true;
} catch (\Exception $e) {
if (App::$Debug) {
App::$Debug->addException($e);
App::$Debug->addMessage('Send mail failed! Info: ' . $e->getMessage(), 'error');
}
return false;
}
}
|
php
|
public function send(string $address, string $subject, ?string $message = null): bool
{
// try to get message from global if not passed direct
if ($message === null) {
$message = $this->message;
}
try {
if ($message === null) {
throw new \Exception('Message body is empty!');
}
// try to build message and send it
$message = (new \Swift_Message($subject))
->setFrom($this->from)
->setTo($address)
->setBody($message, 'text/html');
$this->swift->send($message);
return true;
} catch (\Exception $e) {
if (App::$Debug) {
App::$Debug->addException($e);
App::$Debug->addMessage('Send mail failed! Info: ' . $e->getMessage(), 'error');
}
return false;
}
}
|
[
"public",
"function",
"send",
"(",
"string",
"$",
"address",
",",
"string",
"$",
"subject",
",",
"?",
"string",
"$",
"message",
"=",
"null",
")",
":",
"bool",
"{",
"// try to get message from global if not passed direct",
"if",
"(",
"$",
"message",
"===",
"null",
")",
"{",
"$",
"message",
"=",
"$",
"this",
"->",
"message",
";",
"}",
"try",
"{",
"if",
"(",
"$",
"message",
"===",
"null",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Message body is empty!'",
")",
";",
"}",
"// try to build message and send it",
"$",
"message",
"=",
"(",
"new",
"\\",
"Swift_Message",
"(",
"$",
"subject",
")",
")",
"->",
"setFrom",
"(",
"$",
"this",
"->",
"from",
")",
"->",
"setTo",
"(",
"$",
"address",
")",
"->",
"setBody",
"(",
"$",
"message",
",",
"'text/html'",
")",
";",
"$",
"this",
"->",
"swift",
"->",
"send",
"(",
"$",
"message",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"App",
"::",
"$",
"Debug",
")",
"{",
"App",
"::",
"$",
"Debug",
"->",
"addException",
"(",
"$",
"e",
")",
";",
"App",
"::",
"$",
"Debug",
"->",
"addMessage",
"(",
"'Send mail failed! Info: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"'error'",
")",
";",
"}",
"return",
"false",
";",
"}",
"}"
] |
Set mail to address
@param string $address
@param string $subject
@param null|string $message
@return bool
|
[
"Set",
"mail",
"to",
"address"
] |
44a309553ef9f115ccfcfd71f2ac6e381c612082
|
https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Helper/Mailer.php#L65-L91
|
train
|
agentmedia/phine-core
|
src/Core/Modules/Backend/LayoutForm.php
|
LayoutForm.Init
|
protected function Init()
{
$this->layout = new Layout(Request::GetData('layout'));
$this->layoutRights = new LayoutRights($this->layout->GetUserGroupRights());
$this->InitAreas();
$this->AddNameField();
$this->AddAreasField();
$this->AddUserGroupField();
$this->AddSubmit();
return parent::Init();
}
|
php
|
protected function Init()
{
$this->layout = new Layout(Request::GetData('layout'));
$this->layoutRights = new LayoutRights($this->layout->GetUserGroupRights());
$this->InitAreas();
$this->AddNameField();
$this->AddAreasField();
$this->AddUserGroupField();
$this->AddSubmit();
return parent::Init();
}
|
[
"protected",
"function",
"Init",
"(",
")",
"{",
"$",
"this",
"->",
"layout",
"=",
"new",
"Layout",
"(",
"Request",
"::",
"GetData",
"(",
"'layout'",
")",
")",
";",
"$",
"this",
"->",
"layoutRights",
"=",
"new",
"LayoutRights",
"(",
"$",
"this",
"->",
"layout",
"->",
"GetUserGroupRights",
"(",
")",
")",
";",
"$",
"this",
"->",
"InitAreas",
"(",
")",
";",
"$",
"this",
"->",
"AddNameField",
"(",
")",
";",
"$",
"this",
"->",
"AddAreasField",
"(",
")",
";",
"$",
"this",
"->",
"AddUserGroupField",
"(",
")",
";",
"$",
"this",
"->",
"AddSubmit",
"(",
")",
";",
"return",
"parent",
"::",
"Init",
"(",
")",
";",
"}"
] |
Initializes the layout form
@return boolea
|
[
"Initializes",
"the",
"layout",
"form"
] |
38c1be8d03ebffae950d00a96da3c612aff67832
|
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/LayoutForm.php#L58-L68
|
train
|
agentmedia/phine-core
|
src/Core/Modules/Backend/LayoutForm.php
|
LayoutForm.AddAreasField
|
private function AddAreasField()
{
$name = 'Areas';
$field = Input::Text($name, join(', ' , $this->areaNames));
$this->AddField($field);
if ($this->layout->Exists())
{
$field->SetHtmlAttribute('readonly', 'readonly');
}
else
{
$this->SetTransAttribute($name, 'placeholder');
$this->SetRequired($name);
}
}
|
php
|
private function AddAreasField()
{
$name = 'Areas';
$field = Input::Text($name, join(', ' , $this->areaNames));
$this->AddField($field);
if ($this->layout->Exists())
{
$field->SetHtmlAttribute('readonly', 'readonly');
}
else
{
$this->SetTransAttribute($name, 'placeholder');
$this->SetRequired($name);
}
}
|
[
"private",
"function",
"AddAreasField",
"(",
")",
"{",
"$",
"name",
"=",
"'Areas'",
";",
"$",
"field",
"=",
"Input",
"::",
"Text",
"(",
"$",
"name",
",",
"join",
"(",
"', '",
",",
"$",
"this",
"->",
"areaNames",
")",
")",
";",
"$",
"this",
"->",
"AddField",
"(",
"$",
"field",
")",
";",
"if",
"(",
"$",
"this",
"->",
"layout",
"->",
"Exists",
"(",
")",
")",
"{",
"$",
"field",
"->",
"SetHtmlAttribute",
"(",
"'readonly'",
",",
"'readonly'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"SetTransAttribute",
"(",
"$",
"name",
",",
"'placeholder'",
")",
";",
"$",
"this",
"->",
"SetRequired",
"(",
"$",
"name",
")",
";",
"}",
"}"
] |
Adds the server path field to the form
|
[
"Adds",
"the",
"server",
"path",
"field",
"to",
"the",
"form"
] |
38c1be8d03ebffae950d00a96da3c612aff67832
|
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/LayoutForm.php#L132-L146
|
train
|
agentmedia/phine-core
|
src/Core/Modules/Backend/LayoutForm.php
|
LayoutForm.OnSuccess
|
protected function OnSuccess()
{
$action = Action::Update();
$isNew = !$this->layout->Exists();
if ($isNew)
{
$action = Action::Create();
$this->layout->SetUser(self::Guard()->GetUser());
}
$oldFile = $isNew ? '' : PathUtil::LayoutTemplate($this->layout);
$this->layout->SetName($this->Value('Name'));
$this->layout->Save();
$logger = new Logger(self::Guard()->GetUser());
$logger->ReportLayoutAction($this->layout, $action);
if ($this->CanAssignGroup())
{
$this->SaveRights();
}
if ($isNew)
{
$this->SaveAreas();
}
$this->UpdateFiles($oldFile);
$args = array('layout'=>$this->layout->GetID());
Response::Redirect(BackendRouter::ModuleUrl(new AreaList(), $args));
}
|
php
|
protected function OnSuccess()
{
$action = Action::Update();
$isNew = !$this->layout->Exists();
if ($isNew)
{
$action = Action::Create();
$this->layout->SetUser(self::Guard()->GetUser());
}
$oldFile = $isNew ? '' : PathUtil::LayoutTemplate($this->layout);
$this->layout->SetName($this->Value('Name'));
$this->layout->Save();
$logger = new Logger(self::Guard()->GetUser());
$logger->ReportLayoutAction($this->layout, $action);
if ($this->CanAssignGroup())
{
$this->SaveRights();
}
if ($isNew)
{
$this->SaveAreas();
}
$this->UpdateFiles($oldFile);
$args = array('layout'=>$this->layout->GetID());
Response::Redirect(BackendRouter::ModuleUrl(new AreaList(), $args));
}
|
[
"protected",
"function",
"OnSuccess",
"(",
")",
"{",
"$",
"action",
"=",
"Action",
"::",
"Update",
"(",
")",
";",
"$",
"isNew",
"=",
"!",
"$",
"this",
"->",
"layout",
"->",
"Exists",
"(",
")",
";",
"if",
"(",
"$",
"isNew",
")",
"{",
"$",
"action",
"=",
"Action",
"::",
"Create",
"(",
")",
";",
"$",
"this",
"->",
"layout",
"->",
"SetUser",
"(",
"self",
"::",
"Guard",
"(",
")",
"->",
"GetUser",
"(",
")",
")",
";",
"}",
"$",
"oldFile",
"=",
"$",
"isNew",
"?",
"''",
":",
"PathUtil",
"::",
"LayoutTemplate",
"(",
"$",
"this",
"->",
"layout",
")",
";",
"$",
"this",
"->",
"layout",
"->",
"SetName",
"(",
"$",
"this",
"->",
"Value",
"(",
"'Name'",
")",
")",
";",
"$",
"this",
"->",
"layout",
"->",
"Save",
"(",
")",
";",
"$",
"logger",
"=",
"new",
"Logger",
"(",
"self",
"::",
"Guard",
"(",
")",
"->",
"GetUser",
"(",
")",
")",
";",
"$",
"logger",
"->",
"ReportLayoutAction",
"(",
"$",
"this",
"->",
"layout",
",",
"$",
"action",
")",
";",
"if",
"(",
"$",
"this",
"->",
"CanAssignGroup",
"(",
")",
")",
"{",
"$",
"this",
"->",
"SaveRights",
"(",
")",
";",
"}",
"if",
"(",
"$",
"isNew",
")",
"{",
"$",
"this",
"->",
"SaveAreas",
"(",
")",
";",
"}",
"$",
"this",
"->",
"UpdateFiles",
"(",
"$",
"oldFile",
")",
";",
"$",
"args",
"=",
"array",
"(",
"'layout'",
"=>",
"$",
"this",
"->",
"layout",
"->",
"GetID",
"(",
")",
")",
";",
"Response",
"::",
"Redirect",
"(",
"BackendRouter",
"::",
"ModuleUrl",
"(",
"new",
"AreaList",
"(",
")",
",",
"$",
"args",
")",
")",
";",
"}"
] |
Saves the layout
|
[
"Saves",
"the",
"layout"
] |
38c1be8d03ebffae950d00a96da3c612aff67832
|
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/LayoutForm.php#L151-L176
|
train
|
itkg/core
|
src/Itkg/Core/CollectionAbstract.php
|
CollectionAbstract.getById
|
public function getById($id)
{
if (isset($this->elements[$id])) {
return $this->elements[$id];
}
throw new \InvalidArgumentException(sprintf('Element for id %s does not exist', $id));
}
|
php
|
public function getById($id)
{
if (isset($this->elements[$id])) {
return $this->elements[$id];
}
throw new \InvalidArgumentException(sprintf('Element for id %s does not exist', $id));
}
|
[
"public",
"function",
"getById",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"elements",
"[",
"$",
"id",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"elements",
"[",
"$",
"id",
"]",
";",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Element for id %s does not exist'",
",",
"$",
"id",
")",
")",
";",
"}"
] |
Get an entity by its ID
@param $id
@return EntityAbstract
@throws \InvalidArgumentException
|
[
"Get",
"an",
"entity",
"by",
"its",
"ID"
] |
e5e4efb05feb4d23b0df41f2b21fd095103e593b
|
https://github.com/itkg/core/blob/e5e4efb05feb4d23b0df41f2b21fd095103e593b/src/Itkg/Core/CollectionAbstract.php#L47-L54
|
train
|
ekyna/PaymentBundle
|
Form/EventListener/BuildConfigSubscriber.php
|
BuildConfigSubscriber.buildConfigField
|
public function buildConfigField(FormEvent $event)
{
/** @var array $data */
$data = $event->getData();
if (is_null($data)) {
return;
}
$propertyPath = is_array($data) ? '[factoryName]' : 'factoryName';
$factoryName = PropertyAccess::createPropertyAccessor()->getValue($data, $propertyPath);
if (empty($factoryName)) {
return;
}
$paymentFactory = $this->registry->getGatewayFactory($factoryName);
$config = $paymentFactory->createConfig();
if (empty($config['payum.default_options'])) {
return;
}
$form = $event->getForm();
$form->add('config', 'form', [
'label' => 'ekyna_core.field.config',
]);
$configForm = $form->get('config');
$propertyPath = is_array($data) ? '[config]' : 'config';
$firstTime = false == PropertyAccess::createPropertyAccessor()->getValue($data, $propertyPath);
foreach ($config['payum.default_options'] as $name => $value) {
$propertyPath = is_array($data) ? "[config][$name]" : "config[$name]";
if ($firstTime) {
PropertyAccess::createPropertyAccessor()->setValue($data, $propertyPath, $value);
}
$type = 'text';
$options = array();
if (is_bool($value)) {
$type = 'checkbox';
$options['attr'] = ['align_with_widget' => true];
} elseif(is_numeric($value)) {
$type = is_float($value) ? 'number' : 'integer';
} elseif (is_array($value)) {
continue;
}
$options['required'] = in_array($name, $config['payum.required_options']);
$configForm->add($name, $type, $options);
}
$event->setData($data);
}
|
php
|
public function buildConfigField(FormEvent $event)
{
/** @var array $data */
$data = $event->getData();
if (is_null($data)) {
return;
}
$propertyPath = is_array($data) ? '[factoryName]' : 'factoryName';
$factoryName = PropertyAccess::createPropertyAccessor()->getValue($data, $propertyPath);
if (empty($factoryName)) {
return;
}
$paymentFactory = $this->registry->getGatewayFactory($factoryName);
$config = $paymentFactory->createConfig();
if (empty($config['payum.default_options'])) {
return;
}
$form = $event->getForm();
$form->add('config', 'form', [
'label' => 'ekyna_core.field.config',
]);
$configForm = $form->get('config');
$propertyPath = is_array($data) ? '[config]' : 'config';
$firstTime = false == PropertyAccess::createPropertyAccessor()->getValue($data, $propertyPath);
foreach ($config['payum.default_options'] as $name => $value) {
$propertyPath = is_array($data) ? "[config][$name]" : "config[$name]";
if ($firstTime) {
PropertyAccess::createPropertyAccessor()->setValue($data, $propertyPath, $value);
}
$type = 'text';
$options = array();
if (is_bool($value)) {
$type = 'checkbox';
$options['attr'] = ['align_with_widget' => true];
} elseif(is_numeric($value)) {
$type = is_float($value) ? 'number' : 'integer';
} elseif (is_array($value)) {
continue;
}
$options['required'] = in_array($name, $config['payum.required_options']);
$configForm->add($name, $type, $options);
}
$event->setData($data);
}
|
[
"public",
"function",
"buildConfigField",
"(",
"FormEvent",
"$",
"event",
")",
"{",
"/** @var array $data */",
"$",
"data",
"=",
"$",
"event",
"->",
"getData",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"data",
")",
")",
"{",
"return",
";",
"}",
"$",
"propertyPath",
"=",
"is_array",
"(",
"$",
"data",
")",
"?",
"'[factoryName]'",
":",
"'factoryName'",
";",
"$",
"factoryName",
"=",
"PropertyAccess",
"::",
"createPropertyAccessor",
"(",
")",
"->",
"getValue",
"(",
"$",
"data",
",",
"$",
"propertyPath",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"factoryName",
")",
")",
"{",
"return",
";",
"}",
"$",
"paymentFactory",
"=",
"$",
"this",
"->",
"registry",
"->",
"getGatewayFactory",
"(",
"$",
"factoryName",
")",
";",
"$",
"config",
"=",
"$",
"paymentFactory",
"->",
"createConfig",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"config",
"[",
"'payum.default_options'",
"]",
")",
")",
"{",
"return",
";",
"}",
"$",
"form",
"=",
"$",
"event",
"->",
"getForm",
"(",
")",
";",
"$",
"form",
"->",
"add",
"(",
"'config'",
",",
"'form'",
",",
"[",
"'label'",
"=>",
"'ekyna_core.field.config'",
",",
"]",
")",
";",
"$",
"configForm",
"=",
"$",
"form",
"->",
"get",
"(",
"'config'",
")",
";",
"$",
"propertyPath",
"=",
"is_array",
"(",
"$",
"data",
")",
"?",
"'[config]'",
":",
"'config'",
";",
"$",
"firstTime",
"=",
"false",
"==",
"PropertyAccess",
"::",
"createPropertyAccessor",
"(",
")",
"->",
"getValue",
"(",
"$",
"data",
",",
"$",
"propertyPath",
")",
";",
"foreach",
"(",
"$",
"config",
"[",
"'payum.default_options'",
"]",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"propertyPath",
"=",
"is_array",
"(",
"$",
"data",
")",
"?",
"\"[config][$name]\"",
":",
"\"config[$name]\"",
";",
"if",
"(",
"$",
"firstTime",
")",
"{",
"PropertyAccess",
"::",
"createPropertyAccessor",
"(",
")",
"->",
"setValue",
"(",
"$",
"data",
",",
"$",
"propertyPath",
",",
"$",
"value",
")",
";",
"}",
"$",
"type",
"=",
"'text'",
";",
"$",
"options",
"=",
"array",
"(",
")",
";",
"if",
"(",
"is_bool",
"(",
"$",
"value",
")",
")",
"{",
"$",
"type",
"=",
"'checkbox'",
";",
"$",
"options",
"[",
"'attr'",
"]",
"=",
"[",
"'align_with_widget'",
"=>",
"true",
"]",
";",
"}",
"elseif",
"(",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"$",
"type",
"=",
"is_float",
"(",
"$",
"value",
")",
"?",
"'number'",
":",
"'integer'",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"continue",
";",
"}",
"$",
"options",
"[",
"'required'",
"]",
"=",
"in_array",
"(",
"$",
"name",
",",
"$",
"config",
"[",
"'payum.required_options'",
"]",
")",
";",
"$",
"configForm",
"->",
"add",
"(",
"$",
"name",
",",
"$",
"type",
",",
"$",
"options",
")",
";",
"}",
"$",
"event",
"->",
"setData",
"(",
"$",
"data",
")",
";",
"}"
] |
Builds the config field.
@param FormEvent $event
|
[
"Builds",
"the",
"config",
"field",
"."
] |
1b4f4103b28e3a4f8dbfac2cbd872d728238f4d1
|
https://github.com/ekyna/PaymentBundle/blob/1b4f4103b28e3a4f8dbfac2cbd872d728238f4d1/Form/EventListener/BuildConfigSubscriber.php#L38-L90
|
train
|
Finesse/QueryScribe
|
src/QueryBricks/JoinTrait.php
|
JoinTrait.innerJoin
|
public function innerJoin($table, ...$criterion): self
{
$this->join[] = $this->joinArgumentsToJoinObject('INNER', $table, $criterion);
return $this;
}
|
php
|
public function innerJoin($table, ...$criterion): self
{
$this->join[] = $this->joinArgumentsToJoinObject('INNER', $table, $criterion);
return $this;
}
|
[
"public",
"function",
"innerJoin",
"(",
"$",
"table",
",",
"...",
"$",
"criterion",
")",
":",
"self",
"{",
"$",
"this",
"->",
"join",
"[",
"]",
"=",
"$",
"this",
"->",
"joinArgumentsToJoinObject",
"(",
"'INNER'",
",",
"$",
"table",
",",
"$",
"criterion",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Adds a table joined with the "inner" rule.
The first argument is a table name or an array where the first value is a table name and the second value is the
table alias name.
The rest arguments may have one of the following formats:
- column1, rule, column1 — column compared to another column by the given rule. Include a table name to
eliminate an ambiguity;
- column1, column2 — column is equal to another column;
- Closure – complex joining criterion;
- array[] – criteria joined by the AND rule (the values are the arguments lists for this method);
- Raw – raw SQL.
@param string|\Closure|Query|StatementInterface|string[]|\Closure[]|self[]|StatementInterface[] $table
@param string|\Closure|Query|StatementInterface|array[] $column1
@param string|\Closure|Query|StatementInterface|null $rule
@param string|\Closure|Query|StatementInterface|null $column2
@return $this
@throws InvalidArgumentException
@throws InvalidReturnValueException
|
[
"Adds",
"a",
"table",
"joined",
"with",
"the",
"inner",
"rule",
"."
] |
4edba721e37693780d142229b3ecb0cd4004c7a5
|
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/QueryBricks/JoinTrait.php#L58-L62
|
train
|
Finesse/QueryScribe
|
src/QueryBricks/JoinTrait.php
|
JoinTrait.outerJoin
|
public function outerJoin($table, ...$criterion): self
{
$this->join[] = $this->joinArgumentsToJoinObject('OUTER', $table, $criterion);
return $this;
}
|
php
|
public function outerJoin($table, ...$criterion): self
{
$this->join[] = $this->joinArgumentsToJoinObject('OUTER', $table, $criterion);
return $this;
}
|
[
"public",
"function",
"outerJoin",
"(",
"$",
"table",
",",
"...",
"$",
"criterion",
")",
":",
"self",
"{",
"$",
"this",
"->",
"join",
"[",
"]",
"=",
"$",
"this",
"->",
"joinArgumentsToJoinObject",
"(",
"'OUTER'",
",",
"$",
"table",
",",
"$",
"criterion",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Adds a table joined with the "outer" rule.
@see innerJoin The arguments format
@return $this
@throws InvalidArgumentException
@throws InvalidReturnValueException
|
[
"Adds",
"a",
"table",
"joined",
"with",
"the",
"outer",
"rule",
"."
] |
4edba721e37693780d142229b3ecb0cd4004c7a5
|
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/QueryBricks/JoinTrait.php#L72-L76
|
train
|
Finesse/QueryScribe
|
src/QueryBricks/JoinTrait.php
|
JoinTrait.leftJoin
|
public function leftJoin($table, ...$criterion): self
{
$this->join[] = $this->joinArgumentsToJoinObject('LEFT', $table, $criterion);
return $this;
}
|
php
|
public function leftJoin($table, ...$criterion): self
{
$this->join[] = $this->joinArgumentsToJoinObject('LEFT', $table, $criterion);
return $this;
}
|
[
"public",
"function",
"leftJoin",
"(",
"$",
"table",
",",
"...",
"$",
"criterion",
")",
":",
"self",
"{",
"$",
"this",
"->",
"join",
"[",
"]",
"=",
"$",
"this",
"->",
"joinArgumentsToJoinObject",
"(",
"'LEFT'",
",",
"$",
"table",
",",
"$",
"criterion",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Adds a table joined with the "left" rule.
@see innerJoin The arguments format
@return $this
@throws InvalidArgumentException
@throws InvalidReturnValueException
|
[
"Adds",
"a",
"table",
"joined",
"with",
"the",
"left",
"rule",
"."
] |
4edba721e37693780d142229b3ecb0cd4004c7a5
|
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/QueryBricks/JoinTrait.php#L86-L90
|
train
|
Finesse/QueryScribe
|
src/QueryBricks/JoinTrait.php
|
JoinTrait.rightJoin
|
public function rightJoin($table, ...$criterion): self
{
$this->join[] = $this->joinArgumentsToJoinObject('RIGHT', $table, $criterion);
return $this;
}
|
php
|
public function rightJoin($table, ...$criterion): self
{
$this->join[] = $this->joinArgumentsToJoinObject('RIGHT', $table, $criterion);
return $this;
}
|
[
"public",
"function",
"rightJoin",
"(",
"$",
"table",
",",
"...",
"$",
"criterion",
")",
":",
"self",
"{",
"$",
"this",
"->",
"join",
"[",
"]",
"=",
"$",
"this",
"->",
"joinArgumentsToJoinObject",
"(",
"'RIGHT'",
",",
"$",
"table",
",",
"$",
"criterion",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Adds a table joined with the "right" rule.
@see innerJoin The arguments format
@return $this
@throws InvalidArgumentException
@throws InvalidReturnValueException
|
[
"Adds",
"a",
"table",
"joined",
"with",
"the",
"right",
"rule",
"."
] |
4edba721e37693780d142229b3ecb0cd4004c7a5
|
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/QueryBricks/JoinTrait.php#L100-L104
|
train
|
Finesse/QueryScribe
|
src/QueryBricks/JoinTrait.php
|
JoinTrait.joinArgumentsToJoinObject
|
protected function joinArgumentsToJoinObject(string $type, $table, array $criterion = []): Join
{
if (is_array($table)) {
$tableName = $table[0] ?? null;
$tableAlias = $table[1] ?? null;
} else {
$tableName = $table;
$tableAlias = null;
}
$tableName = $this->checkStringValue('Argument $tableName', $tableName);
if ($tableAlias !== null && !is_string($tableAlias)) {
return $this->handleException(InvalidArgumentException::create(
'Argument $tableAlias',
$tableAlias,
['string', 'null']
));
}
if ($criterion) {
$criterion = $this->whereArgumentsToCriterion($criterion, 'AND', true);
$criteria = ($criterion instanceof CriteriaCriterion && !$criterion->not)
? $criterion->criteria
: [$criterion];
} else {
$criteria = [];
}
return new Join($type, $tableName, $tableAlias, $criteria);
}
|
php
|
protected function joinArgumentsToJoinObject(string $type, $table, array $criterion = []): Join
{
if (is_array($table)) {
$tableName = $table[0] ?? null;
$tableAlias = $table[1] ?? null;
} else {
$tableName = $table;
$tableAlias = null;
}
$tableName = $this->checkStringValue('Argument $tableName', $tableName);
if ($tableAlias !== null && !is_string($tableAlias)) {
return $this->handleException(InvalidArgumentException::create(
'Argument $tableAlias',
$tableAlias,
['string', 'null']
));
}
if ($criterion) {
$criterion = $this->whereArgumentsToCriterion($criterion, 'AND', true);
$criteria = ($criterion instanceof CriteriaCriterion && !$criterion->not)
? $criterion->criteria
: [$criterion];
} else {
$criteria = [];
}
return new Join($type, $tableName, $tableAlias, $criteria);
}
|
[
"protected",
"function",
"joinArgumentsToJoinObject",
"(",
"string",
"$",
"type",
",",
"$",
"table",
",",
"array",
"$",
"criterion",
"=",
"[",
"]",
")",
":",
"Join",
"{",
"if",
"(",
"is_array",
"(",
"$",
"table",
")",
")",
"{",
"$",
"tableName",
"=",
"$",
"table",
"[",
"0",
"]",
"??",
"null",
";",
"$",
"tableAlias",
"=",
"$",
"table",
"[",
"1",
"]",
"??",
"null",
";",
"}",
"else",
"{",
"$",
"tableName",
"=",
"$",
"table",
";",
"$",
"tableAlias",
"=",
"null",
";",
"}",
"$",
"tableName",
"=",
"$",
"this",
"->",
"checkStringValue",
"(",
"'Argument $tableName'",
",",
"$",
"tableName",
")",
";",
"if",
"(",
"$",
"tableAlias",
"!==",
"null",
"&&",
"!",
"is_string",
"(",
"$",
"tableAlias",
")",
")",
"{",
"return",
"$",
"this",
"->",
"handleException",
"(",
"InvalidArgumentException",
"::",
"create",
"(",
"'Argument $tableAlias'",
",",
"$",
"tableAlias",
",",
"[",
"'string'",
",",
"'null'",
"]",
")",
")",
";",
"}",
"if",
"(",
"$",
"criterion",
")",
"{",
"$",
"criterion",
"=",
"$",
"this",
"->",
"whereArgumentsToCriterion",
"(",
"$",
"criterion",
",",
"'AND'",
",",
"true",
")",
";",
"$",
"criteria",
"=",
"(",
"$",
"criterion",
"instanceof",
"CriteriaCriterion",
"&&",
"!",
"$",
"criterion",
"->",
"not",
")",
"?",
"$",
"criterion",
"->",
"criteria",
":",
"[",
"$",
"criterion",
"]",
";",
"}",
"else",
"{",
"$",
"criteria",
"=",
"[",
"]",
";",
"}",
"return",
"new",
"Join",
"(",
"$",
"type",
",",
"$",
"tableName",
",",
"$",
"tableAlias",
",",
"$",
"criteria",
")",
";",
"}"
] |
Converts `join` method arguments to a join object
@see innerJoin The arguments format
@params string $type The join type (INNER, LEFT, etc.)
@params mixed $table The joined table
@params array The join criterion arguments
@return Join
@throws InvalidArgumentException
@throws InvalidReturnValueException
|
[
"Converts",
"join",
"method",
"arguments",
"to",
"a",
"join",
"object"
] |
4edba721e37693780d142229b3ecb0cd4004c7a5
|
https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/QueryBricks/JoinTrait.php#L163-L192
|
train
|
wb-crowdfusion/crowdfusion
|
system/core/classes/mvc/controllers/AbstractApiController.php
|
AbstractApiController.passthruParameter
|
protected function passthruParameter(&$dto, $variableName) {
$reqName = str_replace('.','_', $variableName);
if($this->Request->getParameter($reqName) !== null && $this->Request->getParameter($reqName) != '')
$dto->setParameter($variableName, $this->Request->getParameter($reqName));
}
|
php
|
protected function passthruParameter(&$dto, $variableName) {
$reqName = str_replace('.','_', $variableName);
if($this->Request->getParameter($reqName) !== null && $this->Request->getParameter($reqName) != '')
$dto->setParameter($variableName, $this->Request->getParameter($reqName));
}
|
[
"protected",
"function",
"passthruParameter",
"(",
"&",
"$",
"dto",
",",
"$",
"variableName",
")",
"{",
"$",
"reqName",
"=",
"str_replace",
"(",
"'.'",
",",
"'_'",
",",
"$",
"variableName",
")",
";",
"if",
"(",
"$",
"this",
"->",
"Request",
"->",
"getParameter",
"(",
"$",
"reqName",
")",
"!==",
"null",
"&&",
"$",
"this",
"->",
"Request",
"->",
"getParameter",
"(",
"$",
"reqName",
")",
"!=",
"''",
")",
"$",
"dto",
"->",
"setParameter",
"(",
"$",
"variableName",
",",
"$",
"this",
"->",
"Request",
"->",
"getParameter",
"(",
"$",
"reqName",
")",
")",
";",
"}"
] |
copied from AbstractController
|
[
"copied",
"from",
"AbstractController"
] |
8cad7988f046a6fefbed07d026cb4ae6706c1217
|
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/controllers/AbstractApiController.php#L135-L139
|
train
|
AnonymPHP/Anonym-Route
|
RouteMatcher.php
|
RouteMatcher.matchWhen
|
public function matchWhen($url = null)
{
if (null !== $url) {
$this->setMatchUrl($url);
}
return strpos($this->getRequestedUrl(), $this->getMatchUrl()) === 0;
}
|
php
|
public function matchWhen($url = null)
{
if (null !== $url) {
$this->setMatchUrl($url);
}
return strpos($this->getRequestedUrl(), $this->getMatchUrl()) === 0;
}
|
[
"public",
"function",
"matchWhen",
"(",
"$",
"url",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"url",
")",
"{",
"$",
"this",
"->",
"setMatchUrl",
"(",
"$",
"url",
")",
";",
"}",
"return",
"strpos",
"(",
"$",
"this",
"->",
"getRequestedUrl",
"(",
")",
",",
"$",
"this",
"->",
"getMatchUrl",
"(",
")",
")",
"===",
"0",
";",
"}"
] |
match uri for when( method
@param null|string $url
@return bool
|
[
"match",
"uri",
"for",
"when",
"(",
"method"
] |
bb7f8004fbbd2998af8b0061f404f026f11466ab
|
https://github.com/AnonymPHP/Anonym-Route/blob/bb7f8004fbbd2998af8b0061f404f026f11466ab/RouteMatcher.php#L71-L78
|
train
|
apioo/psx-validate
|
src/Filter/Collection.php
|
Collection.apply
|
public function apply($value)
{
$modified = false;
foreach ($this->filters as $filter) {
$result = $filter->apply($value);
if ($result === false) {
return false;
} elseif ($result === true) {
} else {
$modified = true;
$value = $result;
}
}
return $modified ? $value : true;
}
|
php
|
public function apply($value)
{
$modified = false;
foreach ($this->filters as $filter) {
$result = $filter->apply($value);
if ($result === false) {
return false;
} elseif ($result === true) {
} else {
$modified = true;
$value = $result;
}
}
return $modified ? $value : true;
}
|
[
"public",
"function",
"apply",
"(",
"$",
"value",
")",
"{",
"$",
"modified",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"filters",
"as",
"$",
"filter",
")",
"{",
"$",
"result",
"=",
"$",
"filter",
"->",
"apply",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"result",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"elseif",
"(",
"$",
"result",
"===",
"true",
")",
"{",
"}",
"else",
"{",
"$",
"modified",
"=",
"true",
";",
"$",
"value",
"=",
"$",
"result",
";",
"}",
"}",
"return",
"$",
"modified",
"?",
"$",
"value",
":",
"true",
";",
"}"
] |
Returns true if all filters allow the value
@param mixed $value
@return boolean
|
[
"Returns",
"true",
"if",
"all",
"filters",
"allow",
"the",
"value"
] |
4860c6a2c7f7ca52d3bd6d7e6ec7d6a7ddcfd83d
|
https://github.com/apioo/psx-validate/blob/4860c6a2c7f7ca52d3bd6d7e6ec7d6a7ddcfd83d/src/Filter/Collection.php#L53-L70
|
train
|
Linkvalue-Interne/MobileNotif
|
src/Model/GcmMessage.php
|
GcmMessage.setData
|
public function setData(array $data)
{
$reservedDataKeys = array(
'from',
'notification',
'to',
'registration_ids',
'collapse_key',
'priority',
'restricted_package_name',
'content_available',
'delay_while_idle',
'dry_run',
'time_to_live',
'data',
);
foreach ($data as $key => $value) {
if (!is_string($key)) {
throw new \InvalidArgumentException('Data keys must be of type string in order to convert data in a valid JSON Object.');
}
if (in_array($key, $reservedDataKeys)
|| strpos($key, 'google') === 0
|| strpos($key, 'gcm') === 0
) {
throw new \InvalidArgumentException(sprintf(
'The key "%s" is reserved or not recommended. Do not use it as data key.',
$key
));
}
}
$this->data = $data;
return $this;
}
|
php
|
public function setData(array $data)
{
$reservedDataKeys = array(
'from',
'notification',
'to',
'registration_ids',
'collapse_key',
'priority',
'restricted_package_name',
'content_available',
'delay_while_idle',
'dry_run',
'time_to_live',
'data',
);
foreach ($data as $key => $value) {
if (!is_string($key)) {
throw new \InvalidArgumentException('Data keys must be of type string in order to convert data in a valid JSON Object.');
}
if (in_array($key, $reservedDataKeys)
|| strpos($key, 'google') === 0
|| strpos($key, 'gcm') === 0
) {
throw new \InvalidArgumentException(sprintf(
'The key "%s" is reserved or not recommended. Do not use it as data key.',
$key
));
}
}
$this->data = $data;
return $this;
}
|
[
"public",
"function",
"setData",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"reservedDataKeys",
"=",
"array",
"(",
"'from'",
",",
"'notification'",
",",
"'to'",
",",
"'registration_ids'",
",",
"'collapse_key'",
",",
"'priority'",
",",
"'restricted_package_name'",
",",
"'content_available'",
",",
"'delay_while_idle'",
",",
"'dry_run'",
",",
"'time_to_live'",
",",
"'data'",
",",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Data keys must be of type string in order to convert data in a valid JSON Object.'",
")",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"reservedDataKeys",
")",
"||",
"strpos",
"(",
"$",
"key",
",",
"'google'",
")",
"===",
"0",
"||",
"strpos",
"(",
"$",
"key",
",",
"'gcm'",
")",
"===",
"0",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The key \"%s\" is reserved or not recommended. Do not use it as data key.'",
",",
"$",
"key",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"data",
"=",
"$",
"data",
";",
"return",
"$",
"this",
";",
"}"
] |
Set the value of Data.
@param array $data
@return self
|
[
"Set",
"the",
"value",
"of",
"Data",
"."
] |
e6e4c4219f3bbb0aee32e90e5fdfc8c6a7ed53f6
|
https://github.com/Linkvalue-Interne/MobileNotif/blob/e6e4c4219f3bbb0aee32e90e5fdfc8c6a7ed53f6/src/Model/GcmMessage.php#L733-L771
|
train
|
cloudtek/dynamodm
|
lib/Cloudtek/DynamoDM/Persister/DocumentPersister.php
|
DocumentPersister.addFilterToQueryBuilder
|
public function addFilterToQueryBuilder(QueryBuilder $qb)
{
$filters = $this->dm->getFilterCollection()->getFilterCriteria($this->class);
foreach ($filters as $filter) {
$qb->addCriteria($filter);
}
}
|
php
|
public function addFilterToQueryBuilder(QueryBuilder $qb)
{
$filters = $this->dm->getFilterCollection()->getFilterCriteria($this->class);
foreach ($filters as $filter) {
$qb->addCriteria($filter);
}
}
|
[
"public",
"function",
"addFilterToQueryBuilder",
"(",
"QueryBuilder",
"$",
"qb",
")",
"{",
"$",
"filters",
"=",
"$",
"this",
"->",
"dm",
"->",
"getFilterCollection",
"(",
")",
"->",
"getFilterCriteria",
"(",
"$",
"this",
"->",
"class",
")",
";",
"foreach",
"(",
"$",
"filters",
"as",
"$",
"filter",
")",
"{",
"$",
"qb",
"->",
"addCriteria",
"(",
"$",
"filter",
")",
";",
"}",
"}"
] |
Adds filter criteria to a QueryBuilder instance.
@param QueryBuilder $qb
@return void
|
[
"Adds",
"filter",
"criteria",
"to",
"a",
"QueryBuilder",
"instance",
"."
] |
119d355e2c5cbaef1f867970349b4432f5704fcd
|
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Persister/DocumentPersister.php#L110-L117
|
train
|
cloudtek/dynamodm
|
lib/Cloudtek/DynamoDM/Persister/DocumentPersister.php
|
DocumentPersister.createDocument
|
private function createDocument($data, $document = null, $refresh = false)
{
if ($this->class->isLockable) {
$lockAttribute = $this->class->getLockMetadata()->attributeName;
if (isset($result[$lockAttribute]) && $data[$lockAttribute] === LockMode::PESSIMISTIC_WRITE) {
throw LockException::lockFailed($data);
}
}
if ($document !== null) {
$refresh = true;
$identifier = $this->class->createIdentifier($data);
$this->uow->registerManaged($document, $identifier, $data);
}
return $this->uow->getOrCreateDocument($this->class, $data, $document, $refresh);
}
|
php
|
private function createDocument($data, $document = null, $refresh = false)
{
if ($this->class->isLockable) {
$lockAttribute = $this->class->getLockMetadata()->attributeName;
if (isset($result[$lockAttribute]) && $data[$lockAttribute] === LockMode::PESSIMISTIC_WRITE) {
throw LockException::lockFailed($data);
}
}
if ($document !== null) {
$refresh = true;
$identifier = $this->class->createIdentifier($data);
$this->uow->registerManaged($document, $identifier, $data);
}
return $this->uow->getOrCreateDocument($this->class, $data, $document, $refresh);
}
|
[
"private",
"function",
"createDocument",
"(",
"$",
"data",
",",
"$",
"document",
"=",
"null",
",",
"$",
"refresh",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"class",
"->",
"isLockable",
")",
"{",
"$",
"lockAttribute",
"=",
"$",
"this",
"->",
"class",
"->",
"getLockMetadata",
"(",
")",
"->",
"attributeName",
";",
"if",
"(",
"isset",
"(",
"$",
"result",
"[",
"$",
"lockAttribute",
"]",
")",
"&&",
"$",
"data",
"[",
"$",
"lockAttribute",
"]",
"===",
"LockMode",
"::",
"PESSIMISTIC_WRITE",
")",
"{",
"throw",
"LockException",
"::",
"lockFailed",
"(",
"$",
"data",
")",
";",
"}",
"}",
"if",
"(",
"$",
"document",
"!==",
"null",
")",
"{",
"$",
"refresh",
"=",
"true",
";",
"$",
"identifier",
"=",
"$",
"this",
"->",
"class",
"->",
"createIdentifier",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"uow",
"->",
"registerManaged",
"(",
"$",
"document",
",",
"$",
"identifier",
",",
"$",
"data",
")",
";",
"}",
"return",
"$",
"this",
"->",
"uow",
"->",
"getOrCreateDocument",
"(",
"$",
"this",
"->",
"class",
",",
"$",
"data",
",",
"$",
"document",
",",
"$",
"refresh",
")",
";",
"}"
] |
Creates or fills a single document object from a query result.
@param array $data Raw result data from DynamoDB.
@param object $document The document object to fill, if any.
@param bool $refresh Refresh hint for UnitOfWork behavior.
@return object The filled and managed document object or NULL, if the
query result is empty.
@throws LockException
|
[
"Creates",
"or",
"fills",
"a",
"single",
"document",
"object",
"from",
"a",
"query",
"result",
"."
] |
119d355e2c5cbaef1f867970349b4432f5704fcd
|
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Persister/DocumentPersister.php#L131-L149
|
train
|
cloudtek/dynamodm
|
lib/Cloudtek/DynamoDM/Persister/DocumentPersister.php
|
DocumentPersister.createReferenceInverseSideQuery
|
public function createReferenceInverseSideQuery(PropertyMetadata $mapping, $owner)
{
$targetClass = $this->dm->getClassMetadata($mapping->targetDocument);
$mappedBy = $targetClass->getPropertyMetadata($mapping->mappedBy);
$qb = $this->dm->createQueryBuilder($mapping->targetDocument);
//add the owning document's identifier as criteria for the mapped reference
$qb->attr($mappedBy->name)->equals($owner);
if ($mapping->mappedIndex !== null) {
$qb->index($mapping->mappedIndex);
//if mappedIndex is not set, requireIndexes is in effect and the
//querybuilder cannot find a usable index then the query will throw
//an exception on execution
}
if ($mapping->requireIndexes !== null) {
//if configured this will override any setting on the dm or class
$qb->requireIndexes($mapping->requireIndexes);
}
$qb->addCriteria((array)$mapping->criteria);
foreach ((array)$mapping->prime as $attribute) {
$qb->attr($attribute)->prime(true);
}
$query = $qb->getQuery();
$query->reverse($mapping->reverse);
$query->limit($mapping->association === PropertyMetadata::ASSOCIATION_TYPE_REFERENCE_ONE ? 1 : $mapping->limit);
return $query;
}
|
php
|
public function createReferenceInverseSideQuery(PropertyMetadata $mapping, $owner)
{
$targetClass = $this->dm->getClassMetadata($mapping->targetDocument);
$mappedBy = $targetClass->getPropertyMetadata($mapping->mappedBy);
$qb = $this->dm->createQueryBuilder($mapping->targetDocument);
//add the owning document's identifier as criteria for the mapped reference
$qb->attr($mappedBy->name)->equals($owner);
if ($mapping->mappedIndex !== null) {
$qb->index($mapping->mappedIndex);
//if mappedIndex is not set, requireIndexes is in effect and the
//querybuilder cannot find a usable index then the query will throw
//an exception on execution
}
if ($mapping->requireIndexes !== null) {
//if configured this will override any setting on the dm or class
$qb->requireIndexes($mapping->requireIndexes);
}
$qb->addCriteria((array)$mapping->criteria);
foreach ((array)$mapping->prime as $attribute) {
$qb->attr($attribute)->prime(true);
}
$query = $qb->getQuery();
$query->reverse($mapping->reverse);
$query->limit($mapping->association === PropertyMetadata::ASSOCIATION_TYPE_REFERENCE_ONE ? 1 : $mapping->limit);
return $query;
}
|
[
"public",
"function",
"createReferenceInverseSideQuery",
"(",
"PropertyMetadata",
"$",
"mapping",
",",
"$",
"owner",
")",
"{",
"$",
"targetClass",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"$",
"mapping",
"->",
"targetDocument",
")",
";",
"$",
"mappedBy",
"=",
"$",
"targetClass",
"->",
"getPropertyMetadata",
"(",
"$",
"mapping",
"->",
"mappedBy",
")",
";",
"$",
"qb",
"=",
"$",
"this",
"->",
"dm",
"->",
"createQueryBuilder",
"(",
"$",
"mapping",
"->",
"targetDocument",
")",
";",
"//add the owning document's identifier as criteria for the mapped reference",
"$",
"qb",
"->",
"attr",
"(",
"$",
"mappedBy",
"->",
"name",
")",
"->",
"equals",
"(",
"$",
"owner",
")",
";",
"if",
"(",
"$",
"mapping",
"->",
"mappedIndex",
"!==",
"null",
")",
"{",
"$",
"qb",
"->",
"index",
"(",
"$",
"mapping",
"->",
"mappedIndex",
")",
";",
"//if mappedIndex is not set, requireIndexes is in effect and the",
"//querybuilder cannot find a usable index then the query will throw",
"//an exception on execution",
"}",
"if",
"(",
"$",
"mapping",
"->",
"requireIndexes",
"!==",
"null",
")",
"{",
"//if configured this will override any setting on the dm or class",
"$",
"qb",
"->",
"requireIndexes",
"(",
"$",
"mapping",
"->",
"requireIndexes",
")",
";",
"}",
"$",
"qb",
"->",
"addCriteria",
"(",
"(",
"array",
")",
"$",
"mapping",
"->",
"criteria",
")",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"mapping",
"->",
"prime",
"as",
"$",
"attribute",
")",
"{",
"$",
"qb",
"->",
"attr",
"(",
"$",
"attribute",
")",
"->",
"prime",
"(",
"true",
")",
";",
"}",
"$",
"query",
"=",
"$",
"qb",
"->",
"getQuery",
"(",
")",
";",
"$",
"query",
"->",
"reverse",
"(",
"$",
"mapping",
"->",
"reverse",
")",
";",
"$",
"query",
"->",
"limit",
"(",
"$",
"mapping",
"->",
"association",
"===",
"PropertyMetadata",
"::",
"ASSOCIATION_TYPE_REFERENCE_ONE",
"?",
"1",
":",
"$",
"mapping",
"->",
"limit",
")",
";",
"return",
"$",
"query",
";",
"}"
] |
Build and return a query capable of populating the given inverse-side reference.
@param PropertyMetadata $mapping
@param object $owner
@return Query|Scan
|
[
"Build",
"and",
"return",
"a",
"query",
"capable",
"of",
"populating",
"the",
"given",
"inverse",
"-",
"side",
"reference",
"."
] |
119d355e2c5cbaef1f867970349b4432f5704fcd
|
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Persister/DocumentPersister.php#L159-L193
|
train
|
cloudtek/dynamodm
|
lib/Cloudtek/DynamoDM/Persister/DocumentPersister.php
|
DocumentPersister.delete
|
public function delete($document)
{
$qb = $this->dm->createQueryBuilder($this->class->name);
$identifier = $this->uow->getDocumentIdentifier($document);
$qb->delete();
$qb->setIdentifier($identifier);
if ($this->class->isLockable) {
$qb->attr($this->class->lockMetadata->name)->exists(false);
}
try {
$qb->getQuery()->execute();
} catch (\Aws\DynamoDb\Exception\DynamoDbException $e) {
if (
($this->class->isVersioned || $this->class->isLockable) &&
$e->getAwsErrorCode() === 'ConditionalCheckFailedException'
) {
throw LockException::lockFailed($document);
}
throw $e;
}
}
|
php
|
public function delete($document)
{
$qb = $this->dm->createQueryBuilder($this->class->name);
$identifier = $this->uow->getDocumentIdentifier($document);
$qb->delete();
$qb->setIdentifier($identifier);
if ($this->class->isLockable) {
$qb->attr($this->class->lockMetadata->name)->exists(false);
}
try {
$qb->getQuery()->execute();
} catch (\Aws\DynamoDb\Exception\DynamoDbException $e) {
if (
($this->class->isVersioned || $this->class->isLockable) &&
$e->getAwsErrorCode() === 'ConditionalCheckFailedException'
) {
throw LockException::lockFailed($document);
}
throw $e;
}
}
|
[
"public",
"function",
"delete",
"(",
"$",
"document",
")",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"dm",
"->",
"createQueryBuilder",
"(",
"$",
"this",
"->",
"class",
"->",
"name",
")",
";",
"$",
"identifier",
"=",
"$",
"this",
"->",
"uow",
"->",
"getDocumentIdentifier",
"(",
"$",
"document",
")",
";",
"$",
"qb",
"->",
"delete",
"(",
")",
";",
"$",
"qb",
"->",
"setIdentifier",
"(",
"$",
"identifier",
")",
";",
"if",
"(",
"$",
"this",
"->",
"class",
"->",
"isLockable",
")",
"{",
"$",
"qb",
"->",
"attr",
"(",
"$",
"this",
"->",
"class",
"->",
"lockMetadata",
"->",
"name",
")",
"->",
"exists",
"(",
"false",
")",
";",
"}",
"try",
"{",
"$",
"qb",
"->",
"getQuery",
"(",
")",
"->",
"execute",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Aws",
"\\",
"DynamoDb",
"\\",
"Exception",
"\\",
"DynamoDbException",
"$",
"e",
")",
"{",
"if",
"(",
"(",
"$",
"this",
"->",
"class",
"->",
"isVersioned",
"||",
"$",
"this",
"->",
"class",
"->",
"isLockable",
")",
"&&",
"$",
"e",
"->",
"getAwsErrorCode",
"(",
")",
"===",
"'ConditionalCheckFailedException'",
")",
"{",
"throw",
"LockException",
"::",
"lockFailed",
"(",
"$",
"document",
")",
";",
"}",
"throw",
"$",
"e",
";",
"}",
"}"
] |
Removes a document from DynamoDB
@param object $document
@return void
@throws LockException
|
[
"Removes",
"a",
"document",
"from",
"DynamoDB"
] |
119d355e2c5cbaef1f867970349b4432f5704fcd
|
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Persister/DocumentPersister.php#L237-L261
|
train
|
cloudtek/dynamodm
|
lib/Cloudtek/DynamoDM/Persister/DocumentPersister.php
|
DocumentPersister.insert
|
public function insert($document)
{
$class = $this->dm->getClassMetadata(get_class($document));
$changeset = $this->uow->getDocumentChangeSet($document);
$qb = $this->dm->createQueryBuilder($this->class->name);
foreach ($class->propertyMetadata as $mapping) {
$new = isset($changeset[$mapping->name][1]) ? $changeset[$mapping->name][1] : null;
if (($new === null && !$mapping->nullable) || $mapping->isInverseSide) {
continue;
}
if ($mapping->isMany()) {
if ($mapping->strategy === PropertyMetadata::STORAGE_STRATEGY_ADD_TO_SET || $new->isEmpty()) {
continue;
}
$this->uow->unscheduleCollectionDeletion($new);
$this->uow->unscheduleCollectionUpdate($new);
}
$qb->attr($mapping->name)->put($new);
}
//add a conditional preventing the resulting PutItem from overwriting
//an existing record with the same primary key
$class->createIdentifier($document)->addNotExistsToQueryCondition($qb->expr);
$qb->getQuery()->execute();
}
|
php
|
public function insert($document)
{
$class = $this->dm->getClassMetadata(get_class($document));
$changeset = $this->uow->getDocumentChangeSet($document);
$qb = $this->dm->createQueryBuilder($this->class->name);
foreach ($class->propertyMetadata as $mapping) {
$new = isset($changeset[$mapping->name][1]) ? $changeset[$mapping->name][1] : null;
if (($new === null && !$mapping->nullable) || $mapping->isInverseSide) {
continue;
}
if ($mapping->isMany()) {
if ($mapping->strategy === PropertyMetadata::STORAGE_STRATEGY_ADD_TO_SET || $new->isEmpty()) {
continue;
}
$this->uow->unscheduleCollectionDeletion($new);
$this->uow->unscheduleCollectionUpdate($new);
}
$qb->attr($mapping->name)->put($new);
}
//add a conditional preventing the resulting PutItem from overwriting
//an existing record with the same primary key
$class->createIdentifier($document)->addNotExistsToQueryCondition($qb->expr);
$qb->getQuery()->execute();
}
|
[
"public",
"function",
"insert",
"(",
"$",
"document",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"get_class",
"(",
"$",
"document",
")",
")",
";",
"$",
"changeset",
"=",
"$",
"this",
"->",
"uow",
"->",
"getDocumentChangeSet",
"(",
"$",
"document",
")",
";",
"$",
"qb",
"=",
"$",
"this",
"->",
"dm",
"->",
"createQueryBuilder",
"(",
"$",
"this",
"->",
"class",
"->",
"name",
")",
";",
"foreach",
"(",
"$",
"class",
"->",
"propertyMetadata",
"as",
"$",
"mapping",
")",
"{",
"$",
"new",
"=",
"isset",
"(",
"$",
"changeset",
"[",
"$",
"mapping",
"->",
"name",
"]",
"[",
"1",
"]",
")",
"?",
"$",
"changeset",
"[",
"$",
"mapping",
"->",
"name",
"]",
"[",
"1",
"]",
":",
"null",
";",
"if",
"(",
"(",
"$",
"new",
"===",
"null",
"&&",
"!",
"$",
"mapping",
"->",
"nullable",
")",
"||",
"$",
"mapping",
"->",
"isInverseSide",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"mapping",
"->",
"isMany",
"(",
")",
")",
"{",
"if",
"(",
"$",
"mapping",
"->",
"strategy",
"===",
"PropertyMetadata",
"::",
"STORAGE_STRATEGY_ADD_TO_SET",
"||",
"$",
"new",
"->",
"isEmpty",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"uow",
"->",
"unscheduleCollectionDeletion",
"(",
"$",
"new",
")",
";",
"$",
"this",
"->",
"uow",
"->",
"unscheduleCollectionUpdate",
"(",
"$",
"new",
")",
";",
"}",
"$",
"qb",
"->",
"attr",
"(",
"$",
"mapping",
"->",
"name",
")",
"->",
"put",
"(",
"$",
"new",
")",
";",
"}",
"//add a conditional preventing the resulting PutItem from overwriting",
"//an existing record with the same primary key",
"$",
"class",
"->",
"createIdentifier",
"(",
"$",
"document",
")",
"->",
"addNotExistsToQueryCondition",
"(",
"$",
"qb",
"->",
"expr",
")",
";",
"$",
"qb",
"->",
"getQuery",
"(",
")",
"->",
"execute",
"(",
")",
";",
"}"
] |
Insert the provided document.
@param object $document
@return void
|
[
"Insert",
"the",
"provided",
"document",
"."
] |
119d355e2c5cbaef1f867970349b4432f5704fcd
|
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Persister/DocumentPersister.php#L317-L347
|
train
|
cloudtek/dynamodm
|
lib/Cloudtek/DynamoDM/Persister/DocumentPersister.php
|
DocumentPersister.load
|
public function load(Identifier $identifier, $document = null, $lockMode = LockMode::NONE)
{
$qb = $this->dm->createQueryBuilder($this->class->name);
$query = $qb->get()->setIdentifier($identifier)->getQuery();
$result = $query->getSingleMarshalledResult();
return $result ? $this->createDocument($result, $document) : null;
}
|
php
|
public function load(Identifier $identifier, $document = null, $lockMode = LockMode::NONE)
{
$qb = $this->dm->createQueryBuilder($this->class->name);
$query = $qb->get()->setIdentifier($identifier)->getQuery();
$result = $query->getSingleMarshalledResult();
return $result ? $this->createDocument($result, $document) : null;
}
|
[
"public",
"function",
"load",
"(",
"Identifier",
"$",
"identifier",
",",
"$",
"document",
"=",
"null",
",",
"$",
"lockMode",
"=",
"LockMode",
"::",
"NONE",
")",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"dm",
"->",
"createQueryBuilder",
"(",
"$",
"this",
"->",
"class",
"->",
"name",
")",
";",
"$",
"query",
"=",
"$",
"qb",
"->",
"get",
"(",
")",
"->",
"setIdentifier",
"(",
"$",
"identifier",
")",
"->",
"getQuery",
"(",
")",
";",
"$",
"result",
"=",
"$",
"query",
"->",
"getSingleMarshalledResult",
"(",
")",
";",
"return",
"$",
"result",
"?",
"$",
"this",
"->",
"createDocument",
"(",
"$",
"result",
",",
"$",
"document",
")",
":",
"null",
";",
"}"
] |
Find a document by Identifier instance.
@param Identifier $identifier
@param object|null $document Document to load the data into. If not
specified, a new document is created.
@param int $lockMode
@return object|null The loaded and managed document instance or null if
no document was found
|
[
"Find",
"a",
"document",
"by",
"Identifier",
"instance",
"."
] |
119d355e2c5cbaef1f867970349b4432f5704fcd
|
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Persister/DocumentPersister.php#L360-L367
|
train
|
cloudtek/dynamodm
|
lib/Cloudtek/DynamoDM/Persister/DocumentPersister.php
|
DocumentPersister.loadAll
|
public function loadAll(array $criteria = [], $limit = null)
{
$qb = $this->dm->createQueryBuilder($this->class->name)->addCriteria($criteria);
return $qb->getQuery()->limit($limit)->execute();
}
|
php
|
public function loadAll(array $criteria = [], $limit = null)
{
$qb = $this->dm->createQueryBuilder($this->class->name)->addCriteria($criteria);
return $qb->getQuery()->limit($limit)->execute();
}
|
[
"public",
"function",
"loadAll",
"(",
"array",
"$",
"criteria",
"=",
"[",
"]",
",",
"$",
"limit",
"=",
"null",
")",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"dm",
"->",
"createQueryBuilder",
"(",
"$",
"this",
"->",
"class",
"->",
"name",
")",
"->",
"addCriteria",
"(",
"$",
"criteria",
")",
";",
"return",
"$",
"qb",
"->",
"getQuery",
"(",
")",
"->",
"limit",
"(",
"$",
"limit",
")",
"->",
"execute",
"(",
")",
";",
"}"
] |
Load all documents from a table, optionally limited by the provided criteria.
@param array $criteria Query criteria.
@param int|null $limit Limit the number of documents returned.
@return Iterator
|
[
"Load",
"all",
"documents",
"from",
"a",
"table",
"optionally",
"limited",
"by",
"the",
"provided",
"criteria",
"."
] |
119d355e2c5cbaef1f867970349b4432f5704fcd
|
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Persister/DocumentPersister.php#L377-L382
|
train
|
cloudtek/dynamodm
|
lib/Cloudtek/DynamoDM/Persister/DocumentPersister.php
|
DocumentPersister.loadReferenceManyCollectionInverseSide
|
private function loadReferenceManyCollectionInverseSide(PersistentCollectionInterface $collection)
{
$query = $this->createReferenceInverseSideQuery($collection->getMapping(), $collection->getOwner());
$documents = $query->execute()->toArray();
foreach ($documents as $key => $document) {
$collection->add($document);
}
}
|
php
|
private function loadReferenceManyCollectionInverseSide(PersistentCollectionInterface $collection)
{
$query = $this->createReferenceInverseSideQuery($collection->getMapping(), $collection->getOwner());
$documents = $query->execute()->toArray();
foreach ($documents as $key => $document) {
$collection->add($document);
}
}
|
[
"private",
"function",
"loadReferenceManyCollectionInverseSide",
"(",
"PersistentCollectionInterface",
"$",
"collection",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"createReferenceInverseSideQuery",
"(",
"$",
"collection",
"->",
"getMapping",
"(",
")",
",",
"$",
"collection",
"->",
"getOwner",
"(",
")",
")",
";",
"$",
"documents",
"=",
"$",
"query",
"->",
"execute",
"(",
")",
"->",
"toArray",
"(",
")",
";",
"foreach",
"(",
"$",
"documents",
"as",
"$",
"key",
"=>",
"$",
"document",
")",
"{",
"$",
"collection",
"->",
"add",
"(",
"$",
"document",
")",
";",
"}",
"}"
] |
Populate an inverse-side ReferenceMany association.
@param PersistentCollectionInterface $collection
@return void
|
[
"Populate",
"an",
"inverse",
"-",
"side",
"ReferenceMany",
"association",
"."
] |
119d355e2c5cbaef1f867970349b4432f5704fcd
|
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Persister/DocumentPersister.php#L451-L459
|
train
|
cloudtek/dynamodm
|
lib/Cloudtek/DynamoDM/Persister/DocumentPersister.php
|
DocumentPersister.loadReferenceManyCollectionOwningSide
|
private function loadReferenceManyCollectionOwningSide(PersistentCollectionInterface $collection)
{
$mapping = $collection->getMapping();
/** @var Identifier[] $identifiers */
$identifiers = array_map(
function ($referenceData) use ($mapping) {
return $this->ap->loadReference($mapping, $referenceData);
},
$collection->getRawData()
);
//reverse + limit must be applied here rather than on the query,
//since we are potentially performing multiple queries
if ($mapping->reverse) {
$identifiers = array_reverse($identifiers);
}
if ($mapping->limit !== null) {
$identifiers = array_slice($identifiers, 0, $mapping->limit);
}
//build document proxies and group by class
$groupedIds = [];
foreach ($identifiers as $key => $identifier) {
//create a reference to the class+id and add it to the collection
$reference = $identifier->getDocument($this->dm);
if ($mapping->type === Type::MAP) {
$collection->set($key, $reference);
} else {
$collection->add($reference);
}
//only query for the referenced object if it is not already initialized
if ($reference instanceof Proxy && !$reference->__isInitialized__) {
$className = $identifier->class->name;
$groupedIds[$className][] = $identifier;
}
}
//load documents
foreach ($groupedIds as $className => $batch) {
$class = $this->dm->getClassMetadata($className);
$filters = array_merge(
[(array)$mapping->criteria],
$this->dm->getFilterCollection()->getFilterCriteria($class)
);
$qb = $this->dm->createQueryBuilder($className);
if (!empty($filters)) {
//filters require a full table scan
//TODO: needs documentation
//add identifiers to the query as OR conditions
/** @var Identifier $identifier */
foreach ($batch as $identifier) {
$expr = $qb->expr();
$identifier->addToQueryCondition($expr);
$qb->addOr($expr);
}
//add any other filter criteria
foreach ($filters as $filter) {
$qb->addCriteria($filter);
}
$query = $qb->getQuery();
} else {
//load using batchgetitem
foreach ($batch as $identifier) {
$qb->get()->setIdentifier($identifier)->batch();
}
$query = $qb->getBatch();
}
foreach ($query->getMarshalledResult() as $documentData) {
$identifier = $class->createIdentifier($documentData);
$document = $this->uow->getByIdentifier($identifier);
if ($document instanceof Proxy && !$document->__isInitialized()) {
$data = $this->hydratorFactory->hydrate($document, $documentData);
$this->uow->setOriginalDocumentData($document, $data);
$document->__isInitialized__ = true;
}
}
}
}
|
php
|
private function loadReferenceManyCollectionOwningSide(PersistentCollectionInterface $collection)
{
$mapping = $collection->getMapping();
/** @var Identifier[] $identifiers */
$identifiers = array_map(
function ($referenceData) use ($mapping) {
return $this->ap->loadReference($mapping, $referenceData);
},
$collection->getRawData()
);
//reverse + limit must be applied here rather than on the query,
//since we are potentially performing multiple queries
if ($mapping->reverse) {
$identifiers = array_reverse($identifiers);
}
if ($mapping->limit !== null) {
$identifiers = array_slice($identifiers, 0, $mapping->limit);
}
//build document proxies and group by class
$groupedIds = [];
foreach ($identifiers as $key => $identifier) {
//create a reference to the class+id and add it to the collection
$reference = $identifier->getDocument($this->dm);
if ($mapping->type === Type::MAP) {
$collection->set($key, $reference);
} else {
$collection->add($reference);
}
//only query for the referenced object if it is not already initialized
if ($reference instanceof Proxy && !$reference->__isInitialized__) {
$className = $identifier->class->name;
$groupedIds[$className][] = $identifier;
}
}
//load documents
foreach ($groupedIds as $className => $batch) {
$class = $this->dm->getClassMetadata($className);
$filters = array_merge(
[(array)$mapping->criteria],
$this->dm->getFilterCollection()->getFilterCriteria($class)
);
$qb = $this->dm->createQueryBuilder($className);
if (!empty($filters)) {
//filters require a full table scan
//TODO: needs documentation
//add identifiers to the query as OR conditions
/** @var Identifier $identifier */
foreach ($batch as $identifier) {
$expr = $qb->expr();
$identifier->addToQueryCondition($expr);
$qb->addOr($expr);
}
//add any other filter criteria
foreach ($filters as $filter) {
$qb->addCriteria($filter);
}
$query = $qb->getQuery();
} else {
//load using batchgetitem
foreach ($batch as $identifier) {
$qb->get()->setIdentifier($identifier)->batch();
}
$query = $qb->getBatch();
}
foreach ($query->getMarshalledResult() as $documentData) {
$identifier = $class->createIdentifier($documentData);
$document = $this->uow->getByIdentifier($identifier);
if ($document instanceof Proxy && !$document->__isInitialized()) {
$data = $this->hydratorFactory->hydrate($document, $documentData);
$this->uow->setOriginalDocumentData($document, $data);
$document->__isInitialized__ = true;
}
}
}
}
|
[
"private",
"function",
"loadReferenceManyCollectionOwningSide",
"(",
"PersistentCollectionInterface",
"$",
"collection",
")",
"{",
"$",
"mapping",
"=",
"$",
"collection",
"->",
"getMapping",
"(",
")",
";",
"/** @var Identifier[] $identifiers */",
"$",
"identifiers",
"=",
"array_map",
"(",
"function",
"(",
"$",
"referenceData",
")",
"use",
"(",
"$",
"mapping",
")",
"{",
"return",
"$",
"this",
"->",
"ap",
"->",
"loadReference",
"(",
"$",
"mapping",
",",
"$",
"referenceData",
")",
";",
"}",
",",
"$",
"collection",
"->",
"getRawData",
"(",
")",
")",
";",
"//reverse + limit must be applied here rather than on the query,",
"//since we are potentially performing multiple queries",
"if",
"(",
"$",
"mapping",
"->",
"reverse",
")",
"{",
"$",
"identifiers",
"=",
"array_reverse",
"(",
"$",
"identifiers",
")",
";",
"}",
"if",
"(",
"$",
"mapping",
"->",
"limit",
"!==",
"null",
")",
"{",
"$",
"identifiers",
"=",
"array_slice",
"(",
"$",
"identifiers",
",",
"0",
",",
"$",
"mapping",
"->",
"limit",
")",
";",
"}",
"//build document proxies and group by class",
"$",
"groupedIds",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"identifiers",
"as",
"$",
"key",
"=>",
"$",
"identifier",
")",
"{",
"//create a reference to the class+id and add it to the collection",
"$",
"reference",
"=",
"$",
"identifier",
"->",
"getDocument",
"(",
"$",
"this",
"->",
"dm",
")",
";",
"if",
"(",
"$",
"mapping",
"->",
"type",
"===",
"Type",
"::",
"MAP",
")",
"{",
"$",
"collection",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"reference",
")",
";",
"}",
"else",
"{",
"$",
"collection",
"->",
"add",
"(",
"$",
"reference",
")",
";",
"}",
"//only query for the referenced object if it is not already initialized",
"if",
"(",
"$",
"reference",
"instanceof",
"Proxy",
"&&",
"!",
"$",
"reference",
"->",
"__isInitialized__",
")",
"{",
"$",
"className",
"=",
"$",
"identifier",
"->",
"class",
"->",
"name",
";",
"$",
"groupedIds",
"[",
"$",
"className",
"]",
"[",
"]",
"=",
"$",
"identifier",
";",
"}",
"}",
"//load documents",
"foreach",
"(",
"$",
"groupedIds",
"as",
"$",
"className",
"=>",
"$",
"batch",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"$",
"className",
")",
";",
"$",
"filters",
"=",
"array_merge",
"(",
"[",
"(",
"array",
")",
"$",
"mapping",
"->",
"criteria",
"]",
",",
"$",
"this",
"->",
"dm",
"->",
"getFilterCollection",
"(",
")",
"->",
"getFilterCriteria",
"(",
"$",
"class",
")",
")",
";",
"$",
"qb",
"=",
"$",
"this",
"->",
"dm",
"->",
"createQueryBuilder",
"(",
"$",
"className",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"filters",
")",
")",
"{",
"//filters require a full table scan",
"//TODO: needs documentation",
"//add identifiers to the query as OR conditions",
"/** @var Identifier $identifier */",
"foreach",
"(",
"$",
"batch",
"as",
"$",
"identifier",
")",
"{",
"$",
"expr",
"=",
"$",
"qb",
"->",
"expr",
"(",
")",
";",
"$",
"identifier",
"->",
"addToQueryCondition",
"(",
"$",
"expr",
")",
";",
"$",
"qb",
"->",
"addOr",
"(",
"$",
"expr",
")",
";",
"}",
"//add any other filter criteria",
"foreach",
"(",
"$",
"filters",
"as",
"$",
"filter",
")",
"{",
"$",
"qb",
"->",
"addCriteria",
"(",
"$",
"filter",
")",
";",
"}",
"$",
"query",
"=",
"$",
"qb",
"->",
"getQuery",
"(",
")",
";",
"}",
"else",
"{",
"//load using batchgetitem",
"foreach",
"(",
"$",
"batch",
"as",
"$",
"identifier",
")",
"{",
"$",
"qb",
"->",
"get",
"(",
")",
"->",
"setIdentifier",
"(",
"$",
"identifier",
")",
"->",
"batch",
"(",
")",
";",
"}",
"$",
"query",
"=",
"$",
"qb",
"->",
"getBatch",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"query",
"->",
"getMarshalledResult",
"(",
")",
"as",
"$",
"documentData",
")",
"{",
"$",
"identifier",
"=",
"$",
"class",
"->",
"createIdentifier",
"(",
"$",
"documentData",
")",
";",
"$",
"document",
"=",
"$",
"this",
"->",
"uow",
"->",
"getByIdentifier",
"(",
"$",
"identifier",
")",
";",
"if",
"(",
"$",
"document",
"instanceof",
"Proxy",
"&&",
"!",
"$",
"document",
"->",
"__isInitialized",
"(",
")",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"hydratorFactory",
"->",
"hydrate",
"(",
"$",
"document",
",",
"$",
"documentData",
")",
";",
"$",
"this",
"->",
"uow",
"->",
"setOriginalDocumentData",
"(",
"$",
"document",
",",
"$",
"data",
")",
";",
"$",
"document",
"->",
"__isInitialized__",
"=",
"true",
";",
"}",
"}",
"}",
"}"
] |
Populate an owning-side ReferenceMany association.
@param PersistentCollectionInterface $collection
@return void
|
[
"Populate",
"an",
"owning",
"-",
"side",
"ReferenceMany",
"association",
"."
] |
119d355e2c5cbaef1f867970349b4432f5704fcd
|
https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Persister/DocumentPersister.php#L468-L556
|
train
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.