id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
|
---|---|---|---|---|---|---|---|---|---|---|---|
9,300 | kambo-1st/KamboRouter | src/Dispatcher/ClassAutoBind.php | ClassAutoBind.dispatchNotFound | public function dispatchNotFound()
{
if (isset($this->notFoundHandler)) {
$notFoundHandler = $this->notFoundHandler;
$controllerName = implode(
'\\',
[
$this->baseNamespace,
$this->controllerName,
$notFoundHandler['controler']
]
);
$controllerInstance = new $controllerName();
return call_user_func(
[
$controllerInstance,
$this->actionName.$notFoundHandler['action']
]
);
}
return null;
} | php | public function dispatchNotFound()
{
if (isset($this->notFoundHandler)) {
$notFoundHandler = $this->notFoundHandler;
$controllerName = implode(
'\\',
[
$this->baseNamespace,
$this->controllerName,
$notFoundHandler['controler']
]
);
$controllerInstance = new $controllerName();
return call_user_func(
[
$controllerInstance,
$this->actionName.$notFoundHandler['action']
]
);
}
return null;
} | [
"public",
"function",
"dispatchNotFound",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"notFoundHandler",
")",
")",
"{",
"$",
"notFoundHandler",
"=",
"$",
"this",
"->",
"notFoundHandler",
";",
"$",
"controllerName",
"=",
"implode",
"(",
"'\\\\'",
",",
"[",
"$",
"this",
"->",
"baseNamespace",
",",
"$",
"this",
"->",
"controllerName",
",",
"$",
"notFoundHandler",
"[",
"'controler'",
"]",
"]",
")",
";",
"$",
"controllerInstance",
"=",
"new",
"$",
"controllerName",
"(",
")",
";",
"return",
"call_user_func",
"(",
"[",
"$",
"controllerInstance",
",",
"$",
"this",
"->",
"actionName",
".",
"$",
"notFoundHandler",
"[",
"'action'",
"]",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Called if any of route did not match the request.
@return mixed | [
"Called",
"if",
"any",
"of",
"route",
"did",
"not",
"match",
"the",
"request",
"."
] | 32ad63ab1c5483714868d5acbbc67beb2f0b1cda | https://github.com/kambo-1st/KamboRouter/blob/32ad63ab1c5483714868d5acbbc67beb2f0b1cda/src/Dispatcher/ClassAutoBind.php#L113-L137 |
9,301 | kambo-1st/KamboRouter | src/Dispatcher/ClassAutoBind.php | ClassAutoBind.transformHandler | private function transformHandler($matches, $parameters, $handler)
{
$transformed = [];
foreach ($handler as $target => $placeholder) {
foreach ($parameters as $key => $parameterName) {
if ($parameterName[0][0] == $placeholder) {
if ($target == 'controler') {
$transformed[$target] = $matches[$key].'Controler';
} else {
$transformed[$target] = $matches[$key];
}
}
}
}
return $transformed;
} | php | private function transformHandler($matches, $parameters, $handler)
{
$transformed = [];
foreach ($handler as $target => $placeholder) {
foreach ($parameters as $key => $parameterName) {
if ($parameterName[0][0] == $placeholder) {
if ($target == 'controler') {
$transformed[$target] = $matches[$key].'Controler';
} else {
$transformed[$target] = $matches[$key];
}
}
}
}
return $transformed;
} | [
"private",
"function",
"transformHandler",
"(",
"$",
"matches",
",",
"$",
"parameters",
",",
"$",
"handler",
")",
"{",
"$",
"transformed",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"handler",
"as",
"$",
"target",
"=>",
"$",
"placeholder",
")",
"{",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"key",
"=>",
"$",
"parameterName",
")",
"{",
"if",
"(",
"$",
"parameterName",
"[",
"0",
"]",
"[",
"0",
"]",
"==",
"$",
"placeholder",
")",
"{",
"if",
"(",
"$",
"target",
"==",
"'controler'",
")",
"{",
"$",
"transformed",
"[",
"$",
"target",
"]",
"=",
"$",
"matches",
"[",
"$",
"key",
"]",
".",
"'Controler'",
";",
"}",
"else",
"{",
"$",
"transformed",
"[",
"$",
"target",
"]",
"=",
"$",
"matches",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"transformed",
";",
"}"
] | Transform provided handler with variables and parameters
@param mixed $matches found matched variables
@param mixed $parameters route parameters
@param mixed $handler handler that should be executed
@return mixed | [
"Transform",
"provided",
"handler",
"with",
"variables",
"and",
"parameters"
] | 32ad63ab1c5483714868d5acbbc67beb2f0b1cda | https://github.com/kambo-1st/KamboRouter/blob/32ad63ab1c5483714868d5acbbc67beb2f0b1cda/src/Dispatcher/ClassAutoBind.php#L214-L230 |
9,302 | kambo-1st/KamboRouter | src/Dispatcher/ClassAutoBind.php | ClassAutoBind.resolveNamespace | private function resolveNamespace($parameters, $handler, $matches)
{
if (isset($handler['module'])) {
$moduleName = $handler['module'];
if ($this->isPlaceholder($moduleName)) {
foreach ($handler as $target => $placeholder) {
foreach ($parameters as $key => $parameterName) {
if ($parameterName[0][0] == $placeholder) {
if ($target == 'module') {
$moduleName = $matches[$key];
}
}
}
}
}
return implode(
'\\',
[
$this->baseNamespace,
$this->moduleName,
$moduleName,
$this->controllerName
]
);
}
return $this->baseNamespace.'\\'.$this->controllerName;
} | php | private function resolveNamespace($parameters, $handler, $matches)
{
if (isset($handler['module'])) {
$moduleName = $handler['module'];
if ($this->isPlaceholder($moduleName)) {
foreach ($handler as $target => $placeholder) {
foreach ($parameters as $key => $parameterName) {
if ($parameterName[0][0] == $placeholder) {
if ($target == 'module') {
$moduleName = $matches[$key];
}
}
}
}
}
return implode(
'\\',
[
$this->baseNamespace,
$this->moduleName,
$moduleName,
$this->controllerName
]
);
}
return $this->baseNamespace.'\\'.$this->controllerName;
} | [
"private",
"function",
"resolveNamespace",
"(",
"$",
"parameters",
",",
"$",
"handler",
",",
"$",
"matches",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"handler",
"[",
"'module'",
"]",
")",
")",
"{",
"$",
"moduleName",
"=",
"$",
"handler",
"[",
"'module'",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"isPlaceholder",
"(",
"$",
"moduleName",
")",
")",
"{",
"foreach",
"(",
"$",
"handler",
"as",
"$",
"target",
"=>",
"$",
"placeholder",
")",
"{",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"key",
"=>",
"$",
"parameterName",
")",
"{",
"if",
"(",
"$",
"parameterName",
"[",
"0",
"]",
"[",
"0",
"]",
"==",
"$",
"placeholder",
")",
"{",
"if",
"(",
"$",
"target",
"==",
"'module'",
")",
"{",
"$",
"moduleName",
"=",
"$",
"matches",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"implode",
"(",
"'\\\\'",
",",
"[",
"$",
"this",
"->",
"baseNamespace",
",",
"$",
"this",
"->",
"moduleName",
",",
"$",
"moduleName",
",",
"$",
"this",
"->",
"controllerName",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"baseNamespace",
".",
"'\\\\'",
".",
"$",
"this",
"->",
"controllerName",
";",
"}"
] | Resolve proper namespace according parameters, handler and matches
@param mixed $parameters route parameters
@param mixed $handler handler that should be executed
@param mixed $matches found matched variables
@return mixed | [
"Resolve",
"proper",
"namespace",
"according",
"parameters",
"handler",
"and",
"matches"
] | 32ad63ab1c5483714868d5acbbc67beb2f0b1cda | https://github.com/kambo-1st/KamboRouter/blob/32ad63ab1c5483714868d5acbbc67beb2f0b1cda/src/Dispatcher/ClassAutoBind.php#L241-L269 |
9,303 | kambo-1st/KamboRouter | src/Dispatcher/ClassAutoBind.php | ClassAutoBind.isPlaceholder | private function isPlaceholder(string $value) : bool
{
if (strrchr($value, '}') && (0 === strpos($value, '{'))) {
return true;
}
return false;
} | php | private function isPlaceholder(string $value) : bool
{
if (strrchr($value, '}') && (0 === strpos($value, '{'))) {
return true;
}
return false;
} | [
"private",
"function",
"isPlaceholder",
"(",
"string",
"$",
"value",
")",
":",
"bool",
"{",
"if",
"(",
"strrchr",
"(",
"$",
"value",
",",
"'}'",
")",
"&&",
"(",
"0",
"===",
"strpos",
"(",
"$",
"value",
",",
"'{'",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Check if the variable is placeholder
@param string $value found route
@return boolean true if value should be transfered | [
"Check",
"if",
"the",
"variable",
"is",
"placeholder"
] | 32ad63ab1c5483714868d5acbbc67beb2f0b1cda | https://github.com/kambo-1st/KamboRouter/blob/32ad63ab1c5483714868d5acbbc67beb2f0b1cda/src/Dispatcher/ClassAutoBind.php#L278-L285 |
9,304 | kambo-1st/KamboRouter | src/Dispatcher/ClassAutoBind.php | ClassAutoBind.getFunctionArgumentsControlers | private function getFunctionArgumentsControlers(
$paramMap,
$matches,
$parameters,
$handlers
) {
$output = [];
$matches = array_values($matches);
if (isset($parameters)) {
foreach ($handlers as $placeholder) {
if ($this->isPlaceholder($placeholder)) {
foreach ($parameters as $key => $parameterName) {
if ($parameterName[0][0] == $placeholder) {
unset($parameters[$key]);
unset($matches[$key]);
}
}
}
}
$parameters = array_values($parameters);
$matches = array_values($matches);
foreach ($parameters as $key => $valueName) {
foreach ($paramMap as $possition => $value) {
if ($value == $valueName[1][0]) {
$output[] = $matches[$possition];
}
}
}
}
return $output;
} | php | private function getFunctionArgumentsControlers(
$paramMap,
$matches,
$parameters,
$handlers
) {
$output = [];
$matches = array_values($matches);
if (isset($parameters)) {
foreach ($handlers as $placeholder) {
if ($this->isPlaceholder($placeholder)) {
foreach ($parameters as $key => $parameterName) {
if ($parameterName[0][0] == $placeholder) {
unset($parameters[$key]);
unset($matches[$key]);
}
}
}
}
$parameters = array_values($parameters);
$matches = array_values($matches);
foreach ($parameters as $key => $valueName) {
foreach ($paramMap as $possition => $value) {
if ($value == $valueName[1][0]) {
$output[] = $matches[$possition];
}
}
}
}
return $output;
} | [
"private",
"function",
"getFunctionArgumentsControlers",
"(",
"$",
"paramMap",
",",
"$",
"matches",
",",
"$",
"parameters",
",",
"$",
"handlers",
")",
"{",
"$",
"output",
"=",
"[",
"]",
";",
"$",
"matches",
"=",
"array_values",
"(",
"$",
"matches",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"parameters",
")",
")",
"{",
"foreach",
"(",
"$",
"handlers",
"as",
"$",
"placeholder",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isPlaceholder",
"(",
"$",
"placeholder",
")",
")",
"{",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"key",
"=>",
"$",
"parameterName",
")",
"{",
"if",
"(",
"$",
"parameterName",
"[",
"0",
"]",
"[",
"0",
"]",
"==",
"$",
"placeholder",
")",
"{",
"unset",
"(",
"$",
"parameters",
"[",
"$",
"key",
"]",
")",
";",
"unset",
"(",
"$",
"matches",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"}",
"}",
"$",
"parameters",
"=",
"array_values",
"(",
"$",
"parameters",
")",
";",
"$",
"matches",
"=",
"array_values",
"(",
"$",
"matches",
")",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"key",
"=>",
"$",
"valueName",
")",
"{",
"foreach",
"(",
"$",
"paramMap",
"as",
"$",
"possition",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"==",
"$",
"valueName",
"[",
"1",
"]",
"[",
"0",
"]",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"$",
"matches",
"[",
"$",
"possition",
"]",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"output",
";",
"}"
] | Get function arguments for controler
@param mixed $paramMap parameter map
@param mixed $matches found matched variables
@param mixed $parameters route parameters
@param mixed $handlers handler that should be executed
@return mixed | [
"Get",
"function",
"arguments",
"for",
"controler"
] | 32ad63ab1c5483714868d5acbbc67beb2f0b1cda | https://github.com/kambo-1st/KamboRouter/blob/32ad63ab1c5483714868d5acbbc67beb2f0b1cda/src/Dispatcher/ClassAutoBind.php#L297-L331 |
9,305 | kambo-1st/KamboRouter | src/Dispatcher/ClassAutoBind.php | ClassAutoBind.getMethodParameters | private function getMethodParameters(string $class, string $methodName) : array
{
$methodReflection = new ReflectionMethod($class, $methodName);
$parametersName = [];
foreach ($methodReflection->getParameters() as $parameter) {
$parametersName[] = $parameter->name;
}
return $parametersName;
} | php | private function getMethodParameters(string $class, string $methodName) : array
{
$methodReflection = new ReflectionMethod($class, $methodName);
$parametersName = [];
foreach ($methodReflection->getParameters() as $parameter) {
$parametersName[] = $parameter->name;
}
return $parametersName;
} | [
"private",
"function",
"getMethodParameters",
"(",
"string",
"$",
"class",
",",
"string",
"$",
"methodName",
")",
":",
"array",
"{",
"$",
"methodReflection",
"=",
"new",
"ReflectionMethod",
"(",
"$",
"class",
",",
"$",
"methodName",
")",
";",
"$",
"parametersName",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"methodReflection",
"->",
"getParameters",
"(",
")",
"as",
"$",
"parameter",
")",
"{",
"$",
"parametersName",
"[",
"]",
"=",
"$",
"parameter",
"->",
"name",
";",
"}",
"return",
"$",
"parametersName",
";",
"}"
] | Get names of parameters for provided class and method
@param string $class name of class
@param string $methodName name of method
@return array | [
"Get",
"names",
"of",
"parameters",
"for",
"provided",
"class",
"and",
"method"
] | 32ad63ab1c5483714868d5acbbc67beb2f0b1cda | https://github.com/kambo-1st/KamboRouter/blob/32ad63ab1c5483714868d5acbbc67beb2f0b1cda/src/Dispatcher/ClassAutoBind.php#L341-L351 |
9,306 | gpupo/Coordinate | src/Gpupo/Coordinate/Conversion.php | Conversion.setDMS | public function setDMS($string)
{
$string = preg_replace(
"/[^a-zA-Z0-9,.\s]/",
' ',
trim($string)
);
$string = str_replace(
array('S', 'N', 'E', 'W'),
array(' S', ' N', ' E', ' W'),
strtoupper($string)
);
$string = preg_replace(
'/\s+/',
' ',
$string
);
$this->dms = explode(' ',$string);
} | php | public function setDMS($string)
{
$string = preg_replace(
"/[^a-zA-Z0-9,.\s]/",
' ',
trim($string)
);
$string = str_replace(
array('S', 'N', 'E', 'W'),
array(' S', ' N', ' E', ' W'),
strtoupper($string)
);
$string = preg_replace(
'/\s+/',
' ',
$string
);
$this->dms = explode(' ',$string);
} | [
"public",
"function",
"setDMS",
"(",
"$",
"string",
")",
"{",
"$",
"string",
"=",
"preg_replace",
"(",
"\"/[^a-zA-Z0-9,.\\s]/\"",
",",
"' '",
",",
"trim",
"(",
"$",
"string",
")",
")",
";",
"$",
"string",
"=",
"str_replace",
"(",
"array",
"(",
"'S'",
",",
"'N'",
",",
"'E'",
",",
"'W'",
")",
",",
"array",
"(",
"' S'",
",",
"' N'",
",",
"' E'",
",",
"' W'",
")",
",",
"strtoupper",
"(",
"$",
"string",
")",
")",
";",
"$",
"string",
"=",
"preg_replace",
"(",
"'/\\s+/'",
",",
"' '",
",",
"$",
"string",
")",
";",
"$",
"this",
"->",
"dms",
"=",
"explode",
"(",
"' '",
",",
"$",
"string",
")",
";",
"}"
] | Clean input DMS and set as array. | [
"Clean",
"input",
"DMS",
"and",
"set",
"as",
"array",
"."
] | 7a1725d56dcbf0e6f881e51ba3f3d6a72c7d5946 | https://github.com/gpupo/Coordinate/blob/7a1725d56dcbf0e6f881e51ba3f3d6a72c7d5946/src/Gpupo/Coordinate/Conversion.php#L118-L140 |
9,307 | athena-oss/php-fluent-webdriver-client | src/Browser/BrowserDriverBuilder.php | BrowserDriverBuilder.withProxySettings | public function withProxySettings($proxySettings)
{
if (!empty($proxySettings)) {
$this->extraCapabilities[WebDriverCapabilityType::PROXY] = [
'proxyType' => $proxySettings['proxyType'],
'httpProxy' => $proxySettings['httpProxy'],
'sslProxy' => $proxySettings['sslProxy'],
];
}
return $this;
} | php | public function withProxySettings($proxySettings)
{
if (!empty($proxySettings)) {
$this->extraCapabilities[WebDriverCapabilityType::PROXY] = [
'proxyType' => $proxySettings['proxyType'],
'httpProxy' => $proxySettings['httpProxy'],
'sslProxy' => $proxySettings['sslProxy'],
];
}
return $this;
} | [
"public",
"function",
"withProxySettings",
"(",
"$",
"proxySettings",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"proxySettings",
")",
")",
"{",
"$",
"this",
"->",
"extraCapabilities",
"[",
"WebDriverCapabilityType",
"::",
"PROXY",
"]",
"=",
"[",
"'proxyType'",
"=>",
"$",
"proxySettings",
"[",
"'proxyType'",
"]",
",",
"'httpProxy'",
"=>",
"$",
"proxySettings",
"[",
"'httpProxy'",
"]",
",",
"'sslProxy'",
"=>",
"$",
"proxySettings",
"[",
"'sslProxy'",
"]",
",",
"]",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets the given proxy settings and returns self.
@param array $proxySettings
@return $this | [
"Sets",
"the",
"given",
"proxy",
"settings",
"and",
"returns",
"self",
"."
] | 0b4cca15ab876bd9af40c115728fafce08ce3472 | https://github.com/athena-oss/php-fluent-webdriver-client/blob/0b4cca15ab876bd9af40c115728fafce08ce3472/src/Browser/BrowserDriverBuilder.php#L93-L103 |
9,308 | athena-oss/php-fluent-webdriver-client | src/Browser/BrowserDriverBuilder.php | BrowserDriverBuilder.build | public function build()
{
$capabilities = $this->makeCapabilities($this->type, $this->extraCapabilities);
$this->remoteWebDriver = RemoteWebDriver::create(
$this->url,
$capabilities,
$this->connectionTimeout,
$this->requestTimeout
);
// define web driver configurations before being decorated
if ($this->implicitTimeout > 0) {
$this->remoteWebDriver->manage()->timeouts()->implicitlyWait($this->implicitTimeout);
}
// translator
$baseUrlId = UrlTranslator::BASE_URL_IDENTIFIER;
$baseUrl = array_key_exists($baseUrlId, $this->urls) ? $this->urls[$baseUrlId] : null;
$this->urlTranslator = new UrlTranslator($this->urls, $baseUrl);
return $this;
} | php | public function build()
{
$capabilities = $this->makeCapabilities($this->type, $this->extraCapabilities);
$this->remoteWebDriver = RemoteWebDriver::create(
$this->url,
$capabilities,
$this->connectionTimeout,
$this->requestTimeout
);
// define web driver configurations before being decorated
if ($this->implicitTimeout > 0) {
$this->remoteWebDriver->manage()->timeouts()->implicitlyWait($this->implicitTimeout);
}
// translator
$baseUrlId = UrlTranslator::BASE_URL_IDENTIFIER;
$baseUrl = array_key_exists($baseUrlId, $this->urls) ? $this->urls[$baseUrlId] : null;
$this->urlTranslator = new UrlTranslator($this->urls, $baseUrl);
return $this;
} | [
"public",
"function",
"build",
"(",
")",
"{",
"$",
"capabilities",
"=",
"$",
"this",
"->",
"makeCapabilities",
"(",
"$",
"this",
"->",
"type",
",",
"$",
"this",
"->",
"extraCapabilities",
")",
";",
"$",
"this",
"->",
"remoteWebDriver",
"=",
"RemoteWebDriver",
"::",
"create",
"(",
"$",
"this",
"->",
"url",
",",
"$",
"capabilities",
",",
"$",
"this",
"->",
"connectionTimeout",
",",
"$",
"this",
"->",
"requestTimeout",
")",
";",
"// define web driver configurations before being decorated",
"if",
"(",
"$",
"this",
"->",
"implicitTimeout",
">",
"0",
")",
"{",
"$",
"this",
"->",
"remoteWebDriver",
"->",
"manage",
"(",
")",
"->",
"timeouts",
"(",
")",
"->",
"implicitlyWait",
"(",
"$",
"this",
"->",
"implicitTimeout",
")",
";",
"}",
"// translator",
"$",
"baseUrlId",
"=",
"UrlTranslator",
"::",
"BASE_URL_IDENTIFIER",
";",
"$",
"baseUrl",
"=",
"array_key_exists",
"(",
"$",
"baseUrlId",
",",
"$",
"this",
"->",
"urls",
")",
"?",
"$",
"this",
"->",
"urls",
"[",
"$",
"baseUrlId",
"]",
":",
"null",
";",
"$",
"this",
"->",
"urlTranslator",
"=",
"new",
"UrlTranslator",
"(",
"$",
"this",
"->",
"urls",
",",
"$",
"baseUrl",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Builds a Facebook RemoteWebDriver.
@throws UnsupportedBrowserException
@return $this | [
"Builds",
"a",
"Facebook",
"RemoteWebDriver",
"."
] | 0b4cca15ab876bd9af40c115728fafce08ce3472 | https://github.com/athena-oss/php-fluent-webdriver-client/blob/0b4cca15ab876bd9af40c115728fafce08ce3472/src/Browser/BrowserDriverBuilder.php#L184-L206 |
9,309 | Flowpack/Flowpack.SingleSignOn.Server | Classes/Flowpack/SingleSignOn/Server/Service/AccountManager.php | AccountManager.impersonateAccount | public function impersonateAccount(\TYPO3\Flow\Security\Account $account = NULL) {
if ($this->impersonatedAccount !== $account) {
$this->impersonatedAccount = $account;
$this->destroyRegisteredClientSessions();
$this->emitAccountImpersonated($account);
}
} | php | public function impersonateAccount(\TYPO3\Flow\Security\Account $account = NULL) {
if ($this->impersonatedAccount !== $account) {
$this->impersonatedAccount = $account;
$this->destroyRegisteredClientSessions();
$this->emitAccountImpersonated($account);
}
} | [
"public",
"function",
"impersonateAccount",
"(",
"\\",
"TYPO3",
"\\",
"Flow",
"\\",
"Security",
"\\",
"Account",
"$",
"account",
"=",
"NULL",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"impersonatedAccount",
"!==",
"$",
"account",
")",
"{",
"$",
"this",
"->",
"impersonatedAccount",
"=",
"$",
"account",
";",
"$",
"this",
"->",
"destroyRegisteredClientSessions",
"(",
")",
";",
"$",
"this",
"->",
"emitAccountImpersonated",
"(",
"$",
"account",
")",
";",
"}",
"}"
] | Impersonate another account
Destroys registered client sessions to force re-authentication.
@param \TYPO3\Flow\Security\Account $account
@return void | [
"Impersonate",
"another",
"account"
] | b1fa014f31d0d101a79cb95d5585b9973f35347d | https://github.com/Flowpack/Flowpack.SingleSignOn.Server/blob/b1fa014f31d0d101a79cb95d5585b9973f35347d/Classes/Flowpack/SingleSignOn/Server/Service/AccountManager.php#L77-L85 |
9,310 | pletfix/core | src/Handlers/ExceptionHandler.php | ExceptionHandler.handleForConsole | private function handleForConsole(Exception $e)
{
if ($e instanceof StopException) {
$output = $e->getMessage();
}
else {
$data = $this->convertException($e);
$class = get_class($e);
$file = $this->stripFile($data['file']);
$line = $data['line'];
$code = $data['code'];
// set the error message
if ($e instanceof HttpException) {
$message = http_status_text($data['status']) . ' (' . $data['status'] . ')';
if (!empty($data['message'])) {
$message .= '. ' . $data['message'];
}
}
else if ($e instanceof QueryException) {
$message = $data['message'] . '; sql: ' . $data['sql'];
}
else {
$message = $data['message'];
}
$output = $class . ' in "' . $file . '", line ' . $line . ':' . PHP_EOL . $message . ' (code ' . $code . ')';
}
stdio()->error($output);
$exitCode = $e->getCode();
if ($exitCode === null) {
$exitCode = Command::EXIT_FAILURE;
}
exit ($exitCode);
} | php | private function handleForConsole(Exception $e)
{
if ($e instanceof StopException) {
$output = $e->getMessage();
}
else {
$data = $this->convertException($e);
$class = get_class($e);
$file = $this->stripFile($data['file']);
$line = $data['line'];
$code = $data['code'];
// set the error message
if ($e instanceof HttpException) {
$message = http_status_text($data['status']) . ' (' . $data['status'] . ')';
if (!empty($data['message'])) {
$message .= '. ' . $data['message'];
}
}
else if ($e instanceof QueryException) {
$message = $data['message'] . '; sql: ' . $data['sql'];
}
else {
$message = $data['message'];
}
$output = $class . ' in "' . $file . '", line ' . $line . ':' . PHP_EOL . $message . ' (code ' . $code . ')';
}
stdio()->error($output);
$exitCode = $e->getCode();
if ($exitCode === null) {
$exitCode = Command::EXIT_FAILURE;
}
exit ($exitCode);
} | [
"private",
"function",
"handleForConsole",
"(",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"e",
"instanceof",
"StopException",
")",
"{",
"$",
"output",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"convertException",
"(",
"$",
"e",
")",
";",
"$",
"class",
"=",
"get_class",
"(",
"$",
"e",
")",
";",
"$",
"file",
"=",
"$",
"this",
"->",
"stripFile",
"(",
"$",
"data",
"[",
"'file'",
"]",
")",
";",
"$",
"line",
"=",
"$",
"data",
"[",
"'line'",
"]",
";",
"$",
"code",
"=",
"$",
"data",
"[",
"'code'",
"]",
";",
"// set the error message",
"if",
"(",
"$",
"e",
"instanceof",
"HttpException",
")",
"{",
"$",
"message",
"=",
"http_status_text",
"(",
"$",
"data",
"[",
"'status'",
"]",
")",
".",
"' ('",
".",
"$",
"data",
"[",
"'status'",
"]",
".",
"')'",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"'message'",
"]",
")",
")",
"{",
"$",
"message",
".=",
"'. '",
".",
"$",
"data",
"[",
"'message'",
"]",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"e",
"instanceof",
"QueryException",
")",
"{",
"$",
"message",
"=",
"$",
"data",
"[",
"'message'",
"]",
".",
"'; sql: '",
".",
"$",
"data",
"[",
"'sql'",
"]",
";",
"}",
"else",
"{",
"$",
"message",
"=",
"$",
"data",
"[",
"'message'",
"]",
";",
"}",
"$",
"output",
"=",
"$",
"class",
".",
"' in \"'",
".",
"$",
"file",
".",
"'\", line '",
".",
"$",
"line",
".",
"':'",
".",
"PHP_EOL",
".",
"$",
"message",
".",
"' (code '",
".",
"$",
"code",
".",
"')'",
";",
"}",
"stdio",
"(",
")",
"->",
"error",
"(",
"$",
"output",
")",
";",
"$",
"exitCode",
"=",
"$",
"e",
"->",
"getCode",
"(",
")",
";",
"if",
"(",
"$",
"exitCode",
"===",
"null",
")",
"{",
"$",
"exitCode",
"=",
"Command",
"::",
"EXIT_FAILURE",
";",
"}",
"exit",
"(",
"$",
"exitCode",
")",
";",
"}"
] | Write a error message to the console and exit the script.
@param Exception $e | [
"Write",
"a",
"error",
"message",
"to",
"the",
"console",
"and",
"exit",
"the",
"script",
"."
] | 974945500f278eb6c1779832e08bbfca1007a7b3 | https://github.com/pletfix/core/blob/974945500f278eb6c1779832e08bbfca1007a7b3/src/Handlers/ExceptionHandler.php#L98-L135 |
9,311 | pletfix/core | src/Handlers/ExceptionHandler.php | ExceptionHandler.handleForBrowser | private function handleForBrowser(Exception $e)
{
// $request = request();
// if ($e instanceof ModelNotFoundException) {
// $e = new NotFoundHttpException($e->getMessage(), $e);
// }
// elseif ($e instanceof AuthorizationException) {
// $e = new HttpException(403, $e->getMessage());
// }
//
// if ($e instanceof HttpResponseException) {
// return $e->getResponse();
// }
// if ($e instanceof AuthenticationException) {
// header('Location: ' . url('auth/login'));
// exit;
// }
// else if ($e instanceof ValidationException) {
// return $this->convertValidationExceptionToResponse($e, $request);
// }
// else if ($request->isAjax() || $request->wantsJson()) {
// /** @var HttpException $e */
// return response()->json($e->getMessage(), $this->isHttpException($e) ? $e->getStatusCode() : 400);
// }
$data = $this->convertException($e);
// set error title and subtitle
if ($e instanceof HttpException) {
// set the HTTP Response Status Text as error title
$data['title'] = http_status_text($data['status']);
// set the Exception class and the HTTP Response Status Code as subtitle
$data['subtitle'] = get_class($e) . ', Status Code ' . $data['status'];
}
else if ($e instanceof QueryException) {
// set title
$data['title'] = 'SQL Error';
// set the Exception class and error codes as subtitle
$data['subtitle'] = get_class($e) . ' (Exception code: ' . $data['code'] . ')';
if ($data['ansiCode'] !== null) {
$data['subtitle'] .= ', ANSI SQLSTATE Error Code: ' . $data['ansiCode'];
}
if ($data['driverCode'] !== null) {
$data['subtitle'] .= ', Driver-specific Error Code: ' . $data['driverCode'];
}
}
else {
// set error title
$data['title'] = 'Error';
// // set the Exception class and the Exception code as subtitle
$data['subtitle'] = get_class($e) . ' (Exception code: ' . $data['code'] . ')';
}
// render the source code
if ($e instanceof QueryException) {
// parse the sql line from the message if exists
if (preg_match('/at line (\d)$/', $data['message'], $match)) {
$sqlLine = $match[1];
}
else {
$sqlLine = 0;
}
// set the SQL Statement as source
$data['source'] = $this->renderSQL($data['sql'], $sqlLine);
}
else {
// set the PHP Code as source
$data['source'] = $this->renderPHP($data['file'], $data['line']);
}
// render the trace
$data['trace'] = $this->renderTrace($data['trace']);
// strip the filename
$data['file'] = $this->stripFile($data['file']);
// choose the template
$view = config('app.debug') ? 'errors.debug' : 'errors.default';
if (!config('app.debug') && view()->exists('errors.' . $data['status'])) {
$view = 'errors.' . $data['status'];
}
// send the response
$headers = ($e instanceof HttpException) ? $e->getHeaders() : [];
return response()->view($view, $data, $data['status'], $headers)->send();
} | php | private function handleForBrowser(Exception $e)
{
// $request = request();
// if ($e instanceof ModelNotFoundException) {
// $e = new NotFoundHttpException($e->getMessage(), $e);
// }
// elseif ($e instanceof AuthorizationException) {
// $e = new HttpException(403, $e->getMessage());
// }
//
// if ($e instanceof HttpResponseException) {
// return $e->getResponse();
// }
// if ($e instanceof AuthenticationException) {
// header('Location: ' . url('auth/login'));
// exit;
// }
// else if ($e instanceof ValidationException) {
// return $this->convertValidationExceptionToResponse($e, $request);
// }
// else if ($request->isAjax() || $request->wantsJson()) {
// /** @var HttpException $e */
// return response()->json($e->getMessage(), $this->isHttpException($e) ? $e->getStatusCode() : 400);
// }
$data = $this->convertException($e);
// set error title and subtitle
if ($e instanceof HttpException) {
// set the HTTP Response Status Text as error title
$data['title'] = http_status_text($data['status']);
// set the Exception class and the HTTP Response Status Code as subtitle
$data['subtitle'] = get_class($e) . ', Status Code ' . $data['status'];
}
else if ($e instanceof QueryException) {
// set title
$data['title'] = 'SQL Error';
// set the Exception class and error codes as subtitle
$data['subtitle'] = get_class($e) . ' (Exception code: ' . $data['code'] . ')';
if ($data['ansiCode'] !== null) {
$data['subtitle'] .= ', ANSI SQLSTATE Error Code: ' . $data['ansiCode'];
}
if ($data['driverCode'] !== null) {
$data['subtitle'] .= ', Driver-specific Error Code: ' . $data['driverCode'];
}
}
else {
// set error title
$data['title'] = 'Error';
// // set the Exception class and the Exception code as subtitle
$data['subtitle'] = get_class($e) . ' (Exception code: ' . $data['code'] . ')';
}
// render the source code
if ($e instanceof QueryException) {
// parse the sql line from the message if exists
if (preg_match('/at line (\d)$/', $data['message'], $match)) {
$sqlLine = $match[1];
}
else {
$sqlLine = 0;
}
// set the SQL Statement as source
$data['source'] = $this->renderSQL($data['sql'], $sqlLine);
}
else {
// set the PHP Code as source
$data['source'] = $this->renderPHP($data['file'], $data['line']);
}
// render the trace
$data['trace'] = $this->renderTrace($data['trace']);
// strip the filename
$data['file'] = $this->stripFile($data['file']);
// choose the template
$view = config('app.debug') ? 'errors.debug' : 'errors.default';
if (!config('app.debug') && view()->exists('errors.' . $data['status'])) {
$view = 'errors.' . $data['status'];
}
// send the response
$headers = ($e instanceof HttpException) ? $e->getHeaders() : [];
return response()->view($view, $data, $data['status'], $headers)->send();
} | [
"private",
"function",
"handleForBrowser",
"(",
"Exception",
"$",
"e",
")",
"{",
"// $request = request();",
"// if ($e instanceof ModelNotFoundException) {",
"// $e = new NotFoundHttpException($e->getMessage(), $e);",
"// }",
"// elseif ($e instanceof AuthorizationException) {",
"// $e = new HttpException(403, $e->getMessage());",
"// }",
"//",
"// if ($e instanceof HttpResponseException) {",
"// return $e->getResponse();",
"// }",
"// if ($e instanceof AuthenticationException) {",
"// header('Location: ' . url('auth/login'));",
"// exit;",
"// }",
"// else if ($e instanceof ValidationException) {",
"// return $this->convertValidationExceptionToResponse($e, $request);",
"// }",
"// else if ($request->isAjax() || $request->wantsJson()) {",
"// /** @var HttpException $e */",
"// return response()->json($e->getMessage(), $this->isHttpException($e) ? $e->getStatusCode() : 400);",
"// }",
"$",
"data",
"=",
"$",
"this",
"->",
"convertException",
"(",
"$",
"e",
")",
";",
"// set error title and subtitle",
"if",
"(",
"$",
"e",
"instanceof",
"HttpException",
")",
"{",
"// set the HTTP Response Status Text as error title",
"$",
"data",
"[",
"'title'",
"]",
"=",
"http_status_text",
"(",
"$",
"data",
"[",
"'status'",
"]",
")",
";",
"// set the Exception class and the HTTP Response Status Code as subtitle",
"$",
"data",
"[",
"'subtitle'",
"]",
"=",
"get_class",
"(",
"$",
"e",
")",
".",
"', Status Code '",
".",
"$",
"data",
"[",
"'status'",
"]",
";",
"}",
"else",
"if",
"(",
"$",
"e",
"instanceof",
"QueryException",
")",
"{",
"// set title",
"$",
"data",
"[",
"'title'",
"]",
"=",
"'SQL Error'",
";",
"// set the Exception class and error codes as subtitle",
"$",
"data",
"[",
"'subtitle'",
"]",
"=",
"get_class",
"(",
"$",
"e",
")",
".",
"' (Exception code: '",
".",
"$",
"data",
"[",
"'code'",
"]",
".",
"')'",
";",
"if",
"(",
"$",
"data",
"[",
"'ansiCode'",
"]",
"!==",
"null",
")",
"{",
"$",
"data",
"[",
"'subtitle'",
"]",
".=",
"', ANSI SQLSTATE Error Code: '",
".",
"$",
"data",
"[",
"'ansiCode'",
"]",
";",
"}",
"if",
"(",
"$",
"data",
"[",
"'driverCode'",
"]",
"!==",
"null",
")",
"{",
"$",
"data",
"[",
"'subtitle'",
"]",
".=",
"', Driver-specific Error Code: '",
".",
"$",
"data",
"[",
"'driverCode'",
"]",
";",
"}",
"}",
"else",
"{",
"// set error title",
"$",
"data",
"[",
"'title'",
"]",
"=",
"'Error'",
";",
"// // set the Exception class and the Exception code as subtitle",
"$",
"data",
"[",
"'subtitle'",
"]",
"=",
"get_class",
"(",
"$",
"e",
")",
".",
"' (Exception code: '",
".",
"$",
"data",
"[",
"'code'",
"]",
".",
"')'",
";",
"}",
"// render the source code",
"if",
"(",
"$",
"e",
"instanceof",
"QueryException",
")",
"{",
"// parse the sql line from the message if exists",
"if",
"(",
"preg_match",
"(",
"'/at line (\\d)$/'",
",",
"$",
"data",
"[",
"'message'",
"]",
",",
"$",
"match",
")",
")",
"{",
"$",
"sqlLine",
"=",
"$",
"match",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"$",
"sqlLine",
"=",
"0",
";",
"}",
"// set the SQL Statement as source",
"$",
"data",
"[",
"'source'",
"]",
"=",
"$",
"this",
"->",
"renderSQL",
"(",
"$",
"data",
"[",
"'sql'",
"]",
",",
"$",
"sqlLine",
")",
";",
"}",
"else",
"{",
"// set the PHP Code as source",
"$",
"data",
"[",
"'source'",
"]",
"=",
"$",
"this",
"->",
"renderPHP",
"(",
"$",
"data",
"[",
"'file'",
"]",
",",
"$",
"data",
"[",
"'line'",
"]",
")",
";",
"}",
"// render the trace",
"$",
"data",
"[",
"'trace'",
"]",
"=",
"$",
"this",
"->",
"renderTrace",
"(",
"$",
"data",
"[",
"'trace'",
"]",
")",
";",
"// strip the filename",
"$",
"data",
"[",
"'file'",
"]",
"=",
"$",
"this",
"->",
"stripFile",
"(",
"$",
"data",
"[",
"'file'",
"]",
")",
";",
"// choose the template",
"$",
"view",
"=",
"config",
"(",
"'app.debug'",
")",
"?",
"'errors.debug'",
":",
"'errors.default'",
";",
"if",
"(",
"!",
"config",
"(",
"'app.debug'",
")",
"&&",
"view",
"(",
")",
"->",
"exists",
"(",
"'errors.'",
".",
"$",
"data",
"[",
"'status'",
"]",
")",
")",
"{",
"$",
"view",
"=",
"'errors.'",
".",
"$",
"data",
"[",
"'status'",
"]",
";",
"}",
"// send the response",
"$",
"headers",
"=",
"(",
"$",
"e",
"instanceof",
"HttpException",
")",
"?",
"$",
"e",
"->",
"getHeaders",
"(",
")",
":",
"[",
"]",
";",
"return",
"response",
"(",
")",
"->",
"view",
"(",
"$",
"view",
",",
"$",
"data",
",",
"$",
"data",
"[",
"'status'",
"]",
",",
"$",
"headers",
")",
"->",
"send",
"(",
")",
";",
"}"
] | Send a error message as a HTTP response.
@param Exception $e | [
"Send",
"a",
"error",
"message",
"as",
"a",
"HTTP",
"response",
"."
] | 974945500f278eb6c1779832e08bbfca1007a7b3 | https://github.com/pletfix/core/blob/974945500f278eb6c1779832e08bbfca1007a7b3/src/Handlers/ExceptionHandler.php#L142-L237 |
9,312 | pletfix/core | src/Handlers/ExceptionHandler.php | ExceptionHandler.convertException | private function convertException(Exception $e)
{
$data = [];
$data['message'] = $e->getMessage();
$data['code'] = $e->getCode();
$data['trace'] = $this->filterTrace($e->getTrace());
$data['status'] = Response::HTTP_INTERNAL_SERVER_ERROR;
// determine the relevant file
$firstTraceEntry = !empty($data['trace']) ? reset($data['trace']) : null;
if ($firstTraceEntry !== null && isset($firstTraceEntry['file']) && isset($firstTraceEntry['line'])) {
$data['file'] = $firstTraceEntry['file'];
$data['line'] = $firstTraceEntry['line'];
}
else {
$data['file'] = $e->getFile();
$data['line'] = $e->getLine();
}
if ($e instanceof HttpException) {
$data['status'] = $e->getStatusCode() ?: Response::HTTP_INTERNAL_SERVER_ERROR;
}
else if ($e instanceof QueryException) {
$data['ansiCode'] = isset($e->errorInfo[0]) ? $e->errorInfo[0] : null;
$data['driverCode'] = isset($e->errorInfo[1]) ? $e->errorInfo[1] : null;
if (!empty($e->errorInfo[2])) {
$data['message'] = $e->errorInfo[2];
}
$data['sql'] = $e->getDump();
}
return $data;
} | php | private function convertException(Exception $e)
{
$data = [];
$data['message'] = $e->getMessage();
$data['code'] = $e->getCode();
$data['trace'] = $this->filterTrace($e->getTrace());
$data['status'] = Response::HTTP_INTERNAL_SERVER_ERROR;
// determine the relevant file
$firstTraceEntry = !empty($data['trace']) ? reset($data['trace']) : null;
if ($firstTraceEntry !== null && isset($firstTraceEntry['file']) && isset($firstTraceEntry['line'])) {
$data['file'] = $firstTraceEntry['file'];
$data['line'] = $firstTraceEntry['line'];
}
else {
$data['file'] = $e->getFile();
$data['line'] = $e->getLine();
}
if ($e instanceof HttpException) {
$data['status'] = $e->getStatusCode() ?: Response::HTTP_INTERNAL_SERVER_ERROR;
}
else if ($e instanceof QueryException) {
$data['ansiCode'] = isset($e->errorInfo[0]) ? $e->errorInfo[0] : null;
$data['driverCode'] = isset($e->errorInfo[1]) ? $e->errorInfo[1] : null;
if (!empty($e->errorInfo[2])) {
$data['message'] = $e->errorInfo[2];
}
$data['sql'] = $e->getDump();
}
return $data;
} | [
"private",
"function",
"convertException",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"$",
"data",
"[",
"'message'",
"]",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"$",
"data",
"[",
"'code'",
"]",
"=",
"$",
"e",
"->",
"getCode",
"(",
")",
";",
"$",
"data",
"[",
"'trace'",
"]",
"=",
"$",
"this",
"->",
"filterTrace",
"(",
"$",
"e",
"->",
"getTrace",
"(",
")",
")",
";",
"$",
"data",
"[",
"'status'",
"]",
"=",
"Response",
"::",
"HTTP_INTERNAL_SERVER_ERROR",
";",
"// determine the relevant file",
"$",
"firstTraceEntry",
"=",
"!",
"empty",
"(",
"$",
"data",
"[",
"'trace'",
"]",
")",
"?",
"reset",
"(",
"$",
"data",
"[",
"'trace'",
"]",
")",
":",
"null",
";",
"if",
"(",
"$",
"firstTraceEntry",
"!==",
"null",
"&&",
"isset",
"(",
"$",
"firstTraceEntry",
"[",
"'file'",
"]",
")",
"&&",
"isset",
"(",
"$",
"firstTraceEntry",
"[",
"'line'",
"]",
")",
")",
"{",
"$",
"data",
"[",
"'file'",
"]",
"=",
"$",
"firstTraceEntry",
"[",
"'file'",
"]",
";",
"$",
"data",
"[",
"'line'",
"]",
"=",
"$",
"firstTraceEntry",
"[",
"'line'",
"]",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"'file'",
"]",
"=",
"$",
"e",
"->",
"getFile",
"(",
")",
";",
"$",
"data",
"[",
"'line'",
"]",
"=",
"$",
"e",
"->",
"getLine",
"(",
")",
";",
"}",
"if",
"(",
"$",
"e",
"instanceof",
"HttpException",
")",
"{",
"$",
"data",
"[",
"'status'",
"]",
"=",
"$",
"e",
"->",
"getStatusCode",
"(",
")",
"?",
":",
"Response",
"::",
"HTTP_INTERNAL_SERVER_ERROR",
";",
"}",
"else",
"if",
"(",
"$",
"e",
"instanceof",
"QueryException",
")",
"{",
"$",
"data",
"[",
"'ansiCode'",
"]",
"=",
"isset",
"(",
"$",
"e",
"->",
"errorInfo",
"[",
"0",
"]",
")",
"?",
"$",
"e",
"->",
"errorInfo",
"[",
"0",
"]",
":",
"null",
";",
"$",
"data",
"[",
"'driverCode'",
"]",
"=",
"isset",
"(",
"$",
"e",
"->",
"errorInfo",
"[",
"1",
"]",
")",
"?",
"$",
"e",
"->",
"errorInfo",
"[",
"1",
"]",
":",
"null",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"e",
"->",
"errorInfo",
"[",
"2",
"]",
")",
")",
"{",
"$",
"data",
"[",
"'message'",
"]",
"=",
"$",
"e",
"->",
"errorInfo",
"[",
"2",
"]",
";",
"}",
"$",
"data",
"[",
"'sql'",
"]",
"=",
"$",
"e",
"->",
"getDump",
"(",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Convert a Exception to a simple array.
@param Exception $e
@return array | [
"Convert",
"a",
"Exception",
"to",
"a",
"simple",
"array",
"."
] | 974945500f278eb6c1779832e08bbfca1007a7b3 | https://github.com/pletfix/core/blob/974945500f278eb6c1779832e08bbfca1007a7b3/src/Handlers/ExceptionHandler.php#L248-L280 |
9,313 | pletfix/core | src/Handlers/ExceptionHandler.php | ExceptionHandler.renderSQL | private function renderSQL($sql, $line)
{
try {
$sql = trim($sql);
$count = count(explode(PHP_EOL, $sql));
$code = '<code>' . SqlFormatter::highlight($sql) . '</code>';
return $this->wrapLineNumbers($count, $code, $line);
}
catch(Throwable $e) { // Error or Exception (executed only in PHP 7, will not match in PHP 5)
return null;
}
catch(Exception $e) { // Once PHP 5 support is no longer needed, this block can be removed.
return null;
}
} | php | private function renderSQL($sql, $line)
{
try {
$sql = trim($sql);
$count = count(explode(PHP_EOL, $sql));
$code = '<code>' . SqlFormatter::highlight($sql) . '</code>';
return $this->wrapLineNumbers($count, $code, $line);
}
catch(Throwable $e) { // Error or Exception (executed only in PHP 7, will not match in PHP 5)
return null;
}
catch(Exception $e) { // Once PHP 5 support is no longer needed, this block can be removed.
return null;
}
} | [
"private",
"function",
"renderSQL",
"(",
"$",
"sql",
",",
"$",
"line",
")",
"{",
"try",
"{",
"$",
"sql",
"=",
"trim",
"(",
"$",
"sql",
")",
";",
"$",
"count",
"=",
"count",
"(",
"explode",
"(",
"PHP_EOL",
",",
"$",
"sql",
")",
")",
";",
"$",
"code",
"=",
"'<code>'",
".",
"SqlFormatter",
"::",
"highlight",
"(",
"$",
"sql",
")",
".",
"'</code>'",
";",
"return",
"$",
"this",
"->",
"wrapLineNumbers",
"(",
"$",
"count",
",",
"$",
"code",
",",
"$",
"line",
")",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"e",
")",
"{",
"// Error or Exception (executed only in PHP 7, will not match in PHP 5)",
"return",
"null",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"// Once PHP 5 support is no longer needed, this block can be removed.",
"return",
"null",
";",
"}",
"}"
] | Render SQL.
@param string $sql
@param int $line
@return string | [
"Render",
"SQL",
"."
] | 974945500f278eb6c1779832e08bbfca1007a7b3 | https://github.com/pletfix/core/blob/974945500f278eb6c1779832e08bbfca1007a7b3/src/Handlers/ExceptionHandler.php#L322-L336 |
9,314 | pletfix/core | src/Handlers/ExceptionHandler.php | ExceptionHandler.wrapLineNumbers | private function wrapLineNumbers($count, $code, $line)
{
$length = max(strlen($count), 2);
$numbers = [];
for ($number = 1; $number <= $count; $number++) {
$numbers[] = str_pad($number, $length, '0', STR_PAD_LEFT);
}
if ($line > 0) {
$numbers[$line - 1] = '<span class="errorline">' . $numbers[$line - 1] . '</span>';
}
$numbers = implode('<br/>', $numbers) . '<br/>';
return
'<table class="code"><tr>' .
'<td><code>' . $numbers . '</code></td>' .
'<td>' . $code . '</td>' .
'</tr></table>';
} | php | private function wrapLineNumbers($count, $code, $line)
{
$length = max(strlen($count), 2);
$numbers = [];
for ($number = 1; $number <= $count; $number++) {
$numbers[] = str_pad($number, $length, '0', STR_PAD_LEFT);
}
if ($line > 0) {
$numbers[$line - 1] = '<span class="errorline">' . $numbers[$line - 1] . '</span>';
}
$numbers = implode('<br/>', $numbers) . '<br/>';
return
'<table class="code"><tr>' .
'<td><code>' . $numbers . '</code></td>' .
'<td>' . $code . '</td>' .
'</tr></table>';
} | [
"private",
"function",
"wrapLineNumbers",
"(",
"$",
"count",
",",
"$",
"code",
",",
"$",
"line",
")",
"{",
"$",
"length",
"=",
"max",
"(",
"strlen",
"(",
"$",
"count",
")",
",",
"2",
")",
";",
"$",
"numbers",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"number",
"=",
"1",
";",
"$",
"number",
"<=",
"$",
"count",
";",
"$",
"number",
"++",
")",
"{",
"$",
"numbers",
"[",
"]",
"=",
"str_pad",
"(",
"$",
"number",
",",
"$",
"length",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
";",
"}",
"if",
"(",
"$",
"line",
">",
"0",
")",
"{",
"$",
"numbers",
"[",
"$",
"line",
"-",
"1",
"]",
"=",
"'<span class=\"errorline\">'",
".",
"$",
"numbers",
"[",
"$",
"line",
"-",
"1",
"]",
".",
"'</span>'",
";",
"}",
"$",
"numbers",
"=",
"implode",
"(",
"'<br/>'",
",",
"$",
"numbers",
")",
".",
"'<br/>'",
";",
"return",
"'<table class=\"code\"><tr>'",
".",
"'<td><code>'",
".",
"$",
"numbers",
".",
"'</code></td>'",
".",
"'<td>'",
".",
"$",
"code",
".",
"'</td>'",
".",
"'</tr></table>'",
";",
"}"
] | Render code with line numbers
@param int $count
@param string $code
@param int $line
@return null|string | [
"Render",
"code",
"with",
"line",
"numbers"
] | 974945500f278eb6c1779832e08bbfca1007a7b3 | https://github.com/pletfix/core/blob/974945500f278eb6c1779832e08bbfca1007a7b3/src/Handlers/ExceptionHandler.php#L346-L363 |
9,315 | pletfix/core | src/Handlers/ExceptionHandler.php | ExceptionHandler.filterTrace | private function filterTrace($trace)
{
$ignore = 'app/Services/Database.php';
$j = strlen($ignore);
foreach ($trace as $i => $entry) {
if (isset($entry['file'])) {
$s = $this->stripFile($entry['file']);
if (substr($s, 0, $j) == $ignore) {
unset($trace[$i]);
}
}
}
return $trace;
} | php | private function filterTrace($trace)
{
$ignore = 'app/Services/Database.php';
$j = strlen($ignore);
foreach ($trace as $i => $entry) {
if (isset($entry['file'])) {
$s = $this->stripFile($entry['file']);
if (substr($s, 0, $j) == $ignore) {
unset($trace[$i]);
}
}
}
return $trace;
} | [
"private",
"function",
"filterTrace",
"(",
"$",
"trace",
")",
"{",
"$",
"ignore",
"=",
"'app/Services/Database.php'",
";",
"$",
"j",
"=",
"strlen",
"(",
"$",
"ignore",
")",
";",
"foreach",
"(",
"$",
"trace",
"as",
"$",
"i",
"=>",
"$",
"entry",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"entry",
"[",
"'file'",
"]",
")",
")",
"{",
"$",
"s",
"=",
"$",
"this",
"->",
"stripFile",
"(",
"$",
"entry",
"[",
"'file'",
"]",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"s",
",",
"0",
",",
"$",
"j",
")",
"==",
"$",
"ignore",
")",
"{",
"unset",
"(",
"$",
"trace",
"[",
"$",
"i",
"]",
")",
";",
"}",
"}",
"}",
"return",
"$",
"trace",
";",
"}"
] | Filter Trace to relevant entries
@param array $trace
@return array | [
"Filter",
"Trace",
"to",
"relevant",
"entries"
] | 974945500f278eb6c1779832e08bbfca1007a7b3 | https://github.com/pletfix/core/blob/974945500f278eb6c1779832e08bbfca1007a7b3/src/Handlers/ExceptionHandler.php#L371-L385 |
9,316 | pletfix/core | src/Handlers/ExceptionHandler.php | ExceptionHandler.dumpArgs | private function dumpArgs($args)
{
foreach ($args as $key => $arg) {
if (is_object($arg)) {
$v = '{' . get_class($arg) . '}';
}
else if (is_array($arg)) {
$v = '[' . $this->dumpArgs($arg) . ']';
}
else if (is_string($arg)) {
$v = '"' . (strlen($arg) <= 16 ? $arg : trim(substr($arg, 0, 15)) . '...') . '"';
}
else if (is_bool($arg)) {
$v = $arg ? 'true' : 'false';
}
else if ($arg === null) {
$v = 'null';
}
else {
$v = $arg;
}
$args[$key] = is_string($key) ? '"' . $key . '" => ' . $v : $v;
}
return implode(', ', $args);
} | php | private function dumpArgs($args)
{
foreach ($args as $key => $arg) {
if (is_object($arg)) {
$v = '{' . get_class($arg) . '}';
}
else if (is_array($arg)) {
$v = '[' . $this->dumpArgs($arg) . ']';
}
else if (is_string($arg)) {
$v = '"' . (strlen($arg) <= 16 ? $arg : trim(substr($arg, 0, 15)) . '...') . '"';
}
else if (is_bool($arg)) {
$v = $arg ? 'true' : 'false';
}
else if ($arg === null) {
$v = 'null';
}
else {
$v = $arg;
}
$args[$key] = is_string($key) ? '"' . $key . '" => ' . $v : $v;
}
return implode(', ', $args);
} | [
"private",
"function",
"dumpArgs",
"(",
"$",
"args",
")",
"{",
"foreach",
"(",
"$",
"args",
"as",
"$",
"key",
"=>",
"$",
"arg",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"arg",
")",
")",
"{",
"$",
"v",
"=",
"'{'",
".",
"get_class",
"(",
"$",
"arg",
")",
".",
"'}'",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"arg",
")",
")",
"{",
"$",
"v",
"=",
"'['",
".",
"$",
"this",
"->",
"dumpArgs",
"(",
"$",
"arg",
")",
".",
"']'",
";",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"arg",
")",
")",
"{",
"$",
"v",
"=",
"'\"'",
".",
"(",
"strlen",
"(",
"$",
"arg",
")",
"<=",
"16",
"?",
"$",
"arg",
":",
"trim",
"(",
"substr",
"(",
"$",
"arg",
",",
"0",
",",
"15",
")",
")",
".",
"'...'",
")",
".",
"'\"'",
";",
"}",
"else",
"if",
"(",
"is_bool",
"(",
"$",
"arg",
")",
")",
"{",
"$",
"v",
"=",
"$",
"arg",
"?",
"'true'",
":",
"'false'",
";",
"}",
"else",
"if",
"(",
"$",
"arg",
"===",
"null",
")",
"{",
"$",
"v",
"=",
"'null'",
";",
"}",
"else",
"{",
"$",
"v",
"=",
"$",
"arg",
";",
"}",
"$",
"args",
"[",
"$",
"key",
"]",
"=",
"is_string",
"(",
"$",
"key",
")",
"?",
"'\"'",
".",
"$",
"key",
".",
"'\" => '",
".",
"$",
"v",
":",
"$",
"v",
";",
"}",
"return",
"implode",
"(",
"', '",
",",
"$",
"args",
")",
";",
"}"
] | Render the arguments of a function.
@param $args
@return string | [
"Render",
"the",
"arguments",
"of",
"a",
"function",
"."
] | 974945500f278eb6c1779832e08bbfca1007a7b3 | https://github.com/pletfix/core/blob/974945500f278eb6c1779832e08bbfca1007a7b3/src/Handlers/ExceptionHandler.php#L420-L446 |
9,317 | novuso/system | src/Utility/VarPrinter.php | VarPrinter.toString | public static function toString($value): string
{
if ($value === null) {
return 'NULL';
}
if ($value === true) {
return 'TRUE';
}
if ($value === false) {
return 'FALSE';
}
if (is_object($value)) {
return static::readObject($value);
}
if (is_array($value)) {
return static::readArray($value);
}
if (is_resource($value)) {
return static::readResource($value);
}
return (string) $value;
} | php | public static function toString($value): string
{
if ($value === null) {
return 'NULL';
}
if ($value === true) {
return 'TRUE';
}
if ($value === false) {
return 'FALSE';
}
if (is_object($value)) {
return static::readObject($value);
}
if (is_array($value)) {
return static::readArray($value);
}
if (is_resource($value)) {
return static::readResource($value);
}
return (string) $value;
} | [
"public",
"static",
"function",
"toString",
"(",
"$",
"value",
")",
":",
"string",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"'NULL'",
";",
"}",
"if",
"(",
"$",
"value",
"===",
"true",
")",
"{",
"return",
"'TRUE'",
";",
"}",
"if",
"(",
"$",
"value",
"===",
"false",
")",
"{",
"return",
"'FALSE'",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"return",
"static",
"::",
"readObject",
"(",
"$",
"value",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"static",
"::",
"readArray",
"(",
"$",
"value",
")",
";",
"}",
"if",
"(",
"is_resource",
"(",
"$",
"value",
")",
")",
"{",
"return",
"static",
"::",
"readResource",
"(",
"$",
"value",
")",
";",
"}",
"return",
"(",
"string",
")",
"$",
"value",
";",
"}"
] | Reads a string representation from a value
@param mixed $value The value
@return string | [
"Reads",
"a",
"string",
"representation",
"from",
"a",
"value"
] | e34038b391826edc68d0b5fccfba96642de9d6f0 | https://github.com/novuso/system/blob/e34038b391826edc68d0b5fccfba96642de9d6f0/src/Utility/VarPrinter.php#L24-L51 |
9,318 | novuso/system | src/Utility/VarPrinter.php | VarPrinter.readObject | protected static function readObject($object): string
{
if ($object instanceof Closure) {
return 'Function';
}
if ($object instanceof DateTime) {
return sprintf('DateTime(%s)', $object->format('Y-m-d\TH:i:sP'));
}
if (method_exists($object, 'toString')) {
return (string) $object->toString();
}
if (method_exists($object, '__toString')) {
return (string) $object;
}
return sprintf('Object(%s)', get_class($object));
} | php | protected static function readObject($object): string
{
if ($object instanceof Closure) {
return 'Function';
}
if ($object instanceof DateTime) {
return sprintf('DateTime(%s)', $object->format('Y-m-d\TH:i:sP'));
}
if (method_exists($object, 'toString')) {
return (string) $object->toString();
}
if (method_exists($object, '__toString')) {
return (string) $object;
}
return sprintf('Object(%s)', get_class($object));
} | [
"protected",
"static",
"function",
"readObject",
"(",
"$",
"object",
")",
":",
"string",
"{",
"if",
"(",
"$",
"object",
"instanceof",
"Closure",
")",
"{",
"return",
"'Function'",
";",
"}",
"if",
"(",
"$",
"object",
"instanceof",
"DateTime",
")",
"{",
"return",
"sprintf",
"(",
"'DateTime(%s)'",
",",
"$",
"object",
"->",
"format",
"(",
"'Y-m-d\\TH:i:sP'",
")",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"object",
",",
"'toString'",
")",
")",
"{",
"return",
"(",
"string",
")",
"$",
"object",
"->",
"toString",
"(",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"object",
",",
"'__toString'",
")",
")",
"{",
"return",
"(",
"string",
")",
"$",
"object",
";",
"}",
"return",
"sprintf",
"(",
"'Object(%s)'",
",",
"get_class",
"(",
"$",
"object",
")",
")",
";",
"}"
] | Reads a string representation from an object
@param object $object The object
@return string | [
"Reads",
"a",
"string",
"representation",
"from",
"an",
"object"
] | e34038b391826edc68d0b5fccfba96642de9d6f0 | https://github.com/novuso/system/blob/e34038b391826edc68d0b5fccfba96642de9d6f0/src/Utility/VarPrinter.php#L60-L79 |
9,319 | novuso/system | src/Utility/VarPrinter.php | VarPrinter.readArray | protected static function readArray(array $array): string
{
$data = [];
foreach ($array as $key => $value) {
$data[] = sprintf('%s => %s', $key, static::toString($value));
}
return sprintf('Array(%s)', implode(', ', $data));
} | php | protected static function readArray(array $array): string
{
$data = [];
foreach ($array as $key => $value) {
$data[] = sprintf('%s => %s', $key, static::toString($value));
}
return sprintf('Array(%s)', implode(', ', $data));
} | [
"protected",
"static",
"function",
"readArray",
"(",
"array",
"$",
"array",
")",
":",
"string",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"data",
"[",
"]",
"=",
"sprintf",
"(",
"'%s => %s'",
",",
"$",
"key",
",",
"static",
"::",
"toString",
"(",
"$",
"value",
")",
")",
";",
"}",
"return",
"sprintf",
"(",
"'Array(%s)'",
",",
"implode",
"(",
"', '",
",",
"$",
"data",
")",
")",
";",
"}"
] | Reads a string representation from an array
@param array $array The array
@return string | [
"Reads",
"a",
"string",
"representation",
"from",
"an",
"array"
] | e34038b391826edc68d0b5fccfba96642de9d6f0 | https://github.com/novuso/system/blob/e34038b391826edc68d0b5fccfba96642de9d6f0/src/Utility/VarPrinter.php#L88-L97 |
9,320 | konservs/brilliant.framework | libraries/Log/BLoggerHTML.php | BLoggerHTML.print_html | public static function print_html(){
echo('<div class="debuginfo">');
echo('<p><b>Debug information:</b></p>');
foreach(self::$strings as $msg){
$style='';
switch($msg->level){
case LL_GENERAL:
case LL_DEBUG:
case LL_INFO:
$style='';
break;
case LL_WARNING:
case LL_ERROR:
$style='color: red;';
break;
}
echo('<p style="'.$style.'">');
if(self::$memprof){
echo('(<span class="time">'.sprintf('%.7f',$msg->time).'</span> : ');
echo('<span class="mem" title="'.$msg->mem.' bytes">'.sprintf('%.2f Mb',($msg->mem / 1048576)).')</span> - ');
}
else{
echo('<span class="time">('.sprintf('%.7f',$msg->time).')</span> - ');
}
echo(htmlspecialchars($msg->text));
echo('</p>');
}
echo('</div>');
} | php | public static function print_html(){
echo('<div class="debuginfo">');
echo('<p><b>Debug information:</b></p>');
foreach(self::$strings as $msg){
$style='';
switch($msg->level){
case LL_GENERAL:
case LL_DEBUG:
case LL_INFO:
$style='';
break;
case LL_WARNING:
case LL_ERROR:
$style='color: red;';
break;
}
echo('<p style="'.$style.'">');
if(self::$memprof){
echo('(<span class="time">'.sprintf('%.7f',$msg->time).'</span> : ');
echo('<span class="mem" title="'.$msg->mem.' bytes">'.sprintf('%.2f Mb',($msg->mem / 1048576)).')</span> - ');
}
else{
echo('<span class="time">('.sprintf('%.7f',$msg->time).')</span> - ');
}
echo(htmlspecialchars($msg->text));
echo('</p>');
}
echo('</div>');
} | [
"public",
"static",
"function",
"print_html",
"(",
")",
"{",
"echo",
"(",
"'<div class=\"debuginfo\">'",
")",
";",
"echo",
"(",
"'<p><b>Debug information:</b></p>'",
")",
";",
"foreach",
"(",
"self",
"::",
"$",
"strings",
"as",
"$",
"msg",
")",
"{",
"$",
"style",
"=",
"''",
";",
"switch",
"(",
"$",
"msg",
"->",
"level",
")",
"{",
"case",
"LL_GENERAL",
":",
"case",
"LL_DEBUG",
":",
"case",
"LL_INFO",
":",
"$",
"style",
"=",
"''",
";",
"break",
";",
"case",
"LL_WARNING",
":",
"case",
"LL_ERROR",
":",
"$",
"style",
"=",
"'color: red;'",
";",
"break",
";",
"}",
"echo",
"(",
"'<p style=\"'",
".",
"$",
"style",
".",
"'\">'",
")",
";",
"if",
"(",
"self",
"::",
"$",
"memprof",
")",
"{",
"echo",
"(",
"'(<span class=\"time\">'",
".",
"sprintf",
"(",
"'%.7f'",
",",
"$",
"msg",
"->",
"time",
")",
".",
"'</span> : '",
")",
";",
"echo",
"(",
"'<span class=\"mem\" title=\"'",
".",
"$",
"msg",
"->",
"mem",
".",
"' bytes\">'",
".",
"sprintf",
"(",
"'%.2f Mb'",
",",
"(",
"$",
"msg",
"->",
"mem",
"/",
"1048576",
")",
")",
".",
"')</span> - '",
")",
";",
"}",
"else",
"{",
"echo",
"(",
"'<span class=\"time\">('",
".",
"sprintf",
"(",
"'%.7f'",
",",
"$",
"msg",
"->",
"time",
")",
".",
"')</span> - '",
")",
";",
"}",
"echo",
"(",
"htmlspecialchars",
"(",
"$",
"msg",
"->",
"text",
")",
")",
";",
"echo",
"(",
"'</p>'",
")",
";",
"}",
"echo",
"(",
"'</div>'",
")",
";",
"}"
] | Print HTML log. | [
"Print",
"HTML",
"log",
"."
] | 95f03f1917f746fee98bea8a906ba0588c87762d | https://github.com/konservs/brilliant.framework/blob/95f03f1917f746fee98bea8a906ba0588c87762d/libraries/Log/BLoggerHTML.php#L41-L69 |
9,321 | helthe/Segmentio | Queue.php | Queue.dequeue | public function dequeue($platform = null)
{
if (null === $platform) {
return array_shift($this->queue);
}
// The array pointer does not reset between method calls. So we need to reset it manually.
reset($this->queue);
do {
$index = key($this->queue);
$method = current($this->queue);
next($this->queue);
} while ($method instanceof MethodInterface && !$method->supports($platform));
if (null !== $index) {
unset($this->queue[$index]);
}
if (false === $method) {
$method = null;
}
return $method;
} | php | public function dequeue($platform = null)
{
if (null === $platform) {
return array_shift($this->queue);
}
// The array pointer does not reset between method calls. So we need to reset it manually.
reset($this->queue);
do {
$index = key($this->queue);
$method = current($this->queue);
next($this->queue);
} while ($method instanceof MethodInterface && !$method->supports($platform));
if (null !== $index) {
unset($this->queue[$index]);
}
if (false === $method) {
$method = null;
}
return $method;
} | [
"public",
"function",
"dequeue",
"(",
"$",
"platform",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"platform",
")",
"{",
"return",
"array_shift",
"(",
"$",
"this",
"->",
"queue",
")",
";",
"}",
"// The array pointer does not reset between method calls. So we need to reset it manually.",
"reset",
"(",
"$",
"this",
"->",
"queue",
")",
";",
"do",
"{",
"$",
"index",
"=",
"key",
"(",
"$",
"this",
"->",
"queue",
")",
";",
"$",
"method",
"=",
"current",
"(",
"$",
"this",
"->",
"queue",
")",
";",
"next",
"(",
"$",
"this",
"->",
"queue",
")",
";",
"}",
"while",
"(",
"$",
"method",
"instanceof",
"MethodInterface",
"&&",
"!",
"$",
"method",
"->",
"supports",
"(",
"$",
"platform",
")",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"index",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"queue",
"[",
"$",
"index",
"]",
")",
";",
"}",
"if",
"(",
"false",
"===",
"$",
"method",
")",
"{",
"$",
"method",
"=",
"null",
";",
"}",
"return",
"$",
"method",
";",
"}"
] | Removes the method at the beginning of the queue. You can optionally
filter to dequeue a specific platform method.
@param string $platform
@return MethodInterface|null | [
"Removes",
"the",
"method",
"at",
"the",
"beginning",
"of",
"the",
"queue",
".",
"You",
"can",
"optionally",
"filter",
"to",
"dequeue",
"a",
"specific",
"platform",
"method",
"."
] | 40a97cf9780404bf0a48ad4621cc994ca66e9128 | https://github.com/helthe/Segmentio/blob/40a97cf9780404bf0a48ad4621cc994ca66e9128/Queue.php#L60-L83 |
9,322 | roboapp/crud | src/Move.php | Move.moveDown | protected function moveDown($id)
{
$model = $this->getModel($id);
$orderAttrName = $this->positionAttribute;
$orderDir = SORT_ASC;
$swapModel = $model::find()
->where(['>', $orderAttrName, $model->$orderAttrName])
->orderBy([$orderAttrName => $orderDir])
->one();
if ($swapModel) {
$newOrderNumeric = $swapModel->$orderAttrName;
$swapModel->$orderAttrName = $model->$orderAttrName;
$model->$orderAttrName = $newOrderNumeric;
$swapModel->save() && $model->save();
}
return $this->redirect($model);
} | php | protected function moveDown($id)
{
$model = $this->getModel($id);
$orderAttrName = $this->positionAttribute;
$orderDir = SORT_ASC;
$swapModel = $model::find()
->where(['>', $orderAttrName, $model->$orderAttrName])
->orderBy([$orderAttrName => $orderDir])
->one();
if ($swapModel) {
$newOrderNumeric = $swapModel->$orderAttrName;
$swapModel->$orderAttrName = $model->$orderAttrName;
$model->$orderAttrName = $newOrderNumeric;
$swapModel->save() && $model->save();
}
return $this->redirect($model);
} | [
"protected",
"function",
"moveDown",
"(",
"$",
"id",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"getModel",
"(",
"$",
"id",
")",
";",
"$",
"orderAttrName",
"=",
"$",
"this",
"->",
"positionAttribute",
";",
"$",
"orderDir",
"=",
"SORT_ASC",
";",
"$",
"swapModel",
"=",
"$",
"model",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'>'",
",",
"$",
"orderAttrName",
",",
"$",
"model",
"->",
"$",
"orderAttrName",
"]",
")",
"->",
"orderBy",
"(",
"[",
"$",
"orderAttrName",
"=>",
"$",
"orderDir",
"]",
")",
"->",
"one",
"(",
")",
";",
"if",
"(",
"$",
"swapModel",
")",
"{",
"$",
"newOrderNumeric",
"=",
"$",
"swapModel",
"->",
"$",
"orderAttrName",
";",
"$",
"swapModel",
"->",
"$",
"orderAttrName",
"=",
"$",
"model",
"->",
"$",
"orderAttrName",
";",
"$",
"model",
"->",
"$",
"orderAttrName",
"=",
"$",
"newOrderNumeric",
";",
"$",
"swapModel",
"->",
"save",
"(",
")",
"&&",
"$",
"model",
"->",
"save",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"model",
")",
";",
"}"
] | Move model to down
@param mixed $id ID of the model to be moved down
@return mixed
@throws \yii\web\NotFoundHttpException | [
"Move",
"model",
"to",
"down"
] | cda8ce1b8996157e08df949fcc83e314e25621f1 | https://github.com/roboapp/crud/blob/cda8ce1b8996157e08df949fcc83e314e25621f1/src/Move.php#L53-L72 |
9,323 | roboapp/crud | src/Move.php | Move.moveUp | protected function moveUp($id)
{
$model = $this->getModel($id);
$orderAttrName = $this->positionAttribute;
$orderDir = SORT_DESC;
$swapModel = $model::find()
->where(['<', $orderAttrName, $model->$orderAttrName])
->orderBy([$orderAttrName => $orderDir])
->one();
if ($swapModel) {
$newOrderNumeric = $swapModel->$orderAttrName;
$swapModel->$orderAttrName = $model->$orderAttrName;
$model->$orderAttrName = $newOrderNumeric;
$swapModel->save() && $model->save();
}
return $this->redirect($model);
} | php | protected function moveUp($id)
{
$model = $this->getModel($id);
$orderAttrName = $this->positionAttribute;
$orderDir = SORT_DESC;
$swapModel = $model::find()
->where(['<', $orderAttrName, $model->$orderAttrName])
->orderBy([$orderAttrName => $orderDir])
->one();
if ($swapModel) {
$newOrderNumeric = $swapModel->$orderAttrName;
$swapModel->$orderAttrName = $model->$orderAttrName;
$model->$orderAttrName = $newOrderNumeric;
$swapModel->save() && $model->save();
}
return $this->redirect($model);
} | [
"protected",
"function",
"moveUp",
"(",
"$",
"id",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"getModel",
"(",
"$",
"id",
")",
";",
"$",
"orderAttrName",
"=",
"$",
"this",
"->",
"positionAttribute",
";",
"$",
"orderDir",
"=",
"SORT_DESC",
";",
"$",
"swapModel",
"=",
"$",
"model",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'<'",
",",
"$",
"orderAttrName",
",",
"$",
"model",
"->",
"$",
"orderAttrName",
"]",
")",
"->",
"orderBy",
"(",
"[",
"$",
"orderAttrName",
"=>",
"$",
"orderDir",
"]",
")",
"->",
"one",
"(",
")",
";",
"if",
"(",
"$",
"swapModel",
")",
"{",
"$",
"newOrderNumeric",
"=",
"$",
"swapModel",
"->",
"$",
"orderAttrName",
";",
"$",
"swapModel",
"->",
"$",
"orderAttrName",
"=",
"$",
"model",
"->",
"$",
"orderAttrName",
";",
"$",
"model",
"->",
"$",
"orderAttrName",
"=",
"$",
"newOrderNumeric",
";",
"$",
"swapModel",
"->",
"save",
"(",
")",
"&&",
"$",
"model",
"->",
"save",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"model",
")",
";",
"}"
] | Move model to up
@param mixed $id ID of the model to be moved up
@return mixed
@throws \yii\web\NotFoundHttpException | [
"Move",
"model",
"to",
"up"
] | cda8ce1b8996157e08df949fcc83e314e25621f1 | https://github.com/roboapp/crud/blob/cda8ce1b8996157e08df949fcc83e314e25621f1/src/Move.php#L80-L99 |
9,324 | dlabas/DlcDoctrine | src/DlcDoctrine/Event/CommitTransactionListener.php | CommitTransactionListener.onFinish | public function onFinish(MvcEvent $event)
{
$connection = $this->getObjectManager()->getConnection();
if ($connection->isTransactionActive()) {
$connection->commit();
}
} | php | public function onFinish(MvcEvent $event)
{
$connection = $this->getObjectManager()->getConnection();
if ($connection->isTransactionActive()) {
$connection->commit();
}
} | [
"public",
"function",
"onFinish",
"(",
"MvcEvent",
"$",
"event",
")",
"{",
"$",
"connection",
"=",
"$",
"this",
"->",
"getObjectManager",
"(",
")",
"->",
"getConnection",
"(",
")",
";",
"if",
"(",
"$",
"connection",
"->",
"isTransactionActive",
"(",
")",
")",
"{",
"$",
"connection",
"->",
"commit",
"(",
")",
";",
"}",
"}"
] | Listen to the "finish" event and attempt to commit a transaction
@param MvcEvent $e | [
"Listen",
"to",
"the",
"finish",
"event",
"and",
"attempt",
"to",
"commit",
"a",
"transaction"
] | 1e754c208197e9aa7a9d58efcc726e109aaa6edf | https://github.com/dlabas/DlcDoctrine/blob/1e754c208197e9aa7a9d58efcc726e109aaa6edf/src/DlcDoctrine/Event/CommitTransactionListener.php#L28-L35 |
9,325 | neontabs-drupal8/nt8property | src/Form/NT8PropertyFormBase.php | NT8PropertyFormBase.setupAreaLocTaxonomy | public function setupAreaLocTaxonomy(array &$form, FormStateInterface $formState) {
$limit_arealocs = $formState->getValue('attribute_code_limit') ?: NULL;
$new_arr = [];
if (isset($limit_arealocs)) {
$new_arr = array_map(
'trim',
explode(',', $limit_arealocs)
) ?: [];
}
$locData = $this->propertyMethods->getAreaLocationDataFromTabs($new_arr);
$arealocDataUpdateStatus = $this->propertyMethods->createAreaLocTermsFromTabs($locData);
drupal_set_message(print_r('Updated Areas: ' . $arealocDataUpdateStatus[0], TRUE));
drupal_set_message(print_r('Updated Locations: ' . $arealocDataUpdateStatus[1], TRUE));
} | php | public function setupAreaLocTaxonomy(array &$form, FormStateInterface $formState) {
$limit_arealocs = $formState->getValue('attribute_code_limit') ?: NULL;
$new_arr = [];
if (isset($limit_arealocs)) {
$new_arr = array_map(
'trim',
explode(',', $limit_arealocs)
) ?: [];
}
$locData = $this->propertyMethods->getAreaLocationDataFromTabs($new_arr);
$arealocDataUpdateStatus = $this->propertyMethods->createAreaLocTermsFromTabs($locData);
drupal_set_message(print_r('Updated Areas: ' . $arealocDataUpdateStatus[0], TRUE));
drupal_set_message(print_r('Updated Locations: ' . $arealocDataUpdateStatus[1], TRUE));
} | [
"public",
"function",
"setupAreaLocTaxonomy",
"(",
"array",
"&",
"$",
"form",
",",
"FormStateInterface",
"$",
"formState",
")",
"{",
"$",
"limit_arealocs",
"=",
"$",
"formState",
"->",
"getValue",
"(",
"'attribute_code_limit'",
")",
"?",
":",
"NULL",
";",
"$",
"new_arr",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"limit_arealocs",
")",
")",
"{",
"$",
"new_arr",
"=",
"array_map",
"(",
"'trim'",
",",
"explode",
"(",
"','",
",",
"$",
"limit_arealocs",
")",
")",
"?",
":",
"[",
"]",
";",
"}",
"$",
"locData",
"=",
"$",
"this",
"->",
"propertyMethods",
"->",
"getAreaLocationDataFromTabs",
"(",
"$",
"new_arr",
")",
";",
"$",
"arealocDataUpdateStatus",
"=",
"$",
"this",
"->",
"propertyMethods",
"->",
"createAreaLocTermsFromTabs",
"(",
"$",
"locData",
")",
";",
"drupal_set_message",
"(",
"print_r",
"(",
"'Updated Areas: '",
".",
"$",
"arealocDataUpdateStatus",
"[",
"0",
"]",
",",
"TRUE",
")",
")",
";",
"drupal_set_message",
"(",
"print_r",
"(",
"'Updated Locations: '",
".",
"$",
"arealocDataUpdateStatus",
"[",
"1",
"]",
",",
"TRUE",
")",
")",
";",
"}"
] | Runs the necessary methods in the property service to setup the taxonomy.
@see ::createAreaLocTermsFromTabs | [
"Runs",
"the",
"necessary",
"methods",
"in",
"the",
"property",
"service",
"to",
"setup",
"the",
"taxonomy",
"."
] | 53b630a612c6dc7c90a8ca1ce4ceb41568473447 | https://github.com/neontabs-drupal8/nt8property/blob/53b630a612c6dc7c90a8ca1ce4ceb41568473447/src/Form/NT8PropertyFormBase.php#L233-L249 |
9,326 | neontabs-drupal8/nt8property | src/Form/NT8PropertyFormBase.php | NT8PropertyFormBase.loadPropertyBatchAll | public function loadPropertyBatchAll(array &$form, FormStateInterface $formState) {
$batch_size = $formState->getValue('batch_size') ?: 6;
$modify_replace = $formState->getValue('modify_replace_batch') ?: 0;
NT8PropertyBatch::propertyBatchLoad($batch_size, $modify_replace);
} | php | public function loadPropertyBatchAll(array &$form, FormStateInterface $formState) {
$batch_size = $formState->getValue('batch_size') ?: 6;
$modify_replace = $formState->getValue('modify_replace_batch') ?: 0;
NT8PropertyBatch::propertyBatchLoad($batch_size, $modify_replace);
} | [
"public",
"function",
"loadPropertyBatchAll",
"(",
"array",
"&",
"$",
"form",
",",
"FormStateInterface",
"$",
"formState",
")",
"{",
"$",
"batch_size",
"=",
"$",
"formState",
"->",
"getValue",
"(",
"'batch_size'",
")",
"?",
":",
"6",
";",
"$",
"modify_replace",
"=",
"$",
"formState",
"->",
"getValue",
"(",
"'modify_replace_batch'",
")",
"?",
":",
"0",
";",
"NT8PropertyBatch",
"::",
"propertyBatchLoad",
"(",
"$",
"batch_size",
",",
"$",
"modify_replace",
")",
";",
"}"
] | Initiates a batch method to load all properties. | [
"Initiates",
"a",
"batch",
"method",
"to",
"load",
"all",
"properties",
"."
] | 53b630a612c6dc7c90a8ca1ce4ceb41568473447 | https://github.com/neontabs-drupal8/nt8property/blob/53b630a612c6dc7c90a8ca1ce4ceb41568473447/src/Form/NT8PropertyFormBase.php#L304-L309 |
9,327 | acantepie/CoreBundle | Services/UmbrellaFileUploader.php | UmbrellaFileUploader.createUmbrellaFile | public function createUmbrellaFile(UploadedFile $file, $upload = false)
{
$umbrellaFile = new UmbrellaFile();
$umbrellaFile->name = $file->getClientOriginalName();
$umbrellaFile->md5 = md5_file($file->getRealPath());
$umbrellaFile->mimeType = $file->getMimeType();
$umbrellaFile->size = $file->getSize();
if ($upload) {
$umbrellaFile->path = $this->upload($file);
} else {
$umbrellaFile->file = $file;
}
return $umbrellaFile;
} | php | public function createUmbrellaFile(UploadedFile $file, $upload = false)
{
$umbrellaFile = new UmbrellaFile();
$umbrellaFile->name = $file->getClientOriginalName();
$umbrellaFile->md5 = md5_file($file->getRealPath());
$umbrellaFile->mimeType = $file->getMimeType();
$umbrellaFile->size = $file->getSize();
if ($upload) {
$umbrellaFile->path = $this->upload($file);
} else {
$umbrellaFile->file = $file;
}
return $umbrellaFile;
} | [
"public",
"function",
"createUmbrellaFile",
"(",
"UploadedFile",
"$",
"file",
",",
"$",
"upload",
"=",
"false",
")",
"{",
"$",
"umbrellaFile",
"=",
"new",
"UmbrellaFile",
"(",
")",
";",
"$",
"umbrellaFile",
"->",
"name",
"=",
"$",
"file",
"->",
"getClientOriginalName",
"(",
")",
";",
"$",
"umbrellaFile",
"->",
"md5",
"=",
"md5_file",
"(",
"$",
"file",
"->",
"getRealPath",
"(",
")",
")",
";",
"$",
"umbrellaFile",
"->",
"mimeType",
"=",
"$",
"file",
"->",
"getMimeType",
"(",
")",
";",
"$",
"umbrellaFile",
"->",
"size",
"=",
"$",
"file",
"->",
"getSize",
"(",
")",
";",
"if",
"(",
"$",
"upload",
")",
"{",
"$",
"umbrellaFile",
"->",
"path",
"=",
"$",
"this",
"->",
"upload",
"(",
"$",
"file",
")",
";",
"}",
"else",
"{",
"$",
"umbrellaFile",
"->",
"file",
"=",
"$",
"file",
";",
"}",
"return",
"$",
"umbrellaFile",
";",
"}"
] | Create Umbrella file from UploadedFile
If upload set to true => process upload else upload will be processed on postPersist
@param UploadedFile $file
@param bool $upload
@return UmbrellaFile | [
"Create",
"Umbrella",
"file",
"from",
"UploadedFile",
"If",
"upload",
"set",
"to",
"true",
"=",
">",
"process",
"upload",
"else",
"upload",
"will",
"be",
"processed",
"on",
"postPersist"
] | e9f19194b105bfcc10c34ff0763e45436d719782 | https://github.com/acantepie/CoreBundle/blob/e9f19194b105bfcc10c34ff0763e45436d719782/Services/UmbrellaFileUploader.php#L89-L103 |
9,328 | niconoe-/asserts | src/Asserts/Categories/AssertObjectTrait.php | AssertObjectTrait.assertObjectIsA | public static function assertObjectIsA($object, string $type, Throwable $exception)
{
static::makeAssertion(\is_a($object, $type), $exception);
return $object;
} | php | public static function assertObjectIsA($object, string $type, Throwable $exception)
{
static::makeAssertion(\is_a($object, $type), $exception);
return $object;
} | [
"public",
"static",
"function",
"assertObjectIsA",
"(",
"$",
"object",
",",
"string",
"$",
"type",
",",
"Throwable",
"$",
"exception",
")",
"{",
"static",
"::",
"makeAssertion",
"(",
"\\",
"is_a",
"(",
"$",
"object",
",",
"$",
"type",
")",
",",
"$",
"exception",
")",
";",
"return",
"$",
"object",
";",
"}"
] | Asserts that the given object is an instance of the given type.
@param mixed $object The given object to test.
@param string $type The expected type of the given object.
@param Throwable $exception The exception to throw if the assertion fails.
@return mixed The given object tested. | [
"Asserts",
"that",
"the",
"given",
"object",
"is",
"an",
"instance",
"of",
"the",
"given",
"type",
"."
] | a33dd3fb8983ae6965533c8ff4ff8380367b561d | https://github.com/niconoe-/asserts/blob/a33dd3fb8983ae6965533c8ff4ff8380367b561d/src/Asserts/Categories/AssertObjectTrait.php#L27-L31 |
9,329 | niconoe-/asserts | src/Asserts/Categories/AssertObjectTrait.php | AssertObjectTrait.assertPropertiesInCascade | public static function assertPropertiesInCascade($object, Throwable $exception, string ...$propertiesInCascade)
{
foreach ($propertiesInCascade as $property) {
static::makeAssertion(\property_exists($object, $property), $exception);
$object = $object->{$property};
}
return $object;
} | php | public static function assertPropertiesInCascade($object, Throwable $exception, string ...$propertiesInCascade)
{
foreach ($propertiesInCascade as $property) {
static::makeAssertion(\property_exists($object, $property), $exception);
$object = $object->{$property};
}
return $object;
} | [
"public",
"static",
"function",
"assertPropertiesInCascade",
"(",
"$",
"object",
",",
"Throwable",
"$",
"exception",
",",
"string",
"...",
"$",
"propertiesInCascade",
")",
"{",
"foreach",
"(",
"$",
"propertiesInCascade",
"as",
"$",
"property",
")",
"{",
"static",
"::",
"makeAssertion",
"(",
"\\",
"property_exists",
"(",
"$",
"object",
",",
"$",
"property",
")",
",",
"$",
"exception",
")",
";",
"$",
"object",
"=",
"$",
"object",
"->",
"{",
"$",
"property",
"}",
";",
"}",
"return",
"$",
"object",
";",
"}"
] | Asserts that a list of properties exist in cascade from an original object.
@param mixed $object The original object to check properties in cascade.
@param Throwable $exception The exception to throw if the assertion fails.
@param string ...$propertiesInCascade The list of properties to check in cascade.
@return mixed The value of the last element to check. | [
"Asserts",
"that",
"a",
"list",
"of",
"properties",
"exist",
"in",
"cascade",
"from",
"an",
"original",
"object",
"."
] | a33dd3fb8983ae6965533c8ff4ff8380367b561d | https://github.com/niconoe-/asserts/blob/a33dd3fb8983ae6965533c8ff4ff8380367b561d/src/Asserts/Categories/AssertObjectTrait.php#L41-L48 |
9,330 | jmpantoja/planb-utils | src/Type/Assurance/Exception/AssertException.php | AssertException.parseParams | private static function parseParams(array $arguments): string
{
if (0 === count($arguments)) {
return '';
}
$arguments = array_map(function ($argument) {
return beautify_parse('<argument:argument>', [
'argument' => sprintf('"%s"', $argument),
]);
}, $arguments);
$parameters = implode(', ', $arguments);
return sprintf('(%s)', $parameters);
} | php | private static function parseParams(array $arguments): string
{
if (0 === count($arguments)) {
return '';
}
$arguments = array_map(function ($argument) {
return beautify_parse('<argument:argument>', [
'argument' => sprintf('"%s"', $argument),
]);
}, $arguments);
$parameters = implode(', ', $arguments);
return sprintf('(%s)', $parameters);
} | [
"private",
"static",
"function",
"parseParams",
"(",
"array",
"$",
"arguments",
")",
":",
"string",
"{",
"if",
"(",
"0",
"===",
"count",
"(",
"$",
"arguments",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"arguments",
"=",
"array_map",
"(",
"function",
"(",
"$",
"argument",
")",
"{",
"return",
"beautify_parse",
"(",
"'<argument:argument>'",
",",
"[",
"'argument'",
"=>",
"sprintf",
"(",
"'\"%s\"'",
",",
"$",
"argument",
")",
",",
"]",
")",
";",
"}",
",",
"$",
"arguments",
")",
";",
"$",
"parameters",
"=",
"implode",
"(",
"', '",
",",
"$",
"arguments",
")",
";",
"return",
"sprintf",
"(",
"'(%s)'",
",",
"$",
"parameters",
")",
";",
"}"
] | Convierte los argumentos en una cadena de texto
@param mixed[] $arguments
@return string | [
"Convierte",
"los",
"argumentos",
"en",
"una",
"cadena",
"de",
"texto"
] | d17fbced4a285275928f8428ee56e269eb851690 | https://github.com/jmpantoja/planb-utils/blob/d17fbced4a285275928f8428ee56e269eb851690/src/Type/Assurance/Exception/AssertException.php#L72-L87 |
9,331 | potfur/statemachine | src/StateMachine/PayloadEnvelope.php | PayloadEnvelope.changeState | public function changeState($name)
{
$this->state = $name;
$this->history[] = $name;
$this->hasChanged = true;
} | php | public function changeState($name)
{
$this->state = $name;
$this->history[] = $name;
$this->hasChanged = true;
} | [
"public",
"function",
"changeState",
"(",
"$",
"name",
")",
"{",
"$",
"this",
"->",
"state",
"=",
"$",
"name",
";",
"$",
"this",
"->",
"history",
"[",
"]",
"=",
"$",
"name",
";",
"$",
"this",
"->",
"hasChanged",
"=",
"true",
";",
"}"
] | Set new state to subject
@param string $name state name | [
"Set",
"new",
"state",
"to",
"subject"
] | 6b68535e6c94b10bf618a7809a48f6a8f6d30deb | https://github.com/potfur/statemachine/blob/6b68535e6c94b10bf618a7809a48f6a8f6d30deb/src/StateMachine/PayloadEnvelope.php#L93-L98 |
9,332 | digit-soft/re-action-promise | src/PromiseWithSD.php | PromiseWithSD.always | public function always(callable $onFulfilledOrRejected)
{
return $this->then(function ($value) use ($onFulfilledOrRejected) {
return resolve($onFulfilledOrRejected($this->sharedData))->then(function () use ($value) {
return $value;
});
}, function ($reason) use ($onFulfilledOrRejected) {
return resolve($onFulfilledOrRejected($this->sharedData))->then(function () use ($reason) {
return new RejectedPromiseWithSD($reason, $this->sharedData);
});
});
} | php | public function always(callable $onFulfilledOrRejected)
{
return $this->then(function ($value) use ($onFulfilledOrRejected) {
return resolve($onFulfilledOrRejected($this->sharedData))->then(function () use ($value) {
return $value;
});
}, function ($reason) use ($onFulfilledOrRejected) {
return resolve($onFulfilledOrRejected($this->sharedData))->then(function () use ($reason) {
return new RejectedPromiseWithSD($reason, $this->sharedData);
});
});
} | [
"public",
"function",
"always",
"(",
"callable",
"$",
"onFulfilledOrRejected",
")",
"{",
"return",
"$",
"this",
"->",
"then",
"(",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"$",
"onFulfilledOrRejected",
")",
"{",
"return",
"resolve",
"(",
"$",
"onFulfilledOrRejected",
"(",
"$",
"this",
"->",
"sharedData",
")",
")",
"->",
"then",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"value",
")",
"{",
"return",
"$",
"value",
";",
"}",
")",
";",
"}",
",",
"function",
"(",
"$",
"reason",
")",
"use",
"(",
"$",
"onFulfilledOrRejected",
")",
"{",
"return",
"resolve",
"(",
"$",
"onFulfilledOrRejected",
"(",
"$",
"this",
"->",
"sharedData",
")",
")",
"->",
"then",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"reason",
")",
"{",
"return",
"new",
"RejectedPromiseWithSD",
"(",
"$",
"reason",
",",
"$",
"this",
"->",
"sharedData",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Always callable after resolving or rejecting
@param callable $onFulfilledOrRejected
@return ExtendedPromiseInterface | [
"Always",
"callable",
"after",
"resolving",
"or",
"rejecting"
] | 9a16b9ca95eeafd3ebcc0a1e8e76ad958c48bac1 | https://github.com/digit-soft/re-action-promise/blob/9a16b9ca95eeafd3ebcc0a1e8e76ad958c48bac1/src/PromiseWithSD.php#L84-L95 |
9,333 | digit-soft/re-action-promise | src/PromiseWithSD.php | PromiseWithSD.resolver | protected function resolver(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null)
{
return function ($resolve, $reject, $notify) use ($onFulfilled, $onRejected, $onProgress) {
if ($onProgress) {
$progressHandler = function ($update) use ($notify, $onProgress) {
try {
$notify($onProgress($update), $this->sharedData);
} catch (\Throwable $e) {
$notify($e, $this->sharedData);
}
};
} else {
$progressHandler = $notify;
}
$this->handlers[] = function (ExtendedPromiseInterface $promise) use ($onFulfilled, $onRejected, $resolve, $reject, $progressHandler) {
$promise
->then($onFulfilled, $onRejected)
->done($resolve, $reject, $progressHandler);
};
$this->progressHandlers[] = $progressHandler;
};
} | php | protected function resolver(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null)
{
return function ($resolve, $reject, $notify) use ($onFulfilled, $onRejected, $onProgress) {
if ($onProgress) {
$progressHandler = function ($update) use ($notify, $onProgress) {
try {
$notify($onProgress($update), $this->sharedData);
} catch (\Throwable $e) {
$notify($e, $this->sharedData);
}
};
} else {
$progressHandler = $notify;
}
$this->handlers[] = function (ExtendedPromiseInterface $promise) use ($onFulfilled, $onRejected, $resolve, $reject, $progressHandler) {
$promise
->then($onFulfilled, $onRejected)
->done($resolve, $reject, $progressHandler);
};
$this->progressHandlers[] = $progressHandler;
};
} | [
"protected",
"function",
"resolver",
"(",
"callable",
"$",
"onFulfilled",
"=",
"null",
",",
"callable",
"$",
"onRejected",
"=",
"null",
",",
"callable",
"$",
"onProgress",
"=",
"null",
")",
"{",
"return",
"function",
"(",
"$",
"resolve",
",",
"$",
"reject",
",",
"$",
"notify",
")",
"use",
"(",
"$",
"onFulfilled",
",",
"$",
"onRejected",
",",
"$",
"onProgress",
")",
"{",
"if",
"(",
"$",
"onProgress",
")",
"{",
"$",
"progressHandler",
"=",
"function",
"(",
"$",
"update",
")",
"use",
"(",
"$",
"notify",
",",
"$",
"onProgress",
")",
"{",
"try",
"{",
"$",
"notify",
"(",
"$",
"onProgress",
"(",
"$",
"update",
")",
",",
"$",
"this",
"->",
"sharedData",
")",
";",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
"e",
")",
"{",
"$",
"notify",
"(",
"$",
"e",
",",
"$",
"this",
"->",
"sharedData",
")",
";",
"}",
"}",
";",
"}",
"else",
"{",
"$",
"progressHandler",
"=",
"$",
"notify",
";",
"}",
"$",
"this",
"->",
"handlers",
"[",
"]",
"=",
"function",
"(",
"ExtendedPromiseInterface",
"$",
"promise",
")",
"use",
"(",
"$",
"onFulfilled",
",",
"$",
"onRejected",
",",
"$",
"resolve",
",",
"$",
"reject",
",",
"$",
"progressHandler",
")",
"{",
"$",
"promise",
"->",
"then",
"(",
"$",
"onFulfilled",
",",
"$",
"onRejected",
")",
"->",
"done",
"(",
"$",
"resolve",
",",
"$",
"reject",
",",
"$",
"progressHandler",
")",
";",
"}",
";",
"$",
"this",
"->",
"progressHandlers",
"[",
"]",
"=",
"$",
"progressHandler",
";",
"}",
";",
"}"
] | Promise resolver callback generator
@param callable|null $onFulfilled
@param callable|null $onRejected
@param callable|null $onProgress
@return \Closure | [
"Promise",
"resolver",
"callback",
"generator"
] | 9a16b9ca95eeafd3ebcc0a1e8e76ad958c48bac1 | https://github.com/digit-soft/re-action-promise/blob/9a16b9ca95eeafd3ebcc0a1e8e76ad958c48bac1/src/PromiseWithSD.php#L104-L127 |
9,334 | digit-soft/re-action-promise | src/PromiseWithSD.php | PromiseWithSD.resolveFunction | protected static function resolveFunction(self &$target)
{
return function ($value = null) use (&$target) {
if ($target !== null) {
$target->settle(resolve($value, $target->sharedData));
$target = null;
}
};
} | php | protected static function resolveFunction(self &$target)
{
return function ($value = null) use (&$target) {
if ($target !== null) {
$target->settle(resolve($value, $target->sharedData));
$target = null;
}
};
} | [
"protected",
"static",
"function",
"resolveFunction",
"(",
"self",
"&",
"$",
"target",
")",
"{",
"return",
"function",
"(",
"$",
"value",
"=",
"null",
")",
"use",
"(",
"&",
"$",
"target",
")",
"{",
"if",
"(",
"$",
"target",
"!==",
"null",
")",
"{",
"$",
"target",
"->",
"settle",
"(",
"resolve",
"(",
"$",
"value",
",",
"$",
"target",
"->",
"sharedData",
")",
")",
";",
"$",
"target",
"=",
"null",
";",
"}",
"}",
";",
"}"
] | Creates a static resolver callback that is not bound to a promise instance.
Moving the closure creation to a static method allows us to create a
callback that is not bound to a promise instance. By passing the target
promise instance by reference, we can still execute its resolving logic
and still clear this reference when settling the promise. This helps
avoiding garbage cycles if any callback creates an Exception.
These assumptions are covered by the test suite, so if you ever feel like
refactoring this, go ahead, any alternative suggestions are welcome!
@param ExtendedPromiseInterface $target
@return callable | [
"Creates",
"a",
"static",
"resolver",
"callback",
"that",
"is",
"not",
"bound",
"to",
"a",
"promise",
"instance",
"."
] | 9a16b9ca95eeafd3ebcc0a1e8e76ad958c48bac1 | https://github.com/digit-soft/re-action-promise/blob/9a16b9ca95eeafd3ebcc0a1e8e76ad958c48bac1/src/PromiseWithSD.php#L231-L239 |
9,335 | jmpantoja/planb-utils | src/DS/Resolver/Rule/AbstractRule.php | AbstractRule.execute | public function execute(Input $input): Input
{
if (!$input->isEvaluableForTypes(...$this->types)) {
return $input;
}
return $this->resolve($input);
} | php | public function execute(Input $input): Input
{
if (!$input->isEvaluableForTypes(...$this->types)) {
return $input;
}
return $this->resolve($input);
} | [
"public",
"function",
"execute",
"(",
"Input",
"$",
"input",
")",
":",
"Input",
"{",
"if",
"(",
"!",
"$",
"input",
"->",
"isEvaluableForTypes",
"(",
"...",
"$",
"this",
"->",
"types",
")",
")",
"{",
"return",
"$",
"input",
";",
"}",
"return",
"$",
"this",
"->",
"resolve",
"(",
"$",
"input",
")",
";",
"}"
] | Manipula un input
@param \PlanB\DS\Resolver\Input $input
@return \PlanB\DS\Resolver\Input
@throws \Throwable | [
"Manipula",
"un",
"input"
] | d17fbced4a285275928f8428ee56e269eb851690 | https://github.com/jmpantoja/planb-utils/blob/d17fbced4a285275928f8428ee56e269eb851690/src/DS/Resolver/Rule/AbstractRule.php#L69-L77 |
9,336 | blenderdeluxe/khipu | src/KhipuService/KhipuServiceCreateEmail.php | KhipuServiceCreateEmail.addRecipient | public function addRecipient($name, $email, $amount) {
$this->recipients->addRecipient($name, $email, $amount);
return $this;
} | php | public function addRecipient($name, $email, $amount) {
$this->recipients->addRecipient($name, $email, $amount);
return $this;
} | [
"public",
"function",
"addRecipient",
"(",
"$",
"name",
",",
"$",
"email",
",",
"$",
"amount",
")",
"{",
"$",
"this",
"->",
"recipients",
"->",
"addRecipient",
"(",
"$",
"name",
",",
"$",
"email",
",",
"$",
"amount",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Este metodo se encarga de adjuntar un destinatario al objeto.
@param string $name
Nombre del pagador.
@param string $email
Correo electrónico del pagador.
@param int $amount
Monto que pagará el pagador. | [
"Este",
"metodo",
"se",
"encarga",
"de",
"adjuntar",
"un",
"destinatario",
"al",
"objeto",
"."
] | ef78fa8ba372c7784936ce95a3d0bd46a35e0143 | https://github.com/blenderdeluxe/khipu/blob/ef78fa8ba372c7784936ce95a3d0bd46a35e0143/src/KhipuService/KhipuServiceCreateEmail.php#L70-L73 |
9,337 | synapsestudios/synapse-base | src/Synapse/CliCommand/AbstractCliCommand.php | AbstractCliCommand.run | public function run(CliCommandOptions $options = null)
{
$options = $this->getOptions($options);
$command = $this->buildCommand($options);
$startTime = microtime(true);
$response = $this->executor->execute(
$command,
$options->getCwd(),
$options->getEnv()
);
$elapsedTime = microtime(true) - $startTime;
$output = $response->getOutput();
$returnCode = $response->getReturnCode();
return new CliCommandResponse([
'command' => $command,
'elapsed_time' => $elapsedTime,
'output' => $output,
'start_time' => $startTime,
'return_code' => $returnCode,
'successful' => $returnCode === 0,
]);
} | php | public function run(CliCommandOptions $options = null)
{
$options = $this->getOptions($options);
$command = $this->buildCommand($options);
$startTime = microtime(true);
$response = $this->executor->execute(
$command,
$options->getCwd(),
$options->getEnv()
);
$elapsedTime = microtime(true) - $startTime;
$output = $response->getOutput();
$returnCode = $response->getReturnCode();
return new CliCommandResponse([
'command' => $command,
'elapsed_time' => $elapsedTime,
'output' => $output,
'start_time' => $startTime,
'return_code' => $returnCode,
'successful' => $returnCode === 0,
]);
} | [
"public",
"function",
"run",
"(",
"CliCommandOptions",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"getOptions",
"(",
"$",
"options",
")",
";",
"$",
"command",
"=",
"$",
"this",
"->",
"buildCommand",
"(",
"$",
"options",
")",
";",
"$",
"startTime",
"=",
"microtime",
"(",
"true",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"executor",
"->",
"execute",
"(",
"$",
"command",
",",
"$",
"options",
"->",
"getCwd",
"(",
")",
",",
"$",
"options",
"->",
"getEnv",
"(",
")",
")",
";",
"$",
"elapsedTime",
"=",
"microtime",
"(",
"true",
")",
"-",
"$",
"startTime",
";",
"$",
"output",
"=",
"$",
"response",
"->",
"getOutput",
"(",
")",
";",
"$",
"returnCode",
"=",
"$",
"response",
"->",
"getReturnCode",
"(",
")",
";",
"return",
"new",
"CliCommandResponse",
"(",
"[",
"'command'",
"=>",
"$",
"command",
",",
"'elapsed_time'",
"=>",
"$",
"elapsedTime",
",",
"'output'",
"=>",
"$",
"output",
",",
"'start_time'",
"=>",
"$",
"startTime",
",",
"'return_code'",
"=>",
"$",
"returnCode",
",",
"'successful'",
"=>",
"$",
"returnCode",
"===",
"0",
",",
"]",
")",
";",
"}"
] | Executes a cli command
@param CliCommandOptions $options object of `cwd`, `env`, and `redirect`
@return CliCommandResponse object with output and comand information | [
"Executes",
"a",
"cli",
"command"
] | 60c830550491742a077ab063f924e2f0b63825da | https://github.com/synapsestudios/synapse-base/blob/60c830550491742a077ab063f924e2f0b63825da/src/Synapse/CliCommand/AbstractCliCommand.php#L46-L70 |
9,338 | osflab/container | ZendContainer.php | ZendContainer.getDbConfig | protected static function getDbConfig()
{
static $config = null;
if (!$config) {
$config = Container::getConfig()->getConfig('db');
if (!is_array($config)) {
throw new ArchException('Key db must be declared in application configuration');
}
}
return $config;
} | php | protected static function getDbConfig()
{
static $config = null;
if (!$config) {
$config = Container::getConfig()->getConfig('db');
if (!is_array($config)) {
throw new ArchException('Key db must be declared in application configuration');
}
}
return $config;
} | [
"protected",
"static",
"function",
"getDbConfig",
"(",
")",
"{",
"static",
"$",
"config",
"=",
"null",
";",
"if",
"(",
"!",
"$",
"config",
")",
"{",
"$",
"config",
"=",
"Container",
"::",
"getConfig",
"(",
")",
"->",
"getConfig",
"(",
"'db'",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"config",
")",
")",
"{",
"throw",
"new",
"ArchException",
"(",
"'Key db must be declared in application configuration'",
")",
";",
"}",
"}",
"return",
"$",
"config",
";",
"}"
] | Configuration de la db dans la configuration de l'application
@return array
@throws ArchException | [
"Configuration",
"de",
"la",
"db",
"dans",
"la",
"configuration",
"de",
"l",
"application"
] | 415b374260ad377df00f8b3683b99f08bb4d25b6 | https://github.com/osflab/container/blob/415b374260ad377df00f8b3683b99f08bb4d25b6/ZendContainer.php#L51-L62 |
9,339 | phpservicebus/core | src/Transport/RabbitMq/RabbitMqQueueCreator.php | RabbitMqQueueCreator.createIfNecessary | public function createIfNecessary(QueueBindings $queueBindings)
{
$addresses = array_merge($queueBindings->getReceivingAddresses(), $queueBindings->getSendingAddresses());
foreach ($addresses as $address) {
$this->routingTopology->setupForEndpointUse($this->brokerModel, $address);
}
} | php | public function createIfNecessary(QueueBindings $queueBindings)
{
$addresses = array_merge($queueBindings->getReceivingAddresses(), $queueBindings->getSendingAddresses());
foreach ($addresses as $address) {
$this->routingTopology->setupForEndpointUse($this->brokerModel, $address);
}
} | [
"public",
"function",
"createIfNecessary",
"(",
"QueueBindings",
"$",
"queueBindings",
")",
"{",
"$",
"addresses",
"=",
"array_merge",
"(",
"$",
"queueBindings",
"->",
"getReceivingAddresses",
"(",
")",
",",
"$",
"queueBindings",
"->",
"getSendingAddresses",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"addresses",
"as",
"$",
"address",
")",
"{",
"$",
"this",
"->",
"routingTopology",
"->",
"setupForEndpointUse",
"(",
"$",
"this",
"->",
"brokerModel",
",",
"$",
"address",
")",
";",
"}",
"}"
] | Creates message queues for the defined queue bindings.
@param QueueBindings $queueBindings | [
"Creates",
"message",
"queues",
"for",
"the",
"defined",
"queue",
"bindings",
"."
] | adbcf94be1e022120ede0c5aafa8a4f7900b0a6c | https://github.com/phpservicebus/core/blob/adbcf94be1e022120ede0c5aafa8a4f7900b0a6c/src/Transport/RabbitMq/RabbitMqQueueCreator.php#L42-L48 |
9,340 | ddliu/requery | src/Context.php | Context.extract | public function extract($parts = null) {
if ($this->isEmpty()) {
return false;
}
if ($parts === null) {
return $this->content;
}
if (is_array($parts)) {
$result = array();
foreach ($parts as $key) {
if (isset($this->content[$key])) {
$result[$key] = $this->content[$key];
}
}
return $result;
}
return isset($this->content[$parts])?$this->content[$parts]:false;
} | php | public function extract($parts = null) {
if ($this->isEmpty()) {
return false;
}
if ($parts === null) {
return $this->content;
}
if (is_array($parts)) {
$result = array();
foreach ($parts as $key) {
if (isset($this->content[$key])) {
$result[$key] = $this->content[$key];
}
}
return $result;
}
return isset($this->content[$parts])?$this->content[$parts]:false;
} | [
"public",
"function",
"extract",
"(",
"$",
"parts",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isEmpty",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"parts",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"content",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"parts",
")",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"content",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"result",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"content",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"content",
"[",
"$",
"parts",
"]",
")",
"?",
"$",
"this",
"->",
"content",
"[",
"$",
"parts",
"]",
":",
"false",
";",
"}"
] | Extract result parts of current query.
@param mixed $parts
@return mixed | [
"Extract",
"result",
"parts",
"of",
"current",
"query",
"."
] | ed1a8d45644965cf464b5eb1eede6ed8236ae6e8 | https://github.com/ddliu/requery/blob/ed1a8d45644965cf464b5eb1eede6ed8236ae6e8/src/Context.php#L47-L68 |
9,341 | ddliu/requery | src/Context.php | Context.find | public function find($re, $filter = null) {
if ($this->isEmpty()) {
return self::getEmptyContext();
}
$result = null;
if ($filter) {
$this->findAll($re)->each(function($context) use ($filter, &$result) {
if ($filter($context)) {
$result = $context;
return false;
}
});
return $result?:self::getEmptyContext();
}
if (!preg_match($re, $this->toString(), $match)) {
return self::getEmptyContext();
}
return new self($match);
} | php | public function find($re, $filter = null) {
if ($this->isEmpty()) {
return self::getEmptyContext();
}
$result = null;
if ($filter) {
$this->findAll($re)->each(function($context) use ($filter, &$result) {
if ($filter($context)) {
$result = $context;
return false;
}
});
return $result?:self::getEmptyContext();
}
if (!preg_match($re, $this->toString(), $match)) {
return self::getEmptyContext();
}
return new self($match);
} | [
"public",
"function",
"find",
"(",
"$",
"re",
",",
"$",
"filter",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isEmpty",
"(",
")",
")",
"{",
"return",
"self",
"::",
"getEmptyContext",
"(",
")",
";",
"}",
"$",
"result",
"=",
"null",
";",
"if",
"(",
"$",
"filter",
")",
"{",
"$",
"this",
"->",
"findAll",
"(",
"$",
"re",
")",
"->",
"each",
"(",
"function",
"(",
"$",
"context",
")",
"use",
"(",
"$",
"filter",
",",
"&",
"$",
"result",
")",
"{",
"if",
"(",
"$",
"filter",
"(",
"$",
"context",
")",
")",
"{",
"$",
"result",
"=",
"$",
"context",
";",
"return",
"false",
";",
"}",
"}",
")",
";",
"return",
"$",
"result",
"?",
":",
"self",
"::",
"getEmptyContext",
"(",
")",
";",
"}",
"if",
"(",
"!",
"preg_match",
"(",
"$",
"re",
",",
"$",
"this",
"->",
"toString",
"(",
")",
",",
"$",
"match",
")",
")",
"{",
"return",
"self",
"::",
"getEmptyContext",
"(",
")",
";",
"}",
"return",
"new",
"self",
"(",
"$",
"match",
")",
";",
"}"
] | Find with regexp in current context
@param string $re
@param callable $filter
@return Context | [
"Find",
"with",
"regexp",
"in",
"current",
"context"
] | ed1a8d45644965cf464b5eb1eede6ed8236ae6e8 | https://github.com/ddliu/requery/blob/ed1a8d45644965cf464b5eb1eede6ed8236ae6e8/src/Context.php#L76-L99 |
9,342 | ddliu/requery | src/Context.php | Context.findAll | public function findAll($re, $filter = null) {
if ($this->isEmpty()) {
return self::getEmptyContext();
}
if (!preg_match_all($re, $this->toString(), $matches, PREG_SET_ORDER)) {
$matches = array();
}
$result = array();
foreach ($matches as $match) {
$context = new self($match);
if (!$filter || $filter($context)) {
$result[] = $match;
}
}
return new ContextCollection($result);
} | php | public function findAll($re, $filter = null) {
if ($this->isEmpty()) {
return self::getEmptyContext();
}
if (!preg_match_all($re, $this->toString(), $matches, PREG_SET_ORDER)) {
$matches = array();
}
$result = array();
foreach ($matches as $match) {
$context = new self($match);
if (!$filter || $filter($context)) {
$result[] = $match;
}
}
return new ContextCollection($result);
} | [
"public",
"function",
"findAll",
"(",
"$",
"re",
",",
"$",
"filter",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isEmpty",
"(",
")",
")",
"{",
"return",
"self",
"::",
"getEmptyContext",
"(",
")",
";",
"}",
"if",
"(",
"!",
"preg_match_all",
"(",
"$",
"re",
",",
"$",
"this",
"->",
"toString",
"(",
")",
",",
"$",
"matches",
",",
"PREG_SET_ORDER",
")",
")",
"{",
"$",
"matches",
"=",
"array",
"(",
")",
";",
"}",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"matches",
"as",
"$",
"match",
")",
"{",
"$",
"context",
"=",
"new",
"self",
"(",
"$",
"match",
")",
";",
"if",
"(",
"!",
"$",
"filter",
"||",
"$",
"filter",
"(",
"$",
"context",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"match",
";",
"}",
"}",
"return",
"new",
"ContextCollection",
"(",
"$",
"result",
")",
";",
"}"
] | Find all matching data in the context.
@param string $re
@param callbale $filter
@return ContextCollection | [
"Find",
"all",
"matching",
"data",
"in",
"the",
"context",
"."
] | ed1a8d45644965cf464b5eb1eede6ed8236ae6e8 | https://github.com/ddliu/requery/blob/ed1a8d45644965cf464b5eb1eede6ed8236ae6e8/src/Context.php#L123-L141 |
9,343 | Webiny/BackupService | src/Webiny/BackupService/Lib/Cleanup.php | Cleanup.addToQueue | public static function addToQueue($path, $type)
{
if ($type != self::TYPE_DIR && $type != self::TYPE_FILE) {
throw new \Exception(sprintf('Invalid $type parameter "%s"', $type));
}
self::$cleanupQueue[] = ['path' => $path, 'type' => $type];
} | php | public static function addToQueue($path, $type)
{
if ($type != self::TYPE_DIR && $type != self::TYPE_FILE) {
throw new \Exception(sprintf('Invalid $type parameter "%s"', $type));
}
self::$cleanupQueue[] = ['path' => $path, 'type' => $type];
} | [
"public",
"static",
"function",
"addToQueue",
"(",
"$",
"path",
",",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"type",
"!=",
"self",
"::",
"TYPE_DIR",
"&&",
"$",
"type",
"!=",
"self",
"::",
"TYPE_FILE",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Invalid $type parameter \"%s\"'",
",",
"$",
"type",
")",
")",
";",
"}",
"self",
"::",
"$",
"cleanupQueue",
"[",
"]",
"=",
"[",
"'path'",
"=>",
"$",
"path",
",",
"'type'",
"=>",
"$",
"type",
"]",
";",
"}"
] | Add a file or a folder to the cleanup queue.
@param string $path Path that should be removed.
@param string $type Is it a file or a directory.
@throws \Exception | [
"Add",
"a",
"file",
"or",
"a",
"folder",
"to",
"the",
"cleanup",
"queue",
"."
] | 9728ddaa67e5703ac7898a6f69a0ad14ac37a256 | https://github.com/Webiny/BackupService/blob/9728ddaa67e5703ac7898a6f69a0ad14ac37a256/src/Webiny/BackupService/Lib/Cleanup.php#L53-L60 |
9,344 | Webiny/BackupService | src/Webiny/BackupService/Lib/Cleanup.php | Cleanup.doCleanup | public static function doCleanup()
{
Service::$log->msg('Cleanup started');
foreach (self::$cleanupQueue as $cq) {
Service::$log->msg(sprintf('Removing %s %s', $cq['type'], $cq['path']));
if (strpos($cq['path'], self::$tempFolder) !== 0) {
throw new \Exception(sprintf('Path "%s" is not within the defined temp folder location "%s".',
$cq['path'], self::$tempFolder));
}
if ($cq['type'] == self::TYPE_DIR) {
system('rm -rf ' . $cq['path']);
}
if ($cq['type'] == self::TYPE_FILE) {
system('rm ' . $cq['path']);
}
}
Service::$log->msg('Cleanup ended');
} | php | public static function doCleanup()
{
Service::$log->msg('Cleanup started');
foreach (self::$cleanupQueue as $cq) {
Service::$log->msg(sprintf('Removing %s %s', $cq['type'], $cq['path']));
if (strpos($cq['path'], self::$tempFolder) !== 0) {
throw new \Exception(sprintf('Path "%s" is not within the defined temp folder location "%s".',
$cq['path'], self::$tempFolder));
}
if ($cq['type'] == self::TYPE_DIR) {
system('rm -rf ' . $cq['path']);
}
if ($cq['type'] == self::TYPE_FILE) {
system('rm ' . $cq['path']);
}
}
Service::$log->msg('Cleanup ended');
} | [
"public",
"static",
"function",
"doCleanup",
"(",
")",
"{",
"Service",
"::",
"$",
"log",
"->",
"msg",
"(",
"'Cleanup started'",
")",
";",
"foreach",
"(",
"self",
"::",
"$",
"cleanupQueue",
"as",
"$",
"cq",
")",
"{",
"Service",
"::",
"$",
"log",
"->",
"msg",
"(",
"sprintf",
"(",
"'Removing %s %s'",
",",
"$",
"cq",
"[",
"'type'",
"]",
",",
"$",
"cq",
"[",
"'path'",
"]",
")",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"cq",
"[",
"'path'",
"]",
",",
"self",
"::",
"$",
"tempFolder",
")",
"!==",
"0",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Path \"%s\" is not within the defined temp folder location \"%s\".'",
",",
"$",
"cq",
"[",
"'path'",
"]",
",",
"self",
"::",
"$",
"tempFolder",
")",
")",
";",
"}",
"if",
"(",
"$",
"cq",
"[",
"'type'",
"]",
"==",
"self",
"::",
"TYPE_DIR",
")",
"{",
"system",
"(",
"'rm -rf '",
".",
"$",
"cq",
"[",
"'path'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"cq",
"[",
"'type'",
"]",
"==",
"self",
"::",
"TYPE_FILE",
")",
"{",
"system",
"(",
"'rm '",
".",
"$",
"cq",
"[",
"'path'",
"]",
")",
";",
"}",
"}",
"Service",
"::",
"$",
"log",
"->",
"msg",
"(",
"'Cleanup ended'",
")",
";",
"}"
] | Method that does the actual cleanup.
@throws \Exception | [
"Method",
"that",
"does",
"the",
"actual",
"cleanup",
"."
] | 9728ddaa67e5703ac7898a6f69a0ad14ac37a256 | https://github.com/Webiny/BackupService/blob/9728ddaa67e5703ac7898a6f69a0ad14ac37a256/src/Webiny/BackupService/Lib/Cleanup.php#L67-L88 |
9,345 | monolyth-php/formulaic | src/Element/Group.php | Group.setIdPrefix | public function setIdPrefix(string $prefix = null)
{
foreach ((array)$this as $element) {
if (is_object($element)) {
$element->setIdPrefix($prefix);
}
}
} | php | public function setIdPrefix(string $prefix = null)
{
foreach ((array)$this as $element) {
if (is_object($element)) {
$element->setIdPrefix($prefix);
}
}
} | [
"public",
"function",
"setIdPrefix",
"(",
"string",
"$",
"prefix",
"=",
"null",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"this",
"as",
"$",
"element",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"element",
")",
")",
"{",
"$",
"element",
"->",
"setIdPrefix",
"(",
"$",
"prefix",
")",
";",
"}",
"}",
"}"
] | Sets the ID prefix for this group. The ID prefix is optionally prefixed
to all generated IDs to resolve ambiguity.
@param string $prefix The prefix. Set to `null` to remove. | [
"Sets",
"the",
"ID",
"prefix",
"for",
"this",
"group",
".",
"The",
"ID",
"prefix",
"is",
"optionally",
"prefixed",
"to",
"all",
"generated",
"IDs",
"to",
"resolve",
"ambiguity",
"."
] | 4bf7853a0c29cc17957f1b26c79f633867742c14 | https://github.com/monolyth-php/formulaic/blob/4bf7853a0c29cc17957f1b26c79f633867742c14/src/Element/Group.php#L71-L78 |
9,346 | monolyth-php/formulaic | src/Element/Group.php | Group.valueSuppliedByUser | public function valueSuppliedByUser(bool $status = null) : bool
{
$is = false;
foreach ((array)$this as $field) {
if (is_string($field)) {
continue;
}
if (isset($status)) {
$field->getElement()->valueSuppliedByUser($status);
}
if ($field->getElement()->valueSuppliedByUser()) {
$is = true;
}
}
return $is;
} | php | public function valueSuppliedByUser(bool $status = null) : bool
{
$is = false;
foreach ((array)$this as $field) {
if (is_string($field)) {
continue;
}
if (isset($status)) {
$field->getElement()->valueSuppliedByUser($status);
}
if ($field->getElement()->valueSuppliedByUser()) {
$is = true;
}
}
return $is;
} | [
"public",
"function",
"valueSuppliedByUser",
"(",
"bool",
"$",
"status",
"=",
"null",
")",
":",
"bool",
"{",
"$",
"is",
"=",
"false",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"this",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"field",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"status",
")",
")",
"{",
"$",
"field",
"->",
"getElement",
"(",
")",
"->",
"valueSuppliedByUser",
"(",
"$",
"status",
")",
";",
"}",
"if",
"(",
"$",
"field",
"->",
"getElement",
"(",
")",
"->",
"valueSuppliedByUser",
"(",
")",
")",
"{",
"$",
"is",
"=",
"true",
";",
"}",
"}",
"return",
"$",
"is",
";",
"}"
] | Mark the entire group as set by the user.
@param bool $status Optional setter. Omit if you just want to query the
current status.
@return bool | [
"Mark",
"the",
"entire",
"group",
"as",
"set",
"by",
"the",
"user",
"."
] | 4bf7853a0c29cc17957f1b26c79f633867742c14 | https://github.com/monolyth-php/formulaic/blob/4bf7853a0c29cc17957f1b26c79f633867742c14/src/Element/Group.php#L185-L200 |
9,347 | Dhii/data-state-abstract | src/TransitionerAwareTrait.php | TransitionerAwareTrait._setTransitioner | protected function _setTransitioner($transitioner)
{
if ($transitioner !== null && !($transitioner instanceof TransitionerInterface)) {
throw $this->_createInvalidArgumentException(
$this->__('Argument is not a valid booking transitioner'),
null,
null,
$transitioner
);
}
$this->transitioner = $transitioner;
} | php | protected function _setTransitioner($transitioner)
{
if ($transitioner !== null && !($transitioner instanceof TransitionerInterface)) {
throw $this->_createInvalidArgumentException(
$this->__('Argument is not a valid booking transitioner'),
null,
null,
$transitioner
);
}
$this->transitioner = $transitioner;
} | [
"protected",
"function",
"_setTransitioner",
"(",
"$",
"transitioner",
")",
"{",
"if",
"(",
"$",
"transitioner",
"!==",
"null",
"&&",
"!",
"(",
"$",
"transitioner",
"instanceof",
"TransitionerInterface",
")",
")",
"{",
"throw",
"$",
"this",
"->",
"_createInvalidArgumentException",
"(",
"$",
"this",
"->",
"__",
"(",
"'Argument is not a valid booking transitioner'",
")",
",",
"null",
",",
"null",
",",
"$",
"transitioner",
")",
";",
"}",
"$",
"this",
"->",
"transitioner",
"=",
"$",
"transitioner",
";",
"}"
] | Sets the booking transitioner for this instance.
@since [*next-version*]
@param TransitionerInterface|null $transitioner The transitioner or null.
@throws InvalidArgumentException If the argument is not valid. | [
"Sets",
"the",
"booking",
"transitioner",
"for",
"this",
"instance",
"."
] | c335c37a939861659e657b995cfc657bb3bb2733 | https://github.com/Dhii/data-state-abstract/blob/c335c37a939861659e657b995cfc657bb3bb2733/src/TransitionerAwareTrait.php#L46-L58 |
9,348 | phramework/util | src/File.php | File.directoryToArray | public static function directoryToArray(
string $directory,
bool $recursive = false,
bool $listDirs = false,
bool $listFiles = true,
string $exclude = '',
array $allowedFileTypes = [],
bool $relativePath = false
) : array {
$arrayItems = [];
$skipByExclude = false;
$handle = opendir($directory);
if ($handle) {
while (false !== ($file = readdir($handle))) {
preg_match(
'/(^(([\.]) {1,2})$|(\.(svn|git|md|htaccess))|(Thumbs\.db|\.DS_STORE|\.|\.\.))$/iu',
$file,
$skip
);
if ($exclude) {
preg_match($exclude, $file, $skipByExclude);
}
if ($allowedFileTypes && !is_dir($directory . DIRECTORY_SEPARATOR . $file)) {
$ext = strtolower(preg_replace('/^.*\.([^.]+)$/D', '$1', $file));
if (!in_array($ext, $allowedFileTypes)) {
$skip = true;
}
}
if (!$skip && !$skipByExclude) {
if (is_dir($directory . DIRECTORY_SEPARATOR . $file)) {
if ($recursive) {
$arrayItems = array_merge(
$arrayItems,
self::directoryToArray(
$directory . DIRECTORY_SEPARATOR . $file,
$recursive,
$listDirs,
$listFiles,
$exclude,
$allowedFileTypes,
$relativePath
)
);
}
if ($listDirs) {
$arrayItems[] = (
$relativePath
? $file
: $directory . DIRECTORY_SEPARATOR . $file
);
}
} else {
if ($listFiles) {
$arrayItems[] = (
$relativePath
? $file
: $directory . DIRECTORY_SEPARATOR . $file
);
}
}
}
}
closedir($handle);
}
return $arrayItems;
} | php | public static function directoryToArray(
string $directory,
bool $recursive = false,
bool $listDirs = false,
bool $listFiles = true,
string $exclude = '',
array $allowedFileTypes = [],
bool $relativePath = false
) : array {
$arrayItems = [];
$skipByExclude = false;
$handle = opendir($directory);
if ($handle) {
while (false !== ($file = readdir($handle))) {
preg_match(
'/(^(([\.]) {1,2})$|(\.(svn|git|md|htaccess))|(Thumbs\.db|\.DS_STORE|\.|\.\.))$/iu',
$file,
$skip
);
if ($exclude) {
preg_match($exclude, $file, $skipByExclude);
}
if ($allowedFileTypes && !is_dir($directory . DIRECTORY_SEPARATOR . $file)) {
$ext = strtolower(preg_replace('/^.*\.([^.]+)$/D', '$1', $file));
if (!in_array($ext, $allowedFileTypes)) {
$skip = true;
}
}
if (!$skip && !$skipByExclude) {
if (is_dir($directory . DIRECTORY_SEPARATOR . $file)) {
if ($recursive) {
$arrayItems = array_merge(
$arrayItems,
self::directoryToArray(
$directory . DIRECTORY_SEPARATOR . $file,
$recursive,
$listDirs,
$listFiles,
$exclude,
$allowedFileTypes,
$relativePath
)
);
}
if ($listDirs) {
$arrayItems[] = (
$relativePath
? $file
: $directory . DIRECTORY_SEPARATOR . $file
);
}
} else {
if ($listFiles) {
$arrayItems[] = (
$relativePath
? $file
: $directory . DIRECTORY_SEPARATOR . $file
);
}
}
}
}
closedir($handle);
}
return $arrayItems;
} | [
"public",
"static",
"function",
"directoryToArray",
"(",
"string",
"$",
"directory",
",",
"bool",
"$",
"recursive",
"=",
"false",
",",
"bool",
"$",
"listDirs",
"=",
"false",
",",
"bool",
"$",
"listFiles",
"=",
"true",
",",
"string",
"$",
"exclude",
"=",
"''",
",",
"array",
"$",
"allowedFileTypes",
"=",
"[",
"]",
",",
"bool",
"$",
"relativePath",
"=",
"false",
")",
":",
"array",
"{",
"$",
"arrayItems",
"=",
"[",
"]",
";",
"$",
"skipByExclude",
"=",
"false",
";",
"$",
"handle",
"=",
"opendir",
"(",
"$",
"directory",
")",
";",
"if",
"(",
"$",
"handle",
")",
"{",
"while",
"(",
"false",
"!==",
"(",
"$",
"file",
"=",
"readdir",
"(",
"$",
"handle",
")",
")",
")",
"{",
"preg_match",
"(",
"'/(^(([\\.]) {1,2})$|(\\.(svn|git|md|htaccess))|(Thumbs\\.db|\\.DS_STORE|\\.|\\.\\.))$/iu'",
",",
"$",
"file",
",",
"$",
"skip",
")",
";",
"if",
"(",
"$",
"exclude",
")",
"{",
"preg_match",
"(",
"$",
"exclude",
",",
"$",
"file",
",",
"$",
"skipByExclude",
")",
";",
"}",
"if",
"(",
"$",
"allowedFileTypes",
"&&",
"!",
"is_dir",
"(",
"$",
"directory",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
")",
")",
"{",
"$",
"ext",
"=",
"strtolower",
"(",
"preg_replace",
"(",
"'/^.*\\.([^.]+)$/D'",
",",
"'$1'",
",",
"$",
"file",
")",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"ext",
",",
"$",
"allowedFileTypes",
")",
")",
"{",
"$",
"skip",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"skip",
"&&",
"!",
"$",
"skipByExclude",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"directory",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
")",
")",
"{",
"if",
"(",
"$",
"recursive",
")",
"{",
"$",
"arrayItems",
"=",
"array_merge",
"(",
"$",
"arrayItems",
",",
"self",
"::",
"directoryToArray",
"(",
"$",
"directory",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
",",
"$",
"recursive",
",",
"$",
"listDirs",
",",
"$",
"listFiles",
",",
"$",
"exclude",
",",
"$",
"allowedFileTypes",
",",
"$",
"relativePath",
")",
")",
";",
"}",
"if",
"(",
"$",
"listDirs",
")",
"{",
"$",
"arrayItems",
"[",
"]",
"=",
"(",
"$",
"relativePath",
"?",
"$",
"file",
":",
"$",
"directory",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"listFiles",
")",
"{",
"$",
"arrayItems",
"[",
"]",
"=",
"(",
"$",
"relativePath",
"?",
"$",
"file",
":",
"$",
"directory",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
")",
";",
"}",
"}",
"}",
"}",
"closedir",
"(",
"$",
"handle",
")",
";",
"}",
"return",
"$",
"arrayItems",
";",
"}"
] | Get an array that represents directory tree
@param string $directory Directory path
@param boolean $recursive *[Optional]* Include sub directories
@param boolean $listDirs *[Optional]* Include directories on listing
@param boolean $listFiles *[Optional]* Include files on listing
@param string $exclude *[Optional]* Exclude paths that matches this
regular expression
@param string[] $allowedFileTypes *[Optional]* Allowed file extensions,
default `[]` (allow all)
@param boolean $relativePath *[Optional]* Return paths in relative form,
default `false`
@link https://github.com/phramework/phramework/blob/master/src/Models/Util.php Source
@return array | [
"Get",
"an",
"array",
"that",
"represents",
"directory",
"tree"
] | 09202b9962a9a07e2a31b0c9eff90ece1d6bd3ca | https://github.com/phramework/util/blob/09202b9962a9a07e2a31b0c9eff90ece1d6bd3ca/src/File.php#L91-L156 |
9,349 | phPoirot/PathUri | UriSequence.php | UriSequence.isAbsolute | function isAbsolute()
{
$p = $this->getPath();
reset($p);
$fi = current($p);
return $this->_isRoot($fi);
} | php | function isAbsolute()
{
$p = $this->getPath();
reset($p);
$fi = current($p);
return $this->_isRoot($fi);
} | [
"function",
"isAbsolute",
"(",
")",
"{",
"$",
"p",
"=",
"$",
"this",
"->",
"getPath",
"(",
")",
";",
"reset",
"(",
"$",
"p",
")",
";",
"$",
"fi",
"=",
"current",
"(",
"$",
"p",
")",
";",
"return",
"$",
"this",
"->",
"_isRoot",
"(",
"$",
"fi",
")",
";",
"}"
] | Is Absolute Path?
@return boolean | [
"Is",
"Absolute",
"Path?"
] | 1f765e77b5aca20f6440d3e27a8df60ed888c09e | https://github.com/phPoirot/PathUri/blob/1f765e77b5aca20f6440d3e27a8df60ed888c09e/UriSequence.php#L92-L99 |
9,350 | phPoirot/PathUri | UriSequence.php | UriSequence.joint | function joint(iUriSequence $pathUri)
{
$muchLength = $this->getPath();
$less = $pathUri->getPath();
if ( count($less) > count($muchLength) ) {
$muchLength = $less;
$less = $this->getPath();
}
$similar = array(); // empty path
foreach($muchLength as $i => $v) {
if (!array_key_exists($i, $less) || $v != $less[$i])
break;
$similar[] = $v;
}
$path = clone $this;
$path->setPath($similar);
return $path;
} | php | function joint(iUriSequence $pathUri)
{
$muchLength = $this->getPath();
$less = $pathUri->getPath();
if ( count($less) > count($muchLength) ) {
$muchLength = $less;
$less = $this->getPath();
}
$similar = array(); // empty path
foreach($muchLength as $i => $v) {
if (!array_key_exists($i, $less) || $v != $less[$i])
break;
$similar[] = $v;
}
$path = clone $this;
$path->setPath($similar);
return $path;
} | [
"function",
"joint",
"(",
"iUriSequence",
"$",
"pathUri",
")",
"{",
"$",
"muchLength",
"=",
"$",
"this",
"->",
"getPath",
"(",
")",
";",
"$",
"less",
"=",
"$",
"pathUri",
"->",
"getPath",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"less",
")",
">",
"count",
"(",
"$",
"muchLength",
")",
")",
"{",
"$",
"muchLength",
"=",
"$",
"less",
";",
"$",
"less",
"=",
"$",
"this",
"->",
"getPath",
"(",
")",
";",
"}",
"$",
"similar",
"=",
"array",
"(",
")",
";",
"// empty path",
"foreach",
"(",
"$",
"muchLength",
"as",
"$",
"i",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"i",
",",
"$",
"less",
")",
"||",
"$",
"v",
"!=",
"$",
"less",
"[",
"$",
"i",
"]",
")",
"break",
";",
"$",
"similar",
"[",
"]",
"=",
"$",
"v",
";",
"}",
"$",
"path",
"=",
"clone",
"$",
"this",
";",
"$",
"path",
"->",
"setPath",
"(",
"$",
"similar",
")",
";",
"return",
"$",
"path",
";",
"}"
] | Joint Given PathUri with Current Path
/var/www/html <=> /var/www/ ===> /var/www
@param iUriSequence $pathUri
@return iUriSequence | [
"Joint",
"Given",
"PathUri",
"with",
"Current",
"Path"
] | 1f765e77b5aca20f6440d3e27a8df60ed888c09e | https://github.com/phPoirot/PathUri/blob/1f765e77b5aca20f6440d3e27a8df60ed888c09e/UriSequence.php#L190-L211 |
9,351 | phPoirot/PathUri | UriSequence.php | UriSequence.mask | function mask(iUriSequence $pathUri, $toggle = true)
{
# the absolute path when another is not is always masked on
#- /foo <=> bar ---> /foo
if (
## one is absolute and another is not
($this->isAbsolute() || $pathUri->isAbsolute())
&& !($this->isAbsolute() && $pathUri->isAbsolute())
) {
$uri = clone $this;
if ($pathUri->isAbsolute())
### return absolutes one
$uri->setPath($pathUri->getPath());
return $uri;
}
// ..
$muchLength = $this->getPath();
$less = $pathUri->getPath();
if ( $toggle && (count($less) > count($muchLength)) ) {
$muchLength = $less;
$less = $this->getPath();
}
$masked = $muchLength;
foreach($muchLength as $i => $v) {
if (!array_key_exists($i, $less) || $v != $less[$i])
break;
unset($masked[$i]);
}
$uri = clone $this;
$uri->setPath($masked);
return $uri;
} | php | function mask(iUriSequence $pathUri, $toggle = true)
{
# the absolute path when another is not is always masked on
#- /foo <=> bar ---> /foo
if (
## one is absolute and another is not
($this->isAbsolute() || $pathUri->isAbsolute())
&& !($this->isAbsolute() && $pathUri->isAbsolute())
) {
$uri = clone $this;
if ($pathUri->isAbsolute())
### return absolutes one
$uri->setPath($pathUri->getPath());
return $uri;
}
// ..
$muchLength = $this->getPath();
$less = $pathUri->getPath();
if ( $toggle && (count($less) > count($muchLength)) ) {
$muchLength = $less;
$less = $this->getPath();
}
$masked = $muchLength;
foreach($muchLength as $i => $v) {
if (!array_key_exists($i, $less) || $v != $less[$i])
break;
unset($masked[$i]);
}
$uri = clone $this;
$uri->setPath($masked);
return $uri;
} | [
"function",
"mask",
"(",
"iUriSequence",
"$",
"pathUri",
",",
"$",
"toggle",
"=",
"true",
")",
"{",
"# the absolute path when another is not is always masked on",
"#- /foo <=> bar ---> /foo",
"if",
"(",
"## one is absolute and another is not",
"(",
"$",
"this",
"->",
"isAbsolute",
"(",
")",
"||",
"$",
"pathUri",
"->",
"isAbsolute",
"(",
")",
")",
"&&",
"!",
"(",
"$",
"this",
"->",
"isAbsolute",
"(",
")",
"&&",
"$",
"pathUri",
"->",
"isAbsolute",
"(",
")",
")",
")",
"{",
"$",
"uri",
"=",
"clone",
"$",
"this",
";",
"if",
"(",
"$",
"pathUri",
"->",
"isAbsolute",
"(",
")",
")",
"### return absolutes one",
"$",
"uri",
"->",
"setPath",
"(",
"$",
"pathUri",
"->",
"getPath",
"(",
")",
")",
";",
"return",
"$",
"uri",
";",
"}",
"// ..",
"$",
"muchLength",
"=",
"$",
"this",
"->",
"getPath",
"(",
")",
";",
"$",
"less",
"=",
"$",
"pathUri",
"->",
"getPath",
"(",
")",
";",
"if",
"(",
"$",
"toggle",
"&&",
"(",
"count",
"(",
"$",
"less",
")",
">",
"count",
"(",
"$",
"muchLength",
")",
")",
")",
"{",
"$",
"muchLength",
"=",
"$",
"less",
";",
"$",
"less",
"=",
"$",
"this",
"->",
"getPath",
"(",
")",
";",
"}",
"$",
"masked",
"=",
"$",
"muchLength",
";",
"foreach",
"(",
"$",
"muchLength",
"as",
"$",
"i",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"i",
",",
"$",
"less",
")",
"||",
"$",
"v",
"!=",
"$",
"less",
"[",
"$",
"i",
"]",
")",
"break",
";",
"unset",
"(",
"$",
"masked",
"[",
"$",
"i",
"]",
")",
";",
"}",
"$",
"uri",
"=",
"clone",
"$",
"this",
";",
"$",
"uri",
"->",
"setPath",
"(",
"$",
"masked",
")",
";",
"return",
"$",
"uri",
";",
"}"
] | Mask Given PathUri with Current Path
toggle:
/var/www/html <=> /var/www/ ===> html
/uri <=> contact ===> /uri
/uri <=> /contact ===> uri
/uri/path <=> /contact ===> uri/path
/uri/ <=> /uri/contact ===> (empty)
/uri/ <=> /uri/contact/ ===> contact/
toggle false:
/var/www/ <=> /var/www/html ===> ''
@param iUriSequence $pathUri
@param bool $toggle with toggle always bigger path
compared to little one
@return iUriSequence | [
"Mask",
"Given",
"PathUri",
"with",
"Current",
"Path"
] | 1f765e77b5aca20f6440d3e27a8df60ed888c09e | https://github.com/phPoirot/PathUri/blob/1f765e77b5aca20f6440d3e27a8df60ed888c09e/UriSequence.php#L233-L273 |
9,352 | phPoirot/PathUri | UriSequence.php | UriSequence.normalize | function normalize()
{
$normalized = array();
$paths = $this->getPath();
if (empty($paths))
return $normalized;
// Replace "~" with user's home directory.
if ('~' === $paths[0]) {
$home = explode($this->getSeparator(), str_replace('\\', '/', $this->_getHomeDir()));
$paths = $paths + $home;
}
$isRoot = $this->_isRoot($paths[0]);
$paths = array_filter($paths, function($p, $i) use (&$isRoot, $paths) {
if ( ($isRoot && $i > 0) || $i+1 == count($paths) /* keep last slash remain */) {
// keep last slash /go/to/path/
// keep first slash after root if exists
// phar://path/to/res
$isRoot = false;
return true;
}
// Remove all ['',] from path
// on appended path we don't want any absolute sign in
// array list
return ($p !== '' && $p !== '.');
}, ARRAY_FILTER_USE_BOTH);
// Collapse ".." with the previous part, if one exists
// Don't collapse ".." if the previous part is also ".."
foreach ($paths as $path) {
if ( '..' === $path && count($normalized) > 0 // keep first segment
&& '..' !== $normalized[count($normalized) - 1]
) {
if (! $this->_isRoot($normalized[count($normalized) - 1]) )
array_pop($normalized);
continue;
}
$normalized[] = $path;
}
$this->setPath($normalized);
return $this;
} | php | function normalize()
{
$normalized = array();
$paths = $this->getPath();
if (empty($paths))
return $normalized;
// Replace "~" with user's home directory.
if ('~' === $paths[0]) {
$home = explode($this->getSeparator(), str_replace('\\', '/', $this->_getHomeDir()));
$paths = $paths + $home;
}
$isRoot = $this->_isRoot($paths[0]);
$paths = array_filter($paths, function($p, $i) use (&$isRoot, $paths) {
if ( ($isRoot && $i > 0) || $i+1 == count($paths) /* keep last slash remain */) {
// keep last slash /go/to/path/
// keep first slash after root if exists
// phar://path/to/res
$isRoot = false;
return true;
}
// Remove all ['',] from path
// on appended path we don't want any absolute sign in
// array list
return ($p !== '' && $p !== '.');
}, ARRAY_FILTER_USE_BOTH);
// Collapse ".." with the previous part, if one exists
// Don't collapse ".." if the previous part is also ".."
foreach ($paths as $path) {
if ( '..' === $path && count($normalized) > 0 // keep first segment
&& '..' !== $normalized[count($normalized) - 1]
) {
if (! $this->_isRoot($normalized[count($normalized) - 1]) )
array_pop($normalized);
continue;
}
$normalized[] = $path;
}
$this->setPath($normalized);
return $this;
} | [
"function",
"normalize",
"(",
")",
"{",
"$",
"normalized",
"=",
"array",
"(",
")",
";",
"$",
"paths",
"=",
"$",
"this",
"->",
"getPath",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"paths",
")",
")",
"return",
"$",
"normalized",
";",
"// Replace \"~\" with user's home directory.",
"if",
"(",
"'~'",
"===",
"$",
"paths",
"[",
"0",
"]",
")",
"{",
"$",
"home",
"=",
"explode",
"(",
"$",
"this",
"->",
"getSeparator",
"(",
")",
",",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"this",
"->",
"_getHomeDir",
"(",
")",
")",
")",
";",
"$",
"paths",
"=",
"$",
"paths",
"+",
"$",
"home",
";",
"}",
"$",
"isRoot",
"=",
"$",
"this",
"->",
"_isRoot",
"(",
"$",
"paths",
"[",
"0",
"]",
")",
";",
"$",
"paths",
"=",
"array_filter",
"(",
"$",
"paths",
",",
"function",
"(",
"$",
"p",
",",
"$",
"i",
")",
"use",
"(",
"&",
"$",
"isRoot",
",",
"$",
"paths",
")",
"{",
"if",
"(",
"(",
"$",
"isRoot",
"&&",
"$",
"i",
">",
"0",
")",
"||",
"$",
"i",
"+",
"1",
"==",
"count",
"(",
"$",
"paths",
")",
"/* keep last slash remain */",
")",
"{",
"// keep last slash /go/to/path/",
"// keep first slash after root if exists",
"// phar://path/to/res",
"$",
"isRoot",
"=",
"false",
";",
"return",
"true",
";",
"}",
"// Remove all ['',] from path",
"// on appended path we don't want any absolute sign in",
"// array list",
"return",
"(",
"$",
"p",
"!==",
"''",
"&&",
"$",
"p",
"!==",
"'.'",
")",
";",
"}",
",",
"ARRAY_FILTER_USE_BOTH",
")",
";",
"// Collapse \"..\" with the previous part, if one exists",
"// Don't collapse \"..\" if the previous part is also \"..\"",
"foreach",
"(",
"$",
"paths",
"as",
"$",
"path",
")",
"{",
"if",
"(",
"'..'",
"===",
"$",
"path",
"&&",
"count",
"(",
"$",
"normalized",
")",
">",
"0",
"// keep first segment",
"&&",
"'..'",
"!==",
"$",
"normalized",
"[",
"count",
"(",
"$",
"normalized",
")",
"-",
"1",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_isRoot",
"(",
"$",
"normalized",
"[",
"count",
"(",
"$",
"normalized",
")",
"-",
"1",
"]",
")",
")",
"array_pop",
"(",
"$",
"normalized",
")",
";",
"continue",
";",
"}",
"$",
"normalized",
"[",
"]",
"=",
"$",
"path",
";",
"}",
"$",
"this",
"->",
"setPath",
"(",
"$",
"normalized",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Normalize Array Path Stored On Class
@return $this | [
"Normalize",
"Array",
"Path",
"Stored",
"On",
"Class"
] | 1f765e77b5aca20f6440d3e27a8df60ed888c09e | https://github.com/phPoirot/PathUri/blob/1f765e77b5aca20f6440d3e27a8df60ed888c09e/UriSequence.php#L356-L403 |
9,353 | webriq/core | module/Customize/src/Grid/Customize/Model/Rule/Mapper.php | Mapper.findBySelector | public function findBySelector( $selector, $media = '', $rootId = null )
{
$where = array(
'selector' => (string) $selector,
'media' => (string) $media,
);
if ( empty( $rootId ) )
{
$where[] = new Predicate\IsNull( 'rootParagraphId' );
}
else
{
$where['rootParagraphId'] = (int) $rootId;
}
return $this->findOne( $where );
} | php | public function findBySelector( $selector, $media = '', $rootId = null )
{
$where = array(
'selector' => (string) $selector,
'media' => (string) $media,
);
if ( empty( $rootId ) )
{
$where[] = new Predicate\IsNull( 'rootParagraphId' );
}
else
{
$where['rootParagraphId'] = (int) $rootId;
}
return $this->findOne( $where );
} | [
"public",
"function",
"findBySelector",
"(",
"$",
"selector",
",",
"$",
"media",
"=",
"''",
",",
"$",
"rootId",
"=",
"null",
")",
"{",
"$",
"where",
"=",
"array",
"(",
"'selector'",
"=>",
"(",
"string",
")",
"$",
"selector",
",",
"'media'",
"=>",
"(",
"string",
")",
"$",
"media",
",",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"rootId",
")",
")",
"{",
"$",
"where",
"[",
"]",
"=",
"new",
"Predicate",
"\\",
"IsNull",
"(",
"'rootParagraphId'",
")",
";",
"}",
"else",
"{",
"$",
"where",
"[",
"'rootParagraphId'",
"]",
"=",
"(",
"int",
")",
"$",
"rootId",
";",
"}",
"return",
"$",
"this",
"->",
"findOne",
"(",
"$",
"where",
")",
";",
"}"
] | Find structure by selector & media
@param string $selector
@param string $media [optional]
@param int $rootId [optional]
@return \Customize\Model\Rule\Structure | [
"Find",
"structure",
"by",
"selector",
"&",
"media"
] | cfeb6e8a4732561c2215ec94e736c07f9b8bc990 | https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/Customize/src/Grid/Customize/Model/Rule/Mapper.php#L445-L462 |
9,354 | webriq/core | module/Customize/src/Grid/Customize/Model/Rule/Mapper.php | Mapper.findAllByRoot | public function findAllByRoot( $rootId = null,
$order = null,
$limit = null,
$offset = null )
{
$select = $this->select();
if ( empty( $rootId ) )
{
$where = array(
new Predicate\IsNull( 'rootParagraphId' )
);
}
else
{
$where = array(
'rootParagraphId' => (int) $rootId,
);
}
$select->where( $where )
->order( $order ?: array() )
->limit( $limit )
->offset( $offset );
/* @var $result \Zend\Db\Adapter\Driver\ResultInterface */
$return = array();
$result = $this->sql()
->prepareStatementForSqlObject( $select )
->execute();
foreach ( $result as $row )
{
$return[] = $this->selected( $row );
}
return $return;
} | php | public function findAllByRoot( $rootId = null,
$order = null,
$limit = null,
$offset = null )
{
$select = $this->select();
if ( empty( $rootId ) )
{
$where = array(
new Predicate\IsNull( 'rootParagraphId' )
);
}
else
{
$where = array(
'rootParagraphId' => (int) $rootId,
);
}
$select->where( $where )
->order( $order ?: array() )
->limit( $limit )
->offset( $offset );
/* @var $result \Zend\Db\Adapter\Driver\ResultInterface */
$return = array();
$result = $this->sql()
->prepareStatementForSqlObject( $select )
->execute();
foreach ( $result as $row )
{
$return[] = $this->selected( $row );
}
return $return;
} | [
"public",
"function",
"findAllByRoot",
"(",
"$",
"rootId",
"=",
"null",
",",
"$",
"order",
"=",
"null",
",",
"$",
"limit",
"=",
"null",
",",
"$",
"offset",
"=",
"null",
")",
"{",
"$",
"select",
"=",
"$",
"this",
"->",
"select",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"rootId",
")",
")",
"{",
"$",
"where",
"=",
"array",
"(",
"new",
"Predicate",
"\\",
"IsNull",
"(",
"'rootParagraphId'",
")",
")",
";",
"}",
"else",
"{",
"$",
"where",
"=",
"array",
"(",
"'rootParagraphId'",
"=>",
"(",
"int",
")",
"$",
"rootId",
",",
")",
";",
"}",
"$",
"select",
"->",
"where",
"(",
"$",
"where",
")",
"->",
"order",
"(",
"$",
"order",
"?",
":",
"array",
"(",
")",
")",
"->",
"limit",
"(",
"$",
"limit",
")",
"->",
"offset",
"(",
"$",
"offset",
")",
";",
"/* @var $result \\Zend\\Db\\Adapter\\Driver\\ResultInterface */",
"$",
"return",
"=",
"array",
"(",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"sql",
"(",
")",
"->",
"prepareStatementForSqlObject",
"(",
"$",
"select",
")",
"->",
"execute",
"(",
")",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"row",
")",
"{",
"$",
"return",
"[",
"]",
"=",
"$",
"this",
"->",
"selected",
"(",
"$",
"row",
")",
";",
"}",
"return",
"$",
"return",
";",
"}"
] | Find all structure by rootId
@param null|int $rootId
@param null|array $order
@param null|int $limit
@param null|int $offset
@return \Customize\Model\Rule\Structure[] | [
"Find",
"all",
"structure",
"by",
"rootId"
] | cfeb6e8a4732561c2215ec94e736c07f9b8bc990 | https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/Customize/src/Grid/Customize/Model/Rule/Mapper.php#L473-L511 |
9,355 | webriq/core | module/Customize/src/Grid/Customize/Model/Rule/Mapper.php | Mapper.deleteByRoot | public function deleteByRoot( $rootId = null, array $except = array() )
{
if ( null === $rootId )
{
$where = array( new Predicate\IsNull(
'rootParagraphId'
) );
}
else
{
$where = array(
'rootParagraphId' => (int) $rootId,
);
}
if ( ! empty( $except ) )
{
$where[] = new Predicate\NotIn( 'id', $except );
}
$delete = $this->sql()
->delete()
->where( $where );
$result = $this->sql()
->prepareStatementForSqlObject( $delete )
->execute();
return $result->getAffectedRows();
} | php | public function deleteByRoot( $rootId = null, array $except = array() )
{
if ( null === $rootId )
{
$where = array( new Predicate\IsNull(
'rootParagraphId'
) );
}
else
{
$where = array(
'rootParagraphId' => (int) $rootId,
);
}
if ( ! empty( $except ) )
{
$where[] = new Predicate\NotIn( 'id', $except );
}
$delete = $this->sql()
->delete()
->where( $where );
$result = $this->sql()
->prepareStatementForSqlObject( $delete )
->execute();
return $result->getAffectedRows();
} | [
"public",
"function",
"deleteByRoot",
"(",
"$",
"rootId",
"=",
"null",
",",
"array",
"$",
"except",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"rootId",
")",
"{",
"$",
"where",
"=",
"array",
"(",
"new",
"Predicate",
"\\",
"IsNull",
"(",
"'rootParagraphId'",
")",
")",
";",
"}",
"else",
"{",
"$",
"where",
"=",
"array",
"(",
"'rootParagraphId'",
"=>",
"(",
"int",
")",
"$",
"rootId",
",",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"except",
")",
")",
"{",
"$",
"where",
"[",
"]",
"=",
"new",
"Predicate",
"\\",
"NotIn",
"(",
"'id'",
",",
"$",
"except",
")",
";",
"}",
"$",
"delete",
"=",
"$",
"this",
"->",
"sql",
"(",
")",
"->",
"delete",
"(",
")",
"->",
"where",
"(",
"$",
"where",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"sql",
"(",
")",
"->",
"prepareStatementForSqlObject",
"(",
"$",
"delete",
")",
"->",
"execute",
"(",
")",
";",
"return",
"$",
"result",
"->",
"getAffectedRows",
"(",
")",
";",
"}"
] | Delete rules by root-id
@param int|null $rootId
@param int[] $except
@return int | [
"Delete",
"rules",
"by",
"root",
"-",
"id"
] | cfeb6e8a4732561c2215ec94e736c07f9b8bc990 | https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/Customize/src/Grid/Customize/Model/Rule/Mapper.php#L520-L549 |
9,356 | bseries/base_social | models/Instagram.php | Instagram._resolvePaginated | protected static function _resolvePaginated(array $pagination, array $data) {
$client = new Client();
// `pagination` key is an empty array if there are no more pages.
if (!$pagination) {
Logger::debug("Instagram-API finished resolving pagination.");
return $data;
}
Logger::debug("Instagram-API retrieving next page `{$pagination['next_url']}`.");
$response = $client->request('GET', $pagination['next_url']);
$result = json_decode($response->getBody(), true);
return static::_resolvePaginated(
$result['pagination'], array_merge($data, $result['data'])
);
} | php | protected static function _resolvePaginated(array $pagination, array $data) {
$client = new Client();
// `pagination` key is an empty array if there are no more pages.
if (!$pagination) {
Logger::debug("Instagram-API finished resolving pagination.");
return $data;
}
Logger::debug("Instagram-API retrieving next page `{$pagination['next_url']}`.");
$response = $client->request('GET', $pagination['next_url']);
$result = json_decode($response->getBody(), true);
return static::_resolvePaginated(
$result['pagination'], array_merge($data, $result['data'])
);
} | [
"protected",
"static",
"function",
"_resolvePaginated",
"(",
"array",
"$",
"pagination",
",",
"array",
"$",
"data",
")",
"{",
"$",
"client",
"=",
"new",
"Client",
"(",
")",
";",
"// `pagination` key is an empty array if there are no more pages.",
"if",
"(",
"!",
"$",
"pagination",
")",
"{",
"Logger",
"::",
"debug",
"(",
"\"Instagram-API finished resolving pagination.\"",
")",
";",
"return",
"$",
"data",
";",
"}",
"Logger",
"::",
"debug",
"(",
"\"Instagram-API retrieving next page `{$pagination['next_url']}`.\"",
")",
";",
"$",
"response",
"=",
"$",
"client",
"->",
"request",
"(",
"'GET'",
",",
"$",
"pagination",
"[",
"'next_url'",
"]",
")",
";",
"$",
"result",
"=",
"json_decode",
"(",
"$",
"response",
"->",
"getBody",
"(",
")",
",",
"true",
")",
";",
"return",
"static",
"::",
"_resolvePaginated",
"(",
"$",
"result",
"[",
"'pagination'",
"]",
",",
"array_merge",
"(",
"$",
"data",
",",
"$",
"result",
"[",
"'data'",
"]",
")",
")",
";",
"}"
] | Will never cache first page, but cache all subsequent pages. | [
"Will",
"never",
"cache",
"first",
"page",
"but",
"cache",
"all",
"subsequent",
"pages",
"."
] | a5c4859b0efc9285e7a1fb8a4ff8b59ce01660c0 | https://github.com/bseries/base_social/blob/a5c4859b0efc9285e7a1fb8a4ff8b59ce01660c0/models/Instagram.php#L72-L88 |
9,357 | zhengkai/tango | lib/Drive/DB.php | DB.genAI | public function genAI($sTable) {
$sTable = '`' . addslashes($sTable) . '`';
$sQuery = 'INSERT INTO ' . $sTable . ' () VALUES ()';
$iID = $this->getInsertID($sQuery);
if ($iID && ($iID % 1000 == 0)) {
$sQuery = 'DELETE FROM ' . $sTable;
$this->exec($sQuery);
}
return $iID;
} | php | public function genAI($sTable) {
$sTable = '`' . addslashes($sTable) . '`';
$sQuery = 'INSERT INTO ' . $sTable . ' () VALUES ()';
$iID = $this->getInsertID($sQuery);
if ($iID && ($iID % 1000 == 0)) {
$sQuery = 'DELETE FROM ' . $sTable;
$this->exec($sQuery);
}
return $iID;
} | [
"public",
"function",
"genAI",
"(",
"$",
"sTable",
")",
"{",
"$",
"sTable",
"=",
"'`'",
".",
"addslashes",
"(",
"$",
"sTable",
")",
".",
"'`'",
";",
"$",
"sQuery",
"=",
"'INSERT INTO '",
".",
"$",
"sTable",
".",
"' () VALUES ()'",
";",
"$",
"iID",
"=",
"$",
"this",
"->",
"getInsertID",
"(",
"$",
"sQuery",
")",
";",
"if",
"(",
"$",
"iID",
"&&",
"(",
"$",
"iID",
"%",
"1000",
"==",
"0",
")",
")",
"{",
"$",
"sQuery",
"=",
"'DELETE FROM '",
".",
"$",
"sTable",
";",
"$",
"this",
"->",
"exec",
"(",
"$",
"sQuery",
")",
";",
"}",
"return",
"$",
"iID",
";",
"}"
] | auto increment id generator
@param string $sTable
@access public
@return integer
CREATE TABLE IF NOT EXISTS `id_gen` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=binary AUTO_INCREMENT=1; | [
"auto",
"increment",
"id",
"generator"
] | 2d42c42acd9042f9a3cd902eb4427710fa46c35b | https://github.com/zhengkai/tango/blob/2d42c42acd9042f9a3cd902eb4427710fa46c35b/lib/Drive/DB.php#L428-L437 |
9,358 | ob-ivan/sd-dependency-injection | src/Container.php | Container.getRecursive | private function getRecursive(string $name) {
if ($name === self::SELF_NAME) {
return $this;
}
if (!isset($this->services[$name])) {
if (in_array($name, $this->usedNames)) {
throw new Exception("Cyclic dependency found while resolving $name");
}
$this->usedNames[] = $name;
if (!isset($this->initializers[$name])) {
throw new Exception("No initializer for $name");
}
$this->services[$name] = $this->produceRecursive($this->initializers[$name]);
}
return $this->services[$name];
} | php | private function getRecursive(string $name) {
if ($name === self::SELF_NAME) {
return $this;
}
if (!isset($this->services[$name])) {
if (in_array($name, $this->usedNames)) {
throw new Exception("Cyclic dependency found while resolving $name");
}
$this->usedNames[] = $name;
if (!isset($this->initializers[$name])) {
throw new Exception("No initializer for $name");
}
$this->services[$name] = $this->produceRecursive($this->initializers[$name]);
}
return $this->services[$name];
} | [
"private",
"function",
"getRecursive",
"(",
"string",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"name",
"===",
"self",
"::",
"SELF_NAME",
")",
"{",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"services",
"[",
"$",
"name",
"]",
")",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"usedNames",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Cyclic dependency found while resolving $name\"",
")",
";",
"}",
"$",
"this",
"->",
"usedNames",
"[",
"]",
"=",
"$",
"name",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"initializers",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"No initializer for $name\"",
")",
";",
"}",
"$",
"this",
"->",
"services",
"[",
"$",
"name",
"]",
"=",
"$",
"this",
"->",
"produceRecursive",
"(",
"$",
"this",
"->",
"initializers",
"[",
"$",
"name",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"services",
"[",
"$",
"name",
"]",
";",
"}"
] | Return an initialized service.
@param $name string
@return mixed | [
"Return",
"an",
"initialized",
"service",
"."
] | 279e652ec583a0a11dda359c6f11586b3297a4bd | https://github.com/ob-ivan/sd-dependency-injection/blob/279e652ec583a0a11dda359c6f11586b3297a4bd/src/Container.php#L148-L163 |
9,359 | rinvex/obsolete-attributable | src/Traits/Attributable.php | Attributable.bootAttributable | public static function bootAttributable()
{
$models = array_merge([static::class], array_values(class_parents(static::class)));
$attributes = DB::table(config('rinvex.attributable.tables.attribute_entity'))->whereIn('entity_type', $models)->get()->pluck('attribute_id');
static::$entityAttributes = Attribute::whereIn('id', $attributes)->get()->keyBy('slug');
static::addGlobalScope(new EagerLoadScope());
static::saved(EntityWasSaved::class.'@handle');
static::deleted(EntityWasDeleted::class.'@handle');
} | php | public static function bootAttributable()
{
$models = array_merge([static::class], array_values(class_parents(static::class)));
$attributes = DB::table(config('rinvex.attributable.tables.attribute_entity'))->whereIn('entity_type', $models)->get()->pluck('attribute_id');
static::$entityAttributes = Attribute::whereIn('id', $attributes)->get()->keyBy('slug');
static::addGlobalScope(new EagerLoadScope());
static::saved(EntityWasSaved::class.'@handle');
static::deleted(EntityWasDeleted::class.'@handle');
} | [
"public",
"static",
"function",
"bootAttributable",
"(",
")",
"{",
"$",
"models",
"=",
"array_merge",
"(",
"[",
"static",
"::",
"class",
"]",
",",
"array_values",
"(",
"class_parents",
"(",
"static",
"::",
"class",
")",
")",
")",
";",
"$",
"attributes",
"=",
"DB",
"::",
"table",
"(",
"config",
"(",
"'rinvex.attributable.tables.attribute_entity'",
")",
")",
"->",
"whereIn",
"(",
"'entity_type'",
",",
"$",
"models",
")",
"->",
"get",
"(",
")",
"->",
"pluck",
"(",
"'attribute_id'",
")",
";",
"static",
"::",
"$",
"entityAttributes",
"=",
"Attribute",
"::",
"whereIn",
"(",
"'id'",
",",
"$",
"attributes",
")",
"->",
"get",
"(",
")",
"->",
"keyBy",
"(",
"'slug'",
")",
";",
"static",
"::",
"addGlobalScope",
"(",
"new",
"EagerLoadScope",
"(",
")",
")",
";",
"static",
"::",
"saved",
"(",
"EntityWasSaved",
"::",
"class",
".",
"'@handle'",
")",
";",
"static",
"::",
"deleted",
"(",
"EntityWasDeleted",
"::",
"class",
".",
"'@handle'",
")",
";",
"}"
] | Boot the attributable trait for a model.
@return void | [
"Boot",
"the",
"attributable",
"trait",
"for",
"a",
"model",
"."
] | 23fa78efda9c24e2e1579917967537a3b3b9e4ce | https://github.com/rinvex/obsolete-attributable/blob/23fa78efda9c24e2e1579917967537a3b3b9e4ce/src/Traits/Attributable.php#L57-L67 |
9,360 | rinvex/obsolete-attributable | src/Traits/Attributable.php | Attributable.setEntityAttribute | public function setEntityAttribute(string $key, $value)
{
$current = $this->getEntityAttributeRelation($key);
$attribute = $this->getEntityAttributes()->get($key);
// $current will always contain a collection when an attribute is multivalued
// as morphMany provides collections even if no values were matched, making
// us assume at least an empty collection object will be always provided.
if ($attribute->is_collection) {
if (is_null($current)) {
$this->setRelation($key, $current = new ValueCollection());
}
$current->replace($value);
return $this;
}
// If the attribute to set is a collection, it will be replaced by the
// new value. If the value model does not exist, we will just create
// and set a new value model, otherwise its value will get updated.
if (is_null($current)) {
return $this->setEntityAttributeValue($attribute, $value);
}
if ($value instanceof Value) {
$value = $value->getAttribute('content');
}
$current->setAttribute('entity_type', get_class($this));
return $current->setAttribute('content', $value);
} | php | public function setEntityAttribute(string $key, $value)
{
$current = $this->getEntityAttributeRelation($key);
$attribute = $this->getEntityAttributes()->get($key);
// $current will always contain a collection when an attribute is multivalued
// as morphMany provides collections even if no values were matched, making
// us assume at least an empty collection object will be always provided.
if ($attribute->is_collection) {
if (is_null($current)) {
$this->setRelation($key, $current = new ValueCollection());
}
$current->replace($value);
return $this;
}
// If the attribute to set is a collection, it will be replaced by the
// new value. If the value model does not exist, we will just create
// and set a new value model, otherwise its value will get updated.
if (is_null($current)) {
return $this->setEntityAttributeValue($attribute, $value);
}
if ($value instanceof Value) {
$value = $value->getAttribute('content');
}
$current->setAttribute('entity_type', get_class($this));
return $current->setAttribute('content', $value);
} | [
"public",
"function",
"setEntityAttribute",
"(",
"string",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"current",
"=",
"$",
"this",
"->",
"getEntityAttributeRelation",
"(",
"$",
"key",
")",
";",
"$",
"attribute",
"=",
"$",
"this",
"->",
"getEntityAttributes",
"(",
")",
"->",
"get",
"(",
"$",
"key",
")",
";",
"// $current will always contain a collection when an attribute is multivalued",
"// as morphMany provides collections even if no values were matched, making",
"// us assume at least an empty collection object will be always provided.",
"if",
"(",
"$",
"attribute",
"->",
"is_collection",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"current",
")",
")",
"{",
"$",
"this",
"->",
"setRelation",
"(",
"$",
"key",
",",
"$",
"current",
"=",
"new",
"ValueCollection",
"(",
")",
")",
";",
"}",
"$",
"current",
"->",
"replace",
"(",
"$",
"value",
")",
";",
"return",
"$",
"this",
";",
"}",
"// If the attribute to set is a collection, it will be replaced by the",
"// new value. If the value model does not exist, we will just create",
"// and set a new value model, otherwise its value will get updated.",
"if",
"(",
"is_null",
"(",
"$",
"current",
")",
")",
"{",
"return",
"$",
"this",
"->",
"setEntityAttributeValue",
"(",
"$",
"attribute",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"$",
"value",
"instanceof",
"Value",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"->",
"getAttribute",
"(",
"'content'",
")",
";",
"}",
"$",
"current",
"->",
"setAttribute",
"(",
"'entity_type'",
",",
"get_class",
"(",
"$",
"this",
")",
")",
";",
"return",
"$",
"current",
"->",
"setAttribute",
"(",
"'content'",
",",
"$",
"value",
")",
";",
"}"
] | Set the entity attribute.
@param string $key
@param mixed $value
@return mixed | [
"Set",
"the",
"entity",
"attribute",
"."
] | 23fa78efda9c24e2e1579917967537a3b3b9e4ce | https://github.com/rinvex/obsolete-attributable/blob/23fa78efda9c24e2e1579917967537a3b3b9e4ce/src/Traits/Attributable.php#L324-L356 |
9,361 | thecodingmachine/html.utils.weblibrarymanager | src/WebLibraryManager.php | WebLibraryManager.toHtml | public function toHtml()
{
/*if ($this->rendered) {
throw new WebLibraryException("The library has already been rendered.");
}*/
echo $this->getCssHtml();
echo $this->getJsHtml();
echo $this->getAdditionalHtml();
$this->rendered = true;
} | php | public function toHtml()
{
/*if ($this->rendered) {
throw new WebLibraryException("The library has already been rendered.");
}*/
echo $this->getCssHtml();
echo $this->getJsHtml();
echo $this->getAdditionalHtml();
$this->rendered = true;
} | [
"public",
"function",
"toHtml",
"(",
")",
"{",
"/*if ($this->rendered) {\n throw new WebLibraryException(\"The library has already been rendered.\");\n }*/",
"echo",
"$",
"this",
"->",
"getCssHtml",
"(",
")",
";",
"echo",
"$",
"this",
"->",
"getJsHtml",
"(",
")",
";",
"echo",
"$",
"this",
"->",
"getAdditionalHtml",
"(",
")",
";",
"$",
"this",
"->",
"rendered",
"=",
"true",
";",
"}"
] | Renders the HTML in charge of loading CSS and JS files.
The Html is echoed directly into the output.
This function should be called within the head tag. | [
"Renders",
"the",
"HTML",
"in",
"charge",
"of",
"loading",
"CSS",
"and",
"JS",
"files",
".",
"The",
"Html",
"is",
"echoed",
"directly",
"into",
"the",
"output",
".",
"This",
"function",
"should",
"be",
"called",
"within",
"the",
"head",
"tag",
"."
] | e1e5e06d7221a4e77196798ca8bdc3908025eb51 | https://github.com/thecodingmachine/html.utils.weblibrarymanager/blob/e1e5e06d7221a4e77196798ca8bdc3908025eb51/src/WebLibraryManager.php#L99-L110 |
9,362 | thecodingmachine/html.utils.weblibrarymanager | src/WebLibraryManager.php | WebLibraryManager.addAdditionalScript | public function addAdditionalScript($additionalScript): void
{
if (!$additionalScript instanceof HtmlElementInterface) {
$additionalScript = new HtmlString($additionalScript);
}
$this->webLibraries[] = new InlineWebLibrary(null, null, $additionalScript);
} | php | public function addAdditionalScript($additionalScript): void
{
if (!$additionalScript instanceof HtmlElementInterface) {
$additionalScript = new HtmlString($additionalScript);
}
$this->webLibraries[] = new InlineWebLibrary(null, null, $additionalScript);
} | [
"public",
"function",
"addAdditionalScript",
"(",
"$",
"additionalScript",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"additionalScript",
"instanceof",
"HtmlElementInterface",
")",
"{",
"$",
"additionalScript",
"=",
"new",
"HtmlString",
"(",
"$",
"additionalScript",
")",
";",
"}",
"$",
"this",
"->",
"webLibraries",
"[",
"]",
"=",
"new",
"InlineWebLibrary",
"(",
"null",
",",
"null",
",",
"$",
"additionalScript",
")",
";",
"}"
] | Adds an additional script at the end of the <head> tag.
The provided script can either be a string or an object implementing HtmlElementInterface.
@param string|HtmlElementInterface $additionalScript | [
"Adds",
"an",
"additional",
"script",
"at",
"the",
"end",
"of",
"the",
"<",
";",
"head>",
";",
"tag",
".",
"The",
"provided",
"script",
"can",
"either",
"be",
"a",
"string",
"or",
"an",
"object",
"implementing",
"HtmlElementInterface",
"."
] | e1e5e06d7221a4e77196798ca8bdc3908025eb51 | https://github.com/thecodingmachine/html.utils.weblibrarymanager/blob/e1e5e06d7221a4e77196798ca8bdc3908025eb51/src/WebLibraryManager.php#L142-L148 |
9,363 | PowerOnSystem/HelperService | src/BlockHelper.php | BlockHelper.humaniceTrace | public function humaniceTrace(array $trace) {
/* @var $html_helper HtmlHelper */
$html_helper = $this->html;
$list = [];
foreach ($trace as $id_trace => $e) {
$class = explode('\\', key_exists('class', $e) ? $e['class'] : '');
$type = key_exists('type', $e) ? $e['type'] : '';
$function = key_exists('function', $e) ? $e['function'] : '';
$args = key_exists('args', $e) ? $e['args'] : [];
$file = key_exists('file', $e) ? $e['file'] : [];
$line = key_exists('line', $e) ? $e['line'] : [];
$item = $class ? '<span style="color:blue" title="' . implode('\\', $class) . '">' . end($class) . '</span>' : '';
$item .= $type ? '<span style="color:teal">' . $type . '</span>' : '';
$item .= $function ? '<span style="color:red">' . $function . '</span>' : '';
$item .= $args ?
'(' .
$html_helper->link(count($args) . ' arg', [],
['onclick' => 'var a=document.getElementById(\'args_' . $id_trace . '\');'
. ' if (a.style.display==\'block\') { a.style.display=\'none\' } else { a.style.display=\'block\' };'
. 'return false;']) .
')' : '()';
$item .= $file ? ' - <span style="color:lightgray" onmouseover="this.style.color=\'gray\'" '
. 'onmouseout="this.style.color=\'lightgray\'" >' . $file . '</span>' : '';
$item .= $line ? ' <span style="color:salmon">' . $line . '</span>' : '';
$item .= $args ? '<div style="display:none" id="args_' . $id_trace . '">' . @d($args) . '</div>' : '';
$list[] = $item;
}
return $html_helper->nestedList($list, [
'style' => 'font-family: arial; line-height:30px;',
'reversed' => 'reversed'
], [], 'ordered');
} | php | public function humaniceTrace(array $trace) {
/* @var $html_helper HtmlHelper */
$html_helper = $this->html;
$list = [];
foreach ($trace as $id_trace => $e) {
$class = explode('\\', key_exists('class', $e) ? $e['class'] : '');
$type = key_exists('type', $e) ? $e['type'] : '';
$function = key_exists('function', $e) ? $e['function'] : '';
$args = key_exists('args', $e) ? $e['args'] : [];
$file = key_exists('file', $e) ? $e['file'] : [];
$line = key_exists('line', $e) ? $e['line'] : [];
$item = $class ? '<span style="color:blue" title="' . implode('\\', $class) . '">' . end($class) . '</span>' : '';
$item .= $type ? '<span style="color:teal">' . $type . '</span>' : '';
$item .= $function ? '<span style="color:red">' . $function . '</span>' : '';
$item .= $args ?
'(' .
$html_helper->link(count($args) . ' arg', [],
['onclick' => 'var a=document.getElementById(\'args_' . $id_trace . '\');'
. ' if (a.style.display==\'block\') { a.style.display=\'none\' } else { a.style.display=\'block\' };'
. 'return false;']) .
')' : '()';
$item .= $file ? ' - <span style="color:lightgray" onmouseover="this.style.color=\'gray\'" '
. 'onmouseout="this.style.color=\'lightgray\'" >' . $file . '</span>' : '';
$item .= $line ? ' <span style="color:salmon">' . $line . '</span>' : '';
$item .= $args ? '<div style="display:none" id="args_' . $id_trace . '">' . @d($args) . '</div>' : '';
$list[] = $item;
}
return $html_helper->nestedList($list, [
'style' => 'font-family: arial; line-height:30px;',
'reversed' => 'reversed'
], [], 'ordered');
} | [
"public",
"function",
"humaniceTrace",
"(",
"array",
"$",
"trace",
")",
"{",
"/* @var $html_helper HtmlHelper */",
"$",
"html_helper",
"=",
"$",
"this",
"->",
"html",
";",
"$",
"list",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"trace",
"as",
"$",
"id_trace",
"=>",
"$",
"e",
")",
"{",
"$",
"class",
"=",
"explode",
"(",
"'\\\\'",
",",
"key_exists",
"(",
"'class'",
",",
"$",
"e",
")",
"?",
"$",
"e",
"[",
"'class'",
"]",
":",
"''",
")",
";",
"$",
"type",
"=",
"key_exists",
"(",
"'type'",
",",
"$",
"e",
")",
"?",
"$",
"e",
"[",
"'type'",
"]",
":",
"''",
";",
"$",
"function",
"=",
"key_exists",
"(",
"'function'",
",",
"$",
"e",
")",
"?",
"$",
"e",
"[",
"'function'",
"]",
":",
"''",
";",
"$",
"args",
"=",
"key_exists",
"(",
"'args'",
",",
"$",
"e",
")",
"?",
"$",
"e",
"[",
"'args'",
"]",
":",
"[",
"]",
";",
"$",
"file",
"=",
"key_exists",
"(",
"'file'",
",",
"$",
"e",
")",
"?",
"$",
"e",
"[",
"'file'",
"]",
":",
"[",
"]",
";",
"$",
"line",
"=",
"key_exists",
"(",
"'line'",
",",
"$",
"e",
")",
"?",
"$",
"e",
"[",
"'line'",
"]",
":",
"[",
"]",
";",
"$",
"item",
"=",
"$",
"class",
"?",
"'<span style=\"color:blue\" title=\"'",
".",
"implode",
"(",
"'\\\\'",
",",
"$",
"class",
")",
".",
"'\">'",
".",
"end",
"(",
"$",
"class",
")",
".",
"'</span>'",
":",
"''",
";",
"$",
"item",
".=",
"$",
"type",
"?",
"'<span style=\"color:teal\">'",
".",
"$",
"type",
".",
"'</span>'",
":",
"''",
";",
"$",
"item",
".=",
"$",
"function",
"?",
"'<span style=\"color:red\">'",
".",
"$",
"function",
".",
"'</span>'",
":",
"''",
";",
"$",
"item",
".=",
"$",
"args",
"?",
"'('",
".",
"$",
"html_helper",
"->",
"link",
"(",
"count",
"(",
"$",
"args",
")",
".",
"' arg'",
",",
"[",
"]",
",",
"[",
"'onclick'",
"=>",
"'var a=document.getElementById(\\'args_'",
".",
"$",
"id_trace",
".",
"'\\');'",
".",
"' if (a.style.display==\\'block\\') { a.style.display=\\'none\\' } else { a.style.display=\\'block\\' };'",
".",
"'return false;'",
"]",
")",
".",
"')'",
":",
"'()'",
";",
"$",
"item",
".=",
"$",
"file",
"?",
"' - <span style=\"color:lightgray\" onmouseover=\"this.style.color=\\'gray\\'\" '",
".",
"'onmouseout=\"this.style.color=\\'lightgray\\'\" >'",
".",
"$",
"file",
".",
"'</span>'",
":",
"''",
";",
"$",
"item",
".=",
"$",
"line",
"?",
"' <span style=\"color:salmon\">'",
".",
"$",
"line",
".",
"'</span>'",
":",
"''",
";",
"$",
"item",
".=",
"$",
"args",
"?",
"'<div style=\"display:none\" id=\"args_'",
".",
"$",
"id_trace",
".",
"'\">'",
".",
"@",
"d",
"(",
"$",
"args",
")",
".",
"'</div>'",
":",
"''",
";",
"$",
"list",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"return",
"$",
"html_helper",
"->",
"nestedList",
"(",
"$",
"list",
",",
"[",
"'style'",
"=>",
"'font-family: arial; line-height:30px;'",
",",
"'reversed'",
"=>",
"'reversed'",
"]",
",",
"[",
"]",
",",
"'ordered'",
")",
";",
"}"
] | Obtiene el trace de legible de una excepcion
@param array $trace
@return string | [
"Obtiene",
"el",
"trace",
"de",
"legible",
"de",
"una",
"excepcion"
] | 6d300764d7b3a090dd674b25415ce5088156ce8b | https://github.com/PowerOnSystem/HelperService/blob/6d300764d7b3a090dd674b25415ce5088156ce8b/src/BlockHelper.php#L35-L69 |
9,364 | znframework/package-crontab | Job.php | Job.listArray | public function listArray() : Array
{
if( ! is_file($this->crontabCommands) )
{
return [];
}
return Arrays\RemoveElement::element(explode(EOL, file_get_contents($this->crontabCommands)), '');
} | php | public function listArray() : Array
{
if( ! is_file($this->crontabCommands) )
{
return [];
}
return Arrays\RemoveElement::element(explode(EOL, file_get_contents($this->crontabCommands)), '');
} | [
"public",
"function",
"listArray",
"(",
")",
":",
"Array",
"{",
"if",
"(",
"!",
"is_file",
"(",
"$",
"this",
"->",
"crontabCommands",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"Arrays",
"\\",
"RemoveElement",
"::",
"element",
"(",
"explode",
"(",
"EOL",
",",
"file_get_contents",
"(",
"$",
"this",
"->",
"crontabCommands",
")",
")",
",",
"''",
")",
";",
"}"
] | Gets crontab list array
@return array | [
"Gets",
"crontab",
"list",
"array"
] | 7e75efdaa714728bfe8800a1d0fd962c42f46c25 | https://github.com/znframework/package-crontab/blob/7e75efdaa714728bfe8800a1d0fd962c42f46c25/Job.php#L195-L203 |
9,365 | znframework/package-crontab | Job.php | Job.list | public function list() : String
{
$list = '';
if( is_file($this->crontabCommands) )
{
$jobs = $this->listArray();
$list = '<pre>';
$list .= '[ID] CRON JOB<br><br>';
foreach( $jobs as $key => $job )
{
$list .= '[' . $key . ']: '. $job . '<br>';
}
$list .= '</pre>';
}
return $list;
} | php | public function list() : String
{
$list = '';
if( is_file($this->crontabCommands) )
{
$jobs = $this->listArray();
$list = '<pre>';
$list .= '[ID] CRON JOB<br><br>';
foreach( $jobs as $key => $job )
{
$list .= '[' . $key . ']: '. $job . '<br>';
}
$list .= '</pre>';
}
return $list;
} | [
"public",
"function",
"list",
"(",
")",
":",
"String",
"{",
"$",
"list",
"=",
"''",
";",
"if",
"(",
"is_file",
"(",
"$",
"this",
"->",
"crontabCommands",
")",
")",
"{",
"$",
"jobs",
"=",
"$",
"this",
"->",
"listArray",
"(",
")",
";",
"$",
"list",
"=",
"'<pre>'",
";",
"$",
"list",
".=",
"'[ID] CRON JOB<br><br>'",
";",
"foreach",
"(",
"$",
"jobs",
"as",
"$",
"key",
"=>",
"$",
"job",
")",
"{",
"$",
"list",
".=",
"'['",
".",
"$",
"key",
".",
"']: '",
".",
"$",
"job",
".",
"'<br>'",
";",
"}",
"$",
"list",
".=",
"'</pre>'",
";",
"}",
"return",
"$",
"list",
";",
"}"
] | Gets crontab list
@return string | [
"Gets",
"crontab",
"list"
] | 7e75efdaa714728bfe8800a1d0fd962c42f46c25 | https://github.com/znframework/package-crontab/blob/7e75efdaa714728bfe8800a1d0fd962c42f46c25/Job.php#L210-L229 |
9,366 | znframework/package-crontab | Job.php | Job.remove | public function remove($key = NULL)
{
$this->executeRemoveCommand();
if( $key === NULL )
{
unlink($this->crontabCommands);
}
else
{
$this->removeJobFromExecFile($key);
$this->executeCommand();
}
} | php | public function remove($key = NULL)
{
$this->executeRemoveCommand();
if( $key === NULL )
{
unlink($this->crontabCommands);
}
else
{
$this->removeJobFromExecFile($key);
$this->executeCommand();
}
} | [
"public",
"function",
"remove",
"(",
"$",
"key",
"=",
"NULL",
")",
"{",
"$",
"this",
"->",
"executeRemoveCommand",
"(",
")",
";",
"if",
"(",
"$",
"key",
"===",
"NULL",
")",
"{",
"unlink",
"(",
"$",
"this",
"->",
"crontabCommands",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"removeJobFromExecFile",
"(",
"$",
"key",
")",
";",
"$",
"this",
"->",
"executeCommand",
"(",
")",
";",
"}",
"}"
] | Remove cron job
@param string $key = NULL | [
"Remove",
"cron",
"job"
] | 7e75efdaa714728bfe8800a1d0fd962c42f46c25 | https://github.com/znframework/package-crontab/blob/7e75efdaa714728bfe8800a1d0fd962c42f46c25/Job.php#L246-L260 |
9,367 | znframework/package-crontab | Job.php | Job.createCrontabDirectoryIfNotExists | protected function createCrontabDirectoryIfNotExists()
{
if( ! is_dir($crontabDirectory = pathinfo($this->crontabCommands, PATHINFO_DIRNAME)) )
{
Filesystem::createFolder($crontabDirectory);
}
} | php | protected function createCrontabDirectoryIfNotExists()
{
if( ! is_dir($crontabDirectory = pathinfo($this->crontabCommands, PATHINFO_DIRNAME)) )
{
Filesystem::createFolder($crontabDirectory);
}
} | [
"protected",
"function",
"createCrontabDirectoryIfNotExists",
"(",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"crontabDirectory",
"=",
"pathinfo",
"(",
"$",
"this",
"->",
"crontabCommands",
",",
"PATHINFO_DIRNAME",
")",
")",
")",
"{",
"Filesystem",
"::",
"createFolder",
"(",
"$",
"crontabDirectory",
")",
";",
"}",
"}"
] | Protected create crontab directory if not exists | [
"Protected",
"create",
"crontab",
"directory",
"if",
"not",
"exists"
] | 7e75efdaa714728bfe8800a1d0fd962c42f46c25 | https://github.com/znframework/package-crontab/blob/7e75efdaa714728bfe8800a1d0fd962c42f46c25/Job.php#L351-L357 |
9,368 | znframework/package-crontab | Job.php | Job.createExecFileIfNotExists | protected function createExecFileIfNotExists()
{
if( ! is_file($this->crontabCommands) )
{
Filesystem\Forge::create($this->crontabCommands);
$this->processor->exec('chmod 0777 ' . $this->crontabCommands);
}
} | php | protected function createExecFileIfNotExists()
{
if( ! is_file($this->crontabCommands) )
{
Filesystem\Forge::create($this->crontabCommands);
$this->processor->exec('chmod 0777 ' . $this->crontabCommands);
}
} | [
"protected",
"function",
"createExecFileIfNotExists",
"(",
")",
"{",
"if",
"(",
"!",
"is_file",
"(",
"$",
"this",
"->",
"crontabCommands",
")",
")",
"{",
"Filesystem",
"\\",
"Forge",
"::",
"create",
"(",
"$",
"this",
"->",
"crontabCommands",
")",
";",
"$",
"this",
"->",
"processor",
"->",
"exec",
"(",
"'chmod 0777 '",
".",
"$",
"this",
"->",
"crontabCommands",
")",
";",
"}",
"}"
] | Protected create exec file if not exists | [
"Protected",
"create",
"exec",
"file",
"if",
"not",
"exists"
] | 7e75efdaa714728bfe8800a1d0fd962c42f46c25 | https://github.com/znframework/package-crontab/blob/7e75efdaa714728bfe8800a1d0fd962c42f46c25/Job.php#L378-L386 |
9,369 | znframework/package-crontab | Job.php | Job.addJobToExecFile | protected function addJobToExecFile($cmd)
{
$content = file_get_contents($this->crontabCommands);
if( ! stristr($content, $cmd))
{
$content = $content . $this->getValidCommand() . $cmd . EOL;
file_put_contents($this->crontabCommands, $content);
}
} | php | protected function addJobToExecFile($cmd)
{
$content = file_get_contents($this->crontabCommands);
if( ! stristr($content, $cmd))
{
$content = $content . $this->getValidCommand() . $cmd . EOL;
file_put_contents($this->crontabCommands, $content);
}
} | [
"protected",
"function",
"addJobToExecFile",
"(",
"$",
"cmd",
")",
"{",
"$",
"content",
"=",
"file_get_contents",
"(",
"$",
"this",
"->",
"crontabCommands",
")",
";",
"if",
"(",
"!",
"stristr",
"(",
"$",
"content",
",",
"$",
"cmd",
")",
")",
"{",
"$",
"content",
"=",
"$",
"content",
".",
"$",
"this",
"->",
"getValidCommand",
"(",
")",
".",
"$",
"cmd",
".",
"EOL",
";",
"file_put_contents",
"(",
"$",
"this",
"->",
"crontabCommands",
",",
"$",
"content",
")",
";",
"}",
"}"
] | Protected add job to exec file | [
"Protected",
"add",
"job",
"to",
"exec",
"file"
] | 7e75efdaa714728bfe8800a1d0fd962c42f46c25 | https://github.com/znframework/package-crontab/blob/7e75efdaa714728bfe8800a1d0fd962c42f46c25/Job.php#L391-L401 |
9,370 | znframework/package-crontab | Job.php | Job.removeJobFromExecFile | protected function removeJobFromExecFile($cmd)
{
$jobs = $this->listArray();
unset($jobs[$cmd]);
file_put_contents($this->crontabCommands, implode(EOL, $jobs) . EOL);
} | php | protected function removeJobFromExecFile($cmd)
{
$jobs = $this->listArray();
unset($jobs[$cmd]);
file_put_contents($this->crontabCommands, implode(EOL, $jobs) . EOL);
} | [
"protected",
"function",
"removeJobFromExecFile",
"(",
"$",
"cmd",
")",
"{",
"$",
"jobs",
"=",
"$",
"this",
"->",
"listArray",
"(",
")",
";",
"unset",
"(",
"$",
"jobs",
"[",
"$",
"cmd",
"]",
")",
";",
"file_put_contents",
"(",
"$",
"this",
"->",
"crontabCommands",
",",
"implode",
"(",
"EOL",
",",
"$",
"jobs",
")",
".",
"EOL",
")",
";",
"}"
] | Protected remove job from exec file | [
"Protected",
"remove",
"job",
"from",
"exec",
"file"
] | 7e75efdaa714728bfe8800a1d0fd962c42f46c25 | https://github.com/znframework/package-crontab/blob/7e75efdaa714728bfe8800a1d0fd962c42f46c25/Job.php#L406-L413 |
9,371 | znframework/package-crontab | Job.php | Job.getDatetimeFormat | protected function getDatetimeFormat()
{
if( $this->interval !== '* * * * *' )
{
$interval = $this->interval.' ';
}
else
{
$interval = ( $this->minute ?? '*' ) . ' '.
( $this->hour ?? '*' ) . ' '.
( $this->dayNumber ?? '*' ) . ' '.
( $this->month ?? '*' ) . ' '.
( $this->day ?? '*' ) . ' ';
}
$this->defaultIntervalVariables();
return $interval;
} | php | protected function getDatetimeFormat()
{
if( $this->interval !== '* * * * *' )
{
$interval = $this->interval.' ';
}
else
{
$interval = ( $this->minute ?? '*' ) . ' '.
( $this->hour ?? '*' ) . ' '.
( $this->dayNumber ?? '*' ) . ' '.
( $this->month ?? '*' ) . ' '.
( $this->day ?? '*' ) . ' ';
}
$this->defaultIntervalVariables();
return $interval;
} | [
"protected",
"function",
"getDatetimeFormat",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"interval",
"!==",
"'* * * * *'",
")",
"{",
"$",
"interval",
"=",
"$",
"this",
"->",
"interval",
".",
"' '",
";",
"}",
"else",
"{",
"$",
"interval",
"=",
"(",
"$",
"this",
"->",
"minute",
"??",
"'*'",
")",
".",
"' '",
".",
"(",
"$",
"this",
"->",
"hour",
"??",
"'*'",
")",
".",
"' '",
".",
"(",
"$",
"this",
"->",
"dayNumber",
"??",
"'*'",
")",
".",
"' '",
".",
"(",
"$",
"this",
"->",
"month",
"??",
"'*'",
")",
".",
"' '",
".",
"(",
"$",
"this",
"->",
"day",
"??",
"'*'",
")",
".",
"' '",
";",
"}",
"$",
"this",
"->",
"defaultIntervalVariables",
"(",
")",
";",
"return",
"$",
"interval",
";",
"}"
] | Protected datet time format | [
"Protected",
"datet",
"time",
"format"
] | 7e75efdaa714728bfe8800a1d0fd962c42f46c25 | https://github.com/znframework/package-crontab/blob/7e75efdaa714728bfe8800a1d0fd962c42f46c25/Job.php#L442-L460 |
9,372 | znframework/package-crontab | Job.php | Job.defaultCommandVariables | protected function defaultCommandVariables()
{
$this->type = NULL;
$this->path = NULL;
$this->command = NULL;
$this->debug = false;
} | php | protected function defaultCommandVariables()
{
$this->type = NULL;
$this->path = NULL;
$this->command = NULL;
$this->debug = false;
} | [
"protected",
"function",
"defaultCommandVariables",
"(",
")",
"{",
"$",
"this",
"->",
"type",
"=",
"NULL",
";",
"$",
"this",
"->",
"path",
"=",
"NULL",
";",
"$",
"this",
"->",
"command",
"=",
"NULL",
";",
"$",
"this",
"->",
"debug",
"=",
"false",
";",
"}"
] | Protected defaul command variables | [
"Protected",
"defaul",
"command",
"variables"
] | 7e75efdaa714728bfe8800a1d0fd962c42f46c25 | https://github.com/znframework/package-crontab/blob/7e75efdaa714728bfe8800a1d0fd962c42f46c25/Job.php#L492-L498 |
9,373 | znframework/package-crontab | Job.php | Job.defaultIntervalVariables | protected function defaultIntervalVariables()
{
$this->interval = '* * * * *';
$this->minute = '*';
$this->hour = '*';
$this->dayNumber = '*';
$this->month = '*';
$this->day = '*';
} | php | protected function defaultIntervalVariables()
{
$this->interval = '* * * * *';
$this->minute = '*';
$this->hour = '*';
$this->dayNumber = '*';
$this->month = '*';
$this->day = '*';
} | [
"protected",
"function",
"defaultIntervalVariables",
"(",
")",
"{",
"$",
"this",
"->",
"interval",
"=",
"'* * * * *'",
";",
"$",
"this",
"->",
"minute",
"=",
"'*'",
";",
"$",
"this",
"->",
"hour",
"=",
"'*'",
";",
"$",
"this",
"->",
"dayNumber",
"=",
"'*'",
";",
"$",
"this",
"->",
"month",
"=",
"'*'",
";",
"$",
"this",
"->",
"day",
"=",
"'*'",
";",
"}"
] | Protected default interval variables | [
"Protected",
"default",
"interval",
"variables"
] | 7e75efdaa714728bfe8800a1d0fd962c42f46c25 | https://github.com/znframework/package-crontab/blob/7e75efdaa714728bfe8800a1d0fd962c42f46c25/Job.php#L503-L511 |
9,374 | AnonymPHP/Anonym-Library | src/Anonym/Cron/Task/ConsoleTask.php | ConsoleTask.setCommand | public function setCommand($command, $base = null)
{
$base = ($base === null) ? BASE : $base;
parent::setCommand($this->resolveBase($base).'anonym '.$command);
return $this;
} | php | public function setCommand($command, $base = null)
{
$base = ($base === null) ? BASE : $base;
parent::setCommand($this->resolveBase($base).'anonym '.$command);
return $this;
} | [
"public",
"function",
"setCommand",
"(",
"$",
"command",
",",
"$",
"base",
"=",
"null",
")",
"{",
"$",
"base",
"=",
"(",
"$",
"base",
"===",
"null",
")",
"?",
"BASE",
":",
"$",
"base",
";",
"parent",
"::",
"setCommand",
"(",
"$",
"this",
"->",
"resolveBase",
"(",
"$",
"base",
")",
".",
"'anonym '",
".",
"$",
"command",
")",
";",
"return",
"$",
"this",
";",
"}"
] | register the command
@param string $command
@param string $base
@return $this | [
"register",
"the",
"command"
] | c967ad804f84e8fb204593a0959cda2fed5ae075 | https://github.com/AnonymPHP/Anonym-Library/blob/c967ad804f84e8fb204593a0959cda2fed5ae075/src/Anonym/Cron/Task/ConsoleTask.php#L27-L34 |
9,375 | NuclearCMS/Synthesizer | src/Processors/DocumentsProcessor.php | DocumentsProcessor.process | public function process($text, $args = null)
{
$text = $this->processDocuments($text, $args);
$text = $this->processGalleries($text, $args);
return $text;
} | php | public function process($text, $args = null)
{
$text = $this->processDocuments($text, $args);
$text = $this->processGalleries($text, $args);
return $text;
} | [
"public",
"function",
"process",
"(",
"$",
"text",
",",
"$",
"args",
"=",
"null",
")",
"{",
"$",
"text",
"=",
"$",
"this",
"->",
"processDocuments",
"(",
"$",
"text",
",",
"$",
"args",
")",
";",
"$",
"text",
"=",
"$",
"this",
"->",
"processGalleries",
"(",
"$",
"text",
",",
"$",
"args",
")",
";",
"return",
"$",
"text",
";",
"}"
] | Processes the given text
@param string $text
@param array|null $args
@return string | [
"Processes",
"the",
"given",
"text"
] | 750e24b7ab5d625af5471584108d2fad0443dbca | https://github.com/NuclearCMS/Synthesizer/blob/750e24b7ab5d625af5471584108d2fad0443dbca/src/Processors/DocumentsProcessor.php#L33-L39 |
9,376 | NuclearCMS/Synthesizer | src/Processors/DocumentsProcessor.php | DocumentsProcessor.makeDocuments | protected function makeDocuments(array $matches, array $ids, $documents, $text)
{
foreach ($ids as $key => $id)
{
$document = $documents->find($id);
$parsedDocument = '';
if ( ! is_null($document))
{
$parsedDocument = $document->present()->preview;
}
$text = str_replace($matches[$key], $parsedDocument, $text);
}
return $text;
} | php | protected function makeDocuments(array $matches, array $ids, $documents, $text)
{
foreach ($ids as $key => $id)
{
$document = $documents->find($id);
$parsedDocument = '';
if ( ! is_null($document))
{
$parsedDocument = $document->present()->preview;
}
$text = str_replace($matches[$key], $parsedDocument, $text);
}
return $text;
} | [
"protected",
"function",
"makeDocuments",
"(",
"array",
"$",
"matches",
",",
"array",
"$",
"ids",
",",
"$",
"documents",
",",
"$",
"text",
")",
"{",
"foreach",
"(",
"$",
"ids",
"as",
"$",
"key",
"=>",
"$",
"id",
")",
"{",
"$",
"document",
"=",
"$",
"documents",
"->",
"find",
"(",
"$",
"id",
")",
";",
"$",
"parsedDocument",
"=",
"''",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"document",
")",
")",
"{",
"$",
"parsedDocument",
"=",
"$",
"document",
"->",
"present",
"(",
")",
"->",
"preview",
";",
"}",
"$",
"text",
"=",
"str_replace",
"(",
"$",
"matches",
"[",
"$",
"key",
"]",
",",
"$",
"parsedDocument",
",",
"$",
"text",
")",
";",
"}",
"return",
"$",
"text",
";",
"}"
] | Replaces the document tags with presenter renders
@param array $matches
@param array $ids
@param Collection|null $documents
@param string $text
@return string | [
"Replaces",
"the",
"document",
"tags",
"with",
"presenter",
"renders"
] | 750e24b7ab5d625af5471584108d2fad0443dbca | https://github.com/NuclearCMS/Synthesizer/blob/750e24b7ab5d625af5471584108d2fad0443dbca/src/Processors/DocumentsProcessor.php#L90-L107 |
9,377 | NuclearCMS/Synthesizer | src/Processors/DocumentsProcessor.php | DocumentsProcessor.getGalleryMatches | protected function getGalleryMatches($text)
{
preg_match_all('~\[gallery.+ids="(\d+(?:,\d+)*)"\]~', $text, $matches);
list($matches, $gallery) = $matches;
foreach ($gallery as $key => $ids)
{
$gallery[$key] = explode(',', $ids);
}
return [$matches, $gallery];
} | php | protected function getGalleryMatches($text)
{
preg_match_all('~\[gallery.+ids="(\d+(?:,\d+)*)"\]~', $text, $matches);
list($matches, $gallery) = $matches;
foreach ($gallery as $key => $ids)
{
$gallery[$key] = explode(',', $ids);
}
return [$matches, $gallery];
} | [
"protected",
"function",
"getGalleryMatches",
"(",
"$",
"text",
")",
"{",
"preg_match_all",
"(",
"'~\\[gallery.+ids=\"(\\d+(?:,\\d+)*)\"\\]~'",
",",
"$",
"text",
",",
"$",
"matches",
")",
";",
"list",
"(",
"$",
"matches",
",",
"$",
"gallery",
")",
"=",
"$",
"matches",
";",
"foreach",
"(",
"$",
"gallery",
"as",
"$",
"key",
"=>",
"$",
"ids",
")",
"{",
"$",
"gallery",
"[",
"$",
"key",
"]",
"=",
"explode",
"(",
"','",
",",
"$",
"ids",
")",
";",
"}",
"return",
"[",
"$",
"matches",
",",
"$",
"gallery",
"]",
";",
"}"
] | Finds all media in given string
@param string $text
@return array | [
"Finds",
"all",
"media",
"in",
"given",
"string"
] | 750e24b7ab5d625af5471584108d2fad0443dbca | https://github.com/NuclearCMS/Synthesizer/blob/750e24b7ab5d625af5471584108d2fad0443dbca/src/Processors/DocumentsProcessor.php#L129-L141 |
9,378 | NuclearCMS/Synthesizer | src/Processors/DocumentsProcessor.php | DocumentsProcessor.makeGalleries | protected function makeGalleries(array $matches, array $idSets, $text)
{
foreach ($idSets as $key => $ids)
{
$slides = get_nuclear_gallery($ids);
$gallery = (count($slides)) ? $this->makeGalleryHTML($slides) : '';
$text = str_replace($matches[$key], $gallery, $text);
}
return $text;
} | php | protected function makeGalleries(array $matches, array $idSets, $text)
{
foreach ($idSets as $key => $ids)
{
$slides = get_nuclear_gallery($ids);
$gallery = (count($slides)) ? $this->makeGalleryHTML($slides) : '';
$text = str_replace($matches[$key], $gallery, $text);
}
return $text;
} | [
"protected",
"function",
"makeGalleries",
"(",
"array",
"$",
"matches",
",",
"array",
"$",
"idSets",
",",
"$",
"text",
")",
"{",
"foreach",
"(",
"$",
"idSets",
"as",
"$",
"key",
"=>",
"$",
"ids",
")",
"{",
"$",
"slides",
"=",
"get_nuclear_gallery",
"(",
"$",
"ids",
")",
";",
"$",
"gallery",
"=",
"(",
"count",
"(",
"$",
"slides",
")",
")",
"?",
"$",
"this",
"->",
"makeGalleryHTML",
"(",
"$",
"slides",
")",
":",
"''",
";",
"$",
"text",
"=",
"str_replace",
"(",
"$",
"matches",
"[",
"$",
"key",
"]",
",",
"$",
"gallery",
",",
"$",
"text",
")",
";",
"}",
"return",
"$",
"text",
";",
"}"
] | Replaces the document tags with gallery render
@param array $matches
@param array $idSets
@param string $text
@return string | [
"Replaces",
"the",
"document",
"tags",
"with",
"gallery",
"render"
] | 750e24b7ab5d625af5471584108d2fad0443dbca | https://github.com/NuclearCMS/Synthesizer/blob/750e24b7ab5d625af5471584108d2fad0443dbca/src/Processors/DocumentsProcessor.php#L151-L163 |
9,379 | NuclearCMS/Synthesizer | src/Processors/DocumentsProcessor.php | DocumentsProcessor.makeGalleryHTML | protected function makeGalleryHTML(Collection $slides)
{
if ( ! count($slides))
{
return '';
}
$html = '';
foreach ($slides as $slide)
{
$html .= $this->makeSlideHTML($slide);
}
return $this->wrapSlidesHTML($html);
} | php | protected function makeGalleryHTML(Collection $slides)
{
if ( ! count($slides))
{
return '';
}
$html = '';
foreach ($slides as $slide)
{
$html .= $this->makeSlideHTML($slide);
}
return $this->wrapSlidesHTML($html);
} | [
"protected",
"function",
"makeGalleryHTML",
"(",
"Collection",
"$",
"slides",
")",
"{",
"if",
"(",
"!",
"count",
"(",
"$",
"slides",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"html",
"=",
"''",
";",
"foreach",
"(",
"$",
"slides",
"as",
"$",
"slide",
")",
"{",
"$",
"html",
".=",
"$",
"this",
"->",
"makeSlideHTML",
"(",
"$",
"slide",
")",
";",
"}",
"return",
"$",
"this",
"->",
"wrapSlidesHTML",
"(",
"$",
"html",
")",
";",
"}"
] | Makes gallery HTML
@param Collection $slides
@return string | [
"Makes",
"gallery",
"HTML"
] | 750e24b7ab5d625af5471584108d2fad0443dbca | https://github.com/NuclearCMS/Synthesizer/blob/750e24b7ab5d625af5471584108d2fad0443dbca/src/Processors/DocumentsProcessor.php#L171-L186 |
9,380 | NuclearCMS/Synthesizer | src/Processors/DocumentsProcessor.php | DocumentsProcessor.makeSlideHTML | protected function makeSlideHTML(Image $image)
{
$translation = $image->translate();
$caption = ($translation) ? $translation->caption : '';
$description = ($translation) ? $translation->description : '';
return '<li class="gallery__item">
<figure data-original="' . $image->getPublicURL() . '">' .
$image->present()->thumbnail .
'<figcaption class="gallery-thumbnail__caption">' . $caption . '</figcaption>
<p class="gallery-thumbnail__description">' . $description . '</p>
</figure>
</li>';
} | php | protected function makeSlideHTML(Image $image)
{
$translation = $image->translate();
$caption = ($translation) ? $translation->caption : '';
$description = ($translation) ? $translation->description : '';
return '<li class="gallery__item">
<figure data-original="' . $image->getPublicURL() . '">' .
$image->present()->thumbnail .
'<figcaption class="gallery-thumbnail__caption">' . $caption . '</figcaption>
<p class="gallery-thumbnail__description">' . $description . '</p>
</figure>
</li>';
} | [
"protected",
"function",
"makeSlideHTML",
"(",
"Image",
"$",
"image",
")",
"{",
"$",
"translation",
"=",
"$",
"image",
"->",
"translate",
"(",
")",
";",
"$",
"caption",
"=",
"(",
"$",
"translation",
")",
"?",
"$",
"translation",
"->",
"caption",
":",
"''",
";",
"$",
"description",
"=",
"(",
"$",
"translation",
")",
"?",
"$",
"translation",
"->",
"description",
":",
"''",
";",
"return",
"'<li class=\"gallery__item\">\n <figure data-original=\"'",
".",
"$",
"image",
"->",
"getPublicURL",
"(",
")",
".",
"'\">'",
".",
"$",
"image",
"->",
"present",
"(",
")",
"->",
"thumbnail",
".",
"'<figcaption class=\"gallery-thumbnail__caption\">'",
".",
"$",
"caption",
".",
"'</figcaption>\n <p class=\"gallery-thumbnail__description\">'",
".",
"$",
"description",
".",
"'</p>\n </figure>\n </li>'",
";",
"}"
] | Makes slide HTML
@param Image $image
@return string | [
"Makes",
"slide",
"HTML"
] | 750e24b7ab5d625af5471584108d2fad0443dbca | https://github.com/NuclearCMS/Synthesizer/blob/750e24b7ab5d625af5471584108d2fad0443dbca/src/Processors/DocumentsProcessor.php#L194-L207 |
9,381 | kore/CTXParser | src/php/CTXParser/Parser.php | Parser.parseString | public function parseString($string)
{
$tokens = new Stack($this->tokenizer->tokenize($string));
if ($tokens[0]->type === Tokenizer::T_EOF) {
return new CTX\AccountInfoList();
}
$ctx = new CTX();
$this->reduceStruct($tokens, $ctx);
return $ctx->accountInfoList[0];
} | php | public function parseString($string)
{
$tokens = new Stack($this->tokenizer->tokenize($string));
if ($tokens[0]->type === Tokenizer::T_EOF) {
return new CTX\AccountInfoList();
}
$ctx = new CTX();
$this->reduceStruct($tokens, $ctx);
return $ctx->accountInfoList[0];
} | [
"public",
"function",
"parseString",
"(",
"$",
"string",
")",
"{",
"$",
"tokens",
"=",
"new",
"Stack",
"(",
"$",
"this",
"->",
"tokenizer",
"->",
"tokenize",
"(",
"$",
"string",
")",
")",
";",
"if",
"(",
"$",
"tokens",
"[",
"0",
"]",
"->",
"type",
"===",
"Tokenizer",
"::",
"T_EOF",
")",
"{",
"return",
"new",
"CTX",
"\\",
"AccountInfoList",
"(",
")",
";",
"}",
"$",
"ctx",
"=",
"new",
"CTX",
"(",
")",
";",
"$",
"this",
"->",
"reduceStruct",
"(",
"$",
"tokens",
",",
"$",
"ctx",
")",
";",
"return",
"$",
"ctx",
"->",
"accountInfoList",
"[",
"0",
"]",
";",
"}"
] | Parse the given string
@param string $string
@return AccountInfoList | [
"Parse",
"the",
"given",
"string"
] | 9b11c2311a9de61baee7edafe46d1671dd5833c4 | https://github.com/kore/CTXParser/blob/9b11c2311a9de61baee7edafe46d1671dd5833c4/src/php/CTXParser/Parser.php#L43-L55 |
9,382 | kore/CTXParser | src/php/CTXParser/Parser.php | Parser.read | private function read(array $types, Stack $tokens)
{
$token = $tokens->shift();
if (!in_array($token->type, $types, true)) {
$names = array();
foreach ($types as $type) {
$names[] = $this->tokenizer->getTokenName($type);
}
throw new \RuntimeException(
"Expected one of: " . implode(', ', $names) . ", found " .
$this->tokenizer->getTokenName($token->type) .
". in line {$token->line} at position {$token->position}."
);
}
return $token;
} | php | private function read(array $types, Stack $tokens)
{
$token = $tokens->shift();
if (!in_array($token->type, $types, true)) {
$names = array();
foreach ($types as $type) {
$names[] = $this->tokenizer->getTokenName($type);
}
throw new \RuntimeException(
"Expected one of: " . implode(', ', $names) . ", found " .
$this->tokenizer->getTokenName($token->type) .
". in line {$token->line} at position {$token->position}."
);
}
return $token;
} | [
"private",
"function",
"read",
"(",
"array",
"$",
"types",
",",
"Stack",
"$",
"tokens",
")",
"{",
"$",
"token",
"=",
"$",
"tokens",
"->",
"shift",
"(",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"token",
"->",
"type",
",",
"$",
"types",
",",
"true",
")",
")",
"{",
"$",
"names",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"types",
"as",
"$",
"type",
")",
"{",
"$",
"names",
"[",
"]",
"=",
"$",
"this",
"->",
"tokenizer",
"->",
"getTokenName",
"(",
"$",
"type",
")",
";",
"}",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Expected one of: \"",
".",
"implode",
"(",
"', '",
",",
"$",
"names",
")",
".",
"\", found \"",
".",
"$",
"this",
"->",
"tokenizer",
"->",
"getTokenName",
"(",
"$",
"token",
"->",
"type",
")",
".",
"\". in line {$token->line} at position {$token->position}.\"",
")",
";",
"}",
"return",
"$",
"token",
";",
"}"
] | Read expected from token array
Try to read the given token from the token array. If another token is
found, a parse error is issued. If the token is found, the token is
removed fromt he token array and returned.
@param array $types
@param Token[] $tokens
@return Token | [
"Read",
"expected",
"from",
"token",
"array"
] | 9b11c2311a9de61baee7edafe46d1671dd5833c4 | https://github.com/kore/CTXParser/blob/9b11c2311a9de61baee7edafe46d1671dd5833c4/src/php/CTXParser/Parser.php#L68-L86 |
9,383 | kore/CTXParser | src/php/CTXParser/Parser.php | Parser.reduceArrayValue | protected function reduceArrayValue(Stack $tokens, Struct $parent)
{
$token = $this->read(array(Tokenizer::T_ARRAY_VALUE), $tokens);
$name = $token->match['name'];
$parent->$name = array_map(
function ($value) use ($token) {
return $this->getValue($token, $value);
},
preg_split('(",\\s*")', $token->match['value'])
);
} | php | protected function reduceArrayValue(Stack $tokens, Struct $parent)
{
$token = $this->read(array(Tokenizer::T_ARRAY_VALUE), $tokens);
$name = $token->match['name'];
$parent->$name = array_map(
function ($value) use ($token) {
return $this->getValue($token, $value);
},
preg_split('(",\\s*")', $token->match['value'])
);
} | [
"protected",
"function",
"reduceArrayValue",
"(",
"Stack",
"$",
"tokens",
",",
"Struct",
"$",
"parent",
")",
"{",
"$",
"token",
"=",
"$",
"this",
"->",
"read",
"(",
"array",
"(",
"Tokenizer",
"::",
"T_ARRAY_VALUE",
")",
",",
"$",
"tokens",
")",
";",
"$",
"name",
"=",
"$",
"token",
"->",
"match",
"[",
"'name'",
"]",
";",
"$",
"parent",
"->",
"$",
"name",
"=",
"array_map",
"(",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"$",
"token",
")",
"{",
"return",
"$",
"this",
"->",
"getValue",
"(",
"$",
"token",
",",
"$",
"value",
")",
";",
"}",
",",
"preg_split",
"(",
"'(\",\\\\s*\")'",
",",
"$",
"token",
"->",
"match",
"[",
"'value'",
"]",
")",
")",
";",
"}"
] | Reduce array value
@param Stack $tokens
@param Struct $parent
@return void | [
"Reduce",
"array",
"value"
] | 9b11c2311a9de61baee7edafe46d1671dd5833c4 | https://github.com/kore/CTXParser/blob/9b11c2311a9de61baee7edafe46d1671dd5833c4/src/php/CTXParser/Parser.php#L149-L160 |
9,384 | kore/CTXParser | src/php/CTXParser/Parser.php | Parser.getValue | protected function getValue(Token $token, $value = null)
{
$value = $value ?: $token->match['value'];
$type = $token->match['type'];
switch (true) {
case $type === 'int':
return (int) $value;
case $type === 'char' &&
preg_match('(^(?P<value>-?\\d+)%2F100$)', $value, $match):
return $match['value'] / 100;
case $type === 'char':
return (string) urldecode($value);
default:
throw new \RuntimeException(
"Unknown value type $type in line {$token->line} at position {$token->position}."
);
}
} | php | protected function getValue(Token $token, $value = null)
{
$value = $value ?: $token->match['value'];
$type = $token->match['type'];
switch (true) {
case $type === 'int':
return (int) $value;
case $type === 'char' &&
preg_match('(^(?P<value>-?\\d+)%2F100$)', $value, $match):
return $match['value'] / 100;
case $type === 'char':
return (string) urldecode($value);
default:
throw new \RuntimeException(
"Unknown value type $type in line {$token->line} at position {$token->position}."
);
}
} | [
"protected",
"function",
"getValue",
"(",
"Token",
"$",
"token",
",",
"$",
"value",
"=",
"null",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"?",
":",
"$",
"token",
"->",
"match",
"[",
"'value'",
"]",
";",
"$",
"type",
"=",
"$",
"token",
"->",
"match",
"[",
"'type'",
"]",
";",
"switch",
"(",
"true",
")",
"{",
"case",
"$",
"type",
"===",
"'int'",
":",
"return",
"(",
"int",
")",
"$",
"value",
";",
"case",
"$",
"type",
"===",
"'char'",
"&&",
"preg_match",
"(",
"'(^(?P<value>-?\\\\d+)%2F100$)'",
",",
"$",
"value",
",",
"$",
"match",
")",
":",
"return",
"$",
"match",
"[",
"'value'",
"]",
"/",
"100",
";",
"case",
"$",
"type",
"===",
"'char'",
":",
"return",
"(",
"string",
")",
"urldecode",
"(",
"$",
"value",
")",
";",
"default",
":",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Unknown value type $type in line {$token->line} at position {$token->position}.\"",
")",
";",
"}",
"}"
] | Convert token value type
@param Token $token
@param string $value
@return mixed | [
"Convert",
"token",
"value",
"type"
] | 9b11c2311a9de61baee7edafe46d1671dd5833c4 | https://github.com/kore/CTXParser/blob/9b11c2311a9de61baee7edafe46d1671dd5833c4/src/php/CTXParser/Parser.php#L169-L187 |
9,385 | mszewcz/php-light-framework | src/Validator/Specific/Password.php | Password.validateLetter | private function validateLetter(): bool
{
if ($this->options['require-letter'] === true) {
if (!\preg_match('/[a-z]/iu', (string)$this->value)) {
$this->setError(self::VALIDATOR_ERROR_PASSWORD_MUST_CONTAIN_LETTER);
return false;
}
}
return true;
} | php | private function validateLetter(): bool
{
if ($this->options['require-letter'] === true) {
if (!\preg_match('/[a-z]/iu', (string)$this->value)) {
$this->setError(self::VALIDATOR_ERROR_PASSWORD_MUST_CONTAIN_LETTER);
return false;
}
}
return true;
} | [
"private",
"function",
"validateLetter",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"'require-letter'",
"]",
"===",
"true",
")",
"{",
"if",
"(",
"!",
"\\",
"preg_match",
"(",
"'/[a-z]/iu'",
",",
"(",
"string",
")",
"$",
"this",
"->",
"value",
")",
")",
"{",
"$",
"this",
"->",
"setError",
"(",
"self",
"::",
"VALIDATOR_ERROR_PASSWORD_MUST_CONTAIN_LETTER",
")",
";",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Validates that password contains a letter
@return bool | [
"Validates",
"that",
"password",
"contains",
"a",
"letter"
] | 4d3b46781c387202c2dfbdb8760151b3ae8ef49c | https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Validator/Specific/Password.php#L76-L85 |
9,386 | mszewcz/php-light-framework | src/Validator/Specific/Password.php | Password.validateLowercaseLetter | private function validateLowercaseLetter(): bool
{
if ($this->options['require-lowercase-letter'] === true) {
if (!\preg_match('/[a-z]/u', (string)$this->value)) {
$this->setError(self::VALIDATOR_ERROR_PASSWORD_MUST_CONTAIN_LOWERCASE_LETTER);
return false;
}
}
return true;
} | php | private function validateLowercaseLetter(): bool
{
if ($this->options['require-lowercase-letter'] === true) {
if (!\preg_match('/[a-z]/u', (string)$this->value)) {
$this->setError(self::VALIDATOR_ERROR_PASSWORD_MUST_CONTAIN_LOWERCASE_LETTER);
return false;
}
}
return true;
} | [
"private",
"function",
"validateLowercaseLetter",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"'require-lowercase-letter'",
"]",
"===",
"true",
")",
"{",
"if",
"(",
"!",
"\\",
"preg_match",
"(",
"'/[a-z]/u'",
",",
"(",
"string",
")",
"$",
"this",
"->",
"value",
")",
")",
"{",
"$",
"this",
"->",
"setError",
"(",
"self",
"::",
"VALIDATOR_ERROR_PASSWORD_MUST_CONTAIN_LOWERCASE_LETTER",
")",
";",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Validates that password contains a lowercase letter
@return bool | [
"Validates",
"that",
"password",
"contains",
"a",
"lowercase",
"letter"
] | 4d3b46781c387202c2dfbdb8760151b3ae8ef49c | https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Validator/Specific/Password.php#L92-L101 |
9,387 | mszewcz/php-light-framework | src/Validator/Specific/Password.php | Password.validateUppercaseLetter | private function validateUppercaseLetter(): bool
{
if ($this->options['require-uppercase-letter'] === true) {
if (!\preg_match('/[A-Z]/u', (string)$this->value)) {
$this->setError(self::VALIDATOR_ERROR_PASSWORD_MUST_CONTAIN_UPPERCASE_LETTER);
return false;
}
}
return true;
} | php | private function validateUppercaseLetter(): bool
{
if ($this->options['require-uppercase-letter'] === true) {
if (!\preg_match('/[A-Z]/u', (string)$this->value)) {
$this->setError(self::VALIDATOR_ERROR_PASSWORD_MUST_CONTAIN_UPPERCASE_LETTER);
return false;
}
}
return true;
} | [
"private",
"function",
"validateUppercaseLetter",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"'require-uppercase-letter'",
"]",
"===",
"true",
")",
"{",
"if",
"(",
"!",
"\\",
"preg_match",
"(",
"'/[A-Z]/u'",
",",
"(",
"string",
")",
"$",
"this",
"->",
"value",
")",
")",
"{",
"$",
"this",
"->",
"setError",
"(",
"self",
"::",
"VALIDATOR_ERROR_PASSWORD_MUST_CONTAIN_UPPERCASE_LETTER",
")",
";",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Validates that password contains an uppercase letter
@return bool | [
"Validates",
"that",
"password",
"contains",
"an",
"uppercase",
"letter"
] | 4d3b46781c387202c2dfbdb8760151b3ae8ef49c | https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Validator/Specific/Password.php#L108-L117 |
9,388 | mszewcz/php-light-framework | src/Validator/Specific/Password.php | Password.validateNumber | private function validateNumber(): bool
{
if ($this->options['require-number'] === true) {
if (!\preg_match('/[0-9]/', (string)$this->value)) {
$this->setError(self::VALIDATOR_ERROR_PASSWORD_MUST_CONTAIN_NUMBER);
return false;
}
}
return true;
} | php | private function validateNumber(): bool
{
if ($this->options['require-number'] === true) {
if (!\preg_match('/[0-9]/', (string)$this->value)) {
$this->setError(self::VALIDATOR_ERROR_PASSWORD_MUST_CONTAIN_NUMBER);
return false;
}
}
return true;
} | [
"private",
"function",
"validateNumber",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"'require-number'",
"]",
"===",
"true",
")",
"{",
"if",
"(",
"!",
"\\",
"preg_match",
"(",
"'/[0-9]/'",
",",
"(",
"string",
")",
"$",
"this",
"->",
"value",
")",
")",
"{",
"$",
"this",
"->",
"setError",
"(",
"self",
"::",
"VALIDATOR_ERROR_PASSWORD_MUST_CONTAIN_NUMBER",
")",
";",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Validates that password contains a number
@return bool | [
"Validates",
"that",
"password",
"contains",
"a",
"number"
] | 4d3b46781c387202c2dfbdb8760151b3ae8ef49c | https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Validator/Specific/Password.php#L124-L133 |
9,389 | mszewcz/php-light-framework | src/Validator/Specific/Password.php | Password.validateSpecialCharacter | private function validateSpecialCharacter(): bool
{
if ($this->options['require-special-character'] === true) {
if (!\preg_match('/'.$this->options['special-character-pattern'].'/', (string)$this->value)) {
$this->setError(self::VALIDATOR_ERROR_PASSWORD_MUST_CONTAIN_SPECIAL_CHARACTER);
return false;
}
}
return true;
} | php | private function validateSpecialCharacter(): bool
{
if ($this->options['require-special-character'] === true) {
if (!\preg_match('/'.$this->options['special-character-pattern'].'/', (string)$this->value)) {
$this->setError(self::VALIDATOR_ERROR_PASSWORD_MUST_CONTAIN_SPECIAL_CHARACTER);
return false;
}
}
return true;
} | [
"private",
"function",
"validateSpecialCharacter",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"'require-special-character'",
"]",
"===",
"true",
")",
"{",
"if",
"(",
"!",
"\\",
"preg_match",
"(",
"'/'",
".",
"$",
"this",
"->",
"options",
"[",
"'special-character-pattern'",
"]",
".",
"'/'",
",",
"(",
"string",
")",
"$",
"this",
"->",
"value",
")",
")",
"{",
"$",
"this",
"->",
"setError",
"(",
"self",
"::",
"VALIDATOR_ERROR_PASSWORD_MUST_CONTAIN_SPECIAL_CHARACTER",
")",
";",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Validates that password contains a special character
@return bool | [
"Validates",
"that",
"password",
"contains",
"a",
"special",
"character"
] | 4d3b46781c387202c2dfbdb8760151b3ae8ef49c | https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Validator/Specific/Password.php#L140-L149 |
9,390 | mszewcz/php-light-framework | src/Validator/Specific/Password.php | Password.validateDifferentPreviousOne | private function validateDifferentPreviousOne(): bool
{
if ($this->options['require-different-than-previous-one'] === true) {
if (isset($this->options['stored-passwords'][0])) {
$passwordHash = (string)$this->value;
if (PasswordEnctyption::compare($passwordHash, $this->options['stored-passwords'][0])) {
$this->setError(self::VALIDATOR_ERROR_PASSWORD_MUST_BE_DIFFERENT_THAN_PREVIOUS_ONE);
return false;
}
}
}
return true;
} | php | private function validateDifferentPreviousOne(): bool
{
if ($this->options['require-different-than-previous-one'] === true) {
if (isset($this->options['stored-passwords'][0])) {
$passwordHash = (string)$this->value;
if (PasswordEnctyption::compare($passwordHash, $this->options['stored-passwords'][0])) {
$this->setError(self::VALIDATOR_ERROR_PASSWORD_MUST_BE_DIFFERENT_THAN_PREVIOUS_ONE);
return false;
}
}
}
return true;
} | [
"private",
"function",
"validateDifferentPreviousOne",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"'require-different-than-previous-one'",
"]",
"===",
"true",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'stored-passwords'",
"]",
"[",
"0",
"]",
")",
")",
"{",
"$",
"passwordHash",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"value",
";",
"if",
"(",
"PasswordEnctyption",
"::",
"compare",
"(",
"$",
"passwordHash",
",",
"$",
"this",
"->",
"options",
"[",
"'stored-passwords'",
"]",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setError",
"(",
"self",
"::",
"VALIDATOR_ERROR_PASSWORD_MUST_BE_DIFFERENT_THAN_PREVIOUS_ONE",
")",
";",
"return",
"false",
";",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] | Validates that password is different than previous one
@return bool | [
"Validates",
"that",
"password",
"is",
"different",
"than",
"previous",
"one"
] | 4d3b46781c387202c2dfbdb8760151b3ae8ef49c | https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Validator/Specific/Password.php#L156-L168 |
9,391 | mszewcz/php-light-framework | src/Validator/Specific/Password.php | Password.validateDifferentPreviousAll | private function validateDifferentPreviousAll(): bool
{
if ($this->options['require-different-than-previous-all'] === true) {
$passwordHash = (string)$this->value;
foreach ($this->options['stored-passwords'] as $storedPassword) {
if (PasswordEnctyption::compare($passwordHash, $storedPassword)) {
$this->setError(self::VALIDATOR_ERROR_PASSWORD_MUST_BE_DIFFERENT_THAN_PREVIOUS_ALL);
return false;
}
}
}
return true;
} | php | private function validateDifferentPreviousAll(): bool
{
if ($this->options['require-different-than-previous-all'] === true) {
$passwordHash = (string)$this->value;
foreach ($this->options['stored-passwords'] as $storedPassword) {
if (PasswordEnctyption::compare($passwordHash, $storedPassword)) {
$this->setError(self::VALIDATOR_ERROR_PASSWORD_MUST_BE_DIFFERENT_THAN_PREVIOUS_ALL);
return false;
}
}
}
return true;
} | [
"private",
"function",
"validateDifferentPreviousAll",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"'require-different-than-previous-all'",
"]",
"===",
"true",
")",
"{",
"$",
"passwordHash",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"value",
";",
"foreach",
"(",
"$",
"this",
"->",
"options",
"[",
"'stored-passwords'",
"]",
"as",
"$",
"storedPassword",
")",
"{",
"if",
"(",
"PasswordEnctyption",
"::",
"compare",
"(",
"$",
"passwordHash",
",",
"$",
"storedPassword",
")",
")",
"{",
"$",
"this",
"->",
"setError",
"(",
"self",
"::",
"VALIDATOR_ERROR_PASSWORD_MUST_BE_DIFFERENT_THAN_PREVIOUS_ALL",
")",
";",
"return",
"false",
";",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] | Validates that password is different than all previous passwords
@return bool | [
"Validates",
"that",
"password",
"is",
"different",
"than",
"all",
"previous",
"passwords"
] | 4d3b46781c387202c2dfbdb8760151b3ae8ef49c | https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Validator/Specific/Password.php#L175-L187 |
9,392 | iRAP-software/package-core-libs | src/ArrayLib.php | ArrayLib.getLastElement | public static function getLastElement(array &$inputArray, $removeElement=false)
{
if (count($inputArray) > 0)
{
if (!$removeElement)
{
$element = end($inputArray);
}
else
{
$element = array_pop($inputArray);
}
}
else
{
throw new \Exception('inputArray has no elements');
}
return $element;
} | php | public static function getLastElement(array &$inputArray, $removeElement=false)
{
if (count($inputArray) > 0)
{
if (!$removeElement)
{
$element = end($inputArray);
}
else
{
$element = array_pop($inputArray);
}
}
else
{
throw new \Exception('inputArray has no elements');
}
return $element;
} | [
"public",
"static",
"function",
"getLastElement",
"(",
"array",
"&",
"$",
"inputArray",
",",
"$",
"removeElement",
"=",
"false",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"inputArray",
")",
">",
"0",
")",
"{",
"if",
"(",
"!",
"$",
"removeElement",
")",
"{",
"$",
"element",
"=",
"end",
"(",
"$",
"inputArray",
")",
";",
"}",
"else",
"{",
"$",
"element",
"=",
"array_pop",
"(",
"$",
"inputArray",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'inputArray has no elements'",
")",
";",
"}",
"return",
"$",
"element",
";",
"}"
] | Fetches the last element of an array
@param array &$inputArray - the array we want the last element of.
@param bool removeElement - override to true if you also want to remove that element
@return $element - the last element of the array. | [
"Fetches",
"the",
"last",
"element",
"of",
"an",
"array"
] | 244871d2fbc2f3fac26ff4b98715224953d9befb | https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/ArrayLib.php#L57-L76 |
9,393 | iRAP-software/package-core-libs | src/ArrayLib.php | ArrayLib.getLastIndex | public static function getLastIndex(array &$inputArray, $removeElement=false)
{
$arrayIndexes = array_keys($inputArray);
return self::getLastElement($arrayIndexes, $removeElement);
} | php | public static function getLastIndex(array &$inputArray, $removeElement=false)
{
$arrayIndexes = array_keys($inputArray);
return self::getLastElement($arrayIndexes, $removeElement);
} | [
"public",
"static",
"function",
"getLastIndex",
"(",
"array",
"&",
"$",
"inputArray",
",",
"$",
"removeElement",
"=",
"false",
")",
"{",
"$",
"arrayIndexes",
"=",
"array_keys",
"(",
"$",
"inputArray",
")",
";",
"return",
"self",
"::",
"getLastElement",
"(",
"$",
"arrayIndexes",
",",
"$",
"removeElement",
")",
";",
"}"
] | Returns the last index in the provided array
@param array $inputArray - the array we want the last index of
@param bool $removeElement - override to true if you want to also remove the element
@return mixed | [
"Returns",
"the",
"last",
"index",
"in",
"the",
"provided",
"array"
] | 244871d2fbc2f3fac26ff4b98715224953d9befb | https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/ArrayLib.php#L85-L89 |
9,394 | iRAP-software/package-core-libs | src/ArrayLib.php | ArrayLib.removeIndexes | public static function removeIndexes(array $inputArray,
array $indexes,
$reIndex=false)
{
if ($reIndex)
{
# Was going to use array_filter here but realized user may want
# 'false' values.
$outputArray = array();
foreach ($inputArray as $index => $value)
{
if (!in_array($index, $indexes))
{
$outputArray[] = $value;
}
}
}
else
{
foreach ($indexes as $index)
{
if (isset($inputArray[$index]))
{
unset($inputArray[$index]);
}
}
$outputArray = $inputArray;
}
return $outputArray;
} | php | public static function removeIndexes(array $inputArray,
array $indexes,
$reIndex=false)
{
if ($reIndex)
{
# Was going to use array_filter here but realized user may want
# 'false' values.
$outputArray = array();
foreach ($inputArray as $index => $value)
{
if (!in_array($index, $indexes))
{
$outputArray[] = $value;
}
}
}
else
{
foreach ($indexes as $index)
{
if (isset($inputArray[$index]))
{
unset($inputArray[$index]);
}
}
$outputArray = $inputArray;
}
return $outputArray;
} | [
"public",
"static",
"function",
"removeIndexes",
"(",
"array",
"$",
"inputArray",
",",
"array",
"$",
"indexes",
",",
"$",
"reIndex",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"reIndex",
")",
"{",
"# Was going to use array_filter here but realized user may want ",
"# 'false' values.",
"$",
"outputArray",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"inputArray",
"as",
"$",
"index",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"index",
",",
"$",
"indexes",
")",
")",
"{",
"$",
"outputArray",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"else",
"{",
"foreach",
"(",
"$",
"indexes",
"as",
"$",
"index",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"inputArray",
"[",
"$",
"index",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"inputArray",
"[",
"$",
"index",
"]",
")",
";",
"}",
"}",
"$",
"outputArray",
"=",
"$",
"inputArray",
";",
"}",
"return",
"$",
"outputArray",
";",
"}"
] | Removes the specified indexes from the input array before returning it.
@param array $inputArray - the array we are manipulating
@param array $indexes - array list of indexes whose elements we wish to
remove
@param bool $reIndex - override to true if your array needs re-indexing
(e.g. 0,1,2,3)
@return array $outputArray - the newly generated output array. | [
"Removes",
"the",
"specified",
"indexes",
"from",
"the",
"input",
"array",
"before",
"returning",
"it",
"."
] | 244871d2fbc2f3fac26ff4b98715224953d9befb | https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/ArrayLib.php#L103-L135 |
9,395 | iRAP-software/package-core-libs | src/ArrayLib.php | ArrayLib.mysqliWrapValues | public static function mysqliWrapValues($inputArray)
{
foreach ($inputArray as &$value)
{
if ($value !== null)
{
$value = "'" . $value . "'";
}
else
{
$value = "NULL";
}
}
return $inputArray;
} | php | public static function mysqliWrapValues($inputArray)
{
foreach ($inputArray as &$value)
{
if ($value !== null)
{
$value = "'" . $value . "'";
}
else
{
$value = "NULL";
}
}
return $inputArray;
} | [
"public",
"static",
"function",
"mysqliWrapValues",
"(",
"$",
"inputArray",
")",
"{",
"foreach",
"(",
"$",
"inputArray",
"as",
"&",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"!==",
"null",
")",
"{",
"$",
"value",
"=",
"\"'\"",
".",
"$",
"value",
".",
"\"'\"",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"\"NULL\"",
";",
"}",
"}",
"return",
"$",
"inputArray",
";",
"}"
] | Wrap all of values in an array for insertion into a database. This is a
specific variation of the wrap_elements method that will correctly
convert null values into a NULL string without quotes so that nulls get
inserted into the database correctly.
@param $inputArray - array we are going to create our wrapped array from
@return array | [
"Wrap",
"all",
"of",
"values",
"in",
"an",
"array",
"for",
"insertion",
"into",
"a",
"database",
".",
"This",
"is",
"a",
"specific",
"variation",
"of",
"the",
"wrap_elements",
"method",
"that",
"will",
"correctly",
"convert",
"null",
"values",
"into",
"a",
"NULL",
"string",
"without",
"quotes",
"so",
"that",
"nulls",
"get",
"inserted",
"into",
"the",
"database",
"correctly",
"."
] | 244871d2fbc2f3fac26ff4b98715224953d9befb | https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/ArrayLib.php#L164-L179 |
9,396 | iRAP-software/package-core-libs | src/ArrayLib.php | ArrayLib.fastDiff | public static function fastDiff($array1, $array2)
{
$missingValues = array();
$flippedArray2 = array_flip($array2); # swaps indexes and values
foreach ($array1 as $value)
{
if (!isset($flippedArray2[$value]))
{
$missingValues[] = $value;
}
}
return $missingValues;
} | php | public static function fastDiff($array1, $array2)
{
$missingValues = array();
$flippedArray2 = array_flip($array2); # swaps indexes and values
foreach ($array1 as $value)
{
if (!isset($flippedArray2[$value]))
{
$missingValues[] = $value;
}
}
return $missingValues;
} | [
"public",
"static",
"function",
"fastDiff",
"(",
"$",
"array1",
",",
"$",
"array2",
")",
"{",
"$",
"missingValues",
"=",
"array",
"(",
")",
";",
"$",
"flippedArray2",
"=",
"array_flip",
"(",
"$",
"array2",
")",
";",
"# swaps indexes and values",
"foreach",
"(",
"$",
"array1",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"flippedArray2",
"[",
"$",
"value",
"]",
")",
")",
"{",
"$",
"missingValues",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"missingValues",
";",
"}"
] | Faster version of array_diff that relies on not needing to keep indexes
of the missing values
Compares values, but returns the indexes
@param array $array1 - array to compare
@param array $array2 - array to compare
@return array - values in array1 but not array2 | [
"Faster",
"version",
"of",
"array_diff",
"that",
"relies",
"on",
"not",
"needing",
"to",
"keep",
"indexes",
"of",
"the",
"missing",
"values",
"Compares",
"values",
"but",
"returns",
"the",
"indexes"
] | 244871d2fbc2f3fac26ff4b98715224953d9befb | https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/ArrayLib.php#L190-L204 |
9,397 | iRAP-software/package-core-libs | src/ArrayLib.php | ArrayLib.fastIntersect | public static function fastIntersect($array1, $array2)
{
$sharedValues = array();
$flippedArray2 = array_flip($array2); # swaps indexes and values
foreach ($array1 as $value)
{
if (isset($flippedArray2[$value]))
{
$sharedValues[] = $value;
}
}
return $sharedValues;
} | php | public static function fastIntersect($array1, $array2)
{
$sharedValues = array();
$flippedArray2 = array_flip($array2); # swaps indexes and values
foreach ($array1 as $value)
{
if (isset($flippedArray2[$value]))
{
$sharedValues[] = $value;
}
}
return $sharedValues;
} | [
"public",
"static",
"function",
"fastIntersect",
"(",
"$",
"array1",
",",
"$",
"array2",
")",
"{",
"$",
"sharedValues",
"=",
"array",
"(",
")",
";",
"$",
"flippedArray2",
"=",
"array_flip",
"(",
"$",
"array2",
")",
";",
"# swaps indexes and values",
"foreach",
"(",
"$",
"array1",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"flippedArray2",
"[",
"$",
"value",
"]",
")",
")",
"{",
"$",
"sharedValues",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"sharedValues",
";",
"}"
] | Returns all the values that are in array1 and array2.
Relies on the values being integers or strings
Will only return a value once, even if it appears multiple times in the
array.
Does not maintain indexes.
@param array $array1 - array of integers or strings to compare
@param array $array2 - array of integers or strings to compare
@return array - values that are in both arrays | [
"Returns",
"all",
"the",
"values",
"that",
"are",
"in",
"array1",
"and",
"array2",
".",
"Relies",
"on",
"the",
"values",
"being",
"integers",
"or",
"strings",
"Will",
"only",
"return",
"a",
"value",
"once",
"even",
"if",
"it",
"appears",
"multiple",
"times",
"in",
"the",
"array",
".",
"Does",
"not",
"maintain",
"indexes",
"."
] | 244871d2fbc2f3fac26ff4b98715224953d9befb | https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/ArrayLib.php#L217-L231 |
9,398 | iRAP-software/package-core-libs | src/ArrayLib.php | ArrayLib.indexDiff | public static function indexDiff(array $array1, array $array2)
{
$indexes = array();
$flippedArray2 = array_flip($array2); # swaps indexes and values
foreach ($array1 as $index => $value)
{
if (!isset($flippedArray2[$value]))
{
$indexes[] = $index;
}
}
return $indexes;
} | php | public static function indexDiff(array $array1, array $array2)
{
$indexes = array();
$flippedArray2 = array_flip($array2); # swaps indexes and values
foreach ($array1 as $index => $value)
{
if (!isset($flippedArray2[$value]))
{
$indexes[] = $index;
}
}
return $indexes;
} | [
"public",
"static",
"function",
"indexDiff",
"(",
"array",
"$",
"array1",
",",
"array",
"$",
"array2",
")",
"{",
"$",
"indexes",
"=",
"array",
"(",
")",
";",
"$",
"flippedArray2",
"=",
"array_flip",
"(",
"$",
"array2",
")",
";",
"# swaps indexes and values",
"foreach",
"(",
"$",
"array1",
"as",
"$",
"index",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"flippedArray2",
"[",
"$",
"value",
"]",
")",
")",
"{",
"$",
"indexes",
"[",
"]",
"=",
"$",
"index",
";",
"}",
"}",
"return",
"$",
"indexes",
";",
"}"
] | Same as array_diff except that this returns the indexes of the values
that are in array1 but not array2.
WARNING - this is NOT comparing the indexes themselves.
@param array $array1
@param array $array2
@return array - array of indexes in array1 where the values are not in
array2 | [
"Same",
"as",
"array_diff",
"except",
"that",
"this",
"returns",
"the",
"indexes",
"of",
"the",
"values",
"that",
"are",
"in",
"array1",
"but",
"not",
"array2",
".",
"WARNING",
"-",
"this",
"is",
"NOT",
"comparing",
"the",
"indexes",
"themselves",
"."
] | 244871d2fbc2f3fac26ff4b98715224953d9befb | https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/ArrayLib.php#L304-L318 |
9,399 | iRAP-software/package-core-libs | src/ArrayLib.php | ArrayLib.stripEmptyElements | public static function stripEmptyElements($inputArray)
{
$outputArray = array_filter($inputArray);
if (!self::isAssoc($inputArray))
{
$outputArray = array_values($outputArray);
}
return $outputArray;
} | php | public static function stripEmptyElements($inputArray)
{
$outputArray = array_filter($inputArray);
if (!self::isAssoc($inputArray))
{
$outputArray = array_values($outputArray);
}
return $outputArray;
} | [
"public",
"static",
"function",
"stripEmptyElements",
"(",
"$",
"inputArray",
")",
"{",
"$",
"outputArray",
"=",
"array_filter",
"(",
"$",
"inputArray",
")",
";",
"if",
"(",
"!",
"self",
"::",
"isAssoc",
"(",
"$",
"inputArray",
")",
")",
"{",
"$",
"outputArray",
"=",
"array_values",
"(",
"$",
"outputArray",
")",
";",
"}",
"return",
"$",
"outputArray",
";",
"}"
] | Remove empty elements from the provided array.
If the input array is not assosciative, then it will be re-indexed. 0,1,2,3 etc
@param array $inputArray - the array to perform actions upon. | [
"Remove",
"empty",
"elements",
"from",
"the",
"provided",
"array",
".",
"If",
"the",
"input",
"array",
"is",
"not",
"assosciative",
"then",
"it",
"will",
"be",
"re",
"-",
"indexed",
".",
"0",
"1",
"2",
"3",
"etc"
] | 244871d2fbc2f3fac26ff4b98715224953d9befb | https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/ArrayLib.php#L326-L336 |
Subsets and Splits