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
3,100
FlexPress/component-shortcode
src/FlexPress/Components/Shortcode/Helper.php
Helper.registerShortcodes
public function registerShortcodes() { if (!function_exists('add_shortcode')) { return; } $this->shortcodes->rewind(); while ($this->shortcodes->valid()) { $shortcode = $this->shortcodes->current(); add_shortcode($shortcode->getName(), array($shortcode, 'getCallback')); $this->shortcodes->next(); } }
php
public function registerShortcodes() { if (!function_exists('add_shortcode')) { return; } $this->shortcodes->rewind(); while ($this->shortcodes->valid()) { $shortcode = $this->shortcodes->current(); add_shortcode($shortcode->getName(), array($shortcode, 'getCallback')); $this->shortcodes->next(); } }
[ "public", "function", "registerShortcodes", "(", ")", "{", "if", "(", "!", "function_exists", "(", "'add_shortcode'", ")", ")", "{", "return", ";", "}", "$", "this", "->", "shortcodes", "->", "rewind", "(", ")", ";", "while", "(", "$", "this", "->", "shortcodes", "->", "valid", "(", ")", ")", "{", "$", "shortcode", "=", "$", "this", "->", "shortcodes", "->", "current", "(", ")", ";", "add_shortcode", "(", "$", "shortcode", "->", "getName", "(", ")", ",", "array", "(", "$", "shortcode", ",", "'getCallback'", ")", ")", ";", "$", "this", "->", "shortcodes", "->", "next", "(", ")", ";", "}", "}" ]
Registers all shortcodes added @author Tim Perry
[ "Registers", "all", "shortcodes", "added" ]
6da0e06f3a60650988e85fe78e562be6a9f8b0c5
https://github.com/FlexPress/component-shortcode/blob/6da0e06f3a60650988e85fe78e562be6a9f8b0c5/src/FlexPress/Components/Shortcode/Helper.php#L42-L58
3,101
Niirrty/Niirrty.Observer
src/Observable.php
Observable.subscribe
public function subscribe( IObserver $observer ) : IObservable { if ( ! \in_array( $observer, $this->_observers, true ) ) { $this->_observers[] = $observer; } return $this; }
php
public function subscribe( IObserver $observer ) : IObservable { if ( ! \in_array( $observer, $this->_observers, true ) ) { $this->_observers[] = $observer; } return $this; }
[ "public", "function", "subscribe", "(", "IObserver", "$", "observer", ")", ":", "IObservable", "{", "if", "(", "!", "\\", "in_array", "(", "$", "observer", ",", "$", "this", "->", "_observers", ",", "true", ")", ")", "{", "$", "this", "->", "_observers", "[", "]", "=", "$", "observer", ";", "}", "return", "$", "this", ";", "}" ]
Subscribe a new observer to this observable implementation. @param \Niirrty\Observer\IObserver $observer @return \Niirrty\Observer\IObservable
[ "Subscribe", "a", "new", "observer", "to", "this", "observable", "implementation", "." ]
fc019a97b8102b14ae5c5c3302e8828e09940a79
https://github.com/Niirrty/Niirrty.Observer/blob/fc019a97b8102b14ae5c5c3302e8828e09940a79/src/Observable.php#L70-L80
3,102
Niirrty/Niirrty.Observer
src/Observable.php
Observable.notify
public function notify( $extras = null ) : IObservable { if ( 1 < \count( $this->_cache ) ) { $this->_cache[] = $extras; } else { $this->_cache = $extras; } foreach ( $this->_observers as $ob ) { $ob->onUpdate( $this, $this->_cache ); } $this->_cache = []; return $this; }
php
public function notify( $extras = null ) : IObservable { if ( 1 < \count( $this->_cache ) ) { $this->_cache[] = $extras; } else { $this->_cache = $extras; } foreach ( $this->_observers as $ob ) { $ob->onUpdate( $this, $this->_cache ); } $this->_cache = []; return $this; }
[ "public", "function", "notify", "(", "$", "extras", "=", "null", ")", ":", "IObservable", "{", "if", "(", "1", "<", "\\", "count", "(", "$", "this", "->", "_cache", ")", ")", "{", "$", "this", "->", "_cache", "[", "]", "=", "$", "extras", ";", "}", "else", "{", "$", "this", "->", "_cache", "=", "$", "extras", ";", "}", "foreach", "(", "$", "this", "->", "_observers", "as", "$", "ob", ")", "{", "$", "ob", "->", "onUpdate", "(", "$", "this", ",", "$", "this", "->", "_cache", ")", ";", "}", "$", "this", "->", "_cache", "=", "[", "]", ";", "return", "$", "this", ";", "}" ]
Notify all subscribed observers @param mixed $extras @return \Niirrty\Observer\IObservable
[ "Notify", "all", "subscribed", "observers" ]
fc019a97b8102b14ae5c5c3302e8828e09940a79
https://github.com/Niirrty/Niirrty.Observer/blob/fc019a97b8102b14ae5c5c3302e8828e09940a79/src/Observable.php#L113-L134
3,103
WasabiLib/wasabilib
src/WasabiLib/Wizard/Wizard.php
Wizard.isFirstCall
public function isFirstCall() { if (!$this->stepAction && $this->stepCollection->isFirst($this->stepCollectionIterator->current())) return true; else return false; }
php
public function isFirstCall() { if (!$this->stepAction && $this->stepCollection->isFirst($this->stepCollectionIterator->current())) return true; else return false; }
[ "public", "function", "isFirstCall", "(", ")", "{", "if", "(", "!", "$", "this", "->", "stepAction", "&&", "$", "this", "->", "stepCollection", "->", "isFirst", "(", "$", "this", "->", "stepCollectionIterator", "->", "current", "(", ")", ")", ")", "return", "true", ";", "else", "return", "false", ";", "}" ]
checks if the wizard is first time called @return bool
[ "checks", "if", "the", "wizard", "is", "first", "time", "called" ]
5a55bfbea6b6ee10222c521112d469015db170b7
https://github.com/WasabiLib/wasabilib/blob/5a55bfbea6b6ee10222c521112d469015db170b7/src/WasabiLib/Wizard/Wizard.php#L207-L211
3,104
WasabiLib/wasabilib
src/WasabiLib/Wizard/Wizard.php
Wizard.process
public function process() { /* @var $currentStep StepController */ /* @var $ancestorStep StepController */ /* @var $descendantStep StepController */ $currentStep = $this->stepCollectionIterator->current(); if ($this->stepAction == self::WIZARD_STEP_ACTION_PREV && !$this->stepCollection->isFirst($this->stepCollectionIterator->current())) { $currentStep->leaveToAncestorStep(); $this->stepCollectionIterator->previous(); $ancestorStep = $this->stepCollectionIterator->current(); $ancestorStep->enterFromDescendant(); $this->resultContent = $this->prepareNextStepView($ancestorStep); } elseif ($this->stepAction == self::WIZARD_STEP_ACTION_PREV && $this->stepCollection->isFirst($this->stepCollectionIterator->current())) { $this->resultContent = new ResponseConfigurator(); } if ($this->stepAction == self::WIZARD_STEP_ACTION_NEXT) { $currentStep->preProcess(); if ($currentStep->process($currentStep->standardClosureArguments())) { $currentStep->postProcess(); $currentStep->leaveStep(); $this->stepCollectionIterator->next(); $descendantStep = $this->stepCollectionIterator->current(); $descendantStep->enterStep(); $this->resultContent = $this->prepareNextStepView($descendantStep); } else { $this->resultContent = $this->prepareNextStepView($currentStep); $this->resultContent->setVariable("errorMessage", $currentStep->getProcessErrorMessage()); } } }
php
public function process() { /* @var $currentStep StepController */ /* @var $ancestorStep StepController */ /* @var $descendantStep StepController */ $currentStep = $this->stepCollectionIterator->current(); if ($this->stepAction == self::WIZARD_STEP_ACTION_PREV && !$this->stepCollection->isFirst($this->stepCollectionIterator->current())) { $currentStep->leaveToAncestorStep(); $this->stepCollectionIterator->previous(); $ancestorStep = $this->stepCollectionIterator->current(); $ancestorStep->enterFromDescendant(); $this->resultContent = $this->prepareNextStepView($ancestorStep); } elseif ($this->stepAction == self::WIZARD_STEP_ACTION_PREV && $this->stepCollection->isFirst($this->stepCollectionIterator->current())) { $this->resultContent = new ResponseConfigurator(); } if ($this->stepAction == self::WIZARD_STEP_ACTION_NEXT) { $currentStep->preProcess(); if ($currentStep->process($currentStep->standardClosureArguments())) { $currentStep->postProcess(); $currentStep->leaveStep(); $this->stepCollectionIterator->next(); $descendantStep = $this->stepCollectionIterator->current(); $descendantStep->enterStep(); $this->resultContent = $this->prepareNextStepView($descendantStep); } else { $this->resultContent = $this->prepareNextStepView($currentStep); $this->resultContent->setVariable("errorMessage", $currentStep->getProcessErrorMessage()); } } }
[ "public", "function", "process", "(", ")", "{", "/* @var $currentStep StepController */", "/* @var $ancestorStep StepController */", "/* @var $descendantStep StepController */", "$", "currentStep", "=", "$", "this", "->", "stepCollectionIterator", "->", "current", "(", ")", ";", "if", "(", "$", "this", "->", "stepAction", "==", "self", "::", "WIZARD_STEP_ACTION_PREV", "&&", "!", "$", "this", "->", "stepCollection", "->", "isFirst", "(", "$", "this", "->", "stepCollectionIterator", "->", "current", "(", ")", ")", ")", "{", "$", "currentStep", "->", "leaveToAncestorStep", "(", ")", ";", "$", "this", "->", "stepCollectionIterator", "->", "previous", "(", ")", ";", "$", "ancestorStep", "=", "$", "this", "->", "stepCollectionIterator", "->", "current", "(", ")", ";", "$", "ancestorStep", "->", "enterFromDescendant", "(", ")", ";", "$", "this", "->", "resultContent", "=", "$", "this", "->", "prepareNextStepView", "(", "$", "ancestorStep", ")", ";", "}", "elseif", "(", "$", "this", "->", "stepAction", "==", "self", "::", "WIZARD_STEP_ACTION_PREV", "&&", "$", "this", "->", "stepCollection", "->", "isFirst", "(", "$", "this", "->", "stepCollectionIterator", "->", "current", "(", ")", ")", ")", "{", "$", "this", "->", "resultContent", "=", "new", "ResponseConfigurator", "(", ")", ";", "}", "if", "(", "$", "this", "->", "stepAction", "==", "self", "::", "WIZARD_STEP_ACTION_NEXT", ")", "{", "$", "currentStep", "->", "preProcess", "(", ")", ";", "if", "(", "$", "currentStep", "->", "process", "(", "$", "currentStep", "->", "standardClosureArguments", "(", ")", ")", ")", "{", "$", "currentStep", "->", "postProcess", "(", ")", ";", "$", "currentStep", "->", "leaveStep", "(", ")", ";", "$", "this", "->", "stepCollectionIterator", "->", "next", "(", ")", ";", "$", "descendantStep", "=", "$", "this", "->", "stepCollectionIterator", "->", "current", "(", ")", ";", "$", "descendantStep", "->", "enterStep", "(", ")", ";", "$", "this", "->", "resultContent", "=", "$", "this", "->", "prepareNextStepView", "(", "$", "descendantStep", ")", ";", "}", "else", "{", "$", "this", "->", "resultContent", "=", "$", "this", "->", "prepareNextStepView", "(", "$", "currentStep", ")", ";", "$", "this", "->", "resultContent", "->", "setVariable", "(", "\"errorMessage\"", ",", "$", "currentStep", "->", "getProcessErrorMessage", "(", ")", ")", ";", "}", "}", "}" ]
processing the step
[ "processing", "the", "step" ]
5a55bfbea6b6ee10222c521112d469015db170b7
https://github.com/WasabiLib/wasabilib/blob/5a55bfbea6b6ee10222c521112d469015db170b7/src/WasabiLib/Wizard/Wizard.php#L216-L246
3,105
WasabiLib/wasabilib
src/WasabiLib/Wizard/Wizard.php
Wizard.createBreadcrumbItems
private function createBreadcrumbItems(StepController $step) { $viewModel = new ViewModel(); $viewModel->setTemplate($this->breadcrumbTemplatePath); $viewModel->setVariable("breadcrumbTitle", $step->getBreadCrumbTitle()); $viewModel->setVariable("stepNumber", $step->getBreadCrumbTitle()); return $viewModel; }
php
private function createBreadcrumbItems(StepController $step) { $viewModel = new ViewModel(); $viewModel->setTemplate($this->breadcrumbTemplatePath); $viewModel->setVariable("breadcrumbTitle", $step->getBreadCrumbTitle()); $viewModel->setVariable("stepNumber", $step->getBreadCrumbTitle()); return $viewModel; }
[ "private", "function", "createBreadcrumbItems", "(", "StepController", "$", "step", ")", "{", "$", "viewModel", "=", "new", "ViewModel", "(", ")", ";", "$", "viewModel", "->", "setTemplate", "(", "$", "this", "->", "breadcrumbTemplatePath", ")", ";", "$", "viewModel", "->", "setVariable", "(", "\"breadcrumbTitle\"", ",", "$", "step", "->", "getBreadCrumbTitle", "(", ")", ")", ";", "$", "viewModel", "->", "setVariable", "(", "\"stepNumber\"", ",", "$", "step", "->", "getBreadCrumbTitle", "(", ")", ")", ";", "return", "$", "viewModel", ";", "}" ]
generate one elementView for the breadcrumb path @param StepController $step @return ViewModel
[ "generate", "one", "elementView", "for", "the", "breadcrumb", "path" ]
5a55bfbea6b6ee10222c521112d469015db170b7
https://github.com/WasabiLib/wasabilib/blob/5a55bfbea6b6ee10222c521112d469015db170b7/src/WasabiLib/Wizard/Wizard.php#L253-L260
3,106
WasabiLib/wasabilib
src/WasabiLib/Wizard/Wizard.php
Wizard.initStepViewModel
private function initStepViewModel() { #first start of Wizard #load template from first step $currentStep = $this->stepCollectionIterator->current(); $isFirstStep = $this->getSteps()->isFirst($currentStep); if ($isFirstStep) { $firstStep = $this->getSteps()->getFirst(); $this->viewModel->addChild($firstStep->getViewModel(), "wizardContent"); $firstStepFormName = $firstStep->getViewModel()->getVariable("formName", false); if (empty($firstStepFormName)) throw new \Exception("viewModel variable 'formName' must set for Step '".$firstStep->getName()."'"); } if (!($this->prevButtonDisabled && $isFirstStep)) { $this->prevButtonViewModel = new ViewModel(); $this->prevButtonViewModel->setTemplate("wizard/wizardButton"); $this->prevButtonViewModel->setVariable("stepActionDirection", "prev"); $this->prevButtonViewModel->setVariable("id", "prevButton"); } $this->nextButtonViewModel = new ViewModel(); $this->nextButtonViewModel->setTemplate("wizard/wizardButton"); $this->nextButtonViewModel->setVariable("stepActionDirection", "next"); $this->nextButtonViewModel->setVariable("id", "nextButton"); /** * creates breadcrumbPath */ $stepIterator = $this->getSteps()->getIterator(); while ($stepIterator->valid()) { $view = $this->createBreadcrumbItems($stepIterator->current()); $this->getSteps()->isFirst($stepIterator->current()) ? $view->setVariable("extendCssClass", "active first") : false; $this->getSteps()->isLast($stepIterator->current()) ? $view->setVariable("extendCssClass", "last") : false; $view->setVariable("breadcrumbStepName", $stepIterator->current()->getName()); $this->viewModel->addChild($view, "breadcrumbNavigation", true); $stepIterator->next(); } $this->resultContent = $this->viewModel; $this->process(); }
php
private function initStepViewModel() { #first start of Wizard #load template from first step $currentStep = $this->stepCollectionIterator->current(); $isFirstStep = $this->getSteps()->isFirst($currentStep); if ($isFirstStep) { $firstStep = $this->getSteps()->getFirst(); $this->viewModel->addChild($firstStep->getViewModel(), "wizardContent"); $firstStepFormName = $firstStep->getViewModel()->getVariable("formName", false); if (empty($firstStepFormName)) throw new \Exception("viewModel variable 'formName' must set for Step '".$firstStep->getName()."'"); } if (!($this->prevButtonDisabled && $isFirstStep)) { $this->prevButtonViewModel = new ViewModel(); $this->prevButtonViewModel->setTemplate("wizard/wizardButton"); $this->prevButtonViewModel->setVariable("stepActionDirection", "prev"); $this->prevButtonViewModel->setVariable("id", "prevButton"); } $this->nextButtonViewModel = new ViewModel(); $this->nextButtonViewModel->setTemplate("wizard/wizardButton"); $this->nextButtonViewModel->setVariable("stepActionDirection", "next"); $this->nextButtonViewModel->setVariable("id", "nextButton"); /** * creates breadcrumbPath */ $stepIterator = $this->getSteps()->getIterator(); while ($stepIterator->valid()) { $view = $this->createBreadcrumbItems($stepIterator->current()); $this->getSteps()->isFirst($stepIterator->current()) ? $view->setVariable("extendCssClass", "active first") : false; $this->getSteps()->isLast($stepIterator->current()) ? $view->setVariable("extendCssClass", "last") : false; $view->setVariable("breadcrumbStepName", $stepIterator->current()->getName()); $this->viewModel->addChild($view, "breadcrumbNavigation", true); $stepIterator->next(); } $this->resultContent = $this->viewModel; $this->process(); }
[ "private", "function", "initStepViewModel", "(", ")", "{", "#first start of Wizard", "#load template from first step", "$", "currentStep", "=", "$", "this", "->", "stepCollectionIterator", "->", "current", "(", ")", ";", "$", "isFirstStep", "=", "$", "this", "->", "getSteps", "(", ")", "->", "isFirst", "(", "$", "currentStep", ")", ";", "if", "(", "$", "isFirstStep", ")", "{", "$", "firstStep", "=", "$", "this", "->", "getSteps", "(", ")", "->", "getFirst", "(", ")", ";", "$", "this", "->", "viewModel", "->", "addChild", "(", "$", "firstStep", "->", "getViewModel", "(", ")", ",", "\"wizardContent\"", ")", ";", "$", "firstStepFormName", "=", "$", "firstStep", "->", "getViewModel", "(", ")", "->", "getVariable", "(", "\"formName\"", ",", "false", ")", ";", "if", "(", "empty", "(", "$", "firstStepFormName", ")", ")", "throw", "new", "\\", "Exception", "(", "\"viewModel variable 'formName' must set for Step '\"", ".", "$", "firstStep", "->", "getName", "(", ")", ".", "\"'\"", ")", ";", "}", "if", "(", "!", "(", "$", "this", "->", "prevButtonDisabled", "&&", "$", "isFirstStep", ")", ")", "{", "$", "this", "->", "prevButtonViewModel", "=", "new", "ViewModel", "(", ")", ";", "$", "this", "->", "prevButtonViewModel", "->", "setTemplate", "(", "\"wizard/wizardButton\"", ")", ";", "$", "this", "->", "prevButtonViewModel", "->", "setVariable", "(", "\"stepActionDirection\"", ",", "\"prev\"", ")", ";", "$", "this", "->", "prevButtonViewModel", "->", "setVariable", "(", "\"id\"", ",", "\"prevButton\"", ")", ";", "}", "$", "this", "->", "nextButtonViewModel", "=", "new", "ViewModel", "(", ")", ";", "$", "this", "->", "nextButtonViewModel", "->", "setTemplate", "(", "\"wizard/wizardButton\"", ")", ";", "$", "this", "->", "nextButtonViewModel", "->", "setVariable", "(", "\"stepActionDirection\"", ",", "\"next\"", ")", ";", "$", "this", "->", "nextButtonViewModel", "->", "setVariable", "(", "\"id\"", ",", "\"nextButton\"", ")", ";", "/**\n * creates breadcrumbPath\n */", "$", "stepIterator", "=", "$", "this", "->", "getSteps", "(", ")", "->", "getIterator", "(", ")", ";", "while", "(", "$", "stepIterator", "->", "valid", "(", ")", ")", "{", "$", "view", "=", "$", "this", "->", "createBreadcrumbItems", "(", "$", "stepIterator", "->", "current", "(", ")", ")", ";", "$", "this", "->", "getSteps", "(", ")", "->", "isFirst", "(", "$", "stepIterator", "->", "current", "(", ")", ")", "?", "$", "view", "->", "setVariable", "(", "\"extendCssClass\"", ",", "\"active first\"", ")", ":", "false", ";", "$", "this", "->", "getSteps", "(", ")", "->", "isLast", "(", "$", "stepIterator", "->", "current", "(", ")", ")", "?", "$", "view", "->", "setVariable", "(", "\"extendCssClass\"", ",", "\"last\"", ")", ":", "false", ";", "$", "view", "->", "setVariable", "(", "\"breadcrumbStepName\"", ",", "$", "stepIterator", "->", "current", "(", ")", "->", "getName", "(", ")", ")", ";", "$", "this", "->", "viewModel", "->", "addChild", "(", "$", "view", ",", "\"breadcrumbNavigation\"", ",", "true", ")", ";", "$", "stepIterator", "->", "next", "(", ")", ";", "}", "$", "this", "->", "resultContent", "=", "$", "this", "->", "viewModel", ";", "$", "this", "->", "process", "(", ")", ";", "}" ]
init the ViewModel for the wizard @throws \Exception
[ "init", "the", "ViewModel", "for", "the", "wizard" ]
5a55bfbea6b6ee10222c521112d469015db170b7
https://github.com/WasabiLib/wasabilib/blob/5a55bfbea6b6ee10222c521112d469015db170b7/src/WasabiLib/Wizard/Wizard.php#L292-L330
3,107
WasabiLib/wasabilib
src/WasabiLib/Wizard/Wizard.php
Wizard.toggleStandardWizardButtons
private function toggleStandardWizardButtons($show = true) { $this->prevButtonViewModel->setVariable("btnClass_extend", (!$show ? "hide" : ""), true); $this->nextButtonViewModel->setVariable("btnClass_extend", (!$show ? "hide" : ""), true); }
php
private function toggleStandardWizardButtons($show = true) { $this->prevButtonViewModel->setVariable("btnClass_extend", (!$show ? "hide" : ""), true); $this->nextButtonViewModel->setVariable("btnClass_extend", (!$show ? "hide" : ""), true); }
[ "private", "function", "toggleStandardWizardButtons", "(", "$", "show", "=", "true", ")", "{", "$", "this", "->", "prevButtonViewModel", "->", "setVariable", "(", "\"btnClass_extend\"", ",", "(", "!", "$", "show", "?", "\"hide\"", ":", "\"\"", ")", ",", "true", ")", ";", "$", "this", "->", "nextButtonViewModel", "->", "setVariable", "(", "\"btnClass_extend\"", ",", "(", "!", "$", "show", "?", "\"hide\"", ":", "\"\"", ")", ",", "true", ")", ";", "}" ]
toggle the visibility of the wizardbutton depending on wether the step is the last one or not @param bool $show @return ResponseConfigurator
[ "toggle", "the", "visibility", "of", "the", "wizardbutton", "depending", "on", "wether", "the", "step", "is", "the", "last", "one", "or", "not" ]
5a55bfbea6b6ee10222c521112d469015db170b7
https://github.com/WasabiLib/wasabilib/blob/5a55bfbea6b6ee10222c521112d469015db170b7/src/WasabiLib/Wizard/Wizard.php#L373-L376
3,108
niconoe-/asserts
src/Asserts/Categories/AssertComparisonTrait.php
AssertComparisonTrait.assertLooselyEquals
public static function assertLooselyEquals($actual, $expected, Throwable $exception) { /** @noinspection TypeUnsafeComparisonInspection This assertion is wanted to be unsafe type. */ static::makeAssertion($actual == $expected, $exception); return $actual; }
php
public static function assertLooselyEquals($actual, $expected, Throwable $exception) { /** @noinspection TypeUnsafeComparisonInspection This assertion is wanted to be unsafe type. */ static::makeAssertion($actual == $expected, $exception); return $actual; }
[ "public", "static", "function", "assertLooselyEquals", "(", "$", "actual", ",", "$", "expected", ",", "Throwable", "$", "exception", ")", "{", "/** @noinspection TypeUnsafeComparisonInspection This assertion is wanted to be unsafe type. */", "static", "::", "makeAssertion", "(", "$", "actual", "==", "$", "expected", ",", "$", "exception", ")", ";", "return", "$", "actual", ";", "}" ]
Asserts that the given values are loosely equals. @param mixed $actual The actual value to test. @param mixed $expected The expected value. @param Throwable $exception The exception to throw if the assertion fails. @return mixed The actual value tested.
[ "Asserts", "that", "the", "given", "values", "are", "loosely", "equals", "." ]
a33dd3fb8983ae6965533c8ff4ff8380367b561d
https://github.com/niconoe-/asserts/blob/a33dd3fb8983ae6965533c8ff4ff8380367b561d/src/Asserts/Categories/AssertComparisonTrait.php#L27-L32
3,109
niconoe-/asserts
src/Asserts/Categories/AssertComparisonTrait.php
AssertComparisonTrait.assertEquals
public static function assertEquals($actual, $expected, Throwable $exception) { static::makeAssertion($actual === $expected, $exception); return $actual; }
php
public static function assertEquals($actual, $expected, Throwable $exception) { static::makeAssertion($actual === $expected, $exception); return $actual; }
[ "public", "static", "function", "assertEquals", "(", "$", "actual", ",", "$", "expected", ",", "Throwable", "$", "exception", ")", "{", "static", "::", "makeAssertion", "(", "$", "actual", "===", "$", "expected", ",", "$", "exception", ")", ";", "return", "$", "actual", ";", "}" ]
Asserts that the given values are strictly equals. @param mixed $actual The actual value to test. @param mixed $expected The expected value. @param Throwable $exception The exception to throw if the assertion fails. @return mixed The actual value tested.
[ "Asserts", "that", "the", "given", "values", "are", "strictly", "equals", "." ]
a33dd3fb8983ae6965533c8ff4ff8380367b561d
https://github.com/niconoe-/asserts/blob/a33dd3fb8983ae6965533c8ff4ff8380367b561d/src/Asserts/Categories/AssertComparisonTrait.php#L42-L46
3,110
niconoe-/asserts
src/Asserts/Categories/AssertComparisonTrait.php
AssertComparisonTrait.assertLooselyNotEquals
public static function assertLooselyNotEquals($actual, $expected, Throwable $exception) { /** @noinspection TypeUnsafeComparisonInspection This assertion is wanted to be unsafe type. */ static::makeAssertion($actual != $expected, $exception); return $actual; }
php
public static function assertLooselyNotEquals($actual, $expected, Throwable $exception) { /** @noinspection TypeUnsafeComparisonInspection This assertion is wanted to be unsafe type. */ static::makeAssertion($actual != $expected, $exception); return $actual; }
[ "public", "static", "function", "assertLooselyNotEquals", "(", "$", "actual", ",", "$", "expected", ",", "Throwable", "$", "exception", ")", "{", "/** @noinspection TypeUnsafeComparisonInspection This assertion is wanted to be unsafe type. */", "static", "::", "makeAssertion", "(", "$", "actual", "!=", "$", "expected", ",", "$", "exception", ")", ";", "return", "$", "actual", ";", "}" ]
Asserts that the given values are loosely not equals. @param mixed $actual The actual value to test. @param mixed $expected The expected value. @param Throwable $exception The exception to throw if the assertion fails. @return mixed The actual value tested.
[ "Asserts", "that", "the", "given", "values", "are", "loosely", "not", "equals", "." ]
a33dd3fb8983ae6965533c8ff4ff8380367b561d
https://github.com/niconoe-/asserts/blob/a33dd3fb8983ae6965533c8ff4ff8380367b561d/src/Asserts/Categories/AssertComparisonTrait.php#L56-L61
3,111
niconoe-/asserts
src/Asserts/Categories/AssertComparisonTrait.php
AssertComparisonTrait.assertNotEquals
public static function assertNotEquals($actual, $expected, Throwable $exception) { static::makeAssertion($actual !== $expected, $exception); return $actual; }
php
public static function assertNotEquals($actual, $expected, Throwable $exception) { static::makeAssertion($actual !== $expected, $exception); return $actual; }
[ "public", "static", "function", "assertNotEquals", "(", "$", "actual", ",", "$", "expected", ",", "Throwable", "$", "exception", ")", "{", "static", "::", "makeAssertion", "(", "$", "actual", "!==", "$", "expected", ",", "$", "exception", ")", ";", "return", "$", "actual", ";", "}" ]
Asserts that the given values are strictly not equals. @param mixed $actual The actual value to test. @param mixed $expected The expected value. @param Throwable $exception The exception to throw if the assertion fails. @return mixed The actual value tested.
[ "Asserts", "that", "the", "given", "values", "are", "strictly", "not", "equals", "." ]
a33dd3fb8983ae6965533c8ff4ff8380367b561d
https://github.com/niconoe-/asserts/blob/a33dd3fb8983ae6965533c8ff4ff8380367b561d/src/Asserts/Categories/AssertComparisonTrait.php#L71-L75
3,112
niconoe-/asserts
src/Asserts/Categories/AssertComparisonTrait.php
AssertComparisonTrait.assertGreaterThanOrEquals
public static function assertGreaterThanOrEquals($actual, $expected, Throwable $exception): bool { static::makeAssertion($actual >= $expected, $exception); return true; }
php
public static function assertGreaterThanOrEquals($actual, $expected, Throwable $exception): bool { static::makeAssertion($actual >= $expected, $exception); return true; }
[ "public", "static", "function", "assertGreaterThanOrEquals", "(", "$", "actual", ",", "$", "expected", ",", "Throwable", "$", "exception", ")", ":", "bool", "{", "static", "::", "makeAssertion", "(", "$", "actual", ">=", "$", "expected", ",", "$", "exception", ")", ";", "return", "true", ";", "}" ]
Asserts that the given actual value is greater than or equals the expected value. @param mixed $actual The actual value to test. @param mixed $expected The expected value. @param Throwable $exception The exception to throw if the assertion fails. @return bool
[ "Asserts", "that", "the", "given", "actual", "value", "is", "greater", "than", "or", "equals", "the", "expected", "value", "." ]
a33dd3fb8983ae6965533c8ff4ff8380367b561d
https://github.com/niconoe-/asserts/blob/a33dd3fb8983ae6965533c8ff4ff8380367b561d/src/Asserts/Categories/AssertComparisonTrait.php#L85-L89
3,113
niconoe-/asserts
src/Asserts/Categories/AssertComparisonTrait.php
AssertComparisonTrait.assertGreaterThan
public static function assertGreaterThan($actual, $expected, Throwable $exception): bool { static::makeAssertion($actual > $expected, $exception); return true; }
php
public static function assertGreaterThan($actual, $expected, Throwable $exception): bool { static::makeAssertion($actual > $expected, $exception); return true; }
[ "public", "static", "function", "assertGreaterThan", "(", "$", "actual", ",", "$", "expected", ",", "Throwable", "$", "exception", ")", ":", "bool", "{", "static", "::", "makeAssertion", "(", "$", "actual", ">", "$", "expected", ",", "$", "exception", ")", ";", "return", "true", ";", "}" ]
Asserts that the given actual value is strictly greater than the expected value. @param mixed $actual The actual value to test. @param mixed $expected The expected value. @param Throwable $exception The exception to throw if the assertion fails. @return bool
[ "Asserts", "that", "the", "given", "actual", "value", "is", "strictly", "greater", "than", "the", "expected", "value", "." ]
a33dd3fb8983ae6965533c8ff4ff8380367b561d
https://github.com/niconoe-/asserts/blob/a33dd3fb8983ae6965533c8ff4ff8380367b561d/src/Asserts/Categories/AssertComparisonTrait.php#L99-L103
3,114
niconoe-/asserts
src/Asserts/Categories/AssertComparisonTrait.php
AssertComparisonTrait.assertLessThanOrEquals
public static function assertLessThanOrEquals($actual, $expected, Throwable $exception): bool { static::makeAssertion($actual <= $expected, $exception); return true; }
php
public static function assertLessThanOrEquals($actual, $expected, Throwable $exception): bool { static::makeAssertion($actual <= $expected, $exception); return true; }
[ "public", "static", "function", "assertLessThanOrEquals", "(", "$", "actual", ",", "$", "expected", ",", "Throwable", "$", "exception", ")", ":", "bool", "{", "static", "::", "makeAssertion", "(", "$", "actual", "<=", "$", "expected", ",", "$", "exception", ")", ";", "return", "true", ";", "}" ]
Asserts that the given actual value is less than or equals the expected value. @param mixed $actual The actual value to test. @param mixed $expected The expected value. @param Throwable $exception The exception to throw if the assertion fails. @return bool
[ "Asserts", "that", "the", "given", "actual", "value", "is", "less", "than", "or", "equals", "the", "expected", "value", "." ]
a33dd3fb8983ae6965533c8ff4ff8380367b561d
https://github.com/niconoe-/asserts/blob/a33dd3fb8983ae6965533c8ff4ff8380367b561d/src/Asserts/Categories/AssertComparisonTrait.php#L113-L117
3,115
niconoe-/asserts
src/Asserts/Categories/AssertComparisonTrait.php
AssertComparisonTrait.assertLessThan
public static function assertLessThan($actual, $expected, Throwable $exception): bool { static::makeAssertion($actual < $expected, $exception); return true; }
php
public static function assertLessThan($actual, $expected, Throwable $exception): bool { static::makeAssertion($actual < $expected, $exception); return true; }
[ "public", "static", "function", "assertLessThan", "(", "$", "actual", ",", "$", "expected", ",", "Throwable", "$", "exception", ")", ":", "bool", "{", "static", "::", "makeAssertion", "(", "$", "actual", "<", "$", "expected", ",", "$", "exception", ")", ";", "return", "true", ";", "}" ]
Asserts that the given actual value is strictly less than the expected value. @param mixed $actual The actual value to test. @param mixed $expected The expected value. @param Throwable $exception The exception to throw if the assertion fails. @return bool
[ "Asserts", "that", "the", "given", "actual", "value", "is", "strictly", "less", "than", "the", "expected", "value", "." ]
a33dd3fb8983ae6965533c8ff4ff8380367b561d
https://github.com/niconoe-/asserts/blob/a33dd3fb8983ae6965533c8ff4ff8380367b561d/src/Asserts/Categories/AssertComparisonTrait.php#L127-L131
3,116
sios13/simox
src/Flash.php
Flash.output
public function output( $type = null ) { $session = $this->_di->getService( "session" ); /** * Get the messages from the session */ $messages = $session->get( "__flash__" ); /** * If there are no messages to output -> exit early */ if ( $messages == null ) { return; } /** * If a type is specified -> implode and return the type messages */ if ( isset($type) ) { /** * Get the messages of the type */ $messages_type = implode( $messages[$type] ); /** * Clear the type messages in the flash session */ $messages[$type] = array(); $session->set( "__flash__", $messages ); return $messages_type; } /** * Create a string with all messages */ $all_messages_str = ""; foreach ( $messages as $messages_type ) { $all_messages_str .= implode( $messages_type ); } /** * When all the messages have been output -> clear all the messages in the flash session */ $session->set( "__flash__", array() ); return $all_messages_str; }
php
public function output( $type = null ) { $session = $this->_di->getService( "session" ); /** * Get the messages from the session */ $messages = $session->get( "__flash__" ); /** * If there are no messages to output -> exit early */ if ( $messages == null ) { return; } /** * If a type is specified -> implode and return the type messages */ if ( isset($type) ) { /** * Get the messages of the type */ $messages_type = implode( $messages[$type] ); /** * Clear the type messages in the flash session */ $messages[$type] = array(); $session->set( "__flash__", $messages ); return $messages_type; } /** * Create a string with all messages */ $all_messages_str = ""; foreach ( $messages as $messages_type ) { $all_messages_str .= implode( $messages_type ); } /** * When all the messages have been output -> clear all the messages in the flash session */ $session->set( "__flash__", array() ); return $all_messages_str; }
[ "public", "function", "output", "(", "$", "type", "=", "null", ")", "{", "$", "session", "=", "$", "this", "->", "_di", "->", "getService", "(", "\"session\"", ")", ";", "/**\r\n * Get the messages from the session\r\n */", "$", "messages", "=", "$", "session", "->", "get", "(", "\"__flash__\"", ")", ";", "/**\r\n\t\t * If there are no messages to output -> exit early\r\n\t\t */", "if", "(", "$", "messages", "==", "null", ")", "{", "return", ";", "}", "/**\r\n * If a type is specified -> implode and return the type messages\r\n */", "if", "(", "isset", "(", "$", "type", ")", ")", "{", "/**\r\n * Get the messages of the type\r\n */", "$", "messages_type", "=", "implode", "(", "$", "messages", "[", "$", "type", "]", ")", ";", "/**\r\n * Clear the type messages in the flash session\r\n */", "$", "messages", "[", "$", "type", "]", "=", "array", "(", ")", ";", "$", "session", "->", "set", "(", "\"__flash__\"", ",", "$", "messages", ")", ";", "return", "$", "messages_type", ";", "}", "/**\r\n * Create a string with all messages\r\n */", "$", "all_messages_str", "=", "\"\"", ";", "foreach", "(", "$", "messages", "as", "$", "messages_type", ")", "{", "$", "all_messages_str", ".=", "implode", "(", "$", "messages_type", ")", ";", "}", "/**\r\n * When all the messages have been output -> clear all the messages in the flash session\r\n */", "$", "session", "->", "set", "(", "\"__flash__\"", ",", "array", "(", ")", ")", ";", "return", "$", "all_messages_str", ";", "}" ]
Returns the messages
[ "Returns", "the", "messages" ]
8be964949ef179aba7eceb3fc6439815a1af2ad2
https://github.com/sios13/simox/blob/8be964949ef179aba7eceb3fc6439815a1af2ad2/src/Flash.php#L32-L85
3,117
webriq/core
module/Core/src/Grid/Core/Controller/IndexController.php
IndexController.contentUriAction
public function contentUriAction() { $actual = $this->getSubDomainModel() ->findActual(); if ( empty( $actual ) ) { $this->getResponse() ->setStatusCode( 404 ); return; } $uri = $this->params() ->fromRoute( 'uri' ); // prevent "Invalid Encoding Attack" if ( ! mb_check_encoding( $uri, 'UTF-8' ) ) { $this->getResponse() ->setStatusCode( 404 ); return; } $structure = $this->getUriModel() ->findBySubdomainUri( $actual->id, $uri ); if ( empty( $structure ) ) { $this->paragraphLayout(); $this->getResponse() ->setStatusCode( 404 ); return; } if ( ! $structure->default ) { $default = $this->getUriModel() ->findDefaultByContentSubdomain( $structure->contentId, $actual->id, $structure->locale ); if ( $default->uri != $structure->uri ) // Avoid infinite redirect circles { $response = $this->getResponse(); $response->getHeaders() ->addHeaderLine( 'Location', '/' . $default->safeUri ); // Permanent redirect: for "old" uris return $response->setStatusCode( 301 ); } } if ( ! empty( $structure->locale ) ) { $this->getServiceLocator() ->get( 'Locale' ) ->setCurrent( $structure->locale ); } return $this->forward() ->dispatch( 'Grid\Paragraph\Controller\Render', array( 'controller' => 'Grid\Paragraph\Controller\Render', 'action' => 'paragraph', 'locale' => (string) $this->locale(), 'paragraphId' => $structure->contentId ) ); }
php
public function contentUriAction() { $actual = $this->getSubDomainModel() ->findActual(); if ( empty( $actual ) ) { $this->getResponse() ->setStatusCode( 404 ); return; } $uri = $this->params() ->fromRoute( 'uri' ); // prevent "Invalid Encoding Attack" if ( ! mb_check_encoding( $uri, 'UTF-8' ) ) { $this->getResponse() ->setStatusCode( 404 ); return; } $structure = $this->getUriModel() ->findBySubdomainUri( $actual->id, $uri ); if ( empty( $structure ) ) { $this->paragraphLayout(); $this->getResponse() ->setStatusCode( 404 ); return; } if ( ! $structure->default ) { $default = $this->getUriModel() ->findDefaultByContentSubdomain( $structure->contentId, $actual->id, $structure->locale ); if ( $default->uri != $structure->uri ) // Avoid infinite redirect circles { $response = $this->getResponse(); $response->getHeaders() ->addHeaderLine( 'Location', '/' . $default->safeUri ); // Permanent redirect: for "old" uris return $response->setStatusCode( 301 ); } } if ( ! empty( $structure->locale ) ) { $this->getServiceLocator() ->get( 'Locale' ) ->setCurrent( $structure->locale ); } return $this->forward() ->dispatch( 'Grid\Paragraph\Controller\Render', array( 'controller' => 'Grid\Paragraph\Controller\Render', 'action' => 'paragraph', 'locale' => (string) $this->locale(), 'paragraphId' => $structure->contentId ) ); }
[ "public", "function", "contentUriAction", "(", ")", "{", "$", "actual", "=", "$", "this", "->", "getSubDomainModel", "(", ")", "->", "findActual", "(", ")", ";", "if", "(", "empty", "(", "$", "actual", ")", ")", "{", "$", "this", "->", "getResponse", "(", ")", "->", "setStatusCode", "(", "404", ")", ";", "return", ";", "}", "$", "uri", "=", "$", "this", "->", "params", "(", ")", "->", "fromRoute", "(", "'uri'", ")", ";", "// prevent \"Invalid Encoding Attack\"", "if", "(", "!", "mb_check_encoding", "(", "$", "uri", ",", "'UTF-8'", ")", ")", "{", "$", "this", "->", "getResponse", "(", ")", "->", "setStatusCode", "(", "404", ")", ";", "return", ";", "}", "$", "structure", "=", "$", "this", "->", "getUriModel", "(", ")", "->", "findBySubdomainUri", "(", "$", "actual", "->", "id", ",", "$", "uri", ")", ";", "if", "(", "empty", "(", "$", "structure", ")", ")", "{", "$", "this", "->", "paragraphLayout", "(", ")", ";", "$", "this", "->", "getResponse", "(", ")", "->", "setStatusCode", "(", "404", ")", ";", "return", ";", "}", "if", "(", "!", "$", "structure", "->", "default", ")", "{", "$", "default", "=", "$", "this", "->", "getUriModel", "(", ")", "->", "findDefaultByContentSubdomain", "(", "$", "structure", "->", "contentId", ",", "$", "actual", "->", "id", ",", "$", "structure", "->", "locale", ")", ";", "if", "(", "$", "default", "->", "uri", "!=", "$", "structure", "->", "uri", ")", "// Avoid infinite redirect circles", "{", "$", "response", "=", "$", "this", "->", "getResponse", "(", ")", ";", "$", "response", "->", "getHeaders", "(", ")", "->", "addHeaderLine", "(", "'Location'", ",", "'/'", ".", "$", "default", "->", "safeUri", ")", ";", "// Permanent redirect: for \"old\" uris", "return", "$", "response", "->", "setStatusCode", "(", "301", ")", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "structure", "->", "locale", ")", ")", "{", "$", "this", "->", "getServiceLocator", "(", ")", "->", "get", "(", "'Locale'", ")", "->", "setCurrent", "(", "$", "structure", "->", "locale", ")", ";", "}", "return", "$", "this", "->", "forward", "(", ")", "->", "dispatch", "(", "'Grid\\Paragraph\\Controller\\Render'", ",", "array", "(", "'controller'", "=>", "'Grid\\Paragraph\\Controller\\Render'", ",", "'action'", "=>", "'paragraph'", ",", "'locale'", "=>", "(", "string", ")", "$", "this", "->", "locale", "(", ")", ",", "'paragraphId'", "=>", "$", "structure", "->", "contentId", ")", ")", ";", "}" ]
Content-uri action
[ "Content", "-", "uri", "action" ]
cfeb6e8a4732561c2215ec94e736c07f9b8bc990
https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/Core/src/Grid/Core/Controller/IndexController.php#L104-L178
3,118
jaswdr/mock
src/Jaschweder/Mock/Object.php
Object.method
public function method($name) { $method = new Method($name); $this->container->put($name, $method); return $method; }
php
public function method($name) { $method = new Method($name); $this->container->put($name, $method); return $method; }
[ "public", "function", "method", "(", "$", "name", ")", "{", "$", "method", "=", "new", "Method", "(", "$", "name", ")", ";", "$", "this", "->", "container", "->", "put", "(", "$", "name", ",", "$", "method", ")", ";", "return", "$", "method", ";", "}" ]
Define a new mock method. @param string $name The name of the method @return Method
[ "Define", "a", "new", "mock", "method", "." ]
869377802d39d6628611f8868a3fc877398ef72d
https://github.com/jaswdr/mock/blob/869377802d39d6628611f8868a3fc877398ef72d/src/Jaschweder/Mock/Object.php#L29-L35
3,119
unyx/console
input/formats/parsers/Argv.php
Argv.parse
public function parse(interfaces\Tokens $input, values\Arguments $arguments, values\Options $options) : void { $isParsingOptions = true; // Grab all tokens. Can't iterate directly over the Collection as we need to easily determine // which tokens are left to be processed (thus array_shift() below). $input = $input->all(); // Loop through the input given. while (null !== $token = array_shift($input)) { if ($isParsingOptions) { // When '--' is present as a token, it forces us to treat // everything following it as arguments. if ('--' === $token) { $isParsingOptions = false; continue; } // Full options (token beginning with two hyphens). if (0 === strpos($token, '--')) { $this->parseLongOption($token, $options, $input); continue; } // Shortcuts (token beginning with exactly one hyphen). if ('-' === $token[0]) { $this->parseShortOption($token, $options, $input); continue; } } // In any other case treat the token as an argument. $arguments->push($token); } }
php
public function parse(interfaces\Tokens $input, values\Arguments $arguments, values\Options $options) : void { $isParsingOptions = true; // Grab all tokens. Can't iterate directly over the Collection as we need to easily determine // which tokens are left to be processed (thus array_shift() below). $input = $input->all(); // Loop through the input given. while (null !== $token = array_shift($input)) { if ($isParsingOptions) { // When '--' is present as a token, it forces us to treat // everything following it as arguments. if ('--' === $token) { $isParsingOptions = false; continue; } // Full options (token beginning with two hyphens). if (0 === strpos($token, '--')) { $this->parseLongOption($token, $options, $input); continue; } // Shortcuts (token beginning with exactly one hyphen). if ('-' === $token[0]) { $this->parseShortOption($token, $options, $input); continue; } } // In any other case treat the token as an argument. $arguments->push($token); } }
[ "public", "function", "parse", "(", "interfaces", "\\", "Tokens", "$", "input", ",", "values", "\\", "Arguments", "$", "arguments", ",", "values", "\\", "Options", "$", "options", ")", ":", "void", "{", "$", "isParsingOptions", "=", "true", ";", "// Grab all tokens. Can't iterate directly over the Collection as we need to easily determine", "// which tokens are left to be processed (thus array_shift() below).", "$", "input", "=", "$", "input", "->", "all", "(", ")", ";", "// Loop through the input given.", "while", "(", "null", "!==", "$", "token", "=", "array_shift", "(", "$", "input", ")", ")", "{", "if", "(", "$", "isParsingOptions", ")", "{", "// When '--' is present as a token, it forces us to treat", "// everything following it as arguments.", "if", "(", "'--'", "===", "$", "token", ")", "{", "$", "isParsingOptions", "=", "false", ";", "continue", ";", "}", "// Full options (token beginning with two hyphens).", "if", "(", "0", "===", "strpos", "(", "$", "token", ",", "'--'", ")", ")", "{", "$", "this", "->", "parseLongOption", "(", "$", "token", ",", "$", "options", ",", "$", "input", ")", ";", "continue", ";", "}", "// Shortcuts (token beginning with exactly one hyphen).", "if", "(", "'-'", "===", "$", "token", "[", "0", "]", ")", "{", "$", "this", "->", "parseShortOption", "(", "$", "token", ",", "$", "options", ",", "$", "input", ")", ";", "continue", ";", "}", "}", "// In any other case treat the token as an argument.", "$", "arguments", "->", "push", "(", "$", "token", ")", ";", "}", "}" ]
Fill the given Input Arguments and Options based on their definitions and the Argv input given. @param values\Arguments $arguments The Input Arguments to fill. @param values\Options $options The Input Options to fill. @param tokens\Argv $input The Argv tokens to be parsed.
[ "Fill", "the", "given", "Input", "Arguments", "and", "Options", "based", "on", "their", "definitions", "and", "the", "Argv", "input", "given", "." ]
b4a76e08bbb5428b0349c0ec4259a914f81a2957
https://github.com/unyx/console/blob/b4a76e08bbb5428b0349c0ec4259a914f81a2957/input/formats/parsers/Argv.php#L30-L65
3,120
unyx/console
input/formats/parsers/Argv.php
Argv.parseLongOption
protected function parseLongOption(string $token, values\Options $options, array& $input) : void { // Remove the two starting hyphens. $name = substr($token, 2); $value = null; // If the token contains a value for the option, we need to split the token accordingly. if (false !== $pos = strpos($name, '=')) { $value = substr($name, $pos + 1); $name = substr($name, 0, $pos); } // If the option didn't have a value assigned using the 'equals' sign, the value may be contained in // the next token, *if* the Option accepts values to begin with. // Note: It's possible that no Definition for the given Option even exists, but we're deferring // Exception throwing to parameters\Options::set() to avoid some duplicate code. /* @var input\Option $definition */ if (!isset($value) && $definition = $options->definitions()->get($name) and $definition->hasValue()) { // $input[0][0] is the first character of the first token in the $input array. // Ensure the token does not begin with a hyphen, which would indicate it's another Option, // and not a value for the Option we are processing. if (isset($input[0]) && '-' !== $input[0][0]) { $value = array_shift($input); } } $options->set($name, $value); }
php
protected function parseLongOption(string $token, values\Options $options, array& $input) : void { // Remove the two starting hyphens. $name = substr($token, 2); $value = null; // If the token contains a value for the option, we need to split the token accordingly. if (false !== $pos = strpos($name, '=')) { $value = substr($name, $pos + 1); $name = substr($name, 0, $pos); } // If the option didn't have a value assigned using the 'equals' sign, the value may be contained in // the next token, *if* the Option accepts values to begin with. // Note: It's possible that no Definition for the given Option even exists, but we're deferring // Exception throwing to parameters\Options::set() to avoid some duplicate code. /* @var input\Option $definition */ if (!isset($value) && $definition = $options->definitions()->get($name) and $definition->hasValue()) { // $input[0][0] is the first character of the first token in the $input array. // Ensure the token does not begin with a hyphen, which would indicate it's another Option, // and not a value for the Option we are processing. if (isset($input[0]) && '-' !== $input[0][0]) { $value = array_shift($input); } } $options->set($name, $value); }
[ "protected", "function", "parseLongOption", "(", "string", "$", "token", ",", "values", "\\", "Options", "$", "options", ",", "array", "&", "$", "input", ")", ":", "void", "{", "// Remove the two starting hyphens.", "$", "name", "=", "substr", "(", "$", "token", ",", "2", ")", ";", "$", "value", "=", "null", ";", "// If the token contains a value for the option, we need to split the token accordingly.", "if", "(", "false", "!==", "$", "pos", "=", "strpos", "(", "$", "name", ",", "'='", ")", ")", "{", "$", "value", "=", "substr", "(", "$", "name", ",", "$", "pos", "+", "1", ")", ";", "$", "name", "=", "substr", "(", "$", "name", ",", "0", ",", "$", "pos", ")", ";", "}", "// If the option didn't have a value assigned using the 'equals' sign, the value may be contained in", "// the next token, *if* the Option accepts values to begin with.", "// Note: It's possible that no Definition for the given Option even exists, but we're deferring", "// Exception throwing to parameters\\Options::set() to avoid some duplicate code.", "/* @var input\\Option $definition */", "if", "(", "!", "isset", "(", "$", "value", ")", "&&", "$", "definition", "=", "$", "options", "->", "definitions", "(", ")", "->", "get", "(", "$", "name", ")", "and", "$", "definition", "->", "hasValue", "(", ")", ")", "{", "// $input[0][0] is the first character of the first token in the $input array.", "// Ensure the token does not begin with a hyphen, which would indicate it's another Option,", "// and not a value for the Option we are processing.", "if", "(", "isset", "(", "$", "input", "[", "0", "]", ")", "&&", "'-'", "!==", "$", "input", "[", "0", "]", "[", "0", "]", ")", "{", "$", "value", "=", "array_shift", "(", "$", "input", ")", ";", "}", "}", "$", "options", "->", "set", "(", "$", "name", ",", "$", "value", ")", ";", "}" ]
Parses the given token as a long option and adds it to the Options set. @param string $token The token to parse. @param values\Options $options The collection of Options being filled. @param array& $input A reference to the argv input array.
[ "Parses", "the", "given", "token", "as", "a", "long", "option", "and", "adds", "it", "to", "the", "Options", "set", "." ]
b4a76e08bbb5428b0349c0ec4259a914f81a2957
https://github.com/unyx/console/blob/b4a76e08bbb5428b0349c0ec4259a914f81a2957/input/formats/parsers/Argv.php#L74-L101
3,121
unyx/console
input/formats/parsers/Argv.php
Argv.parseShortOption
protected function parseShortOption($token, values\Options $options, array& $input) : void { // Remove the starting hyphen. // If it's just a hyphen and nothing else, ignore it since it's most likely a mistype. if (empty($shortcut = substr($token, 1))) { return; } foreach ($this->resolveShortOption($shortcut, $options) as $name => $value) { $options->set($name, $value); } }
php
protected function parseShortOption($token, values\Options $options, array& $input) : void { // Remove the starting hyphen. // If it's just a hyphen and nothing else, ignore it since it's most likely a mistype. if (empty($shortcut = substr($token, 1))) { return; } foreach ($this->resolveShortOption($shortcut, $options) as $name => $value) { $options->set($name, $value); } }
[ "protected", "function", "parseShortOption", "(", "$", "token", ",", "values", "\\", "Options", "$", "options", ",", "array", "&", "$", "input", ")", ":", "void", "{", "// Remove the starting hyphen.", "// If it's just a hyphen and nothing else, ignore it since it's most likely a mistype.", "if", "(", "empty", "(", "$", "shortcut", "=", "substr", "(", "$", "token", ",", "1", ")", ")", ")", "{", "return", ";", "}", "foreach", "(", "$", "this", "->", "resolveShortOption", "(", "$", "shortcut", ",", "$", "options", ")", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "options", "->", "set", "(", "$", "name", ",", "$", "value", ")", ";", "}", "}" ]
Parses the given token as a short option and adds it to the Options set. @param string $token The token to parse. @param values\Options $options The collection of Options being filled. @param array& $input A reference to the argv input array.
[ "Parses", "the", "given", "token", "as", "a", "short", "option", "and", "adds", "it", "to", "the", "Options", "set", "." ]
b4a76e08bbb5428b0349c0ec4259a914f81a2957
https://github.com/unyx/console/blob/b4a76e08bbb5428b0349c0ec4259a914f81a2957/input/formats/parsers/Argv.php#L110-L121
3,122
unyx/console
input/formats/parsers/Argv.php
Argv.resolveShortOptionSet
private function resolveShortOptionSet(string $shortcut, definitions\Options $definitions) : array { $length = strlen($shortcut); $result = []; // Loop through the string, character by character. for ($i = 0; $i < $length; $i++) { $definition = $definitions->getByShortcut($shortcut[$i]); // The last shortcut in a set may have a value appended afterwards. if ($definition->hasValue()) { $result[$definition->getName()] = $i === $length - 1 ? null : substr($shortcut, $i + 1); break; } $result[$definition->getName()] = null; } return $result; }
php
private function resolveShortOptionSet(string $shortcut, definitions\Options $definitions) : array { $length = strlen($shortcut); $result = []; // Loop through the string, character by character. for ($i = 0; $i < $length; $i++) { $definition = $definitions->getByShortcut($shortcut[$i]); // The last shortcut in a set may have a value appended afterwards. if ($definition->hasValue()) { $result[$definition->getName()] = $i === $length - 1 ? null : substr($shortcut, $i + 1); break; } $result[$definition->getName()] = null; } return $result; }
[ "private", "function", "resolveShortOptionSet", "(", "string", "$", "shortcut", ",", "definitions", "\\", "Options", "$", "definitions", ")", ":", "array", "{", "$", "length", "=", "strlen", "(", "$", "shortcut", ")", ";", "$", "result", "=", "[", "]", ";", "// Loop through the string, character by character.", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "length", ";", "$", "i", "++", ")", "{", "$", "definition", "=", "$", "definitions", "->", "getByShortcut", "(", "$", "shortcut", "[", "$", "i", "]", ")", ";", "// The last shortcut in a set may have a value appended afterwards.", "if", "(", "$", "definition", "->", "hasValue", "(", ")", ")", "{", "$", "result", "[", "$", "definition", "->", "getName", "(", ")", "]", "=", "$", "i", "===", "$", "length", "-", "1", "?", "null", ":", "substr", "(", "$", "shortcut", ",", "$", "i", "+", "1", ")", ";", "break", ";", "}", "$", "result", "[", "$", "definition", "->", "getName", "(", ")", "]", "=", "null", ";", "}", "return", "$", "result", ";", "}" ]
Takes a set of short options contained in a string and resolves them to full options and their values, depending on the Definitions given. @param string $shortcut The short option(s) to resolve. @param definitions\Options $definitions The Options Definition. @return array An array of full option $names => $values.
[ "Takes", "a", "set", "of", "short", "options", "contained", "in", "a", "string", "and", "resolves", "them", "to", "full", "options", "and", "their", "values", "depending", "on", "the", "Definitions", "given", "." ]
b4a76e08bbb5428b0349c0ec4259a914f81a2957
https://github.com/unyx/console/blob/b4a76e08bbb5428b0349c0ec4259a914f81a2957/input/formats/parsers/Argv.php#L162-L181
3,123
mtils/collection
src/Collection/Dictionary.php
Dictionary.update
public function update($other){ if(is_array($other)){ $this->_array = $other; return $this; } $this->_array = array(); foreach($other as $key=>$value){ $this->_array[$key] = $value; } return $this; }
php
public function update($other){ if(is_array($other)){ $this->_array = $other; return $this; } $this->_array = array(); foreach($other as $key=>$value){ $this->_array[$key] = $value; } return $this; }
[ "public", "function", "update", "(", "$", "other", ")", "{", "if", "(", "is_array", "(", "$", "other", ")", ")", "{", "$", "this", "->", "_array", "=", "$", "other", ";", "return", "$", "this", ";", "}", "$", "this", "->", "_array", "=", "array", "(", ")", ";", "foreach", "(", "$", "other", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "this", "->", "_array", "[", "$", "key", "]", "=", "$", "value", ";", "}", "return", "$", "this", ";", "}" ]
Updates the values of this hash with the values of other. @param Traversable: $other @return Dictionary
[ "Updates", "the", "values", "of", "this", "hash", "with", "the", "values", "of", "other", "." ]
186f8a6cc68fef1babc486438aa6d6c643186cc8
https://github.com/mtils/collection/blob/186f8a6cc68fef1babc486438aa6d6c643186cc8/src/Collection/Dictionary.php#L270-L280
3,124
mtils/collection
src/Collection/Dictionary.php
Dictionary.fromKeys
public static function fromKeys($keys){ $hash = new Dictionary(); foreach($keys as $key){ $hash[$key] = NULL; } return $hash; }
php
public static function fromKeys($keys){ $hash = new Dictionary(); foreach($keys as $key){ $hash[$key] = NULL; } return $hash; }
[ "public", "static", "function", "fromKeys", "(", "$", "keys", ")", "{", "$", "hash", "=", "new", "Dictionary", "(", ")", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "$", "hash", "[", "$", "key", "]", "=", "NULL", ";", "}", "return", "$", "hash", ";", "}" ]
Constructs a Hash with the passed keys @param Traversable $keys @return Dictionary
[ "Constructs", "a", "Hash", "with", "the", "passed", "keys" ]
186f8a6cc68fef1babc486438aa6d6c643186cc8
https://github.com/mtils/collection/blob/186f8a6cc68fef1babc486438aa6d6c643186cc8/src/Collection/Dictionary.php#L297-L303
3,125
php-rest-server/core
src/Core/General/ActionInfo.php
ActionInfo.getAllowedMethods
public function getAllowedMethods() { $result = []; if ($this->get) { $result[] = HttpMethods::GET; } if ($this->post) { $result[] = HttpMethods::POST; } if ($this->put) { $result[] = HttpMethods::PUT; } if ($this->path) { $result[] = HttpMethods::PATCH; } if ($this->delete) { $result[] = HttpMethods::DELETE; } if ($this->head) { $result[] = HttpMethods::HEAD; } if ($this->options) { $result[] = HttpMethods::OPTIONS; } return $result; }
php
public function getAllowedMethods() { $result = []; if ($this->get) { $result[] = HttpMethods::GET; } if ($this->post) { $result[] = HttpMethods::POST; } if ($this->put) { $result[] = HttpMethods::PUT; } if ($this->path) { $result[] = HttpMethods::PATCH; } if ($this->delete) { $result[] = HttpMethods::DELETE; } if ($this->head) { $result[] = HttpMethods::HEAD; } if ($this->options) { $result[] = HttpMethods::OPTIONS; } return $result; }
[ "public", "function", "getAllowedMethods", "(", ")", "{", "$", "result", "=", "[", "]", ";", "if", "(", "$", "this", "->", "get", ")", "{", "$", "result", "[", "]", "=", "HttpMethods", "::", "GET", ";", "}", "if", "(", "$", "this", "->", "post", ")", "{", "$", "result", "[", "]", "=", "HttpMethods", "::", "POST", ";", "}", "if", "(", "$", "this", "->", "put", ")", "{", "$", "result", "[", "]", "=", "HttpMethods", "::", "PUT", ";", "}", "if", "(", "$", "this", "->", "path", ")", "{", "$", "result", "[", "]", "=", "HttpMethods", "::", "PATCH", ";", "}", "if", "(", "$", "this", "->", "delete", ")", "{", "$", "result", "[", "]", "=", "HttpMethods", "::", "DELETE", ";", "}", "if", "(", "$", "this", "->", "head", ")", "{", "$", "result", "[", "]", "=", "HttpMethods", "::", "HEAD", ";", "}", "if", "(", "$", "this", "->", "options", ")", "{", "$", "result", "[", "]", "=", "HttpMethods", "::", "OPTIONS", ";", "}", "return", "$", "result", ";", "}" ]
Get array of allowed methods for this action @return string[]
[ "Get", "array", "of", "allowed", "methods", "for", "this", "action" ]
4d1ee0d4b6bd7d170cf1ec924a8b743b5d486888
https://github.com/php-rest-server/core/blob/4d1ee0d4b6bd7d170cf1ec924a8b743b5d486888/src/Core/General/ActionInfo.php#L122-L148
3,126
interactivesolutions/honeycomb-acl
src/app/http/controllers/HCAuthController.php
HCAuthController.login
public function login(Request $request) { $this->validateLogin($request); // If the class is using the ThrottlesLogins trait, we can automatically throttle // the login attempts for this application. We'll key this by the username and // the IP address of the client making these requests into this application. if( $this->hasTooManyLoginAttempts($request) ) { $this->fireLockoutEvent($request); return $this->sendLockoutResponse($request); } // If the login attempt was unsuccessful we will increment the number of attempts // to login and redirect the user back to the login form. Of course, when this // user surpasses their maximum number of attempts they will get locked out. $this->incrementLoginAttempts($request); if( ! $this->attemptLogin($request) ) { return HCLog::info('AUTH-002', trans('HCACL::users.errors.login')); } // check if user is not activated if( auth()->user()->isNotActivated() ) { $user = auth()->user(); $this->logout($request); $response = $this->activation->sendActivationMail($user); return HCLog::info('AUTH-003', $response); } //TODO update providers? auth()->user()->updateLastLogin(); //redirect to intended url return response(['success' => true, 'redirectURL' => session()->pull('url.intended', url('/'))]); }
php
public function login(Request $request) { $this->validateLogin($request); // If the class is using the ThrottlesLogins trait, we can automatically throttle // the login attempts for this application. We'll key this by the username and // the IP address of the client making these requests into this application. if( $this->hasTooManyLoginAttempts($request) ) { $this->fireLockoutEvent($request); return $this->sendLockoutResponse($request); } // If the login attempt was unsuccessful we will increment the number of attempts // to login and redirect the user back to the login form. Of course, when this // user surpasses their maximum number of attempts they will get locked out. $this->incrementLoginAttempts($request); if( ! $this->attemptLogin($request) ) { return HCLog::info('AUTH-002', trans('HCACL::users.errors.login')); } // check if user is not activated if( auth()->user()->isNotActivated() ) { $user = auth()->user(); $this->logout($request); $response = $this->activation->sendActivationMail($user); return HCLog::info('AUTH-003', $response); } //TODO update providers? auth()->user()->updateLastLogin(); //redirect to intended url return response(['success' => true, 'redirectURL' => session()->pull('url.intended', url('/'))]); }
[ "public", "function", "login", "(", "Request", "$", "request", ")", "{", "$", "this", "->", "validateLogin", "(", "$", "request", ")", ";", "// If the class is using the ThrottlesLogins trait, we can automatically throttle", "// the login attempts for this application. We'll key this by the username and", "// the IP address of the client making these requests into this application.", "if", "(", "$", "this", "->", "hasTooManyLoginAttempts", "(", "$", "request", ")", ")", "{", "$", "this", "->", "fireLockoutEvent", "(", "$", "request", ")", ";", "return", "$", "this", "->", "sendLockoutResponse", "(", "$", "request", ")", ";", "}", "// If the login attempt was unsuccessful we will increment the number of attempts", "// to login and redirect the user back to the login form. Of course, when this", "// user surpasses their maximum number of attempts they will get locked out.", "$", "this", "->", "incrementLoginAttempts", "(", "$", "request", ")", ";", "if", "(", "!", "$", "this", "->", "attemptLogin", "(", "$", "request", ")", ")", "{", "return", "HCLog", "::", "info", "(", "'AUTH-002'", ",", "trans", "(", "'HCACL::users.errors.login'", ")", ")", ";", "}", "// check if user is not activated", "if", "(", "auth", "(", ")", "->", "user", "(", ")", "->", "isNotActivated", "(", ")", ")", "{", "$", "user", "=", "auth", "(", ")", "->", "user", "(", ")", ";", "$", "this", "->", "logout", "(", "$", "request", ")", ";", "$", "response", "=", "$", "this", "->", "activation", "->", "sendActivationMail", "(", "$", "user", ")", ";", "return", "HCLog", "::", "info", "(", "'AUTH-003'", ",", "$", "response", ")", ";", "}", "//TODO update providers?", "auth", "(", ")", "->", "user", "(", ")", "->", "updateLastLogin", "(", ")", ";", "//redirect to intended url", "return", "response", "(", "[", "'success'", "=>", "true", ",", "'redirectURL'", "=>", "session", "(", ")", "->", "pull", "(", "'url.intended'", ",", "url", "(", "'/'", ")", ")", "]", ")", ";", "}" ]
Function which login users @param Request $request @return string
[ "Function", "which", "login", "users" ]
6c73d7d1c5d17ef730593e03386236a746bab12c
https://github.com/interactivesolutions/honeycomb-acl/blob/6c73d7d1c5d17ef730593e03386236a746bab12c/src/app/http/controllers/HCAuthController.php#L69-L108
3,127
interactivesolutions/honeycomb-acl
src/app/http/controllers/HCAuthController.php
HCAuthController.showActivation
public function showActivation(string $token) { $message = null; $tokenRecord = DB::table('hc_users_activations')->where('token', $token)->first(); if( is_null($tokenRecord) ) { $message = trans('HCACL::users.activation.token_not_exists'); } else { if( strtotime($tokenRecord->created_at) + 60 * 60 * 24 < time() ) { $message = trans('HCACL::users.activation.token_expired'); } } return hcview('HCACL::auth.activation', ['token' => $token, 'message' => $message]); }
php
public function showActivation(string $token) { $message = null; $tokenRecord = DB::table('hc_users_activations')->where('token', $token)->first(); if( is_null($tokenRecord) ) { $message = trans('HCACL::users.activation.token_not_exists'); } else { if( strtotime($tokenRecord->created_at) + 60 * 60 * 24 < time() ) { $message = trans('HCACL::users.activation.token_expired'); } } return hcview('HCACL::auth.activation', ['token' => $token, 'message' => $message]); }
[ "public", "function", "showActivation", "(", "string", "$", "token", ")", "{", "$", "message", "=", "null", ";", "$", "tokenRecord", "=", "DB", "::", "table", "(", "'hc_users_activations'", ")", "->", "where", "(", "'token'", ",", "$", "token", ")", "->", "first", "(", ")", ";", "if", "(", "is_null", "(", "$", "tokenRecord", ")", ")", "{", "$", "message", "=", "trans", "(", "'HCACL::users.activation.token_not_exists'", ")", ";", "}", "else", "{", "if", "(", "strtotime", "(", "$", "tokenRecord", "->", "created_at", ")", "+", "60", "*", "60", "*", "24", "<", "time", "(", ")", ")", "{", "$", "message", "=", "trans", "(", "'HCACL::users.activation.token_expired'", ")", ";", "}", "}", "return", "hcview", "(", "'HCACL::auth.activation'", ",", "[", "'token'", "=>", "$", "token", ",", "'message'", "=>", "$", "message", "]", ")", ";", "}" ]
Show activation page @param $token @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
[ "Show", "activation", "page" ]
6c73d7d1c5d17ef730593e03386236a746bab12c
https://github.com/interactivesolutions/honeycomb-acl/blob/6c73d7d1c5d17ef730593e03386236a746bab12c/src/app/http/controllers/HCAuthController.php#L221-L236
3,128
DripsPHP/HTTP
src/Response.php
Response.send
public function send() { if (!static::isSent()) { static::call('send', $this); foreach ($this->headers as $header => $value) { $this->setHttpHeader($header, $value); } http_response_code($this->status); echo $this->body; static::$sent = true; return true; } return false; }
php
public function send() { if (!static::isSent()) { static::call('send', $this); foreach ($this->headers as $header => $value) { $this->setHttpHeader($header, $value); } http_response_code($this->status); echo $this->body; static::$sent = true; return true; } return false; }
[ "public", "function", "send", "(", ")", "{", "if", "(", "!", "static", "::", "isSent", "(", ")", ")", "{", "static", "::", "call", "(", "'send'", ",", "$", "this", ")", ";", "foreach", "(", "$", "this", "->", "headers", "as", "$", "header", "=>", "$", "value", ")", "{", "$", "this", "->", "setHttpHeader", "(", "$", "header", ",", "$", "value", ")", ";", "}", "http_response_code", "(", "$", "this", "->", "status", ")", ";", "echo", "$", "this", "->", "body", ";", "static", "::", "$", "sent", "=", "true", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Bastelt den Response zusammen und sendet diesen ab, sofern er noch nicht abgesendet wurde. @return bool
[ "Bastelt", "den", "Response", "zusammen", "und", "sendet", "diesen", "ab", "sofern", "er", "noch", "nicht", "abgesendet", "wurde", "." ]
6c571427231f95f3a26f4893fc50a251d1a29aba
https://github.com/DripsPHP/HTTP/blob/6c571427231f95f3a26f4893fc50a251d1a29aba/src/Response.php#L97-L110
3,129
webriq/core
module/Core/src/Grid/Core/View/Helper/IsModuleLoaded.php
IsModuleLoaded.isAllModulesLoaded
protected function isAllModulesLoaded( array $modules ) { foreach ( $modules as $module ) { if ( ! $this->isModuleLoaded( $module ) ) { return false; } } return true; }
php
protected function isAllModulesLoaded( array $modules ) { foreach ( $modules as $module ) { if ( ! $this->isModuleLoaded( $module ) ) { return false; } } return true; }
[ "protected", "function", "isAllModulesLoaded", "(", "array", "$", "modules", ")", "{", "foreach", "(", "$", "modules", "as", "$", "module", ")", "{", "if", "(", "!", "$", "this", "->", "isModuleLoaded", "(", "$", "module", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Is all modules loaded @param array $modules @return bool
[ "Is", "all", "modules", "loaded" ]
cfeb6e8a4732561c2215ec94e736c07f9b8bc990
https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/Core/src/Grid/Core/View/Helper/IsModuleLoaded.php#L72-L83
3,130
webriq/core
module/Core/src/Grid/Core/View/Helper/IsModuleLoaded.php
IsModuleLoaded.isModulesLoaded
public function isModulesLoaded( $modules ) { if ( $modules instanceof Traversable ) { $modules = ArrayUtils::iteratorToArray( $modules ); } if ( ! is_array( $modules ) ) { $modules = preg_split( '/\|{1,2}/', (string) $modules ); } foreach ( $modules as $module ) { if ( ! is_array( $module ) ) { $module = preg_split( '/&{1,2}/', (string) $module ); } if ( $this->isAllModulesLoaded( $module ) ) { return true; } } return false; }
php
public function isModulesLoaded( $modules ) { if ( $modules instanceof Traversable ) { $modules = ArrayUtils::iteratorToArray( $modules ); } if ( ! is_array( $modules ) ) { $modules = preg_split( '/\|{1,2}/', (string) $modules ); } foreach ( $modules as $module ) { if ( ! is_array( $module ) ) { $module = preg_split( '/&{1,2}/', (string) $module ); } if ( $this->isAllModulesLoaded( $module ) ) { return true; } } return false; }
[ "public", "function", "isModulesLoaded", "(", "$", "modules", ")", "{", "if", "(", "$", "modules", "instanceof", "Traversable", ")", "{", "$", "modules", "=", "ArrayUtils", "::", "iteratorToArray", "(", "$", "modules", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "modules", ")", ")", "{", "$", "modules", "=", "preg_split", "(", "'/\\|{1,2}/'", ",", "(", "string", ")", "$", "modules", ")", ";", "}", "foreach", "(", "$", "modules", "as", "$", "module", ")", "{", "if", "(", "!", "is_array", "(", "$", "module", ")", ")", "{", "$", "module", "=", "preg_split", "(", "'/&{1,2}/'", ",", "(", "string", ")", "$", "module", ")", ";", "}", "if", "(", "$", "this", "->", "isAllModulesLoaded", "(", "$", "module", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Is any modules loaded @param string|array $modules @return bool
[ "Is", "any", "modules", "loaded" ]
cfeb6e8a4732561c2215ec94e736c07f9b8bc990
https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/Core/src/Grid/Core/View/Helper/IsModuleLoaded.php#L91-L117
3,131
yrizos/data-entity
src/Type.php
Type.factory
public static function factory($type) { if ($type instanceof TypeInterface) return $type; if (strpos($type, "\\") === false) { $type = ucfirst(trim(strval($type))); if (strripos(strrev($type), strrev('type')) === false) $type .= 'Type'; $type = "DataEntity\\Type\\" . $type; } if ( !class_exists($type) || !in_array("DataEntity\\TypeInterface", class_implements($type)) ) throw new \InvalidArgumentException('Type ' . $type . ' is invalid.'); return new $type; }
php
public static function factory($type) { if ($type instanceof TypeInterface) return $type; if (strpos($type, "\\") === false) { $type = ucfirst(trim(strval($type))); if (strripos(strrev($type), strrev('type')) === false) $type .= 'Type'; $type = "DataEntity\\Type\\" . $type; } if ( !class_exists($type) || !in_array("DataEntity\\TypeInterface", class_implements($type)) ) throw new \InvalidArgumentException('Type ' . $type . ' is invalid.'); return new $type; }
[ "public", "static", "function", "factory", "(", "$", "type", ")", "{", "if", "(", "$", "type", "instanceof", "TypeInterface", ")", "return", "$", "type", ";", "if", "(", "strpos", "(", "$", "type", ",", "\"\\\\\"", ")", "===", "false", ")", "{", "$", "type", "=", "ucfirst", "(", "trim", "(", "strval", "(", "$", "type", ")", ")", ")", ";", "if", "(", "strripos", "(", "strrev", "(", "$", "type", ")", ",", "strrev", "(", "'type'", ")", ")", "===", "false", ")", "$", "type", ".=", "'Type'", ";", "$", "type", "=", "\"DataEntity\\\\Type\\\\\"", ".", "$", "type", ";", "}", "if", "(", "!", "class_exists", "(", "$", "type", ")", "||", "!", "in_array", "(", "\"DataEntity\\\\TypeInterface\"", ",", "class_implements", "(", "$", "type", ")", ")", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "'Type '", ".", "$", "type", ".", "' is invalid.'", ")", ";", "return", "new", "$", "type", ";", "}" ]
Builds type objects @param string|TypeInterface $type @return TypeInterface @throws \InvalidArgumentException
[ "Builds", "type", "objects" ]
7dd80ff837ee6bb1c1d96d2458fa6a9b1bb31686
https://github.com/yrizos/data-entity/blob/7dd80ff837ee6bb1c1d96d2458fa6a9b1bb31686/src/Type.php#L28-L45
3,132
indigophp-archive/codeception-fuel-module
fuel/fuel/core/classes/uri.php
Uri.to_assoc
public static function to_assoc($start = 1) { $segments = array_slice(static::segments(), ($start - 1)); count($segments) % 2 and $segments[] = null; return \Arr::to_assoc($segments); }
php
public static function to_assoc($start = 1) { $segments = array_slice(static::segments(), ($start - 1)); count($segments) % 2 and $segments[] = null; return \Arr::to_assoc($segments); }
[ "public", "static", "function", "to_assoc", "(", "$", "start", "=", "1", ")", "{", "$", "segments", "=", "array_slice", "(", "static", "::", "segments", "(", ")", ",", "(", "$", "start", "-", "1", ")", ")", ";", "count", "(", "$", "segments", ")", "%", "2", "and", "$", "segments", "[", "]", "=", "null", ";", "return", "\\", "Arr", "::", "to_assoc", "(", "$", "segments", ")", ";", "}" ]
Converts the current URI segments to an associative array. If the URI has an odd number of segments, an empty value will be added. @param int segment number to start from. default value is the first segment @return array the assoc array
[ "Converts", "the", "current", "URI", "segments", "to", "an", "associative", "array", ".", "If", "the", "URI", "has", "an", "odd", "number", "of", "segments", "an", "empty", "value", "will", "be", "added", "." ]
0973b7cbd540a0e89cc5bb7af94627f77f09bf49
https://github.com/indigophp-archive/codeception-fuel-module/blob/0973b7cbd540a0e89cc5bb7af94627f77f09bf49/fuel/fuel/core/classes/uri.php#L120-L126
3,133
indigophp-archive/codeception-fuel-module
fuel/fuel/core/classes/uri.php
Uri.create
public static function create($uri = null, $variables = array(), $get_variables = array(), $secure = null) { $url = ''; is_null($uri) and $uri = static::string(); // If the given uri is not a full URL if( ! preg_match("#^(http|https|ftp)://#i", $uri)) { $url .= \Config::get('base_url'); if ($index_file = \Config::get('index_file')) { $url .= $index_file.'/'; } } $url .= ltrim($uri, '/'); // stick a url suffix onto it if defined and needed if ($url_suffix = \Config::get('url_suffix', false) and substr($url, -1) != '/') { $current_suffix = strrchr($url, '.'); if ( ! $current_suffix or strpos($current_suffix, '/') !== false) { $url .= $url_suffix; } } if ( ! empty($get_variables)) { $char = strpos($url, '?') === false ? '?' : '&'; if (is_string($get_variables)) { $url .= $char.str_replace('%3A', ':', $get_variables); } else { $url .= $char.str_replace('%3A', ':', http_build_query($get_variables)); } } array_walk( $variables, function ($val, $key) use (&$url) { $url = str_replace(':'.$key, $val, $url); } ); is_bool($secure) and $url = http_build_url($url, array('scheme' => $secure ? 'https' : 'http')); return $url; }
php
public static function create($uri = null, $variables = array(), $get_variables = array(), $secure = null) { $url = ''; is_null($uri) and $uri = static::string(); // If the given uri is not a full URL if( ! preg_match("#^(http|https|ftp)://#i", $uri)) { $url .= \Config::get('base_url'); if ($index_file = \Config::get('index_file')) { $url .= $index_file.'/'; } } $url .= ltrim($uri, '/'); // stick a url suffix onto it if defined and needed if ($url_suffix = \Config::get('url_suffix', false) and substr($url, -1) != '/') { $current_suffix = strrchr($url, '.'); if ( ! $current_suffix or strpos($current_suffix, '/') !== false) { $url .= $url_suffix; } } if ( ! empty($get_variables)) { $char = strpos($url, '?') === false ? '?' : '&'; if (is_string($get_variables)) { $url .= $char.str_replace('%3A', ':', $get_variables); } else { $url .= $char.str_replace('%3A', ':', http_build_query($get_variables)); } } array_walk( $variables, function ($val, $key) use (&$url) { $url = str_replace(':'.$key, $val, $url); } ); is_bool($secure) and $url = http_build_url($url, array('scheme' => $secure ? 'https' : 'http')); return $url; }
[ "public", "static", "function", "create", "(", "$", "uri", "=", "null", ",", "$", "variables", "=", "array", "(", ")", ",", "$", "get_variables", "=", "array", "(", ")", ",", "$", "secure", "=", "null", ")", "{", "$", "url", "=", "''", ";", "is_null", "(", "$", "uri", ")", "and", "$", "uri", "=", "static", "::", "string", "(", ")", ";", "// If the given uri is not a full URL", "if", "(", "!", "preg_match", "(", "\"#^(http|https|ftp)://#i\"", ",", "$", "uri", ")", ")", "{", "$", "url", ".=", "\\", "Config", "::", "get", "(", "'base_url'", ")", ";", "if", "(", "$", "index_file", "=", "\\", "Config", "::", "get", "(", "'index_file'", ")", ")", "{", "$", "url", ".=", "$", "index_file", ".", "'/'", ";", "}", "}", "$", "url", ".=", "ltrim", "(", "$", "uri", ",", "'/'", ")", ";", "// stick a url suffix onto it if defined and needed", "if", "(", "$", "url_suffix", "=", "\\", "Config", "::", "get", "(", "'url_suffix'", ",", "false", ")", "and", "substr", "(", "$", "url", ",", "-", "1", ")", "!=", "'/'", ")", "{", "$", "current_suffix", "=", "strrchr", "(", "$", "url", ",", "'.'", ")", ";", "if", "(", "!", "$", "current_suffix", "or", "strpos", "(", "$", "current_suffix", ",", "'/'", ")", "!==", "false", ")", "{", "$", "url", ".=", "$", "url_suffix", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "get_variables", ")", ")", "{", "$", "char", "=", "strpos", "(", "$", "url", ",", "'?'", ")", "===", "false", "?", "'?'", ":", "'&'", ";", "if", "(", "is_string", "(", "$", "get_variables", ")", ")", "{", "$", "url", ".=", "$", "char", ".", "str_replace", "(", "'%3A'", ",", "':'", ",", "$", "get_variables", ")", ";", "}", "else", "{", "$", "url", ".=", "$", "char", ".", "str_replace", "(", "'%3A'", ",", "':'", ",", "http_build_query", "(", "$", "get_variables", ")", ")", ";", "}", "}", "array_walk", "(", "$", "variables", ",", "function", "(", "$", "val", ",", "$", "key", ")", "use", "(", "&", "$", "url", ")", "{", "$", "url", "=", "str_replace", "(", "':'", ".", "$", "key", ",", "$", "val", ",", "$", "url", ")", ";", "}", ")", ";", "is_bool", "(", "$", "secure", ")", "and", "$", "url", "=", "http_build_url", "(", "$", "url", ",", "array", "(", "'scheme'", "=>", "$", "secure", "?", "'https'", ":", "'http'", ")", ")", ";", "return", "$", "url", ";", "}" ]
Creates a url with the given uri, including the base url @param string $uri The uri to create the URL for @param array $variables Some variables for the URL @param array $get_variables Any GET urls to append via a query string @param bool $secure If false, force http. If true, force https @return string
[ "Creates", "a", "url", "with", "the", "given", "uri", "including", "the", "base", "url" ]
0973b7cbd540a0e89cc5bb7af94627f77f09bf49
https://github.com/indigophp-archive/codeception-fuel-module/blob/0973b7cbd540a0e89cc5bb7af94627f77f09bf49/fuel/fuel/core/classes/uri.php#L152-L203
3,134
indigophp-archive/codeception-fuel-module
fuel/fuel/core/classes/uri.php
Uri.base
public static function base($include_index = true) { $url = \Config::get('base_url'); if ($include_index and \Config::get('index_file')) { $url .= \Config::get('index_file').'/'; } return $url; }
php
public static function base($include_index = true) { $url = \Config::get('base_url'); if ($include_index and \Config::get('index_file')) { $url .= \Config::get('index_file').'/'; } return $url; }
[ "public", "static", "function", "base", "(", "$", "include_index", "=", "true", ")", "{", "$", "url", "=", "\\", "Config", "::", "get", "(", "'base_url'", ")", ";", "if", "(", "$", "include_index", "and", "\\", "Config", "::", "get", "(", "'index_file'", ")", ")", "{", "$", "url", ".=", "\\", "Config", "::", "get", "(", "'index_file'", ")", ".", "'/'", ";", "}", "return", "$", "url", ";", "}" ]
Gets the base URL, including the index_file if wanted. @param bool $include_index Whether to include index.php in the URL @return string
[ "Gets", "the", "base", "URL", "including", "the", "index_file", "if", "wanted", "." ]
0973b7cbd540a0e89cc5bb7af94627f77f09bf49
https://github.com/indigophp-archive/codeception-fuel-module/blob/0973b7cbd540a0e89cc5bb7af94627f77f09bf49/fuel/fuel/core/classes/uri.php#L231-L241
3,135
indigophp-archive/codeception-fuel-module
fuel/fuel/core/classes/uri.php
Uri.build_query_string
public static function build_query_string() { $params = array(); foreach (func_get_args() as $arg) { $arg = is_array($arg) ? $arg : array($arg => '1'); $params = array_merge($params, $arg); } return http_build_query($params); }
php
public static function build_query_string() { $params = array(); foreach (func_get_args() as $arg) { $arg = is_array($arg) ? $arg : array($arg => '1'); $params = array_merge($params, $arg); } return http_build_query($params); }
[ "public", "static", "function", "build_query_string", "(", ")", "{", "$", "params", "=", "array", "(", ")", ";", "foreach", "(", "func_get_args", "(", ")", "as", "$", "arg", ")", "{", "$", "arg", "=", "is_array", "(", "$", "arg", ")", "?", "$", "arg", ":", "array", "(", "$", "arg", "=>", "'1'", ")", ";", "$", "params", "=", "array_merge", "(", "$", "params", ",", "$", "arg", ")", ";", "}", "return", "http_build_query", "(", "$", "params", ")", ";", "}" ]
Builds a query string by merging all array and string values passed. If a string is passed, it will be assumed to be a switch, and converted to "string=1". @param array|string Array or string to merge @param array|string ... @return string
[ "Builds", "a", "query", "string", "by", "merging", "all", "array", "and", "string", "values", "passed", ".", "If", "a", "string", "is", "passed", "it", "will", "be", "assumed", "to", "be", "a", "switch", "and", "converted", "to", "string", "=", "1", "." ]
0973b7cbd540a0e89cc5bb7af94627f77f09bf49
https://github.com/indigophp-archive/codeception-fuel-module/blob/0973b7cbd540a0e89cc5bb7af94627f77f09bf49/fuel/fuel/core/classes/uri.php#L253-L265
3,136
indigophp-archive/codeception-fuel-module
fuel/fuel/core/classes/uri.php
Uri.update_query_string
public static function update_query_string($vars = array(), $uri = null, $secure = null) { // unify the input data if ( ! is_array($vars)) { $vars = array($vars => $uri); $uri = null; } // if we have a custom URI, use that if ($uri === null) { // use the current URI if not is passed $uri = static::current(); // merge them with the existing query string data $vars = array_merge(\Input::get(), $vars); } // return the updated uri return static::create($uri, array(), $vars, $secure); }
php
public static function update_query_string($vars = array(), $uri = null, $secure = null) { // unify the input data if ( ! is_array($vars)) { $vars = array($vars => $uri); $uri = null; } // if we have a custom URI, use that if ($uri === null) { // use the current URI if not is passed $uri = static::current(); // merge them with the existing query string data $vars = array_merge(\Input::get(), $vars); } // return the updated uri return static::create($uri, array(), $vars, $secure); }
[ "public", "static", "function", "update_query_string", "(", "$", "vars", "=", "array", "(", ")", ",", "$", "uri", "=", "null", ",", "$", "secure", "=", "null", ")", "{", "// unify the input data", "if", "(", "!", "is_array", "(", "$", "vars", ")", ")", "{", "$", "vars", "=", "array", "(", "$", "vars", "=>", "$", "uri", ")", ";", "$", "uri", "=", "null", ";", "}", "// if we have a custom URI, use that", "if", "(", "$", "uri", "===", "null", ")", "{", "// use the current URI if not is passed", "$", "uri", "=", "static", "::", "current", "(", ")", ";", "// merge them with the existing query string data", "$", "vars", "=", "array_merge", "(", "\\", "Input", "::", "get", "(", ")", ",", "$", "vars", ")", ";", "}", "// return the updated uri", "return", "static", "::", "create", "(", "$", "uri", ",", "array", "(", ")", ",", "$", "vars", ",", "$", "secure", ")", ";", "}" ]
Updates the query string of the current or passed URL with the data passed @param array|string $vars Assoc array of GET variables, or a get variable name @param string|mixed $uri Optional URI to use if $vars is an array, otherwise the get variable name @param bool $secure If false, force http. If true, force https @return string
[ "Updates", "the", "query", "string", "of", "the", "current", "or", "passed", "URL", "with", "the", "data", "passed" ]
0973b7cbd540a0e89cc5bb7af94627f77f09bf49
https://github.com/indigophp-archive/codeception-fuel-module/blob/0973b7cbd540a0e89cc5bb7af94627f77f09bf49/fuel/fuel/core/classes/uri.php#L276-L297
3,137
indigophp-archive/codeception-fuel-module
fuel/fuel/core/classes/uri.php
Uri.get_segment
public function get_segment($segment, $default = null) { if (isset($this->segments[$segment - 1])) { return $this->segments[$segment - 1]; } return \Fuel::value($default); }
php
public function get_segment($segment, $default = null) { if (isset($this->segments[$segment - 1])) { return $this->segments[$segment - 1]; } return \Fuel::value($default); }
[ "public", "function", "get_segment", "(", "$", "segment", ",", "$", "default", "=", "null", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "segments", "[", "$", "segment", "-", "1", "]", ")", ")", "{", "return", "$", "this", "->", "segments", "[", "$", "segment", "-", "1", "]", ";", "}", "return", "\\", "Fuel", "::", "value", "(", "$", "default", ")", ";", "}" ]
Get the specified URI segment, return default if it doesn't exist. Segment index is 1 based, not 0 based @param string $segment The 1-based segment index @param mixed $default The default value @return mixed
[ "Get", "the", "specified", "URI", "segment", "return", "default", "if", "it", "doesn", "t", "exist", "." ]
0973b7cbd540a0e89cc5bb7af94627f77f09bf49
https://github.com/indigophp-archive/codeception-fuel-module/blob/0973b7cbd540a0e89cc5bb7af94627f77f09bf49/fuel/fuel/core/classes/uri.php#L372-L380
3,138
jhorlima/wp-mocabonita
src/tools/MbMigration.php
MbMigration.enablePdoConnection
public static function enablePdoConnection() { if (is_null(self::$instance)) { global $wpdb; $capsule = new self(); $capsule->addConnection([ 'driver' => 'mysql', 'host' => DB_HOST, 'database' => DB_NAME, 'username' => DB_USER, 'password' => DB_PASSWORD, 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_general_ci', ]); $capsule->setAsGlobal(); $capsule->bootEloquent(); } }
php
public static function enablePdoConnection() { if (is_null(self::$instance)) { global $wpdb; $capsule = new self(); $capsule->addConnection([ 'driver' => 'mysql', 'host' => DB_HOST, 'database' => DB_NAME, 'username' => DB_USER, 'password' => DB_PASSWORD, 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_general_ci', ]); $capsule->setAsGlobal(); $capsule->bootEloquent(); } }
[ "public", "static", "function", "enablePdoConnection", "(", ")", "{", "if", "(", "is_null", "(", "self", "::", "$", "instance", ")", ")", "{", "global", "$", "wpdb", ";", "$", "capsule", "=", "new", "self", "(", ")", ";", "$", "capsule", "->", "addConnection", "(", "[", "'driver'", "=>", "'mysql'", ",", "'host'", "=>", "DB_HOST", ",", "'database'", "=>", "DB_NAME", ",", "'username'", "=>", "DB_USER", ",", "'password'", "=>", "DB_PASSWORD", ",", "'charset'", "=>", "'utf8mb4'", ",", "'collation'", "=>", "'utf8mb4_general_ci'", ",", "]", ")", ";", "$", "capsule", "->", "setAsGlobal", "(", ")", ";", "$", "capsule", "->", "bootEloquent", "(", ")", ";", "}", "}" ]
Enable PDO for eloquent @return void
[ "Enable", "PDO", "for", "eloquent" ]
a864b40d5452bc9b892f02a6bb28c02639f25fa8
https://github.com/jhorlima/wp-mocabonita/blob/a864b40d5452bc9b892f02a6bb28c02639f25fa8/src/tools/MbMigration.php#L31-L49
3,139
coolms/authentication
src/Mvc/Controller/Plugin/Authentication.php
Authentication.getRequest
public function getRequest() { if (null === $this->request) { $this->setRequest($this->getController()->getRequest()); } return $this->request; }
php
public function getRequest() { if (null === $this->request) { $this->setRequest($this->getController()->getRequest()); } return $this->request; }
[ "public", "function", "getRequest", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "request", ")", "{", "$", "this", "->", "setRequest", "(", "$", "this", "->", "getController", "(", ")", "->", "getRequest", "(", ")", ")", ";", "}", "return", "$", "this", "->", "request", ";", "}" ]
Get request to be authenticated @return RequestInterface
[ "Get", "request", "to", "be", "authenticated" ]
4563cc4cc3a4d777db45977bd179cc5bd3f57cd8
https://github.com/coolms/authentication/blob/4563cc4cc3a4d777db45977bd179cc5bd3f57cd8/src/Mvc/Controller/Plugin/Authentication.php#L60-L67
3,140
coolms/authentication
src/Mvc/Controller/Plugin/Authentication.php
Authentication.getAuthenticationAdapter
public function getAuthenticationAdapter() { if (null === $this->authenticationAdapter) { $authenticationAdapter = $this->getAuthenticationService()->getAdapter(); $this->setAuthenticationAdapter($authenticationAdapter); } return $this->authenticationAdapter; }
php
public function getAuthenticationAdapter() { if (null === $this->authenticationAdapter) { $authenticationAdapter = $this->getAuthenticationService()->getAdapter(); $this->setAuthenticationAdapter($authenticationAdapter); } return $this->authenticationAdapter; }
[ "public", "function", "getAuthenticationAdapter", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "authenticationAdapter", ")", "{", "$", "authenticationAdapter", "=", "$", "this", "->", "getAuthenticationService", "(", ")", "->", "getAdapter", "(", ")", ";", "$", "this", "->", "setAuthenticationAdapter", "(", "$", "authenticationAdapter", ")", ";", "}", "return", "$", "this", "->", "authenticationAdapter", ";", "}" ]
Get authentication adapter @return AdapterInterface
[ "Get", "authentication", "adapter" ]
4563cc4cc3a4d777db45977bd179cc5bd3f57cd8
https://github.com/coolms/authentication/blob/4563cc4cc3a4d777db45977bd179cc5bd3f57cd8/src/Mvc/Controller/Plugin/Authentication.php#L164-L172
3,141
51systems/zf2-extensions
src/Http/RequestUtils.php
RequestUtils.toUriString
public static function toUriString(Request $request) { $uri = clone $request->getUri(); $uri->setQuery(array_merge($uri->getQueryAsArray(), $request->getQuery()->toArray())); return $uri->toString(); }
php
public static function toUriString(Request $request) { $uri = clone $request->getUri(); $uri->setQuery(array_merge($uri->getQueryAsArray(), $request->getQuery()->toArray())); return $uri->toString(); }
[ "public", "static", "function", "toUriString", "(", "Request", "$", "request", ")", "{", "$", "uri", "=", "clone", "$", "request", "->", "getUri", "(", ")", ";", "$", "uri", "->", "setQuery", "(", "array_merge", "(", "$", "uri", "->", "getQueryAsArray", "(", ")", ",", "$", "request", "->", "getQuery", "(", ")", "->", "toArray", "(", ")", ")", ")", ";", "return", "$", "uri", "->", "toString", "(", ")", ";", "}" ]
Converts the request into a url. This encodes the query parameters associated with the request. @param Request $request @return string
[ "Converts", "the", "request", "into", "a", "url", "." ]
81534327733ce8469e6f50e1ee0e1ae6d0c2f5ff
https://github.com/51systems/zf2-extensions/blob/81534327733ce8469e6f50e1ee0e1ae6d0c2f5ff/src/Http/RequestUtils.php#L19-L27
3,142
synapsestudios/synapse-base
src/Synapse/Config/Config.php
Config.attach
public function attach(ReaderInterface $reader, $last = true) { if ($last) { // Add to the end (i.e. read this last, highest merge priority) $this->readers[] = $reader; } else { // Add to the beginning (i.e. read this first, lowest merge priority) array_unshift($this->readers, $reader); } // Clear any cached groups $this->groups = []; }
php
public function attach(ReaderInterface $reader, $last = true) { if ($last) { // Add to the end (i.e. read this last, highest merge priority) $this->readers[] = $reader; } else { // Add to the beginning (i.e. read this first, lowest merge priority) array_unshift($this->readers, $reader); } // Clear any cached groups $this->groups = []; }
[ "public", "function", "attach", "(", "ReaderInterface", "$", "reader", ",", "$", "last", "=", "true", ")", "{", "if", "(", "$", "last", ")", "{", "// Add to the end (i.e. read this last, highest merge priority)", "$", "this", "->", "readers", "[", "]", "=", "$", "reader", ";", "}", "else", "{", "// Add to the beginning (i.e. read this first, lowest merge priority)", "array_unshift", "(", "$", "this", "->", "readers", ",", "$", "reader", ")", ";", "}", "// Clear any cached groups", "$", "this", "->", "groups", "=", "[", "]", ";", "}" ]
Attach a new config reader Readers are accessed in order by their priority. By default, their priority is the order in which they were attached. Calling Config::attach($reader) will cause any configs read by it to override any configs read by previously attached readers. @param ReaderInterface $reader @param boolean $last
[ "Attach", "a", "new", "config", "reader" ]
60c830550491742a077ab063f924e2f0b63825da
https://github.com/synapsestudios/synapse-base/blob/60c830550491742a077ab063f924e2f0b63825da/src/Synapse/Config/Config.php#L21-L33
3,143
synapsestudios/synapse-base
src/Synapse/Config/Config.php
Config.detach
public function detach(ReaderInterface $reader) { if (($key = array_search($reader, $this->readers)) !== false) { unset($this->readers[$key]); } // Clear any cached groups $this->groups = []; }
php
public function detach(ReaderInterface $reader) { if (($key = array_search($reader, $this->readers)) !== false) { unset($this->readers[$key]); } // Clear any cached groups $this->groups = []; }
[ "public", "function", "detach", "(", "ReaderInterface", "$", "reader", ")", "{", "if", "(", "(", "$", "key", "=", "array_search", "(", "$", "reader", ",", "$", "this", "->", "readers", ")", ")", "!==", "false", ")", "{", "unset", "(", "$", "this", "->", "readers", "[", "$", "key", "]", ")", ";", "}", "// Clear any cached groups", "$", "this", "->", "groups", "=", "[", "]", ";", "}" ]
Detach a config reader @param ReaderInterface $reader
[ "Detach", "a", "config", "reader" ]
60c830550491742a077ab063f924e2f0b63825da
https://github.com/synapsestudios/synapse-base/blob/60c830550491742a077ab063f924e2f0b63825da/src/Synapse/Config/Config.php#L40-L48
3,144
synapsestudios/synapse-base
src/Synapse/Config/Config.php
Config.load
public function load($groupName) { if (! count($this->readers)) { throw new \RuntimeException('No config readers attached'); } if (! $groupName) { throw new \InvalidArgumentException('No config group specified'); } if (! is_string($groupName)) { throw new \InvalidArgumentException('Config group must be a string'); } if (isset($this->groups[$groupName])) { return $this->groups[$groupName]; } $config = []; foreach ($this->readers as $reader) { if ($groupConfig = $reader->load($groupName)) { $config = array_replace_recursive($config, $groupConfig); } } $this->groups[$groupName] = $config; return $this->groups[$groupName]; }
php
public function load($groupName) { if (! count($this->readers)) { throw new \RuntimeException('No config readers attached'); } if (! $groupName) { throw new \InvalidArgumentException('No config group specified'); } if (! is_string($groupName)) { throw new \InvalidArgumentException('Config group must be a string'); } if (isset($this->groups[$groupName])) { return $this->groups[$groupName]; } $config = []; foreach ($this->readers as $reader) { if ($groupConfig = $reader->load($groupName)) { $config = array_replace_recursive($config, $groupConfig); } } $this->groups[$groupName] = $config; return $this->groups[$groupName]; }
[ "public", "function", "load", "(", "$", "groupName", ")", "{", "if", "(", "!", "count", "(", "$", "this", "->", "readers", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'No config readers attached'", ")", ";", "}", "if", "(", "!", "$", "groupName", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'No config group specified'", ")", ";", "}", "if", "(", "!", "is_string", "(", "$", "groupName", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Config group must be a string'", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "groups", "[", "$", "groupName", "]", ")", ")", "{", "return", "$", "this", "->", "groups", "[", "$", "groupName", "]", ";", "}", "$", "config", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "readers", "as", "$", "reader", ")", "{", "if", "(", "$", "groupConfig", "=", "$", "reader", "->", "load", "(", "$", "groupName", ")", ")", "{", "$", "config", "=", "array_replace_recursive", "(", "$", "config", ",", "$", "groupConfig", ")", ";", "}", "}", "$", "this", "->", "groups", "[", "$", "groupName", "]", "=", "$", "config", ";", "return", "$", "this", "->", "groups", "[", "$", "groupName", "]", ";", "}" ]
Load configuration for a group @param string $groupName @return array
[ "Load", "configuration", "for", "a", "group" ]
60c830550491742a077ab063f924e2f0b63825da
https://github.com/synapsestudios/synapse-base/blob/60c830550491742a077ab063f924e2f0b63825da/src/Synapse/Config/Config.php#L66-L95
3,145
php-packages/fluent
src/PhpPackages/Fluent/Fluent.php
Fluent.registerCall
public function registerCall($name, array $arguments = []) { $name = strtolower(preg_replace("/([A-Z]{1})/", "_$0", $name)); $this->calls = array_merge($this->calls, array_filter(explode("_", $name))); if (count($arguments) > 0) { $lastIndex = count($this->calls) - 1; $this->calls[$lastIndex] = [$this->calls[$lastIndex], $arguments]; } }
php
public function registerCall($name, array $arguments = []) { $name = strtolower(preg_replace("/([A-Z]{1})/", "_$0", $name)); $this->calls = array_merge($this->calls, array_filter(explode("_", $name))); if (count($arguments) > 0) { $lastIndex = count($this->calls) - 1; $this->calls[$lastIndex] = [$this->calls[$lastIndex], $arguments]; } }
[ "public", "function", "registerCall", "(", "$", "name", ",", "array", "$", "arguments", "=", "[", "]", ")", "{", "$", "name", "=", "strtolower", "(", "preg_replace", "(", "\"/([A-Z]{1})/\"", ",", "\"_$0\"", ",", "$", "name", ")", ")", ";", "$", "this", "->", "calls", "=", "array_merge", "(", "$", "this", "->", "calls", ",", "array_filter", "(", "explode", "(", "\"_\"", ",", "$", "name", ")", ")", ")", ";", "if", "(", "count", "(", "$", "arguments", ")", ">", "0", ")", "{", "$", "lastIndex", "=", "count", "(", "$", "this", "->", "calls", ")", "-", "1", ";", "$", "this", "->", "calls", "[", "$", "lastIndex", "]", "=", "[", "$", "this", "->", "calls", "[", "$", "lastIndex", "]", ",", "$", "arguments", "]", ";", "}", "}" ]
Registers a call. @param string $name @param array $arguments @return void
[ "Registers", "a", "call", "." ]
5dfea85aaa9e8ddc3eddbcb95d6511ac187dbc82
https://github.com/php-packages/fluent/blob/5dfea85aaa9e8ddc3eddbcb95d6511ac187dbc82/src/PhpPackages/Fluent/Fluent.php#L20-L31
3,146
laasti/views
src/Engines/PlainPhp.php
PlainPhp.findTemplateFile
protected function findTemplateFile($file) { //Add missing extension $ext = pathinfo($file, PATHINFO_EXTENSION); $file = ($ext === '') ? $file . '.'.$this->getExtension() : $file; $found = false; foreach ($this->locations as $location) { if (is_file($location . '/' . $file)) { $found = true; $file = $location . '/' . $file; continue; } } if (!$found) { throw new TemplateNotFoundException('This template was not found in any of the registered locations: ' . $file); } return $file; }
php
protected function findTemplateFile($file) { //Add missing extension $ext = pathinfo($file, PATHINFO_EXTENSION); $file = ($ext === '') ? $file . '.'.$this->getExtension() : $file; $found = false; foreach ($this->locations as $location) { if (is_file($location . '/' . $file)) { $found = true; $file = $location . '/' . $file; continue; } } if (!$found) { throw new TemplateNotFoundException('This template was not found in any of the registered locations: ' . $file); } return $file; }
[ "protected", "function", "findTemplateFile", "(", "$", "file", ")", "{", "//Add missing extension", "$", "ext", "=", "pathinfo", "(", "$", "file", ",", "PATHINFO_EXTENSION", ")", ";", "$", "file", "=", "(", "$", "ext", "===", "''", ")", "?", "$", "file", ".", "'.'", ".", "$", "this", "->", "getExtension", "(", ")", ":", "$", "file", ";", "$", "found", "=", "false", ";", "foreach", "(", "$", "this", "->", "locations", "as", "$", "location", ")", "{", "if", "(", "is_file", "(", "$", "location", ".", "'/'", ".", "$", "file", ")", ")", "{", "$", "found", "=", "true", ";", "$", "file", "=", "$", "location", ".", "'/'", ".", "$", "file", ";", "continue", ";", "}", "}", "if", "(", "!", "$", "found", ")", "{", "throw", "new", "TemplateNotFoundException", "(", "'This template was not found in any of the registered locations: '", ".", "$", "file", ")", ";", "}", "return", "$", "file", ";", "}" ]
Finds the file by looping through locations @param string $file @return string @throws TemplateNotFoundException
[ "Finds", "the", "file", "by", "looping", "through", "locations" ]
7b45b81b3bec8c902e241e99a85341c256ecf834
https://github.com/laasti/views/blob/7b45b81b3bec8c902e241e99a85341c256ecf834/src/Engines/PlainPhp.php#L106-L126
3,147
OpenResourceManager/client-php
src/ORM.php
ORM.validateAuth
public function validateAuth() { // Send a get request to the API $response = $this->uniRequest->get(implode([$this->authURL, 'validate/']), $this->headers); // Check that we get 20X back if (in_array($response->code, $this->validCodes)) { // Return the response return $response; } else { // If we did not get 20X throw an exception throw new Exception($response->body->message, $response->code); } }
php
public function validateAuth() { // Send a get request to the API $response = $this->uniRequest->get(implode([$this->authURL, 'validate/']), $this->headers); // Check that we get 20X back if (in_array($response->code, $this->validCodes)) { // Return the response return $response; } else { // If we did not get 20X throw an exception throw new Exception($response->body->message, $response->code); } }
[ "public", "function", "validateAuth", "(", ")", "{", "// Send a get request to the API", "$", "response", "=", "$", "this", "->", "uniRequest", "->", "get", "(", "implode", "(", "[", "$", "this", "->", "authURL", ",", "'validate/'", "]", ")", ",", "$", "this", "->", "headers", ")", ";", "// Check that we get 20X back", "if", "(", "in_array", "(", "$", "response", "->", "code", ",", "$", "this", "->", "validCodes", ")", ")", "{", "// Return the response", "return", "$", "response", ";", "}", "else", "{", "// If we did not get 20X throw an exception", "throw", "new", "Exception", "(", "$", "response", "->", "body", "->", "message", ",", "$", "response", "->", "code", ")", ";", "}", "}" ]
Validate Authenticated Session Validates the current JWT with with the API to determine if the session is still valid. @return \Unirest\Response @throws Exception
[ "Validate", "Authenticated", "Session" ]
fa468e3425d32f97294fefed77a7f096f3f8cc86
https://github.com/OpenResourceManager/client-php/blob/fa468e3425d32f97294fefed77a7f096f3f8cc86/src/ORM.php#L169-L181
3,148
tekton-php/session
src/Segment.php
Segment.all
public function all() { $this->resumeOrStartSession(); return isset($_SESSION[$this->name]) ? $_SESSION[$this->name] : []; }
php
public function all() { $this->resumeOrStartSession(); return isset($_SESSION[$this->name]) ? $_SESSION[$this->name] : []; }
[ "public", "function", "all", "(", ")", "{", "$", "this", "->", "resumeOrStartSession", "(", ")", ";", "return", "isset", "(", "$", "_SESSION", "[", "$", "this", "->", "name", "]", ")", "?", "$", "_SESSION", "[", "$", "this", "->", "name", "]", ":", "[", "]", ";", "}" ]
Get all of the session data. @return array
[ "Get", "all", "of", "the", "session", "data", "." ]
5a18f0f33eac9a9297c59649d9ac4f874885f07f
https://github.com/tekton-php/session/blob/5a18f0f33eac9a9297c59649d9ac4f874885f07f/src/Segment.php#L105-L111
3,149
tekton-php/session
src/Segment.php
Segment.remove
public function remove($key) { if (isset($_SESSION[$this->name][$key])) { $value = $_SESSION[$this->name][$key]; unset($_SESSION[$this->name][$key]); return $value; } return null; }
php
public function remove($key) { if (isset($_SESSION[$this->name][$key])) { $value = $_SESSION[$this->name][$key]; unset($_SESSION[$this->name][$key]); return $value; } return null; }
[ "public", "function", "remove", "(", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "_SESSION", "[", "$", "this", "->", "name", "]", "[", "$", "key", "]", ")", ")", "{", "$", "value", "=", "$", "_SESSION", "[", "$", "this", "->", "name", "]", "[", "$", "key", "]", ";", "unset", "(", "$", "_SESSION", "[", "$", "this", "->", "name", "]", "[", "$", "key", "]", ")", ";", "return", "$", "value", ";", "}", "return", "null", ";", "}" ]
Remove an item from the session, returning its value. @param string $key @return mixed
[ "Remove", "an", "item", "from", "the", "session", "returning", "its", "value", "." ]
5a18f0f33eac9a9297c59649d9ac4f874885f07f
https://github.com/tekton-php/session/blob/5a18f0f33eac9a9297c59649d9ac4f874885f07f/src/Segment.php#L163-L172
3,150
cawaphp/db
src/TransactionDatabase.php
TransactionDatabase.rollback
public function rollback() : bool { $sql = 'ROLLBACK'; if (!$this->transactionStarted) { $event = new TimerEvent('db.query'); $this->emitQueryEvent($event, null, $sql); throw new QueryException( $this, $sql, "Can't rollback unstarted transaction" ); } $this->query($sql); $this->transactionStarted = false; $this->instanceDispatcher()->emit(new Event('db.rollback')); return true; }
php
public function rollback() : bool { $sql = 'ROLLBACK'; if (!$this->transactionStarted) { $event = new TimerEvent('db.query'); $this->emitQueryEvent($event, null, $sql); throw new QueryException( $this, $sql, "Can't rollback unstarted transaction" ); } $this->query($sql); $this->transactionStarted = false; $this->instanceDispatcher()->emit(new Event('db.rollback')); return true; }
[ "public", "function", "rollback", "(", ")", ":", "bool", "{", "$", "sql", "=", "'ROLLBACK'", ";", "if", "(", "!", "$", "this", "->", "transactionStarted", ")", "{", "$", "event", "=", "new", "TimerEvent", "(", "'db.query'", ")", ";", "$", "this", "->", "emitQueryEvent", "(", "$", "event", ",", "null", ",", "$", "sql", ")", ";", "throw", "new", "QueryException", "(", "$", "this", ",", "$", "sql", ",", "\"Can't rollback unstarted transaction\"", ")", ";", "}", "$", "this", "->", "query", "(", "$", "sql", ")", ";", "$", "this", "->", "transactionStarted", "=", "false", ";", "$", "this", "->", "instanceDispatcher", "(", ")", "->", "emit", "(", "new", "Event", "(", "'db.rollback'", ")", ")", ";", "return", "true", ";", "}" ]
Rollback a sql transaction. @throws QueryException @return bool
[ "Rollback", "a", "sql", "transaction", "." ]
b5381b39ecdde3e01435711c9c5be67dc1006b11
https://github.com/cawaphp/db/blob/b5381b39ecdde3e01435711c9c5be67dc1006b11/src/TransactionDatabase.php#L91-L112
3,151
bkdotcom/Form
src/Form.php
Form.&
public function &__get($property) { $getter = 'get'.\ucfirst($property); if (\in_array($property, array('alerts','cfg','status'))) { return $this->{$property}; } elseif (\method_exists($this, $getter)) { $return = $this->{$getter}(); return $return; } elseif (isset($this->status[$property])) { return $this->status[$property]; } else { $this->debug->log('property', $property); } }
php
public function &__get($property) { $getter = 'get'.\ucfirst($property); if (\in_array($property, array('alerts','cfg','status'))) { return $this->{$property}; } elseif (\method_exists($this, $getter)) { $return = $this->{$getter}(); return $return; } elseif (isset($this->status[$property])) { return $this->status[$property]; } else { $this->debug->log('property', $property); } }
[ "public", "function", "&", "__get", "(", "$", "property", ")", "{", "$", "getter", "=", "'get'", ".", "\\", "ucfirst", "(", "$", "property", ")", ";", "if", "(", "\\", "in_array", "(", "$", "property", ",", "array", "(", "'alerts'", ",", "'cfg'", ",", "'status'", ")", ")", ")", "{", "return", "$", "this", "->", "{", "$", "property", "}", ";", "}", "elseif", "(", "\\", "method_exists", "(", "$", "this", ",", "$", "getter", ")", ")", "{", "$", "return", "=", "$", "this", "->", "{", "$", "getter", "}", "(", ")", ";", "return", "$", "return", ";", "}", "elseif", "(", "isset", "(", "$", "this", "->", "status", "[", "$", "property", "]", ")", ")", "{", "return", "$", "this", "->", "status", "[", "$", "property", "]", ";", "}", "else", "{", "$", "this", "->", "debug", "->", "log", "(", "'property'", ",", "$", "property", ")", ";", "}", "}" ]
Get protected properties @param string $property property name @return mixed
[ "Get", "protected", "properties" ]
6aa5704b20300e1c8bd1c187a4fa88db9d442cee
https://github.com/bkdotcom/Form/blob/6aa5704b20300e1c8bd1c187a4fa88db9d442cee/src/Form.php#L142-L155
3,152
bkdotcom/Form
src/Form.php
Form.getField
public function getField($fieldName) { $this->debug->group(__METHOD__, $fieldName); $field = false; if (\preg_match('|^(.*?)[/.](.*)$|', $fieldName, $matches)) { $pageName = $matches[1]; $fieldName = $matches[2]; } else { $pageName = $this->status['currentPageName']; } if ($pageName == $this->status['currentPageName'] && isset($this->currentFields[$fieldName])) { $field = &$this->currentFields[$fieldName]; if (!\is_object($field)) { $field['pageI'] = $this->persist->get('i'); $this->currentFields[$fieldName] = $this->buildField($field, $fieldName); } } elseif (isset($this->cfg['pages'][$pageName])) { $pages = $this->persist->get('pages'); foreach ($pages as $pageI => $page) { if ($page['name'] != $pageName) { continue; } foreach ($this->cfg['pages'][$pageName] as $k => $fieldProps) { if ($k === $fieldName || isset($fieldProps['attribs']['name']) && $fieldProps['attribs']['name'] == $fieldName || isset($fieldProps['name']) && $fieldProps['name'] == $fieldName ) { $this->debug->info('found field'); $fieldProps['pageI'] = $pageI; $field = $this->buildField($fieldProps, $k); $val = $this->getValue($fieldName, $pageI); $field->val($val, false); break 2; } } break; } } $this->debug->groupEnd(); return $field; }
php
public function getField($fieldName) { $this->debug->group(__METHOD__, $fieldName); $field = false; if (\preg_match('|^(.*?)[/.](.*)$|', $fieldName, $matches)) { $pageName = $matches[1]; $fieldName = $matches[2]; } else { $pageName = $this->status['currentPageName']; } if ($pageName == $this->status['currentPageName'] && isset($this->currentFields[$fieldName])) { $field = &$this->currentFields[$fieldName]; if (!\is_object($field)) { $field['pageI'] = $this->persist->get('i'); $this->currentFields[$fieldName] = $this->buildField($field, $fieldName); } } elseif (isset($this->cfg['pages'][$pageName])) { $pages = $this->persist->get('pages'); foreach ($pages as $pageI => $page) { if ($page['name'] != $pageName) { continue; } foreach ($this->cfg['pages'][$pageName] as $k => $fieldProps) { if ($k === $fieldName || isset($fieldProps['attribs']['name']) && $fieldProps['attribs']['name'] == $fieldName || isset($fieldProps['name']) && $fieldProps['name'] == $fieldName ) { $this->debug->info('found field'); $fieldProps['pageI'] = $pageI; $field = $this->buildField($fieldProps, $k); $val = $this->getValue($fieldName, $pageI); $field->val($val, false); break 2; } } break; } } $this->debug->groupEnd(); return $field; }
[ "public", "function", "getField", "(", "$", "fieldName", ")", "{", "$", "this", "->", "debug", "->", "group", "(", "__METHOD__", ",", "$", "fieldName", ")", ";", "$", "field", "=", "false", ";", "if", "(", "\\", "preg_match", "(", "'|^(.*?)[/.](.*)$|'", ",", "$", "fieldName", ",", "$", "matches", ")", ")", "{", "$", "pageName", "=", "$", "matches", "[", "1", "]", ";", "$", "fieldName", "=", "$", "matches", "[", "2", "]", ";", "}", "else", "{", "$", "pageName", "=", "$", "this", "->", "status", "[", "'currentPageName'", "]", ";", "}", "if", "(", "$", "pageName", "==", "$", "this", "->", "status", "[", "'currentPageName'", "]", "&&", "isset", "(", "$", "this", "->", "currentFields", "[", "$", "fieldName", "]", ")", ")", "{", "$", "field", "=", "&", "$", "this", "->", "currentFields", "[", "$", "fieldName", "]", ";", "if", "(", "!", "\\", "is_object", "(", "$", "field", ")", ")", "{", "$", "field", "[", "'pageI'", "]", "=", "$", "this", "->", "persist", "->", "get", "(", "'i'", ")", ";", "$", "this", "->", "currentFields", "[", "$", "fieldName", "]", "=", "$", "this", "->", "buildField", "(", "$", "field", ",", "$", "fieldName", ")", ";", "}", "}", "elseif", "(", "isset", "(", "$", "this", "->", "cfg", "[", "'pages'", "]", "[", "$", "pageName", "]", ")", ")", "{", "$", "pages", "=", "$", "this", "->", "persist", "->", "get", "(", "'pages'", ")", ";", "foreach", "(", "$", "pages", "as", "$", "pageI", "=>", "$", "page", ")", "{", "if", "(", "$", "page", "[", "'name'", "]", "!=", "$", "pageName", ")", "{", "continue", ";", "}", "foreach", "(", "$", "this", "->", "cfg", "[", "'pages'", "]", "[", "$", "pageName", "]", "as", "$", "k", "=>", "$", "fieldProps", ")", "{", "if", "(", "$", "k", "===", "$", "fieldName", "||", "isset", "(", "$", "fieldProps", "[", "'attribs'", "]", "[", "'name'", "]", ")", "&&", "$", "fieldProps", "[", "'attribs'", "]", "[", "'name'", "]", "==", "$", "fieldName", "||", "isset", "(", "$", "fieldProps", "[", "'name'", "]", ")", "&&", "$", "fieldProps", "[", "'name'", "]", "==", "$", "fieldName", ")", "{", "$", "this", "->", "debug", "->", "info", "(", "'found field'", ")", ";", "$", "fieldProps", "[", "'pageI'", "]", "=", "$", "pageI", ";", "$", "field", "=", "$", "this", "->", "buildField", "(", "$", "fieldProps", ",", "$", "k", ")", ";", "$", "val", "=", "$", "this", "->", "getValue", "(", "$", "fieldName", ",", "$", "pageI", ")", ";", "$", "field", "->", "val", "(", "$", "val", ",", "false", ")", ";", "break", "2", ";", "}", "}", "break", ";", "}", "}", "$", "this", "->", "debug", "->", "groupEnd", "(", ")", ";", "return", "$", "field", ";", "}" ]
Get form field @param string $fieldName field's name @return Field
[ "Get", "form", "field" ]
6aa5704b20300e1c8bd1c187a4fa88db9d442cee
https://github.com/bkdotcom/Form/blob/6aa5704b20300e1c8bd1c187a4fa88db9d442cee/src/Form.php#L164-L204
3,153
bkdotcom/Form
src/Form.php
Form.getInvalidFields
public function getInvalidFields() { $invalidFields = array(); foreach ($this->currentFields as $field) { if (!$field->isValid) { $invalidFields[] = $field; } } return $invalidFields; }
php
public function getInvalidFields() { $invalidFields = array(); foreach ($this->currentFields as $field) { if (!$field->isValid) { $invalidFields[] = $field; } } return $invalidFields; }
[ "public", "function", "getInvalidFields", "(", ")", "{", "$", "invalidFields", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "currentFields", "as", "$", "field", ")", "{", "if", "(", "!", "$", "field", "->", "isValid", ")", "{", "$", "invalidFields", "[", "]", "=", "$", "field", ";", "}", "}", "return", "$", "invalidFields", ";", "}" ]
Get list of invalid fields @return Field[]
[ "Get", "list", "of", "invalid", "fields" ]
6aa5704b20300e1c8bd1c187a4fa88db9d442cee
https://github.com/bkdotcom/Form/blob/6aa5704b20300e1c8bd1c187a4fa88db9d442cee/src/Form.php#L211-L220
3,154
bkdotcom/Form
src/Form.php
Form.setCurrentFields
public function setCurrentFields($i = null) { $this->debug->groupCollapsed(__METHOD__, $i); $this->debug->groupUncollapse(); $cfg = &$this->cfg; $status = &$this->status; if (isset($i)) { $this->status['submitted'] = false; $this->persist->set('i', $i); } $this->resetStatus(); // $this->debug->warn('currentPageName', $status['currentPageName']); // $this->debug->log('persist', $this->persist); // $this->debug->info('status', $status); // $this->debug->log('cfg', $cfg); $this->currentFields = isset($cfg['pages'][ $status['currentPageName'] ]) ? $cfg['pages'][ $status['currentPageName'] ] : array(); $this->debug->log('count(currentFields)', \count($this->currentFields)); $this->currentValues = $this->persist->get('currentPage.values'); // $this->debug->warn('currentValues', $this->currentValues); if (!empty($cfg['pre']) && \is_callable($cfg['pre'])) { $return = \call_user_func($cfg['pre'], $this); if ($return === false) { $status['error'] = 'pre error'; } } $this->buildFields(); $this->debug->groupEnd(); return; }
php
public function setCurrentFields($i = null) { $this->debug->groupCollapsed(__METHOD__, $i); $this->debug->groupUncollapse(); $cfg = &$this->cfg; $status = &$this->status; if (isset($i)) { $this->status['submitted'] = false; $this->persist->set('i', $i); } $this->resetStatus(); // $this->debug->warn('currentPageName', $status['currentPageName']); // $this->debug->log('persist', $this->persist); // $this->debug->info('status', $status); // $this->debug->log('cfg', $cfg); $this->currentFields = isset($cfg['pages'][ $status['currentPageName'] ]) ? $cfg['pages'][ $status['currentPageName'] ] : array(); $this->debug->log('count(currentFields)', \count($this->currentFields)); $this->currentValues = $this->persist->get('currentPage.values'); // $this->debug->warn('currentValues', $this->currentValues); if (!empty($cfg['pre']) && \is_callable($cfg['pre'])) { $return = \call_user_func($cfg['pre'], $this); if ($return === false) { $status['error'] = 'pre error'; } } $this->buildFields(); $this->debug->groupEnd(); return; }
[ "public", "function", "setCurrentFields", "(", "$", "i", "=", "null", ")", "{", "$", "this", "->", "debug", "->", "groupCollapsed", "(", "__METHOD__", ",", "$", "i", ")", ";", "$", "this", "->", "debug", "->", "groupUncollapse", "(", ")", ";", "$", "cfg", "=", "&", "$", "this", "->", "cfg", ";", "$", "status", "=", "&", "$", "this", "->", "status", ";", "if", "(", "isset", "(", "$", "i", ")", ")", "{", "$", "this", "->", "status", "[", "'submitted'", "]", "=", "false", ";", "$", "this", "->", "persist", "->", "set", "(", "'i'", ",", "$", "i", ")", ";", "}", "$", "this", "->", "resetStatus", "(", ")", ";", "// $this->debug->warn('currentPageName', $status['currentPageName']);", "// $this->debug->log('persist', $this->persist);", "// $this->debug->info('status', $status);", "// $this->debug->log('cfg', $cfg);", "$", "this", "->", "currentFields", "=", "isset", "(", "$", "cfg", "[", "'pages'", "]", "[", "$", "status", "[", "'currentPageName'", "]", "]", ")", "?", "$", "cfg", "[", "'pages'", "]", "[", "$", "status", "[", "'currentPageName'", "]", "]", ":", "array", "(", ")", ";", "$", "this", "->", "debug", "->", "log", "(", "'count(currentFields)'", ",", "\\", "count", "(", "$", "this", "->", "currentFields", ")", ")", ";", "$", "this", "->", "currentValues", "=", "$", "this", "->", "persist", "->", "get", "(", "'currentPage.values'", ")", ";", "// $this->debug->warn('currentValues', $this->currentValues);", "if", "(", "!", "empty", "(", "$", "cfg", "[", "'pre'", "]", ")", "&&", "\\", "is_callable", "(", "$", "cfg", "[", "'pre'", "]", ")", ")", "{", "$", "return", "=", "\\", "call_user_func", "(", "$", "cfg", "[", "'pre'", "]", ",", "$", "this", ")", ";", "if", "(", "$", "return", "===", "false", ")", "{", "$", "status", "[", "'error'", "]", "=", "'pre error'", ";", "}", "}", "$", "this", "->", "buildFields", "(", ")", ";", "$", "this", "->", "debug", "->", "groupEnd", "(", ")", ";", "return", ";", "}" ]
Set current "page" @param integer $i index of forms/fields to use @return void
[ "Set", "current", "page" ]
6aa5704b20300e1c8bd1c187a4fa88db9d442cee
https://github.com/bkdotcom/Form/blob/6aa5704b20300e1c8bd1c187a4fa88db9d442cee/src/Form.php#L314-L344
3,155
bkdotcom/Form
src/Form.php
Form.buildField
protected function buildField($fieldProps, $nameDefault = null) { $this->debug->group(__METHOD__, $nameDefault); if (!isset($fieldProps['attribs']['name']) && !isset($fieldProps['name'])) { $fieldProps['attribs']['name'] = $nameDefault; } if (!empty($fieldProps['newPage'])) { $fieldProps['attribs']['type'] = 'newPage'; $fieldProps['attribs']['value'] = $fieldProps['newPage']; unset($fieldProps['newPage']); } $field = $this->fieldFactory->build($fieldProps); if ($this->status['submitted'] && $field->attribs['type'] != 'newPage') { $pageI = $this->persist->get('i'); $value = $this->persist->get('pages/'.$pageI.'/values/'.$field->attribs['name']); $field->val($value, false); } $this->debug->groupEnd(); return $field; }
php
protected function buildField($fieldProps, $nameDefault = null) { $this->debug->group(__METHOD__, $nameDefault); if (!isset($fieldProps['attribs']['name']) && !isset($fieldProps['name'])) { $fieldProps['attribs']['name'] = $nameDefault; } if (!empty($fieldProps['newPage'])) { $fieldProps['attribs']['type'] = 'newPage'; $fieldProps['attribs']['value'] = $fieldProps['newPage']; unset($fieldProps['newPage']); } $field = $this->fieldFactory->build($fieldProps); if ($this->status['submitted'] && $field->attribs['type'] != 'newPage') { $pageI = $this->persist->get('i'); $value = $this->persist->get('pages/'.$pageI.'/values/'.$field->attribs['name']); $field->val($value, false); } $this->debug->groupEnd(); return $field; }
[ "protected", "function", "buildField", "(", "$", "fieldProps", ",", "$", "nameDefault", "=", "null", ")", "{", "$", "this", "->", "debug", "->", "group", "(", "__METHOD__", ",", "$", "nameDefault", ")", ";", "if", "(", "!", "isset", "(", "$", "fieldProps", "[", "'attribs'", "]", "[", "'name'", "]", ")", "&&", "!", "isset", "(", "$", "fieldProps", "[", "'name'", "]", ")", ")", "{", "$", "fieldProps", "[", "'attribs'", "]", "[", "'name'", "]", "=", "$", "nameDefault", ";", "}", "if", "(", "!", "empty", "(", "$", "fieldProps", "[", "'newPage'", "]", ")", ")", "{", "$", "fieldProps", "[", "'attribs'", "]", "[", "'type'", "]", "=", "'newPage'", ";", "$", "fieldProps", "[", "'attribs'", "]", "[", "'value'", "]", "=", "$", "fieldProps", "[", "'newPage'", "]", ";", "unset", "(", "$", "fieldProps", "[", "'newPage'", "]", ")", ";", "}", "$", "field", "=", "$", "this", "->", "fieldFactory", "->", "build", "(", "$", "fieldProps", ")", ";", "if", "(", "$", "this", "->", "status", "[", "'submitted'", "]", "&&", "$", "field", "->", "attribs", "[", "'type'", "]", "!=", "'newPage'", ")", "{", "$", "pageI", "=", "$", "this", "->", "persist", "->", "get", "(", "'i'", ")", ";", "$", "value", "=", "$", "this", "->", "persist", "->", "get", "(", "'pages/'", ".", "$", "pageI", ".", "'/values/'", ".", "$", "field", "->", "attribs", "[", "'name'", "]", ")", ";", "$", "field", "->", "val", "(", "$", "value", ",", "false", ")", ";", "}", "$", "this", "->", "debug", "->", "groupEnd", "(", ")", ";", "return", "$", "field", ";", "}" ]
Build field object @param array $fieldProps field properties @param string $nameDefault default name @return object
[ "Build", "field", "object" ]
6aa5704b20300e1c8bd1c187a4fa88db9d442cee
https://github.com/bkdotcom/Form/blob/6aa5704b20300e1c8bd1c187a4fa88db9d442cee/src/Form.php#L428-L447
3,156
bkdotcom/Form
src/Form.php
Form.buildFields
protected function buildFields() { $this->debug->groupCollapsed(__METHOD__); $status = &$this->status; $persist = $this->persist; $pageI = $this->persist->get('i'); $submitFieldCount = 0; $keys = \array_keys($this->currentFields); foreach ($keys as $k) { $field = $this->currentFields[$k]; unset($this->currentFields[$k]); if (!\is_object($field)) { $field = $this->buildField($field, $k); } $field->pageI = $pageI; if ($field->attribs['type'] == 'newPage') { $this->debug->info('possible new page', $field->attribs['value']); if ($field->isRequired()) { $this->debug->log('adding new page', $field->attribs['value']); $status['additionalPages'][] = $field; } continue; } elseif ($field->attribs['type'] == 'submit') { $submitFieldCount++; } elseif ($field->attribs['type'] == 'file') { $status['multipart'] = true; } $k = \is_int($k) ? $field->attribs['name'] : $k; $this->currentFields[$k] = $field; } if ($submitFieldCount < 1) { $this->debug->info('submit field not set'); $fieldArray = array( 'type' => 'submit', 'label' => ( !empty($status['additionalPages']) || $persist->pageCount() > $persist->pageCount(true)+1 ) ? 'Continue' : 'Submit', 'attribs' => array('class' => array('btn btn-primary', 'replace')), 'tagOnly' => true, ); $this->currentFields['submit'] = $this->fieldFactory->build($fieldArray); $this->debug->log('array_keys(currentFields)', \array_keys($this->currentFields)); } if ($status['multipart']) { $this->debug->log('<a target="_blank" href="http://www.php.net/manual/en/ini.php">post_max_size</a> = '.Str::getBytes(\ini_get('post_max_size'))); $this->debug->log('<a target="_blank" href="http://www.php.net/manual/en/ini.php">upload_max_filesize</a> = '.Str::getBytes(\ini_get('upload_max_filesize'))); } $this->debug->groupEnd(); }
php
protected function buildFields() { $this->debug->groupCollapsed(__METHOD__); $status = &$this->status; $persist = $this->persist; $pageI = $this->persist->get('i'); $submitFieldCount = 0; $keys = \array_keys($this->currentFields); foreach ($keys as $k) { $field = $this->currentFields[$k]; unset($this->currentFields[$k]); if (!\is_object($field)) { $field = $this->buildField($field, $k); } $field->pageI = $pageI; if ($field->attribs['type'] == 'newPage') { $this->debug->info('possible new page', $field->attribs['value']); if ($field->isRequired()) { $this->debug->log('adding new page', $field->attribs['value']); $status['additionalPages'][] = $field; } continue; } elseif ($field->attribs['type'] == 'submit') { $submitFieldCount++; } elseif ($field->attribs['type'] == 'file') { $status['multipart'] = true; } $k = \is_int($k) ? $field->attribs['name'] : $k; $this->currentFields[$k] = $field; } if ($submitFieldCount < 1) { $this->debug->info('submit field not set'); $fieldArray = array( 'type' => 'submit', 'label' => ( !empty($status['additionalPages']) || $persist->pageCount() > $persist->pageCount(true)+1 ) ? 'Continue' : 'Submit', 'attribs' => array('class' => array('btn btn-primary', 'replace')), 'tagOnly' => true, ); $this->currentFields['submit'] = $this->fieldFactory->build($fieldArray); $this->debug->log('array_keys(currentFields)', \array_keys($this->currentFields)); } if ($status['multipart']) { $this->debug->log('<a target="_blank" href="http://www.php.net/manual/en/ini.php">post_max_size</a> = '.Str::getBytes(\ini_get('post_max_size'))); $this->debug->log('<a target="_blank" href="http://www.php.net/manual/en/ini.php">upload_max_filesize</a> = '.Str::getBytes(\ini_get('upload_max_filesize'))); } $this->debug->groupEnd(); }
[ "protected", "function", "buildFields", "(", ")", "{", "$", "this", "->", "debug", "->", "groupCollapsed", "(", "__METHOD__", ")", ";", "$", "status", "=", "&", "$", "this", "->", "status", ";", "$", "persist", "=", "$", "this", "->", "persist", ";", "$", "pageI", "=", "$", "this", "->", "persist", "->", "get", "(", "'i'", ")", ";", "$", "submitFieldCount", "=", "0", ";", "$", "keys", "=", "\\", "array_keys", "(", "$", "this", "->", "currentFields", ")", ";", "foreach", "(", "$", "keys", "as", "$", "k", ")", "{", "$", "field", "=", "$", "this", "->", "currentFields", "[", "$", "k", "]", ";", "unset", "(", "$", "this", "->", "currentFields", "[", "$", "k", "]", ")", ";", "if", "(", "!", "\\", "is_object", "(", "$", "field", ")", ")", "{", "$", "field", "=", "$", "this", "->", "buildField", "(", "$", "field", ",", "$", "k", ")", ";", "}", "$", "field", "->", "pageI", "=", "$", "pageI", ";", "if", "(", "$", "field", "->", "attribs", "[", "'type'", "]", "==", "'newPage'", ")", "{", "$", "this", "->", "debug", "->", "info", "(", "'possible new page'", ",", "$", "field", "->", "attribs", "[", "'value'", "]", ")", ";", "if", "(", "$", "field", "->", "isRequired", "(", ")", ")", "{", "$", "this", "->", "debug", "->", "log", "(", "'adding new page'", ",", "$", "field", "->", "attribs", "[", "'value'", "]", ")", ";", "$", "status", "[", "'additionalPages'", "]", "[", "]", "=", "$", "field", ";", "}", "continue", ";", "}", "elseif", "(", "$", "field", "->", "attribs", "[", "'type'", "]", "==", "'submit'", ")", "{", "$", "submitFieldCount", "++", ";", "}", "elseif", "(", "$", "field", "->", "attribs", "[", "'type'", "]", "==", "'file'", ")", "{", "$", "status", "[", "'multipart'", "]", "=", "true", ";", "}", "$", "k", "=", "\\", "is_int", "(", "$", "k", ")", "?", "$", "field", "->", "attribs", "[", "'name'", "]", ":", "$", "k", ";", "$", "this", "->", "currentFields", "[", "$", "k", "]", "=", "$", "field", ";", "}", "if", "(", "$", "submitFieldCount", "<", "1", ")", "{", "$", "this", "->", "debug", "->", "info", "(", "'submit field not set'", ")", ";", "$", "fieldArray", "=", "array", "(", "'type'", "=>", "'submit'", ",", "'label'", "=>", "(", "!", "empty", "(", "$", "status", "[", "'additionalPages'", "]", ")", "||", "$", "persist", "->", "pageCount", "(", ")", ">", "$", "persist", "->", "pageCount", "(", "true", ")", "+", "1", ")", "?", "'Continue'", ":", "'Submit'", ",", "'attribs'", "=>", "array", "(", "'class'", "=>", "array", "(", "'btn btn-primary'", ",", "'replace'", ")", ")", ",", "'tagOnly'", "=>", "true", ",", ")", ";", "$", "this", "->", "currentFields", "[", "'submit'", "]", "=", "$", "this", "->", "fieldFactory", "->", "build", "(", "$", "fieldArray", ")", ";", "$", "this", "->", "debug", "->", "log", "(", "'array_keys(currentFields)'", ",", "\\", "array_keys", "(", "$", "this", "->", "currentFields", ")", ")", ";", "}", "if", "(", "$", "status", "[", "'multipart'", "]", ")", "{", "$", "this", "->", "debug", "->", "log", "(", "'<a target=\"_blank\" href=\"http://www.php.net/manual/en/ini.php\">post_max_size</a> = '", ".", "Str", "::", "getBytes", "(", "\\", "ini_get", "(", "'post_max_size'", ")", ")", ")", ";", "$", "this", "->", "debug", "->", "log", "(", "'<a target=\"_blank\" href=\"http://www.php.net/manual/en/ini.php\">upload_max_filesize</a> = '", ".", "Str", "::", "getBytes", "(", "\\", "ini_get", "(", "'upload_max_filesize'", ")", ")", ")", ";", "}", "$", "this", "->", "debug", "->", "groupEnd", "(", ")", ";", "}" ]
Build current fields @return void
[ "Build", "current", "fields" ]
6aa5704b20300e1c8bd1c187a4fa88db9d442cee
https://github.com/bkdotcom/Form/blob/6aa5704b20300e1c8bd1c187a4fa88db9d442cee/src/Form.php#L454-L504
3,157
bkdotcom/Form
src/Form.php
Form.initPersist
private function initPersist() { $this->debug->groupCollapsed(__METHOD__); $this->persist = new Persist($this->cfg['name'], array( 'persist' => $this->cfg['persist'], 'trashCollectable' => $this->cfg['trashCollectable'], 'userKey' => $this->cfg['verifyKey'] ? ( isset($_REQUEST['_key_']) ? $_REQUEST['_key_'] : null ) : false, )); if (!$this->persist->pageCount()) { $this->debug->info('persist just created... add first page'); $firstPageName = \key($this->cfg['pages']); $this->persist->appendPages(array($firstPageName)); } $this->debug->groupEnd(); }
php
private function initPersist() { $this->debug->groupCollapsed(__METHOD__); $this->persist = new Persist($this->cfg['name'], array( 'persist' => $this->cfg['persist'], 'trashCollectable' => $this->cfg['trashCollectable'], 'userKey' => $this->cfg['verifyKey'] ? ( isset($_REQUEST['_key_']) ? $_REQUEST['_key_'] : null ) : false, )); if (!$this->persist->pageCount()) { $this->debug->info('persist just created... add first page'); $firstPageName = \key($this->cfg['pages']); $this->persist->appendPages(array($firstPageName)); } $this->debug->groupEnd(); }
[ "private", "function", "initPersist", "(", ")", "{", "$", "this", "->", "debug", "->", "groupCollapsed", "(", "__METHOD__", ")", ";", "$", "this", "->", "persist", "=", "new", "Persist", "(", "$", "this", "->", "cfg", "[", "'name'", "]", ",", "array", "(", "'persist'", "=>", "$", "this", "->", "cfg", "[", "'persist'", "]", ",", "'trashCollectable'", "=>", "$", "this", "->", "cfg", "[", "'trashCollectable'", "]", ",", "'userKey'", "=>", "$", "this", "->", "cfg", "[", "'verifyKey'", "]", "?", "(", "isset", "(", "$", "_REQUEST", "[", "'_key_'", "]", ")", "?", "$", "_REQUEST", "[", "'_key_'", "]", ":", "null", ")", ":", "false", ",", ")", ")", ";", "if", "(", "!", "$", "this", "->", "persist", "->", "pageCount", "(", ")", ")", "{", "$", "this", "->", "debug", "->", "info", "(", "'persist just created... add first page'", ")", ";", "$", "firstPageName", "=", "\\", "key", "(", "$", "this", "->", "cfg", "[", "'pages'", "]", ")", ";", "$", "this", "->", "persist", "->", "appendPages", "(", "array", "(", "$", "firstPageName", ")", ")", ";", "}", "$", "this", "->", "debug", "->", "groupEnd", "(", ")", ";", "}" ]
Initialize persist object @return void
[ "Initialize", "persist", "object" ]
6aa5704b20300e1c8bd1c187a4fa88db9d442cee
https://github.com/bkdotcom/Form/blob/6aa5704b20300e1c8bd1c187a4fa88db9d442cee/src/Form.php#L603-L619
3,158
bkdotcom/Form
src/Form.php
Form.pagesAddEnd
private function pagesAddEnd($pagesEnd = array()) { $this->debug->groupCollapsed(__METHOD__); $this->persist->appendPages($pagesEnd); $this->debug->groupEnd(); }
php
private function pagesAddEnd($pagesEnd = array()) { $this->debug->groupCollapsed(__METHOD__); $this->persist->appendPages($pagesEnd); $this->debug->groupEnd(); }
[ "private", "function", "pagesAddEnd", "(", "$", "pagesEnd", "=", "array", "(", ")", ")", "{", "$", "this", "->", "debug", "->", "groupCollapsed", "(", "__METHOD__", ")", ";", "$", "this", "->", "persist", "->", "appendPages", "(", "$", "pagesEnd", ")", ";", "$", "this", "->", "debug", "->", "groupEnd", "(", ")", ";", "}" ]
Add pages to end of form @param array $pagesEnd list of pagenames @return void
[ "Add", "pages", "to", "end", "of", "form" ]
6aa5704b20300e1c8bd1c187a4fa88db9d442cee
https://github.com/bkdotcom/Form/blob/6aa5704b20300e1c8bd1c187a4fa88db9d442cee/src/Form.php#L628-L633
3,159
bkdotcom/Form
src/Form.php
Form.pagesAddNext
private function pagesAddNext($pagesNext = array()) { $this->debug->groupCollapsed(__METHOD__); $pagesNext = \array_values($pagesNext); $pages = $this->persist->get('pages'); $iCur = $this->persist->get('i'); $currentPage = $pages[ $iCur ]; // offset is where we will insert pagesNext $offset = $iCur + \count($currentPage['addPages']) + 1; foreach ($pages as $k => $page) { foreach ($page['addPages'] as $k2 => $i) { if ($i >= $offset) { $pages[$k]['addPages'][$k2] += \count($pagesNext); } } } foreach ($pagesNext as $i => $pageName) { $pages[$k]['addPages'][] = $offset + $i; \array_splice($pages, $offset + $i, 0, array( array( 'name' => $pageName, 'completed' => false, 'values' => array(), 'addPages' => array(), ) )); } $this->persist->set('pages', $pages); $this->debug->groupEnd(); }
php
private function pagesAddNext($pagesNext = array()) { $this->debug->groupCollapsed(__METHOD__); $pagesNext = \array_values($pagesNext); $pages = $this->persist->get('pages'); $iCur = $this->persist->get('i'); $currentPage = $pages[ $iCur ]; // offset is where we will insert pagesNext $offset = $iCur + \count($currentPage['addPages']) + 1; foreach ($pages as $k => $page) { foreach ($page['addPages'] as $k2 => $i) { if ($i >= $offset) { $pages[$k]['addPages'][$k2] += \count($pagesNext); } } } foreach ($pagesNext as $i => $pageName) { $pages[$k]['addPages'][] = $offset + $i; \array_splice($pages, $offset + $i, 0, array( array( 'name' => $pageName, 'completed' => false, 'values' => array(), 'addPages' => array(), ) )); } $this->persist->set('pages', $pages); $this->debug->groupEnd(); }
[ "private", "function", "pagesAddNext", "(", "$", "pagesNext", "=", "array", "(", ")", ")", "{", "$", "this", "->", "debug", "->", "groupCollapsed", "(", "__METHOD__", ")", ";", "$", "pagesNext", "=", "\\", "array_values", "(", "$", "pagesNext", ")", ";", "$", "pages", "=", "$", "this", "->", "persist", "->", "get", "(", "'pages'", ")", ";", "$", "iCur", "=", "$", "this", "->", "persist", "->", "get", "(", "'i'", ")", ";", "$", "currentPage", "=", "$", "pages", "[", "$", "iCur", "]", ";", "// offset is where we will insert pagesNext", "$", "offset", "=", "$", "iCur", "+", "\\", "count", "(", "$", "currentPage", "[", "'addPages'", "]", ")", "+", "1", ";", "foreach", "(", "$", "pages", "as", "$", "k", "=>", "$", "page", ")", "{", "foreach", "(", "$", "page", "[", "'addPages'", "]", "as", "$", "k2", "=>", "$", "i", ")", "{", "if", "(", "$", "i", ">=", "$", "offset", ")", "{", "$", "pages", "[", "$", "k", "]", "[", "'addPages'", "]", "[", "$", "k2", "]", "+=", "\\", "count", "(", "$", "pagesNext", ")", ";", "}", "}", "}", "foreach", "(", "$", "pagesNext", "as", "$", "i", "=>", "$", "pageName", ")", "{", "$", "pages", "[", "$", "k", "]", "[", "'addPages'", "]", "[", "]", "=", "$", "offset", "+", "$", "i", ";", "\\", "array_splice", "(", "$", "pages", ",", "$", "offset", "+", "$", "i", ",", "0", ",", "array", "(", "array", "(", "'name'", "=>", "$", "pageName", ",", "'completed'", "=>", "false", ",", "'values'", "=>", "array", "(", ")", ",", "'addPages'", "=>", "array", "(", ")", ",", ")", ")", ")", ";", "}", "$", "this", "->", "persist", "->", "set", "(", "'pages'", ",", "$", "pages", ")", ";", "$", "this", "->", "debug", "->", "groupEnd", "(", ")", ";", "}" ]
Add pages to be seen immediately after current page @param array $pagesNext list of page names @return void
[ "Add", "pages", "to", "be", "seen", "immediately", "after", "current", "page" ]
6aa5704b20300e1c8bd1c187a4fa88db9d442cee
https://github.com/bkdotcom/Form/blob/6aa5704b20300e1c8bd1c187a4fa88db9d442cee/src/Form.php#L642-L671
3,160
bkdotcom/Form
src/Form.php
Form.processSubmit
private function processSubmit() { $this->debug->group(__METHOD__); $this->debug->groupUncollapse(); $cfg = &$this->cfg; $status = &$this->status; if ($status['submitted']) { $this->validate(); if (\is_callable($cfg['post'])) { $return = \call_user_func($cfg['post'], $this); if ($return === false) { $status['error'] = true; } // $this->updateInvalid(); } if ($status['error']) { // $this->debug->log('status[error]', $status['error']); $this->alerts->add($cfg['messages']['errorAlert']); } elseif ($invalidFields = $this->getInvalidFields()) { // $this->debug->log('invalidFields', $invalidFields); $alert = $cfg['messages']['invalidAlert']; foreach ($invalidFields as $field) { if (!\strlen($field->attribs['value'])) { $alert = $cfg['messages']['unansweredAlert']; break; } } $this->alerts->add($alert); } else { $this->debug->info('completed ', $status['currentPageName']); $this->persist->set('currentPage.completed', true); $this->addRemovePages(); if ($this->persist->pageCount(true) == $this->persist->pageCount()) { $this->debug->info('completed all pages'); $status['completed'] = true; $complete = new Complete($this); $return = $complete->complete(); if ($return === false) { $status['error'] = true; } elseif (\is_string($return)) { $cfg['messages']['completed'] = $return; } if ($status['error']) { $this->alerts->add($this->cfg['messages']['errorAlert']); } else { $this->alerts->add($this->cfg['messages']['completedAlert']); } if ($this->status['completed'] && $cfg['trashOnComplete']) { $this->debug->warn('shutting this whole thing down'); $this->persist->remove(); } } else { $this->debug->info('more pages to go'); $nextI = $this->persist->get('nextI'); $this->setCurrentFields($nextI); } } } $this->debug->groupEnd(); }
php
private function processSubmit() { $this->debug->group(__METHOD__); $this->debug->groupUncollapse(); $cfg = &$this->cfg; $status = &$this->status; if ($status['submitted']) { $this->validate(); if (\is_callable($cfg['post'])) { $return = \call_user_func($cfg['post'], $this); if ($return === false) { $status['error'] = true; } // $this->updateInvalid(); } if ($status['error']) { // $this->debug->log('status[error]', $status['error']); $this->alerts->add($cfg['messages']['errorAlert']); } elseif ($invalidFields = $this->getInvalidFields()) { // $this->debug->log('invalidFields', $invalidFields); $alert = $cfg['messages']['invalidAlert']; foreach ($invalidFields as $field) { if (!\strlen($field->attribs['value'])) { $alert = $cfg['messages']['unansweredAlert']; break; } } $this->alerts->add($alert); } else { $this->debug->info('completed ', $status['currentPageName']); $this->persist->set('currentPage.completed', true); $this->addRemovePages(); if ($this->persist->pageCount(true) == $this->persist->pageCount()) { $this->debug->info('completed all pages'); $status['completed'] = true; $complete = new Complete($this); $return = $complete->complete(); if ($return === false) { $status['error'] = true; } elseif (\is_string($return)) { $cfg['messages']['completed'] = $return; } if ($status['error']) { $this->alerts->add($this->cfg['messages']['errorAlert']); } else { $this->alerts->add($this->cfg['messages']['completedAlert']); } if ($this->status['completed'] && $cfg['trashOnComplete']) { $this->debug->warn('shutting this whole thing down'); $this->persist->remove(); } } else { $this->debug->info('more pages to go'); $nextI = $this->persist->get('nextI'); $this->setCurrentFields($nextI); } } } $this->debug->groupEnd(); }
[ "private", "function", "processSubmit", "(", ")", "{", "$", "this", "->", "debug", "->", "group", "(", "__METHOD__", ")", ";", "$", "this", "->", "debug", "->", "groupUncollapse", "(", ")", ";", "$", "cfg", "=", "&", "$", "this", "->", "cfg", ";", "$", "status", "=", "&", "$", "this", "->", "status", ";", "if", "(", "$", "status", "[", "'submitted'", "]", ")", "{", "$", "this", "->", "validate", "(", ")", ";", "if", "(", "\\", "is_callable", "(", "$", "cfg", "[", "'post'", "]", ")", ")", "{", "$", "return", "=", "\\", "call_user_func", "(", "$", "cfg", "[", "'post'", "]", ",", "$", "this", ")", ";", "if", "(", "$", "return", "===", "false", ")", "{", "$", "status", "[", "'error'", "]", "=", "true", ";", "}", "// $this->updateInvalid();", "}", "if", "(", "$", "status", "[", "'error'", "]", ")", "{", "// $this->debug->log('status[error]', $status['error']);", "$", "this", "->", "alerts", "->", "add", "(", "$", "cfg", "[", "'messages'", "]", "[", "'errorAlert'", "]", ")", ";", "}", "elseif", "(", "$", "invalidFields", "=", "$", "this", "->", "getInvalidFields", "(", ")", ")", "{", "// $this->debug->log('invalidFields', $invalidFields);", "$", "alert", "=", "$", "cfg", "[", "'messages'", "]", "[", "'invalidAlert'", "]", ";", "foreach", "(", "$", "invalidFields", "as", "$", "field", ")", "{", "if", "(", "!", "\\", "strlen", "(", "$", "field", "->", "attribs", "[", "'value'", "]", ")", ")", "{", "$", "alert", "=", "$", "cfg", "[", "'messages'", "]", "[", "'unansweredAlert'", "]", ";", "break", ";", "}", "}", "$", "this", "->", "alerts", "->", "add", "(", "$", "alert", ")", ";", "}", "else", "{", "$", "this", "->", "debug", "->", "info", "(", "'completed '", ",", "$", "status", "[", "'currentPageName'", "]", ")", ";", "$", "this", "->", "persist", "->", "set", "(", "'currentPage.completed'", ",", "true", ")", ";", "$", "this", "->", "addRemovePages", "(", ")", ";", "if", "(", "$", "this", "->", "persist", "->", "pageCount", "(", "true", ")", "==", "$", "this", "->", "persist", "->", "pageCount", "(", ")", ")", "{", "$", "this", "->", "debug", "->", "info", "(", "'completed all pages'", ")", ";", "$", "status", "[", "'completed'", "]", "=", "true", ";", "$", "complete", "=", "new", "Complete", "(", "$", "this", ")", ";", "$", "return", "=", "$", "complete", "->", "complete", "(", ")", ";", "if", "(", "$", "return", "===", "false", ")", "{", "$", "status", "[", "'error'", "]", "=", "true", ";", "}", "elseif", "(", "\\", "is_string", "(", "$", "return", ")", ")", "{", "$", "cfg", "[", "'messages'", "]", "[", "'completed'", "]", "=", "$", "return", ";", "}", "if", "(", "$", "status", "[", "'error'", "]", ")", "{", "$", "this", "->", "alerts", "->", "add", "(", "$", "this", "->", "cfg", "[", "'messages'", "]", "[", "'errorAlert'", "]", ")", ";", "}", "else", "{", "$", "this", "->", "alerts", "->", "add", "(", "$", "this", "->", "cfg", "[", "'messages'", "]", "[", "'completedAlert'", "]", ")", ";", "}", "if", "(", "$", "this", "->", "status", "[", "'completed'", "]", "&&", "$", "cfg", "[", "'trashOnComplete'", "]", ")", "{", "$", "this", "->", "debug", "->", "warn", "(", "'shutting this whole thing down'", ")", ";", "$", "this", "->", "persist", "->", "remove", "(", ")", ";", "}", "}", "else", "{", "$", "this", "->", "debug", "->", "info", "(", "'more pages to go'", ")", ";", "$", "nextI", "=", "$", "this", "->", "persist", "->", "get", "(", "'nextI'", ")", ";", "$", "this", "->", "setCurrentFields", "(", "$", "nextI", ")", ";", "}", "}", "}", "$", "this", "->", "debug", "->", "groupEnd", "(", ")", ";", "}" ]
Process submitted values @return void
[ "Process", "submitted", "values" ]
6aa5704b20300e1c8bd1c187a4fa88db9d442cee
https://github.com/bkdotcom/Form/blob/6aa5704b20300e1c8bd1c187a4fa88db9d442cee/src/Form.php#L725-L784
3,161
bkdotcom/Form
src/Form.php
Form.redirectPost
private function redirectPost() { if (!isset($_SERVER['REQUEST_URI'])) { return; } if (!isset($_SERVER['REQUEST_METHOD']) || $_SERVER['REQUEST_METHOD'] != 'POST') { return; } if (!$this->cfg['prg']) { return; } if (!$this->status['submitted']) { return; } $this->debug->log('redirecting'); $event = $this->eventManager->publish('page.redirect', null, array('location' => $_SERVER['REQUEST_URI'])); $location = $event['location']; $this->debug->log('%cLocation:%c <a href="%s">%s</a>', 'font-weight:bold;', '', $location, $location); if (\headers_sent($file, $line)) { $this->debug->warn('headers alrady sent from '.$file.' line '.$line); return; } if ($event->isPropagationStopped()) { $this->debug->alert('<i class="fa fa-external-link fa-lg" aria-hidden="true"></i> Location: <a class="alert-link" href="'.\htmlspecialchars($location).'">'.\htmlspecialchars($location).'</a>', 'info'); } else { \header('Location: '.$location); } throw new \Exception('exit'); }
php
private function redirectPost() { if (!isset($_SERVER['REQUEST_URI'])) { return; } if (!isset($_SERVER['REQUEST_METHOD']) || $_SERVER['REQUEST_METHOD'] != 'POST') { return; } if (!$this->cfg['prg']) { return; } if (!$this->status['submitted']) { return; } $this->debug->log('redirecting'); $event = $this->eventManager->publish('page.redirect', null, array('location' => $_SERVER['REQUEST_URI'])); $location = $event['location']; $this->debug->log('%cLocation:%c <a href="%s">%s</a>', 'font-weight:bold;', '', $location, $location); if (\headers_sent($file, $line)) { $this->debug->warn('headers alrady sent from '.$file.' line '.$line); return; } if ($event->isPropagationStopped()) { $this->debug->alert('<i class="fa fa-external-link fa-lg" aria-hidden="true"></i> Location: <a class="alert-link" href="'.\htmlspecialchars($location).'">'.\htmlspecialchars($location).'</a>', 'info'); } else { \header('Location: '.$location); } throw new \Exception('exit'); }
[ "private", "function", "redirectPost", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ")", ")", "{", "return", ";", "}", "if", "(", "!", "isset", "(", "$", "_SERVER", "[", "'REQUEST_METHOD'", "]", ")", "||", "$", "_SERVER", "[", "'REQUEST_METHOD'", "]", "!=", "'POST'", ")", "{", "return", ";", "}", "if", "(", "!", "$", "this", "->", "cfg", "[", "'prg'", "]", ")", "{", "return", ";", "}", "if", "(", "!", "$", "this", "->", "status", "[", "'submitted'", "]", ")", "{", "return", ";", "}", "$", "this", "->", "debug", "->", "log", "(", "'redirecting'", ")", ";", "$", "event", "=", "$", "this", "->", "eventManager", "->", "publish", "(", "'page.redirect'", ",", "null", ",", "array", "(", "'location'", "=>", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ")", ")", ";", "$", "location", "=", "$", "event", "[", "'location'", "]", ";", "$", "this", "->", "debug", "->", "log", "(", "'%cLocation:%c <a href=\"%s\">%s</a>'", ",", "'font-weight:bold;'", ",", "''", ",", "$", "location", ",", "$", "location", ")", ";", "if", "(", "\\", "headers_sent", "(", "$", "file", ",", "$", "line", ")", ")", "{", "$", "this", "->", "debug", "->", "warn", "(", "'headers alrady sent from '", ".", "$", "file", ".", "' line '", ".", "$", "line", ")", ";", "return", ";", "}", "if", "(", "$", "event", "->", "isPropagationStopped", "(", ")", ")", "{", "$", "this", "->", "debug", "->", "alert", "(", "'<i class=\"fa fa-external-link fa-lg\" aria-hidden=\"true\"></i> Location: <a class=\"alert-link\" href=\"'", ".", "\\", "htmlspecialchars", "(", "$", "location", ")", ".", "'\">'", ".", "\\", "htmlspecialchars", "(", "$", "location", ")", ".", "'</a>'", ",", "'info'", ")", ";", "}", "else", "{", "\\", "header", "(", "'Location: '", ".", "$", "location", ")", ";", "}", "throw", "new", "\\", "Exception", "(", "'exit'", ")", ";", "}" ]
Stores submitted values in persistence Redirects if submoitted via POST @return void @throws \Exception Rather than exit.
[ "Stores", "submitted", "values", "in", "persistence", "Redirects", "if", "submoitted", "via", "POST" ]
6aa5704b20300e1c8bd1c187a4fa88db9d442cee
https://github.com/bkdotcom/Form/blob/6aa5704b20300e1c8bd1c187a4fa88db9d442cee/src/Form.php#L793-L821
3,162
bkdotcom/Form
src/Form.php
Form.resetStatus
private function resetStatus() { $this->debug->info('resetStatus'); $this->status = \array_merge($this->status, array( 'currentPageName' => $this->persist->get('currentPage.name'), // 'keyVerified' => false, // don't reset // 'submitted' => false, // don't reset 'completed' => false, 'error' => false, 'postMaxExceeded' => false, 'multipart' => false, // multipart form (file fields)? 'additionalPages' => array(), // 'invalidFields' => array(), 'idCounts' => array(), )); }
php
private function resetStatus() { $this->debug->info('resetStatus'); $this->status = \array_merge($this->status, array( 'currentPageName' => $this->persist->get('currentPage.name'), // 'keyVerified' => false, // don't reset // 'submitted' => false, // don't reset 'completed' => false, 'error' => false, 'postMaxExceeded' => false, 'multipart' => false, // multipart form (file fields)? 'additionalPages' => array(), // 'invalidFields' => array(), 'idCounts' => array(), )); }
[ "private", "function", "resetStatus", "(", ")", "{", "$", "this", "->", "debug", "->", "info", "(", "'resetStatus'", ")", ";", "$", "this", "->", "status", "=", "\\", "array_merge", "(", "$", "this", "->", "status", ",", "array", "(", "'currentPageName'", "=>", "$", "this", "->", "persist", "->", "get", "(", "'currentPage.name'", ")", ",", "// 'keyVerified' => false, // don't reset", "// 'submitted' => false, // don't reset", "'completed'", "=>", "false", ",", "'error'", "=>", "false", ",", "'postMaxExceeded'", "=>", "false", ",", "'multipart'", "=>", "false", ",", "// multipart form (file fields)?", "'additionalPages'", "=>", "array", "(", ")", ",", "// 'invalidFields' => array(),", "'idCounts'", "=>", "array", "(", ")", ",", ")", ")", ";", "}" ]
Reset form status @return void
[ "Reset", "form", "status" ]
6aa5704b20300e1c8bd1c187a4fa88db9d442cee
https://github.com/bkdotcom/Form/blob/6aa5704b20300e1c8bd1c187a4fa88db9d442cee/src/Form.php#L828-L843
3,163
bkdotcom/Form
src/Form.php
Form.storeValues
private function storeValues() { $this->debug->groupCollapsed(__METHOD__); // if (!$this->status['keyVerified']) { if (!$this->status['submitted']) { // $this->debug->warn('not submitted'); $this->debug->groupEnd(); return; } if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') { $this->debug->warn('POST method'); if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH'] > Str::getBytes(\ini_get('post_max_size'), true)) { $this->debug->warn('post_max_size exceeded'); $this->alerts->add('Your upload has exceeded the '.Str::getBytes(\ini_get('post_max_size')).' limit'); $this->status['postMaxExceeded'] = true; } $values = $_POST; foreach ($_FILES as $k => $file) { if ($file['error'] === UPLOAD_ERR_NO_FILE) { continue; } if ($file['error'] === UPLOAD_ERR_OK) { // by calling move_uploaded_file, we prevent its automatic deletion \move_uploaded_file($file['tmp_name'], $file['tmp_name']); } $values[$k] = $file; /* errors: UPLOAD_ERR_OK => 'There is no error, the file uploaded with success', UPLOAD_ERR_INI_SIZE => 'The uploaded file exceeds the upload_max_filesize directive in php.ini ('.\ini_get('upload_max_filesize').')', UPLOAD_ERR_FORM_SIZE => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form', UPLOAD_ERR_PARTIAL => 'The uploaded file was only partially uploaded', UPLOAD_ERR_NO_FILE => 'No file was uploaded', UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder', UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk.', UPLOAD_ERR_EXTENSION => 'A PHP extension stopped the file upload.', */ } $this->status['submitted'] = true; $this->persist->set('submitted', true); $this->persist->set('currentPage.values', $values); } elseif (\strtolower($this->cfg['attribs']['method']) == 'get') { $this->debug->warn('storing GET vals'); $this->persist->set('currentPage.values', $_GET); } $this->debug->groupEnd(); }
php
private function storeValues() { $this->debug->groupCollapsed(__METHOD__); // if (!$this->status['keyVerified']) { if (!$this->status['submitted']) { // $this->debug->warn('not submitted'); $this->debug->groupEnd(); return; } if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') { $this->debug->warn('POST method'); if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH'] > Str::getBytes(\ini_get('post_max_size'), true)) { $this->debug->warn('post_max_size exceeded'); $this->alerts->add('Your upload has exceeded the '.Str::getBytes(\ini_get('post_max_size')).' limit'); $this->status['postMaxExceeded'] = true; } $values = $_POST; foreach ($_FILES as $k => $file) { if ($file['error'] === UPLOAD_ERR_NO_FILE) { continue; } if ($file['error'] === UPLOAD_ERR_OK) { // by calling move_uploaded_file, we prevent its automatic deletion \move_uploaded_file($file['tmp_name'], $file['tmp_name']); } $values[$k] = $file; /* errors: UPLOAD_ERR_OK => 'There is no error, the file uploaded with success', UPLOAD_ERR_INI_SIZE => 'The uploaded file exceeds the upload_max_filesize directive in php.ini ('.\ini_get('upload_max_filesize').')', UPLOAD_ERR_FORM_SIZE => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form', UPLOAD_ERR_PARTIAL => 'The uploaded file was only partially uploaded', UPLOAD_ERR_NO_FILE => 'No file was uploaded', UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder', UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk.', UPLOAD_ERR_EXTENSION => 'A PHP extension stopped the file upload.', */ } $this->status['submitted'] = true; $this->persist->set('submitted', true); $this->persist->set('currentPage.values', $values); } elseif (\strtolower($this->cfg['attribs']['method']) == 'get') { $this->debug->warn('storing GET vals'); $this->persist->set('currentPage.values', $_GET); } $this->debug->groupEnd(); }
[ "private", "function", "storeValues", "(", ")", "{", "$", "this", "->", "debug", "->", "groupCollapsed", "(", "__METHOD__", ")", ";", "// if (!$this->status['keyVerified']) {", "if", "(", "!", "$", "this", "->", "status", "[", "'submitted'", "]", ")", "{", "// $this->debug->warn('not submitted');", "$", "this", "->", "debug", "->", "groupEnd", "(", ")", ";", "return", ";", "}", "if", "(", "isset", "(", "$", "_SERVER", "[", "'REQUEST_METHOD'", "]", ")", "&&", "$", "_SERVER", "[", "'REQUEST_METHOD'", "]", "==", "'POST'", ")", "{", "$", "this", "->", "debug", "->", "warn", "(", "'POST method'", ")", ";", "if", "(", "isset", "(", "$", "_SERVER", "[", "'CONTENT_LENGTH'", "]", ")", "&&", "$", "_SERVER", "[", "'CONTENT_LENGTH'", "]", ">", "Str", "::", "getBytes", "(", "\\", "ini_get", "(", "'post_max_size'", ")", ",", "true", ")", ")", "{", "$", "this", "->", "debug", "->", "warn", "(", "'post_max_size exceeded'", ")", ";", "$", "this", "->", "alerts", "->", "add", "(", "'Your upload has exceeded the '", ".", "Str", "::", "getBytes", "(", "\\", "ini_get", "(", "'post_max_size'", ")", ")", ".", "' limit'", ")", ";", "$", "this", "->", "status", "[", "'postMaxExceeded'", "]", "=", "true", ";", "}", "$", "values", "=", "$", "_POST", ";", "foreach", "(", "$", "_FILES", "as", "$", "k", "=>", "$", "file", ")", "{", "if", "(", "$", "file", "[", "'error'", "]", "===", "UPLOAD_ERR_NO_FILE", ")", "{", "continue", ";", "}", "if", "(", "$", "file", "[", "'error'", "]", "===", "UPLOAD_ERR_OK", ")", "{", "// by calling move_uploaded_file, we prevent its automatic deletion", "\\", "move_uploaded_file", "(", "$", "file", "[", "'tmp_name'", "]", ",", "$", "file", "[", "'tmp_name'", "]", ")", ";", "}", "$", "values", "[", "$", "k", "]", "=", "$", "file", ";", "/*\n errors:\n UPLOAD_ERR_OK => 'There is no error, the file uploaded with success',\n UPLOAD_ERR_INI_SIZE => 'The uploaded file exceeds the upload_max_filesize directive in php.ini ('.\\ini_get('upload_max_filesize').')',\n UPLOAD_ERR_FORM_SIZE => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form',\n UPLOAD_ERR_PARTIAL => 'The uploaded file was only partially uploaded',\n UPLOAD_ERR_NO_FILE => 'No file was uploaded',\n UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder',\n UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk.',\n UPLOAD_ERR_EXTENSION => 'A PHP extension stopped the file upload.',\n */", "}", "$", "this", "->", "status", "[", "'submitted'", "]", "=", "true", ";", "$", "this", "->", "persist", "->", "set", "(", "'submitted'", ",", "true", ")", ";", "$", "this", "->", "persist", "->", "set", "(", "'currentPage.values'", ",", "$", "values", ")", ";", "}", "elseif", "(", "\\", "strtolower", "(", "$", "this", "->", "cfg", "[", "'attribs'", "]", "[", "'method'", "]", ")", "==", "'get'", ")", "{", "$", "this", "->", "debug", "->", "warn", "(", "'storing GET vals'", ")", ";", "$", "this", "->", "persist", "->", "set", "(", "'currentPage.values'", ",", "$", "_GET", ")", ";", "}", "$", "this", "->", "debug", "->", "groupEnd", "(", ")", ";", "}" ]
Copies request params to persist for storage @return void
[ "Copies", "request", "params", "to", "persist", "for", "storage" ]
6aa5704b20300e1c8bd1c187a4fa88db9d442cee
https://github.com/bkdotcom/Form/blob/6aa5704b20300e1c8bd1c187a4fa88db9d442cee/src/Form.php#L850-L896
3,164
phpservicebus/core
src/Transport/RabbitMq/BrokerModel.php
BrokerModel.produceExchangeInstance
private function produceExchangeInstance($exchangeName) { if (isset($this->declaredExchangeInstances[$exchangeName])) { return $this->declaredExchangeInstances[$exchangeName]; } if (isset($this->usedExchangeInstances[$exchangeName])) { return $this->usedExchangeInstances[$exchangeName]; } $this->ensureChannel(); $exchange = new AMQPExchange($this->channel); $exchange->setName($exchangeName); $this->usedExchangeInstances[$exchangeName] = $exchange; return $exchange; }
php
private function produceExchangeInstance($exchangeName) { if (isset($this->declaredExchangeInstances[$exchangeName])) { return $this->declaredExchangeInstances[$exchangeName]; } if (isset($this->usedExchangeInstances[$exchangeName])) { return $this->usedExchangeInstances[$exchangeName]; } $this->ensureChannel(); $exchange = new AMQPExchange($this->channel); $exchange->setName($exchangeName); $this->usedExchangeInstances[$exchangeName] = $exchange; return $exchange; }
[ "private", "function", "produceExchangeInstance", "(", "$", "exchangeName", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "declaredExchangeInstances", "[", "$", "exchangeName", "]", ")", ")", "{", "return", "$", "this", "->", "declaredExchangeInstances", "[", "$", "exchangeName", "]", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "usedExchangeInstances", "[", "$", "exchangeName", "]", ")", ")", "{", "return", "$", "this", "->", "usedExchangeInstances", "[", "$", "exchangeName", "]", ";", "}", "$", "this", "->", "ensureChannel", "(", ")", ";", "$", "exchange", "=", "new", "AMQPExchange", "(", "$", "this", "->", "channel", ")", ";", "$", "exchange", "->", "setName", "(", "$", "exchangeName", ")", ";", "$", "this", "->", "usedExchangeInstances", "[", "$", "exchangeName", "]", "=", "$", "exchange", ";", "return", "$", "exchange", ";", "}" ]
It returns a cached exchange or a new one if none exists. @param string $exchangeName @return AMQPExchange
[ "It", "returns", "a", "cached", "exchange", "or", "a", "new", "one", "if", "none", "exists", "." ]
adbcf94be1e022120ede0c5aafa8a4f7900b0a6c
https://github.com/phpservicebus/core/blob/adbcf94be1e022120ede0c5aafa8a4f7900b0a6c/src/Transport/RabbitMq/BrokerModel.php#L218-L233
3,165
phpservicebus/core
src/Transport/RabbitMq/BrokerModel.php
BrokerModel.produceQueueInstance
private function produceQueueInstance($queueName) { if (isset($this->declaredQueueInstances[$queueName])) { return $this->declaredQueueInstances[$queueName]; } if (isset($this->usedQueueInstances[$queueName])) { return $this->usedQueueInstances[$queueName]; } $this->ensureChannel(); $queue = new AMQPQueue($this->channel); $queue->setName($queueName); $this->usedQueueInstances[$queueName] = $queue; return $queue; }
php
private function produceQueueInstance($queueName) { if (isset($this->declaredQueueInstances[$queueName])) { return $this->declaredQueueInstances[$queueName]; } if (isset($this->usedQueueInstances[$queueName])) { return $this->usedQueueInstances[$queueName]; } $this->ensureChannel(); $queue = new AMQPQueue($this->channel); $queue->setName($queueName); $this->usedQueueInstances[$queueName] = $queue; return $queue; }
[ "private", "function", "produceQueueInstance", "(", "$", "queueName", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "declaredQueueInstances", "[", "$", "queueName", "]", ")", ")", "{", "return", "$", "this", "->", "declaredQueueInstances", "[", "$", "queueName", "]", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "usedQueueInstances", "[", "$", "queueName", "]", ")", ")", "{", "return", "$", "this", "->", "usedQueueInstances", "[", "$", "queueName", "]", ";", "}", "$", "this", "->", "ensureChannel", "(", ")", ";", "$", "queue", "=", "new", "AMQPQueue", "(", "$", "this", "->", "channel", ")", ";", "$", "queue", "->", "setName", "(", "$", "queueName", ")", ";", "$", "this", "->", "usedQueueInstances", "[", "$", "queueName", "]", "=", "$", "queue", ";", "return", "$", "queue", ";", "}" ]
It returns a cached queue or a new one if none exists. @param string $queueName @return AMQPQueue
[ "It", "returns", "a", "cached", "queue", "or", "a", "new", "one", "if", "none", "exists", "." ]
adbcf94be1e022120ede0c5aafa8a4f7900b0a6c
https://github.com/phpservicebus/core/blob/adbcf94be1e022120ede0c5aafa8a4f7900b0a6c/src/Transport/RabbitMq/BrokerModel.php#L242-L257
3,166
bariew/yii2-user-cms-module
controllers/DefaultController.php
DefaultController.actionLogin
public function actionLogin($view = 'login', $partial = false) { if (!\Yii::$app->user->isGuest) { return $this->goHome(); } $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { return $this->redirect($this->getLoginRedirect()); } if (\Yii::$app->request->isAjax || $partial) { return $this->renderAjax($view, compact('model')); } return $this->render($view, compact('model')); }
php
public function actionLogin($view = 'login', $partial = false) { if (!\Yii::$app->user->isGuest) { return $this->goHome(); } $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { return $this->redirect($this->getLoginRedirect()); } if (\Yii::$app->request->isAjax || $partial) { return $this->renderAjax($view, compact('model')); } return $this->render($view, compact('model')); }
[ "public", "function", "actionLogin", "(", "$", "view", "=", "'login'", ",", "$", "partial", "=", "false", ")", "{", "if", "(", "!", "\\", "Yii", "::", "$", "app", "->", "user", "->", "isGuest", ")", "{", "return", "$", "this", "->", "goHome", "(", ")", ";", "}", "$", "model", "=", "new", "LoginForm", "(", ")", ";", "if", "(", "$", "model", "->", "load", "(", "Yii", "::", "$", "app", "->", "request", "->", "post", "(", ")", ")", "&&", "$", "model", "->", "login", "(", ")", ")", "{", "return", "$", "this", "->", "redirect", "(", "$", "this", "->", "getLoginRedirect", "(", ")", ")", ";", "}", "if", "(", "\\", "Yii", "::", "$", "app", "->", "request", "->", "isAjax", "||", "$", "partial", ")", "{", "return", "$", "this", "->", "renderAjax", "(", "$", "view", ",", "compact", "(", "'model'", ")", ")", ";", "}", "return", "$", "this", "->", "render", "(", "$", "view", ",", "compact", "(", "'model'", ")", ")", ";", "}" ]
Renders login form. @param string $view @param bool $partial @return string view.
[ "Renders", "login", "form", "." ]
d9f5658cae45308c0916bc99976272a4ec906490
https://github.com/bariew/yii2-user-cms-module/blob/d9f5658cae45308c0916bc99976272a4ec906490/controllers/DefaultController.php#L65-L78
3,167
bariew/yii2-user-cms-module
controllers/DefaultController.php
DefaultController.actionRegister
public function actionRegister() { if (!\Yii::$app->user->isGuest) { return $this->goHome(); } $model = new RegisterForm(); if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash("success", Yii::$app->user->isGuest ? Yii::t('modules/user', 'Please confirm registration email!') : Yii::t('modules/user', 'Registration completed!') ); return (($url = $this->getLoginRedirect()) && !Yii::$app->user->isGuest) ? $this->redirect($url) : $this->goBack(); } return $this->render('register', compact('model')); }
php
public function actionRegister() { if (!\Yii::$app->user->isGuest) { return $this->goHome(); } $model = new RegisterForm(); if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash("success", Yii::$app->user->isGuest ? Yii::t('modules/user', 'Please confirm registration email!') : Yii::t('modules/user', 'Registration completed!') ); return (($url = $this->getLoginRedirect()) && !Yii::$app->user->isGuest) ? $this->redirect($url) : $this->goBack(); } return $this->render('register', compact('model')); }
[ "public", "function", "actionRegister", "(", ")", "{", "if", "(", "!", "\\", "Yii", "::", "$", "app", "->", "user", "->", "isGuest", ")", "{", "return", "$", "this", "->", "goHome", "(", ")", ";", "}", "$", "model", "=", "new", "RegisterForm", "(", ")", ";", "if", "(", "$", "model", "->", "load", "(", "Yii", "::", "$", "app", "->", "request", "->", "post", "(", ")", ")", "&&", "$", "model", "->", "save", "(", ")", ")", "{", "Yii", "::", "$", "app", "->", "session", "->", "setFlash", "(", "\"success\"", ",", "Yii", "::", "$", "app", "->", "user", "->", "isGuest", "?", "Yii", "::", "t", "(", "'modules/user'", ",", "'Please confirm registration email!'", ")", ":", "Yii", "::", "t", "(", "'modules/user'", ",", "'Registration completed!'", ")", ")", ";", "return", "(", "(", "$", "url", "=", "$", "this", "->", "getLoginRedirect", "(", ")", ")", "&&", "!", "Yii", "::", "$", "app", "->", "user", "->", "isGuest", ")", "?", "$", "this", "->", "redirect", "(", "$", "url", ")", ":", "$", "this", "->", "goBack", "(", ")", ";", "}", "return", "$", "this", "->", "render", "(", "'register'", ",", "compact", "(", "'model'", ")", ")", ";", "}" ]
Registers user. @return string view.
[ "Registers", "user", "." ]
d9f5658cae45308c0916bc99976272a4ec906490
https://github.com/bariew/yii2-user-cms-module/blob/d9f5658cae45308c0916bc99976272a4ec906490/controllers/DefaultController.php#L95-L112
3,168
bariew/yii2-user-cms-module
controllers/DefaultController.php
DefaultController.actionConfirm
public function actionConfirm($auth_key) { $model = $this->findModel(true); /** * @var User $user */ if ($auth_key && ($user = $model::findOne(compact('auth_key')))) { Yii::$app->session->setFlash("success", Yii::t('modules/user', "You have successfully completed your registration. Please set your password.")); Yii::$app->user->login($user); $user->activate(); }else{ Yii::$app->session->setFlash("error", Yii::t('modules/user', "Your auth link is invalid.")); return $this->goHome(); } $this->redirect(['update']); }
php
public function actionConfirm($auth_key) { $model = $this->findModel(true); /** * @var User $user */ if ($auth_key && ($user = $model::findOne(compact('auth_key')))) { Yii::$app->session->setFlash("success", Yii::t('modules/user', "You have successfully completed your registration. Please set your password.")); Yii::$app->user->login($user); $user->activate(); }else{ Yii::$app->session->setFlash("error", Yii::t('modules/user', "Your auth link is invalid.")); return $this->goHome(); } $this->redirect(['update']); }
[ "public", "function", "actionConfirm", "(", "$", "auth_key", ")", "{", "$", "model", "=", "$", "this", "->", "findModel", "(", "true", ")", ";", "/**\n * @var User $user\n */", "if", "(", "$", "auth_key", "&&", "(", "$", "user", "=", "$", "model", "::", "findOne", "(", "compact", "(", "'auth_key'", ")", ")", ")", ")", "{", "Yii", "::", "$", "app", "->", "session", "->", "setFlash", "(", "\"success\"", ",", "Yii", "::", "t", "(", "'modules/user'", ",", "\"You have successfully completed your registration. Please set your password.\"", ")", ")", ";", "Yii", "::", "$", "app", "->", "user", "->", "login", "(", "$", "user", ")", ";", "$", "user", "->", "activate", "(", ")", ";", "}", "else", "{", "Yii", "::", "$", "app", "->", "session", "->", "setFlash", "(", "\"error\"", ",", "Yii", "::", "t", "(", "'modules/user'", ",", "\"Your auth link is invalid.\"", ")", ")", ";", "return", "$", "this", "->", "goHome", "(", ")", ";", "}", "$", "this", "->", "redirect", "(", "[", "'update'", "]", ")", ";", "}" ]
For registration confirmation by email auth link. @param string $auth_key user authorization key. @return string view.
[ "For", "registration", "confirmation", "by", "email", "auth", "link", "." ]
d9f5658cae45308c0916bc99976272a4ec906490
https://github.com/bariew/yii2-user-cms-module/blob/d9f5658cae45308c0916bc99976272a4ec906490/controllers/DefaultController.php#L119-L135
3,169
bariew/yii2-user-cms-module
controllers/DefaultController.php
DefaultController.findModel
public function findModel($new = false) { $class = \Yii::$app->user->identityClass; return $new === true ? new $class() : Yii::$app->user->identity; }
php
public function findModel($new = false) { $class = \Yii::$app->user->identityClass; return $new === true ? new $class() : Yii::$app->user->identity; }
[ "public", "function", "findModel", "(", "$", "new", "=", "false", ")", "{", "$", "class", "=", "\\", "Yii", "::", "$", "app", "->", "user", "->", "identityClass", ";", "return", "$", "new", "===", "true", "?", "new", "$", "class", "(", ")", ":", "Yii", "::", "$", "app", "->", "user", "->", "identity", ";", "}" ]
Finds user model. @param boolean $new @return User
[ "Finds", "user", "model", "." ]
d9f5658cae45308c0916bc99976272a4ec906490
https://github.com/bariew/yii2-user-cms-module/blob/d9f5658cae45308c0916bc99976272a4ec906490/controllers/DefaultController.php#L163-L167
3,170
soloproyectos-php/array
src/arr/arguments/ArrArguments.php
ArrArguments.fetch
public function fetch() { $ret = array(); $pos = 0; $len = count($this->_arguments); foreach ($this->_descriptors as $name => $descriptor) { $value = $descriptor->getDefault(); for ($i = $pos; ; $i++) { if ($i < $len && $descriptor->match($this->_arguments[$i])) { $value = $this->_arguments[$i]; $pos = $i + 1; break; } else { if ($descriptor->isRequired()) { throw new InvalidArgumentException( "Argument is required: `$name`" ); } if ($i > $len - 1) { break; } } } $ret[$name] = $value; } return $ret; }
php
public function fetch() { $ret = array(); $pos = 0; $len = count($this->_arguments); foreach ($this->_descriptors as $name => $descriptor) { $value = $descriptor->getDefault(); for ($i = $pos; ; $i++) { if ($i < $len && $descriptor->match($this->_arguments[$i])) { $value = $this->_arguments[$i]; $pos = $i + 1; break; } else { if ($descriptor->isRequired()) { throw new InvalidArgumentException( "Argument is required: `$name`" ); } if ($i > $len - 1) { break; } } } $ret[$name] = $value; } return $ret; }
[ "public", "function", "fetch", "(", ")", "{", "$", "ret", "=", "array", "(", ")", ";", "$", "pos", "=", "0", ";", "$", "len", "=", "count", "(", "$", "this", "->", "_arguments", ")", ";", "foreach", "(", "$", "this", "->", "_descriptors", "as", "$", "name", "=>", "$", "descriptor", ")", "{", "$", "value", "=", "$", "descriptor", "->", "getDefault", "(", ")", ";", "for", "(", "$", "i", "=", "$", "pos", ";", ";", "$", "i", "++", ")", "{", "if", "(", "$", "i", "<", "$", "len", "&&", "$", "descriptor", "->", "match", "(", "$", "this", "->", "_arguments", "[", "$", "i", "]", ")", ")", "{", "$", "value", "=", "$", "this", "->", "_arguments", "[", "$", "i", "]", ";", "$", "pos", "=", "$", "i", "+", "1", ";", "break", ";", "}", "else", "{", "if", "(", "$", "descriptor", "->", "isRequired", "(", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Argument is required: `$name`\"", ")", ";", "}", "if", "(", "$", "i", ">", "$", "len", "-", "1", ")", "{", "break", ";", "}", "}", "}", "$", "ret", "[", "$", "name", "]", "=", "$", "value", ";", "}", "return", "$", "ret", ";", "}" ]
Fetches elements from the arguments that matches specific descriptors. @return array associative array @throws InvalidArgumentException
[ "Fetches", "elements", "from", "the", "arguments", "that", "matches", "specific", "descriptors", "." ]
de38c800f3388005cbd37e70ab055f22609a5eae
https://github.com/soloproyectos-php/array/blob/de38c800f3388005cbd37e70ab055f22609a5eae/src/arr/arguments/ArrArguments.php#L67-L97
3,171
liverbool/dos-resource-bundle
EventListener/ReplaceSyliusTrans.php
ReplaceSyliusTrans.replaceKeys
public function replaceKeys(FilterResponseEvent $event) { if (!$event->isMasterRequest()) { return; } if ($this->controller !== $event->getRequest()->attributes->get('_controller')) { return; } $response = $event->getResponse(); $content = preg_replace($this->pattern, $this->replacement, $response->getContent()); $response->setContent($content); }
php
public function replaceKeys(FilterResponseEvent $event) { if (!$event->isMasterRequest()) { return; } if ($this->controller !== $event->getRequest()->attributes->get('_controller')) { return; } $response = $event->getResponse(); $content = preg_replace($this->pattern, $this->replacement, $response->getContent()); $response->setContent($content); }
[ "public", "function", "replaceKeys", "(", "FilterResponseEvent", "$", "event", ")", "{", "if", "(", "!", "$", "event", "->", "isMasterRequest", "(", ")", ")", "{", "return", ";", "}", "if", "(", "$", "this", "->", "controller", "!==", "$", "event", "->", "getRequest", "(", ")", "->", "attributes", "->", "get", "(", "'_controller'", ")", ")", "{", "return", ";", "}", "$", "response", "=", "$", "event", "->", "getResponse", "(", ")", ";", "$", "content", "=", "preg_replace", "(", "$", "this", "->", "pattern", ",", "$", "this", "->", "replacement", ",", "$", "response", "->", "getContent", "(", ")", ")", ";", "$", "response", "->", "setContent", "(", "$", "content", ")", ";", "}" ]
Replace Sylius translation keys. @param FilterResponseEvent $event
[ "Replace", "Sylius", "translation", "keys", "." ]
c8607a46c2cea80cc138994be74f4dea3c197abc
https://github.com/liverbool/dos-resource-bundle/blob/c8607a46c2cea80cc138994be74f4dea3c197abc/EventListener/ReplaceSyliusTrans.php#L25-L38
3,172
jannisfink/yarf
src/request/PageMapper.php
PageMapper.uriKeyExists
private function uriKeyExists($nextUriPart, array $pageMap) { if (array_key_exists($nextUriPart, $pageMap)) { return $nextUriPart; } $keys = array_keys($pageMap); $variableParts = array_values(preg_grep('/\{(.*)\}/', $keys)); $variablePartsCount = count($variableParts); if ($variablePartsCount === 0) { return null; } elseif ($variablePartsCount > 1) { throw new RoutingException('Single node has more than one variable key'); } $variablePartRaw = $variableParts[0]; $variablePart = preg_replace(['/\{/', '/\}/'], '', $variablePartRaw); if (array_key_exists($variablePart, $this->uriVariables)) { throw new RoutingException('a key named ' . $variablePart . ' appears more than once on a single route'); } $this->uriVariables[$variablePart] = $nextUriPart; return $variablePartRaw; }
php
private function uriKeyExists($nextUriPart, array $pageMap) { if (array_key_exists($nextUriPart, $pageMap)) { return $nextUriPart; } $keys = array_keys($pageMap); $variableParts = array_values(preg_grep('/\{(.*)\}/', $keys)); $variablePartsCount = count($variableParts); if ($variablePartsCount === 0) { return null; } elseif ($variablePartsCount > 1) { throw new RoutingException('Single node has more than one variable key'); } $variablePartRaw = $variableParts[0]; $variablePart = preg_replace(['/\{/', '/\}/'], '', $variablePartRaw); if (array_key_exists($variablePart, $this->uriVariables)) { throw new RoutingException('a key named ' . $variablePart . ' appears more than once on a single route'); } $this->uriVariables[$variablePart] = $nextUriPart; return $variablePartRaw; }
[ "private", "function", "uriKeyExists", "(", "$", "nextUriPart", ",", "array", "$", "pageMap", ")", "{", "if", "(", "array_key_exists", "(", "$", "nextUriPart", ",", "$", "pageMap", ")", ")", "{", "return", "$", "nextUriPart", ";", "}", "$", "keys", "=", "array_keys", "(", "$", "pageMap", ")", ";", "$", "variableParts", "=", "array_values", "(", "preg_grep", "(", "'/\\{(.*)\\}/'", ",", "$", "keys", ")", ")", ";", "$", "variablePartsCount", "=", "count", "(", "$", "variableParts", ")", ";", "if", "(", "$", "variablePartsCount", "===", "0", ")", "{", "return", "null", ";", "}", "elseif", "(", "$", "variablePartsCount", ">", "1", ")", "{", "throw", "new", "RoutingException", "(", "'Single node has more than one variable key'", ")", ";", "}", "$", "variablePartRaw", "=", "$", "variableParts", "[", "0", "]", ";", "$", "variablePart", "=", "preg_replace", "(", "[", "'/\\{/'", ",", "'/\\}/'", "]", ",", "''", ",", "$", "variablePartRaw", ")", ";", "if", "(", "array_key_exists", "(", "$", "variablePart", ",", "$", "this", "->", "uriVariables", ")", ")", "{", "throw", "new", "RoutingException", "(", "'a key named '", ".", "$", "variablePart", ".", "' appears more than once on a single route'", ")", ";", "}", "$", "this", "->", "uriVariables", "[", "$", "variablePart", "]", "=", "$", "nextUriPart", ";", "return", "$", "variablePartRaw", ";", "}" ]
Checks, if there is a key in the page map for the given uri part. If there is a wildcard in the url, it will save the wildcard + it's value @param string $nextUriPart @param array $pageMap @return string|null the key, if there is any, {@code null} else @throws RoutingException if a variable in the url appears twice on a single part
[ "Checks", "if", "there", "is", "a", "key", "in", "the", "page", "map", "for", "the", "given", "uri", "part", ".", "If", "there", "is", "a", "wildcard", "in", "the", "url", "it", "will", "save", "the", "wildcard", "+", "it", "s", "value" ]
91237dc0f3b724abaaba490f5171f181a92e939f
https://github.com/jannisfink/yarf/blob/91237dc0f3b724abaaba490f5171f181a92e939f/src/request/PageMapper.php#L108-L127
3,173
arvici/framework
src/Arvici/Component/View/View.php
View.getFullPath
public function getFullPath() { $key = 'template.templatePath'; if ($this->type === self::PART_BODY) { $key = 'template.viewPath'; } $path = Configuration::get($key, null); if ($path === null) { // @codeCoverageIgnore throw new ConfigurationException("The template.templatePath or template.viewPath isn't configured right or doesn't exists!"); // @codeCoverageIgnore } // @codeCoverageIgnore $foundView = false; try { AppManager::getInstance()->initApps(); } catch (\Exception $exception) {} foreach (AppManager::getInstance()->getApps() as $app) { $testPath = $app->getAppDirectory() . DS . $path . DS . $this->getPath(); if (is_file($testPath)) { $path = $testPath; $foundView = true; } } if (! $foundView) { throw new NotFoundException('Template or view file not found in any apps!'); } return $path; }
php
public function getFullPath() { $key = 'template.templatePath'; if ($this->type === self::PART_BODY) { $key = 'template.viewPath'; } $path = Configuration::get($key, null); if ($path === null) { // @codeCoverageIgnore throw new ConfigurationException("The template.templatePath or template.viewPath isn't configured right or doesn't exists!"); // @codeCoverageIgnore } // @codeCoverageIgnore $foundView = false; try { AppManager::getInstance()->initApps(); } catch (\Exception $exception) {} foreach (AppManager::getInstance()->getApps() as $app) { $testPath = $app->getAppDirectory() . DS . $path . DS . $this->getPath(); if (is_file($testPath)) { $path = $testPath; $foundView = true; } } if (! $foundView) { throw new NotFoundException('Template or view file not found in any apps!'); } return $path; }
[ "public", "function", "getFullPath", "(", ")", "{", "$", "key", "=", "'template.templatePath'", ";", "if", "(", "$", "this", "->", "type", "===", "self", "::", "PART_BODY", ")", "{", "$", "key", "=", "'template.viewPath'", ";", "}", "$", "path", "=", "Configuration", "::", "get", "(", "$", "key", ",", "null", ")", ";", "if", "(", "$", "path", "===", "null", ")", "{", "// @codeCoverageIgnore", "throw", "new", "ConfigurationException", "(", "\"The template.templatePath or template.viewPath isn't configured right or doesn't exists!\"", ")", ";", "// @codeCoverageIgnore", "}", "// @codeCoverageIgnore", "$", "foundView", "=", "false", ";", "try", "{", "AppManager", "::", "getInstance", "(", ")", "->", "initApps", "(", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "exception", ")", "{", "}", "foreach", "(", "AppManager", "::", "getInstance", "(", ")", "->", "getApps", "(", ")", "as", "$", "app", ")", "{", "$", "testPath", "=", "$", "app", "->", "getAppDirectory", "(", ")", ".", "DS", ".", "$", "path", ".", "DS", ".", "$", "this", "->", "getPath", "(", ")", ";", "if", "(", "is_file", "(", "$", "testPath", ")", ")", "{", "$", "path", "=", "$", "testPath", ";", "$", "foundView", "=", "true", ";", "}", "}", "if", "(", "!", "$", "foundView", ")", "{", "throw", "new", "NotFoundException", "(", "'Template or view file not found in any apps!'", ")", ";", "}", "return", "$", "path", ";", "}" ]
Get full path of view file. @return string @throws ConfigurationException @throws NotFoundException
[ "Get", "full", "path", "of", "view", "file", "." ]
4d0933912fef8f9edc756ef1ace009e96d9fc4b1
https://github.com/arvici/framework/blob/4d0933912fef8f9edc756ef1ace009e96d9fc4b1/src/Arvici/Component/View/View.php#L168-L199
3,174
calgamo/logger
src/LogManager.php
LogManager.writeMessage
private function writeMessage(string $level, string $message, string $tag, string $file, int $line, array $target_loggers) { if ( !$this->logger_config->isLogEnabled() ){ return; } // determine log level filter $log_level_filter = 'E'; foreach($this->logger_config->getLogLevelFilters() as $path => $lv) { if ($this->route_context === $path || strpos($this->route_context, $path) === 0){ $log_level_filter = $lv; } } // do not output message when log level does not meet the filter level $cmp = self::compareLogLevel($level, $log_level_filter); if ( $cmp > 0 ){ return; } // ignore different tags $log_tag_filters = $this->logger_config->getTagFilters(); if ( is_array($log_tag_filters) && !empty($log_tag_filters) ){ if ( !in_array( $tag, $log_tag_filters ) ){ return; } } $msg = new LogMessage($level, $message, $tag, $file, $line); foreach( $target_loggers as $key ) { if ( isset($this->loggers[$key]) && in_array($key,$target_loggers) ) { $this->loggers[$key]->writeln($msg); } } }
php
private function writeMessage(string $level, string $message, string $tag, string $file, int $line, array $target_loggers) { if ( !$this->logger_config->isLogEnabled() ){ return; } // determine log level filter $log_level_filter = 'E'; foreach($this->logger_config->getLogLevelFilters() as $path => $lv) { if ($this->route_context === $path || strpos($this->route_context, $path) === 0){ $log_level_filter = $lv; } } // do not output message when log level does not meet the filter level $cmp = self::compareLogLevel($level, $log_level_filter); if ( $cmp > 0 ){ return; } // ignore different tags $log_tag_filters = $this->logger_config->getTagFilters(); if ( is_array($log_tag_filters) && !empty($log_tag_filters) ){ if ( !in_array( $tag, $log_tag_filters ) ){ return; } } $msg = new LogMessage($level, $message, $tag, $file, $line); foreach( $target_loggers as $key ) { if ( isset($this->loggers[$key]) && in_array($key,$target_loggers) ) { $this->loggers[$key]->writeln($msg); } } }
[ "private", "function", "writeMessage", "(", "string", "$", "level", ",", "string", "$", "message", ",", "string", "$", "tag", ",", "string", "$", "file", ",", "int", "$", "line", ",", "array", "$", "target_loggers", ")", "{", "if", "(", "!", "$", "this", "->", "logger_config", "->", "isLogEnabled", "(", ")", ")", "{", "return", ";", "}", "// determine log level filter", "$", "log_level_filter", "=", "'E'", ";", "foreach", "(", "$", "this", "->", "logger_config", "->", "getLogLevelFilters", "(", ")", "as", "$", "path", "=>", "$", "lv", ")", "{", "if", "(", "$", "this", "->", "route_context", "===", "$", "path", "||", "strpos", "(", "$", "this", "->", "route_context", ",", "$", "path", ")", "===", "0", ")", "{", "$", "log_level_filter", "=", "$", "lv", ";", "}", "}", "// do not output message when log level does not meet the filter level", "$", "cmp", "=", "self", "::", "compareLogLevel", "(", "$", "level", ",", "$", "log_level_filter", ")", ";", "if", "(", "$", "cmp", ">", "0", ")", "{", "return", ";", "}", "// ignore different tags", "$", "log_tag_filters", "=", "$", "this", "->", "logger_config", "->", "getTagFilters", "(", ")", ";", "if", "(", "is_array", "(", "$", "log_tag_filters", ")", "&&", "!", "empty", "(", "$", "log_tag_filters", ")", ")", "{", "if", "(", "!", "in_array", "(", "$", "tag", ",", "$", "log_tag_filters", ")", ")", "{", "return", ";", "}", "}", "$", "msg", "=", "new", "LogMessage", "(", "$", "level", ",", "$", "message", ",", "$", "tag", ",", "$", "file", ",", "$", "line", ")", ";", "foreach", "(", "$", "target_loggers", "as", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "loggers", "[", "$", "key", "]", ")", "&&", "in_array", "(", "$", "key", ",", "$", "target_loggers", ")", ")", "{", "$", "this", "->", "loggers", "[", "$", "key", "]", "->", "writeln", "(", "$", "msg", ")", ";", "}", "}", "}" ]
write a message @param string $level log level @param string $message log message @param string $tag log tag @param string $file file path @param int $line line of file @param array $target_loggers
[ "write", "a", "message" ]
58aab9ddfe3f383337c61cad1f4742ce5afb9591
https://github.com/calgamo/logger/blob/58aab9ddfe3f383337c61cad1f4742ce5afb9591/src/LogManager.php#L81-L119
3,175
calgamo/logger
src/LogManager.php
LogManager.terminate
public function terminate() { if ( $this->loggers ) { foreach( $this->loggers as $key => $logger ) { $logger->writeFooter(); $logger->terminate(); unset($this->loggers[$key]); } $this->loggers = NULL; } }
php
public function terminate() { if ( $this->loggers ) { foreach( $this->loggers as $key => $logger ) { $logger->writeFooter(); $logger->terminate(); unset($this->loggers[$key]); } $this->loggers = NULL; } }
[ "public", "function", "terminate", "(", ")", "{", "if", "(", "$", "this", "->", "loggers", ")", "{", "foreach", "(", "$", "this", "->", "loggers", "as", "$", "key", "=>", "$", "logger", ")", "{", "$", "logger", "->", "writeFooter", "(", ")", ";", "$", "logger", "->", "terminate", "(", ")", ";", "unset", "(", "$", "this", "->", "loggers", "[", "$", "key", "]", ")", ";", "}", "$", "this", "->", "loggers", "=", "NULL", ";", "}", "}" ]
shutdown all loggers
[ "shutdown", "all", "loggers" ]
58aab9ddfe3f383337c61cad1f4742ce5afb9591
https://github.com/calgamo/logger/blob/58aab9ddfe3f383337c61cad1f4742ce5afb9591/src/LogManager.php#L124-L136
3,176
calgamo/logger
src/LogManager.php
LogManager.trace
public function trace( string $file, int $line, string $target, string $message, string $tag = NULL ) { self::log( $file, $line, "T:$target", $message, $tag ); }
php
public function trace( string $file, int $line, string $target, string $message, string $tag = NULL ) { self::log( $file, $line, "T:$target", $message, $tag ); }
[ "public", "function", "trace", "(", "string", "$", "file", ",", "int", "$", "line", ",", "string", "$", "target", ",", "string", "$", "message", ",", "string", "$", "tag", "=", "NULL", ")", "{", "self", "::", "log", "(", "$", "file", ",", "$", "line", ",", "\"T:$target\"", ",", "$", "message", ",", "$", "tag", ")", ";", "}" ]
write trace log @param string $file file path @param int $line line of file @param string $target log target @param string $message log message to write @param string $tag tag string(optional)
[ "write", "trace", "log" ]
58aab9ddfe3f383337c61cad1f4742ce5afb9591
https://github.com/calgamo/logger/blob/58aab9ddfe3f383337c61cad1f4742ce5afb9591/src/LogManager.php#L196-L199
3,177
calgamo/logger
src/LogManager.php
LogManager._getLevelAndTargetLoggers
private function _getLevelAndTargetLoggers( $target ) { $target = strpos($target, ':') !== false ? explode( ':' , $target ) : ['', '*']; list($level,$target_loggers) = $target; $target_loggers = explode( ',' , $target_loggers ); $target_loggers = array_map( 'trim', $target_loggers ); if (in_array('*',$target_loggers)) { $target_loggers = array_keys($this->loggers); } return array( $level, $target_loggers ); }
php
private function _getLevelAndTargetLoggers( $target ) { $target = strpos($target, ':') !== false ? explode( ':' , $target ) : ['', '*']; list($level,$target_loggers) = $target; $target_loggers = explode( ',' , $target_loggers ); $target_loggers = array_map( 'trim', $target_loggers ); if (in_array('*',$target_loggers)) { $target_loggers = array_keys($this->loggers); } return array( $level, $target_loggers ); }
[ "private", "function", "_getLevelAndTargetLoggers", "(", "$", "target", ")", "{", "$", "target", "=", "strpos", "(", "$", "target", ",", "':'", ")", "!==", "false", "?", "explode", "(", "':'", ",", "$", "target", ")", ":", "[", "''", ",", "'*'", "]", ";", "list", "(", "$", "level", ",", "$", "target_loggers", ")", "=", "$", "target", ";", "$", "target_loggers", "=", "explode", "(", "','", ",", "$", "target_loggers", ")", ";", "$", "target_loggers", "=", "array_map", "(", "'trim'", ",", "$", "target_loggers", ")", ";", "if", "(", "in_array", "(", "'*'", ",", "$", "target_loggers", ")", ")", "{", "$", "target_loggers", "=", "array_keys", "(", "$", "this", "->", "loggers", ")", ";", "}", "return", "array", "(", "$", "level", ",", "$", "target_loggers", ")", ";", "}" ]
Split target loggers and levels from target list format of parameter '$target_list': [level]:[logger1],[logger2],... ex) "I:app,debug,sql" @param string $target log target @return array
[ "Split", "target", "loggers", "and", "levels", "from", "target", "list" ]
58aab9ddfe3f383337c61cad1f4742ce5afb9591
https://github.com/calgamo/logger/blob/58aab9ddfe3f383337c61cad1f4742ce5afb9591/src/LogManager.php#L301-L312
3,178
bogdananton/php-class-helper
ClassHelper.php
ClassHelper.instance
public static function instance($object) { if (!is_object($object)) { throw new \InvalidArgumentException('Only objects are allowed to be passed to the helper.'); } $response = new self(); $response->origin = $object; $response->target = new ReflectionClass($object); return $response; }
php
public static function instance($object) { if (!is_object($object)) { throw new \InvalidArgumentException('Only objects are allowed to be passed to the helper.'); } $response = new self(); $response->origin = $object; $response->target = new ReflectionClass($object); return $response; }
[ "public", "static", "function", "instance", "(", "$", "object", ")", "{", "if", "(", "!", "is_object", "(", "$", "object", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Only objects are allowed to be passed to the helper.'", ")", ";", "}", "$", "response", "=", "new", "self", "(", ")", ";", "$", "response", "->", "origin", "=", "$", "object", ";", "$", "response", "->", "target", "=", "new", "ReflectionClass", "(", "$", "object", ")", ";", "return", "$", "response", ";", "}" ]
Creates and returns the wrapper. Only objects are allowed to be passed, else an exception will be thrown. Store the input object to the created wrapper. @param $object @return Helper
[ "Creates", "and", "returns", "the", "wrapper", ".", "Only", "objects", "are", "allowed", "to", "be", "passed", "else", "an", "exception", "will", "be", "thrown", ".", "Store", "the", "input", "object", "to", "the", "created", "wrapper", "." ]
38bf4524e0fcb30730b8226d34159dcb59420ffe
https://github.com/bogdananton/php-class-helper/blob/38bf4524e0fcb30730b8226d34159dcb59420ffe/ClassHelper.php#L18-L28
3,179
mszewcz/php-light-framework
src/Base.php
Base.parsePath
public function parsePath(?string $path = null): ?string { if ($path === null) { return null; } $path = \str_replace('%DOCUMENT_ROOT%', $this->documentRoot, $path); $path = \str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $path); return $path; }
php
public function parsePath(?string $path = null): ?string { if ($path === null) { return null; } $path = \str_replace('%DOCUMENT_ROOT%', $this->documentRoot, $path); $path = \str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $path); return $path; }
[ "public", "function", "parsePath", "(", "?", "string", "$", "path", "=", "null", ")", ":", "?", "string", "{", "if", "(", "$", "path", "===", "null", ")", "{", "return", "null", ";", "}", "$", "path", "=", "\\", "str_replace", "(", "'%DOCUMENT_ROOT%'", ",", "$", "this", "->", "documentRoot", ",", "$", "path", ")", ";", "$", "path", "=", "\\", "str_replace", "(", "[", "'\\\\'", ",", "'/'", "]", ",", "DIRECTORY_SEPARATOR", ",", "$", "path", ")", ";", "return", "$", "path", ";", "}" ]
Replaces predefined constants in path string to document and framework root @param null|string $path @return null|string
[ "Replaces", "predefined", "constants", "in", "path", "string", "to", "document", "and", "framework", "root" ]
4d3b46781c387202c2dfbdb8760151b3ae8ef49c
https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Base.php#L106-L114
3,180
roydejong/Enlighten
lib/Routing/Filters.php
Filters.register
public function register($eventType, callable $filter) { if (!isset($this->handlers[$eventType])) { $this->handlers[$eventType] = []; } $this->handlers[$eventType][] = $filter; }
php
public function register($eventType, callable $filter) { if (!isset($this->handlers[$eventType])) { $this->handlers[$eventType] = []; } $this->handlers[$eventType][] = $filter; }
[ "public", "function", "register", "(", "$", "eventType", ",", "callable", "$", "filter", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "handlers", "[", "$", "eventType", "]", ")", ")", "{", "$", "this", "->", "handlers", "[", "$", "eventType", "]", "=", "[", "]", ";", "}", "$", "this", "->", "handlers", "[", "$", "eventType", "]", "[", "]", "=", "$", "filter", ";", "}" ]
Registers a filter function. @param string $eventType The type of event, see constant values in Filters class. e.g. 'beforeRoute'. @param callable $filter
[ "Registers", "a", "filter", "function", "." ]
67585b061a50f20da23de75ce920c8e26517d900
https://github.com/roydejong/Enlighten/blob/67585b061a50f20da23de75ce920c8e26517d900/lib/Routing/Filters.php#L61-L68
3,181
issei-m/simple-job-queue
Worker.php
Worker.start
public function start(int $maxRuntimeInSec = 60 * 15): void { \pcntl_signal(SIGTERM, function () { $this->shouldTerminate = true; $this->logger->debug('Caught SIGTERM, worker goes into termination.'); }); $this->startedTime = \time(); $this->logger->info('Worker started: ' . $this->name); while (!$this->shouldTerminate || 0 < \count($this->runningJobs)) { \pcntl_signal_dispatch(); $this->checkRunningJobs(); if (!$this->shouldTerminate) { if (\count($this->runningJobs) < $this->maxJobs && null !== $job = $this->queue->dequeue()) { $this->handleDequeuedJob($job); } if (\time() > $this->startedTime + $maxRuntimeInSec) { $this->shouldTerminate = true; $this->logger->debug('Elapsed maximum runtime, worker goes into termination.'); } } \usleep(500000); } }
php
public function start(int $maxRuntimeInSec = 60 * 15): void { \pcntl_signal(SIGTERM, function () { $this->shouldTerminate = true; $this->logger->debug('Caught SIGTERM, worker goes into termination.'); }); $this->startedTime = \time(); $this->logger->info('Worker started: ' . $this->name); while (!$this->shouldTerminate || 0 < \count($this->runningJobs)) { \pcntl_signal_dispatch(); $this->checkRunningJobs(); if (!$this->shouldTerminate) { if (\count($this->runningJobs) < $this->maxJobs && null !== $job = $this->queue->dequeue()) { $this->handleDequeuedJob($job); } if (\time() > $this->startedTime + $maxRuntimeInSec) { $this->shouldTerminate = true; $this->logger->debug('Elapsed maximum runtime, worker goes into termination.'); } } \usleep(500000); } }
[ "public", "function", "start", "(", "int", "$", "maxRuntimeInSec", "=", "60", "*", "15", ")", ":", "void", "{", "\\", "pcntl_signal", "(", "SIGTERM", ",", "function", "(", ")", "{", "$", "this", "->", "shouldTerminate", "=", "true", ";", "$", "this", "->", "logger", "->", "debug", "(", "'Caught SIGTERM, worker goes into termination.'", ")", ";", "}", ")", ";", "$", "this", "->", "startedTime", "=", "\\", "time", "(", ")", ";", "$", "this", "->", "logger", "->", "info", "(", "'Worker started: '", ".", "$", "this", "->", "name", ")", ";", "while", "(", "!", "$", "this", "->", "shouldTerminate", "||", "0", "<", "\\", "count", "(", "$", "this", "->", "runningJobs", ")", ")", "{", "\\", "pcntl_signal_dispatch", "(", ")", ";", "$", "this", "->", "checkRunningJobs", "(", ")", ";", "if", "(", "!", "$", "this", "->", "shouldTerminate", ")", "{", "if", "(", "\\", "count", "(", "$", "this", "->", "runningJobs", ")", "<", "$", "this", "->", "maxJobs", "&&", "null", "!==", "$", "job", "=", "$", "this", "->", "queue", "->", "dequeue", "(", ")", ")", "{", "$", "this", "->", "handleDequeuedJob", "(", "$", "job", ")", ";", "}", "if", "(", "\\", "time", "(", ")", ">", "$", "this", "->", "startedTime", "+", "$", "maxRuntimeInSec", ")", "{", "$", "this", "->", "shouldTerminate", "=", "true", ";", "$", "this", "->", "logger", "->", "debug", "(", "'Elapsed maximum runtime, worker goes into termination.'", ")", ";", "}", "}", "\\", "usleep", "(", "500000", ")", ";", "}", "}" ]
Starts polling to run jobs. @param int $maxRuntimeInSec The maximum runtime in second, the polling will be terminated after this time was elapsed.
[ "Starts", "polling", "to", "run", "jobs", "." ]
2fcc9f7a123b690664f470aad9b52a991b540d0d
https://github.com/issei-m/simple-job-queue/blob/2fcc9f7a123b690664f470aad9b52a991b540d0d/Worker.php#L90-L119
3,182
gliverphp/database
src/DbException.php
DbeException.show
public function show() { //get the global $config array for site title global $config; //set the title variable $title = $config['title']; //the variable to be populated with the error message $msg = $this->getCode() . ': Error on line '.$this->getLine().' in '.$this->getFile() .': <b> "'.$this->getMessage().' " </b> '; //load the template file include Path::sys() . 'Exceptions' . DIRECTORY_SEPARATOR . 'index.php'; //stop further output exit(); }
php
public function show() { //get the global $config array for site title global $config; //set the title variable $title = $config['title']; //the variable to be populated with the error message $msg = $this->getCode() . ': Error on line '.$this->getLine().' in '.$this->getFile() .': <b> "'.$this->getMessage().' " </b> '; //load the template file include Path::sys() . 'Exceptions' . DIRECTORY_SEPARATOR . 'index.php'; //stop further output exit(); }
[ "public", "function", "show", "(", ")", "{", "//get the global $config array for site title", "global", "$", "config", ";", "//set the title variable", "$", "title", "=", "$", "config", "[", "'title'", "]", ";", "//the variable to be populated with the error message", "$", "msg", "=", "$", "this", "->", "getCode", "(", ")", ".", "': Error on line '", ".", "$", "this", "->", "getLine", "(", ")", ".", "' in '", ".", "$", "this", "->", "getFile", "(", ")", ".", "': <b> \"'", ".", "$", "this", "->", "getMessage", "(", ")", ".", "' \" </b> '", ";", "//load the template file", "include", "Path", "::", "sys", "(", ")", ".", "'Exceptions'", ".", "DIRECTORY_SEPARATOR", ".", "'index.php'", ";", "//stop further output", "exit", "(", ")", ";", "}" ]
This method displays the error message @param
[ "This", "method", "displays", "the", "error", "message" ]
b998bd3d24cb2f269b9bd54438c7df8751377ba9
https://github.com/gliverphp/database/blob/b998bd3d24cb2f269b9bd54438c7df8751377ba9/src/DbException.php#L25-L42
3,183
unyx/utils
Arr.php
Arr.add
public static function add(array& $array, string $key, $value, string $delimiter = null) { if (null === static::get($array, $key, null, $delimiter)) { static::set($array, $key, $value, $delimiter); } }
php
public static function add(array& $array, string $key, $value, string $delimiter = null) { if (null === static::get($array, $key, null, $delimiter)) { static::set($array, $key, $value, $delimiter); } }
[ "public", "static", "function", "add", "(", "array", "&", "$", "array", ",", "string", "$", "key", ",", "$", "value", ",", "string", "$", "delimiter", "=", "null", ")", "{", "if", "(", "null", "===", "static", "::", "get", "(", "$", "array", ",", "$", "key", ",", "null", ",", "$", "delimiter", ")", ")", "{", "static", "::", "set", "(", "$", "array", ",", "$", "key", ",", "$", "value", ",", "$", "delimiter", ")", ";", "}", "}" ]
Adds an element to the given array but only if it does not yet exist. Note: Null as value of an item is considered a non-existing item for the purposes of this method. @param array $array The array to which the element should be added. @param string $key The key at which the value should be added. @param mixed $value The value of the element. @param string $delimiter The delimiter to use when exploding the key into parts.
[ "Adds", "an", "element", "to", "the", "given", "array", "but", "only", "if", "it", "does", "not", "yet", "exist", "." ]
503a3dd46fd2216024ab771b6e830be16d36b358
https://github.com/unyx/utils/blob/503a3dd46fd2216024ab771b6e830be16d36b358/Arr.php#L63-L68
3,184
unyx/utils
Arr.php
Arr.collapse
public static function collapse(array $array) : array { $results = []; foreach ($array as $key => $item) { // Nested arrays will be merged in (non-recursively). if (is_array($item)) { $results = array_merge($results, $item); continue; } // Values with numeric keys will be appended in any case. if (is_int($key)) { $results[] = $item; continue; } // Non-numeric keys. If we've got the given key in $results already, it means it was merged // in from one of the nested arrays and those are meant to overwrite the initial values on collisions - // thus we're not going to do anything in that case. if (!array_key_exists($key, $results)) { $results[$key] = $item; } } return $results; }
php
public static function collapse(array $array) : array { $results = []; foreach ($array as $key => $item) { // Nested arrays will be merged in (non-recursively). if (is_array($item)) { $results = array_merge($results, $item); continue; } // Values with numeric keys will be appended in any case. if (is_int($key)) { $results[] = $item; continue; } // Non-numeric keys. If we've got the given key in $results already, it means it was merged // in from one of the nested arrays and those are meant to overwrite the initial values on collisions - // thus we're not going to do anything in that case. if (!array_key_exists($key, $results)) { $results[$key] = $item; } } return $results; }
[ "public", "static", "function", "collapse", "(", "array", "$", "array", ")", ":", "array", "{", "$", "results", "=", "[", "]", ";", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "item", ")", "{", "// Nested arrays will be merged in (non-recursively).", "if", "(", "is_array", "(", "$", "item", ")", ")", "{", "$", "results", "=", "array_merge", "(", "$", "results", ",", "$", "item", ")", ";", "continue", ";", "}", "// Values with numeric keys will be appended in any case.", "if", "(", "is_int", "(", "$", "key", ")", ")", "{", "$", "results", "[", "]", "=", "$", "item", ";", "continue", ";", "}", "// Non-numeric keys. If we've got the given key in $results already, it means it was merged", "// in from one of the nested arrays and those are meant to overwrite the initial values on collisions -", "// thus we're not going to do anything in that case.", "if", "(", "!", "array_key_exists", "(", "$", "key", ",", "$", "results", ")", ")", "{", "$", "results", "[", "$", "key", "]", "=", "$", "item", ";", "}", "}", "return", "$", "results", ";", "}" ]
Collapses an array of arrays into a single array. Not recursive, ie. only the first dimension of arrays will be collapsed down. Standard array_merge() rules apply - @link http://php.net/manual/en/function.array-merge.php - non-array values with numeric keys will be appended to the resulting array in the order they are given, while non-array values with non-numeric keys will have their keys preserved but the values may be overwritten by the nested arrays being collapsed down if those contain values with the same non-numeric keys. Latter arrays overwrite previous arrays' keys on collisions. @param array $array The array to collapse. @return array The resulting array.
[ "Collapses", "an", "array", "of", "arrays", "into", "a", "single", "array", ".", "Not", "recursive", "ie", ".", "only", "the", "first", "dimension", "of", "arrays", "will", "be", "collapsed", "down", "." ]
503a3dd46fd2216024ab771b6e830be16d36b358
https://github.com/unyx/utils/blob/503a3dd46fd2216024ab771b6e830be16d36b358/Arr.php#L146-L171
3,185
unyx/utils
Arr.php
Arr.contains
public static function contains(array $haystack, $needle, bool $strict = true) { foreach ($haystack as $value) { if ((!$strict && $needle == $value) || $needle === $value) { return true; } if (is_array($value) && static::contains($needle, $value, $strict)) { return true; } } return false; }
php
public static function contains(array $haystack, $needle, bool $strict = true) { foreach ($haystack as $value) { if ((!$strict && $needle == $value) || $needle === $value) { return true; } if (is_array($value) && static::contains($needle, $value, $strict)) { return true; } } return false; }
[ "public", "static", "function", "contains", "(", "array", "$", "haystack", ",", "$", "needle", ",", "bool", "$", "strict", "=", "true", ")", "{", "foreach", "(", "$", "haystack", "as", "$", "value", ")", "{", "if", "(", "(", "!", "$", "strict", "&&", "$", "needle", "==", "$", "value", ")", "||", "$", "needle", "===", "$", "value", ")", "{", "return", "true", ";", "}", "if", "(", "is_array", "(", "$", "value", ")", "&&", "static", "::", "contains", "(", "$", "needle", ",", "$", "value", ",", "$", "strict", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Checks whether the given value is contained within the given array. Equivalent of a recursive in_array. When you are sure you are dealing with a 1-dimensional array, use in_array instead to avoid the overhead. @param array $haystack The array to search in. @param mixed $needle The value to search for. @param bool $strict Whether strict equality matches should be performed on the values. @return bool True when the value was found in the array, false otherwise.
[ "Checks", "whether", "the", "given", "value", "is", "contained", "within", "the", "given", "array", ".", "Equivalent", "of", "a", "recursive", "in_array", ".", "When", "you", "are", "sure", "you", "are", "dealing", "with", "a", "1", "-", "dimensional", "array", "use", "in_array", "instead", "to", "avoid", "the", "overhead", "." ]
503a3dd46fd2216024ab771b6e830be16d36b358
https://github.com/unyx/utils/blob/503a3dd46fd2216024ab771b6e830be16d36b358/Arr.php#L182-L195
3,186
unyx/utils
Arr.php
Arr.delimit
public static function delimit(array $array, string $prepend = '', string $delimiter = null) { // Results holder. $results = []; // Which string delimiter should we use? if (null === $delimiter) { $delimiter = static::$delimiter; } foreach ($array as $key => $value) { if (is_array($value) && !empty($value)) { $results = array_merge($results, static::delimit($value, $prepend.$key.$delimiter)); } else { $results[$prepend.$key] = $value; } } return $results; }
php
public static function delimit(array $array, string $prepend = '', string $delimiter = null) { // Results holder. $results = []; // Which string delimiter should we use? if (null === $delimiter) { $delimiter = static::$delimiter; } foreach ($array as $key => $value) { if (is_array($value) && !empty($value)) { $results = array_merge($results, static::delimit($value, $prepend.$key.$delimiter)); } else { $results[$prepend.$key] = $value; } } return $results; }
[ "public", "static", "function", "delimit", "(", "array", "$", "array", ",", "string", "$", "prepend", "=", "''", ",", "string", "$", "delimiter", "=", "null", ")", "{", "// Results holder.", "$", "results", "=", "[", "]", ";", "// Which string delimiter should we use?", "if", "(", "null", "===", "$", "delimiter", ")", "{", "$", "delimiter", "=", "static", "::", "$", "delimiter", ";", "}", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", "&&", "!", "empty", "(", "$", "value", ")", ")", "{", "$", "results", "=", "array_merge", "(", "$", "results", ",", "static", "::", "delimit", "(", "$", "value", ",", "$", "prepend", ".", "$", "key", ".", "$", "delimiter", ")", ")", ";", "}", "else", "{", "$", "results", "[", "$", "prepend", ".", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "results", ";", "}" ]
Flattens a multi-dimensional array using the given delimiter. @param array $array The initial array. @param string $prepend A string that should be prepended to the keys. @param string $delimiter The delimiter to use when exploding the key into parts. @return array The resulting array.
[ "Flattens", "a", "multi", "-", "dimensional", "array", "using", "the", "given", "delimiter", "." ]
503a3dd46fd2216024ab771b6e830be16d36b358
https://github.com/unyx/utils/blob/503a3dd46fd2216024ab771b6e830be16d36b358/Arr.php#L205-L224
3,187
unyx/utils
Arr.php
Arr.fetch
public static function fetch(array $array, string $key, string $delimiter = null) : array { // Results holder. $results = []; // Which string delimiter should we use? if (null === $delimiter) { $delimiter = static::$delimiter; } foreach (explode($delimiter, $key) as $segment) { $results = []; foreach ($array as $value) { $value = (array) $value; $results[] = $value[$segment]; } $array = array_values($results); } return array_values($results); }
php
public static function fetch(array $array, string $key, string $delimiter = null) : array { // Results holder. $results = []; // Which string delimiter should we use? if (null === $delimiter) { $delimiter = static::$delimiter; } foreach (explode($delimiter, $key) as $segment) { $results = []; foreach ($array as $value) { $value = (array) $value; $results[] = $value[$segment]; } $array = array_values($results); } return array_values($results); }
[ "public", "static", "function", "fetch", "(", "array", "$", "array", ",", "string", "$", "key", ",", "string", "$", "delimiter", "=", "null", ")", ":", "array", "{", "// Results holder.", "$", "results", "=", "[", "]", ";", "// Which string delimiter should we use?", "if", "(", "null", "===", "$", "delimiter", ")", "{", "$", "delimiter", "=", "static", "::", "$", "delimiter", ";", "}", "foreach", "(", "explode", "(", "$", "delimiter", ",", "$", "key", ")", "as", "$", "segment", ")", "{", "$", "results", "=", "[", "]", ";", "foreach", "(", "$", "array", "as", "$", "value", ")", "{", "$", "value", "=", "(", "array", ")", "$", "value", ";", "$", "results", "[", "]", "=", "$", "value", "[", "$", "segment", "]", ";", "}", "$", "array", "=", "array_values", "(", "$", "results", ")", ";", "}", "return", "array_values", "(", "$", "results", ")", ";", "}" ]
Fetches a flattened array of an element nested in the initial array. @param array $array The initial array. @param string $key The string delimited key. @param string $delimiter The delimiter to use when exploding the key into parts. @return array The resulting array.
[ "Fetches", "a", "flattened", "array", "of", "an", "element", "nested", "in", "the", "initial", "array", "." ]
503a3dd46fd2216024ab771b6e830be16d36b358
https://github.com/unyx/utils/blob/503a3dd46fd2216024ab771b6e830be16d36b358/Arr.php#L273-L296
3,188
unyx/utils
Arr.php
Arr.find
public static function find(array $array, callable $callback, $default = null) { foreach ($array as $key => $value) { if ($callback($value, $key)) { return $value; } } return $default; }
php
public static function find(array $array, callable $callback, $default = null) { foreach ($array as $key => $value) { if ($callback($value, $key)) { return $value; } } return $default; }
[ "public", "static", "function", "find", "(", "array", "$", "array", ",", "callable", "$", "callback", ",", "$", "default", "=", "null", ")", "{", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "callback", "(", "$", "value", ",", "$", "key", ")", ")", "{", "return", "$", "value", ";", "}", "}", "return", "$", "default", ";", "}" ]
Returns the first value which passes the given truth test. Aliases: - @see Arr::detect() @param array $array The array to traverse. @param callable $callback The truth test the value should pass. @param mixed $default The default value to be returned if none of the elements passes the test. @return mixed
[ "Returns", "the", "first", "value", "which", "passes", "the", "given", "truth", "test", "." ]
503a3dd46fd2216024ab771b6e830be16d36b358
https://github.com/unyx/utils/blob/503a3dd46fd2216024ab771b6e830be16d36b358/Arr.php#L309-L318
3,189
unyx/utils
Arr.php
Arr.get
public static function get(array $array, $key = null, $default = null, string $delimiter = null) { // Make loops easier for the end-user - return the initial array if the key is null instead of forcing // a valid value. if (!isset($key)) { return $array; } // Which string delimiter should we use? if (!isset($delimiter)) { $delimiter = static::$delimiter; } // If the key is string delimited, we need to explode it into an array of segments. $segments = is_array($key) ? $key : explode($delimiter, $key); // One dimension at a time. while ($segment = array_shift($segments)) { // If the current segment is a wildcard, make sure the it points to an array // and pluck the remaining segments from it. if ($segment === '*') { return is_array($array) ? static::pluck($array, $segments, $delimiter) : $default; } // Note: isset() is the cheapest condition to check for while being rather probable at the same time, // thus the seemingly unintuitive condition ordering. if (isset($array->{$segment})) { $array = $array->{$segment}; } elseif (is_array($array) && array_key_exists($segment, $array)) { $array = $array[$segment]; } else { return $default; } } return $array; }
php
public static function get(array $array, $key = null, $default = null, string $delimiter = null) { // Make loops easier for the end-user - return the initial array if the key is null instead of forcing // a valid value. if (!isset($key)) { return $array; } // Which string delimiter should we use? if (!isset($delimiter)) { $delimiter = static::$delimiter; } // If the key is string delimited, we need to explode it into an array of segments. $segments = is_array($key) ? $key : explode($delimiter, $key); // One dimension at a time. while ($segment = array_shift($segments)) { // If the current segment is a wildcard, make sure the it points to an array // and pluck the remaining segments from it. if ($segment === '*') { return is_array($array) ? static::pluck($array, $segments, $delimiter) : $default; } // Note: isset() is the cheapest condition to check for while being rather probable at the same time, // thus the seemingly unintuitive condition ordering. if (isset($array->{$segment})) { $array = $array->{$segment}; } elseif (is_array($array) && array_key_exists($segment, $array)) { $array = $array[$segment]; } else { return $default; } } return $array; }
[ "public", "static", "function", "get", "(", "array", "$", "array", ",", "$", "key", "=", "null", ",", "$", "default", "=", "null", ",", "string", "$", "delimiter", "=", "null", ")", "{", "// Make loops easier for the end-user - return the initial array if the key is null instead of forcing", "// a valid value.", "if", "(", "!", "isset", "(", "$", "key", ")", ")", "{", "return", "$", "array", ";", "}", "// Which string delimiter should we use?", "if", "(", "!", "isset", "(", "$", "delimiter", ")", ")", "{", "$", "delimiter", "=", "static", "::", "$", "delimiter", ";", "}", "// If the key is string delimited, we need to explode it into an array of segments.", "$", "segments", "=", "is_array", "(", "$", "key", ")", "?", "$", "key", ":", "explode", "(", "$", "delimiter", ",", "$", "key", ")", ";", "// One dimension at a time.", "while", "(", "$", "segment", "=", "array_shift", "(", "$", "segments", ")", ")", "{", "// If the current segment is a wildcard, make sure the it points to an array", "// and pluck the remaining segments from it.", "if", "(", "$", "segment", "===", "'*'", ")", "{", "return", "is_array", "(", "$", "array", ")", "?", "static", "::", "pluck", "(", "$", "array", ",", "$", "segments", ",", "$", "delimiter", ")", ":", "$", "default", ";", "}", "// Note: isset() is the cheapest condition to check for while being rather probable at the same time,", "// thus the seemingly unintuitive condition ordering.", "if", "(", "isset", "(", "$", "array", "->", "{", "$", "segment", "}", ")", ")", "{", "$", "array", "=", "$", "array", "->", "{", "$", "segment", "}", ";", "}", "elseif", "(", "is_array", "(", "$", "array", ")", "&&", "array_key_exists", "(", "$", "segment", ",", "$", "array", ")", ")", "{", "$", "array", "=", "$", "array", "[", "$", "segment", "]", ";", "}", "else", "{", "return", "$", "default", ";", "}", "}", "return", "$", "array", ";", "}" ]
Returns a string delimited key from an array, with a default value if the given key does not exist. If null is given instead of a key, the whole initial array will be returned. Note: Nested objects will be accessed as if they were arrays, eg. if "some.nested.object" is an object, then looking for "some.nested.object.property" will be handled just as a normal array would. @param array $array The array to search in. @param string|array $key The string delimited key or a chain (array) of nested keys pointing to the desired key. @param mixed $default The default value. @param string $delimiter The delimiter to use when exploding the key into parts. @return mixed
[ "Returns", "a", "string", "delimited", "key", "from", "an", "array", "with", "a", "default", "value", "if", "the", "given", "key", "does", "not", "exist", ".", "If", "null", "is", "given", "instead", "of", "a", "key", "the", "whole", "initial", "array", "will", "be", "returned", "." ]
503a3dd46fd2216024ab771b6e830be16d36b358
https://github.com/unyx/utils/blob/503a3dd46fd2216024ab771b6e830be16d36b358/Arr.php#L398-L435
3,190
unyx/utils
Arr.php
Arr.has
public static function has(array $array, string $key, string $delimiter = null) { // Which string delimiter should we use? if (null === $delimiter) { $delimiter = static::$delimiter; } foreach (explode($delimiter, $key) as $segment) { if (!is_array($array) || !array_key_exists($segment, $array)) { return false; } $array = $array[$segment]; } return true; }
php
public static function has(array $array, string $key, string $delimiter = null) { // Which string delimiter should we use? if (null === $delimiter) { $delimiter = static::$delimiter; } foreach (explode($delimiter, $key) as $segment) { if (!is_array($array) || !array_key_exists($segment, $array)) { return false; } $array = $array[$segment]; } return true; }
[ "public", "static", "function", "has", "(", "array", "$", "array", ",", "string", "$", "key", ",", "string", "$", "delimiter", "=", "null", ")", "{", "// Which string delimiter should we use?", "if", "(", "null", "===", "$", "delimiter", ")", "{", "$", "delimiter", "=", "static", "::", "$", "delimiter", ";", "}", "foreach", "(", "explode", "(", "$", "delimiter", ",", "$", "key", ")", "as", "$", "segment", ")", "{", "if", "(", "!", "is_array", "(", "$", "array", ")", "||", "!", "array_key_exists", "(", "$", "segment", ",", "$", "array", ")", ")", "{", "return", "false", ";", "}", "$", "array", "=", "$", "array", "[", "$", "segment", "]", ";", "}", "return", "true", ";", "}" ]
Checks whether the given string delimited key exists in the array. Note: Nested objects will not be accessed as if they were arrays, ie. if "some.nested.object" is an object, not an array, then looking for "some.nested.object.key" will always return false. @param array $array The array to search in. @param string $key The string delimited key. @param string $delimiter The delimiter to use when exploding the key into parts. @return bool True when the given key exists, false otherwise.
[ "Checks", "whether", "the", "given", "string", "delimited", "key", "exists", "in", "the", "array", "." ]
503a3dd46fd2216024ab771b6e830be16d36b358
https://github.com/unyx/utils/blob/503a3dd46fd2216024ab771b6e830be16d36b358/Arr.php#L448-L464
3,191
unyx/utils
Arr.php
Arr.pull
public static function pull(&$array, string $key, string $delimiter = null) { $value = static::get($array, $key, null, $delimiter); static::remove($array, $key, $delimiter); return $value; }
php
public static function pull(&$array, string $key, string $delimiter = null) { $value = static::get($array, $key, null, $delimiter); static::remove($array, $key, $delimiter); return $value; }
[ "public", "static", "function", "pull", "(", "&", "$", "array", ",", "string", "$", "key", ",", "string", "$", "delimiter", "=", "null", ")", "{", "$", "value", "=", "static", "::", "get", "(", "$", "array", ",", "$", "key", ",", "null", ",", "$", "delimiter", ")", ";", "static", "::", "remove", "(", "$", "array", ",", "$", "key", ",", "$", "delimiter", ")", ";", "return", "$", "value", ";", "}" ]
Returns the value for a string delimited key from an array and then removes it. @param array $array The array to search in. @param string $key The string delimited key. @param string $delimiter The delimiter to use when exploding the key into parts. @return mixed
[ "Returns", "the", "value", "for", "a", "string", "delimited", "key", "from", "an", "array", "and", "then", "removes", "it", "." ]
503a3dd46fd2216024ab771b6e830be16d36b358
https://github.com/unyx/utils/blob/503a3dd46fd2216024ab771b6e830be16d36b358/Arr.php#L740-L747
3,192
unyx/utils
Arr.php
Arr.remove
public static function remove(array& $array, string $key, string $delimiter = null) { // Which string delimiter should we use? if (!isset($delimiter)) { $delimiter = static::$delimiter; } // Explode the key according to that delimiter. $keys = explode($delimiter, $key); while ($key = array_shift($keys)) { if (!isset($array[$key]) || !is_array($array[$key])) { return; } $array =& $array[$key]; } unset($array[array_shift($keys)]); }
php
public static function remove(array& $array, string $key, string $delimiter = null) { // Which string delimiter should we use? if (!isset($delimiter)) { $delimiter = static::$delimiter; } // Explode the key according to that delimiter. $keys = explode($delimiter, $key); while ($key = array_shift($keys)) { if (!isset($array[$key]) || !is_array($array[$key])) { return; } $array =& $array[$key]; } unset($array[array_shift($keys)]); }
[ "public", "static", "function", "remove", "(", "array", "&", "$", "array", ",", "string", "$", "key", ",", "string", "$", "delimiter", "=", "null", ")", "{", "// Which string delimiter should we use?", "if", "(", "!", "isset", "(", "$", "delimiter", ")", ")", "{", "$", "delimiter", "=", "static", "::", "$", "delimiter", ";", "}", "// Explode the key according to that delimiter.", "$", "keys", "=", "explode", "(", "$", "delimiter", ",", "$", "key", ")", ";", "while", "(", "$", "key", "=", "array_shift", "(", "$", "keys", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "array", "[", "$", "key", "]", ")", "||", "!", "is_array", "(", "$", "array", "[", "$", "key", "]", ")", ")", "{", "return", ";", "}", "$", "array", "=", "&", "$", "array", "[", "$", "key", "]", ";", "}", "unset", "(", "$", "array", "[", "array_shift", "(", "$", "keys", ")", "]", ")", ";", "}" ]
Removes a string delimited key from the given array. @param array& $array The array to search in. @param string $key The string delimited key. @param string $delimiter The delimiter to use when exploding the key into parts.
[ "Removes", "a", "string", "delimited", "key", "from", "the", "given", "array", "." ]
503a3dd46fd2216024ab771b6e830be16d36b358
https://github.com/unyx/utils/blob/503a3dd46fd2216024ab771b6e830be16d36b358/Arr.php#L756-L775
3,193
Messier-1001/Messier.HttpClient
src/Client.php
Client._sendRequest
protected function _sendRequest( array $parameters ) { $this->_curlInfo = []; // Merge defined parameters with default parameters $parameters = array_merge( static::DEFAULT_REQUEST_PARAMS, $parameters ); // close existing curl handle if defined $this->_closeCurl(); // Init the curl handle $this->_initCurl( $parameters ); // If output should be redirected to a file, set the option $toFilePointer = null; if ( isset( $parameters[ 'toFile' ] ) ) { $toFilePointer = @\fopen( $parameters[ 'toFile' ], 'wb' ); if ( ! $toFilePointer ) { ( $this->_onError )( 'HTTPClient can not open file "' . $parameters[ 'toFile' ] . '" for writing!' ); return false; } \curl_setopt( $this->_curlHandle, CURLOPT_FILE, $toFilePointer ); } // Do the HTTP request while success or error do { $response = \curl_exec( $this->_curlHandle ); } while ( false === $response && 0 !== --$parameters['attemptsMax'] && false !== \sleep( $parameters[ 'attemptsDelay' ] ) ); // Close to file pointer if defined if ( null !== $toFilePointer ) { \fclose( $toFilePointer ); // delete the to file if no valid response exists if ( false === $response ) { \unlink( $parameters[ 'toFile' ] ); } } $error = @\curl_error( $this->_curlHandle ); $this->_curlInfo = @\curl_getinfo( $this->_curlHandle ); if ( ! empty( $error ) ) { ( $this->_onError )( $error ); return false; } if ( false === $response ) { ( $this->_onError )( 'HTTPClient can not get a response from "' . $parameters[ 'url' ] . '"!' ); return false; } // Saving response content into lastpageFile if ( null !== $this->_lastResponseToFile ) { \file_put_contents( $this->_lastResponseToFile, $response ); } return $response; }
php
protected function _sendRequest( array $parameters ) { $this->_curlInfo = []; // Merge defined parameters with default parameters $parameters = array_merge( static::DEFAULT_REQUEST_PARAMS, $parameters ); // close existing curl handle if defined $this->_closeCurl(); // Init the curl handle $this->_initCurl( $parameters ); // If output should be redirected to a file, set the option $toFilePointer = null; if ( isset( $parameters[ 'toFile' ] ) ) { $toFilePointer = @\fopen( $parameters[ 'toFile' ], 'wb' ); if ( ! $toFilePointer ) { ( $this->_onError )( 'HTTPClient can not open file "' . $parameters[ 'toFile' ] . '" for writing!' ); return false; } \curl_setopt( $this->_curlHandle, CURLOPT_FILE, $toFilePointer ); } // Do the HTTP request while success or error do { $response = \curl_exec( $this->_curlHandle ); } while ( false === $response && 0 !== --$parameters['attemptsMax'] && false !== \sleep( $parameters[ 'attemptsDelay' ] ) ); // Close to file pointer if defined if ( null !== $toFilePointer ) { \fclose( $toFilePointer ); // delete the to file if no valid response exists if ( false === $response ) { \unlink( $parameters[ 'toFile' ] ); } } $error = @\curl_error( $this->_curlHandle ); $this->_curlInfo = @\curl_getinfo( $this->_curlHandle ); if ( ! empty( $error ) ) { ( $this->_onError )( $error ); return false; } if ( false === $response ) { ( $this->_onError )( 'HTTPClient can not get a response from "' . $parameters[ 'url' ] . '"!' ); return false; } // Saving response content into lastpageFile if ( null !== $this->_lastResponseToFile ) { \file_put_contents( $this->_lastResponseToFile, $response ); } return $response; }
[ "protected", "function", "_sendRequest", "(", "array", "$", "parameters", ")", "{", "$", "this", "->", "_curlInfo", "=", "[", "]", ";", "// Merge defined parameters with default parameters", "$", "parameters", "=", "array_merge", "(", "static", "::", "DEFAULT_REQUEST_PARAMS", ",", "$", "parameters", ")", ";", "// close existing curl handle if defined", "$", "this", "->", "_closeCurl", "(", ")", ";", "// Init the curl handle", "$", "this", "->", "_initCurl", "(", "$", "parameters", ")", ";", "// If output should be redirected to a file, set the option", "$", "toFilePointer", "=", "null", ";", "if", "(", "isset", "(", "$", "parameters", "[", "'toFile'", "]", ")", ")", "{", "$", "toFilePointer", "=", "@", "\\", "fopen", "(", "$", "parameters", "[", "'toFile'", "]", ",", "'wb'", ")", ";", "if", "(", "!", "$", "toFilePointer", ")", "{", "(", "$", "this", "->", "_onError", ")", "(", "'HTTPClient can not open file \"'", ".", "$", "parameters", "[", "'toFile'", "]", ".", "'\" for writing!'", ")", ";", "return", "false", ";", "}", "\\", "curl_setopt", "(", "$", "this", "->", "_curlHandle", ",", "CURLOPT_FILE", ",", "$", "toFilePointer", ")", ";", "}", "// Do the HTTP request while success or error", "do", "{", "$", "response", "=", "\\", "curl_exec", "(", "$", "this", "->", "_curlHandle", ")", ";", "}", "while", "(", "false", "===", "$", "response", "&&", "0", "!==", "--", "$", "parameters", "[", "'attemptsMax'", "]", "&&", "false", "!==", "\\", "sleep", "(", "$", "parameters", "[", "'attemptsDelay'", "]", ")", ")", ";", "// Close to file pointer if defined", "if", "(", "null", "!==", "$", "toFilePointer", ")", "{", "\\", "fclose", "(", "$", "toFilePointer", ")", ";", "// delete the to file if no valid response exists", "if", "(", "false", "===", "$", "response", ")", "{", "\\", "unlink", "(", "$", "parameters", "[", "'toFile'", "]", ")", ";", "}", "}", "$", "error", "=", "@", "\\", "curl_error", "(", "$", "this", "->", "_curlHandle", ")", ";", "$", "this", "->", "_curlInfo", "=", "@", "\\", "curl_getinfo", "(", "$", "this", "->", "_curlHandle", ")", ";", "if", "(", "!", "empty", "(", "$", "error", ")", ")", "{", "(", "$", "this", "->", "_onError", ")", "(", "$", "error", ")", ";", "return", "false", ";", "}", "if", "(", "false", "===", "$", "response", ")", "{", "(", "$", "this", "->", "_onError", ")", "(", "'HTTPClient can not get a response from \"'", ".", "$", "parameters", "[", "'url'", "]", ".", "'\"!'", ")", ";", "return", "false", ";", "}", "// Saving response content into lastpageFile", "if", "(", "null", "!==", "$", "this", "->", "_lastResponseToFile", ")", "{", "\\", "file_put_contents", "(", "$", "this", "->", "_lastResponseToFile", ",", "$", "response", ")", ";", "}", "return", "$", "response", ";", "}" ]
Runs the request and return the response. @param array $parameters The request parameters. @return string|false Returns the response in the usual case, TRUE if result is a file and FALSE on error.
[ "Runs", "the", "request", "and", "return", "the", "response", "." ]
27b8edd283fe7e76a25c169668ca41c11f83911c
https://github.com/Messier-1001/Messier.HttpClient/blob/27b8edd283fe7e76a25c169668ca41c11f83911c/src/Client.php#L186-L260
3,194
Messier-1001/Messier.HttpClient
src/Client.php
Client.getCookies
public final function getCookies() : array { if ( ! $this->getCookieFile() ) { return []; } unset( $this->_curlHandle ); $text = \file_get_contents( $this->getCookieFile() ); $cookies = []; foreach ( \explode( "\n", $text ) as $line ) { $parts = explode( "\t", $line ); if ( 7 === \count( $parts ) ) { $cookies[ $parts[ 5 ] ] = $parts[ 6 ]; } } return $cookies; }
php
public final function getCookies() : array { if ( ! $this->getCookieFile() ) { return []; } unset( $this->_curlHandle ); $text = \file_get_contents( $this->getCookieFile() ); $cookies = []; foreach ( \explode( "\n", $text ) as $line ) { $parts = explode( "\t", $line ); if ( 7 === \count( $parts ) ) { $cookies[ $parts[ 5 ] ] = $parts[ 6 ]; } } return $cookies; }
[ "public", "final", "function", "getCookies", "(", ")", ":", "array", "{", "if", "(", "!", "$", "this", "->", "getCookieFile", "(", ")", ")", "{", "return", "[", "]", ";", "}", "unset", "(", "$", "this", "->", "_curlHandle", ")", ";", "$", "text", "=", "\\", "file_get_contents", "(", "$", "this", "->", "getCookieFile", "(", ")", ")", ";", "$", "cookies", "=", "[", "]", ";", "foreach", "(", "\\", "explode", "(", "\"\\n\"", ",", "$", "text", ")", "as", "$", "line", ")", "{", "$", "parts", "=", "explode", "(", "\"\\t\"", ",", "$", "line", ")", ";", "if", "(", "7", "===", "\\", "count", "(", "$", "parts", ")", ")", "{", "$", "cookies", "[", "$", "parts", "[", "5", "]", "]", "=", "$", "parts", "[", "6", "]", ";", "}", "}", "return", "$", "cookies", ";", "}" ]
Gets the current cookies. @return array
[ "Gets", "the", "current", "cookies", "." ]
27b8edd283fe7e76a25c169668ca41c11f83911c
https://github.com/Messier-1001/Messier.HttpClient/blob/27b8edd283fe7e76a25c169668ca41c11f83911c/src/Client.php#L425-L449
3,195
Messier-1001/Messier.HttpClient
src/Client.php
Client.setLastResponseToFile
public function setLastResponseToFile( ?string $lastResponseToFile ) : Client { $this->_lastResponseToFile = $lastResponseToFile ?? ''; if ( '' === \trim( $this->_lastResponseToFile ) ) { $this->_lastResponseToFile = null; } return $this; }
php
public function setLastResponseToFile( ?string $lastResponseToFile ) : Client { $this->_lastResponseToFile = $lastResponseToFile ?? ''; if ( '' === \trim( $this->_lastResponseToFile ) ) { $this->_lastResponseToFile = null; } return $this; }
[ "public", "function", "setLastResponseToFile", "(", "?", "string", "$", "lastResponseToFile", ")", ":", "Client", "{", "$", "this", "->", "_lastResponseToFile", "=", "$", "lastResponseToFile", "??", "''", ";", "if", "(", "''", "===", "\\", "trim", "(", "$", "this", "->", "_lastResponseToFile", ")", ")", "{", "$", "this", "->", "_lastResponseToFile", "=", "null", ";", "}", "return", "$", "this", ";", "}" ]
If here a valid file path is defined, the last response is stored inside the file. @param null|string $lastResponseToFile @return Client
[ "If", "here", "a", "valid", "file", "path", "is", "defined", "the", "last", "response", "is", "stored", "inside", "the", "file", "." ]
27b8edd283fe7e76a25c169668ca41c11f83911c
https://github.com/Messier-1001/Messier.HttpClient/blob/27b8edd283fe7e76a25c169668ca41c11f83911c/src/Client.php#L526-L535
3,196
Messier-1001/Messier.HttpClient
src/Client.php
Client.sendHead
public function sendHead( string $url, array $parameters = [], array $options = [] ) { // The request URL $options[ 'url' ] = $this->_buildUrl( $url, $parameters ); // Getting the headers $options[ 'header' ] = true; // Get no body $options[ 'nobody' ] = true; return $this->_sendRequest( $options ); }
php
public function sendHead( string $url, array $parameters = [], array $options = [] ) { // The request URL $options[ 'url' ] = $this->_buildUrl( $url, $parameters ); // Getting the headers $options[ 'header' ] = true; // Get no body $options[ 'nobody' ] = true; return $this->_sendRequest( $options ); }
[ "public", "function", "sendHead", "(", "string", "$", "url", ",", "array", "$", "parameters", "=", "[", "]", ",", "array", "$", "options", "=", "[", "]", ")", "{", "// The request URL", "$", "options", "[", "'url'", "]", "=", "$", "this", "->", "_buildUrl", "(", "$", "url", ",", "$", "parameters", ")", ";", "// Getting the headers", "$", "options", "[", "'header'", "]", "=", "true", ";", "// Get no body", "$", "options", "[", "'nobody'", "]", "=", "true", ";", "return", "$", "this", "->", "_sendRequest", "(", "$", "options", ")", ";", "}" ]
Executes a HEAD HTTP request to get all response headers. If no external error handler is defined, on error here an ClientException is thrown @param string $url The request url. @param array $parameters Optional GET URL parameters. @param array $options Known options are: headers, referer, timeout, toFile, attemptsMax, attemptsDelay @return string|boolean Returns a string on success or FALSE on error
[ "Executes", "a", "HEAD", "HTTP", "request", "to", "get", "all", "response", "headers", "." ]
27b8edd283fe7e76a25c169668ca41c11f83911c
https://github.com/Messier-1001/Messier.HttpClient/blob/27b8edd283fe7e76a25c169668ca41c11f83911c/src/Client.php#L567-L579
3,197
Messier-1001/Messier.HttpClient
src/Client.php
Client.sendGet
public function sendGet( string $url, array $parameters = [], array $options = [] ) { // The request URL $options[ 'url' ] = $this->_buildUrl( $url, $parameters ); return $this->_sendRequest( $options ); }
php
public function sendGet( string $url, array $parameters = [], array $options = [] ) { // The request URL $options[ 'url' ] = $this->_buildUrl( $url, $parameters ); return $this->_sendRequest( $options ); }
[ "public", "function", "sendGet", "(", "string", "$", "url", ",", "array", "$", "parameters", "=", "[", "]", ",", "array", "$", "options", "=", "[", "]", ")", "{", "// The request URL", "$", "options", "[", "'url'", "]", "=", "$", "this", "->", "_buildUrl", "(", "$", "url", ",", "$", "parameters", ")", ";", "return", "$", "this", "->", "_sendRequest", "(", "$", "options", ")", ";", "}" ]
Executes GET HTTP request. If no external error handler is defined, on error here an ClientException is thrown @param string $url The request url. @param array $parameters Optional GET URL parameters. @param array $options Known options are: headers, referer, timeout, toFile, attemptsMax, attemptsDelay @return string|boolean Returns a string on success or FALSE on error
[ "Executes", "GET", "HTTP", "request", "." ]
27b8edd283fe7e76a25c169668ca41c11f83911c
https://github.com/Messier-1001/Messier.HttpClient/blob/27b8edd283fe7e76a25c169668ca41c11f83911c/src/Client.php#L591-L599
3,198
Messier-1001/Messier.HttpClient
src/Client.php
Client.sendPost
public function sendPost( string $url, array $data = [], array $options = [] ) { $options[ 'url' ] = $this->_buildUrl( $url ); $options[ 'post' ] = $data; return $this->_sendRequest( $options ); }
php
public function sendPost( string $url, array $data = [], array $options = [] ) { $options[ 'url' ] = $this->_buildUrl( $url ); $options[ 'post' ] = $data; return $this->_sendRequest( $options ); }
[ "public", "function", "sendPost", "(", "string", "$", "url", ",", "array", "$", "data", "=", "[", "]", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "options", "[", "'url'", "]", "=", "$", "this", "->", "_buildUrl", "(", "$", "url", ")", ";", "$", "options", "[", "'post'", "]", "=", "$", "data", ";", "return", "$", "this", "->", "_sendRequest", "(", "$", "options", ")", ";", "}" ]
Executes a POST HTTP request. If no external error handler is defined, on error here an ClientException is thrown @param string $url The request url. @param array $data The POST data array. @param array $options Known options are: headers, referer, timeout, toFile, attemptsMax, attemptsDelay @return string|boolean Returns a string on success, TRUE on successful file transfer or FALSE on error
[ "Executes", "a", "POST", "HTTP", "request", "." ]
27b8edd283fe7e76a25c169668ca41c11f83911c
https://github.com/Messier-1001/Messier.HttpClient/blob/27b8edd283fe7e76a25c169668ca41c11f83911c/src/Client.php#L611-L619
3,199
Messier-1001/Messier.HttpClient
src/Client.php
Client.sendDownload
public function sendDownload( string $url, string $destinationFile, array $options = [] ) { $options[ 'url' ] = $this->_buildUrl( $url ); $options[ 'toFile' ] = $destinationFile; return $this->_sendRequest( $options ); }
php
public function sendDownload( string $url, string $destinationFile, array $options = [] ) { $options[ 'url' ] = $this->_buildUrl( $url ); $options[ 'toFile' ] = $destinationFile; return $this->_sendRequest( $options ); }
[ "public", "function", "sendDownload", "(", "string", "$", "url", ",", "string", "$", "destinationFile", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "options", "[", "'url'", "]", "=", "$", "this", "->", "_buildUrl", "(", "$", "url", ")", ";", "$", "options", "[", "'toFile'", "]", "=", "$", "destinationFile", ";", "return", "$", "this", "->", "_sendRequest", "(", "$", "options", ")", ";", "}" ]
Downloads file to specified destination file. If no external error handler is defined, on error here an ClientException is thrown @param string $url The request url. @param string $destinationFile file destination. @param array $options Known options are: headers, referer, timeout, attemptsMax, attemptsDelay @return boolean Return TRUE on success, FALSE otherwise
[ "Downloads", "file", "to", "specified", "destination", "file", "." ]
27b8edd283fe7e76a25c169668ca41c11f83911c
https://github.com/Messier-1001/Messier.HttpClient/blob/27b8edd283fe7e76a25c169668ca41c11f83911c/src/Client.php#L632-L640