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 |
---|---|---|---|---|---|---|---|---|---|---|---|
koolkode/context | src/Bind/ContainerInitializerLoader.php | ContainerInitializerLoader.getHash | public function getHash()
{
$names = array_keys($this->initializers);
sort($names);
return md5(implode('|', $names));
} | php | public function getHash()
{
$names = array_keys($this->initializers);
sort($names);
return md5(implode('|', $names));
} | [
"public",
"function",
"getHash",
"(",
")",
"{",
"$",
"names",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"initializers",
")",
";",
"sort",
"(",
"$",
"names",
")",
";",
"return",
"md5",
"(",
"implode",
"(",
"'|'",
",",
"$",
"names",
")",
")",
";",
"}"
] | Get an MD5 hash computed from the sorted type names of all initializers.
@return string | [
"Get",
"an",
"MD5",
"hash",
"computed",
"from",
"the",
"sorted",
"type",
"names",
"of",
"all",
"initializers",
"."
] | f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36 | https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/Bind/ContainerInitializerLoader.php#L63-L69 | train |
koolkode/context | src/Bind/ContainerInitializerLoader.php | ContainerInitializerLoader.getLastModified | public function getLastModified()
{
$mtime = 0;
foreach($this->initializers as $initializer)
{
$mtime = max($mtime, filemtime((new \ReflectionClass(get_class($initializer)))->getFileName()));
}
return $mtime;
} | php | public function getLastModified()
{
$mtime = 0;
foreach($this->initializers as $initializer)
{
$mtime = max($mtime, filemtime((new \ReflectionClass(get_class($initializer)))->getFileName()));
}
return $mtime;
} | [
"public",
"function",
"getLastModified",
"(",
")",
"{",
"$",
"mtime",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"initializers",
"as",
"$",
"initializer",
")",
"{",
"$",
"mtime",
"=",
"max",
"(",
"$",
"mtime",
",",
"filemtime",
"(",
"(",
"new",
"\\",
"ReflectionClass",
"(",
"get_class",
"(",
"$",
"initializer",
")",
")",
")",
"->",
"getFileName",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"mtime",
";",
"}"
] | Get the time of the most recent modification to an initializer.
@return integer | [
"Get",
"the",
"time",
"of",
"the",
"most",
"recent",
"modification",
"to",
"an",
"initializer",
"."
] | f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36 | https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/Bind/ContainerInitializerLoader.php#L76-L86 | train |
koolkode/context | src/Bind/ContainerInitializerLoader.php | ContainerInitializerLoader.registerInitializer | public function registerInitializer(ContainerInitializerInterface $initializer)
{
$key = get_class($initializer);
if(empty($this->initializers[$key]))
{
$this->initializers[$key] = $initializer;
}
return $this;
} | php | public function registerInitializer(ContainerInitializerInterface $initializer)
{
$key = get_class($initializer);
if(empty($this->initializers[$key]))
{
$this->initializers[$key] = $initializer;
}
return $this;
} | [
"public",
"function",
"registerInitializer",
"(",
"ContainerInitializerInterface",
"$",
"initializer",
")",
"{",
"$",
"key",
"=",
"get_class",
"(",
"$",
"initializer",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"initializers",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"initializers",
"[",
"$",
"key",
"]",
"=",
"$",
"initializer",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Register a container initializer if it has not been registered yet.
@param ContainerInitializerInterface $initializer
@return ContainerInitializerLoader | [
"Register",
"a",
"container",
"initializer",
"if",
"it",
"has",
"not",
"been",
"registered",
"yet",
"."
] | f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36 | https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/Bind/ContainerInitializerLoader.php#L94-L104 | train |
larapulse/support | src/Helpers/Regex.php | Regex.fetchQuantifier | public static function fetchQuantifier($min = null, $max = INF, bool $lazyLoad = false) : string
{
$lazy = $lazyLoad ? '?' : '';
switch (true) {
case ($min === 0 && $max === 1):
return '?'.$lazy;
case ($min === 0 && $max === INF):
return '*'.$lazy;
case ($min === 1 && $max === INF):
return '+'.$lazy;
case (is_int($min) && $min >= 1 && $max === null):
return '{'.$min.'}'.$lazy;
case (is_int($min) && (is_int($max) || $max === INF)):
$max = is_int($max) ? $max : '';
return '{'.$min.','.$max.'}'.$lazy;
default:
return '';
}
} | php | public static function fetchQuantifier($min = null, $max = INF, bool $lazyLoad = false) : string
{
$lazy = $lazyLoad ? '?' : '';
switch (true) {
case ($min === 0 && $max === 1):
return '?'.$lazy;
case ($min === 0 && $max === INF):
return '*'.$lazy;
case ($min === 1 && $max === INF):
return '+'.$lazy;
case (is_int($min) && $min >= 1 && $max === null):
return '{'.$min.'}'.$lazy;
case (is_int($min) && (is_int($max) || $max === INF)):
$max = is_int($max) ? $max : '';
return '{'.$min.','.$max.'}'.$lazy;
default:
return '';
}
} | [
"public",
"static",
"function",
"fetchQuantifier",
"(",
"$",
"min",
"=",
"null",
",",
"$",
"max",
"=",
"INF",
",",
"bool",
"$",
"lazyLoad",
"=",
"false",
")",
":",
"string",
"{",
"$",
"lazy",
"=",
"$",
"lazyLoad",
"?",
"'?'",
":",
"''",
";",
"switch",
"(",
"true",
")",
"{",
"case",
"(",
"$",
"min",
"===",
"0",
"&&",
"$",
"max",
"===",
"1",
")",
":",
"return",
"'?'",
".",
"$",
"lazy",
";",
"case",
"(",
"$",
"min",
"===",
"0",
"&&",
"$",
"max",
"===",
"INF",
")",
":",
"return",
"'*'",
".",
"$",
"lazy",
";",
"case",
"(",
"$",
"min",
"===",
"1",
"&&",
"$",
"max",
"===",
"INF",
")",
":",
"return",
"'+'",
".",
"$",
"lazy",
";",
"case",
"(",
"is_int",
"(",
"$",
"min",
")",
"&&",
"$",
"min",
">=",
"1",
"&&",
"$",
"max",
"===",
"null",
")",
":",
"return",
"'{'",
".",
"$",
"min",
".",
"'}'",
".",
"$",
"lazy",
";",
"case",
"(",
"is_int",
"(",
"$",
"min",
")",
"&&",
"(",
"is_int",
"(",
"$",
"max",
")",
"||",
"$",
"max",
"===",
"INF",
")",
")",
":",
"$",
"max",
"=",
"is_int",
"(",
"$",
"max",
")",
"?",
"$",
"max",
":",
"''",
";",
"return",
"'{'",
".",
"$",
"min",
".",
"','",
".",
"$",
"max",
".",
"'}'",
".",
"$",
"lazy",
";",
"default",
":",
"return",
"''",
";",
"}",
"}"
] | Build quantifier from parameters
@param int|null $min
@param float|int $max
@param bool $lazyLoad
@return string | [
"Build",
"quantifier",
"from",
"parameters"
] | 601ee3fd6967be669afe081322340c82c7edf32d | https://github.com/larapulse/support/blob/601ee3fd6967be669afe081322340c82c7edf32d/src/Helpers/Regex.php#L23-L42 | train |
locomotivemtl/charcoal-translator | src/Charcoal/Translator/Script/TranslationParserScript.php | TranslationParserScript.displayInformations | protected function displayInformations()
{
$this->climate()->underline()->out(
'Initializing translations parser script...'
);
$this->climate()->green()->out(
'CSV file output: <white>'.$this->filePath().'</white>'
);
$this->climate()->green()->out(
'CSV file names: <white>'.$this->domain().'.{locale}.csv</white>'
);
$this->climate()->green()->out(
'Looping through <white>'.$this->maxRecursiveLevel().'</white> level of folders'
);
$this->climate()->green()->out(
'File type parsed: <white>mustache</white>'
);
return $this;
} | php | protected function displayInformations()
{
$this->climate()->underline()->out(
'Initializing translations parser script...'
);
$this->climate()->green()->out(
'CSV file output: <white>'.$this->filePath().'</white>'
);
$this->climate()->green()->out(
'CSV file names: <white>'.$this->domain().'.{locale}.csv</white>'
);
$this->climate()->green()->out(
'Looping through <white>'.$this->maxRecursiveLevel().'</white> level of folders'
);
$this->climate()->green()->out(
'File type parsed: <white>mustache</white>'
);
return $this;
} | [
"protected",
"function",
"displayInformations",
"(",
")",
"{",
"$",
"this",
"->",
"climate",
"(",
")",
"->",
"underline",
"(",
")",
"->",
"out",
"(",
"'Initializing translations parser script...'",
")",
";",
"$",
"this",
"->",
"climate",
"(",
")",
"->",
"green",
"(",
")",
"->",
"out",
"(",
"'CSV file output: <white>'",
".",
"$",
"this",
"->",
"filePath",
"(",
")",
".",
"'</white>'",
")",
";",
"$",
"this",
"->",
"climate",
"(",
")",
"->",
"green",
"(",
")",
"->",
"out",
"(",
"'CSV file names: <white>'",
".",
"$",
"this",
"->",
"domain",
"(",
")",
".",
"'.{locale}.csv</white>'",
")",
";",
"$",
"this",
"->",
"climate",
"(",
")",
"->",
"green",
"(",
")",
"->",
"out",
"(",
"'Looping through <white>'",
".",
"$",
"this",
"->",
"maxRecursiveLevel",
"(",
")",
".",
"'</white> level of folders'",
")",
";",
"$",
"this",
"->",
"climate",
"(",
")",
"->",
"green",
"(",
")",
"->",
"out",
"(",
"'File type parsed: <white>mustache</white>'",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Give feedback about what's going on.
@return self Chainable. | [
"Give",
"feedback",
"about",
"what",
"s",
"going",
"on",
"."
] | 0a64432baef223dcccbfecf057015440dfa76e49 | https://github.com/locomotivemtl/charcoal-translator/blob/0a64432baef223dcccbfecf057015440dfa76e49/src/Charcoal/Translator/Script/TranslationParserScript.php#L205-L228 | train |
locomotivemtl/charcoal-translator | src/Charcoal/Translator/Script/TranslationParserScript.php | TranslationParserScript.filePath | protected function filePath()
{
if ($this->filePath) {
return $this->filePath;
}
$base = $this->appConfig->get('base_path');
$output = $this->output();
$this->filePath = str_replace('/', DIRECTORY_SEPARATOR, $base.$output);
return $this->filePath;
} | php | protected function filePath()
{
if ($this->filePath) {
return $this->filePath;
}
$base = $this->appConfig->get('base_path');
$output = $this->output();
$this->filePath = str_replace('/', DIRECTORY_SEPARATOR, $base.$output);
return $this->filePath;
} | [
"protected",
"function",
"filePath",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"filePath",
")",
"{",
"return",
"$",
"this",
"->",
"filePath",
";",
"}",
"$",
"base",
"=",
"$",
"this",
"->",
"appConfig",
"->",
"get",
"(",
"'base_path'",
")",
";",
"$",
"output",
"=",
"$",
"this",
"->",
"output",
"(",
")",
";",
"$",
"this",
"->",
"filePath",
"=",
"str_replace",
"(",
"'/'",
",",
"DIRECTORY_SEPARATOR",
",",
"$",
"base",
".",
"$",
"output",
")",
";",
"return",
"$",
"this",
"->",
"filePath",
";",
"}"
] | Complete filepath to the CSV location.
@return string Filepath to the csv. | [
"Complete",
"filepath",
"to",
"the",
"CSV",
"location",
"."
] | 0a64432baef223dcccbfecf057015440dfa76e49 | https://github.com/locomotivemtl/charcoal-translator/blob/0a64432baef223dcccbfecf057015440dfa76e49/src/Charcoal/Translator/Script/TranslationParserScript.php#L234-L244 | train |
locomotivemtl/charcoal-translator | src/Charcoal/Translator/Script/TranslationParserScript.php | TranslationParserScript.regEx | public function regEx($type)
{
switch ($type) {
case 'php':
$f = $this->phpFunction();
$regex = '/->'.$f.'\(\s*\n*\r*(["\'])(?<text>(.|\n|\r|\n\r)*?)\s*\n*\r*\1\)/i';
break;
case 'mustache':
$tag = $this->mustacheTag();
$regex = '/({{|\[\[)\s*#\s*'.$tag.'\s*(}}|\]\])(?<text>(.|\n|\r|\n\r)*?)({{|\[\[)\s*\/\s*'.$tag.'\s*(}}|\]\])/i';
break;
default:
$regex = '/({{|\[\[)\s*#\s*_t\s*(}}|\]\])(?<text>(.|\n|\r|\n\r)*?)({{|\[\[)\s*\/\s*_t\s*(}}|\]\])/i';
break;
}
return $regex;
} | php | public function regEx($type)
{
switch ($type) {
case 'php':
$f = $this->phpFunction();
$regex = '/->'.$f.'\(\s*\n*\r*(["\'])(?<text>(.|\n|\r|\n\r)*?)\s*\n*\r*\1\)/i';
break;
case 'mustache':
$tag = $this->mustacheTag();
$regex = '/({{|\[\[)\s*#\s*'.$tag.'\s*(}}|\]\])(?<text>(.|\n|\r|\n\r)*?)({{|\[\[)\s*\/\s*'.$tag.'\s*(}}|\]\])/i';
break;
default:
$regex = '/({{|\[\[)\s*#\s*_t\s*(}}|\]\])(?<text>(.|\n|\r|\n\r)*?)({{|\[\[)\s*\/\s*_t\s*(}}|\]\])/i';
break;
}
return $regex;
} | [
"public",
"function",
"regEx",
"(",
"$",
"type",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'php'",
":",
"$",
"f",
"=",
"$",
"this",
"->",
"phpFunction",
"(",
")",
";",
"$",
"regex",
"=",
"'/->'",
".",
"$",
"f",
".",
"'\\(\\s*\\n*\\r*([\"\\'])(?<text>(.|\\n|\\r|\\n\\r)*?)\\s*\\n*\\r*\\1\\)/i'",
";",
"break",
";",
"case",
"'mustache'",
":",
"$",
"tag",
"=",
"$",
"this",
"->",
"mustacheTag",
"(",
")",
";",
"$",
"regex",
"=",
"'/({{|\\[\\[)\\s*#\\s*'",
".",
"$",
"tag",
".",
"'\\s*(}}|\\]\\])(?<text>(.|\\n|\\r|\\n\\r)*?)({{|\\[\\[)\\s*\\/\\s*'",
".",
"$",
"tag",
".",
"'\\s*(}}|\\]\\])/i'",
";",
"break",
";",
"default",
":",
"$",
"regex",
"=",
"'/({{|\\[\\[)\\s*#\\s*_t\\s*(}}|\\]\\])(?<text>(.|\\n|\\r|\\n\\r)*?)({{|\\[\\[)\\s*\\/\\s*_t\\s*(}}|\\]\\])/i'",
";",
"break",
";",
"}",
"return",
"$",
"regex",
";",
"}"
] | Regex to match in files.
@param string $type File type (mustache|php).
@return string Regex string. | [
"Regex",
"to",
"match",
"in",
"files",
"."
] | 0a64432baef223dcccbfecf057015440dfa76e49 | https://github.com/locomotivemtl/charcoal-translator/blob/0a64432baef223dcccbfecf057015440dfa76e49/src/Charcoal/Translator/Script/TranslationParserScript.php#L291-L310 | train |
OxfordInfoLabs/kinikit-core | src/Util/Caching/FileCache.php | FileCache.getCachedFile | public function getCachedFile($cacheKey) {
// Get directory and filename
list($directory, $filename) = $this->getDirectoryAndFilenameFromKey($cacheKey);
if (file_exists($directory . "/" . $filename) && !is_dir($directory . "/" . $filename)) {
return file_get_contents($directory . "/" . $filename);
}
return null;
} | php | public function getCachedFile($cacheKey) {
// Get directory and filename
list($directory, $filename) = $this->getDirectoryAndFilenameFromKey($cacheKey);
if (file_exists($directory . "/" . $filename) && !is_dir($directory . "/" . $filename)) {
return file_get_contents($directory . "/" . $filename);
}
return null;
} | [
"public",
"function",
"getCachedFile",
"(",
"$",
"cacheKey",
")",
"{",
"// Get directory and filename",
"list",
"(",
"$",
"directory",
",",
"$",
"filename",
")",
"=",
"$",
"this",
"->",
"getDirectoryAndFilenameFromKey",
"(",
"$",
"cacheKey",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"directory",
".",
"\"/\"",
".",
"$",
"filename",
")",
"&&",
"!",
"is_dir",
"(",
"$",
"directory",
".",
"\"/\"",
".",
"$",
"filename",
")",
")",
"{",
"return",
"file_get_contents",
"(",
"$",
"directory",
".",
"\"/\"",
".",
"$",
"filename",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Get a cached file using the cache key - either a string or an array of keys
@param mixed $cacheKey | [
"Get",
"a",
"cached",
"file",
"using",
"the",
"cache",
"key",
"-",
"either",
"a",
"string",
"or",
"an",
"array",
"of",
"keys"
] | edc1b2e6ffabd595c4c7d322279b3dd1e59ef359 | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/Caching/FileCache.php#L31-L43 | train |
OxfordInfoLabs/kinikit-core | src/Util/Caching/FileCache.php | FileCache.cacheFile | public function cacheFile($cacheKey, $fileContents) {
// Get directory and filename
list($directory, $filename) = $this->getDirectoryAndFilenameFromKey($cacheKey);
// Make the cache directory
if (!file_exists($directory)) mkdir($directory, 0777, true);
// Save the file
file_put_contents($directory . "/" . $filename, $fileContents);
} | php | public function cacheFile($cacheKey, $fileContents) {
// Get directory and filename
list($directory, $filename) = $this->getDirectoryAndFilenameFromKey($cacheKey);
// Make the cache directory
if (!file_exists($directory)) mkdir($directory, 0777, true);
// Save the file
file_put_contents($directory . "/" . $filename, $fileContents);
} | [
"public",
"function",
"cacheFile",
"(",
"$",
"cacheKey",
",",
"$",
"fileContents",
")",
"{",
"// Get directory and filename",
"list",
"(",
"$",
"directory",
",",
"$",
"filename",
")",
"=",
"$",
"this",
"->",
"getDirectoryAndFilenameFromKey",
"(",
"$",
"cacheKey",
")",
";",
"// Make the cache directory",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"directory",
")",
")",
"mkdir",
"(",
"$",
"directory",
",",
"0777",
",",
"true",
")",
";",
"// Save the file",
"file_put_contents",
"(",
"$",
"directory",
".",
"\"/\"",
".",
"$",
"filename",
",",
"$",
"fileContents",
")",
";",
"}"
] | Cache a file using the file contents - overwrite if necessary.
@param $cacheKey
@param $fileContents | [
"Cache",
"a",
"file",
"using",
"the",
"file",
"contents",
"-",
"overwrite",
"if",
"necessary",
"."
] | edc1b2e6ffabd595c4c7d322279b3dd1e59ef359 | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/Caching/FileCache.php#L51-L62 | train |
OxfordInfoLabs/kinikit-core | src/Util/Caching/FileCache.php | FileCache.getDirectoryAndFilenameFromKey | private function getDirectoryAndFilenameFromKey($cacheKey) {
if (!is_array($cacheKey)) {
$cacheKey = array($cacheKey);
}
$filename = array_pop($cacheKey);
$dir = $this->cacheBaseDir . "/" . join("/", $cacheKey);
// Return dir and filename
return array($dir, $filename);
} | php | private function getDirectoryAndFilenameFromKey($cacheKey) {
if (!is_array($cacheKey)) {
$cacheKey = array($cacheKey);
}
$filename = array_pop($cacheKey);
$dir = $this->cacheBaseDir . "/" . join("/", $cacheKey);
// Return dir and filename
return array($dir, $filename);
} | [
"private",
"function",
"getDirectoryAndFilenameFromKey",
"(",
"$",
"cacheKey",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"cacheKey",
")",
")",
"{",
"$",
"cacheKey",
"=",
"array",
"(",
"$",
"cacheKey",
")",
";",
"}",
"$",
"filename",
"=",
"array_pop",
"(",
"$",
"cacheKey",
")",
";",
"$",
"dir",
"=",
"$",
"this",
"->",
"cacheBaseDir",
".",
"\"/\"",
".",
"join",
"(",
"\"/\"",
",",
"$",
"cacheKey",
")",
";",
"// Return dir and filename",
"return",
"array",
"(",
"$",
"dir",
",",
"$",
"filename",
")",
";",
"}"
] | Get the filename and directory from a key | [
"Get",
"the",
"filename",
"and",
"directory",
"from",
"a",
"key"
] | edc1b2e6ffabd595c4c7d322279b3dd1e59ef359 | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/Caching/FileCache.php#L82-L95 | train |
miBadger/miBadger.Enum | src/Enum.php | Enum.getOrdinal | public function getOrdinal()
{
$ordinal = array_search($this->value, array_values(static::toArray()));
return $ordinal !== false ? $ordinal : -1;
} | php | public function getOrdinal()
{
$ordinal = array_search($this->value, array_values(static::toArray()));
return $ordinal !== false ? $ordinal : -1;
} | [
"public",
"function",
"getOrdinal",
"(",
")",
"{",
"$",
"ordinal",
"=",
"array_search",
"(",
"$",
"this",
"->",
"value",
",",
"array_values",
"(",
"static",
"::",
"toArray",
"(",
")",
")",
")",
";",
"return",
"$",
"ordinal",
"!==",
"false",
"?",
"$",
"ordinal",
":",
"-",
"1",
";",
"}"
] | Returns the ordinal.
@return int the ordinal. | [
"Returns",
"the",
"ordinal",
"."
] | e0ed0e9c69630442b498ce2900021440224a4a15 | https://github.com/miBadger/miBadger.Enum/blob/e0ed0e9c69630442b498ce2900021440224a4a15/src/Enum.php#L54-L59 | train |
TiMESPLiNTER/tsFramework | src/ch/timesplinter/auth/AuthHandlerHttp.php | AuthHandlerHttp.http_digest_parse | private function http_digest_parse($txt) {
// gegen fehlende Daten schützen
$noetige_teile = array('nonce' => 1
,'nc' => 1
,'cnonce' => 1
,'qop' => 1
,'username' => 1
,'uri' => 1
,'response' => 1
);
$daten = array();
$schluessel = implode('|', array_keys($noetige_teile));
preg_match_all('@(' . $schluessel . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@', $txt, $treffer, PREG_SET_ORDER);
foreach ($treffer as $t) {
$daten[$t[1]] = $t[3] ? $t[3] : $t[4];
unset($noetige_teile[$t[1]]);
}
return $noetige_teile ? false : $daten;
} | php | private function http_digest_parse($txt) {
// gegen fehlende Daten schützen
$noetige_teile = array('nonce' => 1
,'nc' => 1
,'cnonce' => 1
,'qop' => 1
,'username' => 1
,'uri' => 1
,'response' => 1
);
$daten = array();
$schluessel = implode('|', array_keys($noetige_teile));
preg_match_all('@(' . $schluessel . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@', $txt, $treffer, PREG_SET_ORDER);
foreach ($treffer as $t) {
$daten[$t[1]] = $t[3] ? $t[3] : $t[4];
unset($noetige_teile[$t[1]]);
}
return $noetige_teile ? false : $daten;
} | [
"private",
"function",
"http_digest_parse",
"(",
"$",
"txt",
")",
"{",
"// gegen fehlende Daten schützen",
"$",
"noetige_teile",
"=",
"array",
"(",
"'nonce'",
"=>",
"1",
",",
"'nc'",
"=>",
"1",
",",
"'cnonce'",
"=>",
"1",
",",
"'qop'",
"=>",
"1",
",",
"'username'",
"=>",
"1",
",",
"'uri'",
"=>",
"1",
",",
"'response'",
"=>",
"1",
")",
";",
"$",
"daten",
"=",
"array",
"(",
")",
";",
"$",
"schluessel",
"=",
"implode",
"(",
"'|'",
",",
"array_keys",
"(",
"$",
"noetige_teile",
")",
")",
";",
"preg_match_all",
"(",
"'@('",
".",
"$",
"schluessel",
".",
"')=(?:([\\'\"])([^\\2]+?)\\2|([^\\s,]+))@'",
",",
"$",
"txt",
",",
"$",
"treffer",
",",
"PREG_SET_ORDER",
")",
";",
"foreach",
"(",
"$",
"treffer",
"as",
"$",
"t",
")",
"{",
"$",
"daten",
"[",
"$",
"t",
"[",
"1",
"]",
"]",
"=",
"$",
"t",
"[",
"3",
"]",
"?",
"$",
"t",
"[",
"3",
"]",
":",
"$",
"t",
"[",
"4",
"]",
";",
"unset",
"(",
"$",
"noetige_teile",
"[",
"$",
"t",
"[",
"1",
"]",
"]",
")",
";",
"}",
"return",
"$",
"noetige_teile",
"?",
"false",
":",
"$",
"daten",
";",
"}"
] | Funktion zum analysieren der HTTP-Auth-Header | [
"Funktion",
"zum",
"analysieren",
"der",
"HTTP",
"-",
"Auth",
"-",
"Header"
] | b3b9fd98f6d456a9e571015877ecca203786fd0c | https://github.com/TiMESPLiNTER/tsFramework/blob/b3b9fd98f6d456a9e571015877ecca203786fd0c/src/ch/timesplinter/auth/AuthHandlerHttp.php#L93-L115 | train |
loevgaard/dandomain-foundation-entities | src/Entity/QueueItem.php | QueueItem.create | public static function create(string $identifier, string $type): QueueItemInterface
{
$queueItem = new self();
$queueItem
->setIdentifier($identifier)
->setType($type);
return $queueItem;
} | php | public static function create(string $identifier, string $type): QueueItemInterface
{
$queueItem = new self();
$queueItem
->setIdentifier($identifier)
->setType($type);
return $queueItem;
} | [
"public",
"static",
"function",
"create",
"(",
"string",
"$",
"identifier",
",",
"string",
"$",
"type",
")",
":",
"QueueItemInterface",
"{",
"$",
"queueItem",
"=",
"new",
"self",
"(",
")",
";",
"$",
"queueItem",
"->",
"setIdentifier",
"(",
"$",
"identifier",
")",
"->",
"setType",
"(",
"$",
"type",
")",
";",
"return",
"$",
"queueItem",
";",
"}"
] | The create method creates a valid queue item object.
@param string $identifier
@param string $type
@return QueueItemInterface | [
"The",
"create",
"method",
"creates",
"a",
"valid",
"queue",
"item",
"object",
"."
] | 256f7aa8b40d2bd9488046c3c2b1e04e982d78ad | https://github.com/loevgaard/dandomain-foundation-entities/blob/256f7aa8b40d2bd9488046c3c2b1e04e982d78ad/src/Entity/QueueItem.php#L110-L118 | train |
rzajac/phptools | src/Helper/Str.php | Str.getRandomWeightedElement | public static function getRandomWeightedElement(array $weightedValues, $default = 1)
{
$sum = (int) array_sum($weightedValues);
$min = 1;
$rand = mt_rand(min($min, $sum), max($min, $sum));
$ret = $default;
foreach ($weightedValues as $key => $value) {
$rand -= (int) $value;
if ($rand <= 0) {
$ret = $key;
break;
}
}
return $ret;
} | php | public static function getRandomWeightedElement(array $weightedValues, $default = 1)
{
$sum = (int) array_sum($weightedValues);
$min = 1;
$rand = mt_rand(min($min, $sum), max($min, $sum));
$ret = $default;
foreach ($weightedValues as $key => $value) {
$rand -= (int) $value;
if ($rand <= 0) {
$ret = $key;
break;
}
}
return $ret;
} | [
"public",
"static",
"function",
"getRandomWeightedElement",
"(",
"array",
"$",
"weightedValues",
",",
"$",
"default",
"=",
"1",
")",
"{",
"$",
"sum",
"=",
"(",
"int",
")",
"array_sum",
"(",
"$",
"weightedValues",
")",
";",
"$",
"min",
"=",
"1",
";",
"$",
"rand",
"=",
"mt_rand",
"(",
"min",
"(",
"$",
"min",
",",
"$",
"sum",
")",
",",
"max",
"(",
"$",
"min",
",",
"$",
"sum",
")",
")",
";",
"$",
"ret",
"=",
"$",
"default",
";",
"foreach",
"(",
"$",
"weightedValues",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"rand",
"-=",
"(",
"int",
")",
"$",
"value",
";",
"if",
"(",
"$",
"rand",
"<=",
"0",
")",
"{",
"$",
"ret",
"=",
"$",
"key",
";",
"break",
";",
"}",
"}",
"return",
"$",
"ret",
";",
"}"
] | Get random weighted element.
Utility function for getting random values with weighting.
Pass in an associative array, such as array('A'=>5, 'B'=>45, 'C'=>50)
An array like this means that "A" has a 5% chance of being selected, "B" 45%, and "C" 50%.
The return value is the array key, A, B, or C in this case. Note that the values assigned
do not have to be percentages. The values are simply relative to each other. If one value
weight was 2, and the other weight of 1, the value with the weight of 2 has about a 66%
chance of being selected. Also note that weights should be integers.
@param array $weightedValues
@param int $default
@return int | [
"Get",
"random",
"weighted",
"element",
"."
] | 3cbece7645942d244603c14ba897d8a676ee3088 | https://github.com/rzajac/phptools/blob/3cbece7645942d244603c14ba897d8a676ee3088/src/Helper/Str.php#L95-L114 | train |
rzajac/phptools | src/Helper/Str.php | Str.toString | public static function toString($value)
{
if (is_null($value)) {
$ret = 'null';
} elseif (is_bool($value)) {
$ret = $value ? 'true' : 'false';
} elseif (is_array($value)) {
$ret = '[' . implode(',', $value) . ']';
} else if ((!is_object($value) && settype($value, 'string') !== false)
|| (is_object($value) && method_exists($value, '__toString'))
) {
$ret = '' . $value;
} else {
$ret = '[no string representation]';
}
return $ret;
} | php | public static function toString($value)
{
if (is_null($value)) {
$ret = 'null';
} elseif (is_bool($value)) {
$ret = $value ? 'true' : 'false';
} elseif (is_array($value)) {
$ret = '[' . implode(',', $value) . ']';
} else if ((!is_object($value) && settype($value, 'string') !== false)
|| (is_object($value) && method_exists($value, '__toString'))
) {
$ret = '' . $value;
} else {
$ret = '[no string representation]';
}
return $ret;
} | [
"public",
"static",
"function",
"toString",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"$",
"ret",
"=",
"'null'",
";",
"}",
"elseif",
"(",
"is_bool",
"(",
"$",
"value",
")",
")",
"{",
"$",
"ret",
"=",
"$",
"value",
"?",
"'true'",
":",
"'false'",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"ret",
"=",
"'['",
".",
"implode",
"(",
"','",
",",
"$",
"value",
")",
".",
"']'",
";",
"}",
"else",
"if",
"(",
"(",
"!",
"is_object",
"(",
"$",
"value",
")",
"&&",
"settype",
"(",
"$",
"value",
",",
"'string'",
")",
"!==",
"false",
")",
"||",
"(",
"is_object",
"(",
"$",
"value",
")",
"&&",
"method_exists",
"(",
"$",
"value",
",",
"'__toString'",
")",
")",
")",
"{",
"$",
"ret",
"=",
"''",
".",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"ret",
"=",
"'[no string representation]'",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Cast anything to string.
@param mixed $value The value to cast to string.
@return string | [
"Cast",
"anything",
"to",
"string",
"."
] | 3cbece7645942d244603c14ba897d8a676ee3088 | https://github.com/rzajac/phptools/blob/3cbece7645942d244603c14ba897d8a676ee3088/src/Helper/Str.php#L227-L244 | train |
rzajac/phptools | src/Helper/Str.php | Str.contains | public static function contains($haystack, $needle, $ignoreCase = false)
{
if ($ignoreCase) {
$needle = strtolower($needle);
$haystack = strtolower($haystack);
}
$pos = strpos($haystack, $needle);
return !($pos === false);
} | php | public static function contains($haystack, $needle, $ignoreCase = false)
{
if ($ignoreCase) {
$needle = strtolower($needle);
$haystack = strtolower($haystack);
}
$pos = strpos($haystack, $needle);
return !($pos === false);
} | [
"public",
"static",
"function",
"contains",
"(",
"$",
"haystack",
",",
"$",
"needle",
",",
"$",
"ignoreCase",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"ignoreCase",
")",
"{",
"$",
"needle",
"=",
"strtolower",
"(",
"$",
"needle",
")",
";",
"$",
"haystack",
"=",
"strtolower",
"(",
"$",
"haystack",
")",
";",
"}",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"haystack",
",",
"$",
"needle",
")",
";",
"return",
"!",
"(",
"$",
"pos",
"===",
"false",
")",
";",
"}"
] | Return true if haystack contains needle.
@param string $haystack The string to check for needle existence.
@param string $needle The string to find in the haystack.
@param bool $ignoreCase Set to true to ignore case.
@return bool | [
"Return",
"true",
"if",
"haystack",
"contains",
"needle",
"."
] | 3cbece7645942d244603c14ba897d8a676ee3088 | https://github.com/rzajac/phptools/blob/3cbece7645942d244603c14ba897d8a676ee3088/src/Helper/Str.php#L255-L264 | train |
frameworkwtf/core | src/Root.php | Root.setData | public function setData(array $data): self
{
$this->data = \array_merge($this->data, $data);
return $this;
} | php | public function setData(array $data): self
{
$this->data = \array_merge($this->data, $data);
return $this;
} | [
"public",
"function",
"setData",
"(",
"array",
"$",
"data",
")",
":",
"self",
"{",
"$",
"this",
"->",
"data",
"=",
"\\",
"array_merge",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"data",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set all data to entity.
@param array $data
@return Root | [
"Set",
"all",
"data",
"to",
"entity",
"."
] | 8104ca140ec287c26724389780e5e1dba57a030a | https://github.com/frameworkwtf/core/blob/8104ca140ec287c26724389780e5e1dba57a030a/src/Root.php#L127-L132 | train |
jonesiscoding/xq-sassy | src/AbstractSassDriver.php | AbstractSassDriver.setOutputStyle | public function setOutputStyle( $style )
{
$possibleStyles = array(
self::STYLE_NESTED,
self::STYLE_EXPANDED,
self::STYLE_COMPACT,
self::STYLE_COMPRESSED
);
if ( !in_array( $style, $possibleStyles ) )
{
throw new \Exception( 'Invalid output style specified.' );
}
$this->style = $style;
return $this;
} | php | public function setOutputStyle( $style )
{
$possibleStyles = array(
self::STYLE_NESTED,
self::STYLE_EXPANDED,
self::STYLE_COMPACT,
self::STYLE_COMPRESSED
);
if ( !in_array( $style, $possibleStyles ) )
{
throw new \Exception( 'Invalid output style specified.' );
}
$this->style = $style;
return $this;
} | [
"public",
"function",
"setOutputStyle",
"(",
"$",
"style",
")",
"{",
"$",
"possibleStyles",
"=",
"array",
"(",
"self",
"::",
"STYLE_NESTED",
",",
"self",
"::",
"STYLE_EXPANDED",
",",
"self",
"::",
"STYLE_COMPACT",
",",
"self",
"::",
"STYLE_COMPRESSED",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"style",
",",
"$",
"possibleStyles",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Invalid output style specified.'",
")",
";",
"}",
"$",
"this",
"->",
"style",
"=",
"$",
"style",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the output style between the various output styles supported by SASS.
@param int $style One of the output style constants from this class.
@return $this
@throws \Exception If an invalid output style is specified. | [
"Sets",
"the",
"output",
"style",
"between",
"the",
"various",
"output",
"styles",
"supported",
"by",
"SASS",
"."
] | cad2575ac54c997f9bf13233775fb4738dee4bbf | https://github.com/jonesiscoding/xq-sassy/blob/cad2575ac54c997f9bf13233775fb4738dee4bbf/src/AbstractSassDriver.php#L69-L86 | train |
jonesiscoding/xq-sassy | src/AbstractSassDriver.php | AbstractSassDriver.setDefaults | protected function setDefaults()
{
$this->importPaths = array();
$this->pluginPaths = array();
$this->sourceMap = self::DEFAULT_SOURCEMAP;
$this->mapComment = self::DEFAULT_MAPCOMMENT;
$this->lineNumbers = self::DEFAULT_LINENUMBERS;
$this->precision = self::DEFAULT_PRECISION;
$this->style = self::DEFAULT_STYLE;
} | php | protected function setDefaults()
{
$this->importPaths = array();
$this->pluginPaths = array();
$this->sourceMap = self::DEFAULT_SOURCEMAP;
$this->mapComment = self::DEFAULT_MAPCOMMENT;
$this->lineNumbers = self::DEFAULT_LINENUMBERS;
$this->precision = self::DEFAULT_PRECISION;
$this->style = self::DEFAULT_STYLE;
} | [
"protected",
"function",
"setDefaults",
"(",
")",
"{",
"$",
"this",
"->",
"importPaths",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"pluginPaths",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"sourceMap",
"=",
"self",
"::",
"DEFAULT_SOURCEMAP",
";",
"$",
"this",
"->",
"mapComment",
"=",
"self",
"::",
"DEFAULT_MAPCOMMENT",
";",
"$",
"this",
"->",
"lineNumbers",
"=",
"self",
"::",
"DEFAULT_LINENUMBERS",
";",
"$",
"this",
"->",
"precision",
"=",
"self",
"::",
"DEFAULT_PRECISION",
";",
"$",
"this",
"->",
"style",
"=",
"self",
"::",
"DEFAULT_STYLE",
";",
"}"
] | Sets the object's properties back to their defaults. | [
"Sets",
"the",
"object",
"s",
"properties",
"back",
"to",
"their",
"defaults",
"."
] | cad2575ac54c997f9bf13233775fb4738dee4bbf | https://github.com/jonesiscoding/xq-sassy/blob/cad2575ac54c997f9bf13233775fb4738dee4bbf/src/AbstractSassDriver.php#L207-L216 | train |
kaiohken1982/Neobazaar | src/Neobazaar/Doctrine/ORM/EntityRepository.php | EntityRepository.findByEncryptedId | public function findByEncryptedId($id, $field = 'id')
{
$hashids = $this->getServiceLocator()->get('neobazaar.service.hashid');
$id = $hashids->decrypt($id);
$id = is_array($id) ? reset($id) : $id;
$options = array();
$qb = $this->_em->createQueryBuilder();
$qb->select(array('a'));
$qb->from($this->getEntityName(), 'a');
$qb->where($qb->expr()->eq('a.' . $field, ':value'));
$qb->setParameter('value', $id);
$result = $qb->getQuery()->getResult();
return reset($result);
} | php | public function findByEncryptedId($id, $field = 'id')
{
$hashids = $this->getServiceLocator()->get('neobazaar.service.hashid');
$id = $hashids->decrypt($id);
$id = is_array($id) ? reset($id) : $id;
$options = array();
$qb = $this->_em->createQueryBuilder();
$qb->select(array('a'));
$qb->from($this->getEntityName(), 'a');
$qb->where($qb->expr()->eq('a.' . $field, ':value'));
$qb->setParameter('value', $id);
$result = $qb->getQuery()->getResult();
return reset($result);
} | [
"public",
"function",
"findByEncryptedId",
"(",
"$",
"id",
",",
"$",
"field",
"=",
"'id'",
")",
"{",
"$",
"hashids",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'neobazaar.service.hashid'",
")",
";",
"$",
"id",
"=",
"$",
"hashids",
"->",
"decrypt",
"(",
"$",
"id",
")",
";",
"$",
"id",
"=",
"is_array",
"(",
"$",
"id",
")",
"?",
"reset",
"(",
"$",
"id",
")",
":",
"$",
"id",
";",
"$",
"options",
"=",
"array",
"(",
")",
";",
"$",
"qb",
"=",
"$",
"this",
"->",
"_em",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"qb",
"->",
"select",
"(",
"array",
"(",
"'a'",
")",
")",
";",
"$",
"qb",
"->",
"from",
"(",
"$",
"this",
"->",
"getEntityName",
"(",
")",
",",
"'a'",
")",
";",
"$",
"qb",
"->",
"where",
"(",
"$",
"qb",
"->",
"expr",
"(",
")",
"->",
"eq",
"(",
"'a.'",
".",
"$",
"field",
",",
"':value'",
")",
")",
";",
"$",
"qb",
"->",
"setParameter",
"(",
"'value'",
",",
"$",
"id",
")",
";",
"$",
"result",
"=",
"$",
"qb",
"->",
"getQuery",
"(",
")",
"->",
"getResult",
"(",
")",
";",
"return",
"reset",
"(",
"$",
"result",
")",
";",
"}"
] | Get an entity using the encrypted ID
@param string $id
@param string $field
@return unknown | [
"Get",
"an",
"entity",
"using",
"the",
"encrypted",
"ID"
] | 288c972dea981d715c4e136edb5dba0318c9e6cb | https://github.com/kaiohken1982/Neobazaar/blob/288c972dea981d715c4e136edb5dba0318c9e6cb/src/Neobazaar/Doctrine/ORM/EntityRepository.php#L47-L62 | train |
kaiohken1982/Neobazaar | src/Neobazaar/Doctrine/ORM/EntityRepository.php | EntityRepository.getEncryptedId | public function getEncryptedId($id)
{
$hashids = $this->getServiceLocator()->get('neobazaar.service.hashid');
$hash = $hashids->encrypt($id);
return $hash;
} | php | public function getEncryptedId($id)
{
$hashids = $this->getServiceLocator()->get('neobazaar.service.hashid');
$hash = $hashids->encrypt($id);
return $hash;
} | [
"public",
"function",
"getEncryptedId",
"(",
"$",
"id",
")",
"{",
"$",
"hashids",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'neobazaar.service.hashid'",
")",
";",
"$",
"hash",
"=",
"$",
"hashids",
"->",
"encrypt",
"(",
"$",
"id",
")",
";",
"return",
"$",
"hash",
";",
"}"
] | Return the encrypted id using hash id service
@param int $id
@return string | [
"Return",
"the",
"encrypted",
"id",
"using",
"hash",
"id",
"service"
] | 288c972dea981d715c4e136edb5dba0318c9e6cb | https://github.com/kaiohken1982/Neobazaar/blob/288c972dea981d715c4e136edb5dba0318c9e6cb/src/Neobazaar/Doctrine/ORM/EntityRepository.php#L70-L76 | train |
xZ1mEFx/yii2-base | helpers/Url.php | Url.removeUrlSegment | public static function removeUrlSegment($url, $segment, $replacement = '/')
{
$preparedSegment = trim($segment, '/');
if (empty($preparedSegment)) {
return $url;
}
preg_match('/^([^?]+?)(\?.+?)?$/', $url, $matches); // get url and get apart
return preg_replace(
'/(?:\/|^)' . $preparedSegment . '(?:\/|$)/i',
$replacement,
(isset($matches[1]) ? $matches[1] : '')
) . (isset($matches[2]) ? $matches[2] : '');
} | php | public static function removeUrlSegment($url, $segment, $replacement = '/')
{
$preparedSegment = trim($segment, '/');
if (empty($preparedSegment)) {
return $url;
}
preg_match('/^([^?]+?)(\?.+?)?$/', $url, $matches); // get url and get apart
return preg_replace(
'/(?:\/|^)' . $preparedSegment . '(?:\/|$)/i',
$replacement,
(isset($matches[1]) ? $matches[1] : '')
) . (isset($matches[2]) ? $matches[2] : '');
} | [
"public",
"static",
"function",
"removeUrlSegment",
"(",
"$",
"url",
",",
"$",
"segment",
",",
"$",
"replacement",
"=",
"'/'",
")",
"{",
"$",
"preparedSegment",
"=",
"trim",
"(",
"$",
"segment",
",",
"'/'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"preparedSegment",
")",
")",
"{",
"return",
"$",
"url",
";",
"}",
"preg_match",
"(",
"'/^([^?]+?)(\\?.+?)?$/'",
",",
"$",
"url",
",",
"$",
"matches",
")",
";",
"// get url and get apart",
"return",
"preg_replace",
"(",
"'/(?:\\/|^)'",
".",
"$",
"preparedSegment",
".",
"'(?:\\/|$)/i'",
",",
"$",
"replacement",
",",
"(",
"isset",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
"?",
"$",
"matches",
"[",
"1",
"]",
":",
"''",
")",
")",
".",
"(",
"isset",
"(",
"$",
"matches",
"[",
"2",
"]",
")",
"?",
"$",
"matches",
"[",
"2",
"]",
":",
"''",
")",
";",
"}"
] | Try to remove URL segment
@param string $url Subject URL
@param string $segment Search segment
@param string $replacement Replacement string
@return string Results URL | [
"Try",
"to",
"remove",
"URL",
"segment"
] | f6633c08ccccb7eb5ac000dfae0db26cb2e0a76a | https://github.com/xZ1mEFx/yii2-base/blob/f6633c08ccccb7eb5ac000dfae0db26cb2e0a76a/helpers/Url.php#L20-L32 | train |
ekyna/MediaBundle | Browser/Browser.php | Browser.findMedias | public function findMedias(array $types = [])
{
if (null === $this->folder) {
throw new \RuntimeException('No folder selected.');
}
$criteria = ['folder' => $this->folder];
if (count($types)) {
$criteria['type'] = $types;
}
/** @var MediaInterface[] $medias */
$medias = $this->repository->findBy($criteria);
foreach ($medias as $media) {
$media
->setThumb($this->thumbGenerator->generateThumbUrl($media))
->setFront($this->thumbGenerator->generateFrontUrl($media))
;
}
return $medias;
} | php | public function findMedias(array $types = [])
{
if (null === $this->folder) {
throw new \RuntimeException('No folder selected.');
}
$criteria = ['folder' => $this->folder];
if (count($types)) {
$criteria['type'] = $types;
}
/** @var MediaInterface[] $medias */
$medias = $this->repository->findBy($criteria);
foreach ($medias as $media) {
$media
->setThumb($this->thumbGenerator->generateThumbUrl($media))
->setFront($this->thumbGenerator->generateFrontUrl($media))
;
}
return $medias;
} | [
"public",
"function",
"findMedias",
"(",
"array",
"$",
"types",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"folder",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'No folder selected.'",
")",
";",
"}",
"$",
"criteria",
"=",
"[",
"'folder'",
"=>",
"$",
"this",
"->",
"folder",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"types",
")",
")",
"{",
"$",
"criteria",
"[",
"'type'",
"]",
"=",
"$",
"types",
";",
"}",
"/** @var MediaInterface[] $medias */",
"$",
"medias",
"=",
"$",
"this",
"->",
"repository",
"->",
"findBy",
"(",
"$",
"criteria",
")",
";",
"foreach",
"(",
"$",
"medias",
"as",
"$",
"media",
")",
"{",
"$",
"media",
"->",
"setThumb",
"(",
"$",
"this",
"->",
"thumbGenerator",
"->",
"generateThumbUrl",
"(",
"$",
"media",
")",
")",
"->",
"setFront",
"(",
"$",
"this",
"->",
"thumbGenerator",
"->",
"generateFrontUrl",
"(",
"$",
"media",
")",
")",
";",
"}",
"return",
"$",
"medias",
";",
"}"
] | Returns the media found in the current folder.
@param array $types
@return MediaInterface[] | [
"Returns",
"the",
"media",
"found",
"in",
"the",
"current",
"folder",
"."
] | 512cf86c801a130a9f17eba8b48d646d23acdbab | https://github.com/ekyna/MediaBundle/blob/512cf86c801a130a9f17eba8b48d646d23acdbab/Browser/Browser.php#L72-L94 | train |
koolkode/lexer | src/AbstractLexer.php | AbstractLexer.tokenizeUrl | public function tokenizeUrl($url)
{
if(!is_file($url))
{
throw new \RuntimeException(sprintf('URL does not point to a valid file: "%s"', $url));
}
$source = @file_get_contents($url);
if($source === false)
{
// @codeCoverageIgnoreStart
throw new \RuntimeException(sprintf('Unable to tokenize contents loaded from: "%s"', $url));
// @codeCoverageIgnoreEnd
}
return $this->tokenize($source);
} | php | public function tokenizeUrl($url)
{
if(!is_file($url))
{
throw new \RuntimeException(sprintf('URL does not point to a valid file: "%s"', $url));
}
$source = @file_get_contents($url);
if($source === false)
{
// @codeCoverageIgnoreStart
throw new \RuntimeException(sprintf('Unable to tokenize contents loaded from: "%s"', $url));
// @codeCoverageIgnoreEnd
}
return $this->tokenize($source);
} | [
"public",
"function",
"tokenizeUrl",
"(",
"$",
"url",
")",
"{",
"if",
"(",
"!",
"is_file",
"(",
"$",
"url",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'URL does not point to a valid file: \"%s\"'",
",",
"$",
"url",
")",
")",
";",
"}",
"$",
"source",
"=",
"@",
"file_get_contents",
"(",
"$",
"url",
")",
";",
"if",
"(",
"$",
"source",
"===",
"false",
")",
"{",
"// @codeCoverageIgnoreStart",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Unable to tokenize contents loaded from: \"%s\"'",
",",
"$",
"url",
")",
")",
";",
"// @codeCoverageIgnoreEnd",
"}",
"return",
"$",
"this",
"->",
"tokenize",
"(",
"$",
"source",
")",
";",
"}"
] | Tokenize the resource at the given url and return the
resulting token sequence.
@param string $url
@return AbstractTokenSequence
@throws \RuntimeException | [
"Tokenize",
"the",
"resource",
"at",
"the",
"given",
"url",
"and",
"return",
"the",
"resulting",
"token",
"sequence",
"."
] | 1f33fb4e95bf3b6b21c63187e503bbe612a1646c | https://github.com/koolkode/lexer/blob/1f33fb4e95bf3b6b21c63187e503bbe612a1646c/src/AbstractLexer.php#L39-L56 | train |
koolkode/lexer | src/AbstractLexer.php | AbstractLexer.readLiteral | protected function readLiteral($input, $delim = '"', $escaper = NULL)
{
$literal = '';
$escaped = false;
$terminated = false;
for($size = strlen($input), $i = 1; $i < $size; $i++)
{
if($input[$i] == $escaper)
{
if($escaped)
{
$literal .= $escaper;
$escaped = false;
continue;
}
$escaped = true;
continue;
}
if($input[$i] == $delim)
{
if($escaped)
{
$escaped = false;
$literal .= $delim;
continue;
}
$terminated = true;
break;
}
$escaped = false;
$literal .= $input[$i];
}
if(!$terminated)
{
throw new \RuntimeException(sprintf('Unterminated literal: %s%s', $delim, $literal));
}
return $literal;
} | php | protected function readLiteral($input, $delim = '"', $escaper = NULL)
{
$literal = '';
$escaped = false;
$terminated = false;
for($size = strlen($input), $i = 1; $i < $size; $i++)
{
if($input[$i] == $escaper)
{
if($escaped)
{
$literal .= $escaper;
$escaped = false;
continue;
}
$escaped = true;
continue;
}
if($input[$i] == $delim)
{
if($escaped)
{
$escaped = false;
$literal .= $delim;
continue;
}
$terminated = true;
break;
}
$escaped = false;
$literal .= $input[$i];
}
if(!$terminated)
{
throw new \RuntimeException(sprintf('Unterminated literal: %s%s', $delim, $literal));
}
return $literal;
} | [
"protected",
"function",
"readLiteral",
"(",
"$",
"input",
",",
"$",
"delim",
"=",
"'\"'",
",",
"$",
"escaper",
"=",
"NULL",
")",
"{",
"$",
"literal",
"=",
"''",
";",
"$",
"escaped",
"=",
"false",
";",
"$",
"terminated",
"=",
"false",
";",
"for",
"(",
"$",
"size",
"=",
"strlen",
"(",
"$",
"input",
")",
",",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<",
"$",
"size",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"input",
"[",
"$",
"i",
"]",
"==",
"$",
"escaper",
")",
"{",
"if",
"(",
"$",
"escaped",
")",
"{",
"$",
"literal",
".=",
"$",
"escaper",
";",
"$",
"escaped",
"=",
"false",
";",
"continue",
";",
"}",
"$",
"escaped",
"=",
"true",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"input",
"[",
"$",
"i",
"]",
"==",
"$",
"delim",
")",
"{",
"if",
"(",
"$",
"escaped",
")",
"{",
"$",
"escaped",
"=",
"false",
";",
"$",
"literal",
".=",
"$",
"delim",
";",
"continue",
";",
"}",
"$",
"terminated",
"=",
"true",
";",
"break",
";",
"}",
"$",
"escaped",
"=",
"false",
";",
"$",
"literal",
".=",
"$",
"input",
"[",
"$",
"i",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"terminated",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Unterminated literal: %s%s'",
",",
"$",
"delim",
",",
"$",
"literal",
")",
")",
";",
"}",
"return",
"$",
"literal",
";",
"}"
] | Reads a literal from the input delimited by the given delimiter.
@param string $input
@param string $delim The delimiter character.
@param string $escaper An escaping character.
@return string Parsed literal value without delimters.
@throws \RuntimeException When an unterminated literal is detected. | [
"Reads",
"a",
"literal",
"from",
"the",
"input",
"delimited",
"by",
"the",
"given",
"delimiter",
"."
] | 1f33fb4e95bf3b6b21c63187e503bbe612a1646c | https://github.com/koolkode/lexer/blob/1f33fb4e95bf3b6b21c63187e503bbe612a1646c/src/AbstractLexer.php#L68-L116 | train |
bkstg/schedule-bundle | Entity/Event.php | Event.addGroup | public function addGroup(GroupInterface $group): self
{
if (!$group instanceof Production) {
throw new Exception('Group type not supported.');
}
$this->groups[] = $group;
return $this;
} | php | public function addGroup(GroupInterface $group): self
{
if (!$group instanceof Production) {
throw new Exception('Group type not supported.');
}
$this->groups[] = $group;
return $this;
} | [
"public",
"function",
"addGroup",
"(",
"GroupInterface",
"$",
"group",
")",
":",
"self",
"{",
"if",
"(",
"!",
"$",
"group",
"instanceof",
"Production",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Group type not supported.'",
")",
";",
"}",
"$",
"this",
"->",
"groups",
"[",
"]",
"=",
"$",
"group",
";",
"return",
"$",
"this",
";",
"}"
] | Add group.
@param Production $group The production.
@return Event | [
"Add",
"group",
"."
] | e64ac897aa7b28bc48319470d65de13cd4788afe | https://github.com/bkstg/schedule-bundle/blob/e64ac897aa7b28bc48319470d65de13cd4788afe/Entity/Event.php#L257-L265 | train |
bkstg/schedule-bundle | Entity/Event.php | Event.addInvitation | public function addInvitation(Invitation $invitation): self
{
$invitation->setEvent($this);
$this->invitations[] = $invitation;
return $this;
} | php | public function addInvitation(Invitation $invitation): self
{
$invitation->setEvent($this);
$this->invitations[] = $invitation;
return $this;
} | [
"public",
"function",
"addInvitation",
"(",
"Invitation",
"$",
"invitation",
")",
":",
"self",
"{",
"$",
"invitation",
"->",
"setEvent",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"invitations",
"[",
"]",
"=",
"$",
"invitation",
";",
"return",
"$",
"this",
";",
"}"
] | Add invitation.
@param Invitation $invitation The invitation.
@return Event | [
"Add",
"invitation",
"."
] | e64ac897aa7b28bc48319470d65de13cd4788afe | https://github.com/bkstg/schedule-bundle/blob/e64ac897aa7b28bc48319470d65de13cd4788afe/Entity/Event.php#L314-L320 | train |
dorsataio/Squibble | src/SquibbleDriver.php | SquibbleDriver.getConnection | public static function getConnection($filter = ''){
switch ($filter) {
case 'host':
return self::$_host;
break;
case 'port':
return self::$_port;
break;
case 'dbname':
return self::$_dbname;
break;
case 'user':
return self::$_user;
break;
default:
return self::$_pdo;
break;
}
} | php | public static function getConnection($filter = ''){
switch ($filter) {
case 'host':
return self::$_host;
break;
case 'port':
return self::$_port;
break;
case 'dbname':
return self::$_dbname;
break;
case 'user':
return self::$_user;
break;
default:
return self::$_pdo;
break;
}
} | [
"public",
"static",
"function",
"getConnection",
"(",
"$",
"filter",
"=",
"''",
")",
"{",
"switch",
"(",
"$",
"filter",
")",
"{",
"case",
"'host'",
":",
"return",
"self",
"::",
"$",
"_host",
";",
"break",
";",
"case",
"'port'",
":",
"return",
"self",
"::",
"$",
"_port",
";",
"break",
";",
"case",
"'dbname'",
":",
"return",
"self",
"::",
"$",
"_dbname",
";",
"break",
";",
"case",
"'user'",
":",
"return",
"self",
"::",
"$",
"_user",
";",
"break",
";",
"default",
":",
"return",
"self",
"::",
"$",
"_pdo",
";",
"break",
";",
"}",
"}"
] | Get specific connection parameters. Unfortunately the password is used during the
connection phase and is not stored therefore not returnable.
@method getConnection
@param string $filter A database connection parameter (host, port, dbname, user).
If none is supplied, the PDO object is returned instead.
@return mixed A database connection parameter (host, port, dbname, user) value.
If none is supplied, the PDO object is returned instead. | [
"Get",
"specific",
"connection",
"parameters",
".",
"Unfortunately",
"the",
"password",
"is",
"used",
"during",
"the",
"connection",
"phase",
"and",
"is",
"not",
"stored",
"therefore",
"not",
"returnable",
"."
] | 77f3e8049c11b6cb56baac4686c0bd2a82e5b6e9 | https://github.com/dorsataio/Squibble/blob/77f3e8049c11b6cb56baac4686c0bd2a82e5b6e9/src/SquibbleDriver.php#L207-L229 | train |
dorsataio/Squibble | src/SquibbleDriver.php | SquibbleDriver.table | public function table($t){
if(is_array($t)){
$tArray = $t;
$t = $t_alias = array_shift(array_keys($tArray));
$driver = get_called_class();
if(($tArray[$t_alias] instanceof $driver) === true){
$this->_placeholders = array_merge($this->_placeholders, $tArray[$t_alias]->queryData());
$t = $tArray[$t_alias]->queryString();
$t = "({$t}) AS {$this->formatWithQuote($t_alias, 'alias')}";
}
$t = (string) $t;
$this->_table = trim($t);
}else{
$t = \Dorsataio\Squibble\Resource\Extract::fromTable((string) $t);
$this->_table = trim($t['table']);
if(isset($t['alias']) && !empty($t['alias'])){
$this->_table = "{$this->_table} as {$t['alias']}";
}
}
return $this;
} | php | public function table($t){
if(is_array($t)){
$tArray = $t;
$t = $t_alias = array_shift(array_keys($tArray));
$driver = get_called_class();
if(($tArray[$t_alias] instanceof $driver) === true){
$this->_placeholders = array_merge($this->_placeholders, $tArray[$t_alias]->queryData());
$t = $tArray[$t_alias]->queryString();
$t = "({$t}) AS {$this->formatWithQuote($t_alias, 'alias')}";
}
$t = (string) $t;
$this->_table = trim($t);
}else{
$t = \Dorsataio\Squibble\Resource\Extract::fromTable((string) $t);
$this->_table = trim($t['table']);
if(isset($t['alias']) && !empty($t['alias'])){
$this->_table = "{$this->_table} as {$t['alias']}";
}
}
return $this;
} | [
"public",
"function",
"table",
"(",
"$",
"t",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"t",
")",
")",
"{",
"$",
"tArray",
"=",
"$",
"t",
";",
"$",
"t",
"=",
"$",
"t_alias",
"=",
"array_shift",
"(",
"array_keys",
"(",
"$",
"tArray",
")",
")",
";",
"$",
"driver",
"=",
"get_called_class",
"(",
")",
";",
"if",
"(",
"(",
"$",
"tArray",
"[",
"$",
"t_alias",
"]",
"instanceof",
"$",
"driver",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"_placeholders",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"_placeholders",
",",
"$",
"tArray",
"[",
"$",
"t_alias",
"]",
"->",
"queryData",
"(",
")",
")",
";",
"$",
"t",
"=",
"$",
"tArray",
"[",
"$",
"t_alias",
"]",
"->",
"queryString",
"(",
")",
";",
"$",
"t",
"=",
"\"({$t}) AS {$this->formatWithQuote($t_alias, 'alias')}\"",
";",
"}",
"$",
"t",
"=",
"(",
"string",
")",
"$",
"t",
";",
"$",
"this",
"->",
"_table",
"=",
"trim",
"(",
"$",
"t",
")",
";",
"}",
"else",
"{",
"$",
"t",
"=",
"\\",
"Dorsataio",
"\\",
"Squibble",
"\\",
"Resource",
"\\",
"Extract",
"::",
"fromTable",
"(",
"(",
"string",
")",
"$",
"t",
")",
";",
"$",
"this",
"->",
"_table",
"=",
"trim",
"(",
"$",
"t",
"[",
"'table'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"t",
"[",
"'alias'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"t",
"[",
"'alias'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_table",
"=",
"\"{$this->_table} as {$t['alias']}\"",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Set a table or subquery to execute the query on.
@param mixed $t Can be a string defining the table to execute the query on or an array
whose key is a subquery alias and the value is a Squibble object.
@return object returns the current squibble object. | [
"Set",
"a",
"table",
"or",
"subquery",
"to",
"execute",
"the",
"query",
"on",
"."
] | 77f3e8049c11b6cb56baac4686c0bd2a82e5b6e9 | https://github.com/dorsataio/Squibble/blob/77f3e8049c11b6cb56baac4686c0bd2a82e5b6e9/src/SquibbleDriver.php#L276-L296 | train |
dorsataio/Squibble | src/SquibbleDriver.php | SquibbleDriver.select | public function select($t, $c = array()){
if(!is_array($c)){
$c = array($c);
}
if(is_array($t)){
$c = $t;
}elseif(is_string($t)){
$this->table($t);
}
$columns = [];
foreach($c as $i => $s){
$column = [];
if(!is_array($s)){
$column = \Dorsataio\Squibble\Resource\Extract::fromColumn($s);
}else{
$column = \Dorsataio\Squibble\Resource\Extract::fromColumn($i);
$column['cases'] = \Dorsataio\Squibble\Resource\Extract::extractCase($s);
}
array_push($columns, $column);
}
$this->_sql = $this->getSelectStatement($columns);
return $this;
} | php | public function select($t, $c = array()){
if(!is_array($c)){
$c = array($c);
}
if(is_array($t)){
$c = $t;
}elseif(is_string($t)){
$this->table($t);
}
$columns = [];
foreach($c as $i => $s){
$column = [];
if(!is_array($s)){
$column = \Dorsataio\Squibble\Resource\Extract::fromColumn($s);
}else{
$column = \Dorsataio\Squibble\Resource\Extract::fromColumn($i);
$column['cases'] = \Dorsataio\Squibble\Resource\Extract::extractCase($s);
}
array_push($columns, $column);
}
$this->_sql = $this->getSelectStatement($columns);
return $this;
} | [
"public",
"function",
"select",
"(",
"$",
"t",
",",
"$",
"c",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"c",
")",
")",
"{",
"$",
"c",
"=",
"array",
"(",
"$",
"c",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"t",
")",
")",
"{",
"$",
"c",
"=",
"$",
"t",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"t",
")",
")",
"{",
"$",
"this",
"->",
"table",
"(",
"$",
"t",
")",
";",
"}",
"$",
"columns",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"c",
"as",
"$",
"i",
"=>",
"$",
"s",
")",
"{",
"$",
"column",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"s",
")",
")",
"{",
"$",
"column",
"=",
"\\",
"Dorsataio",
"\\",
"Squibble",
"\\",
"Resource",
"\\",
"Extract",
"::",
"fromColumn",
"(",
"$",
"s",
")",
";",
"}",
"else",
"{",
"$",
"column",
"=",
"\\",
"Dorsataio",
"\\",
"Squibble",
"\\",
"Resource",
"\\",
"Extract",
"::",
"fromColumn",
"(",
"$",
"i",
")",
";",
"$",
"column",
"[",
"'cases'",
"]",
"=",
"\\",
"Dorsataio",
"\\",
"Squibble",
"\\",
"Resource",
"\\",
"Extract",
"::",
"extractCase",
"(",
"$",
"s",
")",
";",
"}",
"array_push",
"(",
"$",
"columns",
",",
"$",
"column",
")",
";",
"}",
"$",
"this",
"->",
"_sql",
"=",
"$",
"this",
"->",
"getSelectStatement",
"(",
"$",
"columns",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Start a new SELECT query.
@param array $c Array containing columns that the SELECT query will return.
@return object returns the current squibble object. | [
"Start",
"a",
"new",
"SELECT",
"query",
"."
] | 77f3e8049c11b6cb56baac4686c0bd2a82e5b6e9 | https://github.com/dorsataio/Squibble/blob/77f3e8049c11b6cb56baac4686c0bd2a82e5b6e9/src/SquibbleDriver.php#L305-L328 | train |
dorsataio/Squibble | src/SquibbleDriver.php | SquibbleDriver.insert | public function insert($t, $nvp = array()){
$nvps = $nvp;
if(is_array($t)){
$nvps = $t;
}elseif(is_string($t)){
$this->table($t);
}
if(!isset($nvps[0])){
$nvps = array($nvps);
}
$columns = [];
foreach($nvps as $i => $nvp){
$columns[$i] = [];
foreach(array_keys($nvp) as $s){
$column = \Dorsataio\Squibble\Resource\Extract::fromColumn($s);
$column['value'] = $nvp[$s];
array_push($columns[$i], $column);
}
}
$this->_sql = $this->getInsertStatement($columns);
return $this;
} | php | public function insert($t, $nvp = array()){
$nvps = $nvp;
if(is_array($t)){
$nvps = $t;
}elseif(is_string($t)){
$this->table($t);
}
if(!isset($nvps[0])){
$nvps = array($nvps);
}
$columns = [];
foreach($nvps as $i => $nvp){
$columns[$i] = [];
foreach(array_keys($nvp) as $s){
$column = \Dorsataio\Squibble\Resource\Extract::fromColumn($s);
$column['value'] = $nvp[$s];
array_push($columns[$i], $column);
}
}
$this->_sql = $this->getInsertStatement($columns);
return $this;
} | [
"public",
"function",
"insert",
"(",
"$",
"t",
",",
"$",
"nvp",
"=",
"array",
"(",
")",
")",
"{",
"$",
"nvps",
"=",
"$",
"nvp",
";",
"if",
"(",
"is_array",
"(",
"$",
"t",
")",
")",
"{",
"$",
"nvps",
"=",
"$",
"t",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"t",
")",
")",
"{",
"$",
"this",
"->",
"table",
"(",
"$",
"t",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"nvps",
"[",
"0",
"]",
")",
")",
"{",
"$",
"nvps",
"=",
"array",
"(",
"$",
"nvps",
")",
";",
"}",
"$",
"columns",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"nvps",
"as",
"$",
"i",
"=>",
"$",
"nvp",
")",
"{",
"$",
"columns",
"[",
"$",
"i",
"]",
"=",
"[",
"]",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"nvp",
")",
"as",
"$",
"s",
")",
"{",
"$",
"column",
"=",
"\\",
"Dorsataio",
"\\",
"Squibble",
"\\",
"Resource",
"\\",
"Extract",
"::",
"fromColumn",
"(",
"$",
"s",
")",
";",
"$",
"column",
"[",
"'value'",
"]",
"=",
"$",
"nvp",
"[",
"$",
"s",
"]",
";",
"array_push",
"(",
"$",
"columns",
"[",
"$",
"i",
"]",
",",
"$",
"column",
")",
";",
"}",
"}",
"$",
"this",
"->",
"_sql",
"=",
"$",
"this",
"->",
"getInsertStatement",
"(",
"$",
"columns",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Start a new INSERT query.
@param array $nvp An NVP array containing columns their value to be inserted.
@return object returns the current squibble object. | [
"Start",
"a",
"new",
"INSERT",
"query",
"."
] | 77f3e8049c11b6cb56baac4686c0bd2a82e5b6e9 | https://github.com/dorsataio/Squibble/blob/77f3e8049c11b6cb56baac4686c0bd2a82e5b6e9/src/SquibbleDriver.php#L337-L358 | train |
dorsataio/Squibble | src/SquibbleDriver.php | SquibbleDriver.update | public function update($t, $nvp = array()){
if(is_array($t)){
$nvp = $t;
}elseif(is_string($t)){
$this->table($t);
}
$columns = [];
foreach(array_keys($nvp) as $s){
$column = \Dorsataio\Squibble\Resource\Extract::fromColumn($s);
$column['value'] = $nvp[$s];
array_push($columns, $column);
}
$this->_sql = $this->getUpdateStatement($columns);
return $this;
} | php | public function update($t, $nvp = array()){
if(is_array($t)){
$nvp = $t;
}elseif(is_string($t)){
$this->table($t);
}
$columns = [];
foreach(array_keys($nvp) as $s){
$column = \Dorsataio\Squibble\Resource\Extract::fromColumn($s);
$column['value'] = $nvp[$s];
array_push($columns, $column);
}
$this->_sql = $this->getUpdateStatement($columns);
return $this;
} | [
"public",
"function",
"update",
"(",
"$",
"t",
",",
"$",
"nvp",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"t",
")",
")",
"{",
"$",
"nvp",
"=",
"$",
"t",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"t",
")",
")",
"{",
"$",
"this",
"->",
"table",
"(",
"$",
"t",
")",
";",
"}",
"$",
"columns",
"=",
"[",
"]",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"nvp",
")",
"as",
"$",
"s",
")",
"{",
"$",
"column",
"=",
"\\",
"Dorsataio",
"\\",
"Squibble",
"\\",
"Resource",
"\\",
"Extract",
"::",
"fromColumn",
"(",
"$",
"s",
")",
";",
"$",
"column",
"[",
"'value'",
"]",
"=",
"$",
"nvp",
"[",
"$",
"s",
"]",
";",
"array_push",
"(",
"$",
"columns",
",",
"$",
"column",
")",
";",
"}",
"$",
"this",
"->",
"_sql",
"=",
"$",
"this",
"->",
"getUpdateStatement",
"(",
"$",
"columns",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Start a new UPDATE query.
@param array $nvp An NVP array containing columns their value to be updated.
@return object returns the current squibble object. | [
"Start",
"a",
"new",
"UPDATE",
"query",
"."
] | 77f3e8049c11b6cb56baac4686c0bd2a82e5b6e9 | https://github.com/dorsataio/Squibble/blob/77f3e8049c11b6cb56baac4686c0bd2a82e5b6e9/src/SquibbleDriver.php#L367-L381 | train |
dorsataio/Squibble | src/SquibbleDriver.php | SquibbleDriver.delete | public function delete($t, $conditions = array()){
if(is_array($t)){
$conditions = $t;
}elseif(is_string($t)){
$this->table($t);
}
if(!empty($conditions)){
$this->where($conditions);
}
$this->_sql = $this->getDeleteStatement();
return $this;
} | php | public function delete($t, $conditions = array()){
if(is_array($t)){
$conditions = $t;
}elseif(is_string($t)){
$this->table($t);
}
if(!empty($conditions)){
$this->where($conditions);
}
$this->_sql = $this->getDeleteStatement();
return $this;
} | [
"public",
"function",
"delete",
"(",
"$",
"t",
",",
"$",
"conditions",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"t",
")",
")",
"{",
"$",
"conditions",
"=",
"$",
"t",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"t",
")",
")",
"{",
"$",
"this",
"->",
"table",
"(",
"$",
"t",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"conditions",
")",
")",
"{",
"$",
"this",
"->",
"where",
"(",
"$",
"conditions",
")",
";",
"}",
"$",
"this",
"->",
"_sql",
"=",
"$",
"this",
"->",
"getDeleteStatement",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Start a new DELETE query.
@param array $conditions An NVP array containing WHERE conditions.
@return object returns the current squibble object. | [
"Start",
"a",
"new",
"DELETE",
"query",
"."
] | 77f3e8049c11b6cb56baac4686c0bd2a82e5b6e9 | https://github.com/dorsataio/Squibble/blob/77f3e8049c11b6cb56baac4686c0bd2a82e5b6e9/src/SquibbleDriver.php#L390-L401 | train |
TeaLabs/collections | src/Forest.php | Forest.get | public function get($path, $default = null)
{
return Arr::get($this->items, $this->keyFor($path), $default);
} | php | public function get($path, $default = null)
{
return Arr::get($this->items, $this->keyFor($path), $default);
} | [
"public",
"function",
"get",
"(",
"$",
"path",
",",
"$",
"default",
"=",
"null",
")",
"{",
"return",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"items",
",",
"$",
"this",
"->",
"keyFor",
"(",
"$",
"path",
")",
",",
"$",
"default",
")",
";",
"}"
] | Get an item from the collection by path.
@param mixed $path
@param mixed $default
@return mixed | [
"Get",
"an",
"item",
"from",
"the",
"collection",
"by",
"path",
"."
] | 5d8885b2799791c0bcbff4e6cbacddb270b4288e | https://github.com/TeaLabs/collections/blob/5d8885b2799791c0bcbff4e6cbacddb270b4288e/src/Forest.php#L94-L97 | train |
hiqdev/minii-validators | src/IpValidator.php | IpValidator.inRange | private function inRange($ip, $cidr, $range)
{
$ipVersion = $this->getIpVersion($ip);
$binIp = $this->ip2bin($ip);
$parts = explode('/', $range);
$net = array_shift($parts);
$range_cidr = array_shift($parts);
$netVersion = $this->getIpVersion($net);
if ($ipVersion !== $netVersion) {
return false;
}
if ($range_cidr === null) {
$range_cidr = $netVersion === 4 ? static::IPV4_ADDRESS_LENGTH : static::IPV6_ADDRESS_LENGTH;
}
$binNet = $this->ip2bin($net);
if (substr($binIp, 0, $range_cidr) === substr($binNet, 0, $range_cidr) && $cidr >= $range_cidr) {
return true;
}
return false;
} | php | private function inRange($ip, $cidr, $range)
{
$ipVersion = $this->getIpVersion($ip);
$binIp = $this->ip2bin($ip);
$parts = explode('/', $range);
$net = array_shift($parts);
$range_cidr = array_shift($parts);
$netVersion = $this->getIpVersion($net);
if ($ipVersion !== $netVersion) {
return false;
}
if ($range_cidr === null) {
$range_cidr = $netVersion === 4 ? static::IPV4_ADDRESS_LENGTH : static::IPV6_ADDRESS_LENGTH;
}
$binNet = $this->ip2bin($net);
if (substr($binIp, 0, $range_cidr) === substr($binNet, 0, $range_cidr) && $cidr >= $range_cidr) {
return true;
}
return false;
} | [
"private",
"function",
"inRange",
"(",
"$",
"ip",
",",
"$",
"cidr",
",",
"$",
"range",
")",
"{",
"$",
"ipVersion",
"=",
"$",
"this",
"->",
"getIpVersion",
"(",
"$",
"ip",
")",
";",
"$",
"binIp",
"=",
"$",
"this",
"->",
"ip2bin",
"(",
"$",
"ip",
")",
";",
"$",
"parts",
"=",
"explode",
"(",
"'/'",
",",
"$",
"range",
")",
";",
"$",
"net",
"=",
"array_shift",
"(",
"$",
"parts",
")",
";",
"$",
"range_cidr",
"=",
"array_shift",
"(",
"$",
"parts",
")",
";",
"$",
"netVersion",
"=",
"$",
"this",
"->",
"getIpVersion",
"(",
"$",
"net",
")",
";",
"if",
"(",
"$",
"ipVersion",
"!==",
"$",
"netVersion",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"range_cidr",
"===",
"null",
")",
"{",
"$",
"range_cidr",
"=",
"$",
"netVersion",
"===",
"4",
"?",
"static",
"::",
"IPV4_ADDRESS_LENGTH",
":",
"static",
"::",
"IPV6_ADDRESS_LENGTH",
";",
"}",
"$",
"binNet",
"=",
"$",
"this",
"->",
"ip2bin",
"(",
"$",
"net",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"binIp",
",",
"0",
",",
"$",
"range_cidr",
")",
"===",
"substr",
"(",
"$",
"binNet",
",",
"0",
",",
"$",
"range_cidr",
")",
"&&",
"$",
"cidr",
">=",
"$",
"range_cidr",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Checks whether the IP is in subnet range
@param string $ip an IPv4 or IPv6 address
@param integer $cidr
@param string $range subnet in CIDR format e.g. `10.0.0.0/8` or `2001:af::/64`
@return bool | [
"Checks",
"whether",
"the",
"IP",
"is",
"in",
"subnet",
"range"
] | 3e32ccf5d0dadc070bc5a9bd6ebe98f778a1f741 | https://github.com/hiqdev/minii-validators/blob/3e32ccf5d0dadc070bc5a9bd6ebe98f778a1f741/src/IpValidator.php#L511-L534 | train |
hiqdev/minii-validators | src/IpValidator.php | IpValidator.ip2bin | private function ip2bin($ip)
{
if ($this->getIpVersion($ip) === 4) {
return str_pad(base_convert(ip2long($ip), 10, 2), static::IPV4_ADDRESS_LENGTH, '0', STR_PAD_LEFT);
} else {
$unpack = unpack('A16', inet_pton($ip));
$binStr = array_shift($unpack);
$bytes = static::IPV6_ADDRESS_LENGTH / 8; // 128 bit / 8 = 16 bytes
$result = '';
while ($bytes-- > 0) {
$result = sprintf('%08b', isset($binStr[$bytes]) ? ord($binStr[$bytes]) : '0') . $result;
}
return $result;
}
} | php | private function ip2bin($ip)
{
if ($this->getIpVersion($ip) === 4) {
return str_pad(base_convert(ip2long($ip), 10, 2), static::IPV4_ADDRESS_LENGTH, '0', STR_PAD_LEFT);
} else {
$unpack = unpack('A16', inet_pton($ip));
$binStr = array_shift($unpack);
$bytes = static::IPV6_ADDRESS_LENGTH / 8; // 128 bit / 8 = 16 bytes
$result = '';
while ($bytes-- > 0) {
$result = sprintf('%08b', isset($binStr[$bytes]) ? ord($binStr[$bytes]) : '0') . $result;
}
return $result;
}
} | [
"private",
"function",
"ip2bin",
"(",
"$",
"ip",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getIpVersion",
"(",
"$",
"ip",
")",
"===",
"4",
")",
"{",
"return",
"str_pad",
"(",
"base_convert",
"(",
"ip2long",
"(",
"$",
"ip",
")",
",",
"10",
",",
"2",
")",
",",
"static",
"::",
"IPV4_ADDRESS_LENGTH",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
";",
"}",
"else",
"{",
"$",
"unpack",
"=",
"unpack",
"(",
"'A16'",
",",
"inet_pton",
"(",
"$",
"ip",
")",
")",
";",
"$",
"binStr",
"=",
"array_shift",
"(",
"$",
"unpack",
")",
";",
"$",
"bytes",
"=",
"static",
"::",
"IPV6_ADDRESS_LENGTH",
"/",
"8",
";",
"// 128 bit / 8 = 16 bytes",
"$",
"result",
"=",
"''",
";",
"while",
"(",
"$",
"bytes",
"--",
">",
"0",
")",
"{",
"$",
"result",
"=",
"sprintf",
"(",
"'%08b'",
",",
"isset",
"(",
"$",
"binStr",
"[",
"$",
"bytes",
"]",
")",
"?",
"ord",
"(",
"$",
"binStr",
"[",
"$",
"bytes",
"]",
")",
":",
"'0'",
")",
".",
"$",
"result",
";",
"}",
"return",
"$",
"result",
";",
"}",
"}"
] | Converts IP address to bits representation
@param string $ip
@return string bits as a string | [
"Converts",
"IP",
"address",
"to",
"bits",
"representation"
] | 3e32ccf5d0dadc070bc5a9bd6ebe98f778a1f741 | https://github.com/hiqdev/minii-validators/blob/3e32ccf5d0dadc070bc5a9bd6ebe98f778a1f741/src/IpValidator.php#L542-L556 | train |
kambalabs/KmbDomain | src/KmbDomain/Model/Group.php | Group.dump | public function dump()
{
$dump = [];
if ($this->hasClasses()) {
foreach ($this->classes as $class) {
$dump[$class->getName()] = $class->dump();
}
}
return $dump;
} | php | public function dump()
{
$dump = [];
if ($this->hasClasses()) {
foreach ($this->classes as $class) {
$dump[$class->getName()] = $class->dump();
}
}
return $dump;
} | [
"public",
"function",
"dump",
"(",
")",
"{",
"$",
"dump",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"hasClasses",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"classes",
"as",
"$",
"class",
")",
"{",
"$",
"dump",
"[",
"$",
"class",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"class",
"->",
"dump",
"(",
")",
";",
"}",
"}",
"return",
"$",
"dump",
";",
"}"
] | Dump group classes.
@return array | [
"Dump",
"group",
"classes",
"."
] | b1631bd936c6c6798076b51dfaebd706e1bdc8c2 | https://github.com/kambalabs/KmbDomain/blob/b1631bd936c6c6798076b51dfaebd706e1bdc8c2/src/KmbDomain/Model/Group.php#L374-L383 | train |
kambalabs/KmbDomain | src/KmbDomain/Model/Group.php | Group.extract | public function extract()
{
return [
'name' => $this->getName(),
'ordering' => $this->getOrdering(),
'type' => $this->getType(),
'include_pattern' => $this->getIncludePattern(),
'exclude_pattern' => $this->getExcludePattern(),
'classes' => $this->dump(),
];
} | php | public function extract()
{
return [
'name' => $this->getName(),
'ordering' => $this->getOrdering(),
'type' => $this->getType(),
'include_pattern' => $this->getIncludePattern(),
'exclude_pattern' => $this->getExcludePattern(),
'classes' => $this->dump(),
];
} | [
"public",
"function",
"extract",
"(",
")",
"{",
"return",
"[",
"'name'",
"=>",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"'ordering'",
"=>",
"$",
"this",
"->",
"getOrdering",
"(",
")",
",",
"'type'",
"=>",
"$",
"this",
"->",
"getType",
"(",
")",
",",
"'include_pattern'",
"=>",
"$",
"this",
"->",
"getIncludePattern",
"(",
")",
",",
"'exclude_pattern'",
"=>",
"$",
"this",
"->",
"getExcludePattern",
"(",
")",
",",
"'classes'",
"=>",
"$",
"this",
"->",
"dump",
"(",
")",
",",
"]",
";",
"}"
] | Extract all group's data in array.
@return array | [
"Extract",
"all",
"group",
"s",
"data",
"in",
"array",
"."
] | b1631bd936c6c6798076b51dfaebd706e1bdc8c2 | https://github.com/kambalabs/KmbDomain/blob/b1631bd936c6c6798076b51dfaebd706e1bdc8c2/src/KmbDomain/Model/Group.php#L390-L400 | train |
OliverMonneke/pennePHP | src/Datatype/Boolean.php | Boolean.isValid | public static function isValid($expression, $translate = false)
{
if ($translate) {
$expression = self::translate($expression);
}
return is_bool($expression);
} | php | public static function isValid($expression, $translate = false)
{
if ($translate) {
$expression = self::translate($expression);
}
return is_bool($expression);
} | [
"public",
"static",
"function",
"isValid",
"(",
"$",
"expression",
",",
"$",
"translate",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"translate",
")",
"{",
"$",
"expression",
"=",
"self",
"::",
"translate",
"(",
"$",
"expression",
")",
";",
"}",
"return",
"is_bool",
"(",
"$",
"expression",
")",
";",
"}"
] | Check if expression is valid
@param mixed $expression The expression to check
@param bool $translate
@return bool | [
"Check",
"if",
"expression",
"is",
"valid"
] | dd0de7944685a3f1947157e1254fc54b55ff9942 | https://github.com/OliverMonneke/pennePHP/blob/dd0de7944685a3f1947157e1254fc54b55ff9942/src/Datatype/Boolean.php#L37-L44 | train |
libgraviton/analytics-mongoshell-converter | src/Parser.php | Parser.parse | public function parse()
{
$this->lexer->moveNext();
while (true) {
if (!$this->lexer->lookahead) {
break;
}
$this->lexer->moveNext();
$thisLine = null;
switch ($this->lexer->token['type']) {
case Lexer::T_OPEN_PARENTHESIS:
case Lexer::T_OPEN_BRACKET:
case Lexer::T_OPEN_CURLY_BRACE:
$thisLine = '[';
$this->currentLevel++;
break;
case Lexer::T_CLOSE_PARENTHESIS:
case Lexer::T_CLOSE_BRACKET:
case Lexer::T_CLOSE_CURLY_BRACE:
$thisLine = ']';
$this->currentLevel--;
break;
case Lexer::T_STRING:
$thisLine = "'".str_replace("'", "\'", $this->lexer->token['value'])."'";
break;
case Lexer::T_DOUBLEPOINT:
$thisLine = '=>';
break;
case Lexer::T_COMMENT_PARAMSTART:
$paramName = $this->lexer->lookahead['value'];
$thisLine = '$this->getParam("'.$paramName.'")';
// scroll to end of param
while ($this->lexer->token['type'] != Lexer::T_COMMENT_PARAMEND) {
$this->lexer->moveNext();
}
break;
case Lexer::T_COMMENT_IFPARAMSTART:
case Lexer::T_COMMENT_IFNOTPARAMSTART:
$conditionalId = str_pad((string) $this->conditionalCounter, 5, '0', STR_PAD_LEFT);
$this->conditionalCounter++;
$isNegated = '';
if ($this->lexer->token['type'] == Lexer::T_COMMENT_IFNOTPARAMSTART) {
$isNegated = 'true';
}
$this->addContent('$this->getConditional'.$conditionalId.'('.$isNegated.'),');
$this->openConditional($conditionalId, $this->lexer->lookahead['value']);
break;
case Lexer::T_COMMENT_IFPARAMEND:
case Lexer::T_COMMENT_IFNOTPARAMEND:
$this->closeConditional();
break;
case Lexer::T_DATE_EMPTY:
$thisLine = 'new '.$this->mongoDateClass.'()';
break;
case Lexer::T_DATE_WITH_PARAM:
$paramName = $this->lexer->lookahead['value'];
$thisLine = '$this->getParam("'.$paramName.'")';
break;
case Lexer::T_BOOLEAN_TRUE:
$thisLine = 'true';
break;
case Lexer::T_BOOLEAN_FALSE:
$thisLine = 'false';
break;
case Lexer::T_NULL:
$thisLine = 'null';
break;
case Lexer::T_COMMA:
case Lexer::T_NUMBER:
case Lexer::T_DASH:
$thisLine = $this->lexer->token['value'];
break;
default:
// nothing
}
if (!is_null($thisLine)) {
$this->addContent($thisLine);
}
}
return implode(PHP_EOL, $this->lines);
} | php | public function parse()
{
$this->lexer->moveNext();
while (true) {
if (!$this->lexer->lookahead) {
break;
}
$this->lexer->moveNext();
$thisLine = null;
switch ($this->lexer->token['type']) {
case Lexer::T_OPEN_PARENTHESIS:
case Lexer::T_OPEN_BRACKET:
case Lexer::T_OPEN_CURLY_BRACE:
$thisLine = '[';
$this->currentLevel++;
break;
case Lexer::T_CLOSE_PARENTHESIS:
case Lexer::T_CLOSE_BRACKET:
case Lexer::T_CLOSE_CURLY_BRACE:
$thisLine = ']';
$this->currentLevel--;
break;
case Lexer::T_STRING:
$thisLine = "'".str_replace("'", "\'", $this->lexer->token['value'])."'";
break;
case Lexer::T_DOUBLEPOINT:
$thisLine = '=>';
break;
case Lexer::T_COMMENT_PARAMSTART:
$paramName = $this->lexer->lookahead['value'];
$thisLine = '$this->getParam("'.$paramName.'")';
// scroll to end of param
while ($this->lexer->token['type'] != Lexer::T_COMMENT_PARAMEND) {
$this->lexer->moveNext();
}
break;
case Lexer::T_COMMENT_IFPARAMSTART:
case Lexer::T_COMMENT_IFNOTPARAMSTART:
$conditionalId = str_pad((string) $this->conditionalCounter, 5, '0', STR_PAD_LEFT);
$this->conditionalCounter++;
$isNegated = '';
if ($this->lexer->token['type'] == Lexer::T_COMMENT_IFNOTPARAMSTART) {
$isNegated = 'true';
}
$this->addContent('$this->getConditional'.$conditionalId.'('.$isNegated.'),');
$this->openConditional($conditionalId, $this->lexer->lookahead['value']);
break;
case Lexer::T_COMMENT_IFPARAMEND:
case Lexer::T_COMMENT_IFNOTPARAMEND:
$this->closeConditional();
break;
case Lexer::T_DATE_EMPTY:
$thisLine = 'new '.$this->mongoDateClass.'()';
break;
case Lexer::T_DATE_WITH_PARAM:
$paramName = $this->lexer->lookahead['value'];
$thisLine = '$this->getParam("'.$paramName.'")';
break;
case Lexer::T_BOOLEAN_TRUE:
$thisLine = 'true';
break;
case Lexer::T_BOOLEAN_FALSE:
$thisLine = 'false';
break;
case Lexer::T_NULL:
$thisLine = 'null';
break;
case Lexer::T_COMMA:
case Lexer::T_NUMBER:
case Lexer::T_DASH:
$thisLine = $this->lexer->token['value'];
break;
default:
// nothing
}
if (!is_null($thisLine)) {
$this->addContent($thisLine);
}
}
return implode(PHP_EOL, $this->lines);
} | [
"public",
"function",
"parse",
"(",
")",
"{",
"$",
"this",
"->",
"lexer",
"->",
"moveNext",
"(",
")",
";",
"while",
"(",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"lexer",
"->",
"lookahead",
")",
"{",
"break",
";",
"}",
"$",
"this",
"->",
"lexer",
"->",
"moveNext",
"(",
")",
";",
"$",
"thisLine",
"=",
"null",
";",
"switch",
"(",
"$",
"this",
"->",
"lexer",
"->",
"token",
"[",
"'type'",
"]",
")",
"{",
"case",
"Lexer",
"::",
"T_OPEN_PARENTHESIS",
":",
"case",
"Lexer",
"::",
"T_OPEN_BRACKET",
":",
"case",
"Lexer",
"::",
"T_OPEN_CURLY_BRACE",
":",
"$",
"thisLine",
"=",
"'['",
";",
"$",
"this",
"->",
"currentLevel",
"++",
";",
"break",
";",
"case",
"Lexer",
"::",
"T_CLOSE_PARENTHESIS",
":",
"case",
"Lexer",
"::",
"T_CLOSE_BRACKET",
":",
"case",
"Lexer",
"::",
"T_CLOSE_CURLY_BRACE",
":",
"$",
"thisLine",
"=",
"']'",
";",
"$",
"this",
"->",
"currentLevel",
"--",
";",
"break",
";",
"case",
"Lexer",
"::",
"T_STRING",
":",
"$",
"thisLine",
"=",
"\"'\"",
".",
"str_replace",
"(",
"\"'\"",
",",
"\"\\'\"",
",",
"$",
"this",
"->",
"lexer",
"->",
"token",
"[",
"'value'",
"]",
")",
".",
"\"'\"",
";",
"break",
";",
"case",
"Lexer",
"::",
"T_DOUBLEPOINT",
":",
"$",
"thisLine",
"=",
"'=>'",
";",
"break",
";",
"case",
"Lexer",
"::",
"T_COMMENT_PARAMSTART",
":",
"$",
"paramName",
"=",
"$",
"this",
"->",
"lexer",
"->",
"lookahead",
"[",
"'value'",
"]",
";",
"$",
"thisLine",
"=",
"'$this->getParam(\"'",
".",
"$",
"paramName",
".",
"'\")'",
";",
"// scroll to end of param",
"while",
"(",
"$",
"this",
"->",
"lexer",
"->",
"token",
"[",
"'type'",
"]",
"!=",
"Lexer",
"::",
"T_COMMENT_PARAMEND",
")",
"{",
"$",
"this",
"->",
"lexer",
"->",
"moveNext",
"(",
")",
";",
"}",
"break",
";",
"case",
"Lexer",
"::",
"T_COMMENT_IFPARAMSTART",
":",
"case",
"Lexer",
"::",
"T_COMMENT_IFNOTPARAMSTART",
":",
"$",
"conditionalId",
"=",
"str_pad",
"(",
"(",
"string",
")",
"$",
"this",
"->",
"conditionalCounter",
",",
"5",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
";",
"$",
"this",
"->",
"conditionalCounter",
"++",
";",
"$",
"isNegated",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"lexer",
"->",
"token",
"[",
"'type'",
"]",
"==",
"Lexer",
"::",
"T_COMMENT_IFNOTPARAMSTART",
")",
"{",
"$",
"isNegated",
"=",
"'true'",
";",
"}",
"$",
"this",
"->",
"addContent",
"(",
"'$this->getConditional'",
".",
"$",
"conditionalId",
".",
"'('",
".",
"$",
"isNegated",
".",
"'),'",
")",
";",
"$",
"this",
"->",
"openConditional",
"(",
"$",
"conditionalId",
",",
"$",
"this",
"->",
"lexer",
"->",
"lookahead",
"[",
"'value'",
"]",
")",
";",
"break",
";",
"case",
"Lexer",
"::",
"T_COMMENT_IFPARAMEND",
":",
"case",
"Lexer",
"::",
"T_COMMENT_IFNOTPARAMEND",
":",
"$",
"this",
"->",
"closeConditional",
"(",
")",
";",
"break",
";",
"case",
"Lexer",
"::",
"T_DATE_EMPTY",
":",
"$",
"thisLine",
"=",
"'new '",
".",
"$",
"this",
"->",
"mongoDateClass",
".",
"'()'",
";",
"break",
";",
"case",
"Lexer",
"::",
"T_DATE_WITH_PARAM",
":",
"$",
"paramName",
"=",
"$",
"this",
"->",
"lexer",
"->",
"lookahead",
"[",
"'value'",
"]",
";",
"$",
"thisLine",
"=",
"'$this->getParam(\"'",
".",
"$",
"paramName",
".",
"'\")'",
";",
"break",
";",
"case",
"Lexer",
"::",
"T_BOOLEAN_TRUE",
":",
"$",
"thisLine",
"=",
"'true'",
";",
"break",
";",
"case",
"Lexer",
"::",
"T_BOOLEAN_FALSE",
":",
"$",
"thisLine",
"=",
"'false'",
";",
"break",
";",
"case",
"Lexer",
"::",
"T_NULL",
":",
"$",
"thisLine",
"=",
"'null'",
";",
"break",
";",
"case",
"Lexer",
"::",
"T_COMMA",
":",
"case",
"Lexer",
"::",
"T_NUMBER",
":",
"case",
"Lexer",
"::",
"T_DASH",
":",
"$",
"thisLine",
"=",
"$",
"this",
"->",
"lexer",
"->",
"token",
"[",
"'value'",
"]",
";",
"break",
";",
"default",
":",
"// nothing",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"thisLine",
")",
")",
"{",
"$",
"this",
"->",
"addContent",
"(",
"$",
"thisLine",
")",
";",
"}",
"}",
"return",
"implode",
"(",
"PHP_EOL",
",",
"$",
"this",
"->",
"lines",
")",
";",
"}"
] | parses our stuff
@return string parsed pipeline as a script | [
"parses",
"our",
"stuff"
] | 437731c353c58978d39bcd40ac5a741a0b106667 | https://github.com/libgraviton/analytics-mongoshell-converter/blob/437731c353c58978d39bcd40ac5a741a0b106667/src/Parser.php#L46-L133 | train |
FusePump/cli.php | lib/FusePump/Cli/Colours.php | Colours.string | public static function string($string, $foreground_colour = null, $background_colour = null)
{
$coloured_string = "";
// Check if given foreground colour found
if (isset(self::$foreground_colours[$foreground_colour])) {
$coloured_string .= self::getForegroundCode($foreground_colour);
}
// Check if given background colour found
if (isset(self::$background_colours[$background_colour])) {
$coloured_string .= self::getBackgroundCode($background_colour);
}
// Add string and end colouring
$coloured_string .= $string . self::getResetCode();
return $coloured_string;
} | php | public static function string($string, $foreground_colour = null, $background_colour = null)
{
$coloured_string = "";
// Check if given foreground colour found
if (isset(self::$foreground_colours[$foreground_colour])) {
$coloured_string .= self::getForegroundCode($foreground_colour);
}
// Check if given background colour found
if (isset(self::$background_colours[$background_colour])) {
$coloured_string .= self::getBackgroundCode($background_colour);
}
// Add string and end colouring
$coloured_string .= $string . self::getResetCode();
return $coloured_string;
} | [
"public",
"static",
"function",
"string",
"(",
"$",
"string",
",",
"$",
"foreground_colour",
"=",
"null",
",",
"$",
"background_colour",
"=",
"null",
")",
"{",
"$",
"coloured_string",
"=",
"\"\"",
";",
"// Check if given foreground colour found",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"foreground_colours",
"[",
"$",
"foreground_colour",
"]",
")",
")",
"{",
"$",
"coloured_string",
".=",
"self",
"::",
"getForegroundCode",
"(",
"$",
"foreground_colour",
")",
";",
"}",
"// Check if given background colour found",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"background_colours",
"[",
"$",
"background_colour",
"]",
")",
")",
"{",
"$",
"coloured_string",
".=",
"self",
"::",
"getBackgroundCode",
"(",
"$",
"background_colour",
")",
";",
"}",
"// Add string and end colouring",
"$",
"coloured_string",
".=",
"$",
"string",
".",
"self",
"::",
"getResetCode",
"(",
")",
";",
"return",
"$",
"coloured_string",
";",
"}"
] | Adds colouring control codes to a string.
@param string $string String to format.
@param string $foreground_colour Optional foreground colour for string.
@param string $background_colour Optional background colour for string.
@return string Formatted string. | [
"Adds",
"colouring",
"control",
"codes",
"to",
"a",
"string",
"."
] | 2cc92f09ce7b2f73d5cbc09f5ae4f31f3f9ae3b4 | https://github.com/FusePump/cli.php/blob/2cc92f09ce7b2f73d5cbc09f5ae4f31f3f9ae3b4/lib/FusePump/Cli/Colours.php#L69-L86 | train |
FusePump/cli.php | lib/FusePump/Cli/Colours.php | Colours.getForegroundCode | public static function getForegroundCode($foregroundColour)
{
if (!isset(self::$foreground_colours[$foregroundColour])) {
throw new \Exception('Invalid foreground colour.');
}
return "\033[" . self::$foreground_colours[$foregroundColour] . 'm';
} | php | public static function getForegroundCode($foregroundColour)
{
if (!isset(self::$foreground_colours[$foregroundColour])) {
throw new \Exception('Invalid foreground colour.');
}
return "\033[" . self::$foreground_colours[$foregroundColour] . 'm';
} | [
"public",
"static",
"function",
"getForegroundCode",
"(",
"$",
"foregroundColour",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"foreground_colours",
"[",
"$",
"foregroundColour",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Invalid foreground colour.'",
")",
";",
"}",
"return",
"\"\\033[\"",
".",
"self",
"::",
"$",
"foreground_colours",
"[",
"$",
"foregroundColour",
"]",
".",
"'m'",
";",
"}"
] | Returns the code for a foreground colour.
@param string $foregroundColour Foreground colour to set.
@return string Foreground colour code.
@throws \Exception if the colour code is invalid. | [
"Returns",
"the",
"code",
"for",
"a",
"foreground",
"colour",
"."
] | 2cc92f09ce7b2f73d5cbc09f5ae4f31f3f9ae3b4 | https://github.com/FusePump/cli.php/blob/2cc92f09ce7b2f73d5cbc09f5ae4f31f3f9ae3b4/lib/FusePump/Cli/Colours.php#L97-L103 | train |
FusePump/cli.php | lib/FusePump/Cli/Colours.php | Colours.getBackgroundCode | public static function getBackgroundCode($backgroundColour)
{
if (!isset(self::$background_colours[$backgroundColour])) {
throw new \Exception('Invalid background colour.');
}
return "\033[" . self::$background_colours[$backgroundColour] . 'm';
} | php | public static function getBackgroundCode($backgroundColour)
{
if (!isset(self::$background_colours[$backgroundColour])) {
throw new \Exception('Invalid background colour.');
}
return "\033[" . self::$background_colours[$backgroundColour] . 'm';
} | [
"public",
"static",
"function",
"getBackgroundCode",
"(",
"$",
"backgroundColour",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"background_colours",
"[",
"$",
"backgroundColour",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Invalid background colour.'",
")",
";",
"}",
"return",
"\"\\033[\"",
".",
"self",
"::",
"$",
"background_colours",
"[",
"$",
"backgroundColour",
"]",
".",
"'m'",
";",
"}"
] | Returns the code for a background colour.
@param string $backgroundColour Background colour to set.
@return string Background colour code.
@throws \Exception if the colour code is invalid. | [
"Returns",
"the",
"code",
"for",
"a",
"background",
"colour",
"."
] | 2cc92f09ce7b2f73d5cbc09f5ae4f31f3f9ae3b4 | https://github.com/FusePump/cli.php/blob/2cc92f09ce7b2f73d5cbc09f5ae4f31f3f9ae3b4/lib/FusePump/Cli/Colours.php#L114-L120 | train |
dms-org/common.structure | src/Table/Form/Builder/TableRowFieldDefiner.php | TableRowFieldDefiner.withPredefinedRowValues | public function withPredefinedRowValues(FieldBuilderBase $field, array $rowValues) : TableCellValueFieldDefiner
{
$this->fieldBuilder->attr(TableType::ATTR_PREDEFINED_ROWS, array_values($rowValues));
return $this->withRowKeyAs($field);
} | php | public function withPredefinedRowValues(FieldBuilderBase $field, array $rowValues) : TableCellValueFieldDefiner
{
$this->fieldBuilder->attr(TableType::ATTR_PREDEFINED_ROWS, array_values($rowValues));
return $this->withRowKeyAs($field);
} | [
"public",
"function",
"withPredefinedRowValues",
"(",
"FieldBuilderBase",
"$",
"field",
",",
"array",
"$",
"rowValues",
")",
":",
"TableCellValueFieldDefiner",
"{",
"$",
"this",
"->",
"fieldBuilder",
"->",
"attr",
"(",
"TableType",
"::",
"ATTR_PREDEFINED_ROWS",
",",
"array_values",
"(",
"$",
"rowValues",
")",
")",
";",
"return",
"$",
"this",
"->",
"withRowKeyAs",
"(",
"$",
"field",
")",
";",
"}"
] | Defines the rows as predefined set of values.
@param FieldBuilderBase $field
@param array $rowValues
@return TableCellValueFieldDefiner | [
"Defines",
"the",
"rows",
"as",
"predefined",
"set",
"of",
"values",
"."
] | 23f122182f60df5ec847047a81a39c8aab019ff1 | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/Table/Form/Builder/TableRowFieldDefiner.php#L53-L57 | train |
dms-org/common.structure | src/Table/Form/Builder/TableRowFieldDefiner.php | TableRowFieldDefiner.withRowKeyAsField | public function withRowKeyAsField(IField $field) : TableCellValueFieldDefiner
{
return new TableCellValueFieldDefiner($this->fieldBuilder, $this->cellClassName, $this->columnField, $field);
} | php | public function withRowKeyAsField(IField $field) : TableCellValueFieldDefiner
{
return new TableCellValueFieldDefiner($this->fieldBuilder, $this->cellClassName, $this->columnField, $field);
} | [
"public",
"function",
"withRowKeyAsField",
"(",
"IField",
"$",
"field",
")",
":",
"TableCellValueFieldDefiner",
"{",
"return",
"new",
"TableCellValueFieldDefiner",
"(",
"$",
"this",
"->",
"fieldBuilder",
",",
"$",
"this",
"->",
"cellClassName",
",",
"$",
"this",
"->",
"columnField",
",",
"$",
"field",
")",
";",
"}"
] | Defines the row key as the supplied field.
@param IField $field
@return TableCellValueFieldDefiner | [
"Defines",
"the",
"row",
"key",
"as",
"the",
"supplied",
"field",
"."
] | 23f122182f60df5ec847047a81a39c8aab019ff1 | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/Table/Form/Builder/TableRowFieldDefiner.php#L78-L81 | train |
Wayn0/Log | src/Log/Log.php | Log.log | private function log($line, $log_level)
{
// Write all events less than log verbosity
if ($log_level <= $this->log_verbosity) {
$line = $this->prepend($log_level) . $line . "\n";
$this->writeLine($line);
}
} | php | private function log($line, $log_level)
{
// Write all events less than log verbosity
if ($log_level <= $this->log_verbosity) {
$line = $this->prepend($log_level) . $line . "\n";
$this->writeLine($line);
}
} | [
"private",
"function",
"log",
"(",
"$",
"line",
",",
"$",
"log_level",
")",
"{",
"// Write all events less than log verbosity",
"if",
"(",
"$",
"log_level",
"<=",
"$",
"this",
"->",
"log_verbosity",
")",
"{",
"$",
"line",
"=",
"$",
"this",
"->",
"prepend",
"(",
"$",
"log_level",
")",
".",
"$",
"line",
".",
"\"\\n\"",
";",
"$",
"this",
"->",
"writeLine",
"(",
"$",
"line",
")",
";",
"}",
"}"
] | Write the log entry | [
"Write",
"the",
"log",
"entry"
] | d049c9a2188b9684faa29be9a920cc4216c747bd | https://github.com/Wayn0/Log/blob/d049c9a2188b9684faa29be9a920cc4216c747bd/src/Log/Log.php#L138-L145 | train |
Wayn0/Log | src/Log/Log.php | Log.prepend | private function prepend($log_level)
{
$time = date('Y-m-d G:i:s');
switch ($log_level) {
case self::FATAL:
return $time . ' - FATAL - ';
break;
case self::ERROR:
return $time . ' - ERROR - ';
break;
case self::WARN:
return $time . ' - WARN - ';
break;
case self::INFO:
return $time . ' - INFO - ';
break;
case self::DEBUG:
return $time . ' - DEBUG - ';
break;
case self::QUERY:
return $time . ' - QUERY - ';
break;
default:
return $time . ' - LOG - ';
}
} | php | private function prepend($log_level)
{
$time = date('Y-m-d G:i:s');
switch ($log_level) {
case self::FATAL:
return $time . ' - FATAL - ';
break;
case self::ERROR:
return $time . ' - ERROR - ';
break;
case self::WARN:
return $time . ' - WARN - ';
break;
case self::INFO:
return $time . ' - INFO - ';
break;
case self::DEBUG:
return $time . ' - DEBUG - ';
break;
case self::QUERY:
return $time . ' - QUERY - ';
break;
default:
return $time . ' - LOG - ';
}
} | [
"private",
"function",
"prepend",
"(",
"$",
"log_level",
")",
"{",
"$",
"time",
"=",
"date",
"(",
"'Y-m-d G:i:s'",
")",
";",
"switch",
"(",
"$",
"log_level",
")",
"{",
"case",
"self",
"::",
"FATAL",
":",
"return",
"$",
"time",
".",
"' - FATAL - '",
";",
"break",
";",
"case",
"self",
"::",
"ERROR",
":",
"return",
"$",
"time",
".",
"' - ERROR - '",
";",
"break",
";",
"case",
"self",
"::",
"WARN",
":",
"return",
"$",
"time",
".",
"' - WARN - '",
";",
"break",
";",
"case",
"self",
"::",
"INFO",
":",
"return",
"$",
"time",
".",
"' - INFO - '",
";",
"break",
";",
"case",
"self",
"::",
"DEBUG",
":",
"return",
"$",
"time",
".",
"' - DEBUG - '",
";",
"break",
";",
"case",
"self",
"::",
"QUERY",
":",
"return",
"$",
"time",
".",
"' - QUERY - '",
";",
"break",
";",
"default",
":",
"return",
"$",
"time",
".",
"' - LOG - '",
";",
"}",
"}"
] | format the line prefix | [
"format",
"the",
"line",
"prefix"
] | d049c9a2188b9684faa29be9a920cc4216c747bd | https://github.com/Wayn0/Log/blob/d049c9a2188b9684faa29be9a920cc4216c747bd/src/Log/Log.php#L154-L187 | train |
zapheus/zapheus | src/Provider/Configuration.php | Configuration.all | public function all($dotify = false)
{
return $dotify ? $this->dotify($this->data) : $this->data;
} | php | public function all($dotify = false)
{
return $dotify ? $this->dotify($this->data) : $this->data;
} | [
"public",
"function",
"all",
"(",
"$",
"dotify",
"=",
"false",
")",
"{",
"return",
"$",
"dotify",
"?",
"$",
"this",
"->",
"dotify",
"(",
"$",
"this",
"->",
"data",
")",
":",
"$",
"this",
"->",
"data",
";",
"}"
] | Returns all the stored configurations.
@param boolean $dotify
@return array | [
"Returns",
"all",
"the",
"stored",
"configurations",
"."
] | 96618b5cee7d20b6700d0475e4334ae4b5163a6b | https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Provider/Configuration.php#L34-L37 | train |
zapheus/zapheus | src/Provider/Configuration.php | Configuration.get | public function get($key, $default = null, $dotify = false)
{
$items = $this->data;
$keys = array_filter(explode('.', $key));
$length = count($keys);
for ($i = 0; $i < $length; $i++)
{
$index = $keys[(int) $i];
$items = &$items[$index];
}
if ($items === null)
{
$items = $default;
}
if ($dotify)
{
return $this->dotify($items);
}
return $items;
} | php | public function get($key, $default = null, $dotify = false)
{
$items = $this->data;
$keys = array_filter(explode('.', $key));
$length = count($keys);
for ($i = 0; $i < $length; $i++)
{
$index = $keys[(int) $i];
$items = &$items[$index];
}
if ($items === null)
{
$items = $default;
}
if ($dotify)
{
return $this->dotify($items);
}
return $items;
} | [
"public",
"function",
"get",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
",",
"$",
"dotify",
"=",
"false",
")",
"{",
"$",
"items",
"=",
"$",
"this",
"->",
"data",
";",
"$",
"keys",
"=",
"array_filter",
"(",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
")",
";",
"$",
"length",
"=",
"count",
"(",
"$",
"keys",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"index",
"=",
"$",
"keys",
"[",
"(",
"int",
")",
"$",
"i",
"]",
";",
"$",
"items",
"=",
"&",
"$",
"items",
"[",
"$",
"index",
"]",
";",
"}",
"if",
"(",
"$",
"items",
"===",
"null",
")",
"{",
"$",
"items",
"=",
"$",
"default",
";",
"}",
"if",
"(",
"$",
"dotify",
")",
"{",
"return",
"$",
"this",
"->",
"dotify",
"(",
"$",
"items",
")",
";",
"}",
"return",
"$",
"items",
";",
"}"
] | Returns the value from the specified key.
@param string $key
@param mixed|null $default
@param boolean $dotify
@return mixed | [
"Returns",
"the",
"value",
"from",
"the",
"specified",
"key",
"."
] | 96618b5cee7d20b6700d0475e4334ae4b5163a6b | https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Provider/Configuration.php#L47-L73 | train |
zapheus/zapheus | src/Provider/Configuration.php | Configuration.load | public function load($path)
{
list($data, $items) = array(array(), array($path));
if (substr((string) $path, -4) !== '.php')
{
$directory = new \RecursiveDirectoryIterator($path);
$iterator = new \RecursiveIteratorIterator($directory);
$regex = new \RegexIterator($iterator, '/^.+\.php$/i', 1);
$items = (array) array_keys(iterator_to_array($regex));
}
foreach ((array) $items as $item)
{
$name = $this->rename($item, $path);
$data = require $item;
$this->set((string) $name, $data);
}
} | php | public function load($path)
{
list($data, $items) = array(array(), array($path));
if (substr((string) $path, -4) !== '.php')
{
$directory = new \RecursiveDirectoryIterator($path);
$iterator = new \RecursiveIteratorIterator($directory);
$regex = new \RegexIterator($iterator, '/^.+\.php$/i', 1);
$items = (array) array_keys(iterator_to_array($regex));
}
foreach ((array) $items as $item)
{
$name = $this->rename($item, $path);
$data = require $item;
$this->set((string) $name, $data);
}
} | [
"public",
"function",
"load",
"(",
"$",
"path",
")",
"{",
"list",
"(",
"$",
"data",
",",
"$",
"items",
")",
"=",
"array",
"(",
"array",
"(",
")",
",",
"array",
"(",
"$",
"path",
")",
")",
";",
"if",
"(",
"substr",
"(",
"(",
"string",
")",
"$",
"path",
",",
"-",
"4",
")",
"!==",
"'.php'",
")",
"{",
"$",
"directory",
"=",
"new",
"\\",
"RecursiveDirectoryIterator",
"(",
"$",
"path",
")",
";",
"$",
"iterator",
"=",
"new",
"\\",
"RecursiveIteratorIterator",
"(",
"$",
"directory",
")",
";",
"$",
"regex",
"=",
"new",
"\\",
"RegexIterator",
"(",
"$",
"iterator",
",",
"'/^.+\\.php$/i'",
",",
"1",
")",
";",
"$",
"items",
"=",
"(",
"array",
")",
"array_keys",
"(",
"iterator_to_array",
"(",
"$",
"regex",
")",
")",
";",
"}",
"foreach",
"(",
"(",
"array",
")",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"rename",
"(",
"$",
"item",
",",
"$",
"path",
")",
";",
"$",
"data",
"=",
"require",
"$",
"item",
";",
"$",
"this",
"->",
"set",
"(",
"(",
"string",
")",
"$",
"name",
",",
"$",
"data",
")",
";",
"}",
"}"
] | Loads an array of values from a specified file or directory.
@param string $path
@return void | [
"Loads",
"an",
"array",
"of",
"values",
"from",
"a",
"specified",
"file",
"or",
"directory",
"."
] | 96618b5cee7d20b6700d0475e4334ae4b5163a6b | https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Provider/Configuration.php#L81-L104 | train |
zapheus/zapheus | src/Provider/Configuration.php | Configuration.dotify | protected function dotify(array $data, $result = array(), $key = '')
{
foreach ((array) $data as $name => $value)
{
if (is_array($value) && empty($value) === false)
{
$text = (string) $key . $name . '.';
$item = $this->dotify($value, $result, $text);
$result = array_merge($result, $item);
continue;
}
$result[$key . $name] = $value;
}
return $result;
} | php | protected function dotify(array $data, $result = array(), $key = '')
{
foreach ((array) $data as $name => $value)
{
if (is_array($value) && empty($value) === false)
{
$text = (string) $key . $name . '.';
$item = $this->dotify($value, $result, $text);
$result = array_merge($result, $item);
continue;
}
$result[$key . $name] = $value;
}
return $result;
} | [
"protected",
"function",
"dotify",
"(",
"array",
"$",
"data",
",",
"$",
"result",
"=",
"array",
"(",
")",
",",
"$",
"key",
"=",
"''",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"data",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"empty",
"(",
"$",
"value",
")",
"===",
"false",
")",
"{",
"$",
"text",
"=",
"(",
"string",
")",
"$",
"key",
".",
"$",
"name",
".",
"'.'",
";",
"$",
"item",
"=",
"$",
"this",
"->",
"dotify",
"(",
"$",
"value",
",",
"$",
"result",
",",
"$",
"text",
")",
";",
"$",
"result",
"=",
"array_merge",
"(",
"$",
"result",
",",
"$",
"item",
")",
";",
"continue",
";",
"}",
"$",
"result",
"[",
"$",
"key",
".",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Converts the data into dot notation values.
@param array $data
@param array $result
@param string $key
@return array | [
"Converts",
"the",
"data",
"into",
"dot",
"notation",
"values",
"."
] | 96618b5cee7d20b6700d0475e4334ae4b5163a6b | https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Provider/Configuration.php#L114-L133 | train |
zapheus/zapheus | src/Provider/Configuration.php | Configuration.rename | protected function rename($item, $path)
{
$name = str_replace($path, '', (string) $item);
$name = str_replace(array('\\', '/'), '.', $name);
$regex = preg_replace('/^./i', '', $name);
return basename(strtolower($regex), '.php');
} | php | protected function rename($item, $path)
{
$name = str_replace($path, '', (string) $item);
$name = str_replace(array('\\', '/'), '.', $name);
$regex = preg_replace('/^./i', '', $name);
return basename(strtolower($regex), '.php');
} | [
"protected",
"function",
"rename",
"(",
"$",
"item",
",",
"$",
"path",
")",
"{",
"$",
"name",
"=",
"str_replace",
"(",
"$",
"path",
",",
"''",
",",
"(",
"string",
")",
"$",
"item",
")",
";",
"$",
"name",
"=",
"str_replace",
"(",
"array",
"(",
"'\\\\'",
",",
"'/'",
")",
",",
"'.'",
",",
"$",
"name",
")",
";",
"$",
"regex",
"=",
"preg_replace",
"(",
"'/^./i'",
",",
"''",
",",
"$",
"name",
")",
";",
"return",
"basename",
"(",
"strtolower",
"(",
"$",
"regex",
")",
",",
"'.php'",
")",
";",
"}"
] | Renames the item into a dot notation one.
@param string $item
@param string $path
@return string | [
"Renames",
"the",
"item",
"into",
"a",
"dot",
"notation",
"one",
"."
] | 96618b5cee7d20b6700d0475e4334ae4b5163a6b | https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Provider/Configuration.php#L158-L167 | train |
zapheus/zapheus | src/Provider/Configuration.php | Configuration.save | protected function save(array &$keys, &$data, $value)
{
$key = array_shift($keys);
if (! isset($data[$key]))
{
$data[$key] = array();
}
if (empty($keys))
{
return $data[$key] = $value;
}
return $this->save($keys, $data[$key], $value);
} | php | protected function save(array &$keys, &$data, $value)
{
$key = array_shift($keys);
if (! isset($data[$key]))
{
$data[$key] = array();
}
if (empty($keys))
{
return $data[$key] = $value;
}
return $this->save($keys, $data[$key], $value);
} | [
"protected",
"function",
"save",
"(",
"array",
"&",
"$",
"keys",
",",
"&",
"$",
"data",
",",
"$",
"value",
")",
"{",
"$",
"key",
"=",
"array_shift",
"(",
"$",
"keys",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"keys",
")",
")",
"{",
"return",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
"->",
"save",
"(",
"$",
"keys",
",",
"$",
"data",
"[",
"$",
"key",
"]",
",",
"$",
"value",
")",
";",
"}"
] | Saves the specified key in the list of data.
@param array &$keys
@param array &$data
@param mixed $value
@return mixed | [
"Saves",
"the",
"specified",
"key",
"in",
"the",
"list",
"of",
"data",
"."
] | 96618b5cee7d20b6700d0475e4334ae4b5163a6b | https://github.com/zapheus/zapheus/blob/96618b5cee7d20b6700d0475e4334ae4b5163a6b/src/Provider/Configuration.php#L177-L192 | train |
agentmedia/phine-builtin | src/BuiltIn/Modules/Backend/LogoutForm.php | LogoutForm.InitForm | protected function InitForm()
{
$this->logout = $this->LoadElement();
$this->AddNextUrlField();
$this->AddCssIDField();
$this->AddCssClassField();
$this->AddTemplateField();
$this->AddSubmit();
} | php | protected function InitForm()
{
$this->logout = $this->LoadElement();
$this->AddNextUrlField();
$this->AddCssIDField();
$this->AddCssClassField();
$this->AddTemplateField();
$this->AddSubmit();
} | [
"protected",
"function",
"InitForm",
"(",
")",
"{",
"$",
"this",
"->",
"logout",
"=",
"$",
"this",
"->",
"LoadElement",
"(",
")",
";",
"$",
"this",
"->",
"AddNextUrlField",
"(",
")",
";",
"$",
"this",
"->",
"AddCssIDField",
"(",
")",
";",
"$",
"this",
"->",
"AddCssClassField",
"(",
")",
";",
"$",
"this",
"->",
"AddTemplateField",
"(",
")",
";",
"$",
"this",
"->",
"AddSubmit",
"(",
")",
";",
"}"
] | Intializes the form | [
"Intializes",
"the",
"form"
] | 4dd05bc406a71e997bd4eaa16b12e23dbe62a456 | https://github.com/agentmedia/phine-builtin/blob/4dd05bc406a71e997bd4eaa16b12e23dbe62a456/src/BuiltIn/Modules/Backend/LogoutForm.php#L47-L55 | train |
agentmedia/phine-builtin | src/BuiltIn/Modules/Backend/LogoutForm.php | LogoutForm.SaveElement | protected function SaveElement()
{
$this->logout->SetNextUrl($this->selectorNext->Save($this->logout->GetNextUrl()));
return $this->logout;
} | php | protected function SaveElement()
{
$this->logout->SetNextUrl($this->selectorNext->Save($this->logout->GetNextUrl()));
return $this->logout;
} | [
"protected",
"function",
"SaveElement",
"(",
")",
"{",
"$",
"this",
"->",
"logout",
"->",
"SetNextUrl",
"(",
"$",
"this",
"->",
"selectorNext",
"->",
"Save",
"(",
"$",
"this",
"->",
"logout",
"->",
"GetNextUrl",
"(",
")",
")",
")",
";",
"return",
"$",
"this",
"->",
"logout",
";",
"}"
] | Saves the element and returns it
@return ContentLogout | [
"Saves",
"the",
"element",
"and",
"returns",
"it"
] | 4dd05bc406a71e997bd4eaa16b12e23dbe62a456 | https://github.com/agentmedia/phine-builtin/blob/4dd05bc406a71e997bd4eaa16b12e23dbe62a456/src/BuiltIn/Modules/Backend/LogoutForm.php#L72-L76 | train |
nativgames-old/pegase | src/Pegase/Extension/Form/Service/FormBuilder.php | FormBuilder.generate | public function generate($target, $type = 'post') {
$form = new \Pegase\Extension\Form\Objects\Form(
$target,
$this->sm->get('pegase.security.token_csrf_container'),
$type);
return $form;
} | php | public function generate($target, $type = 'post') {
$form = new \Pegase\Extension\Form\Objects\Form(
$target,
$this->sm->get('pegase.security.token_csrf_container'),
$type);
return $form;
} | [
"public",
"function",
"generate",
"(",
"$",
"target",
",",
"$",
"type",
"=",
"'post'",
")",
"{",
"$",
"form",
"=",
"new",
"\\",
"Pegase",
"\\",
"Extension",
"\\",
"Form",
"\\",
"Objects",
"\\",
"Form",
"(",
"$",
"target",
",",
"$",
"this",
"->",
"sm",
"->",
"get",
"(",
"'pegase.security.token_csrf_container'",
")",
",",
"$",
"type",
")",
";",
"return",
"$",
"form",
";",
"}"
] | generate a form | [
"generate",
"a",
"form"
] | 9a00e09a26f391c988aadecd7640c72316eaa521 | https://github.com/nativgames-old/pegase/blob/9a00e09a26f391c988aadecd7640c72316eaa521/src/Pegase/Extension/Form/Service/FormBuilder.php#L22-L30 | train |
cubicmushroom/valueobjects | src/Geography/Street.php | Street.fromNative | public static function fromNative()
{
$args = func_get_args();
if (\count($args) < 2) {
throw new \BadMethodCallException('You must provide from 2 to 4 arguments: 1) street name, 2) street number, 3) elements, 4) format (optional)');
}
$nameString = $args[0];
$numberString = $args[1];
$elementsString = isset($args[2]) ? $args[2] : null;
$formatString = isset($args[3]) ? $args[3] : null;
$name = new StringLiteral($nameString);
$number = new StringLiteral($numberString);
$elements = $elementsString ? new StringLiteral($elementsString) : null;
$format = $formatString ? new StringLiteral($formatString) : null;
return new self($name, $number, $elements, $format);
} | php | public static function fromNative()
{
$args = func_get_args();
if (\count($args) < 2) {
throw new \BadMethodCallException('You must provide from 2 to 4 arguments: 1) street name, 2) street number, 3) elements, 4) format (optional)');
}
$nameString = $args[0];
$numberString = $args[1];
$elementsString = isset($args[2]) ? $args[2] : null;
$formatString = isset($args[3]) ? $args[3] : null;
$name = new StringLiteral($nameString);
$number = new StringLiteral($numberString);
$elements = $elementsString ? new StringLiteral($elementsString) : null;
$format = $formatString ? new StringLiteral($formatString) : null;
return new self($name, $number, $elements, $format);
} | [
"public",
"static",
"function",
"fromNative",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"if",
"(",
"\\",
"count",
"(",
"$",
"args",
")",
"<",
"2",
")",
"{",
"throw",
"new",
"\\",
"BadMethodCallException",
"(",
"'You must provide from 2 to 4 arguments: 1) street name, 2) street number, 3) elements, 4) format (optional)'",
")",
";",
"}",
"$",
"nameString",
"=",
"$",
"args",
"[",
"0",
"]",
";",
"$",
"numberString",
"=",
"$",
"args",
"[",
"1",
"]",
";",
"$",
"elementsString",
"=",
"isset",
"(",
"$",
"args",
"[",
"2",
"]",
")",
"?",
"$",
"args",
"[",
"2",
"]",
":",
"null",
";",
"$",
"formatString",
"=",
"isset",
"(",
"$",
"args",
"[",
"3",
"]",
")",
"?",
"$",
"args",
"[",
"3",
"]",
":",
"null",
";",
"$",
"name",
"=",
"new",
"StringLiteral",
"(",
"$",
"nameString",
")",
";",
"$",
"number",
"=",
"new",
"StringLiteral",
"(",
"$",
"numberString",
")",
";",
"$",
"elements",
"=",
"$",
"elementsString",
"?",
"new",
"StringLiteral",
"(",
"$",
"elementsString",
")",
":",
"null",
";",
"$",
"format",
"=",
"$",
"formatString",
"?",
"new",
"StringLiteral",
"(",
"$",
"formatString",
")",
":",
"null",
";",
"return",
"new",
"self",
"(",
"$",
"name",
",",
"$",
"number",
",",
"$",
"elements",
",",
"$",
"format",
")",
";",
"}"
] | Returns a new Street from native PHP string name and number.
@param string $name
@param string $number
@param string $elements
@return Street
@throws \BadFunctionCallException | [
"Returns",
"a",
"new",
"Street",
"from",
"native",
"PHP",
"string",
"name",
"and",
"number",
"."
] | 4554239ab75d65eeb9773219aa5b07e9fbfabb92 | https://github.com/cubicmushroom/valueobjects/blob/4554239ab75d65eeb9773219aa5b07e9fbfabb92/src/Geography/Street.php#L35-L54 | train |
cubicmushroom/valueobjects | src/Geography/Street.php | Street.sameValueAs | public function sameValueAs(ValueObjectInterface $street)
{
if (false === Util::classEquals($this, $street)) {
return false;
}
return $this->getName()->sameValueAs($street->getName()) &&
$this->getNumber()->sameValueAs($street->getNumber()) &&
$this->getElements()->sameValueAs($street->getElements());
;
} | php | public function sameValueAs(ValueObjectInterface $street)
{
if (false === Util::classEquals($this, $street)) {
return false;
}
return $this->getName()->sameValueAs($street->getName()) &&
$this->getNumber()->sameValueAs($street->getNumber()) &&
$this->getElements()->sameValueAs($street->getElements());
;
} | [
"public",
"function",
"sameValueAs",
"(",
"ValueObjectInterface",
"$",
"street",
")",
"{",
"if",
"(",
"false",
"===",
"Util",
"::",
"classEquals",
"(",
"$",
"this",
",",
"$",
"street",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"getName",
"(",
")",
"->",
"sameValueAs",
"(",
"$",
"street",
"->",
"getName",
"(",
")",
")",
"&&",
"$",
"this",
"->",
"getNumber",
"(",
")",
"->",
"sameValueAs",
"(",
"$",
"street",
"->",
"getNumber",
"(",
")",
")",
"&&",
"$",
"this",
"->",
"getElements",
"(",
")",
"->",
"sameValueAs",
"(",
"$",
"street",
"->",
"getElements",
"(",
")",
")",
";",
";",
"}"
] | Tells whether two Street objects are equal
@param ValueObjectInterface $street
@return bool | [
"Tells",
"whether",
"two",
"Street",
"objects",
"are",
"equal"
] | 4554239ab75d65eeb9773219aa5b07e9fbfabb92 | https://github.com/cubicmushroom/valueobjects/blob/4554239ab75d65eeb9773219aa5b07e9fbfabb92/src/Geography/Street.php#L83-L93 | train |
rafrsr/generic-api | src/GenericApi.php | GenericApi.validate | protected function validate(ApiServiceInterface $service)
{
$validator = Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator();
$violations = $validator->validate($service);
/** @var ConstraintViolation $violation */
foreach ($violations as $violation) {
$errorMessage = $violation->getMessage();
if ($violation->getPropertyPath()) {
$errorMessage = sprintf('Error in field "%s": ', $violation->getPropertyPath()) . $errorMessage;
}
throw new InvalidApiDataException($errorMessage);
}
} | php | protected function validate(ApiServiceInterface $service)
{
$validator = Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator();
$violations = $validator->validate($service);
/** @var ConstraintViolation $violation */
foreach ($violations as $violation) {
$errorMessage = $violation->getMessage();
if ($violation->getPropertyPath()) {
$errorMessage = sprintf('Error in field "%s": ', $violation->getPropertyPath()) . $errorMessage;
}
throw new InvalidApiDataException($errorMessage);
}
} | [
"protected",
"function",
"validate",
"(",
"ApiServiceInterface",
"$",
"service",
")",
"{",
"$",
"validator",
"=",
"Validation",
"::",
"createValidatorBuilder",
"(",
")",
"->",
"enableAnnotationMapping",
"(",
")",
"->",
"getValidator",
"(",
")",
";",
"$",
"violations",
"=",
"$",
"validator",
"->",
"validate",
"(",
"$",
"service",
")",
";",
"/** @var ConstraintViolation $violation */",
"foreach",
"(",
"$",
"violations",
"as",
"$",
"violation",
")",
"{",
"$",
"errorMessage",
"=",
"$",
"violation",
"->",
"getMessage",
"(",
")",
";",
"if",
"(",
"$",
"violation",
"->",
"getPropertyPath",
"(",
")",
")",
"{",
"$",
"errorMessage",
"=",
"sprintf",
"(",
"'Error in field \"%s\": '",
",",
"$",
"violation",
"->",
"getPropertyPath",
"(",
")",
")",
".",
"$",
"errorMessage",
";",
"}",
"throw",
"new",
"InvalidApiDataException",
"(",
"$",
"errorMessage",
")",
";",
"}",
"}"
] | Validate a service data using Symfony validation component
@param ApiServiceInterface $service
@throws InvalidApiDataException | [
"Validate",
"a",
"service",
"data",
"using",
"Symfony",
"validation",
"component"
] | 2572d3dcc32e03914cf710f0229d72e1c09ea65b | https://github.com/rafrsr/generic-api/blob/2572d3dcc32e03914cf710f0229d72e1c09ea65b/src/GenericApi.php#L235-L247 | train |
vpg/titon.utility | src/Titon/Utility/Time.php | Time.factory | public static function factory($time = null, $timezone = null) {
$timezone = static::timezone($timezone);
if ($time instanceof DateTime) {
return $time->setTimezone($timezone);
}
if (is_numeric($time)) {
$time = '@' . $time;
}
$dt = new DateTime($time);
$dt->setTimezone($timezone);
return $dt;
} | php | public static function factory($time = null, $timezone = null) {
$timezone = static::timezone($timezone);
if ($time instanceof DateTime) {
return $time->setTimezone($timezone);
}
if (is_numeric($time)) {
$time = '@' . $time;
}
$dt = new DateTime($time);
$dt->setTimezone($timezone);
return $dt;
} | [
"public",
"static",
"function",
"factory",
"(",
"$",
"time",
"=",
"null",
",",
"$",
"timezone",
"=",
"null",
")",
"{",
"$",
"timezone",
"=",
"static",
"::",
"timezone",
"(",
"$",
"timezone",
")",
";",
"if",
"(",
"$",
"time",
"instanceof",
"DateTime",
")",
"{",
"return",
"$",
"time",
"->",
"setTimezone",
"(",
"$",
"timezone",
")",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"time",
")",
")",
"{",
"$",
"time",
"=",
"'@'",
".",
"$",
"time",
";",
"}",
"$",
"dt",
"=",
"new",
"DateTime",
"(",
"$",
"time",
")",
";",
"$",
"dt",
"->",
"setTimezone",
"(",
"$",
"timezone",
")",
";",
"return",
"$",
"dt",
";",
"}"
] | Return a DateTime object based on the current time and timezone.
@param string|int $time
@param string $timezone
@return \DateTime | [
"Return",
"a",
"DateTime",
"object",
"based",
"on",
"the",
"current",
"time",
"and",
"timezone",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Time.php#L49-L64 | train |
vpg/titon.utility | src/Titon/Utility/Time.php | Time.isWithinNext | public static function isWithinNext($time, $span) {
$span = static::factory($span);
$time = static::factory($time);
$now = static::factory();
return ($time <= $span && $time >= $now);
} | php | public static function isWithinNext($time, $span) {
$span = static::factory($span);
$time = static::factory($time);
$now = static::factory();
return ($time <= $span && $time >= $now);
} | [
"public",
"static",
"function",
"isWithinNext",
"(",
"$",
"time",
",",
"$",
"span",
")",
"{",
"$",
"span",
"=",
"static",
"::",
"factory",
"(",
"$",
"span",
")",
";",
"$",
"time",
"=",
"static",
"::",
"factory",
"(",
"$",
"time",
")",
";",
"$",
"now",
"=",
"static",
"::",
"factory",
"(",
")",
";",
"return",
"(",
"$",
"time",
"<=",
"$",
"span",
"&&",
"$",
"time",
">=",
"$",
"now",
")",
";",
"}"
] | Returns true if the date passed will be within the next time frame span.
@param string|int $time
@param int $span
@return bool
static | [
"Returns",
"true",
"if",
"the",
"date",
"passed",
"will",
"be",
"within",
"the",
"next",
"time",
"frame",
"span",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Time.php#L124-L130 | train |
vpg/titon.utility | src/Titon/Utility/Time.php | Time.toUnix | public static function toUnix($time) {
if (!$time) {
return time();
} else if ($time instanceof DateTime) {
return $time->format('U');
}
return is_string($time) ? strtotime($time) : (int) $time;
} | php | public static function toUnix($time) {
if (!$time) {
return time();
} else if ($time instanceof DateTime) {
return $time->format('U');
}
return is_string($time) ? strtotime($time) : (int) $time;
} | [
"public",
"static",
"function",
"toUnix",
"(",
"$",
"time",
")",
"{",
"if",
"(",
"!",
"$",
"time",
")",
"{",
"return",
"time",
"(",
")",
";",
"}",
"else",
"if",
"(",
"$",
"time",
"instanceof",
"DateTime",
")",
"{",
"return",
"$",
"time",
"->",
"format",
"(",
"'U'",
")",
";",
"}",
"return",
"is_string",
"(",
"$",
"time",
")",
"?",
"strtotime",
"(",
"$",
"time",
")",
":",
"(",
"int",
")",
"$",
"time",
";",
"}"
] | Return a unix timestamp. If the time is a string convert it, else cast to int.
@param int|string $time
@return int | [
"Return",
"a",
"unix",
"timestamp",
".",
"If",
"the",
"time",
"is",
"a",
"string",
"convert",
"it",
"else",
"cast",
"to",
"int",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Time.php#L156-L165 | train |
vpg/titon.utility | src/Titon/Utility/Time.php | Time.wasLastWeek | public static function wasLastWeek($time) {
$start = static::factory('last week 00:00:00');
$end = clone $start;
$end->modify('next week -1 second');
$time = static::factory($time);
return ($time >= $start && $time <= $end);
} | php | public static function wasLastWeek($time) {
$start = static::factory('last week 00:00:00');
$end = clone $start;
$end->modify('next week -1 second');
$time = static::factory($time);
return ($time >= $start && $time <= $end);
} | [
"public",
"static",
"function",
"wasLastWeek",
"(",
"$",
"time",
")",
"{",
"$",
"start",
"=",
"static",
"::",
"factory",
"(",
"'last week 00:00:00'",
")",
";",
"$",
"end",
"=",
"clone",
"$",
"start",
";",
"$",
"end",
"->",
"modify",
"(",
"'next week -1 second'",
")",
";",
"$",
"time",
"=",
"static",
"::",
"factory",
"(",
"$",
"time",
")",
";",
"return",
"(",
"$",
"time",
">=",
"$",
"start",
"&&",
"$",
"time",
"<=",
"$",
"end",
")",
";",
"}"
] | Returns true if date passed was within last week.
@param string|int $time
@return bool | [
"Returns",
"true",
"if",
"date",
"passed",
"was",
"within",
"last",
"week",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Time.php#L173-L182 | train |
vpg/titon.utility | src/Titon/Utility/Time.php | Time.wasLastMonth | public static function wasLastMonth($time) {
$start = static::factory('first day of last month 00:00:00');
$end = clone $start;
$end->modify('next month -1 second');
$time = static::factory($time);
return ($time >= $start && $time <= $end);
} | php | public static function wasLastMonth($time) {
$start = static::factory('first day of last month 00:00:00');
$end = clone $start;
$end->modify('next month -1 second');
$time = static::factory($time);
return ($time >= $start && $time <= $end);
} | [
"public",
"static",
"function",
"wasLastMonth",
"(",
"$",
"time",
")",
"{",
"$",
"start",
"=",
"static",
"::",
"factory",
"(",
"'first day of last month 00:00:00'",
")",
";",
"$",
"end",
"=",
"clone",
"$",
"start",
";",
"$",
"end",
"->",
"modify",
"(",
"'next month -1 second'",
")",
";",
"$",
"time",
"=",
"static",
"::",
"factory",
"(",
"$",
"time",
")",
";",
"return",
"(",
"$",
"time",
">=",
"$",
"start",
"&&",
"$",
"time",
"<=",
"$",
"end",
")",
";",
"}"
] | Returns true if date passed was within last month.
@param string|int $time
@return bool | [
"Returns",
"true",
"if",
"date",
"passed",
"was",
"within",
"last",
"month",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Time.php#L190-L199 | train |
vpg/titon.utility | src/Titon/Utility/Time.php | Time.wasLastYear | public static function wasLastYear($time) {
$start = static::factory('last year January 1st 00:00:00');
$end = clone $start;
$end->modify('next year -1 second');
$time = static::factory($time);
return ($time >= $start && $time <= $end);
} | php | public static function wasLastYear($time) {
$start = static::factory('last year January 1st 00:00:00');
$end = clone $start;
$end->modify('next year -1 second');
$time = static::factory($time);
return ($time >= $start && $time <= $end);
} | [
"public",
"static",
"function",
"wasLastYear",
"(",
"$",
"time",
")",
"{",
"$",
"start",
"=",
"static",
"::",
"factory",
"(",
"'last year January 1st 00:00:00'",
")",
";",
"$",
"end",
"=",
"clone",
"$",
"start",
";",
"$",
"end",
"->",
"modify",
"(",
"'next year -1 second'",
")",
";",
"$",
"time",
"=",
"static",
"::",
"factory",
"(",
"$",
"time",
")",
";",
"return",
"(",
"$",
"time",
">=",
"$",
"start",
"&&",
"$",
"time",
"<=",
"$",
"end",
")",
";",
"}"
] | Returns true if date passed was within last year.
@param string|int $time
@return bool | [
"Returns",
"true",
"if",
"date",
"passed",
"was",
"within",
"last",
"year",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Time.php#L207-L216 | train |
vpg/titon.utility | src/Titon/Utility/Time.php | Time.wasWithinLast | public static function wasWithinLast($time, $span) {
$span = static::factory($span);
$time = static::factory($time);
$now = static::factory();
return ($time >= $span && $time <= $now);
} | php | public static function wasWithinLast($time, $span) {
$span = static::factory($span);
$time = static::factory($time);
$now = static::factory();
return ($time >= $span && $time <= $now);
} | [
"public",
"static",
"function",
"wasWithinLast",
"(",
"$",
"time",
",",
"$",
"span",
")",
"{",
"$",
"span",
"=",
"static",
"::",
"factory",
"(",
"$",
"span",
")",
";",
"$",
"time",
"=",
"static",
"::",
"factory",
"(",
"$",
"time",
")",
";",
"$",
"now",
"=",
"static",
"::",
"factory",
"(",
")",
";",
"return",
"(",
"$",
"time",
">=",
"$",
"span",
"&&",
"$",
"time",
"<=",
"$",
"now",
")",
";",
"}"
] | Returns true if the date passed was within the last time frame span.
@param string|int $time
@param int $span
@return bool | [
"Returns",
"true",
"if",
"the",
"date",
"passed",
"was",
"within",
"the",
"last",
"time",
"frame",
"span",
"."
] | 8a77eb9e7b8baacf41cc25487289779d8319cd3a | https://github.com/vpg/titon.utility/blob/8a77eb9e7b8baacf41cc25487289779d8319cd3a/src/Titon/Utility/Time.php#L235-L241 | train |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Persister/CollectionPersister.php | CollectionPersister.delete | public function delete(PersistentCollectionInterface $coll)
{
$mapping = $coll->getMapping();
if ($mapping->isInverseSide) {
return; // ignore inverse side
}
if ($mapping->strategy === PropertyMetadata::STORAGE_STRATEGY_ATOMIC_SET) {
throw new \UnexpectedValueException(sprintf('%s delete collection strategy should have been handled by DocumentPersister. Please report a bug in issue tracker', $mapping->strategy));
}
list($qb, $path, $parent) = $this->getQueryPathAndParent($coll);
$path->remove();
$this->executeQuery($qb, $parent);
} | php | public function delete(PersistentCollectionInterface $coll)
{
$mapping = $coll->getMapping();
if ($mapping->isInverseSide) {
return; // ignore inverse side
}
if ($mapping->strategy === PropertyMetadata::STORAGE_STRATEGY_ATOMIC_SET) {
throw new \UnexpectedValueException(sprintf('%s delete collection strategy should have been handled by DocumentPersister. Please report a bug in issue tracker', $mapping->strategy));
}
list($qb, $path, $parent) = $this->getQueryPathAndParent($coll);
$path->remove();
$this->executeQuery($qb, $parent);
} | [
"public",
"function",
"delete",
"(",
"PersistentCollectionInterface",
"$",
"coll",
")",
"{",
"$",
"mapping",
"=",
"$",
"coll",
"->",
"getMapping",
"(",
")",
";",
"if",
"(",
"$",
"mapping",
"->",
"isInverseSide",
")",
"{",
"return",
";",
"// ignore inverse side",
"}",
"if",
"(",
"$",
"mapping",
"->",
"strategy",
"===",
"PropertyMetadata",
"::",
"STORAGE_STRATEGY_ATOMIC_SET",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"'%s delete collection strategy should have been handled by DocumentPersister. Please report a bug in issue tracker'",
",",
"$",
"mapping",
"->",
"strategy",
")",
")",
";",
"}",
"list",
"(",
"$",
"qb",
",",
"$",
"path",
",",
"$",
"parent",
")",
"=",
"$",
"this",
"->",
"getQueryPathAndParent",
"(",
"$",
"coll",
")",
";",
"$",
"path",
"->",
"remove",
"(",
")",
";",
"$",
"this",
"->",
"executeQuery",
"(",
"$",
"qb",
",",
"$",
"parent",
")",
";",
"}"
] | Deletes a PersistentCollection instance completely from a document using REMOVE.
@param PersistentCollectionInterface $coll | [
"Deletes",
"a",
"PersistentCollection",
"instance",
"completely",
"from",
"a",
"document",
"using",
"REMOVE",
"."
] | 119d355e2c5cbaef1f867970349b4432f5704fcd | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Persister/CollectionPersister.php#L75-L89 | train |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Persister/CollectionPersister.php | CollectionPersister.getQueryPathAndParent | public function getQueryPathAndParent(PersistentCollectionInterface $coll, QueryBuilder $qb = null)
{
$collMapping = $coll->getMapping();
$parent = $coll->getOwner();
$paths[] = [$collMapping->name, null];
while (($association = $this->uow->getParentAssociation($parent)) !== null) {
list($mapping, $owner, $propertyName, $propertyKey) = $association;
if ($mapping->reference) {
break;
}
$parent = $owner;
$paths[] = [$propertyName, $propertyKey];
}
if ($qb === null) {
$qb = $this->dm->createQueryBuilder(get_class($parent));
}
/** @var RootPath|null $path */
$path = null;
foreach (array_reverse($paths) as $pathValue) {
list($pathName, $pathKey) = $pathValue;
$path = $path === null ? $qb->attr($pathName) : $path->map($pathName);
switch (gettype($pathKey)) {
case 'string':
$path = $path->map($pathKey);
break;
case 'integer':
$path = $path->i($pathKey);
break;
}
}
return [$qb, $path, $parent];
} | php | public function getQueryPathAndParent(PersistentCollectionInterface $coll, QueryBuilder $qb = null)
{
$collMapping = $coll->getMapping();
$parent = $coll->getOwner();
$paths[] = [$collMapping->name, null];
while (($association = $this->uow->getParentAssociation($parent)) !== null) {
list($mapping, $owner, $propertyName, $propertyKey) = $association;
if ($mapping->reference) {
break;
}
$parent = $owner;
$paths[] = [$propertyName, $propertyKey];
}
if ($qb === null) {
$qb = $this->dm->createQueryBuilder(get_class($parent));
}
/** @var RootPath|null $path */
$path = null;
foreach (array_reverse($paths) as $pathValue) {
list($pathName, $pathKey) = $pathValue;
$path = $path === null ? $qb->attr($pathName) : $path->map($pathName);
switch (gettype($pathKey)) {
case 'string':
$path = $path->map($pathKey);
break;
case 'integer':
$path = $path->i($pathKey);
break;
}
}
return [$qb, $path, $parent];
} | [
"public",
"function",
"getQueryPathAndParent",
"(",
"PersistentCollectionInterface",
"$",
"coll",
",",
"QueryBuilder",
"$",
"qb",
"=",
"null",
")",
"{",
"$",
"collMapping",
"=",
"$",
"coll",
"->",
"getMapping",
"(",
")",
";",
"$",
"parent",
"=",
"$",
"coll",
"->",
"getOwner",
"(",
")",
";",
"$",
"paths",
"[",
"]",
"=",
"[",
"$",
"collMapping",
"->",
"name",
",",
"null",
"]",
";",
"while",
"(",
"(",
"$",
"association",
"=",
"$",
"this",
"->",
"uow",
"->",
"getParentAssociation",
"(",
"$",
"parent",
")",
")",
"!==",
"null",
")",
"{",
"list",
"(",
"$",
"mapping",
",",
"$",
"owner",
",",
"$",
"propertyName",
",",
"$",
"propertyKey",
")",
"=",
"$",
"association",
";",
"if",
"(",
"$",
"mapping",
"->",
"reference",
")",
"{",
"break",
";",
"}",
"$",
"parent",
"=",
"$",
"owner",
";",
"$",
"paths",
"[",
"]",
"=",
"[",
"$",
"propertyName",
",",
"$",
"propertyKey",
"]",
";",
"}",
"if",
"(",
"$",
"qb",
"===",
"null",
")",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"dm",
"->",
"createQueryBuilder",
"(",
"get_class",
"(",
"$",
"parent",
")",
")",
";",
"}",
"/** @var RootPath|null $path */",
"$",
"path",
"=",
"null",
";",
"foreach",
"(",
"array_reverse",
"(",
"$",
"paths",
")",
"as",
"$",
"pathValue",
")",
"{",
"list",
"(",
"$",
"pathName",
",",
"$",
"pathKey",
")",
"=",
"$",
"pathValue",
";",
"$",
"path",
"=",
"$",
"path",
"===",
"null",
"?",
"$",
"qb",
"->",
"attr",
"(",
"$",
"pathName",
")",
":",
"$",
"path",
"->",
"map",
"(",
"$",
"pathName",
")",
";",
"switch",
"(",
"gettype",
"(",
"$",
"pathKey",
")",
")",
"{",
"case",
"'string'",
":",
"$",
"path",
"=",
"$",
"path",
"->",
"map",
"(",
"$",
"pathKey",
")",
";",
"break",
";",
"case",
"'integer'",
":",
"$",
"path",
"=",
"$",
"path",
"->",
"i",
"(",
"$",
"pathKey",
")",
";",
"break",
";",
"}",
"}",
"return",
"[",
"$",
"qb",
",",
"$",
"path",
",",
"$",
"parent",
"]",
";",
"}"
] | Create and return a QueryBuilder and Path instance representing the provided
collection's document path, along with the top-level document.
@param PersistentCollectionInterface $coll
@param QueryBuilder|null $qb
@return mixed[] list($qb, $path, $parent) | [
"Create",
"and",
"return",
"a",
"QueryBuilder",
"and",
"Path",
"instance",
"representing",
"the",
"provided",
"collection",
"s",
"document",
"path",
"along",
"with",
"the",
"top",
"-",
"level",
"document",
"."
] | 119d355e2c5cbaef1f867970349b4432f5704fcd | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Persister/CollectionPersister.php#L176-L215 | train |
iqg/UtilsBundle | Utils/StringUtil.php | StringUtil.randomStr | public function randomStr( $length = 16 )
{
$arr = array_merge(range(0, 9), range('a', 'z'), range('A', 'Z'));
$str = '';
$arr_len = count($arr);
for ($i = 0; $i < $length; $i++)
{
$rand = mt_rand(0, $arr_len-1);
$str.=$arr[$rand];
}
return $str;
} | php | public function randomStr( $length = 16 )
{
$arr = array_merge(range(0, 9), range('a', 'z'), range('A', 'Z'));
$str = '';
$arr_len = count($arr);
for ($i = 0; $i < $length; $i++)
{
$rand = mt_rand(0, $arr_len-1);
$str.=$arr[$rand];
}
return $str;
} | [
"public",
"function",
"randomStr",
"(",
"$",
"length",
"=",
"16",
")",
"{",
"$",
"arr",
"=",
"array_merge",
"(",
"range",
"(",
"0",
",",
"9",
")",
",",
"range",
"(",
"'a'",
",",
"'z'",
")",
",",
"range",
"(",
"'A'",
",",
"'Z'",
")",
")",
";",
"$",
"str",
"=",
"''",
";",
"$",
"arr_len",
"=",
"count",
"(",
"$",
"arr",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"rand",
"=",
"mt_rand",
"(",
"0",
",",
"$",
"arr_len",
"-",
"1",
")",
";",
"$",
"str",
".=",
"$",
"arr",
"[",
"$",
"rand",
"]",
";",
"}",
"return",
"$",
"str",
";",
"}"
] | generate a random string include uppercase and lowercase letters and numbers | [
"generate",
"a",
"random",
"string",
"include",
"uppercase",
"and",
"lowercase",
"letters",
"and",
"numbers"
] | ef1ed67fc5dc8605d9828f8ecba0e4645faf8bc8 | https://github.com/iqg/UtilsBundle/blob/ef1ed67fc5dc8605d9828f8ecba0e4645faf8bc8/Utils/StringUtil.php#L78-L91 | train |
stubbles/stubbles-dbal | src/main/php/config/ArrayBasedDatabaseConfigurations.php | ArrayBasedDatabaseConfigurations.get | public function get(string $id): DatabaseConfiguration
{
if (isset($this->configurations[$id])) {
return $this->configurations[$id];
}
throw new \OutOfBoundsException(
'No database configuration known for database requested with id '
. $id
);
} | php | public function get(string $id): DatabaseConfiguration
{
if (isset($this->configurations[$id])) {
return $this->configurations[$id];
}
throw new \OutOfBoundsException(
'No database configuration known for database requested with id '
. $id
);
} | [
"public",
"function",
"get",
"(",
"string",
"$",
"id",
")",
":",
"DatabaseConfiguration",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"configurations",
"[",
"$",
"id",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"configurations",
"[",
"$",
"id",
"]",
";",
"}",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"'No database configuration known for database requested with id '",
".",
"$",
"id",
")",
";",
"}"
] | returns database configuration for given id
@param string $id id of configuration to return
@return \stubbles\db\config\DatabaseConfiguration
@throws \OutOfBoundsException in case no config for given id exists | [
"returns",
"database",
"configuration",
"for",
"given",
"id"
] | b42a589025a9e511b40a2798ac84df94d6451c36 | https://github.com/stubbles/stubbles-dbal/blob/b42a589025a9e511b40a2798ac84df94d6451c36/src/main/php/config/ArrayBasedDatabaseConfigurations.php#L54-L64 | train |
Zazalt/Databaser | src/Engine/PostgreSQL.php | PostgreSQL.getTables | public function getTables()
{
$statement = $this->connection->prepare("SELECT * FROM information_schema.tables WHERE table_catalog = :database AND table_schema = 'public'");
$statement->execute([
':database' => $this->Databaser->database
]);
return $statement->fetchAll(\PDO::FETCH_ASSOC);
} | php | public function getTables()
{
$statement = $this->connection->prepare("SELECT * FROM information_schema.tables WHERE table_catalog = :database AND table_schema = 'public'");
$statement->execute([
':database' => $this->Databaser->database
]);
return $statement->fetchAll(\PDO::FETCH_ASSOC);
} | [
"public",
"function",
"getTables",
"(",
")",
"{",
"$",
"statement",
"=",
"$",
"this",
"->",
"connection",
"->",
"prepare",
"(",
"\"SELECT * FROM information_schema.tables WHERE table_catalog = :database AND table_schema = 'public'\"",
")",
";",
"$",
"statement",
"->",
"execute",
"(",
"[",
"':database'",
"=>",
"$",
"this",
"->",
"Databaser",
"->",
"database",
"]",
")",
";",
"return",
"$",
"statement",
"->",
"fetchAll",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"}"
] | Get all tables for a database | [
"Get",
"all",
"tables",
"for",
"a",
"database"
] | 245eccd6ee960435b1c7fa5031d8f3db4ef557f2 | https://github.com/Zazalt/Databaser/blob/245eccd6ee960435b1c7fa5031d8f3db4ef557f2/src/Engine/PostgreSQL.php#L69-L77 | train |
Zazalt/Databaser | src/Engine/PostgreSQL.php | PostgreSQL.getTableRows | public function getTableRows(string $tableName)
{
$statement = $this->connection->prepare("SELECT * FROM information_schema.columns WHERE table_catalog = :database AND table_name = :table");
$statement->execute([
':database' => $this->Databaser->database,
':table' => $tableName
]);
return $statement->fetchAll(\PDO::FETCH_ASSOC);
} | php | public function getTableRows(string $tableName)
{
$statement = $this->connection->prepare("SELECT * FROM information_schema.columns WHERE table_catalog = :database AND table_name = :table");
$statement->execute([
':database' => $this->Databaser->database,
':table' => $tableName
]);
return $statement->fetchAll(\PDO::FETCH_ASSOC);
} | [
"public",
"function",
"getTableRows",
"(",
"string",
"$",
"tableName",
")",
"{",
"$",
"statement",
"=",
"$",
"this",
"->",
"connection",
"->",
"prepare",
"(",
"\"SELECT * FROM information_schema.columns WHERE table_catalog = :database AND table_name = :table\"",
")",
";",
"$",
"statement",
"->",
"execute",
"(",
"[",
"':database'",
"=>",
"$",
"this",
"->",
"Databaser",
"->",
"database",
",",
"':table'",
"=>",
"$",
"tableName",
"]",
")",
";",
"return",
"$",
"statement",
"->",
"fetchAll",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"}"
] | Get all rows for all tables | [
"Get",
"all",
"rows",
"for",
"all",
"tables"
] | 245eccd6ee960435b1c7fa5031d8f3db4ef557f2 | https://github.com/Zazalt/Databaser/blob/245eccd6ee960435b1c7fa5031d8f3db4ef557f2/src/Engine/PostgreSQL.php#L82-L91 | train |
Erebot/CallableWrapper | src/CallableWrapper.php | CallableWrapper.wrap | public static function wrap($callable)
{
$parts = explode('::', static::represent($callable));
if (count($parts) == 1) {
// We wrapped a function.
$reflector = new \ReflectionFunction($callable);
} else {
if (!is_array($callable)) {
// We wrapped a Closure or some invokable object.
$callable = array($callable, $parts[1]);
}
$reflector = new \ReflectionMethod($callable[0], $callable[1]);
}
// References are lost, unless __invoke()'s signature also requires them.
// We must also make sure default values are preserved.
$args = array();
foreach ($reflector->getParameters() as $argReflect) {
$arg = '';
if ($argReflect->isPassedByReference()) {
$arg .= '&';
}
$arg .= '$a' . count($args);
if ($argReflect->isOptional()) {
$arg .= '=' . var_export($argReflect->getDefaultValue(), true);
} else {
$arg .= '=null';
}
$args[] = $arg;
}
$args = implode(',', $args);
$class = 'Wrapped_' . sha1($args);
if (!class_exists("\\Erebot\\CallableWrapper\\$class", false)) {
$tpl = "
namespace Erebot\\CallableWrapper {
class $class extends \\Erebot\\CallableWrapper
{
public function __invoke($args)
{
// HACK: we use debug_backtrace() to get (and pass along)
// references for call_user_func_array().
// Starting with PHP 5.4.0, it is possible to limit
// the number of stack frames returned.
if (version_compare(PHP_VERSION, '5.4', '>='))
\$bt = debug_backtrace(0, 1);
// Starting with PHP 5.3.6, the first argument
// to debug_backtrace() is a bitmask of options.
else if (version_compare(PHP_VERSION, '5.3.6', '>='))
\$bt = debug_backtrace(0);
else
\$bt = debug_backtrace(FALSE);
if (isset(\$bt[0]['args']))
\$args =& \$bt[0]['args'];
else
\$args = array();
return call_user_func_array(\$this->callable, \$args);
}
}
}
";
eval($tpl);
}
$class = "\\Erebot\\CallableWrapper\\$class";
return new $class($callable);
} | php | public static function wrap($callable)
{
$parts = explode('::', static::represent($callable));
if (count($parts) == 1) {
// We wrapped a function.
$reflector = new \ReflectionFunction($callable);
} else {
if (!is_array($callable)) {
// We wrapped a Closure or some invokable object.
$callable = array($callable, $parts[1]);
}
$reflector = new \ReflectionMethod($callable[0], $callable[1]);
}
// References are lost, unless __invoke()'s signature also requires them.
// We must also make sure default values are preserved.
$args = array();
foreach ($reflector->getParameters() as $argReflect) {
$arg = '';
if ($argReflect->isPassedByReference()) {
$arg .= '&';
}
$arg .= '$a' . count($args);
if ($argReflect->isOptional()) {
$arg .= '=' . var_export($argReflect->getDefaultValue(), true);
} else {
$arg .= '=null';
}
$args[] = $arg;
}
$args = implode(',', $args);
$class = 'Wrapped_' . sha1($args);
if (!class_exists("\\Erebot\\CallableWrapper\\$class", false)) {
$tpl = "
namespace Erebot\\CallableWrapper {
class $class extends \\Erebot\\CallableWrapper
{
public function __invoke($args)
{
// HACK: we use debug_backtrace() to get (and pass along)
// references for call_user_func_array().
// Starting with PHP 5.4.0, it is possible to limit
// the number of stack frames returned.
if (version_compare(PHP_VERSION, '5.4', '>='))
\$bt = debug_backtrace(0, 1);
// Starting with PHP 5.3.6, the first argument
// to debug_backtrace() is a bitmask of options.
else if (version_compare(PHP_VERSION, '5.3.6', '>='))
\$bt = debug_backtrace(0);
else
\$bt = debug_backtrace(FALSE);
if (isset(\$bt[0]['args']))
\$args =& \$bt[0]['args'];
else
\$args = array();
return call_user_func_array(\$this->callable, \$args);
}
}
}
";
eval($tpl);
}
$class = "\\Erebot\\CallableWrapper\\$class";
return new $class($callable);
} | [
"public",
"static",
"function",
"wrap",
"(",
"$",
"callable",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'::'",
",",
"static",
"::",
"represent",
"(",
"$",
"callable",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
"==",
"1",
")",
"{",
"// We wrapped a function.",
"$",
"reflector",
"=",
"new",
"\\",
"ReflectionFunction",
"(",
"$",
"callable",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"callable",
")",
")",
"{",
"// We wrapped a Closure or some invokable object.",
"$",
"callable",
"=",
"array",
"(",
"$",
"callable",
",",
"$",
"parts",
"[",
"1",
"]",
")",
";",
"}",
"$",
"reflector",
"=",
"new",
"\\",
"ReflectionMethod",
"(",
"$",
"callable",
"[",
"0",
"]",
",",
"$",
"callable",
"[",
"1",
"]",
")",
";",
"}",
"// References are lost, unless __invoke()'s signature also requires them.",
"// We must also make sure default values are preserved.",
"$",
"args",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"reflector",
"->",
"getParameters",
"(",
")",
"as",
"$",
"argReflect",
")",
"{",
"$",
"arg",
"=",
"''",
";",
"if",
"(",
"$",
"argReflect",
"->",
"isPassedByReference",
"(",
")",
")",
"{",
"$",
"arg",
".=",
"'&'",
";",
"}",
"$",
"arg",
".=",
"'$a'",
".",
"count",
"(",
"$",
"args",
")",
";",
"if",
"(",
"$",
"argReflect",
"->",
"isOptional",
"(",
")",
")",
"{",
"$",
"arg",
".=",
"'='",
".",
"var_export",
"(",
"$",
"argReflect",
"->",
"getDefaultValue",
"(",
")",
",",
"true",
")",
";",
"}",
"else",
"{",
"$",
"arg",
".=",
"'=null'",
";",
"}",
"$",
"args",
"[",
"]",
"=",
"$",
"arg",
";",
"}",
"$",
"args",
"=",
"implode",
"(",
"','",
",",
"$",
"args",
")",
";",
"$",
"class",
"=",
"'Wrapped_'",
".",
"sha1",
"(",
"$",
"args",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"\"\\\\Erebot\\\\CallableWrapper\\\\$class\"",
",",
"false",
")",
")",
"{",
"$",
"tpl",
"=",
"\"\n namespace Erebot\\\\CallableWrapper {\n class $class extends \\\\Erebot\\\\CallableWrapper\n {\n public function __invoke($args)\n {\n // HACK: we use debug_backtrace() to get (and pass along)\n // references for call_user_func_array().\n\n // Starting with PHP 5.4.0, it is possible to limit\n // the number of stack frames returned.\n if (version_compare(PHP_VERSION, '5.4', '>='))\n \\$bt = debug_backtrace(0, 1);\n // Starting with PHP 5.3.6, the first argument\n // to debug_backtrace() is a bitmask of options.\n else if (version_compare(PHP_VERSION, '5.3.6', '>='))\n \\$bt = debug_backtrace(0);\n else\n \\$bt = debug_backtrace(FALSE);\n\n if (isset(\\$bt[0]['args']))\n \\$args =& \\$bt[0]['args'];\n else\n \\$args = array();\n return call_user_func_array(\\$this->callable, \\$args);\n }\n }\n }\n \"",
";",
"eval",
"(",
"$",
"tpl",
")",
";",
"}",
"$",
"class",
"=",
"\"\\\\Erebot\\\\CallableWrapper\\\\$class\"",
";",
"return",
"new",
"$",
"class",
"(",
"$",
"callable",
")",
";",
"}"
] | Wraps an existing callable piece of code.
\param mixed $callable
Callable piece of code to wrap.
\retval Erebot::CallableInterface
An object of a class implementing the
Erebot::CallableInterface is returned.
The precise type of the object will usually vary
between calls as new types are created on-the-fly
if needed. | [
"Wraps",
"an",
"existing",
"callable",
"piece",
"of",
"code",
"."
] | 28b427e7471d21ed60d9feee3886ff3b43b78d33 | https://github.com/Erebot/CallableWrapper/blob/28b427e7471d21ed60d9feee3886ff3b43b78d33/src/CallableWrapper.php#L90-L157 | train |
Erebot/CallableWrapper | src/CallableWrapper.php | CallableWrapper.initialize | public static function initialize()
{
static $initialized = false;
static $structures = array();
if (defined('T_CALLABLE')) {
return;
}
if (!$initialized) {
spl_autoload_register(
function ($class) {
$parts = array_map('strrev', explode('\\', strrev($class), 2));
$short = array_shift($parts);
$ns = (string) array_shift($parts);
if ($short === 'callable') {
// The class to load is "callable", inject the alias.
if (class_alias('\\Erebot\\CallableInterface', $class, true) !== true) {
throw new \RuntimeException('Could not load wrapper');
}
return true;
}
// Otherwise, inject the alias in the namespace
// of the class being loaded.
class_exists("$ns\\callable");
return false;
},
true
);
$initialized = true;
}
// Inject the alias in existing namespaces.
$funcs = get_defined_functions();
$new = array_merge(
$funcs['user'],
get_declared_classes(),
get_declared_interfaces()
);
if ($new != $structures) {
$newNS = array();
foreach (array_diff($new, $structures) as $structure) {
$parts = explode('\\', strrev($structure), 2);
array_shift($parts); // Remove class/interface name.
$newNS[] = (string) array_shift($parts);
}
$structures = $new;
$newNS = array_unique($newNS);
foreach ($newNS as $ns) {
class_exists(strrev($ns) . '\\callable');
}
}
} | php | public static function initialize()
{
static $initialized = false;
static $structures = array();
if (defined('T_CALLABLE')) {
return;
}
if (!$initialized) {
spl_autoload_register(
function ($class) {
$parts = array_map('strrev', explode('\\', strrev($class), 2));
$short = array_shift($parts);
$ns = (string) array_shift($parts);
if ($short === 'callable') {
// The class to load is "callable", inject the alias.
if (class_alias('\\Erebot\\CallableInterface', $class, true) !== true) {
throw new \RuntimeException('Could not load wrapper');
}
return true;
}
// Otherwise, inject the alias in the namespace
// of the class being loaded.
class_exists("$ns\\callable");
return false;
},
true
);
$initialized = true;
}
// Inject the alias in existing namespaces.
$funcs = get_defined_functions();
$new = array_merge(
$funcs['user'],
get_declared_classes(),
get_declared_interfaces()
);
if ($new != $structures) {
$newNS = array();
foreach (array_diff($new, $structures) as $structure) {
$parts = explode('\\', strrev($structure), 2);
array_shift($parts); // Remove class/interface name.
$newNS[] = (string) array_shift($parts);
}
$structures = $new;
$newNS = array_unique($newNS);
foreach ($newNS as $ns) {
class_exists(strrev($ns) . '\\callable');
}
}
} | [
"public",
"static",
"function",
"initialize",
"(",
")",
"{",
"static",
"$",
"initialized",
"=",
"false",
";",
"static",
"$",
"structures",
"=",
"array",
"(",
")",
";",
"if",
"(",
"defined",
"(",
"'T_CALLABLE'",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"initialized",
")",
"{",
"spl_autoload_register",
"(",
"function",
"(",
"$",
"class",
")",
"{",
"$",
"parts",
"=",
"array_map",
"(",
"'strrev'",
",",
"explode",
"(",
"'\\\\'",
",",
"strrev",
"(",
"$",
"class",
")",
",",
"2",
")",
")",
";",
"$",
"short",
"=",
"array_shift",
"(",
"$",
"parts",
")",
";",
"$",
"ns",
"=",
"(",
"string",
")",
"array_shift",
"(",
"$",
"parts",
")",
";",
"if",
"(",
"$",
"short",
"===",
"'callable'",
")",
"{",
"// The class to load is \"callable\", inject the alias.",
"if",
"(",
"class_alias",
"(",
"'\\\\Erebot\\\\CallableInterface'",
",",
"$",
"class",
",",
"true",
")",
"!==",
"true",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Could not load wrapper'",
")",
";",
"}",
"return",
"true",
";",
"}",
"// Otherwise, inject the alias in the namespace",
"// of the class being loaded.",
"class_exists",
"(",
"\"$ns\\\\callable\"",
")",
";",
"return",
"false",
";",
"}",
",",
"true",
")",
";",
"$",
"initialized",
"=",
"true",
";",
"}",
"// Inject the alias in existing namespaces.",
"$",
"funcs",
"=",
"get_defined_functions",
"(",
")",
";",
"$",
"new",
"=",
"array_merge",
"(",
"$",
"funcs",
"[",
"'user'",
"]",
",",
"get_declared_classes",
"(",
")",
",",
"get_declared_interfaces",
"(",
")",
")",
";",
"if",
"(",
"$",
"new",
"!=",
"$",
"structures",
")",
"{",
"$",
"newNS",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"array_diff",
"(",
"$",
"new",
",",
"$",
"structures",
")",
"as",
"$",
"structure",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'\\\\'",
",",
"strrev",
"(",
"$",
"structure",
")",
",",
"2",
")",
";",
"array_shift",
"(",
"$",
"parts",
")",
";",
"// Remove class/interface name.",
"$",
"newNS",
"[",
"]",
"=",
"(",
"string",
")",
"array_shift",
"(",
"$",
"parts",
")",
";",
"}",
"$",
"structures",
"=",
"$",
"new",
";",
"$",
"newNS",
"=",
"array_unique",
"(",
"$",
"newNS",
")",
";",
"foreach",
"(",
"$",
"newNS",
"as",
"$",
"ns",
")",
"{",
"class_exists",
"(",
"strrev",
"(",
"$",
"ns",
")",
".",
"'\\\\callable'",
")",
";",
"}",
"}",
"}"
] | Initialize the wrapper.
\param bool $existing
(optional) Whether to inject the wrapper inside existing
namespaces. You don't need to pass this argument: the wrapper
already does so internally when needed.
\note
This method must be called before using any of the wrapper's
other methods. It registers an autoloader that automatically
adds a "callable" typehint to namespaces on PHP 5.3.x when
a new class/interface is autoloaded.
\note
This method needs to be called only once, unless you're using
functions or requiring/including files manually, in which case
it is advisable to call this method periodically (eg. using
register_tick_function() and declare(ticks=N) with an adequate
value for N depending on your code). | [
"Initialize",
"the",
"wrapper",
"."
] | 28b427e7471d21ed60d9feee3886ff3b43b78d33 | https://github.com/Erebot/CallableWrapper/blob/28b427e7471d21ed60d9feee3886ff3b43b78d33/src/CallableWrapper.php#L180-L235 | train |
zeageorge/php-object | src/Object/Event.php | Event.subscribe | public function subscribe($handler, $priority = Event::DEFAULT_CALLBACKS_PRIORITY)
{
$_priority = \is_int($priority) ? $priority : self::DEFAULT_CALLBACKS_PRIORITY;
if (!($_priority >= self::DEFAULT_CALLBACKS_MAX_PRIORITY && $_priority <= self::DEFAULT_CALLBACKS_MIN_PRIORITY)) {
$_priority = self::DEFAULT_CALLBACKS_PRIORITY;
}
if (\array_key_exists($_priority, $this->callbacks)) {
foreach ($this->callbacks[$_priority] as $callback) {
if ($callback == $handler) {
return $this;
}
}
} else {
$this->callbacks[$_priority] = [];
}
if (\is_string($handler) || \is_callable($handler) || $handler instanceof \Closure) {
$this->callbacks[$_priority][] = $handler;
} else if (\is_array($handler)) {
if (\count($handler) == 2) {
if ((\is_string($handler[0]) // static call, ['Page', 'handleClick'] --> Page::handleClick()
|| \is_object($handler[0])) // method call, [$object, 'handleClick'] --> $object->handleClick()
&& (\is_string($handler[1]))
) {
$this->callbacks[$_priority][] = $handler;
} else { // error, unknown $handler type...
throw new UnknownEventHandlerTypeException("Unknown Event handler type.");
}
} else { // error, unknown $handler type...
throw new UnknownEventHandlerTypeException("Unknown Event handler type.");
}
} else { // error, unknown $handler type...
throw new UnknownEventHandlerTypeException("Unknown Event handler type.");
}
return $this;
} | php | public function subscribe($handler, $priority = Event::DEFAULT_CALLBACKS_PRIORITY)
{
$_priority = \is_int($priority) ? $priority : self::DEFAULT_CALLBACKS_PRIORITY;
if (!($_priority >= self::DEFAULT_CALLBACKS_MAX_PRIORITY && $_priority <= self::DEFAULT_CALLBACKS_MIN_PRIORITY)) {
$_priority = self::DEFAULT_CALLBACKS_PRIORITY;
}
if (\array_key_exists($_priority, $this->callbacks)) {
foreach ($this->callbacks[$_priority] as $callback) {
if ($callback == $handler) {
return $this;
}
}
} else {
$this->callbacks[$_priority] = [];
}
if (\is_string($handler) || \is_callable($handler) || $handler instanceof \Closure) {
$this->callbacks[$_priority][] = $handler;
} else if (\is_array($handler)) {
if (\count($handler) == 2) {
if ((\is_string($handler[0]) // static call, ['Page', 'handleClick'] --> Page::handleClick()
|| \is_object($handler[0])) // method call, [$object, 'handleClick'] --> $object->handleClick()
&& (\is_string($handler[1]))
) {
$this->callbacks[$_priority][] = $handler;
} else { // error, unknown $handler type...
throw new UnknownEventHandlerTypeException("Unknown Event handler type.");
}
} else { // error, unknown $handler type...
throw new UnknownEventHandlerTypeException("Unknown Event handler type.");
}
} else { // error, unknown $handler type...
throw new UnknownEventHandlerTypeException("Unknown Event handler type.");
}
return $this;
} | [
"public",
"function",
"subscribe",
"(",
"$",
"handler",
",",
"$",
"priority",
"=",
"Event",
"::",
"DEFAULT_CALLBACKS_PRIORITY",
")",
"{",
"$",
"_priority",
"=",
"\\",
"is_int",
"(",
"$",
"priority",
")",
"?",
"$",
"priority",
":",
"self",
"::",
"DEFAULT_CALLBACKS_PRIORITY",
";",
"if",
"(",
"!",
"(",
"$",
"_priority",
">=",
"self",
"::",
"DEFAULT_CALLBACKS_MAX_PRIORITY",
"&&",
"$",
"_priority",
"<=",
"self",
"::",
"DEFAULT_CALLBACKS_MIN_PRIORITY",
")",
")",
"{",
"$",
"_priority",
"=",
"self",
"::",
"DEFAULT_CALLBACKS_PRIORITY",
";",
"}",
"if",
"(",
"\\",
"array_key_exists",
"(",
"$",
"_priority",
",",
"$",
"this",
"->",
"callbacks",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"callbacks",
"[",
"$",
"_priority",
"]",
"as",
"$",
"callback",
")",
"{",
"if",
"(",
"$",
"callback",
"==",
"$",
"handler",
")",
"{",
"return",
"$",
"this",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"callbacks",
"[",
"$",
"_priority",
"]",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"handler",
")",
"||",
"\\",
"is_callable",
"(",
"$",
"handler",
")",
"||",
"$",
"handler",
"instanceof",
"\\",
"Closure",
")",
"{",
"$",
"this",
"->",
"callbacks",
"[",
"$",
"_priority",
"]",
"[",
"]",
"=",
"$",
"handler",
";",
"}",
"else",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"handler",
")",
")",
"{",
"if",
"(",
"\\",
"count",
"(",
"$",
"handler",
")",
"==",
"2",
")",
"{",
"if",
"(",
"(",
"\\",
"is_string",
"(",
"$",
"handler",
"[",
"0",
"]",
")",
"// static call, ['Page', 'handleClick'] --> Page::handleClick()\r",
"||",
"\\",
"is_object",
"(",
"$",
"handler",
"[",
"0",
"]",
")",
")",
"// method call, [$object, 'handleClick'] --> $object->handleClick()\r",
"&&",
"(",
"\\",
"is_string",
"(",
"$",
"handler",
"[",
"1",
"]",
")",
")",
")",
"{",
"$",
"this",
"->",
"callbacks",
"[",
"$",
"_priority",
"]",
"[",
"]",
"=",
"$",
"handler",
";",
"}",
"else",
"{",
"// error, unknown $handler type...\r",
"throw",
"new",
"UnknownEventHandlerTypeException",
"(",
"\"Unknown Event handler type.\"",
")",
";",
"}",
"}",
"else",
"{",
"// error, unknown $handler type...\r",
"throw",
"new",
"UnknownEventHandlerTypeException",
"(",
"\"Unknown Event handler type.\"",
")",
";",
"}",
"}",
"else",
"{",
"// error, unknown $handler type...\r",
"throw",
"new",
"UnknownEventHandlerTypeException",
"(",
"\"Unknown Event handler type.\"",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Subscribe to this event.
The event handler must be a valid PHP callback. The following are
some examples:
~~~
function ($event) { ... } // anonymous function
[$object, 'handleClick'] // $object->handleClick()
['Page', 'handleClick'] // Page::handleClick()
'handleClick' // global function handleClick()
~~~
The event handler must be defined with the following signature,
~~~
function ($event)
~~~
where `$event` is an [[Event]] object which includes parameters associated with the event.
@param callable|\Closure|array|string $handler the event handler
@param int $priority
@return EventInterface
@see publish()
@see unsubscribe() | [
"Subscribe",
"to",
"this",
"event",
"."
] | 760bffd226c67ea3b9d898f0c6d76fb209ade72f | https://github.com/zeageorge/php-object/blob/760bffd226c67ea3b9d898f0c6d76fb209ade72f/src/Object/Event.php#L145-L181 | train |
Weblab-nl/curl | src/Request.php | Request.setPostFields | public function setPostFields($value) {
if (is_array($value)) {
return $this->setOption(CURLOPT_POSTFIELDS, http_build_query($value));
} else {
return $this->setOption(CURLOPT_POSTFIELDS, $value);
}
} | php | public function setPostFields($value) {
if (is_array($value)) {
return $this->setOption(CURLOPT_POSTFIELDS, http_build_query($value));
} else {
return $this->setOption(CURLOPT_POSTFIELDS, $value);
}
} | [
"public",
"function",
"setPostFields",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"this",
"->",
"setOption",
"(",
"CURLOPT_POSTFIELDS",
",",
"http_build_query",
"(",
"$",
"value",
")",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"setOption",
"(",
"CURLOPT_POSTFIELDS",
",",
"$",
"value",
")",
";",
"}",
"}"
] | Set post fields
@param array|string $value Array should be in key => value format. String === json
@return Request | [
"Set",
"post",
"fields"
] | e2879ab970e0d8161d5a49b46805bc36a8ba94a9 | https://github.com/Weblab-nl/curl/blob/e2879ab970e0d8161d5a49b46805bc36a8ba94a9/src/Request.php#L78-L84 | train |
Weblab-nl/curl | src/Request.php | Request.doesFileExist | public function doesFileExist($url) {
// Setup connection
$ch = curl_init($url);
// We don't want to download the file, we just want to know if the file exists
curl_setopt($ch, CURLOPT_NOBODY, true);
// Execute cURL
curl_exec($ch);
// Get the HTTP status code
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Close the connection
curl_close($ch);
// If status 200 the file exists, so return true in that case, otherwise false
return $httpCode == 200;
} | php | public function doesFileExist($url) {
// Setup connection
$ch = curl_init($url);
// We don't want to download the file, we just want to know if the file exists
curl_setopt($ch, CURLOPT_NOBODY, true);
// Execute cURL
curl_exec($ch);
// Get the HTTP status code
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Close the connection
curl_close($ch);
// If status 200 the file exists, so return true in that case, otherwise false
return $httpCode == 200;
} | [
"public",
"function",
"doesFileExist",
"(",
"$",
"url",
")",
"{",
"// Setup connection",
"$",
"ch",
"=",
"curl_init",
"(",
"$",
"url",
")",
";",
"// We don't want to download the file, we just want to know if the file exists",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_NOBODY",
",",
"true",
")",
";",
"// Execute cURL",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"// Get the HTTP status code",
"$",
"httpCode",
"=",
"curl_getinfo",
"(",
"$",
"ch",
",",
"CURLINFO_HTTP_CODE",
")",
";",
"// Close the connection",
"curl_close",
"(",
"$",
"ch",
")",
";",
"// If status 200 the file exists, so return true in that case, otherwise false",
"return",
"$",
"httpCode",
"==",
"200",
";",
"}"
] | Checks if a file exists
@return bool | [
"Checks",
"if",
"a",
"file",
"exists"
] | e2879ab970e0d8161d5a49b46805bc36a8ba94a9 | https://github.com/Weblab-nl/curl/blob/e2879ab970e0d8161d5a49b46805bc36a8ba94a9/src/Request.php#L273-L291 | train |
Weblab-nl/curl | src/Request.php | Request.getStatus | public function getStatus(string $url) {
// Setup connection
$resource = curl_init($url);
// Setup cURL options
curl_setopt($resource, CURLOPT_NOBODY, true);
curl_setopt($resource, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($resource,CURLOPT_HEADER,true);
curl_setopt($resource,CURLOPT_RETURNTRANSFER,true);
curl_setopt($resource, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($resource, CURLOPT_MAXREDIRS, 10);
curl_setopt($resource,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; rv:65.0) Gecko/20100101 Firefox/65.0');
curl_setopt($resource, CURLOPT_HTTPGET, true);
curl_setopt($resource, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($resource, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($resource, CURLOPT_SSL_VERIFYPEER, 0);
// Execute cURL
curl_exec($resource);
// Get the HTTP status code
$httpCode = curl_getinfo($resource, CURLINFO_HTTP_CODE);
// Close the connection
curl_close($resource);
// Return the status
return $httpCode;
} | php | public function getStatus(string $url) {
// Setup connection
$resource = curl_init($url);
// Setup cURL options
curl_setopt($resource, CURLOPT_NOBODY, true);
curl_setopt($resource, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($resource,CURLOPT_HEADER,true);
curl_setopt($resource,CURLOPT_RETURNTRANSFER,true);
curl_setopt($resource, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($resource, CURLOPT_MAXREDIRS, 10);
curl_setopt($resource,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; rv:65.0) Gecko/20100101 Firefox/65.0');
curl_setopt($resource, CURLOPT_HTTPGET, true);
curl_setopt($resource, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($resource, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($resource, CURLOPT_SSL_VERIFYPEER, 0);
// Execute cURL
curl_exec($resource);
// Get the HTTP status code
$httpCode = curl_getinfo($resource, CURLINFO_HTTP_CODE);
// Close the connection
curl_close($resource);
// Return the status
return $httpCode;
} | [
"public",
"function",
"getStatus",
"(",
"string",
"$",
"url",
")",
"{",
"// Setup connection",
"$",
"resource",
"=",
"curl_init",
"(",
"$",
"url",
")",
";",
"// Setup cURL options",
"curl_setopt",
"(",
"$",
"resource",
",",
"CURLOPT_NOBODY",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"resource",
",",
"CURLOPT_CONNECTTIMEOUT",
",",
"10",
")",
";",
"curl_setopt",
"(",
"$",
"resource",
",",
"CURLOPT_HEADER",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"resource",
",",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"resource",
",",
"CURLOPT_FOLLOWLOCATION",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"resource",
",",
"CURLOPT_MAXREDIRS",
",",
"10",
")",
";",
"curl_setopt",
"(",
"$",
"resource",
",",
"CURLOPT_USERAGENT",
",",
"'Mozilla/5.0 (Windows NT 6.1; rv:65.0) Gecko/20100101 Firefox/65.0'",
")",
";",
"curl_setopt",
"(",
"$",
"resource",
",",
"CURLOPT_HTTPGET",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"resource",
",",
"CURLOPT_CUSTOMREQUEST",
",",
"'GET'",
")",
";",
"curl_setopt",
"(",
"$",
"resource",
",",
"CURLOPT_SSL_VERIFYHOST",
",",
"0",
")",
";",
"curl_setopt",
"(",
"$",
"resource",
",",
"CURLOPT_SSL_VERIFYPEER",
",",
"0",
")",
";",
"// Execute cURL",
"curl_exec",
"(",
"$",
"resource",
")",
";",
"// Get the HTTP status code",
"$",
"httpCode",
"=",
"curl_getinfo",
"(",
"$",
"resource",
",",
"CURLINFO_HTTP_CODE",
")",
";",
"// Close the connection",
"curl_close",
"(",
"$",
"resource",
")",
";",
"// Return the status",
"return",
"$",
"httpCode",
";",
"}"
] | Get the response code of a url
@return bool | [
"Get",
"the",
"response",
"code",
"of",
"a",
"url"
] | e2879ab970e0d8161d5a49b46805bc36a8ba94a9 | https://github.com/Weblab-nl/curl/blob/e2879ab970e0d8161d5a49b46805bc36a8ba94a9/src/Request.php#L298-L327 | train |
Weblab-nl/curl | src/Request.php | Request.run | public function run() {
// Setup connection
$resource = curl_init();
// Set cURL options
foreach ($this->settings as $option => $setting) {
curl_setopt($resource, $option, $setting);
}
// Process headers
$headers = [];
foreach ($this->headers as $key => $value) {
if (!empty($value)) {
$headers[] = implode(' : ', [$key, $value]);
}
else {
$this->headers[] = $key;
}
}
// Add the headers
curl_setopt($resource, CURLOPT_HTTPHEADER, $headers);
// Execute cURL
$response = curl_exec($resource);
// Get the size of the header
$header_size = curl_getinfo($resource, CURLINFO_HEADER_SIZE);
// Get the header from the result
$headers = substr($response, 0, $header_size);
// Get the body from the result
$body = substr($response, $header_size);
// Get the HTTP response code from the result
$responseCode = curl_getinfo($resource, CURLINFO_HTTP_CODE);
// Close the connection
curl_close($resource);
// Create Result instance
$this->result = new Result($body, $responseCode, $headers);
return $this->result;
} | php | public function run() {
// Setup connection
$resource = curl_init();
// Set cURL options
foreach ($this->settings as $option => $setting) {
curl_setopt($resource, $option, $setting);
}
// Process headers
$headers = [];
foreach ($this->headers as $key => $value) {
if (!empty($value)) {
$headers[] = implode(' : ', [$key, $value]);
}
else {
$this->headers[] = $key;
}
}
// Add the headers
curl_setopt($resource, CURLOPT_HTTPHEADER, $headers);
// Execute cURL
$response = curl_exec($resource);
// Get the size of the header
$header_size = curl_getinfo($resource, CURLINFO_HEADER_SIZE);
// Get the header from the result
$headers = substr($response, 0, $header_size);
// Get the body from the result
$body = substr($response, $header_size);
// Get the HTTP response code from the result
$responseCode = curl_getinfo($resource, CURLINFO_HTTP_CODE);
// Close the connection
curl_close($resource);
// Create Result instance
$this->result = new Result($body, $responseCode, $headers);
return $this->result;
} | [
"public",
"function",
"run",
"(",
")",
"{",
"// Setup connection",
"$",
"resource",
"=",
"curl_init",
"(",
")",
";",
"// Set cURL options",
"foreach",
"(",
"$",
"this",
"->",
"settings",
"as",
"$",
"option",
"=>",
"$",
"setting",
")",
"{",
"curl_setopt",
"(",
"$",
"resource",
",",
"$",
"option",
",",
"$",
"setting",
")",
";",
"}",
"// Process headers",
"$",
"headers",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"headers",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"implode",
"(",
"' : '",
",",
"[",
"$",
"key",
",",
"$",
"value",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"headers",
"[",
"]",
"=",
"$",
"key",
";",
"}",
"}",
"// Add the headers",
"curl_setopt",
"(",
"$",
"resource",
",",
"CURLOPT_HTTPHEADER",
",",
"$",
"headers",
")",
";",
"// Execute cURL",
"$",
"response",
"=",
"curl_exec",
"(",
"$",
"resource",
")",
";",
"// Get the size of the header",
"$",
"header_size",
"=",
"curl_getinfo",
"(",
"$",
"resource",
",",
"CURLINFO_HEADER_SIZE",
")",
";",
"// Get the header from the result",
"$",
"headers",
"=",
"substr",
"(",
"$",
"response",
",",
"0",
",",
"$",
"header_size",
")",
";",
"// Get the body from the result",
"$",
"body",
"=",
"substr",
"(",
"$",
"response",
",",
"$",
"header_size",
")",
";",
"// Get the HTTP response code from the result",
"$",
"responseCode",
"=",
"curl_getinfo",
"(",
"$",
"resource",
",",
"CURLINFO_HTTP_CODE",
")",
";",
"// Close the connection",
"curl_close",
"(",
"$",
"resource",
")",
";",
"// Create Result instance",
"$",
"this",
"->",
"result",
"=",
"new",
"Result",
"(",
"$",
"body",
",",
"$",
"responseCode",
",",
"$",
"headers",
")",
";",
"return",
"$",
"this",
"->",
"result",
";",
"}"
] | Actually executes the cURL request
@return Result | [
"Actually",
"executes",
"the",
"cURL",
"request"
] | e2879ab970e0d8161d5a49b46805bc36a8ba94a9 | https://github.com/Weblab-nl/curl/blob/e2879ab970e0d8161d5a49b46805bc36a8ba94a9/src/Request.php#L334-L379 | train |
werx/core | src/Database.php | Database.init | public static function init($config = null)
{
$defaults = [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'mysql',
'username' => 'root',
'password' => null,
'log_queries' => true,
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => null
];
$capsule = new Capsule;
if (is_string($config)) {
$config = self::parseDsn($config);
}
if (is_array($config)) {
// missing 'driver' key, so it must be an array of arrays
if (!array_key_exists('driver', $config)) {
// if we have an array of connections, iterate through them.
// Cnnections should be stored in the form of name => conn_info
foreach ($config as $connection_name => $connection_info) {
// if it's a dsn string, then parse it
if (is_string($connection_info)) {
$connection_info = self::parseDsn($connection_info);
}
// now merge it into our options
$options[$connection_name] = array_merge($defaults, $connection_info);
}
} else {
$options['default'] = array_merge($defaults, $config);
}
} else {
$options['default'] = $defaults;
}
// add each connection, then set as global and boot
foreach ($options as $name => $info) {
$capsule->addConnection($info, $name);
self::$driver[$name] = $info['driver'];
}
$capsule->setAsGlobal();
$capsule->bootEloquent();
// determine if we should log queries or not
foreach ($options as $name => $info) {
// make sure we use FALSE to disable queries, otherwise it'll just default to logging queries
if (isset($info['log_queries']) && $info['log_queries'] === false) {
Capsule::connection($name)->disableQueryLog();
} else {
Capsule::connection($name)->enableQueryLog();
}
}
} | php | public static function init($config = null)
{
$defaults = [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'mysql',
'username' => 'root',
'password' => null,
'log_queries' => true,
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => null
];
$capsule = new Capsule;
if (is_string($config)) {
$config = self::parseDsn($config);
}
if (is_array($config)) {
// missing 'driver' key, so it must be an array of arrays
if (!array_key_exists('driver', $config)) {
// if we have an array of connections, iterate through them.
// Cnnections should be stored in the form of name => conn_info
foreach ($config as $connection_name => $connection_info) {
// if it's a dsn string, then parse it
if (is_string($connection_info)) {
$connection_info = self::parseDsn($connection_info);
}
// now merge it into our options
$options[$connection_name] = array_merge($defaults, $connection_info);
}
} else {
$options['default'] = array_merge($defaults, $config);
}
} else {
$options['default'] = $defaults;
}
// add each connection, then set as global and boot
foreach ($options as $name => $info) {
$capsule->addConnection($info, $name);
self::$driver[$name] = $info['driver'];
}
$capsule->setAsGlobal();
$capsule->bootEloquent();
// determine if we should log queries or not
foreach ($options as $name => $info) {
// make sure we use FALSE to disable queries, otherwise it'll just default to logging queries
if (isset($info['log_queries']) && $info['log_queries'] === false) {
Capsule::connection($name)->disableQueryLog();
} else {
Capsule::connection($name)->enableQueryLog();
}
}
} | [
"public",
"static",
"function",
"init",
"(",
"$",
"config",
"=",
"null",
")",
"{",
"$",
"defaults",
"=",
"[",
"'driver'",
"=>",
"'mysql'",
",",
"'host'",
"=>",
"'localhost'",
",",
"'database'",
"=>",
"'mysql'",
",",
"'username'",
"=>",
"'root'",
",",
"'password'",
"=>",
"null",
",",
"'log_queries'",
"=>",
"true",
",",
"'charset'",
"=>",
"'utf8'",
",",
"'collation'",
"=>",
"'utf8_unicode_ci'",
",",
"'prefix'",
"=>",
"null",
"]",
";",
"$",
"capsule",
"=",
"new",
"Capsule",
";",
"if",
"(",
"is_string",
"(",
"$",
"config",
")",
")",
"{",
"$",
"config",
"=",
"self",
"::",
"parseDsn",
"(",
"$",
"config",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"config",
")",
")",
"{",
"// missing 'driver' key, so it must be an array of arrays",
"if",
"(",
"!",
"array_key_exists",
"(",
"'driver'",
",",
"$",
"config",
")",
")",
"{",
"// if we have an array of connections, iterate through them.",
"// Cnnections should be stored in the form of name => conn_info",
"foreach",
"(",
"$",
"config",
"as",
"$",
"connection_name",
"=>",
"$",
"connection_info",
")",
"{",
"// if it's a dsn string, then parse it",
"if",
"(",
"is_string",
"(",
"$",
"connection_info",
")",
")",
"{",
"$",
"connection_info",
"=",
"self",
"::",
"parseDsn",
"(",
"$",
"connection_info",
")",
";",
"}",
"// now merge it into our options",
"$",
"options",
"[",
"$",
"connection_name",
"]",
"=",
"array_merge",
"(",
"$",
"defaults",
",",
"$",
"connection_info",
")",
";",
"}",
"}",
"else",
"{",
"$",
"options",
"[",
"'default'",
"]",
"=",
"array_merge",
"(",
"$",
"defaults",
",",
"$",
"config",
")",
";",
"}",
"}",
"else",
"{",
"$",
"options",
"[",
"'default'",
"]",
"=",
"$",
"defaults",
";",
"}",
"// add each connection, then set as global and boot",
"foreach",
"(",
"$",
"options",
"as",
"$",
"name",
"=>",
"$",
"info",
")",
"{",
"$",
"capsule",
"->",
"addConnection",
"(",
"$",
"info",
",",
"$",
"name",
")",
";",
"self",
"::",
"$",
"driver",
"[",
"$",
"name",
"]",
"=",
"$",
"info",
"[",
"'driver'",
"]",
";",
"}",
"$",
"capsule",
"->",
"setAsGlobal",
"(",
")",
";",
"$",
"capsule",
"->",
"bootEloquent",
"(",
")",
";",
"// determine if we should log queries or not",
"foreach",
"(",
"$",
"options",
"as",
"$",
"name",
"=>",
"$",
"info",
")",
"{",
"// make sure we use FALSE to disable queries, otherwise it'll just default to logging queries",
"if",
"(",
"isset",
"(",
"$",
"info",
"[",
"'log_queries'",
"]",
")",
"&&",
"$",
"info",
"[",
"'log_queries'",
"]",
"===",
"false",
")",
"{",
"Capsule",
"::",
"connection",
"(",
"$",
"name",
")",
"->",
"disableQueryLog",
"(",
")",
";",
"}",
"else",
"{",
"Capsule",
"::",
"connection",
"(",
"$",
"name",
")",
"->",
"enableQueryLog",
"(",
")",
";",
"}",
"}",
"}"
] | Initialize the connection to the database.
@param null $config | [
"Initialize",
"the",
"connection",
"to",
"the",
"database",
"."
] | 9ab7a9f7a8c02e1d41ca40301afada8129ea0a79 | https://github.com/werx/core/blob/9ab7a9f7a8c02e1d41ca40301afada8129ea0a79/src/Database.php#L18-L77 | train |
werx/core | src/Database.php | Database.parseDsn | public static function parseDsn($string = null)
{
$opts = null;
if (!empty($string)) {
$dsn = new DSN($string);
$port = empty($dsn->getFirstPort()) ? '' : (':' . $dsn->getFirstPort());
$password = empty($dsn->getPassword()) ? null : $dsn->getPassword();
$opts = [
'driver' => $dsn->getProtocol(),
'host' => $dsn->getFirstHost() . $port,
'database' => $dsn->getDatabase(),
'username' => $dsn->getUsername(),
'password' => $password
];
}
return $opts;
} | php | public static function parseDsn($string = null)
{
$opts = null;
if (!empty($string)) {
$dsn = new DSN($string);
$port = empty($dsn->getFirstPort()) ? '' : (':' . $dsn->getFirstPort());
$password = empty($dsn->getPassword()) ? null : $dsn->getPassword();
$opts = [
'driver' => $dsn->getProtocol(),
'host' => $dsn->getFirstHost() . $port,
'database' => $dsn->getDatabase(),
'username' => $dsn->getUsername(),
'password' => $password
];
}
return $opts;
} | [
"public",
"static",
"function",
"parseDsn",
"(",
"$",
"string",
"=",
"null",
")",
"{",
"$",
"opts",
"=",
"null",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"string",
")",
")",
"{",
"$",
"dsn",
"=",
"new",
"DSN",
"(",
"$",
"string",
")",
";",
"$",
"port",
"=",
"empty",
"(",
"$",
"dsn",
"->",
"getFirstPort",
"(",
")",
")",
"?",
"''",
":",
"(",
"':'",
".",
"$",
"dsn",
"->",
"getFirstPort",
"(",
")",
")",
";",
"$",
"password",
"=",
"empty",
"(",
"$",
"dsn",
"->",
"getPassword",
"(",
")",
")",
"?",
"null",
":",
"$",
"dsn",
"->",
"getPassword",
"(",
")",
";",
"$",
"opts",
"=",
"[",
"'driver'",
"=>",
"$",
"dsn",
"->",
"getProtocol",
"(",
")",
",",
"'host'",
"=>",
"$",
"dsn",
"->",
"getFirstHost",
"(",
")",
".",
"$",
"port",
",",
"'database'",
"=>",
"$",
"dsn",
"->",
"getDatabase",
"(",
")",
",",
"'username'",
"=>",
"$",
"dsn",
"->",
"getUsername",
"(",
")",
",",
"'password'",
"=>",
"$",
"password",
"]",
";",
"}",
"return",
"$",
"opts",
";",
"}"
] | Take a string DSN and parse it into an array of its pieces
@param null $string
@return array|null | [
"Take",
"a",
"string",
"DSN",
"and",
"parse",
"it",
"into",
"an",
"array",
"of",
"its",
"pieces"
] | 9ab7a9f7a8c02e1d41ca40301afada8129ea0a79 | https://github.com/werx/core/blob/9ab7a9f7a8c02e1d41ca40301afada8129ea0a79/src/Database.php#L100-L120 | train |
wb-crowdfusion/crowdfusion | system/core/classes/nodedb/events/AbstractBulkCountsHandler.php | AbstractBulkCountsHandler.commit | public function commit() {
if(empty($this->NodeCounts)) {
$this->Logger->debug(__FUNCTION__ .'-> No nodes to change counts on.');
return;
}
foreach($this->NodeCounts as $nodeRefUrl => $count) {
$nodeRef = $this->NodeRefService->parseFromString($nodeRefUrl);
// incrementMeta can handle negative values, so no need to call decrementMeta here
if($count != 0) {
$this->Logger->debug(__FUNCTION__ ."-> Updating ".$this->getMetaID()." by {$count} for: $nodeRefUrl");
$this->NodeService->incrementMeta($nodeRef, $this->getMetaID(), $count);
}
else
$this->Logger->debug(__FUNCTION__ ."-> No update of ".$this->getMetaID()." for: $nodeRefUrl");
}
$this->NodeCounts = array();
} | php | public function commit() {
if(empty($this->NodeCounts)) {
$this->Logger->debug(__FUNCTION__ .'-> No nodes to change counts on.');
return;
}
foreach($this->NodeCounts as $nodeRefUrl => $count) {
$nodeRef = $this->NodeRefService->parseFromString($nodeRefUrl);
// incrementMeta can handle negative values, so no need to call decrementMeta here
if($count != 0) {
$this->Logger->debug(__FUNCTION__ ."-> Updating ".$this->getMetaID()." by {$count} for: $nodeRefUrl");
$this->NodeService->incrementMeta($nodeRef, $this->getMetaID(), $count);
}
else
$this->Logger->debug(__FUNCTION__ ."-> No update of ".$this->getMetaID()." for: $nodeRefUrl");
}
$this->NodeCounts = array();
} | [
"public",
"function",
"commit",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"NodeCounts",
")",
")",
"{",
"$",
"this",
"->",
"Logger",
"->",
"debug",
"(",
"__FUNCTION__",
".",
"'-> No nodes to change counts on.'",
")",
";",
"return",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"NodeCounts",
"as",
"$",
"nodeRefUrl",
"=>",
"$",
"count",
")",
"{",
"$",
"nodeRef",
"=",
"$",
"this",
"->",
"NodeRefService",
"->",
"parseFromString",
"(",
"$",
"nodeRefUrl",
")",
";",
"// incrementMeta can handle negative values, so no need to call decrementMeta here",
"if",
"(",
"$",
"count",
"!=",
"0",
")",
"{",
"$",
"this",
"->",
"Logger",
"->",
"debug",
"(",
"__FUNCTION__",
".",
"\"-> Updating \"",
".",
"$",
"this",
"->",
"getMetaID",
"(",
")",
".",
"\" by {$count} for: $nodeRefUrl\"",
")",
";",
"$",
"this",
"->",
"NodeService",
"->",
"incrementMeta",
"(",
"$",
"nodeRef",
",",
"$",
"this",
"->",
"getMetaID",
"(",
")",
",",
"$",
"count",
")",
";",
"}",
"else",
"$",
"this",
"->",
"Logger",
"->",
"debug",
"(",
"__FUNCTION__",
".",
"\"-> No update of \"",
".",
"$",
"this",
"->",
"getMetaID",
"(",
")",
".",
"\" for: $nodeRefUrl\"",
")",
";",
"}",
"$",
"this",
"->",
"NodeCounts",
"=",
"array",
"(",
")",
";",
"}"
] | Update all meta on nodes queued
@return void | [
"Update",
"all",
"meta",
"on",
"nodes",
"queued"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/nodedb/events/AbstractBulkCountsHandler.php#L34-L53 | train |
wb-crowdfusion/crowdfusion | system/core/classes/nodedb/events/AbstractBulkCountsHandler.php | AbstractBulkCountsHandler.increment | public function increment(NodeRef $nodeRef, NodeRef $extNodeRef, $tag)
{
$nodeRefUrl = $nodeRef->getRefURL();
if(!isset($this->NodeCounts[$nodeRefUrl]))
$this->NodeCounts[$nodeRefUrl] = 0;
$this->NodeCounts[$nodeRefUrl]++;
$this->Logger->debug(__FUNCTION__ ."-> Increment ".$this->getMetaID()." for: $nodeRefUrl");
} | php | public function increment(NodeRef $nodeRef, NodeRef $extNodeRef, $tag)
{
$nodeRefUrl = $nodeRef->getRefURL();
if(!isset($this->NodeCounts[$nodeRefUrl]))
$this->NodeCounts[$nodeRefUrl] = 0;
$this->NodeCounts[$nodeRefUrl]++;
$this->Logger->debug(__FUNCTION__ ."-> Increment ".$this->getMetaID()." for: $nodeRefUrl");
} | [
"public",
"function",
"increment",
"(",
"NodeRef",
"$",
"nodeRef",
",",
"NodeRef",
"$",
"extNodeRef",
",",
"$",
"tag",
")",
"{",
"$",
"nodeRefUrl",
"=",
"$",
"nodeRef",
"->",
"getRefURL",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"NodeCounts",
"[",
"$",
"nodeRefUrl",
"]",
")",
")",
"$",
"this",
"->",
"NodeCounts",
"[",
"$",
"nodeRefUrl",
"]",
"=",
"0",
";",
"$",
"this",
"->",
"NodeCounts",
"[",
"$",
"nodeRefUrl",
"]",
"++",
";",
"$",
"this",
"->",
"Logger",
"->",
"debug",
"(",
"__FUNCTION__",
".",
"\"-> Increment \"",
".",
"$",
"this",
"->",
"getMetaID",
"(",
")",
".",
"\" for: $nodeRefUrl\"",
")",
";",
"}"
] | Queue a node to have its meta incremented
@param NodeRef $nodeRef
@param NodeRef $extNodeRef
@param $tag | [
"Queue",
"a",
"node",
"to",
"have",
"its",
"meta",
"incremented"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/nodedb/events/AbstractBulkCountsHandler.php#L62-L71 | train |
arrounded/core | src/Composers/AbstractComposer.php | AbstractComposer.getWebpackAssets | protected function getWebpackAssets()
{
$assets = public_path('builds/manifest.json');
$assets = file_get_contents($assets);
$assets = json_decode($assets, true);
return $assets;
} | php | protected function getWebpackAssets()
{
$assets = public_path('builds/manifest.json');
$assets = file_get_contents($assets);
$assets = json_decode($assets, true);
return $assets;
} | [
"protected",
"function",
"getWebpackAssets",
"(",
")",
"{",
"$",
"assets",
"=",
"public_path",
"(",
"'builds/manifest.json'",
")",
";",
"$",
"assets",
"=",
"file_get_contents",
"(",
"$",
"assets",
")",
";",
"$",
"assets",
"=",
"json_decode",
"(",
"$",
"assets",
",",
"true",
")",
";",
"return",
"$",
"assets",
";",
"}"
] | Get the manifest of assets compiled by Webpack.
@return array | [
"Get",
"the",
"manifest",
"of",
"assets",
"compiled",
"by",
"Webpack",
"."
] | 9573d9ae63f5173bdfd51077ce065e9e8c176ac4 | https://github.com/arrounded/core/blob/9573d9ae63f5173bdfd51077ce065e9e8c176ac4/src/Composers/AbstractComposer.php#L28-L35 | train |
arrounded/core | src/Composers/AbstractComposer.php | AbstractComposer.makeMenu | protected function makeMenu($menu)
{
$links = [];
foreach ($menu as $key => $item) {
// Rebuild from associative array
if (is_string($item)) {
$item = [$key, $item];
}
list($endpoint, $label) = $item;
$attributes = array_get($item, 4, []);
// Compute actual URL
$parameters = array_get($item, 2, []);
$link = $this->router->getRoutes()->getByName($endpoint)
? $this->url->route($endpoint, $parameters)
: $this->url->to($endpoint, $parameters);
// Compute active state
if ($link !== '#') {
$active = array_get($item, 3) ?: str_replace($this->request->root().'/', null, $link);
$active = $this->isOnPage($active);
} else {
$active = false;
}
$links[] = array_merge([
'endpoint' => $link,
'label' => $this->translate($label),
'active' => $active ? 'active' : false,
], $attributes);
}
return $links;
} | php | protected function makeMenu($menu)
{
$links = [];
foreach ($menu as $key => $item) {
// Rebuild from associative array
if (is_string($item)) {
$item = [$key, $item];
}
list($endpoint, $label) = $item;
$attributes = array_get($item, 4, []);
// Compute actual URL
$parameters = array_get($item, 2, []);
$link = $this->router->getRoutes()->getByName($endpoint)
? $this->url->route($endpoint, $parameters)
: $this->url->to($endpoint, $parameters);
// Compute active state
if ($link !== '#') {
$active = array_get($item, 3) ?: str_replace($this->request->root().'/', null, $link);
$active = $this->isOnPage($active);
} else {
$active = false;
}
$links[] = array_merge([
'endpoint' => $link,
'label' => $this->translate($label),
'active' => $active ? 'active' : false,
], $attributes);
}
return $links;
} | [
"protected",
"function",
"makeMenu",
"(",
"$",
"menu",
")",
"{",
"$",
"links",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"menu",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"// Rebuild from associative array",
"if",
"(",
"is_string",
"(",
"$",
"item",
")",
")",
"{",
"$",
"item",
"=",
"[",
"$",
"key",
",",
"$",
"item",
"]",
";",
"}",
"list",
"(",
"$",
"endpoint",
",",
"$",
"label",
")",
"=",
"$",
"item",
";",
"$",
"attributes",
"=",
"array_get",
"(",
"$",
"item",
",",
"4",
",",
"[",
"]",
")",
";",
"// Compute actual URL",
"$",
"parameters",
"=",
"array_get",
"(",
"$",
"item",
",",
"2",
",",
"[",
"]",
")",
";",
"$",
"link",
"=",
"$",
"this",
"->",
"router",
"->",
"getRoutes",
"(",
")",
"->",
"getByName",
"(",
"$",
"endpoint",
")",
"?",
"$",
"this",
"->",
"url",
"->",
"route",
"(",
"$",
"endpoint",
",",
"$",
"parameters",
")",
":",
"$",
"this",
"->",
"url",
"->",
"to",
"(",
"$",
"endpoint",
",",
"$",
"parameters",
")",
";",
"// Compute active state",
"if",
"(",
"$",
"link",
"!==",
"'#'",
")",
"{",
"$",
"active",
"=",
"array_get",
"(",
"$",
"item",
",",
"3",
")",
"?",
":",
"str_replace",
"(",
"$",
"this",
"->",
"request",
"->",
"root",
"(",
")",
".",
"'/'",
",",
"null",
",",
"$",
"link",
")",
";",
"$",
"active",
"=",
"$",
"this",
"->",
"isOnPage",
"(",
"$",
"active",
")",
";",
"}",
"else",
"{",
"$",
"active",
"=",
"false",
";",
"}",
"$",
"links",
"[",
"]",
"=",
"array_merge",
"(",
"[",
"'endpoint'",
"=>",
"$",
"link",
",",
"'label'",
"=>",
"$",
"this",
"->",
"translate",
"(",
"$",
"label",
")",
",",
"'active'",
"=>",
"$",
"active",
"?",
"'active'",
":",
"false",
",",
"]",
",",
"$",
"attributes",
")",
";",
"}",
"return",
"$",
"links",
";",
"}"
] | Make a menu from a list of links.
@param array $menu
@return array | [
"Make",
"a",
"menu",
"from",
"a",
"list",
"of",
"links",
"."
] | 9573d9ae63f5173bdfd51077ce065e9e8c176ac4 | https://github.com/arrounded/core/blob/9573d9ae63f5173bdfd51077ce065e9e8c176ac4/src/Composers/AbstractComposer.php#L44-L78 | train |
arrounded/core | src/Composers/AbstractComposer.php | AbstractComposer.isOnPage | protected function isOnPage($page, $loose = true)
{
$page = $loose ? $page : '^'.$page.'$';
$page = str_replace('#', '\#', $page);
return (bool) preg_match('#'.$page.'#', $this->request->path());
} | php | protected function isOnPage($page, $loose = true)
{
$page = $loose ? $page : '^'.$page.'$';
$page = str_replace('#', '\#', $page);
return (bool) preg_match('#'.$page.'#', $this->request->path());
} | [
"protected",
"function",
"isOnPage",
"(",
"$",
"page",
",",
"$",
"loose",
"=",
"true",
")",
"{",
"$",
"page",
"=",
"$",
"loose",
"?",
"$",
"page",
":",
"'^'",
".",
"$",
"page",
".",
"'$'",
";",
"$",
"page",
"=",
"str_replace",
"(",
"'#'",
",",
"'\\#'",
",",
"$",
"page",
")",
";",
"return",
"(",
"bool",
")",
"preg_match",
"(",
"'#'",
".",
"$",
"page",
".",
"'#'",
",",
"$",
"this",
"->",
"request",
"->",
"path",
"(",
")",
")",
";",
"}"
] | Check if a string matches the given url.
@param string $page
@param bool $loose
@return bool | [
"Check",
"if",
"a",
"string",
"matches",
"the",
"given",
"url",
"."
] | 9573d9ae63f5173bdfd51077ce065e9e8c176ac4 | https://github.com/arrounded/core/blob/9573d9ae63f5173bdfd51077ce065e9e8c176ac4/src/Composers/AbstractComposer.php#L88-L94 | train |
arrounded/core | src/Composers/AbstractComposer.php | AbstractComposer.translate | protected function translate($string)
{
$translated = $this->app['translator']->get($string);
return is_string($translated) ? $translated : $string;
} | php | protected function translate($string)
{
$translated = $this->app['translator']->get($string);
return is_string($translated) ? $translated : $string;
} | [
"protected",
"function",
"translate",
"(",
"$",
"string",
")",
"{",
"$",
"translated",
"=",
"$",
"this",
"->",
"app",
"[",
"'translator'",
"]",
"->",
"get",
"(",
"$",
"string",
")",
";",
"return",
"is_string",
"(",
"$",
"translated",
")",
"?",
"$",
"translated",
":",
"$",
"string",
";",
"}"
] | Act on a string to translate it.
@param string $string
@return string | [
"Act",
"on",
"a",
"string",
"to",
"translate",
"it",
"."
] | 9573d9ae63f5173bdfd51077ce065e9e8c176ac4 | https://github.com/arrounded/core/blob/9573d9ae63f5173bdfd51077ce065e9e8c176ac4/src/Composers/AbstractComposer.php#L103-L108 | train |
squareproton/Bond | src/Bond/Container/FindFilterComponentMulti.php | FindFilterComponentMulti.check | public function check( $obj )
{
foreach( $this->findFilterComponents as $findFilterComponent ) {
if( $findFilterComponent->check($obj) ) {
return true;
}
}
return false;
} | php | public function check( $obj )
{
foreach( $this->findFilterComponents as $findFilterComponent ) {
if( $findFilterComponent->check($obj) ) {
return true;
}
}
return false;
} | [
"public",
"function",
"check",
"(",
"$",
"obj",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"findFilterComponents",
"as",
"$",
"findFilterComponent",
")",
"{",
"if",
"(",
"$",
"findFilterComponent",
"->",
"check",
"(",
"$",
"obj",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Pass a entity through a filter. Does it match?
@param mixed $object we're going to filter on
@return bool | [
"Pass",
"a",
"entity",
"through",
"a",
"filter",
".",
"Does",
"it",
"match?"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Container/FindFilterComponentMulti.php#L56-L64 | train |
gplcart/cli | controllers/commands/Cache.php | Cache.cmdGetCache | public function cmdGetCache()
{
$id = $this->getParam(0);
if (empty($id)) {
$this->errorAndExit($this->text('Invalid command'));
}
$result = $this->cache->get($id);
if (!isset($result)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->outputFormat($result, 'json');
$this->output();
} | php | public function cmdGetCache()
{
$id = $this->getParam(0);
if (empty($id)) {
$this->errorAndExit($this->text('Invalid command'));
}
$result = $this->cache->get($id);
if (!isset($result)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->outputFormat($result, 'json');
$this->output();
} | [
"public",
"function",
"cmdGetCache",
"(",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"getParam",
"(",
"0",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid command'",
")",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"cache",
"->",
"get",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"result",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"$",
"this",
"->",
"outputFormat",
"(",
"$",
"result",
",",
"'json'",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "cache-get" command | [
"Callback",
"for",
"cache",
"-",
"get",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Cache.php#L40-L56 | train |
gplcart/cli | controllers/commands/Cache.php | Cache.cmdClearCache | public function cmdClearCache()
{
$id = $this->getParam(0);
$all = $this->getParam('all');
if (!isset($id) && empty($all)) {
$this->errorAndExit($this->text('Invalid command'));
}
$result = false;
if (isset($id)) {
$pattern = $this->getParam('pattern');
if (isset($pattern)) {
$result = $this->cache->clear($id, array('pattern' => $pattern));
} else {
$result = $this->cache->clear($id);
}
} else if ($all) {
$result = $this->cache->clear(null);
}
if (empty($result)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->output();
} | php | public function cmdClearCache()
{
$id = $this->getParam(0);
$all = $this->getParam('all');
if (!isset($id) && empty($all)) {
$this->errorAndExit($this->text('Invalid command'));
}
$result = false;
if (isset($id)) {
$pattern = $this->getParam('pattern');
if (isset($pattern)) {
$result = $this->cache->clear($id, array('pattern' => $pattern));
} else {
$result = $this->cache->clear($id);
}
} else if ($all) {
$result = $this->cache->clear(null);
}
if (empty($result)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->output();
} | [
"public",
"function",
"cmdClearCache",
"(",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"getParam",
"(",
"0",
")",
";",
"$",
"all",
"=",
"$",
"this",
"->",
"getParam",
"(",
"'all'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"id",
")",
"&&",
"empty",
"(",
"$",
"all",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid command'",
")",
")",
";",
"}",
"$",
"result",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"id",
")",
")",
"{",
"$",
"pattern",
"=",
"$",
"this",
"->",
"getParam",
"(",
"'pattern'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"pattern",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"cache",
"->",
"clear",
"(",
"$",
"id",
",",
"array",
"(",
"'pattern'",
"=>",
"$",
"pattern",
")",
")",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"cache",
"->",
"clear",
"(",
"$",
"id",
")",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"all",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"cache",
"->",
"clear",
"(",
"null",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "cache-clear" command | [
"Callback",
"for",
"cache",
"-",
"clear",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Cache.php#L61-L88 | train |
synaq/SynaqCurlBundle | Curl/Wrapper.php | Wrapper.setRequestOptions | private function setRequestOptions($url, $vars, $options = array())
{
curl_setopt($this->request, CURLOPT_URL, $url);
if (!empty($vars)) {
curl_setopt($this->request, CURLOPT_POSTFIELDS, $vars);
}
# Set some default CURL options
curl_setopt($this->request, CURLOPT_HEADER, true);
curl_setopt($this->request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->request, CURLOPT_USERAGENT, $this->userAgent);
curl_setopt($this->request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
if ($this->cookieFile) {
curl_setopt($this->request, CURLOPT_COOKIEFILE, $this->cookieFile);
curl_setopt($this->request, CURLOPT_COOKIEJAR, $this->cookieFile);
}
if ($this->followRedirects) {
curl_setopt($this->request, CURLOPT_FOLLOWLOCATION, true);
}
if ($this->referrer) {
curl_setopt($this->request, CURLOPT_REFERER, $this->referrer);
}
# Set any custom CURL options
foreach (array_merge($options, $this->options) as $option => $value) {
curl_setopt($this->request, constant('CURLOPT_' . str_replace('CURLOPT_', '', strtoupper($option))), $value);
}
} | php | private function setRequestOptions($url, $vars, $options = array())
{
curl_setopt($this->request, CURLOPT_URL, $url);
if (!empty($vars)) {
curl_setopt($this->request, CURLOPT_POSTFIELDS, $vars);
}
# Set some default CURL options
curl_setopt($this->request, CURLOPT_HEADER, true);
curl_setopt($this->request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->request, CURLOPT_USERAGENT, $this->userAgent);
curl_setopt($this->request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
if ($this->cookieFile) {
curl_setopt($this->request, CURLOPT_COOKIEFILE, $this->cookieFile);
curl_setopt($this->request, CURLOPT_COOKIEJAR, $this->cookieFile);
}
if ($this->followRedirects) {
curl_setopt($this->request, CURLOPT_FOLLOWLOCATION, true);
}
if ($this->referrer) {
curl_setopt($this->request, CURLOPT_REFERER, $this->referrer);
}
# Set any custom CURL options
foreach (array_merge($options, $this->options) as $option => $value) {
curl_setopt($this->request, constant('CURLOPT_' . str_replace('CURLOPT_', '', strtoupper($option))), $value);
}
} | [
"private",
"function",
"setRequestOptions",
"(",
"$",
"url",
",",
"$",
"vars",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"curl_setopt",
"(",
"$",
"this",
"->",
"request",
",",
"CURLOPT_URL",
",",
"$",
"url",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"vars",
")",
")",
"{",
"curl_setopt",
"(",
"$",
"this",
"->",
"request",
",",
"CURLOPT_POSTFIELDS",
",",
"$",
"vars",
")",
";",
"}",
"# Set some default CURL options",
"curl_setopt",
"(",
"$",
"this",
"->",
"request",
",",
"CURLOPT_HEADER",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"this",
"->",
"request",
",",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"this",
"->",
"request",
",",
"CURLOPT_USERAGENT",
",",
"$",
"this",
"->",
"userAgent",
")",
";",
"curl_setopt",
"(",
"$",
"this",
"->",
"request",
",",
"CURLOPT_HTTP_VERSION",
",",
"CURL_HTTP_VERSION_1_0",
")",
";",
"if",
"(",
"$",
"this",
"->",
"cookieFile",
")",
"{",
"curl_setopt",
"(",
"$",
"this",
"->",
"request",
",",
"CURLOPT_COOKIEFILE",
",",
"$",
"this",
"->",
"cookieFile",
")",
";",
"curl_setopt",
"(",
"$",
"this",
"->",
"request",
",",
"CURLOPT_COOKIEJAR",
",",
"$",
"this",
"->",
"cookieFile",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"followRedirects",
")",
"{",
"curl_setopt",
"(",
"$",
"this",
"->",
"request",
",",
"CURLOPT_FOLLOWLOCATION",
",",
"true",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"referrer",
")",
"{",
"curl_setopt",
"(",
"$",
"this",
"->",
"request",
",",
"CURLOPT_REFERER",
",",
"$",
"this",
"->",
"referrer",
")",
";",
"}",
"# Set any custom CURL options",
"foreach",
"(",
"array_merge",
"(",
"$",
"options",
",",
"$",
"this",
"->",
"options",
")",
"as",
"$",
"option",
"=>",
"$",
"value",
")",
"{",
"curl_setopt",
"(",
"$",
"this",
"->",
"request",
",",
"constant",
"(",
"'CURLOPT_'",
".",
"str_replace",
"(",
"'CURLOPT_'",
",",
"''",
",",
"strtoupper",
"(",
"$",
"option",
")",
")",
")",
",",
"$",
"value",
")",
";",
"}",
"}"
] | Sets the CURLOPT options for the current request
@param string $url
@param string $vars
@return void
@access protected | [
"Sets",
"the",
"CURLOPT",
"options",
"for",
"the",
"current",
"request"
] | 3bfb4ef7693ea621c31b9a32565a23c7d99f8a14 | https://github.com/synaq/SynaqCurlBundle/blob/3bfb4ef7693ea621c31b9a32565a23c7d99f8a14/Curl/Wrapper.php#L316-L343 | train |
synaq/SynaqCurlBundle | Curl/Wrapper.php | Wrapper.setRequestHeaders | private function setRequestHeaders($headers = array()) {
foreach ($this->headers as $key => $value) {
$headers[] = $key . ': ' . $value;
}
curl_setopt($this->request, CURLOPT_HTTPHEADER, $headers);
} | php | private function setRequestHeaders($headers = array()) {
foreach ($this->headers as $key => $value) {
$headers[] = $key . ': ' . $value;
}
curl_setopt($this->request, CURLOPT_HTTPHEADER, $headers);
} | [
"private",
"function",
"setRequestHeaders",
"(",
"$",
"headers",
"=",
"array",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"headers",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"$",
"key",
".",
"': '",
".",
"$",
"value",
";",
"}",
"curl_setopt",
"(",
"$",
"this",
"->",
"request",
",",
"CURLOPT_HTTPHEADER",
",",
"$",
"headers",
")",
";",
"}"
] | Formats and adds custom headers to the current request
@param array $headers
@return void
@access protected | [
"Formats",
"and",
"adds",
"custom",
"headers",
"to",
"the",
"current",
"request"
] | 3bfb4ef7693ea621c31b9a32565a23c7d99f8a14 | https://github.com/synaq/SynaqCurlBundle/blob/3bfb4ef7693ea621c31b9a32565a23c7d99f8a14/Curl/Wrapper.php#L352-L357 | train |
story75/Bonefish-Router | src/FastRoute.php | FastRoute.addRoutes | public function addRoutes(array $routes = [])
{
foreach($routes as $route)
{
if ($route instanceof RouteInterface) $this->routes[] = $route;
}
} | php | public function addRoutes(array $routes = [])
{
foreach($routes as $route)
{
if ($route instanceof RouteInterface) $this->routes[] = $route;
}
} | [
"public",
"function",
"addRoutes",
"(",
"array",
"$",
"routes",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"routes",
"as",
"$",
"route",
")",
"{",
"if",
"(",
"$",
"route",
"instanceof",
"RouteInterface",
")",
"$",
"this",
"->",
"routes",
"[",
"]",
"=",
"$",
"route",
";",
"}",
"}"
] | Add all routes which are available
@param RouteInterface[] $routes
@return void | [
"Add",
"all",
"routes",
"which",
"are",
"available"
] | bb16960c9442303ceeb0c9d14b14be62018de05d | https://github.com/story75/Bonefish-Router/blob/bb16960c9442303ceeb0c9d14b14be62018de05d/src/FastRoute.php#L69-L75 | train |
story75/Bonefish-Router | src/FastRoute.php | FastRoute.dispatch | public function dispatch(Request $request)
{
if (ltrim($_SERVER['REQUEST_URI'], '/') === '') {
return new DispatcherResult(200, $this->defaultHandler);
}
$dispatcher = $this->getDispatcher();
$match = $dispatcher->dispatch($request->getMethod(), $_SERVER['REQUEST_URI']);
$code = null;
$handler = null;
switch ($match[0]) {
case Dispatcher::NOT_FOUND:
$code = 404;
$handler = $this->errorHandlers[$code];
break;
case Dispatcher::METHOD_NOT_ALLOWED:
$code = 405;
$handler = $this->errorHandlers[$code];
$handler->setSuppliedParameters(['allowedMethods' => $match[1]]);
break;
case Dispatcher::FOUND:
$code = 200;
/** @var RouteCallbackDTOInterface $handler */
$handler = $match[1];
$handler->setSuppliedParameters($match[2]);
break;
}
if ($code !== null) {
return new DispatcherResult($code, $handler);
}
return new DispatcherResult(200, $this->defaultHandler);
} | php | public function dispatch(Request $request)
{
if (ltrim($_SERVER['REQUEST_URI'], '/') === '') {
return new DispatcherResult(200, $this->defaultHandler);
}
$dispatcher = $this->getDispatcher();
$match = $dispatcher->dispatch($request->getMethod(), $_SERVER['REQUEST_URI']);
$code = null;
$handler = null;
switch ($match[0]) {
case Dispatcher::NOT_FOUND:
$code = 404;
$handler = $this->errorHandlers[$code];
break;
case Dispatcher::METHOD_NOT_ALLOWED:
$code = 405;
$handler = $this->errorHandlers[$code];
$handler->setSuppliedParameters(['allowedMethods' => $match[1]]);
break;
case Dispatcher::FOUND:
$code = 200;
/** @var RouteCallbackDTOInterface $handler */
$handler = $match[1];
$handler->setSuppliedParameters($match[2]);
break;
}
if ($code !== null) {
return new DispatcherResult($code, $handler);
}
return new DispatcherResult(200, $this->defaultHandler);
} | [
"public",
"function",
"dispatch",
"(",
"Request",
"$",
"request",
")",
"{",
"if",
"(",
"ltrim",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
",",
"'/'",
")",
"===",
"''",
")",
"{",
"return",
"new",
"DispatcherResult",
"(",
"200",
",",
"$",
"this",
"->",
"defaultHandler",
")",
";",
"}",
"$",
"dispatcher",
"=",
"$",
"this",
"->",
"getDispatcher",
"(",
")",
";",
"$",
"match",
"=",
"$",
"dispatcher",
"->",
"dispatch",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
",",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
")",
";",
"$",
"code",
"=",
"null",
";",
"$",
"handler",
"=",
"null",
";",
"switch",
"(",
"$",
"match",
"[",
"0",
"]",
")",
"{",
"case",
"Dispatcher",
"::",
"NOT_FOUND",
":",
"$",
"code",
"=",
"404",
";",
"$",
"handler",
"=",
"$",
"this",
"->",
"errorHandlers",
"[",
"$",
"code",
"]",
";",
"break",
";",
"case",
"Dispatcher",
"::",
"METHOD_NOT_ALLOWED",
":",
"$",
"code",
"=",
"405",
";",
"$",
"handler",
"=",
"$",
"this",
"->",
"errorHandlers",
"[",
"$",
"code",
"]",
";",
"$",
"handler",
"->",
"setSuppliedParameters",
"(",
"[",
"'allowedMethods'",
"=>",
"$",
"match",
"[",
"1",
"]",
"]",
")",
";",
"break",
";",
"case",
"Dispatcher",
"::",
"FOUND",
":",
"$",
"code",
"=",
"200",
";",
"/** @var RouteCallbackDTOInterface $handler */",
"$",
"handler",
"=",
"$",
"match",
"[",
"1",
"]",
";",
"$",
"handler",
"->",
"setSuppliedParameters",
"(",
"$",
"match",
"[",
"2",
"]",
")",
";",
"break",
";",
"}",
"if",
"(",
"$",
"code",
"!==",
"null",
")",
"{",
"return",
"new",
"DispatcherResult",
"(",
"$",
"code",
",",
"$",
"handler",
")",
";",
"}",
"return",
"new",
"DispatcherResult",
"(",
"200",
",",
"$",
"this",
"->",
"defaultHandler",
")",
";",
"}"
] | Once called the router should examine the current request by request method and url
and find a matching route. If no route was find dispatch a http error instead.
Dispatch means in this context that the router will use the RouteCallbackDTO in the Route
and call the controller with the correct action and pass the parameters.
@param Request $request
@return DispatcherResultInterface | [
"Once",
"called",
"the",
"router",
"should",
"examine",
"the",
"current",
"request",
"by",
"request",
"method",
"and",
"url",
"and",
"find",
"a",
"matching",
"route",
".",
"If",
"no",
"route",
"was",
"find",
"dispatch",
"a",
"http",
"error",
"instead",
"."
] | bb16960c9442303ceeb0c9d14b14be62018de05d | https://github.com/story75/Bonefish-Router/blob/bb16960c9442303ceeb0c9d14b14be62018de05d/src/FastRoute.php#L110-L146 | train |
netlogix/Netlogix.Crud | Classes/Netlogix/Crud/Utility/ArrayUtility.php | ArrayUtility.flatten | static public function flatten(array $array, $prefix = '', $keepEmptyArrayNode = TRUE, $segmentationCharacter = self::SEGMENTATION_CHARACTER) {
$flatArray = array();
foreach ($array as $key => $value) {
// Ensure there is no trailling dot:
$key = rtrim($key, $segmentationCharacter);
if (!is_array($value) || (count($value) === 0 && $keepEmptyArrayNode)) {
$flatArray[$prefix . $key] = $value;
} else {
$flatArray = array_merge($flatArray, self::flatten($value, $prefix . $key . $segmentationCharacter, $keepEmptyArrayNode));
}
}
return $flatArray;
} | php | static public function flatten(array $array, $prefix = '', $keepEmptyArrayNode = TRUE, $segmentationCharacter = self::SEGMENTATION_CHARACTER) {
$flatArray = array();
foreach ($array as $key => $value) {
// Ensure there is no trailling dot:
$key = rtrim($key, $segmentationCharacter);
if (!is_array($value) || (count($value) === 0 && $keepEmptyArrayNode)) {
$flatArray[$prefix . $key] = $value;
} else {
$flatArray = array_merge($flatArray, self::flatten($value, $prefix . $key . $segmentationCharacter, $keepEmptyArrayNode));
}
}
return $flatArray;
} | [
"static",
"public",
"function",
"flatten",
"(",
"array",
"$",
"array",
",",
"$",
"prefix",
"=",
"''",
",",
"$",
"keepEmptyArrayNode",
"=",
"TRUE",
",",
"$",
"segmentationCharacter",
"=",
"self",
"::",
"SEGMENTATION_CHARACTER",
")",
"{",
"$",
"flatArray",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"// Ensure there is no trailling dot:",
"$",
"key",
"=",
"rtrim",
"(",
"$",
"key",
",",
"$",
"segmentationCharacter",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
"||",
"(",
"count",
"(",
"$",
"value",
")",
"===",
"0",
"&&",
"$",
"keepEmptyArrayNode",
")",
")",
"{",
"$",
"flatArray",
"[",
"$",
"prefix",
".",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"flatArray",
"=",
"array_merge",
"(",
"$",
"flatArray",
",",
"self",
"::",
"flatten",
"(",
"$",
"value",
",",
"$",
"prefix",
".",
"$",
"key",
".",
"$",
"segmentationCharacter",
",",
"$",
"keepEmptyArrayNode",
")",
")",
";",
"}",
"}",
"return",
"$",
"flatArray",
";",
"}"
] | Converts a multidimensional array to a flat representation.
See unit tests for more details
Example:
- array:
array(
'first.' => array(
'second' => 1
)
)
- result:
array(
'first.second' => 1
)
Example:
- array:
array(
'first' => array(
'second' => 1
)
)
- result:
array(
'first.second' => 1
)
@param array $array The (relative) array to be converted
@param string $prefix The (relative) prefix to be used (e.g. 'section.')
@return array | [
"Converts",
"a",
"multidimensional",
"array",
"to",
"a",
"flat",
"representation",
"."
] | 61438827ba6b0a7a63cd2f08a294967ed5928144 | https://github.com/netlogix/Netlogix.Crud/blob/61438827ba6b0a7a63cd2f08a294967ed5928144/Classes/Netlogix/Crud/Utility/ArrayUtility.php#L61-L73 | train |
Saritasa/php-eloquent-custom | src/Entity.php | Entity.getAttributeValue | public function getAttributeValue($key)
{
$value = $this->getAttributeFromArray($key);
// check if it's a enum
if (isset($this->enums[$key]) && is_scalar($value)) {
$enumClass = $this->enums[$key];
return new $enumClass($value);
}
return parent::getAttributeValue($key);
} | php | public function getAttributeValue($key)
{
$value = $this->getAttributeFromArray($key);
// check if it's a enum
if (isset($this->enums[$key]) && is_scalar($value)) {
$enumClass = $this->enums[$key];
return new $enumClass($value);
}
return parent::getAttributeValue($key);
} | [
"public",
"function",
"getAttributeValue",
"(",
"$",
"key",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"getAttributeFromArray",
"(",
"$",
"key",
")",
";",
"// check if it's a enum",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"enums",
"[",
"$",
"key",
"]",
")",
"&&",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"$",
"enumClass",
"=",
"$",
"this",
"->",
"enums",
"[",
"$",
"key",
"]",
";",
"return",
"new",
"$",
"enumClass",
"(",
"$",
"value",
")",
";",
"}",
"return",
"parent",
"::",
"getAttributeValue",
"(",
"$",
"key",
")",
";",
"}"
] | Gets the value of attribute,
taking enums typecast into consideration
@param string $key Name of attribute
@return mixed | [
"Gets",
"the",
"value",
"of",
"attribute",
"taking",
"enums",
"typecast",
"into",
"consideration"
] | 54a2479f1d6e9cddac14dd8e473ab6a99dc6a82a | https://github.com/Saritasa/php-eloquent-custom/blob/54a2479f1d6e9cddac14dd8e473ab6a99dc6a82a/src/Entity.php#L41-L50 | train |
Saritasa/php-eloquent-custom | src/Entity.php | Entity.setAttribute | public function setAttribute($key, $value)
{
// check if it's a enum
if (isset($this->enums[$key]) && is_scalar($value)) {
$enumClass = $this->enums[$key];
$this->attributes[$key] = new $enumClass($value);
} else {
parent::setAttribute($key, $value);
}
return $this;
} | php | public function setAttribute($key, $value)
{
// check if it's a enum
if (isset($this->enums[$key]) && is_scalar($value)) {
$enumClass = $this->enums[$key];
$this->attributes[$key] = new $enumClass($value);
} else {
parent::setAttribute($key, $value);
}
return $this;
} | [
"public",
"function",
"setAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"// check if it's a enum",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"enums",
"[",
"$",
"key",
"]",
")",
"&&",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"$",
"enumClass",
"=",
"$",
"this",
"->",
"enums",
"[",
"$",
"key",
"]",
";",
"$",
"this",
"->",
"attributes",
"[",
"$",
"key",
"]",
"=",
"new",
"$",
"enumClass",
"(",
"$",
"value",
")",
";",
"}",
"else",
"{",
"parent",
"::",
"setAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets the value of attribute,
taking enums typecast into consideration
@param string $key Name of the attribute
@param mixed $value Value of the attribute to set
@return $this | [
"Sets",
"the",
"value",
"of",
"attribute",
"taking",
"enums",
"typecast",
"into",
"consideration"
] | 54a2479f1d6e9cddac14dd8e473ab6a99dc6a82a | https://github.com/Saritasa/php-eloquent-custom/blob/54a2479f1d6e9cddac14dd8e473ab6a99dc6a82a/src/Entity.php#L60-L70 | train |
Saritasa/php-eloquent-custom | src/Entity.php | Entity.getEnumValidationRule | protected static function getEnumValidationRule(string $enumClass) : array
{
if (!is_a($enumClass, Enum::class, true)) {
throw new \UnexpectedValueException('Class is not enum');
}
return array_merge(['in'], $enumClass::getConstants());
} | php | protected static function getEnumValidationRule(string $enumClass) : array
{
if (!is_a($enumClass, Enum::class, true)) {
throw new \UnexpectedValueException('Class is not enum');
}
return array_merge(['in'], $enumClass::getConstants());
} | [
"protected",
"static",
"function",
"getEnumValidationRule",
"(",
"string",
"$",
"enumClass",
")",
":",
"array",
"{",
"if",
"(",
"!",
"is_a",
"(",
"$",
"enumClass",
",",
"Enum",
"::",
"class",
",",
"true",
")",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"'Class is not enum'",
")",
";",
"}",
"return",
"array_merge",
"(",
"[",
"'in'",
"]",
",",
"$",
"enumClass",
"::",
"getConstants",
"(",
")",
")",
";",
"}"
] | Gets validation rule for given enum class
@deprecated Should use Rule::enum($enumClass)
@param string $enumClass Enum class name
@return array | [
"Gets",
"validation",
"rule",
"for",
"given",
"enum",
"class"
] | 54a2479f1d6e9cddac14dd8e473ab6a99dc6a82a | https://github.com/Saritasa/php-eloquent-custom/blob/54a2479f1d6e9cddac14dd8e473ab6a99dc6a82a/src/Entity.php#L80-L87 | train |
stubbles/stubbles-dbal | src/main/php/DatabaseConnections.php | DatabaseConnections.get | public function get(string $name = null): DatabaseConnection
{
if (null == $name) {
$name = DatabaseConfiguration::DEFAULT_ID;
}
if (isset($this->connections[$name])) {
return $this->connections[$name];
}
$this->connections[$name] = new PdoDatabaseConnection(
$this->configurations->get($name)
);
return $this->connections[$name];
} | php | public function get(string $name = null): DatabaseConnection
{
if (null == $name) {
$name = DatabaseConfiguration::DEFAULT_ID;
}
if (isset($this->connections[$name])) {
return $this->connections[$name];
}
$this->connections[$name] = new PdoDatabaseConnection(
$this->configurations->get($name)
);
return $this->connections[$name];
} | [
"public",
"function",
"get",
"(",
"string",
"$",
"name",
"=",
"null",
")",
":",
"DatabaseConnection",
"{",
"if",
"(",
"null",
"==",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"DatabaseConfiguration",
"::",
"DEFAULT_ID",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"connections",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"connections",
"[",
"$",
"name",
"]",
";",
"}",
"$",
"this",
"->",
"connections",
"[",
"$",
"name",
"]",
"=",
"new",
"PdoDatabaseConnection",
"(",
"$",
"this",
"->",
"configurations",
"->",
"get",
"(",
"$",
"name",
")",
")",
";",
"return",
"$",
"this",
"->",
"connections",
"[",
"$",
"name",
"]",
";",
"}"
] | returns the connection
If a name is provided and a connection with this name exists this
connection will be returned. If fallback is enabled and the named
connection does not exist the default connection will be returned, if
fallback is disabled a DatabaseException will be thrown.
If no name is provided the default connection will be returned.
@param string $name
@return \stubbles\db\DatabaseConnection | [
"returns",
"the",
"connection"
] | b42a589025a9e511b40a2798ac84df94d6451c36 | https://github.com/stubbles/stubbles-dbal/blob/b42a589025a9e511b40a2798ac84df94d6451c36/src/main/php/DatabaseConnections.php#L58-L72 | train |
geniv/nette-identity-authorizator | src/Drivers/ArrayDriver.php | ArrayDriver.init | protected function init()
{
if ($this->policy != self::POLICY_NONE) {
// set role
foreach ($this->_role as $role) {
$this->role[$role] = ['id' => $role, 'role' => $role];
$this->permission->addRole($role);
}
// set resource
foreach ($this->_resource as $resource) {
$this->resource[$resource] = ['id' => $resource, 'resource' => $resource];
$this->permission->addResource($resource);
}
// set privilege
foreach ($this->_privilege as $privilege) {
$this->privilege[$privilege] = ['id' => $privilege, 'privilege' => $privilege];
}
// for deny enable all
if ($this->policy == self::POLICY_DENY) {
$this->permission->allow();
}
// set acl
foreach ($this->_acl as $role => $resources) {
if (is_array($resources)) {
foreach ($resources as $resource => $privilege) {
// fill acl array
foreach ($privilege as $item) {
// strict define keys!
$this->acl[] = [
'id_role' => $role, 'role' => $role,
'id_resource' => $resource, 'resource' => $resource,
'id_privilege' => $item, 'privilege' => $item,
];
}
// automatic remove acl if not exist role in role array (remove all acl by role)
if (!isset($this->role[$role])) {
$this->saveAcl($role, []);
continue;
}
// automatic remove acl resource if resource not exist in resource array (remove acl resource by role)
if (!isset($this->resource[$resource])) {
unset($this->_acl[$role][$resource]);
$this->saveAcl($role, $this->_acl[$role]);
continue;
}
// convert acl all to permission all
if (in_array('all', $privilege)) {
$privilege = self::ALL;
}
$this->setAllowed($role, $resource, $privilege);
}
} else {
//vse
if ($resources == 'all') {
// automatic remove acl if not exist role in role array (remove all acl by role)
if (!isset($this->role[$role])) {
$this->saveAcl($role, []);
} else {
$this->acl[] = [
'id_role' => $role, 'role' => $role,
'id_resource' => null, 'resource' => null,
'id_privilege' => null, 'privilege' => null,
];
$this->setAllowed($role);
}
}
}
}
}
} | php | protected function init()
{
if ($this->policy != self::POLICY_NONE) {
// set role
foreach ($this->_role as $role) {
$this->role[$role] = ['id' => $role, 'role' => $role];
$this->permission->addRole($role);
}
// set resource
foreach ($this->_resource as $resource) {
$this->resource[$resource] = ['id' => $resource, 'resource' => $resource];
$this->permission->addResource($resource);
}
// set privilege
foreach ($this->_privilege as $privilege) {
$this->privilege[$privilege] = ['id' => $privilege, 'privilege' => $privilege];
}
// for deny enable all
if ($this->policy == self::POLICY_DENY) {
$this->permission->allow();
}
// set acl
foreach ($this->_acl as $role => $resources) {
if (is_array($resources)) {
foreach ($resources as $resource => $privilege) {
// fill acl array
foreach ($privilege as $item) {
// strict define keys!
$this->acl[] = [
'id_role' => $role, 'role' => $role,
'id_resource' => $resource, 'resource' => $resource,
'id_privilege' => $item, 'privilege' => $item,
];
}
// automatic remove acl if not exist role in role array (remove all acl by role)
if (!isset($this->role[$role])) {
$this->saveAcl($role, []);
continue;
}
// automatic remove acl resource if resource not exist in resource array (remove acl resource by role)
if (!isset($this->resource[$resource])) {
unset($this->_acl[$role][$resource]);
$this->saveAcl($role, $this->_acl[$role]);
continue;
}
// convert acl all to permission all
if (in_array('all', $privilege)) {
$privilege = self::ALL;
}
$this->setAllowed($role, $resource, $privilege);
}
} else {
//vse
if ($resources == 'all') {
// automatic remove acl if not exist role in role array (remove all acl by role)
if (!isset($this->role[$role])) {
$this->saveAcl($role, []);
} else {
$this->acl[] = [
'id_role' => $role, 'role' => $role,
'id_resource' => null, 'resource' => null,
'id_privilege' => null, 'privilege' => null,
];
$this->setAllowed($role);
}
}
}
}
}
} | [
"protected",
"function",
"init",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"policy",
"!=",
"self",
"::",
"POLICY_NONE",
")",
"{",
"// set role",
"foreach",
"(",
"$",
"this",
"->",
"_role",
"as",
"$",
"role",
")",
"{",
"$",
"this",
"->",
"role",
"[",
"$",
"role",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"role",
",",
"'role'",
"=>",
"$",
"role",
"]",
";",
"$",
"this",
"->",
"permission",
"->",
"addRole",
"(",
"$",
"role",
")",
";",
"}",
"// set resource",
"foreach",
"(",
"$",
"this",
"->",
"_resource",
"as",
"$",
"resource",
")",
"{",
"$",
"this",
"->",
"resource",
"[",
"$",
"resource",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"resource",
",",
"'resource'",
"=>",
"$",
"resource",
"]",
";",
"$",
"this",
"->",
"permission",
"->",
"addResource",
"(",
"$",
"resource",
")",
";",
"}",
"// set privilege",
"foreach",
"(",
"$",
"this",
"->",
"_privilege",
"as",
"$",
"privilege",
")",
"{",
"$",
"this",
"->",
"privilege",
"[",
"$",
"privilege",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"privilege",
",",
"'privilege'",
"=>",
"$",
"privilege",
"]",
";",
"}",
"// for deny enable all",
"if",
"(",
"$",
"this",
"->",
"policy",
"==",
"self",
"::",
"POLICY_DENY",
")",
"{",
"$",
"this",
"->",
"permission",
"->",
"allow",
"(",
")",
";",
"}",
"// set acl",
"foreach",
"(",
"$",
"this",
"->",
"_acl",
"as",
"$",
"role",
"=>",
"$",
"resources",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"resources",
")",
")",
"{",
"foreach",
"(",
"$",
"resources",
"as",
"$",
"resource",
"=>",
"$",
"privilege",
")",
"{",
"// fill acl array",
"foreach",
"(",
"$",
"privilege",
"as",
"$",
"item",
")",
"{",
"// strict define keys!",
"$",
"this",
"->",
"acl",
"[",
"]",
"=",
"[",
"'id_role'",
"=>",
"$",
"role",
",",
"'role'",
"=>",
"$",
"role",
",",
"'id_resource'",
"=>",
"$",
"resource",
",",
"'resource'",
"=>",
"$",
"resource",
",",
"'id_privilege'",
"=>",
"$",
"item",
",",
"'privilege'",
"=>",
"$",
"item",
",",
"]",
";",
"}",
"// automatic remove acl if not exist role in role array (remove all acl by role)",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"role",
"[",
"$",
"role",
"]",
")",
")",
"{",
"$",
"this",
"->",
"saveAcl",
"(",
"$",
"role",
",",
"[",
"]",
")",
";",
"continue",
";",
"}",
"// automatic remove acl resource if resource not exist in resource array (remove acl resource by role)",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"resource",
"[",
"$",
"resource",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"_acl",
"[",
"$",
"role",
"]",
"[",
"$",
"resource",
"]",
")",
";",
"$",
"this",
"->",
"saveAcl",
"(",
"$",
"role",
",",
"$",
"this",
"->",
"_acl",
"[",
"$",
"role",
"]",
")",
";",
"continue",
";",
"}",
"// convert acl all to permission all",
"if",
"(",
"in_array",
"(",
"'all'",
",",
"$",
"privilege",
")",
")",
"{",
"$",
"privilege",
"=",
"self",
"::",
"ALL",
";",
"}",
"$",
"this",
"->",
"setAllowed",
"(",
"$",
"role",
",",
"$",
"resource",
",",
"$",
"privilege",
")",
";",
"}",
"}",
"else",
"{",
"//vse",
"if",
"(",
"$",
"resources",
"==",
"'all'",
")",
"{",
"// automatic remove acl if not exist role in role array (remove all acl by role)",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"role",
"[",
"$",
"role",
"]",
")",
")",
"{",
"$",
"this",
"->",
"saveAcl",
"(",
"$",
"role",
",",
"[",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"acl",
"[",
"]",
"=",
"[",
"'id_role'",
"=>",
"$",
"role",
",",
"'role'",
"=>",
"$",
"role",
",",
"'id_resource'",
"=>",
"null",
",",
"'resource'",
"=>",
"null",
",",
"'id_privilege'",
"=>",
"null",
",",
"'privilege'",
"=>",
"null",
",",
"]",
";",
"$",
"this",
"->",
"setAllowed",
"(",
"$",
"role",
")",
";",
"}",
"}",
"}",
"}",
"}",
"}"
] | Init data. | [
"Init",
"data",
"."
] | f7db1cd589d022b6443f24a59432098a343d4639 | https://github.com/geniv/nette-identity-authorizator/blob/f7db1cd589d022b6443f24a59432098a343d4639/src/Drivers/ArrayDriver.php#L44-L124 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.