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/Binding.php | Binding.getTarget | public function getTarget()
{
if($this->to === NULL && $this->options | self::TYPE_IMPLEMENTATION)
{
return $this->typeName;
}
return $this->to;
} | php | public function getTarget()
{
if($this->to === NULL && $this->options | self::TYPE_IMPLEMENTATION)
{
return $this->typeName;
}
return $this->to;
} | [
"public",
"function",
"getTarget",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"to",
"===",
"NULL",
"&&",
"$",
"this",
"->",
"options",
"|",
"self",
"::",
"TYPE_IMPLEMENTATION",
")",
"{",
"return",
"$",
"this",
"->",
"typeName",
";",
"}",
"return",
"$",
"this",
"->",
"to",
";",
"}"
] | Get the target of this binding, eighter a string or a closure.
@return mixed | [
"Get",
"the",
"target",
"of",
"this",
"binding",
"eighter",
"a",
"string",
"or",
"a",
"closure",
"."
] | f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36 | https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/Bind/Binding.php#L108-L116 | train |
koolkode/context | src/Bind/Binding.php | Binding.getMarkers | public function getMarkers($marker = NULL)
{
if($marker !== NULL && $this->markers !== NULL)
{
$result = [];
foreach($this->markers as $check)
{
if($check instanceof $marker)
{
$result[] = $check;
}
}
return $result;
}
return (array)$this->markers;
} | php | public function getMarkers($marker = NULL)
{
if($marker !== NULL && $this->markers !== NULL)
{
$result = [];
foreach($this->markers as $check)
{
if($check instanceof $marker)
{
$result[] = $check;
}
}
return $result;
}
return (array)$this->markers;
} | [
"public",
"function",
"getMarkers",
"(",
"$",
"marker",
"=",
"NULL",
")",
"{",
"if",
"(",
"$",
"marker",
"!==",
"NULL",
"&&",
"$",
"this",
"->",
"markers",
"!==",
"NULL",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"markers",
"as",
"$",
"check",
")",
"{",
"if",
"(",
"$",
"check",
"instanceof",
"$",
"marker",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"check",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}",
"return",
"(",
"array",
")",
"$",
"this",
"->",
"markers",
";",
"}"
] | Get all markers being set for this binding.
@param string $marker The type of marker to be considerd.
@return array<Marker> | [
"Get",
"all",
"markers",
"being",
"set",
"for",
"this",
"binding",
"."
] | f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36 | https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/Bind/Binding.php#L124-L142 | train |
koolkode/context | src/Bind/Binding.php | Binding.toAlias | public function toAlias($typeName)
{
$this->options = self::TYPE_ALIAS;
$this->to = (string)$typeName;
return $this;
} | php | public function toAlias($typeName)
{
$this->options = self::TYPE_ALIAS;
$this->to = (string)$typeName;
return $this;
} | [
"public",
"function",
"toAlias",
"(",
"$",
"typeName",
")",
"{",
"$",
"this",
"->",
"options",
"=",
"self",
"::",
"TYPE_ALIAS",
";",
"$",
"this",
"->",
"to",
"=",
"(",
"string",
")",
"$",
"typeName",
";",
"return",
"$",
"this",
";",
"}"
] | Bind to another binding specified by name.
@param string $typeName
@return Binding | [
"Bind",
"to",
"another",
"binding",
"specified",
"by",
"name",
"."
] | f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36 | https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/Bind/Binding.php#L195-L201 | train |
koolkode/context | src/Bind/Binding.php | Binding.scoped | public function scoped(Scope $scope)
{
if($scope instanceof Dependent)
{
$this->scope = NULL;
}
else
{
$this->scope = get_class($scope);
}
return $this;
} | php | public function scoped(Scope $scope)
{
if($scope instanceof Dependent)
{
$this->scope = NULL;
}
else
{
$this->scope = get_class($scope);
}
return $this;
} | [
"public",
"function",
"scoped",
"(",
"Scope",
"$",
"scope",
")",
"{",
"if",
"(",
"$",
"scope",
"instanceof",
"Dependent",
")",
"{",
"$",
"this",
"->",
"scope",
"=",
"NULL",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"scope",
"=",
"get_class",
"(",
"$",
"scope",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set the scope of the binding according to the binary value of the scope.
@param Scope $scope
@return Binding | [
"Set",
"the",
"scope",
"of",
"the",
"binding",
"according",
"to",
"the",
"binary",
"value",
"of",
"the",
"scope",
"."
] | f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36 | https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/Bind/Binding.php#L209-L221 | train |
koolkode/context | src/Bind/Binding.php | Binding.isMarked | public function isMarked($marker)
{
if(empty($this->markers))
{
return false;
}
if($marker instanceof \ReflectionClass)
{
foreach($this->markers as $check)
{
if($marker->isInstance($check))
{
return true;
}
}
}
elseif($marker instanceof Marker)
{
foreach($this->markers as $check)
{
if($marker->isInstance($check))
{
return true;
}
}
}
else
{
foreach($this->markers as $check)
{
if($check instanceof $marker)
{
return true;
}
}
}
return false;
} | php | public function isMarked($marker)
{
if(empty($this->markers))
{
return false;
}
if($marker instanceof \ReflectionClass)
{
foreach($this->markers as $check)
{
if($marker->isInstance($check))
{
return true;
}
}
}
elseif($marker instanceof Marker)
{
foreach($this->markers as $check)
{
if($marker->isInstance($check))
{
return true;
}
}
}
else
{
foreach($this->markers as $check)
{
if($check instanceof $marker)
{
return true;
}
}
}
return false;
} | [
"public",
"function",
"isMarked",
"(",
"$",
"marker",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"markers",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"marker",
"instanceof",
"\\",
"ReflectionClass",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"markers",
"as",
"$",
"check",
")",
"{",
"if",
"(",
"$",
"marker",
"->",
"isInstance",
"(",
"$",
"check",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"elseif",
"(",
"$",
"marker",
"instanceof",
"Marker",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"markers",
"as",
"$",
"check",
")",
"{",
"if",
"(",
"$",
"marker",
"->",
"isInstance",
"(",
"$",
"check",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"else",
"{",
"foreach",
"(",
"$",
"this",
"->",
"markers",
"as",
"$",
"check",
")",
"{",
"if",
"(",
"$",
"check",
"instanceof",
"$",
"marker",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Check if the binding has a marker of the given type.
@param mixed $marker Marker instance, reflection class or fully-qualified name of the marker.
@return boolean | [
"Check",
"if",
"the",
"binding",
"has",
"a",
"marker",
"of",
"the",
"given",
"type",
"."
] | f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36 | https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/Bind/Binding.php#L242-L281 | train |
koolkode/context | src/Bind/Binding.php | Binding.decorate | public function decorate(\Closure $decorator, $priority = 0)
{
$this->decorators->insert($decorator, $priority);
return $this;
} | php | public function decorate(\Closure $decorator, $priority = 0)
{
$this->decorators->insert($decorator, $priority);
return $this;
} | [
"public",
"function",
"decorate",
"(",
"\\",
"Closure",
"$",
"decorator",
",",
"$",
"priority",
"=",
"0",
")",
"{",
"$",
"this",
"->",
"decorators",
"->",
"insert",
"(",
"$",
"decorator",
",",
"$",
"priority",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Register a decorator with this binding.
Decorators are custom initializers (created object instance as first argument + any number of additional
params reslved by DI are supported) that must return the decorator object instance.
@param \Closure $decorator
@param integer $priority
@return Binding | [
"Register",
"a",
"decorator",
"with",
"this",
"binding",
"."
] | f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36 | https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/Bind/Binding.php#L360-L365 | train |
koolkode/context | src/Bind/Binding.php | Binding.getInitializers | public function getInitializers()
{
$initializers = $this->initializers;
foreach(clone $this->decorators as $decorator)
{
$initializers[] = $decorator;
}
return $initializers;
} | php | public function getInitializers()
{
$initializers = $this->initializers;
foreach(clone $this->decorators as $decorator)
{
$initializers[] = $decorator;
}
return $initializers;
} | [
"public",
"function",
"getInitializers",
"(",
")",
"{",
"$",
"initializers",
"=",
"$",
"this",
"->",
"initializers",
";",
"foreach",
"(",
"clone",
"$",
"this",
"->",
"decorators",
"as",
"$",
"decorator",
")",
"{",
"$",
"initializers",
"[",
"]",
"=",
"$",
"decorator",
";",
"}",
"return",
"$",
"initializers",
";",
"}"
] | Get all custom initializers of this binding.
@return array<\Closure> | [
"Get",
"all",
"custom",
"initializers",
"of",
"this",
"binding",
"."
] | f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36 | https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/Bind/Binding.php#L372-L382 | train |
phpffcms/ffcms-core | src/Helper/Environment.php | Environment.loadAverage | public static function loadAverage()
{
$load = 0;
if (stristr(PHP_OS, 'win')) {
// its not a better solution, but no other way to do this
$cmd = "wmic cpu get loadpercentage /all";
@exec($cmd, $output);
// if output is exist
if ($output) {
// try to find line with numeric data
foreach ($output as $line) {
if ($line && preg_match("/^[0-9]+\$/", $line)) {
$load = $line;
break;
}
}
}
} else {
$sys_load = sys_getloadavg(); // get linux load average (1 = 100% of 1 CPU)
$load = $sys_load[0] * 100; // to percentage
}
if ((int)$load <= 0) {
return 'error';
}
return (int)$load . '%';
} | php | public static function loadAverage()
{
$load = 0;
if (stristr(PHP_OS, 'win')) {
// its not a better solution, but no other way to do this
$cmd = "wmic cpu get loadpercentage /all";
@exec($cmd, $output);
// if output is exist
if ($output) {
// try to find line with numeric data
foreach ($output as $line) {
if ($line && preg_match("/^[0-9]+\$/", $line)) {
$load = $line;
break;
}
}
}
} else {
$sys_load = sys_getloadavg(); // get linux load average (1 = 100% of 1 CPU)
$load = $sys_load[0] * 100; // to percentage
}
if ((int)$load <= 0) {
return 'error';
}
return (int)$load . '%';
} | [
"public",
"static",
"function",
"loadAverage",
"(",
")",
"{",
"$",
"load",
"=",
"0",
";",
"if",
"(",
"stristr",
"(",
"PHP_OS",
",",
"'win'",
")",
")",
"{",
"// its not a better solution, but no other way to do this",
"$",
"cmd",
"=",
"\"wmic cpu get loadpercentage /all\"",
";",
"@",
"exec",
"(",
"$",
"cmd",
",",
"$",
"output",
")",
";",
"// if output is exist",
"if",
"(",
"$",
"output",
")",
"{",
"// try to find line with numeric data",
"foreach",
"(",
"$",
"output",
"as",
"$",
"line",
")",
"{",
"if",
"(",
"$",
"line",
"&&",
"preg_match",
"(",
"\"/^[0-9]+\\$/\"",
",",
"$",
"line",
")",
")",
"{",
"$",
"load",
"=",
"$",
"line",
";",
"break",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"$",
"sys_load",
"=",
"sys_getloadavg",
"(",
")",
";",
"// get linux load average (1 = 100% of 1 CPU)",
"$",
"load",
"=",
"$",
"sys_load",
"[",
"0",
"]",
"*",
"100",
";",
"// to percentage",
"}",
"if",
"(",
"(",
"int",
")",
"$",
"load",
"<=",
"0",
")",
"{",
"return",
"'error'",
";",
"}",
"return",
"(",
"int",
")",
"$",
"load",
".",
"'%'",
";",
"}"
] | Get load average in percents.
@return string | [
"Get",
"load",
"average",
"in",
"percents",
"."
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Helper/Environment.php#L42-L70 | train |
t3v/t3v_core | Classes/Domain/Model/Traits/FileReferenceTrait.php | FileReferenceTrait.getLocalizedFileReference | protected function getLocalizedFileReference(string $table, string $field) {
if ($this->getSysLanguageUid() > 0) {
$localizedFileReferences = $this->getLocalizedFileReferences($table, $field);
if (!empty($localizedFileReferences)) {
$localizedFileObject = $localizedFileReferences[0]->toArray();
if ($localizedFileObject) {
$pid = intval($localizedFileObject['pid']);
$uid = intval($localizedFileObject['uid']);
$fileReference = new FileReference();
$fileReference->pid = $pid;
$fileReference->uid = $uid;
$fileReference->_languageUid = 0;
$fileReference->_localizedUid = $uid;
$fileReference->_versionedUid = $uid;
return $fileReference;
}
}
}
return null;
} | php | protected function getLocalizedFileReference(string $table, string $field) {
if ($this->getSysLanguageUid() > 0) {
$localizedFileReferences = $this->getLocalizedFileReferences($table, $field);
if (!empty($localizedFileReferences)) {
$localizedFileObject = $localizedFileReferences[0]->toArray();
if ($localizedFileObject) {
$pid = intval($localizedFileObject['pid']);
$uid = intval($localizedFileObject['uid']);
$fileReference = new FileReference();
$fileReference->pid = $pid;
$fileReference->uid = $uid;
$fileReference->_languageUid = 0;
$fileReference->_localizedUid = $uid;
$fileReference->_versionedUid = $uid;
return $fileReference;
}
}
}
return null;
} | [
"protected",
"function",
"getLocalizedFileReference",
"(",
"string",
"$",
"table",
",",
"string",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getSysLanguageUid",
"(",
")",
">",
"0",
")",
"{",
"$",
"localizedFileReferences",
"=",
"$",
"this",
"->",
"getLocalizedFileReferences",
"(",
"$",
"table",
",",
"$",
"field",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"localizedFileReferences",
")",
")",
"{",
"$",
"localizedFileObject",
"=",
"$",
"localizedFileReferences",
"[",
"0",
"]",
"->",
"toArray",
"(",
")",
";",
"if",
"(",
"$",
"localizedFileObject",
")",
"{",
"$",
"pid",
"=",
"intval",
"(",
"$",
"localizedFileObject",
"[",
"'pid'",
"]",
")",
";",
"$",
"uid",
"=",
"intval",
"(",
"$",
"localizedFileObject",
"[",
"'uid'",
"]",
")",
";",
"$",
"fileReference",
"=",
"new",
"FileReference",
"(",
")",
";",
"$",
"fileReference",
"->",
"pid",
"=",
"$",
"pid",
";",
"$",
"fileReference",
"->",
"uid",
"=",
"$",
"uid",
";",
"$",
"fileReference",
"->",
"_languageUid",
"=",
"0",
";",
"$",
"fileReference",
"->",
"_localizedUid",
"=",
"$",
"uid",
";",
"$",
"fileReference",
"->",
"_versionedUid",
"=",
"$",
"uid",
";",
"return",
"$",
"fileReference",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] | Gets a localized file reference.
@param string $table The table
@param string $field The field
@return array|null The localized file reference or null if no localized file reference was found | [
"Gets",
"a",
"localized",
"file",
"reference",
"."
] | 8c04b7688cc2773f11fcc87fda3f7cd53d80a980 | https://github.com/t3v/t3v_core/blob/8c04b7688cc2773f11fcc87fda3f7cd53d80a980/Classes/Domain/Model/Traits/FileReferenceTrait.php#L19-L43 | train |
t3v/t3v_core | Classes/Domain/Model/Traits/FileReferenceTrait.php | FileReferenceTrait.getLocalizedFileReferences | protected function getLocalizedFileReferences(string $table, string $field) {
if ($this->getSysLanguageUid() > 0) {
return $this->fileRepository->findByRelation($table, $field, $this->getLocalizedUid());
}
return null;
} | php | protected function getLocalizedFileReferences(string $table, string $field) {
if ($this->getSysLanguageUid() > 0) {
return $this->fileRepository->findByRelation($table, $field, $this->getLocalizedUid());
}
return null;
} | [
"protected",
"function",
"getLocalizedFileReferences",
"(",
"string",
"$",
"table",
",",
"string",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getSysLanguageUid",
"(",
")",
">",
"0",
")",
"{",
"return",
"$",
"this",
"->",
"fileRepository",
"->",
"findByRelation",
"(",
"$",
"table",
",",
"$",
"field",
",",
"$",
"this",
"->",
"getLocalizedUid",
"(",
")",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Gets localized file references.
@param string $table The table
@param string $field The field
@return array|null The localized file references or null if no localized file references were found | [
"Gets",
"localized",
"file",
"references",
"."
] | 8c04b7688cc2773f11fcc87fda3f7cd53d80a980 | https://github.com/t3v/t3v_core/blob/8c04b7688cc2773f11fcc87fda3f7cd53d80a980/Classes/Domain/Model/Traits/FileReferenceTrait.php#L52-L58 | train |
freialib/hlin.tools | src/Command/Cmdhelp.php | CmdhelpCommand.printp | protected function printp($input, $indent = 0) {
$input = trim($input, "\n\t\r ");
$indentation = str_repeat(' ', $indent);
$this->cli->printf($indentation.wordwrap(str_replace("\n", "\n$indentation", $input), 75 - $indent, "\n$indentation")."\n");
} | php | protected function printp($input, $indent = 0) {
$input = trim($input, "\n\t\r ");
$indentation = str_repeat(' ', $indent);
$this->cli->printf($indentation.wordwrap(str_replace("\n", "\n$indentation", $input), 75 - $indent, "\n$indentation")."\n");
} | [
"protected",
"function",
"printp",
"(",
"$",
"input",
",",
"$",
"indent",
"=",
"0",
")",
"{",
"$",
"input",
"=",
"trim",
"(",
"$",
"input",
",",
"\"\\n\\t\\r \"",
")",
";",
"$",
"indentation",
"=",
"str_repeat",
"(",
"' '",
",",
"$",
"indent",
")",
";",
"$",
"this",
"->",
"cli",
"->",
"printf",
"(",
"$",
"indentation",
".",
"wordwrap",
"(",
"str_replace",
"(",
"\"\\n\"",
",",
"\"\\n$indentation\"",
",",
"$",
"input",
")",
",",
"75",
"-",
"$",
"indent",
",",
"\"\\n$indentation\"",
")",
".",
"\"\\n\"",
")",
";",
"}"
] | Print paragraph. Anything passed will be trimmed and printed so as to fit
in the limit of 75 characters per line. | [
"Print",
"paragraph",
".",
"Anything",
"passed",
"will",
"be",
"trimmed",
"and",
"printed",
"so",
"as",
"to",
"fit",
"in",
"the",
"limit",
"of",
"75",
"characters",
"per",
"line",
"."
] | 42ad9e9fe081918d2ee5d52b72d174ccdcf7cbe7 | https://github.com/freialib/hlin.tools/blob/42ad9e9fe081918d2ee5d52b72d174ccdcf7cbe7/src/Command/Cmdhelp.php#L85-L89 | train |
ciims/ciims-modules-api | controllers/ContentController.php | ContentController.createNewPost | private function createNewPost()
{
if (!$this->user->role->hasPermission('create'))
throw new CHttpException(403, Yii::t('Api.content', 'You do not have permission to create new entries.'));
$model = new Content;
$model->populate($_POST);
// Return a model instance to work with
if ($model->savePrototype($this->user->id))
{
return $model->getAPIAttributes(array(
'category_id',
'parent_id',
'author_id'
),
array(
'author' => array(
'password',
'activation_key',
'email',
'about',
'user_role',
'status',
'created',
'updated'
),
'category' => array(
'parent_id'
),
'metadata' => array(
'content_id'
)
));
}
return $this->returnError(400, NULL, $model->getErrors());
} | php | private function createNewPost()
{
if (!$this->user->role->hasPermission('create'))
throw new CHttpException(403, Yii::t('Api.content', 'You do not have permission to create new entries.'));
$model = new Content;
$model->populate($_POST);
// Return a model instance to work with
if ($model->savePrototype($this->user->id))
{
return $model->getAPIAttributes(array(
'category_id',
'parent_id',
'author_id'
),
array(
'author' => array(
'password',
'activation_key',
'email',
'about',
'user_role',
'status',
'created',
'updated'
),
'category' => array(
'parent_id'
),
'metadata' => array(
'content_id'
)
));
}
return $this->returnError(400, NULL, $model->getErrors());
} | [
"private",
"function",
"createNewPost",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"user",
"->",
"role",
"->",
"hasPermission",
"(",
"'create'",
")",
")",
"throw",
"new",
"CHttpException",
"(",
"403",
",",
"Yii",
"::",
"t",
"(",
"'Api.content'",
",",
"'You do not have permission to create new entries.'",
")",
")",
";",
"$",
"model",
"=",
"new",
"Content",
";",
"$",
"model",
"->",
"populate",
"(",
"$",
"_POST",
")",
";",
"// Return a model instance to work with",
"if",
"(",
"$",
"model",
"->",
"savePrototype",
"(",
"$",
"this",
"->",
"user",
"->",
"id",
")",
")",
"{",
"return",
"$",
"model",
"->",
"getAPIAttributes",
"(",
"array",
"(",
"'category_id'",
",",
"'parent_id'",
",",
"'author_id'",
")",
",",
"array",
"(",
"'author'",
"=>",
"array",
"(",
"'password'",
",",
"'activation_key'",
",",
"'email'",
",",
"'about'",
",",
"'user_role'",
",",
"'status'",
",",
"'created'",
",",
"'updated'",
")",
",",
"'category'",
"=>",
"array",
"(",
"'parent_id'",
")",
",",
"'metadata'",
"=>",
"array",
"(",
"'content_id'",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"returnError",
"(",
"400",
",",
"NULL",
",",
"$",
"model",
"->",
"getErrors",
"(",
")",
")",
";",
"}"
] | Creates a new entry | [
"Creates",
"a",
"new",
"entry"
] | 4351855328da0b112ac27bde7e7e07e212be8689 | https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/controllers/ContentController.php#L330-L368 | train |
ciims/ciims-modules-api | controllers/ContentController.php | ContentController.updatePost | private function updatePost($id)
{
$model = $this->loadModel($id);
if (!$this->user->role->hasPermission('modify'))
throw new CHttpException(403, Yii::t('Api.content', 'You do not have permission to create new entries.'));
if ($this->user->role->isA('author') || $this->user->role->isA('collaborator'))
$model->author_id = $this->user->id;
$vid = $model->vid;
$model = new Content;
$model->id = $id;
$model->populate($_POST);
$model->vid = Yii::app()->db->createCommand('SELECT MAX(vid)+1 FROM content WHERE id = :id')->bindParam(':id', $id)->queryScalar();
if ($model->save())
return $model->getAPIAttributes(array(
'category_id',
'parent_id',
'author_id'
),
array(
'author' => array(
'password',
'activation_key',
'email',
'about',
'user_role',
'status',
'created',
'updated'
),
'category' => array(
'parent_id'
),
'metadata' => array(
'content_id'
)
));
return $this->returnError(400, NULL, $model->getErrors());
} | php | private function updatePost($id)
{
$model = $this->loadModel($id);
if (!$this->user->role->hasPermission('modify'))
throw new CHttpException(403, Yii::t('Api.content', 'You do not have permission to create new entries.'));
if ($this->user->role->isA('author') || $this->user->role->isA('collaborator'))
$model->author_id = $this->user->id;
$vid = $model->vid;
$model = new Content;
$model->id = $id;
$model->populate($_POST);
$model->vid = Yii::app()->db->createCommand('SELECT MAX(vid)+1 FROM content WHERE id = :id')->bindParam(':id', $id)->queryScalar();
if ($model->save())
return $model->getAPIAttributes(array(
'category_id',
'parent_id',
'author_id'
),
array(
'author' => array(
'password',
'activation_key',
'email',
'about',
'user_role',
'status',
'created',
'updated'
),
'category' => array(
'parent_id'
),
'metadata' => array(
'content_id'
)
));
return $this->returnError(400, NULL, $model->getErrors());
} | [
"private",
"function",
"updatePost",
"(",
"$",
"id",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"loadModel",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"user",
"->",
"role",
"->",
"hasPermission",
"(",
"'modify'",
")",
")",
"throw",
"new",
"CHttpException",
"(",
"403",
",",
"Yii",
"::",
"t",
"(",
"'Api.content'",
",",
"'You do not have permission to create new entries.'",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"user",
"->",
"role",
"->",
"isA",
"(",
"'author'",
")",
"||",
"$",
"this",
"->",
"user",
"->",
"role",
"->",
"isA",
"(",
"'collaborator'",
")",
")",
"$",
"model",
"->",
"author_id",
"=",
"$",
"this",
"->",
"user",
"->",
"id",
";",
"$",
"vid",
"=",
"$",
"model",
"->",
"vid",
";",
"$",
"model",
"=",
"new",
"Content",
";",
"$",
"model",
"->",
"id",
"=",
"$",
"id",
";",
"$",
"model",
"->",
"populate",
"(",
"$",
"_POST",
")",
";",
"$",
"model",
"->",
"vid",
"=",
"Yii",
"::",
"app",
"(",
")",
"->",
"db",
"->",
"createCommand",
"(",
"'SELECT MAX(vid)+1 FROM content WHERE id = :id'",
")",
"->",
"bindParam",
"(",
"':id'",
",",
"$",
"id",
")",
"->",
"queryScalar",
"(",
")",
";",
"if",
"(",
"$",
"model",
"->",
"save",
"(",
")",
")",
"return",
"$",
"model",
"->",
"getAPIAttributes",
"(",
"array",
"(",
"'category_id'",
",",
"'parent_id'",
",",
"'author_id'",
")",
",",
"array",
"(",
"'author'",
"=>",
"array",
"(",
"'password'",
",",
"'activation_key'",
",",
"'email'",
",",
"'about'",
",",
"'user_role'",
",",
"'status'",
",",
"'created'",
",",
"'updated'",
")",
",",
"'category'",
"=>",
"array",
"(",
"'parent_id'",
")",
",",
"'metadata'",
"=>",
"array",
"(",
"'content_id'",
")",
")",
")",
";",
"return",
"$",
"this",
"->",
"returnError",
"(",
"400",
",",
"NULL",
",",
"$",
"model",
"->",
"getErrors",
"(",
")",
")",
";",
"}"
] | Updates an existing entry
@param int $id The Content id | [
"Updates",
"an",
"existing",
"entry"
] | 4351855328da0b112ac27bde7e7e07e212be8689 | https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/controllers/ContentController.php#L374-L416 | train |
ciims/ciims-modules-api | controllers/ContentController.php | ContentController.loadModel | private function loadModel($id=NULL)
{
if ($id === NULL)
throw new CHttpException(400, Yii::t('Api.content', 'Missing id'));
$model = Content::model()->findByPk($id);
if ($model === NULL)
throw new CHttpException(404, Yii::t('Api.content', 'An entry with the id of {{id}} was not found', array('{{id}}' => $id)));
return $model;
} | php | private function loadModel($id=NULL)
{
if ($id === NULL)
throw new CHttpException(400, Yii::t('Api.content', 'Missing id'));
$model = Content::model()->findByPk($id);
if ($model === NULL)
throw new CHttpException(404, Yii::t('Api.content', 'An entry with the id of {{id}} was not found', array('{{id}}' => $id)));
return $model;
} | [
"private",
"function",
"loadModel",
"(",
"$",
"id",
"=",
"NULL",
")",
"{",
"if",
"(",
"$",
"id",
"===",
"NULL",
")",
"throw",
"new",
"CHttpException",
"(",
"400",
",",
"Yii",
"::",
"t",
"(",
"'Api.content'",
",",
"'Missing id'",
")",
")",
";",
"$",
"model",
"=",
"Content",
"::",
"model",
"(",
")",
"->",
"findByPk",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"model",
"===",
"NULL",
")",
"throw",
"new",
"CHttpException",
"(",
"404",
",",
"Yii",
"::",
"t",
"(",
"'Api.content'",
",",
"'An entry with the id of {{id}} was not found'",
",",
"array",
"(",
"'{{id}}'",
"=>",
"$",
"id",
")",
")",
")",
";",
"return",
"$",
"model",
";",
"}"
] | Retrieves the model
@param int $id The content ID
@return Content | [
"Retrieves",
"the",
"model"
] | 4351855328da0b112ac27bde7e7e07e212be8689 | https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/controllers/ContentController.php#L423-L433 | train |
ciims/ciims-modules-api | controllers/ContentController.php | ContentController.actionUploadImagePost | public function actionUploadImagePost($id=NULL, $promote = 0)
{
$result = new CiiFileUpload($id, $promote);
return $result->uploadFile();
} | php | public function actionUploadImagePost($id=NULL, $promote = 0)
{
$result = new CiiFileUpload($id, $promote);
return $result->uploadFile();
} | [
"public",
"function",
"actionUploadImagePost",
"(",
"$",
"id",
"=",
"NULL",
",",
"$",
"promote",
"=",
"0",
")",
"{",
"$",
"result",
"=",
"new",
"CiiFileUpload",
"(",
"$",
"id",
",",
"$",
"promote",
")",
";",
"return",
"$",
"result",
"->",
"uploadFile",
"(",
")",
";",
"}"
] | Uploads a video to the site.
@param integer $id The content_id
@param integer $promote Whether or not this image should be a promoted image or not
@return array | [
"Uploads",
"a",
"video",
"to",
"the",
"site",
"."
] | 4351855328da0b112ac27bde7e7e07e212be8689 | https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/controllers/ContentController.php#L441-L445 | train |
black-project/common | src/Common/Application/Form/Transformer/ArrayToDelimitedStringTransformer.php | ArrayToDelimitedStringTransformer.transform | public function transform($array)
{
if (null === $array) {
return '';
}
if (!is_array($array)) {
throw new TransformationFailedException('Expected an array.');
}
foreach ($array as &$value) {
$value = sprintf('%s%s%s',
str_repeat(' ', $this->paddingLeft),
$value,
str_repeat(' ', $this->paddingRight)
);
}
$string = trim(implode($this->delimiter, $array));
return $string;
} | php | public function transform($array)
{
if (null === $array) {
return '';
}
if (!is_array($array)) {
throw new TransformationFailedException('Expected an array.');
}
foreach ($array as &$value) {
$value = sprintf('%s%s%s',
str_repeat(' ', $this->paddingLeft),
$value,
str_repeat(' ', $this->paddingRight)
);
}
$string = trim(implode($this->delimiter, $array));
return $string;
} | [
"public",
"function",
"transform",
"(",
"$",
"array",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"array",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"array",
")",
")",
"{",
"throw",
"new",
"TransformationFailedException",
"(",
"'Expected an array.'",
")",
";",
"}",
"foreach",
"(",
"$",
"array",
"as",
"&",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"sprintf",
"(",
"'%s%s%s'",
",",
"str_repeat",
"(",
"' '",
",",
"$",
"this",
"->",
"paddingLeft",
")",
",",
"$",
"value",
",",
"str_repeat",
"(",
"' '",
",",
"$",
"this",
"->",
"paddingRight",
")",
")",
";",
"}",
"$",
"string",
"=",
"trim",
"(",
"implode",
"(",
"$",
"this",
"->",
"delimiter",
",",
"$",
"array",
")",
")",
";",
"return",
"$",
"string",
";",
"}"
] | Transforms an array into a delimited string
@param array $array Array to transform
@return string
@throws TransformationFailedException If the given value is not an array | [
"Transforms",
"an",
"array",
"into",
"a",
"delimited",
"string"
] | d1de2aaae75a7ca7997dbe402897c651d9c7412a | https://github.com/black-project/common/blob/d1de2aaae75a7ca7997dbe402897c651d9c7412a/src/Common/Application/Form/Transformer/ArrayToDelimitedStringTransformer.php#L44-L65 | train |
black-project/common | src/Common/Application/Form/Transformer/ArrayToDelimitedStringTransformer.php | ArrayToDelimitedStringTransformer.reverseTransform | public function reverseTransform($string)
{
if (null !== $string && !is_string($string)) {
throw new TransformationFailedException('Expected a string.');
}
$string = trim($string);
if (empty($string)) {
return array();
}
$values = explode($this->delimiter, $string);
if (0 === count($values)) {
return array();
}
foreach ($values as &$value) {
$value = trim($value);
}
return $values;
} | php | public function reverseTransform($string)
{
if (null !== $string && !is_string($string)) {
throw new TransformationFailedException('Expected a string.');
}
$string = trim($string);
if (empty($string)) {
return array();
}
$values = explode($this->delimiter, $string);
if (0 === count($values)) {
return array();
}
foreach ($values as &$value) {
$value = trim($value);
}
return $values;
} | [
"public",
"function",
"reverseTransform",
"(",
"$",
"string",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"string",
"&&",
"!",
"is_string",
"(",
"$",
"string",
")",
")",
"{",
"throw",
"new",
"TransformationFailedException",
"(",
"'Expected a string.'",
")",
";",
"}",
"$",
"string",
"=",
"trim",
"(",
"$",
"string",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"string",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"values",
"=",
"explode",
"(",
"$",
"this",
"->",
"delimiter",
",",
"$",
"string",
")",
";",
"if",
"(",
"0",
"===",
"count",
"(",
"$",
"values",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"values",
"as",
"&",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"trim",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"values",
";",
"}"
] | Transforms a delimited string into an array
@param string $string String to transform
@return array
@throws TransformationFailedException If the given value is not a string | [
"Transforms",
"a",
"delimited",
"string",
"into",
"an",
"array"
] | d1de2aaae75a7ca7997dbe402897c651d9c7412a | https://github.com/black-project/common/blob/d1de2aaae75a7ca7997dbe402897c651d9c7412a/src/Common/Application/Form/Transformer/ArrayToDelimitedStringTransformer.php#L76-L98 | train |
railken/lem | src/Concerns/HasPermissions.php | HasPermissions.getPermission | public function getPermission($code)
{
if (!isset($this->permissions[$code])) {
throw new Exceptions\PermissionNotDefinedException($this, $code);
}
return $this->permissions[$code];
} | php | public function getPermission($code)
{
if (!isset($this->permissions[$code])) {
throw new Exceptions\PermissionNotDefinedException($this, $code);
}
return $this->permissions[$code];
} | [
"public",
"function",
"getPermission",
"(",
"$",
"code",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"permissions",
"[",
"$",
"code",
"]",
")",
")",
"{",
"throw",
"new",
"Exceptions",
"\\",
"PermissionNotDefinedException",
"(",
"$",
"this",
",",
"$",
"code",
")",
";",
"}",
"return",
"$",
"this",
"->",
"permissions",
"[",
"$",
"code",
"]",
";",
"}"
] | Retrieve a permission name given code.
@param string $code
@return string | [
"Retrieve",
"a",
"permission",
"name",
"given",
"code",
"."
] | cff1efcd090a9504b2faf5594121885786dea67a | https://github.com/railken/lem/blob/cff1efcd090a9504b2faf5594121885786dea67a/src/Concerns/HasPermissions.php#L16-L23 | train |
romm/configuration_object | Classes/Traits/ConfigurationObject/ArrayConversionTrait.php | ArrayConversionTrait.getObjectPropertiesValues | private function getObjectPropertiesValues($object)
{
$properties = Core::get()->getGettablePropertiesOfObject($object);
$finalProperties = [];
foreach ($properties as $property) {
$finalProperties[$property] = Core::get()->getObjectService()->getObjectProperty($object, $property);
}
return $finalProperties;
} | php | private function getObjectPropertiesValues($object)
{
$properties = Core::get()->getGettablePropertiesOfObject($object);
$finalProperties = [];
foreach ($properties as $property) {
$finalProperties[$property] = Core::get()->getObjectService()->getObjectProperty($object, $property);
}
return $finalProperties;
} | [
"private",
"function",
"getObjectPropertiesValues",
"(",
"$",
"object",
")",
"{",
"$",
"properties",
"=",
"Core",
"::",
"get",
"(",
")",
"->",
"getGettablePropertiesOfObject",
"(",
"$",
"object",
")",
";",
"$",
"finalProperties",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"property",
")",
"{",
"$",
"finalProperties",
"[",
"$",
"property",
"]",
"=",
"Core",
"::",
"get",
"(",
")",
"->",
"getObjectService",
"(",
")",
"->",
"getObjectProperty",
"(",
"$",
"object",
",",
"$",
"property",
")",
";",
"}",
"return",
"$",
"finalProperties",
";",
"}"
] | Will return all the accessible properties of the given object instance.
@param object $object
@return array | [
"Will",
"return",
"all",
"the",
"accessible",
"properties",
"of",
"the",
"given",
"object",
"instance",
"."
] | d3a40903386c2e0766bd8279337fe6da45cf5ce3 | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Traits/ConfigurationObject/ArrayConversionTrait.php#L76-L86 | train |
bheisig/cli | src/App.php | App.invokeStandardCommands | protected function invokeStandardCommands() {
return $this
->addCommand(
'help',
__NAMESPACE__ . '\\Command\\Help',
'Show this help'
)
->addCommand(
'list',
__NAMESPACE__ . '\\Command\\ListCommands',
'List all commands'
)
->addCommand(
'init',
__NAMESPACE__ . '\\Command\\Init',
'Create/update user-defined or system-wide configuration settings'
)
->addCommand(
'configtest',
__NAMESPACE__ . '\\Command\\ConfigTest',
'Validate configuration settings'
)
->addCommand(
'print-config',
__NAMESPACE__ . '\\Command\\PrintConfig',
'Print current configuration settings'
)
->addCommand(
'version',
__NAMESPACE__ . '\\Command\\Version',
'Print version information'
);
} | php | protected function invokeStandardCommands() {
return $this
->addCommand(
'help',
__NAMESPACE__ . '\\Command\\Help',
'Show this help'
)
->addCommand(
'list',
__NAMESPACE__ . '\\Command\\ListCommands',
'List all commands'
)
->addCommand(
'init',
__NAMESPACE__ . '\\Command\\Init',
'Create/update user-defined or system-wide configuration settings'
)
->addCommand(
'configtest',
__NAMESPACE__ . '\\Command\\ConfigTest',
'Validate configuration settings'
)
->addCommand(
'print-config',
__NAMESPACE__ . '\\Command\\PrintConfig',
'Print current configuration settings'
)
->addCommand(
'version',
__NAMESPACE__ . '\\Command\\Version',
'Print version information'
);
} | [
"protected",
"function",
"invokeStandardCommands",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"addCommand",
"(",
"'help'",
",",
"__NAMESPACE__",
".",
"'\\\\Command\\\\Help'",
",",
"'Show this help'",
")",
"->",
"addCommand",
"(",
"'list'",
",",
"__NAMESPACE__",
".",
"'\\\\Command\\\\ListCommands'",
",",
"'List all commands'",
")",
"->",
"addCommand",
"(",
"'init'",
",",
"__NAMESPACE__",
".",
"'\\\\Command\\\\Init'",
",",
"'Create/update user-defined or system-wide configuration settings'",
")",
"->",
"addCommand",
"(",
"'configtest'",
",",
"__NAMESPACE__",
".",
"'\\\\Command\\\\ConfigTest'",
",",
"'Validate configuration settings'",
")",
"->",
"addCommand",
"(",
"'print-config'",
",",
"__NAMESPACE__",
".",
"'\\\\Command\\\\PrintConfig'",
",",
"'Print current configuration settings'",
")",
"->",
"addCommand",
"(",
"'version'",
",",
"__NAMESPACE__",
".",
"'\\\\Command\\\\Version'",
",",
"'Print version information'",
")",
";",
"}"
] | Invoke standard commands
@return self Returns itself | [
"Invoke",
"standard",
"commands"
] | ee77266e173335950357899cdfe86b43c00a6776 | https://github.com/bheisig/cli/blob/ee77266e173335950357899cdfe86b43c00a6776/src/App.php#L113-L145 | train |
bheisig/cli | src/App.php | App.invokeStandardOptions | protected function invokeStandardOptions() {
return $this
->addOption('c', 'config', self::OPTION_NOT_REQUIRED)
->addOption('h', 'help', self::NO_VALUE)
->addOption(null, 'no-colors', self::NO_VALUE)
->addOption('q', 'quiet', self::NO_VALUE)
->addOption('v', 'verbose', self::NO_VALUE)
->addOption(null, 'version', self::NO_VALUE)
->addOption('s', 'setting', self::OPTION_NOT_REQUIRED);
} | php | protected function invokeStandardOptions() {
return $this
->addOption('c', 'config', self::OPTION_NOT_REQUIRED)
->addOption('h', 'help', self::NO_VALUE)
->addOption(null, 'no-colors', self::NO_VALUE)
->addOption('q', 'quiet', self::NO_VALUE)
->addOption('v', 'verbose', self::NO_VALUE)
->addOption(null, 'version', self::NO_VALUE)
->addOption('s', 'setting', self::OPTION_NOT_REQUIRED);
} | [
"protected",
"function",
"invokeStandardOptions",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"addOption",
"(",
"'c'",
",",
"'config'",
",",
"self",
"::",
"OPTION_NOT_REQUIRED",
")",
"->",
"addOption",
"(",
"'h'",
",",
"'help'",
",",
"self",
"::",
"NO_VALUE",
")",
"->",
"addOption",
"(",
"null",
",",
"'no-colors'",
",",
"self",
"::",
"NO_VALUE",
")",
"->",
"addOption",
"(",
"'q'",
",",
"'quiet'",
",",
"self",
"::",
"NO_VALUE",
")",
"->",
"addOption",
"(",
"'v'",
",",
"'verbose'",
",",
"self",
"::",
"NO_VALUE",
")",
"->",
"addOption",
"(",
"null",
",",
"'version'",
",",
"self",
"::",
"NO_VALUE",
")",
"->",
"addOption",
"(",
"'s'",
",",
"'setting'",
",",
"self",
"::",
"OPTION_NOT_REQUIRED",
")",
";",
"}"
] | Invoke standard options
@return self Returns itself
@throws Exception on error | [
"Invoke",
"standard",
"options"
] | ee77266e173335950357899cdfe86b43c00a6776 | https://github.com/bheisig/cli/blob/ee77266e173335950357899cdfe86b43c00a6776/src/App.php#L154-L163 | train |
bheisig/cli | src/App.php | App.invokeLogging | protected function invokeLogging() {
$this->config['log'] = [
'colorize' => true,
'verbosity' => Log::ALL | ~Log::DEBUG
];
$this->log = new Log();
return $this;
} | php | protected function invokeLogging() {
$this->config['log'] = [
'colorize' => true,
'verbosity' => Log::ALL | ~Log::DEBUG
];
$this->log = new Log();
return $this;
} | [
"protected",
"function",
"invokeLogging",
"(",
")",
"{",
"$",
"this",
"->",
"config",
"[",
"'log'",
"]",
"=",
"[",
"'colorize'",
"=>",
"true",
",",
"'verbosity'",
"=>",
"Log",
"::",
"ALL",
"|",
"~",
"Log",
"::",
"DEBUG",
"]",
";",
"$",
"this",
"->",
"log",
"=",
"new",
"Log",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Initialize logger with default values
@return self Returns itself | [
"Initialize",
"logger",
"with",
"default",
"values"
] | ee77266e173335950357899cdfe86b43c00a6776 | https://github.com/bheisig/cli/blob/ee77266e173335950357899cdfe86b43c00a6776/src/App.php#L170-L179 | train |
bheisig/cli | src/App.php | App.addConfigFile | public function addConfigFile($file, $force = false) {
$settings = JSONFile::read($file, $force);
$this->addConfigSettings($settings);
return $this;
} | php | public function addConfigFile($file, $force = false) {
$settings = JSONFile::read($file, $force);
$this->addConfigSettings($settings);
return $this;
} | [
"public",
"function",
"addConfigFile",
"(",
"$",
"file",
",",
"$",
"force",
"=",
"false",
")",
"{",
"$",
"settings",
"=",
"JSONFile",
"::",
"read",
"(",
"$",
"file",
",",
"$",
"force",
")",
";",
"$",
"this",
"->",
"addConfigSettings",
"(",
"$",
"settings",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Parse a JSON file and add its content to the configuration settings
@param string $file File path
@param bool $force If "true" and file is not readable ignore it, otherwise throw an exception. Defaults to
"false".
@return self Returns itself
@throws Exception on error | [
"Parse",
"a",
"JSON",
"file",
"and",
"add",
"its",
"content",
"to",
"the",
"configuration",
"settings"
] | ee77266e173335950357899cdfe86b43c00a6776 | https://github.com/bheisig/cli/blob/ee77266e173335950357899cdfe86b43c00a6776/src/App.php#L192-L198 | train |
bheisig/cli | src/App.php | App.addConfigSettings | public function addConfigSettings(array $settings) {
$this->config = $this->arrayMergeRecursiveOverwrite(
$this->config,
$settings
);
return $this;
} | php | public function addConfigSettings(array $settings) {
$this->config = $this->arrayMergeRecursiveOverwrite(
$this->config,
$settings
);
return $this;
} | [
"public",
"function",
"addConfigSettings",
"(",
"array",
"$",
"settings",
")",
"{",
"$",
"this",
"->",
"config",
"=",
"$",
"this",
"->",
"arrayMergeRecursiveOverwrite",
"(",
"$",
"this",
"->",
"config",
",",
"$",
"settings",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add configuration settings
@param array $settings Configuration settings
@return self Returns itself | [
"Add",
"configuration",
"settings"
] | ee77266e173335950357899cdfe86b43c00a6776 | https://github.com/bheisig/cli/blob/ee77266e173335950357899cdfe86b43c00a6776/src/App.php#L207-L214 | train |
bheisig/cli | src/App.php | App.satisfyUserChoice | protected function satisfyUserChoice() {
// <APP NAME> --version:
if (array_key_exists('version', $this->config['options'])) {
$this->executeCommand('version');
$this->close();
}
// <APP NAME> -v:
if (count($this->config['args']) === 2 &&
array_key_exists('v', $this->config['options'])) {
$this->executeCommand('version');
$this->close();
}
// <APP NAME> <COMMAND>:
foreach ($this->config['args'] as $arg) {
if (array_key_exists($arg, $this->config['commands'])) {
$this->executeCommand($arg);
$this->close();
}
}
switch (count($this->config['arguments'])) {
// <APP NAME> [<COMMAND>] [<OPTION>] --help:
// <APP NAME> [<COMMAND>] [<OPTION>] -h:
case 0:
$this->executeCommand('help');
$this->close();
break;
// <APP NAME> <UNKNOWN COMMAND>:
default:
throw new RuntimeException(sprintf(
'Command "%s" not found',
$this->config['arguments'][0]
), ExitApp::BAD_USER_INTERACTION);
break;
}
} | php | protected function satisfyUserChoice() {
// <APP NAME> --version:
if (array_key_exists('version', $this->config['options'])) {
$this->executeCommand('version');
$this->close();
}
// <APP NAME> -v:
if (count($this->config['args']) === 2 &&
array_key_exists('v', $this->config['options'])) {
$this->executeCommand('version');
$this->close();
}
// <APP NAME> <COMMAND>:
foreach ($this->config['args'] as $arg) {
if (array_key_exists($arg, $this->config['commands'])) {
$this->executeCommand($arg);
$this->close();
}
}
switch (count($this->config['arguments'])) {
// <APP NAME> [<COMMAND>] [<OPTION>] --help:
// <APP NAME> [<COMMAND>] [<OPTION>] -h:
case 0:
$this->executeCommand('help');
$this->close();
break;
// <APP NAME> <UNKNOWN COMMAND>:
default:
throw new RuntimeException(sprintf(
'Command "%s" not found',
$this->config['arguments'][0]
), ExitApp::BAD_USER_INTERACTION);
break;
}
} | [
"protected",
"function",
"satisfyUserChoice",
"(",
")",
"{",
"// <APP NAME> --version:",
"if",
"(",
"array_key_exists",
"(",
"'version'",
",",
"$",
"this",
"->",
"config",
"[",
"'options'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"executeCommand",
"(",
"'version'",
")",
";",
"$",
"this",
"->",
"close",
"(",
")",
";",
"}",
"// <APP NAME> -v:",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"config",
"[",
"'args'",
"]",
")",
"===",
"2",
"&&",
"array_key_exists",
"(",
"'v'",
",",
"$",
"this",
"->",
"config",
"[",
"'options'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"executeCommand",
"(",
"'version'",
")",
";",
"$",
"this",
"->",
"close",
"(",
")",
";",
"}",
"// <APP NAME> <COMMAND>:",
"foreach",
"(",
"$",
"this",
"->",
"config",
"[",
"'args'",
"]",
"as",
"$",
"arg",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"arg",
",",
"$",
"this",
"->",
"config",
"[",
"'commands'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"executeCommand",
"(",
"$",
"arg",
")",
";",
"$",
"this",
"->",
"close",
"(",
")",
";",
"}",
"}",
"switch",
"(",
"count",
"(",
"$",
"this",
"->",
"config",
"[",
"'arguments'",
"]",
")",
")",
"{",
"// <APP NAME> [<COMMAND>] [<OPTION>] --help:",
"// <APP NAME> [<COMMAND>] [<OPTION>] -h:",
"case",
"0",
":",
"$",
"this",
"->",
"executeCommand",
"(",
"'help'",
")",
";",
"$",
"this",
"->",
"close",
"(",
")",
";",
"break",
";",
"// <APP NAME> <UNKNOWN COMMAND>:",
"default",
":",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Command \"%s\" not found'",
",",
"$",
"this",
"->",
"config",
"[",
"'arguments'",
"]",
"[",
"0",
"]",
")",
",",
"ExitApp",
"::",
"BAD_USER_INTERACTION",
")",
";",
"break",
";",
"}",
"}"
] | Try to find out what the user wants
@throws Exception on error | [
"Try",
"to",
"find",
"out",
"what",
"the",
"user",
"wants"
] | ee77266e173335950357899cdfe86b43c00a6776 | https://github.com/bheisig/cli/blob/ee77266e173335950357899cdfe86b43c00a6776/src/App.php#L366-L403 | train |
bheisig/cli | src/App.php | App.parseArguments | protected function parseArguments() {
$this->config['arguments'] = [];
$commandFound =false;
for ($index = 0; $index < count($this->config['args']); $index++) {
// Ignore binary name:
if ($index === 0) {
continue;
}
$arg = $this->config['args'][$index];
// Ignore command:
if (array_key_exists($arg, $this->config['commands']) &&
$commandFound === false) {
$commandFound = true;
continue;
}
// Ignore options:
if (strpos($arg, '--') === 0) {
foreach ($this->options as $option) {
if (!array_key_exists('long', $option)) {
continue;
}
if ('--' . $option['long'] !== $arg) {
continue;
}
if ($option['value'] !== self::NO_VALUE &&
strpos($arg, '--' . $option['long'] . '=') === 0) {
break;
} elseif ($option['value'] === self::NO_VALUE) {
$index += 1;
break;
} else {
$index += 2;
break;
}
}
} elseif (strpos($arg, '-') === 0) {
foreach ($this->options as $option) {
if (!array_key_exists('short', $option)) {
continue;
}
if ('-' . $option['short'] !== $arg) {
continue;
}
if ($option['value'] === self::NO_VALUE) {
$index += 1;
break;
} else {
$index += 2;
break;
}
}
} else {
$this->config['arguments'][] = $arg;
}
}
return $this;
} | php | protected function parseArguments() {
$this->config['arguments'] = [];
$commandFound =false;
for ($index = 0; $index < count($this->config['args']); $index++) {
// Ignore binary name:
if ($index === 0) {
continue;
}
$arg = $this->config['args'][$index];
// Ignore command:
if (array_key_exists($arg, $this->config['commands']) &&
$commandFound === false) {
$commandFound = true;
continue;
}
// Ignore options:
if (strpos($arg, '--') === 0) {
foreach ($this->options as $option) {
if (!array_key_exists('long', $option)) {
continue;
}
if ('--' . $option['long'] !== $arg) {
continue;
}
if ($option['value'] !== self::NO_VALUE &&
strpos($arg, '--' . $option['long'] . '=') === 0) {
break;
} elseif ($option['value'] === self::NO_VALUE) {
$index += 1;
break;
} else {
$index += 2;
break;
}
}
} elseif (strpos($arg, '-') === 0) {
foreach ($this->options as $option) {
if (!array_key_exists('short', $option)) {
continue;
}
if ('-' . $option['short'] !== $arg) {
continue;
}
if ($option['value'] === self::NO_VALUE) {
$index += 1;
break;
} else {
$index += 2;
break;
}
}
} else {
$this->config['arguments'][] = $arg;
}
}
return $this;
} | [
"protected",
"function",
"parseArguments",
"(",
")",
"{",
"$",
"this",
"->",
"config",
"[",
"'arguments'",
"]",
"=",
"[",
"]",
";",
"$",
"commandFound",
"=",
"false",
";",
"for",
"(",
"$",
"index",
"=",
"0",
";",
"$",
"index",
"<",
"count",
"(",
"$",
"this",
"->",
"config",
"[",
"'args'",
"]",
")",
";",
"$",
"index",
"++",
")",
"{",
"// Ignore binary name:",
"if",
"(",
"$",
"index",
"===",
"0",
")",
"{",
"continue",
";",
"}",
"$",
"arg",
"=",
"$",
"this",
"->",
"config",
"[",
"'args'",
"]",
"[",
"$",
"index",
"]",
";",
"// Ignore command:",
"if",
"(",
"array_key_exists",
"(",
"$",
"arg",
",",
"$",
"this",
"->",
"config",
"[",
"'commands'",
"]",
")",
"&&",
"$",
"commandFound",
"===",
"false",
")",
"{",
"$",
"commandFound",
"=",
"true",
";",
"continue",
";",
"}",
"// Ignore options:",
"if",
"(",
"strpos",
"(",
"$",
"arg",
",",
"'--'",
")",
"===",
"0",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"options",
"as",
"$",
"option",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"'long'",
",",
"$",
"option",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"'--'",
".",
"$",
"option",
"[",
"'long'",
"]",
"!==",
"$",
"arg",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"option",
"[",
"'value'",
"]",
"!==",
"self",
"::",
"NO_VALUE",
"&&",
"strpos",
"(",
"$",
"arg",
",",
"'--'",
".",
"$",
"option",
"[",
"'long'",
"]",
".",
"'='",
")",
"===",
"0",
")",
"{",
"break",
";",
"}",
"elseif",
"(",
"$",
"option",
"[",
"'value'",
"]",
"===",
"self",
"::",
"NO_VALUE",
")",
"{",
"$",
"index",
"+=",
"1",
";",
"break",
";",
"}",
"else",
"{",
"$",
"index",
"+=",
"2",
";",
"break",
";",
"}",
"}",
"}",
"elseif",
"(",
"strpos",
"(",
"$",
"arg",
",",
"'-'",
")",
"===",
"0",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"options",
"as",
"$",
"option",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"'short'",
",",
"$",
"option",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"'-'",
".",
"$",
"option",
"[",
"'short'",
"]",
"!==",
"$",
"arg",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"option",
"[",
"'value'",
"]",
"===",
"self",
"::",
"NO_VALUE",
")",
"{",
"$",
"index",
"+=",
"1",
";",
"break",
";",
"}",
"else",
"{",
"$",
"index",
"+=",
"2",
";",
"break",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"config",
"[",
"'arguments'",
"]",
"[",
"]",
"=",
"$",
"arg",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Parse given arguments
@return self Returns itself | [
"Parse",
"given",
"arguments"
] | ee77266e173335950357899cdfe86b43c00a6776 | https://github.com/bheisig/cli/blob/ee77266e173335950357899cdfe86b43c00a6776/src/App.php#L509-L575 | train |
bheisig/cli | src/App.php | App.loadAdditionalConfigFiles | protected function loadAdditionalConfigFiles() {
$additionalConfigFiles = [];
foreach ($this->config['options'] as $option => $value) {
if (in_array($option, ['c', 'config'])) {
switch (gettype($value)) {
case 'string':
$additionalConfigFiles[] = $value;
break;
case 'array':
foreach ($value as $item) {
if (!is_string($item)) {
throw new Exception(sprintf(
'Unknown value "%s" for option "%s"',
$item,
$option
), ExitApp::BAD_USER_INTERACTION);
}
$additionalConfigFiles[] = $item;
}
break;
default:
throw new Exception(sprintf(
'Unknown value "%s" for option "%s"',
$value,
$option
), ExitApp::BAD_USER_INTERACTION);
}
}
}
foreach ($additionalConfigFiles as $additionalConfigFile) {
$this->addConfigFile($additionalConfigFile);
}
return $this;
} | php | protected function loadAdditionalConfigFiles() {
$additionalConfigFiles = [];
foreach ($this->config['options'] as $option => $value) {
if (in_array($option, ['c', 'config'])) {
switch (gettype($value)) {
case 'string':
$additionalConfigFiles[] = $value;
break;
case 'array':
foreach ($value as $item) {
if (!is_string($item)) {
throw new Exception(sprintf(
'Unknown value "%s" for option "%s"',
$item,
$option
), ExitApp::BAD_USER_INTERACTION);
}
$additionalConfigFiles[] = $item;
}
break;
default:
throw new Exception(sprintf(
'Unknown value "%s" for option "%s"',
$value,
$option
), ExitApp::BAD_USER_INTERACTION);
}
}
}
foreach ($additionalConfigFiles as $additionalConfigFile) {
$this->addConfigFile($additionalConfigFile);
}
return $this;
} | [
"protected",
"function",
"loadAdditionalConfigFiles",
"(",
")",
"{",
"$",
"additionalConfigFiles",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"config",
"[",
"'options'",
"]",
"as",
"$",
"option",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"option",
",",
"[",
"'c'",
",",
"'config'",
"]",
")",
")",
"{",
"switch",
"(",
"gettype",
"(",
"$",
"value",
")",
")",
"{",
"case",
"'string'",
":",
"$",
"additionalConfigFiles",
"[",
"]",
"=",
"$",
"value",
";",
"break",
";",
"case",
"'array'",
":",
"foreach",
"(",
"$",
"value",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"item",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'Unknown value \"%s\" for option \"%s\"'",
",",
"$",
"item",
",",
"$",
"option",
")",
",",
"ExitApp",
"::",
"BAD_USER_INTERACTION",
")",
";",
"}",
"$",
"additionalConfigFiles",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"break",
";",
"default",
":",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'Unknown value \"%s\" for option \"%s\"'",
",",
"$",
"value",
",",
"$",
"option",
")",
",",
"ExitApp",
"::",
"BAD_USER_INTERACTION",
")",
";",
"}",
"}",
"}",
"foreach",
"(",
"$",
"additionalConfigFiles",
"as",
"$",
"additionalConfigFile",
")",
"{",
"$",
"this",
"->",
"addConfigFile",
"(",
"$",
"additionalConfigFile",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Parse additional configuration files given as options
@return self Returns itself
@throws Exception on error | [
"Parse",
"additional",
"configuration",
"files",
"given",
"as",
"options"
] | ee77266e173335950357899cdfe86b43c00a6776 | https://github.com/bheisig/cli/blob/ee77266e173335950357899cdfe86b43c00a6776/src/App.php#L652-L689 | train |
bheisig/cli | src/App.php | App.addRuntimeSettings | protected function addRuntimeSettings() {
$newSettings = [];
foreach ($this->config['options'] as $option => $value) {
if (in_array($option, ['s', 'setting'])) {
switch (gettype($value)) {
case 'string':
$newSettings[] = $value;
break;
case 'array':
foreach ($value as $item) {
if (!is_string($item)) {
throw new Exception(sprintf(
'Unknown value "%s" for option "%s"',
$item,
$option
));
}
$newSettings[] = $item;
}
break;
default:
throw new Exception(sprintf(
'Unknown value "%s" for option "%s"',
$value,
$option
), ExitApp::BAD_USER_INTERACTION);
}
}
}
foreach ($newSettings as $newSetting) {
$key = strstr($newSetting, '=', true);
$value = strstr($newSetting, '=');
if ($key === false || $value === false ||
strlen($key) === 0 || strlen($value) <= 1) {
throw new Exception('Invalid runtime settings', ExitApp::BAD_USER_INTERACTION);
}
// Crop "=":
$value = substr($value, 1);
// Type casting:
if (is_numeric($value) && (int) $value == $value) {
$value = (int) $value;
} elseif (is_numeric($value) && (float) $value == $value) {
$value = (float) $value;
} elseif (strtolower($value) === 'true') {
$value = true;
} elseif (strtolower($value) === 'false') {
$value = false;
}
$keys = explode('.', $key);
$settings = $this->buildSettings($keys, $value);
$this->addConfigSettings($settings);
}
return $this;
} | php | protected function addRuntimeSettings() {
$newSettings = [];
foreach ($this->config['options'] as $option => $value) {
if (in_array($option, ['s', 'setting'])) {
switch (gettype($value)) {
case 'string':
$newSettings[] = $value;
break;
case 'array':
foreach ($value as $item) {
if (!is_string($item)) {
throw new Exception(sprintf(
'Unknown value "%s" for option "%s"',
$item,
$option
));
}
$newSettings[] = $item;
}
break;
default:
throw new Exception(sprintf(
'Unknown value "%s" for option "%s"',
$value,
$option
), ExitApp::BAD_USER_INTERACTION);
}
}
}
foreach ($newSettings as $newSetting) {
$key = strstr($newSetting, '=', true);
$value = strstr($newSetting, '=');
if ($key === false || $value === false ||
strlen($key) === 0 || strlen($value) <= 1) {
throw new Exception('Invalid runtime settings', ExitApp::BAD_USER_INTERACTION);
}
// Crop "=":
$value = substr($value, 1);
// Type casting:
if (is_numeric($value) && (int) $value == $value) {
$value = (int) $value;
} elseif (is_numeric($value) && (float) $value == $value) {
$value = (float) $value;
} elseif (strtolower($value) === 'true') {
$value = true;
} elseif (strtolower($value) === 'false') {
$value = false;
}
$keys = explode('.', $key);
$settings = $this->buildSettings($keys, $value);
$this->addConfigSettings($settings);
}
return $this;
} | [
"protected",
"function",
"addRuntimeSettings",
"(",
")",
"{",
"$",
"newSettings",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"config",
"[",
"'options'",
"]",
"as",
"$",
"option",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"option",
",",
"[",
"'s'",
",",
"'setting'",
"]",
")",
")",
"{",
"switch",
"(",
"gettype",
"(",
"$",
"value",
")",
")",
"{",
"case",
"'string'",
":",
"$",
"newSettings",
"[",
"]",
"=",
"$",
"value",
";",
"break",
";",
"case",
"'array'",
":",
"foreach",
"(",
"$",
"value",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"item",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'Unknown value \"%s\" for option \"%s\"'",
",",
"$",
"item",
",",
"$",
"option",
")",
")",
";",
"}",
"$",
"newSettings",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"break",
";",
"default",
":",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'Unknown value \"%s\" for option \"%s\"'",
",",
"$",
"value",
",",
"$",
"option",
")",
",",
"ExitApp",
"::",
"BAD_USER_INTERACTION",
")",
";",
"}",
"}",
"}",
"foreach",
"(",
"$",
"newSettings",
"as",
"$",
"newSetting",
")",
"{",
"$",
"key",
"=",
"strstr",
"(",
"$",
"newSetting",
",",
"'='",
",",
"true",
")",
";",
"$",
"value",
"=",
"strstr",
"(",
"$",
"newSetting",
",",
"'='",
")",
";",
"if",
"(",
"$",
"key",
"===",
"false",
"||",
"$",
"value",
"===",
"false",
"||",
"strlen",
"(",
"$",
"key",
")",
"===",
"0",
"||",
"strlen",
"(",
"$",
"value",
")",
"<=",
"1",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Invalid runtime settings'",
",",
"ExitApp",
"::",
"BAD_USER_INTERACTION",
")",
";",
"}",
"// Crop \"=\":",
"$",
"value",
"=",
"substr",
"(",
"$",
"value",
",",
"1",
")",
";",
"// Type casting:",
"if",
"(",
"is_numeric",
"(",
"$",
"value",
")",
"&&",
"(",
"int",
")",
"$",
"value",
"==",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"(",
"int",
")",
"$",
"value",
";",
"}",
"elseif",
"(",
"is_numeric",
"(",
"$",
"value",
")",
"&&",
"(",
"float",
")",
"$",
"value",
"==",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"(",
"float",
")",
"$",
"value",
";",
"}",
"elseif",
"(",
"strtolower",
"(",
"$",
"value",
")",
"===",
"'true'",
")",
"{",
"$",
"value",
"=",
"true",
";",
"}",
"elseif",
"(",
"strtolower",
"(",
"$",
"value",
")",
"===",
"'false'",
")",
"{",
"$",
"value",
"=",
"false",
";",
"}",
"$",
"keys",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"$",
"settings",
"=",
"$",
"this",
"->",
"buildSettings",
"(",
"$",
"keys",
",",
"$",
"value",
")",
";",
"$",
"this",
"->",
"addConfigSettings",
"(",
"$",
"settings",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Look for additional configuration settings given as options
@return self Returns itself
@throws Exception on error | [
"Look",
"for",
"additional",
"configuration",
"settings",
"given",
"as",
"options"
] | ee77266e173335950357899cdfe86b43c00a6776 | https://github.com/bheisig/cli/blob/ee77266e173335950357899cdfe86b43c00a6776/src/App.php#L698-L761 | train |
bheisig/cli | src/App.php | App.buildSettings | protected function buildSettings($keys, $value) {
$result = [];
$index = array_shift($keys);
if (!isset($keys[0])) {
$result[$index] = $value;
} else {
$result[$index] = $this->buildSettings($keys, $value);
}
return $result;
} | php | protected function buildSettings($keys, $value) {
$result = [];
$index = array_shift($keys);
if (!isset($keys[0])) {
$result[$index] = $value;
} else {
$result[$index] = $this->buildSettings($keys, $value);
}
return $result;
} | [
"protected",
"function",
"buildSettings",
"(",
"$",
"keys",
",",
"$",
"value",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"index",
"=",
"array_shift",
"(",
"$",
"keys",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"keys",
"[",
"0",
"]",
")",
")",
"{",
"$",
"result",
"[",
"$",
"index",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"$",
"index",
"]",
"=",
"$",
"this",
"->",
"buildSettings",
"(",
"$",
"keys",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Create associative array for settings
@param string[] $keys Setting path
@param mixed $value Value
@return array | [
"Create",
"associative",
"array",
"for",
"settings"
] | ee77266e173335950357899cdfe86b43c00a6776 | https://github.com/bheisig/cli/blob/ee77266e173335950357899cdfe86b43c00a6776/src/App.php#L771-L783 | train |
bheisig/cli | src/App.php | App.configureLogger | protected function configureLogger() {
$appNoColor = strtoupper($this->config['composer']['extra']['name']) . '_NOCOLOR';
if (array_key_exists('no-colors', $this->config['options']) ||
getenv('NO_COLOR') !== false ||
getenv($appNoColor) !== false ||
(function_exists('posix_isatty') && posix_isatty(STDOUT) === false)) {
$this->config['log']['colorize'] = false;
}
$this->log->printColors($this->config['log']['colorize']);
if (array_key_exists('q', $this->config['options']) ||
array_key_exists('quiet', $this->config['options'])) {
$this->config['log']['verbosity'] = Log::FATAL | Log::ERROR;
} elseif (array_key_exists('v', $this->config['options']) ||
array_key_exists('verbose', $this->config['options'])) {
$this->config['log']['verbosity'] = Log::ALL;
}
$this->log->setVerbosity($this->config['log']['verbosity']);
return $this;
} | php | protected function configureLogger() {
$appNoColor = strtoupper($this->config['composer']['extra']['name']) . '_NOCOLOR';
if (array_key_exists('no-colors', $this->config['options']) ||
getenv('NO_COLOR') !== false ||
getenv($appNoColor) !== false ||
(function_exists('posix_isatty') && posix_isatty(STDOUT) === false)) {
$this->config['log']['colorize'] = false;
}
$this->log->printColors($this->config['log']['colorize']);
if (array_key_exists('q', $this->config['options']) ||
array_key_exists('quiet', $this->config['options'])) {
$this->config['log']['verbosity'] = Log::FATAL | Log::ERROR;
} elseif (array_key_exists('v', $this->config['options']) ||
array_key_exists('verbose', $this->config['options'])) {
$this->config['log']['verbosity'] = Log::ALL;
}
$this->log->setVerbosity($this->config['log']['verbosity']);
return $this;
} | [
"protected",
"function",
"configureLogger",
"(",
")",
"{",
"$",
"appNoColor",
"=",
"strtoupper",
"(",
"$",
"this",
"->",
"config",
"[",
"'composer'",
"]",
"[",
"'extra'",
"]",
"[",
"'name'",
"]",
")",
".",
"'_NOCOLOR'",
";",
"if",
"(",
"array_key_exists",
"(",
"'no-colors'",
",",
"$",
"this",
"->",
"config",
"[",
"'options'",
"]",
")",
"||",
"getenv",
"(",
"'NO_COLOR'",
")",
"!==",
"false",
"||",
"getenv",
"(",
"$",
"appNoColor",
")",
"!==",
"false",
"||",
"(",
"function_exists",
"(",
"'posix_isatty'",
")",
"&&",
"posix_isatty",
"(",
"STDOUT",
")",
"===",
"false",
")",
")",
"{",
"$",
"this",
"->",
"config",
"[",
"'log'",
"]",
"[",
"'colorize'",
"]",
"=",
"false",
";",
"}",
"$",
"this",
"->",
"log",
"->",
"printColors",
"(",
"$",
"this",
"->",
"config",
"[",
"'log'",
"]",
"[",
"'colorize'",
"]",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'q'",
",",
"$",
"this",
"->",
"config",
"[",
"'options'",
"]",
")",
"||",
"array_key_exists",
"(",
"'quiet'",
",",
"$",
"this",
"->",
"config",
"[",
"'options'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"config",
"[",
"'log'",
"]",
"[",
"'verbosity'",
"]",
"=",
"Log",
"::",
"FATAL",
"|",
"Log",
"::",
"ERROR",
";",
"}",
"elseif",
"(",
"array_key_exists",
"(",
"'v'",
",",
"$",
"this",
"->",
"config",
"[",
"'options'",
"]",
")",
"||",
"array_key_exists",
"(",
"'verbose'",
",",
"$",
"this",
"->",
"config",
"[",
"'options'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"config",
"[",
"'log'",
"]",
"[",
"'verbosity'",
"]",
"=",
"Log",
"::",
"ALL",
";",
"}",
"$",
"this",
"->",
"log",
"->",
"setVerbosity",
"(",
"$",
"this",
"->",
"config",
"[",
"'log'",
"]",
"[",
"'verbosity'",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set color handling and verbosity for used logger
Respect environment variables
- "NO_COLOR" (@see https://no-color.org/) and
- "<App name in upper case>_NOCOLOR"
regardless of their values
Also, disable colors if there is no TTY available
(for example, then output is piped to another app)
@return self Returns itself | [
"Set",
"color",
"handling",
"and",
"verbosity",
"for",
"used",
"logger"
] | ee77266e173335950357899cdfe86b43c00a6776 | https://github.com/bheisig/cli/blob/ee77266e173335950357899cdfe86b43c00a6776/src/App.php#L798-L821 | train |
bheisig/cli | src/App.php | App.loadComposerFile | protected function loadComposerFile() {
$composerFile = $this->config['appDir'] . '/composer.json';
if (!is_readable($composerFile)) {
throw new Exception(sprintf(
'Composer file "%s" is missing or not readable',
$composerFile
), ExitApp::RUNTIME_ERROR);
}
$this->config['composer'] = JSONFile::read($composerFile);
if (!array_key_exists('extra', $this->config['composer']) ||
!is_array($this->config['composer']['extra'])) {
throw new Exception(sprintf(
'Missing "extra" in composer file "%s"',
$composerFile
), ExitApp::RUNTIME_ERROR);
}
$keys = [
'name',
'version'
];
foreach ($keys as $key) {
if (!array_key_exists($key, $this->config['composer']['extra'])) {
throw new Exception(sprintf(
'Missing "extra.%s" in composer file "%s"',
$key,
$composerFile
), ExitApp::RUNTIME_ERROR);
}
}
return $this;
} | php | protected function loadComposerFile() {
$composerFile = $this->config['appDir'] . '/composer.json';
if (!is_readable($composerFile)) {
throw new Exception(sprintf(
'Composer file "%s" is missing or not readable',
$composerFile
), ExitApp::RUNTIME_ERROR);
}
$this->config['composer'] = JSONFile::read($composerFile);
if (!array_key_exists('extra', $this->config['composer']) ||
!is_array($this->config['composer']['extra'])) {
throw new Exception(sprintf(
'Missing "extra" in composer file "%s"',
$composerFile
), ExitApp::RUNTIME_ERROR);
}
$keys = [
'name',
'version'
];
foreach ($keys as $key) {
if (!array_key_exists($key, $this->config['composer']['extra'])) {
throw new Exception(sprintf(
'Missing "extra.%s" in composer file "%s"',
$key,
$composerFile
), ExitApp::RUNTIME_ERROR);
}
}
return $this;
} | [
"protected",
"function",
"loadComposerFile",
"(",
")",
"{",
"$",
"composerFile",
"=",
"$",
"this",
"->",
"config",
"[",
"'appDir'",
"]",
".",
"'/composer.json'",
";",
"if",
"(",
"!",
"is_readable",
"(",
"$",
"composerFile",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'Composer file \"%s\" is missing or not readable'",
",",
"$",
"composerFile",
")",
",",
"ExitApp",
"::",
"RUNTIME_ERROR",
")",
";",
"}",
"$",
"this",
"->",
"config",
"[",
"'composer'",
"]",
"=",
"JSONFile",
"::",
"read",
"(",
"$",
"composerFile",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"'extra'",
",",
"$",
"this",
"->",
"config",
"[",
"'composer'",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"this",
"->",
"config",
"[",
"'composer'",
"]",
"[",
"'extra'",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'Missing \"extra\" in composer file \"%s\"'",
",",
"$",
"composerFile",
")",
",",
"ExitApp",
"::",
"RUNTIME_ERROR",
")",
";",
"}",
"$",
"keys",
"=",
"[",
"'name'",
",",
"'version'",
"]",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"config",
"[",
"'composer'",
"]",
"[",
"'extra'",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'Missing \"extra.%s\" in composer file \"%s\"'",
",",
"$",
"key",
",",
"$",
"composerFile",
")",
",",
"ExitApp",
"::",
"RUNTIME_ERROR",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Parse composer.json
@return self Returns itself
@throws Exception on error | [
"Parse",
"composer",
".",
"json"
] | ee77266e173335950357899cdfe86b43c00a6776 | https://github.com/bheisig/cli/blob/ee77266e173335950357899cdfe86b43c00a6776/src/App.php#L830-L866 | train |
chalasr/RCHCapistranoBundle | Util/OutputWritableTrait.php | OutputWritableTrait.sayWelcome | public function sayWelcome(OutputInterface $output)
{
$breakline = '';
$output = $this->createBlockTitle($output);
$title = $this->formatAsTitle('RCHCapistranoBundle - Continuous Deployment');
$welcome = array(
$breakline,
$title,
$breakline,
'This bundle provides continuous deployment for Symfony2+ using <comment>Capistrano</comment>',
'Created by Robin Chalas - github.com/chalasr',
$breakline,
);
$output->writeln($welcome);
} | php | public function sayWelcome(OutputInterface $output)
{
$breakline = '';
$output = $this->createBlockTitle($output);
$title = $this->formatAsTitle('RCHCapistranoBundle - Continuous Deployment');
$welcome = array(
$breakline,
$title,
$breakline,
'This bundle provides continuous deployment for Symfony2+ using <comment>Capistrano</comment>',
'Created by Robin Chalas - github.com/chalasr',
$breakline,
);
$output->writeln($welcome);
} | [
"public",
"function",
"sayWelcome",
"(",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"breakline",
"=",
"''",
";",
"$",
"output",
"=",
"$",
"this",
"->",
"createBlockTitle",
"(",
"$",
"output",
")",
";",
"$",
"title",
"=",
"$",
"this",
"->",
"formatAsTitle",
"(",
"'RCHCapistranoBundle - Continuous Deployment'",
")",
";",
"$",
"welcome",
"=",
"array",
"(",
"$",
"breakline",
",",
"$",
"title",
",",
"$",
"breakline",
",",
"'This bundle provides continuous deployment for Symfony2+ using <comment>Capistrano</comment>'",
",",
"'Created by Robin Chalas - github.com/chalasr'",
",",
"$",
"breakline",
",",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"$",
"welcome",
")",
";",
"}"
] | Writes stylized welcome message in Output.
@param InputInterface $input
@param OutputInterface $output | [
"Writes",
"stylized",
"welcome",
"message",
"in",
"Output",
"."
] | c4a4cbaa2bc05f33bf431fd3afe6cac39947640e | https://github.com/chalasr/RCHCapistranoBundle/blob/c4a4cbaa2bc05f33bf431fd3afe6cac39947640e/Util/OutputWritableTrait.php#L30-L46 | train |
chalasr/RCHCapistranoBundle | Util/OutputWritableTrait.php | OutputWritableTrait.formatAsTitle | protected function formatAsTitle($content)
{
$formatter = $this->getHelper('formatter');
$title = $formatter->formatBlock($content, 'title', true);
return $title;
} | php | protected function formatAsTitle($content)
{
$formatter = $this->getHelper('formatter');
$title = $formatter->formatBlock($content, 'title', true);
return $title;
} | [
"protected",
"function",
"formatAsTitle",
"(",
"$",
"content",
")",
"{",
"$",
"formatter",
"=",
"$",
"this",
"->",
"getHelper",
"(",
"'formatter'",
")",
";",
"$",
"title",
"=",
"$",
"formatter",
"->",
"formatBlock",
"(",
"$",
"content",
",",
"'title'",
",",
"true",
")",
";",
"return",
"$",
"title",
";",
"}"
] | Formats string as output block title.
@param string $content
@return string | [
"Formats",
"string",
"as",
"output",
"block",
"title",
"."
] | c4a4cbaa2bc05f33bf431fd3afe6cac39947640e | https://github.com/chalasr/RCHCapistranoBundle/blob/c4a4cbaa2bc05f33bf431fd3afe6cac39947640e/Util/OutputWritableTrait.php#L63-L69 | train |
TypiCMS/Menulinks | src/Http/Controllers/AdminController.php | AdminController.show | public function show($menu = null, $model = null)
{
return Redirect::route('admin.menus.menulinks.edit', [$menu->id, $model->id]);
} | php | public function show($menu = null, $model = null)
{
return Redirect::route('admin.menus.menulinks.edit', [$menu->id, $model->id]);
} | [
"public",
"function",
"show",
"(",
"$",
"menu",
"=",
"null",
",",
"$",
"model",
"=",
"null",
")",
"{",
"return",
"Redirect",
"::",
"route",
"(",
"'admin.menus.menulinks.edit'",
",",
"[",
"$",
"menu",
"->",
"id",
",",
"$",
"model",
"->",
"id",
"]",
")",
";",
"}"
] | Show resource.
@param $menu
@param $model
@return Redirect | [
"Show",
"resource",
"."
] | 68e0a4067b6d04c8d9933cefacb09637e0d67ce1 | https://github.com/TypiCMS/Menulinks/blob/68e0a4067b6d04c8d9933cefacb09637e0d67ce1/src/Http/Controllers/AdminController.php#L56-L59 | train |
kreta/SimpleApiDocBundle | src/Kreta/SimpleApiDocBundle/Controller/ApiDocController.php | ApiDocController.indexAction | public function indexAction()
{
$extractedDoc = $this->get('kreta_simple_api_doc.extractor.api_doc_extractor')->all();
$htmlContent = $this->get('nelmio_api_doc.formatter.html_formatter')->format($extractedDoc);
return new Response($htmlContent, 200, ['Content-Type' => 'text/html']);
} | php | public function indexAction()
{
$extractedDoc = $this->get('kreta_simple_api_doc.extractor.api_doc_extractor')->all();
$htmlContent = $this->get('nelmio_api_doc.formatter.html_formatter')->format($extractedDoc);
return new Response($htmlContent, 200, ['Content-Type' => 'text/html']);
} | [
"public",
"function",
"indexAction",
"(",
")",
"{",
"$",
"extractedDoc",
"=",
"$",
"this",
"->",
"get",
"(",
"'kreta_simple_api_doc.extractor.api_doc_extractor'",
")",
"->",
"all",
"(",
")",
";",
"$",
"htmlContent",
"=",
"$",
"this",
"->",
"get",
"(",
"'nelmio_api_doc.formatter.html_formatter'",
")",
"->",
"format",
"(",
"$",
"extractedDoc",
")",
";",
"return",
"new",
"Response",
"(",
"$",
"htmlContent",
",",
"200",
",",
"[",
"'Content-Type'",
"=>",
"'text/html'",
"]",
")",
";",
"}"
] | The index action.
@return Response | [
"The",
"index",
"action",
"."
] | 786aa9310cdf087253f65f68165a0a0c8ad5c816 | https://github.com/kreta/SimpleApiDocBundle/blob/786aa9310cdf087253f65f68165a0a0c8ad5c816/src/Kreta/SimpleApiDocBundle/Controller/ApiDocController.php#L31-L37 | train |
nicodevs/laito | src/Laito/Router.php | Router.register | public function register($method, $path, $action, $filter = null)
{
// Add leading slash if not present
if (strncmp($path, '/', 1) !== 0) {
$path = '/' . $path;
}
// Add API base url to the path
$path = $this->app->config('url.root') . $path;
// Create arrays
$params = [];
$matches = [];
$method = strtolower($method);
// Replace placeholders
if (preg_match_all('/\{([\w-\.]+)\}/i', $path, $matches)) {
$params = end($matches);
}
$pattern = preg_replace(
['/(\{[\w-\.]+\})/i', '/\\//'],
['([\w-\.]+)', '\\/'],
$path
);
// Store in the routes array
return $this->routes[$method][$path] = [
'path' => $path,
'pattern' => '/^' . $pattern . '\\/?$/i',
'class' => $action[0],
'method' => $action[1],
'params' => $params,
'filter' => $filter
];
} | php | public function register($method, $path, $action, $filter = null)
{
// Add leading slash if not present
if (strncmp($path, '/', 1) !== 0) {
$path = '/' . $path;
}
// Add API base url to the path
$path = $this->app->config('url.root') . $path;
// Create arrays
$params = [];
$matches = [];
$method = strtolower($method);
// Replace placeholders
if (preg_match_all('/\{([\w-\.]+)\}/i', $path, $matches)) {
$params = end($matches);
}
$pattern = preg_replace(
['/(\{[\w-\.]+\})/i', '/\\//'],
['([\w-\.]+)', '\\/'],
$path
);
// Store in the routes array
return $this->routes[$method][$path] = [
'path' => $path,
'pattern' => '/^' . $pattern . '\\/?$/i',
'class' => $action[0],
'method' => $action[1],
'params' => $params,
'filter' => $filter
];
} | [
"public",
"function",
"register",
"(",
"$",
"method",
",",
"$",
"path",
",",
"$",
"action",
",",
"$",
"filter",
"=",
"null",
")",
"{",
"// Add leading slash if not present",
"if",
"(",
"strncmp",
"(",
"$",
"path",
",",
"'/'",
",",
"1",
")",
"!==",
"0",
")",
"{",
"$",
"path",
"=",
"'/'",
".",
"$",
"path",
";",
"}",
"// Add API base url to the path",
"$",
"path",
"=",
"$",
"this",
"->",
"app",
"->",
"config",
"(",
"'url.root'",
")",
".",
"$",
"path",
";",
"// Create arrays",
"$",
"params",
"=",
"[",
"]",
";",
"$",
"matches",
"=",
"[",
"]",
";",
"$",
"method",
"=",
"strtolower",
"(",
"$",
"method",
")",
";",
"// Replace placeholders",
"if",
"(",
"preg_match_all",
"(",
"'/\\{([\\w-\\.]+)\\}/i'",
",",
"$",
"path",
",",
"$",
"matches",
")",
")",
"{",
"$",
"params",
"=",
"end",
"(",
"$",
"matches",
")",
";",
"}",
"$",
"pattern",
"=",
"preg_replace",
"(",
"[",
"'/(\\{[\\w-\\.]+\\})/i'",
",",
"'/\\\\//'",
"]",
",",
"[",
"'([\\w-\\.]+)'",
",",
"'\\\\/'",
"]",
",",
"$",
"path",
")",
";",
"// Store in the routes array",
"return",
"$",
"this",
"->",
"routes",
"[",
"$",
"method",
"]",
"[",
"$",
"path",
"]",
"=",
"[",
"'path'",
"=>",
"$",
"path",
",",
"'pattern'",
"=>",
"'/^'",
".",
"$",
"pattern",
".",
"'\\\\/?$/i'",
",",
"'class'",
"=>",
"$",
"action",
"[",
"0",
"]",
",",
"'method'",
"=>",
"$",
"action",
"[",
"1",
"]",
",",
"'params'",
"=>",
"$",
"params",
",",
"'filter'",
"=>",
"$",
"filter",
"]",
";",
"}"
] | Register a url
@param string $method Method
@param string $path Route to match
@param array $action Controller and method to execute
@param array $filter Optional filter to execute
@return boolean Success or fail of registration | [
"Register",
"a",
"url"
] | d2d28abfcbf981c4decfec28ce94f8849600e9fe | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Router.php#L37-L71 | train |
nicodevs/laito | src/Laito/Router.php | Router.routes | public function routes($method = null)
{
if ($method && isset($this->methods[$method])) {
return $this->routes[$method];
}
return $this->routes;
} | php | public function routes($method = null)
{
if ($method && isset($this->methods[$method])) {
return $this->routes[$method];
}
return $this->routes;
} | [
"public",
"function",
"routes",
"(",
"$",
"method",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"method",
"&&",
"isset",
"(",
"$",
"this",
"->",
"methods",
"[",
"$",
"method",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"routes",
"[",
"$",
"method",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"routes",
";",
"}"
] | Retrieve registered routes
@param string $method (Optional) Method specific routes.
@return array Array of routes | [
"Retrieve",
"registered",
"routes"
] | d2d28abfcbf981c4decfec28ce94f8849600e9fe | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Router.php#L79-L85 | train |
nicodevs/laito | src/Laito/Router.php | Router.getAction | public function getAction($url)
{
// Current route holder
$current = false;
// Get requested method
$method = $this->app->request->method() ? : 'GET';
$method = strtolower($method);
// Check all routes until one matches
foreach ($this->routes[$method] as $route) {
$matches = [];
if (preg_match($route['pattern'], $url, $matches)) {
if (!empty($matches)) {
array_shift($matches);
$route['params'] = array_combine(
$route['params'],
$matches
);
}
$current = $route;
break;
}
}
// Abort if none of the routes matched
if (!$current) {
throw new \Exception('Route not found', 404);
}
// Return current route
return $current;
} | php | public function getAction($url)
{
// Current route holder
$current = false;
// Get requested method
$method = $this->app->request->method() ? : 'GET';
$method = strtolower($method);
// Check all routes until one matches
foreach ($this->routes[$method] as $route) {
$matches = [];
if (preg_match($route['pattern'], $url, $matches)) {
if (!empty($matches)) {
array_shift($matches);
$route['params'] = array_combine(
$route['params'],
$matches
);
}
$current = $route;
break;
}
}
// Abort if none of the routes matched
if (!$current) {
throw new \Exception('Route not found', 404);
}
// Return current route
return $current;
} | [
"public",
"function",
"getAction",
"(",
"$",
"url",
")",
"{",
"// Current route holder",
"$",
"current",
"=",
"false",
";",
"// Get requested method",
"$",
"method",
"=",
"$",
"this",
"->",
"app",
"->",
"request",
"->",
"method",
"(",
")",
"?",
":",
"'GET'",
";",
"$",
"method",
"=",
"strtolower",
"(",
"$",
"method",
")",
";",
"// Check all routes until one matches",
"foreach",
"(",
"$",
"this",
"->",
"routes",
"[",
"$",
"method",
"]",
"as",
"$",
"route",
")",
"{",
"$",
"matches",
"=",
"[",
"]",
";",
"if",
"(",
"preg_match",
"(",
"$",
"route",
"[",
"'pattern'",
"]",
",",
"$",
"url",
",",
"$",
"matches",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"matches",
")",
")",
"{",
"array_shift",
"(",
"$",
"matches",
")",
";",
"$",
"route",
"[",
"'params'",
"]",
"=",
"array_combine",
"(",
"$",
"route",
"[",
"'params'",
"]",
",",
"$",
"matches",
")",
";",
"}",
"$",
"current",
"=",
"$",
"route",
";",
"break",
";",
"}",
"}",
"// Abort if none of the routes matched",
"if",
"(",
"!",
"$",
"current",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Route not found'",
",",
"404",
")",
";",
"}",
"// Return current route",
"return",
"$",
"current",
";",
"}"
] | Retrieve model and method to execute
@param string $route Route to match
@return array Action and parameters | [
"Retrieve",
"model",
"and",
"method",
"to",
"execute"
] | d2d28abfcbf981c4decfec28ce94f8849600e9fe | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Router.php#L93-L125 | train |
nicodevs/laito | src/Laito/Router.php | Router.resource | public function resource($route, $controller, $filter = null)
{
$this->register('get', $route, [$controller, 'index'], $filter);
$this->register('get', $route . '/{id}', [$controller, 'show'], $filter);
$this->register('post', $route, [$controller, 'store'], $filter);
$this->register('put', $route . '/{id}', [$controller, 'update'], $filter);
$this->register('delete', $route . '/{id}', [$controller, 'destroy'], $filter);
return true;
} | php | public function resource($route, $controller, $filter = null)
{
$this->register('get', $route, [$controller, 'index'], $filter);
$this->register('get', $route . '/{id}', [$controller, 'show'], $filter);
$this->register('post', $route, [$controller, 'store'], $filter);
$this->register('put', $route . '/{id}', [$controller, 'update'], $filter);
$this->register('delete', $route . '/{id}', [$controller, 'destroy'], $filter);
return true;
} | [
"public",
"function",
"resource",
"(",
"$",
"route",
",",
"$",
"controller",
",",
"$",
"filter",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"register",
"(",
"'get'",
",",
"$",
"route",
",",
"[",
"$",
"controller",
",",
"'index'",
"]",
",",
"$",
"filter",
")",
";",
"$",
"this",
"->",
"register",
"(",
"'get'",
",",
"$",
"route",
".",
"'/{id}'",
",",
"[",
"$",
"controller",
",",
"'show'",
"]",
",",
"$",
"filter",
")",
";",
"$",
"this",
"->",
"register",
"(",
"'post'",
",",
"$",
"route",
",",
"[",
"$",
"controller",
",",
"'store'",
"]",
",",
"$",
"filter",
")",
";",
"$",
"this",
"->",
"register",
"(",
"'put'",
",",
"$",
"route",
".",
"'/{id}'",
",",
"[",
"$",
"controller",
",",
"'update'",
"]",
",",
"$",
"filter",
")",
";",
"$",
"this",
"->",
"register",
"(",
"'delete'",
",",
"$",
"route",
".",
"'/{id}'",
",",
"[",
"$",
"controller",
",",
"'destroy'",
"]",
",",
"$",
"filter",
")",
";",
"return",
"true",
";",
"}"
] | Register a resource
@param string $route Route for the resource
@param string $controller Controller name
@param string $filter Optional filter to execute
@return boolean Success or fail of registration | [
"Register",
"a",
"resource"
] | d2d28abfcbf981c4decfec28ce94f8849600e9fe | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Router.php#L135-L143 | train |
nicodevs/laito | src/Laito/Router.php | Router.getFilter | public function getFilter($filterName = null)
{
return isset($this->filters[$filterName])? $this->filters[$filterName] : false;
} | php | public function getFilter($filterName = null)
{
return isset($this->filters[$filterName])? $this->filters[$filterName] : false;
} | [
"public",
"function",
"getFilter",
"(",
"$",
"filterName",
"=",
"null",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"filters",
"[",
"$",
"filterName",
"]",
")",
"?",
"$",
"this",
"->",
"filters",
"[",
"$",
"filterName",
"]",
":",
"false",
";",
"}"
] | Returns a route filter
@param string $filterName Filter name
@return mixed Registered filter | [
"Returns",
"a",
"route",
"filter"
] | d2d28abfcbf981c4decfec28ce94f8849600e9fe | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Router.php#L163-L166 | train |
nicodevs/laito | src/Laito/Router.php | Router.performFilter | public function performFilter($filter)
{
$filter = $this->getFilter($filter);
if (!$filter) {
throw new \Exception('Filter not found', 500);
}
if ($filter instanceof \Closure) {
call_user_func($filter);
return $this->setAppliedFilter($filter);
}
if (is_array($filter)) {
list($class, $method) = $filter;
if (!class_exists($class)) {
throw new \Exception('Invalid filter class', 500);
}
$class = $this->app->make($class);
call_user_func([$class, $method]);
return $this->setAppliedFilter($filter);
}
throw new \Exception('Invalid filter', 500);
} | php | public function performFilter($filter)
{
$filter = $this->getFilter($filter);
if (!$filter) {
throw new \Exception('Filter not found', 500);
}
if ($filter instanceof \Closure) {
call_user_func($filter);
return $this->setAppliedFilter($filter);
}
if (is_array($filter)) {
list($class, $method) = $filter;
if (!class_exists($class)) {
throw new \Exception('Invalid filter class', 500);
}
$class = $this->app->make($class);
call_user_func([$class, $method]);
return $this->setAppliedFilter($filter);
}
throw new \Exception('Invalid filter', 500);
} | [
"public",
"function",
"performFilter",
"(",
"$",
"filter",
")",
"{",
"$",
"filter",
"=",
"$",
"this",
"->",
"getFilter",
"(",
"$",
"filter",
")",
";",
"if",
"(",
"!",
"$",
"filter",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Filter not found'",
",",
"500",
")",
";",
"}",
"if",
"(",
"$",
"filter",
"instanceof",
"\\",
"Closure",
")",
"{",
"call_user_func",
"(",
"$",
"filter",
")",
";",
"return",
"$",
"this",
"->",
"setAppliedFilter",
"(",
"$",
"filter",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"filter",
")",
")",
"{",
"list",
"(",
"$",
"class",
",",
"$",
"method",
")",
"=",
"$",
"filter",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Invalid filter class'",
",",
"500",
")",
";",
"}",
"$",
"class",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"$",
"class",
")",
";",
"call_user_func",
"(",
"[",
"$",
"class",
",",
"$",
"method",
"]",
")",
";",
"return",
"$",
"this",
"->",
"setAppliedFilter",
"(",
"$",
"filter",
")",
";",
"}",
"throw",
"new",
"\\",
"Exception",
"(",
"'Invalid filter'",
",",
"500",
")",
";",
"}"
] | Performs a filter
@param string $filter Filter name | [
"Performs",
"a",
"filter"
] | d2d28abfcbf981c4decfec28ce94f8849600e9fe | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Router.php#L195-L220 | train |
nicodevs/laito | src/Laito/Router.php | Router.group | public function group()
{
// Get arguments
if (func_num_args() === 2) {
list($prefix, $routes) = func_get_args();
$filter = null;
} elseif (func_num_args() === 3) {
list($filter, $prefix, $routes) = func_get_args();
}
// Add leading slash to prefix if not present
if (strncmp($prefix, '/', 1) !== 0) {
$prefix = '/' . $prefix;
}
// Add trailing slash to prefix if not present
if (substr($prefix, -1) !== '/') {
$prefix .= '/';
}
// Register routes
foreach ($routes as $route) {
$type = $route[0];
if ($type === 'resource') {
$this->resource($prefix . $route[1], $route[2], $filter);
} else {
$this->register($type, $prefix . $route[1], $route[2], $filter);
}
}
} | php | public function group()
{
// Get arguments
if (func_num_args() === 2) {
list($prefix, $routes) = func_get_args();
$filter = null;
} elseif (func_num_args() === 3) {
list($filter, $prefix, $routes) = func_get_args();
}
// Add leading slash to prefix if not present
if (strncmp($prefix, '/', 1) !== 0) {
$prefix = '/' . $prefix;
}
// Add trailing slash to prefix if not present
if (substr($prefix, -1) !== '/') {
$prefix .= '/';
}
// Register routes
foreach ($routes as $route) {
$type = $route[0];
if ($type === 'resource') {
$this->resource($prefix . $route[1], $route[2], $filter);
} else {
$this->register($type, $prefix . $route[1], $route[2], $filter);
}
}
} | [
"public",
"function",
"group",
"(",
")",
"{",
"// Get arguments",
"if",
"(",
"func_num_args",
"(",
")",
"===",
"2",
")",
"{",
"list",
"(",
"$",
"prefix",
",",
"$",
"routes",
")",
"=",
"func_get_args",
"(",
")",
";",
"$",
"filter",
"=",
"null",
";",
"}",
"elseif",
"(",
"func_num_args",
"(",
")",
"===",
"3",
")",
"{",
"list",
"(",
"$",
"filter",
",",
"$",
"prefix",
",",
"$",
"routes",
")",
"=",
"func_get_args",
"(",
")",
";",
"}",
"// Add leading slash to prefix if not present",
"if",
"(",
"strncmp",
"(",
"$",
"prefix",
",",
"'/'",
",",
"1",
")",
"!==",
"0",
")",
"{",
"$",
"prefix",
"=",
"'/'",
".",
"$",
"prefix",
";",
"}",
"// Add trailing slash to prefix if not present",
"if",
"(",
"substr",
"(",
"$",
"prefix",
",",
"-",
"1",
")",
"!==",
"'/'",
")",
"{",
"$",
"prefix",
".=",
"'/'",
";",
"}",
"// Register routes",
"foreach",
"(",
"$",
"routes",
"as",
"$",
"route",
")",
"{",
"$",
"type",
"=",
"$",
"route",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"type",
"===",
"'resource'",
")",
"{",
"$",
"this",
"->",
"resource",
"(",
"$",
"prefix",
".",
"$",
"route",
"[",
"1",
"]",
",",
"$",
"route",
"[",
"2",
"]",
",",
"$",
"filter",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"register",
"(",
"$",
"type",
",",
"$",
"prefix",
".",
"$",
"route",
"[",
"1",
"]",
",",
"$",
"route",
"[",
"2",
"]",
",",
"$",
"filter",
")",
";",
"}",
"}",
"}"
] | Register a group of routers with a common filter
@param string $filter Filter name
@param string $prefix Prefix for all routes
@param array $routers Routes | [
"Register",
"a",
"group",
"of",
"routers",
"with",
"a",
"common",
"filter"
] | d2d28abfcbf981c4decfec28ce94f8849600e9fe | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Router.php#L229-L258 | train |
judus/minimal-database | src/DB.php | DB.get | public static function get($name = 'default')
{
if (!isset(self::$connections[$name])) {
return null;
}
$connector = self::$connections[$name];
return $connector->connection();
} | php | public static function get($name = 'default')
{
if (!isset(self::$connections[$name])) {
return null;
}
$connector = self::$connections[$name];
return $connector->connection();
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"name",
"=",
"'default'",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"connections",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"connector",
"=",
"self",
"::",
"$",
"connections",
"[",
"$",
"name",
"]",
";",
"return",
"$",
"connector",
"->",
"connection",
"(",
")",
";",
"}"
] | Get a PDO-Connection
@param string $name
@return null | [
"Get",
"a",
"PDO",
"-",
"Connection"
] | e6f8cb46eab41c3f1b6cabe0da5ccd0926727279 | https://github.com/judus/minimal-database/blob/e6f8cb46eab41c3f1b6cabe0da5ccd0926727279/src/DB.php#L55-L64 | train |
WellCommerce/CategoryBundle | Twig/Extension/CategoryExtension.php | CategoryExtension.getCategoriesTree | public function getCategoriesTree($limit = 1000, $orderBy = 'hierarchy', $orderDir = 'asc')
{
return $this->dataset->getResult('tree', [
'limit' => $limit,
'order_by' => $orderBy,
'order_dir' => $orderDir
]);
} | php | public function getCategoriesTree($limit = 1000, $orderBy = 'hierarchy', $orderDir = 'asc')
{
return $this->dataset->getResult('tree', [
'limit' => $limit,
'order_by' => $orderBy,
'order_dir' => $orderDir
]);
} | [
"public",
"function",
"getCategoriesTree",
"(",
"$",
"limit",
"=",
"1000",
",",
"$",
"orderBy",
"=",
"'hierarchy'",
",",
"$",
"orderDir",
"=",
"'asc'",
")",
"{",
"return",
"$",
"this",
"->",
"dataset",
"->",
"getResult",
"(",
"'tree'",
",",
"[",
"'limit'",
"=>",
"$",
"limit",
",",
"'order_by'",
"=>",
"$",
"orderBy",
",",
"'order_dir'",
"=>",
"$",
"orderDir",
"]",
")",
";",
"}"
] | Returns categories tree
@param int $limit
@param string $orderBy
@param string $orderDir
@return array | [
"Returns",
"categories",
"tree"
] | 7a23ac678f91d15e86bdff624c4799be7b076e1a | https://github.com/WellCommerce/CategoryBundle/blob/7a23ac678f91d15e86bdff624c4799be7b076e1a/Twig/Extension/CategoryExtension.php#L62-L69 | train |
rzajac/phptools | src/Cli/Colors.php | Colors.getColoredString | public static function getColoredString($string, $foreground_color = '', $background_color = '')
{
$colored_string = '';
// Check if given foreground color exists
if (isset(static::$foreground_colors[$foreground_color])) {
$colored_string .= "\033[".static::$foreground_colors[$foreground_color].'m';
}
// Check if given background color exists
if (isset(static::$background_colors[$background_color])) {
$colored_string .= "\033[".static::$background_colors[$background_color].'m';
}
if ($colored_string) {
// Add string and end coloring
$colored_string .= $string."\033[0m";
} else {
$colored_string = $string;
}
return $colored_string;
} | php | public static function getColoredString($string, $foreground_color = '', $background_color = '')
{
$colored_string = '';
// Check if given foreground color exists
if (isset(static::$foreground_colors[$foreground_color])) {
$colored_string .= "\033[".static::$foreground_colors[$foreground_color].'m';
}
// Check if given background color exists
if (isset(static::$background_colors[$background_color])) {
$colored_string .= "\033[".static::$background_colors[$background_color].'m';
}
if ($colored_string) {
// Add string and end coloring
$colored_string .= $string."\033[0m";
} else {
$colored_string = $string;
}
return $colored_string;
} | [
"public",
"static",
"function",
"getColoredString",
"(",
"$",
"string",
",",
"$",
"foreground_color",
"=",
"''",
",",
"$",
"background_color",
"=",
"''",
")",
"{",
"$",
"colored_string",
"=",
"''",
";",
"// Check if given foreground color exists",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"foreground_colors",
"[",
"$",
"foreground_color",
"]",
")",
")",
"{",
"$",
"colored_string",
".=",
"\"\\033[\"",
".",
"static",
"::",
"$",
"foreground_colors",
"[",
"$",
"foreground_color",
"]",
".",
"'m'",
";",
"}",
"// Check if given background color exists",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"background_colors",
"[",
"$",
"background_color",
"]",
")",
")",
"{",
"$",
"colored_string",
".=",
"\"\\033[\"",
".",
"static",
"::",
"$",
"background_colors",
"[",
"$",
"background_color",
"]",
".",
"'m'",
";",
"}",
"if",
"(",
"$",
"colored_string",
")",
"{",
"// Add string and end coloring",
"$",
"colored_string",
".=",
"$",
"string",
".",
"\"\\033[0m\"",
";",
"}",
"else",
"{",
"$",
"colored_string",
"=",
"$",
"string",
";",
"}",
"return",
"$",
"colored_string",
";",
"}"
] | Returns colored string.
@param string $string The string to applu color to
@param string $foreground_color The foreground color
@param string $background_color The background color
@return string | [
"Returns",
"colored",
"string",
"."
] | 3cbece7645942d244603c14ba897d8a676ee3088 | https://github.com/rzajac/phptools/blob/3cbece7645942d244603c14ba897d8a676ee3088/src/Cli/Colors.php#L76-L98 | train |
gplcart/device | Main.php | Main.getDeviceType | public function getDeviceType()
{
$device = $this->session->get('device');
if (empty($device)) {
$detector = $this->getLibrary();
if ($detector->isMobile()) {
$device = 'mobile';
} else if ($detector->isTablet()) {
$device = 'tablet';
} else {
$device = 'desktop';
}
$this->session->set('device', $device);
}
return $device;
} | php | public function getDeviceType()
{
$device = $this->session->get('device');
if (empty($device)) {
$detector = $this->getLibrary();
if ($detector->isMobile()) {
$device = 'mobile';
} else if ($detector->isTablet()) {
$device = 'tablet';
} else {
$device = 'desktop';
}
$this->session->set('device', $device);
}
return $device;
} | [
"public",
"function",
"getDeviceType",
"(",
")",
"{",
"$",
"device",
"=",
"$",
"this",
"->",
"session",
"->",
"get",
"(",
"'device'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"device",
")",
")",
"{",
"$",
"detector",
"=",
"$",
"this",
"->",
"getLibrary",
"(",
")",
";",
"if",
"(",
"$",
"detector",
"->",
"isMobile",
"(",
")",
")",
"{",
"$",
"device",
"=",
"'mobile'",
";",
"}",
"else",
"if",
"(",
"$",
"detector",
"->",
"isTablet",
"(",
")",
")",
"{",
"$",
"device",
"=",
"'tablet'",
";",
"}",
"else",
"{",
"$",
"device",
"=",
"'desktop'",
";",
"}",
"$",
"this",
"->",
"session",
"->",
"set",
"(",
"'device'",
",",
"$",
"device",
")",
";",
"}",
"return",
"$",
"device",
";",
"}"
] | Returns a device type
@return string | [
"Returns",
"a",
"device",
"type"
] | 288fcbd50cc3a2c7aa74cc0c3410135dcc9b2881 | https://github.com/gplcart/device/blob/288fcbd50cc3a2c7aa74cc0c3410135dcc9b2881/Main.php#L100-L120 | train |
gplcart/device | Main.php | Main.switchTheme | protected function switchTheme(Controller $controller)
{
if (!$controller->isInternalRoute()) {
try {
$device = $this->getDeviceType();
$store_id = $controller->getStoreId();
$settings = $this->module->getSettings('device');
if (!$controller->isBackend() && $device !== 'desktop' && !empty($settings['theme'][$store_id][$device])) {
$theme = $settings['theme'][$store_id][$device];
if ($this->module->isEnabled($theme)) {
$controller->setCurrentTheme($theme);
}
}
} catch (Exception $ex) {
trigger_error($ex->getMessage());
}
}
} | php | protected function switchTheme(Controller $controller)
{
if (!$controller->isInternalRoute()) {
try {
$device = $this->getDeviceType();
$store_id = $controller->getStoreId();
$settings = $this->module->getSettings('device');
if (!$controller->isBackend() && $device !== 'desktop' && !empty($settings['theme'][$store_id][$device])) {
$theme = $settings['theme'][$store_id][$device];
if ($this->module->isEnabled($theme)) {
$controller->setCurrentTheme($theme);
}
}
} catch (Exception $ex) {
trigger_error($ex->getMessage());
}
}
} | [
"protected",
"function",
"switchTheme",
"(",
"Controller",
"$",
"controller",
")",
"{",
"if",
"(",
"!",
"$",
"controller",
"->",
"isInternalRoute",
"(",
")",
")",
"{",
"try",
"{",
"$",
"device",
"=",
"$",
"this",
"->",
"getDeviceType",
"(",
")",
";",
"$",
"store_id",
"=",
"$",
"controller",
"->",
"getStoreId",
"(",
")",
";",
"$",
"settings",
"=",
"$",
"this",
"->",
"module",
"->",
"getSettings",
"(",
"'device'",
")",
";",
"if",
"(",
"!",
"$",
"controller",
"->",
"isBackend",
"(",
")",
"&&",
"$",
"device",
"!==",
"'desktop'",
"&&",
"!",
"empty",
"(",
"$",
"settings",
"[",
"'theme'",
"]",
"[",
"$",
"store_id",
"]",
"[",
"$",
"device",
"]",
")",
")",
"{",
"$",
"theme",
"=",
"$",
"settings",
"[",
"'theme'",
"]",
"[",
"$",
"store_id",
"]",
"[",
"$",
"device",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"module",
"->",
"isEnabled",
"(",
"$",
"theme",
")",
")",
"{",
"$",
"controller",
"->",
"setCurrentTheme",
"(",
"$",
"theme",
")",
";",
"}",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"trigger_error",
"(",
"$",
"ex",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"}"
] | Switch the current theme
@param Controller $controller | [
"Switch",
"the",
"current",
"theme"
] | 288fcbd50cc3a2c7aa74cc0c3410135dcc9b2881 | https://github.com/gplcart/device/blob/288fcbd50cc3a2c7aa74cc0c3410135dcc9b2881/Main.php#L142-L163 | train |
lasallecms/lasallecms-l5-usermanagement-pkg | src/Helpers/NotifySuperAdministrators/EmailSuperAdministrators.php | EmailSuperAdministrators.sendEmailToSuperAdmins | public function sendEmailToSuperAdmins($subject, $event, $emailBladeFile) {
// Grab the super administrators who need to be notified from the config settting
$superAdminEmails = config('auth_frontend_registration_successful_admins_who_receive_notification_email');
// If there are no super administrators who are specified in the config setting, use the first-among-equals admin
if (count($superAdminEmails) == 0) {
$superAdminEmails[] = config('lasallecmsusermanagement.administrator_first_among_equals_email');
}
// create data array from the event DTO
$data = $event->data;
// Set the data needed to send the email
$data['subject'] = $subject;
$data['site_name'] = config('lasallecmsfrontend.site_name');
// data used in the body of the email, in the blade file
$data['data']['site_name'] = config('lasallecmsfrontend.site_name');
$data['data']['id'] = $event->data['id'];
// Send the notification email to each specified super administrator
foreach ($superAdminEmails as $superAdminEmail) {
// ensure that this email is a super admins
if (!$this->isSuperAdministrator($superAdminEmail)) {
continue;
}
// set the "to" email field
$data['to'] = $superAdminEmail;
Mail::queue($emailBladeFile, $data, function ($message) use ($data) {
$message->subject($data['subject'])
->to($data['to'])
;
});
}
} | php | public function sendEmailToSuperAdmins($subject, $event, $emailBladeFile) {
// Grab the super administrators who need to be notified from the config settting
$superAdminEmails = config('auth_frontend_registration_successful_admins_who_receive_notification_email');
// If there are no super administrators who are specified in the config setting, use the first-among-equals admin
if (count($superAdminEmails) == 0) {
$superAdminEmails[] = config('lasallecmsusermanagement.administrator_first_among_equals_email');
}
// create data array from the event DTO
$data = $event->data;
// Set the data needed to send the email
$data['subject'] = $subject;
$data['site_name'] = config('lasallecmsfrontend.site_name');
// data used in the body of the email, in the blade file
$data['data']['site_name'] = config('lasallecmsfrontend.site_name');
$data['data']['id'] = $event->data['id'];
// Send the notification email to each specified super administrator
foreach ($superAdminEmails as $superAdminEmail) {
// ensure that this email is a super admins
if (!$this->isSuperAdministrator($superAdminEmail)) {
continue;
}
// set the "to" email field
$data['to'] = $superAdminEmail;
Mail::queue($emailBladeFile, $data, function ($message) use ($data) {
$message->subject($data['subject'])
->to($data['to'])
;
});
}
} | [
"public",
"function",
"sendEmailToSuperAdmins",
"(",
"$",
"subject",
",",
"$",
"event",
",",
"$",
"emailBladeFile",
")",
"{",
"// Grab the super administrators who need to be notified from the config settting",
"$",
"superAdminEmails",
"=",
"config",
"(",
"'auth_frontend_registration_successful_admins_who_receive_notification_email'",
")",
";",
"// If there are no super administrators who are specified in the config setting, use the first-among-equals admin",
"if",
"(",
"count",
"(",
"$",
"superAdminEmails",
")",
"==",
"0",
")",
"{",
"$",
"superAdminEmails",
"[",
"]",
"=",
"config",
"(",
"'lasallecmsusermanagement.administrator_first_among_equals_email'",
")",
";",
"}",
"// create data array from the event DTO",
"$",
"data",
"=",
"$",
"event",
"->",
"data",
";",
"// Set the data needed to send the email",
"$",
"data",
"[",
"'subject'",
"]",
"=",
"$",
"subject",
";",
"$",
"data",
"[",
"'site_name'",
"]",
"=",
"config",
"(",
"'lasallecmsfrontend.site_name'",
")",
";",
"// data used in the body of the email, in the blade file",
"$",
"data",
"[",
"'data'",
"]",
"[",
"'site_name'",
"]",
"=",
"config",
"(",
"'lasallecmsfrontend.site_name'",
")",
";",
"$",
"data",
"[",
"'data'",
"]",
"[",
"'id'",
"]",
"=",
"$",
"event",
"->",
"data",
"[",
"'id'",
"]",
";",
"// Send the notification email to each specified super administrator",
"foreach",
"(",
"$",
"superAdminEmails",
"as",
"$",
"superAdminEmail",
")",
"{",
"// ensure that this email is a super admins",
"if",
"(",
"!",
"$",
"this",
"->",
"isSuperAdministrator",
"(",
"$",
"superAdminEmail",
")",
")",
"{",
"continue",
";",
"}",
"// set the \"to\" email field",
"$",
"data",
"[",
"'to'",
"]",
"=",
"$",
"superAdminEmail",
";",
"Mail",
"::",
"queue",
"(",
"$",
"emailBladeFile",
",",
"$",
"data",
",",
"function",
"(",
"$",
"message",
")",
"use",
"(",
"$",
"data",
")",
"{",
"$",
"message",
"->",
"subject",
"(",
"$",
"data",
"[",
"'subject'",
"]",
")",
"->",
"to",
"(",
"$",
"data",
"[",
"'to'",
"]",
")",
";",
"}",
")",
";",
"}",
"}"
] | Send email notifications to the super admins
@param text $subject Email subject
@param object $event Data object from event DTO
@param text $emailBladeFile Full package::path..blade.file
@return void | [
"Send",
"email",
"notifications",
"to",
"the",
"super",
"admins"
] | b5203d596e18e2566e7fdcd3f13868bb44a94c1d | https://github.com/lasallecms/lasallecms-l5-usermanagement-pkg/blob/b5203d596e18e2566e7fdcd3f13868bb44a94c1d/src/Helpers/NotifySuperAdministrators/EmailSuperAdministrators.php#L54-L92 | train |
lasallecms/lasallecms-l5-usermanagement-pkg | src/Helpers/NotifySuperAdministrators/EmailSuperAdministrators.php | EmailSuperAdministrators.isSuperAdministrator | public function isSuperAdministrator($email) {
// get the user id
$userId = $this->findUserIdByEmail($email);
// if there is no user ID for that email, then zero is returned
if ($userId == 0) {
return;
}
// does this user id belong to the usergroup "super administrator"
if ($this->isUserSuperAdministrator($userId)) {
return true;
}
return false;
} | php | public function isSuperAdministrator($email) {
// get the user id
$userId = $this->findUserIdByEmail($email);
// if there is no user ID for that email, then zero is returned
if ($userId == 0) {
return;
}
// does this user id belong to the usergroup "super administrator"
if ($this->isUserSuperAdministrator($userId)) {
return true;
}
return false;
} | [
"public",
"function",
"isSuperAdministrator",
"(",
"$",
"email",
")",
"{",
"// get the user id",
"$",
"userId",
"=",
"$",
"this",
"->",
"findUserIdByEmail",
"(",
"$",
"email",
")",
";",
"// if there is no user ID for that email, then zero is returned",
"if",
"(",
"$",
"userId",
"==",
"0",
")",
"{",
"return",
";",
"}",
"// does this user id belong to the usergroup \"super administrator\"",
"if",
"(",
"$",
"this",
"->",
"isUserSuperAdministrator",
"(",
"$",
"userId",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Does this email belong to a super administrator?
@param text $email
@return bool | [
"Does",
"this",
"email",
"belong",
"to",
"a",
"super",
"administrator?"
] | b5203d596e18e2566e7fdcd3f13868bb44a94c1d | https://github.com/lasallecms/lasallecms-l5-usermanagement-pkg/blob/b5203d596e18e2566e7fdcd3f13868bb44a94c1d/src/Helpers/NotifySuperAdministrators/EmailSuperAdministrators.php#L101-L118 | train |
lasallecms/lasallecms-l5-usermanagement-pkg | src/Helpers/NotifySuperAdministrators/EmailSuperAdministrators.php | EmailSuperAdministrators.findUserIdByEmail | public function findUserIdByEmail($email) {
$userId = DB::table('users')
->where('email', $email)
->value('id')
;
if (!$userId) {
return 0;
}
return $userId;
} | php | public function findUserIdByEmail($email) {
$userId = DB::table('users')
->where('email', $email)
->value('id')
;
if (!$userId) {
return 0;
}
return $userId;
} | [
"public",
"function",
"findUserIdByEmail",
"(",
"$",
"email",
")",
"{",
"$",
"userId",
"=",
"DB",
"::",
"table",
"(",
"'users'",
")",
"->",
"where",
"(",
"'email'",
",",
"$",
"email",
")",
"->",
"value",
"(",
"'id'",
")",
";",
"if",
"(",
"!",
"$",
"userId",
")",
"{",
"return",
"0",
";",
"}",
"return",
"$",
"userId",
";",
"}"
] | Find the user's ID from their email address.
Return 0 if no ID is found.
@param string $email
@return int | [
"Find",
"the",
"user",
"s",
"ID",
"from",
"their",
"email",
"address",
"."
] | b5203d596e18e2566e7fdcd3f13868bb44a94c1d | https://github.com/lasallecms/lasallecms-l5-usermanagement-pkg/blob/b5203d596e18e2566e7fdcd3f13868bb44a94c1d/src/Helpers/NotifySuperAdministrators/EmailSuperAdministrators.php#L133-L144 | train |
lasallecms/lasallecms-l5-usermanagement-pkg | src/Helpers/NotifySuperAdministrators/EmailSuperAdministrators.php | EmailSuperAdministrators.isUserSuperAdministrator | public function isUserSuperAdministrator($userId) {
$result = DB::table('user_group')
->where('user_id', $userId)
->where('group_id', 3)
->first()
;
if (!$result) {
return false;
}
return true;
} | php | public function isUserSuperAdministrator($userId) {
$result = DB::table('user_group')
->where('user_id', $userId)
->where('group_id', 3)
->first()
;
if (!$result) {
return false;
}
return true;
} | [
"public",
"function",
"isUserSuperAdministrator",
"(",
"$",
"userId",
")",
"{",
"$",
"result",
"=",
"DB",
"::",
"table",
"(",
"'user_group'",
")",
"->",
"where",
"(",
"'user_id'",
",",
"$",
"userId",
")",
"->",
"where",
"(",
"'group_id'",
",",
"3",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Does the user belong to the Super Administrator user group?
It is assumed that Super Administrator is ID=3 in the groups database table.
@param int $userId
@return bool | [
"Does",
"the",
"user",
"belong",
"to",
"the",
"Super",
"Administrator",
"user",
"group?"
] | b5203d596e18e2566e7fdcd3f13868bb44a94c1d | https://github.com/lasallecms/lasallecms-l5-usermanagement-pkg/blob/b5203d596e18e2566e7fdcd3f13868bb44a94c1d/src/Helpers/NotifySuperAdministrators/EmailSuperAdministrators.php#L154-L166 | train |
martinlindhe/php-debughelper | src/Logger.php | Logger.dbgTime | public static function dbgTime($s)
{
if (getenv('DEBUG') == '1') {
self::printMessage('<' . Carbon::now()->toTimeString() . '> ' . self::withCallsite($s), 'comment');
}
} | php | public static function dbgTime($s)
{
if (getenv('DEBUG') == '1') {
self::printMessage('<' . Carbon::now()->toTimeString() . '> ' . self::withCallsite($s), 'comment');
}
} | [
"public",
"static",
"function",
"dbgTime",
"(",
"$",
"s",
")",
"{",
"if",
"(",
"getenv",
"(",
"'DEBUG'",
")",
"==",
"'1'",
")",
"{",
"self",
"::",
"printMessage",
"(",
"'<'",
".",
"Carbon",
"::",
"now",
"(",
")",
"->",
"toTimeString",
"(",
")",
".",
"'> '",
".",
"self",
"::",
"withCallsite",
"(",
"$",
"s",
")",
",",
"'comment'",
")",
";",
"}",
"}"
] | Yellow text with current time
@param string $s | [
"Yellow",
"text",
"with",
"current",
"time"
] | 8fde5bbfd77d71f3f0990829f235242232094734 | https://github.com/martinlindhe/php-debughelper/blob/8fde5bbfd77d71f3f0990829f235242232094734/src/Logger.php#L46-L51 | train |
martinlindhe/php-debughelper | src/Logger.php | Logger.nfoTime | public static function nfoTime($s)
{
self::printMessage('<' . Carbon::now()->toTimeString() . '> ' . self::withCallsite($s), 'info');
} | php | public static function nfoTime($s)
{
self::printMessage('<' . Carbon::now()->toTimeString() . '> ' . self::withCallsite($s), 'info');
} | [
"public",
"static",
"function",
"nfoTime",
"(",
"$",
"s",
")",
"{",
"self",
"::",
"printMessage",
"(",
"'<'",
".",
"Carbon",
"::",
"now",
"(",
")",
"->",
"toTimeString",
"(",
")",
".",
"'> '",
".",
"self",
"::",
"withCallsite",
"(",
"$",
"s",
")",
",",
"'info'",
")",
";",
"}"
] | Green text with current time
@param string $s | [
"Green",
"text",
"with",
"current",
"time"
] | 8fde5bbfd77d71f3f0990829f235242232094734 | https://github.com/martinlindhe/php-debughelper/blob/8fde5bbfd77d71f3f0990829f235242232094734/src/Logger.php#L57-L60 | train |
martinlindhe/php-debughelper | src/Logger.php | Logger.errTime | public static function errTime($s)
{
self::printMessage('<' . Carbon::now()->toTimeString() . '> ' . self::withCallsite($s), 'error');
} | php | public static function errTime($s)
{
self::printMessage('<' . Carbon::now()->toTimeString() . '> ' . self::withCallsite($s), 'error');
} | [
"public",
"static",
"function",
"errTime",
"(",
"$",
"s",
")",
"{",
"self",
"::",
"printMessage",
"(",
"'<'",
".",
"Carbon",
"::",
"now",
"(",
")",
"->",
"toTimeString",
"(",
")",
".",
"'> '",
".",
"self",
"::",
"withCallsite",
"(",
"$",
"s",
")",
",",
"'error'",
")",
";",
"}"
] | White text on red background with current time
@param string $s | [
"White",
"text",
"on",
"red",
"background",
"with",
"current",
"time"
] | 8fde5bbfd77d71f3f0990829f235242232094734 | https://github.com/martinlindhe/php-debughelper/blob/8fde5bbfd77d71f3f0990829f235242232094734/src/Logger.php#L66-L69 | train |
dmitrya2e/filtration-bundle | Filter/Executor/FilterExecutor.php | FilterExecutor.registerHandler | public function registerHandler($handler, $type = false)
{
if (!is_object($handler)) {
throw new FilterExecutorException('Handler must be an object.');
}
if ($type === false) {
// Try to guess handler type by class FQN.
$type = $this->guessHandlerType($handler);
if ($type === false) {
throw new FilterExecutorException('Could not guess handler type. Please, provide the type for the handler manually.');
}
}
if (!array_key_exists($type, $this->availableHandlerTypes)) {
throw new FilterExecutorException(sprintf(
'Handler type "%s" is not allowed (available handler types: [%s]).',
$type, implode(', ', array_keys($this->availableHandlerTypes))
));
}
if (!array_key_exists($type, $this->registeredHandlers)) {
$this->registeredHandlers[$type] = $handler;
}
return $this;
} | php | public function registerHandler($handler, $type = false)
{
if (!is_object($handler)) {
throw new FilterExecutorException('Handler must be an object.');
}
if ($type === false) {
// Try to guess handler type by class FQN.
$type = $this->guessHandlerType($handler);
if ($type === false) {
throw new FilterExecutorException('Could not guess handler type. Please, provide the type for the handler manually.');
}
}
if (!array_key_exists($type, $this->availableHandlerTypes)) {
throw new FilterExecutorException(sprintf(
'Handler type "%s" is not allowed (available handler types: [%s]).',
$type, implode(', ', array_keys($this->availableHandlerTypes))
));
}
if (!array_key_exists($type, $this->registeredHandlers)) {
$this->registeredHandlers[$type] = $handler;
}
return $this;
} | [
"public",
"function",
"registerHandler",
"(",
"$",
"handler",
",",
"$",
"type",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"handler",
")",
")",
"{",
"throw",
"new",
"FilterExecutorException",
"(",
"'Handler must be an object.'",
")",
";",
"}",
"if",
"(",
"$",
"type",
"===",
"false",
")",
"{",
"// Try to guess handler type by class FQN.",
"$",
"type",
"=",
"$",
"this",
"->",
"guessHandlerType",
"(",
"$",
"handler",
")",
";",
"if",
"(",
"$",
"type",
"===",
"false",
")",
"{",
"throw",
"new",
"FilterExecutorException",
"(",
"'Could not guess handler type. Please, provide the type for the handler manually.'",
")",
";",
"}",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"availableHandlerTypes",
")",
")",
"{",
"throw",
"new",
"FilterExecutorException",
"(",
"sprintf",
"(",
"'Handler type \"%s\" is not allowed (available handler types: [%s]).'",
",",
"$",
"type",
",",
"implode",
"(",
"', '",
",",
"array_keys",
"(",
"$",
"this",
"->",
"availableHandlerTypes",
")",
")",
")",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"registeredHandlers",
")",
")",
"{",
"$",
"this",
"->",
"registeredHandlers",
"[",
"$",
"type",
"]",
"=",
"$",
"handler",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Registers specific filtration handler.
@param object|mixed $handler Any supported resource, which can handle filtration (QueryBuilder, ...)
@param string|bool $type The type of the handler
@return static
@throws FilterExecutorException on handler errors | [
"Registers",
"specific",
"filtration",
"handler",
"."
] | fed5764af4e43871835744fb84957b2a76e9a215 | https://github.com/dmitrya2e/filtration-bundle/blob/fed5764af4e43871835744fb84957b2a76e9a215/Filter/Executor/FilterExecutor.php#L83-L110 | train |
dmitrya2e/filtration-bundle | Filter/Executor/FilterExecutor.php | FilterExecutor.registerHandlers | public function registerHandlers(array $handlers)
{
foreach ($handlers as $type => $handler) {
if (!is_string($type)) {
// Probably, non-string $type is a numeric index, which means,
// that the handler array was defined as [ $handler1, $handler2, ... ] without handler types.
// So try to guess the type.
$type = $this->guessHandlerType($handler);
}
$this->registerHandler($handler, $type);
}
return $this;
} | php | public function registerHandlers(array $handlers)
{
foreach ($handlers as $type => $handler) {
if (!is_string($type)) {
// Probably, non-string $type is a numeric index, which means,
// that the handler array was defined as [ $handler1, $handler2, ... ] without handler types.
// So try to guess the type.
$type = $this->guessHandlerType($handler);
}
$this->registerHandler($handler, $type);
}
return $this;
} | [
"public",
"function",
"registerHandlers",
"(",
"array",
"$",
"handlers",
")",
"{",
"foreach",
"(",
"$",
"handlers",
"as",
"$",
"type",
"=>",
"$",
"handler",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"type",
")",
")",
"{",
"// Probably, non-string $type is a numeric index, which means,",
"// that the handler array was defined as [ $handler1, $handler2, ... ] without handler types.",
"// So try to guess the type.",
"$",
"type",
"=",
"$",
"this",
"->",
"guessHandlerType",
"(",
"$",
"handler",
")",
";",
"}",
"$",
"this",
"->",
"registerHandler",
"(",
"$",
"handler",
",",
"$",
"type",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Registers different filtration handlers.
@param array|object[]|mixed[] $handlers
@return static | [
"Registers",
"different",
"filtration",
"handlers",
"."
] | fed5764af4e43871835744fb84957b2a76e9a215 | https://github.com/dmitrya2e/filtration-bundle/blob/fed5764af4e43871835744fb84957b2a76e9a215/Filter/Executor/FilterExecutor.php#L119-L133 | train |
dmitrya2e/filtration-bundle | Filter/Executor/FilterExecutor.php | FilterExecutor.applyFilter | protected function applyFilter(FilterInterface $filter, $handler)
{
if (!($filter instanceof CustomApplyFilterInterface) || !is_callable($filter->getApplyFilterFunction())) {
return $filter->applyFilter($handler);
}
return call_user_func($filter->getApplyFilterFunction(), $filter, $handler);
} | php | protected function applyFilter(FilterInterface $filter, $handler)
{
if (!($filter instanceof CustomApplyFilterInterface) || !is_callable($filter->getApplyFilterFunction())) {
return $filter->applyFilter($handler);
}
return call_user_func($filter->getApplyFilterFunction(), $filter, $handler);
} | [
"protected",
"function",
"applyFilter",
"(",
"FilterInterface",
"$",
"filter",
",",
"$",
"handler",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"filter",
"instanceof",
"CustomApplyFilterInterface",
")",
"||",
"!",
"is_callable",
"(",
"$",
"filter",
"->",
"getApplyFilterFunction",
"(",
")",
")",
")",
"{",
"return",
"$",
"filter",
"->",
"applyFilter",
"(",
"$",
"handler",
")",
";",
"}",
"return",
"call_user_func",
"(",
"$",
"filter",
"->",
"getApplyFilterFunction",
"(",
")",
",",
"$",
"filter",
",",
"$",
"handler",
")",
";",
"}"
] | Applies filtration.
If the filter has custom function for filtration applying, than it will be used.
@param FilterInterface|CustomApplyFilterInterface $filter
@param object|mixed $handler Any supported resource, which can handle filtration
@return static | [
"Applies",
"filtration",
".",
"If",
"the",
"filter",
"has",
"custom",
"function",
"for",
"filtration",
"applying",
"than",
"it",
"will",
"be",
"used",
"."
] | fed5764af4e43871835744fb84957b2a76e9a215 | https://github.com/dmitrya2e/filtration-bundle/blob/fed5764af4e43871835744fb84957b2a76e9a215/Filter/Executor/FilterExecutor.php#L144-L151 | train |
dmitrya2e/filtration-bundle | Filter/Executor/FilterExecutor.php | FilterExecutor.guessHandlerType | protected function guessHandlerType($handler)
{
if (!is_object($handler)) {
return false;
}
foreach ($this->availableHandlerTypes as $type => $classFQN) {
if ($handler instanceof $classFQN) {
return $type;
}
}
return false;
} | php | protected function guessHandlerType($handler)
{
if (!is_object($handler)) {
return false;
}
foreach ($this->availableHandlerTypes as $type => $classFQN) {
if ($handler instanceof $classFQN) {
return $type;
}
}
return false;
} | [
"protected",
"function",
"guessHandlerType",
"(",
"$",
"handler",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"handler",
")",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"availableHandlerTypes",
"as",
"$",
"type",
"=>",
"$",
"classFQN",
")",
"{",
"if",
"(",
"$",
"handler",
"instanceof",
"$",
"classFQN",
")",
"{",
"return",
"$",
"type",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Guesses handler type by handler object class FQN.
Basically, it checks if the handler class name exists in the available handler types.
@param object|mixed $handler Any supported resource, which can handle filtration
@return false|string False if the type can not be guessed | [
"Guesses",
"handler",
"type",
"by",
"handler",
"object",
"class",
"FQN",
".",
"Basically",
"it",
"checks",
"if",
"the",
"handler",
"class",
"name",
"exists",
"in",
"the",
"available",
"handler",
"types",
"."
] | fed5764af4e43871835744fb84957b2a76e9a215 | https://github.com/dmitrya2e/filtration-bundle/blob/fed5764af4e43871835744fb84957b2a76e9a215/Filter/Executor/FilterExecutor.php#L161-L174 | train |
Aviogram/Common | src/Plugin/PluginTrait.php | PluginTrait.getPluginClassByName | protected function getPluginClassByName($name)
{
if (array_key_exists($name, $this->plugins) === false) {
return false;
}
return $this->plugins[$name];
} | php | protected function getPluginClassByName($name)
{
if (array_key_exists($name, $this->plugins) === false) {
return false;
}
return $this->plugins[$name];
} | [
"protected",
"function",
"getPluginClassByName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"plugins",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"plugins",
"[",
"$",
"name",
"]",
";",
"}"
] | Returns the class name for the given name
@param string $name
@return string | boolean FALSE when the name could not be found | [
"Returns",
"the",
"class",
"name",
"for",
"the",
"given",
"name"
] | bcff2e409cccd4791a3f9bca0b2cdd70c25ddec5 | https://github.com/Aviogram/Common/blob/bcff2e409cccd4791a3f9bca0b2cdd70c25ddec5/src/Plugin/PluginTrait.php#L29-L36 | train |
Aviogram/Common | src/Plugin/PluginTrait.php | PluginTrait.getPlugin | protected function getPlugin($name, callable $constructClosure = null)
{
static $cache = array();
// Check if the plugin is already constructed
if (array_key_exists($name, $cache) === true) {
return $cache[$name];
}
// Fetch the full className
$class = $this->getPluginClassByName($name);
if ($class === false) {
throw new Exception\PluginNotFound("Plugin with name `{$name}` does not exists");
}
// Check if the plugin is in the correct instance
if ($this->isCorrectPlugin($class) === false) {
throw new Exception\PluginNotCreated("Plugin with name `{$name}` does not exists");
}
// No closure given we just construct the class
if ($constructClosure === null) {
return $cache[$name] = new $class();
}
$object = $constructClosure($class);
if (is_object($object) === false) {
throw new Exception\PluginNotCreated(
"Plugin with name `{$name}` could not be created, because callable did not return an object."
);
}
return $cache[$name] = $object;
} | php | protected function getPlugin($name, callable $constructClosure = null)
{
static $cache = array();
// Check if the plugin is already constructed
if (array_key_exists($name, $cache) === true) {
return $cache[$name];
}
// Fetch the full className
$class = $this->getPluginClassByName($name);
if ($class === false) {
throw new Exception\PluginNotFound("Plugin with name `{$name}` does not exists");
}
// Check if the plugin is in the correct instance
if ($this->isCorrectPlugin($class) === false) {
throw new Exception\PluginNotCreated("Plugin with name `{$name}` does not exists");
}
// No closure given we just construct the class
if ($constructClosure === null) {
return $cache[$name] = new $class();
}
$object = $constructClosure($class);
if (is_object($object) === false) {
throw new Exception\PluginNotCreated(
"Plugin with name `{$name}` could not be created, because callable did not return an object."
);
}
return $cache[$name] = $object;
} | [
"protected",
"function",
"getPlugin",
"(",
"$",
"name",
",",
"callable",
"$",
"constructClosure",
"=",
"null",
")",
"{",
"static",
"$",
"cache",
"=",
"array",
"(",
")",
";",
"// Check if the plugin is already constructed\r",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"cache",
")",
"===",
"true",
")",
"{",
"return",
"$",
"cache",
"[",
"$",
"name",
"]",
";",
"}",
"// Fetch the full className\r",
"$",
"class",
"=",
"$",
"this",
"->",
"getPluginClassByName",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"class",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"PluginNotFound",
"(",
"\"Plugin with name `{$name}` does not exists\"",
")",
";",
"}",
"// Check if the plugin is in the correct instance\r",
"if",
"(",
"$",
"this",
"->",
"isCorrectPlugin",
"(",
"$",
"class",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"PluginNotCreated",
"(",
"\"Plugin with name `{$name}` does not exists\"",
")",
";",
"}",
"// No closure given we just construct the class\r",
"if",
"(",
"$",
"constructClosure",
"===",
"null",
")",
"{",
"return",
"$",
"cache",
"[",
"$",
"name",
"]",
"=",
"new",
"$",
"class",
"(",
")",
";",
"}",
"$",
"object",
"=",
"$",
"constructClosure",
"(",
"$",
"class",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"object",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"PluginNotCreated",
"(",
"\"Plugin with name `{$name}` could not be created, because callable did not return an object.\"",
")",
";",
"}",
"return",
"$",
"cache",
"[",
"$",
"name",
"]",
"=",
"$",
"object",
";",
"}"
] | Method for fetching a singleton instance of a plugin
@param string $name
@param callable $constructClosure
@return object | [
"Method",
"for",
"fetching",
"a",
"singleton",
"instance",
"of",
"a",
"plugin"
] | bcff2e409cccd4791a3f9bca0b2cdd70c25ddec5 | https://github.com/Aviogram/Common/blob/bcff2e409cccd4791a3f9bca0b2cdd70c25ddec5/src/Plugin/PluginTrait.php#L46-L80 | train |
danielgp/bank-holidays | source/Romanian.php | Romanian.readTypeFromJsonFileUniversal | protected function readTypeFromJsonFileUniversal($filePath, $fileBaseName)
{
$fName = $filePath . DIRECTORY_SEPARATOR . $fileBaseName . '.min.json';
$fJson = fopen($fName, 'r');
$jSonContent = fread($fJson, filesize($fName));
fclose($fJson);
return json_decode($jSonContent, true);
} | php | protected function readTypeFromJsonFileUniversal($filePath, $fileBaseName)
{
$fName = $filePath . DIRECTORY_SEPARATOR . $fileBaseName . '.min.json';
$fJson = fopen($fName, 'r');
$jSonContent = fread($fJson, filesize($fName));
fclose($fJson);
return json_decode($jSonContent, true);
} | [
"protected",
"function",
"readTypeFromJsonFileUniversal",
"(",
"$",
"filePath",
",",
"$",
"fileBaseName",
")",
"{",
"$",
"fName",
"=",
"$",
"filePath",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"fileBaseName",
".",
"'.min.json'",
";",
"$",
"fJson",
"=",
"fopen",
"(",
"$",
"fName",
",",
"'r'",
")",
";",
"$",
"jSonContent",
"=",
"fread",
"(",
"$",
"fJson",
",",
"filesize",
"(",
"$",
"fName",
")",
")",
";",
"fclose",
"(",
"$",
"fJson",
")",
";",
"return",
"json_decode",
"(",
"$",
"jSonContent",
",",
"true",
")",
";",
"}"
] | returns an array with non-standard holidays from a JSON file
@param string $fileBaseName
@return mixed | [
"returns",
"an",
"array",
"with",
"non",
"-",
"standard",
"holidays",
"from",
"a",
"JSON",
"file"
] | edebfd9d99b836aaff80887442f9a28ee988850b | https://github.com/danielgp/bank-holidays/blob/edebfd9d99b836aaff80887442f9a28ee988850b/source/Romanian.php#L57-L64 | train |
danielgp/bank-holidays | source/Romanian.php | Romanian.setHolidays | public function setHolidays(\DateTime $lngDate, $inclCatholicEaster = false, $inclWorkingHolidays = false)
{
$givenYear = $lngDate->format('Y');
$daying = array_merge($this->setHolidaysOrthodoxEaster($lngDate), $this->setHolidaysFixed($lngDate));
if ($inclWorkingHolidays) {
$daying = array_merge($daying, $this->setHolidaysFixedButWorking($lngDate));
}
if ($inclCatholicEaster) { // Catholic easter is already known by PHP
$firstEasterDate = strtotime($this->getEasterDatetime($givenYear)->format('Y-m-d'));
$secondEasterDate = strtotime('+1 day', $firstEasterDate);
$daying = array_merge($daying, [
$firstEasterDate,
$secondEasterDate,
]);
}
sort($daying);
return array_unique($daying); // remove duplicate for when catholic and orthodox easter match
} | php | public function setHolidays(\DateTime $lngDate, $inclCatholicEaster = false, $inclWorkingHolidays = false)
{
$givenYear = $lngDate->format('Y');
$daying = array_merge($this->setHolidaysOrthodoxEaster($lngDate), $this->setHolidaysFixed($lngDate));
if ($inclWorkingHolidays) {
$daying = array_merge($daying, $this->setHolidaysFixedButWorking($lngDate));
}
if ($inclCatholicEaster) { // Catholic easter is already known by PHP
$firstEasterDate = strtotime($this->getEasterDatetime($givenYear)->format('Y-m-d'));
$secondEasterDate = strtotime('+1 day', $firstEasterDate);
$daying = array_merge($daying, [
$firstEasterDate,
$secondEasterDate,
]);
}
sort($daying);
return array_unique($daying); // remove duplicate for when catholic and orthodox easter match
} | [
"public",
"function",
"setHolidays",
"(",
"\\",
"DateTime",
"$",
"lngDate",
",",
"$",
"inclCatholicEaster",
"=",
"false",
",",
"$",
"inclWorkingHolidays",
"=",
"false",
")",
"{",
"$",
"givenYear",
"=",
"$",
"lngDate",
"->",
"format",
"(",
"'Y'",
")",
";",
"$",
"daying",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"setHolidaysOrthodoxEaster",
"(",
"$",
"lngDate",
")",
",",
"$",
"this",
"->",
"setHolidaysFixed",
"(",
"$",
"lngDate",
")",
")",
";",
"if",
"(",
"$",
"inclWorkingHolidays",
")",
"{",
"$",
"daying",
"=",
"array_merge",
"(",
"$",
"daying",
",",
"$",
"this",
"->",
"setHolidaysFixedButWorking",
"(",
"$",
"lngDate",
")",
")",
";",
"}",
"if",
"(",
"$",
"inclCatholicEaster",
")",
"{",
"// Catholic easter is already known by PHP",
"$",
"firstEasterDate",
"=",
"strtotime",
"(",
"$",
"this",
"->",
"getEasterDatetime",
"(",
"$",
"givenYear",
")",
"->",
"format",
"(",
"'Y-m-d'",
")",
")",
";",
"$",
"secondEasterDate",
"=",
"strtotime",
"(",
"'+1 day'",
",",
"$",
"firstEasterDate",
")",
";",
"$",
"daying",
"=",
"array_merge",
"(",
"$",
"daying",
",",
"[",
"$",
"firstEasterDate",
",",
"$",
"secondEasterDate",
",",
"]",
")",
";",
"}",
"sort",
"(",
"$",
"daying",
")",
";",
"return",
"array_unique",
"(",
"$",
"daying",
")",
";",
"// remove duplicate for when catholic and orthodox easter match",
"}"
] | List of legal holidays
@param \DateTime $lngDate
@param boolean $inclCatholicEaster
@return array | [
"List",
"of",
"legal",
"holidays"
] | edebfd9d99b836aaff80887442f9a28ee988850b | https://github.com/danielgp/bank-holidays/blob/edebfd9d99b836aaff80887442f9a28ee988850b/source/Romanian.php#L73-L90 | train |
danielgp/bank-holidays | source/Romanian.php | Romanian.setHolidaysOrthodoxEaster | private function setHolidaysOrthodoxEaster(\DateTime $lngDate)
{
$givenYear = $lngDate->format('Y');
$daying = [];
$configPath = __DIR__ . DIRECTORY_SEPARATOR . 'json';
$statmentsArray = $this->readTypeFromJsonFileUniversal($configPath, 'RomanianBankHolidays');
if (array_key_exists($givenYear, $statmentsArray)) {
foreach ($statmentsArray[$givenYear] as $value) {
$daying[] = strtotime($value);
}
}
return $daying;
} | php | private function setHolidaysOrthodoxEaster(\DateTime $lngDate)
{
$givenYear = $lngDate->format('Y');
$daying = [];
$configPath = __DIR__ . DIRECTORY_SEPARATOR . 'json';
$statmentsArray = $this->readTypeFromJsonFileUniversal($configPath, 'RomanianBankHolidays');
if (array_key_exists($givenYear, $statmentsArray)) {
foreach ($statmentsArray[$givenYear] as $value) {
$daying[] = strtotime($value);
}
}
return $daying;
} | [
"private",
"function",
"setHolidaysOrthodoxEaster",
"(",
"\\",
"DateTime",
"$",
"lngDate",
")",
"{",
"$",
"givenYear",
"=",
"$",
"lngDate",
"->",
"format",
"(",
"'Y'",
")",
";",
"$",
"daying",
"=",
"[",
"]",
";",
"$",
"configPath",
"=",
"__DIR__",
".",
"DIRECTORY_SEPARATOR",
".",
"'json'",
";",
"$",
"statmentsArray",
"=",
"$",
"this",
"->",
"readTypeFromJsonFileUniversal",
"(",
"$",
"configPath",
",",
"'RomanianBankHolidays'",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"givenYear",
",",
"$",
"statmentsArray",
")",
")",
"{",
"foreach",
"(",
"$",
"statmentsArray",
"[",
"$",
"givenYear",
"]",
"as",
"$",
"value",
")",
"{",
"$",
"daying",
"[",
"]",
"=",
"strtotime",
"(",
"$",
"value",
")",
";",
"}",
"}",
"return",
"$",
"daying",
";",
"}"
] | List of all Orthodox holidays and Pentecost
@param \DateTime $lngDate
@return array | [
"List",
"of",
"all",
"Orthodox",
"holidays",
"and",
"Pentecost"
] | edebfd9d99b836aaff80887442f9a28ee988850b | https://github.com/danielgp/bank-holidays/blob/edebfd9d99b836aaff80887442f9a28ee988850b/source/Romanian.php#L166-L178 | train |
danielgp/bank-holidays | source/Romanian.php | Romanian.setHolidaysInMonth | public function setHolidaysInMonth(\DateTime $lngDate, $inclCatholicEaster = false)
{
$holidaysInGivenYear = $this->setHolidays($lngDate, $inclCatholicEaster);
$thisMonthDayArray = $this->setMonthAllDaysIntoArray($lngDate);
$holidays = 0;
foreach ($thisMonthDayArray as $value) {
if (in_array($value, $holidaysInGivenYear)) {
$holidays += 1;
}
}
return $holidays;
} | php | public function setHolidaysInMonth(\DateTime $lngDate, $inclCatholicEaster = false)
{
$holidaysInGivenYear = $this->setHolidays($lngDate, $inclCatholicEaster);
$thisMonthDayArray = $this->setMonthAllDaysIntoArray($lngDate);
$holidays = 0;
foreach ($thisMonthDayArray as $value) {
if (in_array($value, $holidaysInGivenYear)) {
$holidays += 1;
}
}
return $holidays;
} | [
"public",
"function",
"setHolidaysInMonth",
"(",
"\\",
"DateTime",
"$",
"lngDate",
",",
"$",
"inclCatholicEaster",
"=",
"false",
")",
"{",
"$",
"holidaysInGivenYear",
"=",
"$",
"this",
"->",
"setHolidays",
"(",
"$",
"lngDate",
",",
"$",
"inclCatholicEaster",
")",
";",
"$",
"thisMonthDayArray",
"=",
"$",
"this",
"->",
"setMonthAllDaysIntoArray",
"(",
"$",
"lngDate",
")",
";",
"$",
"holidays",
"=",
"0",
";",
"foreach",
"(",
"$",
"thisMonthDayArray",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"value",
",",
"$",
"holidaysInGivenYear",
")",
")",
"{",
"$",
"holidays",
"+=",
"1",
";",
"}",
"}",
"return",
"$",
"holidays",
";",
"}"
] | returns bank holidays in a given month
@param \DateTime $lngDate
@param boolean $inclCatholicEaster
@return int | [
"returns",
"bank",
"holidays",
"in",
"a",
"given",
"month"
] | edebfd9d99b836aaff80887442f9a28ee988850b | https://github.com/danielgp/bank-holidays/blob/edebfd9d99b836aaff80887442f9a28ee988850b/source/Romanian.php#L187-L198 | train |
danielgp/bank-holidays | source/Romanian.php | Romanian.setMonthAllDaysIntoArray | protected function setMonthAllDaysIntoArray(\DateTime $lngDate)
{
$firstDayGivenMonth = strtotime($lngDate->modify('first day of this month')->format('Y-m-d'));
$lastDayInGivenMonth = strtotime($lngDate->modify('last day of this month')->format('Y-m-d'));
$secondsInOneDay = 24 * 60 * 60;
return range($firstDayGivenMonth, $lastDayInGivenMonth, $secondsInOneDay);
} | php | protected function setMonthAllDaysIntoArray(\DateTime $lngDate)
{
$firstDayGivenMonth = strtotime($lngDate->modify('first day of this month')->format('Y-m-d'));
$lastDayInGivenMonth = strtotime($lngDate->modify('last day of this month')->format('Y-m-d'));
$secondsInOneDay = 24 * 60 * 60;
return range($firstDayGivenMonth, $lastDayInGivenMonth, $secondsInOneDay);
} | [
"protected",
"function",
"setMonthAllDaysIntoArray",
"(",
"\\",
"DateTime",
"$",
"lngDate",
")",
"{",
"$",
"firstDayGivenMonth",
"=",
"strtotime",
"(",
"$",
"lngDate",
"->",
"modify",
"(",
"'first day of this month'",
")",
"->",
"format",
"(",
"'Y-m-d'",
")",
")",
";",
"$",
"lastDayInGivenMonth",
"=",
"strtotime",
"(",
"$",
"lngDate",
"->",
"modify",
"(",
"'last day of this month'",
")",
"->",
"format",
"(",
"'Y-m-d'",
")",
")",
";",
"$",
"secondsInOneDay",
"=",
"24",
"*",
"60",
"*",
"60",
";",
"return",
"range",
"(",
"$",
"firstDayGivenMonth",
",",
"$",
"lastDayInGivenMonth",
",",
"$",
"secondsInOneDay",
")",
";",
"}"
] | return an array with all days within a month from a given date
@param \DateTime $lngDate
@return array | [
"return",
"an",
"array",
"with",
"all",
"days",
"within",
"a",
"month",
"from",
"a",
"given",
"date"
] | edebfd9d99b836aaff80887442f9a28ee988850b | https://github.com/danielgp/bank-holidays/blob/edebfd9d99b836aaff80887442f9a28ee988850b/source/Romanian.php#L206-L212 | train |
danielgp/bank-holidays | source/Romanian.php | Romanian.setWorkingDaysInMonth | public function setWorkingDaysInMonth(\DateTime $lngDate, $inclCatholicEaster = false)
{
$holidaysInGivenYear = $this->setHolidays($lngDate, $inclCatholicEaster);
$thisMonthDayArray = $this->setMonthAllDaysIntoArray($lngDate);
$workingDays = 0;
foreach ($thisMonthDayArray as $value) {
if (!in_array(strftime('%w', $value), [0, 6]) && !in_array($value, $holidaysInGivenYear)) {
$workingDays += 1;
}
}
return $workingDays;
} | php | public function setWorkingDaysInMonth(\DateTime $lngDate, $inclCatholicEaster = false)
{
$holidaysInGivenYear = $this->setHolidays($lngDate, $inclCatholicEaster);
$thisMonthDayArray = $this->setMonthAllDaysIntoArray($lngDate);
$workingDays = 0;
foreach ($thisMonthDayArray as $value) {
if (!in_array(strftime('%w', $value), [0, 6]) && !in_array($value, $holidaysInGivenYear)) {
$workingDays += 1;
}
}
return $workingDays;
} | [
"public",
"function",
"setWorkingDaysInMonth",
"(",
"\\",
"DateTime",
"$",
"lngDate",
",",
"$",
"inclCatholicEaster",
"=",
"false",
")",
"{",
"$",
"holidaysInGivenYear",
"=",
"$",
"this",
"->",
"setHolidays",
"(",
"$",
"lngDate",
",",
"$",
"inclCatholicEaster",
")",
";",
"$",
"thisMonthDayArray",
"=",
"$",
"this",
"->",
"setMonthAllDaysIntoArray",
"(",
"$",
"lngDate",
")",
";",
"$",
"workingDays",
"=",
"0",
";",
"foreach",
"(",
"$",
"thisMonthDayArray",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"strftime",
"(",
"'%w'",
",",
"$",
"value",
")",
",",
"[",
"0",
",",
"6",
"]",
")",
"&&",
"!",
"in_array",
"(",
"$",
"value",
",",
"$",
"holidaysInGivenYear",
")",
")",
"{",
"$",
"workingDays",
"+=",
"1",
";",
"}",
"}",
"return",
"$",
"workingDays",
";",
"}"
] | returns working days in a given month
@param \DateTime $lngDate
@param boolean $inclCatholicEaster
@return int | [
"returns",
"working",
"days",
"in",
"a",
"given",
"month"
] | edebfd9d99b836aaff80887442f9a28ee988850b | https://github.com/danielgp/bank-holidays/blob/edebfd9d99b836aaff80887442f9a28ee988850b/source/Romanian.php#L221-L232 | train |
romm/configuration_object | Classes/Legacy/Reflection/ReflectionService.php | ReflectionService.setDataCache | public function setDataCache(\TYPO3\CMS\Core\Cache\Frontend\VariableFrontend $dataCache)
{
$this->dataCache = $dataCache;
} | php | public function setDataCache(\TYPO3\CMS\Core\Cache\Frontend\VariableFrontend $dataCache)
{
$this->dataCache = $dataCache;
} | [
"public",
"function",
"setDataCache",
"(",
"\\",
"TYPO3",
"\\",
"CMS",
"\\",
"Core",
"\\",
"Cache",
"\\",
"Frontend",
"\\",
"VariableFrontend",
"$",
"dataCache",
")",
"{",
"$",
"this",
"->",
"dataCache",
"=",
"$",
"dataCache",
";",
"}"
] | Sets the data cache.
The cache must be set before initializing the Reflection Service.
@param \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend $dataCache Cache for the Reflection service | [
"Sets",
"the",
"data",
"cache",
"."
] | d3a40903386c2e0766bd8279337fe6da45cf5ce3 | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Legacy/Reflection/ReflectionService.php#L177-L180 | train |
romm/configuration_object | Classes/Legacy/Reflection/ReflectionService.php | ReflectionService.initialize | public function initialize()
{
if ($this->initialized) {
throw new Exception('The Reflection Service can only be initialized once.', 1232044696);
}
$frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
$this->cacheIdentifier = 'ReflectionData_' . $frameworkConfiguration['extensionName'];
$this->loadFromCache();
$this->initialized = true;
} | php | public function initialize()
{
if ($this->initialized) {
throw new Exception('The Reflection Service can only be initialized once.', 1232044696);
}
$frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
$this->cacheIdentifier = 'ReflectionData_' . $frameworkConfiguration['extensionName'];
$this->loadFromCache();
$this->initialized = true;
} | [
"public",
"function",
"initialize",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"initialized",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'The Reflection Service can only be initialized once.'",
",",
"1232044696",
")",
";",
"}",
"$",
"frameworkConfiguration",
"=",
"$",
"this",
"->",
"configurationManager",
"->",
"getConfiguration",
"(",
"\\",
"TYPO3",
"\\",
"CMS",
"\\",
"Extbase",
"\\",
"Configuration",
"\\",
"ConfigurationManagerInterface",
"::",
"CONFIGURATION_TYPE_FRAMEWORK",
")",
";",
"$",
"this",
"->",
"cacheIdentifier",
"=",
"'ReflectionData_'",
".",
"$",
"frameworkConfiguration",
"[",
"'extensionName'",
"]",
";",
"$",
"this",
"->",
"loadFromCache",
"(",
")",
";",
"$",
"this",
"->",
"initialized",
"=",
"true",
";",
"}"
] | Initializes this service
@throws Exception | [
"Initializes",
"this",
"service"
] | d3a40903386c2e0766bd8279337fe6da45cf5ce3 | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Legacy/Reflection/ReflectionService.php#L187-L196 | train |
romm/configuration_object | Classes/Legacy/Reflection/ReflectionService.php | ReflectionService.getClassTagsValues | public function getClassTagsValues($className)
{
if (!isset($this->reflectedClassNames[$className])) {
$this->reflectClass($className);
}
if (!isset($this->classTagsValues[$className])) {
return [];
}
return isset($this->classTagsValues[$className]) ? $this->classTagsValues[$className] : [];
} | php | public function getClassTagsValues($className)
{
if (!isset($this->reflectedClassNames[$className])) {
$this->reflectClass($className);
}
if (!isset($this->classTagsValues[$className])) {
return [];
}
return isset($this->classTagsValues[$className]) ? $this->classTagsValues[$className] : [];
} | [
"public",
"function",
"getClassTagsValues",
"(",
"$",
"className",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"reflectedClassNames",
"[",
"$",
"className",
"]",
")",
")",
"{",
"$",
"this",
"->",
"reflectClass",
"(",
"$",
"className",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"classTagsValues",
"[",
"$",
"className",
"]",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"classTagsValues",
"[",
"$",
"className",
"]",
")",
"?",
"$",
"this",
"->",
"classTagsValues",
"[",
"$",
"className",
"]",
":",
"[",
"]",
";",
"}"
] | Returns all tags and their values the specified class is tagged with
@param string $className Name of the class
@return array An array of tags and their values or an empty array if no tags were found | [
"Returns",
"all",
"tags",
"and",
"their",
"values",
"the",
"specified",
"class",
"is",
"tagged",
"with"
] | d3a40903386c2e0766bd8279337fe6da45cf5ce3 | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Legacy/Reflection/ReflectionService.php#L225-L234 | train |
romm/configuration_object | Classes/Legacy/Reflection/ReflectionService.php | ReflectionService.getClassTagValues | public function getClassTagValues($className, $tag)
{
if (!isset($this->reflectedClassNames[$className])) {
$this->reflectClass($className);
}
if (!isset($this->classTagsValues[$className])) {
return [];
}
return isset($this->classTagsValues[$className][$tag]) ? $this->classTagsValues[$className][$tag] : [];
} | php | public function getClassTagValues($className, $tag)
{
if (!isset($this->reflectedClassNames[$className])) {
$this->reflectClass($className);
}
if (!isset($this->classTagsValues[$className])) {
return [];
}
return isset($this->classTagsValues[$className][$tag]) ? $this->classTagsValues[$className][$tag] : [];
} | [
"public",
"function",
"getClassTagValues",
"(",
"$",
"className",
",",
"$",
"tag",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"reflectedClassNames",
"[",
"$",
"className",
"]",
")",
")",
"{",
"$",
"this",
"->",
"reflectClass",
"(",
"$",
"className",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"classTagsValues",
"[",
"$",
"className",
"]",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"classTagsValues",
"[",
"$",
"className",
"]",
"[",
"$",
"tag",
"]",
")",
"?",
"$",
"this",
"->",
"classTagsValues",
"[",
"$",
"className",
"]",
"[",
"$",
"tag",
"]",
":",
"[",
"]",
";",
"}"
] | Returns the values of the specified class tag
@param string $className Name of the class containing the property
@param string $tag Tag to return the values of
@return array An array of values or an empty array if the tag was not found | [
"Returns",
"the",
"values",
"of",
"the",
"specified",
"class",
"tag"
] | d3a40903386c2e0766bd8279337fe6da45cf5ce3 | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Legacy/Reflection/ReflectionService.php#L243-L252 | train |
romm/configuration_object | Classes/Legacy/Reflection/ReflectionService.php | ReflectionService.isClassTaggedWith | public function isClassTaggedWith($className, $tag)
{
if ($this->initialized === false) {
return false;
}
if (!isset($this->reflectedClassNames[$className])) {
$this->reflectClass($className);
}
if (!isset($this->classTagsValues[$className])) {
return false;
}
return isset($this->classTagsValues[$className][$tag]);
} | php | public function isClassTaggedWith($className, $tag)
{
if ($this->initialized === false) {
return false;
}
if (!isset($this->reflectedClassNames[$className])) {
$this->reflectClass($className);
}
if (!isset($this->classTagsValues[$className])) {
return false;
}
return isset($this->classTagsValues[$className][$tag]);
} | [
"public",
"function",
"isClassTaggedWith",
"(",
"$",
"className",
",",
"$",
"tag",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"initialized",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"reflectedClassNames",
"[",
"$",
"className",
"]",
")",
")",
"{",
"$",
"this",
"->",
"reflectClass",
"(",
"$",
"className",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"classTagsValues",
"[",
"$",
"className",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"classTagsValues",
"[",
"$",
"className",
"]",
"[",
"$",
"tag",
"]",
")",
";",
"}"
] | Tells if the specified class is tagged with the given tag
@param string $className Name of the class
@param string $tag Tag to check for
@return bool TRUE if the class is tagged with $tag, otherwise FALSE | [
"Tells",
"if",
"the",
"specified",
"class",
"is",
"tagged",
"with",
"the",
"given",
"tag"
] | d3a40903386c2e0766bd8279337fe6da45cf5ce3 | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Legacy/Reflection/ReflectionService.php#L401-L413 | train |
romm/configuration_object | Classes/Legacy/Reflection/ReflectionService.php | ReflectionService.getMethodReflection | protected function getMethodReflection($className, $methodName)
{
$this->dataCacheNeedsUpdate = true;
if (!isset($this->methodReflections[$className][$methodName])) {
$this->methodReflections[$className][$methodName] = new MethodReflection($className, $methodName);
}
return $this->methodReflections[$className][$methodName];
} | php | protected function getMethodReflection($className, $methodName)
{
$this->dataCacheNeedsUpdate = true;
if (!isset($this->methodReflections[$className][$methodName])) {
$this->methodReflections[$className][$methodName] = new MethodReflection($className, $methodName);
}
return $this->methodReflections[$className][$methodName];
} | [
"protected",
"function",
"getMethodReflection",
"(",
"$",
"className",
",",
"$",
"methodName",
")",
"{",
"$",
"this",
"->",
"dataCacheNeedsUpdate",
"=",
"true",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"methodReflections",
"[",
"$",
"className",
"]",
"[",
"$",
"methodName",
"]",
")",
")",
"{",
"$",
"this",
"->",
"methodReflections",
"[",
"$",
"className",
"]",
"[",
"$",
"methodName",
"]",
"=",
"new",
"MethodReflection",
"(",
"$",
"className",
",",
"$",
"methodName",
")",
";",
"}",
"return",
"$",
"this",
"->",
"methodReflections",
"[",
"$",
"className",
"]",
"[",
"$",
"methodName",
"]",
";",
"}"
] | Returns the Reflection of a method.
@param string $className Name of the class containing the method
@param string $methodName Name of the method to return the Reflection for
@return MethodReflection the method Reflection object | [
"Returns",
"the",
"Reflection",
"of",
"a",
"method",
"."
] | d3a40903386c2e0766bd8279337fe6da45cf5ce3 | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Legacy/Reflection/ReflectionService.php#L568-L575 | train |
romm/configuration_object | Classes/Legacy/Reflection/ReflectionService.php | ReflectionService.loadFromCache | protected function loadFromCache()
{
$data = $this->dataCache->get($this->cacheIdentifier);
if ($data !== false) {
foreach ($data as $propertyName => $propertyValue) {
$this->{$propertyName} = $propertyValue;
}
}
} | php | protected function loadFromCache()
{
$data = $this->dataCache->get($this->cacheIdentifier);
if ($data !== false) {
foreach ($data as $propertyName => $propertyValue) {
$this->{$propertyName} = $propertyValue;
}
}
} | [
"protected",
"function",
"loadFromCache",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"dataCache",
"->",
"get",
"(",
"$",
"this",
"->",
"cacheIdentifier",
")",
";",
"if",
"(",
"$",
"data",
"!==",
"false",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"propertyName",
"=>",
"$",
"propertyValue",
")",
"{",
"$",
"this",
"->",
"{",
"$",
"propertyName",
"}",
"=",
"$",
"propertyValue",
";",
"}",
"}",
"}"
] | Tries to load the reflection data from this service's cache. | [
"Tries",
"to",
"load",
"the",
"reflection",
"data",
"from",
"this",
"service",
"s",
"cache",
"."
] | d3a40903386c2e0766bd8279337fe6da45cf5ce3 | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Legacy/Reflection/ReflectionService.php#L580-L588 | train |
romm/configuration_object | Classes/Legacy/Reflection/ReflectionService.php | ReflectionService.saveToCache | protected function saveToCache()
{
if (!is_object($this->dataCache)) {
throw new Exception('A cache must be injected before initializing the Reflection Service.', 1232044697);
}
$data = [];
$propertyNames = [
'reflectedClassNames',
'classPropertyNames',
'classMethodNames',
'classTagsValues',
'methodTagsValues',
'methodParameters',
'propertyTagsValues',
'taggedClasses',
'classSchemata'
];
foreach ($propertyNames as $propertyName) {
$data[$propertyName] = $this->{$propertyName};
}
$this->dataCache->set($this->cacheIdentifier, $data);
$this->dataCacheNeedsUpdate = false;
} | php | protected function saveToCache()
{
if (!is_object($this->dataCache)) {
throw new Exception('A cache must be injected before initializing the Reflection Service.', 1232044697);
}
$data = [];
$propertyNames = [
'reflectedClassNames',
'classPropertyNames',
'classMethodNames',
'classTagsValues',
'methodTagsValues',
'methodParameters',
'propertyTagsValues',
'taggedClasses',
'classSchemata'
];
foreach ($propertyNames as $propertyName) {
$data[$propertyName] = $this->{$propertyName};
}
$this->dataCache->set($this->cacheIdentifier, $data);
$this->dataCacheNeedsUpdate = false;
} | [
"protected",
"function",
"saveToCache",
"(",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"this",
"->",
"dataCache",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'A cache must be injected before initializing the Reflection Service.'",
",",
"1232044697",
")",
";",
"}",
"$",
"data",
"=",
"[",
"]",
";",
"$",
"propertyNames",
"=",
"[",
"'reflectedClassNames'",
",",
"'classPropertyNames'",
",",
"'classMethodNames'",
",",
"'classTagsValues'",
",",
"'methodTagsValues'",
",",
"'methodParameters'",
",",
"'propertyTagsValues'",
",",
"'taggedClasses'",
",",
"'classSchemata'",
"]",
";",
"foreach",
"(",
"$",
"propertyNames",
"as",
"$",
"propertyName",
")",
"{",
"$",
"data",
"[",
"$",
"propertyName",
"]",
"=",
"$",
"this",
"->",
"{",
"$",
"propertyName",
"}",
";",
"}",
"$",
"this",
"->",
"dataCache",
"->",
"set",
"(",
"$",
"this",
"->",
"cacheIdentifier",
",",
"$",
"data",
")",
";",
"$",
"this",
"->",
"dataCacheNeedsUpdate",
"=",
"false",
";",
"}"
] | Exports the internal reflection data into the ReflectionData cache.
@throws Exception | [
"Exports",
"the",
"internal",
"reflection",
"data",
"into",
"the",
"ReflectionData",
"cache",
"."
] | d3a40903386c2e0766bd8279337fe6da45cf5ce3 | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Legacy/Reflection/ReflectionService.php#L595-L617 | train |
geoffadams/bedrest-core | library/BedRest/Service/Mapping/ServiceMetadata.php | ServiceMetadata.addListener | public function addListener($event, $method)
{
if (!isset($this->listeners[$event])) {
$this->listeners[$event] = array();
}
$this->listeners[$event][] = $method;
} | php | public function addListener($event, $method)
{
if (!isset($this->listeners[$event])) {
$this->listeners[$event] = array();
}
$this->listeners[$event][] = $method;
} | [
"public",
"function",
"addListener",
"(",
"$",
"event",
",",
"$",
"method",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"listeners",
"[",
"$",
"event",
"]",
")",
")",
"{",
"$",
"this",
"->",
"listeners",
"[",
"$",
"event",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"this",
"->",
"listeners",
"[",
"$",
"event",
"]",
"[",
"]",
"=",
"$",
"method",
";",
"}"
] | Adds a listener for the specified event.
@param string $event
@param string $method | [
"Adds",
"a",
"listener",
"for",
"the",
"specified",
"event",
"."
] | a77bf8b7492dfbfb720b201f7ec91a4f03417b5c | https://github.com/geoffadams/bedrest-core/blob/a77bf8b7492dfbfb720b201f7ec91a4f03417b5c/library/BedRest/Service/Mapping/ServiceMetadata.php#L76-L83 | train |
t3v/t3v_core | Classes/Validation/Validator/AbstractValidator.php | AbstractValidator.addErrorToProperty | protected function addErrorToProperty(string $property, string $key, string $extensionName) {
$errorMessage = LocalizationUtility::translate($key, $extensionName);
$error = $this->objectManager->get(Error::class, $errorMessage, time());
$this->result->forProperty($property)->addError($error);
} | php | protected function addErrorToProperty(string $property, string $key, string $extensionName) {
$errorMessage = LocalizationUtility::translate($key, $extensionName);
$error = $this->objectManager->get(Error::class, $errorMessage, time());
$this->result->forProperty($property)->addError($error);
} | [
"protected",
"function",
"addErrorToProperty",
"(",
"string",
"$",
"property",
",",
"string",
"$",
"key",
",",
"string",
"$",
"extensionName",
")",
"{",
"$",
"errorMessage",
"=",
"LocalizationUtility",
"::",
"translate",
"(",
"$",
"key",
",",
"$",
"extensionName",
")",
";",
"$",
"error",
"=",
"$",
"this",
"->",
"objectManager",
"->",
"get",
"(",
"Error",
"::",
"class",
",",
"$",
"errorMessage",
",",
"time",
"(",
")",
")",
";",
"$",
"this",
"->",
"result",
"->",
"forProperty",
"(",
"$",
"property",
")",
"->",
"addError",
"(",
"$",
"error",
")",
";",
"}"
] | Adds an error to a property.
@param string $property The property
@param string $key The key to reference the error
@param string $extensionName The extension name | [
"Adds",
"an",
"error",
"to",
"a",
"property",
"."
] | 8c04b7688cc2773f11fcc87fda3f7cd53d80a980 | https://github.com/t3v/t3v_core/blob/8c04b7688cc2773f11fcc87fda3f7cd53d80a980/Classes/Validation/Validator/AbstractValidator.php#L30-L35 | train |
Vectrex/vxPHP | src/Template/Filter/AnchorHref.php | AnchorHref.filterHrefWithPath | private function filterHrefWithPath($matches) {
static $script;
static $observeRewrite;
static $config;
static $assetsPath;
if(is_null($config)) {
$application = Application::getInstance();
$config = $application->getConfig();
$observeRewrite = $application->getRouter()->getServerSideRewrite();
}
if(is_null($script)) {
$script = basename(trim(Request::createFromGlobals()->getScriptName(), '/'));
}
$matchSegments = explode('/', $matches[3]);
$pathToFind = array_shift($matchSegments);
$recursiveFind = function(Menu $m) use (&$recursiveFind, $pathToFind) {
foreach($m->getEntries() as $e) {
if($e->getPath() === $pathToFind) {
return $e;
}
if(($sm = $e->getSubMenu()) && $sm->getType() !== 'dynamic') {
if($e = $recursiveFind($sm)) {
return $e;
}
}
}
};
foreach($config->menus as $menu) {
if($menu->getScript() === $script) {
if(($e = $recursiveFind($menu))) {
break;
}
}
}
if(isset($e)) {
$pathSegments = [$e->getPath()];
while($e = $e->getMenu()->getParentEntry()) {
$pathSegments[] = $e->getPath();
}
$uriParts = [];
if($observeRewrite) {
if($script !== 'index.php') {
$uriParts[] = basename($script, '.php');
}
}
else {
if(is_null($assetsPath)) {
$assetsPath = Application::getInstance()->getRelativeAssetsPath();
}
$uriParts[] = ltrim($assetsPath, '/') . $script;
}
if(count($pathSegments)) {
$uriParts[] = implode('/', array_reverse($pathSegments));
}
if(count($matchSegments)) {
$uriParts[] = implode('/', $matchSegments);
}
$uri = implode('/', $uriParts) . $matches[4];
return "<a{$matches[1]} href={$matches[2]}/$uri{$matches[2]}{$matches[5]}>";
}
} | php | private function filterHrefWithPath($matches) {
static $script;
static $observeRewrite;
static $config;
static $assetsPath;
if(is_null($config)) {
$application = Application::getInstance();
$config = $application->getConfig();
$observeRewrite = $application->getRouter()->getServerSideRewrite();
}
if(is_null($script)) {
$script = basename(trim(Request::createFromGlobals()->getScriptName(), '/'));
}
$matchSegments = explode('/', $matches[3]);
$pathToFind = array_shift($matchSegments);
$recursiveFind = function(Menu $m) use (&$recursiveFind, $pathToFind) {
foreach($m->getEntries() as $e) {
if($e->getPath() === $pathToFind) {
return $e;
}
if(($sm = $e->getSubMenu()) && $sm->getType() !== 'dynamic') {
if($e = $recursiveFind($sm)) {
return $e;
}
}
}
};
foreach($config->menus as $menu) {
if($menu->getScript() === $script) {
if(($e = $recursiveFind($menu))) {
break;
}
}
}
if(isset($e)) {
$pathSegments = [$e->getPath()];
while($e = $e->getMenu()->getParentEntry()) {
$pathSegments[] = $e->getPath();
}
$uriParts = [];
if($observeRewrite) {
if($script !== 'index.php') {
$uriParts[] = basename($script, '.php');
}
}
else {
if(is_null($assetsPath)) {
$assetsPath = Application::getInstance()->getRelativeAssetsPath();
}
$uriParts[] = ltrim($assetsPath, '/') . $script;
}
if(count($pathSegments)) {
$uriParts[] = implode('/', array_reverse($pathSegments));
}
if(count($matchSegments)) {
$uriParts[] = implode('/', $matchSegments);
}
$uri = implode('/', $uriParts) . $matches[4];
return "<a{$matches[1]} href={$matches[2]}/$uri{$matches[2]}{$matches[5]}>";
}
} | [
"private",
"function",
"filterHrefWithPath",
"(",
"$",
"matches",
")",
"{",
"static",
"$",
"script",
";",
"static",
"$",
"observeRewrite",
";",
"static",
"$",
"config",
";",
"static",
"$",
"assetsPath",
";",
"if",
"(",
"is_null",
"(",
"$",
"config",
")",
")",
"{",
"$",
"application",
"=",
"Application",
"::",
"getInstance",
"(",
")",
";",
"$",
"config",
"=",
"$",
"application",
"->",
"getConfig",
"(",
")",
";",
"$",
"observeRewrite",
"=",
"$",
"application",
"->",
"getRouter",
"(",
")",
"->",
"getServerSideRewrite",
"(",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"script",
")",
")",
"{",
"$",
"script",
"=",
"basename",
"(",
"trim",
"(",
"Request",
"::",
"createFromGlobals",
"(",
")",
"->",
"getScriptName",
"(",
")",
",",
"'/'",
")",
")",
";",
"}",
"$",
"matchSegments",
"=",
"explode",
"(",
"'/'",
",",
"$",
"matches",
"[",
"3",
"]",
")",
";",
"$",
"pathToFind",
"=",
"array_shift",
"(",
"$",
"matchSegments",
")",
";",
"$",
"recursiveFind",
"=",
"function",
"(",
"Menu",
"$",
"m",
")",
"use",
"(",
"&",
"$",
"recursiveFind",
",",
"$",
"pathToFind",
")",
"{",
"foreach",
"(",
"$",
"m",
"->",
"getEntries",
"(",
")",
"as",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"e",
"->",
"getPath",
"(",
")",
"===",
"$",
"pathToFind",
")",
"{",
"return",
"$",
"e",
";",
"}",
"if",
"(",
"(",
"$",
"sm",
"=",
"$",
"e",
"->",
"getSubMenu",
"(",
")",
")",
"&&",
"$",
"sm",
"->",
"getType",
"(",
")",
"!==",
"'dynamic'",
")",
"{",
"if",
"(",
"$",
"e",
"=",
"$",
"recursiveFind",
"(",
"$",
"sm",
")",
")",
"{",
"return",
"$",
"e",
";",
"}",
"}",
"}",
"}",
";",
"foreach",
"(",
"$",
"config",
"->",
"menus",
"as",
"$",
"menu",
")",
"{",
"if",
"(",
"$",
"menu",
"->",
"getScript",
"(",
")",
"===",
"$",
"script",
")",
"{",
"if",
"(",
"(",
"$",
"e",
"=",
"$",
"recursiveFind",
"(",
"$",
"menu",
")",
")",
")",
"{",
"break",
";",
"}",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"e",
")",
")",
"{",
"$",
"pathSegments",
"=",
"[",
"$",
"e",
"->",
"getPath",
"(",
")",
"]",
";",
"while",
"(",
"$",
"e",
"=",
"$",
"e",
"->",
"getMenu",
"(",
")",
"->",
"getParentEntry",
"(",
")",
")",
"{",
"$",
"pathSegments",
"[",
"]",
"=",
"$",
"e",
"->",
"getPath",
"(",
")",
";",
"}",
"$",
"uriParts",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"observeRewrite",
")",
"{",
"if",
"(",
"$",
"script",
"!==",
"'index.php'",
")",
"{",
"$",
"uriParts",
"[",
"]",
"=",
"basename",
"(",
"$",
"script",
",",
"'.php'",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"is_null",
"(",
"$",
"assetsPath",
")",
")",
"{",
"$",
"assetsPath",
"=",
"Application",
"::",
"getInstance",
"(",
")",
"->",
"getRelativeAssetsPath",
"(",
")",
";",
"}",
"$",
"uriParts",
"[",
"]",
"=",
"ltrim",
"(",
"$",
"assetsPath",
",",
"'/'",
")",
".",
"$",
"script",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"pathSegments",
")",
")",
"{",
"$",
"uriParts",
"[",
"]",
"=",
"implode",
"(",
"'/'",
",",
"array_reverse",
"(",
"$",
"pathSegments",
")",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"matchSegments",
")",
")",
"{",
"$",
"uriParts",
"[",
"]",
"=",
"implode",
"(",
"'/'",
",",
"$",
"matchSegments",
")",
";",
"}",
"$",
"uri",
"=",
"implode",
"(",
"'/'",
",",
"$",
"uriParts",
")",
".",
"$",
"matches",
"[",
"4",
"]",
";",
"return",
"\"<a{$matches[1]} href={$matches[2]}/$uri{$matches[2]}{$matches[5]}>\"",
";",
"}",
"}"
] | callback to turn href shortcuts into site conform valid URLs
tries to build a path reflecting the position of the page in a nested menu
$foo/bar?baz=1 becomes /level1/level2/foo/bar?baz=1 or index.php/level1/level2/foo/bar?baz=1
@param array $matches
@return string | [
"callback",
"to",
"turn",
"href",
"shortcuts",
"into",
"site",
"conform",
"valid",
"URLs",
"tries",
"to",
"build",
"a",
"path",
"reflecting",
"the",
"position",
"of",
"the",
"page",
"in",
"a",
"nested",
"menu"
] | 295c21b00e7ef6085efcdf5b64fabb28d499b5a6 | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Template/Filter/AnchorHref.php#L57-L137 | train |
Vectrex/vxPHP | src/Template/Filter/AnchorHref.php | AnchorHref.filterHref | private function filterHref($matches) {
static $script;
static $observeRewrite;
if(is_null($script)) {
$script = trim(Request::createFromGlobals()->getScriptName(), '/');
}
if(is_null($observeRewrite)) {
$observeRewrite = Application::getInstance()->getRouter()->getServerSideRewrite();
}
$matches[4] = html_entity_decode($matches[4]);
$uriParts = [];
if($observeRewrite) {
if($script !== 'index.php') {
$uriParts[] = basename($script, '.php');
}
}
else {
$uriParts[] = $script;
}
if($matches[3] !== '') {
$uriParts[] = $matches[3];
}
$uri = implode('/', $uriParts) . $matches[4];
return "<a{$matches[1]} href={$matches[2]}/$uri{$matches[2]}{$matches[5]}>";
} | php | private function filterHref($matches) {
static $script;
static $observeRewrite;
if(is_null($script)) {
$script = trim(Request::createFromGlobals()->getScriptName(), '/');
}
if(is_null($observeRewrite)) {
$observeRewrite = Application::getInstance()->getRouter()->getServerSideRewrite();
}
$matches[4] = html_entity_decode($matches[4]);
$uriParts = [];
if($observeRewrite) {
if($script !== 'index.php') {
$uriParts[] = basename($script, '.php');
}
}
else {
$uriParts[] = $script;
}
if($matches[3] !== '') {
$uriParts[] = $matches[3];
}
$uri = implode('/', $uriParts) . $matches[4];
return "<a{$matches[1]} href={$matches[2]}/$uri{$matches[2]}{$matches[5]}>";
} | [
"private",
"function",
"filterHref",
"(",
"$",
"matches",
")",
"{",
"static",
"$",
"script",
";",
"static",
"$",
"observeRewrite",
";",
"if",
"(",
"is_null",
"(",
"$",
"script",
")",
")",
"{",
"$",
"script",
"=",
"trim",
"(",
"Request",
"::",
"createFromGlobals",
"(",
")",
"->",
"getScriptName",
"(",
")",
",",
"'/'",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"observeRewrite",
")",
")",
"{",
"$",
"observeRewrite",
"=",
"Application",
"::",
"getInstance",
"(",
")",
"->",
"getRouter",
"(",
")",
"->",
"getServerSideRewrite",
"(",
")",
";",
"}",
"$",
"matches",
"[",
"4",
"]",
"=",
"html_entity_decode",
"(",
"$",
"matches",
"[",
"4",
"]",
")",
";",
"$",
"uriParts",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"observeRewrite",
")",
"{",
"if",
"(",
"$",
"script",
"!==",
"'index.php'",
")",
"{",
"$",
"uriParts",
"[",
"]",
"=",
"basename",
"(",
"$",
"script",
",",
"'.php'",
")",
";",
"}",
"}",
"else",
"{",
"$",
"uriParts",
"[",
"]",
"=",
"$",
"script",
";",
"}",
"if",
"(",
"$",
"matches",
"[",
"3",
"]",
"!==",
"''",
")",
"{",
"$",
"uriParts",
"[",
"]",
"=",
"$",
"matches",
"[",
"3",
"]",
";",
"}",
"$",
"uri",
"=",
"implode",
"(",
"'/'",
",",
"$",
"uriParts",
")",
".",
"$",
"matches",
"[",
"4",
"]",
";",
"return",
"\"<a{$matches[1]} href={$matches[2]}/$uri{$matches[2]}{$matches[5]}>\"",
";",
"}"
] | callback to turn href shortcuts into site conform valid URLs
$/foo/bar?baz=1 becomes /foo/bar?baz=1 or index.php/foo/bar?baz=1
@param array $matches
@return string | [
"callback",
"to",
"turn",
"href",
"shortcuts",
"into",
"site",
"conform",
"valid",
"URLs"
] | 295c21b00e7ef6085efcdf5b64fabb28d499b5a6 | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Template/Filter/AnchorHref.php#L147-L180 | train |
FlexModel/FlexModelBundle | Twig/FlexModelExtension.php | FlexModelExtension.optionLabelFilter | public function optionLabelFilter($value, $objectName, $fieldName)
{
$fieldConfiguration = $this->flexModel->getField($objectName, $fieldName);
$label = "";
if (is_array($fieldConfiguration)) {
if (isset($fieldConfiguration['options'])) {
if (is_array($value)) {
foreach ($value as $i => $valueItem) {
$value[$i] = $this->getLabelForValue($fieldConfiguration, $valueItem);
}
$label = implode(', ', $value);
} else {
$label = $this->getLabelForValue($fieldConfiguration, $value);
}
} else {
$label = $value;
}
}
return $label;
} | php | public function optionLabelFilter($value, $objectName, $fieldName)
{
$fieldConfiguration = $this->flexModel->getField($objectName, $fieldName);
$label = "";
if (is_array($fieldConfiguration)) {
if (isset($fieldConfiguration['options'])) {
if (is_array($value)) {
foreach ($value as $i => $valueItem) {
$value[$i] = $this->getLabelForValue($fieldConfiguration, $valueItem);
}
$label = implode(', ', $value);
} else {
$label = $this->getLabelForValue($fieldConfiguration, $value);
}
} else {
$label = $value;
}
}
return $label;
} | [
"public",
"function",
"optionLabelFilter",
"(",
"$",
"value",
",",
"$",
"objectName",
",",
"$",
"fieldName",
")",
"{",
"$",
"fieldConfiguration",
"=",
"$",
"this",
"->",
"flexModel",
"->",
"getField",
"(",
"$",
"objectName",
",",
"$",
"fieldName",
")",
";",
"$",
"label",
"=",
"\"\"",
";",
"if",
"(",
"is_array",
"(",
"$",
"fieldConfiguration",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"fieldConfiguration",
"[",
"'options'",
"]",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"$",
"i",
"=>",
"$",
"valueItem",
")",
"{",
"$",
"value",
"[",
"$",
"i",
"]",
"=",
"$",
"this",
"->",
"getLabelForValue",
"(",
"$",
"fieldConfiguration",
",",
"$",
"valueItem",
")",
";",
"}",
"$",
"label",
"=",
"implode",
"(",
"', '",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"label",
"=",
"$",
"this",
"->",
"getLabelForValue",
"(",
"$",
"fieldConfiguration",
",",
"$",
"value",
")",
";",
"}",
"}",
"else",
"{",
"$",
"label",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"label",
";",
"}"
] | Gets the option label based on the object and field name.
@param string $value
@param string $objectName
@param string $fieldName
@return string $label | [
"Gets",
"the",
"option",
"label",
"based",
"on",
"the",
"object",
"and",
"field",
"name",
"."
] | 7b4720d25b0dc6baf29b1da8ad7c67dfb2686460 | https://github.com/FlexModel/FlexModelBundle/blob/7b4720d25b0dc6baf29b1da8ad7c67dfb2686460/Twig/FlexModelExtension.php#L56-L77 | train |
FlexModel/FlexModelBundle | Twig/FlexModelExtension.php | FlexModelExtension.getLabelForValue | private function getLabelForValue($fieldConfiguration, $value)
{
$label = "";
foreach ($fieldConfiguration['options'] as $option) {
if ($option['value'] == $value) {
$label = $option['label'];
}
}
return $label;
} | php | private function getLabelForValue($fieldConfiguration, $value)
{
$label = "";
foreach ($fieldConfiguration['options'] as $option) {
if ($option['value'] == $value) {
$label = $option['label'];
}
}
return $label;
} | [
"private",
"function",
"getLabelForValue",
"(",
"$",
"fieldConfiguration",
",",
"$",
"value",
")",
"{",
"$",
"label",
"=",
"\"\"",
";",
"foreach",
"(",
"$",
"fieldConfiguration",
"[",
"'options'",
"]",
"as",
"$",
"option",
")",
"{",
"if",
"(",
"$",
"option",
"[",
"'value'",
"]",
"==",
"$",
"value",
")",
"{",
"$",
"label",
"=",
"$",
"option",
"[",
"'label'",
"]",
";",
"}",
"}",
"return",
"$",
"label",
";",
"}"
] | Gets the label for the set value.
@param mixed $fieldConfiguration
@param string $value
@return string $label | [
"Gets",
"the",
"label",
"for",
"the",
"set",
"value",
"."
] | 7b4720d25b0dc6baf29b1da8ad7c67dfb2686460 | https://github.com/FlexModel/FlexModelBundle/blob/7b4720d25b0dc6baf29b1da8ad7c67dfb2686460/Twig/FlexModelExtension.php#L87-L97 | train |
FlexModel/FlexModelBundle | Twig/FlexModelExtension.php | FlexModelExtension.fieldLabelFilter | public function fieldLabelFilter($value, $objectName, $fieldName)
{
$fieldConfiguration = $this->flexModel->getField($objectName, $fieldName);
$label = "";
if (is_array($fieldConfiguration)) {
$label = $fieldConfiguration['label'];
}
return $label;
} | php | public function fieldLabelFilter($value, $objectName, $fieldName)
{
$fieldConfiguration = $this->flexModel->getField($objectName, $fieldName);
$label = "";
if (is_array($fieldConfiguration)) {
$label = $fieldConfiguration['label'];
}
return $label;
} | [
"public",
"function",
"fieldLabelFilter",
"(",
"$",
"value",
",",
"$",
"objectName",
",",
"$",
"fieldName",
")",
"{",
"$",
"fieldConfiguration",
"=",
"$",
"this",
"->",
"flexModel",
"->",
"getField",
"(",
"$",
"objectName",
",",
"$",
"fieldName",
")",
";",
"$",
"label",
"=",
"\"\"",
";",
"if",
"(",
"is_array",
"(",
"$",
"fieldConfiguration",
")",
")",
"{",
"$",
"label",
"=",
"$",
"fieldConfiguration",
"[",
"'label'",
"]",
";",
"}",
"return",
"$",
"label",
";",
"}"
] | Gets the field label based on the object and field name.
@param string $objectName
@param string $fieldName
@return string $label | [
"Gets",
"the",
"field",
"label",
"based",
"on",
"the",
"object",
"and",
"field",
"name",
"."
] | 7b4720d25b0dc6baf29b1da8ad7c67dfb2686460 | https://github.com/FlexModel/FlexModelBundle/blob/7b4720d25b0dc6baf29b1da8ad7c67dfb2686460/Twig/FlexModelExtension.php#L107-L117 | train |
rutger-speksnijder/restphp | src/RestPHP/Request/RequestFactory.php | RequestFactory.build | public function build($type)
{
if (!isset($this->types[$type])) {
throw new \Exception("Unknown request type.");
}
return new $this->types[$type]();
} | php | public function build($type)
{
if (!isset($this->types[$type])) {
throw new \Exception("Unknown request type.");
}
return new $this->types[$type]();
} | [
"public",
"function",
"build",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"types",
"[",
"$",
"type",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Unknown request type.\"",
")",
";",
"}",
"return",
"new",
"$",
"this",
"->",
"types",
"[",
"$",
"type",
"]",
"(",
")",
";",
"}"
] | Builds the request object.
@param string $type The type of request to build.
@throws Exception Throws an exception for unknown request types.
@return \RestPHP\Request The created object. | [
"Builds",
"the",
"request",
"object",
"."
] | 326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d | https://github.com/rutger-speksnijder/restphp/blob/326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d/src/RestPHP/Request/RequestFactory.php#L51-L57 | train |
Finesse/QueryScribe | src/PostProcessors/AbstractProcessor.php | AbstractProcessor.processQuery | protected function processQuery(Query $query, $context): Query
{
$queryProperties = [];
// Table
$queryProperties['table'] = $this->processTable($query->table, $context);
// Select
foreach ($query->select as $alias => $select) {
$queryProperties['select'][$alias] = $this->processSelect($select, $context);
}
// Insert
foreach ($query->insert as $index => $insert) {
$queryProperties['insert'][$index] = $this->processInsert($insert, $context);
}
// Update
foreach ($query->update as $column => $update) {
$column = $this->processColumnName($column, $context);
$queryProperties['update'][$column] = $this->processValueOrSubQuery($update, $context);
}
// Join
foreach ($query->join as $index => $join) {
$queryProperties['join'][$index] = $this->processJoin($join, $context);
}
// Where
foreach ($query->where as $index => $criterion) {
$queryProperties['where'][$index] = $this->processCriterion($criterion, $context);
}
// Order
foreach ($query->order as $index => $order) {
$queryProperties['order'][$index] = $this->processOrder($order, $context);
}
// Offset
$queryProperties['offset'] = $this->processValueOrSubQuery($query->offset, $context);
// Limit
$queryProperties['limit'] = $this->processValueOrSubQuery($query->limit, $context);
// Is any property changed?
$isChanged = false;
foreach ($queryProperties as $property => $value) {
if ($value !== $query->$property) {
$isChanged = true;
break;
}
}
if ($isChanged) {
$query = clone $query;
foreach ($queryProperties as $property => $value) {
$query->$property = $value;
}
return $query;
} else {
return $query;
}
} | php | protected function processQuery(Query $query, $context): Query
{
$queryProperties = [];
// Table
$queryProperties['table'] = $this->processTable($query->table, $context);
// Select
foreach ($query->select as $alias => $select) {
$queryProperties['select'][$alias] = $this->processSelect($select, $context);
}
// Insert
foreach ($query->insert as $index => $insert) {
$queryProperties['insert'][$index] = $this->processInsert($insert, $context);
}
// Update
foreach ($query->update as $column => $update) {
$column = $this->processColumnName($column, $context);
$queryProperties['update'][$column] = $this->processValueOrSubQuery($update, $context);
}
// Join
foreach ($query->join as $index => $join) {
$queryProperties['join'][$index] = $this->processJoin($join, $context);
}
// Where
foreach ($query->where as $index => $criterion) {
$queryProperties['where'][$index] = $this->processCriterion($criterion, $context);
}
// Order
foreach ($query->order as $index => $order) {
$queryProperties['order'][$index] = $this->processOrder($order, $context);
}
// Offset
$queryProperties['offset'] = $this->processValueOrSubQuery($query->offset, $context);
// Limit
$queryProperties['limit'] = $this->processValueOrSubQuery($query->limit, $context);
// Is any property changed?
$isChanged = false;
foreach ($queryProperties as $property => $value) {
if ($value !== $query->$property) {
$isChanged = true;
break;
}
}
if ($isChanged) {
$query = clone $query;
foreach ($queryProperties as $property => $value) {
$query->$property = $value;
}
return $query;
} else {
return $query;
}
} | [
"protected",
"function",
"processQuery",
"(",
"Query",
"$",
"query",
",",
"$",
"context",
")",
":",
"Query",
"{",
"$",
"queryProperties",
"=",
"[",
"]",
";",
"// Table",
"$",
"queryProperties",
"[",
"'table'",
"]",
"=",
"$",
"this",
"->",
"processTable",
"(",
"$",
"query",
"->",
"table",
",",
"$",
"context",
")",
";",
"// Select",
"foreach",
"(",
"$",
"query",
"->",
"select",
"as",
"$",
"alias",
"=>",
"$",
"select",
")",
"{",
"$",
"queryProperties",
"[",
"'select'",
"]",
"[",
"$",
"alias",
"]",
"=",
"$",
"this",
"->",
"processSelect",
"(",
"$",
"select",
",",
"$",
"context",
")",
";",
"}",
"// Insert",
"foreach",
"(",
"$",
"query",
"->",
"insert",
"as",
"$",
"index",
"=>",
"$",
"insert",
")",
"{",
"$",
"queryProperties",
"[",
"'insert'",
"]",
"[",
"$",
"index",
"]",
"=",
"$",
"this",
"->",
"processInsert",
"(",
"$",
"insert",
",",
"$",
"context",
")",
";",
"}",
"// Update",
"foreach",
"(",
"$",
"query",
"->",
"update",
"as",
"$",
"column",
"=>",
"$",
"update",
")",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"processColumnName",
"(",
"$",
"column",
",",
"$",
"context",
")",
";",
"$",
"queryProperties",
"[",
"'update'",
"]",
"[",
"$",
"column",
"]",
"=",
"$",
"this",
"->",
"processValueOrSubQuery",
"(",
"$",
"update",
",",
"$",
"context",
")",
";",
"}",
"// Join",
"foreach",
"(",
"$",
"query",
"->",
"join",
"as",
"$",
"index",
"=>",
"$",
"join",
")",
"{",
"$",
"queryProperties",
"[",
"'join'",
"]",
"[",
"$",
"index",
"]",
"=",
"$",
"this",
"->",
"processJoin",
"(",
"$",
"join",
",",
"$",
"context",
")",
";",
"}",
"// Where",
"foreach",
"(",
"$",
"query",
"->",
"where",
"as",
"$",
"index",
"=>",
"$",
"criterion",
")",
"{",
"$",
"queryProperties",
"[",
"'where'",
"]",
"[",
"$",
"index",
"]",
"=",
"$",
"this",
"->",
"processCriterion",
"(",
"$",
"criterion",
",",
"$",
"context",
")",
";",
"}",
"// Order",
"foreach",
"(",
"$",
"query",
"->",
"order",
"as",
"$",
"index",
"=>",
"$",
"order",
")",
"{",
"$",
"queryProperties",
"[",
"'order'",
"]",
"[",
"$",
"index",
"]",
"=",
"$",
"this",
"->",
"processOrder",
"(",
"$",
"order",
",",
"$",
"context",
")",
";",
"}",
"// Offset",
"$",
"queryProperties",
"[",
"'offset'",
"]",
"=",
"$",
"this",
"->",
"processValueOrSubQuery",
"(",
"$",
"query",
"->",
"offset",
",",
"$",
"context",
")",
";",
"// Limit",
"$",
"queryProperties",
"[",
"'limit'",
"]",
"=",
"$",
"this",
"->",
"processValueOrSubQuery",
"(",
"$",
"query",
"->",
"limit",
",",
"$",
"context",
")",
";",
"// Is any property changed?",
"$",
"isChanged",
"=",
"false",
";",
"foreach",
"(",
"$",
"queryProperties",
"as",
"$",
"property",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"!==",
"$",
"query",
"->",
"$",
"property",
")",
"{",
"$",
"isChanged",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"isChanged",
")",
"{",
"$",
"query",
"=",
"clone",
"$",
"query",
";",
"foreach",
"(",
"$",
"queryProperties",
"as",
"$",
"property",
"=>",
"$",
"value",
")",
"{",
"$",
"query",
"->",
"$",
"property",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"query",
";",
"}",
"else",
"{",
"return",
"$",
"query",
";",
"}",
"}"
] | Processes a Query object. DOES NOT change the given query or it's components by the link but may return it.
@param Query $query
@param mixed $context The processing context
@return Query | [
"Processes",
"a",
"Query",
"object",
".",
"DOES",
"NOT",
"change",
"the",
"given",
"query",
"or",
"it",
"s",
"components",
"by",
"the",
"link",
"but",
"may",
"return",
"it",
"."
] | 4edba721e37693780d142229b3ecb0cd4004c7a5 | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/PostProcessors/AbstractProcessor.php#L67-L129 | train |
Finesse/QueryScribe | src/PostProcessors/AbstractProcessor.php | AbstractProcessor.processTable | protected function processTable($table, $context)
{
if (is_string($table)) {
return $this->processTableName($table, $context);
} else {
return $this->processSubQuery($table, $context);
}
} | php | protected function processTable($table, $context)
{
if (is_string($table)) {
return $this->processTableName($table, $context);
} else {
return $this->processSubQuery($table, $context);
}
} | [
"protected",
"function",
"processTable",
"(",
"$",
"table",
",",
"$",
"context",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"table",
")",
")",
"{",
"return",
"$",
"this",
"->",
"processTableName",
"(",
"$",
"table",
",",
"$",
"context",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"processSubQuery",
"(",
"$",
"table",
",",
"$",
"context",
")",
";",
"}",
"}"
] | Processes a table name or table subquery
@param Query|StatementInterface|string $table
@param mixed $context The processing context
@return Query|StatementInterface|string | [
"Processes",
"a",
"table",
"name",
"or",
"table",
"subquery"
] | 4edba721e37693780d142229b3ecb0cd4004c7a5 | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/PostProcessors/AbstractProcessor.php#L138-L145 | train |
Finesse/QueryScribe | src/PostProcessors/AbstractProcessor.php | AbstractProcessor.processSelect | protected function processSelect($select, $context)
{
if ($select instanceof Aggregate) {
$column = $this->processColumnOrSubQuery($select->column, $context);
if ($column === $select->column) {
return $select;
} else {
return new Aggregate($select->function, $column);
}
}
return $this->processColumnOrSubQuery($select, $context);
} | php | protected function processSelect($select, $context)
{
if ($select instanceof Aggregate) {
$column = $this->processColumnOrSubQuery($select->column, $context);
if ($column === $select->column) {
return $select;
} else {
return new Aggregate($select->function, $column);
}
}
return $this->processColumnOrSubQuery($select, $context);
} | [
"protected",
"function",
"processSelect",
"(",
"$",
"select",
",",
"$",
"context",
")",
"{",
"if",
"(",
"$",
"select",
"instanceof",
"Aggregate",
")",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"processColumnOrSubQuery",
"(",
"$",
"select",
"->",
"column",
",",
"$",
"context",
")",
";",
"if",
"(",
"$",
"column",
"===",
"$",
"select",
"->",
"column",
")",
"{",
"return",
"$",
"select",
";",
"}",
"else",
"{",
"return",
"new",
"Aggregate",
"(",
"$",
"select",
"->",
"function",
",",
"$",
"column",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"processColumnOrSubQuery",
"(",
"$",
"select",
",",
"$",
"context",
")",
";",
"}"
] | Processes a single select column.
@param string|Aggregate|Query|StatementInterface $select
@param mixed $context The processing context
@return string|Aggregate|Query|StatementInterface | [
"Processes",
"a",
"single",
"select",
"column",
"."
] | 4edba721e37693780d142229b3ecb0cd4004c7a5 | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/PostProcessors/AbstractProcessor.php#L165-L177 | train |
Finesse/QueryScribe | src/PostProcessors/AbstractProcessor.php | AbstractProcessor.processColumnOrSubQuery | protected function processColumnOrSubQuery($column, $context)
{
if (is_string($column)) {
return $this->processColumnName($column, $context);
}
return $this->processSubQuery($column, $context);
} | php | protected function processColumnOrSubQuery($column, $context)
{
if (is_string($column)) {
return $this->processColumnName($column, $context);
}
return $this->processSubQuery($column, $context);
} | [
"protected",
"function",
"processColumnOrSubQuery",
"(",
"$",
"column",
",",
"$",
"context",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"column",
")",
")",
"{",
"return",
"$",
"this",
"->",
"processColumnName",
"(",
"$",
"column",
",",
"$",
"context",
")",
";",
"}",
"return",
"$",
"this",
"->",
"processSubQuery",
"(",
"$",
"column",
",",
"$",
"context",
")",
";",
"}"
] | Processes a "column or subquery" value.
@param string|Query|StatementInterface $column
@param mixed $context The processing context
@return string|Query|StatementInterface | [
"Processes",
"a",
"column",
"or",
"subquery",
"value",
"."
] | 4edba721e37693780d142229b3ecb0cd4004c7a5 | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/PostProcessors/AbstractProcessor.php#L186-L193 | train |
Finesse/QueryScribe | src/PostProcessors/AbstractProcessor.php | AbstractProcessor.processSubQuery | protected function processSubQuery($subQuery, $context)
{
if ($subQuery instanceof Query) {
return $this->processQuery($subQuery, $context);
}
return $subQuery;
} | php | protected function processSubQuery($subQuery, $context)
{
if ($subQuery instanceof Query) {
return $this->processQuery($subQuery, $context);
}
return $subQuery;
} | [
"protected",
"function",
"processSubQuery",
"(",
"$",
"subQuery",
",",
"$",
"context",
")",
"{",
"if",
"(",
"$",
"subQuery",
"instanceof",
"Query",
")",
"{",
"return",
"$",
"this",
"->",
"processQuery",
"(",
"$",
"subQuery",
",",
"$",
"context",
")",
";",
"}",
"return",
"$",
"subQuery",
";",
"}"
] | Processes a subquery. Not-subquery values are just passed through.
@param Query|StatementInterface $subQuery
@param mixed $context The processing context
@return Query|StatementInterface | [
"Processes",
"a",
"subquery",
".",
"Not",
"-",
"subquery",
"values",
"are",
"just",
"passed",
"through",
"."
] | 4edba721e37693780d142229b3ecb0cd4004c7a5 | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/PostProcessors/AbstractProcessor.php#L226-L233 | train |
Finesse/QueryScribe | src/PostProcessors/AbstractProcessor.php | AbstractProcessor.processInsert | protected function processInsert($row, $context)
{
if ($row instanceof InsertFromSelect) {
return $this->processInsertFromSelect($row, $context);
}
$newRow = [];
foreach ($row as $column => $value) {
$column = $this->processColumnName($column, $context);
$newRow[$column] = $this->processValueOrSubQuery($value, $context);
}
return $newRow;
} | php | protected function processInsert($row, $context)
{
if ($row instanceof InsertFromSelect) {
return $this->processInsertFromSelect($row, $context);
}
$newRow = [];
foreach ($row as $column => $value) {
$column = $this->processColumnName($column, $context);
$newRow[$column] = $this->processValueOrSubQuery($value, $context);
}
return $newRow;
} | [
"protected",
"function",
"processInsert",
"(",
"$",
"row",
",",
"$",
"context",
")",
"{",
"if",
"(",
"$",
"row",
"instanceof",
"InsertFromSelect",
")",
"{",
"return",
"$",
"this",
"->",
"processInsertFromSelect",
"(",
"$",
"row",
",",
"$",
"context",
")",
";",
"}",
"$",
"newRow",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"row",
"as",
"$",
"column",
"=>",
"$",
"value",
")",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"processColumnName",
"(",
"$",
"column",
",",
"$",
"context",
")",
";",
"$",
"newRow",
"[",
"$",
"column",
"]",
"=",
"$",
"this",
"->",
"processValueOrSubQuery",
"(",
"$",
"value",
",",
"$",
"context",
")",
";",
"}",
"return",
"$",
"newRow",
";",
"}"
] | Processes a single insert statement.
@param mixed[]|Query[]|StatementInterface[]|InsertFromSelect $row
@param mixed $context The processing context
@return mixed[]|Query[]|StatementInterface[]|InsertFromSelect | [
"Processes",
"a",
"single",
"insert",
"statement",
"."
] | 4edba721e37693780d142229b3ecb0cd4004c7a5 | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/PostProcessors/AbstractProcessor.php#L242-L255 | train |
Finesse/QueryScribe | src/PostProcessors/AbstractProcessor.php | AbstractProcessor.processInsertFromSelect | protected function processInsertFromSelect(InsertFromSelect $row, $context): InsertFromSelect
{
if ($row->columns === null) {
$columns = null;
} else {
$columns = [];
foreach ($row->columns as $index => $column) {
$columns[$index] = $this->processColumnName($column, $context);
}
}
$selectQuery = $this->processSubQuery($row->selectQuery, $context);
if ($selectQuery === $row->selectQuery && $columns === $row->columns) {
return $row;
} else {
return new InsertFromSelect($columns, $selectQuery);
}
} | php | protected function processInsertFromSelect(InsertFromSelect $row, $context): InsertFromSelect
{
if ($row->columns === null) {
$columns = null;
} else {
$columns = [];
foreach ($row->columns as $index => $column) {
$columns[$index] = $this->processColumnName($column, $context);
}
}
$selectQuery = $this->processSubQuery($row->selectQuery, $context);
if ($selectQuery === $row->selectQuery && $columns === $row->columns) {
return $row;
} else {
return new InsertFromSelect($columns, $selectQuery);
}
} | [
"protected",
"function",
"processInsertFromSelect",
"(",
"InsertFromSelect",
"$",
"row",
",",
"$",
"context",
")",
":",
"InsertFromSelect",
"{",
"if",
"(",
"$",
"row",
"->",
"columns",
"===",
"null",
")",
"{",
"$",
"columns",
"=",
"null",
";",
"}",
"else",
"{",
"$",
"columns",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"row",
"->",
"columns",
"as",
"$",
"index",
"=>",
"$",
"column",
")",
"{",
"$",
"columns",
"[",
"$",
"index",
"]",
"=",
"$",
"this",
"->",
"processColumnName",
"(",
"$",
"column",
",",
"$",
"context",
")",
";",
"}",
"}",
"$",
"selectQuery",
"=",
"$",
"this",
"->",
"processSubQuery",
"(",
"$",
"row",
"->",
"selectQuery",
",",
"$",
"context",
")",
";",
"if",
"(",
"$",
"selectQuery",
"===",
"$",
"row",
"->",
"selectQuery",
"&&",
"$",
"columns",
"===",
"$",
"row",
"->",
"columns",
")",
"{",
"return",
"$",
"row",
";",
"}",
"else",
"{",
"return",
"new",
"InsertFromSelect",
"(",
"$",
"columns",
",",
"$",
"selectQuery",
")",
";",
"}",
"}"
] | Processes a single "insert from select" statement.
@param InsertFromSelect $row
@param mixed $context The processing context
@return InsertFromSelect | [
"Processes",
"a",
"single",
"insert",
"from",
"select",
"statement",
"."
] | 4edba721e37693780d142229b3ecb0cd4004c7a5 | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/PostProcessors/AbstractProcessor.php#L264-L281 | train |
Finesse/QueryScribe | src/PostProcessors/AbstractProcessor.php | AbstractProcessor.processJoin | protected function processJoin(Join $join, $context): Join
{
$table = $this->processTable($join->table, $context);
$criteria = [];
foreach ($join->criteria as $index => $criterion) {
$criteria[$index] = $this->processCriterion($criterion, $context);
}
if ($table === $join->table && $criteria === $join->criteria) {
return $join;
} else {
return new Join($join->type, $table, $join->tableAlias, $criteria);
}
} | php | protected function processJoin(Join $join, $context): Join
{
$table = $this->processTable($join->table, $context);
$criteria = [];
foreach ($join->criteria as $index => $criterion) {
$criteria[$index] = $this->processCriterion($criterion, $context);
}
if ($table === $join->table && $criteria === $join->criteria) {
return $join;
} else {
return new Join($join->type, $table, $join->tableAlias, $criteria);
}
} | [
"protected",
"function",
"processJoin",
"(",
"Join",
"$",
"join",
",",
"$",
"context",
")",
":",
"Join",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"processTable",
"(",
"$",
"join",
"->",
"table",
",",
"$",
"context",
")",
";",
"$",
"criteria",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"join",
"->",
"criteria",
"as",
"$",
"index",
"=>",
"$",
"criterion",
")",
"{",
"$",
"criteria",
"[",
"$",
"index",
"]",
"=",
"$",
"this",
"->",
"processCriterion",
"(",
"$",
"criterion",
",",
"$",
"context",
")",
";",
"}",
"if",
"(",
"$",
"table",
"===",
"$",
"join",
"->",
"table",
"&&",
"$",
"criteria",
"===",
"$",
"join",
"->",
"criteria",
")",
"{",
"return",
"$",
"join",
";",
"}",
"else",
"{",
"return",
"new",
"Join",
"(",
"$",
"join",
"->",
"type",
",",
"$",
"table",
",",
"$",
"join",
"->",
"tableAlias",
",",
"$",
"criteria",
")",
";",
"}",
"}"
] | Processes a single join.
@param Join $join
@param mixed $context The processing context
@return Join | [
"Processes",
"a",
"single",
"join",
"."
] | 4edba721e37693780d142229b3ecb0cd4004c7a5 | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/PostProcessors/AbstractProcessor.php#L290-L303 | train |
Finesse/QueryScribe | src/PostProcessors/AbstractProcessor.php | AbstractProcessor.processOrder | protected function processOrder($order, $context)
{
if ($order instanceof Order || $order instanceof OrderByIsNull) {
$column = $this->processColumnOrSubQuery($order->column, $context);
if ($column === $order->column) {
return $order;
} elseif ($order instanceof Order) {
return new Order($column, $order->isDescending);
} else {
return new OrderByIsNull($column, $order->areNullFirst);
}
}
if ($order instanceof ExplicitOrder) {
$column = $this->processColumnOrSubQuery($order->column, $context);
$values = [];
foreach ($order->order as $index => $value) {
$values[$index] = $this->processValueOrSubQuery($value, $context);
}
if ($column === $order->column && $values === $order->order) {
return $order;
} else {
return new ExplicitOrder($column, $values, $order->areOtherFirst);
}
}
return $order;
} | php | protected function processOrder($order, $context)
{
if ($order instanceof Order || $order instanceof OrderByIsNull) {
$column = $this->processColumnOrSubQuery($order->column, $context);
if ($column === $order->column) {
return $order;
} elseif ($order instanceof Order) {
return new Order($column, $order->isDescending);
} else {
return new OrderByIsNull($column, $order->areNullFirst);
}
}
if ($order instanceof ExplicitOrder) {
$column = $this->processColumnOrSubQuery($order->column, $context);
$values = [];
foreach ($order->order as $index => $value) {
$values[$index] = $this->processValueOrSubQuery($value, $context);
}
if ($column === $order->column && $values === $order->order) {
return $order;
} else {
return new ExplicitOrder($column, $values, $order->areOtherFirst);
}
}
return $order;
} | [
"protected",
"function",
"processOrder",
"(",
"$",
"order",
",",
"$",
"context",
")",
"{",
"if",
"(",
"$",
"order",
"instanceof",
"Order",
"||",
"$",
"order",
"instanceof",
"OrderByIsNull",
")",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"processColumnOrSubQuery",
"(",
"$",
"order",
"->",
"column",
",",
"$",
"context",
")",
";",
"if",
"(",
"$",
"column",
"===",
"$",
"order",
"->",
"column",
")",
"{",
"return",
"$",
"order",
";",
"}",
"elseif",
"(",
"$",
"order",
"instanceof",
"Order",
")",
"{",
"return",
"new",
"Order",
"(",
"$",
"column",
",",
"$",
"order",
"->",
"isDescending",
")",
";",
"}",
"else",
"{",
"return",
"new",
"OrderByIsNull",
"(",
"$",
"column",
",",
"$",
"order",
"->",
"areNullFirst",
")",
";",
"}",
"}",
"if",
"(",
"$",
"order",
"instanceof",
"ExplicitOrder",
")",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"processColumnOrSubQuery",
"(",
"$",
"order",
"->",
"column",
",",
"$",
"context",
")",
";",
"$",
"values",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"order",
"->",
"order",
"as",
"$",
"index",
"=>",
"$",
"value",
")",
"{",
"$",
"values",
"[",
"$",
"index",
"]",
"=",
"$",
"this",
"->",
"processValueOrSubQuery",
"(",
"$",
"value",
",",
"$",
"context",
")",
";",
"}",
"if",
"(",
"$",
"column",
"===",
"$",
"order",
"->",
"column",
"&&",
"$",
"values",
"===",
"$",
"order",
"->",
"order",
")",
"{",
"return",
"$",
"order",
";",
"}",
"else",
"{",
"return",
"new",
"ExplicitOrder",
"(",
"$",
"column",
",",
"$",
"values",
",",
"$",
"order",
"->",
"areOtherFirst",
")",
";",
"}",
"}",
"return",
"$",
"order",
";",
"}"
] | Processes a single order statement.
@param Order|OrderByIsNull|ExplicitOrder|string $order
@param mixed $context The processing context
@return Order|string | [
"Processes",
"a",
"single",
"order",
"statement",
"."
] | 4edba721e37693780d142229b3ecb0cd4004c7a5 | https://github.com/Finesse/QueryScribe/blob/4edba721e37693780d142229b3ecb0cd4004c7a5/src/PostProcessors/AbstractProcessor.php#L409-L439 | train |
bseddon/XPath20 | Iterator/ChildNodeIterator.php | ChildNodeIterator.skip | private function skip( $nav )
{
if ( $this->excludeComments && $nav->getNodeType() == XML_COMMENT_NODE )
{
$this->commentsSkipped++;
}
return ( $this->excludeComments && $nav->getNodeType() == XML_COMMENT_NODE ) ||
( $this->excludeWhitespace && $nav->IsWhitespaceNode() );
} | php | private function skip( $nav )
{
if ( $this->excludeComments && $nav->getNodeType() == XML_COMMENT_NODE )
{
$this->commentsSkipped++;
}
return ( $this->excludeComments && $nav->getNodeType() == XML_COMMENT_NODE ) ||
( $this->excludeWhitespace && $nav->IsWhitespaceNode() );
} | [
"private",
"function",
"skip",
"(",
"$",
"nav",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"excludeComments",
"&&",
"$",
"nav",
"->",
"getNodeType",
"(",
")",
"==",
"XML_COMMENT_NODE",
")",
"{",
"$",
"this",
"->",
"commentsSkipped",
"++",
";",
"}",
"return",
"(",
"$",
"this",
"->",
"excludeComments",
"&&",
"$",
"nav",
"->",
"getNodeType",
"(",
")",
"==",
"XML_COMMENT_NODE",
")",
"||",
"(",
"$",
"this",
"->",
"excludeWhitespace",
"&&",
"$",
"nav",
"->",
"IsWhitespaceNode",
"(",
")",
")",
";",
"}"
] | Check whether to skip this node
@param XPathNavigator $nav
@return boolean | [
"Check",
"whether",
"to",
"skip",
"this",
"node"
] | 69882b6efffaa5470a819d5fdd2f6473ddeb046d | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Iterator/ChildNodeIterator.php#L112-L120 | train |
eureka-framework/component-http | src/Http/Data.php | Data.get | public function get($name = null, $default = null)
{
$value = null;
if (null === $name) {
$value = $this->data;
} elseif (isset($this->data[$name])) {
$value = $this->data[$name];
} elseif (null !== $default) {
$value = $default;
} else {
throw new \Exception('Key not found in data ! (key: ' . $name . ')');
}
return $value;
} | php | public function get($name = null, $default = null)
{
$value = null;
if (null === $name) {
$value = $this->data;
} elseif (isset($this->data[$name])) {
$value = $this->data[$name];
} elseif (null !== $default) {
$value = $default;
} else {
throw new \Exception('Key not found in data ! (key: ' . $name . ')');
}
return $value;
} | [
"public",
"function",
"get",
"(",
"$",
"name",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"value",
"=",
"null",
";",
"if",
"(",
"null",
"===",
"$",
"name",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"data",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"data",
"[",
"$",
"name",
"]",
";",
"}",
"elseif",
"(",
"null",
"!==",
"$",
"default",
")",
"{",
"$",
"value",
"=",
"$",
"default",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Key not found in data ! (key: '",
".",
"$",
"name",
".",
"')'",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Get request data.
@param string $name
@param mixed $default
@return mixed Value
@throws \Exception | [
"Get",
"request",
"data",
"."
] | 698c3b73581a9703a9c932890c57e50f8774607a | https://github.com/eureka-framework/component-http/blob/698c3b73581a9703a9c932890c57e50f8774607a/src/Http/Data.php#L53-L68 | train |
kitpages/KitpagesChainBundle | Step/StepAbstract.php | StepAbstract.getRenderedParameter | public function getRenderedParameter($key, $escaper = null)
{
$subject = $this->getParameter($key);
preg_match_all('/{{([a-zA-Z0-9\.\-\_]+)}}/', $subject, $matches);
$parameterList = $matches[1];
foreach ($parameterList as $parameterKey) {
$val = $this->getParameter($parameterKey);
if ($val) {
if (is_callable($escaper)) {
$val = $escaper($val);
}
$subject = str_replace('{{'.$parameterKey.'}}', $val, $subject);
} else {
$subject = str_replace('{{'.$parameterKey.'}}', '', $subject);
}
}
return $subject;
} | php | public function getRenderedParameter($key, $escaper = null)
{
$subject = $this->getParameter($key);
preg_match_all('/{{([a-zA-Z0-9\.\-\_]+)}}/', $subject, $matches);
$parameterList = $matches[1];
foreach ($parameterList as $parameterKey) {
$val = $this->getParameter($parameterKey);
if ($val) {
if (is_callable($escaper)) {
$val = $escaper($val);
}
$subject = str_replace('{{'.$parameterKey.'}}', $val, $subject);
} else {
$subject = str_replace('{{'.$parameterKey.'}}', '', $subject);
}
}
return $subject;
} | [
"public",
"function",
"getRenderedParameter",
"(",
"$",
"key",
",",
"$",
"escaper",
"=",
"null",
")",
"{",
"$",
"subject",
"=",
"$",
"this",
"->",
"getParameter",
"(",
"$",
"key",
")",
";",
"preg_match_all",
"(",
"'/{{([a-zA-Z0-9\\.\\-\\_]+)}}/'",
",",
"$",
"subject",
",",
"$",
"matches",
")",
";",
"$",
"parameterList",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"foreach",
"(",
"$",
"parameterList",
"as",
"$",
"parameterKey",
")",
"{",
"$",
"val",
"=",
"$",
"this",
"->",
"getParameter",
"(",
"$",
"parameterKey",
")",
";",
"if",
"(",
"$",
"val",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"escaper",
")",
")",
"{",
"$",
"val",
"=",
"$",
"escaper",
"(",
"$",
"val",
")",
";",
"}",
"$",
"subject",
"=",
"str_replace",
"(",
"'{{'",
".",
"$",
"parameterKey",
".",
"'}}'",
",",
"$",
"val",
",",
"$",
"subject",
")",
";",
"}",
"else",
"{",
"$",
"subject",
"=",
"str_replace",
"(",
"'{{'",
".",
"$",
"parameterKey",
".",
"'}}'",
",",
"''",
",",
"$",
"subject",
")",
";",
"}",
"}",
"return",
"$",
"subject",
";",
"}"
] | used to transform a value in a parameter.
ex :
$parameterList['foo'] = 'ls {{fileName}} {{bar}}';
$parameterList['fileName'] = '/tmp/titi';
// $parameterList['bar'] is undefined
=> $this->getRenderedParameter('foo', function ($str) { strtoupper($str); } );
Result : ls /TMP/TITI
@param $key
@param callable $escaper
@return mixed|null | [
"used",
"to",
"transform",
"a",
"value",
"in",
"a",
"parameter",
"."
] | f884d1875b6a6b6b9c66e161884cc3a2c1edc0e6 | https://github.com/kitpages/KitpagesChainBundle/blob/f884d1875b6a6b6b9c66e161884cc3a2c1edc0e6/Step/StepAbstract.php#L54-L71 | train |
Innmind/Math | src/Polynom/Polynom.php | Polynom.withDegree | public function withDegree(Integer $degree, Number $coeff): self
{
$degrees = $this->degrees->put(
$degree->value(),
new Degree($degree, $coeff)
);
return new self(
$this->intercept,
...$degrees->values()
);
} | php | public function withDegree(Integer $degree, Number $coeff): self
{
$degrees = $this->degrees->put(
$degree->value(),
new Degree($degree, $coeff)
);
return new self(
$this->intercept,
...$degrees->values()
);
} | [
"public",
"function",
"withDegree",
"(",
"Integer",
"$",
"degree",
",",
"Number",
"$",
"coeff",
")",
":",
"self",
"{",
"$",
"degrees",
"=",
"$",
"this",
"->",
"degrees",
"->",
"put",
"(",
"$",
"degree",
"->",
"value",
"(",
")",
",",
"new",
"Degree",
"(",
"$",
"degree",
",",
"$",
"coeff",
")",
")",
";",
"return",
"new",
"self",
"(",
"$",
"this",
"->",
"intercept",
",",
"...",
"$",
"degrees",
"->",
"values",
"(",
")",
")",
";",
"}"
] | Create a new polynom with this added degree
@param Integer $degree
@param Number $coeff
@return self | [
"Create",
"a",
"new",
"polynom",
"with",
"this",
"added",
"degree"
] | ac9ad4dd1852c145e90f5edc0f38a873b125a50b | https://github.com/Innmind/Math/blob/ac9ad4dd1852c145e90f5edc0f38a873b125a50b/src/Polynom/Polynom.php#L44-L55 | train |
Innmind/Math | src/Polynom/Polynom.php | Polynom.derived | public function derived(Number $x, Number $limit = null): Number
{
$limit = $limit ?? Tangent::limit();
return divide(
subtract(
$this(add($x, $limit)),
$this($x)
),
$limit
);
} | php | public function derived(Number $x, Number $limit = null): Number
{
$limit = $limit ?? Tangent::limit();
return divide(
subtract(
$this(add($x, $limit)),
$this($x)
),
$limit
);
} | [
"public",
"function",
"derived",
"(",
"Number",
"$",
"x",
",",
"Number",
"$",
"limit",
"=",
"null",
")",
":",
"Number",
"{",
"$",
"limit",
"=",
"$",
"limit",
"??",
"Tangent",
"::",
"limit",
"(",
")",
";",
"return",
"divide",
"(",
"subtract",
"(",
"$",
"this",
"(",
"add",
"(",
"$",
"x",
",",
"$",
"limit",
")",
")",
",",
"$",
"this",
"(",
"$",
"x",
")",
")",
",",
"$",
"limit",
")",
";",
"}"
] | Compute the derived number of x
@param Number $x
@param Number|null $limit Value that tend to 0 (default to 0.000000000001)
@return Number | [
"Compute",
"the",
"derived",
"number",
"of",
"x"
] | ac9ad4dd1852c145e90f5edc0f38a873b125a50b | https://github.com/Innmind/Math/blob/ac9ad4dd1852c145e90f5edc0f38a873b125a50b/src/Polynom/Polynom.php#L121-L132 | train |
TiMESPLiNTER/gphpio | src/RPi.php | RPi.getGPIOPins | public function getGPIOPins()
{
if(true === in_array($this->revision, ['a01041', 'a21041', 'a22042'], true)) {
// Pi 2 revs
return range(2, 27);
}
if(true === in_array($this->revision, ['a02082', 'a22082', 'a32082'], true)) {
// Pi 3 revs
return range(2, 27);
}
// Pi 1 revs
return [0, 1, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 21, 22, 23, 25];
} | php | public function getGPIOPins()
{
if(true === in_array($this->revision, ['a01041', 'a21041', 'a22042'], true)) {
// Pi 2 revs
return range(2, 27);
}
if(true === in_array($this->revision, ['a02082', 'a22082', 'a32082'], true)) {
// Pi 3 revs
return range(2, 27);
}
// Pi 1 revs
return [0, 1, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 21, 22, 23, 25];
} | [
"public",
"function",
"getGPIOPins",
"(",
")",
"{",
"if",
"(",
"true",
"===",
"in_array",
"(",
"$",
"this",
"->",
"revision",
",",
"[",
"'a01041'",
",",
"'a21041'",
",",
"'a22042'",
"]",
",",
"true",
")",
")",
"{",
"// Pi 2 revs",
"return",
"range",
"(",
"2",
",",
"27",
")",
";",
"}",
"if",
"(",
"true",
"===",
"in_array",
"(",
"$",
"this",
"->",
"revision",
",",
"[",
"'a02082'",
",",
"'a22082'",
",",
"'a32082'",
"]",
",",
"true",
")",
")",
"{",
"// Pi 3 revs",
"return",
"range",
"(",
"2",
",",
"27",
")",
";",
"}",
"// Pi 1 revs",
"return",
"[",
"0",
",",
"1",
",",
"4",
",",
"7",
",",
"8",
",",
"9",
",",
"10",
",",
"11",
",",
"14",
",",
"15",
",",
"17",
",",
"18",
",",
"21",
",",
"22",
",",
"23",
",",
"25",
"]",
";",
"}"
] | Get the valid GPIO pin map
@return array | [
"Get",
"the",
"valid",
"GPIO",
"pin",
"map"
] | afde198a37dcf9f1558313cfcd29b813e6d746a8 | https://github.com/TiMESPLiNTER/gphpio/blob/afde198a37dcf9f1558313cfcd29b813e6d746a8/src/RPi.php#L64-L78 | train |
TiMESPLiNTER/gphpio | src/RPi.php | RPi.getName | public function getName()
{
if(false === isset(self::$modelNameMap[$this->revision])) {
return 'unknown';
}
return self::$modelNameMap[$this->revision];
} | php | public function getName()
{
if(false === isset(self::$modelNameMap[$this->revision])) {
return 'unknown';
}
return self::$modelNameMap[$this->revision];
} | [
"public",
"function",
"getName",
"(",
")",
"{",
"if",
"(",
"false",
"===",
"isset",
"(",
"self",
"::",
"$",
"modelNameMap",
"[",
"$",
"this",
"->",
"revision",
"]",
")",
")",
"{",
"return",
"'unknown'",
";",
"}",
"return",
"self",
"::",
"$",
"modelNameMap",
"[",
"$",
"this",
"->",
"revision",
"]",
";",
"}"
] | Get the revision name
@return string | [
"Get",
"the",
"revision",
"name"
] | afde198a37dcf9f1558313cfcd29b813e6d746a8 | https://github.com/TiMESPLiNTER/gphpio/blob/afde198a37dcf9f1558313cfcd29b813e6d746a8/src/RPi.php#L85-L92 | train |
linuxjuggler/lumen-make | src/Commands/ModelMakeCommand.php | ModelMakeCommand.createFactory | protected function createFactory()
{
$factory = Str::studly(class_basename($this->argument('name')));
$this->call('make:factory', [
'name' => "{$factory}Factory",
'--model' => $this->argument('name'),
]);
} | php | protected function createFactory()
{
$factory = Str::studly(class_basename($this->argument('name')));
$this->call('make:factory', [
'name' => "{$factory}Factory",
'--model' => $this->argument('name'),
]);
} | [
"protected",
"function",
"createFactory",
"(",
")",
"{",
"$",
"factory",
"=",
"Str",
"::",
"studly",
"(",
"class_basename",
"(",
"$",
"this",
"->",
"argument",
"(",
"'name'",
")",
")",
")",
";",
"$",
"this",
"->",
"call",
"(",
"'make:factory'",
",",
"[",
"'name'",
"=>",
"\"{$factory}Factory\"",
",",
"'--model'",
"=>",
"$",
"this",
"->",
"argument",
"(",
"'name'",
")",
",",
"]",
")",
";",
"}"
] | Create a model factory for the model. | [
"Create",
"a",
"model",
"factory",
"for",
"the",
"model",
"."
] | 80e794f78957ea56770a1b27c0f7160d0b7ea76d | https://github.com/linuxjuggler/lumen-make/blob/80e794f78957ea56770a1b27c0f7160d0b7ea76d/src/Commands/ModelMakeCommand.php#L64-L72 | train |
itcreator/custom-cmf | Module/Captcha/src/Cmf/Captcha/Captcha.php | Captcha.generateCode | public function generateCode()
{
$this->digits[0] = rand(0, 9);
$this->digits[1] = rand(0, 9);
$this->digits[2] = rand(0, 9);
$this->digits[3] = rand(0, 9);
$this->digits[4] = rand(0, 9);
$this->value = $this->digits[0] * 10000 + $this->digits[1] * 1000;
$this->value += $this->digits[2] * 100 + $this->digits[3] * 10 + $this->digits[4];
$this->xorValue = $this->value ^ $this->config->codeKey;
$_SESSION['captcha'] = $this->xorValue;
return $this;
} | php | public function generateCode()
{
$this->digits[0] = rand(0, 9);
$this->digits[1] = rand(0, 9);
$this->digits[2] = rand(0, 9);
$this->digits[3] = rand(0, 9);
$this->digits[4] = rand(0, 9);
$this->value = $this->digits[0] * 10000 + $this->digits[1] * 1000;
$this->value += $this->digits[2] * 100 + $this->digits[3] * 10 + $this->digits[4];
$this->xorValue = $this->value ^ $this->config->codeKey;
$_SESSION['captcha'] = $this->xorValue;
return $this;
} | [
"public",
"function",
"generateCode",
"(",
")",
"{",
"$",
"this",
"->",
"digits",
"[",
"0",
"]",
"=",
"rand",
"(",
"0",
",",
"9",
")",
";",
"$",
"this",
"->",
"digits",
"[",
"1",
"]",
"=",
"rand",
"(",
"0",
",",
"9",
")",
";",
"$",
"this",
"->",
"digits",
"[",
"2",
"]",
"=",
"rand",
"(",
"0",
",",
"9",
")",
";",
"$",
"this",
"->",
"digits",
"[",
"3",
"]",
"=",
"rand",
"(",
"0",
",",
"9",
")",
";",
"$",
"this",
"->",
"digits",
"[",
"4",
"]",
"=",
"rand",
"(",
"0",
",",
"9",
")",
";",
"$",
"this",
"->",
"value",
"=",
"$",
"this",
"->",
"digits",
"[",
"0",
"]",
"*",
"10000",
"+",
"$",
"this",
"->",
"digits",
"[",
"1",
"]",
"*",
"1000",
";",
"$",
"this",
"->",
"value",
"+=",
"$",
"this",
"->",
"digits",
"[",
"2",
"]",
"*",
"100",
"+",
"$",
"this",
"->",
"digits",
"[",
"3",
"]",
"*",
"10",
"+",
"$",
"this",
"->",
"digits",
"[",
"4",
"]",
";",
"$",
"this",
"->",
"xorValue",
"=",
"$",
"this",
"->",
"value",
"^",
"$",
"this",
"->",
"config",
"->",
"codeKey",
";",
"$",
"_SESSION",
"[",
"'captcha'",
"]",
"=",
"$",
"this",
"->",
"xorValue",
";",
"return",
"$",
"this",
";",
"}"
] | generate captcha value
@return Captcha | [
"generate",
"captcha",
"value"
] | 42fc0535dfa0f641856f06673f6ab596b2020c40 | https://github.com/itcreator/custom-cmf/blob/42fc0535dfa0f641856f06673f6ab596b2020c40/Module/Captcha/src/Cmf/Captcha/Captcha.php#L40-L53 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.