repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
ezra-obiwale/dSCore
src/Core/AInjector.php
AInjector.checkInjections
final public function checkInjections($className) { if (is_array($this->inject())) { foreach ($this->inject() as $classArray) { if (!is_array($classArray) || (is_array($classArray) && !isset($classArray['class'])) || (is_array($classArray) && !class_exists($classArray['class']))) continue; if ($classArray['class'] === $className) return false; if (!$this->canInject($classArray, $className)) return false; } } return true; }
php
final public function checkInjections($className) { if (is_array($this->inject())) { foreach ($this->inject() as $classArray) { if (!is_array($classArray) || (is_array($classArray) && !isset($classArray['class'])) || (is_array($classArray) && !class_exists($classArray['class']))) continue; if ($classArray['class'] === $className) return false; if (!$this->canInject($classArray, $className)) return false; } } return true; }
[ "final", "public", "function", "checkInjections", "(", "$", "className", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "inject", "(", ")", ")", ")", "{", "foreach", "(", "$", "this", "->", "inject", "(", ")", "as", "$", "classArray", ")", "{", "if", "(", "!", "is_array", "(", "$", "classArray", ")", "||", "(", "is_array", "(", "$", "classArray", ")", "&&", "!", "isset", "(", "$", "classArray", "[", "'class'", "]", ")", ")", "||", "(", "is_array", "(", "$", "classArray", ")", "&&", "!", "class_exists", "(", "$", "classArray", "[", "'class'", "]", ")", ")", ")", "continue", ";", "if", "(", "$", "classArray", "[", "'class'", "]", "===", "$", "className", ")", "return", "false", ";", "if", "(", "!", "$", "this", "->", "canInject", "(", "$", "classArray", ",", "$", "className", ")", ")", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Checks the injection for cyclic dependencies @param string $className @return boolean
[ "Checks", "the", "injection", "for", "cyclic", "dependencies" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/AInjector.php#L77-L94
train
ezra-obiwale/dSCore
src/Core/AInjector.php
AInjector.canInject
private function canInject(array $classArray, $className = null) { $className = ($className === null) ? $this->getClass() : $className; if (!self::addInjecting($className)) { return false; } $refClass = new \ReflectionClass($classArray['class']); if ($refClass->isSubclassOf('DScribe\Core\AInjector')) { $class = new $classArray['class'](); if (!$class->checkInjections($className)) return false; } self::removeInjecting($className); return (isset($classArray['params']) && $refClass->getConstructor()) ? $refClass->newInstanceArgs($classArray['params']) : $refClass->newInstance(); }
php
private function canInject(array $classArray, $className = null) { $className = ($className === null) ? $this->getClass() : $className; if (!self::addInjecting($className)) { return false; } $refClass = new \ReflectionClass($classArray['class']); if ($refClass->isSubclassOf('DScribe\Core\AInjector')) { $class = new $classArray['class'](); if (!$class->checkInjections($className)) return false; } self::removeInjecting($className); return (isset($classArray['params']) && $refClass->getConstructor()) ? $refClass->newInstanceArgs($classArray['params']) : $refClass->newInstance(); }
[ "private", "function", "canInject", "(", "array", "$", "classArray", ",", "$", "className", "=", "null", ")", "{", "$", "className", "=", "(", "$", "className", "===", "null", ")", "?", "$", "this", "->", "getClass", "(", ")", ":", "$", "className", ";", "if", "(", "!", "self", "::", "addInjecting", "(", "$", "className", ")", ")", "{", "return", "false", ";", "}", "$", "refClass", "=", "new", "\\", "ReflectionClass", "(", "$", "classArray", "[", "'class'", "]", ")", ";", "if", "(", "$", "refClass", "->", "isSubclassOf", "(", "'DScribe\\Core\\AInjector'", ")", ")", "{", "$", "class", "=", "new", "$", "classArray", "[", "'class'", "]", "(", ")", ";", "if", "(", "!", "$", "class", "->", "checkInjections", "(", "$", "className", ")", ")", "return", "false", ";", "}", "self", "::", "removeInjecting", "(", "$", "className", ")", ";", "return", "(", "isset", "(", "$", "classArray", "[", "'params'", "]", ")", "&&", "$", "refClass", "->", "getConstructor", "(", ")", ")", "?", "$", "refClass", "->", "newInstanceArgs", "(", "$", "classArray", "[", "'params'", "]", ")", ":", "$", "refClass", "->", "newInstance", "(", ")", ";", "}" ]
Checks if the class can be injected @param array $classArray @param string|null $className @return boolean
[ "Checks", "if", "the", "class", "can", "be", "injected" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/AInjector.php#L114-L134
train
ezra-obiwale/dSCore
src/Core/AInjector.php
AInjector.doInject
private function doInject() { foreach ($this->prepareInject() as $alias => $classArray) { if (!is_array($classArray)) { throw new \Exception('Injection failed. Values of injection array in class "' . $this->getClass() . '" must be an array'); } if (!isset($classArray['class'])) { throw new \Exception('Injection failed. Class not specified for injection for alias "' . $alias . '" in class "' . $this->getClass() . '"'); } if (!class_exists($classArray['class'])) { throw new \Exception('Injection failed. Class "' . $classArray['class'] . '" with alias "' . $alias . '" does not exist in class "' . $this->getClass() . '"'); } if (isset($classArray['params']) && !is_array($classArray['params'])) { $classArray['params'] = array($classArray['params']); } if (FALSE === ($class = $this->canInject($classArray))) { throw new \Exception('Injection failed. Unending injection cycle detected for class "' . $classArray['class'] . '" with alias "' . $alias . '" in "' . $this->getClass() . '"' . $this->parseInjected()); } $this->$alias = $class; } }
php
private function doInject() { foreach ($this->prepareInject() as $alias => $classArray) { if (!is_array($classArray)) { throw new \Exception('Injection failed. Values of injection array in class "' . $this->getClass() . '" must be an array'); } if (!isset($classArray['class'])) { throw new \Exception('Injection failed. Class not specified for injection for alias "' . $alias . '" in class "' . $this->getClass() . '"'); } if (!class_exists($classArray['class'])) { throw new \Exception('Injection failed. Class "' . $classArray['class'] . '" with alias "' . $alias . '" does not exist in class "' . $this->getClass() . '"'); } if (isset($classArray['params']) && !is_array($classArray['params'])) { $classArray['params'] = array($classArray['params']); } if (FALSE === ($class = $this->canInject($classArray))) { throw new \Exception('Injection failed. Unending injection cycle detected for class "' . $classArray['class'] . '" with alias "' . $alias . '" in "' . $this->getClass() . '"' . $this->parseInjected()); } $this->$alias = $class; } }
[ "private", "function", "doInject", "(", ")", "{", "foreach", "(", "$", "this", "->", "prepareInject", "(", ")", "as", "$", "alias", "=>", "$", "classArray", ")", "{", "if", "(", "!", "is_array", "(", "$", "classArray", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Injection failed. Values of injection array in class \"'", ".", "$", "this", "->", "getClass", "(", ")", ".", "'\" must be an array'", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "classArray", "[", "'class'", "]", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Injection failed. Class not specified for injection for alias \"'", ".", "$", "alias", ".", "'\" in class \"'", ".", "$", "this", "->", "getClass", "(", ")", ".", "'\"'", ")", ";", "}", "if", "(", "!", "class_exists", "(", "$", "classArray", "[", "'class'", "]", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Injection failed. Class \"'", ".", "$", "classArray", "[", "'class'", "]", ".", "'\" with alias \"'", ".", "$", "alias", ".", "'\" does not exist in class \"'", ".", "$", "this", "->", "getClass", "(", ")", ".", "'\"'", ")", ";", "}", "if", "(", "isset", "(", "$", "classArray", "[", "'params'", "]", ")", "&&", "!", "is_array", "(", "$", "classArray", "[", "'params'", "]", ")", ")", "{", "$", "classArray", "[", "'params'", "]", "=", "array", "(", "$", "classArray", "[", "'params'", "]", ")", ";", "}", "if", "(", "FALSE", "===", "(", "$", "class", "=", "$", "this", "->", "canInject", "(", "$", "classArray", ")", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Injection failed. Unending injection cycle detected for class \"'", ".", "$", "classArray", "[", "'class'", "]", ".", "'\" with alias \"'", ".", "$", "alias", ".", "'\" in \"'", ".", "$", "this", "->", "getClass", "(", ")", ".", "'\"'", ".", "$", "this", "->", "parseInjected", "(", ")", ")", ";", "}", "$", "this", "->", "$", "alias", "=", "$", "class", ";", "}", "}" ]
Performs the actual injection @throws \Exception
[ "Performs", "the", "actual", "injection" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Core/AInjector.php#L140-L168
train
Danack/Weaver
src/Weaver/CompositeWeaveGenerator.php
CompositeWeaveGenerator.addPropertiesAndConstantsForContainer
private function addPropertiesAndConstantsForContainer() { $this->addPropertiesAndConstantsFromReflection($this->containerClassReflection); foreach ($this->compositeClassReflectionArray as $compositeClassReflection) { $paramName = $this->getComponentName($compositeClassReflection); $newProperty = new PropertyGenerator($paramName, null, PropertyGenerator::FLAG_PRIVATE); $this->generator->addPropertyFromGenerator($newProperty); } }
php
private function addPropertiesAndConstantsForContainer() { $this->addPropertiesAndConstantsFromReflection($this->containerClassReflection); foreach ($this->compositeClassReflectionArray as $compositeClassReflection) { $paramName = $this->getComponentName($compositeClassReflection); $newProperty = new PropertyGenerator($paramName, null, PropertyGenerator::FLAG_PRIVATE); $this->generator->addPropertyFromGenerator($newProperty); } }
[ "private", "function", "addPropertiesAndConstantsForContainer", "(", ")", "{", "$", "this", "->", "addPropertiesAndConstantsFromReflection", "(", "$", "this", "->", "containerClassReflection", ")", ";", "foreach", "(", "$", "this", "->", "compositeClassReflectionArray", "as", "$", "compositeClassReflection", ")", "{", "$", "paramName", "=", "$", "this", "->", "getComponentName", "(", "$", "compositeClassReflection", ")", ";", "$", "newProperty", "=", "new", "PropertyGenerator", "(", "$", "paramName", ",", "null", ",", "PropertyGenerator", "::", "FLAG_PRIVATE", ")", ";", "$", "this", "->", "generator", "->", "addPropertyFromGenerator", "(", "$", "newProperty", ")", ";", "}", "}" ]
Adds the properties and constants from the decorating class to the class being weaved. @internal param $originalSourceClass
[ "Adds", "the", "properties", "and", "constants", "from", "the", "decorating", "class", "to", "the", "class", "being", "weaved", "." ]
414894cd397daff22d2c71e4988784a1f71b702e
https://github.com/Danack/Weaver/blob/414894cd397daff22d2c71e4988784a1f71b702e/src/Weaver/CompositeWeaveGenerator.php#L263-L271
train
AdamB7586/menu-builder
src/Builder/Link.php
Link.title
public static function title($link) { if(isset($link['title']) || isset($link['label'])){ return ' title="'.trim(isset($link['title']) && !empty(trim($link['title'])) ? $link['title'] : $link['label']).'"'; } return false; }
php
public static function title($link) { if(isset($link['title']) || isset($link['label'])){ return ' title="'.trim(isset($link['title']) && !empty(trim($link['title'])) ? $link['title'] : $link['label']).'"'; } return false; }
[ "public", "static", "function", "title", "(", "$", "link", ")", "{", "if", "(", "isset", "(", "$", "link", "[", "'title'", "]", ")", "||", "isset", "(", "$", "link", "[", "'label'", "]", ")", ")", "{", "return", "' title=\"'", ".", "trim", "(", "isset", "(", "$", "link", "[", "'title'", "]", ")", "&&", "!", "empty", "(", "trim", "(", "$", "link", "[", "'title'", "]", ")", ")", "?", "$", "link", "[", "'title'", "]", ":", "$", "link", "[", "'label'", "]", ")", ".", "'\"'", ";", "}", "return", "false", ";", "}" ]
Returns the HTML title element @param array $link This should be an array containing all of the set link values @return string
[ "Returns", "the", "HTML", "title", "element" ]
dbc192bca7d59475068c19d1a07a039e5f997ee4
https://github.com/AdamB7586/menu-builder/blob/dbc192bca7d59475068c19d1a07a039e5f997ee4/src/Builder/Link.php#L32-L37
train
AdamB7586/menu-builder
src/Builder/Link.php
Link.label
public static function label($link) { if(isset($link['label']) && !empty(trim($link['label']))) { return trim($link['label']); } elseif(isset($link['title']) && !empty(trim($link['title']))) { return trim($link['title']); } return false; }
php
public static function label($link) { if(isset($link['label']) && !empty(trim($link['label']))) { return trim($link['label']); } elseif(isset($link['title']) && !empty(trim($link['title']))) { return trim($link['title']); } return false; }
[ "public", "static", "function", "label", "(", "$", "link", ")", "{", "if", "(", "isset", "(", "$", "link", "[", "'label'", "]", ")", "&&", "!", "empty", "(", "trim", "(", "$", "link", "[", "'label'", "]", ")", ")", ")", "{", "return", "trim", "(", "$", "link", "[", "'label'", "]", ")", ";", "}", "elseif", "(", "isset", "(", "$", "link", "[", "'title'", "]", ")", "&&", "!", "empty", "(", "trim", "(", "$", "link", "[", "'title'", "]", ")", ")", ")", "{", "return", "trim", "(", "$", "link", "[", "'title'", "]", ")", ";", "}", "return", "false", ";", "}" ]
Returns the link label element @param array $link This should be an array containing all of the set link values @return string Returns a valid string from the link label
[ "Returns", "the", "link", "label", "element" ]
dbc192bca7d59475068c19d1a07a039e5f997ee4
https://github.com/AdamB7586/menu-builder/blob/dbc192bca7d59475068c19d1a07a039e5f997ee4/src/Builder/Link.php#L68-L76
train
AdamB7586/menu-builder
src/Builder/Link.php
Link.href
public static function href($link) { if(isset($link['uri']) || isset($link['fragment'])) { return ' href="'.URI::getHref($link).'"'; } return false; }
php
public static function href($link) { if(isset($link['uri']) || isset($link['fragment'])) { return ' href="'.URI::getHref($link).'"'; } return false; }
[ "public", "static", "function", "href", "(", "$", "link", ")", "{", "if", "(", "isset", "(", "$", "link", "[", "'uri'", "]", ")", "||", "isset", "(", "$", "link", "[", "'fragment'", "]", ")", ")", "{", "return", "' href=\"'", ".", "URI", "::", "getHref", "(", "$", "link", ")", ".", "'\"'", ";", "}", "return", "false", ";", "}" ]
Returns the link href element @param array $link This should be an array containing all of the set link values @return string|false Returns the HTML href element if the uri or fragment information is set
[ "Returns", "the", "link", "href", "element" ]
dbc192bca7d59475068c19d1a07a039e5f997ee4
https://github.com/AdamB7586/menu-builder/blob/dbc192bca7d59475068c19d1a07a039e5f997ee4/src/Builder/Link.php#L83-L88
train
AdamB7586/menu-builder
src/Builder/Link.php
Link.htmlClass
public static function htmlClass($class, $activeClass) { if((isset($class) && is_string($class) && !empty(trim($class))) || (is_string($activeClass) && !empty(trim($activeClass)))) { return ' class="'.trim(trim($class).' '.$activeClass).'"'; } return false; }
php
public static function htmlClass($class, $activeClass) { if((isset($class) && is_string($class) && !empty(trim($class))) || (is_string($activeClass) && !empty(trim($activeClass)))) { return ' class="'.trim(trim($class).' '.$activeClass).'"'; } return false; }
[ "public", "static", "function", "htmlClass", "(", "$", "class", ",", "$", "activeClass", ")", "{", "if", "(", "(", "isset", "(", "$", "class", ")", "&&", "is_string", "(", "$", "class", ")", "&&", "!", "empty", "(", "trim", "(", "$", "class", ")", ")", ")", "||", "(", "is_string", "(", "$", "activeClass", ")", "&&", "!", "empty", "(", "trim", "(", "$", "activeClass", ")", ")", ")", ")", "{", "return", "' class=\"'", ".", "trim", "(", "trim", "(", "$", "class", ")", ".", "' '", ".", "$", "activeClass", ")", ".", "'\"'", ";", "}", "return", "false", ";", "}" ]
Returns the HTML class element @param string $class Should be a string containing the classes to add @param string $activeClass If the link is active the active class will be set else will be empty @return string|false If element is set and is valid will return the HTML element else return false
[ "Returns", "the", "HTML", "class", "element" ]
dbc192bca7d59475068c19d1a07a039e5f997ee4
https://github.com/AdamB7586/menu-builder/blob/dbc192bca7d59475068c19d1a07a039e5f997ee4/src/Builder/Link.php#L96-L101
train
AdamB7586/menu-builder
src/Builder/Link.php
Link.htmlID
public static function htmlID($link) { if(isset($link['id']) && is_string($link['id']) && !empty(trim($link['id']))) { return ' id="'.trim($link['id']).'"'; } return false; }
php
public static function htmlID($link) { if(isset($link['id']) && is_string($link['id']) && !empty(trim($link['id']))) { return ' id="'.trim($link['id']).'"'; } return false; }
[ "public", "static", "function", "htmlID", "(", "$", "link", ")", "{", "if", "(", "isset", "(", "$", "link", "[", "'id'", "]", ")", "&&", "is_string", "(", "$", "link", "[", "'id'", "]", ")", "&&", "!", "empty", "(", "trim", "(", "$", "link", "[", "'id'", "]", ")", ")", ")", "{", "return", "' id=\"'", ".", "trim", "(", "$", "link", "[", "'id'", "]", ")", ".", "'\"'", ";", "}", "return", "false", ";", "}" ]
Returns the HTML id element @param array $link This should be an array containing all of the set link values @return string|false If element is set and is valid will return the HTML element else return false
[ "Returns", "the", "HTML", "id", "element" ]
dbc192bca7d59475068c19d1a07a039e5f997ee4
https://github.com/AdamB7586/menu-builder/blob/dbc192bca7d59475068c19d1a07a039e5f997ee4/src/Builder/Link.php#L108-L113
train
AdamB7586/menu-builder
src/Builder/Link.php
Link.fontIcon
public static function fontIcon($link){ if(isset($link['font-icon']) && is_string($link['font-icon']) && !empty(trim($link['font-icon']))){ return '<span class="'.trim($link['font-icon']).'"></span> '; } return false; }
php
public static function fontIcon($link){ if(isset($link['font-icon']) && is_string($link['font-icon']) && !empty(trim($link['font-icon']))){ return '<span class="'.trim($link['font-icon']).'"></span> '; } return false; }
[ "public", "static", "function", "fontIcon", "(", "$", "link", ")", "{", "if", "(", "isset", "(", "$", "link", "[", "'font-icon'", "]", ")", "&&", "is_string", "(", "$", "link", "[", "'font-icon'", "]", ")", "&&", "!", "empty", "(", "trim", "(", "$", "link", "[", "'font-icon'", "]", ")", ")", ")", "{", "return", "'<span class=\"'", ".", "trim", "(", "$", "link", "[", "'font-icon'", "]", ")", ".", "'\"></span> '", ";", "}", "return", "false", ";", "}" ]
Inserts a given font ion in a span class @param array $link This should be an array containing all of the set link values @return string|boolean If the font icon is set will return a string else will return false
[ "Inserts", "a", "given", "font", "ion", "in", "a", "span", "class" ]
dbc192bca7d59475068c19d1a07a039e5f997ee4
https://github.com/AdamB7586/menu-builder/blob/dbc192bca7d59475068c19d1a07a039e5f997ee4/src/Builder/Link.php#L120-L125
train
AdamB7586/menu-builder
src/Builder/Link.php
Link.formatLink
public static function formatLink($link, $activeClass, $hasChild = false, $breadcrumbLink = false) { return "<a".self::href($link).self::title($link).self::htmlClass(($breadcrumbLink ? '' : self::$linkDefaults['a_default'].' ').(isset($link['class']) ? $link['class'] : ''), $activeClass).self::target($link).self::rel($link).self::htmlID($link).($hasChild ? self::$dropdownLinkExtras : '').">".($breadcrumbLink ? '' : self::fontIcon($link)).self::label($link).($hasChild ? self::$caretElement : '')."</a>"; }
php
public static function formatLink($link, $activeClass, $hasChild = false, $breadcrumbLink = false) { return "<a".self::href($link).self::title($link).self::htmlClass(($breadcrumbLink ? '' : self::$linkDefaults['a_default'].' ').(isset($link['class']) ? $link['class'] : ''), $activeClass).self::target($link).self::rel($link).self::htmlID($link).($hasChild ? self::$dropdownLinkExtras : '').">".($breadcrumbLink ? '' : self::fontIcon($link)).self::label($link).($hasChild ? self::$caretElement : '')."</a>"; }
[ "public", "static", "function", "formatLink", "(", "$", "link", ",", "$", "activeClass", ",", "$", "hasChild", "=", "false", ",", "$", "breadcrumbLink", "=", "false", ")", "{", "return", "\"<a\"", ".", "self", "::", "href", "(", "$", "link", ")", ".", "self", "::", "title", "(", "$", "link", ")", ".", "self", "::", "htmlClass", "(", "(", "$", "breadcrumbLink", "?", "''", ":", "self", "::", "$", "linkDefaults", "[", "'a_default'", "]", ".", "' '", ")", ".", "(", "isset", "(", "$", "link", "[", "'class'", "]", ")", "?", "$", "link", "[", "'class'", "]", ":", "''", ")", ",", "$", "activeClass", ")", ".", "self", "::", "target", "(", "$", "link", ")", ".", "self", "::", "rel", "(", "$", "link", ")", ".", "self", "::", "htmlID", "(", "$", "link", ")", ".", "(", "$", "hasChild", "?", "self", "::", "$", "dropdownLinkExtras", ":", "''", ")", ".", "\">\"", ".", "(", "$", "breadcrumbLink", "?", "''", ":", "self", "::", "fontIcon", "(", "$", "link", ")", ")", ".", "self", "::", "label", "(", "$", "link", ")", ".", "(", "$", "hasChild", "?", "self", "::", "$", "caretElement", ":", "''", ")", ".", "\"</a>\"", ";", "}" ]
Returns a formatted link with all of the attributes @param array $link This should be an array containing all of the set link values @param string $activeClass If the link is active should have the active class string set else should be empty @param boolean If the element has any child elements set to true else set to false @return string The HTML link element will be returned
[ "Returns", "a", "formatted", "link", "with", "all", "of", "the", "attributes" ]
dbc192bca7d59475068c19d1a07a039e5f997ee4
https://github.com/AdamB7586/menu-builder/blob/dbc192bca7d59475068c19d1a07a039e5f997ee4/src/Builder/Link.php#L134-L136
train
Innmind/Colour
src/HSLA.php
HSLA.hueToPoint
private function hueToPoint(float $p, float $q, float $t): float { if ($t < 0) { $t += 1; } if ($t > 1) { $t -= 1; } switch (true) { case $t < 1 / 6: return $p + ($q - $p) * 6 * $t; case $t < 1 / 2: return $q; case $t < 2 / 3: return $p + ($q - $p) * (2 / 3 - $t) * 6; } return $p; }
php
private function hueToPoint(float $p, float $q, float $t): float { if ($t < 0) { $t += 1; } if ($t > 1) { $t -= 1; } switch (true) { case $t < 1 / 6: return $p + ($q - $p) * 6 * $t; case $t < 1 / 2: return $q; case $t < 2 / 3: return $p + ($q - $p) * (2 / 3 - $t) * 6; } return $p; }
[ "private", "function", "hueToPoint", "(", "float", "$", "p", ",", "float", "$", "q", ",", "float", "$", "t", ")", ":", "float", "{", "if", "(", "$", "t", "<", "0", ")", "{", "$", "t", "+=", "1", ";", "}", "if", "(", "$", "t", ">", "1", ")", "{", "$", "t", "-=", "1", ";", "}", "switch", "(", "true", ")", "{", "case", "$", "t", "<", "1", "/", "6", ":", "return", "$", "p", "+", "(", "$", "q", "-", "$", "p", ")", "*", "6", "*", "$", "t", ";", "case", "$", "t", "<", "1", "/", "2", ":", "return", "$", "q", ";", "case", "$", "t", "<", "2", "/", "3", ":", "return", "$", "p", "+", "(", "$", "q", "-", "$", "p", ")", "*", "(", "2", "/", "3", "-", "$", "t", ")", "*", "6", ";", "}", "return", "$", "p", ";", "}" ]
Formula taken from the internet, don't know what it means @param float $p Don't know what it represents @param float $q Don't know what it represents @param float $t Don't know what it represents @return float
[ "Formula", "taken", "from", "the", "internet", "don", "t", "know", "what", "it", "means" ]
7fcddde00d74aba6bce6af4e4d70f323b9267f70
https://github.com/Innmind/Colour/blob/7fcddde00d74aba6bce6af4e4d70f323b9267f70/src/HSLA.php#L246-L268
train
WellCommerce/LocaleBundle
Doctrine/ORM/Filter/LocaleFilter.php
LocaleFilter.addFilterConstraint
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) { if (!$targetEntity->reflClass->implementsInterface(\WellCommerce\Bundle\LocaleBundle\Entity\LocaleAwareInterface::class)) { return ""; } return $targetTableAlias . '.locale = ' . $this->getParameter('locale'); }
php
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) { if (!$targetEntity->reflClass->implementsInterface(\WellCommerce\Bundle\LocaleBundle\Entity\LocaleAwareInterface::class)) { return ""; } return $targetTableAlias . '.locale = ' . $this->getParameter('locale'); }
[ "public", "function", "addFilterConstraint", "(", "ClassMetadata", "$", "targetEntity", ",", "$", "targetTableAlias", ")", "{", "if", "(", "!", "$", "targetEntity", "->", "reflClass", "->", "implementsInterface", "(", "\\", "WellCommerce", "\\", "Bundle", "\\", "LocaleBundle", "\\", "Entity", "\\", "LocaleAwareInterface", "::", "class", ")", ")", "{", "return", "\"\"", ";", "}", "return", "$", "targetTableAlias", ".", "'.locale = '", ".", "$", "this", "->", "getParameter", "(", "'locale'", ")", ";", "}" ]
Adds locale filter to query @param ClassMetadata $targetEntity @param string $targetTableAlias @return string
[ "Adds", "locale", "filter", "to", "query" ]
da61e059b789ccc748fd3cb0e881780fe6e6d3c6
https://github.com/WellCommerce/LocaleBundle/blob/da61e059b789ccc748fd3cb0e881780fe6e6d3c6/Doctrine/ORM/Filter/LocaleFilter.php#L33-L40
train
bseddon/XPath20
Iterator/FollowingNodeIterator.php
FollowingNodeIterator.fromFollowingNodeIteratorParts
protected function fromFollowingNodeIteratorParts() { if ( is_null( $this->typeTest ) ) { if ( is_null( $this->nameTest ) ) $this->kind = XPathNodeType::All; else $this->kind = XPathNodeType::Element; } else $this->kind = $this->typeTest->GetNodeKind(); }
php
protected function fromFollowingNodeIteratorParts() { if ( is_null( $this->typeTest ) ) { if ( is_null( $this->nameTest ) ) $this->kind = XPathNodeType::All; else $this->kind = XPathNodeType::Element; } else $this->kind = $this->typeTest->GetNodeKind(); }
[ "protected", "function", "fromFollowingNodeIteratorParts", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "typeTest", ")", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "nameTest", ")", ")", "$", "this", "->", "kind", "=", "XPathNodeType", "::", "All", ";", "else", "$", "this", "->", "kind", "=", "XPathNodeType", "::", "Element", ";", "}", "else", "$", "this", "->", "kind", "=", "$", "this", "->", "typeTest", "->", "GetNodeKind", "(", ")", ";", "}" ]
Supports constructing an instance
[ "Supports", "constructing", "an", "instance" ]
69882b6efffaa5470a819d5fdd2f6473ddeb046d
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Iterator/FollowingNodeIterator.php#L70-L81
train
FlexModel/FlexModelBundle
DependencyInjection/FlexModelFactory.php
FlexModelFactory.createFlexModel
public static function createFlexModel($identifier, $resource, $cachePath) { $domDocument = new DOMDocument('1.0', 'UTF-8'); $domDocument->load($resource); $domDocument->xinclude(); $flexModel = new FlexModel($identifier); $flexModel->load($domDocument, $cachePath); return $flexModel; }
php
public static function createFlexModel($identifier, $resource, $cachePath) { $domDocument = new DOMDocument('1.0', 'UTF-8'); $domDocument->load($resource); $domDocument->xinclude(); $flexModel = new FlexModel($identifier); $flexModel->load($domDocument, $cachePath); return $flexModel; }
[ "public", "static", "function", "createFlexModel", "(", "$", "identifier", ",", "$", "resource", ",", "$", "cachePath", ")", "{", "$", "domDocument", "=", "new", "DOMDocument", "(", "'1.0'", ",", "'UTF-8'", ")", ";", "$", "domDocument", "->", "load", "(", "$", "resource", ")", ";", "$", "domDocument", "->", "xinclude", "(", ")", ";", "$", "flexModel", "=", "new", "FlexModel", "(", "$", "identifier", ")", ";", "$", "flexModel", "->", "load", "(", "$", "domDocument", ",", "$", "cachePath", ")", ";", "return", "$", "flexModel", ";", "}" ]
Creates a new FlexModel instance. @param string $identifier @param string $resource @param string $cachePath @return FlexModel
[ "Creates", "a", "new", "FlexModel", "instance", "." ]
7b4720d25b0dc6baf29b1da8ad7c67dfb2686460
https://github.com/FlexModel/FlexModelBundle/blob/7b4720d25b0dc6baf29b1da8ad7c67dfb2686460/DependencyInjection/FlexModelFactory.php#L24-L34
train
ComPHPPuebla/restful-extensions
src/ComPHPPuebla/Slim/Middleware/JsonpMiddleware.php
JsonpMiddleware.call
public function call() { if ('application/json' !== $this->app->request()->headers('Accept')) { $this->next->call(); return; //Only JSON can be turned into JSONP } $callback = $this->app->request()->get('callback'); $this->next->call(); if (empty($callback)) { return; //Not a JSONP request } $this->app->contentType('application/javascript'); $jsonp = htmlspecialchars($callback) . "(" .$this->app->response()->body() . ")"; $this->app->response()->body($jsonp); }
php
public function call() { if ('application/json' !== $this->app->request()->headers('Accept')) { $this->next->call(); return; //Only JSON can be turned into JSONP } $callback = $this->app->request()->get('callback'); $this->next->call(); if (empty($callback)) { return; //Not a JSONP request } $this->app->contentType('application/javascript'); $jsonp = htmlspecialchars($callback) . "(" .$this->app->response()->body() . ")"; $this->app->response()->body($jsonp); }
[ "public", "function", "call", "(", ")", "{", "if", "(", "'application/json'", "!==", "$", "this", "->", "app", "->", "request", "(", ")", "->", "headers", "(", "'Accept'", ")", ")", "{", "$", "this", "->", "next", "->", "call", "(", ")", ";", "return", ";", "//Only JSON can be turned into JSONP", "}", "$", "callback", "=", "$", "this", "->", "app", "->", "request", "(", ")", "->", "get", "(", "'callback'", ")", ";", "$", "this", "->", "next", "->", "call", "(", ")", ";", "if", "(", "empty", "(", "$", "callback", ")", ")", "{", "return", ";", "//Not a JSONP request", "}", "$", "this", "->", "app", "->", "contentType", "(", "'application/javascript'", ")", ";", "$", "jsonp", "=", "htmlspecialchars", "(", "$", "callback", ")", ".", "\"(\"", ".", "$", "this", "->", "app", "->", "response", "(", ")", "->", "body", "(", ")", ".", "\")\"", ";", "$", "this", "->", "app", "->", "response", "(", ")", "->", "body", "(", "$", "jsonp", ")", ";", "}" ]
Adjust the content type accordingly and add the given callback name to the response for JSONP requests @see \Slim\Middleware::call()
[ "Adjust", "the", "content", "type", "accordingly", "and", "add", "the", "given", "callback", "name", "to", "the", "response", "for", "JSONP", "requests" ]
3dc5e554d7ebe1305eed4cd4ec71a6944316199c
https://github.com/ComPHPPuebla/restful-extensions/blob/3dc5e554d7ebe1305eed4cd4ec71a6944316199c/src/ComPHPPuebla/Slim/Middleware/JsonpMiddleware.php#L14-L35
train
itcreator/custom-cmf
Module/System/src/Cmf/System/Controller/RedirectController.php
RedirectController.defaultAction
public function defaultAction() { $lng = \Cmf\Language\Factory::get($this); HelperFactory::getMeta()->clear(); HelperFactory::getJS()->clear(); HelperFactory::getStyle()->clear(); HelperFactory::getTitle()->setTitle('Redirect'); if ($path = urldecode(Application::getRequest()->get('path'))) { HelperFactory::getMeta()->addTag('refresh', '0; url=' . $path); $response = ['path' => $path]; } else { $response = ['error' => $lng['error_badPath']]; } return $response; }
php
public function defaultAction() { $lng = \Cmf\Language\Factory::get($this); HelperFactory::getMeta()->clear(); HelperFactory::getJS()->clear(); HelperFactory::getStyle()->clear(); HelperFactory::getTitle()->setTitle('Redirect'); if ($path = urldecode(Application::getRequest()->get('path'))) { HelperFactory::getMeta()->addTag('refresh', '0; url=' . $path); $response = ['path' => $path]; } else { $response = ['error' => $lng['error_badPath']]; } return $response; }
[ "public", "function", "defaultAction", "(", ")", "{", "$", "lng", "=", "\\", "Cmf", "\\", "Language", "\\", "Factory", "::", "get", "(", "$", "this", ")", ";", "HelperFactory", "::", "getMeta", "(", ")", "->", "clear", "(", ")", ";", "HelperFactory", "::", "getJS", "(", ")", "->", "clear", "(", ")", ";", "HelperFactory", "::", "getStyle", "(", ")", "->", "clear", "(", ")", ";", "HelperFactory", "::", "getTitle", "(", ")", "->", "setTitle", "(", "'Redirect'", ")", ";", "if", "(", "$", "path", "=", "urldecode", "(", "Application", "::", "getRequest", "(", ")", "->", "get", "(", "'path'", ")", ")", ")", "{", "HelperFactory", "::", "getMeta", "(", ")", "->", "addTag", "(", "'refresh'", ",", "'0; url='", ".", "$", "path", ")", ";", "$", "response", "=", "[", "'path'", "=>", "$", "path", "]", ";", "}", "else", "{", "$", "response", "=", "[", "'error'", "=>", "$", "lng", "[", "'error_badPath'", "]", "]", ";", "}", "return", "$", "response", ";", "}" ]
This method display redirect page @return array
[ "This", "method", "display", "redirect", "page" ]
42fc0535dfa0f641856f06673f6ab596b2020c40
https://github.com/itcreator/custom-cmf/blob/42fc0535dfa0f641856f06673f6ab596b2020c40/Module/System/src/Cmf/System/Controller/RedirectController.php#L26-L41
train
stubbles/stubbles-dbal
src/main/php/config/DatabaseConfiguration.php
DatabaseConfiguration.fromArray
public static function fromArray(string $id, string $dsn, array $properties): DatabaseConfiguration { $self = new self($id, $dsn); if (isset($properties['username'])) { $self->userName = $properties['username']; unset($properties['username']); } if (isset($properties['password'])) { $self->setPassword(Secret::create($properties['password'])); unset($properties['password']); } if (isset($properties['initialQuery'])) { $self->initialQuery = $properties['initialQuery']; unset($properties['initialQuery']); } if (isset($properties['details'])) { $self->details = $properties['details']; unset($properties['details']); } $self->properties = $properties; return $self; }
php
public static function fromArray(string $id, string $dsn, array $properties): DatabaseConfiguration { $self = new self($id, $dsn); if (isset($properties['username'])) { $self->userName = $properties['username']; unset($properties['username']); } if (isset($properties['password'])) { $self->setPassword(Secret::create($properties['password'])); unset($properties['password']); } if (isset($properties['initialQuery'])) { $self->initialQuery = $properties['initialQuery']; unset($properties['initialQuery']); } if (isset($properties['details'])) { $self->details = $properties['details']; unset($properties['details']); } $self->properties = $properties; return $self; }
[ "public", "static", "function", "fromArray", "(", "string", "$", "id", ",", "string", "$", "dsn", ",", "array", "$", "properties", ")", ":", "DatabaseConfiguration", "{", "$", "self", "=", "new", "self", "(", "$", "id", ",", "$", "dsn", ")", ";", "if", "(", "isset", "(", "$", "properties", "[", "'username'", "]", ")", ")", "{", "$", "self", "->", "userName", "=", "$", "properties", "[", "'username'", "]", ";", "unset", "(", "$", "properties", "[", "'username'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "properties", "[", "'password'", "]", ")", ")", "{", "$", "self", "->", "setPassword", "(", "Secret", "::", "create", "(", "$", "properties", "[", "'password'", "]", ")", ")", ";", "unset", "(", "$", "properties", "[", "'password'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "properties", "[", "'initialQuery'", "]", ")", ")", "{", "$", "self", "->", "initialQuery", "=", "$", "properties", "[", "'initialQuery'", "]", ";", "unset", "(", "$", "properties", "[", "'initialQuery'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "properties", "[", "'details'", "]", ")", ")", "{", "$", "self", "->", "details", "=", "$", "properties", "[", "'details'", "]", ";", "unset", "(", "$", "properties", "[", "'details'", "]", ")", ";", "}", "$", "self", "->", "properties", "=", "$", "properties", ";", "return", "$", "self", ";", "}" ]
create connection data instance from an array Please note that this method does not support driver options. Driver options must be set separately. @param string $id @param string $dsn @param array $properties @return \stubbles\db\config\DatabaseConfiguration
[ "create", "connection", "data", "instance", "from", "an", "array" ]
b42a589025a9e511b40a2798ac84df94d6451c36
https://github.com/stubbles/stubbles-dbal/blob/b42a589025a9e511b40a2798ac84df94d6451c36/src/main/php/config/DatabaseConfiguration.php#L82-L107
train
aztech-digital/phinject
src/ObjectContainer.php
ObjectContainer.lateBind
public function lateBind($key, & $item) { if (is_array($item)) { return $this->classes[$key] = $item; } return $this->registry->rset($key, $item); }
php
public function lateBind($key, & $item) { if (is_array($item)) { return $this->classes[$key] = $item; } return $this->registry->rset($key, $item); }
[ "public", "function", "lateBind", "(", "$", "key", ",", "&", "$", "item", ")", "{", "if", "(", "is_array", "(", "$", "item", ")", ")", "{", "return", "$", "this", "->", "classes", "[", "$", "key", "]", "=", "$", "item", ";", "}", "return", "$", "this", "->", "registry", "->", "rset", "(", "$", "key", ",", "$", "item", ")", ";", "}" ]
Binds by reference an existing object or an object definition to a key in the container. @param string $key The key to which the new object/definition should be bound. @param mixed $item An array or an object to bind. If $item is an object, it will be registered as a singleton in the object registry. Otherwise, $item will be handled as an object definition.
[ "Binds", "by", "reference", "an", "existing", "object", "or", "an", "object", "definition", "to", "a", "key", "in", "the", "container", "." ]
1bb2fb3b5ef44e62f168af71134c613c48b58d95
https://github.com/aztech-digital/phinject/blob/1bb2fb3b5ef44e62f168af71134c613c48b58d95/src/ObjectContainer.php#L133-L140
train
jbouzekri/SculpinTagCloudBundle
Model/TagCloud.php
TagCloud.current
public function current() { $keys = array_keys($this->tags); return $this->tags[$keys[$this->position]]; }
php
public function current() { $keys = array_keys($this->tags); return $this->tags[$keys[$this->position]]; }
[ "public", "function", "current", "(", ")", "{", "$", "keys", "=", "array_keys", "(", "$", "this", "->", "tags", ")", ";", "return", "$", "this", "->", "tags", "[", "$", "keys", "[", "$", "this", "->", "position", "]", "]", ";", "}" ]
Iterator current item @return \Jb\Bundle\TagCloudBundle\Model\Tag
[ "Iterator", "current", "item" ]
936cf34ce60cb8fb4774931b1841fc775a3e9208
https://github.com/jbouzekri/SculpinTagCloudBundle/blob/936cf34ce60cb8fb4774931b1841fc775a3e9208/Model/TagCloud.php#L125-L129
train
jbouzekri/SculpinTagCloudBundle
Model/TagCloud.php
TagCloud.valid
public function valid() { $keys = array_keys($this->tags); return isset($keys[$this->position]) && isset($this->tags[$keys[$this->position]]); }
php
public function valid() { $keys = array_keys($this->tags); return isset($keys[$this->position]) && isset($this->tags[$keys[$this->position]]); }
[ "public", "function", "valid", "(", ")", "{", "$", "keys", "=", "array_keys", "(", "$", "this", "->", "tags", ")", ";", "return", "isset", "(", "$", "keys", "[", "$", "this", "->", "position", "]", ")", "&&", "isset", "(", "$", "this", "->", "tags", "[", "$", "keys", "[", "$", "this", "->", "position", "]", "]", ")", ";", "}" ]
Iterator item exists @return boolean
[ "Iterator", "item", "exists" ]
936cf34ce60cb8fb4774931b1841fc775a3e9208
https://github.com/jbouzekri/SculpinTagCloudBundle/blob/936cf34ce60cb8fb4774931b1841fc775a3e9208/Model/TagCloud.php#L156-L160
train
jbouzekri/SculpinTagCloudBundle
Model/TagCloud.php
TagCloud.slice
public function slice($offset, $length = null) { $this->tags = array_slice($this->tags, $offset, $length, true); return $this; }
php
public function slice($offset, $length = null) { $this->tags = array_slice($this->tags, $offset, $length, true); return $this; }
[ "public", "function", "slice", "(", "$", "offset", ",", "$", "length", "=", "null", ")", "{", "$", "this", "->", "tags", "=", "array_slice", "(", "$", "this", "->", "tags", ",", "$", "offset", ",", "$", "length", ",", "true", ")", ";", "return", "$", "this", ";", "}" ]
Slice the tag cloud @param int $offset @param int $length @return \Jb\Bundle\TagCloudBundle\Model\TagCloud
[ "Slice", "the", "tag", "cloud" ]
936cf34ce60cb8fb4774931b1841fc775a3e9208
https://github.com/jbouzekri/SculpinTagCloudBundle/blob/936cf34ce60cb8fb4774931b1841fc775a3e9208/Model/TagCloud.php#L170-L175
train
PenoaksDev/Milky-Framework
src/Milky/Binding/Globals.php
Globals.getByClass
public static function getByClass( $class ) { $results = []; foreach ( static::$globals as $k => $v ) if ( $v instanceof $class ) $results[$k] = $v; return $results; }
php
public static function getByClass( $class ) { $results = []; foreach ( static::$globals as $k => $v ) if ( $v instanceof $class ) $results[$k] = $v; return $results; }
[ "public", "static", "function", "getByClass", "(", "$", "class", ")", "{", "$", "results", "=", "[", "]", ";", "foreach", "(", "static", "::", "$", "globals", "as", "$", "k", "=>", "$", "v", ")", "if", "(", "$", "v", "instanceof", "$", "class", ")", "$", "results", "[", "$", "k", "]", "=", "$", "v", ";", "return", "$", "results", ";", "}" ]
Gets globals by their final class @param string $class @return array
[ "Gets", "globals", "by", "their", "final", "class" ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Binding/Globals.php#L88-L95
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/benchmark/Benchmark.php
Benchmark.start
public function start($name, $preset = null, $isGlobalStart = false) { if(!$this->isEnabled()) return; // if(empty($name)) // throw new BenchmarkException("Empty timer name!"); // // $name = $this->uniqueTimerName($name); $t = $this->getTime(); $this->timers[$name] = array( 'name' => $name, // 'start' => $preset == null ? $t : $preset, // 'end' => null, 'time' => $preset == null ? $t : $preset, 'aggregate' => null, // 'checkpoints' => array() ); if (!$this->globalMode && $isGlobalStart) { $this->globalMode = true; $this->firstTime = $this->timers[$name]['time']; } return $name; }
php
public function start($name, $preset = null, $isGlobalStart = false) { if(!$this->isEnabled()) return; // if(empty($name)) // throw new BenchmarkException("Empty timer name!"); // // $name = $this->uniqueTimerName($name); $t = $this->getTime(); $this->timers[$name] = array( 'name' => $name, // 'start' => $preset == null ? $t : $preset, // 'end' => null, 'time' => $preset == null ? $t : $preset, 'aggregate' => null, // 'checkpoints' => array() ); if (!$this->globalMode && $isGlobalStart) { $this->globalMode = true; $this->firstTime = $this->timers[$name]['time']; } return $name; }
[ "public", "function", "start", "(", "$", "name", ",", "$", "preset", "=", "null", ",", "$", "isGlobalStart", "=", "false", ")", "{", "if", "(", "!", "$", "this", "->", "isEnabled", "(", ")", ")", "return", ";", "// if(empty($name))", "// throw new BenchmarkException(\"Empty timer name!\");", "//", "// $name = $this->uniqueTimerName($name);", "$", "t", "=", "$", "this", "->", "getTime", "(", ")", ";", "$", "this", "->", "timers", "[", "$", "name", "]", "=", "array", "(", "'name'", "=>", "$", "name", ",", "// 'start' => $preset == null ? $t : $preset,", "// 'end' => null,", "'time'", "=>", "$", "preset", "==", "null", "?", "$", "t", ":", "$", "preset", ",", "'aggregate'", "=>", "null", ",", "// 'checkpoints' => array()", ")", ";", "if", "(", "!", "$", "this", "->", "globalMode", "&&", "$", "isGlobalStart", ")", "{", "$", "this", "->", "globalMode", "=", "true", ";", "$", "this", "->", "firstTime", "=", "$", "this", "->", "timers", "[", "$", "name", "]", "[", "'time'", "]", ";", "}", "return", "$", "name", ";", "}" ]
Starts a timer with the given name The {@link $preset} parameter is useful for starting a timer for a process that begin before the Benchmark instance was available, ex. at the start of the entire request The {@link $isGlobalStart} parameter is required if you'd like {@link getTotals()} to return aggregate times for each stored timer. Enables aggregation mode where every timer end will also store time in relation to the entire request. Upon starting a timer by the same name as a previously stored timer, this function will auto-increment the {@link $name} with a numeric digit ex. 'timer-2'. @param string $name Name of timer @param int $preset If not null, Unix timestamp with microseconds to store as the start time @param boolean $isGlobalStart Whether or not this timer begins the entire request, used for aggregate profiling in {@link getTotals()} @return string Timer name
[ "Starts", "a", "timer", "with", "the", "given", "name" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/benchmark/Benchmark.php#L95-L121
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/benchmark/Benchmark.php
Benchmark.end
public function end($name) { if(!$this->isEnabled()) return; $aggregate = 0; // if (empty($name)) // throw new BenchmarkException("Empty timer name!"); // // if (array_key_exists($name, $this->timers) && !empty($this->timers[$name]['end'])) { // $inc = 1; // while (array_key_exists($name.'-'.$inc, $this->timers) && !empty($this->timers[$name]['end'])) { // $inc++; // } // $name = $name.'-'.$inc; // } $oldTime = $this->firstTime; if (array_key_exists($name, $this->timers)) $oldTime = $this->timers[$name]['time']; //throw new BenchmarkException("Timer name '{$name}' not found! Please call start(...) first!"); // $this->timers[$name]['end'] = $this->getTime(); $n = $this->getTime(); // $this->timers[$name]['time'] = ($this->timers[$name]['end'] - $this->timers[$name]['start'])*1000; $time = ($n - $oldTime)*1000; if ($this->globalMode) // $this->timers[$name]['aggregate'] = ($n - $this->firstTime)*1000; $aggregate = ($n - $this->firstTime)*1000; // $this->Logger->debug("Timer [{$name}]: {$this->timers[$name]['time']}ms, aggregate {$this->timers[$name]['aggregate']}ms"); $this->Logger->debug("Timer [{$name}]: {$time}ms".($this->globalMode?", aggregate {$aggregate}ms":"")); unset($this->timers[$name]); return $time; }
php
public function end($name) { if(!$this->isEnabled()) return; $aggregate = 0; // if (empty($name)) // throw new BenchmarkException("Empty timer name!"); // // if (array_key_exists($name, $this->timers) && !empty($this->timers[$name]['end'])) { // $inc = 1; // while (array_key_exists($name.'-'.$inc, $this->timers) && !empty($this->timers[$name]['end'])) { // $inc++; // } // $name = $name.'-'.$inc; // } $oldTime = $this->firstTime; if (array_key_exists($name, $this->timers)) $oldTime = $this->timers[$name]['time']; //throw new BenchmarkException("Timer name '{$name}' not found! Please call start(...) first!"); // $this->timers[$name]['end'] = $this->getTime(); $n = $this->getTime(); // $this->timers[$name]['time'] = ($this->timers[$name]['end'] - $this->timers[$name]['start'])*1000; $time = ($n - $oldTime)*1000; if ($this->globalMode) // $this->timers[$name]['aggregate'] = ($n - $this->firstTime)*1000; $aggregate = ($n - $this->firstTime)*1000; // $this->Logger->debug("Timer [{$name}]: {$this->timers[$name]['time']}ms, aggregate {$this->timers[$name]['aggregate']}ms"); $this->Logger->debug("Timer [{$name}]: {$time}ms".($this->globalMode?", aggregate {$aggregate}ms":"")); unset($this->timers[$name]); return $time; }
[ "public", "function", "end", "(", "$", "name", ")", "{", "if", "(", "!", "$", "this", "->", "isEnabled", "(", ")", ")", "return", ";", "$", "aggregate", "=", "0", ";", "// if (empty($name))", "// throw new BenchmarkException(\"Empty timer name!\");", "//", "// if (array_key_exists($name, $this->timers) && !empty($this->timers[$name]['end'])) {", "// $inc = 1;", "// while (array_key_exists($name.'-'.$inc, $this->timers) && !empty($this->timers[$name]['end'])) {", "// $inc++;", "// }", "// $name = $name.'-'.$inc;", "// }", "$", "oldTime", "=", "$", "this", "->", "firstTime", ";", "if", "(", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "timers", ")", ")", "$", "oldTime", "=", "$", "this", "->", "timers", "[", "$", "name", "]", "[", "'time'", "]", ";", "//throw new BenchmarkException(\"Timer name '{$name}' not found! Please call start(...) first!\");", "// $this->timers[$name]['end'] = $this->getTime();", "$", "n", "=", "$", "this", "->", "getTime", "(", ")", ";", "// $this->timers[$name]['time'] = ($this->timers[$name]['end'] - $this->timers[$name]['start'])*1000;", "$", "time", "=", "(", "$", "n", "-", "$", "oldTime", ")", "*", "1000", ";", "if", "(", "$", "this", "->", "globalMode", ")", "// $this->timers[$name]['aggregate'] = ($n - $this->firstTime)*1000;", "$", "aggregate", "=", "(", "$", "n", "-", "$", "this", "->", "firstTime", ")", "*", "1000", ";", "// $this->Logger->debug(\"Timer [{$name}]: {$this->timers[$name]['time']}ms, aggregate {$this->timers[$name]['aggregate']}ms\");", "$", "this", "->", "Logger", "->", "debug", "(", "\"Timer [{$name}]: {$time}ms\"", ".", "(", "$", "this", "->", "globalMode", "?", "\", aggregate {$aggregate}ms\"", ":", "\"\"", ")", ")", ";", "unset", "(", "$", "this", "->", "timers", "[", "$", "name", "]", ")", ";", "return", "$", "time", ";", "}" ]
Ends and stores the elapsed time for the timer with the given name If is in aggregation mode, also stores the aggregate time for this timer. This is useful for tracing a request and noticing large lapses in processing that may not have a timer implemented. If a timer by the same name has already been stored, this function will auto-increment the {@link $name} with a numeric digit, ex. 'timer-2', before attempting to store the end time. @param string $name Name of timer @return int Elapsed time in milliseconds @throws BenchmarkException When ending a timer that was not started
[ "Ends", "and", "stores", "the", "elapsed", "time", "for", "the", "timer", "with", "the", "given", "name" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/benchmark/Benchmark.php#L139-L175
train
jacksleight/coast
library/Config.php
Config.fromArray
public function fromArray(array $opts) { $this->_opts = \Coast\array_merge_smart( $this->_opts, $opts ); return $this; }
php
public function fromArray(array $opts) { $this->_opts = \Coast\array_merge_smart( $this->_opts, $opts ); return $this; }
[ "public", "function", "fromArray", "(", "array", "$", "opts", ")", "{", "$", "this", "->", "_opts", "=", "\\", "Coast", "\\", "array_merge_smart", "(", "$", "this", "->", "_opts", ",", "$", "opts", ")", ";", "return", "$", "this", ";", "}" ]
Import from an array. @param string $name @return mixed
[ "Import", "from", "an", "array", "." ]
cd6cd41e8304adce41f59f799d4183adcaf666f9
https://github.com/jacksleight/coast/blob/cd6cd41e8304adce41f59f799d4183adcaf666f9/library/Config.php#L61-L68
train
shgysk8zer0/core_api
traits/errors.php
Errors.errorToException
protected static function errorToException( $level, $message, $file, $line ) { try { throw new \ErrorException($message, 0, $level, $file, $line); } catch(\ErrorException $e) { return $e; } }
php
protected static function errorToException( $level, $message, $file, $line ) { try { throw new \ErrorException($message, 0, $level, $file, $line); } catch(\ErrorException $e) { return $e; } }
[ "protected", "static", "function", "errorToException", "(", "$", "level", ",", "$", "message", ",", "$", "file", ",", "$", "line", ")", "{", "try", "{", "throw", "new", "\\", "ErrorException", "(", "$", "message", ",", "0", ",", "$", "level", ",", "$", "file", ",", "$", "line", ")", ";", "}", "catch", "(", "\\", "ErrorException", "$", "e", ")", "{", "return", "$", "e", ";", "}", "}" ]
Throws, catches, and returns an \ErrorException created from error args @param int $level Any of the error levels (E_*) @param string $message Message given with the error @param string $file File generating the error @param int $line Line on which the error occured @return \ErrorException @see http://php.net/manual/en/class.errorexception.php
[ "Throws", "catches", "and", "returns", "an", "\\", "ErrorException", "created", "from", "error", "args" ]
9e9b8baf761af874b95256ad2462e55fbb2b2e58
https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/errors.php#L39-L51
train
jayalfredprufrock/codeigniter-messages
libraries/messages.php
Messages.add
public function add($type, $message, $data = FALSE, $title = FALSE) { $messages = $this->_session_get(); if (!is_array($messages)) { $messages = array(); } if (is_a($message, 'Exception')) { $title = 'Exception Thrown!'; $message = $message->getMessage(); $type = 'error'; } $msg = array('type'=>$type,'title'=>$title); $msg['text'] = is_array($data) ? vsprintf($message, $data) : sprintf($message, $data); $messages[] = (object)$msg; $this->_session_set($messages); return $this; }
php
public function add($type, $message, $data = FALSE, $title = FALSE) { $messages = $this->_session_get(); if (!is_array($messages)) { $messages = array(); } if (is_a($message, 'Exception')) { $title = 'Exception Thrown!'; $message = $message->getMessage(); $type = 'error'; } $msg = array('type'=>$type,'title'=>$title); $msg['text'] = is_array($data) ? vsprintf($message, $data) : sprintf($message, $data); $messages[] = (object)$msg; $this->_session_set($messages); return $this; }
[ "public", "function", "add", "(", "$", "type", ",", "$", "message", ",", "$", "data", "=", "FALSE", ",", "$", "title", "=", "FALSE", ")", "{", "$", "messages", "=", "$", "this", "->", "_session_get", "(", ")", ";", "if", "(", "!", "is_array", "(", "$", "messages", ")", ")", "{", "$", "messages", "=", "array", "(", ")", ";", "}", "if", "(", "is_a", "(", "$", "message", ",", "'Exception'", ")", ")", "{", "$", "title", "=", "'Exception Thrown!'", ";", "$", "message", "=", "$", "message", "->", "getMessage", "(", ")", ";", "$", "type", "=", "'error'", ";", "}", "$", "msg", "=", "array", "(", "'type'", "=>", "$", "type", ",", "'title'", "=>", "$", "title", ")", ";", "$", "msg", "[", "'text'", "]", "=", "is_array", "(", "$", "data", ")", "?", "vsprintf", "(", "$", "message", ",", "$", "data", ")", ":", "sprintf", "(", "$", "message", ",", "$", "data", ")", ";", "$", "messages", "[", "]", "=", "(", "object", ")", "$", "msg", ";", "$", "this", "->", "_session_set", "(", "$", "messages", ")", ";", "return", "$", "this", ";", "}" ]
Adds a message to the a list. The optional parameter $data may be a primitive value or an array. If the $data parameter is present, $message must be a {@link http://www.php.net/manual/en/function.sprintf.php printf()}-style template string that includes formatting for the value(s) in $data. The $message formatting string is applied to the $data value(s) and the resulting message string is added to the list. Eg. $this->messages->add('success', '%d files uploaded (%.2f kB)', array($num_files, $uploaded_size)); @param string $message message to be displayed @param string $type one of the message types specified in the constructor params @param mixed $data optional data to be included in the message @return $this
[ "Adds", "a", "message", "to", "the", "a", "list", "." ]
d1891b0439c08b2df902effde171d25e4dbc6c79
https://github.com/jayalfredprufrock/codeigniter-messages/blob/d1891b0439c08b2df902effde171d25e4dbc6c79/libraries/messages.php#L48-L75
train
jayalfredprufrock/codeigniter-messages
libraries/messages.php
Messages.clear
public function clear($type = FALSE) { if ($type === FALSE){ $this->_session_unset(); } else { $messages = $this->_session_get(); if (is_array($messages)) { foreach($messages as $i=>$message){ if ($message->type == $type){ unset($messages[$i]); } } if (!$this->count()) { $this->clear(); } else { $this->_session_set($messages); } } } return $this; }
php
public function clear($type = FALSE) { if ($type === FALSE){ $this->_session_unset(); } else { $messages = $this->_session_get(); if (is_array($messages)) { foreach($messages as $i=>$message){ if ($message->type == $type){ unset($messages[$i]); } } if (!$this->count()) { $this->clear(); } else { $this->_session_set($messages); } } } return $this; }
[ "public", "function", "clear", "(", "$", "type", "=", "FALSE", ")", "{", "if", "(", "$", "type", "===", "FALSE", ")", "{", "$", "this", "->", "_session_unset", "(", ")", ";", "}", "else", "{", "$", "messages", "=", "$", "this", "->", "_session_get", "(", ")", ";", "if", "(", "is_array", "(", "$", "messages", ")", ")", "{", "foreach", "(", "$", "messages", "as", "$", "i", "=>", "$", "message", ")", "{", "if", "(", "$", "message", "->", "type", "==", "$", "type", ")", "{", "unset", "(", "$", "messages", "[", "$", "i", "]", ")", ";", "}", "}", "if", "(", "!", "$", "this", "->", "count", "(", ")", ")", "{", "$", "this", "->", "clear", "(", ")", ";", "}", "else", "{", "$", "this", "->", "_session_set", "(", "$", "messages", ")", ";", "}", "}", "}", "return", "$", "this", ";", "}" ]
Removes messages from the list. If $type is given, clears only messages of that type If $type is not given, clears all messages @param string $type type of messages to remove @return $this
[ "Removes", "messages", "from", "the", "list", "." ]
d1891b0439c08b2df902effde171d25e4dbc6c79
https://github.com/jayalfredprufrock/codeigniter-messages/blob/d1891b0439c08b2df902effde171d25e4dbc6c79/libraries/messages.php#L86-L119
train
jayalfredprufrock/codeigniter-messages
libraries/messages.php
Messages.peek
public function peek($type = FALSE) { $messages = $this->_session_get(); if (!is_array($messages)){ return array(); } if ($type === FALSE) { return $messages; } else { $tmessages = array(); foreach($messages as $message){ if ($message->type == $type){ $tmessages[] = $message; } } return $tmessages; } }
php
public function peek($type = FALSE) { $messages = $this->_session_get(); if (!is_array($messages)){ return array(); } if ($type === FALSE) { return $messages; } else { $tmessages = array(); foreach($messages as $message){ if ($message->type == $type){ $tmessages[] = $message; } } return $tmessages; } }
[ "public", "function", "peek", "(", "$", "type", "=", "FALSE", ")", "{", "$", "messages", "=", "$", "this", "->", "_session_get", "(", ")", ";", "if", "(", "!", "is_array", "(", "$", "messages", ")", ")", "{", "return", "array", "(", ")", ";", "}", "if", "(", "$", "type", "===", "FALSE", ")", "{", "return", "$", "messages", ";", "}", "else", "{", "$", "tmessages", "=", "array", "(", ")", ";", "foreach", "(", "$", "messages", "as", "$", "message", ")", "{", "if", "(", "$", "message", "->", "type", "==", "$", "type", ")", "{", "$", "tmessages", "[", "]", "=", "$", "message", ";", "}", "}", "return", "$", "tmessages", ";", "}", "}" ]
Returns an array of messages to be displayed without removing them from the session If $type is given, returns an array of messages of that type If $type is not given, returns an array of all messages objects, in the order they were added. Each message object contains two properties, type and text. @param string $type type of messages to peek at @return array messages
[ "Returns", "an", "array", "of", "messages", "to", "be", "displayed", "without", "removing", "them", "from", "the", "session" ]
d1891b0439c08b2df902effde171d25e4dbc6c79
https://github.com/jayalfredprufrock/codeigniter-messages/blob/d1891b0439c08b2df902effde171d25e4dbc6c79/libraries/messages.php#L183-L212
train
shgysk8zer0/core_api
traits/fileuploads.php
FileUploads._hasFileKeys
final private static function _hasFileKeys(Array $file): Bool { $valid = true; foreach(['error', 'tmp_name', 'type', 'size', 'name'] as $key) { if (! array_key_exists($key, $file)) { $valid = false; break; } } return $valid; }
php
final private static function _hasFileKeys(Array $file): Bool { $valid = true; foreach(['error', 'tmp_name', 'type', 'size', 'name'] as $key) { if (! array_key_exists($key, $file)) { $valid = false; break; } } return $valid; }
[ "final", "private", "static", "function", "_hasFileKeys", "(", "Array", "$", "file", ")", ":", "Bool", "{", "$", "valid", "=", "true", ";", "foreach", "(", "[", "'error'", ",", "'tmp_name'", ",", "'type'", ",", "'size'", ",", "'name'", "]", "as", "$", "key", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "key", ",", "$", "file", ")", ")", "{", "$", "valid", "=", "false", ";", "break", ";", "}", "}", "return", "$", "valid", ";", "}" ]
Verifies that an array has all keys expected of a file upload @param Array $file Array, such as from `$_FILES` to validate @return Bool If $file has all array keys expected of an upload
[ "Verifies", "that", "an", "array", "has", "all", "keys", "expected", "of", "a", "file", "upload" ]
9e9b8baf761af874b95256ad2462e55fbb2b2e58
https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/fileuploads.php#L136-L146
train
gplcart/cli
controllers/commands/Cart.php
Cart.cmdGetCart
public function cmdGetCart() { $result = $this->getListCart(); $this->outputFormat($result); $this->outputFormatTableCart($result); $this->output(); }
php
public function cmdGetCart() { $result = $this->getListCart(); $this->outputFormat($result); $this->outputFormatTableCart($result); $this->output(); }
[ "public", "function", "cmdGetCart", "(", ")", "{", "$", "result", "=", "$", "this", "->", "getListCart", "(", ")", ";", "$", "this", "->", "outputFormat", "(", "$", "result", ")", ";", "$", "this", "->", "outputFormatTableCart", "(", "$", "result", ")", ";", "$", "this", "->", "output", "(", ")", ";", "}" ]
Callback for "cart-get" command
[ "Callback", "for", "cart", "-", "get", "command" ]
e57dba53e291a225b4bff0c0d9b23d685dd1c125
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Cart.php#L40-L46
train
gplcart/cli
controllers/commands/Cart.php
Cart.cmdDeleteCart
public function cmdDeleteCart() { $id = $this->getParam(0); $options = null; if ($this->getParam('user')) { $options = array('user_id' => $id); } else if ($this->getParam('sku')) { $options = array('sku' => $id); } else if ($this->getParam('order')) { if (!is_numeric($id)) { $this->errorAndExit($this->text('Invalid argument')); } $options = array('order_id' => $id); } if (isset($options)) { $deleted = $count = 0; foreach ($this->cart->getList($options) as $item) { $count++; $deleted += (int) $this->cart->delete($item['cart_id']); } $result = $count && $count == $deleted; } else { if (empty($id) || !is_numeric($id)) { $this->errorAndExit($this->text('Invalid argument')); } $result = $this->cart->delete($id); } if (empty($result)) { $this->errorAndExit($this->text('Unexpected result')); } $this->output(); }
php
public function cmdDeleteCart() { $id = $this->getParam(0); $options = null; if ($this->getParam('user')) { $options = array('user_id' => $id); } else if ($this->getParam('sku')) { $options = array('sku' => $id); } else if ($this->getParam('order')) { if (!is_numeric($id)) { $this->errorAndExit($this->text('Invalid argument')); } $options = array('order_id' => $id); } if (isset($options)) { $deleted = $count = 0; foreach ($this->cart->getList($options) as $item) { $count++; $deleted += (int) $this->cart->delete($item['cart_id']); } $result = $count && $count == $deleted; } else { if (empty($id) || !is_numeric($id)) { $this->errorAndExit($this->text('Invalid argument')); } $result = $this->cart->delete($id); } if (empty($result)) { $this->errorAndExit($this->text('Unexpected result')); } $this->output(); }
[ "public", "function", "cmdDeleteCart", "(", ")", "{", "$", "id", "=", "$", "this", "->", "getParam", "(", "0", ")", ";", "$", "options", "=", "null", ";", "if", "(", "$", "this", "->", "getParam", "(", "'user'", ")", ")", "{", "$", "options", "=", "array", "(", "'user_id'", "=>", "$", "id", ")", ";", "}", "else", "if", "(", "$", "this", "->", "getParam", "(", "'sku'", ")", ")", "{", "$", "options", "=", "array", "(", "'sku'", "=>", "$", "id", ")", ";", "}", "else", "if", "(", "$", "this", "->", "getParam", "(", "'order'", ")", ")", "{", "if", "(", "!", "is_numeric", "(", "$", "id", ")", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Invalid argument'", ")", ")", ";", "}", "$", "options", "=", "array", "(", "'order_id'", "=>", "$", "id", ")", ";", "}", "if", "(", "isset", "(", "$", "options", ")", ")", "{", "$", "deleted", "=", "$", "count", "=", "0", ";", "foreach", "(", "$", "this", "->", "cart", "->", "getList", "(", "$", "options", ")", "as", "$", "item", ")", "{", "$", "count", "++", ";", "$", "deleted", "+=", "(", "int", ")", "$", "this", "->", "cart", "->", "delete", "(", "$", "item", "[", "'cart_id'", "]", ")", ";", "}", "$", "result", "=", "$", "count", "&&", "$", "count", "==", "$", "deleted", ";", "}", "else", "{", "if", "(", "empty", "(", "$", "id", ")", "||", "!", "is_numeric", "(", "$", "id", ")", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Invalid argument'", ")", ")", ";", "}", "$", "result", "=", "$", "this", "->", "cart", "->", "delete", "(", "$", "id", ")", ";", "}", "if", "(", "empty", "(", "$", "result", ")", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Unexpected result'", ")", ")", ";", "}", "$", "this", "->", "output", "(", ")", ";", "}" ]
Callback for "cart-delete" command
[ "Callback", "for", "cart", "-", "delete", "command" ]
e57dba53e291a225b4bff0c0d9b23d685dd1c125
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Cart.php#L51-L94
train
gplcart/cli
controllers/commands/Cart.php
Cart.getListCart
protected function getListCart() { $id = $this->getParam(0); if (!isset($id)) { return $this->cart->getList(array('limit' => $this->getLimit())); } if ($this->getParam('user')) { return $this->cart->getList(array('user_id' => $id, 'limit' => $this->getLimit())); } if ($this->getParam('sku')) { return $this->cart->getList(array('sku' => $id, 'limit' => $this->getLimit())); } if (!is_numeric($id)) { $this->errorAndExit($this->text('Invalid argument')); } if ($this->getParam('order')) { return $this->cart->getList(array('order_id' => $id, 'limit' => $this->getLimit())); } if ($this->getParam('store')) { return $this->cart->getList(array('store_id' => $id, 'limit' => $this->getLimit())); } $result = $this->cart->get($id); if (empty($result)) { $this->errorAndExit($this->text('Unexpected result')); } return array($result); }
php
protected function getListCart() { $id = $this->getParam(0); if (!isset($id)) { return $this->cart->getList(array('limit' => $this->getLimit())); } if ($this->getParam('user')) { return $this->cart->getList(array('user_id' => $id, 'limit' => $this->getLimit())); } if ($this->getParam('sku')) { return $this->cart->getList(array('sku' => $id, 'limit' => $this->getLimit())); } if (!is_numeric($id)) { $this->errorAndExit($this->text('Invalid argument')); } if ($this->getParam('order')) { return $this->cart->getList(array('order_id' => $id, 'limit' => $this->getLimit())); } if ($this->getParam('store')) { return $this->cart->getList(array('store_id' => $id, 'limit' => $this->getLimit())); } $result = $this->cart->get($id); if (empty($result)) { $this->errorAndExit($this->text('Unexpected result')); } return array($result); }
[ "protected", "function", "getListCart", "(", ")", "{", "$", "id", "=", "$", "this", "->", "getParam", "(", "0", ")", ";", "if", "(", "!", "isset", "(", "$", "id", ")", ")", "{", "return", "$", "this", "->", "cart", "->", "getList", "(", "array", "(", "'limit'", "=>", "$", "this", "->", "getLimit", "(", ")", ")", ")", ";", "}", "if", "(", "$", "this", "->", "getParam", "(", "'user'", ")", ")", "{", "return", "$", "this", "->", "cart", "->", "getList", "(", "array", "(", "'user_id'", "=>", "$", "id", ",", "'limit'", "=>", "$", "this", "->", "getLimit", "(", ")", ")", ")", ";", "}", "if", "(", "$", "this", "->", "getParam", "(", "'sku'", ")", ")", "{", "return", "$", "this", "->", "cart", "->", "getList", "(", "array", "(", "'sku'", "=>", "$", "id", ",", "'limit'", "=>", "$", "this", "->", "getLimit", "(", ")", ")", ")", ";", "}", "if", "(", "!", "is_numeric", "(", "$", "id", ")", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Invalid argument'", ")", ")", ";", "}", "if", "(", "$", "this", "->", "getParam", "(", "'order'", ")", ")", "{", "return", "$", "this", "->", "cart", "->", "getList", "(", "array", "(", "'order_id'", "=>", "$", "id", ",", "'limit'", "=>", "$", "this", "->", "getLimit", "(", ")", ")", ")", ";", "}", "if", "(", "$", "this", "->", "getParam", "(", "'store'", ")", ")", "{", "return", "$", "this", "->", "cart", "->", "getList", "(", "array", "(", "'store_id'", "=>", "$", "id", ",", "'limit'", "=>", "$", "this", "->", "getLimit", "(", ")", ")", ")", ";", "}", "$", "result", "=", "$", "this", "->", "cart", "->", "get", "(", "$", "id", ")", ";", "if", "(", "empty", "(", "$", "result", ")", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Unexpected result'", ")", ")", ";", "}", "return", "array", "(", "$", "result", ")", ";", "}" ]
Returns an array of cart items @return array
[ "Returns", "an", "array", "of", "cart", "items" ]
e57dba53e291a225b4bff0c0d9b23d685dd1c125
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Cart.php#L114-L149
train
gplcart/cli
controllers/commands/Cart.php
Cart.submitAddCart
protected function submitAddCart() { $this->setSubmitted(null, $this->getParam()); $this->setSubmittedJson('data'); $this->validateComponent('cart'); $this->addAddCart(); }
php
protected function submitAddCart() { $this->setSubmitted(null, $this->getParam()); $this->setSubmittedJson('data'); $this->validateComponent('cart'); $this->addAddCart(); }
[ "protected", "function", "submitAddCart", "(", ")", "{", "$", "this", "->", "setSubmitted", "(", "null", ",", "$", "this", "->", "getParam", "(", ")", ")", ";", "$", "this", "->", "setSubmittedJson", "(", "'data'", ")", ";", "$", "this", "->", "validateComponent", "(", "'cart'", ")", ";", "$", "this", "->", "addAddCart", "(", ")", ";", "}" ]
Add a new cart item at once
[ "Add", "a", "new", "cart", "item", "at", "once" ]
e57dba53e291a225b4bff0c0d9b23d685dd1c125
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Cart.php#L187-L193
train
gplcart/cli
controllers/commands/Cart.php
Cart.wizardAddCart
protected function wizardAddCart() { // Required $this->validatePrompt('user_id', $this->text('User ID'), 'cart'); $this->validatePrompt('product_id', $this->text('Product ID'), 'cart'); $this->validatePrompt('sku', $this->text('Product SKU'), 'cart'); $this->validatePrompt('store_id', $this->text('Store ID'), 'cart'); // Optional $this->validatePrompt('quantity', $this->text('Quantity'), 'cart', 1); $this->validatePrompt('order_id', $this->text('Order ID'), 'cart', 0); $this->validatePrompt('data', $this->text('Data'), 'cart'); $this->setSubmittedJson('data'); $this->validateComponent('cart'); $this->addAddCart(); }
php
protected function wizardAddCart() { // Required $this->validatePrompt('user_id', $this->text('User ID'), 'cart'); $this->validatePrompt('product_id', $this->text('Product ID'), 'cart'); $this->validatePrompt('sku', $this->text('Product SKU'), 'cart'); $this->validatePrompt('store_id', $this->text('Store ID'), 'cart'); // Optional $this->validatePrompt('quantity', $this->text('Quantity'), 'cart', 1); $this->validatePrompt('order_id', $this->text('Order ID'), 'cart', 0); $this->validatePrompt('data', $this->text('Data'), 'cart'); $this->setSubmittedJson('data'); $this->validateComponent('cart'); $this->addAddCart(); }
[ "protected", "function", "wizardAddCart", "(", ")", "{", "// Required", "$", "this", "->", "validatePrompt", "(", "'user_id'", ",", "$", "this", "->", "text", "(", "'User ID'", ")", ",", "'cart'", ")", ";", "$", "this", "->", "validatePrompt", "(", "'product_id'", ",", "$", "this", "->", "text", "(", "'Product ID'", ")", ",", "'cart'", ")", ";", "$", "this", "->", "validatePrompt", "(", "'sku'", ",", "$", "this", "->", "text", "(", "'Product SKU'", ")", ",", "'cart'", ")", ";", "$", "this", "->", "validatePrompt", "(", "'store_id'", ",", "$", "this", "->", "text", "(", "'Store ID'", ")", ",", "'cart'", ")", ";", "// Optional", "$", "this", "->", "validatePrompt", "(", "'quantity'", ",", "$", "this", "->", "text", "(", "'Quantity'", ")", ",", "'cart'", ",", "1", ")", ";", "$", "this", "->", "validatePrompt", "(", "'order_id'", ",", "$", "this", "->", "text", "(", "'Order ID'", ")", ",", "'cart'", ",", "0", ")", ";", "$", "this", "->", "validatePrompt", "(", "'data'", ",", "$", "this", "->", "text", "(", "'Data'", ")", ",", "'cart'", ")", ";", "$", "this", "->", "setSubmittedJson", "(", "'data'", ")", ";", "$", "this", "->", "validateComponent", "(", "'cart'", ")", ";", "$", "this", "->", "addAddCart", "(", ")", ";", "}" ]
Add a new cart item step by step
[ "Add", "a", "new", "cart", "item", "step", "by", "step" ]
e57dba53e291a225b4bff0c0d9b23d685dd1c125
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Cart.php#L198-L214
train
gplcart/cli
controllers/commands/Cart.php
Cart.addAddCart
protected function addAddCart() { if (!$this->isError()) { $id = $this->cart->add($this->getSubmitted()); if (empty($id)) { $this->errorAndExit($this->text('Unexpected result')); } $this->line($id); } }
php
protected function addAddCart() { if (!$this->isError()) { $id = $this->cart->add($this->getSubmitted()); if (empty($id)) { $this->errorAndExit($this->text('Unexpected result')); } $this->line($id); } }
[ "protected", "function", "addAddCart", "(", ")", "{", "if", "(", "!", "$", "this", "->", "isError", "(", ")", ")", "{", "$", "id", "=", "$", "this", "->", "cart", "->", "add", "(", "$", "this", "->", "getSubmitted", "(", ")", ")", ";", "if", "(", "empty", "(", "$", "id", ")", ")", "{", "$", "this", "->", "errorAndExit", "(", "$", "this", "->", "text", "(", "'Unexpected result'", ")", ")", ";", "}", "$", "this", "->", "line", "(", "$", "id", ")", ";", "}", "}" ]
Add a new cart item
[ "Add", "a", "new", "cart", "item" ]
e57dba53e291a225b4bff0c0d9b23d685dd1c125
https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Cart.php#L219-L228
train
koolkode/context
src/Scope/AbstractScopeManager.php
AbstractScopeManager.bindContext
protected function bindContext($object = NULL) { if($object !== NULL && !is_object($object)) { throw new \InvalidArgumentException(sprintf('Expecting an object, given %s', gettype($object))); } $previous = $this->context; $this->context = $object; if($object === NULL) { $this->proxies = new \SplObjectStorage(); return $previous; } if($this->contextualInstances->offsetExists($object)) { $this->proxies = $this->contextualInstances[$object]; } else { $this->proxies = new \SplObjectStorage(); $this->contextualInstances[$object] = $this->proxies; } return $previous; }
php
protected function bindContext($object = NULL) { if($object !== NULL && !is_object($object)) { throw new \InvalidArgumentException(sprintf('Expecting an object, given %s', gettype($object))); } $previous = $this->context; $this->context = $object; if($object === NULL) { $this->proxies = new \SplObjectStorage(); return $previous; } if($this->contextualInstances->offsetExists($object)) { $this->proxies = $this->contextualInstances[$object]; } else { $this->proxies = new \SplObjectStorage(); $this->contextualInstances[$object] = $this->proxies; } return $previous; }
[ "protected", "function", "bindContext", "(", "$", "object", "=", "NULL", ")", "{", "if", "(", "$", "object", "!==", "NULL", "&&", "!", "is_object", "(", "$", "object", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Expecting an object, given %s'", ",", "gettype", "(", "$", "object", ")", ")", ")", ";", "}", "$", "previous", "=", "$", "this", "->", "context", ";", "$", "this", "->", "context", "=", "$", "object", ";", "if", "(", "$", "object", "===", "NULL", ")", "{", "$", "this", "->", "proxies", "=", "new", "\\", "SplObjectStorage", "(", ")", ";", "return", "$", "previous", ";", "}", "if", "(", "$", "this", "->", "contextualInstances", "->", "offsetExists", "(", "$", "object", ")", ")", "{", "$", "this", "->", "proxies", "=", "$", "this", "->", "contextualInstances", "[", "$", "object", "]", ";", "}", "else", "{", "$", "this", "->", "proxies", "=", "new", "\\", "SplObjectStorage", "(", ")", ";", "$", "this", "->", "contextualInstances", "[", "$", "object", "]", "=", "$", "this", "->", "proxies", ";", "}", "return", "$", "previous", ";", "}" ]
Bind the scope to the given object. @param object $object @return object The previous context or NULL when the scope was not active.
[ "Bind", "the", "scope", "to", "the", "given", "object", "." ]
f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36
https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/Scope/AbstractScopeManager.php#L226-L254
train
koolkode/context
src/Scope/AbstractScopeManager.php
AbstractScopeManager.unbindContext
protected function unbindContext($object, $terminate = true) { if(!is_object($object)) { throw new \InvalidArgumentException(sprintf('Expecting an object, given %s', gettype($object))); } if($this->context === $object) { $this->context = NULL; $this->proxies = new \SplObjectStorage(); } if($terminate && $this->contextualInstances->offsetExists($object)) { unset($this->contextualInstances[$object]); } }
php
protected function unbindContext($object, $terminate = true) { if(!is_object($object)) { throw new \InvalidArgumentException(sprintf('Expecting an object, given %s', gettype($object))); } if($this->context === $object) { $this->context = NULL; $this->proxies = new \SplObjectStorage(); } if($terminate && $this->contextualInstances->offsetExists($object)) { unset($this->contextualInstances[$object]); } }
[ "protected", "function", "unbindContext", "(", "$", "object", ",", "$", "terminate", "=", "true", ")", "{", "if", "(", "!", "is_object", "(", "$", "object", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Expecting an object, given %s'", ",", "gettype", "(", "$", "object", ")", ")", ")", ";", "}", "if", "(", "$", "this", "->", "context", "===", "$", "object", ")", "{", "$", "this", "->", "context", "=", "NULL", ";", "$", "this", "->", "proxies", "=", "new", "\\", "SplObjectStorage", "(", ")", ";", "}", "if", "(", "$", "terminate", "&&", "$", "this", "->", "contextualInstances", "->", "offsetExists", "(", "$", "object", ")", ")", "{", "unset", "(", "$", "this", "->", "contextualInstances", "[", "$", "object", "]", ")", ";", "}", "}" ]
Unbind scope from the given object, will optionally destroy all contextual instances bound to the object. @param object $object @param boolean $terminate Clear all contextual instances? @throws \InvalidArgumentException
[ "Unbind", "scope", "from", "the", "given", "object", "will", "optionally", "destroy", "all", "contextual", "instances", "bound", "to", "the", "object", "." ]
f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36
https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/Scope/AbstractScopeManager.php#L264-L281
train
koolkode/context
src/Scope/AbstractScopeManager.php
AbstractScopeManager.initializeProxy
protected function initializeProxy($typeName, callable $factory = NULL) { $proxyName = $this->container->loadScopedProxy($typeName); if($factory === NULL) { $factory = function() { throw new ScopeNotActiveException(sprintf('Scope "%s" is not active', $this->getScope())); }; } return new $proxyName(new DelegateBinding($typeName, $this->getScope(), 0, $factory), $this, $this->proxies); }
php
protected function initializeProxy($typeName, callable $factory = NULL) { $proxyName = $this->container->loadScopedProxy($typeName); if($factory === NULL) { $factory = function() { throw new ScopeNotActiveException(sprintf('Scope "%s" is not active', $this->getScope())); }; } return new $proxyName(new DelegateBinding($typeName, $this->getScope(), 0, $factory), $this, $this->proxies); }
[ "protected", "function", "initializeProxy", "(", "$", "typeName", ",", "callable", "$", "factory", "=", "NULL", ")", "{", "$", "proxyName", "=", "$", "this", "->", "container", "->", "loadScopedProxy", "(", "$", "typeName", ")", ";", "if", "(", "$", "factory", "===", "NULL", ")", "{", "$", "factory", "=", "function", "(", ")", "{", "throw", "new", "ScopeNotActiveException", "(", "sprintf", "(", "'Scope \"%s\" is not active'", ",", "$", "this", "->", "getScope", "(", ")", ")", ")", ";", "}", ";", "}", "return", "new", "$", "proxyName", "(", "new", "DelegateBinding", "(", "$", "typeName", ",", "$", "this", "->", "getScope", "(", ")", ",", "0", ",", "$", "factory", ")", ",", "$", "this", ",", "$", "this", "->", "proxies", ")", ";", "}" ]
Create a scoped proxy for the given type. @param string $typeName @param callable $factory Will be called when the proxy is activated. @return ScopedProxyInterface
[ "Create", "a", "scoped", "proxy", "for", "the", "given", "type", "." ]
f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36
https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/Scope/AbstractScopeManager.php#L290-L302
train
koolkode/context
src/Scope/AbstractScopeManager.php
AbstractScopeManager.bindFactoryProxy
protected function bindFactoryProxy($typeName, callable $factory) { $proxy = $this->initializeProxy($typeName, $factory); $this->scopedProxies[$proxy->K2GetProxyBinding()] = $proxy; $this->container->bindInstance($typeName, $proxy, true); return $proxy; }
php
protected function bindFactoryProxy($typeName, callable $factory) { $proxy = $this->initializeProxy($typeName, $factory); $this->scopedProxies[$proxy->K2GetProxyBinding()] = $proxy; $this->container->bindInstance($typeName, $proxy, true); return $proxy; }
[ "protected", "function", "bindFactoryProxy", "(", "$", "typeName", ",", "callable", "$", "factory", ")", "{", "$", "proxy", "=", "$", "this", "->", "initializeProxy", "(", "$", "typeName", ",", "$", "factory", ")", ";", "$", "this", "->", "scopedProxies", "[", "$", "proxy", "->", "K2GetProxyBinding", "(", ")", "]", "=", "$", "proxy", ";", "$", "this", "->", "container", "->", "bindInstance", "(", "$", "typeName", ",", "$", "proxy", ",", "true", ")", ";", "return", "$", "proxy", ";", "}" ]
Creates a factory-based proxy for the target type and binds it to the DI container. @param string $typeName @param callable $factory @return ScopedProxyInterface
[ "Creates", "a", "factory", "-", "based", "proxy", "for", "the", "target", "type", "and", "binds", "it", "to", "the", "DI", "container", "." ]
f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36
https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/Scope/AbstractScopeManager.php#L311-L319
train
Xsaven/laravel-intelect-admin
src/Console/UninstallCommand.php
UninstallCommand.removeFilesAndDirectories
protected function removeFilesAndDirectories() { $this->laravel['files']->deleteDirectory(config('lia.directory')); $this->laravel['files']->deleteDirectory(public_path('vendor/lia/')); $this->laravel['files']->delete(config_path('lia.php')); $this->laravel['files']->delete(config_path('terminal.php')); }
php
protected function removeFilesAndDirectories() { $this->laravel['files']->deleteDirectory(config('lia.directory')); $this->laravel['files']->deleteDirectory(public_path('vendor/lia/')); $this->laravel['files']->delete(config_path('lia.php')); $this->laravel['files']->delete(config_path('terminal.php')); }
[ "protected", "function", "removeFilesAndDirectories", "(", ")", "{", "$", "this", "->", "laravel", "[", "'files'", "]", "->", "deleteDirectory", "(", "config", "(", "'lia.directory'", ")", ")", ";", "$", "this", "->", "laravel", "[", "'files'", "]", "->", "deleteDirectory", "(", "public_path", "(", "'vendor/lia/'", ")", ")", ";", "$", "this", "->", "laravel", "[", "'files'", "]", "->", "delete", "(", "config_path", "(", "'lia.php'", ")", ")", ";", "$", "this", "->", "laravel", "[", "'files'", "]", "->", "delete", "(", "config_path", "(", "'terminal.php'", ")", ")", ";", "}" ]
Remove files and directories. @return void
[ "Remove", "files", "and", "directories", "." ]
592574633d12c74cf25b43dd6694fee496abefcb
https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Console/UninstallCommand.php#L44-L50
train
bkstg/schedule-bundle
EventSubscriber/ProductionMenuSubscriber.php
ProductionMenuSubscriber.addScheduleItem
public function addScheduleItem(ProductionMenuCollectionEvent $event): void { $menu = $event->getMenu(); $group = $event->getGroup(); // Create overview menu item. $schedule = $this->factory->createItem('menu_item.schedule', [ 'route' => 'bkstg_calendar_production', 'routeParameters' => ['production_slug' => $group->getSlug()], 'extras' => [ 'icon' => 'calendar', 'translation_domain' => BkstgScheduleBundle::TRANSLATION_DOMAIN, ], ]); $menu->addChild($schedule); // If this user is an editor create the calendar and archive items. if ($this->auth->isGranted('GROUP_ROLE_EDITOR', $group)) { $calendar = $this->factory->createItem('menu_item.schedule_calendar', [ 'route' => 'bkstg_calendar_production', 'routeParameters' => ['production_slug' => $group->getSlug()], 'extras' => ['translation_domain' => BkstgScheduleBundle::TRANSLATION_DOMAIN], ]); $schedule->addChild($calendar); $archive = $this->factory->createItem('menu_item.schedule_archive', [ 'route' => 'bkstg_schedule_archive', 'routeParameters' => ['production_slug' => $group->getSlug()], 'extras' => ['translation_domain' => BkstgScheduleBundle::TRANSLATION_DOMAIN], ]); $schedule->addChild($archive); } }
php
public function addScheduleItem(ProductionMenuCollectionEvent $event): void { $menu = $event->getMenu(); $group = $event->getGroup(); // Create overview menu item. $schedule = $this->factory->createItem('menu_item.schedule', [ 'route' => 'bkstg_calendar_production', 'routeParameters' => ['production_slug' => $group->getSlug()], 'extras' => [ 'icon' => 'calendar', 'translation_domain' => BkstgScheduleBundle::TRANSLATION_DOMAIN, ], ]); $menu->addChild($schedule); // If this user is an editor create the calendar and archive items. if ($this->auth->isGranted('GROUP_ROLE_EDITOR', $group)) { $calendar = $this->factory->createItem('menu_item.schedule_calendar', [ 'route' => 'bkstg_calendar_production', 'routeParameters' => ['production_slug' => $group->getSlug()], 'extras' => ['translation_domain' => BkstgScheduleBundle::TRANSLATION_DOMAIN], ]); $schedule->addChild($calendar); $archive = $this->factory->createItem('menu_item.schedule_archive', [ 'route' => 'bkstg_schedule_archive', 'routeParameters' => ['production_slug' => $group->getSlug()], 'extras' => ['translation_domain' => BkstgScheduleBundle::TRANSLATION_DOMAIN], ]); $schedule->addChild($archive); } }
[ "public", "function", "addScheduleItem", "(", "ProductionMenuCollectionEvent", "$", "event", ")", ":", "void", "{", "$", "menu", "=", "$", "event", "->", "getMenu", "(", ")", ";", "$", "group", "=", "$", "event", "->", "getGroup", "(", ")", ";", "// Create overview menu item.", "$", "schedule", "=", "$", "this", "->", "factory", "->", "createItem", "(", "'menu_item.schedule'", ",", "[", "'route'", "=>", "'bkstg_calendar_production'", ",", "'routeParameters'", "=>", "[", "'production_slug'", "=>", "$", "group", "->", "getSlug", "(", ")", "]", ",", "'extras'", "=>", "[", "'icon'", "=>", "'calendar'", ",", "'translation_domain'", "=>", "BkstgScheduleBundle", "::", "TRANSLATION_DOMAIN", ",", "]", ",", "]", ")", ";", "$", "menu", "->", "addChild", "(", "$", "schedule", ")", ";", "// If this user is an editor create the calendar and archive items.", "if", "(", "$", "this", "->", "auth", "->", "isGranted", "(", "'GROUP_ROLE_EDITOR'", ",", "$", "group", ")", ")", "{", "$", "calendar", "=", "$", "this", "->", "factory", "->", "createItem", "(", "'menu_item.schedule_calendar'", ",", "[", "'route'", "=>", "'bkstg_calendar_production'", ",", "'routeParameters'", "=>", "[", "'production_slug'", "=>", "$", "group", "->", "getSlug", "(", ")", "]", ",", "'extras'", "=>", "[", "'translation_domain'", "=>", "BkstgScheduleBundle", "::", "TRANSLATION_DOMAIN", "]", ",", "]", ")", ";", "$", "schedule", "->", "addChild", "(", "$", "calendar", ")", ";", "$", "archive", "=", "$", "this", "->", "factory", "->", "createItem", "(", "'menu_item.schedule_archive'", ",", "[", "'route'", "=>", "'bkstg_schedule_archive'", ",", "'routeParameters'", "=>", "[", "'production_slug'", "=>", "$", "group", "->", "getSlug", "(", ")", "]", ",", "'extras'", "=>", "[", "'translation_domain'", "=>", "BkstgScheduleBundle", "::", "TRANSLATION_DOMAIN", "]", ",", "]", ")", ";", "$", "schedule", "->", "addChild", "(", "$", "archive", ")", ";", "}", "}" ]
Add the schedule menu item. @param ProductionMenuCollectionEvent $event The menu collection event. @return void
[ "Add", "the", "schedule", "menu", "item", "." ]
e64ac897aa7b28bc48319470d65de13cd4788afe
https://github.com/bkstg/schedule-bundle/blob/e64ac897aa7b28bc48319470d65de13cd4788afe/EventSubscriber/ProductionMenuSubscriber.php#L60-L92
train
inwendo/iw_client_latex_php
lib/Api/DocumentApi.php
DocumentApi.setApiClient
public function setApiClient(\Inwendo\Latex\Common\ApiClient $apiClient) { $this->apiClient = $apiClient; return $this; }
php
public function setApiClient(\Inwendo\Latex\Common\ApiClient $apiClient) { $this->apiClient = $apiClient; return $this; }
[ "public", "function", "setApiClient", "(", "\\", "Inwendo", "\\", "Latex", "\\", "Common", "\\", "ApiClient", "$", "apiClient", ")", "{", "$", "this", "->", "apiClient", "=", "$", "apiClient", ";", "return", "$", "this", ";", "}" ]
Set the API client @param \Inwendo\Latex\Common\ApiClient $apiClient set the API client @return DocumentApi
[ "Set", "the", "API", "client" ]
6f24b2cf473a4981845666f20fa906994bada5c2
https://github.com/inwendo/iw_client_latex_php/blob/6f24b2cf473a4981845666f20fa906994bada5c2/lib/Api/DocumentApi.php#L99-L103
train
sndsgd/sndsgd-field
src/Field.php
Field.addAliases
public function addAliases($alias) { foreach (func_get_args() as $alias) { $this->aliases[$alias] = true; } return $this; }
php
public function addAliases($alias) { foreach (func_get_args() as $alias) { $this->aliases[$alias] = true; } return $this; }
[ "public", "function", "addAliases", "(", "$", "alias", ")", "{", "foreach", "(", "func_get_args", "(", ")", "as", "$", "alias", ")", "{", "$", "this", "->", "aliases", "[", "$", "alias", "]", "=", "true", ";", "}", "return", "$", "this", ";", "}" ]
Add one or more aliases to the field @param string $alias,... @return \sndsgd\Field
[ "Add", "one", "or", "more", "aliases", "to", "the", "field" ]
34ac3aabfe031bd9b259b3b93e84964b04031334
https://github.com/sndsgd/sndsgd-field/blob/34ac3aabfe031bd9b259b3b93e84964b04031334/src/Field.php#L140-L146
train
sndsgd/sndsgd-field
src/Field.php
Field.setExportHandler
public function setExportHandler($type) { if ( $type === self::EXPORT_NORMAL || $type === self::EXPORT_ARRAY || $type === self::EXPORT_SKIP || is_callable($type) ) { $this->exportHandler = $type; return $this; } throw new InvalidArgumentException( "invalid value provided for 'type'; ". "expecting a callable, or one of the following contstants: ". "sndsgd\Field::EXPORT_NORMAL, sndsgd\Field::EXPORT_ARRAY, or ". "sndsgd\Field::EXPORT_SKIP" ); }
php
public function setExportHandler($type) { if ( $type === self::EXPORT_NORMAL || $type === self::EXPORT_ARRAY || $type === self::EXPORT_SKIP || is_callable($type) ) { $this->exportHandler = $type; return $this; } throw new InvalidArgumentException( "invalid value provided for 'type'; ". "expecting a callable, or one of the following contstants: ". "sndsgd\Field::EXPORT_NORMAL, sndsgd\Field::EXPORT_ARRAY, or ". "sndsgd\Field::EXPORT_SKIP" ); }
[ "public", "function", "setExportHandler", "(", "$", "type", ")", "{", "if", "(", "$", "type", "===", "self", "::", "EXPORT_NORMAL", "||", "$", "type", "===", "self", "::", "EXPORT_ARRAY", "||", "$", "type", "===", "self", "::", "EXPORT_SKIP", "||", "is_callable", "(", "$", "type", ")", ")", "{", "$", "this", "->", "exportHandler", "=", "$", "type", ";", "return", "$", "this", ";", "}", "throw", "new", "InvalidArgumentException", "(", "\"invalid value provided for 'type'; \"", ".", "\"expecting a callable, or one of the following contstants: \"", ".", "\"sndsgd\\Field::EXPORT_NORMAL, sndsgd\\Field::EXPORT_ARRAY, or \"", ".", "\"sndsgd\\Field::EXPORT_SKIP\"", ")", ";", "}" ]
Set the method by which to export the value @param integer|callable $type @return \sndsgd\Field @throws InvalidArgumentException If $type is not valid
[ "Set", "the", "method", "by", "which", "to", "export", "the", "value" ]
34ac3aabfe031bd9b259b3b93e84964b04031334
https://github.com/sndsgd/sndsgd-field/blob/34ac3aabfe031bd9b259b3b93e84964b04031334/src/Field.php#L232-L250
train
sndsgd/sndsgd-field
src/Field.php
Field.addValue
public function addValue($value, $index = null) { if ($this->value === null) { $this->value = []; } if ($index === null) { $this->value[] = $value; } else { $this->value[$index] = $value; } return $this; }
php
public function addValue($value, $index = null) { if ($this->value === null) { $this->value = []; } if ($index === null) { $this->value[] = $value; } else { $this->value[$index] = $value; } return $this; }
[ "public", "function", "addValue", "(", "$", "value", ",", "$", "index", "=", "null", ")", "{", "if", "(", "$", "this", "->", "value", "===", "null", ")", "{", "$", "this", "->", "value", "=", "[", "]", ";", "}", "if", "(", "$", "index", "===", "null", ")", "{", "$", "this", "->", "value", "[", "]", "=", "$", "value", ";", "}", "else", "{", "$", "this", "->", "value", "[", "$", "index", "]", "=", "$", "value", ";", "}", "return", "$", "this", ";", "}" ]
Add a value @param string|number $value The value to add @param string|integer|null $index The value key in the values array @return \sndsgd\Field
[ "Add", "a", "value" ]
34ac3aabfe031bd9b259b3b93e84964b04031334
https://github.com/sndsgd/sndsgd-field/blob/34ac3aabfe031bd9b259b3b93e84964b04031334/src/Field.php#L267-L281
train
sndsgd/sndsgd-field
src/Field.php
Field.setValue
public function setValue($value, $index = null) { if ($index === null) { $this->value = Arr::cast($value); } else { $this->value[$index] = $value; } return $this; }
php
public function setValue($value, $index = null) { if ($index === null) { $this->value = Arr::cast($value); } else { $this->value[$index] = $value; } return $this; }
[ "public", "function", "setValue", "(", "$", "value", ",", "$", "index", "=", "null", ")", "{", "if", "(", "$", "index", "===", "null", ")", "{", "$", "this", "->", "value", "=", "Arr", "::", "cast", "(", "$", "value", ")", ";", "}", "else", "{", "$", "this", "->", "value", "[", "$", "index", "]", "=", "$", "value", ";", "}", "return", "$", "this", ";", "}" ]
Set one or all values @param string|integer|float|array<string|integer|float> $value @param integer|null $index @return \sndsgd\Field
[ "Set", "one", "or", "all", "values" ]
34ac3aabfe031bd9b259b3b93e84964b04031334
https://github.com/sndsgd/sndsgd-field/blob/34ac3aabfe031bd9b259b3b93e84964b04031334/src/Field.php#L290-L299
train
sndsgd/sndsgd-field
src/Field.php
Field.getValue
public function getValue($index = 0) { if ($index === 0 && $this->value === null) { return $this->defaultValue; } return (is_array($this->value) && array_key_exists($index, $this->value)) ? $this->value[$index] : null; }
php
public function getValue($index = 0) { if ($index === 0 && $this->value === null) { return $this->defaultValue; } return (is_array($this->value) && array_key_exists($index, $this->value)) ? $this->value[$index] : null; }
[ "public", "function", "getValue", "(", "$", "index", "=", "0", ")", "{", "if", "(", "$", "index", "===", "0", "&&", "$", "this", "->", "value", "===", "null", ")", "{", "return", "$", "this", "->", "defaultValue", ";", "}", "return", "(", "is_array", "(", "$", "this", "->", "value", ")", "&&", "array_key_exists", "(", "$", "index", ",", "$", "this", "->", "value", ")", ")", "?", "$", "this", "->", "value", "[", "$", "index", "]", ":", "null", ";", "}" ]
Get a single value @param integer $index @return number|string|null
[ "Get", "a", "single", "value" ]
34ac3aabfe031bd9b259b3b93e84964b04031334
https://github.com/sndsgd/sndsgd-field/blob/34ac3aabfe031bd9b259b3b93e84964b04031334/src/Field.php#L318-L327
train
sndsgd/sndsgd-field
src/Field.php
Field.getValuesAsArray
private function getValuesAsArray() { if ($this->value === null) { return is_array($this->defaultValue) ? $this->defaultValue : [ $this->defaultValue ]; } return $this->value; }
php
private function getValuesAsArray() { if ($this->value === null) { return is_array($this->defaultValue) ? $this->defaultValue : [ $this->defaultValue ]; } return $this->value; }
[ "private", "function", "getValuesAsArray", "(", ")", "{", "if", "(", "$", "this", "->", "value", "===", "null", ")", "{", "return", "is_array", "(", "$", "this", "->", "defaultValue", ")", "?", "$", "this", "->", "defaultValue", ":", "[", "$", "this", "->", "defaultValue", "]", ";", "}", "return", "$", "this", "->", "value", ";", "}" ]
Get all of the current values as an array of values If no value is currently set, the default value will be returned @return array<string|integer|float|boolean|null>
[ "Get", "all", "of", "the", "current", "values", "as", "an", "array", "of", "values" ]
34ac3aabfe031bd9b259b3b93e84964b04031334
https://github.com/sndsgd/sndsgd-field/blob/34ac3aabfe031bd9b259b3b93e84964b04031334/src/Field.php#L335-L343
train
sndsgd/sndsgd-field
src/Field.php
Field.addRule
public function addRule(Rule $rule) { $classname = $rule->getClass(); if ($this->hasRule($classname) === true) { throw new Exception( "failed to add rule; the field {$this->name} already has an ". "instance of '$classname'" ); } else if ($classname === Rule::REQUIRED) { $this->rules = [$classname => $rule] + $this->rules; } else { $this->rules[$classname] = $rule; } return $this; }
php
public function addRule(Rule $rule) { $classname = $rule->getClass(); if ($this->hasRule($classname) === true) { throw new Exception( "failed to add rule; the field {$this->name} already has an ". "instance of '$classname'" ); } else if ($classname === Rule::REQUIRED) { $this->rules = [$classname => $rule] + $this->rules; } else { $this->rules[$classname] = $rule; } return $this; }
[ "public", "function", "addRule", "(", "Rule", "$", "rule", ")", "{", "$", "classname", "=", "$", "rule", "->", "getClass", "(", ")", ";", "if", "(", "$", "this", "->", "hasRule", "(", "$", "classname", ")", "===", "true", ")", "{", "throw", "new", "Exception", "(", "\"failed to add rule; the field {$this->name} already has an \"", ".", "\"instance of '$classname'\"", ")", ";", "}", "else", "if", "(", "$", "classname", "===", "Rule", "::", "REQUIRED", ")", "{", "$", "this", "->", "rules", "=", "[", "$", "classname", "=>", "$", "rule", "]", "+", "$", "this", "->", "rules", ";", "}", "else", "{", "$", "this", "->", "rules", "[", "$", "classname", "]", "=", "$", "rule", ";", "}", "return", "$", "this", ";", "}" ]
Add a validation rule to the field @param \sndsgd\field\Rule $rule @return \sndsgd\Field The field instance
[ "Add", "a", "validation", "rule", "to", "the", "field" ]
34ac3aabfe031bd9b259b3b93e84964b04031334
https://github.com/sndsgd/sndsgd-field/blob/34ac3aabfe031bd9b259b3b93e84964b04031334/src/Field.php#L381-L397
train
sndsgd/sndsgd-field
src/Field.php
Field.validate
public function validate(Collection $collection = null) { $this->errors = []; foreach ($this->getValuesAsArray() as $index => $value) { # skip fields with a null value if they are not required if ($value === null && $this->hasRule(Rule::REQUIRED) === false) { continue; } foreach ($this->rules as $name => $rule) { $rule->setValue($value); $rule->setField($this, $index); $rule->setCollection($collection); if ($rule->validate() === true) { $fmtValue = $rule->getValue(); if ($fmtValue !== $value) { $value = $fmtValue; $this->setValue($fmtValue, $index); } } else { $this->errors[] = $rule->getError(); break; } } } return count($this->errors) === 0; }
php
public function validate(Collection $collection = null) { $this->errors = []; foreach ($this->getValuesAsArray() as $index => $value) { # skip fields with a null value if they are not required if ($value === null && $this->hasRule(Rule::REQUIRED) === false) { continue; } foreach ($this->rules as $name => $rule) { $rule->setValue($value); $rule->setField($this, $index); $rule->setCollection($collection); if ($rule->validate() === true) { $fmtValue = $rule->getValue(); if ($fmtValue !== $value) { $value = $fmtValue; $this->setValue($fmtValue, $index); } } else { $this->errors[] = $rule->getError(); break; } } } return count($this->errors) === 0; }
[ "public", "function", "validate", "(", "Collection", "$", "collection", "=", "null", ")", "{", "$", "this", "->", "errors", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "getValuesAsArray", "(", ")", "as", "$", "index", "=>", "$", "value", ")", "{", "# skip fields with a null value if they are not required", "if", "(", "$", "value", "===", "null", "&&", "$", "this", "->", "hasRule", "(", "Rule", "::", "REQUIRED", ")", "===", "false", ")", "{", "continue", ";", "}", "foreach", "(", "$", "this", "->", "rules", "as", "$", "name", "=>", "$", "rule", ")", "{", "$", "rule", "->", "setValue", "(", "$", "value", ")", ";", "$", "rule", "->", "setField", "(", "$", "this", ",", "$", "index", ")", ";", "$", "rule", "->", "setCollection", "(", "$", "collection", ")", ";", "if", "(", "$", "rule", "->", "validate", "(", ")", "===", "true", ")", "{", "$", "fmtValue", "=", "$", "rule", "->", "getValue", "(", ")", ";", "if", "(", "$", "fmtValue", "!==", "$", "value", ")", "{", "$", "value", "=", "$", "fmtValue", ";", "$", "this", "->", "setValue", "(", "$", "fmtValue", ",", "$", "index", ")", ";", "}", "}", "else", "{", "$", "this", "->", "errors", "[", "]", "=", "$", "rule", "->", "getError", "(", ")", ";", "break", ";", "}", "}", "}", "return", "count", "(", "$", "this", "->", "errors", ")", "===", "0", ";", "}" ]
Validate all the values in the field @param \sndsgd\field\Collection|null $collection A field collection @return boolean True if all values are
[ "Validate", "all", "the", "values", "in", "the", "field" ]
34ac3aabfe031bd9b259b3b93e84964b04031334
https://github.com/sndsgd/sndsgd-field/blob/34ac3aabfe031bd9b259b3b93e84964b04031334/src/Field.php#L440-L467
train
TuumPHP/Web
src/Middleware/MatchRootTrait.php
MatchRootTrait.matchRoot
public function matchRoot(&$request) { // empty means match always. if (empty($this->_patterns)) { return true; } $path = $request->getPathToMatch(); $method = $request->getMethod(); foreach ($this->_patterns as $pattern) { if ($matched = Matcher::verify($pattern, $path, $method)) { if (isset($matched['matched'])) { $request = $request->withPathToMatch($matched['matched'], $matched['trailing']); } return true; } } return false; }
php
public function matchRoot(&$request) { // empty means match always. if (empty($this->_patterns)) { return true; } $path = $request->getPathToMatch(); $method = $request->getMethod(); foreach ($this->_patterns as $pattern) { if ($matched = Matcher::verify($pattern, $path, $method)) { if (isset($matched['matched'])) { $request = $request->withPathToMatch($matched['matched'], $matched['trailing']); } return true; } } return false; }
[ "public", "function", "matchRoot", "(", "&", "$", "request", ")", "{", "// empty means match always.", "if", "(", "empty", "(", "$", "this", "->", "_patterns", ")", ")", "{", "return", "true", ";", "}", "$", "path", "=", "$", "request", "->", "getPathToMatch", "(", ")", ";", "$", "method", "=", "$", "request", "->", "getMethod", "(", ")", ";", "foreach", "(", "$", "this", "->", "_patterns", "as", "$", "pattern", ")", "{", "if", "(", "$", "matched", "=", "Matcher", "::", "verify", "(", "$", "pattern", ",", "$", "path", ",", "$", "method", ")", ")", "{", "if", "(", "isset", "(", "$", "matched", "[", "'matched'", "]", ")", ")", "{", "$", "request", "=", "$", "request", "->", "withPathToMatch", "(", "$", "matched", "[", "'matched'", "]", ",", "$", "matched", "[", "'trailing'", "]", ")", ";", "}", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
check if the requested path matches with the root. returns $request if matches, or return false if not matched (i.e. execute the next middleware). @param Request $request @return bool
[ "check", "if", "the", "requested", "path", "matches", "with", "the", "root", "." ]
8f296b6358aa93226ce08d6cc54a309f5b0a9820
https://github.com/TuumPHP/Web/blob/8f296b6358aa93226ce08d6cc54a309f5b0a9820/src/Middleware/MatchRootTrait.php#L42-L59
train
jmfeurprier/perf-caching
lib/perf/Caching/FileSystemStorage.php
FileSystemStorage.flushAll
public function flushAll() { $mask = '*' . self::CACHE_FILE_SUFFIX; foreach (glob($this->basePath . $mask) as $cacheFilePath) { if (!unlink($cacheFilePath)) { throw new \RuntimeException("Failed to delete cache file '{$cacheFilePath}'."); } } }
php
public function flushAll() { $mask = '*' . self::CACHE_FILE_SUFFIX; foreach (glob($this->basePath . $mask) as $cacheFilePath) { if (!unlink($cacheFilePath)) { throw new \RuntimeException("Failed to delete cache file '{$cacheFilePath}'."); } } }
[ "public", "function", "flushAll", "(", ")", "{", "$", "mask", "=", "'*'", ".", "self", "::", "CACHE_FILE_SUFFIX", ";", "foreach", "(", "glob", "(", "$", "this", "->", "basePath", ".", "$", "mask", ")", "as", "$", "cacheFilePath", ")", "{", "if", "(", "!", "unlink", "(", "$", "cacheFilePath", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "\"Failed to delete cache file '{$cacheFilePath}'.\"", ")", ";", "}", "}", "}" ]
Deletes every cache file. @return void @throws \RuntimeException
[ "Deletes", "every", "cache", "file", "." ]
16cf61dae3aa4d6dcb8722e14760934457087173
https://github.com/jmfeurprier/perf-caching/blob/16cf61dae3aa4d6dcb8722e14760934457087173/lib/perf/Caching/FileSystemStorage.php#L114-L123
train
itkg/core
src/Itkg/Core/Legacy/Kernel.php
Kernel.loadRouting
protected function loadRouting() { $parser = new YamlParser(); $routes = array(); foreach ($this->getRoutingFiles() as $file) { $routes = array_merge($routes, $parser->parse(file_get_contents($file))); } foreach ($routes as $name => $routeInfos) { $this->processRouteInfos($name, $routeInfos); } return $this; }
php
protected function loadRouting() { $parser = new YamlParser(); $routes = array(); foreach ($this->getRoutingFiles() as $file) { $routes = array_merge($routes, $parser->parse(file_get_contents($file))); } foreach ($routes as $name => $routeInfos) { $this->processRouteInfos($name, $routeInfos); } return $this; }
[ "protected", "function", "loadRouting", "(", ")", "{", "$", "parser", "=", "new", "YamlParser", "(", ")", ";", "$", "routes", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "getRoutingFiles", "(", ")", "as", "$", "file", ")", "{", "$", "routes", "=", "array_merge", "(", "$", "routes", ",", "$", "parser", "->", "parse", "(", "file_get_contents", "(", "$", "file", ")", ")", ")", ";", "}", "foreach", "(", "$", "routes", "as", "$", "name", "=>", "$", "routeInfos", ")", "{", "$", "this", "->", "processRouteInfos", "(", "$", "name", ",", "$", "routeInfos", ")", ";", "}", "return", "$", "this", ";", "}" ]
Load routing from routing files @return $this
[ "Load", "routing", "from", "routing", "files" ]
e5e4efb05feb4d23b0df41f2b21fd095103e593b
https://github.com/itkg/core/blob/e5e4efb05feb4d23b0df41f2b21fd095103e593b/src/Itkg/Core/Legacy/Kernel.php#L62-L75
train
itkg/core
src/Itkg/Core/Legacy/Kernel.php
Kernel.processRouteInfos
private function processRouteInfos($name, array $routeInfos) { $className = null; if (isset($routeInfos['sequence'])) { $className = $routeInfos['sequence']; $this->container['core']['router']->addRouteSequence($className); } if (isset($routeInfos['pattern'])) { if (!isset($routeInfos['arguments'])) { $routeInfos['arguments'] = array(); } $route = new Route($routeInfos['pattern'], $routeInfos['arguments'], $className); if (isset($routeInfos['defaults'])) { $route->defaults($routeInfos['defaults']); } if (isset($routeInfos['params'])) { $route->pushRequestParams($routeInfos['params']); } $this->container['core']['router']->addRoute($route, $name); } }
php
private function processRouteInfos($name, array $routeInfos) { $className = null; if (isset($routeInfos['sequence'])) { $className = $routeInfos['sequence']; $this->container['core']['router']->addRouteSequence($className); } if (isset($routeInfos['pattern'])) { if (!isset($routeInfos['arguments'])) { $routeInfos['arguments'] = array(); } $route = new Route($routeInfos['pattern'], $routeInfos['arguments'], $className); if (isset($routeInfos['defaults'])) { $route->defaults($routeInfos['defaults']); } if (isset($routeInfos['params'])) { $route->pushRequestParams($routeInfos['params']); } $this->container['core']['router']->addRoute($route, $name); } }
[ "private", "function", "processRouteInfos", "(", "$", "name", ",", "array", "$", "routeInfos", ")", "{", "$", "className", "=", "null", ";", "if", "(", "isset", "(", "$", "routeInfos", "[", "'sequence'", "]", ")", ")", "{", "$", "className", "=", "$", "routeInfos", "[", "'sequence'", "]", ";", "$", "this", "->", "container", "[", "'core'", "]", "[", "'router'", "]", "->", "addRouteSequence", "(", "$", "className", ")", ";", "}", "if", "(", "isset", "(", "$", "routeInfos", "[", "'pattern'", "]", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "routeInfos", "[", "'arguments'", "]", ")", ")", "{", "$", "routeInfos", "[", "'arguments'", "]", "=", "array", "(", ")", ";", "}", "$", "route", "=", "new", "Route", "(", "$", "routeInfos", "[", "'pattern'", "]", ",", "$", "routeInfos", "[", "'arguments'", "]", ",", "$", "className", ")", ";", "if", "(", "isset", "(", "$", "routeInfos", "[", "'defaults'", "]", ")", ")", "{", "$", "route", "->", "defaults", "(", "$", "routeInfos", "[", "'defaults'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "routeInfos", "[", "'params'", "]", ")", ")", "{", "$", "route", "->", "pushRequestParams", "(", "$", "routeInfos", "[", "'params'", "]", ")", ";", "}", "$", "this", "->", "container", "[", "'core'", "]", "[", "'router'", "]", "->", "addRoute", "(", "$", "route", ",", "$", "name", ")", ";", "}", "}" ]
Process route infos @param string $name @param array $routeInfos
[ "Process", "route", "infos" ]
e5e4efb05feb4d23b0df41f2b21fd095103e593b
https://github.com/itkg/core/blob/e5e4efb05feb4d23b0df41f2b21fd095103e593b/src/Itkg/Core/Legacy/Kernel.php#L83-L106
train
VTacius/ldapPM
src/Controlador/ldapOperations.php
ldapOperations.iterarEntradas
private function iterarEntradas($busquedaLdap, array $atributos){ $datos = array(); if (($entrada = ldap_first_entry($this->conexionLdap, $busquedaLdap))) { do { // Ejecutamos al menos una vez el mapeo de entradas con sus atributos, a menos // que no haya nada $datos[] = $this->mapa($atributos, $entrada); } while ($entrada = ldap_next_entry($this->conexionLdap, $entrada)); return $datos; }else{ return FALSE; } }
php
private function iterarEntradas($busquedaLdap, array $atributos){ $datos = array(); if (($entrada = ldap_first_entry($this->conexionLdap, $busquedaLdap))) { do { // Ejecutamos al menos una vez el mapeo de entradas con sus atributos, a menos // que no haya nada $datos[] = $this->mapa($atributos, $entrada); } while ($entrada = ldap_next_entry($this->conexionLdap, $entrada)); return $datos; }else{ return FALSE; } }
[ "private", "function", "iterarEntradas", "(", "$", "busquedaLdap", ",", "array", "$", "atributos", ")", "{", "$", "datos", "=", "array", "(", ")", ";", "if", "(", "(", "$", "entrada", "=", "ldap_first_entry", "(", "$", "this", "->", "conexionLdap", ",", "$", "busquedaLdap", ")", ")", ")", "{", "do", "{", "// Ejecutamos al menos una vez el mapeo de entradas con sus atributos, a menos ", "// que no haya nada", "$", "datos", "[", "]", "=", "$", "this", "->", "mapa", "(", "$", "atributos", ",", "$", "entrada", ")", ";", "}", "while", "(", "$", "entrada", "=", "ldap_next_entry", "(", "$", "this", "->", "conexionLdap", ",", "$", "entrada", ")", ")", ";", "return", "$", "datos", ";", "}", "else", "{", "return", "FALSE", ";", "}", "}" ]
Auxiliar directo de busqueda. Dado un ldap result, itera por el para conseguir sus datos @param ldap result $busquedaLdap @param array $atributos @return boolean
[ "Auxiliar", "directo", "de", "busqueda", ".", "Dado", "un", "ldap", "result", "itera", "por", "el", "para", "conseguir", "sus", "datos" ]
728af24cd0a5ca4fbed76ffb52aa4800b118879f
https://github.com/VTacius/ldapPM/blob/728af24cd0a5ca4fbed76ffb52aa4800b118879f/src/Controlador/ldapOperations.php#L46-L58
train
hiqdev/minii-helpers
src/BaseInflector.php
BaseInflector.ordinalize
public static function ordinalize($number) { if (in_array(($number % 100), range(11, 13))) { return $number . 'th'; } switch ($number % 10) { case 1: return $number . 'st'; case 2: return $number . 'nd'; case 3: return $number . 'rd'; default: return $number . 'th'; } }
php
public static function ordinalize($number) { if (in_array(($number % 100), range(11, 13))) { return $number . 'th'; } switch ($number % 10) { case 1: return $number . 'st'; case 2: return $number . 'nd'; case 3: return $number . 'rd'; default: return $number . 'th'; } }
[ "public", "static", "function", "ordinalize", "(", "$", "number", ")", "{", "if", "(", "in_array", "(", "(", "$", "number", "%", "100", ")", ",", "range", "(", "11", ",", "13", ")", ")", ")", "{", "return", "$", "number", ".", "'th'", ";", "}", "switch", "(", "$", "number", "%", "10", ")", "{", "case", "1", ":", "return", "$", "number", ".", "'st'", ";", "case", "2", ":", "return", "$", "number", ".", "'nd'", ";", "case", "3", ":", "return", "$", "number", ".", "'rd'", ";", "default", ":", "return", "$", "number", ".", "'th'", ";", "}", "}" ]
Converts number to its ordinal English form. For example, converts 13 to 13th, 2 to 2nd ... @param integer $number the number to get its ordinal value @return string
[ "Converts", "number", "to", "its", "ordinal", "English", "form", ".", "For", "example", "converts", "13", "to", "13th", "2", "to", "2nd", "..." ]
001b7a56a6ebdc432c4683fe47c00a913f8e57d7
https://github.com/hiqdev/minii-helpers/blob/001b7a56a6ebdc432c4683fe47c00a913f8e57d7/src/BaseInflector.php#L475-L490
train
Kris-Kuiper/sFire-Framework
src/Image/Driver/GD.php
GD.pixelate
public function pixelate($blocksize = 5, $effect = 50) { $this -> filter(IMG_FILTER_PIXELATE, $blocksize, $effect); return $this -> image; }
php
public function pixelate($blocksize = 5, $effect = 50) { $this -> filter(IMG_FILTER_PIXELATE, $blocksize, $effect); return $this -> image; }
[ "public", "function", "pixelate", "(", "$", "blocksize", "=", "5", ",", "$", "effect", "=", "50", ")", "{", "$", "this", "->", "filter", "(", "IMG_FILTER_PIXELATE", ",", "$", "blocksize", ",", "$", "effect", ")", ";", "return", "$", "this", "->", "image", ";", "}" ]
Give current image a pixelate filter @param int $blocksize @param int $effect @return resource
[ "Give", "current", "image", "a", "pixelate", "filter" ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Image/Driver/GD.php#L274-L278
train
Kris-Kuiper/sFire-Framework
src/Image/Driver/GD.php
GD.createImage
private function createImage($x, $y, $width, $height, $new_width, $new_height, $interlace = false) { $resource = imagecreatetruecolor($new_width, $new_height); if(false === imagesavealpha($resource, true)) { trigger_error('Could not set the flag to save full alpha channel', E_USER_ERROR); } if(false === imagealphablending($resource, false)) { trigger_error('Could not set the blending mode', E_USER_ERROR); } if(false === imagefill($resource, 0, 0, imagecolorallocate($resource, 255, 255, 255))) { trigger_error('Could not flood fill the image', E_USER_ERROR); } if(false === imagecopyresampled($resource, $this -> image, 0, 0, $x, $y, $new_width, $new_height, $width, $height)) { trigger_error('Could not copy and resize part of an image with resampling', E_USER_ERROR); } if((true === $interlace && imageinterlace($this -> image, true)) || false === $interlace) { $this -> image = $resource; return $this -> image; } return false; }
php
private function createImage($x, $y, $width, $height, $new_width, $new_height, $interlace = false) { $resource = imagecreatetruecolor($new_width, $new_height); if(false === imagesavealpha($resource, true)) { trigger_error('Could not set the flag to save full alpha channel', E_USER_ERROR); } if(false === imagealphablending($resource, false)) { trigger_error('Could not set the blending mode', E_USER_ERROR); } if(false === imagefill($resource, 0, 0, imagecolorallocate($resource, 255, 255, 255))) { trigger_error('Could not flood fill the image', E_USER_ERROR); } if(false === imagecopyresampled($resource, $this -> image, 0, 0, $x, $y, $new_width, $new_height, $width, $height)) { trigger_error('Could not copy and resize part of an image with resampling', E_USER_ERROR); } if((true === $interlace && imageinterlace($this -> image, true)) || false === $interlace) { $this -> image = $resource; return $this -> image; } return false; }
[ "private", "function", "createImage", "(", "$", "x", ",", "$", "y", ",", "$", "width", ",", "$", "height", ",", "$", "new_width", ",", "$", "new_height", ",", "$", "interlace", "=", "false", ")", "{", "$", "resource", "=", "imagecreatetruecolor", "(", "$", "new_width", ",", "$", "new_height", ")", ";", "if", "(", "false", "===", "imagesavealpha", "(", "$", "resource", ",", "true", ")", ")", "{", "trigger_error", "(", "'Could not set the flag to save full alpha channel'", ",", "E_USER_ERROR", ")", ";", "}", "if", "(", "false", "===", "imagealphablending", "(", "$", "resource", ",", "false", ")", ")", "{", "trigger_error", "(", "'Could not set the blending mode'", ",", "E_USER_ERROR", ")", ";", "}", "if", "(", "false", "===", "imagefill", "(", "$", "resource", ",", "0", ",", "0", ",", "imagecolorallocate", "(", "$", "resource", ",", "255", ",", "255", ",", "255", ")", ")", ")", "{", "trigger_error", "(", "'Could not flood fill the image'", ",", "E_USER_ERROR", ")", ";", "}", "if", "(", "false", "===", "imagecopyresampled", "(", "$", "resource", ",", "$", "this", "->", "image", ",", "0", ",", "0", ",", "$", "x", ",", "$", "y", ",", "$", "new_width", ",", "$", "new_height", ",", "$", "width", ",", "$", "height", ")", ")", "{", "trigger_error", "(", "'Could not copy and resize part of an image with resampling'", ",", "E_USER_ERROR", ")", ";", "}", "if", "(", "(", "true", "===", "$", "interlace", "&&", "imageinterlace", "(", "$", "this", "->", "image", ",", "true", ")", ")", "||", "false", "===", "$", "interlace", ")", "{", "$", "this", "->", "image", "=", "$", "resource", ";", "return", "$", "this", "->", "image", ";", "}", "return", "false", ";", "}" ]
Creates new image resource. Returns false if failed. @param int $x @param int $y @param int $width @param int $height @param int $new_width @param int $new_height @param boolean $interlace @return resource|boolean
[ "Creates", "new", "image", "resource", ".", "Returns", "false", "if", "failed", "." ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Image/Driver/GD.php#L385-L412
train
wb-crowdfusion/crowdfusion
system/core/classes/mvc/filters/DisplayFilterer.php
DisplayFilterer.substring
public function substring () { $start = $this->getParameter('start'); $length = $this->getParameter('length'); if (empty($start)) $start = 0; if (empty($length)) $length = strlen($this->getParameter('value')) - (int)$start; $str = substr($this->getParameter('value'), (int)$start, (int)$length); return $str; }
php
public function substring () { $start = $this->getParameter('start'); $length = $this->getParameter('length'); if (empty($start)) $start = 0; if (empty($length)) $length = strlen($this->getParameter('value')) - (int)$start; $str = substr($this->getParameter('value'), (int)$start, (int)$length); return $str; }
[ "public", "function", "substring", "(", ")", "{", "$", "start", "=", "$", "this", "->", "getParameter", "(", "'start'", ")", ";", "$", "length", "=", "$", "this", "->", "getParameter", "(", "'length'", ")", ";", "if", "(", "empty", "(", "$", "start", ")", ")", "$", "start", "=", "0", ";", "if", "(", "empty", "(", "$", "length", ")", ")", "$", "length", "=", "strlen", "(", "$", "this", "->", "getParameter", "(", "'value'", ")", ")", "-", "(", "int", ")", "$", "start", ";", "$", "str", "=", "substr", "(", "$", "this", "->", "getParameter", "(", "'value'", ")", ",", "(", "int", ")", "$", "start", ",", "(", "int", ")", "$", "length", ")", ";", "return", "$", "str", ";", "}" ]
Returns a substring from param 'value'. Returns the 1st letter if only 'value' is specified Expected Params: value string the string to operate upon start integer (optional) the starting point for our substring, default 0 length integer (optional) the length of the substring. default 1 @return string
[ "Returns", "a", "substring", "from", "param", "value", ".", "Returns", "the", "1st", "letter", "if", "only", "value", "is", "specified" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/filters/DisplayFilterer.php#L110-L124
train
wb-crowdfusion/crowdfusion
system/core/classes/mvc/filters/DisplayFilterer.php
DisplayFilterer.showVars
public function showVars() { $what = $this->getParameter('scope'); switch ( $what ) { case 'global': case 'globals': case 'system': case 'systems': $debug = $this->getGlobals(); break; default: $debug = $this->getLocals(); break; } return '<pre>' . JSONUtils::encode($debug, true, false) . '</pre>'; }
php
public function showVars() { $what = $this->getParameter('scope'); switch ( $what ) { case 'global': case 'globals': case 'system': case 'systems': $debug = $this->getGlobals(); break; default: $debug = $this->getLocals(); break; } return '<pre>' . JSONUtils::encode($debug, true, false) . '</pre>'; }
[ "public", "function", "showVars", "(", ")", "{", "$", "what", "=", "$", "this", "->", "getParameter", "(", "'scope'", ")", ";", "switch", "(", "$", "what", ")", "{", "case", "'global'", ":", "case", "'globals'", ":", "case", "'system'", ":", "case", "'systems'", ":", "$", "debug", "=", "$", "this", "->", "getGlobals", "(", ")", ";", "break", ";", "default", ":", "$", "debug", "=", "$", "this", "->", "getLocals", "(", ")", ";", "break", ";", "}", "return", "'<pre>'", ".", "JSONUtils", "::", "encode", "(", "$", "debug", ",", "true", ",", "false", ")", ".", "'</pre>'", ";", "}" ]
Returns debuggging information about the current vars Expected Params: scope string (optional) If set to 'globals', then dump the globals. Otherwise dump the locals. @return string
[ "Returns", "debuggging", "information", "about", "the", "current", "vars" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/filters/DisplayFilterer.php#L134-L151
train
wb-crowdfusion/crowdfusion
system/core/classes/mvc/filters/DisplayFilterer.php
DisplayFilterer.htmlEscape
public function htmlEscape() { if ($this->getParameter('value') == null) return; return str_replace('%', '&#37;', htmlentities($this->getParameter('value'), ENT_QUOTES, 'UTF-8', false)); }
php
public function htmlEscape() { if ($this->getParameter('value') == null) return; return str_replace('%', '&#37;', htmlentities($this->getParameter('value'), ENT_QUOTES, 'UTF-8', false)); }
[ "public", "function", "htmlEscape", "(", ")", "{", "if", "(", "$", "this", "->", "getParameter", "(", "'value'", ")", "==", "null", ")", "return", ";", "return", "str_replace", "(", "'%'", ",", "'&#37;'", ",", "htmlentities", "(", "$", "this", "->", "getParameter", "(", "'value'", ")", ",", "ENT_QUOTES", ",", "'UTF-8'", ",", "false", ")", ")", ";", "}" ]
HTML-Escapes the specified parameter. Converts all html chars into their entities equivalent Expected Param: value string @return string
[ "HTML", "-", "Escapes", "the", "specified", "parameter", ".", "Converts", "all", "html", "chars", "into", "their", "entities", "equivalent" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/filters/DisplayFilterer.php#L213-L219
train
wb-crowdfusion/crowdfusion
system/core/classes/mvc/filters/DisplayFilterer.php
DisplayFilterer.strReplace
function strReplace() { if (($this->getParameter('needle') == null) || ($this->getParameter('haystack') == null)) return $this->getParameter('haystack'); $needle = $this->getParameter('needle'); if($needle == '\n') $needle = "\n"; return str_replace($needle, $this->getParameter('replace'), $this->getParameter('haystack')); }
php
function strReplace() { if (($this->getParameter('needle') == null) || ($this->getParameter('haystack') == null)) return $this->getParameter('haystack'); $needle = $this->getParameter('needle'); if($needle == '\n') $needle = "\n"; return str_replace($needle, $this->getParameter('replace'), $this->getParameter('haystack')); }
[ "function", "strReplace", "(", ")", "{", "if", "(", "(", "$", "this", "->", "getParameter", "(", "'needle'", ")", "==", "null", ")", "||", "(", "$", "this", "->", "getParameter", "(", "'haystack'", ")", "==", "null", ")", ")", "return", "$", "this", "->", "getParameter", "(", "'haystack'", ")", ";", "$", "needle", "=", "$", "this", "->", "getParameter", "(", "'needle'", ")", ";", "if", "(", "$", "needle", "==", "'\\n'", ")", "$", "needle", "=", "\"\\n\"", ";", "return", "str_replace", "(", "$", "needle", ",", "$", "this", "->", "getParameter", "(", "'replace'", ")", ",", "$", "this", "->", "getParameter", "(", "'haystack'", ")", ")", ";", "}" ]
Performs a string replace on the specified param Expected Params: needle string The item to search for haystack string The string to look in replace string The string to replace the found text with @return string
[ "Performs", "a", "string", "replace", "on", "the", "specified", "param" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/filters/DisplayFilterer.php#L247-L257
train
wb-crowdfusion/crowdfusion
system/core/classes/mvc/filters/DisplayFilterer.php
DisplayFilterer.pregReplace
public function pregReplace() { if ($this->getParameter('pattern') == null) return $this->getParameter('subject'); return preg_replace($this->getParameter('pattern'), $this->getParameter('replace'), $this->getParameter('subject')); }
php
public function pregReplace() { if ($this->getParameter('pattern') == null) return $this->getParameter('subject'); return preg_replace($this->getParameter('pattern'), $this->getParameter('replace'), $this->getParameter('subject')); }
[ "public", "function", "pregReplace", "(", ")", "{", "if", "(", "$", "this", "->", "getParameter", "(", "'pattern'", ")", "==", "null", ")", "return", "$", "this", "->", "getParameter", "(", "'subject'", ")", ";", "return", "preg_replace", "(", "$", "this", "->", "getParameter", "(", "'pattern'", ")", ",", "$", "this", "->", "getParameter", "(", "'replace'", ")", ",", "$", "this", "->", "getParameter", "(", "'subject'", ")", ")", ";", "}" ]
Performs a regular expression search and replace Expected Params: pattern regex The regular expression used to locate the text to replace subject string The string to look at replace string The text to replace the found items with @return string
[ "Performs", "a", "regular", "expression", "search", "and", "replace" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/filters/DisplayFilterer.php#L269-L274
train
wb-crowdfusion/crowdfusion
system/core/classes/mvc/filters/DisplayFilterer.php
DisplayFilterer.firstLetter
protected function firstLetter() { $string = trim((string) $this->getParameter('string')); $lower = (boolean) $this->getParameter('lower'); return StringUtils::firstLetter($string, $lower); }
php
protected function firstLetter() { $string = trim((string) $this->getParameter('string')); $lower = (boolean) $this->getParameter('lower'); return StringUtils::firstLetter($string, $lower); }
[ "protected", "function", "firstLetter", "(", ")", "{", "$", "string", "=", "trim", "(", "(", "string", ")", "$", "this", "->", "getParameter", "(", "'string'", ")", ")", ";", "$", "lower", "=", "(", "boolean", ")", "$", "this", "->", "getParameter", "(", "'lower'", ")", ";", "return", "StringUtils", "::", "firstLetter", "(", "$", "string", ",", "$", "lower", ")", ";", "}" ]
Return the first character from a string. Expected Params: string string lower boolean return string in lower case. defaults to false @return string
[ "Return", "the", "first", "character", "from", "a", "string", "." ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/filters/DisplayFilterer.php#L285-L290
train
wb-crowdfusion/crowdfusion
system/core/classes/mvc/filters/DisplayFilterer.php
DisplayFilterer.trim
public function trim() { return StringUtils::trim( $this->getParameter('value'), $this->getParameter('len'), $this->getParameter('keeptags'), $this->getParameter('decodehtml'), $this->getParameter('stripurls')); }
php
public function trim() { return StringUtils::trim( $this->getParameter('value'), $this->getParameter('len'), $this->getParameter('keeptags'), $this->getParameter('decodehtml'), $this->getParameter('stripurls')); }
[ "public", "function", "trim", "(", ")", "{", "return", "StringUtils", "::", "trim", "(", "$", "this", "->", "getParameter", "(", "'value'", ")", ",", "$", "this", "->", "getParameter", "(", "'len'", ")", ",", "$", "this", "->", "getParameter", "(", "'keeptags'", ")", ",", "$", "this", "->", "getParameter", "(", "'decodehtml'", ")", ",", "$", "this", "->", "getParameter", "(", "'stripurls'", ")", ")", ";", "}" ]
Trims a string to a specified length. It will allow tags listed in 'KeepTags' to remain and will intelligently append the trimmed text with '...' or '-' depending on if the trim ends on a word or a space. Expected Params: len integer The length to trim the string to value string The string to trim KeepTags string A list of tags (like '<p><a>') that are allowed in the trimmed text. @return string
[ "Trims", "a", "string", "to", "a", "specified", "length", ".", "It", "will", "allow", "tags", "listed", "in", "KeepTags", "to", "remain", "and", "will", "intelligently", "append", "the", "trimmed", "text", "with", "...", "or", "-", "depending", "on", "if", "the", "trim", "ends", "on", "a", "word", "or", "a", "space", "." ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/filters/DisplayFilterer.php#L319-L327
train
wb-crowdfusion/crowdfusion
system/core/classes/mvc/filters/DisplayFilterer.php
DisplayFilterer.wordCount
public function wordCount() { $count = 0; foreach ($this->getParameters() as $value) $count += str_word_count(strip_tags($value)); return $count; }
php
public function wordCount() { $count = 0; foreach ($this->getParameters() as $value) $count += str_word_count(strip_tags($value)); return $count; }
[ "public", "function", "wordCount", "(", ")", "{", "$", "count", "=", "0", ";", "foreach", "(", "$", "this", "->", "getParameters", "(", ")", "as", "$", "value", ")", "$", "count", "+=", "str_word_count", "(", "strip_tags", "(", "$", "value", ")", ")", ";", "return", "$", "count", ";", "}" ]
Returns the total count of all words in all params passed @return integer
[ "Returns", "the", "total", "count", "of", "all", "words", "in", "all", "params", "passed" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/filters/DisplayFilterer.php#L373-L381
train
wb-crowdfusion/crowdfusion
system/core/classes/mvc/filters/DisplayFilterer.php
DisplayFilterer.charCount
public function charCount() { $count = 0; foreach ($this->getParameters() as $value) $count += strlen(strip_tags($value)); return $count; }
php
public function charCount() { $count = 0; foreach ($this->getParameters() as $value) $count += strlen(strip_tags($value)); return $count; }
[ "public", "function", "charCount", "(", ")", "{", "$", "count", "=", "0", ";", "foreach", "(", "$", "this", "->", "getParameters", "(", ")", "as", "$", "value", ")", "$", "count", "+=", "strlen", "(", "strip_tags", "(", "$", "value", ")", ")", ";", "return", "$", "count", ";", "}" ]
Returns the total count of all characters in all params passed @return integer
[ "Returns", "the", "total", "count", "of", "all", "characters", "in", "all", "params", "passed" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/filters/DisplayFilterer.php#L388-L396
train
wb-crowdfusion/crowdfusion
system/core/classes/mvc/filters/DisplayFilterer.php
DisplayFilterer.pluralize
public function pluralize() { if($this->getParameter('upperCaseFirst') == 'true') return ucfirst(StringUtils::pluralize($this->getParameter('value'))); return StringUtils::pluralize($this->getParameter('value')); }
php
public function pluralize() { if($this->getParameter('upperCaseFirst') == 'true') return ucfirst(StringUtils::pluralize($this->getParameter('value'))); return StringUtils::pluralize($this->getParameter('value')); }
[ "public", "function", "pluralize", "(", ")", "{", "if", "(", "$", "this", "->", "getParameter", "(", "'upperCaseFirst'", ")", "==", "'true'", ")", "return", "ucfirst", "(", "StringUtils", "::", "pluralize", "(", "$", "this", "->", "getParameter", "(", "'value'", ")", ")", ")", ";", "return", "StringUtils", "::", "pluralize", "(", "$", "this", "->", "getParameter", "(", "'value'", ")", ")", ";", "}" ]
Returns the plural version of the parameter in 'value' Expected Params: value string the string to pluralize upperCaseFirst string if set to 'true' then the result string will be Capitalized @return string
[ "Returns", "the", "plural", "version", "of", "the", "parameter", "in", "value" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/filters/DisplayFilterer.php#L457-L463
train
wb-crowdfusion/crowdfusion
system/core/classes/mvc/filters/DisplayFilterer.php
DisplayFilterer.repeat
public function repeat() { if ($this->getParameter('value') == null) return; $value = $this->getParameter('value'); $multiplier = $this->getParameter('multiplier'); $offset = $this->getParameter('offset'); return str_repeat($value, (int)$multiplier + (int)$offset); }
php
public function repeat() { if ($this->getParameter('value') == null) return; $value = $this->getParameter('value'); $multiplier = $this->getParameter('multiplier'); $offset = $this->getParameter('offset'); return str_repeat($value, (int)$multiplier + (int)$offset); }
[ "public", "function", "repeat", "(", ")", "{", "if", "(", "$", "this", "->", "getParameter", "(", "'value'", ")", "==", "null", ")", "return", ";", "$", "value", "=", "$", "this", "->", "getParameter", "(", "'value'", ")", ";", "$", "multiplier", "=", "$", "this", "->", "getParameter", "(", "'multiplier'", ")", ";", "$", "offset", "=", "$", "this", "->", "getParameter", "(", "'offset'", ")", ";", "return", "str_repeat", "(", "$", "value", ",", "(", "int", ")", "$", "multiplier", "+", "(", "int", ")", "$", "offset", ")", ";", "}" ]
Returns the supplied snippet repeated X times Expected Params: value string the string to repeat multiplier int the number of times to repeat the value @return string
[ "Returns", "the", "supplied", "snippet", "repeated", "X", "times" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/filters/DisplayFilterer.php#L483-L492
train
wb-crowdfusion/crowdfusion
system/core/classes/mvc/filters/DisplayFilterer.php
DisplayFilterer.implode
public function implode() { if (!is_array($this->getParameter('value'))) { return $this->getParameter('value'); } $glue = $this->getParameter('glue'); if ($glue === null) { $glue = '&nbsp;'; } return implode($glue, $this->getParameter('value')); }
php
public function implode() { if (!is_array($this->getParameter('value'))) { return $this->getParameter('value'); } $glue = $this->getParameter('glue'); if ($glue === null) { $glue = '&nbsp;'; } return implode($glue, $this->getParameter('value')); }
[ "public", "function", "implode", "(", ")", "{", "if", "(", "!", "is_array", "(", "$", "this", "->", "getParameter", "(", "'value'", ")", ")", ")", "{", "return", "$", "this", "->", "getParameter", "(", "'value'", ")", ";", "}", "$", "glue", "=", "$", "this", "->", "getParameter", "(", "'glue'", ")", ";", "if", "(", "$", "glue", "===", "null", ")", "{", "$", "glue", "=", "'&nbsp;'", ";", "}", "return", "implode", "(", "$", "glue", ",", "$", "this", "->", "getParameter", "(", "'value'", ")", ")", ";", "}" ]
Implode Array to String @return string
[ "Implode", "Array", "to", "String" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/filters/DisplayFilterer.php#L528-L541
train
Vectrex/vxPHP
src/Orm/Query.php
Query.sortBy
public function sortBy($columnName, $asc = TRUE) { $sort = new \stdClass(); $sort->column = $columnName; $sort->asc = !!$asc; $this->columnSorts[] = $sort; return $this; }
php
public function sortBy($columnName, $asc = TRUE) { $sort = new \stdClass(); $sort->column = $columnName; $sort->asc = !!$asc; $this->columnSorts[] = $sort; return $this; }
[ "public", "function", "sortBy", "(", "$", "columnName", ",", "$", "asc", "=", "TRUE", ")", "{", "$", "sort", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "sort", "->", "column", "=", "$", "columnName", ";", "$", "sort", "->", "asc", "=", "!", "!", "$", "asc", ";", "$", "this", "->", "columnSorts", "[", "]", "=", "$", "sort", ";", "return", "$", "this", ";", "}" ]
add ORDER BY clause @param string $columnName @param boolean $asc @return \vxPHP\Orm\Query
[ "add", "ORDER", "BY", "clause" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Orm/Query.php#L128-L139
train
Vectrex/vxPHP
src/Orm/Query.php
Query.buildQueryString
protected function buildQueryString() { $w = []; $s = []; $qc = $this->quoteChar; // start SQL statement $this->sql = 'SELECT '; // add columns if(!$this->columns || !count($this->columns)) { $this->sql .= '*'; } else { $this->sql .= $qc . str_replace('.', $qc . '.' . $qc, implode($qc . ',' . $qc, $this->columns)) . $qc; } // add table $this->sql .= ' FROM ' . $qc . preg_replace('/\s+/', $qc . ' ' . $qc, $this->table) . $qc; // add alias if($this->alias) { $this->sql .= ' ' . $qc . $this->alias . $qc; } // add INNER JOINs foreach($this->innerJoins as $join) { $this->sql .= sprintf(' INNER JOIN %1$s%2$s%1$s ON %3$s', $qc, preg_replace('/\s+/', $qc . ' ' . $qc, trim($join->table)), $join->on); } // build WHERE clause foreach($this->whereClauses as $where) { // complete condition when no operator set if(!$where->operator) { $w[] = $where->conditionOrColumn; } // otherwise parse operator else { if($where->operator === 'IN') { $w[] = sprintf( '%1$s%2$s%1$s IN (%3$s)', $qc, str_replace('.', $qc . '.' . $qc, $where->conditionOrColumn), implode(', ', array_fill(0, count($where->value), '?')) ); } else { $w[] = sprintf( '%1$s%2$s%1$s %3$s ?', $qc, str_replace('.', $qc . '.' . $qc, $where->conditionOrColumn), $where->operator ); } } } // build SORT clause foreach($this->columnSorts as $sort) { $s[] = $sort->column . ($sort->asc ? '' : ' DESC'); } if(count($w)) { $this->sql .= ' WHERE (' . implode(') AND (', $w) .')'; } if(count($s)) { $this->sql .= ' ORDER BY ' . implode(', ', $s); } }
php
protected function buildQueryString() { $w = []; $s = []; $qc = $this->quoteChar; // start SQL statement $this->sql = 'SELECT '; // add columns if(!$this->columns || !count($this->columns)) { $this->sql .= '*'; } else { $this->sql .= $qc . str_replace('.', $qc . '.' . $qc, implode($qc . ',' . $qc, $this->columns)) . $qc; } // add table $this->sql .= ' FROM ' . $qc . preg_replace('/\s+/', $qc . ' ' . $qc, $this->table) . $qc; // add alias if($this->alias) { $this->sql .= ' ' . $qc . $this->alias . $qc; } // add INNER JOINs foreach($this->innerJoins as $join) { $this->sql .= sprintf(' INNER JOIN %1$s%2$s%1$s ON %3$s', $qc, preg_replace('/\s+/', $qc . ' ' . $qc, trim($join->table)), $join->on); } // build WHERE clause foreach($this->whereClauses as $where) { // complete condition when no operator set if(!$where->operator) { $w[] = $where->conditionOrColumn; } // otherwise parse operator else { if($where->operator === 'IN') { $w[] = sprintf( '%1$s%2$s%1$s IN (%3$s)', $qc, str_replace('.', $qc . '.' . $qc, $where->conditionOrColumn), implode(', ', array_fill(0, count($where->value), '?')) ); } else { $w[] = sprintf( '%1$s%2$s%1$s %3$s ?', $qc, str_replace('.', $qc . '.' . $qc, $where->conditionOrColumn), $where->operator ); } } } // build SORT clause foreach($this->columnSorts as $sort) { $s[] = $sort->column . ($sort->asc ? '' : ' DESC'); } if(count($w)) { $this->sql .= ' WHERE (' . implode(') AND (', $w) .')'; } if(count($s)) { $this->sql .= ' ORDER BY ' . implode(', ', $s); } }
[ "protected", "function", "buildQueryString", "(", ")", "{", "$", "w", "=", "[", "]", ";", "$", "s", "=", "[", "]", ";", "$", "qc", "=", "$", "this", "->", "quoteChar", ";", "// start SQL statement", "$", "this", "->", "sql", "=", "'SELECT '", ";", "// add columns", "if", "(", "!", "$", "this", "->", "columns", "||", "!", "count", "(", "$", "this", "->", "columns", ")", ")", "{", "$", "this", "->", "sql", ".=", "'*'", ";", "}", "else", "{", "$", "this", "->", "sql", ".=", "$", "qc", ".", "str_replace", "(", "'.'", ",", "$", "qc", ".", "'.'", ".", "$", "qc", ",", "implode", "(", "$", "qc", ".", "','", ".", "$", "qc", ",", "$", "this", "->", "columns", ")", ")", ".", "$", "qc", ";", "}", "// add table", "$", "this", "->", "sql", ".=", "' FROM '", ".", "$", "qc", ".", "preg_replace", "(", "'/\\s+/'", ",", "$", "qc", ".", "' '", ".", "$", "qc", ",", "$", "this", "->", "table", ")", ".", "$", "qc", ";", "// add alias", "if", "(", "$", "this", "->", "alias", ")", "{", "$", "this", "->", "sql", ".=", "' '", ".", "$", "qc", ".", "$", "this", "->", "alias", ".", "$", "qc", ";", "}", "// add INNER JOINs", "foreach", "(", "$", "this", "->", "innerJoins", "as", "$", "join", ")", "{", "$", "this", "->", "sql", ".=", "sprintf", "(", "' INNER JOIN %1$s%2$s%1$s ON %3$s'", ",", "$", "qc", ",", "preg_replace", "(", "'/\\s+/'", ",", "$", "qc", ".", "' '", ".", "$", "qc", ",", "trim", "(", "$", "join", "->", "table", ")", ")", ",", "$", "join", "->", "on", ")", ";", "}", "// build WHERE clause", "foreach", "(", "$", "this", "->", "whereClauses", "as", "$", "where", ")", "{", "// complete condition when no operator set", "if", "(", "!", "$", "where", "->", "operator", ")", "{", "$", "w", "[", "]", "=", "$", "where", "->", "conditionOrColumn", ";", "}", "// otherwise parse operator", "else", "{", "if", "(", "$", "where", "->", "operator", "===", "'IN'", ")", "{", "$", "w", "[", "]", "=", "sprintf", "(", "'%1$s%2$s%1$s IN (%3$s)'", ",", "$", "qc", ",", "str_replace", "(", "'.'", ",", "$", "qc", ".", "'.'", ".", "$", "qc", ",", "$", "where", "->", "conditionOrColumn", ")", ",", "implode", "(", "', '", ",", "array_fill", "(", "0", ",", "count", "(", "$", "where", "->", "value", ")", ",", "'?'", ")", ")", ")", ";", "}", "else", "{", "$", "w", "[", "]", "=", "sprintf", "(", "'%1$s%2$s%1$s %3$s ?'", ",", "$", "qc", ",", "str_replace", "(", "'.'", ",", "$", "qc", ".", "'.'", ".", "$", "qc", ",", "$", "where", "->", "conditionOrColumn", ")", ",", "$", "where", "->", "operator", ")", ";", "}", "}", "}", "// build SORT clause", "foreach", "(", "$", "this", "->", "columnSorts", "as", "$", "sort", ")", "{", "$", "s", "[", "]", "=", "$", "sort", "->", "column", ".", "(", "$", "sort", "->", "asc", "?", "''", ":", "' DESC'", ")", ";", "}", "if", "(", "count", "(", "$", "w", ")", ")", "{", "$", "this", "->", "sql", ".=", "' WHERE ('", ".", "implode", "(", "') AND ('", ",", "$", "w", ")", ".", "')'", ";", "}", "if", "(", "count", "(", "$", "s", ")", ")", "{", "$", "this", "->", "sql", ".=", "' ORDER BY '", ".", "implode", "(", "', '", ",", "$", "s", ")", ";", "}", "}" ]
builds query string by parsing WHERE and ORDER BY clauses @todo column names are currently masked in MySQL style @todo incomplete masking (e.g. ON clauses)
[ "builds", "query", "string", "by", "parsing", "WHERE", "and", "ORDER", "BY", "clauses" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Orm/Query.php#L225-L308
train
Vectrex/vxPHP
src/Orm/Query.php
Query.buildValuesArray
protected function buildValuesArray() { foreach($this->whereClauses as $where) { if(is_null($where->value)) { continue; } if(is_array($where->value)) { $this->valuesToBind = array_merge($this->valuesToBind, $where->value); } else { $this->valuesToBind[] = $where->value; } } }
php
protected function buildValuesArray() { foreach($this->whereClauses as $where) { if(is_null($where->value)) { continue; } if(is_array($where->value)) { $this->valuesToBind = array_merge($this->valuesToBind, $where->value); } else { $this->valuesToBind[] = $where->value; } } }
[ "protected", "function", "buildValuesArray", "(", ")", "{", "foreach", "(", "$", "this", "->", "whereClauses", "as", "$", "where", ")", "{", "if", "(", "is_null", "(", "$", "where", "->", "value", ")", ")", "{", "continue", ";", "}", "if", "(", "is_array", "(", "$", "where", "->", "value", ")", ")", "{", "$", "this", "->", "valuesToBind", "=", "array_merge", "(", "$", "this", "->", "valuesToBind", ",", "$", "where", "->", "value", ")", ";", "}", "else", "{", "$", "this", "->", "valuesToBind", "[", "]", "=", "$", "where", "->", "value", ";", "}", "}", "}" ]
prepares array containing values which must be bound to prepared statement
[ "prepares", "array", "containing", "values", "which", "must", "be", "bound", "to", "prepared", "statement" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Orm/Query.php#L313-L329
train
Vectrex/vxPHP
src/Orm/Query.php
Query.executeQuery
protected function executeQuery() { $this->lastQuerySql = $this->sql; return $this->dbConnection->doPreparedQuery($this->sql, $this->valuesToBind); }
php
protected function executeQuery() { $this->lastQuerySql = $this->sql; return $this->dbConnection->doPreparedQuery($this->sql, $this->valuesToBind); }
[ "protected", "function", "executeQuery", "(", ")", "{", "$", "this", "->", "lastQuerySql", "=", "$", "this", "->", "sql", ";", "return", "$", "this", "->", "dbConnection", "->", "doPreparedQuery", "(", "$", "this", "->", "sql", ",", "$", "this", "->", "valuesToBind", ")", ";", "}" ]
bind values and execute the SQL statement returns array of records @todo caching/do not prepare statement again, if query hasn't changed @return array
[ "bind", "values", "and", "execute", "the", "SQL", "statement", "returns", "array", "of", "records" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Orm/Query.php#L339-L344
train
moaction/jsonrpc-common
src/Moaction/Jsonrpc/Common/Error.php
Error.fromArray
public static function fromArray(array $data) { return new self( !empty($data['code']) ? $data['code'] : null, !empty($data['message']) ? $data['message'] : null, !empty($data['data']) ? $data['data'] : null ); }
php
public static function fromArray(array $data) { return new self( !empty($data['code']) ? $data['code'] : null, !empty($data['message']) ? $data['message'] : null, !empty($data['data']) ? $data['data'] : null ); }
[ "public", "static", "function", "fromArray", "(", "array", "$", "data", ")", "{", "return", "new", "self", "(", "!", "empty", "(", "$", "data", "[", "'code'", "]", ")", "?", "$", "data", "[", "'code'", "]", ":", "null", ",", "!", "empty", "(", "$", "data", "[", "'message'", "]", ")", "?", "$", "data", "[", "'message'", "]", ":", "null", ",", "!", "empty", "(", "$", "data", "[", "'data'", "]", ")", "?", "$", "data", "[", "'data'", "]", ":", "null", ")", ";", "}" ]
Create object from array @param array $data @return self
[ "Create", "object", "from", "array" ]
05692a2c58d647f20f11b6f7b9568c8fff2d5f8c
https://github.com/moaction/jsonrpc-common/blob/05692a2c58d647f20f11b6f7b9568c8fff2d5f8c/src/Moaction/Jsonrpc/Common/Error.php#L97-L104
train
moaction/jsonrpc-common
src/Moaction/Jsonrpc/Common/Error.php
Error.toArray
public function toArray() { $error = array( 'code' => $this->getCode(), 'message' => $this->getMessage(), ); if ($this->getData()) { $error['data'] = $this->getData(); } return $error; }
php
public function toArray() { $error = array( 'code' => $this->getCode(), 'message' => $this->getMessage(), ); if ($this->getData()) { $error['data'] = $this->getData(); } return $error; }
[ "public", "function", "toArray", "(", ")", "{", "$", "error", "=", "array", "(", "'code'", "=>", "$", "this", "->", "getCode", "(", ")", ",", "'message'", "=>", "$", "this", "->", "getMessage", "(", ")", ",", ")", ";", "if", "(", "$", "this", "->", "getData", "(", ")", ")", "{", "$", "error", "[", "'data'", "]", "=", "$", "this", "->", "getData", "(", ")", ";", "}", "return", "$", "error", ";", "}" ]
Transform object to array @return array
[ "Transform", "object", "to", "array" ]
05692a2c58d647f20f11b6f7b9568c8fff2d5f8c
https://github.com/moaction/jsonrpc-common/blob/05692a2c58d647f20f11b6f7b9568c8fff2d5f8c/src/Moaction/Jsonrpc/Common/Error.php#L111-L123
train
moaction/jsonrpc-common
src/Moaction/Jsonrpc/Common/Error.php
Error.getMessageString
public function getMessageString($errorCode) { return isset($this->errorMessages[$errorCode]) ? $this->errorMessages[$errorCode] : null; }
php
public function getMessageString($errorCode) { return isset($this->errorMessages[$errorCode]) ? $this->errorMessages[$errorCode] : null; }
[ "public", "function", "getMessageString", "(", "$", "errorCode", ")", "{", "return", "isset", "(", "$", "this", "->", "errorMessages", "[", "$", "errorCode", "]", ")", "?", "$", "this", "->", "errorMessages", "[", "$", "errorCode", "]", ":", "null", ";", "}" ]
Return message string by code @param $errorCode @return string|null
[ "Return", "message", "string", "by", "code" ]
05692a2c58d647f20f11b6f7b9568c8fff2d5f8c
https://github.com/moaction/jsonrpc-common/blob/05692a2c58d647f20f11b6f7b9568c8fff2d5f8c/src/Moaction/Jsonrpc/Common/Error.php#L131-L134
train
squareproton/Bond
src/Bond/BackTrace.php
BackTrace.getSane
public function getSane( $shift = 1, $limitOrFilter = null ) { $backtrace = $this->trace; while( $shift-- > 0 ) { array_shift( $backtrace ); } if( is_numeric( $limitOrFilter ) ){ $backtrace = array_slice( $backtrace, 0, (int) $limitOrFilter ); $limitOrFilter = null; } $formattedTrace = array_map( array( $this, 'traceComponentMakeSane' ), $backtrace ); // Apply the filter. Trace fragment is returned if the string limitOrFilter is found anywhere in a trace if( null !== $limitOrFilter ) { foreach( $formattedTrace as $key => $trace ) { $traceMatchesFilter = false; while( !$traceMatchesFilter and list(,$traceLine) = each($trace) ) { if( is_string( $traceLine ) ) { $traceMatchesFilter = false !== stripos( $traceLine, $limitOrFilter ); } } if( !$traceMatchesFilter ) { unset( $formattedTrace[$key] ); } } } return $formattedTrace; }
php
public function getSane( $shift = 1, $limitOrFilter = null ) { $backtrace = $this->trace; while( $shift-- > 0 ) { array_shift( $backtrace ); } if( is_numeric( $limitOrFilter ) ){ $backtrace = array_slice( $backtrace, 0, (int) $limitOrFilter ); $limitOrFilter = null; } $formattedTrace = array_map( array( $this, 'traceComponentMakeSane' ), $backtrace ); // Apply the filter. Trace fragment is returned if the string limitOrFilter is found anywhere in a trace if( null !== $limitOrFilter ) { foreach( $formattedTrace as $key => $trace ) { $traceMatchesFilter = false; while( !$traceMatchesFilter and list(,$traceLine) = each($trace) ) { if( is_string( $traceLine ) ) { $traceMatchesFilter = false !== stripos( $traceLine, $limitOrFilter ); } } if( !$traceMatchesFilter ) { unset( $formattedTrace[$key] ); } } } return $formattedTrace; }
[ "public", "function", "getSane", "(", "$", "shift", "=", "1", ",", "$", "limitOrFilter", "=", "null", ")", "{", "$", "backtrace", "=", "$", "this", "->", "trace", ";", "while", "(", "$", "shift", "--", ">", "0", ")", "{", "array_shift", "(", "$", "backtrace", ")", ";", "}", "if", "(", "is_numeric", "(", "$", "limitOrFilter", ")", ")", "{", "$", "backtrace", "=", "array_slice", "(", "$", "backtrace", ",", "0", ",", "(", "int", ")", "$", "limitOrFilter", ")", ";", "$", "limitOrFilter", "=", "null", ";", "}", "$", "formattedTrace", "=", "array_map", "(", "array", "(", "$", "this", ",", "'traceComponentMakeSane'", ")", ",", "$", "backtrace", ")", ";", "// Apply the filter. Trace fragment is returned if the string limitOrFilter is found anywhere in a trace", "if", "(", "null", "!==", "$", "limitOrFilter", ")", "{", "foreach", "(", "$", "formattedTrace", "as", "$", "key", "=>", "$", "trace", ")", "{", "$", "traceMatchesFilter", "=", "false", ";", "while", "(", "!", "$", "traceMatchesFilter", "and", "list", "(", ",", "$", "traceLine", ")", "=", "each", "(", "$", "trace", ")", ")", "{", "if", "(", "is_string", "(", "$", "traceLine", ")", ")", "{", "$", "traceMatchesFilter", "=", "false", "!==", "stripos", "(", "$", "traceLine", ",", "$", "limitOrFilter", ")", ";", "}", "}", "if", "(", "!", "$", "traceMatchesFilter", ")", "{", "unset", "(", "$", "formattedTrace", "[", "$", "key", "]", ")", ";", "}", "}", "}", "return", "$", "formattedTrace", ";", "}" ]
Shift trace, filter as required and fix the arguments object @return array
[ "Shift", "trace", "filter", "as", "required", "and", "fix", "the", "arguments", "object" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/BackTrace.php#L76-L112
train
squareproton/Bond
src/Bond/BackTrace.php
BackTrace.traceComponentMakeSane
private function traceComponentMakeSane( $trace ) { // debugging wondering why some traces's don't have a args object set if( isset( $trace['args'] ) ) { $trace['args'] = array_map( function($arg){ switch(true) { case is_object($arg): return get_class($arg); case is_bool($arg): return $arg ? 'true' : 'false'; case is_scalar($arg): return $arg; default: return gettype($arg); } }, $trace['args'] ); } else { $trace['args'] = array(); } if( isset( $trace['file'] ) and false !== $pos = strpos( $trace['file'], '/Symfony/' ) ) { $trace['file'] = ".".substr( $trace['file'], $pos ); } // set the file and line properties if they don't exist if( !array_key_exists( 'file', $trace ) ) { $trace['file'] = null; } if( !array_key_exists( 'line', $trace ) ) { $trace['line'] = null; } // attempt to add file and line back in // not sure why this would be required - it seems very hacky but seemingly corrects some inexplicatbly missing information if( !$trace['file'] and !$trace['line'] and isset( $trace['class'] ) and isset( $trace['function'] ) ) { try { $reflMethod = new \ReflectionMethod( $trace['class'], $trace['function'] ); $trace['file'] = $reflMethod->getFileName(); $trace['line'] = $reflMethod->getStartLine(); } catch ( \Exception $e ) { } } // unset the object property - not sure why this has appeared. It wasn't present in the output of the original sane_debug_backtrace() unset( $trace['object'] ); return $trace; }
php
private function traceComponentMakeSane( $trace ) { // debugging wondering why some traces's don't have a args object set if( isset( $trace['args'] ) ) { $trace['args'] = array_map( function($arg){ switch(true) { case is_object($arg): return get_class($arg); case is_bool($arg): return $arg ? 'true' : 'false'; case is_scalar($arg): return $arg; default: return gettype($arg); } }, $trace['args'] ); } else { $trace['args'] = array(); } if( isset( $trace['file'] ) and false !== $pos = strpos( $trace['file'], '/Symfony/' ) ) { $trace['file'] = ".".substr( $trace['file'], $pos ); } // set the file and line properties if they don't exist if( !array_key_exists( 'file', $trace ) ) { $trace['file'] = null; } if( !array_key_exists( 'line', $trace ) ) { $trace['line'] = null; } // attempt to add file and line back in // not sure why this would be required - it seems very hacky but seemingly corrects some inexplicatbly missing information if( !$trace['file'] and !$trace['line'] and isset( $trace['class'] ) and isset( $trace['function'] ) ) { try { $reflMethod = new \ReflectionMethod( $trace['class'], $trace['function'] ); $trace['file'] = $reflMethod->getFileName(); $trace['line'] = $reflMethod->getStartLine(); } catch ( \Exception $e ) { } } // unset the object property - not sure why this has appeared. It wasn't present in the output of the original sane_debug_backtrace() unset( $trace['object'] ); return $trace; }
[ "private", "function", "traceComponentMakeSane", "(", "$", "trace", ")", "{", "// debugging wondering why some traces's don't have a args object set", "if", "(", "isset", "(", "$", "trace", "[", "'args'", "]", ")", ")", "{", "$", "trace", "[", "'args'", "]", "=", "array_map", "(", "function", "(", "$", "arg", ")", "{", "switch", "(", "true", ")", "{", "case", "is_object", "(", "$", "arg", ")", ":", "return", "get_class", "(", "$", "arg", ")", ";", "case", "is_bool", "(", "$", "arg", ")", ":", "return", "$", "arg", "?", "'true'", ":", "'false'", ";", "case", "is_scalar", "(", "$", "arg", ")", ":", "return", "$", "arg", ";", "default", ":", "return", "gettype", "(", "$", "arg", ")", ";", "}", "}", ",", "$", "trace", "[", "'args'", "]", ")", ";", "}", "else", "{", "$", "trace", "[", "'args'", "]", "=", "array", "(", ")", ";", "}", "if", "(", "isset", "(", "$", "trace", "[", "'file'", "]", ")", "and", "false", "!==", "$", "pos", "=", "strpos", "(", "$", "trace", "[", "'file'", "]", ",", "'/Symfony/'", ")", ")", "{", "$", "trace", "[", "'file'", "]", "=", "\".\"", ".", "substr", "(", "$", "trace", "[", "'file'", "]", ",", "$", "pos", ")", ";", "}", "// set the file and line properties if they don't exist", "if", "(", "!", "array_key_exists", "(", "'file'", ",", "$", "trace", ")", ")", "{", "$", "trace", "[", "'file'", "]", "=", "null", ";", "}", "if", "(", "!", "array_key_exists", "(", "'line'", ",", "$", "trace", ")", ")", "{", "$", "trace", "[", "'line'", "]", "=", "null", ";", "}", "// attempt to add file and line back in", "// not sure why this would be required - it seems very hacky but seemingly corrects some inexplicatbly missing information", "if", "(", "!", "$", "trace", "[", "'file'", "]", "and", "!", "$", "trace", "[", "'line'", "]", "and", "isset", "(", "$", "trace", "[", "'class'", "]", ")", "and", "isset", "(", "$", "trace", "[", "'function'", "]", ")", ")", "{", "try", "{", "$", "reflMethod", "=", "new", "\\", "ReflectionMethod", "(", "$", "trace", "[", "'class'", "]", ",", "$", "trace", "[", "'function'", "]", ")", ";", "$", "trace", "[", "'file'", "]", "=", "$", "reflMethod", "->", "getFileName", "(", ")", ";", "$", "trace", "[", "'line'", "]", "=", "$", "reflMethod", "->", "getStartLine", "(", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "}", "}", "// unset the object property - not sure why this has appeared. It wasn't present in the output of the original sane_debug_backtrace()", "unset", "(", "$", "trace", "[", "'object'", "]", ")", ";", "return", "$", "trace", ";", "}" ]
Format a trace into a more managable output when massive objects are involved @param array $trace @return array
[ "Format", "a", "trace", "into", "a", "more", "managable", "output", "when", "massive", "objects", "are", "involved" ]
a04ad9dd1a35adeaec98237716c2a41ce02b4f1a
https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/BackTrace.php#L119-L167
train
net-tools/core
src/Containers/Pool.php
Pool.release
public function release($item) { // search the item in the used items array $k = array_search($item, $this->_inUseItems); if ( $k === FALSE ) return; // remove it from the used items and adding it to the pool unset($this->_inUseItems[$k]); $this->_poolItems[] = $item; }
php
public function release($item) { // search the item in the used items array $k = array_search($item, $this->_inUseItems); if ( $k === FALSE ) return; // remove it from the used items and adding it to the pool unset($this->_inUseItems[$k]); $this->_poolItems[] = $item; }
[ "public", "function", "release", "(", "$", "item", ")", "{", "// search the item in the used items array", "$", "k", "=", "array_search", "(", "$", "item", ",", "$", "this", "->", "_inUseItems", ")", ";", "if", "(", "$", "k", "===", "FALSE", ")", "return", ";", "// remove it from the used items and adding it to the pool", "unset", "(", "$", "this", "->", "_inUseItems", "[", "$", "k", "]", ")", ";", "$", "this", "->", "_poolItems", "[", "]", "=", "$", "item", ";", "}" ]
Free an item, and replace it in the pool @param object $item Item to release and replace in the pool
[ "Free", "an", "item", "and", "replace", "it", "in", "the", "pool" ]
51446641cee22c0cf53d2b409c76cc8bd1a187e7
https://github.com/net-tools/core/blob/51446641cee22c0cf53d2b409c76cc8bd1a187e7/src/Containers/Pool.php#L98-L108
train
phossa/phossa-logger
src/Phossa/Logger/LogLevel.php
LogLevel.getLevelCode
public static function getLevelCode( /*# string */ $level )/*# : int */ { if (is_string($level) && isset(self::$levels[$level])) { return self::$levels[$level]; } throw new Exception\InvalidArgumentException( Message::get( Message::INVALID_LOG_LEVEL, (string) $level ), Message::INVALID_LOG_LEVEL ); }
php
public static function getLevelCode( /*# string */ $level )/*# : int */ { if (is_string($level) && isset(self::$levels[$level])) { return self::$levels[$level]; } throw new Exception\InvalidArgumentException( Message::get( Message::INVALID_LOG_LEVEL, (string) $level ), Message::INVALID_LOG_LEVEL ); }
[ "public", "static", "function", "getLevelCode", "(", "/*# string */", "$", "level", ")", "/*# : int */", "{", "if", "(", "is_string", "(", "$", "level", ")", "&&", "isset", "(", "self", "::", "$", "levels", "[", "$", "level", "]", ")", ")", "{", "return", "self", "::", "$", "levels", "[", "$", "level", "]", ";", "}", "throw", "new", "Exception", "\\", "InvalidArgumentException", "(", "Message", "::", "get", "(", "Message", "::", "INVALID_LOG_LEVEL", ",", "(", "string", ")", "$", "level", ")", ",", "Message", "::", "INVALID_LOG_LEVEL", ")", ";", "}" ]
Get level code by name @param string $level level name @return int @access public @throws Exception\InvalidArgumentException if $throwException and not the right level name @static @api
[ "Get", "level", "code", "by", "name" ]
dfec8a1e6015c66d2aa77134077902fd3d49e41d
https://github.com/phossa/phossa-logger/blob/dfec8a1e6015c66d2aa77134077902fd3d49e41d/src/Phossa/Logger/LogLevel.php#L63-L78
train
Subscribo/klarna-invoice-sdk-wrapped
src/klarnacalc.php
KlarnaCalc._irr
private static function _irr($pval, $payarray, $fromdayone) { $low = 0.0; $high = 100.0; $lowval = self::_npv($pval, $payarray, $low, $fromdayone); $highval = self::_npv($pval, $payarray, $high, $fromdayone); // The sum of $payarray is smaller than $pval, impossible! if ($lowval > 0.0) { return (-1); } // Standard divide and conquer. do { $mid = self::_midpoint($low, $high); $midval = self::_npv($pval, $payarray, $mid, $fromdayone); if (abs($midval) < self::$accuracy) { //we are close enough return ($mid); } if ($highval < 0.0) { // we are not in range, so double it $low = $high; $lowval = $highval; $high *= 2; $highval = self::_npv($pval, $payarray, $high, $fromdayone); } else if ($midval >= 0.0) { // irr is between low and mid $high = $mid; $highval = $midval; } else { // irr is between mid and high $low = $mid; $lowval = $midval; } } while ($high < 1000000); // bad input, insanely high interest. APR will be INSANER! return (-2); }
php
private static function _irr($pval, $payarray, $fromdayone) { $low = 0.0; $high = 100.0; $lowval = self::_npv($pval, $payarray, $low, $fromdayone); $highval = self::_npv($pval, $payarray, $high, $fromdayone); // The sum of $payarray is smaller than $pval, impossible! if ($lowval > 0.0) { return (-1); } // Standard divide and conquer. do { $mid = self::_midpoint($low, $high); $midval = self::_npv($pval, $payarray, $mid, $fromdayone); if (abs($midval) < self::$accuracy) { //we are close enough return ($mid); } if ($highval < 0.0) { // we are not in range, so double it $low = $high; $lowval = $highval; $high *= 2; $highval = self::_npv($pval, $payarray, $high, $fromdayone); } else if ($midval >= 0.0) { // irr is between low and mid $high = $mid; $highval = $midval; } else { // irr is between mid and high $low = $mid; $lowval = $midval; } } while ($high < 1000000); // bad input, insanely high interest. APR will be INSANER! return (-2); }
[ "private", "static", "function", "_irr", "(", "$", "pval", ",", "$", "payarray", ",", "$", "fromdayone", ")", "{", "$", "low", "=", "0.0", ";", "$", "high", "=", "100.0", ";", "$", "lowval", "=", "self", "::", "_npv", "(", "$", "pval", ",", "$", "payarray", ",", "$", "low", ",", "$", "fromdayone", ")", ";", "$", "highval", "=", "self", "::", "_npv", "(", "$", "pval", ",", "$", "payarray", ",", "$", "high", ",", "$", "fromdayone", ")", ";", "// The sum of $payarray is smaller than $pval, impossible!", "if", "(", "$", "lowval", ">", "0.0", ")", "{", "return", "(", "-", "1", ")", ";", "}", "// Standard divide and conquer.", "do", "{", "$", "mid", "=", "self", "::", "_midpoint", "(", "$", "low", ",", "$", "high", ")", ";", "$", "midval", "=", "self", "::", "_npv", "(", "$", "pval", ",", "$", "payarray", ",", "$", "mid", ",", "$", "fromdayone", ")", ";", "if", "(", "abs", "(", "$", "midval", ")", "<", "self", "::", "$", "accuracy", ")", "{", "//we are close enough", "return", "(", "$", "mid", ")", ";", "}", "if", "(", "$", "highval", "<", "0.0", ")", "{", "// we are not in range, so double it", "$", "low", "=", "$", "high", ";", "$", "lowval", "=", "$", "highval", ";", "$", "high", "*=", "2", ";", "$", "highval", "=", "self", "::", "_npv", "(", "$", "pval", ",", "$", "payarray", ",", "$", "high", ",", "$", "fromdayone", ")", ";", "}", "else", "if", "(", "$", "midval", ">=", "0.0", ")", "{", "// irr is between low and mid", "$", "high", "=", "$", "mid", ";", "$", "highval", "=", "$", "midval", ";", "}", "else", "{", "// irr is between mid and high", "$", "low", "=", "$", "mid", ";", "$", "lowval", "=", "$", "midval", ";", "}", "}", "while", "(", "$", "high", "<", "1000000", ")", ";", "// bad input, insanely high interest. APR will be INSANER!", "return", "(", "-", "2", ")", ";", "}" ]
This function uses divide and conquer to numerically find the IRR, Internal Rate of Return. It starts of by trying a low of 0% and a high of 100%. If this isn't enough it will double the interval up to 1000000%. Note that this is insanely high, and if you try to convert an IRR that high to an APR you will get even more insane values, so feed this function good data. Return values: float irr if it was possible to find a rate that gets npv closer to 0 than $accuracy. int -1 The sum of the payarray is less than the lent amount, $pval. Hellooooooo. Impossible. int -2 the IRR is way to high, giving up. This algorithm works in logarithmic time no matter what inputs you give and it will come to a good answer within ~30 steps. @param float $pval initial loan to customer (in any currency) @param array $payarray array of monthly payments from the customer @param int $fromdayone count interest from the first day? yes(1)/no(0) @return float
[ "This", "function", "uses", "divide", "and", "conquer", "to", "numerically", "find", "the", "IRR", "Internal", "Rate", "of", "Return", ".", "It", "starts", "of", "by", "trying", "a", "low", "of", "0%", "and", "a", "high", "of", "100%", ".", "If", "this", "isn", "t", "enough", "it", "will", "double", "the", "interval", "up", "to", "1000000%", ".", "Note", "that", "this", "is", "insanely", "high", "and", "if", "you", "try", "to", "convert", "an", "IRR", "that", "high", "to", "an", "APR", "you", "will", "get", "even", "more", "insane", "values", "so", "feed", "this", "function", "good", "data", "." ]
4a45ddd9ec444f5a6d02628ad65e635a3e12611c
https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/klarnacalc.php#L114-L153
train
Subscribo/klarna-invoice-sdk-wrapped
src/klarnacalc.php
KlarnaCalc._fulpacc
private static function _fulpacc( $pval, $rate, $fee, $minpay, $payment, $months, $base ) { $bal = $pval; $payarray = array(); while (($months != 0) && ($bal > self::$accuracy)) { $interest = $bal * $rate / (100.0 * 12); $newbal = $bal + $interest + $fee; if ($minpay >= $newbal || $payment >= $newbal) { $payarray[] = $newbal; return $payarray; } $newpay = max($payment, $minpay); if ($base) { $newpay = max($newpay, $bal/24.0 + $fee + $interest); } $bal = $newbal - $newpay; $payarray[] = $newpay; $months -= 1; } return $payarray; }
php
private static function _fulpacc( $pval, $rate, $fee, $minpay, $payment, $months, $base ) { $bal = $pval; $payarray = array(); while (($months != 0) && ($bal > self::$accuracy)) { $interest = $bal * $rate / (100.0 * 12); $newbal = $bal + $interest + $fee; if ($minpay >= $newbal || $payment >= $newbal) { $payarray[] = $newbal; return $payarray; } $newpay = max($payment, $minpay); if ($base) { $newpay = max($newpay, $bal/24.0 + $fee + $interest); } $bal = $newbal - $newpay; $payarray[] = $newpay; $months -= 1; } return $payarray; }
[ "private", "static", "function", "_fulpacc", "(", "$", "pval", ",", "$", "rate", ",", "$", "fee", ",", "$", "minpay", ",", "$", "payment", ",", "$", "months", ",", "$", "base", ")", "{", "$", "bal", "=", "$", "pval", ";", "$", "payarray", "=", "array", "(", ")", ";", "while", "(", "(", "$", "months", "!=", "0", ")", "&&", "(", "$", "bal", ">", "self", "::", "$", "accuracy", ")", ")", "{", "$", "interest", "=", "$", "bal", "*", "$", "rate", "/", "(", "100.0", "*", "12", ")", ";", "$", "newbal", "=", "$", "bal", "+", "$", "interest", "+", "$", "fee", ";", "if", "(", "$", "minpay", ">=", "$", "newbal", "||", "$", "payment", ">=", "$", "newbal", ")", "{", "$", "payarray", "[", "]", "=", "$", "newbal", ";", "return", "$", "payarray", ";", "}", "$", "newpay", "=", "max", "(", "$", "payment", ",", "$", "minpay", ")", ";", "if", "(", "$", "base", ")", "{", "$", "newpay", "=", "max", "(", "$", "newpay", ",", "$", "bal", "/", "24.0", "+", "$", "fee", "+", "$", "interest", ")", ";", "}", "$", "bal", "=", "$", "newbal", "-", "$", "newpay", ";", "$", "payarray", "[", "]", "=", "$", "newpay", ";", "$", "months", "-=", "1", ";", "}", "return", "$", "payarray", ";", "}" ]
This is a simplified model of how our paccengine works if a client always pays their bills. It adds interest and fees and checks minimum payments. It will run until the value of the account reaches 0, and return an array of all the individual payments. Months is the amount of months to run the simulation. Important! Don't feed it too few months or the whole loan won't be paid off, but the other functions should handle this correctly. Giving it too many months has no bad effects, or negative amount of months which means run forever, but it will stop as soon as the account is paid in full. Depending if the account is a base account or not, the payment has to be 1/24 of the capital amount. The payment has to be at least $minpay, unless the capital amount + interest + fee is less than $minpay; in that case that amount is paid and the function returns since the client no longer owes any money. @param float $pval initial loan to customer (in any currency) @param float $rate interest rate per year in % @param float $fee monthly invoice fee @param float $minpay minimum monthly payment allowed for this country. @param float $payment payment the client to pay each month @param int $months amount of months to run (-1 => infinity) @param boolean $base is it a base account? @return array An array of monthly payments for the customer.
[ "This", "is", "a", "simplified", "model", "of", "how", "our", "paccengine", "works", "if", "a", "client", "always", "pays", "their", "bills", ".", "It", "adds", "interest", "and", "fees", "and", "checks", "minimum", "payments", ".", "It", "will", "run", "until", "the", "value", "of", "the", "account", "reaches", "0", "and", "return", "an", "array", "of", "all", "the", "individual", "payments", ".", "Months", "is", "the", "amount", "of", "months", "to", "run", "the", "simulation", ".", "Important!", "Don", "t", "feed", "it", "too", "few", "months", "or", "the", "whole", "loan", "won", "t", "be", "paid", "off", "but", "the", "other", "functions", "should", "handle", "this", "correctly", "." ]
4a45ddd9ec444f5a6d02628ad65e635a3e12611c
https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/klarnacalc.php#L209-L234
train
Subscribo/klarna-invoice-sdk-wrapped
src/klarnacalc.php
KlarnaCalc._aprAnnuity
private static function _aprAnnuity($pval, $months, $rate, $fee, $minpay) { $payment = self::_annuity($pval, $months, $rate) + $fee; if ($payment < 0) { return $payment; } $payarray = self::_fulpacc( $pval, $rate, $fee, $minpay, $payment, $months, false ); $apr = self::_irr2apr(self::_irr($pval, $payarray, 1)); return $apr; }
php
private static function _aprAnnuity($pval, $months, $rate, $fee, $minpay) { $payment = self::_annuity($pval, $months, $rate) + $fee; if ($payment < 0) { return $payment; } $payarray = self::_fulpacc( $pval, $rate, $fee, $minpay, $payment, $months, false ); $apr = self::_irr2apr(self::_irr($pval, $payarray, 1)); return $apr; }
[ "private", "static", "function", "_aprAnnuity", "(", "$", "pval", ",", "$", "months", ",", "$", "rate", ",", "$", "fee", ",", "$", "minpay", ")", "{", "$", "payment", "=", "self", "::", "_annuity", "(", "$", "pval", ",", "$", "months", ",", "$", "rate", ")", "+", "$", "fee", ";", "if", "(", "$", "payment", "<", "0", ")", "{", "return", "$", "payment", ";", "}", "$", "payarray", "=", "self", "::", "_fulpacc", "(", "$", "pval", ",", "$", "rate", ",", "$", "fee", ",", "$", "minpay", ",", "$", "payment", ",", "$", "months", ",", "false", ")", ";", "$", "apr", "=", "self", "::", "_irr2apr", "(", "self", "::", "_irr", "(", "$", "pval", ",", "$", "payarray", ",", "1", ")", ")", ";", "return", "$", "apr", ";", "}" ]
Calculate the APR for an annuity given the following inputs. If you give it bad inputs, it will return negative values. @param float $pval principal value @param int $months months to pay off in @param float $rate interest rate in % as before @param float $fee monthly fee @param float $minpay minimum payment per month @return float APR in %
[ "Calculate", "the", "APR", "for", "an", "annuity", "given", "the", "following", "inputs", "." ]
4a45ddd9ec444f5a6d02628ad65e635a3e12611c
https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/klarnacalc.php#L278-L290
train
Subscribo/klarna-invoice-sdk-wrapped
src/klarnacalc.php
KlarnaCalc._getPayArray
private static function _getPayArray($sum, $pclass, $flags) { $monthsfee = 0; if ($flags === KlarnaFlags::CHECKOUT_PAGE) { $monthsfee = $pclass->getInvoiceFee(); } $startfee = 0; if ($flags === KlarnaFlags::CHECKOUT_PAGE) { $startfee = $pclass->getStartFee(); } //Include start fee in sum $sum += $startfee; $base = ($pclass->getType() === KlarnaPClass::ACCOUNT); $lowest = self::get_lowest_payment_for_account($pclass->getCountry()); if ($flags == KlarnaFlags::CHECKOUT_PAGE) { $minpay = ($pclass->getType() === KlarnaPClass::ACCOUNT) ? $lowest : 0; } else { $minpay = 0; } $payment = self::_annuity( $sum, $pclass->getMonths(), $pclass->getInterestRate() ); //Add monthly fee $payment += $monthsfee; return self::_fulpacc( $sum, $pclass->getInterestRate(), $monthsfee, $minpay, $payment, $pclass->getMonths(), $base ); }
php
private static function _getPayArray($sum, $pclass, $flags) { $monthsfee = 0; if ($flags === KlarnaFlags::CHECKOUT_PAGE) { $monthsfee = $pclass->getInvoiceFee(); } $startfee = 0; if ($flags === KlarnaFlags::CHECKOUT_PAGE) { $startfee = $pclass->getStartFee(); } //Include start fee in sum $sum += $startfee; $base = ($pclass->getType() === KlarnaPClass::ACCOUNT); $lowest = self::get_lowest_payment_for_account($pclass->getCountry()); if ($flags == KlarnaFlags::CHECKOUT_PAGE) { $minpay = ($pclass->getType() === KlarnaPClass::ACCOUNT) ? $lowest : 0; } else { $minpay = 0; } $payment = self::_annuity( $sum, $pclass->getMonths(), $pclass->getInterestRate() ); //Add monthly fee $payment += $monthsfee; return self::_fulpacc( $sum, $pclass->getInterestRate(), $monthsfee, $minpay, $payment, $pclass->getMonths(), $base ); }
[ "private", "static", "function", "_getPayArray", "(", "$", "sum", ",", "$", "pclass", ",", "$", "flags", ")", "{", "$", "monthsfee", "=", "0", ";", "if", "(", "$", "flags", "===", "KlarnaFlags", "::", "CHECKOUT_PAGE", ")", "{", "$", "monthsfee", "=", "$", "pclass", "->", "getInvoiceFee", "(", ")", ";", "}", "$", "startfee", "=", "0", ";", "if", "(", "$", "flags", "===", "KlarnaFlags", "::", "CHECKOUT_PAGE", ")", "{", "$", "startfee", "=", "$", "pclass", "->", "getStartFee", "(", ")", ";", "}", "//Include start fee in sum", "$", "sum", "+=", "$", "startfee", ";", "$", "base", "=", "(", "$", "pclass", "->", "getType", "(", ")", "===", "KlarnaPClass", "::", "ACCOUNT", ")", ";", "$", "lowest", "=", "self", "::", "get_lowest_payment_for_account", "(", "$", "pclass", "->", "getCountry", "(", ")", ")", ";", "if", "(", "$", "flags", "==", "KlarnaFlags", "::", "CHECKOUT_PAGE", ")", "{", "$", "minpay", "=", "(", "$", "pclass", "->", "getType", "(", ")", "===", "KlarnaPClass", "::", "ACCOUNT", ")", "?", "$", "lowest", ":", "0", ";", "}", "else", "{", "$", "minpay", "=", "0", ";", "}", "$", "payment", "=", "self", "::", "_annuity", "(", "$", "sum", ",", "$", "pclass", "->", "getMonths", "(", ")", ",", "$", "pclass", "->", "getInterestRate", "(", ")", ")", ";", "//Add monthly fee", "$", "payment", "+=", "$", "monthsfee", ";", "return", "self", "::", "_fulpacc", "(", "$", "sum", ",", "$", "pclass", "->", "getInterestRate", "(", ")", ",", "$", "monthsfee", ",", "$", "minpay", ",", "$", "payment", ",", "$", "pclass", "->", "getMonths", "(", ")", ",", "$", "base", ")", ";", "}" ]
Grabs the array of all monthly payments for specified PClass. <b>Flags can be either</b>:<br> {@link KlarnaFlags::CHECKOUT_PAGE}<br> {@link KlarnaFlags::PRODUCT_PAGE}<br> @param float $sum The sum for the order/product. @param KlarnaPClass $pclass KlarnaPClass used to calculate the APR. @param int $flags Checkout or Product page. @throws KlarnaException @return array An array of monthly payments.
[ "Grabs", "the", "array", "of", "all", "monthly", "payments", "for", "specified", "PClass", "." ]
4a45ddd9ec444f5a6d02628ad65e635a3e12611c
https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/klarnacalc.php#L306-L347
train
Subscribo/klarna-invoice-sdk-wrapped
src/klarnacalc.php
KlarnaCalc.pRound
public static function pRound($value, $country) { $multiply = 1; //Round to closest integer $country = KlarnaCountry::getCode($country); switch($country) { case "FI": case "DE": case "NL": case "AT": $multiply = 10; //Round to closest decimal break; } return floor(($value*$multiply)+0.5)/$multiply; }
php
public static function pRound($value, $country) { $multiply = 1; //Round to closest integer $country = KlarnaCountry::getCode($country); switch($country) { case "FI": case "DE": case "NL": case "AT": $multiply = 10; //Round to closest decimal break; } return floor(($value*$multiply)+0.5)/$multiply; }
[ "public", "static", "function", "pRound", "(", "$", "value", ",", "$", "country", ")", "{", "$", "multiply", "=", "1", ";", "//Round to closest integer", "$", "country", "=", "KlarnaCountry", "::", "getCode", "(", "$", "country", ")", ";", "switch", "(", "$", "country", ")", "{", "case", "\"FI\"", ":", "case", "\"DE\"", ":", "case", "\"NL\"", ":", "case", "\"AT\"", ":", "$", "multiply", "=", "10", ";", "//Round to closest decimal", "break", ";", "}", "return", "floor", "(", "(", "$", "value", "*", "$", "multiply", ")", "+", "0.5", ")", "/", "$", "multiply", ";", "}" ]
Rounds a value depending on the specified country. @param int|float $value The value to be rounded. @param int $country KlarnaCountry constant. @return float|int
[ "Rounds", "a", "value", "depending", "on", "the", "specified", "country", "." ]
4a45ddd9ec444f5a6d02628ad65e635a3e12611c
https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/klarnacalc.php#L638-L652
train
mossphp/moss-storage
Moss/Storage/Query/Relation/AbstractRelation.php
AbstractRelation.where
public function where($field, $value, $comparison = '==', $logical = 'and') { $this->conditions[] = [$field, $value, $comparison, $logical]; return $this; }
php
public function where($field, $value, $comparison = '==', $logical = 'and') { $this->conditions[] = [$field, $value, $comparison, $logical]; return $this; }
[ "public", "function", "where", "(", "$", "field", ",", "$", "value", ",", "$", "comparison", "=", "'=='", ",", "$", "logical", "=", "'and'", ")", "{", "$", "this", "->", "conditions", "[", "]", "=", "[", "$", "field", ",", "$", "value", ",", "$", "comparison", ",", "$", "logical", "]", ";", "return", "$", "this", ";", "}" ]
Adds where condition to relation @param mixed $field @param mixed $value @param string $comparison @param string $logical @return $this
[ "Adds", "where", "condition", "to", "relation" ]
0d123e7ae6bbfce1e2a18e73bf70997277b430c1
https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Query/Relation/AbstractRelation.php#L116-L121
train
mossphp/moss-storage
Moss/Storage/Query/Relation/AbstractRelation.php
AbstractRelation.buildLocalKey
protected function buildLocalKey($entity, array $pairs) { $keys = array_keys($pairs); return $this->buildKey($entity, array_combine($keys, $keys)); }
php
protected function buildLocalKey($entity, array $pairs) { $keys = array_keys($pairs); return $this->buildKey($entity, array_combine($keys, $keys)); }
[ "protected", "function", "buildLocalKey", "(", "$", "entity", ",", "array", "$", "pairs", ")", "{", "$", "keys", "=", "array_keys", "(", "$", "pairs", ")", ";", "return", "$", "this", "->", "buildKey", "(", "$", "entity", ",", "array_combine", "(", "$", "keys", ",", "$", "keys", ")", ")", ";", "}" ]
Builds local key from field property pairs @param mixed $entity @param array $pairs @return string
[ "Builds", "local", "key", "from", "field", "property", "pairs" ]
0d123e7ae6bbfce1e2a18e73bf70997277b430c1
https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Query/Relation/AbstractRelation.php#L162-L167
train
mossphp/moss-storage
Moss/Storage/Query/Relation/AbstractRelation.php
AbstractRelation.buildKey
protected function buildKey($entity, array $pairs) { $key = []; foreach ($pairs as $local => $refer) { $key[] = $local . ':' . $this->accessor->getPropertyValue($entity, $refer); } return implode('-', $key); }
php
protected function buildKey($entity, array $pairs) { $key = []; foreach ($pairs as $local => $refer) { $key[] = $local . ':' . $this->accessor->getPropertyValue($entity, $refer); } return implode('-', $key); }
[ "protected", "function", "buildKey", "(", "$", "entity", ",", "array", "$", "pairs", ")", "{", "$", "key", "=", "[", "]", ";", "foreach", "(", "$", "pairs", "as", "$", "local", "=>", "$", "refer", ")", "{", "$", "key", "[", "]", "=", "$", "local", ".", "':'", ".", "$", "this", "->", "accessor", "->", "getPropertyValue", "(", "$", "entity", ",", "$", "refer", ")", ";", "}", "return", "implode", "(", "'-'", ",", "$", "key", ")", ";", "}" ]
Builds key from key-value pairs @param mixed $entity @param array $pairs @return string
[ "Builds", "key", "from", "key", "-", "value", "pairs" ]
0d123e7ae6bbfce1e2a18e73bf70997277b430c1
https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Query/Relation/AbstractRelation.php#L190-L198
train
mossphp/moss-storage
Moss/Storage/Query/Relation/AbstractRelation.php
AbstractRelation.fetch
protected function fetch($entityName, array $conditions, $result = false) { $query = $this->storage->read($entityName); foreach ($conditions as $field => $values) { $query->where($field, $values); } if (!$result) { return $query->execute(); } foreach ($this->relations as $relation) { $query->with($relation->name()); } foreach ($this->conditions as $condition) { $query->where($condition[0], $condition[1], $condition[2], $condition[3]); } foreach ($this->orders as $order) { $query->order($order[0], $order[1]); } if ($this->limit !== null || $this->offset !== null) { $query->limit($this->limit, $this->offset); } return $query->execute(); }
php
protected function fetch($entityName, array $conditions, $result = false) { $query = $this->storage->read($entityName); foreach ($conditions as $field => $values) { $query->where($field, $values); } if (!$result) { return $query->execute(); } foreach ($this->relations as $relation) { $query->with($relation->name()); } foreach ($this->conditions as $condition) { $query->where($condition[0], $condition[1], $condition[2], $condition[3]); } foreach ($this->orders as $order) { $query->order($order[0], $order[1]); } if ($this->limit !== null || $this->offset !== null) { $query->limit($this->limit, $this->offset); } return $query->execute(); }
[ "protected", "function", "fetch", "(", "$", "entityName", ",", "array", "$", "conditions", ",", "$", "result", "=", "false", ")", "{", "$", "query", "=", "$", "this", "->", "storage", "->", "read", "(", "$", "entityName", ")", ";", "foreach", "(", "$", "conditions", "as", "$", "field", "=>", "$", "values", ")", "{", "$", "query", "->", "where", "(", "$", "field", ",", "$", "values", ")", ";", "}", "if", "(", "!", "$", "result", ")", "{", "return", "$", "query", "->", "execute", "(", ")", ";", "}", "foreach", "(", "$", "this", "->", "relations", "as", "$", "relation", ")", "{", "$", "query", "->", "with", "(", "$", "relation", "->", "name", "(", ")", ")", ";", "}", "foreach", "(", "$", "this", "->", "conditions", "as", "$", "condition", ")", "{", "$", "query", "->", "where", "(", "$", "condition", "[", "0", "]", ",", "$", "condition", "[", "1", "]", ",", "$", "condition", "[", "2", "]", ",", "$", "condition", "[", "3", "]", ")", ";", "}", "foreach", "(", "$", "this", "->", "orders", "as", "$", "order", ")", "{", "$", "query", "->", "order", "(", "$", "order", "[", "0", "]", ",", "$", "order", "[", "1", "]", ")", ";", "}", "if", "(", "$", "this", "->", "limit", "!==", "null", "||", "$", "this", "->", "offset", "!==", "null", ")", "{", "$", "query", "->", "limit", "(", "$", "this", "->", "limit", ",", "$", "this", "->", "offset", ")", ";", "}", "return", "$", "query", "->", "execute", "(", ")", ";", "}" ]
Fetches collection of entities matching set conditions Optionally sorts it and limits it @param string $entityName @param array $conditions @param bool $result @return array
[ "Fetches", "collection", "of", "entities", "matching", "set", "conditions", "Optionally", "sorts", "it", "and", "limits", "it" ]
0d123e7ae6bbfce1e2a18e73bf70997277b430c1
https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Query/Relation/AbstractRelation.php#L210-L239
train
mossphp/moss-storage
Moss/Storage/Query/Relation/AbstractRelation.php
AbstractRelation.assertInstance
protected function assertInstance($entity) { $entityClass = $this->definition->entity(); if (!$entity instanceof $entityClass) { throw new RelationException(sprintf('Relation entity must be instance of %s, got %s', $entityClass, $this->getType($entity))); } return true; }
php
protected function assertInstance($entity) { $entityClass = $this->definition->entity(); if (!$entity instanceof $entityClass) { throw new RelationException(sprintf('Relation entity must be instance of %s, got %s', $entityClass, $this->getType($entity))); } return true; }
[ "protected", "function", "assertInstance", "(", "$", "entity", ")", "{", "$", "entityClass", "=", "$", "this", "->", "definition", "->", "entity", "(", ")", ";", "if", "(", "!", "$", "entity", "instanceof", "$", "entityClass", ")", "{", "throw", "new", "RelationException", "(", "sprintf", "(", "'Relation entity must be instance of %s, got %s'", ",", "$", "entityClass", ",", "$", "this", "->", "getType", "(", "$", "entity", ")", ")", ")", ";", "}", "return", "true", ";", "}" ]
Throws exception when entity is not required instance @param mixed $entity @return bool @throws RelationException
[ "Throws", "exception", "when", "entity", "is", "not", "required", "instance" ]
0d123e7ae6bbfce1e2a18e73bf70997277b430c1
https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Query/Relation/AbstractRelation.php#L249-L257
train
mossphp/moss-storage
Moss/Storage/Query/Relation/AbstractRelation.php
AbstractRelation.cleanup
protected function cleanup($entityName, array $collection, array $conditions) { if (!$existing = $this->isCleanupNecessary($entityName, $conditions)) { return; } $identifiers = []; foreach ($collection as $instance) { $identifiers[] = $this->identifyEntity($instance, $entityName); } foreach ($existing as $instance) { if (in_array($this->identifyEntity($instance, $entityName), $identifiers)) { continue; } $this->storage->delete($instance, $entityName)->execute(); } return; }
php
protected function cleanup($entityName, array $collection, array $conditions) { if (!$existing = $this->isCleanupNecessary($entityName, $conditions)) { return; } $identifiers = []; foreach ($collection as $instance) { $identifiers[] = $this->identifyEntity($instance, $entityName); } foreach ($existing as $instance) { if (in_array($this->identifyEntity($instance, $entityName), $identifiers)) { continue; } $this->storage->delete($instance, $entityName)->execute(); } return; }
[ "protected", "function", "cleanup", "(", "$", "entityName", ",", "array", "$", "collection", ",", "array", "$", "conditions", ")", "{", "if", "(", "!", "$", "existing", "=", "$", "this", "->", "isCleanupNecessary", "(", "$", "entityName", ",", "$", "conditions", ")", ")", "{", "return", ";", "}", "$", "identifiers", "=", "[", "]", ";", "foreach", "(", "$", "collection", "as", "$", "instance", ")", "{", "$", "identifiers", "[", "]", "=", "$", "this", "->", "identifyEntity", "(", "$", "instance", ",", "$", "entityName", ")", ";", "}", "foreach", "(", "$", "existing", "as", "$", "instance", ")", "{", "if", "(", "in_array", "(", "$", "this", "->", "identifyEntity", "(", "$", "instance", ",", "$", "entityName", ")", ",", "$", "identifiers", ")", ")", "{", "continue", ";", "}", "$", "this", "->", "storage", "->", "delete", "(", "$", "instance", ",", "$", "entityName", ")", "->", "execute", "(", ")", ";", "}", "return", ";", "}" ]
Removes obsolete entities that match conditions but don't exist in collection @param string $entityName @param array $collection @param array $conditions
[ "Removes", "obsolete", "entities", "that", "match", "conditions", "but", "don", "t", "exist", "in", "collection" ]
0d123e7ae6bbfce1e2a18e73bf70997277b430c1
https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Query/Relation/AbstractRelation.php#L266-L286
train
mossphp/moss-storage
Moss/Storage/Query/Relation/AbstractRelation.php
AbstractRelation.isCleanupNecessary
private function isCleanupNecessary($entityName, $conditions) { if (empty($conditions)) { return false; } $existing = $this->fetch($entityName, $conditions); if (empty($existing)) { return false; } return $existing; }
php
private function isCleanupNecessary($entityName, $conditions) { if (empty($conditions)) { return false; } $existing = $this->fetch($entityName, $conditions); if (empty($existing)) { return false; } return $existing; }
[ "private", "function", "isCleanupNecessary", "(", "$", "entityName", ",", "$", "conditions", ")", "{", "if", "(", "empty", "(", "$", "conditions", ")", ")", "{", "return", "false", ";", "}", "$", "existing", "=", "$", "this", "->", "fetch", "(", "$", "entityName", ",", "$", "conditions", ")", ";", "if", "(", "empty", "(", "$", "existing", ")", ")", "{", "return", "false", ";", "}", "return", "$", "existing", ";", "}" ]
Returns array with entities that should be deleted or false otherwise @param string $entityName @param array $conditions @return array|bool
[ "Returns", "array", "with", "entities", "that", "should", "be", "deleted", "or", "false", "otherwise" ]
0d123e7ae6bbfce1e2a18e73bf70997277b430c1
https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Query/Relation/AbstractRelation.php#L296-L309
train
mossphp/moss-storage
Moss/Storage/Query/Relation/AbstractRelation.php
AbstractRelation.identifyEntity
protected function identifyEntity($instance, $entityName) { $fields = $this->models->get($entityName)->primaryFields(); $id = []; foreach ($fields as $field) { $id[] = $this->accessor->getPropertyValue($instance, $field->name()); } return implode(':', $id); }
php
protected function identifyEntity($instance, $entityName) { $fields = $this->models->get($entityName)->primaryFields(); $id = []; foreach ($fields as $field) { $id[] = $this->accessor->getPropertyValue($instance, $field->name()); } return implode(':', $id); }
[ "protected", "function", "identifyEntity", "(", "$", "instance", ",", "$", "entityName", ")", "{", "$", "fields", "=", "$", "this", "->", "models", "->", "get", "(", "$", "entityName", ")", "->", "primaryFields", "(", ")", ";", "$", "id", "=", "[", "]", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "$", "id", "[", "]", "=", "$", "this", "->", "accessor", "->", "getPropertyValue", "(", "$", "instance", ",", "$", "field", "->", "name", "(", ")", ")", ";", "}", "return", "implode", "(", "':'", ",", "$", "id", ")", ";", "}" ]
Returns entity identifier If more than one primary keys, entity will not be identified @param object $instance @param string $entityName @return string
[ "Returns", "entity", "identifier", "If", "more", "than", "one", "primary", "keys", "entity", "will", "not", "be", "identified" ]
0d123e7ae6bbfce1e2a18e73bf70997277b430c1
https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Query/Relation/AbstractRelation.php#L320-L330
train
mossphp/moss-storage
Moss/Storage/Query/Relation/AbstractRelation.php
AbstractRelation.assertArrayAccess
protected function assertArrayAccess($container) { if (!$container instanceof \Traversable && !is_array($container)) { throw new RelationException(sprintf('Relation container must be array or instance of ArrayAccess, got %s', $this->getType($container))); } }
php
protected function assertArrayAccess($container) { if (!$container instanceof \Traversable && !is_array($container)) { throw new RelationException(sprintf('Relation container must be array or instance of ArrayAccess, got %s', $this->getType($container))); } }
[ "protected", "function", "assertArrayAccess", "(", "$", "container", ")", "{", "if", "(", "!", "$", "container", "instanceof", "\\", "Traversable", "&&", "!", "is_array", "(", "$", "container", ")", ")", "{", "throw", "new", "RelationException", "(", "sprintf", "(", "'Relation container must be array or instance of ArrayAccess, got %s'", ",", "$", "this", "->", "getType", "(", "$", "container", ")", ")", ")", ";", "}", "}" ]
Checks if container has array access @param $container @throws RelationException
[ "Checks", "if", "container", "has", "array", "access" ]
0d123e7ae6bbfce1e2a18e73bf70997277b430c1
https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Query/Relation/AbstractRelation.php#L339-L344
train
SlaxWeb/Database
src/BaseModelResult.php
BaseModelResult.row
public function row(int $row): bool { $this->resultExists(); return $this->result->row($row); }
php
public function row(int $row): bool { $this->resultExists(); return $this->result->row($row); }
[ "public", "function", "row", "(", "int", "$", "row", ")", ":", "bool", "{", "$", "this", "->", "resultExists", "(", ")", ";", "return", "$", "this", "->", "result", "->", "row", "(", "$", "row", ")", ";", "}" ]
Jump to row Check if the Result object has been set and forwards the call to the 'row' method in the Result object. @param int $row Row number @return bool
[ "Jump", "to", "row" ]
75fb701cda426eccb99e7604f6c7ddb0eb81a572
https://github.com/SlaxWeb/Database/blob/75fb701cda426eccb99e7604f6c7ddb0eb81a572/src/BaseModelResult.php#L80-L84
train
Torann/skosh-generator
src/AssetManifest.php
AssetManifest.load
public function load() { $file = BASE_PATH . '/rev-manifest.json'; if (file_exists($file)) { $this->manifest = json_decode(file_get_contents($file), true); } }
php
public function load() { $file = BASE_PATH . '/rev-manifest.json'; if (file_exists($file)) { $this->manifest = json_decode(file_get_contents($file), true); } }
[ "public", "function", "load", "(", ")", "{", "$", "file", "=", "BASE_PATH", ".", "'/rev-manifest.json'", ";", "if", "(", "file_exists", "(", "$", "file", ")", ")", "{", "$", "this", "->", "manifest", "=", "json_decode", "(", "file_get_contents", "(", "$", "file", ")", ",", "true", ")", ";", "}", "}" ]
Load manifest file
[ "Load", "manifest", "file" ]
ea60e037d92398d7c146eb2349735d5692e3c48c
https://github.com/Torann/skosh-generator/blob/ea60e037d92398d7c146eb2349735d5692e3c48c/src/AssetManifest.php#L38-L45
train
balintsera/evista-perform
src/ValueObject/UploadedFile.php
UploadedFile.findRealType
public function findRealType() { $finfo = new \finfo(); // Move file to the upload folder for checking $fileName = md5(microtime()); $destination = $this->uploadDir; move_uploaded_file($this->tmpName, $destination.'/'.$fileName); $this->realType = $finfo->file($destination.'/'.$fileName, FILEINFO_MIME_TYPE); $this->tmpName = $destination.'/'.$fileName; return $this; }
php
public function findRealType() { $finfo = new \finfo(); // Move file to the upload folder for checking $fileName = md5(microtime()); $destination = $this->uploadDir; move_uploaded_file($this->tmpName, $destination.'/'.$fileName); $this->realType = $finfo->file($destination.'/'.$fileName, FILEINFO_MIME_TYPE); $this->tmpName = $destination.'/'.$fileName; return $this; }
[ "public", "function", "findRealType", "(", ")", "{", "$", "finfo", "=", "new", "\\", "finfo", "(", ")", ";", "// Move file to the upload folder for checking", "$", "fileName", "=", "md5", "(", "microtime", "(", ")", ")", ";", "$", "destination", "=", "$", "this", "->", "uploadDir", ";", "move_uploaded_file", "(", "$", "this", "->", "tmpName", ",", "$", "destination", ".", "'/'", ".", "$", "fileName", ")", ";", "$", "this", "->", "realType", "=", "$", "finfo", "->", "file", "(", "$", "destination", ".", "'/'", ".", "$", "fileName", ",", "FILEINFO_MIME_TYPE", ")", ";", "$", "this", "->", "tmpName", "=", "$", "destination", ".", "'/'", ".", "$", "fileName", ";", "return", "$", "this", ";", "}" ]
adds real file type @return [type] [description]
[ "adds", "real", "file", "type" ]
2b8723852ebe824ed721f30293e1e0d2c14f4b21
https://github.com/balintsera/evista-perform/blob/2b8723852ebe824ed721f30293e1e0d2c14f4b21/src/ValueObject/UploadedFile.php#L121-L133
train