repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
oophp/mailparse | src/Mailparse.php | Mailparse.setStream | public function setStream($stream, bool $closeStream = false)
{
$meta = @stream_get_meta_data($stream);
if (!$meta || !$meta['mode'] || $meta['mode'][0] != 'r' || $meta['eof']) {
throw new NonReadableStreamException();
}
$text = '';
while (!feof($stream)) {
$text .= fread($stream, 2082);
}
if ($closeStream) {
fclose($stream);
}
return $this->setText($text);
} | php | public function setStream($stream, bool $closeStream = false)
{
$meta = @stream_get_meta_data($stream);
if (!$meta || !$meta['mode'] || $meta['mode'][0] != 'r' || $meta['eof']) {
throw new NonReadableStreamException();
}
$text = '';
while (!feof($stream)) {
$text .= fread($stream, 2082);
}
if ($closeStream) {
fclose($stream);
}
return $this->setText($text);
} | [
"public",
"function",
"setStream",
"(",
"$",
"stream",
",",
"bool",
"$",
"closeStream",
"=",
"false",
")",
"{",
"$",
"meta",
"=",
"@",
"stream_get_meta_data",
"(",
"$",
"stream",
")",
";",
"if",
"(",
"!",
"$",
"meta",
"||",
"!",
"$",
"meta",
"[",
"'mode'",
"]",
"||",
"$",
"meta",
"[",
"'mode'",
"]",
"[",
"0",
"]",
"!=",
"'r'",
"||",
"$",
"meta",
"[",
"'eof'",
"]",
")",
"{",
"throw",
"new",
"NonReadableStreamException",
"(",
")",
";",
"}",
"$",
"text",
"=",
"''",
";",
"while",
"(",
"!",
"feof",
"(",
"$",
"stream",
")",
")",
"{",
"$",
"text",
".=",
"fread",
"(",
"$",
"stream",
",",
"2082",
")",
";",
"}",
"if",
"(",
"$",
"closeStream",
")",
"{",
"fclose",
"(",
"$",
"stream",
")",
";",
"}",
"return",
"$",
"this",
"->",
"setText",
"(",
"$",
"text",
")",
";",
"}"
] | @param resource $stream
@return $this
@throws NonReadableStreamException | [
"@param",
"resource",
"$stream"
] | train | https://github.com/oophp/mailparse/blob/829b3ca301449ac8972da6a574584527e14dbcbd/src/Mailparse.php#L52-L69 |
oophp/mailparse | src/Mailparse.php | Mailparse.setText | public function setText(string $text)
{
$this->resource = mailparse_msg_create();
$eaten = 0;
$text_length = strlen($text);
while ($eaten < $text_length) {
mailparse_msg_parse($this->resource, substr($text, $eaten, 2082));
$eaten += 2082;
}
$this->text = $text;
return $this;
} | php | public function setText(string $text)
{
$this->resource = mailparse_msg_create();
$eaten = 0;
$text_length = strlen($text);
while ($eaten < $text_length) {
mailparse_msg_parse($this->resource, substr($text, $eaten, 2082));
$eaten += 2082;
}
$this->text = $text;
return $this;
} | [
"public",
"function",
"setText",
"(",
"string",
"$",
"text",
")",
"{",
"$",
"this",
"->",
"resource",
"=",
"mailparse_msg_create",
"(",
")",
";",
"$",
"eaten",
"=",
"0",
";",
"$",
"text_length",
"=",
"strlen",
"(",
"$",
"text",
")",
";",
"while",
"(",
"$",
"eaten",
"<",
"$",
"text_length",
")",
"{",
"mailparse_msg_parse",
"(",
"$",
"this",
"->",
"resource",
",",
"substr",
"(",
"$",
"text",
",",
"$",
"eaten",
",",
"2082",
")",
")",
";",
"$",
"eaten",
"+=",
"2082",
";",
"}",
"$",
"this",
"->",
"text",
"=",
"$",
"text",
";",
"return",
"$",
"this",
";",
"}"
] | @param string $text
@return $this | [
"@param",
"string",
"$text"
] | train | https://github.com/oophp/mailparse/blob/829b3ca301449ac8972da6a574584527e14dbcbd/src/Mailparse.php#L76-L89 |
oophp/mailparse | src/Mailparse.php | Mailparse.getPartData | public function getPartData($part = null)
{
if ($part === null) {
$part = $this->resource;
}
return mailparse_msg_get_part_data($part);
} | php | public function getPartData($part = null)
{
if ($part === null) {
$part = $this->resource;
}
return mailparse_msg_get_part_data($part);
} | [
"public",
"function",
"getPartData",
"(",
"$",
"part",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"part",
"===",
"null",
")",
"{",
"$",
"part",
"=",
"$",
"this",
"->",
"resource",
";",
"}",
"return",
"mailparse_msg_get_part_data",
"(",
"$",
"part",
")",
";",
"}"
] | @param resource|null $part
@return array | [
"@param",
"resource|null",
"$part"
] | train | https://github.com/oophp/mailparse/blob/829b3ca301449ac8972da6a574584527e14dbcbd/src/Mailparse.php#L137-L144 |
oophp/mailparse | src/Mailparse.php | Mailparse.getPartObject | public function getPartObject(string $partId): Mailparse
{
$object = new static;
$object->text = &$this->text;
$object->resource = $this->getPart($partId);
return $object;
} | php | public function getPartObject(string $partId): Mailparse
{
$object = new static;
$object->text = &$this->text;
$object->resource = $this->getPart($partId);
return $object;
} | [
"public",
"function",
"getPartObject",
"(",
"string",
"$",
"partId",
")",
":",
"Mailparse",
"{",
"$",
"object",
"=",
"new",
"static",
";",
"$",
"object",
"->",
"text",
"=",
"&",
"$",
"this",
"->",
"text",
";",
"$",
"object",
"->",
"resource",
"=",
"$",
"this",
"->",
"getPart",
"(",
"$",
"partId",
")",
";",
"return",
"$",
"object",
";",
"}"
] | @param $partId
@return Mailparse | [
"@param",
"$partId"
] | train | https://github.com/oophp/mailparse/blob/829b3ca301449ac8972da6a574584527e14dbcbd/src/Mailparse.php#L151-L158 |
oophp/mailparse | src/Mailparse.php | Mailparse.getBody | public function getBody($part = null)
{
$data = $this->getPartData($part);
$start = $data['starting-pos-body'];
$end = $data['ending-pos-body'];
return substr($this->text, $start, $end - $start);
} | php | public function getBody($part = null)
{
$data = $this->getPartData($part);
$start = $data['starting-pos-body'];
$end = $data['ending-pos-body'];
return substr($this->text, $start, $end - $start);
} | [
"public",
"function",
"getBody",
"(",
"$",
"part",
"=",
"null",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getPartData",
"(",
"$",
"part",
")",
";",
"$",
"start",
"=",
"$",
"data",
"[",
"'starting-pos-body'",
"]",
";",
"$",
"end",
"=",
"$",
"data",
"[",
"'ending-pos-body'",
"]",
";",
"return",
"substr",
"(",
"$",
"this",
"->",
"text",
",",
"$",
"start",
",",
"$",
"end",
"-",
"$",
"start",
")",
";",
"}"
] | @param resource|null $part
@return string | [
"@param",
"resource|null",
"$part"
] | train | https://github.com/oophp/mailparse/blob/829b3ca301449ac8972da6a574584527e14dbcbd/src/Mailparse.php#L183-L190 |
zhouyl/mellivora | Mellivora/Pagination/AbstractPaginator.php | AbstractPaginator.url | public function url($page)
{
if ($page <= 0) {
$page = 1;
}
// If we have any extra query string key / value pairs that need to be added
// onto the URL, we will put them in query string form and then attach it
// to the URL. This allows for extra information like sortings storage.
$parameters = [$this->pageName => $page];
if (count($this->query) > 0) {
$parameters = array_merge($this->query, $parameters);
}
$uri = Uri::createFromString($this->path);
parse_str($uri->getQuery(), $queryParts);
return $uri->withQuery(http_build_query($parameters + $queryParts))
->withFragment($this->buildFragment())
->__toString();
} | php | public function url($page)
{
if ($page <= 0) {
$page = 1;
}
// If we have any extra query string key / value pairs that need to be added
// onto the URL, we will put them in query string form and then attach it
// to the URL. This allows for extra information like sortings storage.
$parameters = [$this->pageName => $page];
if (count($this->query) > 0) {
$parameters = array_merge($this->query, $parameters);
}
$uri = Uri::createFromString($this->path);
parse_str($uri->getQuery(), $queryParts);
return $uri->withQuery(http_build_query($parameters + $queryParts))
->withFragment($this->buildFragment())
->__toString();
} | [
"public",
"function",
"url",
"(",
"$",
"page",
")",
"{",
"if",
"(",
"$",
"page",
"<=",
"0",
")",
"{",
"$",
"page",
"=",
"1",
";",
"}",
"// If we have any extra query string key / value pairs that need to be added",
"// onto the URL, we will put them in query string form and then attach it",
"// to the URL. This allows for extra information like sortings storage.",
"$",
"parameters",
"=",
"[",
"$",
"this",
"->",
"pageName",
"=>",
"$",
"page",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"query",
")",
">",
"0",
")",
"{",
"$",
"parameters",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"query",
",",
"$",
"parameters",
")",
";",
"}",
"$",
"uri",
"=",
"Uri",
"::",
"createFromString",
"(",
"$",
"this",
"->",
"path",
")",
";",
"parse_str",
"(",
"$",
"uri",
"->",
"getQuery",
"(",
")",
",",
"$",
"queryParts",
")",
";",
"return",
"$",
"uri",
"->",
"withQuery",
"(",
"http_build_query",
"(",
"$",
"parameters",
"+",
"$",
"queryParts",
")",
")",
"->",
"withFragment",
"(",
"$",
"this",
"->",
"buildFragment",
"(",
")",
")",
"->",
"__toString",
"(",
")",
";",
"}"
] | Get the URL for a given page number.
@param int $page
@return string | [
"Get",
"the",
"URL",
"for",
"a",
"given",
"page",
"number",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Pagination/AbstractPaginator.php#L143-L165 |
gpupo/common-schema | src/ORM/Entity/Application/API/OAuth/Provider.php | Provider.addClient | public function addClient(\Gpupo\CommonSchema\ORM\Entity\Application\API\OAuth\Client\Client $client)
{
$this->clients[] = $client;
return $this;
} | php | public function addClient(\Gpupo\CommonSchema\ORM\Entity\Application\API\OAuth\Client\Client $client)
{
$this->clients[] = $client;
return $this;
} | [
"public",
"function",
"addClient",
"(",
"\\",
"Gpupo",
"\\",
"CommonSchema",
"\\",
"ORM",
"\\",
"Entity",
"\\",
"Application",
"\\",
"API",
"\\",
"OAuth",
"\\",
"Client",
"\\",
"Client",
"$",
"client",
")",
"{",
"$",
"this",
"->",
"clients",
"[",
"]",
"=",
"$",
"client",
";",
"return",
"$",
"this",
";",
"}"
] | Add client.
@param \Gpupo\CommonSchema\ORM\Entity\Application\API\OAuth\Client\Client $client
@return Provider | [
"Add",
"client",
"."
] | train | https://github.com/gpupo/common-schema/blob/a762d2eb3063b7317c72c69cbb463b1f95b86b0a/src/ORM/Entity/Application/API/OAuth/Provider.php#L279-L284 |
gpupo/common-schema | src/ORM/Entity/Application/API/OAuth/Provider.php | Provider.removeClient | public function removeClient(\Gpupo\CommonSchema\ORM\Entity\Application\API\OAuth\Client\Client $client)
{
return $this->clients->removeElement($client);
} | php | public function removeClient(\Gpupo\CommonSchema\ORM\Entity\Application\API\OAuth\Client\Client $client)
{
return $this->clients->removeElement($client);
} | [
"public",
"function",
"removeClient",
"(",
"\\",
"Gpupo",
"\\",
"CommonSchema",
"\\",
"ORM",
"\\",
"Entity",
"\\",
"Application",
"\\",
"API",
"\\",
"OAuth",
"\\",
"Client",
"\\",
"Client",
"$",
"client",
")",
"{",
"return",
"$",
"this",
"->",
"clients",
"->",
"removeElement",
"(",
"$",
"client",
")",
";",
"}"
] | Remove client.
@param \Gpupo\CommonSchema\ORM\Entity\Application\API\OAuth\Client\Client $client
@return bool TRUE if this collection contained the specified element, FALSE otherwise | [
"Remove",
"client",
"."
] | train | https://github.com/gpupo/common-schema/blob/a762d2eb3063b7317c72c69cbb463b1f95b86b0a/src/ORM/Entity/Application/API/OAuth/Provider.php#L293-L296 |
bytic/framework | src/Paginator.php | Paginator.getLimits | public function getLimits()
{
$totalPages = $this->getTotalPages();
$this->currentPage = ($this->currentPage > $totalPages) ? $totalPages : $this->currentPage;
$dLimit = ($this->currentPage - 1) * $this->itemsPerPage;
return array($dLimit, $this->itemsPerPage);
} | php | public function getLimits()
{
$totalPages = $this->getTotalPages();
$this->currentPage = ($this->currentPage > $totalPages) ? $totalPages : $this->currentPage;
$dLimit = ($this->currentPage - 1) * $this->itemsPerPage;
return array($dLimit, $this->itemsPerPage);
} | [
"public",
"function",
"getLimits",
"(",
")",
"{",
"$",
"totalPages",
"=",
"$",
"this",
"->",
"getTotalPages",
"(",
")",
";",
"$",
"this",
"->",
"currentPage",
"=",
"(",
"$",
"this",
"->",
"currentPage",
">",
"$",
"totalPages",
")",
"?",
"$",
"totalPages",
":",
"$",
"this",
"->",
"currentPage",
";",
"$",
"dLimit",
"=",
"(",
"$",
"this",
"->",
"currentPage",
"-",
"1",
")",
"*",
"$",
"this",
"->",
"itemsPerPage",
";",
"return",
"array",
"(",
"$",
"dLimit",
",",
"$",
"this",
"->",
"itemsPerPage",
")",
";",
"}"
] | Returns the offset ant length for limiting results to current page
@return array | [
"Returns",
"the",
"offset",
"ant",
"length",
"for",
"limiting",
"results",
"to",
"current",
"page"
] | train | https://github.com/bytic/framework/blob/36b4a761f4b64899f3841b0f6c8eb92887e91677/src/Paginator.php#L17-L26 |
Eresus/EresusCMS | src/core/Admin/FrontController.php | Eresus_Admin_FrontController.dispatch | public function dispatch()
{
Eresus_Kernel::app()->getEventDispatcher()->dispatch('cms.admin.start');
if (!UserRights(EDITOR))
{
$response = $this->authAction();
}
else
{
/** @var TAdminUI|TClientUI $page */
$page = $this->getPage();
$response = $page->render($this->getRequest());
}
return $response;
} | php | public function dispatch()
{
Eresus_Kernel::app()->getEventDispatcher()->dispatch('cms.admin.start');
if (!UserRights(EDITOR))
{
$response = $this->authAction();
}
else
{
/** @var TAdminUI|TClientUI $page */
$page = $this->getPage();
$response = $page->render($this->getRequest());
}
return $response;
} | [
"public",
"function",
"dispatch",
"(",
")",
"{",
"Eresus_Kernel",
"::",
"app",
"(",
")",
"->",
"getEventDispatcher",
"(",
")",
"->",
"dispatch",
"(",
"'cms.admin.start'",
")",
";",
"if",
"(",
"!",
"UserRights",
"(",
"EDITOR",
")",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"authAction",
"(",
")",
";",
"}",
"else",
"{",
"/** @var TAdminUI|TClientUI $page */",
"$",
"page",
"=",
"$",
"this",
"->",
"getPage",
"(",
")",
";",
"$",
"response",
"=",
"$",
"page",
"->",
"render",
"(",
"$",
"this",
"->",
"getRequest",
"(",
")",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Выполняет действия контроллера и возвращает ответ
@return Eresus_HTTP_Response
@since 3.01 | [
"Выполняет",
"действия",
"контроллера",
"и",
"возвращает",
"ответ"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/Admin/FrontController.php#L43-L58 |
Eresus/EresusCMS | src/core/Admin/FrontController.php | Eresus_Admin_FrontController.authAction | private function authAction()
{
$data = array('errors' => array(), 'user' => '', 'autologin' => '');
$legacyKernel = Eresus_CMS::getLegacyKernel();
$req = $this->getRequest();
if ($req->getMethod() == 'POST')
{
$user = $req->request->filter('user', null, FILTER_REGEXP, '/[^a-z0-9_\-\.\@]/');
$password = $req->request->get('password');
$autologin = $req->request->get('autologin');
if ($legacyKernel->login($user, $legacyKernel->password_hash($password), $autologin))
{
return new Eresus_HTTP_Redirect($legacyKernel->root . 'admin.php');
}
$data['user'] = $user;
$data['autologin'] = $autologin;
}
$data['errors'] = $this->getPage()->getErrorMessages();
$this->getPage()->clearErrorMessages();
if (isset($legacyKernel->session['msg']['errors']) &&
count($legacyKernel->session['msg']['errors']))
{
$data['errors'] = $legacyKernel->session['msg']['errors'];
$legacyKernel->session['msg']['errors'] = array();
}
$tmpl = Eresus_Template::loadFromFile('core/templates/auth.html');
$html = $tmpl->compile($data);
$response = new Eresus_HTTP_Response($html);
return $response;
} | php | private function authAction()
{
$data = array('errors' => array(), 'user' => '', 'autologin' => '');
$legacyKernel = Eresus_CMS::getLegacyKernel();
$req = $this->getRequest();
if ($req->getMethod() == 'POST')
{
$user = $req->request->filter('user', null, FILTER_REGEXP, '/[^a-z0-9_\-\.\@]/');
$password = $req->request->get('password');
$autologin = $req->request->get('autologin');
if ($legacyKernel->login($user, $legacyKernel->password_hash($password), $autologin))
{
return new Eresus_HTTP_Redirect($legacyKernel->root . 'admin.php');
}
$data['user'] = $user;
$data['autologin'] = $autologin;
}
$data['errors'] = $this->getPage()->getErrorMessages();
$this->getPage()->clearErrorMessages();
if (isset($legacyKernel->session['msg']['errors']) &&
count($legacyKernel->session['msg']['errors']))
{
$data['errors'] = $legacyKernel->session['msg']['errors'];
$legacyKernel->session['msg']['errors'] = array();
}
$tmpl = Eresus_Template::loadFromFile('core/templates/auth.html');
$html = $tmpl->compile($data);
$response = new Eresus_HTTP_Response($html);
return $response;
} | [
"private",
"function",
"authAction",
"(",
")",
"{",
"$",
"data",
"=",
"array",
"(",
"'errors'",
"=>",
"array",
"(",
")",
",",
"'user'",
"=>",
"''",
",",
"'autologin'",
"=>",
"''",
")",
";",
"$",
"legacyKernel",
"=",
"Eresus_CMS",
"::",
"getLegacyKernel",
"(",
")",
";",
"$",
"req",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"if",
"(",
"$",
"req",
"->",
"getMethod",
"(",
")",
"==",
"'POST'",
")",
"{",
"$",
"user",
"=",
"$",
"req",
"->",
"request",
"->",
"filter",
"(",
"'user'",
",",
"null",
",",
"FILTER_REGEXP",
",",
"'/[^a-z0-9_\\-\\.\\@]/'",
")",
";",
"$",
"password",
"=",
"$",
"req",
"->",
"request",
"->",
"get",
"(",
"'password'",
")",
";",
"$",
"autologin",
"=",
"$",
"req",
"->",
"request",
"->",
"get",
"(",
"'autologin'",
")",
";",
"if",
"(",
"$",
"legacyKernel",
"->",
"login",
"(",
"$",
"user",
",",
"$",
"legacyKernel",
"->",
"password_hash",
"(",
"$",
"password",
")",
",",
"$",
"autologin",
")",
")",
"{",
"return",
"new",
"Eresus_HTTP_Redirect",
"(",
"$",
"legacyKernel",
"->",
"root",
".",
"'admin.php'",
")",
";",
"}",
"$",
"data",
"[",
"'user'",
"]",
"=",
"$",
"user",
";",
"$",
"data",
"[",
"'autologin'",
"]",
"=",
"$",
"autologin",
";",
"}",
"$",
"data",
"[",
"'errors'",
"]",
"=",
"$",
"this",
"->",
"getPage",
"(",
")",
"->",
"getErrorMessages",
"(",
")",
";",
"$",
"this",
"->",
"getPage",
"(",
")",
"->",
"clearErrorMessages",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"legacyKernel",
"->",
"session",
"[",
"'msg'",
"]",
"[",
"'errors'",
"]",
")",
"&&",
"count",
"(",
"$",
"legacyKernel",
"->",
"session",
"[",
"'msg'",
"]",
"[",
"'errors'",
"]",
")",
")",
"{",
"$",
"data",
"[",
"'errors'",
"]",
"=",
"$",
"legacyKernel",
"->",
"session",
"[",
"'msg'",
"]",
"[",
"'errors'",
"]",
";",
"$",
"legacyKernel",
"->",
"session",
"[",
"'msg'",
"]",
"[",
"'errors'",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"tmpl",
"=",
"Eresus_Template",
"::",
"loadFromFile",
"(",
"'core/templates/auth.html'",
")",
";",
"$",
"html",
"=",
"$",
"tmpl",
"->",
"compile",
"(",
"$",
"data",
")",
";",
"$",
"response",
"=",
"new",
"Eresus_HTTP_Response",
"(",
"$",
"html",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Отрисовка страницы аутентификации
@return Eresus_HTTP_Response
@since 3.01 | [
"Отрисовка",
"страницы",
"аутентификации"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/Admin/FrontController.php#L78-L110 |
colorium/web | src/Colorium/Web/Context.php | Context.url | public function url(...$parts)
{
$uri = implode('/', $parts);
return (string)$this->request->uri->make($uri);
} | php | public function url(...$parts)
{
$uri = implode('/', $parts);
return (string)$this->request->uri->make($uri);
} | [
"public",
"function",
"url",
"(",
"...",
"$",
"parts",
")",
"{",
"$",
"uri",
"=",
"implode",
"(",
"'/'",
",",
"$",
"parts",
")",
";",
"return",
"(",
"string",
")",
"$",
"this",
"->",
"request",
"->",
"uri",
"->",
"make",
"(",
"$",
"uri",
")",
";",
"}"
] | Uri helper
@param ...$parts
@return string | [
"Uri",
"helper"
] | train | https://github.com/colorium/web/blob/2a767658b8737022939b0cc4505b5f652c1683d2/src/Colorium/Web/Context.php#L63-L67 |
colorium/web | src/Colorium/Web/Context.php | Context.post | public function post(...$keys)
{
if(!$keys) {
return $this->request->values;
}
elseif(count($keys) === 1) {
return $this->request->value($keys[0]);
}
$values = [];
foreach($keys as $key) {
$values[] = $this->request->value($key);
}
return $values;
} | php | public function post(...$keys)
{
if(!$keys) {
return $this->request->values;
}
elseif(count($keys) === 1) {
return $this->request->value($keys[0]);
}
$values = [];
foreach($keys as $key) {
$values[] = $this->request->value($key);
}
return $values;
} | [
"public",
"function",
"post",
"(",
"...",
"$",
"keys",
")",
"{",
"if",
"(",
"!",
"$",
"keys",
")",
"{",
"return",
"$",
"this",
"->",
"request",
"->",
"values",
";",
"}",
"elseif",
"(",
"count",
"(",
"$",
"keys",
")",
"===",
"1",
")",
"{",
"return",
"$",
"this",
"->",
"request",
"->",
"value",
"(",
"$",
"keys",
"[",
"0",
"]",
")",
";",
"}",
"$",
"values",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"values",
"[",
"]",
"=",
"$",
"this",
"->",
"request",
"->",
"value",
"(",
"$",
"key",
")",
";",
"}",
"return",
"$",
"values",
";",
"}"
] | Get post value
@param array $keys
@return string | [
"Get",
"post",
"value"
] | train | https://github.com/colorium/web/blob/2a767658b8737022939b0cc4505b5f652c1683d2/src/Colorium/Web/Context.php#L76-L90 |
colorium/web | src/Colorium/Web/Context.php | Context.forward | public function forward($logic, ...$params)
{
$context = clone $this;
$context->depth++;
$context->params = $params;
return call_user_func($this->forwarder, $context, $logic);
} | php | public function forward($logic, ...$params)
{
$context = clone $this;
$context->depth++;
$context->params = $params;
return call_user_func($this->forwarder, $context, $logic);
} | [
"public",
"function",
"forward",
"(",
"$",
"logic",
",",
"...",
"$",
"params",
")",
"{",
"$",
"context",
"=",
"clone",
"$",
"this",
";",
"$",
"context",
"->",
"depth",
"++",
";",
"$",
"context",
"->",
"params",
"=",
"$",
"params",
";",
"return",
"call_user_func",
"(",
"$",
"this",
"->",
"forwarder",
",",
"$",
"context",
",",
"$",
"logic",
")",
";",
"}"
] | Forward to logic
@param string $logic name
@param $params
@return Context | [
"Forward",
"to",
"logic"
] | train | https://github.com/colorium/web/blob/2a767658b8737022939b0cc4505b5f652c1683d2/src/Colorium/Web/Context.php#L100-L106 |
oroinc/OroLayoutComponent | Extension/Theme/Model/DependencyInitializer.php | DependencyInitializer.initialize | public function initialize($object)
{
if (!is_object($object)) {
return;
}
foreach ($this->knownDependencies as $interface => $dependencyInfo) {
list($setterMethod, $serviceId) = $dependencyInfo;
if (is_a($object, $interface)) {
$object->$setterMethod($this->container->get($serviceId));
}
}
} | php | public function initialize($object)
{
if (!is_object($object)) {
return;
}
foreach ($this->knownDependencies as $interface => $dependencyInfo) {
list($setterMethod, $serviceId) = $dependencyInfo;
if (is_a($object, $interface)) {
$object->$setterMethod($this->container->get($serviceId));
}
}
} | [
"public",
"function",
"initialize",
"(",
"$",
"object",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"object",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"knownDependencies",
"as",
"$",
"interface",
"=>",
"$",
"dependencyInfo",
")",
"{",
"list",
"(",
"$",
"setterMethod",
",",
"$",
"serviceId",
")",
"=",
"$",
"dependencyInfo",
";",
"if",
"(",
"is_a",
"(",
"$",
"object",
",",
"$",
"interface",
")",
")",
"{",
"$",
"object",
"->",
"$",
"setterMethod",
"(",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"$",
"serviceId",
")",
")",
";",
"}",
"}",
"}"
] | Initializes object dependencies
@param object $object | [
"Initializes",
"object",
"dependencies"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Extension/Theme/Model/DependencyInitializer.php#L42-L55 |
mekras/atompub | src/Document/ServiceDocument.php | ServiceDocument.getWorkspaces | public function getWorkspaces()
{
return $this->getCachedProperty(
'workspaces',
function () {
$workspaces = [];
$items = $this->getDomElement()->getElementsByTagNameNS($this->ns(), 'workspace');
foreach ($items as $item) {
$workspaces[] = $this->getExtensions()->parseElement($this, $item);
}
return $workspaces;
}
);
} | php | public function getWorkspaces()
{
return $this->getCachedProperty(
'workspaces',
function () {
$workspaces = [];
$items = $this->getDomElement()->getElementsByTagNameNS($this->ns(), 'workspace');
foreach ($items as $item) {
$workspaces[] = $this->getExtensions()->parseElement($this, $item);
}
return $workspaces;
}
);
} | [
"public",
"function",
"getWorkspaces",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"getCachedProperty",
"(",
"'workspaces'",
",",
"function",
"(",
")",
"{",
"$",
"workspaces",
"=",
"[",
"]",
";",
"$",
"items",
"=",
"$",
"this",
"->",
"getDomElement",
"(",
")",
"->",
"getElementsByTagNameNS",
"(",
"$",
"this",
"->",
"ns",
"(",
")",
",",
"'workspace'",
")",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"workspaces",
"[",
"]",
"=",
"$",
"this",
"->",
"getExtensions",
"(",
")",
"->",
"parseElement",
"(",
"$",
"this",
",",
"$",
"item",
")",
";",
"}",
"return",
"$",
"workspaces",
";",
"}",
")",
";",
"}"
] | Return workspaces.
@return Workspace[]
@since 1.0 | [
"Return",
"workspaces",
"."
] | train | https://github.com/mekras/atompub/blob/cfc9aab97cff7a822b720e1dd84ef16733183dbb/src/Document/ServiceDocument.php#L28-L42 |
mekras/atompub | src/Document/ServiceDocument.php | ServiceDocument.addWorkspace | public function addWorkspace($title)
{
$workspaces = $this->getWorkspaces();
/** @var Workspace $workspace */
$workspace = $this->getExtensions()->createElement($this, 'app:workspace');
$workspace->addTitle($title);
$workspaces[] = $workspace;
$this->setCachedProperty('workspaces', $workspaces);
return $workspace;
} | php | public function addWorkspace($title)
{
$workspaces = $this->getWorkspaces();
/** @var Workspace $workspace */
$workspace = $this->getExtensions()->createElement($this, 'app:workspace');
$workspace->addTitle($title);
$workspaces[] = $workspace;
$this->setCachedProperty('workspaces', $workspaces);
return $workspace;
} | [
"public",
"function",
"addWorkspace",
"(",
"$",
"title",
")",
"{",
"$",
"workspaces",
"=",
"$",
"this",
"->",
"getWorkspaces",
"(",
")",
";",
"/** @var Workspace $workspace */",
"$",
"workspace",
"=",
"$",
"this",
"->",
"getExtensions",
"(",
")",
"->",
"createElement",
"(",
"$",
"this",
",",
"'app:workspace'",
")",
";",
"$",
"workspace",
"->",
"addTitle",
"(",
"$",
"title",
")",
";",
"$",
"workspaces",
"[",
"]",
"=",
"$",
"workspace",
";",
"$",
"this",
"->",
"setCachedProperty",
"(",
"'workspaces'",
",",
"$",
"workspaces",
")",
";",
"return",
"$",
"workspace",
";",
"}"
] | Add workspace to document.
@param string $title
@return Workspace
@since 1.0 | [
"Add",
"workspace",
"to",
"document",
"."
] | train | https://github.com/mekras/atompub/blob/cfc9aab97cff7a822b720e1dd84ef16733183dbb/src/Document/ServiceDocument.php#L53-L65 |
mustardandrew/muan-laravel-acl | src/Commands/Permission/RemoveCommand.php | RemoveCommand.handle | public function handle()
{
$permissionName = $this->argument('permission');
if (! $permission = Permission::whereName($permissionName)->first()) {
$this->warn("Permission {$permissionName} not exists.");
return 1;
}
if ($permission->delete()) {
echo "Permission {$permissionName} removed successfully.", PHP_EOL;
} else {
$this->error("Permission {$permissionName} not removed!");
}
return 0;
} | php | public function handle()
{
$permissionName = $this->argument('permission');
if (! $permission = Permission::whereName($permissionName)->first()) {
$this->warn("Permission {$permissionName} not exists.");
return 1;
}
if ($permission->delete()) {
echo "Permission {$permissionName} removed successfully.", PHP_EOL;
} else {
$this->error("Permission {$permissionName} not removed!");
}
return 0;
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"$",
"permissionName",
"=",
"$",
"this",
"->",
"argument",
"(",
"'permission'",
")",
";",
"if",
"(",
"!",
"$",
"permission",
"=",
"Permission",
"::",
"whereName",
"(",
"$",
"permissionName",
")",
"->",
"first",
"(",
")",
")",
"{",
"$",
"this",
"->",
"warn",
"(",
"\"Permission {$permissionName} not exists.\"",
")",
";",
"return",
"1",
";",
"}",
"if",
"(",
"$",
"permission",
"->",
"delete",
"(",
")",
")",
"{",
"echo",
"\"Permission {$permissionName} removed successfully.\"",
",",
"PHP_EOL",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"error",
"(",
"\"Permission {$permissionName} not removed!\"",
")",
";",
"}",
"return",
"0",
";",
"}"
] | Execute the console command.
@return mixed | [
"Execute",
"the",
"console",
"command",
"."
] | train | https://github.com/mustardandrew/muan-laravel-acl/blob/b5f23340b5536babb98d9fd0d727a7a3371c97d5/src/Commands/Permission/RemoveCommand.php#L34-L50 |
Speicher210/monsum-api | src/Service/Article/ArticleService.php | ArticleService.getArticles | public function getArticles($articleNumber = null)
{
$requestData = new Get\RequestData();
$requestData->setArticleNumber($articleNumber);
$request = new Get\Request($requestData);
return $this->sendRequest($request, Get\ApiResponse::class);
} | php | public function getArticles($articleNumber = null)
{
$requestData = new Get\RequestData();
$requestData->setArticleNumber($articleNumber);
$request = new Get\Request($requestData);
return $this->sendRequest($request, Get\ApiResponse::class);
} | [
"public",
"function",
"getArticles",
"(",
"$",
"articleNumber",
"=",
"null",
")",
"{",
"$",
"requestData",
"=",
"new",
"Get",
"\\",
"RequestData",
"(",
")",
";",
"$",
"requestData",
"->",
"setArticleNumber",
"(",
"$",
"articleNumber",
")",
";",
"$",
"request",
"=",
"new",
"Get",
"\\",
"Request",
"(",
"$",
"requestData",
")",
";",
"return",
"$",
"this",
"->",
"sendRequest",
"(",
"$",
"request",
",",
"Get",
"\\",
"ApiResponse",
"::",
"class",
")",
";",
"}"
] | Get the articles.
@param string $articleNumber Article number to filter on.
@return Get\ApiResponse | [
"Get",
"the",
"articles",
"."
] | train | https://github.com/Speicher210/monsum-api/blob/4611a048097de5d2b0efe9d4426779c783c0af4d/src/Service/Article/ArticleService.php#L23-L31 |
Speicher210/monsum-api | src/Service/Article/ArticleService.php | ArticleService.getArticle | public function getArticle($articleNumber)
{
$requestData = new Get\RequestData();
$requestData->setArticleNumber($articleNumber);
$request = new Get\Request($requestData);
$request->setLimit(1);
/** @var Get\ApiResponse $apiResponse */
$apiResponse = $this->sendRequest($request, Get\ApiResponse::class);
$articles = $apiResponse->getResponse()->getArticles();
return isset($articles[0]) ? $articles[0] : null;
} | php | public function getArticle($articleNumber)
{
$requestData = new Get\RequestData();
$requestData->setArticleNumber($articleNumber);
$request = new Get\Request($requestData);
$request->setLimit(1);
/** @var Get\ApiResponse $apiResponse */
$apiResponse = $this->sendRequest($request, Get\ApiResponse::class);
$articles = $apiResponse->getResponse()->getArticles();
return isset($articles[0]) ? $articles[0] : null;
} | [
"public",
"function",
"getArticle",
"(",
"$",
"articleNumber",
")",
"{",
"$",
"requestData",
"=",
"new",
"Get",
"\\",
"RequestData",
"(",
")",
";",
"$",
"requestData",
"->",
"setArticleNumber",
"(",
"$",
"articleNumber",
")",
";",
"$",
"request",
"=",
"new",
"Get",
"\\",
"Request",
"(",
"$",
"requestData",
")",
";",
"$",
"request",
"->",
"setLimit",
"(",
"1",
")",
";",
"/** @var Get\\ApiResponse $apiResponse */",
"$",
"apiResponse",
"=",
"$",
"this",
"->",
"sendRequest",
"(",
"$",
"request",
",",
"Get",
"\\",
"ApiResponse",
"::",
"class",
")",
";",
"$",
"articles",
"=",
"$",
"apiResponse",
"->",
"getResponse",
"(",
")",
"->",
"getArticles",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"articles",
"[",
"0",
"]",
")",
"?",
"$",
"articles",
"[",
"0",
"]",
":",
"null",
";",
"}"
] | Get one article by article number.
@param string $articleNumber Article number of the article to get.
@return Article|null | [
"Get",
"one",
"article",
"by",
"article",
"number",
"."
] | train | https://github.com/Speicher210/monsum-api/blob/4611a048097de5d2b0efe9d4426779c783c0af4d/src/Service/Article/ArticleService.php#L39-L52 |
Speicher210/monsum-api | src/Service/Article/ArticleService.php | ArticleService.getArticleCheckoutURL | public function getArticleCheckoutURL(
Article $article,
Customer $customer = null,
CustomerQueryParams $customerQueryParams = null,
SubscriptionQueryParams $subscriptionQueryParams = null
) {
if ($customer === null) {
return $article->getCheckoutUrl() . (string)$customerQueryParams . (string)$subscriptionQueryParams;
}
// If Customer is passed then we do not pass customer query params because the value from customer always takes precedence.
return $this->generateCheckoutURLForCustomer($customer->getHash(), $article->getArticleNumber()) . (string)$subscriptionQueryParams;
} | php | public function getArticleCheckoutURL(
Article $article,
Customer $customer = null,
CustomerQueryParams $customerQueryParams = null,
SubscriptionQueryParams $subscriptionQueryParams = null
) {
if ($customer === null) {
return $article->getCheckoutUrl() . (string)$customerQueryParams . (string)$subscriptionQueryParams;
}
// If Customer is passed then we do not pass customer query params because the value from customer always takes precedence.
return $this->generateCheckoutURLForCustomer($customer->getHash(), $article->getArticleNumber()) . (string)$subscriptionQueryParams;
} | [
"public",
"function",
"getArticleCheckoutURL",
"(",
"Article",
"$",
"article",
",",
"Customer",
"$",
"customer",
"=",
"null",
",",
"CustomerQueryParams",
"$",
"customerQueryParams",
"=",
"null",
",",
"SubscriptionQueryParams",
"$",
"subscriptionQueryParams",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"customer",
"===",
"null",
")",
"{",
"return",
"$",
"article",
"->",
"getCheckoutUrl",
"(",
")",
".",
"(",
"string",
")",
"$",
"customerQueryParams",
".",
"(",
"string",
")",
"$",
"subscriptionQueryParams",
";",
"}",
"// If Customer is passed then we do not pass customer query params because the value from customer always takes precedence.",
"return",
"$",
"this",
"->",
"generateCheckoutURLForCustomer",
"(",
"$",
"customer",
"->",
"getHash",
"(",
")",
",",
"$",
"article",
"->",
"getArticleNumber",
"(",
")",
")",
".",
"(",
"string",
")",
"$",
"subscriptionQueryParams",
";",
"}"
] | Get the article checkout URL.
@param Article $article The article.
@param Customer|null $customer The customer for which the checkout URL should be created.
@param CustomerQueryParams|null $customerQueryParams Additional query params for customer data. If $customer is passed query params will be ignored.
@param SubscriptionQueryParams|null $subscriptionQueryParams Additional query params for subscription data.
@return string | [
"Get",
"the",
"article",
"checkout",
"URL",
"."
] | train | https://github.com/Speicher210/monsum-api/blob/4611a048097de5d2b0efe9d4426779c783c0af4d/src/Service/Article/ArticleService.php#L63-L75 |
Speicher210/monsum-api | src/Service/Article/ArticleService.php | ArticleService.getArticleNumberCheckoutURL | public function getArticleNumberCheckoutURL($articleNumber, Customer $customer = null)
{
$article = $this->getArticle($articleNumber);
if ($article === null) {
throw new \OutOfBoundsException('Article not found.');
}
return $this->getArticleCheckoutURL($article, $customer);
} | php | public function getArticleNumberCheckoutURL($articleNumber, Customer $customer = null)
{
$article = $this->getArticle($articleNumber);
if ($article === null) {
throw new \OutOfBoundsException('Article not found.');
}
return $this->getArticleCheckoutURL($article, $customer);
} | [
"public",
"function",
"getArticleNumberCheckoutURL",
"(",
"$",
"articleNumber",
",",
"Customer",
"$",
"customer",
"=",
"null",
")",
"{",
"$",
"article",
"=",
"$",
"this",
"->",
"getArticle",
"(",
"$",
"articleNumber",
")",
";",
"if",
"(",
"$",
"article",
"===",
"null",
")",
"{",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"'Article not found.'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getArticleCheckoutURL",
"(",
"$",
"article",
",",
"$",
"customer",
")",
";",
"}"
] | Get the checkout URL for an article.
@param string $articleNumber Article number of the article to get the checkout URL.
@param Customer $customer The customer for which the checkout URL should be created.
@return string
@throws \OutOfBoundsException If the article is not found. | [
"Get",
"the",
"checkout",
"URL",
"for",
"an",
"article",
"."
] | train | https://github.com/Speicher210/monsum-api/blob/4611a048097de5d2b0efe9d4426779c783c0af4d/src/Service/Article/ArticleService.php#L85-L93 |
Speicher210/monsum-api | src/Service/Article/ArticleService.php | ArticleService.generateCheckoutURLForCustomer | protected function generateCheckoutURLForCustomer($customerHash, $articleNumber)
{
return sprintf(
'https://app.monsum.com/checkout/0/%s/%s/%s',
$this->transport->getCredentials()->getAccountHash(),
$customerHash,
$articleNumber
);
} | php | protected function generateCheckoutURLForCustomer($customerHash, $articleNumber)
{
return sprintf(
'https://app.monsum.com/checkout/0/%s/%s/%s',
$this->transport->getCredentials()->getAccountHash(),
$customerHash,
$articleNumber
);
} | [
"protected",
"function",
"generateCheckoutURLForCustomer",
"(",
"$",
"customerHash",
",",
"$",
"articleNumber",
")",
"{",
"return",
"sprintf",
"(",
"'https://app.monsum.com/checkout/0/%s/%s/%s'",
",",
"$",
"this",
"->",
"transport",
"->",
"getCredentials",
"(",
")",
"->",
"getAccountHash",
"(",
")",
",",
"$",
"customerHash",
",",
"$",
"articleNumber",
")",
";",
"}"
] | Get the checkout URL of an article for a customer.
@param string $customerHash The customer hash.
@param string $articleNumber The article number.
@return string | [
"Get",
"the",
"checkout",
"URL",
"of",
"an",
"article",
"for",
"a",
"customer",
"."
] | train | https://github.com/Speicher210/monsum-api/blob/4611a048097de5d2b0efe9d4426779c783c0af4d/src/Service/Article/ArticleService.php#L116-L124 |
Speicher210/monsum-api | src/Service/Article/ArticleService.php | ArticleService.generateSubscriptionProductChangeURL | protected function generateSubscriptionProductChangeURL($subscriptionId, $articleNumber)
{
return sprintf(
'https://app.monsum.com/change/%s/%s/%s',
$this->transport->getCredentials()->getAccountHash(),
$subscriptionId,
$articleNumber
);
} | php | protected function generateSubscriptionProductChangeURL($subscriptionId, $articleNumber)
{
return sprintf(
'https://app.monsum.com/change/%s/%s/%s',
$this->transport->getCredentials()->getAccountHash(),
$subscriptionId,
$articleNumber
);
} | [
"protected",
"function",
"generateSubscriptionProductChangeURL",
"(",
"$",
"subscriptionId",
",",
"$",
"articleNumber",
")",
"{",
"return",
"sprintf",
"(",
"'https://app.monsum.com/change/%s/%s/%s'",
",",
"$",
"this",
"->",
"transport",
"->",
"getCredentials",
"(",
")",
"->",
"getAccountHash",
"(",
")",
",",
"$",
"subscriptionId",
",",
"$",
"articleNumber",
")",
";",
"}"
] | Get the checkout URL to change a product for a subscription.
@param string $subscriptionId The subscription ID.
@param string $articleNumber The new article number.
@return string | [
"Get",
"the",
"checkout",
"URL",
"to",
"change",
"a",
"product",
"for",
"a",
"subscription",
"."
] | train | https://github.com/Speicher210/monsum-api/blob/4611a048097de5d2b0efe9d4426779c783c0af4d/src/Service/Article/ArticleService.php#L145-L153 |
zhouyl/mellivora | Mellivora/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php | InteractsWithPivotTable.toggle | public function toggle($ids, $touch = true)
{
$changes = [
'attached' => [], 'detached' => [],
];
$records = $this->formatRecordsList((array) $this->parseIds($ids));
// Next, we will determine which IDs should get removed from the join table by
// checking which of the given ID/records is in the list of current records
// and removing all of those rows from this "intermediate" joining table.
$detach = array_values(array_intersect(
$this->newPivotQuery()->pluck($this->relatedKey)->all(),
array_keys($records)
));
if (count($detach) > 0) {
$this->detach($detach, false);
$changes['detached'] = $this->castKeys($detach);
}
// Finally, for all of the records which were not "detached", we'll attach the
// records into the intermediate table. Then, we will add those attaches to
// this change list and get ready to return these results to the callers.
$attach = array_diff_key($records, array_flip($detach));
if (count($attach) > 0) {
$this->attach($attach, [], false);
$changes['attached'] = array_keys($attach);
}
// Once we have finished attaching or detaching the records, we will see if we
// have done any attaching or detaching, and if we have we will touch these
// relationships if they are configured to touch on any database updates.
if ($touch && (count($changes['attached']) ||
count($changes['detached']))) {
$this->touchIfTouching();
}
return $changes;
} | php | public function toggle($ids, $touch = true)
{
$changes = [
'attached' => [], 'detached' => [],
];
$records = $this->formatRecordsList((array) $this->parseIds($ids));
// Next, we will determine which IDs should get removed from the join table by
// checking which of the given ID/records is in the list of current records
// and removing all of those rows from this "intermediate" joining table.
$detach = array_values(array_intersect(
$this->newPivotQuery()->pluck($this->relatedKey)->all(),
array_keys($records)
));
if (count($detach) > 0) {
$this->detach($detach, false);
$changes['detached'] = $this->castKeys($detach);
}
// Finally, for all of the records which were not "detached", we'll attach the
// records into the intermediate table. Then, we will add those attaches to
// this change list and get ready to return these results to the callers.
$attach = array_diff_key($records, array_flip($detach));
if (count($attach) > 0) {
$this->attach($attach, [], false);
$changes['attached'] = array_keys($attach);
}
// Once we have finished attaching or detaching the records, we will see if we
// have done any attaching or detaching, and if we have we will touch these
// relationships if they are configured to touch on any database updates.
if ($touch && (count($changes['attached']) ||
count($changes['detached']))) {
$this->touchIfTouching();
}
return $changes;
} | [
"public",
"function",
"toggle",
"(",
"$",
"ids",
",",
"$",
"touch",
"=",
"true",
")",
"{",
"$",
"changes",
"=",
"[",
"'attached'",
"=>",
"[",
"]",
",",
"'detached'",
"=>",
"[",
"]",
",",
"]",
";",
"$",
"records",
"=",
"$",
"this",
"->",
"formatRecordsList",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"parseIds",
"(",
"$",
"ids",
")",
")",
";",
"// Next, we will determine which IDs should get removed from the join table by",
"// checking which of the given ID/records is in the list of current records",
"// and removing all of those rows from this \"intermediate\" joining table.",
"$",
"detach",
"=",
"array_values",
"(",
"array_intersect",
"(",
"$",
"this",
"->",
"newPivotQuery",
"(",
")",
"->",
"pluck",
"(",
"$",
"this",
"->",
"relatedKey",
")",
"->",
"all",
"(",
")",
",",
"array_keys",
"(",
"$",
"records",
")",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"detach",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"detach",
"(",
"$",
"detach",
",",
"false",
")",
";",
"$",
"changes",
"[",
"'detached'",
"]",
"=",
"$",
"this",
"->",
"castKeys",
"(",
"$",
"detach",
")",
";",
"}",
"// Finally, for all of the records which were not \"detached\", we'll attach the",
"// records into the intermediate table. Then, we will add those attaches to",
"// this change list and get ready to return these results to the callers.",
"$",
"attach",
"=",
"array_diff_key",
"(",
"$",
"records",
",",
"array_flip",
"(",
"$",
"detach",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"attach",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"attach",
"(",
"$",
"attach",
",",
"[",
"]",
",",
"false",
")",
";",
"$",
"changes",
"[",
"'attached'",
"]",
"=",
"array_keys",
"(",
"$",
"attach",
")",
";",
"}",
"// Once we have finished attaching or detaching the records, we will see if we",
"// have done any attaching or detaching, and if we have we will touch these",
"// relationships if they are configured to touch on any database updates.",
"if",
"(",
"$",
"touch",
"&&",
"(",
"count",
"(",
"$",
"changes",
"[",
"'attached'",
"]",
")",
"||",
"count",
"(",
"$",
"changes",
"[",
"'detached'",
"]",
")",
")",
")",
"{",
"$",
"this",
"->",
"touchIfTouching",
"(",
")",
";",
"}",
"return",
"$",
"changes",
";",
"}"
] | Toggles a model (or models) from the parent.
Each existing model is detached, and non existing ones are attached.
@param mixed $ids
@param bool $touch
@return array | [
"Toggles",
"a",
"model",
"(",
"or",
"models",
")",
"from",
"the",
"parent",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php#L21-L63 |
zhouyl/mellivora | Mellivora/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php | InteractsWithPivotTable.sync | public function sync($ids, $detaching = true)
{
$changes = [
'attached' => [], 'detached' => [], 'updated' => [],
];
// First we need to attach any of the associated models that are not currently
// in this joining table. We'll spin through the given IDs, checking to see
// if they exist in the array of current ones, and if not we will insert.
$current = $this->newPivotQuery()->pluck(
$this->relatedKey
)->all();
$detach = array_diff($current, array_keys(
$records = $this->formatRecordsList($this->parseIds($ids))
));
// Next, we will take the differences of the currents and given IDs and detach
// all of the entities that exist in the "current" array but are not in the
// array of the new IDs given to the method which will complete the sync.
if ($detaching && count($detach) > 0) {
$this->detach($detach);
$changes['detached'] = $this->castKeys($detach);
}
// Now we are finally ready to attach the new records. Note that we'll disable
// touching until after the entire operation is complete so we don't fire a
// ton of touch operations until we are totally done syncing the records.
$changes = array_merge(
$changes,
$this->attachNew($records, $current, false)
);
// Once we have finished attaching or detaching the records, we will see if we
// have done any attaching or detaching, and if we have we will touch these
// relationships if they are configured to touch on any database updates.
if (count($changes['attached']) ||
count($changes['updated'])) {
$this->touchIfTouching();
}
return $changes;
} | php | public function sync($ids, $detaching = true)
{
$changes = [
'attached' => [], 'detached' => [], 'updated' => [],
];
// First we need to attach any of the associated models that are not currently
// in this joining table. We'll spin through the given IDs, checking to see
// if they exist in the array of current ones, and if not we will insert.
$current = $this->newPivotQuery()->pluck(
$this->relatedKey
)->all();
$detach = array_diff($current, array_keys(
$records = $this->formatRecordsList($this->parseIds($ids))
));
// Next, we will take the differences of the currents and given IDs and detach
// all of the entities that exist in the "current" array but are not in the
// array of the new IDs given to the method which will complete the sync.
if ($detaching && count($detach) > 0) {
$this->detach($detach);
$changes['detached'] = $this->castKeys($detach);
}
// Now we are finally ready to attach the new records. Note that we'll disable
// touching until after the entire operation is complete so we don't fire a
// ton of touch operations until we are totally done syncing the records.
$changes = array_merge(
$changes,
$this->attachNew($records, $current, false)
);
// Once we have finished attaching or detaching the records, we will see if we
// have done any attaching or detaching, and if we have we will touch these
// relationships if they are configured to touch on any database updates.
if (count($changes['attached']) ||
count($changes['updated'])) {
$this->touchIfTouching();
}
return $changes;
} | [
"public",
"function",
"sync",
"(",
"$",
"ids",
",",
"$",
"detaching",
"=",
"true",
")",
"{",
"$",
"changes",
"=",
"[",
"'attached'",
"=>",
"[",
"]",
",",
"'detached'",
"=>",
"[",
"]",
",",
"'updated'",
"=>",
"[",
"]",
",",
"]",
";",
"// First we need to attach any of the associated models that are not currently",
"// in this joining table. We'll spin through the given IDs, checking to see",
"// if they exist in the array of current ones, and if not we will insert.",
"$",
"current",
"=",
"$",
"this",
"->",
"newPivotQuery",
"(",
")",
"->",
"pluck",
"(",
"$",
"this",
"->",
"relatedKey",
")",
"->",
"all",
"(",
")",
";",
"$",
"detach",
"=",
"array_diff",
"(",
"$",
"current",
",",
"array_keys",
"(",
"$",
"records",
"=",
"$",
"this",
"->",
"formatRecordsList",
"(",
"$",
"this",
"->",
"parseIds",
"(",
"$",
"ids",
")",
")",
")",
")",
";",
"// Next, we will take the differences of the currents and given IDs and detach",
"// all of the entities that exist in the \"current\" array but are not in the",
"// array of the new IDs given to the method which will complete the sync.",
"if",
"(",
"$",
"detaching",
"&&",
"count",
"(",
"$",
"detach",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"detach",
"(",
"$",
"detach",
")",
";",
"$",
"changes",
"[",
"'detached'",
"]",
"=",
"$",
"this",
"->",
"castKeys",
"(",
"$",
"detach",
")",
";",
"}",
"// Now we are finally ready to attach the new records. Note that we'll disable",
"// touching until after the entire operation is complete so we don't fire a",
"// ton of touch operations until we are totally done syncing the records.",
"$",
"changes",
"=",
"array_merge",
"(",
"$",
"changes",
",",
"$",
"this",
"->",
"attachNew",
"(",
"$",
"records",
",",
"$",
"current",
",",
"false",
")",
")",
";",
"// Once we have finished attaching or detaching the records, we will see if we",
"// have done any attaching or detaching, and if we have we will touch these",
"// relationships if they are configured to touch on any database updates.",
"if",
"(",
"count",
"(",
"$",
"changes",
"[",
"'attached'",
"]",
")",
"||",
"count",
"(",
"$",
"changes",
"[",
"'updated'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"touchIfTouching",
"(",
")",
";",
"}",
"return",
"$",
"changes",
";",
"}"
] | Sync the intermediate tables with a list of IDs or collection of models.
@param array|\Mellivora\Database\Eloquent\Collection|\Mellivora\Support\Collection $ids
@param bool $detaching
@return array | [
"Sync",
"the",
"intermediate",
"tables",
"with",
"a",
"list",
"of",
"IDs",
"or",
"collection",
"of",
"models",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php#L85-L128 |
zhouyl/mellivora | Mellivora/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php | InteractsWithPivotTable.formatRecordsList | protected function formatRecordsList(array $records)
{
return collect($records)->mapWithKeys(function ($attributes, $id) {
if (!is_array($attributes)) {
list($id, $attributes) = [$attributes, []];
}
return [$id => $attributes];
})->all();
} | php | protected function formatRecordsList(array $records)
{
return collect($records)->mapWithKeys(function ($attributes, $id) {
if (!is_array($attributes)) {
list($id, $attributes) = [$attributes, []];
}
return [$id => $attributes];
})->all();
} | [
"protected",
"function",
"formatRecordsList",
"(",
"array",
"$",
"records",
")",
"{",
"return",
"collect",
"(",
"$",
"records",
")",
"->",
"mapWithKeys",
"(",
"function",
"(",
"$",
"attributes",
",",
"$",
"id",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"attributes",
")",
")",
"{",
"list",
"(",
"$",
"id",
",",
"$",
"attributes",
")",
"=",
"[",
"$",
"attributes",
",",
"[",
"]",
"]",
";",
"}",
"return",
"[",
"$",
"id",
"=>",
"$",
"attributes",
"]",
";",
"}",
")",
"->",
"all",
"(",
")",
";",
"}"
] | Format the sync / toggle record list so that it is keyed by ID.
@param array $records
@return array | [
"Format",
"the",
"sync",
"/",
"toggle",
"record",
"list",
"so",
"that",
"it",
"is",
"keyed",
"by",
"ID",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php#L137-L146 |
superjimpupcake/Pupcake | src/Pupcake/Route.php | Route.execute | public function execute($params = array())
{
$app = $this->router->getAppInstance();
return $app->trigger("system.routing.route.execute", function($event) {
$app = $event->props('app');
$route = $event->props('route');
$params = $event->props('params');
if (count($params) == 0) {
$params = $route->getParams();
}
//enhancement, detect the type of the callback
$callback = $route->getCallback();
if (is_string($callback)) {
$callback_comps = explode("#", $callback);
$callback_object_class = $callback_comps[0]; //starting from root namespace
$callback_object_class = str_replace(".", "\\", $callback_object_class);
$callback_object = new $callback_object_class($app);
$callback_object_method = $callback_comps[1];
$callback = array($callback_object, $callback_object_method);
}
return call_user_func_array($callback, $params);
}, array('app' => $app, 'route' => $this, 'params' => $params));
} | php | public function execute($params = array())
{
$app = $this->router->getAppInstance();
return $app->trigger("system.routing.route.execute", function($event) {
$app = $event->props('app');
$route = $event->props('route');
$params = $event->props('params');
if (count($params) == 0) {
$params = $route->getParams();
}
//enhancement, detect the type of the callback
$callback = $route->getCallback();
if (is_string($callback)) {
$callback_comps = explode("#", $callback);
$callback_object_class = $callback_comps[0]; //starting from root namespace
$callback_object_class = str_replace(".", "\\", $callback_object_class);
$callback_object = new $callback_object_class($app);
$callback_object_method = $callback_comps[1];
$callback = array($callback_object, $callback_object_method);
}
return call_user_func_array($callback, $params);
}, array('app' => $app, 'route' => $this, 'params' => $params));
} | [
"public",
"function",
"execute",
"(",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"app",
"=",
"$",
"this",
"->",
"router",
"->",
"getAppInstance",
"(",
")",
";",
"return",
"$",
"app",
"->",
"trigger",
"(",
"\"system.routing.route.execute\"",
",",
"function",
"(",
"$",
"event",
")",
"{",
"$",
"app",
"=",
"$",
"event",
"->",
"props",
"(",
"'app'",
")",
";",
"$",
"route",
"=",
"$",
"event",
"->",
"props",
"(",
"'route'",
")",
";",
"$",
"params",
"=",
"$",
"event",
"->",
"props",
"(",
"'params'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"params",
")",
"==",
"0",
")",
"{",
"$",
"params",
"=",
"$",
"route",
"->",
"getParams",
"(",
")",
";",
"}",
"//enhancement, detect the type of the callback",
"$",
"callback",
"=",
"$",
"route",
"->",
"getCallback",
"(",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"callback",
")",
")",
"{",
"$",
"callback_comps",
"=",
"explode",
"(",
"\"#\"",
",",
"$",
"callback",
")",
";",
"$",
"callback_object_class",
"=",
"$",
"callback_comps",
"[",
"0",
"]",
";",
"//starting from root namespace",
"$",
"callback_object_class",
"=",
"str_replace",
"(",
"\".\"",
",",
"\"\\\\\"",
",",
"$",
"callback_object_class",
")",
";",
"$",
"callback_object",
"=",
"new",
"$",
"callback_object_class",
"(",
"$",
"app",
")",
";",
"$",
"callback_object_method",
"=",
"$",
"callback_comps",
"[",
"1",
"]",
";",
"$",
"callback",
"=",
"array",
"(",
"$",
"callback_object",
",",
"$",
"callback_object_method",
")",
";",
"}",
"return",
"call_user_func_array",
"(",
"$",
"callback",
",",
"$",
"params",
")",
";",
"}",
",",
"array",
"(",
"'app'",
"=>",
"$",
"app",
",",
"'route'",
"=>",
"$",
"this",
",",
"'params'",
"=>",
"$",
"params",
")",
")",
";",
"}"
] | Execute this route | [
"Execute",
"this",
"route"
] | train | https://github.com/superjimpupcake/Pupcake/blob/2f962818646e4e1d65f5d008eeb953cb41ebb3e0/src/Pupcake/Route.php#L88-L110 |
inhere/php-librarys | src/Collections/Collection.php | Collection.parseYaml | public static function parseYaml($data, $enhancement = false, callable $pathHandler = null, $fileDir = '')
{
return YmlParser::parse($data, $enhancement, $pathHandler, $fileDir);
} | php | public static function parseYaml($data, $enhancement = false, callable $pathHandler = null, $fileDir = '')
{
return YmlParser::parse($data, $enhancement, $pathHandler, $fileDir);
} | [
"public",
"static",
"function",
"parseYaml",
"(",
"$",
"data",
",",
"$",
"enhancement",
"=",
"false",
",",
"callable",
"$",
"pathHandler",
"=",
"null",
",",
"$",
"fileDir",
"=",
"''",
")",
"{",
"return",
"YmlParser",
"::",
"parse",
"(",
"$",
"data",
",",
"$",
"enhancement",
",",
"$",
"pathHandler",
",",
"$",
"fileDir",
")",
";",
"}"
] | parse YAML
@param string|bool $data Waiting for the parse data
@param bool $enhancement Simple support import other config by tag 'import'. must is bool.
@param callable $pathHandler When the second param is true, this param is valid.
@param string $fileDir When the second param is true, this param is valid.
@return array | [
"parse",
"YAML"
] | train | https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Collections/Collection.php#L427-L430 |
mustardandrew/muan-laravel-acl | src/Traits/HasRolesTrait.php | HasRolesTrait.hasRole | public function hasRole(...$roles)
{
$roles = array_flatten($roles);
foreach ($roles as $role) {
$name = $role instanceof Role ? $role->name : $role;
if ($this->roles->contains('name', $name)) {
return true;
}
}
return false;
} | php | public function hasRole(...$roles)
{
$roles = array_flatten($roles);
foreach ($roles as $role) {
$name = $role instanceof Role ? $role->name : $role;
if ($this->roles->contains('name', $name)) {
return true;
}
}
return false;
} | [
"public",
"function",
"hasRole",
"(",
"...",
"$",
"roles",
")",
"{",
"$",
"roles",
"=",
"array_flatten",
"(",
"$",
"roles",
")",
";",
"foreach",
"(",
"$",
"roles",
"as",
"$",
"role",
")",
"{",
"$",
"name",
"=",
"$",
"role",
"instanceof",
"Role",
"?",
"$",
"role",
"->",
"name",
":",
"$",
"role",
";",
"if",
"(",
"$",
"this",
"->",
"roles",
"->",
"contains",
"(",
"'name'",
",",
"$",
"name",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Has role
@param mixed $roles
@return boolean | [
"Has",
"role"
] | train | https://github.com/mustardandrew/muan-laravel-acl/blob/b5f23340b5536babb98d9fd0d727a7a3371c97d5/src/Traits/HasRolesTrait.php#L21-L34 |
mustardandrew/muan-laravel-acl | src/Traits/HasRolesTrait.php | HasRolesTrait.attachRole | public function attachRole(...$roles)
{
$this->eachRole($roles, function($role) {
if (! $this->hasRole($role)) {
$this->roles()->attach($role->id);
}
});
return $this;
} | php | public function attachRole(...$roles)
{
$this->eachRole($roles, function($role) {
if (! $this->hasRole($role)) {
$this->roles()->attach($role->id);
}
});
return $this;
} | [
"public",
"function",
"attachRole",
"(",
"...",
"$",
"roles",
")",
"{",
"$",
"this",
"->",
"eachRole",
"(",
"$",
"roles",
",",
"function",
"(",
"$",
"role",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasRole",
"(",
"$",
"role",
")",
")",
"{",
"$",
"this",
"->",
"roles",
"(",
")",
"->",
"attach",
"(",
"$",
"role",
"->",
"id",
")",
";",
"}",
"}",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Attach role
@param mixed ...$roles
@return $this | [
"Attach",
"role"
] | train | https://github.com/mustardandrew/muan-laravel-acl/blob/b5f23340b5536babb98d9fd0d727a7a3371c97d5/src/Traits/HasRolesTrait.php#L42-L51 |
mustardandrew/muan-laravel-acl | src/Traits/HasRolesTrait.php | HasRolesTrait.detachRole | public function detachRole(...$roles)
{
$this->eachRole($roles, function($role) {
if ($this->hasRole($role)) {
$this->roles()->detach($role->id);
}
});
return $this;
} | php | public function detachRole(...$roles)
{
$this->eachRole($roles, function($role) {
if ($this->hasRole($role)) {
$this->roles()->detach($role->id);
}
});
return $this;
} | [
"public",
"function",
"detachRole",
"(",
"...",
"$",
"roles",
")",
"{",
"$",
"this",
"->",
"eachRole",
"(",
"$",
"roles",
",",
"function",
"(",
"$",
"role",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasRole",
"(",
"$",
"role",
")",
")",
"{",
"$",
"this",
"->",
"roles",
"(",
")",
"->",
"detach",
"(",
"$",
"role",
"->",
"id",
")",
";",
"}",
"}",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Detach role
@param mixed ...$roles
@return $this | [
"Detach",
"role"
] | train | https://github.com/mustardandrew/muan-laravel-acl/blob/b5f23340b5536babb98d9fd0d727a7a3371c97d5/src/Traits/HasRolesTrait.php#L59-L68 |
mustardandrew/muan-laravel-acl | src/Traits/HasRolesTrait.php | HasRolesTrait.prepareRole | public function prepareRole($role)
{
if ($role instanceof Role) {
return $role;
}
if (is_numeric($role)) {
return Role::whereId($role)->first();
}
return Role::whereName($role)->first();
} | php | public function prepareRole($role)
{
if ($role instanceof Role) {
return $role;
}
if (is_numeric($role)) {
return Role::whereId($role)->first();
}
return Role::whereName($role)->first();
} | [
"public",
"function",
"prepareRole",
"(",
"$",
"role",
")",
"{",
"if",
"(",
"$",
"role",
"instanceof",
"Role",
")",
"{",
"return",
"$",
"role",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"role",
")",
")",
"{",
"return",
"Role",
"::",
"whereId",
"(",
"$",
"role",
")",
"->",
"first",
"(",
")",
";",
"}",
"return",
"Role",
"::",
"whereName",
"(",
"$",
"role",
")",
"->",
"first",
"(",
")",
";",
"}"
] | Prepare role
@param Role|int|string $role
@return Role | [
"Prepare",
"role"
] | train | https://github.com/mustardandrew/muan-laravel-acl/blob/b5f23340b5536babb98d9fd0d727a7a3371c97d5/src/Traits/HasRolesTrait.php#L98-L109 |
mustardandrew/muan-laravel-acl | src/Traits/HasRolesTrait.php | HasRolesTrait.eachRole | public function eachRole(array $roles, callable $callback)
{
$roles = array_flatten($roles);
foreach ($roles as $role) {
if ($role = $this->prepareRole($role)) {
$callback($role);
}
}
} | php | public function eachRole(array $roles, callable $callback)
{
$roles = array_flatten($roles);
foreach ($roles as $role) {
if ($role = $this->prepareRole($role)) {
$callback($role);
}
}
} | [
"public",
"function",
"eachRole",
"(",
"array",
"$",
"roles",
",",
"callable",
"$",
"callback",
")",
"{",
"$",
"roles",
"=",
"array_flatten",
"(",
"$",
"roles",
")",
";",
"foreach",
"(",
"$",
"roles",
"as",
"$",
"role",
")",
"{",
"if",
"(",
"$",
"role",
"=",
"$",
"this",
"->",
"prepareRole",
"(",
"$",
"role",
")",
")",
"{",
"$",
"callback",
"(",
"$",
"role",
")",
";",
"}",
"}",
"}"
] | Calc each rote
@param array $roles
@param callable $callback | [
"Calc",
"each",
"rote"
] | train | https://github.com/mustardandrew/muan-laravel-acl/blob/b5f23340b5536babb98d9fd0d727a7a3371c97d5/src/Traits/HasRolesTrait.php#L117-L126 |
mustardandrew/muan-laravel-acl | src/Commands/User/DetachRoleCommand.php | DetachRoleCommand.handle | public function handle()
{
$id = $this->argument('id');
try {
$user = $this->prepareUser($id);
} catch (Exception $e) {
$this->warn($e->getMessage());
return 1;
}
$detachList = array_merge($this->option('id'), $this->option('name'));
if (! method_exists($user, 'detachRole')) {
$this->warn("User not use HasRolesTrait!");
return 1;
}
$user->detachRole($detachList);
echo "Detached roles. Done!", PHP_EOL;
return 0;
} | php | public function handle()
{
$id = $this->argument('id');
try {
$user = $this->prepareUser($id);
} catch (Exception $e) {
$this->warn($e->getMessage());
return 1;
}
$detachList = array_merge($this->option('id'), $this->option('name'));
if (! method_exists($user, 'detachRole')) {
$this->warn("User not use HasRolesTrait!");
return 1;
}
$user->detachRole($detachList);
echo "Detached roles. Done!", PHP_EOL;
return 0;
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"argument",
"(",
"'id'",
")",
";",
"try",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"prepareUser",
"(",
"$",
"id",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"warn",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"return",
"1",
";",
"}",
"$",
"detachList",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"option",
"(",
"'id'",
")",
",",
"$",
"this",
"->",
"option",
"(",
"'name'",
")",
")",
";",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"user",
",",
"'detachRole'",
")",
")",
"{",
"$",
"this",
"->",
"warn",
"(",
"\"User not use HasRolesTrait!\"",
")",
";",
"return",
"1",
";",
"}",
"$",
"user",
"->",
"detachRole",
"(",
"$",
"detachList",
")",
";",
"echo",
"\"Detached roles. Done!\"",
",",
"PHP_EOL",
";",
"return",
"0",
";",
"}"
] | Execute the console command.
@return mixed | [
"Execute",
"the",
"console",
"command",
"."
] | train | https://github.com/mustardandrew/muan-laravel-acl/blob/b5f23340b5536babb98d9fd0d727a7a3371c97d5/src/Commands/User/DetachRoleCommand.php#L39-L61 |
heidelpay/PhpDoc | src/phpDocumentor/Console/Output/Output.php | Output.writeTimedLog | public function writeTimedLog($message, $operation, array $arguments = array())
{
$this->write(sprintf('%-66.66s .. ', $message));
$timerStart = microtime(true);
call_user_func_array($operation, $arguments);
$this->writeln(sprintf('%8.3fs', microtime(true) - $timerStart));
} | php | public function writeTimedLog($message, $operation, array $arguments = array())
{
$this->write(sprintf('%-66.66s .. ', $message));
$timerStart = microtime(true);
call_user_func_array($operation, $arguments);
$this->writeln(sprintf('%8.3fs', microtime(true) - $timerStart));
} | [
"public",
"function",
"writeTimedLog",
"(",
"$",
"message",
",",
"$",
"operation",
",",
"array",
"$",
"arguments",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"write",
"(",
"sprintf",
"(",
"'%-66.66s .. '",
",",
"$",
"message",
")",
")",
";",
"$",
"timerStart",
"=",
"microtime",
"(",
"true",
")",
";",
"call_user_func_array",
"(",
"$",
"operation",
",",
"$",
"arguments",
")",
";",
"$",
"this",
"->",
"writeln",
"(",
"sprintf",
"(",
"'%8.3fs'",
",",
"microtime",
"(",
"true",
")",
"-",
"$",
"timerStart",
")",
")",
";",
"}"
] | Executes a callable piece of code and writes an entry to the log detailing how long it took.
@param string $message
@param callable $operation
@param array $arguments
@return void | [
"Executes",
"a",
"callable",
"piece",
"of",
"code",
"and",
"writes",
"an",
"entry",
"to",
"the",
"log",
"detailing",
"how",
"long",
"it",
"took",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Console/Output/Output.php#L54-L62 |
heidelpay/PhpDoc | src/phpDocumentor/Console/Output/Output.php | Output.write | public function write($message, $newline = false, $type = 0)
{
$messages = (array) $message;
if ($this->getLogger()) {
foreach ($messages as $message) {
$this->getLogger()->info($this->getFormatter()->format(strip_tags($message)));
}
}
parent::write($messages, $newline, $type);
} | php | public function write($message, $newline = false, $type = 0)
{
$messages = (array) $message;
if ($this->getLogger()) {
foreach ($messages as $message) {
$this->getLogger()->info($this->getFormatter()->format(strip_tags($message)));
}
}
parent::write($messages, $newline, $type);
} | [
"public",
"function",
"write",
"(",
"$",
"message",
",",
"$",
"newline",
"=",
"false",
",",
"$",
"type",
"=",
"0",
")",
"{",
"$",
"messages",
"=",
"(",
"array",
")",
"$",
"message",
";",
"if",
"(",
"$",
"this",
"->",
"getLogger",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"messages",
"as",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"info",
"(",
"$",
"this",
"->",
"getFormatter",
"(",
")",
"->",
"format",
"(",
"strip_tags",
"(",
"$",
"message",
")",
")",
")",
";",
"}",
"}",
"parent",
"::",
"write",
"(",
"$",
"messages",
",",
"$",
"newline",
",",
"$",
"type",
")",
";",
"}"
] | Write an entry to the console and to the provided logger.
@param array|string $message
@param bool $newline
@param int $type
@return void | [
"Write",
"an",
"entry",
"to",
"the",
"console",
"and",
"to",
"the",
"provided",
"logger",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Console/Output/Output.php#L73-L84 |
ronaldborla/chikka | src/Borla/Chikka/Base/Model.php | Model.getAttribute | public function getAttribute($name) {
// Check first if mutator exists
$mutator = 'get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $name))) . 'Attribute';
// Check if method exists
if (method_exists($this, $mutator)) {
// Use it
return $this->$mutator();
}
// If set
if (array_key_exists($name, $this->attributes)) {
// Return
return $this->attributes[$name];
}
} | php | public function getAttribute($name) {
// Check first if mutator exists
$mutator = 'get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $name))) . 'Attribute';
// Check if method exists
if (method_exists($this, $mutator)) {
// Use it
return $this->$mutator();
}
// If set
if (array_key_exists($name, $this->attributes)) {
// Return
return $this->attributes[$name];
}
} | [
"public",
"function",
"getAttribute",
"(",
"$",
"name",
")",
"{",
"// Check first if mutator exists",
"$",
"mutator",
"=",
"'get'",
".",
"str_replace",
"(",
"' '",
",",
"''",
",",
"ucwords",
"(",
"str_replace",
"(",
"'_'",
",",
"' '",
",",
"$",
"name",
")",
")",
")",
".",
"'Attribute'",
";",
"// Check if method exists",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"mutator",
")",
")",
"{",
"// Use it",
"return",
"$",
"this",
"->",
"$",
"mutator",
"(",
")",
";",
"}",
"// If set",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"attributes",
")",
")",
"{",
"// Return",
"return",
"$",
"this",
"->",
"attributes",
"[",
"$",
"name",
"]",
";",
"}",
"}"
] | Get attribute | [
"Get",
"attribute"
] | train | https://github.com/ronaldborla/chikka/blob/446987706f81d5a0efbc8bd6b7d3b259d0527719/src/Borla/Chikka/Base/Model.php#L43-L56 |
ronaldborla/chikka | src/Borla/Chikka/Base/Model.php | Model.set | public function set($nameOrAttributes, $value = false) {
// Use set attributes
if ( ! is_array($nameOrAttributes) && $value !== false) {
// Set name in attributes
$nameOrAttributes = [
$nameOrAttributes=> $value
];
}
// Return with set attributes
return $this->setAttributes($nameOrAttributes);
} | php | public function set($nameOrAttributes, $value = false) {
// Use set attributes
if ( ! is_array($nameOrAttributes) && $value !== false) {
// Set name in attributes
$nameOrAttributes = [
$nameOrAttributes=> $value
];
}
// Return with set attributes
return $this->setAttributes($nameOrAttributes);
} | [
"public",
"function",
"set",
"(",
"$",
"nameOrAttributes",
",",
"$",
"value",
"=",
"false",
")",
"{",
"// Use set attributes",
"if",
"(",
"!",
"is_array",
"(",
"$",
"nameOrAttributes",
")",
"&&",
"$",
"value",
"!==",
"false",
")",
"{",
"// Set name in attributes",
"$",
"nameOrAttributes",
"=",
"[",
"$",
"nameOrAttributes",
"=>",
"$",
"value",
"]",
";",
"}",
"// Return with set attributes",
"return",
"$",
"this",
"->",
"setAttributes",
"(",
"$",
"nameOrAttributes",
")",
";",
"}"
] | Use set | [
"Use",
"set"
] | train | https://github.com/ronaldborla/chikka/blob/446987706f81d5a0efbc8bd6b7d3b259d0527719/src/Borla/Chikka/Base/Model.php#L69-L79 |
ronaldborla/chikka | src/Borla/Chikka/Base/Model.php | Model.setAttribute | public function setAttribute($name, $value) {
// Check first if mutator exists
$mutator = 'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $name))) . 'Attribute';
// Check if method exists
if (method_exists($this, $mutator)) {
// Use it
$value = call_user_func_array(array($this, $mutator), [$value]);
}
// If there's a callback
if (method_exists($this, 'onSetAttribute')) {
// Call
call_user_func_array(array($this, 'onSetAttribute'), [$name, $value]);
}
// Set this attribute
$this->attributes[$name] = $value;
} | php | public function setAttribute($name, $value) {
// Check first if mutator exists
$mutator = 'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $name))) . 'Attribute';
// Check if method exists
if (method_exists($this, $mutator)) {
// Use it
$value = call_user_func_array(array($this, $mutator), [$value]);
}
// If there's a callback
if (method_exists($this, 'onSetAttribute')) {
// Call
call_user_func_array(array($this, 'onSetAttribute'), [$name, $value]);
}
// Set this attribute
$this->attributes[$name] = $value;
} | [
"public",
"function",
"setAttribute",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"// Check first if mutator exists",
"$",
"mutator",
"=",
"'set'",
".",
"str_replace",
"(",
"' '",
",",
"''",
",",
"ucwords",
"(",
"str_replace",
"(",
"'_'",
",",
"' '",
",",
"$",
"name",
")",
")",
")",
".",
"'Attribute'",
";",
"// Check if method exists",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"mutator",
")",
")",
"{",
"// Use it",
"$",
"value",
"=",
"call_user_func_array",
"(",
"array",
"(",
"$",
"this",
",",
"$",
"mutator",
")",
",",
"[",
"$",
"value",
"]",
")",
";",
"}",
"// If there's a callback",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"'onSetAttribute'",
")",
")",
"{",
"// Call",
"call_user_func_array",
"(",
"array",
"(",
"$",
"this",
",",
"'onSetAttribute'",
")",
",",
"[",
"$",
"name",
",",
"$",
"value",
"]",
")",
";",
"}",
"// Set this attribute",
"$",
"this",
"->",
"attributes",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}"
] | Set attribute | [
"Set",
"attribute"
] | train | https://github.com/ronaldborla/chikka/blob/446987706f81d5a0efbc8bd6b7d3b259d0527719/src/Borla/Chikka/Base/Model.php#L84-L101 |
ronaldborla/chikka | src/Borla/Chikka/Base/Model.php | Model.toArray | public function toArray() {
// Set array
$array = [];
// Loop through attributes
foreach ($this->getAttributes() as $key=> $attribute) {
// If attribute has toArray() method
if (is_object($attribute) && method_exists($attribute, 'toArray')) {
// Set array
$array[$key] = $attribute->toArray();
}
// If can be converted to string
elseif (is_object($attribute) && method_exists($attribute, '__toString')) {
// Convert to string
$array[$key] = (string) $attribute;
}
// Otherwise
else {
// Simply add to array
$array[$key] = $attribute;
}
}
// Return
return $array;
} | php | public function toArray() {
// Set array
$array = [];
// Loop through attributes
foreach ($this->getAttributes() as $key=> $attribute) {
// If attribute has toArray() method
if (is_object($attribute) && method_exists($attribute, 'toArray')) {
// Set array
$array[$key] = $attribute->toArray();
}
// If can be converted to string
elseif (is_object($attribute) && method_exists($attribute, '__toString')) {
// Convert to string
$array[$key] = (string) $attribute;
}
// Otherwise
else {
// Simply add to array
$array[$key] = $attribute;
}
}
// Return
return $array;
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"// Set array",
"$",
"array",
"=",
"[",
"]",
";",
"// Loop through attributes",
"foreach",
"(",
"$",
"this",
"->",
"getAttributes",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"attribute",
")",
"{",
"// If attribute has toArray() method",
"if",
"(",
"is_object",
"(",
"$",
"attribute",
")",
"&&",
"method_exists",
"(",
"$",
"attribute",
",",
"'toArray'",
")",
")",
"{",
"// Set array",
"$",
"array",
"[",
"$",
"key",
"]",
"=",
"$",
"attribute",
"->",
"toArray",
"(",
")",
";",
"}",
"// If can be converted to string",
"elseif",
"(",
"is_object",
"(",
"$",
"attribute",
")",
"&&",
"method_exists",
"(",
"$",
"attribute",
",",
"'__toString'",
")",
")",
"{",
"// Convert to string",
"$",
"array",
"[",
"$",
"key",
"]",
"=",
"(",
"string",
")",
"$",
"attribute",
";",
"}",
"// Otherwise",
"else",
"{",
"// Simply add to array",
"$",
"array",
"[",
"$",
"key",
"]",
"=",
"$",
"attribute",
";",
"}",
"}",
"// Return",
"return",
"$",
"array",
";",
"}"
] | To array | [
"To",
"array"
] | train | https://github.com/ronaldborla/chikka/blob/446987706f81d5a0efbc8bd6b7d3b259d0527719/src/Borla/Chikka/Base/Model.php#L119-L142 |
expectation-php/expect | src/matcher/PatternMatcher.php | PatternMatcher.match | public function match($actual)
{
$this->actual = $actual;
return (preg_match($this->expected, $this->actual) === 1);
} | php | public function match($actual)
{
$this->actual = $actual;
return (preg_match($this->expected, $this->actual) === 1);
} | [
"public",
"function",
"match",
"(",
"$",
"actual",
")",
"{",
"$",
"this",
"->",
"actual",
"=",
"$",
"actual",
";",
"return",
"(",
"preg_match",
"(",
"$",
"this",
"->",
"expected",
",",
"$",
"this",
"->",
"actual",
")",
"===",
"1",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/expectation-php/expect/blob/1a32c5af37f3dc8dabe4e8eedeeb21aea16ce139/src/matcher/PatternMatcher.php#L41-L46 |
interactivesolutions/honeycomb-core | src/http/controllers/HCCoreFormValidator.php | HCCoreFormValidator.validateForm | public function validateForm()
{
$validator = $this->getValidationFactory()->make(
$this->requestData(),
$this->rules()
);
if ($validator->fails())
throw new \Exception($this->formatErrors($validator->errors()));
} | php | public function validateForm()
{
$validator = $this->getValidationFactory()->make(
$this->requestData(),
$this->rules()
);
if ($validator->fails())
throw new \Exception($this->formatErrors($validator->errors()));
} | [
"public",
"function",
"validateForm",
"(",
")",
"{",
"$",
"validator",
"=",
"$",
"this",
"->",
"getValidationFactory",
"(",
")",
"->",
"make",
"(",
"$",
"this",
"->",
"requestData",
"(",
")",
",",
"$",
"this",
"->",
"rules",
"(",
")",
")",
";",
"if",
"(",
"$",
"validator",
"->",
"fails",
"(",
")",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"this",
"->",
"formatErrors",
"(",
"$",
"validator",
"->",
"errors",
"(",
")",
")",
")",
";",
"}"
] | Validate form
@throws \Exception | [
"Validate",
"form"
] | train | https://github.com/interactivesolutions/honeycomb-core/blob/06b8d88bb285e73a1a286e60411ca5f41863f39f/src/http/controllers/HCCoreFormValidator.php#L39-L48 |
interactivesolutions/honeycomb-core | src/http/controllers/HCCoreFormValidator.php | HCCoreFormValidator.formatErrors | protected function formatErrors(string $errors)
{
$errors = json_decode($errors);
$output = '';
foreach ($errors as $error)
foreach ($error as $message)
$output .= $message . "\r\n";
return $output;
} | php | protected function formatErrors(string $errors)
{
$errors = json_decode($errors);
$output = '';
foreach ($errors as $error)
foreach ($error as $message)
$output .= $message . "\r\n";
return $output;
} | [
"protected",
"function",
"formatErrors",
"(",
"string",
"$",
"errors",
")",
"{",
"$",
"errors",
"=",
"json_decode",
"(",
"$",
"errors",
")",
";",
"$",
"output",
"=",
"''",
";",
"foreach",
"(",
"$",
"errors",
"as",
"$",
"error",
")",
"foreach",
"(",
"$",
"error",
"as",
"$",
"message",
")",
"$",
"output",
".=",
"$",
"message",
".",
"\"\\r\\n\"",
";",
"return",
"$",
"output",
";",
"}"
] | Must return string!!
@param string $errors
@return mixed | [
"Must",
"return",
"string!!"
] | train | https://github.com/interactivesolutions/honeycomb-core/blob/06b8d88bb285e73a1a286e60411ca5f41863f39f/src/http/controllers/HCCoreFormValidator.php#L95-L105 |
php-lug/lug | src/Component/Grid/Filter/Type/BooleanType.php | BooleanType.process | protected function process($field, $data, array $options)
{
$builder = $options['builder'];
return $builder->getExpressionBuilder()->eq(
$builder->getProperty($field),
$builder->createPlaceholder($field, $data)
);
} | php | protected function process($field, $data, array $options)
{
$builder = $options['builder'];
return $builder->getExpressionBuilder()->eq(
$builder->getProperty($field),
$builder->createPlaceholder($field, $data)
);
} | [
"protected",
"function",
"process",
"(",
"$",
"field",
",",
"$",
"data",
",",
"array",
"$",
"options",
")",
"{",
"$",
"builder",
"=",
"$",
"options",
"[",
"'builder'",
"]",
";",
"return",
"$",
"builder",
"->",
"getExpressionBuilder",
"(",
")",
"->",
"eq",
"(",
"$",
"builder",
"->",
"getProperty",
"(",
"$",
"field",
")",
",",
"$",
"builder",
"->",
"createPlaceholder",
"(",
"$",
"field",
",",
"$",
"data",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Filter/Type/BooleanType.php#L30-L38 |
bespoke-ws/blademanager | src/Services/BladeDirectiveManager.php | BladeDirectiveManager.register | public function register()
{
$this->registerFormGroupDirective();
$this->registerLabelDirective();
$this->registerStaticDirective();
// Form fields
$this->registerCheckboxDirective();
$this->registerDatePickerDirective();
$this->registerTimePickerDirective();
$this->registerInputDirective();
$this->registerSelectDirective();
$this->registerTextareaDirective();
// Buttons
$this->registerCreateButtonDirective();
$this->registerEditButtonDirective();
$this->registerShowButtonDirective();
$this->registerSaveButtonDirective();
$this->registerDeleteButtonDirective();
$this->registerBackButtonDirective();
} | php | public function register()
{
$this->registerFormGroupDirective();
$this->registerLabelDirective();
$this->registerStaticDirective();
// Form fields
$this->registerCheckboxDirective();
$this->registerDatePickerDirective();
$this->registerTimePickerDirective();
$this->registerInputDirective();
$this->registerSelectDirective();
$this->registerTextareaDirective();
// Buttons
$this->registerCreateButtonDirective();
$this->registerEditButtonDirective();
$this->registerShowButtonDirective();
$this->registerSaveButtonDirective();
$this->registerDeleteButtonDirective();
$this->registerBackButtonDirective();
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"registerFormGroupDirective",
"(",
")",
";",
"$",
"this",
"->",
"registerLabelDirective",
"(",
")",
";",
"$",
"this",
"->",
"registerStaticDirective",
"(",
")",
";",
"// Form fields",
"$",
"this",
"->",
"registerCheckboxDirective",
"(",
")",
";",
"$",
"this",
"->",
"registerDatePickerDirective",
"(",
")",
";",
"$",
"this",
"->",
"registerTimePickerDirective",
"(",
")",
";",
"$",
"this",
"->",
"registerInputDirective",
"(",
")",
";",
"$",
"this",
"->",
"registerSelectDirective",
"(",
")",
";",
"$",
"this",
"->",
"registerTextareaDirective",
"(",
")",
";",
"// Buttons",
"$",
"this",
"->",
"registerCreateButtonDirective",
"(",
")",
";",
"$",
"this",
"->",
"registerEditButtonDirective",
"(",
")",
";",
"$",
"this",
"->",
"registerShowButtonDirective",
"(",
")",
";",
"$",
"this",
"->",
"registerSaveButtonDirective",
"(",
")",
";",
"$",
"this",
"->",
"registerDeleteButtonDirective",
"(",
")",
";",
"$",
"this",
"->",
"registerBackButtonDirective",
"(",
")",
";",
"}"
] | Register the blade directives | [
"Register",
"the",
"blade",
"directives"
] | train | https://github.com/bespoke-ws/blademanager/blob/4bf358bfbcdde953415f7bebba7db5b40aca8a4c/src/Services/BladeDirectiveManager.php#L17-L38 |
ezsystems/ezcomments-ls-extension | classes/ezcompermission.php | ezcomPermission.hasFunctionAccess | public function hasFunctionAccess( $user, $functionName, $contentObject, $languageCode, $comment = null, $scope = null, $node = null )
{
$result = $user->hasAccessTo( self::$moduleName, $functionName );
if ( $result['accessWord'] !== 'limited' )
{
$return = ( $result['accessWord'] === 'yes' ) and ( $scope !== 'personal' );
}
else
{
foreach( $result['policies'] as $limitationArray )
{
// eZDebug::writeDebug( $limitationArray, "limitationArray for function $functionName" );
$return = true;
foreach( $limitationArray as $limitationKey => $limitation )
{
// deal with limitation checking
$resultItem = $this->checkPermission( $user, $limitationKey, $limitation,
$contentObject, $languageCode, $comment, $scope, $node );
ezDebugSetting::writeNotice( 'extension-ezcomments',
"Permission check result for function '$functionName' with limitation '$limitationKey': " . ( $resultItem === true ? 'true' : 'false' ), __METHOD__ );
$return = ( $return and $resultItem );
}
if ( $return === true )
break;
}
}
return $return;
} | php | public function hasFunctionAccess( $user, $functionName, $contentObject, $languageCode, $comment = null, $scope = null, $node = null )
{
$result = $user->hasAccessTo( self::$moduleName, $functionName );
if ( $result['accessWord'] !== 'limited' )
{
$return = ( $result['accessWord'] === 'yes' ) and ( $scope !== 'personal' );
}
else
{
foreach( $result['policies'] as $limitationArray )
{
// eZDebug::writeDebug( $limitationArray, "limitationArray for function $functionName" );
$return = true;
foreach( $limitationArray as $limitationKey => $limitation )
{
// deal with limitation checking
$resultItem = $this->checkPermission( $user, $limitationKey, $limitation,
$contentObject, $languageCode, $comment, $scope, $node );
ezDebugSetting::writeNotice( 'extension-ezcomments',
"Permission check result for function '$functionName' with limitation '$limitationKey': " . ( $resultItem === true ? 'true' : 'false' ), __METHOD__ );
$return = ( $return and $resultItem );
}
if ( $return === true )
break;
}
}
return $return;
} | [
"public",
"function",
"hasFunctionAccess",
"(",
"$",
"user",
",",
"$",
"functionName",
",",
"$",
"contentObject",
",",
"$",
"languageCode",
",",
"$",
"comment",
"=",
"null",
",",
"$",
"scope",
"=",
"null",
",",
"$",
"node",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"$",
"user",
"->",
"hasAccessTo",
"(",
"self",
"::",
"$",
"moduleName",
",",
"$",
"functionName",
")",
";",
"if",
"(",
"$",
"result",
"[",
"'accessWord'",
"]",
"!==",
"'limited'",
")",
"{",
"$",
"return",
"=",
"(",
"$",
"result",
"[",
"'accessWord'",
"]",
"===",
"'yes'",
")",
"and",
"(",
"$",
"scope",
"!==",
"'personal'",
")",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"result",
"[",
"'policies'",
"]",
"as",
"$",
"limitationArray",
")",
"{",
"// eZDebug::writeDebug( $limitationArray, \"limitationArray for function $functionName\" );",
"$",
"return",
"=",
"true",
";",
"foreach",
"(",
"$",
"limitationArray",
"as",
"$",
"limitationKey",
"=>",
"$",
"limitation",
")",
"{",
"// deal with limitation checking",
"$",
"resultItem",
"=",
"$",
"this",
"->",
"checkPermission",
"(",
"$",
"user",
",",
"$",
"limitationKey",
",",
"$",
"limitation",
",",
"$",
"contentObject",
",",
"$",
"languageCode",
",",
"$",
"comment",
",",
"$",
"scope",
",",
"$",
"node",
")",
";",
"ezDebugSetting",
"::",
"writeNotice",
"(",
"'extension-ezcomments'",
",",
"\"Permission check result for function '$functionName' with limitation '$limitationKey': \"",
".",
"(",
"$",
"resultItem",
"===",
"true",
"?",
"'true'",
":",
"'false'",
")",
",",
"__METHOD__",
")",
";",
"$",
"return",
"=",
"(",
"$",
"return",
"and",
"$",
"resultItem",
")",
";",
"}",
"if",
"(",
"$",
"return",
"===",
"true",
")",
"break",
";",
"}",
"}",
"return",
"$",
"return",
";",
"}"
] | check if the user has Acceess to the object with limitation of class, section, owner, language, nodes, subtrees
return true if has, false if not | [
"check",
"if",
"the",
"user",
"has",
"Acceess",
"to",
"the",
"object",
"with",
"limitation",
"of",
"class",
"section",
"owner",
"language",
"nodes",
"subtrees"
] | train | https://github.com/ezsystems/ezcomments-ls-extension/blob/2b4cd8c34d4a77813e4d6a9c5a0d317a274c63c5/classes/ezcompermission.php#L28-L58 |
ezsystems/ezcomments-ls-extension | classes/ezcompermission.php | ezcomPermission.checkPermission | protected function checkPermission( $user, $limitationKey, $limitation, $contentObject, $languageCode, $comment = null, $scope = null, $node = null )
{
switch( $limitationKey )
{
// section limited policy
case self::$sectionKey:
case self::$userSectionKey:
// this does not match when looking for personal policies
if ( $scope == 'personal' )
return false;
$contentSectionID = $contentObject->attribute( 'section_id' );
return in_array( $contentSectionID, $limitation );
// owner limited policy
case self::$commentCreatorKey:
// this does not match when looking for role wide policies
if ( $scope == 'role' )
return false;
if ( $user->isAnonymous() )
{
return false;
}
else
{
$userID = $user->attribute( 'contentobject_id' );
$commentUserID = $comment->attribute( 'user_id' );
return ( $userID == $commentUserID );
}
// role assignment by subtree limitation
case self::$subtreeKey:
if ( !( $node instanceof eZContentObjectTreeNode ) )
{
return false;
}
else
{
foreach( $limitation as $subtree )
{
if ( strpos( $node->attribute( 'path_string' ), $subtree ) === 0 )
{
return true;
}
}
return false;
}
default:
return false;
}
} | php | protected function checkPermission( $user, $limitationKey, $limitation, $contentObject, $languageCode, $comment = null, $scope = null, $node = null )
{
switch( $limitationKey )
{
// section limited policy
case self::$sectionKey:
case self::$userSectionKey:
// this does not match when looking for personal policies
if ( $scope == 'personal' )
return false;
$contentSectionID = $contentObject->attribute( 'section_id' );
return in_array( $contentSectionID, $limitation );
// owner limited policy
case self::$commentCreatorKey:
// this does not match when looking for role wide policies
if ( $scope == 'role' )
return false;
if ( $user->isAnonymous() )
{
return false;
}
else
{
$userID = $user->attribute( 'contentobject_id' );
$commentUserID = $comment->attribute( 'user_id' );
return ( $userID == $commentUserID );
}
// role assignment by subtree limitation
case self::$subtreeKey:
if ( !( $node instanceof eZContentObjectTreeNode ) )
{
return false;
}
else
{
foreach( $limitation as $subtree )
{
if ( strpos( $node->attribute( 'path_string' ), $subtree ) === 0 )
{
return true;
}
}
return false;
}
default:
return false;
}
} | [
"protected",
"function",
"checkPermission",
"(",
"$",
"user",
",",
"$",
"limitationKey",
",",
"$",
"limitation",
",",
"$",
"contentObject",
",",
"$",
"languageCode",
",",
"$",
"comment",
"=",
"null",
",",
"$",
"scope",
"=",
"null",
",",
"$",
"node",
"=",
"null",
")",
"{",
"switch",
"(",
"$",
"limitationKey",
")",
"{",
"// section limited policy",
"case",
"self",
"::",
"$",
"sectionKey",
":",
"case",
"self",
"::",
"$",
"userSectionKey",
":",
"// this does not match when looking for personal policies",
"if",
"(",
"$",
"scope",
"==",
"'personal'",
")",
"return",
"false",
";",
"$",
"contentSectionID",
"=",
"$",
"contentObject",
"->",
"attribute",
"(",
"'section_id'",
")",
";",
"return",
"in_array",
"(",
"$",
"contentSectionID",
",",
"$",
"limitation",
")",
";",
"// owner limited policy",
"case",
"self",
"::",
"$",
"commentCreatorKey",
":",
"// this does not match when looking for role wide policies",
"if",
"(",
"$",
"scope",
"==",
"'role'",
")",
"return",
"false",
";",
"if",
"(",
"$",
"user",
"->",
"isAnonymous",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"userID",
"=",
"$",
"user",
"->",
"attribute",
"(",
"'contentobject_id'",
")",
";",
"$",
"commentUserID",
"=",
"$",
"comment",
"->",
"attribute",
"(",
"'user_id'",
")",
";",
"return",
"(",
"$",
"userID",
"==",
"$",
"commentUserID",
")",
";",
"}",
"// role assignment by subtree limitation",
"case",
"self",
"::",
"$",
"subtreeKey",
":",
"if",
"(",
"!",
"(",
"$",
"node",
"instanceof",
"eZContentObjectTreeNode",
")",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"limitation",
"as",
"$",
"subtree",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"node",
"->",
"attribute",
"(",
"'path_string'",
")",
",",
"$",
"subtree",
")",
"===",
"0",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}",
"default",
":",
"return",
"false",
";",
"}",
"}"
] | Check the permission given user contentobject, language and comment(optional)
To extend the permission checking, please extend the class and override this method
@param $user
@param $limitationKey key name of the limitiation, for instance 'Language'
@param $limitation limitation array, for instance '{eng-GB,nor-NO}'
@param $contentObject contentobject of the comments
@param $languageCode language code of the content object
@param $comment comment object if the permaission is based on one comment.When the permission checking is for editing and delete, it's useful
@return true if the checking result is true, false otherwise | [
"Check",
"the",
"permission",
"given",
"user",
"contentobject",
"language",
"and",
"comment",
"(",
"optional",
")",
"To",
"extend",
"the",
"permission",
"checking",
"please",
"extend",
"the",
"class",
"and",
"override",
"this",
"method"
] | train | https://github.com/ezsystems/ezcomments-ls-extension/blob/2b4cd8c34d4a77813e4d6a9c5a0d317a274c63c5/classes/ezcompermission.php#L71-L122 |
ezsystems/ezcomments-ls-extension | classes/ezcompermission.php | ezcomPermission.selfPolicies | public static function selfPolicies( $contentObject )
{
$return = array( 'edit' => false, 'delete' => false );
$sectionID = $contentObject->attribute( 'section_id' );
$user = eZUser::currentUser();
foreach( array_keys( $return ) as $functionName )
{
$policies = $user->hasAccessTo( self::$moduleName, $functionName );
// unlimited policy, not personal
if ( $policies['accessWord'] !== 'limited' )
{
$return[$functionName] = false;
}
else
{
// scan limited policies
foreach( $policies['policies'] as $limitationArray )
{
// a self limitation exists
if ( isset( $limitationArray[self::$commentCreatorKey] ) )
{
// but it also has a section limitation
if ( isset( $limitationArray[self::$sectionKey] ) )
{
if ( in_array( $sectionID, $limitationArray[self::$sectionKey] ) )
{
$return[$functionName] = true;
break;
}
}
else
{
$return[$functionName] = true;
break;
}
}
}
}
}
return array( 'result' => $return );
} | php | public static function selfPolicies( $contentObject )
{
$return = array( 'edit' => false, 'delete' => false );
$sectionID = $contentObject->attribute( 'section_id' );
$user = eZUser::currentUser();
foreach( array_keys( $return ) as $functionName )
{
$policies = $user->hasAccessTo( self::$moduleName, $functionName );
// unlimited policy, not personal
if ( $policies['accessWord'] !== 'limited' )
{
$return[$functionName] = false;
}
else
{
// scan limited policies
foreach( $policies['policies'] as $limitationArray )
{
// a self limitation exists
if ( isset( $limitationArray[self::$commentCreatorKey] ) )
{
// but it also has a section limitation
if ( isset( $limitationArray[self::$sectionKey] ) )
{
if ( in_array( $sectionID, $limitationArray[self::$sectionKey] ) )
{
$return[$functionName] = true;
break;
}
}
else
{
$return[$functionName] = true;
break;
}
}
}
}
}
return array( 'result' => $return );
} | [
"public",
"static",
"function",
"selfPolicies",
"(",
"$",
"contentObject",
")",
"{",
"$",
"return",
"=",
"array",
"(",
"'edit'",
"=>",
"false",
",",
"'delete'",
"=>",
"false",
")",
";",
"$",
"sectionID",
"=",
"$",
"contentObject",
"->",
"attribute",
"(",
"'section_id'",
")",
";",
"$",
"user",
"=",
"eZUser",
"::",
"currentUser",
"(",
")",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"return",
")",
"as",
"$",
"functionName",
")",
"{",
"$",
"policies",
"=",
"$",
"user",
"->",
"hasAccessTo",
"(",
"self",
"::",
"$",
"moduleName",
",",
"$",
"functionName",
")",
";",
"// unlimited policy, not personal",
"if",
"(",
"$",
"policies",
"[",
"'accessWord'",
"]",
"!==",
"'limited'",
")",
"{",
"$",
"return",
"[",
"$",
"functionName",
"]",
"=",
"false",
";",
"}",
"else",
"{",
"// scan limited policies",
"foreach",
"(",
"$",
"policies",
"[",
"'policies'",
"]",
"as",
"$",
"limitationArray",
")",
"{",
"// a self limitation exists",
"if",
"(",
"isset",
"(",
"$",
"limitationArray",
"[",
"self",
"::",
"$",
"commentCreatorKey",
"]",
")",
")",
"{",
"// but it also has a section limitation",
"if",
"(",
"isset",
"(",
"$",
"limitationArray",
"[",
"self",
"::",
"$",
"sectionKey",
"]",
")",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"sectionID",
",",
"$",
"limitationArray",
"[",
"self",
"::",
"$",
"sectionKey",
"]",
")",
")",
"{",
"$",
"return",
"[",
"$",
"functionName",
"]",
"=",
"true",
";",
"break",
";",
"}",
"}",
"else",
"{",
"$",
"return",
"[",
"$",
"functionName",
"]",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"array",
"(",
"'result'",
"=>",
"$",
"return",
")",
";",
"}"
] | Checks if the current user has a 'self' edit/delete policy
@param eZContentObject $contentObject Used to check with a possible section
@return array An array with edit and delete as keys, and booleans as values | [
"Checks",
"if",
"the",
"current",
"user",
"has",
"a",
"self",
"edit",
"/",
"delete",
"policy"
] | train | https://github.com/ezsystems/ezcomments-ls-extension/blob/2b4cd8c34d4a77813e4d6a9c5a0d317a274c63c5/classes/ezcompermission.php#L131-L174 |
alevilar/ristorantino-vendor | Stats/Controller/QueriesController.php | QueriesController.contruye_excel | function contruye_excel($id){
$this->layout = 'excel';
Configure::write('debug',0);
$this->RequestHandler->setContent('xls', 'application/vnd.ms-excel');
$res = $this->Query->findById($id);
$sql = $res['Query']['query'];
$this->Query->recursive = -1;
$consulta_ejecutada = $this->Query->query($sql);
$precols = array_keys($consulta_ejecutada[0]);
$quitar_columnas = $consulta_ejecutada[0][0];
while(list($key,$value) = each($quitar_columnas)):
$columnas[] = $key;
endwhile;
$this->set('nombre',$res['Query']['name']);
$this->set('columnas',$columnas);
$this->set('filas',$consulta_ejecutada);
} | php | function contruye_excel($id){
$this->layout = 'excel';
Configure::write('debug',0);
$this->RequestHandler->setContent('xls', 'application/vnd.ms-excel');
$res = $this->Query->findById($id);
$sql = $res['Query']['query'];
$this->Query->recursive = -1;
$consulta_ejecutada = $this->Query->query($sql);
$precols = array_keys($consulta_ejecutada[0]);
$quitar_columnas = $consulta_ejecutada[0][0];
while(list($key,$value) = each($quitar_columnas)):
$columnas[] = $key;
endwhile;
$this->set('nombre',$res['Query']['name']);
$this->set('columnas',$columnas);
$this->set('filas',$consulta_ejecutada);
} | [
"function",
"contruye_excel",
"(",
"$",
"id",
")",
"{",
"$",
"this",
"->",
"layout",
"=",
"'excel'",
";",
"Configure",
"::",
"write",
"(",
"'debug'",
",",
"0",
")",
";",
"$",
"this",
"->",
"RequestHandler",
"->",
"setContent",
"(",
"'xls'",
",",
"'application/vnd.ms-excel'",
")",
";",
"$",
"res",
"=",
"$",
"this",
"->",
"Query",
"->",
"findById",
"(",
"$",
"id",
")",
";",
"$",
"sql",
"=",
"$",
"res",
"[",
"'Query'",
"]",
"[",
"'query'",
"]",
";",
"$",
"this",
"->",
"Query",
"->",
"recursive",
"=",
"-",
"1",
";",
"$",
"consulta_ejecutada",
"=",
"$",
"this",
"->",
"Query",
"->",
"query",
"(",
"$",
"sql",
")",
";",
"$",
"precols",
"=",
"array_keys",
"(",
"$",
"consulta_ejecutada",
"[",
"0",
"]",
")",
";",
"$",
"quitar_columnas",
"=",
"$",
"consulta_ejecutada",
"[",
"0",
"]",
"[",
"0",
"]",
";",
"while",
"(",
"list",
"(",
"$",
"key",
",",
"$",
"value",
")",
"=",
"each",
"(",
"$",
"quitar_columnas",
")",
")",
":",
"$",
"columnas",
"[",
"]",
"=",
"$",
"key",
";",
"endwhile",
";",
"$",
"this",
"->",
"set",
"(",
"'nombre'",
",",
"$",
"res",
"[",
"'Query'",
"]",
"[",
"'name'",
"]",
")",
";",
"$",
"this",
"->",
"set",
"(",
"'columnas'",
",",
"$",
"columnas",
")",
";",
"$",
"this",
"->",
"set",
"(",
"'filas'",
",",
"$",
"consulta_ejecutada",
")",
";",
"}"
] | esto me construye un excel en la vista con el id de la query
@param $id | [
"esto",
"me",
"construye",
"un",
"excel",
"en",
"la",
"vista",
"con",
"el",
"id",
"de",
"la",
"query"
] | train | https://github.com/alevilar/ristorantino-vendor/blob/6b91a1e20cc0ba09a1968d77e3de6512cfa2d966/Stats/Controller/QueriesController.php#L94-L114 |
hametuha/wpametu | src/WPametu/DB/TableBuilder.php | TableBuilder.db_update | private function db_update( $file ){
require $file;
if( isset($table) ){
// Test required members
$config = wp_parse_args($table, [
'name' => str_replace('.php', '', basename($file)),
'version' => false,
'engine' => Engine::INNODB,
'columns' => false,
'primary_key' => [],
'indexes' => [],
'unique' => [],
'fulltext' => [],
]);
$table_name = $config['name'];
if( $config['name'] && $config['version'] && $config['indexes'] ){
if( $this->need_update($table_name, $config['version']) ){
// Add prefix
$config['name'] = $this->db->prefix.$config['name'];
// Need update. Let's make query!
$query = $this->make_query($config);
if( !function_exists('dbDelta') ){
require_once ABSPATH . "wp-admin/includes/upgrade.php";
}
// Do dbDelta
$result = dbDelta($query);
// Return message
if( isset( $result[$config['name']] ) ){
$message = sprintf('<code>%s</code> created.', $config['name']);
}else{
$message = sprintf('<code>%s</code> updated.', $config['name']);
}
if( !empty($this->db->last_error) ){
$message .= sprintf(' <small>(Error: %s)</small>', $this->db->last_error);
}
// Check table existence
if( $this->table_exists($config['name']) ){
update_option($this->option_key, array_merge($this->option, [
$table_name => $config['version'],
]));
}else{
$message = sprintf('Failed to create or update <code>%s</code>', $config['name']);
}
return $message;
}
}else{
throw new \Exception(sprintf('Config file %s is wrong.', $file));
}
}else{
throw new \Exception(sprintf('Config file %s must be PHP Array format.', $file));
}
return '';
} | php | private function db_update( $file ){
require $file;
if( isset($table) ){
// Test required members
$config = wp_parse_args($table, [
'name' => str_replace('.php', '', basename($file)),
'version' => false,
'engine' => Engine::INNODB,
'columns' => false,
'primary_key' => [],
'indexes' => [],
'unique' => [],
'fulltext' => [],
]);
$table_name = $config['name'];
if( $config['name'] && $config['version'] && $config['indexes'] ){
if( $this->need_update($table_name, $config['version']) ){
// Add prefix
$config['name'] = $this->db->prefix.$config['name'];
// Need update. Let's make query!
$query = $this->make_query($config);
if( !function_exists('dbDelta') ){
require_once ABSPATH . "wp-admin/includes/upgrade.php";
}
// Do dbDelta
$result = dbDelta($query);
// Return message
if( isset( $result[$config['name']] ) ){
$message = sprintf('<code>%s</code> created.', $config['name']);
}else{
$message = sprintf('<code>%s</code> updated.', $config['name']);
}
if( !empty($this->db->last_error) ){
$message .= sprintf(' <small>(Error: %s)</small>', $this->db->last_error);
}
// Check table existence
if( $this->table_exists($config['name']) ){
update_option($this->option_key, array_merge($this->option, [
$table_name => $config['version'],
]));
}else{
$message = sprintf('Failed to create or update <code>%s</code>', $config['name']);
}
return $message;
}
}else{
throw new \Exception(sprintf('Config file %s is wrong.', $file));
}
}else{
throw new \Exception(sprintf('Config file %s must be PHP Array format.', $file));
}
return '';
} | [
"private",
"function",
"db_update",
"(",
"$",
"file",
")",
"{",
"require",
"$",
"file",
";",
"if",
"(",
"isset",
"(",
"$",
"table",
")",
")",
"{",
"// Test required members",
"$",
"config",
"=",
"wp_parse_args",
"(",
"$",
"table",
",",
"[",
"'name'",
"=>",
"str_replace",
"(",
"'.php'",
",",
"''",
",",
"basename",
"(",
"$",
"file",
")",
")",
",",
"'version'",
"=>",
"false",
",",
"'engine'",
"=>",
"Engine",
"::",
"INNODB",
",",
"'columns'",
"=>",
"false",
",",
"'primary_key'",
"=>",
"[",
"]",
",",
"'indexes'",
"=>",
"[",
"]",
",",
"'unique'",
"=>",
"[",
"]",
",",
"'fulltext'",
"=>",
"[",
"]",
",",
"]",
")",
";",
"$",
"table_name",
"=",
"$",
"config",
"[",
"'name'",
"]",
";",
"if",
"(",
"$",
"config",
"[",
"'name'",
"]",
"&&",
"$",
"config",
"[",
"'version'",
"]",
"&&",
"$",
"config",
"[",
"'indexes'",
"]",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"need_update",
"(",
"$",
"table_name",
",",
"$",
"config",
"[",
"'version'",
"]",
")",
")",
"{",
"// Add prefix",
"$",
"config",
"[",
"'name'",
"]",
"=",
"$",
"this",
"->",
"db",
"->",
"prefix",
".",
"$",
"config",
"[",
"'name'",
"]",
";",
"// Need update. Let's make query!",
"$",
"query",
"=",
"$",
"this",
"->",
"make_query",
"(",
"$",
"config",
")",
";",
"if",
"(",
"!",
"function_exists",
"(",
"'dbDelta'",
")",
")",
"{",
"require_once",
"ABSPATH",
".",
"\"wp-admin/includes/upgrade.php\"",
";",
"}",
"// Do dbDelta",
"$",
"result",
"=",
"dbDelta",
"(",
"$",
"query",
")",
";",
"// Return message",
"if",
"(",
"isset",
"(",
"$",
"result",
"[",
"$",
"config",
"[",
"'name'",
"]",
"]",
")",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'<code>%s</code> created.'",
",",
"$",
"config",
"[",
"'name'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'<code>%s</code> updated.'",
",",
"$",
"config",
"[",
"'name'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"db",
"->",
"last_error",
")",
")",
"{",
"$",
"message",
".=",
"sprintf",
"(",
"' <small>(Error: %s)</small>'",
",",
"$",
"this",
"->",
"db",
"->",
"last_error",
")",
";",
"}",
"// Check table existence",
"if",
"(",
"$",
"this",
"->",
"table_exists",
"(",
"$",
"config",
"[",
"'name'",
"]",
")",
")",
"{",
"update_option",
"(",
"$",
"this",
"->",
"option_key",
",",
"array_merge",
"(",
"$",
"this",
"->",
"option",
",",
"[",
"$",
"table_name",
"=>",
"$",
"config",
"[",
"'version'",
"]",
",",
"]",
")",
")",
";",
"}",
"else",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'Failed to create or update <code>%s</code>'",
",",
"$",
"config",
"[",
"'name'",
"]",
")",
";",
"}",
"return",
"$",
"message",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Config file %s is wrong.'",
",",
"$",
"file",
")",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Config file %s must be PHP Array format.'",
",",
"$",
"file",
")",
")",
";",
"}",
"return",
"''",
";",
"}"
] | Update db if possible
@param string $file path to config
@return string
@throws \Exception | [
"Update",
"db",
"if",
"possible"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/DB/TableBuilder.php#L80-L132 |
hametuha/wpametu | src/WPametu/DB/TableBuilder.php | TableBuilder.table_exists | private function table_exists($table_name){
return (bool)$this->db->get_row($this->db->prepare('SHOW TABLES LIKE %s', $table_name));
} | php | private function table_exists($table_name){
return (bool)$this->db->get_row($this->db->prepare('SHOW TABLES LIKE %s', $table_name));
} | [
"private",
"function",
"table_exists",
"(",
"$",
"table_name",
")",
"{",
"return",
"(",
"bool",
")",
"$",
"this",
"->",
"db",
"->",
"get_row",
"(",
"$",
"this",
"->",
"db",
"->",
"prepare",
"(",
"'SHOW TABLES LIKE %s'",
",",
"$",
"table_name",
")",
")",
";",
"}"
] | Detect if table exists
@param string $table_name
@return bool | [
"Detect",
"if",
"table",
"exists"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/DB/TableBuilder.php#L140-L142 |
hametuha/wpametu | src/WPametu/DB/TableBuilder.php | TableBuilder.make_query | private function make_query($config){
/** @var $name string */
/** @var $version string */
/** @var $engine string */
/** @var $columns array */
/** @var $primary_key array */
/** @var $indexes array */
/** @var $unique array */
/** @var $fulltext array */
/** @var $charset string */
extract($config);
if( empty($columns) ){
throw new \Exception(sprintf('Columns of %s shouldn\'t be empty.', $name), 500);
}
$column_query = [];
foreach( $columns as $name => $column ){
$column_query[] = Column::build_query($name, $column);
}
// Is primary key is specified.
if( !empty($primary_key) ){
$column_query[] = sprintf('PRIMARY KEY (%s)', implode(', ', $primary_key));
}
// Is index exists?
if( !empty($indexes) ){
foreach( $indexes as $name => $index ){
$keys = (array)$index;
$column_query[] = sprintf('KEY %s (%s)', $name, implode(', ', $index));
}
}
// Is unique?
if( !empty($unique) ){
foreach ( $unique as $name => $index ) {
$keys = (array)$index;
$column_query[] = sprintf('UNIQUE (%s)', implode(', ', $index));
}
}
// has full text index?
if( !empty($fulltext) ){
foreach( $fulltext as $name => $index ){
$keys = (array) $index;
$column_query[] = sprintf('FULLTEXT %s (%s)', $name, implode(', ', $index));
}
}
if( !isset($charset) ){
$charset = 'utf8';
}
// Normalize charset
$sql = <<<SQL
CREATE TABLE %s (
%s
) ENGINE = %s CHARACTER SET %s
SQL;
$sql = sprintf($sql, $config['name'], implode(','.PHP_EOL.' ', $column_query), $engine, $charset);
return $sql;
} | php | private function make_query($config){
/** @var $name string */
/** @var $version string */
/** @var $engine string */
/** @var $columns array */
/** @var $primary_key array */
/** @var $indexes array */
/** @var $unique array */
/** @var $fulltext array */
/** @var $charset string */
extract($config);
if( empty($columns) ){
throw new \Exception(sprintf('Columns of %s shouldn\'t be empty.', $name), 500);
}
$column_query = [];
foreach( $columns as $name => $column ){
$column_query[] = Column::build_query($name, $column);
}
// Is primary key is specified.
if( !empty($primary_key) ){
$column_query[] = sprintf('PRIMARY KEY (%s)', implode(', ', $primary_key));
}
// Is index exists?
if( !empty($indexes) ){
foreach( $indexes as $name => $index ){
$keys = (array)$index;
$column_query[] = sprintf('KEY %s (%s)', $name, implode(', ', $index));
}
}
// Is unique?
if( !empty($unique) ){
foreach ( $unique as $name => $index ) {
$keys = (array)$index;
$column_query[] = sprintf('UNIQUE (%s)', implode(', ', $index));
}
}
// has full text index?
if( !empty($fulltext) ){
foreach( $fulltext as $name => $index ){
$keys = (array) $index;
$column_query[] = sprintf('FULLTEXT %s (%s)', $name, implode(', ', $index));
}
}
if( !isset($charset) ){
$charset = 'utf8';
}
// Normalize charset
$sql = <<<SQL
CREATE TABLE %s (
%s
) ENGINE = %s CHARACTER SET %s
SQL;
$sql = sprintf($sql, $config['name'], implode(','.PHP_EOL.' ', $column_query), $engine, $charset);
return $sql;
} | [
"private",
"function",
"make_query",
"(",
"$",
"config",
")",
"{",
"/** @var $name string */",
"/** @var $version string */",
"/** @var $engine string */",
"/** @var $columns array */",
"/** @var $primary_key array */",
"/** @var $indexes array */",
"/** @var $unique array */",
"/** @var $fulltext array */",
"/** @var $charset string */",
"extract",
"(",
"$",
"config",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"columns",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Columns of %s shouldn\\'t be empty.'",
",",
"$",
"name",
")",
",",
"500",
")",
";",
"}",
"$",
"column_query",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"name",
"=>",
"$",
"column",
")",
"{",
"$",
"column_query",
"[",
"]",
"=",
"Column",
"::",
"build_query",
"(",
"$",
"name",
",",
"$",
"column",
")",
";",
"}",
"// Is primary key is specified.",
"if",
"(",
"!",
"empty",
"(",
"$",
"primary_key",
")",
")",
"{",
"$",
"column_query",
"[",
"]",
"=",
"sprintf",
"(",
"'PRIMARY KEY (%s)'",
",",
"implode",
"(",
"', '",
",",
"$",
"primary_key",
")",
")",
";",
"}",
"// Is index exists?",
"if",
"(",
"!",
"empty",
"(",
"$",
"indexes",
")",
")",
"{",
"foreach",
"(",
"$",
"indexes",
"as",
"$",
"name",
"=>",
"$",
"index",
")",
"{",
"$",
"keys",
"=",
"(",
"array",
")",
"$",
"index",
";",
"$",
"column_query",
"[",
"]",
"=",
"sprintf",
"(",
"'KEY %s (%s)'",
",",
"$",
"name",
",",
"implode",
"(",
"', '",
",",
"$",
"index",
")",
")",
";",
"}",
"}",
"// Is unique?",
"if",
"(",
"!",
"empty",
"(",
"$",
"unique",
")",
")",
"{",
"foreach",
"(",
"$",
"unique",
"as",
"$",
"name",
"=>",
"$",
"index",
")",
"{",
"$",
"keys",
"=",
"(",
"array",
")",
"$",
"index",
";",
"$",
"column_query",
"[",
"]",
"=",
"sprintf",
"(",
"'UNIQUE (%s)'",
",",
"implode",
"(",
"', '",
",",
"$",
"index",
")",
")",
";",
"}",
"}",
"// has full text index?",
"if",
"(",
"!",
"empty",
"(",
"$",
"fulltext",
")",
")",
"{",
"foreach",
"(",
"$",
"fulltext",
"as",
"$",
"name",
"=>",
"$",
"index",
")",
"{",
"$",
"keys",
"=",
"(",
"array",
")",
"$",
"index",
";",
"$",
"column_query",
"[",
"]",
"=",
"sprintf",
"(",
"'FULLTEXT %s (%s)'",
",",
"$",
"name",
",",
"implode",
"(",
"', '",
",",
"$",
"index",
")",
")",
";",
"}",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"charset",
")",
")",
"{",
"$",
"charset",
"=",
"'utf8'",
";",
"}",
"// Normalize charset",
"$",
"sql",
"=",
" <<<SQL\nCREATE TABLE %s (\n %s\n) ENGINE = %s CHARACTER SET %s\nSQL",
";",
"$",
"sql",
"=",
"sprintf",
"(",
"$",
"sql",
",",
"$",
"config",
"[",
"'name'",
"]",
",",
"implode",
"(",
"','",
".",
"PHP_EOL",
".",
"' '",
",",
"$",
"column_query",
")",
",",
"$",
"engine",
",",
"$",
"charset",
")",
";",
"return",
"$",
"sql",
";",
"}"
] | Build create query
@param array $config
@return string
@throws \Exception | [
"Build",
"create",
"query"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/DB/TableBuilder.php#L151-L205 |
hametuha/wpametu | src/WPametu/DB/TableBuilder.php | TableBuilder.need_update | protected function need_update($name, $version){
return !isset($this->option[$name]) || !$this->option[$name] || version_compare($this->option[$name], $version, '<');
} | php | protected function need_update($name, $version){
return !isset($this->option[$name]) || !$this->option[$name] || version_compare($this->option[$name], $version, '<');
} | [
"protected",
"function",
"need_update",
"(",
"$",
"name",
",",
"$",
"version",
")",
"{",
"return",
"!",
"isset",
"(",
"$",
"this",
"->",
"option",
"[",
"$",
"name",
"]",
")",
"||",
"!",
"$",
"this",
"->",
"option",
"[",
"$",
"name",
"]",
"||",
"version_compare",
"(",
"$",
"this",
"->",
"option",
"[",
"$",
"name",
"]",
",",
"$",
"version",
",",
"'<'",
")",
";",
"}"
] | Detect if source version is greater than existing db
@param string $name
@param string $version
@return bool | [
"Detect",
"if",
"source",
"version",
"is",
"greater",
"than",
"existing",
"db"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/DB/TableBuilder.php#L229-L231 |
Erdiko/core | src/Controller.php | Controller.setTheme | public function setTheme($name)
{
$this->getResponse()->setThemeName($name);
$this->getResponse()->getTheme()->setName($name);
} | php | public function setTheme($name)
{
$this->getResponse()->setThemeName($name);
$this->getResponse()->getTheme()->setName($name);
} | [
"public",
"function",
"setTheme",
"(",
"$",
"name",
")",
"{",
"$",
"this",
"->",
"getResponse",
"(",
")",
"->",
"setThemeName",
"(",
"$",
"name",
")",
";",
"$",
"this",
"->",
"getResponse",
"(",
")",
"->",
"getTheme",
"(",
")",
"->",
"setName",
"(",
"$",
"name",
")",
";",
"}"
] | Set the theme name in both the response and the theme objects
@param string $name, the name/id of the theme | [
"Set",
"the",
"theme",
"name",
"in",
"both",
"the",
"response",
"and",
"the",
"theme",
"objects"
] | train | https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Controller.php#L158-L162 |
Erdiko/core | src/Controller.php | Controller.setBodyTitle | public function setBodyTitle($title)
{
$this->getResponse()->getTheme()->setBodyTitle($title);
$this->_title = $title;
} | php | public function setBodyTitle($title)
{
$this->getResponse()->getTheme()->setBodyTitle($title);
$this->_title = $title;
} | [
"public",
"function",
"setBodyTitle",
"(",
"$",
"title",
")",
"{",
"$",
"this",
"->",
"getResponse",
"(",
")",
"->",
"getTheme",
"(",
")",
"->",
"setBodyTitle",
"(",
"$",
"title",
")",
";",
"$",
"this",
"->",
"_title",
"=",
"$",
"title",
";",
"}"
] | Set page content title to be themed in the view
@param string $title | [
"Set",
"page",
"content",
"title",
"to",
"be",
"themed",
"in",
"the",
"view"
] | train | https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Controller.php#L238-L242 |
Erdiko/core | src/Controller.php | Controller._autoaction | protected function _autoaction($var, $httpMethod = 'get')
{
$method = $this->urlToActionName($var, $httpMethod);
if (method_exists($this, $method)) {
return $this->$method();
} else {
ToroHook::fire('404', array(
"error" => "Controller ".get_class($this)." does not contain $method action",
"path_info" => $this->_pathInfo ));
}
} | php | protected function _autoaction($var, $httpMethod = 'get')
{
$method = $this->urlToActionName($var, $httpMethod);
if (method_exists($this, $method)) {
return $this->$method();
} else {
ToroHook::fire('404', array(
"error" => "Controller ".get_class($this)." does not contain $method action",
"path_info" => $this->_pathInfo ));
}
} | [
"protected",
"function",
"_autoaction",
"(",
"$",
"var",
",",
"$",
"httpMethod",
"=",
"'get'",
")",
"{",
"$",
"method",
"=",
"$",
"this",
"->",
"urlToActionName",
"(",
"$",
"var",
",",
"$",
"httpMethod",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
"{",
"return",
"$",
"this",
"->",
"$",
"method",
"(",
")",
";",
"}",
"else",
"{",
"ToroHook",
"::",
"fire",
"(",
"'404'",
",",
"array",
"(",
"\"error\"",
"=>",
"\"Controller \"",
".",
"get_class",
"(",
"$",
"this",
")",
".",
"\" does not contain $method action\"",
",",
"\"path_info\"",
"=>",
"$",
"this",
"->",
"_pathInfo",
")",
")",
";",
"}",
"}"
] | Autoaction
@param string $var
@param string $httpMethod | [
"Autoaction"
] | train | https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Controller.php#L299-L309 |
Erdiko/core | src/Controller.php | Controller.addView | public function addView($view, $data = null)
{
if(!is_object($view))
$view = new \erdiko\core\View($view, $data);
if($data != null)
$view->setData($data);
$this->appendContent($view->toHtml());
} | php | public function addView($view, $data = null)
{
if(!is_object($view))
$view = new \erdiko\core\View($view, $data);
if($data != null)
$view->setData($data);
$this->appendContent($view->toHtml());
} | [
"public",
"function",
"addView",
"(",
"$",
"view",
",",
"$",
"data",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"view",
")",
")",
"$",
"view",
"=",
"new",
"\\",
"erdiko",
"\\",
"core",
"\\",
"View",
"(",
"$",
"view",
",",
"$",
"data",
")",
";",
"if",
"(",
"$",
"data",
"!=",
"null",
")",
"$",
"view",
"->",
"setData",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"appendContent",
"(",
"$",
"view",
"->",
"toHtml",
"(",
")",
")",
";",
"}"
] | Add a view from the current theme with the given data
@param mixed $view, can be a string (view name) or object (view object)
@param array $data
@return string $html, view contents | [
"Add",
"a",
"view",
"from",
"the",
"current",
"theme",
"with",
"the",
"given",
"data"
] | train | https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Controller.php#L357-L365 |
Erdiko/core | src/Controller.php | Controller.getLayout | public function getLayout($layoutName, $data = null, $templateRootFolder = null)
{
$layout = new \erdiko\core\Layout($layoutName, $data, $this->getThemeName());
$layout->setTitle($this->getBodyTitle());
if ($templateRootFolder != null) {
$layout->setViewRootFolder($templateRootFolder);
$layout->setTemplateRootFolder($templateRootFolder);
}
return $layout->toHtml();
} | php | public function getLayout($layoutName, $data = null, $templateRootFolder = null)
{
$layout = new \erdiko\core\Layout($layoutName, $data, $this->getThemeName());
$layout->setTitle($this->getBodyTitle());
if ($templateRootFolder != null) {
$layout->setViewRootFolder($templateRootFolder);
$layout->setTemplateRootFolder($templateRootFolder);
}
return $layout->toHtml();
} | [
"public",
"function",
"getLayout",
"(",
"$",
"layoutName",
",",
"$",
"data",
"=",
"null",
",",
"$",
"templateRootFolder",
"=",
"null",
")",
"{",
"$",
"layout",
"=",
"new",
"\\",
"erdiko",
"\\",
"core",
"\\",
"Layout",
"(",
"$",
"layoutName",
",",
"$",
"data",
",",
"$",
"this",
"->",
"getThemeName",
"(",
")",
")",
";",
"$",
"layout",
"->",
"setTitle",
"(",
"$",
"this",
"->",
"getBodyTitle",
"(",
")",
")",
";",
"if",
"(",
"$",
"templateRootFolder",
"!=",
"null",
")",
"{",
"$",
"layout",
"->",
"setViewRootFolder",
"(",
"$",
"templateRootFolder",
")",
";",
"$",
"layout",
"->",
"setTemplateRootFolder",
"(",
"$",
"templateRootFolder",
")",
";",
"}",
"return",
"$",
"layout",
"->",
"toHtml",
"(",
")",
";",
"}"
] | Load a layout with the given data
@param string $layoutName
@param array $data
@return string $html, layout contents | [
"Load",
"a",
"layout",
"with",
"the",
"given",
"data"
] | train | https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Controller.php#L374-L385 |
Erdiko/core | src/Controller.php | Controller.setMeta | public function setMeta($meta)
{
foreach($meta as $name => $content)
$this->getResponse()->getTheme()->addMeta($name, $content);
} | php | public function setMeta($meta)
{
foreach($meta as $name => $content)
$this->getResponse()->getTheme()->addMeta($name, $content);
} | [
"public",
"function",
"setMeta",
"(",
"$",
"meta",
")",
"{",
"foreach",
"(",
"$",
"meta",
"as",
"$",
"name",
"=>",
"$",
"content",
")",
"$",
"this",
"->",
"getResponse",
"(",
")",
"->",
"getTheme",
"(",
")",
"->",
"addMeta",
"(",
"$",
"name",
",",
"$",
"content",
")",
";",
"}"
] | Set multiple meta fields at once
@param array $meta | [
"Set",
"multiple",
"meta",
"fields",
"at",
"once"
] | train | https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Controller.php#L412-L416 |
Erdiko/core | src/Controller.php | Controller.addCss | public function addCss($name, $file, $order = 10, $active = 1)
{
$this->getResponse()
->getTheme()
->addCss($name, $file, $order,$active);
} | php | public function addCss($name, $file, $order = 10, $active = 1)
{
$this->getResponse()
->getTheme()
->addCss($name, $file, $order,$active);
} | [
"public",
"function",
"addCss",
"(",
"$",
"name",
",",
"$",
"file",
",",
"$",
"order",
"=",
"10",
",",
"$",
"active",
"=",
"1",
")",
"{",
"$",
"this",
"->",
"getResponse",
"(",
")",
"->",
"getTheme",
"(",
")",
"->",
"addCss",
"(",
"$",
"name",
",",
"$",
"file",
",",
"$",
"order",
",",
"$",
"active",
")",
";",
"}"
] | Add Css includes to the page
@param string $name
@param string $file
@param int $order
@param int $active | [
"Add",
"Css",
"includes",
"to",
"the",
"page"
] | train | https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Controller.php#L426-L431 |
Erdiko/core | src/Controller.php | Controller.addJs | public function addJs($name, $file, $order = 10, $active = 1)
{
$this->getResponse()
->getTheme()
->addJs($name, $file, $order,$active);
} | php | public function addJs($name, $file, $order = 10, $active = 1)
{
$this->getResponse()
->getTheme()
->addJs($name, $file, $order,$active);
} | [
"public",
"function",
"addJs",
"(",
"$",
"name",
",",
"$",
"file",
",",
"$",
"order",
"=",
"10",
",",
"$",
"active",
"=",
"1",
")",
"{",
"$",
"this",
"->",
"getResponse",
"(",
")",
"->",
"getTheme",
"(",
")",
"->",
"addJs",
"(",
"$",
"name",
",",
"$",
"file",
",",
"$",
"order",
",",
"$",
"active",
")",
";",
"}"
] | Add Css includes to the page
@param string $name
@param string $file
@param int $order
@param int $active | [
"Add",
"Css",
"includes",
"to",
"the",
"page"
] | train | https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Controller.php#L441-L446 |
Erdiko/core | src/Controller.php | Controller.addPhpToJs | public function addPhpToJs($key, $value)
{
if (is_bool($value)) {
$value = $value ? "true" : "false";
} elseif (is_string($value)) {
$value = "\"$value\"";
} elseif (is_array($value)) {
$value = json_encode($value);
} elseif (is_object($value) && method_exists($value, "toArray")) {
$value = json_encode($value->toArray());
} else {
throw new \Exception("Can not translate a parameter from PHP to JS\n".print_r($value, true));
}
$this->_themeExtras['phpToJs'][$key] = $value;
} | php | public function addPhpToJs($key, $value)
{
if (is_bool($value)) {
$value = $value ? "true" : "false";
} elseif (is_string($value)) {
$value = "\"$value\"";
} elseif (is_array($value)) {
$value = json_encode($value);
} elseif (is_object($value) && method_exists($value, "toArray")) {
$value = json_encode($value->toArray());
} else {
throw new \Exception("Can not translate a parameter from PHP to JS\n".print_r($value, true));
}
$this->_themeExtras['phpToJs'][$key] = $value;
} | [
"public",
"function",
"addPhpToJs",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"?",
"\"true\"",
":",
"\"false\"",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"\"\\\"$value\\\"\"",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"json_encode",
"(",
"$",
"value",
")",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"value",
")",
"&&",
"method_exists",
"(",
"$",
"value",
",",
"\"toArray\"",
")",
")",
"{",
"$",
"value",
"=",
"json_encode",
"(",
"$",
"value",
"->",
"toArray",
"(",
")",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Can not translate a parameter from PHP to JS\\n\"",
".",
"print_r",
"(",
"$",
"value",
",",
"true",
")",
")",
";",
"}",
"$",
"this",
"->",
"_themeExtras",
"[",
"'phpToJs'",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}"
] | Add phpToJs variable to be set on the current page
@param mixed $key
@param mixed $value | [
"Add",
"phpToJs",
"variable",
"to",
"be",
"set",
"on",
"the",
"current",
"page"
] | train | https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Controller.php#L485-L500 |
gpupo/common-schema | src/ORM/Entity/Trading/Order/Shipping/Seller.php | Seller.setShipping | public function setShipping(\Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Shipping $shipping = null)
{
$this->shipping = $shipping;
return $this;
} | php | public function setShipping(\Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Shipping $shipping = null)
{
$this->shipping = $shipping;
return $this;
} | [
"public",
"function",
"setShipping",
"(",
"\\",
"Gpupo",
"\\",
"CommonSchema",
"\\",
"ORM",
"\\",
"Entity",
"\\",
"Trading",
"\\",
"Order",
"\\",
"Shipping",
"\\",
"Shipping",
"$",
"shipping",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"shipping",
"=",
"$",
"shipping",
";",
"return",
"$",
"this",
";",
"}"
] | Set shipping.
@param null|\Gpupo\CommonSchema\ORM\Entity\Trading\Order\Shipping\Shipping $shipping
@return Seller | [
"Set",
"shipping",
"."
] | train | https://github.com/gpupo/common-schema/blob/a762d2eb3063b7317c72c69cbb463b1f95b86b0a/src/ORM/Entity/Trading/Order/Shipping/Seller.php#L345-L350 |
surebert/surebert-framework | src/sb/PDO/Statement/Logger.php | Logger.execute | public function execute($bound_input_params = Array())
{
$log = "Executing: " . $this->queryString;
if (count($bound_input_params) > 0) {
foreach ($bound_input_params as $key => $val) {
$log .= "\nBinding Values: " . $key . ' = ' . $val;
}
}
$this->connection->writeToLog($log);
return parent::execute($bound_input_params);
} | php | public function execute($bound_input_params = Array())
{
$log = "Executing: " . $this->queryString;
if (count($bound_input_params) > 0) {
foreach ($bound_input_params as $key => $val) {
$log .= "\nBinding Values: " . $key . ' = ' . $val;
}
}
$this->connection->writeToLog($log);
return parent::execute($bound_input_params);
} | [
"public",
"function",
"execute",
"(",
"$",
"bound_input_params",
"=",
"Array",
"(",
")",
")",
"{",
"$",
"log",
"=",
"\"Executing: \"",
".",
"$",
"this",
"->",
"queryString",
";",
"if",
"(",
"count",
"(",
"$",
"bound_input_params",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"bound_input_params",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"log",
".=",
"\"\\nBinding Values: \"",
".",
"$",
"key",
".",
"' = '",
".",
"$",
"val",
";",
"}",
"}",
"$",
"this",
"->",
"connection",
"->",
"writeToLog",
"(",
"$",
"log",
")",
";",
"return",
"parent",
"::",
"execute",
"(",
"$",
"bound_input_params",
")",
";",
"}"
] | Extends PDOStatement::execute in order to include logging
@param array $bound_input_params input params to bind Array(':myparam' => 1)
@return boolean | [
"Extends",
"PDOStatement",
"::",
"execute",
"in",
"order",
"to",
"include",
"logging"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/PDO/Statement/Logger.php#L35-L48 |
surebert/surebert-framework | src/sb/PDO/Statement/Logger.php | Logger.bindParam | public function bindParam($paramno, &$param, $type = null, $maxlen = null, $driverdata = null)
{
$log = 'Binding Parameters: ' . $paramno . '=' . $param;
if (!is_null($type)) {
$log .= '| Type: ' . $type;
}
if (!is_null($maxlen)) {
$log .= '| Maxlen: ' . $maxlen;
}
if (!is_null($driverdata)) {
$log .= '| DriverData: ' . $driverdata;
}
$this->connection->writeToLog($log);
if (!empty($type)) {
return parent::bindParam($paramno, $param, $type, $maxlen, $driverdata);
}
return parent::bindParam($key, $val);
} | php | public function bindParam($paramno, &$param, $type = null, $maxlen = null, $driverdata = null)
{
$log = 'Binding Parameters: ' . $paramno . '=' . $param;
if (!is_null($type)) {
$log .= '| Type: ' . $type;
}
if (!is_null($maxlen)) {
$log .= '| Maxlen: ' . $maxlen;
}
if (!is_null($driverdata)) {
$log .= '| DriverData: ' . $driverdata;
}
$this->connection->writeToLog($log);
if (!empty($type)) {
return parent::bindParam($paramno, $param, $type, $maxlen, $driverdata);
}
return parent::bindParam($key, $val);
} | [
"public",
"function",
"bindParam",
"(",
"$",
"paramno",
",",
"&",
"$",
"param",
",",
"$",
"type",
"=",
"null",
",",
"$",
"maxlen",
"=",
"null",
",",
"$",
"driverdata",
"=",
"null",
")",
"{",
"$",
"log",
"=",
"'Binding Parameters: '",
".",
"$",
"paramno",
".",
"'='",
".",
"$",
"param",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"type",
")",
")",
"{",
"$",
"log",
".=",
"'| Type: '",
".",
"$",
"type",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"maxlen",
")",
")",
"{",
"$",
"log",
".=",
"'| Maxlen: '",
".",
"$",
"maxlen",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"driverdata",
")",
")",
"{",
"$",
"log",
".=",
"'| DriverData: '",
".",
"$",
"driverdata",
";",
"}",
"$",
"this",
"->",
"connection",
"->",
"writeToLog",
"(",
"$",
"log",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"type",
")",
")",
"{",
"return",
"parent",
"::",
"bindParam",
"(",
"$",
"paramno",
",",
"$",
"param",
",",
"$",
"type",
",",
"$",
"maxlen",
",",
"$",
"driverdata",
")",
";",
"}",
"return",
"parent",
"::",
"bindParam",
"(",
"$",
"key",
",",
"$",
"val",
")",
";",
"}"
] | Extends PDOStatement::bindParam in order to include logging
@param mixed $paramno
@param <type> $param
@param <type> $type
@param <type> $maxlen
@param <type> $driverdata
@return boolean | [
"Extends",
"PDOStatement",
"::",
"bindParam",
"in",
"order",
"to",
"include",
"logging"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/PDO/Statement/Logger.php#L59-L79 |
surebert/surebert-framework | src/sb/PDO/Statement/Logger.php | Logger.bindValue | public function bindValue($paramno, $param, $type = null)
{
$log = 'Binding Value: ' . $paramno . '=' . $param;
if (!is_null($type)) {
$log .= '| Type: ' . $type;
}
$this->connection->writeToLog($log);
return parent::bindParam($paramno, $param, $type);
} | php | public function bindValue($paramno, $param, $type = null)
{
$log = 'Binding Value: ' . $paramno . '=' . $param;
if (!is_null($type)) {
$log .= '| Type: ' . $type;
}
$this->connection->writeToLog($log);
return parent::bindParam($paramno, $param, $type);
} | [
"public",
"function",
"bindValue",
"(",
"$",
"paramno",
",",
"$",
"param",
",",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"log",
"=",
"'Binding Value: '",
".",
"$",
"paramno",
".",
"'='",
".",
"$",
"param",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"type",
")",
")",
"{",
"$",
"log",
".=",
"'| Type: '",
".",
"$",
"type",
";",
"}",
"$",
"this",
"->",
"connection",
"->",
"writeToLog",
"(",
"$",
"log",
")",
";",
"return",
"parent",
"::",
"bindParam",
"(",
"$",
"paramno",
",",
"$",
"param",
",",
"$",
"type",
")",
";",
"}"
] | Extends PDOStatement::bindValue in order to include logging
@param <type> $column
@param <type> $param
@param <type> $type
@param <type> $maxlen
@param <type> $driverdata
@return <type> | [
"Extends",
"PDOStatement",
"::",
"bindValue",
"in",
"order",
"to",
"include",
"logging"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/PDO/Statement/Logger.php#L122-L132 |
nabab/bbn | src/bbn/user/manager.php | manager.groups | public function groups(){
$a =& $this->class_cfg['arch'];
$t =& $this->class_cfg['tables'];
$id = $this->db->cfn($a['groups']['id'], $t['groups'], 1);
$group = $this->db->cfn($a['groups']['group'], $t['groups'], 1);
$id_group = $this->db->cfn($a['users']['id_group'], $t['users'], 1);
$active = $this->db->cfn($a['users']['active'], $t['users'], 1);
$users_id = $this->db->cfn($a['users']['id'], $t['users'], 1);
$groups = $this->db->escape($t['groups']);
$users = $this->db->escape($t['users']);
return $this->db->get_rows("
SELECT $id, $group,
COUNT($users_id) AS `num`
FROM $groups
LEFT JOIN $users
ON $id_group = $id
GROUP BY $id");
} | php | public function groups(){
$a =& $this->class_cfg['arch'];
$t =& $this->class_cfg['tables'];
$id = $this->db->cfn($a['groups']['id'], $t['groups'], 1);
$group = $this->db->cfn($a['groups']['group'], $t['groups'], 1);
$id_group = $this->db->cfn($a['users']['id_group'], $t['users'], 1);
$active = $this->db->cfn($a['users']['active'], $t['users'], 1);
$users_id = $this->db->cfn($a['users']['id'], $t['users'], 1);
$groups = $this->db->escape($t['groups']);
$users = $this->db->escape($t['users']);
return $this->db->get_rows("
SELECT $id, $group,
COUNT($users_id) AS `num`
FROM $groups
LEFT JOIN $users
ON $id_group = $id
GROUP BY $id");
} | [
"public",
"function",
"groups",
"(",
")",
"{",
"$",
"a",
"=",
"&",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
";",
"$",
"t",
"=",
"&",
"$",
"this",
"->",
"class_cfg",
"[",
"'tables'",
"]",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"db",
"->",
"cfn",
"(",
"$",
"a",
"[",
"'groups'",
"]",
"[",
"'id'",
"]",
",",
"$",
"t",
"[",
"'groups'",
"]",
",",
"1",
")",
";",
"$",
"group",
"=",
"$",
"this",
"->",
"db",
"->",
"cfn",
"(",
"$",
"a",
"[",
"'groups'",
"]",
"[",
"'group'",
"]",
",",
"$",
"t",
"[",
"'groups'",
"]",
",",
"1",
")",
";",
"$",
"id_group",
"=",
"$",
"this",
"->",
"db",
"->",
"cfn",
"(",
"$",
"a",
"[",
"'users'",
"]",
"[",
"'id_group'",
"]",
",",
"$",
"t",
"[",
"'users'",
"]",
",",
"1",
")",
";",
"$",
"active",
"=",
"$",
"this",
"->",
"db",
"->",
"cfn",
"(",
"$",
"a",
"[",
"'users'",
"]",
"[",
"'active'",
"]",
",",
"$",
"t",
"[",
"'users'",
"]",
",",
"1",
")",
";",
"$",
"users_id",
"=",
"$",
"this",
"->",
"db",
"->",
"cfn",
"(",
"$",
"a",
"[",
"'users'",
"]",
"[",
"'id'",
"]",
",",
"$",
"t",
"[",
"'users'",
"]",
",",
"1",
")",
";",
"$",
"groups",
"=",
"$",
"this",
"->",
"db",
"->",
"escape",
"(",
"$",
"t",
"[",
"'groups'",
"]",
")",
";",
"$",
"users",
"=",
"$",
"this",
"->",
"db",
"->",
"escape",
"(",
"$",
"t",
"[",
"'users'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"db",
"->",
"get_rows",
"(",
"\"\n SELECT $id, $group,\n COUNT($users_id) AS `num`\n FROM $groups\n LEFT JOIN $users\n ON $id_group = $id\n GROUP BY $id\"",
")",
";",
"}"
] | Returns all the users' groups - with or without admin
@param bool $adm
@return array|false | [
"Returns",
"all",
"the",
"users",
"groups",
"-",
"with",
"or",
"without",
"admin"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/manager.php#L124-L141 |
nabab/bbn | src/bbn/user/manager.php | manager.add | public function add($cfg)
{
$u =& $this->class_cfg['arch']['users'];
$fields = array_unique(array_values($u));
$cfg[$u['active']] = 1;
$cfg[$u['cfg']] = '{}';
foreach ( $cfg as $k => $v ){
if ( !\in_array($k, $fields) ){
unset($cfg[$k]);
}
}
if ( isset($cfg['id']) ){
unset($cfg['id']);
}
if (
bbn\str::is_email($cfg[$u['email']]) &&
$this->db->insert($this->class_cfg['tables']['users'], $cfg)
){
$cfg[$u['id']] = $this->db->last_id();
// Envoi d'un lien
$this->make_hotlink($cfg[$this->class_cfg['arch']['users']['id']], 'creation');
return $cfg;
}
return false;
} | php | public function add($cfg)
{
$u =& $this->class_cfg['arch']['users'];
$fields = array_unique(array_values($u));
$cfg[$u['active']] = 1;
$cfg[$u['cfg']] = '{}';
foreach ( $cfg as $k => $v ){
if ( !\in_array($k, $fields) ){
unset($cfg[$k]);
}
}
if ( isset($cfg['id']) ){
unset($cfg['id']);
}
if (
bbn\str::is_email($cfg[$u['email']]) &&
$this->db->insert($this->class_cfg['tables']['users'], $cfg)
){
$cfg[$u['id']] = $this->db->last_id();
// Envoi d'un lien
$this->make_hotlink($cfg[$this->class_cfg['arch']['users']['id']], 'creation');
return $cfg;
}
return false;
} | [
"public",
"function",
"add",
"(",
"$",
"cfg",
")",
"{",
"$",
"u",
"=",
"&",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'users'",
"]",
";",
"$",
"fields",
"=",
"array_unique",
"(",
"array_values",
"(",
"$",
"u",
")",
")",
";",
"$",
"cfg",
"[",
"$",
"u",
"[",
"'active'",
"]",
"]",
"=",
"1",
";",
"$",
"cfg",
"[",
"$",
"u",
"[",
"'cfg'",
"]",
"]",
"=",
"'{}'",
";",
"foreach",
"(",
"$",
"cfg",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"!",
"\\",
"in_array",
"(",
"$",
"k",
",",
"$",
"fields",
")",
")",
"{",
"unset",
"(",
"$",
"cfg",
"[",
"$",
"k",
"]",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"cfg",
"[",
"'id'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"cfg",
"[",
"'id'",
"]",
")",
";",
"}",
"if",
"(",
"bbn",
"\\",
"str",
"::",
"is_email",
"(",
"$",
"cfg",
"[",
"$",
"u",
"[",
"'email'",
"]",
"]",
")",
"&&",
"$",
"this",
"->",
"db",
"->",
"insert",
"(",
"$",
"this",
"->",
"class_cfg",
"[",
"'tables'",
"]",
"[",
"'users'",
"]",
",",
"$",
"cfg",
")",
")",
"{",
"$",
"cfg",
"[",
"$",
"u",
"[",
"'id'",
"]",
"]",
"=",
"$",
"this",
"->",
"db",
"->",
"last_id",
"(",
")",
";",
"// Envoi d'un lien",
"$",
"this",
"->",
"make_hotlink",
"(",
"$",
"cfg",
"[",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'users'",
"]",
"[",
"'id'",
"]",
"]",
",",
"'creation'",
")",
";",
"return",
"$",
"cfg",
";",
"}",
"return",
"false",
";",
"}"
] | Creates a new user and returns its configuration (with the new ID)
@param array $cfg A configuration array
@return array|false | [
"Creates",
"a",
"new",
"user",
"and",
"returns",
"its",
"configuration",
"(",
"with",
"the",
"new",
"ID",
")"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/manager.php#L291-L316 |
nabab/bbn | src/bbn/user/manager.php | manager.edit | public function edit($cfg, $id_user=false)
{
$u =& $this->class_cfg['arch']['users'];
$fields = array_unique(array_values($this->class_cfg['arch']['users']));
$cfg[$u['active']] = 1;
foreach ( $cfg as $k => $v ){
if ( !\in_array($k, $fields) ){
unset($cfg[$k]);
}
}
if ( !$id_user && isset($cfg[$u['id']]) ){
$id_user = $cfg[$u['id']];
}
if ( $id_user && (
!isset($cfg[$this->class_cfg['arch']['users']['email']]) ||
bbn\str::is_email($cfg[$this->class_cfg['arch']['users']['email']])
)
){
if ( $this->db->update($this->class_cfg['tables']['users'], $cfg, [
$u['id'] => $id_user
]) ){
$cfg['id'] = $id_user;
return $cfg;
}
}
return false;
} | php | public function edit($cfg, $id_user=false)
{
$u =& $this->class_cfg['arch']['users'];
$fields = array_unique(array_values($this->class_cfg['arch']['users']));
$cfg[$u['active']] = 1;
foreach ( $cfg as $k => $v ){
if ( !\in_array($k, $fields) ){
unset($cfg[$k]);
}
}
if ( !$id_user && isset($cfg[$u['id']]) ){
$id_user = $cfg[$u['id']];
}
if ( $id_user && (
!isset($cfg[$this->class_cfg['arch']['users']['email']]) ||
bbn\str::is_email($cfg[$this->class_cfg['arch']['users']['email']])
)
){
if ( $this->db->update($this->class_cfg['tables']['users'], $cfg, [
$u['id'] => $id_user
]) ){
$cfg['id'] = $id_user;
return $cfg;
}
}
return false;
} | [
"public",
"function",
"edit",
"(",
"$",
"cfg",
",",
"$",
"id_user",
"=",
"false",
")",
"{",
"$",
"u",
"=",
"&",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'users'",
"]",
";",
"$",
"fields",
"=",
"array_unique",
"(",
"array_values",
"(",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'users'",
"]",
")",
")",
";",
"$",
"cfg",
"[",
"$",
"u",
"[",
"'active'",
"]",
"]",
"=",
"1",
";",
"foreach",
"(",
"$",
"cfg",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"!",
"\\",
"in_array",
"(",
"$",
"k",
",",
"$",
"fields",
")",
")",
"{",
"unset",
"(",
"$",
"cfg",
"[",
"$",
"k",
"]",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"id_user",
"&&",
"isset",
"(",
"$",
"cfg",
"[",
"$",
"u",
"[",
"'id'",
"]",
"]",
")",
")",
"{",
"$",
"id_user",
"=",
"$",
"cfg",
"[",
"$",
"u",
"[",
"'id'",
"]",
"]",
";",
"}",
"if",
"(",
"$",
"id_user",
"&&",
"(",
"!",
"isset",
"(",
"$",
"cfg",
"[",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'users'",
"]",
"[",
"'email'",
"]",
"]",
")",
"||",
"bbn",
"\\",
"str",
"::",
"is_email",
"(",
"$",
"cfg",
"[",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'users'",
"]",
"[",
"'email'",
"]",
"]",
")",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"db",
"->",
"update",
"(",
"$",
"this",
"->",
"class_cfg",
"[",
"'tables'",
"]",
"[",
"'users'",
"]",
",",
"$",
"cfg",
",",
"[",
"$",
"u",
"[",
"'id'",
"]",
"=>",
"$",
"id_user",
"]",
")",
")",
"{",
"$",
"cfg",
"[",
"'id'",
"]",
"=",
"$",
"id_user",
";",
"return",
"$",
"cfg",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Creates a new user and returns its configuration (with the new ID)
@param array $cfg A configuration array
@return array|false | [
"Creates",
"a",
"new",
"user",
"and",
"returns",
"its",
"configuration",
"(",
"with",
"the",
"new",
"ID",
")"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/manager.php#L324-L350 |
nabab/bbn | src/bbn/user/manager.php | manager.deactivate | public function deactivate($id_user){
$update = [
$this->class_cfg['arch']['users']['active'] => 0,
$this->class_cfg['arch']['users']['email'] => null,
];
if ( !empty($this->class_cfg['arch']['users']['login']) ){
$update[$this->class_cfg['arch']['users']['login']] = null;
}
return $this->db->update($this->class_cfg['tables']['users'], $update, [
$this->class_cfg['arch']['users']['id'] => $id_user
]);
} | php | public function deactivate($id_user){
$update = [
$this->class_cfg['arch']['users']['active'] => 0,
$this->class_cfg['arch']['users']['email'] => null,
];
if ( !empty($this->class_cfg['arch']['users']['login']) ){
$update[$this->class_cfg['arch']['users']['login']] = null;
}
return $this->db->update($this->class_cfg['tables']['users'], $update, [
$this->class_cfg['arch']['users']['id'] => $id_user
]);
} | [
"public",
"function",
"deactivate",
"(",
"$",
"id_user",
")",
"{",
"$",
"update",
"=",
"[",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'users'",
"]",
"[",
"'active'",
"]",
"=>",
"0",
",",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'users'",
"]",
"[",
"'email'",
"]",
"=>",
"null",
",",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'users'",
"]",
"[",
"'login'",
"]",
")",
")",
"{",
"$",
"update",
"[",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'users'",
"]",
"[",
"'login'",
"]",
"]",
"=",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"db",
"->",
"update",
"(",
"$",
"this",
"->",
"class_cfg",
"[",
"'tables'",
"]",
"[",
"'users'",
"]",
",",
"$",
"update",
",",
"[",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'users'",
"]",
"[",
"'id'",
"]",
"=>",
"$",
"id_user",
"]",
")",
";",
"}"
] | @param int $id_user User ID
@return int|false Update result | [
"@param",
"int",
"$id_user",
"User",
"ID"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/manager.php#L553-L565 |
nabab/bbn | src/bbn/user/manager.php | manager.reactivate | public function reactivate($id_user){
$this->db->update($this->class_cfg['tables']['users'], [
$this->class_cfg['arch']['users']['active'] => 1
], [
$this->class_cfg['arch']['users']['id'] => $id_user
]);
return $this;
} | php | public function reactivate($id_user){
$this->db->update($this->class_cfg['tables']['users'], [
$this->class_cfg['arch']['users']['active'] => 1
], [
$this->class_cfg['arch']['users']['id'] => $id_user
]);
return $this;
} | [
"public",
"function",
"reactivate",
"(",
"$",
"id_user",
")",
"{",
"$",
"this",
"->",
"db",
"->",
"update",
"(",
"$",
"this",
"->",
"class_cfg",
"[",
"'tables'",
"]",
"[",
"'users'",
"]",
",",
"[",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'users'",
"]",
"[",
"'active'",
"]",
"=>",
"1",
"]",
",",
"[",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'users'",
"]",
"[",
"'id'",
"]",
"=>",
"$",
"id_user",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] | @param int $id_user User ID
@return manager | [
"@param",
"int",
"$id_user",
"User",
"ID"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user/manager.php#L572-L579 |
m4grio/bangkok-insurance-php | src/Client.php | Client.call | public function call($method, Array $params = [])
{
$params = $this->mergeParams($method, $params);
try {
$result = $this->soapClient->__soapCall($method, $params);
} catch (SoapFault $fault) {
// @todo log
throw $fault;
}
return $result;
} | php | public function call($method, Array $params = [])
{
$params = $this->mergeParams($method, $params);
try {
$result = $this->soapClient->__soapCall($method, $params);
} catch (SoapFault $fault) {
// @todo log
throw $fault;
}
return $result;
} | [
"public",
"function",
"call",
"(",
"$",
"method",
",",
"Array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"mergeParams",
"(",
"$",
"method",
",",
"$",
"params",
")",
";",
"try",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"soapClient",
"->",
"__soapCall",
"(",
"$",
"method",
",",
"$",
"params",
")",
";",
"}",
"catch",
"(",
"SoapFault",
"$",
"fault",
")",
"{",
"// @todo log",
"throw",
"$",
"fault",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Prepare and issue a call
@param $method
@param array $params
@return AbstractResult
@throws SoapFault
@throws \Exception | [
"Prepare",
"and",
"issue",
"a",
"call"
] | train | https://github.com/m4grio/bangkok-insurance-php/blob/400266d043abe6b7cacb9da36064cbb169149c2a/src/Client.php#L54-L65 |
m4grio/bangkok-insurance-php | src/Client.php | Client.mergeParams | protected function mergeParams($method, Array $params = [])
{
$mergedParams = array_merge($this->defaultParams, $params);
$newParams = [$method => $mergedParams];
return $newParams;
} | php | protected function mergeParams($method, Array $params = [])
{
$mergedParams = array_merge($this->defaultParams, $params);
$newParams = [$method => $mergedParams];
return $newParams;
} | [
"protected",
"function",
"mergeParams",
"(",
"$",
"method",
",",
"Array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"mergedParams",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"defaultParams",
",",
"$",
"params",
")",
";",
"$",
"newParams",
"=",
"[",
"$",
"method",
"=>",
"$",
"mergedParams",
"]",
";",
"return",
"$",
"newParams",
";",
"}"
] | Default way to merge params
@param $method
@param array $params
@return array | [
"Default",
"way",
"to",
"merge",
"params"
] | train | https://github.com/m4grio/bangkok-insurance-php/blob/400266d043abe6b7cacb9da36064cbb169149c2a/src/Client.php#L75-L81 |
ajgarlag/AjglSessionConcurrency | src/Http/Session/Registry/Storage/FileSessionRegistryStorage.php | FileSessionRegistryStorage.getSessionInformations | public function getSessionInformations($username, $includeExpiredSessions = false)
{
$result = array();
foreach (glob($this->getUsernameFilePattern($username)) as $filename) {
$sessionInfo = $this->fileToSessionInfo($filename);
if ($includeExpiredSessions || !$sessionInfo->isExpired()) {
$result[] = $sessionInfo;
}
}
usort(
$result,
function (SessionInformation $a, SessionInformation $b) {
return $a->getLastUsed() === $b->getLastUsed() ? 0 : $a->getLastUsed()>$b->getLastUsed() ? -1 : 1;
}
);
return $result;
} | php | public function getSessionInformations($username, $includeExpiredSessions = false)
{
$result = array();
foreach (glob($this->getUsernameFilePattern($username)) as $filename) {
$sessionInfo = $this->fileToSessionInfo($filename);
if ($includeExpiredSessions || !$sessionInfo->isExpired()) {
$result[] = $sessionInfo;
}
}
usort(
$result,
function (SessionInformation $a, SessionInformation $b) {
return $a->getLastUsed() === $b->getLastUsed() ? 0 : $a->getLastUsed()>$b->getLastUsed() ? -1 : 1;
}
);
return $result;
} | [
"public",
"function",
"getSessionInformations",
"(",
"$",
"username",
",",
"$",
"includeExpiredSessions",
"=",
"false",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"glob",
"(",
"$",
"this",
"->",
"getUsernameFilePattern",
"(",
"$",
"username",
")",
")",
"as",
"$",
"filename",
")",
"{",
"$",
"sessionInfo",
"=",
"$",
"this",
"->",
"fileToSessionInfo",
"(",
"$",
"filename",
")",
";",
"if",
"(",
"$",
"includeExpiredSessions",
"||",
"!",
"$",
"sessionInfo",
"->",
"isExpired",
"(",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"sessionInfo",
";",
"}",
"}",
"usort",
"(",
"$",
"result",
",",
"function",
"(",
"SessionInformation",
"$",
"a",
",",
"SessionInformation",
"$",
"b",
")",
"{",
"return",
"$",
"a",
"->",
"getLastUsed",
"(",
")",
"===",
"$",
"b",
"->",
"getLastUsed",
"(",
")",
"?",
"0",
":",
"$",
"a",
"->",
"getLastUsed",
"(",
")",
">",
"$",
"b",
"->",
"getLastUsed",
"(",
")",
"?",
"-",
"1",
":",
"1",
";",
"}",
")",
";",
"return",
"$",
"result",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/ajgarlag/AjglSessionConcurrency/blob/daa3b1ff3ad4951947f7192e12b2496555e135fb/src/Http/Session/Registry/Storage/FileSessionRegistryStorage.php#L58-L77 |
ajgarlag/AjglSessionConcurrency | src/Http/Session/Registry/Storage/FileSessionRegistryStorage.php | FileSessionRegistryStorage.saveSessionInformation | public function saveSessionInformation(SessionInformation $sessionInformation)
{
$filename = $this->getFilePath($sessionInformation);
file_put_contents($filename, serialize($sessionInformation));
/*
* Set the file mtime to last used
*/
touch($filename, $sessionInformation->getLastUsed());
} | php | public function saveSessionInformation(SessionInformation $sessionInformation)
{
$filename = $this->getFilePath($sessionInformation);
file_put_contents($filename, serialize($sessionInformation));
/*
* Set the file mtime to last used
*/
touch($filename, $sessionInformation->getLastUsed());
} | [
"public",
"function",
"saveSessionInformation",
"(",
"SessionInformation",
"$",
"sessionInformation",
")",
"{",
"$",
"filename",
"=",
"$",
"this",
"->",
"getFilePath",
"(",
"$",
"sessionInformation",
")",
";",
"file_put_contents",
"(",
"$",
"filename",
",",
"serialize",
"(",
"$",
"sessionInformation",
")",
")",
";",
"/*\n * Set the file mtime to last used\n */",
"touch",
"(",
"$",
"filename",
",",
"$",
"sessionInformation",
"->",
"getLastUsed",
"(",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/ajgarlag/AjglSessionConcurrency/blob/daa3b1ff3ad4951947f7192e12b2496555e135fb/src/Http/Session/Registry/Storage/FileSessionRegistryStorage.php#L82-L90 |
ajgarlag/AjglSessionConcurrency | src/Http/Session/Registry/Storage/FileSessionRegistryStorage.php | FileSessionRegistryStorage.collectGarbage | public function collectGarbage($maxLifetime)
{
$now = time();
foreach (glob($this->getSessionFilePattern('*')) as $filename) {
/*
* Check the file mtime like the native file-based session handler
* @see http://php.net/manual/en/session.configuration.php#ini.session.gc-maxlifetime
*/
if ($now - filemtime($filename) > $maxLifetime) {
$sessionInfo = $this->fileToSessionInfo($filename);
if ($now - $sessionInfo->getLastUsed() > $maxLifetime) {
unlink($filename);
} else {
/*
* If the file mtime is expired, but the session info is not expired, fix file mtime
*/
touch($filename, $sessionInfo->getLastUsed());
}
}
}
} | php | public function collectGarbage($maxLifetime)
{
$now = time();
foreach (glob($this->getSessionFilePattern('*')) as $filename) {
/*
* Check the file mtime like the native file-based session handler
* @see http://php.net/manual/en/session.configuration.php#ini.session.gc-maxlifetime
*/
if ($now - filemtime($filename) > $maxLifetime) {
$sessionInfo = $this->fileToSessionInfo($filename);
if ($now - $sessionInfo->getLastUsed() > $maxLifetime) {
unlink($filename);
} else {
/*
* If the file mtime is expired, but the session info is not expired, fix file mtime
*/
touch($filename, $sessionInfo->getLastUsed());
}
}
}
} | [
"public",
"function",
"collectGarbage",
"(",
"$",
"maxLifetime",
")",
"{",
"$",
"now",
"=",
"time",
"(",
")",
";",
"foreach",
"(",
"glob",
"(",
"$",
"this",
"->",
"getSessionFilePattern",
"(",
"'*'",
")",
")",
"as",
"$",
"filename",
")",
"{",
"/*\n * Check the file mtime like the native file-based session handler\n * @see http://php.net/manual/en/session.configuration.php#ini.session.gc-maxlifetime\n */",
"if",
"(",
"$",
"now",
"-",
"filemtime",
"(",
"$",
"filename",
")",
">",
"$",
"maxLifetime",
")",
"{",
"$",
"sessionInfo",
"=",
"$",
"this",
"->",
"fileToSessionInfo",
"(",
"$",
"filename",
")",
";",
"if",
"(",
"$",
"now",
"-",
"$",
"sessionInfo",
"->",
"getLastUsed",
"(",
")",
">",
"$",
"maxLifetime",
")",
"{",
"unlink",
"(",
"$",
"filename",
")",
";",
"}",
"else",
"{",
"/*\n * If the file mtime is expired, but the session info is not expired, fix file mtime\n */",
"touch",
"(",
"$",
"filename",
",",
"$",
"sessionInfo",
"->",
"getLastUsed",
"(",
")",
")",
";",
"}",
"}",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/ajgarlag/AjglSessionConcurrency/blob/daa3b1ff3ad4951947f7192e12b2496555e135fb/src/Http/Session/Registry/Storage/FileSessionRegistryStorage.php#L105-L125 |
rhosocial/yii2-user | models/log/Login.php | Login.deleteExtraRecords | protected function deleteExtraRecords()
{
try {
$limit = (int)($this->limitMax);
} catch (\Exception $ex) {
Yii::error($ex->getMessage(), __METHOD__);
return 0;
}
$host = $this->host;
/* @var $host \rhosocial\user\User */
$count = static::find()->createdBy($host)->count();
Yii::info($host->getReadableGUID() . " has $count login logs.", __METHOD__);
if ($count > $limit) {
foreach (static::find()->createdBy($host)->orderByCreatedAt()->limit($count - $limit)->all() as $login) {
/* @var $login static */
$result = $login->delete();
if (YII_ENV_DEV) {
Yii::info($host->getReadableGUID() . ": ($result) login record created at (" . $login->getCreatedAt() . ") was just deleted.", __METHOD__);
}
}
}
return $count - $limit;
} | php | protected function deleteExtraRecords()
{
try {
$limit = (int)($this->limitMax);
} catch (\Exception $ex) {
Yii::error($ex->getMessage(), __METHOD__);
return 0;
}
$host = $this->host;
/* @var $host \rhosocial\user\User */
$count = static::find()->createdBy($host)->count();
Yii::info($host->getReadableGUID() . " has $count login logs.", __METHOD__);
if ($count > $limit) {
foreach (static::find()->createdBy($host)->orderByCreatedAt()->limit($count - $limit)->all() as $login) {
/* @var $login static */
$result = $login->delete();
if (YII_ENV_DEV) {
Yii::info($host->getReadableGUID() . ": ($result) login record created at (" . $login->getCreatedAt() . ") was just deleted.", __METHOD__);
}
}
}
return $count - $limit;
} | [
"protected",
"function",
"deleteExtraRecords",
"(",
")",
"{",
"try",
"{",
"$",
"limit",
"=",
"(",
"int",
")",
"(",
"$",
"this",
"->",
"limitMax",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"Yii",
"::",
"error",
"(",
"$",
"ex",
"->",
"getMessage",
"(",
")",
",",
"__METHOD__",
")",
";",
"return",
"0",
";",
"}",
"$",
"host",
"=",
"$",
"this",
"->",
"host",
";",
"/* @var $host \\rhosocial\\user\\User */",
"$",
"count",
"=",
"static",
"::",
"find",
"(",
")",
"->",
"createdBy",
"(",
"$",
"host",
")",
"->",
"count",
"(",
")",
";",
"Yii",
"::",
"info",
"(",
"$",
"host",
"->",
"getReadableGUID",
"(",
")",
".",
"\" has $count login logs.\"",
",",
"__METHOD__",
")",
";",
"if",
"(",
"$",
"count",
">",
"$",
"limit",
")",
"{",
"foreach",
"(",
"static",
"::",
"find",
"(",
")",
"->",
"createdBy",
"(",
"$",
"host",
")",
"->",
"orderByCreatedAt",
"(",
")",
"->",
"limit",
"(",
"$",
"count",
"-",
"$",
"limit",
")",
"->",
"all",
"(",
")",
"as",
"$",
"login",
")",
"{",
"/* @var $login static */",
"$",
"result",
"=",
"$",
"login",
"->",
"delete",
"(",
")",
";",
"if",
"(",
"YII_ENV_DEV",
")",
"{",
"Yii",
"::",
"info",
"(",
"$",
"host",
"->",
"getReadableGUID",
"(",
")",
".",
"\": ($result) login record created at (\"",
".",
"$",
"login",
"->",
"getCreatedAt",
"(",
")",
".",
"\") was just deleted.\"",
",",
"__METHOD__",
")",
";",
"}",
"}",
"}",
"return",
"$",
"count",
"-",
"$",
"limit",
";",
"}"
] | Delete extra records.
@return integer The total of rows deleted. | [
"Delete",
"extra",
"records",
"."
] | train | https://github.com/rhosocial/yii2-user/blob/96737a9d8ca7e9c42cd2b7736d6c0a90ede6e5bc/models/log/Login.php#L102-L124 |
rhosocial/yii2-user | models/log/Login.php | Login.deleteExpiredRecords | protected function deleteExpiredRecords()
{
try {
$limit = (int)($this->limitDuration);
} catch (\Exception $ex) {
Yii::error($ex->getMessage(), __METHOD__);
return 0;
}
$count = 0;
$host = $this->host;
/* @var $host \rhosocial\user\User */
foreach (static::find()
->createdBy($host)
->andWhere(['<=', $this->createdAtAttribute, $this->offsetDatetime($this->currentUtcDatetime(), -$limit)])
->all() as $login) {
/* @var $login static */
$result = $login->delete();
$count += $result;
if (YII_ENV_DEV) {
Yii::info($host->getReadableGUID() . ": ($result) login record created at (" . $login->getCreatedAt() . ") was just deleted.", __METHOD__);
}
}
return $count;
} | php | protected function deleteExpiredRecords()
{
try {
$limit = (int)($this->limitDuration);
} catch (\Exception $ex) {
Yii::error($ex->getMessage(), __METHOD__);
return 0;
}
$count = 0;
$host = $this->host;
/* @var $host \rhosocial\user\User */
foreach (static::find()
->createdBy($host)
->andWhere(['<=', $this->createdAtAttribute, $this->offsetDatetime($this->currentUtcDatetime(), -$limit)])
->all() as $login) {
/* @var $login static */
$result = $login->delete();
$count += $result;
if (YII_ENV_DEV) {
Yii::info($host->getReadableGUID() . ": ($result) login record created at (" . $login->getCreatedAt() . ") was just deleted.", __METHOD__);
}
}
return $count;
} | [
"protected",
"function",
"deleteExpiredRecords",
"(",
")",
"{",
"try",
"{",
"$",
"limit",
"=",
"(",
"int",
")",
"(",
"$",
"this",
"->",
"limitDuration",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"Yii",
"::",
"error",
"(",
"$",
"ex",
"->",
"getMessage",
"(",
")",
",",
"__METHOD__",
")",
";",
"return",
"0",
";",
"}",
"$",
"count",
"=",
"0",
";",
"$",
"host",
"=",
"$",
"this",
"->",
"host",
";",
"/* @var $host \\rhosocial\\user\\User */",
"foreach",
"(",
"static",
"::",
"find",
"(",
")",
"->",
"createdBy",
"(",
"$",
"host",
")",
"->",
"andWhere",
"(",
"[",
"'<='",
",",
"$",
"this",
"->",
"createdAtAttribute",
",",
"$",
"this",
"->",
"offsetDatetime",
"(",
"$",
"this",
"->",
"currentUtcDatetime",
"(",
")",
",",
"-",
"$",
"limit",
")",
"]",
")",
"->",
"all",
"(",
")",
"as",
"$",
"login",
")",
"{",
"/* @var $login static */",
"$",
"result",
"=",
"$",
"login",
"->",
"delete",
"(",
")",
";",
"$",
"count",
"+=",
"$",
"result",
";",
"if",
"(",
"YII_ENV_DEV",
")",
"{",
"Yii",
"::",
"info",
"(",
"$",
"host",
"->",
"getReadableGUID",
"(",
")",
".",
"\": ($result) login record created at (\"",
".",
"$",
"login",
"->",
"getCreatedAt",
"(",
")",
".",
"\") was just deleted.\"",
",",
"__METHOD__",
")",
";",
"}",
"}",
"return",
"$",
"count",
";",
"}"
] | Delete expired records.
@return integer The total of rows deleted. | [
"Delete",
"expired",
"records",
"."
] | train | https://github.com/rhosocial/yii2-user/blob/96737a9d8ca7e9c42cd2b7736d6c0a90ede6e5bc/models/log/Login.php#L130-L153 |
nabab/bbn | src/bbn/mvc/model.php | model.has_data | public function has_data($idx=null)
{
if ( !\is_array($this->data) ){
return false;
}
if ( \is_null($idx) ){
return !empty($this->data);
}
$args = \func_get_args();
foreach ( $args as $arg ){
if ( !isset($this->data[$idx]) ){
return false;
}
}
return true;
} | php | public function has_data($idx=null)
{
if ( !\is_array($this->data) ){
return false;
}
if ( \is_null($idx) ){
return !empty($this->data);
}
$args = \func_get_args();
foreach ( $args as $arg ){
if ( !isset($this->data[$idx]) ){
return false;
}
}
return true;
} | [
"public",
"function",
"has_data",
"(",
"$",
"idx",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"this",
"->",
"data",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"\\",
"is_null",
"(",
"$",
"idx",
")",
")",
"{",
"return",
"!",
"empty",
"(",
"$",
"this",
"->",
"data",
")",
";",
"}",
"$",
"args",
"=",
"\\",
"func_get_args",
"(",
")",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"arg",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"idx",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Checks if data exists or if a specific index exists in the data
@return bool | [
"Checks",
"if",
"data",
"exists",
"or",
"if",
"a",
"specific",
"index",
"exists",
"in",
"the",
"data"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/mvc/model.php#L145-L160 |
nabab/bbn | src/bbn/mvc/model.php | model.add_data | public function add_data(array $data)
{
$ar = \func_get_args();
foreach ( $ar as $d ){
if ( \is_array($d) ){
$this->data = $this->has_data() ? array_merge($this->data,$d) : $d;
}
}
return $this;
} | php | public function add_data(array $data)
{
$ar = \func_get_args();
foreach ( $ar as $d ){
if ( \is_array($d) ){
$this->data = $this->has_data() ? array_merge($this->data,$d) : $d;
}
}
return $this;
} | [
"public",
"function",
"add_data",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"ar",
"=",
"\\",
"func_get_args",
"(",
")",
";",
"foreach",
"(",
"$",
"ar",
"as",
"$",
"d",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"d",
")",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"$",
"this",
"->",
"has_data",
"(",
")",
"?",
"array_merge",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"d",
")",
":",
"$",
"d",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Merges the existing data if there is with this one. Chainable.
@return void | [
"Merges",
"the",
"existing",
"data",
"if",
"there",
"is",
"with",
"this",
"one",
".",
"Chainable",
"."
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/mvc/model.php#L179-L188 |
JBZoo/Assets | src/Asset/File.php | File._findSource | protected function _findSource()
{
$path = $this->_manager->getPath();
if ($path->isVirtual($this->_source)) {
$path = $path->get($this->_source);
$isStrictMode = $this->_manager->getParams()->get('strict_mode', false, 'bool');
if ($isStrictMode && !$path) {
throw new Exception("Asset file not found: {$this->_source}");
}
return $path;
}
if (Url::isAbsolute($this->_source)) {
return $this->_source;
}
$fullPath = $path->get('root:' . $this->_source);
return $fullPath;
} | php | protected function _findSource()
{
$path = $this->_manager->getPath();
if ($path->isVirtual($this->_source)) {
$path = $path->get($this->_source);
$isStrictMode = $this->_manager->getParams()->get('strict_mode', false, 'bool');
if ($isStrictMode && !$path) {
throw new Exception("Asset file not found: {$this->_source}");
}
return $path;
}
if (Url::isAbsolute($this->_source)) {
return $this->_source;
}
$fullPath = $path->get('root:' . $this->_source);
return $fullPath;
} | [
"protected",
"function",
"_findSource",
"(",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"_manager",
"->",
"getPath",
"(",
")",
";",
"if",
"(",
"$",
"path",
"->",
"isVirtual",
"(",
"$",
"this",
"->",
"_source",
")",
")",
"{",
"$",
"path",
"=",
"$",
"path",
"->",
"get",
"(",
"$",
"this",
"->",
"_source",
")",
";",
"$",
"isStrictMode",
"=",
"$",
"this",
"->",
"_manager",
"->",
"getParams",
"(",
")",
"->",
"get",
"(",
"'strict_mode'",
",",
"false",
",",
"'bool'",
")",
";",
"if",
"(",
"$",
"isStrictMode",
"&&",
"!",
"$",
"path",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Asset file not found: {$this->_source}\"",
")",
";",
"}",
"return",
"$",
"path",
";",
"}",
"if",
"(",
"Url",
"::",
"isAbsolute",
"(",
"$",
"this",
"->",
"_source",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_source",
";",
"}",
"$",
"fullPath",
"=",
"$",
"path",
"->",
"get",
"(",
"'root:'",
".",
"$",
"this",
"->",
"_source",
")",
";",
"return",
"$",
"fullPath",
";",
"}"
] | Find source in variants.
@return string|array
@throws Exception | [
"Find",
"source",
"in",
"variants",
"."
] | train | https://github.com/JBZoo/Assets/blob/134a109378f5b5e955dfb15e6ed2821581564991/src/Asset/File.php#L46-L68 |
FriendsOfApi/phraseapp | src/Model/Translation/TranslationUpdated.php | TranslationUpdated.createFromArray | public static function createFromArray(array $data)
{
$self = new self();
if (isset($data['id'])) {
$self->setId($data['id']);
}
if (isset($data['content'])) {
$self->setContent($data['content']);
}
if (isset($data['unverified'])) {
$self->setUnverified($data['unverified']);
}
if (isset($data['excluded'])) {
$self->setExcluded($data['excluded']);
}
if (isset($data['plural_suffix'])) {
$self->setPluralSuffix($data['plural_suffix']);
}
if (isset($data['created_at'])) {
$self->setCreatedAt($data['created_at']);
}
if (isset($data['updated_at'])) {
$self->setUpdatedAt($data['updated_at']);
}
if (isset($data['placeholders'])) {
$self->setPlaceholders($data['placeholders']);
}
if (isset($data['word_count'])) {
$self->setWordCount($data['word_count']);
}
if (isset($data['key']) && is_array($data['key'])) {
$self->setKey(Key::createFromArray($data['key']));
}
if (isset($data['locale']) && is_array($data['locale'])) {
$self->setLocale(Locale::createFromArray($data['locale']));
}
if (isset($data['user']) && is_array($data['user'])) {
$self->setUser(User::createFromArray($data['user']));
}
return $self;
} | php | public static function createFromArray(array $data)
{
$self = new self();
if (isset($data['id'])) {
$self->setId($data['id']);
}
if (isset($data['content'])) {
$self->setContent($data['content']);
}
if (isset($data['unverified'])) {
$self->setUnverified($data['unverified']);
}
if (isset($data['excluded'])) {
$self->setExcluded($data['excluded']);
}
if (isset($data['plural_suffix'])) {
$self->setPluralSuffix($data['plural_suffix']);
}
if (isset($data['created_at'])) {
$self->setCreatedAt($data['created_at']);
}
if (isset($data['updated_at'])) {
$self->setUpdatedAt($data['updated_at']);
}
if (isset($data['placeholders'])) {
$self->setPlaceholders($data['placeholders']);
}
if (isset($data['word_count'])) {
$self->setWordCount($data['word_count']);
}
if (isset($data['key']) && is_array($data['key'])) {
$self->setKey(Key::createFromArray($data['key']));
}
if (isset($data['locale']) && is_array($data['locale'])) {
$self->setLocale(Locale::createFromArray($data['locale']));
}
if (isset($data['user']) && is_array($data['user'])) {
$self->setUser(User::createFromArray($data['user']));
}
return $self;
} | [
"public",
"static",
"function",
"createFromArray",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"self",
"=",
"new",
"self",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"self",
"->",
"setId",
"(",
"$",
"data",
"[",
"'id'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'content'",
"]",
")",
")",
"{",
"$",
"self",
"->",
"setContent",
"(",
"$",
"data",
"[",
"'content'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'unverified'",
"]",
")",
")",
"{",
"$",
"self",
"->",
"setUnverified",
"(",
"$",
"data",
"[",
"'unverified'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'excluded'",
"]",
")",
")",
"{",
"$",
"self",
"->",
"setExcluded",
"(",
"$",
"data",
"[",
"'excluded'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'plural_suffix'",
"]",
")",
")",
"{",
"$",
"self",
"->",
"setPluralSuffix",
"(",
"$",
"data",
"[",
"'plural_suffix'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'created_at'",
"]",
")",
")",
"{",
"$",
"self",
"->",
"setCreatedAt",
"(",
"$",
"data",
"[",
"'created_at'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'updated_at'",
"]",
")",
")",
"{",
"$",
"self",
"->",
"setUpdatedAt",
"(",
"$",
"data",
"[",
"'updated_at'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'placeholders'",
"]",
")",
")",
"{",
"$",
"self",
"->",
"setPlaceholders",
"(",
"$",
"data",
"[",
"'placeholders'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'word_count'",
"]",
")",
")",
"{",
"$",
"self",
"->",
"setWordCount",
"(",
"$",
"data",
"[",
"'word_count'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'key'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"data",
"[",
"'key'",
"]",
")",
")",
"{",
"$",
"self",
"->",
"setKey",
"(",
"Key",
"::",
"createFromArray",
"(",
"$",
"data",
"[",
"'key'",
"]",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'locale'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"data",
"[",
"'locale'",
"]",
")",
")",
"{",
"$",
"self",
"->",
"setLocale",
"(",
"Locale",
"::",
"createFromArray",
"(",
"$",
"data",
"[",
"'locale'",
"]",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'user'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"data",
"[",
"'user'",
"]",
")",
")",
"{",
"$",
"self",
"->",
"setUser",
"(",
"User",
"::",
"createFromArray",
"(",
"$",
"data",
"[",
"'user'",
"]",
")",
")",
";",
"}",
"return",
"$",
"self",
";",
"}"
] | @param array $data
@return TranslationUpdated | [
"@param",
"array",
"$data"
] | train | https://github.com/FriendsOfApi/phraseapp/blob/1553bf857eb0858f9a7eb905b085864d24f80886/src/Model/Translation/TranslationUpdated.php#L84-L126 |
SporkCode/Spork | src/View/Helper/Date.php | Date.createService | public function createService(ServiceLocatorInterface $serviceLocator)
{
$appConfig = $serviceLocator;
$config = array_key_exists($appConfig['view_helper_date']) ? $appConfig['view_helper_date'] : array();
if (array_key_exists('formats', $config)) {
$this->addFormats($config['formats']);
}
} | php | public function createService(ServiceLocatorInterface $serviceLocator)
{
$appConfig = $serviceLocator;
$config = array_key_exists($appConfig['view_helper_date']) ? $appConfig['view_helper_date'] : array();
if (array_key_exists('formats', $config)) {
$this->addFormats($config['formats']);
}
} | [
"public",
"function",
"createService",
"(",
"ServiceLocatorInterface",
"$",
"serviceLocator",
")",
"{",
"$",
"appConfig",
"=",
"$",
"serviceLocator",
";",
"$",
"config",
"=",
"array_key_exists",
"(",
"$",
"appConfig",
"[",
"'view_helper_date'",
"]",
")",
"?",
"$",
"appConfig",
"[",
"'view_helper_date'",
"]",
":",
"array",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'formats'",
",",
"$",
"config",
")",
")",
"{",
"$",
"this",
"->",
"addFormats",
"(",
"$",
"config",
"[",
"'formats'",
"]",
")",
";",
"}",
"}"
] | Create and configure instance
@see \Zend\ServiceManager\FactoryInterface::createService()
@param ServiceLocatorInterface $serviceLocator | [
"Create",
"and",
"configure",
"instance"
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/View/Helper/Date.php#L57-L64 |
SporkCode/Spork | src/View/Helper/Date.php | Date.addFormats | public function addFormats(array $formats)
{
foreach ($formats as $name => $format) {
$this->formats[$name] = $format;
}
} | php | public function addFormats(array $formats)
{
foreach ($formats as $name => $format) {
$this->formats[$name] = $format;
}
} | [
"public",
"function",
"addFormats",
"(",
"array",
"$",
"formats",
")",
"{",
"foreach",
"(",
"$",
"formats",
"as",
"$",
"name",
"=>",
"$",
"format",
")",
"{",
"$",
"this",
"->",
"formats",
"[",
"$",
"name",
"]",
"=",
"$",
"format",
";",
"}",
"}"
] | Add datetime formats
@param array $formats | [
"Add",
"datetime",
"formats"
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/View/Helper/Date.php#L101-L106 |
canis-io/yii2-broadcaster | lib/Bootstrap.php | Bootstrap.bootstrap | public function bootstrap($app)
{
$app->registerMigrationAlias('@canis/broadcaster/migrations');
$app->setModule('broadcaster', ['class' => Module::className()]);
$module = $app->getModule('broadcaster');
$module->registerHandlers($this->initialHandlers);
$module->registerEventTypes($this->initialEventTypes);
Event::on(Daemon::className(), Daemon::EVENT_REGISTER_DAEMONS, [$this, 'registerDaemon']);
// Event::on(Cron::className(), Cron::EVENT_WEEKLY, [$module, 'weeklyEmailDigest']);
// Event::on(Cron::className(), Cron::EVENT_MORNING, [$module, 'dailyEmailDigest']);
} | php | public function bootstrap($app)
{
$app->registerMigrationAlias('@canis/broadcaster/migrations');
$app->setModule('broadcaster', ['class' => Module::className()]);
$module = $app->getModule('broadcaster');
$module->registerHandlers($this->initialHandlers);
$module->registerEventTypes($this->initialEventTypes);
Event::on(Daemon::className(), Daemon::EVENT_REGISTER_DAEMONS, [$this, 'registerDaemon']);
// Event::on(Cron::className(), Cron::EVENT_WEEKLY, [$module, 'weeklyEmailDigest']);
// Event::on(Cron::className(), Cron::EVENT_MORNING, [$module, 'dailyEmailDigest']);
} | [
"public",
"function",
"bootstrap",
"(",
"$",
"app",
")",
"{",
"$",
"app",
"->",
"registerMigrationAlias",
"(",
"'@canis/broadcaster/migrations'",
")",
";",
"$",
"app",
"->",
"setModule",
"(",
"'broadcaster'",
",",
"[",
"'class'",
"=>",
"Module",
"::",
"className",
"(",
")",
"]",
")",
";",
"$",
"module",
"=",
"$",
"app",
"->",
"getModule",
"(",
"'broadcaster'",
")",
";",
"$",
"module",
"->",
"registerHandlers",
"(",
"$",
"this",
"->",
"initialHandlers",
")",
";",
"$",
"module",
"->",
"registerEventTypes",
"(",
"$",
"this",
"->",
"initialEventTypes",
")",
";",
"Event",
"::",
"on",
"(",
"Daemon",
"::",
"className",
"(",
")",
",",
"Daemon",
"::",
"EVENT_REGISTER_DAEMONS",
",",
"[",
"$",
"this",
",",
"'registerDaemon'",
"]",
")",
";",
"// Event::on(Cron::className(), Cron::EVENT_WEEKLY, [$module, 'weeklyEmailDigest']);",
"// Event::on(Cron::className(), Cron::EVENT_MORNING, [$module, 'dailyEmailDigest']);",
"}"
] | [[@doctodo method_description:bootstrap]].
@param [[@doctodo param_type:app]] $app [[@doctodo param_description:app]] | [
"[[",
"@doctodo",
"method_description",
":",
"bootstrap",
"]]",
"."
] | train | https://github.com/canis-io/yii2-broadcaster/blob/b8d7b5b24f2d8f4fdb29132dd85df34602dcd6b1/lib/Bootstrap.php#L26-L39 |
antaresproject/notifications | src/Http/Filter/NotificationAreaFilter.php | NotificationAreaFilter.options | protected function options()
{
$areas = app(AreaManager::class)->getAreas();
$options = [];
foreach ($areas as $area) {
array_set($options, $area->getId(), $area->getLabel());
}
return $options;
} | php | protected function options()
{
$areas = app(AreaManager::class)->getAreas();
$options = [];
foreach ($areas as $area) {
array_set($options, $area->getId(), $area->getLabel());
}
return $options;
} | [
"protected",
"function",
"options",
"(",
")",
"{",
"$",
"areas",
"=",
"app",
"(",
"AreaManager",
"::",
"class",
")",
"->",
"getAreas",
"(",
")",
";",
"$",
"options",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"areas",
"as",
"$",
"area",
")",
"{",
"array_set",
"(",
"$",
"options",
",",
"$",
"area",
"->",
"getId",
"(",
")",
",",
"$",
"area",
"->",
"getLabel",
"(",
")",
")",
";",
"}",
"return",
"$",
"options",
";",
"}"
] | Filter instance dataprovider
@return Collection | [
"Filter",
"instance",
"dataprovider"
] | train | https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Http/Filter/NotificationAreaFilter.php#L61-L69 |
ekuiter/feature-php | FeaturePhp/Helper/_Array.php | _Array.findByKey | public static function findByKey($array, $key, $value) {
foreach ($array as $element)
if (call_user_func(array($element, $key)) === $value)
return $element;
return null;
} | php | public static function findByKey($array, $key, $value) {
foreach ($array as $element)
if (call_user_func(array($element, $key)) === $value)
return $element;
return null;
} | [
"public",
"static",
"function",
"findByKey",
"(",
"$",
"array",
",",
"$",
"key",
",",
"$",
"value",
")",
"{",
"foreach",
"(",
"$",
"array",
"as",
"$",
"element",
")",
"if",
"(",
"call_user_func",
"(",
"array",
"(",
"$",
"element",
",",
"$",
"key",
")",
")",
"===",
"$",
"value",
")",
"return",
"$",
"element",
";",
"return",
"null",
";",
"}"
] | Finds an array element by comparing a member with the given value.
@param array $array
@param callable $key
@param mixed $value
@return object | [
"Finds",
"an",
"array",
"element",
"by",
"comparing",
"a",
"member",
"with",
"the",
"given",
"value",
"."
] | train | https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Helper/_Array.php#L26-L31 |
ekuiter/feature-php | FeaturePhp/Helper/_Array.php | _Array.assertNoDuplicates | public static function assertNoDuplicates($_array, $key) {
$array = $_array;
while (count($array) > 0) {
$element = $array[0];
$array = array_slice($array, 1);
$value = call_user_func(array($element, $key));
if (self::findByKey($array, $key, $value))
throw new ArrayException("duplicate found for \"$value\"");
}
return $_array;
} | php | public static function assertNoDuplicates($_array, $key) {
$array = $_array;
while (count($array) > 0) {
$element = $array[0];
$array = array_slice($array, 1);
$value = call_user_func(array($element, $key));
if (self::findByKey($array, $key, $value))
throw new ArrayException("duplicate found for \"$value\"");
}
return $_array;
} | [
"public",
"static",
"function",
"assertNoDuplicates",
"(",
"$",
"_array",
",",
"$",
"key",
")",
"{",
"$",
"array",
"=",
"$",
"_array",
";",
"while",
"(",
"count",
"(",
"$",
"array",
")",
">",
"0",
")",
"{",
"$",
"element",
"=",
"$",
"array",
"[",
"0",
"]",
";",
"$",
"array",
"=",
"array_slice",
"(",
"$",
"array",
",",
"1",
")",
";",
"$",
"value",
"=",
"call_user_func",
"(",
"array",
"(",
"$",
"element",
",",
"$",
"key",
")",
")",
";",
"if",
"(",
"self",
"::",
"findByKey",
"(",
"$",
"array",
",",
"$",
"key",
",",
"$",
"value",
")",
")",
"throw",
"new",
"ArrayException",
"(",
"\"duplicate found for \\\"$value\\\"\"",
")",
";",
"}",
"return",
"$",
"_array",
";",
"}"
] | Asserts that an array does not contain duplicates regarding a member.
Throws {@see \FeaturePhp\Helper\ArrayException} if duplicates are found.
@param array $_array
@param callable $key
@return array | [
"Asserts",
"that",
"an",
"array",
"does",
"not",
"contain",
"duplicates",
"regarding",
"a",
"member",
".",
"Throws",
"{"
] | train | https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Helper/_Array.php#L40-L50 |
ekuiter/feature-php | FeaturePhp/Helper/_Array.php | _Array.sortByKey | public static function sortByKey($_array, $key) {
$array = $_array;
$result = usort($array, function($a, $b) use ($key) {
return strcmp(call_user_func(array($a, $key)),
call_user_func(array($b, $key)));
});
if (!$result)
throw new ArrayException("sorting by \"$key\" failed");
return $array;
} | php | public static function sortByKey($_array, $key) {
$array = $_array;
$result = usort($array, function($a, $b) use ($key) {
return strcmp(call_user_func(array($a, $key)),
call_user_func(array($b, $key)));
});
if (!$result)
throw new ArrayException("sorting by \"$key\" failed");
return $array;
} | [
"public",
"static",
"function",
"sortByKey",
"(",
"$",
"_array",
",",
"$",
"key",
")",
"{",
"$",
"array",
"=",
"$",
"_array",
";",
"$",
"result",
"=",
"usort",
"(",
"$",
"array",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"use",
"(",
"$",
"key",
")",
"{",
"return",
"strcmp",
"(",
"call_user_func",
"(",
"array",
"(",
"$",
"a",
",",
"$",
"key",
")",
")",
",",
"call_user_func",
"(",
"array",
"(",
"$",
"b",
",",
"$",
"key",
")",
")",
")",
";",
"}",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"throw",
"new",
"ArrayException",
"(",
"\"sorting by \\\"$key\\\" failed\"",
")",
";",
"return",
"$",
"array",
";",
"}"
] | Sorts an array in ascending order regarding a member.
@param array $_array
@param callable $key
@return array | [
"Sorts",
"an",
"array",
"in",
"ascending",
"order",
"regarding",
"a",
"member",
"."
] | train | https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Helper/_Array.php#L58-L67 |
ekuiter/feature-php | FeaturePhp/Helper/_Array.php | _Array.schwartzianTransform | public static function schwartzianTransform($_array, $func) {
$array = $_array;
array_walk($array, function(&$v) use ($func) {
$v = array($v, call_user_func($func, $v));
});
usort($array, function($a, $b) {
return strcmp($a[1], $b[1]);
});
array_walk($array, function(&$v) {
$v = $v[0];
});
return $array;
} | php | public static function schwartzianTransform($_array, $func) {
$array = $_array;
array_walk($array, function(&$v) use ($func) {
$v = array($v, call_user_func($func, $v));
});
usort($array, function($a, $b) {
return strcmp($a[1], $b[1]);
});
array_walk($array, function(&$v) {
$v = $v[0];
});
return $array;
} | [
"public",
"static",
"function",
"schwartzianTransform",
"(",
"$",
"_array",
",",
"$",
"func",
")",
"{",
"$",
"array",
"=",
"$",
"_array",
";",
"array_walk",
"(",
"$",
"array",
",",
"function",
"(",
"&",
"$",
"v",
")",
"use",
"(",
"$",
"func",
")",
"{",
"$",
"v",
"=",
"array",
"(",
"$",
"v",
",",
"call_user_func",
"(",
"$",
"func",
",",
"$",
"v",
")",
")",
";",
"}",
")",
";",
"usort",
"(",
"$",
"array",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"return",
"strcmp",
"(",
"$",
"a",
"[",
"1",
"]",
",",
"$",
"b",
"[",
"1",
"]",
")",
";",
"}",
")",
";",
"array_walk",
"(",
"$",
"array",
",",
"function",
"(",
"&",
"$",
"v",
")",
"{",
"$",
"v",
"=",
"$",
"v",
"[",
"0",
"]",
";",
"}",
")",
";",
"return",
"$",
"array",
";",
"}"
] | Sorts an array regarding a custom key using the decorate-sort-undecorate pattern.
This is useful if the key should only be calculated once per element
({@see https://gregheo.com/blog/schwartzian-transform/}).
@param array $_array
@param callable $func extracts a string value from an element
@return array | [
"Sorts",
"an",
"array",
"regarding",
"a",
"custom",
"key",
"using",
"the",
"decorate",
"-",
"sort",
"-",
"undecorate",
"pattern",
".",
"This",
"is",
"useful",
"if",
"the",
"key",
"should",
"only",
"be",
"calculated",
"once",
"per",
"element",
"(",
"{"
] | train | https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Helper/_Array.php#L77-L89 |
j-d/draggy | src/Draggy/Utils/Indenter/AbstractIndenter.php | AbstractIndenter.getLine | public function getLine($lineNumber)
{
return isset($this->lines[$lineNumber])
? $this->lines[$lineNumber]
: null;
} | php | public function getLine($lineNumber)
{
return isset($this->lines[$lineNumber])
? $this->lines[$lineNumber]
: null;
} | [
"public",
"function",
"getLine",
"(",
"$",
"lineNumber",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"lines",
"[",
"$",
"lineNumber",
"]",
")",
"?",
"$",
"this",
"->",
"lines",
"[",
"$",
"lineNumber",
"]",
":",
"null",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Utils/Indenter/AbstractIndenter.php#L70-L75 |
j-d/draggy | src/Draggy/Utils/Indenter/AbstractIndenter.php | AbstractIndenter.getOutputLine | public function getOutputLine($lineNumber)
{
return isset($this->outputLines[$lineNumber])
? $this->outputLines[$lineNumber]
: null;
} | php | public function getOutputLine($lineNumber)
{
return isset($this->outputLines[$lineNumber])
? $this->outputLines[$lineNumber]
: null;
} | [
"public",
"function",
"getOutputLine",
"(",
"$",
"lineNumber",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"outputLines",
"[",
"$",
"lineNumber",
"]",
")",
"?",
"$",
"this",
"->",
"outputLines",
"[",
"$",
"lineNumber",
"]",
":",
"null",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Utils/Indenter/AbstractIndenter.php#L88-L93 |
j-d/draggy | src/Draggy/Utils/Indenter/AbstractIndenter.php | AbstractIndenter.indentLines | public function indentLines($startLine, $endLine)
{
for ($i = $startLine; $i <= $endLine; $i++) {
if ('' !== $this->lines[$i]) { // Don't indent blank lines
$this->outputLines[$i] = $this->indentation . $this->outputLines[$i];
}
}
} | php | public function indentLines($startLine, $endLine)
{
for ($i = $startLine; $i <= $endLine; $i++) {
if ('' !== $this->lines[$i]) { // Don't indent blank lines
$this->outputLines[$i] = $this->indentation . $this->outputLines[$i];
}
}
} | [
"public",
"function",
"indentLines",
"(",
"$",
"startLine",
",",
"$",
"endLine",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"$",
"startLine",
";",
"$",
"i",
"<=",
"$",
"endLine",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"''",
"!==",
"$",
"this",
"->",
"lines",
"[",
"$",
"i",
"]",
")",
"{",
"// Don't indent blank lines",
"$",
"this",
"->",
"outputLines",
"[",
"$",
"i",
"]",
"=",
"$",
"this",
"->",
"indentation",
".",
"$",
"this",
"->",
"outputLines",
"[",
"$",
"i",
"]",
";",
"}",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Utils/Indenter/AbstractIndenter.php#L106-L113 |
j-d/draggy | src/Draggy/Utils/Indenter/AbstractIndenter.php | AbstractIndenter.indentFromSourceFile | public function indentFromSourceFile($sourceFile)
{
$this->initialiseFromSourceFile($sourceFile);
$this->indent();
return implode($this->eol, $this->outputLines);
} | php | public function indentFromSourceFile($sourceFile)
{
$this->initialiseFromSourceFile($sourceFile);
$this->indent();
return implode($this->eol, $this->outputLines);
} | [
"public",
"function",
"indentFromSourceFile",
"(",
"$",
"sourceFile",
")",
"{",
"$",
"this",
"->",
"initialiseFromSourceFile",
"(",
"$",
"sourceFile",
")",
";",
"$",
"this",
"->",
"indent",
"(",
")",
";",
"return",
"implode",
"(",
"$",
"this",
"->",
"eol",
",",
"$",
"this",
"->",
"outputLines",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Utils/Indenter/AbstractIndenter.php#L161-L168 |
j-d/draggy | src/Draggy/Utils/Indenter/AbstractIndenter.php | AbstractIndenter.prepareToIndent | protected function prepareToIndent()
{
foreach ($this->lines as $lineNumber => $line) {
$this->lines[$lineNumber] = trim($line);
}
$this->outputLines = $this->lines;
} | php | protected function prepareToIndent()
{
foreach ($this->lines as $lineNumber => $line) {
$this->lines[$lineNumber] = trim($line);
}
$this->outputLines = $this->lines;
} | [
"protected",
"function",
"prepareToIndent",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"lines",
"as",
"$",
"lineNumber",
"=>",
"$",
"line",
")",
"{",
"$",
"this",
"->",
"lines",
"[",
"$",
"lineNumber",
"]",
"=",
"trim",
"(",
"$",
"line",
")",
";",
"}",
"$",
"this",
"->",
"outputLines",
"=",
"$",
"this",
"->",
"lines",
";",
"}"
] | Pre-process all the lines so they are ready to be indented | [
"Pre",
"-",
"process",
"all",
"the",
"lines",
"so",
"they",
"are",
"ready",
"to",
"be",
"indented"
] | train | https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Utils/Indenter/AbstractIndenter.php#L181-L188 |
NuclearCMS/Hierarchy | src/Tags/TagTranslation.php | TagTranslation.boot | public static function boot()
{
TagTranslation::saving(function ($translation)
{
if (empty($translation->getTagName()) || is_null($translation->getTagName()))
{
$translation->setSlugFromTitle();
}
});
} | php | public static function boot()
{
TagTranslation::saving(function ($translation)
{
if (empty($translation->getTagName()) || is_null($translation->getTagName()))
{
$translation->setSlugFromTitle();
}
});
} | [
"public",
"static",
"function",
"boot",
"(",
")",
"{",
"TagTranslation",
"::",
"saving",
"(",
"function",
"(",
"$",
"translation",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"translation",
"->",
"getTagName",
"(",
")",
")",
"||",
"is_null",
"(",
"$",
"translation",
"->",
"getTagName",
"(",
")",
")",
")",
"{",
"$",
"translation",
"->",
"setSlugFromTitle",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] | Boot the model | [
"Boot",
"the",
"model"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Tags/TagTranslation.php#L23-L32 |
Danack/GithubArtaxService | lib/GithubService/Operation/searchRepos.php | searchRepos.createAndExecute | public function createAndExecute() {
$request = $this->createRequest();
$response = $this->api->execute($request, $this);
$this->response = $response;
return $response;
} | php | public function createAndExecute() {
$request = $this->createRequest();
$response = $this->api->execute($request, $this);
$this->response = $response;
return $response;
} | [
"public",
"function",
"createAndExecute",
"(",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"createRequest",
"(",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"api",
"->",
"execute",
"(",
"$",
"request",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"response",
"=",
"$",
"response",
";",
"return",
"$",
"response",
";",
"}"
] | Create and execute the operation, returning the raw response from the server.
@return \Amp\Artax\Response | [
"Create",
"and",
"execute",
"the",
"operation",
"returning",
"the",
"raw",
"response",
"from",
"the",
"server",
"."
] | train | https://github.com/Danack/GithubArtaxService/blob/9f62b5be4f413207d4012e7fa084d0ae505680eb/lib/GithubService/Operation/searchRepos.php#L289-L295 |
Danack/GithubArtaxService | lib/GithubService/Operation/searchRepos.php | searchRepos.call | public function call() {
$request = $this->createRequest();
$response = $this->api->execute($request, $this);
$this->response = $response;
if ($this->shouldResponseBeProcessed($response)) {
$instance = $this->api->instantiateResult($response, $this);
return $instance;
}
return $response;
} | php | public function call() {
$request = $this->createRequest();
$response = $this->api->execute($request, $this);
$this->response = $response;
if ($this->shouldResponseBeProcessed($response)) {
$instance = $this->api->instantiateResult($response, $this);
return $instance;
}
return $response;
} | [
"public",
"function",
"call",
"(",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"createRequest",
"(",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"api",
"->",
"execute",
"(",
"$",
"request",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"response",
"=",
"$",
"response",
";",
"if",
"(",
"$",
"this",
"->",
"shouldResponseBeProcessed",
"(",
"$",
"response",
")",
")",
"{",
"$",
"instance",
"=",
"$",
"this",
"->",
"api",
"->",
"instantiateResult",
"(",
"$",
"response",
",",
"$",
"this",
")",
";",
"return",
"$",
"instance",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Create and execute the operation, then return the processed response.
@return mixed|\GithubService\Model\SearchRepos | [
"Create",
"and",
"execute",
"the",
"operation",
"then",
"return",
"the",
"processed",
"response",
"."
] | train | https://github.com/Danack/GithubArtaxService/blob/9f62b5be4f413207d4012e7fa084d0ae505680eb/lib/GithubService/Operation/searchRepos.php#L302-L313 |
Danack/GithubArtaxService | lib/GithubService/Operation/searchRepos.php | searchRepos.dispatch | public function dispatch(\Amp\Artax\Request $request) {
$response = $this->api->execute($request, $this);
$this->response = $response;
$instance = $this->api->instantiateResult($response, $this);
return $instance;
} | php | public function dispatch(\Amp\Artax\Request $request) {
$response = $this->api->execute($request, $this);
$this->response = $response;
$instance = $this->api->instantiateResult($response, $this);
return $instance;
} | [
"public",
"function",
"dispatch",
"(",
"\\",
"Amp",
"\\",
"Artax",
"\\",
"Request",
"$",
"request",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"api",
"->",
"execute",
"(",
"$",
"request",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"response",
"=",
"$",
"response",
";",
"$",
"instance",
"=",
"$",
"this",
"->",
"api",
"->",
"instantiateResult",
"(",
"$",
"response",
",",
"$",
"this",
")",
";",
"return",
"$",
"instance",
";",
"}"
] | Dispatch the request for this operation and process the response. Allows you to
modify the request before it is sent.
@return \GithubService\Model\SearchRepos
@param \Amp\Artax\Request $request The request to be processed | [
"Dispatch",
"the",
"request",
"for",
"this",
"operation",
"and",
"process",
"the",
"response",
".",
"Allows",
"you",
"to",
"modify",
"the",
"request",
"before",
"it",
"is",
"sent",
"."
] | train | https://github.com/Danack/GithubArtaxService/blob/9f62b5be4f413207d4012e7fa084d0ae505680eb/lib/GithubService/Operation/searchRepos.php#L343-L349 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.