repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
AlexHowansky/ork-core
src/ConfigurableTrait.php
ConfigurableTrait.filterConfig
protected function filterConfig(string $name, $value = null) { $class = 'filterConfig' . ucfirst($name); if (method_exists($this, $class) === true) { $value = call_user_func([$this, $class], $value); } return $value; }
php
protected function filterConfig(string $name, $value = null) { $class = 'filterConfig' . ucfirst($name); if (method_exists($this, $class) === true) { $value = call_user_func([$this, $class], $value); } return $value; }
[ "protected", "function", "filterConfig", "(", "string", "$", "name", ",", "$", "value", "=", "null", ")", "{", "$", "class", "=", "'filterConfig'", ".", "ucfirst", "(", "$", "name", ")", ";", "if", "(", "method_exists", "(", "$", "this", ",", "$", "class", ")", "===", "true", ")", "{", "$", "value", "=", "call_user_func", "(", "[", "$", "this", ",", "$", "class", "]", ",", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}" ]
Filter a configuration attribute value as it's being set. @param string $name The name of the configuration to filter. @param mixed $value The value to filter. @return mixed The filtered value.
[ "Filter", "a", "configuration", "attribute", "value", "as", "it", "s", "being", "set", "." ]
b9c7ff50028cb63f67cb42c693fca84b8dc82796
https://github.com/AlexHowansky/ork-core/blob/b9c7ff50028cb63f67cb42c693fca84b8dc82796/src/ConfigurableTrait.php#L60-L67
train
AlexHowansky/ork-core
src/ConfigurableTrait.php
ConfigurableTrait.loadConfig
public function loadConfig(string $file): self { if (file_exists($file) === false) { throw new \RuntimeException('No such config file.'); } $data = json_decode(file_get_contents($file), true); if ($data === null) { throw new \RuntimeException('Invalid config file.'); } return $this->setConfigs($data); }
php
public function loadConfig(string $file): self { if (file_exists($file) === false) { throw new \RuntimeException('No such config file.'); } $data = json_decode(file_get_contents($file), true); if ($data === null) { throw new \RuntimeException('Invalid config file.'); } return $this->setConfigs($data); }
[ "public", "function", "loadConfig", "(", "string", "$", "file", ")", ":", "self", "{", "if", "(", "file_exists", "(", "$", "file", ")", "===", "false", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'No such config file.'", ")", ";", "}", "$", "data", "=", "json_decode", "(", "file_get_contents", "(", "$", "file", ")", ",", "true", ")", ";", "if", "(", "$", "data", "===", "null", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Invalid config file.'", ")", ";", "}", "return", "$", "this", "->", "setConfigs", "(", "$", "data", ")", ";", "}" ]
Set configuration from a JSON file. @param string $file The file containing the configuration attributes. @return self Allow method chaining. @throws \RuntimeException On error.
[ "Set", "configuration", "from", "a", "JSON", "file", "." ]
b9c7ff50028cb63f67cb42c693fca84b8dc82796
https://github.com/AlexHowansky/ork-core/blob/b9c7ff50028cb63f67cb42c693fca84b8dc82796/src/ConfigurableTrait.php#L100-L110
train
offworks/laraquent
src/Schema.php
Schema.table
public function table($table, \Closure $callback) { try { parent::create($table, $callback); } catch(\Exception $e) { try { parent::table($table, $callback); } catch(\Exception $e) { echo $e->getMessage(); } } }
php
public function table($table, \Closure $callback) { try { parent::create($table, $callback); } catch(\Exception $e) { try { parent::table($table, $callback); } catch(\Exception $e) { echo $e->getMessage(); } } }
[ "public", "function", "table", "(", "$", "table", ",", "\\", "Closure", "$", "callback", ")", "{", "try", "{", "parent", "::", "create", "(", "$", "table", ",", "$", "callback", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "try", "{", "parent", "::", "table", "(", "$", "table", ",", "$", "callback", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "echo", "$", "e", "->", "getMessage", "(", ")", ";", "}", "}", "}" ]
Create table if not exist. @param string table @param \Closure $callback
[ "Create", "table", "if", "not", "exist", "." ]
74cbc6258acfda8f7213c701887a7b223aff954f
https://github.com/offworks/laraquent/blob/74cbc6258acfda8f7213c701887a7b223aff954f/src/Schema.php#L19-L36
train
koolkode/view-express
src/Helper/AbstractViewHelper.php
AbstractViewHelper.isDynamic
protected function isDynamic(array $attributeNames) { foreach($attributeNames as $name) { if(isset($this->__attr[$name])) { return true; } } return false; }
php
protected function isDynamic(array $attributeNames) { foreach($attributeNames as $name) { if(isset($this->__attr[$name])) { return true; } } return false; }
[ "protected", "function", "isDynamic", "(", "array", "$", "attributeNames", ")", "{", "foreach", "(", "$", "attributeNames", "as", "$", "name", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "__attr", "[", "$", "name", "]", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Check if any of the given attribute names refers to a dynamic attribute. @param array<string> $attributeNames @return boolean
[ "Check", "if", "any", "of", "the", "given", "attribute", "names", "refers", "to", "a", "dynamic", "attribute", "." ]
a8ebe6f373b6bfe8b8818d6264535e8fe063a596
https://github.com/koolkode/view-express/blob/a8ebe6f373b6bfe8b8818d6264535e8fe063a596/src/Helper/AbstractViewHelper.php#L185-L196
train
koolkode/view-express
src/Helper/AbstractViewHelper.php
AbstractViewHelper.createIterator
protected function createIterator($subject) { if($subject === NULL) { return new \ArrayIterator([]); } if(is_array($subject)) { return new \ArrayIterator($subject); } if($subject instanceof \Generator) { return $subject; } if($subject instanceof \Iterator) { $subject->rewind(); return $subject; } if($subject instanceof \IteratorAggregate) { return $subject->getIterator(); } if($subject instanceof \Traversable) { return new \IteratorIterator($subject); } if(is_object($subject)) { return new \ArrayIterator(get_object_vars($subject)); } throw new \InvalidArgumentException(sprintf('Unable to create an iterator from %s', gettype($subject))); }
php
protected function createIterator($subject) { if($subject === NULL) { return new \ArrayIterator([]); } if(is_array($subject)) { return new \ArrayIterator($subject); } if($subject instanceof \Generator) { return $subject; } if($subject instanceof \Iterator) { $subject->rewind(); return $subject; } if($subject instanceof \IteratorAggregate) { return $subject->getIterator(); } if($subject instanceof \Traversable) { return new \IteratorIterator($subject); } if(is_object($subject)) { return new \ArrayIterator(get_object_vars($subject)); } throw new \InvalidArgumentException(sprintf('Unable to create an iterator from %s', gettype($subject))); }
[ "protected", "function", "createIterator", "(", "$", "subject", ")", "{", "if", "(", "$", "subject", "===", "NULL", ")", "{", "return", "new", "\\", "ArrayIterator", "(", "[", "]", ")", ";", "}", "if", "(", "is_array", "(", "$", "subject", ")", ")", "{", "return", "new", "\\", "ArrayIterator", "(", "$", "subject", ")", ";", "}", "if", "(", "$", "subject", "instanceof", "\\", "Generator", ")", "{", "return", "$", "subject", ";", "}", "if", "(", "$", "subject", "instanceof", "\\", "Iterator", ")", "{", "$", "subject", "->", "rewind", "(", ")", ";", "return", "$", "subject", ";", "}", "if", "(", "$", "subject", "instanceof", "\\", "IteratorAggregate", ")", "{", "return", "$", "subject", "->", "getIterator", "(", ")", ";", "}", "if", "(", "$", "subject", "instanceof", "\\", "Traversable", ")", "{", "return", "new", "\\", "IteratorIterator", "(", "$", "subject", ")", ";", "}", "if", "(", "is_object", "(", "$", "subject", ")", ")", "{", "return", "new", "\\", "ArrayIterator", "(", "get_object_vars", "(", "$", "subject", ")", ")", ";", "}", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Unable to create an iterator from %s'", ",", "gettype", "(", "$", "subject", ")", ")", ")", ";", "}" ]
Create an iterator from the given input, will create an ArrayIterator backed by an empty array when the input is NULL. This method will rewind any Iterator given as input (with the exception of a Generator which cannot be reset to it's initial position). @param mixed $subject @return \Iterator @throws \InvalidArgumentException When no iterator could be created for a non-object input.
[ "Create", "an", "iterator", "from", "the", "given", "input", "will", "create", "an", "ArrayIterator", "backed", "by", "an", "empty", "array", "when", "the", "input", "is", "NULL", "." ]
a8ebe6f373b6bfe8b8818d6264535e8fe063a596
https://github.com/koolkode/view-express/blob/a8ebe6f373b6bfe8b8818d6264535e8fe063a596/src/Helper/AbstractViewHelper.php#L255-L295
train
Facebook-Anonymous-Publisher/graph-api
src/GraphApi.php
GraphApi.status
public function status($message, $link = null) { $this->response = $this->fb->post('/me/feed', [ 'message' => $message, 'link' => $link, ]); return $this; }
php
public function status($message, $link = null) { $this->response = $this->fb->post('/me/feed', [ 'message' => $message, 'link' => $link, ]); return $this; }
[ "public", "function", "status", "(", "$", "message", ",", "$", "link", "=", "null", ")", "{", "$", "this", "->", "response", "=", "$", "this", "->", "fb", "->", "post", "(", "'/me/feed'", ",", "[", "'message'", "=>", "$", "message", ",", "'link'", "=>", "$", "link", ",", "]", ")", ";", "return", "$", "this", ";", "}" ]
Create a status. @param string $message @param null|string $link @return $this
[ "Create", "a", "status", "." ]
a42b8b832ca5b9a9b0c7e056c0fc10433ca1babd
https://github.com/Facebook-Anonymous-Publisher/graph-api/blob/a42b8b832ca5b9a9b0c7e056c0fc10433ca1babd/src/GraphApi.php#L41-L49
train
Facebook-Anonymous-Publisher/graph-api
src/GraphApi.php
GraphApi.photo
public function photo($source, $caption = null) { $this->response = $this->fb->post('/me/photos', [ 'source' => new FacebookFile($source), 'caption' => $caption, ]); return $this; }
php
public function photo($source, $caption = null) { $this->response = $this->fb->post('/me/photos', [ 'source' => new FacebookFile($source), 'caption' => $caption, ]); return $this; }
[ "public", "function", "photo", "(", "$", "source", ",", "$", "caption", "=", "null", ")", "{", "$", "this", "->", "response", "=", "$", "this", "->", "fb", "->", "post", "(", "'/me/photos'", ",", "[", "'source'", "=>", "new", "FacebookFile", "(", "$", "source", ")", ",", "'caption'", "=>", "$", "caption", ",", "]", ")", ";", "return", "$", "this", ";", "}" ]
Create a photo. @param string $source @param null|string $caption @return $this
[ "Create", "a", "photo", "." ]
a42b8b832ca5b9a9b0c7e056c0fc10433ca1babd
https://github.com/Facebook-Anonymous-Publisher/graph-api/blob/a42b8b832ca5b9a9b0c7e056c0fc10433ca1babd/src/GraphApi.php#L59-L67
train
Facebook-Anonymous-Publisher/graph-api
src/GraphApi.php
GraphApi.photos
public function photos(array $sources, $caption = null) { $images = $this->unpublishedPhotos($sources); $this->response = $this->fb->post('/me/feed', array_merge([ 'message' => $caption, ], $images)); return $this; }
php
public function photos(array $sources, $caption = null) { $images = $this->unpublishedPhotos($sources); $this->response = $this->fb->post('/me/feed', array_merge([ 'message' => $caption, ], $images)); return $this; }
[ "public", "function", "photos", "(", "array", "$", "sources", ",", "$", "caption", "=", "null", ")", "{", "$", "images", "=", "$", "this", "->", "unpublishedPhotos", "(", "$", "sources", ")", ";", "$", "this", "->", "response", "=", "$", "this", "->", "fb", "->", "post", "(", "'/me/feed'", ",", "array_merge", "(", "[", "'message'", "=>", "$", "caption", ",", "]", ",", "$", "images", ")", ")", ";", "return", "$", "this", ";", "}" ]
Create multiple photos. @param array $sources @param null|string $caption @return $this
[ "Create", "multiple", "photos", "." ]
a42b8b832ca5b9a9b0c7e056c0fc10433ca1babd
https://github.com/Facebook-Anonymous-Publisher/graph-api/blob/a42b8b832ca5b9a9b0c7e056c0fc10433ca1babd/src/GraphApi.php#L77-L86
train
Facebook-Anonymous-Publisher/graph-api
src/GraphApi.php
GraphApi.unpublishedPhotos
protected function unpublishedPhotos(array $sources) { $images = []; foreach ($sources as $index => $source) { $response = $this->fb ->post('/me/photos', [ 'source' => new FacebookFile($source), 'published' => false, ]) ->getDecodedBody(); $images["attached_media[{$index}]"] = sprintf('{"media_fbid":"%d"}', $response['id']); } return $images; }
php
protected function unpublishedPhotos(array $sources) { $images = []; foreach ($sources as $index => $source) { $response = $this->fb ->post('/me/photos', [ 'source' => new FacebookFile($source), 'published' => false, ]) ->getDecodedBody(); $images["attached_media[{$index}]"] = sprintf('{"media_fbid":"%d"}', $response['id']); } return $images; }
[ "protected", "function", "unpublishedPhotos", "(", "array", "$", "sources", ")", "{", "$", "images", "=", "[", "]", ";", "foreach", "(", "$", "sources", "as", "$", "index", "=>", "$", "source", ")", "{", "$", "response", "=", "$", "this", "->", "fb", "->", "post", "(", "'/me/photos'", ",", "[", "'source'", "=>", "new", "FacebookFile", "(", "$", "source", ")", ",", "'published'", "=>", "false", ",", "]", ")", "->", "getDecodedBody", "(", ")", ";", "$", "images", "[", "\"attached_media[{$index}]\"", "]", "=", "sprintf", "(", "'{\"media_fbid\":\"%d\"}'", ",", "$", "response", "[", "'id'", "]", ")", ";", "}", "return", "$", "images", ";", "}" ]
Create unpublished photos. @param array $sources @return array
[ "Create", "unpublished", "photos", "." ]
a42b8b832ca5b9a9b0c7e056c0fc10433ca1babd
https://github.com/Facebook-Anonymous-Publisher/graph-api/blob/a42b8b832ca5b9a9b0c7e056c0fc10433ca1babd/src/GraphApi.php#L95-L111
train
Facebook-Anonymous-Publisher/graph-api
src/GraphApi.php
GraphApi.getId
public function getId() { if (is_null($this->response)) { return false; } return $this->explodeId($this->response->getDecodedBody()); }
php
public function getId() { if (is_null($this->response)) { return false; } return $this->explodeId($this->response->getDecodedBody()); }
[ "public", "function", "getId", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "response", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "explodeId", "(", "$", "this", "->", "response", "->", "getDecodedBody", "(", ")", ")", ";", "}" ]
Get facebook response id. @return array|bool
[ "Get", "facebook", "response", "id", "." ]
a42b8b832ca5b9a9b0c7e056c0fc10433ca1babd
https://github.com/Facebook-Anonymous-Publisher/graph-api/blob/a42b8b832ca5b9a9b0c7e056c0fc10433ca1babd/src/GraphApi.php#L118-L125
train
Facebook-Anonymous-Publisher/graph-api
src/GraphApi.php
GraphApi.explodeId
protected function explodeId(array $body) { if (isset($body['post_id'])) { $key = 'post_id'; } elseif (isset($body['id'])) { $key = 'id'; } else { return false; } return array_combine(['id', 'fbid'], explode('_', $body[$key])); }
php
protected function explodeId(array $body) { if (isset($body['post_id'])) { $key = 'post_id'; } elseif (isset($body['id'])) { $key = 'id'; } else { return false; } return array_combine(['id', 'fbid'], explode('_', $body[$key])); }
[ "protected", "function", "explodeId", "(", "array", "$", "body", ")", "{", "if", "(", "isset", "(", "$", "body", "[", "'post_id'", "]", ")", ")", "{", "$", "key", "=", "'post_id'", ";", "}", "elseif", "(", "isset", "(", "$", "body", "[", "'id'", "]", ")", ")", "{", "$", "key", "=", "'id'", ";", "}", "else", "{", "return", "false", ";", "}", "return", "array_combine", "(", "[", "'id'", ",", "'fbid'", "]", ",", "explode", "(", "'_'", ",", "$", "body", "[", "$", "key", "]", ")", ")", ";", "}" ]
Explode facebook response id field. @param array $body @return array|bool
[ "Explode", "facebook", "response", "id", "field", "." ]
a42b8b832ca5b9a9b0c7e056c0fc10433ca1babd
https://github.com/Facebook-Anonymous-Publisher/graph-api/blob/a42b8b832ca5b9a9b0c7e056c0fc10433ca1babd/src/GraphApi.php#L134-L145
train
ezra-obiwale/dSCore
src/View/View.php
View.file
final public function file($_) { $args = func_get_args(); if (count($args) > 3) { for ($i = 3; $i < count($args); $i++) { unset($args[$i]); } } switch (count($args)) { case 1: $this->viewFile[2] = Util::camelToHyphen($args[0]); break; case 2: $this->viewFile[1] = Util::camelToHyphen($args[0]); $this->viewFile[2] = Util::camelToHyphen($args[1]); break; case 3: $this->viewFile[0] = ucfirst(Util::hyphenToCamel($args[0])); $this->viewFile[1] = Util::camelToHyphen($args[1]); $this->viewFile[2] = Util::camelToHyphen($args[2]); break; } return $this; }
php
final public function file($_) { $args = func_get_args(); if (count($args) > 3) { for ($i = 3; $i < count($args); $i++) { unset($args[$i]); } } switch (count($args)) { case 1: $this->viewFile[2] = Util::camelToHyphen($args[0]); break; case 2: $this->viewFile[1] = Util::camelToHyphen($args[0]); $this->viewFile[2] = Util::camelToHyphen($args[1]); break; case 3: $this->viewFile[0] = ucfirst(Util::hyphenToCamel($args[0])); $this->viewFile[1] = Util::camelToHyphen($args[1]); $this->viewFile[2] = Util::camelToHyphen($args[2]); break; } return $this; }
[ "final", "public", "function", "file", "(", "$", "_", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "if", "(", "count", "(", "$", "args", ")", ">", "3", ")", "{", "for", "(", "$", "i", "=", "3", ";", "$", "i", "<", "count", "(", "$", "args", ")", ";", "$", "i", "++", ")", "{", "unset", "(", "$", "args", "[", "$", "i", "]", ")", ";", "}", "}", "switch", "(", "count", "(", "$", "args", ")", ")", "{", "case", "1", ":", "$", "this", "->", "viewFile", "[", "2", "]", "=", "Util", "::", "camelToHyphen", "(", "$", "args", "[", "0", "]", ")", ";", "break", ";", "case", "2", ":", "$", "this", "->", "viewFile", "[", "1", "]", "=", "Util", "::", "camelToHyphen", "(", "$", "args", "[", "0", "]", ")", ";", "$", "this", "->", "viewFile", "[", "2", "]", "=", "Util", "::", "camelToHyphen", "(", "$", "args", "[", "1", "]", ")", ";", "break", ";", "case", "3", ":", "$", "this", "->", "viewFile", "[", "0", "]", "=", "ucfirst", "(", "Util", "::", "hyphenToCamel", "(", "$", "args", "[", "0", "]", ")", ")", ";", "$", "this", "->", "viewFile", "[", "1", "]", "=", "Util", "::", "camelToHyphen", "(", "$", "args", "[", "1", "]", ")", ";", "$", "this", "->", "viewFile", "[", "2", "]", "=", "Util", "::", "camelToHyphen", "(", "$", "args", "[", "2", "]", ")", ";", "break", ";", "}", "return", "$", "this", ";", "}" ]
Determines which action's view to use instead of current's @param string $_ You may pass 1 to 3 parameters as [module],[controller],action @return View
[ "Determines", "which", "action", "s", "view", "to", "use", "instead", "of", "current", "s" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/View/View.php#L192-L217
train
ezra-obiwale/dSCore
src/View/View.php
View.getViewFile
final public function getViewFile($addOthers = true) { if ($addOthers) { if (!isset($this->viewFile[0])) $this->viewFile[0] = ucfirst(Util::hyphenToCamel(engineGet('module'))); if (!isset($this->viewFile[1])) $this->viewFile[1] = Util::camelToHyphen(engineGet('controller')); if (!isset($this->viewFile[2])) $this->viewFile[2] = Util::camelToHyphen(engineGet('action')); ksort($this->viewFile); } return $this->viewFile; }
php
final public function getViewFile($addOthers = true) { if ($addOthers) { if (!isset($this->viewFile[0])) $this->viewFile[0] = ucfirst(Util::hyphenToCamel(engineGet('module'))); if (!isset($this->viewFile[1])) $this->viewFile[1] = Util::camelToHyphen(engineGet('controller')); if (!isset($this->viewFile[2])) $this->viewFile[2] = Util::camelToHyphen(engineGet('action')); ksort($this->viewFile); } return $this->viewFile; }
[ "final", "public", "function", "getViewFile", "(", "$", "addOthers", "=", "true", ")", "{", "if", "(", "$", "addOthers", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "viewFile", "[", "0", "]", ")", ")", "$", "this", "->", "viewFile", "[", "0", "]", "=", "ucfirst", "(", "Util", "::", "hyphenToCamel", "(", "engineGet", "(", "'module'", ")", ")", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "viewFile", "[", "1", "]", ")", ")", "$", "this", "->", "viewFile", "[", "1", "]", "=", "Util", "::", "camelToHyphen", "(", "engineGet", "(", "'controller'", ")", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "viewFile", "[", "2", "]", ")", ")", "$", "this", "->", "viewFile", "[", "2", "]", "=", "Util", "::", "camelToHyphen", "(", "engineGet", "(", "'action'", ")", ")", ";", "ksort", "(", "$", "this", "->", "viewFile", ")", ";", "}", "return", "$", "this", "->", "viewFile", ";", "}" ]
Fetches the view file array @param boolean $addOthers Indicates whether to add missing parameters i.e. module, controller, or action @return array
[ "Fetches", "the", "view", "file", "array" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/View/View.php#L225-L237
train
ezra-obiwale/dSCore
src/View/View.php
View.url
final public function url($module, $controller = null, $action = null, array $params = array(), $hash = null) { $module = ucfirst(Util::hyphenToCamel($module)); $moduleOptions = engineGet('config', 'modules', $module, false); $module = (isset($moduleOptions['alias'])) ? $moduleOptions['alias'] : $module; $return = Util::camelToHyphen($module); if ($controller) $return .= '/' . Util::camelToHyphen($controller); if ($action) $return .= '/' . Util::camelToHyphen($action); if (!empty($params)) $return .= str_replace('//', '/' . urlencode(' ') . '/', '/' . join('/', $this->encodeParams($params))); if ($hash) $return .= '#' . $hash; return engineGet('serverPath') . $return; }
php
final public function url($module, $controller = null, $action = null, array $params = array(), $hash = null) { $module = ucfirst(Util::hyphenToCamel($module)); $moduleOptions = engineGet('config', 'modules', $module, false); $module = (isset($moduleOptions['alias'])) ? $moduleOptions['alias'] : $module; $return = Util::camelToHyphen($module); if ($controller) $return .= '/' . Util::camelToHyphen($controller); if ($action) $return .= '/' . Util::camelToHyphen($action); if (!empty($params)) $return .= str_replace('//', '/' . urlencode(' ') . '/', '/' . join('/', $this->encodeParams($params))); if ($hash) $return .= '#' . $hash; return engineGet('serverPath') . $return; }
[ "final", "public", "function", "url", "(", "$", "module", ",", "$", "controller", "=", "null", ",", "$", "action", "=", "null", ",", "array", "$", "params", "=", "array", "(", ")", ",", "$", "hash", "=", "null", ")", "{", "$", "module", "=", "ucfirst", "(", "Util", "::", "hyphenToCamel", "(", "$", "module", ")", ")", ";", "$", "moduleOptions", "=", "engineGet", "(", "'config'", ",", "'modules'", ",", "$", "module", ",", "false", ")", ";", "$", "module", "=", "(", "isset", "(", "$", "moduleOptions", "[", "'alias'", "]", ")", ")", "?", "$", "moduleOptions", "[", "'alias'", "]", ":", "$", "module", ";", "$", "return", "=", "Util", "::", "camelToHyphen", "(", "$", "module", ")", ";", "if", "(", "$", "controller", ")", "$", "return", ".=", "'/'", ".", "Util", "::", "camelToHyphen", "(", "$", "controller", ")", ";", "if", "(", "$", "action", ")", "$", "return", ".=", "'/'", ".", "Util", "::", "camelToHyphen", "(", "$", "action", ")", ";", "if", "(", "!", "empty", "(", "$", "params", ")", ")", "$", "return", ".=", "str_replace", "(", "'//'", ",", "'/'", ".", "urlencode", "(", "' '", ")", ".", "'/'", ",", "'/'", ".", "join", "(", "'/'", ",", "$", "this", "->", "encodeParams", "(", "$", "params", ")", ")", ")", ";", "if", "(", "$", "hash", ")", "$", "return", ".=", "'#'", ".", "$", "hash", ";", "return", "engineGet", "(", "'serverPath'", ")", ".", "$", "return", ";", "}" ]
Fetches the relative path to a resource @param string $module @param string $controller @param string $action @param array $params @param string $hash @return string
[ "Fetches", "the", "relative", "path", "to", "a", "resource" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/View/View.php#L248-L264
train
ezra-obiwale/dSCore
src/View/View.php
View.getOutput
final public function getOutput($module, $controller, $action, array $params = array(), $partial = true) { $view = new View(); $controllerClass = ucfirst(\Util::hyphenToCamel($module)) . '\Controllers\\' . ucfirst(\Util::hyphenToCamel($controller)) . 'Controller'; $controllerClass = new $controllerClass; $controllerClass->setView($view); $action = lcfirst(\Util::hyphenToCamel($action)); $view->setController($controllerClass) ->setAction(lcfirst(\Util::hyphenToCamel($action))) ->setModule(ucfirst(\Util::hyphenToCamel($module))); $actionRet = call_user_func_array(array($controllerClass, $action . 'Action'), $params); if (is_object($actionRet) && is_a($actionRet, 'DScribe\View\View')) { $view = $actionRet; } else { $view->variables(($actionRet) ? $actionRet : array()); } if ($viewFile = $view->getViewFile(false)) { if (!isset($viewFile[0]) && !isset($viewFile[1])) { $view->file($module, $controller, $viewFile[2]); } else if (!isset($viewFile[0])) { $view->file($module, $viewFile[1], $viewFile[2]); } } else { $view->file($module, $controller, $action); } if ($partial) { $view->partial(); } ob_start(); $view->render(); return ob_get_clean(); }
php
final public function getOutput($module, $controller, $action, array $params = array(), $partial = true) { $view = new View(); $controllerClass = ucfirst(\Util::hyphenToCamel($module)) . '\Controllers\\' . ucfirst(\Util::hyphenToCamel($controller)) . 'Controller'; $controllerClass = new $controllerClass; $controllerClass->setView($view); $action = lcfirst(\Util::hyphenToCamel($action)); $view->setController($controllerClass) ->setAction(lcfirst(\Util::hyphenToCamel($action))) ->setModule(ucfirst(\Util::hyphenToCamel($module))); $actionRet = call_user_func_array(array($controllerClass, $action . 'Action'), $params); if (is_object($actionRet) && is_a($actionRet, 'DScribe\View\View')) { $view = $actionRet; } else { $view->variables(($actionRet) ? $actionRet : array()); } if ($viewFile = $view->getViewFile(false)) { if (!isset($viewFile[0]) && !isset($viewFile[1])) { $view->file($module, $controller, $viewFile[2]); } else if (!isset($viewFile[0])) { $view->file($module, $viewFile[1], $viewFile[2]); } } else { $view->file($module, $controller, $action); } if ($partial) { $view->partial(); } ob_start(); $view->render(); return ob_get_clean(); }
[ "final", "public", "function", "getOutput", "(", "$", "module", ",", "$", "controller", ",", "$", "action", ",", "array", "$", "params", "=", "array", "(", ")", ",", "$", "partial", "=", "true", ")", "{", "$", "view", "=", "new", "View", "(", ")", ";", "$", "controllerClass", "=", "ucfirst", "(", "\\", "Util", "::", "hyphenToCamel", "(", "$", "module", ")", ")", ".", "'\\Controllers\\\\'", ".", "ucfirst", "(", "\\", "Util", "::", "hyphenToCamel", "(", "$", "controller", ")", ")", ".", "'Controller'", ";", "$", "controllerClass", "=", "new", "$", "controllerClass", ";", "$", "controllerClass", "->", "setView", "(", "$", "view", ")", ";", "$", "action", "=", "lcfirst", "(", "\\", "Util", "::", "hyphenToCamel", "(", "$", "action", ")", ")", ";", "$", "view", "->", "setController", "(", "$", "controllerClass", ")", "->", "setAction", "(", "lcfirst", "(", "\\", "Util", "::", "hyphenToCamel", "(", "$", "action", ")", ")", ")", "->", "setModule", "(", "ucfirst", "(", "\\", "Util", "::", "hyphenToCamel", "(", "$", "module", ")", ")", ")", ";", "$", "actionRet", "=", "call_user_func_array", "(", "array", "(", "$", "controllerClass", ",", "$", "action", ".", "'Action'", ")", ",", "$", "params", ")", ";", "if", "(", "is_object", "(", "$", "actionRet", ")", "&&", "is_a", "(", "$", "actionRet", ",", "'DScribe\\View\\View'", ")", ")", "{", "$", "view", "=", "$", "actionRet", ";", "}", "else", "{", "$", "view", "->", "variables", "(", "(", "$", "actionRet", ")", "?", "$", "actionRet", ":", "array", "(", ")", ")", ";", "}", "if", "(", "$", "viewFile", "=", "$", "view", "->", "getViewFile", "(", "false", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "viewFile", "[", "0", "]", ")", "&&", "!", "isset", "(", "$", "viewFile", "[", "1", "]", ")", ")", "{", "$", "view", "->", "file", "(", "$", "module", ",", "$", "controller", ",", "$", "viewFile", "[", "2", "]", ")", ";", "}", "else", "if", "(", "!", "isset", "(", "$", "viewFile", "[", "0", "]", ")", ")", "{", "$", "view", "->", "file", "(", "$", "module", ",", "$", "viewFile", "[", "1", "]", ",", "$", "viewFile", "[", "2", "]", ")", ";", "}", "}", "else", "{", "$", "view", "->", "file", "(", "$", "module", ",", "$", "controller", ",", "$", "action", ")", ";", "}", "if", "(", "$", "partial", ")", "{", "$", "view", "->", "partial", "(", ")", ";", "}", "ob_start", "(", ")", ";", "$", "view", "->", "render", "(", ")", ";", "return", "ob_get_clean", "(", ")", ";", "}" ]
Fetches the output of an action @param string $module @param string $controller @param string $action @param array $params @param boolean $partial Indicates whether to return partial or full view @return string
[ "Fetches", "the", "output", "of", "an", "action" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/View/View.php#L300-L335
train
FlorianWolters/PHP-Component-Core-Enum
src/php/FlorianWolters/Component/Core/Enum/EnumUtils.php
EnumUtils.getNameForOrdinal
public static function getNameForOrdinal($enumType, $ordinal) { $constants = $enumType::values(); $result = null; foreach ($constants as $constant) { if ($constant->getOrdinal() === $ordinal) { $result = $constant->getName(); break; } } return $result; }
php
public static function getNameForOrdinal($enumType, $ordinal) { $constants = $enumType::values(); $result = null; foreach ($constants as $constant) { if ($constant->getOrdinal() === $ordinal) { $result = $constant->getName(); break; } } return $result; }
[ "public", "static", "function", "getNameForOrdinal", "(", "$", "enumType", ",", "$", "ordinal", ")", "{", "$", "constants", "=", "$", "enumType", "::", "values", "(", ")", ";", "$", "result", "=", "null", ";", "foreach", "(", "$", "constants", "as", "$", "constant", ")", "{", "if", "(", "$", "constant", "->", "getOrdinal", "(", ")", "===", "$", "ordinal", ")", "{", "$", "result", "=", "$", "constant", "->", "getName", "(", ")", ";", "break", ";", "}", "}", "return", "$", "result", ";", "}" ]
Returns the name of the enumeration constant of the specified enumeration type with the specified ordinal. @param string $enumType The class name of the enumeration type from which to return the ordinal of the enumeration constant. @param integer $ordinal The ordinal of the enumeration constant to return. @return string|null The name of the enumeration constant of the specified enumeration type with the specified ordinal on success; `null` on failure.
[ "Returns", "the", "name", "of", "the", "enumeration", "constant", "of", "the", "specified", "enumeration", "type", "with", "the", "specified", "ordinal", "." ]
838dcdc5705c3e1a2c0ff879987590b0a455db38
https://github.com/FlorianWolters/PHP-Component-Core-Enum/blob/838dcdc5705c3e1a2c0ff879987590b0a455db38/src/php/FlorianWolters/Component/Core/Enum/EnumUtils.php#L177-L190
train
FlorianWolters/PHP-Component-Core-Enum
src/php/FlorianWolters/Component/Core/Enum/EnumUtils.php
EnumUtils.getOrdinalForName
public static function getOrdinalForName($enumType, $name) { $constants = $enumType::values(); $result = null; foreach ($constants as $constant) { if ($constant->getName() === $name) { $result = $constant->getOrdinal(); break; } } return $result; }
php
public static function getOrdinalForName($enumType, $name) { $constants = $enumType::values(); $result = null; foreach ($constants as $constant) { if ($constant->getName() === $name) { $result = $constant->getOrdinal(); break; } } return $result; }
[ "public", "static", "function", "getOrdinalForName", "(", "$", "enumType", ",", "$", "name", ")", "{", "$", "constants", "=", "$", "enumType", "::", "values", "(", ")", ";", "$", "result", "=", "null", ";", "foreach", "(", "$", "constants", "as", "$", "constant", ")", "{", "if", "(", "$", "constant", "->", "getName", "(", ")", "===", "$", "name", ")", "{", "$", "result", "=", "$", "constant", "->", "getOrdinal", "(", ")", ";", "break", ";", "}", "}", "return", "$", "result", ";", "}" ]
Returns the ordinal of the enumeration constant of the specified enumeration type with the specified name. @param string $enumType The class name of the enumeration type from which to return the name of the enumeration constant. @param string $name The name of the enumeration constant to return. @return integer|null The ordinal of the enumeration constant of the specified enumeration type with the specified ordinal on success; `null` on failure.
[ "Returns", "the", "ordinal", "of", "the", "enumeration", "constant", "of", "the", "specified", "enumeration", "type", "with", "the", "specified", "name", "." ]
838dcdc5705c3e1a2c0ff879987590b0a455db38
https://github.com/FlorianWolters/PHP-Component-Core-Enum/blob/838dcdc5705c3e1a2c0ff879987590b0a455db38/src/php/FlorianWolters/Component/Core/Enum/EnumUtils.php#L204-L217
train
FlorianWolters/PHP-Component-Core-Enum
src/php/FlorianWolters/Component/Core/Enum/EnumUtils.php
EnumUtils.isDefinedName
public static function isDefinedName($enumType, $name) { $names = $enumType::names(); $result = false; foreach ($names as $item) { if ($item === $name) { $result = true; break; } } return $result; }
php
public static function isDefinedName($enumType, $name) { $names = $enumType::names(); $result = false; foreach ($names as $item) { if ($item === $name) { $result = true; break; } } return $result; }
[ "public", "static", "function", "isDefinedName", "(", "$", "enumType", ",", "$", "name", ")", "{", "$", "names", "=", "$", "enumType", "::", "names", "(", ")", ";", "$", "result", "=", "false", ";", "foreach", "(", "$", "names", "as", "$", "item", ")", "{", "if", "(", "$", "item", "===", "$", "name", ")", "{", "$", "result", "=", "true", ";", "break", ";", "}", "}", "return", "$", "result", ";", "}" ]
Checks whether an enumeration constant with the specified name exists in the specified enumeration type. @param string $enumType The class name of the enumeration type to check. @param string $name The name of the enumeration constant to check. @return boolean `true` if the enumeration constant with the specified name exists in the specified enumeration type; `false` otherwise.
[ "Checks", "whether", "an", "enumeration", "constant", "with", "the", "specified", "name", "exists", "in", "the", "specified", "enumeration", "type", "." ]
838dcdc5705c3e1a2c0ff879987590b0a455db38
https://github.com/FlorianWolters/PHP-Component-Core-Enum/blob/838dcdc5705c3e1a2c0ff879987590b0a455db38/src/php/FlorianWolters/Component/Core/Enum/EnumUtils.php#L230-L243
train
FlorianWolters/PHP-Component-Core-Enum
src/php/FlorianWolters/Component/Core/Enum/EnumUtils.php
EnumUtils.isDefinedOrdinal
public static function isDefinedOrdinal($enumType, $ordinal) { $constants = $enumType::values(); $result = false; foreach ($constants as $constant) { if ($constant->getOrdinal() === $ordinal) { $result = true; break; } } return $result; }
php
public static function isDefinedOrdinal($enumType, $ordinal) { $constants = $enumType::values(); $result = false; foreach ($constants as $constant) { if ($constant->getOrdinal() === $ordinal) { $result = true; break; } } return $result; }
[ "public", "static", "function", "isDefinedOrdinal", "(", "$", "enumType", ",", "$", "ordinal", ")", "{", "$", "constants", "=", "$", "enumType", "::", "values", "(", ")", ";", "$", "result", "=", "false", ";", "foreach", "(", "$", "constants", "as", "$", "constant", ")", "{", "if", "(", "$", "constant", "->", "getOrdinal", "(", ")", "===", "$", "ordinal", ")", "{", "$", "result", "=", "true", ";", "break", ";", "}", "}", "return", "$", "result", ";", "}" ]
Checks whether an enumeration constant with the specified ordinal exists in the specified enumeration type. @param string $enumType The class name of the enumeration type to check. @param integer $ordinal The ordinal of the enumeration constant to check. @return boolean `true` if the enumeration constant with the specified ordinal exists in the specified enumeration type; `false` otherwise.
[ "Checks", "whether", "an", "enumeration", "constant", "with", "the", "specified", "ordinal", "exists", "in", "the", "specified", "enumeration", "type", "." ]
838dcdc5705c3e1a2c0ff879987590b0a455db38
https://github.com/FlorianWolters/PHP-Component-Core-Enum/blob/838dcdc5705c3e1a2c0ff879987590b0a455db38/src/php/FlorianWolters/Component/Core/Enum/EnumUtils.php#L257-L270
train
imsamurai/CakePHP-AdvancedShell
Console/Command/Task/Scheduled/ScheduleSplitByRange.php
ScheduleSplitByRange.split
public function split(array $arguments = array()) { $splittedArguments = new AppendIterator(); foreach ($this->_options['Period'] as $Date) { $_arguments = $arguments; $_arguments['--range'] = $Date->format(Configure::read('Task.dateFormat')); $splittedArguments->append($this->splitInner($_arguments)); } return $splittedArguments; }
php
public function split(array $arguments = array()) { $splittedArguments = new AppendIterator(); foreach ($this->_options['Period'] as $Date) { $_arguments = $arguments; $_arguments['--range'] = $Date->format(Configure::read('Task.dateFormat')); $splittedArguments->append($this->splitInner($_arguments)); } return $splittedArguments; }
[ "public", "function", "split", "(", "array", "$", "arguments", "=", "array", "(", ")", ")", "{", "$", "splittedArguments", "=", "new", "AppendIterator", "(", ")", ";", "foreach", "(", "$", "this", "->", "_options", "[", "'Period'", "]", "as", "$", "Date", ")", "{", "$", "_arguments", "=", "$", "arguments", ";", "$", "_arguments", "[", "'--range'", "]", "=", "$", "Date", "->", "format", "(", "Configure", "::", "read", "(", "'Task.dateFormat'", ")", ")", ";", "$", "splittedArguments", "->", "append", "(", "$", "this", "->", "splitInner", "(", "$", "_arguments", ")", ")", ";", "}", "return", "$", "splittedArguments", ";", "}" ]
Split arguments by date range @param array $arguments
[ "Split", "arguments", "by", "date", "range" ]
087d483742e2a76bee45e35b8d94957b0d20f857
https://github.com/imsamurai/CakePHP-AdvancedShell/blob/087d483742e2a76bee45e35b8d94957b0d20f857/Console/Command/Task/Scheduled/ScheduleSplitByRange.php#L23-L33
train
fuelphp-storage/security
src/Manager.php
Manager.csrf
public function csrf() { if ( ! $this->csrf) { $this->csrf = \Dependency::resolve('security.csrf', array($this->config, \Application::getInstance()->getSession())); } return $this->csrf; }
php
public function csrf() { if ( ! $this->csrf) { $this->csrf = \Dependency::resolve('security.csrf', array($this->config, \Application::getInstance()->getSession())); } return $this->csrf; }
[ "public", "function", "csrf", "(", ")", "{", "if", "(", "!", "$", "this", "->", "csrf", ")", "{", "$", "this", "->", "csrf", "=", "\\", "Dependency", "::", "resolve", "(", "'security.csrf'", ",", "array", "(", "$", "this", "->", "config", ",", "\\", "Application", "::", "getInstance", "(", ")", "->", "getSession", "(", ")", ")", ")", ";", "}", "return", "$", "this", "->", "csrf", ";", "}" ]
Returns a Csrf instance @return Csrf
[ "Returns", "a", "Csrf", "instance" ]
2cad42a8432bc9c9de46486623b71e105ff84b1b
https://github.com/fuelphp-storage/security/blob/2cad42a8432bc9c9de46486623b71e105ff84b1b/src/Manager.php#L68-L76
train
KDF5000/EasyThink
src/ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_templatebase.php
Smarty_Internal_TemplateBase.unregisterResource
public function unregisterResource($type) { if (isset($this->smarty->registered_resources[$type])) { unset($this->smarty->registered_resources[$type]); } }
php
public function unregisterResource($type) { if (isset($this->smarty->registered_resources[$type])) { unset($this->smarty->registered_resources[$type]); } }
[ "public", "function", "unregisterResource", "(", "$", "type", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "smarty", "->", "registered_resources", "[", "$", "type", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "smarty", "->", "registered_resources", "[", "$", "type", "]", ")", ";", "}", "}" ]
Unregisters a resource @param string $type name of resource type
[ "Unregisters", "a", "resource" ]
86efc9c8a0d504e01e2fea55868227fdc8928841
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_templatebase.php#L450-L455
train
KDF5000/EasyThink
src/ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_templatebase.php
Smarty_Internal_TemplateBase.unregisterCacheResource
public function unregisterCacheResource($type) { if (isset($this->smarty->registered_cache_resources[$type])) { unset($this->smarty->registered_cache_resources[$type]); } }
php
public function unregisterCacheResource($type) { if (isset($this->smarty->registered_cache_resources[$type])) { unset($this->smarty->registered_cache_resources[$type]); } }
[ "public", "function", "unregisterCacheResource", "(", "$", "type", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "smarty", "->", "registered_cache_resources", "[", "$", "type", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "smarty", "->", "registered_cache_resources", "[", "$", "type", "]", ")", ";", "}", "}" ]
Unregisters a cache resource @param string $type name of cache resource type
[ "Unregisters", "a", "cache", "resource" ]
86efc9c8a0d504e01e2fea55868227fdc8928841
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_templatebase.php#L473-L478
train
enikeishik/ufoframework
src/Ufo/StorableCache/StorableCache.php
StorableCache.expired
public function expired(string $key): bool { try { return $this->storage->expired($key); } catch (BadPacketException $e) { return true; } }
php
public function expired(string $key): bool { try { return $this->storage->expired($key); } catch (BadPacketException $e) { return true; } }
[ "public", "function", "expired", "(", "string", "$", "key", ")", ":", "bool", "{", "try", "{", "return", "$", "this", "->", "storage", "->", "expired", "(", "$", "key", ")", ";", "}", "catch", "(", "BadPacketException", "$", "e", ")", "{", "return", "true", ";", "}", "}" ]
Determines whether an item is present in the cache and life time expired. @param string $key The unique cache key of the item to check for expiring. @return bool True if the item was expired. False if not.
[ "Determines", "whether", "an", "item", "is", "present", "in", "the", "cache", "and", "life", "time", "expired", "." ]
fb44461bcb0506dbc3257724a2281f756594f62f
https://github.com/enikeishik/ufoframework/blob/fb44461bcb0506dbc3257724a2281f756594f62f/src/Ufo/StorableCache/StorableCache.php#L182-L189
train
nhlm/pipechain
src/Collections/PipeChainCollection.php
PipeChainCollection.attach
public function attach(callable $stage, callable $fallback = null) { $this->storage->attach( $this->marshalClosure($stage), [ 'fallback' => is_callable($fallback) ? $this->marshalClosure($fallback) : null ] ); }
php
public function attach(callable $stage, callable $fallback = null) { $this->storage->attach( $this->marshalClosure($stage), [ 'fallback' => is_callable($fallback) ? $this->marshalClosure($fallback) : null ] ); }
[ "public", "function", "attach", "(", "callable", "$", "stage", ",", "callable", "$", "fallback", "=", "null", ")", "{", "$", "this", "->", "storage", "->", "attach", "(", "$", "this", "->", "marshalClosure", "(", "$", "stage", ")", ",", "[", "'fallback'", "=>", "is_callable", "(", "$", "fallback", ")", "?", "$", "this", "->", "marshalClosure", "(", "$", "fallback", ")", ":", "null", "]", ")", ";", "}" ]
Attaches a stage and assigns a fallback to the attached stage. @param callable $stage @param callable|null $fallback @return void
[ "Attaches", "a", "stage", "and", "assigns", "a", "fallback", "to", "the", "attached", "stage", "." ]
7f67b54372415a66c42ce074bc359c55fda218a5
https://github.com/nhlm/pipechain/blob/7f67b54372415a66c42ce074bc359c55fda218a5/src/Collections/PipeChainCollection.php#L57-L65
train
modulusphp/utility
Reflect.php
Reflect.hasRequest
private function hasRequest($params, $variables, $i = null) : array { foreach($params as $key => $param) { $class = '\\' . $param->getType(); if (class_exists($class) && new $class() instanceof Request) { $i = $key; } } if ($i !== null) $variables = $this->insert($variables, $i, 'Request'); return $variables; }
php
private function hasRequest($params, $variables, $i = null) : array { foreach($params as $key => $param) { $class = '\\' . $param->getType(); if (class_exists($class) && new $class() instanceof Request) { $i = $key; } } if ($i !== null) $variables = $this->insert($variables, $i, 'Request'); return $variables; }
[ "private", "function", "hasRequest", "(", "$", "params", ",", "$", "variables", ",", "$", "i", "=", "null", ")", ":", "array", "{", "foreach", "(", "$", "params", "as", "$", "key", "=>", "$", "param", ")", "{", "$", "class", "=", "'\\\\'", ".", "$", "param", "->", "getType", "(", ")", ";", "if", "(", "class_exists", "(", "$", "class", ")", "&&", "new", "$", "class", "(", ")", "instanceof", "Request", ")", "{", "$", "i", "=", "$", "key", ";", "}", "}", "if", "(", "$", "i", "!==", "null", ")", "$", "variables", "=", "$", "this", "->", "insert", "(", "$", "variables", ",", "$", "i", ",", "'Request'", ")", ";", "return", "$", "variables", ";", "}" ]
Check if the request class exists and insert it if it doesn't @param mixed $params @param mixed $variables @param mixed $i @return array
[ "Check", "if", "the", "request", "class", "exists", "and", "insert", "it", "if", "it", "doesn", "t" ]
c1e127539b13d3ec8381e41c64b881e0701807f5
https://github.com/modulusphp/utility/blob/c1e127539b13d3ec8381e41c64b881e0701807f5/Reflect.php#L128-L139
train
spoom-php/core
src/extension/Storage.php
Storage.clean
protected function clean( $meta = null ) { // if( $meta && !( $meta instanceof StorageMeta ) ) { $meta = $this->getMeta( $meta ); } // clear the cache if( !$meta || empty( $meta->token ) ) $this->cache = []; else foreach( $this->cache as $i => $_ ) { if( empty( $i ) || $i == $meta->token[ 0 ] || strpos( $i, $meta->token[ 0 ] ) === 0 ) { unset( $this->cache[ $i ] ); } } }
php
protected function clean( $meta = null ) { // if( $meta && !( $meta instanceof StorageMeta ) ) { $meta = $this->getMeta( $meta ); } // clear the cache if( !$meta || empty( $meta->token ) ) $this->cache = []; else foreach( $this->cache as $i => $_ ) { if( empty( $i ) || $i == $meta->token[ 0 ] || strpos( $i, $meta->token[ 0 ] ) === 0 ) { unset( $this->cache[ $i ] ); } } }
[ "protected", "function", "clean", "(", "$", "meta", "=", "null", ")", "{", "//", "if", "(", "$", "meta", "&&", "!", "(", "$", "meta", "instanceof", "StorageMeta", ")", ")", "{", "$", "meta", "=", "$", "this", "->", "getMeta", "(", "$", "meta", ")", ";", "}", "// clear the cache", "if", "(", "!", "$", "meta", "||", "empty", "(", "$", "meta", "->", "token", ")", ")", "$", "this", "->", "cache", "=", "[", "]", ";", "else", "foreach", "(", "$", "this", "->", "cache", "as", "$", "i", "=>", "$", "_", ")", "{", "if", "(", "empty", "(", "$", "i", ")", "||", "$", "i", "==", "$", "meta", "->", "token", "[", "0", "]", "||", "strpos", "(", "$", "i", ",", "$", "meta", "->", "token", "[", "0", "]", ")", "===", "0", ")", "{", "unset", "(", "$", "this", "->", "cache", "[", "$", "i", "]", ")", ";", "}", "}", "}" ]
Clean the search cache based on the index @param string|StorageMeta|null $meta
[ "Clean", "the", "search", "cache", "based", "on", "the", "index" ]
ea7184213352fa2fad7636927a019e5798734e04
https://github.com/spoom-php/core/blob/ea7184213352fa2fad7636927a019e5798734e04/src/extension/Storage.php#L321-L336
train
cubicmushroom/valueobjects
src/Geography/Coordinate.php
Coordinate.fromNative
public static function fromNative() { $args = \func_get_args(); if (\count($args) < 2 || \count($args) > 3) { throw new \BadMethodCallException('You must provide 2 to 3 arguments: 1) latitude, 2) longitude, 3) valid ellipsoid type (optional)'); } $coordinate = new BaseCoordinate(array($args[0], $args[1])); $latitude = Latitude::fromNative($coordinate->getLatitude()); $longitude = Longitude::fromNative($coordinate->getLongitude()); $nativeEllipsoid = isset($args[2]) ? $args[2] : null; $ellipsoid = Ellipsoid::fromNative($nativeEllipsoid); return new self($latitude, $longitude, $ellipsoid); }
php
public static function fromNative() { $args = \func_get_args(); if (\count($args) < 2 || \count($args) > 3) { throw new \BadMethodCallException('You must provide 2 to 3 arguments: 1) latitude, 2) longitude, 3) valid ellipsoid type (optional)'); } $coordinate = new BaseCoordinate(array($args[0], $args[1])); $latitude = Latitude::fromNative($coordinate->getLatitude()); $longitude = Longitude::fromNative($coordinate->getLongitude()); $nativeEllipsoid = isset($args[2]) ? $args[2] : null; $ellipsoid = Ellipsoid::fromNative($nativeEllipsoid); return new self($latitude, $longitude, $ellipsoid); }
[ "public", "static", "function", "fromNative", "(", ")", "{", "$", "args", "=", "\\", "func_get_args", "(", ")", ";", "if", "(", "\\", "count", "(", "$", "args", ")", "<", "2", "||", "\\", "count", "(", "$", "args", ")", ">", "3", ")", "{", "throw", "new", "\\", "BadMethodCallException", "(", "'You must provide 2 to 3 arguments: 1) latitude, 2) longitude, 3) valid ellipsoid type (optional)'", ")", ";", "}", "$", "coordinate", "=", "new", "BaseCoordinate", "(", "array", "(", "$", "args", "[", "0", "]", ",", "$", "args", "[", "1", "]", ")", ")", ";", "$", "latitude", "=", "Latitude", "::", "fromNative", "(", "$", "coordinate", "->", "getLatitude", "(", ")", ")", ";", "$", "longitude", "=", "Longitude", "::", "fromNative", "(", "$", "coordinate", "->", "getLongitude", "(", ")", ")", ";", "$", "nativeEllipsoid", "=", "isset", "(", "$", "args", "[", "2", "]", ")", "?", "$", "args", "[", "2", "]", ":", "null", ";", "$", "ellipsoid", "=", "Ellipsoid", "::", "fromNative", "(", "$", "nativeEllipsoid", ")", ";", "return", "new", "self", "(", "$", "latitude", ",", "$", "longitude", ",", "$", "ellipsoid", ")", ";", "}" ]
Returns a new Coordinate object from native PHP arguments @return self @throws \BadMethodCallException
[ "Returns", "a", "new", "Coordinate", "object", "from", "native", "PHP", "arguments" ]
4554239ab75d65eeb9773219aa5b07e9fbfabb92
https://github.com/cubicmushroom/valueobjects/blob/4554239ab75d65eeb9773219aa5b07e9fbfabb92/src/Geography/Coordinate.php#L31-L47
train
cubicmushroom/valueobjects
src/Geography/Coordinate.php
Coordinate.sameValueAs
public function sameValueAs(ValueObjectInterface $coordinate) { if (false === Util::classEquals($this, $coordinate)) { return false; } return $this->getLatitude()->sameValueAs($coordinate->getLatitude()) && $this->getLongitude()->sameValueAs($coordinate->getLongitude()) && $this->getEllipsoid()->sameValueAs($coordinate->getEllipsoid()) ; }
php
public function sameValueAs(ValueObjectInterface $coordinate) { if (false === Util::classEquals($this, $coordinate)) { return false; } return $this->getLatitude()->sameValueAs($coordinate->getLatitude()) && $this->getLongitude()->sameValueAs($coordinate->getLongitude()) && $this->getEllipsoid()->sameValueAs($coordinate->getEllipsoid()) ; }
[ "public", "function", "sameValueAs", "(", "ValueObjectInterface", "$", "coordinate", ")", "{", "if", "(", "false", "===", "Util", "::", "classEquals", "(", "$", "this", ",", "$", "coordinate", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "getLatitude", "(", ")", "->", "sameValueAs", "(", "$", "coordinate", "->", "getLatitude", "(", ")", ")", "&&", "$", "this", "->", "getLongitude", "(", ")", "->", "sameValueAs", "(", "$", "coordinate", "->", "getLongitude", "(", ")", ")", "&&", "$", "this", "->", "getEllipsoid", "(", ")", "->", "sameValueAs", "(", "$", "coordinate", "->", "getEllipsoid", "(", ")", ")", ";", "}" ]
Tells whether tow Coordinate objects are equal @param ValueObjectInterface $coordinate @return bool
[ "Tells", "whether", "tow", "Coordinate", "objects", "are", "equal" ]
4554239ab75d65eeb9773219aa5b07e9fbfabb92
https://github.com/cubicmushroom/valueobjects/blob/4554239ab75d65eeb9773219aa5b07e9fbfabb92/src/Geography/Coordinate.php#L73-L83
train
cubicmushroom/valueobjects
src/Geography/Coordinate.php
Coordinate.toDecimalMinutes
public function toDecimalMinutes() { $coordinate = self::getBaseCoordinate($this); $convert = new Convert($coordinate); $dm = $convert->toDecimalMinutes(); return new StringLiteral($dm); }
php
public function toDecimalMinutes() { $coordinate = self::getBaseCoordinate($this); $convert = new Convert($coordinate); $dm = $convert->toDecimalMinutes(); return new StringLiteral($dm); }
[ "public", "function", "toDecimalMinutes", "(", ")", "{", "$", "coordinate", "=", "self", "::", "getBaseCoordinate", "(", "$", "this", ")", ";", "$", "convert", "=", "new", "Convert", "(", "$", "coordinate", ")", ";", "$", "dm", "=", "$", "convert", "->", "toDecimalMinutes", "(", ")", ";", "return", "new", "StringLiteral", "(", "$", "dm", ")", ";", "}" ]
Returns a decimal minutes representation of the coordinate @return String
[ "Returns", "a", "decimal", "minutes", "representation", "of", "the", "coordinate" ]
4554239ab75d65eeb9773219aa5b07e9fbfabb92
https://github.com/cubicmushroom/valueobjects/blob/4554239ab75d65eeb9773219aa5b07e9fbfabb92/src/Geography/Coordinate.php#L134-L141
train
cubicmushroom/valueobjects
src/Geography/Coordinate.php
Coordinate.toUniversalTransverseMercator
public function toUniversalTransverseMercator() { $coordinate = self::getBaseCoordinate($this); $convert = new Convert($coordinate); $utm = $convert->toUniversalTransverseMercator(); return new StringLiteral($utm); }
php
public function toUniversalTransverseMercator() { $coordinate = self::getBaseCoordinate($this); $convert = new Convert($coordinate); $utm = $convert->toUniversalTransverseMercator(); return new StringLiteral($utm); }
[ "public", "function", "toUniversalTransverseMercator", "(", ")", "{", "$", "coordinate", "=", "self", "::", "getBaseCoordinate", "(", "$", "this", ")", ";", "$", "convert", "=", "new", "Convert", "(", "$", "coordinate", ")", ";", "$", "utm", "=", "$", "convert", "->", "toUniversalTransverseMercator", "(", ")", ";", "return", "new", "StringLiteral", "(", "$", "utm", ")", ";", "}" ]
Returns a Universal Transverse Mercator projection representation of the coordinate in meters @return String
[ "Returns", "a", "Universal", "Transverse", "Mercator", "projection", "representation", "of", "the", "coordinate", "in", "meters" ]
4554239ab75d65eeb9773219aa5b07e9fbfabb92
https://github.com/cubicmushroom/valueobjects/blob/4554239ab75d65eeb9773219aa5b07e9fbfabb92/src/Geography/Coordinate.php#L148-L155
train
cubicmushroom/valueobjects
src/Geography/Coordinate.php
Coordinate.distanceFrom
public function distanceFrom(Coordinate $coordinate, DistanceUnit $unit = null, DistanceFormula $formula = null) { if (null === $unit) { $unit = DistanceUnit::METER(); } if (null === $formula) { $formula = DistanceFormula::FLAT(); } $baseThis = self::getBaseCoordinate($this); $baseCoordinate = self::getBaseCoordinate($coordinate); $distance = new Distance(); $distance ->setFrom($baseThis) ->setTo($baseCoordinate) ->in($unit->toNative()) ; $value = \call_user_func(array($distance, $formula->toNative())); return new Real($value); }
php
public function distanceFrom(Coordinate $coordinate, DistanceUnit $unit = null, DistanceFormula $formula = null) { if (null === $unit) { $unit = DistanceUnit::METER(); } if (null === $formula) { $formula = DistanceFormula::FLAT(); } $baseThis = self::getBaseCoordinate($this); $baseCoordinate = self::getBaseCoordinate($coordinate); $distance = new Distance(); $distance ->setFrom($baseThis) ->setTo($baseCoordinate) ->in($unit->toNative()) ; $value = \call_user_func(array($distance, $formula->toNative())); return new Real($value); }
[ "public", "function", "distanceFrom", "(", "Coordinate", "$", "coordinate", ",", "DistanceUnit", "$", "unit", "=", "null", ",", "DistanceFormula", "$", "formula", "=", "null", ")", "{", "if", "(", "null", "===", "$", "unit", ")", "{", "$", "unit", "=", "DistanceUnit", "::", "METER", "(", ")", ";", "}", "if", "(", "null", "===", "$", "formula", ")", "{", "$", "formula", "=", "DistanceFormula", "::", "FLAT", "(", ")", ";", "}", "$", "baseThis", "=", "self", "::", "getBaseCoordinate", "(", "$", "this", ")", ";", "$", "baseCoordinate", "=", "self", "::", "getBaseCoordinate", "(", "$", "coordinate", ")", ";", "$", "distance", "=", "new", "Distance", "(", ")", ";", "$", "distance", "->", "setFrom", "(", "$", "baseThis", ")", "->", "setTo", "(", "$", "baseCoordinate", ")", "->", "in", "(", "$", "unit", "->", "toNative", "(", ")", ")", ";", "$", "value", "=", "\\", "call_user_func", "(", "array", "(", "$", "distance", ",", "$", "formula", "->", "toNative", "(", ")", ")", ")", ";", "return", "new", "Real", "(", "$", "value", ")", ";", "}" ]
Calculates the distance between two Coordinate objects @param Coordinate $coordinate @param DistanceUnit $unit @param DistanceFormula $formula @return Real
[ "Calculates", "the", "distance", "between", "two", "Coordinate", "objects" ]
4554239ab75d65eeb9773219aa5b07e9fbfabb92
https://github.com/cubicmushroom/valueobjects/blob/4554239ab75d65eeb9773219aa5b07e9fbfabb92/src/Geography/Coordinate.php#L165-L188
train
cubicmushroom/valueobjects
src/Geography/Coordinate.php
Coordinate.getBaseCoordinate
protected static function getBaseCoordinate(self $coordinate) { $latitude = $coordinate->getLatitude()->toNative(); $longitude = $coordinate->getLongitude()->toNative(); $ellipsoid = BaseEllipsoid::createFromName($coordinate->getEllipsoid()->toNative()); $coordinate = new BaseCoordinate(array($latitude, $longitude), $ellipsoid); return $coordinate; }
php
protected static function getBaseCoordinate(self $coordinate) { $latitude = $coordinate->getLatitude()->toNative(); $longitude = $coordinate->getLongitude()->toNative(); $ellipsoid = BaseEllipsoid::createFromName($coordinate->getEllipsoid()->toNative()); $coordinate = new BaseCoordinate(array($latitude, $longitude), $ellipsoid); return $coordinate; }
[ "protected", "static", "function", "getBaseCoordinate", "(", "self", "$", "coordinate", ")", "{", "$", "latitude", "=", "$", "coordinate", "->", "getLatitude", "(", ")", "->", "toNative", "(", ")", ";", "$", "longitude", "=", "$", "coordinate", "->", "getLongitude", "(", ")", "->", "toNative", "(", ")", ";", "$", "ellipsoid", "=", "BaseEllipsoid", "::", "createFromName", "(", "$", "coordinate", "->", "getEllipsoid", "(", ")", "->", "toNative", "(", ")", ")", ";", "$", "coordinate", "=", "new", "BaseCoordinate", "(", "array", "(", "$", "latitude", ",", "$", "longitude", ")", ",", "$", "ellipsoid", ")", ";", "return", "$", "coordinate", ";", "}" ]
Returns the underlying Coordinate object @param self $coordinate @return BaseCoordinate
[ "Returns", "the", "underlying", "Coordinate", "object" ]
4554239ab75d65eeb9773219aa5b07e9fbfabb92
https://github.com/cubicmushroom/valueobjects/blob/4554239ab75d65eeb9773219aa5b07e9fbfabb92/src/Geography/Coordinate.php#L206-L214
train
judus/minimal-event
src/Subscriber.php
Subscriber.getEventActions
public function getEventActions($eventName) { $events = isset($this->events[$eventName]) ? $this->events[$eventName] : []; return is_array($events) ? $events : [$events]; }
php
public function getEventActions($eventName) { $events = isset($this->events[$eventName]) ? $this->events[$eventName] : []; return is_array($events) ? $events : [$events]; }
[ "public", "function", "getEventActions", "(", "$", "eventName", ")", "{", "$", "events", "=", "isset", "(", "$", "this", "->", "events", "[", "$", "eventName", "]", ")", "?", "$", "this", "->", "events", "[", "$", "eventName", "]", ":", "[", "]", ";", "return", "is_array", "(", "$", "events", ")", "?", "$", "events", ":", "[", "$", "events", "]", ";", "}" ]
Returns a list of methods associated with a event @param $name @return array|mixed
[ "Returns", "a", "list", "of", "methods", "associated", "with", "a", "event" ]
031c634080b434c68466bb8207351055120a51e0
https://github.com/judus/minimal-event/blob/031c634080b434c68466bb8207351055120a51e0/src/Subscriber.php#L37-L42
train
judus/minimal-event
src/Subscriber.php
Subscriber.handle
public function handle($eventName, $data = null) { $results = []; if ($actions = $this->getEventActions($eventName)) { $actions = is_array($actions) ? $actions : [$actions]; $data = is_array($data) ? $data : [$data]; foreach ($actions as $action) { if ($result = $this->call($eventName, $action, $data)) { $results[$action] = $result; } } } return count($results) === 1 ? reset($results) : $results; }
php
public function handle($eventName, $data = null) { $results = []; if ($actions = $this->getEventActions($eventName)) { $actions = is_array($actions) ? $actions : [$actions]; $data = is_array($data) ? $data : [$data]; foreach ($actions as $action) { if ($result = $this->call($eventName, $action, $data)) { $results[$action] = $result; } } } return count($results) === 1 ? reset($results) : $results; }
[ "public", "function", "handle", "(", "$", "eventName", ",", "$", "data", "=", "null", ")", "{", "$", "results", "=", "[", "]", ";", "if", "(", "$", "actions", "=", "$", "this", "->", "getEventActions", "(", "$", "eventName", ")", ")", "{", "$", "actions", "=", "is_array", "(", "$", "actions", ")", "?", "$", "actions", ":", "[", "$", "actions", "]", ";", "$", "data", "=", "is_array", "(", "$", "data", ")", "?", "$", "data", ":", "[", "$", "data", "]", ";", "foreach", "(", "$", "actions", "as", "$", "action", ")", "{", "if", "(", "$", "result", "=", "$", "this", "->", "call", "(", "$", "eventName", ",", "$", "action", ",", "$", "data", ")", ")", "{", "$", "results", "[", "$", "action", "]", "=", "$", "result", ";", "}", "}", "}", "return", "count", "(", "$", "results", ")", "===", "1", "?", "reset", "(", "$", "results", ")", ":", "$", "results", ";", "}" ]
Handles the event @param $eventName @param null $data @return array|mixed
[ "Handles", "the", "event" ]
031c634080b434c68466bb8207351055120a51e0
https://github.com/judus/minimal-event/blob/031c634080b434c68466bb8207351055120a51e0/src/Subscriber.php#L52-L69
train
judus/minimal-event
src/Subscriber.php
Subscriber.call
protected function call($eventName, $method, $data = null) { if (method_exists($this, $method)) { $result = call_user_func_array([$this, $method], $data); return $result; } return null; }
php
protected function call($eventName, $method, $data = null) { if (method_exists($this, $method)) { $result = call_user_func_array([$this, $method], $data); return $result; } return null; }
[ "protected", "function", "call", "(", "$", "eventName", ",", "$", "method", ",", "$", "data", "=", "null", ")", "{", "if", "(", "method_exists", "(", "$", "this", ",", "$", "method", ")", ")", "{", "$", "result", "=", "call_user_func_array", "(", "[", "$", "this", ",", "$", "method", "]", ",", "$", "data", ")", ";", "return", "$", "result", ";", "}", "return", "null", ";", "}" ]
Calls a event method @param $method @param null $data @return mixed|null
[ "Calls", "a", "event", "method" ]
031c634080b434c68466bb8207351055120a51e0
https://github.com/judus/minimal-event/blob/031c634080b434c68466bb8207351055120a51e0/src/Subscriber.php#L79-L87
train
fridge-project/dbal
src/Fridge/DBAL/Schema/Diff/TableDiff.php
TableDiff.hasColumnDifference
private function hasColumnDifference() { return !empty($this->createdColumns) || !empty($this->alteredColumns) || !empty($this->droppedColumns); }
php
private function hasColumnDifference() { return !empty($this->createdColumns) || !empty($this->alteredColumns) || !empty($this->droppedColumns); }
[ "private", "function", "hasColumnDifference", "(", ")", "{", "return", "!", "empty", "(", "$", "this", "->", "createdColumns", ")", "||", "!", "empty", "(", "$", "this", "->", "alteredColumns", ")", "||", "!", "empty", "(", "$", "this", "->", "droppedColumns", ")", ";", "}" ]
Checks if the table diff has column difference. @return boolean TRUE if the table has column difference else FALSE.
[ "Checks", "if", "the", "table", "diff", "has", "column", "difference", "." ]
d0b8c3551922d696836487aa0eb1bd74014edcd4
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/Diff/TableDiff.php#L249-L252
train
SetBased/php-affirm
src/ErrorHandler.php
ErrorHandler.handleError
public function handleError($errno, $errstr, $errfile, $errline) { if (error_reporting()===0) { // Error was suppressed with the @-operator. Don't throw an exception. return false; } $exception = new ErrorException($errstr, $errno, $errno, $errfile, $errline); // In case error appeared in __toString method we can't throw any exception. $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); array_shift($trace); foreach ($trace as $frame) { if ($frame['function']==='__toString') { $this->handleException($exception); exit(1); } } throw $exception; }
php
public function handleError($errno, $errstr, $errfile, $errline) { if (error_reporting()===0) { // Error was suppressed with the @-operator. Don't throw an exception. return false; } $exception = new ErrorException($errstr, $errno, $errno, $errfile, $errline); // In case error appeared in __toString method we can't throw any exception. $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); array_shift($trace); foreach ($trace as $frame) { if ($frame['function']==='__toString') { $this->handleException($exception); exit(1); } } throw $exception; }
[ "public", "function", "handleError", "(", "$", "errno", ",", "$", "errstr", ",", "$", "errfile", ",", "$", "errline", ")", "{", "if", "(", "error_reporting", "(", ")", "===", "0", ")", "{", "// Error was suppressed with the @-operator. Don't throw an exception.", "return", "false", ";", "}", "$", "exception", "=", "new", "ErrorException", "(", "$", "errstr", ",", "$", "errno", ",", "$", "errno", ",", "$", "errfile", ",", "$", "errline", ")", ";", "// In case error appeared in __toString method we can't throw any exception.", "$", "trace", "=", "debug_backtrace", "(", "DEBUG_BACKTRACE_IGNORE_ARGS", ")", ";", "array_shift", "(", "$", "trace", ")", ";", "foreach", "(", "$", "trace", "as", "$", "frame", ")", "{", "if", "(", "$", "frame", "[", "'function'", "]", "===", "'__toString'", ")", "{", "$", "this", "->", "handleException", "(", "$", "exception", ")", ";", "exit", "(", "1", ")", ";", "}", "}", "throw", "$", "exception", ";", "}" ]
An error handler function that throws exceptions. @param int $errno The level of the error raised. @param string $errstr The error message. @param string $errfile The filename that the error was raised in. @param string $errline The line number the error was raised at. @return bool See http://php.net/manual/en/function.set-error-handler.php. @throws ErrorException
[ "An", "error", "handler", "function", "that", "throws", "exceptions", "." ]
79394b5ced13bb675546652819dbcd94c4f9ac73
https://github.com/SetBased/php-affirm/blob/79394b5ced13bb675546652819dbcd94c4f9ac73/src/ErrorHandler.php#L39-L63
train
SetBased/php-affirm
src/ErrorHandler.php
ErrorHandler.register
public function register($theDebug = false, $theErrorTypes = null) { // PHP 5.6 set default value with expression. if ($theErrorTypes===null) { $theErrorTypes = E_ALL | E_STRICT; } $this->myDebug = $theDebug; ini_set('display_errors', false); set_exception_handler([$this, 'handleException']); set_error_handler([$this, 'handleError'], $theErrorTypes); }
php
public function register($theDebug = false, $theErrorTypes = null) { // PHP 5.6 set default value with expression. if ($theErrorTypes===null) { $theErrorTypes = E_ALL | E_STRICT; } $this->myDebug = $theDebug; ini_set('display_errors', false); set_exception_handler([$this, 'handleException']); set_error_handler([$this, 'handleError'], $theErrorTypes); }
[ "public", "function", "register", "(", "$", "theDebug", "=", "false", ",", "$", "theErrorTypes", "=", "null", ")", "{", "// PHP 5.6 set default value with expression.", "if", "(", "$", "theErrorTypes", "===", "null", ")", "{", "$", "theErrorTypes", "=", "E_ALL", "|", "E_STRICT", ";", "}", "$", "this", "->", "myDebug", "=", "$", "theDebug", ";", "ini_set", "(", "'display_errors'", ",", "false", ")", ";", "set_exception_handler", "(", "[", "$", "this", ",", "'handleException'", "]", ")", ";", "set_error_handler", "(", "[", "$", "this", ",", "'handleError'", "]", ",", "$", "theErrorTypes", ")", ";", "}" ]
Registers this error handler. @param bool $theDebug If true details and call trace of exceptions are shown. @param null|int $theErrorTypes The mask for triggering this error handler. Defaults to E_ALL | E_STRICT.
[ "Registers", "this", "error", "handler", "." ]
79394b5ced13bb675546652819dbcd94c4f9ac73
https://github.com/SetBased/php-affirm/blob/79394b5ced13bb675546652819dbcd94c4f9ac73/src/ErrorHandler.php#L114-L127
train
dms-org/common.structure
src/Web/IpAddress.php
IpAddress.validateString
protected function validateString(string $string) { if (strlen($string) > self::MAX_LENGTH || !filter_var($string, FILTER_VALIDATE_IP)) { throw InvalidArgumentException::format( 'Cannot construct class %s: argument must be a valid ip address, \'%s\' given', get_class($this), $string ); } }
php
protected function validateString(string $string) { if (strlen($string) > self::MAX_LENGTH || !filter_var($string, FILTER_VALIDATE_IP)) { throw InvalidArgumentException::format( 'Cannot construct class %s: argument must be a valid ip address, \'%s\' given', get_class($this), $string ); } }
[ "protected", "function", "validateString", "(", "string", "$", "string", ")", "{", "if", "(", "strlen", "(", "$", "string", ")", ">", "self", "::", "MAX_LENGTH", "||", "!", "filter_var", "(", "$", "string", ",", "FILTER_VALIDATE_IP", ")", ")", "{", "throw", "InvalidArgumentException", "::", "format", "(", "'Cannot construct class %s: argument must be a valid ip address, \\'%s\\' given'", ",", "get_class", "(", "$", "this", ")", ",", "$", "string", ")", ";", "}", "}" ]
Validates the string is in the required format. @param string $string @return void @throws InvalidArgumentException
[ "Validates", "the", "string", "is", "in", "the", "required", "format", "." ]
23f122182f60df5ec847047a81a39c8aab019ff1
https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/Web/IpAddress.php#L28-L36
train
djmattyg007/Handlebars
src/Compiler.php
Compiler.parseArguments
protected function parseArguments(string $string): ArgumentList { $argParser = $this->argumentParserFactory->create($string); return $argParser->tokenise(); }
php
protected function parseArguments(string $string): ArgumentList { $argParser = $this->argumentParserFactory->create($string); return $argParser->tokenise(); }
[ "protected", "function", "parseArguments", "(", "string", "$", "string", ")", ":", "ArgumentList", "{", "$", "argParser", "=", "$", "this", "->", "argumentParserFactory", "->", "create", "(", "$", "string", ")", ";", "return", "$", "argParser", "->", "tokenise", "(", ")", ";", "}" ]
Handlebars will give arguments in a string. This will transform them into a legitimate argument array. @param string $string The argument string. @return ArgumentList @throws Exception
[ "Handlebars", "will", "give", "arguments", "in", "a", "string", ".", "This", "will", "transform", "them", "into", "a", "legitimate", "argument", "array", "." ]
3f5b36ec22194cdc5d937a77aa71d500a760ebed
https://github.com/djmattyg007/Handlebars/blob/3f5b36ec22194cdc5d937a77aa71d500a760ebed/src/Compiler.php#L509-L513
train
erenmustafaozdal/laravel-modules-base
src/LaravelModulesBaseServiceProvider.php
LaravelModulesBaseServiceProvider.registerValidationRules
protected function registerValidationRules($validator) { /** * elfinder validator */ $validator->resolver(function($translator, $data, $rules, $messages) { return new BaseValidator($translator, $data, $rules, $messages); }); $validator->replacer('elfinder_max', function($message, $attribute, $rule, $parameters) { return str_replace(':size',$parameters[0],$message); }); $validator->replacer('elfinder', function($message, $attribute, $rule, $parameters) { return str_replace(':values',implode(', ', $parameters),$message); }); }
php
protected function registerValidationRules($validator) { /** * elfinder validator */ $validator->resolver(function($translator, $data, $rules, $messages) { return new BaseValidator($translator, $data, $rules, $messages); }); $validator->replacer('elfinder_max', function($message, $attribute, $rule, $parameters) { return str_replace(':size',$parameters[0],$message); }); $validator->replacer('elfinder', function($message, $attribute, $rule, $parameters) { return str_replace(':values',implode(', ', $parameters),$message); }); }
[ "protected", "function", "registerValidationRules", "(", "$", "validator", ")", "{", "/**\n * elfinder validator\n */", "$", "validator", "->", "resolver", "(", "function", "(", "$", "translator", ",", "$", "data", ",", "$", "rules", ",", "$", "messages", ")", "{", "return", "new", "BaseValidator", "(", "$", "translator", ",", "$", "data", ",", "$", "rules", ",", "$", "messages", ")", ";", "}", ")", ";", "$", "validator", "->", "replacer", "(", "'elfinder_max'", ",", "function", "(", "$", "message", ",", "$", "attribute", ",", "$", "rule", ",", "$", "parameters", ")", "{", "return", "str_replace", "(", "':size'", ",", "$", "parameters", "[", "0", "]", ",", "$", "message", ")", ";", "}", ")", ";", "$", "validator", "->", "replacer", "(", "'elfinder'", ",", "function", "(", "$", "message", ",", "$", "attribute", ",", "$", "rule", ",", "$", "parameters", ")", "{", "return", "str_replace", "(", "':values'", ",", "implode", "(", "', '", ",", "$", "parameters", ")", ",", "$", "message", ")", ";", "}", ")", ";", "}" ]
Registers validation rules @param \Illuminate\Validation\Validator $validator @return void
[ "Registers", "validation", "rules" ]
c26600543817642926bcf16ada84009e00d784e0
https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/LaravelModulesBaseServiceProvider.php#L121-L137
train
gplcart/cli
controllers/commands/PriceRule.php
PriceRule.cmdGetPriceRule
public function cmdGetPriceRule() { $result = $this->getListPriceRule(); $this->outputFormat($result); $this->outputFormatTablePriceRule($result); $this->output(); }
php
public function cmdGetPriceRule() { $result = $this->getListPriceRule(); $this->outputFormat($result); $this->outputFormatTablePriceRule($result); $this->output(); }
[ "public", "function", "cmdGetPriceRule", "(", ")", "{", "$", "result", "=", "$", "this", "->", "getListPriceRule", "(", ")", ";", "$", "this", "->", "outputFormat", "(", "$", "result", ")", ";", "$", "this", "->", "outputFormatTablePriceRule", "(", "$", "result", ")", ";", "$", "this", "->", "output", "(", ")", ";", "}" ]
Callback for "pricerule-get" command
[ "Callback", "for", "pricerule", "-", "get", "command" ]
e57dba53e291a225b4bff0c0d9b23d685dd1c125
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/PriceRule.php#L67-L73
train
gplcart/cli
controllers/commands/PriceRule.php
PriceRule.cmdUpdatePriceRule
public function cmdUpdatePriceRule() { $params = $this->getParam(); if (empty($params[0]) || count($params) < 2) { $this->errorAndExit($this->text('Invalid command')); } if (!is_numeric($params[0])) { $this->errorAndExit($this->text('Invalid argument')); } $this->setSubmitted(null, $params); $this->setSubmitted('update', $params[0]); $this->validateComponent('price_rule'); $this->updatePriceRule($params[0]); $this->output(); }
php
public function cmdUpdatePriceRule() { $params = $this->getParam(); if (empty($params[0]) || count($params) < 2) { $this->errorAndExit($this->text('Invalid command')); } if (!is_numeric($params[0])) { $this->errorAndExit($this->text('Invalid argument')); } $this->setSubmitted(null, $params); $this->setSubmitted('update', $params[0]); $this->validateComponent('price_rule'); $this->updatePriceRule($params[0]); $this->output(); }
[ "public", "function", "cmdUpdatePriceRule", "(", ")", "{", "$", "params", "=", "$", "this", "->", "getParam", "(", ")", ";", "if", "(", "empty", "(", "$", "params", "[", "0", "]", ")", "||", "count", "(", "$", "params", ")", "<", "2", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Invalid command'", ")", ")", ";", "}", "if", "(", "!", "is_numeric", "(", "$", "params", "[", "0", "]", ")", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Invalid argument'", ")", ")", ";", "}", "$", "this", "->", "setSubmitted", "(", "null", ",", "$", "params", ")", ";", "$", "this", "->", "setSubmitted", "(", "'update'", ",", "$", "params", "[", "0", "]", ")", ";", "$", "this", "->", "validateComponent", "(", "'price_rule'", ")", ";", "$", "this", "->", "updatePriceRule", "(", "$", "params", "[", "0", "]", ")", ";", "$", "this", "->", "output", "(", ")", ";", "}" ]
Callback for "pricerule-update" command
[ "Callback", "for", "pricerule", "-", "update", "command" ]
e57dba53e291a225b4bff0c0d9b23d685dd1c125
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/PriceRule.php#L140-L158
train
gplcart/cli
controllers/commands/PriceRule.php
PriceRule.addPriceRule
protected function addPriceRule() { if (!$this->isError()) { $id = $this->price_rule->add($this->getSubmitted()); if (empty($id)) { $this->errorAndExit($this->text('Unexpected result')); } $this->line($id); } }
php
protected function addPriceRule() { if (!$this->isError()) { $id = $this->price_rule->add($this->getSubmitted()); if (empty($id)) { $this->errorAndExit($this->text('Unexpected result')); } $this->line($id); } }
[ "protected", "function", "addPriceRule", "(", ")", "{", "if", "(", "!", "$", "this", "->", "isError", "(", ")", ")", "{", "$", "id", "=", "$", "this", "->", "price_rule", "->", "add", "(", "$", "this", "->", "getSubmitted", "(", ")", ")", ";", "if", "(", "empty", "(", "$", "id", ")", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Unexpected result'", ")", ")", ";", "}", "$", "this", "->", "line", "(", "$", "id", ")", ";", "}", "}" ]
Add a new price rule
[ "Add", "a", "new", "price", "rule" ]
e57dba53e291a225b4bff0c0d9b23d685dd1c125
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/PriceRule.php#L229-L238
train
gplcart/cli
controllers/commands/PriceRule.php
PriceRule.submitAddPriceRule
protected function submitAddPriceRule() { $this->setSubmitted(null, $this->getParam()); $this->validateComponent('price_rule'); $this->addPriceRule(); }
php
protected function submitAddPriceRule() { $this->setSubmitted(null, $this->getParam()); $this->validateComponent('price_rule'); $this->addPriceRule(); }
[ "protected", "function", "submitAddPriceRule", "(", ")", "{", "$", "this", "->", "setSubmitted", "(", "null", ",", "$", "this", "->", "getParam", "(", ")", ")", ";", "$", "this", "->", "validateComponent", "(", "'price_rule'", ")", ";", "$", "this", "->", "addPriceRule", "(", ")", ";", "}" ]
Add a new price rule at once
[ "Add", "a", "new", "price", "rule", "at", "once" ]
e57dba53e291a225b4bff0c0d9b23d685dd1c125
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/PriceRule.php#L254-L259
train
gplcart/cli
controllers/commands/PriceRule.php
PriceRule.wizardAddPriceRule
protected function wizardAddPriceRule() { $this->validatePrompt('name', $this->text('Name'), 'price_rule'); $this->validatePrompt('trigger_id', $this->text('Trigger ID'), 'price_rule'); $types = array(); foreach ($this->price_rule->getTypes() as $id => $type) { $types[$id] = $type['title']; } $this->validateMenu('value_type', $this->text('Value type'), 'price_rule', $types, 'percent'); $this->validatePrompt('value', $this->text('Value'), 'price_rule'); $this->validatePrompt('currency', $this->text('Currency'), 'price_rule', $this->currency->getDefault()); $this->validatePrompt('code', $this->text('Code'), 'price_rule', ''); $this->validatePrompt('status', $this->text('Status'), 'price_rule', 0); $this->validatePrompt('weight', $this->text('Weight'), 'price_rule', 0); $this->validateComponent('price_rule'); $this->addPriceRule(); }
php
protected function wizardAddPriceRule() { $this->validatePrompt('name', $this->text('Name'), 'price_rule'); $this->validatePrompt('trigger_id', $this->text('Trigger ID'), 'price_rule'); $types = array(); foreach ($this->price_rule->getTypes() as $id => $type) { $types[$id] = $type['title']; } $this->validateMenu('value_type', $this->text('Value type'), 'price_rule', $types, 'percent'); $this->validatePrompt('value', $this->text('Value'), 'price_rule'); $this->validatePrompt('currency', $this->text('Currency'), 'price_rule', $this->currency->getDefault()); $this->validatePrompt('code', $this->text('Code'), 'price_rule', ''); $this->validatePrompt('status', $this->text('Status'), 'price_rule', 0); $this->validatePrompt('weight', $this->text('Weight'), 'price_rule', 0); $this->validateComponent('price_rule'); $this->addPriceRule(); }
[ "protected", "function", "wizardAddPriceRule", "(", ")", "{", "$", "this", "->", "validatePrompt", "(", "'name'", ",", "$", "this", "->", "text", "(", "'Name'", ")", ",", "'price_rule'", ")", ";", "$", "this", "->", "validatePrompt", "(", "'trigger_id'", ",", "$", "this", "->", "text", "(", "'Trigger ID'", ")", ",", "'price_rule'", ")", ";", "$", "types", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "price_rule", "->", "getTypes", "(", ")", "as", "$", "id", "=>", "$", "type", ")", "{", "$", "types", "[", "$", "id", "]", "=", "$", "type", "[", "'title'", "]", ";", "}", "$", "this", "->", "validateMenu", "(", "'value_type'", ",", "$", "this", "->", "text", "(", "'Value type'", ")", ",", "'price_rule'", ",", "$", "types", ",", "'percent'", ")", ";", "$", "this", "->", "validatePrompt", "(", "'value'", ",", "$", "this", "->", "text", "(", "'Value'", ")", ",", "'price_rule'", ")", ";", "$", "this", "->", "validatePrompt", "(", "'currency'", ",", "$", "this", "->", "text", "(", "'Currency'", ")", ",", "'price_rule'", ",", "$", "this", "->", "currency", "->", "getDefault", "(", ")", ")", ";", "$", "this", "->", "validatePrompt", "(", "'code'", ",", "$", "this", "->", "text", "(", "'Code'", ")", ",", "'price_rule'", ",", "''", ")", ";", "$", "this", "->", "validatePrompt", "(", "'status'", ",", "$", "this", "->", "text", "(", "'Status'", ")", ",", "'price_rule'", ",", "0", ")", ";", "$", "this", "->", "validatePrompt", "(", "'weight'", ",", "$", "this", "->", "text", "(", "'Weight'", ")", ",", "'price_rule'", ",", "0", ")", ";", "$", "this", "->", "validateComponent", "(", "'price_rule'", ")", ";", "$", "this", "->", "addPriceRule", "(", ")", ";", "}" ]
Add a new price rule step by step
[ "Add", "a", "new", "price", "rule", "step", "by", "step" ]
e57dba53e291a225b4bff0c0d9b23d685dd1c125
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/PriceRule.php#L264-L283
train
gplcart/cli
controllers/commands/PriceRule.php
PriceRule.setStatusPriceRule
protected function setStatusPriceRule($status) { $id = $this->getParam(0); $all = $this->getParam('all'); if (!isset($id) && !$all) { $this->errorAndExit($this->text('Invalid command')); } $result = $options = null; if (isset($id)) { if (empty($id) || !is_numeric($id)) { $this->errorAndExit($this->text('Invalid argument')); } if ($this->getParam('trigger')) { $options = array('trigger_id' => $id); } else { $result = $this->price_rule->update($id, array('status' => $status)); } } else if ($all) { $options = array(); } if (isset($options)) { $updated = $count = 0; foreach ($this->price_rule->getList($options) as $item) { $count++; $updated += (int) $this->price_rule->update($item['price_rule_id'], array('status' => $status)); } $result = $count && $count == $updated; } if (empty($result)) { $this->errorAndExit($this->text('Unexpected result')); } $this->output(); }
php
protected function setStatusPriceRule($status) { $id = $this->getParam(0); $all = $this->getParam('all'); if (!isset($id) && !$all) { $this->errorAndExit($this->text('Invalid command')); } $result = $options = null; if (isset($id)) { if (empty($id) || !is_numeric($id)) { $this->errorAndExit($this->text('Invalid argument')); } if ($this->getParam('trigger')) { $options = array('trigger_id' => $id); } else { $result = $this->price_rule->update($id, array('status' => $status)); } } else if ($all) { $options = array(); } if (isset($options)) { $updated = $count = 0; foreach ($this->price_rule->getList($options) as $item) { $count++; $updated += (int) $this->price_rule->update($item['price_rule_id'], array('status' => $status)); } $result = $count && $count == $updated; } if (empty($result)) { $this->errorAndExit($this->text('Unexpected result')); } $this->output(); }
[ "protected", "function", "setStatusPriceRule", "(", "$", "status", ")", "{", "$", "id", "=", "$", "this", "->", "getParam", "(", "0", ")", ";", "$", "all", "=", "$", "this", "->", "getParam", "(", "'all'", ")", ";", "if", "(", "!", "isset", "(", "$", "id", ")", "&&", "!", "$", "all", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Invalid command'", ")", ")", ";", "}", "$", "result", "=", "$", "options", "=", "null", ";", "if", "(", "isset", "(", "$", "id", ")", ")", "{", "if", "(", "empty", "(", "$", "id", ")", "||", "!", "is_numeric", "(", "$", "id", ")", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Invalid argument'", ")", ")", ";", "}", "if", "(", "$", "this", "->", "getParam", "(", "'trigger'", ")", ")", "{", "$", "options", "=", "array", "(", "'trigger_id'", "=>", "$", "id", ")", ";", "}", "else", "{", "$", "result", "=", "$", "this", "->", "price_rule", "->", "update", "(", "$", "id", ",", "array", "(", "'status'", "=>", "$", "status", ")", ")", ";", "}", "}", "else", "if", "(", "$", "all", ")", "{", "$", "options", "=", "array", "(", ")", ";", "}", "if", "(", "isset", "(", "$", "options", ")", ")", "{", "$", "updated", "=", "$", "count", "=", "0", ";", "foreach", "(", "$", "this", "->", "price_rule", "->", "getList", "(", "$", "options", ")", "as", "$", "item", ")", "{", "$", "count", "++", ";", "$", "updated", "+=", "(", "int", ")", "$", "this", "->", "price_rule", "->", "update", "(", "$", "item", "[", "'price_rule_id'", "]", ",", "array", "(", "'status'", "=>", "$", "status", ")", ")", ";", "}", "$", "result", "=", "$", "count", "&&", "$", "count", "==", "$", "updated", ";", "}", "if", "(", "empty", "(", "$", "result", ")", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Unexpected result'", ")", ")", ";", "}", "$", "this", "->", "output", "(", ")", ";", "}" ]
Sets status for one or several price rules @param bool $status
[ "Sets", "status", "for", "one", "or", "several", "price", "rules" ]
e57dba53e291a225b4bff0c0d9b23d685dd1c125
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/PriceRule.php#L289-L332
train
sinri/Ark-Cache
src/ArkCache.php
ArkCache.turnDateIntervalToSeconds
public static function turnDateIntervalToSeconds(DateInterval $dateInterval) { return $dateInterval->y * 365 * 24 * 3600 + $dateInterval->m * 30 * 24 * 3600 + $dateInterval->d * 24 * 3600 + $dateInterval->h * 3600 + $dateInterval->i * 60 + $dateInterval->s; }
php
public static function turnDateIntervalToSeconds(DateInterval $dateInterval) { return $dateInterval->y * 365 * 24 * 3600 + $dateInterval->m * 30 * 24 * 3600 + $dateInterval->d * 24 * 3600 + $dateInterval->h * 3600 + $dateInterval->i * 60 + $dateInterval->s; }
[ "public", "static", "function", "turnDateIntervalToSeconds", "(", "DateInterval", "$", "dateInterval", ")", "{", "return", "$", "dateInterval", "->", "y", "*", "365", "*", "24", "*", "3600", "+", "$", "dateInterval", "->", "m", "*", "30", "*", "24", "*", "3600", "+", "$", "dateInterval", "->", "d", "*", "24", "*", "3600", "+", "$", "dateInterval", "->", "h", "*", "3600", "+", "$", "dateInterval", "->", "i", "*", "60", "+", "$", "dateInterval", "->", "s", ";", "}" ]
1 Year is defined as 365 days and 1 Month is defined as 30 days @param DateInterval $dateInterval @return float|int turn to seconds
[ "1", "Year", "is", "defined", "as", "365", "days", "and", "1", "Month", "is", "defined", "as", "30", "days" ]
224d0b4aa9ae54c3f05348cd11b918c2836b1d3d
https://github.com/sinri/Ark-Cache/blob/224d0b4aa9ae54c3f05348cd11b918c2836b1d3d/src/ArkCache.php#L74-L82
train
hiqdev/minii-widgets
src/ListView.php
ListView.renderItem
public function renderItem($model, $key, $index) { if ($this->itemView === null) { $content = $key; } elseif (is_string($this->itemView)) { $content = $this->getView()->render($this->itemView, array_merge([ 'model' => $model, 'key' => $key, 'index' => $index, 'widget' => $this, ], $this->viewParams)); } else { $content = call_user_func($this->itemView, $model, $key, $index, $this); } $options = $this->itemOptions; $tag = ArrayHelper::remove($options, 'tag', 'div'); if ($tag !== false) { $options['data-key'] = is_array($key) ? json_encode($key, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : (string) $key; return Html::tag($tag, $content, $options); } else { return $content; } }
php
public function renderItem($model, $key, $index) { if ($this->itemView === null) { $content = $key; } elseif (is_string($this->itemView)) { $content = $this->getView()->render($this->itemView, array_merge([ 'model' => $model, 'key' => $key, 'index' => $index, 'widget' => $this, ], $this->viewParams)); } else { $content = call_user_func($this->itemView, $model, $key, $index, $this); } $options = $this->itemOptions; $tag = ArrayHelper::remove($options, 'tag', 'div'); if ($tag !== false) { $options['data-key'] = is_array($key) ? json_encode($key, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : (string) $key; return Html::tag($tag, $content, $options); } else { return $content; } }
[ "public", "function", "renderItem", "(", "$", "model", ",", "$", "key", ",", "$", "index", ")", "{", "if", "(", "$", "this", "->", "itemView", "===", "null", ")", "{", "$", "content", "=", "$", "key", ";", "}", "elseif", "(", "is_string", "(", "$", "this", "->", "itemView", ")", ")", "{", "$", "content", "=", "$", "this", "->", "getView", "(", ")", "->", "render", "(", "$", "this", "->", "itemView", ",", "array_merge", "(", "[", "'model'", "=>", "$", "model", ",", "'key'", "=>", "$", "key", ",", "'index'", "=>", "$", "index", ",", "'widget'", "=>", "$", "this", ",", "]", ",", "$", "this", "->", "viewParams", ")", ")", ";", "}", "else", "{", "$", "content", "=", "call_user_func", "(", "$", "this", "->", "itemView", ",", "$", "model", ",", "$", "key", ",", "$", "index", ",", "$", "this", ")", ";", "}", "$", "options", "=", "$", "this", "->", "itemOptions", ";", "$", "tag", "=", "ArrayHelper", "::", "remove", "(", "$", "options", ",", "'tag'", ",", "'div'", ")", ";", "if", "(", "$", "tag", "!==", "false", ")", "{", "$", "options", "[", "'data-key'", "]", "=", "is_array", "(", "$", "key", ")", "?", "json_encode", "(", "$", "key", ",", "JSON_UNESCAPED_SLASHES", "|", "JSON_UNESCAPED_UNICODE", ")", ":", "(", "string", ")", "$", "key", ";", "return", "Html", "::", "tag", "(", "$", "tag", ",", "$", "content", ",", "$", "options", ")", ";", "}", "else", "{", "return", "$", "content", ";", "}", "}" ]
Renders a single data model. @param mixed $model the data model to be rendered @param mixed $key the key value associated with the data model @param integer $index the zero-based index of the data model in the model array returned by [[dataProvider]]. @return string the rendering result
[ "Renders", "a", "single", "data", "model", "." ]
b8bc54a3645e9e45c228e3ec81b11ff4775385c3
https://github.com/hiqdev/minii-widgets/blob/b8bc54a3645e9e45c228e3ec81b11ff4775385c3/src/ListView.php#L90-L113
train
rafrsr/lib-array2object
src/Utils.php
Utils.getClassProperties
public static function getClassProperties($class) { if (is_string($class)) { if (isset(self::$classPropertyes[$class])) { return self::$classPropertyes[$class]; } $class = new \ReflectionClass($class); } if (!$class instanceof \ReflectionClass) { throw new \InvalidArgumentException('The arguments must be a valid class name or reflection'); } if (isset(self::$classPropertyes[$class->getName()])) { return self::$classPropertyes[$class->getName()]; } $props = $class->getProperties(); $props_arr = []; foreach ($props as $prop) { $f = $prop->getName(); $props_arr[$f] = $prop; } if ($parentClass = $class->getParentClass()) { $parent_props_arr = static::getClassProperties($parentClass);//RECURSION if (count($parent_props_arr) > 0) { $props_arr = array_merge($parent_props_arr, $props_arr); } } self::$classPropertyes[$class->getName()] = $props_arr; return $props_arr; }
php
public static function getClassProperties($class) { if (is_string($class)) { if (isset(self::$classPropertyes[$class])) { return self::$classPropertyes[$class]; } $class = new \ReflectionClass($class); } if (!$class instanceof \ReflectionClass) { throw new \InvalidArgumentException('The arguments must be a valid class name or reflection'); } if (isset(self::$classPropertyes[$class->getName()])) { return self::$classPropertyes[$class->getName()]; } $props = $class->getProperties(); $props_arr = []; foreach ($props as $prop) { $f = $prop->getName(); $props_arr[$f] = $prop; } if ($parentClass = $class->getParentClass()) { $parent_props_arr = static::getClassProperties($parentClass);//RECURSION if (count($parent_props_arr) > 0) { $props_arr = array_merge($parent_props_arr, $props_arr); } } self::$classPropertyes[$class->getName()] = $props_arr; return $props_arr; }
[ "public", "static", "function", "getClassProperties", "(", "$", "class", ")", "{", "if", "(", "is_string", "(", "$", "class", ")", ")", "{", "if", "(", "isset", "(", "self", "::", "$", "classPropertyes", "[", "$", "class", "]", ")", ")", "{", "return", "self", "::", "$", "classPropertyes", "[", "$", "class", "]", ";", "}", "$", "class", "=", "new", "\\", "ReflectionClass", "(", "$", "class", ")", ";", "}", "if", "(", "!", "$", "class", "instanceof", "\\", "ReflectionClass", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The arguments must be a valid class name or reflection'", ")", ";", "}", "if", "(", "isset", "(", "self", "::", "$", "classPropertyes", "[", "$", "class", "->", "getName", "(", ")", "]", ")", ")", "{", "return", "self", "::", "$", "classPropertyes", "[", "$", "class", "->", "getName", "(", ")", "]", ";", "}", "$", "props", "=", "$", "class", "->", "getProperties", "(", ")", ";", "$", "props_arr", "=", "[", "]", ";", "foreach", "(", "$", "props", "as", "$", "prop", ")", "{", "$", "f", "=", "$", "prop", "->", "getName", "(", ")", ";", "$", "props_arr", "[", "$", "f", "]", "=", "$", "prop", ";", "}", "if", "(", "$", "parentClass", "=", "$", "class", "->", "getParentClass", "(", ")", ")", "{", "$", "parent_props_arr", "=", "static", "::", "getClassProperties", "(", "$", "parentClass", ")", ";", "//RECURSION", "if", "(", "count", "(", "$", "parent_props_arr", ")", ">", "0", ")", "{", "$", "props_arr", "=", "array_merge", "(", "$", "parent_props_arr", ",", "$", "props_arr", ")", ";", "}", "}", "self", "::", "$", "classPropertyes", "[", "$", "class", "->", "getName", "(", ")", "]", "=", "$", "props_arr", ";", "return", "$", "props_arr", ";", "}" ]
Get array of class properties including parents private properties. @param \ReflectionClass|string $class @return array|\ReflectionProperty[] @throws \ReflectionException @throws \InvalidArgumentException
[ "Get", "array", "of", "class", "properties", "including", "parents", "private", "properties", "." ]
d15db63b5f5740dbc7c2213373320445785856ef
https://github.com/rafrsr/lib-array2object/blob/d15db63b5f5740dbc7c2213373320445785856ef/src/Utils.php#L33-L68
train
jabernardo/lollipop-php
Library/HTTP/URL/Pretty.php
Pretty.getUrl
public function getUrl(array $data = []) { // Guess the what URL should be looked like $translation_guess = preg_replace(['/\[([^\[]+)\]/is', '/{(\w*?)}/is', '/{(\w*?):(:?.*?)}/is'], '{$1}', $this->_path); $keys = []; preg_match_all('/{(\w*?)}/is', $translation_guess, $keys); foreach ($keys[1] as $key) { $translation_guess = str_replace('{'.$key.'}', isset($data[$key]) ? $data[$key] : 'null', $translation_guess); } // Get raw pattern from route $translation = preg_replace(['/\//is', '/\[([^\[]+)\]/is', '/{(\w*?)}/is'],['\/', '(?:$1)?', '{$1:([^\/]+)}'], $this->_path); $keyex = []; preg_match_all('/{(\w*?):(.*?)}/', $translation, $keyex); $groups = array_map(function($val) { return '(' . trim(trim($val, ')'), '(') . ')'; }, $keyex[2]); $translation = str_replace($keyex[0], $groups, $translation); // Check if guess is valid $test = preg_match("#^$translation$#is", $translation_guess, $vals); return $test ? $translation_guess : ''; }
php
public function getUrl(array $data = []) { // Guess the what URL should be looked like $translation_guess = preg_replace(['/\[([^\[]+)\]/is', '/{(\w*?)}/is', '/{(\w*?):(:?.*?)}/is'], '{$1}', $this->_path); $keys = []; preg_match_all('/{(\w*?)}/is', $translation_guess, $keys); foreach ($keys[1] as $key) { $translation_guess = str_replace('{'.$key.'}', isset($data[$key]) ? $data[$key] : 'null', $translation_guess); } // Get raw pattern from route $translation = preg_replace(['/\//is', '/\[([^\[]+)\]/is', '/{(\w*?)}/is'],['\/', '(?:$1)?', '{$1:([^\/]+)}'], $this->_path); $keyex = []; preg_match_all('/{(\w*?):(.*?)}/', $translation, $keyex); $groups = array_map(function($val) { return '(' . trim(trim($val, ')'), '(') . ')'; }, $keyex[2]); $translation = str_replace($keyex[0], $groups, $translation); // Check if guess is valid $test = preg_match("#^$translation$#is", $translation_guess, $vals); return $test ? $translation_guess : ''; }
[ "public", "function", "getUrl", "(", "array", "$", "data", "=", "[", "]", ")", "{", "// Guess the what URL should be looked like", "$", "translation_guess", "=", "preg_replace", "(", "[", "'/\\[([^\\[]+)\\]/is'", ",", "'/{(\\w*?)}/is'", ",", "'/{(\\w*?):(:?.*?)}/is'", "]", ",", "'{$1}'", ",", "$", "this", "->", "_path", ")", ";", "$", "keys", "=", "[", "]", ";", "preg_match_all", "(", "'/{(\\w*?)}/is'", ",", "$", "translation_guess", ",", "$", "keys", ")", ";", "foreach", "(", "$", "keys", "[", "1", "]", "as", "$", "key", ")", "{", "$", "translation_guess", "=", "str_replace", "(", "'{'", ".", "$", "key", ".", "'}'", ",", "isset", "(", "$", "data", "[", "$", "key", "]", ")", "?", "$", "data", "[", "$", "key", "]", ":", "'null'", ",", "$", "translation_guess", ")", ";", "}", "// Get raw pattern from route", "$", "translation", "=", "preg_replace", "(", "[", "'/\\//is'", ",", "'/\\[([^\\[]+)\\]/is'", ",", "'/{(\\w*?)}/is'", "]", ",", "[", "'\\/'", ",", "'(?:$1)?'", ",", "'{$1:([^\\/]+)}'", "]", ",", "$", "this", "->", "_path", ")", ";", "$", "keyex", "=", "[", "]", ";", "preg_match_all", "(", "'/{(\\w*?):(.*?)}/'", ",", "$", "translation", ",", "$", "keyex", ")", ";", "$", "groups", "=", "array_map", "(", "function", "(", "$", "val", ")", "{", "return", "'('", ".", "trim", "(", "trim", "(", "$", "val", ",", "')'", ")", ",", "'('", ")", ".", "')'", ";", "}", ",", "$", "keyex", "[", "2", "]", ")", ";", "$", "translation", "=", "str_replace", "(", "$", "keyex", "[", "0", "]", ",", "$", "groups", ",", "$", "translation", ")", ";", "// Check if guess is valid", "$", "test", "=", "preg_match", "(", "\"#^$translation$#is\"", ",", "$", "translation_guess", ",", "$", "vals", ")", ";", "return", "$", "test", "?", "$", "translation_guess", ":", "''", ";", "}" ]
Get route URL with parameters passed on. @example // Url: /categories/pages/{page} $pretty->getUrl(['page' => 10]); // Ouput: /categories/pages/10 @access public @param array $data URL parameters @return string Generated URL
[ "Get", "route", "URL", "with", "parameters", "passed", "on", "." ]
004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5
https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/HTTP/URL/Pretty.php#L140-L164
train
AnonymPHP/Anonym-Session
Stroge.php
Stroge.registerToHandler
protected function registerToHandler($name, $value, $crypt = false) { if (is_array($value) || is_object($value)) { $value = base64_encode(serialize($value)); } if (true === $crypt) { $value = $this->getCrypt()->encode($crypt); } $this->getHandler()->write($name, $value); }
php
protected function registerToHandler($name, $value, $crypt = false) { if (is_array($value) || is_object($value)) { $value = base64_encode(serialize($value)); } if (true === $crypt) { $value = $this->getCrypt()->encode($crypt); } $this->getHandler()->write($name, $value); }
[ "protected", "function", "registerToHandler", "(", "$", "name", ",", "$", "value", ",", "$", "crypt", "=", "false", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", "||", "is_object", "(", "$", "value", ")", ")", "{", "$", "value", "=", "base64_encode", "(", "serialize", "(", "$", "value", ")", ")", ";", "}", "if", "(", "true", "===", "$", "crypt", ")", "{", "$", "value", "=", "$", "this", "->", "getCrypt", "(", ")", "->", "encode", "(", "$", "crypt", ")", ";", "}", "$", "this", "->", "getHandler", "(", ")", "->", "write", "(", "$", "name", ",", "$", "value", ")", ";", "}" ]
register a new session to handler @param string $name @param mixed $value @param bool|false $crypt
[ "register", "a", "new", "session", "to", "handler" ]
e13458c8d0f5df346cb86fca45c16f062098046d
https://github.com/AnonymPHP/Anonym-Session/blob/e13458c8d0f5df346cb86fca45c16f062098046d/Stroge.php#L145-L156
train
AnonymPHP/Anonym-Session
Stroge.php
Stroge.has
public function has($name) { $value = $this->get($name); return isset($value) ? $value : false; }
php
public function has($name) { $value = $this->get($name); return isset($value) ? $value : false; }
[ "public", "function", "has", "(", "$", "name", ")", "{", "$", "value", "=", "$", "this", "->", "get", "(", "$", "name", ")", ";", "return", "isset", "(", "$", "value", ")", "?", "$", "value", ":", "false", ";", "}" ]
check the value is exists @return mixed
[ "check", "the", "value", "is", "exists" ]
e13458c8d0f5df346cb86fca45c16f062098046d
https://github.com/AnonymPHP/Anonym-Session/blob/e13458c8d0f5df346cb86fca45c16f062098046d/Stroge.php#L201-L206
train
kaiohken1982/Neobazaar
src/Neobazaar/Form/View/Helper/FormDropdown.php
FormDropdown.renderOptions
public function renderOptions(array $options, array $selectedOptions = array()) { $template = '<li %s><a href="#">%s</a></li>'; $optionStrings = array(); $escapeHtml = $this->getEscapeHtmlHelper(); foreach ($options as $key => $optionSpec) { $value = ''; $label = ''; $selected = false; $disabled = false; if (is_scalar($optionSpec)) { $optionSpec = array( 'label' => $optionSpec, 'value' => $key ); } if (isset($optionSpec['options']) && is_array($optionSpec['options'])) { $optionStrings[] = $this->renderOptgroup($optionSpec, $selectedOptions); continue; } if (isset($optionSpec['value'])) { $value = $optionSpec['value']; } if (isset($optionSpec['label'])) { $label = $optionSpec['label']; } if (isset($optionSpec['selected'])) { $selected = $optionSpec['selected']; } if (isset($optionSpec['disabled'])) { $disabled = $optionSpec['disabled']; } if (ArrayUtils::inArray($value, $selectedOptions)) { $selected = true; } if (null !== ($translator = $this->getTranslator())) { $label = $translator->translate( $label, $this->getTranslatorTextDomain() ); } $attributes = compact('value', 'selected', 'disabled'); if (isset($optionSpec['attributes']) && is_array($optionSpec['attributes'])) { $attributes = array_merge($attributes, $optionSpec['attributes']); } $this->validTagAttributes = $this->validOptionAttributes; $optionStrings[] = sprintf( $template, $this->createAttributesString($attributes), $escapeHtml($label) ); } return implode("\n", $optionStrings); }
php
public function renderOptions(array $options, array $selectedOptions = array()) { $template = '<li %s><a href="#">%s</a></li>'; $optionStrings = array(); $escapeHtml = $this->getEscapeHtmlHelper(); foreach ($options as $key => $optionSpec) { $value = ''; $label = ''; $selected = false; $disabled = false; if (is_scalar($optionSpec)) { $optionSpec = array( 'label' => $optionSpec, 'value' => $key ); } if (isset($optionSpec['options']) && is_array($optionSpec['options'])) { $optionStrings[] = $this->renderOptgroup($optionSpec, $selectedOptions); continue; } if (isset($optionSpec['value'])) { $value = $optionSpec['value']; } if (isset($optionSpec['label'])) { $label = $optionSpec['label']; } if (isset($optionSpec['selected'])) { $selected = $optionSpec['selected']; } if (isset($optionSpec['disabled'])) { $disabled = $optionSpec['disabled']; } if (ArrayUtils::inArray($value, $selectedOptions)) { $selected = true; } if (null !== ($translator = $this->getTranslator())) { $label = $translator->translate( $label, $this->getTranslatorTextDomain() ); } $attributes = compact('value', 'selected', 'disabled'); if (isset($optionSpec['attributes']) && is_array($optionSpec['attributes'])) { $attributes = array_merge($attributes, $optionSpec['attributes']); } $this->validTagAttributes = $this->validOptionAttributes; $optionStrings[] = sprintf( $template, $this->createAttributesString($attributes), $escapeHtml($label) ); } return implode("\n", $optionStrings); }
[ "public", "function", "renderOptions", "(", "array", "$", "options", ",", "array", "$", "selectedOptions", "=", "array", "(", ")", ")", "{", "$", "template", "=", "'<li %s><a href=\"#\">%s</a></li>'", ";", "$", "optionStrings", "=", "array", "(", ")", ";", "$", "escapeHtml", "=", "$", "this", "->", "getEscapeHtmlHelper", "(", ")", ";", "foreach", "(", "$", "options", "as", "$", "key", "=>", "$", "optionSpec", ")", "{", "$", "value", "=", "''", ";", "$", "label", "=", "''", ";", "$", "selected", "=", "false", ";", "$", "disabled", "=", "false", ";", "if", "(", "is_scalar", "(", "$", "optionSpec", ")", ")", "{", "$", "optionSpec", "=", "array", "(", "'label'", "=>", "$", "optionSpec", ",", "'value'", "=>", "$", "key", ")", ";", "}", "if", "(", "isset", "(", "$", "optionSpec", "[", "'options'", "]", ")", "&&", "is_array", "(", "$", "optionSpec", "[", "'options'", "]", ")", ")", "{", "$", "optionStrings", "[", "]", "=", "$", "this", "->", "renderOptgroup", "(", "$", "optionSpec", ",", "$", "selectedOptions", ")", ";", "continue", ";", "}", "if", "(", "isset", "(", "$", "optionSpec", "[", "'value'", "]", ")", ")", "{", "$", "value", "=", "$", "optionSpec", "[", "'value'", "]", ";", "}", "if", "(", "isset", "(", "$", "optionSpec", "[", "'label'", "]", ")", ")", "{", "$", "label", "=", "$", "optionSpec", "[", "'label'", "]", ";", "}", "if", "(", "isset", "(", "$", "optionSpec", "[", "'selected'", "]", ")", ")", "{", "$", "selected", "=", "$", "optionSpec", "[", "'selected'", "]", ";", "}", "if", "(", "isset", "(", "$", "optionSpec", "[", "'disabled'", "]", ")", ")", "{", "$", "disabled", "=", "$", "optionSpec", "[", "'disabled'", "]", ";", "}", "if", "(", "ArrayUtils", "::", "inArray", "(", "$", "value", ",", "$", "selectedOptions", ")", ")", "{", "$", "selected", "=", "true", ";", "}", "if", "(", "null", "!==", "(", "$", "translator", "=", "$", "this", "->", "getTranslator", "(", ")", ")", ")", "{", "$", "label", "=", "$", "translator", "->", "translate", "(", "$", "label", ",", "$", "this", "->", "getTranslatorTextDomain", "(", ")", ")", ";", "}", "$", "attributes", "=", "compact", "(", "'value'", ",", "'selected'", ",", "'disabled'", ")", ";", "if", "(", "isset", "(", "$", "optionSpec", "[", "'attributes'", "]", ")", "&&", "is_array", "(", "$", "optionSpec", "[", "'attributes'", "]", ")", ")", "{", "$", "attributes", "=", "array_merge", "(", "$", "attributes", ",", "$", "optionSpec", "[", "'attributes'", "]", ")", ";", "}", "$", "this", "->", "validTagAttributes", "=", "$", "this", "->", "validOptionAttributes", ";", "$", "optionStrings", "[", "]", "=", "sprintf", "(", "$", "template", ",", "$", "this", "->", "createAttributesString", "(", "$", "attributes", ")", ",", "$", "escapeHtml", "(", "$", "label", ")", ")", ";", "}", "return", "implode", "(", "\"\\n\"", ",", "$", "optionStrings", ")", ";", "}" ]
Render an array of options Individual options should be of the form: <code> array( 'value' => 'value', 'label' => 'label', 'disabled' => $booleanFlag, 'selected' => $booleanFlag, ) </code> @param array $options @param array $selectedOptions Option values that should be marked as selected @return string
[ "Render", "an", "array", "of", "options" ]
288c972dea981d715c4e136edb5dba0318c9e6cb
https://github.com/kaiohken1982/Neobazaar/blob/288c972dea981d715c4e136edb5dba0318c9e6cb/src/Neobazaar/Form/View/Helper/FormDropdown.php#L165-L227
train
kaiohken1982/Neobazaar
src/Neobazaar/Form/View/Helper/FormDropdown.php
FormDropdown.renderOptgroup
public function renderOptgroup(array $optgroup, array $selectedOptions = array()) { $template = '<optgroup%s>%s</optgroup>'; $options = array(); if (isset($optgroup['options']) && is_array($optgroup['options'])) { $options = $optgroup['options']; unset($optgroup['options']); } $this->validTagAttributes = $this->validOptgroupAttributes; $attributes = $this->createAttributesString($optgroup); if (!empty($attributes)) { $attributes = ' ' . $attributes; } return sprintf( $template, $attributes, $this->renderOptions($options, $selectedOptions) ); }
php
public function renderOptgroup(array $optgroup, array $selectedOptions = array()) { $template = '<optgroup%s>%s</optgroup>'; $options = array(); if (isset($optgroup['options']) && is_array($optgroup['options'])) { $options = $optgroup['options']; unset($optgroup['options']); } $this->validTagAttributes = $this->validOptgroupAttributes; $attributes = $this->createAttributesString($optgroup); if (!empty($attributes)) { $attributes = ' ' . $attributes; } return sprintf( $template, $attributes, $this->renderOptions($options, $selectedOptions) ); }
[ "public", "function", "renderOptgroup", "(", "array", "$", "optgroup", ",", "array", "$", "selectedOptions", "=", "array", "(", ")", ")", "{", "$", "template", "=", "'<optgroup%s>%s</optgroup>'", ";", "$", "options", "=", "array", "(", ")", ";", "if", "(", "isset", "(", "$", "optgroup", "[", "'options'", "]", ")", "&&", "is_array", "(", "$", "optgroup", "[", "'options'", "]", ")", ")", "{", "$", "options", "=", "$", "optgroup", "[", "'options'", "]", ";", "unset", "(", "$", "optgroup", "[", "'options'", "]", ")", ";", "}", "$", "this", "->", "validTagAttributes", "=", "$", "this", "->", "validOptgroupAttributes", ";", "$", "attributes", "=", "$", "this", "->", "createAttributesString", "(", "$", "optgroup", ")", ";", "if", "(", "!", "empty", "(", "$", "attributes", ")", ")", "{", "$", "attributes", "=", "' '", ".", "$", "attributes", ";", "}", "return", "sprintf", "(", "$", "template", ",", "$", "attributes", ",", "$", "this", "->", "renderOptions", "(", "$", "options", ",", "$", "selectedOptions", ")", ")", ";", "}" ]
Render an optgroup See {@link renderOptions()} for the options specification. Basically, an optgroup is simply an option that has an additional "options" key with an array following the specification for renderOptions(). @param array $optgroup @param array $selectedOptions @return string
[ "Render", "an", "optgroup" ]
288c972dea981d715c4e136edb5dba0318c9e6cb
https://github.com/kaiohken1982/Neobazaar/blob/288c972dea981d715c4e136edb5dba0318c9e6cb/src/Neobazaar/Form/View/Helper/FormDropdown.php#L240-L261
train
kaiohken1982/Neobazaar
src/Neobazaar/Form/View/Helper/FormDropdown.php
FormDropdown.validateMultiValue
protected function validateMultiValue($value, array $attributes) { if (null === $value) { return array(); } if (!is_array($value)) { return (array) $value; } if (!isset($attributes['multiple']) || !$attributes['multiple']) { throw new Exception\DomainException(sprintf( '%s does not allow specifying multiple selected values when the element does not have a multiple attribute set to a boolean true', __CLASS__ )); } return $value; }
php
protected function validateMultiValue($value, array $attributes) { if (null === $value) { return array(); } if (!is_array($value)) { return (array) $value; } if (!isset($attributes['multiple']) || !$attributes['multiple']) { throw new Exception\DomainException(sprintf( '%s does not allow specifying multiple selected values when the element does not have a multiple attribute set to a boolean true', __CLASS__ )); } return $value; }
[ "protected", "function", "validateMultiValue", "(", "$", "value", ",", "array", "$", "attributes", ")", "{", "if", "(", "null", "===", "$", "value", ")", "{", "return", "array", "(", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "value", ")", ")", "{", "return", "(", "array", ")", "$", "value", ";", "}", "if", "(", "!", "isset", "(", "$", "attributes", "[", "'multiple'", "]", ")", "||", "!", "$", "attributes", "[", "'multiple'", "]", ")", "{", "throw", "new", "Exception", "\\", "DomainException", "(", "sprintf", "(", "'%s does not allow specifying multiple selected values when the element does not have a multiple attribute set to a boolean true'", ",", "__CLASS__", ")", ")", ";", "}", "return", "$", "value", ";", "}" ]
Ensure that the value is set appropriately If the element's value attribute is an array, but there is no multiple attribute, or that attribute does not evaluate to true, then we have a domain issue -- you cannot have multiple options selected unless the multiple attribute is present and enabled. @param mixed $value @param array $attributes @return array @throws Exception\DomainException
[ "Ensure", "that", "the", "value", "is", "set", "appropriately" ]
288c972dea981d715c4e136edb5dba0318c9e6cb
https://github.com/kaiohken1982/Neobazaar/blob/288c972dea981d715c4e136edb5dba0318c9e6cb/src/Neobazaar/Form/View/Helper/FormDropdown.php#L276-L294
train
kaiohken1982/Neobazaar
src/Neobazaar/Form/View/Helper/FormDropdown.php
FormDropdown.renderHidden
protected function renderHidden(\Zend\Form\Element\Select $element, array $attributes) { $attributes['type'] = 'select'; $attributes['name'] .= '[id]'; // if (isset($attributes['id'])) { // $attributes['id'] .= '-hidden'; // } if (method_exists($element, 'getId')) { $attributes['value'] = $element->getId(); } elseif (array_key_exists('value', $attributes)) { if (is_array($attributes['value']) && array_key_exists('id', $attributes['value'])) { $attributes['value'] = $attributes['value']['id']; } } $closingBracket = $this->getInlineClosingBracket(); $hidden = sprintf( '<input %s%s', $this->createAttributesString($attributes), $closingBracket ); return $hidden; }
php
protected function renderHidden(\Zend\Form\Element\Select $element, array $attributes) { $attributes['type'] = 'select'; $attributes['name'] .= '[id]'; // if (isset($attributes['id'])) { // $attributes['id'] .= '-hidden'; // } if (method_exists($element, 'getId')) { $attributes['value'] = $element->getId(); } elseif (array_key_exists('value', $attributes)) { if (is_array($attributes['value']) && array_key_exists('id', $attributes['value'])) { $attributes['value'] = $attributes['value']['id']; } } $closingBracket = $this->getInlineClosingBracket(); $hidden = sprintf( '<input %s%s', $this->createAttributesString($attributes), $closingBracket ); return $hidden; }
[ "protected", "function", "renderHidden", "(", "\\", "Zend", "\\", "Form", "\\", "Element", "\\", "Select", "$", "element", ",", "array", "$", "attributes", ")", "{", "$", "attributes", "[", "'type'", "]", "=", "'select'", ";", "$", "attributes", "[", "'name'", "]", ".=", "'[id]'", ";", "// if (isset($attributes['id'])) {", "// $attributes['id'] .= '-hidden';", "// }", "if", "(", "method_exists", "(", "$", "element", ",", "'getId'", ")", ")", "{", "$", "attributes", "[", "'value'", "]", "=", "$", "element", "->", "getId", "(", ")", ";", "}", "elseif", "(", "array_key_exists", "(", "'value'", ",", "$", "attributes", ")", ")", "{", "if", "(", "is_array", "(", "$", "attributes", "[", "'value'", "]", ")", "&&", "array_key_exists", "(", "'id'", ",", "$", "attributes", "[", "'value'", "]", ")", ")", "{", "$", "attributes", "[", "'value'", "]", "=", "$", "attributes", "[", "'value'", "]", "[", "'id'", "]", ";", "}", "}", "$", "closingBracket", "=", "$", "this", "->", "getInlineClosingBracket", "(", ")", ";", "$", "hidden", "=", "sprintf", "(", "'<input %s%s'", ",", "$", "this", "->", "createAttributesString", "(", "$", "attributes", ")", ",", "$", "closingBracket", ")", ";", "return", "$", "hidden", ";", "}" ]
Render the hidden input with the captcha identifier @param CaptchaAdapter $captcha @param array $attributes @return string
[ "Render", "the", "hidden", "input", "with", "the", "captcha", "identifier" ]
288c972dea981d715c4e136edb5dba0318c9e6cb
https://github.com/kaiohken1982/Neobazaar/blob/288c972dea981d715c4e136edb5dba0318c9e6cb/src/Neobazaar/Form/View/Helper/FormDropdown.php#L328-L353
train
koolkode/http
src/Uri.php
Uri.toString
public function toString($to = self::TO_FRAGMENT, $schemaRelative = false) { if($to == static::TO_SCHEME) { return $this->scheme; } if($schemaRelative || empty($this->scheme)) { $uri = empty($this->host) ? '' : '//'; } else { $uri = empty($this->host) ? '' : ($this->scheme . '://'); } if(isset($this->username) && !empty($this->host)) { $uri .= $this->username; if(isset($this->password)) { $uri .= ':' . $this->password; } $uri .= '@'; } $uri .= $this->getHost(true) . '/'; if($to == static::TO_HOST) { return $uri; } $uri .= $this->getPath(true); if($to == static::TO_PATH) { return $uri; } if(!empty($this->query)) { $uri .= '?' . $this->getQueryString(); } if($to == static::TO_QUERY) { return $uri; } if(!empty($this->fragment)) { $uri .= '#' . $this->fragment; } return $uri; }
php
public function toString($to = self::TO_FRAGMENT, $schemaRelative = false) { if($to == static::TO_SCHEME) { return $this->scheme; } if($schemaRelative || empty($this->scheme)) { $uri = empty($this->host) ? '' : '//'; } else { $uri = empty($this->host) ? '' : ($this->scheme . '://'); } if(isset($this->username) && !empty($this->host)) { $uri .= $this->username; if(isset($this->password)) { $uri .= ':' . $this->password; } $uri .= '@'; } $uri .= $this->getHost(true) . '/'; if($to == static::TO_HOST) { return $uri; } $uri .= $this->getPath(true); if($to == static::TO_PATH) { return $uri; } if(!empty($this->query)) { $uri .= '?' . $this->getQueryString(); } if($to == static::TO_QUERY) { return $uri; } if(!empty($this->fragment)) { $uri .= '#' . $this->fragment; } return $uri; }
[ "public", "function", "toString", "(", "$", "to", "=", "self", "::", "TO_FRAGMENT", ",", "$", "schemaRelative", "=", "false", ")", "{", "if", "(", "$", "to", "==", "static", "::", "TO_SCHEME", ")", "{", "return", "$", "this", "->", "scheme", ";", "}", "if", "(", "$", "schemaRelative", "||", "empty", "(", "$", "this", "->", "scheme", ")", ")", "{", "$", "uri", "=", "empty", "(", "$", "this", "->", "host", ")", "?", "''", ":", "'//'", ";", "}", "else", "{", "$", "uri", "=", "empty", "(", "$", "this", "->", "host", ")", "?", "''", ":", "(", "$", "this", "->", "scheme", ".", "'://'", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "username", ")", "&&", "!", "empty", "(", "$", "this", "->", "host", ")", ")", "{", "$", "uri", ".=", "$", "this", "->", "username", ";", "if", "(", "isset", "(", "$", "this", "->", "password", ")", ")", "{", "$", "uri", ".=", "':'", ".", "$", "this", "->", "password", ";", "}", "$", "uri", ".=", "'@'", ";", "}", "$", "uri", ".=", "$", "this", "->", "getHost", "(", "true", ")", ".", "'/'", ";", "if", "(", "$", "to", "==", "static", "::", "TO_HOST", ")", "{", "return", "$", "uri", ";", "}", "$", "uri", ".=", "$", "this", "->", "getPath", "(", "true", ")", ";", "if", "(", "$", "to", "==", "static", "::", "TO_PATH", ")", "{", "return", "$", "uri", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "query", ")", ")", "{", "$", "uri", ".=", "'?'", ".", "$", "this", "->", "getQueryString", "(", ")", ";", "}", "if", "(", "$", "to", "==", "static", "::", "TO_QUERY", ")", "{", "return", "$", "uri", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "fragment", ")", ")", "{", "$", "uri", ".=", "'#'", ".", "$", "this", "->", "fragment", ";", "}", "return", "$", "uri", ";", "}" ]
Renders an encoded URI. @param integer $to Render parts (left to right) up to this part. @param boolean $schemaRelative Create a schema-relative URI? @return string
[ "Renders", "an", "encoded", "URI", "." ]
3c1626d409d5ce5d71d26f0e8f31ae3683a2a966
https://github.com/koolkode/http/blob/3c1626d409d5ce5d71d26f0e8f31ae3683a2a966/src/Uri.php#L144-L202
train
koolkode/http
src/Uri.php
Uri.encode
public static function encode($string, $encodeSlashes = false) { if($encodeSlashes) { return rawurlencode($string); } return implode('/', array_map('rawurlencode', explode('/', (string)$string))); }
php
public static function encode($string, $encodeSlashes = false) { if($encodeSlashes) { return rawurlencode($string); } return implode('/', array_map('rawurlencode', explode('/', (string)$string))); }
[ "public", "static", "function", "encode", "(", "$", "string", ",", "$", "encodeSlashes", "=", "false", ")", "{", "if", "(", "$", "encodeSlashes", ")", "{", "return", "rawurlencode", "(", "$", "string", ")", ";", "}", "return", "implode", "(", "'/'", ",", "array_map", "(", "'rawurlencode'", ",", "explode", "(", "'/'", ",", "(", "string", ")", "$", "string", ")", ")", ")", ";", "}" ]
URL-encode the given string. @param string $string @param boolean $encodeSlashes Apply percent encoding to slashes? @return string
[ "URL", "-", "encode", "the", "given", "string", "." ]
3c1626d409d5ce5d71d26f0e8f31ae3683a2a966
https://github.com/koolkode/http/blob/3c1626d409d5ce5d71d26f0e8f31ae3683a2a966/src/Uri.php#L400-L408
train
eureka-framework/component-http
src/Http/Message/Uri.php
Uri.setUserInfo
private function setUserInfo($user, $pass) { $this->userInfo = $user . (!empty($pass) ? ':' . $pass : ''); return $this; }
php
private function setUserInfo($user, $pass) { $this->userInfo = $user . (!empty($pass) ? ':' . $pass : ''); return $this; }
[ "private", "function", "setUserInfo", "(", "$", "user", ",", "$", "pass", ")", "{", "$", "this", "->", "userInfo", "=", "$", "user", ".", "(", "!", "empty", "(", "$", "pass", ")", "?", "':'", ".", "$", "pass", ":", "''", ")", ";", "return", "$", "this", ";", "}" ]
Set user info @param string $user @param string $pass @return self
[ "Set", "user", "info" ]
698c3b73581a9703a9c932890c57e50f8774607a
https://github.com/eureka-framework/component-http/blob/698c3b73581a9703a9c932890c57e50f8774607a/src/Http/Message/Uri.php#L610-L615
train
fiiSoft/fiisoft-logger
src/Logger/SmartLogger/AbstractSmartLogger.php
AbstractSmartLogger.setMinLevel
final public function setMinLevel($minLevel) { if (isset($this->levels[$minLevel])) { $this->minLevel = $this->levels[$minLevel]; } return $this; }
php
final public function setMinLevel($minLevel) { if (isset($this->levels[$minLevel])) { $this->minLevel = $this->levels[$minLevel]; } return $this; }
[ "final", "public", "function", "setMinLevel", "(", "$", "minLevel", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "levels", "[", "$", "minLevel", "]", ")", ")", "{", "$", "this", "->", "minLevel", "=", "$", "this", "->", "levels", "[", "$", "minLevel", "]", ";", "}", "return", "$", "this", ";", "}" ]
If set then only messages with level equal or greater then minLevel will be logged. @param string $minLevel @return $this fluent interface
[ "If", "set", "then", "only", "messages", "with", "level", "equal", "or", "greater", "then", "minLevel", "will", "be", "logged", "." ]
3d2eb9d18a785ec119d2fbeb9d34b74265e7dcf5
https://github.com/fiiSoft/fiisoft-logger/blob/3d2eb9d18a785ec119d2fbeb9d34b74265e7dcf5/src/Logger/SmartLogger/AbstractSmartLogger.php#L63-L70
train
atk14/StringBuffer
src/stringbuffer.php
StringBuffer.addString
function addString($string_to_add){ settype($string_to_add,"string"); if(strlen($string_to_add)>0){ $this->_Buffer[] = new StringBufferItem($string_to_add); } }
php
function addString($string_to_add){ settype($string_to_add,"string"); if(strlen($string_to_add)>0){ $this->_Buffer[] = new StringBufferItem($string_to_add); } }
[ "function", "addString", "(", "$", "string_to_add", ")", "{", "settype", "(", "$", "string_to_add", ",", "\"string\"", ")", ";", "if", "(", "strlen", "(", "$", "string_to_add", ")", ">", "0", ")", "{", "$", "this", "->", "_Buffer", "[", "]", "=", "new", "StringBufferItem", "(", "$", "string_to_add", ")", ";", "}", "}" ]
Adds another string to the buffer. @param string $string_to_add
[ "Adds", "another", "string", "to", "the", "buffer", "." ]
32f1580f23aff4d729a0a4ff82d3bd82b9194cc8
https://github.com/atk14/StringBuffer/blob/32f1580f23aff4d729a0a4ff82d3bd82b9194cc8/src/stringbuffer.php#L66-L71
train
atk14/StringBuffer
src/stringbuffer.php
StringBuffer.addStringBuffer
function addStringBuffer($stringbuffer_to_add){ if(!isset($stringbuffer_to_add)){ return;} for($i=0;$i<sizeof($stringbuffer_to_add->_Buffer);$i++){ $this->_Buffer[] = $stringbuffer_to_add->_Buffer[$i]; } }
php
function addStringBuffer($stringbuffer_to_add){ if(!isset($stringbuffer_to_add)){ return;} for($i=0;$i<sizeof($stringbuffer_to_add->_Buffer);$i++){ $this->_Buffer[] = $stringbuffer_to_add->_Buffer[$i]; } }
[ "function", "addStringBuffer", "(", "$", "stringbuffer_to_add", ")", "{", "if", "(", "!", "isset", "(", "$", "stringbuffer_to_add", ")", ")", "{", "return", ";", "}", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "sizeof", "(", "$", "stringbuffer_to_add", "->", "_Buffer", ")", ";", "$", "i", "++", ")", "{", "$", "this", "->", "_Buffer", "[", "]", "=", "$", "stringbuffer_to_add", "->", "_Buffer", "[", "$", "i", "]", ";", "}", "}" ]
Adds content of another StringBuffer to the buffer. @param StringBuffer $stringbuffer_to_add
[ "Adds", "content", "of", "another", "StringBuffer", "to", "the", "buffer", "." ]
32f1580f23aff4d729a0a4ff82d3bd82b9194cc8
https://github.com/atk14/StringBuffer/blob/32f1580f23aff4d729a0a4ff82d3bd82b9194cc8/src/stringbuffer.php#L89-L94
train
atk14/StringBuffer
src/stringbuffer.php
StringBuffer.getLength
function getLength(){ $out = 0; for($i=0;$i<sizeof($this->_Buffer);$i++){ $out = $out + $this->_Buffer[$i]->getLength(); } return $out; }
php
function getLength(){ $out = 0; for($i=0;$i<sizeof($this->_Buffer);$i++){ $out = $out + $this->_Buffer[$i]->getLength(); } return $out; }
[ "function", "getLength", "(", ")", "{", "$", "out", "=", "0", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "sizeof", "(", "$", "this", "->", "_Buffer", ")", ";", "$", "i", "++", ")", "{", "$", "out", "=", "$", "out", "+", "$", "this", "->", "_Buffer", "[", "$", "i", "]", "->", "getLength", "(", ")", ";", "}", "return", "$", "out", ";", "}" ]
Returns length of buffer content. @return integer
[ "Returns", "length", "of", "buffer", "content", "." ]
32f1580f23aff4d729a0a4ff82d3bd82b9194cc8
https://github.com/atk14/StringBuffer/blob/32f1580f23aff4d729a0a4ff82d3bd82b9194cc8/src/stringbuffer.php#L101-L107
train
atk14/StringBuffer
src/stringbuffer.php
StringBuffer.printOut
function printOut(){ for($i=0;$i<sizeof($this->_Buffer);$i++){ $this->_Buffer[$i]->flush(); } }
php
function printOut(){ for($i=0;$i<sizeof($this->_Buffer);$i++){ $this->_Buffer[$i]->flush(); } }
[ "function", "printOut", "(", ")", "{", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "sizeof", "(", "$", "this", "->", "_Buffer", ")", ";", "$", "i", "++", ")", "{", "$", "this", "->", "_Buffer", "[", "$", "i", "]", "->", "flush", "(", ")", ";", "}", "}" ]
Echoes content of buffer.
[ "Echoes", "content", "of", "buffer", "." ]
32f1580f23aff4d729a0a4ff82d3bd82b9194cc8
https://github.com/atk14/StringBuffer/blob/32f1580f23aff4d729a0a4ff82d3bd82b9194cc8/src/stringbuffer.php#L112-L116
train
atk14/StringBuffer
src/stringbuffer.php
StringBuffer.replace
function replace($search,$replace){ settype($search,"string"); // prevod StringBuffer na string if(is_object($replace)){ $replace = $replace->toString(); } for($i=0;$i<sizeof($this->_Buffer);$i++){ $this->_Buffer[$i]->replace($search,$replace); } }
php
function replace($search,$replace){ settype($search,"string"); // prevod StringBuffer na string if(is_object($replace)){ $replace = $replace->toString(); } for($i=0;$i<sizeof($this->_Buffer);$i++){ $this->_Buffer[$i]->replace($search,$replace); } }
[ "function", "replace", "(", "$", "search", ",", "$", "replace", ")", "{", "settype", "(", "$", "search", ",", "\"string\"", ")", ";", "// prevod StringBuffer na string", "if", "(", "is_object", "(", "$", "replace", ")", ")", "{", "$", "replace", "=", "$", "replace", "->", "toString", "(", ")", ";", "}", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "sizeof", "(", "$", "this", "->", "_Buffer", ")", ";", "$", "i", "++", ")", "{", "$", "this", "->", "_Buffer", "[", "$", "i", "]", "->", "replace", "(", "$", "search", ",", "$", "replace", ")", ";", "}", "}" ]
Replaces string in buffer with replacement string. @access public @param string $search replaced string @param string|StringBuffer $replace replacement string. or another StringBuffer object
[ "Replaces", "string", "in", "buffer", "with", "replacement", "string", "." ]
32f1580f23aff4d729a0a4ff82d3bd82b9194cc8
https://github.com/atk14/StringBuffer/blob/32f1580f23aff4d729a0a4ff82d3bd82b9194cc8/src/stringbuffer.php#L133-L144
train
atk14/StringBuffer
src/stringbuffer.php
StringBufferItem.replace
function replace($search,$replace){ $this->_String = str_replace($search,$replace,$this->_String); }
php
function replace($search,$replace){ $this->_String = str_replace($search,$replace,$this->_String); }
[ "function", "replace", "(", "$", "search", ",", "$", "replace", ")", "{", "$", "this", "->", "_String", "=", "str_replace", "(", "$", "search", ",", "$", "replace", ",", "$", "this", "->", "_String", ")", ";", "}" ]
Replace part of string in buffer @param string $search @param string $replace
[ "Replace", "part", "of", "string", "in", "buffer" ]
32f1580f23aff4d729a0a4ff82d3bd82b9194cc8
https://github.com/atk14/StringBuffer/blob/32f1580f23aff4d729a0a4ff82d3bd82b9194cc8/src/stringbuffer.php#L189-L191
train
atk14/StringBuffer
src/stringbuffer.php
StringBufferFileItem.toString
function toString(){ if(isset($this->_String)){ return parent::toString(); } return Files::GetFileContent($this->_Filename); }
php
function toString(){ if(isset($this->_String)){ return parent::toString(); } return Files::GetFileContent($this->_Filename); }
[ "function", "toString", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_String", ")", ")", "{", "return", "parent", "::", "toString", "(", ")", ";", "}", "return", "Files", "::", "GetFileContent", "(", "$", "this", "->", "_Filename", ")", ";", "}" ]
Outputs content of buffer as string. @return string
[ "Outputs", "content", "of", "buffer", "as", "string", "." ]
32f1580f23aff4d729a0a4ff82d3bd82b9194cc8
https://github.com/atk14/StringBuffer/blob/32f1580f23aff4d729a0a4ff82d3bd82b9194cc8/src/stringbuffer.php#L232-L235
train
atk14/StringBuffer
src/stringbuffer.php
StringBufferFileItem.replace
function replace($search,$replace){ $this->_String = $this->toString(); return parent::replace($search,$replace); }
php
function replace($search,$replace){ $this->_String = $this->toString(); return parent::replace($search,$replace); }
[ "function", "replace", "(", "$", "search", ",", "$", "replace", ")", "{", "$", "this", "->", "_String", "=", "$", "this", "->", "toString", "(", ")", ";", "return", "parent", "::", "replace", "(", "$", "search", ",", "$", "replace", ")", ";", "}" ]
Replaces part of a string with another string. @param string $search @param string $replace
[ "Replaces", "part", "of", "a", "string", "with", "another", "string", "." ]
32f1580f23aff4d729a0a4ff82d3bd82b9194cc8
https://github.com/atk14/StringBuffer/blob/32f1580f23aff4d729a0a4ff82d3bd82b9194cc8/src/stringbuffer.php#L243-L246
train
Linkvalue-Interne/MajoraFrameworkExtraBundle
src/Majora/Framework/Model/CollectionableTrait.php
CollectionableTrait.toCollection
protected function toCollection($data, $collectionClass) { if ($data instanceof $collectionClass) { return $data; } $data = $data ?: array(); if (!is_array($data) && !$data instanceof Collection) { throw new \InvalidArgumentException('Can transform only Collections or arrays.'); } return new $collectionClass( is_array($data) ? $data : $data->toArray() ); }
php
protected function toCollection($data, $collectionClass) { if ($data instanceof $collectionClass) { return $data; } $data = $data ?: array(); if (!is_array($data) && !$data instanceof Collection) { throw new \InvalidArgumentException('Can transform only Collections or arrays.'); } return new $collectionClass( is_array($data) ? $data : $data->toArray() ); }
[ "protected", "function", "toCollection", "(", "$", "data", ",", "$", "collectionClass", ")", "{", "if", "(", "$", "data", "instanceof", "$", "collectionClass", ")", "{", "return", "$", "data", ";", "}", "$", "data", "=", "$", "data", "?", ":", "array", "(", ")", ";", "if", "(", "!", "is_array", "(", "$", "data", ")", "&&", "!", "$", "data", "instanceof", "Collection", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Can transform only Collections or arrays.'", ")", ";", "}", "return", "new", "$", "collectionClass", "(", "is_array", "(", "$", "data", ")", "?", "$", "data", ":", "$", "data", "->", "toArray", "(", ")", ")", ";", "}" ]
helper method to use for cast arrays to collections of entities. @param Collection|array $data @param string $collectionClass @return EntityCollection
[ "helper", "method", "to", "use", "for", "cast", "arrays", "to", "collections", "of", "entities", "." ]
6f368380cfc39d27fafb0844e9a53b4d86d7c034
https://github.com/Linkvalue-Interne/MajoraFrameworkExtraBundle/blob/6f368380cfc39d27fafb0844e9a53b4d86d7c034/src/Majora/Framework/Model/CollectionableTrait.php#L21-L35
train
linpax/microphp-framework
src/base/Autoload.php
Autoload.setAlias
public static function setAlias($alias, $realPath) { if (is_string($alias) && is_string($realPath)) { self::$aliases[strtolower($alias)] = $realPath; } }
php
public static function setAlias($alias, $realPath) { if (is_string($alias) && is_string($realPath)) { self::$aliases[strtolower($alias)] = $realPath; } }
[ "public", "static", "function", "setAlias", "(", "$", "alias", ",", "$", "realPath", ")", "{", "if", "(", "is_string", "(", "$", "alias", ")", "&&", "is_string", "(", "$", "realPath", ")", ")", "{", "self", "::", "$", "aliases", "[", "strtolower", "(", "$", "alias", ")", "]", "=", "$", "realPath", ";", "}", "}" ]
Setting or installing new alias @access public @param string $alias name for new alias @param string $realPath path of alias @return void @static
[ "Setting", "or", "installing", "new", "alias" ]
11f3370f3f64c516cce9b84ecd8276c6e9ae8df9
https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/base/Autoload.php#L34-L39
train
linpax/microphp-framework
src/base/Autoload.php
Autoload.getClassPath
public static function getClassPath($className, $extension = '.php') { $prefix = $className = self::camelCaseToLowerNamespace(str_replace('_', '\\', $className)); while (false !== $position = strrpos($prefix, '\\')) { $prefix = substr($prefix, 0, $position); $alias = self::getAlias($prefix); if (!$alias) { continue; } $path = $alias.'\\'.substr($className, mb_strlen($prefix) + 1); $absolutePath = str_replace('\\', DIRECTORY_SEPARATOR, $path).$extension; if (is_readable($absolutePath)) { return $absolutePath; } } return false; }
php
public static function getClassPath($className, $extension = '.php') { $prefix = $className = self::camelCaseToLowerNamespace(str_replace('_', '\\', $className)); while (false !== $position = strrpos($prefix, '\\')) { $prefix = substr($prefix, 0, $position); $alias = self::getAlias($prefix); if (!$alias) { continue; } $path = $alias.'\\'.substr($className, mb_strlen($prefix) + 1); $absolutePath = str_replace('\\', DIRECTORY_SEPARATOR, $path).$extension; if (is_readable($absolutePath)) { return $absolutePath; } } return false; }
[ "public", "static", "function", "getClassPath", "(", "$", "className", ",", "$", "extension", "=", "'.php'", ")", "{", "$", "prefix", "=", "$", "className", "=", "self", "::", "camelCaseToLowerNamespace", "(", "str_replace", "(", "'_'", ",", "'\\\\'", ",", "$", "className", ")", ")", ";", "while", "(", "false", "!==", "$", "position", "=", "strrpos", "(", "$", "prefix", ",", "'\\\\'", ")", ")", "{", "$", "prefix", "=", "substr", "(", "$", "prefix", ",", "0", ",", "$", "position", ")", ";", "$", "alias", "=", "self", "::", "getAlias", "(", "$", "prefix", ")", ";", "if", "(", "!", "$", "alias", ")", "{", "continue", ";", "}", "$", "path", "=", "$", "alias", ".", "'\\\\'", ".", "substr", "(", "$", "className", ",", "mb_strlen", "(", "$", "prefix", ")", "+", "1", ")", ";", "$", "absolutePath", "=", "str_replace", "(", "'\\\\'", ",", "DIRECTORY_SEPARATOR", ",", "$", "path", ")", ".", "$", "extension", ";", "if", "(", "is_readable", "(", "$", "absolutePath", ")", ")", "{", "return", "$", "absolutePath", ";", "}", "}", "return", "false", ";", "}" ]
Get class path @access public @param string $className search class name @param string $extension extension of class @return string @static
[ "Get", "class", "path" ]
11f3370f3f64c516cce9b84ecd8276c6e9ae8df9
https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/base/Autoload.php#L74-L95
train
linpax/microphp-framework
src/base/Autoload.php
Autoload.camelCaseToLowerNamespace
private static function camelCaseToLowerNamespace($path) { $classNameArr = array_map(function($val) { return lcfirst($val); }, explode('\\', $path)); $classNameArr[] = ucfirst(array_pop($classNameArr)); return implode('\\', $classNameArr); }
php
private static function camelCaseToLowerNamespace($path) { $classNameArr = array_map(function($val) { return lcfirst($val); }, explode('\\', $path)); $classNameArr[] = ucfirst(array_pop($classNameArr)); return implode('\\', $classNameArr); }
[ "private", "static", "function", "camelCaseToLowerNamespace", "(", "$", "path", ")", "{", "$", "classNameArr", "=", "array_map", "(", "function", "(", "$", "val", ")", "{", "return", "lcfirst", "(", "$", "val", ")", ";", "}", ",", "explode", "(", "'\\\\'", ",", "$", "path", ")", ")", ";", "$", "classNameArr", "[", "]", "=", "ucfirst", "(", "array_pop", "(", "$", "classNameArr", ")", ")", ";", "return", "implode", "(", "'\\\\'", ",", "$", "classNameArr", ")", ";", "}" ]
Convert first symbols of namespace to lowercase @access protected @param string $path @return string @static
[ "Convert", "first", "symbols", "of", "namespace", "to", "lowercase" ]
11f3370f3f64c516cce9b84ecd8276c6e9ae8df9
https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/base/Autoload.php#L107-L116
train
ptlis/grep-db
src/Metadata/MySQL/DatabaseMetadata.php
DatabaseMetadata.getTableMetadata
public function getTableMetadata(string $tableName): TableMetadata { if (!array_key_exists($tableName, $this->tableMetadataList)) { throw new \RuntimeException('Database "' . $this->databaseName . '" doesn\'t contain table "' . $tableName . '"'); } return $this->tableMetadataList[$tableName]; }
php
public function getTableMetadata(string $tableName): TableMetadata { if (!array_key_exists($tableName, $this->tableMetadataList)) { throw new \RuntimeException('Database "' . $this->databaseName . '" doesn\'t contain table "' . $tableName . '"'); } return $this->tableMetadataList[$tableName]; }
[ "public", "function", "getTableMetadata", "(", "string", "$", "tableName", ")", ":", "TableMetadata", "{", "if", "(", "!", "array_key_exists", "(", "$", "tableName", ",", "$", "this", "->", "tableMetadataList", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Database \"'", ".", "$", "this", "->", "databaseName", ".", "'\" doesn\\'t contain table \"'", ".", "$", "tableName", ".", "'\"'", ")", ";", "}", "return", "$", "this", "->", "tableMetadataList", "[", "$", "tableName", "]", ";", "}" ]
Get the metadata for a single table.
[ "Get", "the", "metadata", "for", "a", "single", "table", "." ]
7abff68982d426690d0515ccd7adc7a2e3d72a3f
https://github.com/ptlis/grep-db/blob/7abff68982d426690d0515ccd7adc7a2e3d72a3f/src/Metadata/MySQL/DatabaseMetadata.php#L46-L53
train
PenoaksDev/Milky-Framework
src/Milky/Http/Routing/Controller.php
Controller.error
public function error( $code = 404, $msg = "Resource not found" ) { $request = HttpFactory::i()->request(); if ( $request->ajax() || $request->wantsJson() ) return new JsonResponse( ['error' => $msg] ); else return new Response( Redirect::back()->withInput( $request->input() )->withErrors( ['error' => $msg] ) ); }
php
public function error( $code = 404, $msg = "Resource not found" ) { $request = HttpFactory::i()->request(); if ( $request->ajax() || $request->wantsJson() ) return new JsonResponse( ['error' => $msg] ); else return new Response( Redirect::back()->withInput( $request->input() )->withErrors( ['error' => $msg] ) ); }
[ "public", "function", "error", "(", "$", "code", "=", "404", ",", "$", "msg", "=", "\"Resource not found\"", ")", "{", "$", "request", "=", "HttpFactory", "::", "i", "(", ")", "->", "request", "(", ")", ";", "if", "(", "$", "request", "->", "ajax", "(", ")", "||", "$", "request", "->", "wantsJson", "(", ")", ")", "return", "new", "JsonResponse", "(", "[", "'error'", "=>", "$", "msg", "]", ")", ";", "else", "return", "new", "Response", "(", "Redirect", "::", "back", "(", ")", "->", "withInput", "(", "$", "request", "->", "input", "(", ")", ")", "->", "withErrors", "(", "[", "'error'", "=>", "$", "msg", "]", ")", ")", ";", "}" ]
Produces a new error response based on if this is an api request or not. @param int $code @param string $msg @return JsonResponse|Response
[ "Produces", "a", "new", "error", "response", "based", "on", "if", "this", "is", "an", "api", "request", "or", "not", "." ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Http/Routing/Controller.php#L118-L126
train
Nekland/BaseApi
lib/Nekland/BaseApi/Api/AbstractApi.php
AbstractApi.get
protected function get($path, $body = [], array $headers = []) { $client = $this->getClient(); $request = AbstractHttpClient::createRequest('GET', $path, $body, $headers); return $this->transformer->transform($client->send($request)); }
php
protected function get($path, $body = [], array $headers = []) { $client = $this->getClient(); $request = AbstractHttpClient::createRequest('GET', $path, $body, $headers); return $this->transformer->transform($client->send($request)); }
[ "protected", "function", "get", "(", "$", "path", ",", "$", "body", "=", "[", "]", ",", "array", "$", "headers", "=", "[", "]", ")", "{", "$", "client", "=", "$", "this", "->", "getClient", "(", ")", ";", "$", "request", "=", "AbstractHttpClient", "::", "createRequest", "(", "'GET'", ",", "$", "path", ",", "$", "body", ",", "$", "headers", ")", ";", "return", "$", "this", "->", "transformer", "->", "transform", "(", "$", "client", "->", "send", "(", "$", "request", ")", ")", ";", "}" ]
Execute a http get query @param string $path @param array|string $body @param array $headers @return array|mixed
[ "Execute", "a", "http", "get", "query" ]
c96051b36d6982abf2a8b1f1ec16351bcae2455e
https://github.com/Nekland/BaseApi/blob/c96051b36d6982abf2a8b1f1ec16351bcae2455e/lib/Nekland/BaseApi/Api/AbstractApi.php#L57-L63
train
ekyna/Table
TableBuilder.php
TableBuilder.createColumn
public function createColumn($name, $type = null, array $options = []) { $this->preventIfLocked(); if (null !== $type) { return $this->getFactory()->createColumnBuilder($name, $type, $options); } throw new \InvalidArgumentException('Column type guessing is not yet supported.'); // TODO return $this->getFormFactory()->createBuilderForProperty($this->getDataClass(), $name, $options); }
php
public function createColumn($name, $type = null, array $options = []) { $this->preventIfLocked(); if (null !== $type) { return $this->getFactory()->createColumnBuilder($name, $type, $options); } throw new \InvalidArgumentException('Column type guessing is not yet supported.'); // TODO return $this->getFormFactory()->createBuilderForProperty($this->getDataClass(), $name, $options); }
[ "public", "function", "createColumn", "(", "$", "name", ",", "$", "type", "=", "null", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "this", "->", "preventIfLocked", "(", ")", ";", "if", "(", "null", "!==", "$", "type", ")", "{", "return", "$", "this", "->", "getFactory", "(", ")", "->", "createColumnBuilder", "(", "$", "name", ",", "$", "type", ",", "$", "options", ")", ";", "}", "throw", "new", "\\", "InvalidArgumentException", "(", "'Column type guessing is not yet supported.'", ")", ";", "// TODO return $this->getFormFactory()->createBuilderForProperty($this->getDataClass(), $name, $options);", "}" ]
Creates a column builder. @param string $name @param string $type @param array $options @return Column\ColumnBuilderInterface
[ "Creates", "a", "column", "builder", "." ]
6f06e8fd8a3248d52f3a91f10508471344db311a
https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/TableBuilder.php#L101-L111
train
ekyna/Table
TableBuilder.php
TableBuilder.createFilter
public function createFilter($name, $type = null, array $options = []) { $this->preventIfLocked(); if (null !== $type) { return $this->getFactory()->createFilterBuilder($name, $type, $options); } throw new \InvalidArgumentException('Filter type guessing is not yet supported.'); // TODO return $this->getFormFactory()->createFilterBuilderForProperty($this->getDataClass(), $name, $options); }
php
public function createFilter($name, $type = null, array $options = []) { $this->preventIfLocked(); if (null !== $type) { return $this->getFactory()->createFilterBuilder($name, $type, $options); } throw new \InvalidArgumentException('Filter type guessing is not yet supported.'); // TODO return $this->getFormFactory()->createFilterBuilderForProperty($this->getDataClass(), $name, $options); }
[ "public", "function", "createFilter", "(", "$", "name", ",", "$", "type", "=", "null", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "this", "->", "preventIfLocked", "(", ")", ";", "if", "(", "null", "!==", "$", "type", ")", "{", "return", "$", "this", "->", "getFactory", "(", ")", "->", "createFilterBuilder", "(", "$", "name", ",", "$", "type", ",", "$", "options", ")", ";", "}", "throw", "new", "\\", "InvalidArgumentException", "(", "'Filter type guessing is not yet supported.'", ")", ";", "// TODO return $this->getFormFactory()->createFilterBuilderForProperty($this->getDataClass(), $name, $options);", "}" ]
Creates a filter builder. @param string $name @param string $type @param array $options @return Filter\FilterBuilderInterface
[ "Creates", "a", "filter", "builder", "." ]
6f06e8fd8a3248d52f3a91f10508471344db311a
https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/TableBuilder.php#L185-L195
train
ekyna/Table
TableBuilder.php
TableBuilder.createAction
public function createAction($name, $type = null, array $options = []) { $this->preventIfLocked(); if (null !== $type) { return $this->getFactory()->createActionBuilder($name, $type, $options); } throw new \InvalidArgumentException('Action type guessing is not yet supported.'); // TODO return $this->getFormFactory()->createActionBuilderForProperty($this->getDataClass(), $name, $options); }
php
public function createAction($name, $type = null, array $options = []) { $this->preventIfLocked(); if (null !== $type) { return $this->getFactory()->createActionBuilder($name, $type, $options); } throw new \InvalidArgumentException('Action type guessing is not yet supported.'); // TODO return $this->getFormFactory()->createActionBuilderForProperty($this->getDataClass(), $name, $options); }
[ "public", "function", "createAction", "(", "$", "name", ",", "$", "type", "=", "null", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "this", "->", "preventIfLocked", "(", ")", ";", "if", "(", "null", "!==", "$", "type", ")", "{", "return", "$", "this", "->", "getFactory", "(", ")", "->", "createActionBuilder", "(", "$", "name", ",", "$", "type", ",", "$", "options", ")", ";", "}", "throw", "new", "\\", "InvalidArgumentException", "(", "'Action type guessing is not yet supported.'", ")", ";", "// TODO return $this->getFormFactory()->createActionBuilderForProperty($this->getDataClass(), $name, $options);", "}" ]
Creates a action builder. @param string $name @param string $type @param array $options @return Action\ActionBuilderInterface
[ "Creates", "a", "action", "builder", "." ]
6f06e8fd8a3248d52f3a91f10508471344db311a
https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/TableBuilder.php#L269-L279
train
ekyna/Table
TableBuilder.php
TableBuilder.resolveColumn
private function resolveColumn($name) { $info = $this->unresolvedColumns[$name]; $child = $this->createColumn($name, $info['type'], $info['options']); $this->columns[$name] = $child; unset($this->unresolvedColumns[$name]); return $child; }
php
private function resolveColumn($name) { $info = $this->unresolvedColumns[$name]; $child = $this->createColumn($name, $info['type'], $info['options']); $this->columns[$name] = $child; unset($this->unresolvedColumns[$name]); return $child; }
[ "private", "function", "resolveColumn", "(", "$", "name", ")", "{", "$", "info", "=", "$", "this", "->", "unresolvedColumns", "[", "$", "name", "]", ";", "$", "child", "=", "$", "this", "->", "createColumn", "(", "$", "name", ",", "$", "info", "[", "'type'", "]", ",", "$", "info", "[", "'options'", "]", ")", ";", "$", "this", "->", "columns", "[", "$", "name", "]", "=", "$", "child", ";", "unset", "(", "$", "this", "->", "unresolvedColumns", "[", "$", "name", "]", ")", ";", "return", "$", "child", ";", "}" ]
Converts an unresolved column into a column builder instance. @param string $name The name of the unresolved column @return Column\ColumnBuilderInterface
[ "Converts", "an", "unresolved", "column", "into", "a", "column", "builder", "instance", "." ]
6f06e8fd8a3248d52f3a91f10508471344db311a
https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/TableBuilder.php#L365-L373
train
ekyna/Table
TableBuilder.php
TableBuilder.resolveFilter
private function resolveFilter($name) { $info = $this->unresolvedFilters[$name]; $child = $this->createFilter($name, $info['type'], $info['options']); $this->filters[$name] = $child; unset($this->unresolvedFilters[$name]); return $child; }
php
private function resolveFilter($name) { $info = $this->unresolvedFilters[$name]; $child = $this->createFilter($name, $info['type'], $info['options']); $this->filters[$name] = $child; unset($this->unresolvedFilters[$name]); return $child; }
[ "private", "function", "resolveFilter", "(", "$", "name", ")", "{", "$", "info", "=", "$", "this", "->", "unresolvedFilters", "[", "$", "name", "]", ";", "$", "child", "=", "$", "this", "->", "createFilter", "(", "$", "name", ",", "$", "info", "[", "'type'", "]", ",", "$", "info", "[", "'options'", "]", ")", ";", "$", "this", "->", "filters", "[", "$", "name", "]", "=", "$", "child", ";", "unset", "(", "$", "this", "->", "unresolvedFilters", "[", "$", "name", "]", ")", ";", "return", "$", "child", ";", "}" ]
Converts an unresolved filter into a filter builder instance. @param string $name The name of the unresolved filter @return Filter\FilterBuilderInterface
[ "Converts", "an", "unresolved", "filter", "into", "a", "filter", "builder", "instance", "." ]
6f06e8fd8a3248d52f3a91f10508471344db311a
https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/TableBuilder.php#L382-L390
train
ekyna/Table
TableBuilder.php
TableBuilder.resolveAction
private function resolveAction($name) { $info = $this->unresolvedActions[$name]; $child = $this->createAction($name, $info['type'], $info['options']); $this->actions[$name] = $child; unset($this->unresolvedActions[$name]); return $child; }
php
private function resolveAction($name) { $info = $this->unresolvedActions[$name]; $child = $this->createAction($name, $info['type'], $info['options']); $this->actions[$name] = $child; unset($this->unresolvedActions[$name]); return $child; }
[ "private", "function", "resolveAction", "(", "$", "name", ")", "{", "$", "info", "=", "$", "this", "->", "unresolvedActions", "[", "$", "name", "]", ";", "$", "child", "=", "$", "this", "->", "createAction", "(", "$", "name", ",", "$", "info", "[", "'type'", "]", ",", "$", "info", "[", "'options'", "]", ")", ";", "$", "this", "->", "actions", "[", "$", "name", "]", "=", "$", "child", ";", "unset", "(", "$", "this", "->", "unresolvedActions", "[", "$", "name", "]", ")", ";", "return", "$", "child", ";", "}" ]
Converts an unresolved action into a action builder instance. @param string $name The name of the unresolved action @return Action\ActionBuilderInterface
[ "Converts", "an", "unresolved", "action", "into", "a", "action", "builder", "instance", "." ]
6f06e8fd8a3248d52f3a91f10508471344db311a
https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/TableBuilder.php#L399-L407
train
ekyna/Table
TableBuilder.php
TableBuilder.resolveElements
private function resolveElements() { foreach ($this->unresolvedColumns as $name => $info) { $this->columns[$name] = $this->createColumn($name, $info['type'], $info['options']); } $this->unresolvedColumns = []; foreach ($this->unresolvedFilters as $name => $info) { $this->filters[$name] = $this->createFilter($name, $info['type'], $info['options']); } $this->unresolvedFilters = []; foreach ($this->unresolvedActions as $name => $info) { $this->actions[$name] = $this->createAction($name, $info['type'], $info['options']); } $this->unresolvedActions = []; }
php
private function resolveElements() { foreach ($this->unresolvedColumns as $name => $info) { $this->columns[$name] = $this->createColumn($name, $info['type'], $info['options']); } $this->unresolvedColumns = []; foreach ($this->unresolvedFilters as $name => $info) { $this->filters[$name] = $this->createFilter($name, $info['type'], $info['options']); } $this->unresolvedFilters = []; foreach ($this->unresolvedActions as $name => $info) { $this->actions[$name] = $this->createAction($name, $info['type'], $info['options']); } $this->unresolvedActions = []; }
[ "private", "function", "resolveElements", "(", ")", "{", "foreach", "(", "$", "this", "->", "unresolvedColumns", "as", "$", "name", "=>", "$", "info", ")", "{", "$", "this", "->", "columns", "[", "$", "name", "]", "=", "$", "this", "->", "createColumn", "(", "$", "name", ",", "$", "info", "[", "'type'", "]", ",", "$", "info", "[", "'options'", "]", ")", ";", "}", "$", "this", "->", "unresolvedColumns", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "unresolvedFilters", "as", "$", "name", "=>", "$", "info", ")", "{", "$", "this", "->", "filters", "[", "$", "name", "]", "=", "$", "this", "->", "createFilter", "(", "$", "name", ",", "$", "info", "[", "'type'", "]", ",", "$", "info", "[", "'options'", "]", ")", ";", "}", "$", "this", "->", "unresolvedFilters", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "unresolvedActions", "as", "$", "name", "=>", "$", "info", ")", "{", "$", "this", "->", "actions", "[", "$", "name", "]", "=", "$", "this", "->", "createAction", "(", "$", "name", ",", "$", "info", "[", "'type'", "]", ",", "$", "info", "[", "'options'", "]", ")", ";", "}", "$", "this", "->", "unresolvedActions", "=", "[", "]", ";", "}" ]
Converts all unresolved elements into builder instances.
[ "Converts", "all", "unresolved", "elements", "into", "builder", "instances", "." ]
6f06e8fd8a3248d52f3a91f10508471344db311a
https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/TableBuilder.php#L412-L428
train
stubbles/stubbles-peer
src/main/php/Uri.php
Uri.isSyntacticallyValid
protected function isSyntacticallyValid(): bool { if (preg_match('!^([a-z][a-z0-9\+]*)://([^@]+@)?([^/?#]*)(/([^#?]*))?(.*)$!', $this->parsedUri->asString()) == 0) { return false; } if ($this->parsedUri->hasUser()) { if (preg_match('~([@:/])~', $this->parsedUri->user()) != 0) { return false; } if (!empty($this->parsedUri->password()) && preg_match('~([@:/])~', $this->parsedUri->password()) != 0) { return false; } } if (!$this->parsedUri->hasHostname() || strlen($this->parsedUri->hostname()) === 0) { return true; } if ($this->parsedUri->hasHostname() && preg_match('!^([a-zA-Z0-9\.-]+|\[[^\]]+\])(:([0-9]+))?$!', $this->parsedUri->hostname()) != 0) { return true; } return false; }
php
protected function isSyntacticallyValid(): bool { if (preg_match('!^([a-z][a-z0-9\+]*)://([^@]+@)?([^/?#]*)(/([^#?]*))?(.*)$!', $this->parsedUri->asString()) == 0) { return false; } if ($this->parsedUri->hasUser()) { if (preg_match('~([@:/])~', $this->parsedUri->user()) != 0) { return false; } if (!empty($this->parsedUri->password()) && preg_match('~([@:/])~', $this->parsedUri->password()) != 0) { return false; } } if (!$this->parsedUri->hasHostname() || strlen($this->parsedUri->hostname()) === 0) { return true; } if ($this->parsedUri->hasHostname() && preg_match('!^([a-zA-Z0-9\.-]+|\[[^\]]+\])(:([0-9]+))?$!', $this->parsedUri->hostname()) != 0) { return true; } return false; }
[ "protected", "function", "isSyntacticallyValid", "(", ")", ":", "bool", "{", "if", "(", "preg_match", "(", "'!^([a-z][a-z0-9\\+]*)://([^@]+@)?([^/?#]*)(/([^#?]*))?(.*)$!'", ",", "$", "this", "->", "parsedUri", "->", "asString", "(", ")", ")", "==", "0", ")", "{", "return", "false", ";", "}", "if", "(", "$", "this", "->", "parsedUri", "->", "hasUser", "(", ")", ")", "{", "if", "(", "preg_match", "(", "'~([@:/])~'", ",", "$", "this", "->", "parsedUri", "->", "user", "(", ")", ")", "!=", "0", ")", "{", "return", "false", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "parsedUri", "->", "password", "(", ")", ")", "&&", "preg_match", "(", "'~([@:/])~'", ",", "$", "this", "->", "parsedUri", "->", "password", "(", ")", ")", "!=", "0", ")", "{", "return", "false", ";", "}", "}", "if", "(", "!", "$", "this", "->", "parsedUri", "->", "hasHostname", "(", ")", "||", "strlen", "(", "$", "this", "->", "parsedUri", "->", "hostname", "(", ")", ")", "===", "0", ")", "{", "return", "true", ";", "}", "if", "(", "$", "this", "->", "parsedUri", "->", "hasHostname", "(", ")", "&&", "preg_match", "(", "'!^([a-zA-Z0-9\\.-]+|\\[[^\\]]+\\])(:([0-9]+))?$!'", ",", "$", "this", "->", "parsedUri", "->", "hostname", "(", ")", ")", "!=", "0", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Checks whether URI is a syntactically correct URI. @return bool
[ "Checks", "whether", "URI", "is", "a", "syntactically", "correct", "URI", "." ]
dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc
https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/Uri.php#L52-L78
train
stubbles/stubbles-peer
src/main/php/Uri.php
Uri.asStringWithNonDefaultPort
public function asStringWithNonDefaultPort(): string { if ($this->parsedUri->hasPort() && !$this->hasDefaultPort()) { return $this->asString(); } return $this->asStringWithoutPort(); }
php
public function asStringWithNonDefaultPort(): string { if ($this->parsedUri->hasPort() && !$this->hasDefaultPort()) { return $this->asString(); } return $this->asStringWithoutPort(); }
[ "public", "function", "asStringWithNonDefaultPort", "(", ")", ":", "string", "{", "if", "(", "$", "this", "->", "parsedUri", "->", "hasPort", "(", ")", "&&", "!", "$", "this", "->", "hasDefaultPort", "(", ")", ")", "{", "return", "$", "this", "->", "asString", "(", ")", ";", "}", "return", "$", "this", "->", "asStringWithoutPort", "(", ")", ";", "}" ]
Returns uri as string containing the port if it is not the default port. @return string
[ "Returns", "uri", "as", "string", "containing", "the", "port", "if", "it", "is", "not", "the", "default", "port", "." ]
dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc
https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/Uri.php#L139-L146
train
stubbles/stubbles-peer
src/main/php/Uri.php
Uri.password
public function password(string $defaultPassword = null) { if (!$this->parsedUri->hasUser()) { return null; } if ($this->parsedUri->hasPassword()) { return $this->parsedUri->password(); } return $defaultPassword; }
php
public function password(string $defaultPassword = null) { if (!$this->parsedUri->hasUser()) { return null; } if ($this->parsedUri->hasPassword()) { return $this->parsedUri->password(); } return $defaultPassword; }
[ "public", "function", "password", "(", "string", "$", "defaultPassword", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "parsedUri", "->", "hasUser", "(", ")", ")", "{", "return", "null", ";", "}", "if", "(", "$", "this", "->", "parsedUri", "->", "hasPassword", "(", ")", ")", "{", "return", "$", "this", "->", "parsedUri", "->", "password", "(", ")", ";", "}", "return", "$", "defaultPassword", ";", "}" ]
returns the password @param string $defaultPassword password to return if no password is set @return string|null @deprecated since 8.0.0, passing a password via URI is inherintly insecure, will be removed with 9.0.0
[ "returns", "the", "password" ]
dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc
https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/Uri.php#L176-L187
train
stubbles/stubbles-peer
src/main/php/Uri.php
Uri.addParams
public function addParams(array $params): self { foreach ($params as $name => $value) { $this->addParam($name, $value); } return $this; }
php
public function addParams(array $params): self { foreach ($params as $name => $value) { $this->addParam($name, $value); } return $this; }
[ "public", "function", "addParams", "(", "array", "$", "params", ")", ":", "self", "{", "foreach", "(", "$", "params", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "this", "->", "addParam", "(", "$", "name", ",", "$", "value", ")", ";", "}", "return", "$", "this", ";", "}" ]
adds given map of params @param array $params map of parameters to add @return \stubbles\peer\Uri @since 5.1.2
[ "adds", "given", "map", "of", "params" ]
dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc
https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/Uri.php#L281-L288
train
stubbles/stubbles-peer
src/main/php/Uri.php
Uri.addParam
public function addParam(string $name, $value): self { $this->parsedUri->queryString()->addParam($name, $value); return $this; }
php
public function addParam(string $name, $value): self { $this->parsedUri->queryString()->addParam($name, $value); return $this; }
[ "public", "function", "addParam", "(", "string", "$", "name", ",", "$", "value", ")", ":", "self", "{", "$", "this", "->", "parsedUri", "->", "queryString", "(", ")", "->", "addParam", "(", "$", "name", ",", "$", "value", ")", ";", "return", "$", "this", ";", "}" ]
add a parameter to the uri @param string $name name of parameter @param mixed $value value of parameter @return \stubbles\peer\Uri
[ "add", "a", "parameter", "to", "the", "uri" ]
dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc
https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/Uri.php#L297-L301
train
stubbles/stubbles-peer
src/main/php/Uri.php
Uri.removeParam
public function removeParam(string $name): self { $this->parsedUri->queryString()->removeParam($name); return $this; }
php
public function removeParam(string $name): self { $this->parsedUri->queryString()->removeParam($name); return $this; }
[ "public", "function", "removeParam", "(", "string", "$", "name", ")", ":", "self", "{", "$", "this", "->", "parsedUri", "->", "queryString", "(", ")", "->", "removeParam", "(", "$", "name", ")", ";", "return", "$", "this", ";", "}" ]
remove a param from uri @param string $name name of parameter @return \stubbles\peer\Uri @since 1.1.2
[ "remove", "a", "param", "from", "uri" ]
dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc
https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/Uri.php#L310-L314
train
asaokamei/ScoreSql
src/Builder/Bind.php
Bind.prepare
public function prepare( $val, $col=null, $type=null ) { if( is_array( $val ) ) { $holder = []; foreach( $val as $key => $v ) { $holder[$key] = $this->prepare( $v, $col, $type ); } return $holder; } if( $val instanceof \Closure ) return $val; $holder = ( static::$useColumnInBindValues ) ? ':' : ''; $holder .= 'db_prep_' . $this->prepared_counter++; $this->prepared_values[ $holder ] = $val; $this->setPreparedType( $holder, $col, $type ); if( !static::$useColumnInBindValues ) $holder = ':'.$holder; return $holder; }
php
public function prepare( $val, $col=null, $type=null ) { if( is_array( $val ) ) { $holder = []; foreach( $val as $key => $v ) { $holder[$key] = $this->prepare( $v, $col, $type ); } return $holder; } if( $val instanceof \Closure ) return $val; $holder = ( static::$useColumnInBindValues ) ? ':' : ''; $holder .= 'db_prep_' . $this->prepared_counter++; $this->prepared_values[ $holder ] = $val; $this->setPreparedType( $holder, $col, $type ); if( !static::$useColumnInBindValues ) $holder = ':'.$holder; return $holder; }
[ "public", "function", "prepare", "(", "$", "val", ",", "$", "col", "=", "null", ",", "$", "type", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "val", ")", ")", "{", "$", "holder", "=", "[", "]", ";", "foreach", "(", "$", "val", "as", "$", "key", "=>", "$", "v", ")", "{", "$", "holder", "[", "$", "key", "]", "=", "$", "this", "->", "prepare", "(", "$", "v", ",", "$", "col", ",", "$", "type", ")", ";", "}", "return", "$", "holder", ";", "}", "if", "(", "$", "val", "instanceof", "\\", "Closure", ")", "return", "$", "val", ";", "$", "holder", "=", "(", "static", "::", "$", "useColumnInBindValues", ")", "?", "':'", ":", "''", ";", "$", "holder", ".=", "'db_prep_'", ".", "$", "this", "->", "prepared_counter", "++", ";", "$", "this", "->", "prepared_values", "[", "$", "holder", "]", "=", "$", "val", ";", "$", "this", "->", "setPreparedType", "(", "$", "holder", ",", "$", "col", ",", "$", "type", ")", ";", "if", "(", "!", "static", "::", "$", "useColumnInBindValues", ")", "$", "holder", "=", "':'", ".", "$", "holder", ";", "return", "$", "holder", ";", "}" ]
replaces value with place holder for prepared statement. the value is kept in prepared_value array. if $type is specified, or column data type is set in col_data_types, types for the place holder is kept in prepared_types array. @param string|array $val @param null|int|string $col column name. used to find data type @param null|int $type data type @return string|array
[ "replaces", "value", "with", "place", "holder", "for", "prepared", "statement", ".", "the", "value", "is", "kept", "in", "prepared_value", "array", "." ]
f1fce28476629e98b3c4c1216859c7f5309de7a1
https://github.com/asaokamei/ScoreSql/blob/f1fce28476629e98b3c4c1216859c7f5309de7a1/src/Builder/Bind.php#L55-L72
train
fridge-project/dbal
src/Fridge/DBAL/Schema/AbstractAsset.php
AbstractAsset.setName
public function setName($name) { if (!is_string($name) || (strlen($name) <= 0)) { $explodedNamespace = explode('\\', get_class($this)); $class = $explodedNamespace[count($explodedNamespace) - 1]; $asset = strtolower(preg_replace('/(.)([A-Z])/', '\\1 \\2', $class)); throw SchemaException::invalidAssetName($asset); } $this->name = $name; }
php
public function setName($name) { if (!is_string($name) || (strlen($name) <= 0)) { $explodedNamespace = explode('\\', get_class($this)); $class = $explodedNamespace[count($explodedNamespace) - 1]; $asset = strtolower(preg_replace('/(.)([A-Z])/', '\\1 \\2', $class)); throw SchemaException::invalidAssetName($asset); } $this->name = $name; }
[ "public", "function", "setName", "(", "$", "name", ")", "{", "if", "(", "!", "is_string", "(", "$", "name", ")", "||", "(", "strlen", "(", "$", "name", ")", "<=", "0", ")", ")", "{", "$", "explodedNamespace", "=", "explode", "(", "'\\\\'", ",", "get_class", "(", "$", "this", ")", ")", ";", "$", "class", "=", "$", "explodedNamespace", "[", "count", "(", "$", "explodedNamespace", ")", "-", "1", "]", ";", "$", "asset", "=", "strtolower", "(", "preg_replace", "(", "'/(.)([A-Z])/'", ",", "'\\\\1 \\\\2'", ",", "$", "class", ")", ")", ";", "throw", "SchemaException", "::", "invalidAssetName", "(", "$", "asset", ")", ";", "}", "$", "this", "->", "name", "=", "$", "name", ";", "}" ]
Sets the asset name. @param string $name The asset name. @throws \Fridge\DBAL\Exception\SchemaException If the name is not a valid string.
[ "Sets", "the", "asset", "name", "." ]
d0b8c3551922d696836487aa0eb1bd74014edcd4
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/AbstractAsset.php#L55-L66
train
fridge-project/dbal
src/Fridge/DBAL/Schema/AbstractAsset.php
AbstractAsset.generateIdentifier
protected function generateIdentifier($prefix, $maxLength) { $hash = null; $dictionary = 'abcdefghijklmnopqrstuvwxyz0123456789'; for ($i = 0; $i < ($maxLength - strlen($prefix)); $i++) { $hash .= $dictionary[mt_rand(0, strlen($dictionary) - 1)]; } return $prefix.$hash; }
php
protected function generateIdentifier($prefix, $maxLength) { $hash = null; $dictionary = 'abcdefghijklmnopqrstuvwxyz0123456789'; for ($i = 0; $i < ($maxLength - strlen($prefix)); $i++) { $hash .= $dictionary[mt_rand(0, strlen($dictionary) - 1)]; } return $prefix.$hash; }
[ "protected", "function", "generateIdentifier", "(", "$", "prefix", ",", "$", "maxLength", ")", "{", "$", "hash", "=", "null", ";", "$", "dictionary", "=", "'abcdefghijklmnopqrstuvwxyz0123456789'", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "(", "$", "maxLength", "-", "strlen", "(", "$", "prefix", ")", ")", ";", "$", "i", "++", ")", "{", "$", "hash", ".=", "$", "dictionary", "[", "mt_rand", "(", "0", ",", "strlen", "(", "$", "dictionary", ")", "-", "1", ")", "]", ";", "}", "return", "$", "prefix", ".", "$", "hash", ";", "}" ]
Generates a prefixed identifier. @param string $prefix The identifier prefix. @param integer $maxLength The identifier max length. @return string The prefixed identifier.
[ "Generates", "a", "prefixed", "identifier", "." ]
d0b8c3551922d696836487aa0eb1bd74014edcd4
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/AbstractAsset.php#L76-L86
train
Wedeto/Auth
src/ACL/ACLModel.php
ACLModel.isAllowed
public function isAllowed($action, $role = null) { if ($this->_acl_entity === null) { return $this->getACL()->getDefaultPolicy(); } if ($role === null) { $role = $this->getACL()->getCurrentRole(); } return $this->_acl_entity->isAllowed($role, $action, array(get_class($this), "loadByACLID")); }
php
public function isAllowed($action, $role = null) { if ($this->_acl_entity === null) { return $this->getACL()->getDefaultPolicy(); } if ($role === null) { $role = $this->getACL()->getCurrentRole(); } return $this->_acl_entity->isAllowed($role, $action, array(get_class($this), "loadByACLID")); }
[ "public", "function", "isAllowed", "(", "$", "action", ",", "$", "role", "=", "null", ")", "{", "if", "(", "$", "this", "->", "_acl_entity", "===", "null", ")", "{", "return", "$", "this", "->", "getACL", "(", ")", "->", "getDefaultPolicy", "(", ")", ";", "}", "if", "(", "$", "role", "===", "null", ")", "{", "$", "role", "=", "$", "this", "->", "getACL", "(", ")", "->", "getCurrentRole", "(", ")", ";", "}", "return", "$", "this", "->", "_acl_entity", "->", "isAllowed", "(", "$", "role", ",", "$", "action", ",", "array", "(", "get_class", "(", "$", "this", ")", ",", "\"loadByACLID\"", ")", ")", ";", "}" ]
Check if an action is allowed on this object. If the ACL subsystem is not loaded, true will be returned. @param $action scalar The action to be performed @param $role Wedeto\ACL\Role The role that wants to perform an action. If not specified, the current user is used. @return boolean True if the action is allowed, false if it is not @throws Wedeto\ACL\Exception When the role or the action is invalid
[ "Check", "if", "an", "action", "is", "allowed", "on", "this", "object", ".", "If", "the", "ACL", "subsystem", "is", "not", "loaded", "true", "will", "be", "returned", "." ]
d53777d860a9e67154b84b425e29da5d4dcd28e0
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/ACL/ACLModel.php#L91-L104
train
Wedeto/Auth
src/ACL/ACLModel.php
ACLModel.getACLClass
public static function getACLClass() { $cl = static::class; $parts = explode("\\", $cl); if (count($parts) === 1) return $parts[0]; $first = reset($parts); $last = end($parts); return $first . "_" . $last; }
php
public static function getACLClass() { $cl = static::class; $parts = explode("\\", $cl); if (count($parts) === 1) return $parts[0]; $first = reset($parts); $last = end($parts); return $first . "_" . $last; }
[ "public", "static", "function", "getACLClass", "(", ")", "{", "$", "cl", "=", "static", "::", "class", ";", "$", "parts", "=", "explode", "(", "\"\\\\\"", ",", "$", "cl", ")", ";", "if", "(", "count", "(", "$", "parts", ")", "===", "1", ")", "return", "$", "parts", "[", "0", "]", ";", "$", "first", "=", "reset", "(", "$", "parts", ")", ";", "$", "last", "=", "end", "(", "$", "parts", ")", ";", "return", "$", "first", ".", "\"_\"", ".", "$", "last", ";", "}" ]
Generate a ACL Class name for the called DAO class. It will be composed of the first part of the namespace and the classname by default, but subclasses may override this to alter this behaviour. It should return a unique name @return string The ACL class name for this DAO
[ "Generate", "a", "ACL", "Class", "name", "for", "the", "called", "DAO", "class", ".", "It", "will", "be", "composed", "of", "the", "first", "part", "of", "the", "namespace", "and", "the", "classname", "by", "default", "but", "subclasses", "may", "override", "this", "to", "alter", "this", "behaviour", ".", "It", "should", "return", "a", "unique", "name" ]
d53777d860a9e67154b84b425e29da5d4dcd28e0
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/ACL/ACLModel.php#L114-L126
train
Wedeto/Auth
src/ACL/ACLModel.php
ACLModel.generateID
public function generateID() { $id = $this->getID(); $fmt_string = "%08s"; if (is_array($id)) $id = implode("-", $id); if (empty($id)) throw new Exception("Cannot generate an ID for an empty object"); $id = substr(sha1($id), 0, 10); $acl_class = $this->getACLClass(); return $acl_class . "#" . $id; }
php
public function generateID() { $id = $this->getID(); $fmt_string = "%08s"; if (is_array($id)) $id = implode("-", $id); if (empty($id)) throw new Exception("Cannot generate an ID for an empty object"); $id = substr(sha1($id), 0, 10); $acl_class = $this->getACLClass(); return $acl_class . "#" . $id; }
[ "public", "function", "generateID", "(", ")", "{", "$", "id", "=", "$", "this", "->", "getID", "(", ")", ";", "$", "fmt_string", "=", "\"%08s\"", ";", "if", "(", "is_array", "(", "$", "id", ")", ")", "$", "id", "=", "implode", "(", "\"-\"", ",", "$", "id", ")", ";", "if", "(", "empty", "(", "$", "id", ")", ")", "throw", "new", "Exception", "(", "\"Cannot generate an ID for an empty object\"", ")", ";", "$", "id", "=", "substr", "(", "sha1", "(", "$", "id", ")", ",", "0", ",", "10", ")", ";", "$", "acl_class", "=", "$", "this", "->", "getACLClass", "(", ")", ";", "return", "$", "acl_class", ".", "\"#\"", ".", "$", "id", ";", "}" ]
Generate a ID based on the provided Model object
[ "Generate", "a", "ID", "based", "on", "the", "provided", "Model", "object" ]
d53777d860a9e67154b84b425e29da5d4dcd28e0
https://github.com/Wedeto/Auth/blob/d53777d860a9e67154b84b425e29da5d4dcd28e0/src/ACL/ACLModel.php#L158-L172
train
translationexchange/tml-php-clientsdk
library/Tr8n/Cache/Generators/Base.php
Base.cacheApplication
function cacheApplication() { $this->log("Downloading application..."); $app = Config::instance()->application->apiClient()->get("application", array("definition" => "true")); $this->cache(Application::cacheKey(), json_encode($app)); $this->log("Application has been cached."); return $app; }
php
function cacheApplication() { $this->log("Downloading application..."); $app = Config::instance()->application->apiClient()->get("application", array("definition" => "true")); $this->cache(Application::cacheKey(), json_encode($app)); $this->log("Application has been cached."); return $app; }
[ "function", "cacheApplication", "(", ")", "{", "$", "this", "->", "log", "(", "\"Downloading application...\"", ")", ";", "$", "app", "=", "Config", "::", "instance", "(", ")", "->", "application", "->", "apiClient", "(", ")", "->", "get", "(", "\"application\"", ",", "array", "(", "\"definition\"", "=>", "\"true\"", ")", ")", ";", "$", "this", "->", "cache", "(", "Application", "::", "cacheKey", "(", ")", ",", "json_encode", "(", "$", "app", ")", ")", ";", "$", "this", "->", "log", "(", "\"Application has been cached.\"", ")", ";", "return", "$", "app", ";", "}" ]
Caches application data
[ "Caches", "application", "data" ]
fe51473824e62cfd883c6aa0c6a3783a16ce8425
https://github.com/translationexchange/tml-php-clientsdk/blob/fe51473824e62cfd883c6aa0c6a3783a16ce8425/library/Tr8n/Cache/Generators/Base.php#L95-L101
train
translationexchange/tml-php-clientsdk
library/Tr8n/Cache/Generators/Base.php
Base.cacheLanguages
function cacheLanguages() { $this->log("Downloading languages..."); $count = 0; $languages = Config::instance()->application->apiClient()->get("application/languages", array("definition" => "true")); foreach ($languages as $lang) { $this->cache(Language::cacheKey($lang["locale"]), json_encode($lang)); $count += 1; } $this->log("$count languages have been cached."); return $languages; }
php
function cacheLanguages() { $this->log("Downloading languages..."); $count = 0; $languages = Config::instance()->application->apiClient()->get("application/languages", array("definition" => "true")); foreach ($languages as $lang) { $this->cache(Language::cacheKey($lang["locale"]), json_encode($lang)); $count += 1; } $this->log("$count languages have been cached."); return $languages; }
[ "function", "cacheLanguages", "(", ")", "{", "$", "this", "->", "log", "(", "\"Downloading languages...\"", ")", ";", "$", "count", "=", "0", ";", "$", "languages", "=", "Config", "::", "instance", "(", ")", "->", "application", "->", "apiClient", "(", ")", "->", "get", "(", "\"application/languages\"", ",", "array", "(", "\"definition\"", "=>", "\"true\"", ")", ")", ";", "foreach", "(", "$", "languages", "as", "$", "lang", ")", "{", "$", "this", "->", "cache", "(", "Language", "::", "cacheKey", "(", "$", "lang", "[", "\"locale\"", "]", ")", ",", "json_encode", "(", "$", "lang", ")", ")", ";", "$", "count", "+=", "1", ";", "}", "$", "this", "->", "log", "(", "\"$count languages have been cached.\"", ")", ";", "return", "$", "languages", ";", "}" ]
Caches application languages with full definition
[ "Caches", "application", "languages", "with", "full", "definition" ]
fe51473824e62cfd883c6aa0c6a3783a16ce8425
https://github.com/translationexchange/tml-php-clientsdk/blob/fe51473824e62cfd883c6aa0c6a3783a16ce8425/library/Tr8n/Cache/Generators/Base.php#L106-L116
train
modulusphp/http
Request/HasInput.php
HasInput.only
public function only(array $array) { $data = []; foreach($array as $field) { if ($this->has($field)) { $data[$field] = $this->data[$field]; } } return $data; }
php
public function only(array $array) { $data = []; foreach($array as $field) { if ($this->has($field)) { $data[$field] = $this->data[$field]; } } return $data; }
[ "public", "function", "only", "(", "array", "$", "array", ")", "{", "$", "data", "=", "[", "]", ";", "foreach", "(", "$", "array", "as", "$", "field", ")", "{", "if", "(", "$", "this", "->", "has", "(", "$", "field", ")", ")", "{", "$", "data", "[", "$", "field", "]", "=", "$", "this", "->", "data", "[", "$", "field", "]", ";", "}", "}", "return", "$", "data", ";", "}" ]
Grab selected fields. @param array $array @return array $data
[ "Grab", "selected", "fields", "." ]
fc5c0f2b582a04de1685578d3fb790686a0a240c
https://github.com/modulusphp/http/blob/fc5c0f2b582a04de1685578d3fb790686a0a240c/Request/HasInput.php#L29-L40
train
modulusphp/http
Request/HasInput.php
HasInput.file
public function file($name, $disk = null) { return File::make($this->files[$name], $disk); }
php
public function file($name, $disk = null) { return File::make($this->files[$name], $disk); }
[ "public", "function", "file", "(", "$", "name", ",", "$", "disk", "=", "null", ")", "{", "return", "File", "::", "make", "(", "$", "this", "->", "files", "[", "$", "name", "]", ",", "$", "disk", ")", ";", "}" ]
Get request file @param string $name @param string|null $disk @return array
[ "Get", "request", "file" ]
fc5c0f2b582a04de1685578d3fb790686a0a240c
https://github.com/modulusphp/http/blob/fc5c0f2b582a04de1685578d3fb790686a0a240c/Request/HasInput.php#L102-L105
train