id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
1,900
glendmaatita/Tolkien
src/Tolkien/GeneratePost.php
GeneratePost.setPostContent
public function setPostContent() { $content = "---\n"; $content .= "type: " . $this->properties['type'] . "\n"; $content .= "layout: " . $this->properties['layout'] . "\n"; $content .= "title: " . $this->properties['title'] . "\n"; $content .= "date: " . Date('Y-m-d') . "\n"; $content .= "dateFormat: 'F d, Y' \n"; // default ex January 08, 2014 $content .= "url: :year/:month/:date/:title \n"; // default, cannot generated from cli $content .= "author: ". $this->properties['author'] ." \n"; $content .= "categories: " . implode(',', $this->properties['categories']) . "\n"; $content .= "featuredImage: " . $this->properties['featuredImage'] . "\n"; $content .= "---\n"; $content .= $this->properties['body']; return $content; }
php
public function setPostContent() { $content = "---\n"; $content .= "type: " . $this->properties['type'] . "\n"; $content .= "layout: " . $this->properties['layout'] . "\n"; $content .= "title: " . $this->properties['title'] . "\n"; $content .= "date: " . Date('Y-m-d') . "\n"; $content .= "dateFormat: 'F d, Y' \n"; // default ex January 08, 2014 $content .= "url: :year/:month/:date/:title \n"; // default, cannot generated from cli $content .= "author: ". $this->properties['author'] ." \n"; $content .= "categories: " . implode(',', $this->properties['categories']) . "\n"; $content .= "featuredImage: " . $this->properties['featuredImage'] . "\n"; $content .= "---\n"; $content .= $this->properties['body']; return $content; }
[ "public", "function", "setPostContent", "(", ")", "{", "$", "content", "=", "\"---\\n\"", ";", "$", "content", ".=", "\"type: \"", ".", "$", "this", "->", "properties", "[", "'type'", "]", ".", "\"\\n\"", ";", "$", "content", ".=", "\"layout: \"", ".", "$", "this", "->", "properties", "[", "'layout'", "]", ".", "\"\\n\"", ";", "$", "content", ".=", "\"title: \"", ".", "$", "this", "->", "properties", "[", "'title'", "]", ".", "\"\\n\"", ";", "$", "content", ".=", "\"date: \"", ".", "Date", "(", "'Y-m-d'", ")", ".", "\"\\n\"", ";", "$", "content", ".=", "\"dateFormat: 'F d, Y' \\n\"", ";", "// default ex January 08, 2014", "$", "content", ".=", "\"url: :year/:month/:date/:title \\n\"", ";", "// default, cannot generated from cli", "$", "content", ".=", "\"author: \"", ".", "$", "this", "->", "properties", "[", "'author'", "]", ".", "\" \\n\"", ";", "$", "content", ".=", "\"categories: \"", ".", "implode", "(", "','", ",", "$", "this", "->", "properties", "[", "'categories'", "]", ")", ".", "\"\\n\"", ";", "$", "content", ".=", "\"featuredImage: \"", ".", "$", "this", "->", "properties", "[", "'featuredImage'", "]", ".", "\"\\n\"", ";", "$", "content", ".=", "\"---\\n\"", ";", "$", "content", ".=", "$", "this", "->", "properties", "[", "'body'", "]", ";", "return", "$", "content", ";", "}" ]
Set post metadata template @return string
[ "Set", "post", "metadata", "template" ]
e7c27a103f1a87411dfb8eef626cba381b27d233
https://github.com/glendmaatita/Tolkien/blob/e7c27a103f1a87411dfb8eef626cba381b27d233/src/Tolkien/GeneratePost.php#L60-L76
1,901
tonjoo/tiga-framework
src/Whoops.php
Whoops.init
public function init() { if (TIGA_DEBUG == true && !$this->app->isConsole()) { $whoops = new \Whoops\Run(); if ($this->app['request']->isJson()) { $whoops->pushHandler(new \Whoops\Handler\JsonResponseHandler()); } else { $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler()); } $whoops->register(); } }
php
public function init() { if (TIGA_DEBUG == true && !$this->app->isConsole()) { $whoops = new \Whoops\Run(); if ($this->app['request']->isJson()) { $whoops->pushHandler(new \Whoops\Handler\JsonResponseHandler()); } else { $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler()); } $whoops->register(); } }
[ "public", "function", "init", "(", ")", "{", "if", "(", "TIGA_DEBUG", "==", "true", "&&", "!", "$", "this", "->", "app", "->", "isConsole", "(", ")", ")", "{", "$", "whoops", "=", "new", "\\", "Whoops", "\\", "Run", "(", ")", ";", "if", "(", "$", "this", "->", "app", "[", "'request'", "]", "->", "isJson", "(", ")", ")", "{", "$", "whoops", "->", "pushHandler", "(", "new", "\\", "Whoops", "\\", "Handler", "\\", "JsonResponseHandler", "(", ")", ")", ";", "}", "else", "{", "$", "whoops", "->", "pushHandler", "(", "new", "\\", "Whoops", "\\", "Handler", "\\", "PrettyPageHandler", "(", ")", ")", ";", "}", "$", "whoops", "->", "register", "(", ")", ";", "}", "}" ]
Init Whoops based on App conditional rule.
[ "Init", "Whoops", "based", "on", "App", "conditional", "rule", "." ]
3c2eebd3bc616106fa1bba3e43f1791aff75eec5
https://github.com/tonjoo/tiga-framework/blob/3c2eebd3bc616106fa1bba3e43f1791aff75eec5/src/Whoops.php#L32-L45
1,902
Opifer/RulesEngine
src/Rule/Condition/RelationCondition.php
RelationCondition.setType
public function setType($type) { $this->type = $type; switch ($type) { case 'text': case 'string': $this->operatorOpts = ['equals', 'notequals', 'contains']; break; case 'integer': $this->operatorOpts = ['equals', 'notequals', 'greaterthan', 'lessthan']; break; case 'boolean': $this->operatorOpts = ['equals']; break; } return $this; }
php
public function setType($type) { $this->type = $type; switch ($type) { case 'text': case 'string': $this->operatorOpts = ['equals', 'notequals', 'contains']; break; case 'integer': $this->operatorOpts = ['equals', 'notequals', 'greaterthan', 'lessthan']; break; case 'boolean': $this->operatorOpts = ['equals']; break; } return $this; }
[ "public", "function", "setType", "(", "$", "type", ")", "{", "$", "this", "->", "type", "=", "$", "type", ";", "switch", "(", "$", "type", ")", "{", "case", "'text'", ":", "case", "'string'", ":", "$", "this", "->", "operatorOpts", "=", "[", "'equals'", ",", "'notequals'", ",", "'contains'", "]", ";", "break", ";", "case", "'integer'", ":", "$", "this", "->", "operatorOpts", "=", "[", "'equals'", ",", "'notequals'", ",", "'greaterthan'", ",", "'lessthan'", "]", ";", "break", ";", "case", "'boolean'", ":", "$", "this", "->", "operatorOpts", "=", "[", "'equals'", "]", ";", "break", ";", "}", "return", "$", "this", ";", "}" ]
Set the type and predefine the operatorOpts by type
[ "Set", "the", "type", "and", "predefine", "the", "operatorOpts", "by", "type" ]
d25c447ae6eaed9e9e6b6b21a3e612786159a5f8
https://github.com/Opifer/RulesEngine/blob/d25c447ae6eaed9e9e6b6b21a3e612786159a5f8/src/Rule/Condition/RelationCondition.php#L84-L102
1,903
coolms/common
src/Form/Form.php
Form.addCaptchaElement
protected function addCaptchaElement() { if (!$this->getCaptchaOptions() || $this->has('captcha')) { return; } $spec = array_replace_recursive($this->captchaElementSpec, [ 'name' => $this->getCaptchaElementName(), 'options' => [ 'captcha' => $this->getCaptchaOptions(), ], ]); $this->add($spec, ['priority' => -970]); }
php
protected function addCaptchaElement() { if (!$this->getCaptchaOptions() || $this->has('captcha')) { return; } $spec = array_replace_recursive($this->captchaElementSpec, [ 'name' => $this->getCaptchaElementName(), 'options' => [ 'captcha' => $this->getCaptchaOptions(), ], ]); $this->add($spec, ['priority' => -970]); }
[ "protected", "function", "addCaptchaElement", "(", ")", "{", "if", "(", "!", "$", "this", "->", "getCaptchaOptions", "(", ")", "||", "$", "this", "->", "has", "(", "'captcha'", ")", ")", "{", "return", ";", "}", "$", "spec", "=", "array_replace_recursive", "(", "$", "this", "->", "captchaElementSpec", ",", "[", "'name'", "=>", "$", "this", "->", "getCaptchaElementName", "(", ")", ",", "'options'", "=>", "[", "'captcha'", "=>", "$", "this", "->", "getCaptchaOptions", "(", ")", ",", "]", ",", "]", ")", ";", "$", "this", "->", "add", "(", "$", "spec", ",", "[", "'priority'", "=>", "-", "970", "]", ")", ";", "}" ]
Setup CAPTCHA protection
[ "Setup", "CAPTCHA", "protection" ]
3572993cdcdb2898cdde396a2f1de9864b193660
https://github.com/coolms/common/blob/3572993cdcdb2898cdde396a2f1de9864b193660/src/Form/Form.php#L1062-L1076
1,904
coolms/common
src/Form/Form.php
Form.addCsrfElement
protected function addCsrfElement() { if ($this->has('csrf')) { return; } $spec = array_replace_recursive($this->csrfElementSpec, [ 'name' => $this->getCsrfElementName(), 'options' => [ 'csrf_options' => [ 'timeout' => $this->getFormTimeout(), ], ], ]); $this->add($spec, ['priority' => -980]); }
php
protected function addCsrfElement() { if ($this->has('csrf')) { return; } $spec = array_replace_recursive($this->csrfElementSpec, [ 'name' => $this->getCsrfElementName(), 'options' => [ 'csrf_options' => [ 'timeout' => $this->getFormTimeout(), ], ], ]); $this->add($spec, ['priority' => -980]); }
[ "protected", "function", "addCsrfElement", "(", ")", "{", "if", "(", "$", "this", "->", "has", "(", "'csrf'", ")", ")", "{", "return", ";", "}", "$", "spec", "=", "array_replace_recursive", "(", "$", "this", "->", "csrfElementSpec", ",", "[", "'name'", "=>", "$", "this", "->", "getCsrfElementName", "(", ")", ",", "'options'", "=>", "[", "'csrf_options'", "=>", "[", "'timeout'", "=>", "$", "this", "->", "getFormTimeout", "(", ")", ",", "]", ",", "]", ",", "]", ")", ";", "$", "this", "->", "add", "(", "$", "spec", ",", "[", "'priority'", "=>", "-", "980", "]", ")", ";", "}" ]
Setup CSRF protection
[ "Setup", "CSRF", "protection" ]
3572993cdcdb2898cdde396a2f1de9864b193660
https://github.com/coolms/common/blob/3572993cdcdb2898cdde396a2f1de9864b193660/src/Form/Form.php#L1169-L1185
1,905
jannisfink/yarf
src/response/PageResolver.php
PageResolver.evaluateWebPage
public function evaluateWebPage() { try { $renderer = new PageRenderer($this->webPage, $this->uriVariables); $this->response = $renderer->evaluatePage(); $this->rawRequestBody = $this->response->getResult(); } catch (WebException $e) { // FIXME this is ugly $this->thrownWebException = $e; $this->rawRequestBody = $this->createRequestBodyFromException(); } finally { $this->evaluated = true; } }
php
public function evaluateWebPage() { try { $renderer = new PageRenderer($this->webPage, $this->uriVariables); $this->response = $renderer->evaluatePage(); $this->rawRequestBody = $this->response->getResult(); } catch (WebException $e) { // FIXME this is ugly $this->thrownWebException = $e; $this->rawRequestBody = $this->createRequestBodyFromException(); } finally { $this->evaluated = true; } }
[ "public", "function", "evaluateWebPage", "(", ")", "{", "try", "{", "$", "renderer", "=", "new", "PageRenderer", "(", "$", "this", "->", "webPage", ",", "$", "this", "->", "uriVariables", ")", ";", "$", "this", "->", "response", "=", "$", "renderer", "->", "evaluatePage", "(", ")", ";", "$", "this", "->", "rawRequestBody", "=", "$", "this", "->", "response", "->", "getResult", "(", ")", ";", "}", "catch", "(", "WebException", "$", "e", ")", "{", "// FIXME this is ugly", "$", "this", "->", "thrownWebException", "=", "$", "e", ";", "$", "this", "->", "rawRequestBody", "=", "$", "this", "->", "createRequestBodyFromException", "(", ")", ";", "}", "finally", "{", "$", "this", "->", "evaluated", "=", "true", ";", "}", "}" ]
Evaluates the given webpage and handles any occuring error
[ "Evaluates", "the", "given", "webpage", "and", "handles", "any", "occuring", "error" ]
91237dc0f3b724abaaba490f5171f181a92e939f
https://github.com/jannisfink/yarf/blob/91237dc0f3b724abaaba490f5171f181a92e939f/src/response/PageResolver.php#L85-L97
1,906
jannisfink/yarf
src/response/PageResolver.php
PageResolver.createHeader
public function createHeader() { if ($this->router->isTestRun()) { return; } http_response_code($this->getStatusCode()); if ($this->response === null) { // exception was raised // FIXME ensure that a response is always given initialized with at least the content type header header(Header::CONTENT_TYPE . ":" . $this->getContentType()); } else { foreach ($this->response->getHeaders() as $header => $value) { header($header . ":" . $value); } } }
php
public function createHeader() { if ($this->router->isTestRun()) { return; } http_response_code($this->getStatusCode()); if ($this->response === null) { // exception was raised // FIXME ensure that a response is always given initialized with at least the content type header header(Header::CONTENT_TYPE . ":" . $this->getContentType()); } else { foreach ($this->response->getHeaders() as $header => $value) { header($header . ":" . $value); } } }
[ "public", "function", "createHeader", "(", ")", "{", "if", "(", "$", "this", "->", "router", "->", "isTestRun", "(", ")", ")", "{", "return", ";", "}", "http_response_code", "(", "$", "this", "->", "getStatusCode", "(", ")", ")", ";", "if", "(", "$", "this", "->", "response", "===", "null", ")", "{", "// exception was raised", "// FIXME ensure that a response is always given initialized with at least the content type header", "header", "(", "Header", "::", "CONTENT_TYPE", ".", "\":\"", ".", "$", "this", "->", "getContentType", "(", ")", ")", ";", "}", "else", "{", "foreach", "(", "$", "this", "->", "response", "->", "getHeaders", "(", ")", "as", "$", "header", "=>", "$", "value", ")", "{", "header", "(", "$", "header", ".", "\":\"", ".", "$", "value", ")", ";", "}", "}", "}" ]
Method to set all necessary fields for the response header, such as the content type or the status code. This function will do nothing if this is a test run
[ "Method", "to", "set", "all", "necessary", "fields", "for", "the", "response", "header", "such", "as", "the", "content", "type", "or", "the", "status", "code", "." ]
91237dc0f3b724abaaba490f5171f181a92e939f
https://github.com/jannisfink/yarf/blob/91237dc0f3b724abaaba490f5171f181a92e939f/src/response/PageResolver.php#L125-L140
1,907
jannisfink/yarf
src/response/PageResolver.php
PageResolver.getRequestBody
public function getRequestBody() { if (!$this->evaluated) { $this->evaluateWebPage(); } if ($this->webPage instanceof JsonPage) { $serializer = $this->router->getJsonSerializer(); return $serializer->serialize($this->rawRequestBody); } else { return $this->rawRequestBody; } }
php
public function getRequestBody() { if (!$this->evaluated) { $this->evaluateWebPage(); } if ($this->webPage instanceof JsonPage) { $serializer = $this->router->getJsonSerializer(); return $serializer->serialize($this->rawRequestBody); } else { return $this->rawRequestBody; } }
[ "public", "function", "getRequestBody", "(", ")", "{", "if", "(", "!", "$", "this", "->", "evaluated", ")", "{", "$", "this", "->", "evaluateWebPage", "(", ")", ";", "}", "if", "(", "$", "this", "->", "webPage", "instanceof", "JsonPage", ")", "{", "$", "serializer", "=", "$", "this", "->", "router", "->", "getJsonSerializer", "(", ")", ";", "return", "$", "serializer", "->", "serialize", "(", "$", "this", "->", "rawRequestBody", ")", ";", "}", "else", "{", "return", "$", "this", "->", "rawRequestBody", ";", "}", "}" ]
Method to get the request body from the given web page. @return string the evaluated request body
[ "Method", "to", "get", "the", "request", "body", "from", "the", "given", "web", "page", "." ]
91237dc0f3b724abaaba490f5171f181a92e939f
https://github.com/jannisfink/yarf/blob/91237dc0f3b724abaaba490f5171f181a92e939f/src/response/PageResolver.php#L170-L181
1,908
cityware/city-wmi
src/Models/Variants/Processor.php
Processor.getArchitecture
public function getArchitecture() { $int = $this->variant->architecture(); $possible = [ 0 => 'x86', 1 => 'MIPS', 2 => 'Alpha', 3 => 'PowerPC', 6 => 'ia64', 9 => 'x64', ]; return $this->getFromPossibleValues($int, $possible); }
php
public function getArchitecture() { $int = $this->variant->architecture(); $possible = [ 0 => 'x86', 1 => 'MIPS', 2 => 'Alpha', 3 => 'PowerPC', 6 => 'ia64', 9 => 'x64', ]; return $this->getFromPossibleValues($int, $possible); }
[ "public", "function", "getArchitecture", "(", ")", "{", "$", "int", "=", "$", "this", "->", "variant", "->", "architecture", "(", ")", ";", "$", "possible", "=", "[", "0", "=>", "'x86'", ",", "1", "=>", "'MIPS'", ",", "2", "=>", "'Alpha'", ",", "3", "=>", "'PowerPC'", ",", "6", "=>", "'ia64'", ",", "9", "=>", "'x64'", ",", "]", ";", "return", "$", "this", "->", "getFromPossibleValues", "(", "$", "int", ",", "$", "possible", ")", ";", "}" ]
Returns the processor architecture. @return null|string
[ "Returns", "the", "processor", "architecture", "." ]
c7296e6855b6719f537ff5c2dc19d521ce1415d8
https://github.com/cityware/city-wmi/blob/c7296e6855b6719f537ff5c2dc19d521ce1415d8/src/Models/Variants/Processor.php#L22-L36
1,909
cityware/city-wmi
src/Models/Variants/Processor.php
Processor.getProcessorType
public function getProcessorType() { $int = $this->variant->processorType(); $possible = [ 1 => 'Other', 2 => 'Unknown', 3 => 'Central Processor', 4 => 'Math Processor', 5 => 'DSP Processor', 6 => 'Video Processor', ]; return $this->getFromPossibleValues($int, $possible); }
php
public function getProcessorType() { $int = $this->variant->processorType(); $possible = [ 1 => 'Other', 2 => 'Unknown', 3 => 'Central Processor', 4 => 'Math Processor', 5 => 'DSP Processor', 6 => 'Video Processor', ]; return $this->getFromPossibleValues($int, $possible); }
[ "public", "function", "getProcessorType", "(", ")", "{", "$", "int", "=", "$", "this", "->", "variant", "->", "processorType", "(", ")", ";", "$", "possible", "=", "[", "1", "=>", "'Other'", ",", "2", "=>", "'Unknown'", ",", "3", "=>", "'Central Processor'", ",", "4", "=>", "'Math Processor'", ",", "5", "=>", "'DSP Processor'", ",", "6", "=>", "'Video Processor'", ",", "]", ";", "return", "$", "this", "->", "getFromPossibleValues", "(", "$", "int", ",", "$", "possible", ")", ";", "}" ]
The ProcessorType property specifies the processor's primary function. @return mixed
[ "The", "ProcessorType", "property", "specifies", "the", "processor", "s", "primary", "function", "." ]
c7296e6855b6719f537ff5c2dc19d521ce1415d8
https://github.com/cityware/city-wmi/blob/c7296e6855b6719f537ff5c2dc19d521ce1415d8/src/Models/Variants/Processor.php#L140-L154
1,910
pavex/publixe-website
src/Website/Control.php
Control.action
private function action(ActionHandler $handler) { try { $presenter = $this -> presenterFactory -> createPresenter($handler -> presenter, $handler -> args); } catch (\Exception $e) { throw new InternalServerErrorException($e -> getMessage()); } // Call action/execute if (!method_exists($presenter, $handler -> action)) { throw new BadFunctionCallException(sprintf("Can not call `%s`.", $handler -> action)); } $presenter -> startup(); call_user_func_array([$presenter, $handler -> action], []); // $response = $this -> httpResponse; if (!$response -> isRedirect() && empty($response -> contents)) { $response -> contents = $presenter -> render(); } unset($presenter); }
php
private function action(ActionHandler $handler) { try { $presenter = $this -> presenterFactory -> createPresenter($handler -> presenter, $handler -> args); } catch (\Exception $e) { throw new InternalServerErrorException($e -> getMessage()); } // Call action/execute if (!method_exists($presenter, $handler -> action)) { throw new BadFunctionCallException(sprintf("Can not call `%s`.", $handler -> action)); } $presenter -> startup(); call_user_func_array([$presenter, $handler -> action], []); // $response = $this -> httpResponse; if (!$response -> isRedirect() && empty($response -> contents)) { $response -> contents = $presenter -> render(); } unset($presenter); }
[ "private", "function", "action", "(", "ActionHandler", "$", "handler", ")", "{", "try", "{", "$", "presenter", "=", "$", "this", "->", "presenterFactory", "->", "createPresenter", "(", "$", "handler", "->", "presenter", ",", "$", "handler", "->", "args", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "InternalServerErrorException", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "// Call action/execute", "if", "(", "!", "method_exists", "(", "$", "presenter", ",", "$", "handler", "->", "action", ")", ")", "{", "throw", "new", "BadFunctionCallException", "(", "sprintf", "(", "\"Can not call `%s`.\"", ",", "$", "handler", "->", "action", ")", ")", ";", "}", "$", "presenter", "->", "startup", "(", ")", ";", "call_user_func_array", "(", "[", "$", "presenter", ",", "$", "handler", "->", "action", "]", ",", "[", "]", ")", ";", "//", "$", "response", "=", "$", "this", "->", "httpResponse", ";", "if", "(", "!", "$", "response", "->", "isRedirect", "(", ")", "&&", "empty", "(", "$", "response", "->", "contents", ")", ")", "{", "$", "response", "->", "contents", "=", "$", "presenter", "->", "render", "(", ")", ";", "}", "unset", "(", "$", "presenter", ")", ";", "}" ]
Process website presenter life-cycle @param Publixe\Website\ActionHandler
[ "Process", "website", "presenter", "life", "-", "cycle" ]
1b7205306698e52fbfd887d54fd2e1e1d93391e9
https://github.com/pavex/publixe-website/blob/1b7205306698e52fbfd887d54fd2e1e1d93391e9/src/Website/Control.php#L94-L116
1,911
SymBB/symbb
src/Symbb/Core/SystemBundle/Api/AbstractCrudApi.php
AbstractCrudApi.save
public function save($object) { if (is_array($object)) { $objectData = $object; if ($object['id'] > 0) { $object = $this->find($object['id']); } else { $object = $this->createNewObject(); } $this->assignArrayToObject($object, $objectData); } else if (!$this->isCorrectInstance($object)) { $this->addErrorMessage(self::ERROR_WRONG_OBJECT); } if (!$this->hasError()) { $check = $this->manager->save($object); if ($check) { $this->addSuccessMessage(self::SUCCESS_SAVED); } } return $object; }
php
public function save($object) { if (is_array($object)) { $objectData = $object; if ($object['id'] > 0) { $object = $this->find($object['id']); } else { $object = $this->createNewObject(); } $this->assignArrayToObject($object, $objectData); } else if (!$this->isCorrectInstance($object)) { $this->addErrorMessage(self::ERROR_WRONG_OBJECT); } if (!$this->hasError()) { $check = $this->manager->save($object); if ($check) { $this->addSuccessMessage(self::SUCCESS_SAVED); } } return $object; }
[ "public", "function", "save", "(", "$", "object", ")", "{", "if", "(", "is_array", "(", "$", "object", ")", ")", "{", "$", "objectData", "=", "$", "object", ";", "if", "(", "$", "object", "[", "'id'", "]", ">", "0", ")", "{", "$", "object", "=", "$", "this", "->", "find", "(", "$", "object", "[", "'id'", "]", ")", ";", "}", "else", "{", "$", "object", "=", "$", "this", "->", "createNewObject", "(", ")", ";", "}", "$", "this", "->", "assignArrayToObject", "(", "$", "object", ",", "$", "objectData", ")", ";", "}", "else", "if", "(", "!", "$", "this", "->", "isCorrectInstance", "(", "$", "object", ")", ")", "{", "$", "this", "->", "addErrorMessage", "(", "self", "::", "ERROR_WRONG_OBJECT", ")", ";", "}", "if", "(", "!", "$", "this", "->", "hasError", "(", ")", ")", "{", "$", "check", "=", "$", "this", "->", "manager", "->", "save", "(", "$", "object", ")", ";", "if", "(", "$", "check", ")", "{", "$", "this", "->", "addSuccessMessage", "(", "self", "::", "SUCCESS_SAVED", ")", ";", "}", "}", "return", "$", "object", ";", "}" ]
save a object you can pass the Site object or an array with the fields if you pass an array the keys must be with underscore and not with CamelCase @param object|array $object @return object
[ "save", "a", "object", "you", "can", "pass", "the", "Site", "object", "or", "an", "array", "with", "the", "fields", "if", "you", "pass", "an", "array", "the", "keys", "must", "be", "with", "underscore", "and", "not", "with", "CamelCase" ]
be25357502e6a51016fa0b128a46c2dc87fa8fb2
https://github.com/SymBB/symbb/blob/be25357502e6a51016fa0b128a46c2dc87fa8fb2/src/Symbb/Core/SystemBundle/Api/AbstractCrudApi.php#L58-L81
1,912
tonjoo/tiga-framework
src/Html/FlashFormOldInput.php
FlashFormOldInput.getOldInput
public function getOldInput($key) { $this->input = $this->request->hasOldInput() !== false ? $this->request->oldInput() : array(); // Input that is flashed to the flash can be easily retrieved by the // developer, making repopulating old forms and the like much more // convenient, since the request's previous input is available. return array_get($this->input, $this->transformKey($key), null); }
php
public function getOldInput($key) { $this->input = $this->request->hasOldInput() !== false ? $this->request->oldInput() : array(); // Input that is flashed to the flash can be easily retrieved by the // developer, making repopulating old forms and the like much more // convenient, since the request's previous input is available. return array_get($this->input, $this->transformKey($key), null); }
[ "public", "function", "getOldInput", "(", "$", "key", ")", "{", "$", "this", "->", "input", "=", "$", "this", "->", "request", "->", "hasOldInput", "(", ")", "!==", "false", "?", "$", "this", "->", "request", "->", "oldInput", "(", ")", ":", "array", "(", ")", ";", "// Input that is flashed to the flash can be easily retrieved by the", "// developer, making repopulating old forms and the like much more", "// convenient, since the request's previous input is available.", "return", "array_get", "(", "$", "this", "->", "input", ",", "$", "this", "->", "transformKey", "(", "$", "key", ")", ",", "null", ")", ";", "}" ]
Get old input by key. @param string $key @return mixed
[ "Get", "old", "input", "by", "key", "." ]
3c2eebd3bc616106fa1bba3e43f1791aff75eec5
https://github.com/tonjoo/tiga-framework/blob/3c2eebd3bc616106fa1bba3e43f1791aff75eec5/src/Html/FlashFormOldInput.php#L53-L61
1,913
scholtz/AsyncWeb
src/AsyncWeb/View/MakeForm.php
MakeForm.filters
private function filters($value, $type = null, $safe = true) { if ($type == "date") { $ret = $this->convertDate($value, false); return $ret; } if ($type == "datetime-local") { return $ret = strtotime($value); } if ($type == "date_string") { return date("Y-m-d", \AsyncWeb\Date\Time::getUnix($this->convertDate($value, false))); } if ($type == "number") { $value = str_replace(" ", "", $value); $value = str_replace(",", ".", $value); } if (!$safe) { if (($val = $this->execute($value)) !== false) { return $val; } } return $value; }
php
private function filters($value, $type = null, $safe = true) { if ($type == "date") { $ret = $this->convertDate($value, false); return $ret; } if ($type == "datetime-local") { return $ret = strtotime($value); } if ($type == "date_string") { return date("Y-m-d", \AsyncWeb\Date\Time::getUnix($this->convertDate($value, false))); } if ($type == "number") { $value = str_replace(" ", "", $value); $value = str_replace(",", ".", $value); } if (!$safe) { if (($val = $this->execute($value)) !== false) { return $val; } } return $value; }
[ "private", "function", "filters", "(", "$", "value", ",", "$", "type", "=", "null", ",", "$", "safe", "=", "true", ")", "{", "if", "(", "$", "type", "==", "\"date\"", ")", "{", "$", "ret", "=", "$", "this", "->", "convertDate", "(", "$", "value", ",", "false", ")", ";", "return", "$", "ret", ";", "}", "if", "(", "$", "type", "==", "\"datetime-local\"", ")", "{", "return", "$", "ret", "=", "strtotime", "(", "$", "value", ")", ";", "}", "if", "(", "$", "type", "==", "\"date_string\"", ")", "{", "return", "date", "(", "\"Y-m-d\"", ",", "\\", "AsyncWeb", "\\", "Date", "\\", "Time", "::", "getUnix", "(", "$", "this", "->", "convertDate", "(", "$", "value", ",", "false", ")", ")", ")", ";", "}", "if", "(", "$", "type", "==", "\"number\"", ")", "{", "$", "value", "=", "str_replace", "(", "\" \"", ",", "\"\"", ",", "$", "value", ")", ";", "$", "value", "=", "str_replace", "(", "\",\"", ",", "\".\"", ",", "$", "value", ")", ";", "}", "if", "(", "!", "$", "safe", ")", "{", "if", "(", "(", "$", "val", "=", "$", "this", "->", "execute", "(", "$", "value", ")", ")", "!==", "false", ")", "{", "return", "$", "val", ";", "}", "}", "return", "$", "value", ";", "}" ]
This function makes the input filters and parses php also cleans the number format from spaces and replaces , to . $value = PHP::Time::get(), returns timestamp type = date | date_string | number
[ "This", "function", "makes", "the", "input", "filters", "and", "parses", "php", "also", "cleans", "the", "number", "format", "from", "spaces", "and", "replaces", "to", "." ]
66a906298080c2c66d8f0fb85211b6100b3776bf
https://github.com/scholtz/AsyncWeb/blob/66a906298080c2c66d8f0fb85211b6100b3776bf/src/AsyncWeb/View/MakeForm.php#L583-L604
1,914
scholtz/AsyncWeb
src/AsyncWeb/View/MakeForm.php
MakeForm.show
public function show($what = "ALL", $show_results = true) { // $what == INSERT || UPDATE1 || UPDATE2 || DELETE || ALL $ret = ""; if ($show_results) $ret.= $this->show_results(); if (@$this->data["expectRight"]) if (!Group::is_in_group($this->data["expectRight"])) return; if ($this->insertingN2N) { $what = "INSERT"; } switch ($what) { case "INSERT": $ret.= $this->insertForm(); break; case "UPDATE1": $ret.= $this->update1Form(); break; case "UPDATE2": $ret.= $this->update2Form(); break; case "DELETE": $ret.= $this->deleteForm(); break; case "ONLY_INSERT": $ret.= $this->makeCoverFront(); $ret.= $this->show("INSERT"); $ret.= $this->makeCoverBack(); break; case "ONLY_UPDATE": $ret.= $this->makeCoverFront(); $ret.= $this->show("UPDATE2"); $ret.= $this->makeCoverBack(); break; case "ALL_UPDATE_FIRST": $formName = $this->data["uid"]; $ret.= $this->makeCoverFront(); if ( // ak bol odoslany formular na zobrazenie update2 URLParser::v($formName . "___UPDATE1") || // ak bol odoslany update2, a nastala chyba URLParser::v($formName . "___UPDATE2")) { $ret.= $this->show("UPDATE2"); } else { $ret.= $this->show("UPDATE1"); $ret.= $this->show("INSERT"); $ret.= $this->show("DELETE"); /**/ } $ret.= $this->makeCoverBack(); break; case "ALL": if ( // ak bol odoslany formular na zobrazenie update2 @URLParser::v($formName . "___UPDATE1") || // ak bol odoslany update2, a nastala chyba @URLParser::v($formName . "___UPDATE2")) { $ret.= $this->show("UPDATE2"); } else { return $ret . \AsyncWeb\View\MakeDBView::make($this->data, $this); } /* $formName = $this->data["uid"]; $ret = $this->makeCoverFront(); $ret .= $this->show("INSERT"); $ret .= $this->show("UPDATE1"); $ret .= $this->show("DELETE");/** } $ret .= $this->makeCoverBack();/**/ break; } return $ret; }
php
public function show($what = "ALL", $show_results = true) { // $what == INSERT || UPDATE1 || UPDATE2 || DELETE || ALL $ret = ""; if ($show_results) $ret.= $this->show_results(); if (@$this->data["expectRight"]) if (!Group::is_in_group($this->data["expectRight"])) return; if ($this->insertingN2N) { $what = "INSERT"; } switch ($what) { case "INSERT": $ret.= $this->insertForm(); break; case "UPDATE1": $ret.= $this->update1Form(); break; case "UPDATE2": $ret.= $this->update2Form(); break; case "DELETE": $ret.= $this->deleteForm(); break; case "ONLY_INSERT": $ret.= $this->makeCoverFront(); $ret.= $this->show("INSERT"); $ret.= $this->makeCoverBack(); break; case "ONLY_UPDATE": $ret.= $this->makeCoverFront(); $ret.= $this->show("UPDATE2"); $ret.= $this->makeCoverBack(); break; case "ALL_UPDATE_FIRST": $formName = $this->data["uid"]; $ret.= $this->makeCoverFront(); if ( // ak bol odoslany formular na zobrazenie update2 URLParser::v($formName . "___UPDATE1") || // ak bol odoslany update2, a nastala chyba URLParser::v($formName . "___UPDATE2")) { $ret.= $this->show("UPDATE2"); } else { $ret.= $this->show("UPDATE1"); $ret.= $this->show("INSERT"); $ret.= $this->show("DELETE"); /**/ } $ret.= $this->makeCoverBack(); break; case "ALL": if ( // ak bol odoslany formular na zobrazenie update2 @URLParser::v($formName . "___UPDATE1") || // ak bol odoslany update2, a nastala chyba @URLParser::v($formName . "___UPDATE2")) { $ret.= $this->show("UPDATE2"); } else { return $ret . \AsyncWeb\View\MakeDBView::make($this->data, $this); } /* $formName = $this->data["uid"]; $ret = $this->makeCoverFront(); $ret .= $this->show("INSERT"); $ret .= $this->show("UPDATE1"); $ret .= $this->show("DELETE");/** } $ret .= $this->makeCoverBack();/**/ break; } return $ret; }
[ "public", "function", "show", "(", "$", "what", "=", "\"ALL\"", ",", "$", "show_results", "=", "true", ")", "{", "// $what == INSERT || UPDATE1 || UPDATE2 || DELETE || ALL\r", "$", "ret", "=", "\"\"", ";", "if", "(", "$", "show_results", ")", "$", "ret", ".=", "$", "this", "->", "show_results", "(", ")", ";", "if", "(", "@", "$", "this", "->", "data", "[", "\"expectRight\"", "]", ")", "if", "(", "!", "Group", "::", "is_in_group", "(", "$", "this", "->", "data", "[", "\"expectRight\"", "]", ")", ")", "return", ";", "if", "(", "$", "this", "->", "insertingN2N", ")", "{", "$", "what", "=", "\"INSERT\"", ";", "}", "switch", "(", "$", "what", ")", "{", "case", "\"INSERT\"", ":", "$", "ret", ".=", "$", "this", "->", "insertForm", "(", ")", ";", "break", ";", "case", "\"UPDATE1\"", ":", "$", "ret", ".=", "$", "this", "->", "update1Form", "(", ")", ";", "break", ";", "case", "\"UPDATE2\"", ":", "$", "ret", ".=", "$", "this", "->", "update2Form", "(", ")", ";", "break", ";", "case", "\"DELETE\"", ":", "$", "ret", ".=", "$", "this", "->", "deleteForm", "(", ")", ";", "break", ";", "case", "\"ONLY_INSERT\"", ":", "$", "ret", ".=", "$", "this", "->", "makeCoverFront", "(", ")", ";", "$", "ret", ".=", "$", "this", "->", "show", "(", "\"INSERT\"", ")", ";", "$", "ret", ".=", "$", "this", "->", "makeCoverBack", "(", ")", ";", "break", ";", "case", "\"ONLY_UPDATE\"", ":", "$", "ret", ".=", "$", "this", "->", "makeCoverFront", "(", ")", ";", "$", "ret", ".=", "$", "this", "->", "show", "(", "\"UPDATE2\"", ")", ";", "$", "ret", ".=", "$", "this", "->", "makeCoverBack", "(", ")", ";", "break", ";", "case", "\"ALL_UPDATE_FIRST\"", ":", "$", "formName", "=", "$", "this", "->", "data", "[", "\"uid\"", "]", ";", "$", "ret", ".=", "$", "this", "->", "makeCoverFront", "(", ")", ";", "if", "(", "// ak bol odoslany formular na zobrazenie update2\r", "URLParser", "::", "v", "(", "$", "formName", ".", "\"___UPDATE1\"", ")", "||", "// ak bol odoslany update2, a nastala chyba\r", "URLParser", "::", "v", "(", "$", "formName", ".", "\"___UPDATE2\"", ")", ")", "{", "$", "ret", ".=", "$", "this", "->", "show", "(", "\"UPDATE2\"", ")", ";", "}", "else", "{", "$", "ret", ".=", "$", "this", "->", "show", "(", "\"UPDATE1\"", ")", ";", "$", "ret", ".=", "$", "this", "->", "show", "(", "\"INSERT\"", ")", ";", "$", "ret", ".=", "$", "this", "->", "show", "(", "\"DELETE\"", ")", ";", "/**/", "}", "$", "ret", ".=", "$", "this", "->", "makeCoverBack", "(", ")", ";", "break", ";", "case", "\"ALL\"", ":", "if", "(", "// ak bol odoslany formular na zobrazenie update2\r", "@", "URLParser", "::", "v", "(", "$", "formName", ".", "\"___UPDATE1\"", ")", "||", "// ak bol odoslany update2, a nastala chyba\r", "@", "URLParser", "::", "v", "(", "$", "formName", ".", "\"___UPDATE2\"", ")", ")", "{", "$", "ret", ".=", "$", "this", "->", "show", "(", "\"UPDATE2\"", ")", ";", "}", "else", "{", "return", "$", "ret", ".", "\\", "AsyncWeb", "\\", "View", "\\", "MakeDBView", "::", "make", "(", "$", "this", "->", "data", ",", "$", "this", ")", ";", "}", "/* $formName = $this->data[\"uid\"];\r\n $ret = $this->makeCoverFront();\r\n \r\n $ret .= $this->show(\"INSERT\");\r\n $ret .= $this->show(\"UPDATE1\");\r\n $ret .= $this->show(\"DELETE\");/**\r\n }\r\n $ret .= $this->makeCoverBack();/**/", "break", ";", "}", "return", "$", "ret", ";", "}" ]
Tato funkcia zobrazi formular parametre .. ALL .. zobrazi vsetky insert, update, a delete formulare INSERT .. zobrazi iba formular na vkladanie ONLY_INSERT .. zobrazi iba formular na vkladanie s obalom UPDATE1 .. zobrazi iba formular na upravovanie UPDATE2 .. zobrazi iba formular na upravovanie, ale musi byt vybrany riadok DELETE .. zobrazi iba formular na mazanie
[ "Tato", "funkcia", "zobrazi", "formular", "parametre", "..", "ALL", "..", "zobrazi", "vsetky", "insert", "update", "a", "delete", "formulare", "INSERT", "..", "zobrazi", "iba", "formular", "na", "vkladanie", "ONLY_INSERT", "..", "zobrazi", "iba", "formular", "na", "vkladanie", "s", "obalom", "UPDATE1", "..", "zobrazi", "iba", "formular", "na", "upravovanie", "UPDATE2", "..", "zobrazi", "iba", "formular", "na", "upravovanie", "ale", "musi", "byt", "vybrany", "riadok", "DELETE", "..", "zobrazi", "iba", "formular", "na", "mazanie" ]
66a906298080c2c66d8f0fb85211b6100b3776bf
https://github.com/scholtz/AsyncWeb/blob/66a906298080c2c66d8f0fb85211b6100b3776bf/src/AsyncWeb/View/MakeForm.php#L1089-L1158
1,915
coolms/common
src/Listener/RouterCacheListener.php
RouterCacheListener.routeSave
public function routeSave(MvcEvent $event) { $match = $event->getRouteMatch(); if (!$match || !$event->getRequest() instanceof HttpRequest) { return; } if ($event->getParam('route-cached') || !$event->getParam('route-cacheable')) { return; } $path = $event->getRequest()->getUri()->getPath(); // save the route match into the cache. $services = $event->getApplication()->getServiceManager(); $cacheName = $services->get(RouterCacheOptions::class)->getCache(); $cache = $services->get($cacheName); $cacheKey = $this->getCacheKey($path); $name = $match->getMatchedRouteName(); $data = [ 'name' => $name, 'spec' => [ 'type' => 'Literal', 'options' => [ 'route' => $path, 'defaults' => $match->getParams(), ], ], ]; $routes = $services->get('Config')['router']['routes']; if (isset($routes[$name])) { $data['spec'] = array_replace_recursive($routes[$name], $data['spec']); } $cache->setItem($cacheKey, $data); }
php
public function routeSave(MvcEvent $event) { $match = $event->getRouteMatch(); if (!$match || !$event->getRequest() instanceof HttpRequest) { return; } if ($event->getParam('route-cached') || !$event->getParam('route-cacheable')) { return; } $path = $event->getRequest()->getUri()->getPath(); // save the route match into the cache. $services = $event->getApplication()->getServiceManager(); $cacheName = $services->get(RouterCacheOptions::class)->getCache(); $cache = $services->get($cacheName); $cacheKey = $this->getCacheKey($path); $name = $match->getMatchedRouteName(); $data = [ 'name' => $name, 'spec' => [ 'type' => 'Literal', 'options' => [ 'route' => $path, 'defaults' => $match->getParams(), ], ], ]; $routes = $services->get('Config')['router']['routes']; if (isset($routes[$name])) { $data['spec'] = array_replace_recursive($routes[$name], $data['spec']); } $cache->setItem($cacheKey, $data); }
[ "public", "function", "routeSave", "(", "MvcEvent", "$", "event", ")", "{", "$", "match", "=", "$", "event", "->", "getRouteMatch", "(", ")", ";", "if", "(", "!", "$", "match", "||", "!", "$", "event", "->", "getRequest", "(", ")", "instanceof", "HttpRequest", ")", "{", "return", ";", "}", "if", "(", "$", "event", "->", "getParam", "(", "'route-cached'", ")", "||", "!", "$", "event", "->", "getParam", "(", "'route-cacheable'", ")", ")", "{", "return", ";", "}", "$", "path", "=", "$", "event", "->", "getRequest", "(", ")", "->", "getUri", "(", ")", "->", "getPath", "(", ")", ";", "// save the route match into the cache.", "$", "services", "=", "$", "event", "->", "getApplication", "(", ")", "->", "getServiceManager", "(", ")", ";", "$", "cacheName", "=", "$", "services", "->", "get", "(", "RouterCacheOptions", "::", "class", ")", "->", "getCache", "(", ")", ";", "$", "cache", "=", "$", "services", "->", "get", "(", "$", "cacheName", ")", ";", "$", "cacheKey", "=", "$", "this", "->", "getCacheKey", "(", "$", "path", ")", ";", "$", "name", "=", "$", "match", "->", "getMatchedRouteName", "(", ")", ";", "$", "data", "=", "[", "'name'", "=>", "$", "name", ",", "'spec'", "=>", "[", "'type'", "=>", "'Literal'", ",", "'options'", "=>", "[", "'route'", "=>", "$", "path", ",", "'defaults'", "=>", "$", "match", "->", "getParams", "(", ")", ",", "]", ",", "]", ",", "]", ";", "$", "routes", "=", "$", "services", "->", "get", "(", "'Config'", ")", "[", "'router'", "]", "[", "'routes'", "]", ";", "if", "(", "isset", "(", "$", "routes", "[", "$", "name", "]", ")", ")", "{", "$", "data", "[", "'spec'", "]", "=", "array_replace_recursive", "(", "$", "routes", "[", "$", "name", "]", ",", "$", "data", "[", "'spec'", "]", ")", ";", "}", "$", "cache", "->", "setItem", "(", "$", "cacheKey", ",", "$", "data", ")", ";", "}" ]
Method that tries to save a route match into a cache @param MvcEvent $event
[ "Method", "that", "tries", "to", "save", "a", "route", "match", "into", "a", "cache" ]
3572993cdcdb2898cdde396a2f1de9864b193660
https://github.com/coolms/common/blob/3572993cdcdb2898cdde396a2f1de9864b193660/src/Listener/RouterCacheListener.php#L48-L87
1,916
standardlibrary/collection
src/Collection.php
Collection.apply
final public function apply(callable $function, array $args = []): self { iterator_apply( // Use $this object as the iterator $this, // Wrap callable in closure that alway returns true function(CollectionType $collection) use ($function, $args) { // Set current key to result of callable $collection->set( // Current key $collection->key(), // User-defined callable $function( // Current value $collection->current(), // Optional user-defined arguments $args ) ); return true; }, // Pass $this (again) to the function for reasons unbeknown to science // {@see https://www.reddit.com/r/lolphp/comments/5zkn29/what_the_hell_with_iterator_apply/} [$this->toArray()] ); // Return to allow method-chaining return $this; }
php
final public function apply(callable $function, array $args = []): self { iterator_apply( // Use $this object as the iterator $this, // Wrap callable in closure that alway returns true function(CollectionType $collection) use ($function, $args) { // Set current key to result of callable $collection->set( // Current key $collection->key(), // User-defined callable $function( // Current value $collection->current(), // Optional user-defined arguments $args ) ); return true; }, // Pass $this (again) to the function for reasons unbeknown to science // {@see https://www.reddit.com/r/lolphp/comments/5zkn29/what_the_hell_with_iterator_apply/} [$this->toArray()] ); // Return to allow method-chaining return $this; }
[ "final", "public", "function", "apply", "(", "callable", "$", "function", ",", "array", "$", "args", "=", "[", "]", ")", ":", "self", "{", "iterator_apply", "(", "// Use $this object as the iterator", "$", "this", ",", "// Wrap callable in closure that alway returns true", "function", "(", "CollectionType", "$", "collection", ")", "use", "(", "$", "function", ",", "$", "args", ")", "{", "// Set current key to result of callable", "$", "collection", "->", "set", "(", "// Current key", "$", "collection", "->", "key", "(", ")", ",", "// User-defined callable", "$", "function", "(", "// Current value", "$", "collection", "->", "current", "(", ")", ",", "// Optional user-defined arguments", "$", "args", ")", ")", ";", "return", "true", ";", "}", ",", "// Pass $this (again) to the function for reasons unbeknown to science", "// {@see https://www.reddit.com/r/lolphp/comments/5zkn29/what_the_hell_with_iterator_apply/}", "[", "$", "this", "->", "toArray", "(", ")", "]", ")", ";", "// Return to allow method-chaining", "return", "$", "this", ";", "}" ]
Apply a callback to every element of the collection This method applies the suplied $function callable to each item of the collection. The callable MAY modify the items but it MUST return a value. The method SHOULD return the same instance to allow method-chaining. @param callable $function - the user-defined function to apply @param array $args - OPTIONAL array of arguments to pass to the callable @return self
[ "Apply", "a", "callback", "to", "every", "element", "of", "the", "collection" ]
cbe284e77ed6816dccacc857c65bd3f956f59230
https://github.com/standardlibrary/collection/blob/cbe284e77ed6816dccacc857c65bd3f956f59230/src/Collection.php#L87-L124
1,917
standardlibrary/collection
src/Collection.php
Collection.filter
final public function filter(callable $filter, array $args = []): self { // Start a new Collection to collect the filtered results $collection = new Collection(); // Iterate over current Collection iterator_apply( // Use $this object as the iterator $this, // Wrap callable in closure that alway returns true function(IteratorAggregate $iterator) use ($filter, $args, &$collection) { // Pass current element and optional arguments to callable if ($filter($iterator->current(), $args) === true) { $collection->set( $iterator->key(), $iterator->current() ); } return true; }, // Pass $this (again) to the function for reasons unbeknown to science // {@see https://www.reddit.com/r/lolphp/comments/5zkn29/what_the_hell_with_iterator_apply/} [$this->toArray()] ); // Return filtered Collection return $collection; }
php
final public function filter(callable $filter, array $args = []): self { // Start a new Collection to collect the filtered results $collection = new Collection(); // Iterate over current Collection iterator_apply( // Use $this object as the iterator $this, // Wrap callable in closure that alway returns true function(IteratorAggregate $iterator) use ($filter, $args, &$collection) { // Pass current element and optional arguments to callable if ($filter($iterator->current(), $args) === true) { $collection->set( $iterator->key(), $iterator->current() ); } return true; }, // Pass $this (again) to the function for reasons unbeknown to science // {@see https://www.reddit.com/r/lolphp/comments/5zkn29/what_the_hell_with_iterator_apply/} [$this->toArray()] ); // Return filtered Collection return $collection; }
[ "final", "public", "function", "filter", "(", "callable", "$", "filter", ",", "array", "$", "args", "=", "[", "]", ")", ":", "self", "{", "// Start a new Collection to collect the filtered results", "$", "collection", "=", "new", "Collection", "(", ")", ";", "// Iterate over current Collection", "iterator_apply", "(", "// Use $this object as the iterator", "$", "this", ",", "// Wrap callable in closure that alway returns true", "function", "(", "IteratorAggregate", "$", "iterator", ")", "use", "(", "$", "filter", ",", "$", "args", ",", "&", "$", "collection", ")", "{", "// Pass current element and optional arguments to callable", "if", "(", "$", "filter", "(", "$", "iterator", "->", "current", "(", ")", ",", "$", "args", ")", "===", "true", ")", "{", "$", "collection", "->", "set", "(", "$", "iterator", "->", "key", "(", ")", ",", "$", "iterator", "->", "current", "(", ")", ")", ";", "}", "return", "true", ";", "}", ",", "// Pass $this (again) to the function for reasons unbeknown to science", "// {@see https://www.reddit.com/r/lolphp/comments/5zkn29/what_the_hell_with_iterator_apply/}", "[", "$", "this", "->", "toArray", "(", ")", "]", ")", ";", "// Return filtered Collection", "return", "$", "collection", ";", "}" ]
Filter the current collection by a user-defined function @param callable $filter - the user-defined function to filter by @param array $args - OPTIONAL array of arguments to pass to the callable @return self
[ "Filter", "the", "current", "collection", "by", "a", "user", "-", "defined", "function" ]
cbe284e77ed6816dccacc857c65bd3f956f59230
https://github.com/standardlibrary/collection/blob/cbe284e77ed6816dccacc857c65bd3f956f59230/src/Collection.php#L133-L166
1,918
standardlibrary/collection
src/Collection.php
Collection.first
public function first(callable $filter = null, array $args = [], $default = null) { // Use $this if no filter provided $filtered = ($filter === null) ? $this : $this->filter($filter, $args) ; // Return first value or default if filtered collection is empty return empty($filtered) ? $default : reset($filtered); }
php
public function first(callable $filter = null, array $args = [], $default = null) { // Use $this if no filter provided $filtered = ($filter === null) ? $this : $this->filter($filter, $args) ; // Return first value or default if filtered collection is empty return empty($filtered) ? $default : reset($filtered); }
[ "public", "function", "first", "(", "callable", "$", "filter", "=", "null", ",", "array", "$", "args", "=", "[", "]", ",", "$", "default", "=", "null", ")", "{", "// Use $this if no filter provided", "$", "filtered", "=", "(", "$", "filter", "===", "null", ")", "?", "$", "this", ":", "$", "this", "->", "filter", "(", "$", "filter", ",", "$", "args", ")", ";", "// Return first value or default if filtered collection is empty", "return", "empty", "(", "$", "filtered", ")", "?", "$", "default", ":", "reset", "(", "$", "filtered", ")", ";", "}" ]
Return first element matching criteria @param callable|null $filter - user-defined function to filter elements @param array $args - OPTIONAL array of arguments to pass to the callable @param mixed|null $default - OPTIONAL default value to return @return mixed
[ "Return", "first", "element", "matching", "criteria" ]
cbe284e77ed6816dccacc857c65bd3f956f59230
https://github.com/standardlibrary/collection/blob/cbe284e77ed6816dccacc857c65bd3f956f59230/src/Collection.php#L176-L186
1,919
standardlibrary/collection
src/Collection.php
Collection.last
public function last(callable $filter = null, array $args = [], $default = null) { // Use $this if no filter provided $filtered = ($filter === null) ? $this : $this->filter($filter, $args) ; // Return last value or default if filtered collection is empty return empty($filtered) ? $default : end($filtered); }
php
public function last(callable $filter = null, array $args = [], $default = null) { // Use $this if no filter provided $filtered = ($filter === null) ? $this : $this->filter($filter, $args) ; // Return last value or default if filtered collection is empty return empty($filtered) ? $default : end($filtered); }
[ "public", "function", "last", "(", "callable", "$", "filter", "=", "null", ",", "array", "$", "args", "=", "[", "]", ",", "$", "default", "=", "null", ")", "{", "// Use $this if no filter provided", "$", "filtered", "=", "(", "$", "filter", "===", "null", ")", "?", "$", "this", ":", "$", "this", "->", "filter", "(", "$", "filter", ",", "$", "args", ")", ";", "// Return last value or default if filtered collection is empty", "return", "empty", "(", "$", "filtered", ")", "?", "$", "default", ":", "end", "(", "$", "filtered", ")", ";", "}" ]
Return last element matching criteria @param callable|null $filter - user-defined function to filter elements @param array $args - OPTIONAL array of arguments to pass to the callable @param mixed|null $default - OPTIONAL default value to return @return mixed
[ "Return", "last", "element", "matching", "criteria" ]
cbe284e77ed6816dccacc857c65bd3f956f59230
https://github.com/standardlibrary/collection/blob/cbe284e77ed6816dccacc857c65bd3f956f59230/src/Collection.php#L196-L206
1,920
standardlibrary/collection
src/Collection.php
Collection.exists
public function exists($offset): bool { $offsets = is_array($offset) ? $offset : func_get_args(); foreach ($offsets as $key) { if (! $this->offsetExists($key)) { return false; } } return true; }
php
public function exists($offset): bool { $offsets = is_array($offset) ? $offset : func_get_args(); foreach ($offsets as $key) { if (! $this->offsetExists($key)) { return false; } } return true; }
[ "public", "function", "exists", "(", "$", "offset", ")", ":", "bool", "{", "$", "offsets", "=", "is_array", "(", "$", "offset", ")", "?", "$", "offset", ":", "func_get_args", "(", ")", ";", "foreach", "(", "$", "offsets", "as", "$", "key", ")", "{", "if", "(", "!", "$", "this", "->", "offsetExists", "(", "$", "key", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Check that an offset, or series of offsets exists @param mixed $offset - the offset(s) to check @return bool
[ "Check", "that", "an", "offset", "or", "series", "of", "offsets", "exists" ]
cbe284e77ed6816dccacc857c65bd3f956f59230
https://github.com/standardlibrary/collection/blob/cbe284e77ed6816dccacc857c65bd3f956f59230/src/Collection.php#L252-L264
1,921
standardlibrary/collection
src/Collection.php
Collection.count
final public function count(): int { // If size if known, return it if (isset($this->size)) { return $this->size; } // Calculate, cache and then return the size return $this->size = count($this->data); }
php
final public function count(): int { // If size if known, return it if (isset($this->size)) { return $this->size; } // Calculate, cache and then return the size return $this->size = count($this->data); }
[ "final", "public", "function", "count", "(", ")", ":", "int", "{", "// If size if known, return it", "if", "(", "isset", "(", "$", "this", "->", "size", ")", ")", "{", "return", "$", "this", "->", "size", ";", "}", "// Calculate, cache and then return the size", "return", "$", "this", "->", "size", "=", "count", "(", "$", "this", "->", "data", ")", ";", "}" ]
Counts the items in the set @return int
[ "Counts", "the", "items", "in", "the", "set" ]
cbe284e77ed6816dccacc857c65bd3f956f59230
https://github.com/standardlibrary/collection/blob/cbe284e77ed6816dccacc857c65bd3f956f59230/src/Collection.php#L334-L343
1,922
standardlibrary/collection
src/Collection.php
Collection.getCachedIterator
final private function getCachedIterator(): CachingIterator { // If cache is generated, return it if (isset($this->iterator)) { return $this->iterator; } // Create and return new CachedIterator from the data return $this->iterator = new CachingIterator( // The raw data new ArrayIterator($this->data), // Always use original data and force all items to be cached on read CachingIterator::TOSTRING_USE_CURRENT | CachingIterator::FULL_CACHE ); }
php
final private function getCachedIterator(): CachingIterator { // If cache is generated, return it if (isset($this->iterator)) { return $this->iterator; } // Create and return new CachedIterator from the data return $this->iterator = new CachingIterator( // The raw data new ArrayIterator($this->data), // Always use original data and force all items to be cached on read CachingIterator::TOSTRING_USE_CURRENT | CachingIterator::FULL_CACHE ); }
[ "final", "private", "function", "getCachedIterator", "(", ")", ":", "CachingIterator", "{", "// If cache is generated, return it", "if", "(", "isset", "(", "$", "this", "->", "iterator", ")", ")", "{", "return", "$", "this", "->", "iterator", ";", "}", "// Create and return new CachedIterator from the data", "return", "$", "this", "->", "iterator", "=", "new", "CachingIterator", "(", "// The raw data", "new", "ArrayIterator", "(", "$", "this", "->", "data", ")", ",", "// Always use original data and force all items to be cached on read", "CachingIterator", "::", "TOSTRING_USE_CURRENT", "|", "CachingIterator", "::", "FULL_CACHE", ")", ";", "}" ]
Get the cache @return CachingIterator
[ "Get", "the", "cache" ]
cbe284e77ed6816dccacc857c65bd3f956f59230
https://github.com/standardlibrary/collection/blob/cbe284e77ed6816dccacc857c65bd3f956f59230/src/Collection.php#L455-L471
1,923
consolle/framework
src/Application.php
Application.getLogo
public static function getLogo() { // Verificar se foi definido a logo do app $file_logo_app = app_path('logo.txt'); if (file_exists($file_logo_app)) return file_get_contents($file_logo_app); // Logo do framework $file_logo = __DIR__ . '/Resources/logo.txt'; if (file_exists($file_logo)) return file_get_contents($file_logo); return ''; }
php
public static function getLogo() { // Verificar se foi definido a logo do app $file_logo_app = app_path('logo.txt'); if (file_exists($file_logo_app)) return file_get_contents($file_logo_app); // Logo do framework $file_logo = __DIR__ . '/Resources/logo.txt'; if (file_exists($file_logo)) return file_get_contents($file_logo); return ''; }
[ "public", "static", "function", "getLogo", "(", ")", "{", "// Verificar se foi definido a logo do app", "$", "file_logo_app", "=", "app_path", "(", "'logo.txt'", ")", ";", "if", "(", "file_exists", "(", "$", "file_logo_app", ")", ")", "return", "file_get_contents", "(", "$", "file_logo_app", ")", ";", "// Logo do framework", "$", "file_logo", "=", "__DIR__", ".", "'/Resources/logo.txt'", ";", "if", "(", "file_exists", "(", "$", "file_logo", ")", ")", "return", "file_get_contents", "(", "$", "file_logo", ")", ";", "return", "''", ";", "}" ]
Rerurn logo ASCII @return string
[ "Rerurn", "logo", "ASCII" ]
2799921d6983f31e775099eac116c337bbe29c74
https://github.com/consolle/framework/blob/2799921d6983f31e775099eac116c337bbe29c74/src/Application.php#L190-L202
1,924
consolle/framework
src/Application.php
Application.getDefaultCommands
protected function getDefaultCommands() { $commands = parent::getDefaultCommands(); $commands[] = new Command\AboutCommand($this->app); $commands[] = new Command\StopCommand($this->app); // Comandos da aplicacao $cmds = config('app.commands', []); foreach ($cmds as $cid => $cClass) { $cid = sprintf('command.%s', $cid); $this->app->bind($cid, $cClass); $commands[] = $this->app[$cid]; } // verificar se deve incluir o comando make:command if (('phar:' !== substr(__FILE__, 0, 5)) && (class_exists('\Consolle\Command\MakeCommand'))) $commands[] = new \Consolle\Command\MakeCommand($this->app); // verificar se deve incluir o comando optimize if (('phar:' !== substr(__FILE__, 0, 5)) && (class_exists('\Consolle\Command\OptimizeCommand'))) $commands[] = new \Consolle\Command\OptimizeCommand($this->app); // verificar se deve incluir o comando self-compiler if (('phar:' !== substr(__FILE__, 0, 5)) && (class_exists('\Consolle\Command\SelfCompilerCommand'))) $commands[] = new \Consolle\Command\SelfCompilerCommand($this->app); // Verificar se deve incluir o comando self-update if (('phar:' === substr(__FILE__, 0, 5)) && (class_exists('\Consolle\Command\SelfCompilerCommand')) && (file_exists(base_path('update.json')))) $commands[] = new \Consolle\Command\SelfUpdateCommand($this->app); return $commands; }
php
protected function getDefaultCommands() { $commands = parent::getDefaultCommands(); $commands[] = new Command\AboutCommand($this->app); $commands[] = new Command\StopCommand($this->app); // Comandos da aplicacao $cmds = config('app.commands', []); foreach ($cmds as $cid => $cClass) { $cid = sprintf('command.%s', $cid); $this->app->bind($cid, $cClass); $commands[] = $this->app[$cid]; } // verificar se deve incluir o comando make:command if (('phar:' !== substr(__FILE__, 0, 5)) && (class_exists('\Consolle\Command\MakeCommand'))) $commands[] = new \Consolle\Command\MakeCommand($this->app); // verificar se deve incluir o comando optimize if (('phar:' !== substr(__FILE__, 0, 5)) && (class_exists('\Consolle\Command\OptimizeCommand'))) $commands[] = new \Consolle\Command\OptimizeCommand($this->app); // verificar se deve incluir o comando self-compiler if (('phar:' !== substr(__FILE__, 0, 5)) && (class_exists('\Consolle\Command\SelfCompilerCommand'))) $commands[] = new \Consolle\Command\SelfCompilerCommand($this->app); // Verificar se deve incluir o comando self-update if (('phar:' === substr(__FILE__, 0, 5)) && (class_exists('\Consolle\Command\SelfCompilerCommand')) && (file_exists(base_path('update.json')))) $commands[] = new \Consolle\Command\SelfUpdateCommand($this->app); return $commands; }
[ "protected", "function", "getDefaultCommands", "(", ")", "{", "$", "commands", "=", "parent", "::", "getDefaultCommands", "(", ")", ";", "$", "commands", "[", "]", "=", "new", "Command", "\\", "AboutCommand", "(", "$", "this", "->", "app", ")", ";", "$", "commands", "[", "]", "=", "new", "Command", "\\", "StopCommand", "(", "$", "this", "->", "app", ")", ";", "// Comandos da aplicacao", "$", "cmds", "=", "config", "(", "'app.commands'", ",", "[", "]", ")", ";", "foreach", "(", "$", "cmds", "as", "$", "cid", "=>", "$", "cClass", ")", "{", "$", "cid", "=", "sprintf", "(", "'command.%s'", ",", "$", "cid", ")", ";", "$", "this", "->", "app", "->", "bind", "(", "$", "cid", ",", "$", "cClass", ")", ";", "$", "commands", "[", "]", "=", "$", "this", "->", "app", "[", "$", "cid", "]", ";", "}", "// verificar se deve incluir o comando make:command", "if", "(", "(", "'phar:'", "!==", "substr", "(", "__FILE__", ",", "0", ",", "5", ")", ")", "&&", "(", "class_exists", "(", "'\\Consolle\\Command\\MakeCommand'", ")", ")", ")", "$", "commands", "[", "]", "=", "new", "\\", "Consolle", "\\", "Command", "\\", "MakeCommand", "(", "$", "this", "->", "app", ")", ";", "// verificar se deve incluir o comando optimize", "if", "(", "(", "'phar:'", "!==", "substr", "(", "__FILE__", ",", "0", ",", "5", ")", ")", "&&", "(", "class_exists", "(", "'\\Consolle\\Command\\OptimizeCommand'", ")", ")", ")", "$", "commands", "[", "]", "=", "new", "\\", "Consolle", "\\", "Command", "\\", "OptimizeCommand", "(", "$", "this", "->", "app", ")", ";", "// verificar se deve incluir o comando self-compiler", "if", "(", "(", "'phar:'", "!==", "substr", "(", "__FILE__", ",", "0", ",", "5", ")", ")", "&&", "(", "class_exists", "(", "'\\Consolle\\Command\\SelfCompilerCommand'", ")", ")", ")", "$", "commands", "[", "]", "=", "new", "\\", "Consolle", "\\", "Command", "\\", "SelfCompilerCommand", "(", "$", "this", "->", "app", ")", ";", "// Verificar se deve incluir o comando self-update", "if", "(", "(", "'phar:'", "===", "substr", "(", "__FILE__", ",", "0", ",", "5", ")", ")", "&&", "(", "class_exists", "(", "'\\Consolle\\Command\\SelfCompilerCommand'", ")", ")", "&&", "(", "file_exists", "(", "base_path", "(", "'update.json'", ")", ")", ")", ")", "$", "commands", "[", "]", "=", "new", "\\", "Consolle", "\\", "Command", "\\", "SelfUpdateCommand", "(", "$", "this", "->", "app", ")", ";", "return", "$", "commands", ";", "}" ]
Initializes all the commands default
[ "Initializes", "all", "the", "commands", "default" ]
2799921d6983f31e775099eac116c337bbe29c74
https://github.com/consolle/framework/blob/2799921d6983f31e775099eac116c337bbe29c74/src/Application.php#L207-L239
1,925
gismo-framework/ExpressionLanguage
ExpressionLanguage.php
ExpressionLanguage.compile
public function compile($expression, $names = array()) { return $this->getCompiler()->compile($this->parse($expression, $names)->getNodes())->getSource(); }
php
public function compile($expression, $names = array()) { return $this->getCompiler()->compile($this->parse($expression, $names)->getNodes())->getSource(); }
[ "public", "function", "compile", "(", "$", "expression", ",", "$", "names", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "getCompiler", "(", ")", "->", "compile", "(", "$", "this", "->", "parse", "(", "$", "expression", ",", "$", "names", ")", "->", "getNodes", "(", ")", ")", "->", "getSource", "(", ")", ";", "}" ]
Compiles an expression source code. @param Expression|string $expression The expression to compile @param array $names An array of valid names @return string The compiled PHP source code
[ "Compiles", "an", "expression", "source", "code", "." ]
ceb176416dc3669aa269e8f93b7232a94c221167
https://github.com/gismo-framework/ExpressionLanguage/blob/ceb176416dc3669aa269e8f93b7232a94c221167/ExpressionLanguage.php#L55-L58
1,926
Flowpack/Flowpack.SingleSignOn.Server
Classes/Flowpack/SingleSignOn/Server/Session/SsoSessionManager.php
SsoSessionManager.destroyRegisteredSsoClientSessions
public function destroyRegisteredSsoClientSessions(SessionInterface $session) { if (!$session->isStarted()) { return; } $ssoClients = $this->getRegisteredSsoClients($session); $sessionId = $session->getId(); $ssoServer = $this->ssoServerFactory->create(); $this->ssoClientNotifier->destroySession($ssoServer, $sessionId, $ssoClients); }
php
public function destroyRegisteredSsoClientSessions(SessionInterface $session) { if (!$session->isStarted()) { return; } $ssoClients = $this->getRegisteredSsoClients($session); $sessionId = $session->getId(); $ssoServer = $this->ssoServerFactory->create(); $this->ssoClientNotifier->destroySession($ssoServer, $sessionId, $ssoClients); }
[ "public", "function", "destroyRegisteredSsoClientSessions", "(", "SessionInterface", "$", "session", ")", "{", "if", "(", "!", "$", "session", "->", "isStarted", "(", ")", ")", "{", "return", ";", "}", "$", "ssoClients", "=", "$", "this", "->", "getRegisteredSsoClients", "(", "$", "session", ")", ";", "$", "sessionId", "=", "$", "session", "->", "getId", "(", ")", ";", "$", "ssoServer", "=", "$", "this", "->", "ssoServerFactory", "->", "create", "(", ")", ";", "$", "this", "->", "ssoClientNotifier", "->", "destroySession", "(", "$", "ssoServer", ",", "$", "sessionId", ",", "$", "ssoClients", ")", ";", "}" ]
Destroy the given session on registered SSO clients @param \TYPO3\Flow\Session\SessionInterface $session @return void
[ "Destroy", "the", "given", "session", "on", "registered", "SSO", "clients" ]
b1fa014f31d0d101a79cb95d5585b9973f35347d
https://github.com/Flowpack/Flowpack.SingleSignOn.Server/blob/b1fa014f31d0d101a79cb95d5585b9973f35347d/Classes/Flowpack/SingleSignOn/Server/Session/SsoSessionManager.php#L72-L82
1,927
vincenttouzet/AdminConfigurationBundle
Repository/ConfigSectionRepository.php
ConfigSectionRepository.findAllWithConfigGroups
public function findAllWithConfigGroups() { $query = $this->createQueryBuilder('s') ->select('s', 'g') ->innerJoin('s.configGroups', 'g') ->orderBy('s.position', 'ASC') ->getQuery(); $result = $query->getResult(); return $result; }
php
public function findAllWithConfigGroups() { $query = $this->createQueryBuilder('s') ->select('s', 'g') ->innerJoin('s.configGroups', 'g') ->orderBy('s.position', 'ASC') ->getQuery(); $result = $query->getResult(); return $result; }
[ "public", "function", "findAllWithConfigGroups", "(", ")", "{", "$", "query", "=", "$", "this", "->", "createQueryBuilder", "(", "'s'", ")", "->", "select", "(", "'s'", ",", "'g'", ")", "->", "innerJoin", "(", "'s.configGroups'", ",", "'g'", ")", "->", "orderBy", "(", "'s.position'", ",", "'ASC'", ")", "->", "getQuery", "(", ")", ";", "$", "result", "=", "$", "query", "->", "getResult", "(", ")", ";", "return", "$", "result", ";", "}" ]
Find all section with their groups @return array
[ "Find", "all", "section", "with", "their", "groups" ]
8e7edd0810d88aa1d1be4bd303bcc14cbfd0caeb
https://github.com/vincenttouzet/AdminConfigurationBundle/blob/8e7edd0810d88aa1d1be4bd303bcc14cbfd0caeb/Repository/ConfigSectionRepository.php#L35-L45
1,928
jaredtking/jaqb
src/Operations/Fetchable.php
Fetchable.one
public function one($style = PDO::FETCH_ASSOC) { $stmt = $this->execute(); if ($stmt) { return $stmt->fetch($style); } else { return false; } }
php
public function one($style = PDO::FETCH_ASSOC) { $stmt = $this->execute(); if ($stmt) { return $stmt->fetch($style); } else { return false; } }
[ "public", "function", "one", "(", "$", "style", "=", "PDO", "::", "FETCH_ASSOC", ")", "{", "$", "stmt", "=", "$", "this", "->", "execute", "(", ")", ";", "if", "(", "$", "stmt", ")", "{", "return", "$", "stmt", "->", "fetch", "(", "$", "style", ")", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Executes a query and returns the first row. @param int $style PDO fetch style @return mixed|bool result
[ "Executes", "a", "query", "and", "returns", "the", "first", "row", "." ]
04a853b530fcc12a9863349d3d0da6377d1b9995
https://github.com/jaredtking/jaqb/blob/04a853b530fcc12a9863349d3d0da6377d1b9995/src/Operations/Fetchable.php#L24-L33
1,929
jaredtking/jaqb
src/Operations/Fetchable.php
Fetchable.all
public function all($style = PDO::FETCH_ASSOC) { $stmt = $this->execute(); if ($stmt) { return $stmt->fetchAll($style); } else { return false; } }
php
public function all($style = PDO::FETCH_ASSOC) { $stmt = $this->execute(); if ($stmt) { return $stmt->fetchAll($style); } else { return false; } }
[ "public", "function", "all", "(", "$", "style", "=", "PDO", "::", "FETCH_ASSOC", ")", "{", "$", "stmt", "=", "$", "this", "->", "execute", "(", ")", ";", "if", "(", "$", "stmt", ")", "{", "return", "$", "stmt", "->", "fetchAll", "(", "$", "style", ")", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Executes a query and returns all of the rows. @param int $style PDO fetch style @return mixed|bool result
[ "Executes", "a", "query", "and", "returns", "all", "of", "the", "rows", "." ]
04a853b530fcc12a9863349d3d0da6377d1b9995
https://github.com/jaredtking/jaqb/blob/04a853b530fcc12a9863349d3d0da6377d1b9995/src/Operations/Fetchable.php#L42-L51
1,930
jaredtking/jaqb
src/Operations/Fetchable.php
Fetchable.column
public function column($index = 0) { $stmt = $this->execute(); if ($stmt) { return $stmt->fetchAll(PDO::FETCH_COLUMN, $index); } else { return false; } }
php
public function column($index = 0) { $stmt = $this->execute(); if ($stmt) { return $stmt->fetchAll(PDO::FETCH_COLUMN, $index); } else { return false; } }
[ "public", "function", "column", "(", "$", "index", "=", "0", ")", "{", "$", "stmt", "=", "$", "this", "->", "execute", "(", ")", ";", "if", "(", "$", "stmt", ")", "{", "return", "$", "stmt", "->", "fetchAll", "(", "PDO", "::", "FETCH_COLUMN", ",", "$", "index", ")", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Executes a query and returns a column from all rows. @param int $index zero-indexed column to fetch @return mixed|bool result
[ "Executes", "a", "query", "and", "returns", "a", "column", "from", "all", "rows", "." ]
04a853b530fcc12a9863349d3d0da6377d1b9995
https://github.com/jaredtking/jaqb/blob/04a853b530fcc12a9863349d3d0da6377d1b9995/src/Operations/Fetchable.php#L60-L69
1,931
jaredtking/jaqb
src/Operations/Fetchable.php
Fetchable.scalar
public function scalar($index = 0) { $stmt = $this->execute(); if ($stmt) { return $stmt->fetchColumn($index); } else { return false; } }
php
public function scalar($index = 0) { $stmt = $this->execute(); if ($stmt) { return $stmt->fetchColumn($index); } else { return false; } }
[ "public", "function", "scalar", "(", "$", "index", "=", "0", ")", "{", "$", "stmt", "=", "$", "this", "->", "execute", "(", ")", ";", "if", "(", "$", "stmt", ")", "{", "return", "$", "stmt", "->", "fetchColumn", "(", "$", "index", ")", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Executes a query and returns a value from the first row. @param int $index zero-indexed column to fetch @return mixed|bool result
[ "Executes", "a", "query", "and", "returns", "a", "value", "from", "the", "first", "row", "." ]
04a853b530fcc12a9863349d3d0da6377d1b9995
https://github.com/jaredtking/jaqb/blob/04a853b530fcc12a9863349d3d0da6377d1b9995/src/Operations/Fetchable.php#L78-L87
1,932
bkdotcom/Toolbox
src/Str.php
Str.isBase64Encoded
public static function isBase64Encoded($str) { $debug = \bdk\Debug::getInstance(); return $debug->utilities->isBase64Encoded($str); }
php
public static function isBase64Encoded($str) { $debug = \bdk\Debug::getInstance(); return $debug->utilities->isBase64Encoded($str); }
[ "public", "static", "function", "isBase64Encoded", "(", "$", "str", ")", "{", "$", "debug", "=", "\\", "bdk", "\\", "Debug", "::", "getInstance", "(", ")", ";", "return", "$", "debug", "->", "utilities", "->", "isBase64Encoded", "(", "$", "str", ")", ";", "}" ]
Checks if a given string is base64 encoded @param string $str string to check @return boolean
[ "Checks", "if", "a", "given", "string", "is", "base64", "encoded" ]
2f9d34fd57bd8382baee4c29aac13a6710e3a994
https://github.com/bkdotcom/Toolbox/blob/2f9d34fd57bd8382baee4c29aac13a6710e3a994/src/Str.php#L92-L96
1,933
bkdotcom/Toolbox
src/Str.php
Str.isUrl
public static function isUrl($url, $opts = array()) { $opts = \array_merge(array( 'requireSchema' => true, ), $opts); $urlRegEx = '@^' .($opts['requireSchema'] ? 'https?://' : '(https?://)?' ) .'[-\w\.]+' // hostname .'(:\d+)?' // port // .'(/([-\w/\.]*(\?\S+)?)?)?@'; .'(' .'/' .'(' .'[-\w/\.,%:]*' // path .'(\?\S+)?' // query .'(#\S*)?' // fragment/hash .')?' .')?' .'$@'; return \preg_match($urlRegEx, $url) > 0; }
php
public static function isUrl($url, $opts = array()) { $opts = \array_merge(array( 'requireSchema' => true, ), $opts); $urlRegEx = '@^' .($opts['requireSchema'] ? 'https?://' : '(https?://)?' ) .'[-\w\.]+' // hostname .'(:\d+)?' // port // .'(/([-\w/\.]*(\?\S+)?)?)?@'; .'(' .'/' .'(' .'[-\w/\.,%:]*' // path .'(\?\S+)?' // query .'(#\S*)?' // fragment/hash .')?' .')?' .'$@'; return \preg_match($urlRegEx, $url) > 0; }
[ "public", "static", "function", "isUrl", "(", "$", "url", ",", "$", "opts", "=", "array", "(", ")", ")", "{", "$", "opts", "=", "\\", "array_merge", "(", "array", "(", "'requireSchema'", "=>", "true", ",", ")", ",", "$", "opts", ")", ";", "$", "urlRegEx", "=", "'@^'", ".", "(", "$", "opts", "[", "'requireSchema'", "]", "?", "'https?://'", ":", "'(https?://)?'", ")", ".", "'[-\\w\\.]+'", "// hostname", ".", "'(:\\d+)?'", "// port", "// .'(/([-\\w/\\.]*(\\?\\S+)?)?)?@';", ".", "'('", ".", "'/'", ".", "'('", ".", "'[-\\w/\\.,%:]*'", "// path", ".", "'(\\?\\S+)?'", "// query", ".", "'(#\\S*)?'", "// fragment/hash", ".", "')?'", ".", "')?'", ".", "'$@'", ";", "return", "\\", "preg_match", "(", "$", "urlRegEx", ",", "$", "url", ")", ">", "0", ";", "}" ]
Is the passed string a URL? @param string $url string/URL to test @param array $opts options @return boolean
[ "Is", "the", "passed", "string", "a", "URL?" ]
2f9d34fd57bd8382baee4c29aac13a6710e3a994
https://github.com/bkdotcom/Toolbox/blob/2f9d34fd57bd8382baee4c29aac13a6710e3a994/src/Str.php#L106-L129
1,934
atompulse/data
Transform.php
Transform.fromCamelToUnder
public static function fromCamelToUnder($data) { $transformed = []; foreach ($data as $camelKey => $value) { $transformed[self::unCamelize($camelKey)] = $value; } return $transformed; }
php
public static function fromCamelToUnder($data) { $transformed = []; foreach ($data as $camelKey => $value) { $transformed[self::unCamelize($camelKey)] = $value; } return $transformed; }
[ "public", "static", "function", "fromCamelToUnder", "(", "$", "data", ")", "{", "$", "transformed", "=", "[", "]", ";", "foreach", "(", "$", "data", "as", "$", "camelKey", "=>", "$", "value", ")", "{", "$", "transformed", "[", "self", "::", "unCamelize", "(", "$", "camelKey", ")", "]", "=", "$", "value", ";", "}", "return", "$", "transformed", ";", "}" ]
Transform an array's keys from camelCase to under_score @param array $data @return array
[ "Transform", "an", "array", "s", "keys", "from", "camelCase", "to", "under_score" ]
14bfd67f3b237fcb9d29dfc313b25f32d37506e6
https://github.com/atompulse/data/blob/14bfd67f3b237fcb9d29dfc313b25f32d37506e6/Transform.php#L20-L28
1,935
atompulse/data
Transform.php
Transform.arrayFromCamelToUnder
public static function arrayFromCamelToUnder($arrData) { $transformed = []; foreach ($arrData as $index => $data) { foreach ($data as $camelKey => $value) { $transformed[$index][self::unCamelize($camelKey)] = $value; } } return $transformed; }
php
public static function arrayFromCamelToUnder($arrData) { $transformed = []; foreach ($arrData as $index => $data) { foreach ($data as $camelKey => $value) { $transformed[$index][self::unCamelize($camelKey)] = $value; } } return $transformed; }
[ "public", "static", "function", "arrayFromCamelToUnder", "(", "$", "arrData", ")", "{", "$", "transformed", "=", "[", "]", ";", "foreach", "(", "$", "arrData", "as", "$", "index", "=>", "$", "data", ")", "{", "foreach", "(", "$", "data", "as", "$", "camelKey", "=>", "$", "value", ")", "{", "$", "transformed", "[", "$", "index", "]", "[", "self", "::", "unCamelize", "(", "$", "camelKey", ")", "]", "=", "$", "value", ";", "}", "}", "return", "$", "transformed", ";", "}" ]
Transform arrays keys from camelCase to under_score @param array $arrData @return array
[ "Transform", "arrays", "keys", "from", "camelCase", "to", "under_score" ]
14bfd67f3b237fcb9d29dfc313b25f32d37506e6
https://github.com/atompulse/data/blob/14bfd67f3b237fcb9d29dfc313b25f32d37506e6/Transform.php#L35-L44
1,936
atompulse/data
Transform.php
Transform.transliterateStr
public static function transliterateStr($str) { /** * Transliterated sets * $a = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'Ā', 'ā', 'Ă', 'ă', 'Ą', 'ą', 'Ć', 'ć', 'Ĉ', 'ĉ', 'Ċ', 'ċ', 'Č', 'č', 'Ď', 'ď', 'Đ', 'đ', 'Ē', 'ē', 'Ĕ', 'ĕ', 'Ė', 'ė', 'Ę', 'ę', 'Ě', 'ě', 'Ĝ', 'ĝ', 'Ğ', 'ğ', 'Ġ', 'ġ', 'Ģ', 'ģ', 'Ĥ', 'ĥ', 'Ħ', 'ħ', 'Ĩ', 'ĩ', 'Ī', 'ī', 'Ĭ', 'ĭ', 'Į', 'į', 'İ', 'ı', 'IJ', 'ij', 'Ĵ', 'ĵ', 'Ķ', 'ķ', 'Ĺ', 'ĺ', 'Ļ', 'ļ', 'Ľ', 'ľ', 'Ŀ', 'ŀ', 'Ł', 'ł', 'Ń', 'ń', 'Ņ', 'ņ', 'Ň', 'ň', 'ʼn', 'Ō', 'ō', 'Ŏ', 'ŏ', 'Ő', 'ő', 'Œ', 'œ', 'Ŕ', 'ŕ', 'Ŗ', 'ŗ', 'Ř', 'ř', 'Ś', 'ś', 'Ŝ', 'ŝ', 'Ş', 'ş', 'Š', 'š', 'Ţ', 'ţ', 'Ť', 'ť', 'Ŧ', 'ŧ', 'Ũ', 'ũ', 'Ū', 'ū', 'Ŭ', 'ŭ', 'Ů', 'ů', 'Ű', 'ű', 'Ų', 'ų', 'Ŵ', 'ŵ', 'Ŷ', 'ŷ', 'Ÿ', 'Ź', 'ź', 'Ż', 'ż', 'Ž', 'ž', 'ſ', 'ƒ', 'Ơ', 'ơ', 'Ư', 'ư', 'Ǎ', 'ǎ', 'Ǐ', 'ǐ', 'Ǒ', 'ǒ', 'Ǔ', 'ǔ', 'Ǖ', 'ǖ', 'Ǘ', 'ǘ', 'Ǚ', 'ǚ', 'Ǜ', 'ǜ', 'Ǻ', 'ǻ', 'Ǽ', 'ǽ', 'Ǿ', 'ǿ'); * $b = array('A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o'); */ $rule = 'Any-Latin; Latin-ASCII;'; $transliterator = \Transliterator::create($rule); return $transliterator->transliterate($str); }
php
public static function transliterateStr($str) { /** * Transliterated sets * $a = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'Ā', 'ā', 'Ă', 'ă', 'Ą', 'ą', 'Ć', 'ć', 'Ĉ', 'ĉ', 'Ċ', 'ċ', 'Č', 'č', 'Ď', 'ď', 'Đ', 'đ', 'Ē', 'ē', 'Ĕ', 'ĕ', 'Ė', 'ė', 'Ę', 'ę', 'Ě', 'ě', 'Ĝ', 'ĝ', 'Ğ', 'ğ', 'Ġ', 'ġ', 'Ģ', 'ģ', 'Ĥ', 'ĥ', 'Ħ', 'ħ', 'Ĩ', 'ĩ', 'Ī', 'ī', 'Ĭ', 'ĭ', 'Į', 'į', 'İ', 'ı', 'IJ', 'ij', 'Ĵ', 'ĵ', 'Ķ', 'ķ', 'Ĺ', 'ĺ', 'Ļ', 'ļ', 'Ľ', 'ľ', 'Ŀ', 'ŀ', 'Ł', 'ł', 'Ń', 'ń', 'Ņ', 'ņ', 'Ň', 'ň', 'ʼn', 'Ō', 'ō', 'Ŏ', 'ŏ', 'Ő', 'ő', 'Œ', 'œ', 'Ŕ', 'ŕ', 'Ŗ', 'ŗ', 'Ř', 'ř', 'Ś', 'ś', 'Ŝ', 'ŝ', 'Ş', 'ş', 'Š', 'š', 'Ţ', 'ţ', 'Ť', 'ť', 'Ŧ', 'ŧ', 'Ũ', 'ũ', 'Ū', 'ū', 'Ŭ', 'ŭ', 'Ů', 'ů', 'Ű', 'ű', 'Ų', 'ų', 'Ŵ', 'ŵ', 'Ŷ', 'ŷ', 'Ÿ', 'Ź', 'ź', 'Ż', 'ż', 'Ž', 'ž', 'ſ', 'ƒ', 'Ơ', 'ơ', 'Ư', 'ư', 'Ǎ', 'ǎ', 'Ǐ', 'ǐ', 'Ǒ', 'ǒ', 'Ǔ', 'ǔ', 'Ǖ', 'ǖ', 'Ǘ', 'ǘ', 'Ǚ', 'ǚ', 'Ǜ', 'ǜ', 'Ǻ', 'ǻ', 'Ǽ', 'ǽ', 'Ǿ', 'ǿ'); * $b = array('A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o'); */ $rule = 'Any-Latin; Latin-ASCII;'; $transliterator = \Transliterator::create($rule); return $transliterator->transliterate($str); }
[ "public", "static", "function", "transliterateStr", "(", "$", "str", ")", "{", "/**\n * Transliterated sets\n * $a = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'Ā', 'ā', 'Ă', 'ă', 'Ą', 'ą', 'Ć', 'ć', 'Ĉ', 'ĉ', 'Ċ', 'ċ', 'Č', 'č', 'Ď', 'ď', 'Đ', 'đ', 'Ē', 'ē', 'Ĕ', 'ĕ', 'Ė', 'ė', 'Ę', 'ę', 'Ě', 'ě', 'Ĝ', 'ĝ', 'Ğ', 'ğ', 'Ġ', 'ġ', 'Ģ', 'ģ', 'Ĥ', 'ĥ', 'Ħ', 'ħ', 'Ĩ', 'ĩ', 'Ī', 'ī', 'Ĭ', 'ĭ', 'Į', 'į', 'İ', 'ı', 'IJ', 'ij', 'Ĵ', 'ĵ', 'Ķ', 'ķ', 'Ĺ', 'ĺ', 'Ļ', 'ļ', 'Ľ', 'ľ', 'Ŀ', 'ŀ', 'Ł', 'ł', 'Ń', 'ń', 'Ņ', 'ņ', 'Ň', 'ň', 'ʼn', 'Ō', 'ō', 'Ŏ', 'ŏ', 'Ő', 'ő', 'Œ', 'œ', 'Ŕ', 'ŕ', 'Ŗ', 'ŗ', 'Ř', 'ř', 'Ś', 'ś', 'Ŝ', 'ŝ', 'Ş', 'ş', 'Š', 'š', 'Ţ', 'ţ', 'Ť', 'ť', 'Ŧ', 'ŧ', 'Ũ', 'ũ', 'Ū', 'ū', 'Ŭ', 'ŭ', 'Ů', 'ů', 'Ű', 'ű', 'Ų', 'ų', 'Ŵ', 'ŵ', 'Ŷ', 'ŷ', 'Ÿ', 'Ź', 'ź', 'Ż', 'ż', 'Ž', 'ž', 'ſ', 'ƒ', 'Ơ', 'ơ', 'Ư', 'ư', 'Ǎ', 'ǎ', 'Ǐ', 'ǐ', 'Ǒ', 'ǒ', 'Ǔ', 'ǔ', 'Ǖ', 'ǖ', 'Ǘ', 'ǘ', 'Ǚ', 'ǚ', 'Ǜ', 'ǜ', 'Ǻ', 'ǻ', 'Ǽ', 'ǽ', 'Ǿ', 'ǿ');\n * $b = array('A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o');\n */", "$", "rule", "=", "'Any-Latin; Latin-ASCII;'", ";", "$", "transliterator", "=", "\\", "Transliterator", "::", "create", "(", "$", "rule", ")", ";", "return", "$", "transliterator", "->", "transliterate", "(", "$", "str", ")", ";", "}" ]
Transliterate special characters to LATIN characters @param string $str @return string
[ "Transliterate", "special", "characters", "to", "LATIN", "characters" ]
14bfd67f3b237fcb9d29dfc313b25f32d37506e6
https://github.com/atompulse/data/blob/14bfd67f3b237fcb9d29dfc313b25f32d37506e6/Transform.php#L61-L72
1,937
atompulse/data
Transform.php
Transform.getControllerName
public static function getControllerName($qualifiedControllerName) { $nsComponents = explode('\\', $qualifiedControllerName); $ctrlName = str_replace('Controller', '', end($nsComponents)); return $ctrlName; }
php
public static function getControllerName($qualifiedControllerName) { $nsComponents = explode('\\', $qualifiedControllerName); $ctrlName = str_replace('Controller', '', end($nsComponents)); return $ctrlName; }
[ "public", "static", "function", "getControllerName", "(", "$", "qualifiedControllerName", ")", "{", "$", "nsComponents", "=", "explode", "(", "'\\\\'", ",", "$", "qualifiedControllerName", ")", ";", "$", "ctrlName", "=", "str_replace", "(", "'Controller'", ",", "''", ",", "end", "(", "$", "nsComponents", ")", ")", ";", "return", "$", "ctrlName", ";", "}" ]
Get the controller name from a full qualified class name @param $qualifiedControllerName @return mixed
[ "Get", "the", "controller", "name", "from", "a", "full", "qualified", "class", "name" ]
14bfd67f3b237fcb9d29dfc313b25f32d37506e6
https://github.com/atompulse/data/blob/14bfd67f3b237fcb9d29dfc313b25f32d37506e6/Transform.php#L79-L85
1,938
atompulse/data
Transform.php
Transform.csvFileToArray
public static function csvFileToArray($filename='', $delimiter=',') { $header = null; $data = []; if (($handle = fopen($filename, 'r')) !== false) { while (($row = fgetcsv($handle, 1000, $delimiter)) !== false) { if (!$header) { $header = $row; } else { $data[] = array_combine($header, $row); } } fclose($handle); } return $data; }
php
public static function csvFileToArray($filename='', $delimiter=',') { $header = null; $data = []; if (($handle = fopen($filename, 'r')) !== false) { while (($row = fgetcsv($handle, 1000, $delimiter)) !== false) { if (!$header) { $header = $row; } else { $data[] = array_combine($header, $row); } } fclose($handle); } return $data; }
[ "public", "static", "function", "csvFileToArray", "(", "$", "filename", "=", "''", ",", "$", "delimiter", "=", "','", ")", "{", "$", "header", "=", "null", ";", "$", "data", "=", "[", "]", ";", "if", "(", "(", "$", "handle", "=", "fopen", "(", "$", "filename", ",", "'r'", ")", ")", "!==", "false", ")", "{", "while", "(", "(", "$", "row", "=", "fgetcsv", "(", "$", "handle", ",", "1000", ",", "$", "delimiter", ")", ")", "!==", "false", ")", "{", "if", "(", "!", "$", "header", ")", "{", "$", "header", "=", "$", "row", ";", "}", "else", "{", "$", "data", "[", "]", "=", "array_combine", "(", "$", "header", ",", "$", "row", ")", ";", "}", "}", "fclose", "(", "$", "handle", ")", ";", "}", "return", "$", "data", ";", "}" ]
Transform csv file into array data @param string $filename @param string $delimiter @return array
[ "Transform", "csv", "file", "into", "array", "data" ]
14bfd67f3b237fcb9d29dfc313b25f32d37506e6
https://github.com/atompulse/data/blob/14bfd67f3b237fcb9d29dfc313b25f32d37506e6/Transform.php#L422-L438
1,939
atompulse/data
Transform.php
Transform.csvFileToArrayGenerator
public static function csvFileToArrayGenerator(string $filename = '', string $delimiter = ',') { $complete = false; try { $header = null; if (($handle = fopen($filename, 'r')) !== false) { while (($row = fgetcsv($handle, 4096, $delimiter)) !== false) { if (!$header) { $header = $row; } else { yield array_combine($header, $row); } } } $complete = true; } finally { if (!$complete) { // cleanup when loop breaks } else { // cleanup when loop completes } } // Do something only after loop completes }
php
public static function csvFileToArrayGenerator(string $filename = '', string $delimiter = ',') { $complete = false; try { $header = null; if (($handle = fopen($filename, 'r')) !== false) { while (($row = fgetcsv($handle, 4096, $delimiter)) !== false) { if (!$header) { $header = $row; } else { yield array_combine($header, $row); } } } $complete = true; } finally { if (!$complete) { // cleanup when loop breaks } else { // cleanup when loop completes } } // Do something only after loop completes }
[ "public", "static", "function", "csvFileToArrayGenerator", "(", "string", "$", "filename", "=", "''", ",", "string", "$", "delimiter", "=", "','", ")", "{", "$", "complete", "=", "false", ";", "try", "{", "$", "header", "=", "null", ";", "if", "(", "(", "$", "handle", "=", "fopen", "(", "$", "filename", ",", "'r'", ")", ")", "!==", "false", ")", "{", "while", "(", "(", "$", "row", "=", "fgetcsv", "(", "$", "handle", ",", "4096", ",", "$", "delimiter", ")", ")", "!==", "false", ")", "{", "if", "(", "!", "$", "header", ")", "{", "$", "header", "=", "$", "row", ";", "}", "else", "{", "yield", "array_combine", "(", "$", "header", ",", "$", "row", ")", ";", "}", "}", "}", "$", "complete", "=", "true", ";", "}", "finally", "{", "if", "(", "!", "$", "complete", ")", "{", "// cleanup when loop breaks", "}", "else", "{", "// cleanup when loop completes", "}", "}", "// Do something only after loop completes", "}" ]
Read a csv using a generator in order to avoid memory issues @param string $filename @param string $delimiter @return \Generator
[ "Read", "a", "csv", "using", "a", "generator", "in", "order", "to", "avoid", "memory", "issues" ]
14bfd67f3b237fcb9d29dfc313b25f32d37506e6
https://github.com/atompulse/data/blob/14bfd67f3b237fcb9d29dfc313b25f32d37506e6/Transform.php#L446-L469
1,940
atompulse/data
Transform.php
Transform.arrayToCsvFile
public static function arrayToCsvFile($filename, $data) { $fp = fopen($filename, 'w'); foreach ($data as $fields) { fputcsv($fp, $fields); } fclose($fp); }
php
public static function arrayToCsvFile($filename, $data) { $fp = fopen($filename, 'w'); foreach ($data as $fields) { fputcsv($fp, $fields); } fclose($fp); }
[ "public", "static", "function", "arrayToCsvFile", "(", "$", "filename", ",", "$", "data", ")", "{", "$", "fp", "=", "fopen", "(", "$", "filename", ",", "'w'", ")", ";", "foreach", "(", "$", "data", "as", "$", "fields", ")", "{", "fputcsv", "(", "$", "fp", ",", "$", "fields", ")", ";", "}", "fclose", "(", "$", "fp", ")", ";", "}" ]
Transform array data to csv file @param $filename @param $data
[ "Transform", "array", "data", "to", "csv", "file" ]
14bfd67f3b237fcb9d29dfc313b25f32d37506e6
https://github.com/atompulse/data/blob/14bfd67f3b237fcb9d29dfc313b25f32d37506e6/Transform.php#L476-L485
1,941
atompulse/data
Transform.php
Transform.shortenAndCapitalize
public static function shortenAndCapitalize($string) { $result = ''; $parts = explode(' ', trim($string)); foreach ($parts as $part) { $result = $result.strtoupper(mb_substr($part, 0, 1)); } return $result; }
php
public static function shortenAndCapitalize($string) { $result = ''; $parts = explode(' ', trim($string)); foreach ($parts as $part) { $result = $result.strtoupper(mb_substr($part, 0, 1)); } return $result; }
[ "public", "static", "function", "shortenAndCapitalize", "(", "$", "string", ")", "{", "$", "result", "=", "''", ";", "$", "parts", "=", "explode", "(", "' '", ",", "trim", "(", "$", "string", ")", ")", ";", "foreach", "(", "$", "parts", "as", "$", "part", ")", "{", "$", "result", "=", "$", "result", ".", "strtoupper", "(", "mb_substr", "(", "$", "part", ",", "0", ",", "1", ")", ")", ";", "}", "return", "$", "result", ";", "}" ]
Shorten a string ant transform into capitals 'john van helsing' will be JVH @param $string $string @return string
[ "Shorten", "a", "string", "ant", "transform", "into", "capitals", "john", "van", "helsing", "will", "be", "JVH" ]
14bfd67f3b237fcb9d29dfc313b25f32d37506e6
https://github.com/atompulse/data/blob/14bfd67f3b237fcb9d29dfc313b25f32d37506e6/Transform.php#L492-L502
1,942
lucidphp/mux
src/RouteCollectionBuilder.php
RouteCollectionBuilder.get
public function get($pattern, $handler, array $requirements = [], array $defaults = []) { $this->addRoute('GET', $pattern, $handler, $requirements, $defaults); }
php
public function get($pattern, $handler, array $requirements = [], array $defaults = []) { $this->addRoute('GET', $pattern, $handler, $requirements, $defaults); }
[ "public", "function", "get", "(", "$", "pattern", ",", "$", "handler", ",", "array", "$", "requirements", "=", "[", "]", ",", "array", "$", "defaults", "=", "[", "]", ")", "{", "$", "this", "->", "addRoute", "(", "'GET'", ",", "$", "pattern", ",", "$", "handler", ",", "$", "requirements", ",", "$", "defaults", ")", ";", "}" ]
Adds a GET route to the collection. @param string $pattern @param string $handler @param array $requirements @param array $defaults @return void
[ "Adds", "a", "GET", "route", "to", "the", "collection", "." ]
2d054ea01450bdad6a4af8198ca6f10705e1c327
https://github.com/lucidphp/mux/blob/2d054ea01450bdad6a4af8198ca6f10705e1c327/src/RouteCollectionBuilder.php#L73-L76
1,943
lucidphp/mux
src/RouteCollectionBuilder.php
RouteCollectionBuilder.head
public function head($pattern, $handler, array $requirements = [], array $defaults = []) { $this->addRoute('HEAD', $pattern, $handler, $requirements, $defaults); }
php
public function head($pattern, $handler, array $requirements = [], array $defaults = []) { $this->addRoute('HEAD', $pattern, $handler, $requirements, $defaults); }
[ "public", "function", "head", "(", "$", "pattern", ",", "$", "handler", ",", "array", "$", "requirements", "=", "[", "]", ",", "array", "$", "defaults", "=", "[", "]", ")", "{", "$", "this", "->", "addRoute", "(", "'HEAD'", ",", "$", "pattern", ",", "$", "handler", ",", "$", "requirements", ",", "$", "defaults", ")", ";", "}" ]
Adds a HEAD route to the collection @see RouteCollectionBuilder#get()
[ "Adds", "a", "HEAD", "route", "to", "the", "collection" ]
2d054ea01450bdad6a4af8198ca6f10705e1c327
https://github.com/lucidphp/mux/blob/2d054ea01450bdad6a4af8198ca6f10705e1c327/src/RouteCollectionBuilder.php#L83-L86
1,944
lucidphp/mux
src/RouteCollectionBuilder.php
RouteCollectionBuilder.patch
public function patch($pattern, $handler, array $requirements = [], array $defaults = []) { $this->addRoute('PATCH', $pattern, $handler, $requirements, $defaults); }
php
public function patch($pattern, $handler, array $requirements = [], array $defaults = []) { $this->addRoute('PATCH', $pattern, $handler, $requirements, $defaults); }
[ "public", "function", "patch", "(", "$", "pattern", ",", "$", "handler", ",", "array", "$", "requirements", "=", "[", "]", ",", "array", "$", "defaults", "=", "[", "]", ")", "{", "$", "this", "->", "addRoute", "(", "'PATCH'", ",", "$", "pattern", ",", "$", "handler", ",", "$", "requirements", ",", "$", "defaults", ")", ";", "}" ]
Adds a PATCH route to the collection @see RouteCollectionBuilder#get()
[ "Adds", "a", "PATCH", "route", "to", "the", "collection" ]
2d054ea01450bdad6a4af8198ca6f10705e1c327
https://github.com/lucidphp/mux/blob/2d054ea01450bdad6a4af8198ca6f10705e1c327/src/RouteCollectionBuilder.php#L113-L116
1,945
lucidphp/mux
src/RouteCollectionBuilder.php
RouteCollectionBuilder.any
public function any($pattern, $handler, array $requirements = [], array $defaults = []) { $this->addRoute('GET|HEAD|POST|PUT|PATCH|DELETE', $pattern, $handler, $requirements, $defaults); }
php
public function any($pattern, $handler, array $requirements = [], array $defaults = []) { $this->addRoute('GET|HEAD|POST|PUT|PATCH|DELETE', $pattern, $handler, $requirements, $defaults); }
[ "public", "function", "any", "(", "$", "pattern", ",", "$", "handler", ",", "array", "$", "requirements", "=", "[", "]", ",", "array", "$", "defaults", "=", "[", "]", ")", "{", "$", "this", "->", "addRoute", "(", "'GET|HEAD|POST|PUT|PATCH|DELETE'", ",", "$", "pattern", ",", "$", "handler", ",", "$", "requirements", ",", "$", "defaults", ")", ";", "}" ]
Adds a route to the collection that handles all available request methods. @see RouteCollectionBuilder#get()
[ "Adds", "a", "route", "to", "the", "collection", "that", "handles", "all", "available", "request", "methods", "." ]
2d054ea01450bdad6a4af8198ca6f10705e1c327
https://github.com/lucidphp/mux/blob/2d054ea01450bdad6a4af8198ca6f10705e1c327/src/RouteCollectionBuilder.php#L134-L137
1,946
lucidphp/mux
src/RouteCollectionBuilder.php
RouteCollectionBuilder.addRoute
public function addRoute($methods, $pattern, $handler, array $requirements = [], array $defaults = []) { list ($name, $host, $schemes, $constraints) = $this->parseRequirements( $this->extendRequirements($requirements), $methods ); $route = new Route( $this->prefixPattern($pattern), $handler, is_array($methods) ? $methods : explode('|', $methods), $host, $defaults, $constraints, is_array($schemes) ? $schemes : explode('|', $schemes) ); $this->routes->add($name, $route); }
php
public function addRoute($methods, $pattern, $handler, array $requirements = [], array $defaults = []) { list ($name, $host, $schemes, $constraints) = $this->parseRequirements( $this->extendRequirements($requirements), $methods ); $route = new Route( $this->prefixPattern($pattern), $handler, is_array($methods) ? $methods : explode('|', $methods), $host, $defaults, $constraints, is_array($schemes) ? $schemes : explode('|', $schemes) ); $this->routes->add($name, $route); }
[ "public", "function", "addRoute", "(", "$", "methods", ",", "$", "pattern", ",", "$", "handler", ",", "array", "$", "requirements", "=", "[", "]", ",", "array", "$", "defaults", "=", "[", "]", ")", "{", "list", "(", "$", "name", ",", "$", "host", ",", "$", "schemes", ",", "$", "constraints", ")", "=", "$", "this", "->", "parseRequirements", "(", "$", "this", "->", "extendRequirements", "(", "$", "requirements", ")", ",", "$", "methods", ")", ";", "$", "route", "=", "new", "Route", "(", "$", "this", "->", "prefixPattern", "(", "$", "pattern", ")", ",", "$", "handler", ",", "is_array", "(", "$", "methods", ")", "?", "$", "methods", ":", "explode", "(", "'|'", ",", "$", "methods", ")", ",", "$", "host", ",", "$", "defaults", ",", "$", "constraints", ",", "is_array", "(", "$", "schemes", ")", "?", "$", "schemes", ":", "explode", "(", "'|'", ",", "$", "schemes", ")", ")", ";", "$", "this", "->", "routes", "->", "add", "(", "$", "name", ",", "$", "route", ")", ";", "}" ]
Adds a route to the collection that handles the given request methods. @param string $methods methods seperated by a pipe |. @param string $pattern @param string $handler @param array $requirements @param array $defaults @return void
[ "Adds", "a", "route", "to", "the", "collection", "that", "handles", "the", "given", "request", "methods", "." ]
2d054ea01450bdad6a4af8198ca6f10705e1c327
https://github.com/lucidphp/mux/blob/2d054ea01450bdad6a4af8198ca6f10705e1c327/src/RouteCollectionBuilder.php#L151-L169
1,947
lucidphp/mux
src/RouteCollectionBuilder.php
RouteCollectionBuilder.group
public function group($prefix, array $requirements = [], callable $groupConstructor = null) { $this->enterGroup($prefix, $requirements); if (null !== $groupConstructor) { call_user_func($groupConstructor, $this); $this->leaveGroup(); } }
php
public function group($prefix, array $requirements = [], callable $groupConstructor = null) { $this->enterGroup($prefix, $requirements); if (null !== $groupConstructor) { call_user_func($groupConstructor, $this); $this->leaveGroup(); } }
[ "public", "function", "group", "(", "$", "prefix", ",", "array", "$", "requirements", "=", "[", "]", ",", "callable", "$", "groupConstructor", "=", "null", ")", "{", "$", "this", "->", "enterGroup", "(", "$", "prefix", ",", "$", "requirements", ")", ";", "if", "(", "null", "!==", "$", "groupConstructor", ")", "{", "call_user_func", "(", "$", "groupConstructor", ",", "$", "this", ")", ";", "$", "this", "->", "leaveGroup", "(", ")", ";", "}", "}" ]
Starts a new entry point for grouping routes. @param string $prefix @param array $requirements @return void
[ "Starts", "a", "new", "entry", "point", "for", "grouping", "routes", "." ]
2d054ea01450bdad6a4af8198ca6f10705e1c327
https://github.com/lucidphp/mux/blob/2d054ea01450bdad6a4af8198ca6f10705e1c327/src/RouteCollectionBuilder.php#L179-L187
1,948
tekreme73/FrametekLight
src/Persistent/Config.php
Config.load
protected function load($parentDirectory) { while (false !== ($entry = $parentDirectory->read())) { if ($entry !== '.' && $entry !== '..') { if (is_dir($entry)) { $tmpD = dir($entry); $this->load($tmpD); $tmpD->close(); } else if (substr($entry, - strlen('.php')) === '.php') { $this[substr($entry, 0, - strlen('.php'))] = include $this->getPath() . $entry; } } } }
php
protected function load($parentDirectory) { while (false !== ($entry = $parentDirectory->read())) { if ($entry !== '.' && $entry !== '..') { if (is_dir($entry)) { $tmpD = dir($entry); $this->load($tmpD); $tmpD->close(); } else if (substr($entry, - strlen('.php')) === '.php') { $this[substr($entry, 0, - strlen('.php'))] = include $this->getPath() . $entry; } } } }
[ "protected", "function", "load", "(", "$", "parentDirectory", ")", "{", "while", "(", "false", "!==", "(", "$", "entry", "=", "$", "parentDirectory", "->", "read", "(", ")", ")", ")", "{", "if", "(", "$", "entry", "!==", "'.'", "&&", "$", "entry", "!==", "'..'", ")", "{", "if", "(", "is_dir", "(", "$", "entry", ")", ")", "{", "$", "tmpD", "=", "dir", "(", "$", "entry", ")", ";", "$", "this", "->", "load", "(", "$", "tmpD", ")", ";", "$", "tmpD", "->", "close", "(", ")", ";", "}", "else", "if", "(", "substr", "(", "$", "entry", ",", "-", "strlen", "(", "'.php'", ")", ")", "===", "'.php'", ")", "{", "$", "this", "[", "substr", "(", "$", "entry", ",", "0", ",", "-", "strlen", "(", "'.php'", ")", ")", "]", "=", "include", "$", "this", "->", "getPath", "(", ")", ".", "$", "entry", ";", "}", "}", "}", "}" ]
Load item from configs Warn: Recursive function @param \Directory $parentDirectory The parent directory
[ "Load", "item", "from", "configs" ]
7a40e8dd14490488d80741d6a6fe5d9c2bcc7bd5
https://github.com/tekreme73/FrametekLight/blob/7a40e8dd14490488d80741d6a6fe5d9c2bcc7bd5/src/Persistent/Config.php#L64-L78
1,949
tekreme73/FrametekLight
src/Persistent/Config.php
Config.loadAll
public function loadAll() { $this->setAll(array()); $d = dir($this->getPath()); $this->load($d); $d->close(); }
php
public function loadAll() { $this->setAll(array()); $d = dir($this->getPath()); $this->load($d); $d->close(); }
[ "public", "function", "loadAll", "(", ")", "{", "$", "this", "->", "setAll", "(", "array", "(", ")", ")", ";", "$", "d", "=", "dir", "(", "$", "this", "->", "getPath", "(", ")", ")", ";", "$", "this", "->", "load", "(", "$", "d", ")", ";", "$", "d", "->", "close", "(", ")", ";", "}" ]
Load all configuration files to be available
[ "Load", "all", "configuration", "files", "to", "be", "available" ]
7a40e8dd14490488d80741d6a6fe5d9c2bcc7bd5
https://github.com/tekreme73/FrametekLight/blob/7a40e8dd14490488d80741d6a6fe5d9c2bcc7bd5/src/Persistent/Config.php#L136-L142
1,950
Sowapps/orpheus-inputcontroller
src/InputController/HTTPController/LocalFileHTTPResponse.php
LocalFileHTTPResponse.getMimetypeFromLocalFilePath
protected static function getMimetypeFromLocalFilePath($filePath) { $mimetype = getMimeType($filePath); if( $mimetype !== 'text/plain' ) { return $mimetype; } return static::getMimetypeFromExtension(pathinfo($filePath, PATHINFO_EXTENSION)); }
php
protected static function getMimetypeFromLocalFilePath($filePath) { $mimetype = getMimeType($filePath); if( $mimetype !== 'text/plain' ) { return $mimetype; } return static::getMimetypeFromExtension(pathinfo($filePath, PATHINFO_EXTENSION)); }
[ "protected", "static", "function", "getMimetypeFromLocalFilePath", "(", "$", "filePath", ")", "{", "$", "mimetype", "=", "getMimeType", "(", "$", "filePath", ")", ";", "if", "(", "$", "mimetype", "!==", "'text/plain'", ")", "{", "return", "$", "mimetype", ";", "}", "return", "static", "::", "getMimetypeFromExtension", "(", "pathinfo", "(", "$", "filePath", ",", "PATHINFO_EXTENSION", ")", ")", ";", "}" ]
Get mimetype from local file path @param string $filePath @return string
[ "Get", "mimetype", "from", "local", "file", "path" ]
91f848a42ac02ae4009ffb3e9a9b4e8c0731455e
https://github.com/Sowapps/orpheus-inputcontroller/blob/91f848a42ac02ae4009ffb3e9a9b4e8c0731455e/src/InputController/HTTPController/LocalFileHTTPResponse.php#L111-L117
1,951
phpzm/data
src/Record.php
Record.parse
public static function parse($record): Record { if ($record instanceof Record) { return $record; } if ($record instanceof stdClass) { $record = (array)$record; } if (is_array($record)) { return static::make($record); } $type = gettype($record); if ($type === TYPE_OBJECT) { $type = get_class($type); } throw new SimplesRunTimeError("Record must be an array or instanceof Record '{$type}' given"); }
php
public static function parse($record): Record { if ($record instanceof Record) { return $record; } if ($record instanceof stdClass) { $record = (array)$record; } if (is_array($record)) { return static::make($record); } $type = gettype($record); if ($type === TYPE_OBJECT) { $type = get_class($type); } throw new SimplesRunTimeError("Record must be an array or instanceof Record '{$type}' given"); }
[ "public", "static", "function", "parse", "(", "$", "record", ")", ":", "Record", "{", "if", "(", "$", "record", "instanceof", "Record", ")", "{", "return", "$", "record", ";", "}", "if", "(", "$", "record", "instanceof", "stdClass", ")", "{", "$", "record", "=", "(", "array", ")", "$", "record", ";", "}", "if", "(", "is_array", "(", "$", "record", ")", ")", "{", "return", "static", "::", "make", "(", "$", "record", ")", ";", "}", "$", "type", "=", "gettype", "(", "$", "record", ")", ";", "if", "(", "$", "type", "===", "TYPE_OBJECT", ")", "{", "$", "type", "=", "get_class", "(", "$", "type", ")", ";", "}", "throw", "new", "SimplesRunTimeError", "(", "\"Record must be an array or instanceof Record '{$type}' given\"", ")", ";", "}" ]
Convert data into a Record instance @param $record @return Record @throws SimplesRunTimeError
[ "Convert", "data", "into", "a", "Record", "instance" ]
9b4891bc86a9a716466f7f300f3a769b5e42e812
https://github.com/phpzm/data/blob/9b4891bc86a9a716466f7f300f3a769b5e42e812/src/Record.php#L90-L106
1,952
phpzm/data
src/Record.php
Record.set
public function set(string $name, $value): Record { if (!$this->isEditable()) { throw new SimplesRecordReadonlyError(['set' => [$name => $value]]); } $this->public[$name] = $value; return $this; }
php
public function set(string $name, $value): Record { if (!$this->isEditable()) { throw new SimplesRecordReadonlyError(['set' => [$name => $value]]); } $this->public[$name] = $value; return $this; }
[ "public", "function", "set", "(", "string", "$", "name", ",", "$", "value", ")", ":", "Record", "{", "if", "(", "!", "$", "this", "->", "isEditable", "(", ")", ")", "{", "throw", "new", "SimplesRecordReadonlyError", "(", "[", "'set'", "=>", "[", "$", "name", "=>", "$", "value", "]", "]", ")", ";", "}", "$", "this", "->", "public", "[", "$", "name", "]", "=", "$", "value", ";", "return", "$", "this", ";", "}" ]
Set a value of the Record @param string $name @param mixed $value @return Record @throws SimplesRunTimeError
[ "Set", "a", "value", "of", "the", "Record" ]
9b4891bc86a9a716466f7f300f3a769b5e42e812
https://github.com/phpzm/data/blob/9b4891bc86a9a716466f7f300f3a769b5e42e812/src/Record.php#L151-L158
1,953
phpzm/data
src/Record.php
Record.copy
public function copy(string $target, string $source, bool $override = false) { if (is_null($this->get($target)) || $override) { $this->set($target, $this->get($source)); } return $this; }
php
public function copy(string $target, string $source, bool $override = false) { if (is_null($this->get($target)) || $override) { $this->set($target, $this->get($source)); } return $this; }
[ "public", "function", "copy", "(", "string", "$", "target", ",", "string", "$", "source", ",", "bool", "$", "override", "=", "false", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "get", "(", "$", "target", ")", ")", "||", "$", "override", ")", "{", "$", "this", "->", "set", "(", "$", "target", ",", "$", "this", "->", "get", "(", "$", "source", ")", ")", ";", "}", "return", "$", "this", ";", "}" ]
Copy the value of one index to another @param string $target @param string $source @param bool $override (true) @return $this @throws SimplesRunTimeError
[ "Copy", "the", "value", "of", "one", "index", "to", "another" ]
9b4891bc86a9a716466f7f300f3a769b5e42e812
https://github.com/phpzm/data/blob/9b4891bc86a9a716466f7f300f3a769b5e42e812/src/Record.php#L169-L175
1,954
phpzm/data
src/Record.php
Record.remove
public function remove(string $name): Record { if (!$this->isEditable()) { throw new SimplesRecordReadonlyError(['remove' => $name]); } unset($this->public[$name]); return $this; }
php
public function remove(string $name): Record { if (!$this->isEditable()) { throw new SimplesRecordReadonlyError(['remove' => $name]); } unset($this->public[$name]); return $this; }
[ "public", "function", "remove", "(", "string", "$", "name", ")", ":", "Record", "{", "if", "(", "!", "$", "this", "->", "isEditable", "(", ")", ")", "{", "throw", "new", "SimplesRecordReadonlyError", "(", "[", "'remove'", "=>", "$", "name", "]", ")", ";", "}", "unset", "(", "$", "this", "->", "public", "[", "$", "name", "]", ")", ";", "return", "$", "this", ";", "}" ]
Remove a key and associated value of the Record @param string $name @return Record @throws SimplesRecordReadonlyError
[ "Remove", "a", "key", "and", "associated", "value", "of", "the", "Record" ]
9b4891bc86a9a716466f7f300f3a769b5e42e812
https://github.com/phpzm/data/blob/9b4891bc86a9a716466f7f300f3a769b5e42e812/src/Record.php#L183-L190
1,955
phpzm/data
src/Record.php
Record.setPrivate
public function setPrivate(string $name): Record { if ($this->indexOf($name)) { $this->private[$name] = $this->public[$name]; unset($this->public[$name]); } return $this; }
php
public function setPrivate(string $name): Record { if ($this->indexOf($name)) { $this->private[$name] = $this->public[$name]; unset($this->public[$name]); } return $this; }
[ "public", "function", "setPrivate", "(", "string", "$", "name", ")", ":", "Record", "{", "if", "(", "$", "this", "->", "indexOf", "(", "$", "name", ")", ")", "{", "$", "this", "->", "private", "[", "$", "name", "]", "=", "$", "this", "->", "public", "[", "$", "name", "]", ";", "unset", "(", "$", "this", "->", "public", "[", "$", "name", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Make a property hidden @param string $name @return Record
[ "Make", "a", "property", "hidden" ]
9b4891bc86a9a716466f7f300f3a769b5e42e812
https://github.com/phpzm/data/blob/9b4891bc86a9a716466f7f300f3a769b5e42e812/src/Record.php#L197-L204
1,956
phpzm/data
src/Record.php
Record.setPublic
public function setPublic(string $name): Record { if ($this->indexOf($name, false)) { $this->public[$name] = $this->private[$name]; unset($this->private[$name]); } return $this; }
php
public function setPublic(string $name): Record { if ($this->indexOf($name, false)) { $this->public[$name] = $this->private[$name]; unset($this->private[$name]); } return $this; }
[ "public", "function", "setPublic", "(", "string", "$", "name", ")", ":", "Record", "{", "if", "(", "$", "this", "->", "indexOf", "(", "$", "name", ",", "false", ")", ")", "{", "$", "this", "->", "public", "[", "$", "name", "]", "=", "$", "this", "->", "private", "[", "$", "name", "]", ";", "unset", "(", "$", "this", "->", "private", "[", "$", "name", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Make a property be public @param string $name @return Record
[ "Make", "a", "property", "be", "public" ]
9b4891bc86a9a716466f7f300f3a769b5e42e812
https://github.com/phpzm/data/blob/9b4891bc86a9a716466f7f300f3a769b5e42e812/src/Record.php#L211-L218
1,957
phpzm/data
src/Record.php
Record.merge
public function merge(array $public, array $private = []): Record { $public = array_merge($this->public, $public); $private = array_merge($this->private, $private); if ($this->isEditable()) { $this->public = $public; $this->private = $private; return $this; } return static::make($public, $this->isEditable(), $this->mutations, $this->private); }
php
public function merge(array $public, array $private = []): Record { $public = array_merge($this->public, $public); $private = array_merge($this->private, $private); if ($this->isEditable()) { $this->public = $public; $this->private = $private; return $this; } return static::make($public, $this->isEditable(), $this->mutations, $this->private); }
[ "public", "function", "merge", "(", "array", "$", "public", ",", "array", "$", "private", "=", "[", "]", ")", ":", "Record", "{", "$", "public", "=", "array_merge", "(", "$", "this", "->", "public", ",", "$", "public", ")", ";", "$", "private", "=", "array_merge", "(", "$", "this", "->", "private", ",", "$", "private", ")", ";", "if", "(", "$", "this", "->", "isEditable", "(", ")", ")", "{", "$", "this", "->", "public", "=", "$", "public", ";", "$", "this", "->", "private", "=", "$", "private", ";", "return", "$", "this", ";", "}", "return", "static", "::", "make", "(", "$", "public", ",", "$", "this", "->", "isEditable", "(", ")", ",", "$", "this", "->", "mutations", ",", "$", "this", "->", "private", ")", ";", "}" ]
This method merge an array of data to record overriding the previously value of the keys @param array $public @param array $private @return Record
[ "This", "method", "merge", "an", "array", "of", "data", "to", "record", "overriding", "the", "previously", "value", "of", "the", "keys" ]
9b4891bc86a9a716466f7f300f3a769b5e42e812
https://github.com/phpzm/data/blob/9b4891bc86a9a716466f7f300f3a769b5e42e812/src/Record.php#L227-L237
1,958
phpzm/data
src/Record.php
Record.import
public function import(array $public, array $private = []): Record { $public = array_merge($public, $this->public); $private = array_merge($private, $this->private); if ($this->isEditable()) { $this->public = $public; $this->private = $private; return $this; } return static::make($public, $this->isEditable(), $this->mutations, $this->private); }
php
public function import(array $public, array $private = []): Record { $public = array_merge($public, $this->public); $private = array_merge($private, $this->private); if ($this->isEditable()) { $this->public = $public; $this->private = $private; return $this; } return static::make($public, $this->isEditable(), $this->mutations, $this->private); }
[ "public", "function", "import", "(", "array", "$", "public", ",", "array", "$", "private", "=", "[", "]", ")", ":", "Record", "{", "$", "public", "=", "array_merge", "(", "$", "public", ",", "$", "this", "->", "public", ")", ";", "$", "private", "=", "array_merge", "(", "$", "private", ",", "$", "this", "->", "private", ")", ";", "if", "(", "$", "this", "->", "isEditable", "(", ")", ")", "{", "$", "this", "->", "public", "=", "$", "public", ";", "$", "this", "->", "private", "=", "$", "private", ";", "return", "$", "this", ";", "}", "return", "static", "::", "make", "(", "$", "public", ",", "$", "this", "->", "isEditable", "(", ")", ",", "$", "this", "->", "mutations", ",", "$", "this", "->", "private", ")", ";", "}" ]
This method import an array of data to record keeping the previously value of the keys @param array $public @param array $private @return Record
[ "This", "method", "import", "an", "array", "of", "data", "to", "record", "keeping", "the", "previously", "value", "of", "the", "keys" ]
9b4891bc86a9a716466f7f300f3a769b5e42e812
https://github.com/phpzm/data/blob/9b4891bc86a9a716466f7f300f3a769b5e42e812/src/Record.php#L246-L256
1,959
phpzm/data
src/Record.php
Record.update
public function update(array $public, array $private = []): Record { if ($this->isEditable()) { $this->public = $public; if (count($private)) { $this->private = $private; } return $this; } return static::make($public, $this->isEditable(), $this->mutations, $this->private); }
php
public function update(array $public, array $private = []): Record { if ($this->isEditable()) { $this->public = $public; if (count($private)) { $this->private = $private; } return $this; } return static::make($public, $this->isEditable(), $this->mutations, $this->private); }
[ "public", "function", "update", "(", "array", "$", "public", ",", "array", "$", "private", "=", "[", "]", ")", ":", "Record", "{", "if", "(", "$", "this", "->", "isEditable", "(", ")", ")", "{", "$", "this", "->", "public", "=", "$", "public", ";", "if", "(", "count", "(", "$", "private", ")", ")", "{", "$", "this", "->", "private", "=", "$", "private", ";", "}", "return", "$", "this", ";", "}", "return", "static", "::", "make", "(", "$", "public", ",", "$", "this", "->", "isEditable", "(", ")", ",", "$", "this", "->", "mutations", ",", "$", "this", "->", "private", ")", ";", "}" ]
Update all data in Record @param array $public @param array $private @return Record
[ "Update", "all", "data", "in", "Record" ]
9b4891bc86a9a716466f7f300f3a769b5e42e812
https://github.com/phpzm/data/blob/9b4891bc86a9a716466f7f300f3a769b5e42e812/src/Record.php#L265-L275
1,960
phpzm/data
src/Record.php
Record.indexOf
public function indexOf(string $name, bool $public = true) { if ($public) { return isset($this->public[$name]); } return isset($this->private[$name]); }
php
public function indexOf(string $name, bool $public = true) { if ($public) { return isset($this->public[$name]); } return isset($this->private[$name]); }
[ "public", "function", "indexOf", "(", "string", "$", "name", ",", "bool", "$", "public", "=", "true", ")", "{", "if", "(", "$", "public", ")", "{", "return", "isset", "(", "$", "this", "->", "public", "[", "$", "name", "]", ")", ";", "}", "return", "isset", "(", "$", "this", "->", "private", "[", "$", "name", "]", ")", ";", "}" ]
Check is exists a property into Record @param string $name @param bool $public @return bool
[ "Check", "is", "exists", "a", "property", "into", "Record" ]
9b4891bc86a9a716466f7f300f3a769b5e42e812
https://github.com/phpzm/data/blob/9b4891bc86a9a716466f7f300f3a769b5e42e812/src/Record.php#L341-L347
1,961
lemonphp/cli
src/Console/Command/Command.php
Command.getService
public function getService($name) { $container = $this->getContainer(); return !is_null($container) && isset($container[$name]) ? $container[$name] : null; }
php
public function getService($name) { $container = $this->getContainer(); return !is_null($container) && isset($container[$name]) ? $container[$name] : null; }
[ "public", "function", "getService", "(", "$", "name", ")", "{", "$", "container", "=", "$", "this", "->", "getContainer", "(", ")", ";", "return", "!", "is_null", "(", "$", "container", ")", "&&", "isset", "(", "$", "container", "[", "$", "name", "]", ")", "?", "$", "container", "[", "$", "name", "]", ":", "null", ";", "}" ]
Get service in container Returns a service contained in the application container or null if none is found with that name. @param string $name Name of service @return mixed
[ "Get", "service", "in", "container" ]
55b11789621f106ba33f6f6dec88d12ad953b625
https://github.com/lemonphp/cli/blob/55b11789621f106ba33f6f6dec88d12ad953b625/src/Console/Command/Command.php#L44-L49
1,962
strident/Trident
src/Trident/Module/FrameworkModule/Debug/Toolbar/Extension/TridentControllerExtension.php
TridentControllerExtension.collectControllerData
public function collectControllerData(FilterControllerEvent $event) { if (HttpKernelInterface::SUB_REQUEST === $event->getRequestType()) { return; } $controller = $this->getClassName($event->getController()[0]); $action = $event->getController()[1]; $this->setController($controller); $this->setAction($action); }
php
public function collectControllerData(FilterControllerEvent $event) { if (HttpKernelInterface::SUB_REQUEST === $event->getRequestType()) { return; } $controller = $this->getClassName($event->getController()[0]); $action = $event->getController()[1]; $this->setController($controller); $this->setAction($action); }
[ "public", "function", "collectControllerData", "(", "FilterControllerEvent", "$", "event", ")", "{", "if", "(", "HttpKernelInterface", "::", "SUB_REQUEST", "===", "$", "event", "->", "getRequestType", "(", ")", ")", "{", "return", ";", "}", "$", "controller", "=", "$", "this", "->", "getClassName", "(", "$", "event", "->", "getController", "(", ")", "[", "0", "]", ")", ";", "$", "action", "=", "$", "event", "->", "getController", "(", ")", "[", "1", "]", ";", "$", "this", "->", "setController", "(", "$", "controller", ")", ";", "$", "this", "->", "setAction", "(", "$", "action", ")", ";", "}" ]
Collect data from controller. @param FilterResponseEvent $event
[ "Collect", "data", "from", "controller", "." ]
a112f0b75601b897c470a49d85791dc386c29952
https://github.com/strident/Trident/blob/a112f0b75601b897c470a49d85791dc386c29952/src/Trident/Module/FrameworkModule/Debug/Toolbar/Extension/TridentControllerExtension.php#L142-L153
1,963
xmmedia/XMSecurityBundle
Controller/RegistrationConfirmationController.php
RegistrationConfirmationController.resendAction
public function resendAction(Request $request, User $user = null) { $currentUser = $this->getUser(); if (null === $user) { $user = $currentUser; if (!is_object($user) || !$user instanceof UserInterface) { throw new AccessDeniedException( 'This user does not have access to this section.' ); } } else if (!$this->isGranted('ROLE_SUPER_ADMIN')) { throw new AccessDeniedException( 'You cannot resend the confirmation for another user.' ); } $isCurrentUser = $user->getId() === $currentUser->getId(); // get the referer, if none redirect to the login // which should go to the default page after login $redirect = $request->headers->get( 'referer', $this->generateUrl('fos_user_security_login') ); if ($user->isEnabled()) { if ($isCurrentUser) { $this->addFlash('warning', 'Your account is already enabled.'); } else { $this->addFlash('warning', 'The user is already enabled.'); } return $this->redirect($redirect); } if (null === $user->getConfirmationToken()) { $user->setConfirmationToken( $this->get('fos_user.util.token_generator') ->generateToken() ); $this->get('fos_user.user_manager')->updateUser($user); } $this->get('fos_user.mailer')->sendConfirmationEmailMessage($user); if ($isCurrentUser) { $this->addFlash( 'success', 'Your account activation email has been resent.' ); } else { $this->addFlash( 'success', 'The account activation email has been resent.' ); } return $this->redirect($redirect); }
php
public function resendAction(Request $request, User $user = null) { $currentUser = $this->getUser(); if (null === $user) { $user = $currentUser; if (!is_object($user) || !$user instanceof UserInterface) { throw new AccessDeniedException( 'This user does not have access to this section.' ); } } else if (!$this->isGranted('ROLE_SUPER_ADMIN')) { throw new AccessDeniedException( 'You cannot resend the confirmation for another user.' ); } $isCurrentUser = $user->getId() === $currentUser->getId(); // get the referer, if none redirect to the login // which should go to the default page after login $redirect = $request->headers->get( 'referer', $this->generateUrl('fos_user_security_login') ); if ($user->isEnabled()) { if ($isCurrentUser) { $this->addFlash('warning', 'Your account is already enabled.'); } else { $this->addFlash('warning', 'The user is already enabled.'); } return $this->redirect($redirect); } if (null === $user->getConfirmationToken()) { $user->setConfirmationToken( $this->get('fos_user.util.token_generator') ->generateToken() ); $this->get('fos_user.user_manager')->updateUser($user); } $this->get('fos_user.mailer')->sendConfirmationEmailMessage($user); if ($isCurrentUser) { $this->addFlash( 'success', 'Your account activation email has been resent.' ); } else { $this->addFlash( 'success', 'The account activation email has been resent.' ); } return $this->redirect($redirect); }
[ "public", "function", "resendAction", "(", "Request", "$", "request", ",", "User", "$", "user", "=", "null", ")", "{", "$", "currentUser", "=", "$", "this", "->", "getUser", "(", ")", ";", "if", "(", "null", "===", "$", "user", ")", "{", "$", "user", "=", "$", "currentUser", ";", "if", "(", "!", "is_object", "(", "$", "user", ")", "||", "!", "$", "user", "instanceof", "UserInterface", ")", "{", "throw", "new", "AccessDeniedException", "(", "'This user does not have access to this section.'", ")", ";", "}", "}", "else", "if", "(", "!", "$", "this", "->", "isGranted", "(", "'ROLE_SUPER_ADMIN'", ")", ")", "{", "throw", "new", "AccessDeniedException", "(", "'You cannot resend the confirmation for another user.'", ")", ";", "}", "$", "isCurrentUser", "=", "$", "user", "->", "getId", "(", ")", "===", "$", "currentUser", "->", "getId", "(", ")", ";", "// get the referer, if none redirect to the login", "// which should go to the default page after login", "$", "redirect", "=", "$", "request", "->", "headers", "->", "get", "(", "'referer'", ",", "$", "this", "->", "generateUrl", "(", "'fos_user_security_login'", ")", ")", ";", "if", "(", "$", "user", "->", "isEnabled", "(", ")", ")", "{", "if", "(", "$", "isCurrentUser", ")", "{", "$", "this", "->", "addFlash", "(", "'warning'", ",", "'Your account is already enabled.'", ")", ";", "}", "else", "{", "$", "this", "->", "addFlash", "(", "'warning'", ",", "'The user is already enabled.'", ")", ";", "}", "return", "$", "this", "->", "redirect", "(", "$", "redirect", ")", ";", "}", "if", "(", "null", "===", "$", "user", "->", "getConfirmationToken", "(", ")", ")", "{", "$", "user", "->", "setConfirmationToken", "(", "$", "this", "->", "get", "(", "'fos_user.util.token_generator'", ")", "->", "generateToken", "(", ")", ")", ";", "$", "this", "->", "get", "(", "'fos_user.user_manager'", ")", "->", "updateUser", "(", "$", "user", ")", ";", "}", "$", "this", "->", "get", "(", "'fos_user.mailer'", ")", "->", "sendConfirmationEmailMessage", "(", "$", "user", ")", ";", "if", "(", "$", "isCurrentUser", ")", "{", "$", "this", "->", "addFlash", "(", "'success'", ",", "'Your account activation email has been resent.'", ")", ";", "}", "else", "{", "$", "this", "->", "addFlash", "(", "'success'", ",", "'The account activation email has been resent.'", ")", ";", "}", "return", "$", "this", "->", "redirect", "(", "$", "redirect", ")", ";", "}" ]
Resends the account activation link typically sent during registration. @param Request $request @param User|null $user @return Response
[ "Resends", "the", "account", "activation", "link", "typically", "sent", "during", "registration", "." ]
ee71a1bb4fe038e5a08e44f73247c4e03631a840
https://github.com/xmmedia/XMSecurityBundle/blob/ee71a1bb4fe038e5a08e44f73247c4e03631a840/Controller/RegistrationConfirmationController.php#L22-L81
1,964
droath/console-form
src/FormHelper.php
FormHelper.getFormByName
public function getFormByName($name, InputInterface $input, OutputInterface $output) { if (!isset($this->forms[$name])) { throw new \Exception( sprintf('Unable to find %s form.', $name) ); } return $this->createInstance($input, $output, $this->forms[$name]); }
php
public function getFormByName($name, InputInterface $input, OutputInterface $output) { if (!isset($this->forms[$name])) { throw new \Exception( sprintf('Unable to find %s form.', $name) ); } return $this->createInstance($input, $output, $this->forms[$name]); }
[ "public", "function", "getFormByName", "(", "$", "name", ",", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "forms", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "sprintf", "(", "'Unable to find %s form.'", ",", "$", "name", ")", ")", ";", "}", "return", "$", "this", "->", "createInstance", "(", "$", "input", ",", "$", "output", ",", "$", "this", "->", "forms", "[", "$", "name", "]", ")", ";", "}" ]
Get form by name. @param string $name The form name. @param \Symfony\Component\Console\Input\InputInterface $input The console input. @param \Symfony\Component\Console\Output\OutputInterface $output The console output. @return \Droath\ConsoleForm\Form The form instance.
[ "Get", "form", "by", "name", "." ]
0fb43fdebd1f685779c9fffea43a0dccd4ebe14a
https://github.com/droath/console-form/blob/0fb43fdebd1f685779c9fffea43a0dccd4ebe14a/src/FormHelper.php#L71-L80
1,965
droath/console-form
src/FormHelper.php
FormHelper.createInstance
protected function createInstance( InputInterface $input, OutputInterface $output, Form $form = null ) { if (!isset($form)) { $form = new Form(); } return $form ->setInput($input) ->setOutput($output) ->setHelperSet($this->getHelperSet()); }
php
protected function createInstance( InputInterface $input, OutputInterface $output, Form $form = null ) { if (!isset($form)) { $form = new Form(); } return $form ->setInput($input) ->setOutput($output) ->setHelperSet($this->getHelperSet()); }
[ "protected", "function", "createInstance", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ",", "Form", "$", "form", "=", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "form", ")", ")", "{", "$", "form", "=", "new", "Form", "(", ")", ";", "}", "return", "$", "form", "->", "setInput", "(", "$", "input", ")", "->", "setOutput", "(", "$", "output", ")", "->", "setHelperSet", "(", "$", "this", "->", "getHelperSet", "(", ")", ")", ";", "}" ]
Create form instance. @param \Droath\ConsoleForm\Form|null $form An already created form instance or null if one should be created. @return \Droath\ConsoleForm\Form
[ "Create", "form", "instance", "." ]
0fb43fdebd1f685779c9fffea43a0dccd4ebe14a
https://github.com/droath/console-form/blob/0fb43fdebd1f685779c9fffea43a0dccd4ebe14a/src/FormHelper.php#L90-L103
1,966
jacobemerick/archangel
src/Archangel.php
Archangel.addTo
public function addTo($address, $title = '') { array_push( $this->toAddresses, $this->formatEmailAddress($address, $title) ); return $this; }
php
public function addTo($address, $title = '') { array_push( $this->toAddresses, $this->formatEmailAddress($address, $title) ); return $this; }
[ "public", "function", "addTo", "(", "$", "address", ",", "$", "title", "=", "''", ")", "{", "array_push", "(", "$", "this", "->", "toAddresses", ",", "$", "this", "->", "formatEmailAddress", "(", "$", "address", ",", "$", "title", ")", ")", ";", "return", "$", "this", ";", "}" ]
Setter method for adding recipients @param string $address email address for the recipient @param string $title name of the recipient (optional) @return object instantiated $this
[ "Setter", "method", "for", "adding", "recipients" ]
a0acb17f2de01f1bea45d47bc856d57dfd28b7f9
https://github.com/jacobemerick/archangel/blob/a0acb17f2de01f1bea45d47bc856d57dfd28b7f9/src/Archangel.php#L89-L97
1,967
jacobemerick/archangel
src/Archangel.php
Archangel.addCC
public function addCC($address, $title = '') { if (!isset($this->headers['CC'])) { $this->headers['CC'] = array(); } array_push( $this->headers['CC'], $this->formatEmailAddress($address, $title) ); return $this; }
php
public function addCC($address, $title = '') { if (!isset($this->headers['CC'])) { $this->headers['CC'] = array(); } array_push( $this->headers['CC'], $this->formatEmailAddress($address, $title) ); return $this; }
[ "public", "function", "addCC", "(", "$", "address", ",", "$", "title", "=", "''", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "headers", "[", "'CC'", "]", ")", ")", "{", "$", "this", "->", "headers", "[", "'CC'", "]", "=", "array", "(", ")", ";", "}", "array_push", "(", "$", "this", "->", "headers", "[", "'CC'", "]", ",", "$", "this", "->", "formatEmailAddress", "(", "$", "address", ",", "$", "title", ")", ")", ";", "return", "$", "this", ";", "}" ]
Setter method for adding cc recipients @param string $address email address for the cc recipient @param string $title name of the cc recipient (optional) @return object instantiated $this
[ "Setter", "method", "for", "adding", "cc", "recipients" ]
a0acb17f2de01f1bea45d47bc856d57dfd28b7f9
https://github.com/jacobemerick/archangel/blob/a0acb17f2de01f1bea45d47bc856d57dfd28b7f9/src/Archangel.php#L107-L119
1,968
jacobemerick/archangel
src/Archangel.php
Archangel.addBCC
public function addBCC($address, $title = '') { if (!isset($this->headers['BCC'])) { $this->headers['BCC'] = array(); } array_push( $this->headers['BCC'], $this->formatEmailAddress($address, $title) ); return $this; }
php
public function addBCC($address, $title = '') { if (!isset($this->headers['BCC'])) { $this->headers['BCC'] = array(); } array_push( $this->headers['BCC'], $this->formatEmailAddress($address, $title) ); return $this; }
[ "public", "function", "addBCC", "(", "$", "address", ",", "$", "title", "=", "''", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "headers", "[", "'BCC'", "]", ")", ")", "{", "$", "this", "->", "headers", "[", "'BCC'", "]", "=", "array", "(", ")", ";", "}", "array_push", "(", "$", "this", "->", "headers", "[", "'BCC'", "]", ",", "$", "this", "->", "formatEmailAddress", "(", "$", "address", ",", "$", "title", ")", ")", ";", "return", "$", "this", ";", "}" ]
Setter method for adding bcc recipients @param string $address email address for the bcc recipient @param string $title name of the bcc recipient (optional) @return object instantiated $this
[ "Setter", "method", "for", "adding", "bcc", "recipients" ]
a0acb17f2de01f1bea45d47bc856d57dfd28b7f9
https://github.com/jacobemerick/archangel/blob/a0acb17f2de01f1bea45d47bc856d57dfd28b7f9/src/Archangel.php#L129-L141
1,969
jacobemerick/archangel
src/Archangel.php
Archangel.setFrom
public function setFrom($address, $title = '') { $this->headers['From'] = $this->formatEmailAddress($address, $title); return $this; }
php
public function setFrom($address, $title = '') { $this->headers['From'] = $this->formatEmailAddress($address, $title); return $this; }
[ "public", "function", "setFrom", "(", "$", "address", ",", "$", "title", "=", "''", ")", "{", "$", "this", "->", "headers", "[", "'From'", "]", "=", "$", "this", "->", "formatEmailAddress", "(", "$", "address", ",", "$", "title", ")", ";", "return", "$", "this", ";", "}" ]
Setter method for setting the single 'from' field @param string $address email address for the sender @param string $title name of the sender (optional) @return object instantiated $this
[ "Setter", "method", "for", "setting", "the", "single", "from", "field" ]
a0acb17f2de01f1bea45d47bc856d57dfd28b7f9
https://github.com/jacobemerick/archangel/blob/a0acb17f2de01f1bea45d47bc856d57dfd28b7f9/src/Archangel.php#L151-L156
1,970
jacobemerick/archangel
src/Archangel.php
Archangel.setReplyTo
public function setReplyTo($address, $title = '') { $this->headers['Reply-To'] = $this->formatEmailAddress($address, $title); return $this; }
php
public function setReplyTo($address, $title = '') { $this->headers['Reply-To'] = $this->formatEmailAddress($address, $title); return $this; }
[ "public", "function", "setReplyTo", "(", "$", "address", ",", "$", "title", "=", "''", ")", "{", "$", "this", "->", "headers", "[", "'Reply-To'", "]", "=", "$", "this", "->", "formatEmailAddress", "(", "$", "address", ",", "$", "title", ")", ";", "return", "$", "this", ";", "}" ]
Setter method for setting the single 'reply-to' field @param string $address email address for the reply-to @param string $title name of the reply-to (optional) @return object instantiated $this
[ "Setter", "method", "for", "setting", "the", "single", "reply", "-", "to", "field" ]
a0acb17f2de01f1bea45d47bc856d57dfd28b7f9
https://github.com/jacobemerick/archangel/blob/a0acb17f2de01f1bea45d47bc856d57dfd28b7f9/src/Archangel.php#L166-L171
1,971
jacobemerick/archangel
src/Archangel.php
Archangel.addAttachment
public function addAttachment($path, $type, $title = '') { array_push($this->attachments, array( 'path' => $path, 'type' => $type, 'title' => $title, )); return $this; }
php
public function addAttachment($path, $type, $title = '') { array_push($this->attachments, array( 'path' => $path, 'type' => $type, 'title' => $title, )); return $this; }
[ "public", "function", "addAttachment", "(", "$", "path", ",", "$", "type", ",", "$", "title", "=", "''", ")", "{", "array_push", "(", "$", "this", "->", "attachments", ",", "array", "(", "'path'", "=>", "$", "path", ",", "'type'", "=>", "$", "type", ",", "'title'", "=>", "$", "title", ",", ")", ")", ";", "return", "$", "this", ";", "}" ]
Setter method for adding attachments @param string $path the full path of the attachment @param string $type mime type of the file @param string $title the title of the attachment (optional) @return object instantiated $this
[ "Setter", "method", "for", "adding", "attachments" ]
a0acb17f2de01f1bea45d47bc856d57dfd28b7f9
https://github.com/jacobemerick/archangel/blob/a0acb17f2de01f1bea45d47bc856d57dfd28b7f9/src/Archangel.php#L238-L247
1,972
jacobemerick/archangel
src/Archangel.php
Archangel.checkRequiredFields
protected function checkRequiredFields() { if (empty($this->toAddresses)) { return false; } if (empty($this->subject)) { return false; } if (empty($this->plainMessage) && empty($this->htmlMessage) && empty($this->attachments)) { return false; } return true; }
php
protected function checkRequiredFields() { if (empty($this->toAddresses)) { return false; } if (empty($this->subject)) { return false; } if (empty($this->plainMessage) && empty($this->htmlMessage) && empty($this->attachments)) { return false; } return true; }
[ "protected", "function", "checkRequiredFields", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "toAddresses", ")", ")", "{", "return", "false", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "subject", ")", ")", "{", "return", "false", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "plainMessage", ")", "&&", "empty", "(", "$", "this", "->", "htmlMessage", ")", "&&", "empty", "(", "$", "this", "->", "attachments", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Call to check the minimum required fields @return boolean whether or not the email meets the minimum required fields
[ "Call", "to", "check", "the", "minimum", "required", "fields" ]
a0acb17f2de01f1bea45d47bc856d57dfd28b7f9
https://github.com/jacobemerick/archangel/blob/a0acb17f2de01f1bea45d47bc856d57dfd28b7f9/src/Archangel.php#L288-L302
1,973
jacobemerick/archangel
src/Archangel.php
Archangel.buildMessage
protected function buildMessage() { if (empty($this->plainMessage) && empty($this->htmlMessage)) { return ''; } if (!empty($this->plainMessage) && empty($this->htmlMessage)) { return $this->plainMessage; } if (empty($this->plainMessage) && !empty($this->htmlMessage)) { return $this->htmlMessage; } $message = array(); array_push($message, "--{$this->boundaryAlternative}"); $message = array_merge($message, $this->buildPlainMessageHeader()); array_push($message, $this->plainMessage); array_push($message, "--{$this->boundaryAlternative}"); $message = array_merge($message, $this->buildHtmlMessageHeader()); array_push($message, $this->htmlMessage); array_push($message, "--{$this->boundaryAlternative}--"); return implode(self::LINE_BREAK, $message); }
php
protected function buildMessage() { if (empty($this->plainMessage) && empty($this->htmlMessage)) { return ''; } if (!empty($this->plainMessage) && empty($this->htmlMessage)) { return $this->plainMessage; } if (empty($this->plainMessage) && !empty($this->htmlMessage)) { return $this->htmlMessage; } $message = array(); array_push($message, "--{$this->boundaryAlternative}"); $message = array_merge($message, $this->buildPlainMessageHeader()); array_push($message, $this->plainMessage); array_push($message, "--{$this->boundaryAlternative}"); $message = array_merge($message, $this->buildHtmlMessageHeader()); array_push($message, $this->htmlMessage); array_push($message, "--{$this->boundaryAlternative}--"); return implode(self::LINE_BREAK, $message); }
[ "protected", "function", "buildMessage", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "plainMessage", ")", "&&", "empty", "(", "$", "this", "->", "htmlMessage", ")", ")", "{", "return", "''", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "plainMessage", ")", "&&", "empty", "(", "$", "this", "->", "htmlMessage", ")", ")", "{", "return", "$", "this", "->", "plainMessage", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "plainMessage", ")", "&&", "!", "empty", "(", "$", "this", "->", "htmlMessage", ")", ")", "{", "return", "$", "this", "->", "htmlMessage", ";", "}", "$", "message", "=", "array", "(", ")", ";", "array_push", "(", "$", "message", ",", "\"--{$this->boundaryAlternative}\"", ")", ";", "$", "message", "=", "array_merge", "(", "$", "message", ",", "$", "this", "->", "buildPlainMessageHeader", "(", ")", ")", ";", "array_push", "(", "$", "message", ",", "$", "this", "->", "plainMessage", ")", ";", "array_push", "(", "$", "message", ",", "\"--{$this->boundaryAlternative}\"", ")", ";", "$", "message", "=", "array_merge", "(", "$", "message", ",", "$", "this", "->", "buildHtmlMessageHeader", "(", ")", ")", ";", "array_push", "(", "$", "message", ",", "$", "this", "->", "htmlMessage", ")", ";", "array_push", "(", "$", "message", ",", "\"--{$this->boundaryAlternative}--\"", ")", ";", "return", "implode", "(", "self", "::", "LINE_BREAK", ",", "$", "message", ")", ";", "}" ]
Returns a simple email message without attachments @return string email message
[ "Returns", "a", "simple", "email", "message", "without", "attachments" ]
a0acb17f2de01f1bea45d47bc856d57dfd28b7f9
https://github.com/jacobemerick/archangel/blob/a0acb17f2de01f1bea45d47bc856d57dfd28b7f9/src/Archangel.php#L319-L341
1,974
jacobemerick/archangel
src/Archangel.php
Archangel.buildMessageWithAttachments
protected function buildMessageWithAttachments() { $message = array(); if (!empty($this->plainMessage) || !empty($this->htmlMessage)) { array_push($message, "--{$this->boundaryMixed}"); } if (!empty($this->plainMessage) && !empty($this->htmlMessage)) { array_push($message, "Content-Type: multipart/alternative; boundary={$this->boundaryAlternative}"); array_push($message, ''); array_push($message, "--{$this->boundaryAlternative}"); $message = array_merge($message, $this->buildPlainMessageHeader()); array_push($message, $this->plainMessage); array_push($message, "--{$this->boundaryAlternative}"); $message = array_merge($message, $this->buildHtmlMessageHeader()); array_push($message, $this->htmlMessage); array_push($message, "--{$this->boundaryAlternative}--"); array_push($message, ''); } elseif (!empty($this->plainMessage)) { $message = array_merge($message, $this->buildPlainMessageHeader()); array_push($message, $this->plainMessage); } elseif (!empty($this->htmlMessage)) { $message = array_merge($message, $this->buildHtmlMessageHeader()); array_push($message, $this->htmlMessage); } foreach ($this->attachments as $attachment) { array_push($message, "--{$this->boundaryMixed}"); array_push($message, "Content-Type: {$attachment['type']}; name=\"{$attachment['title']}\""); array_push($message, 'Content-Transfer-Encoding: base64'); array_push($message, 'Content-Disposition: attachment'); array_push($message, ''); array_push($message, $this->buildAttachmentContent($attachment['path'])); } array_push($message, "--{$this->boundaryMixed}--"); return implode(self::LINE_BREAK, $message); }
php
protected function buildMessageWithAttachments() { $message = array(); if (!empty($this->plainMessage) || !empty($this->htmlMessage)) { array_push($message, "--{$this->boundaryMixed}"); } if (!empty($this->plainMessage) && !empty($this->htmlMessage)) { array_push($message, "Content-Type: multipart/alternative; boundary={$this->boundaryAlternative}"); array_push($message, ''); array_push($message, "--{$this->boundaryAlternative}"); $message = array_merge($message, $this->buildPlainMessageHeader()); array_push($message, $this->plainMessage); array_push($message, "--{$this->boundaryAlternative}"); $message = array_merge($message, $this->buildHtmlMessageHeader()); array_push($message, $this->htmlMessage); array_push($message, "--{$this->boundaryAlternative}--"); array_push($message, ''); } elseif (!empty($this->plainMessage)) { $message = array_merge($message, $this->buildPlainMessageHeader()); array_push($message, $this->plainMessage); } elseif (!empty($this->htmlMessage)) { $message = array_merge($message, $this->buildHtmlMessageHeader()); array_push($message, $this->htmlMessage); } foreach ($this->attachments as $attachment) { array_push($message, "--{$this->boundaryMixed}"); array_push($message, "Content-Type: {$attachment['type']}; name=\"{$attachment['title']}\""); array_push($message, 'Content-Transfer-Encoding: base64'); array_push($message, 'Content-Disposition: attachment'); array_push($message, ''); array_push($message, $this->buildAttachmentContent($attachment['path'])); } array_push($message, "--{$this->boundaryMixed}--"); return implode(self::LINE_BREAK, $message); }
[ "protected", "function", "buildMessageWithAttachments", "(", ")", "{", "$", "message", "=", "array", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "plainMessage", ")", "||", "!", "empty", "(", "$", "this", "->", "htmlMessage", ")", ")", "{", "array_push", "(", "$", "message", ",", "\"--{$this->boundaryMixed}\"", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "plainMessage", ")", "&&", "!", "empty", "(", "$", "this", "->", "htmlMessage", ")", ")", "{", "array_push", "(", "$", "message", ",", "\"Content-Type: multipart/alternative; boundary={$this->boundaryAlternative}\"", ")", ";", "array_push", "(", "$", "message", ",", "''", ")", ";", "array_push", "(", "$", "message", ",", "\"--{$this->boundaryAlternative}\"", ")", ";", "$", "message", "=", "array_merge", "(", "$", "message", ",", "$", "this", "->", "buildPlainMessageHeader", "(", ")", ")", ";", "array_push", "(", "$", "message", ",", "$", "this", "->", "plainMessage", ")", ";", "array_push", "(", "$", "message", ",", "\"--{$this->boundaryAlternative}\"", ")", ";", "$", "message", "=", "array_merge", "(", "$", "message", ",", "$", "this", "->", "buildHtmlMessageHeader", "(", ")", ")", ";", "array_push", "(", "$", "message", ",", "$", "this", "->", "htmlMessage", ")", ";", "array_push", "(", "$", "message", ",", "\"--{$this->boundaryAlternative}--\"", ")", ";", "array_push", "(", "$", "message", ",", "''", ")", ";", "}", "elseif", "(", "!", "empty", "(", "$", "this", "->", "plainMessage", ")", ")", "{", "$", "message", "=", "array_merge", "(", "$", "message", ",", "$", "this", "->", "buildPlainMessageHeader", "(", ")", ")", ";", "array_push", "(", "$", "message", ",", "$", "this", "->", "plainMessage", ")", ";", "}", "elseif", "(", "!", "empty", "(", "$", "this", "->", "htmlMessage", ")", ")", "{", "$", "message", "=", "array_merge", "(", "$", "message", ",", "$", "this", "->", "buildHtmlMessageHeader", "(", ")", ")", ";", "array_push", "(", "$", "message", ",", "$", "this", "->", "htmlMessage", ")", ";", "}", "foreach", "(", "$", "this", "->", "attachments", "as", "$", "attachment", ")", "{", "array_push", "(", "$", "message", ",", "\"--{$this->boundaryMixed}\"", ")", ";", "array_push", "(", "$", "message", ",", "\"Content-Type: {$attachment['type']}; name=\\\"{$attachment['title']}\\\"\"", ")", ";", "array_push", "(", "$", "message", ",", "'Content-Transfer-Encoding: base64'", ")", ";", "array_push", "(", "$", "message", ",", "'Content-Disposition: attachment'", ")", ";", "array_push", "(", "$", "message", ",", "''", ")", ";", "array_push", "(", "$", "message", ",", "$", "this", "->", "buildAttachmentContent", "(", "$", "attachment", "[", "'path'", "]", ")", ")", ";", "}", "array_push", "(", "$", "message", ",", "\"--{$this->boundaryMixed}--\"", ")", ";", "return", "implode", "(", "self", "::", "LINE_BREAK", ",", "$", "message", ")", ";", "}" ]
Build multi-part message with attachments @return string email message
[ "Build", "multi", "-", "part", "message", "with", "attachments" ]
a0acb17f2de01f1bea45d47bc856d57dfd28b7f9
https://github.com/jacobemerick/archangel/blob/a0acb17f2de01f1bea45d47bc856d57dfd28b7f9/src/Archangel.php#L348-L385
1,975
jacobemerick/archangel
src/Archangel.php
Archangel.buildHeaders
protected function buildHeaders() { $headers = array(); foreach ($this->headers as $key => $value) { if ($key == 'CC' || $key == 'BCC') { $value = implode(', ', $value); } array_push($headers, sprintf('%s: %s', $key, $value)); } if (!empty($this->attachments)) { array_push( $headers, "Content-Type: multipart/mixed; boundary=\"{$this->boundaryMixed}\"" ); } elseif (!empty($this->plainMessage) && !empty($this->htmlMessage)) { array_push( $headers, "Content-Type: multipart/alternative; boundary=\"{$this->boundaryAlternative}\"" ); } elseif (!empty($this->htmlMessage)) { array_push( $headers, 'Content-type: text/html; charset="iso-8859-1"' ); } return implode(self::LINE_BREAK, $headers); }
php
protected function buildHeaders() { $headers = array(); foreach ($this->headers as $key => $value) { if ($key == 'CC' || $key == 'BCC') { $value = implode(', ', $value); } array_push($headers, sprintf('%s: %s', $key, $value)); } if (!empty($this->attachments)) { array_push( $headers, "Content-Type: multipart/mixed; boundary=\"{$this->boundaryMixed}\"" ); } elseif (!empty($this->plainMessage) && !empty($this->htmlMessage)) { array_push( $headers, "Content-Type: multipart/alternative; boundary=\"{$this->boundaryAlternative}\"" ); } elseif (!empty($this->htmlMessage)) { array_push( $headers, 'Content-type: text/html; charset="iso-8859-1"' ); } return implode(self::LINE_BREAK, $headers); }
[ "protected", "function", "buildHeaders", "(", ")", "{", "$", "headers", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "headers", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "key", "==", "'CC'", "||", "$", "key", "==", "'BCC'", ")", "{", "$", "value", "=", "implode", "(", "', '", ",", "$", "value", ")", ";", "}", "array_push", "(", "$", "headers", ",", "sprintf", "(", "'%s: %s'", ",", "$", "key", ",", "$", "value", ")", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "attachments", ")", ")", "{", "array_push", "(", "$", "headers", ",", "\"Content-Type: multipart/mixed; boundary=\\\"{$this->boundaryMixed}\\\"\"", ")", ";", "}", "elseif", "(", "!", "empty", "(", "$", "this", "->", "plainMessage", ")", "&&", "!", "empty", "(", "$", "this", "->", "htmlMessage", ")", ")", "{", "array_push", "(", "$", "headers", ",", "\"Content-Type: multipart/alternative; boundary=\\\"{$this->boundaryAlternative}\\\"\"", ")", ";", "}", "elseif", "(", "!", "empty", "(", "$", "this", "->", "htmlMessage", ")", ")", "{", "array_push", "(", "$", "headers", ",", "'Content-type: text/html; charset=\"iso-8859-1\"'", ")", ";", "}", "return", "implode", "(", "self", "::", "LINE_BREAK", ",", "$", "headers", ")", ";", "}" ]
Builder for the additional headers needed for multipart emails @return string headers needed for multipart
[ "Builder", "for", "the", "additional", "headers", "needed", "for", "multipart", "emails" ]
a0acb17f2de01f1bea45d47bc856d57dfd28b7f9
https://github.com/jacobemerick/archangel/blob/a0acb17f2de01f1bea45d47bc856d57dfd28b7f9/src/Archangel.php#L421-L449
1,976
jacobemerick/archangel
src/Archangel.php
Archangel.buildAttachmentContent
protected function buildAttachmentContent($path) { if (!file_exists($path)) { $this->logger->error("Could not find file {$path} for attaching to Archangel mail."); return ''; } $handle = fopen($path, 'r'); $contents = fread($handle, filesize($path)); fclose($handle); $contents = base64_encode($contents); $contents = chunk_split($contents); return $contents; }
php
protected function buildAttachmentContent($path) { if (!file_exists($path)) { $this->logger->error("Could not find file {$path} for attaching to Archangel mail."); return ''; } $handle = fopen($path, 'r'); $contents = fread($handle, filesize($path)); fclose($handle); $contents = base64_encode($contents); $contents = chunk_split($contents); return $contents; }
[ "protected", "function", "buildAttachmentContent", "(", "$", "path", ")", "{", "if", "(", "!", "file_exists", "(", "$", "path", ")", ")", "{", "$", "this", "->", "logger", "->", "error", "(", "\"Could not find file {$path} for attaching to Archangel mail.\"", ")", ";", "return", "''", ";", "}", "$", "handle", "=", "fopen", "(", "$", "path", ",", "'r'", ")", ";", "$", "contents", "=", "fread", "(", "$", "handle", ",", "filesize", "(", "$", "path", ")", ")", ";", "fclose", "(", "$", "handle", ")", ";", "$", "contents", "=", "base64_encode", "(", "$", "contents", ")", ";", "$", "contents", "=", "chunk_split", "(", "$", "contents", ")", ";", "return", "$", "contents", ";", "}" ]
File reader for attachments @param string $path filepath of the attachment @return string binary representation of file, base64'd
[ "File", "reader", "for", "attachments" ]
a0acb17f2de01f1bea45d47bc856d57dfd28b7f9
https://github.com/jacobemerick/archangel/blob/a0acb17f2de01f1bea45d47bc856d57dfd28b7f9/src/Archangel.php#L458-L472
1,977
chornij/yii2-zeroclipboard
Button.php
Button.registerScript
private function registerScript() { ZeroClipboardAsset::register($this->getView()); $clipboardVar = 'client' . preg_replace('/[^0-9a-zA-Z_$]/', '_', $this->id); $this->getView()->registerJs('var ' . $clipboardVar . ';', View::POS_HEAD); $this->getView()->registerJs( $clipboardVar . " = new ZeroClipboard($('#" . $this->id . "')); " . $clipboardVar . ".on('copy', function (event) { var clipboard = event.clipboardData; clipboard.setData('text/plain', " . $this->text . '); });' ); if ($this->enableAftercopy) { $this->getView()->registerJs($clipboardVar . ".on('aftercopy', function(event) { var oldLabel = $('#" . $this->id . "').html(); $('#" . $this->id . "').html('" . $this->afterCopyLabel . "'); setTimeout(function() { $('#" . $this->id . "').html(oldLabel); }, 1000); });"); } }
php
private function registerScript() { ZeroClipboardAsset::register($this->getView()); $clipboardVar = 'client' . preg_replace('/[^0-9a-zA-Z_$]/', '_', $this->id); $this->getView()->registerJs('var ' . $clipboardVar . ';', View::POS_HEAD); $this->getView()->registerJs( $clipboardVar . " = new ZeroClipboard($('#" . $this->id . "')); " . $clipboardVar . ".on('copy', function (event) { var clipboard = event.clipboardData; clipboard.setData('text/plain', " . $this->text . '); });' ); if ($this->enableAftercopy) { $this->getView()->registerJs($clipboardVar . ".on('aftercopy', function(event) { var oldLabel = $('#" . $this->id . "').html(); $('#" . $this->id . "').html('" . $this->afterCopyLabel . "'); setTimeout(function() { $('#" . $this->id . "').html(oldLabel); }, 1000); });"); } }
[ "private", "function", "registerScript", "(", ")", "{", "ZeroClipboardAsset", "::", "register", "(", "$", "this", "->", "getView", "(", ")", ")", ";", "$", "clipboardVar", "=", "'client'", ".", "preg_replace", "(", "'/[^0-9a-zA-Z_$]/'", ",", "'_'", ",", "$", "this", "->", "id", ")", ";", "$", "this", "->", "getView", "(", ")", "->", "registerJs", "(", "'var '", ".", "$", "clipboardVar", ".", "';'", ",", "View", "::", "POS_HEAD", ")", ";", "$", "this", "->", "getView", "(", ")", "->", "registerJs", "(", "$", "clipboardVar", ".", "\" = new ZeroClipboard($('#\"", ".", "$", "this", "->", "id", ".", "\"'));\n\n \"", ".", "$", "clipboardVar", ".", "\".on('copy', function (event) {\n var clipboard = event.clipboardData;\n\n clipboard.setData('text/plain', \"", ".", "$", "this", "->", "text", ".", "');\n });'", ")", ";", "if", "(", "$", "this", "->", "enableAftercopy", ")", "{", "$", "this", "->", "getView", "(", ")", "->", "registerJs", "(", "$", "clipboardVar", ".", "\".on('aftercopy', function(event) {\n var oldLabel = $('#\"", ".", "$", "this", "->", "id", ".", "\"').html();\n\n $('#\"", ".", "$", "this", "->", "id", ".", "\"').html('\"", ".", "$", "this", "->", "afterCopyLabel", ".", "\"');\n\n setTimeout(function() {\n $('#\"", ".", "$", "this", "->", "id", ".", "\"').html(oldLabel);\n }, 1000);\n });\"", ")", ";", "}", "}" ]
Register button scripts
[ "Register", "button", "scripts" ]
76f7713d811ec6794aed48b0106a6cba2c2c1519
https://github.com/chornij/yii2-zeroclipboard/blob/76f7713d811ec6794aed48b0106a6cba2c2c1519/Button.php#L82-L109
1,978
iRAP-software/package-core-libs
src/CsvLib.php
CsvLib.convertCsvToJson
public static function convertCsvToJson($csvFilepath, $jsonFilepath, $compressed) { $lines = file($csvFilepath); $jsonFile = fopen($jsonFilepath, "w"); $headers = array(); if ($compressed) { fwrite($jsonFile, "["); } else { fwrite($jsonFile, "[" . PHP_EOL); } foreach ($lines as $lineIndex => $line) { if ($lineIndex === 0) { # this is the header line $headers = str_getcsv($line); } else { $data = str_getcsv($line); $obj = new \stdClass(); foreach ($headers as $headerIndex => $header) { $obj->$header = $data[$headerIndex]; } if ($compressed) { $jsonString = json_encode($obj, JSON_UNESCAPED_SLASHES); } else { $jsonString = json_encode($obj, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); } if (!$compressed) { $jsonStringLines = explode(PHP_EOL, $jsonString); foreach ($jsonStringLines as $jsonStringLineIndex => $line) { $jsonStringLines[$jsonStringLineIndex] = " " . $line; } $jsonString = implode(PHP_EOL, $jsonStringLines); } if ($lineIndex > 1) { if ($compressed) { $jsonString = "," . $jsonString; } else { $jsonString = "," . PHP_EOL . $jsonString; } } fwrite($jsonFile, $jsonString); } } fwrite($jsonFile, "]"); }
php
public static function convertCsvToJson($csvFilepath, $jsonFilepath, $compressed) { $lines = file($csvFilepath); $jsonFile = fopen($jsonFilepath, "w"); $headers = array(); if ($compressed) { fwrite($jsonFile, "["); } else { fwrite($jsonFile, "[" . PHP_EOL); } foreach ($lines as $lineIndex => $line) { if ($lineIndex === 0) { # this is the header line $headers = str_getcsv($line); } else { $data = str_getcsv($line); $obj = new \stdClass(); foreach ($headers as $headerIndex => $header) { $obj->$header = $data[$headerIndex]; } if ($compressed) { $jsonString = json_encode($obj, JSON_UNESCAPED_SLASHES); } else { $jsonString = json_encode($obj, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); } if (!$compressed) { $jsonStringLines = explode(PHP_EOL, $jsonString); foreach ($jsonStringLines as $jsonStringLineIndex => $line) { $jsonStringLines[$jsonStringLineIndex] = " " . $line; } $jsonString = implode(PHP_EOL, $jsonStringLines); } if ($lineIndex > 1) { if ($compressed) { $jsonString = "," . $jsonString; } else { $jsonString = "," . PHP_EOL . $jsonString; } } fwrite($jsonFile, $jsonString); } } fwrite($jsonFile, "]"); }
[ "public", "static", "function", "convertCsvToJson", "(", "$", "csvFilepath", ",", "$", "jsonFilepath", ",", "$", "compressed", ")", "{", "$", "lines", "=", "file", "(", "$", "csvFilepath", ")", ";", "$", "jsonFile", "=", "fopen", "(", "$", "jsonFilepath", ",", "\"w\"", ")", ";", "$", "headers", "=", "array", "(", ")", ";", "if", "(", "$", "compressed", ")", "{", "fwrite", "(", "$", "jsonFile", ",", "\"[\"", ")", ";", "}", "else", "{", "fwrite", "(", "$", "jsonFile", ",", "\"[\"", ".", "PHP_EOL", ")", ";", "}", "foreach", "(", "$", "lines", "as", "$", "lineIndex", "=>", "$", "line", ")", "{", "if", "(", "$", "lineIndex", "===", "0", ")", "{", "# this is the header line", "$", "headers", "=", "str_getcsv", "(", "$", "line", ")", ";", "}", "else", "{", "$", "data", "=", "str_getcsv", "(", "$", "line", ")", ";", "$", "obj", "=", "new", "\\", "stdClass", "(", ")", ";", "foreach", "(", "$", "headers", "as", "$", "headerIndex", "=>", "$", "header", ")", "{", "$", "obj", "->", "$", "header", "=", "$", "data", "[", "$", "headerIndex", "]", ";", "}", "if", "(", "$", "compressed", ")", "{", "$", "jsonString", "=", "json_encode", "(", "$", "obj", ",", "JSON_UNESCAPED_SLASHES", ")", ";", "}", "else", "{", "$", "jsonString", "=", "json_encode", "(", "$", "obj", ",", "JSON_PRETTY_PRINT", "|", "JSON_UNESCAPED_SLASHES", ")", ";", "}", "if", "(", "!", "$", "compressed", ")", "{", "$", "jsonStringLines", "=", "explode", "(", "PHP_EOL", ",", "$", "jsonString", ")", ";", "foreach", "(", "$", "jsonStringLines", "as", "$", "jsonStringLineIndex", "=>", "$", "line", ")", "{", "$", "jsonStringLines", "[", "$", "jsonStringLineIndex", "]", "=", "\" \"", ".", "$", "line", ";", "}", "$", "jsonString", "=", "implode", "(", "PHP_EOL", ",", "$", "jsonStringLines", ")", ";", "}", "if", "(", "$", "lineIndex", ">", "1", ")", "{", "if", "(", "$", "compressed", ")", "{", "$", "jsonString", "=", "\",\"", ".", "$", "jsonString", ";", "}", "else", "{", "$", "jsonString", "=", "\",\"", ".", "PHP_EOL", ".", "$", "jsonString", ";", "}", "}", "fwrite", "(", "$", "jsonFile", ",", "$", "jsonString", ")", ";", "}", "}", "fwrite", "(", "$", "jsonFile", ",", "\"]\"", ")", ";", "}" ]
Converts a CSV file into a JSON file. @param string $csvFilepath - location of the CSV file we wish to convert. @param string $jsonFilepath - path to where we wish to store the result. If the file already exists, then it will be overwritten. If not then it will be created. @param bool $compressed - if true then this will have no line endings or padding, if false then the outputted json will be much easier to read by humans.
[ "Converts", "a", "CSV", "file", "into", "a", "JSON", "file", "." ]
244871d2fbc2f3fac26ff4b98715224953d9befb
https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/CsvLib.php#L21-L93
1,979
iRAP-software/package-core-libs
src/CsvLib.php
CsvLib.convertArrayToCsv
public static function convertArrayToCsv(string $filepath, array $rows, bool $addHeader, string $delimiter = ",", string $enclosure = '"') { $fileHandle = fopen($filepath, 'w'); if ($fileHandle === FALSE) { throw new \Exception("Failed to open {$filepath} for writing."); } if (count($rows) === 0) { throw new \Exception("Cannot create CSV file with no data."); } $firstRow = ArrayLib::getFirstElement($rows); if (ArrayLib::isAssoc($firstRow) === FALSE) { throw new \Exception("convertArrayToCsv expects a list of assosciative arrays."); } $keys = array_keys($firstRow); if ($addHeader) { fputcsv($fileHandle, $keys, $delimiter, $enclosure); } foreach ($rows as $index => $row) { if (count($keys) != count($row)) { $msg = "Cannot convert array to CSV. Number of keys: " . count($keys) . " is not the same as the number of values: " . count($row); throw new \Exception($msg); } $rowOfValues = array(); foreach ($keys as $key) { if (!isset($row[$key])) { // key might be set, the value might just be null. Check for this. $keys = array_keys($row); if (in_array($key, $keys) === FALSE) { throw new \Exception("row missing expected key {$key} on row {$index}"); } else { $value = null; } } else { $value = $row[$key]; } $rowOfValues[] = $value; } fputcsv($fileHandle, $rowOfValues, $delimiter, $enclosure); } }
php
public static function convertArrayToCsv(string $filepath, array $rows, bool $addHeader, string $delimiter = ",", string $enclosure = '"') { $fileHandle = fopen($filepath, 'w'); if ($fileHandle === FALSE) { throw new \Exception("Failed to open {$filepath} for writing."); } if (count($rows) === 0) { throw new \Exception("Cannot create CSV file with no data."); } $firstRow = ArrayLib::getFirstElement($rows); if (ArrayLib::isAssoc($firstRow) === FALSE) { throw new \Exception("convertArrayToCsv expects a list of assosciative arrays."); } $keys = array_keys($firstRow); if ($addHeader) { fputcsv($fileHandle, $keys, $delimiter, $enclosure); } foreach ($rows as $index => $row) { if (count($keys) != count($row)) { $msg = "Cannot convert array to CSV. Number of keys: " . count($keys) . " is not the same as the number of values: " . count($row); throw new \Exception($msg); } $rowOfValues = array(); foreach ($keys as $key) { if (!isset($row[$key])) { // key might be set, the value might just be null. Check for this. $keys = array_keys($row); if (in_array($key, $keys) === FALSE) { throw new \Exception("row missing expected key {$key} on row {$index}"); } else { $value = null; } } else { $value = $row[$key]; } $rowOfValues[] = $value; } fputcsv($fileHandle, $rowOfValues, $delimiter, $enclosure); } }
[ "public", "static", "function", "convertArrayToCsv", "(", "string", "$", "filepath", ",", "array", "$", "rows", ",", "bool", "$", "addHeader", ",", "string", "$", "delimiter", "=", "\",\"", ",", "string", "$", "enclosure", "=", "'\"'", ")", "{", "$", "fileHandle", "=", "fopen", "(", "$", "filepath", ",", "'w'", ")", ";", "if", "(", "$", "fileHandle", "===", "FALSE", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Failed to open {$filepath} for writing.\"", ")", ";", "}", "if", "(", "count", "(", "$", "rows", ")", "===", "0", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Cannot create CSV file with no data.\"", ")", ";", "}", "$", "firstRow", "=", "ArrayLib", "::", "getFirstElement", "(", "$", "rows", ")", ";", "if", "(", "ArrayLib", "::", "isAssoc", "(", "$", "firstRow", ")", "===", "FALSE", ")", "{", "throw", "new", "\\", "Exception", "(", "\"convertArrayToCsv expects a list of assosciative arrays.\"", ")", ";", "}", "$", "keys", "=", "array_keys", "(", "$", "firstRow", ")", ";", "if", "(", "$", "addHeader", ")", "{", "fputcsv", "(", "$", "fileHandle", ",", "$", "keys", ",", "$", "delimiter", ",", "$", "enclosure", ")", ";", "}", "foreach", "(", "$", "rows", "as", "$", "index", "=>", "$", "row", ")", "{", "if", "(", "count", "(", "$", "keys", ")", "!=", "count", "(", "$", "row", ")", ")", "{", "$", "msg", "=", "\"Cannot convert array to CSV. Number of keys: \"", ".", "count", "(", "$", "keys", ")", ".", "\" is not the same as the number of values: \"", ".", "count", "(", "$", "row", ")", ";", "throw", "new", "\\", "Exception", "(", "$", "msg", ")", ";", "}", "$", "rowOfValues", "=", "array", "(", ")", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "if", "(", "!", "isset", "(", "$", "row", "[", "$", "key", "]", ")", ")", "{", "// key might be set, the value might just be null. Check for this.", "$", "keys", "=", "array_keys", "(", "$", "row", ")", ";", "if", "(", "in_array", "(", "$", "key", ",", "$", "keys", ")", "===", "FALSE", ")", "{", "throw", "new", "\\", "Exception", "(", "\"row missing expected key {$key} on row {$index}\"", ")", ";", "}", "else", "{", "$", "value", "=", "null", ";", "}", "}", "else", "{", "$", "value", "=", "$", "row", "[", "$", "key", "]", ";", "}", "$", "rowOfValues", "[", "]", "=", "$", "value", ";", "}", "fputcsv", "(", "$", "fileHandle", ",", "$", "rowOfValues", ",", "$", "delimiter", ",", "$", "enclosure", ")", ";", "}", "}" ]
Create a CSV file from the provided array of data. This is done in a memory efficient manner of writing one line at a time to the file rather then building a massive string and dumping the entire string to the file. @param string $filepath - the path to the file that we will write the csv to, creating if necessary. @param array $rows - a collection of assosciative name/value pairs for the data to fill the csv file. The values will be filled in in the order of the keys in the first row. @param bool $addHeader - specify whether the CSV file we should put the header row in for the csv file. If true, we will use the keys of the first row as we expect all keys to match. @param string $delimiter - optionally specify a delimiter if you dont wish to use the comma @param string $enclosure - optionally specify the enclosure if you don't wish to use " @return void - all data written to the passed in filepath. Throws exception if anything goes wrong. @throws Exception @throws \Exception
[ "Create", "a", "CSV", "file", "from", "the", "provided", "array", "of", "data", ".", "This", "is", "done", "in", "a", "memory", "efficient", "manner", "of", "writing", "one", "line", "at", "a", "time", "to", "the", "file", "rather", "then", "building", "a", "massive", "string", "and", "dumping", "the", "entire", "string", "to", "the", "file", "." ]
244871d2fbc2f3fac26ff4b98715224953d9befb
https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/CsvLib.php#L182-L248
1,980
iRAP-software/package-core-libs
src/CsvLib.php
CsvLib.trim
public static function trim($filepath, $delimiter) { $tmpFile = tmpfile(); $uploaded_fh = fopen($filepath, "r"); if ($uploaded_fh) { while (!feof($uploaded_fh)) { $lineArray = fgetcsv($uploaded_fh, 0, $delimiter); if (!empty($lineArray)) { foreach ($lineArray as $index => $value) { $lineArray[$index] = trim($value); } fputcsv($tmpFile, $lineArray, ","); } } fclose($uploaded_fh); $meta_data = stream_get_meta_data($tmpFile); $tmpFileName = $meta_data["uri"]; rename($tmpFileName, $filepath); # replace the old upload file with new. } else { throw new \Exception("Failed to open upload file for trimming."); } }
php
public static function trim($filepath, $delimiter) { $tmpFile = tmpfile(); $uploaded_fh = fopen($filepath, "r"); if ($uploaded_fh) { while (!feof($uploaded_fh)) { $lineArray = fgetcsv($uploaded_fh, 0, $delimiter); if (!empty($lineArray)) { foreach ($lineArray as $index => $value) { $lineArray[$index] = trim($value); } fputcsv($tmpFile, $lineArray, ","); } } fclose($uploaded_fh); $meta_data = stream_get_meta_data($tmpFile); $tmpFileName = $meta_data["uri"]; rename($tmpFileName, $filepath); # replace the old upload file with new. } else { throw new \Exception("Failed to open upload file for trimming."); } }
[ "public", "static", "function", "trim", "(", "$", "filepath", ",", "$", "delimiter", ")", "{", "$", "tmpFile", "=", "tmpfile", "(", ")", ";", "$", "uploaded_fh", "=", "fopen", "(", "$", "filepath", ",", "\"r\"", ")", ";", "if", "(", "$", "uploaded_fh", ")", "{", "while", "(", "!", "feof", "(", "$", "uploaded_fh", ")", ")", "{", "$", "lineArray", "=", "fgetcsv", "(", "$", "uploaded_fh", ",", "0", ",", "$", "delimiter", ")", ";", "if", "(", "!", "empty", "(", "$", "lineArray", ")", ")", "{", "foreach", "(", "$", "lineArray", "as", "$", "index", "=>", "$", "value", ")", "{", "$", "lineArray", "[", "$", "index", "]", "=", "trim", "(", "$", "value", ")", ";", "}", "fputcsv", "(", "$", "tmpFile", ",", "$", "lineArray", ",", "\",\"", ")", ";", "}", "}", "fclose", "(", "$", "uploaded_fh", ")", ";", "$", "meta_data", "=", "stream_get_meta_data", "(", "$", "tmpFile", ")", ";", "$", "tmpFileName", "=", "$", "meta_data", "[", "\"uri\"", "]", ";", "rename", "(", "$", "tmpFileName", ",", "$", "filepath", ")", ";", "# replace the old upload file with new.", "}", "else", "{", "throw", "new", "\\", "Exception", "(", "\"Failed to open upload file for trimming.\"", ")", ";", "}", "}" ]
Go through the CSV file and trim the values. This saves memory by working line by line rather than reading everything into memory This will replace the existing file's contents, so if you need to keep that, make a copy first. @param sring $filepath - the path to the CSV file we are trimming @param string $delimiter - the delimiter used in the CSV. E.g. ',' or ';' @throws \Exception
[ "Go", "through", "the", "CSV", "file", "and", "trim", "the", "values", ".", "This", "saves", "memory", "by", "working", "line", "by", "line", "rather", "than", "reading", "everything", "into", "memory", "This", "will", "replace", "the", "existing", "file", "s", "contents", "so", "if", "you", "need", "to", "keep", "that", "make", "a", "copy", "first", "." ]
244871d2fbc2f3fac26ff4b98715224953d9befb
https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/CsvLib.php#L260-L292
1,981
iRAP-software/package-core-libs
src/CsvLib.php
CsvLib.removeColumns
public static function removeColumns($filepath, array $columnIndexes, $delimiter=",", $enclosure='"') { $tmpFile = tmpfile(); $fileHandle = fopen($filepath, "r"); $lineNumber = 1; if ($fileHandle) { while (!feof($fileHandle)) { $lineArray = fgetcsv($fileHandle, 0, $delimiter, $enclosure); if (!empty($lineArray)) { foreach ($columnIndexes as $columnHumanIndex) { $columnIndex = $columnHumanIndex - 1; if (!isset($lineArray[$columnIndex])) { $msg = "removeColumns: source CSV file does not have " . "column: " . $columnIndex . " on line: " . $lineNumber; throw new \Exception($msg); } unset($lineArray[$columnIndex]); } fputcsv($tmpFile, $lineArray, $delimiter, $enclosure); } $lineNumber++; } fclose($fileHandle); $meta_data = stream_get_meta_data($tmpFile); $tmpFileName = $meta_data["uri"]; rename($tmpFileName, $filepath); # replace the old upload file with new. } else { throw new \Exception("removeColumns: failed to open CSV file for trimming."); } }
php
public static function removeColumns($filepath, array $columnIndexes, $delimiter=",", $enclosure='"') { $tmpFile = tmpfile(); $fileHandle = fopen($filepath, "r"); $lineNumber = 1; if ($fileHandle) { while (!feof($fileHandle)) { $lineArray = fgetcsv($fileHandle, 0, $delimiter, $enclosure); if (!empty($lineArray)) { foreach ($columnIndexes as $columnHumanIndex) { $columnIndex = $columnHumanIndex - 1; if (!isset($lineArray[$columnIndex])) { $msg = "removeColumns: source CSV file does not have " . "column: " . $columnIndex . " on line: " . $lineNumber; throw new \Exception($msg); } unset($lineArray[$columnIndex]); } fputcsv($tmpFile, $lineArray, $delimiter, $enclosure); } $lineNumber++; } fclose($fileHandle); $meta_data = stream_get_meta_data($tmpFile); $tmpFileName = $meta_data["uri"]; rename($tmpFileName, $filepath); # replace the old upload file with new. } else { throw new \Exception("removeColumns: failed to open CSV file for trimming."); } }
[ "public", "static", "function", "removeColumns", "(", "$", "filepath", ",", "array", "$", "columnIndexes", ",", "$", "delimiter", "=", "\",\"", ",", "$", "enclosure", "=", "'\"'", ")", "{", "$", "tmpFile", "=", "tmpfile", "(", ")", ";", "$", "fileHandle", "=", "fopen", "(", "$", "filepath", ",", "\"r\"", ")", ";", "$", "lineNumber", "=", "1", ";", "if", "(", "$", "fileHandle", ")", "{", "while", "(", "!", "feof", "(", "$", "fileHandle", ")", ")", "{", "$", "lineArray", "=", "fgetcsv", "(", "$", "fileHandle", ",", "0", ",", "$", "delimiter", ",", "$", "enclosure", ")", ";", "if", "(", "!", "empty", "(", "$", "lineArray", ")", ")", "{", "foreach", "(", "$", "columnIndexes", "as", "$", "columnHumanIndex", ")", "{", "$", "columnIndex", "=", "$", "columnHumanIndex", "-", "1", ";", "if", "(", "!", "isset", "(", "$", "lineArray", "[", "$", "columnIndex", "]", ")", ")", "{", "$", "msg", "=", "\"removeColumns: source CSV file does not have \"", ".", "\"column: \"", ".", "$", "columnIndex", ".", "\" on line: \"", ".", "$", "lineNumber", ";", "throw", "new", "\\", "Exception", "(", "$", "msg", ")", ";", "}", "unset", "(", "$", "lineArray", "[", "$", "columnIndex", "]", ")", ";", "}", "fputcsv", "(", "$", "tmpFile", ",", "$", "lineArray", ",", "$", "delimiter", ",", "$", "enclosure", ")", ";", "}", "$", "lineNumber", "++", ";", "}", "fclose", "(", "$", "fileHandle", ")", ";", "$", "meta_data", "=", "stream_get_meta_data", "(", "$", "tmpFile", ")", ";", "$", "tmpFileName", "=", "$", "meta_data", "[", "\"uri\"", "]", ";", "rename", "(", "$", "tmpFileName", ",", "$", "filepath", ")", ";", "# replace the old upload file with new.", "}", "else", "{", "throw", "new", "\\", "Exception", "(", "\"removeColumns: failed to open CSV file for trimming.\"", ")", ";", "}", "}" ]
Remove columns from a CSV file. @param string $filepath - the path of the CSV file we are modifying. @param array $columnIndexes - array of integers specifying the column indexes to remove, starting at 1 @param string $delimiter - optionally specify the delimiter if it isn't a comma @param string $enclosure - optionally specify the enclosure if it isn't double quote
[ "Remove", "columns", "from", "a", "CSV", "file", "." ]
244871d2fbc2f3fac26ff4b98715224953d9befb
https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/CsvLib.php#L302-L347
1,982
iRAP-software/package-core-libs
src/CsvLib.php
CsvLib.removeRows
public static function removeRows($filepath, array $rowIndexes, $delimiter=",", $enclosure='"') { $tmpFile = tmpfile(); $fileHandle = fopen($filepath, "r"); $lineNumber = 1; if ($fileHandle) { while (!feof($fileHandle)) { $lineArray = fgetcsv($fileHandle, 0, $delimiter, $enclosure); if ($lineArray) { if (!in_array($lineNumber, $rowIndexes)) { fputcsv($tmpFile, $lineArray, $delimiter, $enclosure); } } $lineNumber++; } fclose($fileHandle); $meta_data = stream_get_meta_data($tmpFile); $tmpFileName = $meta_data["uri"]; rename($tmpFileName, $filepath); # replace the old upload file with new. } else { throw new \Exception("removeRows: Failed to open CSV file for trimming."); } }
php
public static function removeRows($filepath, array $rowIndexes, $delimiter=",", $enclosure='"') { $tmpFile = tmpfile(); $fileHandle = fopen($filepath, "r"); $lineNumber = 1; if ($fileHandle) { while (!feof($fileHandle)) { $lineArray = fgetcsv($fileHandle, 0, $delimiter, $enclosure); if ($lineArray) { if (!in_array($lineNumber, $rowIndexes)) { fputcsv($tmpFile, $lineArray, $delimiter, $enclosure); } } $lineNumber++; } fclose($fileHandle); $meta_data = stream_get_meta_data($tmpFile); $tmpFileName = $meta_data["uri"]; rename($tmpFileName, $filepath); # replace the old upload file with new. } else { throw new \Exception("removeRows: Failed to open CSV file for trimming."); } }
[ "public", "static", "function", "removeRows", "(", "$", "filepath", ",", "array", "$", "rowIndexes", ",", "$", "delimiter", "=", "\",\"", ",", "$", "enclosure", "=", "'\"'", ")", "{", "$", "tmpFile", "=", "tmpfile", "(", ")", ";", "$", "fileHandle", "=", "fopen", "(", "$", "filepath", ",", "\"r\"", ")", ";", "$", "lineNumber", "=", "1", ";", "if", "(", "$", "fileHandle", ")", "{", "while", "(", "!", "feof", "(", "$", "fileHandle", ")", ")", "{", "$", "lineArray", "=", "fgetcsv", "(", "$", "fileHandle", ",", "0", ",", "$", "delimiter", ",", "$", "enclosure", ")", ";", "if", "(", "$", "lineArray", ")", "{", "if", "(", "!", "in_array", "(", "$", "lineNumber", ",", "$", "rowIndexes", ")", ")", "{", "fputcsv", "(", "$", "tmpFile", ",", "$", "lineArray", ",", "$", "delimiter", ",", "$", "enclosure", ")", ";", "}", "}", "$", "lineNumber", "++", ";", "}", "fclose", "(", "$", "fileHandle", ")", ";", "$", "meta_data", "=", "stream_get_meta_data", "(", "$", "tmpFile", ")", ";", "$", "tmpFileName", "=", "$", "meta_data", "[", "\"uri\"", "]", ";", "rename", "(", "$", "tmpFileName", ",", "$", "filepath", ")", ";", "# replace the old upload file with new.", "}", "else", "{", "throw", "new", "\\", "Exception", "(", "\"removeRows: Failed to open CSV file for trimming.\"", ")", ";", "}", "}" ]
Remove rows from a CSV file. @param string $filepath - the path of the CSV file we are modifying. @param array $rowIndexes - array of integers specifying the row numbers to remove, starting at 1 @param string $delimiter - optionally specify the delimiter if it isn't a comma @param string $enclosure - optionally specify the enclosure if it isn't double quote
[ "Remove", "rows", "from", "a", "CSV", "file", "." ]
244871d2fbc2f3fac26ff4b98715224953d9befb
https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/CsvLib.php#L357-L389
1,983
iRAP-software/package-core-libs
src/CsvLib.php
CsvLib.decimalDiff
public static function decimalDiff($filepath1, $filepath2, $delimiter=",", $enclosure='"') { $newFileName = tempnam(sys_get_temp_dir(), ""); $newFileHandle = fopen($newFileName, "w"); if (!$newFileHandle) { throw new \Exception("Cannot create file to store diff in."); } $fileHandle1 = fopen($filepath1, "r"); $fileHandle2 = fopen($filepath2, "r"); $lineNumber = 0; if ($fileHandle1 && $fileHandle2) { while (!feof($fileHandle1)) { $lineArray1 = fgetcsv($fileHandle1, 0, $delimiter, $enclosure); $lineArray2 = fgetcsv($fileHandle2, 0, $delimiter, $enclosure); $resultArray = array(); if ($lineArray1) { foreach ($lineArray1 as $index => $value1) { if (!isset($lineArray2[$index])) { throw new \Exception("decimalDiff: rows do not have the same column count."); } $value2 = $lineArray2[$index]; if (is_numeric($value1) && is_numeric($value2)) { $resultArray[$index] = $value1 - $value2; } else { if ($value1 === $value2) { $resultArray[$index] = $value1; } else { $resultArray[$index] = $value1 . "|" . $value2; } } } } fputcsv($newFileHandle, $resultArray, $delimiter, $enclosure); $lineNumber++; } fclose($fileHandle1); fclose($fileHandle2); fclose($newFileHandle); return $newFileName; } else { throw new \Exception("decimalDiff: Failed to open CSV file for processing."); } return $newFileName; }
php
public static function decimalDiff($filepath1, $filepath2, $delimiter=",", $enclosure='"') { $newFileName = tempnam(sys_get_temp_dir(), ""); $newFileHandle = fopen($newFileName, "w"); if (!$newFileHandle) { throw new \Exception("Cannot create file to store diff in."); } $fileHandle1 = fopen($filepath1, "r"); $fileHandle2 = fopen($filepath2, "r"); $lineNumber = 0; if ($fileHandle1 && $fileHandle2) { while (!feof($fileHandle1)) { $lineArray1 = fgetcsv($fileHandle1, 0, $delimiter, $enclosure); $lineArray2 = fgetcsv($fileHandle2, 0, $delimiter, $enclosure); $resultArray = array(); if ($lineArray1) { foreach ($lineArray1 as $index => $value1) { if (!isset($lineArray2[$index])) { throw new \Exception("decimalDiff: rows do not have the same column count."); } $value2 = $lineArray2[$index]; if (is_numeric($value1) && is_numeric($value2)) { $resultArray[$index] = $value1 - $value2; } else { if ($value1 === $value2) { $resultArray[$index] = $value1; } else { $resultArray[$index] = $value1 . "|" . $value2; } } } } fputcsv($newFileHandle, $resultArray, $delimiter, $enclosure); $lineNumber++; } fclose($fileHandle1); fclose($fileHandle2); fclose($newFileHandle); return $newFileName; } else { throw new \Exception("decimalDiff: Failed to open CSV file for processing."); } return $newFileName; }
[ "public", "static", "function", "decimalDiff", "(", "$", "filepath1", ",", "$", "filepath2", ",", "$", "delimiter", "=", "\",\"", ",", "$", "enclosure", "=", "'\"'", ")", "{", "$", "newFileName", "=", "tempnam", "(", "sys_get_temp_dir", "(", ")", ",", "\"\"", ")", ";", "$", "newFileHandle", "=", "fopen", "(", "$", "newFileName", ",", "\"w\"", ")", ";", "if", "(", "!", "$", "newFileHandle", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Cannot create file to store diff in.\"", ")", ";", "}", "$", "fileHandle1", "=", "fopen", "(", "$", "filepath1", ",", "\"r\"", ")", ";", "$", "fileHandle2", "=", "fopen", "(", "$", "filepath2", ",", "\"r\"", ")", ";", "$", "lineNumber", "=", "0", ";", "if", "(", "$", "fileHandle1", "&&", "$", "fileHandle2", ")", "{", "while", "(", "!", "feof", "(", "$", "fileHandle1", ")", ")", "{", "$", "lineArray1", "=", "fgetcsv", "(", "$", "fileHandle1", ",", "0", ",", "$", "delimiter", ",", "$", "enclosure", ")", ";", "$", "lineArray2", "=", "fgetcsv", "(", "$", "fileHandle2", ",", "0", ",", "$", "delimiter", ",", "$", "enclosure", ")", ";", "$", "resultArray", "=", "array", "(", ")", ";", "if", "(", "$", "lineArray1", ")", "{", "foreach", "(", "$", "lineArray1", "as", "$", "index", "=>", "$", "value1", ")", "{", "if", "(", "!", "isset", "(", "$", "lineArray2", "[", "$", "index", "]", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "\"decimalDiff: rows do not have the same column count.\"", ")", ";", "}", "$", "value2", "=", "$", "lineArray2", "[", "$", "index", "]", ";", "if", "(", "is_numeric", "(", "$", "value1", ")", "&&", "is_numeric", "(", "$", "value2", ")", ")", "{", "$", "resultArray", "[", "$", "index", "]", "=", "$", "value1", "-", "$", "value2", ";", "}", "else", "{", "if", "(", "$", "value1", "===", "$", "value2", ")", "{", "$", "resultArray", "[", "$", "index", "]", "=", "$", "value1", ";", "}", "else", "{", "$", "resultArray", "[", "$", "index", "]", "=", "$", "value1", ".", "\"|\"", ".", "$", "value2", ";", "}", "}", "}", "}", "fputcsv", "(", "$", "newFileHandle", ",", "$", "resultArray", ",", "$", "delimiter", ",", "$", "enclosure", ")", ";", "$", "lineNumber", "++", ";", "}", "fclose", "(", "$", "fileHandle1", ")", ";", "fclose", "(", "$", "fileHandle2", ")", ";", "fclose", "(", "$", "newFileHandle", ")", ";", "return", "$", "newFileName", ";", "}", "else", "{", "throw", "new", "\\", "Exception", "(", "\"decimalDiff: Failed to open CSV file for processing.\"", ")", ";", "}", "return", "$", "newFileName", ";", "}" ]
Calculate the mathematical differences between two CSV files. If this comes across string values, it will check if they are the same and put the the string in if they are, otherwise, it will concatenate the two values with a | divider. WARNING - this expects the two files to have the same number of columns and rows. @param string $filepath1 - path to a CSV file to compare. @param string $filepath2 - path to a CSV file to compare. @param string $delimiter - optionally specify the delimiter if it isn't a comma @param string $enclosure - optionally specify the enclosure if it isn't double quote @return string - the path to the created diff CSV file. @throws \Exception
[ "Calculate", "the", "mathematical", "differences", "between", "two", "CSV", "files", ".", "If", "this", "comes", "across", "string", "values", "it", "will", "check", "if", "they", "are", "the", "same", "and", "put", "the", "the", "string", "in", "if", "they", "are", "otherwise", "it", "will", "concatenate", "the", "two", "values", "with", "a", "|", "divider", ".", "WARNING", "-", "this", "expects", "the", "two", "files", "to", "have", "the", "same", "number", "of", "columns", "and", "rows", "." ]
244871d2fbc2f3fac26ff4b98715224953d9befb
https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/CsvLib.php#L404-L471
1,984
iRAP-software/package-core-libs
src/CsvLib.php
CsvLib.diffTolerance
public static function diffTolerance($filepath1, $filepath2, array $tolerances, $compareOtherColumns = true, $delimiter=",", $enclosure='"') { $hasFailed = false; $humanRowNumber = 1; $fileHandle1 = fopen($filepath1, "r"); $fileHandle2 = fopen($filepath2, "r"); if (!$fileHandle1 || !$fileHandle2) { throw new \Exception("diffTolerance: Failed to open CSV files for comparison."); } while (!feof($fileHandle1) && $hasFailed === FALSE) { $lineArray1 = fgetcsv($fileHandle1, 0, $delimiter, $enclosure); $lineArray2 = fgetcsv($fileHandle2, 0, $delimiter, $enclosure); if ($lineArray1) { foreach ($lineArray1 as $index => $value1) { $humanColumnNumber = $index + 1; if (!isset($lineArray2[$index])) { throw new \Exception("decimalDiff: rows do not have the same column count."); } $value2 = $lineArray2[$index]; if ($compareOtherColumns || (isset($tolerances[$humanColumnNumber]))) { if (is_numeric($value1) && is_numeric($value2)) { $numericDifference = abs($value1 - $value2); if (isset($tolerances[$humanColumnNumber])) { if ($numericDifference > $tolerances[$humanColumnNumber]) { $hasFailed = TRUE; } } else { if ($numericDifference > 0) // can't use !== on the values as 1.100 !== 1.1 { $hasFailed = TRUE; } } } else { // comparing non numeric values... if (isset($tolerances[$humanColumnNumber])) { $msg = "diffTolerance: Trying to perform numeric tolerance " . "diff on non numeric column. Column: $humanColumnNumber " . "Row: $humanRowNumber"; throw new \Exception($msg); } } } else { // Skip this column as we don't wish to check it. } } } $humanRowNumber++; } fclose($fileHandle1); fclose($fileHandle2); $passed = !$hasFailed; return $passed; }
php
public static function diffTolerance($filepath1, $filepath2, array $tolerances, $compareOtherColumns = true, $delimiter=",", $enclosure='"') { $hasFailed = false; $humanRowNumber = 1; $fileHandle1 = fopen($filepath1, "r"); $fileHandle2 = fopen($filepath2, "r"); if (!$fileHandle1 || !$fileHandle2) { throw new \Exception("diffTolerance: Failed to open CSV files for comparison."); } while (!feof($fileHandle1) && $hasFailed === FALSE) { $lineArray1 = fgetcsv($fileHandle1, 0, $delimiter, $enclosure); $lineArray2 = fgetcsv($fileHandle2, 0, $delimiter, $enclosure); if ($lineArray1) { foreach ($lineArray1 as $index => $value1) { $humanColumnNumber = $index + 1; if (!isset($lineArray2[$index])) { throw new \Exception("decimalDiff: rows do not have the same column count."); } $value2 = $lineArray2[$index]; if ($compareOtherColumns || (isset($tolerances[$humanColumnNumber]))) { if (is_numeric($value1) && is_numeric($value2)) { $numericDifference = abs($value1 - $value2); if (isset($tolerances[$humanColumnNumber])) { if ($numericDifference > $tolerances[$humanColumnNumber]) { $hasFailed = TRUE; } } else { if ($numericDifference > 0) // can't use !== on the values as 1.100 !== 1.1 { $hasFailed = TRUE; } } } else { // comparing non numeric values... if (isset($tolerances[$humanColumnNumber])) { $msg = "diffTolerance: Trying to perform numeric tolerance " . "diff on non numeric column. Column: $humanColumnNumber " . "Row: $humanRowNumber"; throw new \Exception($msg); } } } else { // Skip this column as we don't wish to check it. } } } $humanRowNumber++; } fclose($fileHandle1); fclose($fileHandle2); $passed = !$hasFailed; return $passed; }
[ "public", "static", "function", "diffTolerance", "(", "$", "filepath1", ",", "$", "filepath2", ",", "array", "$", "tolerances", ",", "$", "compareOtherColumns", "=", "true", ",", "$", "delimiter", "=", "\",\"", ",", "$", "enclosure", "=", "'\"'", ")", "{", "$", "hasFailed", "=", "false", ";", "$", "humanRowNumber", "=", "1", ";", "$", "fileHandle1", "=", "fopen", "(", "$", "filepath1", ",", "\"r\"", ")", ";", "$", "fileHandle2", "=", "fopen", "(", "$", "filepath2", ",", "\"r\"", ")", ";", "if", "(", "!", "$", "fileHandle1", "||", "!", "$", "fileHandle2", ")", "{", "throw", "new", "\\", "Exception", "(", "\"diffTolerance: Failed to open CSV files for comparison.\"", ")", ";", "}", "while", "(", "!", "feof", "(", "$", "fileHandle1", ")", "&&", "$", "hasFailed", "===", "FALSE", ")", "{", "$", "lineArray1", "=", "fgetcsv", "(", "$", "fileHandle1", ",", "0", ",", "$", "delimiter", ",", "$", "enclosure", ")", ";", "$", "lineArray2", "=", "fgetcsv", "(", "$", "fileHandle2", ",", "0", ",", "$", "delimiter", ",", "$", "enclosure", ")", ";", "if", "(", "$", "lineArray1", ")", "{", "foreach", "(", "$", "lineArray1", "as", "$", "index", "=>", "$", "value1", ")", "{", "$", "humanColumnNumber", "=", "$", "index", "+", "1", ";", "if", "(", "!", "isset", "(", "$", "lineArray2", "[", "$", "index", "]", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "\"decimalDiff: rows do not have the same column count.\"", ")", ";", "}", "$", "value2", "=", "$", "lineArray2", "[", "$", "index", "]", ";", "if", "(", "$", "compareOtherColumns", "||", "(", "isset", "(", "$", "tolerances", "[", "$", "humanColumnNumber", "]", ")", ")", ")", "{", "if", "(", "is_numeric", "(", "$", "value1", ")", "&&", "is_numeric", "(", "$", "value2", ")", ")", "{", "$", "numericDifference", "=", "abs", "(", "$", "value1", "-", "$", "value2", ")", ";", "if", "(", "isset", "(", "$", "tolerances", "[", "$", "humanColumnNumber", "]", ")", ")", "{", "if", "(", "$", "numericDifference", ">", "$", "tolerances", "[", "$", "humanColumnNumber", "]", ")", "{", "$", "hasFailed", "=", "TRUE", ";", "}", "}", "else", "{", "if", "(", "$", "numericDifference", ">", "0", ")", "// can't use !== on the values as 1.100 !== 1.1", "{", "$", "hasFailed", "=", "TRUE", ";", "}", "}", "}", "else", "{", "// comparing non numeric values...", "if", "(", "isset", "(", "$", "tolerances", "[", "$", "humanColumnNumber", "]", ")", ")", "{", "$", "msg", "=", "\"diffTolerance: Trying to perform numeric tolerance \"", ".", "\"diff on non numeric column. Column: $humanColumnNumber \"", ".", "\"Row: $humanRowNumber\"", ";", "throw", "new", "\\", "Exception", "(", "$", "msg", ")", ";", "}", "}", "}", "else", "{", "// Skip this column as we don't wish to check it.", "}", "}", "}", "$", "humanRowNumber", "++", ";", "}", "fclose", "(", "$", "fileHandle1", ")", ";", "fclose", "(", "$", "fileHandle2", ")", ";", "$", "passed", "=", "!", "$", "hasFailed", ";", "return", "$", "passed", ";", "}" ]
Perform a diff on two CSV files with a tolerance of values being different by the amount specified. This can be useful in situations with floating point values where the last decimal place may be different. WARNING: if your CSV file has headers, you will need to remove them with a call to CsvLib::removeRows @param string $filepath1 - the path to the file we are checking @param array $tolerances - array of column index / tolerance pairs. For this function, the columns indexes start from 1, not 0. @param bool $compareOtherColumns - optionally specify false to tell this function to ignore all the other columns and only compare the ones specified in the tolerances array. @param type $delimiter - optionally specify the delimiter to pass to fgetcsv (comma default) @param string $enclosure - optionally specify the enclosure to pass to fgetcsv (default: ") @return bool - true if the files are the same, false if different. @throws \Exception
[ "Perform", "a", "diff", "on", "two", "CSV", "files", "with", "a", "tolerance", "of", "values", "being", "different", "by", "the", "amount", "specified", ".", "This", "can", "be", "useful", "in", "situations", "with", "floating", "point", "values", "where", "the", "last", "decimal", "place", "may", "be", "different", "." ]
244871d2fbc2f3fac26ff4b98715224953d9befb
https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/CsvLib.php#L493-L572
1,985
novuso/common
src/Application/Messaging/Command/Routing/ServiceAwareCommandMap.php
ServiceAwareCommandMap.registerHandler
public function registerHandler(string $commandClass, string $serviceName): void { if (!Validate::implementsInterface($commandClass, Command::class)) { $message = sprintf('Invalid command class: %s', $commandClass); throw new DomainException($message); } $type = Type::create($commandClass)->toString(); $this->handlers[$type] = $serviceName; }
php
public function registerHandler(string $commandClass, string $serviceName): void { if (!Validate::implementsInterface($commandClass, Command::class)) { $message = sprintf('Invalid command class: %s', $commandClass); throw new DomainException($message); } $type = Type::create($commandClass)->toString(); $this->handlers[$type] = $serviceName; }
[ "public", "function", "registerHandler", "(", "string", "$", "commandClass", ",", "string", "$", "serviceName", ")", ":", "void", "{", "if", "(", "!", "Validate", "::", "implementsInterface", "(", "$", "commandClass", ",", "Command", "::", "class", ")", ")", "{", "$", "message", "=", "sprintf", "(", "'Invalid command class: %s'", ",", "$", "commandClass", ")", ";", "throw", "new", "DomainException", "(", "$", "message", ")", ";", "}", "$", "type", "=", "Type", "::", "create", "(", "$", "commandClass", ")", "->", "toString", "(", ")", ";", "$", "this", "->", "handlers", "[", "$", "type", "]", "=", "$", "serviceName", ";", "}" ]
Registers a command handler @param string $commandClass The full command class name @param string $serviceName The handler service name @return void @throws DomainException When the command class is not valid
[ "Registers", "a", "command", "handler" ]
7d0e5a4f4c79c9622e068efc8b7c70815c460863
https://github.com/novuso/common/blob/7d0e5a4f4c79c9622e068efc8b7c70815c460863/src/Application/Messaging/Command/Routing/ServiceAwareCommandMap.php#L77-L87
1,986
othercodes/fcontroller
src/Core/Core.php
Core.registerModule
protected function registerModule($name, \OtherCode\FController\Modules\BaseModule $module) { $name = strtolower($name); if (!array_key_exists($name, $this->modules)) { $module->connect($this->services, $this->storage, $this->messages); $this->modules[$name] = $module; return true; } return false; }
php
protected function registerModule($name, \OtherCode\FController\Modules\BaseModule $module) { $name = strtolower($name); if (!array_key_exists($name, $this->modules)) { $module->connect($this->services, $this->storage, $this->messages); $this->modules[$name] = $module; return true; } return false; }
[ "protected", "function", "registerModule", "(", "$", "name", ",", "\\", "OtherCode", "\\", "FController", "\\", "Modules", "\\", "BaseModule", "$", "module", ")", "{", "$", "name", "=", "strtolower", "(", "$", "name", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "modules", ")", ")", "{", "$", "module", "->", "connect", "(", "$", "this", "->", "services", ",", "$", "this", "->", "storage", ",", "$", "this", "->", "messages", ")", ";", "$", "this", "->", "modules", "[", "$", "name", "]", "=", "$", "module", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Register and instantiate a new module @param string $name @param \OtherCode\FController\Modules\BaseModule $module @return boolean
[ "Register", "and", "instantiate", "a", "new", "module" ]
866e5906d6150a344a57caf0560fd273fbc448a8
https://github.com/othercodes/fcontroller/blob/866e5906d6150a344a57caf0560fd273fbc448a8/src/Core/Core.php#L95-L106
1,987
othercodes/fcontroller
src/Core/Core.php
Core.unregisterModule
public function unregisterModule($name) { if (array_key_exists($name, $this->modules)) { unset($this->modules[$name]); return true; } return false; }
php
public function unregisterModule($name) { if (array_key_exists($name, $this->modules)) { unset($this->modules[$name]); return true; } return false; }
[ "public", "function", "unregisterModule", "(", "$", "name", ")", "{", "if", "(", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "modules", ")", ")", "{", "unset", "(", "$", "this", "->", "modules", "[", "$", "name", "]", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Un register a module @param $name string @return boolean
[ "Un", "register", "a", "module" ]
866e5906d6150a344a57caf0560fd273fbc448a8
https://github.com/othercodes/fcontroller/blob/866e5906d6150a344a57caf0560fd273fbc448a8/src/Core/Core.php#L113-L120
1,988
othercodes/fcontroller
src/Core/Core.php
Core.registerService
protected function registerService($name, $service) { $name = strtolower($name); if (!isset($this->services->$name)) { $this->services->$name = $service; return true; } return false; }
php
protected function registerService($name, $service) { $name = strtolower($name); if (!isset($this->services->$name)) { $this->services->$name = $service; return true; } return false; }
[ "protected", "function", "registerService", "(", "$", "name", ",", "$", "service", ")", "{", "$", "name", "=", "strtolower", "(", "$", "name", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "services", "->", "$", "name", ")", ")", "{", "$", "this", "->", "services", "->", "$", "name", "=", "$", "service", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Register and instantiate a new service @param string $name string @param object $service @return boolean
[ "Register", "and", "instantiate", "a", "new", "service" ]
866e5906d6150a344a57caf0560fd273fbc448a8
https://github.com/othercodes/fcontroller/blob/866e5906d6150a344a57caf0560fd273fbc448a8/src/Core/Core.php#L128-L137
1,989
othercodes/fcontroller
src/Core/Core.php
Core.unregisterService
public function unregisterService($name) { $name = strtolower($name); if (isset($this->services->$name)) { unset($this->services->$name); return true; } return false; }
php
public function unregisterService($name) { $name = strtolower($name); if (isset($this->services->$name)) { unset($this->services->$name); return true; } return false; }
[ "public", "function", "unregisterService", "(", "$", "name", ")", "{", "$", "name", "=", "strtolower", "(", "$", "name", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "services", "->", "$", "name", ")", ")", "{", "unset", "(", "$", "this", "->", "services", "->", "$", "name", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Un register a service @param string $name @return boolean
[ "Un", "register", "a", "service" ]
866e5906d6150a344a57caf0560fd273fbc448a8
https://github.com/othercodes/fcontroller/blob/866e5906d6150a344a57caf0560fd273fbc448a8/src/Core/Core.php#L144-L153
1,990
othercodes/fcontroller
src/Core/Core.php
Core.run
public function run($path, $data = null) { $model = array(); /** * first we have get the correct path * of the module name and method to execute */ $callPath = $this->route($path); /** * once we have the module name and the * method name we build the payload and * data array. */ $payload = array( $this->modules[$callPath->module], $callPath->method ); if (isset($data)) { foreach ($data as $key => $argument) { $model[$key] = $argument; } } /** * here finally perform the actual call * to the module method requested. */ return call_user_func_array($payload, $model); }
php
public function run($path, $data = null) { $model = array(); /** * first we have get the correct path * of the module name and method to execute */ $callPath = $this->route($path); /** * once we have the module name and the * method name we build the payload and * data array. */ $payload = array( $this->modules[$callPath->module], $callPath->method ); if (isset($data)) { foreach ($data as $key => $argument) { $model[$key] = $argument; } } /** * here finally perform the actual call * to the module method requested. */ return call_user_func_array($payload, $model); }
[ "public", "function", "run", "(", "$", "path", ",", "$", "data", "=", "null", ")", "{", "$", "model", "=", "array", "(", ")", ";", "/**\n * first we have get the correct path\n * of the module name and method to execute\n */", "$", "callPath", "=", "$", "this", "->", "route", "(", "$", "path", ")", ";", "/**\n * once we have the module name and the\n * method name we build the payload and\n * data array.\n */", "$", "payload", "=", "array", "(", "$", "this", "->", "modules", "[", "$", "callPath", "->", "module", "]", ",", "$", "callPath", "->", "method", ")", ";", "if", "(", "isset", "(", "$", "data", ")", ")", "{", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "argument", ")", "{", "$", "model", "[", "$", "key", "]", "=", "$", "argument", ";", "}", "}", "/**\n * here finally perform the actual call\n * to the module method requested.\n */", "return", "call_user_func_array", "(", "$", "payload", ",", "$", "model", ")", ";", "}" ]
Perform the main call of the module method @param string $path @param object|array|null $data @return mixed
[ "Perform", "the", "main", "call", "of", "the", "module", "method" ]
866e5906d6150a344a57caf0560fd273fbc448a8
https://github.com/othercodes/fcontroller/blob/866e5906d6150a344a57caf0560fd273fbc448a8/src/Core/Core.php#L170-L201
1,991
othercodes/fcontroller
src/Core/Core.php
Core.route
protected function route($path) { /** * We check the pattern of the callPath * to construct the main call */ if (!preg_match('/[a-zA-Z0-9]\.[a-zA-Z0-9]/', $path)) { throw new \OtherCode\FController\Exceptions\FControllerException("Incorrect module call pattern", 400); } /** * If the match is good we have to explode * the path in different parts. */ $callPath = explode(".", $path); $module = strtolower($callPath[0]); $method = $callPath[1]; /** * Now we have to check if the module that we want to * call is available */ if (!array_key_exists($module, $this->modules)) { throw new \OtherCode\FController\Exceptions\NotFoundException("Module instance not found", 404); } /** * Finally we have to check that the requested method exists * in the module */ if (!method_exists($this->modules[$module], $method)) { throw new \OtherCode\FController\Exceptions\NotFoundException("Module method requested is not available", 405); } /** * Build the final payload and * return it to the main call method */ return (object)array( 'module' => $module, 'method' => $method ); }
php
protected function route($path) { /** * We check the pattern of the callPath * to construct the main call */ if (!preg_match('/[a-zA-Z0-9]\.[a-zA-Z0-9]/', $path)) { throw new \OtherCode\FController\Exceptions\FControllerException("Incorrect module call pattern", 400); } /** * If the match is good we have to explode * the path in different parts. */ $callPath = explode(".", $path); $module = strtolower($callPath[0]); $method = $callPath[1]; /** * Now we have to check if the module that we want to * call is available */ if (!array_key_exists($module, $this->modules)) { throw new \OtherCode\FController\Exceptions\NotFoundException("Module instance not found", 404); } /** * Finally we have to check that the requested method exists * in the module */ if (!method_exists($this->modules[$module], $method)) { throw new \OtherCode\FController\Exceptions\NotFoundException("Module method requested is not available", 405); } /** * Build the final payload and * return it to the main call method */ return (object)array( 'module' => $module, 'method' => $method ); }
[ "protected", "function", "route", "(", "$", "path", ")", "{", "/**\n * We check the pattern of the callPath\n * to construct the main call\n */", "if", "(", "!", "preg_match", "(", "'/[a-zA-Z0-9]\\.[a-zA-Z0-9]/'", ",", "$", "path", ")", ")", "{", "throw", "new", "\\", "OtherCode", "\\", "FController", "\\", "Exceptions", "\\", "FControllerException", "(", "\"Incorrect module call pattern\"", ",", "400", ")", ";", "}", "/**\n * If the match is good we have to explode\n * the path in different parts.\n */", "$", "callPath", "=", "explode", "(", "\".\"", ",", "$", "path", ")", ";", "$", "module", "=", "strtolower", "(", "$", "callPath", "[", "0", "]", ")", ";", "$", "method", "=", "$", "callPath", "[", "1", "]", ";", "/**\n * Now we have to check if the module that we want to\n * call is available\n */", "if", "(", "!", "array_key_exists", "(", "$", "module", ",", "$", "this", "->", "modules", ")", ")", "{", "throw", "new", "\\", "OtherCode", "\\", "FController", "\\", "Exceptions", "\\", "NotFoundException", "(", "\"Module instance not found\"", ",", "404", ")", ";", "}", "/**\n * Finally we have to check that the requested method exists\n * in the module\n */", "if", "(", "!", "method_exists", "(", "$", "this", "->", "modules", "[", "$", "module", "]", ",", "$", "method", ")", ")", "{", "throw", "new", "\\", "OtherCode", "\\", "FController", "\\", "Exceptions", "\\", "NotFoundException", "(", "\"Module method requested is not available\"", ",", "405", ")", ";", "}", "/**\n * Build the final payload and\n * return it to the main call method\n */", "return", "(", "object", ")", "array", "(", "'module'", "=>", "$", "module", ",", "'method'", "=>", "$", "method", ")", ";", "}" ]
Check and build the payload call @param $path @return object @throws \OtherCode\FController\Exceptions\FControllerException @throws \OtherCode\FController\Exceptions\NotFoundException
[ "Check", "and", "build", "the", "payload", "call" ]
866e5906d6150a344a57caf0560fd273fbc448a8
https://github.com/othercodes/fcontroller/blob/866e5906d6150a344a57caf0560fd273fbc448a8/src/Core/Core.php#L210-L254
1,992
jmpantoja/planb-utils
src/DS/Set/AbstractSet.php
AbstractSet.xor
public function xor(Set $set): SetInterface { $set = new \DS\Set($set); $items = $this->items->xor($set); return $this->duplicate($items); }
php
public function xor(Set $set): SetInterface { $set = new \DS\Set($set); $items = $this->items->xor($set); return $this->duplicate($items); }
[ "public", "function", "xor", "(", "Set", "$", "set", ")", ":", "SetInterface", "{", "$", "set", "=", "new", "\\", "DS", "\\", "Set", "(", "$", "set", ")", ";", "$", "items", "=", "$", "this", "->", "items", "->", "xor", "(", "$", "set", ")", ";", "return", "$", "this", "->", "duplicate", "(", "$", "items", ")", ";", "}" ]
Creates a new set using values in either this set or in another set, but not in both. Formally: A ⊖ B = {x : x ∈ (A \ B) ∪ (B \ A)} @param \PlanB\DS\Set $set @return \PlanB\DS\Set\SetInterface
[ "Creates", "a", "new", "set", "using", "values", "in", "either", "this", "set", "or", "in", "another", "set", "but", "not", "in", "both", "." ]
d17fbced4a285275928f8428ee56e269eb851690
https://github.com/jmpantoja/planb-utils/blob/d17fbced4a285275928f8428ee56e269eb851690/src/DS/Set/AbstractSet.php#L161-L167
1,993
jmpantoja/planb-utils
src/DS/Set/AbstractSet.php
AbstractSet.filter
public function filter(?callable $callback = null): SetInterface { $items = $callback ? $this->items->filter($callback) : $this->items->filter(); return $this->duplicate($items); }
php
public function filter(?callable $callback = null): SetInterface { $items = $callback ? $this->items->filter($callback) : $this->items->filter(); return $this->duplicate($items); }
[ "public", "function", "filter", "(", "?", "callable", "$", "callback", "=", "null", ")", ":", "SetInterface", "{", "$", "items", "=", "$", "callback", "?", "$", "this", "->", "items", "->", "filter", "(", "$", "callback", ")", ":", "$", "this", "->", "items", "->", "filter", "(", ")", ";", "return", "$", "this", "->", "duplicate", "(", "$", "items", ")", ";", "}" ]
Returns a new set containing only the values for which a callback returns true. A boolean test will be used if a callback is not provided. @param callable|null $callback Accepts a value, returns a boolean: true : include the value, false: skip the value. @return \PlanB\DS\Set\SetInterface
[ "Returns", "a", "new", "set", "containing", "only", "the", "values", "for", "which", "a", "callback", "returns", "true", ".", "A", "boolean", "test", "will", "be", "used", "if", "a", "callback", "is", "not", "provided", "." ]
d17fbced4a285275928f8428ee56e269eb851690
https://github.com/jmpantoja/planb-utils/blob/d17fbced4a285275928f8428ee56e269eb851690/src/DS/Set/AbstractSet.php#L179-L187
1,994
jmpantoja/planb-utils
src/DS/Set/AbstractSet.php
AbstractSet.sort
public function sort(?callable $comparator = null): SetInterface { $comparator ? $this->items->sort($comparator) : $this->items->sort(); return $this; }
php
public function sort(?callable $comparator = null): SetInterface { $comparator ? $this->items->sort($comparator) : $this->items->sort(); return $this; }
[ "public", "function", "sort", "(", "?", "callable", "$", "comparator", "=", "null", ")", ":", "SetInterface", "{", "$", "comparator", "?", "$", "this", "->", "items", "->", "sort", "(", "$", "comparator", ")", ":", "$", "this", "->", "items", "->", "sort", "(", ")", ";", "return", "$", "this", ";", "}" ]
Sorts the set in-place, based on an optional callable comparator. @param callable|null $comparator Accepts two values to be compared. Should return the result of a <=> b. @return \PlanB\DS\Set\SetInterface
[ "Sorts", "the", "set", "in", "-", "place", "based", "on", "an", "optional", "callable", "comparator", "." ]
d17fbced4a285275928f8428ee56e269eb851690
https://github.com/jmpantoja/planb-utils/blob/d17fbced4a285275928f8428ee56e269eb851690/src/DS/Set/AbstractSet.php#L338-L345
1,995
phox-pro/pulsar-core
src/app/Logic/Front/Helper.php
Helper.fromFile
public static function fromFile(string $file, string $package) { $html = ''; if (file_exists($file)) { $html = file_get_contents($file); $html = preg_replace( "/{(.*)template(.*)}/", "/templates/" . template() . "/" . $package, $html ); } return $html; }
php
public static function fromFile(string $file, string $package) { $html = ''; if (file_exists($file)) { $html = file_get_contents($file); $html = preg_replace( "/{(.*)template(.*)}/", "/templates/" . template() . "/" . $package, $html ); } return $html; }
[ "public", "static", "function", "fromFile", "(", "string", "$", "file", ",", "string", "$", "package", ")", "{", "$", "html", "=", "''", ";", "if", "(", "file_exists", "(", "$", "file", ")", ")", "{", "$", "html", "=", "file_get_contents", "(", "$", "file", ")", ";", "$", "html", "=", "preg_replace", "(", "\"/{(.*)template(.*)}/\"", ",", "\"/templates/\"", ".", "template", "(", ")", ".", "\"/\"", ".", "$", "package", ",", "$", "html", ")", ";", "}", "return", "$", "html", ";", "}" ]
Function for return html from file in template @param string $file @param string $package @return void
[ "Function", "for", "return", "html", "from", "file", "in", "template" ]
fa9c66f6578180253a65c91edf422fc3c51b32ba
https://github.com/phox-pro/pulsar-core/blob/fa9c66f6578180253a65c91edf422fc3c51b32ba/src/app/Logic/Front/Helper.php#L14-L25
1,996
felixarntz/config
src/AbstractConfig.php
AbstractConfig.has
public function has(string ...$path): bool { try { $this->get(...$path); } catch (ConfigKeyNotFoundException $e) { return false; } return true; }
php
public function has(string ...$path): bool { try { $this->get(...$path); } catch (ConfigKeyNotFoundException $e) { return false; } return true; }
[ "public", "function", "has", "(", "string", "...", "$", "path", ")", ":", "bool", "{", "try", "{", "$", "this", "->", "get", "(", "...", "$", "path", ")", ";", "}", "catch", "(", "ConfigKeyNotFoundException", "$", "e", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Check whether the config has a specific key. @since 1.0.0 @param string ...$path Key, or path segments if key is nested. @return bool True if the key exists, false otherwise.
[ "Check", "whether", "the", "config", "has", "a", "specific", "key", "." ]
7e4d6041927974800f850336a51e5dad11b4bdd8
https://github.com/felixarntz/config/blob/7e4d6041927974800f850336a51e5dad11b4bdd8/src/AbstractConfig.php#L57-L66
1,997
felixarntz/config
src/AbstractConfig.php
AbstractConfig.get
public function get(string ...$path) { if (count($path) === 1) { if (!$this->offsetExists($path[0])) { throw ConfigKeyNotFoundException::fromPath($path); } return $this->offsetGet($path[0]); } $keys = array_reverse($path); $arr = $this->getArrayCopy(); while (count($keys) > 0) { $key = array_pop($keys); if (!isset($arr[$key])) { throw ConfigKeyNotFoundException::fromPath($path); } $arr = $arr[$key]; } return $arr; }
php
public function get(string ...$path) { if (count($path) === 1) { if (!$this->offsetExists($path[0])) { throw ConfigKeyNotFoundException::fromPath($path); } return $this->offsetGet($path[0]); } $keys = array_reverse($path); $arr = $this->getArrayCopy(); while (count($keys) > 0) { $key = array_pop($keys); if (!isset($arr[$key])) { throw ConfigKeyNotFoundException::fromPath($path); } $arr = $arr[$key]; } return $arr; }
[ "public", "function", "get", "(", "string", "...", "$", "path", ")", "{", "if", "(", "count", "(", "$", "path", ")", "===", "1", ")", "{", "if", "(", "!", "$", "this", "->", "offsetExists", "(", "$", "path", "[", "0", "]", ")", ")", "{", "throw", "ConfigKeyNotFoundException", "::", "fromPath", "(", "$", "path", ")", ";", "}", "return", "$", "this", "->", "offsetGet", "(", "$", "path", "[", "0", "]", ")", ";", "}", "$", "keys", "=", "array_reverse", "(", "$", "path", ")", ";", "$", "arr", "=", "$", "this", "->", "getArrayCopy", "(", ")", ";", "while", "(", "count", "(", "$", "keys", ")", ">", "0", ")", "{", "$", "key", "=", "array_pop", "(", "$", "keys", ")", ";", "if", "(", "!", "isset", "(", "$", "arr", "[", "$", "key", "]", ")", ")", "{", "throw", "ConfigKeyNotFoundException", "::", "fromPath", "(", "$", "path", ")", ";", "}", "$", "arr", "=", "$", "arr", "[", "$", "key", "]", ";", "}", "return", "$", "arr", ";", "}" ]
Get the value for a specific key. @since 1.0.0 @param string ...$path Key, or path segments if key is nested. @return mixed Value for the key. @throws ConfigKeyNotFoundException Thrown if the key does not exist.
[ "Get", "the", "value", "for", "a", "specific", "key", "." ]
7e4d6041927974800f850336a51e5dad11b4bdd8
https://github.com/felixarntz/config/blob/7e4d6041927974800f850336a51e5dad11b4bdd8/src/AbstractConfig.php#L79-L101
1,998
emaphp/fluent-configuration
lib/FluentConfiguration.php
FluentConfiguration.setOption
public function setOption($name, $value) { $this->validateName($name); $this->config[$name] = $value; }
php
public function setOption($name, $value) { $this->validateName($name); $this->config[$name] = $value; }
[ "public", "function", "setOption", "(", "$", "name", ",", "$", "value", ")", "{", "$", "this", "->", "validateName", "(", "$", "name", ")", ";", "$", "this", "->", "config", "[", "$", "name", "]", "=", "$", "value", ";", "}" ]
Declares a non-transient configuration value @param string $name @param mixed $value @throws \InvalidArgumentException
[ "Declares", "a", "non", "-", "transient", "configuration", "value" ]
9f46a1902cbac91bb00e014f3511d8eaa4dfa6a3
https://github.com/emaphp/fluent-configuration/blob/9f46a1902cbac91bb00e014f3511d8eaa4dfa6a3/lib/FluentConfiguration.php#L51-L54
1,999
eureka-framework/component-container
src/Container/Container.php
Container.attach
public function attach($id, $instance) { if ($this->has($id)) { return $this; } $this->instances[$id] = $instance; return $this; }
php
public function attach($id, $instance) { if ($this->has($id)) { return $this; } $this->instances[$id] = $instance; return $this; }
[ "public", "function", "attach", "(", "$", "id", ",", "$", "instance", ")", "{", "if", "(", "$", "this", "->", "has", "(", "$", "id", ")", ")", "{", "return", "$", "this", ";", "}", "$", "this", "->", "instances", "[", "$", "id", "]", "=", "$", "instance", ";", "return", "$", "this", ";", "}" ]
Attach new instance of any class to this container. If already exists, does not attach the new instance. @param string $id Key name to retrieve the instance @param object $instance Instance to attach @param string $type Type of object @return self @throws \LogicException
[ "Attach", "new", "instance", "of", "any", "class", "to", "this", "container", ".", "If", "already", "exists", "does", "not", "attach", "the", "new", "instance", "." ]
051c695d5b6e7f9e90fcc40db27569a96f2782d4
https://github.com/eureka-framework/component-container/blob/051c695d5b6e7f9e90fcc40db27569a96f2782d4/src/Container/Container.php#L84-L93