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
|
---|---|---|---|---|---|---|---|---|---|---|---|
13,100 | christophe-brachet/aspi-framework | src/Framework/Form/Element/Select/Optgroup.php | Optgroup.getOptions | public function getOptions()
{
$options = [];
foreach ($this->childNodes as $child) {
if ($child instanceof Option) {
$options[] = $child;
}
}
return $options;
} | php | public function getOptions()
{
$options = [];
foreach ($this->childNodes as $child) {
if ($child instanceof Option) {
$options[] = $child;
}
}
return $options;
} | [
"public",
"function",
"getOptions",
"(",
")",
"{",
"$",
"options",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"childNodes",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"$",
"child",
"instanceof",
"Option",
")",
"{",
"$",
"options",
"[",
"]",
"=",
"$",
"child",
";",
"}",
"}",
"return",
"$",
"options",
";",
"}"
] | Get option elements
@return array | [
"Get",
"option",
"elements"
] | 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/Element/Select/Optgroup.php#L67-L76 |
13,101 | malahierba-lab/token | src/Token.php | Token.get | public function get()
{
if (Cache::has($this->getCacheKey()))
return Cache::get($this->getCacheKey());
return $this->create();
} | php | public function get()
{
if (Cache::has($this->getCacheKey()))
return Cache::get($this->getCacheKey());
return $this->create();
} | [
"public",
"function",
"get",
"(",
")",
"{",
"if",
"(",
"Cache",
"::",
"has",
"(",
"$",
"this",
"->",
"getCacheKey",
"(",
")",
")",
")",
"return",
"Cache",
"::",
"get",
"(",
"$",
"this",
"->",
"getCacheKey",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"create",
"(",
")",
";",
"}"
] | Get the Token
@param void
@return string | [
"Get",
"the",
"Token"
] | 47e32e8af6b3fa69abdd00a286b364bc6cfa328d | https://github.com/malahierba-lab/token/blob/47e32e8af6b3fa69abdd00a286b364bc6cfa328d/src/Token.php#L66-L72 |
13,102 | malahierba-lab/token | src/Token.php | Token.check | public function check($token)
{
if (! Cache::has($this->getCacheKey()))
return false;
return Cache::get($this->getCacheKey()) === $token;
} | php | public function check($token)
{
if (! Cache::has($this->getCacheKey()))
return false;
return Cache::get($this->getCacheKey()) === $token;
} | [
"public",
"function",
"check",
"(",
"$",
"token",
")",
"{",
"if",
"(",
"!",
"Cache",
"::",
"has",
"(",
"$",
"this",
"->",
"getCacheKey",
"(",
")",
")",
")",
"return",
"false",
";",
"return",
"Cache",
"::",
"get",
"(",
"$",
"this",
"->",
"getCacheKey",
"(",
")",
")",
"===",
"$",
"token",
";",
"}"
] | Check the token
@param string $token
@return boolean | [
"Check",
"the",
"token"
] | 47e32e8af6b3fa69abdd00a286b364bc6cfa328d | https://github.com/malahierba-lab/token/blob/47e32e8af6b3fa69abdd00a286b364bc6cfa328d/src/Token.php#L80-L86 |
13,103 | malahierba-lab/token | src/Token.php | Token.getCacheKey | protected function getCacheKey()
{
$model = new \ReflectionClass($this->model);
$namespace = Str::slug($model->getNamespaceName());
$class = Str::slug($model->getShortName());
$type = Str::slug($this->type);
$key = $this->model->getKey();
if (empty($key))
throw new Exception("[Token] Error: Empty value for " . $model->getShortName() . "'s attribute '" . $this->model->getKeyName() . "'.", 1);
return 'malahierba-token' . '---' . $namespace . '---' . $class . '---' . $type . '---' . $key;
} | php | protected function getCacheKey()
{
$model = new \ReflectionClass($this->model);
$namespace = Str::slug($model->getNamespaceName());
$class = Str::slug($model->getShortName());
$type = Str::slug($this->type);
$key = $this->model->getKey();
if (empty($key))
throw new Exception("[Token] Error: Empty value for " . $model->getShortName() . "'s attribute '" . $this->model->getKeyName() . "'.", 1);
return 'malahierba-token' . '---' . $namespace . '---' . $class . '---' . $type . '---' . $key;
} | [
"protected",
"function",
"getCacheKey",
"(",
")",
"{",
"$",
"model",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"this",
"->",
"model",
")",
";",
"$",
"namespace",
"=",
"Str",
"::",
"slug",
"(",
"$",
"model",
"->",
"getNamespaceName",
"(",
")",
")",
";",
"$",
"class",
"=",
"Str",
"::",
"slug",
"(",
"$",
"model",
"->",
"getShortName",
"(",
")",
")",
";",
"$",
"type",
"=",
"Str",
"::",
"slug",
"(",
"$",
"this",
"->",
"type",
")",
";",
"$",
"key",
"=",
"$",
"this",
"->",
"model",
"->",
"getKey",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"key",
")",
")",
"throw",
"new",
"Exception",
"(",
"\"[Token] Error: Empty value for \"",
".",
"$",
"model",
"->",
"getShortName",
"(",
")",
".",
"\"'s attribute '\"",
".",
"$",
"this",
"->",
"model",
"->",
"getKeyName",
"(",
")",
".",
"\"'.\"",
",",
"1",
")",
";",
"return",
"'malahierba-token'",
".",
"'---'",
".",
"$",
"namespace",
".",
"'---'",
".",
"$",
"class",
".",
"'---'",
".",
"$",
"type",
".",
"'---'",
".",
"$",
"key",
";",
"}"
] | Get the cache key for save the token
@param void
@return string | [
"Get",
"the",
"cache",
"key",
"for",
"save",
"the",
"token"
] | 47e32e8af6b3fa69abdd00a286b364bc6cfa328d | https://github.com/malahierba-lab/token/blob/47e32e8af6b3fa69abdd00a286b364bc6cfa328d/src/Token.php#L106-L119 |
13,104 | malahierba-lab/token | src/Token.php | Token.create | protected function create()
{
$token = $this->generateTokenString();
Cache::put($this->getCacheKey(), $token, $this->expire_in);
return $token;
} | php | protected function create()
{
$token = $this->generateTokenString();
Cache::put($this->getCacheKey(), $token, $this->expire_in);
return $token;
} | [
"protected",
"function",
"create",
"(",
")",
"{",
"$",
"token",
"=",
"$",
"this",
"->",
"generateTokenString",
"(",
")",
";",
"Cache",
"::",
"put",
"(",
"$",
"this",
"->",
"getCacheKey",
"(",
")",
",",
"$",
"token",
",",
"$",
"this",
"->",
"expire_in",
")",
";",
"return",
"$",
"token",
";",
"}"
] | Create a new token and save as cache var
@param void
@return string | [
"Create",
"a",
"new",
"token",
"and",
"save",
"as",
"cache",
"var"
] | 47e32e8af6b3fa69abdd00a286b364bc6cfa328d | https://github.com/malahierba-lab/token/blob/47e32e8af6b3fa69abdd00a286b364bc6cfa328d/src/Token.php#L138-L145 |
13,105 | cicada/cicada | src/Application.php | Application.query | public function query($method, $pattern, $callback)
{
$route = new Route($pattern, $callback, $method);
$this['router']->addRoute($route);
return $route;
} | php | public function query($method, $pattern, $callback)
{
$route = new Route($pattern, $callback, $method);
$this['router']->addRoute($route);
return $route;
} | [
"public",
"function",
"query",
"(",
"$",
"method",
",",
"$",
"pattern",
",",
"$",
"callback",
")",
"{",
"$",
"route",
"=",
"new",
"Route",
"(",
"$",
"pattern",
",",
"$",
"callback",
",",
"$",
"method",
")",
";",
"$",
"this",
"[",
"'router'",
"]",
"->",
"addRoute",
"(",
"$",
"route",
")",
";",
"return",
"$",
"route",
";",
"}"
] | Creates a route for a request.
@param string $method HTTP method to match.
@param string $pattern Path pattern which matches the callback.
@param callable $callback Callback function which processes the request.
@return Route | [
"Creates",
"a",
"route",
"for",
"a",
"request",
"."
] | 5a54bd05dfa1df38e7aa3d704d270853f0329e13 | https://github.com/cicada/cicada/blob/5a54bd05dfa1df38e7aa3d704d270853f0329e13/src/Application.php#L160-L166 |
13,106 | cicada/cicada | src/Application.php | Application.run | public function run()
{
$request = Request::createFromGlobals();
$response = $this->handle($request);
$response->send();
$this->invokeFinish([], [$this, $request, $response]);
} | php | public function run()
{
$request = Request::createFromGlobals();
$response = $this->handle($request);
$response->send();
$this->invokeFinish([], [$this, $request, $response]);
} | [
"public",
"function",
"run",
"(",
")",
"{",
"$",
"request",
"=",
"Request",
"::",
"createFromGlobals",
"(",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"handle",
"(",
"$",
"request",
")",
";",
"$",
"response",
"->",
"send",
"(",
")",
";",
"$",
"this",
"->",
"invokeFinish",
"(",
"[",
"]",
",",
"[",
"$",
"this",
",",
"$",
"request",
",",
"$",
"response",
"]",
")",
";",
"}"
] | Creates the request from globals, handles it and returns the response. | [
"Creates",
"the",
"request",
"from",
"globals",
"handles",
"it",
"and",
"returns",
"the",
"response",
"."
] | 5a54bd05dfa1df38e7aa3d704d270853f0329e13 | https://github.com/cicada/cicada/blob/5a54bd05dfa1df38e7aa3d704d270853f0329e13/src/Application.php#L188-L195 |
13,107 | markwatkinson/luminous | src/Luminous/Scanners.php | Scanners.addScanner | public function addScanner($languageName, $scanner, $langDescription)
{
$dummy = $scanner === null;
$d = array();
$insert = array(
'scanner' => $scanner,
'description' => $langDescription
);
if (!is_array($languageName)) {
$languageName = array($languageName);
}
foreach ($languageName as $l) {
$this->lookupTable[$l] = $insert;
if (!$dummy) {
$this->addDescription($langDescription, $l);
}
}
} | php | public function addScanner($languageName, $scanner, $langDescription)
{
$dummy = $scanner === null;
$d = array();
$insert = array(
'scanner' => $scanner,
'description' => $langDescription
);
if (!is_array($languageName)) {
$languageName = array($languageName);
}
foreach ($languageName as $l) {
$this->lookupTable[$l] = $insert;
if (!$dummy) {
$this->addDescription($langDescription, $l);
}
}
} | [
"public",
"function",
"addScanner",
"(",
"$",
"languageName",
",",
"$",
"scanner",
",",
"$",
"langDescription",
")",
"{",
"$",
"dummy",
"=",
"$",
"scanner",
"===",
"null",
";",
"$",
"d",
"=",
"array",
"(",
")",
";",
"$",
"insert",
"=",
"array",
"(",
"'scanner'",
"=>",
"$",
"scanner",
",",
"'description'",
"=>",
"$",
"langDescription",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"languageName",
")",
")",
"{",
"$",
"languageName",
"=",
"array",
"(",
"$",
"languageName",
")",
";",
"}",
"foreach",
"(",
"$",
"languageName",
"as",
"$",
"l",
")",
"{",
"$",
"this",
"->",
"lookupTable",
"[",
"$",
"l",
"]",
"=",
"$",
"insert",
";",
"if",
"(",
"!",
"$",
"dummy",
")",
"{",
"$",
"this",
"->",
"addDescription",
"(",
"$",
"langDescription",
",",
"$",
"l",
")",
";",
"}",
"}",
"}"
] | Adds a scanner into the table, or overwrites an existing scanner.
@param language_name may be either a string or an array of strings, if
multiple languages are to use the same scanner
@param $scanner the name of the LuminousScanner object as string, (not an
actual instance!). If the file is actually a dummy file (say for includes),
leave $scanner as @c null.
@param lang_description a human-readable description of the language. | [
"Adds",
"a",
"scanner",
"into",
"the",
"table",
"or",
"overwrites",
"an",
"existing",
"scanner",
"."
] | 4adc18f414534abe986133d6d38e8e9787d32e69 | https://github.com/markwatkinson/luminous/blob/4adc18f414534abe986133d6d38e8e9787d32e69/src/Luminous/Scanners.php#L49-L67 |
13,108 | markwatkinson/luminous | src/Luminous/Scanners.php | Scanners.removeScanner | public function removeScanner($languageName)
{
if (is_array($languageName)) {
foreach ($languageName as $l) {
unset($this->lookupTable[$l]);
$this->unsetDescription($l);
}
} else {
$this->unsetDescription($languageName);
unset($this->lookupTable[$languageName]);
}
} | php | public function removeScanner($languageName)
{
if (is_array($languageName)) {
foreach ($languageName as $l) {
unset($this->lookupTable[$l]);
$this->unsetDescription($l);
}
} else {
$this->unsetDescription($languageName);
unset($this->lookupTable[$languageName]);
}
} | [
"public",
"function",
"removeScanner",
"(",
"$",
"languageName",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"languageName",
")",
")",
"{",
"foreach",
"(",
"$",
"languageName",
"as",
"$",
"l",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"lookupTable",
"[",
"$",
"l",
"]",
")",
";",
"$",
"this",
"->",
"unsetDescription",
"(",
"$",
"l",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"unsetDescription",
"(",
"$",
"languageName",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"lookupTable",
"[",
"$",
"languageName",
"]",
")",
";",
"}",
"}"
] | Removes a scanner from the table
@param language_name may be either a string or an array of strings, each of
which will be removed from the lookup table. | [
"Removes",
"a",
"scanner",
"from",
"the",
"table"
] | 4adc18f414534abe986133d6d38e8e9787d32e69 | https://github.com/markwatkinson/luminous/blob/4adc18f414534abe986133d6d38e8e9787d32e69/src/Luminous/Scanners.php#L95-L106 |
13,109 | markwatkinson/luminous | src/Luminous/Scanners.php | Scanners.getScannerArray | private function getScannerArray($languageName, $default = true)
{
$g = null;
if (array_key_exists($languageName, $this->lookupTable)) {
$g = $this->lookupTable[$languageName];
} elseif ($this->defaultScanner !== null && $default === true) {
$g = $this->lookupTable[$this->defaultScanner];
}
if ($g === null) {
return false;
}
return $g;
} | php | private function getScannerArray($languageName, $default = true)
{
$g = null;
if (array_key_exists($languageName, $this->lookupTable)) {
$g = $this->lookupTable[$languageName];
} elseif ($this->defaultScanner !== null && $default === true) {
$g = $this->lookupTable[$this->defaultScanner];
}
if ($g === null) {
return false;
}
return $g;
} | [
"private",
"function",
"getScannerArray",
"(",
"$",
"languageName",
",",
"$",
"default",
"=",
"true",
")",
"{",
"$",
"g",
"=",
"null",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"languageName",
",",
"$",
"this",
"->",
"lookupTable",
")",
")",
"{",
"$",
"g",
"=",
"$",
"this",
"->",
"lookupTable",
"[",
"$",
"languageName",
"]",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"defaultScanner",
"!==",
"null",
"&&",
"$",
"default",
"===",
"true",
")",
"{",
"$",
"g",
"=",
"$",
"this",
"->",
"lookupTable",
"[",
"$",
"this",
"->",
"defaultScanner",
"]",
";",
"}",
"if",
"(",
"$",
"g",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"g",
";",
"}"
] | Method which retrives the desired scanner array, and
recursively settles the include dependencies while doing so.
@param language_name the name under which the gramar was originally indexed
@param default if true: if the scanner doesn't exist, return the default
scanner. If false, return false
@return the scanner-array stored for the given language name
@internal
@see LuminousScanners::GetScanner | [
"Method",
"which",
"retrives",
"the",
"desired",
"scanner",
"array",
"and",
"recursively",
"settles",
"the",
"include",
"dependencies",
"while",
"doing",
"so",
"."
] | 4adc18f414534abe986133d6d38e8e9787d32e69 | https://github.com/markwatkinson/luminous/blob/4adc18f414534abe986133d6d38e8e9787d32e69/src/Luminous/Scanners.php#L128-L142 |
13,110 | markwatkinson/luminous | src/Luminous/Scanners.php | Scanners.getScanner | public function getScanner($languageName, $default = true, $instance = true)
{
$g = $this->getScannerArray($languageName, $default);
if ($g !== false) {
return $instance ? new $g['scanner'] : $g['scanner'];
}
return null;
} | php | public function getScanner($languageName, $default = true, $instance = true)
{
$g = $this->getScannerArray($languageName, $default);
if ($g !== false) {
return $instance ? new $g['scanner'] : $g['scanner'];
}
return null;
} | [
"public",
"function",
"getScanner",
"(",
"$",
"languageName",
",",
"$",
"default",
"=",
"true",
",",
"$",
"instance",
"=",
"true",
")",
"{",
"$",
"g",
"=",
"$",
"this",
"->",
"getScannerArray",
"(",
"$",
"languageName",
",",
"$",
"default",
")",
";",
"if",
"(",
"$",
"g",
"!==",
"false",
")",
"{",
"return",
"$",
"instance",
"?",
"new",
"$",
"g",
"[",
"'scanner'",
"]",
":",
"$",
"g",
"[",
"'scanner'",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Returns a scanner for a language
@param language_name the name under which the gramar was originally indexed
@param default if true: if the scanner doesn't exist, return the default
scanner. If false, return false
@return The scanner, the default scanner, or null. | [
"Returns",
"a",
"scanner",
"for",
"a",
"language"
] | 4adc18f414534abe986133d6d38e8e9787d32e69 | https://github.com/markwatkinson/luminous/blob/4adc18f414534abe986133d6d38e8e9787d32e69/src/Luminous/Scanners.php#L151-L159 |
13,111 | dphn/ScContent | src/ScContent/Controller/Back/CategoryController.php | CategoryController.addAction | public function addAction()
{
$parent = $this->params()->fromRoute('parent');
if (! is_numeric($parent)) {
$this->flashMessenger()->addMessage(
$this->scTranslate('The category location was not specified.')
);
return $this->redirect()
->toRoute('sc-admin/content-manager')
->setStatusCode(303);
}
try {
$categoryId = $this->getCategoryService()->makeCategory($parent);
} catch (RuntimeException $e) {
$this->flashMessenger()->addMessage($e->getMessage());
return $this->redirect()
->toRoute('sc-admin/content-manager')
->setStatusCode(303);
}
return $this->redirect()->toRoute(
'sc-admin/category/edit',
['id' => $categoryId]
);
} | php | public function addAction()
{
$parent = $this->params()->fromRoute('parent');
if (! is_numeric($parent)) {
$this->flashMessenger()->addMessage(
$this->scTranslate('The category location was not specified.')
);
return $this->redirect()
->toRoute('sc-admin/content-manager')
->setStatusCode(303);
}
try {
$categoryId = $this->getCategoryService()->makeCategory($parent);
} catch (RuntimeException $e) {
$this->flashMessenger()->addMessage($e->getMessage());
return $this->redirect()
->toRoute('sc-admin/content-manager')
->setStatusCode(303);
}
return $this->redirect()->toRoute(
'sc-admin/category/edit',
['id' => $categoryId]
);
} | [
"public",
"function",
"addAction",
"(",
")",
"{",
"$",
"parent",
"=",
"$",
"this",
"->",
"params",
"(",
")",
"->",
"fromRoute",
"(",
"'parent'",
")",
";",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"parent",
")",
")",
"{",
"$",
"this",
"->",
"flashMessenger",
"(",
")",
"->",
"addMessage",
"(",
"$",
"this",
"->",
"scTranslate",
"(",
"'The category location was not specified.'",
")",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
")",
"->",
"toRoute",
"(",
"'sc-admin/content-manager'",
")",
"->",
"setStatusCode",
"(",
"303",
")",
";",
"}",
"try",
"{",
"$",
"categoryId",
"=",
"$",
"this",
"->",
"getCategoryService",
"(",
")",
"->",
"makeCategory",
"(",
"$",
"parent",
")",
";",
"}",
"catch",
"(",
"RuntimeException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"flashMessenger",
"(",
")",
"->",
"addMessage",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
")",
"->",
"toRoute",
"(",
"'sc-admin/content-manager'",
")",
"->",
"setStatusCode",
"(",
"303",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
")",
"->",
"toRoute",
"(",
"'sc-admin/category/edit'",
",",
"[",
"'id'",
"=>",
"$",
"categoryId",
"]",
")",
";",
"}"
] | Add Category.
@return \Zend\Stdlib\ResponseInterface | [
"Add",
"Category",
"."
] | 9dd5732490c45fd788b96cedf7b3c7adfacb30d2 | https://github.com/dphn/ScContent/blob/9dd5732490c45fd788b96cedf7b3c7adfacb30d2/src/ScContent/Controller/Back/CategoryController.php#L39-L62 |
13,112 | dphn/ScContent | src/ScContent/Controller/Back/CategoryController.php | CategoryController.editAction | public function editAction()
{
$id = $this->params()->fromRoute('id');
if (! is_numeric($id)) {
$this->flashMessenger()->addMessage(
$this->scTranslate('The category ID was not specified.')
);
return $this->redirect()
->toRoute('sc-admin/content-manager')
->setStatusCode(303);
}
try {
$category = $this->getCategoryService()->getCategory($id);
} catch (RuntimeException $e) {
$this->flashMessenger()->addMessage($e->getMessage());
return $this->redirect()
->toRoute('sc-admin/content-manager')
->setStatusCode(303);
}
$form = $this->getCategoryForm();
$form->setAttribute(
'action',
$this->url()->fromRoute('sc-admin/category/edit', ['id' => $id])
);
$form->bind($category);
if ($this->getRequest()->isPost()) {
$form->setData($this->getRequest()->getPost());
if ($form->isValid()) {
$this->getCategoryService()->saveContent($form->getData());
}
}
return new ViewModel([
'content' => $category,
'form' => $form,
]);
} | php | public function editAction()
{
$id = $this->params()->fromRoute('id');
if (! is_numeric($id)) {
$this->flashMessenger()->addMessage(
$this->scTranslate('The category ID was not specified.')
);
return $this->redirect()
->toRoute('sc-admin/content-manager')
->setStatusCode(303);
}
try {
$category = $this->getCategoryService()->getCategory($id);
} catch (RuntimeException $e) {
$this->flashMessenger()->addMessage($e->getMessage());
return $this->redirect()
->toRoute('sc-admin/content-manager')
->setStatusCode(303);
}
$form = $this->getCategoryForm();
$form->setAttribute(
'action',
$this->url()->fromRoute('sc-admin/category/edit', ['id' => $id])
);
$form->bind($category);
if ($this->getRequest()->isPost()) {
$form->setData($this->getRequest()->getPost());
if ($form->isValid()) {
$this->getCategoryService()->saveContent($form->getData());
}
}
return new ViewModel([
'content' => $category,
'form' => $form,
]);
} | [
"public",
"function",
"editAction",
"(",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"params",
"(",
")",
"->",
"fromRoute",
"(",
"'id'",
")",
";",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"flashMessenger",
"(",
")",
"->",
"addMessage",
"(",
"$",
"this",
"->",
"scTranslate",
"(",
"'The category ID was not specified.'",
")",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
")",
"->",
"toRoute",
"(",
"'sc-admin/content-manager'",
")",
"->",
"setStatusCode",
"(",
"303",
")",
";",
"}",
"try",
"{",
"$",
"category",
"=",
"$",
"this",
"->",
"getCategoryService",
"(",
")",
"->",
"getCategory",
"(",
"$",
"id",
")",
";",
"}",
"catch",
"(",
"RuntimeException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"flashMessenger",
"(",
")",
"->",
"addMessage",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
")",
"->",
"toRoute",
"(",
"'sc-admin/content-manager'",
")",
"->",
"setStatusCode",
"(",
"303",
")",
";",
"}",
"$",
"form",
"=",
"$",
"this",
"->",
"getCategoryForm",
"(",
")",
";",
"$",
"form",
"->",
"setAttribute",
"(",
"'action'",
",",
"$",
"this",
"->",
"url",
"(",
")",
"->",
"fromRoute",
"(",
"'sc-admin/category/edit'",
",",
"[",
"'id'",
"=>",
"$",
"id",
"]",
")",
")",
";",
"$",
"form",
"->",
"bind",
"(",
"$",
"category",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"isPost",
"(",
")",
")",
"{",
"$",
"form",
"->",
"setData",
"(",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"getPost",
"(",
")",
")",
";",
"if",
"(",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"this",
"->",
"getCategoryService",
"(",
")",
"->",
"saveContent",
"(",
"$",
"form",
"->",
"getData",
"(",
")",
")",
";",
"}",
"}",
"return",
"new",
"ViewModel",
"(",
"[",
"'content'",
"=>",
"$",
"category",
",",
"'form'",
"=>",
"$",
"form",
",",
"]",
")",
";",
"}"
] | Edit Category.
@return \Zend\Stdlib\ResponseInterface|\Zend\View\Model\ViewModel | [
"Edit",
"Category",
"."
] | 9dd5732490c45fd788b96cedf7b3c7adfacb30d2 | https://github.com/dphn/ScContent/blob/9dd5732490c45fd788b96cedf7b3c7adfacb30d2/src/ScContent/Controller/Back/CategoryController.php#L69-L107 |
13,113 | dphn/ScContent | src/ScContent/Controller/Back/WidgetVisibilityController.php | WidgetVisibilityController.indexAction | public function indexAction()
{
$visibilityService = $this->getVisibilityService();
$options = $visibilityService->getOptions();
$widgetId = $options->getWidgetId();
if (! $widgetId) {
$this->flashMessenger()->addMessage(
$this->scTranslate('The widget identifier was not specified.')
);
return $this->redirect()
->toRoute('sc-admin/layout')
->setStatusCode(303);
}
$widget = $this->deriveWidget($widgetId);
if (empty($widget)) {
return $this->getResponse();
}
if ($this->getRequest()->isPost()) {
$event = $this->request->getPost('suboperation');
if (! empty($event)) {
$events = $this->getEventManager();
$params = $this->getRequest()->getPost();
$params['widget_id'] = $widget->getId();
$result = $events->trigger($event, $this, $params);
if ($result->last() instanceof Response) {
return $result->last();
}
}
}
$view = new ViewModel;
$view->options = $options;
$view->widget = $widget;
$moduleOptions = $this->getModuleOptions();
$view->config = $moduleOptions->getWidgetByName($widget->getName());
$view->list = $visibilityService->getContentList();
$visibilityService->saveOptions();
return $view;
} | php | public function indexAction()
{
$visibilityService = $this->getVisibilityService();
$options = $visibilityService->getOptions();
$widgetId = $options->getWidgetId();
if (! $widgetId) {
$this->flashMessenger()->addMessage(
$this->scTranslate('The widget identifier was not specified.')
);
return $this->redirect()
->toRoute('sc-admin/layout')
->setStatusCode(303);
}
$widget = $this->deriveWidget($widgetId);
if (empty($widget)) {
return $this->getResponse();
}
if ($this->getRequest()->isPost()) {
$event = $this->request->getPost('suboperation');
if (! empty($event)) {
$events = $this->getEventManager();
$params = $this->getRequest()->getPost();
$params['widget_id'] = $widget->getId();
$result = $events->trigger($event, $this, $params);
if ($result->last() instanceof Response) {
return $result->last();
}
}
}
$view = new ViewModel;
$view->options = $options;
$view->widget = $widget;
$moduleOptions = $this->getModuleOptions();
$view->config = $moduleOptions->getWidgetByName($widget->getName());
$view->list = $visibilityService->getContentList();
$visibilityService->saveOptions();
return $view;
} | [
"public",
"function",
"indexAction",
"(",
")",
"{",
"$",
"visibilityService",
"=",
"$",
"this",
"->",
"getVisibilityService",
"(",
")",
";",
"$",
"options",
"=",
"$",
"visibilityService",
"->",
"getOptions",
"(",
")",
";",
"$",
"widgetId",
"=",
"$",
"options",
"->",
"getWidgetId",
"(",
")",
";",
"if",
"(",
"!",
"$",
"widgetId",
")",
"{",
"$",
"this",
"->",
"flashMessenger",
"(",
")",
"->",
"addMessage",
"(",
"$",
"this",
"->",
"scTranslate",
"(",
"'The widget identifier was not specified.'",
")",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
")",
"->",
"toRoute",
"(",
"'sc-admin/layout'",
")",
"->",
"setStatusCode",
"(",
"303",
")",
";",
"}",
"$",
"widget",
"=",
"$",
"this",
"->",
"deriveWidget",
"(",
"$",
"widgetId",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"widget",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getResponse",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"isPost",
"(",
")",
")",
"{",
"$",
"event",
"=",
"$",
"this",
"->",
"request",
"->",
"getPost",
"(",
"'suboperation'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"event",
")",
")",
"{",
"$",
"events",
"=",
"$",
"this",
"->",
"getEventManager",
"(",
")",
";",
"$",
"params",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"getPost",
"(",
")",
";",
"$",
"params",
"[",
"'widget_id'",
"]",
"=",
"$",
"widget",
"->",
"getId",
"(",
")",
";",
"$",
"result",
"=",
"$",
"events",
"->",
"trigger",
"(",
"$",
"event",
",",
"$",
"this",
",",
"$",
"params",
")",
";",
"if",
"(",
"$",
"result",
"->",
"last",
"(",
")",
"instanceof",
"Response",
")",
"{",
"return",
"$",
"result",
"->",
"last",
"(",
")",
";",
"}",
"}",
"}",
"$",
"view",
"=",
"new",
"ViewModel",
";",
"$",
"view",
"->",
"options",
"=",
"$",
"options",
";",
"$",
"view",
"->",
"widget",
"=",
"$",
"widget",
";",
"$",
"moduleOptions",
"=",
"$",
"this",
"->",
"getModuleOptions",
"(",
")",
";",
"$",
"view",
"->",
"config",
"=",
"$",
"moduleOptions",
"->",
"getWidgetByName",
"(",
"$",
"widget",
"->",
"getName",
"(",
")",
")",
";",
"$",
"view",
"->",
"list",
"=",
"$",
"visibilityService",
"->",
"getContentList",
"(",
")",
";",
"$",
"visibilityService",
"->",
"saveOptions",
"(",
")",
";",
"return",
"$",
"view",
";",
"}"
] | Show content list with widget visibility options.
@return \Zend\Stdlib\ResponseInterface|\Zend\View\Model\ViewModel | [
"Show",
"content",
"list",
"with",
"widget",
"visibility",
"options",
"."
] | 9dd5732490c45fd788b96cedf7b3c7adfacb30d2 | https://github.com/dphn/ScContent/blob/9dd5732490c45fd788b96cedf7b3c7adfacb30d2/src/ScContent/Controller/Back/WidgetVisibilityController.php#L39-L82 |
13,114 | vardius/crud-bundle | Form/FormErrorHandler.php | FormErrorHandler.getErrorMessages | public function getErrorMessages(FormInterface $form, bool $useLabels = false, array $errors = []):array
{
if ($form->count() > 0) {
foreach ($form->all() as $child) {
if (!$child->isValid()) {
$errors = $this->getErrorMessages($child, $useLabels, $errors);
}
}
}
foreach ($form->getErrors() as $error) {
if ($useLabels) {
$fieldNameData = $this->getErrorFormLabel($form);
} else {
$fieldNameData = $this->getErrorFormId($form);
}
$fieldName = $fieldNameData;
if ($useLabels) {
/**
* @ignore
*/
$fieldName = $this->translator->trans($fieldNameData['label'], array(), $fieldNameData['domain']);
}
$errors[$fieldName] = $error->getMessage();
}
return $errors;
} | php | public function getErrorMessages(FormInterface $form, bool $useLabels = false, array $errors = []):array
{
if ($form->count() > 0) {
foreach ($form->all() as $child) {
if (!$child->isValid()) {
$errors = $this->getErrorMessages($child, $useLabels, $errors);
}
}
}
foreach ($form->getErrors() as $error) {
if ($useLabels) {
$fieldNameData = $this->getErrorFormLabel($form);
} else {
$fieldNameData = $this->getErrorFormId($form);
}
$fieldName = $fieldNameData;
if ($useLabels) {
/**
* @ignore
*/
$fieldName = $this->translator->trans($fieldNameData['label'], array(), $fieldNameData['domain']);
}
$errors[$fieldName] = $error->getMessage();
}
return $errors;
} | [
"public",
"function",
"getErrorMessages",
"(",
"FormInterface",
"$",
"form",
",",
"bool",
"$",
"useLabels",
"=",
"false",
",",
"array",
"$",
"errors",
"=",
"[",
"]",
")",
":",
"array",
"{",
"if",
"(",
"$",
"form",
"->",
"count",
"(",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"form",
"->",
"all",
"(",
")",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"!",
"$",
"child",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"errors",
"=",
"$",
"this",
"->",
"getErrorMessages",
"(",
"$",
"child",
",",
"$",
"useLabels",
",",
"$",
"errors",
")",
";",
"}",
"}",
"}",
"foreach",
"(",
"$",
"form",
"->",
"getErrors",
"(",
")",
"as",
"$",
"error",
")",
"{",
"if",
"(",
"$",
"useLabels",
")",
"{",
"$",
"fieldNameData",
"=",
"$",
"this",
"->",
"getErrorFormLabel",
"(",
"$",
"form",
")",
";",
"}",
"else",
"{",
"$",
"fieldNameData",
"=",
"$",
"this",
"->",
"getErrorFormId",
"(",
"$",
"form",
")",
";",
"}",
"$",
"fieldName",
"=",
"$",
"fieldNameData",
";",
"if",
"(",
"$",
"useLabels",
")",
"{",
"/**\n * @ignore\n */",
"$",
"fieldName",
"=",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"$",
"fieldNameData",
"[",
"'label'",
"]",
",",
"array",
"(",
")",
",",
"$",
"fieldNameData",
"[",
"'domain'",
"]",
")",
";",
"}",
"$",
"errors",
"[",
"$",
"fieldName",
"]",
"=",
"$",
"error",
"->",
"getMessage",
"(",
")",
";",
"}",
"return",
"$",
"errors",
";",
"}"
] | Returns an array with form fields errors
@param FormInterface $form
@param bool $useLabels
@param array $errors
@return array | [
"Returns",
"an",
"array",
"with",
"form",
"fields",
"errors"
] | dda957e3f8516c3b0d6270ea5a6eb50d98e71444 | https://github.com/vardius/crud-bundle/blob/dda957e3f8516c3b0d6270ea5a6eb50d98e71444/Form/FormErrorHandler.php#L42-L72 |
13,115 | vardius/crud-bundle | Form/FormErrorHandler.php | FormErrorHandler.getErrorFormLabel | protected function getErrorFormLabel(FormInterface $form):array
{
$vars = $form->createView()->vars;
$label = $vars['label'];
$translationDomain = $vars['translation_domain'];
$result = array(
'label' => $label,
'domain' => $translationDomain,
);
if (empty($label)) {
if ($form->getParent() !== null) {
$result = $this->getErrorFormLabel($form->getParent());
}
}
return $result;
} | php | protected function getErrorFormLabel(FormInterface $form):array
{
$vars = $form->createView()->vars;
$label = $vars['label'];
$translationDomain = $vars['translation_domain'];
$result = array(
'label' => $label,
'domain' => $translationDomain,
);
if (empty($label)) {
if ($form->getParent() !== null) {
$result = $this->getErrorFormLabel($form->getParent());
}
}
return $result;
} | [
"protected",
"function",
"getErrorFormLabel",
"(",
"FormInterface",
"$",
"form",
")",
":",
"array",
"{",
"$",
"vars",
"=",
"$",
"form",
"->",
"createView",
"(",
")",
"->",
"vars",
";",
"$",
"label",
"=",
"$",
"vars",
"[",
"'label'",
"]",
";",
"$",
"translationDomain",
"=",
"$",
"vars",
"[",
"'translation_domain'",
"]",
";",
"$",
"result",
"=",
"array",
"(",
"'label'",
"=>",
"$",
"label",
",",
"'domain'",
"=>",
"$",
"translationDomain",
",",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"label",
")",
")",
"{",
"if",
"(",
"$",
"form",
"->",
"getParent",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getErrorFormLabel",
"(",
"$",
"form",
"->",
"getParent",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns first label for field with error
@param FormInterface $form
@return array | [
"Returns",
"first",
"label",
"for",
"field",
"with",
"error"
] | dda957e3f8516c3b0d6270ea5a6eb50d98e71444 | https://github.com/vardius/crud-bundle/blob/dda957e3f8516c3b0d6270ea5a6eb50d98e71444/Form/FormErrorHandler.php#L80-L99 |
13,116 | DevGroup-ru/yii2-data-structure-tools | src/helpers/PropertiesHelper.php | PropertiesHelper.applicablePropertyModelId | public static function applicablePropertyModelId($class, $forceRefresh = false)
{
//ability to store properties of all model heirs in the one set of tables
if (true === method_exists($class, 'getApplicableClass')) {
$modelClass = call_user_func([$class, 'getApplicableClass']);
} else {
$modelClass = is_string($class) ? $class : get_class($class);
}
self::retrieveApplicablePropertyModels($forceRefresh);
if (isset(self::$applicablePropertyModels[$modelClass])) {
return self::$applicablePropertyModels[$modelClass];
} else {
throw new Exception('Property group model record not found for class: ' . $modelClass);
}
} | php | public static function applicablePropertyModelId($class, $forceRefresh = false)
{
//ability to store properties of all model heirs in the one set of tables
if (true === method_exists($class, 'getApplicableClass')) {
$modelClass = call_user_func([$class, 'getApplicableClass']);
} else {
$modelClass = is_string($class) ? $class : get_class($class);
}
self::retrieveApplicablePropertyModels($forceRefresh);
if (isset(self::$applicablePropertyModels[$modelClass])) {
return self::$applicablePropertyModels[$modelClass];
} else {
throw new Exception('Property group model record not found for class: ' . $modelClass);
}
} | [
"public",
"static",
"function",
"applicablePropertyModelId",
"(",
"$",
"class",
",",
"$",
"forceRefresh",
"=",
"false",
")",
"{",
"//ability to store properties of all model heirs in the one set of tables",
"if",
"(",
"true",
"===",
"method_exists",
"(",
"$",
"class",
",",
"'getApplicableClass'",
")",
")",
"{",
"$",
"modelClass",
"=",
"call_user_func",
"(",
"[",
"$",
"class",
",",
"'getApplicableClass'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"modelClass",
"=",
"is_string",
"(",
"$",
"class",
")",
"?",
"$",
"class",
":",
"get_class",
"(",
"$",
"class",
")",
";",
"}",
"self",
"::",
"retrieveApplicablePropertyModels",
"(",
"$",
"forceRefresh",
")",
";",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"applicablePropertyModels",
"[",
"$",
"modelClass",
"]",
")",
")",
"{",
"return",
"self",
"::",
"$",
"applicablePropertyModels",
"[",
"$",
"modelClass",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"'Property group model record not found for class: '",
".",
"$",
"modelClass",
")",
";",
"}",
"}"
] | Returns id of property_group_models record for requested classname
@param ActiveRecord | string $class
@param bool|false $forceRefresh
@return integer
@throws \yii\base\Exception | [
"Returns",
"id",
"of",
"property_group_models",
"record",
"for",
"requested",
"classname"
] | a5b24d7c0b24d4b0d58cacd91ec7fd876e979097 | https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/helpers/PropertiesHelper.php#L79-L94 |
13,117 | DevGroup-ru/yii2-data-structure-tools | src/helpers/PropertiesHelper.php | PropertiesHelper.classNameForApplicablePropertyModelId | public static function classNameForApplicablePropertyModelId($id, $forceRefresh = false)
{
self::retrieveApplicablePropertyModels($forceRefresh);
return array_search($id, self::$applicablePropertyModels, true);
} | php | public static function classNameForApplicablePropertyModelId($id, $forceRefresh = false)
{
self::retrieveApplicablePropertyModels($forceRefresh);
return array_search($id, self::$applicablePropertyModels, true);
} | [
"public",
"static",
"function",
"classNameForApplicablePropertyModelId",
"(",
"$",
"id",
",",
"$",
"forceRefresh",
"=",
"false",
")",
"{",
"self",
"::",
"retrieveApplicablePropertyModels",
"(",
"$",
"forceRefresh",
")",
";",
"return",
"array_search",
"(",
"$",
"id",
",",
"self",
"::",
"$",
"applicablePropertyModels",
",",
"true",
")",
";",
"}"
] | Returns class name of Model for which property or property_group model record is associated
@param string $id
@param bool|false $forceRefresh
@return string|false | [
"Returns",
"class",
"name",
"of",
"Model",
"for",
"which",
"property",
"or",
"property_group",
"model",
"record",
"is",
"associated"
] | a5b24d7c0b24d4b0d58cacd91ec7fd876e979097 | https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/helpers/PropertiesHelper.php#L104-L108 |
13,118 | DevGroup-ru/yii2-data-structure-tools | src/helpers/PropertiesHelper.php | PropertiesHelper.generateCacheKey | public static function generateCacheKey($models, $postfix = 'properties')
{
$ids = ArrayHelper::getColumn($models, 'id', false);
sort($ids);
/** @var \yii\db\ActiveRecord $first */
$first = reset($models);
return $first::tableName() . ':' . implode(',', $ids) . "-$postfix";
} | php | public static function generateCacheKey($models, $postfix = 'properties')
{
$ids = ArrayHelper::getColumn($models, 'id', false);
sort($ids);
/** @var \yii\db\ActiveRecord $first */
$first = reset($models);
return $first::tableName() . ':' . implode(',', $ids) . "-$postfix";
} | [
"public",
"static",
"function",
"generateCacheKey",
"(",
"$",
"models",
",",
"$",
"postfix",
"=",
"'properties'",
")",
"{",
"$",
"ids",
"=",
"ArrayHelper",
"::",
"getColumn",
"(",
"$",
"models",
",",
"'id'",
",",
"false",
")",
";",
"sort",
"(",
"$",
"ids",
")",
";",
"/** @var \\yii\\db\\ActiveRecord $first */",
"$",
"first",
"=",
"reset",
"(",
"$",
"models",
")",
";",
"return",
"$",
"first",
"::",
"tableName",
"(",
")",
".",
"':'",
".",
"implode",
"(",
"','",
",",
"$",
"ids",
")",
".",
"\"-$postfix\"",
";",
"}"
] | Generates cache key based on models array, model table name and postfix
@param \yii\db\ActiveRecord[] $models
@param string $postfix
@return string | [
"Generates",
"cache",
"key",
"based",
"on",
"models",
"array",
"model",
"table",
"name",
"and",
"postfix"
] | a5b24d7c0b24d4b0d58cacd91ec7fd876e979097 | https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/helpers/PropertiesHelper.php#L167-L174 |
13,119 | DevGroup-ru/yii2-data-structure-tools | src/helpers/PropertiesHelper.php | PropertiesHelper.getAvailablePropertyGroupsList | public static function getAvailablePropertyGroupsList($className)
{
$applicablePropertyModelId = PropertiesHelper::applicablePropertyModelId($className);
$availableGroups = Yii::$app->cache->lazy(
function () use ($applicablePropertyModelId) {
return ArrayHelper::map(
PropertyGroup::find()->where(
['applicable_property_model_id' => $applicablePropertyModelId]
)->orderBy('sort_order ASC')->all(),
'id',
function ($model) {
return !empty($model->name) ? $model->name : $model->internal_name;
}
);
},
'AvailablePropertyGroupsList: ' . $applicablePropertyModelId,
86400,
PropertyGroup::commonTag()
);
return $availableGroups;
} | php | public static function getAvailablePropertyGroupsList($className)
{
$applicablePropertyModelId = PropertiesHelper::applicablePropertyModelId($className);
$availableGroups = Yii::$app->cache->lazy(
function () use ($applicablePropertyModelId) {
return ArrayHelper::map(
PropertyGroup::find()->where(
['applicable_property_model_id' => $applicablePropertyModelId]
)->orderBy('sort_order ASC')->all(),
'id',
function ($model) {
return !empty($model->name) ? $model->name : $model->internal_name;
}
);
},
'AvailablePropertyGroupsList: ' . $applicablePropertyModelId,
86400,
PropertyGroup::commonTag()
);
return $availableGroups;
} | [
"public",
"static",
"function",
"getAvailablePropertyGroupsList",
"(",
"$",
"className",
")",
"{",
"$",
"applicablePropertyModelId",
"=",
"PropertiesHelper",
"::",
"applicablePropertyModelId",
"(",
"$",
"className",
")",
";",
"$",
"availableGroups",
"=",
"Yii",
"::",
"$",
"app",
"->",
"cache",
"->",
"lazy",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"applicablePropertyModelId",
")",
"{",
"return",
"ArrayHelper",
"::",
"map",
"(",
"PropertyGroup",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'applicable_property_model_id'",
"=>",
"$",
"applicablePropertyModelId",
"]",
")",
"->",
"orderBy",
"(",
"'sort_order ASC'",
")",
"->",
"all",
"(",
")",
",",
"'id'",
",",
"function",
"(",
"$",
"model",
")",
"{",
"return",
"!",
"empty",
"(",
"$",
"model",
"->",
"name",
")",
"?",
"$",
"model",
"->",
"name",
":",
"$",
"model",
"->",
"internal_name",
";",
"}",
")",
";",
"}",
",",
"'AvailablePropertyGroupsList: '",
".",
"$",
"applicablePropertyModelId",
",",
"86400",
",",
"PropertyGroup",
"::",
"commonTag",
"(",
")",
")",
";",
"return",
"$",
"availableGroups",
";",
"}"
] | Get available property groups by class name.
@param string $className
@return array
@throws Exception | [
"Get",
"available",
"property",
"groups",
"by",
"class",
"name",
"."
] | a5b24d7c0b24d4b0d58cacd91ec7fd876e979097 | https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/helpers/PropertiesHelper.php#L432-L453 |
13,120 | mimmi20/Wurfl | src/Handlers/Chain/UserAgentHandlerChain.php | UserAgentHandlerChain.match | public function match(GenericRequest $request)
{
Utils::reset();
$handlers = $this->getHandlers();
$matchResult = WurflConstants::NO_MATCH;
foreach ($handlers as $handler) {
/** @var $handler \Wurfl\Handlers\AbstractHandler */
$handler->setLogger($this->logger);
if ($handler->canHandle($request->getUserAgentNormalized())) {
$matchResult = $handler->applyMatch($request);
break;
}
}
return $matchResult;
} | php | public function match(GenericRequest $request)
{
Utils::reset();
$handlers = $this->getHandlers();
$matchResult = WurflConstants::NO_MATCH;
foreach ($handlers as $handler) {
/** @var $handler \Wurfl\Handlers\AbstractHandler */
$handler->setLogger($this->logger);
if ($handler->canHandle($request->getUserAgentNormalized())) {
$matchResult = $handler->applyMatch($request);
break;
}
}
return $matchResult;
} | [
"public",
"function",
"match",
"(",
"GenericRequest",
"$",
"request",
")",
"{",
"Utils",
"::",
"reset",
"(",
")",
";",
"$",
"handlers",
"=",
"$",
"this",
"->",
"getHandlers",
"(",
")",
";",
"$",
"matchResult",
"=",
"WurflConstants",
"::",
"NO_MATCH",
";",
"foreach",
"(",
"$",
"handlers",
"as",
"$",
"handler",
")",
"{",
"/** @var $handler \\Wurfl\\Handlers\\AbstractHandler */",
"$",
"handler",
"->",
"setLogger",
"(",
"$",
"this",
"->",
"logger",
")",
";",
"if",
"(",
"$",
"handler",
"->",
"canHandle",
"(",
"$",
"request",
"->",
"getUserAgentNormalized",
"(",
")",
")",
")",
"{",
"$",
"matchResult",
"=",
"$",
"handler",
"->",
"applyMatch",
"(",
"$",
"request",
")",
";",
"break",
";",
"}",
"}",
"return",
"$",
"matchResult",
";",
"}"
] | Return the the device id for the request
@param \Wurfl\Request\GenericRequest $request
@return string deviceID | [
"Return",
"the",
"the",
"device",
"id",
"for",
"the",
"request"
] | 443ed0d73a0b9a21ebd0d6ddf1e32669b9de44ec | https://github.com/mimmi20/Wurfl/blob/443ed0d73a0b9a21ebd0d6ddf1e32669b9de44ec/src/Handlers/Chain/UserAgentHandlerChain.php#L108-L126 |
13,121 | mimmi20/Wurfl | src/Handlers/Chain/UserAgentHandlerChain.php | UserAgentHandlerChain.persistData | public function persistData()
{
$handlers = $this->getHandlers();
foreach ($handlers as $handler) {
/** @var $handler \Wurfl\Handlers\AbstractHandler */
$handler->setLogger($this->logger);
$handler->persistData();
}
} | php | public function persistData()
{
$handlers = $this->getHandlers();
foreach ($handlers as $handler) {
/** @var $handler \Wurfl\Handlers\AbstractHandler */
$handler->setLogger($this->logger);
$handler->persistData();
}
} | [
"public",
"function",
"persistData",
"(",
")",
"{",
"$",
"handlers",
"=",
"$",
"this",
"->",
"getHandlers",
"(",
")",
";",
"foreach",
"(",
"$",
"handlers",
"as",
"$",
"handler",
")",
"{",
"/** @var $handler \\Wurfl\\Handlers\\AbstractHandler */",
"$",
"handler",
"->",
"setLogger",
"(",
"$",
"this",
"->",
"logger",
")",
";",
"$",
"handler",
"->",
"persistData",
"(",
")",
";",
"}",
"}"
] | Save the data from each \Wurfl\Handlers\AbstractHandler
@see \Wurfl\Handlers\AbstractHandler::persistData() | [
"Save",
"the",
"data",
"from",
"each",
"\\",
"Wurfl",
"\\",
"Handlers",
"\\",
"AbstractHandler"
] | 443ed0d73a0b9a21ebd0d6ddf1e32669b9de44ec | https://github.com/mimmi20/Wurfl/blob/443ed0d73a0b9a21ebd0d6ddf1e32669b9de44ec/src/Handlers/Chain/UserAgentHandlerChain.php#L133-L143 |
13,122 | todstoychev/icr | src/Manipulator/ManipulatorFactory.php | ManipulatorFactory.create | public function create($operation)
{
if (!is_string($operation)) {
throw new \LogicException("Provided manipulation name {$operation} is not a string!");
}
$operation = str_replace('-', ' ', $operation);
$operation = strtolower($operation);
$operation = ucwords($operation);
$operation = str_replace(' ', '', $operation);
$className = "Todstoychev\\Icr\\Manipulator\\" . $operation;
if (!class_exists($className)) {
throw new IcrRuntimeException("Operation {$operation} does not exists!");
}
return new $className($this->box, $this->point);
} | php | public function create($operation)
{
if (!is_string($operation)) {
throw new \LogicException("Provided manipulation name {$operation} is not a string!");
}
$operation = str_replace('-', ' ', $operation);
$operation = strtolower($operation);
$operation = ucwords($operation);
$operation = str_replace(' ', '', $operation);
$className = "Todstoychev\\Icr\\Manipulator\\" . $operation;
if (!class_exists($className)) {
throw new IcrRuntimeException("Operation {$operation} does not exists!");
}
return new $className($this->box, $this->point);
} | [
"public",
"function",
"create",
"(",
"$",
"operation",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"operation",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"\"Provided manipulation name {$operation} is not a string!\"",
")",
";",
"}",
"$",
"operation",
"=",
"str_replace",
"(",
"'-'",
",",
"' '",
",",
"$",
"operation",
")",
";",
"$",
"operation",
"=",
"strtolower",
"(",
"$",
"operation",
")",
";",
"$",
"operation",
"=",
"ucwords",
"(",
"$",
"operation",
")",
";",
"$",
"operation",
"=",
"str_replace",
"(",
"' '",
",",
"''",
",",
"$",
"operation",
")",
";",
"$",
"className",
"=",
"\"Todstoychev\\\\Icr\\\\Manipulator\\\\\"",
".",
"$",
"operation",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"throw",
"new",
"IcrRuntimeException",
"(",
"\"Operation {$operation} does not exists!\"",
")",
";",
"}",
"return",
"new",
"$",
"className",
"(",
"$",
"this",
"->",
"box",
",",
"$",
"this",
"->",
"point",
")",
";",
"}"
] | Creates manipulation instance
@param string $operation Operation name
@return mixed | [
"Creates",
"manipulation",
"instance"
] | 0214c7bc76e44488e98758d55deb707b72e24000 | https://github.com/todstoychev/icr/blob/0214c7bc76e44488e98758d55deb707b72e24000/src/Manipulator/ManipulatorFactory.php#L43-L61 |
13,123 | rinvex/renamed-tenants | src/Models/Tenant.php | Tenant.scopeOfOwner | public function scopeOfOwner(Builder $builder, Model $owner): Builder
{
return $builder->where('owner_type', $owner->getMorphClass())->where('owner_id', $owner->getKey());
} | php | public function scopeOfOwner(Builder $builder, Model $owner): Builder
{
return $builder->where('owner_type', $owner->getMorphClass())->where('owner_id', $owner->getKey());
} | [
"public",
"function",
"scopeOfOwner",
"(",
"Builder",
"$",
"builder",
",",
"Model",
"$",
"owner",
")",
":",
"Builder",
"{",
"return",
"$",
"builder",
"->",
"where",
"(",
"'owner_type'",
",",
"$",
"owner",
"->",
"getMorphClass",
"(",
")",
")",
"->",
"where",
"(",
"'owner_id'",
",",
"$",
"owner",
"->",
"getKey",
"(",
")",
")",
";",
"}"
] | Get tenants of the given owner.
@param \Illuminate\Database\Eloquent\Builder $builder
@param \Illuminate\Database\Eloquent\Model $owner
@return \Illuminate\Database\Eloquent\Builder | [
"Get",
"tenants",
"of",
"the",
"given",
"owner",
"."
] | 2608656011a55547909251f3667699e1932cfc28 | https://github.com/rinvex/renamed-tenants/blob/2608656011a55547909251f3667699e1932cfc28/src/Models/Tenant.php#L255-L258 |
13,124 | wshafer/assetmanager-core | src/Service/AssetFilterManager.php | AssetFilterManager.getFilters | protected function getFilters($path, AssetInterface $asset)
{
$config = $this->getConfig();
if (!empty($config[$path])) {
return $config[$path];
}
if (!empty($asset->mimetype) && !empty($config[$asset->mimetype])) {
return $config[$asset->mimetype];
}
$extension = strtolower(pathinfo($asset->getSourcePath(), PATHINFO_EXTENSION));
if (!empty($config[$extension])) {
return $config[$extension];
}
return [];
} | php | protected function getFilters($path, AssetInterface $asset)
{
$config = $this->getConfig();
if (!empty($config[$path])) {
return $config[$path];
}
if (!empty($asset->mimetype) && !empty($config[$asset->mimetype])) {
return $config[$asset->mimetype];
}
$extension = strtolower(pathinfo($asset->getSourcePath(), PATHINFO_EXTENSION));
if (!empty($config[$extension])) {
return $config[$extension];
}
return [];
} | [
"protected",
"function",
"getFilters",
"(",
"$",
"path",
",",
"AssetInterface",
"$",
"asset",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"config",
"[",
"$",
"path",
"]",
")",
")",
"{",
"return",
"$",
"config",
"[",
"$",
"path",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"asset",
"->",
"mimetype",
")",
"&&",
"!",
"empty",
"(",
"$",
"config",
"[",
"$",
"asset",
"->",
"mimetype",
"]",
")",
")",
"{",
"return",
"$",
"config",
"[",
"$",
"asset",
"->",
"mimetype",
"]",
";",
"}",
"$",
"extension",
"=",
"strtolower",
"(",
"pathinfo",
"(",
"$",
"asset",
"->",
"getSourcePath",
"(",
")",
",",
"PATHINFO_EXTENSION",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"config",
"[",
"$",
"extension",
"]",
")",
")",
"{",
"return",
"$",
"config",
"[",
"$",
"extension",
"]",
";",
"}",
"return",
"[",
"]",
";",
"}"
] | Get the filters from config based on path, mimetype or extension.
@param string $path
@param AssetInterface $asset
@return array|mixed | [
"Get",
"the",
"filters",
"from",
"config",
"based",
"on",
"path",
"mimetype",
"or",
"extension",
"."
] | b1bf9b3ab3b28f847fbe3f57d6c2c32b98c1431d | https://github.com/wshafer/assetmanager-core/blob/b1bf9b3ab3b28f847fbe3f57d6c2c32b98c1431d/src/Service/AssetFilterManager.php#L83-L102 |
13,125 | wshafer/assetmanager-core | src/Service/AssetFilterManager.php | AssetFilterManager.setFilter | protected function setFilter($filter, AssetInterface $asset)
{
if (is_null($filter)) {
return;
}
if (!empty($filter['filter'])) {
$this->ensureByFilter($asset, $filter['filter']);
return;
}
if (!empty($filter['service'])) {
$this->ensureByService($asset, $filter['service']);
return;
}
throw new Exception\RuntimeException(
'Invalid filter supplied. Expected Filter or Service.'
);
} | php | protected function setFilter($filter, AssetInterface $asset)
{
if (is_null($filter)) {
return;
}
if (!empty($filter['filter'])) {
$this->ensureByFilter($asset, $filter['filter']);
return;
}
if (!empty($filter['service'])) {
$this->ensureByService($asset, $filter['service']);
return;
}
throw new Exception\RuntimeException(
'Invalid filter supplied. Expected Filter or Service.'
);
} | [
"protected",
"function",
"setFilter",
"(",
"$",
"filter",
",",
"AssetInterface",
"$",
"asset",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"filter",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"filter",
"[",
"'filter'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"ensureByFilter",
"(",
"$",
"asset",
",",
"$",
"filter",
"[",
"'filter'",
"]",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"filter",
"[",
"'service'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"ensureByService",
"(",
"$",
"asset",
",",
"$",
"filter",
"[",
"'service'",
"]",
")",
";",
"return",
";",
"}",
"throw",
"new",
"Exception",
"\\",
"RuntimeException",
"(",
"'Invalid filter supplied. Expected Filter or Service.'",
")",
";",
"}"
] | Set the filter by filter or service
@param string $filter
@param AssetInterface $asset | [
"Set",
"the",
"filter",
"by",
"filter",
"or",
"service"
] | b1bf9b3ab3b28f847fbe3f57d6c2c32b98c1431d | https://github.com/wshafer/assetmanager-core/blob/b1bf9b3ab3b28f847fbe3f57d6c2c32b98c1431d/src/Service/AssetFilterManager.php#L110-L131 |
13,126 | GrupaZero/vanilla-integration | src/Gzero/Vanilla/VanillaController.php | VanillaController.index | public function index(Request $request)
{
$referrerDomain = parse_url($request->server('HTTP_REFERER'), PHP_URL_HOST);
if ($referrerDomain !== $this->config->get('vanilla-integration.forum_domain')) {
return app()->abort(404);
}
if (class_exists('Debugbar')) {
\Debugbar::disable();
}
$clientID = $this->config->get('vanilla-integration.client_id');
$secret = $this->config->get('vanilla-integration.secret');
$user = [];
if ($this->auth->check()) {
$currentUser = $this->auth->user();
$user['uniqueid'] = $currentUser->id;
$user['name'] = $currentUser->getPresenter()->displayName();
$user['email'] = $currentUser->email;
}
// Generate the jsConnect string.
// This should be true unless you are testing.
// You can also use a hash name like md5, sha1 etc which must be the name as the connection settings in Vanilla.
$secure = true;
WriteJsConnect($user, $request->only(['client_id', 'signature', 'callback', 'timestamp']), $clientID, $secret, $secure);
return response('')->header('Content-Type', 'application/javascript');
} | php | public function index(Request $request)
{
$referrerDomain = parse_url($request->server('HTTP_REFERER'), PHP_URL_HOST);
if ($referrerDomain !== $this->config->get('vanilla-integration.forum_domain')) {
return app()->abort(404);
}
if (class_exists('Debugbar')) {
\Debugbar::disable();
}
$clientID = $this->config->get('vanilla-integration.client_id');
$secret = $this->config->get('vanilla-integration.secret');
$user = [];
if ($this->auth->check()) {
$currentUser = $this->auth->user();
$user['uniqueid'] = $currentUser->id;
$user['name'] = $currentUser->getPresenter()->displayName();
$user['email'] = $currentUser->email;
}
// Generate the jsConnect string.
// This should be true unless you are testing.
// You can also use a hash name like md5, sha1 etc which must be the name as the connection settings in Vanilla.
$secure = true;
WriteJsConnect($user, $request->only(['client_id', 'signature', 'callback', 'timestamp']), $clientID, $secret, $secure);
return response('')->header('Content-Type', 'application/javascript');
} | [
"public",
"function",
"index",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"referrerDomain",
"=",
"parse_url",
"(",
"$",
"request",
"->",
"server",
"(",
"'HTTP_REFERER'",
")",
",",
"PHP_URL_HOST",
")",
";",
"if",
"(",
"$",
"referrerDomain",
"!==",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'vanilla-integration.forum_domain'",
")",
")",
"{",
"return",
"app",
"(",
")",
"->",
"abort",
"(",
"404",
")",
";",
"}",
"if",
"(",
"class_exists",
"(",
"'Debugbar'",
")",
")",
"{",
"\\",
"Debugbar",
"::",
"disable",
"(",
")",
";",
"}",
"$",
"clientID",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'vanilla-integration.client_id'",
")",
";",
"$",
"secret",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'vanilla-integration.secret'",
")",
";",
"$",
"user",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"auth",
"->",
"check",
"(",
")",
")",
"{",
"$",
"currentUser",
"=",
"$",
"this",
"->",
"auth",
"->",
"user",
"(",
")",
";",
"$",
"user",
"[",
"'uniqueid'",
"]",
"=",
"$",
"currentUser",
"->",
"id",
";",
"$",
"user",
"[",
"'name'",
"]",
"=",
"$",
"currentUser",
"->",
"getPresenter",
"(",
")",
"->",
"displayName",
"(",
")",
";",
"$",
"user",
"[",
"'email'",
"]",
"=",
"$",
"currentUser",
"->",
"email",
";",
"}",
"// Generate the jsConnect string.",
"// This should be true unless you are testing.",
"// You can also use a hash name like md5, sha1 etc which must be the name as the connection settings in Vanilla.",
"$",
"secure",
"=",
"true",
";",
"WriteJsConnect",
"(",
"$",
"user",
",",
"$",
"request",
"->",
"only",
"(",
"[",
"'client_id'",
",",
"'signature'",
",",
"'callback'",
",",
"'timestamp'",
"]",
")",
",",
"$",
"clientID",
",",
"$",
"secret",
",",
"$",
"secure",
")",
";",
"return",
"response",
"(",
"''",
")",
"->",
"header",
"(",
"'Content-Type'",
",",
"'application/javascript'",
")",
";",
"}"
] | Connect method. It's returning JSONP response
@param Request $request
@return string | [
"Connect",
"method",
".",
"It",
"s",
"returning",
"JSONP",
"response"
] | b65f67e2db8021d59f568e918c6da7fc52655a01 | https://github.com/GrupaZero/vanilla-integration/blob/b65f67e2db8021d59f568e918c6da7fc52655a01/src/Gzero/Vanilla/VanillaController.php#L47-L74 |
13,127 | nyeholt/silverstripe-simplewiki | thirdparty/htmlpurifier-4.0.0-lite/library/HTMLPurifier/Encoder.php | HTMLPurifier_Encoder.convertToUTF8 | public static function convertToUTF8($str, $config, $context) {
$encoding = $config->get('Core.Encoding');
if ($encoding === 'utf-8') return $str;
static $iconv = null;
if ($iconv === null) $iconv = function_exists('iconv');
set_error_handler(array('HTMLPurifier_Encoder', 'muteErrorHandler'));
if ($iconv && !$config->get('Test.ForceNoIconv')) {
$str = iconv($encoding, 'utf-8//IGNORE', $str);
if ($str === false) {
// $encoding is not a valid encoding
restore_error_handler();
trigger_error('Invalid encoding ' . $encoding, E_USER_ERROR);
return '';
}
// If the string is bjorked by Shift_JIS or a similar encoding
// that doesn't support all of ASCII, convert the naughty
// characters to their true byte-wise ASCII/UTF-8 equivalents.
$str = strtr($str, HTMLPurifier_Encoder::testEncodingSupportsASCII($encoding));
restore_error_handler();
return $str;
} elseif ($encoding === 'iso-8859-1') {
$str = utf8_encode($str);
restore_error_handler();
return $str;
}
trigger_error('Encoding not supported, please install iconv', E_USER_ERROR);
} | php | public static function convertToUTF8($str, $config, $context) {
$encoding = $config->get('Core.Encoding');
if ($encoding === 'utf-8') return $str;
static $iconv = null;
if ($iconv === null) $iconv = function_exists('iconv');
set_error_handler(array('HTMLPurifier_Encoder', 'muteErrorHandler'));
if ($iconv && !$config->get('Test.ForceNoIconv')) {
$str = iconv($encoding, 'utf-8//IGNORE', $str);
if ($str === false) {
// $encoding is not a valid encoding
restore_error_handler();
trigger_error('Invalid encoding ' . $encoding, E_USER_ERROR);
return '';
}
// If the string is bjorked by Shift_JIS or a similar encoding
// that doesn't support all of ASCII, convert the naughty
// characters to their true byte-wise ASCII/UTF-8 equivalents.
$str = strtr($str, HTMLPurifier_Encoder::testEncodingSupportsASCII($encoding));
restore_error_handler();
return $str;
} elseif ($encoding === 'iso-8859-1') {
$str = utf8_encode($str);
restore_error_handler();
return $str;
}
trigger_error('Encoding not supported, please install iconv', E_USER_ERROR);
} | [
"public",
"static",
"function",
"convertToUTF8",
"(",
"$",
"str",
",",
"$",
"config",
",",
"$",
"context",
")",
"{",
"$",
"encoding",
"=",
"$",
"config",
"->",
"get",
"(",
"'Core.Encoding'",
")",
";",
"if",
"(",
"$",
"encoding",
"===",
"'utf-8'",
")",
"return",
"$",
"str",
";",
"static",
"$",
"iconv",
"=",
"null",
";",
"if",
"(",
"$",
"iconv",
"===",
"null",
")",
"$",
"iconv",
"=",
"function_exists",
"(",
"'iconv'",
")",
";",
"set_error_handler",
"(",
"array",
"(",
"'HTMLPurifier_Encoder'",
",",
"'muteErrorHandler'",
")",
")",
";",
"if",
"(",
"$",
"iconv",
"&&",
"!",
"$",
"config",
"->",
"get",
"(",
"'Test.ForceNoIconv'",
")",
")",
"{",
"$",
"str",
"=",
"iconv",
"(",
"$",
"encoding",
",",
"'utf-8//IGNORE'",
",",
"$",
"str",
")",
";",
"if",
"(",
"$",
"str",
"===",
"false",
")",
"{",
"// $encoding is not a valid encoding",
"restore_error_handler",
"(",
")",
";",
"trigger_error",
"(",
"'Invalid encoding '",
".",
"$",
"encoding",
",",
"E_USER_ERROR",
")",
";",
"return",
"''",
";",
"}",
"// If the string is bjorked by Shift_JIS or a similar encoding",
"// that doesn't support all of ASCII, convert the naughty",
"// characters to their true byte-wise ASCII/UTF-8 equivalents.",
"$",
"str",
"=",
"strtr",
"(",
"$",
"str",
",",
"HTMLPurifier_Encoder",
"::",
"testEncodingSupportsASCII",
"(",
"$",
"encoding",
")",
")",
";",
"restore_error_handler",
"(",
")",
";",
"return",
"$",
"str",
";",
"}",
"elseif",
"(",
"$",
"encoding",
"===",
"'iso-8859-1'",
")",
"{",
"$",
"str",
"=",
"utf8_encode",
"(",
"$",
"str",
")",
";",
"restore_error_handler",
"(",
")",
";",
"return",
"$",
"str",
";",
"}",
"trigger_error",
"(",
"'Encoding not supported, please install iconv'",
",",
"E_USER_ERROR",
")",
";",
"}"
] | Converts a string to UTF-8 based on configuration. | [
"Converts",
"a",
"string",
"to",
"UTF",
"-",
"8",
"based",
"on",
"configuration",
"."
] | ecffed0d75be1454901e1cb24633472b8f67c967 | https://github.com/nyeholt/silverstripe-simplewiki/blob/ecffed0d75be1454901e1cb24633472b8f67c967/thirdparty/htmlpurifier-4.0.0-lite/library/HTMLPurifier/Encoder.php#L266-L292 |
13,128 | Webklex/translator | src/Translator/Translator.php | Translator.all | public function all($locale = null){
if(!$locale){
$locale = $this->getLocale();
}
$this->load($locale);
$translations = collect([]);
foreach($this->languages[$locale] as $key => $arg){
$translations->put($key, $arg['value']);
}
return $translations;
} | php | public function all($locale = null){
if(!$locale){
$locale = $this->getLocale();
}
$this->load($locale);
$translations = collect([]);
foreach($this->languages[$locale] as $key => $arg){
$translations->put($key, $arg['value']);
}
return $translations;
} | [
"public",
"function",
"all",
"(",
"$",
"locale",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"locale",
")",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"getLocale",
"(",
")",
";",
"}",
"$",
"this",
"->",
"load",
"(",
"$",
"locale",
")",
";",
"$",
"translations",
"=",
"collect",
"(",
"[",
"]",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"languages",
"[",
"$",
"locale",
"]",
"as",
"$",
"key",
"=>",
"$",
"arg",
")",
"{",
"$",
"translations",
"->",
"put",
"(",
"$",
"key",
",",
"$",
"arg",
"[",
"'value'",
"]",
")",
";",
"}",
"return",
"$",
"translations",
";",
"}"
] | Get all available translations
@param null $locale
@return mixed | [
"Get",
"all",
"available",
"translations"
] | 6bef2c68da1c05df7d759da8458037eee5203986 | https://github.com/Webklex/translator/blob/6bef2c68da1c05df7d759da8458037eee5203986/src/Translator/Translator.php#L151-L165 |
13,129 | Webklex/translator | src/Translator/Translator.php | Translator.load | public function load($locale)
{
if ($this->isLoaded($locale)) {
return;
}
$this->languages[$locale] = $this->handler->load($locale);
} | php | public function load($locale)
{
if ($this->isLoaded($locale)) {
return;
}
$this->languages[$locale] = $this->handler->load($locale);
} | [
"public",
"function",
"load",
"(",
"$",
"locale",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isLoaded",
"(",
"$",
"locale",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"languages",
"[",
"$",
"locale",
"]",
"=",
"$",
"this",
"->",
"handler",
"->",
"load",
"(",
"$",
"locale",
")",
";",
"}"
] | Load the specified language .
@param string $locale
@return void | [
"Load",
"the",
"specified",
"language",
"."
] | 6bef2c68da1c05df7d759da8458037eee5203986 | https://github.com/Webklex/translator/blob/6bef2c68da1c05df7d759da8458037eee5203986/src/Translator/Translator.php#L203-L209 |
13,130 | sifophp/sifo-common-instance | controllers/debug/commandLineDebug.php | DebugCommandLineDebugController.finalRender | protected function finalRender( $debug_data )
{
parent::finalRender( $debug_data );
$url = \Sifo\Urls::getInstance()->getUrlConfig();
echo '[INFO] Script debug properly saved. You can check it out at: ' . $url['sifo_debug_analyzer'] . '?execution_key=' . \Sifo\Debug::getExecutionKey() . PHP_EOL;
} | php | protected function finalRender( $debug_data )
{
parent::finalRender( $debug_data );
$url = \Sifo\Urls::getInstance()->getUrlConfig();
echo '[INFO] Script debug properly saved. You can check it out at: ' . $url['sifo_debug_analyzer'] . '?execution_key=' . \Sifo\Debug::getExecutionKey() . PHP_EOL;
} | [
"protected",
"function",
"finalRender",
"(",
"$",
"debug_data",
")",
"{",
"parent",
"::",
"finalRender",
"(",
"$",
"debug_data",
")",
";",
"$",
"url",
"=",
"\\",
"Sifo",
"\\",
"Urls",
"::",
"getInstance",
"(",
")",
"->",
"getUrlConfig",
"(",
")",
";",
"echo",
"'[INFO] Script debug properly saved. You can check it out at: '",
".",
"$",
"url",
"[",
"'sifo_debug_analyzer'",
"]",
".",
"'?execution_key='",
".",
"\\",
"Sifo",
"\\",
"Debug",
"::",
"getExecutionKey",
"(",
")",
".",
"PHP_EOL",
";",
"}"
] | Override method in order to show a message with a link to the Sifo Debug Analyzer.
@param array $debug_data Structure containing all debug related data. | [
"Override",
"method",
"in",
"order",
"to",
"show",
"a",
"message",
"with",
"a",
"link",
"to",
"the",
"Sifo",
"Debug",
"Analyzer",
"."
] | 52d54ea3e565bd2bccd77e0b0a6a99b5cae3aff5 | https://github.com/sifophp/sifo-common-instance/blob/52d54ea3e565bd2bccd77e0b0a6a99b5cae3aff5/controllers/debug/commandLineDebug.php#L22-L28 |
13,131 | incraigulous/contentful-sdk | src/ManagementResources/IsPublishable.php | IsPublishable.publish | function publish($id, $previous)
{
$this->requestDecorator->setId($id . '/published');
$this->requestDecorator->addHeader('X-Contentful-Version', $previous['sys']['version']);
$result = $this->client->put($this->requestDecorator->makeResource(), $this->requestDecorator->makePayload(), $this->requestDecorator->makeHeaders());
$this->refresh();
return $result;
} | php | function publish($id, $previous)
{
$this->requestDecorator->setId($id . '/published');
$this->requestDecorator->addHeader('X-Contentful-Version', $previous['sys']['version']);
$result = $this->client->put($this->requestDecorator->makeResource(), $this->requestDecorator->makePayload(), $this->requestDecorator->makeHeaders());
$this->refresh();
return $result;
} | [
"function",
"publish",
"(",
"$",
"id",
",",
"$",
"previous",
")",
"{",
"$",
"this",
"->",
"requestDecorator",
"->",
"setId",
"(",
"$",
"id",
".",
"'/published'",
")",
";",
"$",
"this",
"->",
"requestDecorator",
"->",
"addHeader",
"(",
"'X-Contentful-Version'",
",",
"$",
"previous",
"[",
"'sys'",
"]",
"[",
"'version'",
"]",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"client",
"->",
"put",
"(",
"$",
"this",
"->",
"requestDecorator",
"->",
"makeResource",
"(",
")",
",",
"$",
"this",
"->",
"requestDecorator",
"->",
"makePayload",
"(",
")",
",",
"$",
"this",
"->",
"requestDecorator",
"->",
"makeHeaders",
"(",
")",
")",
";",
"$",
"this",
"->",
"refresh",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Publish a record.
@param $id
@param $previous
@return mixed | [
"Publish",
"a",
"record",
"."
] | 29399b11b0e085a06ea5976661378c379fe5a731 | https://github.com/incraigulous/contentful-sdk/blob/29399b11b0e085a06ea5976661378c379fe5a731/src/ManagementResources/IsPublishable.php#L14-L21 |
13,132 | incraigulous/contentful-sdk | src/ManagementResources/IsPublishable.php | IsPublishable.unpublish | function unpublish($id, $previous)
{
$this->requestDecorator->setId($id . '/published');
$this->requestDecorator->addHeader('X-Contentful-Version', $previous['sys']['version']);
$result = $this->client->delete($this->requestDecorator->makeResource(), $this->requestDecorator->makeHeaders());
$this->refresh();
return $result;
} | php | function unpublish($id, $previous)
{
$this->requestDecorator->setId($id . '/published');
$this->requestDecorator->addHeader('X-Contentful-Version', $previous['sys']['version']);
$result = $this->client->delete($this->requestDecorator->makeResource(), $this->requestDecorator->makeHeaders());
$this->refresh();
return $result;
} | [
"function",
"unpublish",
"(",
"$",
"id",
",",
"$",
"previous",
")",
"{",
"$",
"this",
"->",
"requestDecorator",
"->",
"setId",
"(",
"$",
"id",
".",
"'/published'",
")",
";",
"$",
"this",
"->",
"requestDecorator",
"->",
"addHeader",
"(",
"'X-Contentful-Version'",
",",
"$",
"previous",
"[",
"'sys'",
"]",
"[",
"'version'",
"]",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"client",
"->",
"delete",
"(",
"$",
"this",
"->",
"requestDecorator",
"->",
"makeResource",
"(",
")",
",",
"$",
"this",
"->",
"requestDecorator",
"->",
"makeHeaders",
"(",
")",
")",
";",
"$",
"this",
"->",
"refresh",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Unublish a record.
@param $id
@param $previous
@return mixed | [
"Unublish",
"a",
"record",
"."
] | 29399b11b0e085a06ea5976661378c379fe5a731 | https://github.com/incraigulous/contentful-sdk/blob/29399b11b0e085a06ea5976661378c379fe5a731/src/ManagementResources/IsPublishable.php#L29-L36 |
13,133 | psecio/propauth | src/PolicySet.php | PolicySet.add | public function add($policyName, \Psecio\PropAuth\Policy $policy)
{
$this->policies[$policyName] = $policy;
return $this;
} | php | public function add($policyName, \Psecio\PropAuth\Policy $policy)
{
$this->policies[$policyName] = $policy;
return $this;
} | [
"public",
"function",
"add",
"(",
"$",
"policyName",
",",
"\\",
"Psecio",
"\\",
"PropAuth",
"\\",
"Policy",
"$",
"policy",
")",
"{",
"$",
"this",
"->",
"policies",
"[",
"$",
"policyName",
"]",
"=",
"$",
"policy",
";",
"return",
"$",
"this",
";",
"}"
] | Add a new policy to the current set with the given key name
@param string $policyName Policy name (key)
@param \Psecio\PropAuth\Policy $policy Policy object instance | [
"Add",
"a",
"new",
"policy",
"to",
"the",
"current",
"set",
"with",
"the",
"given",
"key",
"name"
] | cb24fcc0a3fa459f2ef40a867c334951aabf7b83 | https://github.com/psecio/propauth/blob/cb24fcc0a3fa459f2ef40a867c334951aabf7b83/src/PolicySet.php#L71-L75 |
13,134 | markwatkinson/luminous | src/Luminous/Utils/SassParser.php | SassParser.nextIs | public function nextIs($tokenName, $ignoreWhitespace = false)
{
$i = $this->index+1;
$len = count($this->tokens);
while ($i < $len) {
$tok = $this->tokens[$i][0];
if ($ignoreWhitespace && $tok === 'WHITESPACE') {
$i++;
} else {
return $tok === $tokenName;
}
}
return false;
} | php | public function nextIs($tokenName, $ignoreWhitespace = false)
{
$i = $this->index+1;
$len = count($this->tokens);
while ($i < $len) {
$tok = $this->tokens[$i][0];
if ($ignoreWhitespace && $tok === 'WHITESPACE') {
$i++;
} else {
return $tok === $tokenName;
}
}
return false;
} | [
"public",
"function",
"nextIs",
"(",
"$",
"tokenName",
",",
"$",
"ignoreWhitespace",
"=",
"false",
")",
"{",
"$",
"i",
"=",
"$",
"this",
"->",
"index",
"+",
"1",
";",
"$",
"len",
"=",
"count",
"(",
"$",
"this",
"->",
"tokens",
")",
";",
"while",
"(",
"$",
"i",
"<",
"$",
"len",
")",
"{",
"$",
"tok",
"=",
"$",
"this",
"->",
"tokens",
"[",
"$",
"i",
"]",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"ignoreWhitespace",
"&&",
"$",
"tok",
"===",
"'WHITESPACE'",
")",
"{",
"$",
"i",
"++",
";",
"}",
"else",
"{",
"return",
"$",
"tok",
"===",
"$",
"tokenName",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Returns true if the next token is the given token name
optionally skipping whitespace | [
"Returns",
"true",
"if",
"the",
"next",
"token",
"is",
"the",
"given",
"token",
"name",
"optionally",
"skipping",
"whitespace"
] | 4adc18f414534abe986133d6d38e8e9787d32e69 | https://github.com/markwatkinson/luminous/blob/4adc18f414534abe986133d6d38e8e9787d32e69/src/Luminous/Utils/SassParser.php#L19-L32 |
13,135 | markwatkinson/luminous | src/Luminous/Utils/SassParser.php | SassParser.nextSequence | public function nextSequence($sequence, $ignore = array())
{
$i = $this->index+1;
$len = count($this->tokens);
$seqLen = count($sequence);
$seq = 0;
$seqStart = 0;
while ($i < $len) {
$tok = $this->tokens[$i][0];
if ($tok === $sequence[$seq]) {
if ($seq === 0) {
$seqStart = $i;
}
$seq++;
$i++;
if ($seq === $seqLen) {
return $seqStart;
}
} else {
if (in_array($tok, $ignore)) {
} else {
$seq = 0;
}
$i++;
}
}
return $len;
} | php | public function nextSequence($sequence, $ignore = array())
{
$i = $this->index+1;
$len = count($this->tokens);
$seqLen = count($sequence);
$seq = 0;
$seqStart = 0;
while ($i < $len) {
$tok = $this->tokens[$i][0];
if ($tok === $sequence[$seq]) {
if ($seq === 0) {
$seqStart = $i;
}
$seq++;
$i++;
if ($seq === $seqLen) {
return $seqStart;
}
} else {
if (in_array($tok, $ignore)) {
} else {
$seq = 0;
}
$i++;
}
}
return $len;
} | [
"public",
"function",
"nextSequence",
"(",
"$",
"sequence",
",",
"$",
"ignore",
"=",
"array",
"(",
")",
")",
"{",
"$",
"i",
"=",
"$",
"this",
"->",
"index",
"+",
"1",
";",
"$",
"len",
"=",
"count",
"(",
"$",
"this",
"->",
"tokens",
")",
";",
"$",
"seqLen",
"=",
"count",
"(",
"$",
"sequence",
")",
";",
"$",
"seq",
"=",
"0",
";",
"$",
"seqStart",
"=",
"0",
";",
"while",
"(",
"$",
"i",
"<",
"$",
"len",
")",
"{",
"$",
"tok",
"=",
"$",
"this",
"->",
"tokens",
"[",
"$",
"i",
"]",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"tok",
"===",
"$",
"sequence",
"[",
"$",
"seq",
"]",
")",
"{",
"if",
"(",
"$",
"seq",
"===",
"0",
")",
"{",
"$",
"seqStart",
"=",
"$",
"i",
";",
"}",
"$",
"seq",
"++",
";",
"$",
"i",
"++",
";",
"if",
"(",
"$",
"seq",
"===",
"$",
"seqLen",
")",
"{",
"return",
"$",
"seqStart",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"in_array",
"(",
"$",
"tok",
",",
"$",
"ignore",
")",
")",
"{",
"}",
"else",
"{",
"$",
"seq",
"=",
"0",
";",
"}",
"$",
"i",
"++",
";",
"}",
"}",
"return",
"$",
"len",
";",
"}"
] | Returns the index of the next match of the sequence of tokens
given, optionally ignoring ertain tokens | [
"Returns",
"the",
"index",
"of",
"the",
"next",
"match",
"of",
"the",
"sequence",
"of",
"tokens",
"given",
"optionally",
"ignoring",
"ertain",
"tokens"
] | 4adc18f414534abe986133d6d38e8e9787d32e69 | https://github.com/markwatkinson/luminous/blob/4adc18f414534abe986133d6d38e8e9787d32e69/src/Luminous/Utils/SassParser.php#L38-L65 |
13,136 | markwatkinson/luminous | src/Luminous/Utils/SassParser.php | SassParser.nextOf | public function nextOf($tokenNames)
{
$i = $this->index+1;
$len = count($this->tokens);
while ($i < $len) {
$tok = $this->tokens[$i][0];
if (in_array($tok, $tokenNames)) {
return $tok;
}
$i++;
}
return null;
} | php | public function nextOf($tokenNames)
{
$i = $this->index+1;
$len = count($this->tokens);
while ($i < $len) {
$tok = $this->tokens[$i][0];
if (in_array($tok, $tokenNames)) {
return $tok;
}
$i++;
}
return null;
} | [
"public",
"function",
"nextOf",
"(",
"$",
"tokenNames",
")",
"{",
"$",
"i",
"=",
"$",
"this",
"->",
"index",
"+",
"1",
";",
"$",
"len",
"=",
"count",
"(",
"$",
"this",
"->",
"tokens",
")",
";",
"while",
"(",
"$",
"i",
"<",
"$",
"len",
")",
"{",
"$",
"tok",
"=",
"$",
"this",
"->",
"tokens",
"[",
"$",
"i",
"]",
"[",
"0",
"]",
";",
"if",
"(",
"in_array",
"(",
"$",
"tok",
",",
"$",
"tokenNames",
")",
")",
"{",
"return",
"$",
"tok",
";",
"}",
"$",
"i",
"++",
";",
"}",
"return",
"null",
";",
"}"
] | Returns the first token which occurs out of the set of given tokens | [
"Returns",
"the",
"first",
"token",
"which",
"occurs",
"out",
"of",
"the",
"set",
"of",
"given",
"tokens"
] | 4adc18f414534abe986133d6d38e8e9787d32e69 | https://github.com/markwatkinson/luminous/blob/4adc18f414534abe986133d6d38e8e9787d32e69/src/Luminous/Utils/SassParser.php#L70-L82 |
13,137 | markwatkinson/luminous | src/Luminous/Utils/SassParser.php | SassParser.nextOfType | public function nextOfType($tokenName)
{
$i = $this->index+1;
$len = count($this->tokens);
while ($i < $len) {
$tok = $this->tokens[$i][0];
if ($tok === $tokenName) {
return $i;
}
$i++;
}
return $len;
} | php | public function nextOfType($tokenName)
{
$i = $this->index+1;
$len = count($this->tokens);
while ($i < $len) {
$tok = $this->tokens[$i][0];
if ($tok === $tokenName) {
return $i;
}
$i++;
}
return $len;
} | [
"public",
"function",
"nextOfType",
"(",
"$",
"tokenName",
")",
"{",
"$",
"i",
"=",
"$",
"this",
"->",
"index",
"+",
"1",
";",
"$",
"len",
"=",
"count",
"(",
"$",
"this",
"->",
"tokens",
")",
";",
"while",
"(",
"$",
"i",
"<",
"$",
"len",
")",
"{",
"$",
"tok",
"=",
"$",
"this",
"->",
"tokens",
"[",
"$",
"i",
"]",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"tok",
"===",
"$",
"tokenName",
")",
"{",
"return",
"$",
"i",
";",
"}",
"$",
"i",
"++",
";",
"}",
"return",
"$",
"len",
";",
"}"
] | Returns the index of the next token with the given token name | [
"Returns",
"the",
"index",
"of",
"the",
"next",
"token",
"with",
"the",
"given",
"token",
"name"
] | 4adc18f414534abe986133d6d38e8e9787d32e69 | https://github.com/markwatkinson/luminous/blob/4adc18f414534abe986133d6d38e8e9787d32e69/src/Luminous/Utils/SassParser.php#L87-L99 |
13,138 | markwatkinson/luminous | src/Luminous/Utils/SassParser.php | SassParser.parseRule | private function parseRule()
{
$newToken = $this->tokens[$this->index];
$set = false;
if ($this->index > 0) {
$prevToken = &$this->tokens[$this->index-1];
$prevTokenType = &$prevToken[0];
$prevTokenText = &$prevToken[1];
$concat = false;
$map = array(
'DOT' => 'CLASS_SELECTOR',
'HASH' => 'ID_SELECTOR',
'COLON' => 'PSEUDO_SELECTOR',
'DOUBLE_COLON' => 'PSEUDO_SELECTOR'
);
if (isset($map[$prevTokenType])) {
// mark the prev token for deletion and concat into one.
$newToken[0] = $map[$prevTokenType];
$prevTokenType = self::$deleteToken;
$newToken[1] = $prevTokenText . $newToken[1];
$set = true;
}
}
if (!$set) {
// must be an element
$newToken[0] = 'ELEMENT_SELECTOR';
}
$this->tokens[$this->index] = $newToken;
} | php | private function parseRule()
{
$newToken = $this->tokens[$this->index];
$set = false;
if ($this->index > 0) {
$prevToken = &$this->tokens[$this->index-1];
$prevTokenType = &$prevToken[0];
$prevTokenText = &$prevToken[1];
$concat = false;
$map = array(
'DOT' => 'CLASS_SELECTOR',
'HASH' => 'ID_SELECTOR',
'COLON' => 'PSEUDO_SELECTOR',
'DOUBLE_COLON' => 'PSEUDO_SELECTOR'
);
if (isset($map[$prevTokenType])) {
// mark the prev token for deletion and concat into one.
$newToken[0] = $map[$prevTokenType];
$prevTokenType = self::$deleteToken;
$newToken[1] = $prevTokenText . $newToken[1];
$set = true;
}
}
if (!$set) {
// must be an element
$newToken[0] = 'ELEMENT_SELECTOR';
}
$this->tokens[$this->index] = $newToken;
} | [
"private",
"function",
"parseRule",
"(",
")",
"{",
"$",
"newToken",
"=",
"$",
"this",
"->",
"tokens",
"[",
"$",
"this",
"->",
"index",
"]",
";",
"$",
"set",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"index",
">",
"0",
")",
"{",
"$",
"prevToken",
"=",
"&",
"$",
"this",
"->",
"tokens",
"[",
"$",
"this",
"->",
"index",
"-",
"1",
"]",
";",
"$",
"prevTokenType",
"=",
"&",
"$",
"prevToken",
"[",
"0",
"]",
";",
"$",
"prevTokenText",
"=",
"&",
"$",
"prevToken",
"[",
"1",
"]",
";",
"$",
"concat",
"=",
"false",
";",
"$",
"map",
"=",
"array",
"(",
"'DOT'",
"=>",
"'CLASS_SELECTOR'",
",",
"'HASH'",
"=>",
"'ID_SELECTOR'",
",",
"'COLON'",
"=>",
"'PSEUDO_SELECTOR'",
",",
"'DOUBLE_COLON'",
"=>",
"'PSEUDO_SELECTOR'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"map",
"[",
"$",
"prevTokenType",
"]",
")",
")",
"{",
"// mark the prev token for deletion and concat into one.",
"$",
"newToken",
"[",
"0",
"]",
"=",
"$",
"map",
"[",
"$",
"prevTokenType",
"]",
";",
"$",
"prevTokenType",
"=",
"self",
"::",
"$",
"deleteToken",
";",
"$",
"newToken",
"[",
"1",
"]",
"=",
"$",
"prevTokenText",
".",
"$",
"newToken",
"[",
"1",
"]",
";",
"$",
"set",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"set",
")",
"{",
"// must be an element",
"$",
"newToken",
"[",
"0",
"]",
"=",
"'ELEMENT_SELECTOR'",
";",
"}",
"$",
"this",
"->",
"tokens",
"[",
"$",
"this",
"->",
"index",
"]",
"=",
"$",
"newToken",
";",
"}"
] | Parses a selector rule | [
"Parses",
"a",
"selector",
"rule"
] | 4adc18f414534abe986133d6d38e8e9787d32e69 | https://github.com/markwatkinson/luminous/blob/4adc18f414534abe986133d6d38e8e9787d32e69/src/Luminous/Utils/SassParser.php#L113-L142 |
13,139 | markwatkinson/luminous | src/Luminous/Utils/SassParser.php | SassParser.cleanup | private function cleanup()
{
foreach ($this->tokens as $i => $t) {
if ($t[0] === self::$deleteToken) {
unset($this->tokens[$i]);
}
}
$this->tokens = array_values($this->tokens);
} | php | private function cleanup()
{
foreach ($this->tokens as $i => $t) {
if ($t[0] === self::$deleteToken) {
unset($this->tokens[$i]);
}
}
$this->tokens = array_values($this->tokens);
} | [
"private",
"function",
"cleanup",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"tokens",
"as",
"$",
"i",
"=>",
"$",
"t",
")",
"{",
"if",
"(",
"$",
"t",
"[",
"0",
"]",
"===",
"self",
"::",
"$",
"deleteToken",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"tokens",
"[",
"$",
"i",
"]",
")",
";",
"}",
"}",
"$",
"this",
"->",
"tokens",
"=",
"array_values",
"(",
"$",
"this",
"->",
"tokens",
")",
";",
"}"
] | Cleans up the token stream by deleting any tokens marked for
deletion, and makes sure the array is continuous afterwards. | [
"Cleans",
"up",
"the",
"token",
"stream",
"by",
"deleting",
"any",
"tokens",
"marked",
"for",
"deletion",
"and",
"makes",
"sure",
"the",
"array",
"is",
"continuous",
"afterwards",
"."
] | 4adc18f414534abe986133d6d38e8e9787d32e69 | https://github.com/markwatkinson/luminous/blob/4adc18f414534abe986133d6d38e8e9787d32e69/src/Luminous/Utils/SassParser.php#L148-L156 |
13,140 | markwatkinson/luminous | src/Luminous/Scanners/GroovyScanner.php | GroovyScanner.interpString | public function interpString($m)
{
// this should only be called for doubly quoted strings
// and triple-double quotes
//
// interpolation is betwee ${ ... }
$patterns = array('interp' => '/(?<!\\$)\\$\\{/');
$start = $this->pos();
if (preg_match('/^"""/', $m[0])) {
$patterns['term'] = '/"""/';
$this->posShift(3);
} else {
assert(preg_match('/^"/', $m[0]));
$patterns['term'] = '/"/';
$this->posShift(1);
}
while (1) {
$p = $this->pos();
list($name, $index, $matches) = $this->getNextNamed($patterns);
if ($name === null) {
// no matches, terminate
$this->record(substr($this->string(), $start), 'STRING');
$this->terminate();
break;
} elseif ($name === 'term') {
// end of the string
$range = $index + strlen($matches[0]);
$this->record(substr($this->string(), $start, $range - $start), 'STRING');
$this->pos($range);
break;
} else {
// interpolation, handle this with a subscanner
$this->record(substr($this->string(), $start, $index - $start), 'STRING');
$this->record($matches[0], 'DELIMITER');
$subscanner = new GroovyScanner($this->string());
$subscanner->interpolation = true;
$subscanner->init();
$subscanner->pos($index + strlen($matches[0]));
$subscanner->main();
$tagged = $subscanner->tagged();
$this->record($tagged, 'INTERPOLATION', true);
$this->pos($subscanner->pos());
if ($this->scan('/\\}/')) {
$this->record($this->match(), 'DELIMITER');
}
$start = $this->pos();
}
assert($p < $this->pos());
}
} | php | public function interpString($m)
{
// this should only be called for doubly quoted strings
// and triple-double quotes
//
// interpolation is betwee ${ ... }
$patterns = array('interp' => '/(?<!\\$)\\$\\{/');
$start = $this->pos();
if (preg_match('/^"""/', $m[0])) {
$patterns['term'] = '/"""/';
$this->posShift(3);
} else {
assert(preg_match('/^"/', $m[0]));
$patterns['term'] = '/"/';
$this->posShift(1);
}
while (1) {
$p = $this->pos();
list($name, $index, $matches) = $this->getNextNamed($patterns);
if ($name === null) {
// no matches, terminate
$this->record(substr($this->string(), $start), 'STRING');
$this->terminate();
break;
} elseif ($name === 'term') {
// end of the string
$range = $index + strlen($matches[0]);
$this->record(substr($this->string(), $start, $range - $start), 'STRING');
$this->pos($range);
break;
} else {
// interpolation, handle this with a subscanner
$this->record(substr($this->string(), $start, $index - $start), 'STRING');
$this->record($matches[0], 'DELIMITER');
$subscanner = new GroovyScanner($this->string());
$subscanner->interpolation = true;
$subscanner->init();
$subscanner->pos($index + strlen($matches[0]));
$subscanner->main();
$tagged = $subscanner->tagged();
$this->record($tagged, 'INTERPOLATION', true);
$this->pos($subscanner->pos());
if ($this->scan('/\\}/')) {
$this->record($this->match(), 'DELIMITER');
}
$start = $this->pos();
}
assert($p < $this->pos());
}
} | [
"public",
"function",
"interpString",
"(",
"$",
"m",
")",
"{",
"// this should only be called for doubly quoted strings",
"// and triple-double quotes",
"//",
"// interpolation is betwee ${ ... }",
"$",
"patterns",
"=",
"array",
"(",
"'interp'",
"=>",
"'/(?<!\\\\$)\\\\$\\\\{/'",
")",
";",
"$",
"start",
"=",
"$",
"this",
"->",
"pos",
"(",
")",
";",
"if",
"(",
"preg_match",
"(",
"'/^\"\"\"/'",
",",
"$",
"m",
"[",
"0",
"]",
")",
")",
"{",
"$",
"patterns",
"[",
"'term'",
"]",
"=",
"'/\"\"\"/'",
";",
"$",
"this",
"->",
"posShift",
"(",
"3",
")",
";",
"}",
"else",
"{",
"assert",
"(",
"preg_match",
"(",
"'/^\"/'",
",",
"$",
"m",
"[",
"0",
"]",
")",
")",
";",
"$",
"patterns",
"[",
"'term'",
"]",
"=",
"'/\"/'",
";",
"$",
"this",
"->",
"posShift",
"(",
"1",
")",
";",
"}",
"while",
"(",
"1",
")",
"{",
"$",
"p",
"=",
"$",
"this",
"->",
"pos",
"(",
")",
";",
"list",
"(",
"$",
"name",
",",
"$",
"index",
",",
"$",
"matches",
")",
"=",
"$",
"this",
"->",
"getNextNamed",
"(",
"$",
"patterns",
")",
";",
"if",
"(",
"$",
"name",
"===",
"null",
")",
"{",
"// no matches, terminate",
"$",
"this",
"->",
"record",
"(",
"substr",
"(",
"$",
"this",
"->",
"string",
"(",
")",
",",
"$",
"start",
")",
",",
"'STRING'",
")",
";",
"$",
"this",
"->",
"terminate",
"(",
")",
";",
"break",
";",
"}",
"elseif",
"(",
"$",
"name",
"===",
"'term'",
")",
"{",
"// end of the string",
"$",
"range",
"=",
"$",
"index",
"+",
"strlen",
"(",
"$",
"matches",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"record",
"(",
"substr",
"(",
"$",
"this",
"->",
"string",
"(",
")",
",",
"$",
"start",
",",
"$",
"range",
"-",
"$",
"start",
")",
",",
"'STRING'",
")",
";",
"$",
"this",
"->",
"pos",
"(",
"$",
"range",
")",
";",
"break",
";",
"}",
"else",
"{",
"// interpolation, handle this with a subscanner",
"$",
"this",
"->",
"record",
"(",
"substr",
"(",
"$",
"this",
"->",
"string",
"(",
")",
",",
"$",
"start",
",",
"$",
"index",
"-",
"$",
"start",
")",
",",
"'STRING'",
")",
";",
"$",
"this",
"->",
"record",
"(",
"$",
"matches",
"[",
"0",
"]",
",",
"'DELIMITER'",
")",
";",
"$",
"subscanner",
"=",
"new",
"GroovyScanner",
"(",
"$",
"this",
"->",
"string",
"(",
")",
")",
";",
"$",
"subscanner",
"->",
"interpolation",
"=",
"true",
";",
"$",
"subscanner",
"->",
"init",
"(",
")",
";",
"$",
"subscanner",
"->",
"pos",
"(",
"$",
"index",
"+",
"strlen",
"(",
"$",
"matches",
"[",
"0",
"]",
")",
")",
";",
"$",
"subscanner",
"->",
"main",
"(",
")",
";",
"$",
"tagged",
"=",
"$",
"subscanner",
"->",
"tagged",
"(",
")",
";",
"$",
"this",
"->",
"record",
"(",
"$",
"tagged",
",",
"'INTERPOLATION'",
",",
"true",
")",
";",
"$",
"this",
"->",
"pos",
"(",
"$",
"subscanner",
"->",
"pos",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"scan",
"(",
"'/\\\\}/'",
")",
")",
"{",
"$",
"this",
"->",
"record",
"(",
"$",
"this",
"->",
"match",
"(",
")",
",",
"'DELIMITER'",
")",
";",
"}",
"$",
"start",
"=",
"$",
"this",
"->",
"pos",
"(",
")",
";",
"}",
"assert",
"(",
"$",
"p",
"<",
"$",
"this",
"->",
"pos",
"(",
")",
")",
";",
"}",
"}"
] | string interpolation is complex and it nests, so we do that in here | [
"string",
"interpolation",
"is",
"complex",
"and",
"it",
"nests",
"so",
"we",
"do",
"that",
"in",
"here"
] | 4adc18f414534abe986133d6d38e8e9787d32e69 | https://github.com/markwatkinson/luminous/blob/4adc18f414534abe986133d6d38e8e9787d32e69/src/Luminous/Scanners/GroovyScanner.php#L55-L105 |
13,141 | markwatkinson/luminous | src/Luminous/Scanners/GroovyScanner.php | GroovyScanner.brace | public function brace($m)
{
if ($m[0] === '{') {
$this->braceStack++;
} elseif ($m[0] === '}') {
if ($this->braceStack <= 0) {
return true;
}
$this->braceStack--;
} else {
assert(0);
}
$this->record($m[0], null);
$this->posShift(strlen($m[0]));
} | php | public function brace($m)
{
if ($m[0] === '{') {
$this->braceStack++;
} elseif ($m[0] === '}') {
if ($this->braceStack <= 0) {
return true;
}
$this->braceStack--;
} else {
assert(0);
}
$this->record($m[0], null);
$this->posShift(strlen($m[0]));
} | [
"public",
"function",
"brace",
"(",
"$",
"m",
")",
"{",
"if",
"(",
"$",
"m",
"[",
"0",
"]",
"===",
"'{'",
")",
"{",
"$",
"this",
"->",
"braceStack",
"++",
";",
"}",
"elseif",
"(",
"$",
"m",
"[",
"0",
"]",
"===",
"'}'",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"braceStack",
"<=",
"0",
")",
"{",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"braceStack",
"--",
";",
"}",
"else",
"{",
"assert",
"(",
"0",
")",
";",
"}",
"$",
"this",
"->",
"record",
"(",
"$",
"m",
"[",
"0",
"]",
",",
"null",
")",
";",
"$",
"this",
"->",
"posShift",
"(",
"strlen",
"(",
"$",
"m",
"[",
"0",
"]",
")",
")",
";",
"}"
] | this is for interpolated code, the top-level scanner doesn't bind to this | [
"this",
"is",
"for",
"interpolated",
"code",
"the",
"top",
"-",
"level",
"scanner",
"doesn",
"t",
"bind",
"to",
"this"
] | 4adc18f414534abe986133d6d38e8e9787d32e69 | https://github.com/markwatkinson/luminous/blob/4adc18f414534abe986133d6d38e8e9787d32e69/src/Luminous/Scanners/GroovyScanner.php#L109-L123 |
13,142 | assely/fielder | src/Fielder.php | Fielder.get | public function get($name)
{
if (isset($this->fields[$name])) {
return $this->fields[$name];
}
throw new FieldException("Fielder doesn't have [$name] field registered.");
} | php | public function get($name)
{
if (isset($this->fields[$name])) {
return $this->fields[$name];
}
throw new FieldException("Fielder doesn't have [$name] field registered.");
} | [
"public",
"function",
"get",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"fields",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"fields",
"[",
"$",
"name",
"]",
";",
"}",
"throw",
"new",
"FieldException",
"(",
"\"Fielder doesn't have [$name] field registered.\"",
")",
";",
"}"
] | Get registered field.
@param string $name
@return string | [
"Get",
"registered",
"field",
"."
] | c702ef2426522d1a0a9ca9945547513a7788fcdc | https://github.com/assely/fielder/blob/c702ef2426522d1a0a9ca9945547513a7788fcdc/src/Fielder.php#L36-L43 |
13,143 | assely/fielder | src/Fielder.php | Fielder.make | public function make($class, $type, $slug, $arguments = [])
{
$field = $this->container->make($class);
$field
->setType($type)
->setSlug($slug)
->setArguments($arguments)
->boot();
return $field;
} | php | public function make($class, $type, $slug, $arguments = [])
{
$field = $this->container->make($class);
$field
->setType($type)
->setSlug($slug)
->setArguments($arguments)
->boot();
return $field;
} | [
"public",
"function",
"make",
"(",
"$",
"class",
",",
"$",
"type",
",",
"$",
"slug",
",",
"$",
"arguments",
"=",
"[",
"]",
")",
"{",
"$",
"field",
"=",
"$",
"this",
"->",
"container",
"->",
"make",
"(",
"$",
"class",
")",
";",
"$",
"field",
"->",
"setType",
"(",
"$",
"type",
")",
"->",
"setSlug",
"(",
"$",
"slug",
")",
"->",
"setArguments",
"(",
"$",
"arguments",
")",
"->",
"boot",
"(",
")",
";",
"return",
"$",
"field",
";",
"}"
] | Creates field instance.
@param string $class
@param string $type
@param string $slug
@param array $arguments
@return \Assely\Contracts\Field\FieldInterface | [
"Creates",
"field",
"instance",
"."
] | c702ef2426522d1a0a9ca9945547513a7788fcdc | https://github.com/assely/fielder/blob/c702ef2426522d1a0a9ca9945547513a7788fcdc/src/Fielder.php#L55-L66 |
13,144 | IftekherSunny/PDF | src/PDF.php | PDF.output | public function output($view, $data = [])
{
$path = $this->processOutput($view, $data);
$content = file_get_contents($path);
@unlink($path);
return $content;
} | php | public function output($view, $data = [])
{
$path = $this->processOutput($view, $data);
$content = file_get_contents($path);
@unlink($path);
return $content;
} | [
"public",
"function",
"output",
"(",
"$",
"view",
",",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"processOutput",
"(",
"$",
"view",
",",
"$",
"data",
")",
";",
"$",
"content",
"=",
"file_get_contents",
"(",
"$",
"path",
")",
";",
"@",
"unlink",
"(",
"$",
"path",
")",
";",
"return",
"$",
"content",
";",
"}"
] | Get pdf output for the view.
@param string $view
@param array $data
@return string | [
"Get",
"pdf",
"output",
"for",
"the",
"view",
"."
] | 798bad6b140a78d0c1a1823e12da3ed0e4f012ec | https://github.com/IftekherSunny/PDF/blob/798bad6b140a78d0c1a1823e12da3ed0e4f012ec/src/PDF.php#L49-L58 |
13,145 | IftekherSunny/PDF | src/PDF.php | PDF.processOutput | protected function processOutput($view, $data = [])
{
$name = $this->generateFileName();
$path = __DIR__ . DIRECTORY_SEPARATOR . "{$name}";
file_put_contents($path, $this->generateView($view, $data));
$this->getPhantomProcess($path)->setTimeout(0)->mustRun();
return $path;
} | php | protected function processOutput($view, $data = [])
{
$name = $this->generateFileName();
$path = __DIR__ . DIRECTORY_SEPARATOR . "{$name}";
file_put_contents($path, $this->generateView($view, $data));
$this->getPhantomProcess($path)->setTimeout(0)->mustRun();
return $path;
} | [
"protected",
"function",
"processOutput",
"(",
"$",
"view",
",",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"generateFileName",
"(",
")",
";",
"$",
"path",
"=",
"__DIR__",
".",
"DIRECTORY_SEPARATOR",
".",
"\"{$name}\"",
";",
"file_put_contents",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"generateView",
"(",
"$",
"view",
",",
"$",
"data",
")",
")",
";",
"$",
"this",
"->",
"getPhantomProcess",
"(",
"$",
"path",
")",
"->",
"setTimeout",
"(",
"0",
")",
"->",
"mustRun",
"(",
")",
";",
"return",
"$",
"path",
";",
"}"
] | Process pdf output for the view.
@param string $view
@param array $data
@return string | [
"Process",
"pdf",
"output",
"for",
"the",
"view",
"."
] | 798bad6b140a78d0c1a1823e12da3ed0e4f012ec | https://github.com/IftekherSunny/PDF/blob/798bad6b140a78d0c1a1823e12da3ed0e4f012ec/src/PDF.php#L68-L79 |
13,146 | IftekherSunny/PDF | src/PDF.php | PDF.download | public function download($view, $data = [], $name = 'download')
{
$path = $this->processOutput($view, $data);
return $this->responseDownload($path, $name);
} | php | public function download($view, $data = [], $name = 'download')
{
$path = $this->processOutput($view, $data);
return $this->responseDownload($path, $name);
} | [
"public",
"function",
"download",
"(",
"$",
"view",
",",
"$",
"data",
"=",
"[",
"]",
",",
"$",
"name",
"=",
"'download'",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"processOutput",
"(",
"$",
"view",
",",
"$",
"data",
")",
";",
"return",
"$",
"this",
"->",
"responseDownload",
"(",
"$",
"path",
",",
"$",
"name",
")",
";",
"}"
] | Download generated pdf file.
@param string $view
@param array $data
@param string $name
@return \Symfony\Component\HttpFoundation\Response | [
"Download",
"generated",
"pdf",
"file",
"."
] | 798bad6b140a78d0c1a1823e12da3ed0e4f012ec | https://github.com/IftekherSunny/PDF/blob/798bad6b140a78d0c1a1823e12da3ed0e4f012ec/src/PDF.php#L90-L95 |
13,147 | IftekherSunny/PDF | src/PDF.php | PDF.responseDownload | protected function responseDownload($path, $name)
{
$response = new Response(file_get_contents($path), 200, [
'Content-Type' => 'application/pdf',
'Content-Description' => 'File Transfer',
'Content-Disposition' => 'attachment; filename="' . $name . '.pdf"',
'Content-Transfer-Encoding' => 'binary'
]);
@unlink($path);
return $response->send();
} | php | protected function responseDownload($path, $name)
{
$response = new Response(file_get_contents($path), 200, [
'Content-Type' => 'application/pdf',
'Content-Description' => 'File Transfer',
'Content-Disposition' => 'attachment; filename="' . $name . '.pdf"',
'Content-Transfer-Encoding' => 'binary'
]);
@unlink($path);
return $response->send();
} | [
"protected",
"function",
"responseDownload",
"(",
"$",
"path",
",",
"$",
"name",
")",
"{",
"$",
"response",
"=",
"new",
"Response",
"(",
"file_get_contents",
"(",
"$",
"path",
")",
",",
"200",
",",
"[",
"'Content-Type'",
"=>",
"'application/pdf'",
",",
"'Content-Description'",
"=>",
"'File Transfer'",
",",
"'Content-Disposition'",
"=>",
"'attachment; filename=\"'",
".",
"$",
"name",
".",
"'.pdf\"'",
",",
"'Content-Transfer-Encoding'",
"=>",
"'binary'",
"]",
")",
";",
"@",
"unlink",
"(",
"$",
"path",
")",
";",
"return",
"$",
"response",
"->",
"send",
"(",
")",
";",
"}"
] | Http response to download the pdf.
@param string $path
@param string $name
@return \Symfony\Component\HttpFoundation\Response | [
"Http",
"response",
"to",
"download",
"the",
"pdf",
"."
] | 798bad6b140a78d0c1a1823e12da3ed0e4f012ec | https://github.com/IftekherSunny/PDF/blob/798bad6b140a78d0c1a1823e12da3ed0e4f012ec/src/PDF.php#L105-L117 |
13,148 | IftekherSunny/PDF | src/PDF.php | PDF.stream | public function stream($view, $data = [])
{
$path = $this->processOutput($view, $data);
return $this->responseStream($path);
} | php | public function stream($view, $data = [])
{
$path = $this->processOutput($view, $data);
return $this->responseStream($path);
} | [
"public",
"function",
"stream",
"(",
"$",
"view",
",",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"processOutput",
"(",
"$",
"view",
",",
"$",
"data",
")",
";",
"return",
"$",
"this",
"->",
"responseStream",
"(",
"$",
"path",
")",
";",
"}"
] | View pdf in the browser.
@param string $view
@param array $data
@return \Symfony\Component\HttpFoundation\Response | [
"View",
"pdf",
"in",
"the",
"browser",
"."
] | 798bad6b140a78d0c1a1823e12da3ed0e4f012ec | https://github.com/IftekherSunny/PDF/blob/798bad6b140a78d0c1a1823e12da3ed0e4f012ec/src/PDF.php#L128-L133 |
13,149 | IftekherSunny/PDF | src/PDF.php | PDF.responseStream | protected function responseStream($path)
{
$response = new Response(file_get_contents($path), 200, [
'Content-type' => 'application/pdf',
'Content-Transfer-Encoding' => 'binary'
]);
@unlink($path);
return $response->send();
} | php | protected function responseStream($path)
{
$response = new Response(file_get_contents($path), 200, [
'Content-type' => 'application/pdf',
'Content-Transfer-Encoding' => 'binary'
]);
@unlink($path);
return $response->send();
} | [
"protected",
"function",
"responseStream",
"(",
"$",
"path",
")",
"{",
"$",
"response",
"=",
"new",
"Response",
"(",
"file_get_contents",
"(",
"$",
"path",
")",
",",
"200",
",",
"[",
"'Content-type'",
"=>",
"'application/pdf'",
",",
"'Content-Transfer-Encoding'",
"=>",
"'binary'",
"]",
")",
";",
"@",
"unlink",
"(",
"$",
"path",
")",
";",
"return",
"$",
"response",
"->",
"send",
"(",
")",
";",
"}"
] | Http response to stream pdf in the browser.
@param string $path
@return \Symfony\Component\HttpFoundation\Response | [
"Http",
"response",
"to",
"stream",
"pdf",
"in",
"the",
"browser",
"."
] | 798bad6b140a78d0c1a1823e12da3ed0e4f012ec | https://github.com/IftekherSunny/PDF/blob/798bad6b140a78d0c1a1823e12da3ed0e4f012ec/src/PDF.php#L142-L152 |
13,150 | IftekherSunny/PDF | src/PDF.php | PDF.getSystem | protected function getSystem()
{
$osName = strtolower(php_uname());
if ($this->contains($osName, 'darwin')) {
return 'macosx';
} elseif ($this->contains($osName, 'win')) {
return 'windows';
} elseif ($this->contains($osName, 'linux')) {
return PHP_INT_SIZE === 4 ? 'linux-i686' : 'linux-x86_64';
} else {
throw new RuntimeException('Unknown operating system.');
}
} | php | protected function getSystem()
{
$osName = strtolower(php_uname());
if ($this->contains($osName, 'darwin')) {
return 'macosx';
} elseif ($this->contains($osName, 'win')) {
return 'windows';
} elseif ($this->contains($osName, 'linux')) {
return PHP_INT_SIZE === 4 ? 'linux-i686' : 'linux-x86_64';
} else {
throw new RuntimeException('Unknown operating system.');
}
} | [
"protected",
"function",
"getSystem",
"(",
")",
"{",
"$",
"osName",
"=",
"strtolower",
"(",
"php_uname",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"contains",
"(",
"$",
"osName",
",",
"'darwin'",
")",
")",
"{",
"return",
"'macosx'",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"contains",
"(",
"$",
"osName",
",",
"'win'",
")",
")",
"{",
"return",
"'windows'",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"contains",
"(",
"$",
"osName",
",",
"'linux'",
")",
")",
"{",
"return",
"PHP_INT_SIZE",
"===",
"4",
"?",
"'linux-i686'",
":",
"'linux-x86_64'",
";",
"}",
"else",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Unknown operating system.'",
")",
";",
"}",
"}"
] | Get the operating system name for the current platform.
@return string | [
"Get",
"the",
"operating",
"system",
"name",
"for",
"the",
"current",
"platform",
"."
] | 798bad6b140a78d0c1a1823e12da3ed0e4f012ec | https://github.com/IftekherSunny/PDF/blob/798bad6b140a78d0c1a1823e12da3ed0e4f012ec/src/PDF.php#L175-L188 |
13,151 | IftekherSunny/PDF | src/PDF.php | PDF.generateView | protected function generateView($view, $data = [])
{
if(is_null($this->viewPath)) {
return $view;
}
$twig = new Twig_Environment(
new Twig_Loader_Filesystem(realpath($this->viewPath))
);
return $twig->render($view, $data);
} | php | protected function generateView($view, $data = [])
{
if(is_null($this->viewPath)) {
return $view;
}
$twig = new Twig_Environment(
new Twig_Loader_Filesystem(realpath($this->viewPath))
);
return $twig->render($view, $data);
} | [
"protected",
"function",
"generateView",
"(",
"$",
"view",
",",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"viewPath",
")",
")",
"{",
"return",
"$",
"view",
";",
"}",
"$",
"twig",
"=",
"new",
"Twig_Environment",
"(",
"new",
"Twig_Loader_Filesystem",
"(",
"realpath",
"(",
"$",
"this",
"->",
"viewPath",
")",
")",
")",
";",
"return",
"$",
"twig",
"->",
"render",
"(",
"$",
"view",
",",
"$",
"data",
")",
";",
"}"
] | Generate view for the pdf file.
@param string $view
@param array $data
@return string | [
"Generate",
"view",
"for",
"the",
"pdf",
"file",
"."
] | 798bad6b140a78d0c1a1823e12da3ed0e4f012ec | https://github.com/IftekherSunny/PDF/blob/798bad6b140a78d0c1a1823e12da3ed0e4f012ec/src/PDF.php#L222-L233 |
13,152 | IftekherSunny/PDF | src/PDF.php | PDF.getConfigurationFile | protected function getConfigurationFile()
{
if(!is_null($this->configPath)) {
return realpath($this->configPath);
} elseif(function_exists('base_path') and file_exists($phantomConfiguration = base_path() . DIRECTORY_SEPARATOR . 'SunPdf.js')) {
return realpath($phantomConfiguration);
} else {
return realpath(__DIR__.'/../phantom.js');
}
} | php | protected function getConfigurationFile()
{
if(!is_null($this->configPath)) {
return realpath($this->configPath);
} elseif(function_exists('base_path') and file_exists($phantomConfiguration = base_path() . DIRECTORY_SEPARATOR . 'SunPdf.js')) {
return realpath($phantomConfiguration);
} else {
return realpath(__DIR__.'/../phantom.js');
}
} | [
"protected",
"function",
"getConfigurationFile",
"(",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"configPath",
")",
")",
"{",
"return",
"realpath",
"(",
"$",
"this",
"->",
"configPath",
")",
";",
"}",
"elseif",
"(",
"function_exists",
"(",
"'base_path'",
")",
"and",
"file_exists",
"(",
"$",
"phantomConfiguration",
"=",
"base_path",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"'SunPdf.js'",
")",
")",
"{",
"return",
"realpath",
"(",
"$",
"phantomConfiguration",
")",
";",
"}",
"else",
"{",
"return",
"realpath",
"(",
"__DIR__",
".",
"'/../phantom.js'",
")",
";",
"}",
"}"
] | Get PhantomJS configuration file.
@return string | [
"Get",
"PhantomJS",
"configuration",
"file",
"."
] | 798bad6b140a78d0c1a1823e12da3ed0e4f012ec | https://github.com/IftekherSunny/PDF/blob/798bad6b140a78d0c1a1823e12da3ed0e4f012ec/src/PDF.php#L257-L266 |
13,153 | fuelphp/filesystem | src/Filter.php | Filter.isCorrectType | public function isCorrectType($type, $path)
{
if ( ! $type)
{
return true;
}
if ( ! isset($this->typeCache[$path]))
{
$this->typeCache[$path] = is_file($path) ? 'file' : 'dir';
}
return $this->typeCache[$path] === $type;
} | php | public function isCorrectType($type, $path)
{
if ( ! $type)
{
return true;
}
if ( ! isset($this->typeCache[$path]))
{
$this->typeCache[$path] = is_file($path) ? 'file' : 'dir';
}
return $this->typeCache[$path] === $type;
} | [
"public",
"function",
"isCorrectType",
"(",
"$",
"type",
",",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"$",
"type",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"typeCache",
"[",
"$",
"path",
"]",
")",
")",
"{",
"$",
"this",
"->",
"typeCache",
"[",
"$",
"path",
"]",
"=",
"is_file",
"(",
"$",
"path",
")",
"?",
"'file'",
":",
"'dir'",
";",
"}",
"return",
"$",
"this",
"->",
"typeCache",
"[",
"$",
"path",
"]",
"===",
"$",
"type",
";",
"}"
] | Checks wether an path is of the correct type, dir or file
@param string $type
@param string $path
@return boolean | [
"Checks",
"wether",
"an",
"path",
"is",
"of",
"the",
"correct",
"type",
"dir",
"or",
"file"
] | 770a8cb04caca920af8029d7aad7208bc0592743 | https://github.com/fuelphp/filesystem/blob/770a8cb04caca920af8029d7aad7208bc0592743/src/Filter.php#L33-L46 |
13,154 | fuelphp/filesystem | src/Filter.php | Filter.filter | public function filter(array $contents)
{
$filtered = array();
$this->typeCache = array();
foreach ($contents as $item)
{
$passed = true;
foreach ($this->filters as $filter)
{
$correctType = $this->isCorrectType($filter['type'], $item);
if ($correctType and preg_match($filter['pattern'], $item) !== $expected)
{
$passed = false;
}
}
if ($passed)
{
$filtered[] = $item;
}
}
return $contents;
} | php | public function filter(array $contents)
{
$filtered = array();
$this->typeCache = array();
foreach ($contents as $item)
{
$passed = true;
foreach ($this->filters as $filter)
{
$correctType = $this->isCorrectType($filter['type'], $item);
if ($correctType and preg_match($filter['pattern'], $item) !== $expected)
{
$passed = false;
}
}
if ($passed)
{
$filtered[] = $item;
}
}
return $contents;
} | [
"public",
"function",
"filter",
"(",
"array",
"$",
"contents",
")",
"{",
"$",
"filtered",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"typeCache",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"contents",
"as",
"$",
"item",
")",
"{",
"$",
"passed",
"=",
"true",
";",
"foreach",
"(",
"$",
"this",
"->",
"filters",
"as",
"$",
"filter",
")",
"{",
"$",
"correctType",
"=",
"$",
"this",
"->",
"isCorrectType",
"(",
"$",
"filter",
"[",
"'type'",
"]",
",",
"$",
"item",
")",
";",
"if",
"(",
"$",
"correctType",
"and",
"preg_match",
"(",
"$",
"filter",
"[",
"'pattern'",
"]",
",",
"$",
"item",
")",
"!==",
"$",
"expected",
")",
"{",
"$",
"passed",
"=",
"false",
";",
"}",
"}",
"if",
"(",
"$",
"passed",
")",
"{",
"$",
"filtered",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"}",
"return",
"$",
"contents",
";",
"}"
] | Filters a batch of filesystem entries
@param array $contents
@return array | [
"Filters",
"a",
"batch",
"of",
"filesystem",
"entries"
] | 770a8cb04caca920af8029d7aad7208bc0592743 | https://github.com/fuelphp/filesystem/blob/770a8cb04caca920af8029d7aad7208bc0592743/src/Filter.php#L55-L81 |
13,155 | geniv/nette-thumbnail | src/Thumbnail.php | Thumbnail.cleanThumbnail | public static function cleanThumbnail(): array
{
$result = [];
$files = Finder::findFiles('*')->in(self::$parameters['thumbPath']);
foreach ($files as $file) {
if (unlink($file->getPathname())) {
$result[] = $file->getPathname();
}
}
return $result;
} | php | public static function cleanThumbnail(): array
{
$result = [];
$files = Finder::findFiles('*')->in(self::$parameters['thumbPath']);
foreach ($files as $file) {
if (unlink($file->getPathname())) {
$result[] = $file->getPathname();
}
}
return $result;
} | [
"public",
"static",
"function",
"cleanThumbnail",
"(",
")",
":",
"array",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"files",
"=",
"Finder",
"::",
"findFiles",
"(",
"'*'",
")",
"->",
"in",
"(",
"self",
"::",
"$",
"parameters",
"[",
"'thumbPath'",
"]",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"unlink",
"(",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"file",
"->",
"getPathname",
"(",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Clean thumbnail.
@return array | [
"Clean",
"thumbnail",
"."
] | 408fc61e0df99113a873ca1ec463e4fc85016eed | https://github.com/geniv/nette-thumbnail/blob/408fc61e0df99113a873ca1ec463e4fc85016eed/src/Thumbnail.php#L47-L57 |
13,156 | geniv/nette-thumbnail | src/Thumbnail.php | Thumbnail.getThumbFiles | private static function getThumbFiles(): array
{
$result = [];
$thumbFinder = Finder::findFiles('*')->in(self::$parameters['thumbPath']);
foreach ($thumbFinder as $file) {
$basename = $file->getBaseName();
$specialDelimiter = strrpos($basename, '_');
// $pathEnd = strrpos($basename, 'pew');
// $prefixPath = null;
// if ($pathEnd) {
// $prefixPath = str_replace('S', '/', substr($basename, $specialDelimiter + 2, $pathEnd - strlen($basename)));
// }
$lastDot = strrpos($basename, '.');
// restore old name
$result[$file->getRealPath()] = substr($basename, 0, $specialDelimiter) . substr($basename, $lastDot);
}
return $result;
} | php | private static function getThumbFiles(): array
{
$result = [];
$thumbFinder = Finder::findFiles('*')->in(self::$parameters['thumbPath']);
foreach ($thumbFinder as $file) {
$basename = $file->getBaseName();
$specialDelimiter = strrpos($basename, '_');
// $pathEnd = strrpos($basename, 'pew');
// $prefixPath = null;
// if ($pathEnd) {
// $prefixPath = str_replace('S', '/', substr($basename, $specialDelimiter + 2, $pathEnd - strlen($basename)));
// }
$lastDot = strrpos($basename, '.');
// restore old name
$result[$file->getRealPath()] = substr($basename, 0, $specialDelimiter) . substr($basename, $lastDot);
}
return $result;
} | [
"private",
"static",
"function",
"getThumbFiles",
"(",
")",
":",
"array",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"thumbFinder",
"=",
"Finder",
"::",
"findFiles",
"(",
"'*'",
")",
"->",
"in",
"(",
"self",
"::",
"$",
"parameters",
"[",
"'thumbPath'",
"]",
")",
";",
"foreach",
"(",
"$",
"thumbFinder",
"as",
"$",
"file",
")",
"{",
"$",
"basename",
"=",
"$",
"file",
"->",
"getBaseName",
"(",
")",
";",
"$",
"specialDelimiter",
"=",
"strrpos",
"(",
"$",
"basename",
",",
"'_'",
")",
";",
"// $pathEnd = strrpos($basename, 'pew');",
"// $prefixPath = null;",
"// if ($pathEnd) {",
"// $prefixPath = str_replace('S', '/', substr($basename, $specialDelimiter + 2, $pathEnd - strlen($basename)));",
"// }",
"$",
"lastDot",
"=",
"strrpos",
"(",
"$",
"basename",
",",
"'.'",
")",
";",
"// restore old name",
"$",
"result",
"[",
"$",
"file",
"->",
"getRealPath",
"(",
")",
"]",
"=",
"substr",
"(",
"$",
"basename",
",",
"0",
",",
"$",
"specialDelimiter",
")",
".",
"substr",
"(",
"$",
"basename",
",",
"$",
"lastDot",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get thumb files.
@return array | [
"Get",
"thumb",
"files",
"."
] | 408fc61e0df99113a873ca1ec463e4fc85016eed | https://github.com/geniv/nette-thumbnail/blob/408fc61e0df99113a873ca1ec463e4fc85016eed/src/Thumbnail.php#L65-L82 |
13,157 | geniv/nette-thumbnail | src/Thumbnail.php | Thumbnail.getPathFiles | private static function getPathFiles(array $path): array
{
// load external files
$result = [];
$pathFinder = Finder::findFiles('*')->in($path);
foreach ($pathFinder as $file) {
$result[$file->getRealPath()] = $file->getBaseName();
}
return $result;
} | php | private static function getPathFiles(array $path): array
{
// load external files
$result = [];
$pathFinder = Finder::findFiles('*')->in($path);
foreach ($pathFinder as $file) {
$result[$file->getRealPath()] = $file->getBaseName();
}
return $result;
} | [
"private",
"static",
"function",
"getPathFiles",
"(",
"array",
"$",
"path",
")",
":",
"array",
"{",
"// load external files",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"pathFinder",
"=",
"Finder",
"::",
"findFiles",
"(",
"'*'",
")",
"->",
"in",
"(",
"$",
"path",
")",
";",
"foreach",
"(",
"$",
"pathFinder",
"as",
"$",
"file",
")",
"{",
"$",
"result",
"[",
"$",
"file",
"->",
"getRealPath",
"(",
")",
"]",
"=",
"$",
"file",
"->",
"getBaseName",
"(",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get path files.
@param array $path
@return array | [
"Get",
"path",
"files",
"."
] | 408fc61e0df99113a873ca1ec463e4fc85016eed | https://github.com/geniv/nette-thumbnail/blob/408fc61e0df99113a873ca1ec463e4fc85016eed/src/Thumbnail.php#L91-L100 |
13,158 | geniv/nette-thumbnail | src/Thumbnail.php | Thumbnail.synchronizeThumbnail | public static function synchronizeThumbnail(array $path): array
{
$result = [];
//TODO rebuild or removed - it was be lite check
// // remove duplicate files
// $counts = array_count_values($thumbFiles);
// $duplicate = array_filter($counts, function ($row) { return $row > 1; });
// foreach ($duplicate as $item => $count) {
// $pathInfo = pathinfo($item);
// $duplicateFinder = Finder::findFiles($pathInfo['filename'] . '*')->in(self::$parameters['thumbPath']);
// foreach ($duplicateFinder as $duplicateItem) {
// if (unlink($duplicateItem->getPathname())) {
// $result[] = $duplicateItem->getPathname();
// }
// }
// }
// load thumbnail files
$thumbFiles = self::getThumbFiles();
// load path files
$pathFiles = self::getPathFiles($path);
// remove different files
$diff = array_diff($thumbFiles, $pathFiles);
foreach ($diff as $oldName => $file) {
if (unlink($oldName)) {
$result[] = $oldName;
}
}
return $result;
} | php | public static function synchronizeThumbnail(array $path): array
{
$result = [];
//TODO rebuild or removed - it was be lite check
// // remove duplicate files
// $counts = array_count_values($thumbFiles);
// $duplicate = array_filter($counts, function ($row) { return $row > 1; });
// foreach ($duplicate as $item => $count) {
// $pathInfo = pathinfo($item);
// $duplicateFinder = Finder::findFiles($pathInfo['filename'] . '*')->in(self::$parameters['thumbPath']);
// foreach ($duplicateFinder as $duplicateItem) {
// if (unlink($duplicateItem->getPathname())) {
// $result[] = $duplicateItem->getPathname();
// }
// }
// }
// load thumbnail files
$thumbFiles = self::getThumbFiles();
// load path files
$pathFiles = self::getPathFiles($path);
// remove different files
$diff = array_diff($thumbFiles, $pathFiles);
foreach ($diff as $oldName => $file) {
if (unlink($oldName)) {
$result[] = $oldName;
}
}
return $result;
} | [
"public",
"static",
"function",
"synchronizeThumbnail",
"(",
"array",
"$",
"path",
")",
":",
"array",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"//TODO rebuild or removed - it was be lite check",
"// // remove duplicate files",
"// $counts = array_count_values($thumbFiles);",
"// $duplicate = array_filter($counts, function ($row) { return $row > 1; });",
"// foreach ($duplicate as $item => $count) {",
"// $pathInfo = pathinfo($item);",
"// $duplicateFinder = Finder::findFiles($pathInfo['filename'] . '*')->in(self::$parameters['thumbPath']);",
"// foreach ($duplicateFinder as $duplicateItem) {",
"// if (unlink($duplicateItem->getPathname())) {",
"// $result[] = $duplicateItem->getPathname();",
"// }",
"// }",
"// }",
"// load thumbnail files",
"$",
"thumbFiles",
"=",
"self",
"::",
"getThumbFiles",
"(",
")",
";",
"// load path files",
"$",
"pathFiles",
"=",
"self",
"::",
"getPathFiles",
"(",
"$",
"path",
")",
";",
"// remove different files",
"$",
"diff",
"=",
"array_diff",
"(",
"$",
"thumbFiles",
",",
"$",
"pathFiles",
")",
";",
"foreach",
"(",
"$",
"diff",
"as",
"$",
"oldName",
"=>",
"$",
"file",
")",
"{",
"if",
"(",
"unlink",
"(",
"$",
"oldName",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"oldName",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Synchronize thumbnail.
@param array $path
@return array | [
"Synchronize",
"thumbnail",
"."
] | 408fc61e0df99113a873ca1ec463e4fc85016eed | https://github.com/geniv/nette-thumbnail/blob/408fc61e0df99113a873ca1ec463e4fc85016eed/src/Thumbnail.php#L109-L141 |
13,159 | geniv/nette-thumbnail | src/Thumbnail.php | Thumbnail.getUnusedFiles | public static function getUnusedFiles(array $path): array
{
// load thumbnail files
$thumbFiles = self::getThumbFiles();
// load path files
$pathFiles = self::getPathFiles($path);
return $diff = array_diff($pathFiles, $thumbFiles);
} | php | public static function getUnusedFiles(array $path): array
{
// load thumbnail files
$thumbFiles = self::getThumbFiles();
// load path files
$pathFiles = self::getPathFiles($path);
return $diff = array_diff($pathFiles, $thumbFiles);
} | [
"public",
"static",
"function",
"getUnusedFiles",
"(",
"array",
"$",
"path",
")",
":",
"array",
"{",
"// load thumbnail files",
"$",
"thumbFiles",
"=",
"self",
"::",
"getThumbFiles",
"(",
")",
";",
"// load path files",
"$",
"pathFiles",
"=",
"self",
"::",
"getPathFiles",
"(",
"$",
"path",
")",
";",
"return",
"$",
"diff",
"=",
"array_diff",
"(",
"$",
"pathFiles",
",",
"$",
"thumbFiles",
")",
";",
"}"
] | Get unused files.
@param array $path
@return array | [
"Get",
"unused",
"files",
"."
] | 408fc61e0df99113a873ca1ec463e4fc85016eed | https://github.com/geniv/nette-thumbnail/blob/408fc61e0df99113a873ca1ec463e4fc85016eed/src/Thumbnail.php#L150-L159 |
13,160 | geniv/nette-thumbnail | src/Thumbnail.php | Thumbnail.isSrcPathExists | public static function isSrcPathExists(string $path, string $file = null): bool
{
$src = self::$parameters['dir'] . $path . $file;
return file_exists($src) && is_file($src);
} | php | public static function isSrcPathExists(string $path, string $file = null): bool
{
$src = self::$parameters['dir'] . $path . $file;
return file_exists($src) && is_file($src);
} | [
"public",
"static",
"function",
"isSrcPathExists",
"(",
"string",
"$",
"path",
",",
"string",
"$",
"file",
"=",
"null",
")",
":",
"bool",
"{",
"$",
"src",
"=",
"self",
"::",
"$",
"parameters",
"[",
"'dir'",
"]",
".",
"$",
"path",
".",
"$",
"file",
";",
"return",
"file_exists",
"(",
"$",
"src",
")",
"&&",
"is_file",
"(",
"$",
"src",
")",
";",
"}"
] | Is src path exists.
@param string $path
@param string|null $file
@return bool | [
"Is",
"src",
"path",
"exists",
"."
] | 408fc61e0df99113a873ca1ec463e4fc85016eed | https://github.com/geniv/nette-thumbnail/blob/408fc61e0df99113a873ca1ec463e4fc85016eed/src/Thumbnail.php#L169-L173 |
13,161 | geniv/nette-thumbnail | src/Thumbnail.php | Thumbnail.getSrcPath | public static function getSrcPath(string $path, string $file = null, string $width = null, string $height = null, array $flags = [], int $quality = null): string
{
$cacheName = 'getSrcPath' . $path . $file . $width . $height . implode($flags) . $quality;
$destination = (self::$parameters['cache'] ? self::$cache->load($cacheName) : null);
if ($destination === null) {
// create thumbnail dir
if (!file_exists(self::$parameters['thumbPath'])) {
throw new \Exception('Path: ' . self::$parameters['thumbPath'] . ' does not exist!');
}
$template = self::$parameters['template'];
if (isset($template[$path])) {
// resize image by template
$conf = $template[$path];
$destination = self::resizeImage($conf['path'], $file, $conf['width'] ?? null, $conf['height'] ?? null, $conf['flags'] ?? [], $conf['quality'] ?? null);
} else {
// resize image by path
$destination = self::resizeImage($path, $file, $width, $height, $flags, $quality);
}
if (self::$parameters['cache']) { // only for cache
try {
self::$cache->save($cacheName, $destination, [Cache::FILES => [self::$parameters['dir'] . $path . $file]]);
} catch (\Throwable $e) {
}
}
}
return substr($destination, strlen(realpath(self::$parameters['dir'])) + 1);
} | php | public static function getSrcPath(string $path, string $file = null, string $width = null, string $height = null, array $flags = [], int $quality = null): string
{
$cacheName = 'getSrcPath' . $path . $file . $width . $height . implode($flags) . $quality;
$destination = (self::$parameters['cache'] ? self::$cache->load($cacheName) : null);
if ($destination === null) {
// create thumbnail dir
if (!file_exists(self::$parameters['thumbPath'])) {
throw new \Exception('Path: ' . self::$parameters['thumbPath'] . ' does not exist!');
}
$template = self::$parameters['template'];
if (isset($template[$path])) {
// resize image by template
$conf = $template[$path];
$destination = self::resizeImage($conf['path'], $file, $conf['width'] ?? null, $conf['height'] ?? null, $conf['flags'] ?? [], $conf['quality'] ?? null);
} else {
// resize image by path
$destination = self::resizeImage($path, $file, $width, $height, $flags, $quality);
}
if (self::$parameters['cache']) { // only for cache
try {
self::$cache->save($cacheName, $destination, [Cache::FILES => [self::$parameters['dir'] . $path . $file]]);
} catch (\Throwable $e) {
}
}
}
return substr($destination, strlen(realpath(self::$parameters['dir'])) + 1);
} | [
"public",
"static",
"function",
"getSrcPath",
"(",
"string",
"$",
"path",
",",
"string",
"$",
"file",
"=",
"null",
",",
"string",
"$",
"width",
"=",
"null",
",",
"string",
"$",
"height",
"=",
"null",
",",
"array",
"$",
"flags",
"=",
"[",
"]",
",",
"int",
"$",
"quality",
"=",
"null",
")",
":",
"string",
"{",
"$",
"cacheName",
"=",
"'getSrcPath'",
".",
"$",
"path",
".",
"$",
"file",
".",
"$",
"width",
".",
"$",
"height",
".",
"implode",
"(",
"$",
"flags",
")",
".",
"$",
"quality",
";",
"$",
"destination",
"=",
"(",
"self",
"::",
"$",
"parameters",
"[",
"'cache'",
"]",
"?",
"self",
"::",
"$",
"cache",
"->",
"load",
"(",
"$",
"cacheName",
")",
":",
"null",
")",
";",
"if",
"(",
"$",
"destination",
"===",
"null",
")",
"{",
"// create thumbnail dir",
"if",
"(",
"!",
"file_exists",
"(",
"self",
"::",
"$",
"parameters",
"[",
"'thumbPath'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Path: '",
".",
"self",
"::",
"$",
"parameters",
"[",
"'thumbPath'",
"]",
".",
"' does not exist!'",
")",
";",
"}",
"$",
"template",
"=",
"self",
"::",
"$",
"parameters",
"[",
"'template'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"template",
"[",
"$",
"path",
"]",
")",
")",
"{",
"// resize image by template",
"$",
"conf",
"=",
"$",
"template",
"[",
"$",
"path",
"]",
";",
"$",
"destination",
"=",
"self",
"::",
"resizeImage",
"(",
"$",
"conf",
"[",
"'path'",
"]",
",",
"$",
"file",
",",
"$",
"conf",
"[",
"'width'",
"]",
"??",
"null",
",",
"$",
"conf",
"[",
"'height'",
"]",
"??",
"null",
",",
"$",
"conf",
"[",
"'flags'",
"]",
"??",
"[",
"]",
",",
"$",
"conf",
"[",
"'quality'",
"]",
"??",
"null",
")",
";",
"}",
"else",
"{",
"// resize image by path",
"$",
"destination",
"=",
"self",
"::",
"resizeImage",
"(",
"$",
"path",
",",
"$",
"file",
",",
"$",
"width",
",",
"$",
"height",
",",
"$",
"flags",
",",
"$",
"quality",
")",
";",
"}",
"if",
"(",
"self",
"::",
"$",
"parameters",
"[",
"'cache'",
"]",
")",
"{",
"// only for cache",
"try",
"{",
"self",
"::",
"$",
"cache",
"->",
"save",
"(",
"$",
"cacheName",
",",
"$",
"destination",
",",
"[",
"Cache",
"::",
"FILES",
"=>",
"[",
"self",
"::",
"$",
"parameters",
"[",
"'dir'",
"]",
".",
"$",
"path",
".",
"$",
"file",
"]",
"]",
")",
";",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
"e",
")",
"{",
"}",
"}",
"}",
"return",
"substr",
"(",
"$",
"destination",
",",
"strlen",
"(",
"realpath",
"(",
"self",
"::",
"$",
"parameters",
"[",
"'dir'",
"]",
")",
")",
"+",
"1",
")",
";",
"}"
] | Get src path.
@param string $path
@param string|null $file
@param string|null $width
@param string|null $height
@param array $flags
@param int|null $quality
@return string
@throws \Exception | [
"Get",
"src",
"path",
"."
] | 408fc61e0df99113a873ca1ec463e4fc85016eed | https://github.com/geniv/nette-thumbnail/blob/408fc61e0df99113a873ca1ec463e4fc85016eed/src/Thumbnail.php#L188-L216 |
13,162 | geniv/nette-thumbnail | src/Thumbnail.php | Thumbnail.getImageFlag | private static function getImageFlag(array $flags): int
{
$res = 0;
foreach ($flags as $flag) {
$res |= constant(Image::class . '::' . $flag);
}
return $res;
} | php | private static function getImageFlag(array $flags): int
{
$res = 0;
foreach ($flags as $flag) {
$res |= constant(Image::class . '::' . $flag);
}
return $res;
} | [
"private",
"static",
"function",
"getImageFlag",
"(",
"array",
"$",
"flags",
")",
":",
"int",
"{",
"$",
"res",
"=",
"0",
";",
"foreach",
"(",
"$",
"flags",
"as",
"$",
"flag",
")",
"{",
"$",
"res",
"|=",
"constant",
"(",
"Image",
"::",
"class",
".",
"'::'",
".",
"$",
"flag",
")",
";",
"}",
"return",
"$",
"res",
";",
"}"
] | Get image flag.
@param array $flags
@return int | [
"Get",
"image",
"flag",
"."
] | 408fc61e0df99113a873ca1ec463e4fc85016eed | https://github.com/geniv/nette-thumbnail/blob/408fc61e0df99113a873ca1ec463e4fc85016eed/src/Thumbnail.php#L225-L232 |
13,163 | PandaPlatform/framework | src/Panda/Support/Helpers/ArrayHelper.php | ArrayHelper.get | public static function get($array, $key = null, $default = null, $useDotSyntax = false)
{
// Check arguments
if (empty($array)) {
return $default;
}
// Check if key is empty
if (is_null($key)) {
return $array;
}
// Check if value exists as is
if (isset($array[$key])) {
return $array[$key];
}
// Return default value, without dot syntax
if (!$useDotSyntax) {
return $default;
}
// Split name using dots
$keyParts = explode('.', $key);
if (count($keyParts) == 1) {
return isset($array[$key]) ? $array[$key] : $default;
}
// Recursive call
$base = $keyParts[0];
unset($keyParts[0]);
// Check if the base array exists
if (!isset($array[$base])) {
return $default;
}
// Get key, base array and continue
$key = implode('.', $keyParts);
$array = $array[$base];
return static::get($array, $key, $default, $useDotSyntax);
} | php | public static function get($array, $key = null, $default = null, $useDotSyntax = false)
{
// Check arguments
if (empty($array)) {
return $default;
}
// Check if key is empty
if (is_null($key)) {
return $array;
}
// Check if value exists as is
if (isset($array[$key])) {
return $array[$key];
}
// Return default value, without dot syntax
if (!$useDotSyntax) {
return $default;
}
// Split name using dots
$keyParts = explode('.', $key);
if (count($keyParts) == 1) {
return isset($array[$key]) ? $array[$key] : $default;
}
// Recursive call
$base = $keyParts[0];
unset($keyParts[0]);
// Check if the base array exists
if (!isset($array[$base])) {
return $default;
}
// Get key, base array and continue
$key = implode('.', $keyParts);
$array = $array[$base];
return static::get($array, $key, $default, $useDotSyntax);
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"array",
",",
"$",
"key",
"=",
"null",
",",
"$",
"default",
"=",
"null",
",",
"$",
"useDotSyntax",
"=",
"false",
")",
"{",
"// Check arguments",
"if",
"(",
"empty",
"(",
"$",
"array",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"// Check if key is empty",
"if",
"(",
"is_null",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"array",
";",
"}",
"// Check if value exists as is",
"if",
"(",
"isset",
"(",
"$",
"array",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"array",
"[",
"$",
"key",
"]",
";",
"}",
"// Return default value, without dot syntax",
"if",
"(",
"!",
"$",
"useDotSyntax",
")",
"{",
"return",
"$",
"default",
";",
"}",
"// Split name using dots",
"$",
"keyParts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"if",
"(",
"count",
"(",
"$",
"keyParts",
")",
"==",
"1",
")",
"{",
"return",
"isset",
"(",
"$",
"array",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"array",
"[",
"$",
"key",
"]",
":",
"$",
"default",
";",
"}",
"// Recursive call",
"$",
"base",
"=",
"$",
"keyParts",
"[",
"0",
"]",
";",
"unset",
"(",
"$",
"keyParts",
"[",
"0",
"]",
")",
";",
"// Check if the base array exists",
"if",
"(",
"!",
"isset",
"(",
"$",
"array",
"[",
"$",
"base",
"]",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"// Get key, base array and continue",
"$",
"key",
"=",
"implode",
"(",
"'.'",
",",
"$",
"keyParts",
")",
";",
"$",
"array",
"=",
"$",
"array",
"[",
"$",
"base",
"]",
";",
"return",
"static",
"::",
"get",
"(",
"$",
"array",
",",
"$",
"key",
",",
"$",
"default",
",",
"$",
"useDotSyntax",
")",
";",
"}"
] | Get an item from an array.
@param array $array
@param string $key
@param mixed $default
@param bool $useDotSyntax
@return mixed | [
"Get",
"an",
"item",
"from",
"an",
"array",
"."
] | a78cf051b379896b5a4d5df620988e37a0e632f5 | https://github.com/PandaPlatform/framework/blob/a78cf051b379896b5a4d5df620988e37a0e632f5/src/Panda/Support/Helpers/ArrayHelper.php#L32-L74 |
13,164 | PandaPlatform/framework | src/Panda/Support/Helpers/ArrayHelper.php | ArrayHelper.filter | public static function filter(array $array, $callback = null, $default = [], $length = null)
{
// Set result array
$result = [];
// Check callback
if (is_callable($callback)) {
// Filter array elements
foreach ($array as $key => $value) {
if (call_user_func($callback, $key, $value)) {
$result[$key] = $value;
}
}
} else {
reset($array);
$result = empty($array) ? null : $array;
}
// Return result array or default value
return $result ? array_slice($result, 0, $length) : EvalHelper::evaluate($default);
} | php | public static function filter(array $array, $callback = null, $default = [], $length = null)
{
// Set result array
$result = [];
// Check callback
if (is_callable($callback)) {
// Filter array elements
foreach ($array as $key => $value) {
if (call_user_func($callback, $key, $value)) {
$result[$key] = $value;
}
}
} else {
reset($array);
$result = empty($array) ? null : $array;
}
// Return result array or default value
return $result ? array_slice($result, 0, $length) : EvalHelper::evaluate($default);
} | [
"public",
"static",
"function",
"filter",
"(",
"array",
"$",
"array",
",",
"$",
"callback",
"=",
"null",
",",
"$",
"default",
"=",
"[",
"]",
",",
"$",
"length",
"=",
"null",
")",
"{",
"// Set result array",
"$",
"result",
"=",
"[",
"]",
";",
"// Check callback",
"if",
"(",
"is_callable",
"(",
"$",
"callback",
")",
")",
"{",
"// Filter array elements",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"call_user_func",
"(",
"$",
"callback",
",",
"$",
"key",
",",
"$",
"value",
")",
")",
"{",
"$",
"result",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"else",
"{",
"reset",
"(",
"$",
"array",
")",
";",
"$",
"result",
"=",
"empty",
"(",
"$",
"array",
")",
"?",
"null",
":",
"$",
"array",
";",
"}",
"// Return result array or default value",
"return",
"$",
"result",
"?",
"array_slice",
"(",
"$",
"result",
",",
"0",
",",
"$",
"length",
")",
":",
"EvalHelper",
"::",
"evaluate",
"(",
"$",
"default",
")",
";",
"}"
] | Filter array elements with a given callback function.
It returns the item that matches the callback function.
If the callback function is empty, it will return the array as is.
If the array is empty or no element matches the callback, it will return the default value.
The callback function should accept as parameters the key and the value of the array
and it should return true or false if the element matches the purpose of the filter.
@param array $array The array to filter elements
@param callable|null $callback The filter as callback
@param mixed $default The default value in case no element is found
@param int|null $length The length of matched elements to return, as limit
@return mixed | [
"Filter",
"array",
"elements",
"with",
"a",
"given",
"callback",
"function",
"."
] | a78cf051b379896b5a4d5df620988e37a0e632f5 | https://github.com/PandaPlatform/framework/blob/a78cf051b379896b5a4d5df620988e37a0e632f5/src/Panda/Support/Helpers/ArrayHelper.php#L163-L184 |
13,165 | PandaPlatform/framework | src/Panda/Support/Helpers/ArrayHelper.php | ArrayHelper.merge | public static function merge(array $array1, array $array2, $deep = false)
{
// Normal array merge
if (!$deep) {
return array_merge($array1, $array2);
}
// Perform a deep merge
$merged = $array1;
foreach ($array2 as $key => $value) {
if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
$merged[$key] = static::merge($merged[$key], $value, $deep);
} else if (is_numeric($key)) {
if (!in_array($value, $merged)) {
$merged[] = $value;
}
} else {
$merged[$key] = $value;
}
}
return $merged;
} | php | public static function merge(array $array1, array $array2, $deep = false)
{
// Normal array merge
if (!$deep) {
return array_merge($array1, $array2);
}
// Perform a deep merge
$merged = $array1;
foreach ($array2 as $key => $value) {
if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
$merged[$key] = static::merge($merged[$key], $value, $deep);
} else if (is_numeric($key)) {
if (!in_array($value, $merged)) {
$merged[] = $value;
}
} else {
$merged[$key] = $value;
}
}
return $merged;
} | [
"public",
"static",
"function",
"merge",
"(",
"array",
"$",
"array1",
",",
"array",
"$",
"array2",
",",
"$",
"deep",
"=",
"false",
")",
"{",
"// Normal array merge",
"if",
"(",
"!",
"$",
"deep",
")",
"{",
"return",
"array_merge",
"(",
"$",
"array1",
",",
"$",
"array2",
")",
";",
"}",
"// Perform a deep merge",
"$",
"merged",
"=",
"$",
"array1",
";",
"foreach",
"(",
"$",
"array2",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"isset",
"(",
"$",
"merged",
"[",
"$",
"key",
"]",
")",
"&&",
"is_array",
"(",
"$",
"merged",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"merged",
"[",
"$",
"key",
"]",
"=",
"static",
"::",
"merge",
"(",
"$",
"merged",
"[",
"$",
"key",
"]",
",",
"$",
"value",
",",
"$",
"deep",
")",
";",
"}",
"else",
"if",
"(",
"is_numeric",
"(",
"$",
"key",
")",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"value",
",",
"$",
"merged",
")",
")",
"{",
"$",
"merged",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"else",
"{",
"$",
"merged",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"merged",
";",
"}"
] | Perform a merge on the given two arrays.
Deep merge will merge the two arrays in full depth.
@param array $array1
@param array $array2
@param bool $deep
@return array | [
"Perform",
"a",
"merge",
"on",
"the",
"given",
"two",
"arrays",
".",
"Deep",
"merge",
"will",
"merge",
"the",
"two",
"arrays",
"in",
"full",
"depth",
"."
] | a78cf051b379896b5a4d5df620988e37a0e632f5 | https://github.com/PandaPlatform/framework/blob/a78cf051b379896b5a4d5df620988e37a0e632f5/src/Panda/Support/Helpers/ArrayHelper.php#L196-L219 |
13,166 | PandaPlatform/framework | src/Panda/Support/Helpers/ArrayHelper.php | ArrayHelper.toKeyIndex | public static function toKeyIndex($collection, $key, $useDotSyntax = false)
{
$keyIndexArray = [];
foreach ($collection as $item) {
$itemArray = is_array($item) ? $item : (method_exists($item, 'toArray') ? $item->toArray() : []);
$keyValue = self::get($itemArray, $key, null, $useDotSyntax);
$keyIndexArray[$keyValue] = $itemArray;
}
return $keyIndexArray;
} | php | public static function toKeyIndex($collection, $key, $useDotSyntax = false)
{
$keyIndexArray = [];
foreach ($collection as $item) {
$itemArray = is_array($item) ? $item : (method_exists($item, 'toArray') ? $item->toArray() : []);
$keyValue = self::get($itemArray, $key, null, $useDotSyntax);
$keyIndexArray[$keyValue] = $itemArray;
}
return $keyIndexArray;
} | [
"public",
"static",
"function",
"toKeyIndex",
"(",
"$",
"collection",
",",
"$",
"key",
",",
"$",
"useDotSyntax",
"=",
"false",
")",
"{",
"$",
"keyIndexArray",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"item",
")",
"{",
"$",
"itemArray",
"=",
"is_array",
"(",
"$",
"item",
")",
"?",
"$",
"item",
":",
"(",
"method_exists",
"(",
"$",
"item",
",",
"'toArray'",
")",
"?",
"$",
"item",
"->",
"toArray",
"(",
")",
":",
"[",
"]",
")",
";",
"$",
"keyValue",
"=",
"self",
"::",
"get",
"(",
"$",
"itemArray",
",",
"$",
"key",
",",
"null",
",",
"$",
"useDotSyntax",
")",
";",
"$",
"keyIndexArray",
"[",
"$",
"keyValue",
"]",
"=",
"$",
"itemArray",
";",
"}",
"return",
"$",
"keyIndexArray",
";",
"}"
] | Return the array and replace the default keys with the values
of the array, based on the given key.
@param array|object[]|mixed $collection
@param string $key
@param bool $useDotSyntax
@return array | [
"Return",
"the",
"array",
"and",
"replace",
"the",
"default",
"keys",
"with",
"the",
"values",
"of",
"the",
"array",
"based",
"on",
"the",
"given",
"key",
"."
] | a78cf051b379896b5a4d5df620988e37a0e632f5 | https://github.com/PandaPlatform/framework/blob/a78cf051b379896b5a4d5df620988e37a0e632f5/src/Panda/Support/Helpers/ArrayHelper.php#L250-L260 |
13,167 | PandaPlatform/framework | src/Panda/Support/Helpers/ArrayHelper.php | ArrayHelper.toKeyGroup | public static function toKeyGroup($collection, $key, $useDotSyntax = false)
{
$keyGroupArray = [];
foreach ($collection as $item) {
$itemArray = is_array($item) ? $item : (method_exists($item, 'toArray') ? $item->toArray() : []);
$keyValue = self::get($itemArray, $key, null, $useDotSyntax);
$keyGroupArray[$keyValue][] = $itemArray;
}
return $keyGroupArray;
} | php | public static function toKeyGroup($collection, $key, $useDotSyntax = false)
{
$keyGroupArray = [];
foreach ($collection as $item) {
$itemArray = is_array($item) ? $item : (method_exists($item, 'toArray') ? $item->toArray() : []);
$keyValue = self::get($itemArray, $key, null, $useDotSyntax);
$keyGroupArray[$keyValue][] = $itemArray;
}
return $keyGroupArray;
} | [
"public",
"static",
"function",
"toKeyGroup",
"(",
"$",
"collection",
",",
"$",
"key",
",",
"$",
"useDotSyntax",
"=",
"false",
")",
"{",
"$",
"keyGroupArray",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"item",
")",
"{",
"$",
"itemArray",
"=",
"is_array",
"(",
"$",
"item",
")",
"?",
"$",
"item",
":",
"(",
"method_exists",
"(",
"$",
"item",
",",
"'toArray'",
")",
"?",
"$",
"item",
"->",
"toArray",
"(",
")",
":",
"[",
"]",
")",
";",
"$",
"keyValue",
"=",
"self",
"::",
"get",
"(",
"$",
"itemArray",
",",
"$",
"key",
",",
"null",
",",
"$",
"useDotSyntax",
")",
";",
"$",
"keyGroupArray",
"[",
"$",
"keyValue",
"]",
"[",
"]",
"=",
"$",
"itemArray",
";",
"}",
"return",
"$",
"keyGroupArray",
";",
"}"
] | Group all array items by the given key.
@param array|object[]|mixed $collection
@param string $key
@param bool $useDotSyntax
@return array | [
"Group",
"all",
"array",
"items",
"by",
"the",
"given",
"key",
"."
] | a78cf051b379896b5a4d5df620988e37a0e632f5 | https://github.com/PandaPlatform/framework/blob/a78cf051b379896b5a4d5df620988e37a0e632f5/src/Panda/Support/Helpers/ArrayHelper.php#L271-L281 |
13,168 | PandaPlatform/framework | src/Panda/Support/Helpers/ArrayHelper.php | ArrayHelper.toKeyValue | public static function toKeyValue($collection, $key, $value, $useDotSyntax = false)
{
$keyValueArray = [];
foreach ($collection as $item) {
$itemArray = is_array($item) ? $item : (method_exists($item, 'toArray') ? $item->toArray() : []);
$keyValue = self::get($itemArray, $key, null, $useDotSyntax);
$keyValueArray[$keyValue] = $itemArray[$value];
}
return $keyValueArray;
} | php | public static function toKeyValue($collection, $key, $value, $useDotSyntax = false)
{
$keyValueArray = [];
foreach ($collection as $item) {
$itemArray = is_array($item) ? $item : (method_exists($item, 'toArray') ? $item->toArray() : []);
$keyValue = self::get($itemArray, $key, null, $useDotSyntax);
$keyValueArray[$keyValue] = $itemArray[$value];
}
return $keyValueArray;
} | [
"public",
"static",
"function",
"toKeyValue",
"(",
"$",
"collection",
",",
"$",
"key",
",",
"$",
"value",
",",
"$",
"useDotSyntax",
"=",
"false",
")",
"{",
"$",
"keyValueArray",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"item",
")",
"{",
"$",
"itemArray",
"=",
"is_array",
"(",
"$",
"item",
")",
"?",
"$",
"item",
":",
"(",
"method_exists",
"(",
"$",
"item",
",",
"'toArray'",
")",
"?",
"$",
"item",
"->",
"toArray",
"(",
")",
":",
"[",
"]",
")",
";",
"$",
"keyValue",
"=",
"self",
"::",
"get",
"(",
"$",
"itemArray",
",",
"$",
"key",
",",
"null",
",",
"$",
"useDotSyntax",
")",
";",
"$",
"keyValueArray",
"[",
"$",
"keyValue",
"]",
"=",
"$",
"itemArray",
"[",
"$",
"value",
"]",
";",
"}",
"return",
"$",
"keyValueArray",
";",
"}"
] | Return the array in a key-value form, based on the
given parameters for key and value.
@param array|object[] $collection
@param string $key
@param string $value
@param bool $useDotSyntax
@return array | [
"Return",
"the",
"array",
"in",
"a",
"key",
"-",
"value",
"form",
"based",
"on",
"the",
"given",
"parameters",
"for",
"key",
"and",
"value",
"."
] | a78cf051b379896b5a4d5df620988e37a0e632f5 | https://github.com/PandaPlatform/framework/blob/a78cf051b379896b5a4d5df620988e37a0e632f5/src/Panda/Support/Helpers/ArrayHelper.php#L294-L304 |
13,169 | PandaPlatform/framework | src/Panda/Support/Helpers/ArrayHelper.php | ArrayHelper.sortByKey | public static function sortByKey($array, $key, $useDotSyntax = false)
{
uasort($array, function ($a, $b) use ($key, $useDotSyntax) {
$valueA = self::get($a, $key, null, $useDotSyntax);
$valueB = self::get($b, $key, null, $useDotSyntax);
if ($valueA == $valueB) {
return 0;
}
return ($valueA < $valueB) ? -1 : 1;
});
return $array;
} | php | public static function sortByKey($array, $key, $useDotSyntax = false)
{
uasort($array, function ($a, $b) use ($key, $useDotSyntax) {
$valueA = self::get($a, $key, null, $useDotSyntax);
$valueB = self::get($b, $key, null, $useDotSyntax);
if ($valueA == $valueB) {
return 0;
}
return ($valueA < $valueB) ? -1 : 1;
});
return $array;
} | [
"public",
"static",
"function",
"sortByKey",
"(",
"$",
"array",
",",
"$",
"key",
",",
"$",
"useDotSyntax",
"=",
"false",
")",
"{",
"uasort",
"(",
"$",
"array",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"use",
"(",
"$",
"key",
",",
"$",
"useDotSyntax",
")",
"{",
"$",
"valueA",
"=",
"self",
"::",
"get",
"(",
"$",
"a",
",",
"$",
"key",
",",
"null",
",",
"$",
"useDotSyntax",
")",
";",
"$",
"valueB",
"=",
"self",
"::",
"get",
"(",
"$",
"b",
",",
"$",
"key",
",",
"null",
",",
"$",
"useDotSyntax",
")",
";",
"if",
"(",
"$",
"valueA",
"==",
"$",
"valueB",
")",
"{",
"return",
"0",
";",
"}",
"return",
"(",
"$",
"valueA",
"<",
"$",
"valueB",
")",
"?",
"-",
"1",
":",
"1",
";",
"}",
")",
";",
"return",
"$",
"array",
";",
"}"
] | Sort an array by a given value, based on the given key.
@param array $array
@param string $key
@param bool $useDotSyntax
@return array | [
"Sort",
"an",
"array",
"by",
"a",
"given",
"value",
"based",
"on",
"the",
"given",
"key",
"."
] | a78cf051b379896b5a4d5df620988e37a0e632f5 | https://github.com/PandaPlatform/framework/blob/a78cf051b379896b5a4d5df620988e37a0e632f5/src/Panda/Support/Helpers/ArrayHelper.php#L315-L328 |
13,170 | transfer-framework/transfer | src/Transfer/Manifest/ManifestRunner.php | ManifestRunner.run | public function run(ManifestInterface $manifest)
{
$builder = new ProcedureBuilder();
$processor = $manifest->getProcessor();
if ($this->dispatcher) {
$processor->setEventDispatcher($this->dispatcher);
}
$manifest->configureProcedureBuilder($builder);
$manifest->configureProcessor($manifest->getProcessor());
$procedure = $builder->getProcedure();
$processor
->addProcedure($procedure)
->process();
} | php | public function run(ManifestInterface $manifest)
{
$builder = new ProcedureBuilder();
$processor = $manifest->getProcessor();
if ($this->dispatcher) {
$processor->setEventDispatcher($this->dispatcher);
}
$manifest->configureProcedureBuilder($builder);
$manifest->configureProcessor($manifest->getProcessor());
$procedure = $builder->getProcedure();
$processor
->addProcedure($procedure)
->process();
} | [
"public",
"function",
"run",
"(",
"ManifestInterface",
"$",
"manifest",
")",
"{",
"$",
"builder",
"=",
"new",
"ProcedureBuilder",
"(",
")",
";",
"$",
"processor",
"=",
"$",
"manifest",
"->",
"getProcessor",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"dispatcher",
")",
"{",
"$",
"processor",
"->",
"setEventDispatcher",
"(",
"$",
"this",
"->",
"dispatcher",
")",
";",
"}",
"$",
"manifest",
"->",
"configureProcedureBuilder",
"(",
"$",
"builder",
")",
";",
"$",
"manifest",
"->",
"configureProcessor",
"(",
"$",
"manifest",
"->",
"getProcessor",
"(",
")",
")",
";",
"$",
"procedure",
"=",
"$",
"builder",
"->",
"getProcedure",
"(",
")",
";",
"$",
"processor",
"->",
"addProcedure",
"(",
"$",
"procedure",
")",
"->",
"process",
"(",
")",
";",
"}"
] | Configures and runs a manifest.
@param ManifestInterface $manifest Manifest to be run | [
"Configures",
"and",
"runs",
"a",
"manifest",
"."
] | 9225ae068d5924982f14ad4446b15f75384a058a | https://github.com/transfer-framework/transfer/blob/9225ae068d5924982f14ad4446b15f75384a058a/src/Transfer/Manifest/ManifestRunner.php#L40-L57 |
13,171 | chippyash/Strong-Type | src/Chippyash/Type/Number/Complex/ComplexTypeFactory.php | ComplexTypeFactory.create | public static function create($realPart, $imaginaryPart = null)
{
if (is_string($realPart)) {
return self::fromString($realPart);
}
if ($realPart instanceof ComplexType) {
return clone $realPart;
}
if (is_null($imaginaryPart)) {
$imaginaryPart = 0;
}
$real = self::convertType($realPart);
$imaginary = self::convertType($imaginaryPart);
if (self::getRequiredType() == self::TYPE_GMP) {
// @codeCoverageIgnoreStart
return new GMPComplexType($real, $imaginary);
// @codeCoverageIgnoreEnd
}
return new ComplexType($real, $imaginary);
} | php | public static function create($realPart, $imaginaryPart = null)
{
if (is_string($realPart)) {
return self::fromString($realPart);
}
if ($realPart instanceof ComplexType) {
return clone $realPart;
}
if (is_null($imaginaryPart)) {
$imaginaryPart = 0;
}
$real = self::convertType($realPart);
$imaginary = self::convertType($imaginaryPart);
if (self::getRequiredType() == self::TYPE_GMP) {
// @codeCoverageIgnoreStart
return new GMPComplexType($real, $imaginary);
// @codeCoverageIgnoreEnd
}
return new ComplexType($real, $imaginary);
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"realPart",
",",
"$",
"imaginaryPart",
"=",
"null",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"realPart",
")",
")",
"{",
"return",
"self",
"::",
"fromString",
"(",
"$",
"realPart",
")",
";",
"}",
"if",
"(",
"$",
"realPart",
"instanceof",
"ComplexType",
")",
"{",
"return",
"clone",
"$",
"realPart",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"imaginaryPart",
")",
")",
"{",
"$",
"imaginaryPart",
"=",
"0",
";",
"}",
"$",
"real",
"=",
"self",
"::",
"convertType",
"(",
"$",
"realPart",
")",
";",
"$",
"imaginary",
"=",
"self",
"::",
"convertType",
"(",
"$",
"imaginaryPart",
")",
";",
"if",
"(",
"self",
"::",
"getRequiredType",
"(",
")",
"==",
"self",
"::",
"TYPE_GMP",
")",
"{",
"// @codeCoverageIgnoreStart",
"return",
"new",
"GMPComplexType",
"(",
"$",
"real",
",",
"$",
"imaginary",
")",
";",
"// @codeCoverageIgnoreEnd",
"}",
"return",
"new",
"ComplexType",
"(",
"$",
"real",
",",
"$",
"imaginary",
")",
";",
"}"
] | Complex type factory
Construct and return a complex number. You can send in
- a string conforming to 'a+bi', 'a-bi', '-a+bi', '-a-bi' where a & b
are integer or float numbers e.g. '-12+0.67i'
- mixture of numeric (int,float,'1234' etc), IntType and FloatType corresponding to a & b
@param string|float|int|AbstractType $realPart
@param float|int|FloatType|IntType $imaginaryPart
@return \Chippyash\Type\Number\Complex\ComplexType
@throws \InvalidArgumentException | [
"Complex",
"type",
"factory"
] | 9d364c10c68c10f768254fb25b0b1db3dbef6fa9 | https://github.com/chippyash/Strong-Type/blob/9d364c10c68c10f768254fb25b0b1db3dbef6fa9/src/Chippyash/Type/Number/Complex/ComplexTypeFactory.php#L48-L72 |
13,172 | chippyash/Strong-Type | src/Chippyash/Type/Number/Complex/ComplexTypeFactory.php | ComplexTypeFactory.fromPolar | public static function fromPolar(AbstractRationalType $radius, AbstractRationalType $theta)
{
if (self::getRequiredType() == self::TYPE_GMP) {
/** @noinspection PhpParamsInspection */
return self::fromGmpPolar($radius, $theta);
}
/** @noinspection PhpParamsInspection */
return self::fromNativePolar($radius, $theta);
} | php | public static function fromPolar(AbstractRationalType $radius, AbstractRationalType $theta)
{
if (self::getRequiredType() == self::TYPE_GMP) {
/** @noinspection PhpParamsInspection */
return self::fromGmpPolar($radius, $theta);
}
/** @noinspection PhpParamsInspection */
return self::fromNativePolar($radius, $theta);
} | [
"public",
"static",
"function",
"fromPolar",
"(",
"AbstractRationalType",
"$",
"radius",
",",
"AbstractRationalType",
"$",
"theta",
")",
"{",
"if",
"(",
"self",
"::",
"getRequiredType",
"(",
")",
"==",
"self",
"::",
"TYPE_GMP",
")",
"{",
"/** @noinspection PhpParamsInspection */",
"return",
"self",
"::",
"fromGmpPolar",
"(",
"$",
"radius",
",",
"$",
"theta",
")",
";",
"}",
"/** @noinspection PhpParamsInspection */",
"return",
"self",
"::",
"fromNativePolar",
"(",
"$",
"radius",
",",
"$",
"theta",
")",
";",
"}"
] | Create complex type from polar co-ordinates
Be aware that you may lose a bit of precision e.g.
$c = ComplexTypeFactory::create('2/7+3/4i');
$c2 = ComplexTypeFactory::fromPolar($c->radius(), $c->theta());
returns 132664833738225/464326918083788+3382204885901775/4509606514535696i
which is ~0.2857142857142854066 + ~0.75000000000000066525i
whereas the original is
~0.28571428571428571429 + 0.75i
formula for conversion is z = r(cos(theta) + i.sin(theta))
@param \Chippyash\Type\Number\Rational\AbstractRationalType $radius
@param \Chippyash\Type\Number\Rational\AbstractRationalType $theta angle expressed in radians
@return \Chippyash\Type\Number\Complex\ComplexType | [
"Create",
"complex",
"type",
"from",
"polar",
"co",
"-",
"ordinates"
] | 9d364c10c68c10f768254fb25b0b1db3dbef6fa9 | https://github.com/chippyash/Strong-Type/blob/9d364c10c68c10f768254fb25b0b1db3dbef6fa9/src/Chippyash/Type/Number/Complex/ComplexTypeFactory.php#L131-L139 |
13,173 | chippyash/Strong-Type | src/Chippyash/Type/Number/Complex/ComplexTypeFactory.php | ComplexTypeFactory.fromNativePolar | public static function fromNativePolar(RationalType $radius, RationalType $theta)
{
$cos = RationalTypeFactory::fromFloat(cos($theta()));
$sin = RationalTypeFactory::fromFloat(sin($theta()));
list($realNumerator, $realDenominator) = self::getRealPartsFromRadiusAndCos($radius, $cos);
list($imaginaryNumerator, $imaginaryDenominator) = self::getImaginaryPartsFromRadiusAndSin($radius, $sin);
$realPart = RationalTypeFactory::create($realNumerator, $realDenominator);
$imaginaryPart = RationalTypeFactory::create($imaginaryNumerator, $imaginaryDenominator);
return new ComplexType($realPart, $imaginaryPart);
} | php | public static function fromNativePolar(RationalType $radius, RationalType $theta)
{
$cos = RationalTypeFactory::fromFloat(cos($theta()));
$sin = RationalTypeFactory::fromFloat(sin($theta()));
list($realNumerator, $realDenominator) = self::getRealPartsFromRadiusAndCos($radius, $cos);
list($imaginaryNumerator, $imaginaryDenominator) = self::getImaginaryPartsFromRadiusAndSin($radius, $sin);
$realPart = RationalTypeFactory::create($realNumerator, $realDenominator);
$imaginaryPart = RationalTypeFactory::create($imaginaryNumerator, $imaginaryDenominator);
return new ComplexType($realPart, $imaginaryPart);
} | [
"public",
"static",
"function",
"fromNativePolar",
"(",
"RationalType",
"$",
"radius",
",",
"RationalType",
"$",
"theta",
")",
"{",
"$",
"cos",
"=",
"RationalTypeFactory",
"::",
"fromFloat",
"(",
"cos",
"(",
"$",
"theta",
"(",
")",
")",
")",
";",
"$",
"sin",
"=",
"RationalTypeFactory",
"::",
"fromFloat",
"(",
"sin",
"(",
"$",
"theta",
"(",
")",
")",
")",
";",
"list",
"(",
"$",
"realNumerator",
",",
"$",
"realDenominator",
")",
"=",
"self",
"::",
"getRealPartsFromRadiusAndCos",
"(",
"$",
"radius",
",",
"$",
"cos",
")",
";",
"list",
"(",
"$",
"imaginaryNumerator",
",",
"$",
"imaginaryDenominator",
")",
"=",
"self",
"::",
"getImaginaryPartsFromRadiusAndSin",
"(",
"$",
"radius",
",",
"$",
"sin",
")",
";",
"$",
"realPart",
"=",
"RationalTypeFactory",
"::",
"create",
"(",
"$",
"realNumerator",
",",
"$",
"realDenominator",
")",
";",
"$",
"imaginaryPart",
"=",
"RationalTypeFactory",
"::",
"create",
"(",
"$",
"imaginaryNumerator",
",",
"$",
"imaginaryDenominator",
")",
";",
"return",
"new",
"ComplexType",
"(",
"$",
"realPart",
",",
"$",
"imaginaryPart",
")",
";",
"}"
] | Create complex type from polar co-ordinates - Native version
z = radius x (cos(theta) + i.sin(theta))
real = radius x cos(theta)
imag = radius x sin(theta)
@param \Chippyash\Type\Number\Rational\RationalType $radius
@param \Chippyash\Type\Number\Rational\RationalType $theta angle expressed in radians
@return \Chippyash\Type\Number\Complex\ComplexType | [
"Create",
"complex",
"type",
"from",
"polar",
"co",
"-",
"ordinates",
"-",
"Native",
"version"
] | 9d364c10c68c10f768254fb25b0b1db3dbef6fa9 | https://github.com/chippyash/Strong-Type/blob/9d364c10c68c10f768254fb25b0b1db3dbef6fa9/src/Chippyash/Type/Number/Complex/ComplexTypeFactory.php#L153-L165 |
13,174 | chippyash/Strong-Type | src/Chippyash/Type/Number/Complex/ComplexTypeFactory.php | ComplexTypeFactory.fromGmpPolar | public static function fromGmpPolar(GMPRationalType $radius, GMPRationalType $theta)
{
$cos = RationalTypeFactory::fromFloat(cos($theta()));
$sin = RationalTypeFactory::fromFloat(sin($theta()));
//real = radius * cos
$rNum = TypeFactory::create(
'int',
gmp_strval(
gmp_mul(
$radius->numerator()->gmp(),
$cos->numerator()->gmp()
)
)
);
$rDen = TypeFactory::create(
'int',
gmp_strval(
gmp_mul(
$radius->denominator()->gmp(),
$cos->denominator()->gmp()
)
)
);
//imag = radius * sin
$iNum = TypeFactory::create(
'int',
gmp_strval(
gmp_mul(
$radius->numerator()->gmp(),
$sin->numerator()->gmp()
)
)
);
$iDen = TypeFactory::create(
'int',
gmp_strval(
gmp_mul(
$radius->denominator()->gmp(),
$sin->denominator()->gmp()
)
)
);
return new GMPComplexType(
RationalTypeFactory::create($rNum, $rDen),
RationalTypeFactory::create($iNum, $iDen)
);
} | php | public static function fromGmpPolar(GMPRationalType $radius, GMPRationalType $theta)
{
$cos = RationalTypeFactory::fromFloat(cos($theta()));
$sin = RationalTypeFactory::fromFloat(sin($theta()));
//real = radius * cos
$rNum = TypeFactory::create(
'int',
gmp_strval(
gmp_mul(
$radius->numerator()->gmp(),
$cos->numerator()->gmp()
)
)
);
$rDen = TypeFactory::create(
'int',
gmp_strval(
gmp_mul(
$radius->denominator()->gmp(),
$cos->denominator()->gmp()
)
)
);
//imag = radius * sin
$iNum = TypeFactory::create(
'int',
gmp_strval(
gmp_mul(
$radius->numerator()->gmp(),
$sin->numerator()->gmp()
)
)
);
$iDen = TypeFactory::create(
'int',
gmp_strval(
gmp_mul(
$radius->denominator()->gmp(),
$sin->denominator()->gmp()
)
)
);
return new GMPComplexType(
RationalTypeFactory::create($rNum, $rDen),
RationalTypeFactory::create($iNum, $iDen)
);
} | [
"public",
"static",
"function",
"fromGmpPolar",
"(",
"GMPRationalType",
"$",
"radius",
",",
"GMPRationalType",
"$",
"theta",
")",
"{",
"$",
"cos",
"=",
"RationalTypeFactory",
"::",
"fromFloat",
"(",
"cos",
"(",
"$",
"theta",
"(",
")",
")",
")",
";",
"$",
"sin",
"=",
"RationalTypeFactory",
"::",
"fromFloat",
"(",
"sin",
"(",
"$",
"theta",
"(",
")",
")",
")",
";",
"//real = radius * cos",
"$",
"rNum",
"=",
"TypeFactory",
"::",
"create",
"(",
"'int'",
",",
"gmp_strval",
"(",
"gmp_mul",
"(",
"$",
"radius",
"->",
"numerator",
"(",
")",
"->",
"gmp",
"(",
")",
",",
"$",
"cos",
"->",
"numerator",
"(",
")",
"->",
"gmp",
"(",
")",
")",
")",
")",
";",
"$",
"rDen",
"=",
"TypeFactory",
"::",
"create",
"(",
"'int'",
",",
"gmp_strval",
"(",
"gmp_mul",
"(",
"$",
"radius",
"->",
"denominator",
"(",
")",
"->",
"gmp",
"(",
")",
",",
"$",
"cos",
"->",
"denominator",
"(",
")",
"->",
"gmp",
"(",
")",
")",
")",
")",
";",
"//imag = radius * sin",
"$",
"iNum",
"=",
"TypeFactory",
"::",
"create",
"(",
"'int'",
",",
"gmp_strval",
"(",
"gmp_mul",
"(",
"$",
"radius",
"->",
"numerator",
"(",
")",
"->",
"gmp",
"(",
")",
",",
"$",
"sin",
"->",
"numerator",
"(",
")",
"->",
"gmp",
"(",
")",
")",
")",
")",
";",
"$",
"iDen",
"=",
"TypeFactory",
"::",
"create",
"(",
"'int'",
",",
"gmp_strval",
"(",
"gmp_mul",
"(",
"$",
"radius",
"->",
"denominator",
"(",
")",
"->",
"gmp",
"(",
")",
",",
"$",
"sin",
"->",
"denominator",
"(",
")",
"->",
"gmp",
"(",
")",
")",
")",
")",
";",
"return",
"new",
"GMPComplexType",
"(",
"RationalTypeFactory",
"::",
"create",
"(",
"$",
"rNum",
",",
"$",
"rDen",
")",
",",
"RationalTypeFactory",
"::",
"create",
"(",
"$",
"iNum",
",",
"$",
"iDen",
")",
")",
";",
"}"
] | Create complex type from polar co-ordinates - GMP version
@param \Chippyash\Type\Number\Rational\GMPRationalType $radius
@param \Chippyash\Type\Number\Rational\GMPRationalType $theta angle expressed in radians
@return \Chippyash\Type\Number\Complex\GMPComplexType
@codeCoverageIgnore | [
"Create",
"complex",
"type",
"from",
"polar",
"co",
"-",
"ordinates",
"-",
"GMP",
"version"
] | 9d364c10c68c10f768254fb25b0b1db3dbef6fa9 | https://github.com/chippyash/Strong-Type/blob/9d364c10c68c10f768254fb25b0b1db3dbef6fa9/src/Chippyash/Type/Number/Complex/ComplexTypeFactory.php#L177-L225 |
13,175 | chippyash/Strong-Type | src/Chippyash/Type/Number/Complex/ComplexTypeFactory.php | ComplexTypeFactory.convertType | protected static function convertType($original)
{
if ($original instanceof AbstractRationalType) {
return RationalTypeFactory::create(
$original->numerator()->get(),
$original->denominator()->get()
);
}
if (is_numeric($original)) {
if (is_int($original)) {
return RationalTypeFactory::create($original, 1);
}
//default - convert to float
return RationalTypeFactory::fromFloat(floatval($original));
}
if ($original instanceof FloatType) {
return RationalTypeFactory::fromFloat($original());
}
if ($original instanceof IntType) {
return RationalTypeFactory::create($original, 1);
}
if (is_string($original)) {
try {
return RationalTypeFactory::fromString($original);
} catch (\InvalidArgumentException $e) {
throw new InvalidTypeException("{$original} for Complex type construction");
}
}
$type = gettype($original);
throw new InvalidTypeException("{$type} for Complex type construction");
} | php | protected static function convertType($original)
{
if ($original instanceof AbstractRationalType) {
return RationalTypeFactory::create(
$original->numerator()->get(),
$original->denominator()->get()
);
}
if (is_numeric($original)) {
if (is_int($original)) {
return RationalTypeFactory::create($original, 1);
}
//default - convert to float
return RationalTypeFactory::fromFloat(floatval($original));
}
if ($original instanceof FloatType) {
return RationalTypeFactory::fromFloat($original());
}
if ($original instanceof IntType) {
return RationalTypeFactory::create($original, 1);
}
if (is_string($original)) {
try {
return RationalTypeFactory::fromString($original);
} catch (\InvalidArgumentException $e) {
throw new InvalidTypeException("{$original} for Complex type construction");
}
}
$type = gettype($original);
throw new InvalidTypeException("{$type} for Complex type construction");
} | [
"protected",
"static",
"function",
"convertType",
"(",
"$",
"original",
")",
"{",
"if",
"(",
"$",
"original",
"instanceof",
"AbstractRationalType",
")",
"{",
"return",
"RationalTypeFactory",
"::",
"create",
"(",
"$",
"original",
"->",
"numerator",
"(",
")",
"->",
"get",
"(",
")",
",",
"$",
"original",
"->",
"denominator",
"(",
")",
"->",
"get",
"(",
")",
")",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"original",
")",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"original",
")",
")",
"{",
"return",
"RationalTypeFactory",
"::",
"create",
"(",
"$",
"original",
",",
"1",
")",
";",
"}",
"//default - convert to float",
"return",
"RationalTypeFactory",
"::",
"fromFloat",
"(",
"floatval",
"(",
"$",
"original",
")",
")",
";",
"}",
"if",
"(",
"$",
"original",
"instanceof",
"FloatType",
")",
"{",
"return",
"RationalTypeFactory",
"::",
"fromFloat",
"(",
"$",
"original",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"original",
"instanceof",
"IntType",
")",
"{",
"return",
"RationalTypeFactory",
"::",
"create",
"(",
"$",
"original",
",",
"1",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"original",
")",
")",
"{",
"try",
"{",
"return",
"RationalTypeFactory",
"::",
"fromString",
"(",
"$",
"original",
")",
";",
"}",
"catch",
"(",
"\\",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"throw",
"new",
"InvalidTypeException",
"(",
"\"{$original} for Complex type construction\"",
")",
";",
"}",
"}",
"$",
"type",
"=",
"gettype",
"(",
"$",
"original",
")",
";",
"throw",
"new",
"InvalidTypeException",
"(",
"\"{$type} for Complex type construction\"",
")",
";",
"}"
] | Convert to RationalType
@param mixed $original
@return \Chippyash\Type\Number\Rational\RationalType|\Chippyash\Type\Number\Rational\GMPRationalType
@throws InvalidTypeException | [
"Convert",
"to",
"RationalType"
] | 9d364c10c68c10f768254fb25b0b1db3dbef6fa9 | https://github.com/chippyash/Strong-Type/blob/9d364c10c68c10f768254fb25b0b1db3dbef6fa9/src/Chippyash/Type/Number/Complex/ComplexTypeFactory.php#L236-L267 |
13,176 | fuelphp/filesystem | src/Directory.php | Directory.listFiles | public function listFiles($depth = 0, $filter = null, $asHandlers = false)
{
return $this->listContents($depth, $filter, 'file', $asHandlers);
} | php | public function listFiles($depth = 0, $filter = null, $asHandlers = false)
{
return $this->listContents($depth, $filter, 'file', $asHandlers);
} | [
"public",
"function",
"listFiles",
"(",
"$",
"depth",
"=",
"0",
",",
"$",
"filter",
"=",
"null",
",",
"$",
"asHandlers",
"=",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"listContents",
"(",
"$",
"depth",
",",
"$",
"filter",
",",
"'file'",
",",
"$",
"asHandlers",
")",
";",
"}"
] | Lists all files in a directory
@param integer $depth
@param mixed $filter
@param boolean $asHandlers
@return array | [
"Lists",
"all",
"files",
"in",
"a",
"directory"
] | 770a8cb04caca920af8029d7aad7208bc0592743 | https://github.com/fuelphp/filesystem/blob/770a8cb04caca920af8029d7aad7208bc0592743/src/Directory.php#L60-L63 |
13,177 | fuelphp/filesystem | src/Directory.php | Directory.listDirs | public function listDirs($depth = 0, $filter = null, $asHandlers = false)
{
return $this->listContents($depth, $filter, 'dir', $asHandlers);
} | php | public function listDirs($depth = 0, $filter = null, $asHandlers = false)
{
return $this->listContents($depth, $filter, 'dir', $asHandlers);
} | [
"public",
"function",
"listDirs",
"(",
"$",
"depth",
"=",
"0",
",",
"$",
"filter",
"=",
"null",
",",
"$",
"asHandlers",
"=",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"listContents",
"(",
"$",
"depth",
",",
"$",
"filter",
",",
"'dir'",
",",
"$",
"asHandlers",
")",
";",
"}"
] | Lists all directories in a directory
@param integer $depth
@param mixed $filter
@param boolean $asHandlers
@return array | [
"Lists",
"all",
"directories",
"in",
"a",
"directory"
] | 770a8cb04caca920af8029d7aad7208bc0592743 | https://github.com/fuelphp/filesystem/blob/770a8cb04caca920af8029d7aad7208bc0592743/src/Directory.php#L87-L90 |
13,178 | fuelphp/filesystem | src/Directory.php | Directory.listContents | public function listContents($depth = 0, $filter = null, $type = 'all', $asHandlers = false)
{
$pattern = $this->path.'/*';
if (is_array($filter))
{
$filters = $filter;
$filter = new Filter;
foreach ($filters as $f => $type)
{
if ( ! is_int($f))
{
$f = $type;
$type = null;
}
$expected = true;
if (strpos($f, '!') === 0)
{
$f = substr($f, 1);
$expected = false;
}
$filter->addFilter($f, $expected, $type);
}
}
if ($filter instanceof \Closure)
{
$callback = $filter;
$filter = new Filter();
$callback($filter);
}
if ( ! $filter)
{
$filter = new Filter;
}
$flags = GLOB_MARK;
if ($type === 'file' and ! pathinfo($pattern, PATHINFO_EXTENSION))
{
// Add an extension wildcard
$pattern .= '.*';
}
elseif ($type === 'dir')
{
$flags = GLOB_MARK | GLOB_ONLYDIR;
}
$contents = glob($pattern, $flags);
// Filter the content.
$contents = $filter->filter($contents);
// Lower the depth for a recursive call
if ($depth and $depth !== true)
{
$depth--;
}
$formatted = array();
foreach ($contents as $item)
{
if ($filter->isCorrectType('dir', $item))
{
$_contents = array();
if (($depth === true or $depth === 0) and ! $asHandlers)
{
$dir = new Directory($item);
$_contents = $dir->listContents($item, $filter, $depth, $type);
}
if ($asHandlers)
{
$formatted[] = new Directory($item);
}
else
{
$formatted[$item] = $_contents;
}
}
elseif ($filter->isCorrectType('file', $item))
{
if ($asHandlers)
{
$item = new File($item);
}
$formatted[] = $item;
}
}
return $formatted;
} | php | public function listContents($depth = 0, $filter = null, $type = 'all', $asHandlers = false)
{
$pattern = $this->path.'/*';
if (is_array($filter))
{
$filters = $filter;
$filter = new Filter;
foreach ($filters as $f => $type)
{
if ( ! is_int($f))
{
$f = $type;
$type = null;
}
$expected = true;
if (strpos($f, '!') === 0)
{
$f = substr($f, 1);
$expected = false;
}
$filter->addFilter($f, $expected, $type);
}
}
if ($filter instanceof \Closure)
{
$callback = $filter;
$filter = new Filter();
$callback($filter);
}
if ( ! $filter)
{
$filter = new Filter;
}
$flags = GLOB_MARK;
if ($type === 'file' and ! pathinfo($pattern, PATHINFO_EXTENSION))
{
// Add an extension wildcard
$pattern .= '.*';
}
elseif ($type === 'dir')
{
$flags = GLOB_MARK | GLOB_ONLYDIR;
}
$contents = glob($pattern, $flags);
// Filter the content.
$contents = $filter->filter($contents);
// Lower the depth for a recursive call
if ($depth and $depth !== true)
{
$depth--;
}
$formatted = array();
foreach ($contents as $item)
{
if ($filter->isCorrectType('dir', $item))
{
$_contents = array();
if (($depth === true or $depth === 0) and ! $asHandlers)
{
$dir = new Directory($item);
$_contents = $dir->listContents($item, $filter, $depth, $type);
}
if ($asHandlers)
{
$formatted[] = new Directory($item);
}
else
{
$formatted[$item] = $_contents;
}
}
elseif ($filter->isCorrectType('file', $item))
{
if ($asHandlers)
{
$item = new File($item);
}
$formatted[] = $item;
}
}
return $formatted;
} | [
"public",
"function",
"listContents",
"(",
"$",
"depth",
"=",
"0",
",",
"$",
"filter",
"=",
"null",
",",
"$",
"type",
"=",
"'all'",
",",
"$",
"asHandlers",
"=",
"false",
")",
"{",
"$",
"pattern",
"=",
"$",
"this",
"->",
"path",
".",
"'/*'",
";",
"if",
"(",
"is_array",
"(",
"$",
"filter",
")",
")",
"{",
"$",
"filters",
"=",
"$",
"filter",
";",
"$",
"filter",
"=",
"new",
"Filter",
";",
"foreach",
"(",
"$",
"filters",
"as",
"$",
"f",
"=>",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"f",
")",
")",
"{",
"$",
"f",
"=",
"$",
"type",
";",
"$",
"type",
"=",
"null",
";",
"}",
"$",
"expected",
"=",
"true",
";",
"if",
"(",
"strpos",
"(",
"$",
"f",
",",
"'!'",
")",
"===",
"0",
")",
"{",
"$",
"f",
"=",
"substr",
"(",
"$",
"f",
",",
"1",
")",
";",
"$",
"expected",
"=",
"false",
";",
"}",
"$",
"filter",
"->",
"addFilter",
"(",
"$",
"f",
",",
"$",
"expected",
",",
"$",
"type",
")",
";",
"}",
"}",
"if",
"(",
"$",
"filter",
"instanceof",
"\\",
"Closure",
")",
"{",
"$",
"callback",
"=",
"$",
"filter",
";",
"$",
"filter",
"=",
"new",
"Filter",
"(",
")",
";",
"$",
"callback",
"(",
"$",
"filter",
")",
";",
"}",
"if",
"(",
"!",
"$",
"filter",
")",
"{",
"$",
"filter",
"=",
"new",
"Filter",
";",
"}",
"$",
"flags",
"=",
"GLOB_MARK",
";",
"if",
"(",
"$",
"type",
"===",
"'file'",
"and",
"!",
"pathinfo",
"(",
"$",
"pattern",
",",
"PATHINFO_EXTENSION",
")",
")",
"{",
"// Add an extension wildcard",
"$",
"pattern",
".=",
"'.*'",
";",
"}",
"elseif",
"(",
"$",
"type",
"===",
"'dir'",
")",
"{",
"$",
"flags",
"=",
"GLOB_MARK",
"|",
"GLOB_ONLYDIR",
";",
"}",
"$",
"contents",
"=",
"glob",
"(",
"$",
"pattern",
",",
"$",
"flags",
")",
";",
"// Filter the content.",
"$",
"contents",
"=",
"$",
"filter",
"->",
"filter",
"(",
"$",
"contents",
")",
";",
"// Lower the depth for a recursive call",
"if",
"(",
"$",
"depth",
"and",
"$",
"depth",
"!==",
"true",
")",
"{",
"$",
"depth",
"--",
";",
"}",
"$",
"formatted",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"contents",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"filter",
"->",
"isCorrectType",
"(",
"'dir'",
",",
"$",
"item",
")",
")",
"{",
"$",
"_contents",
"=",
"array",
"(",
")",
";",
"if",
"(",
"(",
"$",
"depth",
"===",
"true",
"or",
"$",
"depth",
"===",
"0",
")",
"and",
"!",
"$",
"asHandlers",
")",
"{",
"$",
"dir",
"=",
"new",
"Directory",
"(",
"$",
"item",
")",
";",
"$",
"_contents",
"=",
"$",
"dir",
"->",
"listContents",
"(",
"$",
"item",
",",
"$",
"filter",
",",
"$",
"depth",
",",
"$",
"type",
")",
";",
"}",
"if",
"(",
"$",
"asHandlers",
")",
"{",
"$",
"formatted",
"[",
"]",
"=",
"new",
"Directory",
"(",
"$",
"item",
")",
";",
"}",
"else",
"{",
"$",
"formatted",
"[",
"$",
"item",
"]",
"=",
"$",
"_contents",
";",
"}",
"}",
"elseif",
"(",
"$",
"filter",
"->",
"isCorrectType",
"(",
"'file'",
",",
"$",
"item",
")",
")",
"{",
"if",
"(",
"$",
"asHandlers",
")",
"{",
"$",
"item",
"=",
"new",
"File",
"(",
"$",
"item",
")",
";",
"}",
"$",
"formatted",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"}",
"return",
"$",
"formatted",
";",
"}"
] | Lists all files and directories in a directory
@param integer $depth
@param mixed $filter
@param string $type
@param boolean $asHandlers
@return array | [
"Lists",
"all",
"files",
"and",
"directories",
"in",
"a",
"directory"
] | 770a8cb04caca920af8029d7aad7208bc0592743 | https://github.com/fuelphp/filesystem/blob/770a8cb04caca920af8029d7aad7208bc0592743/src/Directory.php#L115-L215 |
13,179 | skeeks-cms/cms-rbac | src/DbManager.php | DbManager.loadAssignments | private function loadAssignments($userId)
{
if (!isset($this->_assignments[$userId])) {
$query = (new Query)
->select('item_name')
->from($this->assignmentTable)
->where(['user_id' => $userId]);
$this->_assignments[$userId] = $query->column($this->db);
}
} | php | private function loadAssignments($userId)
{
if (!isset($this->_assignments[$userId])) {
$query = (new Query)
->select('item_name')
->from($this->assignmentTable)
->where(['user_id' => $userId]);
$this->_assignments[$userId] = $query->column($this->db);
}
} | [
"private",
"function",
"loadAssignments",
"(",
"$",
"userId",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_assignments",
"[",
"$",
"userId",
"]",
")",
")",
"{",
"$",
"query",
"=",
"(",
"new",
"Query",
")",
"->",
"select",
"(",
"'item_name'",
")",
"->",
"from",
"(",
"$",
"this",
"->",
"assignmentTable",
")",
"->",
"where",
"(",
"[",
"'user_id'",
"=>",
"$",
"userId",
"]",
")",
";",
"$",
"this",
"->",
"_assignments",
"[",
"$",
"userId",
"]",
"=",
"$",
"query",
"->",
"column",
"(",
"$",
"this",
"->",
"db",
")",
";",
"}",
"}"
] | Load data. If avaliable in memory, get from memory
If no, get from cache. If no avaliable, get from database. | [
"Load",
"data",
".",
"If",
"avaliable",
"in",
"memory",
"get",
"from",
"memory",
"If",
"no",
"get",
"from",
"cache",
".",
"If",
"no",
"avaliable",
"get",
"from",
"database",
"."
] | 1e5b17c1eb405f1ea87279da2ce56162c0281def | https://github.com/skeeks-cms/cms-rbac/blob/1e5b17c1eb405f1ea87279da2ce56162c0281def/src/DbManager.php#L662-L672 |
13,180 | cicada/cicada | src/Routing/Router.php | Router.route | public function route(Application $app, Request $request)
{
$url = $request->getPathInfo();
$method = $request->getMethod();
/** @var $route Route */
foreach ($this->routes as $route) {
// Match by method
if ($route->getMethod() == $method) {
// Match by URL
$matches = $route->matches($url);
if ($matches !== false) {
// Emit match event
$app['emitter']->emit(self::EVENT_MATCH, [$app, $request, $route]);
// Execute the route
return $route->run($app, $request, $matches);
}
}
}
// Emit no_match event
$app['emitter']->emit(self::EVENT_NO_MATCH, [$app, $request]);
// Return HTTP 404
return new Response("Page not found", Response::HTTP_NOT_FOUND);
} | php | public function route(Application $app, Request $request)
{
$url = $request->getPathInfo();
$method = $request->getMethod();
/** @var $route Route */
foreach ($this->routes as $route) {
// Match by method
if ($route->getMethod() == $method) {
// Match by URL
$matches = $route->matches($url);
if ($matches !== false) {
// Emit match event
$app['emitter']->emit(self::EVENT_MATCH, [$app, $request, $route]);
// Execute the route
return $route->run($app, $request, $matches);
}
}
}
// Emit no_match event
$app['emitter']->emit(self::EVENT_NO_MATCH, [$app, $request]);
// Return HTTP 404
return new Response("Page not found", Response::HTTP_NOT_FOUND);
} | [
"public",
"function",
"route",
"(",
"Application",
"$",
"app",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"url",
"=",
"$",
"request",
"->",
"getPathInfo",
"(",
")",
";",
"$",
"method",
"=",
"$",
"request",
"->",
"getMethod",
"(",
")",
";",
"/** @var $route Route */",
"foreach",
"(",
"$",
"this",
"->",
"routes",
"as",
"$",
"route",
")",
"{",
"// Match by method",
"if",
"(",
"$",
"route",
"->",
"getMethod",
"(",
")",
"==",
"$",
"method",
")",
"{",
"// Match by URL",
"$",
"matches",
"=",
"$",
"route",
"->",
"matches",
"(",
"$",
"url",
")",
";",
"if",
"(",
"$",
"matches",
"!==",
"false",
")",
"{",
"// Emit match event",
"$",
"app",
"[",
"'emitter'",
"]",
"->",
"emit",
"(",
"self",
"::",
"EVENT_MATCH",
",",
"[",
"$",
"app",
",",
"$",
"request",
",",
"$",
"route",
"]",
")",
";",
"// Execute the route",
"return",
"$",
"route",
"->",
"run",
"(",
"$",
"app",
",",
"$",
"request",
",",
"$",
"matches",
")",
";",
"}",
"}",
"}",
"// Emit no_match event",
"$",
"app",
"[",
"'emitter'",
"]",
"->",
"emit",
"(",
"self",
"::",
"EVENT_NO_MATCH",
",",
"[",
"$",
"app",
",",
"$",
"request",
"]",
")",
";",
"// Return HTTP 404",
"return",
"new",
"Response",
"(",
"\"Page not found\"",
",",
"Response",
"::",
"HTTP_NOT_FOUND",
")",
";",
"}"
] | Routes the request, and returns a Response.
@param Application $app
@param Request $request
@return Response | [
"Routes",
"the",
"request",
"and",
"returns",
"a",
"Response",
"."
] | 5a54bd05dfa1df38e7aa3d704d270853f0329e13 | https://github.com/cicada/cicada/blob/5a54bd05dfa1df38e7aa3d704d270853f0329e13/src/Routing/Router.php#L67-L96 |
13,181 | cicada/cicada | src/Routing/Router.php | Router.getRoute | public function getRoute($name)
{
if (empty($name)) {
throw new \InvalidArgumentException("Route name not provided.");
}
// TODO: This is not very efficient, maybe find a better way
foreach ($this->routes as $route) {
if ($route->getName() === $name) {
return $route;
}
}
throw new \Exception("Route \"$name\" not found.");
} | php | public function getRoute($name)
{
if (empty($name)) {
throw new \InvalidArgumentException("Route name not provided.");
}
// TODO: This is not very efficient, maybe find a better way
foreach ($this->routes as $route) {
if ($route->getName() === $name) {
return $route;
}
}
throw new \Exception("Route \"$name\" not found.");
} | [
"public",
"function",
"getRoute",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Route name not provided.\"",
")",
";",
"}",
"// TODO: This is not very efficient, maybe find a better way",
"foreach",
"(",
"$",
"this",
"->",
"routes",
"as",
"$",
"route",
")",
"{",
"if",
"(",
"$",
"route",
"->",
"getName",
"(",
")",
"===",
"$",
"name",
")",
"{",
"return",
"$",
"route",
";",
"}",
"}",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Route \\\"$name\\\" not found.\"",
")",
";",
"}"
] | Returns a route by name.
@param string $name
@return Route
@throws \Exception If no route with given name is found.
@throws \InvalidArgumentException If given name is empty. | [
"Returns",
"a",
"route",
"by",
"name",
"."
] | 5a54bd05dfa1df38e7aa3d704d270853f0329e13 | https://github.com/cicada/cicada/blob/5a54bd05dfa1df38e7aa3d704d270853f0329e13/src/Routing/Router.php#L115-L129 |
13,182 | vardius/crud-bundle | Controller/CrudController.php | CrudController.checkAccess | public function checkAccess($attributes, $object = null, string $message = 'Access Denied.')
{
$this->denyAccessUnlessGranted($attributes, $object, $message);
} | php | public function checkAccess($attributes, $object = null, string $message = 'Access Denied.')
{
$this->denyAccessUnlessGranted($attributes, $object, $message);
} | [
"public",
"function",
"checkAccess",
"(",
"$",
"attributes",
",",
"$",
"object",
"=",
"null",
",",
"string",
"$",
"message",
"=",
"'Access Denied.'",
")",
"{",
"$",
"this",
"->",
"denyAccessUnlessGranted",
"(",
"$",
"attributes",
",",
"$",
"object",
",",
"$",
"message",
")",
";",
"}"
] | Throws an exception unless the attributes are granted against the current authentication token and optionally
supplied object.
@param mixed $attributes The attributes
@param mixed $object The object
@param string $message The message passed to the exception
@throws AccessDeniedException | [
"Throws",
"an",
"exception",
"unless",
"the",
"attributes",
"are",
"granted",
"against",
"the",
"current",
"authentication",
"token",
"and",
"optionally",
"supplied",
"object",
"."
] | dda957e3f8516c3b0d6270ea5a6eb50d98e71444 | https://github.com/vardius/crud-bundle/blob/dda957e3f8516c3b0d6270ea5a6eb50d98e71444/Controller/CrudController.php#L192-L195 |
13,183 | gyselroth/php-stream-iterator | src/StreamIterator.php | StreamIterator.seek | public function seek($offset, $whence = SEEK_SET)
{
if (!is_int($offset) && !is_numeric($offset)) {
return false;
}
$offset = (int) $offset;
if ($offset < 0) {
return false;
}
$key = $this->iterator->key();
if (!is_int($key) && !is_numeric($key)) {
$key = 0;
$this->iterator->rewind();
}
if ($key >= $offset) {
$key = 0;
$this->iterator->rewind();
}
while ($this->iterator->valid() && $key < $offset) {
$this->iterator->next();
++$key;
}
$this->position = $key;
return true;
} | php | public function seek($offset, $whence = SEEK_SET)
{
if (!is_int($offset) && !is_numeric($offset)) {
return false;
}
$offset = (int) $offset;
if ($offset < 0) {
return false;
}
$key = $this->iterator->key();
if (!is_int($key) && !is_numeric($key)) {
$key = 0;
$this->iterator->rewind();
}
if ($key >= $offset) {
$key = 0;
$this->iterator->rewind();
}
while ($this->iterator->valid() && $key < $offset) {
$this->iterator->next();
++$key;
}
$this->position = $key;
return true;
} | [
"public",
"function",
"seek",
"(",
"$",
"offset",
",",
"$",
"whence",
"=",
"SEEK_SET",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"offset",
")",
"&&",
"!",
"is_numeric",
"(",
"$",
"offset",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"offset",
"=",
"(",
"int",
")",
"$",
"offset",
";",
"if",
"(",
"$",
"offset",
"<",
"0",
")",
"{",
"return",
"false",
";",
"}",
"$",
"key",
"=",
"$",
"this",
"->",
"iterator",
"->",
"key",
"(",
")",
";",
"if",
"(",
"!",
"is_int",
"(",
"$",
"key",
")",
"&&",
"!",
"is_numeric",
"(",
"$",
"key",
")",
")",
"{",
"$",
"key",
"=",
"0",
";",
"$",
"this",
"->",
"iterator",
"->",
"rewind",
"(",
")",
";",
"}",
"if",
"(",
"$",
"key",
">=",
"$",
"offset",
")",
"{",
"$",
"key",
"=",
"0",
";",
"$",
"this",
"->",
"iterator",
"->",
"rewind",
"(",
")",
";",
"}",
"while",
"(",
"$",
"this",
"->",
"iterator",
"->",
"valid",
"(",
")",
"&&",
"$",
"key",
"<",
"$",
"offset",
")",
"{",
"$",
"this",
"->",
"iterator",
"->",
"next",
"(",
")",
";",
"++",
"$",
"key",
";",
"}",
"$",
"this",
"->",
"position",
"=",
"$",
"key",
";",
"return",
"true",
";",
"}"
] | Seek the iterator.
@param int $offset Stream offset
@param int $whence ignored
@return bool returns TRUE on success or FALSE on failure | [
"Seek",
"the",
"iterator",
"."
] | 714b83d529301a2dcb51418fad08abda128686b8 | https://github.com/gyselroth/php-stream-iterator/blob/714b83d529301a2dcb51418fad08abda128686b8/src/StreamIterator.php#L140-L170 |
13,184 | eliep/avro-rpc-php | lib/avro/ipc.php | Requestor.request | public function request($message_name, $request_datum)
{
$io = new AvroStringIO();
$encoder = new AvroIOBinaryEncoder($io);
$this->write_handshake_request($encoder);
$this->write_call_request($message_name, $request_datum, $encoder);
$call_request = $io->string();
if ($this->local_protocol->messages[$message_name]->is_one_way()) {
$this->transceiver->write_message($call_request);
if (!$this->transceiver->is_connected()) {
$handshake_response = $this->transceiver->read_message();
$io = new AvroStringIO($handshake_response);
$decoder = new AvroIOBinaryDecoder($io);
$this->read_handshake_response($decoder);
}
return true;
} else {
$call_response = $this->transceiver->transceive($call_request);
// process the handshake and call response
$io = new AvroStringIO($call_response);
$decoder = new AvroIOBinaryDecoder($io);
$call_response_exists = $this->read_handshake_response($decoder);
if ($call_response_exists) {
$call_response = $this->read_call_response($message_name, $decoder);
return $call_response;
} else
return $this->request($message_name, $request_datum);
}
} | php | public function request($message_name, $request_datum)
{
$io = new AvroStringIO();
$encoder = new AvroIOBinaryEncoder($io);
$this->write_handshake_request($encoder);
$this->write_call_request($message_name, $request_datum, $encoder);
$call_request = $io->string();
if ($this->local_protocol->messages[$message_name]->is_one_way()) {
$this->transceiver->write_message($call_request);
if (!$this->transceiver->is_connected()) {
$handshake_response = $this->transceiver->read_message();
$io = new AvroStringIO($handshake_response);
$decoder = new AvroIOBinaryDecoder($io);
$this->read_handshake_response($decoder);
}
return true;
} else {
$call_response = $this->transceiver->transceive($call_request);
// process the handshake and call response
$io = new AvroStringIO($call_response);
$decoder = new AvroIOBinaryDecoder($io);
$call_response_exists = $this->read_handshake_response($decoder);
if ($call_response_exists) {
$call_response = $this->read_call_response($message_name, $decoder);
return $call_response;
} else
return $this->request($message_name, $request_datum);
}
} | [
"public",
"function",
"request",
"(",
"$",
"message_name",
",",
"$",
"request_datum",
")",
"{",
"$",
"io",
"=",
"new",
"AvroStringIO",
"(",
")",
";",
"$",
"encoder",
"=",
"new",
"AvroIOBinaryEncoder",
"(",
"$",
"io",
")",
";",
"$",
"this",
"->",
"write_handshake_request",
"(",
"$",
"encoder",
")",
";",
"$",
"this",
"->",
"write_call_request",
"(",
"$",
"message_name",
",",
"$",
"request_datum",
",",
"$",
"encoder",
")",
";",
"$",
"call_request",
"=",
"$",
"io",
"->",
"string",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"local_protocol",
"->",
"messages",
"[",
"$",
"message_name",
"]",
"->",
"is_one_way",
"(",
")",
")",
"{",
"$",
"this",
"->",
"transceiver",
"->",
"write_message",
"(",
"$",
"call_request",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"transceiver",
"->",
"is_connected",
"(",
")",
")",
"{",
"$",
"handshake_response",
"=",
"$",
"this",
"->",
"transceiver",
"->",
"read_message",
"(",
")",
";",
"$",
"io",
"=",
"new",
"AvroStringIO",
"(",
"$",
"handshake_response",
")",
";",
"$",
"decoder",
"=",
"new",
"AvroIOBinaryDecoder",
"(",
"$",
"io",
")",
";",
"$",
"this",
"->",
"read_handshake_response",
"(",
"$",
"decoder",
")",
";",
"}",
"return",
"true",
";",
"}",
"else",
"{",
"$",
"call_response",
"=",
"$",
"this",
"->",
"transceiver",
"->",
"transceive",
"(",
"$",
"call_request",
")",
";",
"// process the handshake and call response",
"$",
"io",
"=",
"new",
"AvroStringIO",
"(",
"$",
"call_response",
")",
";",
"$",
"decoder",
"=",
"new",
"AvroIOBinaryDecoder",
"(",
"$",
"io",
")",
";",
"$",
"call_response_exists",
"=",
"$",
"this",
"->",
"read_handshake_response",
"(",
"$",
"decoder",
")",
";",
"if",
"(",
"$",
"call_response_exists",
")",
"{",
"$",
"call_response",
"=",
"$",
"this",
"->",
"read_call_response",
"(",
"$",
"message_name",
",",
"$",
"decoder",
")",
";",
"return",
"$",
"call_response",
";",
"}",
"else",
"return",
"$",
"this",
"->",
"request",
"(",
"$",
"message_name",
",",
"$",
"request_datum",
")",
";",
"}",
"}"
] | Writes a request message and reads a response or error message.
@param string $message_name : name of the IPC method
@param mixed $request_datum : IPC request
@throw AvroException when $message_name is not registered on the local or remote protocol
@throw AvroRemoteException when server send an error | [
"Writes",
"a",
"request",
"message",
"and",
"reads",
"a",
"response",
"or",
"error",
"message",
"."
] | 645321e5224eac9234fc79dbf447de3973a9ed1e | https://github.com/eliep/avro-rpc-php/blob/645321e5224eac9234fc79dbf447de3973a9ed1e/lib/avro/ipc.php#L155-L185 |
13,185 | eliep/avro-rpc-php | lib/avro/ipc.php | Requestor.write_handshake_request | public function write_handshake_request(AvroIOBinaryEncoder $encoder)
{
if ($this->transceiver->is_connected())
return;
$remote_name = $this->transceiver->remote_name();
$local_hash = $this->local_protocol->md5();
$remote_hash = (!isset($this->remote_hash[$remote_name])) ? null : $this->remote_hash[$remote_name];
if (is_null($remote_hash)) {
$remote_hash = $local_hash;
$this->remote = $this->local_protocol;
} else {
$this->remote = $this->remote_protocol[$remote_name];
}
$request_datum = array('clientHash' => $local_hash, 'serverHash' => $remote_hash, 'meta' => null);
$request_datum["clientProtocol"] = ($this->send_protocol) ? $this->local_protocol->__toString() : null;
$this->handshake_requestor_writer->write($request_datum, $encoder);
} | php | public function write_handshake_request(AvroIOBinaryEncoder $encoder)
{
if ($this->transceiver->is_connected())
return;
$remote_name = $this->transceiver->remote_name();
$local_hash = $this->local_protocol->md5();
$remote_hash = (!isset($this->remote_hash[$remote_name])) ? null : $this->remote_hash[$remote_name];
if (is_null($remote_hash)) {
$remote_hash = $local_hash;
$this->remote = $this->local_protocol;
} else {
$this->remote = $this->remote_protocol[$remote_name];
}
$request_datum = array('clientHash' => $local_hash, 'serverHash' => $remote_hash, 'meta' => null);
$request_datum["clientProtocol"] = ($this->send_protocol) ? $this->local_protocol->__toString() : null;
$this->handshake_requestor_writer->write($request_datum, $encoder);
} | [
"public",
"function",
"write_handshake_request",
"(",
"AvroIOBinaryEncoder",
"$",
"encoder",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"transceiver",
"->",
"is_connected",
"(",
")",
")",
"return",
";",
"$",
"remote_name",
"=",
"$",
"this",
"->",
"transceiver",
"->",
"remote_name",
"(",
")",
";",
"$",
"local_hash",
"=",
"$",
"this",
"->",
"local_protocol",
"->",
"md5",
"(",
")",
";",
"$",
"remote_hash",
"=",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"remote_hash",
"[",
"$",
"remote_name",
"]",
")",
")",
"?",
"null",
":",
"$",
"this",
"->",
"remote_hash",
"[",
"$",
"remote_name",
"]",
";",
"if",
"(",
"is_null",
"(",
"$",
"remote_hash",
")",
")",
"{",
"$",
"remote_hash",
"=",
"$",
"local_hash",
";",
"$",
"this",
"->",
"remote",
"=",
"$",
"this",
"->",
"local_protocol",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"remote",
"=",
"$",
"this",
"->",
"remote_protocol",
"[",
"$",
"remote_name",
"]",
";",
"}",
"$",
"request_datum",
"=",
"array",
"(",
"'clientHash'",
"=>",
"$",
"local_hash",
",",
"'serverHash'",
"=>",
"$",
"remote_hash",
",",
"'meta'",
"=>",
"null",
")",
";",
"$",
"request_datum",
"[",
"\"clientProtocol\"",
"]",
"=",
"(",
"$",
"this",
"->",
"send_protocol",
")",
"?",
"$",
"this",
"->",
"local_protocol",
"->",
"__toString",
"(",
")",
":",
"null",
";",
"$",
"this",
"->",
"handshake_requestor_writer",
"->",
"write",
"(",
"$",
"request_datum",
",",
"$",
"encoder",
")",
";",
"}"
] | Write the handshake request.
@param AvroIOBinaryEncoder $encoder : Encoder to write the handshake request into. | [
"Write",
"the",
"handshake",
"request",
"."
] | 645321e5224eac9234fc79dbf447de3973a9ed1e | https://github.com/eliep/avro-rpc-php/blob/645321e5224eac9234fc79dbf447de3973a9ed1e/lib/avro/ipc.php#L191-L211 |
13,186 | eliep/avro-rpc-php | lib/avro/ipc.php | Requestor.read_handshake_response | public function read_handshake_response(AvroIOBinaryDecoder $decoder)
{
// if the handshake has been successfully made previously,
// no need to do it again
if ($this->transceiver->is_connected())
return true;
$established = false;
$handshake_response = $this->handshake_requestor_reader->read($decoder);
$match = $handshake_response["match"];
switch ($match) {
case 'BOTH':
$established = true;
$this->send_protocol = false;
break;
case 'CLIENT':
$established = true;
$this->send_protocol = false;
$this->set_remote($handshake_response);
break;
case 'NONE':
$this->send_protocol = true;
$this->set_remote($handshake_response);
$established = false;
break;
default:
throw new AvroException("Bad handshake response match: $match");
}
if ($established)
$this->transceiver->set_remote($this->remote);
return $established;
} | php | public function read_handshake_response(AvroIOBinaryDecoder $decoder)
{
// if the handshake has been successfully made previously,
// no need to do it again
if ($this->transceiver->is_connected())
return true;
$established = false;
$handshake_response = $this->handshake_requestor_reader->read($decoder);
$match = $handshake_response["match"];
switch ($match) {
case 'BOTH':
$established = true;
$this->send_protocol = false;
break;
case 'CLIENT':
$established = true;
$this->send_protocol = false;
$this->set_remote($handshake_response);
break;
case 'NONE':
$this->send_protocol = true;
$this->set_remote($handshake_response);
$established = false;
break;
default:
throw new AvroException("Bad handshake response match: $match");
}
if ($established)
$this->transceiver->set_remote($this->remote);
return $established;
} | [
"public",
"function",
"read_handshake_response",
"(",
"AvroIOBinaryDecoder",
"$",
"decoder",
")",
"{",
"// if the handshake has been successfully made previously,",
"// no need to do it again",
"if",
"(",
"$",
"this",
"->",
"transceiver",
"->",
"is_connected",
"(",
")",
")",
"return",
"true",
";",
"$",
"established",
"=",
"false",
";",
"$",
"handshake_response",
"=",
"$",
"this",
"->",
"handshake_requestor_reader",
"->",
"read",
"(",
"$",
"decoder",
")",
";",
"$",
"match",
"=",
"$",
"handshake_response",
"[",
"\"match\"",
"]",
";",
"switch",
"(",
"$",
"match",
")",
"{",
"case",
"'BOTH'",
":",
"$",
"established",
"=",
"true",
";",
"$",
"this",
"->",
"send_protocol",
"=",
"false",
";",
"break",
";",
"case",
"'CLIENT'",
":",
"$",
"established",
"=",
"true",
";",
"$",
"this",
"->",
"send_protocol",
"=",
"false",
";",
"$",
"this",
"->",
"set_remote",
"(",
"$",
"handshake_response",
")",
";",
"break",
";",
"case",
"'NONE'",
":",
"$",
"this",
"->",
"send_protocol",
"=",
"true",
";",
"$",
"this",
"->",
"set_remote",
"(",
"$",
"handshake_response",
")",
";",
"$",
"established",
"=",
"false",
";",
"break",
";",
"default",
":",
"throw",
"new",
"AvroException",
"(",
"\"Bad handshake response match: $match\"",
")",
";",
"}",
"if",
"(",
"$",
"established",
")",
"$",
"this",
"->",
"transceiver",
"->",
"set_remote",
"(",
"$",
"this",
"->",
"remote",
")",
";",
"return",
"$",
"established",
";",
"}"
] | Reads and processes the handshake response message.
@param AvroIOBinaryDecoder $decoder : Decoder to read messages from.
@return boolean true if a response exists.
@throw AvroException when server respond an unknown handshake match | [
"Reads",
"and",
"processes",
"the",
"handshake",
"response",
"message",
"."
] | 645321e5224eac9234fc79dbf447de3973a9ed1e | https://github.com/eliep/avro-rpc-php/blob/645321e5224eac9234fc79dbf447de3973a9ed1e/lib/avro/ipc.php#L242-L276 |
13,187 | eliep/avro-rpc-php | lib/avro/ipc.php | Responder.process_handshake | public function process_handshake(AvroIOBinaryDecoder $decoder, AvroIOBinaryEncoder $encoder, Transceiver $transceiver)
{
if ($transceiver->is_connected())
return $transceiver->get_remote();
$handshake_request = $this->handshake_responder_reader->read($decoder);
$client_hash = $handshake_request["clientHash"];
$client_protocol = $handshake_request["clientProtocol"];
$remote_protocol = $this->get_protocol_cache($client_hash);
if (is_null($remote_protocol) && !is_null($client_protocol)) {
$remote_protocol = AvroProtocol::parse($client_protocol);
$this->set_protocol_cache($client_hash, $remote_protocol);
}
$server_hash = $handshake_request["serverHash"];
$handshake_response = array();
if ($this->local_hash == $server_hash)
$handshake_response['match'] = (is_null($remote_protocol)) ? 'NONE' : 'BOTH';
else
$handshake_response['match'] = (is_null($remote_protocol)) ? 'NONE' : 'CLIENT';
$handshake_response["meta"] = null;
if ($handshake_response['match'] != 'BOTH') {
$handshake_response["serverProtocol"] = $this->local_protocol->__toString();
$handshake_response["serverHash"] = $this->local_hash;
} else {
$handshake_response["serverProtocol"] = null;
$handshake_response["serverHash"] = null;
}
$this->handshake_responder_writer->write($handshake_response, $encoder);
if ($handshake_response['match'] != 'NONE')
$transceiver->set_remote($remote_protocol);
return $remote_protocol;
} | php | public function process_handshake(AvroIOBinaryDecoder $decoder, AvroIOBinaryEncoder $encoder, Transceiver $transceiver)
{
if ($transceiver->is_connected())
return $transceiver->get_remote();
$handshake_request = $this->handshake_responder_reader->read($decoder);
$client_hash = $handshake_request["clientHash"];
$client_protocol = $handshake_request["clientProtocol"];
$remote_protocol = $this->get_protocol_cache($client_hash);
if (is_null($remote_protocol) && !is_null($client_protocol)) {
$remote_protocol = AvroProtocol::parse($client_protocol);
$this->set_protocol_cache($client_hash, $remote_protocol);
}
$server_hash = $handshake_request["serverHash"];
$handshake_response = array();
if ($this->local_hash == $server_hash)
$handshake_response['match'] = (is_null($remote_protocol)) ? 'NONE' : 'BOTH';
else
$handshake_response['match'] = (is_null($remote_protocol)) ? 'NONE' : 'CLIENT';
$handshake_response["meta"] = null;
if ($handshake_response['match'] != 'BOTH') {
$handshake_response["serverProtocol"] = $this->local_protocol->__toString();
$handshake_response["serverHash"] = $this->local_hash;
} else {
$handshake_response["serverProtocol"] = null;
$handshake_response["serverHash"] = null;
}
$this->handshake_responder_writer->write($handshake_response, $encoder);
if ($handshake_response['match'] != 'NONE')
$transceiver->set_remote($remote_protocol);
return $remote_protocol;
} | [
"public",
"function",
"process_handshake",
"(",
"AvroIOBinaryDecoder",
"$",
"decoder",
",",
"AvroIOBinaryEncoder",
"$",
"encoder",
",",
"Transceiver",
"$",
"transceiver",
")",
"{",
"if",
"(",
"$",
"transceiver",
"->",
"is_connected",
"(",
")",
")",
"return",
"$",
"transceiver",
"->",
"get_remote",
"(",
")",
";",
"$",
"handshake_request",
"=",
"$",
"this",
"->",
"handshake_responder_reader",
"->",
"read",
"(",
"$",
"decoder",
")",
";",
"$",
"client_hash",
"=",
"$",
"handshake_request",
"[",
"\"clientHash\"",
"]",
";",
"$",
"client_protocol",
"=",
"$",
"handshake_request",
"[",
"\"clientProtocol\"",
"]",
";",
"$",
"remote_protocol",
"=",
"$",
"this",
"->",
"get_protocol_cache",
"(",
"$",
"client_hash",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"remote_protocol",
")",
"&&",
"!",
"is_null",
"(",
"$",
"client_protocol",
")",
")",
"{",
"$",
"remote_protocol",
"=",
"AvroProtocol",
"::",
"parse",
"(",
"$",
"client_protocol",
")",
";",
"$",
"this",
"->",
"set_protocol_cache",
"(",
"$",
"client_hash",
",",
"$",
"remote_protocol",
")",
";",
"}",
"$",
"server_hash",
"=",
"$",
"handshake_request",
"[",
"\"serverHash\"",
"]",
";",
"$",
"handshake_response",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"local_hash",
"==",
"$",
"server_hash",
")",
"$",
"handshake_response",
"[",
"'match'",
"]",
"=",
"(",
"is_null",
"(",
"$",
"remote_protocol",
")",
")",
"?",
"'NONE'",
":",
"'BOTH'",
";",
"else",
"$",
"handshake_response",
"[",
"'match'",
"]",
"=",
"(",
"is_null",
"(",
"$",
"remote_protocol",
")",
")",
"?",
"'NONE'",
":",
"'CLIENT'",
";",
"$",
"handshake_response",
"[",
"\"meta\"",
"]",
"=",
"null",
";",
"if",
"(",
"$",
"handshake_response",
"[",
"'match'",
"]",
"!=",
"'BOTH'",
")",
"{",
"$",
"handshake_response",
"[",
"\"serverProtocol\"",
"]",
"=",
"$",
"this",
"->",
"local_protocol",
"->",
"__toString",
"(",
")",
";",
"$",
"handshake_response",
"[",
"\"serverHash\"",
"]",
"=",
"$",
"this",
"->",
"local_hash",
";",
"}",
"else",
"{",
"$",
"handshake_response",
"[",
"\"serverProtocol\"",
"]",
"=",
"null",
";",
"$",
"handshake_response",
"[",
"\"serverHash\"",
"]",
"=",
"null",
";",
"}",
"$",
"this",
"->",
"handshake_responder_writer",
"->",
"write",
"(",
"$",
"handshake_response",
",",
"$",
"encoder",
")",
";",
"if",
"(",
"$",
"handshake_response",
"[",
"'match'",
"]",
"!=",
"'NONE'",
")",
"$",
"transceiver",
"->",
"set_remote",
"(",
"$",
"remote_protocol",
")",
";",
"return",
"$",
"remote_protocol",
";",
"}"
] | Processes an RPC handshake.
@param AvroIOBinaryDecoder $decoder Where to read from
@param AvroIOBinaryEncoder $encoder Where to write to.
@param Transceiver $transceiver the transceiver used for the response
@return AvroProtocol The requested Protocol. | [
"Processes",
"an",
"RPC",
"handshake",
"."
] | 645321e5224eac9234fc79dbf447de3973a9ed1e | https://github.com/eliep/avro-rpc-php/blob/645321e5224eac9234fc79dbf447de3973a9ed1e/lib/avro/ipc.php#L454-L492 |
13,188 | liquidpineapple/color | src/Color.php | Color.fromRGB | public static function fromRGB($red, $green, $blue)
{
if ($red < 0 || $red > 255 ||
$green < 0 || $green > 255 ||
$blue < 0 || $blue > 255) {
throw new InvalidArgumentException('Values $red, $blue and $green can only be 0 to 255');
}
$red /= 255;
$green /= 255;
$blue /= 255;
$min = min($red, $green, $blue);
$max = max($red, $green, $blue);
$delta = $max - $min;
$hue = 0;
$saturation = 0;
$lightness = ($max + $min) / 2;
if ($delta == 0) {
// Achromatic
return new self($hue, $saturation * 100, $lightness * 100);
} else {
$saturation = $delta / (1 - abs(2 * $lightness - 1));
$hue = ($max == $green) ? 60 * (($blue - $red) / $delta + 2) : $hue;
$hue = ($max == $blue) ? 60 * (($red - $green) / $delta + 4) : $hue;
if ($max == $red) {
$x = ($blue > $green) ? 360 : 0;
$hue = 60 * fmod((($green - $blue) / $delta), 6) + $x;
}
return new self($hue, $saturation * 100, $lightness * 100);
}
} | php | public static function fromRGB($red, $green, $blue)
{
if ($red < 0 || $red > 255 ||
$green < 0 || $green > 255 ||
$blue < 0 || $blue > 255) {
throw new InvalidArgumentException('Values $red, $blue and $green can only be 0 to 255');
}
$red /= 255;
$green /= 255;
$blue /= 255;
$min = min($red, $green, $blue);
$max = max($red, $green, $blue);
$delta = $max - $min;
$hue = 0;
$saturation = 0;
$lightness = ($max + $min) / 2;
if ($delta == 0) {
// Achromatic
return new self($hue, $saturation * 100, $lightness * 100);
} else {
$saturation = $delta / (1 - abs(2 * $lightness - 1));
$hue = ($max == $green) ? 60 * (($blue - $red) / $delta + 2) : $hue;
$hue = ($max == $blue) ? 60 * (($red - $green) / $delta + 4) : $hue;
if ($max == $red) {
$x = ($blue > $green) ? 360 : 0;
$hue = 60 * fmod((($green - $blue) / $delta), 6) + $x;
}
return new self($hue, $saturation * 100, $lightness * 100);
}
} | [
"public",
"static",
"function",
"fromRGB",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
"{",
"if",
"(",
"$",
"red",
"<",
"0",
"||",
"$",
"red",
">",
"255",
"||",
"$",
"green",
"<",
"0",
"||",
"$",
"green",
">",
"255",
"||",
"$",
"blue",
"<",
"0",
"||",
"$",
"blue",
">",
"255",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Values $red, $blue and $green can only be 0 to 255'",
")",
";",
"}",
"$",
"red",
"/=",
"255",
";",
"$",
"green",
"/=",
"255",
";",
"$",
"blue",
"/=",
"255",
";",
"$",
"min",
"=",
"min",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
";",
"$",
"max",
"=",
"max",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
";",
"$",
"delta",
"=",
"$",
"max",
"-",
"$",
"min",
";",
"$",
"hue",
"=",
"0",
";",
"$",
"saturation",
"=",
"0",
";",
"$",
"lightness",
"=",
"(",
"$",
"max",
"+",
"$",
"min",
")",
"/",
"2",
";",
"if",
"(",
"$",
"delta",
"==",
"0",
")",
"{",
"// Achromatic",
"return",
"new",
"self",
"(",
"$",
"hue",
",",
"$",
"saturation",
"*",
"100",
",",
"$",
"lightness",
"*",
"100",
")",
";",
"}",
"else",
"{",
"$",
"saturation",
"=",
"$",
"delta",
"/",
"(",
"1",
"-",
"abs",
"(",
"2",
"*",
"$",
"lightness",
"-",
"1",
")",
")",
";",
"$",
"hue",
"=",
"(",
"$",
"max",
"==",
"$",
"green",
")",
"?",
"60",
"*",
"(",
"(",
"$",
"blue",
"-",
"$",
"red",
")",
"/",
"$",
"delta",
"+",
"2",
")",
":",
"$",
"hue",
";",
"$",
"hue",
"=",
"(",
"$",
"max",
"==",
"$",
"blue",
")",
"?",
"60",
"*",
"(",
"(",
"$",
"red",
"-",
"$",
"green",
")",
"/",
"$",
"delta",
"+",
"4",
")",
":",
"$",
"hue",
";",
"if",
"(",
"$",
"max",
"==",
"$",
"red",
")",
"{",
"$",
"x",
"=",
"(",
"$",
"blue",
">",
"$",
"green",
")",
"?",
"360",
":",
"0",
";",
"$",
"hue",
"=",
"60",
"*",
"fmod",
"(",
"(",
"(",
"$",
"green",
"-",
"$",
"blue",
")",
"/",
"$",
"delta",
")",
",",
"6",
")",
"+",
"$",
"x",
";",
"}",
"return",
"new",
"self",
"(",
"$",
"hue",
",",
"$",
"saturation",
"*",
"100",
",",
"$",
"lightness",
"*",
"100",
")",
";",
"}",
"}"
] | Creates a Color instance based on the given RGB-formatted color.
@param int $red (0-255) The red value of the given color
@param int $green (0-255) The green value of the given color
@param int $blue (0-255) The blue value of the given color
@return Color | [
"Creates",
"a",
"Color",
"instance",
"based",
"on",
"the",
"given",
"RGB",
"-",
"formatted",
"color",
"."
] | f0f323e99a884d482ec35abf21b49af5ab3fa9c3 | https://github.com/liquidpineapple/color/blob/f0f323e99a884d482ec35abf21b49af5ab3fa9c3/src/Color.php#L49-L79 |
13,189 | liquidpineapple/color | src/Color.php | Color.fromHEX | public static function fromHEX($hex)
{
$hex = preg_replace('/[^0-9A-Fa-f]/', '', $hex);
$rgb = [];
if (strlen($hex) == 6) {
$colorVal = hexdec($hex);
$rgb['red'] = 0xFF & ($colorVal >> 0x10);
$rgb['green'] = 0xFF & ($colorVal >> 0x8);
$rgb['blue'] = 0xFF & $colorVal;
} elseif (strlen($hex) == 3) {
$rgb['red'] = hexdec(str_repeat(substr($hex, 0, 1), 2));
$rgb['green'] = hexdec(str_repeat(substr($hex, 1, 1), 2));
$rgb['blue'] = hexdec(str_repeat(substr($hex, 2, 1), 2));
} else {
throw new InvalidArgumentException('Given color does not adhere to hexadecimal format');
}
return self::fromRGB($rgb['red'], $rgb['green'], $rgb['blue']);
} | php | public static function fromHEX($hex)
{
$hex = preg_replace('/[^0-9A-Fa-f]/', '', $hex);
$rgb = [];
if (strlen($hex) == 6) {
$colorVal = hexdec($hex);
$rgb['red'] = 0xFF & ($colorVal >> 0x10);
$rgb['green'] = 0xFF & ($colorVal >> 0x8);
$rgb['blue'] = 0xFF & $colorVal;
} elseif (strlen($hex) == 3) {
$rgb['red'] = hexdec(str_repeat(substr($hex, 0, 1), 2));
$rgb['green'] = hexdec(str_repeat(substr($hex, 1, 1), 2));
$rgb['blue'] = hexdec(str_repeat(substr($hex, 2, 1), 2));
} else {
throw new InvalidArgumentException('Given color does not adhere to hexadecimal format');
}
return self::fromRGB($rgb['red'], $rgb['green'], $rgb['blue']);
} | [
"public",
"static",
"function",
"fromHEX",
"(",
"$",
"hex",
")",
"{",
"$",
"hex",
"=",
"preg_replace",
"(",
"'/[^0-9A-Fa-f]/'",
",",
"''",
",",
"$",
"hex",
")",
";",
"$",
"rgb",
"=",
"[",
"]",
";",
"if",
"(",
"strlen",
"(",
"$",
"hex",
")",
"==",
"6",
")",
"{",
"$",
"colorVal",
"=",
"hexdec",
"(",
"$",
"hex",
")",
";",
"$",
"rgb",
"[",
"'red'",
"]",
"=",
"0xFF",
"&",
"(",
"$",
"colorVal",
">>",
"0x10",
")",
";",
"$",
"rgb",
"[",
"'green'",
"]",
"=",
"0xFF",
"&",
"(",
"$",
"colorVal",
">>",
"0x8",
")",
";",
"$",
"rgb",
"[",
"'blue'",
"]",
"=",
"0xFF",
"&",
"$",
"colorVal",
";",
"}",
"elseif",
"(",
"strlen",
"(",
"$",
"hex",
")",
"==",
"3",
")",
"{",
"$",
"rgb",
"[",
"'red'",
"]",
"=",
"hexdec",
"(",
"str_repeat",
"(",
"substr",
"(",
"$",
"hex",
",",
"0",
",",
"1",
")",
",",
"2",
")",
")",
";",
"$",
"rgb",
"[",
"'green'",
"]",
"=",
"hexdec",
"(",
"str_repeat",
"(",
"substr",
"(",
"$",
"hex",
",",
"1",
",",
"1",
")",
",",
"2",
")",
")",
";",
"$",
"rgb",
"[",
"'blue'",
"]",
"=",
"hexdec",
"(",
"str_repeat",
"(",
"substr",
"(",
"$",
"hex",
",",
"2",
",",
"1",
")",
",",
"2",
")",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Given color does not adhere to hexadecimal format'",
")",
";",
"}",
"return",
"self",
"::",
"fromRGB",
"(",
"$",
"rgb",
"[",
"'red'",
"]",
",",
"$",
"rgb",
"[",
"'green'",
"]",
",",
"$",
"rgb",
"[",
"'blue'",
"]",
")",
";",
"}"
] | Creates a Color instance based on the given Hexadecimal-formatted color.
@param string $hex A hexadecimal color value, the # isn't required but can be given
@return Color | [
"Creates",
"a",
"Color",
"instance",
"based",
"on",
"the",
"given",
"Hexadecimal",
"-",
"formatted",
"color",
"."
] | f0f323e99a884d482ec35abf21b49af5ab3fa9c3 | https://github.com/liquidpineapple/color/blob/f0f323e99a884d482ec35abf21b49af5ab3fa9c3/src/Color.php#L88-L106 |
13,190 | liquidpineapple/color | src/Color.php | Color.fromHSV | public static function fromHSV($hue, $saturation, $value)
{
if ($hue < 0 || $hue > 360 ||
$saturation < 0 || $saturation > 100 ||
$value < 0 || $value > 100) {
throw new InvalidArgumentException('Value $hue can only be 0 to 360, $saturation and $value can only be 0 to 100');
}
$hue /= 360;
$saturation /= 100;
$value /= 100;
$H = $hue * 6;
$I = floor($H);
$F = $H - $I;
$M = $value * (1 - $saturation);
$N = $value * (1 - $saturation * $F);
$K = $value * (1 - $saturation * (1 - $F));
switch ($I) {
case 0: list($red, $green, $blue) = [$value, $K, $M]; break;
case 1: list($red, $green, $blue) = [$N, $value, $M]; break;
case 2: list($red, $green, $blue) = [$M, $value, $K]; break;
case 3: list($red, $green, $blue) = [$M, $N, $value]; break;
case 4: list($red, $green, $blue) = [$K, $M, $value]; break;
case 5:
case 6: list($red, $green, $blue) = [$value, $M, $N]; break;
}
$red *= 255;
$green *= 255;
$blue *= 255;
return self::fromRGB($red, $green, $blue);
} | php | public static function fromHSV($hue, $saturation, $value)
{
if ($hue < 0 || $hue > 360 ||
$saturation < 0 || $saturation > 100 ||
$value < 0 || $value > 100) {
throw new InvalidArgumentException('Value $hue can only be 0 to 360, $saturation and $value can only be 0 to 100');
}
$hue /= 360;
$saturation /= 100;
$value /= 100;
$H = $hue * 6;
$I = floor($H);
$F = $H - $I;
$M = $value * (1 - $saturation);
$N = $value * (1 - $saturation * $F);
$K = $value * (1 - $saturation * (1 - $F));
switch ($I) {
case 0: list($red, $green, $blue) = [$value, $K, $M]; break;
case 1: list($red, $green, $blue) = [$N, $value, $M]; break;
case 2: list($red, $green, $blue) = [$M, $value, $K]; break;
case 3: list($red, $green, $blue) = [$M, $N, $value]; break;
case 4: list($red, $green, $blue) = [$K, $M, $value]; break;
case 5:
case 6: list($red, $green, $blue) = [$value, $M, $N]; break;
}
$red *= 255;
$green *= 255;
$blue *= 255;
return self::fromRGB($red, $green, $blue);
} | [
"public",
"static",
"function",
"fromHSV",
"(",
"$",
"hue",
",",
"$",
"saturation",
",",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"hue",
"<",
"0",
"||",
"$",
"hue",
">",
"360",
"||",
"$",
"saturation",
"<",
"0",
"||",
"$",
"saturation",
">",
"100",
"||",
"$",
"value",
"<",
"0",
"||",
"$",
"value",
">",
"100",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Value $hue can only be 0 to 360, $saturation and $value can only be 0 to 100'",
")",
";",
"}",
"$",
"hue",
"/=",
"360",
";",
"$",
"saturation",
"/=",
"100",
";",
"$",
"value",
"/=",
"100",
";",
"$",
"H",
"=",
"$",
"hue",
"*",
"6",
";",
"$",
"I",
"=",
"floor",
"(",
"$",
"H",
")",
";",
"$",
"F",
"=",
"$",
"H",
"-",
"$",
"I",
";",
"$",
"M",
"=",
"$",
"value",
"*",
"(",
"1",
"-",
"$",
"saturation",
")",
";",
"$",
"N",
"=",
"$",
"value",
"*",
"(",
"1",
"-",
"$",
"saturation",
"*",
"$",
"F",
")",
";",
"$",
"K",
"=",
"$",
"value",
"*",
"(",
"1",
"-",
"$",
"saturation",
"*",
"(",
"1",
"-",
"$",
"F",
")",
")",
";",
"switch",
"(",
"$",
"I",
")",
"{",
"case",
"0",
":",
"list",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
"=",
"[",
"$",
"value",
",",
"$",
"K",
",",
"$",
"M",
"]",
";",
"break",
";",
"case",
"1",
":",
"list",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
"=",
"[",
"$",
"N",
",",
"$",
"value",
",",
"$",
"M",
"]",
";",
"break",
";",
"case",
"2",
":",
"list",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
"=",
"[",
"$",
"M",
",",
"$",
"value",
",",
"$",
"K",
"]",
";",
"break",
";",
"case",
"3",
":",
"list",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
"=",
"[",
"$",
"M",
",",
"$",
"N",
",",
"$",
"value",
"]",
";",
"break",
";",
"case",
"4",
":",
"list",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
"=",
"[",
"$",
"K",
",",
"$",
"M",
",",
"$",
"value",
"]",
";",
"break",
";",
"case",
"5",
":",
"case",
"6",
":",
"list",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
"=",
"[",
"$",
"value",
",",
"$",
"M",
",",
"$",
"N",
"]",
";",
"break",
";",
"}",
"$",
"red",
"*=",
"255",
";",
"$",
"green",
"*=",
"255",
";",
"$",
"blue",
"*=",
"255",
";",
"return",
"self",
"::",
"fromRGB",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
";",
"}"
] | Creates a Color instance based on the given HSV-formatted color.
@param int $hue (0-360) The hue of the color (format: HSV)
@param int $saturation (0-100) The saturation of the color (format: HSV)
@param int $value (0-100) The value of the color (format: HSV)
@return Color | [
"Creates",
"a",
"Color",
"instance",
"based",
"on",
"the",
"given",
"HSV",
"-",
"formatted",
"color",
"."
] | f0f323e99a884d482ec35abf21b49af5ab3fa9c3 | https://github.com/liquidpineapple/color/blob/f0f323e99a884d482ec35abf21b49af5ab3fa9c3/src/Color.php#L117-L151 |
13,191 | liquidpineapple/color | src/Color.php | Color.fromHSL | public static function fromHSL($hue, $saturation, $lightness)
{
if ($hue < 0 || $hue > 360 ||
$saturation < 0 || $saturation > 100 ||
$lightness < 0 || $lightness > 100) {
throw new InvalidArgumentException('Value $hue can only be 0 to 360, $saturation and $lightness can only be 0 to 100');
}
return new self($hue, $saturation, $lightness);
} | php | public static function fromHSL($hue, $saturation, $lightness)
{
if ($hue < 0 || $hue > 360 ||
$saturation < 0 || $saturation > 100 ||
$lightness < 0 || $lightness > 100) {
throw new InvalidArgumentException('Value $hue can only be 0 to 360, $saturation and $lightness can only be 0 to 100');
}
return new self($hue, $saturation, $lightness);
} | [
"public",
"static",
"function",
"fromHSL",
"(",
"$",
"hue",
",",
"$",
"saturation",
",",
"$",
"lightness",
")",
"{",
"if",
"(",
"$",
"hue",
"<",
"0",
"||",
"$",
"hue",
">",
"360",
"||",
"$",
"saturation",
"<",
"0",
"||",
"$",
"saturation",
">",
"100",
"||",
"$",
"lightness",
"<",
"0",
"||",
"$",
"lightness",
">",
"100",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Value $hue can only be 0 to 360, $saturation and $lightness can only be 0 to 100'",
")",
";",
"}",
"return",
"new",
"self",
"(",
"$",
"hue",
",",
"$",
"saturation",
",",
"$",
"lightness",
")",
";",
"}"
] | Creates a Color instance based on the given HSL-formatted color.
@param int $hue (0-360) The hue of the color (format: HSL)
@param int $saturation (0-100) The saturation of the color (format: HSL)
@param int $lightness (0-100) The lightness of the color (format: HSL)
@return Color | [
"Creates",
"a",
"Color",
"instance",
"based",
"on",
"the",
"given",
"HSL",
"-",
"formatted",
"color",
"."
] | f0f323e99a884d482ec35abf21b49af5ab3fa9c3 | https://github.com/liquidpineapple/color/blob/f0f323e99a884d482ec35abf21b49af5ab3fa9c3/src/Color.php#L162-L171 |
13,192 | liquidpineapple/color | src/Color.php | Color.lighten | public function lighten($amount)
{
if ($amount < 0 || $amount > 100) {
throw new InvalidArgumentException('The given amount must be between 0 and 100');
}
$amount /= 100;
$this->lightness += (100 - $this->lightness) * $amount;
return $this;
} | php | public function lighten($amount)
{
if ($amount < 0 || $amount > 100) {
throw new InvalidArgumentException('The given amount must be between 0 and 100');
}
$amount /= 100;
$this->lightness += (100 - $this->lightness) * $amount;
return $this;
} | [
"public",
"function",
"lighten",
"(",
"$",
"amount",
")",
"{",
"if",
"(",
"$",
"amount",
"<",
"0",
"||",
"$",
"amount",
">",
"100",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The given amount must be between 0 and 100'",
")",
";",
"}",
"$",
"amount",
"/=",
"100",
";",
"$",
"this",
"->",
"lightness",
"+=",
"(",
"100",
"-",
"$",
"this",
"->",
"lightness",
")",
"*",
"$",
"amount",
";",
"return",
"$",
"this",
";",
"}"
] | Alters the color by lightening it with the given percentage.
@param int $amount (0-100) Percentage with which to lighten the color
@return Color | [
"Alters",
"the",
"color",
"by",
"lightening",
"it",
"with",
"the",
"given",
"percentage",
"."
] | f0f323e99a884d482ec35abf21b49af5ab3fa9c3 | https://github.com/liquidpineapple/color/blob/f0f323e99a884d482ec35abf21b49af5ab3fa9c3/src/Color.php#L180-L189 |
13,193 | liquidpineapple/color | src/Color.php | Color.darken | public function darken($amount)
{
if ($amount < 0 || $amount > 100) {
throw new InvalidArgumentException('The given amount must be between 0 and 100');
}
$amount /= 100;
$this->lightness -= $this->lightness * $amount;
return $this;
} | php | public function darken($amount)
{
if ($amount < 0 || $amount > 100) {
throw new InvalidArgumentException('The given amount must be between 0 and 100');
}
$amount /= 100;
$this->lightness -= $this->lightness * $amount;
return $this;
} | [
"public",
"function",
"darken",
"(",
"$",
"amount",
")",
"{",
"if",
"(",
"$",
"amount",
"<",
"0",
"||",
"$",
"amount",
">",
"100",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The given amount must be between 0 and 100'",
")",
";",
"}",
"$",
"amount",
"/=",
"100",
";",
"$",
"this",
"->",
"lightness",
"-=",
"$",
"this",
"->",
"lightness",
"*",
"$",
"amount",
";",
"return",
"$",
"this",
";",
"}"
] | Alters the color by darkening it with the given percentage.
@param int $amount (0-100) Percentage with which to darken the color
@return Color | [
"Alters",
"the",
"color",
"by",
"darkening",
"it",
"with",
"the",
"given",
"percentage",
"."
] | f0f323e99a884d482ec35abf21b49af5ab3fa9c3 | https://github.com/liquidpineapple/color/blob/f0f323e99a884d482ec35abf21b49af5ab3fa9c3/src/Color.php#L198-L207 |
13,194 | liquidpineapple/color | src/Color.php | Color.saturate | public function saturate($amount)
{
if ($amount < 0 || $amount > 100) {
throw new InvalidArgumentException('The given amount must be between 0 and 100');
}
$amount /= 100;
$this->saturation += (100 - $this->saturation) * $amount;
return $this;
} | php | public function saturate($amount)
{
if ($amount < 0 || $amount > 100) {
throw new InvalidArgumentException('The given amount must be between 0 and 100');
}
$amount /= 100;
$this->saturation += (100 - $this->saturation) * $amount;
return $this;
} | [
"public",
"function",
"saturate",
"(",
"$",
"amount",
")",
"{",
"if",
"(",
"$",
"amount",
"<",
"0",
"||",
"$",
"amount",
">",
"100",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The given amount must be between 0 and 100'",
")",
";",
"}",
"$",
"amount",
"/=",
"100",
";",
"$",
"this",
"->",
"saturation",
"+=",
"(",
"100",
"-",
"$",
"this",
"->",
"saturation",
")",
"*",
"$",
"amount",
";",
"return",
"$",
"this",
";",
"}"
] | Alters the color by saturating it with the given percentage.
@param int $amount (0-100) Percentage with which to saturate the color
@return Color | [
"Alters",
"the",
"color",
"by",
"saturating",
"it",
"with",
"the",
"given",
"percentage",
"."
] | f0f323e99a884d482ec35abf21b49af5ab3fa9c3 | https://github.com/liquidpineapple/color/blob/f0f323e99a884d482ec35abf21b49af5ab3fa9c3/src/Color.php#L216-L225 |
13,195 | liquidpineapple/color | src/Color.php | Color.desaturate | public function desaturate($amount)
{
if ($amount < 0 || $amount > 100) {
throw new InvalidArgumentException('The given amount must be between 0 and 100');
}
$amount /= 100;
$this->saturation -= $this->saturation * $amount;
return $this;
} | php | public function desaturate($amount)
{
if ($amount < 0 || $amount > 100) {
throw new InvalidArgumentException('The given amount must be between 0 and 100');
}
$amount /= 100;
$this->saturation -= $this->saturation * $amount;
return $this;
} | [
"public",
"function",
"desaturate",
"(",
"$",
"amount",
")",
"{",
"if",
"(",
"$",
"amount",
"<",
"0",
"||",
"$",
"amount",
">",
"100",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The given amount must be between 0 and 100'",
")",
";",
"}",
"$",
"amount",
"/=",
"100",
";",
"$",
"this",
"->",
"saturation",
"-=",
"$",
"this",
"->",
"saturation",
"*",
"$",
"amount",
";",
"return",
"$",
"this",
";",
"}"
] | Alters the color by desaturating it with the given percentage.
@param int $amount (0-100) Percentage with which to desaturate the color
@return Color | [
"Alters",
"the",
"color",
"by",
"desaturating",
"it",
"with",
"the",
"given",
"percentage",
"."
] | f0f323e99a884d482ec35abf21b49af5ab3fa9c3 | https://github.com/liquidpineapple/color/blob/f0f323e99a884d482ec35abf21b49af5ab3fa9c3/src/Color.php#L234-L243 |
13,196 | liquidpineapple/color | src/Color.php | Color.toHSL | public function toHSL()
{
return [
round($this->hue),
round($this->saturation),
round($this->lightness),
];
} | php | public function toHSL()
{
return [
round($this->hue),
round($this->saturation),
round($this->lightness),
];
} | [
"public",
"function",
"toHSL",
"(",
")",
"{",
"return",
"[",
"round",
"(",
"$",
"this",
"->",
"hue",
")",
",",
"round",
"(",
"$",
"this",
"->",
"saturation",
")",
",",
"round",
"(",
"$",
"this",
"->",
"lightness",
")",
",",
"]",
";",
"}"
] | Outputs the color using the HSL format.
@return array HSL representation of the color | [
"Outputs",
"the",
"color",
"using",
"the",
"HSL",
"format",
"."
] | f0f323e99a884d482ec35abf21b49af5ab3fa9c3 | https://github.com/liquidpineapple/color/blob/f0f323e99a884d482ec35abf21b49af5ab3fa9c3/src/Color.php#L250-L257 |
13,197 | liquidpineapple/color | src/Color.php | Color.toRGB | public function toRGB()
{
$h = $this->hue;
$s = $this->saturation / 100;
$l = $this->lightness / 100;
$r;
$g;
$b;
$c = (1 - abs(2 * $l - 1)) * $s;
$x = $c * (1 - abs(fmod(($h / 60), 2) - 1));
$m = $l - ($c / 2);
if ($h < 60) {
list($r, $g, $b) = [$c, $x, 0];
} elseif ($h < 120) {
list($r, $g, $b) = [$x, $c, 0];
} elseif ($h < 180) {
list($r, $g, $b) = [0, $c, $x];
} elseif ($h < 240) {
list($r, $g, $b) = [0, $x, $c];
} elseif ($h < 300) {
list($r, $g, $b) = [$x, 0, $c];
} else {
list($r, $g, $b) = [$c, 0, $x];
}
$r = ($r + $m) * 255;
$g = ($g + $m) * 255;
$b = ($b + $m) * 255;
return [
round($r),
round($g),
round($b),
];
} | php | public function toRGB()
{
$h = $this->hue;
$s = $this->saturation / 100;
$l = $this->lightness / 100;
$r;
$g;
$b;
$c = (1 - abs(2 * $l - 1)) * $s;
$x = $c * (1 - abs(fmod(($h / 60), 2) - 1));
$m = $l - ($c / 2);
if ($h < 60) {
list($r, $g, $b) = [$c, $x, 0];
} elseif ($h < 120) {
list($r, $g, $b) = [$x, $c, 0];
} elseif ($h < 180) {
list($r, $g, $b) = [0, $c, $x];
} elseif ($h < 240) {
list($r, $g, $b) = [0, $x, $c];
} elseif ($h < 300) {
list($r, $g, $b) = [$x, 0, $c];
} else {
list($r, $g, $b) = [$c, 0, $x];
}
$r = ($r + $m) * 255;
$g = ($g + $m) * 255;
$b = ($b + $m) * 255;
return [
round($r),
round($g),
round($b),
];
} | [
"public",
"function",
"toRGB",
"(",
")",
"{",
"$",
"h",
"=",
"$",
"this",
"->",
"hue",
";",
"$",
"s",
"=",
"$",
"this",
"->",
"saturation",
"/",
"100",
";",
"$",
"l",
"=",
"$",
"this",
"->",
"lightness",
"/",
"100",
";",
"$",
"r",
";",
"$",
"g",
";",
"$",
"b",
";",
"$",
"c",
"=",
"(",
"1",
"-",
"abs",
"(",
"2",
"*",
"$",
"l",
"-",
"1",
")",
")",
"*",
"$",
"s",
";",
"$",
"x",
"=",
"$",
"c",
"*",
"(",
"1",
"-",
"abs",
"(",
"fmod",
"(",
"(",
"$",
"h",
"/",
"60",
")",
",",
"2",
")",
"-",
"1",
")",
")",
";",
"$",
"m",
"=",
"$",
"l",
"-",
"(",
"$",
"c",
"/",
"2",
")",
";",
"if",
"(",
"$",
"h",
"<",
"60",
")",
"{",
"list",
"(",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
"=",
"[",
"$",
"c",
",",
"$",
"x",
",",
"0",
"]",
";",
"}",
"elseif",
"(",
"$",
"h",
"<",
"120",
")",
"{",
"list",
"(",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
"=",
"[",
"$",
"x",
",",
"$",
"c",
",",
"0",
"]",
";",
"}",
"elseif",
"(",
"$",
"h",
"<",
"180",
")",
"{",
"list",
"(",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
"=",
"[",
"0",
",",
"$",
"c",
",",
"$",
"x",
"]",
";",
"}",
"elseif",
"(",
"$",
"h",
"<",
"240",
")",
"{",
"list",
"(",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
"=",
"[",
"0",
",",
"$",
"x",
",",
"$",
"c",
"]",
";",
"}",
"elseif",
"(",
"$",
"h",
"<",
"300",
")",
"{",
"list",
"(",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
"=",
"[",
"$",
"x",
",",
"0",
",",
"$",
"c",
"]",
";",
"}",
"else",
"{",
"list",
"(",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
"=",
"[",
"$",
"c",
",",
"0",
",",
"$",
"x",
"]",
";",
"}",
"$",
"r",
"=",
"(",
"$",
"r",
"+",
"$",
"m",
")",
"*",
"255",
";",
"$",
"g",
"=",
"(",
"$",
"g",
"+",
"$",
"m",
")",
"*",
"255",
";",
"$",
"b",
"=",
"(",
"$",
"b",
"+",
"$",
"m",
")",
"*",
"255",
";",
"return",
"[",
"round",
"(",
"$",
"r",
")",
",",
"round",
"(",
"$",
"g",
")",
",",
"round",
"(",
"$",
"b",
")",
",",
"]",
";",
"}"
] | Outputs the color using the RGB format.
@return array RGB representation of the color | [
"Outputs",
"the",
"color",
"using",
"the",
"RGB",
"format",
"."
] | f0f323e99a884d482ec35abf21b49af5ab3fa9c3 | https://github.com/liquidpineapple/color/blob/f0f323e99a884d482ec35abf21b49af5ab3fa9c3/src/Color.php#L276-L309 |
13,198 | liquidpineapple/color | src/Color.php | Color.toHEX | public function toHEX()
{
list($red, $green, $blue) = $this->toRGB();
return strtoupper(sprintf('#%02x%02x%02x', $red, $green, $blue));
} | php | public function toHEX()
{
list($red, $green, $blue) = $this->toRGB();
return strtoupper(sprintf('#%02x%02x%02x', $red, $green, $blue));
} | [
"public",
"function",
"toHEX",
"(",
")",
"{",
"list",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
"=",
"$",
"this",
"->",
"toRGB",
"(",
")",
";",
"return",
"strtoupper",
"(",
"sprintf",
"(",
"'#%02x%02x%02x'",
",",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
")",
";",
"}"
] | Outputs the color using the HEX format.
@return array HEX representation of the color | [
"Outputs",
"the",
"color",
"using",
"the",
"HEX",
"format",
"."
] | f0f323e99a884d482ec35abf21b49af5ab3fa9c3 | https://github.com/liquidpineapple/color/blob/f0f323e99a884d482ec35abf21b49af5ab3fa9c3/src/Color.php#L328-L333 |
13,199 | liquidpineapple/color | src/Color.php | Color.toHSV | public function toHSV()
{
list($red, $green, $blue) = $this->toRGB();
$red /= 255;
$green /= 255;
$blue /= 255;
$maxRGB = max($red, $green, $blue);
$minRGB = min($red, $green, $blue);
$chroma = $maxRGB - $minRGB;
$value = 100 * $maxRGB;
if ($chroma == 0) {
return [0, 0, $value];
}
$saturation = 100 * ($chroma / $maxRGB);
if ($red == $minRGB) {
$h = 3 - (($green - $blue) / $chroma);
} elseif ($blue == $minRGB) {
$h = 1 - (($red - $green) / $chroma);
} else {
$h = 5 - (($blue - $red) / $chroma);
}
$hue = 60 * $h;
return [
round($hue),
round($saturation),
round($value),
];
} | php | public function toHSV()
{
list($red, $green, $blue) = $this->toRGB();
$red /= 255;
$green /= 255;
$blue /= 255;
$maxRGB = max($red, $green, $blue);
$minRGB = min($red, $green, $blue);
$chroma = $maxRGB - $minRGB;
$value = 100 * $maxRGB;
if ($chroma == 0) {
return [0, 0, $value];
}
$saturation = 100 * ($chroma / $maxRGB);
if ($red == $minRGB) {
$h = 3 - (($green - $blue) / $chroma);
} elseif ($blue == $minRGB) {
$h = 1 - (($red - $green) / $chroma);
} else {
$h = 5 - (($blue - $red) / $chroma);
}
$hue = 60 * $h;
return [
round($hue),
round($saturation),
round($value),
];
} | [
"public",
"function",
"toHSV",
"(",
")",
"{",
"list",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
"=",
"$",
"this",
"->",
"toRGB",
"(",
")",
";",
"$",
"red",
"/=",
"255",
";",
"$",
"green",
"/=",
"255",
";",
"$",
"blue",
"/=",
"255",
";",
"$",
"maxRGB",
"=",
"max",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
";",
"$",
"minRGB",
"=",
"min",
"(",
"$",
"red",
",",
"$",
"green",
",",
"$",
"blue",
")",
";",
"$",
"chroma",
"=",
"$",
"maxRGB",
"-",
"$",
"minRGB",
";",
"$",
"value",
"=",
"100",
"*",
"$",
"maxRGB",
";",
"if",
"(",
"$",
"chroma",
"==",
"0",
")",
"{",
"return",
"[",
"0",
",",
"0",
",",
"$",
"value",
"]",
";",
"}",
"$",
"saturation",
"=",
"100",
"*",
"(",
"$",
"chroma",
"/",
"$",
"maxRGB",
")",
";",
"if",
"(",
"$",
"red",
"==",
"$",
"minRGB",
")",
"{",
"$",
"h",
"=",
"3",
"-",
"(",
"(",
"$",
"green",
"-",
"$",
"blue",
")",
"/",
"$",
"chroma",
")",
";",
"}",
"elseif",
"(",
"$",
"blue",
"==",
"$",
"minRGB",
")",
"{",
"$",
"h",
"=",
"1",
"-",
"(",
"(",
"$",
"red",
"-",
"$",
"green",
")",
"/",
"$",
"chroma",
")",
";",
"}",
"else",
"{",
"$",
"h",
"=",
"5",
"-",
"(",
"(",
"$",
"blue",
"-",
"$",
"red",
")",
"/",
"$",
"chroma",
")",
";",
"}",
"$",
"hue",
"=",
"60",
"*",
"$",
"h",
";",
"return",
"[",
"round",
"(",
"$",
"hue",
")",
",",
"round",
"(",
"$",
"saturation",
")",
",",
"round",
"(",
"$",
"value",
")",
",",
"]",
";",
"}"
] | Outputs the color using the HSV format.
@return array HSV representation of the color | [
"Outputs",
"the",
"color",
"using",
"the",
"HSV",
"format",
"."
] | f0f323e99a884d482ec35abf21b49af5ab3fa9c3 | https://github.com/liquidpineapple/color/blob/f0f323e99a884d482ec35abf21b49af5ab3fa9c3/src/Color.php#L350-L384 |
Subsets and Splits