repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
agentmedia/phine-core | src/Core/Logic/Sitemap/Generator.php | Generator.Generate | function Generate()
{
if ($this->cacher->MustUseCache())
{
$this->xml = $this->cacher->GetFromCache();
return;
}
$this->AddAllPages();
$this->xml = $this->sitemap->SaveXml();
if ($this->cacher->MustStoreToCache())
{
$this->cacher->StoreToCache($this->xml);
}
} | php | function Generate()
{
if ($this->cacher->MustUseCache())
{
$this->xml = $this->cacher->GetFromCache();
return;
}
$this->AddAllPages();
$this->xml = $this->sitemap->SaveXml();
if ($this->cacher->MustStoreToCache())
{
$this->cacher->StoreToCache($this->xml);
}
} | [
"function",
"Generate",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"cacher",
"->",
"MustUseCache",
"(",
")",
")",
"{",
"$",
"this",
"->",
"xml",
"=",
"$",
"this",
"->",
"cacher",
"->",
"GetFromCache",
"(",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"AddAllPages",
"(",
")",
";",
"$",
"this",
"->",
"xml",
"=",
"$",
"this",
"->",
"sitemap",
"->",
"SaveXml",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"cacher",
"->",
"MustStoreToCache",
"(",
")",
")",
"{",
"$",
"this",
"->",
"cacher",
"->",
"StoreToCache",
"(",
"$",
"this",
"->",
"xml",
")",
";",
"}",
"}"
] | Generates the xml by pulling it from cache or generating it
@return string | [
"Generates",
"the",
"xml",
"by",
"pulling",
"it",
"from",
"cache",
"or",
"generating",
"it"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Sitemap/Generator.php#L82-L95 | train |
agentmedia/phine-core | src/Core/Logic/Sitemap/Generator.php | Generator.AddAllPages | private function AddAllPages()
{
$page = $this->pageTree->TopMost();
while ($page)
{
$this->AddPageBranch($page);
$page = $this->pageTree->NextOf($page);
}
} | php | private function AddAllPages()
{
$page = $this->pageTree->TopMost();
while ($page)
{
$this->AddPageBranch($page);
$page = $this->pageTree->NextOf($page);
}
} | [
"private",
"function",
"AddAllPages",
"(",
")",
"{",
"$",
"page",
"=",
"$",
"this",
"->",
"pageTree",
"->",
"TopMost",
"(",
")",
";",
"while",
"(",
"$",
"page",
")",
"{",
"$",
"this",
"->",
"AddPageBranch",
"(",
"$",
"page",
")",
";",
"$",
"page",
"=",
"$",
"this",
"->",
"pageTree",
"->",
"NextOf",
"(",
"$",
"page",
")",
";",
"}",
"}"
] | The entry point for fetching all pages as sitemap | [
"The",
"entry",
"point",
"for",
"fetching",
"all",
"pages",
"as",
"sitemap"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Sitemap/Generator.php#L99-L107 | train |
agentmedia/phine-core | src/Core/Logic/Sitemap/Generator.php | Generator.AddPageBranch | private function AddPageBranch(Page $page)
{
$this->AddPage($page);
$child = $this->pageTree->FirstChildOf($page);
while ($child)
{
$this->AddPageBranch($child);
$child = $this->pageTree->NextOf($child);
}
} | php | private function AddPageBranch(Page $page)
{
$this->AddPage($page);
$child = $this->pageTree->FirstChildOf($page);
while ($child)
{
$this->AddPageBranch($child);
$child = $this->pageTree->NextOf($child);
}
} | [
"private",
"function",
"AddPageBranch",
"(",
"Page",
"$",
"page",
")",
"{",
"$",
"this",
"->",
"AddPage",
"(",
"$",
"page",
")",
";",
"$",
"child",
"=",
"$",
"this",
"->",
"pageTree",
"->",
"FirstChildOf",
"(",
"$",
"page",
")",
";",
"while",
"(",
"$",
"child",
")",
"{",
"$",
"this",
"->",
"AddPageBranch",
"(",
"$",
"child",
")",
";",
"$",
"child",
"=",
"$",
"this",
"->",
"pageTree",
"->",
"NextOf",
"(",
"$",
"child",
")",
";",
"}",
"}"
] | Adds a page and all of its children
@param Page $page The current page | [
"Adds",
"a",
"page",
"and",
"all",
"of",
"its",
"children"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Sitemap/Generator.php#L114-L123 | train |
agentmedia/phine-core | src/Core/Logic/Sitemap/Generator.php | Generator.AddPage | private function AddPage(Page $page)
{
if (!$this->PageAllowed($page))
{
return;
}
$params = FrontendRouter::GatherParams($page->GetUrl());
if (count($params) == 0)
{
$changeFreq = ChangeFrequency::ByValue($page->GetSitemapChangeFrequency());
$priority = $page->GetSitemapRelevance();
$lastLog = LogEvaluator::LastPageModLog($page, $this->resolver);
$lastMod = $lastLog ? $lastLog->GetChanged() : null;
$this->sitemap->AddUrl(FrontendRouter::PageUrl($page), $changeFreq, $priority, $lastMod);
}
} | php | private function AddPage(Page $page)
{
if (!$this->PageAllowed($page))
{
return;
}
$params = FrontendRouter::GatherParams($page->GetUrl());
if (count($params) == 0)
{
$changeFreq = ChangeFrequency::ByValue($page->GetSitemapChangeFrequency());
$priority = $page->GetSitemapRelevance();
$lastLog = LogEvaluator::LastPageModLog($page, $this->resolver);
$lastMod = $lastLog ? $lastLog->GetChanged() : null;
$this->sitemap->AddUrl(FrontendRouter::PageUrl($page), $changeFreq, $priority, $lastMod);
}
} | [
"private",
"function",
"AddPage",
"(",
"Page",
"$",
"page",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"PageAllowed",
"(",
"$",
"page",
")",
")",
"{",
"return",
";",
"}",
"$",
"params",
"=",
"FrontendRouter",
"::",
"GatherParams",
"(",
"$",
"page",
"->",
"GetUrl",
"(",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"params",
")",
"==",
"0",
")",
"{",
"$",
"changeFreq",
"=",
"ChangeFrequency",
"::",
"ByValue",
"(",
"$",
"page",
"->",
"GetSitemapChangeFrequency",
"(",
")",
")",
";",
"$",
"priority",
"=",
"$",
"page",
"->",
"GetSitemapRelevance",
"(",
")",
";",
"$",
"lastLog",
"=",
"LogEvaluator",
"::",
"LastPageModLog",
"(",
"$",
"page",
",",
"$",
"this",
"->",
"resolver",
")",
";",
"$",
"lastMod",
"=",
"$",
"lastLog",
"?",
"$",
"lastLog",
"->",
"GetChanged",
"(",
")",
":",
"null",
";",
"$",
"this",
"->",
"sitemap",
"->",
"AddUrl",
"(",
"FrontendRouter",
"::",
"PageUrl",
"(",
"$",
"page",
")",
",",
"$",
"changeFreq",
",",
"$",
"priority",
",",
"$",
"lastMod",
")",
";",
"}",
"}"
] | Adds a single page to the sitemap
@param Page $page The page | [
"Adds",
"a",
"single",
"page",
"to",
"the",
"sitemap"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Sitemap/Generator.php#L129-L144 | train |
modulusphp/utility | Mail.php | Mail.action | public function action(string $message, string $link, string $class = 'btn btn-primary') : Mail
{
$this->body .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"{$class}\">
<tbody>
<tr>
<td align=\"left\">
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tbody>
<tr>
<td>
<a href=\"{$link}\" target=\"_blank\">{$message}</a>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
";
return $this;
} | php | public function action(string $message, string $link, string $class = 'btn btn-primary') : Mail
{
$this->body .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"{$class}\">
<tbody>
<tr>
<td align=\"left\">
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tbody>
<tr>
<td>
<a href=\"{$link}\" target=\"_blank\">{$message}</a>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
";
return $this;
} | [
"public",
"function",
"action",
"(",
"string",
"$",
"message",
",",
"string",
"$",
"link",
",",
"string",
"$",
"class",
"=",
"'btn btn-primary'",
")",
":",
"Mail",
"{",
"$",
"this",
"->",
"body",
".=",
"\"<table border=\\\"0\\\" cellpadding=\\\"0\\\" cellspacing=\\\"0\\\" class=\\\"{$class}\\\">\n<tbody>\n <tr>\n <td align=\\\"left\\\">\n <table border=\\\"0\\\" cellpadding=\\\"0\\\" cellspacing=\\\"0\\\">\n <tbody>\n <tr>\n <td>\n <a href=\\\"{$link}\\\" target=\\\"_blank\\\">{$message}</a>\n </td>\n </tr>\n </tbody>\n </table>\n </td>\n </tr>\n</tbody>\n</table>\n\"",
";",
"return",
"$",
"this",
";",
"}"
] | Create a action
@param string $message
@param string $link
@param string $class
@return Mail | [
"Create",
"a",
"action"
] | c1e127539b13d3ec8381e41c64b881e0701807f5 | https://github.com/modulusphp/utility/blob/c1e127539b13d3ec8381e41c64b881e0701807f5/Mail.php#L187-L208 | train |
modulusphp/utility | Mail.php | Mail.view | public function view(string $view, array $data = []) : Mail
{
$this->viewLocation = $view;
$this->viewArgs = $data;
return $this;
} | php | public function view(string $view, array $data = []) : Mail
{
$this->viewLocation = $view;
$this->viewArgs = $data;
return $this;
} | [
"public",
"function",
"view",
"(",
"string",
"$",
"view",
",",
"array",
"$",
"data",
"=",
"[",
"]",
")",
":",
"Mail",
"{",
"$",
"this",
"->",
"viewLocation",
"=",
"$",
"view",
";",
"$",
"this",
"->",
"viewArgs",
"=",
"$",
"data",
";",
"return",
"$",
"this",
";",
"}"
] | Set view email view
@param string $view
@param array $data
@return Mail | [
"Set",
"view",
"email",
"view"
] | c1e127539b13d3ec8381e41c64b881e0701807f5 | https://github.com/modulusphp/utility/blob/c1e127539b13d3ec8381e41c64b881e0701807f5/Mail.php#L217-L222 | train |
modulusphp/utility | Mail.php | Mail.send | public function send(?string $message = null, ?string $subject = null)
{
if ($message != null) {
$this->body = $message;
}
if ($subject != null) {
$this->subject = $subject;
}
if ($this->viewLocation != null || $this->viewLocation !== '') {
$this->render($this->viewLocation, $this->viewArgs);
}
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = $this->connection['encryption'];
$mail->SMTPKeepAlive = true;
$mail->Host = $this->connection['host'];
$mail->Port = $this->connection['port'];
$mail->IsHTML(true);
$mail->Username = $this->connection['username'];
$mail->Password = $this->connection['password'];
$mail->SetFrom($this->connection['from']['address'], $this->connection['from']['name']);
$mail->Subject = $this->subject;
$mail->Body = $this->outputdata == null ? $this->body : $this->outputdata;
if ($this->replyTo != null) {
$mail->addReplyTo($this->replyTo['email'], $this->replyTo['name']);
}
if ($this->to != null) {
foreach($this->to as $email) {
$mail->AddAddress($email['email'], $email['name']);
}
}
if ($this->bcc != null) {
foreach($this->bcc as $email) {
$mail->addBCC($email['email'], $email['name']);
}
}
if ($this->cc != null) {
foreach($this->cc as $email) {
$mail->addCC($email['email'], $email['name']);
}
}
if ($this->attachment != null) {
foreach($this->attachment as $attachment) {
$mail->addAttachment($attachment['file'], $attachment['name']);
}
}
if(!$mail->Send()) {
return ["status" => "failed", "reason" => $mail->ErrorInfo];
}
return ["status" => "success"];
} | php | public function send(?string $message = null, ?string $subject = null)
{
if ($message != null) {
$this->body = $message;
}
if ($subject != null) {
$this->subject = $subject;
}
if ($this->viewLocation != null || $this->viewLocation !== '') {
$this->render($this->viewLocation, $this->viewArgs);
}
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = $this->connection['encryption'];
$mail->SMTPKeepAlive = true;
$mail->Host = $this->connection['host'];
$mail->Port = $this->connection['port'];
$mail->IsHTML(true);
$mail->Username = $this->connection['username'];
$mail->Password = $this->connection['password'];
$mail->SetFrom($this->connection['from']['address'], $this->connection['from']['name']);
$mail->Subject = $this->subject;
$mail->Body = $this->outputdata == null ? $this->body : $this->outputdata;
if ($this->replyTo != null) {
$mail->addReplyTo($this->replyTo['email'], $this->replyTo['name']);
}
if ($this->to != null) {
foreach($this->to as $email) {
$mail->AddAddress($email['email'], $email['name']);
}
}
if ($this->bcc != null) {
foreach($this->bcc as $email) {
$mail->addBCC($email['email'], $email['name']);
}
}
if ($this->cc != null) {
foreach($this->cc as $email) {
$mail->addCC($email['email'], $email['name']);
}
}
if ($this->attachment != null) {
foreach($this->attachment as $attachment) {
$mail->addAttachment($attachment['file'], $attachment['name']);
}
}
if(!$mail->Send()) {
return ["status" => "failed", "reason" => $mail->ErrorInfo];
}
return ["status" => "success"];
} | [
"public",
"function",
"send",
"(",
"?",
"string",
"$",
"message",
"=",
"null",
",",
"?",
"string",
"$",
"subject",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"message",
"!=",
"null",
")",
"{",
"$",
"this",
"->",
"body",
"=",
"$",
"message",
";",
"}",
"if",
"(",
"$",
"subject",
"!=",
"null",
")",
"{",
"$",
"this",
"->",
"subject",
"=",
"$",
"subject",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"viewLocation",
"!=",
"null",
"||",
"$",
"this",
"->",
"viewLocation",
"!==",
"''",
")",
"{",
"$",
"this",
"->",
"render",
"(",
"$",
"this",
"->",
"viewLocation",
",",
"$",
"this",
"->",
"viewArgs",
")",
";",
"}",
"$",
"mail",
"=",
"new",
"PHPMailer",
"(",
")",
";",
"$",
"mail",
"->",
"IsSMTP",
"(",
")",
";",
"$",
"mail",
"->",
"SMTPDebug",
"=",
"0",
";",
"$",
"mail",
"->",
"SMTPAuth",
"=",
"true",
";",
"$",
"mail",
"->",
"SMTPSecure",
"=",
"$",
"this",
"->",
"connection",
"[",
"'encryption'",
"]",
";",
"$",
"mail",
"->",
"SMTPKeepAlive",
"=",
"true",
";",
"$",
"mail",
"->",
"Host",
"=",
"$",
"this",
"->",
"connection",
"[",
"'host'",
"]",
";",
"$",
"mail",
"->",
"Port",
"=",
"$",
"this",
"->",
"connection",
"[",
"'port'",
"]",
";",
"$",
"mail",
"->",
"IsHTML",
"(",
"true",
")",
";",
"$",
"mail",
"->",
"Username",
"=",
"$",
"this",
"->",
"connection",
"[",
"'username'",
"]",
";",
"$",
"mail",
"->",
"Password",
"=",
"$",
"this",
"->",
"connection",
"[",
"'password'",
"]",
";",
"$",
"mail",
"->",
"SetFrom",
"(",
"$",
"this",
"->",
"connection",
"[",
"'from'",
"]",
"[",
"'address'",
"]",
",",
"$",
"this",
"->",
"connection",
"[",
"'from'",
"]",
"[",
"'name'",
"]",
")",
";",
"$",
"mail",
"->",
"Subject",
"=",
"$",
"this",
"->",
"subject",
";",
"$",
"mail",
"->",
"Body",
"=",
"$",
"this",
"->",
"outputdata",
"==",
"null",
"?",
"$",
"this",
"->",
"body",
":",
"$",
"this",
"->",
"outputdata",
";",
"if",
"(",
"$",
"this",
"->",
"replyTo",
"!=",
"null",
")",
"{",
"$",
"mail",
"->",
"addReplyTo",
"(",
"$",
"this",
"->",
"replyTo",
"[",
"'email'",
"]",
",",
"$",
"this",
"->",
"replyTo",
"[",
"'name'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"to",
"!=",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"to",
"as",
"$",
"email",
")",
"{",
"$",
"mail",
"->",
"AddAddress",
"(",
"$",
"email",
"[",
"'email'",
"]",
",",
"$",
"email",
"[",
"'name'",
"]",
")",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"bcc",
"!=",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"bcc",
"as",
"$",
"email",
")",
"{",
"$",
"mail",
"->",
"addBCC",
"(",
"$",
"email",
"[",
"'email'",
"]",
",",
"$",
"email",
"[",
"'name'",
"]",
")",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"cc",
"!=",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"cc",
"as",
"$",
"email",
")",
"{",
"$",
"mail",
"->",
"addCC",
"(",
"$",
"email",
"[",
"'email'",
"]",
",",
"$",
"email",
"[",
"'name'",
"]",
")",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"attachment",
"!=",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"attachment",
"as",
"$",
"attachment",
")",
"{",
"$",
"mail",
"->",
"addAttachment",
"(",
"$",
"attachment",
"[",
"'file'",
"]",
",",
"$",
"attachment",
"[",
"'name'",
"]",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"mail",
"->",
"Send",
"(",
")",
")",
"{",
"return",
"[",
"\"status\"",
"=>",
"\"failed\"",
",",
"\"reason\"",
"=>",
"$",
"mail",
"->",
"ErrorInfo",
"]",
";",
"}",
"return",
"[",
"\"status\"",
"=>",
"\"success\"",
"]",
";",
"}"
] | Finally send the email!!!
@param mixed ?string
@param mixed ?string
@return void | [
"Finally",
"send",
"the",
"email!!!"
] | c1e127539b13d3ec8381e41c64b881e0701807f5 | https://github.com/modulusphp/utility/blob/c1e127539b13d3ec8381e41c64b881e0701807f5/Mail.php#L330-L394 | train |
phossa/phossa-di | src/Phossa/Di/Definition/Loader/LoaderXml.php | LoaderXml.xmlToArray | protected static function xmlToArray(\SimpleXMLElement $xml)/*# : array */
{
$arr = array();
foreach ($xml as $element) {
$tag = $element->getName();
$ele = get_object_vars($element);
if (!empty($ele)) {
$arr[$tag] = $element instanceof \SimpleXMLElement ?
static::xmlToArray($element) :
$ele;
} else {
$arr[$tag] = trim($element);
}
}
return $arr;
} | php | protected static function xmlToArray(\SimpleXMLElement $xml)/*# : array */
{
$arr = array();
foreach ($xml as $element) {
$tag = $element->getName();
$ele = get_object_vars($element);
if (!empty($ele)) {
$arr[$tag] = $element instanceof \SimpleXMLElement ?
static::xmlToArray($element) :
$ele;
} else {
$arr[$tag] = trim($element);
}
}
return $arr;
} | [
"protected",
"static",
"function",
"xmlToArray",
"(",
"\\",
"SimpleXMLElement",
"$",
"xml",
")",
"/*# : array */",
"{",
"$",
"arr",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"xml",
"as",
"$",
"element",
")",
"{",
"$",
"tag",
"=",
"$",
"element",
"->",
"getName",
"(",
")",
";",
"$",
"ele",
"=",
"get_object_vars",
"(",
"$",
"element",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"ele",
")",
")",
"{",
"$",
"arr",
"[",
"$",
"tag",
"]",
"=",
"$",
"element",
"instanceof",
"\\",
"SimpleXMLElement",
"?",
"static",
"::",
"xmlToArray",
"(",
"$",
"element",
")",
":",
"$",
"ele",
";",
"}",
"else",
"{",
"$",
"arr",
"[",
"$",
"tag",
"]",
"=",
"trim",
"(",
"$",
"element",
")",
";",
"}",
"}",
"return",
"$",
"arr",
";",
"}"
] | Convert SimpleXML object to array
@param \SimpleXMLElement $xml the xml object
@return array
@access protected
@static | [
"Convert",
"SimpleXML",
"object",
"to",
"array"
] | bbe1e95b081068e2bc49c6cd465f38aab0374be5 | https://github.com/phossa/phossa-di/blob/bbe1e95b081068e2bc49c6cd465f38aab0374be5/src/Phossa/Di/Definition/Loader/LoaderXml.php#L55-L70 | train |
agentmedia/phine-core | src/Core/Logic/Rendering/PageRenderer.php | PageRenderer.RenderArea | protected function RenderArea($name)
{
$area = $this->areas[$name];
if (!$area)
{
throw new \InvalidArgumentException("Invalid area name $name");
}
$layoutAreaRenderer = new LayoutAreaRenderer($area);
$result = $layoutAreaRenderer->Render();
$pageAreaRenderer = new PageAreaRenderer($this->page, $area);
$result .= $pageAreaRenderer->Render();
return $result;
} | php | protected function RenderArea($name)
{
$area = $this->areas[$name];
if (!$area)
{
throw new \InvalidArgumentException("Invalid area name $name");
}
$layoutAreaRenderer = new LayoutAreaRenderer($area);
$result = $layoutAreaRenderer->Render();
$pageAreaRenderer = new PageAreaRenderer($this->page, $area);
$result .= $pageAreaRenderer->Render();
return $result;
} | [
"protected",
"function",
"RenderArea",
"(",
"$",
"name",
")",
"{",
"$",
"area",
"=",
"$",
"this",
"->",
"areas",
"[",
"$",
"name",
"]",
";",
"if",
"(",
"!",
"$",
"area",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid area name $name\"",
")",
";",
"}",
"$",
"layoutAreaRenderer",
"=",
"new",
"LayoutAreaRenderer",
"(",
"$",
"area",
")",
";",
"$",
"result",
"=",
"$",
"layoutAreaRenderer",
"->",
"Render",
"(",
")",
";",
"$",
"pageAreaRenderer",
"=",
"new",
"PageAreaRenderer",
"(",
"$",
"this",
"->",
"page",
",",
"$",
"area",
")",
";",
"$",
"result",
".=",
"$",
"pageAreaRenderer",
"->",
"Render",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Renders the area with the given name
@param string $name The area name
@return string Returns the rendering output for the area
@throws \InvalidArgumentException Raises an exception on invalid area name | [
"Renders",
"the",
"area",
"with",
"the",
"given",
"name"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Rendering/PageRenderer.php#L90-L103 | train |
agentmedia/phine-core | src/Core/Logic/Rendering/PageRenderer.php | PageRenderer.Render | function Render()
{
self::$currentPage = $this->page;
self::$Title = self::$currentPage->GetTitle();
self::$Description = self::$currentPage->GetDescription();
self::$Keywords = self::$currentPage->GetKeywords();
if ($this->page->GetType() == (string)PageType::NotFound())
{
header('HTTP/1.0 404 Not Found');
}
else if ($this->page->GetType() !== (string)PageType::Normal())
{
throw new \Exception('Internal phine error: not normal page called');
}
ob_start();
require PathUtil::LayoutTemplate($this->layout);
$result = ob_get_clean();
$replacer = new Replacer();
return $replacer->RealizeVariables($result);
} | php | function Render()
{
self::$currentPage = $this->page;
self::$Title = self::$currentPage->GetTitle();
self::$Description = self::$currentPage->GetDescription();
self::$Keywords = self::$currentPage->GetKeywords();
if ($this->page->GetType() == (string)PageType::NotFound())
{
header('HTTP/1.0 404 Not Found');
}
else if ($this->page->GetType() !== (string)PageType::Normal())
{
throw new \Exception('Internal phine error: not normal page called');
}
ob_start();
require PathUtil::LayoutTemplate($this->layout);
$result = ob_get_clean();
$replacer = new Replacer();
return $replacer->RealizeVariables($result);
} | [
"function",
"Render",
"(",
")",
"{",
"self",
"::",
"$",
"currentPage",
"=",
"$",
"this",
"->",
"page",
";",
"self",
"::",
"$",
"Title",
"=",
"self",
"::",
"$",
"currentPage",
"->",
"GetTitle",
"(",
")",
";",
"self",
"::",
"$",
"Description",
"=",
"self",
"::",
"$",
"currentPage",
"->",
"GetDescription",
"(",
")",
";",
"self",
"::",
"$",
"Keywords",
"=",
"self",
"::",
"$",
"currentPage",
"->",
"GetKeywords",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"page",
"->",
"GetType",
"(",
")",
"==",
"(",
"string",
")",
"PageType",
"::",
"NotFound",
"(",
")",
")",
"{",
"header",
"(",
"'HTTP/1.0 404 Not Found'",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"page",
"->",
"GetType",
"(",
")",
"!==",
"(",
"string",
")",
"PageType",
"::",
"Normal",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Internal phine error: not normal page called'",
")",
";",
"}",
"ob_start",
"(",
")",
";",
"require",
"PathUtil",
"::",
"LayoutTemplate",
"(",
"$",
"this",
"->",
"layout",
")",
";",
"$",
"result",
"=",
"ob_get_clean",
"(",
")",
";",
"$",
"replacer",
"=",
"new",
"Replacer",
"(",
")",
";",
"return",
"$",
"replacer",
"->",
"RealizeVariables",
"(",
"$",
"result",
")",
";",
"}"
] | Renders the complete page by requiring the page layout
@return string Returns the page contents | [
"Renders",
"the",
"complete",
"page",
"by",
"requiring",
"the",
"page",
"layout"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Rendering/PageRenderer.php#L109-L128 | train |
Polosa/shade-framework-core | app/Router/Wildcard.php | Wildcard.getRoute | protected function getRoute($destination)
{
$destinationPieces = explode('/', $destination);
$mappingNode = $this->routeMapping;
$argValues = array();
foreach($destinationPieces as $destinationPiece) {
if (isset($mappingNode[$destinationPiece])) {
$mappingNode = $mappingNode[$destinationPiece];
} elseif (isset($mappingNode['_wildcard'])) {
$argValues[] = $destinationPiece;
$mappingNode = $mappingNode['_wildcard'];
} else {
throw new Exception("Route mapping not found for destination '{$destination}'");
}
}
if (!isset($mappingNode['_mapping']) || !($mappingNode['_mapping'] instanceof Route\Mapping)) {
throw new Exception("Route mapping not found for destination '{$destination}'");
}
/**
* @var Route\Mapping $mapping;
*/
$mapping = $mappingNode['_mapping'];
$patternPieces = explode('/', $mapping->destinationPattern());
$routeArgs = array();
foreach ($patternPieces as $piece) {
if($this->isWildcard($piece)) {
$argName = substr($piece, 1, -1);
$routeArgs[$argName] = array_shift($argValues);
}
}
$this->validateRouteMapping($mapping);
return new Route($mapping->controller(), $mapping->action(), $routeArgs);
} | php | protected function getRoute($destination)
{
$destinationPieces = explode('/', $destination);
$mappingNode = $this->routeMapping;
$argValues = array();
foreach($destinationPieces as $destinationPiece) {
if (isset($mappingNode[$destinationPiece])) {
$mappingNode = $mappingNode[$destinationPiece];
} elseif (isset($mappingNode['_wildcard'])) {
$argValues[] = $destinationPiece;
$mappingNode = $mappingNode['_wildcard'];
} else {
throw new Exception("Route mapping not found for destination '{$destination}'");
}
}
if (!isset($mappingNode['_mapping']) || !($mappingNode['_mapping'] instanceof Route\Mapping)) {
throw new Exception("Route mapping not found for destination '{$destination}'");
}
/**
* @var Route\Mapping $mapping;
*/
$mapping = $mappingNode['_mapping'];
$patternPieces = explode('/', $mapping->destinationPattern());
$routeArgs = array();
foreach ($patternPieces as $piece) {
if($this->isWildcard($piece)) {
$argName = substr($piece, 1, -1);
$routeArgs[$argName] = array_shift($argValues);
}
}
$this->validateRouteMapping($mapping);
return new Route($mapping->controller(), $mapping->action(), $routeArgs);
} | [
"protected",
"function",
"getRoute",
"(",
"$",
"destination",
")",
"{",
"$",
"destinationPieces",
"=",
"explode",
"(",
"'/'",
",",
"$",
"destination",
")",
";",
"$",
"mappingNode",
"=",
"$",
"this",
"->",
"routeMapping",
";",
"$",
"argValues",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"destinationPieces",
"as",
"$",
"destinationPiece",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"mappingNode",
"[",
"$",
"destinationPiece",
"]",
")",
")",
"{",
"$",
"mappingNode",
"=",
"$",
"mappingNode",
"[",
"$",
"destinationPiece",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"mappingNode",
"[",
"'_wildcard'",
"]",
")",
")",
"{",
"$",
"argValues",
"[",
"]",
"=",
"$",
"destinationPiece",
";",
"$",
"mappingNode",
"=",
"$",
"mappingNode",
"[",
"'_wildcard'",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"\"Route mapping not found for destination '{$destination}'\"",
")",
";",
"}",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"mappingNode",
"[",
"'_mapping'",
"]",
")",
"||",
"!",
"(",
"$",
"mappingNode",
"[",
"'_mapping'",
"]",
"instanceof",
"Route",
"\\",
"Mapping",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Route mapping not found for destination '{$destination}'\"",
")",
";",
"}",
"/**\n * @var Route\\Mapping $mapping;\n */",
"$",
"mapping",
"=",
"$",
"mappingNode",
"[",
"'_mapping'",
"]",
";",
"$",
"patternPieces",
"=",
"explode",
"(",
"'/'",
",",
"$",
"mapping",
"->",
"destinationPattern",
"(",
")",
")",
";",
"$",
"routeArgs",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"patternPieces",
"as",
"$",
"piece",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isWildcard",
"(",
"$",
"piece",
")",
")",
"{",
"$",
"argName",
"=",
"substr",
"(",
"$",
"piece",
",",
"1",
",",
"-",
"1",
")",
";",
"$",
"routeArgs",
"[",
"$",
"argName",
"]",
"=",
"array_shift",
"(",
"$",
"argValues",
")",
";",
"}",
"}",
"$",
"this",
"->",
"validateRouteMapping",
"(",
"$",
"mapping",
")",
";",
"return",
"new",
"Route",
"(",
"$",
"mapping",
"->",
"controller",
"(",
")",
",",
"$",
"mapping",
"->",
"action",
"(",
")",
",",
"$",
"routeArgs",
")",
";",
"}"
] | Get Route for given destination
@param string $destination Destination
@throws \Shade\Exception
@return Route | [
"Get",
"Route",
"for",
"given",
"destination"
] | d735d3e8e0616fb9cf4ffc25b8425762ed07940f | https://github.com/Polosa/shade-framework-core/blob/d735d3e8e0616fb9cf4ffc25b8425762ed07940f/app/Router/Wildcard.php#L48-L86 | train |
Polosa/shade-framework-core | app/Router/Wildcard.php | Wildcard.addMapping | public function addMapping($destinationPattern, $controllerClass, $actionName)
{
$mapping = new Route\Mapping($destinationPattern, $controllerClass, $actionName);
$this->reverseMapping[$controllerClass][$actionName] = $mapping;
$destinationPieces = explode('/', $destinationPattern);
$mappingNode = &$this->routeMapping;
foreach($destinationPieces as $destinationPiece) {
if ($this->isWildcard($destinationPiece)) {
if (!isset($mappingNode['_wildcard'])) {
$mappingNode['_wildcard'] = null;
}
$mappingNode = &$mappingNode['_wildcard'];
} else {
if (!isset($mappingNode[$destinationPiece])) {
$mappingNode[$destinationPiece] = null;
}
$mappingNode = &$mappingNode[$destinationPiece];
}
}
$mappingNode['_mapping'] = $mapping;
return $mapping;
} | php | public function addMapping($destinationPattern, $controllerClass, $actionName)
{
$mapping = new Route\Mapping($destinationPattern, $controllerClass, $actionName);
$this->reverseMapping[$controllerClass][$actionName] = $mapping;
$destinationPieces = explode('/', $destinationPattern);
$mappingNode = &$this->routeMapping;
foreach($destinationPieces as $destinationPiece) {
if ($this->isWildcard($destinationPiece)) {
if (!isset($mappingNode['_wildcard'])) {
$mappingNode['_wildcard'] = null;
}
$mappingNode = &$mappingNode['_wildcard'];
} else {
if (!isset($mappingNode[$destinationPiece])) {
$mappingNode[$destinationPiece] = null;
}
$mappingNode = &$mappingNode[$destinationPiece];
}
}
$mappingNode['_mapping'] = $mapping;
return $mapping;
} | [
"public",
"function",
"addMapping",
"(",
"$",
"destinationPattern",
",",
"$",
"controllerClass",
",",
"$",
"actionName",
")",
"{",
"$",
"mapping",
"=",
"new",
"Route",
"\\",
"Mapping",
"(",
"$",
"destinationPattern",
",",
"$",
"controllerClass",
",",
"$",
"actionName",
")",
";",
"$",
"this",
"->",
"reverseMapping",
"[",
"$",
"controllerClass",
"]",
"[",
"$",
"actionName",
"]",
"=",
"$",
"mapping",
";",
"$",
"destinationPieces",
"=",
"explode",
"(",
"'/'",
",",
"$",
"destinationPattern",
")",
";",
"$",
"mappingNode",
"=",
"&",
"$",
"this",
"->",
"routeMapping",
";",
"foreach",
"(",
"$",
"destinationPieces",
"as",
"$",
"destinationPiece",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isWildcard",
"(",
"$",
"destinationPiece",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"mappingNode",
"[",
"'_wildcard'",
"]",
")",
")",
"{",
"$",
"mappingNode",
"[",
"'_wildcard'",
"]",
"=",
"null",
";",
"}",
"$",
"mappingNode",
"=",
"&",
"$",
"mappingNode",
"[",
"'_wildcard'",
"]",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"mappingNode",
"[",
"$",
"destinationPiece",
"]",
")",
")",
"{",
"$",
"mappingNode",
"[",
"$",
"destinationPiece",
"]",
"=",
"null",
";",
"}",
"$",
"mappingNode",
"=",
"&",
"$",
"mappingNode",
"[",
"$",
"destinationPiece",
"]",
";",
"}",
"}",
"$",
"mappingNode",
"[",
"'_mapping'",
"]",
"=",
"$",
"mapping",
";",
"return",
"$",
"mapping",
";",
"}"
] | Add route mapping
@param string $destinationPattern Destination pattern
@param string $controllerClass Controller class
@param string $actionName Action name
@return \Shade\Route\Mapping
@throws Exception | [
"Add",
"route",
"mapping"
] | d735d3e8e0616fb9cf4ffc25b8425762ed07940f | https://github.com/Polosa/shade-framework-core/blob/d735d3e8e0616fb9cf4ffc25b8425762ed07940f/app/Router/Wildcard.php#L114-L139 | train |
Polosa/shade-framework-core | app/Controller/Profiler.php | Profiler.outputAction | public function outputAction($startTime, $showProfiler)
{
$data = ['showProfiler' => $showProfiler];
if ($showProfiler) {
$data = [
'showProfiler' => true,
'memory' => \Shade\Converter::formatBytes(memory_get_usage(true)),
'memoryPeak' => \Shade\Converter::formatBytes(memory_get_peak_usage(true)),
'execTime' => (microtime(true) - $startTime),
];
}
return $this->render('system/profiler.phtml', $data);
} | php | public function outputAction($startTime, $showProfiler)
{
$data = ['showProfiler' => $showProfiler];
if ($showProfiler) {
$data = [
'showProfiler' => true,
'memory' => \Shade\Converter::formatBytes(memory_get_usage(true)),
'memoryPeak' => \Shade\Converter::formatBytes(memory_get_peak_usage(true)),
'execTime' => (microtime(true) - $startTime),
];
}
return $this->render('system/profiler.phtml', $data);
} | [
"public",
"function",
"outputAction",
"(",
"$",
"startTime",
",",
"$",
"showProfiler",
")",
"{",
"$",
"data",
"=",
"[",
"'showProfiler'",
"=>",
"$",
"showProfiler",
"]",
";",
"if",
"(",
"$",
"showProfiler",
")",
"{",
"$",
"data",
"=",
"[",
"'showProfiler'",
"=>",
"true",
",",
"'memory'",
"=>",
"\\",
"Shade",
"\\",
"Converter",
"::",
"formatBytes",
"(",
"memory_get_usage",
"(",
"true",
")",
")",
",",
"'memoryPeak'",
"=>",
"\\",
"Shade",
"\\",
"Converter",
"::",
"formatBytes",
"(",
"memory_get_peak_usage",
"(",
"true",
")",
")",
",",
"'execTime'",
"=>",
"(",
"microtime",
"(",
"true",
")",
"-",
"$",
"startTime",
")",
",",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'system/profiler.phtml'",
",",
"$",
"data",
")",
";",
"}"
] | Output profiler information
@param string $startTime Application start time
@param bool $showProfiler Is debug mode enabled
@return \Shade\Response | [
"Output",
"profiler",
"information"
] | d735d3e8e0616fb9cf4ffc25b8425762ed07940f | https://github.com/Polosa/shade-framework-core/blob/d735d3e8e0616fb9cf4ffc25b8425762ed07940f/app/Controller/Profiler.php#L28-L41 | train |
AnonymPHP/Anonym-HttpFoundation | Response.php | Response.header | public function header($name, $value = null)
{
if ($value === null) {
$this->headers[] = $name;
} else {
$this->headers[] = $this->headerString($name, $value);
}
return $this;
} | php | public function header($name, $value = null)
{
if ($value === null) {
$this->headers[] = $name;
} else {
$this->headers[] = $this->headerString($name, $value);
}
return $this;
} | [
"public",
"function",
"header",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"headers",
"[",
"]",
"=",
"$",
"name",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"headers",
"[",
"]",
"=",
"$",
"this",
"->",
"headerString",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Header kodu ekler mesaja
@param $name
@param null $value
@return $this | [
"Header",
"kodu",
"ekler",
"mesaja"
] | 943e5f40f45bc2e11a4b9e1d22c6583c31dc4317 | https://github.com/AnonymPHP/Anonym-HttpFoundation/blob/943e5f40f45bc2e11a4b9e1d22c6583c31dc4317/Response.php#L297-L307 | train |
bseddon/XPath20 | lyquidity/Convert.php | Convert.ToChar | public static function ToChar( $value, $provider = null )
{
if ( $value instanceof \DateTime )
{
$value = Convert::ToString( $value, $provider );
if ( is_null( $value ) ) return null;
}
if ( is_string( $value ) && strlen( $value ) )
{
return $value[0];
}
else if ( is_numeric( $value ) )
{
$ord = $value & 255;
return chr( $ord );
}
return null;
} | php | public static function ToChar( $value, $provider = null )
{
if ( $value instanceof \DateTime )
{
$value = Convert::ToString( $value, $provider );
if ( is_null( $value ) ) return null;
}
if ( is_string( $value ) && strlen( $value ) )
{
return $value[0];
}
else if ( is_numeric( $value ) )
{
$ord = $value & 255;
return chr( $ord );
}
return null;
} | [
"public",
"static",
"function",
"ToChar",
"(",
"$",
"value",
",",
"$",
"provider",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"\\",
"DateTime",
")",
"{",
"$",
"value",
"=",
"Convert",
"::",
"ToString",
"(",
"$",
"value",
",",
"$",
"provider",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"return",
"null",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
"&&",
"strlen",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"value",
"[",
"0",
"]",
";",
"}",
"else",
"if",
"(",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"$",
"ord",
"=",
"$",
"value",
"&",
"255",
";",
"return",
"chr",
"(",
"$",
"ord",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Converts the value of this instance to an equivalent Unicode character using
the specified culture-specific formatting information.
@param object $value The value to convert
@param IFormatProvider $provider An interface implementation that supplies culture-specific formatting information.
@return char A Unicode character equivalent to the value of this instance. | [
"Converts",
"the",
"value",
"of",
"this",
"instance",
"to",
"an",
"equivalent",
"Unicode",
"character",
"using",
"the",
"specified",
"culture",
"-",
"specific",
"formatting",
"information",
"."
] | 69882b6efffaa5470a819d5fdd2f6473ddeb046d | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/lyquidity/Convert.php#L87-L106 | train |
bseddon/XPath20 | lyquidity/Convert.php | Convert.ChangeType | public static function ChangeType( $value, $conversionType, $provider = null )
{
return Convert::ToType( $value, $conversionType, $provider );
} | php | public static function ChangeType( $value, $conversionType, $provider = null )
{
return Convert::ToType( $value, $conversionType, $provider );
} | [
"public",
"static",
"function",
"ChangeType",
"(",
"$",
"value",
",",
"$",
"conversionType",
",",
"$",
"provider",
"=",
"null",
")",
"{",
"return",
"Convert",
"::",
"ToType",
"(",
"$",
"value",
",",
"$",
"conversionType",
",",
"$",
"provider",
")",
";",
"}"
] | ChangeType an alias for ToType
@param object $value
@param Type $conversionType
@param NodeProvider $provider (optional)
@return object | [
"ChangeType",
"an",
"alias",
"for",
"ToType"
] | 69882b6efffaa5470a819d5fdd2f6473ddeb046d | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/lyquidity/Convert.php#L115-L118 | train |
bseddon/XPath20 | lyquidity/Convert.php | Convert.ToDateTime | public static function ToDateTime( $value, $provider = null )
{
if ( $value instanceof \DateTime ) return $value;
if ( is_string( $value ) )
{
$timestamp = strtotime( $value );
if ( $timestamp === false ) return null;
/**
* @var \DateTime $dt
*/
$dt = new \DateTime();
$dt->setTimestamp( $timestamp );
return $dt;
}
$value = Convert::ToInt( $value, $provider );
if ( is_null( $value ) ) return null;
$dt = new \DateTime();
$dt->setTimestamp( $value );
return $dt;
} | php | public static function ToDateTime( $value, $provider = null )
{
if ( $value instanceof \DateTime ) return $value;
if ( is_string( $value ) )
{
$timestamp = strtotime( $value );
if ( $timestamp === false ) return null;
/**
* @var \DateTime $dt
*/
$dt = new \DateTime();
$dt->setTimestamp( $timestamp );
return $dt;
}
$value = Convert::ToInt( $value, $provider );
if ( is_null( $value ) ) return null;
$dt = new \DateTime();
$dt->setTimestamp( $value );
return $dt;
} | [
"public",
"static",
"function",
"ToDateTime",
"(",
"$",
"value",
",",
"$",
"provider",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"\\",
"DateTime",
")",
"return",
"$",
"value",
";",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"timestamp",
"=",
"strtotime",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"timestamp",
"===",
"false",
")",
"return",
"null",
";",
"/**\r\n\t\t\t * @var \\DateTime $dt\r\n\t\t\t */",
"$",
"dt",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"dt",
"->",
"setTimestamp",
"(",
"$",
"timestamp",
")",
";",
"return",
"$",
"dt",
";",
"}",
"$",
"value",
"=",
"Convert",
"::",
"ToInt",
"(",
"$",
"value",
",",
"$",
"provider",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"return",
"null",
";",
"$",
"dt",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"dt",
"->",
"setTimestamp",
"(",
"$",
"value",
")",
";",
"return",
"$",
"dt",
";",
"}"
] | Converts the value of this instance to an equivalent DateTime using the
specified culture-specific formatting information.
@param object $value The value to convert
@param IFormatProvider $provider An interface implementation that supplies culture-specific formatting information.
@return DateTime A DateTime instance equivalent to the value of this instance. | [
"Converts",
"the",
"value",
"of",
"this",
"instance",
"to",
"an",
"equivalent",
"DateTime",
"using",
"the",
"specified",
"culture",
"-",
"specific",
"formatting",
"information",
"."
] | 69882b6efffaa5470a819d5fdd2f6473ddeb046d | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/lyquidity/Convert.php#L128-L154 | train |
bseddon/XPath20 | lyquidity/Convert.php | Convert.ToDecimal | public static function ToDecimal( $value, $provider = null )
{
return is_double( $value )
? DecimalValue::FromFloat( $value )
: new DecimalValue( $value );
// return Convert::ToDouble( $value, $provider );
} | php | public static function ToDecimal( $value, $provider = null )
{
return is_double( $value )
? DecimalValue::FromFloat( $value )
: new DecimalValue( $value );
// return Convert::ToDouble( $value, $provider );
} | [
"public",
"static",
"function",
"ToDecimal",
"(",
"$",
"value",
",",
"$",
"provider",
"=",
"null",
")",
"{",
"return",
"is_double",
"(",
"$",
"value",
")",
"?",
"DecimalValue",
"::",
"FromFloat",
"(",
"$",
"value",
")",
":",
"new",
"DecimalValue",
"(",
"$",
"value",
")",
";",
"// return Convert::ToDouble( $value, $provider );\r",
"}"
] | Converts the value of this instance to an equivalent System.Decimal number using
the specified culture-specific formatting information.
@param object $value The value to convert
@param IFormatProvider $provider An implementation that supplies culture-specific formatting information.
@return DecimalValue A Decimal number equivalent to the value of this instance. | [
"Converts",
"the",
"value",
"of",
"this",
"instance",
"to",
"an",
"equivalent",
"System",
".",
"Decimal",
"number",
"using",
"the",
"specified",
"culture",
"-",
"specific",
"formatting",
"information",
"."
] | 69882b6efffaa5470a819d5fdd2f6473ddeb046d | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/lyquidity/Convert.php#L164-L170 | train |
bseddon/XPath20 | lyquidity/Convert.php | Convert.ToDouble | public static function ToDouble( $value, $provider = null )
{
if ( $value instanceof \DateTime )
{
return NAN; // $value->getTimestamp() + 0.0;
}
else if ( ( is_numeric( $value ) && $value == INF ) || ( is_string( $value ) && strtoupper( $value ) == "INF" ) )
{
return INF;
}
else if ( ( is_numeric( $value ) && $value == -INF ) || ( is_string( $value ) && strtoupper( $value ) == "-INF" ) )
{
return -INF;
}
if ( $x = ( is_numeric( $value ) && is_nan( $value ) ) || ( is_string( $value ) && strtoupper( $value ) == "NAN" ) )
{
return NAN;
}
else if ( $value instanceof DecimalValue )
{
return $value->ToDouble( $provider );
}
else if ( is_object( $value ) )
{
$text = "unknown";
if ( $value instanceof ValueProxy )
{
/**
* @var ValueProxy $proxy
*/
$proxy = $value;
return $proxy->ToDouble( $provider );
}
else if ( $value instanceof XPath2Item || $value instanceof Integer )
{
return $value->ToDouble( $provider );
}
else if ( $value instanceof UntypedAtomic )
{
$text = $value->__toString();
if ( is_numeric( $text ) ) return $text + 0.0;
}
throw XPath2Exception::withErrorCodeAndParams( "FORG0001", Resources::FORG0001, array( $text, "xs:Double" ) );
}
else if ( is_numeric( trim( $value ) ) )
{
// This is an alternative multi-regional implementation to convert number strings
// $locale = \Collator::create( null )->getLocale( \Locale::VALID_LOCALE );
// $fmt = new \NumberFormatter( $locale, \NumberFormatter::DECIMAL );
// $num = $fmt->parse( $this->Value );
// if ( $num )
// {
// if ( $num == 0 ) $num = 0.0;
// $this->_doubleValue = $num;
// return true;
// }
return trim( $value ) + 0.0;
}
return null;
} | php | public static function ToDouble( $value, $provider = null )
{
if ( $value instanceof \DateTime )
{
return NAN; // $value->getTimestamp() + 0.0;
}
else if ( ( is_numeric( $value ) && $value == INF ) || ( is_string( $value ) && strtoupper( $value ) == "INF" ) )
{
return INF;
}
else if ( ( is_numeric( $value ) && $value == -INF ) || ( is_string( $value ) && strtoupper( $value ) == "-INF" ) )
{
return -INF;
}
if ( $x = ( is_numeric( $value ) && is_nan( $value ) ) || ( is_string( $value ) && strtoupper( $value ) == "NAN" ) )
{
return NAN;
}
else if ( $value instanceof DecimalValue )
{
return $value->ToDouble( $provider );
}
else if ( is_object( $value ) )
{
$text = "unknown";
if ( $value instanceof ValueProxy )
{
/**
* @var ValueProxy $proxy
*/
$proxy = $value;
return $proxy->ToDouble( $provider );
}
else if ( $value instanceof XPath2Item || $value instanceof Integer )
{
return $value->ToDouble( $provider );
}
else if ( $value instanceof UntypedAtomic )
{
$text = $value->__toString();
if ( is_numeric( $text ) ) return $text + 0.0;
}
throw XPath2Exception::withErrorCodeAndParams( "FORG0001", Resources::FORG0001, array( $text, "xs:Double" ) );
}
else if ( is_numeric( trim( $value ) ) )
{
// This is an alternative multi-regional implementation to convert number strings
// $locale = \Collator::create( null )->getLocale( \Locale::VALID_LOCALE );
// $fmt = new \NumberFormatter( $locale, \NumberFormatter::DECIMAL );
// $num = $fmt->parse( $this->Value );
// if ( $num )
// {
// if ( $num == 0 ) $num = 0.0;
// $this->_doubleValue = $num;
// return true;
// }
return trim( $value ) + 0.0;
}
return null;
} | [
"public",
"static",
"function",
"ToDouble",
"(",
"$",
"value",
",",
"$",
"provider",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"\\",
"DateTime",
")",
"{",
"return",
"NAN",
";",
"// $value->getTimestamp() + 0.0;\r",
"}",
"else",
"if",
"(",
"(",
"is_numeric",
"(",
"$",
"value",
")",
"&&",
"$",
"value",
"==",
"INF",
")",
"||",
"(",
"is_string",
"(",
"$",
"value",
")",
"&&",
"strtoupper",
"(",
"$",
"value",
")",
"==",
"\"INF\"",
")",
")",
"{",
"return",
"INF",
";",
"}",
"else",
"if",
"(",
"(",
"is_numeric",
"(",
"$",
"value",
")",
"&&",
"$",
"value",
"==",
"-",
"INF",
")",
"||",
"(",
"is_string",
"(",
"$",
"value",
")",
"&&",
"strtoupper",
"(",
"$",
"value",
")",
"==",
"\"-INF\"",
")",
")",
"{",
"return",
"-",
"INF",
";",
"}",
"if",
"(",
"$",
"x",
"=",
"(",
"is_numeric",
"(",
"$",
"value",
")",
"&&",
"is_nan",
"(",
"$",
"value",
")",
")",
"||",
"(",
"is_string",
"(",
"$",
"value",
")",
"&&",
"strtoupper",
"(",
"$",
"value",
")",
"==",
"\"NAN\"",
")",
")",
"{",
"return",
"NAN",
";",
"}",
"else",
"if",
"(",
"$",
"value",
"instanceof",
"DecimalValue",
")",
"{",
"return",
"$",
"value",
"->",
"ToDouble",
"(",
"$",
"provider",
")",
";",
"}",
"else",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"$",
"text",
"=",
"\"unknown\"",
";",
"if",
"(",
"$",
"value",
"instanceof",
"ValueProxy",
")",
"{",
"/**\r\n\t\t\t\t * @var ValueProxy $proxy\r\n\t\t\t\t */",
"$",
"proxy",
"=",
"$",
"value",
";",
"return",
"$",
"proxy",
"->",
"ToDouble",
"(",
"$",
"provider",
")",
";",
"}",
"else",
"if",
"(",
"$",
"value",
"instanceof",
"XPath2Item",
"||",
"$",
"value",
"instanceof",
"Integer",
")",
"{",
"return",
"$",
"value",
"->",
"ToDouble",
"(",
"$",
"provider",
")",
";",
"}",
"else",
"if",
"(",
"$",
"value",
"instanceof",
"UntypedAtomic",
")",
"{",
"$",
"text",
"=",
"$",
"value",
"->",
"__toString",
"(",
")",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"text",
")",
")",
"return",
"$",
"text",
"+",
"0.0",
";",
"}",
"throw",
"XPath2Exception",
"::",
"withErrorCodeAndParams",
"(",
"\"FORG0001\"",
",",
"Resources",
"::",
"FORG0001",
",",
"array",
"(",
"$",
"text",
",",
"\"xs:Double\"",
")",
")",
";",
"}",
"else",
"if",
"(",
"is_numeric",
"(",
"trim",
"(",
"$",
"value",
")",
")",
")",
"{",
"// This is an alternative multi-regional implementation to convert number strings\r",
"// $locale = \\Collator::create( null )->getLocale( \\Locale::VALID_LOCALE );\r",
"// $fmt = new \\NumberFormatter( $locale, \\NumberFormatter::DECIMAL );\r",
"// $num = $fmt->parse( $this->Value );\r",
"// if ( $num )\r",
"// {\r",
"// \tif ( $num == 0 ) $num = 0.0;\r",
"// \t$this->_doubleValue = $num;\r",
"// \treturn true;\r",
"// }\r",
"return",
"trim",
"(",
"$",
"value",
")",
"+",
"0.0",
";",
"}",
"return",
"null",
";",
"}"
] | Converts the value of this instance to an equivalent double-precision floating-point
number using the specified culture-specific formatting information.
@param object $value The value to convert
@param IFormatProvider $provider An interface implementation that supplies culture-specific formatting information.
@return double A double-precision floating-point number equivalent to the value of this instance. | [
"Converts",
"the",
"value",
"of",
"this",
"instance",
"to",
"an",
"equivalent",
"double",
"-",
"precision",
"floating",
"-",
"point",
"number",
"using",
"the",
"specified",
"culture",
"-",
"specific",
"formatting",
"information",
"."
] | 69882b6efffaa5470a819d5fdd2f6473ddeb046d | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/lyquidity/Convert.php#L180-L244 | train |
bseddon/XPath20 | lyquidity/Convert.php | Convert.ToString | public static function ToString( $value, $provider = null )
{
if ( $value instanceof XPath2Item )
{
return $value->getValue();
}
if ( $value instanceof \DateTime )
{
// Use locale information to create a formatted string
$collator = \Collator::create( null );
$locale = $collator->getLocale( \Locale::VALID_LOCALE );
$dateTime = \IntlDateFormatter::create( $locale, \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE );
return $dateTime->format( $value );
}
return $value . "";
} | php | public static function ToString( $value, $provider = null )
{
if ( $value instanceof XPath2Item )
{
return $value->getValue();
}
if ( $value instanceof \DateTime )
{
// Use locale information to create a formatted string
$collator = \Collator::create( null );
$locale = $collator->getLocale( \Locale::VALID_LOCALE );
$dateTime = \IntlDateFormatter::create( $locale, \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE );
return $dateTime->format( $value );
}
return $value . "";
} | [
"public",
"static",
"function",
"ToString",
"(",
"$",
"value",
",",
"$",
"provider",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"XPath2Item",
")",
"{",
"return",
"$",
"value",
"->",
"getValue",
"(",
")",
";",
"}",
"if",
"(",
"$",
"value",
"instanceof",
"\\",
"DateTime",
")",
"{",
"// Use locale information to create a formatted string\r",
"$",
"collator",
"=",
"\\",
"Collator",
"::",
"create",
"(",
"null",
")",
";",
"$",
"locale",
"=",
"$",
"collator",
"->",
"getLocale",
"(",
"\\",
"Locale",
"::",
"VALID_LOCALE",
")",
";",
"$",
"dateTime",
"=",
"\\",
"IntlDateFormatter",
"::",
"create",
"(",
"$",
"locale",
",",
"\\",
"IntlDateFormatter",
"::",
"SHORT",
",",
"\\",
"IntlDateFormatter",
"::",
"NONE",
")",
";",
"return",
"$",
"dateTime",
"->",
"format",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"value",
".",
"\"\"",
";",
"}"
] | Converts the value of this instance to an equivalent System.String using the
specified culture-specific formatting information.
@param object $value The value to convert
@param IFormatProvider $provider An interface implementation that supplies culture-specific formatting information.
@return string A string instance equivalent to the value of this instance. | [
"Converts",
"the",
"value",
"of",
"this",
"instance",
"to",
"an",
"equivalent",
"System",
".",
"String",
"using",
"the",
"specified",
"culture",
"-",
"specific",
"formatting",
"information",
"."
] | 69882b6efffaa5470a819d5fdd2f6473ddeb046d | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/lyquidity/Convert.php#L254-L271 | train |
bseddon/XPath20 | lyquidity/Convert.php | Convert.ToInt | public static function ToInt( $value, $provider = null )
{
if ( $value instanceof ValueProxy )
{
return $value->ToInt( $provider );
}
if ( $value instanceof XPath2Item )
{
return Convert::ToInt( $value->getTypedValue(), $provider );
// return $value->ToInt( $provider );
}
if ( is_numeric( $value ) )
{
if ( $value > PHP_INT_MAX ) return PHP_INT_MAX;
if ( $value < PHP_INT_MIN ) return PHP_INT_MIN;
return intval( $value + 0 );
}
if ( $value instanceof Integer || $value instanceof IntegerProxy || $value instanceof DecimalValue || $value instanceof DecimalProxy )
{
return $value->ToInt( $provider );
}
if ( $value instanceof \DateTime )
{
return $value->getTimestamp() + 0.0;
}
if ( $value instanceof DecimalValue )
{
return $value->ToInt( $provider );
}
return null;
} | php | public static function ToInt( $value, $provider = null )
{
if ( $value instanceof ValueProxy )
{
return $value->ToInt( $provider );
}
if ( $value instanceof XPath2Item )
{
return Convert::ToInt( $value->getTypedValue(), $provider );
// return $value->ToInt( $provider );
}
if ( is_numeric( $value ) )
{
if ( $value > PHP_INT_MAX ) return PHP_INT_MAX;
if ( $value < PHP_INT_MIN ) return PHP_INT_MIN;
return intval( $value + 0 );
}
if ( $value instanceof Integer || $value instanceof IntegerProxy || $value instanceof DecimalValue || $value instanceof DecimalProxy )
{
return $value->ToInt( $provider );
}
if ( $value instanceof \DateTime )
{
return $value->getTimestamp() + 0.0;
}
if ( $value instanceof DecimalValue )
{
return $value->ToInt( $provider );
}
return null;
} | [
"public",
"static",
"function",
"ToInt",
"(",
"$",
"value",
",",
"$",
"provider",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"ValueProxy",
")",
"{",
"return",
"$",
"value",
"->",
"ToInt",
"(",
"$",
"provider",
")",
";",
"}",
"if",
"(",
"$",
"value",
"instanceof",
"XPath2Item",
")",
"{",
"return",
"Convert",
"::",
"ToInt",
"(",
"$",
"value",
"->",
"getTypedValue",
"(",
")",
",",
"$",
"provider",
")",
";",
"// return $value->ToInt( $provider );\r",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"$",
"value",
">",
"PHP_INT_MAX",
")",
"return",
"PHP_INT_MAX",
";",
"if",
"(",
"$",
"value",
"<",
"PHP_INT_MIN",
")",
"return",
"PHP_INT_MIN",
";",
"return",
"intval",
"(",
"$",
"value",
"+",
"0",
")",
";",
"}",
"if",
"(",
"$",
"value",
"instanceof",
"Integer",
"||",
"$",
"value",
"instanceof",
"IntegerProxy",
"||",
"$",
"value",
"instanceof",
"DecimalValue",
"||",
"$",
"value",
"instanceof",
"DecimalProxy",
")",
"{",
"return",
"$",
"value",
"->",
"ToInt",
"(",
"$",
"provider",
")",
";",
"}",
"if",
"(",
"$",
"value",
"instanceof",
"\\",
"DateTime",
")",
"{",
"return",
"$",
"value",
"->",
"getTimestamp",
"(",
")",
"+",
"0.0",
";",
"}",
"if",
"(",
"$",
"value",
"instanceof",
"DecimalValue",
")",
"{",
"return",
"$",
"value",
"->",
"ToInt",
"(",
"$",
"provider",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Converts the value of this instance to an equivalent integer
using the specified culture-specific formatting information.
@param object $value The value to convert
@param IFormatProvider $provider An interface implementation that supplies culture-specific formatting information.
@return int An 32-bit signed integer equivalent to the value of this instance. | [
"Converts",
"the",
"value",
"of",
"this",
"instance",
"to",
"an",
"equivalent",
"integer",
"using",
"the",
"specified",
"culture",
"-",
"specific",
"formatting",
"information",
"."
] | 69882b6efffaa5470a819d5fdd2f6473ddeb046d | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/lyquidity/Convert.php#L281-L318 | train |
AltCtrlSupr/ACSPanel-Settings | Event/Subscribers/SettingsSubscriber.php | SettingsSubscriber.updateUserSettings | public function updateUserSettings(FilterUserFieldsEvent $userfields_filter)
{
$settings_manager = $userfields_filter->getContainer()->get('acs.setting_manager');
$user = $userfields_filter->getContainer()->get('security.context')->getToken()->getUser();
$fields_template = $userfields_filter->getUserFields();
//if($settings_manager->isUpdateAvailable($user, 'user_schema_version', $fields_template['user_schema_version']['default_value'])){
// We have an update in the user fields
$settings_manager->loadSettingDefaults($fields_template, $user);
//}
} | php | public function updateUserSettings(FilterUserFieldsEvent $userfields_filter)
{
$settings_manager = $userfields_filter->getContainer()->get('acs.setting_manager');
$user = $userfields_filter->getContainer()->get('security.context')->getToken()->getUser();
$fields_template = $userfields_filter->getUserFields();
//if($settings_manager->isUpdateAvailable($user, 'user_schema_version', $fields_template['user_schema_version']['default_value'])){
// We have an update in the user fields
$settings_manager->loadSettingDefaults($fields_template, $user);
//}
} | [
"public",
"function",
"updateUserSettings",
"(",
"FilterUserFieldsEvent",
"$",
"userfields_filter",
")",
"{",
"$",
"settings_manager",
"=",
"$",
"userfields_filter",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'acs.setting_manager'",
")",
";",
"$",
"user",
"=",
"$",
"userfields_filter",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'security.context'",
")",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
";",
"$",
"fields_template",
"=",
"$",
"userfields_filter",
"->",
"getUserFields",
"(",
")",
";",
"//if($settings_manager->isUpdateAvailable($user, 'user_schema_version', $fields_template['user_schema_version']['default_value'])){",
"// We have an update in the user fields",
"$",
"settings_manager",
"->",
"loadSettingDefaults",
"(",
"$",
"fields_template",
",",
"$",
"user",
")",
";",
"//}",
"}"
] | Create new added fields to user or missing fields | [
"Create",
"new",
"added",
"fields",
"to",
"user",
"or",
"missing",
"fields"
] | b1e363bf98d4c74368b3063abba0c77bb3a61230 | https://github.com/AltCtrlSupr/ACSPanel-Settings/blob/b1e363bf98d4c74368b3063abba0c77bb3a61230/Event/Subscribers/SettingsSubscriber.php#L25-L37 | train |
aicouto/sheet | src/Sheet.php | Sheet.toArray | public function toArray($sheet_name,$ext=false)
{
if(!$ext){
$ext=pathinfo($sheet_name, PATHINFO_EXTENSION);
}
switch ($ext) {
case 'csv':
$reader = ReaderFactory::create(Type::CSV);
break;
case 'ods':
$reader = ReaderFactory::create(Type::ODS);
break;
case 'xlsx':
$reader = ReaderFactory::create(Type::XLSX);
break;
}
$reader->open($sheet_name);
foreach ($reader->getSheetIterator() as $sheet) {
$sheetName = $sheet->getName();
foreach ($sheet->getRowIterator() as $row) {
$list['lists'][$sheetName][]=$row;
}
}
$reader->close();
$lists=false;
foreach ($list['lists'] as $key => $value) {
$lists[$key]=$this->sheetToAlpha($value);
}
if($ext=="csv"){
return $lists[""];
}else{
return $lists;
}
} | php | public function toArray($sheet_name,$ext=false)
{
if(!$ext){
$ext=pathinfo($sheet_name, PATHINFO_EXTENSION);
}
switch ($ext) {
case 'csv':
$reader = ReaderFactory::create(Type::CSV);
break;
case 'ods':
$reader = ReaderFactory::create(Type::ODS);
break;
case 'xlsx':
$reader = ReaderFactory::create(Type::XLSX);
break;
}
$reader->open($sheet_name);
foreach ($reader->getSheetIterator() as $sheet) {
$sheetName = $sheet->getName();
foreach ($sheet->getRowIterator() as $row) {
$list['lists'][$sheetName][]=$row;
}
}
$reader->close();
$lists=false;
foreach ($list['lists'] as $key => $value) {
$lists[$key]=$this->sheetToAlpha($value);
}
if($ext=="csv"){
return $lists[""];
}else{
return $lists;
}
} | [
"public",
"function",
"toArray",
"(",
"$",
"sheet_name",
",",
"$",
"ext",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"ext",
")",
"{",
"$",
"ext",
"=",
"pathinfo",
"(",
"$",
"sheet_name",
",",
"PATHINFO_EXTENSION",
")",
";",
"}",
"switch",
"(",
"$",
"ext",
")",
"{",
"case",
"'csv'",
":",
"$",
"reader",
"=",
"ReaderFactory",
"::",
"create",
"(",
"Type",
"::",
"CSV",
")",
";",
"break",
";",
"case",
"'ods'",
":",
"$",
"reader",
"=",
"ReaderFactory",
"::",
"create",
"(",
"Type",
"::",
"ODS",
")",
";",
"break",
";",
"case",
"'xlsx'",
":",
"$",
"reader",
"=",
"ReaderFactory",
"::",
"create",
"(",
"Type",
"::",
"XLSX",
")",
";",
"break",
";",
"}",
"$",
"reader",
"->",
"open",
"(",
"$",
"sheet_name",
")",
";",
"foreach",
"(",
"$",
"reader",
"->",
"getSheetIterator",
"(",
")",
"as",
"$",
"sheet",
")",
"{",
"$",
"sheetName",
"=",
"$",
"sheet",
"->",
"getName",
"(",
")",
";",
"foreach",
"(",
"$",
"sheet",
"->",
"getRowIterator",
"(",
")",
"as",
"$",
"row",
")",
"{",
"$",
"list",
"[",
"'lists'",
"]",
"[",
"$",
"sheetName",
"]",
"[",
"]",
"=",
"$",
"row",
";",
"}",
"}",
"$",
"reader",
"->",
"close",
"(",
")",
";",
"$",
"lists",
"=",
"false",
";",
"foreach",
"(",
"$",
"list",
"[",
"'lists'",
"]",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"lists",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"sheetToAlpha",
"(",
"$",
"value",
")",
";",
"}",
"if",
"(",
"$",
"ext",
"==",
"\"csv\"",
")",
"{",
"return",
"$",
"lists",
"[",
"\"\"",
"]",
";",
"}",
"else",
"{",
"return",
"$",
"lists",
";",
"}",
"}"
] | Converte uma planilha para array | [
"Converte",
"uma",
"planilha",
"para",
"array"
] | 9cd7e850050208b3ab96e7a9fd82e88fd47151ce | https://github.com/aicouto/sheet/blob/9cd7e850050208b3ab96e7a9fd82e88fd47151ce/src/Sheet.php#L59-L92 | train |
aicouto/sheet | src/Sheet.php | Sheet.toSheet | public function toSheet($array, $sheet_name, $ext=false)
{
if(!$ext){
$ext=pathinfo($sheet_name, PATHINFO_EXTENSION);
}
switch ($ext) {
case 'csv':
$writer = WriterFactory::create(Type::CSV);
break;
case 'ods':
$writer = WriterFactory::create(Type::ODS);
break;
case 'xlsx':
$writer = WriterFactory::create(Type::XLSX);
break;
}
@$writer->openToFile($sheet_name);
foreach ($array as $row) {
$writer->addRow($row);
}
if (is_null($writer->close())) {
return true;
} else {
return false;
}
} | php | public function toSheet($array, $sheet_name, $ext=false)
{
if(!$ext){
$ext=pathinfo($sheet_name, PATHINFO_EXTENSION);
}
switch ($ext) {
case 'csv':
$writer = WriterFactory::create(Type::CSV);
break;
case 'ods':
$writer = WriterFactory::create(Type::ODS);
break;
case 'xlsx':
$writer = WriterFactory::create(Type::XLSX);
break;
}
@$writer->openToFile($sheet_name);
foreach ($array as $row) {
$writer->addRow($row);
}
if (is_null($writer->close())) {
return true;
} else {
return false;
}
} | [
"public",
"function",
"toSheet",
"(",
"$",
"array",
",",
"$",
"sheet_name",
",",
"$",
"ext",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"ext",
")",
"{",
"$",
"ext",
"=",
"pathinfo",
"(",
"$",
"sheet_name",
",",
"PATHINFO_EXTENSION",
")",
";",
"}",
"switch",
"(",
"$",
"ext",
")",
"{",
"case",
"'csv'",
":",
"$",
"writer",
"=",
"WriterFactory",
"::",
"create",
"(",
"Type",
"::",
"CSV",
")",
";",
"break",
";",
"case",
"'ods'",
":",
"$",
"writer",
"=",
"WriterFactory",
"::",
"create",
"(",
"Type",
"::",
"ODS",
")",
";",
"break",
";",
"case",
"'xlsx'",
":",
"$",
"writer",
"=",
"WriterFactory",
"::",
"create",
"(",
"Type",
"::",
"XLSX",
")",
";",
"break",
";",
"}",
"@",
"$",
"writer",
"->",
"openToFile",
"(",
"$",
"sheet_name",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"row",
")",
"{",
"$",
"writer",
"->",
"addRow",
"(",
"$",
"row",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"writer",
"->",
"close",
"(",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Converte um array de dados para uma planilha | [
"Converte",
"um",
"array",
"de",
"dados",
"para",
"uma",
"planilha"
] | 9cd7e850050208b3ab96e7a9fd82e88fd47151ce | https://github.com/aicouto/sheet/blob/9cd7e850050208b3ab96e7a9fd82e88fd47151ce/src/Sheet.php#L96-L121 | train |
Kris-Kuiper/sFire-Framework | src/Debugging/Debug.php | Debug.dump | public static function dump($data = null, $export = false) {
if(false === is_bool($export)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type boolean, "%s" given', __METHOD__, gettype($export)), E_USER_ERROR);
}
if($data === null || (true === is_string($data) && trim($data) === '') || true === is_bool($data)) {
if($export) {
return var_export($data);
}
echo '<pre>' . var_dump($data) . '</pre>';
return;
}
if($export) {
return print_r($data, true);
}
echo '<pre>' . print_r($data, true) . '</pre>';
} | php | public static function dump($data = null, $export = false) {
if(false === is_bool($export)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type boolean, "%s" given', __METHOD__, gettype($export)), E_USER_ERROR);
}
if($data === null || (true === is_string($data) && trim($data) === '') || true === is_bool($data)) {
if($export) {
return var_export($data);
}
echo '<pre>' . var_dump($data) . '</pre>';
return;
}
if($export) {
return print_r($data, true);
}
echo '<pre>' . print_r($data, true) . '</pre>';
} | [
"public",
"static",
"function",
"dump",
"(",
"$",
"data",
"=",
"null",
",",
"$",
"export",
"=",
"false",
")",
"{",
"if",
"(",
"false",
"===",
"is_bool",
"(",
"$",
"export",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 2 passed to %s() must be of the type boolean, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"export",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"$",
"data",
"===",
"null",
"||",
"(",
"true",
"===",
"is_string",
"(",
"$",
"data",
")",
"&&",
"trim",
"(",
"$",
"data",
")",
"===",
"''",
")",
"||",
"true",
"===",
"is_bool",
"(",
"$",
"data",
")",
")",
"{",
"if",
"(",
"$",
"export",
")",
"{",
"return",
"var_export",
"(",
"$",
"data",
")",
";",
"}",
"echo",
"'<pre>'",
".",
"var_dump",
"(",
"$",
"data",
")",
".",
"'</pre>'",
";",
"return",
";",
"}",
"if",
"(",
"$",
"export",
")",
"{",
"return",
"print_r",
"(",
"$",
"data",
",",
"true",
")",
";",
"}",
"echo",
"'<pre>'",
".",
"print_r",
"(",
"$",
"data",
",",
"true",
")",
".",
"'</pre>'",
";",
"}"
] | Advanced debugging of variables
@param mixed $data
@param boolean $export
@return mixed | [
"Advanced",
"debugging",
"of",
"variables"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Debugging/Debug.php#L27-L49 | train |
Kris-Kuiper/sFire-Framework | src/Debugging/Debug.php | Debug.time | public static function time($key = null) {
if(null !== $key && false === is_string($key)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($key)), E_USER_ERROR);
}
if(count(static :: $time) === 0) {
static :: $time = [];
}
if(null !== $key) {
static :: $time[] = ['time' => microtime(), 'key' => $key];
return;
}
static :: $time[] = ['time' => microtime(), 'key' => 'end'];
$laps = [];
for($i = 1; $i < count(static :: $time); $i++) {
$start = explode(' ', static :: $time[$i - 1]['time']);
$end = explode(' ', static :: $time[$i]['time']);
$laps[static :: $time[$i - 1]['key'] . ' - ' . static :: $time[$i]['key']] = number_format((($end[1] + $end[0]) - ($start[1] + $start[0])), 4, '.', '');
}
return $laps;
} | php | public static function time($key = null) {
if(null !== $key && false === is_string($key)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($key)), E_USER_ERROR);
}
if(count(static :: $time) === 0) {
static :: $time = [];
}
if(null !== $key) {
static :: $time[] = ['time' => microtime(), 'key' => $key];
return;
}
static :: $time[] = ['time' => microtime(), 'key' => 'end'];
$laps = [];
for($i = 1; $i < count(static :: $time); $i++) {
$start = explode(' ', static :: $time[$i - 1]['time']);
$end = explode(' ', static :: $time[$i]['time']);
$laps[static :: $time[$i - 1]['key'] . ' - ' . static :: $time[$i]['key']] = number_format((($end[1] + $end[0]) - ($start[1] + $start[0])), 4, '.', '');
}
return $laps;
} | [
"public",
"static",
"function",
"time",
"(",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"key",
"&&",
"false",
"===",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"key",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"count",
"(",
"static",
"::",
"$",
"time",
")",
"===",
"0",
")",
"{",
"static",
"::",
"$",
"time",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"key",
")",
"{",
"static",
"::",
"$",
"time",
"[",
"]",
"=",
"[",
"'time'",
"=>",
"microtime",
"(",
")",
",",
"'key'",
"=>",
"$",
"key",
"]",
";",
"return",
";",
"}",
"static",
"::",
"$",
"time",
"[",
"]",
"=",
"[",
"'time'",
"=>",
"microtime",
"(",
")",
",",
"'key'",
"=>",
"'end'",
"]",
";",
"$",
"laps",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<",
"count",
"(",
"static",
"::",
"$",
"time",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"start",
"=",
"explode",
"(",
"' '",
",",
"static",
"::",
"$",
"time",
"[",
"$",
"i",
"-",
"1",
"]",
"[",
"'time'",
"]",
")",
";",
"$",
"end",
"=",
"explode",
"(",
"' '",
",",
"static",
"::",
"$",
"time",
"[",
"$",
"i",
"]",
"[",
"'time'",
"]",
")",
";",
"$",
"laps",
"[",
"static",
"::",
"$",
"time",
"[",
"$",
"i",
"-",
"1",
"]",
"[",
"'key'",
"]",
".",
"' - '",
".",
"static",
"::",
"$",
"time",
"[",
"$",
"i",
"]",
"[",
"'key'",
"]",
"]",
"=",
"number_format",
"(",
"(",
"(",
"$",
"end",
"[",
"1",
"]",
"+",
"$",
"end",
"[",
"0",
"]",
")",
"-",
"(",
"$",
"start",
"[",
"1",
"]",
"+",
"$",
"start",
"[",
"0",
"]",
")",
")",
",",
"4",
",",
"'.'",
",",
"''",
")",
";",
"}",
"return",
"$",
"laps",
";",
"}"
] | Calculate process times by adding new times an exporting them
@param string $key
@return array | [
"Calculate",
"process",
"times",
"by",
"adding",
"new",
"times",
"an",
"exporting",
"them"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Debugging/Debug.php#L57-L86 | train |
sndsgd/http | src/http/HeaderCollection.php | HeaderCollection.has | public function has(string $key): bool
{
$key = $this->getKey($key, true);
return isset($this->headers[$key]);
} | php | public function has(string $key): bool
{
$key = $this->getKey($key, true);
return isset($this->headers[$key]);
} | [
"public",
"function",
"has",
"(",
"string",
"$",
"key",
")",
":",
"bool",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"getKey",
"(",
"$",
"key",
",",
"true",
")",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"$",
"key",
"]",
")",
";",
"}"
] | Determine whether a particular header exists
@param string $key The key to check for
@return bool | [
"Determine",
"whether",
"a",
"particular",
"header",
"exists"
] | e7f82010a66c6d3241a24ea82baf4593130c723b | https://github.com/sndsgd/http/blob/e7f82010a66c6d3241a24ea82baf4593130c723b/src/http/HeaderCollection.php#L25-L29 | train |
sndsgd/http | src/http/HeaderCollection.php | HeaderCollection.getKey | protected function getKey(string $key, bool $register = false): string
{
$lowercaseKey = strtolower($key);
if (isset($this->keyMap[$lowercaseKey])) {
$key = $this->keyMap[$lowercaseKey];
} elseif ($register) {
$this->keyMap[$lowercaseKey] = $key;
}
return $key;
} | php | protected function getKey(string $key, bool $register = false): string
{
$lowercaseKey = strtolower($key);
if (isset($this->keyMap[$lowercaseKey])) {
$key = $this->keyMap[$lowercaseKey];
} elseif ($register) {
$this->keyMap[$lowercaseKey] = $key;
}
return $key;
} | [
"protected",
"function",
"getKey",
"(",
"string",
"$",
"key",
",",
"bool",
"$",
"register",
"=",
"false",
")",
":",
"string",
"{",
"$",
"lowercaseKey",
"=",
"strtolower",
"(",
"$",
"key",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"keyMap",
"[",
"$",
"lowercaseKey",
"]",
")",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"keyMap",
"[",
"$",
"lowercaseKey",
"]",
";",
"}",
"elseif",
"(",
"$",
"register",
")",
"{",
"$",
"this",
"->",
"keyMap",
"[",
"$",
"lowercaseKey",
"]",
"=",
"$",
"key",
";",
"}",
"return",
"$",
"key",
";",
"}"
] | Retrieve a key that can be used in a hashmap to prevent duplicate keys
@param string $key
@param bool $register Whether to register a new key
@return string | [
"Retrieve",
"a",
"key",
"that",
"can",
"be",
"used",
"in",
"a",
"hashmap",
"to",
"prevent",
"duplicate",
"keys"
] | e7f82010a66c6d3241a24ea82baf4593130c723b | https://github.com/sndsgd/http/blob/e7f82010a66c6d3241a24ea82baf4593130c723b/src/http/HeaderCollection.php#L38-L47 | train |
sndsgd/http | src/http/HeaderCollection.php | HeaderCollection.addMultiple | public function addMultiple(array $headers): HeaderCollection
{
foreach ($headers as $key => $value) {
$key = $this->getKey($key, true);
\sndsgd\Arr::addValue($this->headers, $key, $value);
}
return $this;
} | php | public function addMultiple(array $headers): HeaderCollection
{
foreach ($headers as $key => $value) {
$key = $this->getKey($key, true);
\sndsgd\Arr::addValue($this->headers, $key, $value);
}
return $this;
} | [
"public",
"function",
"addMultiple",
"(",
"array",
"$",
"headers",
")",
":",
"HeaderCollection",
"{",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"getKey",
"(",
"$",
"key",
",",
"true",
")",
";",
"\\",
"sndsgd",
"\\",
"Arr",
"::",
"addValue",
"(",
"$",
"this",
"->",
"headers",
",",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Add multiple headers
@param array<string,string> $headers | [
"Add",
"multiple",
"headers"
] | e7f82010a66c6d3241a24ea82baf4593130c723b | https://github.com/sndsgd/http/blob/e7f82010a66c6d3241a24ea82baf4593130c723b/src/http/HeaderCollection.php#L90-L97 | train |
sndsgd/http | src/http/HeaderCollection.php | HeaderCollection.get | public function get(string $key): string
{
$key = $this->getKey($key);
$value = $this->headers[$key] ?? "";
return is_array($value) ? implode(", ", $value) : $value;
} | php | public function get(string $key): string
{
$key = $this->getKey($key);
$value = $this->headers[$key] ?? "";
return is_array($value) ? implode(", ", $value) : $value;
} | [
"public",
"function",
"get",
"(",
"string",
"$",
"key",
")",
":",
"string",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"getKey",
"(",
"$",
"key",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"headers",
"[",
"$",
"key",
"]",
"??",
"\"\"",
";",
"return",
"is_array",
"(",
"$",
"value",
")",
"?",
"implode",
"(",
"\", \"",
",",
"$",
"value",
")",
":",
"$",
"value",
";",
"}"
] | Get a header value
@param string $key
@return string | [
"Get",
"a",
"header",
"value"
] | e7f82010a66c6d3241a24ea82baf4593130c723b | https://github.com/sndsgd/http/blob/e7f82010a66c6d3241a24ea82baf4593130c723b/src/http/HeaderCollection.php#L105-L110 | train |
sndsgd/http | src/http/HeaderCollection.php | HeaderCollection.getMultiple | public function getMultiple(string ...$keys): array
{
$ret = [];
foreach ($keys as $key) {
$ret[] = $this->get($key);
}
return $ret;
} | php | public function getMultiple(string ...$keys): array
{
$ret = [];
foreach ($keys as $key) {
$ret[] = $this->get($key);
}
return $ret;
} | [
"public",
"function",
"getMultiple",
"(",
"string",
"...",
"$",
"keys",
")",
":",
"array",
"{",
"$",
"ret",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"ret",
"[",
"]",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"key",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Get multiple header values
@param string ...$keys
@return array<string> | [
"Get",
"multiple",
"header",
"values"
] | e7f82010a66c6d3241a24ea82baf4593130c723b | https://github.com/sndsgd/http/blob/e7f82010a66c6d3241a24ea82baf4593130c723b/src/http/HeaderCollection.php#L118-L125 | train |
sndsgd/http | src/http/HeaderCollection.php | HeaderCollection.getStringifiedArray | public function getStringifiedArray(): array
{
$ret = [];
foreach ($this->headers as $header => $value) {
if (is_array($value)) {
$value = implode(", ", $value);
}
$ret[] = "$header: $value";
}
return $ret;
} | php | public function getStringifiedArray(): array
{
$ret = [];
foreach ($this->headers as $header => $value) {
if (is_array($value)) {
$value = implode(", ", $value);
}
$ret[] = "$header: $value";
}
return $ret;
} | [
"public",
"function",
"getStringifiedArray",
"(",
")",
":",
"array",
"{",
"$",
"ret",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"headers",
"as",
"$",
"header",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"implode",
"(",
"\", \"",
",",
"$",
"value",
")",
";",
"}",
"$",
"ret",
"[",
"]",
"=",
"\"$header: $value\"",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Retrieve an array of headers as strings
@return array<string> | [
"Retrieve",
"an",
"array",
"of",
"headers",
"as",
"strings"
] | e7f82010a66c6d3241a24ea82baf4593130c723b | https://github.com/sndsgd/http/blob/e7f82010a66c6d3241a24ea82baf4593130c723b/src/http/HeaderCollection.php#L132-L142 | train |
nicmart/DomainSpecificQuery | src/Compiler/MatcherCompiler.php | MatcherCompiler.map | public function map($type, $transformation)
{
if (!is_callable($transformation))
throw new InvalidTransformationException('Transformations must be callable objects');
foreach ((array) $type as $t) {
$this->getMatcher()->rule('type', $t, $transformation);
}
return $this;
} | php | public function map($type, $transformation)
{
if (!is_callable($transformation))
throw new InvalidTransformationException('Transformations must be callable objects');
foreach ((array) $type as $t) {
$this->getMatcher()->rule('type', $t, $transformation);
}
return $this;
} | [
"public",
"function",
"map",
"(",
"$",
"type",
",",
"$",
"transformation",
")",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"transformation",
")",
")",
"throw",
"new",
"InvalidTransformationException",
"(",
"'Transformations must be callable objects'",
")",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"type",
"as",
"$",
"t",
")",
"{",
"$",
"this",
"->",
"getMatcher",
"(",
")",
"->",
"rule",
"(",
"'type'",
",",
"$",
"t",
",",
"$",
"transformation",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Register a map for the compiler, that matches on type
@param string|array $type The type/s of the expressions that will be transformed
@param callable $transformation The transformation
@throws InvalidTransformationException
@return $this The current instance | [
"Register",
"a",
"map",
"for",
"the",
"compiler",
"that",
"matches",
"on",
"type"
] | 7c01fe94337afdfae5884809e8b5487127a63ac3 | https://github.com/nicmart/DomainSpecificQuery/blob/7c01fe94337afdfae5884809e8b5487127a63ac3/src/Compiler/MatcherCompiler.php#L88-L98 | train |
lasallecms/lasallecms-l5-usermanagement-pkg | src/Http/Controllers/Frontendauth/Register2faUserController.php | Register2faUserController.post2faRegisterDisplayForm | public function post2faRegisterDisplayForm(Request $request) {
if (config('lasallecmsusermanagement.auth_users_registration_front_end_require_terms_of_service')) {
if (!$request->input('terms-of-service')) {
return redirect()->route('auth.register')
->withInput($request->only('name', 'email', 'phone_country_code', 'phone_number'))
->withErrors([
'terms-of-service' => 'Please read our Terms of Service',
]);
}
}
// Go through the special validation-only command bus
$response = $this->dispatchFrom(Create2faRegisterUserCommand::class, $request);
//Session::flash('status_code', $response['status_code'] );
if ($response['status_text'] == "validation_failed") {
Session::flash('message', $response['errorMessages']->first());
// Return to the edit form with error messages
return Redirect::back()
->withInput($response['data'])
->withErrors($response['errorMessages']);
}
// The validation is ok. Now, onto the Two Factor Authorization.
$this->twoFactorAuthHelper->doTwoFactorAuthRegistration($response['data']);
// The initial validation is ok, but we do not want to set up an actual database record until the 2FA
// is complete. Otherwise, the bots could create actual records, which is something we are trying to avoid
// with the 2FA process.
// The 2FA code session var is set in $this->twoFactorAuthHelper->doTwoFactorAuthRegistration($response['data']);
return view('usermanagement::frontend.' . $this->frontend_template_name . '.register.two_factor_auth', [
'title' => 'Register',
'two_factor_auth_workflow' => true,
'name' => $response['data']['name'],
'email' => $response['data']['email'],
'password' => $response['data']['password'],
'password_confirmation' => $response['data']['password_confirmation'],
'phone_country_code' => $response['data']['phone_country_code'],
'phone_number' => $response['data']['phone_number'],
'formStartDateTime' => Carbon::now(),
]);
} | php | public function post2faRegisterDisplayForm(Request $request) {
if (config('lasallecmsusermanagement.auth_users_registration_front_end_require_terms_of_service')) {
if (!$request->input('terms-of-service')) {
return redirect()->route('auth.register')
->withInput($request->only('name', 'email', 'phone_country_code', 'phone_number'))
->withErrors([
'terms-of-service' => 'Please read our Terms of Service',
]);
}
}
// Go through the special validation-only command bus
$response = $this->dispatchFrom(Create2faRegisterUserCommand::class, $request);
//Session::flash('status_code', $response['status_code'] );
if ($response['status_text'] == "validation_failed") {
Session::flash('message', $response['errorMessages']->first());
// Return to the edit form with error messages
return Redirect::back()
->withInput($response['data'])
->withErrors($response['errorMessages']);
}
// The validation is ok. Now, onto the Two Factor Authorization.
$this->twoFactorAuthHelper->doTwoFactorAuthRegistration($response['data']);
// The initial validation is ok, but we do not want to set up an actual database record until the 2FA
// is complete. Otherwise, the bots could create actual records, which is something we are trying to avoid
// with the 2FA process.
// The 2FA code session var is set in $this->twoFactorAuthHelper->doTwoFactorAuthRegistration($response['data']);
return view('usermanagement::frontend.' . $this->frontend_template_name . '.register.two_factor_auth', [
'title' => 'Register',
'two_factor_auth_workflow' => true,
'name' => $response['data']['name'],
'email' => $response['data']['email'],
'password' => $response['data']['password'],
'password_confirmation' => $response['data']['password_confirmation'],
'phone_country_code' => $response['data']['phone_country_code'],
'phone_number' => $response['data']['phone_number'],
'formStartDateTime' => Carbon::now(),
]);
} | [
"public",
"function",
"post2faRegisterDisplayForm",
"(",
"Request",
"$",
"request",
")",
"{",
"if",
"(",
"config",
"(",
"'lasallecmsusermanagement.auth_users_registration_front_end_require_terms_of_service'",
")",
")",
"{",
"if",
"(",
"!",
"$",
"request",
"->",
"input",
"(",
"'terms-of-service'",
")",
")",
"{",
"return",
"redirect",
"(",
")",
"->",
"route",
"(",
"'auth.register'",
")",
"->",
"withInput",
"(",
"$",
"request",
"->",
"only",
"(",
"'name'",
",",
"'email'",
",",
"'phone_country_code'",
",",
"'phone_number'",
")",
")",
"->",
"withErrors",
"(",
"[",
"'terms-of-service'",
"=>",
"'Please read our Terms of Service'",
",",
"]",
")",
";",
"}",
"}",
"// Go through the special validation-only command bus",
"$",
"response",
"=",
"$",
"this",
"->",
"dispatchFrom",
"(",
"Create2faRegisterUserCommand",
"::",
"class",
",",
"$",
"request",
")",
";",
"//Session::flash('status_code', $response['status_code'] );",
"if",
"(",
"$",
"response",
"[",
"'status_text'",
"]",
"==",
"\"validation_failed\"",
")",
"{",
"Session",
"::",
"flash",
"(",
"'message'",
",",
"$",
"response",
"[",
"'errorMessages'",
"]",
"->",
"first",
"(",
")",
")",
";",
"// Return to the edit form with error messages",
"return",
"Redirect",
"::",
"back",
"(",
")",
"->",
"withInput",
"(",
"$",
"response",
"[",
"'data'",
"]",
")",
"->",
"withErrors",
"(",
"$",
"response",
"[",
"'errorMessages'",
"]",
")",
";",
"}",
"// The validation is ok. Now, onto the Two Factor Authorization.",
"$",
"this",
"->",
"twoFactorAuthHelper",
"->",
"doTwoFactorAuthRegistration",
"(",
"$",
"response",
"[",
"'data'",
"]",
")",
";",
"// The initial validation is ok, but we do not want to set up an actual database record until the 2FA",
"// is complete. Otherwise, the bots could create actual records, which is something we are trying to avoid",
"// with the 2FA process.",
"// The 2FA code session var is set in $this->twoFactorAuthHelper->doTwoFactorAuthRegistration($response['data']);",
"return",
"view",
"(",
"'usermanagement::frontend.'",
".",
"$",
"this",
"->",
"frontend_template_name",
".",
"'.register.two_factor_auth'",
",",
"[",
"'title'",
"=>",
"'Register'",
",",
"'two_factor_auth_workflow'",
"=>",
"true",
",",
"'name'",
"=>",
"$",
"response",
"[",
"'data'",
"]",
"[",
"'name'",
"]",
",",
"'email'",
"=>",
"$",
"response",
"[",
"'data'",
"]",
"[",
"'email'",
"]",
",",
"'password'",
"=>",
"$",
"response",
"[",
"'data'",
"]",
"[",
"'password'",
"]",
",",
"'password_confirmation'",
"=>",
"$",
"response",
"[",
"'data'",
"]",
"[",
"'password_confirmation'",
"]",
",",
"'phone_country_code'",
"=>",
"$",
"response",
"[",
"'data'",
"]",
"[",
"'phone_country_code'",
"]",
",",
"'phone_number'",
"=>",
"$",
"response",
"[",
"'data'",
"]",
"[",
"'phone_number'",
"]",
",",
"'formStartDateTime'",
"=>",
"Carbon",
"::",
"now",
"(",
")",
",",
"]",
")",
";",
"}"
] | The front-end 2FA registration form comes here.
This method validates the form data only. This validation occurs via the command bus as usual; however,
I modified the command bus flow to accommodate this special validation-only. So far (v1.01), this is the
one-and-only time where any changes to the command bus are happening. It's happening here because all the
validation goodness needs to happen, but there is one extra step to interject before the persist. When this
second 2FA is successful, the original command bus, that is used for the regular non-2FA front-end user
registration, is used in all its original glory. Meaning, the entire validation happens again. The assumption
is that the sanitation and validation will always process flawlessly the second time around.
@param \Illuminate\Http\Request $request
@return \Illuminate\Http\Response | [
"The",
"front",
"-",
"end",
"2FA",
"registration",
"form",
"comes",
"here",
"."
] | b5203d596e18e2566e7fdcd3f13868bb44a94c1d | https://github.com/lasallecms/lasallecms-l5-usermanagement-pkg/blob/b5203d596e18e2566e7fdcd3f13868bb44a94c1d/src/Http/Controllers/Frontendauth/Register2faUserController.php#L135-L182 | train |
itkg/core | src/Itkg/Core/Command/DatabaseList/Finder.php | Finder.findAll | public function findAll()
{
$files = array();
foreach (new \DirectoryIterator($this->path) as $file) {
if ($file->isDot()) {
continue;
}
$files[] = $file->getFilename();
}
sort($files);
return $files;
} | php | public function findAll()
{
$files = array();
foreach (new \DirectoryIterator($this->path) as $file) {
if ($file->isDot()) {
continue;
}
$files[] = $file->getFilename();
}
sort($files);
return $files;
} | [
"public",
"function",
"findAll",
"(",
")",
"{",
"$",
"files",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"new",
"\\",
"DirectoryIterator",
"(",
"$",
"this",
"->",
"path",
")",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"->",
"isDot",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"files",
"[",
"]",
"=",
"$",
"file",
"->",
"getFilename",
"(",
")",
";",
"}",
"sort",
"(",
"$",
"files",
")",
";",
"return",
"$",
"files",
";",
"}"
] | Find all releases
@return array | [
"Find",
"all",
"releases"
] | e5e4efb05feb4d23b0df41f2b21fd095103e593b | https://github.com/itkg/core/blob/e5e4efb05feb4d23b0df41f2b21fd095103e593b/src/Itkg/Core/Command/DatabaseList/Finder.php#L35-L49 | train |
endroid/tile | src/Twig/Extension/TileExtension.php | TileExtension.tileUrlFunction | public function tileUrlFunction($text, $extension = 'png')
{
$router = $this->container->get('router');
$url = $router->generate('tile', [
'text' => $text,
'extension' => $extension,
]);
return $url;
} | php | public function tileUrlFunction($text, $extension = 'png')
{
$router = $this->container->get('router');
$url = $router->generate('tile', [
'text' => $text,
'extension' => $extension,
]);
return $url;
} | [
"public",
"function",
"tileUrlFunction",
"(",
"$",
"text",
",",
"$",
"extension",
"=",
"'png'",
")",
"{",
"$",
"router",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'router'",
")",
";",
"$",
"url",
"=",
"$",
"router",
"->",
"generate",
"(",
"'tile'",
",",
"[",
"'text'",
"=>",
"$",
"text",
",",
"'extension'",
"=>",
"$",
"extension",
",",
"]",
")",
";",
"return",
"$",
"url",
";",
"}"
] | Creates the QR code URL corresponding to the given message and extension.
@param $text
@param string $extension
@return mixed | [
"Creates",
"the",
"QR",
"code",
"URL",
"corresponding",
"to",
"the",
"given",
"message",
"and",
"extension",
"."
] | db7a3556f511f873073b154c13cf49a8b9fe69b0 | https://github.com/endroid/tile/blob/db7a3556f511f873073b154c13cf49a8b9fe69b0/src/Twig/Extension/TileExtension.php#L52-L61 | train |
togucms/FrontendBundle | Controller/ContentController.php | ContentController.typeAction | public function typeAction($contentDocument, $_format, Request $request)
{
if (!$contentDocument || ! $contentDocument instanceof Page) {
throw new NotFoundHttpException('Content not found');
}
if ($this->container->has('profiler')) {
$this->container->get('profiler')->disable();
}
$isAdminUi = $request->query->get('admin', false) && $this->container->get('security.context')->isGranted('ROLE_ADMIN');
$data = $params = $this->formatter->format($contentDocument);
if("html" == $_format) {
$params = array(
'cmfMainContent' => $contentDocument,
'jsData' => $data,
'settings' => array("currentPath"=>"/","urlBase"=>"/"),
'isAdminUI' => $isAdminUi,
'serializationContext' => $this->getSerializerContext(array('front'))
);
}
return $this->renderResponse('ApplicationToguApplicationModelsBundle:Default:index.html.twig', $params);
} | php | public function typeAction($contentDocument, $_format, Request $request)
{
if (!$contentDocument || ! $contentDocument instanceof Page) {
throw new NotFoundHttpException('Content not found');
}
if ($this->container->has('profiler')) {
$this->container->get('profiler')->disable();
}
$isAdminUi = $request->query->get('admin', false) && $this->container->get('security.context')->isGranted('ROLE_ADMIN');
$data = $params = $this->formatter->format($contentDocument);
if("html" == $_format) {
$params = array(
'cmfMainContent' => $contentDocument,
'jsData' => $data,
'settings' => array("currentPath"=>"/","urlBase"=>"/"),
'isAdminUI' => $isAdminUi,
'serializationContext' => $this->getSerializerContext(array('front'))
);
}
return $this->renderResponse('ApplicationToguApplicationModelsBundle:Default:index.html.twig', $params);
} | [
"public",
"function",
"typeAction",
"(",
"$",
"contentDocument",
",",
"$",
"_format",
",",
"Request",
"$",
"request",
")",
"{",
"if",
"(",
"!",
"$",
"contentDocument",
"||",
"!",
"$",
"contentDocument",
"instanceof",
"Page",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
"'Content not found'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"container",
"->",
"has",
"(",
"'profiler'",
")",
")",
"{",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'profiler'",
")",
"->",
"disable",
"(",
")",
";",
"}",
"$",
"isAdminUi",
"=",
"$",
"request",
"->",
"query",
"->",
"get",
"(",
"'admin'",
",",
"false",
")",
"&&",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'security.context'",
")",
"->",
"isGranted",
"(",
"'ROLE_ADMIN'",
")",
";",
"$",
"data",
"=",
"$",
"params",
"=",
"$",
"this",
"->",
"formatter",
"->",
"format",
"(",
"$",
"contentDocument",
")",
";",
"if",
"(",
"\"html\"",
"==",
"$",
"_format",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'cmfMainContent'",
"=>",
"$",
"contentDocument",
",",
"'jsData'",
"=>",
"$",
"data",
",",
"'settings'",
"=>",
"array",
"(",
"\"currentPath\"",
"=>",
"\"/\"",
",",
"\"urlBase\"",
"=>",
"\"/\"",
")",
",",
"'isAdminUI'",
"=>",
"$",
"isAdminUi",
",",
"'serializationContext'",
"=>",
"$",
"this",
"->",
"getSerializerContext",
"(",
"array",
"(",
"'front'",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"renderResponse",
"(",
"'ApplicationToguApplicationModelsBundle:Default:index.html.twig'",
",",
"$",
"params",
")",
";",
"}"
] | This action is mapped in the controller_by_type map
This can inject something else for the template for content with this type
@param object $contentDocument
@return Response | [
"This",
"action",
"is",
"mapped",
"in",
"the",
"controller_by_type",
"map"
] | fd165aca0fb6498ce85b39c1ff536cc1bd8ba285 | https://github.com/togucms/FrontendBundle/blob/fd165aca0fb6498ce85b39c1ff536cc1bd8ba285/Controller/ContentController.php#L65-L87 | train |
DaGhostman/codewave | src/Flash/Manager.php | Manager.getMessage | public function getMessage($type, $id = null)
{
$result = null;
if (null === $id) {
if (array_key_exists($type, $this->messages)) {
$result = $this->messages[$type];
if (!$this->persistMessages) {
unset($this->messages[$type]);
}
}
}
if (null !== $id) {
if (array_key_exists($type, $this->messages)) {
if (array_key_exists($id, $this->messages[$type])) {
$result = $this->messages[$type][$id];
if (!$this->persistMessages) {
unset($this->messages[$type][$id]);
}
}
}
}
return $result;
} | php | public function getMessage($type, $id = null)
{
$result = null;
if (null === $id) {
if (array_key_exists($type, $this->messages)) {
$result = $this->messages[$type];
if (!$this->persistMessages) {
unset($this->messages[$type]);
}
}
}
if (null !== $id) {
if (array_key_exists($type, $this->messages)) {
if (array_key_exists($id, $this->messages[$type])) {
$result = $this->messages[$type][$id];
if (!$this->persistMessages) {
unset($this->messages[$type][$id]);
}
}
}
}
return $result;
} | [
"public",
"function",
"getMessage",
"(",
"$",
"type",
",",
"$",
"id",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"null",
";",
"if",
"(",
"null",
"===",
"$",
"id",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"messages",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"messages",
"[",
"$",
"type",
"]",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"persistMessages",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"messages",
"[",
"$",
"type",
"]",
")",
";",
"}",
"}",
"}",
"if",
"(",
"null",
"!==",
"$",
"id",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"messages",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"id",
",",
"$",
"this",
"->",
"messages",
"[",
"$",
"type",
"]",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"messages",
"[",
"$",
"type",
"]",
"[",
"$",
"id",
"]",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"persistMessages",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"messages",
"[",
"$",
"type",
"]",
"[",
"$",
"id",
"]",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Retrieve a message
@param mixed $type The type of the messages to retrieve.
@param string $id The ID of the message
@return null|Message|\Wave\Framework\Flash\Message[] | [
"Retrieve",
"a",
"message"
] | f0f58e721699cdaaf87cbfaf8ce589a6b3c473b8 | https://github.com/DaGhostman/codewave/blob/f0f58e721699cdaaf87cbfaf8ce589a6b3c473b8/src/Flash/Manager.php#L84-L109 | train |
rzajac/phptools | src/Helper/Num.php | Num.equalWithin | public static function equalWithin($a, $b, $delta)
{
if (is_infinite($a) xor is_infinite($b)) {
return false;
}
if (is_nan($a) || is_nan($b) || is_nan($delta)) {
return false;
}
return abs($a - $b) <= $delta;
} | php | public static function equalWithin($a, $b, $delta)
{
if (is_infinite($a) xor is_infinite($b)) {
return false;
}
if (is_nan($a) || is_nan($b) || is_nan($delta)) {
return false;
}
return abs($a - $b) <= $delta;
} | [
"public",
"static",
"function",
"equalWithin",
"(",
"$",
"a",
",",
"$",
"b",
",",
"$",
"delta",
")",
"{",
"if",
"(",
"is_infinite",
"(",
"$",
"a",
")",
"xor",
"is_infinite",
"(",
"$",
"b",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"is_nan",
"(",
"$",
"a",
")",
"||",
"is_nan",
"(",
"$",
"b",
")",
"||",
"is_nan",
"(",
"$",
"delta",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"abs",
"(",
"$",
"a",
"-",
"$",
"b",
")",
"<=",
"$",
"delta",
";",
"}"
] | Are two numbers equal within given delta.
@param int|float $a
@param int|float $b
@param int|float $delta
@return bool | [
"Are",
"two",
"numbers",
"equal",
"within",
"given",
"delta",
"."
] | 3cbece7645942d244603c14ba897d8a676ee3088 | https://github.com/rzajac/phptools/blob/3cbece7645942d244603c14ba897d8a676ee3088/src/Helper/Num.php#L36-L47 | train |
netzmacht-archive/subcolumns_bootstrap_customizable | src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/colsetStart.php | colsetStart.compile | protected function compile()
{
parent::compile();
if($GLOBALS['TL_CONFIG']['subcolumns'] == 'bootstrap_customizable')
{
$container = ColumnSet::prepareContainer($this->columnset_id);
if($container) {
$this->Template->column = $container[$this->sc_sortid][0] . ' col_' . ($this->sc_sortid+1) . (($this->sc_sortid == count($container)-1) ? ' last' : '');
}
}
} | php | protected function compile()
{
parent::compile();
if($GLOBALS['TL_CONFIG']['subcolumns'] == 'bootstrap_customizable')
{
$container = ColumnSet::prepareContainer($this->columnset_id);
if($container) {
$this->Template->column = $container[$this->sc_sortid][0] . ' col_' . ($this->sc_sortid+1) . (($this->sc_sortid == count($container)-1) ? ' last' : '');
}
}
} | [
"protected",
"function",
"compile",
"(",
")",
"{",
"parent",
"::",
"compile",
"(",
")",
";",
"if",
"(",
"$",
"GLOBALS",
"[",
"'TL_CONFIG'",
"]",
"[",
"'subcolumns'",
"]",
"==",
"'bootstrap_customizable'",
")",
"{",
"$",
"container",
"=",
"ColumnSet",
"::",
"prepareContainer",
"(",
"$",
"this",
"->",
"columnset_id",
")",
";",
"if",
"(",
"$",
"container",
")",
"{",
"$",
"this",
"->",
"Template",
"->",
"column",
"=",
"$",
"container",
"[",
"$",
"this",
"->",
"sc_sortid",
"]",
"[",
"0",
"]",
".",
"' col_'",
".",
"(",
"$",
"this",
"->",
"sc_sortid",
"+",
"1",
")",
".",
"(",
"(",
"$",
"this",
"->",
"sc_sortid",
"==",
"count",
"(",
"$",
"container",
")",
"-",
"1",
")",
"?",
"' last'",
":",
"''",
")",
";",
"}",
"}",
"}"
] | extends subcolumns compile method for generating dynamically column set | [
"extends",
"subcolumns",
"compile",
"method",
"for",
"generating",
"dynamically",
"column",
"set"
] | c0f63755282451fad670ceaa49b984bfabf9e4ee | https://github.com/netzmacht-archive/subcolumns_bootstrap_customizable/blob/c0f63755282451fad670ceaa49b984bfabf9e4ee/src/system/modules/subcolumns_bootstrap_customizable/classes/Netzmacht/ColumnSet/colsetStart.php#L30-L42 | train |
t3v/t3v_core | Classes/Utility/RendererUtility.php | RendererUtility.getFluidRendererForTemplate | public function getFluidRendererForTemplate(string $template, string $format = 'html') {
$configurationManager = $this->objectManager->get(ConfigurationManagerInterface::class);
$configuration = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
$layoutRootPath = $configuration['view']['layoutRootPath'];
if (empty($layoutRootPath)) {
$firstLayoutRootPath = reset($configuration['view']['layoutRootPaths']);
$layoutRootPath = GeneralUtility::getFileAbsFileName($firstLayoutRootPath);
} else {
$layoutRootPath = GeneralUtility::getFileAbsFileName($layoutRootPath);
}
$templateRootPath = $configuration['view']['templateRootPath'];
if (empty($templateRootPath)) {
$firstTemplateRootPath = reset($configuration['view']['templateRootPaths']);
$templateRootPath = GeneralUtility::getFileAbsFileName($firstTemplateRootPath);
} else {
$templateRootPath = GeneralUtility::getFileAbsFileName($templateRootPath);
}
$partialRootPath = $configuration['view']['partialRootPath'];
if (empty($partialRootPath)) {
$firstPartialRootPath = reset($configuration['view']['partialRootPaths']);
$partialRootPath = GeneralUtility::getFileAbsFileName($firstPartialRootPath);
} else {
$partialRootPath = GeneralUtility::getFileAbsFileName($partialRootPath);
}
$renderer = $this->objectManager->get(StandaloneView::class);
$renderer->setLayoutRootPaths([$layoutRootPath]);
$renderer->setPartialRootPaths([$partialRootPath]);
$renderer->setTemplatePathAndFilename($templateRootPath . $template);
$renderer->setFormat($format);
return $renderer;
} | php | public function getFluidRendererForTemplate(string $template, string $format = 'html') {
$configurationManager = $this->objectManager->get(ConfigurationManagerInterface::class);
$configuration = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
$layoutRootPath = $configuration['view']['layoutRootPath'];
if (empty($layoutRootPath)) {
$firstLayoutRootPath = reset($configuration['view']['layoutRootPaths']);
$layoutRootPath = GeneralUtility::getFileAbsFileName($firstLayoutRootPath);
} else {
$layoutRootPath = GeneralUtility::getFileAbsFileName($layoutRootPath);
}
$templateRootPath = $configuration['view']['templateRootPath'];
if (empty($templateRootPath)) {
$firstTemplateRootPath = reset($configuration['view']['templateRootPaths']);
$templateRootPath = GeneralUtility::getFileAbsFileName($firstTemplateRootPath);
} else {
$templateRootPath = GeneralUtility::getFileAbsFileName($templateRootPath);
}
$partialRootPath = $configuration['view']['partialRootPath'];
if (empty($partialRootPath)) {
$firstPartialRootPath = reset($configuration['view']['partialRootPaths']);
$partialRootPath = GeneralUtility::getFileAbsFileName($firstPartialRootPath);
} else {
$partialRootPath = GeneralUtility::getFileAbsFileName($partialRootPath);
}
$renderer = $this->objectManager->get(StandaloneView::class);
$renderer->setLayoutRootPaths([$layoutRootPath]);
$renderer->setPartialRootPaths([$partialRootPath]);
$renderer->setTemplatePathAndFilename($templateRootPath . $template);
$renderer->setFormat($format);
return $renderer;
} | [
"public",
"function",
"getFluidRendererForTemplate",
"(",
"string",
"$",
"template",
",",
"string",
"$",
"format",
"=",
"'html'",
")",
"{",
"$",
"configurationManager",
"=",
"$",
"this",
"->",
"objectManager",
"->",
"get",
"(",
"ConfigurationManagerInterface",
"::",
"class",
")",
";",
"$",
"configuration",
"=",
"$",
"configurationManager",
"->",
"getConfiguration",
"(",
"ConfigurationManagerInterface",
"::",
"CONFIGURATION_TYPE_FRAMEWORK",
")",
";",
"$",
"layoutRootPath",
"=",
"$",
"configuration",
"[",
"'view'",
"]",
"[",
"'layoutRootPath'",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"layoutRootPath",
")",
")",
"{",
"$",
"firstLayoutRootPath",
"=",
"reset",
"(",
"$",
"configuration",
"[",
"'view'",
"]",
"[",
"'layoutRootPaths'",
"]",
")",
";",
"$",
"layoutRootPath",
"=",
"GeneralUtility",
"::",
"getFileAbsFileName",
"(",
"$",
"firstLayoutRootPath",
")",
";",
"}",
"else",
"{",
"$",
"layoutRootPath",
"=",
"GeneralUtility",
"::",
"getFileAbsFileName",
"(",
"$",
"layoutRootPath",
")",
";",
"}",
"$",
"templateRootPath",
"=",
"$",
"configuration",
"[",
"'view'",
"]",
"[",
"'templateRootPath'",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"templateRootPath",
")",
")",
"{",
"$",
"firstTemplateRootPath",
"=",
"reset",
"(",
"$",
"configuration",
"[",
"'view'",
"]",
"[",
"'templateRootPaths'",
"]",
")",
";",
"$",
"templateRootPath",
"=",
"GeneralUtility",
"::",
"getFileAbsFileName",
"(",
"$",
"firstTemplateRootPath",
")",
";",
"}",
"else",
"{",
"$",
"templateRootPath",
"=",
"GeneralUtility",
"::",
"getFileAbsFileName",
"(",
"$",
"templateRootPath",
")",
";",
"}",
"$",
"partialRootPath",
"=",
"$",
"configuration",
"[",
"'view'",
"]",
"[",
"'partialRootPath'",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"partialRootPath",
")",
")",
"{",
"$",
"firstPartialRootPath",
"=",
"reset",
"(",
"$",
"configuration",
"[",
"'view'",
"]",
"[",
"'partialRootPaths'",
"]",
")",
";",
"$",
"partialRootPath",
"=",
"GeneralUtility",
"::",
"getFileAbsFileName",
"(",
"$",
"firstPartialRootPath",
")",
";",
"}",
"else",
"{",
"$",
"partialRootPath",
"=",
"GeneralUtility",
"::",
"getFileAbsFileName",
"(",
"$",
"partialRootPath",
")",
";",
"}",
"$",
"renderer",
"=",
"$",
"this",
"->",
"objectManager",
"->",
"get",
"(",
"StandaloneView",
"::",
"class",
")",
";",
"$",
"renderer",
"->",
"setLayoutRootPaths",
"(",
"[",
"$",
"layoutRootPath",
"]",
")",
";",
"$",
"renderer",
"->",
"setPartialRootPaths",
"(",
"[",
"$",
"partialRootPath",
"]",
")",
";",
"$",
"renderer",
"->",
"setTemplatePathAndFilename",
"(",
"$",
"templateRootPath",
".",
"$",
"template",
")",
";",
"$",
"renderer",
"->",
"setFormat",
"(",
"$",
"format",
")",
";",
"return",
"$",
"renderer",
";",
"}"
] | Gets a Fluid renderer for a template.
@param string $template The template
@param string $format The optional format, `html` is used as default
@return \TYPO3\CMS\Fluid\View\StandaloneView The renderer for the template | [
"Gets",
"a",
"Fluid",
"renderer",
"for",
"a",
"template",
"."
] | 8c04b7688cc2773f11fcc87fda3f7cd53d80a980 | https://github.com/t3v/t3v_core/blob/8c04b7688cc2773f11fcc87fda3f7cd53d80a980/Classes/Utility/RendererUtility.php#L30-L70 | train |
squareproton/Bond | src/Bond/Flock.php | Flock.merge | public function merge( array $members )
{
foreach( $members as $offset => $value ) {
$this->offsetSet( $offset, $value );
}
return $this;
} | php | public function merge( array $members )
{
foreach( $members as $offset => $value ) {
$this->offsetSet( $offset, $value );
}
return $this;
} | [
"public",
"function",
"merge",
"(",
"array",
"$",
"members",
")",
"{",
"foreach",
"(",
"$",
"members",
"as",
"$",
"offset",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"offsetSet",
"(",
"$",
"offset",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Merge a array of potential members into the flock replacing as required
@param array $members
@return Bond\Flock | [
"Merge",
"a",
"array",
"of",
"potential",
"members",
"into",
"the",
"flock",
"replacing",
"as",
"required"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Flock.php#L71-L77 | train |
squareproton/Bond | src/Bond/Flock.php | Flock.add | public function add()
{
$args = func_get_args();
foreach( $args as $arg ) {
if( is_array($arg) ) {
foreach( $arg as $value ) {
$this[] = $value;
}
} else {
$this[] = $arg;
}
}
return $this;
} | php | public function add()
{
$args = func_get_args();
foreach( $args as $arg ) {
if( is_array($arg) ) {
foreach( $arg as $value ) {
$this[] = $value;
}
} else {
$this[] = $arg;
}
}
return $this;
} | [
"public",
"function",
"add",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"arg",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"arg",
")",
")",
"{",
"foreach",
"(",
"$",
"arg",
"as",
"$",
"value",
")",
"{",
"$",
"this",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"[",
"]",
"=",
"$",
"arg",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Add items to this flock
@return $this; | [
"Add",
"items",
"to",
"this",
"flock"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Flock.php#L83-L96 | train |
squareproton/Bond | src/Bond/Flock.php | Flock.remove | public function remove( $member )
{
if( false !== $key = array_search( $member, $this->members, true ) ) {
unset( $this->members[$key] );
}
return $this;
} | php | public function remove( $member )
{
if( false !== $key = array_search( $member, $this->members, true ) ) {
unset( $this->members[$key] );
}
return $this;
} | [
"public",
"function",
"remove",
"(",
"$",
"member",
")",
"{",
"if",
"(",
"false",
"!==",
"$",
"key",
"=",
"array_search",
"(",
"$",
"member",
",",
"$",
"this",
"->",
"members",
",",
"true",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"members",
"[",
"$",
"key",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Remove a member from the flock
@param Member
@return Bond\Flock | [
"Remove",
"a",
"member",
"from",
"the",
"flock"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Flock.php#L113-L119 | train |
squareproton/Bond | src/Bond/Flock.php | Flock.makeCheckCallback | private function makeCheckCallback( $check )
{
// callable
if( is_callable($check) ) {
$this->check = $check;
$this->type = $this->makeCallbackHumanReadable( $check );
return;
}
// class or obj
if( is_object($check) ) {
$class = get_class( $check );
} elseif( is_string($check) ) {
$class = (string) $check;
} else {
throw new BadTypeException( $check, "Class|Object|Callable");
}
$this->type = $class;
$this->check = function( $newMember ) use ( $class ) {
return is_a( $newMember, $class );
};
} | php | private function makeCheckCallback( $check )
{
// callable
if( is_callable($check) ) {
$this->check = $check;
$this->type = $this->makeCallbackHumanReadable( $check );
return;
}
// class or obj
if( is_object($check) ) {
$class = get_class( $check );
} elseif( is_string($check) ) {
$class = (string) $check;
} else {
throw new BadTypeException( $check, "Class|Object|Callable");
}
$this->type = $class;
$this->check = function( $newMember ) use ( $class ) {
return is_a( $newMember, $class );
};
} | [
"private",
"function",
"makeCheckCallback",
"(",
"$",
"check",
")",
"{",
"// callable",
"if",
"(",
"is_callable",
"(",
"$",
"check",
")",
")",
"{",
"$",
"this",
"->",
"check",
"=",
"$",
"check",
";",
"$",
"this",
"->",
"type",
"=",
"$",
"this",
"->",
"makeCallbackHumanReadable",
"(",
"$",
"check",
")",
";",
"return",
";",
"}",
"// class or obj",
"if",
"(",
"is_object",
"(",
"$",
"check",
")",
")",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"check",
")",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"check",
")",
")",
"{",
"$",
"class",
"=",
"(",
"string",
")",
"$",
"check",
";",
"}",
"else",
"{",
"throw",
"new",
"BadTypeException",
"(",
"$",
"check",
",",
"\"Class|Object|Callable\"",
")",
";",
"}",
"$",
"this",
"->",
"type",
"=",
"$",
"class",
";",
"$",
"this",
"->",
"check",
"=",
"function",
"(",
"$",
"newMember",
")",
"use",
"(",
"$",
"class",
")",
"{",
"return",
"is_a",
"(",
"$",
"newMember",
",",
"$",
"class",
")",
";",
"}",
";",
"}"
] | Make check callback for flock
@return Callable | [
"Make",
"check",
"callback",
"for",
"flock"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Flock.php#L214-L235 | train |
squareproton/Bond | src/Bond/Flock.php | Flock.makeCallbackHumanReadable | private function makeCallbackHumanReadable( Callable $callback )
{
if( is_string($callback) ) {
return $callback;
} elseif( is_array($callback) ) {
return sprintf(
"%s::%s",
is_object( $callback[0] ) ? get_class($callback[0]) : $callback[0],
$callback[1]
);
} elseif( !($callback instanceof \Closure) ) {
return "<closure>";
}
throw new \Exception("Wow. I didn't know php could define a callable of this type. Pete __definately__ wants to know all about this.");
} | php | private function makeCallbackHumanReadable( Callable $callback )
{
if( is_string($callback) ) {
return $callback;
} elseif( is_array($callback) ) {
return sprintf(
"%s::%s",
is_object( $callback[0] ) ? get_class($callback[0]) : $callback[0],
$callback[1]
);
} elseif( !($callback instanceof \Closure) ) {
return "<closure>";
}
throw new \Exception("Wow. I didn't know php could define a callable of this type. Pete __definately__ wants to know all about this.");
} | [
"private",
"function",
"makeCallbackHumanReadable",
"(",
"Callable",
"$",
"callback",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"callback",
")",
")",
"{",
"return",
"$",
"callback",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"callback",
")",
")",
"{",
"return",
"sprintf",
"(",
"\"%s::%s\"",
",",
"is_object",
"(",
"$",
"callback",
"[",
"0",
"]",
")",
"?",
"get_class",
"(",
"$",
"callback",
"[",
"0",
"]",
")",
":",
"$",
"callback",
"[",
"0",
"]",
",",
"$",
"callback",
"[",
"1",
"]",
")",
";",
"}",
"elseif",
"(",
"!",
"(",
"$",
"callback",
"instanceof",
"\\",
"Closure",
")",
")",
"{",
"return",
"\"<closure>\"",
";",
"}",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Wow. I didn't know php could define a callable of this type. Pete __definately__ wants to know all about this.\"",
")",
";",
"}"
] | Return a string which is a best human readable representation the callback possible
@param Callable $callback
@return string | [
"Return",
"a",
"string",
"which",
"is",
"a",
"best",
"human",
"readable",
"representation",
"the",
"callback",
"possible"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Flock.php#L242-L256 | train |
quantaphp/container-compilation | src/CompiledFactoryMap.php | CompiledFactoryMap.isPathWritable | private function isPathWritable(): bool
{
if (! file_exists($this->path)) {
return is_writable(dirname($this->path));
}
return is_writable($this->path);
} | php | private function isPathWritable(): bool
{
if (! file_exists($this->path)) {
return is_writable(dirname($this->path));
}
return is_writable($this->path);
} | [
"private",
"function",
"isPathWritable",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"path",
")",
")",
"{",
"return",
"is_writable",
"(",
"dirname",
"(",
"$",
"this",
"->",
"path",
")",
")",
";",
"}",
"return",
"is_writable",
"(",
"$",
"this",
"->",
"path",
")",
";",
"}"
] | Return whether the path is writable.
@return bool | [
"Return",
"whether",
"the",
"path",
"is",
"writable",
"."
] | 411ed1b23b50b3362897f2a9a81147bbd4f478e6 | https://github.com/quantaphp/container-compilation/blob/411ed1b23b50b3362897f2a9a81147bbd4f478e6/src/CompiledFactoryMap.php#L101-L108 | train |
quantaphp/container-compilation | src/CompiledFactoryMap.php | CompiledFactoryMap.write | private function write(array $compiled): void
{
$tmp = tempnam(sys_get_temp_dir(), 'quanta');
if ($tmp !== false) {
file_put_contents($tmp, vsprintf('<?php%s%sreturn %s;%s', [
PHP_EOL,
PHP_EOL,
Utils::ArrayStr($compiled ?? []),
PHP_EOL,
]));
rename($tmp, $this->path);
}
} | php | private function write(array $compiled): void
{
$tmp = tempnam(sys_get_temp_dir(), 'quanta');
if ($tmp !== false) {
file_put_contents($tmp, vsprintf('<?php%s%sreturn %s;%s', [
PHP_EOL,
PHP_EOL,
Utils::ArrayStr($compiled ?? []),
PHP_EOL,
]));
rename($tmp, $this->path);
}
} | [
"private",
"function",
"write",
"(",
"array",
"$",
"compiled",
")",
":",
"void",
"{",
"$",
"tmp",
"=",
"tempnam",
"(",
"sys_get_temp_dir",
"(",
")",
",",
"'quanta'",
")",
";",
"if",
"(",
"$",
"tmp",
"!==",
"false",
")",
"{",
"file_put_contents",
"(",
"$",
"tmp",
",",
"vsprintf",
"(",
"'<?php%s%sreturn %s;%s'",
",",
"[",
"PHP_EOL",
",",
"PHP_EOL",
",",
"Utils",
"::",
"ArrayStr",
"(",
"$",
"compiled",
"??",
"[",
"]",
")",
",",
"PHP_EOL",
",",
"]",
")",
")",
";",
"rename",
"(",
"$",
"tmp",
",",
"$",
"this",
"->",
"path",
")",
";",
"}",
"}"
] | Write the given compiled factories array to a unique temporary file and
move it to the compiled file path.
Is this safe ?
@param string[] $compiled
@return void | [
"Write",
"the",
"given",
"compiled",
"factories",
"array",
"to",
"a",
"unique",
"temporary",
"file",
"and",
"move",
"it",
"to",
"the",
"compiled",
"file",
"path",
"."
] | 411ed1b23b50b3362897f2a9a81147bbd4f478e6 | https://github.com/quantaphp/container-compilation/blob/411ed1b23b50b3362897f2a9a81147bbd4f478e6/src/CompiledFactoryMap.php#L119-L133 | train |
quantaphp/container-compilation | src/CompiledFactoryMap.php | CompiledFactoryMap.compiled | public function compiled(callable $callable): string
{
if (! $this->compiler) {
$this->compiler = new Compiler(
new AstAnalyzerAdapter(
new AstAnalyzer
)
);
}
return ($this->compiler)($callable);
} | php | public function compiled(callable $callable): string
{
if (! $this->compiler) {
$this->compiler = new Compiler(
new AstAnalyzerAdapter(
new AstAnalyzer
)
);
}
return ($this->compiler)($callable);
} | [
"public",
"function",
"compiled",
"(",
"callable",
"$",
"callable",
")",
":",
"string",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"compiler",
")",
"{",
"$",
"this",
"->",
"compiler",
"=",
"new",
"Compiler",
"(",
"new",
"AstAnalyzerAdapter",
"(",
"new",
"AstAnalyzer",
")",
")",
";",
"}",
"return",
"(",
"$",
"this",
"->",
"compiler",
")",
"(",
"$",
"callable",
")",
";",
"}"
] | Return a string representation of the given callable.
@param callable $callable
@return string | [
"Return",
"a",
"string",
"representation",
"of",
"the",
"given",
"callable",
"."
] | 411ed1b23b50b3362897f2a9a81147bbd4f478e6 | https://github.com/quantaphp/container-compilation/blob/411ed1b23b50b3362897f2a9a81147bbd4f478e6/src/CompiledFactoryMap.php#L141-L152 | train |
ekyna/Table | Table.php | Table.getContext | public function getContext()
{
if (!$this->locked) {
throw new Exception\LogicException(
'Context is not yet available. You must first call handleRequest()'
);
}
if (null === $this->context) {
$this->context = new Context\Context();
$this->context
->setVisibleColumns(array_keys($this->columns))
->setMaxPerPage($this->config->getPerPageChoices()[0]);
}
return $this->context;
} | php | public function getContext()
{
if (!$this->locked) {
throw new Exception\LogicException(
'Context is not yet available. You must first call handleRequest()'
);
}
if (null === $this->context) {
$this->context = new Context\Context();
$this->context
->setVisibleColumns(array_keys($this->columns))
->setMaxPerPage($this->config->getPerPageChoices()[0]);
}
return $this->context;
} | [
"public",
"function",
"getContext",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"locked",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"LogicException",
"(",
"'Context is not yet available. You must first call handleRequest()'",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"context",
")",
"{",
"$",
"this",
"->",
"context",
"=",
"new",
"Context",
"\\",
"Context",
"(",
")",
";",
"$",
"this",
"->",
"context",
"->",
"setVisibleColumns",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"columns",
")",
")",
"->",
"setMaxPerPage",
"(",
"$",
"this",
"->",
"config",
"->",
"getPerPageChoices",
"(",
")",
"[",
"0",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"context",
";",
"}"
] | Returns the context.
@return Context\ContextInterface | [
"Returns",
"the",
"context",
"."
] | 6f06e8fd8a3248d52f3a91f10508471344db311a | https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Table.php#L384-L400 | train |
ekyna/Table | Table.php | Table.sortElements | public function sortElements()
{
$sort = function ($a, $b) {
/**
* @var Column\ColumnInterface|Filter\FilterInterface $a
* @var Column\ColumnInterface|Filter\FilterInterface $b
*/
$aPos = $a->getConfig()->getPosition();
$bPos = $b->getConfig()->getPosition();
if ($aPos == $bPos) {
return 0;
}
return $aPos > $bPos ? 1 : -1;
};
uasort($this->columns, $sort);
uasort($this->filters, $sort);
// TODO actions
} | php | public function sortElements()
{
$sort = function ($a, $b) {
/**
* @var Column\ColumnInterface|Filter\FilterInterface $a
* @var Column\ColumnInterface|Filter\FilterInterface $b
*/
$aPos = $a->getConfig()->getPosition();
$bPos = $b->getConfig()->getPosition();
if ($aPos == $bPos) {
return 0;
}
return $aPos > $bPos ? 1 : -1;
};
uasort($this->columns, $sort);
uasort($this->filters, $sort);
// TODO actions
} | [
"public",
"function",
"sortElements",
"(",
")",
"{",
"$",
"sort",
"=",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"/**\n * @var Column\\ColumnInterface|Filter\\FilterInterface $a\n * @var Column\\ColumnInterface|Filter\\FilterInterface $b\n */",
"$",
"aPos",
"=",
"$",
"a",
"->",
"getConfig",
"(",
")",
"->",
"getPosition",
"(",
")",
";",
"$",
"bPos",
"=",
"$",
"b",
"->",
"getConfig",
"(",
")",
"->",
"getPosition",
"(",
")",
";",
"if",
"(",
"$",
"aPos",
"==",
"$",
"bPos",
")",
"{",
"return",
"0",
";",
"}",
"return",
"$",
"aPos",
">",
"$",
"bPos",
"?",
"1",
":",
"-",
"1",
";",
"}",
";",
"uasort",
"(",
"$",
"this",
"->",
"columns",
",",
"$",
"sort",
")",
";",
"uasort",
"(",
"$",
"this",
"->",
"filters",
",",
"$",
"sort",
")",
";",
"// TODO actions",
"}"
] | Sorts the columns and filers. | [
"Sorts",
"the",
"columns",
"and",
"filers",
"."
] | 6f06e8fd8a3248d52f3a91f10508471344db311a | https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Table.php#L441-L461 | train |
ekyna/Table | Table.php | Table.getSelectionMode | private function getSelectionMode()
{
if (null !== $mode = $this->config->getSelectionMode()) {
return $mode;
}
if ($this->config->isBatchable() && !empty($this->actions)) {
return Util\Config::SELECTION_MULTIPLE;
}
if ($this->config->isExportable() && $this->config->hasExportAdapters()) {
return Util\Config::SELECTION_MULTIPLE;
}
return null;
} | php | private function getSelectionMode()
{
if (null !== $mode = $this->config->getSelectionMode()) {
return $mode;
}
if ($this->config->isBatchable() && !empty($this->actions)) {
return Util\Config::SELECTION_MULTIPLE;
}
if ($this->config->isExportable() && $this->config->hasExportAdapters()) {
return Util\Config::SELECTION_MULTIPLE;
}
return null;
} | [
"private",
"function",
"getSelectionMode",
"(",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"mode",
"=",
"$",
"this",
"->",
"config",
"->",
"getSelectionMode",
"(",
")",
")",
"{",
"return",
"$",
"mode",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"isBatchable",
"(",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"actions",
")",
")",
"{",
"return",
"Util",
"\\",
"Config",
"::",
"SELECTION_MULTIPLE",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"isExportable",
"(",
")",
"&&",
"$",
"this",
"->",
"config",
"->",
"hasExportAdapters",
"(",
")",
")",
"{",
"return",
"Util",
"\\",
"Config",
"::",
"SELECTION_MULTIPLE",
";",
"}",
"return",
"null",
";",
"}"
] | Returns the table's selection mode.
@return null|string | [
"Returns",
"the",
"table",
"s",
"selection",
"mode",
"."
] | 6f06e8fd8a3248d52f3a91f10508471344db311a | https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Table.php#L706-L721 | train |
danielgp/common-lib | source/MySQLiMultipleExecution.php | MySQLiMultipleExecution.fixTableSource | protected function fixTableSource($refTbl)
{
$outS = [];
if (substr($refTbl, 0, 1) !== '`') {
$outS[] = '`';
}
$psT = strpos($refTbl, '.`');
if ($psT !== false) {
$refTbl = substr($refTbl, $psT + 2, strlen($refTbl) - $psT);
}
$outS[] = $refTbl;
if (substr($refTbl, -1) !== '`') {
$outS[] = '`';
}
return implode('', $outS);
} | php | protected function fixTableSource($refTbl)
{
$outS = [];
if (substr($refTbl, 0, 1) !== '`') {
$outS[] = '`';
}
$psT = strpos($refTbl, '.`');
if ($psT !== false) {
$refTbl = substr($refTbl, $psT + 2, strlen($refTbl) - $psT);
}
$outS[] = $refTbl;
if (substr($refTbl, -1) !== '`') {
$outS[] = '`';
}
return implode('', $outS);
} | [
"protected",
"function",
"fixTableSource",
"(",
"$",
"refTbl",
")",
"{",
"$",
"outS",
"=",
"[",
"]",
";",
"if",
"(",
"substr",
"(",
"$",
"refTbl",
",",
"0",
",",
"1",
")",
"!==",
"'`'",
")",
"{",
"$",
"outS",
"[",
"]",
"=",
"'`'",
";",
"}",
"$",
"psT",
"=",
"strpos",
"(",
"$",
"refTbl",
",",
"'.`'",
")",
";",
"if",
"(",
"$",
"psT",
"!==",
"false",
")",
"{",
"$",
"refTbl",
"=",
"substr",
"(",
"$",
"refTbl",
",",
"$",
"psT",
"+",
"2",
",",
"strlen",
"(",
"$",
"refTbl",
")",
"-",
"$",
"psT",
")",
";",
"}",
"$",
"outS",
"[",
"]",
"=",
"$",
"refTbl",
";",
"if",
"(",
"substr",
"(",
"$",
"refTbl",
",",
"-",
"1",
")",
"!==",
"'`'",
")",
"{",
"$",
"outS",
"[",
"]",
"=",
"'`'",
";",
"}",
"return",
"implode",
"(",
"''",
",",
"$",
"outS",
")",
";",
"}"
] | Adjust table name with proper sufix and prefix
@param string $refTbl
@return string | [
"Adjust",
"table",
"name",
"with",
"proper",
"sufix",
"and",
"prefix"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/MySQLiMultipleExecution.php#L81-L96 | train |
danielgp/common-lib | source/MySQLiMultipleExecution.php | MySQLiMultipleExecution.handleFeatures | protected function handleFeatures($fieldName, $features)
{
$rOly = $this->handleFeaturesSingle($fieldName, $features, 'readonly');
$rDbld = $this->handleFeaturesSingle($fieldName, $features, 'disabled');
$rNl = [];
if (isset($features['include_null']) && in_array($fieldName, $features['include_null'])) {
$rNl = ['include_null'];
}
return array_merge([], $rOly, $rDbld, $rNl);
} | php | protected function handleFeatures($fieldName, $features)
{
$rOly = $this->handleFeaturesSingle($fieldName, $features, 'readonly');
$rDbld = $this->handleFeaturesSingle($fieldName, $features, 'disabled');
$rNl = [];
if (isset($features['include_null']) && in_array($fieldName, $features['include_null'])) {
$rNl = ['include_null'];
}
return array_merge([], $rOly, $rDbld, $rNl);
} | [
"protected",
"function",
"handleFeatures",
"(",
"$",
"fieldName",
",",
"$",
"features",
")",
"{",
"$",
"rOly",
"=",
"$",
"this",
"->",
"handleFeaturesSingle",
"(",
"$",
"fieldName",
",",
"$",
"features",
",",
"'readonly'",
")",
";",
"$",
"rDbld",
"=",
"$",
"this",
"->",
"handleFeaturesSingle",
"(",
"$",
"fieldName",
",",
"$",
"features",
",",
"'disabled'",
")",
";",
"$",
"rNl",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"features",
"[",
"'include_null'",
"]",
")",
"&&",
"in_array",
"(",
"$",
"fieldName",
",",
"$",
"features",
"[",
"'include_null'",
"]",
")",
")",
"{",
"$",
"rNl",
"=",
"[",
"'include_null'",
"]",
";",
"}",
"return",
"array_merge",
"(",
"[",
"]",
",",
"$",
"rOly",
",",
"$",
"rDbld",
",",
"$",
"rNl",
")",
";",
"}"
] | Manages features flag
@param string $fieldName
@param array $features
@return array | [
"Manages",
"features",
"flag"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/MySQLiMultipleExecution.php#L136-L145 | train |
danielgp/common-lib | source/MySQLiMultipleExecution.php | MySQLiMultipleExecution.handleFeaturesSingle | private function handleFeaturesSingle($fieldName, $features, $featureKey)
{
$fMap = [
'readonly' => ['readonly', 'class', 'input_readonly'],
'disabled' => ['disabled']
];
$aReturn = [];
if (array_key_exists($featureKey, $features)) {
if (array_key_exists($fieldName, $features[$featureKey])) {
$aReturn[$featureKey][$fMap[$featureKey][0]] = $fMap[$featureKey][0];
if (count($fMap[$featureKey]) > 1) {
$aReturn[$featureKey][$fMap[$featureKey][1]] = $fMap[$featureKey][2];
}
}
}
return $aReturn;
} | php | private function handleFeaturesSingle($fieldName, $features, $featureKey)
{
$fMap = [
'readonly' => ['readonly', 'class', 'input_readonly'],
'disabled' => ['disabled']
];
$aReturn = [];
if (array_key_exists($featureKey, $features)) {
if (array_key_exists($fieldName, $features[$featureKey])) {
$aReturn[$featureKey][$fMap[$featureKey][0]] = $fMap[$featureKey][0];
if (count($fMap[$featureKey]) > 1) {
$aReturn[$featureKey][$fMap[$featureKey][1]] = $fMap[$featureKey][2];
}
}
}
return $aReturn;
} | [
"private",
"function",
"handleFeaturesSingle",
"(",
"$",
"fieldName",
",",
"$",
"features",
",",
"$",
"featureKey",
")",
"{",
"$",
"fMap",
"=",
"[",
"'readonly'",
"=>",
"[",
"'readonly'",
",",
"'class'",
",",
"'input_readonly'",
"]",
",",
"'disabled'",
"=>",
"[",
"'disabled'",
"]",
"]",
";",
"$",
"aReturn",
"=",
"[",
"]",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"featureKey",
",",
"$",
"features",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"fieldName",
",",
"$",
"features",
"[",
"$",
"featureKey",
"]",
")",
")",
"{",
"$",
"aReturn",
"[",
"$",
"featureKey",
"]",
"[",
"$",
"fMap",
"[",
"$",
"featureKey",
"]",
"[",
"0",
"]",
"]",
"=",
"$",
"fMap",
"[",
"$",
"featureKey",
"]",
"[",
"0",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"fMap",
"[",
"$",
"featureKey",
"]",
")",
">",
"1",
")",
"{",
"$",
"aReturn",
"[",
"$",
"featureKey",
"]",
"[",
"$",
"fMap",
"[",
"$",
"featureKey",
"]",
"[",
"1",
"]",
"]",
"=",
"$",
"fMap",
"[",
"$",
"featureKey",
"]",
"[",
"2",
"]",
";",
"}",
"}",
"}",
"return",
"$",
"aReturn",
";",
"}"
] | Handles the features
@param string $fieldName
@param array $features
@param string $featureKey
@return array | [
"Handles",
"the",
"features"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/MySQLiMultipleExecution.php#L155-L171 | train |
danielgp/common-lib | source/MySQLiMultipleExecution.php | MySQLiMultipleExecution.handleMySqlVersionConsistenly | private function handleMySqlVersionConsistenly()
{
if (substr($this->mySQLconnection->server_info, -7) === 'MariaDB') {
$strVersionParts = explode('.', explode('-', $this->mySQLconnection->server_info)[1]);
return $this->getTwoDecimalsNumber($strVersionParts[0]) . $this->getTwoDecimalsNumber($strVersionParts[1])
. $this->getTwoDecimalsNumber($strVersionParts[2]);
}
return $this->mySQLconnection->server_version;
} | php | private function handleMySqlVersionConsistenly()
{
if (substr($this->mySQLconnection->server_info, -7) === 'MariaDB') {
$strVersionParts = explode('.', explode('-', $this->mySQLconnection->server_info)[1]);
return $this->getTwoDecimalsNumber($strVersionParts[0]) . $this->getTwoDecimalsNumber($strVersionParts[1])
. $this->getTwoDecimalsNumber($strVersionParts[2]);
}
return $this->mySQLconnection->server_version;
} | [
"private",
"function",
"handleMySqlVersionConsistenly",
"(",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"this",
"->",
"mySQLconnection",
"->",
"server_info",
",",
"-",
"7",
")",
"===",
"'MariaDB'",
")",
"{",
"$",
"strVersionParts",
"=",
"explode",
"(",
"'.'",
",",
"explode",
"(",
"'-'",
",",
"$",
"this",
"->",
"mySQLconnection",
"->",
"server_info",
")",
"[",
"1",
"]",
")",
";",
"return",
"$",
"this",
"->",
"getTwoDecimalsNumber",
"(",
"$",
"strVersionParts",
"[",
"0",
"]",
")",
".",
"$",
"this",
"->",
"getTwoDecimalsNumber",
"(",
"$",
"strVersionParts",
"[",
"1",
"]",
")",
".",
"$",
"this",
"->",
"getTwoDecimalsNumber",
"(",
"$",
"strVersionParts",
"[",
"2",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"mySQLconnection",
"->",
"server_version",
";",
"}"
] | Ensures a consistent output of version for MySQL as well as MariaDB
@return string | [
"Ensures",
"a",
"consistent",
"output",
"of",
"version",
"for",
"MySQL",
"as",
"well",
"as",
"MariaDB"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/MySQLiMultipleExecution.php#L178-L186 | train |
danielgp/common-lib | source/MySQLiMultipleExecution.php | MySQLiMultipleExecution.setVariableTypeForMySqlStatements | protected function setVariableTypeForMySqlStatements($variabaleValue)
{
$sReturn = 'b';
if (is_int($variabaleValue)) {
$sReturn = 'i';
} elseif (is_double($variabaleValue)) {
$sReturn = 'd';
} elseif (is_string($variabaleValue)) {
$sReturn = 's';
}
return $sReturn;
} | php | protected function setVariableTypeForMySqlStatements($variabaleValue)
{
$sReturn = 'b';
if (is_int($variabaleValue)) {
$sReturn = 'i';
} elseif (is_double($variabaleValue)) {
$sReturn = 'd';
} elseif (is_string($variabaleValue)) {
$sReturn = 's';
}
return $sReturn;
} | [
"protected",
"function",
"setVariableTypeForMySqlStatements",
"(",
"$",
"variabaleValue",
")",
"{",
"$",
"sReturn",
"=",
"'b'",
";",
"if",
"(",
"is_int",
"(",
"$",
"variabaleValue",
")",
")",
"{",
"$",
"sReturn",
"=",
"'i'",
";",
"}",
"elseif",
"(",
"is_double",
"(",
"$",
"variabaleValue",
")",
")",
"{",
"$",
"sReturn",
"=",
"'d'",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"variabaleValue",
")",
")",
"{",
"$",
"sReturn",
"=",
"'s'",
";",
"}",
"return",
"$",
"sReturn",
";",
"}"
] | Detects what kind of variable has been transmitted
to return the identifier needed by MySQL statement preparing
@return string | [
"Detects",
"what",
"kind",
"of",
"variable",
"has",
"been",
"transmitted",
"to",
"return",
"the",
"identifier",
"needed",
"by",
"MySQL",
"statement",
"preparing"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/MySQLiMultipleExecution.php#L207-L218 | train |
PenoaksDev/Milky-Framework | src/Milky/Database/Eloquent/Nested/SetValidator.php | SetValidator.validateBounds | protected function validateBounds()
{
$connection = $this->model->getConnection();
$grammar = $connection->getQueryGrammar();
$tableName = $this->model->getTable();
$primaryKeyName = $this->model->getKeyName();
$parentColumn = $this->model->getQualifiedParentColumnName();
$lftCol = $grammar->wrap( $this->model->getLeftColumnName() );
$rgtCol = $grammar->wrap( $this->model->getRightColumnName() );
$qualifiedLftCol = $grammar->wrap( $this->model->getQualifiedLeftColumnName() );
$qualifiedRgtCol = $grammar->wrap( $this->model->getQualifiedRightColumnName() );
$qualifiedParentCol = $grammar->wrap( $this->model->getQualifiedParentColumnName() );
$whereStm = "($qualifiedLftCol IS NULL OR
$qualifiedRgtCol IS NULL OR
$qualifiedLftCol >= $qualifiedRgtCol OR
($qualifiedParentCol IS NOT NULL AND
($qualifiedLftCol <= parent.$lftCol OR
$qualifiedRgtCol >= parent.$rgtCol)))";
$query = $this->model->newQuery()->join( $connection->raw( $grammar->wrapTable( $tableName ) . ' AS parent' ), $parentColumn, '=', $connection->raw( 'parent.' . $grammar->wrap( $primaryKeyName ) ), 'left outer' )->whereRaw( $whereStm );
return ( $query->count() == 0 );
} | php | protected function validateBounds()
{
$connection = $this->model->getConnection();
$grammar = $connection->getQueryGrammar();
$tableName = $this->model->getTable();
$primaryKeyName = $this->model->getKeyName();
$parentColumn = $this->model->getQualifiedParentColumnName();
$lftCol = $grammar->wrap( $this->model->getLeftColumnName() );
$rgtCol = $grammar->wrap( $this->model->getRightColumnName() );
$qualifiedLftCol = $grammar->wrap( $this->model->getQualifiedLeftColumnName() );
$qualifiedRgtCol = $grammar->wrap( $this->model->getQualifiedRightColumnName() );
$qualifiedParentCol = $grammar->wrap( $this->model->getQualifiedParentColumnName() );
$whereStm = "($qualifiedLftCol IS NULL OR
$qualifiedRgtCol IS NULL OR
$qualifiedLftCol >= $qualifiedRgtCol OR
($qualifiedParentCol IS NOT NULL AND
($qualifiedLftCol <= parent.$lftCol OR
$qualifiedRgtCol >= parent.$rgtCol)))";
$query = $this->model->newQuery()->join( $connection->raw( $grammar->wrapTable( $tableName ) . ' AS parent' ), $parentColumn, '=', $connection->raw( 'parent.' . $grammar->wrap( $primaryKeyName ) ), 'left outer' )->whereRaw( $whereStm );
return ( $query->count() == 0 );
} | [
"protected",
"function",
"validateBounds",
"(",
")",
"{",
"$",
"connection",
"=",
"$",
"this",
"->",
"model",
"->",
"getConnection",
"(",
")",
";",
"$",
"grammar",
"=",
"$",
"connection",
"->",
"getQueryGrammar",
"(",
")",
";",
"$",
"tableName",
"=",
"$",
"this",
"->",
"model",
"->",
"getTable",
"(",
")",
";",
"$",
"primaryKeyName",
"=",
"$",
"this",
"->",
"model",
"->",
"getKeyName",
"(",
")",
";",
"$",
"parentColumn",
"=",
"$",
"this",
"->",
"model",
"->",
"getQualifiedParentColumnName",
"(",
")",
";",
"$",
"lftCol",
"=",
"$",
"grammar",
"->",
"wrap",
"(",
"$",
"this",
"->",
"model",
"->",
"getLeftColumnName",
"(",
")",
")",
";",
"$",
"rgtCol",
"=",
"$",
"grammar",
"->",
"wrap",
"(",
"$",
"this",
"->",
"model",
"->",
"getRightColumnName",
"(",
")",
")",
";",
"$",
"qualifiedLftCol",
"=",
"$",
"grammar",
"->",
"wrap",
"(",
"$",
"this",
"->",
"model",
"->",
"getQualifiedLeftColumnName",
"(",
")",
")",
";",
"$",
"qualifiedRgtCol",
"=",
"$",
"grammar",
"->",
"wrap",
"(",
"$",
"this",
"->",
"model",
"->",
"getQualifiedRightColumnName",
"(",
")",
")",
";",
"$",
"qualifiedParentCol",
"=",
"$",
"grammar",
"->",
"wrap",
"(",
"$",
"this",
"->",
"model",
"->",
"getQualifiedParentColumnName",
"(",
")",
")",
";",
"$",
"whereStm",
"=",
"\"($qualifiedLftCol IS NULL OR\n $qualifiedRgtCol IS NULL OR\n $qualifiedLftCol >= $qualifiedRgtCol OR\n ($qualifiedParentCol IS NOT NULL AND\n ($qualifiedLftCol <= parent.$lftCol OR\n $qualifiedRgtCol >= parent.$rgtCol)))\"",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"model",
"->",
"newQuery",
"(",
")",
"->",
"join",
"(",
"$",
"connection",
"->",
"raw",
"(",
"$",
"grammar",
"->",
"wrapTable",
"(",
"$",
"tableName",
")",
".",
"' AS parent'",
")",
",",
"$",
"parentColumn",
",",
"'='",
",",
"$",
"connection",
"->",
"raw",
"(",
"'parent.'",
".",
"$",
"grammar",
"->",
"wrap",
"(",
"$",
"primaryKeyName",
")",
")",
",",
"'left outer'",
")",
"->",
"whereRaw",
"(",
"$",
"whereStm",
")",
";",
"return",
"(",
"$",
"query",
"->",
"count",
"(",
")",
"==",
"0",
")",
";",
"}"
] | Validates bounds of the nested tree structure. It will perform checks on
the `lft`, `rgt` and `parent_id` columns. Mainly that they're not null,
rights greater than lefts, and that they're within the bounds of the parent.
@return boolean | [
"Validates",
"bounds",
"of",
"the",
"nested",
"tree",
"structure",
".",
"It",
"will",
"perform",
"checks",
"on",
"the",
"lft",
"rgt",
"and",
"parent_id",
"columns",
".",
"Mainly",
"that",
"they",
"re",
"not",
"null",
"rights",
"greater",
"than",
"lefts",
"and",
"that",
"they",
"re",
"within",
"the",
"bounds",
"of",
"the",
"parent",
"."
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Nested/SetValidator.php#L50-L76 | train |
PenoaksDev/Milky-Framework | src/Milky/Database/Eloquent/Nested/SetValidator.php | SetValidator.validateDuplicates | protected function validateDuplicates()
{
return ( !$this->duplicatesExistForColumn( $this->model->getQualifiedLeftColumnName() ) && !$this->duplicatesExistForColumn( $this->model->getQualifiedRightColumnName() ) );
} | php | protected function validateDuplicates()
{
return ( !$this->duplicatesExistForColumn( $this->model->getQualifiedLeftColumnName() ) && !$this->duplicatesExistForColumn( $this->model->getQualifiedRightColumnName() ) );
} | [
"protected",
"function",
"validateDuplicates",
"(",
")",
"{",
"return",
"(",
"!",
"$",
"this",
"->",
"duplicatesExistForColumn",
"(",
"$",
"this",
"->",
"model",
"->",
"getQualifiedLeftColumnName",
"(",
")",
")",
"&&",
"!",
"$",
"this",
"->",
"duplicatesExistForColumn",
"(",
"$",
"this",
"->",
"model",
"->",
"getQualifiedRightColumnName",
"(",
")",
")",
")",
";",
"}"
] | Checks that there are no duplicates for the `lft` and `rgt` columns.
@return boolean | [
"Checks",
"that",
"there",
"are",
"no",
"duplicates",
"for",
"the",
"lft",
"and",
"rgt",
"columns",
"."
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Nested/SetValidator.php#L83-L86 | train |
PenoaksDev/Milky-Framework | src/Milky/Database/Eloquent/Nested/SetValidator.php | SetValidator.validateRoots | protected function validateRoots()
{
$roots = forward_static_call( [get_class( $this->model ), 'roots'] )->get();
// If a scope is defined in the model we should check that the roots are
// valid *for each* value in the scope columns.
if ( $this->model->isScoped() )
return $this->validateRootsByScope( $roots );
return $this->isEachRootValid( $roots );
} | php | protected function validateRoots()
{
$roots = forward_static_call( [get_class( $this->model ), 'roots'] )->get();
// If a scope is defined in the model we should check that the roots are
// valid *for each* value in the scope columns.
if ( $this->model->isScoped() )
return $this->validateRootsByScope( $roots );
return $this->isEachRootValid( $roots );
} | [
"protected",
"function",
"validateRoots",
"(",
")",
"{",
"$",
"roots",
"=",
"forward_static_call",
"(",
"[",
"get_class",
"(",
"$",
"this",
"->",
"model",
")",
",",
"'roots'",
"]",
")",
"->",
"get",
"(",
")",
";",
"// If a scope is defined in the model we should check that the roots are",
"// valid *for each* value in the scope columns.",
"if",
"(",
"$",
"this",
"->",
"model",
"->",
"isScoped",
"(",
")",
")",
"return",
"$",
"this",
"->",
"validateRootsByScope",
"(",
"$",
"roots",
")",
";",
"return",
"$",
"this",
"->",
"isEachRootValid",
"(",
"$",
"roots",
")",
";",
"}"
] | For each root of the whole nested set tree structure, checks that their
`lft` and `rgt` bounds are properly set.
@return boolean | [
"For",
"each",
"root",
"of",
"the",
"whole",
"nested",
"set",
"tree",
"structure",
"checks",
"that",
"their",
"lft",
"and",
"rgt",
"bounds",
"are",
"properly",
"set",
"."
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Nested/SetValidator.php#L94-L104 | train |
PenoaksDev/Milky-Framework | src/Milky/Database/Eloquent/Nested/SetValidator.php | SetValidator.keyForScope | protected function keyForScope( $model )
{
return implode( '-', array_map( function ( $column ) use ( $model )
{
$value = $model->getAttribute( $column );
if ( is_null( $value ) )
return 'NULL';
return $value;
}, $model->getScopedColumns() ) );
} | php | protected function keyForScope( $model )
{
return implode( '-', array_map( function ( $column ) use ( $model )
{
$value = $model->getAttribute( $column );
if ( is_null( $value ) )
return 'NULL';
return $value;
}, $model->getScopedColumns() ) );
} | [
"protected",
"function",
"keyForScope",
"(",
"$",
"model",
")",
"{",
"return",
"implode",
"(",
"'-'",
",",
"array_map",
"(",
"function",
"(",
"$",
"column",
")",
"use",
"(",
"$",
"model",
")",
"{",
"$",
"value",
"=",
"$",
"model",
"->",
"getAttribute",
"(",
"$",
"column",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"return",
"'NULL'",
";",
"return",
"$",
"value",
";",
"}",
",",
"$",
"model",
"->",
"getScopedColumns",
"(",
")",
")",
")",
";",
"}"
] | Builds a single string for the given scope columns values. Useful for
making array keys for grouping.
@param NestedModel $model
@return string | [
"Builds",
"a",
"single",
"string",
"for",
"the",
"given",
"scope",
"columns",
"values",
".",
"Useful",
"for",
"making",
"array",
"keys",
"for",
"grouping",
"."
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Nested/SetValidator.php#L215-L226 | train |
translationexchange/tml-php-clientsdk | library/Tr8n/Tokens/DataToken.php | DataToken.parse | function parse() {
$name_without_parens = preg_replace('/[{}]/', '', $this->full_name);
$parts = explode('::', $name_without_parens);
$name_without_case_keys = trim($parts[0]);
array_shift($parts);
$this->case_keys = array_map('trim', $parts);
$parts = explode(':', $name_without_case_keys);
$this->short_name = trim($parts[0]);
array_shift($parts);
$this->context_keys = array_map('trim', $parts);
} | php | function parse() {
$name_without_parens = preg_replace('/[{}]/', '', $this->full_name);
$parts = explode('::', $name_without_parens);
$name_without_case_keys = trim($parts[0]);
array_shift($parts);
$this->case_keys = array_map('trim', $parts);
$parts = explode(':', $name_without_case_keys);
$this->short_name = trim($parts[0]);
array_shift($parts);
$this->context_keys = array_map('trim', $parts);
} | [
"function",
"parse",
"(",
")",
"{",
"$",
"name_without_parens",
"=",
"preg_replace",
"(",
"'/[{}]/'",
",",
"''",
",",
"$",
"this",
"->",
"full_name",
")",
";",
"$",
"parts",
"=",
"explode",
"(",
"'::'",
",",
"$",
"name_without_parens",
")",
";",
"$",
"name_without_case_keys",
"=",
"trim",
"(",
"$",
"parts",
"[",
"0",
"]",
")",
";",
"array_shift",
"(",
"$",
"parts",
")",
";",
"$",
"this",
"->",
"case_keys",
"=",
"array_map",
"(",
"'trim'",
",",
"$",
"parts",
")",
";",
"$",
"parts",
"=",
"explode",
"(",
"':'",
",",
"$",
"name_without_case_keys",
")",
";",
"$",
"this",
"->",
"short_name",
"=",
"trim",
"(",
"$",
"parts",
"[",
"0",
"]",
")",
";",
"array_shift",
"(",
"$",
"parts",
")",
";",
"$",
"this",
"->",
"context_keys",
"=",
"array_map",
"(",
"'trim'",
",",
"$",
"parts",
")",
";",
"}"
] | Parses token name elements | [
"Parses",
"token",
"name",
"elements"
] | fe51473824e62cfd883c6aa0c6a3783a16ce8425 | https://github.com/translationexchange/tml-php-clientsdk/blob/fe51473824e62cfd883c6aa0c6a3783a16ce8425/library/Tr8n/Tokens/DataToken.php#L93-L105 | train |
translationexchange/tml-php-clientsdk | library/Tr8n/Tokens/DataToken.php | DataToken.contextForLanguage | public function contextForLanguage($language, $opts = array()) {
if (count($this->context_keys) > 0) {
$ctx = $language->contextByKeyword($this->context_keys[0]);
} else {
$ctx = $language->contextByTokenName($this->short_name);
}
return $ctx;
} | php | public function contextForLanguage($language, $opts = array()) {
if (count($this->context_keys) > 0) {
$ctx = $language->contextByKeyword($this->context_keys[0]);
} else {
$ctx = $language->contextByTokenName($this->short_name);
}
return $ctx;
} | [
"public",
"function",
"contextForLanguage",
"(",
"$",
"language",
",",
"$",
"opts",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"context_keys",
")",
">",
"0",
")",
"{",
"$",
"ctx",
"=",
"$",
"language",
"->",
"contextByKeyword",
"(",
"$",
"this",
"->",
"context_keys",
"[",
"0",
"]",
")",
";",
"}",
"else",
"{",
"$",
"ctx",
"=",
"$",
"language",
"->",
"contextByTokenName",
"(",
"$",
"this",
"->",
"short_name",
")",
";",
"}",
"return",
"$",
"ctx",
";",
"}"
] | For transform tokens, we can only use the first context key, if it is not mapped in the context itself.
{user:gender | male: , female: ... }
It is not possible to apply multiple context rules on a single token at the same time:
{user:gender:value | .... hah?}
It is still possible to setup dependencies on multiple contexts.
{user:gender:value} - just not with transform tokens
@param \Tr8n\Language $language
@param array $opts
@return \Tr8n\LanguageContext|null
@throws \Tr8n\Tr8nException | [
"For",
"transform",
"tokens",
"we",
"can",
"only",
"use",
"the",
"first",
"context",
"key",
"if",
"it",
"is",
"not",
"mapped",
"in",
"the",
"context",
"itself",
"."
] | fe51473824e62cfd883c6aa0c6a3783a16ce8425 | https://github.com/translationexchange/tml-php-clientsdk/blob/fe51473824e62cfd883c6aa0c6a3783a16ce8425/library/Tr8n/Tokens/DataToken.php#L143-L151 | train |
translationexchange/tml-php-clientsdk | library/Tr8n/Tokens/DataToken.php | DataToken.tokenObject | public static function tokenObject($token_values, $token_name) {
if ($token_values == null)
return null;
if (!array_key_exists($token_name, $token_values))
return null;
$token_object = $token_values[$token_name];
if (is_array($token_object)) {
if (\Tr8n\Utils\ArrayUtils::isHash($token_object)) {
if (!array_key_exists('object', $token_object)) return null;
return $token_object['object'];
}
if (count($token_object) == 0)
return null;
return $token_object[0];
}
return $token_object;
} | php | public static function tokenObject($token_values, $token_name) {
if ($token_values == null)
return null;
if (!array_key_exists($token_name, $token_values))
return null;
$token_object = $token_values[$token_name];
if (is_array($token_object)) {
if (\Tr8n\Utils\ArrayUtils::isHash($token_object)) {
if (!array_key_exists('object', $token_object)) return null;
return $token_object['object'];
}
if (count($token_object) == 0)
return null;
return $token_object[0];
}
return $token_object;
} | [
"public",
"static",
"function",
"tokenObject",
"(",
"$",
"token_values",
",",
"$",
"token_name",
")",
"{",
"if",
"(",
"$",
"token_values",
"==",
"null",
")",
"return",
"null",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"token_name",
",",
"$",
"token_values",
")",
")",
"return",
"null",
";",
"$",
"token_object",
"=",
"$",
"token_values",
"[",
"$",
"token_name",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"token_object",
")",
")",
"{",
"if",
"(",
"\\",
"Tr8n",
"\\",
"Utils",
"\\",
"ArrayUtils",
"::",
"isHash",
"(",
"$",
"token_object",
")",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"'object'",
",",
"$",
"token_object",
")",
")",
"return",
"null",
";",
"return",
"$",
"token_object",
"[",
"'object'",
"]",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"token_object",
")",
"==",
"0",
")",
"return",
"null",
";",
"return",
"$",
"token_object",
"[",
"0",
"]",
";",
"}",
"return",
"$",
"token_object",
";",
"}"
] | Returns an object from values hash.
@param mixed[] $token_values
@param string $token_name
@return mixed | [
"Returns",
"an",
"object",
"from",
"values",
"hash",
"."
] | fe51473824e62cfd883c6aa0c6a3783a16ce8425 | https://github.com/translationexchange/tml-php-clientsdk/blob/fe51473824e62cfd883c6aa0c6a3783a16ce8425/library/Tr8n/Tokens/DataToken.php#L160-L180 | train |
translationexchange/tml-php-clientsdk | library/Tr8n/Tokens/DataToken.php | DataToken.tokenValueFromArrayParam | public function tokenValueFromArrayParam($token_data, $language, $options = array()) {
// if you provided an array, it better have some values
if (count($token_data) == 0)
return $this->error("Invalid number of params of an array");
$object = $token_data[0];
$method = count($token_data) > 1 ? $token_data[1] : null;
// if the first value of an array is an array handle it here
if (is_array($object) && !(ArrayUtils::isHash($object))) {
return $this->tokenValuesFromArray($token_data, $language, $options);
}
if ($method == null)
return $this->sanitize("" . $object, $object, $language, array_merge($options, array("safe" => true)));
if (is_string($method)) {
if (preg_match('/^@/', $method))
return $this->tokenValueFromObjectUsingAttributeMethod($object, $method, $language, $options);
return $this->sanitize($method, $object, $language, array_merge($options, array("safe" => true)));
}
return $this->error("Unsupported second array value");
} | php | public function tokenValueFromArrayParam($token_data, $language, $options = array()) {
// if you provided an array, it better have some values
if (count($token_data) == 0)
return $this->error("Invalid number of params of an array");
$object = $token_data[0];
$method = count($token_data) > 1 ? $token_data[1] : null;
// if the first value of an array is an array handle it here
if (is_array($object) && !(ArrayUtils::isHash($object))) {
return $this->tokenValuesFromArray($token_data, $language, $options);
}
if ($method == null)
return $this->sanitize("" . $object, $object, $language, array_merge($options, array("safe" => true)));
if (is_string($method)) {
if (preg_match('/^@/', $method))
return $this->tokenValueFromObjectUsingAttributeMethod($object, $method, $language, $options);
return $this->sanitize($method, $object, $language, array_merge($options, array("safe" => true)));
}
return $this->error("Unsupported second array value");
} | [
"public",
"function",
"tokenValueFromArrayParam",
"(",
"$",
"token_data",
",",
"$",
"language",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"// if you provided an array, it better have some values",
"if",
"(",
"count",
"(",
"$",
"token_data",
")",
"==",
"0",
")",
"return",
"$",
"this",
"->",
"error",
"(",
"\"Invalid number of params of an array\"",
")",
";",
"$",
"object",
"=",
"$",
"token_data",
"[",
"0",
"]",
";",
"$",
"method",
"=",
"count",
"(",
"$",
"token_data",
")",
">",
"1",
"?",
"$",
"token_data",
"[",
"1",
"]",
":",
"null",
";",
"// if the first value of an array is an array handle it here",
"if",
"(",
"is_array",
"(",
"$",
"object",
")",
"&&",
"!",
"(",
"ArrayUtils",
"::",
"isHash",
"(",
"$",
"object",
")",
")",
")",
"{",
"return",
"$",
"this",
"->",
"tokenValuesFromArray",
"(",
"$",
"token_data",
",",
"$",
"language",
",",
"$",
"options",
")",
";",
"}",
"if",
"(",
"$",
"method",
"==",
"null",
")",
"return",
"$",
"this",
"->",
"sanitize",
"(",
"\"\"",
".",
"$",
"object",
",",
"$",
"object",
",",
"$",
"language",
",",
"array_merge",
"(",
"$",
"options",
",",
"array",
"(",
"\"safe\"",
"=>",
"true",
")",
")",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"method",
")",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^@/'",
",",
"$",
"method",
")",
")",
"return",
"$",
"this",
"->",
"tokenValueFromObjectUsingAttributeMethod",
"(",
"$",
"object",
",",
"$",
"method",
",",
"$",
"language",
",",
"$",
"options",
")",
";",
"return",
"$",
"this",
"->",
"sanitize",
"(",
"$",
"method",
",",
"$",
"object",
",",
"$",
"language",
",",
"array_merge",
"(",
"$",
"options",
",",
"array",
"(",
"\"safe\"",
"=>",
"true",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"error",
"(",
"\"Unsupported second array value\"",
")",
";",
"}"
] | gets the value based on various evaluation methods
examples:
tr("Hello {user}", array("user" => array($current_user, $current_user->name)))
tr("Hello {user}", array("user" => array($current_user, "@name")))
tr("Hello {user}", array("user" => array($current_user, "@@firstName")))
tr("Hello {user}", {:user => array(array("name" => "Michael", "gender" => "male"), "Michael")))
tr("Hello {user}", {:user => array(array("name" => "Michael", "gender" => "male"), "@name")))
@param $array
@param $language
@param $options | [
"gets",
"the",
"value",
"based",
"on",
"various",
"evaluation",
"methods"
] | fe51473824e62cfd883c6aa0c6a3783a16ce8425 | https://github.com/translationexchange/tml-php-clientsdk/blob/fe51473824e62cfd883c6aa0c6a3783a16ce8425/library/Tr8n/Tokens/DataToken.php#L199-L222 | train |
translationexchange/tml-php-clientsdk | library/Tr8n/Tokens/DataToken.php | DataToken.tokenValue | public function tokenValue($token_values, $language, $options = array()) {
if (isset($token_values[$this->short_name])) {
$object = $token_values[$this->short_name];
} else {
$object = Config::instance()->defaultToken($this->short_name, 'data');
}
if ($object === null)
return $this->error("Missing token value");
if (is_string($object) || is_numeric($object) || is_double($object)) {
return $this->sanitize($object, $object, $language, array_merge($options, array("safe" => true)));
}
if (is_array($object)) {
if (\Tr8n\Utils\ArrayUtils::isHash($object))
return $this->tokenValueFromHashParam($object, $language, $options);
return $this->tokenValueFromArrayParam($object, $language, $options);
}
return $this->sanitize($object, $object, $language, array_merge($options, array("safe" => false)));
} | php | public function tokenValue($token_values, $language, $options = array()) {
if (isset($token_values[$this->short_name])) {
$object = $token_values[$this->short_name];
} else {
$object = Config::instance()->defaultToken($this->short_name, 'data');
}
if ($object === null)
return $this->error("Missing token value");
if (is_string($object) || is_numeric($object) || is_double($object)) {
return $this->sanitize($object, $object, $language, array_merge($options, array("safe" => true)));
}
if (is_array($object)) {
if (\Tr8n\Utils\ArrayUtils::isHash($object))
return $this->tokenValueFromHashParam($object, $language, $options);
return $this->tokenValueFromArrayParam($object, $language, $options);
}
return $this->sanitize($object, $object, $language, array_merge($options, array("safe" => false)));
} | [
"public",
"function",
"tokenValue",
"(",
"$",
"token_values",
",",
"$",
"language",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"token_values",
"[",
"$",
"this",
"->",
"short_name",
"]",
")",
")",
"{",
"$",
"object",
"=",
"$",
"token_values",
"[",
"$",
"this",
"->",
"short_name",
"]",
";",
"}",
"else",
"{",
"$",
"object",
"=",
"Config",
"::",
"instance",
"(",
")",
"->",
"defaultToken",
"(",
"$",
"this",
"->",
"short_name",
",",
"'data'",
")",
";",
"}",
"if",
"(",
"$",
"object",
"===",
"null",
")",
"return",
"$",
"this",
"->",
"error",
"(",
"\"Missing token value\"",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"object",
")",
"||",
"is_numeric",
"(",
"$",
"object",
")",
"||",
"is_double",
"(",
"$",
"object",
")",
")",
"{",
"return",
"$",
"this",
"->",
"sanitize",
"(",
"$",
"object",
",",
"$",
"object",
",",
"$",
"language",
",",
"array_merge",
"(",
"$",
"options",
",",
"array",
"(",
"\"safe\"",
"=>",
"true",
")",
")",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"object",
")",
")",
"{",
"if",
"(",
"\\",
"Tr8n",
"\\",
"Utils",
"\\",
"ArrayUtils",
"::",
"isHash",
"(",
"$",
"object",
")",
")",
"return",
"$",
"this",
"->",
"tokenValueFromHashParam",
"(",
"$",
"object",
",",
"$",
"language",
",",
"$",
"options",
")",
";",
"return",
"$",
"this",
"->",
"tokenValueFromArrayParam",
"(",
"$",
"object",
",",
"$",
"language",
",",
"$",
"options",
")",
";",
"}",
"return",
"$",
"this",
"->",
"sanitize",
"(",
"$",
"object",
",",
"$",
"object",
",",
"$",
"language",
",",
"array_merge",
"(",
"$",
"options",
",",
"array",
"(",
"\"safe\"",
"=>",
"false",
")",
")",
")",
";",
"}"
] | Returns a value from values hash.
@param mixed[] $token_values
@param \Tr8n\Language $language
@param array $options
@return string
@throws \Tr8n\Tr8nException | [
"Returns",
"a",
"value",
"from",
"values",
"hash",
"."
] | fe51473824e62cfd883c6aa0c6a3783a16ce8425 | https://github.com/translationexchange/tml-php-clientsdk/blob/fe51473824e62cfd883c6aa0c6a3783a16ce8425/library/Tr8n/Tokens/DataToken.php#L494-L515 | train |
translationexchange/tml-php-clientsdk | library/Tr8n/Tokens/DataToken.php | DataToken.substitute | public function substitute($label, $token_values, $language, $options = array()) {
// Logger::instance()->debug("Substituting $label in " . $language->locale);
$token_value = $this->tokenValue($token_values, $language, $options);
return str_replace($this->full_name, $token_value, $label);
} | php | public function substitute($label, $token_values, $language, $options = array()) {
// Logger::instance()->debug("Substituting $label in " . $language->locale);
$token_value = $this->tokenValue($token_values, $language, $options);
return str_replace($this->full_name, $token_value, $label);
} | [
"public",
"function",
"substitute",
"(",
"$",
"label",
",",
"$",
"token_values",
",",
"$",
"language",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"// Logger::instance()->debug(\"Substituting $label in \" . $language->locale);",
"$",
"token_value",
"=",
"$",
"this",
"->",
"tokenValue",
"(",
"$",
"token_values",
",",
"$",
"language",
",",
"$",
"options",
")",
";",
"return",
"str_replace",
"(",
"$",
"this",
"->",
"full_name",
",",
"$",
"token_value",
",",
"$",
"label",
")",
";",
"}"
] | Main substitution function
@param string $label
@param mixed[] $token_values
@param \Tr8n\Language $language
@param mixed[] $options
@return mixed | [
"Main",
"substitution",
"function"
] | fe51473824e62cfd883c6aa0c6a3783a16ce8425 | https://github.com/translationexchange/tml-php-clientsdk/blob/fe51473824e62cfd883c6aa0c6a3783a16ce8425/library/Tr8n/Tokens/DataToken.php#L581-L585 | train |
fxpio/fxp-doctrine-extensions | Util/SqlFilterUtil.php | SqlFilterUtil.findFilters | public static function findFilters($om, array $filters, $all = false)
{
if (!$om instanceof EntityManagerInterface || (empty($filters) && !$all)) {
return [];
}
$all = ($all && !empty($filters)) ? false : $all;
$enabledFilters = self::getEnabledFilters($om);
return self::doFindFilters($filters, $enabledFilters, $all);
} | php | public static function findFilters($om, array $filters, $all = false)
{
if (!$om instanceof EntityManagerInterface || (empty($filters) && !$all)) {
return [];
}
$all = ($all && !empty($filters)) ? false : $all;
$enabledFilters = self::getEnabledFilters($om);
return self::doFindFilters($filters, $enabledFilters, $all);
} | [
"public",
"static",
"function",
"findFilters",
"(",
"$",
"om",
",",
"array",
"$",
"filters",
",",
"$",
"all",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"om",
"instanceof",
"EntityManagerInterface",
"||",
"(",
"empty",
"(",
"$",
"filters",
")",
"&&",
"!",
"$",
"all",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"all",
"=",
"(",
"$",
"all",
"&&",
"!",
"empty",
"(",
"$",
"filters",
")",
")",
"?",
"false",
":",
"$",
"all",
";",
"$",
"enabledFilters",
"=",
"self",
"::",
"getEnabledFilters",
"(",
"$",
"om",
")",
";",
"return",
"self",
"::",
"doFindFilters",
"(",
"$",
"filters",
",",
"$",
"enabledFilters",
",",
"$",
"all",
")",
";",
"}"
] | Get the list of SQL Filter name must to be disabled.
@param null|ObjectManager $om The object manager instance
@param string[] $filters The list of SQL Filter
@param bool $all Force all SQL Filter
@return string[] | [
"Get",
"the",
"list",
"of",
"SQL",
"Filter",
"name",
"must",
"to",
"be",
"disabled",
"."
] | 82942f51d47cdd79a20a5725ee1b3ecfc69e9d77 | https://github.com/fxpio/fxp-doctrine-extensions/blob/82942f51d47cdd79a20a5725ee1b3ecfc69e9d77/Util/SqlFilterUtil.php#L33-L43 | train |
fxpio/fxp-doctrine-extensions | Util/SqlFilterUtil.php | SqlFilterUtil.getEnabledFilters | public static function getEnabledFilters($om)
{
$filters = [];
if ($om instanceof EntityManagerInterface) {
$enabledFilters = $om->getFilters()->getEnabledFilters();
foreach ($enabledFilters as $name => $filter) {
if (!$filter instanceof EnableFilterInterface
|| ($filter instanceof EnableFilterInterface && $filter->isEnabled())) {
$filters[$name] = $filter;
}
}
}
return $filters;
} | php | public static function getEnabledFilters($om)
{
$filters = [];
if ($om instanceof EntityManagerInterface) {
$enabledFilters = $om->getFilters()->getEnabledFilters();
foreach ($enabledFilters as $name => $filter) {
if (!$filter instanceof EnableFilterInterface
|| ($filter instanceof EnableFilterInterface && $filter->isEnabled())) {
$filters[$name] = $filter;
}
}
}
return $filters;
} | [
"public",
"static",
"function",
"getEnabledFilters",
"(",
"$",
"om",
")",
"{",
"$",
"filters",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"om",
"instanceof",
"EntityManagerInterface",
")",
"{",
"$",
"enabledFilters",
"=",
"$",
"om",
"->",
"getFilters",
"(",
")",
"->",
"getEnabledFilters",
"(",
")",
";",
"foreach",
"(",
"$",
"enabledFilters",
"as",
"$",
"name",
"=>",
"$",
"filter",
")",
"{",
"if",
"(",
"!",
"$",
"filter",
"instanceof",
"EnableFilterInterface",
"||",
"(",
"$",
"filter",
"instanceof",
"EnableFilterInterface",
"&&",
"$",
"filter",
"->",
"isEnabled",
"(",
")",
")",
")",
"{",
"$",
"filters",
"[",
"$",
"name",
"]",
"=",
"$",
"filter",
";",
"}",
"}",
"}",
"return",
"$",
"filters",
";",
"}"
] | Get the enabled sql filters.
@param null|ObjectManager $om The object manager instance
@return SQLFilter[] | [
"Get",
"the",
"enabled",
"sql",
"filters",
"."
] | 82942f51d47cdd79a20a5725ee1b3ecfc69e9d77 | https://github.com/fxpio/fxp-doctrine-extensions/blob/82942f51d47cdd79a20a5725ee1b3ecfc69e9d77/Util/SqlFilterUtil.php#L52-L68 | train |
fxpio/fxp-doctrine-extensions | Util/SqlFilterUtil.php | SqlFilterUtil.isEnabled | public static function isEnabled($om, $name)
{
if ($om instanceof EntityManagerInterface) {
$sqlFilters = $om->getFilters();
if ($sqlFilters->isEnabled($name)) {
$filter = $sqlFilters->getFilter($name);
return !$filter instanceof EnableFilterInterface
|| ($filter instanceof EnableFilterInterface && $filter->isEnabled());
}
}
return false;
} | php | public static function isEnabled($om, $name)
{
if ($om instanceof EntityManagerInterface) {
$sqlFilters = $om->getFilters();
if ($sqlFilters->isEnabled($name)) {
$filter = $sqlFilters->getFilter($name);
return !$filter instanceof EnableFilterInterface
|| ($filter instanceof EnableFilterInterface && $filter->isEnabled());
}
}
return false;
} | [
"public",
"static",
"function",
"isEnabled",
"(",
"$",
"om",
",",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"om",
"instanceof",
"EntityManagerInterface",
")",
"{",
"$",
"sqlFilters",
"=",
"$",
"om",
"->",
"getFilters",
"(",
")",
";",
"if",
"(",
"$",
"sqlFilters",
"->",
"isEnabled",
"(",
"$",
"name",
")",
")",
"{",
"$",
"filter",
"=",
"$",
"sqlFilters",
"->",
"getFilter",
"(",
"$",
"name",
")",
";",
"return",
"!",
"$",
"filter",
"instanceof",
"EnableFilterInterface",
"||",
"(",
"$",
"filter",
"instanceof",
"EnableFilterInterface",
"&&",
"$",
"filter",
"->",
"isEnabled",
"(",
")",
")",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Check if the filter is enabled.
@param null|ObjectManager $om The object manager instance
@param string $name The filter name
@return bool | [
"Check",
"if",
"the",
"filter",
"is",
"enabled",
"."
] | 82942f51d47cdd79a20a5725ee1b3ecfc69e9d77 | https://github.com/fxpio/fxp-doctrine-extensions/blob/82942f51d47cdd79a20a5725ee1b3ecfc69e9d77/Util/SqlFilterUtil.php#L100-L114 | train |
fxpio/fxp-doctrine-extensions | Util/SqlFilterUtil.php | SqlFilterUtil.doFindFilters | protected static function doFindFilters(array $filters, array $enabledFilters, $all)
{
$reactivateFilters = [];
foreach ($enabledFilters as $name => $filter) {
if (\in_array($name, $filters, true) || $all) {
$reactivateFilters[] = $name;
}
}
return $reactivateFilters;
} | php | protected static function doFindFilters(array $filters, array $enabledFilters, $all)
{
$reactivateFilters = [];
foreach ($enabledFilters as $name => $filter) {
if (\in_array($name, $filters, true) || $all) {
$reactivateFilters[] = $name;
}
}
return $reactivateFilters;
} | [
"protected",
"static",
"function",
"doFindFilters",
"(",
"array",
"$",
"filters",
",",
"array",
"$",
"enabledFilters",
",",
"$",
"all",
")",
"{",
"$",
"reactivateFilters",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"enabledFilters",
"as",
"$",
"name",
"=>",
"$",
"filter",
")",
"{",
"if",
"(",
"\\",
"in_array",
"(",
"$",
"name",
",",
"$",
"filters",
",",
"true",
")",
"||",
"$",
"all",
")",
"{",
"$",
"reactivateFilters",
"[",
"]",
"=",
"$",
"name",
";",
"}",
"}",
"return",
"$",
"reactivateFilters",
";",
"}"
] | Do find filters.
@param string[] $filters The filters names to be found
@param SQLFilter[] $enabledFilters The enabled SQL Filters
@param bool $all Force all SQL Filter
@return array | [
"Do",
"find",
"filters",
"."
] | 82942f51d47cdd79a20a5725ee1b3ecfc69e9d77 | https://github.com/fxpio/fxp-doctrine-extensions/blob/82942f51d47cdd79a20a5725ee1b3ecfc69e9d77/Util/SqlFilterUtil.php#L125-L136 | train |
Wedeto/HTTP | src/Response/DataResponse.php | DataResponse.setFileFormats | public function setFileFormats(array $formats)
{
$this->file_formats = array();
foreach ($formats as $mime => $writer)
$this->addFileFormat($mime, $writer);
return $this;
} | php | public function setFileFormats(array $formats)
{
$this->file_formats = array();
foreach ($formats as $mime => $writer)
$this->addFileFormat($mime, $writer);
return $this;
} | [
"public",
"function",
"setFileFormats",
"(",
"array",
"$",
"formats",
")",
"{",
"$",
"this",
"->",
"file_formats",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"formats",
"as",
"$",
"mime",
"=>",
"$",
"writer",
")",
"$",
"this",
"->",
"addFileFormat",
"(",
"$",
"mime",
",",
"$",
"writer",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the available file formats - replacing the previous list
@param array $formats Assocative array of mime-type => writer-class pairs
@return DataResponse Provides fluent interface | [
"Set",
"the",
"available",
"file",
"formats",
"-",
"replacing",
"the",
"previous",
"list"
] | 7318eff1b81a3c103c4263466d09b7f3593b70b9 | https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Response/DataResponse.php#L78-L85 | train |
Wedeto/HTTP | src/Response/DataResponse.php | DataResponse.forceMimeType | public function forceMimeType(string $mime)
{
if (!isset($this->file_formats[$mime]))
{
throw new \InvalidArgumentException(
"Cannot force output without a writer available: " . $mime
);
}
$this->file_formats = [$mime => $this->file_formats[$mime]];
return $this;
} | php | public function forceMimeType(string $mime)
{
if (!isset($this->file_formats[$mime]))
{
throw new \InvalidArgumentException(
"Cannot force output without a writer available: " . $mime
);
}
$this->file_formats = [$mime => $this->file_formats[$mime]];
return $this;
} | [
"public",
"function",
"forceMimeType",
"(",
"string",
"$",
"mime",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"file_formats",
"[",
"$",
"mime",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Cannot force output without a writer available: \"",
".",
"$",
"mime",
")",
";",
"}",
"$",
"this",
"->",
"file_formats",
"=",
"[",
"$",
"mime",
"=>",
"$",
"this",
"->",
"file_formats",
"[",
"$",
"mime",
"]",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Reduce the list of available file formats to a single one
@param string $mime The mime type to output. Must already be known
@return DataResponse Provides fluent interface | [
"Reduce",
"the",
"list",
"of",
"available",
"file",
"formats",
"to",
"a",
"single",
"one"
] | 7318eff1b81a3c103c4263466d09b7f3593b70b9 | https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Response/DataResponse.php#L92-L103 | train |
Wedeto/HTTP | src/Response/DataResponse.php | DataResponse.addFileFormat | public function addFileFormat(string $mime_type, $writer_class)
{
if (is_string($writer_class))
{
if (!class_exists($writer_class) || !(is_subclass_of($writer_class, AbstractWriter::class, $writer_class)))
{
throw new InvalidArgumentException(
"Class {$writer_class} does not exist or does not implement " . AbstractWriter::class
);
}
$this->file_formats[$mime_type] = $writer_class;
}
elseif ($writer_class instanceof AbstractWriter)
{
$this->file_formats[$mime_type] = $writer_class;
}
else
{
throw new InvalidArgumentException(
"Invalid writer specified: " . WF::str($writer_class)
);
}
$this->file_formats[$mime_type] = $writer_class;
return $this;
} | php | public function addFileFormat(string $mime_type, $writer_class)
{
if (is_string($writer_class))
{
if (!class_exists($writer_class) || !(is_subclass_of($writer_class, AbstractWriter::class, $writer_class)))
{
throw new InvalidArgumentException(
"Class {$writer_class} does not exist or does not implement " . AbstractWriter::class
);
}
$this->file_formats[$mime_type] = $writer_class;
}
elseif ($writer_class instanceof AbstractWriter)
{
$this->file_formats[$mime_type] = $writer_class;
}
else
{
throw new InvalidArgumentException(
"Invalid writer specified: " . WF::str($writer_class)
);
}
$this->file_formats[$mime_type] = $writer_class;
return $this;
} | [
"public",
"function",
"addFileFormat",
"(",
"string",
"$",
"mime_type",
",",
"$",
"writer_class",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"writer_class",
")",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"writer_class",
")",
"||",
"!",
"(",
"is_subclass_of",
"(",
"$",
"writer_class",
",",
"AbstractWriter",
"::",
"class",
",",
"$",
"writer_class",
")",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Class {$writer_class} does not exist or does not implement \"",
".",
"AbstractWriter",
"::",
"class",
")",
";",
"}",
"$",
"this",
"->",
"file_formats",
"[",
"$",
"mime_type",
"]",
"=",
"$",
"writer_class",
";",
"}",
"elseif",
"(",
"$",
"writer_class",
"instanceof",
"AbstractWriter",
")",
"{",
"$",
"this",
"->",
"file_formats",
"[",
"$",
"mime_type",
"]",
"=",
"$",
"writer_class",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Invalid writer specified: \"",
".",
"WF",
"::",
"str",
"(",
"$",
"writer_class",
")",
")",
";",
"}",
"$",
"this",
"->",
"file_formats",
"[",
"$",
"mime_type",
"]",
"=",
"$",
"writer_class",
";",
"return",
"$",
"this",
";",
"}"
] | Add a file format that this writer can output. This can be used to
add a custom mime-type -> writer mapping. If the format is already
registered, it is overwritten.
@param string $mime_type The mime type to register
@param string $writer_class The writer class. Should subclass AbstractWriter
@return Wedeto\HTTP\DataResponse Provides fluent interface | [
"Add",
"a",
"file",
"format",
"that",
"this",
"writer",
"can",
"output",
".",
"This",
"can",
"be",
"used",
"to",
"add",
"a",
"custom",
"mime",
"-",
"type",
"-",
">",
"writer",
"mapping",
".",
"If",
"the",
"format",
"is",
"already",
"registered",
"it",
"is",
"overwritten",
"."
] | 7318eff1b81a3c103c4263466d09b7f3593b70b9 | https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Response/DataResponse.php#L114-L139 | train |
Wedeto/HTTP | src/Response/DataResponse.php | DataResponse.output | public function output(string $mime)
{
$pprint = $this->pretty_printing;
$classname = $this->file_formats[$mime] ?? "NullWriter";
$output = "";
try
{
if ($classname instanceof AbstractWriter)
$writer = $classname;
elseif (class_exists($classname))
$writer = new $classname($pprint);
else
throw new InvalidArgumentException("Response writer $classname does not exist");
$writer->setPrettyPrint($pprint);
$op = fopen("php://output", "w");
$writer->write($this->data, $op);
fclose($op);
}
catch (Throwable $e)
{
// Bad. Attempt to override response type if still possible
self::getLogger()->critical('Could not output data, exception occured while writing: {0}', [$e]);
echo WF::str($this->data->getAll());
}
} | php | public function output(string $mime)
{
$pprint = $this->pretty_printing;
$classname = $this->file_formats[$mime] ?? "NullWriter";
$output = "";
try
{
if ($classname instanceof AbstractWriter)
$writer = $classname;
elseif (class_exists($classname))
$writer = new $classname($pprint);
else
throw new InvalidArgumentException("Response writer $classname does not exist");
$writer->setPrettyPrint($pprint);
$op = fopen("php://output", "w");
$writer->write($this->data, $op);
fclose($op);
}
catch (Throwable $e)
{
// Bad. Attempt to override response type if still possible
self::getLogger()->critical('Could not output data, exception occured while writing: {0}', [$e]);
echo WF::str($this->data->getAll());
}
} | [
"public",
"function",
"output",
"(",
"string",
"$",
"mime",
")",
"{",
"$",
"pprint",
"=",
"$",
"this",
"->",
"pretty_printing",
";",
"$",
"classname",
"=",
"$",
"this",
"->",
"file_formats",
"[",
"$",
"mime",
"]",
"??",
"\"NullWriter\"",
";",
"$",
"output",
"=",
"\"\"",
";",
"try",
"{",
"if",
"(",
"$",
"classname",
"instanceof",
"AbstractWriter",
")",
"$",
"writer",
"=",
"$",
"classname",
";",
"elseif",
"(",
"class_exists",
"(",
"$",
"classname",
")",
")",
"$",
"writer",
"=",
"new",
"$",
"classname",
"(",
"$",
"pprint",
")",
";",
"else",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Response writer $classname does not exist\"",
")",
";",
"$",
"writer",
"->",
"setPrettyPrint",
"(",
"$",
"pprint",
")",
";",
"$",
"op",
"=",
"fopen",
"(",
"\"php://output\"",
",",
"\"w\"",
")",
";",
"$",
"writer",
"->",
"write",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"op",
")",
";",
"fclose",
"(",
"$",
"op",
")",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"e",
")",
"{",
"// Bad. Attempt to override response type if still possible",
"self",
"::",
"getLogger",
"(",
")",
"->",
"critical",
"(",
"'Could not output data, exception occured while writing: {0}'",
",",
"[",
"$",
"e",
"]",
")",
";",
"echo",
"WF",
"::",
"str",
"(",
"$",
"this",
"->",
"data",
"->",
"getAll",
"(",
")",
")",
";",
"}",
"}"
] | Output the response data in the selected format
@param string $mime The mime type to output | [
"Output",
"the",
"response",
"data",
"in",
"the",
"selected",
"format"
] | 7318eff1b81a3c103c4263466d09b7f3593b70b9 | https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/Response/DataResponse.php#L185-L211 | train |
mtils/cmsable | src/Cmsable/Resource/EloquentRepository.php | EloquentRepository.findOrFail | public function findOrFail($id)
{
if ($model = $this->find($id)) {
return $model;
}
throw (new ModelNotFoundException)->setModel(get_class($this->getModel()));
} | php | public function findOrFail($id)
{
if ($model = $this->find($id)) {
return $model;
}
throw (new ModelNotFoundException)->setModel(get_class($this->getModel()));
} | [
"public",
"function",
"findOrFail",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"$",
"model",
"=",
"$",
"this",
"->",
"find",
"(",
"$",
"id",
")",
")",
"{",
"return",
"$",
"model",
";",
"}",
"throw",
"(",
"new",
"ModelNotFoundException",
")",
"->",
"setModel",
"(",
"get_class",
"(",
"$",
"this",
"->",
"getModel",
"(",
")",
")",
")",
";",
"}"
] | Find and throw an exception if model not found
@return mixed The resource | [
"Find",
"and",
"throw",
"an",
"exception",
"if",
"model",
"not",
"found"
] | 03ae84ee3c7d46146f2a1cf687e5c29d6de4286d | https://github.com/mtils/cmsable/blob/03ae84ee3c7d46146f2a1cf687e5c29d6de4286d/src/Cmsable/Resource/EloquentRepository.php#L45-L51 | train |
Raphhh/puppy-static-route | src/StaticController.php | StaticController.render | public function render(array $vars = array())
{
$templateFile = $this->getTemplateRouter()->findTemplateFile($this->getRequest());
if ($templateFile) {
return $this->getAppController()->render($templateFile, $vars);
}
return $this->getAppController()->error404();
} | php | public function render(array $vars = array())
{
$templateFile = $this->getTemplateRouter()->findTemplateFile($this->getRequest());
if ($templateFile) {
return $this->getAppController()->render($templateFile, $vars);
}
return $this->getAppController()->error404();
} | [
"public",
"function",
"render",
"(",
"array",
"$",
"vars",
"=",
"array",
"(",
")",
")",
"{",
"$",
"templateFile",
"=",
"$",
"this",
"->",
"getTemplateRouter",
"(",
")",
"->",
"findTemplateFile",
"(",
"$",
"this",
"->",
"getRequest",
"(",
")",
")",
";",
"if",
"(",
"$",
"templateFile",
")",
"{",
"return",
"$",
"this",
"->",
"getAppController",
"(",
")",
"->",
"render",
"(",
"$",
"templateFile",
",",
"$",
"vars",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getAppController",
"(",
")",
"->",
"error404",
"(",
")",
";",
"}"
] | renders the template associated with the current route.
@param array $vars
@return mixed | [
"renders",
"the",
"template",
"associated",
"with",
"the",
"current",
"route",
"."
] | 08d94ffdd9cc58fff1b0cae6982cc51b6e4ece5a | https://github.com/Raphhh/puppy-static-route/blob/08d94ffdd9cc58fff1b0cae6982cc51b6e4ece5a/src/StaticController.php#L51-L58 | train |
Raphhh/puppy-static-route | src/StaticController.php | StaticController.redirect | public function redirect(array $flashes = array())
{
foreach($flashes as $type => $message){
$this->getAppController()->flash()->add($type, $message);
}
return $this->getAppController()->redirect($this->getRequest()->getRequestUri());
} | php | public function redirect(array $flashes = array())
{
foreach($flashes as $type => $message){
$this->getAppController()->flash()->add($type, $message);
}
return $this->getAppController()->redirect($this->getRequest()->getRequestUri());
} | [
"public",
"function",
"redirect",
"(",
"array",
"$",
"flashes",
"=",
"array",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"flashes",
"as",
"$",
"type",
"=>",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"getAppController",
"(",
")",
"->",
"flash",
"(",
")",
"->",
"add",
"(",
"$",
"type",
",",
"$",
"message",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getAppController",
"(",
")",
"->",
"redirect",
"(",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"getRequestUri",
"(",
")",
")",
";",
"}"
] | redirects to the same same uri.
@param array $flashes
@return \Symfony\Component\HttpFoundation\RedirectResponse | [
"redirects",
"to",
"the",
"same",
"same",
"uri",
"."
] | 08d94ffdd9cc58fff1b0cae6982cc51b6e4ece5a | https://github.com/Raphhh/puppy-static-route/blob/08d94ffdd9cc58fff1b0cae6982cc51b6e4ece5a/src/StaticController.php#L66-L72 | train |
rutger-speksnijder/restphp | src/RestPHP/BaseAPI.php | BaseAPI.setStatusCode | public function setStatusCode($statusCode)
{
$statusCode = (int)$statusCode;
if ($statusCode < 100 || $statusCode >= 600) {
throw new \Exception("Invalid status code: {$statusCode}.");
}
$this->statusCode = $statusCode;
return $this;
} | php | public function setStatusCode($statusCode)
{
$statusCode = (int)$statusCode;
if ($statusCode < 100 || $statusCode >= 600) {
throw new \Exception("Invalid status code: {$statusCode}.");
}
$this->statusCode = $statusCode;
return $this;
} | [
"public",
"function",
"setStatusCode",
"(",
"$",
"statusCode",
")",
"{",
"$",
"statusCode",
"=",
"(",
"int",
")",
"$",
"statusCode",
";",
"if",
"(",
"$",
"statusCode",
"<",
"100",
"||",
"$",
"statusCode",
">=",
"600",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Invalid status code: {$statusCode}.\"",
")",
";",
"}",
"$",
"this",
"->",
"statusCode",
"=",
"$",
"statusCode",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the status code.
@param int $statusCode The status code.
@throws Exception Throws an exception when an invalid status code is used.
@return $this The current object. | [
"Sets",
"the",
"status",
"code",
"."
] | 326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d | https://github.com/rutger-speksnijder/restphp/blob/326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d/src/RestPHP/BaseAPI.php#L318-L326 | train |
rutger-speksnijder/restphp | src/RestPHP/BaseAPI.php | BaseAPI.getStatusMessage | protected function getStatusMessage($code)
{
return (
isset($this->statusMessages[$code])
? $this->statusMessages[$code] : $this->statusMessages[500]
);
} | php | protected function getStatusMessage($code)
{
return (
isset($this->statusMessages[$code])
? $this->statusMessages[$code] : $this->statusMessages[500]
);
} | [
"protected",
"function",
"getStatusMessage",
"(",
"$",
"code",
")",
"{",
"return",
"(",
"isset",
"(",
"$",
"this",
"->",
"statusMessages",
"[",
"$",
"code",
"]",
")",
"?",
"$",
"this",
"->",
"statusMessages",
"[",
"$",
"code",
"]",
":",
"$",
"this",
"->",
"statusMessages",
"[",
"500",
"]",
")",
";",
"}"
] | Gets the HTTP status message for a status code.
@param int $code The status code.
@return string The http status. | [
"Gets",
"the",
"HTTP",
"status",
"message",
"for",
"a",
"status",
"code",
"."
] | 326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d | https://github.com/rutger-speksnijder/restphp/blob/326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d/src/RestPHP/BaseAPI.php#L345-L351 | train |
rutger-speksnijder/restphp | src/RestPHP/BaseAPI.php | BaseAPI.removeHypertextRoute | public function removeHypertextRoute($name)
{
if (isset($this->hypertextRoutes[$name])) {
unset($this->hypertextRoutes[$name]);
}
return $this;
} | php | public function removeHypertextRoute($name)
{
if (isset($this->hypertextRoutes[$name])) {
unset($this->hypertextRoutes[$name]);
}
return $this;
} | [
"public",
"function",
"removeHypertextRoute",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"hypertextRoutes",
"[",
"$",
"name",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"hypertextRoutes",
"[",
"$",
"name",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Removes a hypertext route by name.
@param string $name The hypertext route's name.
@return $this The current object. | [
"Removes",
"a",
"hypertext",
"route",
"by",
"name",
"."
] | 326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d | https://github.com/rutger-speksnijder/restphp/blob/326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d/src/RestPHP/BaseAPI.php#L403-L409 | train |
rutger-speksnijder/restphp | src/RestPHP/BaseAPI.php | BaseAPI.output | public function output($isFinal = false)
{
// Check if final output is true
if ($this->finalOutput) {
return;
}
$this->finalOutput = $isFinal;
// HTTP status header
header("HTTP/1.1 {$this->statusCode} {$this->getStatusMessage($this->statusCode)}");
// Disable caching
header("Cache-Control: no-cache, must-revalidate");
header("Expires: 0");
// Add the current uri to the hypertext routes
$this->hypertextRoutes['self'] = $this->uri;
// Create the response object, output the headers and print the response
$response = (new \RestPHP\Response\ResponseFactory())->build(
$this->responseType,
$this->response,
$this->hypertextRoutes
);
$response->outputHeaders();
echo $response;
// Return the current object
return $this;
} | php | public function output($isFinal = false)
{
// Check if final output is true
if ($this->finalOutput) {
return;
}
$this->finalOutput = $isFinal;
// HTTP status header
header("HTTP/1.1 {$this->statusCode} {$this->getStatusMessage($this->statusCode)}");
// Disable caching
header("Cache-Control: no-cache, must-revalidate");
header("Expires: 0");
// Add the current uri to the hypertext routes
$this->hypertextRoutes['self'] = $this->uri;
// Create the response object, output the headers and print the response
$response = (new \RestPHP\Response\ResponseFactory())->build(
$this->responseType,
$this->response,
$this->hypertextRoutes
);
$response->outputHeaders();
echo $response;
// Return the current object
return $this;
} | [
"public",
"function",
"output",
"(",
"$",
"isFinal",
"=",
"false",
")",
"{",
"// Check if final output is true",
"if",
"(",
"$",
"this",
"->",
"finalOutput",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"finalOutput",
"=",
"$",
"isFinal",
";",
"// HTTP status header",
"header",
"(",
"\"HTTP/1.1 {$this->statusCode} {$this->getStatusMessage($this->statusCode)}\"",
")",
";",
"// Disable caching",
"header",
"(",
"\"Cache-Control: no-cache, must-revalidate\"",
")",
";",
"header",
"(",
"\"Expires: 0\"",
")",
";",
"// Add the current uri to the hypertext routes",
"$",
"this",
"->",
"hypertextRoutes",
"[",
"'self'",
"]",
"=",
"$",
"this",
"->",
"uri",
";",
"// Create the response object, output the headers and print the response",
"$",
"response",
"=",
"(",
"new",
"\\",
"RestPHP",
"\\",
"Response",
"\\",
"ResponseFactory",
"(",
")",
")",
"->",
"build",
"(",
"$",
"this",
"->",
"responseType",
",",
"$",
"this",
"->",
"response",
",",
"$",
"this",
"->",
"hypertextRoutes",
")",
";",
"$",
"response",
"->",
"outputHeaders",
"(",
")",
";",
"echo",
"$",
"response",
";",
"// Return the current object",
"return",
"$",
"this",
";",
"}"
] | Outputs the current response in the correct response type
and sets the headers.
@param optional boolean $isFinal Whether this output is final or not.
@return $this The current object. | [
"Outputs",
"the",
"current",
"response",
"in",
"the",
"correct",
"response",
"type",
"and",
"sets",
"the",
"headers",
"."
] | 326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d | https://github.com/rutger-speksnijder/restphp/blob/326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d/src/RestPHP/BaseAPI.php#L470-L499 | train |
rutger-speksnijder/restphp | src/RestPHP/BaseAPI.php | BaseAPI.process | public function process()
{
// Check if we should verify the request
if ($this->configuration->getUseAuthorization()) {
if (
$this->uri != '/token' &&
$this->uri != '/authorize' &&
!$this->tokenServer->verifyResourceRequest(\OAuth2\Request::createFromGlobals())
) {
// Get the data as json and convert it to an array,
// - so we can set our own response type.
$data = $this->tokenServer->getResponse()->getResponseBody('json');
$data = json_decode($data, true);
// Set the response, status code and output content setting final output to true
$this->response = $data;
$this->statusCode = $this->tokenServer->getResponse()->getStatusCode();
$this->output(true);
return $this;
}
}
try {
// Handle OPTIONS requests
if ($this->method == 'options') {
$this->handleOptionsRequest();
} else {
// Execute the router
$this->router->execute();
}
} catch (\Exception $e) {
// Set the response and status code to error
$this->response = ['error' => 1, 'message' => $e->getMessage()];
$this->statusCode = 500;
}
// Output the response
$this->output();
} | php | public function process()
{
// Check if we should verify the request
if ($this->configuration->getUseAuthorization()) {
if (
$this->uri != '/token' &&
$this->uri != '/authorize' &&
!$this->tokenServer->verifyResourceRequest(\OAuth2\Request::createFromGlobals())
) {
// Get the data as json and convert it to an array,
// - so we can set our own response type.
$data = $this->tokenServer->getResponse()->getResponseBody('json');
$data = json_decode($data, true);
// Set the response, status code and output content setting final output to true
$this->response = $data;
$this->statusCode = $this->tokenServer->getResponse()->getStatusCode();
$this->output(true);
return $this;
}
}
try {
// Handle OPTIONS requests
if ($this->method == 'options') {
$this->handleOptionsRequest();
} else {
// Execute the router
$this->router->execute();
}
} catch (\Exception $e) {
// Set the response and status code to error
$this->response = ['error' => 1, 'message' => $e->getMessage()];
$this->statusCode = 500;
}
// Output the response
$this->output();
} | [
"public",
"function",
"process",
"(",
")",
"{",
"// Check if we should verify the request",
"if",
"(",
"$",
"this",
"->",
"configuration",
"->",
"getUseAuthorization",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"uri",
"!=",
"'/token'",
"&&",
"$",
"this",
"->",
"uri",
"!=",
"'/authorize'",
"&&",
"!",
"$",
"this",
"->",
"tokenServer",
"->",
"verifyResourceRequest",
"(",
"\\",
"OAuth2",
"\\",
"Request",
"::",
"createFromGlobals",
"(",
")",
")",
")",
"{",
"// Get the data as json and convert it to an array,",
"// - so we can set our own response type.",
"$",
"data",
"=",
"$",
"this",
"->",
"tokenServer",
"->",
"getResponse",
"(",
")",
"->",
"getResponseBody",
"(",
"'json'",
")",
";",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"data",
",",
"true",
")",
";",
"// Set the response, status code and output content setting final output to true",
"$",
"this",
"->",
"response",
"=",
"$",
"data",
";",
"$",
"this",
"->",
"statusCode",
"=",
"$",
"this",
"->",
"tokenServer",
"->",
"getResponse",
"(",
")",
"->",
"getStatusCode",
"(",
")",
";",
"$",
"this",
"->",
"output",
"(",
"true",
")",
";",
"return",
"$",
"this",
";",
"}",
"}",
"try",
"{",
"// Handle OPTIONS requests",
"if",
"(",
"$",
"this",
"->",
"method",
"==",
"'options'",
")",
"{",
"$",
"this",
"->",
"handleOptionsRequest",
"(",
")",
";",
"}",
"else",
"{",
"// Execute the router",
"$",
"this",
"->",
"router",
"->",
"execute",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// Set the response and status code to error",
"$",
"this",
"->",
"response",
"=",
"[",
"'error'",
"=>",
"1",
",",
"'message'",
"=>",
"$",
"e",
"->",
"getMessage",
"(",
")",
"]",
";",
"$",
"this",
"->",
"statusCode",
"=",
"500",
";",
"}",
"// Output the response",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Processes the API by calling the execute method on the router.
@return $this The current object. | [
"Processes",
"the",
"API",
"by",
"calling",
"the",
"execute",
"method",
"on",
"the",
"router",
"."
] | 326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d | https://github.com/rutger-speksnijder/restphp/blob/326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d/src/RestPHP/BaseAPI.php#L506-L544 | train |
rutger-speksnijder/restphp | src/RestPHP/BaseAPI.php | BaseAPI.handleOptionsRequest | public function handleOptionsRequest()
{
// Generate the "Allow" header
$allow = '';
foreach ($this->router->getMethodsByRoute($this->uri) as $method) {
$allow .= strtoupper($method) . ',';
}
$allow = substr($allow, 0, strlen($allow) - 1);
header('Allow: ' . $allow);
$this->setResponse('');
} | php | public function handleOptionsRequest()
{
// Generate the "Allow" header
$allow = '';
foreach ($this->router->getMethodsByRoute($this->uri) as $method) {
$allow .= strtoupper($method) . ',';
}
$allow = substr($allow, 0, strlen($allow) - 1);
header('Allow: ' . $allow);
$this->setResponse('');
} | [
"public",
"function",
"handleOptionsRequest",
"(",
")",
"{",
"// Generate the \"Allow\" header",
"$",
"allow",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"router",
"->",
"getMethodsByRoute",
"(",
"$",
"this",
"->",
"uri",
")",
"as",
"$",
"method",
")",
"{",
"$",
"allow",
".=",
"strtoupper",
"(",
"$",
"method",
")",
".",
"','",
";",
"}",
"$",
"allow",
"=",
"substr",
"(",
"$",
"allow",
",",
"0",
",",
"strlen",
"(",
"$",
"allow",
")",
"-",
"1",
")",
";",
"header",
"(",
"'Allow: '",
".",
"$",
"allow",
")",
";",
"$",
"this",
"->",
"setResponse",
"(",
"''",
")",
";",
"}"
] | Handles an HTTP OPTIONS requests.
Returns available methods for the current route.
@return void. | [
"Handles",
"an",
"HTTP",
"OPTIONS",
"requests",
".",
"Returns",
"available",
"methods",
"for",
"the",
"current",
"route",
"."
] | 326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d | https://github.com/rutger-speksnijder/restphp/blob/326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d/src/RestPHP/BaseAPI.php#L552-L562 | train |
rutger-speksnijder/restphp | src/RestPHP/BaseAPI.php | BaseAPI.addRoutes | protected function addRoutes()
{
// Define a "not found" route
$this->router->add('/', [$this, 'unknownEndpoint']);
// Only add these routes if we're using authorization
if ($this->configuration->getUseAuthorization()) {
// Token route for requesting tokens
$this->router->add('/token', [$this, 'token']);
if ($this->configuration->getAuthorizationMode() >= 2) {
// Token route for authorizing a client
$this->router->add('/authorize', [$this, 'authorize']);
}
}
return $this;
} | php | protected function addRoutes()
{
// Define a "not found" route
$this->router->add('/', [$this, 'unknownEndpoint']);
// Only add these routes if we're using authorization
if ($this->configuration->getUseAuthorization()) {
// Token route for requesting tokens
$this->router->add('/token', [$this, 'token']);
if ($this->configuration->getAuthorizationMode() >= 2) {
// Token route for authorizing a client
$this->router->add('/authorize', [$this, 'authorize']);
}
}
return $this;
} | [
"protected",
"function",
"addRoutes",
"(",
")",
"{",
"// Define a \"not found\" route",
"$",
"this",
"->",
"router",
"->",
"add",
"(",
"'/'",
",",
"[",
"$",
"this",
",",
"'unknownEndpoint'",
"]",
")",
";",
"// Only add these routes if we're using authorization",
"if",
"(",
"$",
"this",
"->",
"configuration",
"->",
"getUseAuthorization",
"(",
")",
")",
"{",
"// Token route for requesting tokens",
"$",
"this",
"->",
"router",
"->",
"add",
"(",
"'/token'",
",",
"[",
"$",
"this",
",",
"'token'",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"configuration",
"->",
"getAuthorizationMode",
"(",
")",
">=",
"2",
")",
"{",
"// Token route for authorizing a client",
"$",
"this",
"->",
"router",
"->",
"add",
"(",
"'/authorize'",
",",
"[",
"$",
"this",
",",
"'authorize'",
"]",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Adds default routes for the API regarding tokens.
These routes can be overridden in the child API class.
@return $this The current object. | [
"Adds",
"default",
"routes",
"for",
"the",
"API",
"regarding",
"tokens",
".",
"These",
"routes",
"can",
"be",
"overridden",
"in",
"the",
"child",
"API",
"class",
"."
] | 326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d | https://github.com/rutger-speksnijder/restphp/blob/326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d/src/RestPHP/BaseAPI.php#L570-L587 | train |
rutger-speksnijder/restphp | src/RestPHP/BaseAPI.php | BaseAPI.createTokenServer | private function createTokenServer()
{
// Catch errors for pdo object creation and creating the server
try {
// Create the server
$storage = new \OAuth2\Storage\Pdo(
[
'dsn' => $this->configuration->getDsn(),
'username' => $this->configuration->getUsername(),
'password' => $this->configuration->getPassword(),
]
);
$server = new \OAuth2\Server($storage);
// Add grant types
if ($this->configuration->getAuthorizationMode() === 1) {
$server->addGrantType(new \OAuth2\GrantType\ClientCredentials($storage));
} elseif ($this->configuration->getAuthorizationMode() === 2) {
$server->addGrantType(new \OAuth2\GrantType\AuthorizationCode($storage));
} elseif ($this->configuration->getAuthorizationMode() === 3) {
$server->addGrantType(new \OAuth2\GrantType\ClientCredentials($storage));
$server->addGrantType(new \OAuth2\GrantType\AuthorizationCode($storage));
} else {
throw new \Exception("Unknown authorization mode: \"{$this->configuration->getAuthorizationMode()}\".");
}
} catch (\Exception $ex) {
throw $ex;
}
$this->tokenServer = $server;
return $this;
} | php | private function createTokenServer()
{
// Catch errors for pdo object creation and creating the server
try {
// Create the server
$storage = new \OAuth2\Storage\Pdo(
[
'dsn' => $this->configuration->getDsn(),
'username' => $this->configuration->getUsername(),
'password' => $this->configuration->getPassword(),
]
);
$server = new \OAuth2\Server($storage);
// Add grant types
if ($this->configuration->getAuthorizationMode() === 1) {
$server->addGrantType(new \OAuth2\GrantType\ClientCredentials($storage));
} elseif ($this->configuration->getAuthorizationMode() === 2) {
$server->addGrantType(new \OAuth2\GrantType\AuthorizationCode($storage));
} elseif ($this->configuration->getAuthorizationMode() === 3) {
$server->addGrantType(new \OAuth2\GrantType\ClientCredentials($storage));
$server->addGrantType(new \OAuth2\GrantType\AuthorizationCode($storage));
} else {
throw new \Exception("Unknown authorization mode: \"{$this->configuration->getAuthorizationMode()}\".");
}
} catch (\Exception $ex) {
throw $ex;
}
$this->tokenServer = $server;
return $this;
} | [
"private",
"function",
"createTokenServer",
"(",
")",
"{",
"// Catch errors for pdo object creation and creating the server",
"try",
"{",
"// Create the server",
"$",
"storage",
"=",
"new",
"\\",
"OAuth2",
"\\",
"Storage",
"\\",
"Pdo",
"(",
"[",
"'dsn'",
"=>",
"$",
"this",
"->",
"configuration",
"->",
"getDsn",
"(",
")",
",",
"'username'",
"=>",
"$",
"this",
"->",
"configuration",
"->",
"getUsername",
"(",
")",
",",
"'password'",
"=>",
"$",
"this",
"->",
"configuration",
"->",
"getPassword",
"(",
")",
",",
"]",
")",
";",
"$",
"server",
"=",
"new",
"\\",
"OAuth2",
"\\",
"Server",
"(",
"$",
"storage",
")",
";",
"// Add grant types",
"if",
"(",
"$",
"this",
"->",
"configuration",
"->",
"getAuthorizationMode",
"(",
")",
"===",
"1",
")",
"{",
"$",
"server",
"->",
"addGrantType",
"(",
"new",
"\\",
"OAuth2",
"\\",
"GrantType",
"\\",
"ClientCredentials",
"(",
"$",
"storage",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"configuration",
"->",
"getAuthorizationMode",
"(",
")",
"===",
"2",
")",
"{",
"$",
"server",
"->",
"addGrantType",
"(",
"new",
"\\",
"OAuth2",
"\\",
"GrantType",
"\\",
"AuthorizationCode",
"(",
"$",
"storage",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"configuration",
"->",
"getAuthorizationMode",
"(",
")",
"===",
"3",
")",
"{",
"$",
"server",
"->",
"addGrantType",
"(",
"new",
"\\",
"OAuth2",
"\\",
"GrantType",
"\\",
"ClientCredentials",
"(",
"$",
"storage",
")",
")",
";",
"$",
"server",
"->",
"addGrantType",
"(",
"new",
"\\",
"OAuth2",
"\\",
"GrantType",
"\\",
"AuthorizationCode",
"(",
"$",
"storage",
")",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Unknown authorization mode: \\\"{$this->configuration->getAuthorizationMode()}\\\".\"",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"throw",
"$",
"ex",
";",
"}",
"$",
"this",
"->",
"tokenServer",
"=",
"$",
"server",
";",
"return",
"$",
"this",
";",
"}"
] | Creates the new token server.
Sets the connection to the database and grant types.
@throws @see OAuth2 package.
@return self The current object. | [
"Creates",
"the",
"new",
"token",
"server",
".",
"Sets",
"the",
"connection",
"to",
"the",
"database",
"and",
"grant",
"types",
"."
] | 326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d | https://github.com/rutger-speksnijder/restphp/blob/326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d/src/RestPHP/BaseAPI.php#L610-L641 | train |
rutger-speksnijder/restphp | src/RestPHP/BaseAPI.php | BaseAPI.token | public function token()
{
// Handle the token request
$response = $this->tokenServer->handleTokenRequest(\OAuth2\Request::createFromGlobals());
// Get the data as json and convert it to an array,
// - so we can set our own response type.
$data = $response->getResponseBody('json');
$data = json_decode($data, true);
// Set the response, status code and output content setting final output to true
$this->response = $data;
$this->statusCode = $response->getStatusCode();
$this->output(true);
return $this;
} | php | public function token()
{
// Handle the token request
$response = $this->tokenServer->handleTokenRequest(\OAuth2\Request::createFromGlobals());
// Get the data as json and convert it to an array,
// - so we can set our own response type.
$data = $response->getResponseBody('json');
$data = json_decode($data, true);
// Set the response, status code and output content setting final output to true
$this->response = $data;
$this->statusCode = $response->getStatusCode();
$this->output(true);
return $this;
} | [
"public",
"function",
"token",
"(",
")",
"{",
"// Handle the token request",
"$",
"response",
"=",
"$",
"this",
"->",
"tokenServer",
"->",
"handleTokenRequest",
"(",
"\\",
"OAuth2",
"\\",
"Request",
"::",
"createFromGlobals",
"(",
")",
")",
";",
"// Get the data as json and convert it to an array,",
"// - so we can set our own response type.",
"$",
"data",
"=",
"$",
"response",
"->",
"getResponseBody",
"(",
"'json'",
")",
";",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"data",
",",
"true",
")",
";",
"// Set the response, status code and output content setting final output to true",
"$",
"this",
"->",
"response",
"=",
"$",
"data",
";",
"$",
"this",
"->",
"statusCode",
"=",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
";",
"$",
"this",
"->",
"output",
"(",
"true",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Handles generating tokens for clients.
@return $this The current object. | [
"Handles",
"generating",
"tokens",
"for",
"clients",
"."
] | 326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d | https://github.com/rutger-speksnijder/restphp/blob/326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d/src/RestPHP/BaseAPI.php#L648-L663 | train |
rutger-speksnijder/restphp | src/RestPHP/BaseAPI.php | BaseAPI.authorize | public function authorize()
{
// Create the request and response objects
$request = \OAuth2\Request::createFromGlobals();
$response = new \OAuth2\Response();
// Validate the authorize request
if (!$this->tokenServer->validateAuthorizeRequest($request, $response)) {
// Get the data as json and convert it to an array,
// - so we can set our own response type.
$data = $response->getResponseBody('json');
$data = json_decode($data, true);
// Set the response, status code and output content setting final output to true
$this->response = $data;
$this->statusCode = $response->getStatusCode();
$this->output(true);
return $this;
}
// Display an authorization form
if ($this->method != 'post' || !isset($this->data['authorized'])) {
// Get the authorization form
ob_start();
require $this->configuration->getAuthorizationForm();
$form = ob_get_clean();
$this->response = $form;
$this->statusCode = 200;
$this->responseType = 'text/html';
$this->output(true);
return $this;
}
// Print the authorization code if the user has authorized your client
$isAuthorized = ($this->data['authorized'] === 'yes');
$this->tokenServer->handleAuthorizeRequest($request, $response, $isAuthorized);
// Check if the request was successful
if ($response->getStatusCode() === 302) {
// Check if we should redirect according to our configuration
if ($this->configuration->getRedirectAuthorization() === true) {
// The response will contain a Location header we should navigate to
header('Location: ' . $response->getHttpHeader('Location'));
exit;
}
// Create a response with the authorization code
$code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=')+5, 40);
$this->response = ['status' => 1, 'authorization_code' => $code];
$this->statusCode = 200;
$this->output(true);
return $this;
}
// Get the data as json and convert it to an array,
// - so we can set our own response type.
$data = $response->getResponseBody('json');
$data = json_decode($data, true);
// Set the response, status code and output content setting final output to true
$this->response = $data;
$this->statusCode = $response->getStatusCode();
$this->output(true);
return $this;
} | php | public function authorize()
{
// Create the request and response objects
$request = \OAuth2\Request::createFromGlobals();
$response = new \OAuth2\Response();
// Validate the authorize request
if (!$this->tokenServer->validateAuthorizeRequest($request, $response)) {
// Get the data as json and convert it to an array,
// - so we can set our own response type.
$data = $response->getResponseBody('json');
$data = json_decode($data, true);
// Set the response, status code and output content setting final output to true
$this->response = $data;
$this->statusCode = $response->getStatusCode();
$this->output(true);
return $this;
}
// Display an authorization form
if ($this->method != 'post' || !isset($this->data['authorized'])) {
// Get the authorization form
ob_start();
require $this->configuration->getAuthorizationForm();
$form = ob_get_clean();
$this->response = $form;
$this->statusCode = 200;
$this->responseType = 'text/html';
$this->output(true);
return $this;
}
// Print the authorization code if the user has authorized your client
$isAuthorized = ($this->data['authorized'] === 'yes');
$this->tokenServer->handleAuthorizeRequest($request, $response, $isAuthorized);
// Check if the request was successful
if ($response->getStatusCode() === 302) {
// Check if we should redirect according to our configuration
if ($this->configuration->getRedirectAuthorization() === true) {
// The response will contain a Location header we should navigate to
header('Location: ' . $response->getHttpHeader('Location'));
exit;
}
// Create a response with the authorization code
$code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=')+5, 40);
$this->response = ['status' => 1, 'authorization_code' => $code];
$this->statusCode = 200;
$this->output(true);
return $this;
}
// Get the data as json and convert it to an array,
// - so we can set our own response type.
$data = $response->getResponseBody('json');
$data = json_decode($data, true);
// Set the response, status code and output content setting final output to true
$this->response = $data;
$this->statusCode = $response->getStatusCode();
$this->output(true);
return $this;
} | [
"public",
"function",
"authorize",
"(",
")",
"{",
"// Create the request and response objects",
"$",
"request",
"=",
"\\",
"OAuth2",
"\\",
"Request",
"::",
"createFromGlobals",
"(",
")",
";",
"$",
"response",
"=",
"new",
"\\",
"OAuth2",
"\\",
"Response",
"(",
")",
";",
"// Validate the authorize request",
"if",
"(",
"!",
"$",
"this",
"->",
"tokenServer",
"->",
"validateAuthorizeRequest",
"(",
"$",
"request",
",",
"$",
"response",
")",
")",
"{",
"// Get the data as json and convert it to an array,",
"// - so we can set our own response type.",
"$",
"data",
"=",
"$",
"response",
"->",
"getResponseBody",
"(",
"'json'",
")",
";",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"data",
",",
"true",
")",
";",
"// Set the response, status code and output content setting final output to true",
"$",
"this",
"->",
"response",
"=",
"$",
"data",
";",
"$",
"this",
"->",
"statusCode",
"=",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
";",
"$",
"this",
"->",
"output",
"(",
"true",
")",
";",
"return",
"$",
"this",
";",
"}",
"// Display an authorization form",
"if",
"(",
"$",
"this",
"->",
"method",
"!=",
"'post'",
"||",
"!",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"'authorized'",
"]",
")",
")",
"{",
"// Get the authorization form",
"ob_start",
"(",
")",
";",
"require",
"$",
"this",
"->",
"configuration",
"->",
"getAuthorizationForm",
"(",
")",
";",
"$",
"form",
"=",
"ob_get_clean",
"(",
")",
";",
"$",
"this",
"->",
"response",
"=",
"$",
"form",
";",
"$",
"this",
"->",
"statusCode",
"=",
"200",
";",
"$",
"this",
"->",
"responseType",
"=",
"'text/html'",
";",
"$",
"this",
"->",
"output",
"(",
"true",
")",
";",
"return",
"$",
"this",
";",
"}",
"// Print the authorization code if the user has authorized your client",
"$",
"isAuthorized",
"=",
"(",
"$",
"this",
"->",
"data",
"[",
"'authorized'",
"]",
"===",
"'yes'",
")",
";",
"$",
"this",
"->",
"tokenServer",
"->",
"handleAuthorizeRequest",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"isAuthorized",
")",
";",
"// Check if the request was successful",
"if",
"(",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
"===",
"302",
")",
"{",
"// Check if we should redirect according to our configuration",
"if",
"(",
"$",
"this",
"->",
"configuration",
"->",
"getRedirectAuthorization",
"(",
")",
"===",
"true",
")",
"{",
"// The response will contain a Location header we should navigate to",
"header",
"(",
"'Location: '",
".",
"$",
"response",
"->",
"getHttpHeader",
"(",
"'Location'",
")",
")",
";",
"exit",
";",
"}",
"// Create a response with the authorization code",
"$",
"code",
"=",
"substr",
"(",
"$",
"response",
"->",
"getHttpHeader",
"(",
"'Location'",
")",
",",
"strpos",
"(",
"$",
"response",
"->",
"getHttpHeader",
"(",
"'Location'",
")",
",",
"'code='",
")",
"+",
"5",
",",
"40",
")",
";",
"$",
"this",
"->",
"response",
"=",
"[",
"'status'",
"=>",
"1",
",",
"'authorization_code'",
"=>",
"$",
"code",
"]",
";",
"$",
"this",
"->",
"statusCode",
"=",
"200",
";",
"$",
"this",
"->",
"output",
"(",
"true",
")",
";",
"return",
"$",
"this",
";",
"}",
"// Get the data as json and convert it to an array,",
"// - so we can set our own response type.",
"$",
"data",
"=",
"$",
"response",
"->",
"getResponseBody",
"(",
"'json'",
")",
";",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"data",
",",
"true",
")",
";",
"// Set the response, status code and output content setting final output to true",
"$",
"this",
"->",
"response",
"=",
"$",
"data",
";",
"$",
"this",
"->",
"statusCode",
"=",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
";",
"$",
"this",
"->",
"output",
"(",
"true",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Handles authorizing clients to receive an OAuth2 access token.
@return $this The current object, unless the user gets redirected. | [
"Handles",
"authorizing",
"clients",
"to",
"receive",
"an",
"OAuth2",
"access",
"token",
"."
] | 326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d | https://github.com/rutger-speksnijder/restphp/blob/326a7c0d79b266bbdd8a27ff1c8021caf9d28a3d/src/RestPHP/BaseAPI.php#L670-L734 | train |
PenoaksDev/Milky-Framework | src/Milky/Account/Traits/ThrottlesLogins.php | ThrottlesLogins.secondsRemainingOnLockout | protected function secondsRemainingOnLockout( Request $request )
{
return UniversalBuilder::resolveClass( RateLimiter::class )->availableIn( $this->getThrottleKey( $request ) );
} | php | protected function secondsRemainingOnLockout( Request $request )
{
return UniversalBuilder::resolveClass( RateLimiter::class )->availableIn( $this->getThrottleKey( $request ) );
} | [
"protected",
"function",
"secondsRemainingOnLockout",
"(",
"Request",
"$",
"request",
")",
"{",
"return",
"UniversalBuilder",
"::",
"resolveClass",
"(",
"RateLimiter",
"::",
"class",
")",
"->",
"availableIn",
"(",
"$",
"this",
"->",
"getThrottleKey",
"(",
"$",
"request",
")",
")",
";",
"}"
] | Get the lockout seconds.
@param Request $request
@return int | [
"Get",
"the",
"lockout",
"seconds",
"."
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Account/Traits/ThrottlesLogins.php#L85-L88 | train |
ARCANESOFT/SEO | src/Helpers/TextReplacer.php | TextReplacer.getShortcodes | public function getShortcodes()
{
$shortcodes = array_map(function ($replacement) {
return "[{$replacement}]";
}, $this->replacements);
return collect(array_combine($shortcodes, $this->replacements));
} | php | public function getShortcodes()
{
$shortcodes = array_map(function ($replacement) {
return "[{$replacement}]";
}, $this->replacements);
return collect(array_combine($shortcodes, $this->replacements));
} | [
"public",
"function",
"getShortcodes",
"(",
")",
"{",
"$",
"shortcodes",
"=",
"array_map",
"(",
"function",
"(",
"$",
"replacement",
")",
"{",
"return",
"\"[{$replacement}]\"",
";",
"}",
",",
"$",
"this",
"->",
"replacements",
")",
";",
"return",
"collect",
"(",
"array_combine",
"(",
"$",
"shortcodes",
",",
"$",
"this",
"->",
"replacements",
")",
")",
";",
"}"
] | Get the replacements shortcodes.
@return \Illuminate\Support\Collection | [
"Get",
"the",
"replacements",
"shortcodes",
"."
] | ce6d6135d55e8b2fd43cf7923839b4791b7c7ad2 | https://github.com/ARCANESOFT/SEO/blob/ce6d6135d55e8b2fd43cf7923839b4791b7c7ad2/src/Helpers/TextReplacer.php#L45-L52 | train |
ARCANESOFT/SEO | src/Helpers/TextReplacer.php | TextReplacer.mergeReplacements | protected function mergeReplacements(array $replacements)
{
return $this->getShortcodes()
->transform(function ($key) use ($replacements) {
return Arr::get($replacements, $key);
})
->filter();
} | php | protected function mergeReplacements(array $replacements)
{
return $this->getShortcodes()
->transform(function ($key) use ($replacements) {
return Arr::get($replacements, $key);
})
->filter();
} | [
"protected",
"function",
"mergeReplacements",
"(",
"array",
"$",
"replacements",
")",
"{",
"return",
"$",
"this",
"->",
"getShortcodes",
"(",
")",
"->",
"transform",
"(",
"function",
"(",
"$",
"key",
")",
"use",
"(",
"$",
"replacements",
")",
"{",
"return",
"Arr",
"::",
"get",
"(",
"$",
"replacements",
",",
"$",
"key",
")",
";",
"}",
")",
"->",
"filter",
"(",
")",
";",
"}"
] | Merge replacements.
@param array $replacements
@return \Illuminate\Support\Collection | [
"Merge",
"replacements",
"."
] | ce6d6135d55e8b2fd43cf7923839b4791b7c7ad2 | https://github.com/ARCANESOFT/SEO/blob/ce6d6135d55e8b2fd43cf7923839b4791b7c7ad2/src/Helpers/TextReplacer.php#L71-L78 | train |
ARCANESOFT/SEO | src/Helpers/TextReplacer.php | TextReplacer.highlight | public function highlight($content, $replacement = '<code>[\1]</code>')
{
return preg_replace(
'/\[('.$this->getShortcodes()->values()->implode('|').')\]/',
$replacement,
$content
);
} | php | public function highlight($content, $replacement = '<code>[\1]</code>')
{
return preg_replace(
'/\[('.$this->getShortcodes()->values()->implode('|').')\]/',
$replacement,
$content
);
} | [
"public",
"function",
"highlight",
"(",
"$",
"content",
",",
"$",
"replacement",
"=",
"'<code>[\\1]</code>'",
")",
"{",
"return",
"preg_replace",
"(",
"'/\\[('",
".",
"$",
"this",
"->",
"getShortcodes",
"(",
")",
"->",
"values",
"(",
")",
"->",
"implode",
"(",
"'|'",
")",
".",
"')\\]/'",
",",
"$",
"replacement",
",",
"$",
"content",
")",
";",
"}"
] | Highlight the replacement.
@param string $content
@param string $replacement
@return string | [
"Highlight",
"the",
"replacement",
"."
] | ce6d6135d55e8b2fd43cf7923839b4791b7c7ad2 | https://github.com/ARCANESOFT/SEO/blob/ce6d6135d55e8b2fd43cf7923839b4791b7c7ad2/src/Helpers/TextReplacer.php#L118-L125 | train |
TitaPHP/framework | src/TitaPHP/Http/Application.php | Application.processResponseType | protected function processResponseType($response = null)
{
if ($response instanceof Response) {
$this->response = $response;
}
elseif (is_string($response) || is_numeric($response)) {
$this->response->setContent($response);
}
elseif (is_array($response)) {
$this->response = new JsonResponse($response);
}
else {
throw new \Exception("App cannot process this response type");
}
} | php | protected function processResponseType($response = null)
{
if ($response instanceof Response) {
$this->response = $response;
}
elseif (is_string($response) || is_numeric($response)) {
$this->response->setContent($response);
}
elseif (is_array($response)) {
$this->response = new JsonResponse($response);
}
else {
throw new \Exception("App cannot process this response type");
}
} | [
"protected",
"function",
"processResponseType",
"(",
"$",
"response",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"response",
"instanceof",
"Response",
")",
"{",
"$",
"this",
"->",
"response",
"=",
"$",
"response",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"response",
")",
"||",
"is_numeric",
"(",
"$",
"response",
")",
")",
"{",
"$",
"this",
"->",
"response",
"->",
"setContent",
"(",
"$",
"response",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"response",
")",
")",
"{",
"$",
"this",
"->",
"response",
"=",
"new",
"JsonResponse",
"(",
"$",
"response",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"App cannot process this response type\"",
")",
";",
"}",
"}"
] | Process the Response Type.
@param mixed $response
@return void
@throws \Exception | [
"Process",
"the",
"Response",
"Type",
"."
] | 72283a45733a49c1d9c1fc0eba22ff13a802295c | https://github.com/TitaPHP/framework/blob/72283a45733a49c1d9c1fc0eba22ff13a802295c/src/TitaPHP/Http/Application.php#L114-L128 | train |
TeaLabs/collections | src/Key.php | Key.offsetSet | public function offsetSet($offset, $segment)
{
if (is_null($offset)) {
$this->segments[] = (string) $segment;
} else {
$this->segments[$offset] = (string) $segment;
}
} | php | public function offsetSet($offset, $segment)
{
if (is_null($offset)) {
$this->segments[] = (string) $segment;
} else {
$this->segments[$offset] = (string) $segment;
}
} | [
"public",
"function",
"offsetSet",
"(",
"$",
"offset",
",",
"$",
"segment",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"offset",
")",
")",
"{",
"$",
"this",
"->",
"segments",
"[",
"]",
"=",
"(",
"string",
")",
"$",
"segment",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"segments",
"[",
"$",
"offset",
"]",
"=",
"(",
"string",
")",
"$",
"segment",
";",
"}",
"}"
] | Set the segment at a given offset.
@param mixed $offset
@param mixed $segment
@return void | [
"Set",
"the",
"segment",
"at",
"a",
"given",
"offset",
"."
] | 5d8885b2799791c0bcbff4e6cbacddb270b4288e | https://github.com/TeaLabs/collections/blob/5d8885b2799791c0bcbff4e6cbacddb270b4288e/src/Key.php#L191-L198 | train |
TeaLabs/collections | src/Key.php | Key.implode | public static function implode($segments, $separator = self::SEPARATOR)
{
return (string) Uzi::join($separator, $segments, true);
} | php | public static function implode($segments, $separator = self::SEPARATOR)
{
return (string) Uzi::join($separator, $segments, true);
} | [
"public",
"static",
"function",
"implode",
"(",
"$",
"segments",
",",
"$",
"separator",
"=",
"self",
"::",
"SEPARATOR",
")",
"{",
"return",
"(",
"string",
")",
"Uzi",
"::",
"join",
"(",
"$",
"separator",
",",
"$",
"segments",
",",
"true",
")",
";",
"}"
] | Join the segments of a key into a string
@param array $segments
@param string $separator
@return string | [
"Join",
"the",
"segments",
"of",
"a",
"key",
"into",
"a",
"string"
] | 5d8885b2799791c0bcbff4e6cbacddb270b4288e | https://github.com/TeaLabs/collections/blob/5d8885b2799791c0bcbff4e6cbacddb270b4288e/src/Key.php#L254-L257 | train |
railken/lem | src/Attributes/MorphToAttribute.php | MorphToAttribute.getRelationManager | public function getRelationManager(EntityContract $entity)
{
$key = $entity->{$this->getRelationKey()};
if (!isset($this->relations[$key])) {
return null;
}
$class = $this->relations[$key];
return new $class($this->getManager()->getAgent());
} | php | public function getRelationManager(EntityContract $entity)
{
$key = $entity->{$this->getRelationKey()};
if (!isset($this->relations[$key])) {
return null;
}
$class = $this->relations[$key];
return new $class($this->getManager()->getAgent());
} | [
"public",
"function",
"getRelationManager",
"(",
"EntityContract",
"$",
"entity",
")",
"{",
"$",
"key",
"=",
"$",
"entity",
"->",
"{",
"$",
"this",
"->",
"getRelationKey",
"(",
")",
"}",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"relations",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"class",
"=",
"$",
"this",
"->",
"relations",
"[",
"$",
"key",
"]",
";",
"return",
"new",
"$",
"class",
"(",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"getAgent",
"(",
")",
")",
";",
"}"
] | Retrieve relation manager.
@param EntityContract $entity
@return \Railken\Lem\Contracts\ManagerContract | [
"Retrieve",
"relation",
"manager",
"."
] | cff1efcd090a9504b2faf5594121885786dea67a | https://github.com/railken/lem/blob/cff1efcd090a9504b2faf5594121885786dea67a/src/Attributes/MorphToAttribute.php#L101-L112 | train |
SlaxWeb/Hooks | src/Container.php | Container.addHook | public function addHook(Hook $hook)
{
if (isset($this->hooks[$hook->name]) === false) {
$this->logger->debug(
"Adding definition for hook '{$hook->name}' for the first time."
);
$this->hooks[$hook->name] = [];
}
$this->hooks[$hook->name][] = $hook->definition;
} | php | public function addHook(Hook $hook)
{
if (isset($this->hooks[$hook->name]) === false) {
$this->logger->debug(
"Adding definition for hook '{$hook->name}' for the first time."
);
$this->hooks[$hook->name] = [];
}
$this->hooks[$hook->name][] = $hook->definition;
} | [
"public",
"function",
"addHook",
"(",
"Hook",
"$",
"hook",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"hooks",
"[",
"$",
"hook",
"->",
"name",
"]",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"\"Adding definition for hook '{$hook->name}' for the first time.\"",
")",
";",
"$",
"this",
"->",
"hooks",
"[",
"$",
"hook",
"->",
"name",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"hooks",
"[",
"$",
"hook",
"->",
"name",
"]",
"[",
"]",
"=",
"$",
"hook",
"->",
"definition",
";",
"}"
] | Add hook definition to container
@param \SlaxWeb\Hooks\Hook $hook Hook definition
@return void | [
"Add",
"hook",
"definition",
"to",
"container"
] | 678f4d5425c27e0dd2a61b68d59bfb2793955b91 | https://github.com/SlaxWeb/Hooks/blob/678f4d5425c27e0dd2a61b68d59bfb2793955b91/src/Container.php#L70-L80 | train |
SlaxWeb/Hooks | src/Container.php | Container.exec | public function exec(string $name)
{
if (isset($this->hooks[$name]) === false) {
$this->logger->debug(
"No hook definitions found for '{$name}'. Available hook "
. "definitions",
[array_keys($this->hooks)]
);
return null;
}
$return = [];
$params = array_merge($this->params, array_slice(func_get_args(), 1));
foreach ($this->hooks[$name] as $definition) {
if ($this->stop === true) {
$this->stop = false;
$this->logger->info(
"Hook execution was interrupted for hook '{$name}'"
);
break;
}
$this->logger->info("Calling definition for hook '{$name}'");
$this->logger->debug("Hook definition parameters", $params);
$retVal = $definition(...$params);
if ($retVal !== null) {
$return[] = $retVal;
}
}
return count($return) === 1 ? $return[0] : $return;
} | php | public function exec(string $name)
{
if (isset($this->hooks[$name]) === false) {
$this->logger->debug(
"No hook definitions found for '{$name}'. Available hook "
. "definitions",
[array_keys($this->hooks)]
);
return null;
}
$return = [];
$params = array_merge($this->params, array_slice(func_get_args(), 1));
foreach ($this->hooks[$name] as $definition) {
if ($this->stop === true) {
$this->stop = false;
$this->logger->info(
"Hook execution was interrupted for hook '{$name}'"
);
break;
}
$this->logger->info("Calling definition for hook '{$name}'");
$this->logger->debug("Hook definition parameters", $params);
$retVal = $definition(...$params);
if ($retVal !== null) {
$return[] = $retVal;
}
}
return count($return) === 1 ? $return[0] : $return;
} | [
"public",
"function",
"exec",
"(",
"string",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"hooks",
"[",
"$",
"name",
"]",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"\"No hook definitions found for '{$name}'. Available hook \"",
".",
"\"definitions\"",
",",
"[",
"array_keys",
"(",
"$",
"this",
"->",
"hooks",
")",
"]",
")",
";",
"return",
"null",
";",
"}",
"$",
"return",
"=",
"[",
"]",
";",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"params",
",",
"array_slice",
"(",
"func_get_args",
"(",
")",
",",
"1",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"hooks",
"[",
"$",
"name",
"]",
"as",
"$",
"definition",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"stop",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"stop",
"=",
"false",
";",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"\"Hook execution was interrupted for hook '{$name}'\"",
")",
";",
"break",
";",
"}",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"\"Calling definition for hook '{$name}'\"",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"\"Hook definition parameters\"",
",",
"$",
"params",
")",
";",
"$",
"retVal",
"=",
"$",
"definition",
"(",
"...",
"$",
"params",
")",
";",
"if",
"(",
"$",
"retVal",
"!==",
"null",
")",
"{",
"$",
"return",
"[",
"]",
"=",
"$",
"retVal",
";",
"}",
"}",
"return",
"count",
"(",
"$",
"return",
")",
"===",
"1",
"?",
"$",
"return",
"[",
"0",
"]",
":",
"$",
"return",
";",
"}"
] | Execute hook definition
Execute all definitions for the retrieved hook names in the order that
they have been inserted, and store their return values in an array, if it
is not null. If only one definition was called, then return that
executions return value directly, if there were more calls, return all the
return values in an array.
@param string Hook name
@return mixed | [
"Execute",
"hook",
"definition"
] | 678f4d5425c27e0dd2a61b68d59bfb2793955b91 | https://github.com/SlaxWeb/Hooks/blob/678f4d5425c27e0dd2a61b68d59bfb2793955b91/src/Container.php#L94-L125 | train |
oyepez003/YepsuaRADBundle | Controller/Controller.php | Controller.createAndBindForm | public function createAndBindForm(Request $request, $type, $data = null, array $options = array())
{
$form = $this->createForm($type, $data, $options);
$form->submit($request);
return $form;
} | php | public function createAndBindForm(Request $request, $type, $data = null, array $options = array())
{
$form = $this->createForm($type, $data, $options);
$form->submit($request);
return $form;
} | [
"public",
"function",
"createAndBindForm",
"(",
"Request",
"$",
"request",
",",
"$",
"type",
",",
"$",
"data",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"$",
"type",
",",
"$",
"data",
",",
"$",
"options",
")",
";",
"$",
"form",
"->",
"submit",
"(",
"$",
"request",
")",
";",
"return",
"$",
"form",
";",
"}"
] | Creates, binds and returns a Form instance from the type of the form.
@param string|FormTypeInterface $type The built type of the form
@param mixed $data The initial data for the form
@param array $options Options for the form
@return Form | [
"Creates",
"binds",
"and",
"returns",
"a",
"Form",
"instance",
"from",
"the",
"type",
"of",
"the",
"form",
"."
] | 5e8c79f49201d5b2ba9487f16624a3f245941672 | https://github.com/oyepez003/YepsuaRADBundle/blob/5e8c79f49201d5b2ba9487f16624a3f245941672/Controller/Controller.php#L295-L300 | train |
hiqdev/minii-widgets | src/DetailView.php | DetailView.renderAttribute | protected function renderAttribute($attribute, $index)
{
if (is_string($this->template)) {
return strtr($this->template, [
'{label}' => $attribute['label'],
'{value}' => $this->formatter->format($attribute['value'], $attribute['format']),
]);
} else {
return call_user_func($this->template, $attribute, $index, $this);
}
} | php | protected function renderAttribute($attribute, $index)
{
if (is_string($this->template)) {
return strtr($this->template, [
'{label}' => $attribute['label'],
'{value}' => $this->formatter->format($attribute['value'], $attribute['format']),
]);
} else {
return call_user_func($this->template, $attribute, $index, $this);
}
} | [
"protected",
"function",
"renderAttribute",
"(",
"$",
"attribute",
",",
"$",
"index",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"template",
")",
")",
"{",
"return",
"strtr",
"(",
"$",
"this",
"->",
"template",
",",
"[",
"'{label}'",
"=>",
"$",
"attribute",
"[",
"'label'",
"]",
",",
"'{value}'",
"=>",
"$",
"this",
"->",
"formatter",
"->",
"format",
"(",
"$",
"attribute",
"[",
"'value'",
"]",
",",
"$",
"attribute",
"[",
"'format'",
"]",
")",
",",
"]",
")",
";",
"}",
"else",
"{",
"return",
"call_user_func",
"(",
"$",
"this",
"->",
"template",
",",
"$",
"attribute",
",",
"$",
"index",
",",
"$",
"this",
")",
";",
"}",
"}"
] | Renders a single attribute.
@param array $attribute the specification of the attribute to be rendered.
@param integer $index the zero-based index of the attribute in the [[attributes]] array
@return string the rendering result | [
"Renders",
"a",
"single",
"attribute",
"."
] | b8bc54a3645e9e45c228e3ec81b11ff4775385c3 | https://github.com/hiqdev/minii-widgets/blob/b8bc54a3645e9e45c228e3ec81b11ff4775385c3/src/DetailView.php#L154-L164 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.