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
|
---|---|---|---|---|---|---|---|---|---|---|---|
2,400 | gourmet/common | View/Helper/TableHelper.php | TableHelper._replaceCurrency | protected function _replaceCurrency($str) {
if (!preg_match_all('/\[currency(.*?)\](.*)\[\/currency\]/i', $str, $matches)) {
// Fallback regex for when no options are passed.
if (!preg_match_all('/\[currency(.*?)\](.[^\[]*)\[\/currency\]/i', $str, $matches)) {
return $str;
}
}
foreach ($matches[0] as $i => $find) {
$opts = $this->_extractAttributes(trim($matches[1][$i]));
$currency = CakeNumber::defaultCurrency();
if (isset($opts['currency'])) {
$currency = $opts['currency'];
unset($opts['currency']);
}
$replace = (empty($matches[2][$i]) || !is_numeric($matches[2][$i])) ? '' : CakeNumber::currency($matches[2][$i], $currency, $opts);
$str = str_replace($find, $replace, $str);
}
return $str;
} | php | protected function _replaceCurrency($str) {
if (!preg_match_all('/\[currency(.*?)\](.*)\[\/currency\]/i', $str, $matches)) {
// Fallback regex for when no options are passed.
if (!preg_match_all('/\[currency(.*?)\](.[^\[]*)\[\/currency\]/i', $str, $matches)) {
return $str;
}
}
foreach ($matches[0] as $i => $find) {
$opts = $this->_extractAttributes(trim($matches[1][$i]));
$currency = CakeNumber::defaultCurrency();
if (isset($opts['currency'])) {
$currency = $opts['currency'];
unset($opts['currency']);
}
$replace = (empty($matches[2][$i]) || !is_numeric($matches[2][$i])) ? '' : CakeNumber::currency($matches[2][$i], $currency, $opts);
$str = str_replace($find, $replace, $str);
}
return $str;
} | [
"protected",
"function",
"_replaceCurrency",
"(",
"$",
"str",
")",
"{",
"if",
"(",
"!",
"preg_match_all",
"(",
"'/\\[currency(.*?)\\](.*)\\[\\/currency\\]/i'",
",",
"$",
"str",
",",
"$",
"matches",
")",
")",
"{",
"// Fallback regex for when no options are passed.",
"if",
"(",
"!",
"preg_match_all",
"(",
"'/\\[currency(.*?)\\](.[^\\[]*)\\[\\/currency\\]/i'",
",",
"$",
"str",
",",
"$",
"matches",
")",
")",
"{",
"return",
"$",
"str",
";",
"}",
"}",
"foreach",
"(",
"$",
"matches",
"[",
"0",
"]",
"as",
"$",
"i",
"=>",
"$",
"find",
")",
"{",
"$",
"opts",
"=",
"$",
"this",
"->",
"_extractAttributes",
"(",
"trim",
"(",
"$",
"matches",
"[",
"1",
"]",
"[",
"$",
"i",
"]",
")",
")",
";",
"$",
"currency",
"=",
"CakeNumber",
"::",
"defaultCurrency",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"opts",
"[",
"'currency'",
"]",
")",
")",
"{",
"$",
"currency",
"=",
"$",
"opts",
"[",
"'currency'",
"]",
";",
"unset",
"(",
"$",
"opts",
"[",
"'currency'",
"]",
")",
";",
"}",
"$",
"replace",
"=",
"(",
"empty",
"(",
"$",
"matches",
"[",
"2",
"]",
"[",
"$",
"i",
"]",
")",
"||",
"!",
"is_numeric",
"(",
"$",
"matches",
"[",
"2",
"]",
"[",
"$",
"i",
"]",
")",
")",
"?",
"''",
":",
"CakeNumber",
"::",
"currency",
"(",
"$",
"matches",
"[",
"2",
"]",
"[",
"$",
"i",
"]",
",",
"$",
"currency",
",",
"$",
"opts",
")",
";",
"$",
"str",
"=",
"str_replace",
"(",
"$",
"find",
",",
"$",
"replace",
",",
"$",
"str",
")",
";",
"}",
"return",
"$",
"str",
";",
"}"
] | Replace by formatted currency string.
Examples:
- [currency]50[/currency]
- [currency zero="$0.00"]0[/currency]
@param string $str String to check and modify.
@return string Modified string. | [
"Replace",
"by",
"formatted",
"currency",
"string",
"."
] | 53ad4e919c51606dc81f2c716267d01ee768ade5 | https://github.com/gourmet/common/blob/53ad4e919c51606dc81f2c716267d01ee768ade5/View/Helper/TableHelper.php#L436-L458 |
2,401 | gourmet/common | View/Helper/TableHelper.php | TableHelper._replaceTime | protected function _replaceTime($str) {
if (!preg_match_all('/\[time(.*?)\](.*)\[\/time\]/i', $str, $matches)) {
// Fallback regex for when no options are passed.
if (!preg_match_all('/\[time(.*?)\](.[^\[]*)\[\/time\]/i', $str, $matches)) {
return $str;
}
}
foreach ($matches[0] as $i => $find) {
$opts = $this->_extractAttributes(trim($matches[1][$i]));
foreach (Hash::normalize(array('method' => 'nice', 'format', 'timezone')) as $k => $v) {
${$k} = $v;
if (isset($opts[$k])) {
${$k} = $opts[$k];
unset($opts[$k]);
}
}
App::uses('CakeTime', 'Utility');
$replace = (empty($matches[2][$i])) ? '' : CakeTime::$method($matches[2][$i], $timezone, $format);
$str = str_replace($find, $replace, $str);
}
return $str;
} | php | protected function _replaceTime($str) {
if (!preg_match_all('/\[time(.*?)\](.*)\[\/time\]/i', $str, $matches)) {
// Fallback regex for when no options are passed.
if (!preg_match_all('/\[time(.*?)\](.[^\[]*)\[\/time\]/i', $str, $matches)) {
return $str;
}
}
foreach ($matches[0] as $i => $find) {
$opts = $this->_extractAttributes(trim($matches[1][$i]));
foreach (Hash::normalize(array('method' => 'nice', 'format', 'timezone')) as $k => $v) {
${$k} = $v;
if (isset($opts[$k])) {
${$k} = $opts[$k];
unset($opts[$k]);
}
}
App::uses('CakeTime', 'Utility');
$replace = (empty($matches[2][$i])) ? '' : CakeTime::$method($matches[2][$i], $timezone, $format);
$str = str_replace($find, $replace, $str);
}
return $str;
} | [
"protected",
"function",
"_replaceTime",
"(",
"$",
"str",
")",
"{",
"if",
"(",
"!",
"preg_match_all",
"(",
"'/\\[time(.*?)\\](.*)\\[\\/time\\]/i'",
",",
"$",
"str",
",",
"$",
"matches",
")",
")",
"{",
"// Fallback regex for when no options are passed.",
"if",
"(",
"!",
"preg_match_all",
"(",
"'/\\[time(.*?)\\](.[^\\[]*)\\[\\/time\\]/i'",
",",
"$",
"str",
",",
"$",
"matches",
")",
")",
"{",
"return",
"$",
"str",
";",
"}",
"}",
"foreach",
"(",
"$",
"matches",
"[",
"0",
"]",
"as",
"$",
"i",
"=>",
"$",
"find",
")",
"{",
"$",
"opts",
"=",
"$",
"this",
"->",
"_extractAttributes",
"(",
"trim",
"(",
"$",
"matches",
"[",
"1",
"]",
"[",
"$",
"i",
"]",
")",
")",
";",
"foreach",
"(",
"Hash",
"::",
"normalize",
"(",
"array",
"(",
"'method'",
"=>",
"'nice'",
",",
"'format'",
",",
"'timezone'",
")",
")",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"{",
"$",
"k",
"}",
"=",
"$",
"v",
";",
"if",
"(",
"isset",
"(",
"$",
"opts",
"[",
"$",
"k",
"]",
")",
")",
"{",
"$",
"{",
"$",
"k",
"}",
"=",
"$",
"opts",
"[",
"$",
"k",
"]",
";",
"unset",
"(",
"$",
"opts",
"[",
"$",
"k",
"]",
")",
";",
"}",
"}",
"App",
"::",
"uses",
"(",
"'CakeTime'",
",",
"'Utility'",
")",
";",
"$",
"replace",
"=",
"(",
"empty",
"(",
"$",
"matches",
"[",
"2",
"]",
"[",
"$",
"i",
"]",
")",
")",
"?",
"''",
":",
"CakeTime",
"::",
"$",
"method",
"(",
"$",
"matches",
"[",
"2",
"]",
"[",
"$",
"i",
"]",
",",
"$",
"timezone",
",",
"$",
"format",
")",
";",
"$",
"str",
"=",
"str_replace",
"(",
"$",
"find",
",",
"$",
"replace",
",",
"$",
"str",
")",
";",
"}",
"return",
"$",
"str",
";",
"}"
] | Replace by formatted time string.
Examples:
- [time]...[/time]
- [time format="m-d-Y"]...[/time]
- [time method="niceShort"]..[/time]
@param string $str String to check and modify.
@return string Modified string. | [
"Replace",
"by",
"formatted",
"time",
"string",
"."
] | 53ad4e919c51606dc81f2c716267d01ee768ade5 | https://github.com/gourmet/common/blob/53ad4e919c51606dc81f2c716267d01ee768ade5/View/Helper/TableHelper.php#L471-L497 |
2,402 | gourmet/common | View/Helper/TableHelper.php | TableHelper._replaceTranslate | protected function _replaceTranslate($str) {
// [__]Text to translate[/__]
if (preg_match_all('/\[__\](.*?)\[\/__\]/i', $str, $matches)) {
foreach ($matches[0] as $i => $find) {
$str = str_replace($find, I18n::translate($matches[1][$i]), $str);
}
}
// [__d|domain]Text to translate[/__d]
if (preg_match_all('/\[__d\|(.+?)\](.*?)\[\/__d\]/i', $str, $matches)) {
foreach ($matches[0] as $i => $find) {
$str = str_replace($find, I18n::translate($matches[2][$i], null, $matches[1][$i]), $str);
}
}
// [__c|category]Text to translate[/__c]
if (preg_match_all('/\[__c\|(.+?)\](.*?)\[\/__c\]/i', $str, $matches)) {
foreach ($matches[0] as $i => $find) {
$str = str_replace($find, I18n::translate($matches[2][$i], null, null, $matches[1][$i]), $str);
}
}
return $str;
} | php | protected function _replaceTranslate($str) {
// [__]Text to translate[/__]
if (preg_match_all('/\[__\](.*?)\[\/__\]/i', $str, $matches)) {
foreach ($matches[0] as $i => $find) {
$str = str_replace($find, I18n::translate($matches[1][$i]), $str);
}
}
// [__d|domain]Text to translate[/__d]
if (preg_match_all('/\[__d\|(.+?)\](.*?)\[\/__d\]/i', $str, $matches)) {
foreach ($matches[0] as $i => $find) {
$str = str_replace($find, I18n::translate($matches[2][$i], null, $matches[1][$i]), $str);
}
}
// [__c|category]Text to translate[/__c]
if (preg_match_all('/\[__c\|(.+?)\](.*?)\[\/__c\]/i', $str, $matches)) {
foreach ($matches[0] as $i => $find) {
$str = str_replace($find, I18n::translate($matches[2][$i], null, null, $matches[1][$i]), $str);
}
}
return $str;
} | [
"protected",
"function",
"_replaceTranslate",
"(",
"$",
"str",
")",
"{",
"// [__]Text to translate[/__]",
"if",
"(",
"preg_match_all",
"(",
"'/\\[__\\](.*?)\\[\\/__\\]/i'",
",",
"$",
"str",
",",
"$",
"matches",
")",
")",
"{",
"foreach",
"(",
"$",
"matches",
"[",
"0",
"]",
"as",
"$",
"i",
"=>",
"$",
"find",
")",
"{",
"$",
"str",
"=",
"str_replace",
"(",
"$",
"find",
",",
"I18n",
"::",
"translate",
"(",
"$",
"matches",
"[",
"1",
"]",
"[",
"$",
"i",
"]",
")",
",",
"$",
"str",
")",
";",
"}",
"}",
"// [__d|domain]Text to translate[/__d]",
"if",
"(",
"preg_match_all",
"(",
"'/\\[__d\\|(.+?)\\](.*?)\\[\\/__d\\]/i'",
",",
"$",
"str",
",",
"$",
"matches",
")",
")",
"{",
"foreach",
"(",
"$",
"matches",
"[",
"0",
"]",
"as",
"$",
"i",
"=>",
"$",
"find",
")",
"{",
"$",
"str",
"=",
"str_replace",
"(",
"$",
"find",
",",
"I18n",
"::",
"translate",
"(",
"$",
"matches",
"[",
"2",
"]",
"[",
"$",
"i",
"]",
",",
"null",
",",
"$",
"matches",
"[",
"1",
"]",
"[",
"$",
"i",
"]",
")",
",",
"$",
"str",
")",
";",
"}",
"}",
"// [__c|category]Text to translate[/__c]",
"if",
"(",
"preg_match_all",
"(",
"'/\\[__c\\|(.+?)\\](.*?)\\[\\/__c\\]/i'",
",",
"$",
"str",
",",
"$",
"matches",
")",
")",
"{",
"foreach",
"(",
"$",
"matches",
"[",
"0",
"]",
"as",
"$",
"i",
"=>",
"$",
"find",
")",
"{",
"$",
"str",
"=",
"str_replace",
"(",
"$",
"find",
",",
"I18n",
"::",
"translate",
"(",
"$",
"matches",
"[",
"2",
"]",
"[",
"$",
"i",
"]",
",",
"null",
",",
"null",
",",
"$",
"matches",
"[",
"1",
"]",
"[",
"$",
"i",
"]",
")",
",",
"$",
"str",
")",
";",
"}",
"}",
"return",
"$",
"str",
";",
"}"
] | Replace translatable strings by their translated values.
Examples:
- [__]Translate this[/__]
- [__d|domain]Translate this[/__d]
- [__c|category]Translate this[/__c]
@param string $str String to check and modify.
@return string Modified string. | [
"Replace",
"translatable",
"strings",
"by",
"their",
"translated",
"values",
"."
] | 53ad4e919c51606dc81f2c716267d01ee768ade5 | https://github.com/gourmet/common/blob/53ad4e919c51606dc81f2c716267d01ee768ade5/View/Helper/TableHelper.php#L703-L726 |
2,403 | trivialsense/php-framework-common | src/TrivialSense/FrameworkCommon/Controller/AbstractController.php | AbstractController.redirectToPath | public function redirectToPath($path, $parameters = array())
{
$route = $this->getRouter()->generate($path, $parameters);
return $this->redirect($route);
} | php | public function redirectToPath($path, $parameters = array())
{
$route = $this->getRouter()->generate($path, $parameters);
return $this->redirect($route);
} | [
"public",
"function",
"redirectToPath",
"(",
"$",
"path",
",",
"$",
"parameters",
"=",
"array",
"(",
")",
")",
"{",
"$",
"route",
"=",
"$",
"this",
"->",
"getRouter",
"(",
")",
"->",
"generate",
"(",
"$",
"path",
",",
"$",
"parameters",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"route",
")",
";",
"}"
] | Returns a ResponseRedirect to a given route name
@param $path
@param array $parameters
@return \Symfony\Component\HttpFoundation\RedirectResponse | [
"Returns",
"a",
"ResponseRedirect",
"to",
"a",
"given",
"route",
"name"
] | 3cb769c62df7badaeae557306c8f738252adaa28 | https://github.com/trivialsense/php-framework-common/blob/3cb769c62df7badaeae557306c8f738252adaa28/src/TrivialSense/FrameworkCommon/Controller/AbstractController.php#L75-L80 |
2,404 | trivialsense/php-framework-common | src/TrivialSense/FrameworkCommon/Controller/AbstractController.php | AbstractController.sendFile | public function sendFile($filePath, $fileName = null)
{
if ($filePath instanceof File) {
$filePath = $filePath->getPathname();
}
$response = new Response();
$response->headers->set('Cache-Control', 'private');
$response->headers->set('Content-Type', mime_content_type($filePath));
$response->headers->set('Content-Disposition', 'attachment;filename="' . ($fileName ?: basename($filePath)). '"');
$response->headers->set('Content-Length', filesize($filePath));
$response->setContent(file_get_contents($filePath));
return $response;
} | php | public function sendFile($filePath, $fileName = null)
{
if ($filePath instanceof File) {
$filePath = $filePath->getPathname();
}
$response = new Response();
$response->headers->set('Cache-Control', 'private');
$response->headers->set('Content-Type', mime_content_type($filePath));
$response->headers->set('Content-Disposition', 'attachment;filename="' . ($fileName ?: basename($filePath)). '"');
$response->headers->set('Content-Length', filesize($filePath));
$response->setContent(file_get_contents($filePath));
return $response;
} | [
"public",
"function",
"sendFile",
"(",
"$",
"filePath",
",",
"$",
"fileName",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"filePath",
"instanceof",
"File",
")",
"{",
"$",
"filePath",
"=",
"$",
"filePath",
"->",
"getPathname",
"(",
")",
";",
"}",
"$",
"response",
"=",
"new",
"Response",
"(",
")",
";",
"$",
"response",
"->",
"headers",
"->",
"set",
"(",
"'Cache-Control'",
",",
"'private'",
")",
";",
"$",
"response",
"->",
"headers",
"->",
"set",
"(",
"'Content-Type'",
",",
"mime_content_type",
"(",
"$",
"filePath",
")",
")",
";",
"$",
"response",
"->",
"headers",
"->",
"set",
"(",
"'Content-Disposition'",
",",
"'attachment;filename=\"'",
".",
"(",
"$",
"fileName",
"?",
":",
"basename",
"(",
"$",
"filePath",
")",
")",
".",
"'\"'",
")",
";",
"$",
"response",
"->",
"headers",
"->",
"set",
"(",
"'Content-Length'",
",",
"filesize",
"(",
"$",
"filePath",
")",
")",
";",
"$",
"response",
"->",
"setContent",
"(",
"file_get_contents",
"(",
"$",
"filePath",
")",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Sends a Response serving a given file
@param $filePath
@param string $fileName Custom name, to replace original one
@return Response | [
"Sends",
"a",
"Response",
"serving",
"a",
"given",
"file"
] | 3cb769c62df7badaeae557306c8f738252adaa28 | https://github.com/trivialsense/php-framework-common/blob/3cb769c62df7badaeae557306c8f738252adaa28/src/TrivialSense/FrameworkCommon/Controller/AbstractController.php#L90-L105 |
2,405 | trivialsense/php-framework-common | src/TrivialSense/FrameworkCommon/Controller/AbstractController.php | AbstractController.createAndSubmitForm | public function createAndSubmitForm($type, $data = null, callable $validCallback = null)
{
$form = $this->createForm($type, $data);
if ($this->isPost()) {
$form->handleRequest($this->getRequest());
if ($form->isValid()) {
if ($validCallback) {
$response = $validCallback($form->getData(), $form);
if($response instanceof Response)
return $response;
}
}
}
return $form->createView();
} | php | public function createAndSubmitForm($type, $data = null, callable $validCallback = null)
{
$form = $this->createForm($type, $data);
if ($this->isPost()) {
$form->handleRequest($this->getRequest());
if ($form->isValid()) {
if ($validCallback) {
$response = $validCallback($form->getData(), $form);
if($response instanceof Response)
return $response;
}
}
}
return $form->createView();
} | [
"public",
"function",
"createAndSubmitForm",
"(",
"$",
"type",
",",
"$",
"data",
"=",
"null",
",",
"callable",
"$",
"validCallback",
"=",
"null",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"$",
"type",
",",
"$",
"data",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isPost",
"(",
")",
")",
"{",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"this",
"->",
"getRequest",
"(",
")",
")",
";",
"if",
"(",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"if",
"(",
"$",
"validCallback",
")",
"{",
"$",
"response",
"=",
"$",
"validCallback",
"(",
"$",
"form",
"->",
"getData",
"(",
")",
",",
"$",
"form",
")",
";",
"if",
"(",
"$",
"response",
"instanceof",
"Response",
")",
"return",
"$",
"response",
";",
"}",
"}",
"}",
"return",
"$",
"form",
"->",
"createView",
"(",
")",
";",
"}"
] | Creates a submit a form, to use in controllers
@param $type
@param object|array $data
@param callable $validCallback Callback to call when form is valid
@return \Symfony\Component\Form\FormView | [
"Creates",
"a",
"submit",
"a",
"form",
"to",
"use",
"in",
"controllers"
] | 3cb769c62df7badaeae557306c8f738252adaa28 | https://github.com/trivialsense/php-framework-common/blob/3cb769c62df7badaeae557306c8f738252adaa28/src/TrivialSense/FrameworkCommon/Controller/AbstractController.php#L134-L153 |
2,406 | sebardo/ecommerce | EcommerceBundle/Controller/AgreementController.php | AgreementController.createCreateForm | private function createCreateForm(Agreement $entity)
{
$form = $this->createForm(new AgreementType(), $entity, array(
'action' => $this->generateUrl('agreement_create'),
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Create'));
return $form;
} | php | private function createCreateForm(Agreement $entity)
{
$form = $this->createForm(new AgreementType(), $entity, array(
'action' => $this->generateUrl('agreement_create'),
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Create'));
return $form;
} | [
"private",
"function",
"createCreateForm",
"(",
"Agreement",
"$",
"entity",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"AgreementType",
"(",
")",
",",
"$",
"entity",
",",
"array",
"(",
"'action'",
"=>",
"$",
"this",
"->",
"generateUrl",
"(",
"'agreement_create'",
")",
",",
"'method'",
"=>",
"'POST'",
",",
")",
")",
";",
"$",
"form",
"->",
"add",
"(",
"'submit'",
",",
"'submit'",
",",
"array",
"(",
"'label'",
"=>",
"'Create'",
")",
")",
";",
"return",
"$",
"form",
";",
"}"
] | Creates a form to create a Agreement entity.
@param Agreement $entity The entity
@return \Symfony\Component\Form\Form The form | [
"Creates",
"a",
"form",
"to",
"create",
"a",
"Agreement",
"entity",
"."
] | 3e17545e69993f10a1df17f9887810c7378fc7f9 | https://github.com/sebardo/ecommerce/blob/3e17545e69993f10a1df17f9887810c7378fc7f9/EcommerceBundle/Controller/AgreementController.php#L72-L82 |
2,407 | sebardo/ecommerce | EcommerceBundle/Controller/AgreementController.php | AgreementController.newAction | public function newAction()
{
$entity = new Agreement();
$form = $this->createCreateForm($entity);
return array(
'entity' => $entity,
'form' => $form->createView(),
);
} | php | public function newAction()
{
$entity = new Agreement();
$form = $this->createCreateForm($entity);
return array(
'entity' => $entity,
'form' => $form->createView(),
);
} | [
"public",
"function",
"newAction",
"(",
")",
"{",
"$",
"entity",
"=",
"new",
"Agreement",
"(",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"createCreateForm",
"(",
"$",
"entity",
")",
";",
"return",
"array",
"(",
"'entity'",
"=>",
"$",
"entity",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
")",
";",
"}"
] | Displays a form to create a new Agreement entity.
@Route("/new", name="agreement_new")
@Method("GET")
@Template() | [
"Displays",
"a",
"form",
"to",
"create",
"a",
"new",
"Agreement",
"entity",
"."
] | 3e17545e69993f10a1df17f9887810c7378fc7f9 | https://github.com/sebardo/ecommerce/blob/3e17545e69993f10a1df17f9887810c7378fc7f9/EcommerceBundle/Controller/AgreementController.php#L91-L100 |
2,408 | sebardo/ecommerce | EcommerceBundle/Controller/AgreementController.php | AgreementController.createEditForm | private function createEditForm(Agreement $entity)
{
$form = $this->createForm(new AgreementType(), $entity, array(
'action' => $this->generateUrl('agreement_update', array('id' => $entity->getId())),
'method' => 'PUT',
));
$form->add('submit', 'submit', array('label' => 'Update'));
return $form;
} | php | private function createEditForm(Agreement $entity)
{
$form = $this->createForm(new AgreementType(), $entity, array(
'action' => $this->generateUrl('agreement_update', array('id' => $entity->getId())),
'method' => 'PUT',
));
$form->add('submit', 'submit', array('label' => 'Update'));
return $form;
} | [
"private",
"function",
"createEditForm",
"(",
"Agreement",
"$",
"entity",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"AgreementType",
"(",
")",
",",
"$",
"entity",
",",
"array",
"(",
"'action'",
"=>",
"$",
"this",
"->",
"generateUrl",
"(",
"'agreement_update'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"entity",
"->",
"getId",
"(",
")",
")",
")",
",",
"'method'",
"=>",
"'PUT'",
",",
")",
")",
";",
"$",
"form",
"->",
"add",
"(",
"'submit'",
",",
"'submit'",
",",
"array",
"(",
"'label'",
"=>",
"'Update'",
")",
")",
";",
"return",
"$",
"form",
";",
"}"
] | Creates a form to edit a Agreement entity.
@param Agreement $entity The entity
@return \Symfony\Component\Form\Form The form | [
"Creates",
"a",
"form",
"to",
"edit",
"a",
"Agreement",
"entity",
"."
] | 3e17545e69993f10a1df17f9887810c7378fc7f9 | https://github.com/sebardo/ecommerce/blob/3e17545e69993f10a1df17f9887810c7378fc7f9/EcommerceBundle/Controller/AgreementController.php#L161-L171 |
2,409 | vinala/kernel | src/Validation/Validator.php | Validator.ini | public static function ini()
{
$lang = config('lang.default');
self::$langFolder = dirname(dirname(__DIR__)).'/app/lang/'.$lang;
self::$langFile = self::$langFolder.'/validator.php';
if (is_file(self::$langFile)) {
V::langDir(self::$langFolder);
V::lang('validator');
}
} | php | public static function ini()
{
$lang = config('lang.default');
self::$langFolder = dirname(dirname(__DIR__)).'/app/lang/'.$lang;
self::$langFile = self::$langFolder.'/validator.php';
if (is_file(self::$langFile)) {
V::langDir(self::$langFolder);
V::lang('validator');
}
} | [
"public",
"static",
"function",
"ini",
"(",
")",
"{",
"$",
"lang",
"=",
"config",
"(",
"'lang.default'",
")",
";",
"self",
"::",
"$",
"langFolder",
"=",
"dirname",
"(",
"dirname",
"(",
"__DIR__",
")",
")",
".",
"'/app/lang/'",
".",
"$",
"lang",
";",
"self",
"::",
"$",
"langFile",
"=",
"self",
"::",
"$",
"langFolder",
".",
"'/validator.php'",
";",
"if",
"(",
"is_file",
"(",
"self",
"::",
"$",
"langFile",
")",
")",
"{",
"V",
"::",
"langDir",
"(",
"self",
"::",
"$",
"langFolder",
")",
";",
"V",
"::",
"lang",
"(",
"'validator'",
")",
";",
"}",
"}"
] | Initiate validator.
@return null | [
"Initiate",
"validator",
"."
] | 346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a | https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/Validation/Validator.php#L46-L56 |
2,410 | vinala/kernel | src/Validation/Validator.php | Validator.make | public static function make(array $data, array $rules)
{
self::$validator = new V([]);
self::$validator->labels($data);
foreach ($rules as $rule => $columns) {
if (is_string($columns)) {
$columns = self::separte($columns);
} else {
$columns = $columns;
}
$value = self::getValue($rule);
self::$validator->rule($value['rule'], $columns, $value['value']);
}
return new ValidationResult(self::$validator);
} | php | public static function make(array $data, array $rules)
{
self::$validator = new V([]);
self::$validator->labels($data);
foreach ($rules as $rule => $columns) {
if (is_string($columns)) {
$columns = self::separte($columns);
} else {
$columns = $columns;
}
$value = self::getValue($rule);
self::$validator->rule($value['rule'], $columns, $value['value']);
}
return new ValidationResult(self::$validator);
} | [
"public",
"static",
"function",
"make",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"rules",
")",
"{",
"self",
"::",
"$",
"validator",
"=",
"new",
"V",
"(",
"[",
"]",
")",
";",
"self",
"::",
"$",
"validator",
"->",
"labels",
"(",
"$",
"data",
")",
";",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"rule",
"=>",
"$",
"columns",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"columns",
")",
")",
"{",
"$",
"columns",
"=",
"self",
"::",
"separte",
"(",
"$",
"columns",
")",
";",
"}",
"else",
"{",
"$",
"columns",
"=",
"$",
"columns",
";",
"}",
"$",
"value",
"=",
"self",
"::",
"getValue",
"(",
"$",
"rule",
")",
";",
"self",
"::",
"$",
"validator",
"->",
"rule",
"(",
"$",
"value",
"[",
"'rule'",
"]",
",",
"$",
"columns",
",",
"$",
"value",
"[",
"'value'",
"]",
")",
";",
"}",
"return",
"new",
"ValidationResult",
"(",
"self",
"::",
"$",
"validator",
")",
";",
"}"
] | Make new validation procces.
@param array $data
@param array $rules
@return Vinala\Kernel\Validation\Validator | [
"Make",
"new",
"validation",
"procces",
"."
] | 346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a | https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/Validation/Validator.php#L66-L84 |
2,411 | vinala/kernel | src/Validation/Validator.php | Validator.getValue | protected static function getValue($param)
{
$data = explode(':', $param);
$result = ['rule' => trim($data[0])];
$result['value'] = count($data) > 1 ? $data[1] : null;
return $result;
} | php | protected static function getValue($param)
{
$data = explode(':', $param);
$result = ['rule' => trim($data[0])];
$result['value'] = count($data) > 1 ? $data[1] : null;
return $result;
} | [
"protected",
"static",
"function",
"getValue",
"(",
"$",
"param",
")",
"{",
"$",
"data",
"=",
"explode",
"(",
"':'",
",",
"$",
"param",
")",
";",
"$",
"result",
"=",
"[",
"'rule'",
"=>",
"trim",
"(",
"$",
"data",
"[",
"0",
"]",
")",
"]",
";",
"$",
"result",
"[",
"'value'",
"]",
"=",
"count",
"(",
"$",
"data",
")",
">",
"1",
"?",
"$",
"data",
"[",
"1",
"]",
":",
"null",
";",
"return",
"$",
"result",
";",
"}"
] | Get value of the rule.
@param string $param
@return array | [
"Get",
"value",
"of",
"the",
"rule",
"."
] | 346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a | https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/Validation/Validator.php#L105-L114 |
2,412 | novuso/common | src/Domain/Value/Money/LocaleFormatter.php | LocaleFormatter.fromLocale | public static function fromLocale(string $locale): LocaleFormatter
{
$formatter = new NumberFormatter((string) $locale, NumberFormatter::CURRENCY);
return new self($formatter);
} | php | public static function fromLocale(string $locale): LocaleFormatter
{
$formatter = new NumberFormatter((string) $locale, NumberFormatter::CURRENCY);
return new self($formatter);
} | [
"public",
"static",
"function",
"fromLocale",
"(",
"string",
"$",
"locale",
")",
":",
"LocaleFormatter",
"{",
"$",
"formatter",
"=",
"new",
"NumberFormatter",
"(",
"(",
"string",
")",
"$",
"locale",
",",
"NumberFormatter",
"::",
"CURRENCY",
")",
";",
"return",
"new",
"self",
"(",
"$",
"formatter",
")",
";",
"}"
] | Creates instance from a locale string
@param string $locale The locale string
@return LocaleFormatter | [
"Creates",
"instance",
"from",
"a",
"locale",
"string"
] | 7d0e5a4f4c79c9622e068efc8b7c70815c460863 | https://github.com/novuso/common/blob/7d0e5a4f4c79c9622e068efc8b7c70815c460863/src/Domain/Value/Money/LocaleFormatter.php#L42-L47 |
2,413 | squire-assistant/config | Definition/Builder/ArrayNodeDefinition.php | ArrayNodeDefinition.validatePrototypeNode | protected function validatePrototypeNode(PrototypedArrayNode $node)
{
$path = $node->getPath();
if ($this->addDefaults) {
throw new InvalidDefinitionException(
sprintf('->addDefaultsIfNotSet() is not applicable to prototype nodes at path "%s"', $path)
);
}
if (false !== $this->addDefaultChildren) {
if ($this->default) {
throw new InvalidDefinitionException(
sprintf('A default value and default children might not be used together at path "%s"', $path)
);
}
if (null !== $this->key && (null === $this->addDefaultChildren || is_int($this->addDefaultChildren) && $this->addDefaultChildren > 0)) {
throw new InvalidDefinitionException(
sprintf('->addDefaultChildrenIfNoneSet() should set default children names as ->useAttributeAsKey() is used at path "%s"', $path)
);
}
if (null === $this->key && (is_string($this->addDefaultChildren) || is_array($this->addDefaultChildren))) {
throw new InvalidDefinitionException(
sprintf('->addDefaultChildrenIfNoneSet() might not set default children names as ->useAttributeAsKey() is not used at path "%s"', $path)
);
}
}
} | php | protected function validatePrototypeNode(PrototypedArrayNode $node)
{
$path = $node->getPath();
if ($this->addDefaults) {
throw new InvalidDefinitionException(
sprintf('->addDefaultsIfNotSet() is not applicable to prototype nodes at path "%s"', $path)
);
}
if (false !== $this->addDefaultChildren) {
if ($this->default) {
throw new InvalidDefinitionException(
sprintf('A default value and default children might not be used together at path "%s"', $path)
);
}
if (null !== $this->key && (null === $this->addDefaultChildren || is_int($this->addDefaultChildren) && $this->addDefaultChildren > 0)) {
throw new InvalidDefinitionException(
sprintf('->addDefaultChildrenIfNoneSet() should set default children names as ->useAttributeAsKey() is used at path "%s"', $path)
);
}
if (null === $this->key && (is_string($this->addDefaultChildren) || is_array($this->addDefaultChildren))) {
throw new InvalidDefinitionException(
sprintf('->addDefaultChildrenIfNoneSet() might not set default children names as ->useAttributeAsKey() is not used at path "%s"', $path)
);
}
}
} | [
"protected",
"function",
"validatePrototypeNode",
"(",
"PrototypedArrayNode",
"$",
"node",
")",
"{",
"$",
"path",
"=",
"$",
"node",
"->",
"getPath",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"addDefaults",
")",
"{",
"throw",
"new",
"InvalidDefinitionException",
"(",
"sprintf",
"(",
"'->addDefaultsIfNotSet() is not applicable to prototype nodes at path \"%s\"'",
",",
"$",
"path",
")",
")",
";",
"}",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"addDefaultChildren",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"default",
")",
"{",
"throw",
"new",
"InvalidDefinitionException",
"(",
"sprintf",
"(",
"'A default value and default children might not be used together at path \"%s\"'",
",",
"$",
"path",
")",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"key",
"&&",
"(",
"null",
"===",
"$",
"this",
"->",
"addDefaultChildren",
"||",
"is_int",
"(",
"$",
"this",
"->",
"addDefaultChildren",
")",
"&&",
"$",
"this",
"->",
"addDefaultChildren",
">",
"0",
")",
")",
"{",
"throw",
"new",
"InvalidDefinitionException",
"(",
"sprintf",
"(",
"'->addDefaultChildrenIfNoneSet() should set default children names as ->useAttributeAsKey() is used at path \"%s\"'",
",",
"$",
"path",
")",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"key",
"&&",
"(",
"is_string",
"(",
"$",
"this",
"->",
"addDefaultChildren",
")",
"||",
"is_array",
"(",
"$",
"this",
"->",
"addDefaultChildren",
")",
")",
")",
"{",
"throw",
"new",
"InvalidDefinitionException",
"(",
"sprintf",
"(",
"'->addDefaultChildrenIfNoneSet() might not set default children names as ->useAttributeAsKey() is not used at path \"%s\"'",
",",
"$",
"path",
")",
")",
";",
"}",
"}",
"}"
] | Validate the configuration of a prototype node.
@param PrototypedArrayNode $node The related node
@throws InvalidDefinitionException | [
"Validate",
"the",
"configuration",
"of",
"a",
"prototype",
"node",
"."
] | 474835b35fa34fbba4fe15a484299a526c082cc5 | https://github.com/squire-assistant/config/blob/474835b35fa34fbba4fe15a484299a526c082cc5/Definition/Builder/ArrayNodeDefinition.php#L519-L548 |
2,414 | WasabiLib/wasabilib | src/WasabiLib/View/Button.php | Button.setAction | public function setAction($action) {
$this->setVariable(self::ACTION, $this->assembleAssignmentString(self::DATA_HREF, $action));
$this->setEventType(self::CLICK_EVENT);
$this->addClass(self::AJAX_ELEMENT_CLASS);
if(!$this->getId()) {
$this->setId("button_".floor(rand(0, 1000)));
}
} | php | public function setAction($action) {
$this->setVariable(self::ACTION, $this->assembleAssignmentString(self::DATA_HREF, $action));
$this->setEventType(self::CLICK_EVENT);
$this->addClass(self::AJAX_ELEMENT_CLASS);
if(!$this->getId()) {
$this->setId("button_".floor(rand(0, 1000)));
}
} | [
"public",
"function",
"setAction",
"(",
"$",
"action",
")",
"{",
"$",
"this",
"->",
"setVariable",
"(",
"self",
"::",
"ACTION",
",",
"$",
"this",
"->",
"assembleAssignmentString",
"(",
"self",
"::",
"DATA_HREF",
",",
"$",
"action",
")",
")",
";",
"$",
"this",
"->",
"setEventType",
"(",
"self",
"::",
"CLICK_EVENT",
")",
";",
"$",
"this",
"->",
"addClass",
"(",
"self",
"::",
"AJAX_ELEMENT_CLASS",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"getId",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setId",
"(",
"\"button_\"",
".",
"floor",
"(",
"rand",
"(",
"0",
",",
"1000",
")",
")",
")",
";",
"}",
"}"
] | Sets the route to a controller action.
@param string $action | [
"Sets",
"the",
"route",
"to",
"a",
"controller",
"action",
"."
] | 5a55bfbea6b6ee10222c521112d469015db170b7 | https://github.com/WasabiLib/wasabilib/blob/5a55bfbea6b6ee10222c521112d469015db170b7/src/WasabiLib/View/Button.php#L54-L61 |
2,415 | WasabiLib/wasabilib | src/WasabiLib/View/Button.php | Button.setEventType | public function setEventType($eventType) {
$this->setVariable(self::EVENT_TYPE, $this->assembleAssignmentString(self::DATA_EVENT, $eventType));
} | php | public function setEventType($eventType) {
$this->setVariable(self::EVENT_TYPE, $this->assembleAssignmentString(self::DATA_EVENT, $eventType));
} | [
"public",
"function",
"setEventType",
"(",
"$",
"eventType",
")",
"{",
"$",
"this",
"->",
"setVariable",
"(",
"self",
"::",
"EVENT_TYPE",
",",
"$",
"this",
"->",
"assembleAssignmentString",
"(",
"self",
"::",
"DATA_EVENT",
",",
"$",
"eventType",
")",
")",
";",
"}"
] | Sets the event type of the button. Default is "click".
@param string $eventType | [
"Sets",
"the",
"event",
"type",
"of",
"the",
"button",
".",
"Default",
"is",
"click",
"."
] | 5a55bfbea6b6ee10222c521112d469015db170b7 | https://github.com/WasabiLib/wasabilib/blob/5a55bfbea6b6ee10222c521112d469015db170b7/src/WasabiLib/View/Button.php#L91-L93 |
2,416 | WasabiLib/wasabilib | src/WasabiLib/View/Button.php | Button.setParam | public function setParam($paramJsonString) {
$this->setVariable(self::PARAM, $this->assembleAssignmentString(self::DATA_JSON, $paramJsonString));
} | php | public function setParam($paramJsonString) {
$this->setVariable(self::PARAM, $this->assembleAssignmentString(self::DATA_JSON, $paramJsonString));
} | [
"public",
"function",
"setParam",
"(",
"$",
"paramJsonString",
")",
"{",
"$",
"this",
"->",
"setVariable",
"(",
"self",
"::",
"PARAM",
",",
"$",
"this",
"->",
"assembleAssignmentString",
"(",
"self",
"::",
"DATA_JSON",
",",
"$",
"paramJsonString",
")",
")",
";",
"}"
] | Sets an optional parameter which is send to the server if the by the event type specified event occurred.
@param string $paramJsonString | [
"Sets",
"an",
"optional",
"parameter",
"which",
"is",
"send",
"to",
"the",
"server",
"if",
"the",
"by",
"the",
"event",
"type",
"specified",
"event",
"occurred",
"."
] | 5a55bfbea6b6ee10222c521112d469015db170b7 | https://github.com/WasabiLib/wasabilib/blob/5a55bfbea6b6ee10222c521112d469015db170b7/src/WasabiLib/View/Button.php#L107-L109 |
2,417 | novuso/system | src/Collection/HashTable.php | HashTable.of | public static function of(?string $keyType = null, ?string $valueType = null): HashTable
{
return new static($keyType, $valueType);
} | php | public static function of(?string $keyType = null, ?string $valueType = null): HashTable
{
return new static($keyType, $valueType);
} | [
"public",
"static",
"function",
"of",
"(",
"?",
"string",
"$",
"keyType",
"=",
"null",
",",
"?",
"string",
"$",
"valueType",
"=",
"null",
")",
":",
"HashTable",
"{",
"return",
"new",
"static",
"(",
"$",
"keyType",
",",
"$",
"valueType",
")",
";",
"}"
] | Creates collection with specific key and value types
If types are not provided, the types are dynamic.
The type can be any fully-qualified class or interface name,
or one of the following type strings:
[array, object, bool, int, float, string, callable]
@param string|null $keyType The key type
@param string|null $valueType The value type
@return HashTable | [
"Creates",
"collection",
"with",
"specific",
"key",
"and",
"value",
"types"
] | e34038b391826edc68d0b5fccfba96642de9d6f0 | https://github.com/novuso/system/blob/e34038b391826edc68d0b5fccfba96642de9d6f0/src/Collection/HashTable.php#L74-L77 |
2,418 | mszewcz/php-light-framework | src/Validator/Chain.php | Chain.parseChain | private function parseChain($chain = []): void
{
if (!\is_array($chain)) {
throw new InvalidArgumentException('Validators chain must be an array');
}
foreach ($chain as $k => $v) {
if ($v instanceof AbstractSpecific) {
// value is an instance of AbstractSpecific
$reflection = new \ReflectionClass($v);
$name = \str_replace($reflection->getNamespaceName().'\\', '', $reflection->getName());
$this->chain[$name] = $v;
} elseif (\is_string($k) && \is_array($v)) {
// key is a string (validator name) and value is an array (validator options)
$className = '\\MS\\LightFramework\\Validator\\Specific\\'.$k;
if (!\class_exists($className)) {
throw new InvalidArgumentException('Validator "'.$k.'" not found');
}
$this->chain[$k] = new $className($v);
} elseif (\is_numeric($k) && \is_array($v)) {
// key is a numeric and value is an array (validator name => validator options)
$this->parseChain($v);
} else {
// incorrect chain format
$exMsg = 'Validator chain element must be either instance of AbstractValidator ';
$exMsg .= 'or array("validatorName" => array(options))';
throw new InvalidArgumentException($exMsg);
}
}
} | php | private function parseChain($chain = []): void
{
if (!\is_array($chain)) {
throw new InvalidArgumentException('Validators chain must be an array');
}
foreach ($chain as $k => $v) {
if ($v instanceof AbstractSpecific) {
// value is an instance of AbstractSpecific
$reflection = new \ReflectionClass($v);
$name = \str_replace($reflection->getNamespaceName().'\\', '', $reflection->getName());
$this->chain[$name] = $v;
} elseif (\is_string($k) && \is_array($v)) {
// key is a string (validator name) and value is an array (validator options)
$className = '\\MS\\LightFramework\\Validator\\Specific\\'.$k;
if (!\class_exists($className)) {
throw new InvalidArgumentException('Validator "'.$k.'" not found');
}
$this->chain[$k] = new $className($v);
} elseif (\is_numeric($k) && \is_array($v)) {
// key is a numeric and value is an array (validator name => validator options)
$this->parseChain($v);
} else {
// incorrect chain format
$exMsg = 'Validator chain element must be either instance of AbstractValidator ';
$exMsg .= 'or array("validatorName" => array(options))';
throw new InvalidArgumentException($exMsg);
}
}
} | [
"private",
"function",
"parseChain",
"(",
"$",
"chain",
"=",
"[",
"]",
")",
":",
"void",
"{",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"chain",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Validators chain must be an array'",
")",
";",
"}",
"foreach",
"(",
"$",
"chain",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"$",
"v",
"instanceof",
"AbstractSpecific",
")",
"{",
"// value is an instance of AbstractSpecific",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"v",
")",
";",
"$",
"name",
"=",
"\\",
"str_replace",
"(",
"$",
"reflection",
"->",
"getNamespaceName",
"(",
")",
".",
"'\\\\'",
",",
"''",
",",
"$",
"reflection",
"->",
"getName",
"(",
")",
")",
";",
"$",
"this",
"->",
"chain",
"[",
"$",
"name",
"]",
"=",
"$",
"v",
";",
"}",
"elseif",
"(",
"\\",
"is_string",
"(",
"$",
"k",
")",
"&&",
"\\",
"is_array",
"(",
"$",
"v",
")",
")",
"{",
"// key is a string (validator name) and value is an array (validator options)",
"$",
"className",
"=",
"'\\\\MS\\\\LightFramework\\\\Validator\\\\Specific\\\\'",
".",
"$",
"k",
";",
"if",
"(",
"!",
"\\",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Validator \"'",
".",
"$",
"k",
".",
"'\" not found'",
")",
";",
"}",
"$",
"this",
"->",
"chain",
"[",
"$",
"k",
"]",
"=",
"new",
"$",
"className",
"(",
"$",
"v",
")",
";",
"}",
"elseif",
"(",
"\\",
"is_numeric",
"(",
"$",
"k",
")",
"&&",
"\\",
"is_array",
"(",
"$",
"v",
")",
")",
"{",
"// key is a numeric and value is an array (validator name => validator options)",
"$",
"this",
"->",
"parseChain",
"(",
"$",
"v",
")",
";",
"}",
"else",
"{",
"// incorrect chain format",
"$",
"exMsg",
"=",
"'Validator chain element must be either instance of AbstractValidator '",
";",
"$",
"exMsg",
".=",
"'or array(\"validatorName\" => array(options))'",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"exMsg",
")",
";",
"}",
"}",
"}"
] | Parses chain array
@param array $chain | [
"Parses",
"chain",
"array"
] | 4d3b46781c387202c2dfbdb8760151b3ae8ef49c | https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Validator/Chain.php#L44-L72 |
2,419 | mszewcz/php-light-framework | src/Validator/Chain.php | Chain.remove | public function remove($validator = ''): Chain
{
if (!\is_string($validator)) {
throw new InvalidArgumentException('Validator name must be a string');
}
if (isset($this->chain[$validator])) {
unset($this->chain[$validator]);
}
return $this;
} | php | public function remove($validator = ''): Chain
{
if (!\is_string($validator)) {
throw new InvalidArgumentException('Validator name must be a string');
}
if (isset($this->chain[$validator])) {
unset($this->chain[$validator]);
}
return $this;
} | [
"public",
"function",
"remove",
"(",
"$",
"validator",
"=",
"''",
")",
":",
"Chain",
"{",
"if",
"(",
"!",
"\\",
"is_string",
"(",
"$",
"validator",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Validator name must be a string'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"chain",
"[",
"$",
"validator",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"chain",
"[",
"$",
"validator",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Removes validator from chain
@param string $validator
@return Chain | [
"Removes",
"validator",
"from",
"chain"
] | 4d3b46781c387202c2dfbdb8760151b3ae8ef49c | https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Validator/Chain.php#L92-L101 |
2,420 | mszewcz/php-light-framework | src/Validator/Chain.php | Chain.parseOptionValue | private function parseOptionValue($value = null)
{
if (\is_bool($value)) {
$value = $value === true ? 'true' : 'false';
} elseif (\is_null($value)) {
$value = 'null';
} elseif (\is_string($value)) {
$value = '\''.$value.'\'';
}
return $value;
} | php | private function parseOptionValue($value = null)
{
if (\is_bool($value)) {
$value = $value === true ? 'true' : 'false';
} elseif (\is_null($value)) {
$value = 'null';
} elseif (\is_string($value)) {
$value = '\''.$value.'\'';
}
return $value;
} | [
"private",
"function",
"parseOptionValue",
"(",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"\\",
"is_bool",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"===",
"true",
"?",
"'true'",
":",
"'false'",
";",
"}",
"elseif",
"(",
"\\",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"'null'",
";",
"}",
"elseif",
"(",
"\\",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"'\\''",
".",
"$",
"value",
".",
"'\\''",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Parses option value for getChain method
@param mixed $value
@return mixed | [
"Parses",
"option",
"value",
"for",
"getChain",
"method"
] | 4d3b46781c387202c2dfbdb8760151b3ae8ef49c | https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Validator/Chain.php#L118-L128 |
2,421 | mszewcz/php-light-framework | src/Validator/Chain.php | Chain.getChain | public function getChain(bool $includeOptions = true): string
{
$chain = [];
foreach ($this->chain as $validatorName => $validatorObj) {
if ($includeOptions === true) {
$options = [];
$tmpOptions = $validatorObj->getOptions();
foreach ($tmpOptions as $optionName => $optionVal) {
$options[] = \sprintf('\'%s\'=>%s', $optionName, $this->parseOptionValue($optionVal));
}
$chain[] = \sprintf('%s [%s]', $validatorName, \implode(', ', $options));
} else {
$chain[] = $validatorName;
}
}
return \implode(",\n", $chain);
} | php | public function getChain(bool $includeOptions = true): string
{
$chain = [];
foreach ($this->chain as $validatorName => $validatorObj) {
if ($includeOptions === true) {
$options = [];
$tmpOptions = $validatorObj->getOptions();
foreach ($tmpOptions as $optionName => $optionVal) {
$options[] = \sprintf('\'%s\'=>%s', $optionName, $this->parseOptionValue($optionVal));
}
$chain[] = \sprintf('%s [%s]', $validatorName, \implode(', ', $options));
} else {
$chain[] = $validatorName;
}
}
return \implode(",\n", $chain);
} | [
"public",
"function",
"getChain",
"(",
"bool",
"$",
"includeOptions",
"=",
"true",
")",
":",
"string",
"{",
"$",
"chain",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"chain",
"as",
"$",
"validatorName",
"=>",
"$",
"validatorObj",
")",
"{",
"if",
"(",
"$",
"includeOptions",
"===",
"true",
")",
"{",
"$",
"options",
"=",
"[",
"]",
";",
"$",
"tmpOptions",
"=",
"$",
"validatorObj",
"->",
"getOptions",
"(",
")",
";",
"foreach",
"(",
"$",
"tmpOptions",
"as",
"$",
"optionName",
"=>",
"$",
"optionVal",
")",
"{",
"$",
"options",
"[",
"]",
"=",
"\\",
"sprintf",
"(",
"'\\'%s\\'=>%s'",
",",
"$",
"optionName",
",",
"$",
"this",
"->",
"parseOptionValue",
"(",
"$",
"optionVal",
")",
")",
";",
"}",
"$",
"chain",
"[",
"]",
"=",
"\\",
"sprintf",
"(",
"'%s [%s]'",
",",
"$",
"validatorName",
",",
"\\",
"implode",
"(",
"', '",
",",
"$",
"options",
")",
")",
";",
"}",
"else",
"{",
"$",
"chain",
"[",
"]",
"=",
"$",
"validatorName",
";",
"}",
"}",
"return",
"\\",
"implode",
"(",
"\",\\n\"",
",",
"$",
"chain",
")",
";",
"}"
] | Returns validation chain
@param bool $includeOptions
@return string | [
"Returns",
"validation",
"chain"
] | 4d3b46781c387202c2dfbdb8760151b3ae8ef49c | https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Validator/Chain.php#L136-L152 |
2,422 | mtoolkit/mtoolkit-model | src/MFileSystemModel.php | MFileSystemModel.lastModified | public function lastModified($row, $column):?\DateTime
{
$file = $this->getData($row, $column);
if ($file == null) {
return null;
}
$file = rtrim($file, DIRECTORY_SEPARATOR);
$file = $this->rootPath . DIRECTORY_SEPARATOR . $file;
$format = "YmdHis";
$dateTime = \DateTime::createFromFormat($format, date($format, filemtime($file)));
return $dateTime;
} | php | public function lastModified($row, $column):?\DateTime
{
$file = $this->getData($row, $column);
if ($file == null) {
return null;
}
$file = rtrim($file, DIRECTORY_SEPARATOR);
$file = $this->rootPath . DIRECTORY_SEPARATOR . $file;
$format = "YmdHis";
$dateTime = \DateTime::createFromFormat($format, date($format, filemtime($file)));
return $dateTime;
} | [
"public",
"function",
"lastModified",
"(",
"$",
"row",
",",
"$",
"column",
")",
":",
"?",
"\\",
"DateTime",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"getData",
"(",
"$",
"row",
",",
"$",
"column",
")",
";",
"if",
"(",
"$",
"file",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"$",
"file",
"=",
"rtrim",
"(",
"$",
"file",
",",
"DIRECTORY_SEPARATOR",
")",
";",
"$",
"file",
"=",
"$",
"this",
"->",
"rootPath",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
";",
"$",
"format",
"=",
"\"YmdHis\"",
";",
"$",
"dateTime",
"=",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"$",
"format",
",",
"date",
"(",
"$",
"format",
",",
"filemtime",
"(",
"$",
"file",
")",
")",
")",
";",
"return",
"$",
"dateTime",
";",
"}"
] | Returns the date and time when index was last modified.
@param int $row
@param int $column
@return null|\DateTime | [
"Returns",
"the",
"date",
"and",
"time",
"when",
"index",
"was",
"last",
"modified",
"."
] | 7836bc1d32b30c14273c7636dc7388ecd347953d | https://github.com/mtoolkit/mtoolkit-model/blob/7836bc1d32b30c14273c7636dc7388ecd347953d/src/MFileSystemModel.php#L112-L128 |
2,423 | agalbourdin/agl-core | src/Config/Config.php | Config._getInstance | private function _getInstance($pFileStr)
{
$filePath = $this->_configPath;
$file = $filePath . str_replace('-', DS, $pFileStr) . self::EXT;
if ($this->_envPrefix) {
$file = preg_replace('/([a-z0-9]+\.)/i', $this->_envPrefix . '$1', $file);
}
if (! isset($this->_instance[$file])) {
if (is_readable($file)) {
$this->_instance[$file] = require($file);
} else if ($this->_envPrefix
and $file = $filePath . str_replace('-', DS, $pFileStr) . self::EXT
and is_readable($file)) {
$this->_instance[$file] = require($file);
} else {
$this->_instance[$file] = array();
}
}
return $this->_instance[$file];
} | php | private function _getInstance($pFileStr)
{
$filePath = $this->_configPath;
$file = $filePath . str_replace('-', DS, $pFileStr) . self::EXT;
if ($this->_envPrefix) {
$file = preg_replace('/([a-z0-9]+\.)/i', $this->_envPrefix . '$1', $file);
}
if (! isset($this->_instance[$file])) {
if (is_readable($file)) {
$this->_instance[$file] = require($file);
} else if ($this->_envPrefix
and $file = $filePath . str_replace('-', DS, $pFileStr) . self::EXT
and is_readable($file)) {
$this->_instance[$file] = require($file);
} else {
$this->_instance[$file] = array();
}
}
return $this->_instance[$file];
} | [
"private",
"function",
"_getInstance",
"(",
"$",
"pFileStr",
")",
"{",
"$",
"filePath",
"=",
"$",
"this",
"->",
"_configPath",
";",
"$",
"file",
"=",
"$",
"filePath",
".",
"str_replace",
"(",
"'-'",
",",
"DS",
",",
"$",
"pFileStr",
")",
".",
"self",
"::",
"EXT",
";",
"if",
"(",
"$",
"this",
"->",
"_envPrefix",
")",
"{",
"$",
"file",
"=",
"preg_replace",
"(",
"'/([a-z0-9]+\\.)/i'",
",",
"$",
"this",
"->",
"_envPrefix",
".",
"'$1'",
",",
"$",
"file",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_instance",
"[",
"$",
"file",
"]",
")",
")",
"{",
"if",
"(",
"is_readable",
"(",
"$",
"file",
")",
")",
"{",
"$",
"this",
"->",
"_instance",
"[",
"$",
"file",
"]",
"=",
"require",
"(",
"$",
"file",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"_envPrefix",
"and",
"$",
"file",
"=",
"$",
"filePath",
".",
"str_replace",
"(",
"'-'",
",",
"DS",
",",
"$",
"pFileStr",
")",
".",
"self",
"::",
"EXT",
"and",
"is_readable",
"(",
"$",
"file",
")",
")",
"{",
"$",
"this",
"->",
"_instance",
"[",
"$",
"file",
"]",
"=",
"require",
"(",
"$",
"file",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_instance",
"[",
"$",
"file",
"]",
"=",
"array",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"_instance",
"[",
"$",
"file",
"]",
";",
"}"
] | Load configuration file content if not already loaded.
@param string $pFileStr File path to resolve
@return array Configuration file content | [
"Load",
"configuration",
"file",
"content",
"if",
"not",
"already",
"loaded",
"."
] | 1db556f9a49488aa9fab6887fefb7141a79ad97d | https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Config/Config.php#L114-L136 |
2,424 | agalbourdin/agl-core | src/Config/Config.php | Config._getEventsConfig | private function _getEventsConfig()
{
$content = array(self:: MAIN_EVENTS_FILE => array());
$configPath = $this->_configPath;
if (! is_dir($configPath)) {
return $content;
}
$files = DirData::listFilesRecursive($configPath, self:: MAIN_EVENTS_FILE . self::EXT);
foreach ($files as $file) {
$content[self:: MAIN_EVENTS_FILE] = array_merge_recursive(require($file), $content[self:: MAIN_EVENTS_FILE]);
}
return $content;
} | php | private function _getEventsConfig()
{
$content = array(self:: MAIN_EVENTS_FILE => array());
$configPath = $this->_configPath;
if (! is_dir($configPath)) {
return $content;
}
$files = DirData::listFilesRecursive($configPath, self:: MAIN_EVENTS_FILE . self::EXT);
foreach ($files as $file) {
$content[self:: MAIN_EVENTS_FILE] = array_merge_recursive(require($file), $content[self:: MAIN_EVENTS_FILE]);
}
return $content;
} | [
"private",
"function",
"_getEventsConfig",
"(",
")",
"{",
"$",
"content",
"=",
"array",
"(",
"self",
"::",
"MAIN_EVENTS_FILE",
"=>",
"array",
"(",
")",
")",
";",
"$",
"configPath",
"=",
"$",
"this",
"->",
"_configPath",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"configPath",
")",
")",
"{",
"return",
"$",
"content",
";",
"}",
"$",
"files",
"=",
"DirData",
"::",
"listFilesRecursive",
"(",
"$",
"configPath",
",",
"self",
"::",
"MAIN_EVENTS_FILE",
".",
"self",
"::",
"EXT",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"content",
"[",
"self",
"::",
"MAIN_EVENTS_FILE",
"]",
"=",
"array_merge_recursive",
"(",
"require",
"(",
"$",
"file",
")",
",",
"$",
"content",
"[",
"self",
"::",
"MAIN_EVENTS_FILE",
"]",
")",
";",
"}",
"return",
"$",
"content",
";",
"}"
] | Search all events config files and get config value.
@return array | [
"Search",
"all",
"events",
"config",
"files",
"and",
"get",
"config",
"value",
"."
] | 1db556f9a49488aa9fab6887fefb7141a79ad97d | https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Config/Config.php#L143-L158 |
2,425 | agalbourdin/agl-core | src/Config/Config.php | Config._getConfigValues | private function _getConfigValues($pPath, $pForceGlobalArray)
{
$pathArr = explode(DS, $pPath, 2);
if (! isset($pathArr[1])) {
return NULL;
}
$path = rtrim($pathArr[1], '/');
if ($pPath === self::CONFIG_EVENTS_PATH) {
$content = $this->_getEventsConfig();
} else {
$content = $this->_getInstance($pathArr[0]);
}
if ($path) {
$pathArr = explode('/', $path);
$nbKeys = count($pathArr) - 1;
foreach($pathArr as $i => $key) {
$key = str_replace('#', '/', $key);
if (! isset($content[$key])) {
$this->_cache[$pPath] = NULL;
break;
} else if ($i < $nbKeys) {
$content = $content[$key];
} else if ($i == $nbKeys) {
$this->_cache[$pPath] = $content[$key];
}
}
} else {
$this->_cache[$pPath] = $content;
}
if ($pForceGlobalArray and (! is_array($this->_cache[$pPath]) or (is_array($this->_cache[$pPath]) and ! array_key_exists(0, $this->_cache[$pPath])))) {
$this->_cache[$pPath] = array($this->_cache[$pPath]);
}
return $this->_cache[$pPath];
} | php | private function _getConfigValues($pPath, $pForceGlobalArray)
{
$pathArr = explode(DS, $pPath, 2);
if (! isset($pathArr[1])) {
return NULL;
}
$path = rtrim($pathArr[1], '/');
if ($pPath === self::CONFIG_EVENTS_PATH) {
$content = $this->_getEventsConfig();
} else {
$content = $this->_getInstance($pathArr[0]);
}
if ($path) {
$pathArr = explode('/', $path);
$nbKeys = count($pathArr) - 1;
foreach($pathArr as $i => $key) {
$key = str_replace('#', '/', $key);
if (! isset($content[$key])) {
$this->_cache[$pPath] = NULL;
break;
} else if ($i < $nbKeys) {
$content = $content[$key];
} else if ($i == $nbKeys) {
$this->_cache[$pPath] = $content[$key];
}
}
} else {
$this->_cache[$pPath] = $content;
}
if ($pForceGlobalArray and (! is_array($this->_cache[$pPath]) or (is_array($this->_cache[$pPath]) and ! array_key_exists(0, $this->_cache[$pPath])))) {
$this->_cache[$pPath] = array($this->_cache[$pPath]);
}
return $this->_cache[$pPath];
} | [
"private",
"function",
"_getConfigValues",
"(",
"$",
"pPath",
",",
"$",
"pForceGlobalArray",
")",
"{",
"$",
"pathArr",
"=",
"explode",
"(",
"DS",
",",
"$",
"pPath",
",",
"2",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"pathArr",
"[",
"1",
"]",
")",
")",
"{",
"return",
"NULL",
";",
"}",
"$",
"path",
"=",
"rtrim",
"(",
"$",
"pathArr",
"[",
"1",
"]",
",",
"'/'",
")",
";",
"if",
"(",
"$",
"pPath",
"===",
"self",
"::",
"CONFIG_EVENTS_PATH",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"_getEventsConfig",
"(",
")",
";",
"}",
"else",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"_getInstance",
"(",
"$",
"pathArr",
"[",
"0",
"]",
")",
";",
"}",
"if",
"(",
"$",
"path",
")",
"{",
"$",
"pathArr",
"=",
"explode",
"(",
"'/'",
",",
"$",
"path",
")",
";",
"$",
"nbKeys",
"=",
"count",
"(",
"$",
"pathArr",
")",
"-",
"1",
";",
"foreach",
"(",
"$",
"pathArr",
"as",
"$",
"i",
"=>",
"$",
"key",
")",
"{",
"$",
"key",
"=",
"str_replace",
"(",
"'#'",
",",
"'/'",
",",
"$",
"key",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"content",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_cache",
"[",
"$",
"pPath",
"]",
"=",
"NULL",
";",
"break",
";",
"}",
"else",
"if",
"(",
"$",
"i",
"<",
"$",
"nbKeys",
")",
"{",
"$",
"content",
"=",
"$",
"content",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"if",
"(",
"$",
"i",
"==",
"$",
"nbKeys",
")",
"{",
"$",
"this",
"->",
"_cache",
"[",
"$",
"pPath",
"]",
"=",
"$",
"content",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"_cache",
"[",
"$",
"pPath",
"]",
"=",
"$",
"content",
";",
"}",
"if",
"(",
"$",
"pForceGlobalArray",
"and",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"_cache",
"[",
"$",
"pPath",
"]",
")",
"or",
"(",
"is_array",
"(",
"$",
"this",
"->",
"_cache",
"[",
"$",
"pPath",
"]",
")",
"and",
"!",
"array_key_exists",
"(",
"0",
",",
"$",
"this",
"->",
"_cache",
"[",
"$",
"pPath",
"]",
")",
")",
")",
")",
"{",
"$",
"this",
"->",
"_cache",
"[",
"$",
"pPath",
"]",
"=",
"array",
"(",
"$",
"this",
"->",
"_cache",
"[",
"$",
"pPath",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_cache",
"[",
"$",
"pPath",
"]",
";",
"}"
] | Return NULL, the config value or an array of values corresponding to the
requested path.
@param string $pPath Requested path
@param bool $pForceGlobalArray Return the results in a miltidimensional
array
@return mixed | [
"Return",
"NULL",
"the",
"config",
"value",
"or",
"an",
"array",
"of",
"values",
"corresponding",
"to",
"the",
"requested",
"path",
"."
] | 1db556f9a49488aa9fab6887fefb7141a79ad97d | https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Config/Config.php#L169-L209 |
2,426 | agalbourdin/agl-core | src/Config/Config.php | Config.getConfig | public function getConfig($pPath, $pForceGlobalArray = false)
{
if (array_key_exists($pPath, $this->_cache)) {
return $this->_cache[$pPath];
}
if ($this->_cacheEnabled and $pPath != static::CONFIG_CACHE_TYPE_KEY) {
if ($this->_cacheInstance === NULL) {
$this->_cacheInstance = Agl::getCache();
}
if ($this->_cacheInstance->has('config.' . $pPath)) {
$this->_cache[$pPath] = $this->_cacheInstance->get('config.' . $pPath);
return $this->_cache[$pPath];
}
}
$this->_cache[$pPath] = $this->_getConfigValues($pPath, $pForceGlobalArray);
if ($this->_cacheInstance !== NULL) {
$this->_cacheInstance->set('config.' . $pPath, $this->_cache[$pPath]);
}
return $this->_cache[$pPath];
} | php | public function getConfig($pPath, $pForceGlobalArray = false)
{
if (array_key_exists($pPath, $this->_cache)) {
return $this->_cache[$pPath];
}
if ($this->_cacheEnabled and $pPath != static::CONFIG_CACHE_TYPE_KEY) {
if ($this->_cacheInstance === NULL) {
$this->_cacheInstance = Agl::getCache();
}
if ($this->_cacheInstance->has('config.' . $pPath)) {
$this->_cache[$pPath] = $this->_cacheInstance->get('config.' . $pPath);
return $this->_cache[$pPath];
}
}
$this->_cache[$pPath] = $this->_getConfigValues($pPath, $pForceGlobalArray);
if ($this->_cacheInstance !== NULL) {
$this->_cacheInstance->set('config.' . $pPath, $this->_cache[$pPath]);
}
return $this->_cache[$pPath];
} | [
"public",
"function",
"getConfig",
"(",
"$",
"pPath",
",",
"$",
"pForceGlobalArray",
"=",
"false",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"pPath",
",",
"$",
"this",
"->",
"_cache",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_cache",
"[",
"$",
"pPath",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_cacheEnabled",
"and",
"$",
"pPath",
"!=",
"static",
"::",
"CONFIG_CACHE_TYPE_KEY",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_cacheInstance",
"===",
"NULL",
")",
"{",
"$",
"this",
"->",
"_cacheInstance",
"=",
"Agl",
"::",
"getCache",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_cacheInstance",
"->",
"has",
"(",
"'config.'",
".",
"$",
"pPath",
")",
")",
"{",
"$",
"this",
"->",
"_cache",
"[",
"$",
"pPath",
"]",
"=",
"$",
"this",
"->",
"_cacheInstance",
"->",
"get",
"(",
"'config.'",
".",
"$",
"pPath",
")",
";",
"return",
"$",
"this",
"->",
"_cache",
"[",
"$",
"pPath",
"]",
";",
"}",
"}",
"$",
"this",
"->",
"_cache",
"[",
"$",
"pPath",
"]",
"=",
"$",
"this",
"->",
"_getConfigValues",
"(",
"$",
"pPath",
",",
"$",
"pForceGlobalArray",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_cacheInstance",
"!==",
"NULL",
")",
"{",
"$",
"this",
"->",
"_cacheInstance",
"->",
"set",
"(",
"'config.'",
".",
"$",
"pPath",
",",
"$",
"this",
"->",
"_cache",
"[",
"$",
"pPath",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_cache",
"[",
"$",
"pPath",
"]",
";",
"}"
] | Retrieve a value in the configuration files.
@param string $pPath The configuration path to retrieve
@param array $pForceGlobalArray Return the results in a multidimensional
array
@return mixed The configuration value corresponding to the path | [
"Retrieve",
"a",
"value",
"in",
"the",
"configuration",
"files",
"."
] | 1db556f9a49488aa9fab6887fefb7141a79ad97d | https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Config/Config.php#L219-L243 |
2,427 | vox-tecnologia/functions | src/Functions/ExtendedOperations/ValidityFunctions.php | ValidityFunctions.seoFriendlyUrl | public function seoFriendlyUrl(string $str): string
{
/* Make alphanumeric and lowercase (removes all other characters) */
$str = preg_replace('/[^a-z0-9_\s-]/', '', strtolower($str));
/* Clean up multiple dashes or whitespaces */
$str = preg_replace('/[\s-]+/', ' ', $str);
/* Convert whitespaces and underscore to dash */
$str = preg_replace('/[\s_]/', '-', $str);
return $str;
} | php | public function seoFriendlyUrl(string $str): string
{
/* Make alphanumeric and lowercase (removes all other characters) */
$str = preg_replace('/[^a-z0-9_\s-]/', '', strtolower($str));
/* Clean up multiple dashes or whitespaces */
$str = preg_replace('/[\s-]+/', ' ', $str);
/* Convert whitespaces and underscore to dash */
$str = preg_replace('/[\s_]/', '-', $str);
return $str;
} | [
"public",
"function",
"seoFriendlyUrl",
"(",
"string",
"$",
"str",
")",
":",
"string",
"{",
"/* Make alphanumeric and lowercase (removes all other characters) */",
"$",
"str",
"=",
"preg_replace",
"(",
"'/[^a-z0-9_\\s-]/'",
",",
"''",
",",
"strtolower",
"(",
"$",
"str",
")",
")",
";",
"/* Clean up multiple dashes or whitespaces */",
"$",
"str",
"=",
"preg_replace",
"(",
"'/[\\s-]+/'",
",",
"' '",
",",
"$",
"str",
")",
";",
"/* Convert whitespaces and underscore to dash */",
"$",
"str",
"=",
"preg_replace",
"(",
"'/[\\s_]/'",
",",
"'-'",
",",
"$",
"str",
")",
";",
"return",
"$",
"str",
";",
"}"
] | Check for SEO Friendly Url.
@param string $str The string as SEO URL
@return string | [
"Check",
"for",
"SEO",
"Friendly",
"Url",
"."
] | 1da249ac87f9d7c46d1c714d65443cda9face807 | https://github.com/vox-tecnologia/functions/blob/1da249ac87f9d7c46d1c714d65443cda9face807/src/Functions/ExtendedOperations/ValidityFunctions.php#L150-L162 |
2,428 | vox-tecnologia/functions | src/Functions/ExtendedOperations/ValidityFunctions.php | ValidityFunctions.isValidIP4 | public function isValidIP4(string $ipAddress): bool
{
return (bool) filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_RES_RANGE);
} | php | public function isValidIP4(string $ipAddress): bool
{
return (bool) filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_RES_RANGE);
} | [
"public",
"function",
"isValidIP4",
"(",
"string",
"$",
"ipAddress",
")",
":",
"bool",
"{",
"return",
"(",
"bool",
")",
"filter_var",
"(",
"$",
"ipAddress",
",",
"FILTER_VALIDATE_IP",
",",
"FILTER_FLAG_IPV4",
"|",
"FILTER_FLAG_NO_RES_RANGE",
")",
";",
"}"
] | Basic IP4 validation, private and reserved ranges.
@param string $ipAddress The IP Address
@return bool | [
"Basic",
"IP4",
"validation",
"private",
"and",
"reserved",
"ranges",
"."
] | 1da249ac87f9d7c46d1c714d65443cda9face807 | https://github.com/vox-tecnologia/functions/blob/1da249ac87f9d7c46d1c714d65443cda9face807/src/Functions/ExtendedOperations/ValidityFunctions.php#L235-L238 |
2,429 | vox-tecnologia/functions | src/Functions/ExtendedOperations/ValidityFunctions.php | ValidityFunctions.isValidStringLength | public function isValidStringLength($str, $min = null, $max = null): bool
{
$len = mb_strlen($str, 'UTF-8');
return (($min !== null) && ($len >= $min)) || (($max !== null) && ($len <= $max));
} | php | public function isValidStringLength($str, $min = null, $max = null): bool
{
$len = mb_strlen($str, 'UTF-8');
return (($min !== null) && ($len >= $min)) || (($max !== null) && ($len <= $max));
} | [
"public",
"function",
"isValidStringLength",
"(",
"$",
"str",
",",
"$",
"min",
"=",
"null",
",",
"$",
"max",
"=",
"null",
")",
":",
"bool",
"{",
"$",
"len",
"=",
"mb_strlen",
"(",
"$",
"str",
",",
"'UTF-8'",
")",
";",
"return",
"(",
"(",
"$",
"min",
"!==",
"null",
")",
"&&",
"(",
"$",
"len",
">=",
"$",
"min",
")",
")",
"||",
"(",
"(",
"$",
"max",
"!==",
"null",
")",
"&&",
"(",
"$",
"len",
"<=",
"$",
"max",
")",
")",
";",
"}"
] | Checking string length, max and minimum.
@param string $str The string to check
@param int $min The minimum string size
@param int $max The maximum string size
@return bool
@api | [
"Checking",
"string",
"length",
"max",
"and",
"minimum",
"."
] | 1da249ac87f9d7c46d1c714d65443cda9face807 | https://github.com/vox-tecnologia/functions/blob/1da249ac87f9d7c46d1c714d65443cda9face807/src/Functions/ExtendedOperations/ValidityFunctions.php#L253-L258 |
2,430 | vox-tecnologia/functions | src/Functions/ExtendedOperations/ValidityFunctions.php | ValidityFunctions.isValidIP4NoPrivate | public function isValidIP4NoPrivate(string $ipAddress): bool
{
return (bool) filter_var(
$ipAddress,
FILTER_VALIDATE_IP,
FILTER_FLAG_IPV4
| FILTER_FLAG_NO_PRIV_RANGE
| FILTER_FLAG_NO_RES_RANGE
);
} | php | public function isValidIP4NoPrivate(string $ipAddress): bool
{
return (bool) filter_var(
$ipAddress,
FILTER_VALIDATE_IP,
FILTER_FLAG_IPV4
| FILTER_FLAG_NO_PRIV_RANGE
| FILTER_FLAG_NO_RES_RANGE
);
} | [
"public",
"function",
"isValidIP4NoPrivate",
"(",
"string",
"$",
"ipAddress",
")",
":",
"bool",
"{",
"return",
"(",
"bool",
")",
"filter_var",
"(",
"$",
"ipAddress",
",",
"FILTER_VALIDATE_IP",
",",
"FILTER_FLAG_IPV4",
"|",
"FILTER_FLAG_NO_PRIV_RANGE",
"|",
"FILTER_FLAG_NO_RES_RANGE",
")",
";",
"}"
] | Basic IP4 validation; exclude private range.
@param string $ipAddress The IP Address
@return bool | [
"Basic",
"IP4",
"validation",
";",
"exclude",
"private",
"range",
"."
] | 1da249ac87f9d7c46d1c714d65443cda9face807 | https://github.com/vox-tecnologia/functions/blob/1da249ac87f9d7c46d1c714d65443cda9face807/src/Functions/ExtendedOperations/ValidityFunctions.php#L442-L451 |
2,431 | vox-tecnologia/functions | src/Functions/ExtendedOperations/ValidityFunctions.php | ValidityFunctions.isValidIP6NoPrivate | public function isValidIP6NoPrivate(string $ipAddress): bool
{
return (bool) filter_var(
$ipAddress,
FILTER_VALIDATE_IP,
FILTER_FLAG_IPV6
| FILTER_FLAG_NO_PRIV_RANGE
| FILTER_FLAG_NO_RES_RANGE
);
} | php | public function isValidIP6NoPrivate(string $ipAddress): bool
{
return (bool) filter_var(
$ipAddress,
FILTER_VALIDATE_IP,
FILTER_FLAG_IPV6
| FILTER_FLAG_NO_PRIV_RANGE
| FILTER_FLAG_NO_RES_RANGE
);
} | [
"public",
"function",
"isValidIP6NoPrivate",
"(",
"string",
"$",
"ipAddress",
")",
":",
"bool",
"{",
"return",
"(",
"bool",
")",
"filter_var",
"(",
"$",
"ipAddress",
",",
"FILTER_VALIDATE_IP",
",",
"FILTER_FLAG_IPV6",
"|",
"FILTER_FLAG_NO_PRIV_RANGE",
"|",
"FILTER_FLAG_NO_RES_RANGE",
")",
";",
"}"
] | Basic IP6 validation, private and reserved ranges.
@param string $ipAddress The IP Address
@return bool | [
"Basic",
"IP6",
"validation",
"private",
"and",
"reserved",
"ranges",
"."
] | 1da249ac87f9d7c46d1c714d65443cda9face807 | https://github.com/vox-tecnologia/functions/blob/1da249ac87f9d7c46d1c714d65443cda9face807/src/Functions/ExtendedOperations/ValidityFunctions.php#L462-L471 |
2,432 | vox-tecnologia/functions | src/Functions/ExtendedOperations/ValidityFunctions.php | ValidityFunctions.isPostalState | public function isPostalState(string $value): bool
{
return (bool) (in_array(strtoupper(trim($value)), array_keys($this->postalStates)) !== false);
} | php | public function isPostalState(string $value): bool
{
return (bool) (in_array(strtoupper(trim($value)), array_keys($this->postalStates)) !== false);
} | [
"public",
"function",
"isPostalState",
"(",
"string",
"$",
"value",
")",
":",
"bool",
"{",
"return",
"(",
"bool",
")",
"(",
"in_array",
"(",
"strtoupper",
"(",
"trim",
"(",
"$",
"value",
")",
")",
",",
"array_keys",
"(",
"$",
"this",
"->",
"postalStates",
")",
")",
"!==",
"false",
")",
";",
"}"
] | Validation Postal State Address.
@param string $value The state abbreviation whitelist (e.g., CA, AZ, TX)
@return bool | [
"Validation",
"Postal",
"State",
"Address",
"."
] | 1da249ac87f9d7c46d1c714d65443cda9face807 | https://github.com/vox-tecnologia/functions/blob/1da249ac87f9d7c46d1c714d65443cda9face807/src/Functions/ExtendedOperations/ValidityFunctions.php#L513-L516 |
2,433 | vox-tecnologia/functions | src/Functions/ExtendedOperations/ValidityFunctions.php | ValidityFunctions.isValidDate | public function isValidDate($datetime, string $format = 'Y-m-d H:i:s'): bool
{
$dateType = DateTime::createFromFormat($format, $datetime);
return (bool) ($dateType && $dateType->format($format) === $datetime);
} | php | public function isValidDate($datetime, string $format = 'Y-m-d H:i:s'): bool
{
$dateType = DateTime::createFromFormat($format, $datetime);
return (bool) ($dateType && $dateType->format($format) === $datetime);
} | [
"public",
"function",
"isValidDate",
"(",
"$",
"datetime",
",",
"string",
"$",
"format",
"=",
"'Y-m-d H:i:s'",
")",
":",
"bool",
"{",
"$",
"dateType",
"=",
"DateTime",
"::",
"createFromFormat",
"(",
"$",
"format",
",",
"$",
"datetime",
")",
";",
"return",
"(",
"bool",
")",
"(",
"$",
"dateType",
"&&",
"$",
"dateType",
"->",
"format",
"(",
"$",
"format",
")",
"===",
"$",
"datetime",
")",
";",
"}"
] | Check the format and the validity of a date.
@param string $datetime The date or timestamp
@param string $format The format
@return bool
@api | [
"Check",
"the",
"format",
"and",
"the",
"validity",
"of",
"a",
"date",
"."
] | 1da249ac87f9d7c46d1c714d65443cda9face807 | https://github.com/vox-tecnologia/functions/blob/1da249ac87f9d7c46d1c714d65443cda9face807/src/Functions/ExtendedOperations/ValidityFunctions.php#L530-L534 |
2,434 | vox-tecnologia/functions | src/Functions/ExtendedOperations/ValidityFunctions.php | ValidityFunctions.createHashFileName | public function createHashFileName(string $filename, string $extension = '.php'): string
{
return sprintf('%s%s', hash('sha256', $filename, false), $extension);
} | php | public function createHashFileName(string $filename, string $extension = '.php'): string
{
return sprintf('%s%s', hash('sha256', $filename, false), $extension);
} | [
"public",
"function",
"createHashFileName",
"(",
"string",
"$",
"filename",
",",
"string",
"$",
"extension",
"=",
"'.php'",
")",
":",
"string",
"{",
"return",
"sprintf",
"(",
"'%s%s'",
",",
"hash",
"(",
"'sha256'",
",",
"$",
"filename",
",",
"false",
")",
",",
"$",
"extension",
")",
";",
"}"
] | Generate a hash file name.
@param string $filename The file name or key
@param string $extension The file extension
@return string The hash filename
@api | [
"Generate",
"a",
"hash",
"file",
"name",
"."
] | 1da249ac87f9d7c46d1c714d65443cda9face807 | https://github.com/vox-tecnologia/functions/blob/1da249ac87f9d7c46d1c714d65443cda9face807/src/Functions/ExtendedOperations/ValidityFunctions.php#L548-L551 |
2,435 | joffreydemetz/utilities | src/DataObject.php | DataObject.sets | public function sets(array $properties)
{
foreach($properties as $k => $v){
$this->set($k, $v);
}
return $this;
} | php | public function sets(array $properties)
{
foreach($properties as $k => $v){
$this->set($k, $v);
}
return $this;
} | [
"public",
"function",
"sets",
"(",
"array",
"$",
"properties",
")",
"{",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"$",
"k",
",",
"$",
"v",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set some object properties
@param array $properties Key / Value pairs
@return $this | [
"Set",
"some",
"object",
"properties"
] | aa62a178bc463c10067a2ff2992d39c6f0037b9f | https://github.com/joffreydemetz/utilities/blob/aa62a178bc463c10067a2ff2992d39c6f0037b9f/src/DataObject.php#L55-L61 |
2,436 | joffreydemetz/utilities | src/DataObject.php | DataObject.getErrorsAsString | public function getErrorsAsString(string $separator='<br />'): string
{
$errors = $this->errors;
foreach($errors as &$error){
$error = $error->getMessage();
}
return implode($separator, $errors);
} | php | public function getErrorsAsString(string $separator='<br />'): string
{
$errors = $this->errors;
foreach($errors as &$error){
$error = $error->getMessage();
}
return implode($separator, $errors);
} | [
"public",
"function",
"getErrorsAsString",
"(",
"string",
"$",
"separator",
"=",
"'<br />'",
")",
":",
"string",
"{",
"$",
"errors",
"=",
"$",
"this",
"->",
"errors",
";",
"foreach",
"(",
"$",
"errors",
"as",
"&",
"$",
"error",
")",
"{",
"$",
"error",
"=",
"$",
"error",
"->",
"getMessage",
"(",
")",
";",
"}",
"return",
"implode",
"(",
"$",
"separator",
",",
"$",
"errors",
")",
";",
"}"
] | Return all errors, if any, as a unique string
@param string $separator The separator
@return string String containing all the errors separated by the specified sequence | [
"Return",
"all",
"errors",
"if",
"any",
"as",
"a",
"unique",
"string"
] | aa62a178bc463c10067a2ff2992d39c6f0037b9f | https://github.com/joffreydemetz/utilities/blob/aa62a178bc463c10067a2ff2992d39c6f0037b9f/src/DataObject.php#L177-L186 |
2,437 | joffreydemetz/utilities | src/DataObject.php | DataObject.getError | public function getError(?int $i=null): string
{
if ( null === $i ){
$error = end($this->errors);
}
else {
if ( !array_key_exists($i, $this->errors) ){
return false;
}
$error = $this->errors[$i];
}
if ( $error instanceof Exception ){
return $error->getMessage();
}
return $error;
} | php | public function getError(?int $i=null): string
{
if ( null === $i ){
$error = end($this->errors);
}
else {
if ( !array_key_exists($i, $this->errors) ){
return false;
}
$error = $this->errors[$i];
}
if ( $error instanceof Exception ){
return $error->getMessage();
}
return $error;
} | [
"public",
"function",
"getError",
"(",
"?",
"int",
"$",
"i",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"null",
"===",
"$",
"i",
")",
"{",
"$",
"error",
"=",
"end",
"(",
"$",
"this",
"->",
"errors",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"i",
",",
"$",
"this",
"->",
"errors",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"error",
"=",
"$",
"this",
"->",
"errors",
"[",
"$",
"i",
"]",
";",
"}",
"if",
"(",
"$",
"error",
"instanceof",
"Exception",
")",
"{",
"return",
"$",
"error",
"->",
"getMessage",
"(",
")",
";",
"}",
"return",
"$",
"error",
";",
"}"
] | Get an error message
@param integer $i Option error index
@return string Error message | [
"Get",
"an",
"error",
"message"
] | aa62a178bc463c10067a2ff2992d39c6f0037b9f | https://github.com/joffreydemetz/utilities/blob/aa62a178bc463c10067a2ff2992d39c6f0037b9f/src/DataObject.php#L204-L222 |
2,438 | kambo-1st/HttpMessage | src/Parser/Parser.php | Parser.parse | public function parse($data)
{
$parsedData = null;
switch ($this->type) {
case 'application/json':
$parsedData = json_decode($data, true);
break;
case 'application/xml':
case 'text/xml':
$backup = libxml_disable_entity_loader(true);
$parsedData = simplexml_load_string($data);
libxml_disable_entity_loader($backup);
break;
case 'application/x-www-form-urlencoded':
case 'multipart/form-data':
parse_str($data, $parsedData);
break;
default:
$parsedData = null;
break;
}
return $parsedData;
} | php | public function parse($data)
{
$parsedData = null;
switch ($this->type) {
case 'application/json':
$parsedData = json_decode($data, true);
break;
case 'application/xml':
case 'text/xml':
$backup = libxml_disable_entity_loader(true);
$parsedData = simplexml_load_string($data);
libxml_disable_entity_loader($backup);
break;
case 'application/x-www-form-urlencoded':
case 'multipart/form-data':
parse_str($data, $parsedData);
break;
default:
$parsedData = null;
break;
}
return $parsedData;
} | [
"public",
"function",
"parse",
"(",
"$",
"data",
")",
"{",
"$",
"parsedData",
"=",
"null",
";",
"switch",
"(",
"$",
"this",
"->",
"type",
")",
"{",
"case",
"'application/json'",
":",
"$",
"parsedData",
"=",
"json_decode",
"(",
"$",
"data",
",",
"true",
")",
";",
"break",
";",
"case",
"'application/xml'",
":",
"case",
"'text/xml'",
":",
"$",
"backup",
"=",
"libxml_disable_entity_loader",
"(",
"true",
")",
";",
"$",
"parsedData",
"=",
"simplexml_load_string",
"(",
"$",
"data",
")",
";",
"libxml_disable_entity_loader",
"(",
"$",
"backup",
")",
";",
"break",
";",
"case",
"'application/x-www-form-urlencoded'",
":",
"case",
"'multipart/form-data'",
":",
"parse_str",
"(",
"$",
"data",
",",
"$",
"parsedData",
")",
";",
"break",
";",
"default",
":",
"$",
"parsedData",
"=",
"null",
";",
"break",
";",
"}",
"return",
"$",
"parsedData",
";",
"}"
] | Parse data according their type.
@param mixed $data data for parsing
@return mixed Type of returned valus is based on type of data if the type is XML
an instance of SimpleXMLElement is returned, else an array is returned
If the data type is not support a null is returned. | [
"Parse",
"data",
"according",
"their",
"type",
"."
] | 38877b9d895f279fdd5bdf957d8f23f9808a940a | https://github.com/kambo-1st/HttpMessage/blob/38877b9d895f279fdd5bdf957d8f23f9808a940a/src/Parser/Parser.php#L38-L61 |
2,439 | joaogl/base | src/baseServiceProvider.php | baseServiceProvider.registerGroups | protected function registerGroups()
{
$this->app->singleton('jlourenco.group', function ($app) {
$config = $app['config']->get('jlourenco.base');
$model = array_get($config, 'base.models.Group');
return new IlluminateRoleRepository($model);
});
} | php | protected function registerGroups()
{
$this->app->singleton('jlourenco.group', function ($app) {
$config = $app['config']->get('jlourenco.base');
$model = array_get($config, 'base.models.Group');
return new IlluminateRoleRepository($model);
});
} | [
"protected",
"function",
"registerGroups",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'jlourenco.group'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"config",
"=",
"$",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'jlourenco.base'",
")",
";",
"$",
"model",
"=",
"array_get",
"(",
"$",
"config",
",",
"'base.models.Group'",
")",
";",
"return",
"new",
"IlluminateRoleRepository",
"(",
"$",
"model",
")",
";",
"}",
")",
";",
"}"
] | Registers the groups.
@return void | [
"Registers",
"the",
"groups",
"."
] | e6a4e9f4d3c75efc92545941ea5c9810d3291b56 | https://github.com/joaogl/base/blob/e6a4e9f4d3c75efc92545941ea5c9810d3291b56/src/baseServiceProvider.php#L115-L124 |
2,440 | joaogl/base | src/baseServiceProvider.php | baseServiceProvider.registerSettings | protected function registerSettings()
{
$this->app->singleton('jlourenco.settings', function ($app) {
$config = $app['config']->get('jlourenco.base');
$model = array_get($config, 'models.Settings');
return new SettingsRepository($model);
});
} | php | protected function registerSettings()
{
$this->app->singleton('jlourenco.settings', function ($app) {
$config = $app['config']->get('jlourenco.base');
$model = array_get($config, 'models.Settings');
return new SettingsRepository($model);
});
} | [
"protected",
"function",
"registerSettings",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'jlourenco.settings'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"config",
"=",
"$",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'jlourenco.base'",
")",
";",
"$",
"model",
"=",
"array_get",
"(",
"$",
"config",
",",
"'models.Settings'",
")",
";",
"return",
"new",
"SettingsRepository",
"(",
"$",
"model",
")",
";",
"}",
")",
";",
"}"
] | Registers the settings.
@return void | [
"Registers",
"the",
"settings",
"."
] | e6a4e9f4d3c75efc92545941ea5c9810d3291b56 | https://github.com/joaogl/base/blob/e6a4e9f4d3c75efc92545941ea5c9810d3291b56/src/baseServiceProvider.php#L131-L140 |
2,441 | joaogl/base | src/baseServiceProvider.php | baseServiceProvider.registerLog | protected function registerLog()
{
$this->app->singleton('jlourenco.log', function ($app) {
$config = $app['config']->get('jlourenco.base');
$model = array_get($config, 'models.Logs');
return new LogRepository($model);
});
} | php | protected function registerLog()
{
$this->app->singleton('jlourenco.log', function ($app) {
$config = $app['config']->get('jlourenco.base');
$model = array_get($config, 'models.Logs');
return new LogRepository($model);
});
} | [
"protected",
"function",
"registerLog",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'jlourenco.log'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"config",
"=",
"$",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'jlourenco.base'",
")",
";",
"$",
"model",
"=",
"array_get",
"(",
"$",
"config",
",",
"'models.Logs'",
")",
";",
"return",
"new",
"LogRepository",
"(",
"$",
"model",
")",
";",
"}",
")",
";",
"}"
] | Registers the logger.
@return void | [
"Registers",
"the",
"logger",
"."
] | e6a4e9f4d3c75efc92545941ea5c9810d3291b56 | https://github.com/joaogl/base/blob/e6a4e9f4d3c75efc92545941ea5c9810d3291b56/src/baseServiceProvider.php#L147-L156 |
2,442 | joaogl/base | src/baseServiceProvider.php | baseServiceProvider.registerBase | protected function registerBase()
{
$this->app->singleton('base', function ($app) {
$base = new Base($app['jlourenco.settings'], $app['jlourenco.user'], $app['jlourenco.log'], $app['jlourenco.visits'], $app['jlourenco.jobs']);
return $base;
});
$this->app->alias('base', 'jlourenco\base\Base');
} | php | protected function registerBase()
{
$this->app->singleton('base', function ($app) {
$base = new Base($app['jlourenco.settings'], $app['jlourenco.user'], $app['jlourenco.log'], $app['jlourenco.visits'], $app['jlourenco.jobs']);
return $base;
});
$this->app->alias('base', 'jlourenco\base\Base');
} | [
"protected",
"function",
"registerBase",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'base'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"base",
"=",
"new",
"Base",
"(",
"$",
"app",
"[",
"'jlourenco.settings'",
"]",
",",
"$",
"app",
"[",
"'jlourenco.user'",
"]",
",",
"$",
"app",
"[",
"'jlourenco.log'",
"]",
",",
"$",
"app",
"[",
"'jlourenco.visits'",
"]",
",",
"$",
"app",
"[",
"'jlourenco.jobs'",
"]",
")",
";",
"return",
"$",
"base",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"alias",
"(",
"'base'",
",",
"'jlourenco\\base\\Base'",
")",
";",
"}"
] | Registers base.
@return void | [
"Registers",
"base",
"."
] | e6a4e9f4d3c75efc92545941ea5c9810d3291b56 | https://github.com/joaogl/base/blob/e6a4e9f4d3c75efc92545941ea5c9810d3291b56/src/baseServiceProvider.php#L195-L204 |
2,443 | joaogl/base | src/baseServiceProvider.php | baseServiceProvider.registerToAppConfig | protected function registerToAppConfig()
{
/*
* Register the service provider for the dependencies.
*/
$this->app->register(\Cartalyst\Sentinel\Laravel\SentinelServiceProvider::class);
$this->app->register(\TomLingham\Searchy\SearchyServiceProvider::class);
$this->app->register(\Jenssegers\Agent\AgentServiceProvider::class);
$this->app->register(\Torann\GeoIP\GeoIPServiceProvider::class);
/*
* Create aliases for the dependencies.
*/
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('Schema', 'jlourenco\support\Database\Schema');
$loader->alias('Activation', 'Cartalyst\Sentinel\Laravel\Facades\Activation');
$loader->alias('Reminder', 'Cartalyst\Sentinel\Laravel\Facades\Reminder');
$loader->alias('Sentinel', 'Cartalyst\Sentinel\Laravel\Facades\Sentinel');
$loader->alias('Datatables', 'yajra\Datatables\Datatables');
$loader->alias('SentinelUser', 'App\Http\Middleware\SentinelUser');
$loader->alias('Base', 'jlourenco\base\Facades\Base');
$loader->alias('Searchy', 'TomLingham\Searchy\Facades\Searchy');
$loader->alias('Agent', 'Jenssegers\Agent\Facades\Agent');
$loader->alias('GeoIP', 'Torann\GeoIP\GeoIPFacade');
} | php | protected function registerToAppConfig()
{
/*
* Register the service provider for the dependencies.
*/
$this->app->register(\Cartalyst\Sentinel\Laravel\SentinelServiceProvider::class);
$this->app->register(\TomLingham\Searchy\SearchyServiceProvider::class);
$this->app->register(\Jenssegers\Agent\AgentServiceProvider::class);
$this->app->register(\Torann\GeoIP\GeoIPServiceProvider::class);
/*
* Create aliases for the dependencies.
*/
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('Schema', 'jlourenco\support\Database\Schema');
$loader->alias('Activation', 'Cartalyst\Sentinel\Laravel\Facades\Activation');
$loader->alias('Reminder', 'Cartalyst\Sentinel\Laravel\Facades\Reminder');
$loader->alias('Sentinel', 'Cartalyst\Sentinel\Laravel\Facades\Sentinel');
$loader->alias('Datatables', 'yajra\Datatables\Datatables');
$loader->alias('SentinelUser', 'App\Http\Middleware\SentinelUser');
$loader->alias('Base', 'jlourenco\base\Facades\Base');
$loader->alias('Searchy', 'TomLingham\Searchy\Facades\Searchy');
$loader->alias('Agent', 'Jenssegers\Agent\Facades\Agent');
$loader->alias('GeoIP', 'Torann\GeoIP\GeoIPFacade');
} | [
"protected",
"function",
"registerToAppConfig",
"(",
")",
"{",
"/*\n * Register the service provider for the dependencies.\n */",
"$",
"this",
"->",
"app",
"->",
"register",
"(",
"\\",
"Cartalyst",
"\\",
"Sentinel",
"\\",
"Laravel",
"\\",
"SentinelServiceProvider",
"::",
"class",
")",
";",
"$",
"this",
"->",
"app",
"->",
"register",
"(",
"\\",
"TomLingham",
"\\",
"Searchy",
"\\",
"SearchyServiceProvider",
"::",
"class",
")",
";",
"$",
"this",
"->",
"app",
"->",
"register",
"(",
"\\",
"Jenssegers",
"\\",
"Agent",
"\\",
"AgentServiceProvider",
"::",
"class",
")",
";",
"$",
"this",
"->",
"app",
"->",
"register",
"(",
"\\",
"Torann",
"\\",
"GeoIP",
"\\",
"GeoIPServiceProvider",
"::",
"class",
")",
";",
"/*\n * Create aliases for the dependencies.\n */",
"$",
"loader",
"=",
"\\",
"Illuminate",
"\\",
"Foundation",
"\\",
"AliasLoader",
"::",
"getInstance",
"(",
")",
";",
"$",
"loader",
"->",
"alias",
"(",
"'Schema'",
",",
"'jlourenco\\support\\Database\\Schema'",
")",
";",
"$",
"loader",
"->",
"alias",
"(",
"'Activation'",
",",
"'Cartalyst\\Sentinel\\Laravel\\Facades\\Activation'",
")",
";",
"$",
"loader",
"->",
"alias",
"(",
"'Reminder'",
",",
"'Cartalyst\\Sentinel\\Laravel\\Facades\\Reminder'",
")",
";",
"$",
"loader",
"->",
"alias",
"(",
"'Sentinel'",
",",
"'Cartalyst\\Sentinel\\Laravel\\Facades\\Sentinel'",
")",
";",
"$",
"loader",
"->",
"alias",
"(",
"'Datatables'",
",",
"'yajra\\Datatables\\Datatables'",
")",
";",
"$",
"loader",
"->",
"alias",
"(",
"'SentinelUser'",
",",
"'App\\Http\\Middleware\\SentinelUser'",
")",
";",
"$",
"loader",
"->",
"alias",
"(",
"'Base'",
",",
"'jlourenco\\base\\Facades\\Base'",
")",
";",
"$",
"loader",
"->",
"alias",
"(",
"'Searchy'",
",",
"'TomLingham\\Searchy\\Facades\\Searchy'",
")",
";",
"$",
"loader",
"->",
"alias",
"(",
"'Agent'",
",",
"'Jenssegers\\Agent\\Facades\\Agent'",
")",
";",
"$",
"loader",
"->",
"alias",
"(",
"'GeoIP'",
",",
"'Torann\\GeoIP\\GeoIPFacade'",
")",
";",
"}"
] | Registers this module to the
services providers and aliases.
@return void | [
"Registers",
"this",
"module",
"to",
"the",
"services",
"providers",
"and",
"aliases",
"."
] | e6a4e9f4d3c75efc92545941ea5c9810d3291b56 | https://github.com/joaogl/base/blob/e6a4e9f4d3c75efc92545941ea5c9810d3291b56/src/baseServiceProvider.php#L212-L236 |
2,444 | FiveLab/Resource | src/Serializers/Hateoas/HateoasSerializer.php | HateoasSerializer.fixRelations | protected function fixRelations(array $data): array
{
$links = [];
if (array_key_exists('relations', $data)) {
$links = array_merge($links, $data['relations']);
unset($data['relations']);
}
if (array_key_exists('actions', $data)) {
$links = array_merge($links, $data['actions']);
unset($data['actions']);
}
if (count($links)) {
$data['_links'] = $links;
}
return $data;
} | php | protected function fixRelations(array $data): array
{
$links = [];
if (array_key_exists('relations', $data)) {
$links = array_merge($links, $data['relations']);
unset($data['relations']);
}
if (array_key_exists('actions', $data)) {
$links = array_merge($links, $data['actions']);
unset($data['actions']);
}
if (count($links)) {
$data['_links'] = $links;
}
return $data;
} | [
"protected",
"function",
"fixRelations",
"(",
"array",
"$",
"data",
")",
":",
"array",
"{",
"$",
"links",
"=",
"[",
"]",
";",
"if",
"(",
"array_key_exists",
"(",
"'relations'",
",",
"$",
"data",
")",
")",
"{",
"$",
"links",
"=",
"array_merge",
"(",
"$",
"links",
",",
"$",
"data",
"[",
"'relations'",
"]",
")",
";",
"unset",
"(",
"$",
"data",
"[",
"'relations'",
"]",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"'actions'",
",",
"$",
"data",
")",
")",
"{",
"$",
"links",
"=",
"array_merge",
"(",
"$",
"links",
",",
"$",
"data",
"[",
"'actions'",
"]",
")",
";",
"unset",
"(",
"$",
"data",
"[",
"'actions'",
"]",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"links",
")",
")",
"{",
"$",
"data",
"[",
"'_links'",
"]",
"=",
"$",
"links",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Fix relations after normalization
@param array $data
@return array | [
"Fix",
"relations",
"after",
"normalization"
] | f2864924212dd4e2d1a3e7a1ad8a863d9db26127 | https://github.com/FiveLab/Resource/blob/f2864924212dd4e2d1a3e7a1ad8a863d9db26127/src/Serializers/Hateoas/HateoasSerializer.php#L98-L117 |
2,445 | jivoo/core | src/Autoloader.php | Autoloader.addPath | public function addPath($namespace, $path, $prepend = false, $psr0 = false)
{
if ($path != '') {
$path = rtrim(str_replace('\\', '/', $path), '/') . '/';
}
if ($psr0) {
$this->psr0 = true;
if (! isset($this->psr0Paths[$namespace])) {
$this->psr0Paths[$namespace] = array();
}
if ($prepend) {
array_unshift($this->psr0Paths[$namespace], $path);
} else {
array_push($this->psr0Paths[$namespace], $path);
}
} else {
$namespace = '\\' . trim($namespace, '\\');
if (! isset($this->paths[$namespace])) {
$this->paths[$namespace] = array();
}
if ($prepend) {
array_unshift($this->paths[$namespace], $path);
} else {
array_push($this->paths[$namespace], $path);
}
}
} | php | public function addPath($namespace, $path, $prepend = false, $psr0 = false)
{
if ($path != '') {
$path = rtrim(str_replace('\\', '/', $path), '/') . '/';
}
if ($psr0) {
$this->psr0 = true;
if (! isset($this->psr0Paths[$namespace])) {
$this->psr0Paths[$namespace] = array();
}
if ($prepend) {
array_unshift($this->psr0Paths[$namespace], $path);
} else {
array_push($this->psr0Paths[$namespace], $path);
}
} else {
$namespace = '\\' . trim($namespace, '\\');
if (! isset($this->paths[$namespace])) {
$this->paths[$namespace] = array();
}
if ($prepend) {
array_unshift($this->paths[$namespace], $path);
} else {
array_push($this->paths[$namespace], $path);
}
}
} | [
"public",
"function",
"addPath",
"(",
"$",
"namespace",
",",
"$",
"path",
",",
"$",
"prepend",
"=",
"false",
",",
"$",
"psr0",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"path",
"!=",
"''",
")",
"{",
"$",
"path",
"=",
"rtrim",
"(",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"path",
")",
",",
"'/'",
")",
".",
"'/'",
";",
"}",
"if",
"(",
"$",
"psr0",
")",
"{",
"$",
"this",
"->",
"psr0",
"=",
"true",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"psr0Paths",
"[",
"$",
"namespace",
"]",
")",
")",
"{",
"$",
"this",
"->",
"psr0Paths",
"[",
"$",
"namespace",
"]",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"$",
"prepend",
")",
"{",
"array_unshift",
"(",
"$",
"this",
"->",
"psr0Paths",
"[",
"$",
"namespace",
"]",
",",
"$",
"path",
")",
";",
"}",
"else",
"{",
"array_push",
"(",
"$",
"this",
"->",
"psr0Paths",
"[",
"$",
"namespace",
"]",
",",
"$",
"path",
")",
";",
"}",
"}",
"else",
"{",
"$",
"namespace",
"=",
"'\\\\'",
".",
"trim",
"(",
"$",
"namespace",
",",
"'\\\\'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"paths",
"[",
"$",
"namespace",
"]",
")",
")",
"{",
"$",
"this",
"->",
"paths",
"[",
"$",
"namespace",
"]",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"$",
"prepend",
")",
"{",
"array_unshift",
"(",
"$",
"this",
"->",
"paths",
"[",
"$",
"namespace",
"]",
",",
"$",
"path",
")",
";",
"}",
"else",
"{",
"array_push",
"(",
"$",
"this",
"->",
"paths",
"[",
"$",
"namespace",
"]",
",",
"$",
"path",
")",
";",
"}",
"}",
"}"
] | Add an autload directory for a namespace.
@param string $namespace
Namespace prefix (i.e. with trailing backslash).
@param string $path
Directory path.
@param bool $prepend
If true, the path will be prepended instead of
appended.
@param bool $psr0
Whether to use PSR-0 instead of PSR-4 for this path. | [
"Add",
"an",
"autload",
"directory",
"for",
"a",
"namespace",
"."
] | 4ef3445068f0ff9c0a6512cb741831a847013b76 | https://github.com/jivoo/core/blob/4ef3445068f0ff9c0a6512cb741831a847013b76/src/Autoloader.php#L88-L116 |
2,446 | jivoo/core | src/Autoloader.php | Autoloader.load | public function load($class)
{
if ($this->psr0 and $this->loadPsr0($class)) {
return true;
}
$namespace = '\\';
$classPath = str_replace('\\', '/', $class) . '.php';
while (true) {
if ($this->loadFrom($classPath, $namespace)) {
return true;
}
$pos = strpos($classPath, '/');
if ($pos === false) {
if (! $this->psr0) {
break;
}
$pos = strpos($classPath, '_');
if ($pos === false) {
break;
}
}
$namespace = rtrim($namespace, '\\') . '\\' . substr($classPath, 0, $pos);
$classPath = substr($classPath, $pos + 1);
}
return false;
} | php | public function load($class)
{
if ($this->psr0 and $this->loadPsr0($class)) {
return true;
}
$namespace = '\\';
$classPath = str_replace('\\', '/', $class) . '.php';
while (true) {
if ($this->loadFrom($classPath, $namespace)) {
return true;
}
$pos = strpos($classPath, '/');
if ($pos === false) {
if (! $this->psr0) {
break;
}
$pos = strpos($classPath, '_');
if ($pos === false) {
break;
}
}
$namespace = rtrim($namespace, '\\') . '\\' . substr($classPath, 0, $pos);
$classPath = substr($classPath, $pos + 1);
}
return false;
} | [
"public",
"function",
"load",
"(",
"$",
"class",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"psr0",
"and",
"$",
"this",
"->",
"loadPsr0",
"(",
"$",
"class",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"namespace",
"=",
"'\\\\'",
";",
"$",
"classPath",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"class",
")",
".",
"'.php'",
";",
"while",
"(",
"true",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"loadFrom",
"(",
"$",
"classPath",
",",
"$",
"namespace",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"classPath",
",",
"'/'",
")",
";",
"if",
"(",
"$",
"pos",
"===",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"psr0",
")",
"{",
"break",
";",
"}",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"classPath",
",",
"'_'",
")",
";",
"if",
"(",
"$",
"pos",
"===",
"false",
")",
"{",
"break",
";",
"}",
"}",
"$",
"namespace",
"=",
"rtrim",
"(",
"$",
"namespace",
",",
"'\\\\'",
")",
".",
"'\\\\'",
".",
"substr",
"(",
"$",
"classPath",
",",
"0",
",",
"$",
"pos",
")",
";",
"$",
"classPath",
"=",
"substr",
"(",
"$",
"classPath",
",",
"$",
"pos",
"+",
"1",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Attempt to load a class.
@param string $class
Fully qualified class name.
@return bool True on success, false on failure. | [
"Attempt",
"to",
"load",
"a",
"class",
"."
] | 4ef3445068f0ff9c0a6512cb741831a847013b76 | https://github.com/jivoo/core/blob/4ef3445068f0ff9c0a6512cb741831a847013b76/src/Autoloader.php#L125-L150 |
2,447 | deasilworks/cef | src/CEFData.php | CEFData.hydrateClassObject | private function hydrateClassObject($obj, $data)
{
// loop through the class object and hydrate it
foreach ($data as $property => $value) {
$this->hydrate($obj, $property, $value);
}
return $obj;
} | php | private function hydrateClassObject($obj, $data)
{
// loop through the class object and hydrate it
foreach ($data as $property => $value) {
$this->hydrate($obj, $property, $value);
}
return $obj;
} | [
"private",
"function",
"hydrateClassObject",
"(",
"$",
"obj",
",",
"$",
"data",
")",
"{",
"// loop through the class object and hydrate it",
"foreach",
"(",
"$",
"data",
"as",
"$",
"property",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"hydrate",
"(",
"$",
"obj",
",",
"$",
"property",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"obj",
";",
"}"
] | Hydrate class object.
@param $obj
@param $data
@return mixed | [
"Hydrate",
"class",
"object",
"."
] | 18c65f2b123512bba2208975dc655354f57670be | https://github.com/deasilworks/cef/blob/18c65f2b123512bba2208975dc655354f57670be/src/CEFData.php#L265-L273 |
2,448 | webbuilders-group/silverstripe-kapost-bridge | code/model/KapostPreviewToken.php | KapostPreviewToken.onAfterWrite | protected function onAfterWrite() {
parent::onAfterWrite();
//Clean up the expired tokens
$expiredTokens=KapostPreviewToken::get()->filter('Created:LessThan', date('Y-m-d H:i:s', strtotime('-'.KapostService::config()->preview_token_expiry.' minutes')));
if($expiredTokens->count()>0) {
foreach($expiredTokens as $token) {
$token->delete();
}
}
} | php | protected function onAfterWrite() {
parent::onAfterWrite();
//Clean up the expired tokens
$expiredTokens=KapostPreviewToken::get()->filter('Created:LessThan', date('Y-m-d H:i:s', strtotime('-'.KapostService::config()->preview_token_expiry.' minutes')));
if($expiredTokens->count()>0) {
foreach($expiredTokens as $token) {
$token->delete();
}
}
} | [
"protected",
"function",
"onAfterWrite",
"(",
")",
"{",
"parent",
"::",
"onAfterWrite",
"(",
")",
";",
"//Clean up the expired tokens",
"$",
"expiredTokens",
"=",
"KapostPreviewToken",
"::",
"get",
"(",
")",
"->",
"filter",
"(",
"'Created:LessThan'",
",",
"date",
"(",
"'Y-m-d H:i:s'",
",",
"strtotime",
"(",
"'-'",
".",
"KapostService",
"::",
"config",
"(",
")",
"->",
"preview_token_expiry",
".",
"' minutes'",
")",
")",
")",
";",
"if",
"(",
"$",
"expiredTokens",
"->",
"count",
"(",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"expiredTokens",
"as",
"$",
"token",
")",
"{",
"$",
"token",
"->",
"delete",
"(",
")",
";",
"}",
"}",
"}"
] | Cleans up the expired tokens after writing | [
"Cleans",
"up",
"the",
"expired",
"tokens",
"after",
"writing"
] | 718f498cad0eec764d19c9081404b2a0c8f44d71 | https://github.com/webbuilders-group/silverstripe-kapost-bridge/blob/718f498cad0eec764d19c9081404b2a0c8f44d71/code/model/KapostPreviewToken.php#L18-L29 |
2,449 | lrc-se/bth-anax-repository | src/Repository/ReferenceResolverTrait.php | ReferenceResolverTrait.getReference | public function getReference($repository, $attr, $key = 'id')
{
if (isset($this->$attr)) {
return ($repository->find($key, $this->$attr) ?: null);
}
return null;
} | php | public function getReference($repository, $attr, $key = 'id')
{
if (isset($this->$attr)) {
return ($repository->find($key, $this->$attr) ?: null);
}
return null;
} | [
"public",
"function",
"getReference",
"(",
"$",
"repository",
",",
"$",
"attr",
",",
"$",
"key",
"=",
"'id'",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"$",
"attr",
")",
")",
"{",
"return",
"(",
"$",
"repository",
"->",
"find",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"$",
"attr",
")",
"?",
":",
"null",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Retrieve a reference by foreign key.
@param RepositoryInterface $repository Repository to query.
@param string $attr Name of foreign key attribute.
@param string $key Name of primary key attribute in referenced table.
@return mixed Model instance if found, null otherwise. | [
"Retrieve",
"a",
"reference",
"by",
"foreign",
"key",
"."
] | 344a0795fbfadf34ea768719dc5cf2f1d90154df | https://github.com/lrc-se/bth-anax-repository/blob/344a0795fbfadf34ea768719dc5cf2f1d90154df/src/Repository/ReferenceResolverTrait.php#L19-L25 |
2,450 | limit-zero/assets | src/AssetFactory.php | AssetFactory.createFromPath | public static function createFromPath($path)
{
if (!file_exists($path)) {
throw new Exception\FactoryException(sprintf('Unable to open file %s', $path));
}
$file = new \SplFileInfo($path);
return static::createFromSplFileInfo($file);
} | php | public static function createFromPath($path)
{
if (!file_exists($path)) {
throw new Exception\FactoryException(sprintf('Unable to open file %s', $path));
}
$file = new \SplFileInfo($path);
return static::createFromSplFileInfo($file);
} | [
"public",
"static",
"function",
"createFromPath",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"FactoryException",
"(",
"sprintf",
"(",
"'Unable to open file %s'",
",",
"$",
"path",
")",
")",
";",
"}",
"$",
"file",
"=",
"new",
"\\",
"SplFileInfo",
"(",
"$",
"path",
")",
";",
"return",
"static",
"::",
"createFromSplFileInfo",
"(",
"$",
"file",
")",
";",
"}"
] | Creates an Asset from a file path
@param string $path
@throws Exception\FactoryException If the file could not be loaded
@return Asset | [
"Creates",
"an",
"Asset",
"from",
"a",
"file",
"path"
] | ce9c713026ae9eb812b7b119c76a3516f3169ebc | https://github.com/limit-zero/assets/blob/ce9c713026ae9eb812b7b119c76a3516f3169ebc/src/AssetFactory.php#L31-L38 |
2,451 | limit-zero/assets | src/AssetFactory.php | AssetFactory.createFromSplFileInfo | public static function createFromSplFileInfo(\SplFileInfo $file)
{
$asset = new Asset();
$guesser = MimeTypeGuesser::getInstance();
return $asset
->setFilename($file->getFilename())
->setExtension($file->getExtension())
->setPathname($file->getPathname())
->setMimeType($guesser->guess($file->getPathname()))
->setClientOriginalName($file->getFilename())
->setClientOriginalExtension($file->getExtension())
;
} | php | public static function createFromSplFileInfo(\SplFileInfo $file)
{
$asset = new Asset();
$guesser = MimeTypeGuesser::getInstance();
return $asset
->setFilename($file->getFilename())
->setExtension($file->getExtension())
->setPathname($file->getPathname())
->setMimeType($guesser->guess($file->getPathname()))
->setClientOriginalName($file->getFilename())
->setClientOriginalExtension($file->getExtension())
;
} | [
"public",
"static",
"function",
"createFromSplFileInfo",
"(",
"\\",
"SplFileInfo",
"$",
"file",
")",
"{",
"$",
"asset",
"=",
"new",
"Asset",
"(",
")",
";",
"$",
"guesser",
"=",
"MimeTypeGuesser",
"::",
"getInstance",
"(",
")",
";",
"return",
"$",
"asset",
"->",
"setFilename",
"(",
"$",
"file",
"->",
"getFilename",
"(",
")",
")",
"->",
"setExtension",
"(",
"$",
"file",
"->",
"getExtension",
"(",
")",
")",
"->",
"setPathname",
"(",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
"->",
"setMimeType",
"(",
"$",
"guesser",
"->",
"guess",
"(",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
")",
"->",
"setClientOriginalName",
"(",
"$",
"file",
"->",
"getFilename",
"(",
")",
")",
"->",
"setClientOriginalExtension",
"(",
"$",
"file",
"->",
"getExtension",
"(",
")",
")",
";",
"}"
] | Creates an Asset from a \SplFileInfo wrapper
@param \SplFileInfo $file
@throws Exception\FactoryException If the file could not be loaded
@return Asset | [
"Creates",
"an",
"Asset",
"from",
"a",
"\\",
"SplFileInfo",
"wrapper"
] | ce9c713026ae9eb812b7b119c76a3516f3169ebc | https://github.com/limit-zero/assets/blob/ce9c713026ae9eb812b7b119c76a3516f3169ebc/src/AssetFactory.php#L47-L59 |
2,452 | limit-zero/assets | src/AssetFactory.php | AssetFactory.createFromUploadedFile | public static function createFromUploadedFile(UploadedFile $file)
{
$asset = new Asset();
$guesser = MimeTypeGuesser::getInstance();
return $asset
->setFilename($file->getFilename())
->setExtension($file->getExtension())
->setPathname($file->getPathname())
->setMimeType($guesser->guess($file->getPathname()))
->setClientOriginalName($file->getClientOriginalName())
->setClientOriginalExtension($file->getClientOriginalExtension())
->setClientMimeType($file->getClientMimeType())
;
} | php | public static function createFromUploadedFile(UploadedFile $file)
{
$asset = new Asset();
$guesser = MimeTypeGuesser::getInstance();
return $asset
->setFilename($file->getFilename())
->setExtension($file->getExtension())
->setPathname($file->getPathname())
->setMimeType($guesser->guess($file->getPathname()))
->setClientOriginalName($file->getClientOriginalName())
->setClientOriginalExtension($file->getClientOriginalExtension())
->setClientMimeType($file->getClientMimeType())
;
} | [
"public",
"static",
"function",
"createFromUploadedFile",
"(",
"UploadedFile",
"$",
"file",
")",
"{",
"$",
"asset",
"=",
"new",
"Asset",
"(",
")",
";",
"$",
"guesser",
"=",
"MimeTypeGuesser",
"::",
"getInstance",
"(",
")",
";",
"return",
"$",
"asset",
"->",
"setFilename",
"(",
"$",
"file",
"->",
"getFilename",
"(",
")",
")",
"->",
"setExtension",
"(",
"$",
"file",
"->",
"getExtension",
"(",
")",
")",
"->",
"setPathname",
"(",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
"->",
"setMimeType",
"(",
"$",
"guesser",
"->",
"guess",
"(",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
")",
"->",
"setClientOriginalName",
"(",
"$",
"file",
"->",
"getClientOriginalName",
"(",
")",
")",
"->",
"setClientOriginalExtension",
"(",
"$",
"file",
"->",
"getClientOriginalExtension",
"(",
")",
")",
"->",
"setClientMimeType",
"(",
"$",
"file",
"->",
"getClientMimeType",
"(",
")",
")",
";",
"}"
] | Creates an Asset from an UploadedFile instance
@param UploadedFile $file
@throws Exception\FactoryException If the file could not be loaded
@return Asset | [
"Creates",
"an",
"Asset",
"from",
"an",
"UploadedFile",
"instance"
] | ce9c713026ae9eb812b7b119c76a3516f3169ebc | https://github.com/limit-zero/assets/blob/ce9c713026ae9eb812b7b119c76a3516f3169ebc/src/AssetFactory.php#L68-L81 |
2,453 | limit-zero/assets | src/AssetFactory.php | AssetFactory.createFromUri | public static function createFromUri($uri)
{
$name = substr($uri, strrpos($uri, '/'));
$path = sprintf('%s/%s', sys_get_temp_dir(), $name);
copy($uri, $path);
return static::createFromPath($path);
} | php | public static function createFromUri($uri)
{
$name = substr($uri, strrpos($uri, '/'));
$path = sprintf('%s/%s', sys_get_temp_dir(), $name);
copy($uri, $path);
return static::createFromPath($path);
} | [
"public",
"static",
"function",
"createFromUri",
"(",
"$",
"uri",
")",
"{",
"$",
"name",
"=",
"substr",
"(",
"$",
"uri",
",",
"strrpos",
"(",
"$",
"uri",
",",
"'/'",
")",
")",
";",
"$",
"path",
"=",
"sprintf",
"(",
"'%s/%s'",
",",
"sys_get_temp_dir",
"(",
")",
",",
"$",
"name",
")",
";",
"copy",
"(",
"$",
"uri",
",",
"$",
"path",
")",
";",
"return",
"static",
"::",
"createFromPath",
"(",
"$",
"path",
")",
";",
"}"
] | Creates an Asset from a URI
@param string $uri
@throws Exception\FactoryException If the file could not be loaded
@return Asset | [
"Creates",
"an",
"Asset",
"from",
"a",
"URI"
] | ce9c713026ae9eb812b7b119c76a3516f3169ebc | https://github.com/limit-zero/assets/blob/ce9c713026ae9eb812b7b119c76a3516f3169ebc/src/AssetFactory.php#L90-L96 |
2,454 | CloudObjects/CloudObjects-PHP-SDK | CloudObjects/SDK/NodeReader.php | NodeReader.hasType | public function hasType(Node $node = null, $type) {
if (!isset($node))
return false;
$type = $this->expand($type);
$typesFromNode = $node->getType();
if (!isset($typesFromNode))
return false;
if (is_array($typesFromNode)) {
foreach ($typesFromNode as $t)
if (is_a($t, 'ML\JsonLD\Node')
&& $t->getId() == $type)
return true;
} else
if (is_a($typesFromNode, 'ML\JsonLD\Node')
&& $typesFromNode->getId() == $type)
return true;
else
return false;
return false;
} | php | public function hasType(Node $node = null, $type) {
if (!isset($node))
return false;
$type = $this->expand($type);
$typesFromNode = $node->getType();
if (!isset($typesFromNode))
return false;
if (is_array($typesFromNode)) {
foreach ($typesFromNode as $t)
if (is_a($t, 'ML\JsonLD\Node')
&& $t->getId() == $type)
return true;
} else
if (is_a($typesFromNode, 'ML\JsonLD\Node')
&& $typesFromNode->getId() == $type)
return true;
else
return false;
return false;
} | [
"public",
"function",
"hasType",
"(",
"Node",
"$",
"node",
"=",
"null",
",",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"node",
")",
")",
"return",
"false",
";",
"$",
"type",
"=",
"$",
"this",
"->",
"expand",
"(",
"$",
"type",
")",
";",
"$",
"typesFromNode",
"=",
"$",
"node",
"->",
"getType",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"typesFromNode",
")",
")",
"return",
"false",
";",
"if",
"(",
"is_array",
"(",
"$",
"typesFromNode",
")",
")",
"{",
"foreach",
"(",
"$",
"typesFromNode",
"as",
"$",
"t",
")",
"if",
"(",
"is_a",
"(",
"$",
"t",
",",
"'ML\\JsonLD\\Node'",
")",
"&&",
"$",
"t",
"->",
"getId",
"(",
")",
"==",
"$",
"type",
")",
"return",
"true",
";",
"}",
"else",
"if",
"(",
"is_a",
"(",
"$",
"typesFromNode",
",",
"'ML\\JsonLD\\Node'",
")",
"&&",
"$",
"typesFromNode",
"->",
"getId",
"(",
")",
"==",
"$",
"type",
")",
"return",
"true",
";",
"else",
"return",
"false",
";",
"return",
"false",
";",
"}"
] | Checks whether a node has a certain type.
@param Node $node The node to work on.
@param string|object $type The type to check for.
@return boolean | [
"Checks",
"whether",
"a",
"node",
"has",
"a",
"certain",
"type",
"."
] | 4f97f523cdab7501728ad0505e51435f727f6785 | https://github.com/CloudObjects/CloudObjects-PHP-SDK/blob/4f97f523cdab7501728ad0505e51435f727f6785/CloudObjects/SDK/NodeReader.php#L41-L61 |
2,455 | CloudObjects/CloudObjects-PHP-SDK | CloudObjects/SDK/NodeReader.php | NodeReader.getFirstValueString | public function getFirstValueString(Node $node = null, $property, $default = null) {
$valueFromNode = $this->getFirstValue($node, $property, $default);
if ($valueFromNode == $default)
return $default;
if (is_a($valueFromNode, 'ML\JsonLD\Node'))
return $valueFromNode->getId();
else
return $valueFromNode->getValue();
} | php | public function getFirstValueString(Node $node = null, $property, $default = null) {
$valueFromNode = $this->getFirstValue($node, $property, $default);
if ($valueFromNode == $default)
return $default;
if (is_a($valueFromNode, 'ML\JsonLD\Node'))
return $valueFromNode->getId();
else
return $valueFromNode->getValue();
} | [
"public",
"function",
"getFirstValueString",
"(",
"Node",
"$",
"node",
"=",
"null",
",",
"$",
"property",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"valueFromNode",
"=",
"$",
"this",
"->",
"getFirstValue",
"(",
"$",
"node",
",",
"$",
"property",
",",
"$",
"default",
")",
";",
"if",
"(",
"$",
"valueFromNode",
"==",
"$",
"default",
")",
"return",
"$",
"default",
";",
"if",
"(",
"is_a",
"(",
"$",
"valueFromNode",
",",
"'ML\\JsonLD\\Node'",
")",
")",
"return",
"$",
"valueFromNode",
"->",
"getId",
"(",
")",
";",
"else",
"return",
"$",
"valueFromNode",
"->",
"getValue",
"(",
")",
";",
"}"
] | Reads a property from a node and converts it into a string.
If the property has multiple values only the first is returned.
If no value is found or the node is null, the default is returned.
@param Node $node The node to work on.
@param string|object $property The property to read.
@param $default The default that is returned if no value for the property exists on the node.
@return string|null | [
"Reads",
"a",
"property",
"from",
"a",
"node",
"and",
"converts",
"it",
"into",
"a",
"string",
".",
"If",
"the",
"property",
"has",
"multiple",
"values",
"only",
"the",
"first",
"is",
"returned",
".",
"If",
"no",
"value",
"is",
"found",
"or",
"the",
"node",
"is",
"null",
"the",
"default",
"is",
"returned",
"."
] | 4f97f523cdab7501728ad0505e51435f727f6785 | https://github.com/CloudObjects/CloudObjects-PHP-SDK/blob/4f97f523cdab7501728ad0505e51435f727f6785/CloudObjects/SDK/NodeReader.php#L85-L94 |
2,456 | CloudObjects/CloudObjects-PHP-SDK | CloudObjects/SDK/NodeReader.php | NodeReader.getFirstValueIRI | public function getFirstValueIRI(Node $node = null, $property, IRI $default = null) {
$valueFromNode = $this->getFirstValue($node, $property, $default);
if ($valueFromNode == $default)
return $default;
if (is_a($valueFromNode, 'ML\JsonLD\Node'))
return new IRI($valueFromNode->getId());
else
return $default;
} | php | public function getFirstValueIRI(Node $node = null, $property, IRI $default = null) {
$valueFromNode = $this->getFirstValue($node, $property, $default);
if ($valueFromNode == $default)
return $default;
if (is_a($valueFromNode, 'ML\JsonLD\Node'))
return new IRI($valueFromNode->getId());
else
return $default;
} | [
"public",
"function",
"getFirstValueIRI",
"(",
"Node",
"$",
"node",
"=",
"null",
",",
"$",
"property",
",",
"IRI",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"valueFromNode",
"=",
"$",
"this",
"->",
"getFirstValue",
"(",
"$",
"node",
",",
"$",
"property",
",",
"$",
"default",
")",
";",
"if",
"(",
"$",
"valueFromNode",
"==",
"$",
"default",
")",
"return",
"$",
"default",
";",
"if",
"(",
"is_a",
"(",
"$",
"valueFromNode",
",",
"'ML\\JsonLD\\Node'",
")",
")",
"return",
"new",
"IRI",
"(",
"$",
"valueFromNode",
"->",
"getId",
"(",
")",
")",
";",
"else",
"return",
"$",
"default",
";",
"}"
] | Reads a property from a node and converts it into a IRI.
If the property has multiple values only the first is returned.
If no value is found, value is a literal or the node is null, the default is returned.
@param Node $node The node to work on.
@param string|object $property The property to read.
@param $default The default that is returned if no value for the property exists on the node.
@return string|null | [
"Reads",
"a",
"property",
"from",
"a",
"node",
"and",
"converts",
"it",
"into",
"a",
"IRI",
".",
"If",
"the",
"property",
"has",
"multiple",
"values",
"only",
"the",
"first",
"is",
"returned",
".",
"If",
"no",
"value",
"is",
"found",
"value",
"is",
"a",
"literal",
"or",
"the",
"node",
"is",
"null",
"the",
"default",
"is",
"returned",
"."
] | 4f97f523cdab7501728ad0505e51435f727f6785 | https://github.com/CloudObjects/CloudObjects-PHP-SDK/blob/4f97f523cdab7501728ad0505e51435f727f6785/CloudObjects/SDK/NodeReader.php#L106-L115 |
2,457 | CloudObjects/CloudObjects-PHP-SDK | CloudObjects/SDK/NodeReader.php | NodeReader.getFirstValueNode | public function getFirstValueNode(Node $node = null, $property, Node $default = null) {
$valueFromNode = $this->getFirstValue($node, $property, $default);
if ($valueFromNode == $default)
return $default;
if (is_a($valueFromNode, 'ML\JsonLD\Node'))
return $valueFromNode;
else
return $default;
} | php | public function getFirstValueNode(Node $node = null, $property, Node $default = null) {
$valueFromNode = $this->getFirstValue($node, $property, $default);
if ($valueFromNode == $default)
return $default;
if (is_a($valueFromNode, 'ML\JsonLD\Node'))
return $valueFromNode;
else
return $default;
} | [
"public",
"function",
"getFirstValueNode",
"(",
"Node",
"$",
"node",
"=",
"null",
",",
"$",
"property",
",",
"Node",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"valueFromNode",
"=",
"$",
"this",
"->",
"getFirstValue",
"(",
"$",
"node",
",",
"$",
"property",
",",
"$",
"default",
")",
";",
"if",
"(",
"$",
"valueFromNode",
"==",
"$",
"default",
")",
"return",
"$",
"default",
";",
"if",
"(",
"is_a",
"(",
"$",
"valueFromNode",
",",
"'ML\\JsonLD\\Node'",
")",
")",
"return",
"$",
"valueFromNode",
";",
"else",
"return",
"$",
"default",
";",
"}"
] | Reads a property from a node and returns it as a Node.
If the property has multiple values only the first is returned.
If no value is found, value is a literal or the node is null, the default is returned.
@param Node $node The node to work on.
@param string|object $property The property to read.
@param $default The default that is returned if no value for the property exists on the node.
@return string|null | [
"Reads",
"a",
"property",
"from",
"a",
"node",
"and",
"returns",
"it",
"as",
"a",
"Node",
".",
"If",
"the",
"property",
"has",
"multiple",
"values",
"only",
"the",
"first",
"is",
"returned",
".",
"If",
"no",
"value",
"is",
"found",
"value",
"is",
"a",
"literal",
"or",
"the",
"node",
"is",
"null",
"the",
"default",
"is",
"returned",
"."
] | 4f97f523cdab7501728ad0505e51435f727f6785 | https://github.com/CloudObjects/CloudObjects-PHP-SDK/blob/4f97f523cdab7501728ad0505e51435f727f6785/CloudObjects/SDK/NodeReader.php#L127-L136 |
2,458 | CloudObjects/CloudObjects-PHP-SDK | CloudObjects/SDK/NodeReader.php | NodeReader.hasPropertyValue | public function hasPropertyValue(Node $node = null, $property, $value) {
if (!isset($node))
return false;
$valuesFromNode = $node->getProperty($this->expand($property));
if (!isset($valuesFromNode))
return false;
if (!is_array($valuesFromNode))
$valuesFromNode = array($valuesFromNode);
foreach ($valuesFromNode as $v) {
if (is_a($v, 'ML\JsonLD\Node')) {
if ($v->getId() == $this->expand($value))
return true;
} else {
if ($v->getValue() == $value)
return true;
}
}
return false;
} | php | public function hasPropertyValue(Node $node = null, $property, $value) {
if (!isset($node))
return false;
$valuesFromNode = $node->getProperty($this->expand($property));
if (!isset($valuesFromNode))
return false;
if (!is_array($valuesFromNode))
$valuesFromNode = array($valuesFromNode);
foreach ($valuesFromNode as $v) {
if (is_a($v, 'ML\JsonLD\Node')) {
if ($v->getId() == $this->expand($value))
return true;
} else {
if ($v->getValue() == $value)
return true;
}
}
return false;
} | [
"public",
"function",
"hasPropertyValue",
"(",
"Node",
"$",
"node",
"=",
"null",
",",
"$",
"property",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"node",
")",
")",
"return",
"false",
";",
"$",
"valuesFromNode",
"=",
"$",
"node",
"->",
"getProperty",
"(",
"$",
"this",
"->",
"expand",
"(",
"$",
"property",
")",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"valuesFromNode",
")",
")",
"return",
"false",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"valuesFromNode",
")",
")",
"$",
"valuesFromNode",
"=",
"array",
"(",
"$",
"valuesFromNode",
")",
";",
"foreach",
"(",
"$",
"valuesFromNode",
"as",
"$",
"v",
")",
"{",
"if",
"(",
"is_a",
"(",
"$",
"v",
",",
"'ML\\JsonLD\\Node'",
")",
")",
"{",
"if",
"(",
"$",
"v",
"->",
"getId",
"(",
")",
"==",
"$",
"this",
"->",
"expand",
"(",
"$",
"value",
")",
")",
"return",
"true",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"v",
"->",
"getValue",
"(",
")",
"==",
"$",
"value",
")",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks whether a node has a specific value for a property.
@param Node $node The node to work on.
@param string|object $property The property to read.
@param string|object $value The expected value.
@return boolean | [
"Checks",
"whether",
"a",
"node",
"has",
"a",
"specific",
"value",
"for",
"a",
"property",
"."
] | 4f97f523cdab7501728ad0505e51435f727f6785 | https://github.com/CloudObjects/CloudObjects-PHP-SDK/blob/4f97f523cdab7501728ad0505e51435f727f6785/CloudObjects/SDK/NodeReader.php#L146-L166 |
2,459 | CloudObjects/CloudObjects-PHP-SDK | CloudObjects/SDK/NodeReader.php | NodeReader.hasProperty | public function hasProperty(Node $node = null, $property) {
if (!isset($node))
return false;
return ($node->getProperty($this->expand($property)) != null);
} | php | public function hasProperty(Node $node = null, $property) {
if (!isset($node))
return false;
return ($node->getProperty($this->expand($property)) != null);
} | [
"public",
"function",
"hasProperty",
"(",
"Node",
"$",
"node",
"=",
"null",
",",
"$",
"property",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"node",
")",
")",
"return",
"false",
";",
"return",
"(",
"$",
"node",
"->",
"getProperty",
"(",
"$",
"this",
"->",
"expand",
"(",
"$",
"property",
")",
")",
"!=",
"null",
")",
";",
"}"
] | Checks whether the node has at least one value for a property.
@param Node $node The node to work on.
@param string|object $property The property to read.
@return boolean | [
"Checks",
"whether",
"the",
"node",
"has",
"at",
"least",
"one",
"value",
"for",
"a",
"property",
"."
] | 4f97f523cdab7501728ad0505e51435f727f6785 | https://github.com/CloudObjects/CloudObjects-PHP-SDK/blob/4f97f523cdab7501728ad0505e51435f727f6785/CloudObjects/SDK/NodeReader.php#L175-L180 |
2,460 | CloudObjects/CloudObjects-PHP-SDK | CloudObjects/SDK/NodeReader.php | NodeReader.getAllValuesString | public function getAllValuesString(Node $node = null, $property) {
$allValues = $this->getAllValues($node, $property);
$output = [];
foreach ($allValues as $a)
if (is_a($a, 'ML\JsonLD\Node'))
$output[] = $a->getId();
else
$output[] = $a->getValue();
return $output;
} | php | public function getAllValuesString(Node $node = null, $property) {
$allValues = $this->getAllValues($node, $property);
$output = [];
foreach ($allValues as $a)
if (is_a($a, 'ML\JsonLD\Node'))
$output[] = $a->getId();
else
$output[] = $a->getValue();
return $output;
} | [
"public",
"function",
"getAllValuesString",
"(",
"Node",
"$",
"node",
"=",
"null",
",",
"$",
"property",
")",
"{",
"$",
"allValues",
"=",
"$",
"this",
"->",
"getAllValues",
"(",
"$",
"node",
",",
"$",
"property",
")",
";",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"allValues",
"as",
"$",
"a",
")",
"if",
"(",
"is_a",
"(",
"$",
"a",
",",
"'ML\\JsonLD\\Node'",
")",
")",
"$",
"output",
"[",
"]",
"=",
"$",
"a",
"->",
"getId",
"(",
")",
";",
"else",
"$",
"output",
"[",
"]",
"=",
"$",
"a",
"->",
"getValue",
"(",
")",
";",
"return",
"$",
"output",
";",
"}"
] | Reads all values from a node and returns them as a string array.
@param Node $node The node to work on.
@param string|object $property The property to read.
@return array<string> | [
"Reads",
"all",
"values",
"from",
"a",
"node",
"and",
"returns",
"them",
"as",
"a",
"string",
"array",
"."
] | 4f97f523cdab7501728ad0505e51435f727f6785 | https://github.com/CloudObjects/CloudObjects-PHP-SDK/blob/4f97f523cdab7501728ad0505e51435f727f6785/CloudObjects/SDK/NodeReader.php#L201-L211 |
2,461 | CloudObjects/CloudObjects-PHP-SDK | CloudObjects/SDK/NodeReader.php | NodeReader.getAllValuesIRI | public function getAllValuesIRI(Node $node = null, $property) {
$allValues = $this->getAllValues($node, $property);
$output = [];
foreach ($allValues as $a)
if (is_a($a, 'ML\JsonLD\Node'))
$output[] = new IRI($a->getId());
return $output;
} | php | public function getAllValuesIRI(Node $node = null, $property) {
$allValues = $this->getAllValues($node, $property);
$output = [];
foreach ($allValues as $a)
if (is_a($a, 'ML\JsonLD\Node'))
$output[] = new IRI($a->getId());
return $output;
} | [
"public",
"function",
"getAllValuesIRI",
"(",
"Node",
"$",
"node",
"=",
"null",
",",
"$",
"property",
")",
"{",
"$",
"allValues",
"=",
"$",
"this",
"->",
"getAllValues",
"(",
"$",
"node",
",",
"$",
"property",
")",
";",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"allValues",
"as",
"$",
"a",
")",
"if",
"(",
"is_a",
"(",
"$",
"a",
",",
"'ML\\JsonLD\\Node'",
")",
")",
"$",
"output",
"[",
"]",
"=",
"new",
"IRI",
"(",
"$",
"a",
"->",
"getId",
"(",
")",
")",
";",
"return",
"$",
"output",
";",
"}"
] | Reads all values from a node and returns them as a IRI array.
Only converts the Node IDs of nodes into IRI, literal values are skipped.
@param Node $node The node to work on.
@param string|object $property The property to read.
@return array<IRI> | [
"Reads",
"all",
"values",
"from",
"a",
"node",
"and",
"returns",
"them",
"as",
"a",
"IRI",
"array",
".",
"Only",
"converts",
"the",
"Node",
"IDs",
"of",
"nodes",
"into",
"IRI",
"literal",
"values",
"are",
"skipped",
"."
] | 4f97f523cdab7501728ad0505e51435f727f6785 | https://github.com/CloudObjects/CloudObjects-PHP-SDK/blob/4f97f523cdab7501728ad0505e51435f727f6785/CloudObjects/SDK/NodeReader.php#L221-L229 |
2,462 | CloudObjects/CloudObjects-PHP-SDK | CloudObjects/SDK/NodeReader.php | NodeReader.getAllValuesNode | public function getAllValuesNode(Node $node = null, $property) {
$allValues = $this->getAllValues($node, $property);
$output = [];
foreach ($allValues as $a)
if (is_a($a, 'ML\JsonLD\Node'))
$output[] = $a;
return $output;
} | php | public function getAllValuesNode(Node $node = null, $property) {
$allValues = $this->getAllValues($node, $property);
$output = [];
foreach ($allValues as $a)
if (is_a($a, 'ML\JsonLD\Node'))
$output[] = $a;
return $output;
} | [
"public",
"function",
"getAllValuesNode",
"(",
"Node",
"$",
"node",
"=",
"null",
",",
"$",
"property",
")",
"{",
"$",
"allValues",
"=",
"$",
"this",
"->",
"getAllValues",
"(",
"$",
"node",
",",
"$",
"property",
")",
";",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"allValues",
"as",
"$",
"a",
")",
"if",
"(",
"is_a",
"(",
"$",
"a",
",",
"'ML\\JsonLD\\Node'",
")",
")",
"$",
"output",
"[",
"]",
"=",
"$",
"a",
";",
"return",
"$",
"output",
";",
"}"
] | Reads all values from a node and returns them as a Node array.
Returns only nodes, literal values are skipped.
@param Node $node The node to work on.
@param string|object $property The property to read.
@return array<Node> | [
"Reads",
"all",
"values",
"from",
"a",
"node",
"and",
"returns",
"them",
"as",
"a",
"Node",
"array",
".",
"Returns",
"only",
"nodes",
"literal",
"values",
"are",
"skipped",
"."
] | 4f97f523cdab7501728ad0505e51435f727f6785 | https://github.com/CloudObjects/CloudObjects-PHP-SDK/blob/4f97f523cdab7501728ad0505e51435f727f6785/CloudObjects/SDK/NodeReader.php#L239-L247 |
2,463 | gubler/collection | src/Helper.php | Helper.append_config | public static function append_config(array $array): array
{
$start = 9999;
foreach ($array as $key => $value) {
if (is_numeric($key)) {
$start++;
$array[$start] = Arr::pull($array, $key);
}
}
return $array;
} | php | public static function append_config(array $array): array
{
$start = 9999;
foreach ($array as $key => $value) {
if (is_numeric($key)) {
$start++;
$array[$start] = Arr::pull($array, $key);
}
}
return $array;
} | [
"public",
"static",
"function",
"append_config",
"(",
"array",
"$",
"array",
")",
":",
"array",
"{",
"$",
"start",
"=",
"9999",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"key",
")",
")",
"{",
"$",
"start",
"++",
";",
"$",
"array",
"[",
"$",
"start",
"]",
"=",
"Arr",
"::",
"pull",
"(",
"$",
"array",
",",
"$",
"key",
")",
";",
"}",
"}",
"return",
"$",
"array",
";",
"}"
] | Assign high numeric IDs to a config item to force appending.
@param array $array
@return array | [
"Assign",
"high",
"numeric",
"IDs",
"to",
"a",
"config",
"item",
"to",
"force",
"appending",
"."
] | 8af2e0478f78b0fe0fbac7437f3f94f01de307b8 | https://github.com/gubler/collection/blob/8af2e0478f78b0fe0fbac7437f3f94f01de307b8/src/Helper.php#L19-L32 |
2,464 | gubler/collection | src/Helper.php | Helper.class_uses_recursive | public static function class_uses_recursive($class)
{
if (\is_object($class)) {
$class = \get_class($class);
}
$results = [];
foreach (array_reverse(class_parents($class)) + [$class => $class] as $class) {
$results += self::trait_uses_recursive($class);
}
return array_unique($results);
} | php | public static function class_uses_recursive($class)
{
if (\is_object($class)) {
$class = \get_class($class);
}
$results = [];
foreach (array_reverse(class_parents($class)) + [$class => $class] as $class) {
$results += self::trait_uses_recursive($class);
}
return array_unique($results);
} | [
"public",
"static",
"function",
"class_uses_recursive",
"(",
"$",
"class",
")",
"{",
"if",
"(",
"\\",
"is_object",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class",
"=",
"\\",
"get_class",
"(",
"$",
"class",
")",
";",
"}",
"$",
"results",
"=",
"[",
"]",
";",
"foreach",
"(",
"array_reverse",
"(",
"class_parents",
"(",
"$",
"class",
")",
")",
"+",
"[",
"$",
"class",
"=>",
"$",
"class",
"]",
"as",
"$",
"class",
")",
"{",
"$",
"results",
"+=",
"self",
"::",
"trait_uses_recursive",
"(",
"$",
"class",
")",
";",
"}",
"return",
"array_unique",
"(",
"$",
"results",
")",
";",
"}"
] | Returns all traits used by a class, its parent classes and trait of their traits.
@param object|string $class
@return array | [
"Returns",
"all",
"traits",
"used",
"by",
"a",
"class",
"its",
"parent",
"classes",
"and",
"trait",
"of",
"their",
"traits",
"."
] | 8af2e0478f78b0fe0fbac7437f3f94f01de307b8 | https://github.com/gubler/collection/blob/8af2e0478f78b0fe0fbac7437f3f94f01de307b8/src/Helper.php#L80-L93 |
2,465 | gubler/collection | src/Helper.php | Helper.data_fill | public static function data_fill(&$target, $key, $value)
{
return self::data_set($target, $key, $value, false);
} | php | public static function data_fill(&$target, $key, $value)
{
return self::data_set($target, $key, $value, false);
} | [
"public",
"static",
"function",
"data_fill",
"(",
"&",
"$",
"target",
",",
"$",
"key",
",",
"$",
"value",
")",
"{",
"return",
"self",
"::",
"data_set",
"(",
"$",
"target",
",",
"$",
"key",
",",
"$",
"value",
",",
"false",
")",
";",
"}"
] | Fill in data where it's missing.
@param mixed $target
@param string|array $key
@param mixed $value
@return mixed | [
"Fill",
"in",
"data",
"where",
"it",
"s",
"missing",
"."
] | 8af2e0478f78b0fe0fbac7437f3f94f01de307b8 | https://github.com/gubler/collection/blob/8af2e0478f78b0fe0fbac7437f3f94f01de307b8/src/Helper.php#L103-L106 |
2,466 | gubler/collection | src/Helper.php | Helper.data_set | public static function data_set(&$target, $key, $value, $overwrite = true)
{
$segments = \is_array($key) ? $key : explode('.', $key);
if (($segment = array_shift($segments)) === '*') {
if (! Arr::accessible($target)) {
$target = [];
}
if ($segments) {
foreach ($target as &$inner) {
self::data_set($inner, $segments, $value, $overwrite);
}
} elseif ($overwrite) {
foreach ($target as &$inner) {
$inner = $value;
}
}
} elseif (Arr::accessible($target)) {
if ($segments) {
if (! Arr::exists($target, $segment)) {
$target[$segment] = [];
}
self::data_set($target[$segment], $segments, $value, $overwrite);
} elseif ($overwrite || ! Arr::exists($target, $segment)) {
$target[$segment] = $value;
}
} elseif (\is_object($target)) {
if ($segments) {
if (! isset($target->{$segment})) {
$target->{$segment} = [];
}
self::data_set($target->{$segment}, $segments, $value, $overwrite);
} elseif ($overwrite || ! isset($target->{$segment})) {
$target->{$segment} = $value;
}
} else {
$target = [];
if ($segments) {
self::data_set($target[$segment], $segments, $value, $overwrite);
} elseif ($overwrite) {
$target[$segment] = $value;
}
}
return $target;
} | php | public static function data_set(&$target, $key, $value, $overwrite = true)
{
$segments = \is_array($key) ? $key : explode('.', $key);
if (($segment = array_shift($segments)) === '*') {
if (! Arr::accessible($target)) {
$target = [];
}
if ($segments) {
foreach ($target as &$inner) {
self::data_set($inner, $segments, $value, $overwrite);
}
} elseif ($overwrite) {
foreach ($target as &$inner) {
$inner = $value;
}
}
} elseif (Arr::accessible($target)) {
if ($segments) {
if (! Arr::exists($target, $segment)) {
$target[$segment] = [];
}
self::data_set($target[$segment], $segments, $value, $overwrite);
} elseif ($overwrite || ! Arr::exists($target, $segment)) {
$target[$segment] = $value;
}
} elseif (\is_object($target)) {
if ($segments) {
if (! isset($target->{$segment})) {
$target->{$segment} = [];
}
self::data_set($target->{$segment}, $segments, $value, $overwrite);
} elseif ($overwrite || ! isset($target->{$segment})) {
$target->{$segment} = $value;
}
} else {
$target = [];
if ($segments) {
self::data_set($target[$segment], $segments, $value, $overwrite);
} elseif ($overwrite) {
$target[$segment] = $value;
}
}
return $target;
} | [
"public",
"static",
"function",
"data_set",
"(",
"&",
"$",
"target",
",",
"$",
"key",
",",
"$",
"value",
",",
"$",
"overwrite",
"=",
"true",
")",
"{",
"$",
"segments",
"=",
"\\",
"is_array",
"(",
"$",
"key",
")",
"?",
"$",
"key",
":",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"if",
"(",
"(",
"$",
"segment",
"=",
"array_shift",
"(",
"$",
"segments",
")",
")",
"===",
"'*'",
")",
"{",
"if",
"(",
"!",
"Arr",
"::",
"accessible",
"(",
"$",
"target",
")",
")",
"{",
"$",
"target",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"$",
"segments",
")",
"{",
"foreach",
"(",
"$",
"target",
"as",
"&",
"$",
"inner",
")",
"{",
"self",
"::",
"data_set",
"(",
"$",
"inner",
",",
"$",
"segments",
",",
"$",
"value",
",",
"$",
"overwrite",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"overwrite",
")",
"{",
"foreach",
"(",
"$",
"target",
"as",
"&",
"$",
"inner",
")",
"{",
"$",
"inner",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"elseif",
"(",
"Arr",
"::",
"accessible",
"(",
"$",
"target",
")",
")",
"{",
"if",
"(",
"$",
"segments",
")",
"{",
"if",
"(",
"!",
"Arr",
"::",
"exists",
"(",
"$",
"target",
",",
"$",
"segment",
")",
")",
"{",
"$",
"target",
"[",
"$",
"segment",
"]",
"=",
"[",
"]",
";",
"}",
"self",
"::",
"data_set",
"(",
"$",
"target",
"[",
"$",
"segment",
"]",
",",
"$",
"segments",
",",
"$",
"value",
",",
"$",
"overwrite",
")",
";",
"}",
"elseif",
"(",
"$",
"overwrite",
"||",
"!",
"Arr",
"::",
"exists",
"(",
"$",
"target",
",",
"$",
"segment",
")",
")",
"{",
"$",
"target",
"[",
"$",
"segment",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"elseif",
"(",
"\\",
"is_object",
"(",
"$",
"target",
")",
")",
"{",
"if",
"(",
"$",
"segments",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"target",
"->",
"{",
"$",
"segment",
"}",
")",
")",
"{",
"$",
"target",
"->",
"{",
"$",
"segment",
"}",
"=",
"[",
"]",
";",
"}",
"self",
"::",
"data_set",
"(",
"$",
"target",
"->",
"{",
"$",
"segment",
"}",
",",
"$",
"segments",
",",
"$",
"value",
",",
"$",
"overwrite",
")",
";",
"}",
"elseif",
"(",
"$",
"overwrite",
"||",
"!",
"isset",
"(",
"$",
"target",
"->",
"{",
"$",
"segment",
"}",
")",
")",
"{",
"$",
"target",
"->",
"{",
"$",
"segment",
"}",
"=",
"$",
"value",
";",
"}",
"}",
"else",
"{",
"$",
"target",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"segments",
")",
"{",
"self",
"::",
"data_set",
"(",
"$",
"target",
"[",
"$",
"segment",
"]",
",",
"$",
"segments",
",",
"$",
"value",
",",
"$",
"overwrite",
")",
";",
"}",
"elseif",
"(",
"$",
"overwrite",
")",
"{",
"$",
"target",
"[",
"$",
"segment",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"target",
";",
"}"
] | Set an item on an array or object using dot notation.
@param mixed $target
@param string|array $key
@param mixed $value
@param bool $overwrite
@return mixed | [
"Set",
"an",
"item",
"on",
"an",
"array",
"or",
"object",
"using",
"dot",
"notation",
"."
] | 8af2e0478f78b0fe0fbac7437f3f94f01de307b8 | https://github.com/gubler/collection/blob/8af2e0478f78b0fe0fbac7437f3f94f01de307b8/src/Helper.php#L158-L207 |
2,467 | gubler/collection | src/Helper.php | Helper.object_get | public static function object_get($object, $key, $default = null)
{
if (\is_null($key) || trim($key) === '') {
return $object;
}
foreach (explode('.', $key) as $segment) {
if (! \is_object($object) || ! isset($object->{$segment})) {
return self::value($default);
}
$object = $object->{$segment};
}
return $object;
} | php | public static function object_get($object, $key, $default = null)
{
if (\is_null($key) || trim($key) === '') {
return $object;
}
foreach (explode('.', $key) as $segment) {
if (! \is_object($object) || ! isset($object->{$segment})) {
return self::value($default);
}
$object = $object->{$segment};
}
return $object;
} | [
"public",
"static",
"function",
"object_get",
"(",
"$",
"object",
",",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"\\",
"is_null",
"(",
"$",
"key",
")",
"||",
"trim",
"(",
"$",
"key",
")",
"===",
"''",
")",
"{",
"return",
"$",
"object",
";",
"}",
"foreach",
"(",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
"as",
"$",
"segment",
")",
"{",
"if",
"(",
"!",
"\\",
"is_object",
"(",
"$",
"object",
")",
"||",
"!",
"isset",
"(",
"$",
"object",
"->",
"{",
"$",
"segment",
"}",
")",
")",
"{",
"return",
"self",
"::",
"value",
"(",
"$",
"default",
")",
";",
"}",
"$",
"object",
"=",
"$",
"object",
"->",
"{",
"$",
"segment",
"}",
";",
"}",
"return",
"$",
"object",
";",
"}"
] | Get an item from an object using "dot" notation.
@param object $object
@param string $key
@param mixed $default
@return mixed | [
"Get",
"an",
"item",
"from",
"an",
"object",
"using",
"dot",
"notation",
"."
] | 8af2e0478f78b0fe0fbac7437f3f94f01de307b8 | https://github.com/gubler/collection/blob/8af2e0478f78b0fe0fbac7437f3f94f01de307b8/src/Helper.php#L250-L265 |
2,468 | gubler/collection | src/Helper.php | Helper.preg_replace_array | public static function preg_replace_array($pattern, array $replacements, $subject)
{
return preg_replace_callback($pattern, function () use (&$replacements) {
foreach ($replacements as $key => $value) {
return array_shift($replacements);
}
}, $subject);
} | php | public static function preg_replace_array($pattern, array $replacements, $subject)
{
return preg_replace_callback($pattern, function () use (&$replacements) {
foreach ($replacements as $key => $value) {
return array_shift($replacements);
}
}, $subject);
} | [
"public",
"static",
"function",
"preg_replace_array",
"(",
"$",
"pattern",
",",
"array",
"$",
"replacements",
",",
"$",
"subject",
")",
"{",
"return",
"preg_replace_callback",
"(",
"$",
"pattern",
",",
"function",
"(",
")",
"use",
"(",
"&",
"$",
"replacements",
")",
"{",
"foreach",
"(",
"$",
"replacements",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"return",
"array_shift",
"(",
"$",
"replacements",
")",
";",
"}",
"}",
",",
"$",
"subject",
")",
";",
"}"
] | Replace a given pattern with each value in the array in sequentially.
@param string $pattern
@param array $replacements
@param string $subject
@return string | [
"Replace",
"a",
"given",
"pattern",
"with",
"each",
"value",
"in",
"the",
"array",
"in",
"sequentially",
"."
] | 8af2e0478f78b0fe0fbac7437f3f94f01de307b8 | https://github.com/gubler/collection/blob/8af2e0478f78b0fe0fbac7437f3f94f01de307b8/src/Helper.php#L275-L282 |
2,469 | gubler/collection | src/Helper.php | Helper.retry | public static function retry($times, callable $callback, $sleep = 0)
{
$times--;
beginning:
try {
return $callback();
} catch (\Exception $e) {
if (! $times) {
throw $e;
}
$times--;
if ($sleep) {
usleep($sleep * 1000);
}
goto beginning;
}
} | php | public static function retry($times, callable $callback, $sleep = 0)
{
$times--;
beginning:
try {
return $callback();
} catch (\Exception $e) {
if (! $times) {
throw $e;
}
$times--;
if ($sleep) {
usleep($sleep * 1000);
}
goto beginning;
}
} | [
"public",
"static",
"function",
"retry",
"(",
"$",
"times",
",",
"callable",
"$",
"callback",
",",
"$",
"sleep",
"=",
"0",
")",
"{",
"$",
"times",
"--",
";",
"beginning",
":",
"try",
"{",
"return",
"$",
"callback",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"!",
"$",
"times",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"$",
"times",
"--",
";",
"if",
"(",
"$",
"sleep",
")",
"{",
"usleep",
"(",
"$",
"sleep",
"*",
"1000",
")",
";",
"}",
"goto",
"beginning",
";",
"}",
"}"
] | Retry an operation a given number of times.
@param int $times
@param callable $callback
@param int $sleep
@return mixed
@throws \Exception | [
"Retry",
"an",
"operation",
"a",
"given",
"number",
"of",
"times",
"."
] | 8af2e0478f78b0fe0fbac7437f3f94f01de307b8 | https://github.com/gubler/collection/blob/8af2e0478f78b0fe0fbac7437f3f94f01de307b8/src/Helper.php#L294-L314 |
2,470 | gubler/collection | src/Helper.php | Helper.throw_if | public static function throw_if($condition, $exception, ...$parameters)
{
if ($condition) {
throw (\is_string($exception) ? new $exception(...$parameters) : $exception);
}
return $condition;
} | php | public static function throw_if($condition, $exception, ...$parameters)
{
if ($condition) {
throw (\is_string($exception) ? new $exception(...$parameters) : $exception);
}
return $condition;
} | [
"public",
"static",
"function",
"throw_if",
"(",
"$",
"condition",
",",
"$",
"exception",
",",
"...",
"$",
"parameters",
")",
"{",
"if",
"(",
"$",
"condition",
")",
"{",
"throw",
"(",
"\\",
"is_string",
"(",
"$",
"exception",
")",
"?",
"new",
"$",
"exception",
"(",
"...",
"$",
"parameters",
")",
":",
"$",
"exception",
")",
";",
"}",
"return",
"$",
"condition",
";",
"}"
] | Throw the given exception if the given condition is true.
@param mixed $condition
@param \Throwable|string $exception
@param array ...$parameters
@return mixed
@throws \Throwable | [
"Throw",
"the",
"given",
"exception",
"if",
"the",
"given",
"condition",
"is",
"true",
"."
] | 8af2e0478f78b0fe0fbac7437f3f94f01de307b8 | https://github.com/gubler/collection/blob/8af2e0478f78b0fe0fbac7437f3f94f01de307b8/src/Helper.php#L325-L332 |
2,471 | gubler/collection | src/Helper.php | Helper.throw_unless | public static function throw_unless($condition, $exception, ...$parameters)
{
if (! $condition) {
throw (\is_string($exception) ? new $exception(...$parameters) : $exception);
}
return $condition;
} | php | public static function throw_unless($condition, $exception, ...$parameters)
{
if (! $condition) {
throw (\is_string($exception) ? new $exception(...$parameters) : $exception);
}
return $condition;
} | [
"public",
"static",
"function",
"throw_unless",
"(",
"$",
"condition",
",",
"$",
"exception",
",",
"...",
"$",
"parameters",
")",
"{",
"if",
"(",
"!",
"$",
"condition",
")",
"{",
"throw",
"(",
"\\",
"is_string",
"(",
"$",
"exception",
")",
"?",
"new",
"$",
"exception",
"(",
"...",
"$",
"parameters",
")",
":",
"$",
"exception",
")",
";",
"}",
"return",
"$",
"condition",
";",
"}"
] | Throw the given exception unless the given condition is true.
@param mixed $condition
@param \Throwable|string $exception
@param array ...$parameters
@return mixed
@throws \Throwable | [
"Throw",
"the",
"given",
"exception",
"unless",
"the",
"given",
"condition",
"is",
"true",
"."
] | 8af2e0478f78b0fe0fbac7437f3f94f01de307b8 | https://github.com/gubler/collection/blob/8af2e0478f78b0fe0fbac7437f3f94f01de307b8/src/Helper.php#L343-L350 |
2,472 | gubler/collection | src/Helper.php | Helper.transform | public static function transform($value, callable $callback, $default = null)
{
if (self::filled($value)) {
return $callback($value);
}
if (\is_callable($default)) {
return $default($value);
}
return $default;
} | php | public static function transform($value, callable $callback, $default = null)
{
if (self::filled($value)) {
return $callback($value);
}
if (\is_callable($default)) {
return $default($value);
}
return $default;
} | [
"public",
"static",
"function",
"transform",
"(",
"$",
"value",
",",
"callable",
"$",
"callback",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"self",
"::",
"filled",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"callback",
"(",
"$",
"value",
")",
";",
"}",
"if",
"(",
"\\",
"is_callable",
"(",
"$",
"default",
")",
")",
"{",
"return",
"$",
"default",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"default",
";",
"}"
] | Transform the given value if it is present.
@param mixed $value
@param callable $callback
@param mixed $default
@return mixed|null | [
"Transform",
"the",
"given",
"value",
"if",
"it",
"is",
"present",
"."
] | 8af2e0478f78b0fe0fbac7437f3f94f01de307b8 | https://github.com/gubler/collection/blob/8af2e0478f78b0fe0fbac7437f3f94f01de307b8/src/Helper.php#L377-L388 |
2,473 | jeronimos/php-adjutants | src/Arrays/Sort.php | Sort.getMostFrequentValues | public static function getMostFrequentValues(array $data, $mostFrequentQuantity = NULL, $allocationPeriod = NULL)
{
$mostFrequentValues = [];
$allocatedData = self::allocateInfo($data, $allocationPeriod);
usort($allocatedData, function ($a, $b) {
if ($a->getValueQuantity() === $b->getValueQuantity()) {
if ($a->getValue() === $b->getValueQuantity()) {
return 0;
}
return ($a->getValue() < $b->getValue()) ? -1 : 1;
} else {
return ($a->getValueQuantity() > $b->getValueQuantity()) ? -1 : 1;
}
});
if (!$mostFrequentQuantity) {
$mostFrequentQuantity = self::MOST_FREQUENT_QUANTITY;
}
for ($i = 0; $i < $mostFrequentQuantity; $i++) {
$frequentValue = new SortData();
$frequentValue->setValue($allocatedData[$i]->getValue());
$frequentValue->setValueQuantity($allocatedData[$i]->getValueQuantity());
$valueExamples = ($allocatedData[$i]->getValueExamples() !== "")
? substr($allocatedData[$i]->getValueExamples(), 0, -2)
: $allocatedData[$i]->getValueExamples();
$frequentValue->setValueExamples($valueExamples);
if ($mostFrequentQuantity === 1) {
$mostFrequentValues = $frequentValue;
} else {
$mostFrequentValues[] = $frequentValue;
}
}
return $mostFrequentValues;
} | php | public static function getMostFrequentValues(array $data, $mostFrequentQuantity = NULL, $allocationPeriod = NULL)
{
$mostFrequentValues = [];
$allocatedData = self::allocateInfo($data, $allocationPeriod);
usort($allocatedData, function ($a, $b) {
if ($a->getValueQuantity() === $b->getValueQuantity()) {
if ($a->getValue() === $b->getValueQuantity()) {
return 0;
}
return ($a->getValue() < $b->getValue()) ? -1 : 1;
} else {
return ($a->getValueQuantity() > $b->getValueQuantity()) ? -1 : 1;
}
});
if (!$mostFrequentQuantity) {
$mostFrequentQuantity = self::MOST_FREQUENT_QUANTITY;
}
for ($i = 0; $i < $mostFrequentQuantity; $i++) {
$frequentValue = new SortData();
$frequentValue->setValue($allocatedData[$i]->getValue());
$frequentValue->setValueQuantity($allocatedData[$i]->getValueQuantity());
$valueExamples = ($allocatedData[$i]->getValueExamples() !== "")
? substr($allocatedData[$i]->getValueExamples(), 0, -2)
: $allocatedData[$i]->getValueExamples();
$frequentValue->setValueExamples($valueExamples);
if ($mostFrequentQuantity === 1) {
$mostFrequentValues = $frequentValue;
} else {
$mostFrequentValues[] = $frequentValue;
}
}
return $mostFrequentValues;
} | [
"public",
"static",
"function",
"getMostFrequentValues",
"(",
"array",
"$",
"data",
",",
"$",
"mostFrequentQuantity",
"=",
"NULL",
",",
"$",
"allocationPeriod",
"=",
"NULL",
")",
"{",
"$",
"mostFrequentValues",
"=",
"[",
"]",
";",
"$",
"allocatedData",
"=",
"self",
"::",
"allocateInfo",
"(",
"$",
"data",
",",
"$",
"allocationPeriod",
")",
";",
"usort",
"(",
"$",
"allocatedData",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"if",
"(",
"$",
"a",
"->",
"getValueQuantity",
"(",
")",
"===",
"$",
"b",
"->",
"getValueQuantity",
"(",
")",
")",
"{",
"if",
"(",
"$",
"a",
"->",
"getValue",
"(",
")",
"===",
"$",
"b",
"->",
"getValueQuantity",
"(",
")",
")",
"{",
"return",
"0",
";",
"}",
"return",
"(",
"$",
"a",
"->",
"getValue",
"(",
")",
"<",
"$",
"b",
"->",
"getValue",
"(",
")",
")",
"?",
"-",
"1",
":",
"1",
";",
"}",
"else",
"{",
"return",
"(",
"$",
"a",
"->",
"getValueQuantity",
"(",
")",
">",
"$",
"b",
"->",
"getValueQuantity",
"(",
")",
")",
"?",
"-",
"1",
":",
"1",
";",
"}",
"}",
")",
";",
"if",
"(",
"!",
"$",
"mostFrequentQuantity",
")",
"{",
"$",
"mostFrequentQuantity",
"=",
"self",
"::",
"MOST_FREQUENT_QUANTITY",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"mostFrequentQuantity",
";",
"$",
"i",
"++",
")",
"{",
"$",
"frequentValue",
"=",
"new",
"SortData",
"(",
")",
";",
"$",
"frequentValue",
"->",
"setValue",
"(",
"$",
"allocatedData",
"[",
"$",
"i",
"]",
"->",
"getValue",
"(",
")",
")",
";",
"$",
"frequentValue",
"->",
"setValueQuantity",
"(",
"$",
"allocatedData",
"[",
"$",
"i",
"]",
"->",
"getValueQuantity",
"(",
")",
")",
";",
"$",
"valueExamples",
"=",
"(",
"$",
"allocatedData",
"[",
"$",
"i",
"]",
"->",
"getValueExamples",
"(",
")",
"!==",
"\"\"",
")",
"?",
"substr",
"(",
"$",
"allocatedData",
"[",
"$",
"i",
"]",
"->",
"getValueExamples",
"(",
")",
",",
"0",
",",
"-",
"2",
")",
":",
"$",
"allocatedData",
"[",
"$",
"i",
"]",
"->",
"getValueExamples",
"(",
")",
";",
"$",
"frequentValue",
"->",
"setValueExamples",
"(",
"$",
"valueExamples",
")",
";",
"if",
"(",
"$",
"mostFrequentQuantity",
"===",
"1",
")",
"{",
"$",
"mostFrequentValues",
"=",
"$",
"frequentValue",
";",
"}",
"else",
"{",
"$",
"mostFrequentValues",
"[",
"]",
"=",
"$",
"frequentValue",
";",
"}",
"}",
"return",
"$",
"mostFrequentValues",
";",
"}"
] | Allow to sort array with SortData elements.
@param array $data
@param null $mostFrequentQuantity
@return SortData|array
@throws \Exception | [
"Allow",
"to",
"sort",
"array",
"with",
"SortData",
"elements",
"."
] | 78b428ed05a9d6029a29a86ac47906adeb9fd41d | https://github.com/jeronimos/php-adjutants/blob/78b428ed05a9d6029a29a86ac47906adeb9fd41d/src/Arrays/Sort.php#L24-L66 |
2,474 | amilna/yap | GridView.php | GridView.renderExtraRow | protected function renderExtraRow($model, $key, $index, $totals)
{
if ($this->extraRowValue instanceof Closure) {
$content = call_user_func($this->extraRowValue, $model, $index, $totals);
} else {
$values = [];
foreach ($this->extraRowColumns as $name) {
$values[] = ArrayHelper::getValue($model, $name);
}
$content = '<strong>' . implode(' :: ', $values) . '</strong>';
}
$colspan = count($this->columns);
$cell = Html::tag('td', $content, ['class' => $this->extraRowClass, 'colspan' => $colspan]);
return Html::tag('tr', $cell);
} | php | protected function renderExtraRow($model, $key, $index, $totals)
{
if ($this->extraRowValue instanceof Closure) {
$content = call_user_func($this->extraRowValue, $model, $index, $totals);
} else {
$values = [];
foreach ($this->extraRowColumns as $name) {
$values[] = ArrayHelper::getValue($model, $name);
}
$content = '<strong>' . implode(' :: ', $values) . '</strong>';
}
$colspan = count($this->columns);
$cell = Html::tag('td', $content, ['class' => $this->extraRowClass, 'colspan' => $colspan]);
return Html::tag('tr', $cell);
} | [
"protected",
"function",
"renderExtraRow",
"(",
"$",
"model",
",",
"$",
"key",
",",
"$",
"index",
",",
"$",
"totals",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"extraRowValue",
"instanceof",
"Closure",
")",
"{",
"$",
"content",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"extraRowValue",
",",
"$",
"model",
",",
"$",
"index",
",",
"$",
"totals",
")",
";",
"}",
"else",
"{",
"$",
"values",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"extraRowColumns",
"as",
"$",
"name",
")",
"{",
"$",
"values",
"[",
"]",
"=",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"model",
",",
"$",
"name",
")",
";",
"}",
"$",
"content",
"=",
"'<strong>'",
".",
"implode",
"(",
"' :: '",
",",
"$",
"values",
")",
".",
"'</strong>'",
";",
"}",
"$",
"colspan",
"=",
"count",
"(",
"$",
"this",
"->",
"columns",
")",
";",
"$",
"cell",
"=",
"Html",
"::",
"tag",
"(",
"'td'",
",",
"$",
"content",
",",
"[",
"'class'",
"=>",
"$",
"this",
"->",
"extraRowClass",
",",
"'colspan'",
"=>",
"$",
"colspan",
"]",
")",
";",
"return",
"Html",
"::",
"tag",
"(",
"'tr'",
",",
"$",
"cell",
")",
";",
"}"
] | Renders extra row when required
@param mixed $model
@param mixed $key
@param int $index
@param number $totals
@return string the extra row | [
"Renders",
"extra",
"row",
"when",
"required"
] | 24a9e7115cb92055b4c5e78c63a4a7d4f962004a | https://github.com/amilna/yap/blob/24a9e7115cb92055b4c5e78c63a4a7d4f962004a/GridView.php#L267-L285 |
2,475 | amilna/yap | GridView.php | GridView.isGroupEdge | protected function isGroupEdge($name, $row)
{
$result = array();
foreach ($this->_groups[$name] as $column) {
if ($column['start'] == $row) {
$result['start'] = $row;
$result['group'] = $column;
}
if ($column['end'] == $row) {
$result['end'] = $row;
$result['group'] = $column;
}
if (count($result)) break;
}
return $result;
} | php | protected function isGroupEdge($name, $row)
{
$result = array();
foreach ($this->_groups[$name] as $column) {
if ($column['start'] == $row) {
$result['start'] = $row;
$result['group'] = $column;
}
if ($column['end'] == $row) {
$result['end'] = $row;
$result['group'] = $column;
}
if (count($result)) break;
}
return $result;
} | [
"protected",
"function",
"isGroupEdge",
"(",
"$",
"name",
",",
"$",
"row",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"_groups",
"[",
"$",
"name",
"]",
"as",
"$",
"column",
")",
"{",
"if",
"(",
"$",
"column",
"[",
"'start'",
"]",
"==",
"$",
"row",
")",
"{",
"$",
"result",
"[",
"'start'",
"]",
"=",
"$",
"row",
";",
"$",
"result",
"[",
"'group'",
"]",
"=",
"$",
"column",
";",
"}",
"if",
"(",
"$",
"column",
"[",
"'end'",
"]",
"==",
"$",
"row",
")",
"{",
"$",
"result",
"[",
"'end'",
"]",
"=",
"$",
"row",
";",
"$",
"result",
"[",
"'group'",
"]",
"=",
"$",
"column",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"result",
")",
")",
"break",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Is current row start or end of group in particular column
@param string $name the column name
@param int $row the row index
@return array | [
"Is",
"current",
"row",
"start",
"or",
"end",
"of",
"group",
"in",
"particular",
"column"
] | 24a9e7115cb92055b4c5e78c63a4a7d4f962004a | https://github.com/amilna/yap/blob/24a9e7115cb92055b4c5e78c63a4a7d4f962004a/GridView.php#L293-L308 |
2,476 | amilna/yap | GridView.php | GridView.getExtraRowTotals | protected function getExtraRowTotals($model, $index, $totals)
{
return $this->extraRowTotalsValue instanceof Closure
? call_user_func($this->extraRowTotalsValue, $model, $index, $totals)
: [];
} | php | protected function getExtraRowTotals($model, $index, $totals)
{
return $this->extraRowTotalsValue instanceof Closure
? call_user_func($this->extraRowTotalsValue, $model, $index, $totals)
: [];
} | [
"protected",
"function",
"getExtraRowTotals",
"(",
"$",
"model",
",",
"$",
"index",
",",
"$",
"totals",
")",
"{",
"return",
"$",
"this",
"->",
"extraRowTotalsValue",
"instanceof",
"Closure",
"?",
"call_user_func",
"(",
"$",
"this",
"->",
"extraRowTotalsValue",
",",
"$",
"model",
",",
"$",
"index",
",",
"$",
"totals",
")",
":",
"[",
"]",
";",
"}"
] | If there is a Closure will return the newly calculated totals on the Closure according to the code specified by
the user.
@param mixed $model the data model being rendered
@param int $index the zero-based index of the data model among the models array
@param array $totals the calculated totals by the Closure
@return array|mixed | [
"If",
"there",
"is",
"a",
"Closure",
"will",
"return",
"the",
"newly",
"calculated",
"totals",
"on",
"the",
"Closure",
"according",
"to",
"the",
"code",
"specified",
"by",
"the",
"user",
"."
] | 24a9e7115cb92055b4c5e78c63a4a7d4f962004a | https://github.com/amilna/yap/blob/24a9e7115cb92055b4c5e78c63a4a7d4f962004a/GridView.php#L318-L323 |
2,477 | amilna/yap | GridView.php | GridView.getRowValues | protected function getRowValues($columns, $model, $index = 0)
{
$values = [];
$keys = $this->dataProvider->getKeys();
foreach ($columns as $column) {
/** @var \kartik\grid\DataColumn $column */
if ($column instanceof DataColumn) { // we only work with DataColumn types
$values[$column->attribute] = $this->getColumnDataCellContent($column, $model, $keys[$index], $index);
}
}
return $values;
} | php | protected function getRowValues($columns, $model, $index = 0)
{
$values = [];
$keys = $this->dataProvider->getKeys();
foreach ($columns as $column) {
/** @var \kartik\grid\DataColumn $column */
if ($column instanceof DataColumn) { // we only work with DataColumn types
$values[$column->attribute] = $this->getColumnDataCellContent($column, $model, $keys[$index], $index);
}
}
return $values;
} | [
"protected",
"function",
"getRowValues",
"(",
"$",
"columns",
",",
"$",
"model",
",",
"$",
"index",
"=",
"0",
")",
"{",
"$",
"values",
"=",
"[",
"]",
";",
"$",
"keys",
"=",
"$",
"this",
"->",
"dataProvider",
"->",
"getKeys",
"(",
")",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"column",
")",
"{",
"/** @var \\kartik\\grid\\DataColumn $column */",
"if",
"(",
"$",
"column",
"instanceof",
"DataColumn",
")",
"{",
"// we only work with DataColumn types",
"$",
"values",
"[",
"$",
"column",
"->",
"attribute",
"]",
"=",
"$",
"this",
"->",
"getColumnDataCellContent",
"(",
"$",
"column",
",",
"$",
"model",
",",
"$",
"keys",
"[",
"$",
"index",
"]",
",",
"$",
"index",
")",
";",
"}",
"}",
"return",
"$",
"values",
";",
"}"
] | Returns the row values of the column
@param array $columns the columns
@param mixed $model the model
@param int $index the zero-base index of the model among the models array
@return array | [
"Returns",
"the",
"row",
"values",
"of",
"the",
"column"
] | 24a9e7115cb92055b4c5e78c63a4a7d4f962004a | https://github.com/amilna/yap/blob/24a9e7115cb92055b4c5e78c63a4a7d4f962004a/GridView.php#L332-L344 |
2,478 | amilna/yap | GridView.php | GridView.getColumnDataCellContent | protected function getColumnDataCellContent($column, $model, $key, $index)
{
if ($column->content === null) {
return $this->formatter->format($this->getColumnDataCellValue($column, $model, $key, $index), $column->format);
} else {
if ($column->content !== null) {
return call_user_func($column->content, $model, $key, $index, $column);
} else {
return $this->emptyCell;
}
}
} | php | protected function getColumnDataCellContent($column, $model, $key, $index)
{
if ($column->content === null) {
return $this->formatter->format($this->getColumnDataCellValue($column, $model, $key, $index), $column->format);
} else {
if ($column->content !== null) {
return call_user_func($column->content, $model, $key, $index, $column);
} else {
return $this->emptyCell;
}
}
} | [
"protected",
"function",
"getColumnDataCellContent",
"(",
"$",
"column",
",",
"$",
"model",
",",
"$",
"key",
",",
"$",
"index",
")",
"{",
"if",
"(",
"$",
"column",
"->",
"content",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"formatter",
"->",
"format",
"(",
"$",
"this",
"->",
"getColumnDataCellValue",
"(",
"$",
"column",
",",
"$",
"model",
",",
"$",
"key",
",",
"$",
"index",
")",
",",
"$",
"column",
"->",
"format",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"column",
"->",
"content",
"!==",
"null",
")",
"{",
"return",
"call_user_func",
"(",
"$",
"column",
"->",
"content",
",",
"$",
"model",
",",
"$",
"key",
",",
"$",
"index",
",",
"$",
"column",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"emptyCell",
";",
"}",
"}",
"}"
] | Returns the column data cell content
@param \kartik\grid\DataColumn $column
@param mixed $model the data model being rendered
@param mixed $key the key associated with the data model
@param int $index the zero-based index of the data model among the models array returned by [[GridView::dataProvider]]
@return string the rendering result | [
"Returns",
"the",
"column",
"data",
"cell",
"content"
] | 24a9e7115cb92055b4c5e78c63a4a7d4f962004a | https://github.com/amilna/yap/blob/24a9e7115cb92055b4c5e78c63a4a7d4f962004a/GridView.php#L354-L365 |
2,479 | amilna/yap | GridView.php | GridView.getColumnDataCellValue | protected function getColumnDataCellValue($column, $model, $key, $index)
{
if ($column->value !== null) {
if (is_string($column->value)) {
return ArrayHelper::getValue($model, $column->value);
} else {
return call_user_func($column->value, $model, $index, $column);
}
} elseif ($column->attribute !== null) {
return ArrayHelper::getValue($model, $column->attribute);
}
return null;
} | php | protected function getColumnDataCellValue($column, $model, $key, $index)
{
if ($column->value !== null) {
if (is_string($column->value)) {
return ArrayHelper::getValue($model, $column->value);
} else {
return call_user_func($column->value, $model, $index, $column);
}
} elseif ($column->attribute !== null) {
return ArrayHelper::getValue($model, $column->attribute);
}
return null;
} | [
"protected",
"function",
"getColumnDataCellValue",
"(",
"$",
"column",
",",
"$",
"model",
",",
"$",
"key",
",",
"$",
"index",
")",
"{",
"if",
"(",
"$",
"column",
"->",
"value",
"!==",
"null",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"column",
"->",
"value",
")",
")",
"{",
"return",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"model",
",",
"$",
"column",
"->",
"value",
")",
";",
"}",
"else",
"{",
"return",
"call_user_func",
"(",
"$",
"column",
"->",
"value",
",",
"$",
"model",
",",
"$",
"index",
",",
"$",
"column",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"column",
"->",
"attribute",
"!==",
"null",
")",
"{",
"return",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"model",
",",
"$",
"column",
"->",
"attribute",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Returns the column data cell value
@param \kartik\grid\DataColumn $column
@param mixed $model the data model being rendered
@param mixed $key the key associated with the data model
@param int $index the zero-based index of the data model among the models array
@return mixed|null the result | [
"Returns",
"the",
"column",
"data",
"cell",
"value"
] | 24a9e7115cb92055b4c5e78c63a4a7d4f962004a | https://github.com/amilna/yap/blob/24a9e7115cb92055b4c5e78c63a4a7d4f962004a/GridView.php#L375-L387 |
2,480 | XTAIN/JoomlaBundle | Routing/UrlPatcher.php | UrlPatcher.overrideRouteTokens | public function overrideRouteTokens($name, &$tokens) {
$menu = $this->repository->findByViewRoute($name);
if (isset($menu)) {
# search the key for the first token with using 'text' as type
$key = array_search('text', array_column($tokens, 0));
# replace thwe path with the path from the menu, don't forget the beginning /
array_splice($tokens[$key], -1, 1, '/'.$menu->getPath());
return true;
}
return null;
} | php | public function overrideRouteTokens($name, &$tokens) {
$menu = $this->repository->findByViewRoute($name);
if (isset($menu)) {
# search the key for the first token with using 'text' as type
$key = array_search('text', array_column($tokens, 0));
# replace thwe path with the path from the menu, don't forget the beginning /
array_splice($tokens[$key], -1, 1, '/'.$menu->getPath());
return true;
}
return null;
} | [
"public",
"function",
"overrideRouteTokens",
"(",
"$",
"name",
",",
"&",
"$",
"tokens",
")",
"{",
"$",
"menu",
"=",
"$",
"this",
"->",
"repository",
"->",
"findByViewRoute",
"(",
"$",
"name",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"menu",
")",
")",
"{",
"# search the key for the first token with using 'text' as type",
"$",
"key",
"=",
"array_search",
"(",
"'text'",
",",
"array_column",
"(",
"$",
"tokens",
",",
"0",
")",
")",
";",
"# replace thwe path with the path from the menu, don't forget the beginning /",
"array_splice",
"(",
"$",
"tokens",
"[",
"$",
"key",
"]",
",",
"-",
"1",
",",
"1",
",",
"'/'",
".",
"$",
"menu",
"->",
"getPath",
"(",
")",
")",
";",
"return",
"true",
";",
"}",
"return",
"null",
";",
"}"
] | does overwrite the route tokens
does return true on success, or false if wrong route.
@author Hans Mackowiak <[email protected]>
@param string $name
@param array $tokens
@return null|string | [
"does",
"overwrite",
"the",
"route",
"tokens",
"does",
"return",
"true",
"on",
"success",
"or",
"false",
"if",
"wrong",
"route",
"."
] | 3d39e1278deba77c5a2197ad91973964ed2a38bd | https://github.com/XTAIN/JoomlaBundle/blob/3d39e1278deba77c5a2197ad91973964ed2a38bd/Routing/UrlPatcher.php#L49-L59 |
2,481 | synapsestudios/synapse-base | src/Synapse/View/AbstractView.php | AbstractView.template | protected function template()
{
$reflector = new \ReflectionClass(get_class($this));
$classname = $reflector->getName();
$template = preg_replace('/(Application|Synapse)\\\View\\\/', '', $classname);
$template = str_replace('\\', '/', $template);
return $template;
} | php | protected function template()
{
$reflector = new \ReflectionClass(get_class($this));
$classname = $reflector->getName();
$template = preg_replace('/(Application|Synapse)\\\View\\\/', '', $classname);
$template = str_replace('\\', '/', $template);
return $template;
} | [
"protected",
"function",
"template",
"(",
")",
"{",
"$",
"reflector",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"get_class",
"(",
"$",
"this",
")",
")",
";",
"$",
"classname",
"=",
"$",
"reflector",
"->",
"getName",
"(",
")",
";",
"$",
"template",
"=",
"preg_replace",
"(",
"'/(Application|Synapse)\\\\\\View\\\\\\/'",
",",
"''",
",",
"$",
"classname",
")",
";",
"$",
"template",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"template",
")",
";",
"return",
"$",
"template",
";",
"}"
] | Return the corresponding template file name for this class minus file extension
@return string | [
"Return",
"the",
"corresponding",
"template",
"file",
"name",
"for",
"this",
"class",
"minus",
"file",
"extension"
] | 60c830550491742a077ab063f924e2f0b63825da | https://github.com/synapsestudios/synapse-base/blob/60c830550491742a077ab063f924e2f0b63825da/src/Synapse/View/AbstractView.php#L46-L55 |
2,482 | dazarobbo/Cola | src/Enum.php | Enum.compareTo | public function compareTo($obj) {
if(!\is_a($obj, \get_called_class())){
throw new \RuntimeException('$obj is not a comparable instance');
}
if(\is_int($this->_Value) && \is_int($obj->_Value)){
return Number::compare($this->_Value, $obj->_Value);
}
else if(\is_string($this->_Value) && \is_string($obj->_Value)){
return \strcmp($this->_Value, $obj->_Value);
}
else{
throw new \RuntimeException('Incomparable types');
}
} | php | public function compareTo($obj) {
if(!\is_a($obj, \get_called_class())){
throw new \RuntimeException('$obj is not a comparable instance');
}
if(\is_int($this->_Value) && \is_int($obj->_Value)){
return Number::compare($this->_Value, $obj->_Value);
}
else if(\is_string($this->_Value) && \is_string($obj->_Value)){
return \strcmp($this->_Value, $obj->_Value);
}
else{
throw new \RuntimeException('Incomparable types');
}
} | [
"public",
"function",
"compareTo",
"(",
"$",
"obj",
")",
"{",
"if",
"(",
"!",
"\\",
"is_a",
"(",
"$",
"obj",
",",
"\\",
"get_called_class",
"(",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'$obj is not a comparable instance'",
")",
";",
"}",
"if",
"(",
"\\",
"is_int",
"(",
"$",
"this",
"->",
"_Value",
")",
"&&",
"\\",
"is_int",
"(",
"$",
"obj",
"->",
"_Value",
")",
")",
"{",
"return",
"Number",
"::",
"compare",
"(",
"$",
"this",
"->",
"_Value",
",",
"$",
"obj",
"->",
"_Value",
")",
";",
"}",
"else",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"this",
"->",
"_Value",
")",
"&&",
"\\",
"is_string",
"(",
"$",
"obj",
"->",
"_Value",
")",
")",
"{",
"return",
"\\",
"strcmp",
"(",
"$",
"this",
"->",
"_Value",
",",
"$",
"obj",
"->",
"_Value",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Incomparable types'",
")",
";",
"}",
"}"
] | Checks whether this enum's interval value matches another
@param static $obj
@return int
@throws \RuntimeException | [
"Checks",
"whether",
"this",
"enum",
"s",
"interval",
"value",
"matches",
"another"
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/Enum.php#L67-L83 |
2,483 | dazarobbo/Cola | src/Enum.php | Enum.fromName | public static function fromName($str){
$strName = \strtoupper(\trim($str));
foreach(static::getConstants() as $name => $value){
if($strName === \strtoupper($name)){
return new static($value);
}
}
return null;
} | php | public static function fromName($str){
$strName = \strtoupper(\trim($str));
foreach(static::getConstants() as $name => $value){
if($strName === \strtoupper($name)){
return new static($value);
}
}
return null;
} | [
"public",
"static",
"function",
"fromName",
"(",
"$",
"str",
")",
"{",
"$",
"strName",
"=",
"\\",
"strtoupper",
"(",
"\\",
"trim",
"(",
"$",
"str",
")",
")",
";",
"foreach",
"(",
"static",
"::",
"getConstants",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"strName",
"===",
"\\",
"strtoupper",
"(",
"$",
"name",
")",
")",
"{",
"return",
"new",
"static",
"(",
"$",
"value",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Creates a new enum from the case-insensitive name of a given
constant
@param string $str
@return \static | [
"Creates",
"a",
"new",
"enum",
"from",
"the",
"case",
"-",
"insensitive",
"name",
"of",
"a",
"given",
"constant"
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/Enum.php#L115-L127 |
2,484 | dazarobbo/Cola | src/Enum.php | Enum.getName | public function getName(){
foreach(static::getConstants() as $name => $value){
if($this->_Value === $value){
return $name;
}
}
return null;
} | php | public function getName(){
foreach(static::getConstants() as $name => $value){
if($this->_Value === $value){
return $name;
}
}
return null;
} | [
"public",
"function",
"getName",
"(",
")",
"{",
"foreach",
"(",
"static",
"::",
"getConstants",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_Value",
"===",
"$",
"value",
")",
"{",
"return",
"$",
"name",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Returns the name of the constant which matches the enum value
@return string | [
"Returns",
"the",
"name",
"of",
"the",
"constant",
"which",
"matches",
"the",
"enum",
"value"
] | b101b73ebeb8a571345a303cbc75168f60d0e64f | https://github.com/dazarobbo/Cola/blob/b101b73ebeb8a571345a303cbc75168f60d0e64f/src/Enum.php#L167-L177 |
2,485 | objectiveweb/auth | src/Auth.php | Auth.query | public function query($params = array(), $operator = "OR") {
$page = intval(@$params['page']);
$size = intval(@$params['size']);
$sort = @$params['sort'];
unset($params['page']);
unset($params['size']);
unset($params['sort']);
if(!$size) $size = 20;
$cond = array();
$bindings = array();
foreach($params as $key => $value) {
$cond[] = sprintf("`%s` %s :where_%s",
str_replace('`', '``', $key),
is_null($value) ? 'is' : (strpos($value, '%') !== FALSE ? 'LIKE' : '='),
$key);
$bindings[":where_$key"] = $value;
}
$query = sprintf(self::SELECT_SEARCH,
$this->params['table'],
empty($cond) ? '1=1' : implode(" $operator ", $cond)
);
$query .= sprintf(" LIMIT %d, %d", $page * $size, $size);
$stmt = $this->pdo->prepare($query);
$stmt->execute($bindings);
if(!$stmt) {
$error = $this->pdo->errorInfo();
throw new \Exception($error[2]);
}
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt = $this->pdo->query("SELECT FOUND_ROWS() as count");
$count = $stmt->fetch(PDO::FETCH_ASSOC);
if(!$count) {
throw new \Exception("Error fetching count");
}
$count = intval($count['count']);
return array(
'_embedded' => array(
$this->params['table'] => $data
),
'page' => array(
'size' => $size,
'number' => $page,
'totalElements' => $count,
'totalPages' => ceil($count/$size)
)
);
} | php | public function query($params = array(), $operator = "OR") {
$page = intval(@$params['page']);
$size = intval(@$params['size']);
$sort = @$params['sort'];
unset($params['page']);
unset($params['size']);
unset($params['sort']);
if(!$size) $size = 20;
$cond = array();
$bindings = array();
foreach($params as $key => $value) {
$cond[] = sprintf("`%s` %s :where_%s",
str_replace('`', '``', $key),
is_null($value) ? 'is' : (strpos($value, '%') !== FALSE ? 'LIKE' : '='),
$key);
$bindings[":where_$key"] = $value;
}
$query = sprintf(self::SELECT_SEARCH,
$this->params['table'],
empty($cond) ? '1=1' : implode(" $operator ", $cond)
);
$query .= sprintf(" LIMIT %d, %d", $page * $size, $size);
$stmt = $this->pdo->prepare($query);
$stmt->execute($bindings);
if(!$stmt) {
$error = $this->pdo->errorInfo();
throw new \Exception($error[2]);
}
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt = $this->pdo->query("SELECT FOUND_ROWS() as count");
$count = $stmt->fetch(PDO::FETCH_ASSOC);
if(!$count) {
throw new \Exception("Error fetching count");
}
$count = intval($count['count']);
return array(
'_embedded' => array(
$this->params['table'] => $data
),
'page' => array(
'size' => $size,
'number' => $page,
'totalElements' => $count,
'totalPages' => ceil($count/$size)
)
);
} | [
"public",
"function",
"query",
"(",
"$",
"params",
"=",
"array",
"(",
")",
",",
"$",
"operator",
"=",
"\"OR\"",
")",
"{",
"$",
"page",
"=",
"intval",
"(",
"@",
"$",
"params",
"[",
"'page'",
"]",
")",
";",
"$",
"size",
"=",
"intval",
"(",
"@",
"$",
"params",
"[",
"'size'",
"]",
")",
";",
"$",
"sort",
"=",
"@",
"$",
"params",
"[",
"'sort'",
"]",
";",
"unset",
"(",
"$",
"params",
"[",
"'page'",
"]",
")",
";",
"unset",
"(",
"$",
"params",
"[",
"'size'",
"]",
")",
";",
"unset",
"(",
"$",
"params",
"[",
"'sort'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"size",
")",
"$",
"size",
"=",
"20",
";",
"$",
"cond",
"=",
"array",
"(",
")",
";",
"$",
"bindings",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"cond",
"[",
"]",
"=",
"sprintf",
"(",
"\"`%s` %s :where_%s\"",
",",
"str_replace",
"(",
"'`'",
",",
"'``'",
",",
"$",
"key",
")",
",",
"is_null",
"(",
"$",
"value",
")",
"?",
"'is'",
":",
"(",
"strpos",
"(",
"$",
"value",
",",
"'%'",
")",
"!==",
"FALSE",
"?",
"'LIKE'",
":",
"'='",
")",
",",
"$",
"key",
")",
";",
"$",
"bindings",
"[",
"\":where_$key\"",
"]",
"=",
"$",
"value",
";",
"}",
"$",
"query",
"=",
"sprintf",
"(",
"self",
"::",
"SELECT_SEARCH",
",",
"$",
"this",
"->",
"params",
"[",
"'table'",
"]",
",",
"empty",
"(",
"$",
"cond",
")",
"?",
"'1=1'",
":",
"implode",
"(",
"\" $operator \"",
",",
"$",
"cond",
")",
")",
";",
"$",
"query",
".=",
"sprintf",
"(",
"\" LIMIT %d, %d\"",
",",
"$",
"page",
"*",
"$",
"size",
",",
"$",
"size",
")",
";",
"$",
"stmt",
"=",
"$",
"this",
"->",
"pdo",
"->",
"prepare",
"(",
"$",
"query",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
"$",
"bindings",
")",
";",
"if",
"(",
"!",
"$",
"stmt",
")",
"{",
"$",
"error",
"=",
"$",
"this",
"->",
"pdo",
"->",
"errorInfo",
"(",
")",
";",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"error",
"[",
"2",
"]",
")",
";",
"}",
"$",
"data",
"=",
"$",
"stmt",
"->",
"fetchAll",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"$",
"stmt",
"=",
"$",
"this",
"->",
"pdo",
"->",
"query",
"(",
"\"SELECT FOUND_ROWS() as count\"",
")",
";",
"$",
"count",
"=",
"$",
"stmt",
"->",
"fetch",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"if",
"(",
"!",
"$",
"count",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Error fetching count\"",
")",
";",
"}",
"$",
"count",
"=",
"intval",
"(",
"$",
"count",
"[",
"'count'",
"]",
")",
";",
"return",
"array",
"(",
"'_embedded'",
"=>",
"array",
"(",
"$",
"this",
"->",
"params",
"[",
"'table'",
"]",
"=>",
"$",
"data",
")",
",",
"'page'",
"=>",
"array",
"(",
"'size'",
"=>",
"$",
"size",
",",
"'number'",
"=>",
"$",
"page",
",",
"'totalElements'",
"=>",
"$",
"count",
",",
"'totalPages'",
"=>",
"ceil",
"(",
"$",
"count",
"/",
"$",
"size",
")",
")",
")",
";",
"}"
] | Queries the Auth table | [
"Queries",
"the",
"Auth",
"table"
] | e1a1276e23a2a7bed4d13672478ba7b087479f2e | https://github.com/objectiveweb/auth/blob/e1a1276e23a2a7bed4d13672478ba7b087479f2e/src/Auth.php#L66-L129 |
2,486 | objectiveweb/auth | src/Auth.php | Auth.get | public function get($username) {
if(is_numeric($username)) {
$key = 'id';
}
else {
$key = 'username';
}
$query = sprintf(self::SELECT_ALL,
$this->params['table'],
$this->params[$key],
$this->pdo->quote($username));
$stmt = $this->pdo->query($query);
if(!$stmt) {
$error = $this->pdo->errorInfo();
throw new \Exception($error[2]);
}
if($user = $stmt->fetch(PDO::FETCH_ASSOC)) {
return $user;
}
else {
throw new UserException('User not found', 404);
}
} | php | public function get($username) {
if(is_numeric($username)) {
$key = 'id';
}
else {
$key = 'username';
}
$query = sprintf(self::SELECT_ALL,
$this->params['table'],
$this->params[$key],
$this->pdo->quote($username));
$stmt = $this->pdo->query($query);
if(!$stmt) {
$error = $this->pdo->errorInfo();
throw new \Exception($error[2]);
}
if($user = $stmt->fetch(PDO::FETCH_ASSOC)) {
return $user;
}
else {
throw new UserException('User not found', 404);
}
} | [
"public",
"function",
"get",
"(",
"$",
"username",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"username",
")",
")",
"{",
"$",
"key",
"=",
"'id'",
";",
"}",
"else",
"{",
"$",
"key",
"=",
"'username'",
";",
"}",
"$",
"query",
"=",
"sprintf",
"(",
"self",
"::",
"SELECT_ALL",
",",
"$",
"this",
"->",
"params",
"[",
"'table'",
"]",
",",
"$",
"this",
"->",
"params",
"[",
"$",
"key",
"]",
",",
"$",
"this",
"->",
"pdo",
"->",
"quote",
"(",
"$",
"username",
")",
")",
";",
"$",
"stmt",
"=",
"$",
"this",
"->",
"pdo",
"->",
"query",
"(",
"$",
"query",
")",
";",
"if",
"(",
"!",
"$",
"stmt",
")",
"{",
"$",
"error",
"=",
"$",
"this",
"->",
"pdo",
"->",
"errorInfo",
"(",
")",
";",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"error",
"[",
"2",
"]",
")",
";",
"}",
"if",
"(",
"$",
"user",
"=",
"$",
"stmt",
"->",
"fetch",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
")",
"{",
"return",
"$",
"user",
";",
"}",
"else",
"{",
"throw",
"new",
"UserException",
"(",
"'User not found'",
",",
"404",
")",
";",
"}",
"}"
] | Retrieves a user from the database
@param $username username
@return array user data
@throws UserException
@throws Exception | [
"Retrieves",
"a",
"user",
"from",
"the",
"database"
] | e1a1276e23a2a7bed4d13672478ba7b087479f2e | https://github.com/objectiveweb/auth/blob/e1a1276e23a2a7bed4d13672478ba7b087479f2e/src/Auth.php#L138-L167 |
2,487 | objectiveweb/auth | src/Auth.php | Auth.& | public function &user($user = null)
{
if($user) {
$_SESSION[$this->params['session_key']] = $user;
}
else {
if(!$this->check()) {
throw new UserException('Not logged in', 403);
}
}
return $_SESSION[$this->params['session_key']];
} | php | public function &user($user = null)
{
if($user) {
$_SESSION[$this->params['session_key']] = $user;
}
else {
if(!$this->check()) {
throw new UserException('Not logged in', 403);
}
}
return $_SESSION[$this->params['session_key']];
} | [
"public",
"function",
"&",
"user",
"(",
"$",
"user",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"user",
")",
"{",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"params",
"[",
"'session_key'",
"]",
"]",
"=",
"$",
"user",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"check",
"(",
")",
")",
"{",
"throw",
"new",
"UserException",
"(",
"'Not logged in'",
",",
"403",
")",
";",
"}",
"}",
"return",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"params",
"[",
"'session_key'",
"]",
"]",
";",
"}"
] | Returns the current logged in user or sets the current login data
@param $user array
@return array user data
@throws UserException if noone is logged in | [
"Returns",
"the",
"current",
"logged",
"in",
"user",
"or",
"sets",
"the",
"current",
"login",
"data"
] | e1a1276e23a2a7bed4d13672478ba7b087479f2e | https://github.com/objectiveweb/auth/blob/e1a1276e23a2a7bed4d13672478ba7b087479f2e/src/Auth.php#L283-L296 |
2,488 | objectiveweb/auth | src/Auth.php | Auth.update | public function update($username, array $data) {
$cond = array();
unset($data[$this->params['id']]);
unset($data[$this->params['password']]);
if($this->params['token']) {
unset($data[$this->params['token']]);
}
if($this->params['created']) {
unset($data[$this->params['created']]);
}
if($this->params['last_login']) {
unset($data[$this->params['last_login']]);
}
foreach($data as $k => $v) {
$cond[] = sprintf("`%s` = %s", str_replace(array('\\',"\0" ,'`'), '', $k), $this->pdo->quote($v));
}
if(is_numeric($username)) {
$key = 'id';
}
else {
$key = 'username';
}
$query = sprintf(self::UPDATE_QUERY,
$this->params['table'],
implode(', ', $cond),
$this->params[$key],
$this->pdo->quote($username));
$stmt = $this->pdo->query($query);
if($stmt === FALSE) {
throw new UserException(json_encode($this->pdo->errorInfo()));
}
} | php | public function update($username, array $data) {
$cond = array();
unset($data[$this->params['id']]);
unset($data[$this->params['password']]);
if($this->params['token']) {
unset($data[$this->params['token']]);
}
if($this->params['created']) {
unset($data[$this->params['created']]);
}
if($this->params['last_login']) {
unset($data[$this->params['last_login']]);
}
foreach($data as $k => $v) {
$cond[] = sprintf("`%s` = %s", str_replace(array('\\',"\0" ,'`'), '', $k), $this->pdo->quote($v));
}
if(is_numeric($username)) {
$key = 'id';
}
else {
$key = 'username';
}
$query = sprintf(self::UPDATE_QUERY,
$this->params['table'],
implode(', ', $cond),
$this->params[$key],
$this->pdo->quote($username));
$stmt = $this->pdo->query($query);
if($stmt === FALSE) {
throw new UserException(json_encode($this->pdo->errorInfo()));
}
} | [
"public",
"function",
"update",
"(",
"$",
"username",
",",
"array",
"$",
"data",
")",
"{",
"$",
"cond",
"=",
"array",
"(",
")",
";",
"unset",
"(",
"$",
"data",
"[",
"$",
"this",
"->",
"params",
"[",
"'id'",
"]",
"]",
")",
";",
"unset",
"(",
"$",
"data",
"[",
"$",
"this",
"->",
"params",
"[",
"'password'",
"]",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"params",
"[",
"'token'",
"]",
")",
"{",
"unset",
"(",
"$",
"data",
"[",
"$",
"this",
"->",
"params",
"[",
"'token'",
"]",
"]",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"params",
"[",
"'created'",
"]",
")",
"{",
"unset",
"(",
"$",
"data",
"[",
"$",
"this",
"->",
"params",
"[",
"'created'",
"]",
"]",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"params",
"[",
"'last_login'",
"]",
")",
"{",
"unset",
"(",
"$",
"data",
"[",
"$",
"this",
"->",
"params",
"[",
"'last_login'",
"]",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"data",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"cond",
"[",
"]",
"=",
"sprintf",
"(",
"\"`%s` = %s\"",
",",
"str_replace",
"(",
"array",
"(",
"'\\\\'",
",",
"\"\\0\"",
",",
"'`'",
")",
",",
"''",
",",
"$",
"k",
")",
",",
"$",
"this",
"->",
"pdo",
"->",
"quote",
"(",
"$",
"v",
")",
")",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"username",
")",
")",
"{",
"$",
"key",
"=",
"'id'",
";",
"}",
"else",
"{",
"$",
"key",
"=",
"'username'",
";",
"}",
"$",
"query",
"=",
"sprintf",
"(",
"self",
"::",
"UPDATE_QUERY",
",",
"$",
"this",
"->",
"params",
"[",
"'table'",
"]",
",",
"implode",
"(",
"', '",
",",
"$",
"cond",
")",
",",
"$",
"this",
"->",
"params",
"[",
"$",
"key",
"]",
",",
"$",
"this",
"->",
"pdo",
"->",
"quote",
"(",
"$",
"username",
")",
")",
";",
"$",
"stmt",
"=",
"$",
"this",
"->",
"pdo",
"->",
"query",
"(",
"$",
"query",
")",
";",
"if",
"(",
"$",
"stmt",
"===",
"FALSE",
")",
"{",
"throw",
"new",
"UserException",
"(",
"json_encode",
"(",
"$",
"this",
"->",
"pdo",
"->",
"errorInfo",
"(",
")",
")",
")",
";",
"}",
"}"
] | Update arbitrary user data
@param $username
@param array $data associative array of data
@throws UserException if no rows were updated | [
"Update",
"arbitrary",
"user",
"data"
] | e1a1276e23a2a7bed4d13672478ba7b087479f2e | https://github.com/objectiveweb/auth/blob/e1a1276e23a2a7bed4d13672478ba7b087479f2e/src/Auth.php#L373-L415 |
2,489 | objectiveweb/auth | src/Auth.php | Auth.update_token | public function update_token($username) {
$token = self::hash();
$query = sprintf(self::UPDATE_VALUE,
$this->params['table'],
$this->params['token'],
$this->pdo->quote($token),
$this->params['username'],
$this->pdo->quote($username));
$stmt = $this->pdo->query($query);
if($stmt === FALSE || $stmt->rowCount() !== 1) {
throw new UserException('Token not found');
}
return $token;
} | php | public function update_token($username) {
$token = self::hash();
$query = sprintf(self::UPDATE_VALUE,
$this->params['table'],
$this->params['token'],
$this->pdo->quote($token),
$this->params['username'],
$this->pdo->quote($username));
$stmt = $this->pdo->query($query);
if($stmt === FALSE || $stmt->rowCount() !== 1) {
throw new UserException('Token not found');
}
return $token;
} | [
"public",
"function",
"update_token",
"(",
"$",
"username",
")",
"{",
"$",
"token",
"=",
"self",
"::",
"hash",
"(",
")",
";",
"$",
"query",
"=",
"sprintf",
"(",
"self",
"::",
"UPDATE_VALUE",
",",
"$",
"this",
"->",
"params",
"[",
"'table'",
"]",
",",
"$",
"this",
"->",
"params",
"[",
"'token'",
"]",
",",
"$",
"this",
"->",
"pdo",
"->",
"quote",
"(",
"$",
"token",
")",
",",
"$",
"this",
"->",
"params",
"[",
"'username'",
"]",
",",
"$",
"this",
"->",
"pdo",
"->",
"quote",
"(",
"$",
"username",
")",
")",
";",
"$",
"stmt",
"=",
"$",
"this",
"->",
"pdo",
"->",
"query",
"(",
"$",
"query",
")",
";",
"if",
"(",
"$",
"stmt",
"===",
"FALSE",
"||",
"$",
"stmt",
"->",
"rowCount",
"(",
")",
"!==",
"1",
")",
"{",
"throw",
"new",
"UserException",
"(",
"'Token not found'",
")",
";",
"}",
"return",
"$",
"token",
";",
"}"
] | Generates a new token for the user and update the database
@param $username
@return string new token | [
"Generates",
"a",
"new",
"token",
"for",
"the",
"user",
"and",
"update",
"the",
"database"
] | e1a1276e23a2a7bed4d13672478ba7b087479f2e | https://github.com/objectiveweb/auth/blob/e1a1276e23a2a7bed4d13672478ba7b087479f2e/src/Auth.php#L452-L469 |
2,490 | atompulse/data | Xml/Transformer.php | Transformer.& | public function &buildArray($inputXml)
{
$this->init();
if (is_string($inputXml)) {
$this->xml = $this->createDOMDocument();
$parsed = $this->xml->loadXML($inputXml);
if ( ! $parsed) {
throw new \Exception('[Transformer] Error parsing the XML string.');
}
} elseif ($inputXml instanceof \DOMDocument) {
$this->xml = $inputXml;
} else {
throw new \Exception('[Transformer] The input XML object should be of type: DOMDocument but got instead ['.gettype($inputXml).'].');
}
// Convert the XML to an array, starting with the root node
$docNodeName = $this->xml->documentElement->nodeName;
$array[$docNodeName] = $this->convert($this->xml->documentElement);
// Add namespacing information to the root node
if ( ! empty($this->namespaces)) {
if ( ! isset($array[$docNodeName][$this->config['attributesKey']])) {
$array[$docNodeName][$this->config['attributesKey']] = array();
}
foreach ($this->namespaces as $uri => $prefix) {
if ($prefix) {
$prefix = self::ATTRIBUTE_NAMESPACE_SEPARATOR . $prefix;
}
$array[$docNodeName][$this->config['attributesKey']][self::ATTRIBUTE_NAMESPACE . $prefix] = $uri;
}
}
return $array;
} | php | public function &buildArray($inputXml)
{
$this->init();
if (is_string($inputXml)) {
$this->xml = $this->createDOMDocument();
$parsed = $this->xml->loadXML($inputXml);
if ( ! $parsed) {
throw new \Exception('[Transformer] Error parsing the XML string.');
}
} elseif ($inputXml instanceof \DOMDocument) {
$this->xml = $inputXml;
} else {
throw new \Exception('[Transformer] The input XML object should be of type: DOMDocument but got instead ['.gettype($inputXml).'].');
}
// Convert the XML to an array, starting with the root node
$docNodeName = $this->xml->documentElement->nodeName;
$array[$docNodeName] = $this->convert($this->xml->documentElement);
// Add namespacing information to the root node
if ( ! empty($this->namespaces)) {
if ( ! isset($array[$docNodeName][$this->config['attributesKey']])) {
$array[$docNodeName][$this->config['attributesKey']] = array();
}
foreach ($this->namespaces as $uri => $prefix) {
if ($prefix) {
$prefix = self::ATTRIBUTE_NAMESPACE_SEPARATOR . $prefix;
}
$array[$docNodeName][$this->config['attributesKey']][self::ATTRIBUTE_NAMESPACE . $prefix] = $uri;
}
}
return $array;
} | [
"public",
"function",
"&",
"buildArray",
"(",
"$",
"inputXml",
")",
"{",
"$",
"this",
"->",
"init",
"(",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"inputXml",
")",
")",
"{",
"$",
"this",
"->",
"xml",
"=",
"$",
"this",
"->",
"createDOMDocument",
"(",
")",
";",
"$",
"parsed",
"=",
"$",
"this",
"->",
"xml",
"->",
"loadXML",
"(",
"$",
"inputXml",
")",
";",
"if",
"(",
"!",
"$",
"parsed",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'[Transformer] Error parsing the XML string.'",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"inputXml",
"instanceof",
"\\",
"DOMDocument",
")",
"{",
"$",
"this",
"->",
"xml",
"=",
"$",
"inputXml",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'[Transformer] The input XML object should be of type: DOMDocument but got instead ['",
".",
"gettype",
"(",
"$",
"inputXml",
")",
".",
"'].'",
")",
";",
"}",
"// Convert the XML to an array, starting with the root node",
"$",
"docNodeName",
"=",
"$",
"this",
"->",
"xml",
"->",
"documentElement",
"->",
"nodeName",
";",
"$",
"array",
"[",
"$",
"docNodeName",
"]",
"=",
"$",
"this",
"->",
"convert",
"(",
"$",
"this",
"->",
"xml",
"->",
"documentElement",
")",
";",
"// Add namespacing information to the root node",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"namespaces",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"array",
"[",
"$",
"docNodeName",
"]",
"[",
"$",
"this",
"->",
"config",
"[",
"'attributesKey'",
"]",
"]",
")",
")",
"{",
"$",
"array",
"[",
"$",
"docNodeName",
"]",
"[",
"$",
"this",
"->",
"config",
"[",
"'attributesKey'",
"]",
"]",
"=",
"array",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"namespaces",
"as",
"$",
"uri",
"=>",
"$",
"prefix",
")",
"{",
"if",
"(",
"$",
"prefix",
")",
"{",
"$",
"prefix",
"=",
"self",
"::",
"ATTRIBUTE_NAMESPACE_SEPARATOR",
".",
"$",
"prefix",
";",
"}",
"$",
"array",
"[",
"$",
"docNodeName",
"]",
"[",
"$",
"this",
"->",
"config",
"[",
"'attributesKey'",
"]",
"]",
"[",
"self",
"::",
"ATTRIBUTE_NAMESPACE",
".",
"$",
"prefix",
"]",
"=",
"$",
"uri",
";",
"}",
"}",
"return",
"$",
"array",
";",
"}"
] | Convert an XML DOMDocument or XML string to an array
@param \DOMDocument|string $inputXml The XML to convert to an array
@return array An array representation of the input XML
@throws \Exception | [
"Convert",
"an",
"XML",
"DOMDocument",
"or",
"XML",
"string",
"to",
"an",
"array"
] | 14bfd67f3b237fcb9d29dfc313b25f32d37506e6 | https://github.com/atompulse/data/blob/14bfd67f3b237fcb9d29dfc313b25f32d37506e6/Xml/Transformer.php#L114-L147 |
2,491 | atompulse/data | Xml/Transformer.php | Transformer.collateNamespaces | protected function collateNamespaces(\DOMNode $node)
{
if ($this->config['useNamespaces'] && $node->namespaceURI
&& ! array_key_exists($node->namespaceURI, $this->namespaces)) {
$this->namespaces[$node->namespaceURI] = $node->lookupPrefix($node->namespaceURI);
}
} | php | protected function collateNamespaces(\DOMNode $node)
{
if ($this->config['useNamespaces'] && $node->namespaceURI
&& ! array_key_exists($node->namespaceURI, $this->namespaces)) {
$this->namespaces[$node->namespaceURI] = $node->lookupPrefix($node->namespaceURI);
}
} | [
"protected",
"function",
"collateNamespaces",
"(",
"\\",
"DOMNode",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"config",
"[",
"'useNamespaces'",
"]",
"&&",
"$",
"node",
"->",
"namespaceURI",
"&&",
"!",
"array_key_exists",
"(",
"$",
"node",
"->",
"namespaceURI",
",",
"$",
"this",
"->",
"namespaces",
")",
")",
"{",
"$",
"this",
"->",
"namespaces",
"[",
"$",
"node",
"->",
"namespaceURI",
"]",
"=",
"$",
"node",
"->",
"lookupPrefix",
"(",
"$",
"node",
"->",
"namespaceURI",
")",
";",
"}",
"}"
] | Get the namespace of the supplied node, and add it to the list of known namespaces for this document
@param \DOMNode $node | [
"Get",
"the",
"namespace",
"of",
"the",
"supplied",
"node",
"and",
"add",
"it",
"to",
"the",
"list",
"of",
"known",
"namespaces",
"for",
"this",
"document"
] | 14bfd67f3b237fcb9d29dfc313b25f32d37506e6 | https://github.com/atompulse/data/blob/14bfd67f3b237fcb9d29dfc313b25f32d37506e6/Xml/Transformer.php#L226-L232 |
2,492 | coolms/common | src/Mvc/Service/AbstractControllerAbstractServiceFactory.php | AbstractControllerAbstractServiceFactory.getConfig | protected function getConfig($requestedName, ServiceLocatorInterface $services)
{
if ($this->configKey) {
$config = $services->get('Config');
if (!empty($config[$this->configKey][$requestedName])
&& is_array($config[$this->configKey][$requestedName])
) {
return $config[$this->configKey][$requestedName];
}
}
return [];
} | php | protected function getConfig($requestedName, ServiceLocatorInterface $services)
{
if ($this->configKey) {
$config = $services->get('Config');
if (!empty($config[$this->configKey][$requestedName])
&& is_array($config[$this->configKey][$requestedName])
) {
return $config[$this->configKey][$requestedName];
}
}
return [];
} | [
"protected",
"function",
"getConfig",
"(",
"$",
"requestedName",
",",
"ServiceLocatorInterface",
"$",
"services",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"configKey",
")",
"{",
"$",
"config",
"=",
"$",
"services",
"->",
"get",
"(",
"'Config'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"config",
"[",
"$",
"this",
"->",
"configKey",
"]",
"[",
"$",
"requestedName",
"]",
")",
"&&",
"is_array",
"(",
"$",
"config",
"[",
"$",
"this",
"->",
"configKey",
"]",
"[",
"$",
"requestedName",
"]",
")",
")",
"{",
"return",
"$",
"config",
"[",
"$",
"this",
"->",
"configKey",
"]",
"[",
"$",
"requestedName",
"]",
";",
"}",
"}",
"return",
"[",
"]",
";",
"}"
] | Retrieves configuration options
@param string $requestedName
@param ServiceLocatorInterface $services
@return array | [
"Retrieves",
"configuration",
"options"
] | 3572993cdcdb2898cdde396a2f1de9864b193660 | https://github.com/coolms/common/blob/3572993cdcdb2898cdde396a2f1de9864b193660/src/Mvc/Service/AbstractControllerAbstractServiceFactory.php#L108-L120 |
2,493 | joomla-framework/mediawiki-api | src/AbstractMediawikiObject.php | AbstractMediawikiObject.fetchUrl | protected function fetchUrl($path)
{
// Append the path with output format
$path .= '&format=xml';
$uri = new Uri($this->options->get('api.url') . '/api.php' . $path);
if ($this->options->get('api.username', false))
{
$uri->setUser($this->options->get('api.username'));
}
if ($this->options->get('api.password', false))
{
$uri->setPass($this->options->get('api.password'));
}
return (string) $uri;
} | php | protected function fetchUrl($path)
{
// Append the path with output format
$path .= '&format=xml';
$uri = new Uri($this->options->get('api.url') . '/api.php' . $path);
if ($this->options->get('api.username', false))
{
$uri->setUser($this->options->get('api.username'));
}
if ($this->options->get('api.password', false))
{
$uri->setPass($this->options->get('api.password'));
}
return (string) $uri;
} | [
"protected",
"function",
"fetchUrl",
"(",
"$",
"path",
")",
"{",
"// Append the path with output format",
"$",
"path",
".=",
"'&format=xml'",
";",
"$",
"uri",
"=",
"new",
"Uri",
"(",
"$",
"this",
"->",
"options",
"->",
"get",
"(",
"'api.url'",
")",
".",
"'/api.php'",
".",
"$",
"path",
")",
";",
"if",
"(",
"$",
"this",
"->",
"options",
"->",
"get",
"(",
"'api.username'",
",",
"false",
")",
")",
"{",
"$",
"uri",
"->",
"setUser",
"(",
"$",
"this",
"->",
"options",
"->",
"get",
"(",
"'api.username'",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"options",
"->",
"get",
"(",
"'api.password'",
",",
"false",
")",
")",
"{",
"$",
"uri",
"->",
"setPass",
"(",
"$",
"this",
"->",
"options",
"->",
"get",
"(",
"'api.password'",
")",
")",
";",
"}",
"return",
"(",
"string",
")",
"$",
"uri",
";",
"}"
] | Method to build and return a full request URL for the request.
@param string $path URL to inflect
@return string The request URL.
@since 1.0 | [
"Method",
"to",
"build",
"and",
"return",
"a",
"full",
"request",
"URL",
"for",
"the",
"request",
"."
] | 8855d51b61d5518bd92a0806fbd3098f4e063619 | https://github.com/joomla-framework/mediawiki-api/blob/8855d51b61d5518bd92a0806fbd3098f4e063619/src/AbstractMediawikiObject.php#L57-L75 |
2,494 | joomla-framework/mediawiki-api | src/AbstractMediawikiObject.php | AbstractMediawikiObject.buildParameter | public function buildParameter(array $params)
{
$path = '';
foreach ($params as $param)
{
$path .= $param;
if (next($params) == true)
{
$path .= '|';
}
}
return $path;
} | php | public function buildParameter(array $params)
{
$path = '';
foreach ($params as $param)
{
$path .= $param;
if (next($params) == true)
{
$path .= '|';
}
}
return $path;
} | [
"public",
"function",
"buildParameter",
"(",
"array",
"$",
"params",
")",
"{",
"$",
"path",
"=",
"''",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"param",
")",
"{",
"$",
"path",
".=",
"$",
"param",
";",
"if",
"(",
"next",
"(",
"$",
"params",
")",
"==",
"true",
")",
"{",
"$",
"path",
".=",
"'|'",
";",
"}",
"}",
"return",
"$",
"path",
";",
"}"
] | Method to build request parameters from a string array.
@param array $params string array that contains the parameters
@return string request parameter
@since 1.0 | [
"Method",
"to",
"build",
"request",
"parameters",
"from",
"a",
"string",
"array",
"."
] | 8855d51b61d5518bd92a0806fbd3098f4e063619 | https://github.com/joomla-framework/mediawiki-api/blob/8855d51b61d5518bd92a0806fbd3098f4e063619/src/AbstractMediawikiObject.php#L86-L101 |
2,495 | joomla-framework/mediawiki-api | src/AbstractMediawikiObject.php | AbstractMediawikiObject.validateResponse | public function validateResponse(Response $response)
{
$xml = simplexml_load_string($response->body);
if (isset($xml->warnings))
{
throw new \DomainException($xml->warnings->info);
}
if (isset($xml->error))
{
throw new \DomainException($xml->error['info']);
}
return $xml;
} | php | public function validateResponse(Response $response)
{
$xml = simplexml_load_string($response->body);
if (isset($xml->warnings))
{
throw new \DomainException($xml->warnings->info);
}
if (isset($xml->error))
{
throw new \DomainException($xml->error['info']);
}
return $xml;
} | [
"public",
"function",
"validateResponse",
"(",
"Response",
"$",
"response",
")",
"{",
"$",
"xml",
"=",
"simplexml_load_string",
"(",
"$",
"response",
"->",
"body",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"xml",
"->",
"warnings",
")",
")",
"{",
"throw",
"new",
"\\",
"DomainException",
"(",
"$",
"xml",
"->",
"warnings",
"->",
"info",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"xml",
"->",
"error",
")",
")",
"{",
"throw",
"new",
"\\",
"DomainException",
"(",
"$",
"xml",
"->",
"error",
"[",
"'info'",
"]",
")",
";",
"}",
"return",
"$",
"xml",
";",
"}"
] | Method to validate response for errors
@param Response $response The response from the mediawiki server.
@return \SimpleXMLElement
@since 1.0
@throws \DomainException | [
"Method",
"to",
"validate",
"response",
"for",
"errors"
] | 8855d51b61d5518bd92a0806fbd3098f4e063619 | https://github.com/joomla-framework/mediawiki-api/blob/8855d51b61d5518bd92a0806fbd3098f4e063619/src/AbstractMediawikiObject.php#L113-L128 |
2,496 | thinker-g/yii2-helpers | actions/InstallerAction.php | InstallerAction.checkGii | public function checkGii()
{
if (!isset(Yii::$app->controllerMap[$this->giiID])) {
$msg = "Command \"{$this->giiID}\" is not available.\n";
$msg .= "Please check to ensure the module is mounted and added to bootstrap phase.\n";
$this->controller->stderr($msg, Console::FG_RED);
Yii::$app->end(1);
}
} | php | public function checkGii()
{
if (!isset(Yii::$app->controllerMap[$this->giiID])) {
$msg = "Command \"{$this->giiID}\" is not available.\n";
$msg .= "Please check to ensure the module is mounted and added to bootstrap phase.\n";
$this->controller->stderr($msg, Console::FG_RED);
Yii::$app->end(1);
}
} | [
"public",
"function",
"checkGii",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"Yii",
"::",
"$",
"app",
"->",
"controllerMap",
"[",
"$",
"this",
"->",
"giiID",
"]",
")",
")",
"{",
"$",
"msg",
"=",
"\"Command \\\"{$this->giiID}\\\" is not available.\\n\"",
";",
"$",
"msg",
".=",
"\"Please check to ensure the module is mounted and added to bootstrap phase.\\n\"",
";",
"$",
"this",
"->",
"controller",
"->",
"stderr",
"(",
"$",
"msg",
",",
"Console",
"::",
"FG_RED",
")",
";",
"Yii",
"::",
"$",
"app",
"->",
"end",
"(",
"1",
")",
";",
"}",
"}"
] | Check whether Gii module is loaded. | [
"Check",
"whether",
"Gii",
"module",
"is",
"loaded",
"."
] | 3362196e25e83bdf1f37b53f18f9613a43605f38 | https://github.com/thinker-g/yii2-helpers/blob/3362196e25e83bdf1f37b53f18f9613a43605f38/actions/InstallerAction.php#L23-L31 |
2,497 | bishopb/vanilla | library/core/class.uploadimage.php | Gdn_UploadImage.ImageSize | public static function ImageSize($Path, $Filename = FALSE) {
if (!$Filename)
$Filename = $Path;
if (in_array(strtolower(pathinfo($Filename, PATHINFO_EXTENSION)), array('gif', 'jpg', 'jpeg', 'png'))) {
$ImageSize = @getimagesize($Path);
if (!is_array($ImageSize) || !in_array($ImageSize[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG)))
return array(0, 0, FALSE);
return $ImageSize;
}
return array(0, 0, FALSE);
} | php | public static function ImageSize($Path, $Filename = FALSE) {
if (!$Filename)
$Filename = $Path;
if (in_array(strtolower(pathinfo($Filename, PATHINFO_EXTENSION)), array('gif', 'jpg', 'jpeg', 'png'))) {
$ImageSize = @getimagesize($Path);
if (!is_array($ImageSize) || !in_array($ImageSize[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG)))
return array(0, 0, FALSE);
return $ImageSize;
}
return array(0, 0, FALSE);
} | [
"public",
"static",
"function",
"ImageSize",
"(",
"$",
"Path",
",",
"$",
"Filename",
"=",
"FALSE",
")",
"{",
"if",
"(",
"!",
"$",
"Filename",
")",
"$",
"Filename",
"=",
"$",
"Path",
";",
"if",
"(",
"in_array",
"(",
"strtolower",
"(",
"pathinfo",
"(",
"$",
"Filename",
",",
"PATHINFO_EXTENSION",
")",
")",
",",
"array",
"(",
"'gif'",
",",
"'jpg'",
",",
"'jpeg'",
",",
"'png'",
")",
")",
")",
"{",
"$",
"ImageSize",
"=",
"@",
"getimagesize",
"(",
"$",
"Path",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"ImageSize",
")",
"||",
"!",
"in_array",
"(",
"$",
"ImageSize",
"[",
"2",
"]",
",",
"array",
"(",
"IMAGETYPE_GIF",
",",
"IMAGETYPE_JPEG",
",",
"IMAGETYPE_PNG",
")",
")",
")",
"return",
"array",
"(",
"0",
",",
"0",
",",
"FALSE",
")",
";",
"return",
"$",
"ImageSize",
";",
"}",
"return",
"array",
"(",
"0",
",",
"0",
",",
"FALSE",
")",
";",
"}"
] | Gets the image size of a file.
@param string $Path The path to the file.
@param string $Filename The name of the file.
@return array An array of [width, height, image type].
@since 2.1 | [
"Gets",
"the",
"image",
"size",
"of",
"a",
"file",
"."
] | 8494eb4a4ad61603479015a8054d23ff488364e8 | https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.uploadimage.php#L48-L59 |
2,498 | bishopb/vanilla | library/core/class.uploadimage.php | Gdn_UploadImage.ValidateUpload | public function ValidateUpload($InputName, $ThrowError = TRUE) {
if (!function_exists('gd_info'))
throw new Exception(T('The uploaded file could not be processed because GD is not installed.'));
// Make sure that all standard file upload checks are performed.
$TmpFileName = parent::ValidateUpload($InputName, $ThrowError);
// Now perform image-specific checks.
if ($TmpFileName) {
$Size = getimagesize($TmpFileName);
if ($Size === FALSE)
throw new Exception(T('The uploaded file was not an image.'));
}
return $TmpFileName;
} | php | public function ValidateUpload($InputName, $ThrowError = TRUE) {
if (!function_exists('gd_info'))
throw new Exception(T('The uploaded file could not be processed because GD is not installed.'));
// Make sure that all standard file upload checks are performed.
$TmpFileName = parent::ValidateUpload($InputName, $ThrowError);
// Now perform image-specific checks.
if ($TmpFileName) {
$Size = getimagesize($TmpFileName);
if ($Size === FALSE)
throw new Exception(T('The uploaded file was not an image.'));
}
return $TmpFileName;
} | [
"public",
"function",
"ValidateUpload",
"(",
"$",
"InputName",
",",
"$",
"ThrowError",
"=",
"TRUE",
")",
"{",
"if",
"(",
"!",
"function_exists",
"(",
"'gd_info'",
")",
")",
"throw",
"new",
"Exception",
"(",
"T",
"(",
"'The uploaded file could not be processed because GD is not installed.'",
")",
")",
";",
"// Make sure that all standard file upload checks are performed.",
"$",
"TmpFileName",
"=",
"parent",
"::",
"ValidateUpload",
"(",
"$",
"InputName",
",",
"$",
"ThrowError",
")",
";",
"// Now perform image-specific checks.",
"if",
"(",
"$",
"TmpFileName",
")",
"{",
"$",
"Size",
"=",
"getimagesize",
"(",
"$",
"TmpFileName",
")",
";",
"if",
"(",
"$",
"Size",
"===",
"FALSE",
")",
"throw",
"new",
"Exception",
"(",
"T",
"(",
"'The uploaded file was not an image.'",
")",
")",
";",
"}",
"return",
"$",
"TmpFileName",
";",
"}"
] | Validates the uploaded image. Returns the temporary name of the uploaded file. | [
"Validates",
"the",
"uploaded",
"image",
".",
"Returns",
"the",
"temporary",
"name",
"of",
"the",
"uploaded",
"file",
"."
] | 8494eb4a4ad61603479015a8054d23ff488364e8 | https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.uploadimage.php#L64-L80 |
2,499 | novuso/system | src/Collection/ArrayCollection.php | ArrayCollection.prependSet | public function prependSet($key, $value): ArrayCollection
{
$this->items = [$key => $value] + $this->items;
return $this;
} | php | public function prependSet($key, $value): ArrayCollection
{
$this->items = [$key => $value] + $this->items;
return $this;
} | [
"public",
"function",
"prependSet",
"(",
"$",
"key",
",",
"$",
"value",
")",
":",
"ArrayCollection",
"{",
"$",
"this",
"->",
"items",
"=",
"[",
"$",
"key",
"=>",
"$",
"value",
"]",
"+",
"$",
"this",
"->",
"items",
";",
"return",
"$",
"this",
";",
"}"
] | Prepends a keyed value
@param mixed $key The key
@param mixed $value The value
@return ArrayCollection | [
"Prepends",
"a",
"keyed",
"value"
] | e34038b391826edc68d0b5fccfba96642de9d6f0 | https://github.com/novuso/system/blob/e34038b391826edc68d0b5fccfba96642de9d6f0/src/Collection/ArrayCollection.php#L161-L166 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.