id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
|
---|---|---|---|---|---|---|---|---|---|---|---|
8,500 | 99designs/ergo | classes/Ergo/Routing/Router.php | Router.redirect | public function redirect($template, $name, $to)
{
return $this->connect($template, $name, new RedirectController($to));
} | php | public function redirect($template, $name, $to)
{
return $this->connect($template, $name, new RedirectController($to));
} | [
"public",
"function",
"redirect",
"(",
"$",
"template",
",",
"$",
"name",
",",
"$",
"to",
")",
"{",
"return",
"$",
"this",
"->",
"connect",
"(",
"$",
"template",
",",
"$",
"name",
",",
"new",
"RedirectController",
"(",
"$",
"to",
")",
")",
";",
"}"
] | Create a redirect from a particular route name to another
@chainable | [
"Create",
"a",
"redirect",
"from",
"a",
"particular",
"route",
"name",
"to",
"another"
] | 8fbcfe683a14572cbf26ff59c3537c2261a7a4eb | https://github.com/99designs/ergo/blob/8fbcfe683a14572cbf26ff59c3537c2261a7a4eb/classes/Ergo/Routing/Router.php#L83-L86 |
8,501 | 99designs/ergo | classes/Ergo/Routing/Router.php | Router.alias | public function alias($template, $name, $to)
{
$router = $this;
return $this->connect($template, $name, function($request) use($router, $to) {
return $router->controller($to)->execute($request);
});
} | php | public function alias($template, $name, $to)
{
$router = $this;
return $this->connect($template, $name, function($request) use($router, $to) {
return $router->controller($to)->execute($request);
});
} | [
"public",
"function",
"alias",
"(",
"$",
"template",
",",
"$",
"name",
",",
"$",
"to",
")",
"{",
"$",
"router",
"=",
"$",
"this",
";",
"return",
"$",
"this",
"->",
"connect",
"(",
"$",
"template",
",",
"$",
"name",
",",
"function",
"(",
"$",
"request",
")",
"use",
"(",
"$",
"router",
",",
"$",
"to",
")",
"{",
"return",
"$",
"router",
"->",
"controller",
"(",
"$",
"to",
")",
"->",
"execute",
"(",
"$",
"request",
")",
";",
"}",
")",
";",
"}"
] | Register an alias from one route name to another | [
"Register",
"an",
"alias",
"from",
"one",
"route",
"name",
"to",
"another"
] | 8fbcfe683a14572cbf26ff59c3537c2261a7a4eb | https://github.com/99designs/ergo/blob/8fbcfe683a14572cbf26ff59c3537c2261a7a4eb/classes/Ergo/Routing/Router.php#L91-L97 |
8,502 | 99designs/ergo | classes/Ergo/Routing/Router.php | Router.lookup | public function lookup($path)
{
if($match = $this->_getRouteMatch($path,$this->_routes))
return $match;
if($match = $this->_getRouteMatch($path,$this->_customRoutes))
return $match;
throw new LookupException("No route matches path '$path'");
} | php | public function lookup($path)
{
if($match = $this->_getRouteMatch($path,$this->_routes))
return $match;
if($match = $this->_getRouteMatch($path,$this->_customRoutes))
return $match;
throw new LookupException("No route matches path '$path'");
} | [
"public",
"function",
"lookup",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"$",
"match",
"=",
"$",
"this",
"->",
"_getRouteMatch",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"_routes",
")",
")",
"return",
"$",
"match",
";",
"if",
"(",
"$",
"match",
"=",
"$",
"this",
"->",
"_getRouteMatch",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"_customRoutes",
")",
")",
"return",
"$",
"match",
";",
"throw",
"new",
"LookupException",
"(",
"\"No route matches path '$path'\"",
")",
";",
"}"
] | Looks up a route match based on a url path
@param string $path
@return RouteMatch | [
"Looks",
"up",
"a",
"route",
"match",
"based",
"on",
"a",
"url",
"path"
] | 8fbcfe683a14572cbf26ff59c3537c2261a7a4eb | https://github.com/99designs/ergo/blob/8fbcfe683a14572cbf26ff59c3537c2261a7a4eb/classes/Ergo/Routing/Router.php#L104-L113 |
8,503 | 99designs/ergo | classes/Ergo/Routing/Router.php | Router.metadata | public function metadata($routeName)
{
return isset($this->_metadata[$routeName])
? array_merge($this->_defaultMetadata, $this->_metadata[$routeName])
: $this->_defaultMetadata
;
} | php | public function metadata($routeName)
{
return isset($this->_metadata[$routeName])
? array_merge($this->_defaultMetadata, $this->_metadata[$routeName])
: $this->_defaultMetadata
;
} | [
"public",
"function",
"metadata",
"(",
"$",
"routeName",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"_metadata",
"[",
"$",
"routeName",
"]",
")",
"?",
"array_merge",
"(",
"$",
"this",
"->",
"_defaultMetadata",
",",
"$",
"this",
"->",
"_metadata",
"[",
"$",
"routeName",
"]",
")",
":",
"$",
"this",
"->",
"_defaultMetadata",
";",
"}"
] | Looks up metadata for a route name
@return array | [
"Looks",
"up",
"metadata",
"for",
"a",
"route",
"name"
] | 8fbcfe683a14572cbf26ff59c3537c2261a7a4eb | https://github.com/99designs/ergo/blob/8fbcfe683a14572cbf26ff59c3537c2261a7a4eb/classes/Ergo/Routing/Router.php#L119-L125 |
8,504 | 99designs/ergo | classes/Ergo/Routing/Router.php | Router.routeByName | public function routeByName($name)
{
if (isset($this->_routes[$name]))
return $this->_routes[$name];
if (isset($this->_customRoutes[$name]))
return $this->_customRoutes[$name];
throw new LookupException("No route named '$name'");
} | php | public function routeByName($name)
{
if (isset($this->_routes[$name]))
return $this->_routes[$name];
if (isset($this->_customRoutes[$name]))
return $this->_customRoutes[$name];
throw new LookupException("No route named '$name'");
} | [
"public",
"function",
"routeByName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_routes",
"[",
"$",
"name",
"]",
")",
")",
"return",
"$",
"this",
"->",
"_routes",
"[",
"$",
"name",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_customRoutes",
"[",
"$",
"name",
"]",
")",
")",
"return",
"$",
"this",
"->",
"_customRoutes",
"[",
"$",
"name",
"]",
";",
"throw",
"new",
"LookupException",
"(",
"\"No route named '$name'\"",
")",
";",
"}"
] | Looks up a route by name
@return Route | [
"Looks",
"up",
"a",
"route",
"by",
"name"
] | 8fbcfe683a14572cbf26ff59c3537c2261a7a4eb | https://github.com/99designs/ergo/blob/8fbcfe683a14572cbf26ff59c3537c2261a7a4eb/classes/Ergo/Routing/Router.php#L131-L140 |
8,505 | 99designs/ergo | classes/Ergo/Routing/Router.php | Router.buildUrl | public function buildUrl($name, $parameters=array(), $baseUrl=null)
{
$url = $this->routeByName($name)->interpolate($parameters);
if($baseUrl)
return (string) $baseUrl->relative($url);
else if(isset($this->_baseUrl))
return $this->_baseUrl->relative($url);
else
return $url;
} | php | public function buildUrl($name, $parameters=array(), $baseUrl=null)
{
$url = $this->routeByName($name)->interpolate($parameters);
if($baseUrl)
return (string) $baseUrl->relative($url);
else if(isset($this->_baseUrl))
return $this->_baseUrl->relative($url);
else
return $url;
} | [
"public",
"function",
"buildUrl",
"(",
"$",
"name",
",",
"$",
"parameters",
"=",
"array",
"(",
")",
",",
"$",
"baseUrl",
"=",
"null",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"routeByName",
"(",
"$",
"name",
")",
"->",
"interpolate",
"(",
"$",
"parameters",
")",
";",
"if",
"(",
"$",
"baseUrl",
")",
"return",
"(",
"string",
")",
"$",
"baseUrl",
"->",
"relative",
"(",
"$",
"url",
")",
";",
"else",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_baseUrl",
")",
")",
"return",
"$",
"this",
"->",
"_baseUrl",
"->",
"relative",
"(",
"$",
"url",
")",
";",
"else",
"return",
"$",
"url",
";",
"}"
] | Build a URL path based on a route name and associated parameters.
@param string $name
@param array $parameters | [
"Build",
"a",
"URL",
"path",
"based",
"on",
"a",
"route",
"name",
"and",
"associated",
"parameters",
"."
] | 8fbcfe683a14572cbf26ff59c3537c2261a7a4eb | https://github.com/99designs/ergo/blob/8fbcfe683a14572cbf26ff59c3537c2261a7a4eb/classes/Ergo/Routing/Router.php#L147-L157 |
8,506 | 99designs/ergo | classes/Ergo/Routing/Router.php | Router.controller | public function controller($name)
{
if(isset($this->_controllers[$name]) && ($controller = $this->_controllers[$name]))
{
$name = is_callable($controller)
? new CallbackController($controller)
: $controller
;
if(is_object($name))
return $name;
}
if($this->_resolver)
return $this->_resolver->resolve($name);
throw new LookupException("No controller defined for route '$name'");
} | php | public function controller($name)
{
if(isset($this->_controllers[$name]) && ($controller = $this->_controllers[$name]))
{
$name = is_callable($controller)
? new CallbackController($controller)
: $controller
;
if(is_object($name))
return $name;
}
if($this->_resolver)
return $this->_resolver->resolve($name);
throw new LookupException("No controller defined for route '$name'");
} | [
"public",
"function",
"controller",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_controllers",
"[",
"$",
"name",
"]",
")",
"&&",
"(",
"$",
"controller",
"=",
"$",
"this",
"->",
"_controllers",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"name",
"=",
"is_callable",
"(",
"$",
"controller",
")",
"?",
"new",
"CallbackController",
"(",
"$",
"controller",
")",
":",
"$",
"controller",
";",
"if",
"(",
"is_object",
"(",
"$",
"name",
")",
")",
"return",
"$",
"name",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_resolver",
")",
"return",
"$",
"this",
"->",
"_resolver",
"->",
"resolve",
"(",
"$",
"name",
")",
";",
"throw",
"new",
"LookupException",
"(",
"\"No controller defined for route '$name'\"",
")",
";",
"}"
] | Looks up a controller from a route name | [
"Looks",
"up",
"a",
"controller",
"from",
"a",
"route",
"name"
] | 8fbcfe683a14572cbf26ff59c3537c2261a7a4eb | https://github.com/99designs/ergo/blob/8fbcfe683a14572cbf26ff59c3537c2261a7a4eb/classes/Ergo/Routing/Router.php#L162-L179 |
8,507 | 99designs/ergo | classes/Ergo/Routing/Router.php | Router._getRouteMatch | private function _getRouteMatch($path,$routes)
{
foreach ($routes as $route)
{
if ($match = $route->getMatch($path, $this->metadata($route->getName())))
return $match;
}
return false;
} | php | private function _getRouteMatch($path,$routes)
{
foreach ($routes as $route)
{
if ($match = $route->getMatch($path, $this->metadata($route->getName())))
return $match;
}
return false;
} | [
"private",
"function",
"_getRouteMatch",
"(",
"$",
"path",
",",
"$",
"routes",
")",
"{",
"foreach",
"(",
"$",
"routes",
"as",
"$",
"route",
")",
"{",
"if",
"(",
"$",
"match",
"=",
"$",
"route",
"->",
"getMatch",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"metadata",
"(",
"$",
"route",
"->",
"getName",
"(",
")",
")",
")",
")",
"return",
"$",
"match",
";",
"}",
"return",
"false",
";",
"}"
] | Look for a matching route in provided route list.
@param string $path
@param array $routes
@return mixed Ergo\Routing\Route or boolean | [
"Look",
"for",
"a",
"matching",
"route",
"in",
"provided",
"route",
"list",
"."
] | 8fbcfe683a14572cbf26ff59c3537c2261a7a4eb | https://github.com/99designs/ergo/blob/8fbcfe683a14572cbf26ff59c3537c2261a7a4eb/classes/Ergo/Routing/Router.php#L197-L205 |
8,508 | shov/wpci-core | DataSource/WpciQuery.php | WpciQuery.addWpEnv | public function addWpEnv()
{
$wpp = $this->wpProvider;
$data = [
'site-url' => $wpp->getBlogInfo('url'),
'site-wpurl' => $wpp->getBlogInfo('wpurl'),
'site-description' => $wpp->getBlogInfo('description'),
'site-rss_url' => $wpp->getBlogInfo('rss_url'),
'site-rss2_url' => $wpp->getBlogInfo('rss2_url'),
'site-atom_url' => $wpp->getBlogInfo('atom_url'),
'site-comments_atom_url' => $wpp->getBlogInfo('comments_atom_url'),
'site-comments_rss2_url' => $wpp->getBlogInfo('comments_rss2_url'),
'site-pingback_url' => $wpp->getBlogInfo('pingback_url'),
'site-stylesheet_url' => $wpp->getBlogInfo('stylesheet_url'),
'site-stylesheet_directory' => $wpp->getBlogInfo('stylesheet_directory'),
'site-template_directory' => $wpp->getBlogInfo('template_directory'),
'site-admin_email' => $wpp->getBlogInfo('admin_email'),
'site-charset' => $wpp->getBlogInfo('charset'),
'site-html_type' => $wpp->getBlogInfo('html_type'),
'site-version' => $wpp->getBlogInfo('version'),
'site-language' => $wpp->getBlogInfo('language'),
'site-name' => $wpp->getBlogInfo('name'),
];
$this->mergeToTheData($data);
return $this;
} | php | public function addWpEnv()
{
$wpp = $this->wpProvider;
$data = [
'site-url' => $wpp->getBlogInfo('url'),
'site-wpurl' => $wpp->getBlogInfo('wpurl'),
'site-description' => $wpp->getBlogInfo('description'),
'site-rss_url' => $wpp->getBlogInfo('rss_url'),
'site-rss2_url' => $wpp->getBlogInfo('rss2_url'),
'site-atom_url' => $wpp->getBlogInfo('atom_url'),
'site-comments_atom_url' => $wpp->getBlogInfo('comments_atom_url'),
'site-comments_rss2_url' => $wpp->getBlogInfo('comments_rss2_url'),
'site-pingback_url' => $wpp->getBlogInfo('pingback_url'),
'site-stylesheet_url' => $wpp->getBlogInfo('stylesheet_url'),
'site-stylesheet_directory' => $wpp->getBlogInfo('stylesheet_directory'),
'site-template_directory' => $wpp->getBlogInfo('template_directory'),
'site-admin_email' => $wpp->getBlogInfo('admin_email'),
'site-charset' => $wpp->getBlogInfo('charset'),
'site-html_type' => $wpp->getBlogInfo('html_type'),
'site-version' => $wpp->getBlogInfo('version'),
'site-language' => $wpp->getBlogInfo('language'),
'site-name' => $wpp->getBlogInfo('name'),
];
$this->mergeToTheData($data);
return $this;
} | [
"public",
"function",
"addWpEnv",
"(",
")",
"{",
"$",
"wpp",
"=",
"$",
"this",
"->",
"wpProvider",
";",
"$",
"data",
"=",
"[",
"'site-url'",
"=>",
"$",
"wpp",
"->",
"getBlogInfo",
"(",
"'url'",
")",
",",
"'site-wpurl'",
"=>",
"$",
"wpp",
"->",
"getBlogInfo",
"(",
"'wpurl'",
")",
",",
"'site-description'",
"=>",
"$",
"wpp",
"->",
"getBlogInfo",
"(",
"'description'",
")",
",",
"'site-rss_url'",
"=>",
"$",
"wpp",
"->",
"getBlogInfo",
"(",
"'rss_url'",
")",
",",
"'site-rss2_url'",
"=>",
"$",
"wpp",
"->",
"getBlogInfo",
"(",
"'rss2_url'",
")",
",",
"'site-atom_url'",
"=>",
"$",
"wpp",
"->",
"getBlogInfo",
"(",
"'atom_url'",
")",
",",
"'site-comments_atom_url'",
"=>",
"$",
"wpp",
"->",
"getBlogInfo",
"(",
"'comments_atom_url'",
")",
",",
"'site-comments_rss2_url'",
"=>",
"$",
"wpp",
"->",
"getBlogInfo",
"(",
"'comments_rss2_url'",
")",
",",
"'site-pingback_url'",
"=>",
"$",
"wpp",
"->",
"getBlogInfo",
"(",
"'pingback_url'",
")",
",",
"'site-stylesheet_url'",
"=>",
"$",
"wpp",
"->",
"getBlogInfo",
"(",
"'stylesheet_url'",
")",
",",
"'site-stylesheet_directory'",
"=>",
"$",
"wpp",
"->",
"getBlogInfo",
"(",
"'stylesheet_directory'",
")",
",",
"'site-template_directory'",
"=>",
"$",
"wpp",
"->",
"getBlogInfo",
"(",
"'template_directory'",
")",
",",
"'site-admin_email'",
"=>",
"$",
"wpp",
"->",
"getBlogInfo",
"(",
"'admin_email'",
")",
",",
"'site-charset'",
"=>",
"$",
"wpp",
"->",
"getBlogInfo",
"(",
"'charset'",
")",
",",
"'site-html_type'",
"=>",
"$",
"wpp",
"->",
"getBlogInfo",
"(",
"'html_type'",
")",
",",
"'site-version'",
"=>",
"$",
"wpp",
"->",
"getBlogInfo",
"(",
"'version'",
")",
",",
"'site-language'",
"=>",
"$",
"wpp",
"->",
"getBlogInfo",
"(",
"'language'",
")",
",",
"'site-name'",
"=>",
"$",
"wpp",
"->",
"getBlogInfo",
"(",
"'name'",
")",
",",
"]",
";",
"$",
"this",
"->",
"mergeToTheData",
"(",
"$",
"data",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add wordpress environment to the data
@return WpciQuery
@throws \ErrorException | [
"Add",
"wordpress",
"environment",
"to",
"the",
"data"
] | e31084cbc2f310882df2b9b0548330ea5fdb4f26 | https://github.com/shov/wpci-core/blob/e31084cbc2f310882df2b9b0548330ea5fdb4f26/DataSource/WpciQuery.php#L76-L102 |
8,509 | shov/wpci-core | DataSource/WpciQuery.php | WpciQuery.addPostData | public function addPostData(?callable $anotherElse = null, bool $withoutWp = false)
{
/** @var WpPost $post global post */
$post = Core::get(WpPost::class);
$queryObject = $this->wpQuery();
$data = [];
if ($queryObject->have_posts()) {
$queryObject->the_post();
$data['title'] = $this->wpProvider->getTheTitle();
ob_start();
$this->wpProvider->theContent();
$data['content'] = ob_get_clean();
$postData['excerpt'] = $post->post_excerpt;
$data = array_merge($this->getAcfFromPage($post->ID), $data);
if (!is_null($anotherElse)) {
$anotherElse($data, $post);
}
}
if (!$withoutWp) {
ob_start();
$this->wpProvider->wpHead();
$data['wp-head'] = ob_get_clean();
ob_start();
$this->wpProvider->wpFooter();
$data['wp-footer'] = ob_get_clean();
}
$queryObject->rewind_posts();
$this->wpProvider->wpResetPostData();
$this->mergeToTheData($data);
return $this;
} | php | public function addPostData(?callable $anotherElse = null, bool $withoutWp = false)
{
/** @var WpPost $post global post */
$post = Core::get(WpPost::class);
$queryObject = $this->wpQuery();
$data = [];
if ($queryObject->have_posts()) {
$queryObject->the_post();
$data['title'] = $this->wpProvider->getTheTitle();
ob_start();
$this->wpProvider->theContent();
$data['content'] = ob_get_clean();
$postData['excerpt'] = $post->post_excerpt;
$data = array_merge($this->getAcfFromPage($post->ID), $data);
if (!is_null($anotherElse)) {
$anotherElse($data, $post);
}
}
if (!$withoutWp) {
ob_start();
$this->wpProvider->wpHead();
$data['wp-head'] = ob_get_clean();
ob_start();
$this->wpProvider->wpFooter();
$data['wp-footer'] = ob_get_clean();
}
$queryObject->rewind_posts();
$this->wpProvider->wpResetPostData();
$this->mergeToTheData($data);
return $this;
} | [
"public",
"function",
"addPostData",
"(",
"?",
"callable",
"$",
"anotherElse",
"=",
"null",
",",
"bool",
"$",
"withoutWp",
"=",
"false",
")",
"{",
"/** @var WpPost $post global post */",
"$",
"post",
"=",
"Core",
"::",
"get",
"(",
"WpPost",
"::",
"class",
")",
";",
"$",
"queryObject",
"=",
"$",
"this",
"->",
"wpQuery",
"(",
")",
";",
"$",
"data",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"queryObject",
"->",
"have_posts",
"(",
")",
")",
"{",
"$",
"queryObject",
"->",
"the_post",
"(",
")",
";",
"$",
"data",
"[",
"'title'",
"]",
"=",
"$",
"this",
"->",
"wpProvider",
"->",
"getTheTitle",
"(",
")",
";",
"ob_start",
"(",
")",
";",
"$",
"this",
"->",
"wpProvider",
"->",
"theContent",
"(",
")",
";",
"$",
"data",
"[",
"'content'",
"]",
"=",
"ob_get_clean",
"(",
")",
";",
"$",
"postData",
"[",
"'excerpt'",
"]",
"=",
"$",
"post",
"->",
"post_excerpt",
";",
"$",
"data",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"getAcfFromPage",
"(",
"$",
"post",
"->",
"ID",
")",
",",
"$",
"data",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"anotherElse",
")",
")",
"{",
"$",
"anotherElse",
"(",
"$",
"data",
",",
"$",
"post",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"withoutWp",
")",
"{",
"ob_start",
"(",
")",
";",
"$",
"this",
"->",
"wpProvider",
"->",
"wpHead",
"(",
")",
";",
"$",
"data",
"[",
"'wp-head'",
"]",
"=",
"ob_get_clean",
"(",
")",
";",
"ob_start",
"(",
")",
";",
"$",
"this",
"->",
"wpProvider",
"->",
"wpFooter",
"(",
")",
";",
"$",
"data",
"[",
"'wp-footer'",
"]",
"=",
"ob_get_clean",
"(",
")",
";",
"}",
"$",
"queryObject",
"->",
"rewind_posts",
"(",
")",
";",
"$",
"this",
"->",
"wpProvider",
"->",
"wpResetPostData",
"(",
")",
";",
"$",
"this",
"->",
"mergeToTheData",
"(",
"$",
"data",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add to result current post data
@param callable|null $anotherElse
@param bool $withoutWp
@return WpciQuery
@throws \Exception
@throws \Error | [
"Add",
"to",
"result",
"current",
"post",
"data"
] | e31084cbc2f310882df2b9b0548330ea5fdb4f26 | https://github.com/shov/wpci-core/blob/e31084cbc2f310882df2b9b0548330ea5fdb4f26/DataSource/WpciQuery.php#L112-L151 |
8,510 | shov/wpci-core | DataSource/WpciQuery.php | WpciQuery.addMenu | public function addMenu()
{
$menuLocations = $this->wpProvider
->getNavMenuLocations();
$data = [];
foreach ($menuLocations as $menuLocation => $menuId) {
$menu = $this->wpProvider
->wpGetNavMenuItems($menuId);
foreach ($menu as $menuItem) {
$item = new stdClass();
/**
* @var WpPost $menuItem
*/
$item->item = $menuItem->title;
$item->link = $menuItem->url;
$item->active = (Path::getCurrentUrl() === $menuItem->url) ? true : false;
$data[$menuLocation][] = $item;
}
}
$this->mergeToTheData($data);
return $this;
} | php | public function addMenu()
{
$menuLocations = $this->wpProvider
->getNavMenuLocations();
$data = [];
foreach ($menuLocations as $menuLocation => $menuId) {
$menu = $this->wpProvider
->wpGetNavMenuItems($menuId);
foreach ($menu as $menuItem) {
$item = new stdClass();
/**
* @var WpPost $menuItem
*/
$item->item = $menuItem->title;
$item->link = $menuItem->url;
$item->active = (Path::getCurrentUrl() === $menuItem->url) ? true : false;
$data[$menuLocation][] = $item;
}
}
$this->mergeToTheData($data);
return $this;
} | [
"public",
"function",
"addMenu",
"(",
")",
"{",
"$",
"menuLocations",
"=",
"$",
"this",
"->",
"wpProvider",
"->",
"getNavMenuLocations",
"(",
")",
";",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"menuLocations",
"as",
"$",
"menuLocation",
"=>",
"$",
"menuId",
")",
"{",
"$",
"menu",
"=",
"$",
"this",
"->",
"wpProvider",
"->",
"wpGetNavMenuItems",
"(",
"$",
"menuId",
")",
";",
"foreach",
"(",
"$",
"menu",
"as",
"$",
"menuItem",
")",
"{",
"$",
"item",
"=",
"new",
"stdClass",
"(",
")",
";",
"/**\n * @var WpPost $menuItem\n */",
"$",
"item",
"->",
"item",
"=",
"$",
"menuItem",
"->",
"title",
";",
"$",
"item",
"->",
"link",
"=",
"$",
"menuItem",
"->",
"url",
";",
"$",
"item",
"->",
"active",
"=",
"(",
"Path",
"::",
"getCurrentUrl",
"(",
")",
"===",
"$",
"menuItem",
"->",
"url",
")",
"?",
"true",
":",
"false",
";",
"$",
"data",
"[",
"$",
"menuLocation",
"]",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"}",
"$",
"this",
"->",
"mergeToTheData",
"(",
"$",
"data",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add menus to template
@return $this
@throws \ErrorException | [
"Add",
"menus",
"to",
"template"
] | e31084cbc2f310882df2b9b0548330ea5fdb4f26 | https://github.com/shov/wpci-core/blob/e31084cbc2f310882df2b9b0548330ea5fdb4f26/DataSource/WpciQuery.php#L215-L242 |
8,511 | shov/wpci-core | DataSource/WpciQuery.php | WpciQuery.addHomePageAcf | public function addHomePageAcf()
{
$homePageId = (int)$this->wpProvider->getOption('page_on_front');
$this->addAcfFromPage($homePageId);
return $this;
} | php | public function addHomePageAcf()
{
$homePageId = (int)$this->wpProvider->getOption('page_on_front');
$this->addAcfFromPage($homePageId);
return $this;
} | [
"public",
"function",
"addHomePageAcf",
"(",
")",
"{",
"$",
"homePageId",
"=",
"(",
"int",
")",
"$",
"this",
"->",
"wpProvider",
"->",
"getOption",
"(",
"'page_on_front'",
")",
";",
"$",
"this",
"->",
"addAcfFromPage",
"(",
"$",
"homePageId",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Try to add homepage ACF data to result
@return $this
@throws \ErrorException | [
"Try",
"to",
"add",
"homepage",
"ACF",
"data",
"to",
"result"
] | e31084cbc2f310882df2b9b0548330ea5fdb4f26 | https://github.com/shov/wpci-core/blob/e31084cbc2f310882df2b9b0548330ea5fdb4f26/DataSource/WpciQuery.php#L260-L265 |
8,512 | shov/wpci-core | DataSource/WpciQuery.php | WpciQuery.wpQuery | protected function wpQuery(): WpQuery
{
$hashDecoratedObject = spl_object_hash($this->decoratedWpQuery);
$globalObject = spl_object_hash(Core::get(WpQuery::class));
if ($hashDecoratedObject === $globalObject) {
$this->wpProvider->wpResetQuery();
}
return $this->decoratedWpQuery;
} | php | protected function wpQuery(): WpQuery
{
$hashDecoratedObject = spl_object_hash($this->decoratedWpQuery);
$globalObject = spl_object_hash(Core::get(WpQuery::class));
if ($hashDecoratedObject === $globalObject) {
$this->wpProvider->wpResetQuery();
}
return $this->decoratedWpQuery;
} | [
"protected",
"function",
"wpQuery",
"(",
")",
":",
"WpQuery",
"{",
"$",
"hashDecoratedObject",
"=",
"spl_object_hash",
"(",
"$",
"this",
"->",
"decoratedWpQuery",
")",
";",
"$",
"globalObject",
"=",
"spl_object_hash",
"(",
"Core",
"::",
"get",
"(",
"WpQuery",
"::",
"class",
")",
")",
";",
"if",
"(",
"$",
"hashDecoratedObject",
"===",
"$",
"globalObject",
")",
"{",
"$",
"this",
"->",
"wpProvider",
"->",
"wpResetQuery",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"decoratedWpQuery",
";",
"}"
] | Right way to get current and correct query object
@return WpQuery
@throws \Exception
@throws \Error | [
"Right",
"way",
"to",
"get",
"current",
"and",
"correct",
"query",
"object"
] | e31084cbc2f310882df2b9b0548330ea5fdb4f26 | https://github.com/shov/wpci-core/blob/e31084cbc2f310882df2b9b0548330ea5fdb4f26/DataSource/WpciQuery.php#L273-L283 |
8,513 | shov/wpci-core | DataSource/WpciQuery.php | WpciQuery.getAcfFromPage | protected function getAcfFromPage(int $pageId): array
{
$data = [];
try {
$data = $this->wpProvider->getFields($pageId);
} catch (\Throwable $e) {
;
}
if (!is_array($data) || empty($data)) return [];
return $data;
} | php | protected function getAcfFromPage(int $pageId): array
{
$data = [];
try {
$data = $this->wpProvider->getFields($pageId);
} catch (\Throwable $e) {
;
}
if (!is_array($data) || empty($data)) return [];
return $data;
} | [
"protected",
"function",
"getAcfFromPage",
"(",
"int",
"$",
"pageId",
")",
":",
"array",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"try",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"wpProvider",
"->",
"getFields",
"(",
"$",
"pageId",
")",
";",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
"e",
")",
"{",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
"||",
"empty",
"(",
"$",
"data",
")",
")",
"return",
"[",
"]",
";",
"return",
"$",
"data",
";",
"}"
] | Try to receive the ACF data by page id, will return empty array if fail
@param int $pageId
@return array | [
"Try",
"to",
"receive",
"the",
"ACF",
"data",
"by",
"page",
"id",
"will",
"return",
"empty",
"array",
"if",
"fail"
] | e31084cbc2f310882df2b9b0548330ea5fdb4f26 | https://github.com/shov/wpci-core/blob/e31084cbc2f310882df2b9b0548330ea5fdb4f26/DataSource/WpciQuery.php#L300-L312 |
8,514 | jurchiks/commons | src/collections/Collection.php | Collection.getKeys | public function getKeys($value, int $limit = 0): array
{
$predicate = function ($v, $k) use ($value)
{
return ($v === $value);
};
return $this->find($predicate, true, $limit);
} | php | public function getKeys($value, int $limit = 0): array
{
$predicate = function ($v, $k) use ($value)
{
return ($v === $value);
};
return $this->find($predicate, true, $limit);
} | [
"public",
"function",
"getKeys",
"(",
"$",
"value",
",",
"int",
"$",
"limit",
"=",
"0",
")",
":",
"array",
"{",
"$",
"predicate",
"=",
"function",
"(",
"$",
"v",
",",
"$",
"k",
")",
"use",
"(",
"$",
"value",
")",
"{",
"return",
"(",
"$",
"v",
"===",
"$",
"value",
")",
";",
"}",
";",
"return",
"$",
"this",
"->",
"find",
"(",
"$",
"predicate",
",",
"true",
",",
"$",
"limit",
")",
";",
"}"
] | Get all keys of a given value.
@param mixed $value : the value whose keys to get
@param int $limit : the maximum amount of keys to get; 0 - no limit, negative value - get the last N keys
@return array an array containing all keys that were found | [
"Get",
"all",
"keys",
"of",
"a",
"given",
"value",
"."
] | be9e1eca6a94380647160a882b8476bee3e4d8f8 | https://github.com/jurchiks/commons/blob/be9e1eca6a94380647160a882b8476bee3e4d8f8/src/collections/Collection.php#L120-L128 |
8,515 | jurchiks/commons | src/collections/Collection.php | Collection.findValue | public function findValue(callable $predicate, bool $findFirst = true): Option
{
$data = $this->find($predicate, false, $findFirst ? 1 : -1);
return new Option($data[0] ?? null, isset($data[0]));
} | php | public function findValue(callable $predicate, bool $findFirst = true): Option
{
$data = $this->find($predicate, false, $findFirst ? 1 : -1);
return new Option($data[0] ?? null, isset($data[0]));
} | [
"public",
"function",
"findValue",
"(",
"callable",
"$",
"predicate",
",",
"bool",
"$",
"findFirst",
"=",
"true",
")",
":",
"Option",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"find",
"(",
"$",
"predicate",
",",
"false",
",",
"$",
"findFirst",
"?",
"1",
":",
"-",
"1",
")",
";",
"return",
"new",
"Option",
"(",
"$",
"data",
"[",
"0",
"]",
"??",
"null",
",",
"isset",
"(",
"$",
"data",
"[",
"0",
"]",
")",
")",
";",
"}"
] | Find a value that matches the given criteria.
@param callable $predicate : the callback function to use to find the value.
Callback signature - ($value, $key) => bool
@param bool $findFirst : if true, find the first value, otherwise find the last value
@return Option an Option possibly containing the found value | [
"Find",
"a",
"value",
"that",
"matches",
"the",
"given",
"criteria",
"."
] | be9e1eca6a94380647160a882b8476bee3e4d8f8 | https://github.com/jurchiks/commons/blob/be9e1eca6a94380647160a882b8476bee3e4d8f8/src/collections/Collection.php#L138-L143 |
8,516 | jurchiks/commons | src/collections/Collection.php | Collection.findKey | public function findKey(callable $predicate, bool $findFirst = true): Option
{
$data = $this->find($predicate, true, $findFirst ? 1 : -1);
return new Option($data[0] ?? null, isset($data[0]));
} | php | public function findKey(callable $predicate, bool $findFirst = true): Option
{
$data = $this->find($predicate, true, $findFirst ? 1 : -1);
return new Option($data[0] ?? null, isset($data[0]));
} | [
"public",
"function",
"findKey",
"(",
"callable",
"$",
"predicate",
",",
"bool",
"$",
"findFirst",
"=",
"true",
")",
":",
"Option",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"find",
"(",
"$",
"predicate",
",",
"true",
",",
"$",
"findFirst",
"?",
"1",
":",
"-",
"1",
")",
";",
"return",
"new",
"Option",
"(",
"$",
"data",
"[",
"0",
"]",
"??",
"null",
",",
"isset",
"(",
"$",
"data",
"[",
"0",
"]",
")",
")",
";",
"}"
] | Find the key of a value that matches the given criteria.
@param callable $predicate : the callback function to use to find the value.
Callback signature - ($value, $key) => bool
@param bool $findFirst : if true, find the first value, otherwise find the last value
@return Option an Option possibly containing the found key | [
"Find",
"the",
"key",
"of",
"a",
"value",
"that",
"matches",
"the",
"given",
"criteria",
"."
] | be9e1eca6a94380647160a882b8476bee3e4d8f8 | https://github.com/jurchiks/commons/blob/be9e1eca6a94380647160a882b8476bee3e4d8f8/src/collections/Collection.php#L153-L158 |
8,517 | jurchiks/commons | src/collections/Collection.php | Collection.find | public function find(callable $predicate, bool $findKeys = null, int $limit = 0): array
{
$data = [];
$found = 0;
if ($limit >= 0)
{
foreach ($this->data as $key => $value)
{
if ($predicate($value, $key) === true)
{
$found++;
if ($findKeys === null)
{
$data[$key] = $value;
}
else
{
$data[] = $findKeys ? $key : $value;
}
if ($found === $limit)
{
break;
}
}
}
}
else
{
// iterate in reverse rather than reversing the whole array or trimming all matches to the limit
end($this->data);
for ($i = 0; $i < count($this->data); $i++)
{
$key = $this->key();
$value = $this->current();
if ($predicate($value, $key) === true)
{
$found++;
if ($findKeys === null)
{
$data[$key] = $value;
}
else
{
$data[] = $findKeys ? $key : $value;
}
if ($found === -$limit)
{
break;
}
}
$this->prev();
}
$this->rewind();
// entries need to be reversed otherwise they'll be in the wrong order
$data = array_reverse($data, ($findKeys === null));
}
return $data;
} | php | public function find(callable $predicate, bool $findKeys = null, int $limit = 0): array
{
$data = [];
$found = 0;
if ($limit >= 0)
{
foreach ($this->data as $key => $value)
{
if ($predicate($value, $key) === true)
{
$found++;
if ($findKeys === null)
{
$data[$key] = $value;
}
else
{
$data[] = $findKeys ? $key : $value;
}
if ($found === $limit)
{
break;
}
}
}
}
else
{
// iterate in reverse rather than reversing the whole array or trimming all matches to the limit
end($this->data);
for ($i = 0; $i < count($this->data); $i++)
{
$key = $this->key();
$value = $this->current();
if ($predicate($value, $key) === true)
{
$found++;
if ($findKeys === null)
{
$data[$key] = $value;
}
else
{
$data[] = $findKeys ? $key : $value;
}
if ($found === -$limit)
{
break;
}
}
$this->prev();
}
$this->rewind();
// entries need to be reversed otherwise they'll be in the wrong order
$data = array_reverse($data, ($findKeys === null));
}
return $data;
} | [
"public",
"function",
"find",
"(",
"callable",
"$",
"predicate",
",",
"bool",
"$",
"findKeys",
"=",
"null",
",",
"int",
"$",
"limit",
"=",
"0",
")",
":",
"array",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"$",
"found",
"=",
"0",
";",
"if",
"(",
"$",
"limit",
">=",
"0",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"predicate",
"(",
"$",
"value",
",",
"$",
"key",
")",
"===",
"true",
")",
"{",
"$",
"found",
"++",
";",
"if",
"(",
"$",
"findKeys",
"===",
"null",
")",
"{",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"]",
"=",
"$",
"findKeys",
"?",
"$",
"key",
":",
"$",
"value",
";",
"}",
"if",
"(",
"$",
"found",
"===",
"$",
"limit",
")",
"{",
"break",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"// iterate in reverse rather than reversing the whole array or trimming all matches to the limit",
"end",
"(",
"$",
"this",
"->",
"data",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"this",
"->",
"data",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"key",
"(",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"current",
"(",
")",
";",
"if",
"(",
"$",
"predicate",
"(",
"$",
"value",
",",
"$",
"key",
")",
"===",
"true",
")",
"{",
"$",
"found",
"++",
";",
"if",
"(",
"$",
"findKeys",
"===",
"null",
")",
"{",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"]",
"=",
"$",
"findKeys",
"?",
"$",
"key",
":",
"$",
"value",
";",
"}",
"if",
"(",
"$",
"found",
"===",
"-",
"$",
"limit",
")",
"{",
"break",
";",
"}",
"}",
"$",
"this",
"->",
"prev",
"(",
")",
";",
"}",
"$",
"this",
"->",
"rewind",
"(",
")",
";",
"// entries need to be reversed otherwise they'll be in the wrong order",
"$",
"data",
"=",
"array_reverse",
"(",
"$",
"data",
",",
"(",
"$",
"findKeys",
"===",
"null",
")",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Find all entries that match the given criteria.
@param callable $predicate : the callback function to use to find the match.
Callback signature - ($value, $key) => bool
@param bool $findKeys : if true, return an array containing only the matched keys; if false,
return matched values; and if NULL - return the original key => value pairs.
@param int $limit : maximum amount of keys to return. If positive, will return the first N keys, otherwise
the last N keys.
@return array an array containing the matches found | [
"Find",
"all",
"entries",
"that",
"match",
"the",
"given",
"criteria",
"."
] | be9e1eca6a94380647160a882b8476bee3e4d8f8 | https://github.com/jurchiks/commons/blob/be9e1eca6a94380647160a882b8476bee3e4d8f8/src/collections/Collection.php#L199-L267 |
8,518 | monolyth-php/formulaic | src/Attributes.php | Attributes.attributes | public function attributes() : string
{
$return = [];
ksort($this->attributes);
foreach ($this->attributes as $name => $value) {
if (is_null($value) || $value === true) {
if ($name == 'value') {
continue;
}
$return[] = $name;
} else {
if ($value === false) {
continue;
}
if ($name == 'name') {
$value = preg_replace("@^\[(.*?)\]@", '$1', $value);
}
$return[] = sprintf(
'%s="%s"',
$name,
htmlentities($value, ENT_COMPAT, 'UTF-8')
);
}
}
return $return ? ' '.implode(' ', $return) : '';
} | php | public function attributes() : string
{
$return = [];
ksort($this->attributes);
foreach ($this->attributes as $name => $value) {
if (is_null($value) || $value === true) {
if ($name == 'value') {
continue;
}
$return[] = $name;
} else {
if ($value === false) {
continue;
}
if ($name == 'name') {
$value = preg_replace("@^\[(.*?)\]@", '$1', $value);
}
$return[] = sprintf(
'%s="%s"',
$name,
htmlentities($value, ENT_COMPAT, 'UTF-8')
);
}
}
return $return ? ' '.implode(' ', $return) : '';
} | [
"public",
"function",
"attributes",
"(",
")",
":",
"string",
"{",
"$",
"return",
"=",
"[",
"]",
";",
"ksort",
"(",
"$",
"this",
"->",
"attributes",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"attributes",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
"||",
"$",
"value",
"===",
"true",
")",
"{",
"if",
"(",
"$",
"name",
"==",
"'value'",
")",
"{",
"continue",
";",
"}",
"$",
"return",
"[",
"]",
"=",
"$",
"name",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"value",
"===",
"false",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"name",
"==",
"'name'",
")",
"{",
"$",
"value",
"=",
"preg_replace",
"(",
"\"@^\\[(.*?)\\]@\"",
",",
"'$1'",
",",
"$",
"value",
")",
";",
"}",
"$",
"return",
"[",
"]",
"=",
"sprintf",
"(",
"'%s=\"%s\"'",
",",
"$",
"name",
",",
"htmlentities",
"(",
"$",
"value",
",",
"ENT_COMPAT",
",",
"'UTF-8'",
")",
")",
";",
"}",
"}",
"return",
"$",
"return",
"?",
"' '",
".",
"implode",
"(",
"' '",
",",
"$",
"return",
")",
":",
"''",
";",
"}"
] | Formats set attributes as a string ready for insertion into HTML.
@return string | [
"Formats",
"set",
"attributes",
"as",
"a",
"string",
"ready",
"for",
"insertion",
"into",
"HTML",
"."
] | 4bf7853a0c29cc17957f1b26c79f633867742c14 | https://github.com/monolyth-php/formulaic/blob/4bf7853a0c29cc17957f1b26c79f633867742c14/src/Attributes.php#L12-L37 |
8,519 | monolyth-php/formulaic | src/Attributes.php | Attributes.attribute | public function attribute(string $name, string $value = null) : object
{
$this->attributes[$name] = $value;
return $this;
} | php | public function attribute(string $name, string $value = null) : object
{
$this->attributes[$name] = $value;
return $this;
} | [
"public",
"function",
"attribute",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"value",
"=",
"null",
")",
":",
"object",
"{",
"$",
"this",
"->",
"attributes",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Set an attribute with optional value.
@param string $name
@param string|null $value
@return object Self. | [
"Set",
"an",
"attribute",
"with",
"optional",
"value",
"."
] | 4bf7853a0c29cc17957f1b26c79f633867742c14 | https://github.com/monolyth-php/formulaic/blob/4bf7853a0c29cc17957f1b26c79f633867742c14/src/Attributes.php#L46-L50 |
8,520 | bariew/yii2-user-cms-module | models/RegisterForm.php | RegisterForm.afterSave | public function afterSave($insert, $changedAttributes)
{
parent::afterSave($insert, $changedAttributes);
if ($this->isActive()) {
$loginForm = new LoginForm(['username' => $this->username]);
$loginForm->login(false);
}
} | php | public function afterSave($insert, $changedAttributes)
{
parent::afterSave($insert, $changedAttributes);
if ($this->isActive()) {
$loginForm = new LoginForm(['username' => $this->username]);
$loginForm->login(false);
}
} | [
"public",
"function",
"afterSave",
"(",
"$",
"insert",
",",
"$",
"changedAttributes",
")",
"{",
"parent",
"::",
"afterSave",
"(",
"$",
"insert",
",",
"$",
"changedAttributes",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isActive",
"(",
")",
")",
"{",
"$",
"loginForm",
"=",
"new",
"LoginForm",
"(",
"[",
"'username'",
"=>",
"$",
"this",
"->",
"username",
"]",
")",
";",
"$",
"loginForm",
"->",
"login",
"(",
"false",
")",
";",
"}",
"}"
] | Logs user in after registration.
@param boolean $insert
@param array $changedAttributes | [
"Logs",
"user",
"in",
"after",
"registration",
"."
] | d9f5658cae45308c0916bc99976272a4ec906490 | https://github.com/bariew/yii2-user-cms-module/blob/d9f5658cae45308c0916bc99976272a4ec906490/models/RegisterForm.php#L55-L62 |
8,521 | wasabi-cms/core | src/Routing/Route/WasabiRoute.php | WasabiRoute.parse | public function parse($url)
{
if (!$url) {
$url = '/';
}
$Routes = TableRegistry::get('Wasabi/Core.Routes');
$route = $Routes->find()
->orWhere([$Routes->aliasField('page_type') => 'collection'])
->orWhere([$Routes->aliasField('page_type') => 'simple'])
->andWhere([$Routes->aliasField('url') => $url])
->first();
$pageNumber = false;
$urlParts = explode('/', $url);
// no direct route found -> try paged collection routes
if (!$route) {
$part = array_pop($urlParts);
if (preg_match('/^[0-9]+$/', $part)) {
$pageNumber = (int)$part;
$part = array_pop($urlParts);
}
// paged url found so lets try to find a proper collection route
if ($pageNumber !== false && $part === self::PAGE_PART) {
$route = $Routes->find()->where([
$Routes->aliasField('page_type') => 'collection',
$Routes->aliasField('url') => join('/', $urlParts)
])->first();
}
}
if (!$route) {
return false;
}
if ($route->redirect_to !== null) {
/** @var \Wasabi\Core\Model\Entity\Route $redirectRoute */
$redirectRoute = $Routes->get($route->redirect_to);
$redirectUrl = $redirectRoute->url;
$statusCode = 301;
if ($pageNumber !== false && $pageNumber > 1) {
$redirectUrl .= '/' . self::PAGE_PART . '/' . $pageNumber;
}
if ($route->status_code !== null) {
$statusCode = (int)$route->status_code;
}
$this->_redirect($redirectUrl, $statusCode);
}
// Dispatch Wasabi.Routes.parse event to all plugin listeners to get params.
$routesParseEvent = new Event('Wasabi.Routes.parse', $url, [
'route' => $route,
'pageNumber' => $pageNumber
]);
EventManager::instance()->dispatch($routesParseEvent);
if (!$routesParseEvent->isStopped() || empty($routesParseEvent->result['params'])) {
return false;
}
$params = $routesParseEvent->result['params'];
return $params;
} | php | public function parse($url)
{
if (!$url) {
$url = '/';
}
$Routes = TableRegistry::get('Wasabi/Core.Routes');
$route = $Routes->find()
->orWhere([$Routes->aliasField('page_type') => 'collection'])
->orWhere([$Routes->aliasField('page_type') => 'simple'])
->andWhere([$Routes->aliasField('url') => $url])
->first();
$pageNumber = false;
$urlParts = explode('/', $url);
// no direct route found -> try paged collection routes
if (!$route) {
$part = array_pop($urlParts);
if (preg_match('/^[0-9]+$/', $part)) {
$pageNumber = (int)$part;
$part = array_pop($urlParts);
}
// paged url found so lets try to find a proper collection route
if ($pageNumber !== false && $part === self::PAGE_PART) {
$route = $Routes->find()->where([
$Routes->aliasField('page_type') => 'collection',
$Routes->aliasField('url') => join('/', $urlParts)
])->first();
}
}
if (!$route) {
return false;
}
if ($route->redirect_to !== null) {
/** @var \Wasabi\Core\Model\Entity\Route $redirectRoute */
$redirectRoute = $Routes->get($route->redirect_to);
$redirectUrl = $redirectRoute->url;
$statusCode = 301;
if ($pageNumber !== false && $pageNumber > 1) {
$redirectUrl .= '/' . self::PAGE_PART . '/' . $pageNumber;
}
if ($route->status_code !== null) {
$statusCode = (int)$route->status_code;
}
$this->_redirect($redirectUrl, $statusCode);
}
// Dispatch Wasabi.Routes.parse event to all plugin listeners to get params.
$routesParseEvent = new Event('Wasabi.Routes.parse', $url, [
'route' => $route,
'pageNumber' => $pageNumber
]);
EventManager::instance()->dispatch($routesParseEvent);
if (!$routesParseEvent->isStopped() || empty($routesParseEvent->result['params'])) {
return false;
}
$params = $routesParseEvent->result['params'];
return $params;
} | [
"public",
"function",
"parse",
"(",
"$",
"url",
")",
"{",
"if",
"(",
"!",
"$",
"url",
")",
"{",
"$",
"url",
"=",
"'/'",
";",
"}",
"$",
"Routes",
"=",
"TableRegistry",
"::",
"get",
"(",
"'Wasabi/Core.Routes'",
")",
";",
"$",
"route",
"=",
"$",
"Routes",
"->",
"find",
"(",
")",
"->",
"orWhere",
"(",
"[",
"$",
"Routes",
"->",
"aliasField",
"(",
"'page_type'",
")",
"=>",
"'collection'",
"]",
")",
"->",
"orWhere",
"(",
"[",
"$",
"Routes",
"->",
"aliasField",
"(",
"'page_type'",
")",
"=>",
"'simple'",
"]",
")",
"->",
"andWhere",
"(",
"[",
"$",
"Routes",
"->",
"aliasField",
"(",
"'url'",
")",
"=>",
"$",
"url",
"]",
")",
"->",
"first",
"(",
")",
";",
"$",
"pageNumber",
"=",
"false",
";",
"$",
"urlParts",
"=",
"explode",
"(",
"'/'",
",",
"$",
"url",
")",
";",
"// no direct route found -> try paged collection routes",
"if",
"(",
"!",
"$",
"route",
")",
"{",
"$",
"part",
"=",
"array_pop",
"(",
"$",
"urlParts",
")",
";",
"if",
"(",
"preg_match",
"(",
"'/^[0-9]+$/'",
",",
"$",
"part",
")",
")",
"{",
"$",
"pageNumber",
"=",
"(",
"int",
")",
"$",
"part",
";",
"$",
"part",
"=",
"array_pop",
"(",
"$",
"urlParts",
")",
";",
"}",
"// paged url found so lets try to find a proper collection route",
"if",
"(",
"$",
"pageNumber",
"!==",
"false",
"&&",
"$",
"part",
"===",
"self",
"::",
"PAGE_PART",
")",
"{",
"$",
"route",
"=",
"$",
"Routes",
"->",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"$",
"Routes",
"->",
"aliasField",
"(",
"'page_type'",
")",
"=>",
"'collection'",
",",
"$",
"Routes",
"->",
"aliasField",
"(",
"'url'",
")",
"=>",
"join",
"(",
"'/'",
",",
"$",
"urlParts",
")",
"]",
")",
"->",
"first",
"(",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"route",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"route",
"->",
"redirect_to",
"!==",
"null",
")",
"{",
"/** @var \\Wasabi\\Core\\Model\\Entity\\Route $redirectRoute */",
"$",
"redirectRoute",
"=",
"$",
"Routes",
"->",
"get",
"(",
"$",
"route",
"->",
"redirect_to",
")",
";",
"$",
"redirectUrl",
"=",
"$",
"redirectRoute",
"->",
"url",
";",
"$",
"statusCode",
"=",
"301",
";",
"if",
"(",
"$",
"pageNumber",
"!==",
"false",
"&&",
"$",
"pageNumber",
">",
"1",
")",
"{",
"$",
"redirectUrl",
".=",
"'/'",
".",
"self",
"::",
"PAGE_PART",
".",
"'/'",
".",
"$",
"pageNumber",
";",
"}",
"if",
"(",
"$",
"route",
"->",
"status_code",
"!==",
"null",
")",
"{",
"$",
"statusCode",
"=",
"(",
"int",
")",
"$",
"route",
"->",
"status_code",
";",
"}",
"$",
"this",
"->",
"_redirect",
"(",
"$",
"redirectUrl",
",",
"$",
"statusCode",
")",
";",
"}",
"// Dispatch Wasabi.Routes.parse event to all plugin listeners to get params.",
"$",
"routesParseEvent",
"=",
"new",
"Event",
"(",
"'Wasabi.Routes.parse'",
",",
"$",
"url",
",",
"[",
"'route'",
"=>",
"$",
"route",
",",
"'pageNumber'",
"=>",
"$",
"pageNumber",
"]",
")",
";",
"EventManager",
"::",
"instance",
"(",
")",
"->",
"dispatch",
"(",
"$",
"routesParseEvent",
")",
";",
"if",
"(",
"!",
"$",
"routesParseEvent",
"->",
"isStopped",
"(",
")",
"||",
"empty",
"(",
"$",
"routesParseEvent",
"->",
"result",
"[",
"'params'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"params",
"=",
"$",
"routesParseEvent",
"->",
"result",
"[",
"'params'",
"]",
";",
"return",
"$",
"params",
";",
"}"
] | Parse a requested url and create routing parameters from the routes table.
@param string $url The url to parse.
@return array|bool|mixed | [
"Parse",
"a",
"requested",
"url",
"and",
"create",
"routing",
"parameters",
"from",
"the",
"routes",
"table",
"."
] | 0eadbb64d2fc201bacc63c93814adeca70e08f90 | https://github.com/wasabi-cms/core/blob/0eadbb64d2fc201bacc63c93814adeca70e08f90/src/Routing/Route/WasabiRoute.php#L70-L141 |
8,522 | wasabi-cms/core | src/Routing/Route/WasabiRoute.php | WasabiRoute._redirect | protected function _redirect($redirectUrl, $statusCode = 301)
{
header('HTTP/1.1 ' . $statusCode);
header('Location: ' . Router::url($redirectUrl, true));
exit(0);
} | php | protected function _redirect($redirectUrl, $statusCode = 301)
{
header('HTTP/1.1 ' . $statusCode);
header('Location: ' . Router::url($redirectUrl, true));
exit(0);
} | [
"protected",
"function",
"_redirect",
"(",
"$",
"redirectUrl",
",",
"$",
"statusCode",
"=",
"301",
")",
"{",
"header",
"(",
"'HTTP/1.1 '",
".",
"$",
"statusCode",
")",
";",
"header",
"(",
"'Location: '",
".",
"Router",
"::",
"url",
"(",
"$",
"redirectUrl",
",",
"true",
")",
")",
";",
"exit",
"(",
"0",
")",
";",
"}"
] | Redirect to the given url.
@param string $redirectUrl The url to redirect to.
@param int $statusCode The http status code.
@return void | [
"Redirect",
"to",
"the",
"given",
"url",
"."
] | 0eadbb64d2fc201bacc63c93814adeca70e08f90 | https://github.com/wasabi-cms/core/blob/0eadbb64d2fc201bacc63c93814adeca70e08f90/src/Routing/Route/WasabiRoute.php#L150-L155 |
8,523 | fabsor/drupal-release-api | XMLProjectParser.php | XMLProjectParser.parse | function parse(\SimpleXMLElement $data)
{
$project = new DrupalProject();
$project->setApiVersion((string) $data->api_version);
$project->setTitle((string) $data->title);
$project->setShortName((string) $data->short_name);
$project->setRecommendedMajor((int) $data->recommended_major);
$project->setProjectStatus((string) $data->project_status);
$project->setLink((string) $data->link);
$terms = array();
foreach ($data->terms[0]->term as $term) {
$terms[(string) $term->name] = (string) $term->value;
}
$project->setTerms($terms);
$releases = array();
$currentRelease = FALSE;
foreach ($data->releases->release as $release) {
$releaseArr = array(
'version' => (string) $release->version,
'major' => (string) $release->version_major,
'patch' => (string) $release->version_patch,
'extra' => (string) $release->version_extra,
'status' => (string) $release->status,
);
$currentRelease = $this->compareRelease($releaseArr, $currentRelease);
$releases[$releaseArr['version']] = $releaseArr;
}
$project->setReleases($releases);
if ($currentRelease) {
$project->setCurrentRelease($currentRelease);
}
return $project;
} | php | function parse(\SimpleXMLElement $data)
{
$project = new DrupalProject();
$project->setApiVersion((string) $data->api_version);
$project->setTitle((string) $data->title);
$project->setShortName((string) $data->short_name);
$project->setRecommendedMajor((int) $data->recommended_major);
$project->setProjectStatus((string) $data->project_status);
$project->setLink((string) $data->link);
$terms = array();
foreach ($data->terms[0]->term as $term) {
$terms[(string) $term->name] = (string) $term->value;
}
$project->setTerms($terms);
$releases = array();
$currentRelease = FALSE;
foreach ($data->releases->release as $release) {
$releaseArr = array(
'version' => (string) $release->version,
'major' => (string) $release->version_major,
'patch' => (string) $release->version_patch,
'extra' => (string) $release->version_extra,
'status' => (string) $release->status,
);
$currentRelease = $this->compareRelease($releaseArr, $currentRelease);
$releases[$releaseArr['version']] = $releaseArr;
}
$project->setReleases($releases);
if ($currentRelease) {
$project->setCurrentRelease($currentRelease);
}
return $project;
} | [
"function",
"parse",
"(",
"\\",
"SimpleXMLElement",
"$",
"data",
")",
"{",
"$",
"project",
"=",
"new",
"DrupalProject",
"(",
")",
";",
"$",
"project",
"->",
"setApiVersion",
"(",
"(",
"string",
")",
"$",
"data",
"->",
"api_version",
")",
";",
"$",
"project",
"->",
"setTitle",
"(",
"(",
"string",
")",
"$",
"data",
"->",
"title",
")",
";",
"$",
"project",
"->",
"setShortName",
"(",
"(",
"string",
")",
"$",
"data",
"->",
"short_name",
")",
";",
"$",
"project",
"->",
"setRecommendedMajor",
"(",
"(",
"int",
")",
"$",
"data",
"->",
"recommended_major",
")",
";",
"$",
"project",
"->",
"setProjectStatus",
"(",
"(",
"string",
")",
"$",
"data",
"->",
"project_status",
")",
";",
"$",
"project",
"->",
"setLink",
"(",
"(",
"string",
")",
"$",
"data",
"->",
"link",
")",
";",
"$",
"terms",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"->",
"terms",
"[",
"0",
"]",
"->",
"term",
"as",
"$",
"term",
")",
"{",
"$",
"terms",
"[",
"(",
"string",
")",
"$",
"term",
"->",
"name",
"]",
"=",
"(",
"string",
")",
"$",
"term",
"->",
"value",
";",
"}",
"$",
"project",
"->",
"setTerms",
"(",
"$",
"terms",
")",
";",
"$",
"releases",
"=",
"array",
"(",
")",
";",
"$",
"currentRelease",
"=",
"FALSE",
";",
"foreach",
"(",
"$",
"data",
"->",
"releases",
"->",
"release",
"as",
"$",
"release",
")",
"{",
"$",
"releaseArr",
"=",
"array",
"(",
"'version'",
"=>",
"(",
"string",
")",
"$",
"release",
"->",
"version",
",",
"'major'",
"=>",
"(",
"string",
")",
"$",
"release",
"->",
"version_major",
",",
"'patch'",
"=>",
"(",
"string",
")",
"$",
"release",
"->",
"version_patch",
",",
"'extra'",
"=>",
"(",
"string",
")",
"$",
"release",
"->",
"version_extra",
",",
"'status'",
"=>",
"(",
"string",
")",
"$",
"release",
"->",
"status",
",",
")",
";",
"$",
"currentRelease",
"=",
"$",
"this",
"->",
"compareRelease",
"(",
"$",
"releaseArr",
",",
"$",
"currentRelease",
")",
";",
"$",
"releases",
"[",
"$",
"releaseArr",
"[",
"'version'",
"]",
"]",
"=",
"$",
"releaseArr",
";",
"}",
"$",
"project",
"->",
"setReleases",
"(",
"$",
"releases",
")",
";",
"if",
"(",
"$",
"currentRelease",
")",
"{",
"$",
"project",
"->",
"setCurrentRelease",
"(",
"$",
"currentRelease",
")",
";",
"}",
"return",
"$",
"project",
";",
"}"
] | Parse Drupal project ReleaseXML data
and return a DrupalProject object.
@return DrupalProject a fully populated DrupalProject object. | [
"Parse",
"Drupal",
"project",
"ReleaseXML",
"data",
"and",
"return",
"a",
"DrupalProject",
"object",
"."
] | 306a4765c807de2693d320ffc8a93ebe3fdb5bd9 | https://github.com/fabsor/drupal-release-api/blob/306a4765c807de2693d320ffc8a93ebe3fdb5bd9/XMLProjectParser.php#L23-L56 |
8,524 | timonf/static-deploy | src/StaticDeploy/Compiler/Compiler.php | Compiler.parse | public function parse($resource, $output)
{
printf('file %s' . PHP_EOL, $resource);
$pathinfo = pathinfo($resource);
$extension = $pathinfo['extension'];
$this->environment->setSourceFile($resource);
$parser = $this->configuration->getParserForFileExtension($extension);
if (!$parser instanceof ParserInterface) {
throw new \Exception('No parser found. Have you initialized any plugins?');
}
if ($parser instanceof HasEnvironmentInterface) {
$parser->setEnvironment($this->environment);
}
$content = $parser->parse($resource);
$output = $parser->getOutputFilename($output);
file_put_contents($output, $content);
} | php | public function parse($resource, $output)
{
printf('file %s' . PHP_EOL, $resource);
$pathinfo = pathinfo($resource);
$extension = $pathinfo['extension'];
$this->environment->setSourceFile($resource);
$parser = $this->configuration->getParserForFileExtension($extension);
if (!$parser instanceof ParserInterface) {
throw new \Exception('No parser found. Have you initialized any plugins?');
}
if ($parser instanceof HasEnvironmentInterface) {
$parser->setEnvironment($this->environment);
}
$content = $parser->parse($resource);
$output = $parser->getOutputFilename($output);
file_put_contents($output, $content);
} | [
"public",
"function",
"parse",
"(",
"$",
"resource",
",",
"$",
"output",
")",
"{",
"printf",
"(",
"'file %s'",
".",
"PHP_EOL",
",",
"$",
"resource",
")",
";",
"$",
"pathinfo",
"=",
"pathinfo",
"(",
"$",
"resource",
")",
";",
"$",
"extension",
"=",
"$",
"pathinfo",
"[",
"'extension'",
"]",
";",
"$",
"this",
"->",
"environment",
"->",
"setSourceFile",
"(",
"$",
"resource",
")",
";",
"$",
"parser",
"=",
"$",
"this",
"->",
"configuration",
"->",
"getParserForFileExtension",
"(",
"$",
"extension",
")",
";",
"if",
"(",
"!",
"$",
"parser",
"instanceof",
"ParserInterface",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'No parser found. Have you initialized any plugins?'",
")",
";",
"}",
"if",
"(",
"$",
"parser",
"instanceof",
"HasEnvironmentInterface",
")",
"{",
"$",
"parser",
"->",
"setEnvironment",
"(",
"$",
"this",
"->",
"environment",
")",
";",
"}",
"$",
"content",
"=",
"$",
"parser",
"->",
"parse",
"(",
"$",
"resource",
")",
";",
"$",
"output",
"=",
"$",
"parser",
"->",
"getOutputFilename",
"(",
"$",
"output",
")",
";",
"file_put_contents",
"(",
"$",
"output",
",",
"$",
"content",
")",
";",
"}"
] | Will parse a given file, and will write it to output directory
@param string $resource filename of source file
@param string $output directory of destination
@throws \Exception | [
"Will",
"parse",
"a",
"given",
"file",
"and",
"will",
"write",
"it",
"to",
"output",
"directory"
] | 1d0cbc34dfeddcaadabe6975d683daedf313a674 | https://github.com/timonf/static-deploy/blob/1d0cbc34dfeddcaadabe6975d683daedf313a674/src/StaticDeploy/Compiler/Compiler.php#L98-L120 |
8,525 | pletfix/core | src/Bootstraps/LoadConfiguration.php | LoadConfiguration.loadConfigFromFiles | private function loadConfigFromFiles()
{
/** @var \Core\Services\Contracts\Config $config */
$config = DI::getInstance()->get('config');
foreach (scandir($this->configPath) as $file) {
if (is_file($this->configPath . DIRECTORY_SEPARATOR . $file) && $file[0] != '.') {
/** @noinspection PhpIncludeInspection */
$config->set(basename($file, '.php'), require $this->configPath . DIRECTORY_SEPARATOR . $file);
}
}
return $config;
} | php | private function loadConfigFromFiles()
{
/** @var \Core\Services\Contracts\Config $config */
$config = DI::getInstance()->get('config');
foreach (scandir($this->configPath) as $file) {
if (is_file($this->configPath . DIRECTORY_SEPARATOR . $file) && $file[0] != '.') {
/** @noinspection PhpIncludeInspection */
$config->set(basename($file, '.php'), require $this->configPath . DIRECTORY_SEPARATOR . $file);
}
}
return $config;
} | [
"private",
"function",
"loadConfigFromFiles",
"(",
")",
"{",
"/** @var \\Core\\Services\\Contracts\\Config $config */",
"$",
"config",
"=",
"DI",
"::",
"getInstance",
"(",
")",
"->",
"get",
"(",
"'config'",
")",
";",
"foreach",
"(",
"scandir",
"(",
"$",
"this",
"->",
"configPath",
")",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"this",
"->",
"configPath",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
")",
"&&",
"$",
"file",
"[",
"0",
"]",
"!=",
"'.'",
")",
"{",
"/** @noinspection PhpIncludeInspection */",
"$",
"config",
"->",
"set",
"(",
"basename",
"(",
"$",
"file",
",",
"'.php'",
")",
",",
"require",
"$",
"this",
"->",
"configPath",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"file",
")",
";",
"}",
"}",
"return",
"$",
"config",
";",
"}"
] | Load the configuration files.
@return \Core\Services\Contracts\Config | [
"Load",
"the",
"configuration",
"files",
"."
] | 974945500f278eb6c1779832e08bbfca1007a7b3 | https://github.com/pletfix/core/blob/974945500f278eb6c1779832e08bbfca1007a7b3/src/Bootstraps/LoadConfiguration.php#L91-L104 |
8,526 | pletfix/core | src/Bootstraps/LoadConfiguration.php | LoadConfiguration.isCacheUpToDate | private function isCacheUpToDate()
{
if (!file_exists($this->cachedFile)) {
return false;
}
$cacheTime = filemtime($this->cachedFile);
$configTime = max(filemtime($this->configPath), filemtime($this->envFile));
return $cacheTime == $configTime;
} | php | private function isCacheUpToDate()
{
if (!file_exists($this->cachedFile)) {
return false;
}
$cacheTime = filemtime($this->cachedFile);
$configTime = max(filemtime($this->configPath), filemtime($this->envFile));
return $cacheTime == $configTime;
} | [
"private",
"function",
"isCacheUpToDate",
"(",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"cachedFile",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"cacheTime",
"=",
"filemtime",
"(",
"$",
"this",
"->",
"cachedFile",
")",
";",
"$",
"configTime",
"=",
"max",
"(",
"filemtime",
"(",
"$",
"this",
"->",
"configPath",
")",
",",
"filemtime",
"(",
"$",
"this",
"->",
"envFile",
")",
")",
";",
"return",
"$",
"cacheTime",
"==",
"$",
"configTime",
";",
"}"
] | Determine if the cached file is up to date with the configuration path.
@return bool | [
"Determine",
"if",
"the",
"cached",
"file",
"is",
"up",
"to",
"date",
"with",
"the",
"configuration",
"path",
"."
] | 974945500f278eb6c1779832e08bbfca1007a7b3 | https://github.com/pletfix/core/blob/974945500f278eb6c1779832e08bbfca1007a7b3/src/Bootstraps/LoadConfiguration.php#L111-L121 |
8,527 | pletfix/core | src/Bootstraps/LoadConfiguration.php | LoadConfiguration.loadConfigFromCache | private function loadConfigFromCache()
{
/** @var \Core\Services\Contracts\Config $config */
$config = DI::getInstance()->get('config');
/** @noinspection PhpIncludeInspection */
$config->set(null, require $this->cachedFile);
return $config;
} | php | private function loadConfigFromCache()
{
/** @var \Core\Services\Contracts\Config $config */
$config = DI::getInstance()->get('config');
/** @noinspection PhpIncludeInspection */
$config->set(null, require $this->cachedFile);
return $config;
} | [
"private",
"function",
"loadConfigFromCache",
"(",
")",
"{",
"/** @var \\Core\\Services\\Contracts\\Config $config */",
"$",
"config",
"=",
"DI",
"::",
"getInstance",
"(",
")",
"->",
"get",
"(",
"'config'",
")",
";",
"/** @noinspection PhpIncludeInspection */",
"$",
"config",
"->",
"set",
"(",
"null",
",",
"require",
"$",
"this",
"->",
"cachedFile",
")",
";",
"return",
"$",
"config",
";",
"}"
] | Load the configuration from cache.
@return \Core\Services\Contracts\Config | [
"Load",
"the",
"configuration",
"from",
"cache",
"."
] | 974945500f278eb6c1779832e08bbfca1007a7b3 | https://github.com/pletfix/core/blob/974945500f278eb6c1779832e08bbfca1007a7b3/src/Bootstraps/LoadConfiguration.php#L128-L137 |
8,528 | pletfix/core | src/Bootstraps/LoadConfiguration.php | LoadConfiguration.saveConfigToCache | private function saveConfigToCache($config)
{
if (!is_dir($cacheDir = dirname($this->cachedFile))) {
if (!make_dir($cacheDir, 0775)) {
throw new RuntimeException(sprintf('Configuration Loader was not able to create directory "%s"', $cacheDir)); // @codeCoverageIgnore
}
}
if (file_exists($this->cachedFile)) {
@unlink($this->cachedFile); // so we will to be the owner at the new file
}
if (file_put_contents($this->cachedFile, '<?php return ' . var_export($config->get(), true) . ';' . PHP_EOL, LOCK_EX) === false) {
throw new RuntimeException(sprintf('Configuration Loader was not able to save cached file "%s"', $this->cachedFile)); // @codeCoverageIgnore
}
@chmod($this->cachedFile, 0664);
$time = max(filemtime($this->configPath), filemtime($this->envFile));
if (!@touch($this->cachedFile, $time)) {
throw new RuntimeException(sprintf('Configuration Loader was not able to modify time of cached file "%s"', $this->cachedFile)); // @codeCoverageIgnore
}
} | php | private function saveConfigToCache($config)
{
if (!is_dir($cacheDir = dirname($this->cachedFile))) {
if (!make_dir($cacheDir, 0775)) {
throw new RuntimeException(sprintf('Configuration Loader was not able to create directory "%s"', $cacheDir)); // @codeCoverageIgnore
}
}
if (file_exists($this->cachedFile)) {
@unlink($this->cachedFile); // so we will to be the owner at the new file
}
if (file_put_contents($this->cachedFile, '<?php return ' . var_export($config->get(), true) . ';' . PHP_EOL, LOCK_EX) === false) {
throw new RuntimeException(sprintf('Configuration Loader was not able to save cached file "%s"', $this->cachedFile)); // @codeCoverageIgnore
}
@chmod($this->cachedFile, 0664);
$time = max(filemtime($this->configPath), filemtime($this->envFile));
if (!@touch($this->cachedFile, $time)) {
throw new RuntimeException(sprintf('Configuration Loader was not able to modify time of cached file "%s"', $this->cachedFile)); // @codeCoverageIgnore
}
} | [
"private",
"function",
"saveConfigToCache",
"(",
"$",
"config",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"cacheDir",
"=",
"dirname",
"(",
"$",
"this",
"->",
"cachedFile",
")",
")",
")",
"{",
"if",
"(",
"!",
"make_dir",
"(",
"$",
"cacheDir",
",",
"0775",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Configuration Loader was not able to create directory \"%s\"'",
",",
"$",
"cacheDir",
")",
")",
";",
"// @codeCoverageIgnore",
"}",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"cachedFile",
")",
")",
"{",
"@",
"unlink",
"(",
"$",
"this",
"->",
"cachedFile",
")",
";",
"// so we will to be the owner at the new file",
"}",
"if",
"(",
"file_put_contents",
"(",
"$",
"this",
"->",
"cachedFile",
",",
"'<?php return '",
".",
"var_export",
"(",
"$",
"config",
"->",
"get",
"(",
")",
",",
"true",
")",
".",
"';'",
".",
"PHP_EOL",
",",
"LOCK_EX",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Configuration Loader was not able to save cached file \"%s\"'",
",",
"$",
"this",
"->",
"cachedFile",
")",
")",
";",
"// @codeCoverageIgnore",
"}",
"@",
"chmod",
"(",
"$",
"this",
"->",
"cachedFile",
",",
"0664",
")",
";",
"$",
"time",
"=",
"max",
"(",
"filemtime",
"(",
"$",
"this",
"->",
"configPath",
")",
",",
"filemtime",
"(",
"$",
"this",
"->",
"envFile",
")",
")",
";",
"if",
"(",
"!",
"@",
"touch",
"(",
"$",
"this",
"->",
"cachedFile",
",",
"$",
"time",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Configuration Loader was not able to modify time of cached file \"%s\"'",
",",
"$",
"this",
"->",
"cachedFile",
")",
")",
";",
"// @codeCoverageIgnore",
"}",
"}"
] | Save the configuration to the cache.
@param \Core\Services\Contracts\Config $config | [
"Save",
"the",
"configuration",
"to",
"the",
"cache",
"."
] | 974945500f278eb6c1779832e08bbfca1007a7b3 | https://github.com/pletfix/core/blob/974945500f278eb6c1779832e08bbfca1007a7b3/src/Bootstraps/LoadConfiguration.php#L144-L166 |
8,529 | praxisnetau/silverware-model-filters | src/Extensions/DataObjectExtension.php | DataObjectExtension.getStatusFlags | public function getStatusFlags()
{
// Initialise:
$flags = [];
// Is Extended Object Versioned?
if ($this->owner->hasExtension(Versioned::class)) {
if ($this->owner->isOnLiveOnly()) {
// Extended Object Removed from Draft:
$flags['removedfromdraft'] = array(
'text' => _t(__CLASS__ . '.ONLIVEONLYSHORT', 'On live only'),
'title' => _t(__CLASS__ . '.ONLIVEONLYSHORTHELP', 'Record is live, but removed from draft'),
);
} elseif ($this->owner->isArchived()) {
// Extended Object Archived:
$flags['archived'] = [
'text' => _t(__CLASS__ . '.ARCHIVEDSHORT', 'Archived'),
'title' => _t(__CLASS__ . '.ARCHIVEDHELP', 'Record is removed from draft and live')
];
} elseif ($this->owner->isOnDraftOnly()) {
// Extended Object Added to Draft:
$flags['addedtodraft'] = [
'text' => _t(__CLASS__ . '.ADDEDTODRAFTSHORT', 'Draft'),
'title' => _t(__CLASS__ . '.ADDEDTODRAFTHELP', 'Record has not been published yet')
];
} elseif ($this->owner->isModifiedOnDraft()) {
// Extended Object Modified on Draft:
$flags['modified'] = [
'text' => _t(__CLASS__ . '.MODIFIEDONDRAFTSHORT', 'Modified'),
'title' => _t(__CLASS__ . '.MODIFIEDONDRAFTHELP', 'Record has unpublished changes')
];
}
}
// Apply Extensions:
$this->owner->extend('updateStatusFlags', $flags);
// Answer Flags:
return $flags;
} | php | public function getStatusFlags()
{
// Initialise:
$flags = [];
// Is Extended Object Versioned?
if ($this->owner->hasExtension(Versioned::class)) {
if ($this->owner->isOnLiveOnly()) {
// Extended Object Removed from Draft:
$flags['removedfromdraft'] = array(
'text' => _t(__CLASS__ . '.ONLIVEONLYSHORT', 'On live only'),
'title' => _t(__CLASS__ . '.ONLIVEONLYSHORTHELP', 'Record is live, but removed from draft'),
);
} elseif ($this->owner->isArchived()) {
// Extended Object Archived:
$flags['archived'] = [
'text' => _t(__CLASS__ . '.ARCHIVEDSHORT', 'Archived'),
'title' => _t(__CLASS__ . '.ARCHIVEDHELP', 'Record is removed from draft and live')
];
} elseif ($this->owner->isOnDraftOnly()) {
// Extended Object Added to Draft:
$flags['addedtodraft'] = [
'text' => _t(__CLASS__ . '.ADDEDTODRAFTSHORT', 'Draft'),
'title' => _t(__CLASS__ . '.ADDEDTODRAFTHELP', 'Record has not been published yet')
];
} elseif ($this->owner->isModifiedOnDraft()) {
// Extended Object Modified on Draft:
$flags['modified'] = [
'text' => _t(__CLASS__ . '.MODIFIEDONDRAFTSHORT', 'Modified'),
'title' => _t(__CLASS__ . '.MODIFIEDONDRAFTHELP', 'Record has unpublished changes')
];
}
}
// Apply Extensions:
$this->owner->extend('updateStatusFlags', $flags);
// Answer Flags:
return $flags;
} | [
"public",
"function",
"getStatusFlags",
"(",
")",
"{",
"// Initialise:",
"$",
"flags",
"=",
"[",
"]",
";",
"// Is Extended Object Versioned?",
"if",
"(",
"$",
"this",
"->",
"owner",
"->",
"hasExtension",
"(",
"Versioned",
"::",
"class",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"owner",
"->",
"isOnLiveOnly",
"(",
")",
")",
"{",
"// Extended Object Removed from Draft:",
"$",
"flags",
"[",
"'removedfromdraft'",
"]",
"=",
"array",
"(",
"'text'",
"=>",
"_t",
"(",
"__CLASS__",
".",
"'.ONLIVEONLYSHORT'",
",",
"'On live only'",
")",
",",
"'title'",
"=>",
"_t",
"(",
"__CLASS__",
".",
"'.ONLIVEONLYSHORTHELP'",
",",
"'Record is live, but removed from draft'",
")",
",",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"owner",
"->",
"isArchived",
"(",
")",
")",
"{",
"// Extended Object Archived:",
"$",
"flags",
"[",
"'archived'",
"]",
"=",
"[",
"'text'",
"=>",
"_t",
"(",
"__CLASS__",
".",
"'.ARCHIVEDSHORT'",
",",
"'Archived'",
")",
",",
"'title'",
"=>",
"_t",
"(",
"__CLASS__",
".",
"'.ARCHIVEDHELP'",
",",
"'Record is removed from draft and live'",
")",
"]",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"owner",
"->",
"isOnDraftOnly",
"(",
")",
")",
"{",
"// Extended Object Added to Draft:",
"$",
"flags",
"[",
"'addedtodraft'",
"]",
"=",
"[",
"'text'",
"=>",
"_t",
"(",
"__CLASS__",
".",
"'.ADDEDTODRAFTSHORT'",
",",
"'Draft'",
")",
",",
"'title'",
"=>",
"_t",
"(",
"__CLASS__",
".",
"'.ADDEDTODRAFTHELP'",
",",
"'Record has not been published yet'",
")",
"]",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"owner",
"->",
"isModifiedOnDraft",
"(",
")",
")",
"{",
"// Extended Object Modified on Draft:",
"$",
"flags",
"[",
"'modified'",
"]",
"=",
"[",
"'text'",
"=>",
"_t",
"(",
"__CLASS__",
".",
"'.MODIFIEDONDRAFTSHORT'",
",",
"'Modified'",
")",
",",
"'title'",
"=>",
"_t",
"(",
"__CLASS__",
".",
"'.MODIFIEDONDRAFTHELP'",
",",
"'Record has unpublished changes'",
")",
"]",
";",
"}",
"}",
"// Apply Extensions:",
"$",
"this",
"->",
"owner",
"->",
"extend",
"(",
"'updateStatusFlags'",
",",
"$",
"flags",
")",
";",
"// Answer Flags:",
"return",
"$",
"flags",
";",
"}"
] | Answers an array of status flags for the extended object.
@return array | [
"Answers",
"an",
"array",
"of",
"status",
"flags",
"for",
"the",
"extended",
"object",
"."
] | 37165d492fcd6e7efc5b9c465bd21931e18ac5e2 | https://github.com/praxisnetau/silverware-model-filters/blob/37165d492fcd6e7efc5b9c465bd21931e18ac5e2/src/Extensions/DataObjectExtension.php#L41-L98 |
8,530 | praxisnetau/silverware-model-filters | src/Extensions/DataObjectExtension.php | DataObjectExtension.getStatusBadges | public function getStatusBadges()
{
// Initialise:
$badges = [];
// Iterate Status Flags:
foreach ($this->owner->getStatusFlags() as $class => $flag) {
$badges[] = sprintf(
'<span class="badge status-%s" title="%s">%s</span>',
Convert::raw2xml($class),
Convert::raw2xml($flag['title']),
Convert::raw2xml($flag['text'])
);
}
// Answer HTML Fragment:
return DBField::create_field('HTMLFragment', implode(' ', $badges));
} | php | public function getStatusBadges()
{
// Initialise:
$badges = [];
// Iterate Status Flags:
foreach ($this->owner->getStatusFlags() as $class => $flag) {
$badges[] = sprintf(
'<span class="badge status-%s" title="%s">%s</span>',
Convert::raw2xml($class),
Convert::raw2xml($flag['title']),
Convert::raw2xml($flag['text'])
);
}
// Answer HTML Fragment:
return DBField::create_field('HTMLFragment', implode(' ', $badges));
} | [
"public",
"function",
"getStatusBadges",
"(",
")",
"{",
"// Initialise:",
"$",
"badges",
"=",
"[",
"]",
";",
"// Iterate Status Flags:",
"foreach",
"(",
"$",
"this",
"->",
"owner",
"->",
"getStatusFlags",
"(",
")",
"as",
"$",
"class",
"=>",
"$",
"flag",
")",
"{",
"$",
"badges",
"[",
"]",
"=",
"sprintf",
"(",
"'<span class=\"badge status-%s\" title=\"%s\">%s</span>'",
",",
"Convert",
"::",
"raw2xml",
"(",
"$",
"class",
")",
",",
"Convert",
"::",
"raw2xml",
"(",
"$",
"flag",
"[",
"'title'",
"]",
")",
",",
"Convert",
"::",
"raw2xml",
"(",
"$",
"flag",
"[",
"'text'",
"]",
")",
")",
";",
"}",
"// Answer HTML Fragment:",
"return",
"DBField",
"::",
"create_field",
"(",
"'HTMLFragment'",
",",
"implode",
"(",
"' '",
",",
"$",
"badges",
")",
")",
";",
"}"
] | Answers a HTML fragment containing the status badges for the extended object.
@return DBHTMLText | [
"Answers",
"a",
"HTML",
"fragment",
"containing",
"the",
"status",
"badges",
"for",
"the",
"extended",
"object",
"."
] | 37165d492fcd6e7efc5b9c465bd21931e18ac5e2 | https://github.com/praxisnetau/silverware-model-filters/blob/37165d492fcd6e7efc5b9c465bd21931e18ac5e2/src/Extensions/DataObjectExtension.php#L105-L127 |
8,531 | Dhii/data-state-base | src/CreateCouldNotTransitionExceptionCapableTrait.php | CreateCouldNotTransitionExceptionCapableTrait._createCouldNotTransitionException | protected function _createCouldNotTransitionException(
$message = null,
$code = null,
RootException $previous = null,
$transitioner = null,
$subject = null,
$transition = null
) {
return new CouldNotTransitionException($message, $code, $previous, $transitioner, $subject, $transition);
} | php | protected function _createCouldNotTransitionException(
$message = null,
$code = null,
RootException $previous = null,
$transitioner = null,
$subject = null,
$transition = null
) {
return new CouldNotTransitionException($message, $code, $previous, $transitioner, $subject, $transition);
} | [
"protected",
"function",
"_createCouldNotTransitionException",
"(",
"$",
"message",
"=",
"null",
",",
"$",
"code",
"=",
"null",
",",
"RootException",
"$",
"previous",
"=",
"null",
",",
"$",
"transitioner",
"=",
"null",
",",
"$",
"subject",
"=",
"null",
",",
"$",
"transition",
"=",
"null",
")",
"{",
"return",
"new",
"CouldNotTransitionException",
"(",
"$",
"message",
",",
"$",
"code",
",",
"$",
"previous",
",",
"$",
"transitioner",
",",
"$",
"subject",
",",
"$",
"transition",
")",
";",
"}"
] | Creates a new exception for when a transitioner fails to transition.
@since [*next-version*]
@param string|Stringable|null $message The error message, if any.
@param int|null $code The error code, if any.
@param RootException|null $previous The previous exception for chaining, if any.
@param TransitionerInterface|null $transitioner The transitioner that erred, if any.
@param StateAwareInterface|null $subject The transition subject, if any.
@param string|Stringable|null $transition The transitioner that failed, if any.
@return CouldNotTransitionExceptionInterface The created exception. | [
"Creates",
"a",
"new",
"exception",
"for",
"when",
"a",
"transitioner",
"fails",
"to",
"transition",
"."
] | 762866374fc8c7cc482fd8a5d37520b14873be06 | https://github.com/Dhii/data-state-base/blob/762866374fc8c7cc482fd8a5d37520b14873be06/src/CreateCouldNotTransitionExceptionCapableTrait.php#L32-L41 |
8,532 | calgamo/util | src/MemoryUtil.php | MemoryUtil.convertSize | public static function convertSize( int $value, int $unit, int $precision = self::DEFAULT_PRECISION ) : float
{
switch ( $unit ){
case EnumMemoryUnit::UNIT_B:
return (float)$value;
case EnumMemoryUnit::UNIT_KB:
return round( ((float)$value) / self::BYTES_KB, $precision );
case EnumMemoryUnit::UNIT_MB:
return round( ((float)$value) / self::BYTES_MB, $precision );
case EnumMemoryUnit::UNIT_GB:
return round( ((float)$value) / self::BYTES_GB, $precision );
case EnumMemoryUnit::UNIT_TB:
return round( ((float)$value) / self::BYTES_TB, $precision );
}
return (float)$value;
} | php | public static function convertSize( int $value, int $unit, int $precision = self::DEFAULT_PRECISION ) : float
{
switch ( $unit ){
case EnumMemoryUnit::UNIT_B:
return (float)$value;
case EnumMemoryUnit::UNIT_KB:
return round( ((float)$value) / self::BYTES_KB, $precision );
case EnumMemoryUnit::UNIT_MB:
return round( ((float)$value) / self::BYTES_MB, $precision );
case EnumMemoryUnit::UNIT_GB:
return round( ((float)$value) / self::BYTES_GB, $precision );
case EnumMemoryUnit::UNIT_TB:
return round( ((float)$value) / self::BYTES_TB, $precision );
}
return (float)$value;
} | [
"public",
"static",
"function",
"convertSize",
"(",
"int",
"$",
"value",
",",
"int",
"$",
"unit",
",",
"int",
"$",
"precision",
"=",
"self",
"::",
"DEFAULT_PRECISION",
")",
":",
"float",
"{",
"switch",
"(",
"$",
"unit",
")",
"{",
"case",
"EnumMemoryUnit",
"::",
"UNIT_B",
":",
"return",
"(",
"float",
")",
"$",
"value",
";",
"case",
"EnumMemoryUnit",
"::",
"UNIT_KB",
":",
"return",
"round",
"(",
"(",
"(",
"float",
")",
"$",
"value",
")",
"/",
"self",
"::",
"BYTES_KB",
",",
"$",
"precision",
")",
";",
"case",
"EnumMemoryUnit",
"::",
"UNIT_MB",
":",
"return",
"round",
"(",
"(",
"(",
"float",
")",
"$",
"value",
")",
"/",
"self",
"::",
"BYTES_MB",
",",
"$",
"precision",
")",
";",
"case",
"EnumMemoryUnit",
"::",
"UNIT_GB",
":",
"return",
"round",
"(",
"(",
"(",
"float",
")",
"$",
"value",
")",
"/",
"self",
"::",
"BYTES_GB",
",",
"$",
"precision",
")",
";",
"case",
"EnumMemoryUnit",
"::",
"UNIT_TB",
":",
"return",
"round",
"(",
"(",
"(",
"float",
")",
"$",
"value",
")",
"/",
"self",
"::",
"BYTES_TB",
",",
"$",
"precision",
")",
";",
"}",
"return",
"(",
"float",
")",
"$",
"value",
";",
"}"
] | convert memory size
@param int $value memory size in bytes to be converted
@param int $unit memory unit to be converted
@param int $precision precision
@return float converted size | [
"convert",
"memory",
"size"
] | 13ef5caf3d4cce423854a0cb8fb8010c0d40326a | https://github.com/calgamo/util/blob/13ef5caf3d4cce423854a0cb8fb8010c0d40326a/src/MemoryUtil.php#L35-L50 |
8,533 | calgamo/util | src/MemoryUtil.php | MemoryUtil.getByteSizeFromString | public static function getByteSizeFromString( string $size_string ) : float
{
if ( ($pos=strpos($size_string,'TB')) > 0 ){
// TB
$number = substr($size_string,0,$pos);
if ( is_numeric($number) ){
return intval(self::BYTES_TB * $number);
}
}
else if ( ($pos=strpos($size_string,'GB')) > 0 ){
// GB
$number = substr($size_string,0,$pos);
if ( is_numeric($number) ){
return intval(self::BYTES_GB * $number);
}
}
else if ( ($pos=strpos($size_string,'MB')) > 0 ){
// MB
$number = substr($size_string,0,$pos);
if ( is_numeric($number) ){
return intval(self::BYTES_MB * $number);
}
}
else if ( ($pos=strpos($size_string,'KB')) > 0 ){
// KB
$number = substr($size_string,0,$pos);
if ( is_numeric($number) ){
return intval(self::BYTES_KB * $number);
}
}
else if ( ($pos=strpos($size_string,'B')) > 0 ){
// B
$number = substr($size_string,0,$pos);
if ( is_numeric($number) ){
return intval($number);
}
}
else if ( is_numeric($size_string) ){
return intval($size_string);
}
throw( new InvalidArgumentException(1,$size_string) );
} | php | public static function getByteSizeFromString( string $size_string ) : float
{
if ( ($pos=strpos($size_string,'TB')) > 0 ){
// TB
$number = substr($size_string,0,$pos);
if ( is_numeric($number) ){
return intval(self::BYTES_TB * $number);
}
}
else if ( ($pos=strpos($size_string,'GB')) > 0 ){
// GB
$number = substr($size_string,0,$pos);
if ( is_numeric($number) ){
return intval(self::BYTES_GB * $number);
}
}
else if ( ($pos=strpos($size_string,'MB')) > 0 ){
// MB
$number = substr($size_string,0,$pos);
if ( is_numeric($number) ){
return intval(self::BYTES_MB * $number);
}
}
else if ( ($pos=strpos($size_string,'KB')) > 0 ){
// KB
$number = substr($size_string,0,$pos);
if ( is_numeric($number) ){
return intval(self::BYTES_KB * $number);
}
}
else if ( ($pos=strpos($size_string,'B')) > 0 ){
// B
$number = substr($size_string,0,$pos);
if ( is_numeric($number) ){
return intval($number);
}
}
else if ( is_numeric($size_string) ){
return intval($size_string);
}
throw( new InvalidArgumentException(1,$size_string) );
} | [
"public",
"static",
"function",
"getByteSizeFromString",
"(",
"string",
"$",
"size_string",
")",
":",
"float",
"{",
"if",
"(",
"(",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"size_string",
",",
"'TB'",
")",
")",
">",
"0",
")",
"{",
"// TB",
"$",
"number",
"=",
"substr",
"(",
"$",
"size_string",
",",
"0",
",",
"$",
"pos",
")",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"number",
")",
")",
"{",
"return",
"intval",
"(",
"self",
"::",
"BYTES_TB",
"*",
"$",
"number",
")",
";",
"}",
"}",
"else",
"if",
"(",
"(",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"size_string",
",",
"'GB'",
")",
")",
">",
"0",
")",
"{",
"// GB",
"$",
"number",
"=",
"substr",
"(",
"$",
"size_string",
",",
"0",
",",
"$",
"pos",
")",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"number",
")",
")",
"{",
"return",
"intval",
"(",
"self",
"::",
"BYTES_GB",
"*",
"$",
"number",
")",
";",
"}",
"}",
"else",
"if",
"(",
"(",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"size_string",
",",
"'MB'",
")",
")",
">",
"0",
")",
"{",
"// MB",
"$",
"number",
"=",
"substr",
"(",
"$",
"size_string",
",",
"0",
",",
"$",
"pos",
")",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"number",
")",
")",
"{",
"return",
"intval",
"(",
"self",
"::",
"BYTES_MB",
"*",
"$",
"number",
")",
";",
"}",
"}",
"else",
"if",
"(",
"(",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"size_string",
",",
"'KB'",
")",
")",
">",
"0",
")",
"{",
"// KB",
"$",
"number",
"=",
"substr",
"(",
"$",
"size_string",
",",
"0",
",",
"$",
"pos",
")",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"number",
")",
")",
"{",
"return",
"intval",
"(",
"self",
"::",
"BYTES_KB",
"*",
"$",
"number",
")",
";",
"}",
"}",
"else",
"if",
"(",
"(",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"size_string",
",",
"'B'",
")",
")",
">",
"0",
")",
"{",
"// B",
"$",
"number",
"=",
"substr",
"(",
"$",
"size_string",
",",
"0",
",",
"$",
"pos",
")",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"number",
")",
")",
"{",
"return",
"intval",
"(",
"$",
"number",
")",
";",
"}",
"}",
"else",
"if",
"(",
"is_numeric",
"(",
"$",
"size_string",
")",
")",
"{",
"return",
"intval",
"(",
"$",
"size_string",
")",
";",
"}",
"throw",
"(",
"new",
"InvalidArgumentException",
"(",
"1",
",",
"$",
"size_string",
")",
")",
";",
"}"
] | get byte size from string
@param string $size_string string expression of byte size. ex) 2MB, 100KB, 3.5GB
@return float size in bytes
@throws InvalidArgumentException | [
"get",
"byte",
"size",
"from",
"string"
] | 13ef5caf3d4cce423854a0cb8fb8010c0d40326a | https://github.com/calgamo/util/blob/13ef5caf3d4cce423854a0cb8fb8010c0d40326a/src/MemoryUtil.php#L61-L103 |
8,534 | samsonos/cms_app_material | src/FormTab.php | FormTab.header | public function header()
{
// If we have tab content
if (isset($this->content_html{0})) {
// Tab sub-headers html
$sub_headers = '';
// Iterate tab group tabs only if there is atleast two sub headers
if (sizeof($this->tabs) > 2) {
foreach ($this->tabs as $tab) {
// Don't render this tab as sub header
if ($tab == $this) continue;
// Render tab header as sub-header
$sub_headers .= m()->view($this->header_view)->tab($tab)->output();
}
}
// Render just last tab
$this->header_html .= m()
->view($this->header_view)
->sub_headers($sub_headers)
->class(isset($sub_headers{0}) ? 'sub-tabs-list' : '')
->tab($this)// Pass this tab object as main
->tab_id(end($this->tabs)->id)// Pass last tabs object id as identifier
->output();
}
return $this->header_html;
} | php | public function header()
{
// If we have tab content
if (isset($this->content_html{0})) {
// Tab sub-headers html
$sub_headers = '';
// Iterate tab group tabs only if there is atleast two sub headers
if (sizeof($this->tabs) > 2) {
foreach ($this->tabs as $tab) {
// Don't render this tab as sub header
if ($tab == $this) continue;
// Render tab header as sub-header
$sub_headers .= m()->view($this->header_view)->tab($tab)->output();
}
}
// Render just last tab
$this->header_html .= m()
->view($this->header_view)
->sub_headers($sub_headers)
->class(isset($sub_headers{0}) ? 'sub-tabs-list' : '')
->tab($this)// Pass this tab object as main
->tab_id(end($this->tabs)->id)// Pass last tabs object id as identifier
->output();
}
return $this->header_html;
} | [
"public",
"function",
"header",
"(",
")",
"{",
"// If we have tab content",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"content_html",
"{",
"0",
"}",
")",
")",
"{",
"// Tab sub-headers html",
"$",
"sub_headers",
"=",
"''",
";",
"// Iterate tab group tabs only if there is atleast two sub headers",
"if",
"(",
"sizeof",
"(",
"$",
"this",
"->",
"tabs",
")",
">",
"2",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"tabs",
"as",
"$",
"tab",
")",
"{",
"// Don't render this tab as sub header",
"if",
"(",
"$",
"tab",
"==",
"$",
"this",
")",
"continue",
";",
"// Render tab header as sub-header",
"$",
"sub_headers",
".=",
"m",
"(",
")",
"->",
"view",
"(",
"$",
"this",
"->",
"header_view",
")",
"->",
"tab",
"(",
"$",
"tab",
")",
"->",
"output",
"(",
")",
";",
"}",
"}",
"// Render just last tab",
"$",
"this",
"->",
"header_html",
".=",
"m",
"(",
")",
"->",
"view",
"(",
"$",
"this",
"->",
"header_view",
")",
"->",
"sub_headers",
"(",
"$",
"sub_headers",
")",
"->",
"class",
"(",
"isset",
"(",
"$",
"sub_headers",
"{",
"0",
"}",
")",
"?",
"'sub-tabs-list'",
":",
"''",
")",
"->",
"tab",
"(",
"$",
"this",
")",
"// Pass this tab object as main",
"->",
"tab_id",
"(",
"end",
"(",
"$",
"this",
"->",
"tabs",
")",
"->",
"id",
")",
"// Pass last tabs object id as identifier",
"->",
"output",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"header_html",
";",
"}"
] | Render HTML tab header part
@return string HTML tab header part | [
"Render",
"HTML",
"tab",
"header",
"part"
] | 24d8f8ce8dec68b18cd1e941c6b57a23501aa8c1 | https://github.com/samsonos/cms_app_material/blob/24d8f8ce8dec68b18cd1e941c6b57a23501aa8c1/src/FormTab.php#L90-L119 |
8,535 | samsonos/cms_app_material | src/FormTab.php | FormTab.control | public function control()
{
// If we have tab content
//if( isset($tab->content_html{0}))
{
// Iterate tab group tabs
foreach ($this->tabs as $tab) $this->control_html .= m()->view($this->control_view)->tab($tab)->output();
}
return $this->control_html;
} | php | public function control()
{
// If we have tab content
//if( isset($tab->content_html{0}))
{
// Iterate tab group tabs
foreach ($this->tabs as $tab) $this->control_html .= m()->view($this->control_view)->tab($tab)->output();
}
return $this->control_html;
} | [
"public",
"function",
"control",
"(",
")",
"{",
"// If we have tab content",
"//if( isset($tab->content_html{0}))",
"{",
"// Iterate tab group tabs",
"foreach",
"(",
"$",
"this",
"->",
"tabs",
"as",
"$",
"tab",
")",
"$",
"this",
"->",
"control_html",
".=",
"m",
"(",
")",
"->",
"view",
"(",
"$",
"this",
"->",
"control_view",
")",
"->",
"tab",
"(",
"$",
"tab",
")",
"->",
"output",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"control_html",
";",
"}"
] | Render HTML tab colntrols part
@return string HTML tab buttons part | [
"Render",
"HTML",
"tab",
"colntrols",
"part"
] | 24d8f8ce8dec68b18cd1e941c6b57a23501aa8c1 | https://github.com/samsonos/cms_app_material/blob/24d8f8ce8dec68b18cd1e941c6b57a23501aa8c1/src/FormTab.php#L157-L166 |
8,536 | BapCat/Hashing | src/Hasher.php | Hasher.salt | public function salt(int $length = 32): string {
try {
return random_bytes($length);
} catch(Exception $e) {
throw new RuntimeException('Could not generate crytographically secure salt', 0, $e);
}
} | php | public function salt(int $length = 32): string {
try {
return random_bytes($length);
} catch(Exception $e) {
throw new RuntimeException('Could not generate crytographically secure salt', 0, $e);
}
} | [
"public",
"function",
"salt",
"(",
"int",
"$",
"length",
"=",
"32",
")",
":",
"string",
"{",
"try",
"{",
"return",
"random_bytes",
"(",
"$",
"length",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Could not generate crytographically secure salt'",
",",
"0",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Generate a cryptographically secure salt
@param int $length (optional) The length of the salt
@return string A string of cryptographically random bytes of `$length` length | [
"Generate",
"a",
"cryptographically",
"secure",
"salt"
] | cf61f3e8c4bc25232507a2873d08bd78e3917e26 | https://github.com/BapCat/Hashing/blob/cf61f3e8c4bc25232507a2873d08bd78e3917e26/src/Hasher.php#L47-L53 |
8,537 | AkinaySau/library | src/Theme.php | Theme.loadThemeTextdomain | public static function loadThemeTextdomain( $domain, $path ) {
$callback = function () use ( &$domain, &$path ) {
load_theme_textdomain( $domain, $path );
};
Action::afterSetupTheme( $callback );
} | php | public static function loadThemeTextdomain( $domain, $path ) {
$callback = function () use ( &$domain, &$path ) {
load_theme_textdomain( $domain, $path );
};
Action::afterSetupTheme( $callback );
} | [
"public",
"static",
"function",
"loadThemeTextdomain",
"(",
"$",
"domain",
",",
"$",
"path",
")",
"{",
"$",
"callback",
"=",
"function",
"(",
")",
"use",
"(",
"&",
"$",
"domain",
",",
"&",
"$",
"path",
")",
"{",
"load_theme_textdomain",
"(",
"$",
"domain",
",",
"$",
"path",
")",
";",
"}",
";",
"Action",
"::",
"afterSetupTheme",
"(",
"$",
"callback",
")",
";",
"}"
] | Register theme language
@param string $domain Text domain. Unique identifier for retrieving
translated strings.
@param string $path Optional. Path to the directory containing the .mo
file. Default false.
@return void | [
"Register",
"theme",
"language"
] | 91848097914fed0cb0ef638852e5ba214c6e7c8b | https://github.com/AkinaySau/library/blob/91848097914fed0cb0ef638852e5ba214c6e7c8b/src/Theme.php#L25-L30 |
8,538 | inceddy/ieu_http | src/ieu/Http/Response.php | Response.setStatusCode | public function setStatusCode($code)
{
if (!array_key_exists($code, self::$statusCodeMap)) {
throw new InvalidArgumentException(sprintf('The HTTP stauts code %s is unknown.', $code));
}
$this->statusCode = $code;
return $this;
} | php | public function setStatusCode($code)
{
if (!array_key_exists($code, self::$statusCodeMap)) {
throw new InvalidArgumentException(sprintf('The HTTP stauts code %s is unknown.', $code));
}
$this->statusCode = $code;
return $this;
} | [
"public",
"function",
"setStatusCode",
"(",
"$",
"code",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"code",
",",
"self",
"::",
"$",
"statusCodeMap",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The HTTP stauts code %s is unknown.'",
",",
"$",
"code",
")",
")",
";",
"}",
"$",
"this",
"->",
"statusCode",
"=",
"$",
"code",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the HTTP status code
@param integer $code The status code
@return self | [
"Sets",
"the",
"HTTP",
"status",
"code"
] | 4c9b097ee1e31ca45acfb79a855462d78b5c979c | https://github.com/inceddy/ieu_http/blob/4c9b097ee1e31ca45acfb79a855462d78b5c979c/src/ieu/Http/Response.php#L229-L238 |
8,539 | inceddy/ieu_http | src/ieu/Http/Response.php | Response.setProtocolVersion | public function setProtocolVersion($version)
{
if (!array_key_exists($version, self::$protocolVersionMap)) {
throw new InvalidArgumentException(sprintf('The HTTP protkoll version %s is unknown', $version));
}
$this->protocolVersion = $version;
return $this;
} | php | public function setProtocolVersion($version)
{
if (!array_key_exists($version, self::$protocolVersionMap)) {
throw new InvalidArgumentException(sprintf('The HTTP protkoll version %s is unknown', $version));
}
$this->protocolVersion = $version;
return $this;
} | [
"public",
"function",
"setProtocolVersion",
"(",
"$",
"version",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"version",
",",
"self",
"::",
"$",
"protocolVersionMap",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The HTTP protkoll version %s is unknown'",
",",
"$",
"version",
")",
")",
";",
"}",
"$",
"this",
"->",
"protocolVersion",
"=",
"$",
"version",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the HTTP protocol version
@param string $version The protocol version
@return self | [
"Sets",
"the",
"HTTP",
"protocol",
"version"
] | 4c9b097ee1e31ca45acfb79a855462d78b5c979c | https://github.com/inceddy/ieu_http/blob/4c9b097ee1e31ca45acfb79a855462d78b5c979c/src/ieu/Http/Response.php#L276-L285 |
8,540 | inceddy/ieu_http | src/ieu/Http/Response.php | Response.setHeaders | public function setHeaders(array $headers)
{
foreach ($headers as $key => $header) {
$this->setHeader($key, $header);
}
return $this;
} | php | public function setHeaders(array $headers)
{
foreach ($headers as $key => $header) {
$this->setHeader($key, $header);
}
return $this;
} | [
"public",
"function",
"setHeaders",
"(",
"array",
"$",
"headers",
")",
"{",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"key",
"=>",
"$",
"header",
")",
"{",
"$",
"this",
"->",
"setHeader",
"(",
"$",
"key",
",",
"$",
"header",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets an array of multiple headers.
@param array $headers The header name-value-pairs
@return self | [
"Sets",
"an",
"array",
"of",
"multiple",
"headers",
"."
] | 4c9b097ee1e31ca45acfb79a855462d78b5c979c | https://github.com/inceddy/ieu_http/blob/4c9b097ee1e31ca45acfb79a855462d78b5c979c/src/ieu/Http/Response.php#L341-L348 |
8,541 | inceddy/ieu_http | src/ieu/Http/Response.php | Response.sendHeaders | public function sendHeaders()
{
// Early return if headers already have been send
if (headers_sent()) {
return $this;
}
foreach ($this->headers as $key => $value) {
header(
sprintf('%s: %s', $key, is_array($value) ? implode('; ', $value) : $value),
true,
$this->statusCode
);
}
header(sprintf('%s %s %s',
self::$protocolVersionMap[$this->protocolVersion],
$this->statusCode,
self::$statusCodeMap[$this->statusCode]
));
return $this;
} | php | public function sendHeaders()
{
// Early return if headers already have been send
if (headers_sent()) {
return $this;
}
foreach ($this->headers as $key => $value) {
header(
sprintf('%s: %s', $key, is_array($value) ? implode('; ', $value) : $value),
true,
$this->statusCode
);
}
header(sprintf('%s %s %s',
self::$protocolVersionMap[$this->protocolVersion],
$this->statusCode,
self::$statusCodeMap[$this->statusCode]
));
return $this;
} | [
"public",
"function",
"sendHeaders",
"(",
")",
"{",
"// Early return if headers already have been send\r",
"if",
"(",
"headers_sent",
"(",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"headers",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"header",
"(",
"sprintf",
"(",
"'%s: %s'",
",",
"$",
"key",
",",
"is_array",
"(",
"$",
"value",
")",
"?",
"implode",
"(",
"'; '",
",",
"$",
"value",
")",
":",
"$",
"value",
")",
",",
"true",
",",
"$",
"this",
"->",
"statusCode",
")",
";",
"}",
"header",
"(",
"sprintf",
"(",
"'%s %s %s'",
",",
"self",
"::",
"$",
"protocolVersionMap",
"[",
"$",
"this",
"->",
"protocolVersion",
"]",
",",
"$",
"this",
"->",
"statusCode",
",",
"self",
"::",
"$",
"statusCodeMap",
"[",
"$",
"this",
"->",
"statusCode",
"]",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Sends the response headers to the client
if headers have not been send yet.
@return self | [
"Sends",
"the",
"response",
"headers",
"to",
"the",
"client",
"if",
"headers",
"have",
"not",
"been",
"send",
"yet",
"."
] | 4c9b097ee1e31ca45acfb79a855462d78b5c979c | https://github.com/inceddy/ieu_http/blob/4c9b097ee1e31ca45acfb79a855462d78b5c979c/src/ieu/Http/Response.php#L376-L398 |
8,542 | samurai-fw/samurai | src/Samurai/Component/Task/Option.php | Option.importFromArray | public function importFromArray(array $options)
{
foreach ($options as $key => $value) {
switch (true) {
case $key === 'args':
$this->args = $value;
break;
case is_integer($key):
$this->args[] = $value;
break;
default:
$this->options[$key] = $value;
break;
}
}
} | php | public function importFromArray(array $options)
{
foreach ($options as $key => $value) {
switch (true) {
case $key === 'args':
$this->args = $value;
break;
case is_integer($key):
$this->args[] = $value;
break;
default:
$this->options[$key] = $value;
break;
}
}
} | [
"public",
"function",
"importFromArray",
"(",
"array",
"$",
"options",
")",
"{",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"switch",
"(",
"true",
")",
"{",
"case",
"$",
"key",
"===",
"'args'",
":",
"$",
"this",
"->",
"args",
"=",
"$",
"value",
";",
"break",
";",
"case",
"is_integer",
"(",
"$",
"key",
")",
":",
"$",
"this",
"->",
"args",
"[",
"]",
"=",
"$",
"value",
";",
"break",
";",
"default",
":",
"$",
"this",
"->",
"options",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"break",
";",
"}",
"}",
"}"
] | import from array
@param array $options | [
"import",
"from",
"array"
] | 7ca3847b13f86e2847a17ab5e8e4e20893021d5a | https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/Task/Option.php#L108-L123 |
8,543 | samurai-fw/samurai | src/Samurai/Component/Task/Option.php | Option.get | public function get($key, $default = null)
{
if (array_key_exists($key, $this->options)) return $this->valuelize($this->options[$key]);
foreach ($this->getDefinitions() as $define) {
// when short option
if ($key === $define->getShortName()) {
if (array_key_exists($define->getName(), $this->options)) return $this->valuelize($this->options[$define->getName()]);
return $this->valuelize($define->getDefault());
}
// when long option
if ($key === $define->getName()) {
if (array_key_exists($define->getShortName(), $this->options)) return $this->valuelize($this->options[$define->getShortName()]);
return $this->valuelize($define->getDefault());
}
}
return $this->valuelize($default);
} | php | public function get($key, $default = null)
{
if (array_key_exists($key, $this->options)) return $this->valuelize($this->options[$key]);
foreach ($this->getDefinitions() as $define) {
// when short option
if ($key === $define->getShortName()) {
if (array_key_exists($define->getName(), $this->options)) return $this->valuelize($this->options[$define->getName()]);
return $this->valuelize($define->getDefault());
}
// when long option
if ($key === $define->getName()) {
if (array_key_exists($define->getShortName(), $this->options)) return $this->valuelize($this->options[$define->getShortName()]);
return $this->valuelize($define->getDefault());
}
}
return $this->valuelize($default);
} | [
"public",
"function",
"get",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"options",
")",
")",
"return",
"$",
"this",
"->",
"valuelize",
"(",
"$",
"this",
"->",
"options",
"[",
"$",
"key",
"]",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getDefinitions",
"(",
")",
"as",
"$",
"define",
")",
"{",
"// when short option",
"if",
"(",
"$",
"key",
"===",
"$",
"define",
"->",
"getShortName",
"(",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"define",
"->",
"getName",
"(",
")",
",",
"$",
"this",
"->",
"options",
")",
")",
"return",
"$",
"this",
"->",
"valuelize",
"(",
"$",
"this",
"->",
"options",
"[",
"$",
"define",
"->",
"getName",
"(",
")",
"]",
")",
";",
"return",
"$",
"this",
"->",
"valuelize",
"(",
"$",
"define",
"->",
"getDefault",
"(",
")",
")",
";",
"}",
"// when long option",
"if",
"(",
"$",
"key",
"===",
"$",
"define",
"->",
"getName",
"(",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"define",
"->",
"getShortName",
"(",
")",
",",
"$",
"this",
"->",
"options",
")",
")",
"return",
"$",
"this",
"->",
"valuelize",
"(",
"$",
"this",
"->",
"options",
"[",
"$",
"define",
"->",
"getShortName",
"(",
")",
"]",
")",
";",
"return",
"$",
"this",
"->",
"valuelize",
"(",
"$",
"define",
"->",
"getDefault",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"valuelize",
"(",
"$",
"default",
")",
";",
"}"
] | get a option.
@param string $key
@return mixed | [
"get",
"a",
"option",
"."
] | 7ca3847b13f86e2847a17ab5e8e4e20893021d5a | https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/Task/Option.php#L177-L195 |
8,544 | ekyna/InstallBundle | Install/Loader.php | Loader.loadFromDirectory | public function loadFromDirectory($dir)
{
if (!is_dir($dir)) {
throw new \InvalidArgumentException(sprintf('"%s" does not exist', $dir));
}
$installers = [];
$includedFiles = [];
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($dir),
\RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($iterator as $file) {
if (($fileName = $file->getBasename($this->fileExtension)) == $file->getBasename()) {
continue;
}
$sourceFile = realpath($file->getPathName());
require_once $sourceFile;
$includedFiles[] = $sourceFile;
}
$declared = get_declared_classes();
foreach ($declared as $className) {
$refClass = new \ReflectionClass($className);
$sourceFile = $refClass->getFileName();
if (in_array($sourceFile, $includedFiles) && !$this->isTransient($className)) {
$installer = new $className;
$installers[] = $installer;
$this->addInstaller($installer);
}
}
return $installers;
} | php | public function loadFromDirectory($dir)
{
if (!is_dir($dir)) {
throw new \InvalidArgumentException(sprintf('"%s" does not exist', $dir));
}
$installers = [];
$includedFiles = [];
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($dir),
\RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($iterator as $file) {
if (($fileName = $file->getBasename($this->fileExtension)) == $file->getBasename()) {
continue;
}
$sourceFile = realpath($file->getPathName());
require_once $sourceFile;
$includedFiles[] = $sourceFile;
}
$declared = get_declared_classes();
foreach ($declared as $className) {
$refClass = new \ReflectionClass($className);
$sourceFile = $refClass->getFileName();
if (in_array($sourceFile, $includedFiles) && !$this->isTransient($className)) {
$installer = new $className;
$installers[] = $installer;
$this->addInstaller($installer);
}
}
return $installers;
} | [
"public",
"function",
"loadFromDirectory",
"(",
"$",
"dir",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'\"%s\" does not exist'",
",",
"$",
"dir",
")",
")",
";",
"}",
"$",
"installers",
"=",
"[",
"]",
";",
"$",
"includedFiles",
"=",
"[",
"]",
";",
"$",
"iterator",
"=",
"new",
"\\",
"RecursiveIteratorIterator",
"(",
"new",
"\\",
"RecursiveDirectoryIterator",
"(",
"$",
"dir",
")",
",",
"\\",
"RecursiveIteratorIterator",
"::",
"LEAVES_ONLY",
")",
";",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"(",
"$",
"fileName",
"=",
"$",
"file",
"->",
"getBasename",
"(",
"$",
"this",
"->",
"fileExtension",
")",
")",
"==",
"$",
"file",
"->",
"getBasename",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"sourceFile",
"=",
"realpath",
"(",
"$",
"file",
"->",
"getPathName",
"(",
")",
")",
";",
"require_once",
"$",
"sourceFile",
";",
"$",
"includedFiles",
"[",
"]",
"=",
"$",
"sourceFile",
";",
"}",
"$",
"declared",
"=",
"get_declared_classes",
"(",
")",
";",
"foreach",
"(",
"$",
"declared",
"as",
"$",
"className",
")",
"{",
"$",
"refClass",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"$",
"sourceFile",
"=",
"$",
"refClass",
"->",
"getFileName",
"(",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"sourceFile",
",",
"$",
"includedFiles",
")",
"&&",
"!",
"$",
"this",
"->",
"isTransient",
"(",
"$",
"className",
")",
")",
"{",
"$",
"installer",
"=",
"new",
"$",
"className",
";",
"$",
"installers",
"[",
"]",
"=",
"$",
"installer",
";",
"$",
"this",
"->",
"addInstaller",
"(",
"$",
"installer",
")",
";",
"}",
"}",
"return",
"$",
"installers",
";",
"}"
] | Finds installer classes in a given directory and load them.
@param string $dir Directory to find installer classes in.
@return array $installers Array of loaded installer object instances. | [
"Finds",
"installer",
"classes",
"in",
"a",
"given",
"directory",
"and",
"load",
"them",
"."
] | f29b68f21cb3d846d287d92b0c6c507a6b052491 | https://github.com/ekyna/InstallBundle/blob/f29b68f21cb3d846d287d92b0c6c507a6b052491/Install/Loader.php#L54-L90 |
8,545 | ekyna/InstallBundle | Install/Loader.php | Loader.addInstaller | public function addInstaller(InstallerInterface $installer)
{
$installerClass = get_class($installer);
if (!isset($this->installers[$installerClass])) {
if ($installer instanceof OrderedInstallerInterface && $installer instanceof DependentInstallerInterface) {
throw new \InvalidArgumentException(sprintf('Class "%s" can\'t implement "%s" and "%s" at the same time.',
$installerClass,
'OrderedInstallerInterface',
'DependentInstallerInterface'));
} elseif ($installer instanceof OrderedInstallerInterface) {
$this->orderInstallersByNumber = true;
} elseif ($installer instanceof DependentInstallerInterface) {
$this->orderInstallersByDependencies = true;
foreach ($installer->getDependencies() as $class) {
$this->addInstaller(new $class);
}
}
$this->installers[$installerClass] = $installer;
}
} | php | public function addInstaller(InstallerInterface $installer)
{
$installerClass = get_class($installer);
if (!isset($this->installers[$installerClass])) {
if ($installer instanceof OrderedInstallerInterface && $installer instanceof DependentInstallerInterface) {
throw new \InvalidArgumentException(sprintf('Class "%s" can\'t implement "%s" and "%s" at the same time.',
$installerClass,
'OrderedInstallerInterface',
'DependentInstallerInterface'));
} elseif ($installer instanceof OrderedInstallerInterface) {
$this->orderInstallersByNumber = true;
} elseif ($installer instanceof DependentInstallerInterface) {
$this->orderInstallersByDependencies = true;
foreach ($installer->getDependencies() as $class) {
$this->addInstaller(new $class);
}
}
$this->installers[$installerClass] = $installer;
}
} | [
"public",
"function",
"addInstaller",
"(",
"InstallerInterface",
"$",
"installer",
")",
"{",
"$",
"installerClass",
"=",
"get_class",
"(",
"$",
"installer",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"installers",
"[",
"$",
"installerClass",
"]",
")",
")",
"{",
"if",
"(",
"$",
"installer",
"instanceof",
"OrderedInstallerInterface",
"&&",
"$",
"installer",
"instanceof",
"DependentInstallerInterface",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Class \"%s\" can\\'t implement \"%s\" and \"%s\" at the same time.'",
",",
"$",
"installerClass",
",",
"'OrderedInstallerInterface'",
",",
"'DependentInstallerInterface'",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"installer",
"instanceof",
"OrderedInstallerInterface",
")",
"{",
"$",
"this",
"->",
"orderInstallersByNumber",
"=",
"true",
";",
"}",
"elseif",
"(",
"$",
"installer",
"instanceof",
"DependentInstallerInterface",
")",
"{",
"$",
"this",
"->",
"orderInstallersByDependencies",
"=",
"true",
";",
"foreach",
"(",
"$",
"installer",
"->",
"getDependencies",
"(",
")",
"as",
"$",
"class",
")",
"{",
"$",
"this",
"->",
"addInstaller",
"(",
"new",
"$",
"class",
")",
";",
"}",
"}",
"$",
"this",
"->",
"installers",
"[",
"$",
"installerClass",
"]",
"=",
"$",
"installer",
";",
"}",
"}"
] | Adds the installer object instance to the loader.
@param InstallerInterface $installer | [
"Adds",
"the",
"installer",
"object",
"instance",
"to",
"the",
"loader",
"."
] | f29b68f21cb3d846d287d92b0c6c507a6b052491 | https://github.com/ekyna/InstallBundle/blob/f29b68f21cb3d846d287d92b0c6c507a6b052491/Install/Loader.php#L112-L133 |
8,546 | ekyna/InstallBundle | Install/Loader.php | Loader.getInstallers | public function getInstallers()
{
$this->orderedInstallers = [];
if ($this->orderInstallersByNumber) {
$this->orderInstallersByNumber();
}
if ($this->orderInstallersByDependencies) {
$this->orderInstallersByDependencies();
}
if (!$this->orderInstallersByNumber && !$this->orderInstallersByDependencies) {
$this->orderedInstallers = $this->installers;
}
return $this->orderedInstallers;
} | php | public function getInstallers()
{
$this->orderedInstallers = [];
if ($this->orderInstallersByNumber) {
$this->orderInstallersByNumber();
}
if ($this->orderInstallersByDependencies) {
$this->orderInstallersByDependencies();
}
if (!$this->orderInstallersByNumber && !$this->orderInstallersByDependencies) {
$this->orderedInstallers = $this->installers;
}
return $this->orderedInstallers;
} | [
"public",
"function",
"getInstallers",
"(",
")",
"{",
"$",
"this",
"->",
"orderedInstallers",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"orderInstallersByNumber",
")",
"{",
"$",
"this",
"->",
"orderInstallersByNumber",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"orderInstallersByDependencies",
")",
"{",
"$",
"this",
"->",
"orderInstallersByDependencies",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"orderInstallersByNumber",
"&&",
"!",
"$",
"this",
"->",
"orderInstallersByDependencies",
")",
"{",
"$",
"this",
"->",
"orderedInstallers",
"=",
"$",
"this",
"->",
"installers",
";",
"}",
"return",
"$",
"this",
"->",
"orderedInstallers",
";",
"}"
] | Returns the array of data installers to execute.
@return array|InstallerInterface[] $installers | [
"Returns",
"the",
"array",
"of",
"data",
"installers",
"to",
"execute",
"."
] | f29b68f21cb3d846d287d92b0c6c507a6b052491 | https://github.com/ekyna/InstallBundle/blob/f29b68f21cb3d846d287d92b0c6c507a6b052491/Install/Loader.php#L140-L157 |
8,547 | ekyna/InstallBundle | Install/Loader.php | Loader.orderInstallersByNumber | private function orderInstallersByNumber()
{
$this->orderedInstallers = $this->installers;
usort($this->orderedInstallers, function ($a, $b) {
if ($a instanceof OrderedInstallerInterface && $b instanceof OrderedInstallerInterface) {
if ($a->getOrder() === $b->getOrder()) {
return 0;
}
return $a->getOrder() < $b->getOrder() ? -1 : 1;
} elseif ($a instanceof OrderedInstallerInterface) {
return $a->getOrder() === 0 ? 0 : 1;
} elseif ($b instanceof OrderedInstallerInterface) {
return $b->getOrder() === 0 ? 0 : -1;
}
return 0;
});
} | php | private function orderInstallersByNumber()
{
$this->orderedInstallers = $this->installers;
usort($this->orderedInstallers, function ($a, $b) {
if ($a instanceof OrderedInstallerInterface && $b instanceof OrderedInstallerInterface) {
if ($a->getOrder() === $b->getOrder()) {
return 0;
}
return $a->getOrder() < $b->getOrder() ? -1 : 1;
} elseif ($a instanceof OrderedInstallerInterface) {
return $a->getOrder() === 0 ? 0 : 1;
} elseif ($b instanceof OrderedInstallerInterface) {
return $b->getOrder() === 0 ? 0 : -1;
}
return 0;
});
} | [
"private",
"function",
"orderInstallersByNumber",
"(",
")",
"{",
"$",
"this",
"->",
"orderedInstallers",
"=",
"$",
"this",
"->",
"installers",
";",
"usort",
"(",
"$",
"this",
"->",
"orderedInstallers",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"if",
"(",
"$",
"a",
"instanceof",
"OrderedInstallerInterface",
"&&",
"$",
"b",
"instanceof",
"OrderedInstallerInterface",
")",
"{",
"if",
"(",
"$",
"a",
"->",
"getOrder",
"(",
")",
"===",
"$",
"b",
"->",
"getOrder",
"(",
")",
")",
"{",
"return",
"0",
";",
"}",
"return",
"$",
"a",
"->",
"getOrder",
"(",
")",
"<",
"$",
"b",
"->",
"getOrder",
"(",
")",
"?",
"-",
"1",
":",
"1",
";",
"}",
"elseif",
"(",
"$",
"a",
"instanceof",
"OrderedInstallerInterface",
")",
"{",
"return",
"$",
"a",
"->",
"getOrder",
"(",
")",
"===",
"0",
"?",
"0",
":",
"1",
";",
"}",
"elseif",
"(",
"$",
"b",
"instanceof",
"OrderedInstallerInterface",
")",
"{",
"return",
"$",
"b",
"->",
"getOrder",
"(",
")",
"===",
"0",
"?",
"0",
":",
"-",
"1",
";",
"}",
"return",
"0",
";",
"}",
")",
";",
"}"
] | Orders installers by number
@todo maybe there is a better way to handle reordering
@return void | [
"Orders",
"installers",
"by",
"number"
] | f29b68f21cb3d846d287d92b0c6c507a6b052491 | https://github.com/ekyna/InstallBundle/blob/f29b68f21cb3d846d287d92b0c6c507a6b052491/Install/Loader.php#L165-L181 |
8,548 | smeeckaert/di | src/DI/Decorator/Immutable.php | Immutable.forward | protected function forward($callback, $method, $params = [])
{
if ($this->isLoaded()) {
if (!$this->soft) {
$oldInstance = clone $this->instance;
}
$return = $callback();
if (!$this->soft && $oldInstance != $this->instance) {
$this->instance = $oldInstance;
$this->throwImmutableException();
}
return $return;
} else {
return parent::$method($params);
}
} | php | protected function forward($callback, $method, $params = [])
{
if ($this->isLoaded()) {
if (!$this->soft) {
$oldInstance = clone $this->instance;
}
$return = $callback();
if (!$this->soft && $oldInstance != $this->instance) {
$this->instance = $oldInstance;
$this->throwImmutableException();
}
return $return;
} else {
return parent::$method($params);
}
} | [
"protected",
"function",
"forward",
"(",
"$",
"callback",
",",
"$",
"method",
",",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isLoaded",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"soft",
")",
"{",
"$",
"oldInstance",
"=",
"clone",
"$",
"this",
"->",
"instance",
";",
"}",
"$",
"return",
"=",
"$",
"callback",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"soft",
"&&",
"$",
"oldInstance",
"!=",
"$",
"this",
"->",
"instance",
")",
"{",
"$",
"this",
"->",
"instance",
"=",
"$",
"oldInstance",
";",
"$",
"this",
"->",
"throwImmutableException",
"(",
")",
";",
"}",
"return",
"$",
"return",
";",
"}",
"else",
"{",
"return",
"parent",
"::",
"$",
"method",
"(",
"$",
"params",
")",
";",
"}",
"}"
] | If the object is loaded, call the callback, otherwise we call the parent method
@param $callback
@param $method
@param array $params
@return mixed | [
"If",
"the",
"object",
"is",
"loaded",
"call",
"the",
"callback",
"otherwise",
"we",
"call",
"the",
"parent",
"method"
] | 3d5e3ed20038bed9a42fcd2821970f77112b8d3c | https://github.com/smeeckaert/di/blob/3d5e3ed20038bed9a42fcd2821970f77112b8d3c/src/DI/Decorator/Immutable.php#L39-L54 |
8,549 | etcinit/tutum-php | src/Chromabits/TutumClient/Entities/Container.php | Container.findLinks | public function findLinks($serviceName, $tcpPorts = [], $udpPorts = [])
{
// First match names
$matching = [];
$encodedName = $this->encodeServiceName($serviceName);
$regex = '/^' . $encodedName . '_([0-9]+)$/';
if (!is_array($this->links)) {
return [];
}
foreach ($this->links as $link) {
if (preg_match($regex, $link->getName())) {
$matching[] = $link;
}
}
// Find those that match TCP ports
$matching = array_filter(
$matching,
function (ContainerLink $link) use ($tcpPorts) {
foreach ($tcpPorts as $tcpPort) {
if (!$link->hasEndpoint($tcpPort, 'tcp')) {
return false;
}
}
return true;
}
);
// Reduce even more by finding those that match UDP ports
$matching = array_filter(
$matching,
function (ContainerLink $link) use ($udpPorts) {
foreach ($udpPorts as $udpPort) {
if (!$link->hasEndpoint($udpPort, 'udp')) {
return false;
}
}
return true;
}
);
return $matching;
} | php | public function findLinks($serviceName, $tcpPorts = [], $udpPorts = [])
{
// First match names
$matching = [];
$encodedName = $this->encodeServiceName($serviceName);
$regex = '/^' . $encodedName . '_([0-9]+)$/';
if (!is_array($this->links)) {
return [];
}
foreach ($this->links as $link) {
if (preg_match($regex, $link->getName())) {
$matching[] = $link;
}
}
// Find those that match TCP ports
$matching = array_filter(
$matching,
function (ContainerLink $link) use ($tcpPorts) {
foreach ($tcpPorts as $tcpPort) {
if (!$link->hasEndpoint($tcpPort, 'tcp')) {
return false;
}
}
return true;
}
);
// Reduce even more by finding those that match UDP ports
$matching = array_filter(
$matching,
function (ContainerLink $link) use ($udpPorts) {
foreach ($udpPorts as $udpPort) {
if (!$link->hasEndpoint($udpPort, 'udp')) {
return false;
}
}
return true;
}
);
return $matching;
} | [
"public",
"function",
"findLinks",
"(",
"$",
"serviceName",
",",
"$",
"tcpPorts",
"=",
"[",
"]",
",",
"$",
"udpPorts",
"=",
"[",
"]",
")",
"{",
"// First match names",
"$",
"matching",
"=",
"[",
"]",
";",
"$",
"encodedName",
"=",
"$",
"this",
"->",
"encodeServiceName",
"(",
"$",
"serviceName",
")",
";",
"$",
"regex",
"=",
"'/^'",
".",
"$",
"encodedName",
".",
"'_([0-9]+)$/'",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"links",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"links",
"as",
"$",
"link",
")",
"{",
"if",
"(",
"preg_match",
"(",
"$",
"regex",
",",
"$",
"link",
"->",
"getName",
"(",
")",
")",
")",
"{",
"$",
"matching",
"[",
"]",
"=",
"$",
"link",
";",
"}",
"}",
"// Find those that match TCP ports",
"$",
"matching",
"=",
"array_filter",
"(",
"$",
"matching",
",",
"function",
"(",
"ContainerLink",
"$",
"link",
")",
"use",
"(",
"$",
"tcpPorts",
")",
"{",
"foreach",
"(",
"$",
"tcpPorts",
"as",
"$",
"tcpPort",
")",
"{",
"if",
"(",
"!",
"$",
"link",
"->",
"hasEndpoint",
"(",
"$",
"tcpPort",
",",
"'tcp'",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
")",
";",
"// Reduce even more by finding those that match UDP ports",
"$",
"matching",
"=",
"array_filter",
"(",
"$",
"matching",
",",
"function",
"(",
"ContainerLink",
"$",
"link",
")",
"use",
"(",
"$",
"udpPorts",
")",
"{",
"foreach",
"(",
"$",
"udpPorts",
"as",
"$",
"udpPort",
")",
"{",
"if",
"(",
"!",
"$",
"link",
"->",
"hasEndpoint",
"(",
"$",
"udpPort",
",",
"'udp'",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
")",
";",
"return",
"$",
"matching",
";",
"}"
] | Find linked services that match a certain criteria
@param string $serviceName
@param int[] $tcpPorts
@param int[] $udpPorts
@return ContainerLink[] | [
"Find",
"linked",
"services",
"that",
"match",
"a",
"certain",
"criteria"
] | 39fb3375e0d47109a5da70a0e441efb8fd4f4008 | https://github.com/etcinit/tutum-php/blob/39fb3375e0d47109a5da70a0e441efb8fd4f4008/src/Chromabits/TutumClient/Entities/Container.php#L115-L162 |
8,550 | deasilworks/api | src/API.php | API.execute | public function execute(RestRequestModel $apiRequest)
{
$result = new ApiResultModel();
list($controller, $action, $args) = $this->resolveController($apiRequest->getRoute(), $apiRequest->getPath());
$actionReader = new ActionReader($controller);
if ($apiRequest->getMethod() == 'OPTIONS') {
$ack = $this->optionsAck($actionReader, $action);
return $result
->setContent($this->serialize($ack))
->setJson(true)
->setHeaders(['Allow' => 'OPTIONS, GET, POST'])
->setStatusCode(200);
}
$ack = $this->callAction($actionReader, $apiRequest, $action, $args);
return $result
->setContent($this->serialize($ack))
->setJson(true) // serialized ^
->setStatusCode($ack->getServerCode());
} | php | public function execute(RestRequestModel $apiRequest)
{
$result = new ApiResultModel();
list($controller, $action, $args) = $this->resolveController($apiRequest->getRoute(), $apiRequest->getPath());
$actionReader = new ActionReader($controller);
if ($apiRequest->getMethod() == 'OPTIONS') {
$ack = $this->optionsAck($actionReader, $action);
return $result
->setContent($this->serialize($ack))
->setJson(true)
->setHeaders(['Allow' => 'OPTIONS, GET, POST'])
->setStatusCode(200);
}
$ack = $this->callAction($actionReader, $apiRequest, $action, $args);
return $result
->setContent($this->serialize($ack))
->setJson(true) // serialized ^
->setStatusCode($ack->getServerCode());
} | [
"public",
"function",
"execute",
"(",
"RestRequestModel",
"$",
"apiRequest",
")",
"{",
"$",
"result",
"=",
"new",
"ApiResultModel",
"(",
")",
";",
"list",
"(",
"$",
"controller",
",",
"$",
"action",
",",
"$",
"args",
")",
"=",
"$",
"this",
"->",
"resolveController",
"(",
"$",
"apiRequest",
"->",
"getRoute",
"(",
")",
",",
"$",
"apiRequest",
"->",
"getPath",
"(",
")",
")",
";",
"$",
"actionReader",
"=",
"new",
"ActionReader",
"(",
"$",
"controller",
")",
";",
"if",
"(",
"$",
"apiRequest",
"->",
"getMethod",
"(",
")",
"==",
"'OPTIONS'",
")",
"{",
"$",
"ack",
"=",
"$",
"this",
"->",
"optionsAck",
"(",
"$",
"actionReader",
",",
"$",
"action",
")",
";",
"return",
"$",
"result",
"->",
"setContent",
"(",
"$",
"this",
"->",
"serialize",
"(",
"$",
"ack",
")",
")",
"->",
"setJson",
"(",
"true",
")",
"->",
"setHeaders",
"(",
"[",
"'Allow'",
"=>",
"'OPTIONS, GET, POST'",
"]",
")",
"->",
"setStatusCode",
"(",
"200",
")",
";",
"}",
"$",
"ack",
"=",
"$",
"this",
"->",
"callAction",
"(",
"$",
"actionReader",
",",
"$",
"apiRequest",
",",
"$",
"action",
",",
"$",
"args",
")",
";",
"return",
"$",
"result",
"->",
"setContent",
"(",
"$",
"this",
"->",
"serialize",
"(",
"$",
"ack",
")",
")",
"->",
"setJson",
"(",
"true",
")",
"// serialized ^",
"->",
"setStatusCode",
"(",
"$",
"ack",
"->",
"getServerCode",
"(",
")",
")",
";",
"}"
] | Execute API call.
@param RestRequestModel $apiRequest
@throws \Exception
@return mixed | [
"Execute",
"API",
"call",
"."
] | f3ba8900b246e8ea1777692b16168fd7295670fc | https://github.com/deasilworks/api/blob/f3ba8900b246e8ea1777692b16168fd7295670fc/src/API.php#L77-L101 |
8,551 | deasilworks/api | src/API.php | API.optionsAck | private function optionsAck($actionReader, $action)
{
$actionMeta = $actionReader->getActionCollection()[$action];
$ack = new AckModel();
$ack
->setServerCode(200)
->setSuccess(true)
->setPayload($actionMeta);
return $ack;
} | php | private function optionsAck($actionReader, $action)
{
$actionMeta = $actionReader->getActionCollection()[$action];
$ack = new AckModel();
$ack
->setServerCode(200)
->setSuccess(true)
->setPayload($actionMeta);
return $ack;
} | [
"private",
"function",
"optionsAck",
"(",
"$",
"actionReader",
",",
"$",
"action",
")",
"{",
"$",
"actionMeta",
"=",
"$",
"actionReader",
"->",
"getActionCollection",
"(",
")",
"[",
"$",
"action",
"]",
";",
"$",
"ack",
"=",
"new",
"AckModel",
"(",
")",
";",
"$",
"ack",
"->",
"setServerCode",
"(",
"200",
")",
"->",
"setSuccess",
"(",
"true",
")",
"->",
"setPayload",
"(",
"$",
"actionMeta",
")",
";",
"return",
"$",
"ack",
";",
"}"
] | Ack Options.
@param ActionReader $actionReader
@param string $action
@return AckModel | [
"Ack",
"Options",
"."
] | f3ba8900b246e8ea1777692b16168fd7295670fc | https://github.com/deasilworks/api/blob/f3ba8900b246e8ea1777692b16168fd7295670fc/src/API.php#L111-L122 |
8,552 | deasilworks/api | src/API.php | API.callAction | private function callAction($actionReader, $apiRequest, $action, $args)
{
$actionExecutor = new ActionExecutor($actionReader);
/** @var ActionResponseModel $actionResponse */
$actionResponse = $actionExecutor->execute($apiRequest, $action, $args);
$ack = new AckModel();
$class = '';
if (is_object($actionResponse->getResponse())) {
$class = get_class($actionResponse->getResponse());
}
$ack
->setPkgUuid($actionResponse->getPkgUuid())
->setSuccess(true)
->setServerCode(200)
->setLocation($apiRequest->getPath())
->setLocationParams($actionResponse->getParams())
->setRequestArgs($actionResponse->getArgs())
->setPayloadClass($class)
->setPayload($actionResponse->getResponse());
return $ack;
} | php | private function callAction($actionReader, $apiRequest, $action, $args)
{
$actionExecutor = new ActionExecutor($actionReader);
/** @var ActionResponseModel $actionResponse */
$actionResponse = $actionExecutor->execute($apiRequest, $action, $args);
$ack = new AckModel();
$class = '';
if (is_object($actionResponse->getResponse())) {
$class = get_class($actionResponse->getResponse());
}
$ack
->setPkgUuid($actionResponse->getPkgUuid())
->setSuccess(true)
->setServerCode(200)
->setLocation($apiRequest->getPath())
->setLocationParams($actionResponse->getParams())
->setRequestArgs($actionResponse->getArgs())
->setPayloadClass($class)
->setPayload($actionResponse->getResponse());
return $ack;
} | [
"private",
"function",
"callAction",
"(",
"$",
"actionReader",
",",
"$",
"apiRequest",
",",
"$",
"action",
",",
"$",
"args",
")",
"{",
"$",
"actionExecutor",
"=",
"new",
"ActionExecutor",
"(",
"$",
"actionReader",
")",
";",
"/** @var ActionResponseModel $actionResponse */",
"$",
"actionResponse",
"=",
"$",
"actionExecutor",
"->",
"execute",
"(",
"$",
"apiRequest",
",",
"$",
"action",
",",
"$",
"args",
")",
";",
"$",
"ack",
"=",
"new",
"AckModel",
"(",
")",
";",
"$",
"class",
"=",
"''",
";",
"if",
"(",
"is_object",
"(",
"$",
"actionResponse",
"->",
"getResponse",
"(",
")",
")",
")",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"actionResponse",
"->",
"getResponse",
"(",
")",
")",
";",
"}",
"$",
"ack",
"->",
"setPkgUuid",
"(",
"$",
"actionResponse",
"->",
"getPkgUuid",
"(",
")",
")",
"->",
"setSuccess",
"(",
"true",
")",
"->",
"setServerCode",
"(",
"200",
")",
"->",
"setLocation",
"(",
"$",
"apiRequest",
"->",
"getPath",
"(",
")",
")",
"->",
"setLocationParams",
"(",
"$",
"actionResponse",
"->",
"getParams",
"(",
")",
")",
"->",
"setRequestArgs",
"(",
"$",
"actionResponse",
"->",
"getArgs",
"(",
")",
")",
"->",
"setPayloadClass",
"(",
"$",
"class",
")",
"->",
"setPayload",
"(",
"$",
"actionResponse",
"->",
"getResponse",
"(",
")",
")",
";",
"return",
"$",
"ack",
";",
"}"
] | Call Action.
@param ActionReader $actionReader
@param RestRequestModel $apiRequest
@param $action
@param $args
@return AckModel | [
"Call",
"Action",
"."
] | f3ba8900b246e8ea1777692b16168fd7295670fc | https://github.com/deasilworks/api/blob/f3ba8900b246e8ea1777692b16168fd7295670fc/src/API.php#L134-L159 |
8,553 | deasilworks/api | src/API.php | API.resolveController | private function resolveController($route, $path)
{
$pathComponents = explode('/', $path);
$baseClassPath = $this->config->getClassPath($route);
$classObject = null;
$aliases = $this->config->getAliases($route);
$class = $baseClassPath;
$classAlias = '';
$controllerFactory = $this->config->getControllerFactory();
$routeConfig = [];
$routes = $this->config->getRoutes();
if (is_array($routes) && isset($routes[$route]['config'])) {
$routeConfig = $routes[$route]['config'];
}
while ($pathComponents) {
$pathComponent = array_shift($pathComponents);
$class = $class.'\\'.ucfirst($pathComponent);
$classAlias .= ucfirst($pathComponent);
// check for an alias first
if (isset($aliases[strtolower($classAlias)])) {
$aliasClass = $baseClassPath.'\\'.$aliases[strtolower($classAlias)];
if (class_exists($aliasClass)) {
$classObject = $controllerFactory($aliasClass, $routeConfig);
break;
}
}
if (class_exists($class)) {
$classObject = $controllerFactory($class, $routeConfig);
if (!$classObject) {
$classObject = new $class();
break;
}
break;
}
$classAlias .= '/';
}
if (!$classObject) {
throw new \Exception('API: No controller found for the requested end point. ');
}
// any path left over becomes args
$pathArgs = $pathComponents;
return [$classObject, array_shift($pathArgs), $pathArgs];
} | php | private function resolveController($route, $path)
{
$pathComponents = explode('/', $path);
$baseClassPath = $this->config->getClassPath($route);
$classObject = null;
$aliases = $this->config->getAliases($route);
$class = $baseClassPath;
$classAlias = '';
$controllerFactory = $this->config->getControllerFactory();
$routeConfig = [];
$routes = $this->config->getRoutes();
if (is_array($routes) && isset($routes[$route]['config'])) {
$routeConfig = $routes[$route]['config'];
}
while ($pathComponents) {
$pathComponent = array_shift($pathComponents);
$class = $class.'\\'.ucfirst($pathComponent);
$classAlias .= ucfirst($pathComponent);
// check for an alias first
if (isset($aliases[strtolower($classAlias)])) {
$aliasClass = $baseClassPath.'\\'.$aliases[strtolower($classAlias)];
if (class_exists($aliasClass)) {
$classObject = $controllerFactory($aliasClass, $routeConfig);
break;
}
}
if (class_exists($class)) {
$classObject = $controllerFactory($class, $routeConfig);
if (!$classObject) {
$classObject = new $class();
break;
}
break;
}
$classAlias .= '/';
}
if (!$classObject) {
throw new \Exception('API: No controller found for the requested end point. ');
}
// any path left over becomes args
$pathArgs = $pathComponents;
return [$classObject, array_shift($pathArgs), $pathArgs];
} | [
"private",
"function",
"resolveController",
"(",
"$",
"route",
",",
"$",
"path",
")",
"{",
"$",
"pathComponents",
"=",
"explode",
"(",
"'/'",
",",
"$",
"path",
")",
";",
"$",
"baseClassPath",
"=",
"$",
"this",
"->",
"config",
"->",
"getClassPath",
"(",
"$",
"route",
")",
";",
"$",
"classObject",
"=",
"null",
";",
"$",
"aliases",
"=",
"$",
"this",
"->",
"config",
"->",
"getAliases",
"(",
"$",
"route",
")",
";",
"$",
"class",
"=",
"$",
"baseClassPath",
";",
"$",
"classAlias",
"=",
"''",
";",
"$",
"controllerFactory",
"=",
"$",
"this",
"->",
"config",
"->",
"getControllerFactory",
"(",
")",
";",
"$",
"routeConfig",
"=",
"[",
"]",
";",
"$",
"routes",
"=",
"$",
"this",
"->",
"config",
"->",
"getRoutes",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"routes",
")",
"&&",
"isset",
"(",
"$",
"routes",
"[",
"$",
"route",
"]",
"[",
"'config'",
"]",
")",
")",
"{",
"$",
"routeConfig",
"=",
"$",
"routes",
"[",
"$",
"route",
"]",
"[",
"'config'",
"]",
";",
"}",
"while",
"(",
"$",
"pathComponents",
")",
"{",
"$",
"pathComponent",
"=",
"array_shift",
"(",
"$",
"pathComponents",
")",
";",
"$",
"class",
"=",
"$",
"class",
".",
"'\\\\'",
".",
"ucfirst",
"(",
"$",
"pathComponent",
")",
";",
"$",
"classAlias",
".=",
"ucfirst",
"(",
"$",
"pathComponent",
")",
";",
"// check for an alias first",
"if",
"(",
"isset",
"(",
"$",
"aliases",
"[",
"strtolower",
"(",
"$",
"classAlias",
")",
"]",
")",
")",
"{",
"$",
"aliasClass",
"=",
"$",
"baseClassPath",
".",
"'\\\\'",
".",
"$",
"aliases",
"[",
"strtolower",
"(",
"$",
"classAlias",
")",
"]",
";",
"if",
"(",
"class_exists",
"(",
"$",
"aliasClass",
")",
")",
"{",
"$",
"classObject",
"=",
"$",
"controllerFactory",
"(",
"$",
"aliasClass",
",",
"$",
"routeConfig",
")",
";",
"break",
";",
"}",
"}",
"if",
"(",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"classObject",
"=",
"$",
"controllerFactory",
"(",
"$",
"class",
",",
"$",
"routeConfig",
")",
";",
"if",
"(",
"!",
"$",
"classObject",
")",
"{",
"$",
"classObject",
"=",
"new",
"$",
"class",
"(",
")",
";",
"break",
";",
"}",
"break",
";",
"}",
"$",
"classAlias",
".=",
"'/'",
";",
"}",
"if",
"(",
"!",
"$",
"classObject",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'API: No controller found for the requested end point. '",
")",
";",
"}",
"// any path left over becomes args",
"$",
"pathArgs",
"=",
"$",
"pathComponents",
";",
"return",
"[",
"$",
"classObject",
",",
"array_shift",
"(",
"$",
"pathArgs",
")",
",",
"$",
"pathArgs",
"]",
";",
"}"
] | Resolves controller to object and remaining args.
@param string $route
@param string $path
@throws \Exception
@return array | [
"Resolves",
"controller",
"to",
"object",
"and",
"remaining",
"args",
"."
] | f3ba8900b246e8ea1777692b16168fd7295670fc | https://github.com/deasilworks/api/blob/f3ba8900b246e8ea1777692b16168fd7295670fc/src/API.php#L171-L228 |
8,554 | budkit/budkit-framework | src/Budkit/Application/Support/Application.php | Application.registerServices | public function registerServices(array $services = [])
{
if (empty($services)) {
$services = $this->paths['vendor'] . "/services.json";
//If we can't load this file, throw and error;
if (!$this->file->exists($services)) {
return false; //could not
}
//decode;
$services = json_decode($this->file->read($services), true);
}
//@TODO This should be moved to the provider handling class
foreach ($services as $callable) {
if (!class_exists($callable)) {
throw new Exception("Could not locate the service provider {$callable}");
return false;
}
//Create an instance of the callback
$provider = $this->createInstance($callable, [$this]);
//Check implements Service Interface;
if (!($provider instanceof Service)) {
throw new Exception("{$callable} Must implement the Service Interface");
return false;
}
//var_dump($provider);
//Attach the service provider;
$this->observer->attach($provider);
}
//var_dump($this->observer);
//Trigger the register event
$this->observer->trigger(new Event("app.register", $this));
} | php | public function registerServices(array $services = [])
{
if (empty($services)) {
$services = $this->paths['vendor'] . "/services.json";
//If we can't load this file, throw and error;
if (!$this->file->exists($services)) {
return false; //could not
}
//decode;
$services = json_decode($this->file->read($services), true);
}
//@TODO This should be moved to the provider handling class
foreach ($services as $callable) {
if (!class_exists($callable)) {
throw new Exception("Could not locate the service provider {$callable}");
return false;
}
//Create an instance of the callback
$provider = $this->createInstance($callable, [$this]);
//Check implements Service Interface;
if (!($provider instanceof Service)) {
throw new Exception("{$callable} Must implement the Service Interface");
return false;
}
//var_dump($provider);
//Attach the service provider;
$this->observer->attach($provider);
}
//var_dump($this->observer);
//Trigger the register event
$this->observer->trigger(new Event("app.register", $this));
} | [
"public",
"function",
"registerServices",
"(",
"array",
"$",
"services",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"services",
")",
")",
"{",
"$",
"services",
"=",
"$",
"this",
"->",
"paths",
"[",
"'vendor'",
"]",
".",
"\"/services.json\"",
";",
"//If we can't load this file, throw and error;",
"if",
"(",
"!",
"$",
"this",
"->",
"file",
"->",
"exists",
"(",
"$",
"services",
")",
")",
"{",
"return",
"false",
";",
"//could not",
"}",
"//decode;",
"$",
"services",
"=",
"json_decode",
"(",
"$",
"this",
"->",
"file",
"->",
"read",
"(",
"$",
"services",
")",
",",
"true",
")",
";",
"}",
"//@TODO This should be moved to the provider handling class",
"foreach",
"(",
"$",
"services",
"as",
"$",
"callable",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"callable",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Could not locate the service provider {$callable}\"",
")",
";",
"return",
"false",
";",
"}",
"//Create an instance of the callback",
"$",
"provider",
"=",
"$",
"this",
"->",
"createInstance",
"(",
"$",
"callable",
",",
"[",
"$",
"this",
"]",
")",
";",
"//Check implements Service Interface;",
"if",
"(",
"!",
"(",
"$",
"provider",
"instanceof",
"Service",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"{$callable} Must implement the Service Interface\"",
")",
";",
"return",
"false",
";",
"}",
"//var_dump($provider);",
"//Attach the service provider;",
"$",
"this",
"->",
"observer",
"->",
"attach",
"(",
"$",
"provider",
")",
";",
"}",
"//var_dump($this->observer);",
"//Trigger the register event",
"$",
"this",
"->",
"observer",
"->",
"trigger",
"(",
"new",
"Event",
"(",
"\"app.register\"",
",",
"$",
"this",
")",
")",
";",
"}"
] | Registers an array of services, to be initiated by the app.
- Triggers the `app.register` event
@param An array of $services e.g [ "Budkit\\Cms\\Provider", .. ]
@return False if the vendor/services.json file could not be loaded, or an Exception was thrown
@throws \Exception if a defined service is not callable, or if its not an instance of Service | [
"Registers",
"an",
"array",
"of",
"services",
"to",
"be",
"initiated",
"by",
"the",
"app",
"."
] | 0635061815fe07a8c63f9514b845d199b3c0d485 | https://github.com/budkit/budkit-framework/blob/0635061815fe07a8c63f9514b845d199b3c0d485/src/Budkit/Application/Support/Application.php#L89-L129 |
8,555 | budkit/budkit-framework | src/Budkit/Application/Support/Application.php | Application.initialize | public function initialize()
{
//The global dispatcher
//state the application is initialized;
//register aliases as class mocks such that static calls on mock map to instance calls;
$this->createAliasMock(
array_merge(
$this->aliases, [
"route" => 'Budkit\Routing\Router', //this such that we can call Route::add to add router;
'controller' => 'Budkit\Routing\Controller',
'view' => 'Budkit\View\Display'
]
)
);
//Trigger the app initialise event;
$this->observer->trigger(new Event("app.init", $this));
} | php | public function initialize()
{
//The global dispatcher
//state the application is initialized;
//register aliases as class mocks such that static calls on mock map to instance calls;
$this->createAliasMock(
array_merge(
$this->aliases, [
"route" => 'Budkit\Routing\Router', //this such that we can call Route::add to add router;
'controller' => 'Budkit\Routing\Controller',
'view' => 'Budkit\View\Display'
]
)
);
//Trigger the app initialise event;
$this->observer->trigger(new Event("app.init", $this));
} | [
"public",
"function",
"initialize",
"(",
")",
"{",
"//The global dispatcher",
"//state the application is initialized;",
"//register aliases as class mocks such that static calls on mock map to instance calls;",
"$",
"this",
"->",
"createAliasMock",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"aliases",
",",
"[",
"\"route\"",
"=>",
"'Budkit\\Routing\\Router'",
",",
"//this such that we can call Route::add to add router;",
"'controller'",
"=>",
"'Budkit\\Routing\\Controller'",
",",
"'view'",
"=>",
"'Budkit\\View\\Display'",
"]",
")",
")",
";",
"//Trigger the app initialise event;",
"$",
"this",
"->",
"observer",
"->",
"trigger",
"(",
"new",
"Event",
"(",
"\"app.init\"",
",",
"$",
"this",
")",
")",
";",
"}"
] | Initialised the app when all services are registered.
- Triggers the `app.init` event | [
"Initialised",
"the",
"app",
"when",
"all",
"services",
"are",
"registered",
"."
] | 0635061815fe07a8c63f9514b845d199b3c0d485 | https://github.com/budkit/budkit-framework/blob/0635061815fe07a8c63f9514b845d199b3c0d485/src/Budkit/Application/Support/Application.php#L137-L155 |
8,556 | MINISTRYGmbH/morrow-core | src/Language.php | Language.setLocale | public function setLocale($keys) {
if (!setlocale(LC_ALL, $keys)) {
exec('locale -a', $locales);
$locales = implode("<br />", $locales);
throw new \Exception(__METHOD__.'<br>setLocale() failed. These are the locales installed on this system:<br />'.$locales);
}
} | php | public function setLocale($keys) {
if (!setlocale(LC_ALL, $keys)) {
exec('locale -a', $locales);
$locales = implode("<br />", $locales);
throw new \Exception(__METHOD__.'<br>setLocale() failed. These are the locales installed on this system:<br />'.$locales);
}
} | [
"public",
"function",
"setLocale",
"(",
"$",
"keys",
")",
"{",
"if",
"(",
"!",
"setlocale",
"(",
"LC_ALL",
",",
"$",
"keys",
")",
")",
"{",
"exec",
"(",
"'locale -a'",
",",
"$",
"locales",
")",
";",
"$",
"locales",
"=",
"implode",
"(",
"\"<br />\"",
",",
"$",
"locales",
")",
";",
"throw",
"new",
"\\",
"Exception",
"(",
"__METHOD__",
".",
"'<br>setLocale() failed. These are the locales installed on this system:<br />'",
".",
"$",
"locales",
")",
";",
"}",
"}"
] | Tries to set the locales via setlocale. If no array items matches locales installed on the system you will get an overview of all installed locales.
@param array $keys An array of keys to try.
@return `null` | [
"Tries",
"to",
"set",
"the",
"locales",
"via",
"setlocale",
".",
"If",
"no",
"array",
"items",
"matches",
"locales",
"installed",
"on",
"the",
"system",
"you",
"will",
"get",
"an",
"overview",
"of",
"all",
"installed",
"locales",
"."
] | bdc916eedb14b65b06dbc88efbd2b7779f4a9a9e | https://github.com/MINISTRYGmbH/morrow-core/blob/bdc916eedb14b65b06dbc88efbd2b7779f4a9a9e/src/Language.php#L216-L222 |
8,557 | MINISTRYGmbH/morrow-core | src/Language.php | Language.getTranslations | public function getTranslations($alias) {
$translations = [];
foreach ($this->_possible as $possible) {
if ($this->translationExists($possible, $alias)) {
$config = $this->getL10n($possible);
$translations[$possible] = $config['title'];
}
}
return $translations;
} | php | public function getTranslations($alias) {
$translations = [];
foreach ($this->_possible as $possible) {
if ($this->translationExists($possible, $alias)) {
$config = $this->getL10n($possible);
$translations[$possible] = $config['title'];
}
}
return $translations;
} | [
"public",
"function",
"getTranslations",
"(",
"$",
"alias",
")",
"{",
"$",
"translations",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_possible",
"as",
"$",
"possible",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"translationExists",
"(",
"$",
"possible",
",",
"$",
"alias",
")",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"getL10n",
"(",
"$",
"possible",
")",
";",
"$",
"translations",
"[",
"$",
"possible",
"]",
"=",
"$",
"config",
"[",
"'title'",
"]",
";",
"}",
"}",
"return",
"$",
"translations",
";",
"}"
] | Checks in which languages the given page alias is available.
@param string $alias A page alias.
@return `array` Returns an array where the key is the language key like "en" or "de", and the value is the language title like "English". | [
"Checks",
"in",
"which",
"languages",
"the",
"given",
"page",
"alias",
"is",
"available",
"."
] | bdc916eedb14b65b06dbc88efbd2b7779f4a9a9e | https://github.com/MINISTRYGmbH/morrow-core/blob/bdc916eedb14b65b06dbc88efbd2b7779f4a9a9e/src/Language.php#L229-L238 |
8,558 | MINISTRYGmbH/morrow-core | src/Language.php | Language.translationExists | public function translationExists($lang, $alias) {
$tree = $this->getTree($lang);
foreach ($tree as $branch) {
if (isset($branch[$alias])) return true;
}
return false;
} | php | public function translationExists($lang, $alias) {
$tree = $this->getTree($lang);
foreach ($tree as $branch) {
if (isset($branch[$alias])) return true;
}
return false;
} | [
"public",
"function",
"translationExists",
"(",
"$",
"lang",
",",
"$",
"alias",
")",
"{",
"$",
"tree",
"=",
"$",
"this",
"->",
"getTree",
"(",
"$",
"lang",
")",
";",
"foreach",
"(",
"$",
"tree",
"as",
"$",
"branch",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"branch",
"[",
"$",
"alias",
"]",
")",
")",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Checks whether a page alias exists in the given language or not.
@param string $lang A language key.
@param string $alias A page alias.
@return `bool` | [
"Checks",
"whether",
"a",
"page",
"alias",
"exists",
"in",
"the",
"given",
"language",
"or",
"not",
"."
] | bdc916eedb14b65b06dbc88efbd2b7779f4a9a9e | https://github.com/MINISTRYGmbH/morrow-core/blob/bdc916eedb14b65b06dbc88efbd2b7779f4a9a9e/src/Language.php#L246-L253 |
8,559 | MINISTRYGmbH/morrow-core | src/Language.php | Language.set | public function set($lang) {
if ($this->isValid($lang)) {
$this->_language = $lang;
$this->_l10n = $this->getL10n();
// switch the locales
$this->setLocale($this->_l10n['keys']);
// clear content because language has changed
$this->_content = null;
return true;
}
return false;
} | php | public function set($lang) {
if ($this->isValid($lang)) {
$this->_language = $lang;
$this->_l10n = $this->getL10n();
// switch the locales
$this->setLocale($this->_l10n['keys']);
// clear content because language has changed
$this->_content = null;
return true;
}
return false;
} | [
"public",
"function",
"set",
"(",
"$",
"lang",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isValid",
"(",
"$",
"lang",
")",
")",
"{",
"$",
"this",
"->",
"_language",
"=",
"$",
"lang",
";",
"$",
"this",
"->",
"_l10n",
"=",
"$",
"this",
"->",
"getL10n",
"(",
")",
";",
"// switch the locales",
"$",
"this",
"->",
"setLocale",
"(",
"$",
"this",
"->",
"_l10n",
"[",
"'keys'",
"]",
")",
";",
"// clear content because language has changed",
"$",
"this",
"->",
"_content",
"=",
"null",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Sets the current language. Has to be one of the `possible` languages.
@param string $lang The language to set.
@return `bool` Returns `true` if the language could be changed or `false` if not | [
"Sets",
"the",
"current",
"language",
".",
"Has",
"to",
"be",
"one",
"of",
"the",
"possible",
"languages",
"."
] | bdc916eedb14b65b06dbc88efbd2b7779f4a9a9e | https://github.com/MINISTRYGmbH/morrow-core/blob/bdc916eedb14b65b06dbc88efbd2b7779f4a9a9e/src/Language.php#L260-L273 |
8,560 | MINISTRYGmbH/morrow-core | src/Language.php | Language.getBestFromClient | public function getBestFromClient() {
// get all language keys from client
$client_langs = $this->getFromClient();
foreach ($client_langs as $client_lang) {
foreach ($this->_possible as $possible) {
$l10n = $this->getL10n($possible);
if (in_array($client_lang, $l10n['keys'])) {
return $client_lang;
}
}
}
} | php | public function getBestFromClient() {
// get all language keys from client
$client_langs = $this->getFromClient();
foreach ($client_langs as $client_lang) {
foreach ($this->_possible as $possible) {
$l10n = $this->getL10n($possible);
if (in_array($client_lang, $l10n['keys'])) {
return $client_lang;
}
}
}
} | [
"public",
"function",
"getBestFromClient",
"(",
")",
"{",
"// get all language keys from client",
"$",
"client_langs",
"=",
"$",
"this",
"->",
"getFromClient",
"(",
")",
";",
"foreach",
"(",
"$",
"client_langs",
"as",
"$",
"client_lang",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_possible",
"as",
"$",
"possible",
")",
"{",
"$",
"l10n",
"=",
"$",
"this",
"->",
"getL10n",
"(",
"$",
"possible",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"client_lang",
",",
"$",
"l10n",
"[",
"'keys'",
"]",
")",
")",
"{",
"return",
"$",
"client_lang",
";",
"}",
"}",
"}",
"}"
] | Determines the best language according to the users browser settings.
@return `string` A valid language key. | [
"Determines",
"the",
"best",
"language",
"according",
"to",
"the",
"users",
"browser",
"settings",
"."
] | bdc916eedb14b65b06dbc88efbd2b7779f4a9a9e | https://github.com/MINISTRYGmbH/morrow-core/blob/bdc916eedb14b65b06dbc88efbd2b7779f4a9a9e/src/Language.php#L279-L292 |
8,561 | MINISTRYGmbH/morrow-core | src/Language.php | Language.getFromClient | public function getFromClient() {
$returner = [];
// Example string
// en-ca,en;q=0.8,en-us;q=0.6,de-de;q=0.4,de;q=0.2
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$parts = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
foreach ($parts as $part) {
preg_match("|^
(.*?) # the language part
([-].*?)? # the country part (optional)
(;q=(.*))? # the quality part (optional)
$|x", $part, $matches);
// set quality to 1.0 if not given
$quality = isset($matches[4]) ? $matches[4] : '1.0';
$returner[$quality] = strtolower(trim($matches[1]));
}
krsort($returner);
}
return $returner;
} | php | public function getFromClient() {
$returner = [];
// Example string
// en-ca,en;q=0.8,en-us;q=0.6,de-de;q=0.4,de;q=0.2
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$parts = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
foreach ($parts as $part) {
preg_match("|^
(.*?) # the language part
([-].*?)? # the country part (optional)
(;q=(.*))? # the quality part (optional)
$|x", $part, $matches);
// set quality to 1.0 if not given
$quality = isset($matches[4]) ? $matches[4] : '1.0';
$returner[$quality] = strtolower(trim($matches[1]));
}
krsort($returner);
}
return $returner;
} | [
"public",
"function",
"getFromClient",
"(",
")",
"{",
"$",
"returner",
"=",
"[",
"]",
";",
"// Example string",
"// en-ca,en;q=0.8,en-us;q=0.6,de-de;q=0.4,de;q=0.2",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_LANGUAGE'",
"]",
")",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"','",
",",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_LANGUAGE'",
"]",
")",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"part",
")",
"{",
"preg_match",
"(",
"\"|^\n\t\t\t\t\t(.*?)\t\t# the language part\n\t\t\t\t\t([-].*?)?\t# the country part (optional)\n\t\t\t\t\t(;q=(.*))?\t# the quality part (optional)\n\t\t\t\t$|x\"",
",",
"$",
"part",
",",
"$",
"matches",
")",
";",
"// set quality to 1.0 if not given",
"$",
"quality",
"=",
"isset",
"(",
"$",
"matches",
"[",
"4",
"]",
")",
"?",
"$",
"matches",
"[",
"4",
"]",
":",
"'1.0'",
";",
"$",
"returner",
"[",
"$",
"quality",
"]",
"=",
"strtolower",
"(",
"trim",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
")",
";",
"}",
"krsort",
"(",
"$",
"returner",
")",
";",
"}",
"return",
"$",
"returner",
";",
"}"
] | Parses the Accept-Language HTTP header sent by the browser.
It will return an array with the languages the user accepts, sorted from most preferred to least preferred.
@return `array` Key is the importance, value is the language code. | [
"Parses",
"the",
"Accept",
"-",
"Language",
"HTTP",
"header",
"sent",
"by",
"the",
"browser",
".",
"It",
"will",
"return",
"an",
"array",
"with",
"the",
"languages",
"the",
"user",
"accepts",
"sorted",
"from",
"most",
"preferred",
"to",
"least",
"preferred",
"."
] | bdc916eedb14b65b06dbc88efbd2b7779f4a9a9e | https://github.com/MINISTRYGmbH/morrow-core/blob/bdc916eedb14b65b06dbc88efbd2b7779f4a9a9e/src/Language.php#L299-L323 |
8,562 | MINISTRYGmbH/morrow-core | src/Language.php | Language._loadFile | protected function _loadFile($path, $dot_syntax_explode = true) {
if(!is_file($path)) return [];
if ($dot_syntax_explode) return $this->arrayExplode(include($path));
return include($path);
} | php | protected function _loadFile($path, $dot_syntax_explode = true) {
if(!is_file($path)) return [];
if ($dot_syntax_explode) return $this->arrayExplode(include($path));
return include($path);
} | [
"protected",
"function",
"_loadFile",
"(",
"$",
"path",
",",
"$",
"dot_syntax_explode",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"is_file",
"(",
"$",
"path",
")",
")",
"return",
"[",
"]",
";",
"if",
"(",
"$",
"dot_syntax_explode",
")",
"return",
"$",
"this",
"->",
"arrayExplode",
"(",
"include",
"(",
"$",
"path",
")",
")",
";",
"return",
"include",
"(",
"$",
"path",
")",
";",
"}"
] | Loads a config file and extracts dot syntax keys.
@param string $path The path to the config file.
@param boolean $dot_syntax_explode Explode keys or not.
@return array Returns the loaded config. | [
"Loads",
"a",
"config",
"file",
"and",
"extracts",
"dot",
"syntax",
"keys",
"."
] | bdc916eedb14b65b06dbc88efbd2b7779f4a9a9e | https://github.com/MINISTRYGmbH/morrow-core/blob/bdc916eedb14b65b06dbc88efbd2b7779f4a9a9e/src/Language.php#L428-L432 |
8,563 | MINISTRYGmbH/morrow-core | src/Language.php | Language._varExport | protected function _varExport($array, $section) {
if (empty($array)) return '';
$returner = "\n\t/* $section */\n";
foreach ($array as $k => $v) {
$key = str_replace("'", "\'", $k);
$value = str_replace("'", "\'", $v);
$returner .= str_pad("\t'$key'", 40, ' ');
$returner .= '=> ';
$returner .= "'$value',\n";
}
return $returner;
} | php | protected function _varExport($array, $section) {
if (empty($array)) return '';
$returner = "\n\t/* $section */\n";
foreach ($array as $k => $v) {
$key = str_replace("'", "\'", $k);
$value = str_replace("'", "\'", $v);
$returner .= str_pad("\t'$key'", 40, ' ');
$returner .= '=> ';
$returner .= "'$value',\n";
}
return $returner;
} | [
"protected",
"function",
"_varExport",
"(",
"$",
"array",
",",
"$",
"section",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"array",
")",
")",
"return",
"''",
";",
"$",
"returner",
"=",
"\"\\n\\t/* $section */\\n\"",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"key",
"=",
"str_replace",
"(",
"\"'\"",
",",
"\"\\'\"",
",",
"$",
"k",
")",
";",
"$",
"value",
"=",
"str_replace",
"(",
"\"'\"",
",",
"\"\\'\"",
",",
"$",
"v",
")",
";",
"$",
"returner",
".=",
"str_pad",
"(",
"\"\\t'$key'\"",
",",
"40",
",",
"' '",
")",
";",
"$",
"returner",
".=",
"'=> '",
";",
"$",
"returner",
".=",
"\"'$value',\\n\"",
";",
"}",
"return",
"$",
"returner",
";",
"}"
] | Like var_export from php but creates a code styled array. Called by checkLanguageFiles to create the i18n files.
@param array $array The array to create the output string from.
@param string $section A section name to use as comment
@return `string` | [
"Like",
"var_export",
"from",
"php",
"but",
"creates",
"a",
"code",
"styled",
"array",
".",
"Called",
"by",
"checkLanguageFiles",
"to",
"create",
"the",
"i18n",
"files",
"."
] | bdc916eedb14b65b06dbc88efbd2b7779f4a9a9e | https://github.com/MINISTRYGmbH/morrow-core/blob/bdc916eedb14b65b06dbc88efbd2b7779f4a9a9e/src/Language.php#L440-L454 |
8,564 | frogsystem/spawn | src/frogsystem/spawn/Exceptions/ParameterResolutionException.php | ParameterResolutionException.getReflectionParameterName | protected function getReflectionParameterName(\ReflectionParameter $parameter)
{
// parameter is a class
if ($class = $parameter->getClass()) {
return $class->getName() . ' \$' . $parameter->getName();
}
return $parameter->getName();
} | php | protected function getReflectionParameterName(\ReflectionParameter $parameter)
{
// parameter is a class
if ($class = $parameter->getClass()) {
return $class->getName() . ' \$' . $parameter->getName();
}
return $parameter->getName();
} | [
"protected",
"function",
"getReflectionParameterName",
"(",
"\\",
"ReflectionParameter",
"$",
"parameter",
")",
"{",
"// parameter is a class",
"if",
"(",
"$",
"class",
"=",
"$",
"parameter",
"->",
"getClass",
"(",
")",
")",
"{",
"return",
"$",
"class",
"->",
"getName",
"(",
")",
".",
"' \\$'",
".",
"$",
"parameter",
"->",
"getName",
"(",
")",
";",
"}",
"return",
"$",
"parameter",
"->",
"getName",
"(",
")",
";",
"}"
] | Helper method to get the type of a reflection paramter
@param \ReflectionParameter $parameter
@return NULL|\ReflectionType|string | [
"Helper",
"method",
"to",
"get",
"the",
"type",
"of",
"a",
"reflection",
"paramter"
] | fede7dcf09d276a4f0143783cd48c802fe1daad4 | https://github.com/frogsystem/spawn/blob/fede7dcf09d276a4f0143783cd48c802fe1daad4/src/frogsystem/spawn/Exceptions/ParameterResolutionException.php#L41-L49 |
8,565 | frogsystem/spawn | src/frogsystem/spawn/Exceptions/ParameterResolutionException.php | ParameterResolutionException.getReflectionFunctionName | protected function getReflectionFunctionName(\ReflectionFunctionAbstract $reflection)
{
// Class method
if ($reflection instanceof \ReflectionMethod) {
return $reflection->getDeclaringClass()->getName() . '::' . $reflection->getName();
}
return $reflection->getName();
} | php | protected function getReflectionFunctionName(\ReflectionFunctionAbstract $reflection)
{
// Class method
if ($reflection instanceof \ReflectionMethod) {
return $reflection->getDeclaringClass()->getName() . '::' . $reflection->getName();
}
return $reflection->getName();
} | [
"protected",
"function",
"getReflectionFunctionName",
"(",
"\\",
"ReflectionFunctionAbstract",
"$",
"reflection",
")",
"{",
"// Class method",
"if",
"(",
"$",
"reflection",
"instanceof",
"\\",
"ReflectionMethod",
")",
"{",
"return",
"$",
"reflection",
"->",
"getDeclaringClass",
"(",
")",
"->",
"getName",
"(",
")",
".",
"'::'",
".",
"$",
"reflection",
"->",
"getName",
"(",
")",
";",
"}",
"return",
"$",
"reflection",
"->",
"getName",
"(",
")",
";",
"}"
] | Helper method to retrieve the name of a ReflectionFunctionAbstract
@param \ReflectionFunctionAbstract $reflection
@return string | [
"Helper",
"method",
"to",
"retrieve",
"the",
"name",
"of",
"a",
"ReflectionFunctionAbstract"
] | fede7dcf09d276a4f0143783cd48c802fe1daad4 | https://github.com/frogsystem/spawn/blob/fede7dcf09d276a4f0143783cd48c802fe1daad4/src/frogsystem/spawn/Exceptions/ParameterResolutionException.php#L56-L63 |
8,566 | f3ath/flock | src/Lock.php | Lock.release | public function release()
{
if (!$this->handler) {
throw new \LogicException('Lock is not acquired');
}
if (!@ftruncate($this->handler, 0)) {
$this->throwLastErrorException();
}
if (!flock($this->handler, LOCK_UN)) {
throw new \RuntimeException(sprintf('Unable to release lock on %s', $this->file));
}
$this->closeFile();
} | php | public function release()
{
if (!$this->handler) {
throw new \LogicException('Lock is not acquired');
}
if (!@ftruncate($this->handler, 0)) {
$this->throwLastErrorException();
}
if (!flock($this->handler, LOCK_UN)) {
throw new \RuntimeException(sprintf('Unable to release lock on %s', $this->file));
}
$this->closeFile();
} | [
"public",
"function",
"release",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"handler",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Lock is not acquired'",
")",
";",
"}",
"if",
"(",
"!",
"@",
"ftruncate",
"(",
"$",
"this",
"->",
"handler",
",",
"0",
")",
")",
"{",
"$",
"this",
"->",
"throwLastErrorException",
"(",
")",
";",
"}",
"if",
"(",
"!",
"flock",
"(",
"$",
"this",
"->",
"handler",
",",
"LOCK_UN",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Unable to release lock on %s'",
",",
"$",
"this",
"->",
"file",
")",
")",
";",
"}",
"$",
"this",
"->",
"closeFile",
"(",
")",
";",
"}"
] | Release the lock
@return void
@throws \LogicException if lock has not been acquired
@throws \ErrorException if could not truncate lock file
@throws \RuntimeException if could not release lock | [
"Release",
"the",
"lock"
] | 4aa0e5de4b7ee6857643bf69a25fbacb42381a71 | https://github.com/f3ath/flock/blob/4aa0e5de4b7ee6857643bf69a25fbacb42381a71/src/Lock.php#L88-L100 |
8,567 | as3io/modlr-persister-mongodb | src/Formatter.php | Formatter.getAttributeDbValue | public function getAttributeDbValue(AttributeMetadata $attrMeta, $value)
{
// Handle data type conversion, if needed.
if ('date' === $attrMeta->dataType && $value instanceof \DateTime) {
return new \MongoDate($value->getTimestamp(), $value->format('u'));
}
if ('array' === $attrMeta->dataType && empty($value)) {
return;
}
if ('object' === $attrMeta->dataType) {
$array = (array) $value;
return empty($array) ? null : $value;
}
return $value;
} | php | public function getAttributeDbValue(AttributeMetadata $attrMeta, $value)
{
// Handle data type conversion, if needed.
if ('date' === $attrMeta->dataType && $value instanceof \DateTime) {
return new \MongoDate($value->getTimestamp(), $value->format('u'));
}
if ('array' === $attrMeta->dataType && empty($value)) {
return;
}
if ('object' === $attrMeta->dataType) {
$array = (array) $value;
return empty($array) ? null : $value;
}
return $value;
} | [
"public",
"function",
"getAttributeDbValue",
"(",
"AttributeMetadata",
"$",
"attrMeta",
",",
"$",
"value",
")",
"{",
"// Handle data type conversion, if needed.",
"if",
"(",
"'date'",
"===",
"$",
"attrMeta",
"->",
"dataType",
"&&",
"$",
"value",
"instanceof",
"\\",
"DateTime",
")",
"{",
"return",
"new",
"\\",
"MongoDate",
"(",
"$",
"value",
"->",
"getTimestamp",
"(",
")",
",",
"$",
"value",
"->",
"format",
"(",
"'u'",
")",
")",
";",
"}",
"if",
"(",
"'array'",
"===",
"$",
"attrMeta",
"->",
"dataType",
"&&",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"'object'",
"===",
"$",
"attrMeta",
"->",
"dataType",
")",
"{",
"$",
"array",
"=",
"(",
"array",
")",
"$",
"value",
";",
"return",
"empty",
"(",
"$",
"array",
")",
"?",
"null",
":",
"$",
"value",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Prepares and formats an attribute value for proper insertion into the database.
@param AttributeMetadata $attrMeta
@param mixed $value
@return mixed | [
"Prepares",
"and",
"formats",
"an",
"attribute",
"value",
"for",
"proper",
"insertion",
"into",
"the",
"database",
"."
] | 7f7474d1996167d3b03a72ead42c0662166506a3 | https://github.com/as3io/modlr-persister-mongodb/blob/7f7474d1996167d3b03a72ead42c0662166506a3/src/Formatter.php#L80-L94 |
8,568 | as3io/modlr-persister-mongodb | src/Formatter.php | Formatter.getEmbedManyDbValue | public function getEmbedManyDbValue(EmbeddedPropMetadata $embeddedPropMeta, $embeds = null)
{
if (null === $embeds) {
return;
}
if (!is_array($embeds) && !$embeds instanceof \Traversable) {
throw new \InvalidArgumentException('Unable to traverse the embed collection');
}
$created = [];
foreach ($embeds as $embed) {
$created[] = $this->createEmbed($embeddedPropMeta, $embed);
}
return empty($created) ? null : $created;
} | php | public function getEmbedManyDbValue(EmbeddedPropMetadata $embeddedPropMeta, $embeds = null)
{
if (null === $embeds) {
return;
}
if (!is_array($embeds) && !$embeds instanceof \Traversable) {
throw new \InvalidArgumentException('Unable to traverse the embed collection');
}
$created = [];
foreach ($embeds as $embed) {
$created[] = $this->createEmbed($embeddedPropMeta, $embed);
}
return empty($created) ? null : $created;
} | [
"public",
"function",
"getEmbedManyDbValue",
"(",
"EmbeddedPropMetadata",
"$",
"embeddedPropMeta",
",",
"$",
"embeds",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"embeds",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"embeds",
")",
"&&",
"!",
"$",
"embeds",
"instanceof",
"\\",
"Traversable",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Unable to traverse the embed collection'",
")",
";",
"}",
"$",
"created",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"embeds",
"as",
"$",
"embed",
")",
"{",
"$",
"created",
"[",
"]",
"=",
"$",
"this",
"->",
"createEmbed",
"(",
"$",
"embeddedPropMeta",
",",
"$",
"embed",
")",
";",
"}",
"return",
"empty",
"(",
"$",
"created",
")",
"?",
"null",
":",
"$",
"created",
";",
"}"
] | Prepares and formats a has-many embed for proper insertion into the database.
@param EmbeddedPropMetadata $embeddedPropMeta
@param EmbedCollection|array|null $embeds
@return mixed | [
"Prepares",
"and",
"formats",
"a",
"has",
"-",
"many",
"embed",
"for",
"proper",
"insertion",
"into",
"the",
"database",
"."
] | 7f7474d1996167d3b03a72ead42c0662166506a3 | https://github.com/as3io/modlr-persister-mongodb/blob/7f7474d1996167d3b03a72ead42c0662166506a3/src/Formatter.php#L103-L117 |
8,569 | as3io/modlr-persister-mongodb | src/Formatter.php | Formatter.getEmbedOneDbValue | public function getEmbedOneDbValue(EmbeddedPropMetadata $embeddedPropMeta, Embed $embed = null)
{
if (null === $embed) {
return;
}
return $this->createEmbed($embeddedPropMeta, $embed);
} | php | public function getEmbedOneDbValue(EmbeddedPropMetadata $embeddedPropMeta, Embed $embed = null)
{
if (null === $embed) {
return;
}
return $this->createEmbed($embeddedPropMeta, $embed);
} | [
"public",
"function",
"getEmbedOneDbValue",
"(",
"EmbeddedPropMetadata",
"$",
"embeddedPropMeta",
",",
"Embed",
"$",
"embed",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"embed",
")",
"{",
"return",
";",
"}",
"return",
"$",
"this",
"->",
"createEmbed",
"(",
"$",
"embeddedPropMeta",
",",
"$",
"embed",
")",
";",
"}"
] | Prepares and formats a has-one embed for proper insertion into the database.
@param EmbeddedPropMetadata $embeddedPropMeta
@param Embed|null $embed
@return mixed | [
"Prepares",
"and",
"formats",
"a",
"has",
"-",
"one",
"embed",
"for",
"proper",
"insertion",
"into",
"the",
"database",
"."
] | 7f7474d1996167d3b03a72ead42c0662166506a3 | https://github.com/as3io/modlr-persister-mongodb/blob/7f7474d1996167d3b03a72ead42c0662166506a3/src/Formatter.php#L126-L132 |
8,570 | as3io/modlr-persister-mongodb | src/Formatter.php | Formatter.getHasOneDbValue | public function getHasOneDbValue(RelationshipMetadata $relMeta, Model $model = null)
{
if (null === $model || true === $relMeta->isInverse) {
return;
}
return $this->createReference($relMeta, $model);
} | php | public function getHasOneDbValue(RelationshipMetadata $relMeta, Model $model = null)
{
if (null === $model || true === $relMeta->isInverse) {
return;
}
return $this->createReference($relMeta, $model);
} | [
"public",
"function",
"getHasOneDbValue",
"(",
"RelationshipMetadata",
"$",
"relMeta",
",",
"Model",
"$",
"model",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"model",
"||",
"true",
"===",
"$",
"relMeta",
"->",
"isInverse",
")",
"{",
"return",
";",
"}",
"return",
"$",
"this",
"->",
"createReference",
"(",
"$",
"relMeta",
",",
"$",
"model",
")",
";",
"}"
] | Prepares and formats a has-one relationship model for proper insertion into the database.
@param RelationshipMetadata $relMeta
@param Model|null $model
@return mixed | [
"Prepares",
"and",
"formats",
"a",
"has",
"-",
"one",
"relationship",
"model",
"for",
"proper",
"insertion",
"into",
"the",
"database",
"."
] | 7f7474d1996167d3b03a72ead42c0662166506a3 | https://github.com/as3io/modlr-persister-mongodb/blob/7f7474d1996167d3b03a72ead42c0662166506a3/src/Formatter.php#L141-L147 |
8,571 | as3io/modlr-persister-mongodb | src/Formatter.php | Formatter.getHasManyDbValue | public function getHasManyDbValue(RelationshipMetadata $relMeta, array $models = null)
{
if (null === $models || true === $relMeta->isInverse) {
return null;
}
$references = [];
foreach ($models as $model) {
$references[] = $this->createReference($relMeta, $model);
}
return empty($references) ? null : $references;
} | php | public function getHasManyDbValue(RelationshipMetadata $relMeta, array $models = null)
{
if (null === $models || true === $relMeta->isInverse) {
return null;
}
$references = [];
foreach ($models as $model) {
$references[] = $this->createReference($relMeta, $model);
}
return empty($references) ? null : $references;
} | [
"public",
"function",
"getHasManyDbValue",
"(",
"RelationshipMetadata",
"$",
"relMeta",
",",
"array",
"$",
"models",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"models",
"||",
"true",
"===",
"$",
"relMeta",
"->",
"isInverse",
")",
"{",
"return",
"null",
";",
"}",
"$",
"references",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"models",
"as",
"$",
"model",
")",
"{",
"$",
"references",
"[",
"]",
"=",
"$",
"this",
"->",
"createReference",
"(",
"$",
"relMeta",
",",
"$",
"model",
")",
";",
"}",
"return",
"empty",
"(",
"$",
"references",
")",
"?",
"null",
":",
"$",
"references",
";",
"}"
] | Prepares and formats a has-many relationship model set for proper insertion into the database.
@param RelationshipMetadata $relMeta
@param Model[]|null $models
@return mixed | [
"Prepares",
"and",
"formats",
"a",
"has",
"-",
"many",
"relationship",
"model",
"set",
"for",
"proper",
"insertion",
"into",
"the",
"database",
"."
] | 7f7474d1996167d3b03a72ead42c0662166506a3 | https://github.com/as3io/modlr-persister-mongodb/blob/7f7474d1996167d3b03a72ead42c0662166506a3/src/Formatter.php#L156-L166 |
8,572 | as3io/modlr-persister-mongodb | src/Formatter.php | Formatter.createEmbed | private function createEmbed(EmbeddedPropMetadata $embeddedPropMeta, Embed $embed)
{
$embedMeta = $embeddedPropMeta->embedMeta;
$obj = [];
foreach ($embedMeta->getAttributes() as $key => $attrMeta) {
$value = $this->getAttributeDbValue($attrMeta, $embed->get($key));
if (null === $value) {
continue;
}
$obj[$key] = $value;
}
foreach ($embedMeta->getEmbeds() as $key => $propMeta) {
$value = (true === $propMeta->isOne()) ? $this->getEmbedOneDbValue($propMeta, $embed->get($key)) : $this->getEmbedManyDbValue($propMeta, $embed->get($key));
if (null === $value) {
continue;
}
$obj[$key] = $value;
}
return $obj;
} | php | private function createEmbed(EmbeddedPropMetadata $embeddedPropMeta, Embed $embed)
{
$embedMeta = $embeddedPropMeta->embedMeta;
$obj = [];
foreach ($embedMeta->getAttributes() as $key => $attrMeta) {
$value = $this->getAttributeDbValue($attrMeta, $embed->get($key));
if (null === $value) {
continue;
}
$obj[$key] = $value;
}
foreach ($embedMeta->getEmbeds() as $key => $propMeta) {
$value = (true === $propMeta->isOne()) ? $this->getEmbedOneDbValue($propMeta, $embed->get($key)) : $this->getEmbedManyDbValue($propMeta, $embed->get($key));
if (null === $value) {
continue;
}
$obj[$key] = $value;
}
return $obj;
} | [
"private",
"function",
"createEmbed",
"(",
"EmbeddedPropMetadata",
"$",
"embeddedPropMeta",
",",
"Embed",
"$",
"embed",
")",
"{",
"$",
"embedMeta",
"=",
"$",
"embeddedPropMeta",
"->",
"embedMeta",
";",
"$",
"obj",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"embedMeta",
"->",
"getAttributes",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"attrMeta",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"getAttributeDbValue",
"(",
"$",
"attrMeta",
",",
"$",
"embed",
"->",
"get",
"(",
"$",
"key",
")",
")",
";",
"if",
"(",
"null",
"===",
"$",
"value",
")",
"{",
"continue",
";",
"}",
"$",
"obj",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"foreach",
"(",
"$",
"embedMeta",
"->",
"getEmbeds",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"propMeta",
")",
"{",
"$",
"value",
"=",
"(",
"true",
"===",
"$",
"propMeta",
"->",
"isOne",
"(",
")",
")",
"?",
"$",
"this",
"->",
"getEmbedOneDbValue",
"(",
"$",
"propMeta",
",",
"$",
"embed",
"->",
"get",
"(",
"$",
"key",
")",
")",
":",
"$",
"this",
"->",
"getEmbedManyDbValue",
"(",
"$",
"propMeta",
",",
"$",
"embed",
"->",
"get",
"(",
"$",
"key",
")",
")",
";",
"if",
"(",
"null",
"===",
"$",
"value",
")",
"{",
"continue",
";",
"}",
"$",
"obj",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"obj",
";",
"}"
] | Creates an embed for storage of an embed model in the database
@param EmbeddedPropMetadata $embeddedPropMeta
@param Embed $embed
@return array|null | [
"Creates",
"an",
"embed",
"for",
"storage",
"of",
"an",
"embed",
"model",
"in",
"the",
"database"
] | 7f7474d1996167d3b03a72ead42c0662166506a3 | https://github.com/as3io/modlr-persister-mongodb/blob/7f7474d1996167d3b03a72ead42c0662166506a3/src/Formatter.php#L244-L264 |
8,573 | as3io/modlr-persister-mongodb | src/Formatter.php | Formatter.createReference | private function createReference(RelationshipMetadata $relMeta, Model $model)
{
$reference = [];
$identifier = $this->getIdentifierDbValue($model->getId());
if (true === $relMeta->isPolymorphic()) {
$reference[Persister::IDENTIFIER_KEY] = $identifier;
$reference[Persister::POLYMORPHIC_KEY] = $model->getType();
return $reference;
}
return $identifier;
} | php | private function createReference(RelationshipMetadata $relMeta, Model $model)
{
$reference = [];
$identifier = $this->getIdentifierDbValue($model->getId());
if (true === $relMeta->isPolymorphic()) {
$reference[Persister::IDENTIFIER_KEY] = $identifier;
$reference[Persister::POLYMORPHIC_KEY] = $model->getType();
return $reference;
}
return $identifier;
} | [
"private",
"function",
"createReference",
"(",
"RelationshipMetadata",
"$",
"relMeta",
",",
"Model",
"$",
"model",
")",
"{",
"$",
"reference",
"=",
"[",
"]",
";",
"$",
"identifier",
"=",
"$",
"this",
"->",
"getIdentifierDbValue",
"(",
"$",
"model",
"->",
"getId",
"(",
")",
")",
";",
"if",
"(",
"true",
"===",
"$",
"relMeta",
"->",
"isPolymorphic",
"(",
")",
")",
"{",
"$",
"reference",
"[",
"Persister",
"::",
"IDENTIFIER_KEY",
"]",
"=",
"$",
"identifier",
";",
"$",
"reference",
"[",
"Persister",
"::",
"POLYMORPHIC_KEY",
"]",
"=",
"$",
"model",
"->",
"getType",
"(",
")",
";",
"return",
"$",
"reference",
";",
"}",
"return",
"$",
"identifier",
";",
"}"
] | Creates a reference for storage of a related model in the database
@param RelationshipMetadata $relMeta
@param Model $model
@return mixed | [
"Creates",
"a",
"reference",
"for",
"storage",
"of",
"a",
"related",
"model",
"in",
"the",
"database"
] | 7f7474d1996167d3b03a72ead42c0662166506a3 | https://github.com/as3io/modlr-persister-mongodb/blob/7f7474d1996167d3b03a72ead42c0662166506a3/src/Formatter.php#L273-L283 |
8,574 | as3io/modlr-persister-mongodb | src/Formatter.php | Formatter.formatQueryElement | private function formatQueryElement($key, $value, EntityMetadata $metadata, Store $store)
{
// Handle root fields: id or model type.
if (null !== $result = $this->formatQueryElementRoot($key, $value, $metadata)) {
return $result;
}
// Handle attributes.
if (null !== $result = $this->formatQueryElementAttr($key, $value, $metadata, $store)) {
return $result;
}
// Handle relationships.
if (null !== $result = $this->formatQueryElementRel($key, $value, $metadata, $store)) {
return $result;
}
// Handle dot notated fields.
if (null !== $result = $this->formatQueryElementDotted($key, $value, $metadata, $store)) {
return $result;
}
// Pass remaining elements unconverted.
return [$key, $value];
} | php | private function formatQueryElement($key, $value, EntityMetadata $metadata, Store $store)
{
// Handle root fields: id or model type.
if (null !== $result = $this->formatQueryElementRoot($key, $value, $metadata)) {
return $result;
}
// Handle attributes.
if (null !== $result = $this->formatQueryElementAttr($key, $value, $metadata, $store)) {
return $result;
}
// Handle relationships.
if (null !== $result = $this->formatQueryElementRel($key, $value, $metadata, $store)) {
return $result;
}
// Handle dot notated fields.
if (null !== $result = $this->formatQueryElementDotted($key, $value, $metadata, $store)) {
return $result;
}
// Pass remaining elements unconverted.
return [$key, $value];
} | [
"private",
"function",
"formatQueryElement",
"(",
"$",
"key",
",",
"$",
"value",
",",
"EntityMetadata",
"$",
"metadata",
",",
"Store",
"$",
"store",
")",
"{",
"// Handle root fields: id or model type.",
"if",
"(",
"null",
"!==",
"$",
"result",
"=",
"$",
"this",
"->",
"formatQueryElementRoot",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"metadata",
")",
")",
"{",
"return",
"$",
"result",
";",
"}",
"// Handle attributes.",
"if",
"(",
"null",
"!==",
"$",
"result",
"=",
"$",
"this",
"->",
"formatQueryElementAttr",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"metadata",
",",
"$",
"store",
")",
")",
"{",
"return",
"$",
"result",
";",
"}",
"// Handle relationships.",
"if",
"(",
"null",
"!==",
"$",
"result",
"=",
"$",
"this",
"->",
"formatQueryElementRel",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"metadata",
",",
"$",
"store",
")",
")",
"{",
"return",
"$",
"result",
";",
"}",
"// Handle dot notated fields.",
"if",
"(",
"null",
"!==",
"$",
"result",
"=",
"$",
"this",
"->",
"formatQueryElementDotted",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"metadata",
",",
"$",
"store",
")",
")",
"{",
"return",
"$",
"result",
";",
"}",
"// Pass remaining elements unconverted.",
"return",
"[",
"$",
"key",
",",
"$",
"value",
"]",
";",
"}"
] | Formats a query element and ensures the correct key and value are set.
Returns a tuple of the formatted key and value.
@param string $key
@param mixed $value
@param EntityMetadata $metadata
@param Store $store
@return array | [
"Formats",
"a",
"query",
"element",
"and",
"ensures",
"the",
"correct",
"key",
"and",
"value",
"are",
"set",
".",
"Returns",
"a",
"tuple",
"of",
"the",
"formatted",
"key",
"and",
"value",
"."
] | 7f7474d1996167d3b03a72ead42c0662166506a3 | https://github.com/as3io/modlr-persister-mongodb/blob/7f7474d1996167d3b03a72ead42c0662166506a3/src/Formatter.php#L295-L319 |
8,575 | as3io/modlr-persister-mongodb | src/Formatter.php | Formatter.formatQueryElementAttr | private function formatQueryElementAttr($key, $value, EntityMetadata $metadata, Store $store)
{
if (null === $attrMeta = $metadata->getAttribute($key)) {
return;
}
$converter = $this->getQueryAttrConverter($store, $attrMeta);
if (is_array($value)) {
if (true === $this->hasOperators($value)) {
return [$key, $this->formatQueryExpression($value, $converter)];
}
if (in_array($attrMeta->dataType, ['array', 'object'])) {
return [$key, $value];
}
return [$key, $this->formatQueryExpression(['$in' => $value], $converter)];
}
return [$key, $converter($value)];
} | php | private function formatQueryElementAttr($key, $value, EntityMetadata $metadata, Store $store)
{
if (null === $attrMeta = $metadata->getAttribute($key)) {
return;
}
$converter = $this->getQueryAttrConverter($store, $attrMeta);
if (is_array($value)) {
if (true === $this->hasOperators($value)) {
return [$key, $this->formatQueryExpression($value, $converter)];
}
if (in_array($attrMeta->dataType, ['array', 'object'])) {
return [$key, $value];
}
return [$key, $this->formatQueryExpression(['$in' => $value], $converter)];
}
return [$key, $converter($value)];
} | [
"private",
"function",
"formatQueryElementAttr",
"(",
"$",
"key",
",",
"$",
"value",
",",
"EntityMetadata",
"$",
"metadata",
",",
"Store",
"$",
"store",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"attrMeta",
"=",
"$",
"metadata",
"->",
"getAttribute",
"(",
"$",
"key",
")",
")",
"{",
"return",
";",
"}",
"$",
"converter",
"=",
"$",
"this",
"->",
"getQueryAttrConverter",
"(",
"$",
"store",
",",
"$",
"attrMeta",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"hasOperators",
"(",
"$",
"value",
")",
")",
"{",
"return",
"[",
"$",
"key",
",",
"$",
"this",
"->",
"formatQueryExpression",
"(",
"$",
"value",
",",
"$",
"converter",
")",
"]",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"attrMeta",
"->",
"dataType",
",",
"[",
"'array'",
",",
"'object'",
"]",
")",
")",
"{",
"return",
"[",
"$",
"key",
",",
"$",
"value",
"]",
";",
"}",
"return",
"[",
"$",
"key",
",",
"$",
"this",
"->",
"formatQueryExpression",
"(",
"[",
"'$in'",
"=>",
"$",
"value",
"]",
",",
"$",
"converter",
")",
"]",
";",
"}",
"return",
"[",
"$",
"key",
",",
"$",
"converter",
"(",
"$",
"value",
")",
"]",
";",
"}"
] | Formats an attribute query element.
Returns a tuple of the formatted key and value, or null if the key is not an attribute field.
@param string $key
@param mixed $value
@param EntityMetadata $metadata
@param Store $store
@return array|null | [
"Formats",
"an",
"attribute",
"query",
"element",
".",
"Returns",
"a",
"tuple",
"of",
"the",
"formatted",
"key",
"and",
"value",
"or",
"null",
"if",
"the",
"key",
"is",
"not",
"an",
"attribute",
"field",
"."
] | 7f7474d1996167d3b03a72ead42c0662166506a3 | https://github.com/as3io/modlr-persister-mongodb/blob/7f7474d1996167d3b03a72ead42c0662166506a3/src/Formatter.php#L331-L351 |
8,576 | as3io/modlr-persister-mongodb | src/Formatter.php | Formatter.formatQueryElementDotted | private function formatQueryElementDotted($key, $value, EntityMetadata $metadata, Store $store)
{
if (false === stripos($key, '.')) {
return;
}
$parts = explode('.', $key);
$root = array_shift($parts);
if (false === $metadata->hasRelationship($root)) {
// Nothing to format. Allow the dotted field to pass normally.
return [$key, $value];
}
$hasIndex = is_numeric($parts[0]);
if (true === $hasIndex) {
$subKey = isset($parts[1]) ? $parts[1] : 'id';
} else {
$subKey = $parts[0];
}
if ($this->isIdentifierField($subKey)) {
// Handle like a regular relationship
list($key, $value) = $this->formatQueryElementRel($root, $value, $metadata, $store);
$key = (true === $hasIndex) ? sprintf('%s.%s', $key, $parts[0]) : $key;
return [$key, $value];
}
if ($this->isTypeField($subKey)) {
// Handle as a model type field.
list($key, $value) = $this->formatQueryElementRoot($subKey, $value, $metadata);
$key = (true === $hasIndex) ? sprintf('%s.%s.%s', $root, $parts[0], $key) : sprintf('%s.%s', $root, $key);
return [$key, $value];
}
return [$key, $value];
} | php | private function formatQueryElementDotted($key, $value, EntityMetadata $metadata, Store $store)
{
if (false === stripos($key, '.')) {
return;
}
$parts = explode('.', $key);
$root = array_shift($parts);
if (false === $metadata->hasRelationship($root)) {
// Nothing to format. Allow the dotted field to pass normally.
return [$key, $value];
}
$hasIndex = is_numeric($parts[0]);
if (true === $hasIndex) {
$subKey = isset($parts[1]) ? $parts[1] : 'id';
} else {
$subKey = $parts[0];
}
if ($this->isIdentifierField($subKey)) {
// Handle like a regular relationship
list($key, $value) = $this->formatQueryElementRel($root, $value, $metadata, $store);
$key = (true === $hasIndex) ? sprintf('%s.%s', $key, $parts[0]) : $key;
return [$key, $value];
}
if ($this->isTypeField($subKey)) {
// Handle as a model type field.
list($key, $value) = $this->formatQueryElementRoot($subKey, $value, $metadata);
$key = (true === $hasIndex) ? sprintf('%s.%s.%s', $root, $parts[0], $key) : sprintf('%s.%s', $root, $key);
return [$key, $value];
}
return [$key, $value];
} | [
"private",
"function",
"formatQueryElementDotted",
"(",
"$",
"key",
",",
"$",
"value",
",",
"EntityMetadata",
"$",
"metadata",
",",
"Store",
"$",
"store",
")",
"{",
"if",
"(",
"false",
"===",
"stripos",
"(",
"$",
"key",
",",
"'.'",
")",
")",
"{",
"return",
";",
"}",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"$",
"root",
"=",
"array_shift",
"(",
"$",
"parts",
")",
";",
"if",
"(",
"false",
"===",
"$",
"metadata",
"->",
"hasRelationship",
"(",
"$",
"root",
")",
")",
"{",
"// Nothing to format. Allow the dotted field to pass normally.",
"return",
"[",
"$",
"key",
",",
"$",
"value",
"]",
";",
"}",
"$",
"hasIndex",
"=",
"is_numeric",
"(",
"$",
"parts",
"[",
"0",
"]",
")",
";",
"if",
"(",
"true",
"===",
"$",
"hasIndex",
")",
"{",
"$",
"subKey",
"=",
"isset",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
"?",
"$",
"parts",
"[",
"1",
"]",
":",
"'id'",
";",
"}",
"else",
"{",
"$",
"subKey",
"=",
"$",
"parts",
"[",
"0",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isIdentifierField",
"(",
"$",
"subKey",
")",
")",
"{",
"// Handle like a regular relationship",
"list",
"(",
"$",
"key",
",",
"$",
"value",
")",
"=",
"$",
"this",
"->",
"formatQueryElementRel",
"(",
"$",
"root",
",",
"$",
"value",
",",
"$",
"metadata",
",",
"$",
"store",
")",
";",
"$",
"key",
"=",
"(",
"true",
"===",
"$",
"hasIndex",
")",
"?",
"sprintf",
"(",
"'%s.%s'",
",",
"$",
"key",
",",
"$",
"parts",
"[",
"0",
"]",
")",
":",
"$",
"key",
";",
"return",
"[",
"$",
"key",
",",
"$",
"value",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isTypeField",
"(",
"$",
"subKey",
")",
")",
"{",
"// Handle as a model type field.",
"list",
"(",
"$",
"key",
",",
"$",
"value",
")",
"=",
"$",
"this",
"->",
"formatQueryElementRoot",
"(",
"$",
"subKey",
",",
"$",
"value",
",",
"$",
"metadata",
")",
";",
"$",
"key",
"=",
"(",
"true",
"===",
"$",
"hasIndex",
")",
"?",
"sprintf",
"(",
"'%s.%s.%s'",
",",
"$",
"root",
",",
"$",
"parts",
"[",
"0",
"]",
",",
"$",
"key",
")",
":",
"sprintf",
"(",
"'%s.%s'",
",",
"$",
"root",
",",
"$",
"key",
")",
";",
"return",
"[",
"$",
"key",
",",
"$",
"value",
"]",
";",
"}",
"return",
"[",
"$",
"key",
",",
"$",
"value",
"]",
";",
"}"
] | Formats a dot-notated field.
Returns a tuple of the formatted key and value, or null if the key is not a dot-notated field, or cannot be handled.
@param string $key
@param mixed $value
@param EntityMetadata $metadata
@param Store $store
@return array|null | [
"Formats",
"a",
"dot",
"-",
"notated",
"field",
".",
"Returns",
"a",
"tuple",
"of",
"the",
"formatted",
"key",
"and",
"value",
"or",
"null",
"if",
"the",
"key",
"is",
"not",
"a",
"dot",
"-",
"notated",
"field",
"or",
"cannot",
"be",
"handled",
"."
] | 7f7474d1996167d3b03a72ead42c0662166506a3 | https://github.com/as3io/modlr-persister-mongodb/blob/7f7474d1996167d3b03a72ead42c0662166506a3/src/Formatter.php#L363-L397 |
8,577 | as3io/modlr-persister-mongodb | src/Formatter.php | Formatter.formatQueryElementRel | private function formatQueryElementRel($key, $value, EntityMetadata $metadata, Store $store)
{
if (null === $relMeta = $metadata->getRelationship($key)) {
return;
}
$converter = $this->getQueryRelConverter($store, $relMeta);
if (true === $relMeta->isPolymorphic()) {
$key = sprintf('%s.%s', $key, Persister::IDENTIFIER_KEY);
}
if (is_array($value)) {
$value = (true === $this->hasOperators($value)) ? $value : ['$in' => $value];
return [$key, $this->formatQueryExpression($value, $converter)];
}
return [$key, $converter($value)];
} | php | private function formatQueryElementRel($key, $value, EntityMetadata $metadata, Store $store)
{
if (null === $relMeta = $metadata->getRelationship($key)) {
return;
}
$converter = $this->getQueryRelConverter($store, $relMeta);
if (true === $relMeta->isPolymorphic()) {
$key = sprintf('%s.%s', $key, Persister::IDENTIFIER_KEY);
}
if (is_array($value)) {
$value = (true === $this->hasOperators($value)) ? $value : ['$in' => $value];
return [$key, $this->formatQueryExpression($value, $converter)];
}
return [$key, $converter($value)];
} | [
"private",
"function",
"formatQueryElementRel",
"(",
"$",
"key",
",",
"$",
"value",
",",
"EntityMetadata",
"$",
"metadata",
",",
"Store",
"$",
"store",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"relMeta",
"=",
"$",
"metadata",
"->",
"getRelationship",
"(",
"$",
"key",
")",
")",
"{",
"return",
";",
"}",
"$",
"converter",
"=",
"$",
"this",
"->",
"getQueryRelConverter",
"(",
"$",
"store",
",",
"$",
"relMeta",
")",
";",
"if",
"(",
"true",
"===",
"$",
"relMeta",
"->",
"isPolymorphic",
"(",
")",
")",
"{",
"$",
"key",
"=",
"sprintf",
"(",
"'%s.%s'",
",",
"$",
"key",
",",
"Persister",
"::",
"IDENTIFIER_KEY",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"(",
"true",
"===",
"$",
"this",
"->",
"hasOperators",
"(",
"$",
"value",
")",
")",
"?",
"$",
"value",
":",
"[",
"'$in'",
"=>",
"$",
"value",
"]",
";",
"return",
"[",
"$",
"key",
",",
"$",
"this",
"->",
"formatQueryExpression",
"(",
"$",
"value",
",",
"$",
"converter",
")",
"]",
";",
"}",
"return",
"[",
"$",
"key",
",",
"$",
"converter",
"(",
"$",
"value",
")",
"]",
";",
"}"
] | Formats a relationship query element.
Returns a tuple of the formatted key and value, or null if the key is not a relationship field.
@param string $key
@param mixed $value
@param EntityMetadata $metadata
@param Store $store
@return array|null | [
"Formats",
"a",
"relationship",
"query",
"element",
".",
"Returns",
"a",
"tuple",
"of",
"the",
"formatted",
"key",
"and",
"value",
"or",
"null",
"if",
"the",
"key",
"is",
"not",
"a",
"relationship",
"field",
"."
] | 7f7474d1996167d3b03a72ead42c0662166506a3 | https://github.com/as3io/modlr-persister-mongodb/blob/7f7474d1996167d3b03a72ead42c0662166506a3/src/Formatter.php#L409-L426 |
8,578 | as3io/modlr-persister-mongodb | src/Formatter.php | Formatter.formatQueryExpression | private function formatQueryExpression(array $expression, Closure $converter)
{
foreach ($expression as $key => $value) {
if ('$regex' === $key && !$value instanceof \MongoRegex) {
$expression[$key] = new \MongoRegex($value);
continue;
}
if (true === $this->isOpType('ignore', $key)) {
continue;
}
if (true === $this->isOpType('single', $key)) {
$expression[$key] = $converter($value);
continue;
}
if (true === $this->isOpType('multiple', $key)) {
$value = (array) $value;
foreach ($value as $subKey => $subValue) {
$expression[$key][$subKey] = $converter($subValue);
}
continue;
}
if (true === $this->isOpType('recursive', $key)) {
$value = (array) $value;
$expression[$key] = $this->formatQueryExpression($value, $converter);
continue;
}
$expression[$key] = $converter($value);
}
return $expression;
} | php | private function formatQueryExpression(array $expression, Closure $converter)
{
foreach ($expression as $key => $value) {
if ('$regex' === $key && !$value instanceof \MongoRegex) {
$expression[$key] = new \MongoRegex($value);
continue;
}
if (true === $this->isOpType('ignore', $key)) {
continue;
}
if (true === $this->isOpType('single', $key)) {
$expression[$key] = $converter($value);
continue;
}
if (true === $this->isOpType('multiple', $key)) {
$value = (array) $value;
foreach ($value as $subKey => $subValue) {
$expression[$key][$subKey] = $converter($subValue);
}
continue;
}
if (true === $this->isOpType('recursive', $key)) {
$value = (array) $value;
$expression[$key] = $this->formatQueryExpression($value, $converter);
continue;
}
$expression[$key] = $converter($value);
}
return $expression;
} | [
"private",
"function",
"formatQueryExpression",
"(",
"array",
"$",
"expression",
",",
"Closure",
"$",
"converter",
")",
"{",
"foreach",
"(",
"$",
"expression",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"'$regex'",
"===",
"$",
"key",
"&&",
"!",
"$",
"value",
"instanceof",
"\\",
"MongoRegex",
")",
"{",
"$",
"expression",
"[",
"$",
"key",
"]",
"=",
"new",
"\\",
"MongoRegex",
"(",
"$",
"value",
")",
";",
"continue",
";",
"}",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"isOpType",
"(",
"'ignore'",
",",
"$",
"key",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"isOpType",
"(",
"'single'",
",",
"$",
"key",
")",
")",
"{",
"$",
"expression",
"[",
"$",
"key",
"]",
"=",
"$",
"converter",
"(",
"$",
"value",
")",
";",
"continue",
";",
"}",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"isOpType",
"(",
"'multiple'",
",",
"$",
"key",
")",
")",
"{",
"$",
"value",
"=",
"(",
"array",
")",
"$",
"value",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"subKey",
"=>",
"$",
"subValue",
")",
"{",
"$",
"expression",
"[",
"$",
"key",
"]",
"[",
"$",
"subKey",
"]",
"=",
"$",
"converter",
"(",
"$",
"subValue",
")",
";",
"}",
"continue",
";",
"}",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"isOpType",
"(",
"'recursive'",
",",
"$",
"key",
")",
")",
"{",
"$",
"value",
"=",
"(",
"array",
")",
"$",
"value",
";",
"$",
"expression",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"formatQueryExpression",
"(",
"$",
"value",
",",
"$",
"converter",
")",
";",
"continue",
";",
"}",
"$",
"expression",
"[",
"$",
"key",
"]",
"=",
"$",
"converter",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"expression",
";",
"}"
] | Formats a query expression.
@param array $expression
@param Closure $converter
@return array | [
"Formats",
"a",
"query",
"expression",
"."
] | 7f7474d1996167d3b03a72ead42c0662166506a3 | https://github.com/as3io/modlr-persister-mongodb/blob/7f7474d1996167d3b03a72ead42c0662166506a3/src/Formatter.php#L463-L498 |
8,579 | as3io/modlr-persister-mongodb | src/Formatter.php | Formatter.getQueryAttrConverter | private function getQueryAttrConverter(Store $store, AttributeMetadata $attrMeta)
{
return function ($value) use ($store, $attrMeta) {
if (in_array($attrMeta->dataType, ['object', 'array'])) {
// Leave the value as is.
return $value;
}
$value = $store->convertAttributeValue($attrMeta->dataType, $value);
return $this->getAttributeDbValue($attrMeta, $value);
};
} | php | private function getQueryAttrConverter(Store $store, AttributeMetadata $attrMeta)
{
return function ($value) use ($store, $attrMeta) {
if (in_array($attrMeta->dataType, ['object', 'array'])) {
// Leave the value as is.
return $value;
}
$value = $store->convertAttributeValue($attrMeta->dataType, $value);
return $this->getAttributeDbValue($attrMeta, $value);
};
} | [
"private",
"function",
"getQueryAttrConverter",
"(",
"Store",
"$",
"store",
",",
"AttributeMetadata",
"$",
"attrMeta",
")",
"{",
"return",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"$",
"store",
",",
"$",
"attrMeta",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"attrMeta",
"->",
"dataType",
",",
"[",
"'object'",
",",
"'array'",
"]",
")",
")",
"{",
"// Leave the value as is.",
"return",
"$",
"value",
";",
"}",
"$",
"value",
"=",
"$",
"store",
"->",
"convertAttributeValue",
"(",
"$",
"attrMeta",
"->",
"dataType",
",",
"$",
"value",
")",
";",
"return",
"$",
"this",
"->",
"getAttributeDbValue",
"(",
"$",
"attrMeta",
",",
"$",
"value",
")",
";",
"}",
";",
"}"
] | Gets the converter for handling attribute values in queries.
@param Store $store
@param AttributeMetadata $attrMeta
@return Closure | [
"Gets",
"the",
"converter",
"for",
"handling",
"attribute",
"values",
"in",
"queries",
"."
] | 7f7474d1996167d3b03a72ead42c0662166506a3 | https://github.com/as3io/modlr-persister-mongodb/blob/7f7474d1996167d3b03a72ead42c0662166506a3/src/Formatter.php#L507-L518 |
8,580 | as3io/modlr-persister-mongodb | src/Formatter.php | Formatter.getQueryRelConverter | private function getQueryRelConverter(Store $store, RelationshipMetadata $relMeta)
{
$related = $store->getMetadataForType($relMeta->getEntityType());
return $this->getQueryRootConverter($related, Persister::IDENTIFIER_KEY);
} | php | private function getQueryRelConverter(Store $store, RelationshipMetadata $relMeta)
{
$related = $store->getMetadataForType($relMeta->getEntityType());
return $this->getQueryRootConverter($related, Persister::IDENTIFIER_KEY);
} | [
"private",
"function",
"getQueryRelConverter",
"(",
"Store",
"$",
"store",
",",
"RelationshipMetadata",
"$",
"relMeta",
")",
"{",
"$",
"related",
"=",
"$",
"store",
"->",
"getMetadataForType",
"(",
"$",
"relMeta",
"->",
"getEntityType",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"getQueryRootConverter",
"(",
"$",
"related",
",",
"Persister",
"::",
"IDENTIFIER_KEY",
")",
";",
"}"
] | Gets the converter for handling relationship values in queries.
@param Store $store
@param RelationshipMetadata $relMeta
@return Closure | [
"Gets",
"the",
"converter",
"for",
"handling",
"relationship",
"values",
"in",
"queries",
"."
] | 7f7474d1996167d3b03a72ead42c0662166506a3 | https://github.com/as3io/modlr-persister-mongodb/blob/7f7474d1996167d3b03a72ead42c0662166506a3/src/Formatter.php#L527-L531 |
8,581 | as3io/modlr-persister-mongodb | src/Formatter.php | Formatter.hasOperators | private function hasOperators($value)
{
if (!is_array($value) && !is_object($value)) {
return false;
}
if (is_object($value)) {
$value = get_object_vars($value);
}
foreach ($value as $key => $subValue) {
if (true === $this->isOperator($key)) {
return true;
}
}
return false;
} | php | private function hasOperators($value)
{
if (!is_array($value) && !is_object($value)) {
return false;
}
if (is_object($value)) {
$value = get_object_vars($value);
}
foreach ($value as $key => $subValue) {
if (true === $this->isOperator($key)) {
return true;
}
}
return false;
} | [
"private",
"function",
"hasOperators",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
"&&",
"!",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"get_object_vars",
"(",
"$",
"value",
")",
";",
"}",
"foreach",
"(",
"$",
"value",
"as",
"$",
"key",
"=>",
"$",
"subValue",
")",
"{",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"isOperator",
"(",
"$",
"key",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Determines whether a query value has additional query operators.
@param mixed $value
@return bool | [
"Determines",
"whether",
"a",
"query",
"value",
"has",
"additional",
"query",
"operators",
"."
] | 7f7474d1996167d3b03a72ead42c0662166506a3 | https://github.com/as3io/modlr-persister-mongodb/blob/7f7474d1996167d3b03a72ead42c0662166506a3/src/Formatter.php#L557-L574 |
8,582 | as3io/modlr-persister-mongodb | src/Formatter.php | Formatter.isOpType | private function isOpType($type, $key)
{
if (!isset($this->ops[$type])) {
return false;
}
return in_array($key, $this->ops[$type]);
} | php | private function isOpType($type, $key)
{
if (!isset($this->ops[$type])) {
return false;
}
return in_array($key, $this->ops[$type]);
} | [
"private",
"function",
"isOpType",
"(",
"$",
"type",
",",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"ops",
"[",
"$",
"type",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"in_array",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"ops",
"[",
"$",
"type",
"]",
")",
";",
"}"
] | Determines if a key is of a certain operator handling type.
@param string $type
@param string $key
@return bool | [
"Determines",
"if",
"a",
"key",
"is",
"of",
"a",
"certain",
"operator",
"handling",
"type",
"."
] | 7f7474d1996167d3b03a72ead42c0662166506a3 | https://github.com/as3io/modlr-persister-mongodb/blob/7f7474d1996167d3b03a72ead42c0662166506a3/src/Formatter.php#L594-L600 |
8,583 | mszewcz/php-light-framework | src/Validator/Specific/Alnum.php | Alnum.validateAlnum | private function validateAlnum(): bool
{
$charClass = '[:alnum:]';
if ($this->options['allow-spaces'] === true) {
$charClass .= '[:space:]';
}
if ($this->options['allow-whitespaces'] === true) {
$charClass .= '[:blank:]';
}
$modifier = '';
if ($this->options['utf-8'] === true) {
$modifier = 'u';
}
$isValid = \preg_match('/^['.$charClass.']+$/'.$modifier, $this->value) ? true : false;
if (!$isValid) {
$this->setError(self::VALIDATOR_ERROR_ALNUM_NOT_VALID);
if ($this->options['allow-whitespaces'] === true && $this->options['allow-spaces'] === true) {
$this->setError(self::VALIDATOR_ERROR_ALNUM_SPACES_WHITESPACES_NOT_VALID);
} elseif ($this->options['allow-whitespaces'] === true) {
$this->setError(self::VALIDATOR_ERROR_ALNUM_WHITESPACES_NOT_VALID);
} elseif ($this->options['allow-spaces'] === true) {
$this->setError(self::VALIDATOR_ERROR_ALNUM_SPACES_NOT_VALID);
}
}
return $isValid;
} | php | private function validateAlnum(): bool
{
$charClass = '[:alnum:]';
if ($this->options['allow-spaces'] === true) {
$charClass .= '[:space:]';
}
if ($this->options['allow-whitespaces'] === true) {
$charClass .= '[:blank:]';
}
$modifier = '';
if ($this->options['utf-8'] === true) {
$modifier = 'u';
}
$isValid = \preg_match('/^['.$charClass.']+$/'.$modifier, $this->value) ? true : false;
if (!$isValid) {
$this->setError(self::VALIDATOR_ERROR_ALNUM_NOT_VALID);
if ($this->options['allow-whitespaces'] === true && $this->options['allow-spaces'] === true) {
$this->setError(self::VALIDATOR_ERROR_ALNUM_SPACES_WHITESPACES_NOT_VALID);
} elseif ($this->options['allow-whitespaces'] === true) {
$this->setError(self::VALIDATOR_ERROR_ALNUM_WHITESPACES_NOT_VALID);
} elseif ($this->options['allow-spaces'] === true) {
$this->setError(self::VALIDATOR_ERROR_ALNUM_SPACES_NOT_VALID);
}
}
return $isValid;
} | [
"private",
"function",
"validateAlnum",
"(",
")",
":",
"bool",
"{",
"$",
"charClass",
"=",
"'[:alnum:]'",
";",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"'allow-spaces'",
"]",
"===",
"true",
")",
"{",
"$",
"charClass",
".=",
"'[:space:]'",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"'allow-whitespaces'",
"]",
"===",
"true",
")",
"{",
"$",
"charClass",
".=",
"'[:blank:]'",
";",
"}",
"$",
"modifier",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"'utf-8'",
"]",
"===",
"true",
")",
"{",
"$",
"modifier",
"=",
"'u'",
";",
"}",
"$",
"isValid",
"=",
"\\",
"preg_match",
"(",
"'/^['",
".",
"$",
"charClass",
".",
"']+$/'",
".",
"$",
"modifier",
",",
"$",
"this",
"->",
"value",
")",
"?",
"true",
":",
"false",
";",
"if",
"(",
"!",
"$",
"isValid",
")",
"{",
"$",
"this",
"->",
"setError",
"(",
"self",
"::",
"VALIDATOR_ERROR_ALNUM_NOT_VALID",
")",
";",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"'allow-whitespaces'",
"]",
"===",
"true",
"&&",
"$",
"this",
"->",
"options",
"[",
"'allow-spaces'",
"]",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"setError",
"(",
"self",
"::",
"VALIDATOR_ERROR_ALNUM_SPACES_WHITESPACES_NOT_VALID",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"options",
"[",
"'allow-whitespaces'",
"]",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"setError",
"(",
"self",
"::",
"VALIDATOR_ERROR_ALNUM_WHITESPACES_NOT_VALID",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"options",
"[",
"'allow-spaces'",
"]",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"setError",
"(",
"self",
"::",
"VALIDATOR_ERROR_ALNUM_SPACES_NOT_VALID",
")",
";",
"}",
"}",
"return",
"$",
"isValid",
";",
"}"
] | Checks whether string is valid alnum string
@return bool | [
"Checks",
"whether",
"string",
"is",
"valid",
"alnum",
"string"
] | 4d3b46781c387202c2dfbdb8760151b3ae8ef49c | https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Validator/Specific/Alnum.php#L47-L74 |
8,584 | weew/app | src/Weew/App/App.php | App.start | public function start() {
if ($this->started) {
return;
}
$this->started = true;
$this->getConfigLoader()->setEnvironment($this->getEnvironment());
$this->config = $this->getConfigLoader()->load();
$this->container->set([Config::class, IConfig::class], $this->config);
$this->config->set('env', $this->getEnvironment());
$this->config->set('debug', $this->getDebug());
$this->eventer->dispatch(new ConfigLoadedEvent($this->config));
$this->kernel->initialize();
$this->eventer->dispatch(new KernelInitializedEvent($this->kernel));
$this->kernel->boot();
$this->eventer->dispatch(new KernelBootedEvent($this->kernel));
$this->eventer->dispatch(new AppStartedEvent($this));
} | php | public function start() {
if ($this->started) {
return;
}
$this->started = true;
$this->getConfigLoader()->setEnvironment($this->getEnvironment());
$this->config = $this->getConfigLoader()->load();
$this->container->set([Config::class, IConfig::class], $this->config);
$this->config->set('env', $this->getEnvironment());
$this->config->set('debug', $this->getDebug());
$this->eventer->dispatch(new ConfigLoadedEvent($this->config));
$this->kernel->initialize();
$this->eventer->dispatch(new KernelInitializedEvent($this->kernel));
$this->kernel->boot();
$this->eventer->dispatch(new KernelBootedEvent($this->kernel));
$this->eventer->dispatch(new AppStartedEvent($this));
} | [
"public",
"function",
"start",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"started",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"started",
"=",
"true",
";",
"$",
"this",
"->",
"getConfigLoader",
"(",
")",
"->",
"setEnvironment",
"(",
"$",
"this",
"->",
"getEnvironment",
"(",
")",
")",
";",
"$",
"this",
"->",
"config",
"=",
"$",
"this",
"->",
"getConfigLoader",
"(",
")",
"->",
"load",
"(",
")",
";",
"$",
"this",
"->",
"container",
"->",
"set",
"(",
"[",
"Config",
"::",
"class",
",",
"IConfig",
"::",
"class",
"]",
",",
"$",
"this",
"->",
"config",
")",
";",
"$",
"this",
"->",
"config",
"->",
"set",
"(",
"'env'",
",",
"$",
"this",
"->",
"getEnvironment",
"(",
")",
")",
";",
"$",
"this",
"->",
"config",
"->",
"set",
"(",
"'debug'",
",",
"$",
"this",
"->",
"getDebug",
"(",
")",
")",
";",
"$",
"this",
"->",
"eventer",
"->",
"dispatch",
"(",
"new",
"ConfigLoadedEvent",
"(",
"$",
"this",
"->",
"config",
")",
")",
";",
"$",
"this",
"->",
"kernel",
"->",
"initialize",
"(",
")",
";",
"$",
"this",
"->",
"eventer",
"->",
"dispatch",
"(",
"new",
"KernelInitializedEvent",
"(",
"$",
"this",
"->",
"kernel",
")",
")",
";",
"$",
"this",
"->",
"kernel",
"->",
"boot",
"(",
")",
";",
"$",
"this",
"->",
"eventer",
"->",
"dispatch",
"(",
"new",
"KernelBootedEvent",
"(",
"$",
"this",
"->",
"kernel",
")",
")",
";",
"$",
"this",
"->",
"eventer",
"->",
"dispatch",
"(",
"new",
"AppStartedEvent",
"(",
"$",
"this",
")",
")",
";",
"}"
] | Start App. | [
"Start",
"App",
"."
] | cf3ed4aacbe50e8eca0c96956f5803257238ecf3 | https://github.com/weew/app/blob/cf3ed4aacbe50e8eca0c96956f5803257238ecf3/src/Weew/App/App.php#L120-L139 |
8,585 | weew/app | src/Weew/App/App.php | App.shutdown | public function shutdown() {
if ( ! $this->started) {
return;
}
$this->started = false;
$this->kernel->shutdown();
$this->eventer->dispatch(new KernelShutdownEvent($this->kernel));
$this->eventer->dispatch(new AppShutdownEvent($this));
} | php | public function shutdown() {
if ( ! $this->started) {
return;
}
$this->started = false;
$this->kernel->shutdown();
$this->eventer->dispatch(new KernelShutdownEvent($this->kernel));
$this->eventer->dispatch(new AppShutdownEvent($this));
} | [
"public",
"function",
"shutdown",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"started",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"started",
"=",
"false",
";",
"$",
"this",
"->",
"kernel",
"->",
"shutdown",
"(",
")",
";",
"$",
"this",
"->",
"eventer",
"->",
"dispatch",
"(",
"new",
"KernelShutdownEvent",
"(",
"$",
"this",
"->",
"kernel",
")",
")",
";",
"$",
"this",
"->",
"eventer",
"->",
"dispatch",
"(",
"new",
"AppShutdownEvent",
"(",
"$",
"this",
")",
")",
";",
"}"
] | Shutdown App. | [
"Shutdown",
"App",
"."
] | cf3ed4aacbe50e8eca0c96956f5803257238ecf3 | https://github.com/weew/app/blob/cf3ed4aacbe50e8eca0c96956f5803257238ecf3/src/Weew/App/App.php#L144-L154 |
8,586 | JoshuaEstes/Daedalus | src/Daedalus/Command/DumpContainerCommand.php | DumpContainerCommand.renderParameterInformation | private function renderParameterInformation(OutputInterface $output)
{
$table = new Table($output);
$table->setHeaders(array('Parameter Name', 'Parameter Value'));
$parameters = $this->container->getParameterBag()->all();
ksort($parameters);
foreach ($parameters as $name => $value) {
$table->addRow(array($name, $value));
}
$table->render();
} | php | private function renderParameterInformation(OutputInterface $output)
{
$table = new Table($output);
$table->setHeaders(array('Parameter Name', 'Parameter Value'));
$parameters = $this->container->getParameterBag()->all();
ksort($parameters);
foreach ($parameters as $name => $value) {
$table->addRow(array($name, $value));
}
$table->render();
} | [
"private",
"function",
"renderParameterInformation",
"(",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"table",
"=",
"new",
"Table",
"(",
"$",
"output",
")",
";",
"$",
"table",
"->",
"setHeaders",
"(",
"array",
"(",
"'Parameter Name'",
",",
"'Parameter Value'",
")",
")",
";",
"$",
"parameters",
"=",
"$",
"this",
"->",
"container",
"->",
"getParameterBag",
"(",
")",
"->",
"all",
"(",
")",
";",
"ksort",
"(",
"$",
"parameters",
")",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"table",
"->",
"addRow",
"(",
"array",
"(",
"$",
"name",
",",
"$",
"value",
")",
")",
";",
"}",
"$",
"table",
"->",
"render",
"(",
")",
";",
"}"
] | Renders a table that includes all parameters that a developer can use
in a build file
@param OutputInterface $output | [
"Renders",
"a",
"table",
"that",
"includes",
"all",
"parameters",
"that",
"a",
"developer",
"can",
"use",
"in",
"a",
"build",
"file"
] | 4c898c41433242e46b30d45ebe03fdc91512b444 | https://github.com/JoshuaEstes/Daedalus/blob/4c898c41433242e46b30d45ebe03fdc91512b444/src/Daedalus/Command/DumpContainerCommand.php#L57-L69 |
8,587 | JoshuaEstes/Daedalus | src/Daedalus/Command/DumpContainerCommand.php | DumpContainerCommand.renderServiceInformation | private function renderServiceInformation(OutputInterface $output)
{
$table = new Table($output);
$table->setHeaders(array('Service ID', 'Class'));
$serviceIds = $this->container->getServiceIds();
sort($serviceIds);
foreach ($serviceIds as $id) {
$service = $this->container->get($id);
$table->addRow(array($id, get_class($service)));
}
$table->render();
} | php | private function renderServiceInformation(OutputInterface $output)
{
$table = new Table($output);
$table->setHeaders(array('Service ID', 'Class'));
$serviceIds = $this->container->getServiceIds();
sort($serviceIds);
foreach ($serviceIds as $id) {
$service = $this->container->get($id);
$table->addRow(array($id, get_class($service)));
}
$table->render();
} | [
"private",
"function",
"renderServiceInformation",
"(",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"table",
"=",
"new",
"Table",
"(",
"$",
"output",
")",
";",
"$",
"table",
"->",
"setHeaders",
"(",
"array",
"(",
"'Service ID'",
",",
"'Class'",
")",
")",
";",
"$",
"serviceIds",
"=",
"$",
"this",
"->",
"container",
"->",
"getServiceIds",
"(",
")",
";",
"sort",
"(",
"$",
"serviceIds",
")",
";",
"foreach",
"(",
"$",
"serviceIds",
"as",
"$",
"id",
")",
"{",
"$",
"service",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"$",
"id",
")",
";",
"$",
"table",
"->",
"addRow",
"(",
"array",
"(",
"$",
"id",
",",
"get_class",
"(",
"$",
"service",
")",
")",
")",
";",
"}",
"$",
"table",
"->",
"render",
"(",
")",
";",
"}"
] | Renders a table that has all the services in the container
@param OutputInterface $output | [
"Renders",
"a",
"table",
"that",
"has",
"all",
"the",
"services",
"in",
"the",
"container"
] | 4c898c41433242e46b30d45ebe03fdc91512b444 | https://github.com/JoshuaEstes/Daedalus/blob/4c898c41433242e46b30d45ebe03fdc91512b444/src/Daedalus/Command/DumpContainerCommand.php#L76-L89 |
8,588 | samurai-fw/samurai | src/Samurai/Component/DataStore/Redis.php | Redis.addSortedSet | public function addSortedSet($key, $member, $value)
{
$this->driver->zAdd($key, $value, $member);
} | php | public function addSortedSet($key, $member, $value)
{
$this->driver->zAdd($key, $value, $member);
} | [
"public",
"function",
"addSortedSet",
"(",
"$",
"key",
",",
"$",
"member",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"driver",
"->",
"zAdd",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"member",
")",
";",
"}"
] | add data to sorted set.
@param string $key
@param string $member
@param int|float $value | [
"add",
"data",
"to",
"sorted",
"set",
"."
] | 7ca3847b13f86e2847a17ab5e8e4e20893021d5a | https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/DataStore/Redis.php#L166-L169 |
8,589 | samurai-fw/samurai | src/Samurai/Component/DataStore/Redis.php | Redis.getSortedRankAsc | public function getSortedRankAsc($key, $member)
{
$score = $this->getScore($key, $member);
if ($score === false || $score === null) return null;
return $this->driver->zCount($key, '-inf', -- $score);
} | php | public function getSortedRankAsc($key, $member)
{
$score = $this->getScore($key, $member);
if ($score === false || $score === null) return null;
return $this->driver->zCount($key, '-inf', -- $score);
} | [
"public",
"function",
"getSortedRankAsc",
"(",
"$",
"key",
",",
"$",
"member",
")",
"{",
"$",
"score",
"=",
"$",
"this",
"->",
"getScore",
"(",
"$",
"key",
",",
"$",
"member",
")",
";",
"if",
"(",
"$",
"score",
"===",
"false",
"||",
"$",
"score",
"===",
"null",
")",
"return",
"null",
";",
"return",
"$",
"this",
"->",
"driver",
"->",
"zCount",
"(",
"$",
"key",
",",
"'-inf'",
",",
"--",
"$",
"score",
")",
";",
"}"
] | get sorted set rank by asc
@param string $key
@param string $member
@return int|null | [
"get",
"sorted",
"set",
"rank",
"by",
"asc"
] | 7ca3847b13f86e2847a17ab5e8e4e20893021d5a | https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/DataStore/Redis.php#L190-L196 |
8,590 | samurai-fw/samurai | src/Samurai/Component/DataStore/Redis.php | Redis.getSortedSets | public function getSortedSets($key, $start = 0, $limit = 20, $with_scores = true)
{
return $this->getSortedSetsAsc($key, $start, $limit, $with_scores);
} | php | public function getSortedSets($key, $start = 0, $limit = 20, $with_scores = true)
{
return $this->getSortedSetsAsc($key, $start, $limit, $with_scores);
} | [
"public",
"function",
"getSortedSets",
"(",
"$",
"key",
",",
"$",
"start",
"=",
"0",
",",
"$",
"limit",
"=",
"20",
",",
"$",
"with_scores",
"=",
"true",
")",
"{",
"return",
"$",
"this",
"->",
"getSortedSetsAsc",
"(",
"$",
"key",
",",
"$",
"start",
",",
"$",
"limit",
",",
"$",
"with_scores",
")",
";",
"}"
] | get sets with score.
@param string $key
@param int $start
@param int $limit
@param bool $with_scores
@return array | [
"get",
"sets",
"with",
"score",
"."
] | 7ca3847b13f86e2847a17ab5e8e4e20893021d5a | https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/DataStore/Redis.php#L222-L225 |
8,591 | samurai-fw/samurai | src/Samurai/Component/DataStore/Redis.php | Redis.getSortedSetsAsc | public function getSortedSetsAsc($key, $start = 0, $limit = 20, $with_scores = true)
{
return $this->driver->zRangeByScore($key, 0, '+inf', ['limit' => [$start, $limit], 'withscores' => $with_scores]);
} | php | public function getSortedSetsAsc($key, $start = 0, $limit = 20, $with_scores = true)
{
return $this->driver->zRangeByScore($key, 0, '+inf', ['limit' => [$start, $limit], 'withscores' => $with_scores]);
} | [
"public",
"function",
"getSortedSetsAsc",
"(",
"$",
"key",
",",
"$",
"start",
"=",
"0",
",",
"$",
"limit",
"=",
"20",
",",
"$",
"with_scores",
"=",
"true",
")",
"{",
"return",
"$",
"this",
"->",
"driver",
"->",
"zRangeByScore",
"(",
"$",
"key",
",",
"0",
",",
"'+inf'",
",",
"[",
"'limit'",
"=>",
"[",
"$",
"start",
",",
"$",
"limit",
"]",
",",
"'withscores'",
"=>",
"$",
"with_scores",
"]",
")",
";",
"}"
] | get sets with score, order by score asc.
@param string $key
@param int $start
@param int $limit
@param bool $with_scores
@return array | [
"get",
"sets",
"with",
"score",
"order",
"by",
"score",
"asc",
"."
] | 7ca3847b13f86e2847a17ab5e8e4e20893021d5a | https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/DataStore/Redis.php#L236-L239 |
8,592 | samurai-fw/samurai | src/Samurai/Component/DataStore/Redis.php | Redis.getSortedSetsDesc | public function getSortedSetsDesc($key, $start = 0, $limit = 20, $with_scores = true)
{
return $this->driver->zRevRangeByScore($key, '+inf', 0, ['limit' => [$start, $limit], 'withscores' => $with_scores]);
} | php | public function getSortedSetsDesc($key, $start = 0, $limit = 20, $with_scores = true)
{
return $this->driver->zRevRangeByScore($key, '+inf', 0, ['limit' => [$start, $limit], 'withscores' => $with_scores]);
} | [
"public",
"function",
"getSortedSetsDesc",
"(",
"$",
"key",
",",
"$",
"start",
"=",
"0",
",",
"$",
"limit",
"=",
"20",
",",
"$",
"with_scores",
"=",
"true",
")",
"{",
"return",
"$",
"this",
"->",
"driver",
"->",
"zRevRangeByScore",
"(",
"$",
"key",
",",
"'+inf'",
",",
"0",
",",
"[",
"'limit'",
"=>",
"[",
"$",
"start",
",",
"$",
"limit",
"]",
",",
"'withscores'",
"=>",
"$",
"with_scores",
"]",
")",
";",
"}"
] | get sets with score, order by score desc.
@param string $key
@param int $start
@param int $limit
@param bool $with_scores
@return array | [
"get",
"sets",
"with",
"score",
"order",
"by",
"score",
"desc",
"."
] | 7ca3847b13f86e2847a17ab5e8e4e20893021d5a | https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/DataStore/Redis.php#L250-L253 |
8,593 | codger-php/generate | src/Recipe.php | Recipe.set | public function set(string $name, $value) : Recipe
{
$this->variables->$name = $value;
return $this;
} | php | public function set(string $name, $value) : Recipe
{
$this->variables->$name = $value;
return $this;
} | [
"public",
"function",
"set",
"(",
"string",
"$",
"name",
",",
"$",
"value",
")",
":",
"Recipe",
"{",
"$",
"this",
"->",
"variables",
"->",
"$",
"name",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Set a variable to later be passed to Twig.
@param string $name
@param mixed $value
@return Codger\Generate\Recipe Itself for chaining. | [
"Set",
"a",
"variable",
"to",
"later",
"be",
"passed",
"to",
"Twig",
"."
] | 89dd3bd074cef53cf85b1470c0b96b4167825416 | https://github.com/codger-php/generate/blob/89dd3bd074cef53cf85b1470c0b96b4167825416/src/Recipe.php#L56-L60 |
8,594 | codger-php/generate | src/Recipe.php | Recipe.process | public function process() : void
{
if (isset($this->output)) {
$this->output->call($this);
} elseif (!$this->delegated) {
self::$inout->error("Recipe is missing a call to `output` and did not delegate anything, not very useful probably...\n");
}
} | php | public function process() : void
{
if (isset($this->output)) {
$this->output->call($this);
} elseif (!$this->delegated) {
self::$inout->error("Recipe is missing a call to `output` and did not delegate anything, not very useful probably...\n");
}
} | [
"public",
"function",
"process",
"(",
")",
":",
"void",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"output",
")",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"call",
"(",
"$",
"this",
")",
";",
"}",
"elseif",
"(",
"!",
"$",
"this",
"->",
"delegated",
")",
"{",
"self",
"::",
"$",
"inout",
"->",
"error",
"(",
"\"Recipe is missing a call to `output` and did not delegate anything, not very useful probably...\\n\"",
")",
";",
"}",
"}"
] | Process this recipe.
@return void | [
"Process",
"this",
"recipe",
"."
] | 89dd3bd074cef53cf85b1470c0b96b4167825416 | https://github.com/codger-php/generate/blob/89dd3bd074cef53cf85b1470c0b96b4167825416/src/Recipe.php#L177-L184 |
8,595 | codger-php/generate | src/Recipe.php | Recipe.delegate | public function delegate(string $recipe, ...$args) : Recipe
{
(new Bootstrap($recipe))->run(...$args);
$this->delegated = true;
return $this;
} | php | public function delegate(string $recipe, ...$args) : Recipe
{
(new Bootstrap($recipe))->run(...$args);
$this->delegated = true;
return $this;
} | [
"public",
"function",
"delegate",
"(",
"string",
"$",
"recipe",
",",
"...",
"$",
"args",
")",
":",
"Recipe",
"{",
"(",
"new",
"Bootstrap",
"(",
"$",
"recipe",
")",
")",
"->",
"run",
"(",
"...",
"$",
"args",
")",
";",
"$",
"this",
"->",
"delegated",
"=",
"true",
";",
"return",
"$",
"this",
";",
"}"
] | Delegate to a sub-recipe.
@param string $recipe The name of the recipe to delegate to.
@param mixed ...$args Extra arguments.
@return Codger\Generate\Recipe Itself for chaining. | [
"Delegate",
"to",
"a",
"sub",
"-",
"recipe",
"."
] | 89dd3bd074cef53cf85b1470c0b96b4167825416 | https://github.com/codger-php/generate/blob/89dd3bd074cef53cf85b1470c0b96b4167825416/src/Recipe.php#L193-L198 |
8,596 | DevGroup-ru/yii2-admin-utils | src/controllers/BaseController.php | BaseController.init | public function init()
{
parent::init();
$this->on(FrontendController::EVENT_BEFORE_ACTION, function() {
// switch layout to admin or developer-defined in params
$this->layout = isset(Yii::$app->params['admin.layout'])
? Yii::$app->params['admin.layout']
: '@app/views/layouts/main';
// register frontend monster
AdminBundle::register($this->view);
return true;
});
} | php | public function init()
{
parent::init();
$this->on(FrontendController::EVENT_BEFORE_ACTION, function() {
// switch layout to admin or developer-defined in params
$this->layout = isset(Yii::$app->params['admin.layout'])
? Yii::$app->params['admin.layout']
: '@app/views/layouts/main';
// register frontend monster
AdminBundle::register($this->view);
return true;
});
} | [
"public",
"function",
"init",
"(",
")",
"{",
"parent",
"::",
"init",
"(",
")",
";",
"$",
"this",
"->",
"on",
"(",
"FrontendController",
"::",
"EVENT_BEFORE_ACTION",
",",
"function",
"(",
")",
"{",
"// switch layout to admin or developer-defined in params",
"$",
"this",
"->",
"layout",
"=",
"isset",
"(",
"Yii",
"::",
"$",
"app",
"->",
"params",
"[",
"'admin.layout'",
"]",
")",
"?",
"Yii",
"::",
"$",
"app",
"->",
"params",
"[",
"'admin.layout'",
"]",
":",
"'@app/views/layouts/main'",
";",
"// register frontend monster",
"AdminBundle",
"::",
"register",
"(",
"$",
"this",
"->",
"view",
")",
";",
"return",
"true",
";",
"}",
")",
";",
"}"
] | Overrides default init adding some additional stuff | [
"Overrides",
"default",
"init",
"adding",
"some",
"additional",
"stuff"
] | 15c1853a5ec264602de3ad82dbf70f85de66adff | https://github.com/DevGroup-ru/yii2-admin-utils/blob/15c1853a5ec264602de3ad82dbf70f85de66adff/src/controllers/BaseController.php#L25-L39 |
8,597 | cyberspectrum/i18n-metamodels | src/MetaModelHandlerFactory.php | MetaModelHandlerFactory.generate | public function generate(IMetaModel $metaModel): \Generator
{
foreach ($metaModel->getAttributes() as $attribute) {
if (!$attribute instanceof ITranslated) {
continue;
}
if ($this->handlerFactories->has($class = \get_class($attribute))) {
yield $attribute->getColName() => $this->handlerFactories->get($class)->create($attribute);
}
}
} | php | public function generate(IMetaModel $metaModel): \Generator
{
foreach ($metaModel->getAttributes() as $attribute) {
if (!$attribute instanceof ITranslated) {
continue;
}
if ($this->handlerFactories->has($class = \get_class($attribute))) {
yield $attribute->getColName() => $this->handlerFactories->get($class)->create($attribute);
}
}
} | [
"public",
"function",
"generate",
"(",
"IMetaModel",
"$",
"metaModel",
")",
":",
"\\",
"Generator",
"{",
"foreach",
"(",
"$",
"metaModel",
"->",
"getAttributes",
"(",
")",
"as",
"$",
"attribute",
")",
"{",
"if",
"(",
"!",
"$",
"attribute",
"instanceof",
"ITranslated",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"handlerFactories",
"->",
"has",
"(",
"$",
"class",
"=",
"\\",
"get_class",
"(",
"$",
"attribute",
")",
")",
")",
"{",
"yield",
"$",
"attribute",
"->",
"getColName",
"(",
")",
"=>",
"$",
"this",
"->",
"handlerFactories",
"->",
"get",
"(",
"$",
"class",
")",
"->",
"create",
"(",
"$",
"attribute",
")",
";",
"}",
"}",
"}"
] | Generate the attribute handlers.
@param IMetaModel $metaModel The MetaModel.
@return \Generator | [
"Generate",
"the",
"attribute",
"handlers",
"."
] | 5f36f24a3996eebd640c7f2bbbf20e6d9ff92365 | https://github.com/cyberspectrum/i18n-metamodels/blob/5f36f24a3996eebd640c7f2bbbf20e6d9ff92365/src/MetaModelHandlerFactory.php#L57-L68 |
8,598 | digipolisgent/robo-digipolis-code-validation | src/PhpCs.php | PhpCs.ignore | public function ignore($ignore)
{
if (!is_array($ignore)) {
$ignore = [$ignore];
}
$this->ignore = array_unique(array_merge($this->ignore, $ignore));
return $this;
} | php | public function ignore($ignore)
{
if (!is_array($ignore)) {
$ignore = [$ignore];
}
$this->ignore = array_unique(array_merge($this->ignore, $ignore));
return $this;
} | [
"public",
"function",
"ignore",
"(",
"$",
"ignore",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"ignore",
")",
")",
"{",
"$",
"ignore",
"=",
"[",
"$",
"ignore",
"]",
";",
"}",
"$",
"this",
"->",
"ignore",
"=",
"array_unique",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"ignore",
",",
"$",
"ignore",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add a path or file to ignore.
@param string|array $ignore
The path or paths to ignore.
@return $this | [
"Add",
"a",
"path",
"or",
"file",
"to",
"ignore",
"."
] | 56f69f88a368a5049af7021901042820bee914df | https://github.com/digipolisgent/robo-digipolis-code-validation/blob/56f69f88a368a5049af7021901042820bee914df/src/PhpCs.php#L87-L95 |
8,599 | hgraca/php-helper | src/ClassHelper.php | ClassHelper.findPropertiesNames | public static function findPropertiesNames(
string $classFqcn,
array $excludedNames = [],
array $excludedVisibility = []
) {
$defaultVisibility = ['public' => true, 'protected' => true, 'private' => true, 'static' => true];
$excludedVisibility = array_merge(
$defaultVisibility,
self::setGivenExcludedVisivilitiesToKeysWithValueFalse($excludedVisibility)
);
$reflectionClass = self::getReflectionClass($classFqcn);
$reflectionPropertiesArray = $reflectionClass->getProperties();
return self::filterProperties($excludedNames, $excludedVisibility, $reflectionPropertiesArray);
} | php | public static function findPropertiesNames(
string $classFqcn,
array $excludedNames = [],
array $excludedVisibility = []
) {
$defaultVisibility = ['public' => true, 'protected' => true, 'private' => true, 'static' => true];
$excludedVisibility = array_merge(
$defaultVisibility,
self::setGivenExcludedVisivilitiesToKeysWithValueFalse($excludedVisibility)
);
$reflectionClass = self::getReflectionClass($classFqcn);
$reflectionPropertiesArray = $reflectionClass->getProperties();
return self::filterProperties($excludedNames, $excludedVisibility, $reflectionPropertiesArray);
} | [
"public",
"static",
"function",
"findPropertiesNames",
"(",
"string",
"$",
"classFqcn",
",",
"array",
"$",
"excludedNames",
"=",
"[",
"]",
",",
"array",
"$",
"excludedVisibility",
"=",
"[",
"]",
")",
"{",
"$",
"defaultVisibility",
"=",
"[",
"'public'",
"=>",
"true",
",",
"'protected'",
"=>",
"true",
",",
"'private'",
"=>",
"true",
",",
"'static'",
"=>",
"true",
"]",
";",
"$",
"excludedVisibility",
"=",
"array_merge",
"(",
"$",
"defaultVisibility",
",",
"self",
"::",
"setGivenExcludedVisivilitiesToKeysWithValueFalse",
"(",
"$",
"excludedVisibility",
")",
")",
";",
"$",
"reflectionClass",
"=",
"self",
"::",
"getReflectionClass",
"(",
"$",
"classFqcn",
")",
";",
"$",
"reflectionPropertiesArray",
"=",
"$",
"reflectionClass",
"->",
"getProperties",
"(",
")",
";",
"return",
"self",
"::",
"filterProperties",
"(",
"$",
"excludedNames",
",",
"$",
"excludedVisibility",
",",
"$",
"reflectionPropertiesArray",
")",
";",
"}"
] | Returns an array with all properties names of the mixed
@param string $classFqcn
@param string[] $excludedNames
@param string[] $excludedVisibility = ['public', 'protected', 'private', 'static']
@return string[] | [
"Returns",
"an",
"array",
"with",
"all",
"properties",
"names",
"of",
"the",
"mixed"
] | 62b965b76d9116258142911ac7e154411df6009b | https://github.com/hgraca/php-helper/blob/62b965b76d9116258142911ac7e154411df6009b/src/ClassHelper.php#L42-L57 |
Subsets and Splits