id int32 0 241k | repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 |
|---|---|---|---|---|---|---|---|---|---|---|---|
34,900 | mike182uk/cart | src/Cart.php | Cart.save | public function save()
{
$data = serialize($this->toArray());
$this->store->put($this->id, $data);
} | php | public function save()
{
$data = serialize($this->toArray());
$this->store->put($this->id, $data);
} | [
"public",
"function",
"save",
"(",
")",
"{",
"$",
"data",
"=",
"serialize",
"(",
"$",
"this",
"->",
"toArray",
"(",
")",
")",
";",
"$",
"this",
"->",
"store",
"->",
"put",
"(",
"$",
"this",
"->",
"id",
",",
"$",
"data",
")",
";",
"}"
] | Save the cart state. | [
"Save",
"the",
"cart",
"state",
"."
] | 88dadd4b419826336b9a60296264c085d969f77a | https://github.com/mike182uk/cart/blob/88dadd4b419826336b9a60296264c085d969f77a/src/Cart.php#L252-L257 |
34,901 | mike182uk/cart | src/Cart.php | Cart.restore | public function restore()
{
$state = $this->store->get($this->id);
if ($state == '') {
return;
}
$data = @unserialize($state); // suppress unserializable error
$this->restoreCheckType($data);
$this->restoreCheckContents($data);
$this->restoreCheckContentsType($data);
$this->id = $data['id'];
$this->items = [];
foreach ($data['items'] as $itemArr) {
$this->items[] = new CartItem($itemArr);
}
} | php | public function restore()
{
$state = $this->store->get($this->id);
if ($state == '') {
return;
}
$data = @unserialize($state); // suppress unserializable error
$this->restoreCheckType($data);
$this->restoreCheckContents($data);
$this->restoreCheckContentsType($data);
$this->id = $data['id'];
$this->items = [];
foreach ($data['items'] as $itemArr) {
$this->items[] = new CartItem($itemArr);
}
} | [
"public",
"function",
"restore",
"(",
")",
"{",
"$",
"state",
"=",
"$",
"this",
"->",
"store",
"->",
"get",
"(",
"$",
"this",
"->",
"id",
")",
";",
"if",
"(",
"$",
"state",
"==",
"''",
")",
"{",
"return",
";",
"}",
"$",
"data",
"=",
"@",
"unserialize",
"(",
"$",
"state",
")",
";",
"// suppress unserializable error",
"$",
"this",
"->",
"restoreCheckType",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"restoreCheckContents",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"restoreCheckContentsType",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"id",
"=",
"$",
"data",
"[",
"'id'",
"]",
";",
"$",
"this",
"->",
"items",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"[",
"'items'",
"]",
"as",
"$",
"itemArr",
")",
"{",
"$",
"this",
"->",
"items",
"[",
"]",
"=",
"new",
"CartItem",
"(",
"$",
"itemArr",
")",
";",
"}",
"}"
] | Restore the cart from its saved state.
@throws CartRestoreException | [
"Restore",
"the",
"cart",
"from",
"its",
"saved",
"state",
"."
] | 88dadd4b419826336b9a60296264c085d969f77a | https://github.com/mike182uk/cart/blob/88dadd4b419826336b9a60296264c085d969f77a/src/Cart.php#L264-L284 |
34,902 | mike182uk/cart | src/Cart.php | Cart.toArray | public function toArray()
{
return [
'id' => $this->id,
'items' => array_map(function (CartItem $item) {
return $item->toArray();
}, $this->items),
];
} | php | public function toArray()
{
return [
'id' => $this->id,
'items' => array_map(function (CartItem $item) {
return $item->toArray();
}, $this->items),
];
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"return",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"id",
",",
"'items'",
"=>",
"array_map",
"(",
"function",
"(",
"CartItem",
"$",
"item",
")",
"{",
"return",
"$",
"item",
"->",
"toArray",
"(",
")",
";",
"}",
",",
"$",
"this",
"->",
"items",
")",
",",
"]",
";",
"}"
] | Export the cart as an array.
@return array | [
"Export",
"the",
"cart",
"as",
"an",
"array",
"."
] | 88dadd4b419826336b9a60296264c085d969f77a | https://github.com/mike182uk/cart/blob/88dadd4b419826336b9a60296264c085d969f77a/src/Cart.php#L337-L345 |
34,903 | izniburak/php-router | src/Router/RouterRequest.php | RouterRequest.validMethod | public static function validMethod($data, $method)
{
$valid = false;
if (strstr($data, '|')) {
foreach (explode('|', $data) as $value) {
$valid = self::checkMethods($value, $method);
if ($valid) {
break;
}
}
} else {
$valid = self::checkMethods($data, $method);
}
return $valid;
} | php | public static function validMethod($data, $method)
{
$valid = false;
if (strstr($data, '|')) {
foreach (explode('|', $data) as $value) {
$valid = self::checkMethods($value, $method);
if ($valid) {
break;
}
}
} else {
$valid = self::checkMethods($data, $method);
}
return $valid;
} | [
"public",
"static",
"function",
"validMethod",
"(",
"$",
"data",
",",
"$",
"method",
")",
"{",
"$",
"valid",
"=",
"false",
";",
"if",
"(",
"strstr",
"(",
"$",
"data",
",",
"'|'",
")",
")",
"{",
"foreach",
"(",
"explode",
"(",
"'|'",
",",
"$",
"data",
")",
"as",
"$",
"value",
")",
"{",
"$",
"valid",
"=",
"self",
"::",
"checkMethods",
"(",
"$",
"value",
",",
"$",
"method",
")",
";",
"if",
"(",
"$",
"valid",
")",
"{",
"break",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"valid",
"=",
"self",
"::",
"checkMethods",
"(",
"$",
"data",
",",
"$",
"method",
")",
";",
"}",
"return",
"$",
"valid",
";",
"}"
] | Request method validation
@param string $data
@param string $method
@return bool | [
"Request",
"method",
"validation"
] | cc75420df6c0c889123aa0051cbab446c7d79e07 | https://github.com/izniburak/php-router/blob/cc75420df6c0c889123aa0051cbab446c7d79e07/src/Router/RouterRequest.php#L28-L43 |
34,904 | izniburak/php-router | src/Router/RouterRequest.php | RouterRequest.checkMethods | protected static function checkMethods($value, $method)
{
$valid = false;
if ($value === 'AJAX' && self::isAjax() && $value === $method) {
$valid = true;
} elseif ($value === 'AJAXP' && self::isAjax() && $method === 'POST') {
$valid = true;
} elseif (in_array($value, explode('|', self::$validMethods)) && ($value === $method || $value === 'ANY')) {
$valid = true;
}
return $valid;
} | php | protected static function checkMethods($value, $method)
{
$valid = false;
if ($value === 'AJAX' && self::isAjax() && $value === $method) {
$valid = true;
} elseif ($value === 'AJAXP' && self::isAjax() && $method === 'POST') {
$valid = true;
} elseif (in_array($value, explode('|', self::$validMethods)) && ($value === $method || $value === 'ANY')) {
$valid = true;
}
return $valid;
} | [
"protected",
"static",
"function",
"checkMethods",
"(",
"$",
"value",
",",
"$",
"method",
")",
"{",
"$",
"valid",
"=",
"false",
";",
"if",
"(",
"$",
"value",
"===",
"'AJAX'",
"&&",
"self",
"::",
"isAjax",
"(",
")",
"&&",
"$",
"value",
"===",
"$",
"method",
")",
"{",
"$",
"valid",
"=",
"true",
";",
"}",
"elseif",
"(",
"$",
"value",
"===",
"'AJAXP'",
"&&",
"self",
"::",
"isAjax",
"(",
")",
"&&",
"$",
"method",
"===",
"'POST'",
")",
"{",
"$",
"valid",
"=",
"true",
";",
"}",
"elseif",
"(",
"in_array",
"(",
"$",
"value",
",",
"explode",
"(",
"'|'",
",",
"self",
"::",
"$",
"validMethods",
")",
")",
"&&",
"(",
"$",
"value",
"===",
"$",
"method",
"||",
"$",
"value",
"===",
"'ANY'",
")",
")",
"{",
"$",
"valid",
"=",
"true",
";",
"}",
"return",
"$",
"valid",
";",
"}"
] | check method valid
@param string $value
@param string $method
@return bool | [
"check",
"method",
"valid"
] | cc75420df6c0c889123aa0051cbab446c7d79e07 | https://github.com/izniburak/php-router/blob/cc75420df6c0c889123aa0051cbab446c7d79e07/src/Router/RouterRequest.php#L53-L65 |
34,905 | izniburak/php-router | src/Router/RouterCommand.php | RouterCommand.beforeAfter | public function beforeAfter($command, $path = '', $namespace = '')
{
if (! is_null($command)) {
if (is_array($command)) {
foreach ($command as $key => $value) {
$this->beforeAfter($value, $path, $namespace);
}
} elseif (is_string($command)) {
$controller = $this->resolveClass($command, $path, $namespace);
if (method_exists($controller, 'handle')) {
return call_user_func([$controller, 'handle']);
}
return $this->exception('handle() method is not found in <b>'.$command.'</b> class.');
}
}
return;
} | php | public function beforeAfter($command, $path = '', $namespace = '')
{
if (! is_null($command)) {
if (is_array($command)) {
foreach ($command as $key => $value) {
$this->beforeAfter($value, $path, $namespace);
}
} elseif (is_string($command)) {
$controller = $this->resolveClass($command, $path, $namespace);
if (method_exists($controller, 'handle')) {
return call_user_func([$controller, 'handle']);
}
return $this->exception('handle() method is not found in <b>'.$command.'</b> class.');
}
}
return;
} | [
"public",
"function",
"beforeAfter",
"(",
"$",
"command",
",",
"$",
"path",
"=",
"''",
",",
"$",
"namespace",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"command",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"command",
")",
")",
"{",
"foreach",
"(",
"$",
"command",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"beforeAfter",
"(",
"$",
"value",
",",
"$",
"path",
",",
"$",
"namespace",
")",
";",
"}",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"command",
")",
")",
"{",
"$",
"controller",
"=",
"$",
"this",
"->",
"resolveClass",
"(",
"$",
"command",
",",
"$",
"path",
",",
"$",
"namespace",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"controller",
",",
"'handle'",
")",
")",
"{",
"return",
"call_user_func",
"(",
"[",
"$",
"controller",
",",
"'handle'",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"exception",
"(",
"'handle() method is not found in <b>'",
".",
"$",
"command",
".",
"'</b> class.'",
")",
";",
"}",
"}",
"return",
";",
"}"
] | Run Route Middlewares
@param $command
@param $path
@param $namespace
@return mixed|void
@throws | [
"Run",
"Route",
"Middlewares"
] | cc75420df6c0c889123aa0051cbab446c7d79e07 | https://github.com/izniburak/php-router/blob/cc75420df6c0c889123aa0051cbab446c7d79e07/src/Router/RouterCommand.php#L56-L74 |
34,906 | izniburak/php-router | src/Router/RouterCommand.php | RouterCommand.resolveClass | protected function resolveClass($class, $path, $namespace)
{
$file = realpath(rtrim($path, '/') . '/' . $class . '.php');
if (! file_exists($file)) {
return $this->exception($class . ' class is not found. Please, check file.');
}
require_once($file);
$class = $namespace . str_replace('/', '\\', $class);
return new $class();
} | php | protected function resolveClass($class, $path, $namespace)
{
$file = realpath(rtrim($path, '/') . '/' . $class . '.php');
if (! file_exists($file)) {
return $this->exception($class . ' class is not found. Please, check file.');
}
require_once($file);
$class = $namespace . str_replace('/', '\\', $class);
return new $class();
} | [
"protected",
"function",
"resolveClass",
"(",
"$",
"class",
",",
"$",
"path",
",",
"$",
"namespace",
")",
"{",
"$",
"file",
"=",
"realpath",
"(",
"rtrim",
"(",
"$",
"path",
",",
"'/'",
")",
".",
"'/'",
".",
"$",
"class",
".",
"'.php'",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"return",
"$",
"this",
"->",
"exception",
"(",
"$",
"class",
".",
"' class is not found. Please, check file.'",
")",
";",
"}",
"require_once",
"(",
"$",
"file",
")",
";",
"$",
"class",
"=",
"$",
"namespace",
".",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"class",
")",
";",
"return",
"new",
"$",
"class",
"(",
")",
";",
"}"
] | Resolve Controller or Middleware class.
@param $class
@param $path
@param $namespace
@return object
@throws | [
"Resolve",
"Controller",
"or",
"Middleware",
"class",
"."
] | cc75420df6c0c889123aa0051cbab446c7d79e07 | https://github.com/izniburak/php-router/blob/cc75420df6c0c889123aa0051cbab446c7d79e07/src/Router/RouterCommand.php#L124-L135 |
34,907 | izniburak/php-router | src/Router.php | Router.setPaths | protected function setPaths($params)
{
if (isset($params['paths']) && $paths = $params['paths']) {
$this->paths['controllers'] =
isset($paths['controllers'])
? trim($paths['controllers'], '/')
: $this->paths['controllers'];
$this->paths['middlewares'] =
isset($paths['middlewares'])
? trim($paths['middlewares'], '/')
: $this->paths['middlewares'];
}
if (isset($params['namespaces']) && $namespaces = $params['namespaces']) {
$this->namespaces['controllers'] =
isset($namespaces['controllers'])
? trim($namespaces['controllers'], '\\') . '\\'
: '';
$this->namespaces['middlewares'] =
isset($namespaces['middlewares'])
? trim($namespaces['middlewares'], '\\') . '\\'
: '';
}
if (isset($params['base_folder'])) {
$this->baseFolder = rtrim($params['base_folder'], '/');
}
if (isset($params['main_method'])) {
$this->mainMethod = $params['main_method'];
}
if (isset($params['cache'])) {
$this->cacheFile = $params['cache'];
} else {
$this->cacheFile = realpath(__DIR__ . '/../cache.php');
}
} | php | protected function setPaths($params)
{
if (isset($params['paths']) && $paths = $params['paths']) {
$this->paths['controllers'] =
isset($paths['controllers'])
? trim($paths['controllers'], '/')
: $this->paths['controllers'];
$this->paths['middlewares'] =
isset($paths['middlewares'])
? trim($paths['middlewares'], '/')
: $this->paths['middlewares'];
}
if (isset($params['namespaces']) && $namespaces = $params['namespaces']) {
$this->namespaces['controllers'] =
isset($namespaces['controllers'])
? trim($namespaces['controllers'], '\\') . '\\'
: '';
$this->namespaces['middlewares'] =
isset($namespaces['middlewares'])
? trim($namespaces['middlewares'], '\\') . '\\'
: '';
}
if (isset($params['base_folder'])) {
$this->baseFolder = rtrim($params['base_folder'], '/');
}
if (isset($params['main_method'])) {
$this->mainMethod = $params['main_method'];
}
if (isset($params['cache'])) {
$this->cacheFile = $params['cache'];
} else {
$this->cacheFile = realpath(__DIR__ . '/../cache.php');
}
} | [
"protected",
"function",
"setPaths",
"(",
"$",
"params",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'paths'",
"]",
")",
"&&",
"$",
"paths",
"=",
"$",
"params",
"[",
"'paths'",
"]",
")",
"{",
"$",
"this",
"->",
"paths",
"[",
"'controllers'",
"]",
"=",
"isset",
"(",
"$",
"paths",
"[",
"'controllers'",
"]",
")",
"?",
"trim",
"(",
"$",
"paths",
"[",
"'controllers'",
"]",
",",
"'/'",
")",
":",
"$",
"this",
"->",
"paths",
"[",
"'controllers'",
"]",
";",
"$",
"this",
"->",
"paths",
"[",
"'middlewares'",
"]",
"=",
"isset",
"(",
"$",
"paths",
"[",
"'middlewares'",
"]",
")",
"?",
"trim",
"(",
"$",
"paths",
"[",
"'middlewares'",
"]",
",",
"'/'",
")",
":",
"$",
"this",
"->",
"paths",
"[",
"'middlewares'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'namespaces'",
"]",
")",
"&&",
"$",
"namespaces",
"=",
"$",
"params",
"[",
"'namespaces'",
"]",
")",
"{",
"$",
"this",
"->",
"namespaces",
"[",
"'controllers'",
"]",
"=",
"isset",
"(",
"$",
"namespaces",
"[",
"'controllers'",
"]",
")",
"?",
"trim",
"(",
"$",
"namespaces",
"[",
"'controllers'",
"]",
",",
"'\\\\'",
")",
".",
"'\\\\'",
":",
"''",
";",
"$",
"this",
"->",
"namespaces",
"[",
"'middlewares'",
"]",
"=",
"isset",
"(",
"$",
"namespaces",
"[",
"'middlewares'",
"]",
")",
"?",
"trim",
"(",
"$",
"namespaces",
"[",
"'middlewares'",
"]",
",",
"'\\\\'",
")",
".",
"'\\\\'",
":",
"''",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'base_folder'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"baseFolder",
"=",
"rtrim",
"(",
"$",
"params",
"[",
"'base_folder'",
"]",
",",
"'/'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'main_method'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"mainMethod",
"=",
"$",
"params",
"[",
"'main_method'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'cache'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"cacheFile",
"=",
"$",
"params",
"[",
"'cache'",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"cacheFile",
"=",
"realpath",
"(",
"__DIR__",
".",
"'/../cache.php'",
")",
";",
"}",
"}"
] | Set paths and namespaces for Controllers and Middlewares.
@param array $params
@return void | [
"Set",
"paths",
"and",
"namespaces",
"for",
"Controllers",
"and",
"Middlewares",
"."
] | cc75420df6c0c889123aa0051cbab446c7d79e07 | https://github.com/izniburak/php-router/blob/cc75420df6c0c889123aa0051cbab446c7d79e07/src/Router.php#L117-L156 |
34,908 | izniburak/php-router | src/Router.php | Router.add | public function add($methods, $route, $settings, $callback = null)
{
if($this->cacheLoaded) {
return true;
}
if (is_null($callback)) {
$callback = $settings;
$settings = null;
}
if (strstr($methods, '|')) {
foreach (array_unique(explode('|', $methods)) as $method) {
if ($method != '') {
call_user_func_array([$this, strtolower($method)], [$route, $settings, $callback]);
}
}
} else {
call_user_func_array([$this, strtolower($methods)], [$route, $settings, $callback]);
}
return true;
} | php | public function add($methods, $route, $settings, $callback = null)
{
if($this->cacheLoaded) {
return true;
}
if (is_null($callback)) {
$callback = $settings;
$settings = null;
}
if (strstr($methods, '|')) {
foreach (array_unique(explode('|', $methods)) as $method) {
if ($method != '') {
call_user_func_array([$this, strtolower($method)], [$route, $settings, $callback]);
}
}
} else {
call_user_func_array([$this, strtolower($methods)], [$route, $settings, $callback]);
}
return true;
} | [
"public",
"function",
"add",
"(",
"$",
"methods",
",",
"$",
"route",
",",
"$",
"settings",
",",
"$",
"callback",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"cacheLoaded",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"callback",
")",
")",
"{",
"$",
"callback",
"=",
"$",
"settings",
";",
"$",
"settings",
"=",
"null",
";",
"}",
"if",
"(",
"strstr",
"(",
"$",
"methods",
",",
"'|'",
")",
")",
"{",
"foreach",
"(",
"array_unique",
"(",
"explode",
"(",
"'|'",
",",
"$",
"methods",
")",
")",
"as",
"$",
"method",
")",
"{",
"if",
"(",
"$",
"method",
"!=",
"''",
")",
"{",
"call_user_func_array",
"(",
"[",
"$",
"this",
",",
"strtolower",
"(",
"$",
"method",
")",
"]",
",",
"[",
"$",
"route",
",",
"$",
"settings",
",",
"$",
"callback",
"]",
")",
";",
"}",
"}",
"}",
"else",
"{",
"call_user_func_array",
"(",
"[",
"$",
"this",
",",
"strtolower",
"(",
"$",
"methods",
")",
"]",
",",
"[",
"$",
"route",
",",
"$",
"settings",
",",
"$",
"callback",
"]",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Add new route method one or more http methods.
@param string $methods
@param string $route
@param array|string|closure $settings
@param string|closure $callback
@return bool | [
"Add",
"new",
"route",
"method",
"one",
"or",
"more",
"http",
"methods",
"."
] | cc75420df6c0c889123aa0051cbab446c7d79e07 | https://github.com/izniburak/php-router/blob/cc75420df6c0c889123aa0051cbab446c7d79e07/src/Router.php#L229-L251 |
34,909 | izniburak/php-router | src/Router.php | Router.pattern | public function pattern($pattern, $attr = null)
{
if (is_array($pattern)) {
foreach ($pattern as $key => $value) {
if (! in_array('{' . $key . '}', array_keys($this->patterns))) {
$this->patterns['{' . $key . '}'] = '(' . $value . ')';
} else {
return $this->exception($key . ' pattern cannot be changed.');
}
}
} else {
if (! in_array('{' . $pattern . '}', array_keys($this->patterns))) {
$this->patterns['{' . $pattern . '}'] = '(' . $attr . ')';
} else {
return $this->exception($pattern . ' pattern cannot be changed.');
}
}
return true;
} | php | public function pattern($pattern, $attr = null)
{
if (is_array($pattern)) {
foreach ($pattern as $key => $value) {
if (! in_array('{' . $key . '}', array_keys($this->patterns))) {
$this->patterns['{' . $key . '}'] = '(' . $value . ')';
} else {
return $this->exception($key . ' pattern cannot be changed.');
}
}
} else {
if (! in_array('{' . $pattern . '}', array_keys($this->patterns))) {
$this->patterns['{' . $pattern . '}'] = '(' . $attr . ')';
} else {
return $this->exception($pattern . ' pattern cannot be changed.');
}
}
return true;
} | [
"public",
"function",
"pattern",
"(",
"$",
"pattern",
",",
"$",
"attr",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"pattern",
")",
")",
"{",
"foreach",
"(",
"$",
"pattern",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"'{'",
".",
"$",
"key",
".",
"'}'",
",",
"array_keys",
"(",
"$",
"this",
"->",
"patterns",
")",
")",
")",
"{",
"$",
"this",
"->",
"patterns",
"[",
"'{'",
".",
"$",
"key",
".",
"'}'",
"]",
"=",
"'('",
".",
"$",
"value",
".",
"')'",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"exception",
"(",
"$",
"key",
".",
"' pattern cannot be changed.'",
")",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"in_array",
"(",
"'{'",
".",
"$",
"pattern",
".",
"'}'",
",",
"array_keys",
"(",
"$",
"this",
"->",
"patterns",
")",
")",
")",
"{",
"$",
"this",
"->",
"patterns",
"[",
"'{'",
".",
"$",
"pattern",
".",
"'}'",
"]",
"=",
"'('",
".",
"$",
"attr",
".",
"')'",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"exception",
"(",
"$",
"pattern",
".",
"' pattern cannot be changed.'",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Add new route rules pattern; String or Array
@param string|array $pattern
@param null|string $attr
@return mixed
@throws | [
"Add",
"new",
"route",
"rules",
"pattern",
";",
"String",
"or",
"Array"
] | cc75420df6c0c889123aa0051cbab446c7d79e07 | https://github.com/izniburak/php-router/blob/cc75420df6c0c889123aa0051cbab446c7d79e07/src/Router.php#L262-L281 |
34,910 | izniburak/php-router | src/Router.php | Router.controller | public function controller($route, $settings, $controller = null)
{
if($this->cacheLoaded) {
return true;
}
if (is_null($controller)) {
$controller = $settings;
$settings = [];
}
$controller = str_replace(['\\', '.'], '/', $controller);
$controllerFile = realpath(
rtrim($this->paths['controllers'], '/') . '/' . $controller . '.php'
);
if (! file_exists($controllerFile)) {
return $this->exception($controller . ' class is not found!');
}
if (! class_exists($controller)) {
require $controllerFile;
}
$controller = str_replace('/', '\\', $controller);
$classMethods = get_class_methods($this->namespaces['controllers'] . $controller);
if ($classMethods) {
foreach ($classMethods as $methodName) {
if(!strstr($methodName, '__')) {
$method = "any";
foreach(explode('|', RouterRequest::$validMethods) as $m) {
if(stripos($methodName, strtolower($m), 0) === 0) {
$method = strtolower($m);
break;
}
}
$methodVar = lcfirst(str_replace($method, '', $methodName));
$r = new ReflectionMethod($this->namespaces['controllers'] . $controller, $methodName);
$reqiredParam = $r->getNumberOfRequiredParameters();
$totalParam = $r->getNumberOfParameters();
$value = ($methodVar === $this->mainMethod ? $route : $route.'/'.$methodVar);
$this->{$method}(
($value.str_repeat('/{a}', $reqiredParam).str_repeat('/{a?}', $totalParam-$reqiredParam)),
$settings,
($controller . '@' . $methodName)
);
}
}
unset($r);
}
return true;
} | php | public function controller($route, $settings, $controller = null)
{
if($this->cacheLoaded) {
return true;
}
if (is_null($controller)) {
$controller = $settings;
$settings = [];
}
$controller = str_replace(['\\', '.'], '/', $controller);
$controllerFile = realpath(
rtrim($this->paths['controllers'], '/') . '/' . $controller . '.php'
);
if (! file_exists($controllerFile)) {
return $this->exception($controller . ' class is not found!');
}
if (! class_exists($controller)) {
require $controllerFile;
}
$controller = str_replace('/', '\\', $controller);
$classMethods = get_class_methods($this->namespaces['controllers'] . $controller);
if ($classMethods) {
foreach ($classMethods as $methodName) {
if(!strstr($methodName, '__')) {
$method = "any";
foreach(explode('|', RouterRequest::$validMethods) as $m) {
if(stripos($methodName, strtolower($m), 0) === 0) {
$method = strtolower($m);
break;
}
}
$methodVar = lcfirst(str_replace($method, '', $methodName));
$r = new ReflectionMethod($this->namespaces['controllers'] . $controller, $methodName);
$reqiredParam = $r->getNumberOfRequiredParameters();
$totalParam = $r->getNumberOfParameters();
$value = ($methodVar === $this->mainMethod ? $route : $route.'/'.$methodVar);
$this->{$method}(
($value.str_repeat('/{a}', $reqiredParam).str_repeat('/{a?}', $totalParam-$reqiredParam)),
$settings,
($controller . '@' . $methodName)
);
}
}
unset($r);
}
return true;
} | [
"public",
"function",
"controller",
"(",
"$",
"route",
",",
"$",
"settings",
",",
"$",
"controller",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"cacheLoaded",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"controller",
")",
")",
"{",
"$",
"controller",
"=",
"$",
"settings",
";",
"$",
"settings",
"=",
"[",
"]",
";",
"}",
"$",
"controller",
"=",
"str_replace",
"(",
"[",
"'\\\\'",
",",
"'.'",
"]",
",",
"'/'",
",",
"$",
"controller",
")",
";",
"$",
"controllerFile",
"=",
"realpath",
"(",
"rtrim",
"(",
"$",
"this",
"->",
"paths",
"[",
"'controllers'",
"]",
",",
"'/'",
")",
".",
"'/'",
".",
"$",
"controller",
".",
"'.php'",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"controllerFile",
")",
")",
"{",
"return",
"$",
"this",
"->",
"exception",
"(",
"$",
"controller",
".",
"' class is not found!'",
")",
";",
"}",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"controller",
")",
")",
"{",
"require",
"$",
"controllerFile",
";",
"}",
"$",
"controller",
"=",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"controller",
")",
";",
"$",
"classMethods",
"=",
"get_class_methods",
"(",
"$",
"this",
"->",
"namespaces",
"[",
"'controllers'",
"]",
".",
"$",
"controller",
")",
";",
"if",
"(",
"$",
"classMethods",
")",
"{",
"foreach",
"(",
"$",
"classMethods",
"as",
"$",
"methodName",
")",
"{",
"if",
"(",
"!",
"strstr",
"(",
"$",
"methodName",
",",
"'__'",
")",
")",
"{",
"$",
"method",
"=",
"\"any\"",
";",
"foreach",
"(",
"explode",
"(",
"'|'",
",",
"RouterRequest",
"::",
"$",
"validMethods",
")",
"as",
"$",
"m",
")",
"{",
"if",
"(",
"stripos",
"(",
"$",
"methodName",
",",
"strtolower",
"(",
"$",
"m",
")",
",",
"0",
")",
"===",
"0",
")",
"{",
"$",
"method",
"=",
"strtolower",
"(",
"$",
"m",
")",
";",
"break",
";",
"}",
"}",
"$",
"methodVar",
"=",
"lcfirst",
"(",
"str_replace",
"(",
"$",
"method",
",",
"''",
",",
"$",
"methodName",
")",
")",
";",
"$",
"r",
"=",
"new",
"ReflectionMethod",
"(",
"$",
"this",
"->",
"namespaces",
"[",
"'controllers'",
"]",
".",
"$",
"controller",
",",
"$",
"methodName",
")",
";",
"$",
"reqiredParam",
"=",
"$",
"r",
"->",
"getNumberOfRequiredParameters",
"(",
")",
";",
"$",
"totalParam",
"=",
"$",
"r",
"->",
"getNumberOfParameters",
"(",
")",
";",
"$",
"value",
"=",
"(",
"$",
"methodVar",
"===",
"$",
"this",
"->",
"mainMethod",
"?",
"$",
"route",
":",
"$",
"route",
".",
"'/'",
".",
"$",
"methodVar",
")",
";",
"$",
"this",
"->",
"{",
"$",
"method",
"}",
"(",
"(",
"$",
"value",
".",
"str_repeat",
"(",
"'/{a}'",
",",
"$",
"reqiredParam",
")",
".",
"str_repeat",
"(",
"'/{a?}'",
",",
"$",
"totalParam",
"-",
"$",
"reqiredParam",
")",
")",
",",
"$",
"settings",
",",
"(",
"$",
"controller",
".",
"'@'",
".",
"$",
"methodName",
")",
")",
";",
"}",
"}",
"unset",
"(",
"$",
"r",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Added route from methods of Controller file.
@param string $route
@param string|array $settings
@param null|string $controller
@return mixed
@throws | [
"Added",
"route",
"from",
"methods",
"of",
"Controller",
"file",
"."
] | cc75420df6c0c889123aa0051cbab446c7d79e07 | https://github.com/izniburak/php-router/blob/cc75420df6c0c889123aa0051cbab446c7d79e07/src/Router.php#L454-L508 |
34,911 | izniburak/php-router | src/Router.php | Router.addRoute | private function addRoute($uri, $method, $callback, $settings)
{
$groupItem = count($this->groups) - 1;
$group = '';
if ($groupItem > -1) {
foreach ($this->groups as $key => $value) {
$group .= $value['route'];
}
}
$page = dirname($_SERVER['PHP_SELF']);
$page = $page === '/' ? '' : $page;
if (strstr($page, 'index.php')) {
$data = implode('/', explode('/', $page));
$page = str_replace($data, '', $page);
}
$route = $page . $group . '/' . trim($uri, '/');
$route = rtrim($route, '/');
if ($route === $page) {
$route .= '/';
}
$data = [
'route' => str_replace('//', '/', $route),
'method' => strtoupper($method),
'callback' => $callback,
'name' => (isset($settings['name'])
? $settings['name']
: null
),
'before' => (isset($settings['before'])
? $settings['before']
: null
),
'after' => (isset($settings['after'])
? $settings['after']
: null
),
'group' => ($groupItem === -1) ? null : $this->groups[$groupItem]
];
array_push($this->routes, $data);
} | php | private function addRoute($uri, $method, $callback, $settings)
{
$groupItem = count($this->groups) - 1;
$group = '';
if ($groupItem > -1) {
foreach ($this->groups as $key => $value) {
$group .= $value['route'];
}
}
$page = dirname($_SERVER['PHP_SELF']);
$page = $page === '/' ? '' : $page;
if (strstr($page, 'index.php')) {
$data = implode('/', explode('/', $page));
$page = str_replace($data, '', $page);
}
$route = $page . $group . '/' . trim($uri, '/');
$route = rtrim($route, '/');
if ($route === $page) {
$route .= '/';
}
$data = [
'route' => str_replace('//', '/', $route),
'method' => strtoupper($method),
'callback' => $callback,
'name' => (isset($settings['name'])
? $settings['name']
: null
),
'before' => (isset($settings['before'])
? $settings['before']
: null
),
'after' => (isset($settings['after'])
? $settings['after']
: null
),
'group' => ($groupItem === -1) ? null : $this->groups[$groupItem]
];
array_push($this->routes, $data);
} | [
"private",
"function",
"addRoute",
"(",
"$",
"uri",
",",
"$",
"method",
",",
"$",
"callback",
",",
"$",
"settings",
")",
"{",
"$",
"groupItem",
"=",
"count",
"(",
"$",
"this",
"->",
"groups",
")",
"-",
"1",
";",
"$",
"group",
"=",
"''",
";",
"if",
"(",
"$",
"groupItem",
">",
"-",
"1",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"groups",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"group",
".=",
"$",
"value",
"[",
"'route'",
"]",
";",
"}",
"}",
"$",
"page",
"=",
"dirname",
"(",
"$",
"_SERVER",
"[",
"'PHP_SELF'",
"]",
")",
";",
"$",
"page",
"=",
"$",
"page",
"===",
"'/'",
"?",
"''",
":",
"$",
"page",
";",
"if",
"(",
"strstr",
"(",
"$",
"page",
",",
"'index.php'",
")",
")",
"{",
"$",
"data",
"=",
"implode",
"(",
"'/'",
",",
"explode",
"(",
"'/'",
",",
"$",
"page",
")",
")",
";",
"$",
"page",
"=",
"str_replace",
"(",
"$",
"data",
",",
"''",
",",
"$",
"page",
")",
";",
"}",
"$",
"route",
"=",
"$",
"page",
".",
"$",
"group",
".",
"'/'",
".",
"trim",
"(",
"$",
"uri",
",",
"'/'",
")",
";",
"$",
"route",
"=",
"rtrim",
"(",
"$",
"route",
",",
"'/'",
")",
";",
"if",
"(",
"$",
"route",
"===",
"$",
"page",
")",
"{",
"$",
"route",
".=",
"'/'",
";",
"}",
"$",
"data",
"=",
"[",
"'route'",
"=>",
"str_replace",
"(",
"'//'",
",",
"'/'",
",",
"$",
"route",
")",
",",
"'method'",
"=>",
"strtoupper",
"(",
"$",
"method",
")",
",",
"'callback'",
"=>",
"$",
"callback",
",",
"'name'",
"=>",
"(",
"isset",
"(",
"$",
"settings",
"[",
"'name'",
"]",
")",
"?",
"$",
"settings",
"[",
"'name'",
"]",
":",
"null",
")",
",",
"'before'",
"=>",
"(",
"isset",
"(",
"$",
"settings",
"[",
"'before'",
"]",
")",
"?",
"$",
"settings",
"[",
"'before'",
"]",
":",
"null",
")",
",",
"'after'",
"=>",
"(",
"isset",
"(",
"$",
"settings",
"[",
"'after'",
"]",
")",
"?",
"$",
"settings",
"[",
"'after'",
"]",
":",
"null",
")",
",",
"'group'",
"=>",
"(",
"$",
"groupItem",
"===",
"-",
"1",
")",
"?",
"null",
":",
"$",
"this",
"->",
"groups",
"[",
"$",
"groupItem",
"]",
"]",
";",
"array_push",
"(",
"$",
"this",
"->",
"routes",
",",
"$",
"data",
")",
";",
"}"
] | Add new Route and it's settings
@param $uri
@param $method
@param $callback
@param $settings
@return void | [
"Add",
"new",
"Route",
"and",
"it",
"s",
"settings"
] | cc75420df6c0c889123aa0051cbab446c7d79e07 | https://github.com/izniburak/php-router/blob/cc75420df6c0c889123aa0051cbab446c7d79e07/src/Router.php#L532-L574 |
34,912 | izniburak/php-router | src/Router.php | Router.runRouteMiddleware | public function runRouteMiddleware($middleware, $type)
{
$middlewarePath = $this->baseFolder . '/' . $this->paths['middlewares'];
$middlewareNs = $this->namespaces['middlewares'];
if ($type == 'before') {
if (! is_null($middleware['group'])) {
$this->routerCommand()->beforeAfter(
$middleware['group'][$type], $middlewarePath, $middlewareNs
);
}
$this->routerCommand()->beforeAfter(
$middleware[$type], $middlewarePath, $middlewareNs
);
} else {
$this->routerCommand()->beforeAfter(
$middleware[$type], $middlewarePath, $middlewareNs
);
if (! is_null($middleware['group'])) {
$this->routerCommand()->beforeAfter(
$middleware['group'][$type], $middlewarePath, $middlewareNs
);
}
}
} | php | public function runRouteMiddleware($middleware, $type)
{
$middlewarePath = $this->baseFolder . '/' . $this->paths['middlewares'];
$middlewareNs = $this->namespaces['middlewares'];
if ($type == 'before') {
if (! is_null($middleware['group'])) {
$this->routerCommand()->beforeAfter(
$middleware['group'][$type], $middlewarePath, $middlewareNs
);
}
$this->routerCommand()->beforeAfter(
$middleware[$type], $middlewarePath, $middlewareNs
);
} else {
$this->routerCommand()->beforeAfter(
$middleware[$type], $middlewarePath, $middlewareNs
);
if (! is_null($middleware['group'])) {
$this->routerCommand()->beforeAfter(
$middleware['group'][$type], $middlewarePath, $middlewareNs
);
}
}
} | [
"public",
"function",
"runRouteMiddleware",
"(",
"$",
"middleware",
",",
"$",
"type",
")",
"{",
"$",
"middlewarePath",
"=",
"$",
"this",
"->",
"baseFolder",
".",
"'/'",
".",
"$",
"this",
"->",
"paths",
"[",
"'middlewares'",
"]",
";",
"$",
"middlewareNs",
"=",
"$",
"this",
"->",
"namespaces",
"[",
"'middlewares'",
"]",
";",
"if",
"(",
"$",
"type",
"==",
"'before'",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"middleware",
"[",
"'group'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"routerCommand",
"(",
")",
"->",
"beforeAfter",
"(",
"$",
"middleware",
"[",
"'group'",
"]",
"[",
"$",
"type",
"]",
",",
"$",
"middlewarePath",
",",
"$",
"middlewareNs",
")",
";",
"}",
"$",
"this",
"->",
"routerCommand",
"(",
")",
"->",
"beforeAfter",
"(",
"$",
"middleware",
"[",
"$",
"type",
"]",
",",
"$",
"middlewarePath",
",",
"$",
"middlewareNs",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"routerCommand",
"(",
")",
"->",
"beforeAfter",
"(",
"$",
"middleware",
"[",
"$",
"type",
"]",
",",
"$",
"middlewarePath",
",",
"$",
"middlewareNs",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"middleware",
"[",
"'group'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"routerCommand",
"(",
")",
"->",
"beforeAfter",
"(",
"$",
"middleware",
"[",
"'group'",
"]",
"[",
"$",
"type",
"]",
",",
"$",
"middlewarePath",
",",
"$",
"middlewareNs",
")",
";",
"}",
"}",
"}"
] | Detect Routes Middleware; before or after
@param $middleware
@param $type
@return void | [
"Detect",
"Routes",
"Middleware",
";",
"before",
"or",
"after"
] | cc75420df6c0c889123aa0051cbab446c7d79e07 | https://github.com/izniburak/php-router/blob/cc75420df6c0c889123aa0051cbab446c7d79e07/src/Router.php#L601-L624 |
34,913 | izniburak/php-router | src/Router.php | Router.cache | public function cache()
{
foreach($this->getRoutes() as $key => $r) {
if (!is_string($r['callback'])) {
throw new Exception(sprintf('Routes cannot contain a Closure/Function callback while caching.'));
}
}
$cacheContent = '<?php return '.var_export($this->getRoutes(), true).';' . PHP_EOL;
if (false === file_put_contents($this->cacheFile, $cacheContent)) {
throw new Exception(sprintf('Routes cache file could not be written.'));
}
return true;
} | php | public function cache()
{
foreach($this->getRoutes() as $key => $r) {
if (!is_string($r['callback'])) {
throw new Exception(sprintf('Routes cannot contain a Closure/Function callback while caching.'));
}
}
$cacheContent = '<?php return '.var_export($this->getRoutes(), true).';' . PHP_EOL;
if (false === file_put_contents($this->cacheFile, $cacheContent)) {
throw new Exception(sprintf('Routes cache file could not be written.'));
}
return true;
} | [
"public",
"function",
"cache",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getRoutes",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"r",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"r",
"[",
"'callback'",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'Routes cannot contain a Closure/Function callback while caching.'",
")",
")",
";",
"}",
"}",
"$",
"cacheContent",
"=",
"'<?php return '",
".",
"var_export",
"(",
"$",
"this",
"->",
"getRoutes",
"(",
")",
",",
"true",
")",
".",
"';'",
".",
"PHP_EOL",
";",
"if",
"(",
"false",
"===",
"file_put_contents",
"(",
"$",
"this",
"->",
"cacheFile",
",",
"$",
"cacheContent",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'Routes cache file could not be written.'",
")",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Cache all routes
@return bool
@throws Exception | [
"Cache",
"all",
"routes"
] | cc75420df6c0c889123aa0051cbab446c7d79e07 | https://github.com/izniburak/php-router/blob/cc75420df6c0c889123aa0051cbab446c7d79e07/src/Router.php#L688-L702 |
34,914 | izniburak/php-router | src/Router.php | Router.loadCache | protected function loadCache()
{
if (file_exists($this->cacheFile)) {
$this->routes = require $this->cacheFile;
$this->cacheLoaded = true;
return true;
}
return false;
} | php | protected function loadCache()
{
if (file_exists($this->cacheFile)) {
$this->routes = require $this->cacheFile;
$this->cacheLoaded = true;
return true;
}
return false;
} | [
"protected",
"function",
"loadCache",
"(",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"cacheFile",
")",
")",
"{",
"$",
"this",
"->",
"routes",
"=",
"require",
"$",
"this",
"->",
"cacheFile",
";",
"$",
"this",
"->",
"cacheLoaded",
"=",
"true",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Load Cache file
@return bool | [
"Load",
"Cache",
"file"
] | cc75420df6c0c889123aa0051cbab446c7d79e07 | https://github.com/izniburak/php-router/blob/cc75420df6c0c889123aa0051cbab446c7d79e07/src/Router.php#L709-L718 |
34,915 | Litecms/Block | src/Block.php | Block.count | public function count($module)
{
if (User::hasRole('user')) {
$this->block->pushCriteria(new \Litecms\Block\Repositories\Criteria\BlockUserCriteria());
}
if ($module == 'block') {
return $this->block
->scopeQuery(function ($query) {
return $query;
})
->count();
}
if ($module == 'category') {
return $this->category
->scopeQuery(function ($query) {
return $query;
})->count();
}
if ($module == 'public') {
return $this->block
->pushCriteria(new \Litecms\Block\Repositories\Criteria\BlockPublicCriteria())
->scopeQuery(function ($query) {
return $query;
})->count();
}
} | php | public function count($module)
{
if (User::hasRole('user')) {
$this->block->pushCriteria(new \Litecms\Block\Repositories\Criteria\BlockUserCriteria());
}
if ($module == 'block') {
return $this->block
->scopeQuery(function ($query) {
return $query;
})
->count();
}
if ($module == 'category') {
return $this->category
->scopeQuery(function ($query) {
return $query;
})->count();
}
if ($module == 'public') {
return $this->block
->pushCriteria(new \Litecms\Block\Repositories\Criteria\BlockPublicCriteria())
->scopeQuery(function ($query) {
return $query;
})->count();
}
} | [
"public",
"function",
"count",
"(",
"$",
"module",
")",
"{",
"if",
"(",
"User",
"::",
"hasRole",
"(",
"'user'",
")",
")",
"{",
"$",
"this",
"->",
"block",
"->",
"pushCriteria",
"(",
"new",
"\\",
"Litecms",
"\\",
"Block",
"\\",
"Repositories",
"\\",
"Criteria",
"\\",
"BlockUserCriteria",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"module",
"==",
"'block'",
")",
"{",
"return",
"$",
"this",
"->",
"block",
"->",
"scopeQuery",
"(",
"function",
"(",
"$",
"query",
")",
"{",
"return",
"$",
"query",
";",
"}",
")",
"->",
"count",
"(",
")",
";",
"}",
"if",
"(",
"$",
"module",
"==",
"'category'",
")",
"{",
"return",
"$",
"this",
"->",
"category",
"->",
"scopeQuery",
"(",
"function",
"(",
"$",
"query",
")",
"{",
"return",
"$",
"query",
";",
"}",
")",
"->",
"count",
"(",
")",
";",
"}",
"if",
"(",
"$",
"module",
"==",
"'public'",
")",
"{",
"return",
"$",
"this",
"->",
"block",
"->",
"pushCriteria",
"(",
"new",
"\\",
"Litecms",
"\\",
"Block",
"\\",
"Repositories",
"\\",
"Criteria",
"\\",
"BlockPublicCriteria",
"(",
")",
")",
"->",
"scopeQuery",
"(",
"function",
"(",
"$",
"query",
")",
"{",
"return",
"$",
"query",
";",
"}",
")",
"->",
"count",
"(",
")",
";",
"}",
"}"
] | Returns count of blog or category.
@param array $filter
@return int | [
"Returns",
"count",
"of",
"blog",
"or",
"category",
"."
] | 79b6abff0180a2fabeb3574e883972ddd44daaa6 | https://github.com/Litecms/Block/blob/79b6abff0180a2fabeb3574e883972ddd44daaa6/src/Block.php#L34-L64 |
34,916 | Litecms/Block | src/Block.php | Block.selectCategories | public function selectCategories()
{
$temp = [];
$category = $this->category->scopeQuery(function ($query) {
return $query->whereStatus('Show')->orderBy('name', 'ASC');
})->all();
foreach ($category as $key => $value) {
$temp[$value->id] = ucfirst($value->name);
}
return $temp;
} | php | public function selectCategories()
{
$temp = [];
$category = $this->category->scopeQuery(function ($query) {
return $query->whereStatus('Show')->orderBy('name', 'ASC');
})->all();
foreach ($category as $key => $value) {
$temp[$value->id] = ucfirst($value->name);
}
return $temp;
} | [
"public",
"function",
"selectCategories",
"(",
")",
"{",
"$",
"temp",
"=",
"[",
"]",
";",
"$",
"category",
"=",
"$",
"this",
"->",
"category",
"->",
"scopeQuery",
"(",
"function",
"(",
"$",
"query",
")",
"{",
"return",
"$",
"query",
"->",
"whereStatus",
"(",
"'Show'",
")",
"->",
"orderBy",
"(",
"'name'",
",",
"'ASC'",
")",
";",
"}",
")",
"->",
"all",
"(",
")",
";",
"foreach",
"(",
"$",
"category",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"temp",
"[",
"$",
"value",
"->",
"id",
"]",
"=",
"ucfirst",
"(",
"$",
"value",
"->",
"name",
")",
";",
"}",
"return",
"$",
"temp",
";",
"}"
] | take block category
@return array | [
"take",
"block",
"category"
] | 79b6abff0180a2fabeb3574e883972ddd44daaa6 | https://github.com/Litecms/Block/blob/79b6abff0180a2fabeb3574e883972ddd44daaa6/src/Block.php#L71-L83 |
34,917 | Litecms/Block | src/Block.php | Block.display | public function display($category)
{
$view = (View::exists("block::{$category}")) ? "block::{$category}" : "block::default";
$category = $this->category
->scopeQuery(function ($query) use ($category) {
return $query->with('blocks')->whereSlug($category);
})->first();
$blocks = $category->blocks;
return view($view, compact('blocks', 'category'))->render();
} | php | public function display($category)
{
$view = (View::exists("block::{$category}")) ? "block::{$category}" : "block::default";
$category = $this->category
->scopeQuery(function ($query) use ($category) {
return $query->with('blocks')->whereSlug($category);
})->first();
$blocks = $category->blocks;
return view($view, compact('blocks', 'category'))->render();
} | [
"public",
"function",
"display",
"(",
"$",
"category",
")",
"{",
"$",
"view",
"=",
"(",
"View",
"::",
"exists",
"(",
"\"block::{$category}\"",
")",
")",
"?",
"\"block::{$category}\"",
":",
"\"block::default\"",
";",
"$",
"category",
"=",
"$",
"this",
"->",
"category",
"->",
"scopeQuery",
"(",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"category",
")",
"{",
"return",
"$",
"query",
"->",
"with",
"(",
"'blocks'",
")",
"->",
"whereSlug",
"(",
"$",
"category",
")",
";",
"}",
")",
"->",
"first",
"(",
")",
";",
"$",
"blocks",
"=",
"$",
"category",
"->",
"blocks",
";",
"return",
"view",
"(",
"$",
"view",
",",
"compact",
"(",
"'blocks'",
",",
"'category'",
")",
")",
"->",
"render",
"(",
")",
";",
"}"
] | take latest blocks for public side
@param type $count
@param type|string $view
@return type | [
"take",
"latest",
"blocks",
"for",
"public",
"side"
] | 79b6abff0180a2fabeb3574e883972ddd44daaa6 | https://github.com/Litecms/Block/blob/79b6abff0180a2fabeb3574e883972ddd44daaa6/src/Block.php#L92-L104 |
34,918 | Litecms/Block | src/Http/Controllers/CategoryResourceController.php | CategoryResourceController.show | public function show(CategoryRequest $request, Category $category)
{
if ($category->exists) {
$view = 'block::admin.category.show';
} else {
$view = 'block::admin.category.new';
}
return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('block::category.name'))
->data(compact('category'))
->view($view)
->output();
} | php | public function show(CategoryRequest $request, Category $category)
{
if ($category->exists) {
$view = 'block::admin.category.show';
} else {
$view = 'block::admin.category.new';
}
return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('block::category.name'))
->data(compact('category'))
->view($view)
->output();
} | [
"public",
"function",
"show",
"(",
"CategoryRequest",
"$",
"request",
",",
"Category",
"$",
"category",
")",
"{",
"if",
"(",
"$",
"category",
"->",
"exists",
")",
"{",
"$",
"view",
"=",
"'block::admin.category.show'",
";",
"}",
"else",
"{",
"$",
"view",
"=",
"'block::admin.category.new'",
";",
"}",
"return",
"$",
"this",
"->",
"response",
"->",
"setMetaTitle",
"(",
"trans",
"(",
"'app.view'",
")",
".",
"' '",
".",
"trans",
"(",
"'block::category.name'",
")",
")",
"->",
"data",
"(",
"compact",
"(",
"'category'",
")",
")",
"->",
"view",
"(",
"$",
"view",
")",
"->",
"output",
"(",
")",
";",
"}"
] | Display category.
@param Request $request
@param Model $category
@return Response | [
"Display",
"category",
"."
] | 79b6abff0180a2fabeb3574e883972ddd44daaa6 | https://github.com/Litecms/Block/blob/79b6abff0180a2fabeb3574e883972ddd44daaa6/src/Http/Controllers/CategoryResourceController.php#L66-L79 |
34,919 | Litecms/Block | src/Policies/CategoryPolicy.php | CategoryPolicy.view | public function view(User $user, Category $category)
{
if ($user->canDo('block.category.view') && $user->isAdmin()) {
return true;
}
return $user->id == $category->user_id;
} | php | public function view(User $user, Category $category)
{
if ($user->canDo('block.category.view') && $user->isAdmin()) {
return true;
}
return $user->id == $category->user_id;
} | [
"public",
"function",
"view",
"(",
"User",
"$",
"user",
",",
"Category",
"$",
"category",
")",
"{",
"if",
"(",
"$",
"user",
"->",
"canDo",
"(",
"'block.category.view'",
")",
"&&",
"$",
"user",
"->",
"isAdmin",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"$",
"user",
"->",
"id",
"==",
"$",
"category",
"->",
"user_id",
";",
"}"
] | Determine if the given user can view the category.
@param User $user
@param Category $category
@return bool | [
"Determine",
"if",
"the",
"given",
"user",
"can",
"view",
"the",
"category",
"."
] | 79b6abff0180a2fabeb3574e883972ddd44daaa6 | https://github.com/Litecms/Block/blob/79b6abff0180a2fabeb3574e883972ddd44daaa6/src/Policies/CategoryPolicy.php#L21-L29 |
34,920 | Litecms/Block | src/Http/Controllers/BlockResourceController.php | BlockResourceController.index | public function index(BlockRequest $request)
{
if ($this->response->typeIs('json')) {
$pageLimit = $request->input('pageLimit');
$data = $this->repository
->setPresenter(\Litecms\Block\Repositories\Presenter\BlockListPresenter::class)
->getDataTable($pageLimit);
return $this->response
->data($data)
->output();
}
$blocks = $this->repository->paginate();
return $this->response->setMetaTitle(trans('block::block.names'))
->view('block::admin.block.index')
->data(compact('blocks'))
->output();
} | php | public function index(BlockRequest $request)
{
if ($this->response->typeIs('json')) {
$pageLimit = $request->input('pageLimit');
$data = $this->repository
->setPresenter(\Litecms\Block\Repositories\Presenter\BlockListPresenter::class)
->getDataTable($pageLimit);
return $this->response
->data($data)
->output();
}
$blocks = $this->repository->paginate();
return $this->response->setMetaTitle(trans('block::block.names'))
->view('block::admin.block.index')
->data(compact('blocks'))
->output();
} | [
"public",
"function",
"index",
"(",
"BlockRequest",
"$",
"request",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"response",
"->",
"typeIs",
"(",
"'json'",
")",
")",
"{",
"$",
"pageLimit",
"=",
"$",
"request",
"->",
"input",
"(",
"'pageLimit'",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"repository",
"->",
"setPresenter",
"(",
"\\",
"Litecms",
"\\",
"Block",
"\\",
"Repositories",
"\\",
"Presenter",
"\\",
"BlockListPresenter",
"::",
"class",
")",
"->",
"getDataTable",
"(",
"$",
"pageLimit",
")",
";",
"return",
"$",
"this",
"->",
"response",
"->",
"data",
"(",
"$",
"data",
")",
"->",
"output",
"(",
")",
";",
"}",
"$",
"blocks",
"=",
"$",
"this",
"->",
"repository",
"->",
"paginate",
"(",
")",
";",
"return",
"$",
"this",
"->",
"response",
"->",
"setMetaTitle",
"(",
"trans",
"(",
"'block::block.names'",
")",
")",
"->",
"view",
"(",
"'block::admin.block.index'",
")",
"->",
"data",
"(",
"compact",
"(",
"'blocks'",
")",
")",
"->",
"output",
"(",
")",
";",
"}"
] | Display a list of block.
@return Response | [
"Display",
"a",
"list",
"of",
"block",
"."
] | 79b6abff0180a2fabeb3574e883972ddd44daaa6 | https://github.com/Litecms/Block/blob/79b6abff0180a2fabeb3574e883972ddd44daaa6/src/Http/Controllers/BlockResourceController.php#L37-L56 |
34,921 | Litecms/Block | src/Http/Controllers/BlockResourceController.php | BlockResourceController.show | public function show(BlockRequest $request, Block $block)
{
if ($block->exists) {
$view = 'block::admin.block.show';
} else {
$view = 'block::admin.block.new';
}
return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('block::block.name'))
->data(compact('block'))
->view($view)
->output();
} | php | public function show(BlockRequest $request, Block $block)
{
if ($block->exists) {
$view = 'block::admin.block.show';
} else {
$view = 'block::admin.block.new';
}
return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('block::block.name'))
->data(compact('block'))
->view($view)
->output();
} | [
"public",
"function",
"show",
"(",
"BlockRequest",
"$",
"request",
",",
"Block",
"$",
"block",
")",
"{",
"if",
"(",
"$",
"block",
"->",
"exists",
")",
"{",
"$",
"view",
"=",
"'block::admin.block.show'",
";",
"}",
"else",
"{",
"$",
"view",
"=",
"'block::admin.block.new'",
";",
"}",
"return",
"$",
"this",
"->",
"response",
"->",
"setMetaTitle",
"(",
"trans",
"(",
"'app.view'",
")",
".",
"' '",
".",
"trans",
"(",
"'block::block.name'",
")",
")",
"->",
"data",
"(",
"compact",
"(",
"'block'",
")",
")",
"->",
"view",
"(",
"$",
"view",
")",
"->",
"output",
"(",
")",
";",
"}"
] | Display block.
@param Request $request
@param Model $block
@return Response | [
"Display",
"block",
"."
] | 79b6abff0180a2fabeb3574e883972ddd44daaa6 | https://github.com/Litecms/Block/blob/79b6abff0180a2fabeb3574e883972ddd44daaa6/src/Http/Controllers/BlockResourceController.php#L66-L79 |
34,922 | Litecms/Block | src/Http/Controllers/BlockResourceController.php | BlockResourceController.create | public function create(BlockRequest $request)
{
$block = $this->repository->newInstance([]);
return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('block::block.name'))
->view('block::admin.block.create')
->data(compact('block'))
->output();
} | php | public function create(BlockRequest $request)
{
$block = $this->repository->newInstance([]);
return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('block::block.name'))
->view('block::admin.block.create')
->data(compact('block'))
->output();
} | [
"public",
"function",
"create",
"(",
"BlockRequest",
"$",
"request",
")",
"{",
"$",
"block",
"=",
"$",
"this",
"->",
"repository",
"->",
"newInstance",
"(",
"[",
"]",
")",
";",
"return",
"$",
"this",
"->",
"response",
"->",
"setMetaTitle",
"(",
"trans",
"(",
"'app.new'",
")",
".",
"' '",
".",
"trans",
"(",
"'block::block.name'",
")",
")",
"->",
"view",
"(",
"'block::admin.block.create'",
")",
"->",
"data",
"(",
"compact",
"(",
"'block'",
")",
")",
"->",
"output",
"(",
")",
";",
"}"
] | Show the form for creating a new block.
@param Request $request
@return Response | [
"Show",
"the",
"form",
"for",
"creating",
"a",
"new",
"block",
"."
] | 79b6abff0180a2fabeb3574e883972ddd44daaa6 | https://github.com/Litecms/Block/blob/79b6abff0180a2fabeb3574e883972ddd44daaa6/src/Http/Controllers/BlockResourceController.php#L88-L96 |
34,923 | Litecms/Block | src/Http/Controllers/BlockResourceController.php | BlockResourceController.edit | public function edit(BlockRequest $request, Block $block)
{
return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('block::block.name'))
->view('block::admin.block.edit')
->data(compact('block'))
->output();
} | php | public function edit(BlockRequest $request, Block $block)
{
return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('block::block.name'))
->view('block::admin.block.edit')
->data(compact('block'))
->output();
} | [
"public",
"function",
"edit",
"(",
"BlockRequest",
"$",
"request",
",",
"Block",
"$",
"block",
")",
"{",
"return",
"$",
"this",
"->",
"response",
"->",
"setMetaTitle",
"(",
"trans",
"(",
"'app.edit'",
")",
".",
"' '",
".",
"trans",
"(",
"'block::block.name'",
")",
")",
"->",
"view",
"(",
"'block::admin.block.edit'",
")",
"->",
"data",
"(",
"compact",
"(",
"'block'",
")",
")",
"->",
"output",
"(",
")",
";",
"}"
] | Show block for editing.
@param Request $request
@param Model $block
@return Response | [
"Show",
"block",
"for",
"editing",
"."
] | 79b6abff0180a2fabeb3574e883972ddd44daaa6 | https://github.com/Litecms/Block/blob/79b6abff0180a2fabeb3574e883972ddd44daaa6/src/Http/Controllers/BlockResourceController.php#L136-L142 |
34,924 | Litecms/Block | src/Http/Controllers/BlockResourceController.php | BlockResourceController.update | public function update(BlockRequest $request, Block $block)
{
try {
$attributes = $request->all();
$block->update($attributes);
return $this->response->message(trans('messages.success.updated', ['Module' => trans('block::block.name')]))
->code(204)
->status('success')
->url(guard_url('block/block/' . $block->getRouteKey()))
->redirect();
} catch (Exception $e) {
return $this->response->message($e->getMessage())
->code(400)
->status('error')
->url(guard_url('block/block/' . $block->getRouteKey()))
->redirect();
}
} | php | public function update(BlockRequest $request, Block $block)
{
try {
$attributes = $request->all();
$block->update($attributes);
return $this->response->message(trans('messages.success.updated', ['Module' => trans('block::block.name')]))
->code(204)
->status('success')
->url(guard_url('block/block/' . $block->getRouteKey()))
->redirect();
} catch (Exception $e) {
return $this->response->message($e->getMessage())
->code(400)
->status('error')
->url(guard_url('block/block/' . $block->getRouteKey()))
->redirect();
}
} | [
"public",
"function",
"update",
"(",
"BlockRequest",
"$",
"request",
",",
"Block",
"$",
"block",
")",
"{",
"try",
"{",
"$",
"attributes",
"=",
"$",
"request",
"->",
"all",
"(",
")",
";",
"$",
"block",
"->",
"update",
"(",
"$",
"attributes",
")",
";",
"return",
"$",
"this",
"->",
"response",
"->",
"message",
"(",
"trans",
"(",
"'messages.success.updated'",
",",
"[",
"'Module'",
"=>",
"trans",
"(",
"'block::block.name'",
")",
"]",
")",
")",
"->",
"code",
"(",
"204",
")",
"->",
"status",
"(",
"'success'",
")",
"->",
"url",
"(",
"guard_url",
"(",
"'block/block/'",
".",
"$",
"block",
"->",
"getRouteKey",
"(",
")",
")",
")",
"->",
"redirect",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"$",
"this",
"->",
"response",
"->",
"message",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
"->",
"code",
"(",
"400",
")",
"->",
"status",
"(",
"'error'",
")",
"->",
"url",
"(",
"guard_url",
"(",
"'block/block/'",
".",
"$",
"block",
"->",
"getRouteKey",
"(",
")",
")",
")",
"->",
"redirect",
"(",
")",
";",
"}",
"}"
] | Update the block.
@param Request $request
@param Model $block
@return Response | [
"Update",
"the",
"block",
"."
] | 79b6abff0180a2fabeb3574e883972ddd44daaa6 | https://github.com/Litecms/Block/blob/79b6abff0180a2fabeb3574e883972ddd44daaa6/src/Http/Controllers/BlockResourceController.php#L152-L171 |
34,925 | Litecms/Block | src/Http/Controllers/BlockResourceController.php | BlockResourceController.destroy | public function destroy(BlockRequest $request, Block $block)
{
try {
$block->delete();
return $this->response->message(trans('messages.success.deleted', ['Module' => trans('block::block.name')]))
->code(202)
->status('success')
->url(guard_url('block/block'))
->redirect();
} catch (Exception $e) {
return $this->response->message($e->getMessage())
->code(400)
->status('error')
->url(guard_url('block/block/' . $block->getRouteKey()))
->redirect();
}
} | php | public function destroy(BlockRequest $request, Block $block)
{
try {
$block->delete();
return $this->response->message(trans('messages.success.deleted', ['Module' => trans('block::block.name')]))
->code(202)
->status('success')
->url(guard_url('block/block'))
->redirect();
} catch (Exception $e) {
return $this->response->message($e->getMessage())
->code(400)
->status('error')
->url(guard_url('block/block/' . $block->getRouteKey()))
->redirect();
}
} | [
"public",
"function",
"destroy",
"(",
"BlockRequest",
"$",
"request",
",",
"Block",
"$",
"block",
")",
"{",
"try",
"{",
"$",
"block",
"->",
"delete",
"(",
")",
";",
"return",
"$",
"this",
"->",
"response",
"->",
"message",
"(",
"trans",
"(",
"'messages.success.deleted'",
",",
"[",
"'Module'",
"=>",
"trans",
"(",
"'block::block.name'",
")",
"]",
")",
")",
"->",
"code",
"(",
"202",
")",
"->",
"status",
"(",
"'success'",
")",
"->",
"url",
"(",
"guard_url",
"(",
"'block/block'",
")",
")",
"->",
"redirect",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"$",
"this",
"->",
"response",
"->",
"message",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
"->",
"code",
"(",
"400",
")",
"->",
"status",
"(",
"'error'",
")",
"->",
"url",
"(",
"guard_url",
"(",
"'block/block/'",
".",
"$",
"block",
"->",
"getRouteKey",
"(",
")",
")",
")",
"->",
"redirect",
"(",
")",
";",
"}",
"}"
] | Remove the block.
@param Model $block
@return Response | [
"Remove",
"the",
"block",
"."
] | 79b6abff0180a2fabeb3574e883972ddd44daaa6 | https://github.com/Litecms/Block/blob/79b6abff0180a2fabeb3574e883972ddd44daaa6/src/Http/Controllers/BlockResourceController.php#L180-L200 |
34,926 | Litecms/Block | src/Policies/BlockPolicy.php | BlockPolicy.update | public function update(User $user, Block $block)
{
if ($user->canDo('block.block.update') && $user->isAdmin()) {
return true;
}
return $user->id == $block->user_id;
} | php | public function update(User $user, Block $block)
{
if ($user->canDo('block.block.update') && $user->isAdmin()) {
return true;
}
return $user->id == $block->user_id;
} | [
"public",
"function",
"update",
"(",
"User",
"$",
"user",
",",
"Block",
"$",
"block",
")",
"{",
"if",
"(",
"$",
"user",
"->",
"canDo",
"(",
"'block.block.update'",
")",
"&&",
"$",
"user",
"->",
"isAdmin",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"$",
"user",
"->",
"id",
"==",
"$",
"block",
"->",
"user_id",
";",
"}"
] | Determine if the given user can update the given block.
@param User $user
@param Block $block
@return bool | [
"Determine",
"if",
"the",
"given",
"user",
"can",
"update",
"the",
"given",
"block",
"."
] | 79b6abff0180a2fabeb3574e883972ddd44daaa6 | https://github.com/Litecms/Block/blob/79b6abff0180a2fabeb3574e883972ddd44daaa6/src/Policies/BlockPolicy.php#L52-L60 |
34,927 | spatie/7to5 | src/NodeVisitors/AnonymousClassReplacer.php | AnonymousClassReplacer.getAnonymousClassHookIndex | protected function getAnonymousClassHookIndex(array $statements)
{
$hookIndex = false;
foreach ($statements as $index => $statement) {
if (!$statement instanceof Declare_ &&
!$statement instanceof Use_ &&
!$statement instanceof Namespace_) {
$hookIndex = $index;
}
}
if ($hookIndex === false) {
throw InvalidPhpCode::noValidLocationFoundToInsertClasses();
}
return $hookIndex;
} | php | protected function getAnonymousClassHookIndex(array $statements)
{
$hookIndex = false;
foreach ($statements as $index => $statement) {
if (!$statement instanceof Declare_ &&
!$statement instanceof Use_ &&
!$statement instanceof Namespace_) {
$hookIndex = $index;
}
}
if ($hookIndex === false) {
throw InvalidPhpCode::noValidLocationFoundToInsertClasses();
}
return $hookIndex;
} | [
"protected",
"function",
"getAnonymousClassHookIndex",
"(",
"array",
"$",
"statements",
")",
"{",
"$",
"hookIndex",
"=",
"false",
";",
"foreach",
"(",
"$",
"statements",
"as",
"$",
"index",
"=>",
"$",
"statement",
")",
"{",
"if",
"(",
"!",
"$",
"statement",
"instanceof",
"Declare_",
"&&",
"!",
"$",
"statement",
"instanceof",
"Use_",
"&&",
"!",
"$",
"statement",
"instanceof",
"Namespace_",
")",
"{",
"$",
"hookIndex",
"=",
"$",
"index",
";",
"}",
"}",
"if",
"(",
"$",
"hookIndex",
"===",
"false",
")",
"{",
"throw",
"InvalidPhpCode",
"::",
"noValidLocationFoundToInsertClasses",
"(",
")",
";",
"}",
"return",
"$",
"hookIndex",
";",
"}"
] | Find the index of the first statement that is not a declare, use or namespace statement.
@param array $statements
@return int
@throws \Spatie\Php7to5\Exceptions\InvalidPhpCode | [
"Find",
"the",
"index",
"of",
"the",
"first",
"statement",
"that",
"is",
"not",
"a",
"declare",
"use",
"or",
"namespace",
"statement",
"."
] | 64d1e12570eb3e4ce4976245ba48e881383b5580 | https://github.com/spatie/7to5/blob/64d1e12570eb3e4ce4976245ba48e881383b5580/src/NodeVisitors/AnonymousClassReplacer.php#L79-L96 |
34,928 | rairlie/laravel-locking-session | src/Rairlie/LockingSession/LockingSessionServiceProvider.php | LockingSessionServiceProvider.register | public function register()
{
$this->registerSessionManager();
$this->registerSessionDriver();
$this->app->singleton('Illuminate\Session\Middleware\StartSession', function ($app) {
return new Middleware\StartSession($app->make('session'));
});
} | php | public function register()
{
$this->registerSessionManager();
$this->registerSessionDriver();
$this->app->singleton('Illuminate\Session\Middleware\StartSession', function ($app) {
return new Middleware\StartSession($app->make('session'));
});
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"registerSessionManager",
"(",
")",
";",
"$",
"this",
"->",
"registerSessionDriver",
"(",
")",
";",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'Illuminate\\Session\\Middleware\\StartSession'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"Middleware",
"\\",
"StartSession",
"(",
"$",
"app",
"->",
"make",
"(",
"'session'",
")",
")",
";",
"}",
")",
";",
"}"
] | Override so we return our own Middleware\StartSession
@return void | [
"Override",
"so",
"we",
"return",
"our",
"own",
"Middleware",
"\\",
"StartSession"
] | 93a623a7eacbcab6ef29b4f036ec35d7383d7395 | https://github.com/rairlie/laravel-locking-session/blob/93a623a7eacbcab6ef29b4f036ec35d7383d7395/src/Rairlie/LockingSession/LockingSessionServiceProvider.php#L14-L23 |
34,929 | rairlie/laravel-locking-session | src/Rairlie/LockingSession/Lock.php | Lock.acquire | public function acquire()
{
if ($this->lockfp) {
$this->log("acquire - existing lock");
return;
}
$this->openLockFile();
$this->log("acquire - try lock");
flock($this->lockfp, LOCK_EX);
$this->log("acquire - got lock");
} | php | public function acquire()
{
if ($this->lockfp) {
$this->log("acquire - existing lock");
return;
}
$this->openLockFile();
$this->log("acquire - try lock");
flock($this->lockfp, LOCK_EX);
$this->log("acquire - got lock");
} | [
"public",
"function",
"acquire",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"lockfp",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"\"acquire - existing lock\"",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"openLockFile",
"(",
")",
";",
"$",
"this",
"->",
"log",
"(",
"\"acquire - try lock\"",
")",
";",
"flock",
"(",
"$",
"this",
"->",
"lockfp",
",",
"LOCK_EX",
")",
";",
"$",
"this",
"->",
"log",
"(",
"\"acquire - got lock\"",
")",
";",
"}"
] | Acquire an exclusive lock. Will block if locked by another process. | [
"Acquire",
"an",
"exclusive",
"lock",
".",
"Will",
"block",
"if",
"locked",
"by",
"another",
"process",
"."
] | 93a623a7eacbcab6ef29b4f036ec35d7383d7395 | https://github.com/rairlie/laravel-locking-session/blob/93a623a7eacbcab6ef29b4f036ec35d7383d7395/src/Rairlie/LockingSession/Lock.php#L46-L57 |
34,930 | rairlie/laravel-locking-session | src/Rairlie/LockingSession/Lock.php | Lock.release | public function release()
{
if (!$this->lockfp) {
throw new UnderflowException("No lock to release");
}
$this->log("release");
flock($this->lockfp, LOCK_UN);
$this->closeLockFile();
} | php | public function release()
{
if (!$this->lockfp) {
throw new UnderflowException("No lock to release");
}
$this->log("release");
flock($this->lockfp, LOCK_UN);
$this->closeLockFile();
} | [
"public",
"function",
"release",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"lockfp",
")",
"{",
"throw",
"new",
"UnderflowException",
"(",
"\"No lock to release\"",
")",
";",
"}",
"$",
"this",
"->",
"log",
"(",
"\"release\"",
")",
";",
"flock",
"(",
"$",
"this",
"->",
"lockfp",
",",
"LOCK_UN",
")",
";",
"$",
"this",
"->",
"closeLockFile",
"(",
")",
";",
"}"
] | Release an acquired lock | [
"Release",
"an",
"acquired",
"lock"
] | 93a623a7eacbcab6ef29b4f036ec35d7383d7395 | https://github.com/rairlie/laravel-locking-session/blob/93a623a7eacbcab6ef29b4f036ec35d7383d7395/src/Rairlie/LockingSession/Lock.php#L62-L71 |
34,931 | rairlie/laravel-locking-session | src/Rairlie/LockingSession/Lock.php | Lock.openLockFile | protected function openLockFile()
{
if (!is_dir(dirname($this->lockfilePath))) {
// Suppress warning on mkdir - may be created by another process
@mkdir(dirname($this->lockfilePath), 0744, true);
}
$this->lockfp = fopen($this->lockfilePath, 'w+');
} | php | protected function openLockFile()
{
if (!is_dir(dirname($this->lockfilePath))) {
// Suppress warning on mkdir - may be created by another process
@mkdir(dirname($this->lockfilePath), 0744, true);
}
$this->lockfp = fopen($this->lockfilePath, 'w+');
} | [
"protected",
"function",
"openLockFile",
"(",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"dirname",
"(",
"$",
"this",
"->",
"lockfilePath",
")",
")",
")",
"{",
"// Suppress warning on mkdir - may be created by another process",
"@",
"mkdir",
"(",
"dirname",
"(",
"$",
"this",
"->",
"lockfilePath",
")",
",",
"0744",
",",
"true",
")",
";",
"}",
"$",
"this",
"->",
"lockfp",
"=",
"fopen",
"(",
"$",
"this",
"->",
"lockfilePath",
",",
"'w+'",
")",
";",
"}"
] | Open the lock file on disk, creating it if it doesn't exist | [
"Open",
"the",
"lock",
"file",
"on",
"disk",
"creating",
"it",
"if",
"it",
"doesn",
"t",
"exist"
] | 93a623a7eacbcab6ef29b4f036ec35d7383d7395 | https://github.com/rairlie/laravel-locking-session/blob/93a623a7eacbcab6ef29b4f036ec35d7383d7395/src/Rairlie/LockingSession/Lock.php#L95-L102 |
34,932 | rairlie/laravel-locking-session | src/Rairlie/LockingSession/Lock.php | Lock.log | protected function log($message)
{
$this->debug && Log::info($this->lockfilePath . ' ' . getmypid() . ' ' . $message);
} | php | protected function log($message)
{
$this->debug && Log::info($this->lockfilePath . ' ' . getmypid() . ' ' . $message);
} | [
"protected",
"function",
"log",
"(",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"debug",
"&&",
"Log",
"::",
"info",
"(",
"$",
"this",
"->",
"lockfilePath",
".",
"' '",
".",
"getmypid",
"(",
")",
".",
"' '",
".",
"$",
"message",
")",
";",
"}"
] | Log a debug diagnostic message, if enabled | [
"Log",
"a",
"debug",
"diagnostic",
"message",
"if",
"enabled"
] | 93a623a7eacbcab6ef29b4f036ec35d7383d7395 | https://github.com/rairlie/laravel-locking-session/blob/93a623a7eacbcab6ef29b4f036ec35d7383d7395/src/Rairlie/LockingSession/Lock.php#L118-L121 |
34,933 | LUSHDigital/microservice-core | src/Pagination/Response.php | Response.snakeFormat | public function snakeFormat()
{
$snake = new \stdClass;
$rawValues = get_object_vars($this);
foreach ($rawValues as $property => $value){
$snake->{Str::snake($property)} = $value;
}
return $snake;
} | php | public function snakeFormat()
{
$snake = new \stdClass;
$rawValues = get_object_vars($this);
foreach ($rawValues as $property => $value){
$snake->{Str::snake($property)} = $value;
}
return $snake;
} | [
"public",
"function",
"snakeFormat",
"(",
")",
"{",
"$",
"snake",
"=",
"new",
"\\",
"stdClass",
";",
"$",
"rawValues",
"=",
"get_object_vars",
"(",
"$",
"this",
")",
";",
"foreach",
"(",
"$",
"rawValues",
"as",
"$",
"property",
"=>",
"$",
"value",
")",
"{",
"$",
"snake",
"->",
"{",
"Str",
"::",
"snake",
"(",
"$",
"property",
")",
"}",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"snake",
";",
"}"
] | Format the response object with snake case properties.
@return \stdClass | [
"Format",
"the",
"response",
"object",
"with",
"snake",
"case",
"properties",
"."
] | 8455b7c0d53f2d06bcbfd2854191bf0da1f263f5 | https://github.com/LUSHDigital/microservice-core/blob/8455b7c0d53f2d06bcbfd2854191bf0da1f263f5/src/Pagination/Response.php#L209-L219 |
34,934 | LUSHDigital/microservice-core | src/Helpers/MicroServiceHelper.php | MicroServiceHelper.jsonResponseFormatter | public static function jsonResponseFormatter($type, $data, $code = 200, $status = Status::OK, $message = '')
{
// Validate the arguments.
if ($status == Status::OK && empty($type)) {
throw new Exception('Cannot prepare response. No type specified');
}
else {
$type = preg_replace('/[^A-Za-z]/si', '_', strtolower($type));
}
// Ensure the data is in an array.
if (is_object($data)) {
$data = [(array) $data];
}
// Prepare the response object.
$response = new stdClass();
$response->status = $status;
$response->code = $code;
$response->message = $message;
// Return data in an array.
if (!empty($data)) {
$response->data = new stdClass();
$response->data->{$type} = $data;
} elseif (!empty($type)) {
// Return an empty array even if there are no data.
$response->data = new stdClass();
$response->data->{$type} = [];
}
return $response;
} | php | public static function jsonResponseFormatter($type, $data, $code = 200, $status = Status::OK, $message = '')
{
// Validate the arguments.
if ($status == Status::OK && empty($type)) {
throw new Exception('Cannot prepare response. No type specified');
}
else {
$type = preg_replace('/[^A-Za-z]/si', '_', strtolower($type));
}
// Ensure the data is in an array.
if (is_object($data)) {
$data = [(array) $data];
}
// Prepare the response object.
$response = new stdClass();
$response->status = $status;
$response->code = $code;
$response->message = $message;
// Return data in an array.
if (!empty($data)) {
$response->data = new stdClass();
$response->data->{$type} = $data;
} elseif (!empty($type)) {
// Return an empty array even if there are no data.
$response->data = new stdClass();
$response->data->{$type} = [];
}
return $response;
} | [
"public",
"static",
"function",
"jsonResponseFormatter",
"(",
"$",
"type",
",",
"$",
"data",
",",
"$",
"code",
"=",
"200",
",",
"$",
"status",
"=",
"Status",
"::",
"OK",
",",
"$",
"message",
"=",
"''",
")",
"{",
"// Validate the arguments.",
"if",
"(",
"$",
"status",
"==",
"Status",
"::",
"OK",
"&&",
"empty",
"(",
"$",
"type",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Cannot prepare response. No type specified'",
")",
";",
"}",
"else",
"{",
"$",
"type",
"=",
"preg_replace",
"(",
"'/[^A-Za-z]/si'",
",",
"'_'",
",",
"strtolower",
"(",
"$",
"type",
")",
")",
";",
"}",
"// Ensure the data is in an array.",
"if",
"(",
"is_object",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"[",
"(",
"array",
")",
"$",
"data",
"]",
";",
"}",
"// Prepare the response object.",
"$",
"response",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"response",
"->",
"status",
"=",
"$",
"status",
";",
"$",
"response",
"->",
"code",
"=",
"$",
"code",
";",
"$",
"response",
"->",
"message",
"=",
"$",
"message",
";",
"// Return data in an array.",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"$",
"response",
"->",
"data",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"response",
"->",
"data",
"->",
"{",
"$",
"type",
"}",
"=",
"$",
"data",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"type",
")",
")",
"{",
"// Return an empty array even if there are no data.",
"$",
"response",
"->",
"data",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"response",
"->",
"data",
"->",
"{",
"$",
"type",
"}",
"=",
"[",
"]",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Prepare a response an endpoint.
This ensures that all API endpoints return data in a standardised format:
{
"status": "ok", - Can contain any string. Usually 'ok', 'error' etc.
"code": 200, - A HTTP status code.
"message": "", - A message string elaborating on the status.
"data": {[ - A collection of return data. Can be omitted in the event
]} an error occurred.
}
@param string $type
The type of data being returned. Will be used to name the collection.
@param object|array|NULL $data
The data to return. Will always be parsed into a collection.
@param int $code
HTTP status code for the response.
@param string $status
A short status message. Examples: 'OK', 'Bad Request', 'Not Found'.
@param string $message
A more detailed status message.
@return object
The formatted response object.
@throws Exception | [
"Prepare",
"a",
"response",
"an",
"endpoint",
"."
] | 8455b7c0d53f2d06bcbfd2854191bf0da1f263f5 | https://github.com/LUSHDigital/microservice-core/blob/8455b7c0d53f2d06bcbfd2854191bf0da1f263f5/src/Helpers/MicroServiceHelper.php#L64-L96 |
34,935 | LUSHDigital/microservice-core | src/Traits/MicroServiceStringTrait.php | MicroServiceStringTrait.padTrim | protected function padTrim($input, $pad = '0', $length = 3, $mode = STR_PAD_LEFT)
{
// Make sure we have a string.
if (!is_string($input)) {
$input = (string) $input;
}
return substr(str_pad($input, $length, $pad, $mode), 0, $length);
} | php | protected function padTrim($input, $pad = '0', $length = 3, $mode = STR_PAD_LEFT)
{
// Make sure we have a string.
if (!is_string($input)) {
$input = (string) $input;
}
return substr(str_pad($input, $length, $pad, $mode), 0, $length);
} | [
"protected",
"function",
"padTrim",
"(",
"$",
"input",
",",
"$",
"pad",
"=",
"'0'",
",",
"$",
"length",
"=",
"3",
",",
"$",
"mode",
"=",
"STR_PAD_LEFT",
")",
"{",
"// Make sure we have a string.",
"if",
"(",
"!",
"is_string",
"(",
"$",
"input",
")",
")",
"{",
"$",
"input",
"=",
"(",
"string",
")",
"$",
"input",
";",
"}",
"return",
"substr",
"(",
"str_pad",
"(",
"$",
"input",
",",
"$",
"length",
",",
"$",
"pad",
",",
"$",
"mode",
")",
",",
"0",
",",
"$",
"length",
")",
";",
"}"
] | Trim a string to the specified length. Padding if necessary.
@param string $input
The input string.
@param string $pad
The padding character.
@param int $length
The length of string we want.
@param int $mode
The string padding mode.
@return string | [
"Trim",
"a",
"string",
"to",
"the",
"specified",
"length",
".",
"Padding",
"if",
"necessary",
"."
] | 8455b7c0d53f2d06bcbfd2854191bf0da1f263f5 | https://github.com/LUSHDigital/microservice-core/blob/8455b7c0d53f2d06bcbfd2854191bf0da1f263f5/src/Traits/MicroServiceStringTrait.php#L30-L38 |
34,936 | LUSHDigital/microservice-core | src/Traits/MicroServiceJsonResponseTrait.php | MicroServiceJsonResponseTrait.generateResponse | protected function generateResponse($type, $data, $code = 200, $status = Status::OK, $message = '')
{
if ($code == 204) {
return response('', 204);
}
$returnData = MicroServiceHelper::jsonResponseFormatter($type, $data, $code, $status, $message);
return response()->json($returnData, $code);
} | php | protected function generateResponse($type, $data, $code = 200, $status = Status::OK, $message = '')
{
if ($code == 204) {
return response('', 204);
}
$returnData = MicroServiceHelper::jsonResponseFormatter($type, $data, $code, $status, $message);
return response()->json($returnData, $code);
} | [
"protected",
"function",
"generateResponse",
"(",
"$",
"type",
",",
"$",
"data",
",",
"$",
"code",
"=",
"200",
",",
"$",
"status",
"=",
"Status",
"::",
"OK",
",",
"$",
"message",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"code",
"==",
"204",
")",
"{",
"return",
"response",
"(",
"''",
",",
"204",
")",
";",
"}",
"$",
"returnData",
"=",
"MicroServiceHelper",
"::",
"jsonResponseFormatter",
"(",
"$",
"type",
",",
"$",
"data",
",",
"$",
"code",
",",
"$",
"status",
",",
"$",
"message",
")",
";",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"$",
"returnData",
",",
"$",
"code",
")",
";",
"}"
] | Generate a response object in the microservices expected format.
@param string $type
The type of data being returned. Will be used to name the collection.
@param object|array|NULL $data
The data to return. Will always be parsed into a collection.
@param int $code
HTTP status code for the response.
@param string $status
A short status message. Examples: 'OK', 'Bad Request', 'Not Found'.
@param string $message
A more detailed status message.
@return \Illuminate\Http\Response | [
"Generate",
"a",
"response",
"object",
"in",
"the",
"microservices",
"expected",
"format",
"."
] | 8455b7c0d53f2d06bcbfd2854191bf0da1f263f5 | https://github.com/LUSHDigital/microservice-core/blob/8455b7c0d53f2d06bcbfd2854191bf0da1f263f5/src/Traits/MicroServiceJsonResponseTrait.php#L36-L43 |
34,937 | LUSHDigital/microservice-core | src/Traits/MicroServiceJsonResponseTrait.php | MicroServiceJsonResponseTrait.generatePaginatedResponse | protected function generatePaginatedResponse(Paginator $paginator, $type, $data, $code = 200, $status = Status::OK, $message = '')
{
$returnData = MicroServiceHelper::jsonResponseFormatter($type, $data, $code, $status, $message);
// Append the pagination response to the data.
$returnData->pagination = $paginator->preparePaginationResponse()->snakeFormat();
return response()->json($returnData, $code);
} | php | protected function generatePaginatedResponse(Paginator $paginator, $type, $data, $code = 200, $status = Status::OK, $message = '')
{
$returnData = MicroServiceHelper::jsonResponseFormatter($type, $data, $code, $status, $message);
// Append the pagination response to the data.
$returnData->pagination = $paginator->preparePaginationResponse()->snakeFormat();
return response()->json($returnData, $code);
} | [
"protected",
"function",
"generatePaginatedResponse",
"(",
"Paginator",
"$",
"paginator",
",",
"$",
"type",
",",
"$",
"data",
",",
"$",
"code",
"=",
"200",
",",
"$",
"status",
"=",
"Status",
"::",
"OK",
",",
"$",
"message",
"=",
"''",
")",
"{",
"$",
"returnData",
"=",
"MicroServiceHelper",
"::",
"jsonResponseFormatter",
"(",
"$",
"type",
",",
"$",
"data",
",",
"$",
"code",
",",
"$",
"status",
",",
"$",
"message",
")",
";",
"// Append the pagination response to the data.",
"$",
"returnData",
"->",
"pagination",
"=",
"$",
"paginator",
"->",
"preparePaginationResponse",
"(",
")",
"->",
"snakeFormat",
"(",
")",
";",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"$",
"returnData",
",",
"$",
"code",
")",
";",
"}"
] | Generate a paginated response object in the microservices expected format.
@param Paginator $paginator
A paginator for the data being returned.
@param string $type
The type of data being returned. Will be used to name the collection.
@param object|array|NULL $data
The data to return. Will always be parsed into a collection.
@param int $code
HTTP status code for the response.
@param string $status
A short status message. Examples: 'OK', 'Bad Request', 'Not Found'.
@param string $message
A more detailed status message.
@return \Illuminate\Http\Response | [
"Generate",
"a",
"paginated",
"response",
"object",
"in",
"the",
"microservices",
"expected",
"format",
"."
] | 8455b7c0d53f2d06bcbfd2854191bf0da1f263f5 | https://github.com/LUSHDigital/microservice-core/blob/8455b7c0d53f2d06bcbfd2854191bf0da1f263f5/src/Traits/MicroServiceJsonResponseTrait.php#L63-L71 |
34,938 | LUSHDigital/microservice-core | src/Traits/MicroServiceExceptionHandlerTrait.php | MicroServiceExceptionHandlerTrait.isMicroServiceException | public function isMicroServiceException(Exception $e)
{
foreach ($this->microServicesExceptionTypes as $exceptionType) {
if ($e instanceof $exceptionType) {
return true;
}
}
return false;
} | php | public function isMicroServiceException(Exception $e)
{
foreach ($this->microServicesExceptionTypes as $exceptionType) {
if ($e instanceof $exceptionType) {
return true;
}
}
return false;
} | [
"public",
"function",
"isMicroServiceException",
"(",
"Exception",
"$",
"e",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"microServicesExceptionTypes",
"as",
"$",
"exceptionType",
")",
"{",
"if",
"(",
"$",
"e",
"instanceof",
"$",
"exceptionType",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Check if the supplied exception is of any of the types we handle.
@param Exception $e
@return bool | [
"Check",
"if",
"the",
"supplied",
"exception",
"is",
"of",
"any",
"of",
"the",
"types",
"we",
"handle",
"."
] | 8455b7c0d53f2d06bcbfd2854191bf0da1f263f5 | https://github.com/LUSHDigital/microservice-core/blob/8455b7c0d53f2d06bcbfd2854191bf0da1f263f5/src/Traits/MicroServiceExceptionHandlerTrait.php#L42-L51 |
34,939 | LUSHDigital/microservice-core | src/Traits/MicroServiceExceptionHandlerTrait.php | MicroServiceExceptionHandlerTrait.handleMicroServiceException | public function handleMicroServiceException(Exception $e)
{
// Determine the status code and message to return.
if ($e instanceof HttpException) {
return $this->handleHttpException($e);
} elseif ($e instanceof ModelNotFoundException) {
return $this->handleModelNotFoundException($e);
} elseif ($e instanceof ValidationException) {
return $this->handleValidationException($e);
} else {
return $this->handleGenericException($e);
}
} | php | public function handleMicroServiceException(Exception $e)
{
// Determine the status code and message to return.
if ($e instanceof HttpException) {
return $this->handleHttpException($e);
} elseif ($e instanceof ModelNotFoundException) {
return $this->handleModelNotFoundException($e);
} elseif ($e instanceof ValidationException) {
return $this->handleValidationException($e);
} else {
return $this->handleGenericException($e);
}
} | [
"public",
"function",
"handleMicroServiceException",
"(",
"Exception",
"$",
"e",
")",
"{",
"// Determine the status code and message to return.",
"if",
"(",
"$",
"e",
"instanceof",
"HttpException",
")",
"{",
"return",
"$",
"this",
"->",
"handleHttpException",
"(",
"$",
"e",
")",
";",
"}",
"elseif",
"(",
"$",
"e",
"instanceof",
"ModelNotFoundException",
")",
"{",
"return",
"$",
"this",
"->",
"handleModelNotFoundException",
"(",
"$",
"e",
")",
";",
"}",
"elseif",
"(",
"$",
"e",
"instanceof",
"ValidationException",
")",
"{",
"return",
"$",
"this",
"->",
"handleValidationException",
"(",
"$",
"e",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"handleGenericException",
"(",
"$",
"e",
")",
";",
"}",
"}"
] | Handle the exception and produce a valid JSON response.
@param Exception $e
@return \Illuminate\Http\JsonResponse | [
"Handle",
"the",
"exception",
"and",
"produce",
"a",
"valid",
"JSON",
"response",
"."
] | 8455b7c0d53f2d06bcbfd2854191bf0da1f263f5 | https://github.com/LUSHDigital/microservice-core/blob/8455b7c0d53f2d06bcbfd2854191bf0da1f263f5/src/Traits/MicroServiceExceptionHandlerTrait.php#L59-L71 |
34,940 | LUSHDigital/microservice-core | src/Traits/MicroServiceExceptionHandlerTrait.php | MicroServiceExceptionHandlerTrait.handleHttpException | protected function handleHttpException(Exception $e)
{
$statusCode = $e->getStatusCode();
// if there is no exception message just get the standard HTTP text.
if (empty($e->getMessage())) {
$message = Response::$statusTexts[$statusCode];
} else {
$message = $e->getMessage();
}
return $this->generateResponse('', null, $statusCode, Status::FAIL, $message);
} | php | protected function handleHttpException(Exception $e)
{
$statusCode = $e->getStatusCode();
// if there is no exception message just get the standard HTTP text.
if (empty($e->getMessage())) {
$message = Response::$statusTexts[$statusCode];
} else {
$message = $e->getMessage();
}
return $this->generateResponse('', null, $statusCode, Status::FAIL, $message);
} | [
"protected",
"function",
"handleHttpException",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"statusCode",
"=",
"$",
"e",
"->",
"getStatusCode",
"(",
")",
";",
"// if there is no exception message just get the standard HTTP text.",
"if",
"(",
"empty",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
")",
"{",
"$",
"message",
"=",
"Response",
"::",
"$",
"statusTexts",
"[",
"$",
"statusCode",
"]",
";",
"}",
"else",
"{",
"$",
"message",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"generateResponse",
"(",
"''",
",",
"null",
",",
"$",
"statusCode",
",",
"Status",
"::",
"FAIL",
",",
"$",
"message",
")",
";",
"}"
] | Handle a HTTP exception and build return data.
@param Exception $e
@return mixed | [
"Handle",
"a",
"HTTP",
"exception",
"and",
"build",
"return",
"data",
"."
] | 8455b7c0d53f2d06bcbfd2854191bf0da1f263f5 | https://github.com/LUSHDigital/microservice-core/blob/8455b7c0d53f2d06bcbfd2854191bf0da1f263f5/src/Traits/MicroServiceExceptionHandlerTrait.php#L79-L91 |
34,941 | LUSHDigital/microservice-core | src/Traits/MicroServiceExceptionHandlerTrait.php | MicroServiceExceptionHandlerTrait.handleModelNotFoundException | protected function handleModelNotFoundException(Exception $e)
{
// Get the status code and build the message.
$statusCode = 404;
$reflection = new \ReflectionClass($e->getModel());
$message = $reflection->getShortName() . ' not found';
return $this->generateResponse('', null, $statusCode, Status::FAIL, $message);
} | php | protected function handleModelNotFoundException(Exception $e)
{
// Get the status code and build the message.
$statusCode = 404;
$reflection = new \ReflectionClass($e->getModel());
$message = $reflection->getShortName() . ' not found';
return $this->generateResponse('', null, $statusCode, Status::FAIL, $message);
} | [
"protected",
"function",
"handleModelNotFoundException",
"(",
"Exception",
"$",
"e",
")",
"{",
"// Get the status code and build the message.",
"$",
"statusCode",
"=",
"404",
";",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"e",
"->",
"getModel",
"(",
")",
")",
";",
"$",
"message",
"=",
"$",
"reflection",
"->",
"getShortName",
"(",
")",
".",
"' not found'",
";",
"return",
"$",
"this",
"->",
"generateResponse",
"(",
"''",
",",
"null",
",",
"$",
"statusCode",
",",
"Status",
"::",
"FAIL",
",",
"$",
"message",
")",
";",
"}"
] | Handle a model not found exception and build return data.
@param Exception $e
@return mixed | [
"Handle",
"a",
"model",
"not",
"found",
"exception",
"and",
"build",
"return",
"data",
"."
] | 8455b7c0d53f2d06bcbfd2854191bf0da1f263f5 | https://github.com/LUSHDigital/microservice-core/blob/8455b7c0d53f2d06bcbfd2854191bf0da1f263f5/src/Traits/MicroServiceExceptionHandlerTrait.php#L99-L107 |
34,942 | LUSHDigital/microservice-core | src/Traits/MicroServiceExceptionHandlerTrait.php | MicroServiceExceptionHandlerTrait.handleValidationException | protected function handleValidationException(Exception $e)
{
// Get the status code and build the message.
$statusCode = 422;
$message = $e->getMessage();
$errorData = $e->getResponse()->getData();
return $this->generateResponse('errors', $errorData, $statusCode, Status::FAIL, $message);
} | php | protected function handleValidationException(Exception $e)
{
// Get the status code and build the message.
$statusCode = 422;
$message = $e->getMessage();
$errorData = $e->getResponse()->getData();
return $this->generateResponse('errors', $errorData, $statusCode, Status::FAIL, $message);
} | [
"protected",
"function",
"handleValidationException",
"(",
"Exception",
"$",
"e",
")",
"{",
"// Get the status code and build the message.",
"$",
"statusCode",
"=",
"422",
";",
"$",
"message",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"$",
"errorData",
"=",
"$",
"e",
"->",
"getResponse",
"(",
")",
"->",
"getData",
"(",
")",
";",
"return",
"$",
"this",
"->",
"generateResponse",
"(",
"'errors'",
",",
"$",
"errorData",
",",
"$",
"statusCode",
",",
"Status",
"::",
"FAIL",
",",
"$",
"message",
")",
";",
"}"
] | Handle a validation exception and build return data.
@param Exception $e
@return mixed | [
"Handle",
"a",
"validation",
"exception",
"and",
"build",
"return",
"data",
"."
] | 8455b7c0d53f2d06bcbfd2854191bf0da1f263f5 | https://github.com/LUSHDigital/microservice-core/blob/8455b7c0d53f2d06bcbfd2854191bf0da1f263f5/src/Traits/MicroServiceExceptionHandlerTrait.php#L115-L123 |
34,943 | LUSHDigital/microservice-core | src/Traits/MicroServiceExceptionHandlerTrait.php | MicroServiceExceptionHandlerTrait.handleGenericException | protected function handleGenericException(Exception $e)
{
// Get the status code and build the message.
$statusCode = 500;
$message = $e->getMessage();
return $this->generateResponse('', null, $statusCode, Status::FAIL, $message);
} | php | protected function handleGenericException(Exception $e)
{
// Get the status code and build the message.
$statusCode = 500;
$message = $e->getMessage();
return $this->generateResponse('', null, $statusCode, Status::FAIL, $message);
} | [
"protected",
"function",
"handleGenericException",
"(",
"Exception",
"$",
"e",
")",
"{",
"// Get the status code and build the message.",
"$",
"statusCode",
"=",
"500",
";",
"$",
"message",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"return",
"$",
"this",
"->",
"generateResponse",
"(",
"''",
",",
"null",
",",
"$",
"statusCode",
",",
"Status",
"::",
"FAIL",
",",
"$",
"message",
")",
";",
"}"
] | Handle a generic exception and build return data.
@param Exception $e
@return mixed | [
"Handle",
"a",
"generic",
"exception",
"and",
"build",
"return",
"data",
"."
] | 8455b7c0d53f2d06bcbfd2854191bf0da1f263f5 | https://github.com/LUSHDigital/microservice-core/blob/8455b7c0d53f2d06bcbfd2854191bf0da1f263f5/src/Traits/MicroServiceExceptionHandlerTrait.php#L131-L138 |
34,944 | LUSHDigital/microservice-core | src/Http/Controllers/MicroServiceController.php | MicroServiceController.info | public function info()
{
// Build the response object.
$serviceInfo = (object) MicroServiceHelper::getServiceInfo();
$serviceInfo->endpoints = [];
// Add the endpoints.
foreach (app()->getRoutes() as $appRoute) {
$endpoint = new \stdClass();
$endpoint->uri = $appRoute['uri'];
$endpoint->method = $appRoute['method'];
$serviceInfo->endpoints[] = $endpoint;
}
return response()->json($serviceInfo);
} | php | public function info()
{
// Build the response object.
$serviceInfo = (object) MicroServiceHelper::getServiceInfo();
$serviceInfo->endpoints = [];
// Add the endpoints.
foreach (app()->getRoutes() as $appRoute) {
$endpoint = new \stdClass();
$endpoint->uri = $appRoute['uri'];
$endpoint->method = $appRoute['method'];
$serviceInfo->endpoints[] = $endpoint;
}
return response()->json($serviceInfo);
} | [
"public",
"function",
"info",
"(",
")",
"{",
"// Build the response object.",
"$",
"serviceInfo",
"=",
"(",
"object",
")",
"MicroServiceHelper",
"::",
"getServiceInfo",
"(",
")",
";",
"$",
"serviceInfo",
"->",
"endpoints",
"=",
"[",
"]",
";",
"// Add the endpoints.",
"foreach",
"(",
"app",
"(",
")",
"->",
"getRoutes",
"(",
")",
"as",
"$",
"appRoute",
")",
"{",
"$",
"endpoint",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"endpoint",
"->",
"uri",
"=",
"$",
"appRoute",
"[",
"'uri'",
"]",
";",
"$",
"endpoint",
"->",
"method",
"=",
"$",
"appRoute",
"[",
"'method'",
"]",
";",
"$",
"serviceInfo",
"->",
"endpoints",
"[",
"]",
"=",
"$",
"endpoint",
";",
"}",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"$",
"serviceInfo",
")",
";",
"}"
] | Retrieve information about this microservice.
Required by the service registry.
@return Response | [
"Retrieve",
"information",
"about",
"this",
"microservice",
"."
] | 8455b7c0d53f2d06bcbfd2854191bf0da1f263f5 | https://github.com/LUSHDigital/microservice-core/blob/8455b7c0d53f2d06bcbfd2854191bf0da1f263f5/src/Http/Controllers/MicroServiceController.php#L35-L51 |
34,945 | LUSHDigital/microservice-core | src/Http/Controllers/MicroServiceController.php | MicroServiceController.health | public function health()
{
try {
// Logic for validating health (e.g. connections to external
// services) should go here.
// If a cache driver is defined, check it is working.
if (!empty(env('CACHE_DRIVER', null))) {
Cache::put('health_check', 'test', 1);
Cache::get('health_check');
}
// If a DB connection is defined, check it is working.
if (!empty(env('DB_HOST', null))) {
DB::connection()->getPdo();
}
// All of our service dependencies are working so build a valid
// response object.
return $this->generateResponse('health', null);
} catch (\Exception $e) {
return $this->generateResponse('', null, 500, Status::FAIL, $e->getMessage());
}
} | php | public function health()
{
try {
// Logic for validating health (e.g. connections to external
// services) should go here.
// If a cache driver is defined, check it is working.
if (!empty(env('CACHE_DRIVER', null))) {
Cache::put('health_check', 'test', 1);
Cache::get('health_check');
}
// If a DB connection is defined, check it is working.
if (!empty(env('DB_HOST', null))) {
DB::connection()->getPdo();
}
// All of our service dependencies are working so build a valid
// response object.
return $this->generateResponse('health', null);
} catch (\Exception $e) {
return $this->generateResponse('', null, 500, Status::FAIL, $e->getMessage());
}
} | [
"public",
"function",
"health",
"(",
")",
"{",
"try",
"{",
"// Logic for validating health (e.g. connections to external",
"// services) should go here.",
"// If a cache driver is defined, check it is working.",
"if",
"(",
"!",
"empty",
"(",
"env",
"(",
"'CACHE_DRIVER'",
",",
"null",
")",
")",
")",
"{",
"Cache",
"::",
"put",
"(",
"'health_check'",
",",
"'test'",
",",
"1",
")",
";",
"Cache",
"::",
"get",
"(",
"'health_check'",
")",
";",
"}",
"// If a DB connection is defined, check it is working.",
"if",
"(",
"!",
"empty",
"(",
"env",
"(",
"'DB_HOST'",
",",
"null",
")",
")",
")",
"{",
"DB",
"::",
"connection",
"(",
")",
"->",
"getPdo",
"(",
")",
";",
"}",
"// All of our service dependencies are working so build a valid",
"// response object.",
"return",
"$",
"this",
"->",
"generateResponse",
"(",
"'health'",
",",
"null",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"$",
"this",
"->",
"generateResponse",
"(",
"''",
",",
"null",
",",
"500",
",",
"Status",
"::",
"FAIL",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | Retrieve a health check for this microservice.
Required by the service gateway and load balancer.
@return Response | [
"Retrieve",
"a",
"health",
"check",
"for",
"this",
"microservice",
"."
] | 8455b7c0d53f2d06bcbfd2854191bf0da1f263f5 | https://github.com/LUSHDigital/microservice-core/blob/8455b7c0d53f2d06bcbfd2854191bf0da1f263f5/src/Http/Controllers/MicroServiceController.php#L60-L83 |
34,946 | LUSHDigital/microservice-core | src/Pagination/Paginator.php | Paginator.preparePaginationResponse | public function preparePaginationResponse()
{
return new Response($this->total, $this->perPage, $this->page, $this->lastPage);
} | php | public function preparePaginationResponse()
{
return new Response($this->total, $this->perPage, $this->page, $this->lastPage);
} | [
"public",
"function",
"preparePaginationResponse",
"(",
")",
"{",
"return",
"new",
"Response",
"(",
"$",
"this",
"->",
"total",
",",
"$",
"this",
"->",
"perPage",
",",
"$",
"this",
"->",
"page",
",",
"$",
"this",
"->",
"lastPage",
")",
";",
"}"
] | Prepare the pagination response.
@return Response | [
"Prepare",
"the",
"pagination",
"response",
"."
] | 8455b7c0d53f2d06bcbfd2854191bf0da1f263f5 | https://github.com/LUSHDigital/microservice-core/blob/8455b7c0d53f2d06bcbfd2854191bf0da1f263f5/src/Pagination/Paginator.php#L178-L181 |
34,947 | LUSHDigital/microservice-core | src/Pagination/Paginator.php | Paginator.calculateOffset | protected function calculateOffset()
{
if (empty($this->page) || empty($this->perPage)) {
throw new \RuntimeException('Cannot calculate offset. Insufficient data');
}
$this->offset = ($this->page - 1) * $this->perPage;
} | php | protected function calculateOffset()
{
if (empty($this->page) || empty($this->perPage)) {
throw new \RuntimeException('Cannot calculate offset. Insufficient data');
}
$this->offset = ($this->page - 1) * $this->perPage;
} | [
"protected",
"function",
"calculateOffset",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"page",
")",
"||",
"empty",
"(",
"$",
"this",
"->",
"perPage",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Cannot calculate offset. Insufficient data'",
")",
";",
"}",
"$",
"this",
"->",
"offset",
"=",
"(",
"$",
"this",
"->",
"page",
"-",
"1",
")",
"*",
"$",
"this",
"->",
"perPage",
";",
"}"
] | Calculate the offset based on the current values. | [
"Calculate",
"the",
"offset",
"based",
"on",
"the",
"current",
"values",
"."
] | 8455b7c0d53f2d06bcbfd2854191bf0da1f263f5 | https://github.com/LUSHDigital/microservice-core/blob/8455b7c0d53f2d06bcbfd2854191bf0da1f263f5/src/Pagination/Paginator.php#L186-L193 |
34,948 | LUSHDigital/microservice-core | src/Pagination/Paginator.php | Paginator.calculateLastPage | protected function calculateLastPage()
{
if (empty($this->total)) {
$this->lastPage = 0;
return;
}
if (empty($this->perPage)) {
throw new \RuntimeException('Cannot calculate last page. Insufficient data');
}
$this->lastPage = (int) ceil($this->total / $this->perPage);
} | php | protected function calculateLastPage()
{
if (empty($this->total)) {
$this->lastPage = 0;
return;
}
if (empty($this->perPage)) {
throw new \RuntimeException('Cannot calculate last page. Insufficient data');
}
$this->lastPage = (int) ceil($this->total / $this->perPage);
} | [
"protected",
"function",
"calculateLastPage",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"total",
")",
")",
"{",
"$",
"this",
"->",
"lastPage",
"=",
"0",
";",
"return",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"perPage",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Cannot calculate last page. Insufficient data'",
")",
";",
"}",
"$",
"this",
"->",
"lastPage",
"=",
"(",
"int",
")",
"ceil",
"(",
"$",
"this",
"->",
"total",
"/",
"$",
"this",
"->",
"perPage",
")",
";",
"}"
] | Calculate the last page based on the current values. | [
"Calculate",
"the",
"last",
"page",
"based",
"on",
"the",
"current",
"values",
"."
] | 8455b7c0d53f2d06bcbfd2854191bf0da1f263f5 | https://github.com/LUSHDigital/microservice-core/blob/8455b7c0d53f2d06bcbfd2854191bf0da1f263f5/src/Pagination/Paginator.php#L198-L210 |
34,949 | view-components/grids | src/Component/Column.php | Column.formatValue | public function formatValue($value)
{
$formatter = $this->getValueFormatter();
return (string)($formatter ? call_user_func($formatter, $value, $this->getGrid()->getCurrentRow()) : $value);
} | php | public function formatValue($value)
{
$formatter = $this->getValueFormatter();
return (string)($formatter ? call_user_func($formatter, $value, $this->getGrid()->getCurrentRow()) : $value);
} | [
"public",
"function",
"formatValue",
"(",
"$",
"value",
")",
"{",
"$",
"formatter",
"=",
"$",
"this",
"->",
"getValueFormatter",
"(",
")",
";",
"return",
"(",
"string",
")",
"(",
"$",
"formatter",
"?",
"call_user_func",
"(",
"$",
"formatter",
",",
"$",
"value",
",",
"$",
"this",
"->",
"getGrid",
"(",
")",
"->",
"getCurrentRow",
"(",
")",
")",
":",
"$",
"value",
")",
";",
"}"
] | Formats value extracted from data row.
@param $value
@return string | [
"Formats",
"value",
"extracted",
"from",
"data",
"row",
"."
] | 38554165e67c90f48c87a6358212f9b67d6ffd4d | https://github.com/view-components/grids/blob/38554165e67c90f48c87a6358212f9b67d6ffd4d/src/Component/Column.php#L93-L97 |
34,950 | view-components/grids | src/Component/Column.php | Column.getCurrentValue | public function getCurrentValue()
{
$func = $this->getValueCalculator();
$currentDataRow = $this->getGrid()->getCurrentRow();
if ($func !== null) {
return call_user_func($func, $currentDataRow);
} else {
return mp\getValue($currentDataRow, $this->getDataFieldName());
}
} | php | public function getCurrentValue()
{
$func = $this->getValueCalculator();
$currentDataRow = $this->getGrid()->getCurrentRow();
if ($func !== null) {
return call_user_func($func, $currentDataRow);
} else {
return mp\getValue($currentDataRow, $this->getDataFieldName());
}
} | [
"public",
"function",
"getCurrentValue",
"(",
")",
"{",
"$",
"func",
"=",
"$",
"this",
"->",
"getValueCalculator",
"(",
")",
";",
"$",
"currentDataRow",
"=",
"$",
"this",
"->",
"getGrid",
"(",
")",
"->",
"getCurrentRow",
"(",
")",
";",
"if",
"(",
"$",
"func",
"!==",
"null",
")",
"{",
"return",
"call_user_func",
"(",
"$",
"func",
",",
"$",
"currentDataRow",
")",
";",
"}",
"else",
"{",
"return",
"mp",
"\\",
"getValue",
"(",
"$",
"currentDataRow",
",",
"$",
"this",
"->",
"getDataFieldName",
"(",
")",
")",
";",
"}",
"}"
] | Returns current data cell value.
@return mixed | [
"Returns",
"current",
"data",
"cell",
"value",
"."
] | 38554165e67c90f48c87a6358212f9b67d6ffd4d | https://github.com/view-components/grids/blob/38554165e67c90f48c87a6358212f9b67d6ffd4d/src/Component/Column.php#L104-L113 |
34,951 | view-components/grids | src/Component/Column.php | Column.getLabel | public function getLabel()
{
if ($this->label === null) {
$this->label = ucwords(str_replace(array('-', '_', '.'), ' ', $this->id));
}
return $this->label;
} | php | public function getLabel()
{
if ($this->label === null) {
$this->label = ucwords(str_replace(array('-', '_', '.'), ' ', $this->id));
}
return $this->label;
} | [
"public",
"function",
"getLabel",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"label",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"label",
"=",
"ucwords",
"(",
"str_replace",
"(",
"array",
"(",
"'-'",
",",
"'_'",
",",
"'.'",
")",
",",
"' '",
",",
"$",
"this",
"->",
"id",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"label",
";",
"}"
] | Returns text label that will be rendered in table header.
@return string | [
"Returns",
"text",
"label",
"that",
"will",
"be",
"rendered",
"in",
"table",
"header",
"."
] | 38554165e67c90f48c87a6358212f9b67d6ffd4d | https://github.com/view-components/grids/blob/38554165e67c90f48c87a6358212f9b67d6ffd4d/src/Component/Column.php#L270-L276 |
34,952 | view-components/grids | src/Component/ColumnSortingControl.php | ColumnSortingControl.getDirection | protected function getDirection()
{
if (!$this->inputOption->hasValue()) {
return null;
}
list($columnName, $direction) = explode(static::DELIMITER, $this->inputOption->getValue());
if ($columnName !== $this->columnId) {
return null;
}
return $direction;
} | php | protected function getDirection()
{
if (!$this->inputOption->hasValue()) {
return null;
}
list($columnName, $direction) = explode(static::DELIMITER, $this->inputOption->getValue());
if ($columnName !== $this->columnId) {
return null;
}
return $direction;
} | [
"protected",
"function",
"getDirection",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"inputOption",
"->",
"hasValue",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"list",
"(",
"$",
"columnName",
",",
"$",
"direction",
")",
"=",
"explode",
"(",
"static",
"::",
"DELIMITER",
",",
"$",
"this",
"->",
"inputOption",
"->",
"getValue",
"(",
")",
")",
";",
"if",
"(",
"$",
"columnName",
"!==",
"$",
"this",
"->",
"columnId",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"direction",
";",
"}"
] | Returns sorting direction for attached column if specified in input.
@return string|null 'asc', 'desc' or null | [
"Returns",
"sorting",
"direction",
"for",
"attached",
"column",
"if",
"specified",
"in",
"input",
"."
] | 38554165e67c90f48c87a6358212f9b67d6ffd4d | https://github.com/view-components/grids/blob/38554165e67c90f48c87a6358212f9b67d6ffd4d/src/Component/ColumnSortingControl.php#L40-L50 |
34,953 | view-components/grids | src/Component/ColumnSortingControl.php | ColumnSortingControl.getOperation | public function getOperation()
{
$direction = $this->getDirection();
if ($direction === null) {
return new DummyOperation();
}
if ($this->root !== null) {
/** @var Grid $root */
$root = $this->root;
$fieldName = $root->getColumn($this->columnId)->getDataFieldName();
} else {
$fieldName = $this->columnId;
}
return new SortOperation($fieldName, $direction);
} | php | public function getOperation()
{
$direction = $this->getDirection();
if ($direction === null) {
return new DummyOperation();
}
if ($this->root !== null) {
/** @var Grid $root */
$root = $this->root;
$fieldName = $root->getColumn($this->columnId)->getDataFieldName();
} else {
$fieldName = $this->columnId;
}
return new SortOperation($fieldName, $direction);
} | [
"public",
"function",
"getOperation",
"(",
")",
"{",
"$",
"direction",
"=",
"$",
"this",
"->",
"getDirection",
"(",
")",
";",
"if",
"(",
"$",
"direction",
"===",
"null",
")",
"{",
"return",
"new",
"DummyOperation",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"root",
"!==",
"null",
")",
"{",
"/** @var Grid $root */",
"$",
"root",
"=",
"$",
"this",
"->",
"root",
";",
"$",
"fieldName",
"=",
"$",
"root",
"->",
"getColumn",
"(",
"$",
"this",
"->",
"columnId",
")",
"->",
"getDataFieldName",
"(",
")",
";",
"}",
"else",
"{",
"$",
"fieldName",
"=",
"$",
"this",
"->",
"columnId",
";",
"}",
"return",
"new",
"SortOperation",
"(",
"$",
"fieldName",
",",
"$",
"direction",
")",
";",
"}"
] | Creates operation for data provider.
@return DummyOperation|SortOperation | [
"Creates",
"operation",
"for",
"data",
"provider",
"."
] | 38554165e67c90f48c87a6358212f9b67d6ffd4d | https://github.com/view-components/grids/blob/38554165e67c90f48c87a6358212f9b67d6ffd4d/src/Component/ColumnSortingControl.php#L69-L83 |
34,954 | view-components/grids | src/GridPartsAccessTrait.php | GridPartsAccessTrait.setTable | public function setTable(ContainerComponentInterface $component)
{
return $this->setComponent($component, Grid::TABLE_ID, Grid::FORM_ID);
} | php | public function setTable(ContainerComponentInterface $component)
{
return $this->setComponent($component, Grid::TABLE_ID, Grid::FORM_ID);
} | [
"public",
"function",
"setTable",
"(",
"ContainerComponentInterface",
"$",
"component",
")",
"{",
"return",
"$",
"this",
"->",
"setComponent",
"(",
"$",
"component",
",",
"Grid",
"::",
"TABLE_ID",
",",
"Grid",
"::",
"FORM_ID",
")",
";",
"}"
] | Sets component for rendering 'table' tag.
@param ContainerComponentInterface $component
@return $this | [
"Sets",
"component",
"for",
"rendering",
"table",
"tag",
"."
] | 38554165e67c90f48c87a6358212f9b67d6ffd4d | https://github.com/view-components/grids/blob/38554165e67c90f48c87a6358212f9b67d6ffd4d/src/GridPartsAccessTrait.php#L49-L52 |
34,955 | view-components/grids | src/Component/PageTotalsRow.php | PageTotalsRow.render | public function render()
{
/** @var Grid $grid */
$grid = $this->root;
$this->isTotalsCalculationFinished = true;
$tr = $grid->getRecordView();
// set total_row as current grid row
$lastRow = $grid->getCurrentRow();
$grid->setCurrentRow($this->totalData);
// modify columns, prepare it for rendering totals row
$valueCalculators = [];
$valueFormatters = [];
foreach ($grid->getColumns() as $column) {
$valueCalculators[$column->getId()] = $column->getValueCalculator();
$valueFormatters[$column->getId()] = $prevFormatter = $column->getValueFormatter();
$column->setValueCalculator(null);
$column->setValueFormatter(function ($value) use ($prevFormatter, $column) {
$operation = $this->getOperation($column->getId());
if ($prevFormatter && !($operation === static::OPERATION_IGNORE || $operation instanceof Closure)) {
$value = call_user_func($prevFormatter, $value);
}
// Add value prefix if specified for operation
if ($value !== null && is_string($operation) && array_key_exists($operation, $this->valuePrefixes)) {
$value = $this->valuePrefixes[$operation] . ' ' . $value;
}
return $value;
});
}
$output = $tr->render();
// restore column value calculators & formatters
foreach ($grid->getColumns() as $column) {
$column->setValueCalculator($valueCalculators[$column->getId()]);
$column->setValueFormatter($valueFormatters[$column->getId()]);
}
// restore last data row
$grid->setCurrentRow($lastRow);
return $output;
} | php | public function render()
{
/** @var Grid $grid */
$grid = $this->root;
$this->isTotalsCalculationFinished = true;
$tr = $grid->getRecordView();
// set total_row as current grid row
$lastRow = $grid->getCurrentRow();
$grid->setCurrentRow($this->totalData);
// modify columns, prepare it for rendering totals row
$valueCalculators = [];
$valueFormatters = [];
foreach ($grid->getColumns() as $column) {
$valueCalculators[$column->getId()] = $column->getValueCalculator();
$valueFormatters[$column->getId()] = $prevFormatter = $column->getValueFormatter();
$column->setValueCalculator(null);
$column->setValueFormatter(function ($value) use ($prevFormatter, $column) {
$operation = $this->getOperation($column->getId());
if ($prevFormatter && !($operation === static::OPERATION_IGNORE || $operation instanceof Closure)) {
$value = call_user_func($prevFormatter, $value);
}
// Add value prefix if specified for operation
if ($value !== null && is_string($operation) && array_key_exists($operation, $this->valuePrefixes)) {
$value = $this->valuePrefixes[$operation] . ' ' . $value;
}
return $value;
});
}
$output = $tr->render();
// restore column value calculators & formatters
foreach ($grid->getColumns() as $column) {
$column->setValueCalculator($valueCalculators[$column->getId()]);
$column->setValueFormatter($valueFormatters[$column->getId()]);
}
// restore last data row
$grid->setCurrentRow($lastRow);
return $output;
} | [
"public",
"function",
"render",
"(",
")",
"{",
"/** @var Grid $grid */",
"$",
"grid",
"=",
"$",
"this",
"->",
"root",
";",
"$",
"this",
"->",
"isTotalsCalculationFinished",
"=",
"true",
";",
"$",
"tr",
"=",
"$",
"grid",
"->",
"getRecordView",
"(",
")",
";",
"// set total_row as current grid row",
"$",
"lastRow",
"=",
"$",
"grid",
"->",
"getCurrentRow",
"(",
")",
";",
"$",
"grid",
"->",
"setCurrentRow",
"(",
"$",
"this",
"->",
"totalData",
")",
";",
"// modify columns, prepare it for rendering totals row",
"$",
"valueCalculators",
"=",
"[",
"]",
";",
"$",
"valueFormatters",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"grid",
"->",
"getColumns",
"(",
")",
"as",
"$",
"column",
")",
"{",
"$",
"valueCalculators",
"[",
"$",
"column",
"->",
"getId",
"(",
")",
"]",
"=",
"$",
"column",
"->",
"getValueCalculator",
"(",
")",
";",
"$",
"valueFormatters",
"[",
"$",
"column",
"->",
"getId",
"(",
")",
"]",
"=",
"$",
"prevFormatter",
"=",
"$",
"column",
"->",
"getValueFormatter",
"(",
")",
";",
"$",
"column",
"->",
"setValueCalculator",
"(",
"null",
")",
";",
"$",
"column",
"->",
"setValueFormatter",
"(",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"$",
"prevFormatter",
",",
"$",
"column",
")",
"{",
"$",
"operation",
"=",
"$",
"this",
"->",
"getOperation",
"(",
"$",
"column",
"->",
"getId",
"(",
")",
")",
";",
"if",
"(",
"$",
"prevFormatter",
"&&",
"!",
"(",
"$",
"operation",
"===",
"static",
"::",
"OPERATION_IGNORE",
"||",
"$",
"operation",
"instanceof",
"Closure",
")",
")",
"{",
"$",
"value",
"=",
"call_user_func",
"(",
"$",
"prevFormatter",
",",
"$",
"value",
")",
";",
"}",
"// Add value prefix if specified for operation",
"if",
"(",
"$",
"value",
"!==",
"null",
"&&",
"is_string",
"(",
"$",
"operation",
")",
"&&",
"array_key_exists",
"(",
"$",
"operation",
",",
"$",
"this",
"->",
"valuePrefixes",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"valuePrefixes",
"[",
"$",
"operation",
"]",
".",
"' '",
".",
"$",
"value",
";",
"}",
"return",
"$",
"value",
";",
"}",
")",
";",
"}",
"$",
"output",
"=",
"$",
"tr",
"->",
"render",
"(",
")",
";",
"// restore column value calculators & formatters",
"foreach",
"(",
"$",
"grid",
"->",
"getColumns",
"(",
")",
"as",
"$",
"column",
")",
"{",
"$",
"column",
"->",
"setValueCalculator",
"(",
"$",
"valueCalculators",
"[",
"$",
"column",
"->",
"getId",
"(",
")",
"]",
")",
";",
"$",
"column",
"->",
"setValueFormatter",
"(",
"$",
"valueFormatters",
"[",
"$",
"column",
"->",
"getId",
"(",
")",
"]",
")",
";",
"}",
"// restore last data row",
"$",
"grid",
"->",
"setCurrentRow",
"(",
"$",
"lastRow",
")",
";",
"return",
"$",
"output",
";",
"}"
] | Renders tag and returns output.
@return string | [
"Renders",
"tag",
"and",
"returns",
"output",
"."
] | 38554165e67c90f48c87a6358212f9b67d6ffd4d | https://github.com/view-components/grids/blob/38554165e67c90f48c87a6358212f9b67d6ffd4d/src/Component/PageTotalsRow.php#L126-L166 |
34,956 | view-components/grids | src/Grid.php | Grid.getColumn | public function getColumn($id)
{
$column = $this->getComponent($id);
if (!$column) {
throw new RuntimeException("Column '$id' is not defined.");
}
if (!$column instanceof Column) {
throw new RuntimeException("'$id' is not a column.");
}
return $column;
} | php | public function getColumn($id)
{
$column = $this->getComponent($id);
if (!$column) {
throw new RuntimeException("Column '$id' is not defined.");
}
if (!$column instanceof Column) {
throw new RuntimeException("'$id' is not a column.");
}
return $column;
} | [
"public",
"function",
"getColumn",
"(",
"$",
"id",
")",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"getComponent",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"column",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Column '$id' is not defined.\"",
")",
";",
"}",
"if",
"(",
"!",
"$",
"column",
"instanceof",
"Column",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"'$id' is not a column.\"",
")",
";",
"}",
"return",
"$",
"column",
";",
"}"
] | Returns column with specified id,
throws exception if grid does not have specified column.
@param string $id
@return Column | [
"Returns",
"column",
"with",
"specified",
"id",
"throws",
"exception",
"if",
"grid",
"does",
"not",
"have",
"specified",
"column",
"."
] | 38554165e67c90f48c87a6358212f9b67d6ffd4d | https://github.com/view-components/grids/blob/38554165e67c90f48c87a6358212f9b67d6ffd4d/src/Grid.php#L49-L59 |
34,957 | lanthaler/HydraConsole | proxylib.php | AjaxProxy.execute | public function execute()
{
$this->_checkPermissions();
$this->_gatherRequestInfo();
$this->_makeRequest();
$this->_parseResponse();
$this->_buildAndExecuteProxyResponse();
} | php | public function execute()
{
$this->_checkPermissions();
$this->_gatherRequestInfo();
$this->_makeRequest();
$this->_parseResponse();
$this->_buildAndExecuteProxyResponse();
} | [
"public",
"function",
"execute",
"(",
")",
"{",
"$",
"this",
"->",
"_checkPermissions",
"(",
")",
";",
"$",
"this",
"->",
"_gatherRequestInfo",
"(",
")",
";",
"$",
"this",
"->",
"_makeRequest",
"(",
")",
";",
"$",
"this",
"->",
"_parseResponse",
"(",
")",
";",
"$",
"this",
"->",
"_buildAndExecuteProxyResponse",
"(",
")",
";",
"}"
] | Execute the proxy request. This method sets HTTP headers and write to the
output stream. Make sure that no whitespace or headers have already been
sent. | [
"Execute",
"the",
"proxy",
"request",
".",
"This",
"method",
"sets",
"HTTP",
"headers",
"and",
"write",
"to",
"the",
"output",
"stream",
".",
"Make",
"sure",
"that",
"no",
"whitespace",
"or",
"headers",
"have",
"already",
"been",
"sent",
"."
] | 43c3216038b7a65b99f7d1caf3b838424b6b8d3c | https://github.com/lanthaler/HydraConsole/blob/43c3216038b7a65b99f7d1caf3b838424b6b8d3c/proxylib.php#L182-L189 |
34,958 | lanthaler/HydraConsole | proxylib.php | AjaxProxy._gatherRequestInfo | protected function _gatherRequestInfo()
{
$this->_loadRequestMethod();
$this->_loadRequestCookies();
$this->_loadRequestUserAgent();
$this->_loadRequestAuthorizationHeader();
$this->_loadRequestAcceptHeader();
$this->_loadRawHeaders();
$this->_loadContentType();
$this->_loadUrl();
if($this->_requestMethod === 'POST'
|| $this->_requestMethod === 'PUT')
{
$this->_loadRequestBody();
}
} | php | protected function _gatherRequestInfo()
{
$this->_loadRequestMethod();
$this->_loadRequestCookies();
$this->_loadRequestUserAgent();
$this->_loadRequestAuthorizationHeader();
$this->_loadRequestAcceptHeader();
$this->_loadRawHeaders();
$this->_loadContentType();
$this->_loadUrl();
if($this->_requestMethod === 'POST'
|| $this->_requestMethod === 'PUT')
{
$this->_loadRequestBody();
}
} | [
"protected",
"function",
"_gatherRequestInfo",
"(",
")",
"{",
"$",
"this",
"->",
"_loadRequestMethod",
"(",
")",
";",
"$",
"this",
"->",
"_loadRequestCookies",
"(",
")",
";",
"$",
"this",
"->",
"_loadRequestUserAgent",
"(",
")",
";",
"$",
"this",
"->",
"_loadRequestAuthorizationHeader",
"(",
")",
";",
"$",
"this",
"->",
"_loadRequestAcceptHeader",
"(",
")",
";",
"$",
"this",
"->",
"_loadRawHeaders",
"(",
")",
";",
"$",
"this",
"->",
"_loadContentType",
"(",
")",
";",
"$",
"this",
"->",
"_loadUrl",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_requestMethod",
"===",
"'POST'",
"||",
"$",
"this",
"->",
"_requestMethod",
"===",
"'PUT'",
")",
"{",
"$",
"this",
"->",
"_loadRequestBody",
"(",
")",
";",
"}",
"}"
] | Gather any information we need about the request and
store them in the class properties | [
"Gather",
"any",
"information",
"we",
"need",
"about",
"the",
"request",
"and",
"store",
"them",
"in",
"the",
"class",
"properties"
] | 43c3216038b7a65b99f7d1caf3b838424b6b8d3c | https://github.com/lanthaler/HydraConsole/blob/43c3216038b7a65b99f7d1caf3b838424b6b8d3c/proxylib.php#L195-L211 |
34,959 | lanthaler/HydraConsole | proxylib.php | AjaxProxy._loadUrl | protected function _loadUrl()
{
if(!key_exists('url', $_GET))
throw new Exception("You must supply a 'url' parameter in the request");
$this->_url = ($this->_forwardHost)
? $this->_forwardHost . $_GET['url']
: $_GET['url'];
} | php | protected function _loadUrl()
{
if(!key_exists('url', $_GET))
throw new Exception("You must supply a 'url' parameter in the request");
$this->_url = ($this->_forwardHost)
? $this->_forwardHost . $_GET['url']
: $_GET['url'];
} | [
"protected",
"function",
"_loadUrl",
"(",
")",
"{",
"if",
"(",
"!",
"key_exists",
"(",
"'url'",
",",
"$",
"_GET",
")",
")",
"throw",
"new",
"Exception",
"(",
"\"You must supply a 'url' parameter in the request\"",
")",
";",
"$",
"this",
"->",
"_url",
"=",
"(",
"$",
"this",
"->",
"_forwardHost",
")",
"?",
"$",
"this",
"->",
"_forwardHost",
".",
"$",
"_GET",
"[",
"'url'",
"]",
":",
"$",
"_GET",
"[",
"'url'",
"]",
";",
"}"
] | Get the url to where the request will be made.
@throws Exception When there is no 'url' parameter | [
"Get",
"the",
"url",
"to",
"where",
"the",
"request",
"will",
"be",
"made",
"."
] | 43c3216038b7a65b99f7d1caf3b838424b6b8d3c | https://github.com/lanthaler/HydraConsole/blob/43c3216038b7a65b99f7d1caf3b838424b6b8d3c/proxylib.php#L218-L226 |
34,960 | lanthaler/HydraConsole | proxylib.php | AjaxProxy._loadRequestMethod | protected function _loadRequestMethod()
{
if($this->_requestMethod !== NULL) return;
if(!key_exists('REQUEST_METHOD', $_SERVER)) {
throw new Exception("Request method unknown");
}
$method = strtoupper($_SERVER['REQUEST_METHOD']);
if (in_array($method, array('GET', 'POST', 'PUT', 'DELETE', 'PATCH'))) {
$this->_requestMethod = $method;
} else {
throw new Exception("Request method ($method) invalid");
}
} | php | protected function _loadRequestMethod()
{
if($this->_requestMethod !== NULL) return;
if(!key_exists('REQUEST_METHOD', $_SERVER)) {
throw new Exception("Request method unknown");
}
$method = strtoupper($_SERVER['REQUEST_METHOD']);
if (in_array($method, array('GET', 'POST', 'PUT', 'DELETE', 'PATCH'))) {
$this->_requestMethod = $method;
} else {
throw new Exception("Request method ($method) invalid");
}
} | [
"protected",
"function",
"_loadRequestMethod",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_requestMethod",
"!==",
"NULL",
")",
"return",
";",
"if",
"(",
"!",
"key_exists",
"(",
"'REQUEST_METHOD'",
",",
"$",
"_SERVER",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Request method unknown\"",
")",
";",
"}",
"$",
"method",
"=",
"strtoupper",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"method",
",",
"array",
"(",
"'GET'",
",",
"'POST'",
",",
"'PUT'",
",",
"'DELETE'",
",",
"'PATCH'",
")",
")",
")",
"{",
"$",
"this",
"->",
"_requestMethod",
"=",
"$",
"method",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"\"Request method ($method) invalid\"",
")",
";",
"}",
"}"
] | Examine the request and load the HTTP request method
into the _requestMethod property
@throws Exception When there is no request method | [
"Examine",
"the",
"request",
"and",
"load",
"the",
"HTTP",
"request",
"method",
"into",
"the",
"_requestMethod",
"property"
] | 43c3216038b7a65b99f7d1caf3b838424b6b8d3c | https://github.com/lanthaler/HydraConsole/blob/43c3216038b7a65b99f7d1caf3b838424b6b8d3c/proxylib.php#L248-L263 |
34,961 | lanthaler/HydraConsole | proxylib.php | AjaxProxy._loadRequestUserAgent | protected function _loadRequestUserAgent()
{
if($this->_requestUserAgent !== NULL) return;
if(! key_exists('HTTP_USER_AGENT', $_SERVER))
throw new Exception("No HTTP User Agent was found");
$this->_requestUserAgent = $_SERVER['HTTP_USER_AGENT'];
} | php | protected function _loadRequestUserAgent()
{
if($this->_requestUserAgent !== NULL) return;
if(! key_exists('HTTP_USER_AGENT', $_SERVER))
throw new Exception("No HTTP User Agent was found");
$this->_requestUserAgent = $_SERVER['HTTP_USER_AGENT'];
} | [
"protected",
"function",
"_loadRequestUserAgent",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_requestUserAgent",
"!==",
"NULL",
")",
"return",
";",
"if",
"(",
"!",
"key_exists",
"(",
"'HTTP_USER_AGENT'",
",",
"$",
"_SERVER",
")",
")",
"throw",
"new",
"Exception",
"(",
"\"No HTTP User Agent was found\"",
")",
";",
"$",
"this",
"->",
"_requestUserAgent",
"=",
"$",
"_SERVER",
"[",
"'HTTP_USER_AGENT'",
"]",
";",
"}"
] | Loads the user-agent string into the _requestUserAgent property
@throws Exception When the user agent is not sent by the client | [
"Loads",
"the",
"user",
"-",
"agent",
"string",
"into",
"the",
"_requestUserAgent",
"property"
] | 43c3216038b7a65b99f7d1caf3b838424b6b8d3c | https://github.com/lanthaler/HydraConsole/blob/43c3216038b7a65b99f7d1caf3b838424b6b8d3c/proxylib.php#L269-L277 |
34,962 | lanthaler/HydraConsole | proxylib.php | AjaxProxy._loadRequestAuthorizationHeader | protected function _loadRequestAuthorizationHeader()
{
if($this->_requestAuthorization !== NULL) return;
$this->_loadRawHeaders();
if (key_exists('Authorization', $this->_rawHeaders)) {
$this->_requestAuthorization = $this->_rawHeaders['Authorization'];
}
} | php | protected function _loadRequestAuthorizationHeader()
{
if($this->_requestAuthorization !== NULL) return;
$this->_loadRawHeaders();
if (key_exists('Authorization', $this->_rawHeaders)) {
$this->_requestAuthorization = $this->_rawHeaders['Authorization'];
}
} | [
"protected",
"function",
"_loadRequestAuthorizationHeader",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_requestAuthorization",
"!==",
"NULL",
")",
"return",
";",
"$",
"this",
"->",
"_loadRawHeaders",
"(",
")",
";",
"if",
"(",
"key_exists",
"(",
"'Authorization'",
",",
"$",
"this",
"->",
"_rawHeaders",
")",
")",
"{",
"$",
"this",
"->",
"_requestAuthorization",
"=",
"$",
"this",
"->",
"_rawHeaders",
"[",
"'Authorization'",
"]",
";",
"}",
"}"
] | Store the Authorization header in _requestAuthorization
property | [
"Store",
"the",
"Authorization",
"header",
"in",
"_requestAuthorization",
"property"
] | 43c3216038b7a65b99f7d1caf3b838424b6b8d3c | https://github.com/lanthaler/HydraConsole/blob/43c3216038b7a65b99f7d1caf3b838424b6b8d3c/proxylib.php#L294-L303 |
34,963 | lanthaler/HydraConsole | proxylib.php | AjaxProxy._loadRequestAcceptHeader | protected function _loadRequestAcceptHeader()
{
if($this->_requestAccept !== NULL) return;
$this->_loadRawHeaders();
if (key_exists('Accept', $this->_rawHeaders)) {
$this->_requestAccept = $this->_rawHeaders['Accept'];
}
} | php | protected function _loadRequestAcceptHeader()
{
if($this->_requestAccept !== NULL) return;
$this->_loadRawHeaders();
if (key_exists('Accept', $this->_rawHeaders)) {
$this->_requestAccept = $this->_rawHeaders['Accept'];
}
} | [
"protected",
"function",
"_loadRequestAcceptHeader",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_requestAccept",
"!==",
"NULL",
")",
"return",
";",
"$",
"this",
"->",
"_loadRawHeaders",
"(",
")",
";",
"if",
"(",
"key_exists",
"(",
"'Accept'",
",",
"$",
"this",
"->",
"_rawHeaders",
")",
")",
"{",
"$",
"this",
"->",
"_requestAccept",
"=",
"$",
"this",
"->",
"_rawHeaders",
"[",
"'Accept'",
"]",
";",
"}",
"}"
] | Store the Accept header in _requestAccept property | [
"Store",
"the",
"Accept",
"header",
"in",
"_requestAccept",
"property"
] | 43c3216038b7a65b99f7d1caf3b838424b6b8d3c | https://github.com/lanthaler/HydraConsole/blob/43c3216038b7a65b99f7d1caf3b838424b6b8d3c/proxylib.php#L308-L317 |
34,964 | lanthaler/HydraConsole | proxylib.php | AjaxProxy._loadContentType | protected function _loadContentType()
{
$this->_loadRawHeaders();
if(key_exists('Content-Type', $this->_rawHeaders))
$this->_requestContentType = $this->_rawHeaders['Content-Type'];
} | php | protected function _loadContentType()
{
$this->_loadRawHeaders();
if(key_exists('Content-Type', $this->_rawHeaders))
$this->_requestContentType = $this->_rawHeaders['Content-Type'];
} | [
"protected",
"function",
"_loadContentType",
"(",
")",
"{",
"$",
"this",
"->",
"_loadRawHeaders",
"(",
")",
";",
"if",
"(",
"key_exists",
"(",
"'Content-Type'",
",",
"$",
"this",
"->",
"_rawHeaders",
")",
")",
"$",
"this",
"->",
"_requestContentType",
"=",
"$",
"this",
"->",
"_rawHeaders",
"[",
"'Content-Type'",
"]",
";",
"}"
] | Load the content type into the _requestContentType property | [
"Load",
"the",
"content",
"type",
"into",
"the",
"_requestContentType",
"property"
] | 43c3216038b7a65b99f7d1caf3b838424b6b8d3c | https://github.com/lanthaler/HydraConsole/blob/43c3216038b7a65b99f7d1caf3b838424b6b8d3c/proxylib.php#L322-L328 |
34,965 | lanthaler/HydraConsole | proxylib.php | AjaxProxy._loadRawHeaders | protected function _loadRawHeaders()
{
if($this->_rawHeaders !== NULL) return;
$this->_rawHeaders = apache_request_headers();
if($this->_rawHeaders === FALSE)
throw new Exception("Could not get request headers");
} | php | protected function _loadRawHeaders()
{
if($this->_rawHeaders !== NULL) return;
$this->_rawHeaders = apache_request_headers();
if($this->_rawHeaders === FALSE)
throw new Exception("Could not get request headers");
} | [
"protected",
"function",
"_loadRawHeaders",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_rawHeaders",
"!==",
"NULL",
")",
"return",
";",
"$",
"this",
"->",
"_rawHeaders",
"=",
"apache_request_headers",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_rawHeaders",
"===",
"FALSE",
")",
"throw",
"new",
"Exception",
"(",
"\"Could not get request headers\"",
")",
";",
"}"
] | Load raw headers into the _rawHeaders property.
This method REQUIRES APACHE
@throws Exception When we can't load request headers (perhaps when Apache
isn't being used) | [
"Load",
"raw",
"headers",
"into",
"the",
"_rawHeaders",
"property",
".",
"This",
"method",
"REQUIRES",
"APACHE"
] | 43c3216038b7a65b99f7d1caf3b838424b6b8d3c | https://github.com/lanthaler/HydraConsole/blob/43c3216038b7a65b99f7d1caf3b838424b6b8d3c/proxylib.php#L336-L344 |
34,966 | lanthaler/HydraConsole | proxylib.php | AjaxProxy._checkPermissions | protected function _checkPermissions()
{
if($this->_allowedHostnames === NULL)
return;
if(key_exists('REMOTE_HOST', $_SERVER))
$host = $_SERVER['REMOTE_HOST'];
else
$host = $_SERVER['REMOTE_ADDR'];
if(!in_array($host, $this->_allowedHostnames))
throw new Exception("Requests from hostname ($host) are not allowed");
} | php | protected function _checkPermissions()
{
if($this->_allowedHostnames === NULL)
return;
if(key_exists('REMOTE_HOST', $_SERVER))
$host = $_SERVER['REMOTE_HOST'];
else
$host = $_SERVER['REMOTE_ADDR'];
if(!in_array($host, $this->_allowedHostnames))
throw new Exception("Requests from hostname ($host) are not allowed");
} | [
"protected",
"function",
"_checkPermissions",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_allowedHostnames",
"===",
"NULL",
")",
"return",
";",
"if",
"(",
"key_exists",
"(",
"'REMOTE_HOST'",
",",
"$",
"_SERVER",
")",
")",
"$",
"host",
"=",
"$",
"_SERVER",
"[",
"'REMOTE_HOST'",
"]",
";",
"else",
"$",
"host",
"=",
"$",
"_SERVER",
"[",
"'REMOTE_ADDR'",
"]",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"host",
",",
"$",
"this",
"->",
"_allowedHostnames",
")",
")",
"throw",
"new",
"Exception",
"(",
"\"Requests from hostname ($host) are not allowed\"",
")",
";",
"}"
] | Check that the proxy request is coming from the appropriate host
that was set in the second argument of the constructor
@return void
@throws Exception when a client hostname is not permitted on a request | [
"Check",
"that",
"the",
"proxy",
"request",
"is",
"coming",
"from",
"the",
"appropriate",
"host",
"that",
"was",
"set",
"in",
"the",
"second",
"argument",
"of",
"the",
"constructor"
] | 43c3216038b7a65b99f7d1caf3b838424b6b8d3c | https://github.com/lanthaler/HydraConsole/blob/43c3216038b7a65b99f7d1caf3b838424b6b8d3c/proxylib.php#L352-L364 |
34,967 | lanthaler/HydraConsole | proxylib.php | AjaxProxy._makeRequest | protected function _makeRequest()
{
# Check for cURL. If it isn't loaded, fall back to fopen()
if(function_exists('curl_init'))
$this->_rawResponse = $this->_makeCurlRequest($this->_url);
else
$this->_rawResponse = $this->_makeFOpenRequest($this->_url);
} | php | protected function _makeRequest()
{
# Check for cURL. If it isn't loaded, fall back to fopen()
if(function_exists('curl_init'))
$this->_rawResponse = $this->_makeCurlRequest($this->_url);
else
$this->_rawResponse = $this->_makeFOpenRequest($this->_url);
} | [
"protected",
"function",
"_makeRequest",
"(",
")",
"{",
"# Check for cURL. If it isn't loaded, fall back to fopen()\r",
"if",
"(",
"function_exists",
"(",
"'curl_init'",
")",
")",
"$",
"this",
"->",
"_rawResponse",
"=",
"$",
"this",
"->",
"_makeCurlRequest",
"(",
"$",
"this",
"->",
"_url",
")",
";",
"else",
"$",
"this",
"->",
"_rawResponse",
"=",
"$",
"this",
"->",
"_makeFOpenRequest",
"(",
"$",
"this",
"->",
"_url",
")",
";",
"}"
] | Make the proxy request using the supplied route and the base host we got
in the constructor. Store the response in _rawResponse | [
"Make",
"the",
"proxy",
"request",
"using",
"the",
"supplied",
"route",
"and",
"the",
"base",
"host",
"we",
"got",
"in",
"the",
"constructor",
".",
"Store",
"the",
"response",
"in",
"_rawResponse"
] | 43c3216038b7a65b99f7d1caf3b838424b6b8d3c | https://github.com/lanthaler/HydraConsole/blob/43c3216038b7a65b99f7d1caf3b838424b6b8d3c/proxylib.php#L370-L377 |
34,968 | lanthaler/HydraConsole | proxylib.php | AjaxProxy._makeCurlRequest | protected function _makeCurlRequest($url)
{
$curl_handle = curl_init($url);
curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, $this->_requestMethod);
if($this->_requestBody)
{
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $this->_requestBody);
}
curl_setopt($curl_handle, CURLOPT_HEADER, true);
curl_setopt($curl_handle, CURLOPT_USERAGENT, $this->_requestUserAgent);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_COOKIE, $this->_buildProxyRequestCookieString());
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $this->_generateProxyRequestHeaders());
$response = curl_exec($curl_handle);
if (false === $response) {
var_dump(curl_error($curl_handle));
} else {
return $response;
}
} | php | protected function _makeCurlRequest($url)
{
$curl_handle = curl_init($url);
curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, $this->_requestMethod);
if($this->_requestBody)
{
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $this->_requestBody);
}
curl_setopt($curl_handle, CURLOPT_HEADER, true);
curl_setopt($curl_handle, CURLOPT_USERAGENT, $this->_requestUserAgent);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_handle, CURLOPT_COOKIE, $this->_buildProxyRequestCookieString());
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $this->_generateProxyRequestHeaders());
$response = curl_exec($curl_handle);
if (false === $response) {
var_dump(curl_error($curl_handle));
} else {
return $response;
}
} | [
"protected",
"function",
"_makeCurlRequest",
"(",
"$",
"url",
")",
"{",
"$",
"curl_handle",
"=",
"curl_init",
"(",
"$",
"url",
")",
";",
"curl_setopt",
"(",
"$",
"curl_handle",
",",
"CURLOPT_CUSTOMREQUEST",
",",
"$",
"this",
"->",
"_requestMethod",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_requestBody",
")",
"{",
"curl_setopt",
"(",
"$",
"curl_handle",
",",
"CURLOPT_POSTFIELDS",
",",
"$",
"this",
"->",
"_requestBody",
")",
";",
"}",
"curl_setopt",
"(",
"$",
"curl_handle",
",",
"CURLOPT_HEADER",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"curl_handle",
",",
"CURLOPT_USERAGENT",
",",
"$",
"this",
"->",
"_requestUserAgent",
")",
";",
"curl_setopt",
"(",
"$",
"curl_handle",
",",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"curl_handle",
",",
"CURLOPT_COOKIE",
",",
"$",
"this",
"->",
"_buildProxyRequestCookieString",
"(",
")",
")",
";",
"curl_setopt",
"(",
"$",
"curl_handle",
",",
"CURLOPT_HTTPHEADER",
",",
"$",
"this",
"->",
"_generateProxyRequestHeaders",
"(",
")",
")",
";",
"$",
"response",
"=",
"curl_exec",
"(",
"$",
"curl_handle",
")",
";",
"if",
"(",
"false",
"===",
"$",
"response",
")",
"{",
"var_dump",
"(",
"curl_error",
"(",
"$",
"curl_handle",
")",
")",
";",
"}",
"else",
"{",
"return",
"$",
"response",
";",
"}",
"}"
] | Given the object's current settings, make a request to the given url
using the cURL library
@param string $url The url to make the request to
@return string The full HTTP response | [
"Given",
"the",
"object",
"s",
"current",
"settings",
"make",
"a",
"request",
"to",
"the",
"given",
"url",
"using",
"the",
"cURL",
"library"
] | 43c3216038b7a65b99f7d1caf3b838424b6b8d3c | https://github.com/lanthaler/HydraConsole/blob/43c3216038b7a65b99f7d1caf3b838424b6b8d3c/proxylib.php#L385-L408 |
34,969 | lanthaler/HydraConsole | proxylib.php | AjaxProxy._makeFOpenRequest | protected function _makeFOpenRequest($url)
{
$context = $this->_buildFOpenStreamContext();
$file_pointer = @fopen($url, 'r', null, $context);
if(!$file_pointer)
throw new Exception("There was an error making the request. Make sure that the url is valid, and either fopen or cURL are available.");
$meta = stream_get_meta_data($file_pointer);
$headers = $this->_buildResponseHeaderFromMeta($meta);
$content = stream_get_contents($file_pointer);
fclose($file_pointer);
return "$headers\r\n\r\n$content";
} | php | protected function _makeFOpenRequest($url)
{
$context = $this->_buildFOpenStreamContext();
$file_pointer = @fopen($url, 'r', null, $context);
if(!$file_pointer)
throw new Exception("There was an error making the request. Make sure that the url is valid, and either fopen or cURL are available.");
$meta = stream_get_meta_data($file_pointer);
$headers = $this->_buildResponseHeaderFromMeta($meta);
$content = stream_get_contents($file_pointer);
fclose($file_pointer);
return "$headers\r\n\r\n$content";
} | [
"protected",
"function",
"_makeFOpenRequest",
"(",
"$",
"url",
")",
"{",
"$",
"context",
"=",
"$",
"this",
"->",
"_buildFOpenStreamContext",
"(",
")",
";",
"$",
"file_pointer",
"=",
"@",
"fopen",
"(",
"$",
"url",
",",
"'r'",
",",
"null",
",",
"$",
"context",
")",
";",
"if",
"(",
"!",
"$",
"file_pointer",
")",
"throw",
"new",
"Exception",
"(",
"\"There was an error making the request. Make sure that the url is valid, and either fopen or cURL are available.\"",
")",
";",
"$",
"meta",
"=",
"stream_get_meta_data",
"(",
"$",
"file_pointer",
")",
";",
"$",
"headers",
"=",
"$",
"this",
"->",
"_buildResponseHeaderFromMeta",
"(",
"$",
"meta",
")",
";",
"$",
"content",
"=",
"stream_get_contents",
"(",
"$",
"file_pointer",
")",
";",
"fclose",
"(",
"$",
"file_pointer",
")",
";",
"return",
"\"$headers\\r\\n\\r\\n$content\"",
";",
"}"
] | Given the object's current settings, make a request to the supplied url
using PHP's native, less speedy, fopen functions
@param string $url The url to make the request to
@return string The full HTTP response | [
"Given",
"the",
"object",
"s",
"current",
"settings",
"make",
"a",
"request",
"to",
"the",
"supplied",
"url",
"using",
"PHP",
"s",
"native",
"less",
"speedy",
"fopen",
"functions"
] | 43c3216038b7a65b99f7d1caf3b838424b6b8d3c | https://github.com/lanthaler/HydraConsole/blob/43c3216038b7a65b99f7d1caf3b838424b6b8d3c/proxylib.php#L416-L431 |
34,970 | lanthaler/HydraConsole | proxylib.php | AjaxProxy._buildResponseHeaderFromMeta | protected function _buildResponseHeaderFromMeta($meta)
{
if(! array_key_exists('wrapper_data', $meta))
throw new Exception("Did not receive a valid response from the server");
$headers = $meta['wrapper_data'];
/**
* When using stream_context_create, if the socket is redirected via a
* 302, PHP just adds the 302 headers onto the wrapper_data array
* in addition to the headers from the redirected page. We only
* want the redirected page's headers.
*/
$last_status = 0;
for($i = 0; $i < count($headers); $i++)
{
if(strpos($headers[$i], 'HTTP/') === 0)
{
$last_status = $i;
}
}
# Get the applicable portion of the headers
$headers = array_slice($headers, $last_status);
return implode("\n", $headers);
} | php | protected function _buildResponseHeaderFromMeta($meta)
{
if(! array_key_exists('wrapper_data', $meta))
throw new Exception("Did not receive a valid response from the server");
$headers = $meta['wrapper_data'];
/**
* When using stream_context_create, if the socket is redirected via a
* 302, PHP just adds the 302 headers onto the wrapper_data array
* in addition to the headers from the redirected page. We only
* want the redirected page's headers.
*/
$last_status = 0;
for($i = 0; $i < count($headers); $i++)
{
if(strpos($headers[$i], 'HTTP/') === 0)
{
$last_status = $i;
}
}
# Get the applicable portion of the headers
$headers = array_slice($headers, $last_status);
return implode("\n", $headers);
} | [
"protected",
"function",
"_buildResponseHeaderFromMeta",
"(",
"$",
"meta",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"'wrapper_data'",
",",
"$",
"meta",
")",
")",
"throw",
"new",
"Exception",
"(",
"\"Did not receive a valid response from the server\"",
")",
";",
"$",
"headers",
"=",
"$",
"meta",
"[",
"'wrapper_data'",
"]",
";",
"/**\r\n * When using stream_context_create, if the socket is redirected via a\r\n * 302, PHP just adds the 302 headers onto the wrapper_data array\r\n * in addition to the headers from the redirected page. We only\r\n * want the redirected page's headers.\r\n */",
"$",
"last_status",
"=",
"0",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"headers",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"headers",
"[",
"$",
"i",
"]",
",",
"'HTTP/'",
")",
"===",
"0",
")",
"{",
"$",
"last_status",
"=",
"$",
"i",
";",
"}",
"}",
"# Get the applicable portion of the headers\r",
"$",
"headers",
"=",
"array_slice",
"(",
"$",
"headers",
",",
"$",
"last_status",
")",
";",
"return",
"implode",
"(",
"\"\\n\"",
",",
"$",
"headers",
")",
";",
"}"
] | Given an associative array returned by PHP's methods to get stream meta,
extract the HTTP response header from it
@param array $meta The associative array contianing stream information
@return array | [
"Given",
"an",
"associative",
"array",
"returned",
"by",
"PHP",
"s",
"methods",
"to",
"get",
"stream",
"meta",
"extract",
"the",
"HTTP",
"response",
"header",
"from",
"it"
] | 43c3216038b7a65b99f7d1caf3b838424b6b8d3c | https://github.com/lanthaler/HydraConsole/blob/43c3216038b7a65b99f7d1caf3b838424b6b8d3c/proxylib.php#L439-L465 |
34,971 | lanthaler/HydraConsole | proxylib.php | AjaxProxy._parseResponse | protected function _parseResponse()
{
/**
* According to the HTTP spec, we have to respect \n\n too
* @todo: Respect \n\n
*/
$break_1 = strpos($this->_rawResponse, "\r\n\r\n");
$break_2 = strpos($this->_rawResponse, "\n\n");
$break = 0;
if ($break_1 && $break_2 === FALSE) $break = $break_1;
elseif($break_2 && $break_1 === FALSE) $break = $break_2;
elseif($break_1 < $break_2) $break = $break_1;
else $break = $break_2;
# Let's check to see if we recieved a header but no body
if($break === FALSE)
{
if(strpos($this->_rawResponse, 'HTTP/') !== FALSE)
{
$break = strlen($this->_rawResponse);
}
else
{
throw new Exception("A valid response was not received from the host");
}
}
$header = substr($this->_rawResponse, 0, $break);
$this->_responseHeaders = $this->_parseResponseHeaders($header);
$this->_responseBody = substr($this->_rawResponse, $break + 3);
} | php | protected function _parseResponse()
{
/**
* According to the HTTP spec, we have to respect \n\n too
* @todo: Respect \n\n
*/
$break_1 = strpos($this->_rawResponse, "\r\n\r\n");
$break_2 = strpos($this->_rawResponse, "\n\n");
$break = 0;
if ($break_1 && $break_2 === FALSE) $break = $break_1;
elseif($break_2 && $break_1 === FALSE) $break = $break_2;
elseif($break_1 < $break_2) $break = $break_1;
else $break = $break_2;
# Let's check to see if we recieved a header but no body
if($break === FALSE)
{
if(strpos($this->_rawResponse, 'HTTP/') !== FALSE)
{
$break = strlen($this->_rawResponse);
}
else
{
throw new Exception("A valid response was not received from the host");
}
}
$header = substr($this->_rawResponse, 0, $break);
$this->_responseHeaders = $this->_parseResponseHeaders($header);
$this->_responseBody = substr($this->_rawResponse, $break + 3);
} | [
"protected",
"function",
"_parseResponse",
"(",
")",
"{",
"/**\r\n * According to the HTTP spec, we have to respect \\n\\n too\r\n * @todo: Respect \\n\\n\r\n */",
"$",
"break_1",
"=",
"strpos",
"(",
"$",
"this",
"->",
"_rawResponse",
",",
"\"\\r\\n\\r\\n\"",
")",
";",
"$",
"break_2",
"=",
"strpos",
"(",
"$",
"this",
"->",
"_rawResponse",
",",
"\"\\n\\n\"",
")",
";",
"$",
"break",
"=",
"0",
";",
"if",
"(",
"$",
"break_1",
"&&",
"$",
"break_2",
"===",
"FALSE",
")",
"$",
"break",
"=",
"$",
"break_1",
";",
"elseif",
"(",
"$",
"break_2",
"&&",
"$",
"break_1",
"===",
"FALSE",
")",
"$",
"break",
"=",
"$",
"break_2",
";",
"elseif",
"(",
"$",
"break_1",
"<",
"$",
"break_2",
")",
"$",
"break",
"=",
"$",
"break_1",
";",
"else",
"$",
"break",
"=",
"$",
"break_2",
";",
"# Let's check to see if we recieved a header but no body\r",
"if",
"(",
"$",
"break",
"===",
"FALSE",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"this",
"->",
"_rawResponse",
",",
"'HTTP/'",
")",
"!==",
"FALSE",
")",
"{",
"$",
"break",
"=",
"strlen",
"(",
"$",
"this",
"->",
"_rawResponse",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"\"A valid response was not received from the host\"",
")",
";",
"}",
"}",
"$",
"header",
"=",
"substr",
"(",
"$",
"this",
"->",
"_rawResponse",
",",
"0",
",",
"$",
"break",
")",
";",
"$",
"this",
"->",
"_responseHeaders",
"=",
"$",
"this",
"->",
"_parseResponseHeaders",
"(",
"$",
"header",
")",
";",
"$",
"this",
"->",
"_responseBody",
"=",
"substr",
"(",
"$",
"this",
"->",
"_rawResponse",
",",
"$",
"break",
"+",
"3",
")",
";",
"}"
] | Parse the headers and the body out of the raw response sent back by the
server. Store them in _responseHeaders and _responseBody.
@throws Exception When the server does not give us a valid response | [
"Parse",
"the",
"headers",
"and",
"the",
"body",
"out",
"of",
"the",
"raw",
"response",
"sent",
"back",
"by",
"the",
"server",
".",
"Store",
"them",
"in",
"_responseHeaders",
"and",
"_responseBody",
"."
] | 43c3216038b7a65b99f7d1caf3b838424b6b8d3c | https://github.com/lanthaler/HydraConsole/blob/43c3216038b7a65b99f7d1caf3b838424b6b8d3c/proxylib.php#L501-L532 |
34,972 | lanthaler/HydraConsole | proxylib.php | AjaxProxy._parseResponseHeaders | protected function _parseResponseHeaders($headers)
{
$headers = str_replace("\r", "", $headers);
$headers = explode("\n", $headers);
$parsed = array();
foreach($headers as $header)
{
$field_end = strpos($header, ':');
if($field_end === FALSE)
{
/* Cover the case where we're at the first header, the HTTP
* status header
*/
$field = 'status';
$value = $header;
}
else
{
$field = substr($header, 0, $field_end);
$value = substr($header, $field_end + 1);
}
$parsed[$field] = $value;
}
return $parsed;
} | php | protected function _parseResponseHeaders($headers)
{
$headers = str_replace("\r", "", $headers);
$headers = explode("\n", $headers);
$parsed = array();
foreach($headers as $header)
{
$field_end = strpos($header, ':');
if($field_end === FALSE)
{
/* Cover the case where we're at the first header, the HTTP
* status header
*/
$field = 'status';
$value = $header;
}
else
{
$field = substr($header, 0, $field_end);
$value = substr($header, $field_end + 1);
}
$parsed[$field] = $value;
}
return $parsed;
} | [
"protected",
"function",
"_parseResponseHeaders",
"(",
"$",
"headers",
")",
"{",
"$",
"headers",
"=",
"str_replace",
"(",
"\"\\r\"",
",",
"\"\"",
",",
"$",
"headers",
")",
";",
"$",
"headers",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"headers",
")",
";",
"$",
"parsed",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"header",
")",
"{",
"$",
"field_end",
"=",
"strpos",
"(",
"$",
"header",
",",
"':'",
")",
";",
"if",
"(",
"$",
"field_end",
"===",
"FALSE",
")",
"{",
"/* Cover the case where we're at the first header, the HTTP\r\n * status header\r\n */",
"$",
"field",
"=",
"'status'",
";",
"$",
"value",
"=",
"$",
"header",
";",
"}",
"else",
"{",
"$",
"field",
"=",
"substr",
"(",
"$",
"header",
",",
"0",
",",
"$",
"field_end",
")",
";",
"$",
"value",
"=",
"substr",
"(",
"$",
"header",
",",
"$",
"field_end",
"+",
"1",
")",
";",
"}",
"$",
"parsed",
"[",
"$",
"field",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"parsed",
";",
"}"
] | Parse out the headers from the response and store them in a key-value
array and return it
@param string $headers A big chunk of text representing the HTTP headers
@return array A key-value array containing heder names and values | [
"Parse",
"out",
"the",
"headers",
"from",
"the",
"response",
"and",
"store",
"them",
"in",
"a",
"key",
"-",
"value",
"array",
"and",
"return",
"it"
] | 43c3216038b7a65b99f7d1caf3b838424b6b8d3c | https://github.com/lanthaler/HydraConsole/blob/43c3216038b7a65b99f7d1caf3b838424b6b8d3c/proxylib.php#L540-L568 |
34,973 | lanthaler/HydraConsole | proxylib.php | AjaxProxy._generateProxyRequestHeaders | protected function _generateProxyRequestHeaders($as_string = FALSE)
{
$headers = array();
$headers[] = 'Content-Type: ' . $this->_requestContentType;
if ($this->_requestAuthorization) {
$headers[] = 'Authorization: ' . $this->_requestAuthorization;
}
if ($this->_requestAccept) {
$headers[] = 'Accept: ' . $this->_requestAccept;
}
if($as_string)
{
$data = "";
foreach($headers as $value)
if($value)
$data .= "$value\n";
$headers = $data;
}
return $headers;
} | php | protected function _generateProxyRequestHeaders($as_string = FALSE)
{
$headers = array();
$headers[] = 'Content-Type: ' . $this->_requestContentType;
if ($this->_requestAuthorization) {
$headers[] = 'Authorization: ' . $this->_requestAuthorization;
}
if ($this->_requestAccept) {
$headers[] = 'Accept: ' . $this->_requestAccept;
}
if($as_string)
{
$data = "";
foreach($headers as $value)
if($value)
$data .= "$value\n";
$headers = $data;
}
return $headers;
} | [
"protected",
"function",
"_generateProxyRequestHeaders",
"(",
"$",
"as_string",
"=",
"FALSE",
")",
"{",
"$",
"headers",
"=",
"array",
"(",
")",
";",
"$",
"headers",
"[",
"]",
"=",
"'Content-Type: '",
".",
"$",
"this",
"->",
"_requestContentType",
";",
"if",
"(",
"$",
"this",
"->",
"_requestAuthorization",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"'Authorization: '",
".",
"$",
"this",
"->",
"_requestAuthorization",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_requestAccept",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"'Accept: '",
".",
"$",
"this",
"->",
"_requestAccept",
";",
"}",
"if",
"(",
"$",
"as_string",
")",
"{",
"$",
"data",
"=",
"\"\"",
";",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"value",
")",
"if",
"(",
"$",
"value",
")",
"$",
"data",
".=",
"\"$value\\n\"",
";",
"$",
"headers",
"=",
"$",
"data",
";",
"}",
"return",
"$",
"headers",
";",
"}"
] | Generate and return any headers needed to make the proxy request
@param bool $as_string Whether to return the headers as a string instead
of an associative array
@return array|string | [
"Generate",
"and",
"return",
"any",
"headers",
"needed",
"to",
"make",
"the",
"proxy",
"request"
] | 43c3216038b7a65b99f7d1caf3b838424b6b8d3c | https://github.com/lanthaler/HydraConsole/blob/43c3216038b7a65b99f7d1caf3b838424b6b8d3c/proxylib.php#L576-L600 |
34,974 | lanthaler/HydraConsole | proxylib.php | AjaxProxy._buildAndExecuteProxyResponse | protected function _buildAndExecuteProxyResponse()
{
if($this->_responseModifier)
{
$data = call_user_func_array($this->_responseModifier, array(&$this->_responseBody, &$this->_responseHeaders));
}
$this->_generateProxyResponseHeaders();
$this->_output($this->_responseBody);
} | php | protected function _buildAndExecuteProxyResponse()
{
if($this->_responseModifier)
{
$data = call_user_func_array($this->_responseModifier, array(&$this->_responseBody, &$this->_responseHeaders));
}
$this->_generateProxyResponseHeaders();
$this->_output($this->_responseBody);
} | [
"protected",
"function",
"_buildAndExecuteProxyResponse",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_responseModifier",
")",
"{",
"$",
"data",
"=",
"call_user_func_array",
"(",
"$",
"this",
"->",
"_responseModifier",
",",
"array",
"(",
"&",
"$",
"this",
"->",
"_responseBody",
",",
"&",
"$",
"this",
"->",
"_responseHeaders",
")",
")",
";",
"}",
"$",
"this",
"->",
"_generateProxyResponseHeaders",
"(",
")",
";",
"$",
"this",
"->",
"_output",
"(",
"$",
"this",
"->",
"_responseBody",
")",
";",
"}"
] | Generate the headers and send the final response to the output stream | [
"Generate",
"the",
"headers",
"and",
"send",
"the",
"final",
"response",
"to",
"the",
"output",
"stream"
] | 43c3216038b7a65b99f7d1caf3b838424b6b8d3c | https://github.com/lanthaler/HydraConsole/blob/43c3216038b7a65b99f7d1caf3b838424b6b8d3c/proxylib.php#L639-L649 |
34,975 | lanthaler/HydraConsole | proxylib.php | AjaxProxy.handleException | public function handleException(Exception $exception)
{
$this->_sendFatalError("Fatal proxy Exception: '"
. $exception->getMessage()
. "' in "
. $exception->getFile()
. ":"
. $exception->getLine());
} | php | public function handleException(Exception $exception)
{
$this->_sendFatalError("Fatal proxy Exception: '"
. $exception->getMessage()
. "' in "
. $exception->getFile()
. ":"
. $exception->getLine());
} | [
"public",
"function",
"handleException",
"(",
"Exception",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"_sendFatalError",
"(",
"\"Fatal proxy Exception: '\"",
".",
"$",
"exception",
"->",
"getMessage",
"(",
")",
".",
"\"' in \"",
".",
"$",
"exception",
"->",
"getFile",
"(",
")",
".",
"\":\"",
".",
"$",
"exception",
"->",
"getLine",
"(",
")",
")",
";",
"}"
] | A callback method for PHP's set_exception_handler function. Used to
handle application-wide exceptions.
@param Exception $exception The exception being thrown | [
"A",
"callback",
"method",
"for",
"PHP",
"s",
"set_exception_handler",
"function",
".",
"Used",
"to",
"handle",
"application",
"-",
"wide",
"exceptions",
"."
] | 43c3216038b7a65b99f7d1caf3b838424b6b8d3c | https://github.com/lanthaler/HydraConsole/blob/43c3216038b7a65b99f7d1caf3b838424b6b8d3c/proxylib.php#L690-L698 |
34,976 | bobthecow/Faker | src/Faker/DateTime.php | DateTime.dateTimeFormat | public static function dateTimeFormat()
{
return self::pickOne(array(
DATE_ATOM,
DATE_COOKIE,
DATE_ISO8601,
DATE_RFC822,
DATE_RFC850,
DATE_RFC1036,
DATE_RFC1123,
DATE_RFC2822,
DATE_RSS,
DATE_W3C,
));
} | php | public static function dateTimeFormat()
{
return self::pickOne(array(
DATE_ATOM,
DATE_COOKIE,
DATE_ISO8601,
DATE_RFC822,
DATE_RFC850,
DATE_RFC1036,
DATE_RFC1123,
DATE_RFC2822,
DATE_RSS,
DATE_W3C,
));
} | [
"public",
"static",
"function",
"dateTimeFormat",
"(",
")",
"{",
"return",
"self",
"::",
"pickOne",
"(",
"array",
"(",
"DATE_ATOM",
",",
"DATE_COOKIE",
",",
"DATE_ISO8601",
",",
"DATE_RFC822",
",",
"DATE_RFC850",
",",
"DATE_RFC1036",
",",
"DATE_RFC1123",
",",
"DATE_RFC2822",
",",
"DATE_RSS",
",",
"DATE_W3C",
",",
")",
")",
";",
"}"
] | Return a random date and time format.
@access public
@static
@return string Date and time format | [
"Return",
"a",
"random",
"date",
"and",
"time",
"format",
"."
] | 332c9ad613f3511cc30b33a49566f10bb04162a9 | https://github.com/bobthecow/Faker/blob/332c9ad613f3511cc30b33a49566f10bb04162a9/src/Faker/DateTime.php#L129-L143 |
34,977 | bobthecow/Faker | src/Faker/Address.php | Address.streetAddress | public static function streetAddress($includeSecondary = false)
{
$chunks = array(
self::pickOne(array('#####', '####', '###')),
self::streetName(),
);
if ($includeSecondary) {
$chunks[] = self::secondaryAddress();
}
return self::numerify(implode(' ', $chunks));
} | php | public static function streetAddress($includeSecondary = false)
{
$chunks = array(
self::pickOne(array('#####', '####', '###')),
self::streetName(),
);
if ($includeSecondary) {
$chunks[] = self::secondaryAddress();
}
return self::numerify(implode(' ', $chunks));
} | [
"public",
"static",
"function",
"streetAddress",
"(",
"$",
"includeSecondary",
"=",
"false",
")",
"{",
"$",
"chunks",
"=",
"array",
"(",
"self",
"::",
"pickOne",
"(",
"array",
"(",
"'#####'",
",",
"'####'",
",",
"'###'",
")",
")",
",",
"self",
"::",
"streetName",
"(",
")",
",",
")",
";",
"if",
"(",
"$",
"includeSecondary",
")",
"{",
"$",
"chunks",
"[",
"]",
"=",
"self",
"::",
"secondaryAddress",
"(",
")",
";",
"}",
"return",
"self",
"::",
"numerify",
"(",
"implode",
"(",
"' '",
",",
"$",
"chunks",
")",
")",
";",
"}"
] | Generate a random street address.
@access public
@static
@param bool $includeSecondary Include a secondary address, e.g. "Apt. 100"? (default: false)
@return string Street address | [
"Generate",
"a",
"random",
"street",
"address",
"."
] | 332c9ad613f3511cc30b33a49566f10bb04162a9 | https://github.com/bobthecow/Faker/blob/332c9ad613f3511cc30b33a49566f10bb04162a9/src/Faker/Address.php#L54-L66 |
34,978 | bobthecow/Faker | src/Faker/Address.php | Address.city | public static function city()
{
return sprintf(
self::pickOne(array(
'%1$s %2$s%4$s',
'%1$s %2$s',
'%2$s%4$s',
'%3$s%4$s',
)),
self::cityPrefix(),
Name::firstName(),
Name::lastName(),
self::citySuffix()
);
} | php | public static function city()
{
return sprintf(
self::pickOne(array(
'%1$s %2$s%4$s',
'%1$s %2$s',
'%2$s%4$s',
'%3$s%4$s',
)),
self::cityPrefix(),
Name::firstName(),
Name::lastName(),
self::citySuffix()
);
} | [
"public",
"static",
"function",
"city",
"(",
")",
"{",
"return",
"sprintf",
"(",
"self",
"::",
"pickOne",
"(",
"array",
"(",
"'%1$s %2$s%4$s'",
",",
"'%1$s %2$s'",
",",
"'%2$s%4$s'",
",",
"'%3$s%4$s'",
",",
")",
")",
",",
"self",
"::",
"cityPrefix",
"(",
")",
",",
"Name",
"::",
"firstName",
"(",
")",
",",
"Name",
"::",
"lastName",
"(",
")",
",",
"self",
"::",
"citySuffix",
"(",
")",
")",
";",
"}"
] | Generate a random city name.
@access public
@static
@return string City name | [
"Generate",
"a",
"random",
"city",
"name",
"."
] | 332c9ad613f3511cc30b33a49566f10bb04162a9 | https://github.com/bobthecow/Faker/blob/332c9ad613f3511cc30b33a49566f10bb04162a9/src/Faker/Address.php#L114-L128 |
34,979 | bobthecow/Faker | src/Faker/Geo.php | Geo.point | public static function point(array $bounds = null)
{
if ($bounds === null) {
$bounds = static::bounds();
}
return array(
self::LAT => self::randFloat(self::latRange($bounds)),
self::LNG => self::randFloat(self::lngRange($bounds)),
);
} | php | public static function point(array $bounds = null)
{
if ($bounds === null) {
$bounds = static::bounds();
}
return array(
self::LAT => self::randFloat(self::latRange($bounds)),
self::LNG => self::randFloat(self::lngRange($bounds)),
);
} | [
"public",
"static",
"function",
"point",
"(",
"array",
"$",
"bounds",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"bounds",
"===",
"null",
")",
"{",
"$",
"bounds",
"=",
"static",
"::",
"bounds",
"(",
")",
";",
"}",
"return",
"array",
"(",
"self",
"::",
"LAT",
"=>",
"self",
"::",
"randFloat",
"(",
"self",
"::",
"latRange",
"(",
"$",
"bounds",
")",
")",
",",
"self",
"::",
"LNG",
"=>",
"self",
"::",
"randFloat",
"(",
"self",
"::",
"lngRange",
"(",
"$",
"bounds",
")",
")",
",",
")",
";",
"}"
] | Generate random coordinates, as an array.
@access public
@static
@param array $bounds
@return array [$lat, $lng] | [
"Generate",
"random",
"coordinates",
"as",
"an",
"array",
"."
] | 332c9ad613f3511cc30b33a49566f10bb04162a9 | https://github.com/bobthecow/Faker/blob/332c9ad613f3511cc30b33a49566f10bb04162a9/src/Faker/Geo.php#L57-L67 |
34,980 | bobthecow/Faker | src/Faker/Geo.php | Geo.pointDMS | public static function pointDMS(array $bounds = null)
{
list($lat, $lng) = static::point($bounds);
return sprintf('%s %s', self::floatToDMS($lat), self::floatToDMS($lng));
} | php | public static function pointDMS(array $bounds = null)
{
list($lat, $lng) = static::point($bounds);
return sprintf('%s %s', self::floatToDMS($lat), self::floatToDMS($lng));
} | [
"public",
"static",
"function",
"pointDMS",
"(",
"array",
"$",
"bounds",
"=",
"null",
")",
"{",
"list",
"(",
"$",
"lat",
",",
"$",
"lng",
")",
"=",
"static",
"::",
"point",
"(",
"$",
"bounds",
")",
";",
"return",
"sprintf",
"(",
"'%s %s'",
",",
"self",
"::",
"floatToDMS",
"(",
"$",
"lat",
")",
",",
"self",
"::",
"floatToDMS",
"(",
"$",
"lng",
")",
")",
";",
"}"
] | Generate random coordinates, formatted as degrees, minutes and seconds.
45°30'15" -90°30'15"
@access public
@static
@param array $bounds
@return string Formatted coordinates | [
"Generate",
"random",
"coordinates",
"formatted",
"as",
"degrees",
"minutes",
"and",
"seconds",
"."
] | 332c9ad613f3511cc30b33a49566f10bb04162a9 | https://github.com/bobthecow/Faker/blob/332c9ad613f3511cc30b33a49566f10bb04162a9/src/Faker/Geo.php#L79-L84 |
34,981 | bobthecow/Faker | src/Faker/Internet.php | Internet.userName | public static function userName($name = null)
{
if ($name !== null) {
$email = preg_split('/\W+/', $name);
shuffle($email);
$email = implode(self::separator(), $email);
} else {
$email = sprintf(
self::pickOne(array(
'%s',
'%s%s%s'
)),
Name::firstName(),
self::separator(),
Name::lastName()
);
}
return strtolower(preg_replace('/\W/', '', $email));
} | php | public static function userName($name = null)
{
if ($name !== null) {
$email = preg_split('/\W+/', $name);
shuffle($email);
$email = implode(self::separator(), $email);
} else {
$email = sprintf(
self::pickOne(array(
'%s',
'%s%s%s'
)),
Name::firstName(),
self::separator(),
Name::lastName()
);
}
return strtolower(preg_replace('/\W/', '', $email));
} | [
"public",
"static",
"function",
"userName",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"name",
"!==",
"null",
")",
"{",
"$",
"email",
"=",
"preg_split",
"(",
"'/\\W+/'",
",",
"$",
"name",
")",
";",
"shuffle",
"(",
"$",
"email",
")",
";",
"$",
"email",
"=",
"implode",
"(",
"self",
"::",
"separator",
"(",
")",
",",
"$",
"email",
")",
";",
"}",
"else",
"{",
"$",
"email",
"=",
"sprintf",
"(",
"self",
"::",
"pickOne",
"(",
"array",
"(",
"'%s'",
",",
"'%s%s%s'",
")",
")",
",",
"Name",
"::",
"firstName",
"(",
")",
",",
"self",
"::",
"separator",
"(",
")",
",",
"Name",
"::",
"lastName",
"(",
")",
")",
";",
"}",
"return",
"strtolower",
"(",
"preg_replace",
"(",
"'/\\W/'",
",",
"''",
",",
"$",
"email",
")",
")",
";",
"}"
] | Generate a random username.
Optionally, supply a user's name, from which the username will be generated.
@access public
@static
@param string $name (default: null)
@return string Username | [
"Generate",
"a",
"random",
"username",
"."
] | 332c9ad613f3511cc30b33a49566f10bb04162a9 | https://github.com/bobthecow/Faker/blob/332c9ad613f3511cc30b33a49566f10bb04162a9/src/Faker/Internet.php#L87-L106 |
34,982 | bobthecow/Faker | src/Faker/Lorem.php | Lorem.sentences | public static function sentences($sentenceCount = 3)
{
$ret = array();
for ($i = 0; $i < $sentenceCount; $i++) {
$ret[] = self::sentence();
}
return $ret;
} | php | public static function sentences($sentenceCount = 3)
{
$ret = array();
for ($i = 0; $i < $sentenceCount; $i++) {
$ret[] = self::sentence();
}
return $ret;
} | [
"public",
"static",
"function",
"sentences",
"(",
"$",
"sentenceCount",
"=",
"3",
")",
"{",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"sentenceCount",
";",
"$",
"i",
"++",
")",
"{",
"$",
"ret",
"[",
"]",
"=",
"self",
"::",
"sentence",
"(",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Generate random sentences.
@access public
@static
@param int $sentenceCount Number of sentences (default: 3)
@return array Sentences | [
"Generate",
"random",
"sentences",
"."
] | 332c9ad613f3511cc30b33a49566f10bb04162a9 | https://github.com/bobthecow/Faker/blob/332c9ad613f3511cc30b33a49566f10bb04162a9/src/Faker/Lorem.php#L99-L106 |
34,983 | bobthecow/Faker | src/Faker/Lorem.php | Lorem.paragraphs | public static function paragraphs($paragraphCount = 3)
{
$ret = array();
for ($i = 0; $i < $paragraphCount; $i++) {
$ret[] = self::paragraph();
}
return $ret;
} | php | public static function paragraphs($paragraphCount = 3)
{
$ret = array();
for ($i = 0; $i < $paragraphCount; $i++) {
$ret[] = self::paragraph();
}
return $ret;
} | [
"public",
"static",
"function",
"paragraphs",
"(",
"$",
"paragraphCount",
"=",
"3",
")",
"{",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"paragraphCount",
";",
"$",
"i",
"++",
")",
"{",
"$",
"ret",
"[",
"]",
"=",
"self",
"::",
"paragraph",
"(",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Generate random paragraphs.
@access public
@static
@param int $paragraphCount Number of paragraphs (default: 3)
@return array Paragraphs | [
"Generate",
"random",
"paragraphs",
"."
] | 332c9ad613f3511cc30b33a49566f10bb04162a9 | https://github.com/bobthecow/Faker/blob/332c9ad613f3511cc30b33a49566f10bb04162a9/src/Faker/Lorem.php#L132-L139 |
34,984 | bobthecow/Faker | src/Faker/Name.php | Name.name | public static function name()
{
return sprintf(
self::pickOne(array(
'%1$s %2$s %3$s',
'%2$s %3$s %4$s',
'%2$s %3$s',
'%2$s %3$s',
'%2$s %3$s',
'%2$s %3$s',
)),
self::prefix(),
self::firstName(),
self::lastName(),
self::suffix()
);
} | php | public static function name()
{
return sprintf(
self::pickOne(array(
'%1$s %2$s %3$s',
'%2$s %3$s %4$s',
'%2$s %3$s',
'%2$s %3$s',
'%2$s %3$s',
'%2$s %3$s',
)),
self::prefix(),
self::firstName(),
self::lastName(),
self::suffix()
);
} | [
"public",
"static",
"function",
"name",
"(",
")",
"{",
"return",
"sprintf",
"(",
"self",
"::",
"pickOne",
"(",
"array",
"(",
"'%1$s %2$s %3$s'",
",",
"'%2$s %3$s %4$s'",
",",
"'%2$s %3$s'",
",",
"'%2$s %3$s'",
",",
"'%2$s %3$s'",
",",
"'%2$s %3$s'",
",",
")",
")",
",",
"self",
"::",
"prefix",
"(",
")",
",",
"self",
"::",
"firstName",
"(",
")",
",",
"self",
"::",
"lastName",
"(",
")",
",",
"self",
"::",
"suffix",
"(",
")",
")",
";",
"}"
] | Generate a random full name.
@access public
@static
@return string Full name | [
"Generate",
"a",
"random",
"full",
"name",
"."
] | 332c9ad613f3511cc30b33a49566f10bb04162a9 | https://github.com/bobthecow/Faker/blob/332c9ad613f3511cc30b33a49566f10bb04162a9/src/Faker/Name.php#L29-L45 |
34,985 | bobthecow/Faker | src/Faker/Company.php | Company.name | public static function name()
{
return sprintf(
self::pickOne(array(
'%1$s %4$s',
'%1$s-%2$s',
'%1$s, %2$s and %3$s'
)),
Name::lastName(),
Name::lastName(),
Name::lastName(),
self::suffix()
);
} | php | public static function name()
{
return sprintf(
self::pickOne(array(
'%1$s %4$s',
'%1$s-%2$s',
'%1$s, %2$s and %3$s'
)),
Name::lastName(),
Name::lastName(),
Name::lastName(),
self::suffix()
);
} | [
"public",
"static",
"function",
"name",
"(",
")",
"{",
"return",
"sprintf",
"(",
"self",
"::",
"pickOne",
"(",
"array",
"(",
"'%1$s %4$s'",
",",
"'%1$s-%2$s'",
",",
"'%1$s, %2$s and %3$s'",
")",
")",
",",
"Name",
"::",
"lastName",
"(",
")",
",",
"Name",
"::",
"lastName",
"(",
")",
",",
"Name",
"::",
"lastName",
"(",
")",
",",
"self",
"::",
"suffix",
"(",
")",
")",
";",
"}"
] | Generate a fake company name.
@access public
@static
@return string Company name | [
"Generate",
"a",
"fake",
"company",
"name",
"."
] | 332c9ad613f3511cc30b33a49566f10bb04162a9 | https://github.com/bobthecow/Faker/blob/332c9ad613f3511cc30b33a49566f10bb04162a9/src/Faker/Company.php#L29-L42 |
34,986 | ostark/craft-async-queue | src/ProcessPool.php | ProcessPool.canIUse | public function canIUse($context = null)
{
$poolUsage = $this->cache->get(self::CACHE_KEY) ?: 0;
$this->logPoolUsage($poolUsage, $context);
return ($poolUsage < $this->maxItems) ? true : false;
} | php | public function canIUse($context = null)
{
$poolUsage = $this->cache->get(self::CACHE_KEY) ?: 0;
$this->logPoolUsage($poolUsage, $context);
return ($poolUsage < $this->maxItems) ? true : false;
} | [
"public",
"function",
"canIUse",
"(",
"$",
"context",
"=",
"null",
")",
"{",
"$",
"poolUsage",
"=",
"$",
"this",
"->",
"cache",
"->",
"get",
"(",
"self",
"::",
"CACHE_KEY",
")",
"?",
":",
"0",
";",
"$",
"this",
"->",
"logPoolUsage",
"(",
"$",
"poolUsage",
",",
"$",
"context",
")",
";",
"return",
"(",
"$",
"poolUsage",
"<",
"$",
"this",
"->",
"maxItems",
")",
"?",
"true",
":",
"false",
";",
"}"
] | Check if there is room
@param mixed $context
@return bool | [
"Check",
"if",
"there",
"is",
"room"
] | ba6ef528473ab352e1fb5be23c1550f56570efc0 | https://github.com/ostark/craft-async-queue/blob/ba6ef528473ab352e1fb5be23c1550f56570efc0/src/ProcessPool.php#L55-L61 |
34,987 | ostark/craft-async-queue | src/ProcessPool.php | ProcessPool.increment | public function increment($context = null)
{
$poolUsage = $this->cache->get(self::CACHE_KEY) ?: 0;
$this->logPoolUsage($poolUsage, $context);
$this->cache->set(self::CACHE_KEY, $poolUsage + 1, $this->lifetime);
} | php | public function increment($context = null)
{
$poolUsage = $this->cache->get(self::CACHE_KEY) ?: 0;
$this->logPoolUsage($poolUsage, $context);
$this->cache->set(self::CACHE_KEY, $poolUsage + 1, $this->lifetime);
} | [
"public",
"function",
"increment",
"(",
"$",
"context",
"=",
"null",
")",
"{",
"$",
"poolUsage",
"=",
"$",
"this",
"->",
"cache",
"->",
"get",
"(",
"self",
"::",
"CACHE_KEY",
")",
"?",
":",
"0",
";",
"$",
"this",
"->",
"logPoolUsage",
"(",
"$",
"poolUsage",
",",
"$",
"context",
")",
";",
"$",
"this",
"->",
"cache",
"->",
"set",
"(",
"self",
"::",
"CACHE_KEY",
",",
"$",
"poolUsage",
"+",
"1",
",",
"$",
"this",
"->",
"lifetime",
")",
";",
"}"
] | Add one item to pool
@param mixed $context | [
"Add",
"one",
"item",
"to",
"pool"
] | ba6ef528473ab352e1fb5be23c1550f56570efc0 | https://github.com/ostark/craft-async-queue/blob/ba6ef528473ab352e1fb5be23c1550f56570efc0/src/ProcessPool.php#L69-L74 |
34,988 | ostark/craft-async-queue | src/ProcessPool.php | ProcessPool.decrement | public function decrement($context = null)
{
$poolUsage = $this->cache->get(self::CACHE_KEY) ?: 0;
$this->logPoolUsage($poolUsage, $context);
if ($poolUsage > 1) {
$this->cache->set(self::CACHE_KEY, $poolUsage - 1, $this->lifetime);
} else {
$this->cache->delete(self::CACHE_KEY);
}
} | php | public function decrement($context = null)
{
$poolUsage = $this->cache->get(self::CACHE_KEY) ?: 0;
$this->logPoolUsage($poolUsage, $context);
if ($poolUsage > 1) {
$this->cache->set(self::CACHE_KEY, $poolUsage - 1, $this->lifetime);
} else {
$this->cache->delete(self::CACHE_KEY);
}
} | [
"public",
"function",
"decrement",
"(",
"$",
"context",
"=",
"null",
")",
"{",
"$",
"poolUsage",
"=",
"$",
"this",
"->",
"cache",
"->",
"get",
"(",
"self",
"::",
"CACHE_KEY",
")",
"?",
":",
"0",
";",
"$",
"this",
"->",
"logPoolUsage",
"(",
"$",
"poolUsage",
",",
"$",
"context",
")",
";",
"if",
"(",
"$",
"poolUsage",
">",
"1",
")",
"{",
"$",
"this",
"->",
"cache",
"->",
"set",
"(",
"self",
"::",
"CACHE_KEY",
",",
"$",
"poolUsage",
"-",
"1",
",",
"$",
"this",
"->",
"lifetime",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"cache",
"->",
"delete",
"(",
"self",
"::",
"CACHE_KEY",
")",
";",
"}",
"}"
] | Remove one item from pool
@param mixed $context | [
"Remove",
"one",
"item",
"from",
"pool"
] | ba6ef528473ab352e1fb5be23c1550f56570efc0 | https://github.com/ostark/craft-async-queue/blob/ba6ef528473ab352e1fb5be23c1550f56570efc0/src/ProcessPool.php#L81-L90 |
34,989 | approached/laravel-image-optimizer | src/ImageOptimizer.php | ImageOptimizer.optimizeImage | public function optimizeImage($filepath)
{
$fileExtension = $this->extensions[mime_content_type($filepath)];
$transformHandler = config('imageoptimizer.transform_handler');
if (!isset($transformHandler[$fileExtension])) {
throw new \Exception('TransformHandler for file extension: "' . $fileExtension . '" was not found');
}
$this->get($transformHandler[$fileExtension])->optimize($filepath);
} | php | public function optimizeImage($filepath)
{
$fileExtension = $this->extensions[mime_content_type($filepath)];
$transformHandler = config('imageoptimizer.transform_handler');
if (!isset($transformHandler[$fileExtension])) {
throw new \Exception('TransformHandler for file extension: "' . $fileExtension . '" was not found');
}
$this->get($transformHandler[$fileExtension])->optimize($filepath);
} | [
"public",
"function",
"optimizeImage",
"(",
"$",
"filepath",
")",
"{",
"$",
"fileExtension",
"=",
"$",
"this",
"->",
"extensions",
"[",
"mime_content_type",
"(",
"$",
"filepath",
")",
"]",
";",
"$",
"transformHandler",
"=",
"config",
"(",
"'imageoptimizer.transform_handler'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"transformHandler",
"[",
"$",
"fileExtension",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'TransformHandler for file extension: \"'",
".",
"$",
"fileExtension",
".",
"'\" was not found'",
")",
";",
"}",
"$",
"this",
"->",
"get",
"(",
"$",
"transformHandler",
"[",
"$",
"fileExtension",
"]",
")",
"->",
"optimize",
"(",
"$",
"filepath",
")",
";",
"}"
] | Opitimize a image.
@param $filepath
@throws \Exception | [
"Opitimize",
"a",
"image",
"."
] | 5e822ebe1c366c43a3cec484d45b37c8c56fb383 | https://github.com/approached/laravel-image-optimizer/blob/5e822ebe1c366c43a3cec484d45b37c8c56fb383/src/ImageOptimizer.php#L24-L35 |
34,990 | approached/laravel-image-optimizer | src/ImageOptimizer.php | ImageOptimizer.getFileExtensionFromFilepath | private function getFileExtensionFromFilepath($filepath)
{
$fileExtension = pathinfo($filepath, PATHINFO_EXTENSION);
if (empty($fileExtension)) {
throw new \Exception('File extension not found');
}
return $fileExtension;
} | php | private function getFileExtensionFromFilepath($filepath)
{
$fileExtension = pathinfo($filepath, PATHINFO_EXTENSION);
if (empty($fileExtension)) {
throw new \Exception('File extension not found');
}
return $fileExtension;
} | [
"private",
"function",
"getFileExtensionFromFilepath",
"(",
"$",
"filepath",
")",
"{",
"$",
"fileExtension",
"=",
"pathinfo",
"(",
"$",
"filepath",
",",
"PATHINFO_EXTENSION",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"fileExtension",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'File extension not found'",
")",
";",
"}",
"return",
"$",
"fileExtension",
";",
"}"
] | Get extension from a file.
@param $filepath
@throws \Exception
@return string | [
"Get",
"extension",
"from",
"a",
"file",
"."
] | 5e822ebe1c366c43a3cec484d45b37c8c56fb383 | https://github.com/approached/laravel-image-optimizer/blob/5e822ebe1c366c43a3cec484d45b37c8c56fb383/src/ImageOptimizer.php#L58-L67 |
34,991 | letrunghieu/wordpress-xmlrpc-client | src/WordpressClient.php | WordpressClient.setCredentials | function setCredentials($xmlrpcEndPoint, $username, $password)
{
// prepend http protocol to the end point if needed
$scheme = parse_url($xmlrpcEndPoint, PHP_URL_SCHEME);
if (!$scheme) {
$xmlrpcEndPoint = "http://{$xmlrpcEndPoint}";
}
// swith to https when working with wordpress.com blogs
$host = parse_url($xmlrpcEndPoint, PHP_URL_HOST);
if (substr($host, -14) == '.wordpress.com') {
$xmlrpcEndPoint = preg_replace('|http://|', 'https://', $xmlrpcEndPoint, 1);
}
// save information
$this->endPoint = $xmlrpcEndPoint;
$this->username = $username;
$this->password = $password;
} | php | function setCredentials($xmlrpcEndPoint, $username, $password)
{
// prepend http protocol to the end point if needed
$scheme = parse_url($xmlrpcEndPoint, PHP_URL_SCHEME);
if (!$scheme) {
$xmlrpcEndPoint = "http://{$xmlrpcEndPoint}";
}
// swith to https when working with wordpress.com blogs
$host = parse_url($xmlrpcEndPoint, PHP_URL_HOST);
if (substr($host, -14) == '.wordpress.com') {
$xmlrpcEndPoint = preg_replace('|http://|', 'https://', $xmlrpcEndPoint, 1);
}
// save information
$this->endPoint = $xmlrpcEndPoint;
$this->username = $username;
$this->password = $password;
} | [
"function",
"setCredentials",
"(",
"$",
"xmlrpcEndPoint",
",",
"$",
"username",
",",
"$",
"password",
")",
"{",
"// prepend http protocol to the end point if needed",
"$",
"scheme",
"=",
"parse_url",
"(",
"$",
"xmlrpcEndPoint",
",",
"PHP_URL_SCHEME",
")",
";",
"if",
"(",
"!",
"$",
"scheme",
")",
"{",
"$",
"xmlrpcEndPoint",
"=",
"\"http://{$xmlrpcEndPoint}\"",
";",
"}",
"// swith to https when working with wordpress.com blogs",
"$",
"host",
"=",
"parse_url",
"(",
"$",
"xmlrpcEndPoint",
",",
"PHP_URL_HOST",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"host",
",",
"-",
"14",
")",
"==",
"'.wordpress.com'",
")",
"{",
"$",
"xmlrpcEndPoint",
"=",
"preg_replace",
"(",
"'|http://|'",
",",
"'https://'",
",",
"$",
"xmlrpcEndPoint",
",",
"1",
")",
";",
"}",
"// save information",
"$",
"this",
"->",
"endPoint",
"=",
"$",
"xmlrpcEndPoint",
";",
"$",
"this",
"->",
"username",
"=",
"$",
"username",
";",
"$",
"this",
"->",
"password",
"=",
"$",
"password",
";",
"}"
] | Set the endpoint, username and password for next requests
@param string $xmlrpcEndPoint The wordpress XML-RPC endpoint
@param string $username The client's username
@param string $password The client's password
@since 2.4.0 | [
"Set",
"the",
"endpoint",
"username",
"and",
"password",
"for",
"next",
"requests"
] | 64ce550961b1885b8fc8b63dec66670f54fff28f | https://github.com/letrunghieu/wordpress-xmlrpc-client/blob/64ce550961b1885b8fc8b63dec66670f54fff28f/src/WordpressClient.php#L79-L97 |
34,992 | letrunghieu/wordpress-xmlrpc-client | src/WordpressClient.php | WordpressClient.setUserAgent | function setUserAgent($userAgent)
{
if ($userAgent) {
$this->userAgent = $userAgent;
} else {
$this->userAgent = $this->getDefaultUserAgent();
}
} | php | function setUserAgent($userAgent)
{
if ($userAgent) {
$this->userAgent = $userAgent;
} else {
$this->userAgent = $this->getDefaultUserAgent();
}
} | [
"function",
"setUserAgent",
"(",
"$",
"userAgent",
")",
"{",
"if",
"(",
"$",
"userAgent",
")",
"{",
"$",
"this",
"->",
"userAgent",
"=",
"$",
"userAgent",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"userAgent",
"=",
"$",
"this",
"->",
"getDefaultUserAgent",
"(",
")",
";",
"}",
"}"
] | Set the user agent for next requests
@param string $userAgent custom user agent, give a falsy value to use library user agent
@since 2.4.0 | [
"Set",
"the",
"user",
"agent",
"for",
"next",
"requests"
] | 64ce550961b1885b8fc8b63dec66670f54fff28f | https://github.com/letrunghieu/wordpress-xmlrpc-client/blob/64ce550961b1885b8fc8b63dec66670f54fff28f/src/WordpressClient.php#L145-L152 |
34,993 | letrunghieu/wordpress-xmlrpc-client | src/WordpressClient.php | WordpressClient.setAuth | function setAuth($authConfig)
{
if ($authConfig === false || is_array($authConfig)) {
$this->authConfig = $authConfig;
} else {
throw new \InvalidArgumentException(__METHOD__ . " only accept boolean 'false' or an array as parameter.");
}
} | php | function setAuth($authConfig)
{
if ($authConfig === false || is_array($authConfig)) {
$this->authConfig = $authConfig;
} else {
throw new \InvalidArgumentException(__METHOD__ . " only accept boolean 'false' or an array as parameter.");
}
} | [
"function",
"setAuth",
"(",
"$",
"authConfig",
")",
"{",
"if",
"(",
"$",
"authConfig",
"===",
"false",
"||",
"is_array",
"(",
"$",
"authConfig",
")",
")",
"{",
"$",
"this",
"->",
"authConfig",
"=",
"$",
"authConfig",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"\" only accept boolean 'false' or an array as parameter.\"",
")",
";",
"}",
"}"
] | Set authentication info
@param boolean|array $authConfig the configuation array
<ul>
<li><code>auth_user</code>: the username for server authentication</li>
<li><code>auth_pass</code>: the password for server authentication</li>
<li><code>auth_mode</code>: value for CURLOPT_HTTPAUTH option (default to
CURLAUTH_BASIC)</li>
</ul>
@throws \InvalidArgumentException
@see curl_setopt
@since 2.2 | [
"Set",
"authentication",
"info"
] | 64ce550961b1885b8fc8b63dec66670f54fff28f | https://github.com/letrunghieu/wordpress-xmlrpc-client/blob/64ce550961b1885b8fc8b63dec66670f54fff28f/src/WordpressClient.php#L218-L225 |
34,994 | letrunghieu/wordpress-xmlrpc-client | src/WordpressClient.php | WordpressClient.getPost | function getPost($postId, array $fields = array())
{
if (empty($fields)) {
$params = array(1, $this->username, $this->password, $postId);
} else {
$params = array(1, $this->username, $this->password, $postId, $fields);
}
return $this->sendRequest('wp.getPost', $params);
} | php | function getPost($postId, array $fields = array())
{
if (empty($fields)) {
$params = array(1, $this->username, $this->password, $postId);
} else {
$params = array(1, $this->username, $this->password, $postId, $fields);
}
return $this->sendRequest('wp.getPost', $params);
} | [
"function",
"getPost",
"(",
"$",
"postId",
",",
"array",
"$",
"fields",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"1",
",",
"$",
"this",
"->",
"username",
",",
"$",
"this",
"->",
"password",
",",
"$",
"postId",
")",
";",
"}",
"else",
"{",
"$",
"params",
"=",
"array",
"(",
"1",
",",
"$",
"this",
"->",
"username",
",",
"$",
"this",
"->",
"password",
",",
"$",
"postId",
",",
"$",
"fields",
")",
";",
"}",
"return",
"$",
"this",
"->",
"sendRequest",
"(",
"'wp.getPost'",
",",
"$",
"params",
")",
";",
"}"
] | Retrieve a post of any registered post type.
@param integer $postId the id of selected post
@param array $fields (optional) list of field or meta-field names to include in response.
@return array
@link http://codex.wordpress.org/XML-RPC_WordPress_API/Posts#wp.getPosts | [
"Retrieve",
"a",
"post",
"of",
"any",
"registered",
"post",
"type",
"."
] | 64ce550961b1885b8fc8b63dec66670f54fff28f | https://github.com/letrunghieu/wordpress-xmlrpc-client/blob/64ce550961b1885b8fc8b63dec66670f54fff28f/src/WordpressClient.php#L247-L256 |
34,995 | letrunghieu/wordpress-xmlrpc-client | src/WordpressClient.php | WordpressClient.newPost | function newPost($title, $body, array $content = array())
{
$default = array(
'post_type' => 'post',
'post_status' => 'publish',
);
$content = array_merge($default, $content);
$content['post_title'] = $title;
$content['post_content'] = $body;
$params = array(1, $this->username, $this->password, $content);
return $this->sendRequest('wp.newPost', $params);
} | php | function newPost($title, $body, array $content = array())
{
$default = array(
'post_type' => 'post',
'post_status' => 'publish',
);
$content = array_merge($default, $content);
$content['post_title'] = $title;
$content['post_content'] = $body;
$params = array(1, $this->username, $this->password, $content);
return $this->sendRequest('wp.newPost', $params);
} | [
"function",
"newPost",
"(",
"$",
"title",
",",
"$",
"body",
",",
"array",
"$",
"content",
"=",
"array",
"(",
")",
")",
"{",
"$",
"default",
"=",
"array",
"(",
"'post_type'",
"=>",
"'post'",
",",
"'post_status'",
"=>",
"'publish'",
",",
")",
";",
"$",
"content",
"=",
"array_merge",
"(",
"$",
"default",
",",
"$",
"content",
")",
";",
"$",
"content",
"[",
"'post_title'",
"]",
"=",
"$",
"title",
";",
"$",
"content",
"[",
"'post_content'",
"]",
"=",
"$",
"body",
";",
"$",
"params",
"=",
"array",
"(",
"1",
",",
"$",
"this",
"->",
"username",
",",
"$",
"this",
"->",
"password",
",",
"$",
"content",
")",
";",
"return",
"$",
"this",
"->",
"sendRequest",
"(",
"'wp.newPost'",
",",
"$",
"params",
")",
";",
"}"
] | Create a new post of any registered post type.
@param string $title the post title
@param string $body the post body
@param array $categorieIds the list of category ids
@param integer $thumbnailId the thumbnail id
@param array $content the content array, see more at wordpress documentation
@return integer the new post id
@link http://codex.wordpress.org/XML-RPC_WordPress_API/Posts#wp.newPost | [
"Create",
"a",
"new",
"post",
"of",
"any",
"registered",
"post",
"type",
"."
] | 64ce550961b1885b8fc8b63dec66670f54fff28f | https://github.com/letrunghieu/wordpress-xmlrpc-client/blob/64ce550961b1885b8fc8b63dec66670f54fff28f/src/WordpressClient.php#L290-L303 |
34,996 | letrunghieu/wordpress-xmlrpc-client | src/WordpressClient.php | WordpressClient.editPost | function editPost($postId, array $content)
{
$params = array(1, $this->username, $this->password, $postId, $content);
return $this->sendRequest('wp.editPost', $params);
} | php | function editPost($postId, array $content)
{
$params = array(1, $this->username, $this->password, $postId, $content);
return $this->sendRequest('wp.editPost', $params);
} | [
"function",
"editPost",
"(",
"$",
"postId",
",",
"array",
"$",
"content",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"1",
",",
"$",
"this",
"->",
"username",
",",
"$",
"this",
"->",
"password",
",",
"$",
"postId",
",",
"$",
"content",
")",
";",
"return",
"$",
"this",
"->",
"sendRequest",
"(",
"'wp.editPost'",
",",
"$",
"params",
")",
";",
"}"
] | Edit an existing post of any registered post type.
@param integer $postId the id of selected post
@param string $title the new title
@param string $body the new body
@param array $categorieIds the new list of category ids
@param integer $thumbnailId the new thumbnail id
@param array $content the advanced array
@return boolean
@link http://codex.wordpress.org/XML-RPC_WordPress_API/Posts#wp.editPost | [
"Edit",
"an",
"existing",
"post",
"of",
"any",
"registered",
"post",
"type",
"."
] | 64ce550961b1885b8fc8b63dec66670f54fff28f | https://github.com/letrunghieu/wordpress-xmlrpc-client/blob/64ce550961b1885b8fc8b63dec66670f54fff28f/src/WordpressClient.php#L319-L324 |
34,997 | letrunghieu/wordpress-xmlrpc-client | src/WordpressClient.php | WordpressClient.deletePost | function deletePost($postId)
{
$params = array(1, $this->username, $this->password, $postId);
return $this->sendRequest('wp.deletePost', $params);
} | php | function deletePost($postId)
{
$params = array(1, $this->username, $this->password, $postId);
return $this->sendRequest('wp.deletePost', $params);
} | [
"function",
"deletePost",
"(",
"$",
"postId",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"1",
",",
"$",
"this",
"->",
"username",
",",
"$",
"this",
"->",
"password",
",",
"$",
"postId",
")",
";",
"return",
"$",
"this",
"->",
"sendRequest",
"(",
"'wp.deletePost'",
",",
"$",
"params",
")",
";",
"}"
] | Delete an existing post of any registered post type.
@param integer $postId the id of selected post
@return boolean
@link http://codex.wordpress.org/XML-RPC_WordPress_API/Posts#wp.deletePost | [
"Delete",
"an",
"existing",
"post",
"of",
"any",
"registered",
"post",
"type",
"."
] | 64ce550961b1885b8fc8b63dec66670f54fff28f | https://github.com/letrunghieu/wordpress-xmlrpc-client/blob/64ce550961b1885b8fc8b63dec66670f54fff28f/src/WordpressClient.php#L335-L340 |
34,998 | letrunghieu/wordpress-xmlrpc-client | src/WordpressClient.php | WordpressClient.getPostType | function getPostType($postTypeName, array $fields = array())
{
$params = array(1, $this->username, $this->password, $postTypeName, $fields);
return $this->sendRequest('wp.getPostType', $params);
} | php | function getPostType($postTypeName, array $fields = array())
{
$params = array(1, $this->username, $this->password, $postTypeName, $fields);
return $this->sendRequest('wp.getPostType', $params);
} | [
"function",
"getPostType",
"(",
"$",
"postTypeName",
",",
"array",
"$",
"fields",
"=",
"array",
"(",
")",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"1",
",",
"$",
"this",
"->",
"username",
",",
"$",
"this",
"->",
"password",
",",
"$",
"postTypeName",
",",
"$",
"fields",
")",
";",
"return",
"$",
"this",
"->",
"sendRequest",
"(",
"'wp.getPostType'",
",",
"$",
"params",
")",
";",
"}"
] | Retrieve a registered post type.
@param string $postTypeName the post type name
@param array $fields (optional) list of field or meta-field names to include in response.
@return array
@link http://codex.wordpress.org/XML-RPC_WordPress_API/Posts#wp.getPostType | [
"Retrieve",
"a",
"registered",
"post",
"type",
"."
] | 64ce550961b1885b8fc8b63dec66670f54fff28f | https://github.com/letrunghieu/wordpress-xmlrpc-client/blob/64ce550961b1885b8fc8b63dec66670f54fff28f/src/WordpressClient.php#L352-L357 |
34,999 | letrunghieu/wordpress-xmlrpc-client | src/WordpressClient.php | WordpressClient.getPostTypes | function getPostTypes(array $filter = array(), array $fields = array())
{
$params = array(1, $this->username, $this->password, $filter, $fields);
return $this->sendRequest('wp.getPostTypes', $params);
} | php | function getPostTypes(array $filter = array(), array $fields = array())
{
$params = array(1, $this->username, $this->password, $filter, $fields);
return $this->sendRequest('wp.getPostTypes', $params);
} | [
"function",
"getPostTypes",
"(",
"array",
"$",
"filter",
"=",
"array",
"(",
")",
",",
"array",
"$",
"fields",
"=",
"array",
"(",
")",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"1",
",",
"$",
"this",
"->",
"username",
",",
"$",
"this",
"->",
"password",
",",
"$",
"filter",
",",
"$",
"fields",
")",
";",
"return",
"$",
"this",
"->",
"sendRequest",
"(",
"'wp.getPostTypes'",
",",
"$",
"params",
")",
";",
"}"
] | Retrieve list of registered post types.
@param array $filter
@param array $fields
@return array list of struct
@link http://codex.wordpress.org/XML-RPC_WordPress_API/Posts#wp.getPostTypes | [
"Retrieve",
"list",
"of",
"registered",
"post",
"types",
"."
] | 64ce550961b1885b8fc8b63dec66670f54fff28f | https://github.com/letrunghieu/wordpress-xmlrpc-client/blob/64ce550961b1885b8fc8b63dec66670f54fff28f/src/WordpressClient.php#L369-L374 |
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.