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
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
caffeina-core/core | classes/Route.php | Route.compilePatternAsRegex | protected static function compilePatternAsRegex($pattern, $rules=[], $extract_params=true){
return '#^'.preg_replace_callback('#:([a-zA-Z]\w*)#',$extract_params
// Extract named parameters
? function($g) use (&$rules){
return '(?<' . $g[1] . '>' . (isset($rules[$g[1]])?$rules[$g[1]]:'[^/]+') .')';
}
// Optimized for matching
: function($g) use (&$rules){
return isset($rules[$g[1]]) ? $rules[$g[1]] : '[^/]+';
},
str_replace(['.',')','*'],['\.',')?','.+'],$pattern)).'$#';
} | php | protected static function compilePatternAsRegex($pattern, $rules=[], $extract_params=true){
return '#^'.preg_replace_callback('#:([a-zA-Z]\w*)#',$extract_params
// Extract named parameters
? function($g) use (&$rules){
return '(?<' . $g[1] . '>' . (isset($rules[$g[1]])?$rules[$g[1]]:'[^/]+') .')';
}
// Optimized for matching
: function($g) use (&$rules){
return isset($rules[$g[1]]) ? $rules[$g[1]] : '[^/]+';
},
str_replace(['.',')','*'],['\.',')?','.+'],$pattern)).'$#';
} | [
"protected",
"static",
"function",
"compilePatternAsRegex",
"(",
"$",
"pattern",
",",
"$",
"rules",
"=",
"[",
"]",
",",
"$",
"extract_params",
"=",
"true",
")",
"{",
"return",
"'#^'",
".",
"preg_replace_callback",
"(",
"'#:([a-zA-Z]\\w*)#'",
",",
"$",
"extract_params",
"// Extract named parameters",
"?",
"function",
"(",
"$",
"g",
")",
"use",
"(",
"&",
"$",
"rules",
")",
"{",
"return",
"'(?<'",
".",
"$",
"g",
"[",
"1",
"]",
".",
"'>'",
".",
"(",
"isset",
"(",
"$",
"rules",
"[",
"$",
"g",
"[",
"1",
"]",
"]",
")",
"?",
"$",
"rules",
"[",
"$",
"g",
"[",
"1",
"]",
"]",
":",
"'[^/]+'",
")",
".",
"')'",
";",
"}",
"// Optimized for matching",
":",
"function",
"(",
"$",
"g",
")",
"use",
"(",
"&",
"$",
"rules",
")",
"{",
"return",
"isset",
"(",
"$",
"rules",
"[",
"$",
"g",
"[",
"1",
"]",
"]",
")",
"?",
"$",
"rules",
"[",
"$",
"g",
"[",
"1",
"]",
"]",
":",
"'[^/]+'",
";",
"}",
",",
"str_replace",
"(",
"[",
"'.'",
",",
"')'",
",",
"'*'",
"]",
",",
"[",
"'\\.'",
",",
"')?'",
",",
"'.+'",
"]",
",",
"$",
"pattern",
")",
")",
".",
"'$#'",
";",
"}"
]
| Compile an URL schema to a PREG regular expression.
@param string $pattern The URL schema.
@return string The compiled PREG RegEx. | [
"Compile",
"an",
"URL",
"schema",
"to",
"a",
"PREG",
"regular",
"expression",
"."
]
| 819134644dfb3b6379a12fff08fa5ec45a2c614c | https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Route.php#L373-L385 | train |
caffeina-core/core | classes/Route.php | Route.extractVariablesFromURL | protected static function extractVariablesFromURL($pattern, $URL=null, $cut=false){
$URL = $URL ?: Request::URI();
$pattern = $cut ? str_replace('$#','',$pattern).'#' : $pattern;
$args = [];
if ( !preg_match($pattern,'/'.trim($URL,'/'),$args) ) return false;
foreach ($args as $key => $value) {
if (false === is_string($key)) unset($args[$key]);
}
return $args;
} | php | protected static function extractVariablesFromURL($pattern, $URL=null, $cut=false){
$URL = $URL ?: Request::URI();
$pattern = $cut ? str_replace('$#','',$pattern).'#' : $pattern;
$args = [];
if ( !preg_match($pattern,'/'.trim($URL,'/'),$args) ) return false;
foreach ($args as $key => $value) {
if (false === is_string($key)) unset($args[$key]);
}
return $args;
} | [
"protected",
"static",
"function",
"extractVariablesFromURL",
"(",
"$",
"pattern",
",",
"$",
"URL",
"=",
"null",
",",
"$",
"cut",
"=",
"false",
")",
"{",
"$",
"URL",
"=",
"$",
"URL",
"?",
":",
"Request",
"::",
"URI",
"(",
")",
";",
"$",
"pattern",
"=",
"$",
"cut",
"?",
"str_replace",
"(",
"'$#'",
",",
"''",
",",
"$",
"pattern",
")",
".",
"'#'",
":",
"$",
"pattern",
";",
"$",
"args",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"preg_match",
"(",
"$",
"pattern",
",",
"'/'",
".",
"trim",
"(",
"$",
"URL",
",",
"'/'",
")",
",",
"$",
"args",
")",
")",
"return",
"false",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"key",
")",
")",
"unset",
"(",
"$",
"args",
"[",
"$",
"key",
"]",
")",
";",
"}",
"return",
"$",
"args",
";",
"}"
]
| Extract the URL schema variables from the passed URL.
@param string $pattern The URL schema with the named parameters
@param string $URL The URL to process, if omitted the current request URI will be used.
@param boolean $cut If true don't limit the matching to the whole URL (used for group pattern extraction)
@return array The extracted variables | [
"Extract",
"the",
"URL",
"schema",
"variables",
"from",
"the",
"passed",
"URL",
"."
]
| 819134644dfb3b6379a12fff08fa5ec45a2c614c | https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Route.php#L394-L403 | train |
caffeina-core/core | classes/Route.php | Route.add | public static function add($route){
if (is_a($route, 'Route')){
// Add to tag map
if ($route->tag) static::$tags[$route->tag] =& $route;
// Optimize tree
if (Options::get('core.route.auto_optimize', true)){
$base =& static::$optimized_tree;
foreach (explode('/',trim(preg_replace('#^(.+?)\(?:.+$#','$1',$route->URLPattern),'/')) as $segment) {
$segment = trim($segment,'(');
if (!isset($base[$segment])) $base[$segment] = [];
$base =& $base[$segment];
}
$base[] =& $route;
}
}
// Add route to active group
if ( isset(static::$group[0]) ) static::$group[0]->add($route);
return static::$routes[implode('', static::$prefix)][] = $route;
} | php | public static function add($route){
if (is_a($route, 'Route')){
// Add to tag map
if ($route->tag) static::$tags[$route->tag] =& $route;
// Optimize tree
if (Options::get('core.route.auto_optimize', true)){
$base =& static::$optimized_tree;
foreach (explode('/',trim(preg_replace('#^(.+?)\(?:.+$#','$1',$route->URLPattern),'/')) as $segment) {
$segment = trim($segment,'(');
if (!isset($base[$segment])) $base[$segment] = [];
$base =& $base[$segment];
}
$base[] =& $route;
}
}
// Add route to active group
if ( isset(static::$group[0]) ) static::$group[0]->add($route);
return static::$routes[implode('', static::$prefix)][] = $route;
} | [
"public",
"static",
"function",
"add",
"(",
"$",
"route",
")",
"{",
"if",
"(",
"is_a",
"(",
"$",
"route",
",",
"'Route'",
")",
")",
"{",
"// Add to tag map",
"if",
"(",
"$",
"route",
"->",
"tag",
")",
"static",
"::",
"$",
"tags",
"[",
"$",
"route",
"->",
"tag",
"]",
"=",
"&",
"$",
"route",
";",
"// Optimize tree",
"if",
"(",
"Options",
"::",
"get",
"(",
"'core.route.auto_optimize'",
",",
"true",
")",
")",
"{",
"$",
"base",
"=",
"&",
"static",
"::",
"$",
"optimized_tree",
";",
"foreach",
"(",
"explode",
"(",
"'/'",
",",
"trim",
"(",
"preg_replace",
"(",
"'#^(.+?)\\(?:.+$#'",
",",
"'$1'",
",",
"$",
"route",
"->",
"URLPattern",
")",
",",
"'/'",
")",
")",
"as",
"$",
"segment",
")",
"{",
"$",
"segment",
"=",
"trim",
"(",
"$",
"segment",
",",
"'('",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"base",
"[",
"$",
"segment",
"]",
")",
")",
"$",
"base",
"[",
"$",
"segment",
"]",
"=",
"[",
"]",
";",
"$",
"base",
"=",
"&",
"$",
"base",
"[",
"$",
"segment",
"]",
";",
"}",
"$",
"base",
"[",
"]",
"=",
"&",
"$",
"route",
";",
"}",
"}",
"// Add route to active group",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"group",
"[",
"0",
"]",
")",
")",
"static",
"::",
"$",
"group",
"[",
"0",
"]",
"->",
"add",
"(",
"$",
"route",
")",
";",
"return",
"static",
"::",
"$",
"routes",
"[",
"implode",
"(",
"''",
",",
"static",
"::",
"$",
"prefix",
")",
"]",
"[",
"]",
"=",
"$",
"route",
";",
"}"
]
| Add a route to the internal route repository.
@param Route $route
@return Route | [
"Add",
"a",
"route",
"to",
"the",
"internal",
"route",
"repository",
"."
]
| 819134644dfb3b6379a12fff08fa5ec45a2c614c | https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Route.php#L431-L453 | train |
caffeina-core/core | classes/Route.php | Route.group | public static function group($prefix, $callback){
// Skip definition if current request doesn't match group.
$pre_prefix = rtrim(implode('',static::$prefix),'/');
$URI = Request::URI();
$args = [];
$group = false;
switch (true) {
// Dynamic group
case static::isDynamic($prefix) :
$args = static::extractVariablesFromURL($prx=static::compilePatternAsRegex("$pre_prefix$prefix"), null, true);
if ( $args !== false ) {
// Burn-in $prefix as static string
$partial = preg_match_all(str_replace('$#', '#', $prx), $URI, $partial) ? $partial[0][0] : '';
$prefix = $partial ? preg_replace('#^'.implode('',static::$prefix).'#', '', $partial) : $prefix;
}
// Static group
case ( 0 === strpos("$URI/", "$pre_prefix$prefix/") )
|| ( ! Options::get('core.route.pruning', true) ) :
static::$prefix[] = $prefix;
if (empty(static::$group)) static::$group = [];
array_unshift(static::$group, $group = new RouteGroup());
// Call the group body function
call_user_func_array($callback, $args ?: []);
array_shift(static::$group);
array_pop(static::$prefix);
if (empty(static::$prefix)) static::$prefix = [''];
break;
}
return $group ?: new RouteGroup();
} | php | public static function group($prefix, $callback){
// Skip definition if current request doesn't match group.
$pre_prefix = rtrim(implode('',static::$prefix),'/');
$URI = Request::URI();
$args = [];
$group = false;
switch (true) {
// Dynamic group
case static::isDynamic($prefix) :
$args = static::extractVariablesFromURL($prx=static::compilePatternAsRegex("$pre_prefix$prefix"), null, true);
if ( $args !== false ) {
// Burn-in $prefix as static string
$partial = preg_match_all(str_replace('$#', '#', $prx), $URI, $partial) ? $partial[0][0] : '';
$prefix = $partial ? preg_replace('#^'.implode('',static::$prefix).'#', '', $partial) : $prefix;
}
// Static group
case ( 0 === strpos("$URI/", "$pre_prefix$prefix/") )
|| ( ! Options::get('core.route.pruning', true) ) :
static::$prefix[] = $prefix;
if (empty(static::$group)) static::$group = [];
array_unshift(static::$group, $group = new RouteGroup());
// Call the group body function
call_user_func_array($callback, $args ?: []);
array_shift(static::$group);
array_pop(static::$prefix);
if (empty(static::$prefix)) static::$prefix = [''];
break;
}
return $group ?: new RouteGroup();
} | [
"public",
"static",
"function",
"group",
"(",
"$",
"prefix",
",",
"$",
"callback",
")",
"{",
"// Skip definition if current request doesn't match group.",
"$",
"pre_prefix",
"=",
"rtrim",
"(",
"implode",
"(",
"''",
",",
"static",
"::",
"$",
"prefix",
")",
",",
"'/'",
")",
";",
"$",
"URI",
"=",
"Request",
"::",
"URI",
"(",
")",
";",
"$",
"args",
"=",
"[",
"]",
";",
"$",
"group",
"=",
"false",
";",
"switch",
"(",
"true",
")",
"{",
"// Dynamic group",
"case",
"static",
"::",
"isDynamic",
"(",
"$",
"prefix",
")",
":",
"$",
"args",
"=",
"static",
"::",
"extractVariablesFromURL",
"(",
"$",
"prx",
"=",
"static",
"::",
"compilePatternAsRegex",
"(",
"\"$pre_prefix$prefix\"",
")",
",",
"null",
",",
"true",
")",
";",
"if",
"(",
"$",
"args",
"!==",
"false",
")",
"{",
"// Burn-in $prefix as static string",
"$",
"partial",
"=",
"preg_match_all",
"(",
"str_replace",
"(",
"'$#'",
",",
"'#'",
",",
"$",
"prx",
")",
",",
"$",
"URI",
",",
"$",
"partial",
")",
"?",
"$",
"partial",
"[",
"0",
"]",
"[",
"0",
"]",
":",
"''",
";",
"$",
"prefix",
"=",
"$",
"partial",
"?",
"preg_replace",
"(",
"'#^'",
".",
"implode",
"(",
"''",
",",
"static",
"::",
"$",
"prefix",
")",
".",
"'#'",
",",
"''",
",",
"$",
"partial",
")",
":",
"$",
"prefix",
";",
"}",
"// Static group",
"case",
"(",
"0",
"===",
"strpos",
"(",
"\"$URI/\"",
",",
"\"$pre_prefix$prefix/\"",
")",
")",
"||",
"(",
"!",
"Options",
"::",
"get",
"(",
"'core.route.pruning'",
",",
"true",
")",
")",
":",
"static",
"::",
"$",
"prefix",
"[",
"]",
"=",
"$",
"prefix",
";",
"if",
"(",
"empty",
"(",
"static",
"::",
"$",
"group",
")",
")",
"static",
"::",
"$",
"group",
"=",
"[",
"]",
";",
"array_unshift",
"(",
"static",
"::",
"$",
"group",
",",
"$",
"group",
"=",
"new",
"RouteGroup",
"(",
")",
")",
";",
"// Call the group body function",
"call_user_func_array",
"(",
"$",
"callback",
",",
"$",
"args",
"?",
":",
"[",
"]",
")",
";",
"array_shift",
"(",
"static",
"::",
"$",
"group",
")",
";",
"array_pop",
"(",
"static",
"::",
"$",
"prefix",
")",
";",
"if",
"(",
"empty",
"(",
"static",
"::",
"$",
"prefix",
")",
")",
"static",
"::",
"$",
"prefix",
"=",
"[",
"''",
"]",
";",
"break",
";",
"}",
"return",
"$",
"group",
"?",
":",
"new",
"RouteGroup",
"(",
")",
";",
"}"
]
| Define a route group, if not immediately matched internal code will not be invoked.
@param string $prefix The url prefix for the internal route definitions.
@param string $callback This callback is invoked on $prefix match of the current request URI. | [
"Define",
"a",
"route",
"group",
"if",
"not",
"immediately",
"matched",
"internal",
"code",
"will",
"not",
"be",
"invoked",
"."
]
| 819134644dfb3b6379a12fff08fa5ec45a2c614c | https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Route.php#L460-L498 | train |
caffeina-core/core | classes/Route.php | Route.dispatch | public static function dispatch($URL=null, $method=null, $return_route=false){
if (!$URL) $URL = Request::URI();
if (!$method) $method = Request::method();
$__deferred_send = new Deferred(function(){
if (Options::get('core.response.autosend',true)){
Response::send();
}
});
if (empty(static::$optimized_tree)) {
foreach ((array)static::$routes as $group => $routes){
foreach ($routes as $route) {
if (is_a($route, 'Route') && $route->match($URL,$method)){
if ($return_route){
return $route;
} else {
$route->run($route->extractArgs($URL),$method);
return true;
}
}
}
}
} else {
$routes =& static::$optimized_tree;
foreach (explode('/',trim($URL,'/')) as $segment) {
if (is_array($routes) && isset($routes[$segment])) $routes =& $routes[$segment];
// Root-level dynamic routes Ex: "/:param"
else if (is_array($routes) && isset($routes[''])) $routes =& $routes[''];
else break;
}
if (is_array($routes) && isset($routes[0]) && !is_array($routes[0])) foreach ((array)$routes as $route) {
if (is_a($route, __CLASS__) && $route->match($URL, $method)){
if ($return_route){
return $route;
} else {
$route->run($route->extractArgs($URL),$method);
return true;
}
}
}
}
Response::status(404, '404 Resource not found.');
foreach (array_filter(array_merge(
(static::trigger(404)?:[]),
(Event::trigger(404)?:[])
)) as $res){
Response::add($res);
}
return false;
} | php | public static function dispatch($URL=null, $method=null, $return_route=false){
if (!$URL) $URL = Request::URI();
if (!$method) $method = Request::method();
$__deferred_send = new Deferred(function(){
if (Options::get('core.response.autosend',true)){
Response::send();
}
});
if (empty(static::$optimized_tree)) {
foreach ((array)static::$routes as $group => $routes){
foreach ($routes as $route) {
if (is_a($route, 'Route') && $route->match($URL,$method)){
if ($return_route){
return $route;
} else {
$route->run($route->extractArgs($URL),$method);
return true;
}
}
}
}
} else {
$routes =& static::$optimized_tree;
foreach (explode('/',trim($URL,'/')) as $segment) {
if (is_array($routes) && isset($routes[$segment])) $routes =& $routes[$segment];
// Root-level dynamic routes Ex: "/:param"
else if (is_array($routes) && isset($routes[''])) $routes =& $routes[''];
else break;
}
if (is_array($routes) && isset($routes[0]) && !is_array($routes[0])) foreach ((array)$routes as $route) {
if (is_a($route, __CLASS__) && $route->match($URL, $method)){
if ($return_route){
return $route;
} else {
$route->run($route->extractArgs($URL),$method);
return true;
}
}
}
}
Response::status(404, '404 Resource not found.');
foreach (array_filter(array_merge(
(static::trigger(404)?:[]),
(Event::trigger(404)?:[])
)) as $res){
Response::add($res);
}
return false;
} | [
"public",
"static",
"function",
"dispatch",
"(",
"$",
"URL",
"=",
"null",
",",
"$",
"method",
"=",
"null",
",",
"$",
"return_route",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"URL",
")",
"$",
"URL",
"=",
"Request",
"::",
"URI",
"(",
")",
";",
"if",
"(",
"!",
"$",
"method",
")",
"$",
"method",
"=",
"Request",
"::",
"method",
"(",
")",
";",
"$",
"__deferred_send",
"=",
"new",
"Deferred",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"Options",
"::",
"get",
"(",
"'core.response.autosend'",
",",
"true",
")",
")",
"{",
"Response",
"::",
"send",
"(",
")",
";",
"}",
"}",
")",
";",
"if",
"(",
"empty",
"(",
"static",
"::",
"$",
"optimized_tree",
")",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"static",
"::",
"$",
"routes",
"as",
"$",
"group",
"=>",
"$",
"routes",
")",
"{",
"foreach",
"(",
"$",
"routes",
"as",
"$",
"route",
")",
"{",
"if",
"(",
"is_a",
"(",
"$",
"route",
",",
"'Route'",
")",
"&&",
"$",
"route",
"->",
"match",
"(",
"$",
"URL",
",",
"$",
"method",
")",
")",
"{",
"if",
"(",
"$",
"return_route",
")",
"{",
"return",
"$",
"route",
";",
"}",
"else",
"{",
"$",
"route",
"->",
"run",
"(",
"$",
"route",
"->",
"extractArgs",
"(",
"$",
"URL",
")",
",",
"$",
"method",
")",
";",
"return",
"true",
";",
"}",
"}",
"}",
"}",
"}",
"else",
"{",
"$",
"routes",
"=",
"&",
"static",
"::",
"$",
"optimized_tree",
";",
"foreach",
"(",
"explode",
"(",
"'/'",
",",
"trim",
"(",
"$",
"URL",
",",
"'/'",
")",
")",
"as",
"$",
"segment",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"routes",
")",
"&&",
"isset",
"(",
"$",
"routes",
"[",
"$",
"segment",
"]",
")",
")",
"$",
"routes",
"=",
"&",
"$",
"routes",
"[",
"$",
"segment",
"]",
";",
"// Root-level dynamic routes Ex: \"/:param\"",
"else",
"if",
"(",
"is_array",
"(",
"$",
"routes",
")",
"&&",
"isset",
"(",
"$",
"routes",
"[",
"''",
"]",
")",
")",
"$",
"routes",
"=",
"&",
"$",
"routes",
"[",
"''",
"]",
";",
"else",
"break",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"routes",
")",
"&&",
"isset",
"(",
"$",
"routes",
"[",
"0",
"]",
")",
"&&",
"!",
"is_array",
"(",
"$",
"routes",
"[",
"0",
"]",
")",
")",
"foreach",
"(",
"(",
"array",
")",
"$",
"routes",
"as",
"$",
"route",
")",
"{",
"if",
"(",
"is_a",
"(",
"$",
"route",
",",
"__CLASS__",
")",
"&&",
"$",
"route",
"->",
"match",
"(",
"$",
"URL",
",",
"$",
"method",
")",
")",
"{",
"if",
"(",
"$",
"return_route",
")",
"{",
"return",
"$",
"route",
";",
"}",
"else",
"{",
"$",
"route",
"->",
"run",
"(",
"$",
"route",
"->",
"extractArgs",
"(",
"$",
"URL",
")",
",",
"$",
"method",
")",
";",
"return",
"true",
";",
"}",
"}",
"}",
"}",
"Response",
"::",
"status",
"(",
"404",
",",
"'404 Resource not found.'",
")",
";",
"foreach",
"(",
"array_filter",
"(",
"array_merge",
"(",
"(",
"static",
"::",
"trigger",
"(",
"404",
")",
"?",
":",
"[",
"]",
")",
",",
"(",
"Event",
"::",
"trigger",
"(",
"404",
")",
"?",
":",
"[",
"]",
")",
")",
")",
"as",
"$",
"res",
")",
"{",
"Response",
"::",
"add",
"(",
"$",
"res",
")",
";",
"}",
"return",
"false",
";",
"}"
]
| Start the route dispatcher and resolve the URL request.
@param string $URL The URL to match onto.
@param string $method The HTTP method.
@param bool $return_route If setted to true it will *NOT* execute the route but it will return her.
@return boolean true if a route callback was executed. | [
"Start",
"the",
"route",
"dispatcher",
"and",
"resolve",
"the",
"URL",
"request",
"."
]
| 819134644dfb3b6379a12fff08fa5ec45a2c614c | https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Route.php#L513-L564 | train |
caffeina-core/core | classes/Options.php | Options.loadINI | public static function loadINI($filepath,$prefix_path=null){
$results = parse_ini_file($filepath,true);
if($results) {
$results = static::filterWith(["load.ini", "load"], $results);
static::loadArray($results,$prefix_path);
}
} | php | public static function loadINI($filepath,$prefix_path=null){
$results = parse_ini_file($filepath,true);
if($results) {
$results = static::filterWith(["load.ini", "load"], $results);
static::loadArray($results,$prefix_path);
}
} | [
"public",
"static",
"function",
"loadINI",
"(",
"$",
"filepath",
",",
"$",
"prefix_path",
"=",
"null",
")",
"{",
"$",
"results",
"=",
"parse_ini_file",
"(",
"$",
"filepath",
",",
"true",
")",
";",
"if",
"(",
"$",
"results",
")",
"{",
"$",
"results",
"=",
"static",
"::",
"filterWith",
"(",
"[",
"\"load.ini\"",
",",
"\"load\"",
"]",
",",
"$",
"results",
")",
";",
"static",
"::",
"loadArray",
"(",
"$",
"results",
",",
"$",
"prefix_path",
")",
";",
"}",
"}"
]
| Load an INI configuration file
@param string $filepath The path of the INI config file
@param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary | [
"Load",
"an",
"INI",
"configuration",
"file"
]
| 819134644dfb3b6379a12fff08fa5ec45a2c614c | https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Options.php#L36-L42 | train |
caffeina-core/core | classes/Options.php | Options.loadJSON | public static function loadJSON($filepath,$prefix_path=null){
$data = file_get_contents($filepath);
$results = $data?json_decode($data,true):[];
if($results) {
$results = static::filterWith(["load.json", "load"], $results);
static::loadArray($results,$prefix_path);
}
} | php | public static function loadJSON($filepath,$prefix_path=null){
$data = file_get_contents($filepath);
$results = $data?json_decode($data,true):[];
if($results) {
$results = static::filterWith(["load.json", "load"], $results);
static::loadArray($results,$prefix_path);
}
} | [
"public",
"static",
"function",
"loadJSON",
"(",
"$",
"filepath",
",",
"$",
"prefix_path",
"=",
"null",
")",
"{",
"$",
"data",
"=",
"file_get_contents",
"(",
"$",
"filepath",
")",
";",
"$",
"results",
"=",
"$",
"data",
"?",
"json_decode",
"(",
"$",
"data",
",",
"true",
")",
":",
"[",
"]",
";",
"if",
"(",
"$",
"results",
")",
"{",
"$",
"results",
"=",
"static",
"::",
"filterWith",
"(",
"[",
"\"load.json\"",
",",
"\"load\"",
"]",
",",
"$",
"results",
")",
";",
"static",
"::",
"loadArray",
"(",
"$",
"results",
",",
"$",
"prefix_path",
")",
";",
"}",
"}"
]
| Load a JSON configuration file
@param string $filepath The path of the JSON config file
@param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary | [
"Load",
"a",
"JSON",
"configuration",
"file"
]
| 819134644dfb3b6379a12fff08fa5ec45a2c614c | https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Options.php#L49-L56 | train |
caffeina-core/core | classes/Options.php | Options.loadArray | public static function loadArray(array $array,$prefix_path=null){
$array = static::filterWith(["load.array", "load"], $array);
if ($prefix_path){
static::set($prefix_path,$array);
} else {
static::merge($array);
}
self::trigger('loaded');
} | php | public static function loadArray(array $array,$prefix_path=null){
$array = static::filterWith(["load.array", "load"], $array);
if ($prefix_path){
static::set($prefix_path,$array);
} else {
static::merge($array);
}
self::trigger('loaded');
} | [
"public",
"static",
"function",
"loadArray",
"(",
"array",
"$",
"array",
",",
"$",
"prefix_path",
"=",
"null",
")",
"{",
"$",
"array",
"=",
"static",
"::",
"filterWith",
"(",
"[",
"\"load.array\"",
",",
"\"load\"",
"]",
",",
"$",
"array",
")",
";",
"if",
"(",
"$",
"prefix_path",
")",
"{",
"static",
"::",
"set",
"(",
"$",
"prefix_path",
",",
"$",
"array",
")",
";",
"}",
"else",
"{",
"static",
"::",
"merge",
"(",
"$",
"array",
")",
";",
"}",
"self",
"::",
"trigger",
"(",
"'loaded'",
")",
";",
"}"
]
| Load an array to the configuration
@param array $array The array to load
@param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary | [
"Load",
"an",
"array",
"to",
"the",
"configuration"
]
| 819134644dfb3b6379a12fff08fa5ec45a2c614c | https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Options.php#L63-L71 | train |
caffeina-core/core | classes/Options.php | Options.loadENV | public static function loadENV($dir,$envname='.env',$prefix_path=null){
$dir = rtrim($dir,'/');
$results = [];
foreach(file("$dir/$envname", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line){
$line = trim($line);
if ($line[0]=='#' || strpos($line,'=')===false) continue;
list($key,$value) = explode('=',$line,2);
$key = trim(str_replace(['export ', "'", '"'], '', $key));
$value = stripslashes(trim($value,'"\''));
$results[$key] = preg_replace_callback('/\${([a-zA-Z0-9_]+)}/',function($m) use (&$results){
return isset($results[$m[1]]) ? $results[$m[1]] : '';
},$value);
putenv("$key={$results[$key]}");
$_ENV[$key] = $results[$key];
}
if($results) {
$results = static::filterWith(["load.env", "load"], $results);
static::loadArray($results,$prefix_path);
}
} | php | public static function loadENV($dir,$envname='.env',$prefix_path=null){
$dir = rtrim($dir,'/');
$results = [];
foreach(file("$dir/$envname", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line){
$line = trim($line);
if ($line[0]=='#' || strpos($line,'=')===false) continue;
list($key,$value) = explode('=',$line,2);
$key = trim(str_replace(['export ', "'", '"'], '', $key));
$value = stripslashes(trim($value,'"\''));
$results[$key] = preg_replace_callback('/\${([a-zA-Z0-9_]+)}/',function($m) use (&$results){
return isset($results[$m[1]]) ? $results[$m[1]] : '';
},$value);
putenv("$key={$results[$key]}");
$_ENV[$key] = $results[$key];
}
if($results) {
$results = static::filterWith(["load.env", "load"], $results);
static::loadArray($results,$prefix_path);
}
} | [
"public",
"static",
"function",
"loadENV",
"(",
"$",
"dir",
",",
"$",
"envname",
"=",
"'.env'",
",",
"$",
"prefix_path",
"=",
"null",
")",
"{",
"$",
"dir",
"=",
"rtrim",
"(",
"$",
"dir",
",",
"'/'",
")",
";",
"$",
"results",
"=",
"[",
"]",
";",
"foreach",
"(",
"file",
"(",
"\"$dir/$envname\"",
",",
"FILE_IGNORE_NEW_LINES",
"|",
"FILE_SKIP_EMPTY_LINES",
")",
"as",
"$",
"line",
")",
"{",
"$",
"line",
"=",
"trim",
"(",
"$",
"line",
")",
";",
"if",
"(",
"$",
"line",
"[",
"0",
"]",
"==",
"'#'",
"||",
"strpos",
"(",
"$",
"line",
",",
"'='",
")",
"===",
"false",
")",
"continue",
";",
"list",
"(",
"$",
"key",
",",
"$",
"value",
")",
"=",
"explode",
"(",
"'='",
",",
"$",
"line",
",",
"2",
")",
";",
"$",
"key",
"=",
"trim",
"(",
"str_replace",
"(",
"[",
"'export '",
",",
"\"'\"",
",",
"'\"'",
"]",
",",
"''",
",",
"$",
"key",
")",
")",
";",
"$",
"value",
"=",
"stripslashes",
"(",
"trim",
"(",
"$",
"value",
",",
"'\"\\''",
")",
")",
";",
"$",
"results",
"[",
"$",
"key",
"]",
"=",
"preg_replace_callback",
"(",
"'/\\${([a-zA-Z0-9_]+)}/'",
",",
"function",
"(",
"$",
"m",
")",
"use",
"(",
"&",
"$",
"results",
")",
"{",
"return",
"isset",
"(",
"$",
"results",
"[",
"$",
"m",
"[",
"1",
"]",
"]",
")",
"?",
"$",
"results",
"[",
"$",
"m",
"[",
"1",
"]",
"]",
":",
"''",
";",
"}",
",",
"$",
"value",
")",
";",
"putenv",
"(",
"\"$key={$results[$key]}\"",
")",
";",
"$",
"_ENV",
"[",
"$",
"key",
"]",
"=",
"$",
"results",
"[",
"$",
"key",
"]",
";",
"}",
"if",
"(",
"$",
"results",
")",
"{",
"$",
"results",
"=",
"static",
"::",
"filterWith",
"(",
"[",
"\"load.env\"",
",",
"\"load\"",
"]",
",",
"$",
"results",
")",
";",
"static",
"::",
"loadArray",
"(",
"$",
"results",
",",
"$",
"prefix_path",
")",
";",
"}",
"}"
]
| Load an ENV file
@param string $dir The directory of the ENV file
@param string $envname The filename for the ENV file (Default to `.env`)
@param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary | [
"Load",
"an",
"ENV",
"file"
]
| 819134644dfb3b6379a12fff08fa5ec45a2c614c | https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Options.php#L79-L98 | train |
caffeina-core/core | classes/SQL.php | SQL.register | public static function register($name, $dsn, $username=null, $password=null, $options=[]){
return self::$connections[$name] = new SQLConnection($dsn, $username, $password, $options);
} | php | public static function register($name, $dsn, $username=null, $password=null, $options=[]){
return self::$connections[$name] = new SQLConnection($dsn, $username, $password, $options);
} | [
"public",
"static",
"function",
"register",
"(",
"$",
"name",
",",
"$",
"dsn",
",",
"$",
"username",
"=",
"null",
",",
"$",
"password",
"=",
"null",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"return",
"self",
"::",
"$",
"connections",
"[",
"$",
"name",
"]",
"=",
"new",
"SQLConnection",
"(",
"$",
"dsn",
",",
"$",
"username",
",",
"$",
"password",
",",
"$",
"options",
")",
";",
"}"
]
| Register a new datasource
@param string $name The assigned name for the datasource
@param string $dsn PDO DSN URL
@param string $username User credentials
@param string $password User credentials
@param array $options Options to pass to the PDO constructor
@return SQLConnection The datasource resource | [
"Register",
"a",
"new",
"datasource"
]
| 819134644dfb3b6379a12fff08fa5ec45a2c614c | https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/SQL.php#L29-L31 | train |
caffeina-core/core | classes/SQL.php | SQL.connect | public static function connect($dsn, $username=null, $password=null, $options=[]){
return self::register('default', $dsn, $username, $password, $options);
} | php | public static function connect($dsn, $username=null, $password=null, $options=[]){
return self::register('default', $dsn, $username, $password, $options);
} | [
"public",
"static",
"function",
"connect",
"(",
"$",
"dsn",
",",
"$",
"username",
"=",
"null",
",",
"$",
"password",
"=",
"null",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"return",
"self",
"::",
"register",
"(",
"'default'",
",",
"$",
"dsn",
",",
"$",
"username",
",",
"$",
"password",
",",
"$",
"options",
")",
";",
"}"
]
| Register the default datasource
@param string $dsn PDO DSN URL
@param string $username User credentials
@param string $password User credentials
@param array $options Options to pass to the PDO constructor
@return SQLConnection The datasource resource | [
"Register",
"the",
"default",
"datasource"
]
| 819134644dfb3b6379a12fff08fa5ec45a2c614c | https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/SQL.php#L41-L43 | train |
caffeina-core/core | classes/SQL.php | SQL.defaultTo | public static function defaultTo($name){
if (isset(self::$connections[$name])){
self::$current = $name;
return true;
} else return false;
} | php | public static function defaultTo($name){
if (isset(self::$connections[$name])){
self::$current = $name;
return true;
} else return false;
} | [
"public",
"static",
"function",
"defaultTo",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"connections",
"[",
"$",
"name",
"]",
")",
")",
"{",
"self",
"::",
"$",
"current",
"=",
"$",
"name",
";",
"return",
"true",
";",
"}",
"else",
"return",
"false",
";",
"}"
]
| Bind the default datasource to another named connection
@param string $name The datasource name
@return bool `true` if correctly changed | [
"Bind",
"the",
"default",
"datasource",
"to",
"another",
"named",
"connection"
]
| 819134644dfb3b6379a12fff08fa5ec45a2c614c | https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/SQL.php#L50-L55 | train |
caffeina-core/core | classes/SQL.php | SQL.using | public static function using($name){
if (empty(self::$connections[$name])) throw new \Exception("[SQL] Unknown connection named '$name'.");
return self::$connections[$name];
} | php | public static function using($name){
if (empty(self::$connections[$name])) throw new \Exception("[SQL] Unknown connection named '$name'.");
return self::$connections[$name];
} | [
"public",
"static",
"function",
"using",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"empty",
"(",
"self",
"::",
"$",
"connections",
"[",
"$",
"name",
"]",
")",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"\"[SQL] Unknown connection named '$name'.\"",
")",
";",
"return",
"self",
"::",
"$",
"connections",
"[",
"$",
"name",
"]",
";",
"}"
]
| Datasource connection accessor
@param strinf $name The datasource name
@return SQLConnect The datasource connection | [
"Datasource",
"connection",
"accessor"
]
| 819134644dfb3b6379a12fff08fa5ec45a2c614c | https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/SQL.php#L77-L80 | train |
caffeina-core/core | classes/SQL.php | SQLConnection.prepare | public function prepare($query, $pdo_params=[]){
if(!$this->connection()) return false;
return isset($this->queries[$query]) ? $this->queries[$query] : ($this->queries[$query] = $this->connection()->prepare($query, $pdo_params));
} | php | public function prepare($query, $pdo_params=[]){
if(!$this->connection()) return false;
return isset($this->queries[$query]) ? $this->queries[$query] : ($this->queries[$query] = $this->connection()->prepare($query, $pdo_params));
} | [
"public",
"function",
"prepare",
"(",
"$",
"query",
",",
"$",
"pdo_params",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"connection",
"(",
")",
")",
"return",
"false",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"queries",
"[",
"$",
"query",
"]",
")",
"?",
"$",
"this",
"->",
"queries",
"[",
"$",
"query",
"]",
":",
"(",
"$",
"this",
"->",
"queries",
"[",
"$",
"query",
"]",
"=",
"$",
"this",
"->",
"connection",
"(",
")",
"->",
"prepare",
"(",
"$",
"query",
",",
"$",
"pdo_params",
")",
")",
";",
"}"
]
| Prepares a SQL query string
@param string $query The query
@param array $pdo_params The extra PDO parameters
@return boolean | [
"Prepares",
"a",
"SQL",
"query",
"string"
]
| 819134644dfb3b6379a12fff08fa5ec45a2c614c | https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/SQL.php#L155-L158 | train |
caffeina-core/core | classes/Persistence.php | Persistence.load | public static function load($pk){
$table = static::persistenceOptions('table');
$cb = static::persistenceLoad();
$op = static::persistenceOptions();
// Use standard persistence on DB layer
return ( false == is_callable($cb) ) ?
static::persistenceLoadDefault($pk,$table,$op) : $cb($pk,$table,$op);
} | php | public static function load($pk){
$table = static::persistenceOptions('table');
$cb = static::persistenceLoad();
$op = static::persistenceOptions();
// Use standard persistence on DB layer
return ( false == is_callable($cb) ) ?
static::persistenceLoadDefault($pk,$table,$op) : $cb($pk,$table,$op);
} | [
"public",
"static",
"function",
"load",
"(",
"$",
"pk",
")",
"{",
"$",
"table",
"=",
"static",
"::",
"persistenceOptions",
"(",
"'table'",
")",
";",
"$",
"cb",
"=",
"static",
"::",
"persistenceLoad",
"(",
")",
";",
"$",
"op",
"=",
"static",
"::",
"persistenceOptions",
"(",
")",
";",
"// Use standard persistence on DB layer",
"return",
"(",
"false",
"==",
"is_callable",
"(",
"$",
"cb",
")",
")",
"?",
"static",
"::",
"persistenceLoadDefault",
"(",
"$",
"pk",
",",
"$",
"table",
",",
"$",
"op",
")",
":",
"$",
"cb",
"(",
"$",
"pk",
",",
"$",
"table",
",",
"$",
"op",
")",
";",
"}"
]
| Load the model from the persistence layer
@return mixed The retrieved object | [
"Load",
"the",
"model",
"from",
"the",
"persistence",
"layer"
]
| 819134644dfb3b6379a12fff08fa5ec45a2c614c | https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Persistence.php#L123-L131 | train |
caffeina-core/core | classes/Persistence.php | Persistence.persistenceLoadDefault | private static function persistenceLoadDefault($pk, $table, $options){
if ( $data = SQL::single("SELECT * FROM $table WHERE {$options['key']}=? LIMIT 1",[$pk]) ){
$obj = new static;
foreach ((array)$data as $key => $value) {
$obj->$key = $value;
}
if (is_callable(($c=get_called_class())."::trigger")) $c::trigger("load", $obj, $table, $options['key']);
return $obj;
} else {
return null;
}
} | php | private static function persistenceLoadDefault($pk, $table, $options){
if ( $data = SQL::single("SELECT * FROM $table WHERE {$options['key']}=? LIMIT 1",[$pk]) ){
$obj = new static;
foreach ((array)$data as $key => $value) {
$obj->$key = $value;
}
if (is_callable(($c=get_called_class())."::trigger")) $c::trigger("load", $obj, $table, $options['key']);
return $obj;
} else {
return null;
}
} | [
"private",
"static",
"function",
"persistenceLoadDefault",
"(",
"$",
"pk",
",",
"$",
"table",
",",
"$",
"options",
")",
"{",
"if",
"(",
"$",
"data",
"=",
"SQL",
"::",
"single",
"(",
"\"SELECT * FROM $table WHERE {$options['key']}=? LIMIT 1\"",
",",
"[",
"$",
"pk",
"]",
")",
")",
"{",
"$",
"obj",
"=",
"new",
"static",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"obj",
"->",
"$",
"key",
"=",
"$",
"value",
";",
"}",
"if",
"(",
"is_callable",
"(",
"(",
"$",
"c",
"=",
"get_called_class",
"(",
")",
")",
".",
"\"::trigger\"",
")",
")",
"$",
"c",
"::",
"trigger",
"(",
"\"load\"",
",",
"$",
"obj",
",",
"$",
"table",
",",
"$",
"options",
"[",
"'key'",
"]",
")",
";",
"return",
"$",
"obj",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
]
| Private Standard Load Method | [
"Private",
"Standard",
"Load",
"Method"
]
| 819134644dfb3b6379a12fff08fa5ec45a2c614c | https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Persistence.php#L136-L147 | train |
caffeina-core/core | classes/Persistence.php | Persistence.save | public function save(){
$table = static::persistenceOptions('table');
$op = static::persistenceOptions();
$cb = static::persistenceSave();
// Use standard persistence on DB layer
$cb = $cb ? Closure::bind($cb, $this) : [$this,'persistenceSaveDefault'];
return $cb($table,$op);
} | php | public function save(){
$table = static::persistenceOptions('table');
$op = static::persistenceOptions();
$cb = static::persistenceSave();
// Use standard persistence on DB layer
$cb = $cb ? Closure::bind($cb, $this) : [$this,'persistenceSaveDefault'];
return $cb($table,$op);
} | [
"public",
"function",
"save",
"(",
")",
"{",
"$",
"table",
"=",
"static",
"::",
"persistenceOptions",
"(",
"'table'",
")",
";",
"$",
"op",
"=",
"static",
"::",
"persistenceOptions",
"(",
")",
";",
"$",
"cb",
"=",
"static",
"::",
"persistenceSave",
"(",
")",
";",
"// Use standard persistence on DB layer",
"$",
"cb",
"=",
"$",
"cb",
"?",
"Closure",
"::",
"bind",
"(",
"$",
"cb",
",",
"$",
"this",
")",
":",
"[",
"$",
"this",
",",
"'persistenceSaveDefault'",
"]",
";",
"return",
"$",
"cb",
"(",
"$",
"table",
",",
"$",
"op",
")",
";",
"}"
]
| Save the model to the persistence layer
@return mixed The results from the save callback. (default: lastInsertID) | [
"Save",
"the",
"model",
"to",
"the",
"persistence",
"layer"
]
| 819134644dfb3b6379a12fff08fa5ec45a2c614c | https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Persistence.php#L153-L161 | train |
caffeina-core/core | classes/Persistence.php | Persistence.persistenceSaveDefault | private function persistenceSaveDefault($table,$options){
if (is_callable(($c=get_called_class())."::trigger")) $c::trigger("save", $this, $table, $options['key']);
$id = SQL::insertOrUpdate($table,array_filter((array)$this, function($var) {
return !is_null($var);
}),$options['key']);
// Populate retrieved primary key in Models.
if (null !== $id && is_a($this, 'Model')) $this->{$options['key']} = $id;
return $id;
} | php | private function persistenceSaveDefault($table,$options){
if (is_callable(($c=get_called_class())."::trigger")) $c::trigger("save", $this, $table, $options['key']);
$id = SQL::insertOrUpdate($table,array_filter((array)$this, function($var) {
return !is_null($var);
}),$options['key']);
// Populate retrieved primary key in Models.
if (null !== $id && is_a($this, 'Model')) $this->{$options['key']} = $id;
return $id;
} | [
"private",
"function",
"persistenceSaveDefault",
"(",
"$",
"table",
",",
"$",
"options",
")",
"{",
"if",
"(",
"is_callable",
"(",
"(",
"$",
"c",
"=",
"get_called_class",
"(",
")",
")",
".",
"\"::trigger\"",
")",
")",
"$",
"c",
"::",
"trigger",
"(",
"\"save\"",
",",
"$",
"this",
",",
"$",
"table",
",",
"$",
"options",
"[",
"'key'",
"]",
")",
";",
"$",
"id",
"=",
"SQL",
"::",
"insertOrUpdate",
"(",
"$",
"table",
",",
"array_filter",
"(",
"(",
"array",
")",
"$",
"this",
",",
"function",
"(",
"$",
"var",
")",
"{",
"return",
"!",
"is_null",
"(",
"$",
"var",
")",
";",
"}",
")",
",",
"$",
"options",
"[",
"'key'",
"]",
")",
";",
"// Populate retrieved primary key in Models.",
"if",
"(",
"null",
"!==",
"$",
"id",
"&&",
"is_a",
"(",
"$",
"this",
",",
"'Model'",
")",
")",
"$",
"this",
"->",
"{",
"$",
"options",
"[",
"'key'",
"]",
"}",
"=",
"$",
"id",
";",
"return",
"$",
"id",
";",
"}"
]
| Private Standard Save Method | [
"Private",
"Standard",
"Save",
"Method"
]
| 819134644dfb3b6379a12fff08fa5ec45a2c614c | https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Persistence.php#L166-L174 | train |
caffeina-core/core | classes/Request.php | Request.accept | public static function accept($key='type',$choices='') {
if (null === static::$accepts) static::$accepts = [
'type' => new Negotiation(isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : ''),
'language' => new Negotiation(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : ''),
'encoding' => new Negotiation(isset($_SERVER['HTTP_ACCEPT_ENCODING']) ? $_SERVER['HTTP_ACCEPT_ENCODING'] : ''),
'charset' => new Negotiation(isset($_SERVER['HTTP_ACCEPT_CHARSET']) ? $_SERVER['HTTP_ACCEPT_CHARSET'] : ''),
];
return empty(static::$accepts[$key])
? false
: ( empty($choices)
? static::$accepts[$key]->preferred()
: static::$accepts[$key]->best($choices)
);
} | php | public static function accept($key='type',$choices='') {
if (null === static::$accepts) static::$accepts = [
'type' => new Negotiation(isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : ''),
'language' => new Negotiation(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : ''),
'encoding' => new Negotiation(isset($_SERVER['HTTP_ACCEPT_ENCODING']) ? $_SERVER['HTTP_ACCEPT_ENCODING'] : ''),
'charset' => new Negotiation(isset($_SERVER['HTTP_ACCEPT_CHARSET']) ? $_SERVER['HTTP_ACCEPT_CHARSET'] : ''),
];
return empty(static::$accepts[$key])
? false
: ( empty($choices)
? static::$accepts[$key]->preferred()
: static::$accepts[$key]->best($choices)
);
} | [
"public",
"static",
"function",
"accept",
"(",
"$",
"key",
"=",
"'type'",
",",
"$",
"choices",
"=",
"''",
")",
"{",
"if",
"(",
"null",
"===",
"static",
"::",
"$",
"accepts",
")",
"static",
"::",
"$",
"accepts",
"=",
"[",
"'type'",
"=>",
"new",
"Negotiation",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT'",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT'",
"]",
":",
"''",
")",
",",
"'language'",
"=>",
"new",
"Negotiation",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_LANGUAGE'",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_LANGUAGE'",
"]",
":",
"''",
")",
",",
"'encoding'",
"=>",
"new",
"Negotiation",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_ENCODING'",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_ENCODING'",
"]",
":",
"''",
")",
",",
"'charset'",
"=>",
"new",
"Negotiation",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_CHARSET'",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_CHARSET'",
"]",
":",
"''",
")",
",",
"]",
";",
"return",
"empty",
"(",
"static",
"::",
"$",
"accepts",
"[",
"$",
"key",
"]",
")",
"?",
"false",
":",
"(",
"empty",
"(",
"$",
"choices",
")",
"?",
"static",
"::",
"$",
"accepts",
"[",
"$",
"key",
"]",
"->",
"preferred",
"(",
")",
":",
"static",
"::",
"$",
"accepts",
"[",
"$",
"key",
"]",
"->",
"best",
"(",
"$",
"choices",
")",
")",
";",
"}"
]
| Handle Content Negotiation requests
@param string $key The name of the negotiation subject
@param string $choices A query string for the negotiation choices (See RFC 7231)
@return Object The preferred content if $choices is empty else return best match | [
"Handle",
"Content",
"Negotiation",
"requests"
]
| 819134644dfb3b6379a12fff08fa5ec45a2c614c | https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Request.php#L27-L40 | train |
caffeina-core/core | classes/Request.php | Request.URI | public static function URI(){
switch(true){
case !empty($_SERVER['REQUEST_URI']): $serv_uri = $_SERVER['REQUEST_URI']; break;
case !empty($_SERVER['ORIG_PATH_INFO']): $serv_uri = $_SERVER['ORIG_PATH_INFO']; break;
case !empty($_SERVER['PATH_INFO']): $serv_uri = $_SERVER['PATH_INFO']; break;
default: $serv_uri = '/'; break;
}
$uri = rtrim(strtok($serv_uri,'?'),'/') ?: '/';
return Filter::with('core.request.URI', $uri) ?: '/';
} | php | public static function URI(){
switch(true){
case !empty($_SERVER['REQUEST_URI']): $serv_uri = $_SERVER['REQUEST_URI']; break;
case !empty($_SERVER['ORIG_PATH_INFO']): $serv_uri = $_SERVER['ORIG_PATH_INFO']; break;
case !empty($_SERVER['PATH_INFO']): $serv_uri = $_SERVER['PATH_INFO']; break;
default: $serv_uri = '/'; break;
}
$uri = rtrim(strtok($serv_uri,'?'),'/') ?: '/';
return Filter::with('core.request.URI', $uri) ?: '/';
} | [
"public",
"static",
"function",
"URI",
"(",
")",
"{",
"switch",
"(",
"true",
")",
"{",
"case",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
")",
":",
"$",
"serv_uri",
"=",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
";",
"break",
";",
"case",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'ORIG_PATH_INFO'",
"]",
")",
":",
"$",
"serv_uri",
"=",
"$",
"_SERVER",
"[",
"'ORIG_PATH_INFO'",
"]",
";",
"break",
";",
"case",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'PATH_INFO'",
"]",
")",
":",
"$",
"serv_uri",
"=",
"$",
"_SERVER",
"[",
"'PATH_INFO'",
"]",
";",
"break",
";",
"default",
":",
"$",
"serv_uri",
"=",
"'/'",
";",
"break",
";",
"}",
"$",
"uri",
"=",
"rtrim",
"(",
"strtok",
"(",
"$",
"serv_uri",
",",
"'?'",
")",
",",
"'/'",
")",
"?",
":",
"'/'",
";",
"return",
"Filter",
"::",
"with",
"(",
"'core.request.URI'",
",",
"$",
"uri",
")",
"?",
":",
"'/'",
";",
"}"
]
| Returns the current request URI.
@return string | [
"Returns",
"the",
"current",
"request",
"URI",
"."
]
| 819134644dfb3b6379a12fff08fa5ec45a2c614c | https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Request.php#L180-L189 | train |
caffeina-core/core | classes/Request.php | Request.IP | public static function IP(){
switch(true){
case !empty($_SERVER['HTTP_X_FORWARDED_FOR']):
$ip = trim(substr(strrchr($_SERVER['HTTP_X_FORWARDED_FOR'],','),1) ?: $_SERVER['HTTP_X_FORWARDED_FOR']);
break;
case !empty($_SERVER['HTTP_X_FORWARDED_HOST']):
$ip = trim(substr(strrchr($_SERVER['HTTP_X_FORWARDED_HOST'],','),1) ?: $_SERVER['HTTP_X_FORWARDED_HOST']);
break;
case !empty($_SERVER['REMOTE_ADDR']): $ip = $_SERVER['REMOTE_ADDR']; break;
case !empty($_SERVER['HTTP_CLIENT_IP']): $ip = $_SERVER['HTTP_CLIENT_IP']; break;
default: $ip = ''; break;
}
return Filter::with('core.request.IP',$ip);
} | php | public static function IP(){
switch(true){
case !empty($_SERVER['HTTP_X_FORWARDED_FOR']):
$ip = trim(substr(strrchr($_SERVER['HTTP_X_FORWARDED_FOR'],','),1) ?: $_SERVER['HTTP_X_FORWARDED_FOR']);
break;
case !empty($_SERVER['HTTP_X_FORWARDED_HOST']):
$ip = trim(substr(strrchr($_SERVER['HTTP_X_FORWARDED_HOST'],','),1) ?: $_SERVER['HTTP_X_FORWARDED_HOST']);
break;
case !empty($_SERVER['REMOTE_ADDR']): $ip = $_SERVER['REMOTE_ADDR']; break;
case !empty($_SERVER['HTTP_CLIENT_IP']): $ip = $_SERVER['HTTP_CLIENT_IP']; break;
default: $ip = ''; break;
}
return Filter::with('core.request.IP',$ip);
} | [
"public",
"static",
"function",
"IP",
"(",
")",
"{",
"switch",
"(",
"true",
")",
"{",
"case",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'HTTP_X_FORWARDED_FOR'",
"]",
")",
":",
"$",
"ip",
"=",
"trim",
"(",
"substr",
"(",
"strrchr",
"(",
"$",
"_SERVER",
"[",
"'HTTP_X_FORWARDED_FOR'",
"]",
",",
"','",
")",
",",
"1",
")",
"?",
":",
"$",
"_SERVER",
"[",
"'HTTP_X_FORWARDED_FOR'",
"]",
")",
";",
"break",
";",
"case",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'HTTP_X_FORWARDED_HOST'",
"]",
")",
":",
"$",
"ip",
"=",
"trim",
"(",
"substr",
"(",
"strrchr",
"(",
"$",
"_SERVER",
"[",
"'HTTP_X_FORWARDED_HOST'",
"]",
",",
"','",
")",
",",
"1",
")",
"?",
":",
"$",
"_SERVER",
"[",
"'HTTP_X_FORWARDED_HOST'",
"]",
")",
";",
"break",
";",
"case",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'REMOTE_ADDR'",
"]",
")",
":",
"$",
"ip",
"=",
"$",
"_SERVER",
"[",
"'REMOTE_ADDR'",
"]",
";",
"break",
";",
"case",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'HTTP_CLIENT_IP'",
"]",
")",
":",
"$",
"ip",
"=",
"$",
"_SERVER",
"[",
"'HTTP_CLIENT_IP'",
"]",
";",
"break",
";",
"default",
":",
"$",
"ip",
"=",
"''",
";",
"break",
";",
"}",
"return",
"Filter",
"::",
"with",
"(",
"'core.request.IP'",
",",
"$",
"ip",
")",
";",
"}"
]
| Returns the remote IP
@return string | [
"Returns",
"the",
"remote",
"IP"
]
| 819134644dfb3b6379a12fff08fa5ec45a2c614c | https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Request.php#L214-L227 | train |
caffeina-core/core | classes/Password.php | Password.verify | public static function verify($password, $hash){
// Pre PHP 5.5 support
if (!defined('PASSWORD_DEFAULT') || substr($hash,0,4)=='$5h$') {
return '$5h$'.hash('sha1',$password) == $hash;
} else {
return password_verify($password,$hash);
}
} | php | public static function verify($password, $hash){
// Pre PHP 5.5 support
if (!defined('PASSWORD_DEFAULT') || substr($hash,0,4)=='$5h$') {
return '$5h$'.hash('sha1',$password) == $hash;
} else {
return password_verify($password,$hash);
}
} | [
"public",
"static",
"function",
"verify",
"(",
"$",
"password",
",",
"$",
"hash",
")",
"{",
"// Pre PHP 5.5 support",
"if",
"(",
"!",
"defined",
"(",
"'PASSWORD_DEFAULT'",
")",
"||",
"substr",
"(",
"$",
"hash",
",",
"0",
",",
"4",
")",
"==",
"'$5h$'",
")",
"{",
"return",
"'$5h$'",
".",
"hash",
"(",
"'sha1'",
",",
"$",
"password",
")",
"==",
"$",
"hash",
";",
"}",
"else",
"{",
"return",
"password_verify",
"(",
"$",
"password",
",",
"$",
"hash",
")",
";",
"}",
"}"
]
| Verify if password match a given hash
@param string $password The password to check
@param string $hash The hash to match against
@return bool Returns `true` if hash match password | [
"Verify",
"if",
"password",
"match",
"a",
"given",
"hash"
]
| 819134644dfb3b6379a12fff08fa5ec45a2c614c | https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Password.php#L36-L43 | train |
spiral/storage | src/Server/GridFSServer.php | GridFSServer.gridFS | protected function gridFS(BucketInterface $bucket): Bucket
{
if (empty($this->database)) {
$this->database = new Database(
new Manager($this->options['connection']),
$this->options['database']
);
}
return $this->database->selectGridFSBucket([
'bucketName' => $bucket->getOption('bucket')
]);
} | php | protected function gridFS(BucketInterface $bucket): Bucket
{
if (empty($this->database)) {
$this->database = new Database(
new Manager($this->options['connection']),
$this->options['database']
);
}
return $this->database->selectGridFSBucket([
'bucketName' => $bucket->getOption('bucket')
]);
} | [
"protected",
"function",
"gridFS",
"(",
"BucketInterface",
"$",
"bucket",
")",
":",
"Bucket",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"database",
")",
")",
"{",
"$",
"this",
"->",
"database",
"=",
"new",
"Database",
"(",
"new",
"Manager",
"(",
"$",
"this",
"->",
"options",
"[",
"'connection'",
"]",
")",
",",
"$",
"this",
"->",
"options",
"[",
"'database'",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"database",
"->",
"selectGridFSBucket",
"(",
"[",
"'bucketName'",
"=>",
"$",
"bucket",
"->",
"getOption",
"(",
"'bucket'",
")",
"]",
")",
";",
"}"
]
| Get valid GridFS collection associated with bucket.
@param BucketInterface $bucket Bucket instance.
@return Bucket | [
"Get",
"valid",
"GridFS",
"collection",
"associated",
"with",
"bucket",
"."
]
| 65b8336ea45bee9c3fef591bd8e317308774a841 | https://github.com/spiral/storage/blob/65b8336ea45bee9c3fef591bd8e317308774a841/src/Server/GridFSServer.php#L169-L181 | train |
caffeina-core/core | classes/Work.php | Work.install_shutdown | protected static function install_shutdown(){
if (static::$inited_shutdown) return;
// Disable time limit
set_time_limit(0);
// HHVM support
if(function_exists('register_postsend_function')){
register_postsend_function(function(){
Event::trigger('core.shutdown');
});
} else if(function_exists('fastcgi_finish_request')) {
register_shutdown_function(function(){
fastcgi_finish_request();
Event::trigger('core.shutdown');
});
} else {
register_shutdown_function(function(){
Event::trigger('core.shutdown');
});
}
static::$inited_shutdown = true;
} | php | protected static function install_shutdown(){
if (static::$inited_shutdown) return;
// Disable time limit
set_time_limit(0);
// HHVM support
if(function_exists('register_postsend_function')){
register_postsend_function(function(){
Event::trigger('core.shutdown');
});
} else if(function_exists('fastcgi_finish_request')) {
register_shutdown_function(function(){
fastcgi_finish_request();
Event::trigger('core.shutdown');
});
} else {
register_shutdown_function(function(){
Event::trigger('core.shutdown');
});
}
static::$inited_shutdown = true;
} | [
"protected",
"static",
"function",
"install_shutdown",
"(",
")",
"{",
"if",
"(",
"static",
"::",
"$",
"inited_shutdown",
")",
"return",
";",
"// Disable time limit",
"set_time_limit",
"(",
"0",
")",
";",
"// HHVM support",
"if",
"(",
"function_exists",
"(",
"'register_postsend_function'",
")",
")",
"{",
"register_postsend_function",
"(",
"function",
"(",
")",
"{",
"Event",
"::",
"trigger",
"(",
"'core.shutdown'",
")",
";",
"}",
")",
";",
"}",
"else",
"if",
"(",
"function_exists",
"(",
"'fastcgi_finish_request'",
")",
")",
"{",
"register_shutdown_function",
"(",
"function",
"(",
")",
"{",
"fastcgi_finish_request",
"(",
")",
";",
"Event",
"::",
"trigger",
"(",
"'core.shutdown'",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"register_shutdown_function",
"(",
"function",
"(",
")",
"{",
"Event",
"::",
"trigger",
"(",
"'core.shutdown'",
")",
";",
"}",
")",
";",
"}",
"static",
"::",
"$",
"inited_shutdown",
"=",
"true",
";",
"}"
]
| Single shot defer handeler install | [
"Single",
"shot",
"defer",
"handeler",
"install"
]
| 819134644dfb3b6379a12fff08fa5ec45a2c614c | https://github.com/caffeina-core/core/blob/819134644dfb3b6379a12fff08fa5ec45a2c614c/classes/Work.php#L62-L85 | train |
GrahamCampbell/Cache-Plugin | src/CachePlugin.php | CachePlugin.createCacheItem | protected function createCacheItem(RequestInterface $request)
{
$key = sha1($this->generator->generate($request));
return $this->pool->getItem($key);
} | php | protected function createCacheItem(RequestInterface $request)
{
$key = sha1($this->generator->generate($request));
return $this->pool->getItem($key);
} | [
"protected",
"function",
"createCacheItem",
"(",
"RequestInterface",
"$",
"request",
")",
"{",
"$",
"key",
"=",
"sha1",
"(",
"$",
"this",
"->",
"generator",
"->",
"generate",
"(",
"$",
"request",
")",
")",
";",
"return",
"$",
"this",
"->",
"pool",
"->",
"getItem",
"(",
"$",
"key",
")",
";",
"}"
]
| Create a cache item for a request.
@param \Psr\Http\Message\RequestInterface $request
@return \Psr\Cache\CacheItemInterface | [
"Create",
"a",
"cache",
"item",
"for",
"a",
"request",
"."
]
| 330e089fee2f4ee34db1ec5129c12469f8b81f66 | https://github.com/GrahamCampbell/Cache-Plugin/blob/330e089fee2f4ee34db1ec5129c12469f8b81f66/src/CachePlugin.php#L152-L157 | train |
GrahamCampbell/Cache-Plugin | src/CachePlugin.php | CachePlugin.getCacheControlDirective | protected function getCacheControlDirective(ResponseInterface $response, string $name)
{
foreach ($response->getHeader('Cache-Control') as $header) {
if (preg_match(sprintf('|%s=?([0-9]+)?|i', $name), $header, $matches)) {
// return the value for $name if it exists
if (isset($matches[1])) {
return $matches[1];
}
return true;
}
}
return false;
} | php | protected function getCacheControlDirective(ResponseInterface $response, string $name)
{
foreach ($response->getHeader('Cache-Control') as $header) {
if (preg_match(sprintf('|%s=?([0-9]+)?|i', $name), $header, $matches)) {
// return the value for $name if it exists
if (isset($matches[1])) {
return $matches[1];
}
return true;
}
}
return false;
} | [
"protected",
"function",
"getCacheControlDirective",
"(",
"ResponseInterface",
"$",
"response",
",",
"string",
"$",
"name",
")",
"{",
"foreach",
"(",
"$",
"response",
"->",
"getHeader",
"(",
"'Cache-Control'",
")",
"as",
"$",
"header",
")",
"{",
"if",
"(",
"preg_match",
"(",
"sprintf",
"(",
"'|%s=?([0-9]+)?|i'",
",",
"$",
"name",
")",
",",
"$",
"header",
",",
"$",
"matches",
")",
")",
"{",
"// return the value for $name if it exists",
"if",
"(",
"isset",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
")",
"{",
"return",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Get the value of a parameter in the cache control header.
@param \Psr\Http\Message\ResponseInterface $response
@param string $name
@return bool|string | [
"Get",
"the",
"value",
"of",
"a",
"parameter",
"in",
"the",
"cache",
"control",
"header",
"."
]
| 330e089fee2f4ee34db1ec5129c12469f8b81f66 | https://github.com/GrahamCampbell/Cache-Plugin/blob/330e089fee2f4ee34db1ec5129c12469f8b81f66/src/CachePlugin.php#L183-L197 | train |
GrahamCampbell/Cache-Plugin | src/CachePlugin.php | CachePlugin.createResponseFromCacheItem | protected function createResponseFromCacheItem(CacheItemInterface $cacheItem)
{
$data = $cacheItem->get();
$response = $data['response'];
$stream = $this->streamFactory->createStream($data['body']);
try {
$stream->rewind();
} catch (Exception $e) {
throw new RewindStreamException('Cannot rewind stream.', 0, $e);
}
$response = $response->withBody($stream);
return $response;
} | php | protected function createResponseFromCacheItem(CacheItemInterface $cacheItem)
{
$data = $cacheItem->get();
$response = $data['response'];
$stream = $this->streamFactory->createStream($data['body']);
try {
$stream->rewind();
} catch (Exception $e) {
throw new RewindStreamException('Cannot rewind stream.', 0, $e);
}
$response = $response->withBody($stream);
return $response;
} | [
"protected",
"function",
"createResponseFromCacheItem",
"(",
"CacheItemInterface",
"$",
"cacheItem",
")",
"{",
"$",
"data",
"=",
"$",
"cacheItem",
"->",
"get",
"(",
")",
";",
"$",
"response",
"=",
"$",
"data",
"[",
"'response'",
"]",
";",
"$",
"stream",
"=",
"$",
"this",
"->",
"streamFactory",
"->",
"createStream",
"(",
"$",
"data",
"[",
"'body'",
"]",
")",
";",
"try",
"{",
"$",
"stream",
"->",
"rewind",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"RewindStreamException",
"(",
"'Cannot rewind stream.'",
",",
"0",
",",
"$",
"e",
")",
";",
"}",
"$",
"response",
"=",
"$",
"response",
"->",
"withBody",
"(",
"$",
"stream",
")",
";",
"return",
"$",
"response",
";",
"}"
]
| Create a response from a cache item.
@param \Psr\Cache\CacheItemInterface $cacheItem
@return \Psr\Http\Message\ResponseInterface | [
"Create",
"a",
"response",
"from",
"a",
"cache",
"item",
"."
]
| 330e089fee2f4ee34db1ec5129c12469f8b81f66 | https://github.com/GrahamCampbell/Cache-Plugin/blob/330e089fee2f4ee34db1ec5129c12469f8b81f66/src/CachePlugin.php#L206-L222 | train |
GrahamCampbell/Cache-Plugin | src/CachePlugin.php | CachePlugin.getETag | protected function getETag(CacheItemInterface $cacheItem)
{
$data = $cacheItem->get();
foreach ($data['etag'] as $etag) {
if (!empty($etag)) {
return $etag;
}
}
} | php | protected function getETag(CacheItemInterface $cacheItem)
{
$data = $cacheItem->get();
foreach ($data['etag'] as $etag) {
if (!empty($etag)) {
return $etag;
}
}
} | [
"protected",
"function",
"getETag",
"(",
"CacheItemInterface",
"$",
"cacheItem",
")",
"{",
"$",
"data",
"=",
"$",
"cacheItem",
"->",
"get",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"[",
"'etag'",
"]",
"as",
"$",
"etag",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"etag",
")",
")",
"{",
"return",
"$",
"etag",
";",
"}",
"}",
"}"
]
| Get the ETag from the cached response.
@param \Psr\Cache\CacheItemInterface $cacheItem
@return string|null | [
"Get",
"the",
"ETag",
"from",
"the",
"cached",
"response",
"."
]
| 330e089fee2f4ee34db1ec5129c12469f8b81f66 | https://github.com/GrahamCampbell/Cache-Plugin/blob/330e089fee2f4ee34db1ec5129c12469f8b81f66/src/CachePlugin.php#L231-L240 | train |
intraxia/jaxion | src/Axolotl/Model.php | Model.merge | public function merge( array $attributes ) {
foreach ( $attributes as $name => $value ) {
$this->set_attribute( $name, $value );
}
return $this;
} | php | public function merge( array $attributes ) {
foreach ( $attributes as $name => $value ) {
$this->set_attribute( $name, $value );
}
return $this;
} | [
"public",
"function",
"merge",
"(",
"array",
"$",
"attributes",
")",
"{",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"set_attribute",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Merges the provided attributes with the provided array.
@param array $attributes
@return $this | [
"Merges",
"the",
"provided",
"attributes",
"with",
"the",
"provided",
"array",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Axolotl/Model.php#L154-L160 | train |
intraxia/jaxion | src/Axolotl/Model.php | Model.get_changed_table_attributes | public function get_changed_table_attributes() {
$changed = array();
foreach ( $this->get_table_attributes() as $key => $value ) {
if ( $value !==
$this->get_original_attribute( $key )
) {
$changed[ $key ] = $value;
}
}
return $changed;
} | php | public function get_changed_table_attributes() {
$changed = array();
foreach ( $this->get_table_attributes() as $key => $value ) {
if ( $value !==
$this->get_original_attribute( $key )
) {
$changed[ $key ] = $value;
}
}
return $changed;
} | [
"public",
"function",
"get_changed_table_attributes",
"(",
")",
"{",
"$",
"changed",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"get_table_attributes",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"!==",
"$",
"this",
"->",
"get_original_attribute",
"(",
"$",
"key",
")",
")",
"{",
"$",
"changed",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"changed",
";",
"}"
]
| Retrieve an array of the attributes on the model
that have changed compared to the model's
original data.
@return array | [
"Retrieve",
"an",
"array",
"of",
"the",
"attributes",
"on",
"the",
"model",
"that",
"have",
"changed",
"compared",
"to",
"the",
"model",
"s",
"original",
"data",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Axolotl/Model.php#L190-L202 | train |
intraxia/jaxion | src/Axolotl/Model.php | Model.get_underlying_wp_object | public function get_underlying_wp_object() {
if ( isset( $this->attributes[ self::OBJECT_KEY ] ) ) {
return $this->attributes[ self::OBJECT_KEY ];
}
return false;
} | php | public function get_underlying_wp_object() {
if ( isset( $this->attributes[ self::OBJECT_KEY ] ) ) {
return $this->attributes[ self::OBJECT_KEY ];
}
return false;
} | [
"public",
"function",
"get_underlying_wp_object",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"attributes",
"[",
"self",
"::",
"OBJECT_KEY",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"attributes",
"[",
"self",
"::",
"OBJECT_KEY",
"]",
";",
"}",
"return",
"false",
";",
"}"
]
| Get the model's underlying post.
Returns the underlying WP_Post object for the model, representing
the data that will be save in the wp_posts table.
@return false|WP_Post|WP_Term | [
"Get",
"the",
"model",
"s",
"underlying",
"post",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Axolotl/Model.php#L212-L218 | train |
intraxia/jaxion | src/Axolotl/Model.php | Model.get_changed_wp_object_attributes | public function get_changed_wp_object_attributes() {
$changed = array();
foreach ( $this->get_wp_object_keys() as $key ) {
if ( $this->get_attribute( $key ) !==
$this->get_original_attribute( $key )
) {
$changed[ $key ] = $this->get_attribute( $key );
}
}
return $changed;
} | php | public function get_changed_wp_object_attributes() {
$changed = array();
foreach ( $this->get_wp_object_keys() as $key ) {
if ( $this->get_attribute( $key ) !==
$this->get_original_attribute( $key )
) {
$changed[ $key ] = $this->get_attribute( $key );
}
}
return $changed;
} | [
"public",
"function",
"get_changed_wp_object_attributes",
"(",
")",
"{",
"$",
"changed",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"get_wp_object_keys",
"(",
")",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"get_attribute",
"(",
"$",
"key",
")",
"!==",
"$",
"this",
"->",
"get_original_attribute",
"(",
"$",
"key",
")",
")",
"{",
"$",
"changed",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"get_attribute",
"(",
"$",
"key",
")",
";",
"}",
"}",
"return",
"$",
"changed",
";",
"}"
]
| Get the model attributes on the WordPress object
that have changed compared to the model's
original attributes.
@return array | [
"Get",
"the",
"model",
"attributes",
"on",
"the",
"WordPress",
"object",
"that",
"have",
"changed",
"compared",
"to",
"the",
"model",
"s",
"original",
"attributes",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Axolotl/Model.php#L236-L248 | train |
intraxia/jaxion | src/Axolotl/Model.php | Model.set_attribute | public function set_attribute( $name, $value ) {
if ( self::OBJECT_KEY === $name ) {
return $this->override_wp_object( $value );
}
if ( self::TABLE_KEY === $name ) {
return $this->override_table( $value );
}
if ( ! $this->is_fillable( $name ) ) {
throw new GuardedPropertyException;
}
if ( $method = $this->has_map_method( $name ) ) {
$this->attributes[ self::OBJECT_KEY ]->{$this->{$method}()} = $value;
} else {
$this->attributes[ self::TABLE_KEY ][ $name ] = $value;
}
return $this;
} | php | public function set_attribute( $name, $value ) {
if ( self::OBJECT_KEY === $name ) {
return $this->override_wp_object( $value );
}
if ( self::TABLE_KEY === $name ) {
return $this->override_table( $value );
}
if ( ! $this->is_fillable( $name ) ) {
throw new GuardedPropertyException;
}
if ( $method = $this->has_map_method( $name ) ) {
$this->attributes[ self::OBJECT_KEY ]->{$this->{$method}()} = $value;
} else {
$this->attributes[ self::TABLE_KEY ][ $name ] = $value;
}
return $this;
} | [
"public",
"function",
"set_attribute",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"if",
"(",
"self",
"::",
"OBJECT_KEY",
"===",
"$",
"name",
")",
"{",
"return",
"$",
"this",
"->",
"override_wp_object",
"(",
"$",
"value",
")",
";",
"}",
"if",
"(",
"self",
"::",
"TABLE_KEY",
"===",
"$",
"name",
")",
"{",
"return",
"$",
"this",
"->",
"override_table",
"(",
"$",
"value",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"is_fillable",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"GuardedPropertyException",
";",
"}",
"if",
"(",
"$",
"method",
"=",
"$",
"this",
"->",
"has_map_method",
"(",
"$",
"name",
")",
")",
"{",
"$",
"this",
"->",
"attributes",
"[",
"self",
"::",
"OBJECT_KEY",
"]",
"->",
"{",
"$",
"this",
"->",
"{",
"$",
"method",
"}",
"(",
")",
"}",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"attributes",
"[",
"self",
"::",
"TABLE_KEY",
"]",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Sets the model attributes.
Checks whether the model attribute can be set, check if it
maps to the WP_Post property, otherwise, assigns it to the
table attribute array.
@param string $name
@param mixed $value
@return $this
@throws GuardedPropertyException | [
"Sets",
"the",
"model",
"attributes",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Axolotl/Model.php#L276-L296 | train |
intraxia/jaxion | src/Axolotl/Model.php | Model.get_attribute_keys | public function get_attribute_keys() {
if ( isset( self::$memo[ get_called_class() ][ __METHOD__ ] ) ) {
return self::$memo[ get_called_class() ][ __METHOD__ ];
}
return self::$memo[ get_called_class() ][ __METHOD__ ]
= array_merge(
$this->fillable,
$this->guarded,
$this->get_compute_methods()
);
} | php | public function get_attribute_keys() {
if ( isset( self::$memo[ get_called_class() ][ __METHOD__ ] ) ) {
return self::$memo[ get_called_class() ][ __METHOD__ ];
}
return self::$memo[ get_called_class() ][ __METHOD__ ]
= array_merge(
$this->fillable,
$this->guarded,
$this->get_compute_methods()
);
} | [
"public",
"function",
"get_attribute_keys",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"memo",
"[",
"get_called_class",
"(",
")",
"]",
"[",
"__METHOD__",
"]",
")",
")",
"{",
"return",
"self",
"::",
"$",
"memo",
"[",
"get_called_class",
"(",
")",
"]",
"[",
"__METHOD__",
"]",
";",
"}",
"return",
"self",
"::",
"$",
"memo",
"[",
"get_called_class",
"(",
")",
"]",
"[",
"__METHOD__",
"]",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"fillable",
",",
"$",
"this",
"->",
"guarded",
",",
"$",
"this",
"->",
"get_compute_methods",
"(",
")",
")",
";",
"}"
]
| Retrieves all the attribute keys for the model.
@return array | [
"Retrieves",
"all",
"the",
"attribute",
"keys",
"for",
"the",
"model",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Axolotl/Model.php#L303-L314 | train |
intraxia/jaxion | src/Axolotl/Model.php | Model.get_table_keys | public function get_table_keys() {
if ( isset( self::$memo[ get_called_class() ][ __METHOD__ ] ) ) {
return self::$memo[ get_called_class() ][ __METHOD__ ];
}
$keys = array();
foreach ( $this->get_attribute_keys() as $key ) {
if ( ! $this->has_map_method( $key ) &&
! $this->has_compute_method( $key )
) {
$keys[] = $key;
}
}
return self::$memo[ get_called_class() ][ __METHOD__ ] = $keys;
} | php | public function get_table_keys() {
if ( isset( self::$memo[ get_called_class() ][ __METHOD__ ] ) ) {
return self::$memo[ get_called_class() ][ __METHOD__ ];
}
$keys = array();
foreach ( $this->get_attribute_keys() as $key ) {
if ( ! $this->has_map_method( $key ) &&
! $this->has_compute_method( $key )
) {
$keys[] = $key;
}
}
return self::$memo[ get_called_class() ][ __METHOD__ ] = $keys;
} | [
"public",
"function",
"get_table_keys",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"memo",
"[",
"get_called_class",
"(",
")",
"]",
"[",
"__METHOD__",
"]",
")",
")",
"{",
"return",
"self",
"::",
"$",
"memo",
"[",
"get_called_class",
"(",
")",
"]",
"[",
"__METHOD__",
"]",
";",
"}",
"$",
"keys",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"get_attribute_keys",
"(",
")",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"has_map_method",
"(",
"$",
"key",
")",
"&&",
"!",
"$",
"this",
"->",
"has_compute_method",
"(",
"$",
"key",
")",
")",
"{",
"$",
"keys",
"[",
"]",
"=",
"$",
"key",
";",
"}",
"}",
"return",
"self",
"::",
"$",
"memo",
"[",
"get_called_class",
"(",
")",
"]",
"[",
"__METHOD__",
"]",
"=",
"$",
"keys",
";",
"}"
]
| Retrieves the attribute keys that aren't mapped to a post.
@return array | [
"Retrieves",
"the",
"attribute",
"keys",
"that",
"aren",
"t",
"mapped",
"to",
"a",
"post",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Axolotl/Model.php#L321-L337 | train |
intraxia/jaxion | src/Axolotl/Model.php | Model.get_wp_object_keys | public function get_wp_object_keys() {
if ( isset( self::$memo[ get_called_class() ][ __METHOD__ ] ) ) {
return self::$memo[ get_called_class() ][ __METHOD__ ];
}
$keys = array();
foreach ( $this->get_attribute_keys() as $key ) {
if ( $this->has_map_method( $key ) ) {
$keys[] = $key;
}
}
return self::$memo[ get_called_class() ][ __METHOD__ ] = $keys;
} | php | public function get_wp_object_keys() {
if ( isset( self::$memo[ get_called_class() ][ __METHOD__ ] ) ) {
return self::$memo[ get_called_class() ][ __METHOD__ ];
}
$keys = array();
foreach ( $this->get_attribute_keys() as $key ) {
if ( $this->has_map_method( $key ) ) {
$keys[] = $key;
}
}
return self::$memo[ get_called_class() ][ __METHOD__ ] = $keys;
} | [
"public",
"function",
"get_wp_object_keys",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"memo",
"[",
"get_called_class",
"(",
")",
"]",
"[",
"__METHOD__",
"]",
")",
")",
"{",
"return",
"self",
"::",
"$",
"memo",
"[",
"get_called_class",
"(",
")",
"]",
"[",
"__METHOD__",
"]",
";",
"}",
"$",
"keys",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"get_attribute_keys",
"(",
")",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"has_map_method",
"(",
"$",
"key",
")",
")",
"{",
"$",
"keys",
"[",
"]",
"=",
"$",
"key",
";",
"}",
"}",
"return",
"self",
"::",
"$",
"memo",
"[",
"get_called_class",
"(",
")",
"]",
"[",
"__METHOD__",
"]",
"=",
"$",
"keys",
";",
"}"
]
| Retrieves the attribute keys that are mapped to a post.
@return array | [
"Retrieves",
"the",
"attribute",
"keys",
"that",
"are",
"mapped",
"to",
"a",
"post",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Axolotl/Model.php#L344-L358 | train |
intraxia/jaxion | src/Axolotl/Model.php | Model.get_computed_keys | public function get_computed_keys() {
if ( isset( self::$memo[ get_called_class() ][ __METHOD__ ] ) ) {
return self::$memo[ get_called_class() ][ __METHOD__ ];
}
$keys = array();
foreach ( $this->get_attribute_keys() as $key ) {
if ( $this->has_compute_method( $key ) ) {
$keys[] = $key;
}
}
return self::$memo[ get_called_class() ][ __METHOD__ ] = $keys;
} | php | public function get_computed_keys() {
if ( isset( self::$memo[ get_called_class() ][ __METHOD__ ] ) ) {
return self::$memo[ get_called_class() ][ __METHOD__ ];
}
$keys = array();
foreach ( $this->get_attribute_keys() as $key ) {
if ( $this->has_compute_method( $key ) ) {
$keys[] = $key;
}
}
return self::$memo[ get_called_class() ][ __METHOD__ ] = $keys;
} | [
"public",
"function",
"get_computed_keys",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"memo",
"[",
"get_called_class",
"(",
")",
"]",
"[",
"__METHOD__",
"]",
")",
")",
"{",
"return",
"self",
"::",
"$",
"memo",
"[",
"get_called_class",
"(",
")",
"]",
"[",
"__METHOD__",
"]",
";",
"}",
"$",
"keys",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"get_attribute_keys",
"(",
")",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"has_compute_method",
"(",
"$",
"key",
")",
")",
"{",
"$",
"keys",
"[",
"]",
"=",
"$",
"key",
";",
"}",
"}",
"return",
"self",
"::",
"$",
"memo",
"[",
"get_called_class",
"(",
")",
"]",
"[",
"__METHOD__",
"]",
"=",
"$",
"keys",
";",
"}"
]
| Returns the model's keys that are computed at call time.
@return array | [
"Returns",
"the",
"model",
"s",
"keys",
"that",
"are",
"computed",
"at",
"call",
"time",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Axolotl/Model.php#L365-L379 | train |
intraxia/jaxion | src/Axolotl/Model.php | Model.serialize | public function serialize() {
$attributes = array();
if ( $this->visible ) {
// If visible attributes are set, we'll only reveal those.
foreach ( $this->visible as $key ) {
$attributes[ $key ] = $this->get_attribute( $key );
}
} elseif ( $this->hidden ) {
// If hidden attributes are set, we'll grab everything and hide those.
foreach ( $this->get_attribute_keys() as $key ) {
if ( ! in_array( $key, $this->hidden ) ) {
$attributes[ $key ] = $this->get_attribute( $key );
}
}
} else {
// If nothing is hidden/visible, we'll grab and reveal everything.
foreach ( $this->get_attribute_keys() as $key ) {
$attributes[ $key ] = $this->get_attribute( $key );
}
}
return array_map( function ( $attribute ) {
if ( $attribute instanceof Serializes ) {
return $attribute->serialize();
}
return $attribute;
}, $attributes );
} | php | public function serialize() {
$attributes = array();
if ( $this->visible ) {
// If visible attributes are set, we'll only reveal those.
foreach ( $this->visible as $key ) {
$attributes[ $key ] = $this->get_attribute( $key );
}
} elseif ( $this->hidden ) {
// If hidden attributes are set, we'll grab everything and hide those.
foreach ( $this->get_attribute_keys() as $key ) {
if ( ! in_array( $key, $this->hidden ) ) {
$attributes[ $key ] = $this->get_attribute( $key );
}
}
} else {
// If nothing is hidden/visible, we'll grab and reveal everything.
foreach ( $this->get_attribute_keys() as $key ) {
$attributes[ $key ] = $this->get_attribute( $key );
}
}
return array_map( function ( $attribute ) {
if ( $attribute instanceof Serializes ) {
return $attribute->serialize();
}
return $attribute;
}, $attributes );
} | [
"public",
"function",
"serialize",
"(",
")",
"{",
"$",
"attributes",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"visible",
")",
"{",
"// If visible attributes are set, we'll only reveal those.",
"foreach",
"(",
"$",
"this",
"->",
"visible",
"as",
"$",
"key",
")",
"{",
"$",
"attributes",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"get_attribute",
"(",
"$",
"key",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"this",
"->",
"hidden",
")",
"{",
"// If hidden attributes are set, we'll grab everything and hide those.",
"foreach",
"(",
"$",
"this",
"->",
"get_attribute_keys",
"(",
")",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"hidden",
")",
")",
"{",
"$",
"attributes",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"get_attribute",
"(",
"$",
"key",
")",
";",
"}",
"}",
"}",
"else",
"{",
"// If nothing is hidden/visible, we'll grab and reveal everything.",
"foreach",
"(",
"$",
"this",
"->",
"get_attribute_keys",
"(",
")",
"as",
"$",
"key",
")",
"{",
"$",
"attributes",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"get_attribute",
"(",
"$",
"key",
")",
";",
"}",
"}",
"return",
"array_map",
"(",
"function",
"(",
"$",
"attribute",
")",
"{",
"if",
"(",
"$",
"attribute",
"instanceof",
"Serializes",
")",
"{",
"return",
"$",
"attribute",
"->",
"serialize",
"(",
")",
";",
"}",
"return",
"$",
"attribute",
";",
"}",
",",
"$",
"attributes",
")",
";",
"}"
]
| Serializes the model's public data into an array.
@return array | [
"Serializes",
"the",
"model",
"s",
"public",
"data",
"into",
"an",
"array",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Axolotl/Model.php#L386-L415 | train |
intraxia/jaxion | src/Axolotl/Model.php | Model.sync_original | public function sync_original() {
$this->original = $this->attributes;
if ( $this->attributes[ self::OBJECT_KEY ] ) {
$this->original[ self::OBJECT_KEY ] = clone $this->attributes[ self::OBJECT_KEY ];
}
foreach ( $this->original[ self::TABLE_KEY ] as $key => $item ) {
if ( is_object( $item ) ) {
$this->original[ $key ] = clone $item;
}
}
return $this;
} | php | public function sync_original() {
$this->original = $this->attributes;
if ( $this->attributes[ self::OBJECT_KEY ] ) {
$this->original[ self::OBJECT_KEY ] = clone $this->attributes[ self::OBJECT_KEY ];
}
foreach ( $this->original[ self::TABLE_KEY ] as $key => $item ) {
if ( is_object( $item ) ) {
$this->original[ $key ] = clone $item;
}
}
return $this;
} | [
"public",
"function",
"sync_original",
"(",
")",
"{",
"$",
"this",
"->",
"original",
"=",
"$",
"this",
"->",
"attributes",
";",
"if",
"(",
"$",
"this",
"->",
"attributes",
"[",
"self",
"::",
"OBJECT_KEY",
"]",
")",
"{",
"$",
"this",
"->",
"original",
"[",
"self",
"::",
"OBJECT_KEY",
"]",
"=",
"clone",
"$",
"this",
"->",
"attributes",
"[",
"self",
"::",
"OBJECT_KEY",
"]",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"original",
"[",
"self",
"::",
"TABLE_KEY",
"]",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"item",
")",
")",
"{",
"$",
"this",
"->",
"original",
"[",
"$",
"key",
"]",
"=",
"clone",
"$",
"item",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Syncs the current attributes to the model's original.
@return $this | [
"Syncs",
"the",
"current",
"attributes",
"to",
"the",
"model",
"s",
"original",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Axolotl/Model.php#L422-L436 | train |
intraxia/jaxion | src/Axolotl/Model.php | Model.is_fillable | private function is_fillable( $name ) {
// If this model isn't guarded, everything is fillable.
if ( ! $this->is_guarded ) {
return true;
}
// If it's in the fillable array, then it's fillable.
if ( in_array( $name, $this->fillable ) ) {
return true;
}
// If it's explicitly guarded, then it's not fillable.
if ( in_array( $name, $this->guarded ) ) {
return false;
}
// If fillable hasn't been defined, then everything else fillable.
return ! $this->fillable;
} | php | private function is_fillable( $name ) {
// If this model isn't guarded, everything is fillable.
if ( ! $this->is_guarded ) {
return true;
}
// If it's in the fillable array, then it's fillable.
if ( in_array( $name, $this->fillable ) ) {
return true;
}
// If it's explicitly guarded, then it's not fillable.
if ( in_array( $name, $this->guarded ) ) {
return false;
}
// If fillable hasn't been defined, then everything else fillable.
return ! $this->fillable;
} | [
"private",
"function",
"is_fillable",
"(",
"$",
"name",
")",
"{",
"// If this model isn't guarded, everything is fillable.",
"if",
"(",
"!",
"$",
"this",
"->",
"is_guarded",
")",
"{",
"return",
"true",
";",
"}",
"// If it's in the fillable array, then it's fillable.",
"if",
"(",
"in_array",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"fillable",
")",
")",
"{",
"return",
"true",
";",
"}",
"// If it's explicitly guarded, then it's not fillable.",
"if",
"(",
"in_array",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"guarded",
")",
")",
"{",
"return",
"false",
";",
"}",
"// If fillable hasn't been defined, then everything else fillable.",
"return",
"!",
"$",
"this",
"->",
"fillable",
";",
"}"
]
| Checks if a given attribute is mass-fillable.
Returns true if the attribute can be filled, false if it can't.
@param string $name
@return bool | [
"Checks",
"if",
"a",
"given",
"attribute",
"is",
"mass",
"-",
"fillable",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Axolotl/Model.php#L447-L465 | train |
intraxia/jaxion | src/Axolotl/Model.php | Model.override_wp_object | private function override_wp_object( $value ) {
if ( is_object( $value ) ) {
$this->attributes[ self::OBJECT_KEY ] = $this->set_wp_object_constants( $value );
} else {
$this->attributes[ self::OBJECT_KEY ] = null;
if ( $this->uses_wp_object() ) {
$this->create_wp_object();
}
}
return $this;
} | php | private function override_wp_object( $value ) {
if ( is_object( $value ) ) {
$this->attributes[ self::OBJECT_KEY ] = $this->set_wp_object_constants( $value );
} else {
$this->attributes[ self::OBJECT_KEY ] = null;
if ( $this->uses_wp_object() ) {
$this->create_wp_object();
}
}
return $this;
} | [
"private",
"function",
"override_wp_object",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"$",
"this",
"->",
"attributes",
"[",
"self",
"::",
"OBJECT_KEY",
"]",
"=",
"$",
"this",
"->",
"set_wp_object_constants",
"(",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"attributes",
"[",
"self",
"::",
"OBJECT_KEY",
"]",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"uses_wp_object",
"(",
")",
")",
"{",
"$",
"this",
"->",
"create_wp_object",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Overrides the current WordPress object with a provided one.
Resets the post's default values and stores it in the attributes.
@param WP_Post|WP_Term|null $value
@return $this | [
"Overrides",
"the",
"current",
"WordPress",
"object",
"with",
"a",
"provided",
"one",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Axolotl/Model.php#L476-L488 | train |
intraxia/jaxion | src/Axolotl/Model.php | Model.create_wp_object | private function create_wp_object() {
switch ( true ) {
case $this instanceof UsesWordPressPost:
$object = new WP_Post( (object) array() );
break;
case $this instanceof UsesWordPressTerm:
$object = new WP_Term( (object) array() );
break;
default:
throw new LogicException;
break;
}
$this->attributes[ self::OBJECT_KEY ] = $this->set_wp_object_constants( $object );
} | php | private function create_wp_object() {
switch ( true ) {
case $this instanceof UsesWordPressPost:
$object = new WP_Post( (object) array() );
break;
case $this instanceof UsesWordPressTerm:
$object = new WP_Term( (object) array() );
break;
default:
throw new LogicException;
break;
}
$this->attributes[ self::OBJECT_KEY ] = $this->set_wp_object_constants( $object );
} | [
"private",
"function",
"create_wp_object",
"(",
")",
"{",
"switch",
"(",
"true",
")",
"{",
"case",
"$",
"this",
"instanceof",
"UsesWordPressPost",
":",
"$",
"object",
"=",
"new",
"WP_Post",
"(",
"(",
"object",
")",
"array",
"(",
")",
")",
";",
"break",
";",
"case",
"$",
"this",
"instanceof",
"UsesWordPressTerm",
":",
"$",
"object",
"=",
"new",
"WP_Term",
"(",
"(",
"object",
")",
"array",
"(",
")",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"LogicException",
";",
"break",
";",
"}",
"$",
"this",
"->",
"attributes",
"[",
"self",
"::",
"OBJECT_KEY",
"]",
"=",
"$",
"this",
"->",
"set_wp_object_constants",
"(",
"$",
"object",
")",
";",
"}"
]
| Create and set with a new blank post.
Creates a new WP_Post object, assigns it the default attributes,
and stores it in the attributes.
@throws LogicException | [
"Create",
"and",
"set",
"with",
"a",
"new",
"blank",
"post",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Axolotl/Model.php#L511-L525 | train |
intraxia/jaxion | src/Axolotl/Model.php | Model.set_wp_object_constants | protected function set_wp_object_constants( $object ) {
if ( $this instanceof UsesWordPressPost ) {
$object->post_type = static::get_post_type();
}
if ( $this instanceof UsesWordPressTerm ) {
$object->taxonomy = static::get_taxonomy();
}
return $object;
} | php | protected function set_wp_object_constants( $object ) {
if ( $this instanceof UsesWordPressPost ) {
$object->post_type = static::get_post_type();
}
if ( $this instanceof UsesWordPressTerm ) {
$object->taxonomy = static::get_taxonomy();
}
return $object;
} | [
"protected",
"function",
"set_wp_object_constants",
"(",
"$",
"object",
")",
"{",
"if",
"(",
"$",
"this",
"instanceof",
"UsesWordPressPost",
")",
"{",
"$",
"object",
"->",
"post_type",
"=",
"static",
"::",
"get_post_type",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"instanceof",
"UsesWordPressTerm",
")",
"{",
"$",
"object",
"->",
"taxonomy",
"=",
"static",
"::",
"get_taxonomy",
"(",
")",
";",
"}",
"return",
"$",
"object",
";",
"}"
]
| Enforces values on the post that can't change.
Primarily, this is used to make sure the post_type always maps
to the model's "$type" property, but this can all be overridden
by the developer to enforce other values in the model.
@param object $object
@return object | [
"Enforces",
"values",
"on",
"the",
"post",
"that",
"can",
"t",
"change",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Axolotl/Model.php#L538-L548 | train |
intraxia/jaxion | src/Axolotl/Model.php | Model.get_attribute | public function get_attribute( $name ) {
if ( $method = $this->has_map_method( $name ) ) {
return $this->attributes[ self::OBJECT_KEY ]->{$this->{$method}()};
}
if ( $method = $this->has_compute_method( $name ) ) {
return $this->{$method}();
}
if ( isset( $this->attributes[ self::TABLE_KEY ][ $name ] ) ) {
return $this->attributes[ self::TABLE_KEY ][ $name ];
}
if ( isset( $this->defaults[ $name ] ) ) {
return $this->defaults[ $name ];
}
return null;
} | php | public function get_attribute( $name ) {
if ( $method = $this->has_map_method( $name ) ) {
return $this->attributes[ self::OBJECT_KEY ]->{$this->{$method}()};
}
if ( $method = $this->has_compute_method( $name ) ) {
return $this->{$method}();
}
if ( isset( $this->attributes[ self::TABLE_KEY ][ $name ] ) ) {
return $this->attributes[ self::TABLE_KEY ][ $name ];
}
if ( isset( $this->defaults[ $name ] ) ) {
return $this->defaults[ $name ];
}
return null;
} | [
"public",
"function",
"get_attribute",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"method",
"=",
"$",
"this",
"->",
"has_map_method",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"this",
"->",
"attributes",
"[",
"self",
"::",
"OBJECT_KEY",
"]",
"->",
"{",
"$",
"this",
"->",
"{",
"$",
"method",
"}",
"(",
")",
"}",
";",
"}",
"if",
"(",
"$",
"method",
"=",
"$",
"this",
"->",
"has_compute_method",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"this",
"->",
"{",
"$",
"method",
"}",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"attributes",
"[",
"self",
"::",
"TABLE_KEY",
"]",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"attributes",
"[",
"self",
"::",
"TABLE_KEY",
"]",
"[",
"$",
"name",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"defaults",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"defaults",
"[",
"$",
"name",
"]",
";",
"}",
"return",
"null",
";",
"}"
]
| Retrieves the model attribute.
@param string $name
@return mixed
@throws PropertyDoesNotExistException If property isn't found. | [
"Retrieves",
"the",
"model",
"attribute",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Axolotl/Model.php#L572-L590 | train |
intraxia/jaxion | src/Axolotl/Model.php | Model.get_original_attribute | public function get_original_attribute( $name ) {
$original_attributes = $this->original;
if ( ! is_object( $original_attributes[ static::OBJECT_KEY ] ) ) {
unset( $original_attributes[ static::OBJECT_KEY ] );
}
$original = new static( $original_attributes );
return $original->get_attribute( $name );
} | php | public function get_original_attribute( $name ) {
$original_attributes = $this->original;
if ( ! is_object( $original_attributes[ static::OBJECT_KEY ] ) ) {
unset( $original_attributes[ static::OBJECT_KEY ] );
}
$original = new static( $original_attributes );
return $original->get_attribute( $name );
} | [
"public",
"function",
"get_original_attribute",
"(",
"$",
"name",
")",
"{",
"$",
"original_attributes",
"=",
"$",
"this",
"->",
"original",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"original_attributes",
"[",
"static",
"::",
"OBJECT_KEY",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"original_attributes",
"[",
"static",
"::",
"OBJECT_KEY",
"]",
")",
";",
"}",
"$",
"original",
"=",
"new",
"static",
"(",
"$",
"original_attributes",
")",
";",
"return",
"$",
"original",
"->",
"get_attribute",
"(",
"$",
"name",
")",
";",
"}"
]
| Retrieve the model's original attribute value.
@param string $name
@return mixed
@throws PropertyDoesNotExistException If property isn't found. | [
"Retrieve",
"the",
"model",
"s",
"original",
"attribute",
"value",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Axolotl/Model.php#L601-L611 | train |
intraxia/jaxion | src/Axolotl/Model.php | Model.get_primary_id | public function get_primary_id() {
if ( $this instanceof UsesWordPressPost ) {
return $this->get_underlying_wp_object()->ID;
}
if ( $this instanceof UsesWordPressTerm ) {
return $this->get_underlying_wp_object()->term_id;
}
if ( $this instanceof UsesCustomTable ) {
return $this->get_attribute( $this->get_primary_key() );
}
// Model w/o wp_object not yet supported.
throw new LogicException;
} | php | public function get_primary_id() {
if ( $this instanceof UsesWordPressPost ) {
return $this->get_underlying_wp_object()->ID;
}
if ( $this instanceof UsesWordPressTerm ) {
return $this->get_underlying_wp_object()->term_id;
}
if ( $this instanceof UsesCustomTable ) {
return $this->get_attribute( $this->get_primary_key() );
}
// Model w/o wp_object not yet supported.
throw new LogicException;
} | [
"public",
"function",
"get_primary_id",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"instanceof",
"UsesWordPressPost",
")",
"{",
"return",
"$",
"this",
"->",
"get_underlying_wp_object",
"(",
")",
"->",
"ID",
";",
"}",
"if",
"(",
"$",
"this",
"instanceof",
"UsesWordPressTerm",
")",
"{",
"return",
"$",
"this",
"->",
"get_underlying_wp_object",
"(",
")",
"->",
"term_id",
";",
"}",
"if",
"(",
"$",
"this",
"instanceof",
"UsesCustomTable",
")",
"{",
"return",
"$",
"this",
"->",
"get_attribute",
"(",
"$",
"this",
"->",
"get_primary_key",
"(",
")",
")",
";",
"}",
"// Model w/o wp_object not yet supported.",
"throw",
"new",
"LogicException",
";",
"}"
]
| Fetches the Model's primary ID, depending on the model
implementation.
@return int
@throws LogicException | [
"Fetches",
"the",
"Model",
"s",
"primary",
"ID",
"depending",
"on",
"the",
"model",
"implementation",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Axolotl/Model.php#L621-L636 | train |
intraxia/jaxion | src/Axolotl/Model.php | Model.clear | public function clear() {
$keys = array_merge(
$this->get_table_keys(),
$this->get_wp_object_keys()
);
foreach ( $keys as $key ) {
try {
$this->set_attribute( $key, null );
} catch ( Exception $e ) {
// We won't clear out guarded attributes.
if ( ! ( $e instanceof GuardedPropertyException ) ) {
throw $e;
}
}
}
return $this;
} | php | public function clear() {
$keys = array_merge(
$this->get_table_keys(),
$this->get_wp_object_keys()
);
foreach ( $keys as $key ) {
try {
$this->set_attribute( $key, null );
} catch ( Exception $e ) {
// We won't clear out guarded attributes.
if ( ! ( $e instanceof GuardedPropertyException ) ) {
throw $e;
}
}
}
return $this;
} | [
"public",
"function",
"clear",
"(",
")",
"{",
"$",
"keys",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"get_table_keys",
"(",
")",
",",
"$",
"this",
"->",
"get_wp_object_keys",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"set_attribute",
"(",
"$",
"key",
",",
"null",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"// We won't clear out guarded attributes.",
"if",
"(",
"!",
"(",
"$",
"e",
"instanceof",
"GuardedPropertyException",
")",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Clears all the current attributes from the model.
This does not touch the model's original attributes, and will
only clear fillable attributes, unless the model is unguarded.
@throws Exception
@return $this | [
"Clears",
"all",
"the",
"current",
"attributes",
"from",
"the",
"model",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Axolotl/Model.php#L684-L702 | train |
intraxia/jaxion | src/Axolotl/Model.php | Model.get_compute_methods | protected function get_compute_methods() {
$methods = get_class_methods( get_called_class() );
$methods = array_filter( $methods, function ( $method ) {
return strrpos( $method, 'compute_', - strlen( $method ) ) !== false;
} );
$methods = array_map( function ( $method ) {
return substr( $method, strlen( 'compute_' ) );
}, $methods );
return $methods;
} | php | protected function get_compute_methods() {
$methods = get_class_methods( get_called_class() );
$methods = array_filter( $methods, function ( $method ) {
return strrpos( $method, 'compute_', - strlen( $method ) ) !== false;
} );
$methods = array_map( function ( $method ) {
return substr( $method, strlen( 'compute_' ) );
}, $methods );
return $methods;
} | [
"protected",
"function",
"get_compute_methods",
"(",
")",
"{",
"$",
"methods",
"=",
"get_class_methods",
"(",
"get_called_class",
"(",
")",
")",
";",
"$",
"methods",
"=",
"array_filter",
"(",
"$",
"methods",
",",
"function",
"(",
"$",
"method",
")",
"{",
"return",
"strrpos",
"(",
"$",
"method",
",",
"'compute_'",
",",
"-",
"strlen",
"(",
"$",
"method",
")",
")",
"!==",
"false",
";",
"}",
")",
";",
"$",
"methods",
"=",
"array_map",
"(",
"function",
"(",
"$",
"method",
")",
"{",
"return",
"substr",
"(",
"$",
"method",
",",
"strlen",
"(",
"'compute_'",
")",
")",
";",
"}",
",",
"$",
"methods",
")",
";",
"return",
"$",
"methods",
";",
"}"
]
| Retrieves all the compute methods on the model.
@return array | [
"Retrieves",
"all",
"the",
"compute",
"methods",
"on",
"the",
"model",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Axolotl/Model.php#L729-L739 | train |
intraxia/jaxion | src/Assets/Register.php | Register.enqueue_script | protected function enqueue_script( $script, $hook = null ) {
if ( $script['condition']( $hook ) ) {
wp_enqueue_script(
$script['handle'],
$this->url . $script['src'] . $this->min . '.js',
isset( $script['deps'] ) ? $script['deps'] : array(),
$this->version,
isset( $script['footer'] ) ? $script['footer'] : false
);
if ( isset( $script['localize'] ) ) {
if ( is_callable( $script['localize'] ) ) { // @todo make all properties callables
$script['localize'] = call_user_func( $script['localize'] );
}
wp_localize_script(
$script['handle'],
$script['localize']['name'],
$script['localize']['data']
);
}
}
} | php | protected function enqueue_script( $script, $hook = null ) {
if ( $script['condition']( $hook ) ) {
wp_enqueue_script(
$script['handle'],
$this->url . $script['src'] . $this->min . '.js',
isset( $script['deps'] ) ? $script['deps'] : array(),
$this->version,
isset( $script['footer'] ) ? $script['footer'] : false
);
if ( isset( $script['localize'] ) ) {
if ( is_callable( $script['localize'] ) ) { // @todo make all properties callables
$script['localize'] = call_user_func( $script['localize'] );
}
wp_localize_script(
$script['handle'],
$script['localize']['name'],
$script['localize']['data']
);
}
}
} | [
"protected",
"function",
"enqueue_script",
"(",
"$",
"script",
",",
"$",
"hook",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"script",
"[",
"'condition'",
"]",
"(",
"$",
"hook",
")",
")",
"{",
"wp_enqueue_script",
"(",
"$",
"script",
"[",
"'handle'",
"]",
",",
"$",
"this",
"->",
"url",
".",
"$",
"script",
"[",
"'src'",
"]",
".",
"$",
"this",
"->",
"min",
".",
"'.js'",
",",
"isset",
"(",
"$",
"script",
"[",
"'deps'",
"]",
")",
"?",
"$",
"script",
"[",
"'deps'",
"]",
":",
"array",
"(",
")",
",",
"$",
"this",
"->",
"version",
",",
"isset",
"(",
"$",
"script",
"[",
"'footer'",
"]",
")",
"?",
"$",
"script",
"[",
"'footer'",
"]",
":",
"false",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"script",
"[",
"'localize'",
"]",
")",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"script",
"[",
"'localize'",
"]",
")",
")",
"{",
"// @todo make all properties callables",
"$",
"script",
"[",
"'localize'",
"]",
"=",
"call_user_func",
"(",
"$",
"script",
"[",
"'localize'",
"]",
")",
";",
"}",
"wp_localize_script",
"(",
"$",
"script",
"[",
"'handle'",
"]",
",",
"$",
"script",
"[",
"'localize'",
"]",
"[",
"'name'",
"]",
",",
"$",
"script",
"[",
"'localize'",
"]",
"[",
"'data'",
"]",
")",
";",
"}",
"}",
"}"
]
| Enqueues an individual script if the style's condition is met.
@param array $script The script attachment callback.
@param string $hook The location hook. Only passed on admin side. | [
"Enqueues",
"an",
"individual",
"script",
"if",
"the",
"style",
"s",
"condition",
"is",
"met",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Assets/Register.php#L178-L200 | train |
intraxia/jaxion | src/Assets/Register.php | Register.enqueue_style | protected function enqueue_style( $style, $hook = null ) {
if ( $style['condition']( $hook ) ) {
wp_enqueue_style(
$style['handle'],
$this->url . $style['src'] . $this->min . '.css',
isset( $style['deps'] ) ? $style['deps'] : array(),
$this->version,
isset( $style['media'] ) ? $style['media'] : 'all'
);
}
} | php | protected function enqueue_style( $style, $hook = null ) {
if ( $style['condition']( $hook ) ) {
wp_enqueue_style(
$style['handle'],
$this->url . $style['src'] . $this->min . '.css',
isset( $style['deps'] ) ? $style['deps'] : array(),
$this->version,
isset( $style['media'] ) ? $style['media'] : 'all'
);
}
} | [
"protected",
"function",
"enqueue_style",
"(",
"$",
"style",
",",
"$",
"hook",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"style",
"[",
"'condition'",
"]",
"(",
"$",
"hook",
")",
")",
"{",
"wp_enqueue_style",
"(",
"$",
"style",
"[",
"'handle'",
"]",
",",
"$",
"this",
"->",
"url",
".",
"$",
"style",
"[",
"'src'",
"]",
".",
"$",
"this",
"->",
"min",
".",
"'.css'",
",",
"isset",
"(",
"$",
"style",
"[",
"'deps'",
"]",
")",
"?",
"$",
"style",
"[",
"'deps'",
"]",
":",
"array",
"(",
")",
",",
"$",
"this",
"->",
"version",
",",
"isset",
"(",
"$",
"style",
"[",
"'media'",
"]",
")",
"?",
"$",
"style",
"[",
"'media'",
"]",
":",
"'all'",
")",
";",
"}",
"}"
]
| Enqueues an individual stylesheet if the style's condition is met.
@param array $style The style attachment callback.
@param string $hook The location hook. | [
"Enqueues",
"an",
"individual",
"stylesheet",
"if",
"the",
"style",
"s",
"condition",
"is",
"met",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Assets/Register.php#L208-L218 | train |
intraxia/jaxion | src/Core/Config.php | Config.get_config_json | public function get_config_json( $filename ) {
if ( isset( $this->loaded[ $filename ] ) ) {
return $this->loaded[ $filename ];
}
$config = $this->path . 'config/' . $filename . '.json';
if ( ! file_exists( $config ) ) {
return null;
}
$contents = file_get_contents( $config );
if ( false === $contents ) {
return null;
}
return $this->loaded[ $filename ] = json_decode( $contents, true );
} | php | public function get_config_json( $filename ) {
if ( isset( $this->loaded[ $filename ] ) ) {
return $this->loaded[ $filename ];
}
$config = $this->path . 'config/' . $filename . '.json';
if ( ! file_exists( $config ) ) {
return null;
}
$contents = file_get_contents( $config );
if ( false === $contents ) {
return null;
}
return $this->loaded[ $filename ] = json_decode( $contents, true );
} | [
"public",
"function",
"get_config_json",
"(",
"$",
"filename",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"loaded",
"[",
"$",
"filename",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"loaded",
"[",
"$",
"filename",
"]",
";",
"}",
"$",
"config",
"=",
"$",
"this",
"->",
"path",
".",
"'config/'",
".",
"$",
"filename",
".",
"'.json'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"config",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"contents",
"=",
"file_get_contents",
"(",
"$",
"config",
")",
";",
"if",
"(",
"false",
"===",
"$",
"contents",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"loaded",
"[",
"$",
"filename",
"]",
"=",
"json_decode",
"(",
"$",
"contents",
",",
"true",
")",
";",
"}"
]
| Load a configuration JSON file from the config folder.
@param string $filename
@return array|null | [
"Load",
"a",
"configuration",
"JSON",
"file",
"from",
"the",
"config",
"folder",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Core/Config.php#L95-L113 | train |
intraxia/jaxion | src/Http/Guard.php | Guard.authorized | public function authorized() {
// if the rule is public, always authorized
if ( 'public' === $this->options['rule'] ) {
return true;
}
// enable passing in callback
if ( 'callback' === $this->options['rule'] && is_callable( $this->options['callback'] ) ) {
return call_user_func( $this->options['callback'] );
}
// map rule to method
if ( method_exists( $this, $method = $this->options['rule'] ) ) {
return $this->{$method}();
}
// disable in rule is misconfigused
// @todo set up internal translations
// @todo also, this error message kinda sucks
return new WP_Error( '500', __( 'Guard failure', 'jaxion' ) );
} | php | public function authorized() {
// if the rule is public, always authorized
if ( 'public' === $this->options['rule'] ) {
return true;
}
// enable passing in callback
if ( 'callback' === $this->options['rule'] && is_callable( $this->options['callback'] ) ) {
return call_user_func( $this->options['callback'] );
}
// map rule to method
if ( method_exists( $this, $method = $this->options['rule'] ) ) {
return $this->{$method}();
}
// disable in rule is misconfigused
// @todo set up internal translations
// @todo also, this error message kinda sucks
return new WP_Error( '500', __( 'Guard failure', 'jaxion' ) );
} | [
"public",
"function",
"authorized",
"(",
")",
"{",
"// if the rule is public, always authorized",
"if",
"(",
"'public'",
"===",
"$",
"this",
"->",
"options",
"[",
"'rule'",
"]",
")",
"{",
"return",
"true",
";",
"}",
"// enable passing in callback",
"if",
"(",
"'callback'",
"===",
"$",
"this",
"->",
"options",
"[",
"'rule'",
"]",
"&&",
"is_callable",
"(",
"$",
"this",
"->",
"options",
"[",
"'callback'",
"]",
")",
")",
"{",
"return",
"call_user_func",
"(",
"$",
"this",
"->",
"options",
"[",
"'callback'",
"]",
")",
";",
"}",
"// map rule to method",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
"=",
"$",
"this",
"->",
"options",
"[",
"'rule'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"{",
"$",
"method",
"}",
"(",
")",
";",
"}",
"// disable in rule is misconfigused",
"// @todo set up internal translations",
"// @todo also, this error message kinda sucks",
"return",
"new",
"WP_Error",
"(",
"'500'",
",",
"__",
"(",
"'Guard failure'",
",",
"'jaxion'",
")",
")",
";",
"}"
]
| Validates whether the current user is authorized.
@return true|WP_Error | [
"Validates",
"whether",
"the",
"current",
"user",
"is",
"authorized",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Http/Guard.php#L49-L69 | train |
intraxia/jaxion | src/Core/Application.php | Application.register_constants | private function register_constants( Config $config ) {
$this->share( 'file', function() use ( $config ) {
return $config->file;
} );
$this->share( 'url', function() use ( $config ) {
return $config->url;
} );
$this->share( 'path', function() use ( $config ) {
return $config->path;
} );
$this->share( 'basename', function() use ( $config ) {
return $config->basename;
} );
$this->share( 'slug', function() use ( $config ) {
return $config->slug;
} );
$this->share( 'version', static::VERSION );
} | php | private function register_constants( Config $config ) {
$this->share( 'file', function() use ( $config ) {
return $config->file;
} );
$this->share( 'url', function() use ( $config ) {
return $config->url;
} );
$this->share( 'path', function() use ( $config ) {
return $config->path;
} );
$this->share( 'basename', function() use ( $config ) {
return $config->basename;
} );
$this->share( 'slug', function() use ( $config ) {
return $config->slug;
} );
$this->share( 'version', static::VERSION );
} | [
"private",
"function",
"register_constants",
"(",
"Config",
"$",
"config",
")",
"{",
"$",
"this",
"->",
"share",
"(",
"'file'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"config",
")",
"{",
"return",
"$",
"config",
"->",
"file",
";",
"}",
")",
";",
"$",
"this",
"->",
"share",
"(",
"'url'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"config",
")",
"{",
"return",
"$",
"config",
"->",
"url",
";",
"}",
")",
";",
"$",
"this",
"->",
"share",
"(",
"'path'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"config",
")",
"{",
"return",
"$",
"config",
"->",
"path",
";",
"}",
")",
";",
"$",
"this",
"->",
"share",
"(",
"'basename'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"config",
")",
"{",
"return",
"$",
"config",
"->",
"basename",
";",
"}",
")",
";",
"$",
"this",
"->",
"share",
"(",
"'slug'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"config",
")",
"{",
"return",
"$",
"config",
"->",
"slug",
";",
"}",
")",
";",
"$",
"this",
"->",
"share",
"(",
"'version'",
",",
"static",
"::",
"VERSION",
")",
";",
"}"
]
| Sets the plugin's url, path, and basename.
@param Config $config | [
"Sets",
"the",
"plugin",
"s",
"url",
"path",
"and",
"basename",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Core/Application.php#L134-L151 | train |
intraxia/jaxion | src/Core/Application.php | Application.register_core_services | private function register_core_services( Config $config ) {
$this->share( array( 'config' => 'Intraxia\Jaxion\Core\Config' ), $config );
$this->share( array( 'loader' => 'Intraxia\Jaxion\Contract\Core\Loader' ), function () {
return new Loader;
} );
$this->share( array( 'i18n' => 'Intaxia\Jaxion\Contract\Core\I18n' ), function ( Container $app ) {
return new I18n( $app->fetch( 'basename' ), $app->fetch( 'path' ) );
} );
} | php | private function register_core_services( Config $config ) {
$this->share( array( 'config' => 'Intraxia\Jaxion\Core\Config' ), $config );
$this->share( array( 'loader' => 'Intraxia\Jaxion\Contract\Core\Loader' ), function () {
return new Loader;
} );
$this->share( array( 'i18n' => 'Intaxia\Jaxion\Contract\Core\I18n' ), function ( Container $app ) {
return new I18n( $app->fetch( 'basename' ), $app->fetch( 'path' ) );
} );
} | [
"private",
"function",
"register_core_services",
"(",
"Config",
"$",
"config",
")",
"{",
"$",
"this",
"->",
"share",
"(",
"array",
"(",
"'config'",
"=>",
"'Intraxia\\Jaxion\\Core\\Config'",
")",
",",
"$",
"config",
")",
";",
"$",
"this",
"->",
"share",
"(",
"array",
"(",
"'loader'",
"=>",
"'Intraxia\\Jaxion\\Contract\\Core\\Loader'",
")",
",",
"function",
"(",
")",
"{",
"return",
"new",
"Loader",
";",
"}",
")",
";",
"$",
"this",
"->",
"share",
"(",
"array",
"(",
"'i18n'",
"=>",
"'Intaxia\\Jaxion\\Contract\\Core\\I18n'",
")",
",",
"function",
"(",
"Container",
"$",
"app",
")",
"{",
"return",
"new",
"I18n",
"(",
"$",
"app",
"->",
"fetch",
"(",
"'basename'",
")",
",",
"$",
"app",
"->",
"fetch",
"(",
"'path'",
")",
")",
";",
"}",
")",
";",
"}"
]
| Registers the built-in services with the Application container.
@param Config $config | [
"Registers",
"the",
"built",
"-",
"in",
"services",
"with",
"the",
"Application",
"container",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Core/Application.php#L158-L166 | train |
intraxia/jaxion | src/Axolotl/Collection.php | Collection.new_from_trusted | protected function new_from_trusted( array $elements, $type = null ) {
$collection = new static( null !== $type ? $type : $this->get_type() );
$collection->set_from_trusted( $elements );
return $collection;
} | php | protected function new_from_trusted( array $elements, $type = null ) {
$collection = new static( null !== $type ? $type : $this->get_type() );
$collection->set_from_trusted( $elements );
return $collection;
} | [
"protected",
"function",
"new_from_trusted",
"(",
"array",
"$",
"elements",
",",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"collection",
"=",
"new",
"static",
"(",
"null",
"!==",
"$",
"type",
"?",
"$",
"type",
":",
"$",
"this",
"->",
"get_type",
"(",
")",
")",
";",
"$",
"collection",
"->",
"set_from_trusted",
"(",
"$",
"elements",
")",
";",
"return",
"$",
"collection",
";",
"}"
]
| Creates a new instance of the Collection
from a trusted set of elements.
@param array $elements Array of elements to pass into new collection.
@param null|mixed $type
@return static | [
"Creates",
"a",
"new",
"instance",
"of",
"the",
"Collection",
"from",
"a",
"trusted",
"set",
"of",
"elements",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Axolotl/Collection.php#L710-L715 | train |
intraxia/jaxion | src/Axolotl/Collection.php | Collection.count_while_true | protected function count_while_true( $condition ) {
$count = 0;
foreach ( $this->elements as $element ) {
if ( ! $condition($element) ) {
break;
}
$count++;
}
return $count;
} | php | protected function count_while_true( $condition ) {
$count = 0;
foreach ( $this->elements as $element ) {
if ( ! $condition($element) ) {
break;
}
$count++;
}
return $count;
} | [
"protected",
"function",
"count_while_true",
"(",
"$",
"condition",
")",
"{",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"elements",
"as",
"$",
"element",
")",
"{",
"if",
"(",
"!",
"$",
"condition",
"(",
"$",
"element",
")",
")",
"{",
"break",
";",
"}",
"$",
"count",
"++",
";",
"}",
"return",
"$",
"count",
";",
"}"
]
| Number of elements true for the condition.
@param callable $condition Condition to check.
@return int | [
"Number",
"of",
"elements",
"true",
"for",
"the",
"condition",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Axolotl/Collection.php#L732-L743 | train |
intraxia/jaxion | src/Http/Filter.php | Filter.rules | public function rules() {
$args = array();
foreach ( $this->rules as $arg => $validation ) {
if ( ! $validation || ! is_string( $validation ) ) {
continue;
}
$args[ $arg ] = $this->parse_validation( $validation );
}
return $args;
} | php | public function rules() {
$args = array();
foreach ( $this->rules as $arg => $validation ) {
if ( ! $validation || ! is_string( $validation ) ) {
continue;
}
$args[ $arg ] = $this->parse_validation( $validation );
}
return $args;
} | [
"public",
"function",
"rules",
"(",
")",
"{",
"$",
"args",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"rules",
"as",
"$",
"arg",
"=>",
"$",
"validation",
")",
"{",
"if",
"(",
"!",
"$",
"validation",
"||",
"!",
"is_string",
"(",
"$",
"validation",
")",
")",
"{",
"continue",
";",
"}",
"$",
"args",
"[",
"$",
"arg",
"]",
"=",
"$",
"this",
"->",
"parse_validation",
"(",
"$",
"validation",
")",
";",
"}",
"return",
"$",
"args",
";",
"}"
]
| Generates argument rules.
Returns an array matching the WP-API format for argument rules,
including sanitization, validation, required, or defaults.
@return array | [
"Generates",
"argument",
"rules",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Http/Filter.php#L39-L51 | train |
intraxia/jaxion | src/Http/Filter.php | Filter.parse_validation | protected function parse_validation( $validation ) {
$validation = explode( '|', $validation );
$rules = array();
foreach ( $validation as $rule ) {
if ( 0 === strpos( $rule, 'default' ) ) {
$rule_arr = explode( ':', $rule );
$rules['default'] = count( $rule_arr ) === 2 ? array_pop( $rule_arr ) : '';
}
if ( 0 === strpos( $rule, 'oneof' ) ) {
list( $rule, $values ) = explode( ':', $rule );
$values = explode( ',', $values );
$callback = function ( $value ) use ( $values ) {
if ( in_array( $value, $values, true ) ) {
return true;
}
return false;
};
$rules['validate_callback'] = isset( $rules['validate_callback'] ) ? $this->add_callback( $rules['validate_callback'], $callback ) : $callback;
}
switch ( $rule ) {
case 'required':
$rules['required'] = true;
break;
case 'integer':
$callback = array( $this, 'validate_integer' );
$rules['validate_callback'] = isset( $rules['validate_callback'] ) ? $this->add_callback( $rules['validate_callback'], $callback ) : $callback;
$callback = array( $this, 'make_integer' );
$rules['sanitize_callback'] = isset( $rules['sanitize_callback'] ) ? $this->add_callback( $rules['sanitize_callback'], $callback ) : $callback;
break;
}
}
return $rules;
} | php | protected function parse_validation( $validation ) {
$validation = explode( '|', $validation );
$rules = array();
foreach ( $validation as $rule ) {
if ( 0 === strpos( $rule, 'default' ) ) {
$rule_arr = explode( ':', $rule );
$rules['default'] = count( $rule_arr ) === 2 ? array_pop( $rule_arr ) : '';
}
if ( 0 === strpos( $rule, 'oneof' ) ) {
list( $rule, $values ) = explode( ':', $rule );
$values = explode( ',', $values );
$callback = function ( $value ) use ( $values ) {
if ( in_array( $value, $values, true ) ) {
return true;
}
return false;
};
$rules['validate_callback'] = isset( $rules['validate_callback'] ) ? $this->add_callback( $rules['validate_callback'], $callback ) : $callback;
}
switch ( $rule ) {
case 'required':
$rules['required'] = true;
break;
case 'integer':
$callback = array( $this, 'validate_integer' );
$rules['validate_callback'] = isset( $rules['validate_callback'] ) ? $this->add_callback( $rules['validate_callback'], $callback ) : $callback;
$callback = array( $this, 'make_integer' );
$rules['sanitize_callback'] = isset( $rules['sanitize_callback'] ) ? $this->add_callback( $rules['sanitize_callback'], $callback ) : $callback;
break;
}
}
return $rules;
} | [
"protected",
"function",
"parse_validation",
"(",
"$",
"validation",
")",
"{",
"$",
"validation",
"=",
"explode",
"(",
"'|'",
",",
"$",
"validation",
")",
";",
"$",
"rules",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"validation",
"as",
"$",
"rule",
")",
"{",
"if",
"(",
"0",
"===",
"strpos",
"(",
"$",
"rule",
",",
"'default'",
")",
")",
"{",
"$",
"rule_arr",
"=",
"explode",
"(",
"':'",
",",
"$",
"rule",
")",
";",
"$",
"rules",
"[",
"'default'",
"]",
"=",
"count",
"(",
"$",
"rule_arr",
")",
"===",
"2",
"?",
"array_pop",
"(",
"$",
"rule_arr",
")",
":",
"''",
";",
"}",
"if",
"(",
"0",
"===",
"strpos",
"(",
"$",
"rule",
",",
"'oneof'",
")",
")",
"{",
"list",
"(",
"$",
"rule",
",",
"$",
"values",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"rule",
")",
";",
"$",
"values",
"=",
"explode",
"(",
"','",
",",
"$",
"values",
")",
";",
"$",
"callback",
"=",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"$",
"values",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"value",
",",
"$",
"values",
",",
"true",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}",
";",
"$",
"rules",
"[",
"'validate_callback'",
"]",
"=",
"isset",
"(",
"$",
"rules",
"[",
"'validate_callback'",
"]",
")",
"?",
"$",
"this",
"->",
"add_callback",
"(",
"$",
"rules",
"[",
"'validate_callback'",
"]",
",",
"$",
"callback",
")",
":",
"$",
"callback",
";",
"}",
"switch",
"(",
"$",
"rule",
")",
"{",
"case",
"'required'",
":",
"$",
"rules",
"[",
"'required'",
"]",
"=",
"true",
";",
"break",
";",
"case",
"'integer'",
":",
"$",
"callback",
"=",
"array",
"(",
"$",
"this",
",",
"'validate_integer'",
")",
";",
"$",
"rules",
"[",
"'validate_callback'",
"]",
"=",
"isset",
"(",
"$",
"rules",
"[",
"'validate_callback'",
"]",
")",
"?",
"$",
"this",
"->",
"add_callback",
"(",
"$",
"rules",
"[",
"'validate_callback'",
"]",
",",
"$",
"callback",
")",
":",
"$",
"callback",
";",
"$",
"callback",
"=",
"array",
"(",
"$",
"this",
",",
"'make_integer'",
")",
";",
"$",
"rules",
"[",
"'sanitize_callback'",
"]",
"=",
"isset",
"(",
"$",
"rules",
"[",
"'sanitize_callback'",
"]",
")",
"?",
"$",
"this",
"->",
"add_callback",
"(",
"$",
"rules",
"[",
"'sanitize_callback'",
"]",
",",
"$",
"callback",
")",
":",
"$",
"callback",
";",
"break",
";",
"}",
"}",
"return",
"$",
"rules",
";",
"}"
]
| Parses a validation string into a WP-API compatible rule.
@param string $validation
@return array
@todo The next rule added needs to refactor this process. | [
"Parses",
"a",
"validation",
"string",
"into",
"a",
"WP",
"-",
"API",
"compatible",
"rule",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Http/Filter.php#L62-L104 | train |
intraxia/jaxion | src/Http/Filter.php | Filter.add_callback | private function add_callback( $previous, $next ) {
return function ( $value ) use ( $previous, $next ) {
if ( call_user_func( $previous, $value ) ) {
return call_user_func( $next, $value );
}
return false;
};
} | php | private function add_callback( $previous, $next ) {
return function ( $value ) use ( $previous, $next ) {
if ( call_user_func( $previous, $value ) ) {
return call_user_func( $next, $value );
}
return false;
};
} | [
"private",
"function",
"add_callback",
"(",
"$",
"previous",
",",
"$",
"next",
")",
"{",
"return",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"$",
"previous",
",",
"$",
"next",
")",
"{",
"if",
"(",
"call_user_func",
"(",
"$",
"previous",
",",
"$",
"value",
")",
")",
"{",
"return",
"call_user_func",
"(",
"$",
"next",
",",
"$",
"value",
")",
";",
"}",
"return",
"false",
";",
"}",
";",
"}"
]
| Creates a new callback that connects the previous and next callback.
@param callable $previous
@param callable $next
@return \Closure; | [
"Creates",
"a",
"new",
"callback",
"that",
"connects",
"the",
"previous",
"and",
"next",
"callback",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Http/Filter.php#L136-L144 | train |
intraxia/jaxion | src/Core/Loader.php | Loader.add | protected function add( $hooks, $hook, $service, $method, $priority, $accepted_args ) {
$hooks[] = array(
'hook' => $hook,
'service' => $service,
'method' => $method,
'priority' => $priority,
'args' => $accepted_args,
);
return $hooks;
} | php | protected function add( $hooks, $hook, $service, $method, $priority, $accepted_args ) {
$hooks[] = array(
'hook' => $hook,
'service' => $service,
'method' => $method,
'priority' => $priority,
'args' => $accepted_args,
);
return $hooks;
} | [
"protected",
"function",
"add",
"(",
"$",
"hooks",
",",
"$",
"hook",
",",
"$",
"service",
",",
"$",
"method",
",",
"$",
"priority",
",",
"$",
"accepted_args",
")",
"{",
"$",
"hooks",
"[",
"]",
"=",
"array",
"(",
"'hook'",
"=>",
"$",
"hook",
",",
"'service'",
"=>",
"$",
"service",
",",
"'method'",
"=>",
"$",
"method",
",",
"'priority'",
"=>",
"$",
"priority",
",",
"'args'",
"=>",
"$",
"accepted_args",
",",
")",
";",
"return",
"$",
"hooks",
";",
"}"
]
| Utility to register the actions and hooks into a single collection.
@param array $hooks
@param string $hook
@param object $service
@param string $method
@param int $priority
@param int $accepted_args
@return array | [
"Utility",
"to",
"register",
"the",
"actions",
"and",
"hooks",
"into",
"a",
"single",
"collection",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Core/Loader.php#L112-L122 | train |
intraxia/jaxion | src/Http/Router.php | Router.register | public function register() {
if ( ! $this->vendor ) {
throw new VendorNotSetException;
}
if ( ! $this->version ) {
throw new VersionNotSetException;
}
foreach ( $this->endpoints as $endpoint ) {
register_rest_route(
$this->get_namespace(),
$endpoint->get_route(),
$endpoint->get_options()
);
}
} | php | public function register() {
if ( ! $this->vendor ) {
throw new VendorNotSetException;
}
if ( ! $this->version ) {
throw new VersionNotSetException;
}
foreach ( $this->endpoints as $endpoint ) {
register_rest_route(
$this->get_namespace(),
$endpoint->get_route(),
$endpoint->get_options()
);
}
} | [
"public",
"function",
"register",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"vendor",
")",
"{",
"throw",
"new",
"VendorNotSetException",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"version",
")",
"{",
"throw",
"new",
"VersionNotSetException",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"endpoints",
"as",
"$",
"endpoint",
")",
"{",
"register_rest_route",
"(",
"$",
"this",
"->",
"get_namespace",
"(",
")",
",",
"$",
"endpoint",
"->",
"get_route",
"(",
")",
",",
"$",
"endpoint",
"->",
"get_options",
"(",
")",
")",
";",
"}",
"}"
]
| Registers all of the routes with the WP-API.
Runs on the `rest_api_init` hook. Registers all of the routes loaded
on the router into the WordPress REST API.
@throws VendorNotSetException
@throws VersionNotSetException | [
"Registers",
"all",
"of",
"the",
"routes",
"with",
"the",
"WP",
"-",
"API",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Http/Router.php#L104-L120 | train |
intraxia/jaxion | src/Http/Router.php | Router.group | public function group( array $options, $callback ) {
$router = new static;
call_user_func( $callback, $router );
foreach ( $router->get_endpoints() as $endpoint ) {
$this->endpoints[] = $this->set_options( $endpoint, $options );
}
} | php | public function group( array $options, $callback ) {
$router = new static;
call_user_func( $callback, $router );
foreach ( $router->get_endpoints() as $endpoint ) {
$this->endpoints[] = $this->set_options( $endpoint, $options );
}
} | [
"public",
"function",
"group",
"(",
"array",
"$",
"options",
",",
"$",
"callback",
")",
"{",
"$",
"router",
"=",
"new",
"static",
";",
"call_user_func",
"(",
"$",
"callback",
",",
"$",
"router",
")",
";",
"foreach",
"(",
"$",
"router",
"->",
"get_endpoints",
"(",
")",
"as",
"$",
"endpoint",
")",
"{",
"$",
"this",
"->",
"endpoints",
"[",
"]",
"=",
"$",
"this",
"->",
"set_options",
"(",
"$",
"endpoint",
",",
"$",
"options",
")",
";",
"}",
"}"
]
| Registers a set of routes with a shared set of options.
Allows you to group routes together with shared set of options, including
a route prefix, shared guards, and common parameter validation or sanitization.
@param array $options
@param callable $callback | [
"Registers",
"a",
"set",
"of",
"routes",
"with",
"a",
"shared",
"set",
"of",
"options",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Http/Router.php#L131-L139 | train |
intraxia/jaxion | src/Http/Router.php | Router.set_options | protected function set_options( Endpoint $endpoint, array $options ) {
if ( isset( $options['guard'] ) ) {
$endpoint->set_guard( $options['guard'] );
}
if ( isset( $options['filter'] ) ) {
$endpoint->set_filter( $options['filter'] );
}
if ( isset( $options['prefix'] ) ) {
$endpoint->set_prefix( $options['prefix'] );
}
return $endpoint;
} | php | protected function set_options( Endpoint $endpoint, array $options ) {
if ( isset( $options['guard'] ) ) {
$endpoint->set_guard( $options['guard'] );
}
if ( isset( $options['filter'] ) ) {
$endpoint->set_filter( $options['filter'] );
}
if ( isset( $options['prefix'] ) ) {
$endpoint->set_prefix( $options['prefix'] );
}
return $endpoint;
} | [
"protected",
"function",
"set_options",
"(",
"Endpoint",
"$",
"endpoint",
",",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'guard'",
"]",
")",
")",
"{",
"$",
"endpoint",
"->",
"set_guard",
"(",
"$",
"options",
"[",
"'guard'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'filter'",
"]",
")",
")",
"{",
"$",
"endpoint",
"->",
"set_filter",
"(",
"$",
"options",
"[",
"'filter'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'prefix'",
"]",
")",
")",
"{",
"$",
"endpoint",
"->",
"set_prefix",
"(",
"$",
"options",
"[",
"'prefix'",
"]",
")",
";",
"}",
"return",
"$",
"endpoint",
";",
"}"
]
| Sets the passed options on the endpoint.
Only sets endpoints matching setters in the Endpoint class.
@param Endpoint $endpoint
@param array $options
@return Endpoint
@throws MalformedRouteException | [
"Sets",
"the",
"passed",
"options",
"on",
"the",
"endpoint",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Http/Router.php#L192-L206 | train |
intraxia/jaxion | src/Axolotl/Type.php | Type.is_model | public function is_model() {
if ( ! class_exists( $this->type ) ) {
return false;
}
$reflection = new ReflectionClass( $this->type );
return $reflection->isSubclassOf( 'Intraxia\Jaxion\Axolotl\Model' );
} | php | public function is_model() {
if ( ! class_exists( $this->type ) ) {
return false;
}
$reflection = new ReflectionClass( $this->type );
return $reflection->isSubclassOf( 'Intraxia\Jaxion\Axolotl\Model' );
} | [
"public",
"function",
"is_model",
"(",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"this",
"->",
"type",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"reflection",
"=",
"new",
"ReflectionClass",
"(",
"$",
"this",
"->",
"type",
")",
";",
"return",
"$",
"reflection",
"->",
"isSubclassOf",
"(",
"'Intraxia\\Jaxion\\Axolotl\\Model'",
")",
";",
"}"
]
| Returns whether the type is an Axolotl model.
@return bool | [
"Returns",
"whether",
"the",
"type",
"is",
"an",
"Axolotl",
"model",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Axolotl/Type.php#L49-L56 | train |
intraxia/jaxion | src/Axolotl/Type.php | Type.validate_element | public function validate_element( $element ) {
$type = gettype( $element );
$callable = $this->type === 'callable';
$is_object = 'object' === $type;
$loose_check = $this->type === 'object';
// callable must be callable
if ( $callable && ! is_callable( $element ) ) {
throw new InvalidArgumentException( 'Item must be callable' );
}
// target isn't callable, object must be an instance of target
if ( ! $loose_check && ! $callable && $is_object && ! is_a( $element, $this->type ) ) {
throw new InvalidArgumentException( "Item is not type or subtype of $this->type" );
}
// a non callable, non object type should match the target string
if ( ! $callable && ! $is_object && $type !== $this->type ) {
throw new InvalidArgumentException( "Item is not of type: $this->type" );
}
} | php | public function validate_element( $element ) {
$type = gettype( $element );
$callable = $this->type === 'callable';
$is_object = 'object' === $type;
$loose_check = $this->type === 'object';
// callable must be callable
if ( $callable && ! is_callable( $element ) ) {
throw new InvalidArgumentException( 'Item must be callable' );
}
// target isn't callable, object must be an instance of target
if ( ! $loose_check && ! $callable && $is_object && ! is_a( $element, $this->type ) ) {
throw new InvalidArgumentException( "Item is not type or subtype of $this->type" );
}
// a non callable, non object type should match the target string
if ( ! $callable && ! $is_object && $type !== $this->type ) {
throw new InvalidArgumentException( "Item is not of type: $this->type" );
}
} | [
"public",
"function",
"validate_element",
"(",
"$",
"element",
")",
"{",
"$",
"type",
"=",
"gettype",
"(",
"$",
"element",
")",
";",
"$",
"callable",
"=",
"$",
"this",
"->",
"type",
"===",
"'callable'",
";",
"$",
"is_object",
"=",
"'object'",
"===",
"$",
"type",
";",
"$",
"loose_check",
"=",
"$",
"this",
"->",
"type",
"===",
"'object'",
";",
"// callable must be callable",
"if",
"(",
"$",
"callable",
"&&",
"!",
"is_callable",
"(",
"$",
"element",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Item must be callable'",
")",
";",
"}",
"// target isn't callable, object must be an instance of target",
"if",
"(",
"!",
"$",
"loose_check",
"&&",
"!",
"$",
"callable",
"&&",
"$",
"is_object",
"&&",
"!",
"is_a",
"(",
"$",
"element",
",",
"$",
"this",
"->",
"type",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Item is not type or subtype of $this->type\"",
")",
";",
"}",
"// a non callable, non object type should match the target string",
"if",
"(",
"!",
"$",
"callable",
"&&",
"!",
"$",
"is_object",
"&&",
"$",
"type",
"!==",
"$",
"this",
"->",
"type",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Item is not of type: $this->type\"",
")",
";",
"}",
"}"
]
| Validate whether the
@param mixed $element Element to validate.
@throws InvalidArgumentException | [
"Validate",
"whether",
"the"
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Axolotl/Type.php#L89-L109 | train |
intraxia/jaxion | src/Axolotl/Type.php | Type.determine | private function determine( $type, $key_type = false ) {
if ( ! $key_type && $this->non_scalar_type_exists( $type ) ) {
return $type;
}
if ( $scalar_type = $this->determine_scalar( $type ) ) {
if ( $key_type && (in_array( $scalar_type, array( 'double', 'boolean' ) )) ) {
throw new InvalidArgumentException( 'This type is not supported as a key.' );
}
return $scalar_type;
}
throw new InvalidArgumentException( 'This type does not exist.' );
} | php | private function determine( $type, $key_type = false ) {
if ( ! $key_type && $this->non_scalar_type_exists( $type ) ) {
return $type;
}
if ( $scalar_type = $this->determine_scalar( $type ) ) {
if ( $key_type && (in_array( $scalar_type, array( 'double', 'boolean' ) )) ) {
throw new InvalidArgumentException( 'This type is not supported as a key.' );
}
return $scalar_type;
}
throw new InvalidArgumentException( 'This type does not exist.' );
} | [
"private",
"function",
"determine",
"(",
"$",
"type",
",",
"$",
"key_type",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"key_type",
"&&",
"$",
"this",
"->",
"non_scalar_type_exists",
"(",
"$",
"type",
")",
")",
"{",
"return",
"$",
"type",
";",
"}",
"if",
"(",
"$",
"scalar_type",
"=",
"$",
"this",
"->",
"determine_scalar",
"(",
"$",
"type",
")",
")",
"{",
"if",
"(",
"$",
"key_type",
"&&",
"(",
"in_array",
"(",
"$",
"scalar_type",
",",
"array",
"(",
"'double'",
",",
"'boolean'",
")",
")",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'This type is not supported as a key.'",
")",
";",
"}",
"return",
"$",
"scalar_type",
";",
"}",
"throw",
"new",
"InvalidArgumentException",
"(",
"'This type does not exist.'",
")",
";",
"}"
]
| Determine the type to validate against.
@param string $type Type to determine.
@param bool $key_type Whether the type is for keys.
@return string
@throws InvalidArgumentException | [
"Determine",
"the",
"type",
"to",
"validate",
"against",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Axolotl/Type.php#L121-L135 | train |
intraxia/jaxion | src/Axolotl/Type.php | Type.determine_scalar | private function determine_scalar( $type ) {
$synonyms = array(
'int' => 'integer',
'float' => 'double',
'bool' => 'boolean',
);
if ( array_key_exists( $type, $synonyms ) ) {
$type = $synonyms[ $type ];
}
return in_array( $type, array( 'string', 'integer', 'double', 'boolean' ) ) ?
$type :
null;
} | php | private function determine_scalar( $type ) {
$synonyms = array(
'int' => 'integer',
'float' => 'double',
'bool' => 'boolean',
);
if ( array_key_exists( $type, $synonyms ) ) {
$type = $synonyms[ $type ];
}
return in_array( $type, array( 'string', 'integer', 'double', 'boolean' ) ) ?
$type :
null;
} | [
"private",
"function",
"determine_scalar",
"(",
"$",
"type",
")",
"{",
"$",
"synonyms",
"=",
"array",
"(",
"'int'",
"=>",
"'integer'",
",",
"'float'",
"=>",
"'double'",
",",
"'bool'",
"=>",
"'boolean'",
",",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"type",
",",
"$",
"synonyms",
")",
")",
"{",
"$",
"type",
"=",
"$",
"synonyms",
"[",
"$",
"type",
"]",
";",
"}",
"return",
"in_array",
"(",
"$",
"type",
",",
"array",
"(",
"'string'",
",",
"'integer'",
",",
"'double'",
",",
"'boolean'",
")",
")",
"?",
"$",
"type",
":",
"null",
";",
"}"
]
| Returns the type if it's scalar, otherwise, returns null.
@param string $type Type to check.
@return string|null | [
"Returns",
"the",
"type",
"if",
"it",
"s",
"scalar",
"otherwise",
"returns",
"null",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Axolotl/Type.php#L157-L171 | train |
intraxia/jaxion | src/Http/Endpoint.php | Endpoint.get_options | public function get_options() {
$options = array(
'methods' => $this->method,
'callback' => $this->callback,
);
if ( $this->guard ) {
$options['permission_callback'] = array( $this->guard, 'authorized' );
}
if ( $this->filter ) {
$options['args'] = $this->filter->rules();
}
return $options;
} | php | public function get_options() {
$options = array(
'methods' => $this->method,
'callback' => $this->callback,
);
if ( $this->guard ) {
$options['permission_callback'] = array( $this->guard, 'authorized' );
}
if ( $this->filter ) {
$options['args'] = $this->filter->rules();
}
return $options;
} | [
"public",
"function",
"get_options",
"(",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"'methods'",
"=>",
"$",
"this",
"->",
"method",
",",
"'callback'",
"=>",
"$",
"this",
"->",
"callback",
",",
")",
";",
"if",
"(",
"$",
"this",
"->",
"guard",
")",
"{",
"$",
"options",
"[",
"'permission_callback'",
"]",
"=",
"array",
"(",
"$",
"this",
"->",
"guard",
",",
"'authorized'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"filter",
")",
"{",
"$",
"options",
"[",
"'args'",
"]",
"=",
"$",
"this",
"->",
"filter",
"->",
"rules",
"(",
")",
";",
"}",
"return",
"$",
"options",
";",
"}"
]
| Generates the endpoint's WP-API options array.
@return array | [
"Generates",
"the",
"endpoint",
"s",
"WP",
"-",
"API",
"options",
"array",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Http/Endpoint.php#L94-L109 | train |
intraxia/jaxion | src/Http/Endpoint.php | Endpoint.set_prefix | public function set_prefix( $prefix ) {
if ( ! Str::starts_with( $prefix, '/' ) || Str::ends_with( $prefix, '/' ) ) {
throw new MalformedRouteException;
}
$this->prefix = $prefix;
return $this;
} | php | public function set_prefix( $prefix ) {
if ( ! Str::starts_with( $prefix, '/' ) || Str::ends_with( $prefix, '/' ) ) {
throw new MalformedRouteException;
}
$this->prefix = $prefix;
return $this;
} | [
"public",
"function",
"set_prefix",
"(",
"$",
"prefix",
")",
"{",
"if",
"(",
"!",
"Str",
"::",
"starts_with",
"(",
"$",
"prefix",
",",
"'/'",
")",
"||",
"Str",
"::",
"ends_with",
"(",
"$",
"prefix",
",",
"'/'",
")",
")",
"{",
"throw",
"new",
"MalformedRouteException",
";",
"}",
"$",
"this",
"->",
"prefix",
"=",
"$",
"prefix",
";",
"return",
"$",
"this",
";",
"}"
]
| Sets the endpoint's prefix.
@param string $prefix
@return $this
@throws MalformedRouteException | [
"Sets",
"the",
"endpoint",
"s",
"prefix",
"."
]
| f45a869720067f597afe64d397a23155e412742d | https://github.com/intraxia/jaxion/blob/f45a869720067f597afe64d397a23155e412742d/src/Http/Endpoint.php#L145-L153 | train |
geocoder-php/plugin | PluginProvider.php | PluginProvider.configure | private function configure(array $options = []): array
{
$defaults = [
'max_restarts' => 10,
];
$config = array_merge($defaults, $options);
// Make sure no invalid values are provided
if (count($config) !== count($defaults)) {
throw new LogicException(sprintf('Valid options to the PluginProviders are: %s', implode(', ', array_values($defaults))));
}
return $config;
} | php | private function configure(array $options = []): array
{
$defaults = [
'max_restarts' => 10,
];
$config = array_merge($defaults, $options);
// Make sure no invalid values are provided
if (count($config) !== count($defaults)) {
throw new LogicException(sprintf('Valid options to the PluginProviders are: %s', implode(', ', array_values($defaults))));
}
return $config;
} | [
"private",
"function",
"configure",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"array",
"{",
"$",
"defaults",
"=",
"[",
"'max_restarts'",
"=>",
"10",
",",
"]",
";",
"$",
"config",
"=",
"array_merge",
"(",
"$",
"defaults",
",",
"$",
"options",
")",
";",
"// Make sure no invalid values are provided",
"if",
"(",
"count",
"(",
"$",
"config",
")",
"!==",
"count",
"(",
"$",
"defaults",
")",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"sprintf",
"(",
"'Valid options to the PluginProviders are: %s'",
",",
"implode",
"(",
"', '",
",",
"array_values",
"(",
"$",
"defaults",
")",
")",
")",
")",
";",
"}",
"return",
"$",
"config",
";",
"}"
]
| Configure the plugin provider.
@param array $options
@return array | [
"Configure",
"the",
"plugin",
"provider",
"."
]
| 28be5389ab2b6c23447e248c016b3d45d9b17fb9 | https://github.com/geocoder-php/plugin/blob/28be5389ab2b6c23447e248c016b3d45d9b17fb9/PluginProvider.php#L111-L125 | train |
Aerendir/stripe-bundle | src/Syncer/AbstractSyncer.php | AbstractSyncer.getLocalCustomer | protected function getLocalCustomer($stripeCustomerId)
{
// First try to get the customer from the database
$localCustomer = $this->getEntityManager()->getRepository('SHQStripeBundle:StripeLocalCustomer')->findOneByStripeId($stripeCustomerId);
// If we found it, return it
if (null !== $localCustomer) {
return $localCustomer;
}
// Try to find the customer in the newly created one that are not already persisted
return $this->getEntityManager()->getUnitOfWork()->tryGetById($stripeCustomerId, StripeLocalCustomer::class);
} | php | protected function getLocalCustomer($stripeCustomerId)
{
// First try to get the customer from the database
$localCustomer = $this->getEntityManager()->getRepository('SHQStripeBundle:StripeLocalCustomer')->findOneByStripeId($stripeCustomerId);
// If we found it, return it
if (null !== $localCustomer) {
return $localCustomer;
}
// Try to find the customer in the newly created one that are not already persisted
return $this->getEntityManager()->getUnitOfWork()->tryGetById($stripeCustomerId, StripeLocalCustomer::class);
} | [
"protected",
"function",
"getLocalCustomer",
"(",
"$",
"stripeCustomerId",
")",
"{",
"// First try to get the customer from the database",
"$",
"localCustomer",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"getRepository",
"(",
"'SHQStripeBundle:StripeLocalCustomer'",
")",
"->",
"findOneByStripeId",
"(",
"$",
"stripeCustomerId",
")",
";",
"// If we found it, return it",
"if",
"(",
"null",
"!==",
"$",
"localCustomer",
")",
"{",
"return",
"$",
"localCustomer",
";",
"}",
"// Try to find the customer in the newly created one that are not already persisted",
"return",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"getUnitOfWork",
"(",
")",
"->",
"tryGetById",
"(",
"$",
"stripeCustomerId",
",",
"StripeLocalCustomer",
"::",
"class",
")",
";",
"}"
]
| Gets the local customer object searching for it in the database or in the newly created entities persisted but
not yet flushed.
@param $stripeCustomerId
@return bool|StripeLocalCustomer false if the StripeLocalCustomer was not found | [
"Gets",
"the",
"local",
"customer",
"object",
"searching",
"for",
"it",
"in",
"the",
"database",
"or",
"in",
"the",
"newly",
"created",
"entities",
"persisted",
"but",
"not",
"yet",
"flushed",
"."
]
| 5d74a3c2a133fe6d97e838cbcbecad939d32626f | https://github.com/Aerendir/stripe-bundle/blob/5d74a3c2a133fe6d97e838cbcbecad939d32626f/src/Syncer/AbstractSyncer.php#L150-L162 | train |
danielstjules/pho | src/Reporter/DotReporter.php | DotReporter.beforeSpec | public function beforeSpec(Spec $spec)
{
parent::beforeSpec($spec);
if ($this->lineLength == self::$maxPerLine) {
$this->console->writeLn('');
$this->lineLength = 0;
}
} | php | public function beforeSpec(Spec $spec)
{
parent::beforeSpec($spec);
if ($this->lineLength == self::$maxPerLine) {
$this->console->writeLn('');
$this->lineLength = 0;
}
} | [
"public",
"function",
"beforeSpec",
"(",
"Spec",
"$",
"spec",
")",
"{",
"parent",
"::",
"beforeSpec",
"(",
"$",
"spec",
")",
";",
"if",
"(",
"$",
"this",
"->",
"lineLength",
"==",
"self",
"::",
"$",
"maxPerLine",
")",
"{",
"$",
"this",
"->",
"console",
"->",
"writeLn",
"(",
"''",
")",
";",
"$",
"this",
"->",
"lineLength",
"=",
"0",
";",
"}",
"}"
]
| Ran before an individual spec.
@param Spec $spec The spec before which to run this method | [
"Ran",
"before",
"an",
"individual",
"spec",
"."
]
| 1514be7fc15632bd04ba1c3f0cccc57859c7969f | https://github.com/danielstjules/pho/blob/1514be7fc15632bd04ba1c3f0cccc57859c7969f/src/Reporter/DotReporter.php#L40-L48 | train |
danielstjules/pho | src/Reporter/DotReporter.php | DotReporter.afterSpec | public function afterSpec(Spec $spec)
{
$this->lineLength += 1;
if ($spec->isFailed()) {
$this->failures[] = $spec;
$failure = $this->formatter->red('F');
$this->console->write($failure);
} elseif ($spec->isIncomplete()) {
$this->incompleteSpecs[] = $spec;
$incomplete = $this->formatter->cyan('I');
$this->console->write($incomplete);
} elseif ($spec->isPending()) {
$this->pendingSpecs[] = $spec;
$pending = $this->formatter->yellow('P');
$this->console->write($pending);
} else {
$this->console->write('.');
}
} | php | public function afterSpec(Spec $spec)
{
$this->lineLength += 1;
if ($spec->isFailed()) {
$this->failures[] = $spec;
$failure = $this->formatter->red('F');
$this->console->write($failure);
} elseif ($spec->isIncomplete()) {
$this->incompleteSpecs[] = $spec;
$incomplete = $this->formatter->cyan('I');
$this->console->write($incomplete);
} elseif ($spec->isPending()) {
$this->pendingSpecs[] = $spec;
$pending = $this->formatter->yellow('P');
$this->console->write($pending);
} else {
$this->console->write('.');
}
} | [
"public",
"function",
"afterSpec",
"(",
"Spec",
"$",
"spec",
")",
"{",
"$",
"this",
"->",
"lineLength",
"+=",
"1",
";",
"if",
"(",
"$",
"spec",
"->",
"isFailed",
"(",
")",
")",
"{",
"$",
"this",
"->",
"failures",
"[",
"]",
"=",
"$",
"spec",
";",
"$",
"failure",
"=",
"$",
"this",
"->",
"formatter",
"->",
"red",
"(",
"'F'",
")",
";",
"$",
"this",
"->",
"console",
"->",
"write",
"(",
"$",
"failure",
")",
";",
"}",
"elseif",
"(",
"$",
"spec",
"->",
"isIncomplete",
"(",
")",
")",
"{",
"$",
"this",
"->",
"incompleteSpecs",
"[",
"]",
"=",
"$",
"spec",
";",
"$",
"incomplete",
"=",
"$",
"this",
"->",
"formatter",
"->",
"cyan",
"(",
"'I'",
")",
";",
"$",
"this",
"->",
"console",
"->",
"write",
"(",
"$",
"incomplete",
")",
";",
"}",
"elseif",
"(",
"$",
"spec",
"->",
"isPending",
"(",
")",
")",
"{",
"$",
"this",
"->",
"pendingSpecs",
"[",
"]",
"=",
"$",
"spec",
";",
"$",
"pending",
"=",
"$",
"this",
"->",
"formatter",
"->",
"yellow",
"(",
"'P'",
")",
";",
"$",
"this",
"->",
"console",
"->",
"write",
"(",
"$",
"pending",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"console",
"->",
"write",
"(",
"'.'",
")",
";",
"}",
"}"
]
| Ran after an individual spec.
@param Spec $spec The spec after which to run this method | [
"Ran",
"after",
"an",
"individual",
"spec",
"."
]
| 1514be7fc15632bd04ba1c3f0cccc57859c7969f | https://github.com/danielstjules/pho/blob/1514be7fc15632bd04ba1c3f0cccc57859c7969f/src/Reporter/DotReporter.php#L55-L74 | train |
stymiee/authnetjson | src/authnet/AuthnetWebhooksResponse.php | AuthnetWebhooksResponse.getEventTypes | public function getEventTypes()
{
$events = [];
if (isset($this->response->eventTypes)) {
foreach ($this->response->eventTypes as $event) {
$events[] = $event;
}
} else {
$events = array_column($this->response, 'name');
}
return $events;
} | php | public function getEventTypes()
{
$events = [];
if (isset($this->response->eventTypes)) {
foreach ($this->response->eventTypes as $event) {
$events[] = $event;
}
} else {
$events = array_column($this->response, 'name');
}
return $events;
} | [
"public",
"function",
"getEventTypes",
"(",
")",
"{",
"$",
"events",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"response",
"->",
"eventTypes",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"response",
"->",
"eventTypes",
"as",
"$",
"event",
")",
"{",
"$",
"events",
"[",
"]",
"=",
"$",
"event",
";",
"}",
"}",
"else",
"{",
"$",
"events",
"=",
"array_column",
"(",
"$",
"this",
"->",
"response",
",",
"'name'",
")",
";",
"}",
"return",
"$",
"events",
";",
"}"
]
| Gets a response variable from the API response
net.authorize.customer.created
net.authorize.customer.deleted
net.authorize.customer.updated
net.authorize.customer.paymentProfile.created
net.authorize.customer.paymentProfile.deleted
net.authorize.customer.paymentProfile.updated
net.authorize.customer.subscription.cancelled
net.authorize.customer.subscription.created
net.authorize.customer.subscription.expiring
net.authorize.customer.subscription.suspended
net.authorize.customer.subscription.terminated
net.authorize.customer.subscription.updated
net.authorize.payment.authcapture.created
net.authorize.payment.authorization.created
net.authorize.payment.capture.created
net.authorize.payment.fraud.approved
net.authorize.payment.fraud.declined
net.authorize.payment.fraud.held
net.authorize.payment.priorAuthCapture.created
net.authorize.payment.refund.created
net.authorize.payment.void.created
@return array Array of event types supported by Webhooks API | [
"Gets",
"a",
"response",
"variable",
"from",
"the",
"API",
"response"
]
| fb871877d978b5571d94163b59d4d1c97395eb8f | https://github.com/stymiee/authnetjson/blob/fb871877d978b5571d94163b59d4d1c97395eb8f/src/authnet/AuthnetWebhooksResponse.php#L94-L105 | train |
danielstjules/pho | src/Expectation/Expectation.php | Expectation.invokeCustomMatcher | private function invokeCustomMatcher($name)
{
$class = self::$customMatchers[$name];
$args = array_slice(func_get_args(), 1);
$matcher = call_user_func_array(
[new \ReflectionClass($class), 'newInstance'],
$args
);
$this->test($matcher);
return $this;
} | php | private function invokeCustomMatcher($name)
{
$class = self::$customMatchers[$name];
$args = array_slice(func_get_args(), 1);
$matcher = call_user_func_array(
[new \ReflectionClass($class), 'newInstance'],
$args
);
$this->test($matcher);
return $this;
} | [
"private",
"function",
"invokeCustomMatcher",
"(",
"$",
"name",
")",
"{",
"$",
"class",
"=",
"self",
"::",
"$",
"customMatchers",
"[",
"$",
"name",
"]",
";",
"$",
"args",
"=",
"array_slice",
"(",
"func_get_args",
"(",
")",
",",
"1",
")",
";",
"$",
"matcher",
"=",
"call_user_func_array",
"(",
"[",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
",",
"'newInstance'",
"]",
",",
"$",
"args",
")",
";",
"$",
"this",
"->",
"test",
"(",
"$",
"matcher",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Calls a custom matcher. The matcher is expected to implement
pho\Expectation\Matcher\MatcherInterface. A new instance is created,
and its match method is called with a variable number of arguments. If
match returns false, getFailureMessage is passed as the description to
an ExpectationException.
@param string $name The name of the custom matcher
@param mixed $arg,.. Arguments to be passed
@returns Expectation The current expectation
@throws ExpectationException If the positive or negative match fails | [
"Calls",
"a",
"custom",
"matcher",
".",
"The",
"matcher",
"is",
"expected",
"to",
"implement",
"pho",
"\\",
"Expectation",
"\\",
"Matcher",
"\\",
"MatcherInterface",
".",
"A",
"new",
"instance",
"is",
"created",
"and",
"its",
"match",
"method",
"is",
"called",
"with",
"a",
"variable",
"number",
"of",
"arguments",
".",
"If",
"match",
"returns",
"false",
"getFailureMessage",
"is",
"passed",
"as",
"the",
"description",
"to",
"an",
"ExpectationException",
"."
]
| 1514be7fc15632bd04ba1c3f0cccc57859c7969f | https://github.com/danielstjules/pho/blob/1514be7fc15632bd04ba1c3f0cccc57859c7969f/src/Expectation/Expectation.php#L416-L428 | train |
NtimYeboah/laravel-database-trigger | src/Command/TriggerMakeCommand.php | TriggerMakeCommand.writeMigration | private function writeMigration($name, $eventObjectTable, $actionTiming, $event)
{
$file = pathinfo($this->creator->write(
$name,
$eventObjectTable,
$actionTiming,
$event,
$this->getMigrationPath()
), PATHINFO_FILENAME);
$this->line("<info>Created Migration:</info> {$file}");
} | php | private function writeMigration($name, $eventObjectTable, $actionTiming, $event)
{
$file = pathinfo($this->creator->write(
$name,
$eventObjectTable,
$actionTiming,
$event,
$this->getMigrationPath()
), PATHINFO_FILENAME);
$this->line("<info>Created Migration:</info> {$file}");
} | [
"private",
"function",
"writeMigration",
"(",
"$",
"name",
",",
"$",
"eventObjectTable",
",",
"$",
"actionTiming",
",",
"$",
"event",
")",
"{",
"$",
"file",
"=",
"pathinfo",
"(",
"$",
"this",
"->",
"creator",
"->",
"write",
"(",
"$",
"name",
",",
"$",
"eventObjectTable",
",",
"$",
"actionTiming",
",",
"$",
"event",
",",
"$",
"this",
"->",
"getMigrationPath",
"(",
")",
")",
",",
"PATHINFO_FILENAME",
")",
";",
"$",
"this",
"->",
"line",
"(",
"\"<info>Created Migration:</info> {$file}\"",
")",
";",
"}"
]
| Write to migration file.
@param string $name
@param string $eventObjectTable
@param string $actionTiming
@param string $event
@return void | [
"Write",
"to",
"migration",
"file",
"."
]
| 1f9e44ad0faf351ae60cbb025d33d63af9ec2e41 | https://github.com/NtimYeboah/laravel-database-trigger/blob/1f9e44ad0faf351ae60cbb025d33d63af9ec2e41/src/Command/TriggerMakeCommand.php#L82-L93 | train |
Aerendir/stripe-bundle | src/Model/StripeLocalSubscription.php | StripeLocalSubscription.metadataTransformer | public function metadataTransformer()
{
if (is_string($this->getMetadata())) {
$this->setMetadata(json_decode($this->getMetadata(), true));
}
} | php | public function metadataTransformer()
{
if (is_string($this->getMetadata())) {
$this->setMetadata(json_decode($this->getMetadata(), true));
}
} | [
"public",
"function",
"metadataTransformer",
"(",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"getMetadata",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"setMetadata",
"(",
"json_decode",
"(",
"$",
"this",
"->",
"getMetadata",
"(",
")",
",",
"true",
")",
")",
";",
"}",
"}"
]
| Transforms metadata from string to array.
As metadata can be set by the developer or by reflection during syncronization of the StripeCustomer object with
this local one, may happen the value is a string.
This lifecycle callback ensures the value ever is an array. | [
"Transforms",
"metadata",
"from",
"string",
"to",
"array",
"."
]
| 5d74a3c2a133fe6d97e838cbcbecad939d32626f | https://github.com/Aerendir/stripe-bundle/blob/5d74a3c2a133fe6d97e838cbcbecad939d32626f/src/Model/StripeLocalSubscription.php#L431-L436 | train |
stymiee/authnetjson | src/authnet/AuthnetWebhooksRequest.php | AuthnetWebhooksRequest.getEventTypes | public function getEventTypes()
{
$this->endpoint = 'eventtypes';
$this->url = sprintf('%s%s', $this->url, $this->endpoint);
$response = $this->get($this->url);
return new AuthnetWebhooksResponse($response);
} | php | public function getEventTypes()
{
$this->endpoint = 'eventtypes';
$this->url = sprintf('%s%s', $this->url, $this->endpoint);
$response = $this->get($this->url);
return new AuthnetWebhooksResponse($response);
} | [
"public",
"function",
"getEventTypes",
"(",
")",
"{",
"$",
"this",
"->",
"endpoint",
"=",
"'eventtypes'",
";",
"$",
"this",
"->",
"url",
"=",
"sprintf",
"(",
"'%s%s'",
",",
"$",
"this",
"->",
"url",
",",
"$",
"this",
"->",
"endpoint",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"this",
"->",
"url",
")",
";",
"return",
"new",
"AuthnetWebhooksResponse",
"(",
"$",
"response",
")",
";",
"}"
]
| Gets all of the available event types
@return \JohnConde\Authnet\AuthnetWebhooksResponse
@throws \JohnConde\Authnet\AuthnetInvalidJsonException
@throws \JohnConde\Authnet\AuthnetCurlException | [
"Gets",
"all",
"of",
"the",
"available",
"event",
"types"
]
| fb871877d978b5571d94163b59d4d1c97395eb8f | https://github.com/stymiee/authnetjson/blob/fb871877d978b5571d94163b59d4d1c97395eb8f/src/authnet/AuthnetWebhooksRequest.php#L87-L93 | train |
stymiee/authnetjson | src/authnet/AuthnetWebhooksRequest.php | AuthnetWebhooksRequest.createWebhooks | public function createWebhooks(Array $webhooks, $webhookUrl, $status = 'active')
{
$this->endpoint = 'webhooks';
$this->url = sprintf('%s%s', $this->url, $this->endpoint);
$request = [
'url' => $webhookUrl,
'eventTypes' => $webhooks,
'status' => $status
];
$this->requestJson = json_encode($request);
$response = $this->post($this->url, $this->requestJson);
return new AuthnetWebhooksResponse($response);
} | php | public function createWebhooks(Array $webhooks, $webhookUrl, $status = 'active')
{
$this->endpoint = 'webhooks';
$this->url = sprintf('%s%s', $this->url, $this->endpoint);
$request = [
'url' => $webhookUrl,
'eventTypes' => $webhooks,
'status' => $status
];
$this->requestJson = json_encode($request);
$response = $this->post($this->url, $this->requestJson);
return new AuthnetWebhooksResponse($response);
} | [
"public",
"function",
"createWebhooks",
"(",
"Array",
"$",
"webhooks",
",",
"$",
"webhookUrl",
",",
"$",
"status",
"=",
"'active'",
")",
"{",
"$",
"this",
"->",
"endpoint",
"=",
"'webhooks'",
";",
"$",
"this",
"->",
"url",
"=",
"sprintf",
"(",
"'%s%s'",
",",
"$",
"this",
"->",
"url",
",",
"$",
"this",
"->",
"endpoint",
")",
";",
"$",
"request",
"=",
"[",
"'url'",
"=>",
"$",
"webhookUrl",
",",
"'eventTypes'",
"=>",
"$",
"webhooks",
",",
"'status'",
"=>",
"$",
"status",
"]",
";",
"$",
"this",
"->",
"requestJson",
"=",
"json_encode",
"(",
"$",
"request",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"post",
"(",
"$",
"this",
"->",
"url",
",",
"$",
"this",
"->",
"requestJson",
")",
";",
"return",
"new",
"AuthnetWebhooksResponse",
"(",
"$",
"response",
")",
";",
"}"
]
| Creates a new webhook
@param array $webhooks Array of webhooks to be created or modified
@param string $webhookUrl URL of where webhook notifications will be sent
@param string $status Status of webhooks to be created or modified [active/inactive]
@return \JohnConde\Authnet\AuthnetWebhooksResponse
@throws \JohnConde\Authnet\AuthnetInvalidJsonException
@throws \JohnConde\Authnet\AuthnetCurlException | [
"Creates",
"a",
"new",
"webhook"
]
| fb871877d978b5571d94163b59d4d1c97395eb8f | https://github.com/stymiee/authnetjson/blob/fb871877d978b5571d94163b59d4d1c97395eb8f/src/authnet/AuthnetWebhooksRequest.php#L105-L117 | train |
stymiee/authnetjson | src/authnet/AuthnetWebhooksRequest.php | AuthnetWebhooksRequest.getWebhooks | public function getWebhooks()
{
$this->endpoint = 'webhooks';
$this->url = sprintf('%s%s', $this->url, $this->endpoint);
$response = $this->get($this->url);
return new AuthnetWebhooksResponse($response);
} | php | public function getWebhooks()
{
$this->endpoint = 'webhooks';
$this->url = sprintf('%s%s', $this->url, $this->endpoint);
$response = $this->get($this->url);
return new AuthnetWebhooksResponse($response);
} | [
"public",
"function",
"getWebhooks",
"(",
")",
"{",
"$",
"this",
"->",
"endpoint",
"=",
"'webhooks'",
";",
"$",
"this",
"->",
"url",
"=",
"sprintf",
"(",
"'%s%s'",
",",
"$",
"this",
"->",
"url",
",",
"$",
"this",
"->",
"endpoint",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"this",
"->",
"url",
")",
";",
"return",
"new",
"AuthnetWebhooksResponse",
"(",
"$",
"response",
")",
";",
"}"
]
| List all of your webhooks
@return \JohnConde\Authnet\AuthnetWebhooksResponse
@throws \JohnConde\Authnet\AuthnetInvalidJsonException
@throws \JohnConde\Authnet\AuthnetCurlException | [
"List",
"all",
"of",
"your",
"webhooks"
]
| fb871877d978b5571d94163b59d4d1c97395eb8f | https://github.com/stymiee/authnetjson/blob/fb871877d978b5571d94163b59d4d1c97395eb8f/src/authnet/AuthnetWebhooksRequest.php#L140-L146 | train |
stymiee/authnetjson | src/authnet/AuthnetWebhooksRequest.php | AuthnetWebhooksRequest.getWebhook | public function getWebhook($webhookId)
{
$this->endpoint = 'webhooks';
$this->url = sprintf('%s%s/%s', $this->url, $this->endpoint, $webhookId);
$response = $this->get($this->url);
return new AuthnetWebhooksResponse($response);
} | php | public function getWebhook($webhookId)
{
$this->endpoint = 'webhooks';
$this->url = sprintf('%s%s/%s', $this->url, $this->endpoint, $webhookId);
$response = $this->get($this->url);
return new AuthnetWebhooksResponse($response);
} | [
"public",
"function",
"getWebhook",
"(",
"$",
"webhookId",
")",
"{",
"$",
"this",
"->",
"endpoint",
"=",
"'webhooks'",
";",
"$",
"this",
"->",
"url",
"=",
"sprintf",
"(",
"'%s%s/%s'",
",",
"$",
"this",
"->",
"url",
",",
"$",
"this",
"->",
"endpoint",
",",
"$",
"webhookId",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"this",
"->",
"url",
")",
";",
"return",
"new",
"AuthnetWebhooksResponse",
"(",
"$",
"response",
")",
";",
"}"
]
| Get a webhook
@param string $webhookId Webhook ID to be retrieved
@return \JohnConde\Authnet\AuthnetWebhooksResponse
@throws \JohnConde\Authnet\AuthnetInvalidJsonException
@throws \JohnConde\Authnet\AuthnetCurlException | [
"Get",
"a",
"webhook"
]
| fb871877d978b5571d94163b59d4d1c97395eb8f | https://github.com/stymiee/authnetjson/blob/fb871877d978b5571d94163b59d4d1c97395eb8f/src/authnet/AuthnetWebhooksRequest.php#L156-L162 | train |
stymiee/authnetjson | src/authnet/AuthnetWebhooksRequest.php | AuthnetWebhooksRequest.updateWebhook | public function updateWebhook($webhookId, $webhookUrl, Array $eventTypes, $status = 'active')
{
$this->endpoint = 'webhooks';
$this->url = sprintf('%s%s/%s', $this->url, $this->endpoint, $webhookId);
$request = [
'url' => $webhookUrl,
'eventTypes' => $eventTypes,
'status' => $status
];
$this->requestJson = json_encode($request);
$response = $this->put($this->url, $this->requestJson);
return new AuthnetWebhooksResponse($response);
} | php | public function updateWebhook($webhookId, $webhookUrl, Array $eventTypes, $status = 'active')
{
$this->endpoint = 'webhooks';
$this->url = sprintf('%s%s/%s', $this->url, $this->endpoint, $webhookId);
$request = [
'url' => $webhookUrl,
'eventTypes' => $eventTypes,
'status' => $status
];
$this->requestJson = json_encode($request);
$response = $this->put($this->url, $this->requestJson);
return new AuthnetWebhooksResponse($response);
} | [
"public",
"function",
"updateWebhook",
"(",
"$",
"webhookId",
",",
"$",
"webhookUrl",
",",
"Array",
"$",
"eventTypes",
",",
"$",
"status",
"=",
"'active'",
")",
"{",
"$",
"this",
"->",
"endpoint",
"=",
"'webhooks'",
";",
"$",
"this",
"->",
"url",
"=",
"sprintf",
"(",
"'%s%s/%s'",
",",
"$",
"this",
"->",
"url",
",",
"$",
"this",
"->",
"endpoint",
",",
"$",
"webhookId",
")",
";",
"$",
"request",
"=",
"[",
"'url'",
"=>",
"$",
"webhookUrl",
",",
"'eventTypes'",
"=>",
"$",
"eventTypes",
",",
"'status'",
"=>",
"$",
"status",
"]",
";",
"$",
"this",
"->",
"requestJson",
"=",
"json_encode",
"(",
"$",
"request",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"put",
"(",
"$",
"this",
"->",
"url",
",",
"$",
"this",
"->",
"requestJson",
")",
";",
"return",
"new",
"AuthnetWebhooksResponse",
"(",
"$",
"response",
")",
";",
"}"
]
| Updates webhook event types
@param array $webhookId Webhook ID to be modified
@param string $webhookUrl URL of where webhook notifications will be sent
@param array $eventTypes Array of event types to be added/removed
@param string $status Status of webhooks to be modified [active/inactive]
@return \JohnConde\Authnet\AuthnetWebhooksResponse
@throws \JohnConde\Authnet\AuthnetInvalidJsonException
@throws \JohnConde\Authnet\AuthnetCurlException | [
"Updates",
"webhook",
"event",
"types"
]
| fb871877d978b5571d94163b59d4d1c97395eb8f | https://github.com/stymiee/authnetjson/blob/fb871877d978b5571d94163b59d4d1c97395eb8f/src/authnet/AuthnetWebhooksRequest.php#L175-L187 | train |
stymiee/authnetjson | src/authnet/AuthnetWebhooksRequest.php | AuthnetWebhooksRequest.deleteWebhook | public function deleteWebhook($webhookId)
{
$this->endpoint = 'webhooks';
$this->url = sprintf('%s%s/%s', $this->url, $this->endpoint, $webhookId);
$this->delete($this->url);
} | php | public function deleteWebhook($webhookId)
{
$this->endpoint = 'webhooks';
$this->url = sprintf('%s%s/%s', $this->url, $this->endpoint, $webhookId);
$this->delete($this->url);
} | [
"public",
"function",
"deleteWebhook",
"(",
"$",
"webhookId",
")",
"{",
"$",
"this",
"->",
"endpoint",
"=",
"'webhooks'",
";",
"$",
"this",
"->",
"url",
"=",
"sprintf",
"(",
"'%s%s/%s'",
",",
"$",
"this",
"->",
"url",
",",
"$",
"this",
"->",
"endpoint",
",",
"$",
"webhookId",
")",
";",
"$",
"this",
"->",
"delete",
"(",
"$",
"this",
"->",
"url",
")",
";",
"}"
]
| Delete a webhook
@param string $webhookId Webhook ID to be deleted
@throws \JohnConde\Authnet\AuthnetCurlException | [
"Delete",
"a",
"webhook"
]
| fb871877d978b5571d94163b59d4d1c97395eb8f | https://github.com/stymiee/authnetjson/blob/fb871877d978b5571d94163b59d4d1c97395eb8f/src/authnet/AuthnetWebhooksRequest.php#L195-L200 | train |
stymiee/authnetjson | src/authnet/AuthnetWebhooksRequest.php | AuthnetWebhooksRequest.getNotificationHistory | public function getNotificationHistory($limit = 1000, $offset = 0)
{
$this->endpoint = 'notifications';
$this->url = sprintf('%s%s', $this->url, $this->endpoint);
$response = $this->get($this->url, [
'offset' => $offset,
'limit' => $limit
]);
return new AuthnetWebhooksResponse($response);
} | php | public function getNotificationHistory($limit = 1000, $offset = 0)
{
$this->endpoint = 'notifications';
$this->url = sprintf('%s%s', $this->url, $this->endpoint);
$response = $this->get($this->url, [
'offset' => $offset,
'limit' => $limit
]);
return new AuthnetWebhooksResponse($response);
} | [
"public",
"function",
"getNotificationHistory",
"(",
"$",
"limit",
"=",
"1000",
",",
"$",
"offset",
"=",
"0",
")",
"{",
"$",
"this",
"->",
"endpoint",
"=",
"'notifications'",
";",
"$",
"this",
"->",
"url",
"=",
"sprintf",
"(",
"'%s%s'",
",",
"$",
"this",
"->",
"url",
",",
"$",
"this",
"->",
"endpoint",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"this",
"->",
"url",
",",
"[",
"'offset'",
"=>",
"$",
"offset",
",",
"'limit'",
"=>",
"$",
"limit",
"]",
")",
";",
"return",
"new",
"AuthnetWebhooksResponse",
"(",
"$",
"response",
")",
";",
"}"
]
| Retrieve Notification History
@param integer $limit Default: 1000
@param integer $offset Default: 0
@return \JohnConde\Authnet\AuthnetWebhooksResponse
@throws \JohnConde\Authnet\AuthnetInvalidJsonException
@throws \JohnConde\Authnet\AuthnetCurlException | [
"Retrieve",
"Notification",
"History"
]
| fb871877d978b5571d94163b59d4d1c97395eb8f | https://github.com/stymiee/authnetjson/blob/fb871877d978b5571d94163b59d4d1c97395eb8f/src/authnet/AuthnetWebhooksRequest.php#L211-L220 | train |
stymiee/authnetjson | src/authnet/AuthnetWebhooksRequest.php | AuthnetWebhooksRequest.get | private function get($url, Array $params = []) {
$this->processor->get($url, $params);
return $this->handleResponse();
} | php | private function get($url, Array $params = []) {
$this->processor->get($url, $params);
return $this->handleResponse();
} | [
"private",
"function",
"get",
"(",
"$",
"url",
",",
"Array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"processor",
"->",
"get",
"(",
"$",
"url",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"handleResponse",
"(",
")",
";",
"}"
]
| Make GET request via Curl
@param string $url
@param array $params
@return string
@throws \JohnConde\Authnet\AuthnetCurlException
@codeCoverageIgnore | [
"Make",
"GET",
"request",
"via",
"Curl"
]
| fb871877d978b5571d94163b59d4d1c97395eb8f | https://github.com/stymiee/authnetjson/blob/fb871877d978b5571d94163b59d4d1c97395eb8f/src/authnet/AuthnetWebhooksRequest.php#L256-L259 | train |
stymiee/authnetjson | src/authnet/AuthnetWebhooksRequest.php | AuthnetWebhooksRequest.post | private function post($url, $request) {
$this->processor->post($url, $request);
return $this->handleResponse();
} | php | private function post($url, $request) {
$this->processor->post($url, $request);
return $this->handleResponse();
} | [
"private",
"function",
"post",
"(",
"$",
"url",
",",
"$",
"request",
")",
"{",
"$",
"this",
"->",
"processor",
"->",
"post",
"(",
"$",
"url",
",",
"$",
"request",
")",
";",
"return",
"$",
"this",
"->",
"handleResponse",
"(",
")",
";",
"}"
]
| Make POST request via Curl
@param string $url API endpoint
@param string $request JSON request payload
@return string
@throws \JohnConde\Authnet\AuthnetCurlException
@codeCoverageIgnore | [
"Make",
"POST",
"request",
"via",
"Curl"
]
| fb871877d978b5571d94163b59d4d1c97395eb8f | https://github.com/stymiee/authnetjson/blob/fb871877d978b5571d94163b59d4d1c97395eb8f/src/authnet/AuthnetWebhooksRequest.php#L271-L274 | train |
stymiee/authnetjson | src/authnet/AuthnetWebhooksRequest.php | AuthnetWebhooksRequest.put | private function put($url, $request) {
$this->processor->put($url, $request, true);
return $this->handleResponse();
} | php | private function put($url, $request) {
$this->processor->put($url, $request, true);
return $this->handleResponse();
} | [
"private",
"function",
"put",
"(",
"$",
"url",
",",
"$",
"request",
")",
"{",
"$",
"this",
"->",
"processor",
"->",
"put",
"(",
"$",
"url",
",",
"$",
"request",
",",
"true",
")",
";",
"return",
"$",
"this",
"->",
"handleResponse",
"(",
")",
";",
"}"
]
| Make PUT request via Curl
@param string $url API endpoint
@param string $request JSON request payload
@return string
@throws \JohnConde\Authnet\AuthnetCurlException
@codeCoverageIgnore | [
"Make",
"PUT",
"request",
"via",
"Curl"
]
| fb871877d978b5571d94163b59d4d1c97395eb8f | https://github.com/stymiee/authnetjson/blob/fb871877d978b5571d94163b59d4d1c97395eb8f/src/authnet/AuthnetWebhooksRequest.php#L286-L289 | train |
danielstjules/pho | src/Console/ConsoleOption.php | ConsoleOption.setValue | public function setValue($value)
{
if ($this->acceptsArguments()) {
$this->value = $value;
} else {
$this->value = (boolean) $value;
}
} | php | public function setValue($value)
{
if ($this->acceptsArguments()) {
$this->value = $value;
} else {
$this->value = (boolean) $value;
}
} | [
"public",
"function",
"setValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"acceptsArguments",
"(",
")",
")",
"{",
"$",
"this",
"->",
"value",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"value",
"=",
"(",
"boolean",
")",
"$",
"value",
";",
"}",
"}"
]
| Sets the value of the option. If the option accepts arguments, the
supplied value can be of any type. Otherwise, the value is cast as a
boolean.
@param mixed $value The value to assign to the option | [
"Sets",
"the",
"value",
"of",
"the",
"option",
".",
"If",
"the",
"option",
"accepts",
"arguments",
"the",
"supplied",
"value",
"can",
"be",
"of",
"any",
"type",
".",
"Otherwise",
"the",
"value",
"is",
"cast",
"as",
"a",
"boolean",
"."
]
| 1514be7fc15632bd04ba1c3f0cccc57859c7969f | https://github.com/danielstjules/pho/blob/1514be7fc15632bd04ba1c3f0cccc57859c7969f/src/Console/ConsoleOption.php#L89-L96 | train |
danielstjules/pho | src/Runner/Runner.php | Runner.describe | public function describe($title, \Closure $closure)
{
$previous = $this->current;
$suite = new Suite($title, $closure, $previous);
if ($this->current === $this->root) {
$this->suites[] = $suite;
} else {
$this->current->addSuite($suite);
}
$this->current = $suite;
$suite->getClosure()->__invoke();
$this->current = $previous;
} | php | public function describe($title, \Closure $closure)
{
$previous = $this->current;
$suite = new Suite($title, $closure, $previous);
if ($this->current === $this->root) {
$this->suites[] = $suite;
} else {
$this->current->addSuite($suite);
}
$this->current = $suite;
$suite->getClosure()->__invoke();
$this->current = $previous;
} | [
"public",
"function",
"describe",
"(",
"$",
"title",
",",
"\\",
"Closure",
"$",
"closure",
")",
"{",
"$",
"previous",
"=",
"$",
"this",
"->",
"current",
";",
"$",
"suite",
"=",
"new",
"Suite",
"(",
"$",
"title",
",",
"$",
"closure",
",",
"$",
"previous",
")",
";",
"if",
"(",
"$",
"this",
"->",
"current",
"===",
"$",
"this",
"->",
"root",
")",
"{",
"$",
"this",
"->",
"suites",
"[",
"]",
"=",
"$",
"suite",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"current",
"->",
"addSuite",
"(",
"$",
"suite",
")",
";",
"}",
"$",
"this",
"->",
"current",
"=",
"$",
"suite",
";",
"$",
"suite",
"->",
"getClosure",
"(",
")",
"->",
"__invoke",
"(",
")",
";",
"$",
"this",
"->",
"current",
"=",
"$",
"previous",
";",
"}"
]
| Constructs a test Suite, assigning it the given title and anonymous
function. If it's a child of another suite, a reference to the parent
suite is stored. This is done by tracking the current and previously
defined suites.
@param string $title A title to be associated with the suite
@param \Closure $closure The closure to invoke when the suite is ran | [
"Constructs",
"a",
"test",
"Suite",
"assigning",
"it",
"the",
"given",
"title",
"and",
"anonymous",
"function",
".",
"If",
"it",
"s",
"a",
"child",
"of",
"another",
"suite",
"a",
"reference",
"to",
"the",
"parent",
"suite",
"is",
"stored",
".",
"This",
"is",
"done",
"by",
"tracking",
"the",
"current",
"and",
"previously",
"defined",
"suites",
"."
]
| 1514be7fc15632bd04ba1c3f0cccc57859c7969f | https://github.com/danielstjules/pho/blob/1514be7fc15632bd04ba1c3f0cccc57859c7969f/src/Runner/Runner.php#L61-L75 | train |
danielstjules/pho | src/Runner/Runner.php | Runner.xdescribe | public function xdescribe($title, \Closure $closure)
{
$previous = $this->current;
$suite = new Suite($title, $closure, $previous);
$suite->setPending();
// If current is null, this is the root suite for the file
if ($this->current === null) {
$this->suites[] = $suite;
} else {
$this->current->addSuite($suite);
}
$this->current = $suite;
$suite->getClosure()->__invoke();
$this->current = $previous;
} | php | public function xdescribe($title, \Closure $closure)
{
$previous = $this->current;
$suite = new Suite($title, $closure, $previous);
$suite->setPending();
// If current is null, this is the root suite for the file
if ($this->current === null) {
$this->suites[] = $suite;
} else {
$this->current->addSuite($suite);
}
$this->current = $suite;
$suite->getClosure()->__invoke();
$this->current = $previous;
} | [
"public",
"function",
"xdescribe",
"(",
"$",
"title",
",",
"\\",
"Closure",
"$",
"closure",
")",
"{",
"$",
"previous",
"=",
"$",
"this",
"->",
"current",
";",
"$",
"suite",
"=",
"new",
"Suite",
"(",
"$",
"title",
",",
"$",
"closure",
",",
"$",
"previous",
")",
";",
"$",
"suite",
"->",
"setPending",
"(",
")",
";",
"// If current is null, this is the root suite for the file",
"if",
"(",
"$",
"this",
"->",
"current",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"suites",
"[",
"]",
"=",
"$",
"suite",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"current",
"->",
"addSuite",
"(",
"$",
"suite",
")",
";",
"}",
"$",
"this",
"->",
"current",
"=",
"$",
"suite",
";",
"$",
"suite",
"->",
"getClosure",
"(",
")",
"->",
"__invoke",
"(",
")",
";",
"$",
"this",
"->",
"current",
"=",
"$",
"previous",
";",
"}"
]
| Creates a suite and marks it as pending.
@param string $title A title to be associated with the suite
@param \Closure $closure The closure to invoke when the suite is ran | [
"Creates",
"a",
"suite",
"and",
"marks",
"it",
"as",
"pending",
"."
]
| 1514be7fc15632bd04ba1c3f0cccc57859c7969f | https://github.com/danielstjules/pho/blob/1514be7fc15632bd04ba1c3f0cccc57859c7969f/src/Runner/Runner.php#L83-L99 | train |
danielstjules/pho | src/Runner/Runner.php | Runner.it | public function it($title, \Closure $closure = null)
{
$spec = new Spec($title, $closure, $this->current);
$this->current->addSpec($spec);
} | php | public function it($title, \Closure $closure = null)
{
$spec = new Spec($title, $closure, $this->current);
$this->current->addSpec($spec);
} | [
"public",
"function",
"it",
"(",
"$",
"title",
",",
"\\",
"Closure",
"$",
"closure",
"=",
"null",
")",
"{",
"$",
"spec",
"=",
"new",
"Spec",
"(",
"$",
"title",
",",
"$",
"closure",
",",
"$",
"this",
"->",
"current",
")",
";",
"$",
"this",
"->",
"current",
"->",
"addSpec",
"(",
"$",
"spec",
")",
";",
"}"
]
| Constructs a new Spec, adding it to the list of specs in the current
suite.
@param string $title A title to be associated with the spec
@param \Closure $closure The closure to invoke when the spec is ran | [
"Constructs",
"a",
"new",
"Spec",
"adding",
"it",
"to",
"the",
"list",
"of",
"specs",
"in",
"the",
"current",
"suite",
"."
]
| 1514be7fc15632bd04ba1c3f0cccc57859c7969f | https://github.com/danielstjules/pho/blob/1514be7fc15632bd04ba1c3f0cccc57859c7969f/src/Runner/Runner.php#L108-L112 | train |
danielstjules/pho | src/Runner/Runner.php | Runner.xit | public function xit($title, \Closure $closure = null)
{
$spec = new Spec($title, $closure, $this->current);
$spec->setPending();
$this->current->addSpec($spec);
} | php | public function xit($title, \Closure $closure = null)
{
$spec = new Spec($title, $closure, $this->current);
$spec->setPending();
$this->current->addSpec($spec);
} | [
"public",
"function",
"xit",
"(",
"$",
"title",
",",
"\\",
"Closure",
"$",
"closure",
"=",
"null",
")",
"{",
"$",
"spec",
"=",
"new",
"Spec",
"(",
"$",
"title",
",",
"$",
"closure",
",",
"$",
"this",
"->",
"current",
")",
";",
"$",
"spec",
"->",
"setPending",
"(",
")",
";",
"$",
"this",
"->",
"current",
"->",
"addSpec",
"(",
"$",
"spec",
")",
";",
"}"
]
| Constructs a new Spec, adding it to the list of specs in the current
suite and mark it as pending.
@param string $title A title to be associated with the spec
@param \Closure $closure The closure to invoke when the spec is ran | [
"Constructs",
"a",
"new",
"Spec",
"adding",
"it",
"to",
"the",
"list",
"of",
"specs",
"in",
"the",
"current",
"suite",
"and",
"mark",
"it",
"as",
"pending",
"."
]
| 1514be7fc15632bd04ba1c3f0cccc57859c7969f | https://github.com/danielstjules/pho/blob/1514be7fc15632bd04ba1c3f0cccc57859c7969f/src/Runner/Runner.php#L121-L126 | train |
danielstjules/pho | src/Runner/Runner.php | Runner.before | public function before(\Closure $closure)
{
$key = 'before';
$before = new Hook($key, $closure, $this->current);
$this->current->setHook($key, $before);
} | php | public function before(\Closure $closure)
{
$key = 'before';
$before = new Hook($key, $closure, $this->current);
$this->current->setHook($key, $before);
} | [
"public",
"function",
"before",
"(",
"\\",
"Closure",
"$",
"closure",
")",
"{",
"$",
"key",
"=",
"'before'",
";",
"$",
"before",
"=",
"new",
"Hook",
"(",
"$",
"key",
",",
"$",
"closure",
",",
"$",
"this",
"->",
"current",
")",
";",
"$",
"this",
"->",
"current",
"->",
"setHook",
"(",
"$",
"key",
",",
"$",
"before",
")",
";",
"}"
]
| Constructs a new Hook, defining a closure to be ran prior to the parent
suite's closure.
@param \Closure $closure The closure to be ran before the suite | [
"Constructs",
"a",
"new",
"Hook",
"defining",
"a",
"closure",
"to",
"be",
"ran",
"prior",
"to",
"the",
"parent",
"suite",
"s",
"closure",
"."
]
| 1514be7fc15632bd04ba1c3f0cccc57859c7969f | https://github.com/danielstjules/pho/blob/1514be7fc15632bd04ba1c3f0cccc57859c7969f/src/Runner/Runner.php#L134-L139 | train |
danielstjules/pho | src/Runner/Runner.php | Runner.after | public function after(\Closure $closure)
{
$key = 'after';
$after = new Hook($key, $closure, $this->current);
$this->current->setHook($key, $after);
} | php | public function after(\Closure $closure)
{
$key = 'after';
$after = new Hook($key, $closure, $this->current);
$this->current->setHook($key, $after);
} | [
"public",
"function",
"after",
"(",
"\\",
"Closure",
"$",
"closure",
")",
"{",
"$",
"key",
"=",
"'after'",
";",
"$",
"after",
"=",
"new",
"Hook",
"(",
"$",
"key",
",",
"$",
"closure",
",",
"$",
"this",
"->",
"current",
")",
";",
"$",
"this",
"->",
"current",
"->",
"setHook",
"(",
"$",
"key",
",",
"$",
"after",
")",
";",
"}"
]
| Constructs a new Hook, defining a closure to be ran after the parent
suite's closure.
@param \Closure $closure The closure to be ran after the suite | [
"Constructs",
"a",
"new",
"Hook",
"defining",
"a",
"closure",
"to",
"be",
"ran",
"after",
"the",
"parent",
"suite",
"s",
"closure",
"."
]
| 1514be7fc15632bd04ba1c3f0cccc57859c7969f | https://github.com/danielstjules/pho/blob/1514be7fc15632bd04ba1c3f0cccc57859c7969f/src/Runner/Runner.php#L147-L152 | train |
danielstjules/pho | src/Runner/Runner.php | Runner.watch | public function watch()
{
$watcher = new Watcher();
$watcher->watchPath(getcwd());
$watcher->addListener(function() {
$paths = implode(' ', self::$console->getPaths());
$descriptor = [
0 => ['pipe', 'r'],
1 => ['pipe', 'w']
];
// Rebuild option string, without watch
$optionString = '';
foreach (self::$console->options as $key => $val) {
if ($key == 'watch') {
continue;
} elseif ($val === true) { // test
$optionString .= "--$key ";
} elseif ($val) {
$optionString .= "--$key $val ";
}
}
// Run pho in another process and echo its stdout
$procStr = "{$_SERVER['SCRIPT_FILENAME']} {$optionString} {$paths}";
$process = proc_open($procStr, $descriptor, $pipes);
if (is_resource($process)) {
while ($buffer = fread($pipes[1], 16)) {
self::$console->write($buffer);
}
fclose($pipes[0]);
fclose($pipes[1]);
proc_close($process);
}
});
// Ever vigilant
$watcher->watch();
} | php | public function watch()
{
$watcher = new Watcher();
$watcher->watchPath(getcwd());
$watcher->addListener(function() {
$paths = implode(' ', self::$console->getPaths());
$descriptor = [
0 => ['pipe', 'r'],
1 => ['pipe', 'w']
];
// Rebuild option string, without watch
$optionString = '';
foreach (self::$console->options as $key => $val) {
if ($key == 'watch') {
continue;
} elseif ($val === true) { // test
$optionString .= "--$key ";
} elseif ($val) {
$optionString .= "--$key $val ";
}
}
// Run pho in another process and echo its stdout
$procStr = "{$_SERVER['SCRIPT_FILENAME']} {$optionString} {$paths}";
$process = proc_open($procStr, $descriptor, $pipes);
if (is_resource($process)) {
while ($buffer = fread($pipes[1], 16)) {
self::$console->write($buffer);
}
fclose($pipes[0]);
fclose($pipes[1]);
proc_close($process);
}
});
// Ever vigilant
$watcher->watch();
} | [
"public",
"function",
"watch",
"(",
")",
"{",
"$",
"watcher",
"=",
"new",
"Watcher",
"(",
")",
";",
"$",
"watcher",
"->",
"watchPath",
"(",
"getcwd",
"(",
")",
")",
";",
"$",
"watcher",
"->",
"addListener",
"(",
"function",
"(",
")",
"{",
"$",
"paths",
"=",
"implode",
"(",
"' '",
",",
"self",
"::",
"$",
"console",
"->",
"getPaths",
"(",
")",
")",
";",
"$",
"descriptor",
"=",
"[",
"0",
"=>",
"[",
"'pipe'",
",",
"'r'",
"]",
",",
"1",
"=>",
"[",
"'pipe'",
",",
"'w'",
"]",
"]",
";",
"// Rebuild option string, without watch",
"$",
"optionString",
"=",
"''",
";",
"foreach",
"(",
"self",
"::",
"$",
"console",
"->",
"options",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"key",
"==",
"'watch'",
")",
"{",
"continue",
";",
"}",
"elseif",
"(",
"$",
"val",
"===",
"true",
")",
"{",
"// test",
"$",
"optionString",
".=",
"\"--$key \"",
";",
"}",
"elseif",
"(",
"$",
"val",
")",
"{",
"$",
"optionString",
".=",
"\"--$key $val \"",
";",
"}",
"}",
"// Run pho in another process and echo its stdout",
"$",
"procStr",
"=",
"\"{$_SERVER['SCRIPT_FILENAME']} {$optionString} {$paths}\"",
";",
"$",
"process",
"=",
"proc_open",
"(",
"$",
"procStr",
",",
"$",
"descriptor",
",",
"$",
"pipes",
")",
";",
"if",
"(",
"is_resource",
"(",
"$",
"process",
")",
")",
"{",
"while",
"(",
"$",
"buffer",
"=",
"fread",
"(",
"$",
"pipes",
"[",
"1",
"]",
",",
"16",
")",
")",
"{",
"self",
"::",
"$",
"console",
"->",
"write",
"(",
"$",
"buffer",
")",
";",
"}",
"fclose",
"(",
"$",
"pipes",
"[",
"0",
"]",
")",
";",
"fclose",
"(",
"$",
"pipes",
"[",
"1",
"]",
")",
";",
"proc_close",
"(",
"$",
"process",
")",
";",
"}",
"}",
")",
";",
"// Ever vigilant",
"$",
"watcher",
"->",
"watch",
"(",
")",
";",
"}"
]
| Monitors the the current working directory for modifications, and reruns
the specs in another process on change. | [
"Monitors",
"the",
"the",
"current",
"working",
"directory",
"for",
"modifications",
"and",
"reruns",
"the",
"specs",
"in",
"another",
"process",
"on",
"change",
"."
]
| 1514be7fc15632bd04ba1c3f0cccc57859c7969f | https://github.com/danielstjules/pho/blob/1514be7fc15632bd04ba1c3f0cccc57859c7969f/src/Runner/Runner.php#L206-L247 | train |
danielstjules/pho | src/Runner/Runner.php | Runner.runSuite | private function runSuite(Suite $suite)
{
$this->runRunnable($suite->getHook('before'));
$this->reporter->beforeSuite($suite);
// Run the specs
$this->runSpecs($suite);
// Run nested suites
foreach ($suite->getSuites() as $nestedSuite) {
$this->runSuite($nestedSuite);
}
$this->reporter->afterSuite($suite);
$this->runRunnable($suite->getHook('after'));
} | php | private function runSuite(Suite $suite)
{
$this->runRunnable($suite->getHook('before'));
$this->reporter->beforeSuite($suite);
// Run the specs
$this->runSpecs($suite);
// Run nested suites
foreach ($suite->getSuites() as $nestedSuite) {
$this->runSuite($nestedSuite);
}
$this->reporter->afterSuite($suite);
$this->runRunnable($suite->getHook('after'));
} | [
"private",
"function",
"runSuite",
"(",
"Suite",
"$",
"suite",
")",
"{",
"$",
"this",
"->",
"runRunnable",
"(",
"$",
"suite",
"->",
"getHook",
"(",
"'before'",
")",
")",
";",
"$",
"this",
"->",
"reporter",
"->",
"beforeSuite",
"(",
"$",
"suite",
")",
";",
"// Run the specs",
"$",
"this",
"->",
"runSpecs",
"(",
"$",
"suite",
")",
";",
"// Run nested suites",
"foreach",
"(",
"$",
"suite",
"->",
"getSuites",
"(",
")",
"as",
"$",
"nestedSuite",
")",
"{",
"$",
"this",
"->",
"runSuite",
"(",
"$",
"nestedSuite",
")",
";",
"}",
"$",
"this",
"->",
"reporter",
"->",
"afterSuite",
"(",
"$",
"suite",
")",
";",
"$",
"this",
"->",
"runRunnable",
"(",
"$",
"suite",
"->",
"getHook",
"(",
"'after'",
")",
")",
";",
"}"
]
| Runs a particular suite by running the associated hooks and reporter,
methods, iterating over its child suites and recursively calling itself,
followed by running its specs.
@param Suite $suite The suite to run | [
"Runs",
"a",
"particular",
"suite",
"by",
"running",
"the",
"associated",
"hooks",
"and",
"reporter",
"methods",
"iterating",
"over",
"its",
"child",
"suites",
"and",
"recursively",
"calling",
"itself",
"followed",
"by",
"running",
"its",
"specs",
"."
]
| 1514be7fc15632bd04ba1c3f0cccc57859c7969f | https://github.com/danielstjules/pho/blob/1514be7fc15632bd04ba1c3f0cccc57859c7969f/src/Runner/Runner.php#L256-L271 | train |
danielstjules/pho | src/Runner/Runner.php | Runner.runSpecs | private function runSpecs(Suite $suite)
{
foreach ($suite->getSpecs() as $spec) {
// If using the filter option, only run matching specs
$pattern = self::$console->options['filter'];
if ($pattern && !preg_match($pattern, $spec)) {
continue;
}
$this->reporter->beforeSpec($spec);
$this->runBeforeEachHooks($suite, $spec);
$this->runRunnable($spec);
$this->runAfterEachHooks($suite, $spec);
$this->reporter->afterSpec($spec);
}
} | php | private function runSpecs(Suite $suite)
{
foreach ($suite->getSpecs() as $spec) {
// If using the filter option, only run matching specs
$pattern = self::$console->options['filter'];
if ($pattern && !preg_match($pattern, $spec)) {
continue;
}
$this->reporter->beforeSpec($spec);
$this->runBeforeEachHooks($suite, $spec);
$this->runRunnable($spec);
$this->runAfterEachHooks($suite, $spec);
$this->reporter->afterSpec($spec);
}
} | [
"private",
"function",
"runSpecs",
"(",
"Suite",
"$",
"suite",
")",
"{",
"foreach",
"(",
"$",
"suite",
"->",
"getSpecs",
"(",
")",
"as",
"$",
"spec",
")",
"{",
"// If using the filter option, only run matching specs",
"$",
"pattern",
"=",
"self",
"::",
"$",
"console",
"->",
"options",
"[",
"'filter'",
"]",
";",
"if",
"(",
"$",
"pattern",
"&&",
"!",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"spec",
")",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"reporter",
"->",
"beforeSpec",
"(",
"$",
"spec",
")",
";",
"$",
"this",
"->",
"runBeforeEachHooks",
"(",
"$",
"suite",
",",
"$",
"spec",
")",
";",
"$",
"this",
"->",
"runRunnable",
"(",
"$",
"spec",
")",
";",
"$",
"this",
"->",
"runAfterEachHooks",
"(",
"$",
"suite",
",",
"$",
"spec",
")",
";",
"$",
"this",
"->",
"reporter",
"->",
"afterSpec",
"(",
"$",
"spec",
")",
";",
"}",
"}"
]
| Runs the specs associated with the provided test suite. It iterates over
and runs each spec, calling the reporter's beforeSpec and afterSpec
methods, as well as the suite's beforeEach and aferEach hooks. If the
filter option is used, only specs containing a pattern are ran. And if
the stop flag is used, it quits when an exception or error is thrown.
@param Suite $suite The suite containing the specs to run | [
"Runs",
"the",
"specs",
"associated",
"with",
"the",
"provided",
"test",
"suite",
".",
"It",
"iterates",
"over",
"and",
"runs",
"each",
"spec",
"calling",
"the",
"reporter",
"s",
"beforeSpec",
"and",
"afterSpec",
"methods",
"as",
"well",
"as",
"the",
"suite",
"s",
"beforeEach",
"and",
"aferEach",
"hooks",
".",
"If",
"the",
"filter",
"option",
"is",
"used",
"only",
"specs",
"containing",
"a",
"pattern",
"are",
"ran",
".",
"And",
"if",
"the",
"stop",
"flag",
"is",
"used",
"it",
"quits",
"when",
"an",
"exception",
"or",
"error",
"is",
"thrown",
"."
]
| 1514be7fc15632bd04ba1c3f0cccc57859c7969f | https://github.com/danielstjules/pho/blob/1514be7fc15632bd04ba1c3f0cccc57859c7969f/src/Runner/Runner.php#L282-L299 | train |
danielstjules/pho | src/Runner/Runner.php | Runner.runBeforeEachHooks | private function runBeforeEachHooks(Suite $suite, Spec $spec)
{
if ($suite->getParent()) {
$this->runBeforeEachHooks($suite->getParent(), $spec);
}
$hook = $suite->getHook('beforeEach');
$this->runRunnable($hook);
if (!$spec->getException() && $hook) {
$spec->setException($hook->getException());
}
} | php | private function runBeforeEachHooks(Suite $suite, Spec $spec)
{
if ($suite->getParent()) {
$this->runBeforeEachHooks($suite->getParent(), $spec);
}
$hook = $suite->getHook('beforeEach');
$this->runRunnable($hook);
if (!$spec->getException() && $hook) {
$spec->setException($hook->getException());
}
} | [
"private",
"function",
"runBeforeEachHooks",
"(",
"Suite",
"$",
"suite",
",",
"Spec",
"$",
"spec",
")",
"{",
"if",
"(",
"$",
"suite",
"->",
"getParent",
"(",
")",
")",
"{",
"$",
"this",
"->",
"runBeforeEachHooks",
"(",
"$",
"suite",
"->",
"getParent",
"(",
")",
",",
"$",
"spec",
")",
";",
"}",
"$",
"hook",
"=",
"$",
"suite",
"->",
"getHook",
"(",
"'beforeEach'",
")",
";",
"$",
"this",
"->",
"runRunnable",
"(",
"$",
"hook",
")",
";",
"if",
"(",
"!",
"$",
"spec",
"->",
"getException",
"(",
")",
"&&",
"$",
"hook",
")",
"{",
"$",
"spec",
"->",
"setException",
"(",
"$",
"hook",
"->",
"getException",
"(",
")",
")",
";",
"}",
"}"
]
| Runs the beforeEach hooks of the given suite and its parent suites
recursively. They are ran in the order in which they were defined,
from outer suite to inner suites.
@param Suite $suite The suite with the hooks to run
@param Spec $spec The spec to assign any hook failures | [
"Runs",
"the",
"beforeEach",
"hooks",
"of",
"the",
"given",
"suite",
"and",
"its",
"parent",
"suites",
"recursively",
".",
"They",
"are",
"ran",
"in",
"the",
"order",
"in",
"which",
"they",
"were",
"defined",
"from",
"outer",
"suite",
"to",
"inner",
"suites",
"."
]
| 1514be7fc15632bd04ba1c3f0cccc57859c7969f | https://github.com/danielstjules/pho/blob/1514be7fc15632bd04ba1c3f0cccc57859c7969f/src/Runner/Runner.php#L309-L320 | train |
danielstjules/pho | src/Expectation/Matcher/TypeMatcher.php | TypeMatcher.match | public function match($actual)
{
$this->actual = gettype($actual);
return ($this->actual === $this->expected);
} | php | public function match($actual)
{
$this->actual = gettype($actual);
return ($this->actual === $this->expected);
} | [
"public",
"function",
"match",
"(",
"$",
"actual",
")",
"{",
"$",
"this",
"->",
"actual",
"=",
"gettype",
"(",
"$",
"actual",
")",
";",
"return",
"(",
"$",
"this",
"->",
"actual",
"===",
"$",
"this",
"->",
"expected",
")",
";",
"}"
]
| Compares the type of the passed argument to the expected type. Returns
true if the two values are of the same type, false otherwise.
@param mixed $actual The value to test
@return boolean Whether or not the value has the expected type | [
"Compares",
"the",
"type",
"of",
"the",
"passed",
"argument",
"to",
"the",
"expected",
"type",
".",
"Returns",
"true",
"if",
"the",
"two",
"values",
"are",
"of",
"the",
"same",
"type",
"false",
"otherwise",
"."
]
| 1514be7fc15632bd04ba1c3f0cccc57859c7969f | https://github.com/danielstjules/pho/blob/1514be7fc15632bd04ba1c3f0cccc57859c7969f/src/Expectation/Matcher/TypeMatcher.php#L28-L33 | train |
danielstjules/pho | src/Expectation/Matcher/PrintMatcher.php | PrintMatcher.match | public function match($callable)
{
ob_start();
$callable();
$this->actual = ob_get_contents();
ob_end_clean();
return ($this->actual == $this->expected);
} | php | public function match($callable)
{
ob_start();
$callable();
$this->actual = ob_get_contents();
ob_end_clean();
return ($this->actual == $this->expected);
} | [
"public",
"function",
"match",
"(",
"$",
"callable",
")",
"{",
"ob_start",
"(",
")",
";",
"$",
"callable",
"(",
")",
";",
"$",
"this",
"->",
"actual",
"=",
"ob_get_contents",
"(",
")",
";",
"ob_end_clean",
"(",
")",
";",
"return",
"(",
"$",
"this",
"->",
"actual",
"==",
"$",
"this",
"->",
"expected",
")",
";",
"}"
]
| Compares the output printed by the callable to the expected output.
Returns true if the two strings are equal, false otherwise.
@param callable $callable The function to invoke
@return boolean Whether or not the printed and expected output are equal | [
"Compares",
"the",
"output",
"printed",
"by",
"the",
"callable",
"to",
"the",
"expected",
"output",
".",
"Returns",
"true",
"if",
"the",
"two",
"strings",
"are",
"equal",
"false",
"otherwise",
"."
]
| 1514be7fc15632bd04ba1c3f0cccc57859c7969f | https://github.com/danielstjules/pho/blob/1514be7fc15632bd04ba1c3f0cccc57859c7969f/src/Expectation/Matcher/PrintMatcher.php#L28-L37 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.