repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
Wedeto/Util | src/Cache/Item.php | Item.unserialize | public function unserialize($data)
{
$data = unserialize($data);
$this->key = $data['key'];
$this->value = $data['value'];
$this->expires = $data['expires'];
$this->hit = $data['hit'];
} | php | public function unserialize($data)
{
$data = unserialize($data);
$this->key = $data['key'];
$this->value = $data['value'];
$this->expires = $data['expires'];
$this->hit = $data['hit'];
} | [
"public",
"function",
"unserialize",
"(",
"$",
"data",
")",
"{",
"$",
"data",
"=",
"unserialize",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"key",
"=",
"$",
"data",
"[",
"'key'",
"]",
";",
"$",
"this",
"->",
"value",
"=",
"$",
"data",
"[",
"'value'",
"]",
";",
"$",
"this",
"->",
"expires",
"=",
"$",
"data",
"[",
"'expires'",
"]",
";",
"$",
"this",
"->",
"hit",
"=",
"$",
"data",
"[",
"'hit'",
"]",
";",
"}"
] | Unserialize the item. Required for storing in the containing cache
@param string $data The data to unserialize | [
"Unserialize",
"the",
"item",
".",
"Required",
"for",
"storing",
"in",
"the",
"containing",
"cache"
] | 0e080251bbaa8e7d91ae8d02eb79c029c976744a | https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/Cache/Item.php#L204-L211 | train |
ekyna/Table | Extension/Core/Source/ArrayAdapter.php | ArrayAdapter.buildSortClosure | public function buildSortClosure($propertyPath, $direction)
{
$value = function ($data) use ($propertyPath) {
return $this->propertyAccessor->getValue($data, $propertyPath);
};
if ($direction === Util\ColumnSort::ASC) {
return function ($rowA, $rowB) use ($value) {
$a = $value($rowA);
$b = $value($rowB);
if ($a == $b) {
return 0;
}
return $a < $b ? -1 : 1;
};
} elseif ($direction === Util\ColumnSort::DESC) {
return function ($rowA, $rowB) use ($value) {
$a = $value($rowA);
$b = $value($rowB);
if ($a == $b) {
return 0;
}
return $a > $b ? -1 : 1;
};
}
throw new Exception\InvalidArgumentException("Unexpected column sort direction.");
} | php | public function buildSortClosure($propertyPath, $direction)
{
$value = function ($data) use ($propertyPath) {
return $this->propertyAccessor->getValue($data, $propertyPath);
};
if ($direction === Util\ColumnSort::ASC) {
return function ($rowA, $rowB) use ($value) {
$a = $value($rowA);
$b = $value($rowB);
if ($a == $b) {
return 0;
}
return $a < $b ? -1 : 1;
};
} elseif ($direction === Util\ColumnSort::DESC) {
return function ($rowA, $rowB) use ($value) {
$a = $value($rowA);
$b = $value($rowB);
if ($a == $b) {
return 0;
}
return $a > $b ? -1 : 1;
};
}
throw new Exception\InvalidArgumentException("Unexpected column sort direction.");
} | [
"public",
"function",
"buildSortClosure",
"(",
"$",
"propertyPath",
",",
"$",
"direction",
")",
"{",
"$",
"value",
"=",
"function",
"(",
"$",
"data",
")",
"use",
"(",
"$",
"propertyPath",
")",
"{",
"return",
"$",
"this",
"->",
"propertyAccessor",
"->",
"getValue",
"(",
"$",
"data",
",",
"$",
"propertyPath",
")",
";",
"}",
";",
"if",
"(",
"$",
"direction",
"===",
"Util",
"\\",
"ColumnSort",
"::",
"ASC",
")",
"{",
"return",
"function",
"(",
"$",
"rowA",
",",
"$",
"rowB",
")",
"use",
"(",
"$",
"value",
")",
"{",
"$",
"a",
"=",
"$",
"value",
"(",
"$",
"rowA",
")",
";",
"$",
"b",
"=",
"$",
"value",
"(",
"$",
"rowB",
")",
";",
"if",
"(",
"$",
"a",
"==",
"$",
"b",
")",
"{",
"return",
"0",
";",
"}",
"return",
"$",
"a",
"<",
"$",
"b",
"?",
"-",
"1",
":",
"1",
";",
"}",
";",
"}",
"elseif",
"(",
"$",
"direction",
"===",
"Util",
"\\",
"ColumnSort",
"::",
"DESC",
")",
"{",
"return",
"function",
"(",
"$",
"rowA",
",",
"$",
"rowB",
")",
"use",
"(",
"$",
"value",
")",
"{",
"$",
"a",
"=",
"$",
"value",
"(",
"$",
"rowA",
")",
";",
"$",
"b",
"=",
"$",
"value",
"(",
"$",
"rowB",
")",
";",
"if",
"(",
"$",
"a",
"==",
"$",
"b",
")",
"{",
"return",
"0",
";",
"}",
"return",
"$",
"a",
">",
"$",
"b",
"?",
"-",
"1",
":",
"1",
";",
"}",
";",
"}",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"\"Unexpected column sort direction.\"",
")",
";",
"}"
] | Builds the sort closure.
@param string $propertyPath
@param string $direction
@return \Closure | [
"Builds",
"the",
"sort",
"closure",
"."
] | 6f06e8fd8a3248d52f3a91f10508471344db311a | https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Extension/Core/Source/ArrayAdapter.php#L161-L192 | train |
ekyna/Table | Extension/Core/Source/ArrayAdapter.php | ArrayAdapter.applyClosures | private function applyClosures($data)
{
if (!empty($this->filterClosures)) {
$data = array_filter($data, function ($datum) {
foreach ($this->filterClosures as $closure) {
if (!$closure($datum)) {
return false;
}
}
return true;
});
}
if (!empty($this->sortClosures)) {
uasort($data, function($rowA, $rowB) {
foreach ($this->sortClosures as $closure) {
if (0 != $result = $closure($rowA, $rowB)) {
return $result;
}
}
return 0;
});
}
if ($this->identifiersClosures) {
$data = array_filter($data, $this->identifiersClosures, ARRAY_FILTER_USE_KEY);
}
return $data;
} | php | private function applyClosures($data)
{
if (!empty($this->filterClosures)) {
$data = array_filter($data, function ($datum) {
foreach ($this->filterClosures as $closure) {
if (!$closure($datum)) {
return false;
}
}
return true;
});
}
if (!empty($this->sortClosures)) {
uasort($data, function($rowA, $rowB) {
foreach ($this->sortClosures as $closure) {
if (0 != $result = $closure($rowA, $rowB)) {
return $result;
}
}
return 0;
});
}
if ($this->identifiersClosures) {
$data = array_filter($data, $this->identifiersClosures, ARRAY_FILTER_USE_KEY);
}
return $data;
} | [
"private",
"function",
"applyClosures",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"filterClosures",
")",
")",
"{",
"$",
"data",
"=",
"array_filter",
"(",
"$",
"data",
",",
"function",
"(",
"$",
"datum",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"filterClosures",
"as",
"$",
"closure",
")",
"{",
"if",
"(",
"!",
"$",
"closure",
"(",
"$",
"datum",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"sortClosures",
")",
")",
"{",
"uasort",
"(",
"$",
"data",
",",
"function",
"(",
"$",
"rowA",
",",
"$",
"rowB",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"sortClosures",
"as",
"$",
"closure",
")",
"{",
"if",
"(",
"0",
"!=",
"$",
"result",
"=",
"$",
"closure",
"(",
"$",
"rowA",
",",
"$",
"rowB",
")",
")",
"{",
"return",
"$",
"result",
";",
"}",
"}",
"return",
"0",
";",
"}",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"identifiersClosures",
")",
"{",
"$",
"data",
"=",
"array_filter",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"identifiersClosures",
",",
"ARRAY_FILTER_USE_KEY",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Applies the filters and sort closures.
@param array $data
@return array | [
"Applies",
"the",
"filters",
"and",
"sort",
"closures",
"."
] | 6f06e8fd8a3248d52f3a91f10508471344db311a | https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Extension/Core/Source/ArrayAdapter.php#L280-L311 | train |
rednose-public/RednoseComboHandlerBundle | Controller/MinifyController.php | MinifyController.rewriteUris | public static function rewriteUris($css, $options = array())
{
// Prepend the base URL and symlink schema so the proper root path gets prepended.
$symlinks = array();
if (is_link($_SERVER['DOCUMENT_ROOT'])) {
$symlinks = array(
'/'.$options['baseUrl'] => readlink($_SERVER['DOCUMENT_ROOT'])
);
}
return \Minify_CSS_UriRewriter::rewrite($css, $options['currentDir'], $_SERVER['DOCUMENT_ROOT'], $symlinks);
} | php | public static function rewriteUris($css, $options = array())
{
// Prepend the base URL and symlink schema so the proper root path gets prepended.
$symlinks = array();
if (is_link($_SERVER['DOCUMENT_ROOT'])) {
$symlinks = array(
'/'.$options['baseUrl'] => readlink($_SERVER['DOCUMENT_ROOT'])
);
}
return \Minify_CSS_UriRewriter::rewrite($css, $options['currentDir'], $_SERVER['DOCUMENT_ROOT'], $symlinks);
} | [
"public",
"static",
"function",
"rewriteUris",
"(",
"$",
"css",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"// Prepend the base URL and symlink schema so the proper root path gets prepended.",
"$",
"symlinks",
"=",
"array",
"(",
")",
";",
"if",
"(",
"is_link",
"(",
"$",
"_SERVER",
"[",
"'DOCUMENT_ROOT'",
"]",
")",
")",
"{",
"$",
"symlinks",
"=",
"array",
"(",
"'/'",
".",
"$",
"options",
"[",
"'baseUrl'",
"]",
"=>",
"readlink",
"(",
"$",
"_SERVER",
"[",
"'DOCUMENT_ROOT'",
"]",
")",
")",
";",
"}",
"return",
"\\",
"Minify_CSS_UriRewriter",
"::",
"rewrite",
"(",
"$",
"css",
",",
"$",
"options",
"[",
"'currentDir'",
"]",
",",
"$",
"_SERVER",
"[",
"'DOCUMENT_ROOT'",
"]",
",",
"$",
"symlinks",
")",
";",
"}"
] | Rewrite CSS URIs.
@param string $css
@param array $options
@return string | [
"Rewrite",
"CSS",
"URIs",
"."
] | 44b55dbd6653cebcf280822156cff8b850bdae00 | https://github.com/rednose-public/RednoseComboHandlerBundle/blob/44b55dbd6653cebcf280822156cff8b850bdae00/Controller/MinifyController.php#L76-L88 | train |
rednose-public/RednoseComboHandlerBundle | Controller/MinifyController.php | MinifyController.getBaseUrl | protected function getBaseUrl()
{
$baseUrl = $this->container->get('router')->getContext()->getBaseUrl();
if ($baseUrl === '/') {
return '';
}
return rtrim(str_replace('app_dev.php', '', $this->container->get('router')->getContext()->getBaseUrl()), '/').'/';
} | php | protected function getBaseUrl()
{
$baseUrl = $this->container->get('router')->getContext()->getBaseUrl();
if ($baseUrl === '/') {
return '';
}
return rtrim(str_replace('app_dev.php', '', $this->container->get('router')->getContext()->getBaseUrl()), '/').'/';
} | [
"protected",
"function",
"getBaseUrl",
"(",
")",
"{",
"$",
"baseUrl",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'router'",
")",
"->",
"getContext",
"(",
")",
"->",
"getBaseUrl",
"(",
")",
";",
"if",
"(",
"$",
"baseUrl",
"===",
"'/'",
")",
"{",
"return",
"''",
";",
"}",
"return",
"rtrim",
"(",
"str_replace",
"(",
"'app_dev.php'",
",",
"''",
",",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'router'",
")",
"->",
"getContext",
"(",
")",
"->",
"getBaseUrl",
"(",
")",
")",
",",
"'/'",
")",
".",
"'/'",
";",
"}"
] | Returns the normalized base URL.
@return string | [
"Returns",
"the",
"normalized",
"base",
"URL",
"."
] | 44b55dbd6653cebcf280822156cff8b850bdae00 | https://github.com/rednose-public/RednoseComboHandlerBundle/blob/44b55dbd6653cebcf280822156cff8b850bdae00/Controller/MinifyController.php#L133-L142 | train |
polusphp/polus-middleware | src/UserAgent.php | UserAgent.determineClientUserAgent | protected function determineClientUserAgent($request)
{
$userAgent = null;
$serverParams = $request->getServerParams();
$userAgent = $serverParams['HTTP_USER_AGENT'];
$checkProxyHeaders = $this->checkProxyHeaders;
if ($checkProxyHeaders && !empty($this->trustedProxies)) {
if (!in_array($userAgent, $this->trustedProxies)) {
$checkProxyHeaders = false;
}
}
if ($checkProxyHeaders) {
foreach ($this->headersToInspect as $header) {
if ($request->hasHeader($header)) {
$userAgent = trim(current(explode(',', $request->getHeaderLine($header))));
break;
}
}
}
return $userAgent;
} | php | protected function determineClientUserAgent($request)
{
$userAgent = null;
$serverParams = $request->getServerParams();
$userAgent = $serverParams['HTTP_USER_AGENT'];
$checkProxyHeaders = $this->checkProxyHeaders;
if ($checkProxyHeaders && !empty($this->trustedProxies)) {
if (!in_array($userAgent, $this->trustedProxies)) {
$checkProxyHeaders = false;
}
}
if ($checkProxyHeaders) {
foreach ($this->headersToInspect as $header) {
if ($request->hasHeader($header)) {
$userAgent = trim(current(explode(',', $request->getHeaderLine($header))));
break;
}
}
}
return $userAgent;
} | [
"protected",
"function",
"determineClientUserAgent",
"(",
"$",
"request",
")",
"{",
"$",
"userAgent",
"=",
"null",
";",
"$",
"serverParams",
"=",
"$",
"request",
"->",
"getServerParams",
"(",
")",
";",
"$",
"userAgent",
"=",
"$",
"serverParams",
"[",
"'HTTP_USER_AGENT'",
"]",
";",
"$",
"checkProxyHeaders",
"=",
"$",
"this",
"->",
"checkProxyHeaders",
";",
"if",
"(",
"$",
"checkProxyHeaders",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"trustedProxies",
")",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"userAgent",
",",
"$",
"this",
"->",
"trustedProxies",
")",
")",
"{",
"$",
"checkProxyHeaders",
"=",
"false",
";",
"}",
"}",
"if",
"(",
"$",
"checkProxyHeaders",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"headersToInspect",
"as",
"$",
"header",
")",
"{",
"if",
"(",
"$",
"request",
"->",
"hasHeader",
"(",
"$",
"header",
")",
")",
"{",
"$",
"userAgent",
"=",
"trim",
"(",
"current",
"(",
"explode",
"(",
"','",
",",
"$",
"request",
"->",
"getHeaderLine",
"(",
"$",
"header",
")",
")",
")",
")",
";",
"break",
";",
"}",
"}",
"}",
"return",
"$",
"userAgent",
";",
"}"
] | Find out the client's UserAgent from the headers available to us
@param ServerRequestInterface $request PSR-7 Request
@return string | [
"Find",
"out",
"the",
"client",
"s",
"UserAgent",
"from",
"the",
"headers",
"available",
"to",
"us"
] | c265c51fbdf6b2c5ed85686415b47a1fbf720c57 | https://github.com/polusphp/polus-middleware/blob/c265c51fbdf6b2c5ed85686415b47a1fbf720c57/src/UserAgent.php#L85-L107 | train |
horntell/php-sdk | lib/guzzle/GuzzleHttp/Event/ErrorEvent.php | ErrorEvent.intercept | public function intercept(ResponseInterface $response)
{
$this->stopPropagation();
$this->getTransaction()->setResponse($response);
$this->exception->setThrowImmediately(false);
RequestEvents::emitComplete($this->getTransaction());
} | php | public function intercept(ResponseInterface $response)
{
$this->stopPropagation();
$this->getTransaction()->setResponse($response);
$this->exception->setThrowImmediately(false);
RequestEvents::emitComplete($this->getTransaction());
} | [
"public",
"function",
"intercept",
"(",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"this",
"->",
"stopPropagation",
"(",
")",
";",
"$",
"this",
"->",
"getTransaction",
"(",
")",
"->",
"setResponse",
"(",
"$",
"response",
")",
";",
"$",
"this",
"->",
"exception",
"->",
"setThrowImmediately",
"(",
"false",
")",
";",
"RequestEvents",
"::",
"emitComplete",
"(",
"$",
"this",
"->",
"getTransaction",
"(",
")",
")",
";",
"}"
] | Intercept the exception and inject a response
@param ResponseInterface $response Response to set | [
"Intercept",
"the",
"exception",
"and",
"inject",
"a",
"response"
] | e5205e9396a21b754d5651a8aa5898da5922a1b7 | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Event/ErrorEvent.php#L39-L45 | train |
ARCANESOFT/SEO | src/Http/Requests/Admin/Footers/FooterFormRequest.php | FooterFormRequest.getPageRule | protected function getPageRule()
{
$existsRule = Rule::exists($this->getTablePrefix().'pages', 'id')->using(function ($query) {
if ($this->has('locale'))
$query->where('locale', $this->get('locale', config('app.locale')));
});
return ['required', 'integer', $existsRule];
} | php | protected function getPageRule()
{
$existsRule = Rule::exists($this->getTablePrefix().'pages', 'id')->using(function ($query) {
if ($this->has('locale'))
$query->where('locale', $this->get('locale', config('app.locale')));
});
return ['required', 'integer', $existsRule];
} | [
"protected",
"function",
"getPageRule",
"(",
")",
"{",
"$",
"existsRule",
"=",
"Rule",
"::",
"exists",
"(",
"$",
"this",
"->",
"getTablePrefix",
"(",
")",
".",
"'pages'",
",",
"'id'",
")",
"->",
"using",
"(",
"function",
"(",
"$",
"query",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"'locale'",
")",
")",
"$",
"query",
"->",
"where",
"(",
"'locale'",
",",
"$",
"this",
"->",
"get",
"(",
"'locale'",
",",
"config",
"(",
"'app.locale'",
")",
")",
")",
";",
"}",
")",
";",
"return",
"[",
"'required'",
",",
"'integer'",
",",
"$",
"existsRule",
"]",
";",
"}"
] | Get the page validation rule.
@return array | [
"Get",
"the",
"page",
"validation",
"rule",
"."
] | ce6d6135d55e8b2fd43cf7923839b4791b7c7ad2 | https://github.com/ARCANESOFT/SEO/blob/ce6d6135d55e8b2fd43cf7923839b4791b7c7ad2/src/Http/Requests/Admin/Footers/FooterFormRequest.php#L39-L47 | train |
helsingborg-stad/better-post-UI | source/php/Components/InternalLinks.php | InternalLinks.updateLinkInfo | public function updateLinkInfo($results, $query)
{
$results = array_map(function ($result) {
// Get post type
$post_type = get_post_type($result['ID']);
$obj = get_post_type_object($post_type);
// Add post type to result info
$result['info'] = '<strong>' . $obj->labels->singular_name . '</strong>';
// Get post parents
$ancestors = get_post_ancestors($result['ID']);
$ancestors = array_reverse($ancestors);
// Add post parents path to info string
if (is_array($ancestors) && !empty($ancestors)) {
$parent_string = implode(' / ', array_map(function ($ancestor) {
return get_the_title($ancestor);
}, $ancestors)) . ' / '. $result['title'];
$result['info'] = $result['info'] . ': ' . $parent_string;
}
return $result;
}, $results);
return $results;
} | php | public function updateLinkInfo($results, $query)
{
$results = array_map(function ($result) {
// Get post type
$post_type = get_post_type($result['ID']);
$obj = get_post_type_object($post_type);
// Add post type to result info
$result['info'] = '<strong>' . $obj->labels->singular_name . '</strong>';
// Get post parents
$ancestors = get_post_ancestors($result['ID']);
$ancestors = array_reverse($ancestors);
// Add post parents path to info string
if (is_array($ancestors) && !empty($ancestors)) {
$parent_string = implode(' / ', array_map(function ($ancestor) {
return get_the_title($ancestor);
}, $ancestors)) . ' / '. $result['title'];
$result['info'] = $result['info'] . ': ' . $parent_string;
}
return $result;
}, $results);
return $results;
} | [
"public",
"function",
"updateLinkInfo",
"(",
"$",
"results",
",",
"$",
"query",
")",
"{",
"$",
"results",
"=",
"array_map",
"(",
"function",
"(",
"$",
"result",
")",
"{",
"// Get post type",
"$",
"post_type",
"=",
"get_post_type",
"(",
"$",
"result",
"[",
"'ID'",
"]",
")",
";",
"$",
"obj",
"=",
"get_post_type_object",
"(",
"$",
"post_type",
")",
";",
"// Add post type to result info",
"$",
"result",
"[",
"'info'",
"]",
"=",
"'<strong>'",
".",
"$",
"obj",
"->",
"labels",
"->",
"singular_name",
".",
"'</strong>'",
";",
"// Get post parents",
"$",
"ancestors",
"=",
"get_post_ancestors",
"(",
"$",
"result",
"[",
"'ID'",
"]",
")",
";",
"$",
"ancestors",
"=",
"array_reverse",
"(",
"$",
"ancestors",
")",
";",
"// Add post parents path to info string",
"if",
"(",
"is_array",
"(",
"$",
"ancestors",
")",
"&&",
"!",
"empty",
"(",
"$",
"ancestors",
")",
")",
"{",
"$",
"parent_string",
"=",
"implode",
"(",
"' / '",
",",
"array_map",
"(",
"function",
"(",
"$",
"ancestor",
")",
"{",
"return",
"get_the_title",
"(",
"$",
"ancestor",
")",
";",
"}",
",",
"$",
"ancestors",
")",
")",
".",
"' / '",
".",
"$",
"result",
"[",
"'title'",
"]",
";",
"$",
"result",
"[",
"'info'",
"]",
"=",
"$",
"result",
"[",
"'info'",
"]",
".",
"': '",
".",
"$",
"parent_string",
";",
"}",
"return",
"$",
"result",
";",
"}",
",",
"$",
"results",
")",
";",
"return",
"$",
"results",
";",
"}"
] | Get the post type and its parents
@param array $results An associative array of query results
@param array $query An array of WP_Query arguments
@return array | [
"Get",
"the",
"post",
"type",
"and",
"its",
"parents"
] | 0454e8d6f42787244d02f0e976825ed8dca579f0 | https://github.com/helsingborg-stad/better-post-UI/blob/0454e8d6f42787244d02f0e976825ed8dca579f0/source/php/Components/InternalLinks.php#L34-L59 | train |
helsingborg-stad/better-post-UI | source/php/Components/InternalLinks.php | InternalLinks.limitLinkSearch | public function limitLinkSearch($search, $wp_query)
{
global $wpdb;
if (empty($search)) {
return $search;
}
$query_vars = $wp_query->query_vars;
$search = '';
$and = '';
foreach((array)$query_vars['search_terms'] as $term) {
$search .= "{$searchand}(($wpdb->posts.post_title LIKE '%{$wpdb->esc_like($term)}%'))";
$and = ' AND ';
}
$search = (!empty($search)) ? " AND ({$search}) " : $search;
return $search;
} | php | public function limitLinkSearch($search, $wp_query)
{
global $wpdb;
if (empty($search)) {
return $search;
}
$query_vars = $wp_query->query_vars;
$search = '';
$and = '';
foreach((array)$query_vars['search_terms'] as $term) {
$search .= "{$searchand}(($wpdb->posts.post_title LIKE '%{$wpdb->esc_like($term)}%'))";
$and = ' AND ';
}
$search = (!empty($search)) ? " AND ({$search}) " : $search;
return $search;
} | [
"public",
"function",
"limitLinkSearch",
"(",
"$",
"search",
",",
"$",
"wp_query",
")",
"{",
"global",
"$",
"wpdb",
";",
"if",
"(",
"empty",
"(",
"$",
"search",
")",
")",
"{",
"return",
"$",
"search",
";",
"}",
"$",
"query_vars",
"=",
"$",
"wp_query",
"->",
"query_vars",
";",
"$",
"search",
"=",
"''",
";",
"$",
"and",
"=",
"''",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"query_vars",
"[",
"'search_terms'",
"]",
"as",
"$",
"term",
")",
"{",
"$",
"search",
".=",
"\"{$searchand}(($wpdb->posts.post_title LIKE '%{$wpdb->esc_like($term)}%'))\"",
";",
"$",
"and",
"=",
"' AND '",
";",
"}",
"$",
"search",
"=",
"(",
"!",
"empty",
"(",
"$",
"search",
")",
")",
"?",
"\" AND ({$search}) \"",
":",
"$",
"search",
";",
"return",
"$",
"search",
";",
"}"
] | Limits internal link search to "post title" field
@param string $search Search SQL for WHERE clause
@param obj $wp_query The current WP_Query object
@return string Modified search string | [
"Limits",
"internal",
"link",
"search",
"to",
"post",
"title",
"field"
] | 0454e8d6f42787244d02f0e976825ed8dca579f0 | https://github.com/helsingborg-stad/better-post-UI/blob/0454e8d6f42787244d02f0e976825ed8dca579f0/source/php/Components/InternalLinks.php#L67-L87 | train |
Linkvalue-Interne/MajoraFrameworkExtraBundle | src/Majora/Framework/Model/TranslatableTrait.php | TranslatableTrait.getTranslation | protected function getTranslation(array $translationData, $default = '')
{
// undefined locale
if (empty($translationData)) {
return $default;
}
// current locale matched
if ($this->locale && isset($translationData[$this->locale])) {
return $translationData[$this->locale];
}
// default locale matched
return $this->defaultLocale && isset($translationData[$this->defaultLocale]) ?
$translationData[$this->defaultLocale] :
$default
;
} | php | protected function getTranslation(array $translationData, $default = '')
{
// undefined locale
if (empty($translationData)) {
return $default;
}
// current locale matched
if ($this->locale && isset($translationData[$this->locale])) {
return $translationData[$this->locale];
}
// default locale matched
return $this->defaultLocale && isset($translationData[$this->defaultLocale]) ?
$translationData[$this->defaultLocale] :
$default
;
} | [
"protected",
"function",
"getTranslation",
"(",
"array",
"$",
"translationData",
",",
"$",
"default",
"=",
"''",
")",
"{",
"// undefined locale",
"if",
"(",
"empty",
"(",
"$",
"translationData",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"// current locale matched",
"if",
"(",
"$",
"this",
"->",
"locale",
"&&",
"isset",
"(",
"$",
"translationData",
"[",
"$",
"this",
"->",
"locale",
"]",
")",
")",
"{",
"return",
"$",
"translationData",
"[",
"$",
"this",
"->",
"locale",
"]",
";",
"}",
"// default locale matched",
"return",
"$",
"this",
"->",
"defaultLocale",
"&&",
"isset",
"(",
"$",
"translationData",
"[",
"$",
"this",
"->",
"defaultLocale",
"]",
")",
"?",
"$",
"translationData",
"[",
"$",
"this",
"->",
"defaultLocale",
"]",
":",
"$",
"default",
";",
"}"
] | return translation matching current locale from given translation data
@param array $translationData
@param string $default
@return string | [
"return",
"translation",
"matching",
"current",
"locale",
"from",
"given",
"translation",
"data"
] | 6f368380cfc39d27fafb0844e9a53b4d86d7c034 | https://github.com/Linkvalue-Interne/MajoraFrameworkExtraBundle/blob/6f368380cfc39d27fafb0844e9a53b4d86d7c034/src/Majora/Framework/Model/TranslatableTrait.php#L48-L65 | train |
NukaCode/html | src/NukaCode/Html/BBCode.php | BBCode.parse | public function parse($data)
{
$this->table();
$this->images();
$this->text();
$this->html();
// Replace everything that has been found
foreach ($this->matches as $key => $val) {
$data = preg_replace_callback($key, $val, $data);
}
// Replace line-breaks
return preg_replace_callback("/\n\r?/", function () {
return '<br />';
}, $data
);
} | php | public function parse($data)
{
$this->table();
$this->images();
$this->text();
$this->html();
// Replace everything that has been found
foreach ($this->matches as $key => $val) {
$data = preg_replace_callback($key, $val, $data);
}
// Replace line-breaks
return preg_replace_callback("/\n\r?/", function () {
return '<br />';
}, $data
);
} | [
"public",
"function",
"parse",
"(",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"table",
"(",
")",
";",
"$",
"this",
"->",
"images",
"(",
")",
";",
"$",
"this",
"->",
"text",
"(",
")",
";",
"$",
"this",
"->",
"html",
"(",
")",
";",
"// Replace everything that has been found",
"foreach",
"(",
"$",
"this",
"->",
"matches",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"data",
"=",
"preg_replace_callback",
"(",
"$",
"key",
",",
"$",
"val",
",",
"$",
"data",
")",
";",
"}",
"// Replace line-breaks",
"return",
"preg_replace_callback",
"(",
"\"/\\n\\r?/\"",
",",
"function",
"(",
")",
"{",
"return",
"'<br />'",
";",
"}",
",",
"$",
"data",
")",
";",
"}"
] | Parse a text and replace the BBCodes
@access public
@param string $data
@return string | [
"Parse",
"a",
"text",
"and",
"replace",
"the",
"BBCodes"
] | 7288161fb6711b1f9889e31bacb32d0d14b46e85 | https://github.com/NukaCode/html/blob/7288161fb6711b1f9889e31bacb32d0d14b46e85/src/NukaCode/Html/BBCode.php#L31-L48 | train |
aegis-security/JSON | src/Encoder.php | Encoder._encodeConstants | private static function _encodeConstants(\ReflectionClass $cls)
{
$result = "constants : {";
$constants = $cls->getConstants();
$tmpArray = array();
if (!empty($constants)) {
foreach ($constants as $key => $value) {
$tmpArray[] = "$key: " . self::encode($value);
}
$result .= implode(', ', $tmpArray);
}
return $result . "}";
} | php | private static function _encodeConstants(\ReflectionClass $cls)
{
$result = "constants : {";
$constants = $cls->getConstants();
$tmpArray = array();
if (!empty($constants)) {
foreach ($constants as $key => $value) {
$tmpArray[] = "$key: " . self::encode($value);
}
$result .= implode(', ', $tmpArray);
}
return $result . "}";
} | [
"private",
"static",
"function",
"_encodeConstants",
"(",
"\\",
"ReflectionClass",
"$",
"cls",
")",
"{",
"$",
"result",
"=",
"\"constants : {\"",
";",
"$",
"constants",
"=",
"$",
"cls",
"->",
"getConstants",
"(",
")",
";",
"$",
"tmpArray",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"constants",
")",
")",
"{",
"foreach",
"(",
"$",
"constants",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"tmpArray",
"[",
"]",
"=",
"\"$key: \"",
".",
"self",
"::",
"encode",
"(",
"$",
"value",
")",
";",
"}",
"$",
"result",
".=",
"implode",
"(",
"', '",
",",
"$",
"tmpArray",
")",
";",
"}",
"return",
"$",
"result",
".",
"\"}\"",
";",
"}"
] | Encode the constants associated with the \ReflectionClass
parameter. The encoding format is based on the class2 format
@param \ReflectionClass $cls
@return string Encoded constant block in class2 format | [
"Encode",
"the",
"constants",
"associated",
"with",
"the",
"\\",
"ReflectionClass",
"parameter",
".",
"The",
"encoding",
"format",
"is",
"based",
"on",
"the",
"class2",
"format"
] | 7bc8e442e9e570ecbc480053d9aaa42a52910fbc | https://github.com/aegis-security/JSON/blob/7bc8e442e9e570ecbc480053d9aaa42a52910fbc/src/Encoder.php#L262-L277 | train |
rollerworks-graveyard/metadata | src/NullClassMetadata.php | NullClassMetadata.merge | public function merge(ClassMetadata $object)
{
$createdAt = $this->createdAt;
if (($otherCreatedAt = $object->getCreatedAt()) > $createdAt) {
$createdAt = $otherCreatedAt;
}
return new self($this->className, $createdAt);
} | php | public function merge(ClassMetadata $object)
{
$createdAt = $this->createdAt;
if (($otherCreatedAt = $object->getCreatedAt()) > $createdAt) {
$createdAt = $otherCreatedAt;
}
return new self($this->className, $createdAt);
} | [
"public",
"function",
"merge",
"(",
"ClassMetadata",
"$",
"object",
")",
"{",
"$",
"createdAt",
"=",
"$",
"this",
"->",
"createdAt",
";",
"if",
"(",
"(",
"$",
"otherCreatedAt",
"=",
"$",
"object",
"->",
"getCreatedAt",
"(",
")",
")",
">",
"$",
"createdAt",
")",
"{",
"$",
"createdAt",
"=",
"$",
"otherCreatedAt",
";",
"}",
"return",
"new",
"self",
"(",
"$",
"this",
"->",
"className",
",",
"$",
"createdAt",
")",
";",
"}"
] | Returns a new NullClassMetadata with the highest createdAt.
No actual merging is performed as NullClassMetadata can't hold
any data and it's not possible to determine which ClassMetadata
implementation must be used.
Only the createdAt of the object is used if it's higher then
the current createdAt value.
@param ClassMetadata $object Another MergeableClassMetadata object.
@return NullClassMetadata | [
"Returns",
"a",
"new",
"NullClassMetadata",
"with",
"the",
"highest",
"createdAt",
"."
] | 5b07f564aad87709ca0d0b3e140e4dc4edf9d375 | https://github.com/rollerworks-graveyard/metadata/blob/5b07f564aad87709ca0d0b3e140e4dc4edf9d375/src/NullClassMetadata.php#L131-L140 | train |
ezra-obiwale/dSCore | src/Stdlib/Email.php | Email.addAttachment | public function addAttachment($filePath) {
if (!$file = fopen($filePath, 'r')) {
throw new Exception('Cannot open file "' . $filePath . '"');
}
$this->attachments[$filePath] = chunk_split(base64_encode(fread($file, filesize($filePath))));
return $this;
} | php | public function addAttachment($filePath) {
if (!$file = fopen($filePath, 'r')) {
throw new Exception('Cannot open file "' . $filePath . '"');
}
$this->attachments[$filePath] = chunk_split(base64_encode(fread($file, filesize($filePath))));
return $this;
} | [
"public",
"function",
"addAttachment",
"(",
"$",
"filePath",
")",
"{",
"if",
"(",
"!",
"$",
"file",
"=",
"fopen",
"(",
"$",
"filePath",
",",
"'r'",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Cannot open file \"'",
".",
"$",
"filePath",
".",
"'\"'",
")",
";",
"}",
"$",
"this",
"->",
"attachments",
"[",
"$",
"filePath",
"]",
"=",
"chunk_split",
"(",
"base64_encode",
"(",
"fread",
"(",
"$",
"file",
",",
"filesize",
"(",
"$",
"filePath",
")",
")",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Attach a file to the email
@param string $filePath Path to the file
@return \Email
@throws Exception | [
"Attach",
"a",
"file",
"to",
"the",
"email"
] | dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Email.php#L46-L53 | train |
ezra-obiwale/dSCore | src/Stdlib/Email.php | Email.setHTML | public function setHTML($content, array $options = array()) {
$this->html = $content;
$this->htmlCharset = (isset($options['charset'])) ? $options['charset'] : 'utf-8';
if (@$options['autoSetText']) {
$this->setText(strip_tags($this->html), $this->htmlCharset);
}
return $this;
} | php | public function setHTML($content, array $options = array()) {
$this->html = $content;
$this->htmlCharset = (isset($options['charset'])) ? $options['charset'] : 'utf-8';
if (@$options['autoSetText']) {
$this->setText(strip_tags($this->html), $this->htmlCharset);
}
return $this;
} | [
"public",
"function",
"setHTML",
"(",
"$",
"content",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"html",
"=",
"$",
"content",
";",
"$",
"this",
"->",
"htmlCharset",
"=",
"(",
"isset",
"(",
"$",
"options",
"[",
"'charset'",
"]",
")",
")",
"?",
"$",
"options",
"[",
"'charset'",
"]",
":",
"'utf-8'",
";",
"if",
"(",
"@",
"$",
"options",
"[",
"'autoSetText'",
"]",
")",
"{",
"$",
"this",
"->",
"setText",
"(",
"strip_tags",
"(",
"$",
"this",
"->",
"html",
")",
",",
"$",
"this",
"->",
"htmlCharset",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set html content
@param string $content
@param array $options Keys may include [(string) charset [= "utf-8"], (boolean) autoSetText]
@return \Email | [
"Set",
"html",
"content"
] | dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Email.php#L74-L81 | train |
ezra-obiwale/dSCore | src/Stdlib/Email.php | Email.setText | public function setText($content, $charset = 'utf-8') {
$this->text = $content;
$this->textCharset = $charset;
return $this;
} | php | public function setText($content, $charset = 'utf-8') {
$this->text = $content;
$this->textCharset = $charset;
return $this;
} | [
"public",
"function",
"setText",
"(",
"$",
"content",
",",
"$",
"charset",
"=",
"'utf-8'",
")",
"{",
"$",
"this",
"->",
"text",
"=",
"$",
"content",
";",
"$",
"this",
"->",
"textCharset",
"=",
"$",
"charset",
";",
"return",
"$",
"this",
";",
"}"
] | Set text content
@param string $content
@return \Email | [
"Set",
"text",
"content"
] | dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Email.php#L88-L92 | train |
ezra-obiwale/dSCore | src/Stdlib/Email.php | Email.addBcc | public function addBcc($bcc) {
$this->bcc = (!empty($this->bcc)) ? $this->bcc . ',' . $bcc : $bcc;
return $this;
} | php | public function addBcc($bcc) {
$this->bcc = (!empty($this->bcc)) ? $this->bcc . ',' . $bcc : $bcc;
return $this;
} | [
"public",
"function",
"addBcc",
"(",
"$",
"bcc",
")",
"{",
"$",
"this",
"->",
"bcc",
"=",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"bcc",
")",
")",
"?",
"$",
"this",
"->",
"bcc",
".",
"','",
".",
"$",
"bcc",
":",
"$",
"bcc",
";",
"return",
"$",
"this",
";",
"}"
] | Adds a best carbon copy
@param string $bcc Email address to send to
@return \Email | [
"Adds",
"a",
"best",
"carbon",
"copy"
] | dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d | https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Stdlib/Email.php#L200-L203 | train |
wearenolte/wp-acf | src/Acf.php | Acf.get_post_field | public static function get_post_field( $post_id = 0, $include_wp_fields = true, $field = '' ) {
if ( $include_wp_fields && ! $field ) {
$wp_fields = [
'post_id' => $post_id,
'permalink' => get_permalink( $post_id ),
'title' => get_the_title( $post_id ),
'content' => apply_filters( 'the_content', get_post_field( 'post_content', $post_id ) ),
];
return array_merge( $wp_fields, self::get_field( $post_id ) );
}
return self::get_field( $post_id, $field );
} | php | public static function get_post_field( $post_id = 0, $include_wp_fields = true, $field = '' ) {
if ( $include_wp_fields && ! $field ) {
$wp_fields = [
'post_id' => $post_id,
'permalink' => get_permalink( $post_id ),
'title' => get_the_title( $post_id ),
'content' => apply_filters( 'the_content', get_post_field( 'post_content', $post_id ) ),
];
return array_merge( $wp_fields, self::get_field( $post_id ) );
}
return self::get_field( $post_id, $field );
} | [
"public",
"static",
"function",
"get_post_field",
"(",
"$",
"post_id",
"=",
"0",
",",
"$",
"include_wp_fields",
"=",
"true",
",",
"$",
"field",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"include_wp_fields",
"&&",
"!",
"$",
"field",
")",
"{",
"$",
"wp_fields",
"=",
"[",
"'post_id'",
"=>",
"$",
"post_id",
",",
"'permalink'",
"=>",
"get_permalink",
"(",
"$",
"post_id",
")",
",",
"'title'",
"=>",
"get_the_title",
"(",
"$",
"post_id",
")",
",",
"'content'",
"=>",
"apply_filters",
"(",
"'the_content'",
",",
"get_post_field",
"(",
"'post_content'",
",",
"$",
"post_id",
")",
")",
",",
"]",
";",
"return",
"array_merge",
"(",
"$",
"wp_fields",
",",
"self",
"::",
"get_field",
"(",
"$",
"post_id",
")",
")",
";",
"}",
"return",
"self",
"::",
"get_field",
"(",
"$",
"post_id",
",",
"$",
"field",
")",
";",
"}"
] | Get the field value for a post.
@param int $post_id The target post's id. Or leave blank for he current post if in the loop.
@param bool $include_wp_fields Whether or not to include the default WP fields.
@param string $field The ACF field id or name. Return all fields if blank.
@return array | [
"Get",
"the",
"field",
"value",
"for",
"a",
"post",
"."
] | 2f5093438d637fa0eca42ad6d10f6b433ec078b2 | https://github.com/wearenolte/wp-acf/blob/2f5093438d637fa0eca42ad6d10f6b433ec078b2/src/Acf.php#L26-L37 | train |
wearenolte/wp-acf | src/Acf.php | Acf.get_taxonomy_field | public static function get_taxonomy_field( $taxonomy_term, $field = '' ) {
if ( is_a( $taxonomy_term, 'WP_Term' ) ) {
return self::get_field( $taxonomy_term, $field );
} elseif ( is_array( $taxonomy_term ) && count( $taxonomy_term ) >= 2 ) {
return self::get_field( "{$taxonomy_term[0]}_{$taxonomy_term[1]}", $field );
}
throw new \Exception( '$taxonomy_term must be either a term object or an array of [$taxonomy, $term_id]' );
} | php | public static function get_taxonomy_field( $taxonomy_term, $field = '' ) {
if ( is_a( $taxonomy_term, 'WP_Term' ) ) {
return self::get_field( $taxonomy_term, $field );
} elseif ( is_array( $taxonomy_term ) && count( $taxonomy_term ) >= 2 ) {
return self::get_field( "{$taxonomy_term[0]}_{$taxonomy_term[1]}", $field );
}
throw new \Exception( '$taxonomy_term must be either a term object or an array of [$taxonomy, $term_id]' );
} | [
"public",
"static",
"function",
"get_taxonomy_field",
"(",
"$",
"taxonomy_term",
",",
"$",
"field",
"=",
"''",
")",
"{",
"if",
"(",
"is_a",
"(",
"$",
"taxonomy_term",
",",
"'WP_Term'",
")",
")",
"{",
"return",
"self",
"::",
"get_field",
"(",
"$",
"taxonomy_term",
",",
"$",
"field",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"taxonomy_term",
")",
"&&",
"count",
"(",
"$",
"taxonomy_term",
")",
">=",
"2",
")",
"{",
"return",
"self",
"::",
"get_field",
"(",
"\"{$taxonomy_term[0]}_{$taxonomy_term[1]}\"",
",",
"$",
"field",
")",
";",
"}",
"throw",
"new",
"\\",
"Exception",
"(",
"'$taxonomy_term must be either a term object or an array of [$taxonomy, $term_id]'",
")",
";",
"}"
] | Get the fields for a taxonomy term.
@param array|\WP_Term $taxonomy_term The target term's [taxonomy, $term_id] or term object.
@param string $field The ACF field id or name. Return all fields if blank.
@return mixed
@throws \Exception | [
"Get",
"the",
"fields",
"for",
"a",
"taxonomy",
"term",
"."
] | 2f5093438d637fa0eca42ad6d10f6b433ec078b2 | https://github.com/wearenolte/wp-acf/blob/2f5093438d637fa0eca42ad6d10f6b433ec078b2/src/Acf.php#L69-L76 | train |
wearenolte/wp-acf | src/Acf.php | Acf.get_field | private static function get_field( $target_id = 0, $field = '' ) {
if ( self::is_active() ) {
if ( $field ) {
return self::get_single_field( $target_id, $field );
} else {
return self::get_all_fields( $target_id );
}
}
return $field ? null : [];
} | php | private static function get_field( $target_id = 0, $field = '' ) {
if ( self::is_active() ) {
if ( $field ) {
return self::get_single_field( $target_id, $field );
} else {
return self::get_all_fields( $target_id );
}
}
return $field ? null : [];
} | [
"private",
"static",
"function",
"get_field",
"(",
"$",
"target_id",
"=",
"0",
",",
"$",
"field",
"=",
"''",
")",
"{",
"if",
"(",
"self",
"::",
"is_active",
"(",
")",
")",
"{",
"if",
"(",
"$",
"field",
")",
"{",
"return",
"self",
"::",
"get_single_field",
"(",
"$",
"target_id",
",",
"$",
"field",
")",
";",
"}",
"else",
"{",
"return",
"self",
"::",
"get_all_fields",
"(",
"$",
"target_id",
")",
";",
"}",
"}",
"return",
"$",
"field",
"?",
"null",
":",
"[",
"]",
";",
"}"
] | Get all field values.
@param int $target_id The target object's id.
@param string $field The ACF field id or name. Return all fields if blank.
@return array | [
"Get",
"all",
"field",
"values",
"."
] | 2f5093438d637fa0eca42ad6d10f6b433ec078b2 | https://github.com/wearenolte/wp-acf/blob/2f5093438d637fa0eca42ad6d10f6b433ec078b2/src/Acf.php#L117-L126 | train |
wearenolte/wp-acf | src/Acf.php | Acf.get_all_fields | private static function get_all_fields( $target_id = 0 ) {
$data = [];
$field_objs = get_field_objects( $target_id );
if ( $field_objs ) {
foreach ( $field_objs as $field_name => $field_obj ) {
$value = self::get_single_field( $target_id, $field_obj );
$group_slug = self::get_group_slug( $field_obj['parent'] );
if ( $group_slug ) {
$data[ $group_slug ][ $field_name ] = $value;
} else {
$data[ $field_name ] = $value;
}
}
}
return $data;
} | php | private static function get_all_fields( $target_id = 0 ) {
$data = [];
$field_objs = get_field_objects( $target_id );
if ( $field_objs ) {
foreach ( $field_objs as $field_name => $field_obj ) {
$value = self::get_single_field( $target_id, $field_obj );
$group_slug = self::get_group_slug( $field_obj['parent'] );
if ( $group_slug ) {
$data[ $group_slug ][ $field_name ] = $value;
} else {
$data[ $field_name ] = $value;
}
}
}
return $data;
} | [
"private",
"static",
"function",
"get_all_fields",
"(",
"$",
"target_id",
"=",
"0",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"$",
"field_objs",
"=",
"get_field_objects",
"(",
"$",
"target_id",
")",
";",
"if",
"(",
"$",
"field_objs",
")",
"{",
"foreach",
"(",
"$",
"field_objs",
"as",
"$",
"field_name",
"=>",
"$",
"field_obj",
")",
"{",
"$",
"value",
"=",
"self",
"::",
"get_single_field",
"(",
"$",
"target_id",
",",
"$",
"field_obj",
")",
";",
"$",
"group_slug",
"=",
"self",
"::",
"get_group_slug",
"(",
"$",
"field_obj",
"[",
"'parent'",
"]",
")",
";",
"if",
"(",
"$",
"group_slug",
")",
"{",
"$",
"data",
"[",
"$",
"group_slug",
"]",
"[",
"$",
"field_name",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"$",
"field_name",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Get all the fields for the target object.
@param int $target_id The id of the target object.
@return array | [
"Get",
"all",
"the",
"fields",
"for",
"the",
"target",
"object",
"."
] | 2f5093438d637fa0eca42ad6d10f6b433ec078b2 | https://github.com/wearenolte/wp-acf/blob/2f5093438d637fa0eca42ad6d10f6b433ec078b2/src/Acf.php#L134-L154 | train |
wearenolte/wp-acf | src/Acf.php | Acf.get_single_field | private static function get_single_field( $target_id = 0, $field = '' ) {
$field_obj = is_array( $field ) ? $field : get_field_object( $field, $target_id );
$field_key = isset( $field_obj['key'] ) ? $field_obj['key'] : '';
$filter_name = Filter::create_name( Filter::DEFAULT_TRANSFORMS, $field_key );
$apply_default_transforms = apply_filters( $filter_name, $target_id, $field_obj );
$value = $apply_default_transforms ? self::apply_default_transform( $field_obj ) : $field_obj['value'];
$filter_name = Filter::create_name( Filter::FIELD, $field_key );
return apply_filters( $filter_name, $value, $target_id, $field_obj );
} | php | private static function get_single_field( $target_id = 0, $field = '' ) {
$field_obj = is_array( $field ) ? $field : get_field_object( $field, $target_id );
$field_key = isset( $field_obj['key'] ) ? $field_obj['key'] : '';
$filter_name = Filter::create_name( Filter::DEFAULT_TRANSFORMS, $field_key );
$apply_default_transforms = apply_filters( $filter_name, $target_id, $field_obj );
$value = $apply_default_transforms ? self::apply_default_transform( $field_obj ) : $field_obj['value'];
$filter_name = Filter::create_name( Filter::FIELD, $field_key );
return apply_filters( $filter_name, $value, $target_id, $field_obj );
} | [
"private",
"static",
"function",
"get_single_field",
"(",
"$",
"target_id",
"=",
"0",
",",
"$",
"field",
"=",
"''",
")",
"{",
"$",
"field_obj",
"=",
"is_array",
"(",
"$",
"field",
")",
"?",
"$",
"field",
":",
"get_field_object",
"(",
"$",
"field",
",",
"$",
"target_id",
")",
";",
"$",
"field_key",
"=",
"isset",
"(",
"$",
"field_obj",
"[",
"'key'",
"]",
")",
"?",
"$",
"field_obj",
"[",
"'key'",
"]",
":",
"''",
";",
"$",
"filter_name",
"=",
"Filter",
"::",
"create_name",
"(",
"Filter",
"::",
"DEFAULT_TRANSFORMS",
",",
"$",
"field_key",
")",
";",
"$",
"apply_default_transforms",
"=",
"apply_filters",
"(",
"$",
"filter_name",
",",
"$",
"target_id",
",",
"$",
"field_obj",
")",
";",
"$",
"value",
"=",
"$",
"apply_default_transforms",
"?",
"self",
"::",
"apply_default_transform",
"(",
"$",
"field_obj",
")",
":",
"$",
"field_obj",
"[",
"'value'",
"]",
";",
"$",
"filter_name",
"=",
"Filter",
"::",
"create_name",
"(",
"Filter",
"::",
"FIELD",
",",
"$",
"field_key",
")",
";",
"return",
"apply_filters",
"(",
"$",
"filter_name",
",",
"$",
"value",
",",
"$",
"target_id",
",",
"$",
"field_obj",
")",
";",
"}"
] | Gat a single field value for a target object.
@param int $target_id The id of the target object.
@param string $field The field id or name.
@return mixed | [
"Gat",
"a",
"single",
"field",
"value",
"for",
"a",
"target",
"object",
"."
] | 2f5093438d637fa0eca42ad6d10f6b433ec078b2 | https://github.com/wearenolte/wp-acf/blob/2f5093438d637fa0eca42ad6d10f6b433ec078b2/src/Acf.php#L163-L175 | train |
wearenolte/wp-acf | src/Acf.php | Acf.get_group_slug | private static function get_group_slug( $group_id ) {
global $acf_local;
if ( isset( $acf_local->groups[ $group_id ] ) ) {
// First try the local groups (added by PHP).
$title = $acf_local->groups[ $group_id ]['title'];
} else {
$title = '';
if ( is_numeric( $group_id ) ) {
$args = [
'post_type' => 'acf-field-group',
'no_found_rows' => true,
'update_post_meta_cache' => false,
'update_post_term_cache' => false,
'fields' => 'ids',
'post__in' => [ $group_id ],
];
$groups = new \WP_Query( $args );
$acf_groups = is_array( $groups->posts ) ? $groups->posts : [];
$acf_id = empty( $acf_groups ) ? 0 : $acf_groups[0];
$title = get_the_title( $acf_id );
} else {
$group = acf_get_local_field_group( $group_id );
$title = empty( $group['title'] ) ? $group['title'] : '';
}
// Patch for the new version of ACF Fields plugins >= 5.4.*.
if ( ! $title ) {
$groups = acf_get_field_group( $group_id );
$title = empty( $groups ) ? false : $groups['title'];
}
}
if ( $title ) {
return strtolower( str_replace( ' ', '_', $title ) );
}
return false;
} | php | private static function get_group_slug( $group_id ) {
global $acf_local;
if ( isset( $acf_local->groups[ $group_id ] ) ) {
// First try the local groups (added by PHP).
$title = $acf_local->groups[ $group_id ]['title'];
} else {
$title = '';
if ( is_numeric( $group_id ) ) {
$args = [
'post_type' => 'acf-field-group',
'no_found_rows' => true,
'update_post_meta_cache' => false,
'update_post_term_cache' => false,
'fields' => 'ids',
'post__in' => [ $group_id ],
];
$groups = new \WP_Query( $args );
$acf_groups = is_array( $groups->posts ) ? $groups->posts : [];
$acf_id = empty( $acf_groups ) ? 0 : $acf_groups[0];
$title = get_the_title( $acf_id );
} else {
$group = acf_get_local_field_group( $group_id );
$title = empty( $group['title'] ) ? $group['title'] : '';
}
// Patch for the new version of ACF Fields plugins >= 5.4.*.
if ( ! $title ) {
$groups = acf_get_field_group( $group_id );
$title = empty( $groups ) ? false : $groups['title'];
}
}
if ( $title ) {
return strtolower( str_replace( ' ', '_', $title ) );
}
return false;
} | [
"private",
"static",
"function",
"get_group_slug",
"(",
"$",
"group_id",
")",
"{",
"global",
"$",
"acf_local",
";",
"if",
"(",
"isset",
"(",
"$",
"acf_local",
"->",
"groups",
"[",
"$",
"group_id",
"]",
")",
")",
"{",
"// First try the local groups (added by PHP).",
"$",
"title",
"=",
"$",
"acf_local",
"->",
"groups",
"[",
"$",
"group_id",
"]",
"[",
"'title'",
"]",
";",
"}",
"else",
"{",
"$",
"title",
"=",
"''",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"group_id",
")",
")",
"{",
"$",
"args",
"=",
"[",
"'post_type'",
"=>",
"'acf-field-group'",
",",
"'no_found_rows'",
"=>",
"true",
",",
"'update_post_meta_cache'",
"=>",
"false",
",",
"'update_post_term_cache'",
"=>",
"false",
",",
"'fields'",
"=>",
"'ids'",
",",
"'post__in'",
"=>",
"[",
"$",
"group_id",
"]",
",",
"]",
";",
"$",
"groups",
"=",
"new",
"\\",
"WP_Query",
"(",
"$",
"args",
")",
";",
"$",
"acf_groups",
"=",
"is_array",
"(",
"$",
"groups",
"->",
"posts",
")",
"?",
"$",
"groups",
"->",
"posts",
":",
"[",
"]",
";",
"$",
"acf_id",
"=",
"empty",
"(",
"$",
"acf_groups",
")",
"?",
"0",
":",
"$",
"acf_groups",
"[",
"0",
"]",
";",
"$",
"title",
"=",
"get_the_title",
"(",
"$",
"acf_id",
")",
";",
"}",
"else",
"{",
"$",
"group",
"=",
"acf_get_local_field_group",
"(",
"$",
"group_id",
")",
";",
"$",
"title",
"=",
"empty",
"(",
"$",
"group",
"[",
"'title'",
"]",
")",
"?",
"$",
"group",
"[",
"'title'",
"]",
":",
"''",
";",
"}",
"// Patch for the new version of ACF Fields plugins >= 5.4.*.",
"if",
"(",
"!",
"$",
"title",
")",
"{",
"$",
"groups",
"=",
"acf_get_field_group",
"(",
"$",
"group_id",
")",
";",
"$",
"title",
"=",
"empty",
"(",
"$",
"groups",
")",
"?",
"false",
":",
"$",
"groups",
"[",
"'title'",
"]",
";",
"}",
"}",
"if",
"(",
"$",
"title",
")",
"{",
"return",
"strtolower",
"(",
"str_replace",
"(",
"' '",
",",
"'_'",
",",
"$",
"title",
")",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Get an ACF group slug
@param $group_id
@return string|bool | [
"Get",
"an",
"ACF",
"group",
"slug"
] | 2f5093438d637fa0eca42ad6d10f6b433ec078b2 | https://github.com/wearenolte/wp-acf/blob/2f5093438d637fa0eca42ad6d10f6b433ec078b2/src/Acf.php#L211-L250 | train |
Vectrex/vxPHP | src/Form/FormElement/FileInputElement.php | FileInputElement.getValue | public function getValue()
{
$file = $this->getFile();
if($file instanceof UploadedFile) {
return $file->getOriginalName();
}
if(is_array($file) && $file[0] instanceof UploadedFile) {
return $file[0]->getOriginalName();
}
return null;
} | php | public function getValue()
{
$file = $this->getFile();
if($file instanceof UploadedFile) {
return $file->getOriginalName();
}
if(is_array($file) && $file[0] instanceof UploadedFile) {
return $file[0]->getOriginalName();
}
return null;
} | [
"public",
"function",
"getValue",
"(",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"getFile",
"(",
")",
";",
"if",
"(",
"$",
"file",
"instanceof",
"UploadedFile",
")",
"{",
"return",
"$",
"file",
"->",
"getOriginalName",
"(",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"file",
")",
"&&",
"$",
"file",
"[",
"0",
"]",
"instanceof",
"UploadedFile",
")",
"{",
"return",
"$",
"file",
"[",
"0",
"]",
"->",
"getOriginalName",
"(",
")",
";",
"}",
"return",
"null",
";",
"}"
] | get original name of an uploaded file associated with this element
if attribute multiple is set the name of the first file is returned
@return string | [
"get",
"original",
"name",
"of",
"an",
"uploaded",
"file",
"associated",
"with",
"this",
"element",
"if",
"attribute",
"multiple",
"is",
"set",
"the",
"name",
"of",
"the",
"first",
"file",
"is",
"returned"
] | 295c21b00e7ef6085efcdf5b64fabb28d499b5a6 | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Form/FormElement/FileInputElement.php#L44-L57 | train |
wb-crowdfusion/crowdfusion | system/core/classes/mvc/filters/NonceFilterer.php | NonceFilterer.nonce | protected function nonce()
{
$action = ($this->getParameter('action') == null) ?
$this->RequestContext->getControls()->getControl('action')
: $this->getParameter('action');
return $this->Nonces->create($action);
} | php | protected function nonce()
{
$action = ($this->getParameter('action') == null) ?
$this->RequestContext->getControls()->getControl('action')
: $this->getParameter('action');
return $this->Nonces->create($action);
} | [
"protected",
"function",
"nonce",
"(",
")",
"{",
"$",
"action",
"=",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'action'",
")",
"==",
"null",
")",
"?",
"$",
"this",
"->",
"RequestContext",
"->",
"getControls",
"(",
")",
"->",
"getControl",
"(",
"'action'",
")",
":",
"$",
"this",
"->",
"getParameter",
"(",
"'action'",
")",
";",
"return",
"$",
"this",
"->",
"Nonces",
"->",
"create",
"(",
"$",
"action",
")",
";",
"}"
] | Creates a nonce for the current or specified action
Expected Param:
action string (optional) The action that the nonce will be valid for.
If not specified, the current action will be used
@return string | [
"Creates",
"a",
"nonce",
"for",
"the",
"current",
"or",
"specified",
"action"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/filters/NonceFilterer.php#L50-L57 | train |
flipbox/spark | src/services/traits/ElementByString.php | ElementByString.findCacheByString | public function findCacheByString(string $string, int $siteId = null)
{
// Check if already in cache
if ($this->isCachedByString($string, $siteId)) {
return $this->cacheByString[$siteId][$string];
}
return null;
} | php | public function findCacheByString(string $string, int $siteId = null)
{
// Check if already in cache
if ($this->isCachedByString($string, $siteId)) {
return $this->cacheByString[$siteId][$string];
}
return null;
} | [
"public",
"function",
"findCacheByString",
"(",
"string",
"$",
"string",
",",
"int",
"$",
"siteId",
"=",
"null",
")",
"{",
"// Check if already in cache",
"if",
"(",
"$",
"this",
"->",
"isCachedByString",
"(",
"$",
"string",
",",
"$",
"siteId",
")",
")",
"{",
"return",
"$",
"this",
"->",
"cacheByString",
"[",
"$",
"siteId",
"]",
"[",
"$",
"string",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Find an existing cache by Handle
@param string $string
@param int|null $siteId
@return BaseElement|ElementInterface|null | [
"Find",
"an",
"existing",
"cache",
"by",
"Handle"
] | 9d75fd3d95744b9c9187921c4f3b9eea42c035d4 | https://github.com/flipbox/spark/blob/9d75fd3d95744b9c9187921c4f3b9eea42c035d4/src/services/traits/ElementByString.php#L125-L134 | train |
flipbox/spark | src/services/traits/ElementByString.php | ElementByString.isCachedByString | protected function isCachedByString($string, int $siteId = null)
{
// Resolve siteId
$siteId = SiteHelper::resolveSiteId($siteId);
if (!isset($this->cacheByString[$siteId])) {
$this->cacheByString[$siteId] = [];
}
return array_key_exists($string, $this->cacheByString[$siteId]);
} | php | protected function isCachedByString($string, int $siteId = null)
{
// Resolve siteId
$siteId = SiteHelper::resolveSiteId($siteId);
if (!isset($this->cacheByString[$siteId])) {
$this->cacheByString[$siteId] = [];
}
return array_key_exists($string, $this->cacheByString[$siteId]);
} | [
"protected",
"function",
"isCachedByString",
"(",
"$",
"string",
",",
"int",
"$",
"siteId",
"=",
"null",
")",
"{",
"// Resolve siteId",
"$",
"siteId",
"=",
"SiteHelper",
"::",
"resolveSiteId",
"(",
"$",
"siteId",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"cacheByString",
"[",
"$",
"siteId",
"]",
")",
")",
"{",
"$",
"this",
"->",
"cacheByString",
"[",
"$",
"siteId",
"]",
"=",
"[",
"]",
";",
"}",
"return",
"array_key_exists",
"(",
"$",
"string",
",",
"$",
"this",
"->",
"cacheByString",
"[",
"$",
"siteId",
"]",
")",
";",
"}"
] | Identify whether in cached by string
@param $string
@param int|null $siteId
@return bool | [
"Identify",
"whether",
"in",
"cached",
"by",
"string"
] | 9d75fd3d95744b9c9187921c4f3b9eea42c035d4 | https://github.com/flipbox/spark/blob/9d75fd3d95744b9c9187921c4f3b9eea42c035d4/src/services/traits/ElementByString.php#L143-L154 | train |
maddoger/yii2-datetime-behavior | DateTimeAttribute.php | DateTimeAttribute.parseDateValue | protected static function parseDateValue($value, $format, $timeZone)
{
$date = DateTime::createFromFormat($format, $value, new DateTimeZone($timeZone));
$errors = DateTime::getLastErrors();
if ($date === false || $errors['error_count'] || $errors['warning_count']) {
return false;
} else {
// if no time was provided in the format string set time to 0 to get a simple date timestamp
if (strpbrk($format, 'UHhGgis') === false) {
$date->setTime(0, 0, 0);
}
return $date;
}
} | php | protected static function parseDateValue($value, $format, $timeZone)
{
$date = DateTime::createFromFormat($format, $value, new DateTimeZone($timeZone));
$errors = DateTime::getLastErrors();
if ($date === false || $errors['error_count'] || $errors['warning_count']) {
return false;
} else {
// if no time was provided in the format string set time to 0 to get a simple date timestamp
if (strpbrk($format, 'UHhGgis') === false) {
$date->setTime(0, 0, 0);
}
return $date;
}
} | [
"protected",
"static",
"function",
"parseDateValue",
"(",
"$",
"value",
",",
"$",
"format",
",",
"$",
"timeZone",
")",
"{",
"$",
"date",
"=",
"DateTime",
"::",
"createFromFormat",
"(",
"$",
"format",
",",
"$",
"value",
",",
"new",
"DateTimeZone",
"(",
"$",
"timeZone",
")",
")",
";",
"$",
"errors",
"=",
"DateTime",
"::",
"getLastErrors",
"(",
")",
";",
"if",
"(",
"$",
"date",
"===",
"false",
"||",
"$",
"errors",
"[",
"'error_count'",
"]",
"||",
"$",
"errors",
"[",
"'warning_count'",
"]",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"// if no time was provided in the format string set time to 0 to get a simple date timestamp",
"if",
"(",
"strpbrk",
"(",
"$",
"format",
",",
"'UHhGgis'",
")",
"===",
"false",
")",
"{",
"$",
"date",
"->",
"setTime",
"(",
"0",
",",
"0",
",",
"0",
")",
";",
"}",
"return",
"$",
"date",
";",
"}",
"}"
] | Parses date string into DateTime object
@param string $value string representing date
@param string $format string representing date
@param string $timeZone string representing date
@return boolean|DateTime DateTime object or false on failure | [
"Parses",
"date",
"string",
"into",
"DateTime",
"object"
] | 3fd04ab1b2c3b10e620ae4c7971e3d9ef8084db3 | https://github.com/maddoger/yii2-datetime-behavior/blob/3fd04ab1b2c3b10e620ae4c7971e3d9ef8084db3/DateTimeAttribute.php#L145-L158 | train |
Eden-PHP/Registry | src/Index.php | Index.remove | public function remove()
{
$args = func_get_args();
if (count($args) == 0) {
return $this;
}
$last = array_pop($args);
$pointer = &$this->data;
foreach ($args as $i => $step) {
if (!isset($pointer[$step])
|| !is_array($pointer[$step])
) {
return $this;
}
$pointer = &$pointer[$step];
}
unset($pointer[$last]);
return $this;
} | php | public function remove()
{
$args = func_get_args();
if (count($args) == 0) {
return $this;
}
$last = array_pop($args);
$pointer = &$this->data;
foreach ($args as $i => $step) {
if (!isset($pointer[$step])
|| !is_array($pointer[$step])
) {
return $this;
}
$pointer = &$pointer[$step];
}
unset($pointer[$last]);
return $this;
} | [
"public",
"function",
"remove",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"args",
")",
"==",
"0",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"last",
"=",
"array_pop",
"(",
"$",
"args",
")",
";",
"$",
"pointer",
"=",
"&",
"$",
"this",
"->",
"data",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"i",
"=>",
"$",
"step",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"pointer",
"[",
"$",
"step",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"pointer",
"[",
"$",
"step",
"]",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"pointer",
"=",
"&",
"$",
"pointer",
"[",
"$",
"step",
"]",
";",
"}",
"unset",
"(",
"$",
"pointer",
"[",
"$",
"last",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Removes a key and everything associated with it
@return Eden\Registry\Index | [
"Removes",
"a",
"key",
"and",
"everything",
"associated",
"with",
"it"
] | 4ec72e314a65372fdf30b6dff772db6ff21dd11a | https://github.com/Eden-PHP/Registry/blob/4ec72e314a65372fdf30b6dff772db6ff21dd11a/src/Index.php#L158-L182 | train |
zodream/database | src/Model/Model.php | Model.findOrDefault | public static function findOrDefault($param, array $attributes) {
$model = self::findOrNew($param);
if ($model->isNewRecord) {
$model->set($attributes);
}
return $model;
} | php | public static function findOrDefault($param, array $attributes) {
$model = self::findOrNew($param);
if ($model->isNewRecord) {
$model->set($attributes);
}
return $model;
} | [
"public",
"static",
"function",
"findOrDefault",
"(",
"$",
"param",
",",
"array",
"$",
"attributes",
")",
"{",
"$",
"model",
"=",
"self",
"::",
"findOrNew",
"(",
"$",
"param",
")",
";",
"if",
"(",
"$",
"model",
"->",
"isNewRecord",
")",
"{",
"$",
"model",
"->",
"set",
"(",
"$",
"attributes",
")",
";",
"}",
"return",
"$",
"model",
";",
"}"
] | Set not found default data
@param $param
@param array $attributes
@return bool|Model
@throws \Exception | [
"Set",
"not",
"found",
"default",
"data"
] | 03712219c057799d07350a3a2650c55bcc92c28e | https://github.com/zodream/database/blob/03712219c057799d07350a3a2650c55bcc92c28e/src/Model/Model.php#L195-L201 | train |
zodream/database | src/Model/Model.php | Model.findWithReplace | public static function findWithReplace($param, array $attributes) {
$model = self::findOrNew($param);
$model->set($attributes);
return $model;
} | php | public static function findWithReplace($param, array $attributes) {
$model = self::findOrNew($param);
$model->set($attributes);
return $model;
} | [
"public",
"static",
"function",
"findWithReplace",
"(",
"$",
"param",
",",
"array",
"$",
"attributes",
")",
"{",
"$",
"model",
"=",
"self",
"::",
"findOrNew",
"(",
"$",
"param",
")",
";",
"$",
"model",
"->",
"set",
"(",
"$",
"attributes",
")",
";",
"return",
"$",
"model",
";",
"}"
] | Set new attr
@param $param
@param array $attributes
@return bool|Model
@throws \Exception | [
"Set",
"new",
"attr"
] | 03712219c057799d07350a3a2650c55bcc92c28e | https://github.com/zodream/database/blob/03712219c057799d07350a3a2650c55bcc92c28e/src/Model/Model.php#L210-L214 | train |
stubbles/stubbles-peer | src/main/php/Stream.php | Stream.setTimeout | public function setTimeout(int $seconds, int $microseconds = 0): self
{
$this->timeout = (float) ($seconds . '.' . $microseconds);
stream_set_timeout($this->resource, $seconds, $microseconds);
return $this;
} | php | public function setTimeout(int $seconds, int $microseconds = 0): self
{
$this->timeout = (float) ($seconds . '.' . $microseconds);
stream_set_timeout($this->resource, $seconds, $microseconds);
return $this;
} | [
"public",
"function",
"setTimeout",
"(",
"int",
"$",
"seconds",
",",
"int",
"$",
"microseconds",
"=",
"0",
")",
":",
"self",
"{",
"$",
"this",
"->",
"timeout",
"=",
"(",
"float",
")",
"(",
"$",
"seconds",
".",
"'.'",
".",
"$",
"microseconds",
")",
";",
"stream_set_timeout",
"(",
"$",
"this",
"->",
"resource",
",",
"$",
"seconds",
",",
"$",
"microseconds",
")",
";",
"return",
"$",
"this",
";",
"}"
] | set timeout for connections
@param int $seconds timeout for connection in seconds
@param int $microseconds optional timeout for connection in microseconds
@return $this | [
"set",
"timeout",
"for",
"connections"
] | dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc | https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/Stream.php#L96-L101 | train |
stubbles/stubbles-peer | src/main/php/Stream.php | Stream.read | public function read(int $length = null): string
{
// can not call fgets with null when not specified
$data = null === $length ? fgets($this->resource) : fgets($this->resource, $length);
if (false === $data) {
// fgets() returns false on eof while feof() returned false before
// but will now return true
if ($this->eof()) {
return '';
}
if (stream_get_meta_data($this->resource)['timed_out']) {
throw new Timeout(
'Reading of ' . $length . ' bytes failed: timeout of '
. $this->timeout . ' seconds exceeded'
);
}
throw new ConnectionFailure(
'Reading of ' . $length . ' bytes failed.'
);
}
return $data;
} | php | public function read(int $length = null): string
{
// can not call fgets with null when not specified
$data = null === $length ? fgets($this->resource) : fgets($this->resource, $length);
if (false === $data) {
// fgets() returns false on eof while feof() returned false before
// but will now return true
if ($this->eof()) {
return '';
}
if (stream_get_meta_data($this->resource)['timed_out']) {
throw new Timeout(
'Reading of ' . $length . ' bytes failed: timeout of '
. $this->timeout . ' seconds exceeded'
);
}
throw new ConnectionFailure(
'Reading of ' . $length . ' bytes failed.'
);
}
return $data;
} | [
"public",
"function",
"read",
"(",
"int",
"$",
"length",
"=",
"null",
")",
":",
"string",
"{",
"// can not call fgets with null when not specified",
"$",
"data",
"=",
"null",
"===",
"$",
"length",
"?",
"fgets",
"(",
"$",
"this",
"->",
"resource",
")",
":",
"fgets",
"(",
"$",
"this",
"->",
"resource",
",",
"$",
"length",
")",
";",
"if",
"(",
"false",
"===",
"$",
"data",
")",
"{",
"// fgets() returns false on eof while feof() returned false before",
"// but will now return true",
"if",
"(",
"$",
"this",
"->",
"eof",
"(",
")",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"stream_get_meta_data",
"(",
"$",
"this",
"->",
"resource",
")",
"[",
"'timed_out'",
"]",
")",
"{",
"throw",
"new",
"Timeout",
"(",
"'Reading of '",
".",
"$",
"length",
".",
"' bytes failed: timeout of '",
".",
"$",
"this",
"->",
"timeout",
".",
"' seconds exceeded'",
")",
";",
"}",
"throw",
"new",
"ConnectionFailure",
"(",
"'Reading of '",
".",
"$",
"length",
".",
"' bytes failed.'",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | read from socket
@param int $length optional length of data to read
@return string data read from socket
@throws \stubbles\peer\ConnectionFailure
@throws \stubbles\peer\Timeout | [
"read",
"from",
"socket"
] | dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc | https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/Stream.php#L121-L145 | train |
stubbles/stubbles-peer | src/main/php/Stream.php | Stream.readBinary | public function readBinary(int $length = 1024): string
{
$data = fread($this->resource, $length);
if (false === $data) {
if (stream_get_meta_data($this->resource)['timed_out']) {
throw new Timeout(
'Reading of ' . $length . ' bytes failed: timeout of '
. $this->timeout . ' seconds exceeded'
);
}
throw new ConnectionFailure(
'Reading of ' . $length . ' bytes failed.'
);
}
return $data;
} | php | public function readBinary(int $length = 1024): string
{
$data = fread($this->resource, $length);
if (false === $data) {
if (stream_get_meta_data($this->resource)['timed_out']) {
throw new Timeout(
'Reading of ' . $length . ' bytes failed: timeout of '
. $this->timeout . ' seconds exceeded'
);
}
throw new ConnectionFailure(
'Reading of ' . $length . ' bytes failed.'
);
}
return $data;
} | [
"public",
"function",
"readBinary",
"(",
"int",
"$",
"length",
"=",
"1024",
")",
":",
"string",
"{",
"$",
"data",
"=",
"fread",
"(",
"$",
"this",
"->",
"resource",
",",
"$",
"length",
")",
";",
"if",
"(",
"false",
"===",
"$",
"data",
")",
"{",
"if",
"(",
"stream_get_meta_data",
"(",
"$",
"this",
"->",
"resource",
")",
"[",
"'timed_out'",
"]",
")",
"{",
"throw",
"new",
"Timeout",
"(",
"'Reading of '",
".",
"$",
"length",
".",
"' bytes failed: timeout of '",
".",
"$",
"this",
"->",
"timeout",
".",
"' seconds exceeded'",
")",
";",
"}",
"throw",
"new",
"ConnectionFailure",
"(",
"'Reading of '",
".",
"$",
"length",
".",
"' bytes failed.'",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | read binary data from socket
@param int $length length of data to read
@return string data read from socket
@throws \stubbles\peer\ConnectionFailure
@throws \stubbles\peer\Timeout | [
"read",
"binary",
"data",
"from",
"socket"
] | dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc | https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/Stream.php#L165-L182 | train |
stubbles/stubbles-peer | src/main/php/Stream.php | Stream.write | public function write(string $data): int
{
$length = fputs($this->resource, $data, strlen($data));
if (false === $length) {
if (stream_get_meta_data($this->resource)['timed_out']) {
throw new Timeout(
'Writing of ' . strlen($data) . ' bytes failed:'
. ' timeout of ' . $this->timeout . ' seconds exceeded'
);
}
throw new ConnectionFailure(
'Writing of ' . strlen($data) . ' bytes failed.'
);
}
return $length;
} | php | public function write(string $data): int
{
$length = fputs($this->resource, $data, strlen($data));
if (false === $length) {
if (stream_get_meta_data($this->resource)['timed_out']) {
throw new Timeout(
'Writing of ' . strlen($data) . ' bytes failed:'
. ' timeout of ' . $this->timeout . ' seconds exceeded'
);
}
throw new ConnectionFailure(
'Writing of ' . strlen($data) . ' bytes failed.'
);
}
return $length;
} | [
"public",
"function",
"write",
"(",
"string",
"$",
"data",
")",
":",
"int",
"{",
"$",
"length",
"=",
"fputs",
"(",
"$",
"this",
"->",
"resource",
",",
"$",
"data",
",",
"strlen",
"(",
"$",
"data",
")",
")",
";",
"if",
"(",
"false",
"===",
"$",
"length",
")",
"{",
"if",
"(",
"stream_get_meta_data",
"(",
"$",
"this",
"->",
"resource",
")",
"[",
"'timed_out'",
"]",
")",
"{",
"throw",
"new",
"Timeout",
"(",
"'Writing of '",
".",
"strlen",
"(",
"$",
"data",
")",
".",
"' bytes failed:'",
".",
"' timeout of '",
".",
"$",
"this",
"->",
"timeout",
".",
"' seconds exceeded'",
")",
";",
"}",
"throw",
"new",
"ConnectionFailure",
"(",
"'Writing of '",
".",
"strlen",
"(",
"$",
"data",
")",
".",
"' bytes failed.'",
")",
";",
"}",
"return",
"$",
"length",
";",
"}"
] | write data to socket
@param string $data data to write
@return int amount of bytes written to socket
@throws \stubbles\peer\ConnectionFailure
@throws \stubbles\peer\Timeout | [
"write",
"data",
"to",
"socket"
] | dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc | https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/Stream.php#L192-L209 | train |
sil-project/VarietyBundle | src/Controller/VarietyCRUDController.php | VarietyCRUDController.strainAction | public function strainAction()
{
$id = $this->getRequest()->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
$strain = clone $object;
$strain->setIsStrain(true);
$strain->setParent($object);
$fieldSets = ['Professional', 'Amateur', 'Production', 'Commercial', 'Plant', 'Culture', 'Inner'];
foreach ($fieldSets as $label) {
$getter = 'get' . $label . 'Descriptions';
$adder = 'add' . $label . 'Description';
$collection = $object->$getter();
$collection->initialize();
foreach ($collection as $desc) {
$new = clone $desc;
$strain->$adder($new);
}
}
$this->duplicateFiles($object, $strain);
foreach ($object->getPlantCategories() as $cat) {
$strain->addPlantCategory($cat);
}
return $this->createAction($strain);
} | php | public function strainAction()
{
$id = $this->getRequest()->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
$strain = clone $object;
$strain->setIsStrain(true);
$strain->setParent($object);
$fieldSets = ['Professional', 'Amateur', 'Production', 'Commercial', 'Plant', 'Culture', 'Inner'];
foreach ($fieldSets as $label) {
$getter = 'get' . $label . 'Descriptions';
$adder = 'add' . $label . 'Description';
$collection = $object->$getter();
$collection->initialize();
foreach ($collection as $desc) {
$new = clone $desc;
$strain->$adder($new);
}
}
$this->duplicateFiles($object, $strain);
foreach ($object->getPlantCategories() as $cat) {
$strain->addPlantCategory($cat);
}
return $this->createAction($strain);
} | [
"public",
"function",
"strainAction",
"(",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"get",
"(",
"$",
"this",
"->",
"admin",
"->",
"getIdParameter",
"(",
")",
")",
";",
"$",
"object",
"=",
"$",
"this",
"->",
"admin",
"->",
"getObject",
"(",
"$",
"id",
")",
";",
"$",
"strain",
"=",
"clone",
"$",
"object",
";",
"$",
"strain",
"->",
"setIsStrain",
"(",
"true",
")",
";",
"$",
"strain",
"->",
"setParent",
"(",
"$",
"object",
")",
";",
"$",
"fieldSets",
"=",
"[",
"'Professional'",
",",
"'Amateur'",
",",
"'Production'",
",",
"'Commercial'",
",",
"'Plant'",
",",
"'Culture'",
",",
"'Inner'",
"]",
";",
"foreach",
"(",
"$",
"fieldSets",
"as",
"$",
"label",
")",
"{",
"$",
"getter",
"=",
"'get'",
".",
"$",
"label",
".",
"'Descriptions'",
";",
"$",
"adder",
"=",
"'add'",
".",
"$",
"label",
".",
"'Description'",
";",
"$",
"collection",
"=",
"$",
"object",
"->",
"$",
"getter",
"(",
")",
";",
"$",
"collection",
"->",
"initialize",
"(",
")",
";",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"desc",
")",
"{",
"$",
"new",
"=",
"clone",
"$",
"desc",
";",
"$",
"strain",
"->",
"$",
"adder",
"(",
"$",
"new",
")",
";",
"}",
"}",
"$",
"this",
"->",
"duplicateFiles",
"(",
"$",
"object",
",",
"$",
"strain",
")",
";",
"foreach",
"(",
"$",
"object",
"->",
"getPlantCategories",
"(",
")",
"as",
"$",
"cat",
")",
"{",
"$",
"strain",
"->",
"addPlantCategory",
"(",
"$",
"cat",
")",
";",
"}",
"return",
"$",
"this",
"->",
"createAction",
"(",
"$",
"strain",
")",
";",
"}"
] | Creates a strain from a variety and passes it to create action.
@return Response | [
"Creates",
"a",
"strain",
"from",
"a",
"variety",
"and",
"passes",
"it",
"to",
"create",
"action",
"."
] | e9508ce13a4bb277d10bdcd925fdb84bc01f453f | https://github.com/sil-project/VarietyBundle/blob/e9508ce13a4bb277d10bdcd925fdb84bc01f453f/src/Controller/VarietyCRUDController.php#L52-L82 | train |
sil-project/VarietyBundle | src/Controller/VarietyCRUDController.php | VarietyCRUDController.getFilterWidgetAction | public function getFilterWidgetAction(Request $request)
{
$translator = $this->get('translator');
$fieldSet = $request->get('fieldset');
$field = $request->get('field');
$config = $this->admin->getConfigurationPool()->getContainer()->getParameter('librinfo_varieties');
$fieldConfig = $config['variety_descriptions'][$fieldSet][$field];
$choiceType = CustomChoiceType::class;
$options = $fieldConfig['options'];
$type = $fieldConfig['type'] != 'textarea' ? $fieldConfig['type'] : 'text';
if ($type == 'blast_custom_checkbox') {
$type = 'choice';
$options = array_merge($options, array(
'choices' => array('1' => $translator->trans('yes'), '0' => $translator->trans('no')),
));
}
if ($type == $choiceType) {
$options['is_filter'] = true;
if (isset($options['expanded'])) {
unset($options['expanded']);
}
if (isset($options['multiple'])) {
unset($options['multiple']);
}
}
if ($type == 'blast_tinymce') {
$type = 'text';
}
if (isset($options['choices']) && empty($options['choices'])) {
unset($options['choices']);
}
if (isset($options['choices_class']) && $type != $choiceType) {
unset($options['choices_class']);
}
if (isset($options['blast_choices']) && $type != $choiceType) {
unset($options['blast_choices']);
}
if (isset($options['help'])) {
unset($options['help']);
}
$view = $this->createFormBuilder()
->add('value', $type, $options)
->getForm()
->createView()
;
return $this->render(
'LibrinfoVarietiesBundle:Form:filter_widget.html.twig',
array(
'form' => $view,
),
null
);
} | php | public function getFilterWidgetAction(Request $request)
{
$translator = $this->get('translator');
$fieldSet = $request->get('fieldset');
$field = $request->get('field');
$config = $this->admin->getConfigurationPool()->getContainer()->getParameter('librinfo_varieties');
$fieldConfig = $config['variety_descriptions'][$fieldSet][$field];
$choiceType = CustomChoiceType::class;
$options = $fieldConfig['options'];
$type = $fieldConfig['type'] != 'textarea' ? $fieldConfig['type'] : 'text';
if ($type == 'blast_custom_checkbox') {
$type = 'choice';
$options = array_merge($options, array(
'choices' => array('1' => $translator->trans('yes'), '0' => $translator->trans('no')),
));
}
if ($type == $choiceType) {
$options['is_filter'] = true;
if (isset($options['expanded'])) {
unset($options['expanded']);
}
if (isset($options['multiple'])) {
unset($options['multiple']);
}
}
if ($type == 'blast_tinymce') {
$type = 'text';
}
if (isset($options['choices']) && empty($options['choices'])) {
unset($options['choices']);
}
if (isset($options['choices_class']) && $type != $choiceType) {
unset($options['choices_class']);
}
if (isset($options['blast_choices']) && $type != $choiceType) {
unset($options['blast_choices']);
}
if (isset($options['help'])) {
unset($options['help']);
}
$view = $this->createFormBuilder()
->add('value', $type, $options)
->getForm()
->createView()
;
return $this->render(
'LibrinfoVarietiesBundle:Form:filter_widget.html.twig',
array(
'form' => $view,
),
null
);
} | [
"public",
"function",
"getFilterWidgetAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"translator",
"=",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
";",
"$",
"fieldSet",
"=",
"$",
"request",
"->",
"get",
"(",
"'fieldset'",
")",
";",
"$",
"field",
"=",
"$",
"request",
"->",
"get",
"(",
"'field'",
")",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"admin",
"->",
"getConfigurationPool",
"(",
")",
"->",
"getContainer",
"(",
")",
"->",
"getParameter",
"(",
"'librinfo_varieties'",
")",
";",
"$",
"fieldConfig",
"=",
"$",
"config",
"[",
"'variety_descriptions'",
"]",
"[",
"$",
"fieldSet",
"]",
"[",
"$",
"field",
"]",
";",
"$",
"choiceType",
"=",
"CustomChoiceType",
"::",
"class",
";",
"$",
"options",
"=",
"$",
"fieldConfig",
"[",
"'options'",
"]",
";",
"$",
"type",
"=",
"$",
"fieldConfig",
"[",
"'type'",
"]",
"!=",
"'textarea'",
"?",
"$",
"fieldConfig",
"[",
"'type'",
"]",
":",
"'text'",
";",
"if",
"(",
"$",
"type",
"==",
"'blast_custom_checkbox'",
")",
"{",
"$",
"type",
"=",
"'choice'",
";",
"$",
"options",
"=",
"array_merge",
"(",
"$",
"options",
",",
"array",
"(",
"'choices'",
"=>",
"array",
"(",
"'1'",
"=>",
"$",
"translator",
"->",
"trans",
"(",
"'yes'",
")",
",",
"'0'",
"=>",
"$",
"translator",
"->",
"trans",
"(",
"'no'",
")",
")",
",",
")",
")",
";",
"}",
"if",
"(",
"$",
"type",
"==",
"$",
"choiceType",
")",
"{",
"$",
"options",
"[",
"'is_filter'",
"]",
"=",
"true",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'expanded'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"options",
"[",
"'expanded'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'multiple'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"options",
"[",
"'multiple'",
"]",
")",
";",
"}",
"}",
"if",
"(",
"$",
"type",
"==",
"'blast_tinymce'",
")",
"{",
"$",
"type",
"=",
"'text'",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'choices'",
"]",
")",
"&&",
"empty",
"(",
"$",
"options",
"[",
"'choices'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"options",
"[",
"'choices'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'choices_class'",
"]",
")",
"&&",
"$",
"type",
"!=",
"$",
"choiceType",
")",
"{",
"unset",
"(",
"$",
"options",
"[",
"'choices_class'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'blast_choices'",
"]",
")",
"&&",
"$",
"type",
"!=",
"$",
"choiceType",
")",
"{",
"unset",
"(",
"$",
"options",
"[",
"'blast_choices'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'help'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"options",
"[",
"'help'",
"]",
")",
";",
"}",
"$",
"view",
"=",
"$",
"this",
"->",
"createFormBuilder",
"(",
")",
"->",
"add",
"(",
"'value'",
",",
"$",
"type",
",",
"$",
"options",
")",
"->",
"getForm",
"(",
")",
"->",
"createView",
"(",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'LibrinfoVarietiesBundle:Form:filter_widget.html.twig'",
",",
"array",
"(",
"'form'",
"=>",
"$",
"view",
",",
")",
",",
"null",
")",
";",
"}"
] | Get field widget for filter form.
@param string $fieldName the name of the field to get the form widget for
@return JsonResponse | [
"Get",
"field",
"widget",
"for",
"filter",
"form",
"."
] | e9508ce13a4bb277d10bdcd925fdb84bc01f453f | https://github.com/sil-project/VarietyBundle/blob/e9508ce13a4bb277d10bdcd925fdb84bc01f453f/src/Controller/VarietyCRUDController.php#L91-L155 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/errors/ErrorHandler.php | ErrorHandler.handleErrors | public function handleErrors($severity, $message, $filepath, $line)
{
if (error_reporting() == 0 || $severity == E_STRICT)
return;
if (false !== strpos($filepath, '/')) {
$x = explode('/', $filepath);
$filepath = $x[count($x)-3].'/'.$x[count($x)-2].'/'.end($x);
}
$mess = $this->getLevel($severity).'('.$severity.'): '.$message. ' in '.$filepath.' on line '.$line;
/*
* shouldn't need to log the error here as the exception will handle the logging.
*/
/*
$context = (isset($_SERVER['CONTEXT']) ? $_SERVER['CONTEXT'] : 'none');
if (array_key_exists('SITE', $_SERVER)) {
$appName = (string) $_SERVER['SITE']['slug'];
if ($appName === $context) {
$appName = $this->SiteService->getAnchoredSite()->Slug;
}
} else {
$appName = $_SERVER['SERVER_NAME'];
}
error_log("[{$this->environment}][$appName][$context][PHP_ERROR] " . $mess);
*/
if($severity == E_RECOVERABLE_ERROR)
throw new Exception($mess);
if (($severity & error_reporting()) == $severity) {
if($this->redeployOnError && isset($this->ApplicationContext))
$this->ApplicationContext->clearContextFiles();
throw new Exception($mess);
}
return true;
} | php | public function handleErrors($severity, $message, $filepath, $line)
{
if (error_reporting() == 0 || $severity == E_STRICT)
return;
if (false !== strpos($filepath, '/')) {
$x = explode('/', $filepath);
$filepath = $x[count($x)-3].'/'.$x[count($x)-2].'/'.end($x);
}
$mess = $this->getLevel($severity).'('.$severity.'): '.$message. ' in '.$filepath.' on line '.$line;
/*
* shouldn't need to log the error here as the exception will handle the logging.
*/
/*
$context = (isset($_SERVER['CONTEXT']) ? $_SERVER['CONTEXT'] : 'none');
if (array_key_exists('SITE', $_SERVER)) {
$appName = (string) $_SERVER['SITE']['slug'];
if ($appName === $context) {
$appName = $this->SiteService->getAnchoredSite()->Slug;
}
} else {
$appName = $_SERVER['SERVER_NAME'];
}
error_log("[{$this->environment}][$appName][$context][PHP_ERROR] " . $mess);
*/
if($severity == E_RECOVERABLE_ERROR)
throw new Exception($mess);
if (($severity & error_reporting()) == $severity) {
if($this->redeployOnError && isset($this->ApplicationContext))
$this->ApplicationContext->clearContextFiles();
throw new Exception($mess);
}
return true;
} | [
"public",
"function",
"handleErrors",
"(",
"$",
"severity",
",",
"$",
"message",
",",
"$",
"filepath",
",",
"$",
"line",
")",
"{",
"if",
"(",
"error_reporting",
"(",
")",
"==",
"0",
"||",
"$",
"severity",
"==",
"E_STRICT",
")",
"return",
";",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"filepath",
",",
"'/'",
")",
")",
"{",
"$",
"x",
"=",
"explode",
"(",
"'/'",
",",
"$",
"filepath",
")",
";",
"$",
"filepath",
"=",
"$",
"x",
"[",
"count",
"(",
"$",
"x",
")",
"-",
"3",
"]",
".",
"'/'",
".",
"$",
"x",
"[",
"count",
"(",
"$",
"x",
")",
"-",
"2",
"]",
".",
"'/'",
".",
"end",
"(",
"$",
"x",
")",
";",
"}",
"$",
"mess",
"=",
"$",
"this",
"->",
"getLevel",
"(",
"$",
"severity",
")",
".",
"'('",
".",
"$",
"severity",
".",
"'): '",
".",
"$",
"message",
".",
"' in '",
".",
"$",
"filepath",
".",
"' on line '",
".",
"$",
"line",
";",
"/*\n * shouldn't need to log the error here as the exception will handle the logging.\n */",
"/*\n $context = (isset($_SERVER['CONTEXT']) ? $_SERVER['CONTEXT'] : 'none');\n if (array_key_exists('SITE', $_SERVER)) {\n $appName = (string) $_SERVER['SITE']['slug'];\n if ($appName === $context) {\n $appName = $this->SiteService->getAnchoredSite()->Slug;\n }\n } else {\n $appName = $_SERVER['SERVER_NAME'];\n }\n error_log(\"[{$this->environment}][$appName][$context][PHP_ERROR] \" . $mess);\n */",
"if",
"(",
"$",
"severity",
"==",
"E_RECOVERABLE_ERROR",
")",
"throw",
"new",
"Exception",
"(",
"$",
"mess",
")",
";",
"if",
"(",
"(",
"$",
"severity",
"&",
"error_reporting",
"(",
")",
")",
"==",
"$",
"severity",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"redeployOnError",
"&&",
"isset",
"(",
"$",
"this",
"->",
"ApplicationContext",
")",
")",
"$",
"this",
"->",
"ApplicationContext",
"->",
"clearContextFiles",
"(",
")",
";",
"throw",
"new",
"Exception",
"(",
"$",
"mess",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Defines the error handler that will be used when this class is created.
Using error_log, this function will record the error.
@param string $severity The severity of the error
@param string $message The error message
@param string $filepath The file where the error was encountered
@param string $line The line number where the error occured
@return void|boolean | [
"Defines",
"the",
"error",
"handler",
"that",
"will",
"be",
"used",
"when",
"this",
"class",
"is",
"created",
"."
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/errors/ErrorHandler.php#L140-L179 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/errors/ErrorHandler.php | ErrorHandler.handleExceptions | public function handleExceptions($exception)
{
$this->displayError($exception);
$this->sendErrorNotification($exception);
if(isset($this->ApplicationContext) && ($this->ApplicationContext->isOneOffRedeploy() || $this->redeployOnError))
$this->ApplicationContext->clearContextFiles();
} | php | public function handleExceptions($exception)
{
$this->displayError($exception);
$this->sendErrorNotification($exception);
if(isset($this->ApplicationContext) && ($this->ApplicationContext->isOneOffRedeploy() || $this->redeployOnError))
$this->ApplicationContext->clearContextFiles();
} | [
"public",
"function",
"handleExceptions",
"(",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"displayError",
"(",
"$",
"exception",
")",
";",
"$",
"this",
"->",
"sendErrorNotification",
"(",
"$",
"exception",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"ApplicationContext",
")",
"&&",
"(",
"$",
"this",
"->",
"ApplicationContext",
"->",
"isOneOffRedeploy",
"(",
")",
"||",
"$",
"this",
"->",
"redeployOnError",
")",
")",
"$",
"this",
"->",
"ApplicationContext",
"->",
"clearContextFiles",
"(",
")",
";",
"}"
] | Defines the exception handler to use.
@param Exception $exception The exception to handle
@return void | [
"Defines",
"the",
"exception",
"handler",
"to",
"use",
"."
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/errors/ErrorHandler.php#L234-L241 | train |
translationexchange/tml-php-clientsdk | library/Tr8n/Utils/BrowserUtils.php | BrowserUtils.matchLanguage | public static function matchLanguage($a, $b) {
$a = explode('-', $a);
$b = explode('-', $b);
for ($i=0, $n=min(count($a), count($b)); $i<$n; $i++) {
if ($a[$i] !== $b[$i]) break;
}
return $i === 0 ? 0 : (float) $i / count($a);
} | php | public static function matchLanguage($a, $b) {
$a = explode('-', $a);
$b = explode('-', $b);
for ($i=0, $n=min(count($a), count($b)); $i<$n; $i++) {
if ($a[$i] !== $b[$i]) break;
}
return $i === 0 ? 0 : (float) $i / count($a);
} | [
"public",
"static",
"function",
"matchLanguage",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"$",
"a",
"=",
"explode",
"(",
"'-'",
",",
"$",
"a",
")",
";",
"$",
"b",
"=",
"explode",
"(",
"'-'",
",",
"$",
"b",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"n",
"=",
"min",
"(",
"count",
"(",
"$",
"a",
")",
",",
"count",
"(",
"$",
"b",
")",
")",
";",
"$",
"i",
"<",
"$",
"n",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"a",
"[",
"$",
"i",
"]",
"!==",
"$",
"b",
"[",
"$",
"i",
"]",
")",
"break",
";",
"}",
"return",
"$",
"i",
"===",
"0",
"?",
"0",
":",
"(",
"float",
")",
"$",
"i",
"/",
"count",
"(",
"$",
"a",
")",
";",
"}"
] | compare two language tags and distinguish the degree of matching | [
"compare",
"two",
"language",
"tags",
"and",
"distinguish",
"the",
"degree",
"of",
"matching"
] | fe51473824e62cfd883c6aa0c6a3783a16ce8425 | https://github.com/translationexchange/tml-php-clientsdk/blob/fe51473824e62cfd883c6aa0c6a3783a16ce8425/library/Tr8n/Utils/BrowserUtils.php#L69-L76 | train |
Beotie/Beotie-PSR7-stream | src/Stream/Factory/FileInfoStreamFactory.php | FileInfoStreamFactory.paramHasContent | protected function paramHasContent(array $params, string $method = 'getStream') : bool
{
if (!array_key_exists(self::ARRAY_KEY, $params)) {
throw new \RuntimeException(
sprintf(
'The "%s::%s" expect a file array key to build an instance of FileInfoStreamAdapter',
static::class,
$method
)
);
}
return true;
} | php | protected function paramHasContent(array $params, string $method = 'getStream') : bool
{
if (!array_key_exists(self::ARRAY_KEY, $params)) {
throw new \RuntimeException(
sprintf(
'The "%s::%s" expect a file array key to build an instance of FileInfoStreamAdapter',
static::class,
$method
)
);
}
return true;
} | [
"protected",
"function",
"paramHasContent",
"(",
"array",
"$",
"params",
",",
"string",
"$",
"method",
"=",
"'getStream'",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"self",
"::",
"ARRAY_KEY",
",",
"$",
"params",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'The \"%s::%s\" expect a file array key to build an instance of FileInfoStreamAdapter'",
",",
"static",
"::",
"class",
",",
"$",
"method",
")",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Param has content
This method aim to validate the existance of a 'inner_content' key into the parameters array.
@param array $params The original method parameters validated by the function
@param string $method The original method name. This parameter is used to build the exception message
@throws \RuntimeException If the given parameters does not have a 'inner_content' key
@return bool | [
"Param",
"has",
"content"
] | 8f4f4bfb8252e392fc17eed2a2b0682c4e9d08ca | https://github.com/Beotie/Beotie-PSR7-stream/blob/8f4f4bfb8252e392fc17eed2a2b0682c4e9d08ca/src/Stream/Factory/FileInfoStreamFactory.php#L92-L105 | train |
Beotie/Beotie-PSR7-stream | src/Stream/Factory/FileInfoStreamFactory.php | FileInfoStreamFactory.contentIsFileInfo | protected function contentIsFileInfo($file, string $method = 'getStream') : bool
{
if (! $file instanceof \SplFileInfo) {
$message = 'The "%s::%s" expect the file array key to be an instance of "%s". "%s" given';
$givenType = (is_object($file) ? get_class($file) : gettype($file));
throw new \RuntimeException(sprintf($message, static::class, $method, \SplFileInfo::class, $givenType));
}
return true;
} | php | protected function contentIsFileInfo($file, string $method = 'getStream') : bool
{
if (! $file instanceof \SplFileInfo) {
$message = 'The "%s::%s" expect the file array key to be an instance of "%s". "%s" given';
$givenType = (is_object($file) ? get_class($file) : gettype($file));
throw new \RuntimeException(sprintf($message, static::class, $method, \SplFileInfo::class, $givenType));
}
return true;
} | [
"protected",
"function",
"contentIsFileInfo",
"(",
"$",
"file",
",",
"string",
"$",
"method",
"=",
"'getStream'",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"$",
"file",
"instanceof",
"\\",
"SplFileInfo",
")",
"{",
"$",
"message",
"=",
"'The \"%s::%s\" expect the file array key to be an instance of \"%s\". \"%s\" given'",
";",
"$",
"givenType",
"=",
"(",
"is_object",
"(",
"$",
"file",
")",
"?",
"get_class",
"(",
"$",
"file",
")",
":",
"gettype",
"(",
"$",
"file",
")",
")",
";",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"$",
"message",
",",
"static",
"::",
"class",
",",
"$",
"method",
",",
"\\",
"SplFileInfo",
"::",
"class",
",",
"$",
"givenType",
")",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Content is FileInfo
This method validate the instance of the given content parameter. This type is expected to be SplFileInfo.
@param mixed $file The file which the method aim to validate the type
@param string $method The original method name. This parameter is used to define the exception message
@throws \RuntimeException If the given content does not match the expected type
@return bool | [
"Content",
"is",
"FileInfo"
] | 8f4f4bfb8252e392fc17eed2a2b0682c4e9d08ca | https://github.com/Beotie/Beotie-PSR7-stream/blob/8f4f4bfb8252e392fc17eed2a2b0682c4e9d08ca/src/Stream/Factory/FileInfoStreamFactory.php#L118-L128 | train |
itcreator/custom-cmf | Module/Data/src/Cmf/Data/Filter/StripTags.php | StripTags._filterTag | protected function _filterTag($tag)
{
// Parse the tag into:
// 1. a starting delimiter (mandatory)
// 2. a tag name (if available)
// 3. a string of attributes (if available)
// 4. an ending delimiter (if available)
$isMatch = preg_match('~(</?)(\w*)((/(?!>)|[^/>])*)(/?>)~', $tag, $matches);
// If the tag does not match, then strip the tag entirely
if (!$isMatch) {
return '';
}
// Save the matches to more meaningfully named variables
$tagStart = $matches[1];
$tagName = strtolower($matches[2]);
$tagAttributes = $matches[3];
$tagEnd = $matches[5];
// If the tag is not an allowed tag, then remove the tag entirely
if (!isset($this->_tagsAllowed[$tagName])) {
return '';
}
// Trim the attribute string of whitespace at the ends
$tagAttributes = trim($tagAttributes);
// If there are non-whitespace characters in the attribute string
if (strlen($tagAttributes)) {
// Parse iteratively for well-formed attributes
preg_match_all('/(\w+)\s*=\s*(?:(")(.*?)"|(\')(.*?)\')/s', $tagAttributes, $matches);
// Initialize valid attribute accumulator
$tagAttributes = '';
// Iterate over each matched attribute
foreach ($matches[1] as $index => $attributeName) {
$attributeName = strtolower($attributeName);
$attributeDelimiter = $matches[2][$index];
$attributeValue = $matches[3][$index];
// If the attribute is not allowed, then remove it entirely
if (!array_key_exists($attributeName, $this->_tagsAllowed[$tagName]) && !array_key_exists($attributeName, $this->_attributesAllowed)) {
continue;
}
// Add the attribute to the accumulator
$tagAttributes .= " $attributeName=" . $attributeDelimiter . $attributeValue . $attributeDelimiter;
}
}
// Reconstruct tags ending with "/>" as backwards-compatible XHTML tag
if (strpos($tagEnd, '/') !== false) {
$tagEnd = " $tagEnd";
}
// Return the filtered tag
return $tagStart . $tagName . $tagAttributes . $tagEnd;
} | php | protected function _filterTag($tag)
{
// Parse the tag into:
// 1. a starting delimiter (mandatory)
// 2. a tag name (if available)
// 3. a string of attributes (if available)
// 4. an ending delimiter (if available)
$isMatch = preg_match('~(</?)(\w*)((/(?!>)|[^/>])*)(/?>)~', $tag, $matches);
// If the tag does not match, then strip the tag entirely
if (!$isMatch) {
return '';
}
// Save the matches to more meaningfully named variables
$tagStart = $matches[1];
$tagName = strtolower($matches[2]);
$tagAttributes = $matches[3];
$tagEnd = $matches[5];
// If the tag is not an allowed tag, then remove the tag entirely
if (!isset($this->_tagsAllowed[$tagName])) {
return '';
}
// Trim the attribute string of whitespace at the ends
$tagAttributes = trim($tagAttributes);
// If there are non-whitespace characters in the attribute string
if (strlen($tagAttributes)) {
// Parse iteratively for well-formed attributes
preg_match_all('/(\w+)\s*=\s*(?:(")(.*?)"|(\')(.*?)\')/s', $tagAttributes, $matches);
// Initialize valid attribute accumulator
$tagAttributes = '';
// Iterate over each matched attribute
foreach ($matches[1] as $index => $attributeName) {
$attributeName = strtolower($attributeName);
$attributeDelimiter = $matches[2][$index];
$attributeValue = $matches[3][$index];
// If the attribute is not allowed, then remove it entirely
if (!array_key_exists($attributeName, $this->_tagsAllowed[$tagName]) && !array_key_exists($attributeName, $this->_attributesAllowed)) {
continue;
}
// Add the attribute to the accumulator
$tagAttributes .= " $attributeName=" . $attributeDelimiter . $attributeValue . $attributeDelimiter;
}
}
// Reconstruct tags ending with "/>" as backwards-compatible XHTML tag
if (strpos($tagEnd, '/') !== false) {
$tagEnd = " $tagEnd";
}
// Return the filtered tag
return $tagStart . $tagName . $tagAttributes . $tagEnd;
} | [
"protected",
"function",
"_filterTag",
"(",
"$",
"tag",
")",
"{",
"// Parse the tag into:",
"// 1. a starting delimiter (mandatory)",
"// 2. a tag name (if available)",
"// 3. a string of attributes (if available)",
"// 4. an ending delimiter (if available)",
"$",
"isMatch",
"=",
"preg_match",
"(",
"'~(</?)(\\w*)((/(?!>)|[^/>])*)(/?>)~'",
",",
"$",
"tag",
",",
"$",
"matches",
")",
";",
"// If the tag does not match, then strip the tag entirely",
"if",
"(",
"!",
"$",
"isMatch",
")",
"{",
"return",
"''",
";",
"}",
"// Save the matches to more meaningfully named variables",
"$",
"tagStart",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"$",
"tagName",
"=",
"strtolower",
"(",
"$",
"matches",
"[",
"2",
"]",
")",
";",
"$",
"tagAttributes",
"=",
"$",
"matches",
"[",
"3",
"]",
";",
"$",
"tagEnd",
"=",
"$",
"matches",
"[",
"5",
"]",
";",
"// If the tag is not an allowed tag, then remove the tag entirely",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_tagsAllowed",
"[",
"$",
"tagName",
"]",
")",
")",
"{",
"return",
"''",
";",
"}",
"// Trim the attribute string of whitespace at the ends",
"$",
"tagAttributes",
"=",
"trim",
"(",
"$",
"tagAttributes",
")",
";",
"// If there are non-whitespace characters in the attribute string",
"if",
"(",
"strlen",
"(",
"$",
"tagAttributes",
")",
")",
"{",
"// Parse iteratively for well-formed attributes",
"preg_match_all",
"(",
"'/(\\w+)\\s*=\\s*(?:(\")(.*?)\"|(\\')(.*?)\\')/s'",
",",
"$",
"tagAttributes",
",",
"$",
"matches",
")",
";",
"// Initialize valid attribute accumulator",
"$",
"tagAttributes",
"=",
"''",
";",
"// Iterate over each matched attribute",
"foreach",
"(",
"$",
"matches",
"[",
"1",
"]",
"as",
"$",
"index",
"=>",
"$",
"attributeName",
")",
"{",
"$",
"attributeName",
"=",
"strtolower",
"(",
"$",
"attributeName",
")",
";",
"$",
"attributeDelimiter",
"=",
"$",
"matches",
"[",
"2",
"]",
"[",
"$",
"index",
"]",
";",
"$",
"attributeValue",
"=",
"$",
"matches",
"[",
"3",
"]",
"[",
"$",
"index",
"]",
";",
"// If the attribute is not allowed, then remove it entirely",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"attributeName",
",",
"$",
"this",
"->",
"_tagsAllowed",
"[",
"$",
"tagName",
"]",
")",
"&&",
"!",
"array_key_exists",
"(",
"$",
"attributeName",
",",
"$",
"this",
"->",
"_attributesAllowed",
")",
")",
"{",
"continue",
";",
"}",
"// Add the attribute to the accumulator",
"$",
"tagAttributes",
".=",
"\" $attributeName=\"",
".",
"$",
"attributeDelimiter",
".",
"$",
"attributeValue",
".",
"$",
"attributeDelimiter",
";",
"}",
"}",
"// Reconstruct tags ending with \"/>\" as backwards-compatible XHTML tag",
"if",
"(",
"strpos",
"(",
"$",
"tagEnd",
",",
"'/'",
")",
"!==",
"false",
")",
"{",
"$",
"tagEnd",
"=",
"\" $tagEnd\"",
";",
"}",
"// Return the filtered tag",
"return",
"$",
"tagStart",
".",
"$",
"tagName",
".",
"$",
"tagAttributes",
".",
"$",
"tagEnd",
";",
"}"
] | Filters a single tag against the current option settings
@param string $tag
@return string | [
"Filters",
"a",
"single",
"tag",
"against",
"the",
"current",
"option",
"settings"
] | 42fc0535dfa0f641856f06673f6ab596b2020c40 | https://github.com/itcreator/custom-cmf/blob/42fc0535dfa0f641856f06673f6ab596b2020c40/Module/Data/src/Cmf/Data/Filter/StripTags.php#L237-L295 | train |
phpguard/listen | src/PhpGuard/Listen/Adapter/BasicAdapter.php | BasicAdapter.initialize | public function initialize(Listener $listener)
{
$this->listener = $listener;
$this->topDirs = array_merge($this->topDirs,$listener->getPaths());
$this->tracker->initialize($listener);
} | php | public function initialize(Listener $listener)
{
$this->listener = $listener;
$this->topDirs = array_merge($this->topDirs,$listener->getPaths());
$this->tracker->initialize($listener);
} | [
"public",
"function",
"initialize",
"(",
"Listener",
"$",
"listener",
")",
"{",
"$",
"this",
"->",
"listener",
"=",
"$",
"listener",
";",
"$",
"this",
"->",
"topDirs",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"topDirs",
",",
"$",
"listener",
"->",
"getPaths",
"(",
")",
")",
";",
"$",
"this",
"->",
"tracker",
"->",
"initialize",
"(",
"$",
"listener",
")",
";",
"}"
] | Initialize a listener
@param Listener $listener
@return void | [
"Initialize",
"a",
"listener"
] | cd0cda150858d6d85deb025a72996873d2af3532 | https://github.com/phpguard/listen/blob/cd0cda150858d6d85deb025a72996873d2af3532/src/PhpGuard/Listen/Adapter/BasicAdapter.php#L46-L51 | train |
phpguard/listen | src/PhpGuard/Listen/Adapter/BasicAdapter.php | BasicAdapter.doCleanup | private function doCleanup($unchecked)
{
$tracker = $this->tracker;
/* @var \PhpGuard\Listen\Resource\TrackedObject $tracked */
foreach($unchecked as $id=>$tracked){
$origin = $tracked->getResource();
if(!$origin->isExists()){
$tracker->addChangeSet($tracked,FilesystemEvent::DELETE);
$tracker->remove($tracked);
}
unset($unchecked[$id]);
}
} | php | private function doCleanup($unchecked)
{
$tracker = $this->tracker;
/* @var \PhpGuard\Listen\Resource\TrackedObject $tracked */
foreach($unchecked as $id=>$tracked){
$origin = $tracked->getResource();
if(!$origin->isExists()){
$tracker->addChangeSet($tracked,FilesystemEvent::DELETE);
$tracker->remove($tracked);
}
unset($unchecked[$id]);
}
} | [
"private",
"function",
"doCleanup",
"(",
"$",
"unchecked",
")",
"{",
"$",
"tracker",
"=",
"$",
"this",
"->",
"tracker",
";",
"/* @var \\PhpGuard\\Listen\\Resource\\TrackedObject $tracked */",
"foreach",
"(",
"$",
"unchecked",
"as",
"$",
"id",
"=>",
"$",
"tracked",
")",
"{",
"$",
"origin",
"=",
"$",
"tracked",
"->",
"getResource",
"(",
")",
";",
"if",
"(",
"!",
"$",
"origin",
"->",
"isExists",
"(",
")",
")",
"{",
"$",
"tracker",
"->",
"addChangeSet",
"(",
"$",
"tracked",
",",
"FilesystemEvent",
"::",
"DELETE",
")",
";",
"$",
"tracker",
"->",
"remove",
"(",
"$",
"tracked",
")",
";",
"}",
"unset",
"(",
"$",
"unchecked",
"[",
"$",
"id",
"]",
")",
";",
"}",
"}"
] | Track any undetected changes
such as recursive directory delete | [
"Track",
"any",
"undetected",
"changes",
"such",
"as",
"recursive",
"directory",
"delete"
] | cd0cda150858d6d85deb025a72996873d2af3532 | https://github.com/phpguard/listen/blob/cd0cda150858d6d85deb025a72996873d2af3532/src/PhpGuard/Listen/Adapter/BasicAdapter.php#L89-L101 | train |
shgysk8zer0/core_api | traits/http_auth.php | HTTP_Auth.authenticateBasic | final public function authenticateBasic($realm = null)
{
if (! (
array_key_exists('PHP_AUTH_USER', $_SERVER)
and array_key_exists('PHP_AUTH_PW', $_SERVER))
and ! empty($_SERVER['PHP_AUTH_USER'])
and ! empty($_SERER['PHP_AUTH_PW'])
) {
$this->HTTPAuthenticate('Basic', array('realm' => $realm));
return false;
} else {
$this->HTTP_user = $_SERVER['PHP_AUTH_USER'];
$this->HTTP_pass = $_SERVER['PHP_AUTH_PW'];
return true;
}
} | php | final public function authenticateBasic($realm = null)
{
if (! (
array_key_exists('PHP_AUTH_USER', $_SERVER)
and array_key_exists('PHP_AUTH_PW', $_SERVER))
and ! empty($_SERVER['PHP_AUTH_USER'])
and ! empty($_SERER['PHP_AUTH_PW'])
) {
$this->HTTPAuthenticate('Basic', array('realm' => $realm));
return false;
} else {
$this->HTTP_user = $_SERVER['PHP_AUTH_USER'];
$this->HTTP_pass = $_SERVER['PHP_AUTH_PW'];
return true;
}
} | [
"final",
"public",
"function",
"authenticateBasic",
"(",
"$",
"realm",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"(",
"array_key_exists",
"(",
"'PHP_AUTH_USER'",
",",
"$",
"_SERVER",
")",
"and",
"array_key_exists",
"(",
"'PHP_AUTH_PW'",
",",
"$",
"_SERVER",
")",
")",
"and",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'PHP_AUTH_USER'",
"]",
")",
"and",
"!",
"empty",
"(",
"$",
"_SERER",
"[",
"'PHP_AUTH_PW'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"HTTPAuthenticate",
"(",
"'Basic'",
",",
"array",
"(",
"'realm'",
"=>",
"$",
"realm",
")",
")",
";",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"HTTP_user",
"=",
"$",
"_SERVER",
"[",
"'PHP_AUTH_USER'",
"]",
";",
"$",
"this",
"->",
"HTTP_pass",
"=",
"$",
"_SERVER",
"[",
"'PHP_AUTH_PW'",
"]",
";",
"return",
"true",
";",
"}",
"}"
] | Checks for credentials in HTTP headers for "Basic" authentication
@param string $realm
@return bool | [
"Checks",
"for",
"credentials",
"in",
"HTTP",
"headers",
"for",
"Basic",
"authentication"
] | 9e9b8baf761af874b95256ad2462e55fbb2b2e58 | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/http_auth.php#L48-L63 | train |
ThomasSquall/PHPMagicAnnotations | src/Reflection/ReflectionBase.php | ReflectionBase.hasAnnotation | public function hasAnnotation($name)
{
$result = false;
if (!string_ends_with($name, 'Annotation')) $name .= 'Annotation';
foreach ($this->annotations as $annotation)
{
$class = get_class($annotation);
if (string_starts_with($class, "\\") && !string_starts_with($name, "\\"))
$name = "\\" . $name;
elseif (!string_starts_with($class, "\\") && string_starts_with($name, "\\"))
$name = substr($name, 1);
if (string_ends_with($class, $name))
{
$result = true;
break;
}
}
return $result;
} | php | public function hasAnnotation($name)
{
$result = false;
if (!string_ends_with($name, 'Annotation')) $name .= 'Annotation';
foreach ($this->annotations as $annotation)
{
$class = get_class($annotation);
if (string_starts_with($class, "\\") && !string_starts_with($name, "\\"))
$name = "\\" . $name;
elseif (!string_starts_with($class, "\\") && string_starts_with($name, "\\"))
$name = substr($name, 1);
if (string_ends_with($class, $name))
{
$result = true;
break;
}
}
return $result;
} | [
"public",
"function",
"hasAnnotation",
"(",
"$",
"name",
")",
"{",
"$",
"result",
"=",
"false",
";",
"if",
"(",
"!",
"string_ends_with",
"(",
"$",
"name",
",",
"'Annotation'",
")",
")",
"$",
"name",
".=",
"'Annotation'",
";",
"foreach",
"(",
"$",
"this",
"->",
"annotations",
"as",
"$",
"annotation",
")",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"annotation",
")",
";",
"if",
"(",
"string_starts_with",
"(",
"$",
"class",
",",
"\"\\\\\"",
")",
"&&",
"!",
"string_starts_with",
"(",
"$",
"name",
",",
"\"\\\\\"",
")",
")",
"$",
"name",
"=",
"\"\\\\\"",
".",
"$",
"name",
";",
"elseif",
"(",
"!",
"string_starts_with",
"(",
"$",
"class",
",",
"\"\\\\\"",
")",
"&&",
"string_starts_with",
"(",
"$",
"name",
",",
"\"\\\\\"",
")",
")",
"$",
"name",
"=",
"substr",
"(",
"$",
"name",
",",
"1",
")",
";",
"if",
"(",
"string_ends_with",
"(",
"$",
"class",
",",
"$",
"name",
")",
")",
"{",
"$",
"result",
"=",
"true",
";",
"break",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Tells if the reflection object has the given annotation or not.
@param string $name
@return bool | [
"Tells",
"if",
"the",
"reflection",
"object",
"has",
"the",
"given",
"annotation",
"or",
"not",
"."
] | 3a733fa6e1ca9ebdfdfb7250f67e7aceb6a4c001 | https://github.com/ThomasSquall/PHPMagicAnnotations/blob/3a733fa6e1ca9ebdfdfb7250f67e7aceb6a4c001/src/Reflection/ReflectionBase.php#L20-L43 | train |
ThomasSquall/PHPMagicAnnotations | src/Reflection/ReflectionBase.php | ReflectionBase.getAnnotation | public function getAnnotation($name)
{
$result = null;
if ($this->hasAnnotationAndReturn($name))
{
if (!string_ends_with($name, 'Annotation')) $name .= 'Annotation';
$result = isset($this->annotations[$name]) ? $this->annotations[$name] : null;
if ($result == null)
{
if (string_starts_with($name, '\\'))
$name = substr($name, 1, strlen($name) - 1);
else
$name = '\\' . $name;
$result = isset($this->annotations[$name]) ? $this->annotations[$name] : null;
}
$result = $this->evaluateAnnotation($result);
}
return $result;
} | php | public function getAnnotation($name)
{
$result = null;
if ($this->hasAnnotationAndReturn($name))
{
if (!string_ends_with($name, 'Annotation')) $name .= 'Annotation';
$result = isset($this->annotations[$name]) ? $this->annotations[$name] : null;
if ($result == null)
{
if (string_starts_with($name, '\\'))
$name = substr($name, 1, strlen($name) - 1);
else
$name = '\\' . $name;
$result = isset($this->annotations[$name]) ? $this->annotations[$name] : null;
}
$result = $this->evaluateAnnotation($result);
}
return $result;
} | [
"public",
"function",
"getAnnotation",
"(",
"$",
"name",
")",
"{",
"$",
"result",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"hasAnnotationAndReturn",
"(",
"$",
"name",
")",
")",
"{",
"if",
"(",
"!",
"string_ends_with",
"(",
"$",
"name",
",",
"'Annotation'",
")",
")",
"$",
"name",
".=",
"'Annotation'",
";",
"$",
"result",
"=",
"isset",
"(",
"$",
"this",
"->",
"annotations",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"this",
"->",
"annotations",
"[",
"$",
"name",
"]",
":",
"null",
";",
"if",
"(",
"$",
"result",
"==",
"null",
")",
"{",
"if",
"(",
"string_starts_with",
"(",
"$",
"name",
",",
"'\\\\'",
")",
")",
"$",
"name",
"=",
"substr",
"(",
"$",
"name",
",",
"1",
",",
"strlen",
"(",
"$",
"name",
")",
"-",
"1",
")",
";",
"else",
"$",
"name",
"=",
"'\\\\'",
".",
"$",
"name",
";",
"$",
"result",
"=",
"isset",
"(",
"$",
"this",
"->",
"annotations",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"this",
"->",
"annotations",
"[",
"$",
"name",
"]",
":",
"null",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"evaluateAnnotation",
"(",
"$",
"result",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns the requested annotation.
@param string $name
@return Annotation|null | [
"Returns",
"the",
"requested",
"annotation",
"."
] | 3a733fa6e1ca9ebdfdfb7250f67e7aceb6a4c001 | https://github.com/ThomasSquall/PHPMagicAnnotations/blob/3a733fa6e1ca9ebdfdfb7250f67e7aceb6a4c001/src/Reflection/ReflectionBase.php#L76-L100 | train |
native5/native5-sdk-client-php | src/Native5/Sessions/WebSessionManager.php | WebSessionManager.isActiveSession | public function isActiveSession()
{
// Check if session timeout is defined in application settings
$sessionConfig = $GLOBALS['app']->getConfiguration()->getRawConfiguration('session');
if (!empty($sessionConfig) && isset($sessionConfig['timeout']) && !empty($sessionConfig['timeout'])) {
$sessionTimeout = $sessionConfig['timeout'];
} else {
$sessionTimeout = SESSION_TIMEOUT;
}
file_put_contents(getcwd().'/logs/session.log', print_r($_SESSION, 1));
if(isset($_SESSION[self::GLOBAL_PREFIX.'last_accessed']) &&
(time() - $_SESSION[self::GLOBAL_PREFIX.'last_accessed'] > $sessionTimeout)) {
return FALSE;
}
return TRUE;
} | php | public function isActiveSession()
{
// Check if session timeout is defined in application settings
$sessionConfig = $GLOBALS['app']->getConfiguration()->getRawConfiguration('session');
if (!empty($sessionConfig) && isset($sessionConfig['timeout']) && !empty($sessionConfig['timeout'])) {
$sessionTimeout = $sessionConfig['timeout'];
} else {
$sessionTimeout = SESSION_TIMEOUT;
}
file_put_contents(getcwd().'/logs/session.log', print_r($_SESSION, 1));
if(isset($_SESSION[self::GLOBAL_PREFIX.'last_accessed']) &&
(time() - $_SESSION[self::GLOBAL_PREFIX.'last_accessed'] > $sessionTimeout)) {
return FALSE;
}
return TRUE;
} | [
"public",
"function",
"isActiveSession",
"(",
")",
"{",
"// Check if session timeout is defined in application settings",
"$",
"sessionConfig",
"=",
"$",
"GLOBALS",
"[",
"'app'",
"]",
"->",
"getConfiguration",
"(",
")",
"->",
"getRawConfiguration",
"(",
"'session'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"sessionConfig",
")",
"&&",
"isset",
"(",
"$",
"sessionConfig",
"[",
"'timeout'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"sessionConfig",
"[",
"'timeout'",
"]",
")",
")",
"{",
"$",
"sessionTimeout",
"=",
"$",
"sessionConfig",
"[",
"'timeout'",
"]",
";",
"}",
"else",
"{",
"$",
"sessionTimeout",
"=",
"SESSION_TIMEOUT",
";",
"}",
"file_put_contents",
"(",
"getcwd",
"(",
")",
".",
"'/logs/session.log'",
",",
"print_r",
"(",
"$",
"_SESSION",
",",
"1",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_SESSION",
"[",
"self",
"::",
"GLOBAL_PREFIX",
".",
"'last_accessed'",
"]",
")",
"&&",
"(",
"time",
"(",
")",
"-",
"$",
"_SESSION",
"[",
"self",
"::",
"GLOBAL_PREFIX",
".",
"'last_accessed'",
"]",
">",
"$",
"sessionTimeout",
")",
")",
"{",
"return",
"FALSE",
";",
"}",
"return",
"TRUE",
";",
"}"
] | Checks if session is currently active.
@access public
@return boolean | [
"Checks",
"if",
"session",
"is",
"currently",
"active",
"."
] | e1f598cf27654d81bb5facace1990b737242a2f9 | https://github.com/native5/native5-sdk-client-php/blob/e1f598cf27654d81bb5facace1990b737242a2f9/src/Native5/Sessions/WebSessionManager.php#L175-L193 | train |
native5/native5-sdk-client-php | src/Native5/Sessions/WebSessionManager.php | WebSessionManager.resetActiveSession | public static function resetActiveSession()
{
// Strip '.'
$appContext = rtrim($GLOBALS['app']->getConfiguration()->getApplicationContext(), '.');
if (empty($appContext)) {
$appContext = "/";
} else {
$appContext = "/".$appContext."/";
}
$category = $_SESSION[self::GLOBAL_PREFIX.'category'];
session_unset();
session_destroy();
$sessionCookieName = $GLOBALS['app']->getConfiguration()->getApplicationContext()."-"."_n5_session";
$sessionCookieName = preg_replace("/\./", "_",$sessionCookieName);
session_set_cookie_params(0, $appContext, null, false, true);
session_name($sessionCookieName);
session_start();
session_regenerate_id();
$_SESSION = array();
$_SESSION[self::GLOBAL_PREFIX.'category'] = $category;
$_SESSION[self::GLOBAL_PREFIX.'last_accessed'] = time();
} | php | public static function resetActiveSession()
{
// Strip '.'
$appContext = rtrim($GLOBALS['app']->getConfiguration()->getApplicationContext(), '.');
if (empty($appContext)) {
$appContext = "/";
} else {
$appContext = "/".$appContext."/";
}
$category = $_SESSION[self::GLOBAL_PREFIX.'category'];
session_unset();
session_destroy();
$sessionCookieName = $GLOBALS['app']->getConfiguration()->getApplicationContext()."-"."_n5_session";
$sessionCookieName = preg_replace("/\./", "_",$sessionCookieName);
session_set_cookie_params(0, $appContext, null, false, true);
session_name($sessionCookieName);
session_start();
session_regenerate_id();
$_SESSION = array();
$_SESSION[self::GLOBAL_PREFIX.'category'] = $category;
$_SESSION[self::GLOBAL_PREFIX.'last_accessed'] = time();
} | [
"public",
"static",
"function",
"resetActiveSession",
"(",
")",
"{",
"// Strip '.'",
"$",
"appContext",
"=",
"rtrim",
"(",
"$",
"GLOBALS",
"[",
"'app'",
"]",
"->",
"getConfiguration",
"(",
")",
"->",
"getApplicationContext",
"(",
")",
",",
"'.'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"appContext",
")",
")",
"{",
"$",
"appContext",
"=",
"\"/\"",
";",
"}",
"else",
"{",
"$",
"appContext",
"=",
"\"/\"",
".",
"$",
"appContext",
".",
"\"/\"",
";",
"}",
"$",
"category",
"=",
"$",
"_SESSION",
"[",
"self",
"::",
"GLOBAL_PREFIX",
".",
"'category'",
"]",
";",
"session_unset",
"(",
")",
";",
"session_destroy",
"(",
")",
";",
"$",
"sessionCookieName",
"=",
"$",
"GLOBALS",
"[",
"'app'",
"]",
"->",
"getConfiguration",
"(",
")",
"->",
"getApplicationContext",
"(",
")",
".",
"\"-\"",
".",
"\"_n5_session\"",
";",
"$",
"sessionCookieName",
"=",
"preg_replace",
"(",
"\"/\\./\"",
",",
"\"_\"",
",",
"$",
"sessionCookieName",
")",
";",
"session_set_cookie_params",
"(",
"0",
",",
"$",
"appContext",
",",
"null",
",",
"false",
",",
"true",
")",
";",
"session_name",
"(",
"$",
"sessionCookieName",
")",
";",
"session_start",
"(",
")",
";",
"session_regenerate_id",
"(",
")",
";",
"$",
"_SESSION",
"=",
"array",
"(",
")",
";",
"$",
"_SESSION",
"[",
"self",
"::",
"GLOBAL_PREFIX",
".",
"'category'",
"]",
"=",
"$",
"category",
";",
"$",
"_SESSION",
"[",
"self",
"::",
"GLOBAL_PREFIX",
".",
"'last_accessed'",
"]",
"=",
"time",
"(",
")",
";",
"}"
] | Resets currently active session.
@access public
@return void | [
"Resets",
"currently",
"active",
"session",
"."
] | e1f598cf27654d81bb5facace1990b737242a2f9 | https://github.com/native5/native5-sdk-client-php/blob/e1f598cf27654d81bb5facace1990b737242a2f9/src/Native5/Sessions/WebSessionManager.php#L202-L225 | train |
MindyPHP/QueryBuilder | Database/Pgsql/Adapter.php | Adapter.sqlCheckIntegrity | public function sqlCheckIntegrity($check = true, $schema = '', $table = '')
{
if (empty($schema) && empty($table)) {
return 'SET CONSTRAINTS ALL '.($check ? 'IMMEDIATE' : 'DEFERRED');
}
return sprintf(
'ALTER TABLE %s.%s %s TRIGGER ALL',
$this->getQuotedName($table),
$this->getQuotedName($schema),
$check ? 'ENABLE' : 'DISABLE'
);
} | php | public function sqlCheckIntegrity($check = true, $schema = '', $table = '')
{
if (empty($schema) && empty($table)) {
return 'SET CONSTRAINTS ALL '.($check ? 'IMMEDIATE' : 'DEFERRED');
}
return sprintf(
'ALTER TABLE %s.%s %s TRIGGER ALL',
$this->getQuotedName($table),
$this->getQuotedName($schema),
$check ? 'ENABLE' : 'DISABLE'
);
} | [
"public",
"function",
"sqlCheckIntegrity",
"(",
"$",
"check",
"=",
"true",
",",
"$",
"schema",
"=",
"''",
",",
"$",
"table",
"=",
"''",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"schema",
")",
"&&",
"empty",
"(",
"$",
"table",
")",
")",
"{",
"return",
"'SET CONSTRAINTS ALL '",
".",
"(",
"$",
"check",
"?",
"'IMMEDIATE'",
":",
"'DEFERRED'",
")",
";",
"}",
"return",
"sprintf",
"(",
"'ALTER TABLE %s.%s %s TRIGGER ALL'",
",",
"$",
"this",
"->",
"getQuotedName",
"(",
"$",
"table",
")",
",",
"$",
"this",
"->",
"getQuotedName",
"(",
"$",
"schema",
")",
",",
"$",
"check",
"?",
"'ENABLE'",
":",
"'DISABLE'",
")",
";",
"}"
] | Builds a SQL statement for enabling or disabling integrity check.
@param bool $check whether to turn on or off the integrity check
@param string $schema the schema of the tables
@param string $table the table name
@return string the SQL statement for checking integrity | [
"Builds",
"a",
"SQL",
"statement",
"for",
"enabling",
"or",
"disabling",
"integrity",
"check",
"."
] | fc486454786f3d38887dd7246802ea11e2954e54 | https://github.com/MindyPHP/QueryBuilder/blob/fc486454786f3d38887dd7246802ea11e2954e54/Database/Pgsql/Adapter.php#L28-L40 | train |
linpax/microphp-framework | src/web/Identity.php | Identity.addCookie | public function addCookie(
$name,
$value,
$expire = 0,
$path = '/',
$domain = '',
$secure = false,
$httpOnly = true
) {
return (new CookieInjector)->build()->set($name, $value, $expire, $path, $domain, $secure, $httpOnly);
} | php | public function addCookie(
$name,
$value,
$expire = 0,
$path = '/',
$domain = '',
$secure = false,
$httpOnly = true
) {
return (new CookieInjector)->build()->set($name, $value, $expire, $path, $domain, $secure, $httpOnly);
} | [
"public",
"function",
"addCookie",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"expire",
"=",
"0",
",",
"$",
"path",
"=",
"'/'",
",",
"$",
"domain",
"=",
"''",
",",
"$",
"secure",
"=",
"false",
",",
"$",
"httpOnly",
"=",
"true",
")",
"{",
"return",
"(",
"new",
"CookieInjector",
")",
"->",
"build",
"(",
")",
"->",
"set",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"expire",
",",
"$",
"path",
",",
"$",
"domain",
",",
"$",
"secure",
",",
"$",
"httpOnly",
")",
";",
"}"
] | Add data into cookie
@access public
@param string $name cookie name
@param mixed $value data value
@param int $expire life time
@param string $path path access cookie
@param string $domain domain access cookie
@param bool $secure use SSL?
@param bool $httpOnly disable on JS?
@return mixed
@throws Exception | [
"Add",
"data",
"into",
"cookie"
] | 11f3370f3f64c516cce9b84ecd8276c6e9ae8df9 | https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/web/Identity.php#L89-L99 | train |
pryley/castor-framework | src/Forms/Fields/Base.php | Base.generateDescription | public function generateDescription( $paragraph = true )
{
if( !isset( $this->args['desc'] ) || !$this->args['desc'] )return;
$tag = ( !!$paragraph || $paragraph == 'p' ) ? 'p' : 'span';
return sprintf( '<%1$s class="description">%2$s</%1$s>', $tag, $this->args['desc'] );
} | php | public function generateDescription( $paragraph = true )
{
if( !isset( $this->args['desc'] ) || !$this->args['desc'] )return;
$tag = ( !!$paragraph || $paragraph == 'p' ) ? 'p' : 'span';
return sprintf( '<%1$s class="description">%2$s</%1$s>', $tag, $this->args['desc'] );
} | [
"public",
"function",
"generateDescription",
"(",
"$",
"paragraph",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"args",
"[",
"'desc'",
"]",
")",
"||",
"!",
"$",
"this",
"->",
"args",
"[",
"'desc'",
"]",
")",
"return",
";",
"$",
"tag",
"=",
"(",
"!",
"!",
"$",
"paragraph",
"||",
"$",
"paragraph",
"==",
"'p'",
")",
"?",
"'p'",
":",
"'span'",
";",
"return",
"sprintf",
"(",
"'<%1$s class=\"description\">%2$s</%1$s>'",
",",
"$",
"tag",
",",
"$",
"this",
"->",
"args",
"[",
"'desc'",
"]",
")",
";",
"}"
] | Generate the field description
@param bool $paragraph
@return null|string | [
"Generate",
"the",
"field",
"description"
] | cbc137d02625cd05f4cc96414d6f70e451cb821f | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Forms/Fields/Base.php#L72-L79 | train |
pryley/castor-framework | src/Forms/Fields/Base.php | Base.implodeOptions | protected function implodeOptions( $method = 'select_option', $default = null )
{
$this->args['default'] ?: $this->args['default'] = $default;
$method = $this->camelCase( $method );
$method = method_exists( $this, $method )
? $method
: 'selectOption';
$i = 0;
if( $method === 'singleInput' ) {
if( !isset( $this->args['options'] ) || empty( $this->args['options'] ))return;
// hack to make sure unset single checkbox values start at 1 instead of 0
if( key( $this->args['options'] ) === 0 ) {
$options = ['1' => $this->args['options'][0]];
$this->args['options'] = $options;
}
return $this->singleInput();
}
return array_reduce( array_keys( $this->args['options'] ), function( $carry, $key ) use ( &$i, $method ) {
return $carry .= $this->$method( $key, $i++ );
});
} | php | protected function implodeOptions( $method = 'select_option', $default = null )
{
$this->args['default'] ?: $this->args['default'] = $default;
$method = $this->camelCase( $method );
$method = method_exists( $this, $method )
? $method
: 'selectOption';
$i = 0;
if( $method === 'singleInput' ) {
if( !isset( $this->args['options'] ) || empty( $this->args['options'] ))return;
// hack to make sure unset single checkbox values start at 1 instead of 0
if( key( $this->args['options'] ) === 0 ) {
$options = ['1' => $this->args['options'][0]];
$this->args['options'] = $options;
}
return $this->singleInput();
}
return array_reduce( array_keys( $this->args['options'] ), function( $carry, $key ) use ( &$i, $method ) {
return $carry .= $this->$method( $key, $i++ );
});
} | [
"protected",
"function",
"implodeOptions",
"(",
"$",
"method",
"=",
"'select_option'",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"args",
"[",
"'default'",
"]",
"?",
":",
"$",
"this",
"->",
"args",
"[",
"'default'",
"]",
"=",
"$",
"default",
";",
"$",
"method",
"=",
"$",
"this",
"->",
"camelCase",
"(",
"$",
"method",
")",
";",
"$",
"method",
"=",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
"?",
"$",
"method",
":",
"'selectOption'",
";",
"$",
"i",
"=",
"0",
";",
"if",
"(",
"$",
"method",
"===",
"'singleInput'",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"args",
"[",
"'options'",
"]",
")",
"||",
"empty",
"(",
"$",
"this",
"->",
"args",
"[",
"'options'",
"]",
")",
")",
"return",
";",
"// hack to make sure unset single checkbox values start at 1 instead of 0",
"if",
"(",
"key",
"(",
"$",
"this",
"->",
"args",
"[",
"'options'",
"]",
")",
"===",
"0",
")",
"{",
"$",
"options",
"=",
"[",
"'1'",
"=>",
"$",
"this",
"->",
"args",
"[",
"'options'",
"]",
"[",
"0",
"]",
"]",
";",
"$",
"this",
"->",
"args",
"[",
"'options'",
"]",
"=",
"$",
"options",
";",
"}",
"return",
"$",
"this",
"->",
"singleInput",
"(",
")",
";",
"}",
"return",
"array_reduce",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"args",
"[",
"'options'",
"]",
")",
",",
"function",
"(",
"$",
"carry",
",",
"$",
"key",
")",
"use",
"(",
"&",
"$",
"i",
",",
"$",
"method",
")",
"{",
"return",
"$",
"carry",
".=",
"$",
"this",
"->",
"$",
"method",
"(",
"$",
"key",
",",
"$",
"i",
"++",
")",
";",
"}",
")",
";",
"}"
] | Implode multi-field items
@return null|string | [
"Implode",
"multi",
"-",
"field",
"items"
] | cbc137d02625cd05f4cc96414d6f70e451cb821f | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Forms/Fields/Base.php#L133-L161 | train |
pryley/castor-framework | src/Forms/Fields/Base.php | Base.normalize | protected function normalize( array $defaults = [], $implode = false )
{
$args = $this->mergeAttributesWith( $defaults );
$normalize = new Normalizer;
return ( $this->element && method_exists( $normalize, $this->element ))
? $normalize->{$this->element}( $args, $implode )
: ( !!$implode ? '' : [] );
} | php | protected function normalize( array $defaults = [], $implode = false )
{
$args = $this->mergeAttributesWith( $defaults );
$normalize = new Normalizer;
return ( $this->element && method_exists( $normalize, $this->element ))
? $normalize->{$this->element}( $args, $implode )
: ( !!$implode ? '' : [] );
} | [
"protected",
"function",
"normalize",
"(",
"array",
"$",
"defaults",
"=",
"[",
"]",
",",
"$",
"implode",
"=",
"false",
")",
"{",
"$",
"args",
"=",
"$",
"this",
"->",
"mergeAttributesWith",
"(",
"$",
"defaults",
")",
";",
"$",
"normalize",
"=",
"new",
"Normalizer",
";",
"return",
"(",
"$",
"this",
"->",
"element",
"&&",
"method_exists",
"(",
"$",
"normalize",
",",
"$",
"this",
"->",
"element",
")",
")",
"?",
"$",
"normalize",
"->",
"{",
"$",
"this",
"->",
"element",
"}",
"(",
"$",
"args",
",",
"$",
"implode",
")",
":",
"(",
"!",
"!",
"$",
"implode",
"?",
"''",
":",
"[",
"]",
")",
";",
"}"
] | Normalize attributes for this specific field type
@param bool|string $implode
@return array|string | [
"Normalize",
"attributes",
"for",
"this",
"specific",
"field",
"type"
] | cbc137d02625cd05f4cc96414d6f70e451cb821f | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Forms/Fields/Base.php#L170-L179 | train |
pryley/castor-framework | src/Forms/Fields/Base.php | Base.multiInput | protected function multiInput( $optionKey, $number, $type = 'radio' )
{
$args = $this->multiInputArgs( $type, $optionKey, $number );
if( !$args )return;
$attributes = '';
foreach( $args['attributes'] as $key => $val ) {
$attributes .= sprintf( '%s="%s" ', $key, $val );
}
return sprintf( '<li><label for="%s"><input %s%s/> %s</label></li>',
$args['attributes']['id'],
$attributes,
checked( $args['value'], $args['attributes']['value'], false ),
$args['label']
);
} | php | protected function multiInput( $optionKey, $number, $type = 'radio' )
{
$args = $this->multiInputArgs( $type, $optionKey, $number );
if( !$args )return;
$attributes = '';
foreach( $args['attributes'] as $key => $val ) {
$attributes .= sprintf( '%s="%s" ', $key, $val );
}
return sprintf( '<li><label for="%s"><input %s%s/> %s</label></li>',
$args['attributes']['id'],
$attributes,
checked( $args['value'], $args['attributes']['value'], false ),
$args['label']
);
} | [
"protected",
"function",
"multiInput",
"(",
"$",
"optionKey",
",",
"$",
"number",
",",
"$",
"type",
"=",
"'radio'",
")",
"{",
"$",
"args",
"=",
"$",
"this",
"->",
"multiInputArgs",
"(",
"$",
"type",
",",
"$",
"optionKey",
",",
"$",
"number",
")",
";",
"if",
"(",
"!",
"$",
"args",
")",
"return",
";",
"$",
"attributes",
"=",
"''",
";",
"foreach",
"(",
"$",
"args",
"[",
"'attributes'",
"]",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"attributes",
".=",
"sprintf",
"(",
"'%s=\"%s\" '",
",",
"$",
"key",
",",
"$",
"val",
")",
";",
"}",
"return",
"sprintf",
"(",
"'<li><label for=\"%s\"><input %s%s/> %s</label></li>'",
",",
"$",
"args",
"[",
"'attributes'",
"]",
"[",
"'id'",
"]",
",",
"$",
"attributes",
",",
"checked",
"(",
"$",
"args",
"[",
"'value'",
"]",
",",
"$",
"args",
"[",
"'attributes'",
"]",
"[",
"'value'",
"]",
",",
"false",
")",
",",
"$",
"args",
"[",
"'label'",
"]",
")",
";",
"}"
] | Generate checkboxes and radios
@param string $optionKey
@param string $number
@param string $type
@return null|string | [
"Generate",
"checkboxes",
"and",
"radios"
] | cbc137d02625cd05f4cc96414d6f70e451cb821f | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Forms/Fields/Base.php#L209-L227 | train |
pryley/castor-framework | src/Forms/Fields/Base.php | Base.selectOption | protected function selectOption( $optionKey )
{
return sprintf( '<option value="%s"%s>%s</option>',
$optionKey,
selected( $this->args['value'], $optionKey, false ),
$this->args['options'][ $optionKey ]
);
} | php | protected function selectOption( $optionKey )
{
return sprintf( '<option value="%s"%s>%s</option>',
$optionKey,
selected( $this->args['value'], $optionKey, false ),
$this->args['options'][ $optionKey ]
);
} | [
"protected",
"function",
"selectOption",
"(",
"$",
"optionKey",
")",
"{",
"return",
"sprintf",
"(",
"'<option value=\"%s\"%s>%s</option>'",
",",
"$",
"optionKey",
",",
"selected",
"(",
"$",
"this",
"->",
"args",
"[",
"'value'",
"]",
",",
"$",
"optionKey",
",",
"false",
")",
",",
"$",
"this",
"->",
"args",
"[",
"'options'",
"]",
"[",
"$",
"optionKey",
"]",
")",
";",
"}"
] | Generate select options
@param string $optionKey
@return string | [
"Generate",
"select",
"options"
] | cbc137d02625cd05f4cc96414d6f70e451cb821f | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Forms/Fields/Base.php#L312-L319 | train |
pryley/castor-framework | src/Forms/Fields/Base.php | Base.singleInput | protected function singleInput( $type = 'checkbox' )
{
$optionKey = key( $this->args['options'] );
$args = $this->multiInputArgs( $type, $optionKey, 1 );
if( !$args )return;
$atts = $this->normalize();
$atts = wp_parse_args( $args['attributes'], $atts );
$attributes = '';
foreach( $atts as $key => $val ) {
$attributes .= sprintf( '%s="%s" ', $key, $val );
}
return sprintf( '<label for="%s"><input %s%s/> %s</label>',
$atts['id'],
$attributes,
checked( $args['value'], $atts['value'], false ),
$args['label']
);
} | php | protected function singleInput( $type = 'checkbox' )
{
$optionKey = key( $this->args['options'] );
$args = $this->multiInputArgs( $type, $optionKey, 1 );
if( !$args )return;
$atts = $this->normalize();
$atts = wp_parse_args( $args['attributes'], $atts );
$attributes = '';
foreach( $atts as $key => $val ) {
$attributes .= sprintf( '%s="%s" ', $key, $val );
}
return sprintf( '<label for="%s"><input %s%s/> %s</label>',
$atts['id'],
$attributes,
checked( $args['value'], $atts['value'], false ),
$args['label']
);
} | [
"protected",
"function",
"singleInput",
"(",
"$",
"type",
"=",
"'checkbox'",
")",
"{",
"$",
"optionKey",
"=",
"key",
"(",
"$",
"this",
"->",
"args",
"[",
"'options'",
"]",
")",
";",
"$",
"args",
"=",
"$",
"this",
"->",
"multiInputArgs",
"(",
"$",
"type",
",",
"$",
"optionKey",
",",
"1",
")",
";",
"if",
"(",
"!",
"$",
"args",
")",
"return",
";",
"$",
"atts",
"=",
"$",
"this",
"->",
"normalize",
"(",
")",
";",
"$",
"atts",
"=",
"wp_parse_args",
"(",
"$",
"args",
"[",
"'attributes'",
"]",
",",
"$",
"atts",
")",
";",
"$",
"attributes",
"=",
"''",
";",
"foreach",
"(",
"$",
"atts",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"attributes",
".=",
"sprintf",
"(",
"'%s=\"%s\" '",
",",
"$",
"key",
",",
"$",
"val",
")",
";",
"}",
"return",
"sprintf",
"(",
"'<label for=\"%s\"><input %s%s/> %s</label>'",
",",
"$",
"atts",
"[",
"'id'",
"]",
",",
"$",
"attributes",
",",
"checked",
"(",
"$",
"args",
"[",
"'value'",
"]",
",",
"$",
"atts",
"[",
"'value'",
"]",
",",
"false",
")",
",",
"$",
"args",
"[",
"'label'",
"]",
")",
";",
"}"
] | Generate a single checkbox
@param string $type
@return null|string | [
"Generate",
"a",
"single",
"checkbox"
] | cbc137d02625cd05f4cc96414d6f70e451cb821f | https://github.com/pryley/castor-framework/blob/cbc137d02625cd05f4cc96414d6f70e451cb821f/src/Forms/Fields/Base.php#L328-L351 | train |
erenmustafaozdal/laravel-modules-base | src/Controllers/DataTableTrait.php | DataTableTrait.setColumns | public function setColumns(array $columns)
{
// add columns
foreach($columns['add'] as $key => $value) {
$this->dataTables->addColumn($key, $value);
}
// edit columns
foreach($columns['edit'] as $key => $value) {
$this->dataTables->editColumn($key, $value);
}
// remove columns
foreach($columns['remove'] as $value) {
$this->dataTables->removeColumn($value);
}
} | php | public function setColumns(array $columns)
{
// add columns
foreach($columns['add'] as $key => $value) {
$this->dataTables->addColumn($key, $value);
}
// edit columns
foreach($columns['edit'] as $key => $value) {
$this->dataTables->editColumn($key, $value);
}
// remove columns
foreach($columns['remove'] as $value) {
$this->dataTables->removeColumn($value);
}
} | [
"public",
"function",
"setColumns",
"(",
"array",
"$",
"columns",
")",
"{",
"// add columns",
"foreach",
"(",
"$",
"columns",
"[",
"'add'",
"]",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"dataTables",
"->",
"addColumn",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"// edit columns",
"foreach",
"(",
"$",
"columns",
"[",
"'edit'",
"]",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"dataTables",
"->",
"editColumn",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"// remove columns",
"foreach",
"(",
"$",
"columns",
"[",
"'remove'",
"]",
"as",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"dataTables",
"->",
"removeColumn",
"(",
"$",
"value",
")",
";",
"}",
"}"
] | set data table columns
@param array $columns [array('add' => ..., 'edit' => ...,'remove' => ...)]
@return void | [
"set",
"data",
"table",
"columns"
] | c26600543817642926bcf16ada84009e00d784e0 | https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Controllers/DataTableTrait.php#L56-L72 | train |
erenmustafaozdal/laravel-modules-base | src/Controllers/DataTableTrait.php | DataTableTrait.getDefaultUrls | private function getDefaultUrls($model)
{
$slug = getModelSlug($model);
return [
'details' => lmbRoute("api.{$slug}.detail", ['id' => $model->id]),
'fast_edit' => lmbRoute("api.{$slug}.fastEdit", ['id' => $model->id]),
'edit' => lmbRoute("api.{$slug}.update", ['id' => $model->id]),
'destroy' => lmbRoute("api.{$slug}.destroy", ['id' => $model->id]),
'show' => lmbRoute("admin.{$slug}.show", ['id' => $model->id])
];
} | php | private function getDefaultUrls($model)
{
$slug = getModelSlug($model);
return [
'details' => lmbRoute("api.{$slug}.detail", ['id' => $model->id]),
'fast_edit' => lmbRoute("api.{$slug}.fastEdit", ['id' => $model->id]),
'edit' => lmbRoute("api.{$slug}.update", ['id' => $model->id]),
'destroy' => lmbRoute("api.{$slug}.destroy", ['id' => $model->id]),
'show' => lmbRoute("admin.{$slug}.show", ['id' => $model->id])
];
} | [
"private",
"function",
"getDefaultUrls",
"(",
"$",
"model",
")",
"{",
"$",
"slug",
"=",
"getModelSlug",
"(",
"$",
"model",
")",
";",
"return",
"[",
"'details'",
"=>",
"lmbRoute",
"(",
"\"api.{$slug}.detail\"",
",",
"[",
"'id'",
"=>",
"$",
"model",
"->",
"id",
"]",
")",
",",
"'fast_edit'",
"=>",
"lmbRoute",
"(",
"\"api.{$slug}.fastEdit\"",
",",
"[",
"'id'",
"=>",
"$",
"model",
"->",
"id",
"]",
")",
",",
"'edit'",
"=>",
"lmbRoute",
"(",
"\"api.{$slug}.update\"",
",",
"[",
"'id'",
"=>",
"$",
"model",
"->",
"id",
"]",
")",
",",
"'destroy'",
"=>",
"lmbRoute",
"(",
"\"api.{$slug}.destroy\"",
",",
"[",
"'id'",
"=>",
"$",
"model",
"->",
"id",
"]",
")",
",",
"'show'",
"=>",
"lmbRoute",
"(",
"\"admin.{$slug}.show\"",
",",
"[",
"'id'",
"=>",
"$",
"model",
"->",
"id",
"]",
")",
"]",
";",
"}"
] | get default urls for Datatables
@param \Illuminate\Database\Eloquent\Model $model
@return array | [
"get",
"default",
"urls",
"for",
"Datatables"
] | c26600543817642926bcf16ada84009e00d784e0 | https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Controllers/DataTableTrait.php#L99-L109 | train |
Eden-PHP/Block | Component/Pagination.php | Pagination.setShow | public function setShow($show)
{
Argument::i()->test(1, 'int');
if($show < 1) {
$show = 1;
}
$this->show = $show;
return $this;
} | php | public function setShow($show)
{
Argument::i()->test(1, 'int');
if($show < 1) {
$show = 1;
}
$this->show = $show;
return $this;
} | [
"public",
"function",
"setShow",
"(",
"$",
"show",
")",
"{",
"Argument",
"::",
"i",
"(",
")",
"->",
"test",
"(",
"1",
",",
"'int'",
")",
";",
"if",
"(",
"$",
"show",
"<",
"1",
")",
"{",
"$",
"show",
"=",
"1",
";",
"}",
"$",
"this",
"->",
"show",
"=",
"$",
"show",
";",
"return",
"$",
"this",
";",
"}"
] | Sets pages to show left and right of the current page
@param int
@return Eden\Block\Component\Pagination | [
"Sets",
"pages",
"to",
"show",
"left",
"and",
"right",
"of",
"the",
"current",
"page"
] | 681b9f01dd118612d0fced84d2f702167b52109b | https://github.com/Eden-PHP/Block/blob/681b9f01dd118612d0fced84d2f702167b52109b/Component/Pagination.php#L146-L156 | train |
Wedeto/DB | src/Query/ConstantArray.php | ConstantArray.toSQL | public function toSQL(Parameters $params, bool $inner_clause)
{
if ($key = $this->getKey())
{
try
{
$params->get($key);
}
catch (\OutOfRangeException $e)
{
// Not a valid key, replace
$key = null;
}
}
if (!$key)
$key = $params->assign(null);
// Rebind, to be sure
$this->bind($params, $key, array($params->getDriver(), 'formatArray'));
return ':' . $key;
} | php | public function toSQL(Parameters $params, bool $inner_clause)
{
if ($key = $this->getKey())
{
try
{
$params->get($key);
}
catch (\OutOfRangeException $e)
{
// Not a valid key, replace
$key = null;
}
}
if (!$key)
$key = $params->assign(null);
// Rebind, to be sure
$this->bind($params, $key, array($params->getDriver(), 'formatArray'));
return ':' . $key;
} | [
"public",
"function",
"toSQL",
"(",
"Parameters",
"$",
"params",
",",
"bool",
"$",
"inner_clause",
")",
"{",
"if",
"(",
"$",
"key",
"=",
"$",
"this",
"->",
"getKey",
"(",
")",
")",
"{",
"try",
"{",
"$",
"params",
"->",
"get",
"(",
"$",
"key",
")",
";",
"}",
"catch",
"(",
"\\",
"OutOfRangeException",
"$",
"e",
")",
"{",
"// Not a valid key, replace",
"$",
"key",
"=",
"null",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"key",
")",
"$",
"key",
"=",
"$",
"params",
"->",
"assign",
"(",
"null",
")",
";",
"// Rebind, to be sure",
"$",
"this",
"->",
"bind",
"(",
"$",
"params",
",",
"$",
"key",
",",
"array",
"(",
"$",
"params",
"->",
"getDriver",
"(",
")",
",",
"'formatArray'",
")",
")",
";",
"return",
"':'",
".",
"$",
"key",
";",
"}"
] | Write a constant array clause as SQL query syntax
@param Parameters $params The query parameters: tables and placeholder values
@return string The generated SQL | [
"Write",
"a",
"constant",
"array",
"clause",
"as",
"SQL",
"query",
"syntax"
] | 715f8f2e3ae6b53c511c40b620921cb9c87e6f62 | https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/Query/ConstantArray.php#L63-L84 | train |
sndsgd/form | src/form/field/FieldAbstract.php | FieldAbstract.getName | public function getName(array $keys = [], string $delimiter = "."): string
{
if (empty($keys)) {
return $this->name;
}
$keys[] = $this->name;
return implode($delimiter, $keys);
} | php | public function getName(array $keys = [], string $delimiter = "."): string
{
if (empty($keys)) {
return $this->name;
}
$keys[] = $this->name;
return implode($delimiter, $keys);
} | [
"public",
"function",
"getName",
"(",
"array",
"$",
"keys",
"=",
"[",
"]",
",",
"string",
"$",
"delimiter",
"=",
"\".\"",
")",
":",
"string",
"{",
"if",
"(",
"empty",
"(",
"$",
"keys",
")",
")",
"{",
"return",
"$",
"this",
"->",
"name",
";",
"}",
"$",
"keys",
"[",
"]",
"=",
"$",
"this",
"->",
"name",
";",
"return",
"implode",
"(",
"$",
"delimiter",
",",
"$",
"keys",
")",
";",
"}"
] | Get the name of the field
@param array<string> $keys The nested names of parents
@param string $delimiter A string to use when joining the name
@return string | [
"Get",
"the",
"name",
"of",
"the",
"field"
] | 56b5b9572a8942aea34c97c7c838b871e198e34f | https://github.com/sndsgd/form/blob/56b5b9572a8942aea34c97c7c838b871e198e34f/src/form/field/FieldAbstract.php#L67-L75 | train |
sndsgd/form | src/form/field/FieldAbstract.php | FieldAbstract.getNestedName | public function getNestedName(
string $delimiter = ".",
string $name = ""
): string
{
$keys = array_filter([$this->name, $name], "strlen");
$parent = $this;
while ($parent = $parent->getParent()) {
$name = $parent->getName();
if ($name) {
array_unshift($keys, $parent->getName());
}
}
return implode($delimiter, $keys);
} | php | public function getNestedName(
string $delimiter = ".",
string $name = ""
): string
{
$keys = array_filter([$this->name, $name], "strlen");
$parent = $this;
while ($parent = $parent->getParent()) {
$name = $parent->getName();
if ($name) {
array_unshift($keys, $parent->getName());
}
}
return implode($delimiter, $keys);
} | [
"public",
"function",
"getNestedName",
"(",
"string",
"$",
"delimiter",
"=",
"\".\"",
",",
"string",
"$",
"name",
"=",
"\"\"",
")",
":",
"string",
"{",
"$",
"keys",
"=",
"array_filter",
"(",
"[",
"$",
"this",
"->",
"name",
",",
"$",
"name",
"]",
",",
"\"strlen\"",
")",
";",
"$",
"parent",
"=",
"$",
"this",
";",
"while",
"(",
"$",
"parent",
"=",
"$",
"parent",
"->",
"getParent",
"(",
")",
")",
"{",
"$",
"name",
"=",
"$",
"parent",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"$",
"name",
")",
"{",
"array_unshift",
"(",
"$",
"keys",
",",
"$",
"parent",
"->",
"getName",
"(",
")",
")",
";",
"}",
"}",
"return",
"implode",
"(",
"$",
"delimiter",
",",
"$",
"keys",
")",
";",
"}"
] | Get a field's nested name
@param string $delimiter
@param string $name A name to append to the result
@return string | [
"Get",
"a",
"field",
"s",
"nested",
"name"
] | 56b5b9572a8942aea34c97c7c838b871e198e34f | https://github.com/sndsgd/form/blob/56b5b9572a8942aea34c97c7c838b871e198e34f/src/form/field/FieldAbstract.php#L84-L98 | train |
sokil/NotificationBundle | src/TransportProvider.php | TransportProvider.getTransport | public function getTransport($transportName)
{
if (empty($this->transport[$transportName])) {
throw new InvalidArgumentException(sprintf('Transport %s not found', $transportName));
}
return $this->transport[$transportName];
} | php | public function getTransport($transportName)
{
if (empty($this->transport[$transportName])) {
throw new InvalidArgumentException(sprintf('Transport %s not found', $transportName));
}
return $this->transport[$transportName];
} | [
"public",
"function",
"getTransport",
"(",
"$",
"transportName",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"transport",
"[",
"$",
"transportName",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Transport %s not found'",
",",
"$",
"transportName",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"transport",
"[",
"$",
"transportName",
"]",
";",
"}"
] | Get transport by name
@param $transportName
@return TransportInterface
@throws InvalidArgumentException | [
"Get",
"transport",
"by",
"name"
] | bf8d793b6b5a13827b2db4f0b3c588cf6a03c66b | https://github.com/sokil/NotificationBundle/blob/bf8d793b6b5a13827b2db4f0b3c588cf6a03c66b/src/TransportProvider.php#L35-L42 | train |
tonis-io-legacy/tonis | src/Router/RouteMap.php | RouteMap.add | public function add($path, $handler)
{
$route = new Route($path, $handler);
$this->routes[] = $route;
$this->nameCache = [];
$this->routeParser = new RouteParser;
return $route;
} | php | public function add($path, $handler)
{
$route = new Route($path, $handler);
$this->routes[] = $route;
$this->nameCache = [];
$this->routeParser = new RouteParser;
return $route;
} | [
"public",
"function",
"add",
"(",
"$",
"path",
",",
"$",
"handler",
")",
"{",
"$",
"route",
"=",
"new",
"Route",
"(",
"$",
"path",
",",
"$",
"handler",
")",
";",
"$",
"this",
"->",
"routes",
"[",
"]",
"=",
"$",
"route",
";",
"$",
"this",
"->",
"nameCache",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"routeParser",
"=",
"new",
"RouteParser",
";",
"return",
"$",
"route",
";",
"}"
] | Adds a route to the map and resets the name cache.
@param string $path
@param callable $handler
@return Route | [
"Adds",
"a",
"route",
"to",
"the",
"map",
"and",
"resets",
"the",
"name",
"cache",
"."
] | 8371a277a94232433d882aaf37a85cd469daf501 | https://github.com/tonis-io-legacy/tonis/blob/8371a277a94232433d882aaf37a85cd469daf501/src/Router/RouteMap.php#L25-L33 | train |
tonis-io-legacy/tonis | src/Router/RouteMap.php | RouteMap.buildNameCache | private function buildNameCache()
{
if (!empty($this->nameCache)) {
return;
}
foreach ($this as $route) {
if (!$route->name()) {
continue;
}
$this->nameCache[$route->name()] = $route;
}
} | php | private function buildNameCache()
{
if (!empty($this->nameCache)) {
return;
}
foreach ($this as $route) {
if (!$route->name()) {
continue;
}
$this->nameCache[$route->name()] = $route;
}
} | [
"private",
"function",
"buildNameCache",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"nameCache",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"this",
"as",
"$",
"route",
")",
"{",
"if",
"(",
"!",
"$",
"route",
"->",
"name",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"nameCache",
"[",
"$",
"route",
"->",
"name",
"(",
")",
"]",
"=",
"$",
"route",
";",
"}",
"}"
] | Iterates through routes and builds a name cache. | [
"Iterates",
"through",
"routes",
"and",
"builds",
"a",
"name",
"cache",
"."
] | 8371a277a94232433d882aaf37a85cd469daf501 | https://github.com/tonis-io-legacy/tonis/blob/8371a277a94232433d882aaf37a85cd469daf501/src/Router/RouteMap.php#L110-L121 | train |
PenoaksDev/Milky-Framework | src/Milky/Http/JsonResponse.php | JsonResponse.setJsonOptions | public function setJsonOptions($options)
{
$this->encodingOptions = (int) $options;
return $this->setData($this->getData());
} | php | public function setJsonOptions($options)
{
$this->encodingOptions = (int) $options;
return $this->setData($this->getData());
} | [
"public",
"function",
"setJsonOptions",
"(",
"$",
"options",
")",
"{",
"$",
"this",
"->",
"encodingOptions",
"=",
"(",
"int",
")",
"$",
"options",
";",
"return",
"$",
"this",
"->",
"setData",
"(",
"$",
"this",
"->",
"getData",
"(",
")",
")",
";",
"}"
] | Set the JSON encoding options.
@param int $options
@return mixed | [
"Set",
"the",
"JSON",
"encoding",
"options",
"."
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Http/JsonResponse.php#L86-L91 | train |
RhubarbPHP/Scaffold.BackgroundTasks | src/Task.php | Task.initiate | public static function initiate($settings)
{
// Create an entry in our database.
$taskStatus = new BackgroundTaskStatus();
$taskStatus->TaskClass = get_called_class();
$taskStatus->TaskSettings = $settings;
$taskStatus->save();
$task = new static();
$additionalArguments = $task->getShellArguments();
$additionalArgumentString = "";
foreach ($additionalArguments as $argument) {
$additionalArgumentString .= escapeshellarg($argument);
}
if (BackgroundTasksModule::$debugServerName) {
// This setting can be used to make command line tasks use a named configuration
// in your IDE - this matches up to the PHP Server name in PhpStorm, found in
// Settings -> Languages and Frameworks -> PHP -> Servers -> Name
$command = 'PHP_IDE_CONFIG=' . escapeshellarg('serverName=' . BackgroundTasksModule::$debugServerName) . ' ';
} else {
$command = '';
}
$runningRhubarbAppClass = escapeshellarg(get_class(Application::current()));
$command .= "rhubarb_app=$runningRhubarbAppClass /usr/bin/env php " . realpath(VENDOR_DIR . "/rhubarbphp/rhubarb/platform/execute-cli.php") . " " .
realpath(__DIR__ . "/Scripts/task-runner.php") . " " . escapeshellarg(get_called_class()) . " " . $taskStatus->BackgroundTaskStatusID . " " . $additionalArgumentString . " > /dev/null 2>&1 &";
Log::debug("Launching background task " . $taskStatus->UniqueIdentifier, "BACKGROUND", $command);
exec($command);
return $taskStatus;
} | php | public static function initiate($settings)
{
// Create an entry in our database.
$taskStatus = new BackgroundTaskStatus();
$taskStatus->TaskClass = get_called_class();
$taskStatus->TaskSettings = $settings;
$taskStatus->save();
$task = new static();
$additionalArguments = $task->getShellArguments();
$additionalArgumentString = "";
foreach ($additionalArguments as $argument) {
$additionalArgumentString .= escapeshellarg($argument);
}
if (BackgroundTasksModule::$debugServerName) {
// This setting can be used to make command line tasks use a named configuration
// in your IDE - this matches up to the PHP Server name in PhpStorm, found in
// Settings -> Languages and Frameworks -> PHP -> Servers -> Name
$command = 'PHP_IDE_CONFIG=' . escapeshellarg('serverName=' . BackgroundTasksModule::$debugServerName) . ' ';
} else {
$command = '';
}
$runningRhubarbAppClass = escapeshellarg(get_class(Application::current()));
$command .= "rhubarb_app=$runningRhubarbAppClass /usr/bin/env php " . realpath(VENDOR_DIR . "/rhubarbphp/rhubarb/platform/execute-cli.php") . " " .
realpath(__DIR__ . "/Scripts/task-runner.php") . " " . escapeshellarg(get_called_class()) . " " . $taskStatus->BackgroundTaskStatusID . " " . $additionalArgumentString . " > /dev/null 2>&1 &";
Log::debug("Launching background task " . $taskStatus->UniqueIdentifier, "BACKGROUND", $command);
exec($command);
return $taskStatus;
} | [
"public",
"static",
"function",
"initiate",
"(",
"$",
"settings",
")",
"{",
"// Create an entry in our database.",
"$",
"taskStatus",
"=",
"new",
"BackgroundTaskStatus",
"(",
")",
";",
"$",
"taskStatus",
"->",
"TaskClass",
"=",
"get_called_class",
"(",
")",
";",
"$",
"taskStatus",
"->",
"TaskSettings",
"=",
"$",
"settings",
";",
"$",
"taskStatus",
"->",
"save",
"(",
")",
";",
"$",
"task",
"=",
"new",
"static",
"(",
")",
";",
"$",
"additionalArguments",
"=",
"$",
"task",
"->",
"getShellArguments",
"(",
")",
";",
"$",
"additionalArgumentString",
"=",
"\"\"",
";",
"foreach",
"(",
"$",
"additionalArguments",
"as",
"$",
"argument",
")",
"{",
"$",
"additionalArgumentString",
".=",
"escapeshellarg",
"(",
"$",
"argument",
")",
";",
"}",
"if",
"(",
"BackgroundTasksModule",
"::",
"$",
"debugServerName",
")",
"{",
"// This setting can be used to make command line tasks use a named configuration",
"// in your IDE - this matches up to the PHP Server name in PhpStorm, found in",
"// Settings -> Languages and Frameworks -> PHP -> Servers -> Name",
"$",
"command",
"=",
"'PHP_IDE_CONFIG='",
".",
"escapeshellarg",
"(",
"'serverName='",
".",
"BackgroundTasksModule",
"::",
"$",
"debugServerName",
")",
".",
"' '",
";",
"}",
"else",
"{",
"$",
"command",
"=",
"''",
";",
"}",
"$",
"runningRhubarbAppClass",
"=",
"escapeshellarg",
"(",
"get_class",
"(",
"Application",
"::",
"current",
"(",
")",
")",
")",
";",
"$",
"command",
".=",
"\"rhubarb_app=$runningRhubarbAppClass /usr/bin/env php \"",
".",
"realpath",
"(",
"VENDOR_DIR",
".",
"\"/rhubarbphp/rhubarb/platform/execute-cli.php\"",
")",
".",
"\" \"",
".",
"realpath",
"(",
"__DIR__",
".",
"\"/Scripts/task-runner.php\"",
")",
".",
"\" \"",
".",
"escapeshellarg",
"(",
"get_called_class",
"(",
")",
")",
".",
"\" \"",
".",
"$",
"taskStatus",
"->",
"BackgroundTaskStatusID",
".",
"\" \"",
".",
"$",
"additionalArgumentString",
".",
"\" > /dev/null 2>&1 &\"",
";",
"Log",
"::",
"debug",
"(",
"\"Launching background task \"",
".",
"$",
"taskStatus",
"->",
"UniqueIdentifier",
",",
"\"BACKGROUND\"",
",",
"$",
"command",
")",
";",
"exec",
"(",
"$",
"command",
")",
";",
"return",
"$",
"taskStatus",
";",
"}"
] | Initiates execution of the background task.
@param array $settings Settings which will be passed to the execute method of the BackgroundTask (must be JSON serialisable)
@return BackgroundTaskStatus The status object for this task. | [
"Initiates",
"execution",
"of",
"the",
"background",
"task",
"."
] | 92a5feab27599288e8bf39deb522588115838904 | https://github.com/RhubarbPHP/Scaffold.BackgroundTasks/blob/92a5feab27599288e8bf39deb522588115838904/src/Task.php#L71-L107 | train |
heiglandreas/OrgHeiglFileFinder | src/ClassMapList.php | ClassMapList.add | public function add(\SplFileInfo $file)
{
$content = new \Org_Heigl\FileFinder\Service\Tokenlist(file_get_contents($file->getPathname()));
$classname = $content->getClassName();
if (! $classname) {
return;
}
$class = $content->getNamespace();
$class[] = $classname;
$key = str_replace('\\\\', '\\', '\\' . implode('\\', $class));
$this->list[$key] = realpath($file->getPathname());
} | php | public function add(\SplFileInfo $file)
{
$content = new \Org_Heigl\FileFinder\Service\Tokenlist(file_get_contents($file->getPathname()));
$classname = $content->getClassName();
if (! $classname) {
return;
}
$class = $content->getNamespace();
$class[] = $classname;
$key = str_replace('\\\\', '\\', '\\' . implode('\\', $class));
$this->list[$key] = realpath($file->getPathname());
} | [
"public",
"function",
"add",
"(",
"\\",
"SplFileInfo",
"$",
"file",
")",
"{",
"$",
"content",
"=",
"new",
"\\",
"Org_Heigl",
"\\",
"FileFinder",
"\\",
"Service",
"\\",
"Tokenlist",
"(",
"file_get_contents",
"(",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
")",
";",
"$",
"classname",
"=",
"$",
"content",
"->",
"getClassName",
"(",
")",
";",
"if",
"(",
"!",
"$",
"classname",
")",
"{",
"return",
";",
"}",
"$",
"class",
"=",
"$",
"content",
"->",
"getNamespace",
"(",
")",
";",
"$",
"class",
"[",
"]",
"=",
"$",
"classname",
";",
"$",
"key",
"=",
"str_replace",
"(",
"'\\\\\\\\'",
",",
"'\\\\'",
",",
"'\\\\'",
".",
"implode",
"(",
"'\\\\'",
",",
"$",
"class",
")",
")",
";",
"$",
"this",
"->",
"list",
"[",
"$",
"key",
"]",
"=",
"realpath",
"(",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
";",
"}"
] | Add an SPL-File-Info to the filelist
@param \SplFileInfo $file
@return void | [
"Add",
"an",
"SPL",
"-",
"File",
"-",
"Info",
"to",
"the",
"filelist"
] | 189d15b95bec7dc186ef73681463c104831234d8 | https://github.com/heiglandreas/OrgHeiglFileFinder/blob/189d15b95bec7dc186ef73681463c104831234d8/src/ClassMapList.php#L48-L62 | train |
ComPHPPuebla/restful-extensions | src/ComPHPPuebla/Slim/Middleware/CheckOptionsMiddleware.php | CheckOptionsMiddleware.call | public function call()
{
$params = $this->app->router()->getCurrentRoute()->getParams();
$options = $this->model->getOptionsList();
if (isset($params['id'])) {
$options = $this->model->getOptions();
}
if (in_array($this->app->request()->getMethod(), $options)) {
$this->next->call();
return;
}
$this->app->response()->setStatus(405); // Method Not Allowed
} | php | public function call()
{
$params = $this->app->router()->getCurrentRoute()->getParams();
$options = $this->model->getOptionsList();
if (isset($params['id'])) {
$options = $this->model->getOptions();
}
if (in_array($this->app->request()->getMethod(), $options)) {
$this->next->call();
return;
}
$this->app->response()->setStatus(405); // Method Not Allowed
} | [
"public",
"function",
"call",
"(",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"app",
"->",
"router",
"(",
")",
"->",
"getCurrentRoute",
"(",
")",
"->",
"getParams",
"(",
")",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"model",
"->",
"getOptionsList",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"model",
"->",
"getOptions",
"(",
")",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"app",
"->",
"request",
"(",
")",
"->",
"getMethod",
"(",
")",
",",
"$",
"options",
")",
")",
"{",
"$",
"this",
"->",
"next",
"->",
"call",
"(",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"app",
"->",
"response",
"(",
")",
"->",
"setStatus",
"(",
"405",
")",
";",
"// Method Not Allowed",
"}"
] | Check if the current HTTP method is allowed for the resource being accesed
@see \Slim\Middleware::call() | [
"Check",
"if",
"the",
"current",
"HTTP",
"method",
"is",
"allowed",
"for",
"the",
"resource",
"being",
"accesed"
] | 3dc5e554d7ebe1305eed4cd4ec71a6944316199c | https://github.com/ComPHPPuebla/restful-extensions/blob/3dc5e554d7ebe1305eed4cd4ec71a6944316199c/src/ComPHPPuebla/Slim/Middleware/CheckOptionsMiddleware.php#L27-L43 | train |
Nicklas766/Comment | src/Comment/Modules/ActiveRecordModelExtender.php | ActiveRecordModelExtender.getMD | public function getMD($content)
{
$funcArr = ["yamlfrontmatter", "shortcode", "markdown", "titlefromheader"];
$textFilter = new textFilter();
return $textFilter->parse($content, $funcArr)->text;
} | php | public function getMD($content)
{
$funcArr = ["yamlfrontmatter", "shortcode", "markdown", "titlefromheader"];
$textFilter = new textFilter();
return $textFilter->parse($content, $funcArr)->text;
} | [
"public",
"function",
"getMD",
"(",
"$",
"content",
")",
"{",
"$",
"funcArr",
"=",
"[",
"\"yamlfrontmatter\"",
",",
"\"shortcode\"",
",",
"\"markdown\"",
",",
"\"titlefromheader\"",
"]",
";",
"$",
"textFilter",
"=",
"new",
"textFilter",
"(",
")",
";",
"return",
"$",
"textFilter",
"->",
"parse",
"(",
"$",
"content",
",",
"$",
"funcArr",
")",
"->",
"text",
";",
"}"
] | Return markdown based on string
@param string $content unparsed markdown
@return string as parsed markdown | [
"Return",
"markdown",
"based",
"on",
"string"
] | 1483eaf1ebb120b8bd6c2a1552c084b3a288ff25 | https://github.com/Nicklas766/Comment/blob/1483eaf1ebb120b8bd6c2a1552c084b3a288ff25/src/Comment/Modules/ActiveRecordModelExtender.php#L42-L47 | train |
the-eater/odango.php | src/NyaaCollector.php | NyaaCollector.getFeed | protected function getFeed($query, $options)
{
$options = array_merge(['query' => $query], $options);
$nyaa = $this->getNyaa();
$feed = $nyaa->getFeed($options);
$matcher = $this->getMatcher();
return array_filter($feed, function ($item) use ($matcher, $query) {
$title = $item->getMeta('title');
return $title !== null && $matcher($title, $query);
});
} | php | protected function getFeed($query, $options)
{
$options = array_merge(['query' => $query], $options);
$nyaa = $this->getNyaa();
$feed = $nyaa->getFeed($options);
$matcher = $this->getMatcher();
return array_filter($feed, function ($item) use ($matcher, $query) {
$title = $item->getMeta('title');
return $title !== null && $matcher($title, $query);
});
} | [
"protected",
"function",
"getFeed",
"(",
"$",
"query",
",",
"$",
"options",
")",
"{",
"$",
"options",
"=",
"array_merge",
"(",
"[",
"'query'",
"=>",
"$",
"query",
"]",
",",
"$",
"options",
")",
";",
"$",
"nyaa",
"=",
"$",
"this",
"->",
"getNyaa",
"(",
")",
";",
"$",
"feed",
"=",
"$",
"nyaa",
"->",
"getFeed",
"(",
"$",
"options",
")",
";",
"$",
"matcher",
"=",
"$",
"this",
"->",
"getMatcher",
"(",
")",
";",
"return",
"array_filter",
"(",
"$",
"feed",
",",
"function",
"(",
"$",
"item",
")",
"use",
"(",
"$",
"matcher",
",",
"$",
"query",
")",
"{",
"$",
"title",
"=",
"$",
"item",
"->",
"getMeta",
"(",
"'title'",
")",
";",
"return",
"$",
"title",
"!==",
"null",
"&&",
"$",
"matcher",
"(",
"$",
"title",
",",
"$",
"query",
")",
";",
"}",
")",
";",
"}"
] | Gets the torrent feed for given query and options
@param string $query Query to search for in the nyaa feed
@param array $options Options for the nyaa feed
@return NyaaTorrent[] | [
"Gets",
"the",
"torrent",
"feed",
"for",
"given",
"query",
"and",
"options"
] | 6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f | https://github.com/the-eater/odango.php/blob/6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f/src/NyaaCollector.php#L63-L75 | train |
the-eater/odango.php | src/NyaaCollector.php | NyaaCollector.filterDuplicates | public function filterDuplicates($torrents)
{
$arr = [];
foreach ($torrents as $torrent) {
$arr[$torrent->getTorrentId()] = $torrent;
}
return array_values($arr);
} | php | public function filterDuplicates($torrents)
{
$arr = [];
foreach ($torrents as $torrent) {
$arr[$torrent->getTorrentId()] = $torrent;
}
return array_values($arr);
} | [
"public",
"function",
"filterDuplicates",
"(",
"$",
"torrents",
")",
"{",
"$",
"arr",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"torrents",
"as",
"$",
"torrent",
")",
"{",
"$",
"arr",
"[",
"$",
"torrent",
"->",
"getTorrentId",
"(",
")",
"]",
"=",
"$",
"torrent",
";",
"}",
"return",
"array_values",
"(",
"$",
"arr",
")",
";",
"}"
] | Return list with unique torrents from given array
@param NyaaTorrent[] The list to filter duplicates out
@param NyaaTorrent[] | [
"Return",
"list",
"with",
"unique",
"torrents",
"from",
"given",
"array"
] | 6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f | https://github.com/the-eater/odango.php/blob/6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f/src/NyaaCollector.php#L83-L92 | train |
the-eater/odango.php | src/NyaaCollector.php | NyaaCollector.mapByHash | public function mapByHash($feed)
{
$torrents = [];
foreach ($feed as $torrent) {
$hash = $torrent->getSeriesHash();
if(!isset($torrents[$hash])) {
$torrents[$hash] = new NyaaSet($hash);
}
$torrents[$hash]->add($torrent);
}
return $torrents;
} | php | public function mapByHash($feed)
{
$torrents = [];
foreach ($feed as $torrent) {
$hash = $torrent->getSeriesHash();
if(!isset($torrents[$hash])) {
$torrents[$hash] = new NyaaSet($hash);
}
$torrents[$hash]->add($torrent);
}
return $torrents;
} | [
"public",
"function",
"mapByHash",
"(",
"$",
"feed",
")",
"{",
"$",
"torrents",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"feed",
"as",
"$",
"torrent",
")",
"{",
"$",
"hash",
"=",
"$",
"torrent",
"->",
"getSeriesHash",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"torrents",
"[",
"$",
"hash",
"]",
")",
")",
"{",
"$",
"torrents",
"[",
"$",
"hash",
"]",
"=",
"new",
"NyaaSet",
"(",
"$",
"hash",
")",
";",
"}",
"$",
"torrents",
"[",
"$",
"hash",
"]",
"->",
"add",
"(",
"$",
"torrent",
")",
";",
"}",
"return",
"$",
"torrents",
";",
"}"
] | Maps the torrents by series hash and collects them in a NyaaSet
@param NyaaTorrent[] list of torrents to be mapped
@param NyaaSet[] | [
"Maps",
"the",
"torrents",
"by",
"series",
"hash",
"and",
"collects",
"them",
"in",
"a",
"NyaaSet"
] | 6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f | https://github.com/the-eater/odango.php/blob/6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f/src/NyaaCollector.php#L100-L115 | train |
the-eater/odango.php | src/NyaaCollector.php | NyaaCollector.collectForUser | public function collectForUser($query, $users, $options = [])
{
$bigFeed = [];
foreach ($users as $userId) {
$userOptions = array_merge($options, ['user' => $userId]);
$userFeed = $this->getFeed($query, $userOptions);
$bigFeed = array_merge($bigFeed, $userFeed);
}
$bigFeed = $this->filterDuplicates($bigFeed);
return $this->mapByHash($bigFeed);
} | php | public function collectForUser($query, $users, $options = [])
{
$bigFeed = [];
foreach ($users as $userId) {
$userOptions = array_merge($options, ['user' => $userId]);
$userFeed = $this->getFeed($query, $userOptions);
$bigFeed = array_merge($bigFeed, $userFeed);
}
$bigFeed = $this->filterDuplicates($bigFeed);
return $this->mapByHash($bigFeed);
} | [
"public",
"function",
"collectForUser",
"(",
"$",
"query",
",",
"$",
"users",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"bigFeed",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"users",
"as",
"$",
"userId",
")",
"{",
"$",
"userOptions",
"=",
"array_merge",
"(",
"$",
"options",
",",
"[",
"'user'",
"=>",
"$",
"userId",
"]",
")",
";",
"$",
"userFeed",
"=",
"$",
"this",
"->",
"getFeed",
"(",
"$",
"query",
",",
"$",
"userOptions",
")",
";",
"$",
"bigFeed",
"=",
"array_merge",
"(",
"$",
"bigFeed",
",",
"$",
"userFeed",
")",
";",
"}",
"$",
"bigFeed",
"=",
"$",
"this",
"->",
"filterDuplicates",
"(",
"$",
"bigFeed",
")",
";",
"return",
"$",
"this",
"->",
"mapByHash",
"(",
"$",
"bigFeed",
")",
";",
"}"
] | Searches for torrents per user
@param string $query The query to search for
@param int[] $users The users to search in
@param array $options extra options for the nyaa feed
@return NyaaSet[] | [
"Searches",
"for",
"torrents",
"per",
"user"
] | 6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f | https://github.com/the-eater/odango.php/blob/6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f/src/NyaaCollector.php#L125-L138 | train |
the-eater/odango.php | src/NyaaCollector.php | NyaaCollector.collectRecursive | public function collectRecursive($query, $options = [])
{
$feed = $this->getFeed($query, $options);
$userIds = [];
foreach ($feed as $torrent) {
if (!isset($userIds[$torrent->getSeriesHash()])) {
$userIds[$torrent->getSeriesHash()] = $torrent->getUserId();
}
}
$userIds = array_unique(array_values($userIds));
return $this->collectForUser($query, $userIds, $options);
} | php | public function collectRecursive($query, $options = [])
{
$feed = $this->getFeed($query, $options);
$userIds = [];
foreach ($feed as $torrent) {
if (!isset($userIds[$torrent->getSeriesHash()])) {
$userIds[$torrent->getSeriesHash()] = $torrent->getUserId();
}
}
$userIds = array_unique(array_values($userIds));
return $this->collectForUser($query, $userIds, $options);
} | [
"public",
"function",
"collectRecursive",
"(",
"$",
"query",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"feed",
"=",
"$",
"this",
"->",
"getFeed",
"(",
"$",
"query",
",",
"$",
"options",
")",
";",
"$",
"userIds",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"feed",
"as",
"$",
"torrent",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"userIds",
"[",
"$",
"torrent",
"->",
"getSeriesHash",
"(",
")",
"]",
")",
")",
"{",
"$",
"userIds",
"[",
"$",
"torrent",
"->",
"getSeriesHash",
"(",
")",
"]",
"=",
"$",
"torrent",
"->",
"getUserId",
"(",
")",
";",
"}",
"}",
"$",
"userIds",
"=",
"array_unique",
"(",
"array_values",
"(",
"$",
"userIds",
")",
")",
";",
"return",
"$",
"this",
"->",
"collectForUser",
"(",
"$",
"query",
",",
"$",
"userIds",
",",
"$",
"options",
")",
";",
"}"
] | Searches for torrent and searches for each found torrent in their user for more torrents, to create complete sets
@param string $query The query to search for
@param array $options Extra options for the nyaa feed
@return NyaaSet[] | [
"Searches",
"for",
"torrent",
"and",
"searches",
"for",
"each",
"found",
"torrent",
"in",
"their",
"user",
"for",
"more",
"torrents",
"to",
"create",
"complete",
"sets"
] | 6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f | https://github.com/the-eater/odango.php/blob/6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f/src/NyaaCollector.php#L147-L162 | train |
the-eater/odango.php | src/NyaaCollector.php | NyaaCollector.collect | public function collect($query, $options = [])
{
if (!$this->getNyaa()->canProvideAllData()) {
return $this->collectRecursive($query, $options);
}
return $this->collectSingleFeed($query, $options);
} | php | public function collect($query, $options = [])
{
if (!$this->getNyaa()->canProvideAllData()) {
return $this->collectRecursive($query, $options);
}
return $this->collectSingleFeed($query, $options);
} | [
"public",
"function",
"collect",
"(",
"$",
"query",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getNyaa",
"(",
")",
"->",
"canProvideAllData",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"collectRecursive",
"(",
"$",
"query",
",",
"$",
"options",
")",
";",
"}",
"return",
"$",
"this",
"->",
"collectSingleFeed",
"(",
"$",
"query",
",",
"$",
"options",
")",
";",
"}"
] | Searches for torrents by query and returns sets created from it
Collects recursively if backend doesn't provide all data
@param string $query The query to search for
@param array $options Extra options for the nyaa feed | [
"Searches",
"for",
"torrents",
"by",
"query",
"and",
"returns",
"sets",
"created",
"from",
"it",
"Collects",
"recursively",
"if",
"backend",
"doesn",
"t",
"provide",
"all",
"data"
] | 6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f | https://github.com/the-eater/odango.php/blob/6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f/src/NyaaCollector.php#L171-L179 | train |
the-eater/odango.php | src/NyaaCollector.php | NyaaCollector.collectSingleFeed | public function collectSingleFeed($query, $options = [])
{
$feed = $this->getFeed($query, $options);
return $this->mapByHash($feed);
} | php | public function collectSingleFeed($query, $options = [])
{
$feed = $this->getFeed($query, $options);
return $this->mapByHash($feed);
} | [
"public",
"function",
"collectSingleFeed",
"(",
"$",
"query",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"feed",
"=",
"$",
"this",
"->",
"getFeed",
"(",
"$",
"query",
",",
"$",
"options",
")",
";",
"return",
"$",
"this",
"->",
"mapByHash",
"(",
"$",
"feed",
")",
";",
"}"
] | Searches for torrents by query and returns sets created from it, only fetches one feed.
@param string $query
@param array $options | [
"Searches",
"for",
"torrents",
"by",
"query",
"and",
"returns",
"sets",
"created",
"from",
"it",
"only",
"fetches",
"one",
"feed",
"."
] | 6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f | https://github.com/the-eater/odango.php/blob/6c78f983e7b3c49ff2f8a10ce7299747d3c82e3f/src/NyaaCollector.php#L187-L192 | train |
praxigento/mobi_mod_downline | Block/Customer/Account/Reflink.php | Reflink.getDwnlCustomer | private function getDwnlCustomer()
{
if (is_null($this->cacheDwnlCust)) {
$custId = $this->session->getCustomerId();
$this->cacheDwnlCust = $this->daoDwnlCust->getById($custId);
}
return $this->cacheDwnlCust;
} | php | private function getDwnlCustomer()
{
if (is_null($this->cacheDwnlCust)) {
$custId = $this->session->getCustomerId();
$this->cacheDwnlCust = $this->daoDwnlCust->getById($custId);
}
return $this->cacheDwnlCust;
} | [
"private",
"function",
"getDwnlCustomer",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"cacheDwnlCust",
")",
")",
"{",
"$",
"custId",
"=",
"$",
"this",
"->",
"session",
"->",
"getCustomerId",
"(",
")",
";",
"$",
"this",
"->",
"cacheDwnlCust",
"=",
"$",
"this",
"->",
"daoDwnlCust",
"->",
"getById",
"(",
"$",
"custId",
")",
";",
"}",
"return",
"$",
"this",
"->",
"cacheDwnlCust",
";",
"}"
] | Cached data for current downline customer.
@return \Praxigento\Downline\Repo\Data\Customer | [
"Cached",
"data",
"for",
"current",
"downline",
"customer",
"."
] | 0f3c276dfff1aa029f9fd205ccfc56f207a2e75b | https://github.com/praxigento/mobi_mod_downline/blob/0f3c276dfff1aa029f9fd205ccfc56f207a2e75b/Block/Customer/Account/Reflink.php#L44-L51 | train |
LIN3S/CMSKernel | src/LIN3S/CMSKernel/Infrastructure/Lin3sAdminBundle/Twig/TwigActionTranslationFilter.php | TwigActionTranslationFilter.actionTranslation | public function actionTranslation($options)
{
if (!is_array($options)) {
return $this->translator->trans($options, [], 'CmsKernelAdminBridge');
}
$resultOptions = [];
foreach ($options as $optionKey => $option) {
$option = null === json_decode($option, true) ? $option : json_decode($option, true);
if (is_array($option)) {
foreach ($option as $iterationKey => $iteration) {
if (is_array($iteration)) {
foreach ($iteration as $iKey => $i) {
if (is_array($i)) {
foreach ($i as $iiKey => $ii) {
$resultOptions[$optionKey][$iterationKey][$iKey][$iiKey] = $this->translator->trans($ii, [], 'CmsKernelAdminBridge');
}
} else {
$resultOptions[$optionKey][$iterationKey][$iKey] = $this->translator->trans($i, [], 'CmsKernelAdminBridge');
}
}
} else {
$resultOptions[$optionKey][$iterationKey] = $this->translator->trans($iteration, [], 'CmsKernelAdminBridge');
}
}
} else {
$resultOptions[$optionKey] = $this->translator->trans($option, [], 'CmsKernelAdminBridge');
}
}
return $resultOptions;
} | php | public function actionTranslation($options)
{
if (!is_array($options)) {
return $this->translator->trans($options, [], 'CmsKernelAdminBridge');
}
$resultOptions = [];
foreach ($options as $optionKey => $option) {
$option = null === json_decode($option, true) ? $option : json_decode($option, true);
if (is_array($option)) {
foreach ($option as $iterationKey => $iteration) {
if (is_array($iteration)) {
foreach ($iteration as $iKey => $i) {
if (is_array($i)) {
foreach ($i as $iiKey => $ii) {
$resultOptions[$optionKey][$iterationKey][$iKey][$iiKey] = $this->translator->trans($ii, [], 'CmsKernelAdminBridge');
}
} else {
$resultOptions[$optionKey][$iterationKey][$iKey] = $this->translator->trans($i, [], 'CmsKernelAdminBridge');
}
}
} else {
$resultOptions[$optionKey][$iterationKey] = $this->translator->trans($iteration, [], 'CmsKernelAdminBridge');
}
}
} else {
$resultOptions[$optionKey] = $this->translator->trans($option, [], 'CmsKernelAdminBridge');
}
}
return $resultOptions;
} | [
"public",
"function",
"actionTranslation",
"(",
"$",
"options",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"options",
")",
")",
"{",
"return",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"$",
"options",
",",
"[",
"]",
",",
"'CmsKernelAdminBridge'",
")",
";",
"}",
"$",
"resultOptions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"optionKey",
"=>",
"$",
"option",
")",
"{",
"$",
"option",
"=",
"null",
"===",
"json_decode",
"(",
"$",
"option",
",",
"true",
")",
"?",
"$",
"option",
":",
"json_decode",
"(",
"$",
"option",
",",
"true",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"option",
")",
")",
"{",
"foreach",
"(",
"$",
"option",
"as",
"$",
"iterationKey",
"=>",
"$",
"iteration",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"iteration",
")",
")",
"{",
"foreach",
"(",
"$",
"iteration",
"as",
"$",
"iKey",
"=>",
"$",
"i",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"i",
")",
")",
"{",
"foreach",
"(",
"$",
"i",
"as",
"$",
"iiKey",
"=>",
"$",
"ii",
")",
"{",
"$",
"resultOptions",
"[",
"$",
"optionKey",
"]",
"[",
"$",
"iterationKey",
"]",
"[",
"$",
"iKey",
"]",
"[",
"$",
"iiKey",
"]",
"=",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"$",
"ii",
",",
"[",
"]",
",",
"'CmsKernelAdminBridge'",
")",
";",
"}",
"}",
"else",
"{",
"$",
"resultOptions",
"[",
"$",
"optionKey",
"]",
"[",
"$",
"iterationKey",
"]",
"[",
"$",
"iKey",
"]",
"=",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"$",
"i",
",",
"[",
"]",
",",
"'CmsKernelAdminBridge'",
")",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"resultOptions",
"[",
"$",
"optionKey",
"]",
"[",
"$",
"iterationKey",
"]",
"=",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"$",
"iteration",
",",
"[",
"]",
",",
"'CmsKernelAdminBridge'",
")",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"resultOptions",
"[",
"$",
"optionKey",
"]",
"=",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"$",
"option",
",",
"[",
"]",
",",
"'CmsKernelAdminBridge'",
")",
";",
"}",
"}",
"return",
"$",
"resultOptions",
";",
"}"
] | Callback of action translation Twig filter that returns resultant array.
@param string $options The action options
@return array|string | [
"Callback",
"of",
"action",
"translation",
"Twig",
"filter",
"that",
"returns",
"resultant",
"array",
"."
] | 71b5fc1930cd60d6eac1a9816df34af4654f9a7e | https://github.com/LIN3S/CMSKernel/blob/71b5fc1930cd60d6eac1a9816df34af4654f9a7e/src/LIN3S/CMSKernel/Infrastructure/Lin3sAdminBundle/Twig/TwigActionTranslationFilter.php#L57-L89 | train |
K-Phoen/rulerz-bridge | Form/SpecificationToBooleanTransformer.php | SpecificationToBooleanTransformer.reverseTransform | public function reverseTransform($boolean)
{
if (!$boolean) {
return null;
}
$rClass = new \ReflectionClass($this->specificationClass);
if ($rClass->getConstructor() && $rClass->getConstructor()->getNumberOfParameters() > 0) {
return $rClass->newInstanceArgs($this->constructorArgs);
}
return $rClass->newInstance();
} | php | public function reverseTransform($boolean)
{
if (!$boolean) {
return null;
}
$rClass = new \ReflectionClass($this->specificationClass);
if ($rClass->getConstructor() && $rClass->getConstructor()->getNumberOfParameters() > 0) {
return $rClass->newInstanceArgs($this->constructorArgs);
}
return $rClass->newInstance();
} | [
"public",
"function",
"reverseTransform",
"(",
"$",
"boolean",
")",
"{",
"if",
"(",
"!",
"$",
"boolean",
")",
"{",
"return",
"null",
";",
"}",
"$",
"rClass",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"this",
"->",
"specificationClass",
")",
";",
"if",
"(",
"$",
"rClass",
"->",
"getConstructor",
"(",
")",
"&&",
"$",
"rClass",
"->",
"getConstructor",
"(",
")",
"->",
"getNumberOfParameters",
"(",
")",
">",
"0",
")",
"{",
"return",
"$",
"rClass",
"->",
"newInstanceArgs",
"(",
"$",
"this",
"->",
"constructorArgs",
")",
";",
"}",
"return",
"$",
"rClass",
"->",
"newInstance",
"(",
")",
";",
"}"
] | Transforms a value into a specification.
@param bool $boolean
@return \RulerZ\Spec\Specification|null | [
"Transforms",
"a",
"value",
"into",
"a",
"specification",
"."
] | fdad5856b669d59b5e4bda47c4e927a0485bf7a0 | https://github.com/K-Phoen/rulerz-bridge/blob/fdad5856b669d59b5e4bda47c4e927a0485bf7a0/Form/SpecificationToBooleanTransformer.php#L48-L61 | train |
schpill/thin | src/Request.php | Request.detectEnv | public static function detectEnv(array $environments, $uri)
{
foreach ($environments as $environment => $patterns) {
// Essentially we just want to loop through each environment pattern
// and determine if the current URI matches the pattern and if so
// we will simply return the environment for that URI pattern.
foreach ($patterns as $pattern) {
if (Inflector::is($pattern, $uri) or $pattern == gethostname()) {
return $environment;
}
}
}
} | php | public static function detectEnv(array $environments, $uri)
{
foreach ($environments as $environment => $patterns) {
// Essentially we just want to loop through each environment pattern
// and determine if the current URI matches the pattern and if so
// we will simply return the environment for that URI pattern.
foreach ($patterns as $pattern) {
if (Inflector::is($pattern, $uri) or $pattern == gethostname()) {
return $environment;
}
}
}
} | [
"public",
"static",
"function",
"detectEnv",
"(",
"array",
"$",
"environments",
",",
"$",
"uri",
")",
"{",
"foreach",
"(",
"$",
"environments",
"as",
"$",
"environment",
"=>",
"$",
"patterns",
")",
"{",
"// Essentially we just want to loop through each environment pattern",
"// and determine if the current URI matches the pattern and if so",
"// we will simply return the environment for that URI pattern.",
"foreach",
"(",
"$",
"patterns",
"as",
"$",
"pattern",
")",
"{",
"if",
"(",
"Inflector",
"::",
"is",
"(",
"$",
"pattern",
",",
"$",
"uri",
")",
"or",
"$",
"pattern",
"==",
"gethostname",
"(",
")",
")",
"{",
"return",
"$",
"environment",
";",
"}",
"}",
"}",
"}"
] | Detect the current environment from an environment configuration.
@param array $environments
@param string $uri
@return string|null | [
"Detect",
"the",
"current",
"environment",
"from",
"an",
"environment",
"configuration",
"."
] | a9102d9d6f70e8b0f6be93153f70849f46489ee1 | https://github.com/schpill/thin/blob/a9102d9d6f70e8b0f6be93153f70849f46489ee1/src/Request.php#L231-L243 | train |
atelierspierrot/patterns | src/Patterns/Commons/Registry.php | Registry.setEntry | public function setEntry($var = null, $val = null, $section = false)
{
if (!empty($var)) {
if ($section) {
if (!isset($this->registry[$section])) {
$this->registry[$section] = array();
}
$this->registry[$section][$var] = $val;
} else {
$this->registry[$var] = $val;
}
}
return $this;
} | php | public function setEntry($var = null, $val = null, $section = false)
{
if (!empty($var)) {
if ($section) {
if (!isset($this->registry[$section])) {
$this->registry[$section] = array();
}
$this->registry[$section][$var] = $val;
} else {
$this->registry[$var] = $val;
}
}
return $this;
} | [
"public",
"function",
"setEntry",
"(",
"$",
"var",
"=",
"null",
",",
"$",
"val",
"=",
"null",
",",
"$",
"section",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"var",
")",
")",
"{",
"if",
"(",
"$",
"section",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"registry",
"[",
"$",
"section",
"]",
")",
")",
"{",
"$",
"this",
"->",
"registry",
"[",
"$",
"section",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"this",
"->",
"registry",
"[",
"$",
"section",
"]",
"[",
"$",
"var",
"]",
"=",
"$",
"val",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"registry",
"[",
"$",
"var",
"]",
"=",
"$",
"val",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Set an entry in the instance registry
@param null|string $var The variable name to set
@param null|mixed $val The variable value to set
@param false|string $section A section name in the registry (default is FALSE)
@return self | [
"Set",
"an",
"entry",
"in",
"the",
"instance",
"registry"
] | b7a8313e98bbfb6525e1672d0a726a1ead6f156e | https://github.com/atelierspierrot/patterns/blob/b7a8313e98bbfb6525e1672d0a726a1ead6f156e/src/Patterns/Commons/Registry.php#L102-L115 | train |
atelierspierrot/patterns | src/Patterns/Commons/Registry.php | Registry.getEntry | public function getEntry($var = null, $section = false, $default = null)
{
if (!empty($var)) {
if (!empty($section) && isset($this->registry[$section]) && isset($this->registry[$section][$var])) {
return $this->registry[$section][$var];
} elseif (isset($this->registry[$var])) {
return $this->registry[$var];
}
}
return !is_null($default) ? $default : false;
} | php | public function getEntry($var = null, $section = false, $default = null)
{
if (!empty($var)) {
if (!empty($section) && isset($this->registry[$section]) && isset($this->registry[$section][$var])) {
return $this->registry[$section][$var];
} elseif (isset($this->registry[$var])) {
return $this->registry[$var];
}
}
return !is_null($default) ? $default : false;
} | [
"public",
"function",
"getEntry",
"(",
"$",
"var",
"=",
"null",
",",
"$",
"section",
"=",
"false",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"var",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"section",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"registry",
"[",
"$",
"section",
"]",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"registry",
"[",
"$",
"section",
"]",
"[",
"$",
"var",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"registry",
"[",
"$",
"section",
"]",
"[",
"$",
"var",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"this",
"->",
"registry",
"[",
"$",
"var",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"registry",
"[",
"$",
"var",
"]",
";",
"}",
"}",
"return",
"!",
"is_null",
"(",
"$",
"default",
")",
"?",
"$",
"default",
":",
"false",
";",
"}"
] | Get an entry from the instance registry
@param string $var The variable name to get
@param string $section A section name in the registry (default is FALSE)
@param mixed $default The default value to return if it is not in registry (default is NULL)
@return mixed The value found or $default | [
"Get",
"an",
"entry",
"from",
"the",
"instance",
"registry"
] | b7a8313e98bbfb6525e1672d0a726a1ead6f156e | https://github.com/atelierspierrot/patterns/blob/b7a8313e98bbfb6525e1672d0a726a1ead6f156e/src/Patterns/Commons/Registry.php#L143-L153 | train |
atelierspierrot/patterns | src/Patterns/Commons/Registry.php | Registry.isEntry | public function isEntry($var = null, $section = false)
{
return (
!empty($var) and (
(!empty($section) && isset($this->registry[$section]) && isset($this->registry[$section][$var])) or
isset($this->registry[$var])
)
);
} | php | public function isEntry($var = null, $section = false)
{
return (
!empty($var) and (
(!empty($section) && isset($this->registry[$section]) && isset($this->registry[$section][$var])) or
isset($this->registry[$var])
)
);
} | [
"public",
"function",
"isEntry",
"(",
"$",
"var",
"=",
"null",
",",
"$",
"section",
"=",
"false",
")",
"{",
"return",
"(",
"!",
"empty",
"(",
"$",
"var",
")",
"and",
"(",
"(",
"!",
"empty",
"(",
"$",
"section",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"registry",
"[",
"$",
"section",
"]",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"registry",
"[",
"$",
"section",
"]",
"[",
"$",
"var",
"]",
")",
")",
"or",
"isset",
"(",
"$",
"this",
"->",
"registry",
"[",
"$",
"var",
"]",
")",
")",
")",
";",
"}"
] | Check if an entry exists in registry
@param string $var The variable name to check
@param string $section A section name in the registry (default is FALSE)
@return bool | [
"Check",
"if",
"an",
"entry",
"exists",
"in",
"registry"
] | b7a8313e98bbfb6525e1672d0a726a1ead6f156e | https://github.com/atelierspierrot/patterns/blob/b7a8313e98bbfb6525e1672d0a726a1ead6f156e/src/Patterns/Commons/Registry.php#L162-L170 | train |
atelierspierrot/patterns | src/Patterns/Commons/Registry.php | Registry.getKey | public function getKey($val = null, $var = null, $section = false)
{
if (!empty($val)) {
if (!empty($var)) {
foreach ($this->registry as $_sct=>$_data) {
if ($ok=array_search($val, $_data) && $ok==$var) {
return $_sct;
}
}
} elseif (!empty($section) && isset($this->registry[$section])) {
return array_search($val, $this->registry[$section]);
} else {
return array_search($val, $this->registry);
}
}
} | php | public function getKey($val = null, $var = null, $section = false)
{
if (!empty($val)) {
if (!empty($var)) {
foreach ($this->registry as $_sct=>$_data) {
if ($ok=array_search($val, $_data) && $ok==$var) {
return $_sct;
}
}
} elseif (!empty($section) && isset($this->registry[$section])) {
return array_search($val, $this->registry[$section]);
} else {
return array_search($val, $this->registry);
}
}
} | [
"public",
"function",
"getKey",
"(",
"$",
"val",
"=",
"null",
",",
"$",
"var",
"=",
"null",
",",
"$",
"section",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"val",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"var",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"registry",
"as",
"$",
"_sct",
"=>",
"$",
"_data",
")",
"{",
"if",
"(",
"$",
"ok",
"=",
"array_search",
"(",
"$",
"val",
",",
"$",
"_data",
")",
"&&",
"$",
"ok",
"==",
"$",
"var",
")",
"{",
"return",
"$",
"_sct",
";",
"}",
"}",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"section",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"registry",
"[",
"$",
"section",
"]",
")",
")",
"{",
"return",
"array_search",
"(",
"$",
"val",
",",
"$",
"this",
"->",
"registry",
"[",
"$",
"section",
"]",
")",
";",
"}",
"else",
"{",
"return",
"array_search",
"(",
"$",
"val",
",",
"$",
"this",
"->",
"registry",
")",
";",
"}",
"}",
"}"
] | Search a key in registry
@param mixed $val The variable value to find
@param string $var The variable name to search in (in case of array)
@param string $section A section name in the registry (default is FALSE)
@return string|null The key found in the registry | [
"Search",
"a",
"key",
"in",
"registry"
] | b7a8313e98bbfb6525e1672d0a726a1ead6f156e | https://github.com/atelierspierrot/patterns/blob/b7a8313e98bbfb6525e1672d0a726a1ead6f156e/src/Patterns/Commons/Registry.php#L180-L195 | train |
atelierspierrot/patterns | src/Patterns/Commons/Registry.php | Registry.dumpStack | public function dumpStack($index = null, $default = null)
{
if (array_key_exists($index, $this->registry_stacks)) {
return $this->registry_stacks[$index];
}
return $default;
} | php | public function dumpStack($index = null, $default = null)
{
if (array_key_exists($index, $this->registry_stacks)) {
return $this->registry_stacks[$index];
}
return $default;
} | [
"public",
"function",
"dumpStack",
"(",
"$",
"index",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"index",
",",
"$",
"this",
"->",
"registry_stacks",
")",
")",
"{",
"return",
"$",
"this",
"->",
"registry_stacks",
"[",
"$",
"index",
"]",
";",
"}",
"return",
"$",
"default",
";",
"}"
] | Get a full stack from registry stacks
@param string $index The stack index
@param mixed $default The default value to return if it is not in registry (default is NULL)
@return mixed The requested stack entry if so | [
"Get",
"a",
"full",
"stack",
"from",
"registry",
"stacks"
] | b7a8313e98bbfb6525e1672d0a726a1ead6f156e | https://github.com/atelierspierrot/patterns/blob/b7a8313e98bbfb6525e1672d0a726a1ead6f156e/src/Patterns/Commons/Registry.php#L208-L214 | train |
atelierspierrot/patterns | src/Patterns/Commons/Registry.php | Registry.saveStack | public function saveStack($index = null, $and_clean = false)
{
$this->registry_stacks[$index] = $this->registry;
if ($and_clean===true) {
$this->registry=array();
}
return $this;
} | php | public function saveStack($index = null, $and_clean = false)
{
$this->registry_stacks[$index] = $this->registry;
if ($and_clean===true) {
$this->registry=array();
}
return $this;
} | [
"public",
"function",
"saveStack",
"(",
"$",
"index",
"=",
"null",
",",
"$",
"and_clean",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"registry_stacks",
"[",
"$",
"index",
"]",
"=",
"$",
"this",
"->",
"registry",
";",
"if",
"(",
"$",
"and_clean",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"registry",
"=",
"array",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Save a stack of entries in registry
@param string $index The stack index
@param bool $and_clean Clean the actual registry after recorded the stack (default is FALSE)
@return self | [
"Save",
"a",
"stack",
"of",
"entries",
"in",
"registry"
] | b7a8313e98bbfb6525e1672d0a726a1ead6f156e | https://github.com/atelierspierrot/patterns/blob/b7a8313e98bbfb6525e1672d0a726a1ead6f156e/src/Patterns/Commons/Registry.php#L223-L230 | train |
atelierspierrot/patterns | src/Patterns/Commons/Registry.php | Registry.getStackEntry | public function getStackEntry($var = null, $section = false, $stack = null, $default = null)
{
if (!empty($var)) {
if (!empty($stack) && $this->isStack($stack)) {
$tmp_stack = $this->registry;
$this->loadStack($stack);
$val = $this->getEntry($var, $section, $default);
$this->registry = $tmp_stack;
return $val;
}
return $this->getEntry($var, $section, $default);
}
} | php | public function getStackEntry($var = null, $section = false, $stack = null, $default = null)
{
if (!empty($var)) {
if (!empty($stack) && $this->isStack($stack)) {
$tmp_stack = $this->registry;
$this->loadStack($stack);
$val = $this->getEntry($var, $section, $default);
$this->registry = $tmp_stack;
return $val;
}
return $this->getEntry($var, $section, $default);
}
} | [
"public",
"function",
"getStackEntry",
"(",
"$",
"var",
"=",
"null",
",",
"$",
"section",
"=",
"false",
",",
"$",
"stack",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"var",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"stack",
")",
"&&",
"$",
"this",
"->",
"isStack",
"(",
"$",
"stack",
")",
")",
"{",
"$",
"tmp_stack",
"=",
"$",
"this",
"->",
"registry",
";",
"$",
"this",
"->",
"loadStack",
"(",
"$",
"stack",
")",
";",
"$",
"val",
"=",
"$",
"this",
"->",
"getEntry",
"(",
"$",
"var",
",",
"$",
"section",
",",
"$",
"default",
")",
";",
"$",
"this",
"->",
"registry",
"=",
"$",
"tmp_stack",
";",
"return",
"$",
"val",
";",
"}",
"return",
"$",
"this",
"->",
"getEntry",
"(",
"$",
"var",
",",
"$",
"section",
",",
"$",
"default",
")",
";",
"}",
"}"
] | Get a stack entry of the registry stacks
@param string $var The variable name to search
@param string $section A section name in the registry (default is FALSE)
@param string $stack The stack name to search in
@param mixed $default The default value to return if it is not in registry (default is NULL)
@return mixed The value found or $default | [
"Get",
"a",
"stack",
"entry",
"of",
"the",
"registry",
"stacks"
] | b7a8313e98bbfb6525e1672d0a726a1ead6f156e | https://github.com/atelierspierrot/patterns/blob/b7a8313e98bbfb6525e1672d0a726a1ead6f156e/src/Patterns/Commons/Registry.php#L264-L276 | train |
atelierspierrot/patterns | src/Patterns/Commons/Registry.php | Registry.getStackKey | public function getStackKey($val = null, $section = false, $stack = null, $default = null)
{
if (!empty($val)) {
if (!empty($stack) && $this->isStack($stack)) {
$tmp_stack = $this->registry;
$this->loadStack($stack);
$var = $this->getKey($val, $section, $default);
$this->registry = $tmp_stack;
return $var;
}
return $this->getKey($val, $section, $default);
}
} | php | public function getStackKey($val = null, $section = false, $stack = null, $default = null)
{
if (!empty($val)) {
if (!empty($stack) && $this->isStack($stack)) {
$tmp_stack = $this->registry;
$this->loadStack($stack);
$var = $this->getKey($val, $section, $default);
$this->registry = $tmp_stack;
return $var;
}
return $this->getKey($val, $section, $default);
}
} | [
"public",
"function",
"getStackKey",
"(",
"$",
"val",
"=",
"null",
",",
"$",
"section",
"=",
"false",
",",
"$",
"stack",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"val",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"stack",
")",
"&&",
"$",
"this",
"->",
"isStack",
"(",
"$",
"stack",
")",
")",
"{",
"$",
"tmp_stack",
"=",
"$",
"this",
"->",
"registry",
";",
"$",
"this",
"->",
"loadStack",
"(",
"$",
"stack",
")",
";",
"$",
"var",
"=",
"$",
"this",
"->",
"getKey",
"(",
"$",
"val",
",",
"$",
"section",
",",
"$",
"default",
")",
";",
"$",
"this",
"->",
"registry",
"=",
"$",
"tmp_stack",
";",
"return",
"$",
"var",
";",
"}",
"return",
"$",
"this",
"->",
"getKey",
"(",
"$",
"val",
",",
"$",
"section",
",",
"$",
"default",
")",
";",
"}",
"}"
] | Get the key of a stack entry of the registry stacks
@param string $val The variable value to search
@param string $section A section name in the registry (default is FALSE)
@param string $stack The stack name to search in
@param mixed $default The default value to return if it is not in registry (default is NULL)
@return mixed The key found or $default | [
"Get",
"the",
"key",
"of",
"a",
"stack",
"entry",
"of",
"the",
"registry",
"stacks"
] | b7a8313e98bbfb6525e1672d0a726a1ead6f156e | https://github.com/atelierspierrot/patterns/blob/b7a8313e98bbfb6525e1672d0a726a1ead6f156e/src/Patterns/Commons/Registry.php#L287-L299 | train |
ben-gibson/foursquare-venue-client | src/Factory/Tip/TipFactory.php | TipFactory.create | public function create(Description $description)
{
return new Tip(
new Identifier($description->getMandatoryProperty('id')),
$description->getMandatoryProperty('text'),
$description->getMandatoryProperty('type'),
$description->getMandatoryProperty('agreeCount'),
$description->getMandatoryProperty('disagreeCount')
);
} | php | public function create(Description $description)
{
return new Tip(
new Identifier($description->getMandatoryProperty('id')),
$description->getMandatoryProperty('text'),
$description->getMandatoryProperty('type'),
$description->getMandatoryProperty('agreeCount'),
$description->getMandatoryProperty('disagreeCount')
);
} | [
"public",
"function",
"create",
"(",
"Description",
"$",
"description",
")",
"{",
"return",
"new",
"Tip",
"(",
"new",
"Identifier",
"(",
"$",
"description",
"->",
"getMandatoryProperty",
"(",
"'id'",
")",
")",
",",
"$",
"description",
"->",
"getMandatoryProperty",
"(",
"'text'",
")",
",",
"$",
"description",
"->",
"getMandatoryProperty",
"(",
"'type'",
")",
",",
"$",
"description",
"->",
"getMandatoryProperty",
"(",
"'agreeCount'",
")",
",",
"$",
"description",
"->",
"getMandatoryProperty",
"(",
"'disagreeCount'",
")",
")",
";",
"}"
] | Create a tip from a description.
@param Description $description The tip description.
@return Tip | [
"Create",
"a",
"tip",
"from",
"a",
"description",
"."
] | ce5e7c308f87d5ccc28ab8d27a9cb51bd106d969 | https://github.com/ben-gibson/foursquare-venue-client/blob/ce5e7c308f87d5ccc28ab8d27a9cb51bd106d969/src/Factory/Tip/TipFactory.php#L21-L30 | train |
PHPColibri/framework | Util/File.php | File.getMimeType | public static function getMimeType($filePath)
{
$fInfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($fInfo, $filePath);
finfo_close($fInfo);
return $mime;
} | php | public static function getMimeType($filePath)
{
$fInfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($fInfo, $filePath);
finfo_close($fInfo);
return $mime;
} | [
"public",
"static",
"function",
"getMimeType",
"(",
"$",
"filePath",
")",
"{",
"$",
"fInfo",
"=",
"finfo_open",
"(",
"FILEINFO_MIME_TYPE",
")",
";",
"$",
"mime",
"=",
"finfo_file",
"(",
"$",
"fInfo",
",",
"$",
"filePath",
")",
";",
"finfo_close",
"(",
"$",
"fInfo",
")",
";",
"return",
"$",
"mime",
";",
"}"
] | Get mime-type og the file.
@param string $filePath
@throws \Exception
@return string string with mime-type like 'image/jpeg' & etc | [
"Get",
"mime",
"-",
"type",
"og",
"the",
"file",
"."
] | 7e5b77141da5e5e7c63afc83592671321ac52f36 | https://github.com/PHPColibri/framework/blob/7e5b77141da5e5e7c63afc83592671321ac52f36/Util/File.php#L18-L25 | train |
atelierspierrot/patterns | src/Patterns/Abstracts/AbstractSingleton.php | AbstractSingleton.createInstance | private static function createInstance($classname, array $arguments = array())
{
$reflection_obj = new ReflectionClass($classname);
if ($reflection_obj->getMethod('__construct')->isPublic()) {
self::$_instances[ $classname ] = call_user_func_array(array($reflection_obj, 'newInstance'), $arguments);
if (
method_exists(self::$_instances[ $classname ], 'init') &&
is_callable(array(self::$_instances[ $classname ], 'init'))
) {
self::$_instances[ $classname ]->init();
}
} else {
self::$_instances[ $classname ] = new $classname;
if (
method_exists(self::$_instances[ $classname ], 'init') &&
is_callable(array(self::$_instances[ $classname ], 'init'))
) {
call_user_func_array(array(self::$_instances[ $classname ], 'init'), $arguments);
}
}
} | php | private static function createInstance($classname, array $arguments = array())
{
$reflection_obj = new ReflectionClass($classname);
if ($reflection_obj->getMethod('__construct')->isPublic()) {
self::$_instances[ $classname ] = call_user_func_array(array($reflection_obj, 'newInstance'), $arguments);
if (
method_exists(self::$_instances[ $classname ], 'init') &&
is_callable(array(self::$_instances[ $classname ], 'init'))
) {
self::$_instances[ $classname ]->init();
}
} else {
self::$_instances[ $classname ] = new $classname;
if (
method_exists(self::$_instances[ $classname ], 'init') &&
is_callable(array(self::$_instances[ $classname ], 'init'))
) {
call_user_func_array(array(self::$_instances[ $classname ], 'init'), $arguments);
}
}
} | [
"private",
"static",
"function",
"createInstance",
"(",
"$",
"classname",
",",
"array",
"$",
"arguments",
"=",
"array",
"(",
")",
")",
"{",
"$",
"reflection_obj",
"=",
"new",
"ReflectionClass",
"(",
"$",
"classname",
")",
";",
"if",
"(",
"$",
"reflection_obj",
"->",
"getMethod",
"(",
"'__construct'",
")",
"->",
"isPublic",
"(",
")",
")",
"{",
"self",
"::",
"$",
"_instances",
"[",
"$",
"classname",
"]",
"=",
"call_user_func_array",
"(",
"array",
"(",
"$",
"reflection_obj",
",",
"'newInstance'",
")",
",",
"$",
"arguments",
")",
";",
"if",
"(",
"method_exists",
"(",
"self",
"::",
"$",
"_instances",
"[",
"$",
"classname",
"]",
",",
"'init'",
")",
"&&",
"is_callable",
"(",
"array",
"(",
"self",
"::",
"$",
"_instances",
"[",
"$",
"classname",
"]",
",",
"'init'",
")",
")",
")",
"{",
"self",
"::",
"$",
"_instances",
"[",
"$",
"classname",
"]",
"->",
"init",
"(",
")",
";",
"}",
"}",
"else",
"{",
"self",
"::",
"$",
"_instances",
"[",
"$",
"classname",
"]",
"=",
"new",
"$",
"classname",
";",
"if",
"(",
"method_exists",
"(",
"self",
"::",
"$",
"_instances",
"[",
"$",
"classname",
"]",
",",
"'init'",
")",
"&&",
"is_callable",
"(",
"array",
"(",
"self",
"::",
"$",
"_instances",
"[",
"$",
"classname",
"]",
",",
"'init'",
")",
")",
")",
"{",
"call_user_func_array",
"(",
"array",
"(",
"self",
"::",
"$",
"_instances",
"[",
"$",
"classname",
"]",
",",
"'init'",
")",
",",
"$",
"arguments",
")",
";",
"}",
"}",
"}"
] | Real object instances creation
@param string $classname The classname to create object from
@param array $arguments The arguments to pass to the `__construct` or `init` method
@return void | [
"Real",
"object",
"instances",
"creation"
] | b7a8313e98bbfb6525e1672d0a726a1ead6f156e | https://github.com/atelierspierrot/patterns/blob/b7a8313e98bbfb6525e1672d0a726a1ead6f156e/src/Patterns/Abstracts/AbstractSingleton.php#L124-L144 | train |
harp-orm/harp | src/Rel/AbstractRel.php | AbstractRel.linkModels | public function linkModels(Models $models, Models $foreign, Closure $yield)
{
foreach ($models as $model) {
$linked = [];
foreach ($foreign as $foreignModel) {
if ($this->areLinked($model, $foreignModel)) {
$linked []= $foreignModel;
}
}
$link = $this->newLinkFrom($model, $linked);
$yield($link);
}
} | php | public function linkModels(Models $models, Models $foreign, Closure $yield)
{
foreach ($models as $model) {
$linked = [];
foreach ($foreign as $foreignModel) {
if ($this->areLinked($model, $foreignModel)) {
$linked []= $foreignModel;
}
}
$link = $this->newLinkFrom($model, $linked);
$yield($link);
}
} | [
"public",
"function",
"linkModels",
"(",
"Models",
"$",
"models",
",",
"Models",
"$",
"foreign",
",",
"Closure",
"$",
"yield",
")",
"{",
"foreach",
"(",
"$",
"models",
"as",
"$",
"model",
")",
"{",
"$",
"linked",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"foreign",
"as",
"$",
"foreignModel",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"areLinked",
"(",
"$",
"model",
",",
"$",
"foreignModel",
")",
")",
"{",
"$",
"linked",
"[",
"]",
"=",
"$",
"foreignModel",
";",
"}",
"}",
"$",
"link",
"=",
"$",
"this",
"->",
"newLinkFrom",
"(",
"$",
"model",
",",
"$",
"linked",
")",
";",
"$",
"yield",
"(",
"$",
"link",
")",
";",
"}",
"}"
] | Iterate models and foreign models one by one and and assign links based on the areLinked method
Yeild the resulted links one by one for further processing.
@param Models $models
@param Models $foreign
@param Closure $yield call for each link | [
"Iterate",
"models",
"and",
"foreign",
"models",
"one",
"by",
"one",
"and",
"and",
"assign",
"links",
"based",
"on",
"the",
"areLinked",
"method",
"Yeild",
"the",
"resulted",
"links",
"one",
"by",
"one",
"for",
"further",
"processing",
"."
] | e0751696521164c86ccd0a76d708df490efd8306 | https://github.com/harp-orm/harp/blob/e0751696521164c86ccd0a76d708df490efd8306/src/Rel/AbstractRel.php#L165-L181 | train |
praxisnetau/silverware-navigation | src/Model/LinkHolder.php | LinkHolder.getEnabledLinks | public function getEnabledLinks()
{
switch ($this->LinkMode) {
case self::MODE_PAGES:
$links = ArrayList::create();
foreach ($this->LinkedPages() as $page) {
$link = $page->toLink();
$link->setParent($this);
$links->push($link);
}
break;
default:
$links = $this->getLinks()->filterByCallback(function ($link) {
return $link->isEnabled();
});
}
return $links->sort($this->getSortOrder());
} | php | public function getEnabledLinks()
{
switch ($this->LinkMode) {
case self::MODE_PAGES:
$links = ArrayList::create();
foreach ($this->LinkedPages() as $page) {
$link = $page->toLink();
$link->setParent($this);
$links->push($link);
}
break;
default:
$links = $this->getLinks()->filterByCallback(function ($link) {
return $link->isEnabled();
});
}
return $links->sort($this->getSortOrder());
} | [
"public",
"function",
"getEnabledLinks",
"(",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"LinkMode",
")",
"{",
"case",
"self",
"::",
"MODE_PAGES",
":",
"$",
"links",
"=",
"ArrayList",
"::",
"create",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"LinkedPages",
"(",
")",
"as",
"$",
"page",
")",
"{",
"$",
"link",
"=",
"$",
"page",
"->",
"toLink",
"(",
")",
";",
"$",
"link",
"->",
"setParent",
"(",
"$",
"this",
")",
";",
"$",
"links",
"->",
"push",
"(",
"$",
"link",
")",
";",
"}",
"break",
";",
"default",
":",
"$",
"links",
"=",
"$",
"this",
"->",
"getLinks",
"(",
")",
"->",
"filterByCallback",
"(",
"function",
"(",
"$",
"link",
")",
"{",
"return",
"$",
"link",
"->",
"isEnabled",
"(",
")",
";",
"}",
")",
";",
"}",
"return",
"$",
"links",
"->",
"sort",
"(",
"$",
"this",
"->",
"getSortOrder",
"(",
")",
")",
";",
"}"
] | Answers a list of the enabled links within the receiver.
@return ArrayList | [
"Answers",
"a",
"list",
"of",
"the",
"enabled",
"links",
"within",
"the",
"receiver",
"."
] | 04e6f3003c2871348d5bba7869d4fc273641627e | https://github.com/praxisnetau/silverware-navigation/blob/04e6f3003c2871348d5bba7869d4fc273641627e/src/Model/LinkHolder.php#L316-L341 | train |
atelierspierrot/templatengine | src/TemplateEngine/TemplateObject/CssFile.php | CssFile.addIfExists | public function addIfExists($file_path, $media = 'screen', $condition = null)
{
$_fp = $this->__template->findAsset($file_path);
if ($_fp || \AssetsManager\Loader::isUrl($file_path)) {
return $this->add($file_path, $media, $condition);
}
return $this;
} | php | public function addIfExists($file_path, $media = 'screen', $condition = null)
{
$_fp = $this->__template->findAsset($file_path);
if ($_fp || \AssetsManager\Loader::isUrl($file_path)) {
return $this->add($file_path, $media, $condition);
}
return $this;
} | [
"public",
"function",
"addIfExists",
"(",
"$",
"file_path",
",",
"$",
"media",
"=",
"'screen'",
",",
"$",
"condition",
"=",
"null",
")",
"{",
"$",
"_fp",
"=",
"$",
"this",
"->",
"__template",
"->",
"findAsset",
"(",
"$",
"file_path",
")",
";",
"if",
"(",
"$",
"_fp",
"||",
"\\",
"AssetsManager",
"\\",
"Loader",
"::",
"isUrl",
"(",
"$",
"file_path",
")",
")",
"{",
"return",
"$",
"this",
"->",
"add",
"(",
"$",
"file_path",
",",
"$",
"media",
",",
"$",
"condition",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Add a CSS file in CSS stack if it exists
@param string $file_path The new CSS path
@param string $media The media type for the CSS file (default is "screen")
@param string|null $condition Define a condition (for IE) for this stylesheet
@return self | [
"Add",
"a",
"CSS",
"file",
"in",
"CSS",
"stack",
"if",
"it",
"exists"
] | de01b117f882670bed7b322e2d3b8b30fa9ae45f | https://github.com/atelierspierrot/templatengine/blob/de01b117f882670bed7b322e2d3b8b30fa9ae45f/src/TemplateEngine/TemplateObject/CssFile.php#L70-L77 | train |
atelierspierrot/templatengine | src/TemplateEngine/TemplateObject/CssFile.php | CssFile.add | public function add($file_path, $media = 'screen', $condition = null)
{
$_fp = $this->__template->findAsset($file_path);
if ($_fp || \AssetsManager\Loader::isUrl($file_path)) {
$this->registry->addEntry(array(
'file'=>$_fp, 'media'=>$media, 'condition'=>$condition
), 'css_files');
} else {
throw new \InvalidArgumentException(
sprintf('CSS file "%s" not found!', $file_path)
);
}
return $this;
} | php | public function add($file_path, $media = 'screen', $condition = null)
{
$_fp = $this->__template->findAsset($file_path);
if ($_fp || \AssetsManager\Loader::isUrl($file_path)) {
$this->registry->addEntry(array(
'file'=>$_fp, 'media'=>$media, 'condition'=>$condition
), 'css_files');
} else {
throw new \InvalidArgumentException(
sprintf('CSS file "%s" not found!', $file_path)
);
}
return $this;
} | [
"public",
"function",
"add",
"(",
"$",
"file_path",
",",
"$",
"media",
"=",
"'screen'",
",",
"$",
"condition",
"=",
"null",
")",
"{",
"$",
"_fp",
"=",
"$",
"this",
"->",
"__template",
"->",
"findAsset",
"(",
"$",
"file_path",
")",
";",
"if",
"(",
"$",
"_fp",
"||",
"\\",
"AssetsManager",
"\\",
"Loader",
"::",
"isUrl",
"(",
"$",
"file_path",
")",
")",
"{",
"$",
"this",
"->",
"registry",
"->",
"addEntry",
"(",
"array",
"(",
"'file'",
"=>",
"$",
"_fp",
",",
"'media'",
"=>",
"$",
"media",
",",
"'condition'",
"=>",
"$",
"condition",
")",
",",
"'css_files'",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'CSS file \"%s\" not found!'",
",",
"$",
"file_path",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Add a CSS file in CSS stack
@param string $file_path The new CSS path
@param string $media The media type for the CSS file (default is "screen")
@param string|null $condition Define a condition (for IE) for this stylesheet
@return self
@throws \InvalidArgumentException if the path doesn't exist | [
"Add",
"a",
"CSS",
"file",
"in",
"CSS",
"stack"
] | de01b117f882670bed7b322e2d3b8b30fa9ae45f | https://github.com/atelierspierrot/templatengine/blob/de01b117f882670bed7b322e2d3b8b30fa9ae45f/src/TemplateEngine/TemplateObject/CssFile.php#L88-L101 | train |
atelierspierrot/templatengine | src/TemplateEngine/TemplateObject/CssFile.php | CssFile.set | public function set(array $files)
{
if (!empty($files)) {
foreach ($files as $_file) {
if (is_array($_file) && isset($_file['file'])) {
$this->add(
$_file['file'],
isset($_file['media']) ? $_file['media'] : '',
isset($_file['condition']) ? $_file['condition'] : null
);
} elseif (is_string($_file)) {
$this->add($_file);
}
}
}
return $this;
} | php | public function set(array $files)
{
if (!empty($files)) {
foreach ($files as $_file) {
if (is_array($_file) && isset($_file['file'])) {
$this->add(
$_file['file'],
isset($_file['media']) ? $_file['media'] : '',
isset($_file['condition']) ? $_file['condition'] : null
);
} elseif (is_string($_file)) {
$this->add($_file);
}
}
}
return $this;
} | [
"public",
"function",
"set",
"(",
"array",
"$",
"files",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"files",
")",
")",
"{",
"foreach",
"(",
"$",
"files",
"as",
"$",
"_file",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"_file",
")",
"&&",
"isset",
"(",
"$",
"_file",
"[",
"'file'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"add",
"(",
"$",
"_file",
"[",
"'file'",
"]",
",",
"isset",
"(",
"$",
"_file",
"[",
"'media'",
"]",
")",
"?",
"$",
"_file",
"[",
"'media'",
"]",
":",
"''",
",",
"isset",
"(",
"$",
"_file",
"[",
"'condition'",
"]",
")",
"?",
"$",
"_file",
"[",
"'condition'",
"]",
":",
"null",
")",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"_file",
")",
")",
"{",
"$",
"this",
"->",
"add",
"(",
"$",
"_file",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Set a full CSS stack
@param array $files An array of CSS files paths
@return self
@see self::add() | [
"Set",
"a",
"full",
"CSS",
"stack"
] | de01b117f882670bed7b322e2d3b8b30fa9ae45f | https://github.com/atelierspierrot/templatengine/blob/de01b117f882670bed7b322e2d3b8b30fa9ae45f/src/TemplateEngine/TemplateObject/CssFile.php#L110-L126 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.