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
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
phpffcms/ffcms-core | src/I18n/Translate.php | Translate.getAvailableLangs | public function getAvailableLangs(): array
{
$langs = ['en'];
$scan = Directory::scan(root . '/I18n/' . env_name . '/', GLOB_ONLYDIR, true);
foreach ($scan as $row) {
$langs[] = trim($row, '/');
}
return $langs;
} | php | public function getAvailableLangs(): array
{
$langs = ['en'];
$scan = Directory::scan(root . '/I18n/' . env_name . '/', GLOB_ONLYDIR, true);
foreach ($scan as $row) {
$langs[] = trim($row, '/');
}
return $langs;
} | [
"public",
"function",
"getAvailableLangs",
"(",
")",
":",
"array",
"{",
"$",
"langs",
"=",
"[",
"'en'",
"]",
";",
"$",
"scan",
"=",
"Directory",
"::",
"scan",
"(",
"root",
".",
"'/I18n/'",
".",
"env_name",
".",
"'/'",
",",
"GLOB_ONLYDIR",
",",
"true",
")",
";",
"foreach",
"(",
"$",
"scan",
"as",
"$",
"row",
")",
"{",
"$",
"langs",
"[",
"]",
"=",
"trim",
"(",
"$",
"row",
",",
"'/'",
")",
";",
"}",
"return",
"$",
"langs",
";",
"}"
] | Get available languages in the filesystem
@return array | [
"Get",
"available",
"languages",
"in",
"the",
"filesystem"
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/I18n/Translate.php#L125-L133 | train |
phpffcms/ffcms-core | src/I18n/Translate.php | Translate.getLocaleText | public function getLocaleText($input, ?string $lang = null, ?string $default = null): ?string
{
// define language if empty
if ($lang === null) {
$lang = App::$Request->getLanguage();
}
// unserialize from string to array
if (Any::isStr($input)) {
$input = Serialize::decode($input);
}
if (Any::isArray($input) && array_key_exists($lang, $input)) {
return $input[$lang];
}
return $default;
} | php | public function getLocaleText($input, ?string $lang = null, ?string $default = null): ?string
{
// define language if empty
if ($lang === null) {
$lang = App::$Request->getLanguage();
}
// unserialize from string to array
if (Any::isStr($input)) {
$input = Serialize::decode($input);
}
if (Any::isArray($input) && array_key_exists($lang, $input)) {
return $input[$lang];
}
return $default;
} | [
"public",
"function",
"getLocaleText",
"(",
"$",
"input",
",",
"?",
"string",
"$",
"lang",
"=",
"null",
",",
"?",
"string",
"$",
"default",
"=",
"null",
")",
":",
"?",
"string",
"{",
"// define language if empty",
"if",
"(",
"$",
"lang",
"===",
"null",
")",
"{",
"$",
"lang",
"=",
"App",
"::",
"$",
"Request",
"->",
"getLanguage",
"(",
")",
";",
"}",
"// unserialize from string to array",
"if",
"(",
"Any",
"::",
"isStr",
"(",
"$",
"input",
")",
")",
"{",
"$",
"input",
"=",
"Serialize",
"::",
"decode",
"(",
"$",
"input",
")",
";",
"}",
"if",
"(",
"Any",
"::",
"isArray",
"(",
"$",
"input",
")",
"&&",
"array_key_exists",
"(",
"$",
"lang",
",",
"$",
"input",
")",
")",
"{",
"return",
"$",
"input",
"[",
"$",
"lang",
"]",
";",
"}",
"return",
"$",
"default",
";",
"}"
] | Get locale data from input array or serialized string
@param array|string $input
@param string|null $lang
@param string|null $default
@return string|null | [
"Get",
"locale",
"data",
"from",
"input",
"array",
"or",
"serialized",
"string"
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/I18n/Translate.php#L142-L158 | train |
RockPhp/Datet | src/Rock/Datet/DateObj.php | Rock_Datet_DateObj.getDate | public function getDate($format = null)
{
$format = empty($format) ? $this->format : $format;
return strftime($format, $this->ts);
} | php | public function getDate($format = null)
{
$format = empty($format) ? $this->format : $format;
return strftime($format, $this->ts);
} | [
"public",
"function",
"getDate",
"(",
"$",
"format",
"=",
"null",
")",
"{",
"$",
"format",
"=",
"empty",
"(",
"$",
"format",
")",
"?",
"$",
"this",
"->",
"format",
":",
"$",
"format",
";",
"return",
"strftime",
"(",
"$",
"format",
",",
"$",
"this",
"->",
"ts",
")",
";",
"}"
] | Retorna data no formato especificado
@param string $format
não obrigatório. Formato padrão da função strftime() http://php.net/strftime
@return string | [
"Retorna",
"data",
"no",
"formato",
"especificado"
] | 10eb9320efbe0a5c5acb2ffb262b514a36476bf0 | https://github.com/RockPhp/Datet/blob/10eb9320efbe0a5c5acb2ffb262b514a36476bf0/src/Rock/Datet/DateObj.php#L86-L91 | train |
SCLInternet/SclZfGenericMapper | src/SclZfGenericMapper/Doctrine/FlushLock.php | FlushLock.unlock | public function unlock()
{
$this->count--;
if ($this->count < 0) {
$this->count = 0;
return false;
}
if (0 === $this->count) {
$this->entityManager->flush();
return true;
}
return false;
} | php | public function unlock()
{
$this->count--;
if ($this->count < 0) {
$this->count = 0;
return false;
}
if (0 === $this->count) {
$this->entityManager->flush();
return true;
}
return false;
} | [
"public",
"function",
"unlock",
"(",
")",
"{",
"$",
"this",
"->",
"count",
"--",
";",
"if",
"(",
"$",
"this",
"->",
"count",
"<",
"0",
")",
"{",
"$",
"this",
"->",
"count",
"=",
"0",
";",
"return",
"false",
";",
"}",
"if",
"(",
"0",
"===",
"$",
"this",
"->",
"count",
")",
"{",
"$",
"this",
"->",
"entityManager",
"->",
"flush",
"(",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Call this at the end of a persistence function.
@return boolean True if flush was called. | [
"Call",
"this",
"at",
"the",
"end",
"of",
"a",
"persistence",
"function",
"."
] | c61c61546bfbc07e9c9a4b425e8e02fd7182d80b | https://github.com/SCLInternet/SclZfGenericMapper/blob/c61c61546bfbc07e9c9a4b425e8e02fd7182d80b/src/SclZfGenericMapper/Doctrine/FlushLock.php#L60-L76 | train |
AdamB7586/menu-builder | src/Helpers/Levels.php | Levels.getCurrent | public static function getCurrent($navigation, $current) {
self::iterateItems($navigation);
foreach(self::$navItem as $item) {
if($item === $current) {
self::getCurrentItem(intval(floor(self::$navItem->getDepth() / 2)));
}
}
ksort(self::$currentItems);
return self::$currentItems;
} | php | public static function getCurrent($navigation, $current) {
self::iterateItems($navigation);
foreach(self::$navItem as $item) {
if($item === $current) {
self::getCurrentItem(intval(floor(self::$navItem->getDepth() / 2)));
}
}
ksort(self::$currentItems);
return self::$currentItems;
} | [
"public",
"static",
"function",
"getCurrent",
"(",
"$",
"navigation",
",",
"$",
"current",
")",
"{",
"self",
"::",
"iterateItems",
"(",
"$",
"navigation",
")",
";",
"foreach",
"(",
"self",
"::",
"$",
"navItem",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"===",
"$",
"current",
")",
"{",
"self",
"::",
"getCurrentItem",
"(",
"intval",
"(",
"floor",
"(",
"self",
"::",
"$",
"navItem",
"->",
"getDepth",
"(",
")",
"/",
"2",
")",
")",
")",
";",
"}",
"}",
"ksort",
"(",
"self",
"::",
"$",
"currentItems",
")",
";",
"return",
"self",
"::",
"$",
"currentItems",
";",
"}"
] | Creates the current menu items which are selected from the navigation item hierarchy | [
"Creates",
"the",
"current",
"menu",
"items",
"which",
"are",
"selected",
"from",
"the",
"navigation",
"item",
"hierarchy"
] | dbc192bca7d59475068c19d1a07a039e5f997ee4 | https://github.com/AdamB7586/menu-builder/blob/dbc192bca7d59475068c19d1a07a039e5f997ee4/src/Helpers/Levels.php#L15-L24 | train |
AdamB7586/menu-builder | src/Helpers/Levels.php | Levels.getCurrentItem | protected static function getCurrentItem($depth){
self::$currentItems[$depth] = iterator_to_array(self::$navItem->getSubIterator((($depth * 2) + 1)));
unset(self::$currentItems[$depth]['children']);
if($depth >= 1){
self::getCurrentItem(($depth - 1));
}
} | php | protected static function getCurrentItem($depth){
self::$currentItems[$depth] = iterator_to_array(self::$navItem->getSubIterator((($depth * 2) + 1)));
unset(self::$currentItems[$depth]['children']);
if($depth >= 1){
self::getCurrentItem(($depth - 1));
}
} | [
"protected",
"static",
"function",
"getCurrentItem",
"(",
"$",
"depth",
")",
"{",
"self",
"::",
"$",
"currentItems",
"[",
"$",
"depth",
"]",
"=",
"iterator_to_array",
"(",
"self",
"::",
"$",
"navItem",
"->",
"getSubIterator",
"(",
"(",
"(",
"$",
"depth",
"*",
"2",
")",
"+",
"1",
")",
")",
")",
";",
"unset",
"(",
"self",
"::",
"$",
"currentItems",
"[",
"$",
"depth",
"]",
"[",
"'children'",
"]",
")",
";",
"if",
"(",
"$",
"depth",
">=",
"1",
")",
"{",
"self",
"::",
"getCurrentItem",
"(",
"(",
"$",
"depth",
"-",
"1",
")",
")",
";",
"}",
"}"
] | Gets the current level items from the menu array
@param int $depth This should be the depth of the menu item you are setting | [
"Gets",
"the",
"current",
"level",
"items",
"from",
"the",
"menu",
"array"
] | dbc192bca7d59475068c19d1a07a039e5f997ee4 | https://github.com/AdamB7586/menu-builder/blob/dbc192bca7d59475068c19d1a07a039e5f997ee4/src/Helpers/Levels.php#L30-L36 | train |
juliangut/mapping | src/Driver/Traits/XmlMappingTrait.php | XmlMappingTrait.parseSimpleXML | final protected function parseSimpleXML(\SimpleXMLElement $element)
{
$elements = [];
foreach ($element->attributes() as $attribute => $value) {
$elements[$attribute] = $value instanceof \SimpleXMLElement ? $this->parseSimpleXML($value) : $value;
}
foreach ($element->children() as $node => $child) {
$elements[$node] = $child instanceof \SimpleXMLElement ? $this->parseSimpleXML($child) : $child;
}
if ($element->count() === 0 && \trim((string) $element) !== '') {
$value = $this->getTypedValue((string) $element);
if (\count($elements) === 0) {
return $value;
}
$elements['_value_'] = $value;
}
return $elements;
} | php | final protected function parseSimpleXML(\SimpleXMLElement $element)
{
$elements = [];
foreach ($element->attributes() as $attribute => $value) {
$elements[$attribute] = $value instanceof \SimpleXMLElement ? $this->parseSimpleXML($value) : $value;
}
foreach ($element->children() as $node => $child) {
$elements[$node] = $child instanceof \SimpleXMLElement ? $this->parseSimpleXML($child) : $child;
}
if ($element->count() === 0 && \trim((string) $element) !== '') {
$value = $this->getTypedValue((string) $element);
if (\count($elements) === 0) {
return $value;
}
$elements['_value_'] = $value;
}
return $elements;
} | [
"final",
"protected",
"function",
"parseSimpleXML",
"(",
"\\",
"SimpleXMLElement",
"$",
"element",
")",
"{",
"$",
"elements",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"element",
"->",
"attributes",
"(",
")",
"as",
"$",
"attribute",
"=>",
"$",
"value",
")",
"{",
"$",
"elements",
"[",
"$",
"attribute",
"]",
"=",
"$",
"value",
"instanceof",
"\\",
"SimpleXMLElement",
"?",
"$",
"this",
"->",
"parseSimpleXML",
"(",
"$",
"value",
")",
":",
"$",
"value",
";",
"}",
"foreach",
"(",
"$",
"element",
"->",
"children",
"(",
")",
"as",
"$",
"node",
"=>",
"$",
"child",
")",
"{",
"$",
"elements",
"[",
"$",
"node",
"]",
"=",
"$",
"child",
"instanceof",
"\\",
"SimpleXMLElement",
"?",
"$",
"this",
"->",
"parseSimpleXML",
"(",
"$",
"child",
")",
":",
"$",
"child",
";",
"}",
"if",
"(",
"$",
"element",
"->",
"count",
"(",
")",
"===",
"0",
"&&",
"\\",
"trim",
"(",
"(",
"string",
")",
"$",
"element",
")",
"!==",
"''",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"getTypedValue",
"(",
"(",
"string",
")",
"$",
"element",
")",
";",
"if",
"(",
"\\",
"count",
"(",
"$",
"elements",
")",
"===",
"0",
")",
"{",
"return",
"$",
"value",
";",
"}",
"$",
"elements",
"[",
"'_value_'",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"elements",
";",
"}"
] | Parse xml to array.
@param \SimpleXMLElement $element
@return string|float|int|bool|array | [
"Parse",
"xml",
"to",
"array",
"."
] | 1830ff84c054d8e3759df170a5664a97f7070be9 | https://github.com/juliangut/mapping/blob/1830ff84c054d8e3759df170a5664a97f7070be9/src/Driver/Traits/XmlMappingTrait.php#L112-L135 | train |
juliangut/mapping | src/Driver/Traits/XmlMappingTrait.php | XmlMappingTrait.getTypedValue | private function getTypedValue(string $value)
{
if (\in_array($value, self::$boolValues, true)) {
return \in_array($value, self::$truthlyValues, true);
}
if (\is_numeric($value)) {
return $this->getNumericValue($value);
}
return $value;
} | php | private function getTypedValue(string $value)
{
if (\in_array($value, self::$boolValues, true)) {
return \in_array($value, self::$truthlyValues, true);
}
if (\is_numeric($value)) {
return $this->getNumericValue($value);
}
return $value;
} | [
"private",
"function",
"getTypedValue",
"(",
"string",
"$",
"value",
")",
"{",
"if",
"(",
"\\",
"in_array",
"(",
"$",
"value",
",",
"self",
"::",
"$",
"boolValues",
",",
"true",
")",
")",
"{",
"return",
"\\",
"in_array",
"(",
"$",
"value",
",",
"self",
"::",
"$",
"truthlyValues",
",",
"true",
")",
";",
"}",
"if",
"(",
"\\",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getNumericValue",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Transforms string to type.
@param string $value
@return bool|float|int|string | [
"Transforms",
"string",
"to",
"type",
"."
] | 1830ff84c054d8e3759df170a5664a97f7070be9 | https://github.com/juliangut/mapping/blob/1830ff84c054d8e3759df170a5664a97f7070be9/src/Driver/Traits/XmlMappingTrait.php#L144-L155 | train |
juliangut/mapping | src/Driver/Traits/XmlMappingTrait.php | XmlMappingTrait.getNumericValue | private function getNumericValue(string $value)
{
if (\strpos($value, '.') !== false) {
return (float) $value;
}
return (int) $value;
} | php | private function getNumericValue(string $value)
{
if (\strpos($value, '.') !== false) {
return (float) $value;
}
return (int) $value;
} | [
"private",
"function",
"getNumericValue",
"(",
"string",
"$",
"value",
")",
"{",
"if",
"(",
"\\",
"strpos",
"(",
"$",
"value",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"return",
"(",
"float",
")",
"$",
"value",
";",
"}",
"return",
"(",
"int",
")",
"$",
"value",
";",
"}"
] | Get numeric value from string.
@param string $value
@return float|int | [
"Get",
"numeric",
"value",
"from",
"string",
"."
] | 1830ff84c054d8e3759df170a5664a97f7070be9 | https://github.com/juliangut/mapping/blob/1830ff84c054d8e3759df170a5664a97f7070be9/src/Driver/Traits/XmlMappingTrait.php#L164-L171 | train |
QoboLtd/qobo-robo-cakephp | src/Command/Cakephp/Plugins.php | Plugins.cakephpPlugins | public function cakephpPlugins($opts = ['format' => 'table', 'fields' => ''])
{
$result = $this->taskCakephpPlugins()
->run();
if (!$result->wasSuccessful()) {
$this->exitError("Failed to run the command");
}
return new PropertyList($result->getData()['data']);
} | php | public function cakephpPlugins($opts = ['format' => 'table', 'fields' => ''])
{
$result = $this->taskCakephpPlugins()
->run();
if (!$result->wasSuccessful()) {
$this->exitError("Failed to run the command");
}
return new PropertyList($result->getData()['data']);
} | [
"public",
"function",
"cakephpPlugins",
"(",
"$",
"opts",
"=",
"[",
"'format'",
"=>",
"'table'",
",",
"'fields'",
"=>",
"''",
"]",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"taskCakephpPlugins",
"(",
")",
"->",
"run",
"(",
")",
";",
"if",
"(",
"!",
"$",
"result",
"->",
"wasSuccessful",
"(",
")",
")",
"{",
"$",
"this",
"->",
"exitError",
"(",
"\"Failed to run the command\"",
")",
";",
"}",
"return",
"new",
"PropertyList",
"(",
"$",
"result",
"->",
"getData",
"(",
")",
"[",
"'data'",
"]",
")",
";",
"}"
] | List CakePHP loaded plugins
@option string $format Output format (table, list, csv, json, xml)
@option string $fields Limit output to given fields, comma-separated
@return PropertyList result | [
"List",
"CakePHP",
"loaded",
"plugins"
] | 942d1839ad55a26e4aba893bd5bed35ec6edca94 | https://github.com/QoboLtd/qobo-robo-cakephp/blob/942d1839ad55a26e4aba893bd5bed35ec6edca94/src/Command/Cakephp/Plugins.php#L27-L36 | train |
ezra-obiwale/dSCore | src/Core/AUser.php | AUser.check | final public function check(array $options) {
foreach ($options as $property => $value) {
if ((is_array($value) && !in_array($this->$property, $value)) ||
(!is_array($value) && $this->$property !== $value))
return false;
}
return true;
} | php | final public function check(array $options) {
foreach ($options as $property => $value) {
if ((is_array($value) && !in_array($this->$property, $value)) ||
(!is_array($value) && $this->$property !== $value))
return false;
}
return true;
} | [
"final",
"public",
"function",
"check",
"(",
"array",
"$",
"options",
")",
"{",
"foreach",
"(",
"$",
"options",
"as",
"$",
"property",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"!",
"in_array",
"(",
"$",
"this",
"->",
"$",
"property",
",",
"$",
"value",
")",
")",
"||",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
"&&",
"$",
"this",
"->",
"$",
"property",
"!==",
"$",
"value",
")",
")",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Checks if properties exist and their values are as required
@param array $options
@return boolean | [
"Checks",
"if",
"properties",
"exist",
"and",
"their",
"values",
"are",
"as",
"required"
] | dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/AUser.php#L45-L53 | train |
ARCANESOFT/Blog | src/Seeds/PermissionsTableSeeder.php | PermissionsTableSeeder.getPostsPermissions | private function getPostsPermissions()
{
return [
[
'name' => 'Posts - List all posts',
'description' => 'Allow to list all posts.',
'slug' => PostsPolicy::PERMISSION_LIST,
],
[
'name' => 'Posts - View a post',
'description' => 'Allow to display a post.',
'slug' => PostsPolicy::PERMISSION_SHOW,
],
[
'name' => 'Posts - Create a post',
'description' => 'Allow to create a post.',
'slug' => PostsPolicy::PERMISSION_CREATE,
],
[
'name' => 'Posts - Update a post',
'description' => 'Allow to update a post.',
'slug' => PostsPolicy::PERMISSION_UPDATE,
],
[
'name' => 'Posts - Delete a post',
'description' => 'Allow to delete a post.',
'slug' => PostsPolicy::PERMISSION_DELETE,
],
];
} | php | private function getPostsPermissions()
{
return [
[
'name' => 'Posts - List all posts',
'description' => 'Allow to list all posts.',
'slug' => PostsPolicy::PERMISSION_LIST,
],
[
'name' => 'Posts - View a post',
'description' => 'Allow to display a post.',
'slug' => PostsPolicy::PERMISSION_SHOW,
],
[
'name' => 'Posts - Create a post',
'description' => 'Allow to create a post.',
'slug' => PostsPolicy::PERMISSION_CREATE,
],
[
'name' => 'Posts - Update a post',
'description' => 'Allow to update a post.',
'slug' => PostsPolicy::PERMISSION_UPDATE,
],
[
'name' => 'Posts - Delete a post',
'description' => 'Allow to delete a post.',
'slug' => PostsPolicy::PERMISSION_DELETE,
],
];
} | [
"private",
"function",
"getPostsPermissions",
"(",
")",
"{",
"return",
"[",
"[",
"'name'",
"=>",
"'Posts - List all posts'",
",",
"'description'",
"=>",
"'Allow to list all posts.'",
",",
"'slug'",
"=>",
"PostsPolicy",
"::",
"PERMISSION_LIST",
",",
"]",
",",
"[",
"'name'",
"=>",
"'Posts - View a post'",
",",
"'description'",
"=>",
"'Allow to display a post.'",
",",
"'slug'",
"=>",
"PostsPolicy",
"::",
"PERMISSION_SHOW",
",",
"]",
",",
"[",
"'name'",
"=>",
"'Posts - Create a post'",
",",
"'description'",
"=>",
"'Allow to create a post.'",
",",
"'slug'",
"=>",
"PostsPolicy",
"::",
"PERMISSION_CREATE",
",",
"]",
",",
"[",
"'name'",
"=>",
"'Posts - Update a post'",
",",
"'description'",
"=>",
"'Allow to update a post.'",
",",
"'slug'",
"=>",
"PostsPolicy",
"::",
"PERMISSION_UPDATE",
",",
"]",
",",
"[",
"'name'",
"=>",
"'Posts - Delete a post'",
",",
"'description'",
"=>",
"'Allow to delete a post.'",
",",
"'slug'",
"=>",
"PostsPolicy",
"::",
"PERMISSION_DELETE",
",",
"]",
",",
"]",
";",
"}"
] | Get the Posts permissions.
@return array | [
"Get",
"the",
"Posts",
"permissions",
"."
] | 2078fdfdcbccda161c02899b9e1f344f011b2859 | https://github.com/ARCANESOFT/Blog/blob/2078fdfdcbccda161c02899b9e1f344f011b2859/src/Seeds/PermissionsTableSeeder.php#L70-L99 | train |
ARCANESOFT/Blog | src/Seeds/PermissionsTableSeeder.php | PermissionsTableSeeder.getCategoriesPermissions | private function getCategoriesPermissions()
{
return [
[
'name' => 'Categories - List all categories',
'description' => 'Allow to list all categories.',
'slug' => CategoriesPolicy::PERMISSION_LIST,
],
[
'name' => 'Categories - View a category',
'description' => 'Allow to display a category.',
'slug' => CategoriesPolicy::PERMISSION_SHOW,
],
[
'name' => 'Categories - Create a category',
'description' => 'Allow to create a category.',
'slug' => CategoriesPolicy::PERMISSION_CREATE,
],
[
'name' => 'Categories - Update a category',
'description' => 'Allow to update a category.',
'slug' => CategoriesPolicy::PERMISSION_UPDATE,
],
[
'name' => 'Categories - Delete a category',
'description' => 'Allow to delete a category.',
'slug' => CategoriesPolicy::PERMISSION_DELETE,
],
];
} | php | private function getCategoriesPermissions()
{
return [
[
'name' => 'Categories - List all categories',
'description' => 'Allow to list all categories.',
'slug' => CategoriesPolicy::PERMISSION_LIST,
],
[
'name' => 'Categories - View a category',
'description' => 'Allow to display a category.',
'slug' => CategoriesPolicy::PERMISSION_SHOW,
],
[
'name' => 'Categories - Create a category',
'description' => 'Allow to create a category.',
'slug' => CategoriesPolicy::PERMISSION_CREATE,
],
[
'name' => 'Categories - Update a category',
'description' => 'Allow to update a category.',
'slug' => CategoriesPolicy::PERMISSION_UPDATE,
],
[
'name' => 'Categories - Delete a category',
'description' => 'Allow to delete a category.',
'slug' => CategoriesPolicy::PERMISSION_DELETE,
],
];
} | [
"private",
"function",
"getCategoriesPermissions",
"(",
")",
"{",
"return",
"[",
"[",
"'name'",
"=>",
"'Categories - List all categories'",
",",
"'description'",
"=>",
"'Allow to list all categories.'",
",",
"'slug'",
"=>",
"CategoriesPolicy",
"::",
"PERMISSION_LIST",
",",
"]",
",",
"[",
"'name'",
"=>",
"'Categories - View a category'",
",",
"'description'",
"=>",
"'Allow to display a category.'",
",",
"'slug'",
"=>",
"CategoriesPolicy",
"::",
"PERMISSION_SHOW",
",",
"]",
",",
"[",
"'name'",
"=>",
"'Categories - Create a category'",
",",
"'description'",
"=>",
"'Allow to create a category.'",
",",
"'slug'",
"=>",
"CategoriesPolicy",
"::",
"PERMISSION_CREATE",
",",
"]",
",",
"[",
"'name'",
"=>",
"'Categories - Update a category'",
",",
"'description'",
"=>",
"'Allow to update a category.'",
",",
"'slug'",
"=>",
"CategoriesPolicy",
"::",
"PERMISSION_UPDATE",
",",
"]",
",",
"[",
"'name'",
"=>",
"'Categories - Delete a category'",
",",
"'description'",
"=>",
"'Allow to delete a category.'",
",",
"'slug'",
"=>",
"CategoriesPolicy",
"::",
"PERMISSION_DELETE",
",",
"]",
",",
"]",
";",
"}"
] | Get the Categories permissions.
@return array | [
"Get",
"the",
"Categories",
"permissions",
"."
] | 2078fdfdcbccda161c02899b9e1f344f011b2859 | https://github.com/ARCANESOFT/Blog/blob/2078fdfdcbccda161c02899b9e1f344f011b2859/src/Seeds/PermissionsTableSeeder.php#L106-L135 | train |
ARCANESOFT/Blog | src/Seeds/PermissionsTableSeeder.php | PermissionsTableSeeder.getTagsPermissions | private function getTagsPermissions()
{
return [
[
'name' => 'Tags - List all tags',
'description' => 'Allow to list all tags.',
'slug' => TagsPolicy::PERMISSION_LIST,
],
[
'name' => 'Tags - View a tag',
'description' => 'Allow to display a tag.',
'slug' => TagsPolicy::PERMISSION_SHOW,
],
[
'name' => 'Tags - Create a tag',
'description' => 'Allow to create a tag.',
'slug' => TagsPolicy::PERMISSION_CREATE,
],
[
'name' => 'Tags - Update a tag',
'description' => 'Allow to update a tag.',
'slug' => TagsPolicy::PERMISSION_UPDATE,
],
[
'name' => 'Tags - Delete a tag',
'description' => 'Allow to delete a tag.',
'slug' => TagsPolicy::PERMISSION_DELETE,
],
];
} | php | private function getTagsPermissions()
{
return [
[
'name' => 'Tags - List all tags',
'description' => 'Allow to list all tags.',
'slug' => TagsPolicy::PERMISSION_LIST,
],
[
'name' => 'Tags - View a tag',
'description' => 'Allow to display a tag.',
'slug' => TagsPolicy::PERMISSION_SHOW,
],
[
'name' => 'Tags - Create a tag',
'description' => 'Allow to create a tag.',
'slug' => TagsPolicy::PERMISSION_CREATE,
],
[
'name' => 'Tags - Update a tag',
'description' => 'Allow to update a tag.',
'slug' => TagsPolicy::PERMISSION_UPDATE,
],
[
'name' => 'Tags - Delete a tag',
'description' => 'Allow to delete a tag.',
'slug' => TagsPolicy::PERMISSION_DELETE,
],
];
} | [
"private",
"function",
"getTagsPermissions",
"(",
")",
"{",
"return",
"[",
"[",
"'name'",
"=>",
"'Tags - List all tags'",
",",
"'description'",
"=>",
"'Allow to list all tags.'",
",",
"'slug'",
"=>",
"TagsPolicy",
"::",
"PERMISSION_LIST",
",",
"]",
",",
"[",
"'name'",
"=>",
"'Tags - View a tag'",
",",
"'description'",
"=>",
"'Allow to display a tag.'",
",",
"'slug'",
"=>",
"TagsPolicy",
"::",
"PERMISSION_SHOW",
",",
"]",
",",
"[",
"'name'",
"=>",
"'Tags - Create a tag'",
",",
"'description'",
"=>",
"'Allow to create a tag.'",
",",
"'slug'",
"=>",
"TagsPolicy",
"::",
"PERMISSION_CREATE",
",",
"]",
",",
"[",
"'name'",
"=>",
"'Tags - Update a tag'",
",",
"'description'",
"=>",
"'Allow to update a tag.'",
",",
"'slug'",
"=>",
"TagsPolicy",
"::",
"PERMISSION_UPDATE",
",",
"]",
",",
"[",
"'name'",
"=>",
"'Tags - Delete a tag'",
",",
"'description'",
"=>",
"'Allow to delete a tag.'",
",",
"'slug'",
"=>",
"TagsPolicy",
"::",
"PERMISSION_DELETE",
",",
"]",
",",
"]",
";",
"}"
] | Get the Tags permissions.
@return array | [
"Get",
"the",
"Tags",
"permissions",
"."
] | 2078fdfdcbccda161c02899b9e1f344f011b2859 | https://github.com/ARCANESOFT/Blog/blob/2078fdfdcbccda161c02899b9e1f344f011b2859/src/Seeds/PermissionsTableSeeder.php#L142-L171 | train |
ARCANESOFT/Auth | src/ViewComposers/PermissionGroupsFilterComposer.php | PermissionGroupsFilterComposer.getFilters | private function getFilters()
{
$filters = new Collection;
foreach ($this->getCachedPermissionGroups() as $group) {
/** @var \Arcanesoft\Auth\Models\PermissionsGroup $group */
$filters->push([
'name' => $group->name,
'params' => [$group->hashed_id],
]);
}
// Custom Permission group
//----------------------------------
if (Permission::where('group_id', 0)->count()) {
$filters->push([
'name' => trans('auth::permission-groups.custom'),
'params' => [hasher()->encode(0)],
]);
}
return $filters;
} | php | private function getFilters()
{
$filters = new Collection;
foreach ($this->getCachedPermissionGroups() as $group) {
/** @var \Arcanesoft\Auth\Models\PermissionsGroup $group */
$filters->push([
'name' => $group->name,
'params' => [$group->hashed_id],
]);
}
// Custom Permission group
//----------------------------------
if (Permission::where('group_id', 0)->count()) {
$filters->push([
'name' => trans('auth::permission-groups.custom'),
'params' => [hasher()->encode(0)],
]);
}
return $filters;
} | [
"private",
"function",
"getFilters",
"(",
")",
"{",
"$",
"filters",
"=",
"new",
"Collection",
";",
"foreach",
"(",
"$",
"this",
"->",
"getCachedPermissionGroups",
"(",
")",
"as",
"$",
"group",
")",
"{",
"/** @var \\Arcanesoft\\Auth\\Models\\PermissionsGroup $group */",
"$",
"filters",
"->",
"push",
"(",
"[",
"'name'",
"=>",
"$",
"group",
"->",
"name",
",",
"'params'",
"=>",
"[",
"$",
"group",
"->",
"hashed_id",
"]",
",",
"]",
")",
";",
"}",
"// Custom Permission group",
"//----------------------------------",
"if",
"(",
"Permission",
"::",
"where",
"(",
"'group_id'",
",",
"0",
")",
"->",
"count",
"(",
")",
")",
"{",
"$",
"filters",
"->",
"push",
"(",
"[",
"'name'",
"=>",
"trans",
"(",
"'auth::permission-groups.custom'",
")",
",",
"'params'",
"=>",
"[",
"hasher",
"(",
")",
"->",
"encode",
"(",
"0",
")",
"]",
",",
"]",
")",
";",
"}",
"return",
"$",
"filters",
";",
"}"
] | Get the groups filters data.
@return \Illuminate\Support\Collection | [
"Get",
"the",
"groups",
"filters",
"data",
"."
] | b33ca82597a76b1e395071f71ae3e51f1ec67e62 | https://github.com/ARCANESOFT/Auth/blob/b33ca82597a76b1e395071f71ae3e51f1ec67e62/src/ViewComposers/PermissionGroupsFilterComposer.php#L45-L67 | train |
Aerendir/PHPTextMatrix | src/PHPTextMatrix.php | PHPTextMatrix.render | public function render(array $options = []): string
{
// Set the options to use
$this->resolveOptions($options);
if (false === $this->validate()) {
return false;
}
// Splits the content of the cells to fit into the defined line length
$this->splitCellsContent();
/*
* Calculate the height of each row and the width of each column.
* The height is equal to highest cell content found in the row.
* The width is equal to the longest line found in the content of each cell of the column.
*/
$this->calculateSizes();
$this->tableWidth = $this->calculateTableWidth();
$table = $this->options['has_header'] ? $this->drawHeaderDivider() : $this->drawDivider();
// If the top divider of the header hasn't to be shown...
if ($this->options['has_header'] && false === $this->options['show_head_top_sep']) {
// ... Remove it
$table = '';
}
foreach ($this->data as $rowPosition => $rowContent) {
$table .= $this->drawRow($rowPosition, $rowContent);
$table .= $this->options['has_header'] && 0 === $rowPosition ? $this->drawHeaderDivider() : $this->drawDivider();
}
$this->table = $table;
// Reset options
$this->options = [];
return $this->table;
} | php | public function render(array $options = []): string
{
// Set the options to use
$this->resolveOptions($options);
if (false === $this->validate()) {
return false;
}
// Splits the content of the cells to fit into the defined line length
$this->splitCellsContent();
/*
* Calculate the height of each row and the width of each column.
* The height is equal to highest cell content found in the row.
* The width is equal to the longest line found in the content of each cell of the column.
*/
$this->calculateSizes();
$this->tableWidth = $this->calculateTableWidth();
$table = $this->options['has_header'] ? $this->drawHeaderDivider() : $this->drawDivider();
// If the top divider of the header hasn't to be shown...
if ($this->options['has_header'] && false === $this->options['show_head_top_sep']) {
// ... Remove it
$table = '';
}
foreach ($this->data as $rowPosition => $rowContent) {
$table .= $this->drawRow($rowPosition, $rowContent);
$table .= $this->options['has_header'] && 0 === $rowPosition ? $this->drawHeaderDivider() : $this->drawDivider();
}
$this->table = $table;
// Reset options
$this->options = [];
return $this->table;
} | [
"public",
"function",
"render",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"string",
"{",
"// Set the options to use",
"$",
"this",
"->",
"resolveOptions",
"(",
"$",
"options",
")",
";",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"validate",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Splits the content of the cells to fit into the defined line length",
"$",
"this",
"->",
"splitCellsContent",
"(",
")",
";",
"/*\n * Calculate the height of each row and the width of each column.\n * The height is equal to highest cell content found in the row.\n * The width is equal to the longest line found in the content of each cell of the column.\n */",
"$",
"this",
"->",
"calculateSizes",
"(",
")",
";",
"$",
"this",
"->",
"tableWidth",
"=",
"$",
"this",
"->",
"calculateTableWidth",
"(",
")",
";",
"$",
"table",
"=",
"$",
"this",
"->",
"options",
"[",
"'has_header'",
"]",
"?",
"$",
"this",
"->",
"drawHeaderDivider",
"(",
")",
":",
"$",
"this",
"->",
"drawDivider",
"(",
")",
";",
"// If the top divider of the header hasn't to be shown...",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"'has_header'",
"]",
"&&",
"false",
"===",
"$",
"this",
"->",
"options",
"[",
"'show_head_top_sep'",
"]",
")",
"{",
"// ... Remove it",
"$",
"table",
"=",
"''",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"rowPosition",
"=>",
"$",
"rowContent",
")",
"{",
"$",
"table",
".=",
"$",
"this",
"->",
"drawRow",
"(",
"$",
"rowPosition",
",",
"$",
"rowContent",
")",
";",
"$",
"table",
".=",
"$",
"this",
"->",
"options",
"[",
"'has_header'",
"]",
"&&",
"0",
"===",
"$",
"rowPosition",
"?",
"$",
"this",
"->",
"drawHeaderDivider",
"(",
")",
":",
"$",
"this",
"->",
"drawDivider",
"(",
")",
";",
"}",
"$",
"this",
"->",
"table",
"=",
"$",
"table",
";",
"// Reset options",
"$",
"this",
"->",
"options",
"=",
"[",
"]",
";",
"return",
"$",
"this",
"->",
"table",
";",
"}"
] | Renders the table as plain text.
@param array $options
@return string | [
"Renders",
"the",
"table",
"as",
"plain",
"text",
"."
] | d8b3ce58b7174c6ddd9959e33427aa61862302d6 | https://github.com/Aerendir/PHPTextMatrix/blob/d8b3ce58b7174c6ddd9959e33427aa61862302d6/src/PHPTextMatrix.php#L73-L113 | train |
Aerendir/PHPTextMatrix | src/PHPTextMatrix.php | PHPTextMatrix.validate | public function validate(): bool
{
// The number of columns
$numberOfColumns = null;
// Reset the errors
$this->errors = [];
// Check that there are rows in the data
if (0 >= count($this->data)) {
$message = 'There are no rows in the table';
$this->errors[] = $message;
return false;
}
// Check that all rows have the same number of columns
foreach ($this->data as $row) {
$found = count($row);
if (null === $numberOfColumns) {
$numberOfColumns = $found;
}
if ($numberOfColumns !== $found) {
$message = sprintf(
'The number of columns mismatches. First row has %s columns while column %s has %s.',
$numberOfColumns,
key($row),
$found
);
$this->errors[] = $message;
}
}
return 0 < count($this->errors) ? false : true;
} | php | public function validate(): bool
{
// The number of columns
$numberOfColumns = null;
// Reset the errors
$this->errors = [];
// Check that there are rows in the data
if (0 >= count($this->data)) {
$message = 'There are no rows in the table';
$this->errors[] = $message;
return false;
}
// Check that all rows have the same number of columns
foreach ($this->data as $row) {
$found = count($row);
if (null === $numberOfColumns) {
$numberOfColumns = $found;
}
if ($numberOfColumns !== $found) {
$message = sprintf(
'The number of columns mismatches. First row has %s columns while column %s has %s.',
$numberOfColumns,
key($row),
$found
);
$this->errors[] = $message;
}
}
return 0 < count($this->errors) ? false : true;
} | [
"public",
"function",
"validate",
"(",
")",
":",
"bool",
"{",
"// The number of columns",
"$",
"numberOfColumns",
"=",
"null",
";",
"// Reset the errors",
"$",
"this",
"->",
"errors",
"=",
"[",
"]",
";",
"// Check that there are rows in the data",
"if",
"(",
"0",
">=",
"count",
"(",
"$",
"this",
"->",
"data",
")",
")",
"{",
"$",
"message",
"=",
"'There are no rows in the table'",
";",
"$",
"this",
"->",
"errors",
"[",
"]",
"=",
"$",
"message",
";",
"return",
"false",
";",
"}",
"// Check that all rows have the same number of columns",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"row",
")",
"{",
"$",
"found",
"=",
"count",
"(",
"$",
"row",
")",
";",
"if",
"(",
"null",
"===",
"$",
"numberOfColumns",
")",
"{",
"$",
"numberOfColumns",
"=",
"$",
"found",
";",
"}",
"if",
"(",
"$",
"numberOfColumns",
"!==",
"$",
"found",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'The number of columns mismatches. First row has %s columns while column %s has %s.'",
",",
"$",
"numberOfColumns",
",",
"key",
"(",
"$",
"row",
")",
",",
"$",
"found",
")",
";",
"$",
"this",
"->",
"errors",
"[",
"]",
"=",
"$",
"message",
";",
"}",
"}",
"return",
"0",
"<",
"count",
"(",
"$",
"this",
"->",
"errors",
")",
"?",
"false",
":",
"true",
";",
"}"
] | Validates the given array to check all the rows have the same number of columns.
Returns false if the validation fails and calling the getErrors() method it is possible to know
which are these errors.
@return bool False if the validation fails, true if all succeeds | [
"Validates",
"the",
"given",
"array",
"to",
"check",
"all",
"the",
"rows",
"have",
"the",
"same",
"number",
"of",
"columns",
"."
] | d8b3ce58b7174c6ddd9959e33427aa61862302d6 | https://github.com/Aerendir/PHPTextMatrix/blob/d8b3ce58b7174c6ddd9959e33427aa61862302d6/src/PHPTextMatrix.php#L123-L159 | train |
Aerendir/PHPTextMatrix | src/PHPTextMatrix.php | PHPTextMatrix.splitCellsContent | private function splitCellsContent()
{
// For each row...
foreach ($this->data as $rowPosition => $rowContent) {
// ... cycle each column to get its content
foreach ($rowContent as $columnName => $cellContent) {
// Remove extra spaces from the string
$cellContent = $this->reduceSpaces($cellContent);
// If we don't have a max width set for the column...
if (false === isset($this->options['columns'][$columnName]['max_width'])) {
// ... simply wrap the content in an array and continue
$this->data[$rowPosition][$columnName] = [$cellContent];
goto addVerticalPadding;
}
// ... We have a max_width set: split the column
$length = $this->options['columns'][$columnName]['max_width'];
$cut = $this->options['columns'][$columnName]['cut'];
$wrapped = wordwrap($cellContent, $length, PHP_EOL, $cut);
$this->data[$rowPosition][$columnName] = explode(PHP_EOL, $wrapped);
// At the end, add the vertical padding to the cell's content
addVerticalPadding:
if (0 < $this->options['cells_padding'][0]) {
// Now add the top padding
for ($paddingLine = 0; $paddingLine < $this->options['cells_padding'][0]; ++$paddingLine) {
array_unshift($this->data[$rowPosition][$columnName], '');
}
}
if (0 < $this->options['cells_padding'][2]) {
// And the bottom padding
for ($paddingLine = 0; $paddingLine < $this->options['cells_padding'][2]; ++$paddingLine) {
array_push($this->data[$rowPosition][$columnName], '');
}
}
}
}
} | php | private function splitCellsContent()
{
// For each row...
foreach ($this->data as $rowPosition => $rowContent) {
// ... cycle each column to get its content
foreach ($rowContent as $columnName => $cellContent) {
// Remove extra spaces from the string
$cellContent = $this->reduceSpaces($cellContent);
// If we don't have a max width set for the column...
if (false === isset($this->options['columns'][$columnName]['max_width'])) {
// ... simply wrap the content in an array and continue
$this->data[$rowPosition][$columnName] = [$cellContent];
goto addVerticalPadding;
}
// ... We have a max_width set: split the column
$length = $this->options['columns'][$columnName]['max_width'];
$cut = $this->options['columns'][$columnName]['cut'];
$wrapped = wordwrap($cellContent, $length, PHP_EOL, $cut);
$this->data[$rowPosition][$columnName] = explode(PHP_EOL, $wrapped);
// At the end, add the vertical padding to the cell's content
addVerticalPadding:
if (0 < $this->options['cells_padding'][0]) {
// Now add the top padding
for ($paddingLine = 0; $paddingLine < $this->options['cells_padding'][0]; ++$paddingLine) {
array_unshift($this->data[$rowPosition][$columnName], '');
}
}
if (0 < $this->options['cells_padding'][2]) {
// And the bottom padding
for ($paddingLine = 0; $paddingLine < $this->options['cells_padding'][2]; ++$paddingLine) {
array_push($this->data[$rowPosition][$columnName], '');
}
}
}
}
} | [
"private",
"function",
"splitCellsContent",
"(",
")",
"{",
"// For each row...",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"rowPosition",
"=>",
"$",
"rowContent",
")",
"{",
"// ... cycle each column to get its content",
"foreach",
"(",
"$",
"rowContent",
"as",
"$",
"columnName",
"=>",
"$",
"cellContent",
")",
"{",
"// Remove extra spaces from the string",
"$",
"cellContent",
"=",
"$",
"this",
"->",
"reduceSpaces",
"(",
"$",
"cellContent",
")",
";",
"// If we don't have a max width set for the column...",
"if",
"(",
"false",
"===",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'columns'",
"]",
"[",
"$",
"columnName",
"]",
"[",
"'max_width'",
"]",
")",
")",
"{",
"// ... simply wrap the content in an array and continue",
"$",
"this",
"->",
"data",
"[",
"$",
"rowPosition",
"]",
"[",
"$",
"columnName",
"]",
"=",
"[",
"$",
"cellContent",
"]",
";",
"goto",
"addVerticalPadding",
";",
"}",
"// ... We have a max_width set: split the column",
"$",
"length",
"=",
"$",
"this",
"->",
"options",
"[",
"'columns'",
"]",
"[",
"$",
"columnName",
"]",
"[",
"'max_width'",
"]",
";",
"$",
"cut",
"=",
"$",
"this",
"->",
"options",
"[",
"'columns'",
"]",
"[",
"$",
"columnName",
"]",
"[",
"'cut'",
"]",
";",
"$",
"wrapped",
"=",
"wordwrap",
"(",
"$",
"cellContent",
",",
"$",
"length",
",",
"PHP_EOL",
",",
"$",
"cut",
")",
";",
"$",
"this",
"->",
"data",
"[",
"$",
"rowPosition",
"]",
"[",
"$",
"columnName",
"]",
"=",
"explode",
"(",
"PHP_EOL",
",",
"$",
"wrapped",
")",
";",
"// At the end, add the vertical padding to the cell's content",
"addVerticalPadding",
":",
"if",
"(",
"0",
"<",
"$",
"this",
"->",
"options",
"[",
"'cells_padding'",
"]",
"[",
"0",
"]",
")",
"{",
"// Now add the top padding",
"for",
"(",
"$",
"paddingLine",
"=",
"0",
";",
"$",
"paddingLine",
"<",
"$",
"this",
"->",
"options",
"[",
"'cells_padding'",
"]",
"[",
"0",
"]",
";",
"++",
"$",
"paddingLine",
")",
"{",
"array_unshift",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"rowPosition",
"]",
"[",
"$",
"columnName",
"]",
",",
"''",
")",
";",
"}",
"}",
"if",
"(",
"0",
"<",
"$",
"this",
"->",
"options",
"[",
"'cells_padding'",
"]",
"[",
"2",
"]",
")",
"{",
"// And the bottom padding",
"for",
"(",
"$",
"paddingLine",
"=",
"0",
";",
"$",
"paddingLine",
"<",
"$",
"this",
"->",
"options",
"[",
"'cells_padding'",
"]",
"[",
"2",
"]",
";",
"++",
"$",
"paddingLine",
")",
"{",
"array_push",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"rowPosition",
"]",
"[",
"$",
"columnName",
"]",
",",
"''",
")",
";",
"}",
"}",
"}",
"}",
"}"
] | Splits the content of each cell into multiple lines according to the set max column width. | [
"Splits",
"the",
"content",
"of",
"each",
"cell",
"into",
"multiple",
"lines",
"according",
"to",
"the",
"set",
"max",
"column",
"width",
"."
] | d8b3ce58b7174c6ddd9959e33427aa61862302d6 | https://github.com/Aerendir/PHPTextMatrix/blob/d8b3ce58b7174c6ddd9959e33427aa61862302d6/src/PHPTextMatrix.php#L184-L225 | train |
Aerendir/PHPTextMatrix | src/PHPTextMatrix.php | PHPTextMatrix.calculateSizes | private function calculateSizes()
{
// For each row...
foreach ($this->data as $rowPosition => $rowContent) {
// ... cycle each column to get its content ...
foreach ($rowContent as $columnName => $cellContent) {
// If we don't already know the height of this row...
if (false === isset($this->rowsHeights[$rowPosition])) {
// ... we save the current calculated height
$this->rowsHeights[$rowPosition] = count($cellContent);
}
// Set the min_width if it is set
if (isset($this->options['columns'][$columnName]['min_width'])) {
$this->columnsWidths[$columnName] = $this->options['columns'][$columnName]['min_width'];
}
// At this point we have the heigth for sure: on each cycle, we need the highest height
if (count($cellContent) > $this->rowsHeights[$rowPosition]) {
/*
* The height of this row is the highest found: use this to set the height of the entire row.
*/
$this->rowsHeights[$rowPosition] = count($cellContent);
}
// ... and calculate the length of each line to get the max length of the column
foreach ($cellContent as $lineNumber => $lineContent) {
// Get the length of the cell
$contentLength = iconv_strlen($lineContent);
// If we don't already have a length for this column...
if (false === isset($this->columnsWidths[$columnName])) {
// ... we save the current calculated length
$this->columnsWidths[$columnName] = $contentLength;
}
// At this point we have a length for sure: on each cycle we need the longest length
if ($contentLength > $this->columnsWidths[$columnName]) {
/*
* The length of the content of this cell is longer than the value we already have.
* So we need to use this new value as length for the current column.
*/
$this->columnsWidths[$columnName] = $contentLength;
}
}
}
}
} | php | private function calculateSizes()
{
// For each row...
foreach ($this->data as $rowPosition => $rowContent) {
// ... cycle each column to get its content ...
foreach ($rowContent as $columnName => $cellContent) {
// If we don't already know the height of this row...
if (false === isset($this->rowsHeights[$rowPosition])) {
// ... we save the current calculated height
$this->rowsHeights[$rowPosition] = count($cellContent);
}
// Set the min_width if it is set
if (isset($this->options['columns'][$columnName]['min_width'])) {
$this->columnsWidths[$columnName] = $this->options['columns'][$columnName]['min_width'];
}
// At this point we have the heigth for sure: on each cycle, we need the highest height
if (count($cellContent) > $this->rowsHeights[$rowPosition]) {
/*
* The height of this row is the highest found: use this to set the height of the entire row.
*/
$this->rowsHeights[$rowPosition] = count($cellContent);
}
// ... and calculate the length of each line to get the max length of the column
foreach ($cellContent as $lineNumber => $lineContent) {
// Get the length of the cell
$contentLength = iconv_strlen($lineContent);
// If we don't already have a length for this column...
if (false === isset($this->columnsWidths[$columnName])) {
// ... we save the current calculated length
$this->columnsWidths[$columnName] = $contentLength;
}
// At this point we have a length for sure: on each cycle we need the longest length
if ($contentLength > $this->columnsWidths[$columnName]) {
/*
* The length of the content of this cell is longer than the value we already have.
* So we need to use this new value as length for the current column.
*/
$this->columnsWidths[$columnName] = $contentLength;
}
}
}
}
} | [
"private",
"function",
"calculateSizes",
"(",
")",
"{",
"// For each row...",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"rowPosition",
"=>",
"$",
"rowContent",
")",
"{",
"// ... cycle each column to get its content ...",
"foreach",
"(",
"$",
"rowContent",
"as",
"$",
"columnName",
"=>",
"$",
"cellContent",
")",
"{",
"// If we don't already know the height of this row...",
"if",
"(",
"false",
"===",
"isset",
"(",
"$",
"this",
"->",
"rowsHeights",
"[",
"$",
"rowPosition",
"]",
")",
")",
"{",
"// ... we save the current calculated height",
"$",
"this",
"->",
"rowsHeights",
"[",
"$",
"rowPosition",
"]",
"=",
"count",
"(",
"$",
"cellContent",
")",
";",
"}",
"// Set the min_width if it is set",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'columns'",
"]",
"[",
"$",
"columnName",
"]",
"[",
"'min_width'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"columnsWidths",
"[",
"$",
"columnName",
"]",
"=",
"$",
"this",
"->",
"options",
"[",
"'columns'",
"]",
"[",
"$",
"columnName",
"]",
"[",
"'min_width'",
"]",
";",
"}",
"// At this point we have the heigth for sure: on each cycle, we need the highest height",
"if",
"(",
"count",
"(",
"$",
"cellContent",
")",
">",
"$",
"this",
"->",
"rowsHeights",
"[",
"$",
"rowPosition",
"]",
")",
"{",
"/*\n * The height of this row is the highest found: use this to set the height of the entire row.\n */",
"$",
"this",
"->",
"rowsHeights",
"[",
"$",
"rowPosition",
"]",
"=",
"count",
"(",
"$",
"cellContent",
")",
";",
"}",
"// ... and calculate the length of each line to get the max length of the column",
"foreach",
"(",
"$",
"cellContent",
"as",
"$",
"lineNumber",
"=>",
"$",
"lineContent",
")",
"{",
"// Get the length of the cell",
"$",
"contentLength",
"=",
"iconv_strlen",
"(",
"$",
"lineContent",
")",
";",
"// If we don't already have a length for this column...",
"if",
"(",
"false",
"===",
"isset",
"(",
"$",
"this",
"->",
"columnsWidths",
"[",
"$",
"columnName",
"]",
")",
")",
"{",
"// ... we save the current calculated length",
"$",
"this",
"->",
"columnsWidths",
"[",
"$",
"columnName",
"]",
"=",
"$",
"contentLength",
";",
"}",
"// At this point we have a length for sure: on each cycle we need the longest length",
"if",
"(",
"$",
"contentLength",
">",
"$",
"this",
"->",
"columnsWidths",
"[",
"$",
"columnName",
"]",
")",
"{",
"/*\n * The length of the content of this cell is longer than the value we already have.\n * So we need to use this new value as length for the current column.\n */",
"$",
"this",
"->",
"columnsWidths",
"[",
"$",
"columnName",
"]",
"=",
"$",
"contentLength",
";",
"}",
"}",
"}",
"}",
"}"
] | Calculates the width of each column of the table. | [
"Calculates",
"the",
"width",
"of",
"each",
"column",
"of",
"the",
"table",
"."
] | d8b3ce58b7174c6ddd9959e33427aa61862302d6 | https://github.com/Aerendir/PHPTextMatrix/blob/d8b3ce58b7174c6ddd9959e33427aa61862302d6/src/PHPTextMatrix.php#L242-L289 | train |
Aerendir/PHPTextMatrix | src/PHPTextMatrix.php | PHPTextMatrix.calculateTableWidth | private function calculateTableWidth(): int
{
// Now calculate the total width of the table
$tableWidth = 0;
// Add the width of the columns
foreach ($this->columnsWidths as $width) {
$tableWidth += $width;
}
// Add 1 for the first separator
$tableWidth += 1;
// Add the left and right padding * number of columns
$tableWidth += ($this->options['cells_padding'][1] + $this->options['cells_padding'][3]) * count($this->columnsWidths);
// Add the left separators
$tableWidth += count($this->columnsWidths);
return $tableWidth;
} | php | private function calculateTableWidth(): int
{
// Now calculate the total width of the table
$tableWidth = 0;
// Add the width of the columns
foreach ($this->columnsWidths as $width) {
$tableWidth += $width;
}
// Add 1 for the first separator
$tableWidth += 1;
// Add the left and right padding * number of columns
$tableWidth += ($this->options['cells_padding'][1] + $this->options['cells_padding'][3]) * count($this->columnsWidths);
// Add the left separators
$tableWidth += count($this->columnsWidths);
return $tableWidth;
} | [
"private",
"function",
"calculateTableWidth",
"(",
")",
":",
"int",
"{",
"// Now calculate the total width of the table",
"$",
"tableWidth",
"=",
"0",
";",
"// Add the width of the columns",
"foreach",
"(",
"$",
"this",
"->",
"columnsWidths",
"as",
"$",
"width",
")",
"{",
"$",
"tableWidth",
"+=",
"$",
"width",
";",
"}",
"// Add 1 for the first separator",
"$",
"tableWidth",
"+=",
"1",
";",
"// Add the left and right padding * number of columns",
"$",
"tableWidth",
"+=",
"(",
"$",
"this",
"->",
"options",
"[",
"'cells_padding'",
"]",
"[",
"1",
"]",
"+",
"$",
"this",
"->",
"options",
"[",
"'cells_padding'",
"]",
"[",
"3",
"]",
")",
"*",
"count",
"(",
"$",
"this",
"->",
"columnsWidths",
")",
";",
"// Add the left separators",
"$",
"tableWidth",
"+=",
"count",
"(",
"$",
"this",
"->",
"columnsWidths",
")",
";",
"return",
"$",
"tableWidth",
";",
"}"
] | Calculates the total width of the table.
@return int | [
"Calculates",
"the",
"total",
"width",
"of",
"the",
"table",
"."
] | d8b3ce58b7174c6ddd9959e33427aa61862302d6 | https://github.com/Aerendir/PHPTextMatrix/blob/d8b3ce58b7174c6ddd9959e33427aa61862302d6/src/PHPTextMatrix.php#L296-L316 | train |
Aerendir/PHPTextMatrix | src/PHPTextMatrix.php | PHPTextMatrix.drawDivider | private function drawDivider(string $prefix = 'sep_'): string
{
$divider = '';
foreach ($this->columnsWidths as $width) {
// Column width position for the xSep + left and rigth padding
$times = $width + $this->options['cells_padding'][1] + $this->options['cells_padding'][3];
$divider .= $this->options[$prefix . 'x'] . $this->repeatChar($this->options[$prefix . 'h'], $times);
}
return $divider . $this->options[$prefix . 'x'] . PHP_EOL;
} | php | private function drawDivider(string $prefix = 'sep_'): string
{
$divider = '';
foreach ($this->columnsWidths as $width) {
// Column width position for the xSep + left and rigth padding
$times = $width + $this->options['cells_padding'][1] + $this->options['cells_padding'][3];
$divider .= $this->options[$prefix . 'x'] . $this->repeatChar($this->options[$prefix . 'h'], $times);
}
return $divider . $this->options[$prefix . 'x'] . PHP_EOL;
} | [
"private",
"function",
"drawDivider",
"(",
"string",
"$",
"prefix",
"=",
"'sep_'",
")",
":",
"string",
"{",
"$",
"divider",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"columnsWidths",
"as",
"$",
"width",
")",
"{",
"// Column width position for the xSep + left and rigth padding",
"$",
"times",
"=",
"$",
"width",
"+",
"$",
"this",
"->",
"options",
"[",
"'cells_padding'",
"]",
"[",
"1",
"]",
"+",
"$",
"this",
"->",
"options",
"[",
"'cells_padding'",
"]",
"[",
"3",
"]",
";",
"$",
"divider",
".=",
"$",
"this",
"->",
"options",
"[",
"$",
"prefix",
".",
"'x'",
"]",
".",
"$",
"this",
"->",
"repeatChar",
"(",
"$",
"this",
"->",
"options",
"[",
"$",
"prefix",
".",
"'h'",
"]",
",",
"$",
"times",
")",
";",
"}",
"return",
"$",
"divider",
".",
"$",
"this",
"->",
"options",
"[",
"$",
"prefix",
".",
"'x'",
"]",
".",
"PHP_EOL",
";",
"}"
] | Draws the horizontal divider.
@param string $prefix
@return string | [
"Draws",
"the",
"horizontal",
"divider",
"."
] | d8b3ce58b7174c6ddd9959e33427aa61862302d6 | https://github.com/Aerendir/PHPTextMatrix/blob/d8b3ce58b7174c6ddd9959e33427aa61862302d6/src/PHPTextMatrix.php#L333-L343 | train |
Aerendir/PHPTextMatrix | src/PHPTextMatrix.php | PHPTextMatrix.resolveCellsPaddings | private function resolveCellsPaddings(): array
{
$return = [0, 0, 0, 0];
// If padding is not set, return default values
if (false === isset($this->options['cells_padding'])) {
return $return;
}
// Create a resolver to validate passed values
$resolver = new OptionsResolver();
$resolver->setDefined(0);
$resolver->setDefined(1);
$resolver->setDefined(2);
$resolver->setDefined(3);
$resolver->setAllowedTypes(0, 'integer');
$resolver->setAllowedTypes(1, 'integer');
$resolver->setAllowedTypes(2, 'integer');
$resolver->setAllowedTypes(3, 'integer');
$padding = $this->options['cells_padding'];
// If is only an integer, make it an array with only one set value
if (is_int($padding)) {
$padding = [$padding];
}
$count = count($padding);
switch ($count) {
case 1:
// Set the same padding for all directions
$return = [$padding[0], $padding[0], $padding[0], $padding[0]];
break;
case 2:
// 0: Top and Bottom; 1: Left and Right
$return = [$padding[0], $padding[1], $padding[0], $padding[1]];
break;
case 3:
// 0: Top; 1: Left and Right; 2: Bottom
$return = [$padding[0], $padding[1], $padding[2], $padding[1]];
break;
case 4:
// 0: Top; 1: Right; 2: Bottom; 3: Left
$return = [$padding[0], $padding[1], $padding[2], $padding[3]];
break;
}
return $return;
} | php | private function resolveCellsPaddings(): array
{
$return = [0, 0, 0, 0];
// If padding is not set, return default values
if (false === isset($this->options['cells_padding'])) {
return $return;
}
// Create a resolver to validate passed values
$resolver = new OptionsResolver();
$resolver->setDefined(0);
$resolver->setDefined(1);
$resolver->setDefined(2);
$resolver->setDefined(3);
$resolver->setAllowedTypes(0, 'integer');
$resolver->setAllowedTypes(1, 'integer');
$resolver->setAllowedTypes(2, 'integer');
$resolver->setAllowedTypes(3, 'integer');
$padding = $this->options['cells_padding'];
// If is only an integer, make it an array with only one set value
if (is_int($padding)) {
$padding = [$padding];
}
$count = count($padding);
switch ($count) {
case 1:
// Set the same padding for all directions
$return = [$padding[0], $padding[0], $padding[0], $padding[0]];
break;
case 2:
// 0: Top and Bottom; 1: Left and Right
$return = [$padding[0], $padding[1], $padding[0], $padding[1]];
break;
case 3:
// 0: Top; 1: Left and Right; 2: Bottom
$return = [$padding[0], $padding[1], $padding[2], $padding[1]];
break;
case 4:
// 0: Top; 1: Right; 2: Bottom; 3: Left
$return = [$padding[0], $padding[1], $padding[2], $padding[3]];
break;
}
return $return;
} | [
"private",
"function",
"resolveCellsPaddings",
"(",
")",
":",
"array",
"{",
"$",
"return",
"=",
"[",
"0",
",",
"0",
",",
"0",
",",
"0",
"]",
";",
"// If padding is not set, return default values",
"if",
"(",
"false",
"===",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'cells_padding'",
"]",
")",
")",
"{",
"return",
"$",
"return",
";",
"}",
"// Create a resolver to validate passed values",
"$",
"resolver",
"=",
"new",
"OptionsResolver",
"(",
")",
";",
"$",
"resolver",
"->",
"setDefined",
"(",
"0",
")",
";",
"$",
"resolver",
"->",
"setDefined",
"(",
"1",
")",
";",
"$",
"resolver",
"->",
"setDefined",
"(",
"2",
")",
";",
"$",
"resolver",
"->",
"setDefined",
"(",
"3",
")",
";",
"$",
"resolver",
"->",
"setAllowedTypes",
"(",
"0",
",",
"'integer'",
")",
";",
"$",
"resolver",
"->",
"setAllowedTypes",
"(",
"1",
",",
"'integer'",
")",
";",
"$",
"resolver",
"->",
"setAllowedTypes",
"(",
"2",
",",
"'integer'",
")",
";",
"$",
"resolver",
"->",
"setAllowedTypes",
"(",
"3",
",",
"'integer'",
")",
";",
"$",
"padding",
"=",
"$",
"this",
"->",
"options",
"[",
"'cells_padding'",
"]",
";",
"// If is only an integer, make it an array with only one set value",
"if",
"(",
"is_int",
"(",
"$",
"padding",
")",
")",
"{",
"$",
"padding",
"=",
"[",
"$",
"padding",
"]",
";",
"}",
"$",
"count",
"=",
"count",
"(",
"$",
"padding",
")",
";",
"switch",
"(",
"$",
"count",
")",
"{",
"case",
"1",
":",
"// Set the same padding for all directions",
"$",
"return",
"=",
"[",
"$",
"padding",
"[",
"0",
"]",
",",
"$",
"padding",
"[",
"0",
"]",
",",
"$",
"padding",
"[",
"0",
"]",
",",
"$",
"padding",
"[",
"0",
"]",
"]",
";",
"break",
";",
"case",
"2",
":",
"// 0: Top and Bottom; 1: Left and Right",
"$",
"return",
"=",
"[",
"$",
"padding",
"[",
"0",
"]",
",",
"$",
"padding",
"[",
"1",
"]",
",",
"$",
"padding",
"[",
"0",
"]",
",",
"$",
"padding",
"[",
"1",
"]",
"]",
";",
"break",
";",
"case",
"3",
":",
"// 0: Top; 1: Left and Right; 2: Bottom",
"$",
"return",
"=",
"[",
"$",
"padding",
"[",
"0",
"]",
",",
"$",
"padding",
"[",
"1",
"]",
",",
"$",
"padding",
"[",
"2",
"]",
",",
"$",
"padding",
"[",
"1",
"]",
"]",
";",
"break",
";",
"case",
"4",
":",
"// 0: Top; 1: Right; 2: Bottom; 3: Left",
"$",
"return",
"=",
"[",
"$",
"padding",
"[",
"0",
"]",
",",
"$",
"padding",
"[",
"1",
"]",
",",
"$",
"padding",
"[",
"2",
"]",
",",
"$",
"padding",
"[",
"3",
"]",
"]",
";",
"break",
";",
"}",
"return",
"$",
"return",
";",
"}"
] | Set the padding of the cells.
This is the number of spaces to put on the left and on the right and on top and bottom of the content in each cell.
This method follows the rules of the padding CSS rule.
@see http://www.w3schools.com/css/css_padding.asp
@throws \InvalidArgumentException If the value is not an integer
@return array | [
"Set",
"the",
"padding",
"of",
"the",
"cells",
"."
] | d8b3ce58b7174c6ddd9959e33427aa61862302d6 | https://github.com/Aerendir/PHPTextMatrix/blob/d8b3ce58b7174c6ddd9959e33427aa61862302d6/src/PHPTextMatrix.php#L521-L574 | train |
linpax/microphp-framework | src/logger/drivers/DbDriver.php | DbDriver.sendMessage | public function sendMessage($level, $message)
{
$this->db->insert($this->tableName, [
'level' => $level,
'message' => $message,
'date_create' => $_SERVER['REQUEST_TIME']
]);
} | php | public function sendMessage($level, $message)
{
$this->db->insert($this->tableName, [
'level' => $level,
'message' => $message,
'date_create' => $_SERVER['REQUEST_TIME']
]);
} | [
"public",
"function",
"sendMessage",
"(",
"$",
"level",
",",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"db",
"->",
"insert",
"(",
"$",
"this",
"->",
"tableName",
",",
"[",
"'level'",
"=>",
"$",
"level",
",",
"'message'",
"=>",
"$",
"message",
",",
"'date_create'",
"=>",
"$",
"_SERVER",
"[",
"'REQUEST_TIME'",
"]",
"]",
")",
";",
"}"
] | Send log message into DB
@access public
@param integer $level level number
@param string $message message to write
@return void | [
"Send",
"log",
"message",
"into",
"DB"
] | 11f3370f3f64c516cce9b84ecd8276c6e9ae8df9 | https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/logger/drivers/DbDriver.php#L73-L80 | train |
JochLAin/symfony-database | src/ORM/Repository.php | Repository.count | public function count(array $constraints = [], QueryBuilder $qb = null)
{
$qb = !is_null($qb) ? $qb : $this->createQueryBuilder('e');
if (count($constraints)) $qb = $this->_by($qb, $constraints);
return $this->arrange($this->_count($qb), Repository::RESULT_SHAPE_SCALAR);
} | php | public function count(array $constraints = [], QueryBuilder $qb = null)
{
$qb = !is_null($qb) ? $qb : $this->createQueryBuilder('e');
if (count($constraints)) $qb = $this->_by($qb, $constraints);
return $this->arrange($this->_count($qb), Repository::RESULT_SHAPE_SCALAR);
} | [
"public",
"function",
"count",
"(",
"array",
"$",
"constraints",
"=",
"[",
"]",
",",
"QueryBuilder",
"$",
"qb",
"=",
"null",
")",
"{",
"$",
"qb",
"=",
"!",
"is_null",
"(",
"$",
"qb",
")",
"?",
"$",
"qb",
":",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'e'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"constraints",
")",
")",
"$",
"qb",
"=",
"$",
"this",
"->",
"_by",
"(",
"$",
"qb",
",",
"$",
"constraints",
")",
";",
"return",
"$",
"this",
"->",
"arrange",
"(",
"$",
"this",
"->",
"_count",
"(",
"$",
"qb",
")",
",",
"Repository",
"::",
"RESULT_SHAPE_SCALAR",
")",
";",
"}"
] | Return number of entities
@param Doctrine\ORM\QueryBuilder = null
@return integer | [
"Return",
"number",
"of",
"entities"
] | a0fae6e057e142190ef68d0a37898d5f1b16cba9 | https://github.com/JochLAin/symfony-database/blob/a0fae6e057e142190ef68d0a37898d5f1b16cba9/src/ORM/Repository.php#L40-L45 | train |
JochLAin/symfony-database | src/ORM/Repository.php | Repository._paginate | protected function _paginate(QueryBuilder $qb, int $offset, int $limit)
{
return $qb
->setFirstResult($offset)
->setMaxResults($limit);
} | php | protected function _paginate(QueryBuilder $qb, int $offset, int $limit)
{
return $qb
->setFirstResult($offset)
->setMaxResults($limit);
} | [
"protected",
"function",
"_paginate",
"(",
"QueryBuilder",
"$",
"qb",
",",
"int",
"$",
"offset",
",",
"int",
"$",
"limit",
")",
"{",
"return",
"$",
"qb",
"->",
"setFirstResult",
"(",
"$",
"offset",
")",
"->",
"setMaxResults",
"(",
"$",
"limit",
")",
";",
"}"
] | Improve QueryBuilder with basic paginate request
@param Doctrine\ORM\QueryBuilder
@param integer $offset
@param integer $limit
@return Doctrine\ORM\QueryBuilder | [
"Improve",
"QueryBuilder",
"with",
"basic",
"paginate",
"request"
] | a0fae6e057e142190ef68d0a37898d5f1b16cba9 | https://github.com/JochLAin/symfony-database/blob/a0fae6e057e142190ef68d0a37898d5f1b16cba9/src/ORM/Repository.php#L103-L108 | train |
mylxsw/FocusPHP | src/Server.php | Server.init | public static function init(Container $container = null)
{
if (empty(self::$_instance)) {
// 环境检测
if (version_compare(PHP_VERSION, '5.6.0', '<')) {
throw new \ErrorException('NONSUPPORT_PHP_VERSION');
}
if (is_null($container)) {
$container = Container::instance();
}
self::$_instance = new self($container->getContainer());
}
return self::$_instance;
} | php | public static function init(Container $container = null)
{
if (empty(self::$_instance)) {
// 环境检测
if (version_compare(PHP_VERSION, '5.6.0', '<')) {
throw new \ErrorException('NONSUPPORT_PHP_VERSION');
}
if (is_null($container)) {
$container = Container::instance();
}
self::$_instance = new self($container->getContainer());
}
return self::$_instance;
} | [
"public",
"static",
"function",
"init",
"(",
"Container",
"$",
"container",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"self",
"::",
"$",
"_instance",
")",
")",
"{",
"// 环境检测",
"if",
"(",
"version_compare",
"(",
"PHP_VERSION",
",",
"'5.6.0'",
",",
"'<'",
")",
")",
"{",
"throw",
"new",
"\\",
"ErrorException",
"(",
"'NONSUPPORT_PHP_VERSION'",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"container",
")",
")",
"{",
"$",
"container",
"=",
"Container",
"::",
"instance",
"(",
")",
";",
"}",
"self",
"::",
"$",
"_instance",
"=",
"new",
"self",
"(",
"$",
"container",
"->",
"getContainer",
"(",
")",
")",
";",
"}",
"return",
"self",
"::",
"$",
"_instance",
";",
"}"
] | Initialize the server object.
@param Container $container
@throws \ErrorException
@return Server | [
"Initialize",
"the",
"server",
"object",
"."
] | 33922bacbea66f11f874d991d7308a36cdf5831a | https://github.com/mylxsw/FocusPHP/blob/33922bacbea66f11f874d991d7308a36cdf5831a/src/Server.php#L58-L74 | train |
mylxsw/FocusPHP | src/Server.php | Server.registerRouter | public function registerRouter($router, ...$params)
{
$this->_router->add($router, ...$params);
if (defined('FOCUS_DEBUG') && FOCUS_DEBUG) {
$this->getLogger()->debug('add new router: '
.(is_string($router) ? $router : get_class($router)));
}
} | php | public function registerRouter($router, ...$params)
{
$this->_router->add($router, ...$params);
if (defined('FOCUS_DEBUG') && FOCUS_DEBUG) {
$this->getLogger()->debug('add new router: '
.(is_string($router) ? $router : get_class($router)));
}
} | [
"public",
"function",
"registerRouter",
"(",
"$",
"router",
",",
"...",
"$",
"params",
")",
"{",
"$",
"this",
"->",
"_router",
"->",
"add",
"(",
"$",
"router",
",",
"...",
"$",
"params",
")",
";",
"if",
"(",
"defined",
"(",
"'FOCUS_DEBUG'",
")",
"&&",
"FOCUS_DEBUG",
")",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"debug",
"(",
"'add new router: '",
".",
"(",
"is_string",
"(",
"$",
"router",
")",
"?",
"$",
"router",
":",
"get_class",
"(",
"$",
"router",
")",
")",
")",
";",
"}",
"}"
] | register router.
@param $router
@param $params | [
"register",
"router",
"."
] | 33922bacbea66f11f874d991d7308a36cdf5831a | https://github.com/mylxsw/FocusPHP/blob/33922bacbea66f11f874d991d7308a36cdf5831a/src/Server.php#L104-L111 | train |
mylxsw/FocusPHP | src/Server.php | Server.registerAutoloader | public function registerAutoloader($baseDir, $baseNs)
{
$baseNs = $baseNs[strlen($baseNs) - 1] == '\\' ? $baseNs : "{$baseNs}\\";
$baseDir = rtrim($baseDir, '/');
spl_autoload_register(
function ($class) use ($baseDir, $baseNs) {
if (strncmp($baseNs, $class, strlen($baseNs)) == 0) {
$filename = str_replace(
'\\',
'/',
$baseDir.'/'.substr($class, strlen($baseNs)).'.php'
);
if (file_exists($filename)) {
if (defined('FOCUS_DEBUG') && FOCUS_DEBUG) {
$this->getLogger()->debug('automatic load file '.$filename);
}
include $filename;
if (defined('FOCUS_DEBUG') && FOCUS_DEBUG) {
$this->getLogger()->debug("file {$filename} loaded");
}
}
}
},
true,
false
);
} | php | public function registerAutoloader($baseDir, $baseNs)
{
$baseNs = $baseNs[strlen($baseNs) - 1] == '\\' ? $baseNs : "{$baseNs}\\";
$baseDir = rtrim($baseDir, '/');
spl_autoload_register(
function ($class) use ($baseDir, $baseNs) {
if (strncmp($baseNs, $class, strlen($baseNs)) == 0) {
$filename = str_replace(
'\\',
'/',
$baseDir.'/'.substr($class, strlen($baseNs)).'.php'
);
if (file_exists($filename)) {
if (defined('FOCUS_DEBUG') && FOCUS_DEBUG) {
$this->getLogger()->debug('automatic load file '.$filename);
}
include $filename;
if (defined('FOCUS_DEBUG') && FOCUS_DEBUG) {
$this->getLogger()->debug("file {$filename} loaded");
}
}
}
},
true,
false
);
} | [
"public",
"function",
"registerAutoloader",
"(",
"$",
"baseDir",
",",
"$",
"baseNs",
")",
"{",
"$",
"baseNs",
"=",
"$",
"baseNs",
"[",
"strlen",
"(",
"$",
"baseNs",
")",
"-",
"1",
"]",
"==",
"'\\\\'",
"?",
"$",
"baseNs",
":",
"\"{$baseNs}\\\\\"",
";",
"$",
"baseDir",
"=",
"rtrim",
"(",
"$",
"baseDir",
",",
"'/'",
")",
";",
"spl_autoload_register",
"(",
"function",
"(",
"$",
"class",
")",
"use",
"(",
"$",
"baseDir",
",",
"$",
"baseNs",
")",
"{",
"if",
"(",
"strncmp",
"(",
"$",
"baseNs",
",",
"$",
"class",
",",
"strlen",
"(",
"$",
"baseNs",
")",
")",
"==",
"0",
")",
"{",
"$",
"filename",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"baseDir",
".",
"'/'",
".",
"substr",
"(",
"$",
"class",
",",
"strlen",
"(",
"$",
"baseNs",
")",
")",
".",
"'.php'",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"filename",
")",
")",
"{",
"if",
"(",
"defined",
"(",
"'FOCUS_DEBUG'",
")",
"&&",
"FOCUS_DEBUG",
")",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"debug",
"(",
"'automatic load file '",
".",
"$",
"filename",
")",
";",
"}",
"include",
"$",
"filename",
";",
"if",
"(",
"defined",
"(",
"'FOCUS_DEBUG'",
")",
"&&",
"FOCUS_DEBUG",
")",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"debug",
"(",
"\"file {$filename} loaded\"",
")",
";",
"}",
"}",
"}",
"}",
",",
"true",
",",
"false",
")",
";",
"}"
] | register class autoloader.
@param string $baseDir Root directory of the project
@param string $baseNs Basic namespace | [
"register",
"class",
"autoloader",
"."
] | 33922bacbea66f11f874d991d7308a36cdf5831a | https://github.com/mylxsw/FocusPHP/blob/33922bacbea66f11f874d991d7308a36cdf5831a/src/Server.php#L146-L175 | train |
e-commit/EcommitUtilBundle | Cache/Cache.php | Cache.load | public function load($key)
{
$data = $this->adapter->getItem($key, $success);
if ($success && $this->automaticSerialization) {
$data = unserialize($data);
if ($data === false) {
$this->remove($key);
}
}
return $data;
} | php | public function load($key)
{
$data = $this->adapter->getItem($key, $success);
if ($success && $this->automaticSerialization) {
$data = unserialize($data);
if ($data === false) {
$this->remove($key);
}
}
return $data;
} | [
"public",
"function",
"load",
"(",
"$",
"key",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"adapter",
"->",
"getItem",
"(",
"$",
"key",
",",
"$",
"success",
")",
";",
"if",
"(",
"$",
"success",
"&&",
"$",
"this",
"->",
"automaticSerialization",
")",
"{",
"$",
"data",
"=",
"unserialize",
"(",
"$",
"data",
")",
";",
"if",
"(",
"$",
"data",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"remove",
"(",
"$",
"key",
")",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Get an item
@param string $key
@return mixed Data on success and false on failure
@throws \Zend\Cache\Exception | [
"Get",
"an",
"item"
] | 2ee5ddae7709e8ad4412739cbecda28e0590da8b | https://github.com/e-commit/EcommitUtilBundle/blob/2ee5ddae7709e8ad4412739cbecda28e0590da8b/Cache/Cache.php#L67-L80 | train |
jabernardo/lollipop-php | Library/Security/CsrfToken.php | CsrfToken.isValid | public static function isValid($token) {
// Get configuration
$expiration = Config::get('security.anti_csrf.expiration', 18000);
// Compute for token availablity
$computed = microtime(true) - (double)Text::unlock($token, self::getKey());
return $computed <= $expiration;
} | php | public static function isValid($token) {
// Get configuration
$expiration = Config::get('security.anti_csrf.expiration', 18000);
// Compute for token availablity
$computed = microtime(true) - (double)Text::unlock($token, self::getKey());
return $computed <= $expiration;
} | [
"public",
"static",
"function",
"isValid",
"(",
"$",
"token",
")",
"{",
"// Get configuration",
"$",
"expiration",
"=",
"Config",
"::",
"get",
"(",
"'security.anti_csrf.expiration'",
",",
"18000",
")",
";",
"// Compute for token availablity",
"$",
"computed",
"=",
"microtime",
"(",
"true",
")",
"-",
"(",
"double",
")",
"Text",
"::",
"unlock",
"(",
"$",
"token",
",",
"self",
"::",
"getKey",
"(",
")",
")",
";",
"return",
"$",
"computed",
"<=",
"$",
"expiration",
";",
"}"
] | Check Validity of Token
@access public
@return bool | [
"Check",
"Validity",
"of",
"Token"
] | 004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5 | https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/Security/CsrfToken.php#L75-L82 | train |
WellCommerce/LayoutBundle | Configurator/LayoutBoxConfiguratorCollection.php | LayoutBoxConfiguratorCollection.add | public function add(LayoutBoxConfiguratorInterface $configurator)
{
$type = $configurator->getType();
if ($this->has($type)) {
throw new \InvalidArgumentException(sprintf('Layout box configurator "%s" already exists.', $type));
}
$this->items[$configurator->getType()] = $configurator;
} | php | public function add(LayoutBoxConfiguratorInterface $configurator)
{
$type = $configurator->getType();
if ($this->has($type)) {
throw new \InvalidArgumentException(sprintf('Layout box configurator "%s" already exists.', $type));
}
$this->items[$configurator->getType()] = $configurator;
} | [
"public",
"function",
"add",
"(",
"LayoutBoxConfiguratorInterface",
"$",
"configurator",
")",
"{",
"$",
"type",
"=",
"$",
"configurator",
"->",
"getType",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"$",
"type",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Layout box configurator \"%s\" already exists.'",
",",
"$",
"type",
")",
")",
";",
"}",
"$",
"this",
"->",
"items",
"[",
"$",
"configurator",
"->",
"getType",
"(",
")",
"]",
"=",
"$",
"configurator",
";",
"}"
] | Adds new configurator to collection
@param LayoutBoxConfiguratorInterface $configurator
@throws \InvalidArgumentException If such configurator already exists in collection | [
"Adds",
"new",
"configurator",
"to",
"collection"
] | 470efd187d19827058f88317221cb875b4c9ced3 | https://github.com/WellCommerce/LayoutBundle/blob/470efd187d19827058f88317221cb875b4c9ced3/Configurator/LayoutBoxConfiguratorCollection.php#L31-L38 | train |
geoffroy-aubry/Helpers | src/GAubry/Helpers/Helpers.php | Helpers.isAssociativeArray | public static function isAssociativeArray (array $aArray)
{
foreach (array_keys($aArray) as $key) {
if (! is_int($key)) {
return true;
}
}
return false;
} | php | public static function isAssociativeArray (array $aArray)
{
foreach (array_keys($aArray) as $key) {
if (! is_int($key)) {
return true;
}
}
return false;
} | [
"public",
"static",
"function",
"isAssociativeArray",
"(",
"array",
"$",
"aArray",
")",
"{",
"foreach",
"(",
"array_keys",
"(",
"$",
"aArray",
")",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"key",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Returns TRUE iff the specified array is associative.
If the specified array is empty, then return FALSE.
http://stackoverflow.com/questions/173400/php-arrays-a-good-way-to-check-if-an-array-is-associative-or-sequential
@param array $aArray
@return bool true ssi iff the specified array is associative | [
"Returns",
"TRUE",
"iff",
"the",
"specified",
"array",
"is",
"associative",
".",
"If",
"the",
"specified",
"array",
"is",
"empty",
"then",
"return",
"FALSE",
"."
] | 09e787e554158d7c2233a27107d2949824cd5602 | https://github.com/geoffroy-aubry/Helpers/blob/09e787e554158d7c2233a27107d2949824cd5602/src/GAubry/Helpers/Helpers.php#L291-L299 | train |
geoffroy-aubry/Helpers | src/GAubry/Helpers/Helpers.php | Helpers.getCurrentTimeWithCS | public static function getCurrentTimeWithCS ($sFormat)
{
$aMicrotime = explode(' ', microtime());
$sFilledFormat = sprintf($sFormat, $aMicrotime[0]*1000000);
$sDate = date($sFilledFormat, $aMicrotime[1]);
return $sDate;
} | php | public static function getCurrentTimeWithCS ($sFormat)
{
$aMicrotime = explode(' ', microtime());
$sFilledFormat = sprintf($sFormat, $aMicrotime[0]*1000000);
$sDate = date($sFilledFormat, $aMicrotime[1]);
return $sDate;
} | [
"public",
"static",
"function",
"getCurrentTimeWithCS",
"(",
"$",
"sFormat",
")",
"{",
"$",
"aMicrotime",
"=",
"explode",
"(",
"' '",
",",
"microtime",
"(",
")",
")",
";",
"$",
"sFilledFormat",
"=",
"sprintf",
"(",
"$",
"sFormat",
",",
"$",
"aMicrotime",
"[",
"0",
"]",
"*",
"1000000",
")",
";",
"$",
"sDate",
"=",
"date",
"(",
"$",
"sFilledFormat",
",",
"$",
"aMicrotime",
"[",
"1",
"]",
")",
";",
"return",
"$",
"sDate",
";",
"}"
] | Returns current time with hundredths of a second.
@param string $sFormat including %s for cs, eg: 'Y-m-d H:i:s.%s'
@return string current time with hundredths of a second. | [
"Returns",
"current",
"time",
"with",
"hundredths",
"of",
"a",
"second",
"."
] | 09e787e554158d7c2233a27107d2949824cd5602 | https://github.com/geoffroy-aubry/Helpers/blob/09e787e554158d7c2233a27107d2949824cd5602/src/GAubry/Helpers/Helpers.php#L307-L313 | train |
geoffroy-aubry/Helpers | src/GAubry/Helpers/Helpers.php | Helpers.generateMongoId | public static function generateMongoId ($iTimestamp = 0, $bBase32 = true)
{
static $inc = 0;
if ($inc === 0) {
// set with microseconds:
$inc = (int)substr(microtime(), 2, 6);
}
$bin = sprintf(
'%s%s%s%s',
pack('N', $iTimestamp ?: time()),
substr(md5(gethostname()), 0, 3),
pack('n', posix_getpid()),
substr(pack('N', $inc++), 1, 3)
);
return $bBase32 ? strtolower(Base32::encodeByteStr($bin, true)) : bin2hex($bin);
} | php | public static function generateMongoId ($iTimestamp = 0, $bBase32 = true)
{
static $inc = 0;
if ($inc === 0) {
// set with microseconds:
$inc = (int)substr(microtime(), 2, 6);
}
$bin = sprintf(
'%s%s%s%s',
pack('N', $iTimestamp ?: time()),
substr(md5(gethostname()), 0, 3),
pack('n', posix_getpid()),
substr(pack('N', $inc++), 1, 3)
);
return $bBase32 ? strtolower(Base32::encodeByteStr($bin, true)) : bin2hex($bin);
} | [
"public",
"static",
"function",
"generateMongoId",
"(",
"$",
"iTimestamp",
"=",
"0",
",",
"$",
"bBase32",
"=",
"true",
")",
"{",
"static",
"$",
"inc",
"=",
"0",
";",
"if",
"(",
"$",
"inc",
"===",
"0",
")",
"{",
"// set with microseconds:",
"$",
"inc",
"=",
"(",
"int",
")",
"substr",
"(",
"microtime",
"(",
")",
",",
"2",
",",
"6",
")",
";",
"}",
"$",
"bin",
"=",
"sprintf",
"(",
"'%s%s%s%s'",
",",
"pack",
"(",
"'N'",
",",
"$",
"iTimestamp",
"?",
":",
"time",
"(",
")",
")",
",",
"substr",
"(",
"md5",
"(",
"gethostname",
"(",
")",
")",
",",
"0",
",",
"3",
")",
",",
"pack",
"(",
"'n'",
",",
"posix_getpid",
"(",
")",
")",
",",
"substr",
"(",
"pack",
"(",
"'N'",
",",
"$",
"inc",
"++",
")",
",",
"1",
",",
"3",
")",
")",
";",
"return",
"$",
"bBase32",
"?",
"strtolower",
"(",
"Base32",
"::",
"encodeByteStr",
"(",
"$",
"bin",
",",
"true",
")",
")",
":",
"bin2hex",
"(",
"$",
"bin",
")",
";",
"}"
] | Generates a globally unique id generator using Mongo Object ID algorithm.
The 12-byte ObjectId value consists of:
- a 4-byte value representing the seconds since the Unix epoch,
- a 3-byte machine identifier,
- a 2-byte process id, and
- a 3-byte counter, starting with a random value.
@see https://docs.mongodb.org/manual/reference/method/ObjectId/
Uses SKleeschulte\Base32 because base_convert() may lose precision on large numbers due to properties related
to the internal "double" or "float" type used.
@see http://php.net/manual/function.base-convert.php
@param int $iTimestamp Default: time()
@param bool $bBase32 Base32 (RFC 4648) or hex output?
@return string 20 base32-char or 24 hex-car MongoId.
@see https://www.ietf.org/rfc/rfc4648.txt
@see http://stackoverflow.com/questions/14370143/create-mongodb-objectid-from-date-in-the-past-using-php-driver | [
"Generates",
"a",
"globally",
"unique",
"id",
"generator",
"using",
"Mongo",
"Object",
"ID",
"algorithm",
"."
] | 09e787e554158d7c2233a27107d2949824cd5602 | https://github.com/geoffroy-aubry/Helpers/blob/09e787e554158d7c2233a27107d2949824cd5602/src/GAubry/Helpers/Helpers.php#L355-L372 | train |
yasheena/yii2-view | YFormatter.php | YFormatter.asNtext1line | public function asNtext1line($value, $maxlen = null)
{
if ($value === null) {
return $this->nullDisplay;
}
$suffix = '';
if ((false !== ($n = strpos($value, "\n"))) || (false !== ($n = strpos($value, "\r")))) {
if (($n > 0) && (substr($value, $n - 1, 1) == "\r")) {
$n--;
}
$value = substr($value, 0, $n - 1);
$suffix = ' ...';
}
if ($maxlen) {
if ((strlen($value) + strlen($suffix) > $maxlen)) {
$suffix = ' ...';
$value = substr($value, 0, $maxlen - strlen($suffix));
}
}
return Html::encode($value . $suffix);
} | php | public function asNtext1line($value, $maxlen = null)
{
if ($value === null) {
return $this->nullDisplay;
}
$suffix = '';
if ((false !== ($n = strpos($value, "\n"))) || (false !== ($n = strpos($value, "\r")))) {
if (($n > 0) && (substr($value, $n - 1, 1) == "\r")) {
$n--;
}
$value = substr($value, 0, $n - 1);
$suffix = ' ...';
}
if ($maxlen) {
if ((strlen($value) + strlen($suffix) > $maxlen)) {
$suffix = ' ...';
$value = substr($value, 0, $maxlen - strlen($suffix));
}
}
return Html::encode($value . $suffix);
} | [
"public",
"function",
"asNtext1line",
"(",
"$",
"value",
",",
"$",
"maxlen",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"nullDisplay",
";",
"}",
"$",
"suffix",
"=",
"''",
";",
"if",
"(",
"(",
"false",
"!==",
"(",
"$",
"n",
"=",
"strpos",
"(",
"$",
"value",
",",
"\"\\n\"",
")",
")",
")",
"||",
"(",
"false",
"!==",
"(",
"$",
"n",
"=",
"strpos",
"(",
"$",
"value",
",",
"\"\\r\"",
")",
")",
")",
")",
"{",
"if",
"(",
"(",
"$",
"n",
">",
"0",
")",
"&&",
"(",
"substr",
"(",
"$",
"value",
",",
"$",
"n",
"-",
"1",
",",
"1",
")",
"==",
"\"\\r\"",
")",
")",
"{",
"$",
"n",
"--",
";",
"}",
"$",
"value",
"=",
"substr",
"(",
"$",
"value",
",",
"0",
",",
"$",
"n",
"-",
"1",
")",
";",
"$",
"suffix",
"=",
"' ...'",
";",
"}",
"if",
"(",
"$",
"maxlen",
")",
"{",
"if",
"(",
"(",
"strlen",
"(",
"$",
"value",
")",
"+",
"strlen",
"(",
"$",
"suffix",
")",
">",
"$",
"maxlen",
")",
")",
"{",
"$",
"suffix",
"=",
"' ...'",
";",
"$",
"value",
"=",
"substr",
"(",
"$",
"value",
",",
"0",
",",
"$",
"maxlen",
"-",
"strlen",
"(",
"$",
"suffix",
")",
")",
";",
"}",
"}",
"return",
"Html",
"::",
"encode",
"(",
"$",
"value",
".",
"$",
"suffix",
")",
";",
"}"
] | Formats the value as an HTML-encoded plain text. If the value contains \n or \r
the first line will be returned only.
@param string $value the value to be formatted.
@return string the formatted result. | [
"Formats",
"the",
"value",
"as",
"an",
"HTML",
"-",
"encoded",
"plain",
"text",
".",
"If",
"the",
"value",
"contains",
"\\",
"n",
"or",
"\\",
"r",
"the",
"first",
"line",
"will",
"be",
"returned",
"only",
"."
] | b75a24efc9bbf463c0fce8e2e4477ff3ae169559 | https://github.com/yasheena/yii2-view/blob/b75a24efc9bbf463c0fce8e2e4477ff3ae169559/YFormatter.php#L30-L50 | train |
dms-org/common.structure | src/DateTime/TimezonedDateTimeRange.php | TimezonedDateTimeRange.overlaps | public function overlaps(TimezonedDateTimeRange $otherRange) : bool
{
return $this->contains($otherRange->start) || $this->contains($otherRange->end)
|| $this->encompasses($otherRange)
|| $otherRange->encompasses($this);
} | php | public function overlaps(TimezonedDateTimeRange $otherRange) : bool
{
return $this->contains($otherRange->start) || $this->contains($otherRange->end)
|| $this->encompasses($otherRange)
|| $otherRange->encompasses($this);
} | [
"public",
"function",
"overlaps",
"(",
"TimezonedDateTimeRange",
"$",
"otherRange",
")",
":",
"bool",
"{",
"return",
"$",
"this",
"->",
"contains",
"(",
"$",
"otherRange",
"->",
"start",
")",
"||",
"$",
"this",
"->",
"contains",
"(",
"$",
"otherRange",
"->",
"end",
")",
"||",
"$",
"this",
"->",
"encompasses",
"(",
"$",
"otherRange",
")",
"||",
"$",
"otherRange",
"->",
"encompasses",
"(",
"$",
"this",
")",
";",
"}"
] | Returns whether the supplied timezoned date time range overlaps this date time range.
@param TimezonedDateTimeRange $otherRange
@return bool | [
"Returns",
"whether",
"the",
"supplied",
"timezoned",
"date",
"time",
"range",
"overlaps",
"this",
"date",
"time",
"range",
"."
] | 23f122182f60df5ec847047a81a39c8aab019ff1 | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/DateTime/TimezonedDateTimeRange.php#L105-L110 | train |
Raphhh/puppy-static-route | src/StaticModule.php | StaticModule.init | public function init(Application $application)
{
$application->addService('staticController', new StaticControllerService());
$application->any(':all', $application->getService('staticController'));
} | php | public function init(Application $application)
{
$application->addService('staticController', new StaticControllerService());
$application->any(':all', $application->getService('staticController'));
} | [
"public",
"function",
"init",
"(",
"Application",
"$",
"application",
")",
"{",
"$",
"application",
"->",
"addService",
"(",
"'staticController'",
",",
"new",
"StaticControllerService",
"(",
")",
")",
";",
"$",
"application",
"->",
"any",
"(",
"':all'",
",",
"$",
"application",
"->",
"getService",
"(",
"'staticController'",
")",
")",
";",
"}"
] | init the module.
@param Application $application | [
"init",
"the",
"module",
"."
] | 08d94ffdd9cc58fff1b0cae6982cc51b6e4ece5a | https://github.com/Raphhh/puppy-static-route/blob/08d94ffdd9cc58fff1b0cae6982cc51b6e4ece5a/src/StaticModule.php#L20-L24 | train |
inc2734/wp-page-speed-optimization | src/App/Controller/Assets.php | Assets._builded | public function _builded( $tag, $handle, $src ) {
$handles = apply_filters( 'inc2734_wp_page_speed_optimization_builded_scripts', [] );
if ( ! in_array( $handle, $handles ) ) {
return $tag;
}
return sprintf(
'<script>
document.addEventListener("DOMContentLoaded", function(event) {
var s=document.createElement("script");
s.src="%s";
s.async=true;document.body.appendChild(s);
});
</script>',
$src
);
} | php | public function _builded( $tag, $handle, $src ) {
$handles = apply_filters( 'inc2734_wp_page_speed_optimization_builded_scripts', [] );
if ( ! in_array( $handle, $handles ) ) {
return $tag;
}
return sprintf(
'<script>
document.addEventListener("DOMContentLoaded", function(event) {
var s=document.createElement("script");
s.src="%s";
s.async=true;document.body.appendChild(s);
});
</script>',
$src
);
} | [
"public",
"function",
"_builded",
"(",
"$",
"tag",
",",
"$",
"handle",
",",
"$",
"src",
")",
"{",
"$",
"handles",
"=",
"apply_filters",
"(",
"'inc2734_wp_page_speed_optimization_builded_scripts'",
",",
"[",
"]",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"handle",
",",
"$",
"handles",
")",
")",
"{",
"return",
"$",
"tag",
";",
"}",
"return",
"sprintf",
"(",
"'<script>\n\t\t\tdocument.addEventListener(\"DOMContentLoaded\", function(event) {\n\t\t\t\tvar s=document.createElement(\"script\");\n\t\t\t\ts.src=\"%s\";\n\t\t\t\ts.async=true;document.body.appendChild(s);\n\t\t\t});\n\t\t\t</script>'",
",",
"$",
"src",
")",
";",
"}"
] | Re-build script tag
only in_footer param is true
@param string $tag
@param string handle
@param string src
@return string | [
"Re",
"-",
"build",
"script",
"tag",
"only",
"in_footer",
"param",
"is",
"true"
] | 219963582b592eef4bde6cdd4ed1cf0dc71a6114 | https://github.com/inc2734/wp-page-speed-optimization/blob/219963582b592eef4bde6cdd4ed1cf0dc71a6114/src/App/Controller/Assets.php#L69-L86 | train |
inc2734/wp-page-speed-optimization | src/App/Controller/Assets.php | Assets._set_preload_stylesheet | public function _set_preload_stylesheet( $tag, $handle, $src ) {
$handles = apply_filters( 'inc2734_wp_page_speed_optimization_output_head_styles', [] );
if ( in_array( $handle, $handles ) && 0 === strpos( $src, site_url() ) ) {
$sitepath = site_url( '', 'relative' );
$abspath = untrailingslashit( ABSPATH );
if ( $sitepath ) {
$abspath = preg_replace( '|(.*?)' . preg_quote( $sitepath ) . '$|', '$1', $abspath );
}
$parse = parse_url( $src );
$buffer = \file_get_contents( $abspath . $parse['path'] );
$buffer = str_replace( 'url(../', 'url(' . dirname( $parse['path'] ) . '/../', $buffer );
$buffer = str_replace( 'url(//', 'url(/', $buffer );
// @codingStandardsIgnoreStart
?>
<style><?php echo $buffer; ?></style>
<?php
// @codingStandardsIgnoreEnd
return;
}
$handles = apply_filters( 'inc2734_wp_page_speed_optimization_preload_stylesheets', [] );
if ( in_array( $handle, $handles ) ) {
return str_replace( '\'stylesheet\'', '\'preload\' as="style"', $tag );
}
return $tag;
} | php | public function _set_preload_stylesheet( $tag, $handle, $src ) {
$handles = apply_filters( 'inc2734_wp_page_speed_optimization_output_head_styles', [] );
if ( in_array( $handle, $handles ) && 0 === strpos( $src, site_url() ) ) {
$sitepath = site_url( '', 'relative' );
$abspath = untrailingslashit( ABSPATH );
if ( $sitepath ) {
$abspath = preg_replace( '|(.*?)' . preg_quote( $sitepath ) . '$|', '$1', $abspath );
}
$parse = parse_url( $src );
$buffer = \file_get_contents( $abspath . $parse['path'] );
$buffer = str_replace( 'url(../', 'url(' . dirname( $parse['path'] ) . '/../', $buffer );
$buffer = str_replace( 'url(//', 'url(/', $buffer );
// @codingStandardsIgnoreStart
?>
<style><?php echo $buffer; ?></style>
<?php
// @codingStandardsIgnoreEnd
return;
}
$handles = apply_filters( 'inc2734_wp_page_speed_optimization_preload_stylesheets', [] );
if ( in_array( $handle, $handles ) ) {
return str_replace( '\'stylesheet\'', '\'preload\' as="style"', $tag );
}
return $tag;
} | [
"public",
"function",
"_set_preload_stylesheet",
"(",
"$",
"tag",
",",
"$",
"handle",
",",
"$",
"src",
")",
"{",
"$",
"handles",
"=",
"apply_filters",
"(",
"'inc2734_wp_page_speed_optimization_output_head_styles'",
",",
"[",
"]",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"handle",
",",
"$",
"handles",
")",
"&&",
"0",
"===",
"strpos",
"(",
"$",
"src",
",",
"site_url",
"(",
")",
")",
")",
"{",
"$",
"sitepath",
"=",
"site_url",
"(",
"''",
",",
"'relative'",
")",
";",
"$",
"abspath",
"=",
"untrailingslashit",
"(",
"ABSPATH",
")",
";",
"if",
"(",
"$",
"sitepath",
")",
"{",
"$",
"abspath",
"=",
"preg_replace",
"(",
"'|(.*?)'",
".",
"preg_quote",
"(",
"$",
"sitepath",
")",
".",
"'$|'",
",",
"'$1'",
",",
"$",
"abspath",
")",
";",
"}",
"$",
"parse",
"=",
"parse_url",
"(",
"$",
"src",
")",
";",
"$",
"buffer",
"=",
"\\",
"file_get_contents",
"(",
"$",
"abspath",
".",
"$",
"parse",
"[",
"'path'",
"]",
")",
";",
"$",
"buffer",
"=",
"str_replace",
"(",
"'url(../'",
",",
"'url('",
".",
"dirname",
"(",
"$",
"parse",
"[",
"'path'",
"]",
")",
".",
"'/../'",
",",
"$",
"buffer",
")",
";",
"$",
"buffer",
"=",
"str_replace",
"(",
"'url(//'",
",",
"'url(/'",
",",
"$",
"buffer",
")",
";",
"// @codingStandardsIgnoreStart",
"?>\n\t\t\t<style><?php",
"echo",
"$",
"buffer",
";",
"?></style>\n\t\t\t<?php",
"// @codingStandardsIgnoreEnd",
"return",
";",
"}",
"$",
"handles",
"=",
"apply_filters",
"(",
"'inc2734_wp_page_speed_optimization_preload_stylesheets'",
",",
"[",
"]",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"handle",
",",
"$",
"handles",
")",
")",
"{",
"return",
"str_replace",
"(",
"'\\'stylesheet\\''",
",",
"'\\'preload\\' as=\"style\"'",
",",
"$",
"tag",
")",
";",
"}",
"return",
"$",
"tag",
";",
"}"
] | Set rel="preload" for stylesheet
@param string $tag
@param string handle
@param string src
@return string | [
"Set",
"rel",
"=",
"preload",
"for",
"stylesheet"
] | 219963582b592eef4bde6cdd4ed1cf0dc71a6114 | https://github.com/inc2734/wp-page-speed-optimization/blob/219963582b592eef4bde6cdd4ed1cf0dc71a6114/src/App/Controller/Assets.php#L96-L124 | train |
inc2734/wp-page-speed-optimization | src/App/Controller/Assets.php | Assets._optimize_jquery_loading | public function _optimize_jquery_loading() {
$optimize_loading = apply_filters( 'inc2734_wp_page_speed_optimization_optimize_jquery_loading', false );
if ( ! $optimize_loading ) {
return;
}
if ( is_admin() || in_array( $GLOBALS['pagenow'], [ 'wp-login.php', 'wp-register.php' ] ) ) {
return;
}
global $wp_scripts;
$jquery = $wp_scripts->registered['jquery-core'];
$jquery_ver = $jquery->ver;
$jquery_src = $jquery->src;
wp_deregister_script( 'jquery' );
wp_deregister_script( 'jquery-core' );
wp_register_script( 'jquery', false, [ 'jquery-core' ], $jquery_ver, true );
wp_register_script( 'jquery-core', $jquery_src, [], $jquery_ver, true );
} | php | public function _optimize_jquery_loading() {
$optimize_loading = apply_filters( 'inc2734_wp_page_speed_optimization_optimize_jquery_loading', false );
if ( ! $optimize_loading ) {
return;
}
if ( is_admin() || in_array( $GLOBALS['pagenow'], [ 'wp-login.php', 'wp-register.php' ] ) ) {
return;
}
global $wp_scripts;
$jquery = $wp_scripts->registered['jquery-core'];
$jquery_ver = $jquery->ver;
$jquery_src = $jquery->src;
wp_deregister_script( 'jquery' );
wp_deregister_script( 'jquery-core' );
wp_register_script( 'jquery', false, [ 'jquery-core' ], $jquery_ver, true );
wp_register_script( 'jquery-core', $jquery_src, [], $jquery_ver, true );
} | [
"public",
"function",
"_optimize_jquery_loading",
"(",
")",
"{",
"$",
"optimize_loading",
"=",
"apply_filters",
"(",
"'inc2734_wp_page_speed_optimization_optimize_jquery_loading'",
",",
"false",
")",
";",
"if",
"(",
"!",
"$",
"optimize_loading",
")",
"{",
"return",
";",
"}",
"if",
"(",
"is_admin",
"(",
")",
"||",
"in_array",
"(",
"$",
"GLOBALS",
"[",
"'pagenow'",
"]",
",",
"[",
"'wp-login.php'",
",",
"'wp-register.php'",
"]",
")",
")",
"{",
"return",
";",
"}",
"global",
"$",
"wp_scripts",
";",
"$",
"jquery",
"=",
"$",
"wp_scripts",
"->",
"registered",
"[",
"'jquery-core'",
"]",
";",
"$",
"jquery_ver",
"=",
"$",
"jquery",
"->",
"ver",
";",
"$",
"jquery_src",
"=",
"$",
"jquery",
"->",
"src",
";",
"wp_deregister_script",
"(",
"'jquery'",
")",
";",
"wp_deregister_script",
"(",
"'jquery-core'",
")",
";",
"wp_register_script",
"(",
"'jquery'",
",",
"false",
",",
"[",
"'jquery-core'",
"]",
",",
"$",
"jquery_ver",
",",
"true",
")",
";",
"wp_register_script",
"(",
"'jquery-core'",
",",
"$",
"jquery_src",
",",
"[",
"]",
",",
"$",
"jquery_ver",
",",
"true",
")",
";",
"}"
] | Optimize jQuery loading
jQuery loads in footer and Invalidate jquery-migrate
@return void | [
"Optimize",
"jQuery",
"loading"
] | 219963582b592eef4bde6cdd4ed1cf0dc71a6114 | https://github.com/inc2734/wp-page-speed-optimization/blob/219963582b592eef4bde6cdd4ed1cf0dc71a6114/src/App/Controller/Assets.php#L161-L182 | train |
geega/php-simple-orm | src/Model.php | Model.find | static public function find($id)
{
$model = new static;
$result = $model->execute('SELECT * FROM '.$model->table.' WHERE '.$model->key.' = ?', [$id]);
if (is_array($result)) {
$result = current($result);
}
return $result;
} | php | static public function find($id)
{
$model = new static;
$result = $model->execute('SELECT * FROM '.$model->table.' WHERE '.$model->key.' = ?', [$id]);
if (is_array($result)) {
$result = current($result);
}
return $result;
} | [
"static",
"public",
"function",
"find",
"(",
"$",
"id",
")",
"{",
"$",
"model",
"=",
"new",
"static",
";",
"$",
"result",
"=",
"$",
"model",
"->",
"execute",
"(",
"'SELECT * FROM '",
".",
"$",
"model",
"->",
"table",
".",
"' WHERE '",
".",
"$",
"model",
"->",
"key",
".",
"' = ?'",
",",
"[",
"$",
"id",
"]",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"result",
")",
")",
"{",
"$",
"result",
"=",
"current",
"(",
"$",
"result",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Find record by pk
@param $id
@return array|mixed | [
"Find",
"record",
"by",
"pk"
] | 8ef636fd181c16ee3936d630d99e232c53883447 | https://github.com/geega/php-simple-orm/blob/8ef636fd181c16ee3936d630d99e232c53883447/src/Model.php#L60-L68 | train |
geega/php-simple-orm | src/Model.php | Model.findByQuery | static public function findByQuery($sqlQuery, array $params, $fetchMode = \PDO::FETCH_OBJ)
{
$model = new static;
if($model->table) {
$sqlQuery = str_replace(':table', $model->table, $sqlQuery);
}
$result = $model->execute($sqlQuery);
return $result;
} | php | static public function findByQuery($sqlQuery, array $params, $fetchMode = \PDO::FETCH_OBJ)
{
$model = new static;
if($model->table) {
$sqlQuery = str_replace(':table', $model->table, $sqlQuery);
}
$result = $model->execute($sqlQuery);
return $result;
} | [
"static",
"public",
"function",
"findByQuery",
"(",
"$",
"sqlQuery",
",",
"array",
"$",
"params",
",",
"$",
"fetchMode",
"=",
"\\",
"PDO",
"::",
"FETCH_OBJ",
")",
"{",
"$",
"model",
"=",
"new",
"static",
";",
"if",
"(",
"$",
"model",
"->",
"table",
")",
"{",
"$",
"sqlQuery",
"=",
"str_replace",
"(",
"':table'",
",",
"$",
"model",
"->",
"table",
",",
"$",
"sqlQuery",
")",
";",
"}",
"$",
"result",
"=",
"$",
"model",
"->",
"execute",
"(",
"$",
"sqlQuery",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Find by query
@param $sqlQuery
@param array $params
@param int $fetchMode
@return mixed | [
"Find",
"by",
"query"
] | 8ef636fd181c16ee3936d630d99e232c53883447 | https://github.com/geega/php-simple-orm/blob/8ef636fd181c16ee3936d630d99e232c53883447/src/Model.php#L96-L105 | train |
erenmustafaozdal/laravel-modules-base | src/Controllers/OperationNodeTrait.php | OperationNodeTrait.getNodes | protected function getNodes($class, $id)
{
$records = [];
$records['nodes'] = [];
$models = $this->getNodeModels($class, $id);
foreach ($models as $model) {
$records['nodes'][] = $this->getNodeValues($model);
}
return $records;
} | php | protected function getNodes($class, $id)
{
$records = [];
$records['nodes'] = [];
$models = $this->getNodeModels($class, $id);
foreach ($models as $model) {
$records['nodes'][] = $this->getNodeValues($model);
}
return $records;
} | [
"protected",
"function",
"getNodes",
"(",
"$",
"class",
",",
"$",
"id",
")",
"{",
"$",
"records",
"=",
"[",
"]",
";",
"$",
"records",
"[",
"'nodes'",
"]",
"=",
"[",
"]",
";",
"$",
"models",
"=",
"$",
"this",
"->",
"getNodeModels",
"(",
"$",
"class",
",",
"$",
"id",
")",
";",
"foreach",
"(",
"$",
"models",
"as",
"$",
"model",
")",
"{",
"$",
"records",
"[",
"'nodes'",
"]",
"[",
"]",
"=",
"$",
"this",
"->",
"getNodeValues",
"(",
"$",
"model",
")",
";",
"}",
"return",
"$",
"records",
";",
"}"
] | get nestable nodes
@param $class
@param integer|null $id
@return array | [
"get",
"nestable",
"nodes"
] | c26600543817642926bcf16ada84009e00d784e0 | https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Controllers/OperationNodeTrait.php#L38-L47 | train |
erenmustafaozdal/laravel-modules-base | src/Controllers/OperationNodeTrait.php | OperationNodeTrait.storeNode | protected function storeNode($class, $path = null, $id = null)
{
DB::beginTransaction();
try {
$datas = $this->request->parent != 0 || $this->request->related != 0 ? $this->getDefineDatas($class) : $this->request->all();
$this->model = $class::create($datas);
$this->model->setNode($class, $this->request);
// eğer başka ilişki varsa onları da ekle
if ($this->opsRelation && ! $this->fillModel($this->opsRelation)) {
throw new StoreException($this->request->all());
}
event(new $this->events['success']($this->model));
DB::commit();
if (is_null($path)) {
$attribute = "{$this->name}_uc_first";
return response()->json([
'id' => $this->model->id,
'name' => $this->model->$attribute
]);
}
Flash::success(trans('laravel-modules-base::admin.flash.store_success'));
return $this->redirectRoute($path);
} catch (StoreException $e) {
DB::rollback();
event(new $this->events['fail']($e->getDatas()));
if (is_null($path)) {
return response()->json($this->returnData('error'));
}
Flash::error(trans('laravel-modules-base::admin.flash.store_error'));
return $this->redirectRoute($path);
}
} | php | protected function storeNode($class, $path = null, $id = null)
{
DB::beginTransaction();
try {
$datas = $this->request->parent != 0 || $this->request->related != 0 ? $this->getDefineDatas($class) : $this->request->all();
$this->model = $class::create($datas);
$this->model->setNode($class, $this->request);
// eğer başka ilişki varsa onları da ekle
if ($this->opsRelation && ! $this->fillModel($this->opsRelation)) {
throw new StoreException($this->request->all());
}
event(new $this->events['success']($this->model));
DB::commit();
if (is_null($path)) {
$attribute = "{$this->name}_uc_first";
return response()->json([
'id' => $this->model->id,
'name' => $this->model->$attribute
]);
}
Flash::success(trans('laravel-modules-base::admin.flash.store_success'));
return $this->redirectRoute($path);
} catch (StoreException $e) {
DB::rollback();
event(new $this->events['fail']($e->getDatas()));
if (is_null($path)) {
return response()->json($this->returnData('error'));
}
Flash::error(trans('laravel-modules-base::admin.flash.store_error'));
return $this->redirectRoute($path);
}
} | [
"protected",
"function",
"storeNode",
"(",
"$",
"class",
",",
"$",
"path",
"=",
"null",
",",
"$",
"id",
"=",
"null",
")",
"{",
"DB",
"::",
"beginTransaction",
"(",
")",
";",
"try",
"{",
"$",
"datas",
"=",
"$",
"this",
"->",
"request",
"->",
"parent",
"!=",
"0",
"||",
"$",
"this",
"->",
"request",
"->",
"related",
"!=",
"0",
"?",
"$",
"this",
"->",
"getDefineDatas",
"(",
"$",
"class",
")",
":",
"$",
"this",
"->",
"request",
"->",
"all",
"(",
")",
";",
"$",
"this",
"->",
"model",
"=",
"$",
"class",
"::",
"create",
"(",
"$",
"datas",
")",
";",
"$",
"this",
"->",
"model",
"->",
"setNode",
"(",
"$",
"class",
",",
"$",
"this",
"->",
"request",
")",
";",
"// eğer başka ilişki varsa onları da ekle",
"if",
"(",
"$",
"this",
"->",
"opsRelation",
"&&",
"!",
"$",
"this",
"->",
"fillModel",
"(",
"$",
"this",
"->",
"opsRelation",
")",
")",
"{",
"throw",
"new",
"StoreException",
"(",
"$",
"this",
"->",
"request",
"->",
"all",
"(",
")",
")",
";",
"}",
"event",
"(",
"new",
"$",
"this",
"->",
"events",
"[",
"'success'",
"]",
"(",
"$",
"this",
"->",
"model",
")",
")",
";",
"DB",
"::",
"commit",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"path",
")",
")",
"{",
"$",
"attribute",
"=",
"\"{$this->name}_uc_first\"",
";",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"model",
"->",
"id",
",",
"'name'",
"=>",
"$",
"this",
"->",
"model",
"->",
"$",
"attribute",
"]",
")",
";",
"}",
"Flash",
"::",
"success",
"(",
"trans",
"(",
"'laravel-modules-base::admin.flash.store_success'",
")",
")",
";",
"return",
"$",
"this",
"->",
"redirectRoute",
"(",
"$",
"path",
")",
";",
"}",
"catch",
"(",
"StoreException",
"$",
"e",
")",
"{",
"DB",
"::",
"rollback",
"(",
")",
";",
"event",
"(",
"new",
"$",
"this",
"->",
"events",
"[",
"'fail'",
"]",
"(",
"$",
"e",
"->",
"getDatas",
"(",
")",
")",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"path",
")",
")",
"{",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"$",
"this",
"->",
"returnData",
"(",
"'error'",
")",
")",
";",
"}",
"Flash",
"::",
"error",
"(",
"trans",
"(",
"'laravel-modules-base::admin.flash.store_error'",
")",
")",
";",
"return",
"$",
"this",
"->",
"redirectRoute",
"(",
"$",
"path",
")",
";",
"}",
"}"
] | store nestable node
@param $class
@param string|null $path
@param integer|null $id
@throws StoreException
@return array | [
"store",
"nestable",
"node"
] | c26600543817642926bcf16ada84009e00d784e0 | https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Controllers/OperationNodeTrait.php#L58-L94 | train |
erenmustafaozdal/laravel-modules-base | src/Controllers/OperationNodeTrait.php | OperationNodeTrait.moveModel | protected function moveModel($model)
{
$this->model = $model;
DB::beginTransaction();
try {
if ($this->request->position === 'firstChild' || $this->request->position === 'lastChild') {
$this->model->fill($this->getDefineDatas($this->model))->save();
}
$this->model->setNode(get_class($this->model), $this->request, 'move');
// eğer başka ilişki varsa onları da ekle
if ($this->opsRelation && ! $this->fillModel($this->opsRelation)) {
throw new StoreException($this->request->all());
}
event(new $this->events['success']($this->model));
DB::commit();
$attribute = "{$this->name}_uc_first";
return response()->json([
'id' => $this->model->id,
'name' => $this->model->$attribute
]);
} catch (UpdateException $e) {
DB::rollback();
event(new $this->events['fail']($e->getDatas()));
return response()->json($this->returnData('error'));
}
} | php | protected function moveModel($model)
{
$this->model = $model;
DB::beginTransaction();
try {
if ($this->request->position === 'firstChild' || $this->request->position === 'lastChild') {
$this->model->fill($this->getDefineDatas($this->model))->save();
}
$this->model->setNode(get_class($this->model), $this->request, 'move');
// eğer başka ilişki varsa onları da ekle
if ($this->opsRelation && ! $this->fillModel($this->opsRelation)) {
throw new StoreException($this->request->all());
}
event(new $this->events['success']($this->model));
DB::commit();
$attribute = "{$this->name}_uc_first";
return response()->json([
'id' => $this->model->id,
'name' => $this->model->$attribute
]);
} catch (UpdateException $e) {
DB::rollback();
event(new $this->events['fail']($e->getDatas()));
return response()->json($this->returnData('error'));
}
} | [
"protected",
"function",
"moveModel",
"(",
"$",
"model",
")",
"{",
"$",
"this",
"->",
"model",
"=",
"$",
"model",
";",
"DB",
"::",
"beginTransaction",
"(",
")",
";",
"try",
"{",
"if",
"(",
"$",
"this",
"->",
"request",
"->",
"position",
"===",
"'firstChild'",
"||",
"$",
"this",
"->",
"request",
"->",
"position",
"===",
"'lastChild'",
")",
"{",
"$",
"this",
"->",
"model",
"->",
"fill",
"(",
"$",
"this",
"->",
"getDefineDatas",
"(",
"$",
"this",
"->",
"model",
")",
")",
"->",
"save",
"(",
")",
";",
"}",
"$",
"this",
"->",
"model",
"->",
"setNode",
"(",
"get_class",
"(",
"$",
"this",
"->",
"model",
")",
",",
"$",
"this",
"->",
"request",
",",
"'move'",
")",
";",
"// eğer başka ilişki varsa onları da ekle",
"if",
"(",
"$",
"this",
"->",
"opsRelation",
"&&",
"!",
"$",
"this",
"->",
"fillModel",
"(",
"$",
"this",
"->",
"opsRelation",
")",
")",
"{",
"throw",
"new",
"StoreException",
"(",
"$",
"this",
"->",
"request",
"->",
"all",
"(",
")",
")",
";",
"}",
"event",
"(",
"new",
"$",
"this",
"->",
"events",
"[",
"'success'",
"]",
"(",
"$",
"this",
"->",
"model",
")",
")",
";",
"DB",
"::",
"commit",
"(",
")",
";",
"$",
"attribute",
"=",
"\"{$this->name}_uc_first\"",
";",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"model",
"->",
"id",
",",
"'name'",
"=>",
"$",
"this",
"->",
"model",
"->",
"$",
"attribute",
"]",
")",
";",
"}",
"catch",
"(",
"UpdateException",
"$",
"e",
")",
"{",
"DB",
"::",
"rollback",
"(",
")",
";",
"event",
"(",
"new",
"$",
"this",
"->",
"events",
"[",
"'fail'",
"]",
"(",
"$",
"e",
"->",
"getDatas",
"(",
")",
")",
")",
";",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"$",
"this",
"->",
"returnData",
"(",
"'error'",
")",
")",
";",
"}",
"}"
] | move nestable node
@param $model
@throws StoreException
@return array | [
"move",
"nestable",
"node"
] | c26600543817642926bcf16ada84009e00d784e0 | https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Controllers/OperationNodeTrait.php#L103-L130 | train |
erenmustafaozdal/laravel-modules-base | src/Controllers/OperationNodeTrait.php | OperationNodeTrait.getNodeModels | private function getNodeModels($class, $relation_id)
{
if ($this->request->id === '0') {
return is_null($relation_id)
? $class::all()->toHierarchy()
: $class::where('parent_id',$relation_id)->get()->toHierarchy();
}
return $class::findOrFail($this->request->id)->descendants()->limitDepth(1)->get();
} | php | private function getNodeModels($class, $relation_id)
{
if ($this->request->id === '0') {
return is_null($relation_id)
? $class::all()->toHierarchy()
: $class::where('parent_id',$relation_id)->get()->toHierarchy();
}
return $class::findOrFail($this->request->id)->descendants()->limitDepth(1)->get();
} | [
"private",
"function",
"getNodeModels",
"(",
"$",
"class",
",",
"$",
"relation_id",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"request",
"->",
"id",
"===",
"'0'",
")",
"{",
"return",
"is_null",
"(",
"$",
"relation_id",
")",
"?",
"$",
"class",
"::",
"all",
"(",
")",
"->",
"toHierarchy",
"(",
")",
":",
"$",
"class",
"::",
"where",
"(",
"'parent_id'",
",",
"$",
"relation_id",
")",
"->",
"get",
"(",
")",
"->",
"toHierarchy",
"(",
")",
";",
"}",
"return",
"$",
"class",
"::",
"findOrFail",
"(",
"$",
"this",
"->",
"request",
"->",
"id",
")",
"->",
"descendants",
"(",
")",
"->",
"limitDepth",
"(",
"1",
")",
"->",
"get",
"(",
")",
";",
"}"
] | get node models
@param $class
@param integer $relation_id
@return \Illuminate\Database\Eloquent\Collection | [
"get",
"node",
"models"
] | c26600543817642926bcf16ada84009e00d784e0 | https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Controllers/OperationNodeTrait.php#L139-L148 | train |
erenmustafaozdal/laravel-modules-base | src/Controllers/OperationNodeTrait.php | OperationNodeTrait.getNodeValues | private function getNodeValues($model)
{
$attribute = "{$this->name}_uc_first";
return [
'id' => $model->id,
'parent' => $model->parent_id,
'name' => $model->$attribute,
'level' => $model->depth,
'type' => $model->isLeaf() ? 'file' : 'folder'
];
} | php | private function getNodeValues($model)
{
$attribute = "{$this->name}_uc_first";
return [
'id' => $model->id,
'parent' => $model->parent_id,
'name' => $model->$attribute,
'level' => $model->depth,
'type' => $model->isLeaf() ? 'file' : 'folder'
];
} | [
"private",
"function",
"getNodeValues",
"(",
"$",
"model",
")",
"{",
"$",
"attribute",
"=",
"\"{$this->name}_uc_first\"",
";",
"return",
"[",
"'id'",
"=>",
"$",
"model",
"->",
"id",
",",
"'parent'",
"=>",
"$",
"model",
"->",
"parent_id",
",",
"'name'",
"=>",
"$",
"model",
"->",
"$",
"attribute",
",",
"'level'",
"=>",
"$",
"model",
"->",
"depth",
",",
"'type'",
"=>",
"$",
"model",
"->",
"isLeaf",
"(",
")",
"?",
"'file'",
":",
"'folder'",
"]",
";",
"}"
] | get node values for return data
@param \Illuminate\Database\Eloquent\Model $model
@return array | [
"get",
"node",
"values",
"for",
"return",
"data"
] | c26600543817642926bcf16ada84009e00d784e0 | https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Controllers/OperationNodeTrait.php#L156-L166 | train |
erenmustafaozdal/laravel-modules-base | src/Controllers/OperationNodeTrait.php | OperationNodeTrait.getDefineDatas | protected function getDefineDatas($class)
{
$class = is_string($class) ? $class : get_class($class);
$id = $this->request->has('parent') && $this->request->parent != 0 ? $this->request->parent : $this->request->related;
$parent = $class::findOrFail($id);
$datas = $this->request->all();
foreach($this->defineValues as $value) {
$datas[$value] = $parent->$value;
}
return $datas;
} | php | protected function getDefineDatas($class)
{
$class = is_string($class) ? $class : get_class($class);
$id = $this->request->has('parent') && $this->request->parent != 0 ? $this->request->parent : $this->request->related;
$parent = $class::findOrFail($id);
$datas = $this->request->all();
foreach($this->defineValues as $value) {
$datas[$value] = $parent->$value;
}
return $datas;
} | [
"protected",
"function",
"getDefineDatas",
"(",
"$",
"class",
")",
"{",
"$",
"class",
"=",
"is_string",
"(",
"$",
"class",
")",
"?",
"$",
"class",
":",
"get_class",
"(",
"$",
"class",
")",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"request",
"->",
"has",
"(",
"'parent'",
")",
"&&",
"$",
"this",
"->",
"request",
"->",
"parent",
"!=",
"0",
"?",
"$",
"this",
"->",
"request",
"->",
"parent",
":",
"$",
"this",
"->",
"request",
"->",
"related",
";",
"$",
"parent",
"=",
"$",
"class",
"::",
"findOrFail",
"(",
"$",
"id",
")",
";",
"$",
"datas",
"=",
"$",
"this",
"->",
"request",
"->",
"all",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"defineValues",
"as",
"$",
"value",
")",
"{",
"$",
"datas",
"[",
"$",
"value",
"]",
"=",
"$",
"parent",
"->",
"$",
"value",
";",
"}",
"return",
"$",
"datas",
";",
"}"
] | get the define datas
@param $class
@return array | [
"get",
"the",
"define",
"datas"
] | c26600543817642926bcf16ada84009e00d784e0 | https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Controllers/OperationNodeTrait.php#L185-L195 | train |
ContaoBlackForest/contao-doctrine-orm-timestampable | src/Timestampable/Bridge.php | Bridge.duplicateEntity | public static function duplicateEntity(DuplicateEntity $event)
{
if ($event->getWithoutKeys()) {
$entity = $event->getEntity();
if (isset($GLOBALS['TL_DCA'][$entity->entityTableName()]['fields'])) {
/** @var EntityAccessor $entityAccessor */
$entityAccessor = $GLOBALS['container']['doctrine.orm.entityAccessor'];
$fields = (array) $GLOBALS['TL_DCA'][$entity->entityTableName()]['fields'];
foreach ($fields as $field => $fieldConfig) {
if (isset($fieldConfig['field']['timestampable'])) {
$entityAccessor->setRawProperty($entity, $field, null);
}
}
}
}
} | php | public static function duplicateEntity(DuplicateEntity $event)
{
if ($event->getWithoutKeys()) {
$entity = $event->getEntity();
if (isset($GLOBALS['TL_DCA'][$entity->entityTableName()]['fields'])) {
/** @var EntityAccessor $entityAccessor */
$entityAccessor = $GLOBALS['container']['doctrine.orm.entityAccessor'];
$fields = (array) $GLOBALS['TL_DCA'][$entity->entityTableName()]['fields'];
foreach ($fields as $field => $fieldConfig) {
if (isset($fieldConfig['field']['timestampable'])) {
$entityAccessor->setRawProperty($entity, $field, null);
}
}
}
}
} | [
"public",
"static",
"function",
"duplicateEntity",
"(",
"DuplicateEntity",
"$",
"event",
")",
"{",
"if",
"(",
"$",
"event",
"->",
"getWithoutKeys",
"(",
")",
")",
"{",
"$",
"entity",
"=",
"$",
"event",
"->",
"getEntity",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"GLOBALS",
"[",
"'TL_DCA'",
"]",
"[",
"$",
"entity",
"->",
"entityTableName",
"(",
")",
"]",
"[",
"'fields'",
"]",
")",
")",
"{",
"/** @var EntityAccessor $entityAccessor */",
"$",
"entityAccessor",
"=",
"$",
"GLOBALS",
"[",
"'container'",
"]",
"[",
"'doctrine.orm.entityAccessor'",
"]",
";",
"$",
"fields",
"=",
"(",
"array",
")",
"$",
"GLOBALS",
"[",
"'TL_DCA'",
"]",
"[",
"$",
"entity",
"->",
"entityTableName",
"(",
")",
"]",
"[",
"'fields'",
"]",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
"=>",
"$",
"fieldConfig",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"fieldConfig",
"[",
"'field'",
"]",
"[",
"'timestampable'",
"]",
")",
")",
"{",
"$",
"entityAccessor",
"->",
"setRawProperty",
"(",
"$",
"entity",
",",
"$",
"field",
",",
"null",
")",
";",
"}",
"}",
"}",
"}",
"}"
] | Clean timestamp able entries from duplicated entities.
@param DuplicateEntity $event The event.
@return void
@SuppressWarnings(PHPMD.Superglobals) | [
"Clean",
"timestamp",
"able",
"entries",
"from",
"duplicated",
"entities",
"."
] | 5322a2a4325dfbc4091c9a8ead010f882da13007 | https://github.com/ContaoBlackForest/contao-doctrine-orm-timestampable/blob/5322a2a4325dfbc4091c9a8ead010f882da13007/src/Timestampable/Bridge.php#L56-L73 | train |
itkg/core | src/Itkg/Core/EntityAbstract.php | EntityAbstract.setDataForSubEntitiy | private function setDataForSubEntitiy($propertyKey, $value)
{
$subKey = strtolower(strstr($propertyKey, '_', true));
$getterMethodName = 'get' . ucfirst($subKey);
if (!empty($subKey) && method_exists($this, $getterMethodName)) {
$subObject = $this->$getterMethodName();
// If we managed to get sub object, set his data
if ($subObject instanceof EntityAbstract) {
$subObject->setDataFromArray(
array($propertyKey => $value)
);
}
}
} | php | private function setDataForSubEntitiy($propertyKey, $value)
{
$subKey = strtolower(strstr($propertyKey, '_', true));
$getterMethodName = 'get' . ucfirst($subKey);
if (!empty($subKey) && method_exists($this, $getterMethodName)) {
$subObject = $this->$getterMethodName();
// If we managed to get sub object, set his data
if ($subObject instanceof EntityAbstract) {
$subObject->setDataFromArray(
array($propertyKey => $value)
);
}
}
} | [
"private",
"function",
"setDataForSubEntitiy",
"(",
"$",
"propertyKey",
",",
"$",
"value",
")",
"{",
"$",
"subKey",
"=",
"strtolower",
"(",
"strstr",
"(",
"$",
"propertyKey",
",",
"'_'",
",",
"true",
")",
")",
";",
"$",
"getterMethodName",
"=",
"'get'",
".",
"ucfirst",
"(",
"$",
"subKey",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"subKey",
")",
"&&",
"method_exists",
"(",
"$",
"this",
",",
"$",
"getterMethodName",
")",
")",
"{",
"$",
"subObject",
"=",
"$",
"this",
"->",
"$",
"getterMethodName",
"(",
")",
";",
"// If we managed to get sub object, set his data",
"if",
"(",
"$",
"subObject",
"instanceof",
"EntityAbstract",
")",
"{",
"$",
"subObject",
"->",
"setDataFromArray",
"(",
"array",
"(",
"$",
"propertyKey",
"=>",
"$",
"value",
")",
")",
";",
"}",
"}",
"}"
] | Process sub entity to set data recursively
@param string $propertyKey
@param mixed $value
@return void | [
"Process",
"sub",
"entity",
"to",
"set",
"data",
"recursively"
] | e5e4efb05feb4d23b0df41f2b21fd095103e593b | https://github.com/itkg/core/blob/e5e4efb05feb4d23b0df41f2b21fd095103e593b/src/Itkg/Core/EntityAbstract.php#L129-L144 | train |
itkg/core | src/Itkg/Core/EntityAbstract.php | EntityAbstract.getPropertyValue | protected function getPropertyValue($propertyName)
{
$desiredKey = $this->trimPrefixKey($propertyName);
$getter = 'get' . ucfirst($this->getPropertyName($desiredKey));
if (method_exists($this, $getter)) {
return $this->$getter();
}
// Otherwise, try to get sub object to get data
$subKey = strtolower(strstr($desiredKey, '_', true));
$getterMethodName = 'get' . ucfirst($subKey);
$subObject = $this->$getterMethodName();
if ($subObject instanceof EntityAbstract) {
return $subObject->getPropertyValue($desiredKey);
}
throw new \InvalidArgumentException(
sprintf(
'No getter set for %s (getter was %s:%s)',
$propertyName,
get_called_class(),
$getter
)
);
} | php | protected function getPropertyValue($propertyName)
{
$desiredKey = $this->trimPrefixKey($propertyName);
$getter = 'get' . ucfirst($this->getPropertyName($desiredKey));
if (method_exists($this, $getter)) {
return $this->$getter();
}
// Otherwise, try to get sub object to get data
$subKey = strtolower(strstr($desiredKey, '_', true));
$getterMethodName = 'get' . ucfirst($subKey);
$subObject = $this->$getterMethodName();
if ($subObject instanceof EntityAbstract) {
return $subObject->getPropertyValue($desiredKey);
}
throw new \InvalidArgumentException(
sprintf(
'No getter set for %s (getter was %s:%s)',
$propertyName,
get_called_class(),
$getter
)
);
} | [
"protected",
"function",
"getPropertyValue",
"(",
"$",
"propertyName",
")",
"{",
"$",
"desiredKey",
"=",
"$",
"this",
"->",
"trimPrefixKey",
"(",
"$",
"propertyName",
")",
";",
"$",
"getter",
"=",
"'get'",
".",
"ucfirst",
"(",
"$",
"this",
"->",
"getPropertyName",
"(",
"$",
"desiredKey",
")",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"getter",
")",
")",
"{",
"return",
"$",
"this",
"->",
"$",
"getter",
"(",
")",
";",
"}",
"// Otherwise, try to get sub object to get data",
"$",
"subKey",
"=",
"strtolower",
"(",
"strstr",
"(",
"$",
"desiredKey",
",",
"'_'",
",",
"true",
")",
")",
";",
"$",
"getterMethodName",
"=",
"'get'",
".",
"ucfirst",
"(",
"$",
"subKey",
")",
";",
"$",
"subObject",
"=",
"$",
"this",
"->",
"$",
"getterMethodName",
"(",
")",
";",
"if",
"(",
"$",
"subObject",
"instanceof",
"EntityAbstract",
")",
"{",
"return",
"$",
"subObject",
"->",
"getPropertyValue",
"(",
"$",
"desiredKey",
")",
";",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'No getter set for %s (getter was %s:%s)'",
",",
"$",
"propertyName",
",",
"get_called_class",
"(",
")",
",",
"$",
"getter",
")",
")",
";",
"}"
] | Get method name for getter
@param string $propertyName
@throws \InvalidArgumentException
@return string | [
"Get",
"method",
"name",
"for",
"getter"
] | e5e4efb05feb4d23b0df41f2b21fd095103e593b | https://github.com/itkg/core/blob/e5e4efb05feb4d23b0df41f2b21fd095103e593b/src/Itkg/Core/EntityAbstract.php#L216-L242 | train |
itkg/core | src/Itkg/Core/EntityAbstract.php | EntityAbstract.getDataForCache | public function getDataForCache()
{
$reflectionClass = new \ReflectionObject($this);
$array = array();
$excludes = array_flip($this->excludedPropertiesForCache);
$excludes['excludedPropertiesForCache'] = true;
foreach ($reflectionClass->getProperties() as $property) {
$propertyName = $property->getName();
if (!isset($excludes[$propertyName])
&& null !== $value = $this->processPropertyForCache($propertyName)) {
$array[$propertyName] = $value;
}
}
return $this->encodeDataForCache($array);
} | php | public function getDataForCache()
{
$reflectionClass = new \ReflectionObject($this);
$array = array();
$excludes = array_flip($this->excludedPropertiesForCache);
$excludes['excludedPropertiesForCache'] = true;
foreach ($reflectionClass->getProperties() as $property) {
$propertyName = $property->getName();
if (!isset($excludes[$propertyName])
&& null !== $value = $this->processPropertyForCache($propertyName)) {
$array[$propertyName] = $value;
}
}
return $this->encodeDataForCache($array);
} | [
"public",
"function",
"getDataForCache",
"(",
")",
"{",
"$",
"reflectionClass",
"=",
"new",
"\\",
"ReflectionObject",
"(",
"$",
"this",
")",
";",
"$",
"array",
"=",
"array",
"(",
")",
";",
"$",
"excludes",
"=",
"array_flip",
"(",
"$",
"this",
"->",
"excludedPropertiesForCache",
")",
";",
"$",
"excludes",
"[",
"'excludedPropertiesForCache'",
"]",
"=",
"true",
";",
"foreach",
"(",
"$",
"reflectionClass",
"->",
"getProperties",
"(",
")",
"as",
"$",
"property",
")",
"{",
"$",
"propertyName",
"=",
"$",
"property",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"excludes",
"[",
"$",
"propertyName",
"]",
")",
"&&",
"null",
"!==",
"$",
"value",
"=",
"$",
"this",
"->",
"processPropertyForCache",
"(",
"$",
"propertyName",
")",
")",
"{",
"$",
"array",
"[",
"$",
"propertyName",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"encodeDataForCache",
"(",
"$",
"array",
")",
";",
"}"
] | Get data from entity for cache set
@return mixed | [
"Get",
"data",
"from",
"entity",
"for",
"cache",
"set"
] | e5e4efb05feb4d23b0df41f2b21fd095103e593b | https://github.com/itkg/core/blob/e5e4efb05feb4d23b0df41f2b21fd095103e593b/src/Itkg/Core/EntityAbstract.php#L270-L285 | train |
itkg/core | src/Itkg/Core/EntityAbstract.php | EntityAbstract.processPropertyForCache | protected function processPropertyForCache($propertyName)
{
$value = $this->$propertyName;
if ($value instanceof CacheableInterface) {
$value = $value->getDataForCache();
} elseif (is_object($value)) {
$value = null;
}
return $value;
} | php | protected function processPropertyForCache($propertyName)
{
$value = $this->$propertyName;
if ($value instanceof CacheableInterface) {
$value = $value->getDataForCache();
} elseif (is_object($value)) {
$value = null;
}
return $value;
} | [
"protected",
"function",
"processPropertyForCache",
"(",
"$",
"propertyName",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"$",
"propertyName",
";",
"if",
"(",
"$",
"value",
"instanceof",
"CacheableInterface",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"->",
"getDataForCache",
"(",
")",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"null",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Process a property to get data for caching flow
@param string $propertyName
@return mixed|null | [
"Process",
"a",
"property",
"to",
"get",
"data",
"for",
"caching",
"flow"
] | e5e4efb05feb4d23b0df41f2b21fd095103e593b | https://github.com/itkg/core/blob/e5e4efb05feb4d23b0df41f2b21fd095103e593b/src/Itkg/Core/EntityAbstract.php#L316-L327 | train |
wb-crowdfusion/crowdfusion | system/core/classes/mvc/controllers/NodeCliController.php | NodeCliController.deleteAll | protected function deleteAll()
{
$elements = $this->Request->getRequiredParameter('elements');
$interval = 1000;
$elementSlugs = StringUtils::smartExplode($elements);
$elements = array();
foreach($elementSlugs as $eSlug)
$elements[] = $this->ElementService->getBySlug($eSlug);
foreach($elements as $element)
{
$offset = 0;
if($this->Request->getParameter('offset') != null)
$offset = $this->Request->getParameter('offset');
echo 'Deleting nodes for element: '.$element."\n";
while(true)
{
$count = 0;
// commit any pending transactions and begin new one
$this->TransactionManager->commit()->begin();
$nq = new NodeQuery();
$nq->setParameter('NodeRefs.only', true);
$nq->setParameter('Elements.in', $element->getSlug());
$nq->setLimit($interval);
$nq->setOffset($offset);
$nq = $this->NodeService->findAll($nq, true);
$nodeRefs = $nq->getResults();
$tCount = $nq->getTotalRecords();
if(empty($nodeRefs))
break;
foreach($nodeRefs as $nodeRef)
{
try {
$this->NodeService->delete($nodeRef);
echo ($count+1).". ".$nodeRef->getSlug()." deleted\n";
if(($count+1) % 10 == 0) {
$this->TransactionManager->commit()->begin();
echo "commit\n";
}
} catch(Exception $e) {
echo "Exception caught: ".$e->getMessage()."\n";
// if an error occurs, bail - we don't want to get stuck in a
// loop if we can't delete stuff for some reason
echo "Exiting, please correct problem and re-run\n";
return;
}
++$count;
}
echo 'Deleted '.$count.' of '.$tCount.' '.$element->getSlug()." nodes.\n";
}
}
} | php | protected function deleteAll()
{
$elements = $this->Request->getRequiredParameter('elements');
$interval = 1000;
$elementSlugs = StringUtils::smartExplode($elements);
$elements = array();
foreach($elementSlugs as $eSlug)
$elements[] = $this->ElementService->getBySlug($eSlug);
foreach($elements as $element)
{
$offset = 0;
if($this->Request->getParameter('offset') != null)
$offset = $this->Request->getParameter('offset');
echo 'Deleting nodes for element: '.$element."\n";
while(true)
{
$count = 0;
// commit any pending transactions and begin new one
$this->TransactionManager->commit()->begin();
$nq = new NodeQuery();
$nq->setParameter('NodeRefs.only', true);
$nq->setParameter('Elements.in', $element->getSlug());
$nq->setLimit($interval);
$nq->setOffset($offset);
$nq = $this->NodeService->findAll($nq, true);
$nodeRefs = $nq->getResults();
$tCount = $nq->getTotalRecords();
if(empty($nodeRefs))
break;
foreach($nodeRefs as $nodeRef)
{
try {
$this->NodeService->delete($nodeRef);
echo ($count+1).". ".$nodeRef->getSlug()." deleted\n";
if(($count+1) % 10 == 0) {
$this->TransactionManager->commit()->begin();
echo "commit\n";
}
} catch(Exception $e) {
echo "Exception caught: ".$e->getMessage()."\n";
// if an error occurs, bail - we don't want to get stuck in a
// loop if we can't delete stuff for some reason
echo "Exiting, please correct problem and re-run\n";
return;
}
++$count;
}
echo 'Deleted '.$count.' of '.$tCount.' '.$element->getSlug()." nodes.\n";
}
}
} | [
"protected",
"function",
"deleteAll",
"(",
")",
"{",
"$",
"elements",
"=",
"$",
"this",
"->",
"Request",
"->",
"getRequiredParameter",
"(",
"'elements'",
")",
";",
"$",
"interval",
"=",
"1000",
";",
"$",
"elementSlugs",
"=",
"StringUtils",
"::",
"smartExplode",
"(",
"$",
"elements",
")",
";",
"$",
"elements",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"elementSlugs",
"as",
"$",
"eSlug",
")",
"$",
"elements",
"[",
"]",
"=",
"$",
"this",
"->",
"ElementService",
"->",
"getBySlug",
"(",
"$",
"eSlug",
")",
";",
"foreach",
"(",
"$",
"elements",
"as",
"$",
"element",
")",
"{",
"$",
"offset",
"=",
"0",
";",
"if",
"(",
"$",
"this",
"->",
"Request",
"->",
"getParameter",
"(",
"'offset'",
")",
"!=",
"null",
")",
"$",
"offset",
"=",
"$",
"this",
"->",
"Request",
"->",
"getParameter",
"(",
"'offset'",
")",
";",
"echo",
"'Deleting nodes for element: '",
".",
"$",
"element",
".",
"\"\\n\"",
";",
"while",
"(",
"true",
")",
"{",
"$",
"count",
"=",
"0",
";",
"// commit any pending transactions and begin new one",
"$",
"this",
"->",
"TransactionManager",
"->",
"commit",
"(",
")",
"->",
"begin",
"(",
")",
";",
"$",
"nq",
"=",
"new",
"NodeQuery",
"(",
")",
";",
"$",
"nq",
"->",
"setParameter",
"(",
"'NodeRefs.only'",
",",
"true",
")",
";",
"$",
"nq",
"->",
"setParameter",
"(",
"'Elements.in'",
",",
"$",
"element",
"->",
"getSlug",
"(",
")",
")",
";",
"$",
"nq",
"->",
"setLimit",
"(",
"$",
"interval",
")",
";",
"$",
"nq",
"->",
"setOffset",
"(",
"$",
"offset",
")",
";",
"$",
"nq",
"=",
"$",
"this",
"->",
"NodeService",
"->",
"findAll",
"(",
"$",
"nq",
",",
"true",
")",
";",
"$",
"nodeRefs",
"=",
"$",
"nq",
"->",
"getResults",
"(",
")",
";",
"$",
"tCount",
"=",
"$",
"nq",
"->",
"getTotalRecords",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"nodeRefs",
")",
")",
"break",
";",
"foreach",
"(",
"$",
"nodeRefs",
"as",
"$",
"nodeRef",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"NodeService",
"->",
"delete",
"(",
"$",
"nodeRef",
")",
";",
"echo",
"(",
"$",
"count",
"+",
"1",
")",
".",
"\". \"",
".",
"$",
"nodeRef",
"->",
"getSlug",
"(",
")",
".",
"\" deleted\\n\"",
";",
"if",
"(",
"(",
"$",
"count",
"+",
"1",
")",
"%",
"10",
"==",
"0",
")",
"{",
"$",
"this",
"->",
"TransactionManager",
"->",
"commit",
"(",
")",
"->",
"begin",
"(",
")",
";",
"echo",
"\"commit\\n\"",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"echo",
"\"Exception caught: \"",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
".",
"\"\\n\"",
";",
"// if an error occurs, bail - we don't want to get stuck in a",
"// loop if we can't delete stuff for some reason",
"echo",
"\"Exiting, please correct problem and re-run\\n\"",
";",
"return",
";",
"}",
"++",
"$",
"count",
";",
"}",
"echo",
"'Deleted '",
".",
"$",
"count",
".",
"' of '",
".",
"$",
"tCount",
".",
"' '",
".",
"$",
"element",
"->",
"getSlug",
"(",
")",
".",
"\" nodes.\\n\"",
";",
"}",
"}",
"}"
] | Deletes all nodes for specified elements.
@param elements A comma delimited list of the elements to delete nodes in
@param offset An integer value for the offset to begin deleting nodes from
@return void | [
"Deletes",
"all",
"nodes",
"for",
"specified",
"elements",
"."
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/controllers/NodeCliController.php#L404-L467 | train |
fridge-project/dbal | src/Fridge/DBAL/Schema/Sequence.php | Sequence.setInitialValue | public function setInitialValue($initialValue)
{
if (!is_int($initialValue) || ($initialValue <= 0)) {
throw SchemaException::invalidSequenceInitialValue($this->getName());
}
$this->initialValue = $initialValue;
} | php | public function setInitialValue($initialValue)
{
if (!is_int($initialValue) || ($initialValue <= 0)) {
throw SchemaException::invalidSequenceInitialValue($this->getName());
}
$this->initialValue = $initialValue;
} | [
"public",
"function",
"setInitialValue",
"(",
"$",
"initialValue",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"initialValue",
")",
"||",
"(",
"$",
"initialValue",
"<=",
"0",
")",
")",
"{",
"throw",
"SchemaException",
"::",
"invalidSequenceInitialValue",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"initialValue",
"=",
"$",
"initialValue",
";",
"}"
] | Sets the initial value.
@param integer $initialValue The initial value.
@throws \Fridge\DBAL\Exception\SchemaException If the initial value is not a positive integer. | [
"Sets",
"the",
"initial",
"value",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/Sequence.php#L61-L68 | train |
fridge-project/dbal | src/Fridge/DBAL/Schema/Sequence.php | Sequence.setIncrementSize | public function setIncrementSize($incrementSize)
{
if (!is_int($incrementSize) || ($incrementSize <= 0)) {
throw SchemaException::invalidSequenceIncrementSize($this->getName());
}
$this->incrementSize = $incrementSize;
} | php | public function setIncrementSize($incrementSize)
{
if (!is_int($incrementSize) || ($incrementSize <= 0)) {
throw SchemaException::invalidSequenceIncrementSize($this->getName());
}
$this->incrementSize = $incrementSize;
} | [
"public",
"function",
"setIncrementSize",
"(",
"$",
"incrementSize",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"incrementSize",
")",
"||",
"(",
"$",
"incrementSize",
"<=",
"0",
")",
")",
"{",
"throw",
"SchemaException",
"::",
"invalidSequenceIncrementSize",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"incrementSize",
"=",
"$",
"incrementSize",
";",
"}"
] | Sets the increment size.
@param integer $incrementSize The increment size.
@throws \Fridge\DBAL\Exception\SchemaException If the increment size is not a positive integer. | [
"Sets",
"the",
"increment",
"size",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/Sequence.php#L87-L94 | train |
CalderaWP/caldera-interop | src/Traits/CollectsModels.php | CollectsModels.addItem | public function addItem(Model $item) : Collection
{
call_user_func([$this,$this->setterName()], $item);
return $this;
} | php | public function addItem(Model $item) : Collection
{
call_user_func([$this,$this->setterName()], $item);
return $this;
} | [
"public",
"function",
"addItem",
"(",
"Model",
"$",
"item",
")",
":",
"Collection",
"{",
"call_user_func",
"(",
"[",
"$",
"this",
",",
"$",
"this",
"->",
"setterName",
"(",
")",
"]",
",",
"$",
"item",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add item to collection
@param Model $item
@return Collection | [
"Add",
"item",
"to",
"collection"
] | d25c4bc930200b314fbd42d084080b5d85261c94 | https://github.com/CalderaWP/caldera-interop/blob/d25c4bc930200b314fbd42d084080b5d85261c94/src/Traits/CollectsModels.php#L27-L31 | train |
CalderaWP/caldera-interop | src/Traits/CollectsModels.php | CollectsModels.removeItem | public function removeItem(Model $item) : Collection
{
if ($this->has($item->getId())) {
unset($this->items[$item->getId()]);
}
return $this;
} | php | public function removeItem(Model $item) : Collection
{
if ($this->has($item->getId())) {
unset($this->items[$item->getId()]);
}
return $this;
} | [
"public",
"function",
"removeItem",
"(",
"Model",
"$",
"item",
")",
":",
"Collection",
"{",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"$",
"item",
"->",
"getId",
"(",
")",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"item",
"->",
"getId",
"(",
")",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Remove an item from collection
@param Model $item
@return Collection | [
"Remove",
"an",
"item",
"from",
"collection"
] | d25c4bc930200b314fbd42d084080b5d85261c94 | https://github.com/CalderaWP/caldera-interop/blob/d25c4bc930200b314fbd42d084080b5d85261c94/src/Traits/CollectsModels.php#L56-L63 | train |
CalderaWP/caldera-interop | src/Traits/CollectsModels.php | CollectsModels.toArray | public function toArray() : array
{
$items= is_array($this->items)? $this->items : [];
foreach ($items as $itemIndex => $item) {
if (is_object($item)&& is_callable([$item,'toArray'])) {
try {
$items[ $itemIndex ] = $item->toArray();
} catch (\Exception $e) {
throw $e;
}
}
}
return $items;
} | php | public function toArray() : array
{
$items= is_array($this->items)? $this->items : [];
foreach ($items as $itemIndex => $item) {
if (is_object($item)&& is_callable([$item,'toArray'])) {
try {
$items[ $itemIndex ] = $item->toArray();
} catch (\Exception $e) {
throw $e;
}
}
}
return $items;
} | [
"public",
"function",
"toArray",
"(",
")",
":",
"array",
"{",
"$",
"items",
"=",
"is_array",
"(",
"$",
"this",
"->",
"items",
")",
"?",
"$",
"this",
"->",
"items",
":",
"[",
"]",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"itemIndex",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"item",
")",
"&&",
"is_callable",
"(",
"[",
"$",
"item",
",",
"'toArray'",
"]",
")",
")",
"{",
"try",
"{",
"$",
"items",
"[",
"$",
"itemIndex",
"]",
"=",
"$",
"item",
"->",
"toArray",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"}",
"}",
"return",
"$",
"items",
";",
"}"
] | Get items in collection
@return array | [
"Get",
"items",
"in",
"collection"
] | d25c4bc930200b314fbd42d084080b5d85261c94 | https://github.com/CalderaWP/caldera-interop/blob/d25c4bc930200b314fbd42d084080b5d85261c94/src/Traits/CollectsModels.php#L70-L83 | train |
JamesMcAvoy/PsrRouter | src/Route.php | Route.call | public function call(Request $request, Response $response) : Response {
return call_user_func($this->callable, $request, $response, $this->slugs);
} | php | public function call(Request $request, Response $response) : Response {
return call_user_func($this->callable, $request, $response, $this->slugs);
} | [
"public",
"function",
"call",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
")",
":",
"Response",
"{",
"return",
"call_user_func",
"(",
"$",
"this",
"->",
"callable",
",",
"$",
"request",
",",
"$",
"response",
",",
"$",
"this",
"->",
"slugs",
")",
";",
"}"
] | Call the callback function of the route
@param RequestInterface
@param ResponseInterface
@return mixed | [
"Call",
"the",
"callback",
"function",
"of",
"the",
"route"
] | 00a3e15f8d1f87aef0eadde1074bea2179cd53fe | https://github.com/JamesMcAvoy/PsrRouter/blob/00a3e15f8d1f87aef0eadde1074bea2179cd53fe/src/Route.php#L95-L99 | train |
kambalabs/KmbPuppetDb | src/KmbPuppetDb/Request.php | Request.getFullUri | public function getFullUri()
{
$queryString = '';
$params = array();
if ($this->hasQuery()) {
$params[] = $this->getQueryParam();
}
if ($this->hasOrderBy()) {
$params[] = $this->getOrderByParam();
}
if ($this->hasSummarizeBy()) {
$params[] = 'summarize-by=' . $this->getSummarizeBy();
}
if ($this->hasOffset()) {
$params[] = 'offset=' . $this->getOffset();
}
if ($this->hasLimit()) {
$params[] = 'limit=' . $this->getLimit();
}
if ($this->hasIncludeTotal()) {
$params[] = 'include-total=' . $this->getIncludeTotalAsString();
}
if (!empty($params)) {
$queryString = '?' . implode('&', $params);
}
return '/' . ltrim($this->getUri(), '/') . $queryString;
} | php | public function getFullUri()
{
$queryString = '';
$params = array();
if ($this->hasQuery()) {
$params[] = $this->getQueryParam();
}
if ($this->hasOrderBy()) {
$params[] = $this->getOrderByParam();
}
if ($this->hasSummarizeBy()) {
$params[] = 'summarize-by=' . $this->getSummarizeBy();
}
if ($this->hasOffset()) {
$params[] = 'offset=' . $this->getOffset();
}
if ($this->hasLimit()) {
$params[] = 'limit=' . $this->getLimit();
}
if ($this->hasIncludeTotal()) {
$params[] = 'include-total=' . $this->getIncludeTotalAsString();
}
if (!empty($params)) {
$queryString = '?' . implode('&', $params);
}
return '/' . ltrim($this->getUri(), '/') . $queryString;
} | [
"public",
"function",
"getFullUri",
"(",
")",
"{",
"$",
"queryString",
"=",
"''",
";",
"$",
"params",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasQuery",
"(",
")",
")",
"{",
"$",
"params",
"[",
"]",
"=",
"$",
"this",
"->",
"getQueryParam",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"hasOrderBy",
"(",
")",
")",
"{",
"$",
"params",
"[",
"]",
"=",
"$",
"this",
"->",
"getOrderByParam",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"hasSummarizeBy",
"(",
")",
")",
"{",
"$",
"params",
"[",
"]",
"=",
"'summarize-by='",
".",
"$",
"this",
"->",
"getSummarizeBy",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"hasOffset",
"(",
")",
")",
"{",
"$",
"params",
"[",
"]",
"=",
"'offset='",
".",
"$",
"this",
"->",
"getOffset",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"hasLimit",
"(",
")",
")",
"{",
"$",
"params",
"[",
"]",
"=",
"'limit='",
".",
"$",
"this",
"->",
"getLimit",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"hasIncludeTotal",
"(",
")",
")",
"{",
"$",
"params",
"[",
"]",
"=",
"'include-total='",
".",
"$",
"this",
"->",
"getIncludeTotalAsString",
"(",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"params",
")",
")",
"{",
"$",
"queryString",
"=",
"'?'",
".",
"implode",
"(",
"'&'",
",",
"$",
"params",
")",
";",
"}",
"return",
"'/'",
".",
"ltrim",
"(",
"$",
"this",
"->",
"getUri",
"(",
")",
",",
"'/'",
")",
".",
"$",
"queryString",
";",
"}"
] | Get full constructed URI.
@return string | [
"Get",
"full",
"constructed",
"URI",
"."
] | df56a275cf00f4402cf121a2e99149168f1f8b2d | https://github.com/kambalabs/KmbPuppetDb/blob/df56a275cf00f4402cf121a2e99149168f1f8b2d/src/KmbPuppetDb/Request.php#L70-L104 | train |
Wedeto/Util | src/DI/Injector.php | Injector.getInstance | public function getInstance(string $class, string $selector = Injector::DEFAULT_SELECTOR)
{
if (array_search($class, $this->instance_stack, true))
throw new DIException("Cyclic dependencies in creating $class: " . WF::str($this->instance_stack));
array_push($this->instance_stack, $class);
try
{
if (!isset($this->objects[$class]) || !isset($this->objects[$class][$selector]))
{
if ($selector === Injector::SHARED_SELECTOR)
throw new DIException("Refusing to instantiate shared instance");
if (isset($this->objects[$class][Injector::SHARED_SELECTOR]))
{
$instance = $this->objects[$class][Injector::SHARED_SELECTOR];
}
else
{
$instance = $this->newInstance($class, ['wdiSelector' => $selector]);
$nclass = get_class($instance);
$const_name = $nclass . '::WDI_REUSABLE';
if (defined($const_name) && constant($const_name) === true)
$this->setInstance($class, $instance, $selector);
}
}
else
{
$instance = $this->objects[$class][$selector];
}
}
finally
{
$top = array_pop($this->instance_stack);
if ($class !== $top)
{
// @codeCoverageIgnoreStart
throw new DIException("Unexpected class at top of stack: expected $class, found $top");
// @codeCoverageIgnoreEnd
}
}
return $instance;
} | php | public function getInstance(string $class, string $selector = Injector::DEFAULT_SELECTOR)
{
if (array_search($class, $this->instance_stack, true))
throw new DIException("Cyclic dependencies in creating $class: " . WF::str($this->instance_stack));
array_push($this->instance_stack, $class);
try
{
if (!isset($this->objects[$class]) || !isset($this->objects[$class][$selector]))
{
if ($selector === Injector::SHARED_SELECTOR)
throw new DIException("Refusing to instantiate shared instance");
if (isset($this->objects[$class][Injector::SHARED_SELECTOR]))
{
$instance = $this->objects[$class][Injector::SHARED_SELECTOR];
}
else
{
$instance = $this->newInstance($class, ['wdiSelector' => $selector]);
$nclass = get_class($instance);
$const_name = $nclass . '::WDI_REUSABLE';
if (defined($const_name) && constant($const_name) === true)
$this->setInstance($class, $instance, $selector);
}
}
else
{
$instance = $this->objects[$class][$selector];
}
}
finally
{
$top = array_pop($this->instance_stack);
if ($class !== $top)
{
// @codeCoverageIgnoreStart
throw new DIException("Unexpected class at top of stack: expected $class, found $top");
// @codeCoverageIgnoreEnd
}
}
return $instance;
} | [
"public",
"function",
"getInstance",
"(",
"string",
"$",
"class",
",",
"string",
"$",
"selector",
"=",
"Injector",
"::",
"DEFAULT_SELECTOR",
")",
"{",
"if",
"(",
"array_search",
"(",
"$",
"class",
",",
"$",
"this",
"->",
"instance_stack",
",",
"true",
")",
")",
"throw",
"new",
"DIException",
"(",
"\"Cyclic dependencies in creating $class: \"",
".",
"WF",
"::",
"str",
"(",
"$",
"this",
"->",
"instance_stack",
")",
")",
";",
"array_push",
"(",
"$",
"this",
"->",
"instance_stack",
",",
"$",
"class",
")",
";",
"try",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"objects",
"[",
"$",
"class",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"this",
"->",
"objects",
"[",
"$",
"class",
"]",
"[",
"$",
"selector",
"]",
")",
")",
"{",
"if",
"(",
"$",
"selector",
"===",
"Injector",
"::",
"SHARED_SELECTOR",
")",
"throw",
"new",
"DIException",
"(",
"\"Refusing to instantiate shared instance\"",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"objects",
"[",
"$",
"class",
"]",
"[",
"Injector",
"::",
"SHARED_SELECTOR",
"]",
")",
")",
"{",
"$",
"instance",
"=",
"$",
"this",
"->",
"objects",
"[",
"$",
"class",
"]",
"[",
"Injector",
"::",
"SHARED_SELECTOR",
"]",
";",
"}",
"else",
"{",
"$",
"instance",
"=",
"$",
"this",
"->",
"newInstance",
"(",
"$",
"class",
",",
"[",
"'wdiSelector'",
"=>",
"$",
"selector",
"]",
")",
";",
"$",
"nclass",
"=",
"get_class",
"(",
"$",
"instance",
")",
";",
"$",
"const_name",
"=",
"$",
"nclass",
".",
"'::WDI_REUSABLE'",
";",
"if",
"(",
"defined",
"(",
"$",
"const_name",
")",
"&&",
"constant",
"(",
"$",
"const_name",
")",
"===",
"true",
")",
"$",
"this",
"->",
"setInstance",
"(",
"$",
"class",
",",
"$",
"instance",
",",
"$",
"selector",
")",
";",
"}",
"}",
"else",
"{",
"$",
"instance",
"=",
"$",
"this",
"->",
"objects",
"[",
"$",
"class",
"]",
"[",
"$",
"selector",
"]",
";",
"}",
"}",
"finally",
"{",
"$",
"top",
"=",
"array_pop",
"(",
"$",
"this",
"->",
"instance_stack",
")",
";",
"if",
"(",
"$",
"class",
"!==",
"$",
"top",
")",
"{",
"// @codeCoverageIgnoreStart",
"throw",
"new",
"DIException",
"(",
"\"Unexpected class at top of stack: expected $class, found $top\"",
")",
";",
"// @codeCoverageIgnoreEnd",
"}",
"}",
"return",
"$",
"instance",
";",
"}"
] | Get an instance of the object
@param string $class The class to get an instance of
@param string $selector Where multiple instances may exist, they can be categorized by a selector
@return Object an instance of the class | [
"Get",
"an",
"instance",
"of",
"the",
"object"
] | 0e080251bbaa8e7d91ae8d02eb79c029c976744a | https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/DI/Injector.php#L77-L120 | train |
Wedeto/Util | src/DI/Injector.php | Injector.hasInstance | public function hasInstance(string $class, string $selector = Injector::DEFAULT_SELECTOR)
{
return isset($this->objects[$class][$selector]);
} | php | public function hasInstance(string $class, string $selector = Injector::DEFAULT_SELECTOR)
{
return isset($this->objects[$class][$selector]);
} | [
"public",
"function",
"hasInstance",
"(",
"string",
"$",
"class",
",",
"string",
"$",
"selector",
"=",
"Injector",
"::",
"DEFAULT_SELECTOR",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"objects",
"[",
"$",
"class",
"]",
"[",
"$",
"selector",
"]",
")",
";",
"}"
] | Check if an instance for the class is available.
@param string $class The class to check for an instance
@param string $selector The selector to use to find an instance. Defaults to DEFAULT_SELECTOR
@return bool True if an instance is available, false if not | [
"Check",
"if",
"an",
"instance",
"for",
"the",
"class",
"is",
"available",
"."
] | 0e080251bbaa8e7d91ae8d02eb79c029c976744a | https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/DI/Injector.php#L129-L132 | train |
Wedeto/Util | src/DI/Injector.php | Injector.registerFactory | public function registerFactory(string $produced_class, Factory $factory)
{
$this->factories[$produced_class] = $factory;
return $this;
} | php | public function registerFactory(string $produced_class, Factory $factory)
{
$this->factories[$produced_class] = $factory;
return $this;
} | [
"public",
"function",
"registerFactory",
"(",
"string",
"$",
"produced_class",
",",
"Factory",
"$",
"factory",
")",
"{",
"$",
"this",
"->",
"factories",
"[",
"$",
"produced_class",
"]",
"=",
"$",
"factory",
";",
"return",
"$",
"this",
";",
"}"
] | Register a factory for a class name
@param string $produced_class The class produced by the factory
@param Wedeto\Util\DI\Factory $factory The factory to register
@return $this Provides fluent interface | [
"Register",
"a",
"factory",
"for",
"a",
"class",
"name"
] | 0e080251bbaa8e7d91ae8d02eb79c029c976744a | https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/DI/Injector.php#L161-L165 | train |
Wedeto/Util | src/DI/Injector.php | Injector.setInstance | public function setInstance(string $class, $instance, string $selector = Injector::DEFAULT_SELECTOR)
{
if (!is_a($instance, $class))
throw new DIException("Instance should be a subclass of $class");
if (!isset($this->objects[$class]))
$this->objects[$class] = [];
$this->objects[$class][$selector] = $instance;
} | php | public function setInstance(string $class, $instance, string $selector = Injector::DEFAULT_SELECTOR)
{
if (!is_a($instance, $class))
throw new DIException("Instance should be a subclass of $class");
if (!isset($this->objects[$class]))
$this->objects[$class] = [];
$this->objects[$class][$selector] = $instance;
} | [
"public",
"function",
"setInstance",
"(",
"string",
"$",
"class",
",",
"$",
"instance",
",",
"string",
"$",
"selector",
"=",
"Injector",
"::",
"DEFAULT_SELECTOR",
")",
"{",
"if",
"(",
"!",
"is_a",
"(",
"$",
"instance",
",",
"$",
"class",
")",
")",
"throw",
"new",
"DIException",
"(",
"\"Instance should be a subclass of $class\"",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"objects",
"[",
"$",
"class",
"]",
")",
")",
"$",
"this",
"->",
"objects",
"[",
"$",
"class",
"]",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"objects",
"[",
"$",
"class",
"]",
"[",
"$",
"selector",
"]",
"=",
"$",
"instance",
";",
"}"
] | Set a specific instance of class
@param string $class The name of the class
@param string $selector Where multiple instances may exist, they can be caterogized by a selector
@param object $instance The instance to set for this class | [
"Set",
"a",
"specific",
"instance",
"of",
"class"
] | 0e080251bbaa8e7d91ae8d02eb79c029c976744a | https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/DI/Injector.php#L174-L183 | train |
Wedeto/Util | src/DI/Injector.php | Injector.clearInstance | public function clearInstance(string $class, string $selector = Injector::DEFAULT_SELECTOR)
{
if (!isset($this->objects[$class]))
return;
unset($this->objects[$class][$selector]);
} | php | public function clearInstance(string $class, string $selector = Injector::DEFAULT_SELECTOR)
{
if (!isset($this->objects[$class]))
return;
unset($this->objects[$class][$selector]);
} | [
"public",
"function",
"clearInstance",
"(",
"string",
"$",
"class",
",",
"string",
"$",
"selector",
"=",
"Injector",
"::",
"DEFAULT_SELECTOR",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"objects",
"[",
"$",
"class",
"]",
")",
")",
"return",
";",
"unset",
"(",
"$",
"this",
"->",
"objects",
"[",
"$",
"class",
"]",
"[",
"$",
"selector",
"]",
")",
";",
"}"
] | Remove an instance from the repository
@param string $class The name of the class
@param string $selector The selector to clear | [
"Remove",
"an",
"instance",
"from",
"the",
"repository"
] | 0e080251bbaa8e7d91ae8d02eb79c029c976744a | https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/DI/Injector.php#L190-L196 | train |
shrink0r/php-schema | src/Property/BoolProperty.php | BoolProperty.validate | public function validate($value)
{
return is_bool($value) ? Ok::unit() : Error::unit([ Error::NON_BOOL ]);
} | php | public function validate($value)
{
return is_bool($value) ? Ok::unit() : Error::unit([ Error::NON_BOOL ]);
} | [
"public",
"function",
"validate",
"(",
"$",
"value",
")",
"{",
"return",
"is_bool",
"(",
"$",
"value",
")",
"?",
"Ok",
"::",
"unit",
"(",
")",
":",
"Error",
"::",
"unit",
"(",
"[",
"Error",
"::",
"NON_BOOL",
"]",
")",
";",
"}"
] | Tells if a given value is a valid bool.
@param mixed $value
@return ResultInterface Returns Ok if the value is valid, otherwise an Error is returned. | [
"Tells",
"if",
"a",
"given",
"value",
"is",
"a",
"valid",
"bool",
"."
] | 94293fe897af376dd9d05962e2c516079409dd29 | https://github.com/shrink0r/php-schema/blob/94293fe897af376dd9d05962e2c516079409dd29/src/Property/BoolProperty.php#L18-L21 | train |
oziks/XHProfServiceProvider | src/Oziks/Lib/XHProfRun.php | XHProfRun.end | public function end()
{
if (!extension_loaded('xhprof')) {
throw new Exception("XHProf extension is not loaded.", 1);
}
if ($this->started) {
$this->data = xhprof_disable();
require_once(sprintf('%s/xhprof_lib/utils/xhprof_runs.php', $this->dir));
$xhprof_runs = new XHProfRuns_Default(ini_get("xhprof.output_dir"));
$this->id = $xhprof_runs->save_run($this->data, $this->namespace);
}
return $this->started;
} | php | public function end()
{
if (!extension_loaded('xhprof')) {
throw new Exception("XHProf extension is not loaded.", 1);
}
if ($this->started) {
$this->data = xhprof_disable();
require_once(sprintf('%s/xhprof_lib/utils/xhprof_runs.php', $this->dir));
$xhprof_runs = new XHProfRuns_Default(ini_get("xhprof.output_dir"));
$this->id = $xhprof_runs->save_run($this->data, $this->namespace);
}
return $this->started;
} | [
"public",
"function",
"end",
"(",
")",
"{",
"if",
"(",
"!",
"extension_loaded",
"(",
"'xhprof'",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"XHProf extension is not loaded.\"",
",",
"1",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"started",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"xhprof_disable",
"(",
")",
";",
"require_once",
"(",
"sprintf",
"(",
"'%s/xhprof_lib/utils/xhprof_runs.php'",
",",
"$",
"this",
"->",
"dir",
")",
")",
";",
"$",
"xhprof_runs",
"=",
"new",
"XHProfRuns_Default",
"(",
"ini_get",
"(",
"\"xhprof.output_dir\"",
")",
")",
";",
"$",
"this",
"->",
"id",
"=",
"$",
"xhprof_runs",
"->",
"save_run",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"this",
"->",
"namespace",
")",
";",
"}",
"return",
"$",
"this",
"->",
"started",
";",
"}"
] | Triggers the end of the run
@return boolean True if the run is started before call end method | [
"Triggers",
"the",
"end",
"of",
"the",
"run"
] | 2b262b242bb29a5627c5a9f61545a10035414ae7 | https://github.com/oziks/XHProfServiceProvider/blob/2b262b242bb29a5627c5a9f61545a10035414ae7/src/Oziks/Lib/XHProfRun.php#L66-L81 | train |
oziks/XHProfServiceProvider | src/Oziks/Lib/XHProfRun.php | XHProfRun.getReport | public function getReport($id = null)
{
if ($id === null) {
$id = $this->id;
}
return array('runId' => $id, 'report' => sprintf('%s?run=%s&source=%s', $this->host, $id, $this->namespace));
} | php | public function getReport($id = null)
{
if ($id === null) {
$id = $this->id;
}
return array('runId' => $id, 'report' => sprintf('%s?run=%s&source=%s', $this->host, $id, $this->namespace));
} | [
"public",
"function",
"getReport",
"(",
"$",
"id",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"id",
"===",
"null",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"id",
";",
"}",
"return",
"array",
"(",
"'runId'",
"=>",
"$",
"id",
",",
"'report'",
"=>",
"sprintf",
"(",
"'%s?run=%s&source=%s'",
",",
"$",
"this",
"->",
"host",
",",
"$",
"id",
",",
"$",
"this",
"->",
"namespace",
")",
")",
";",
"}"
] | Gets the current report.
@return array The current report | [
"Gets",
"the",
"current",
"report",
"."
] | 2b262b242bb29a5627c5a9f61545a10035414ae7 | https://github.com/oziks/XHProfServiceProvider/blob/2b262b242bb29a5627c5a9f61545a10035414ae7/src/Oziks/Lib/XHProfRun.php#L88-L95 | train |
oziks/XHProfServiceProvider | src/Oziks/Lib/XHProfRun.php | XHProfRun.getReports | public function getReports()
{
$reports = array();
$dir = ini_get("xhprof.output_dir");
if (is_dir($dir)) {
$finder = new Finder();
$finder
->files()
->name('*.'.$this->namespace)
->notName($this->id.'.'.$this->namespace)
->in($dir)
->sort(function (SplFileInfo $a, SplFileInfo $b) {
return strcmp($b->getRealpath(), $a->getRealpath());
})
;
foreach ($finder as $runFile) {
$infos = explode('.', basename($runFile));
$runId = array_shift($infos);
$reports[] = $this->getReport($runId);
if (count($reports) > 5) {
break;
}
}
}
return $reports;
} | php | public function getReports()
{
$reports = array();
$dir = ini_get("xhprof.output_dir");
if (is_dir($dir)) {
$finder = new Finder();
$finder
->files()
->name('*.'.$this->namespace)
->notName($this->id.'.'.$this->namespace)
->in($dir)
->sort(function (SplFileInfo $a, SplFileInfo $b) {
return strcmp($b->getRealpath(), $a->getRealpath());
})
;
foreach ($finder as $runFile) {
$infos = explode('.', basename($runFile));
$runId = array_shift($infos);
$reports[] = $this->getReport($runId);
if (count($reports) > 5) {
break;
}
}
}
return $reports;
} | [
"public",
"function",
"getReports",
"(",
")",
"{",
"$",
"reports",
"=",
"array",
"(",
")",
";",
"$",
"dir",
"=",
"ini_get",
"(",
"\"xhprof.output_dir\"",
")",
";",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"finder",
"=",
"new",
"Finder",
"(",
")",
";",
"$",
"finder",
"->",
"files",
"(",
")",
"->",
"name",
"(",
"'*.'",
".",
"$",
"this",
"->",
"namespace",
")",
"->",
"notName",
"(",
"$",
"this",
"->",
"id",
".",
"'.'",
".",
"$",
"this",
"->",
"namespace",
")",
"->",
"in",
"(",
"$",
"dir",
")",
"->",
"sort",
"(",
"function",
"(",
"SplFileInfo",
"$",
"a",
",",
"SplFileInfo",
"$",
"b",
")",
"{",
"return",
"strcmp",
"(",
"$",
"b",
"->",
"getRealpath",
"(",
")",
",",
"$",
"a",
"->",
"getRealpath",
"(",
")",
")",
";",
"}",
")",
";",
"foreach",
"(",
"$",
"finder",
"as",
"$",
"runFile",
")",
"{",
"$",
"infos",
"=",
"explode",
"(",
"'.'",
",",
"basename",
"(",
"$",
"runFile",
")",
")",
";",
"$",
"runId",
"=",
"array_shift",
"(",
"$",
"infos",
")",
";",
"$",
"reports",
"[",
"]",
"=",
"$",
"this",
"->",
"getReport",
"(",
"$",
"runId",
")",
";",
"if",
"(",
"count",
"(",
"$",
"reports",
")",
">",
"5",
")",
"{",
"break",
";",
"}",
"}",
"}",
"return",
"$",
"reports",
";",
"}"
] | Gets the last reports.
@return array The last reports | [
"Gets",
"the",
"last",
"reports",
"."
] | 2b262b242bb29a5627c5a9f61545a10035414ae7 | https://github.com/oziks/XHProfServiceProvider/blob/2b262b242bb29a5627c5a9f61545a10035414ae7/src/Oziks/Lib/XHProfRun.php#L102-L132 | train |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Expression/Operand/Path.php | Path.funcCondition | private function funcCondition($name, $arg = null)
{
$this->getExpr()->addCondition(new ConditionFunc(
$name,
$this,
$arg !== null ? $this->getExpr()->value($arg) : null
));
return $this->getExpr();
} | php | private function funcCondition($name, $arg = null)
{
$this->getExpr()->addCondition(new ConditionFunc(
$name,
$this,
$arg !== null ? $this->getExpr()->value($arg) : null
));
return $this->getExpr();
} | [
"private",
"function",
"funcCondition",
"(",
"$",
"name",
",",
"$",
"arg",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"getExpr",
"(",
")",
"->",
"addCondition",
"(",
"new",
"ConditionFunc",
"(",
"$",
"name",
",",
"$",
"this",
",",
"$",
"arg",
"!==",
"null",
"?",
"$",
"this",
"->",
"getExpr",
"(",
")",
"->",
"value",
"(",
"$",
"arg",
")",
":",
"null",
")",
")",
";",
"return",
"$",
"this",
"->",
"getExpr",
"(",
")",
";",
"}"
] | Add a function call to the current expression.
@param string $name
@param string|null $arg
@return QueryBuilder|Expr | [
"Add",
"a",
"function",
"call",
"to",
"the",
"current",
"expression",
"."
] | 119d355e2c5cbaef1f867970349b4432f5704fcd | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Expression/Operand/Path.php#L84-L93 | train |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Expression/Operand/Path.php | Path.prime | public function prime($primer = true)
{
if (!is_bool($primer) && !is_callable($primer)) {
throw new \InvalidArgumentException('$primer is not a boolean or callable');
}
if ($primer === false) {
unset($this->getExpr()->qb->primers[$this->getExpression()]);
return $this;
}
$this->getExpr()->qb->primers[$this->getDotSyntax()] = $primer;
return $this;
} | php | public function prime($primer = true)
{
if (!is_bool($primer) && !is_callable($primer)) {
throw new \InvalidArgumentException('$primer is not a boolean or callable');
}
if ($primer === false) {
unset($this->getExpr()->qb->primers[$this->getExpression()]);
return $this;
}
$this->getExpr()->qb->primers[$this->getDotSyntax()] = $primer;
return $this;
} | [
"public",
"function",
"prime",
"(",
"$",
"primer",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"is_bool",
"(",
"$",
"primer",
")",
"&&",
"!",
"is_callable",
"(",
"$",
"primer",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'$primer is not a boolean or callable'",
")",
";",
"}",
"if",
"(",
"$",
"primer",
"===",
"false",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"getExpr",
"(",
")",
"->",
"qb",
"->",
"primers",
"[",
"$",
"this",
"->",
"getExpression",
"(",
")",
"]",
")",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"getExpr",
"(",
")",
"->",
"qb",
"->",
"primers",
"[",
"$",
"this",
"->",
"getDotSyntax",
"(",
")",
"]",
"=",
"$",
"primer",
";",
"return",
"$",
"this",
";",
"}"
] | Use a primer to eagerly load all references in this path segment.
If $primer is true or a callable is provided, referenced documents for
this attribute will loaded into UnitOfWork immediately after the query is
executed. This will avoid multiple queries due to lazy initialization of
Proxy objects.
If $primer is false, no priming will take place. That is also the default
behavior.
If a custom callable is used, its signature should conform to the default
Closure defined in {@link ReferencePrimer::__construct()}.
@param bool|callable $primer
@return $this
@throws \InvalidArgumentException If $primer is not boolean or callable. | [
"Use",
"a",
"primer",
"to",
"eagerly",
"load",
"all",
"references",
"in",
"this",
"path",
"segment",
"."
] | 119d355e2c5cbaef1f867970349b4432f5704fcd | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Expression/Operand/Path.php#L242-L257 | train |
anime-db/catalog-bundle | src/Controller/RefillController.php | RefillController.refillAction | public function refillAction($plugin, $field, Request $request)
{
/* @var $refiller RefillerInterface */
if (!($refiller = $this->get('anime_db.plugin.refiller')->getPlugin($plugin))) {
throw $this->createNotFoundException('Plugin \''.$plugin.'\' is not found');
}
$item = $this->createForm('entity_item', new Item())
->handleRequest($request)
->getData();
$form = $this->getForm($field, clone $item, $refiller->refill($item, $field));
return $this->render('AnimeDbCatalogBundle:Refill:refill.html.twig', [
'field' => $field,
'form' => $form->createView(),
]);
} | php | public function refillAction($plugin, $field, Request $request)
{
/* @var $refiller RefillerInterface */
if (!($refiller = $this->get('anime_db.plugin.refiller')->getPlugin($plugin))) {
throw $this->createNotFoundException('Plugin \''.$plugin.'\' is not found');
}
$item = $this->createForm('entity_item', new Item())
->handleRequest($request)
->getData();
$form = $this->getForm($field, clone $item, $refiller->refill($item, $field));
return $this->render('AnimeDbCatalogBundle:Refill:refill.html.twig', [
'field' => $field,
'form' => $form->createView(),
]);
} | [
"public",
"function",
"refillAction",
"(",
"$",
"plugin",
",",
"$",
"field",
",",
"Request",
"$",
"request",
")",
"{",
"/* @var $refiller RefillerInterface */",
"if",
"(",
"!",
"(",
"$",
"refiller",
"=",
"$",
"this",
"->",
"get",
"(",
"'anime_db.plugin.refiller'",
")",
"->",
"getPlugin",
"(",
"$",
"plugin",
")",
")",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
"'Plugin \\''",
".",
"$",
"plugin",
".",
"'\\' is not found'",
")",
";",
"}",
"$",
"item",
"=",
"$",
"this",
"->",
"createForm",
"(",
"'entity_item'",
",",
"new",
"Item",
"(",
")",
")",
"->",
"handleRequest",
"(",
"$",
"request",
")",
"->",
"getData",
"(",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"getForm",
"(",
"$",
"field",
",",
"clone",
"$",
"item",
",",
"$",
"refiller",
"->",
"refill",
"(",
"$",
"item",
",",
"$",
"field",
")",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'AnimeDbCatalogBundle:Refill:refill.html.twig'",
",",
"[",
"'field'",
"=>",
"$",
"field",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
"]",
")",
";",
"}"
] | Refill item.
@param string $plugin
@param string $field
@param Request $request
@return Response | [
"Refill",
"item",
"."
] | 631b6f92a654e91bee84f46218c52cf42bdb8606 | https://github.com/anime-db/catalog-bundle/blob/631b6f92a654e91bee84f46218c52cf42bdb8606/src/Controller/RefillController.php#L47-L63 | train |
anime-db/catalog-bundle | src/Controller/RefillController.php | RefillController.searchAction | public function searchAction($plugin, $field, Request $request)
{
/* @var $refiller RefillerInterface */
if (!($refiller = $this->get('anime_db.plugin.refiller')->getPlugin($plugin))) {
throw $this->createNotFoundException('Plugin \''.$plugin.'\' is not found');
}
$item = $this->createForm('entity_item', new Item())
->handleRequest($request)
->getData();
$result = [];
if ($refiller->isCanSearch($item, $field)) {
$result = $refiller->search($item, $field);
/* @var $search_item ItemRefiller */
foreach ($result as $key => $search_item) {
$result[$key] = [
'name' => $search_item->getName(),
'image' => $search_item->getImage(),
'description' => $search_item->getDescription(),
'source' => $search_item->getSource(),
'link' => $this->generateUrl('refiller_search_fill', [
'plugin' => $plugin,
'field' => $field,
'id' => $item->getId(),
'data' => $search_item->getData(),
'source' => $search_item->getSource(),
]),
];
}
}
return $this->render('AnimeDbCatalogBundle:Refill:search.html.twig', [
'result' => $result,
]);
} | php | public function searchAction($plugin, $field, Request $request)
{
/* @var $refiller RefillerInterface */
if (!($refiller = $this->get('anime_db.plugin.refiller')->getPlugin($plugin))) {
throw $this->createNotFoundException('Plugin \''.$plugin.'\' is not found');
}
$item = $this->createForm('entity_item', new Item())
->handleRequest($request)
->getData();
$result = [];
if ($refiller->isCanSearch($item, $field)) {
$result = $refiller->search($item, $field);
/* @var $search_item ItemRefiller */
foreach ($result as $key => $search_item) {
$result[$key] = [
'name' => $search_item->getName(),
'image' => $search_item->getImage(),
'description' => $search_item->getDescription(),
'source' => $search_item->getSource(),
'link' => $this->generateUrl('refiller_search_fill', [
'plugin' => $plugin,
'field' => $field,
'id' => $item->getId(),
'data' => $search_item->getData(),
'source' => $search_item->getSource(),
]),
];
}
}
return $this->render('AnimeDbCatalogBundle:Refill:search.html.twig', [
'result' => $result,
]);
} | [
"public",
"function",
"searchAction",
"(",
"$",
"plugin",
",",
"$",
"field",
",",
"Request",
"$",
"request",
")",
"{",
"/* @var $refiller RefillerInterface */",
"if",
"(",
"!",
"(",
"$",
"refiller",
"=",
"$",
"this",
"->",
"get",
"(",
"'anime_db.plugin.refiller'",
")",
"->",
"getPlugin",
"(",
"$",
"plugin",
")",
")",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
"'Plugin \\''",
".",
"$",
"plugin",
".",
"'\\' is not found'",
")",
";",
"}",
"$",
"item",
"=",
"$",
"this",
"->",
"createForm",
"(",
"'entity_item'",
",",
"new",
"Item",
"(",
")",
")",
"->",
"handleRequest",
"(",
"$",
"request",
")",
"->",
"getData",
"(",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"refiller",
"->",
"isCanSearch",
"(",
"$",
"item",
",",
"$",
"field",
")",
")",
"{",
"$",
"result",
"=",
"$",
"refiller",
"->",
"search",
"(",
"$",
"item",
",",
"$",
"field",
")",
";",
"/* @var $search_item ItemRefiller */",
"foreach",
"(",
"$",
"result",
"as",
"$",
"key",
"=>",
"$",
"search_item",
")",
"{",
"$",
"result",
"[",
"$",
"key",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"search_item",
"->",
"getName",
"(",
")",
",",
"'image'",
"=>",
"$",
"search_item",
"->",
"getImage",
"(",
")",
",",
"'description'",
"=>",
"$",
"search_item",
"->",
"getDescription",
"(",
")",
",",
"'source'",
"=>",
"$",
"search_item",
"->",
"getSource",
"(",
")",
",",
"'link'",
"=>",
"$",
"this",
"->",
"generateUrl",
"(",
"'refiller_search_fill'",
",",
"[",
"'plugin'",
"=>",
"$",
"plugin",
",",
"'field'",
"=>",
"$",
"field",
",",
"'id'",
"=>",
"$",
"item",
"->",
"getId",
"(",
")",
",",
"'data'",
"=>",
"$",
"search_item",
"->",
"getData",
"(",
")",
",",
"'source'",
"=>",
"$",
"search_item",
"->",
"getSource",
"(",
")",
",",
"]",
")",
",",
"]",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'AnimeDbCatalogBundle:Refill:search.html.twig'",
",",
"[",
"'result'",
"=>",
"$",
"result",
",",
"]",
")",
";",
"}"
] | Search for refill.
@param string $plugin
@param string $field
@param Request $request
@return Response | [
"Search",
"for",
"refill",
"."
] | 631b6f92a654e91bee84f46218c52cf42bdb8606 | https://github.com/anime-db/catalog-bundle/blob/631b6f92a654e91bee84f46218c52cf42bdb8606/src/Controller/RefillController.php#L74-L108 | train |
mekras/class-helpers | src/Traits/LoggingHelperTrait.php | LoggingHelperTrait.logException | protected function logException(\Exception $e, $action = null, $level = LogLevel::ERROR)
{
$message = $action
? sprintf('%s failed: %s', $action, $e->getMessage())
: sprintf('%s: %s', get_class($e), $e->getMessage());
$this->getLogger()->log($level, $message, ['backtrace' => $e->getTraceAsString()]);
} | php | protected function logException(\Exception $e, $action = null, $level = LogLevel::ERROR)
{
$message = $action
? sprintf('%s failed: %s', $action, $e->getMessage())
: sprintf('%s: %s', get_class($e), $e->getMessage());
$this->getLogger()->log($level, $message, ['backtrace' => $e->getTraceAsString()]);
} | [
"protected",
"function",
"logException",
"(",
"\\",
"Exception",
"$",
"e",
",",
"$",
"action",
"=",
"null",
",",
"$",
"level",
"=",
"LogLevel",
"::",
"ERROR",
")",
"{",
"$",
"message",
"=",
"$",
"action",
"?",
"sprintf",
"(",
"'%s failed: %s'",
",",
"$",
"action",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
":",
"sprintf",
"(",
"'%s: %s'",
",",
"get_class",
"(",
"$",
"e",
")",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"log",
"(",
"$",
"level",
",",
"$",
"message",
",",
"[",
"'backtrace'",
"=>",
"$",
"e",
"->",
"getTraceAsString",
"(",
")",
"]",
")",
";",
"}"
] | Log exception.
@param \Exception $e Exception.
@param string|null $action Failed action short description.
@param mixed $level Log level (default to LogLevel::ERROR).
@since 1.1 Default log level is LogLevel::ERROR
@since 1.0 | [
"Log",
"exception",
"."
] | 4b00db6cba814cb5f8973a5929c167fce555c172 | https://github.com/mekras/class-helpers/blob/4b00db6cba814cb5f8973a5929c167fce555c172/src/Traits/LoggingHelperTrait.php#L68-L74 | train |
PatrolServer/patrolsdk-php | lib/PatrolObject.php | PatrolObject.defaults | public function defaults($defaults) {
$this->defaults = $defaults;
foreach ($defaults as $k => $v) {
if (property_exists($this, $k)) {
$this->{$k} = $v;
}
}
} | php | public function defaults($defaults) {
$this->defaults = $defaults;
foreach ($defaults as $k => $v) {
if (property_exists($this, $k)) {
$this->{$k} = $v;
}
}
} | [
"public",
"function",
"defaults",
"(",
"$",
"defaults",
")",
"{",
"$",
"this",
"->",
"defaults",
"=",
"$",
"defaults",
";",
"foreach",
"(",
"$",
"defaults",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"property_exists",
"(",
"$",
"this",
",",
"$",
"k",
")",
")",
"{",
"$",
"this",
"->",
"{",
"$",
"k",
"}",
"=",
"$",
"v",
";",
"}",
"}",
"}"
] | Sets the default values for this PatrolObject
@param array $defaults | [
"Sets",
"the",
"default",
"values",
"for",
"this",
"PatrolObject"
] | 2451f0d2ba2bb5bc3d7e47cfc110f7f272620db2 | https://github.com/PatrolServer/patrolsdk-php/blob/2451f0d2ba2bb5bc3d7e47cfc110f7f272620db2/lib/PatrolObject.php#L108-L116 | train |
PatrolServer/patrolsdk-php | lib/PatrolObject.php | PatrolObject.mergeValues | public function mergeValues($object) {
$values = $object->__toArray();
foreach ($values as $k => $v) {
$this->values[$k] = $v;
}
if ($object->id) $this->id = $object->id;
$this->dirty_values = [];
} | php | public function mergeValues($object) {
$values = $object->__toArray();
foreach ($values as $k => $v) {
$this->values[$k] = $v;
}
if ($object->id) $this->id = $object->id;
$this->dirty_values = [];
} | [
"public",
"function",
"mergeValues",
"(",
"$",
"object",
")",
"{",
"$",
"values",
"=",
"$",
"object",
"->",
"__toArray",
"(",
")",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"this",
"->",
"values",
"[",
"$",
"k",
"]",
"=",
"$",
"v",
";",
"}",
"if",
"(",
"$",
"object",
"->",
"id",
")",
"$",
"this",
"->",
"id",
"=",
"$",
"object",
"->",
"id",
";",
"$",
"this",
"->",
"dirty_values",
"=",
"[",
"]",
";",
"}"
] | Merges values from another PatrolObject
@param PatrolObject | [
"Merges",
"values",
"from",
"another",
"PatrolObject"
] | 2451f0d2ba2bb5bc3d7e47cfc110f7f272620db2 | https://github.com/PatrolServer/patrolsdk-php/blob/2451f0d2ba2bb5bc3d7e47cfc110f7f272620db2/lib/PatrolObject.php#L123-L131 | train |
zarathustra323/modlr-data | src/Zarathustra/ModlrData/Metadata/MetadataFactory.php | MetadataFactory.isChildOf | public function isChildOf($child, $parent)
{
$childMeta = $this->getMetadataForType($child);
if (false === $childMeta->isChildEntity()) {
return false;
}
return $childMeta->getParentEntityType() === $parent;
} | php | public function isChildOf($child, $parent)
{
$childMeta = $this->getMetadataForType($child);
if (false === $childMeta->isChildEntity()) {
return false;
}
return $childMeta->getParentEntityType() === $parent;
} | [
"public",
"function",
"isChildOf",
"(",
"$",
"child",
",",
"$",
"parent",
")",
"{",
"$",
"childMeta",
"=",
"$",
"this",
"->",
"getMetadataForType",
"(",
"$",
"child",
")",
";",
"if",
"(",
"false",
"===",
"$",
"childMeta",
"->",
"isChildEntity",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"childMeta",
"->",
"getParentEntityType",
"(",
")",
"===",
"$",
"parent",
";",
"}"
] | Determines if a type is direct child of another type.
@param string $child
@param string $parent
@return bool | [
"Determines",
"if",
"a",
"type",
"is",
"direct",
"child",
"of",
"another",
"type",
"."
] | 7c2c767216055f75abf8cf22e2200f11998ed24e | https://github.com/zarathustra323/modlr-data/blob/7c2c767216055f75abf8cf22e2200f11998ed24e/src/Zarathustra/ModlrData/Metadata/MetadataFactory.php#L205-L212 | train |
zarathustra323/modlr-data | src/Zarathustra/ModlrData/Metadata/MetadataFactory.php | MetadataFactory.isDescendantOf | public function isDescendantOf($child, $parent)
{
$childMeta = $this->getMetadataForType($child);
if (false === $childMeta->isChildEntity()) {
return false;
}
if ($childMeta->getParentEntityType() === $parent) {
return true;
}
return $this->isDescendantOf($childMeta->getParentEntityType(), $parent);
} | php | public function isDescendantOf($child, $parent)
{
$childMeta = $this->getMetadataForType($child);
if (false === $childMeta->isChildEntity()) {
return false;
}
if ($childMeta->getParentEntityType() === $parent) {
return true;
}
return $this->isDescendantOf($childMeta->getParentEntityType(), $parent);
} | [
"public",
"function",
"isDescendantOf",
"(",
"$",
"child",
",",
"$",
"parent",
")",
"{",
"$",
"childMeta",
"=",
"$",
"this",
"->",
"getMetadataForType",
"(",
"$",
"child",
")",
";",
"if",
"(",
"false",
"===",
"$",
"childMeta",
"->",
"isChildEntity",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"childMeta",
"->",
"getParentEntityType",
"(",
")",
"===",
"$",
"parent",
")",
"{",
"return",
"true",
";",
"}",
"return",
"$",
"this",
"->",
"isDescendantOf",
"(",
"$",
"childMeta",
"->",
"getParentEntityType",
"(",
")",
",",
"$",
"parent",
")",
";",
"}"
] | Determines if a type is a descendant of another type.
@param string $child
@param string $parent
@return bool | [
"Determines",
"if",
"a",
"type",
"is",
"a",
"descendant",
"of",
"another",
"type",
"."
] | 7c2c767216055f75abf8cf22e2200f11998ed24e | https://github.com/zarathustra323/modlr-data/blob/7c2c767216055f75abf8cf22e2200f11998ed24e/src/Zarathustra/ModlrData/Metadata/MetadataFactory.php#L233-L243 | train |
zarathustra323/modlr-data | src/Zarathustra/ModlrData/Metadata/MetadataFactory.php | MetadataFactory.mergeMetadata | private function mergeMetadata(EntityMetadata &$metadata = null, EntityMetadata $toAdd)
{
if (null === $metadata) {
$metadata = clone $toAdd;
} else {
$metadata->merge($toAdd);
}
} | php | private function mergeMetadata(EntityMetadata &$metadata = null, EntityMetadata $toAdd)
{
if (null === $metadata) {
$metadata = clone $toAdd;
} else {
$metadata->merge($toAdd);
}
} | [
"private",
"function",
"mergeMetadata",
"(",
"EntityMetadata",
"&",
"$",
"metadata",
"=",
"null",
",",
"EntityMetadata",
"$",
"toAdd",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"metadata",
")",
"{",
"$",
"metadata",
"=",
"clone",
"$",
"toAdd",
";",
"}",
"else",
"{",
"$",
"metadata",
"->",
"merge",
"(",
"$",
"toAdd",
")",
";",
"}",
"}"
] | Merges two sets of EntityMetadata.
Is used for applying inheritance information.
@param EntityMetadata &$metadata
@param EntityMetadata $toAdd | [
"Merges",
"two",
"sets",
"of",
"EntityMetadata",
".",
"Is",
"used",
"for",
"applying",
"inheritance",
"information",
"."
] | 7c2c767216055f75abf8cf22e2200f11998ed24e | https://github.com/zarathustra323/modlr-data/blob/7c2c767216055f75abf8cf22e2200f11998ed24e/src/Zarathustra/ModlrData/Metadata/MetadataFactory.php#L252-L259 | train |
zarathustra323/modlr-data | src/Zarathustra/ModlrData/Metadata/MetadataFactory.php | MetadataFactory.formatEntityType | private function formatEntityType($type)
{
$delim = EntityMetadata::NAMESPACE_DELIM;
if (false === stristr($type, $delim)) {
return $this->inflector->studlify($type);
}
$parts = explode($delim, $type);
foreach ($parts as &$part) {
$part = $this->inflector->studlify($part);
}
return implode($delim, $parts);
} | php | private function formatEntityType($type)
{
$delim = EntityMetadata::NAMESPACE_DELIM;
if (false === stristr($type, $delim)) {
return $this->inflector->studlify($type);
}
$parts = explode($delim, $type);
foreach ($parts as &$part) {
$part = $this->inflector->studlify($part);
}
return implode($delim, $parts);
} | [
"private",
"function",
"formatEntityType",
"(",
"$",
"type",
")",
"{",
"$",
"delim",
"=",
"EntityMetadata",
"::",
"NAMESPACE_DELIM",
";",
"if",
"(",
"false",
"===",
"stristr",
"(",
"$",
"type",
",",
"$",
"delim",
")",
")",
"{",
"return",
"$",
"this",
"->",
"inflector",
"->",
"studlify",
"(",
"$",
"type",
")",
";",
"}",
"$",
"parts",
"=",
"explode",
"(",
"$",
"delim",
",",
"$",
"type",
")",
";",
"foreach",
"(",
"$",
"parts",
"as",
"&",
"$",
"part",
")",
"{",
"$",
"part",
"=",
"$",
"this",
"->",
"inflector",
"->",
"studlify",
"(",
"$",
"part",
")",
";",
"}",
"return",
"implode",
"(",
"$",
"delim",
",",
"$",
"parts",
")",
";",
"}"
] | Formats the entity type.
@param string $type
@return string | [
"Formats",
"the",
"entity",
"type",
"."
] | 7c2c767216055f75abf8cf22e2200f11998ed24e | https://github.com/zarathustra323/modlr-data/blob/7c2c767216055f75abf8cf22e2200f11998ed24e/src/Zarathustra/ModlrData/Metadata/MetadataFactory.php#L267-L279 | train |
zarathustra323/modlr-data | src/Zarathustra/ModlrData/Metadata/MetadataFactory.php | MetadataFactory.getFromMemory | private function getFromMemory($type)
{
if (isset($this->loaded[$type])) {
return $this->loaded[$type];
}
return null;
} | php | private function getFromMemory($type)
{
if (isset($this->loaded[$type])) {
return $this->loaded[$type];
}
return null;
} | [
"private",
"function",
"getFromMemory",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"loaded",
"[",
"$",
"type",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"loaded",
"[",
"$",
"type",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Gets a Metadata instance for a type from memory.
@return EntityMetadata|null | [
"Gets",
"a",
"Metadata",
"instance",
"for",
"a",
"type",
"from",
"memory",
"."
] | 7c2c767216055f75abf8cf22e2200f11998ed24e | https://github.com/zarathustra323/modlr-data/blob/7c2c767216055f75abf8cf22e2200f11998ed24e/src/Zarathustra/ModlrData/Metadata/MetadataFactory.php#L333-L339 | train |
zarathustra323/modlr-data | src/Zarathustra/ModlrData/Metadata/MetadataFactory.php | MetadataFactory.getFromCache | private function getFromCache($type)
{
if (false === $this->hasCache()) {
return null;
}
return $this->cache->loadMetadataFromCache($type);
} | php | private function getFromCache($type)
{
if (false === $this->hasCache()) {
return null;
}
return $this->cache->loadMetadataFromCache($type);
} | [
"private",
"function",
"getFromCache",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"hasCache",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"cache",
"->",
"loadMetadataFromCache",
"(",
"$",
"type",
")",
";",
"}"
] | Retrieves a Metadata instance for a type from cache.
@return EntityMetadata|null | [
"Retrieves",
"a",
"Metadata",
"instance",
"for",
"a",
"type",
"from",
"cache",
"."
] | 7c2c767216055f75abf8cf22e2200f11998ed24e | https://github.com/zarathustra323/modlr-data/blob/7c2c767216055f75abf8cf22e2200f11998ed24e/src/Zarathustra/ModlrData/Metadata/MetadataFactory.php#L358-L364 | train |
wearenolte/assets | src/Assets.php | Assets.set_up_environment | private function set_up_environment() {
if ( $this->it_has( 'environment' ) ) {
$this->environment = $this->options['environment'];
} else {
$this->environment = defined( 'WP_DEBUG' ) && WP_DEBUG
? 'development'
: 'production';
}
} | php | private function set_up_environment() {
if ( $this->it_has( 'environment' ) ) {
$this->environment = $this->options['environment'];
} else {
$this->environment = defined( 'WP_DEBUG' ) && WP_DEBUG
? 'development'
: 'production';
}
} | [
"private",
"function",
"set_up_environment",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"it_has",
"(",
"'environment'",
")",
")",
"{",
"$",
"this",
"->",
"environment",
"=",
"$",
"this",
"->",
"options",
"[",
"'environment'",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"environment",
"=",
"defined",
"(",
"'WP_DEBUG'",
")",
"&&",
"WP_DEBUG",
"?",
"'development'",
":",
"'production'",
";",
"}",
"}"
] | Setup the environment based on options given.
@since 1.1.0
@access private
@return void | [
"Setup",
"the",
"environment",
"based",
"on",
"options",
"given",
"."
] | 2082a8085a4d3731c530aed0f2fa183e4aa4b6e8 | https://github.com/wearenolte/assets/blob/2082a8085a4d3731c530aed0f2fa183e4aa4b6e8/src/Assets.php#L135-L143 | train |
wearenolte/assets | src/Assets.php | Assets.set_up_version_numbers | private function set_up_version_numbers() {
if ( $this->it_has( 'js_version' ) ) {
$this->js_version = $this->options['js_version'];
}
if ( $this->it_has( 'css_version' ) ) {
$this->css_version = $this->options['css_version'];
}
if ( $this->it_has( 'jquery_version' ) ) {
$this->jquery_version = $this->options['jquery_version'];
}
} | php | private function set_up_version_numbers() {
if ( $this->it_has( 'js_version' ) ) {
$this->js_version = $this->options['js_version'];
}
if ( $this->it_has( 'css_version' ) ) {
$this->css_version = $this->options['css_version'];
}
if ( $this->it_has( 'jquery_version' ) ) {
$this->jquery_version = $this->options['jquery_version'];
}
} | [
"private",
"function",
"set_up_version_numbers",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"it_has",
"(",
"'js_version'",
")",
")",
"{",
"$",
"this",
"->",
"js_version",
"=",
"$",
"this",
"->",
"options",
"[",
"'js_version'",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"it_has",
"(",
"'css_version'",
")",
")",
"{",
"$",
"this",
"->",
"css_version",
"=",
"$",
"this",
"->",
"options",
"[",
"'css_version'",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"it_has",
"(",
"'jquery_version'",
")",
")",
"{",
"$",
"this",
"->",
"jquery_version",
"=",
"$",
"this",
"->",
"options",
"[",
"'jquery_version'",
"]",
";",
"}",
"}"
] | Setup JS and CSS version numbers based on options given.
@since 1.1.0
@access private
@return void | [
"Setup",
"JS",
"and",
"CSS",
"version",
"numbers",
"based",
"on",
"options",
"given",
"."
] | 2082a8085a4d3731c530aed0f2fa183e4aa4b6e8 | https://github.com/wearenolte/assets/blob/2082a8085a4d3731c530aed0f2fa183e4aa4b6e8/src/Assets.php#L153-L163 | train |
wearenolte/assets | src/Assets.php | Assets.it_has | private function it_has( $option_name ) {
return array_key_exists( $option_name, $this->options ) && ! empty( $this->options[ $option_name ] );
} | php | private function it_has( $option_name ) {
return array_key_exists( $option_name, $this->options ) && ! empty( $this->options[ $option_name ] );
} | [
"private",
"function",
"it_has",
"(",
"$",
"option_name",
")",
"{",
"return",
"array_key_exists",
"(",
"$",
"option_name",
",",
"$",
"this",
"->",
"options",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"options",
"[",
"$",
"option_name",
"]",
")",
";",
"}"
] | Check whether a given option exists in the options array.
@since 1.1.0
@access private
@param string $option_name The name of the option to check for existence.
@return bool Whether the given option key exists. | [
"Check",
"whether",
"a",
"given",
"option",
"exists",
"in",
"the",
"options",
"array",
"."
] | 2082a8085a4d3731c530aed0f2fa183e4aa4b6e8 | https://github.com/wearenolte/assets/blob/2082a8085a4d3731c530aed0f2fa183e4aa4b6e8/src/Assets.php#L174-L176 | train |
wearenolte/assets | src/Assets.php | Assets.load | public function load() {
$this->load_comments = $this->it_has( 'load_coments', $this->options )
? $this->options['load_comments']
: false;
$this->enqueue_assets();
} | php | public function load() {
$this->load_comments = $this->it_has( 'load_coments', $this->options )
? $this->options['load_comments']
: false;
$this->enqueue_assets();
} | [
"public",
"function",
"load",
"(",
")",
"{",
"$",
"this",
"->",
"load_comments",
"=",
"$",
"this",
"->",
"it_has",
"(",
"'load_coments'",
",",
"$",
"this",
"->",
"options",
")",
"?",
"$",
"this",
"->",
"options",
"[",
"'load_comments'",
"]",
":",
"false",
";",
"$",
"this",
"->",
"enqueue_assets",
"(",
")",
";",
"}"
] | Enqueues the theme assets.
@since 1.1.0
@return void | [
"Enqueues",
"the",
"theme",
"assets",
"."
] | 2082a8085a4d3731c530aed0f2fa183e4aa4b6e8 | https://github.com/wearenolte/assets/blob/2082a8085a4d3731c530aed0f2fa183e4aa4b6e8/src/Assets.php#L185-L190 | train |
wearenolte/assets | src/Assets.php | Assets.setup_assets | public function setup_assets() {
$suffix = $this->get_assets_suffix();
if ( ! is_admin() ) {
if ( ! empty( $this->jquery_uri ) ) {
$this->update_jquery();
}
$remove_emoji_exists = array_key_exists( 'remove_emoji', $this->options );
if ( ! $remove_emoji_exists ||
( $remove_emoji_exists && $this->options['remove_emoji'] )
) {
$this->remove_emoji();
}
}
// Load the JS files.
if ( apply_filters( self::HOOK_PREFIX . 'include_js', true ) ) {
$handle = sprintf( '%s-%s', $this->environment, 'js' );
wp_register_script( $handle, str_replace( '.js', $suffix, $this->js_uri ) . '.js', [], $this->js_version, true );
$localize_script = apply_filters( self::HOOK_PREFIX . 'localize_script', 'lean_localize_js' );
$localize_data = apply_filters( self::HOOK_PREFIX . 'localize_data', [] );
wp_localize_script( $handle, $localize_script, $localize_data );
wp_enqueue_script( $handle );
}
// Load the CSS files.
if ( apply_filters( self::HOOK_PREFIX . 'include_css', true ) ) {
wp_enqueue_style(
sprintf( '%s-%s', $this->environment, 'style' ),
str_replace( '.css', $suffix, $this->css_uri ) . '.css',
array(),
$this->css_version,
'all'
);
}
if ( $this->load_comments ) {
$this->load_comments_assets();
}
} | php | public function setup_assets() {
$suffix = $this->get_assets_suffix();
if ( ! is_admin() ) {
if ( ! empty( $this->jquery_uri ) ) {
$this->update_jquery();
}
$remove_emoji_exists = array_key_exists( 'remove_emoji', $this->options );
if ( ! $remove_emoji_exists ||
( $remove_emoji_exists && $this->options['remove_emoji'] )
) {
$this->remove_emoji();
}
}
// Load the JS files.
if ( apply_filters( self::HOOK_PREFIX . 'include_js', true ) ) {
$handle = sprintf( '%s-%s', $this->environment, 'js' );
wp_register_script( $handle, str_replace( '.js', $suffix, $this->js_uri ) . '.js', [], $this->js_version, true );
$localize_script = apply_filters( self::HOOK_PREFIX . 'localize_script', 'lean_localize_js' );
$localize_data = apply_filters( self::HOOK_PREFIX . 'localize_data', [] );
wp_localize_script( $handle, $localize_script, $localize_data );
wp_enqueue_script( $handle );
}
// Load the CSS files.
if ( apply_filters( self::HOOK_PREFIX . 'include_css', true ) ) {
wp_enqueue_style(
sprintf( '%s-%s', $this->environment, 'style' ),
str_replace( '.css', $suffix, $this->css_uri ) . '.css',
array(),
$this->css_version,
'all'
);
}
if ( $this->load_comments ) {
$this->load_comments_assets();
}
} | [
"public",
"function",
"setup_assets",
"(",
")",
"{",
"$",
"suffix",
"=",
"$",
"this",
"->",
"get_assets_suffix",
"(",
")",
";",
"if",
"(",
"!",
"is_admin",
"(",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"jquery_uri",
")",
")",
"{",
"$",
"this",
"->",
"update_jquery",
"(",
")",
";",
"}",
"$",
"remove_emoji_exists",
"=",
"array_key_exists",
"(",
"'remove_emoji'",
",",
"$",
"this",
"->",
"options",
")",
";",
"if",
"(",
"!",
"$",
"remove_emoji_exists",
"||",
"(",
"$",
"remove_emoji_exists",
"&&",
"$",
"this",
"->",
"options",
"[",
"'remove_emoji'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"remove_emoji",
"(",
")",
";",
"}",
"}",
"// Load the JS files.",
"if",
"(",
"apply_filters",
"(",
"self",
"::",
"HOOK_PREFIX",
".",
"'include_js'",
",",
"true",
")",
")",
"{",
"$",
"handle",
"=",
"sprintf",
"(",
"'%s-%s'",
",",
"$",
"this",
"->",
"environment",
",",
"'js'",
")",
";",
"wp_register_script",
"(",
"$",
"handle",
",",
"str_replace",
"(",
"'.js'",
",",
"$",
"suffix",
",",
"$",
"this",
"->",
"js_uri",
")",
".",
"'.js'",
",",
"[",
"]",
",",
"$",
"this",
"->",
"js_version",
",",
"true",
")",
";",
"$",
"localize_script",
"=",
"apply_filters",
"(",
"self",
"::",
"HOOK_PREFIX",
".",
"'localize_script'",
",",
"'lean_localize_js'",
")",
";",
"$",
"localize_data",
"=",
"apply_filters",
"(",
"self",
"::",
"HOOK_PREFIX",
".",
"'localize_data'",
",",
"[",
"]",
")",
";",
"wp_localize_script",
"(",
"$",
"handle",
",",
"$",
"localize_script",
",",
"$",
"localize_data",
")",
";",
"wp_enqueue_script",
"(",
"$",
"handle",
")",
";",
"}",
"// Load the CSS files.",
"if",
"(",
"apply_filters",
"(",
"self",
"::",
"HOOK_PREFIX",
".",
"'include_css'",
",",
"true",
")",
")",
"{",
"wp_enqueue_style",
"(",
"sprintf",
"(",
"'%s-%s'",
",",
"$",
"this",
"->",
"environment",
",",
"'style'",
")",
",",
"str_replace",
"(",
"'.css'",
",",
"$",
"suffix",
",",
"$",
"this",
"->",
"css_uri",
")",
".",
"'.css'",
",",
"array",
"(",
")",
",",
"$",
"this",
"->",
"css_version",
",",
"'all'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"load_comments",
")",
"{",
"$",
"this",
"->",
"load_comments_assets",
"(",
")",
";",
"}",
"}"
] | Enqueues JS and CSS assets based on options passed.
@since 1.1.0
@return void | [
"Enqueues",
"JS",
"and",
"CSS",
"assets",
"based",
"on",
"options",
"passed",
"."
] | 2082a8085a4d3731c530aed0f2fa183e4aa4b6e8 | https://github.com/wearenolte/assets/blob/2082a8085a4d3731c530aed0f2fa183e4aa4b6e8/src/Assets.php#L214-L253 | train |
wearenolte/assets | src/Assets.php | Assets.update_jquery | private function update_jquery() {
wp_deregister_script( 'jquery' );
if ( apply_filters( self::HOOK_PREFIX . 'include_jquery', false ) ) {
wp_register_script(
// Handle.
'jquery',
// Source path.
$this->jquery_uri,
// No dependencies.
false,
// Version number.
$this->jquery_version,
// Load in footer.
false
);
wp_enqueue_script( 'jquery' );
}
} | php | private function update_jquery() {
wp_deregister_script( 'jquery' );
if ( apply_filters( self::HOOK_PREFIX . 'include_jquery', false ) ) {
wp_register_script(
// Handle.
'jquery',
// Source path.
$this->jquery_uri,
// No dependencies.
false,
// Version number.
$this->jquery_version,
// Load in footer.
false
);
wp_enqueue_script( 'jquery' );
}
} | [
"private",
"function",
"update_jquery",
"(",
")",
"{",
"wp_deregister_script",
"(",
"'jquery'",
")",
";",
"if",
"(",
"apply_filters",
"(",
"self",
"::",
"HOOK_PREFIX",
".",
"'include_jquery'",
",",
"false",
")",
")",
"{",
"wp_register_script",
"(",
"// Handle.",
"'jquery'",
",",
"// Source path.",
"$",
"this",
"->",
"jquery_uri",
",",
"// No dependencies.",
"false",
",",
"// Version number.",
"$",
"this",
"->",
"jquery_version",
",",
"// Load in footer.",
"false",
")",
";",
"wp_enqueue_script",
"(",
"'jquery'",
")",
";",
"}",
"}"
] | Enqueues theme-bundled jQuery instead of default one in WordPress.
@since 1.1.0
@access private
@return void | [
"Enqueues",
"theme",
"-",
"bundled",
"jQuery",
"instead",
"of",
"default",
"one",
"in",
"WordPress",
"."
] | 2082a8085a4d3731c530aed0f2fa183e4aa4b6e8 | https://github.com/wearenolte/assets/blob/2082a8085a4d3731c530aed0f2fa183e4aa4b6e8/src/Assets.php#L263-L282 | train |
phossa/phossa-di | src/Phossa/Di/Extension/Decorate/DecorateExtension.php | DecorateExtension.decorateService | public function decorateService($service)
{
try {
foreach ($this->rules as $rule) {
// if closure returns true
if ($rule[0]($service)) {
// execute the decorate callable
$rule[1]($service);
}
}
} catch (\Exception $e) {
throw new LogicException($e->getMessage(), $e->getCode(), $e);
}
} | php | public function decorateService($service)
{
try {
foreach ($this->rules as $rule) {
// if closure returns true
if ($rule[0]($service)) {
// execute the decorate callable
$rule[1]($service);
}
}
} catch (\Exception $e) {
throw new LogicException($e->getMessage(), $e->getCode(), $e);
}
} | [
"public",
"function",
"decorateService",
"(",
"$",
"service",
")",
"{",
"try",
"{",
"foreach",
"(",
"$",
"this",
"->",
"rules",
"as",
"$",
"rule",
")",
"{",
"// if closure returns true",
"if",
"(",
"$",
"rule",
"[",
"0",
"]",
"(",
"$",
"service",
")",
")",
"{",
"// execute the decorate callable",
"$",
"rule",
"[",
"1",
"]",
"(",
"$",
"service",
")",
";",
"}",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Apply decorating rules to a service object if matches
@param object $service
@return void
@throws LogicException if something goes wrong
@access public
@internal | [
"Apply",
"decorating",
"rules",
"to",
"a",
"service",
"object",
"if",
"matches"
] | bbe1e95b081068e2bc49c6cd465f38aab0374be5 | https://github.com/phossa/phossa-di/blob/bbe1e95b081068e2bc49c6cd465f38aab0374be5/src/Phossa/Di/Extension/Decorate/DecorateExtension.php#L57-L70 | train |
phossa/phossa-di | src/Phossa/Di/Extension/Decorate/DecorateExtension.php | DecorateExtension.setDecorate | public function setDecorate(
/*# string */ $ruleName,
$interfaceOrClosure,
$decorateCallable
) {
// create closure it it is a interface name
if (!is_callable($interfaceOrClosure)) {
$interfaceOrClosure = function ($service) use ($interfaceOrClosure) {
return $service instanceof $interfaceOrClosure;
};
}
// create closure if array [method, arguments] provided
if (!is_callable($decorateCallable)) {
$method = $decorateCallable[0];
$container = $this->getContainer();
$arguments = isset($decorateCallable[1]) ? $decorateCallable[1] : [];
$decorateCallable = function ($service) use ($container, $method, $arguments) {
$container->run([$service, $method], $arguments);
};
}
// set the rule
$this->rules[$ruleName] = [ $interfaceOrClosure, $decorateCallable ];
} | php | public function setDecorate(
/*# string */ $ruleName,
$interfaceOrClosure,
$decorateCallable
) {
// create closure it it is a interface name
if (!is_callable($interfaceOrClosure)) {
$interfaceOrClosure = function ($service) use ($interfaceOrClosure) {
return $service instanceof $interfaceOrClosure;
};
}
// create closure if array [method, arguments] provided
if (!is_callable($decorateCallable)) {
$method = $decorateCallable[0];
$container = $this->getContainer();
$arguments = isset($decorateCallable[1]) ? $decorateCallable[1] : [];
$decorateCallable = function ($service) use ($container, $method, $arguments) {
$container->run([$service, $method], $arguments);
};
}
// set the rule
$this->rules[$ruleName] = [ $interfaceOrClosure, $decorateCallable ];
} | [
"public",
"function",
"setDecorate",
"(",
"/*# string */",
"$",
"ruleName",
",",
"$",
"interfaceOrClosure",
",",
"$",
"decorateCallable",
")",
"{",
"// create closure it it is a interface name",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"interfaceOrClosure",
")",
")",
"{",
"$",
"interfaceOrClosure",
"=",
"function",
"(",
"$",
"service",
")",
"use",
"(",
"$",
"interfaceOrClosure",
")",
"{",
"return",
"$",
"service",
"instanceof",
"$",
"interfaceOrClosure",
";",
"}",
";",
"}",
"// create closure if array [method, arguments] provided",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"decorateCallable",
")",
")",
"{",
"$",
"method",
"=",
"$",
"decorateCallable",
"[",
"0",
"]",
";",
"$",
"container",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
";",
"$",
"arguments",
"=",
"isset",
"(",
"$",
"decorateCallable",
"[",
"1",
"]",
")",
"?",
"$",
"decorateCallable",
"[",
"1",
"]",
":",
"[",
"]",
";",
"$",
"decorateCallable",
"=",
"function",
"(",
"$",
"service",
")",
"use",
"(",
"$",
"container",
",",
"$",
"method",
",",
"$",
"arguments",
")",
"{",
"$",
"container",
"->",
"run",
"(",
"[",
"$",
"service",
",",
"$",
"method",
"]",
",",
"$",
"arguments",
")",
";",
"}",
";",
"}",
"// set the rule",
"$",
"this",
"->",
"rules",
"[",
"$",
"ruleName",
"]",
"=",
"[",
"$",
"interfaceOrClosure",
",",
"$",
"decorateCallable",
"]",
";",
"}"
] | Set up docorating rules
@param string $ruleName decorate rule name
@param string|callable $interfaceOrClosure callable or interface/class
@param array|callable $decorateCallable callable or [method, arguments]
@return void
@throws LogicException if something goes wrong
@access public
@internal | [
"Set",
"up",
"docorating",
"rules"
] | bbe1e95b081068e2bc49c6cd465f38aab0374be5 | https://github.com/phossa/phossa-di/blob/bbe1e95b081068e2bc49c6cd465f38aab0374be5/src/Phossa/Di/Extension/Decorate/DecorateExtension.php#L83-L107 | train |
nicodevs/laito | src/Laito/View.php | View.render | public function render($view, $values = array())
{
// Setup the template path
$folder = $this->app->config('templates.path');
$view = $folder . $view . '.php';
// Check if the template exists
if (!file_exists($view)) {
throw new \Exception('Template not found: ' . $view, 404);
}
// Extract values and include template
extract($values);
ob_start();
include $view;
$html = ob_get_contents();
ob_end_clean();
// Return rendered HTML
return $html;
} | php | public function render($view, $values = array())
{
// Setup the template path
$folder = $this->app->config('templates.path');
$view = $folder . $view . '.php';
// Check if the template exists
if (!file_exists($view)) {
throw new \Exception('Template not found: ' . $view, 404);
}
// Extract values and include template
extract($values);
ob_start();
include $view;
$html = ob_get_contents();
ob_end_clean();
// Return rendered HTML
return $html;
} | [
"public",
"function",
"render",
"(",
"$",
"view",
",",
"$",
"values",
"=",
"array",
"(",
")",
")",
"{",
"// Setup the template path",
"$",
"folder",
"=",
"$",
"this",
"->",
"app",
"->",
"config",
"(",
"'templates.path'",
")",
";",
"$",
"view",
"=",
"$",
"folder",
".",
"$",
"view",
".",
"'.php'",
";",
"// Check if the template exists",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"view",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Template not found: '",
".",
"$",
"view",
",",
"404",
")",
";",
"}",
"// Extract values and include template",
"extract",
"(",
"$",
"values",
")",
";",
"ob_start",
"(",
")",
";",
"include",
"$",
"view",
";",
"$",
"html",
"=",
"ob_get_contents",
"(",
")",
";",
"ob_end_clean",
"(",
")",
";",
"// Return rendered HTML",
"return",
"$",
"html",
";",
"}"
] | Renders a template with optional data
@param string $template Name of the template
@param array $values Array of values to replace in the template
@return string Rendered HTML | [
"Renders",
"a",
"template",
"with",
"optional",
"data"
] | d2d28abfcbf981c4decfec28ce94f8849600e9fe | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/View.php#L15-L35 | train |
ScaraMVC/Framework | src/Scara/Mail/MailerServiceProvider.php | MailerServiceProvider.register | public function register()
{
$this->create('mail', function () {
// return new Mailer();
$c = new Configuration();
$config = $c->from('mail');
$mail = new Mailer($config->get('host'), $config->get('port'),
$config->get('smtp_auth'), $config->get('encryption'));
return $mail->setAuthentication($config->get('user'), $config->get('pass'));
});
} | php | public function register()
{
$this->create('mail', function () {
// return new Mailer();
$c = new Configuration();
$config = $c->from('mail');
$mail = new Mailer($config->get('host'), $config->get('port'),
$config->get('smtp_auth'), $config->get('encryption'));
return $mail->setAuthentication($config->get('user'), $config->get('pass'));
});
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"create",
"(",
"'mail'",
",",
"function",
"(",
")",
"{",
"// return new Mailer();",
"$",
"c",
"=",
"new",
"Configuration",
"(",
")",
";",
"$",
"config",
"=",
"$",
"c",
"->",
"from",
"(",
"'mail'",
")",
";",
"$",
"mail",
"=",
"new",
"Mailer",
"(",
"$",
"config",
"->",
"get",
"(",
"'host'",
")",
",",
"$",
"config",
"->",
"get",
"(",
"'port'",
")",
",",
"$",
"config",
"->",
"get",
"(",
"'smtp_auth'",
")",
",",
"$",
"config",
"->",
"get",
"(",
"'encryption'",
")",
")",
";",
"return",
"$",
"mail",
"->",
"setAuthentication",
"(",
"$",
"config",
"->",
"get",
"(",
"'user'",
")",
",",
"$",
"config",
"->",
"get",
"(",
"'pass'",
")",
")",
";",
"}",
")",
";",
"}"
] | Registers the Mailer Service Provider.
@return void | [
"Registers",
"the",
"Mailer",
"Service",
"Provider",
"."
] | 199b08b45fadf5dae14ac4732af03b36e15bbef2 | https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Mail/MailerServiceProvider.php#L18-L30 | train |
RocketPropelledTortoise/Core | src/Translation/I18N.php | I18N.setCurrentLanguage | public function setCurrentLanguage($language)
{
if (!$this->isAvailable($language)) {
return false;
}
$this->session->put('language', $language);
$this->setLanguage($language);
return true;
} | php | public function setCurrentLanguage($language)
{
if (!$this->isAvailable($language)) {
return false;
}
$this->session->put('language', $language);
$this->setLanguage($language);
return true;
} | [
"public",
"function",
"setCurrentLanguage",
"(",
"$",
"language",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isAvailable",
"(",
"$",
"language",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"session",
"->",
"put",
"(",
"'language'",
",",
"$",
"language",
")",
";",
"$",
"this",
"->",
"setLanguage",
"(",
"$",
"language",
")",
";",
"return",
"true",
";",
"}"
] | Set the current language
@param string $language
@return bool | [
"Set",
"the",
"current",
"language"
] | 78b65663fc463e21e494257140ddbed0a9ccb3c3 | https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Translation/I18N.php#L172-L183 | train |
RocketPropelledTortoise/Core | src/Translation/I18N.php | I18N.setLanguage | public function setLanguage($language)
{
if ($language == $this->currentLanguage) {
return;
}
if (!$this->isLoaded($language)) {
$this->loadLanguage($language);
}
switch ($language) {
case 'fr':
setlocale(LC_ALL, 'fr_FR.utf8', 'fr_FR.UTF-8', 'fr_FR@euro', 'fr_FR', 'french');
break;
case 'en':
setlocale(LC_ALL, 'en_US.utf8', 'en_US.UTF-8', 'en_US');
break;
case 'de':
setlocale(LC_ALL, 'de_DE.utf8', 'de_DE.UTF-8', 'de_DE@euro', 'de_DE', 'deutsch');
break;
}
$this->currentLanguage = $language;
$this->currentLanguageId = $this->languagesIso[$language]['id'];
} | php | public function setLanguage($language)
{
if ($language == $this->currentLanguage) {
return;
}
if (!$this->isLoaded($language)) {
$this->loadLanguage($language);
}
switch ($language) {
case 'fr':
setlocale(LC_ALL, 'fr_FR.utf8', 'fr_FR.UTF-8', 'fr_FR@euro', 'fr_FR', 'french');
break;
case 'en':
setlocale(LC_ALL, 'en_US.utf8', 'en_US.UTF-8', 'en_US');
break;
case 'de':
setlocale(LC_ALL, 'de_DE.utf8', 'de_DE.UTF-8', 'de_DE@euro', 'de_DE', 'deutsch');
break;
}
$this->currentLanguage = $language;
$this->currentLanguageId = $this->languagesIso[$language]['id'];
} | [
"public",
"function",
"setLanguage",
"(",
"$",
"language",
")",
"{",
"if",
"(",
"$",
"language",
"==",
"$",
"this",
"->",
"currentLanguage",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"isLoaded",
"(",
"$",
"language",
")",
")",
"{",
"$",
"this",
"->",
"loadLanguage",
"(",
"$",
"language",
")",
";",
"}",
"switch",
"(",
"$",
"language",
")",
"{",
"case",
"'fr'",
":",
"setlocale",
"(",
"LC_ALL",
",",
"'fr_FR.utf8'",
",",
"'fr_FR.UTF-8'",
",",
"'fr_FR@euro'",
",",
"'fr_FR'",
",",
"'french'",
")",
";",
"break",
";",
"case",
"'en'",
":",
"setlocale",
"(",
"LC_ALL",
",",
"'en_US.utf8'",
",",
"'en_US.UTF-8'",
",",
"'en_US'",
")",
";",
"break",
";",
"case",
"'de'",
":",
"setlocale",
"(",
"LC_ALL",
",",
"'de_DE.utf8'",
",",
"'de_DE.UTF-8'",
",",
"'de_DE@euro'",
",",
"'de_DE'",
",",
"'deutsch'",
")",
";",
"break",
";",
"}",
"$",
"this",
"->",
"currentLanguage",
"=",
"$",
"language",
";",
"$",
"this",
"->",
"currentLanguageId",
"=",
"$",
"this",
"->",
"languagesIso",
"[",
"$",
"language",
"]",
"[",
"'id'",
"]",
";",
"}"
] | Set the language to use
@param string $language
@return bool | [
"Set",
"the",
"language",
"to",
"use"
] | 78b65663fc463e21e494257140ddbed0a9ccb3c3 | https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Translation/I18N.php#L233-L257 | train |
RocketPropelledTortoise/Core | src/Translation/I18N.php | I18N.languages | public function languages($key = null, $subkey = null)
{
if ($key === null) {
return $this->languagesIso;
}
if (is_int($key)) {
if (is_null($subkey)) {
return $this->languagesId[$key];
}
return $this->languagesId[$key][$subkey];
}
if (is_null($subkey)) {
return $this->languagesIso[$key];
}
return $this->languagesIso[$key][$subkey];
} | php | public function languages($key = null, $subkey = null)
{
if ($key === null) {
return $this->languagesIso;
}
if (is_int($key)) {
if (is_null($subkey)) {
return $this->languagesId[$key];
}
return $this->languagesId[$key][$subkey];
}
if (is_null($subkey)) {
return $this->languagesIso[$key];
}
return $this->languagesIso[$key][$subkey];
} | [
"public",
"function",
"languages",
"(",
"$",
"key",
"=",
"null",
",",
"$",
"subkey",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"languagesIso",
";",
"}",
"if",
"(",
"is_int",
"(",
"$",
"key",
")",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"subkey",
")",
")",
"{",
"return",
"$",
"this",
"->",
"languagesId",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"languagesId",
"[",
"$",
"key",
"]",
"[",
"$",
"subkey",
"]",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"subkey",
")",
")",
"{",
"return",
"$",
"this",
"->",
"languagesIso",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"languagesIso",
"[",
"$",
"key",
"]",
"[",
"$",
"subkey",
"]",
";",
"}"
] | Retrieve languages.
this is a hybrid method.
I18N::languages();
returns ['fr' => ['id' => 1, 'name' => 'francais', 'iso' => 'fr'], 'en' => ...]
I18N::languages('fr');
returns ['id' => 1, 'name' => 'francais', 'iso' => 'fr']
I18N::languages(1);
returns ['id' => 1, 'name' => 'francais', 'iso' => 'fr']
I18N::languages('fr', 'id');
returns 1
@param int|string $key
@param string $subkey
@return array | [
"Retrieve",
"languages",
"."
] | 78b65663fc463e21e494257140ddbed0a9ccb3c3 | https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Translation/I18N.php#L321-L340 | train |
RocketPropelledTortoise/Core | src/Translation/I18N.php | I18N.translate | public function translate($string, $context = 'default', $language = 'default')
{
if ($this->isDefault($language)) {
$language = $this->currentLanguage;
} else {
$this->setLanguage($language);
}
//get string from cache
if (array_key_exists($context, $this->strings[$language]) &&
array_key_exists($string, $this->strings[$language][$context])) {
return $this->strings[$language][$context][$string];
}
//check in db
$db_string = StringModel::select('id', 'date_creation')
->where('string', $string)
->where('context', $context)
->first();
if (!$db_string) {
$this->translateInsertString($context, $string);
return $string;
}
$text = $this->translateGetString($context, $language, $db_string->id);
if ($text) {
$this->strings[$language][$context][$string] = $text;
return $text;
}
return $string;
} | php | public function translate($string, $context = 'default', $language = 'default')
{
if ($this->isDefault($language)) {
$language = $this->currentLanguage;
} else {
$this->setLanguage($language);
}
//get string from cache
if (array_key_exists($context, $this->strings[$language]) &&
array_key_exists($string, $this->strings[$language][$context])) {
return $this->strings[$language][$context][$string];
}
//check in db
$db_string = StringModel::select('id', 'date_creation')
->where('string', $string)
->where('context', $context)
->first();
if (!$db_string) {
$this->translateInsertString($context, $string);
return $string;
}
$text = $this->translateGetString($context, $language, $db_string->id);
if ($text) {
$this->strings[$language][$context][$string] = $text;
return $text;
}
return $string;
} | [
"public",
"function",
"translate",
"(",
"$",
"string",
",",
"$",
"context",
"=",
"'default'",
",",
"$",
"language",
"=",
"'default'",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isDefault",
"(",
"$",
"language",
")",
")",
"{",
"$",
"language",
"=",
"$",
"this",
"->",
"currentLanguage",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setLanguage",
"(",
"$",
"language",
")",
";",
"}",
"//get string from cache",
"if",
"(",
"array_key_exists",
"(",
"$",
"context",
",",
"$",
"this",
"->",
"strings",
"[",
"$",
"language",
"]",
")",
"&&",
"array_key_exists",
"(",
"$",
"string",
",",
"$",
"this",
"->",
"strings",
"[",
"$",
"language",
"]",
"[",
"$",
"context",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"strings",
"[",
"$",
"language",
"]",
"[",
"$",
"context",
"]",
"[",
"$",
"string",
"]",
";",
"}",
"//check in db",
"$",
"db_string",
"=",
"StringModel",
"::",
"select",
"(",
"'id'",
",",
"'date_creation'",
")",
"->",
"where",
"(",
"'string'",
",",
"$",
"string",
")",
"->",
"where",
"(",
"'context'",
",",
"$",
"context",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"!",
"$",
"db_string",
")",
"{",
"$",
"this",
"->",
"translateInsertString",
"(",
"$",
"context",
",",
"$",
"string",
")",
";",
"return",
"$",
"string",
";",
"}",
"$",
"text",
"=",
"$",
"this",
"->",
"translateGetString",
"(",
"$",
"context",
",",
"$",
"language",
",",
"$",
"db_string",
"->",
"id",
")",
";",
"if",
"(",
"$",
"text",
")",
"{",
"$",
"this",
"->",
"strings",
"[",
"$",
"language",
"]",
"[",
"$",
"context",
"]",
"[",
"$",
"string",
"]",
"=",
"$",
"text",
";",
"return",
"$",
"text",
";",
"}",
"return",
"$",
"string",
";",
"}"
] | Retreive a string to translate
if it doesn't find it, put it in the database
@param string $string
@param string $context
@param string $language
@return string | [
"Retreive",
"a",
"string",
"to",
"translate"
] | 78b65663fc463e21e494257140ddbed0a9ccb3c3 | https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Translation/I18N.php#L395-L429 | train |
RocketPropelledTortoise/Core | src/Translation/I18N.php | I18N.getContext | public function getContext()
{
if ($this->pageContext) {
return $this->pageContext;
}
$current = \Route::getCurrentRoute();
if (!$current) {
return 'default';
}
if ($current->getName()) {
return $this->pageContext = $current->getName();
}
$action = $current->getAction();
if (array_key_exists('controller', $action)) {
return $this->pageContext = $action['controller'];
}
return $this->pageContext = implode('/', array_map(['Str', 'slug'], explode('/', $current->getUri())));
} | php | public function getContext()
{
if ($this->pageContext) {
return $this->pageContext;
}
$current = \Route::getCurrentRoute();
if (!$current) {
return 'default';
}
if ($current->getName()) {
return $this->pageContext = $current->getName();
}
$action = $current->getAction();
if (array_key_exists('controller', $action)) {
return $this->pageContext = $action['controller'];
}
return $this->pageContext = implode('/', array_map(['Str', 'slug'], explode('/', $current->getUri())));
} | [
"public",
"function",
"getContext",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"pageContext",
")",
"{",
"return",
"$",
"this",
"->",
"pageContext",
";",
"}",
"$",
"current",
"=",
"\\",
"Route",
"::",
"getCurrentRoute",
"(",
")",
";",
"if",
"(",
"!",
"$",
"current",
")",
"{",
"return",
"'default'",
";",
"}",
"if",
"(",
"$",
"current",
"->",
"getName",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"pageContext",
"=",
"$",
"current",
"->",
"getName",
"(",
")",
";",
"}",
"$",
"action",
"=",
"$",
"current",
"->",
"getAction",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'controller'",
",",
"$",
"action",
")",
")",
"{",
"return",
"$",
"this",
"->",
"pageContext",
"=",
"$",
"action",
"[",
"'controller'",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"pageContext",
"=",
"implode",
"(",
"'/'",
",",
"array_map",
"(",
"[",
"'Str'",
",",
"'slug'",
"]",
",",
"explode",
"(",
"'/'",
",",
"$",
"current",
"->",
"getUri",
"(",
")",
")",
")",
")",
";",
"}"
] | Get the page's context
@return string | [
"Get",
"the",
"page",
"s",
"context"
] | 78b65663fc463e21e494257140ddbed0a9ccb3c3 | https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Translation/I18N.php#L446-L468 | train |
tw88/sso | src/Broker.php | Broker.getAttachUrl | public function getAttachUrl($params = [], $cookieBased = null)
{
$this->generateToken($cookieBased);
$data = [
'command' => 'attach',
'broker' => $this->broker,
'token' => $this->token,
'checksum' => hash('sha256', 'attach' . $this->token . $this->secret)
] + $_GET;
return $this->url . "?" . http_build_query($data + $params);
} | php | public function getAttachUrl($params = [], $cookieBased = null)
{
$this->generateToken($cookieBased);
$data = [
'command' => 'attach',
'broker' => $this->broker,
'token' => $this->token,
'checksum' => hash('sha256', 'attach' . $this->token . $this->secret)
] + $_GET;
return $this->url . "?" . http_build_query($data + $params);
} | [
"public",
"function",
"getAttachUrl",
"(",
"$",
"params",
"=",
"[",
"]",
",",
"$",
"cookieBased",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"generateToken",
"(",
"$",
"cookieBased",
")",
";",
"$",
"data",
"=",
"[",
"'command'",
"=>",
"'attach'",
",",
"'broker'",
"=>",
"$",
"this",
"->",
"broker",
",",
"'token'",
"=>",
"$",
"this",
"->",
"token",
",",
"'checksum'",
"=>",
"hash",
"(",
"'sha256'",
",",
"'attach'",
".",
"$",
"this",
"->",
"token",
".",
"$",
"this",
"->",
"secret",
")",
"]",
"+",
"$",
"_GET",
";",
"return",
"$",
"this",
"->",
"url",
".",
"\"?\"",
".",
"http_build_query",
"(",
"$",
"data",
"+",
"$",
"params",
")",
";",
"}"
] | Get URL to attach session at SSO server.
@param array $params
@return string | [
"Get",
"URL",
"to",
"attach",
"session",
"at",
"SSO",
"server",
"."
] | 746323f3087af5a06769f7c207ab4ed5124a14bb | https://github.com/tw88/sso/blob/746323f3087af5a06769f7c207ab4ed5124a14bb/src/Broker.php#L152-L164 | train |
tw88/sso | src/Broker.php | Broker.request | protected function request($method, $command, $data = null)
{
if (!$this->isAttached()) {
throw new NotAttachedException('No token');
}
$url = $this->getRequestUrl($command, !$data || $method === 'POST' ? [] : $data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Accept: application/json', 'Authorization: Bearer '. $this->getSessionID()]);
if ($method === 'POST' && !empty($data)) {
$post = is_string($data) ? $data : http_build_query($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
$response = curl_exec($ch);
if (curl_errno($ch) != 0) {
$message = 'Server request failed: ' . curl_error($ch);
throw new Exception($message);
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
list($contentType) = explode(';', curl_getinfo($ch, CURLINFO_CONTENT_TYPE));
if ($contentType != 'application/json') {
$message = 'Expected application/json response, got ' . $contentType;
throw new Exception($message);
}
$data = json_decode($response, true);
if ($httpCode == 403) {
$this->clearToken();
throw new NotAttachedException($data['error'] ?: $response, $httpCode);
}
if ($httpCode >= 400) {
throw new Exception($data['error'] ?: $response, $httpCode);
}
return $data;
} | php | protected function request($method, $command, $data = null)
{
if (!$this->isAttached()) {
throw new NotAttachedException('No token');
}
$url = $this->getRequestUrl($command, !$data || $method === 'POST' ? [] : $data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Accept: application/json', 'Authorization: Bearer '. $this->getSessionID()]);
if ($method === 'POST' && !empty($data)) {
$post = is_string($data) ? $data : http_build_query($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
$response = curl_exec($ch);
if (curl_errno($ch) != 0) {
$message = 'Server request failed: ' . curl_error($ch);
throw new Exception($message);
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
list($contentType) = explode(';', curl_getinfo($ch, CURLINFO_CONTENT_TYPE));
if ($contentType != 'application/json') {
$message = 'Expected application/json response, got ' . $contentType;
throw new Exception($message);
}
$data = json_decode($response, true);
if ($httpCode == 403) {
$this->clearToken();
throw new NotAttachedException($data['error'] ?: $response, $httpCode);
}
if ($httpCode >= 400) {
throw new Exception($data['error'] ?: $response, $httpCode);
}
return $data;
} | [
"protected",
"function",
"request",
"(",
"$",
"method",
",",
"$",
"command",
",",
"$",
"data",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isAttached",
"(",
")",
")",
"{",
"throw",
"new",
"NotAttachedException",
"(",
"'No token'",
")",
";",
"}",
"$",
"url",
"=",
"$",
"this",
"->",
"getRequestUrl",
"(",
"$",
"command",
",",
"!",
"$",
"data",
"||",
"$",
"method",
"===",
"'POST'",
"?",
"[",
"]",
":",
"$",
"data",
")",
";",
"$",
"ch",
"=",
"curl_init",
"(",
"$",
"url",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_CUSTOMREQUEST",
",",
"$",
"method",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_HTTPHEADER",
",",
"[",
"'Accept: application/json'",
",",
"'Authorization: Bearer '",
".",
"$",
"this",
"->",
"getSessionID",
"(",
")",
"]",
")",
";",
"if",
"(",
"$",
"method",
"===",
"'POST'",
"&&",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"$",
"post",
"=",
"is_string",
"(",
"$",
"data",
")",
"?",
"$",
"data",
":",
"http_build_query",
"(",
"$",
"data",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_POSTFIELDS",
",",
"$",
"post",
")",
";",
"}",
"$",
"response",
"=",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"if",
"(",
"curl_errno",
"(",
"$",
"ch",
")",
"!=",
"0",
")",
"{",
"$",
"message",
"=",
"'Server request failed: '",
".",
"curl_error",
"(",
"$",
"ch",
")",
";",
"throw",
"new",
"Exception",
"(",
"$",
"message",
")",
";",
"}",
"$",
"httpCode",
"=",
"curl_getinfo",
"(",
"$",
"ch",
",",
"CURLINFO_HTTP_CODE",
")",
";",
"list",
"(",
"$",
"contentType",
")",
"=",
"explode",
"(",
"';'",
",",
"curl_getinfo",
"(",
"$",
"ch",
",",
"CURLINFO_CONTENT_TYPE",
")",
")",
";",
"if",
"(",
"$",
"contentType",
"!=",
"'application/json'",
")",
"{",
"$",
"message",
"=",
"'Expected application/json response, got '",
".",
"$",
"contentType",
";",
"throw",
"new",
"Exception",
"(",
"$",
"message",
")",
";",
"}",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"response",
",",
"true",
")",
";",
"if",
"(",
"$",
"httpCode",
"==",
"403",
")",
"{",
"$",
"this",
"->",
"clearToken",
"(",
")",
";",
"throw",
"new",
"NotAttachedException",
"(",
"$",
"data",
"[",
"'error'",
"]",
"?",
":",
"$",
"response",
",",
"$",
"httpCode",
")",
";",
"}",
"if",
"(",
"$",
"httpCode",
">=",
"400",
")",
"{",
"throw",
"new",
"Exception",
"(",
"$",
"data",
"[",
"'error'",
"]",
"?",
":",
"$",
"response",
",",
"$",
"httpCode",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Execute on SSO server.
@param string $method HTTP method: 'GET', 'POST', 'DELETE'
@param string $command Command
@param array|string $data Query or post parameters
@return array|object | [
"Execute",
"on",
"SSO",
"server",
"."
] | 746323f3087af5a06769f7c207ab4ed5124a14bb | https://github.com/tw88/sso/blob/746323f3087af5a06769f7c207ab4ed5124a14bb/src/Broker.php#L227-L269 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.