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
wb-crowdfusion/crowdfusion
system/core/classes/mvc/filters/TagsFilterer.php
TagsFilterer.filter
public function filter() { $count = 0; $tags = $this->getParameter('Tags'); if($tags === null) $tags = $this->getLocal('LinkTags'); $maxRows = $this->getParameter('MaxRows'); $partial = $this->getParameter('Partial'); $partials = array(); if(!empty($partial)) { $partialsStr = explode(',',$partial); foreach($partialsStr as $partial) $partials[] = new TagPartial($partial); } $return = $this->getParameter('Return'); if(empty($return)) $return = 'TagLinkTitle'; $value = ''; if (empty($tags)) return; foreach ((array)$tags as $tag) { if (!empty($partials)) { $found = false; foreach($partials as $partial) { if($this->TagsHelper->matchPartial($partial, $tag)) { $found = true; break; } } if(!$found) continue; } if (($this->getParameter('Status.eq') != null) && $tag['TagLinkStatus'] != $this->getParameter('Status.eq')) continue; if (($this->getParameter('Status.isActive') != null) && empty($tag['TagLinkURL'])) continue; $count++; if ($return != 'count' && ($tag instanceof Tag || is_array($tag))) { $value .= $tag[$return] . ', '; } if(!empty($maxRows) && $count == $maxRows) break; } if ($return == 'count') return $count; if ($this->getParameter('ReturnString') != null) $value = str_replace("%ReturnValue%", $value, $this->getParameter('ReturnString')); return substr($value, 0, -2); }
php
public function filter() { $count = 0; $tags = $this->getParameter('Tags'); if($tags === null) $tags = $this->getLocal('LinkTags'); $maxRows = $this->getParameter('MaxRows'); $partial = $this->getParameter('Partial'); $partials = array(); if(!empty($partial)) { $partialsStr = explode(',',$partial); foreach($partialsStr as $partial) $partials[] = new TagPartial($partial); } $return = $this->getParameter('Return'); if(empty($return)) $return = 'TagLinkTitle'; $value = ''; if (empty($tags)) return; foreach ((array)$tags as $tag) { if (!empty($partials)) { $found = false; foreach($partials as $partial) { if($this->TagsHelper->matchPartial($partial, $tag)) { $found = true; break; } } if(!$found) continue; } if (($this->getParameter('Status.eq') != null) && $tag['TagLinkStatus'] != $this->getParameter('Status.eq')) continue; if (($this->getParameter('Status.isActive') != null) && empty($tag['TagLinkURL'])) continue; $count++; if ($return != 'count' && ($tag instanceof Tag || is_array($tag))) { $value .= $tag[$return] . ', '; } if(!empty($maxRows) && $count == $maxRows) break; } if ($return == 'count') return $count; if ($this->getParameter('ReturnString') != null) $value = str_replace("%ReturnValue%", $value, $this->getParameter('ReturnString')); return substr($value, 0, -2); }
[ "public", "function", "filter", "(", ")", "{", "$", "count", "=", "0", ";", "$", "tags", "=", "$", "this", "->", "getParameter", "(", "'Tags'", ")", ";", "if", "(", "$", "tags", "===", "null", ")", "$", "tags", "=", "$", "this", "->", "getLocal", "(", "'LinkTags'", ")", ";", "$", "maxRows", "=", "$", "this", "->", "getParameter", "(", "'MaxRows'", ")", ";", "$", "partial", "=", "$", "this", "->", "getParameter", "(", "'Partial'", ")", ";", "$", "partials", "=", "array", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "partial", ")", ")", "{", "$", "partialsStr", "=", "explode", "(", "','", ",", "$", "partial", ")", ";", "foreach", "(", "$", "partialsStr", "as", "$", "partial", ")", "$", "partials", "[", "]", "=", "new", "TagPartial", "(", "$", "partial", ")", ";", "}", "$", "return", "=", "$", "this", "->", "getParameter", "(", "'Return'", ")", ";", "if", "(", "empty", "(", "$", "return", ")", ")", "$", "return", "=", "'TagLinkTitle'", ";", "$", "value", "=", "''", ";", "if", "(", "empty", "(", "$", "tags", ")", ")", "return", ";", "foreach", "(", "(", "array", ")", "$", "tags", "as", "$", "tag", ")", "{", "if", "(", "!", "empty", "(", "$", "partials", ")", ")", "{", "$", "found", "=", "false", ";", "foreach", "(", "$", "partials", "as", "$", "partial", ")", "{", "if", "(", "$", "this", "->", "TagsHelper", "->", "matchPartial", "(", "$", "partial", ",", "$", "tag", ")", ")", "{", "$", "found", "=", "true", ";", "break", ";", "}", "}", "if", "(", "!", "$", "found", ")", "continue", ";", "}", "if", "(", "(", "$", "this", "->", "getParameter", "(", "'Status.eq'", ")", "!=", "null", ")", "&&", "$", "tag", "[", "'TagLinkStatus'", "]", "!=", "$", "this", "->", "getParameter", "(", "'Status.eq'", ")", ")", "continue", ";", "if", "(", "(", "$", "this", "->", "getParameter", "(", "'Status.isActive'", ")", "!=", "null", ")", "&&", "empty", "(", "$", "tag", "[", "'TagLinkURL'", "]", ")", ")", "continue", ";", "$", "count", "++", ";", "if", "(", "$", "return", "!=", "'count'", "&&", "(", "$", "tag", "instanceof", "Tag", "||", "is_array", "(", "$", "tag", ")", ")", ")", "{", "$", "value", ".=", "$", "tag", "[", "$", "return", "]", ".", "', '", ";", "}", "if", "(", "!", "empty", "(", "$", "maxRows", ")", "&&", "$", "count", "==", "$", "maxRows", ")", "break", ";", "}", "if", "(", "$", "return", "==", "'count'", ")", "return", "$", "count", ";", "if", "(", "$", "this", "->", "getParameter", "(", "'ReturnString'", ")", "!=", "null", ")", "$", "value", "=", "str_replace", "(", "\"%ReturnValue%\"", ",", "$", "value", ",", "$", "this", "->", "getParameter", "(", "'ReturnString'", ")", ")", ";", "return", "substr", "(", "$", "value", ",", "0", ",", "-", "2", ")", ";", "}" ]
Returns a subset of tags filtered according to the params passed. Expected Params: Tags array An Array of tags that we want to filter Partial string (optional) A CSV string of types that we want FilterElement string (required only with FilterType. Optional otherwise) The tag element to filter for FilterSlug string (optional) The slug to filter for FilterRole string (optional) The TagRole to match FilterLinkStatus string (optional) The TagLinkStatus to match FilterLinkURLExists string (optional) If set, then a value is required in TagLinkURL return string If set to 'count', the function will return a count of the number of tags matched. Otherwise should be set to Type, Element, Slug, Role, (any other Tag* attribute) which specifies what will be returned. ReturnString string If specified and Param 'return' is not set to 'count', then this string will be returned with '%ReturnValue%' in the string replaced with the value the value from the tag. @return string
[ "Returns", "a", "subset", "of", "tags", "filtered", "according", "to", "the", "params", "passed", "." ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/filters/TagsFilterer.php#L100-L162
train
Dhii/config
src/ReplaceReferencesCapableTrait.php
ReplaceReferencesCapableTrait._replaceReferences
protected function _replaceReferences($input, ContainerInterface $container, $default = null, $startDelimiter = '${', $endDelimiter = '}') { $regexpDelimiter = '/'; $input = $this->_normalizeString($input); $defaultValue = $default === null ? '' : $this->_normalizeString($default); $startDelimiter = preg_quote($this->_normalizeString($startDelimiter), $regexpDelimiter); $endDelimiter = preg_quote($this->_normalizeString($endDelimiter), $regexpDelimiter); $regexp = $regexpDelimiter . $startDelimiter . '(.*?)' . $endDelimiter . $regexpDelimiter; preg_match_all($regexp, $input, $matches); foreach ($matches[0] as $i => $token) { $key = $matches[1][$i]; try { $value = $container->get($key); } catch (NotFoundExceptionInterface $e) { $value = $defaultValue; } $input = str_replace($token, $value, $input); } return $input; }
php
protected function _replaceReferences($input, ContainerInterface $container, $default = null, $startDelimiter = '${', $endDelimiter = '}') { $regexpDelimiter = '/'; $input = $this->_normalizeString($input); $defaultValue = $default === null ? '' : $this->_normalizeString($default); $startDelimiter = preg_quote($this->_normalizeString($startDelimiter), $regexpDelimiter); $endDelimiter = preg_quote($this->_normalizeString($endDelimiter), $regexpDelimiter); $regexp = $regexpDelimiter . $startDelimiter . '(.*?)' . $endDelimiter . $regexpDelimiter; preg_match_all($regexp, $input, $matches); foreach ($matches[0] as $i => $token) { $key = $matches[1][$i]; try { $value = $container->get($key); } catch (NotFoundExceptionInterface $e) { $value = $defaultValue; } $input = str_replace($token, $value, $input); } return $input; }
[ "protected", "function", "_replaceReferences", "(", "$", "input", ",", "ContainerInterface", "$", "container", ",", "$", "default", "=", "null", ",", "$", "startDelimiter", "=", "'${'", ",", "$", "endDelimiter", "=", "'}'", ")", "{", "$", "regexpDelimiter", "=", "'/'", ";", "$", "input", "=", "$", "this", "->", "_normalizeString", "(", "$", "input", ")", ";", "$", "defaultValue", "=", "$", "default", "===", "null", "?", "''", ":", "$", "this", "->", "_normalizeString", "(", "$", "default", ")", ";", "$", "startDelimiter", "=", "preg_quote", "(", "$", "this", "->", "_normalizeString", "(", "$", "startDelimiter", ")", ",", "$", "regexpDelimiter", ")", ";", "$", "endDelimiter", "=", "preg_quote", "(", "$", "this", "->", "_normalizeString", "(", "$", "endDelimiter", ")", ",", "$", "regexpDelimiter", ")", ";", "$", "regexp", "=", "$", "regexpDelimiter", ".", "$", "startDelimiter", ".", "'(.*?)'", ".", "$", "endDelimiter", ".", "$", "regexpDelimiter", ";", "preg_match_all", "(", "$", "regexp", ",", "$", "input", ",", "$", "matches", ")", ";", "foreach", "(", "$", "matches", "[", "0", "]", "as", "$", "i", "=>", "$", "token", ")", "{", "$", "key", "=", "$", "matches", "[", "1", "]", "[", "$", "i", "]", ";", "try", "{", "$", "value", "=", "$", "container", "->", "get", "(", "$", "key", ")", ";", "}", "catch", "(", "NotFoundExceptionInterface", "$", "e", ")", "{", "$", "value", "=", "$", "defaultValue", ";", "}", "$", "input", "=", "str_replace", "(", "$", "token", ",", "$", "value", ",", "$", "input", ")", ";", "}", "return", "$", "input", ";", "}" ]
Replaces all tokens wrapped with some delimiters in a string with corresponding values retrieved from a container. @since [*next-version*] @param string|Stringable $input Input string to find and replace references @param ContainerInterface $container Container to retrieve values for replace. @param string|Stringable $startDelimiter Starting delimiter of token for replace @param mixed $default String to replace reference if key not found in container. @param string|Stringable $endDelimiter Ending delimiter of token for replace @throws ContainerExceptionInterface Error while retrieving the entry from the container. @return string The resulting string.
[ "Replaces", "all", "tokens", "wrapped", "with", "some", "delimiters", "in", "a", "string", "with", "corresponding", "values", "retrieved", "from", "a", "container", "." ]
1ab9a7ccf9c0ebd7c6fcbce600b4c00b52b2fdcf
https://github.com/Dhii/config/blob/1ab9a7ccf9c0ebd7c6fcbce600b4c00b52b2fdcf/src/ReplaceReferencesCapableTrait.php#L35-L59
train
carno-php/http
src/Client/Responding.php
Responding.data
public function data() : string { $code = $this->response->getStatusCode(); if ($code >= 400 && $code < 600) { throw new ErrorResponseException($this->response->getReasonPhrase(), $code); } return $this->payload(); }
php
public function data() : string { $code = $this->response->getStatusCode(); if ($code >= 400 && $code < 600) { throw new ErrorResponseException($this->response->getReasonPhrase(), $code); } return $this->payload(); }
[ "public", "function", "data", "(", ")", ":", "string", "{", "$", "code", "=", "$", "this", "->", "response", "->", "getStatusCode", "(", ")", ";", "if", "(", "$", "code", ">=", "400", "&&", "$", "code", "<", "600", ")", "{", "throw", "new", "ErrorResponseException", "(", "$", "this", "->", "response", "->", "getReasonPhrase", "(", ")", ",", "$", "code", ")", ";", "}", "return", "$", "this", "->", "payload", "(", ")", ";", "}" ]
parsed data with status checking @return string @throws ErrorResponseException
[ "parsed", "data", "with", "status", "checking" ]
0a873d1feb9ae6ec50e84e03f2075ac87997aa44
https://github.com/carno-php/http/blob/0a873d1feb9ae6ec50e84e03f2075ac87997aa44/src/Client/Responding.php#L69-L78
train
arrounded/core
src/ParameterBag.php
ParameterBag.only
public function only($keys) { $keys = is_array($keys) ? $keys : func_get_args(); return array_only($this->parameters, $keys); }
php
public function only($keys) { $keys = is_array($keys) ? $keys : func_get_args(); return array_only($this->parameters, $keys); }
[ "public", "function", "only", "(", "$", "keys", ")", "{", "$", "keys", "=", "is_array", "(", "$", "keys", ")", "?", "$", "keys", ":", "func_get_args", "(", ")", ";", "return", "array_only", "(", "$", "this", "->", "parameters", ",", "$", "keys", ")", ";", "}" ]
Get only certain attributes. @param string[]|string $keys,... @return array
[ "Get", "only", "certain", "attributes", "." ]
9573d9ae63f5173bdfd51077ce065e9e8c176ac4
https://github.com/arrounded/core/blob/9573d9ae63f5173bdfd51077ce065e9e8c176ac4/src/ParameterBag.php#L23-L28
train
dms-org/common.structure
src/Colour/ColourStringParser.php
ColourStringParser.parseRgbString
public static function parseRgbString(string $string) : array { if (!preg_match(self::REGEX_RGB, $string, $matches)) { throw InvalidArgumentException::format( 'Invalid rgb string passed to %s: expecting format "rgb(0-255, 0-255, 0-255)", "%s" given', __METHOD__, $string ); } return [(int)$matches[1], (int)$matches[2], (int)$matches[3]]; }
php
public static function parseRgbString(string $string) : array { if (!preg_match(self::REGEX_RGB, $string, $matches)) { throw InvalidArgumentException::format( 'Invalid rgb string passed to %s: expecting format "rgb(0-255, 0-255, 0-255)", "%s" given', __METHOD__, $string ); } return [(int)$matches[1], (int)$matches[2], (int)$matches[3]]; }
[ "public", "static", "function", "parseRgbString", "(", "string", "$", "string", ")", ":", "array", "{", "if", "(", "!", "preg_match", "(", "self", "::", "REGEX_RGB", ",", "$", "string", ",", "$", "matches", ")", ")", "{", "throw", "InvalidArgumentException", "::", "format", "(", "'Invalid rgb string passed to %s: expecting format \"rgb(0-255, 0-255, 0-255)\", \"%s\" given'", ",", "__METHOD__", ",", "$", "string", ")", ";", "}", "return", "[", "(", "int", ")", "$", "matches", "[", "1", "]", ",", "(", "int", ")", "$", "matches", "[", "2", "]", ",", "(", "int", ")", "$", "matches", "[", "3", "]", "]", ";", "}" ]
Parses the supplied rgb string into an array of channels. @param string $string eg: "rgb(100, 100, 100)" @return int[] eg: [100, 100, 100] @throws InvalidArgumentException
[ "Parses", "the", "supplied", "rgb", "string", "into", "an", "array", "of", "channels", "." ]
23f122182f60df5ec847047a81a39c8aab019ff1
https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/Colour/ColourStringParser.php#L26-L36
train
dms-org/common.structure
src/Colour/ColourStringParser.php
ColourStringParser.parseHexString
public static function parseHexString(string $string) : array { if (!preg_match(self::REGEX_HEX, $string, $matches)) { throw InvalidArgumentException::format( 'Invalid rgba string passed to %s: expecting format "#...", "%s" given', __METHOD__, $string ); } $string = str_replace('#', '', $string); if (strlen($string) === 3) { $r = hexdec($string[0] . $string[0]); $g = hexdec($string[1] . $string[1]); $b = hexdec($string[2] . $string[2]); } else { $r = hexdec($string[0] . $string[1]); $g = hexdec($string[2] . $string[3]); $b = hexdec($string[4] . $string[5]); } return [(int)$r, (int)$g, (int)$b]; }
php
public static function parseHexString(string $string) : array { if (!preg_match(self::REGEX_HEX, $string, $matches)) { throw InvalidArgumentException::format( 'Invalid rgba string passed to %s: expecting format "#...", "%s" given', __METHOD__, $string ); } $string = str_replace('#', '', $string); if (strlen($string) === 3) { $r = hexdec($string[0] . $string[0]); $g = hexdec($string[1] . $string[1]); $b = hexdec($string[2] . $string[2]); } else { $r = hexdec($string[0] . $string[1]); $g = hexdec($string[2] . $string[3]); $b = hexdec($string[4] . $string[5]); } return [(int)$r, (int)$g, (int)$b]; }
[ "public", "static", "function", "parseHexString", "(", "string", "$", "string", ")", ":", "array", "{", "if", "(", "!", "preg_match", "(", "self", "::", "REGEX_HEX", ",", "$", "string", ",", "$", "matches", ")", ")", "{", "throw", "InvalidArgumentException", "::", "format", "(", "'Invalid rgba string passed to %s: expecting format \"#...\", \"%s\" given'", ",", "__METHOD__", ",", "$", "string", ")", ";", "}", "$", "string", "=", "str_replace", "(", "'#'", ",", "''", ",", "$", "string", ")", ";", "if", "(", "strlen", "(", "$", "string", ")", "===", "3", ")", "{", "$", "r", "=", "hexdec", "(", "$", "string", "[", "0", "]", ".", "$", "string", "[", "0", "]", ")", ";", "$", "g", "=", "hexdec", "(", "$", "string", "[", "1", "]", ".", "$", "string", "[", "1", "]", ")", ";", "$", "b", "=", "hexdec", "(", "$", "string", "[", "2", "]", ".", "$", "string", "[", "2", "]", ")", ";", "}", "else", "{", "$", "r", "=", "hexdec", "(", "$", "string", "[", "0", "]", ".", "$", "string", "[", "1", "]", ")", ";", "$", "g", "=", "hexdec", "(", "$", "string", "[", "2", "]", ".", "$", "string", "[", "3", "]", ")", ";", "$", "b", "=", "hexdec", "(", "$", "string", "[", "4", "]", ".", "$", "string", "[", "5", "]", ")", ";", "}", "return", "[", "(", "int", ")", "$", "r", ",", "(", "int", ")", "$", "g", ",", "(", "int", ")", "$", "b", "]", ";", "}" ]
Parses the supplied hex string into an array of channels. @param string $string @return \int[] eg: [100, 100, 100] @throws InvalidArgumentException
[ "Parses", "the", "supplied", "hex", "string", "into", "an", "array", "of", "channels", "." ]
23f122182f60df5ec847047a81a39c8aab019ff1
https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/Colour/ColourStringParser.php#L46-L68
train
dms-org/common.structure
src/Colour/ColourStringParser.php
ColourStringParser.parseRgbaString
public static function parseRgbaString(string $string) : array { if (!preg_match(self::REGEX_RGBA, $string, $matches)) { throw InvalidArgumentException::format( 'Invalid rgba string passed to %s: expecting format "rgb(0-255, 0-255, 0-255, 0-1)", "%s" given', __METHOD__, $string ); } return [(int)$matches[1], (int)$matches[2], (int)$matches[3], (float)$matches[4]]; }
php
public static function parseRgbaString(string $string) : array { if (!preg_match(self::REGEX_RGBA, $string, $matches)) { throw InvalidArgumentException::format( 'Invalid rgba string passed to %s: expecting format "rgb(0-255, 0-255, 0-255, 0-1)", "%s" given', __METHOD__, $string ); } return [(int)$matches[1], (int)$matches[2], (int)$matches[3], (float)$matches[4]]; }
[ "public", "static", "function", "parseRgbaString", "(", "string", "$", "string", ")", ":", "array", "{", "if", "(", "!", "preg_match", "(", "self", "::", "REGEX_RGBA", ",", "$", "string", ",", "$", "matches", ")", ")", "{", "throw", "InvalidArgumentException", "::", "format", "(", "'Invalid rgba string passed to %s: expecting format \"rgb(0-255, 0-255, 0-255, 0-1)\", \"%s\" given'", ",", "__METHOD__", ",", "$", "string", ")", ";", "}", "return", "[", "(", "int", ")", "$", "matches", "[", "1", "]", ",", "(", "int", ")", "$", "matches", "[", "2", "]", ",", "(", "int", ")", "$", "matches", "[", "3", "]", ",", "(", "float", ")", "$", "matches", "[", "4", "]", "]", ";", "}" ]
Parses the supplied rgba string into an array of channels. @param string $string eg: "rgba(100, 100, 100, 0.5)" @return int[] eg: [100, 100, 100, 0.5] @throws InvalidArgumentException
[ "Parses", "the", "supplied", "rgba", "string", "into", "an", "array", "of", "channels", "." ]
23f122182f60df5ec847047a81a39c8aab019ff1
https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/Colour/ColourStringParser.php#L78-L88
train
eventerza/module-core
src/App.php
App.loadModules
private function loadModules() { /** @var ModuleRepository $repo */ $repo = $this->getContainer()->get('module_repository'); /** @var Module $module */ foreach ($repo->getAll() as $module) { $moduleClass = $module->getClass(); new $moduleClass($this); } }
php
private function loadModules() { /** @var ModuleRepository $repo */ $repo = $this->getContainer()->get('module_repository'); /** @var Module $module */ foreach ($repo->getAll() as $module) { $moduleClass = $module->getClass(); new $moduleClass($this); } }
[ "private", "function", "loadModules", "(", ")", "{", "/** @var ModuleRepository $repo */", "$", "repo", "=", "$", "this", "->", "getContainer", "(", ")", "->", "get", "(", "'module_repository'", ")", ";", "/** @var Module $module */", "foreach", "(", "$", "repo", "->", "getAll", "(", ")", "as", "$", "module", ")", "{", "$", "moduleClass", "=", "$", "module", "->", "getClass", "(", ")", ";", "new", "$", "moduleClass", "(", "$", "this", ")", ";", "}", "}" ]
add modules to App
[ "add", "modules", "to", "App" ]
9be33859d352c2943991e5fa0eeaed92585da22f
https://github.com/eventerza/module-core/blob/9be33859d352c2943991e5fa0eeaed92585da22f/src/App.php#L56-L66
train
eventerza/module-core
src/App.php
App.configureDI
private function configureDI() { /** @var \DI\Container $container */ $container = $this->getContainer(); $this->add(new NotificationMiddleware($container)); $this->add(new OldInputDataMiddleware($container)); // Random Number Generator $container->set(Generator::class, function () { $randomNumberGeneratorFactory = new RandomNumberGeneratorFactory; $randomNumberGenerator = $randomNumberGeneratorFactory ->getGenerator(new RandomNumberStrength(RandomNumberStrength::MEDIUM)); return $randomNumberGenerator; }); $container->set(TokenGenerator::class, \DI\object()->constructor(\DI\get(Generator::class))); $container->set('logger', function ($c) { $logger = new Logger('eventerza'); $logSettings = $c->get('settings.log'); $logLevel = $logSettings['level']; $isSlackEnabled = $logSettings['enableSlack']; $fileHandler = new StreamHandler("../var/logs/app.log", $logLevel); $logger->pushHandler($fileHandler); if ($isSlackEnabled) { $slackHandler = new SlackWebhookHandler( $logSettings['slackWebhookUrl'], 'prod-alerts', 'CriticalLog', true, null, false, true, Logger::CRITICAL, true, array() ); $logger->pushHandler($slackHandler); } return $logger; }); }
php
private function configureDI() { /** @var \DI\Container $container */ $container = $this->getContainer(); $this->add(new NotificationMiddleware($container)); $this->add(new OldInputDataMiddleware($container)); // Random Number Generator $container->set(Generator::class, function () { $randomNumberGeneratorFactory = new RandomNumberGeneratorFactory; $randomNumberGenerator = $randomNumberGeneratorFactory ->getGenerator(new RandomNumberStrength(RandomNumberStrength::MEDIUM)); return $randomNumberGenerator; }); $container->set(TokenGenerator::class, \DI\object()->constructor(\DI\get(Generator::class))); $container->set('logger', function ($c) { $logger = new Logger('eventerza'); $logSettings = $c->get('settings.log'); $logLevel = $logSettings['level']; $isSlackEnabled = $logSettings['enableSlack']; $fileHandler = new StreamHandler("../var/logs/app.log", $logLevel); $logger->pushHandler($fileHandler); if ($isSlackEnabled) { $slackHandler = new SlackWebhookHandler( $logSettings['slackWebhookUrl'], 'prod-alerts', 'CriticalLog', true, null, false, true, Logger::CRITICAL, true, array() ); $logger->pushHandler($slackHandler); } return $logger; }); }
[ "private", "function", "configureDI", "(", ")", "{", "/** @var \\DI\\Container $container */", "$", "container", "=", "$", "this", "->", "getContainer", "(", ")", ";", "$", "this", "->", "add", "(", "new", "NotificationMiddleware", "(", "$", "container", ")", ")", ";", "$", "this", "->", "add", "(", "new", "OldInputDataMiddleware", "(", "$", "container", ")", ")", ";", "// Random Number Generator", "$", "container", "->", "set", "(", "Generator", "::", "class", ",", "function", "(", ")", "{", "$", "randomNumberGeneratorFactory", "=", "new", "RandomNumberGeneratorFactory", ";", "$", "randomNumberGenerator", "=", "$", "randomNumberGeneratorFactory", "->", "getGenerator", "(", "new", "RandomNumberStrength", "(", "RandomNumberStrength", "::", "MEDIUM", ")", ")", ";", "return", "$", "randomNumberGenerator", ";", "}", ")", ";", "$", "container", "->", "set", "(", "TokenGenerator", "::", "class", ",", "\\", "DI", "\\", "object", "(", ")", "->", "constructor", "(", "\\", "DI", "\\", "get", "(", "Generator", "::", "class", ")", ")", ")", ";", "$", "container", "->", "set", "(", "'logger'", ",", "function", "(", "$", "c", ")", "{", "$", "logger", "=", "new", "Logger", "(", "'eventerza'", ")", ";", "$", "logSettings", "=", "$", "c", "->", "get", "(", "'settings.log'", ")", ";", "$", "logLevel", "=", "$", "logSettings", "[", "'level'", "]", ";", "$", "isSlackEnabled", "=", "$", "logSettings", "[", "'enableSlack'", "]", ";", "$", "fileHandler", "=", "new", "StreamHandler", "(", "\"../var/logs/app.log\"", ",", "$", "logLevel", ")", ";", "$", "logger", "->", "pushHandler", "(", "$", "fileHandler", ")", ";", "if", "(", "$", "isSlackEnabled", ")", "{", "$", "slackHandler", "=", "new", "SlackWebhookHandler", "(", "$", "logSettings", "[", "'slackWebhookUrl'", "]", ",", "'prod-alerts'", ",", "'CriticalLog'", ",", "true", ",", "null", ",", "false", ",", "true", ",", "Logger", "::", "CRITICAL", ",", "true", ",", "array", "(", ")", ")", ";", "$", "logger", "->", "pushHandler", "(", "$", "slackHandler", ")", ";", "}", "return", "$", "logger", ";", "}", ")", ";", "}" ]
Configure the dependency injection container
[ "Configure", "the", "dependency", "injection", "container" ]
9be33859d352c2943991e5fa0eeaed92585da22f
https://github.com/eventerza/module-core/blob/9be33859d352c2943991e5fa0eeaed92585da22f/src/App.php#L71-L116
train
ZFrapid/zfrapid-library
src/View/LayoutListener.php
LayoutListener.renderLayoutSegments
public function renderLayoutSegments(MvcEvent $e) { /* @var $viewModel ViewModel */ $viewModel = $e->getViewModel(); // skip if current ViewModel is of expected type if ('Zend\View\Model\ViewModel' != get_class($viewModel)) { return; } /** @var AggregateResolver $resolver */ $resolver = $e->getApplication()->getServiceManager()->get( 'ViewResolver' ); // loop through layout segments foreach ($this->layoutSegments as $segment) { // skip if layout segment does not exist if (!$resolver->resolve('layout/' . $segment)) { continue; } // add an additional header segment to layout $header = new ViewModel(); $header->setTemplate('layout/' . $segment); $viewModel->addChild($header, $segment); } }
php
public function renderLayoutSegments(MvcEvent $e) { /* @var $viewModel ViewModel */ $viewModel = $e->getViewModel(); // skip if current ViewModel is of expected type if ('Zend\View\Model\ViewModel' != get_class($viewModel)) { return; } /** @var AggregateResolver $resolver */ $resolver = $e->getApplication()->getServiceManager()->get( 'ViewResolver' ); // loop through layout segments foreach ($this->layoutSegments as $segment) { // skip if layout segment does not exist if (!$resolver->resolve('layout/' . $segment)) { continue; } // add an additional header segment to layout $header = new ViewModel(); $header->setTemplate('layout/' . $segment); $viewModel->addChild($header, $segment); } }
[ "public", "function", "renderLayoutSegments", "(", "MvcEvent", "$", "e", ")", "{", "/* @var $viewModel ViewModel */", "$", "viewModel", "=", "$", "e", "->", "getViewModel", "(", ")", ";", "// skip if current ViewModel is of expected type", "if", "(", "'Zend\\View\\Model\\ViewModel'", "!=", "get_class", "(", "$", "viewModel", ")", ")", "{", "return", ";", "}", "/** @var AggregateResolver $resolver */", "$", "resolver", "=", "$", "e", "->", "getApplication", "(", ")", "->", "getServiceManager", "(", ")", "->", "get", "(", "'ViewResolver'", ")", ";", "// loop through layout segments", "foreach", "(", "$", "this", "->", "layoutSegments", "as", "$", "segment", ")", "{", "// skip if layout segment does not exist", "if", "(", "!", "$", "resolver", "->", "resolve", "(", "'layout/'", ".", "$", "segment", ")", ")", "{", "continue", ";", "}", "// add an additional header segment to layout", "$", "header", "=", "new", "ViewModel", "(", ")", ";", "$", "header", "->", "setTemplate", "(", "'layout/'", ".", "$", "segment", ")", ";", "$", "viewModel", "->", "addChild", "(", "$", "header", ",", "$", "segment", ")", ";", "}", "}" ]
Listen to the "render" event and render additional layout segments @param MvcEvent $e @return null
[ "Listen", "to", "the", "render", "event", "and", "render", "additional", "layout", "segments" ]
3eca4f465dd1f2dee889532892c5052e830bc03c
https://github.com/ZFrapid/zfrapid-library/blob/3eca4f465dd1f2dee889532892c5052e830bc03c/src/View/LayoutListener.php#L62-L90
train
anime-db/ani-db-filler-bundle
src/Controller/MediaController.php
MediaController.coverAction
public function coverAction($id, Request $request) { $body = $this->getAnime($id); /* @var $response Response */ $response = $this->get('cache_time_keeper')->getResponse([], self::CACHE_LIFETIME) ->setEtag(sha1($body->html())); $response->headers->set('Content-Type', 'image/jpeg'); // response was not modified for this request if ($response->isNotModified($request)) { return $response; } if ($image = $body->filter('picture')->text()) { $image = $this->get('anime_db.ani_db.browser')->getImageUrl($image); $image_response = (new Client())->get($image)->send(); if (!$image_response->isSuccessful()) { throw new \RuntimeException('Failed download image from anidb.net'); } $response->setContent($image_response->getBody(true)); } else { throw $this->createNotFoundException('Cover not found'); } return $response; }
php
public function coverAction($id, Request $request) { $body = $this->getAnime($id); /* @var $response Response */ $response = $this->get('cache_time_keeper')->getResponse([], self::CACHE_LIFETIME) ->setEtag(sha1($body->html())); $response->headers->set('Content-Type', 'image/jpeg'); // response was not modified for this request if ($response->isNotModified($request)) { return $response; } if ($image = $body->filter('picture')->text()) { $image = $this->get('anime_db.ani_db.browser')->getImageUrl($image); $image_response = (new Client())->get($image)->send(); if (!$image_response->isSuccessful()) { throw new \RuntimeException('Failed download image from anidb.net'); } $response->setContent($image_response->getBody(true)); } else { throw $this->createNotFoundException('Cover not found'); } return $response; }
[ "public", "function", "coverAction", "(", "$", "id", ",", "Request", "$", "request", ")", "{", "$", "body", "=", "$", "this", "->", "getAnime", "(", "$", "id", ")", ";", "/* @var $response Response */", "$", "response", "=", "$", "this", "->", "get", "(", "'cache_time_keeper'", ")", "->", "getResponse", "(", "[", "]", ",", "self", "::", "CACHE_LIFETIME", ")", "->", "setEtag", "(", "sha1", "(", "$", "body", "->", "html", "(", ")", ")", ")", ";", "$", "response", "->", "headers", "->", "set", "(", "'Content-Type'", ",", "'image/jpeg'", ")", ";", "// response was not modified for this request", "if", "(", "$", "response", "->", "isNotModified", "(", "$", "request", ")", ")", "{", "return", "$", "response", ";", "}", "if", "(", "$", "image", "=", "$", "body", "->", "filter", "(", "'picture'", ")", "->", "text", "(", ")", ")", "{", "$", "image", "=", "$", "this", "->", "get", "(", "'anime_db.ani_db.browser'", ")", "->", "getImageUrl", "(", "$", "image", ")", ";", "$", "image_response", "=", "(", "new", "Client", "(", ")", ")", "->", "get", "(", "$", "image", ")", "->", "send", "(", ")", ";", "if", "(", "!", "$", "image_response", "->", "isSuccessful", "(", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Failed download image from anidb.net'", ")", ";", "}", "$", "response", "->", "setContent", "(", "$", "image_response", "->", "getBody", "(", "true", ")", ")", ";", "}", "else", "{", "throw", "$", "this", "->", "createNotFoundException", "(", "'Cover not found'", ")", ";", "}", "return", "$", "response", ";", "}" ]
Get cover from anidb.net item id. @param string $id @param Request $request @return Response
[ "Get", "cover", "from", "anidb", ".", "net", "item", "id", "." ]
7581beda0cd46b11867a703ca429147f0c5b5b46
https://github.com/anime-db/ani-db-filler-bundle/blob/7581beda0cd46b11867a703ca429147f0c5b5b46/src/Controller/MediaController.php#L32-L57
train
agentmedia/phine-core
src/Core/Logic/Tree/AreaListProvider.php
AreaListProvider.TopMost
public function TopMost() { $sql = Access::SqlBuilder(); $tblArea = Area::Schema()->Table(); $where = $sql->Equals($tblArea->Field('Layout'), $sql->Value($this->layout->GetID())) ->And_($sql->IsNull($tblArea->Field('Previous'))); return Area::Schema()->First($where); }
php
public function TopMost() { $sql = Access::SqlBuilder(); $tblArea = Area::Schema()->Table(); $where = $sql->Equals($tblArea->Field('Layout'), $sql->Value($this->layout->GetID())) ->And_($sql->IsNull($tblArea->Field('Previous'))); return Area::Schema()->First($where); }
[ "public", "function", "TopMost", "(", ")", "{", "$", "sql", "=", "Access", "::", "SqlBuilder", "(", ")", ";", "$", "tblArea", "=", "Area", "::", "Schema", "(", ")", "->", "Table", "(", ")", ";", "$", "where", "=", "$", "sql", "->", "Equals", "(", "$", "tblArea", "->", "Field", "(", "'Layout'", ")", ",", "$", "sql", "->", "Value", "(", "$", "this", "->", "layout", "->", "GetID", "(", ")", ")", ")", "->", "And_", "(", "$", "sql", "->", "IsNull", "(", "$", "tblArea", "->", "Field", "(", "'Previous'", ")", ")", ")", ";", "return", "Area", "::", "Schema", "(", ")", "->", "First", "(", "$", "where", ")", ";", "}" ]
Returns the top most area @return Area
[ "Returns", "the", "top", "most", "area" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Tree/AreaListProvider.php#L68-L76
train
Wedeto/Util
src/Cache/Cache.php
Cache.set
public function set($key, $val) { parent::set(func_get_args(), null); $this->values['_changed'] = true; return $this; }
php
public function set($key, $val) { parent::set(func_get_args(), null); $this->values['_changed'] = true; return $this; }
[ "public", "function", "set", "(", "$", "key", ",", "$", "val", ")", "{", "parent", "::", "set", "(", "func_get_args", "(", ")", ",", "null", ")", ";", "$", "this", "->", "values", "[", "'_changed'", "]", "=", "true", ";", "return", "$", "this", ";", "}" ]
Set a value in the cache @param $key scalar The key under which to store. Can be repeated to go deeper. @param $val mixed The value to store. Should be PHP-serializable. If this is null, the entry will be removed from the cache @return Cache Provides fluent interface
[ "Set", "a", "value", "in", "the", "cache" ]
0e080251bbaa8e7d91ae8d02eb79c029c976744a
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/Cache/Cache.php#L81-L86
train
Wedeto/Util
src/Cache/Cache.php
Cache.clear
public function clear() { $expiry = $this->values['_expiry'] ?? null; parent::clear(); $this->set('_changed', true); $this->set('_timestamp', time()); if ($expiry) $this->setExpiry($expiry); return $this; }
php
public function clear() { $expiry = $this->values['_expiry'] ?? null; parent::clear(); $this->set('_changed', true); $this->set('_timestamp', time()); if ($expiry) $this->setExpiry($expiry); return $this; }
[ "public", "function", "clear", "(", ")", "{", "$", "expiry", "=", "$", "this", "->", "values", "[", "'_expiry'", "]", "??", "null", ";", "parent", "::", "clear", "(", ")", ";", "$", "this", "->", "set", "(", "'_changed'", ",", "true", ")", ";", "$", "this", "->", "set", "(", "'_timestamp'", ",", "time", "(", ")", ")", ";", "if", "(", "$", "expiry", ")", "$", "this", "->", "setExpiry", "(", "$", "expiry", ")", ";", "return", "$", "this", ";", "}" ]
Remove all contents from the cache @return Cache Provides fluent interface
[ "Remove", "all", "contents", "from", "the", "cache" ]
0e080251bbaa8e7d91ae8d02eb79c029c976744a
https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/Cache/Cache.php#L118-L127
train
Wedeto/DB
src/Query/OffsetClause.php
OffsetClause.toSQL
public function toSQL(Parameters $params, bool $inner_clause) { return "OFFSET " . $params->getDriver()->toSQL($params, $this->getOffset()); }
php
public function toSQL(Parameters $params, bool $inner_clause) { return "OFFSET " . $params->getDriver()->toSQL($params, $this->getOffset()); }
[ "public", "function", "toSQL", "(", "Parameters", "$", "params", ",", "bool", "$", "inner_clause", ")", "{", "return", "\"OFFSET \"", ".", "$", "params", "->", "getDriver", "(", ")", "->", "toSQL", "(", "$", "params", ",", "$", "this", "->", "getOffset", "(", ")", ")", ";", "}" ]
Write a OFFSET clause to SQL query syntax @param Parameters $params The query parameters: tables and placeholder values @return string The generated SQL
[ "Write", "a", "OFFSET", "clause", "to", "SQL", "query", "syntax" ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/Query/OffsetClause.php#L59-L62
train
bandama-framework/bandama-framework
src/App.php
App.getInstance
public static function getInstance($configFile = null, $mode = self::APP_MODE_PROD) { $c = get_called_class(); if (!isset(self::$_instances[$c])) { // Create an instance self::$_instances[$c] = new $c($configFile, $mode); // Setup application self::$_instances[$c]->setup(); } return self::$_instances[$c]; }
php
public static function getInstance($configFile = null, $mode = self::APP_MODE_PROD) { $c = get_called_class(); if (!isset(self::$_instances[$c])) { // Create an instance self::$_instances[$c] = new $c($configFile, $mode); // Setup application self::$_instances[$c]->setup(); } return self::$_instances[$c]; }
[ "public", "static", "function", "getInstance", "(", "$", "configFile", "=", "null", ",", "$", "mode", "=", "self", "::", "APP_MODE_PROD", ")", "{", "$", "c", "=", "get_called_class", "(", ")", ";", "if", "(", "!", "isset", "(", "self", "::", "$", "_instances", "[", "$", "c", "]", ")", ")", "{", "// Create an instance", "self", "::", "$", "_instances", "[", "$", "c", "]", "=", "new", "$", "c", "(", "$", "configFile", ",", "$", "mode", ")", ";", "// Setup application", "self", "::", "$", "_instances", "[", "$", "c", "]", "->", "setup", "(", ")", ";", "}", "return", "self", "::", "$", "_instances", "[", "$", "c", "]", ";", "}" ]
Initialize and return App uniq instance @param array $configFile Application configuration file @return App
[ "Initialize", "and", "return", "App", "uniq", "instance" ]
234ed703baf9e31268941c9d5f6d5e004cc53066
https://github.com/bandama-framework/bandama-framework/blob/234ed703baf9e31268941c9d5f6d5e004cc53066/src/App.php#L119-L129
train
bandama-framework/bandama-framework
src/App.php
App.run
public function run() { // Start session $session = $this->get('session'); $session->start(); // Route the request $uri = ''; if (strcmp($this->mode, self::APP_MODE_DEV) == 0) { $uri = $_SERVER['REQUEST_URI']; } else { $uri = $_GET['url']; } // $baseUri not empty and $uri starts with $baseUri if (!empty($this->baseUri) && substr($uri, 0, strlen($this->baseUri)) === $this->baseUri) { // Extract $uri without $baseUri $uri = substr($uri, strlen($this->baseUri)); } $this->get('router')->route($uri); }
php
public function run() { // Start session $session = $this->get('session'); $session->start(); // Route the request $uri = ''; if (strcmp($this->mode, self::APP_MODE_DEV) == 0) { $uri = $_SERVER['REQUEST_URI']; } else { $uri = $_GET['url']; } // $baseUri not empty and $uri starts with $baseUri if (!empty($this->baseUri) && substr($uri, 0, strlen($this->baseUri)) === $this->baseUri) { // Extract $uri without $baseUri $uri = substr($uri, strlen($this->baseUri)); } $this->get('router')->route($uri); }
[ "public", "function", "run", "(", ")", "{", "// Start session", "$", "session", "=", "$", "this", "->", "get", "(", "'session'", ")", ";", "$", "session", "->", "start", "(", ")", ";", "// Route the request", "$", "uri", "=", "''", ";", "if", "(", "strcmp", "(", "$", "this", "->", "mode", ",", "self", "::", "APP_MODE_DEV", ")", "==", "0", ")", "{", "$", "uri", "=", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ";", "}", "else", "{", "$", "uri", "=", "$", "_GET", "[", "'url'", "]", ";", "}", "// $baseUri not empty and $uri starts with $baseUri", "if", "(", "!", "empty", "(", "$", "this", "->", "baseUri", ")", "&&", "substr", "(", "$", "uri", ",", "0", ",", "strlen", "(", "$", "this", "->", "baseUri", ")", ")", "===", "$", "this", "->", "baseUri", ")", "{", "// Extract $uri without $baseUri", "$", "uri", "=", "substr", "(", "$", "uri", ",", "strlen", "(", "$", "this", "->", "baseUri", ")", ")", ";", "}", "$", "this", "->", "get", "(", "'router'", ")", "->", "route", "(", "$", "uri", ")", ";", "}" ]
Run Bandama application @return mixed
[ "Run", "Bandama", "application" ]
234ed703baf9e31268941c9d5f6d5e004cc53066
https://github.com/bandama-framework/bandama-framework/blob/234ed703baf9e31268941c9d5f6d5e004cc53066/src/App.php#L136-L156
train
bandama-framework/bandama-framework
src/App.php
App.addService
public function addService($key, $callable) { $instance = Container::newInstance($callable); $this->container->set($key, function() use ($instance) { return $instance; }); }
php
public function addService($key, $callable) { $instance = Container::newInstance($callable); $this->container->set($key, function() use ($instance) { return $instance; }); }
[ "public", "function", "addService", "(", "$", "key", ",", "$", "callable", ")", "{", "$", "instance", "=", "Container", "::", "newInstance", "(", "$", "callable", ")", ";", "$", "this", "->", "container", "->", "set", "(", "$", "key", ",", "function", "(", ")", "use", "(", "$", "instance", ")", "{", "return", "$", "instance", ";", "}", ")", ";", "}" ]
Add an instance of class in container with custom key @return void
[ "Add", "an", "instance", "of", "class", "in", "container", "with", "custom", "key" ]
234ed703baf9e31268941c9d5f6d5e004cc53066
https://github.com/bandama-framework/bandama-framework/blob/234ed703baf9e31268941c9d5f6d5e004cc53066/src/App.php#L174-L179
train
bandama-framework/bandama-framework
src/App.php
App.registerConfig
protected function registerConfig() { $config = new Configuration($this->configFile); $this->container->set('config', function() use ($config) { return $config; }); }
php
protected function registerConfig() { $config = new Configuration($this->configFile); $this->container->set('config', function() use ($config) { return $config; }); }
[ "protected", "function", "registerConfig", "(", ")", "{", "$", "config", "=", "new", "Configuration", "(", "$", "this", "->", "configFile", ")", ";", "$", "this", "->", "container", "->", "set", "(", "'config'", ",", "function", "(", ")", "use", "(", "$", "config", ")", "{", "return", "$", "config", ";", "}", ")", ";", "}" ]
Create and add config in container @return void
[ "Create", "and", "add", "config", "in", "container" ]
234ed703baf9e31268941c9d5f6d5e004cc53066
https://github.com/bandama-framework/bandama-framework/blob/234ed703baf9e31268941c9d5f6d5e004cc53066/src/App.php#L219-L224
train
bandama-framework/bandama-framework
src/App.php
App.registerFlash
protected function registerFlash() { $container = $this->container; $this->container->set('flash', function() use ($container) { return new Flash($container->get('session')); }); }
php
protected function registerFlash() { $container = $this->container; $this->container->set('flash', function() use ($container) { return new Flash($container->get('session')); }); }
[ "protected", "function", "registerFlash", "(", ")", "{", "$", "container", "=", "$", "this", "->", "container", ";", "$", "this", "->", "container", "->", "set", "(", "'flash'", ",", "function", "(", ")", "use", "(", "$", "container", ")", "{", "return", "new", "Flash", "(", "$", "container", "->", "get", "(", "'session'", ")", ")", ";", "}", ")", ";", "}" ]
Create and add session flash object to container @return void
[ "Create", "and", "add", "session", "flash", "object", "to", "container" ]
234ed703baf9e31268941c9d5f6d5e004cc53066
https://github.com/bandama-framework/bandama-framework/blob/234ed703baf9e31268941c9d5f6d5e004cc53066/src/App.php#L267-L272
train
erenmustafaozdal/laravel-modules-base
src/Services/PermissionService.php
PermissionService.setCounts
private function setCounts() { foreach($this->routes as $module) { $this->counts['module']++; foreach($module['routes'] as $route) { $this->counts['route']++; } } }
php
private function setCounts() { foreach($this->routes as $module) { $this->counts['module']++; foreach($module['routes'] as $route) { $this->counts['route']++; } } }
[ "private", "function", "setCounts", "(", ")", "{", "foreach", "(", "$", "this", "->", "routes", "as", "$", "module", ")", "{", "$", "this", "->", "counts", "[", "'module'", "]", "++", ";", "foreach", "(", "$", "module", "[", "'routes'", "]", "as", "$", "route", ")", "{", "$", "this", "->", "counts", "[", "'route'", "]", "++", ";", "}", "}", "}" ]
set module, part, route counts @return void
[ "set", "module", "part", "route", "counts" ]
c26600543817642926bcf16ada84009e00d784e0
https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Services/PermissionService.php#L74-L82
train
erenmustafaozdal/laravel-modules-base
src/Services/PermissionService.php
PermissionService.getMyModules
protected function getMyModules() { $all = array_keys( app()->getLoadedProviders() ); $modules = []; foreach($all as $provider) { $parts = explode('\\', $provider); if ($parts[0] === 'ErenMustafaOzdal' && array_search($parts[1],$modules) === false) { array_push($modules, snake_case($parts[1], '-')); } } return $modules; }
php
protected function getMyModules() { $all = array_keys( app()->getLoadedProviders() ); $modules = []; foreach($all as $provider) { $parts = explode('\\', $provider); if ($parts[0] === 'ErenMustafaOzdal' && array_search($parts[1],$modules) === false) { array_push($modules, snake_case($parts[1], '-')); } } return $modules; }
[ "protected", "function", "getMyModules", "(", ")", "{", "$", "all", "=", "array_keys", "(", "app", "(", ")", "->", "getLoadedProviders", "(", ")", ")", ";", "$", "modules", "=", "[", "]", ";", "foreach", "(", "$", "all", "as", "$", "provider", ")", "{", "$", "parts", "=", "explode", "(", "'\\\\'", ",", "$", "provider", ")", ";", "if", "(", "$", "parts", "[", "0", "]", "===", "'ErenMustafaOzdal'", "&&", "array_search", "(", "$", "parts", "[", "1", "]", ",", "$", "modules", ")", "===", "false", ")", "{", "array_push", "(", "$", "modules", ",", "snake_case", "(", "$", "parts", "[", "1", "]", ",", "'-'", ")", ")", ";", "}", "}", "return", "$", "modules", ";", "}" ]
get ErenMustafaOzdal namespace provider @return array
[ "get", "ErenMustafaOzdal", "namespace", "provider" ]
c26600543817642926bcf16ada84009e00d784e0
https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Services/PermissionService.php#L89-L100
train
selamiphp/views
src/ExtensionsAbstract.php
ExtensionsAbstract.loadFunctions
protected function loadFunctions() : void { $this->extendForTranslator(); $this->extendForWidget(); $this->extendForSiteUrl(); $this->extendForGetUrl(); $this->extendForQueryParams(); $this->extendForPagination(); $this->extendForVarDump(); }
php
protected function loadFunctions() : void { $this->extendForTranslator(); $this->extendForWidget(); $this->extendForSiteUrl(); $this->extendForGetUrl(); $this->extendForQueryParams(); $this->extendForPagination(); $this->extendForVarDump(); }
[ "protected", "function", "loadFunctions", "(", ")", ":", "void", "{", "$", "this", "->", "extendForTranslator", "(", ")", ";", "$", "this", "->", "extendForWidget", "(", ")", ";", "$", "this", "->", "extendForSiteUrl", "(", ")", ";", "$", "this", "->", "extendForGetUrl", "(", ")", ";", "$", "this", "->", "extendForQueryParams", "(", ")", ";", "$", "this", "->", "extendForPagination", "(", ")", ";", "$", "this", "->", "extendForVarDump", "(", ")", ";", "}" ]
Load functions that will be used in the templates
[ "Load", "functions", "that", "will", "be", "used", "in", "the", "templates" ]
94081fc3093b160988e228d6ce63736d21c9f175
https://github.com/selamiphp/views/blob/94081fc3093b160988e228d6ce63736d21c9f175/src/ExtensionsAbstract.php#L17-L26
train
iron-bound-designs/IronBound-Cache
src/Cache.php
Cache.update
public static function update( Cacheable $object ) { return wp_cache_set( $object->get_pk(), $object->get_data_to_cache(), $object::get_cache_group() ); }
php
public static function update( Cacheable $object ) { return wp_cache_set( $object->get_pk(), $object->get_data_to_cache(), $object::get_cache_group() ); }
[ "public", "static", "function", "update", "(", "Cacheable", "$", "object", ")", "{", "return", "wp_cache_set", "(", "$", "object", "->", "get_pk", "(", ")", ",", "$", "object", "->", "get_data_to_cache", "(", ")", ",", "$", "object", "::", "get_cache_group", "(", ")", ")", ";", "}" ]
Update an item in the cache. @since 1.0 @param Cacheable $object @return bool
[ "Update", "an", "item", "in", "the", "cache", "." ]
6f706e7dd0d1cfa1a153dbd6de79e2db99fe0589
https://github.com/iron-bound-designs/IronBound-Cache/blob/6f706e7dd0d1cfa1a153dbd6de79e2db99fe0589/src/Cache.php#L43-L45
train
internetofvoice/vsms-core
src/Helper/LogHelper.php
LogHelper.logRequest
public function logRequest($request, $extra = [], $includeHeader = true) { $extra = count($extra) ? ' ' . json_encode($extra) : ''; // Caller info $trace = debug_backtrace(false, 2); if(isset($trace[1])) { $caller = substr(strrchr($trace[1]['class'], '\\'), 1) . '::' . $trace[1]['function']; $this->debug($request->getMethod() . ' ' . $caller . $extra); } // Parameters, if applicable $params = $request->getQueryParams(); if(!empty($params)) { $this->debug('Query params: ' . json_encode($params)); } // Request headers, if applicable if($includeHeader) { $headers = array_map(function($element) { return implode(', ', $element); }, $request->getHeaders()); $this->debug('Header: ' . json_encode($headers)); } // Request body, if applicable $body = $request->getParsedBody(); if(!is_null($body)) { if(is_array($body)) { // Apply logger mask to all nested elements $mask = array(); foreach($this->getMask() as $key) { array_push($mask, $key); } array_walk_recursive($body, function(&$value, $key) use ($mask) { if(in_array($key, $mask)) { $value = '***'; } }); } $this->debug('Body: ' . json_encode($body)); } }
php
public function logRequest($request, $extra = [], $includeHeader = true) { $extra = count($extra) ? ' ' . json_encode($extra) : ''; // Caller info $trace = debug_backtrace(false, 2); if(isset($trace[1])) { $caller = substr(strrchr($trace[1]['class'], '\\'), 1) . '::' . $trace[1]['function']; $this->debug($request->getMethod() . ' ' . $caller . $extra); } // Parameters, if applicable $params = $request->getQueryParams(); if(!empty($params)) { $this->debug('Query params: ' . json_encode($params)); } // Request headers, if applicable if($includeHeader) { $headers = array_map(function($element) { return implode(', ', $element); }, $request->getHeaders()); $this->debug('Header: ' . json_encode($headers)); } // Request body, if applicable $body = $request->getParsedBody(); if(!is_null($body)) { if(is_array($body)) { // Apply logger mask to all nested elements $mask = array(); foreach($this->getMask() as $key) { array_push($mask, $key); } array_walk_recursive($body, function(&$value, $key) use ($mask) { if(in_array($key, $mask)) { $value = '***'; } }); } $this->debug('Body: ' . json_encode($body)); } }
[ "public", "function", "logRequest", "(", "$", "request", ",", "$", "extra", "=", "[", "]", ",", "$", "includeHeader", "=", "true", ")", "{", "$", "extra", "=", "count", "(", "$", "extra", ")", "?", "' '", ".", "json_encode", "(", "$", "extra", ")", ":", "''", ";", "// Caller info", "$", "trace", "=", "debug_backtrace", "(", "false", ",", "2", ")", ";", "if", "(", "isset", "(", "$", "trace", "[", "1", "]", ")", ")", "{", "$", "caller", "=", "substr", "(", "strrchr", "(", "$", "trace", "[", "1", "]", "[", "'class'", "]", ",", "'\\\\'", ")", ",", "1", ")", ".", "'::'", ".", "$", "trace", "[", "1", "]", "[", "'function'", "]", ";", "$", "this", "->", "debug", "(", "$", "request", "->", "getMethod", "(", ")", ".", "' '", ".", "$", "caller", ".", "$", "extra", ")", ";", "}", "// Parameters, if applicable", "$", "params", "=", "$", "request", "->", "getQueryParams", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "params", ")", ")", "{", "$", "this", "->", "debug", "(", "'Query params: '", ".", "json_encode", "(", "$", "params", ")", ")", ";", "}", "// Request headers, if applicable", "if", "(", "$", "includeHeader", ")", "{", "$", "headers", "=", "array_map", "(", "function", "(", "$", "element", ")", "{", "return", "implode", "(", "', '", ",", "$", "element", ")", ";", "}", ",", "$", "request", "->", "getHeaders", "(", ")", ")", ";", "$", "this", "->", "debug", "(", "'Header: '", ".", "json_encode", "(", "$", "headers", ")", ")", ";", "}", "// Request body, if applicable", "$", "body", "=", "$", "request", "->", "getParsedBody", "(", ")", ";", "if", "(", "!", "is_null", "(", "$", "body", ")", ")", "{", "if", "(", "is_array", "(", "$", "body", ")", ")", "{", "// Apply logger mask to all nested elements", "$", "mask", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "getMask", "(", ")", "as", "$", "key", ")", "{", "array_push", "(", "$", "mask", ",", "$", "key", ")", ";", "}", "array_walk_recursive", "(", "$", "body", ",", "function", "(", "&", "$", "value", ",", "$", "key", ")", "use", "(", "$", "mask", ")", "{", "if", "(", "in_array", "(", "$", "key", ",", "$", "mask", ")", ")", "{", "$", "value", "=", "'***'", ";", "}", "}", ")", ";", "}", "$", "this", "->", "debug", "(", "'Body: '", ".", "json_encode", "(", "$", "body", ")", ")", ";", "}", "}" ]
Log server request @param \Slim\Http\Request $request Request object @param array $extra Additional log data @param bool $includeHeader Whether to include header data @access public @author [email protected]
[ "Log", "server", "request" ]
bd1eb6ca90a55f4928c35b9f0742a5cc922298ef
https://github.com/internetofvoice/vsms-core/blob/bd1eb6ca90a55f4928c35b9f0742a5cc922298ef/src/Helper/LogHelper.php#L48-L92
train
loevgaard/dandomain-foundation-entities
src/Entity/Price.php
Price.create
public static function create(int $amount, int $avance, string $b2bGroupId, CurrencyInterface $currency, int $specialOfferPrice, int $unitPrice): PriceInterface { $specialOfferPrice = new Money($specialOfferPrice, new \Money\Currency($currency->getIsoCodeAlpha())); $unitPrice = new Money($unitPrice, new \Money\Currency($currency->getIsoCodeAlpha())); $price = new self(); $price ->setAmount($amount) ->setAvance($avance) ->setB2bGroupId($b2bGroupId) ->setCurrency($currency) ->setSpecialOfferPrice($specialOfferPrice) ->setUnitPrice($unitPrice) ; return $price; }
php
public static function create(int $amount, int $avance, string $b2bGroupId, CurrencyInterface $currency, int $specialOfferPrice, int $unitPrice): PriceInterface { $specialOfferPrice = new Money($specialOfferPrice, new \Money\Currency($currency->getIsoCodeAlpha())); $unitPrice = new Money($unitPrice, new \Money\Currency($currency->getIsoCodeAlpha())); $price = new self(); $price ->setAmount($amount) ->setAvance($avance) ->setB2bGroupId($b2bGroupId) ->setCurrency($currency) ->setSpecialOfferPrice($specialOfferPrice) ->setUnitPrice($unitPrice) ; return $price; }
[ "public", "static", "function", "create", "(", "int", "$", "amount", ",", "int", "$", "avance", ",", "string", "$", "b2bGroupId", ",", "CurrencyInterface", "$", "currency", ",", "int", "$", "specialOfferPrice", ",", "int", "$", "unitPrice", ")", ":", "PriceInterface", "{", "$", "specialOfferPrice", "=", "new", "Money", "(", "$", "specialOfferPrice", ",", "new", "\\", "Money", "\\", "Currency", "(", "$", "currency", "->", "getIsoCodeAlpha", "(", ")", ")", ")", ";", "$", "unitPrice", "=", "new", "Money", "(", "$", "unitPrice", ",", "new", "\\", "Money", "\\", "Currency", "(", "$", "currency", "->", "getIsoCodeAlpha", "(", ")", ")", ")", ";", "$", "price", "=", "new", "self", "(", ")", ";", "$", "price", "->", "setAmount", "(", "$", "amount", ")", "->", "setAvance", "(", "$", "avance", ")", "->", "setB2bGroupId", "(", "$", "b2bGroupId", ")", "->", "setCurrency", "(", "$", "currency", ")", "->", "setSpecialOfferPrice", "(", "$", "specialOfferPrice", ")", "->", "setUnitPrice", "(", "$", "unitPrice", ")", ";", "return", "$", "price", ";", "}" ]
Creates a valid Price. @param int $amount @param int $avance @param string $b2bGroupId @param CurrencyInterface $currency @param int $specialOfferPrice In cents/ører (in danish) @param int $unitPrice In cents/ører (in danish) @return PriceInterface
[ "Creates", "a", "valid", "Price", "." ]
256f7aa8b40d2bd9488046c3c2b1e04e982d78ad
https://github.com/loevgaard/dandomain-foundation-entities/blob/256f7aa8b40d2bd9488046c3c2b1e04e982d78ad/src/Entity/Price.php#L112-L128
train
freialib/ran.tools
src/Form.php
Form.composite
function composite($label) { $args = func_get_args(); array_shift($args); # remove $label $composite = \ran\CompositeField::instance($this->confs); $composite->fieldlabel_is($label); if (count($args) >= 1) { if (is_array($args[0])) { $array_shorthand = array_shift($args); foreach ($array_shorthand as $key => $value) { if (is_int($key)) { // treat value as fieldname $composite->addfield($this->field(null, $value, 'text')); } else { # key is not an int // treat key as fieldname and value as fieldtype $composite->addfield($this->field(null, $key, $value)); } } } // add remaining HTMLFormFields foreach ($args as $field) { $composite->addfield($field); } } $composite ->form_is($this) ->fieldlabel_is($label) ->fieldtemplate_is($this->fieldtemplate('composite')) ->hintrenderer_is($this->hintrenderer('composite')) ->errorrenderer_is($this->errorrenderer('composite')); return $composite; }
php
function composite($label) { $args = func_get_args(); array_shift($args); # remove $label $composite = \ran\CompositeField::instance($this->confs); $composite->fieldlabel_is($label); if (count($args) >= 1) { if (is_array($args[0])) { $array_shorthand = array_shift($args); foreach ($array_shorthand as $key => $value) { if (is_int($key)) { // treat value as fieldname $composite->addfield($this->field(null, $value, 'text')); } else { # key is not an int // treat key as fieldname and value as fieldtype $composite->addfield($this->field(null, $key, $value)); } } } // add remaining HTMLFormFields foreach ($args as $field) { $composite->addfield($field); } } $composite ->form_is($this) ->fieldlabel_is($label) ->fieldtemplate_is($this->fieldtemplate('composite')) ->hintrenderer_is($this->hintrenderer('composite')) ->errorrenderer_is($this->errorrenderer('composite')); return $composite; }
[ "function", "composite", "(", "$", "label", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "array_shift", "(", "$", "args", ")", ";", "# remove $label", "$", "composite", "=", "\\", "ran", "\\", "CompositeField", "::", "instance", "(", "$", "this", "->", "confs", ")", ";", "$", "composite", "->", "fieldlabel_is", "(", "$", "label", ")", ";", "if", "(", "count", "(", "$", "args", ")", ">=", "1", ")", "{", "if", "(", "is_array", "(", "$", "args", "[", "0", "]", ")", ")", "{", "$", "array_shorthand", "=", "array_shift", "(", "$", "args", ")", ";", "foreach", "(", "$", "array_shorthand", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_int", "(", "$", "key", ")", ")", "{", "// treat value as fieldname", "$", "composite", "->", "addfield", "(", "$", "this", "->", "field", "(", "null", ",", "$", "value", ",", "'text'", ")", ")", ";", "}", "else", "{", "# key is not an int", "// treat key as fieldname and value as fieldtype", "$", "composite", "->", "addfield", "(", "$", "this", "->", "field", "(", "null", ",", "$", "key", ",", "$", "value", ")", ")", ";", "}", "}", "}", "// add remaining HTMLFormFields", "foreach", "(", "$", "args", "as", "$", "field", ")", "{", "$", "composite", "->", "addfield", "(", "$", "field", ")", ";", "}", "}", "$", "composite", "->", "form_is", "(", "$", "this", ")", "->", "fieldlabel_is", "(", "$", "label", ")", "->", "fieldtemplate_is", "(", "$", "this", "->", "fieldtemplate", "(", "'composite'", ")", ")", "->", "hintrenderer_is", "(", "$", "this", "->", "hintrenderer", "(", "'composite'", ")", ")", "->", "errorrenderer_is", "(", "$", "this", "->", "errorrenderer", "(", "'composite'", ")", ")", ";", "return", "$", "composite", ";", "}" ]
Any additonal parameters are interpreted as Fields that are part of the composite. If an array is passed as second parameter the fields will be interpreted as text Field. Therefore the following: $form->composite('Name', ['given_name', 'family_name']); Is equivalent to this: $form->composite ( 'Name', $form->text(null, 'given_name'), $form->text(null, 'family_name') ); You may also specify a type by making entries associative: [ 'address' => 'text', 'postalcode' => 'number' ] @return \ran\CompositeField
[ "Any", "additonal", "parameters", "are", "interpreted", "as", "Fields", "that", "are", "part", "of", "the", "composite", ".", "If", "an", "array", "is", "passed", "as", "second", "parameter", "the", "fields", "will", "be", "interpreted", "as", "text", "Field", "." ]
f4cbb926ef54da357b102cbfa4b6ce273be6ce63
https://github.com/freialib/ran.tools/blob/f4cbb926ef54da357b102cbfa4b6ce273be6ce63/src/Form.php#L130-L166
train
freialib/ran.tools
src/Form.php
Form.autocomplete_array
function autocomplete_array(array &$hints = null) { if ($this->autocomplete === null) { $this->autocomplete = &$hints; } else if ($hints !== null) { foreach ($hints as $key => $hint) { $this->autocomplete[$key] = $hint; } } return $this; }
php
function autocomplete_array(array &$hints = null) { if ($this->autocomplete === null) { $this->autocomplete = &$hints; } else if ($hints !== null) { foreach ($hints as $key => $hint) { $this->autocomplete[$key] = $hint; } } return $this; }
[ "function", "autocomplete_array", "(", "array", "&", "$", "hints", "=", "null", ")", "{", "if", "(", "$", "this", "->", "autocomplete", "===", "null", ")", "{", "$", "this", "->", "autocomplete", "=", "&", "$", "hints", ";", "}", "else", "if", "(", "$", "hints", "!==", "null", ")", "{", "foreach", "(", "$", "hints", "as", "$", "key", "=>", "$", "hint", ")", "{", "$", "this", "->", "autocomplete", "[", "$", "key", "]", "=", "$", "hint", ";", "}", "}", "return", "$", "this", ";", "}" ]
The given values will be used to autofill the form. They may be however ignored depending on context. @return static $this
[ "The", "given", "values", "will", "be", "used", "to", "autofill", "the", "form", ".", "They", "may", "be", "however", "ignored", "depending", "on", "context", "." ]
f4cbb926ef54da357b102cbfa4b6ce273be6ce63
https://github.com/freialib/ran.tools/blob/f4cbb926ef54da357b102cbfa4b6ce273be6ce63/src/Form.php#L176-L187
train
freialib/ran.tools
src/Form.php
Form.autovalue
function autovalue($fieldname, $default = null) { if ($this->autocomplete !== null) { $fieldname = rtrim($fieldname, '[]'); if (isset($this->autocomplete[$fieldname])) { return $this->autocomplete[$fieldname]; } } // no auto complete value found return $default; }
php
function autovalue($fieldname, $default = null) { if ($this->autocomplete !== null) { $fieldname = rtrim($fieldname, '[]'); if (isset($this->autocomplete[$fieldname])) { return $this->autocomplete[$fieldname]; } } // no auto complete value found return $default; }
[ "function", "autovalue", "(", "$", "fieldname", ",", "$", "default", "=", "null", ")", "{", "if", "(", "$", "this", "->", "autocomplete", "!==", "null", ")", "{", "$", "fieldname", "=", "rtrim", "(", "$", "fieldname", ",", "'[]'", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "autocomplete", "[", "$", "fieldname", "]", ")", ")", "{", "return", "$", "this", "->", "autocomplete", "[", "$", "fieldname", "]", ";", "}", "}", "// no auto complete value found", "return", "$", "default", ";", "}" ]
Retrieve autocomplete value for given field or null. @return mixed or null
[ "Retrieve", "autocomplete", "value", "for", "given", "field", "or", "null", "." ]
f4cbb926ef54da357b102cbfa4b6ce273be6ce63
https://github.com/freialib/ran.tools/blob/f4cbb926ef54da357b102cbfa4b6ce273be6ce63/src/Form.php#L194-L204
train
freialib/ran.tools
src/Form.php
Form.signature
function signature($id = null) { if ( ! $this->unsigned) { if ($this->get('id', null) === null) { $formsignature = 'freiaform'.$this->formindex; } else { # custom signature $formsignature = $this->get('id'); } if ($id !== null) { return "{$formsignature}_field$id"; } else { # form signature return $formsignature; } } else { # unsigned return null; } }
php
function signature($id = null) { if ( ! $this->unsigned) { if ($this->get('id', null) === null) { $formsignature = 'freiaform'.$this->formindex; } else { # custom signature $formsignature = $this->get('id'); } if ($id !== null) { return "{$formsignature}_field$id"; } else { # form signature return $formsignature; } } else { # unsigned return null; } }
[ "function", "signature", "(", "$", "id", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "unsigned", ")", "{", "if", "(", "$", "this", "->", "get", "(", "'id'", ",", "null", ")", "===", "null", ")", "{", "$", "formsignature", "=", "'freiaform'", ".", "$", "this", "->", "formindex", ";", "}", "else", "{", "# custom signature", "$", "formsignature", "=", "$", "this", "->", "get", "(", "'id'", ")", ";", "}", "if", "(", "$", "id", "!==", "null", ")", "{", "return", "\"{$formsignature}_field$id\"", ";", "}", "else", "{", "# form signature", "return", "$", "formsignature", ";", "}", "}", "else", "{", "# unsigned", "return", "null", ";", "}", "}" ]
Returns the form signature or creates signature using given id and form signature. @return string
[ "Returns", "the", "form", "signature", "or", "creates", "signature", "using", "given", "id", "and", "form", "signature", "." ]
f4cbb926ef54da357b102cbfa4b6ce273be6ce63
https://github.com/freialib/ran.tools/blob/f4cbb926ef54da357b102cbfa4b6ce273be6ce63/src/Form.php#L214-L233
train
freialib/ran.tools
src/Form.php
Form.render
function render() { if ($this->show_metainfo) { $this->appendtagbody($this->hidden('form') ->value_is($this->signature())); } return parent::render(); }
php
function render() { if ($this->show_metainfo) { $this->appendtagbody($this->hidden('form') ->value_is($this->signature())); } return parent::render(); }
[ "function", "render", "(", ")", "{", "if", "(", "$", "this", "->", "show_metainfo", ")", "{", "$", "this", "->", "appendtagbody", "(", "$", "this", "->", "hidden", "(", "'form'", ")", "->", "value_is", "(", "$", "this", "->", "signature", "(", ")", ")", ")", ";", "}", "return", "parent", "::", "render", "(", ")", ";", "}" ]
A "form" hidden field will be inserted into the form to identify the data submitted belonged to this form. @return string
[ "A", "form", "hidden", "field", "will", "be", "inserted", "into", "the", "form", "to", "identify", "the", "data", "submitted", "belonged", "to", "this", "form", "." ]
f4cbb926ef54da357b102cbfa4b6ce273be6ce63
https://github.com/freialib/ran.tools/blob/f4cbb926ef54da357b102cbfa4b6ce273be6ce63/src/Form.php#L261-L268
train
vegas-cmf/oauth
src/OAuth/ServiceAbstract.php
ServiceAbstract.setupCredentials
public function setupCredentials(array $credentials) { if (!array_key_exists('key', $credentials)) { throw new InvalidApplicationKeyException(); } if (!array_key_exists('secret', $credentials)) { throw new InvalidApplicationSecretKeyException(); } if (isset($credentials['redirect_uri'])) { $this->currentUri->setPath($credentials['redirect_uri']); } $this->credentials = new Credentials( $credentials['key'], $credentials['secret'], $this->getCurrentUri() ); }
php
public function setupCredentials(array $credentials) { if (!array_key_exists('key', $credentials)) { throw new InvalidApplicationKeyException(); } if (!array_key_exists('secret', $credentials)) { throw new InvalidApplicationSecretKeyException(); } if (isset($credentials['redirect_uri'])) { $this->currentUri->setPath($credentials['redirect_uri']); } $this->credentials = new Credentials( $credentials['key'], $credentials['secret'], $this->getCurrentUri() ); }
[ "public", "function", "setupCredentials", "(", "array", "$", "credentials", ")", "{", "if", "(", "!", "array_key_exists", "(", "'key'", ",", "$", "credentials", ")", ")", "{", "throw", "new", "InvalidApplicationKeyException", "(", ")", ";", "}", "if", "(", "!", "array_key_exists", "(", "'secret'", ",", "$", "credentials", ")", ")", "{", "throw", "new", "InvalidApplicationSecretKeyException", "(", ")", ";", "}", "if", "(", "isset", "(", "$", "credentials", "[", "'redirect_uri'", "]", ")", ")", "{", "$", "this", "->", "currentUri", "->", "setPath", "(", "$", "credentials", "[", "'redirect_uri'", "]", ")", ";", "}", "$", "this", "->", "credentials", "=", "new", "Credentials", "(", "$", "credentials", "[", "'key'", "]", ",", "$", "credentials", "[", "'secret'", "]", ",", "$", "this", "->", "getCurrentUri", "(", ")", ")", ";", "}" ]
Setups provider credentials @param array $credentials @throws Exception\InvalidApplicationKeyException @throws Exception\InvalidApplicationSecretKeyException
[ "Setups", "provider", "credentials" ]
5183a60d02cdf3b7db9f3168be1c0bbe1306cddf
https://github.com/vegas-cmf/oauth/blob/5183a60d02cdf3b7db9f3168be1c0bbe1306cddf/src/OAuth/ServiceAbstract.php#L159-L175
train
vegas-cmf/oauth
src/OAuth/ServiceAbstract.php
ServiceAbstract.setAllScopes
public function setAllScopes() { $scopes = array(); $reflectionClass = new \ReflectionClass(__CLASS__); foreach ($reflectionClass->getConstants() as $constantName => $constantValue) { if (strpos($constantName, 'SCOPE_') !== false) { $scopes = $constantValue; } } $this->setScopes($scopes); }
php
public function setAllScopes() { $scopes = array(); $reflectionClass = new \ReflectionClass(__CLASS__); foreach ($reflectionClass->getConstants() as $constantName => $constantValue) { if (strpos($constantName, 'SCOPE_') !== false) { $scopes = $constantValue; } } $this->setScopes($scopes); }
[ "public", "function", "setAllScopes", "(", ")", "{", "$", "scopes", "=", "array", "(", ")", ";", "$", "reflectionClass", "=", "new", "\\", "ReflectionClass", "(", "__CLASS__", ")", ";", "foreach", "(", "$", "reflectionClass", "->", "getConstants", "(", ")", "as", "$", "constantName", "=>", "$", "constantValue", ")", "{", "if", "(", "strpos", "(", "$", "constantName", ",", "'SCOPE_'", ")", "!==", "false", ")", "{", "$", "scopes", "=", "$", "constantValue", ";", "}", "}", "$", "this", "->", "setScopes", "(", "$", "scopes", ")", ";", "}" ]
Sets all permissions, which user will be asked for during authentication process
[ "Sets", "all", "permissions", "which", "user", "will", "be", "asked", "for", "during", "authentication", "process" ]
5183a60d02cdf3b7db9f3168be1c0bbe1306cddf
https://github.com/vegas-cmf/oauth/blob/5183a60d02cdf3b7db9f3168be1c0bbe1306cddf/src/OAuth/ServiceAbstract.php#L190-L201
train
vegas-cmf/oauth
src/OAuth/ServiceAbstract.php
ServiceAbstract.addScope
public function addScope($scope) { if (!in_array($scope, $this->scopes)) { $this->scopes[] = $scope; } return $this; }
php
public function addScope($scope) { if (!in_array($scope, $this->scopes)) { $this->scopes[] = $scope; } return $this; }
[ "public", "function", "addScope", "(", "$", "scope", ")", "{", "if", "(", "!", "in_array", "(", "$", "scope", ",", "$", "this", "->", "scopes", ")", ")", "{", "$", "this", "->", "scopes", "[", "]", "=", "$", "scope", ";", "}", "return", "$", "this", ";", "}" ]
Adds provider scope @param $scope @return $this
[ "Adds", "provider", "scope" ]
5183a60d02cdf3b7db9f3168be1c0bbe1306cddf
https://github.com/vegas-cmf/oauth/blob/5183a60d02cdf3b7db9f3168be1c0bbe1306cddf/src/OAuth/ServiceAbstract.php#L222-L229
train
vegas-cmf/oauth
src/OAuth/ServiceAbstract.php
ServiceAbstract.isAuthenticated
public function isAuthenticated() { try { $session = $this->sessionStorage->retrieveAccessToken($this->getServiceName()); if (!$session) { return false; } return $session->getEndOfLife() > time(); } catch (TokenNotFoundException $e) { return false; } }
php
public function isAuthenticated() { try { $session = $this->sessionStorage->retrieveAccessToken($this->getServiceName()); if (!$session) { return false; } return $session->getEndOfLife() > time(); } catch (TokenNotFoundException $e) { return false; } }
[ "public", "function", "isAuthenticated", "(", ")", "{", "try", "{", "$", "session", "=", "$", "this", "->", "sessionStorage", "->", "retrieveAccessToken", "(", "$", "this", "->", "getServiceName", "(", ")", ")", ";", "if", "(", "!", "$", "session", ")", "{", "return", "false", ";", "}", "return", "$", "session", "->", "getEndOfLife", "(", ")", ">", "time", "(", ")", ";", "}", "catch", "(", "TokenNotFoundException", "$", "e", ")", "{", "return", "false", ";", "}", "}" ]
Obtains authentication for current service @return bool
[ "Obtains", "authentication", "for", "current", "service" ]
5183a60d02cdf3b7db9f3168be1c0bbe1306cddf
https://github.com/vegas-cmf/oauth/blob/5183a60d02cdf3b7db9f3168be1c0bbe1306cddf/src/OAuth/ServiceAbstract.php#L303-L314
train
SagittariusX/Beluga.Core
src/Beluga/BelugaError.php
BelugaError.getErrorMessage
public function getErrorMessage( bool $appendPreviousByNewline = false ) : string { // Getting a optional previous exception $prev = $this->getPrevious(); if ( \is_null( $prev ) ) { // If no previous exception is used return \sprintf( '%s(%d): %s', static::GetCodeName( $this->getCode() ), $this->getCode(), $this->getMessage() ); } // Define the separator between current and previous exception. $separator = $appendPreviousByNewline ? "\n" : ' '; if ( ( $prev instanceof BelugaError ) ) { return \sprintf( '%s(%d): %s%s%s', static::GetCodeName( $this->getCode() ), $this->getCode(), $this->getMessage(), $separator, $prev->getErrorMessage( $appendPreviousByNewline ) ); } return \sprintf( '%s(%d): %s%s%s', static::GetCodeName( $this->getCode() ), $this->getCode(), $this->getMessage(), $separator, $prev->getMessage() ); }
php
public function getErrorMessage( bool $appendPreviousByNewline = false ) : string { // Getting a optional previous exception $prev = $this->getPrevious(); if ( \is_null( $prev ) ) { // If no previous exception is used return \sprintf( '%s(%d): %s', static::GetCodeName( $this->getCode() ), $this->getCode(), $this->getMessage() ); } // Define the separator between current and previous exception. $separator = $appendPreviousByNewline ? "\n" : ' '; if ( ( $prev instanceof BelugaError ) ) { return \sprintf( '%s(%d): %s%s%s', static::GetCodeName( $this->getCode() ), $this->getCode(), $this->getMessage(), $separator, $prev->getErrorMessage( $appendPreviousByNewline ) ); } return \sprintf( '%s(%d): %s%s%s', static::GetCodeName( $this->getCode() ), $this->getCode(), $this->getMessage(), $separator, $prev->getMessage() ); }
[ "public", "function", "getErrorMessage", "(", "bool", "$", "appendPreviousByNewline", "=", "false", ")", ":", "string", "{", "// Getting a optional previous exception", "$", "prev", "=", "$", "this", "->", "getPrevious", "(", ")", ";", "if", "(", "\\", "is_null", "(", "$", "prev", ")", ")", "{", "// If no previous exception is used", "return", "\\", "sprintf", "(", "'%s(%d): %s'", ",", "static", "::", "GetCodeName", "(", "$", "this", "->", "getCode", "(", ")", ")", ",", "$", "this", "->", "getCode", "(", ")", ",", "$", "this", "->", "getMessage", "(", ")", ")", ";", "}", "// Define the separator between current and previous exception.", "$", "separator", "=", "$", "appendPreviousByNewline", "?", "\"\\n\"", ":", "' '", ";", "if", "(", "(", "$", "prev", "instanceof", "BelugaError", ")", ")", "{", "return", "\\", "sprintf", "(", "'%s(%d): %s%s%s'", ",", "static", "::", "GetCodeName", "(", "$", "this", "->", "getCode", "(", ")", ")", ",", "$", "this", "->", "getCode", "(", ")", ",", "$", "this", "->", "getMessage", "(", ")", ",", "$", "separator", ",", "$", "prev", "->", "getErrorMessage", "(", "$", "appendPreviousByNewline", ")", ")", ";", "}", "return", "\\", "sprintf", "(", "'%s(%d): %s%s%s'", ",", "static", "::", "GetCodeName", "(", "$", "this", "->", "getCode", "(", ")", ")", ",", "$", "this", "->", "getCode", "(", ")", ",", "$", "this", "->", "getMessage", "(", ")", ",", "$", "separator", ",", "$", "prev", "->", "getMessage", "(", ")", ")", ";", "}" ]
Extends the origin getMessage method, so also previous messages are include, if defined. @param bool $appendPreviousByNewline If a prev. Exception is defined append it by a new line? (' ' other) @return string
[ "Extends", "the", "origin", "getMessage", "method", "so", "also", "previous", "messages", "are", "include", "if", "defined", "." ]
51057b362707157a4b075df42bb49f397e2d310b
https://github.com/SagittariusX/Beluga.Core/blob/51057b362707157a4b075df42bb49f397e2d310b/src/Beluga/BelugaError.php#L126-L167
train
SagittariusX/Beluga.Core
src/Beluga/BelugaError.php
BelugaError.GetCodeName
public static function GetCodeName( $code ) : string { switch ( $code ) { case \E_ERROR: case \E_USER_ERROR: return 'ERROR'; case \E_WARNING: case \E_USER_WARNING: return 'WARNING'; case \E_DEPRECATED: case \E_USER_DEPRECATED: return 'DEPRECATED'; case \E_NOTICE: case \E_USER_NOTICE: return 'NOTICE'; case \E_PARSE: return 'PARSE'; case \E_RECOVERABLE_ERROR: return 'RECOVERABLE ERROR'; case \E_STRICT: return 'STRICT'; default: if ( \is_string( $code ) ) { return $code; } return 'OTHER'; } }
php
public static function GetCodeName( $code ) : string { switch ( $code ) { case \E_ERROR: case \E_USER_ERROR: return 'ERROR'; case \E_WARNING: case \E_USER_WARNING: return 'WARNING'; case \E_DEPRECATED: case \E_USER_DEPRECATED: return 'DEPRECATED'; case \E_NOTICE: case \E_USER_NOTICE: return 'NOTICE'; case \E_PARSE: return 'PARSE'; case \E_RECOVERABLE_ERROR: return 'RECOVERABLE ERROR'; case \E_STRICT: return 'STRICT'; default: if ( \is_string( $code ) ) { return $code; } return 'OTHER'; } }
[ "public", "static", "function", "GetCodeName", "(", "$", "code", ")", ":", "string", "{", "switch", "(", "$", "code", ")", "{", "case", "\\", "E_ERROR", ":", "case", "\\", "E_USER_ERROR", ":", "return", "'ERROR'", ";", "case", "\\", "E_WARNING", ":", "case", "\\", "E_USER_WARNING", ":", "return", "'WARNING'", ";", "case", "\\", "E_DEPRECATED", ":", "case", "\\", "E_USER_DEPRECATED", ":", "return", "'DEPRECATED'", ";", "case", "\\", "E_NOTICE", ":", "case", "\\", "E_USER_NOTICE", ":", "return", "'NOTICE'", ";", "case", "\\", "E_PARSE", ":", "return", "'PARSE'", ";", "case", "\\", "E_RECOVERABLE_ERROR", ":", "return", "'RECOVERABLE ERROR'", ";", "case", "\\", "E_STRICT", ":", "return", "'STRICT'", ";", "default", ":", "if", "(", "\\", "is_string", "(", "$", "code", ")", ")", "{", "return", "$", "code", ";", "}", "return", "'OTHER'", ";", "}", "}" ]
Returns a string, representing the defined error code. @param int|string $code e.g.: \E_USER_ERROR @return string
[ "Returns", "a", "string", "representing", "the", "defined", "error", "code", "." ]
51057b362707157a4b075df42bb49f397e2d310b
https://github.com/SagittariusX/Beluga.Core/blob/51057b362707157a4b075df42bb49f397e2d310b/src/Beluga/BelugaError.php#L239-L278
train
Vectrex/vxPHP
src/Mail/Email.php
Email.sendMail
private function sendMail() { // check for configured mailer if(is_null($this->mailer) && !is_null(Application::getInstance()->getConfig()->mail->mailer)) { $mailer = Application::getInstance()->getConfig()->mail->mailer; $reflection = new \ReflectionClass(str_replace('/', '\\', $mailer->class)); $port = isset($mailer->port) ? $mailer->port : null; $encryption = isset($mailer->encryption) ? $mailer->encryption : null; $this->mailer = $reflection->newInstanceArgs([$mailer->host, $port, $encryption]); if(isset($mailer->auth_type)) { $this->mailer->setCredentials($mailer->user, $mailer->pass, $mailer->auth_type); } else { $this->mailer->setCredentials($mailer->user, $mailer->pass); } } if(is_null($this->mailer)) { // use PHP's own mail() function $headers = []; foreach($this->headers as $k => $v) { $headers[] = iconv_mime_encode($k, $v); } mb_internal_encoding($this->encoding); // @todo ensure receiver to be RFC conforming return mail( implode(',', $this->receiver), mb_encode_mimeheader($this->subject, mb_internal_encoding(), 'Q'), $this->msg, implode(self::CRLF, $headers) ); } else { // send mail with configured mailer try { $this->mailer->connect(); $this->mailer->setFrom($this->sender); $this->mailer->setTo(array_merge((array) $this->receiver, $this->cc, $this->bcc)); $this->mailer->setHeaders(array_merge( [ 'To' => implode(',', (array) $this->receiver), 'Subject' => $this->subject ], $this->headers )); $this->mailer->setMessage($this->msg); $this->mailer->send(); $this->mailer->close(); return true; } catch(MailerException $e) { $this->mailer->close(); return $e->getMessage(); } } }
php
private function sendMail() { // check for configured mailer if(is_null($this->mailer) && !is_null(Application::getInstance()->getConfig()->mail->mailer)) { $mailer = Application::getInstance()->getConfig()->mail->mailer; $reflection = new \ReflectionClass(str_replace('/', '\\', $mailer->class)); $port = isset($mailer->port) ? $mailer->port : null; $encryption = isset($mailer->encryption) ? $mailer->encryption : null; $this->mailer = $reflection->newInstanceArgs([$mailer->host, $port, $encryption]); if(isset($mailer->auth_type)) { $this->mailer->setCredentials($mailer->user, $mailer->pass, $mailer->auth_type); } else { $this->mailer->setCredentials($mailer->user, $mailer->pass); } } if(is_null($this->mailer)) { // use PHP's own mail() function $headers = []; foreach($this->headers as $k => $v) { $headers[] = iconv_mime_encode($k, $v); } mb_internal_encoding($this->encoding); // @todo ensure receiver to be RFC conforming return mail( implode(',', $this->receiver), mb_encode_mimeheader($this->subject, mb_internal_encoding(), 'Q'), $this->msg, implode(self::CRLF, $headers) ); } else { // send mail with configured mailer try { $this->mailer->connect(); $this->mailer->setFrom($this->sender); $this->mailer->setTo(array_merge((array) $this->receiver, $this->cc, $this->bcc)); $this->mailer->setHeaders(array_merge( [ 'To' => implode(',', (array) $this->receiver), 'Subject' => $this->subject ], $this->headers )); $this->mailer->setMessage($this->msg); $this->mailer->send(); $this->mailer->close(); return true; } catch(MailerException $e) { $this->mailer->close(); return $e->getMessage(); } } }
[ "private", "function", "sendMail", "(", ")", "{", "// check for configured mailer", "if", "(", "is_null", "(", "$", "this", "->", "mailer", ")", "&&", "!", "is_null", "(", "Application", "::", "getInstance", "(", ")", "->", "getConfig", "(", ")", "->", "mail", "->", "mailer", ")", ")", "{", "$", "mailer", "=", "Application", "::", "getInstance", "(", ")", "->", "getConfig", "(", ")", "->", "mail", "->", "mailer", ";", "$", "reflection", "=", "new", "\\", "ReflectionClass", "(", "str_replace", "(", "'/'", ",", "'\\\\'", ",", "$", "mailer", "->", "class", ")", ")", ";", "$", "port", "=", "isset", "(", "$", "mailer", "->", "port", ")", "?", "$", "mailer", "->", "port", ":", "null", ";", "$", "encryption", "=", "isset", "(", "$", "mailer", "->", "encryption", ")", "?", "$", "mailer", "->", "encryption", ":", "null", ";", "$", "this", "->", "mailer", "=", "$", "reflection", "->", "newInstanceArgs", "(", "[", "$", "mailer", "->", "host", ",", "$", "port", ",", "$", "encryption", "]", ")", ";", "if", "(", "isset", "(", "$", "mailer", "->", "auth_type", ")", ")", "{", "$", "this", "->", "mailer", "->", "setCredentials", "(", "$", "mailer", "->", "user", ",", "$", "mailer", "->", "pass", ",", "$", "mailer", "->", "auth_type", ")", ";", "}", "else", "{", "$", "this", "->", "mailer", "->", "setCredentials", "(", "$", "mailer", "->", "user", ",", "$", "mailer", "->", "pass", ")", ";", "}", "}", "if", "(", "is_null", "(", "$", "this", "->", "mailer", ")", ")", "{", "// use PHP's own mail() function", "$", "headers", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "headers", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "headers", "[", "]", "=", "iconv_mime_encode", "(", "$", "k", ",", "$", "v", ")", ";", "}", "mb_internal_encoding", "(", "$", "this", "->", "encoding", ")", ";", "// @todo ensure receiver to be RFC conforming", "return", "mail", "(", "implode", "(", "','", ",", "$", "this", "->", "receiver", ")", ",", "mb_encode_mimeheader", "(", "$", "this", "->", "subject", ",", "mb_internal_encoding", "(", ")", ",", "'Q'", ")", ",", "$", "this", "->", "msg", ",", "implode", "(", "self", "::", "CRLF", ",", "$", "headers", ")", ")", ";", "}", "else", "{", "// send mail with configured mailer", "try", "{", "$", "this", "->", "mailer", "->", "connect", "(", ")", ";", "$", "this", "->", "mailer", "->", "setFrom", "(", "$", "this", "->", "sender", ")", ";", "$", "this", "->", "mailer", "->", "setTo", "(", "array_merge", "(", "(", "array", ")", "$", "this", "->", "receiver", ",", "$", "this", "->", "cc", ",", "$", "this", "->", "bcc", ")", ")", ";", "$", "this", "->", "mailer", "->", "setHeaders", "(", "array_merge", "(", "[", "'To'", "=>", "implode", "(", "','", ",", "(", "array", ")", "$", "this", "->", "receiver", ")", ",", "'Subject'", "=>", "$", "this", "->", "subject", "]", ",", "$", "this", "->", "headers", ")", ")", ";", "$", "this", "->", "mailer", "->", "setMessage", "(", "$", "this", "->", "msg", ")", ";", "$", "this", "->", "mailer", "->", "send", "(", ")", ";", "$", "this", "->", "mailer", "->", "close", "(", ")", ";", "return", "true", ";", "}", "catch", "(", "MailerException", "$", "e", ")", "{", "$", "this", "->", "mailer", "->", "close", "(", ")", ";", "return", "$", "e", "->", "getMessage", "(", ")", ";", "}", "}", "}" ]
evaluate mailer class and send mail @return boolean @throws \ReflectionException @throws \vxPHP\Application\Exception\ApplicationException
[ "evaluate", "mailer", "class", "and", "send", "mail" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Mail/Email.php#L323-L395
train
Vectrex/vxPHP
src/Mail/Email.php
Email.buildHeaders
private function buildHeaders() { $this->headers = [ 'From' => $this->sender, 'Return-Path' => $this->sender, 'Reply-To' => $this->sender, 'Date' => (new \DateTime())->format('r'), 'Message-ID' => '<'.sha1(microtime()) . '@' . substr($this->sender, strpos($this->sender, '@') + 1) . '>', 'User-Agent' => 'vxPHP SmtpMailer', 'X-Mailer' => 'PHP' . phpversion(), 'MIME-Version' => '1.0' ]; if(!empty($this->cc)) { $this->headers['CC'] = implode(',', $this->cc); } if(!empty($this->bcc)) { $this->headers['BCC'] = implode(',', $this->bcc); } if(count($this->attachments) > 0) { $this->boundary = '!!!@snip@here@!!!'; $this->headers['Content-type'] = sprintf('multipart/mixed; boundary="%s"', $this->boundary); } else { $this->headers['Content-type'] = sprintf('text/%s; charset=%s', $this->htmlMail ? 'html' : 'plain', $this->encoding); } }
php
private function buildHeaders() { $this->headers = [ 'From' => $this->sender, 'Return-Path' => $this->sender, 'Reply-To' => $this->sender, 'Date' => (new \DateTime())->format('r'), 'Message-ID' => '<'.sha1(microtime()) . '@' . substr($this->sender, strpos($this->sender, '@') + 1) . '>', 'User-Agent' => 'vxPHP SmtpMailer', 'X-Mailer' => 'PHP' . phpversion(), 'MIME-Version' => '1.0' ]; if(!empty($this->cc)) { $this->headers['CC'] = implode(',', $this->cc); } if(!empty($this->bcc)) { $this->headers['BCC'] = implode(',', $this->bcc); } if(count($this->attachments) > 0) { $this->boundary = '!!!@snip@here@!!!'; $this->headers['Content-type'] = sprintf('multipart/mixed; boundary="%s"', $this->boundary); } else { $this->headers['Content-type'] = sprintf('text/%s; charset=%s', $this->htmlMail ? 'html' : 'plain', $this->encoding); } }
[ "private", "function", "buildHeaders", "(", ")", "{", "$", "this", "->", "headers", "=", "[", "'From'", "=>", "$", "this", "->", "sender", ",", "'Return-Path'", "=>", "$", "this", "->", "sender", ",", "'Reply-To'", "=>", "$", "this", "->", "sender", ",", "'Date'", "=>", "(", "new", "\\", "DateTime", "(", ")", ")", "->", "format", "(", "'r'", ")", ",", "'Message-ID'", "=>", "'<'", ".", "sha1", "(", "microtime", "(", ")", ")", ".", "'@'", ".", "substr", "(", "$", "this", "->", "sender", ",", "strpos", "(", "$", "this", "->", "sender", ",", "'@'", ")", "+", "1", ")", ".", "'>'", ",", "'User-Agent'", "=>", "'vxPHP SmtpMailer'", ",", "'X-Mailer'", "=>", "'PHP'", ".", "phpversion", "(", ")", ",", "'MIME-Version'", "=>", "'1.0'", "]", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "cc", ")", ")", "{", "$", "this", "->", "headers", "[", "'CC'", "]", "=", "implode", "(", "','", ",", "$", "this", "->", "cc", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "bcc", ")", ")", "{", "$", "this", "->", "headers", "[", "'BCC'", "]", "=", "implode", "(", "','", ",", "$", "this", "->", "bcc", ")", ";", "}", "if", "(", "count", "(", "$", "this", "->", "attachments", ")", ">", "0", ")", "{", "$", "this", "->", "boundary", "=", "'!!!@snip@here@!!!'", ";", "$", "this", "->", "headers", "[", "'Content-type'", "]", "=", "sprintf", "(", "'multipart/mixed; boundary=\"%s\"'", ",", "$", "this", "->", "boundary", ")", ";", "}", "else", "{", "$", "this", "->", "headers", "[", "'Content-type'", "]", "=", "sprintf", "(", "'text/%s; charset=%s'", ",", "$", "this", "->", "htmlMail", "?", "'html'", ":", "'plain'", ",", "$", "this", "->", "encoding", ")", ";", "}", "}" ]
fill headers array
[ "fill", "headers", "array" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Mail/Email.php#L424-L453
train
Vectrex/vxPHP
src/Mail/Email.php
Email.buildMsg
private function buildMsg() { if(isset($this->boundary)) { $this->msg = '--' . $this->boundary . self::CRLF; $this->msg .= 'Content-type: text/' . ($this->htmlMail ? 'html' : 'plain') . '; charset=' .$this->encoding . self::CRLF; $this->msg .= 'Content-Transfer-Encoding: 8bit' . self::CRLF . self::CRLF; } else { $this->msg = ''; } $this->msg .= $this->mailText . self::CRLF; // add signature if(!empty($this->sig) && !$this->htmlMail) { $this->msg .= self::CRLF . self::CRLF . '-- ' . self::CRLF . $this->sig; } if(!count($this->attachments)) { $this->msg .= self::CRLF; } else { foreach($this->attachments as $f) { // attached data always has a filename set $filename = empty($f['filename']) ? basename($f['path']) : $f['filename']; $this->msg .= self::CRLF . '--' . $this->boundary . self::CRLF; $this->msg .= sprintf('Content-Type: application/octet-stream; name="%s"', $filename) . self::CRLF; $this->msg .= sprintf('Content-Disposition: attachment; filename="%s"', $filename) . self::CRLF; $this->msg .= 'Content-Transfer-Encoding: base64' . self::CRLF . self::CRLF; if(isset($f['data'])) { $this->msg .= rtrim(chunk_split(base64_encode($f['data']), 72, self::CRLF)); } else { $this->msg .= rtrim(chunk_split(base64_encode(file_get_contents($f['path'])), 72, self::CRLF)); } } $this->msg .= self::CRLF . '--'. $this->boundary . '--' . self::CRLF; } }
php
private function buildMsg() { if(isset($this->boundary)) { $this->msg = '--' . $this->boundary . self::CRLF; $this->msg .= 'Content-type: text/' . ($this->htmlMail ? 'html' : 'plain') . '; charset=' .$this->encoding . self::CRLF; $this->msg .= 'Content-Transfer-Encoding: 8bit' . self::CRLF . self::CRLF; } else { $this->msg = ''; } $this->msg .= $this->mailText . self::CRLF; // add signature if(!empty($this->sig) && !$this->htmlMail) { $this->msg .= self::CRLF . self::CRLF . '-- ' . self::CRLF . $this->sig; } if(!count($this->attachments)) { $this->msg .= self::CRLF; } else { foreach($this->attachments as $f) { // attached data always has a filename set $filename = empty($f['filename']) ? basename($f['path']) : $f['filename']; $this->msg .= self::CRLF . '--' . $this->boundary . self::CRLF; $this->msg .= sprintf('Content-Type: application/octet-stream; name="%s"', $filename) . self::CRLF; $this->msg .= sprintf('Content-Disposition: attachment; filename="%s"', $filename) . self::CRLF; $this->msg .= 'Content-Transfer-Encoding: base64' . self::CRLF . self::CRLF; if(isset($f['data'])) { $this->msg .= rtrim(chunk_split(base64_encode($f['data']), 72, self::CRLF)); } else { $this->msg .= rtrim(chunk_split(base64_encode(file_get_contents($f['path'])), 72, self::CRLF)); } } $this->msg .= self::CRLF . '--'. $this->boundary . '--' . self::CRLF; } }
[ "private", "function", "buildMsg", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "boundary", ")", ")", "{", "$", "this", "->", "msg", "=", "'--'", ".", "$", "this", "->", "boundary", ".", "self", "::", "CRLF", ";", "$", "this", "->", "msg", ".=", "'Content-type: text/'", ".", "(", "$", "this", "->", "htmlMail", "?", "'html'", ":", "'plain'", ")", ".", "'; charset='", ".", "$", "this", "->", "encoding", ".", "self", "::", "CRLF", ";", "$", "this", "->", "msg", ".=", "'Content-Transfer-Encoding: 8bit'", ".", "self", "::", "CRLF", ".", "self", "::", "CRLF", ";", "}", "else", "{", "$", "this", "->", "msg", "=", "''", ";", "}", "$", "this", "->", "msg", ".=", "$", "this", "->", "mailText", ".", "self", "::", "CRLF", ";", "// add signature", "if", "(", "!", "empty", "(", "$", "this", "->", "sig", ")", "&&", "!", "$", "this", "->", "htmlMail", ")", "{", "$", "this", "->", "msg", ".=", "self", "::", "CRLF", ".", "self", "::", "CRLF", ".", "'-- '", ".", "self", "::", "CRLF", ".", "$", "this", "->", "sig", ";", "}", "if", "(", "!", "count", "(", "$", "this", "->", "attachments", ")", ")", "{", "$", "this", "->", "msg", ".=", "self", "::", "CRLF", ";", "}", "else", "{", "foreach", "(", "$", "this", "->", "attachments", "as", "$", "f", ")", "{", "// attached data always has a filename set", "$", "filename", "=", "empty", "(", "$", "f", "[", "'filename'", "]", ")", "?", "basename", "(", "$", "f", "[", "'path'", "]", ")", ":", "$", "f", "[", "'filename'", "]", ";", "$", "this", "->", "msg", ".=", "self", "::", "CRLF", ".", "'--'", ".", "$", "this", "->", "boundary", ".", "self", "::", "CRLF", ";", "$", "this", "->", "msg", ".=", "sprintf", "(", "'Content-Type: application/octet-stream; name=\"%s\"'", ",", "$", "filename", ")", ".", "self", "::", "CRLF", ";", "$", "this", "->", "msg", ".=", "sprintf", "(", "'Content-Disposition: attachment; filename=\"%s\"'", ",", "$", "filename", ")", ".", "self", "::", "CRLF", ";", "$", "this", "->", "msg", ".=", "'Content-Transfer-Encoding: base64'", ".", "self", "::", "CRLF", ".", "self", "::", "CRLF", ";", "if", "(", "isset", "(", "$", "f", "[", "'data'", "]", ")", ")", "{", "$", "this", "->", "msg", ".=", "rtrim", "(", "chunk_split", "(", "base64_encode", "(", "$", "f", "[", "'data'", "]", ")", ",", "72", ",", "self", "::", "CRLF", ")", ")", ";", "}", "else", "{", "$", "this", "->", "msg", ".=", "rtrim", "(", "chunk_split", "(", "base64_encode", "(", "file_get_contents", "(", "$", "f", "[", "'path'", "]", ")", ")", ",", "72", ",", "self", "::", "CRLF", ")", ")", ";", "}", "}", "$", "this", "->", "msg", ".=", "self", "::", "CRLF", ".", "'--'", ".", "$", "this", "->", "boundary", ".", "'--'", ".", "self", "::", "CRLF", ";", "}", "}" ]
build message body
[ "build", "message", "body" ]
295c21b00e7ef6085efcdf5b64fabb28d499b5a6
https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Mail/Email.php#L458-L505
train
rawphp/RawLog
src/RawPHP/RawLog/Log.php
Log.init
public function init( $config = [ ] ) { $handlers = array_values( $config[ 'handlers' ] ); foreach ( $handlers as $conf ) { $class = $conf[ 'class' ]; $handler = new $class( $conf ); $this->addHandler( $handler ); } }
php
public function init( $config = [ ] ) { $handlers = array_values( $config[ 'handlers' ] ); foreach ( $handlers as $conf ) { $class = $conf[ 'class' ]; $handler = new $class( $conf ); $this->addHandler( $handler ); } }
[ "public", "function", "init", "(", "$", "config", "=", "[", "]", ")", "{", "$", "handlers", "=", "array_values", "(", "$", "config", "[", "'handlers'", "]", ")", ";", "foreach", "(", "$", "handlers", "as", "$", "conf", ")", "{", "$", "class", "=", "$", "conf", "[", "'class'", "]", ";", "$", "handler", "=", "new", "$", "class", "(", "$", "conf", ")", ";", "$", "this", "->", "addHandler", "(", "$", "handler", ")", ";", "}", "}" ]
Initialises the log. @param array $config configuration array @throws LogException if log file is missing
[ "Initialises", "the", "log", "." ]
caee6c1ae92015c9b8481302d0bda5bf4ef9d1b6
https://github.com/rawphp/RawLog/blob/caee6c1ae92015c9b8481302d0bda5bf4ef9d1b6/src/RawPHP/RawLog/Log.php#L73-L85
train
rawphp/RawLog
src/RawPHP/RawLog/Log.php
Log._logIt
private function _logIt( $level, $message, $context = [ ] ) { foreach ( $this->_handlers as $handler ) { $args[ 'message' ] = $message; /** @var IHandler $handler */ $record = $handler->createRecord( $level, $args, $context ); $handler->handle( $record ); } }
php
private function _logIt( $level, $message, $context = [ ] ) { foreach ( $this->_handlers as $handler ) { $args[ 'message' ] = $message; /** @var IHandler $handler */ $record = $handler->createRecord( $level, $args, $context ); $handler->handle( $record ); } }
[ "private", "function", "_logIt", "(", "$", "level", ",", "$", "message", ",", "$", "context", "=", "[", "]", ")", "{", "foreach", "(", "$", "this", "->", "_handlers", "as", "$", "handler", ")", "{", "$", "args", "[", "'message'", "]", "=", "$", "message", ";", "/** @var IHandler $handler */", "$", "record", "=", "$", "handler", "->", "createRecord", "(", "$", "level", ",", "$", "args", ",", "$", "context", ")", ";", "$", "handler", "->", "handle", "(", "$", "record", ")", ";", "}", "}" ]
Logs messages to the log. @param int $level the log level @param string $message the log message @param array $context
[ "Logs", "messages", "to", "the", "log", "." ]
caee6c1ae92015c9b8481302d0bda5bf4ef9d1b6
https://github.com/rawphp/RawLog/blob/caee6c1ae92015c9b8481302d0bda5bf4ef9d1b6/src/RawPHP/RawLog/Log.php#L258-L269
train
rawphp/RawLog
src/RawPHP/RawLog/Log.php
Log.getLevelString
public static function getLevelString( $level ) { $name = ''; switch ( $level ) { case self::LEVEL_DEBUG: $name = 'DEBUG'; break; case self::LEVEL_INFO: $name = 'INFO'; break; case self::LEVEL_NOTICE: $name = 'NOTICE'; break; case self::LEVEL_WARNING: $name = 'WARNING'; break; case self::LEVEL_ERROR: $name = 'ERROR'; break; case self::LEVEL_CRITICAL: $name = 'CRITICAL'; break; case self::LEVEL_ALERT: $name = 'ALERT'; break; case self::LEVEL_EMERGENCY: $name = 'EMERGENCY'; break; default: $name = ''; break; } return $name; }
php
public static function getLevelString( $level ) { $name = ''; switch ( $level ) { case self::LEVEL_DEBUG: $name = 'DEBUG'; break; case self::LEVEL_INFO: $name = 'INFO'; break; case self::LEVEL_NOTICE: $name = 'NOTICE'; break; case self::LEVEL_WARNING: $name = 'WARNING'; break; case self::LEVEL_ERROR: $name = 'ERROR'; break; case self::LEVEL_CRITICAL: $name = 'CRITICAL'; break; case self::LEVEL_ALERT: $name = 'ALERT'; break; case self::LEVEL_EMERGENCY: $name = 'EMERGENCY'; break; default: $name = ''; break; } return $name; }
[ "public", "static", "function", "getLevelString", "(", "$", "level", ")", "{", "$", "name", "=", "''", ";", "switch", "(", "$", "level", ")", "{", "case", "self", "::", "LEVEL_DEBUG", ":", "$", "name", "=", "'DEBUG'", ";", "break", ";", "case", "self", "::", "LEVEL_INFO", ":", "$", "name", "=", "'INFO'", ";", "break", ";", "case", "self", "::", "LEVEL_NOTICE", ":", "$", "name", "=", "'NOTICE'", ";", "break", ";", "case", "self", "::", "LEVEL_WARNING", ":", "$", "name", "=", "'WARNING'", ";", "break", ";", "case", "self", "::", "LEVEL_ERROR", ":", "$", "name", "=", "'ERROR'", ";", "break", ";", "case", "self", "::", "LEVEL_CRITICAL", ":", "$", "name", "=", "'CRITICAL'", ";", "break", ";", "case", "self", "::", "LEVEL_ALERT", ":", "$", "name", "=", "'ALERT'", ";", "break", ";", "case", "self", "::", "LEVEL_EMERGENCY", ":", "$", "name", "=", "'EMERGENCY'", ";", "break", ";", "default", ":", "$", "name", "=", "''", ";", "break", ";", "}", "return", "$", "name", ";", "}" ]
Returns the level as string. @param int $level the level number @return string the level label
[ "Returns", "the", "level", "as", "string", "." ]
caee6c1ae92015c9b8481302d0bda5bf4ef9d1b6
https://github.com/rawphp/RawLog/blob/caee6c1ae92015c9b8481302d0bda5bf4ef9d1b6/src/RawPHP/RawLog/Log.php#L278-L322
train
MatiasNAmendola/slimpower-jwt
src/JwtGenerator.php
JwtGenerator.setTokenValidity
public function setTokenValidity($tokenValidity) { $tknVal = intval($tokenValidity); if (empty($tknVal)) { $tknVal = self::BASIC_VALIDITY; } $this->tokenValidity = intval($tknVal); }
php
public function setTokenValidity($tokenValidity) { $tknVal = intval($tokenValidity); if (empty($tknVal)) { $tknVal = self::BASIC_VALIDITY; } $this->tokenValidity = intval($tknVal); }
[ "public", "function", "setTokenValidity", "(", "$", "tokenValidity", ")", "{", "$", "tknVal", "=", "intval", "(", "$", "tokenValidity", ")", ";", "if", "(", "empty", "(", "$", "tknVal", ")", ")", "{", "$", "tknVal", "=", "self", "::", "BASIC_VALIDITY", ";", "}", "$", "this", "->", "tokenValidity", "=", "intval", "(", "$", "tknVal", ")", ";", "}" ]
Sets token validity @param int $tokenValidity Token validity.
[ "Sets", "token", "validity" ]
5afc151e8a37b06fe6cb6a44ff776e7ec9f40e98
https://github.com/MatiasNAmendola/slimpower-jwt/blob/5afc151e8a37b06fe6cb6a44ff776e7ec9f40e98/src/JwtGenerator.php#L93-L101
train
SagittariusX/Beluga.DynamicProperties
src/Beluga/DynamicProperties/ExplicitGetter.php
ExplicitGetter.hasReadableProperty
public function hasReadableProperty( string $name, &$getterName ) : bool { if ( \in_array( $name, $this->ignoreGetProperties ) ) { return false; } $getterName = 'get' . \ucfirst( $name ); return \method_exists( $this, $getterName ); }
php
public function hasReadableProperty( string $name, &$getterName ) : bool { if ( \in_array( $name, $this->ignoreGetProperties ) ) { return false; } $getterName = 'get' . \ucfirst( $name ); return \method_exists( $this, $getterName ); }
[ "public", "function", "hasReadableProperty", "(", "string", "$", "name", ",", "&", "$", "getterName", ")", ":", "bool", "{", "if", "(", "\\", "in_array", "(", "$", "name", ",", "$", "this", "->", "ignoreGetProperties", ")", ")", "{", "return", "false", ";", "}", "$", "getterName", "=", "'get'", ".", "\\", "ucfirst", "(", "$", "name", ")", ";", "return", "\\", "method_exists", "(", "$", "this", ",", "$", "getterName", ")", ";", "}" ]
Returns, if a property with the defined name exists for read access. @param string $name The name of the property. @param string $getterName Returns the name of the associated get method, if method returns TRUE. @return boolean
[ "Returns", "if", "a", "property", "with", "the", "defined", "name", "exists", "for", "read", "access", "." ]
39a036030d768d64e5a9c5d715c4218bf06b1ce5
https://github.com/SagittariusX/Beluga.DynamicProperties/blob/39a036030d768d64e5a9c5d715c4218bf06b1ce5/src/Beluga/DynamicProperties/ExplicitGetter.php#L76-L88
train
Mandarin-Medien/MMCmfContentBundle
Twig/CmfContentParserExtension.php
CmfContentParserExtension.checkUser
private function checkUser() { static $enabled; if (!isset($enabled)) { $token = $this->tokenStorage->getToken(); if ($token) { $user = $token->getUser(); if ($user instanceof \FOS\UserBundle\Model\User) { if ($user->hasRole('ROLE_USER')) $enabled = $token->isAuthenticated(); } } else $enabled = false; } return $enabled; }
php
private function checkUser() { static $enabled; if (!isset($enabled)) { $token = $this->tokenStorage->getToken(); if ($token) { $user = $token->getUser(); if ($user instanceof \FOS\UserBundle\Model\User) { if ($user->hasRole('ROLE_USER')) $enabled = $token->isAuthenticated(); } } else $enabled = false; } return $enabled; }
[ "private", "function", "checkUser", "(", ")", "{", "static", "$", "enabled", ";", "if", "(", "!", "isset", "(", "$", "enabled", ")", ")", "{", "$", "token", "=", "$", "this", "->", "tokenStorage", "->", "getToken", "(", ")", ";", "if", "(", "$", "token", ")", "{", "$", "user", "=", "$", "token", "->", "getUser", "(", ")", ";", "if", "(", "$", "user", "instanceof", "\\", "FOS", "\\", "UserBundle", "\\", "Model", "\\", "User", ")", "{", "if", "(", "$", "user", "->", "hasRole", "(", "'ROLE_USER'", ")", ")", "$", "enabled", "=", "$", "token", "->", "isAuthenticated", "(", ")", ";", "}", "}", "else", "$", "enabled", "=", "false", ";", "}", "return", "$", "enabled", ";", "}" ]
checks if the current User is ROLE_USER @return bool
[ "checks", "if", "the", "current", "User", "is", "ROLE_USER" ]
503ab31cef3ce068f767de5b72f833526355b726
https://github.com/Mandarin-Medien/MMCmfContentBundle/blob/503ab31cef3ce068f767de5b72f833526355b726/Twig/CmfContentParserExtension.php#L43-L64
train
koolkode/context
src/Bind/ContainerModuleLoader.php
ContainerModuleLoader.getHash
public function getHash() { $names = array_keys($this->modules); sort($names); return md5(implode('|', $names)); }
php
public function getHash() { $names = array_keys($this->modules); sort($names); return md5(implode('|', $names)); }
[ "public", "function", "getHash", "(", ")", "{", "$", "names", "=", "array_keys", "(", "$", "this", "->", "modules", ")", ";", "sort", "(", "$", "names", ")", ";", "return", "md5", "(", "implode", "(", "'|'", ",", "$", "names", ")", ")", ";", "}" ]
Get an MD5 hash computed from the sorted type names of all modules. @return string
[ "Get", "an", "MD5", "hash", "computed", "from", "the", "sorted", "type", "names", "of", "all", "modules", "." ]
f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36
https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/Bind/ContainerModuleLoader.php#L63-L69
train
koolkode/context
src/Bind/ContainerModuleLoader.php
ContainerModuleLoader.getLastModified
public function getLastModified() { $mtime = 0; foreach($this->modules as $module) { $mtime = max($mtime, filemtime((new \ReflectionClass(get_class($module)))->getFileName())); } return $mtime; }
php
public function getLastModified() { $mtime = 0; foreach($this->modules as $module) { $mtime = max($mtime, filemtime((new \ReflectionClass(get_class($module)))->getFileName())); } return $mtime; }
[ "public", "function", "getLastModified", "(", ")", "{", "$", "mtime", "=", "0", ";", "foreach", "(", "$", "this", "->", "modules", "as", "$", "module", ")", "{", "$", "mtime", "=", "max", "(", "$", "mtime", ",", "filemtime", "(", "(", "new", "\\", "ReflectionClass", "(", "get_class", "(", "$", "module", ")", ")", ")", "->", "getFileName", "(", ")", ")", ")", ";", "}", "return", "$", "mtime", ";", "}" ]
Get the time of the most recent modification to any registered module. @return integer
[ "Get", "the", "time", "of", "the", "most", "recent", "modification", "to", "any", "registered", "module", "." ]
f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36
https://github.com/koolkode/context/blob/f4aa614eb4ca1080bd89c7a2a54c9467c5b17a36/src/Bind/ContainerModuleLoader.php#L76-L86
train
fridge-project/dbal
src/Fridge/DBAL/Platform/MySQLPlatform.php
MySQLPlatform.getIntegerSQLDeclarationSnippet
private function getIntegerSQLDeclarationSnippet(array $options = array()) { $length = isset($options['length']) ? (int) $options['length'] : null; $unsigned = isset($options['unsigned']) && $options['unsigned'] ? ' UNSIGNED' : null; $autoIncrement = isset($options['auto_increment']) && $options['auto_increment'] ? ' AUTO_INCREMENT' : null; $sql = $unsigned.$autoIncrement; if ($length !== null) { $sql = '('.$length.')'.$sql; } return $sql; }
php
private function getIntegerSQLDeclarationSnippet(array $options = array()) { $length = isset($options['length']) ? (int) $options['length'] : null; $unsigned = isset($options['unsigned']) && $options['unsigned'] ? ' UNSIGNED' : null; $autoIncrement = isset($options['auto_increment']) && $options['auto_increment'] ? ' AUTO_INCREMENT' : null; $sql = $unsigned.$autoIncrement; if ($length !== null) { $sql = '('.$length.')'.$sql; } return $sql; }
[ "private", "function", "getIntegerSQLDeclarationSnippet", "(", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "length", "=", "isset", "(", "$", "options", "[", "'length'", "]", ")", "?", "(", "int", ")", "$", "options", "[", "'length'", "]", ":", "null", ";", "$", "unsigned", "=", "isset", "(", "$", "options", "[", "'unsigned'", "]", ")", "&&", "$", "options", "[", "'unsigned'", "]", "?", "' UNSIGNED'", ":", "null", ";", "$", "autoIncrement", "=", "isset", "(", "$", "options", "[", "'auto_increment'", "]", ")", "&&", "$", "options", "[", "'auto_increment'", "]", "?", "' AUTO_INCREMENT'", ":", "null", ";", "$", "sql", "=", "$", "unsigned", ".", "$", "autoIncrement", ";", "if", "(", "$", "length", "!==", "null", ")", "{", "$", "sql", "=", "'('", ".", "$", "length", ".", "')'", ".", "$", "sql", ";", "}", "return", "$", "sql", ";", "}" ]
Gets the integer SQL declaration snippet. @param array $options The integer options. @return string The integer SQL declaration snippet.
[ "Gets", "the", "integer", "SQL", "declaration", "snippet", "." ]
d0b8c3551922d696836487aa0eb1bd74014edcd4
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Platform/MySQLPlatform.php#L375-L388
train
fridge-project/dbal
src/Fridge/DBAL/Platform/MySQLPlatform.php
MySQLPlatform.getStringTypePrefix
private function getStringTypePrefix($length = null) { if ($length === null) { return 'LONG'; } if (!is_int($length) || ($length <= 0)) { throw PlatformException::invalidStringTypePrefixLength(); } $prefixLimits = array( 'TINY' => 255, '' => 65535, 'MEDIUM' => 16777215, ); $stringTypePrefix = 'LONG'; foreach ($prefixLimits as $prefix => $limit) { if ($length <= $limit) { $stringTypePrefix = $prefix; break; } } return $stringTypePrefix; }
php
private function getStringTypePrefix($length = null) { if ($length === null) { return 'LONG'; } if (!is_int($length) || ($length <= 0)) { throw PlatformException::invalidStringTypePrefixLength(); } $prefixLimits = array( 'TINY' => 255, '' => 65535, 'MEDIUM' => 16777215, ); $stringTypePrefix = 'LONG'; foreach ($prefixLimits as $prefix => $limit) { if ($length <= $limit) { $stringTypePrefix = $prefix; break; } } return $stringTypePrefix; }
[ "private", "function", "getStringTypePrefix", "(", "$", "length", "=", "null", ")", "{", "if", "(", "$", "length", "===", "null", ")", "{", "return", "'LONG'", ";", "}", "if", "(", "!", "is_int", "(", "$", "length", ")", "||", "(", "$", "length", "<=", "0", ")", ")", "{", "throw", "PlatformException", "::", "invalidStringTypePrefixLength", "(", ")", ";", "}", "$", "prefixLimits", "=", "array", "(", "'TINY'", "=>", "255", ",", "''", "=>", "65535", ",", "'MEDIUM'", "=>", "16777215", ",", ")", ";", "$", "stringTypePrefix", "=", "'LONG'", ";", "foreach", "(", "$", "prefixLimits", "as", "$", "prefix", "=>", "$", "limit", ")", "{", "if", "(", "$", "length", "<=", "$", "limit", ")", "{", "$", "stringTypePrefix", "=", "$", "prefix", ";", "break", ";", "}", "}", "return", "$", "stringTypePrefix", ";", "}" ]
Gets the string type prefix for the given length. @link http://dev.mysql.com/doc/refman/5.5/en/string-type-overview.html String types length. @param null|integer $length The length of the type. @throws \Fridge\DBAL\Exception\PlatformException If the length is not a strict positive integer. @return string The prefix.
[ "Gets", "the", "string", "type", "prefix", "for", "the", "given", "length", "." ]
d0b8c3551922d696836487aa0eb1bd74014edcd4
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Platform/MySQLPlatform.php#L401-L427
train
phossa/phossa-cache
src/Phossa/Cache/Extension/TaggableExtension.php
TaggableExtension.clearByTag
public function clearByTag( CachePoolInterface $cache, /*# string */ $tag )/*# : bool */ { // get tagItem for $tag $tagKey = $this->getTagKey($tag); $tagItem = $cache->getItem($tagKey); // read array of keys from $tagItem if ($tagItem->isHit()) { $keyArray = $tagItem->get(); foreach (array_keys($keyArray) as $key) { if ($cache->deleteItem($key)) { unset($keyArray[$key]); } } // get error if (count($keyArray)) { $this->setError( $cache->getError(), $cache->getErrorCode() ); } // update tagItem $tagItem->set($keyArray); $tagItem->expiresAfter($this->tag_life); // one year $cache->save($tagItem); if (count($keyArray)) { return false; } } return $this->trueAndFlushError(); }
php
public function clearByTag( CachePoolInterface $cache, /*# string */ $tag )/*# : bool */ { // get tagItem for $tag $tagKey = $this->getTagKey($tag); $tagItem = $cache->getItem($tagKey); // read array of keys from $tagItem if ($tagItem->isHit()) { $keyArray = $tagItem->get(); foreach (array_keys($keyArray) as $key) { if ($cache->deleteItem($key)) { unset($keyArray[$key]); } } // get error if (count($keyArray)) { $this->setError( $cache->getError(), $cache->getErrorCode() ); } // update tagItem $tagItem->set($keyArray); $tagItem->expiresAfter($this->tag_life); // one year $cache->save($tagItem); if (count($keyArray)) { return false; } } return $this->trueAndFlushError(); }
[ "public", "function", "clearByTag", "(", "CachePoolInterface", "$", "cache", ",", "/*# string */", "$", "tag", ")", "/*# : bool */", "{", "// get tagItem for $tag", "$", "tagKey", "=", "$", "this", "->", "getTagKey", "(", "$", "tag", ")", ";", "$", "tagItem", "=", "$", "cache", "->", "getItem", "(", "$", "tagKey", ")", ";", "// read array of keys from $tagItem", "if", "(", "$", "tagItem", "->", "isHit", "(", ")", ")", "{", "$", "keyArray", "=", "$", "tagItem", "->", "get", "(", ")", ";", "foreach", "(", "array_keys", "(", "$", "keyArray", ")", "as", "$", "key", ")", "{", "if", "(", "$", "cache", "->", "deleteItem", "(", "$", "key", ")", ")", "{", "unset", "(", "$", "keyArray", "[", "$", "key", "]", ")", ";", "}", "}", "// get error", "if", "(", "count", "(", "$", "keyArray", ")", ")", "{", "$", "this", "->", "setError", "(", "$", "cache", "->", "getError", "(", ")", ",", "$", "cache", "->", "getErrorCode", "(", ")", ")", ";", "}", "// update tagItem", "$", "tagItem", "->", "set", "(", "$", "keyArray", ")", ";", "$", "tagItem", "->", "expiresAfter", "(", "$", "this", "->", "tag_life", ")", ";", "// one year", "$", "cache", "->", "save", "(", "$", "tagItem", ")", ";", "if", "(", "count", "(", "$", "keyArray", ")", ")", "{", "return", "false", ";", "}", "}", "return", "$", "this", "->", "trueAndFlushError", "(", ")", ";", "}" ]
Clear by tags @param CachePoolInterface $cache @param string $tag tag @return bool @access public
[ "Clear", "by", "tags" ]
ad86bee9c5c646fbae09f6f58a346b379d16276e
https://github.com/phossa/phossa-cache/blob/ad86bee9c5c646fbae09f6f58a346b379d16276e/src/Phossa/Cache/Extension/TaggableExtension.php#L127-L163
train
devaloka/mu-plugin-installer
src/Installer/MuPluginInstaller.php
MuPluginInstaller.getLoaderInstallPath
public function getLoaderInstallPath(PackageInterface $package) { $config = $this->getInstallerConfig($package); $installPath = 'wp-content/mu-plugins/'; if (!$this->composer->getPackage()) { return $this->parseTemplate($installPath, $config); } $extra = $this->composer->getPackage()->getExtra(); $prettyName = !empty($config['vendor']) ? ($config['vendor'] . '/') : ''; $prettyName = $prettyName . $config['name']; if (!empty($extra['installer-loader-paths'])) { $customPath = $this->resolveInstallPath($extra['installer-loader-paths'], $prettyName); if ($customPath !== false) { $installPath = $customPath; } } return $this->parseTemplate($installPath, $config); }
php
public function getLoaderInstallPath(PackageInterface $package) { $config = $this->getInstallerConfig($package); $installPath = 'wp-content/mu-plugins/'; if (!$this->composer->getPackage()) { return $this->parseTemplate($installPath, $config); } $extra = $this->composer->getPackage()->getExtra(); $prettyName = !empty($config['vendor']) ? ($config['vendor'] . '/') : ''; $prettyName = $prettyName . $config['name']; if (!empty($extra['installer-loader-paths'])) { $customPath = $this->resolveInstallPath($extra['installer-loader-paths'], $prettyName); if ($customPath !== false) { $installPath = $customPath; } } return $this->parseTemplate($installPath, $config); }
[ "public", "function", "getLoaderInstallPath", "(", "PackageInterface", "$", "package", ")", "{", "$", "config", "=", "$", "this", "->", "getInstallerConfig", "(", "$", "package", ")", ";", "$", "installPath", "=", "'wp-content/mu-plugins/'", ";", "if", "(", "!", "$", "this", "->", "composer", "->", "getPackage", "(", ")", ")", "{", "return", "$", "this", "->", "parseTemplate", "(", "$", "installPath", ",", "$", "config", ")", ";", "}", "$", "extra", "=", "$", "this", "->", "composer", "->", "getPackage", "(", ")", "->", "getExtra", "(", ")", ";", "$", "prettyName", "=", "!", "empty", "(", "$", "config", "[", "'vendor'", "]", ")", "?", "(", "$", "config", "[", "'vendor'", "]", ".", "'/'", ")", ":", "''", ";", "$", "prettyName", "=", "$", "prettyName", ".", "$", "config", "[", "'name'", "]", ";", "if", "(", "!", "empty", "(", "$", "extra", "[", "'installer-loader-paths'", "]", ")", ")", "{", "$", "customPath", "=", "$", "this", "->", "resolveInstallPath", "(", "$", "extra", "[", "'installer-loader-paths'", "]", ",", "$", "prettyName", ")", ";", "if", "(", "$", "customPath", "!==", "false", ")", "{", "$", "installPath", "=", "$", "customPath", ";", "}", "}", "return", "$", "this", "->", "parseTemplate", "(", "$", "installPath", ",", "$", "config", ")", ";", "}" ]
Gets the install path for the loader script of an MU plugin. @param PackageInterface $package An instance of PackageInterface. @return string|bool The install path, or `false` if the path cannot be resolved.
[ "Gets", "the", "install", "path", "for", "the", "loader", "script", "of", "an", "MU", "plugin", "." ]
beefc2d8ef523187e8cb1f3b41ba71fd0aeb49fe
https://github.com/devaloka/mu-plugin-installer/blob/beefc2d8ef523187e8cb1f3b41ba71fd0aeb49fe/src/Installer/MuPluginInstaller.php#L86-L108
train
devaloka/mu-plugin-installer
src/Installer/MuPluginInstaller.php
MuPluginInstaller.getLoaderFilePackagePath
public function getLoaderFilePackagePath(PackageInterface $package) { $installPath = $this->getInstallPath($package); if ($installPath === false) { return false; } $config = $this->getInstallerConfig($package); $packagePath = $installPath . $config['loader']; return $packagePath; }
php
public function getLoaderFilePackagePath(PackageInterface $package) { $installPath = $this->getInstallPath($package); if ($installPath === false) { return false; } $config = $this->getInstallerConfig($package); $packagePath = $installPath . $config['loader']; return $packagePath; }
[ "public", "function", "getLoaderFilePackagePath", "(", "PackageInterface", "$", "package", ")", "{", "$", "installPath", "=", "$", "this", "->", "getInstallPath", "(", "$", "package", ")", ";", "if", "(", "$", "installPath", "===", "false", ")", "{", "return", "false", ";", "}", "$", "config", "=", "$", "this", "->", "getInstallerConfig", "(", "$", "package", ")", ";", "$", "packagePath", "=", "$", "installPath", ".", "$", "config", "[", "'loader'", "]", ";", "return", "$", "packagePath", ";", "}" ]
Gets the file path where a loader script is located. @param PackageInterface $package An instance of PackageInterface. @return string The file path, or `false` if the path cannot be resolved.
[ "Gets", "the", "file", "path", "where", "a", "loader", "script", "is", "located", "." ]
beefc2d8ef523187e8cb1f3b41ba71fd0aeb49fe
https://github.com/devaloka/mu-plugin-installer/blob/beefc2d8ef523187e8cb1f3b41ba71fd0aeb49fe/src/Installer/MuPluginInstaller.php#L117-L129
train
devaloka/mu-plugin-installer
src/Installer/MuPluginInstaller.php
MuPluginInstaller.getLoaderFileInstallPath
public function getLoaderFileInstallPath(PackageInterface $package) { $installPath = $this->getLoaderInstallPath($package); if ($installPath === false) { return false; } $config = $this->getInstallerConfig($package); $installPath = $installPath . basename($config['loader']); return $installPath; }
php
public function getLoaderFileInstallPath(PackageInterface $package) { $installPath = $this->getLoaderInstallPath($package); if ($installPath === false) { return false; } $config = $this->getInstallerConfig($package); $installPath = $installPath . basename($config['loader']); return $installPath; }
[ "public", "function", "getLoaderFileInstallPath", "(", "PackageInterface", "$", "package", ")", "{", "$", "installPath", "=", "$", "this", "->", "getLoaderInstallPath", "(", "$", "package", ")", ";", "if", "(", "$", "installPath", "===", "false", ")", "{", "return", "false", ";", "}", "$", "config", "=", "$", "this", "->", "getInstallerConfig", "(", "$", "package", ")", ";", "$", "installPath", "=", "$", "installPath", ".", "basename", "(", "$", "config", "[", "'loader'", "]", ")", ";", "return", "$", "installPath", ";", "}" ]
Gets the file path where a loader script is installed. @param PackageInterface $package An instance of PackageInterface. @return string The file path, or `false` if the path cannot be resolved.
[ "Gets", "the", "file", "path", "where", "a", "loader", "script", "is", "installed", "." ]
beefc2d8ef523187e8cb1f3b41ba71fd0aeb49fe
https://github.com/devaloka/mu-plugin-installer/blob/beefc2d8ef523187e8cb1f3b41ba71fd0aeb49fe/src/Installer/MuPluginInstaller.php#L138-L150
train
devaloka/mu-plugin-installer
src/Installer/MuPluginInstaller.php
MuPluginInstaller.getInstallerConfig
protected function getInstallerConfig(PackageInterface $package) { if ($this->installerConfig !== null) { return $this->installerConfig; } $type = $package->getType(); $prettyName = $package->getPrettyName(); if (strpos($prettyName, '/') !== false) { list($vendor, $name) = explode('/', $prettyName); } else { $vendor = ''; $name = $prettyName; } $extra = $package->getExtra(); if (!empty($extra['installer-name'])) { $name = $extra['installer-name']; } $loader = 'mu-plugins/' . $name . '.php'; if (!empty($extra['installer-loader'])) { $loader = $extra['installer-loader']; } return compact('name', 'vendor', 'type', 'loader'); }
php
protected function getInstallerConfig(PackageInterface $package) { if ($this->installerConfig !== null) { return $this->installerConfig; } $type = $package->getType(); $prettyName = $package->getPrettyName(); if (strpos($prettyName, '/') !== false) { list($vendor, $name) = explode('/', $prettyName); } else { $vendor = ''; $name = $prettyName; } $extra = $package->getExtra(); if (!empty($extra['installer-name'])) { $name = $extra['installer-name']; } $loader = 'mu-plugins/' . $name . '.php'; if (!empty($extra['installer-loader'])) { $loader = $extra['installer-loader']; } return compact('name', 'vendor', 'type', 'loader'); }
[ "protected", "function", "getInstallerConfig", "(", "PackageInterface", "$", "package", ")", "{", "if", "(", "$", "this", "->", "installerConfig", "!==", "null", ")", "{", "return", "$", "this", "->", "installerConfig", ";", "}", "$", "type", "=", "$", "package", "->", "getType", "(", ")", ";", "$", "prettyName", "=", "$", "package", "->", "getPrettyName", "(", ")", ";", "if", "(", "strpos", "(", "$", "prettyName", ",", "'/'", ")", "!==", "false", ")", "{", "list", "(", "$", "vendor", ",", "$", "name", ")", "=", "explode", "(", "'/'", ",", "$", "prettyName", ")", ";", "}", "else", "{", "$", "vendor", "=", "''", ";", "$", "name", "=", "$", "prettyName", ";", "}", "$", "extra", "=", "$", "package", "->", "getExtra", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "extra", "[", "'installer-name'", "]", ")", ")", "{", "$", "name", "=", "$", "extra", "[", "'installer-name'", "]", ";", "}", "$", "loader", "=", "'mu-plugins/'", ".", "$", "name", ".", "'.php'", ";", "if", "(", "!", "empty", "(", "$", "extra", "[", "'installer-loader'", "]", ")", ")", "{", "$", "loader", "=", "$", "extra", "[", "'installer-loader'", "]", ";", "}", "return", "compact", "(", "'name'", ",", "'vendor'", ",", "'type'", ",", "'loader'", ")", ";", "}" ]
Retrieves configuration values from a packages's `composer.json`. @param PackageInterface $package An instance of PackageInterface. @return string[] The configuration values.
[ "Retrieves", "configuration", "values", "from", "a", "packages", "s", "composer", ".", "json", "." ]
beefc2d8ef523187e8cb1f3b41ba71fd0aeb49fe
https://github.com/devaloka/mu-plugin-installer/blob/beefc2d8ef523187e8cb1f3b41ba71fd0aeb49fe/src/Installer/MuPluginInstaller.php#L159-L188
train
devaloka/mu-plugin-installer
src/Installer/MuPluginInstaller.php
MuPluginInstaller.parseTemplate
protected function parseTemplate($template, array $vars = array()) { if (strpos($template, '{') === false) { return $template; } if (preg_match_all('@\{\$([A-Za-z0-9_]+)\}@i', $template, $matches)) { foreach ($matches[1] as $varName) { $template = str_replace('{$' . $varName . '}', $vars[$varName], $template); } } return $template; }
php
protected function parseTemplate($template, array $vars = array()) { if (strpos($template, '{') === false) { return $template; } if (preg_match_all('@\{\$([A-Za-z0-9_]+)\}@i', $template, $matches)) { foreach ($matches[1] as $varName) { $template = str_replace('{$' . $varName . '}', $vars[$varName], $template); } } return $template; }
[ "protected", "function", "parseTemplate", "(", "$", "template", ",", "array", "$", "vars", "=", "array", "(", ")", ")", "{", "if", "(", "strpos", "(", "$", "template", ",", "'{'", ")", "===", "false", ")", "{", "return", "$", "template", ";", "}", "if", "(", "preg_match_all", "(", "'@\\{\\$([A-Za-z0-9_]+)\\}@i'", ",", "$", "template", ",", "$", "matches", ")", ")", "{", "foreach", "(", "$", "matches", "[", "1", "]", "as", "$", "varName", ")", "{", "$", "template", "=", "str_replace", "(", "'{$'", ".", "$", "varName", ".", "'}'", ",", "$", "vars", "[", "$", "varName", "]", ",", "$", "template", ")", ";", "}", "}", "return", "$", "template", ";", "}" ]
Parses a template string. @param string $template A template string. @param mixed[] $vars Template variables. @return string The parsed template string. @see https://github.com/composer/installers This code is based on the Composer Installer.
[ "Parses", "a", "template", "string", "." ]
beefc2d8ef523187e8cb1f3b41ba71fd0aeb49fe
https://github.com/devaloka/mu-plugin-installer/blob/beefc2d8ef523187e8cb1f3b41ba71fd0aeb49fe/src/Installer/MuPluginInstaller.php#L200-L213
train
devaloka/mu-plugin-installer
src/Installer/MuPluginInstaller.php
MuPluginInstaller.resolveInstallPath
protected function resolveInstallPath(array $paths, $name) { foreach ($paths as $path => $names) { if (in_array($name, $names, true) || in_array('type:' . static::TYPE, $names, true)) { return $path; } } return false; }
php
protected function resolveInstallPath(array $paths, $name) { foreach ($paths as $path => $names) { if (in_array($name, $names, true) || in_array('type:' . static::TYPE, $names, true)) { return $path; } } return false; }
[ "protected", "function", "resolveInstallPath", "(", "array", "$", "paths", ",", "$", "name", ")", "{", "foreach", "(", "$", "paths", "as", "$", "path", "=>", "$", "names", ")", "{", "if", "(", "in_array", "(", "$", "name", ",", "$", "names", ",", "true", ")", "||", "in_array", "(", "'type:'", ".", "static", "::", "TYPE", ",", "$", "names", ",", "true", ")", ")", "{", "return", "$", "path", ";", "}", "}", "return", "false", ";", "}" ]
Searches the install path based on a package name and a paths array. @param array[] $paths A paths array. @param string $name A package name. @return string|bool The install path, or `false` if the path cannot be resolved. @see https://github.com/composer/installers This code is based on the Composer Installer.
[ "Searches", "the", "install", "path", "based", "on", "a", "package", "name", "and", "a", "paths", "array", "." ]
beefc2d8ef523187e8cb1f3b41ba71fd0aeb49fe
https://github.com/devaloka/mu-plugin-installer/blob/beefc2d8ef523187e8cb1f3b41ba71fd0aeb49fe/src/Installer/MuPluginInstaller.php#L225-L234
train
devaloka/mu-plugin-installer
src/Installer/MuPluginInstaller.php
MuPluginInstaller.installLoader
protected function installLoader(PackageInterface $package) { $source = $this->getLoaderFilePackagePath($package); $target = $this->getLoaderFileInstallPath($package); copy($source, $target); }
php
protected function installLoader(PackageInterface $package) { $source = $this->getLoaderFilePackagePath($package); $target = $this->getLoaderFileInstallPath($package); copy($source, $target); }
[ "protected", "function", "installLoader", "(", "PackageInterface", "$", "package", ")", "{", "$", "source", "=", "$", "this", "->", "getLoaderFilePackagePath", "(", "$", "package", ")", ";", "$", "target", "=", "$", "this", "->", "getLoaderFileInstallPath", "(", "$", "package", ")", ";", "copy", "(", "$", "source", ",", "$", "target", ")", ";", "}" ]
Installs the loader script of an MU plugin. @param PackageInterface $package An instance of PackageInterface.
[ "Installs", "the", "loader", "script", "of", "an", "MU", "plugin", "." ]
beefc2d8ef523187e8cb1f3b41ba71fd0aeb49fe
https://github.com/devaloka/mu-plugin-installer/blob/beefc2d8ef523187e8cb1f3b41ba71fd0aeb49fe/src/Installer/MuPluginInstaller.php#L251-L257
train
devaloka/mu-plugin-installer
src/Installer/MuPluginInstaller.php
MuPluginInstaller.removeLoader
protected function removeLoader(PackageInterface $package) { $target = $this->getLoaderFileInstallPath($package); if (!$this->filesystem->remove($target)) { throw new \RuntimeException('Could not completely delete ' . $target . ', aborting.'); } }
php
protected function removeLoader(PackageInterface $package) { $target = $this->getLoaderFileInstallPath($package); if (!$this->filesystem->remove($target)) { throw new \RuntimeException('Could not completely delete ' . $target . ', aborting.'); } }
[ "protected", "function", "removeLoader", "(", "PackageInterface", "$", "package", ")", "{", "$", "target", "=", "$", "this", "->", "getLoaderFileInstallPath", "(", "$", "package", ")", ";", "if", "(", "!", "$", "this", "->", "filesystem", "->", "remove", "(", "$", "target", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Could not completely delete '", ".", "$", "target", ".", "', aborting.'", ")", ";", "}", "}" ]
Removes the loader script of an MU plugin. @param PackageInterface $package An instance of PackageInterface.
[ "Removes", "the", "loader", "script", "of", "an", "MU", "plugin", "." ]
beefc2d8ef523187e8cb1f3b41ba71fd0aeb49fe
https://github.com/devaloka/mu-plugin-installer/blob/beefc2d8ef523187e8cb1f3b41ba71fd0aeb49fe/src/Installer/MuPluginInstaller.php#L274-L281
train
pMatviienko/zf2-common
SbxCommon/src/SbxCommon/Form/View/Helper/Bootstrap/FormElement.php
FormElement.renderHelper
protected function renderHelper($name, ElementInterface $element) { $helper = $this->getView()->plugin($name); return $helper($element); }
php
protected function renderHelper($name, ElementInterface $element) { $helper = $this->getView()->plugin($name); return $helper($element); }
[ "protected", "function", "renderHelper", "(", "$", "name", ",", "ElementInterface", "$", "element", ")", "{", "$", "helper", "=", "$", "this", "->", "getView", "(", ")", "->", "plugin", "(", "$", "name", ")", ";", "return", "$", "helper", "(", "$", "element", ")", ";", "}" ]
Render element by helper name @param string $name @param ElementInterface $element @return string
[ "Render", "element", "by", "helper", "name" ]
e59aa9b1eece72437cf0fd7c8466c0daeffcc481
https://github.com/pMatviienko/zf2-common/blob/e59aa9b1eece72437cf0fd7c8466c0daeffcc481/SbxCommon/src/SbxCommon/Form/View/Helper/Bootstrap/FormElement.php#L79-L83
train
JamesMcAvoy/PsrRouter
src/PsrRouter.php
PsrRouter.getRoutes
public function getRoutes() : Array { $return = array(); foreach($this->routes as $route) { array_push($return, [$route->getPath(), $route->getMethod()]); } return $return; }
php
public function getRoutes() : Array { $return = array(); foreach($this->routes as $route) { array_push($return, [$route->getPath(), $route->getMethod()]); } return $return; }
[ "public", "function", "getRoutes", "(", ")", ":", "Array", "{", "$", "return", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "routes", "as", "$", "route", ")", "{", "array_push", "(", "$", "return", ",", "[", "$", "route", "->", "getPath", "(", ")", ",", "$", "route", "->", "getMethod", "(", ")", "]", ")", ";", "}", "return", "$", "return", ";", "}" ]
Return all defined routes with their method @return Array
[ "Return", "all", "defined", "routes", "with", "their", "method" ]
00a3e15f8d1f87aef0eadde1074bea2179cd53fe
https://github.com/JamesMcAvoy/PsrRouter/blob/00a3e15f8d1f87aef0eadde1074bea2179cd53fe/src/PsrRouter.php#L141-L149
train
JamesMcAvoy/PsrRouter
src/PsrRouter.php
PsrRouter.get
public function get(String $path, Callable $callback) : Route { return $this->collectRoute('GET', $path, $callback); }
php
public function get(String $path, Callable $callback) : Route { return $this->collectRoute('GET', $path, $callback); }
[ "public", "function", "get", "(", "String", "$", "path", ",", "Callable", "$", "callback", ")", ":", "Route", "{", "return", "$", "this", "->", "collectRoute", "(", "'GET'", ",", "$", "path", ",", "$", "callback", ")", ";", "}" ]
Create and collect a new Route with GET request @param String $path @param mixed $callback callback or closure function @return Route
[ "Create", "and", "collect", "a", "new", "Route", "with", "GET", "request" ]
00a3e15f8d1f87aef0eadde1074bea2179cd53fe
https://github.com/JamesMcAvoy/PsrRouter/blob/00a3e15f8d1f87aef0eadde1074bea2179cd53fe/src/PsrRouter.php#L177-L181
train
JamesMcAvoy/PsrRouter
src/PsrRouter.php
PsrRouter.post
public function post(String $path, Callable $callback) : Route { return $this->collectRoute('POST', $path, $callback); }
php
public function post(String $path, Callable $callback) : Route { return $this->collectRoute('POST', $path, $callback); }
[ "public", "function", "post", "(", "String", "$", "path", ",", "Callable", "$", "callback", ")", ":", "Route", "{", "return", "$", "this", "->", "collectRoute", "(", "'POST'", ",", "$", "path", ",", "$", "callback", ")", ";", "}" ]
Create and collect a new Route with POST request @param String $path @param mixed $callback callback or closure function @return Route
[ "Create", "and", "collect", "a", "new", "Route", "with", "POST", "request" ]
00a3e15f8d1f87aef0eadde1074bea2179cd53fe
https://github.com/JamesMcAvoy/PsrRouter/blob/00a3e15f8d1f87aef0eadde1074bea2179cd53fe/src/PsrRouter.php#L189-L193
train
JamesMcAvoy/PsrRouter
src/PsrRouter.php
PsrRouter.put
public function put(String $path, Callable $callback) : Route { return $this->collectRoute('PUT', $path, $callback); }
php
public function put(String $path, Callable $callback) : Route { return $this->collectRoute('PUT', $path, $callback); }
[ "public", "function", "put", "(", "String", "$", "path", ",", "Callable", "$", "callback", ")", ":", "Route", "{", "return", "$", "this", "->", "collectRoute", "(", "'PUT'", ",", "$", "path", ",", "$", "callback", ")", ";", "}" ]
Create and collect a new Route with PUT request @param String $path @param mixed $callback callback or closure function @return Route
[ "Create", "and", "collect", "a", "new", "Route", "with", "PUT", "request" ]
00a3e15f8d1f87aef0eadde1074bea2179cd53fe
https://github.com/JamesMcAvoy/PsrRouter/blob/00a3e15f8d1f87aef0eadde1074bea2179cd53fe/src/PsrRouter.php#L201-L205
train
JamesMcAvoy/PsrRouter
src/PsrRouter.php
PsrRouter.delete
public function delete(String $path, Callable $callback) : Route { return $this->collectRoute('DELETE', $path, $callback); }
php
public function delete(String $path, Callable $callback) : Route { return $this->collectRoute('DELETE', $path, $callback); }
[ "public", "function", "delete", "(", "String", "$", "path", ",", "Callable", "$", "callback", ")", ":", "Route", "{", "return", "$", "this", "->", "collectRoute", "(", "'DELETE'", ",", "$", "path", ",", "$", "callback", ")", ";", "}" ]
Create and collect a new Route with DELETE request @param String $path @param mixed $callback callback or closure function @return Route
[ "Create", "and", "collect", "a", "new", "Route", "with", "DELETE", "request" ]
00a3e15f8d1f87aef0eadde1074bea2179cd53fe
https://github.com/JamesMcAvoy/PsrRouter/blob/00a3e15f8d1f87aef0eadde1074bea2179cd53fe/src/PsrRouter.php#L213-L217
train
JamesMcAvoy/PsrRouter
src/PsrRouter.php
PsrRouter.options
public function options(String $path, Callable $callback) : Route { return $this->collectRoute('OPTIONS', $path, $callback); }
php
public function options(String $path, Callable $callback) : Route { return $this->collectRoute('OPTIONS', $path, $callback); }
[ "public", "function", "options", "(", "String", "$", "path", ",", "Callable", "$", "callback", ")", ":", "Route", "{", "return", "$", "this", "->", "collectRoute", "(", "'OPTIONS'", ",", "$", "path", ",", "$", "callback", ")", ";", "}" ]
Create and collect a new Route with OPTIONS request @param String $path @param mixed $callback callback or closure function @return Route
[ "Create", "and", "collect", "a", "new", "Route", "with", "OPTIONS", "request" ]
00a3e15f8d1f87aef0eadde1074bea2179cd53fe
https://github.com/JamesMcAvoy/PsrRouter/blob/00a3e15f8d1f87aef0eadde1074bea2179cd53fe/src/PsrRouter.php#L225-L229
train
JamesMcAvoy/PsrRouter
src/PsrRouter.php
PsrRouter.patch
public function patch(String $path, Callable $callback) : Route { return $this->collectRoute('PATCH', $path, $callback); }
php
public function patch(String $path, Callable $callback) : Route { return $this->collectRoute('PATCH', $path, $callback); }
[ "public", "function", "patch", "(", "String", "$", "path", ",", "Callable", "$", "callback", ")", ":", "Route", "{", "return", "$", "this", "->", "collectRoute", "(", "'PATCH'", ",", "$", "path", ",", "$", "callback", ")", ";", "}" ]
Create and collect a new Route with PATCH request @param String $path @param mixed $callback callback or closure function @return Route
[ "Create", "and", "collect", "a", "new", "Route", "with", "PATCH", "request" ]
00a3e15f8d1f87aef0eadde1074bea2179cd53fe
https://github.com/JamesMcAvoy/PsrRouter/blob/00a3e15f8d1f87aef0eadde1074bea2179cd53fe/src/PsrRouter.php#L237-L241
train
mtils/cmsable
src/Cmsable/Resource/ResourceValidator.php
ResourceValidator.validateOrFail
public function validateOrFail(array $data, $model=null) { $this->publish('validating', [$this, $data, $model]); $rules = $this->rules(); $parsedRules = $this->parseRules($rules, $data, $model); $this->publish('validation-rules.parsed', [&$parsedRules]); $validator = $this->getValidatorInstance($parsedRules, $data, $model); $validator->setAttributeNames($this->customAttributes()); if ($this->validate($validator)) { return true; } throw new \Illuminate\Validation\ValidationException($validator); }
php
public function validateOrFail(array $data, $model=null) { $this->publish('validating', [$this, $data, $model]); $rules = $this->rules(); $parsedRules = $this->parseRules($rules, $data, $model); $this->publish('validation-rules.parsed', [&$parsedRules]); $validator = $this->getValidatorInstance($parsedRules, $data, $model); $validator->setAttributeNames($this->customAttributes()); if ($this->validate($validator)) { return true; } throw new \Illuminate\Validation\ValidationException($validator); }
[ "public", "function", "validateOrFail", "(", "array", "$", "data", ",", "$", "model", "=", "null", ")", "{", "$", "this", "->", "publish", "(", "'validating'", ",", "[", "$", "this", ",", "$", "data", ",", "$", "model", "]", ")", ";", "$", "rules", "=", "$", "this", "->", "rules", "(", ")", ";", "$", "parsedRules", "=", "$", "this", "->", "parseRules", "(", "$", "rules", ",", "$", "data", ",", "$", "model", ")", ";", "$", "this", "->", "publish", "(", "'validation-rules.parsed'", ",", "[", "&", "$", "parsedRules", "]", ")", ";", "$", "validator", "=", "$", "this", "->", "getValidatorInstance", "(", "$", "parsedRules", ",", "$", "data", ",", "$", "model", ")", ";", "$", "validator", "->", "setAttributeNames", "(", "$", "this", "->", "customAttributes", "(", ")", ")", ";", "if", "(", "$", "this", "->", "validate", "(", "$", "validator", ")", ")", "{", "return", "true", ";", "}", "throw", "new", "\\", "Illuminate", "\\", "Validation", "\\", "ValidationException", "(", "$", "validator", ")", ";", "}" ]
Validate the data. If validation failes, throw a exception If a model is passed as the second parameter, parse the rules to match the model. If no model is passed, considerate it as a new model @param array $data The (request) data @param mixed $model (optional) @return bool @throw \Illuminate\Contracts\Validation\ValidationException
[ "Validate", "the", "data", ".", "If", "validation", "failes", "throw", "a", "exception", "If", "a", "model", "is", "passed", "as", "the", "second", "parameter", "parse", "the", "rules", "to", "match", "the", "model", ".", "If", "no", "model", "is", "passed", "considerate", "it", "as", "a", "new", "model" ]
03ae84ee3c7d46146f2a1cf687e5c29d6de4286d
https://github.com/mtils/cmsable/blob/03ae84ee3c7d46146f2a1cf687e5c29d6de4286d/src/Cmsable/Resource/ResourceValidator.php#L52-L72
train
mtils/cmsable
src/Cmsable/Resource/ResourceValidator.php
ResourceValidator.getValidatorInstance
protected function getValidatorInstance($rules, $data, $model=null) { $factory = $this->container->make('Illuminate\Validation\Factory'); if (method_exists($this, 'validatorInstance')) { return $this->container->call( [$this, 'validatorInstance'], compact('factory') ); } return $factory->make( $data, $rules, $this->customMessages(), $this->customAttributes() ); }
php
protected function getValidatorInstance($rules, $data, $model=null) { $factory = $this->container->make('Illuminate\Validation\Factory'); if (method_exists($this, 'validatorInstance')) { return $this->container->call( [$this, 'validatorInstance'], compact('factory') ); } return $factory->make( $data, $rules, $this->customMessages(), $this->customAttributes() ); }
[ "protected", "function", "getValidatorInstance", "(", "$", "rules", ",", "$", "data", ",", "$", "model", "=", "null", ")", "{", "$", "factory", "=", "$", "this", "->", "container", "->", "make", "(", "'Illuminate\\Validation\\Factory'", ")", ";", "if", "(", "method_exists", "(", "$", "this", ",", "'validatorInstance'", ")", ")", "{", "return", "$", "this", "->", "container", "->", "call", "(", "[", "$", "this", ",", "'validatorInstance'", "]", ",", "compact", "(", "'factory'", ")", ")", ";", "}", "return", "$", "factory", "->", "make", "(", "$", "data", ",", "$", "rules", ",", "$", "this", "->", "customMessages", "(", ")", ",", "$", "this", "->", "customAttributes", "(", ")", ")", ";", "}" ]
Get the validator instance to perform the actual validation @return \Illuminate\Validation\Validator
[ "Get", "the", "validator", "instance", "to", "perform", "the", "actual", "validation" ]
03ae84ee3c7d46146f2a1cf687e5c29d6de4286d
https://github.com/mtils/cmsable/blob/03ae84ee3c7d46146f2a1cf687e5c29d6de4286d/src/Cmsable/Resource/ResourceValidator.php#L89-L104
train
mtils/cmsable
src/Cmsable/Resource/ResourceValidator.php
ResourceValidator.customAttributes
public function customAttributes() { if (!$form = $this->distributor->form(null, $this->resourceName())){ return []; } return $form->getValidator()->buildAttributeNames($form); }
php
public function customAttributes() { if (!$form = $this->distributor->form(null, $this->resourceName())){ return []; } return $form->getValidator()->buildAttributeNames($form); }
[ "public", "function", "customAttributes", "(", ")", "{", "if", "(", "!", "$", "form", "=", "$", "this", "->", "distributor", "->", "form", "(", "null", ",", "$", "this", "->", "resourceName", "(", ")", ")", ")", "{", "return", "[", "]", ";", "}", "return", "$", "form", "->", "getValidator", "(", ")", "->", "buildAttributeNames", "(", "$", "form", ")", ";", "}" ]
Set custom attributes for validator errors. @return array
[ "Set", "custom", "attributes", "for", "validator", "errors", "." ]
03ae84ee3c7d46146f2a1cf687e5c29d6de4286d
https://github.com/mtils/cmsable/blob/03ae84ee3c7d46146f2a1cf687e5c29d6de4286d/src/Cmsable/Resource/ResourceValidator.php#L121-L128
train
rollerworks/search-core
Extension/Core/ChoiceList/ArrayChoiceList.php
ArrayChoiceList.flatten
private function flatten(array $choices, callable $value, &$choicesByValues, &$keysByValues, &$structuredValues): void { if (null === $choicesByValues) { $choicesByValues = []; $keysByValues = []; $structuredValues = []; } foreach ($choices as $key => $choice) { if (\is_array($choice)) { $this->flatten($choice, $value, $choicesByValues, $keysByValues, $structuredValues[$key]); continue; } $choiceValue = (string) \call_user_func($value, $choice); $choicesByValues[$choiceValue] = $choice; $keysByValues[$choiceValue] = $key; $structuredValues[$key] = $choiceValue; } }
php
private function flatten(array $choices, callable $value, &$choicesByValues, &$keysByValues, &$structuredValues): void { if (null === $choicesByValues) { $choicesByValues = []; $keysByValues = []; $structuredValues = []; } foreach ($choices as $key => $choice) { if (\is_array($choice)) { $this->flatten($choice, $value, $choicesByValues, $keysByValues, $structuredValues[$key]); continue; } $choiceValue = (string) \call_user_func($value, $choice); $choicesByValues[$choiceValue] = $choice; $keysByValues[$choiceValue] = $key; $structuredValues[$key] = $choiceValue; } }
[ "private", "function", "flatten", "(", "array", "$", "choices", ",", "callable", "$", "value", ",", "&", "$", "choicesByValues", ",", "&", "$", "keysByValues", ",", "&", "$", "structuredValues", ")", ":", "void", "{", "if", "(", "null", "===", "$", "choicesByValues", ")", "{", "$", "choicesByValues", "=", "[", "]", ";", "$", "keysByValues", "=", "[", "]", ";", "$", "structuredValues", "=", "[", "]", ";", "}", "foreach", "(", "$", "choices", "as", "$", "key", "=>", "$", "choice", ")", "{", "if", "(", "\\", "is_array", "(", "$", "choice", ")", ")", "{", "$", "this", "->", "flatten", "(", "$", "choice", ",", "$", "value", ",", "$", "choicesByValues", ",", "$", "keysByValues", ",", "$", "structuredValues", "[", "$", "key", "]", ")", ";", "continue", ";", "}", "$", "choiceValue", "=", "(", "string", ")", "\\", "call_user_func", "(", "$", "value", ",", "$", "choice", ")", ";", "$", "choicesByValues", "[", "$", "choiceValue", "]", "=", "$", "choice", ";", "$", "keysByValues", "[", "$", "choiceValue", "]", "=", "$", "key", ";", "$", "structuredValues", "[", "$", "key", "]", "=", "$", "choiceValue", ";", "}", "}" ]
Flattens an array into the given output variables. @param array $choices The array to flatten @param callable $value The callable for generating choice values @param array|null $choicesByValues The flattened choices indexed by the corresponding values @param array|null $keysByValues The original keys indexed by the corresponding values @param array|null $structuredValues The values indexed by the original keys
[ "Flattens", "an", "array", "into", "the", "given", "output", "variables", "." ]
6b5671b8c4d6298906ded768261b0a59845140fb
https://github.com/rollerworks/search-core/blob/6b5671b8c4d6298906ded768261b0a59845140fb/Extension/Core/ChoiceList/ArrayChoiceList.php#L180-L200
train
kambalabs/KmbPuppetDb
src/KmbPuppetDb/Proxy/NodeProxy.php
NodeProxy.getFacts
public function getFacts() { if ($this->facts === null) { $this->setFacts($this->nodeService->getNodeFacts($this->getName())); } return $this->facts; }
php
public function getFacts() { if ($this->facts === null) { $this->setFacts($this->nodeService->getNodeFacts($this->getName())); } return $this->facts; }
[ "public", "function", "getFacts", "(", ")", "{", "if", "(", "$", "this", "->", "facts", "===", "null", ")", "{", "$", "this", "->", "setFacts", "(", "$", "this", "->", "nodeService", "->", "getNodeFacts", "(", "$", "this", "->", "getName", "(", ")", ")", ")", ";", "}", "return", "$", "this", "->", "facts", ";", "}" ]
Get facts. @return array
[ "Get", "facts", "." ]
df56a275cf00f4402cf121a2e99149168f1f8b2d
https://github.com/kambalabs/KmbPuppetDb/blob/df56a275cf00f4402cf121a2e99149168f1f8b2d/src/KmbPuppetDb/Proxy/NodeProxy.php#L164-L170
train
kambalabs/KmbPuppetDb
src/KmbPuppetDb/Proxy/NodeProxy.php
NodeProxy.hasFact
public function hasFact($name) { if ($this->hasFacts() && array_key_exists($name, $this->facts)) { return true; } return false; }
php
public function hasFact($name) { if ($this->hasFacts() && array_key_exists($name, $this->facts)) { return true; } return false; }
[ "public", "function", "hasFact", "(", "$", "name", ")", "{", "if", "(", "$", "this", "->", "hasFacts", "(", ")", "&&", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "facts", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Determine if the node has the specified fact. @param string $name @return bool
[ "Determine", "if", "the", "node", "has", "the", "specified", "fact", "." ]
df56a275cf00f4402cf121a2e99149168f1f8b2d
https://github.com/kambalabs/KmbPuppetDb/blob/df56a275cf00f4402cf121a2e99149168f1f8b2d/src/KmbPuppetDb/Proxy/NodeProxy.php#L186-L192
train
covex-nn/JooS_Stream
src/JooS/Stream/Wrapper/FS/Changes.php
Wrapper_FS_Changes.get
public function get($path) { $entity = null; $name = null; $subtree = $this->subtree($path, $name); if (!is_null($subtree) && isset($subtree->_ownData[$name])) { $entity = $subtree->_ownData[$name]; } return $entity; }
php
public function get($path) { $entity = null; $name = null; $subtree = $this->subtree($path, $name); if (!is_null($subtree) && isset($subtree->_ownData[$name])) { $entity = $subtree->_ownData[$name]; } return $entity; }
[ "public", "function", "get", "(", "$", "path", ")", "{", "$", "entity", "=", "null", ";", "$", "name", "=", "null", ";", "$", "subtree", "=", "$", "this", "->", "subtree", "(", "$", "path", ",", "$", "name", ")", ";", "if", "(", "!", "is_null", "(", "$", "subtree", ")", "&&", "isset", "(", "$", "subtree", "->", "_ownData", "[", "$", "name", "]", ")", ")", "{", "$", "entity", "=", "$", "subtree", "->", "_ownData", "[", "$", "name", "]", ";", "}", "return", "$", "entity", ";", "}" ]
Return stream entiry @param string $path Path @return Entity_Interface
[ "Return", "stream", "entiry" ]
e9841b804190a9f624b9e44caa0af7a18f3816d1
https://github.com/covex-nn/JooS_Stream/blob/e9841b804190a9f624b9e44caa0af7a18f3816d1/src/JooS/Stream/Wrapper/FS/Changes.php#L43-L54
train
covex-nn/JooS_Stream
src/JooS/Stream/Wrapper/FS/Changes.php
Wrapper_FS_Changes.add
public function add($path, Entity_Interface $entity) { $result = false; if (strlen($path)) { $name = null; $subtree = $this->subtree($path, $name, true); $subtree->_ownData[$name] = $entity; $result = true; } return $result; }
php
public function add($path, Entity_Interface $entity) { $result = false; if (strlen($path)) { $name = null; $subtree = $this->subtree($path, $name, true); $subtree->_ownData[$name] = $entity; $result = true; } return $result; }
[ "public", "function", "add", "(", "$", "path", ",", "Entity_Interface", "$", "entity", ")", "{", "$", "result", "=", "false", ";", "if", "(", "strlen", "(", "$", "path", ")", ")", "{", "$", "name", "=", "null", ";", "$", "subtree", "=", "$", "this", "->", "subtree", "(", "$", "path", ",", "$", "name", ",", "true", ")", ";", "$", "subtree", "->", "_ownData", "[", "$", "name", "]", "=", "$", "entity", ";", "$", "result", "=", "true", ";", "}", "return", "$", "result", ";", "}" ]
Add stream entity to changes array @param string $path Path @param Entity_Interface $entity Stream entity @return boolean
[ "Add", "stream", "entity", "to", "changes", "array" ]
e9841b804190a9f624b9e44caa0af7a18f3816d1
https://github.com/covex-nn/JooS_Stream/blob/e9841b804190a9f624b9e44caa0af7a18f3816d1/src/JooS/Stream/Wrapper/FS/Changes.php#L64-L77
train
covex-nn/JooS_Stream
src/JooS/Stream/Wrapper/FS/Changes.php
Wrapper_FS_Changes.delete
public function delete($path) { $result = false; $parts = $this->split($path); $name = array_shift($parts); if (!sizeof($parts)) { if (isset($this->_ownData[$name])) { unset($this->_ownData[$name]); $result = true; } } elseif (isset($this->_subTrees[$name])) { $subtree = $this->_subTrees[$name]; /* @var $subtree Wrapper_FS_Changes */ $result = $subtree->delete($parts); if ($result && !$subtree->count()) { unset($this->_subTrees[$name]); } } return $result; }
php
public function delete($path) { $result = false; $parts = $this->split($path); $name = array_shift($parts); if (!sizeof($parts)) { if (isset($this->_ownData[$name])) { unset($this->_ownData[$name]); $result = true; } } elseif (isset($this->_subTrees[$name])) { $subtree = $this->_subTrees[$name]; /* @var $subtree Wrapper_FS_Changes */ $result = $subtree->delete($parts); if ($result && !$subtree->count()) { unset($this->_subTrees[$name]); } } return $result; }
[ "public", "function", "delete", "(", "$", "path", ")", "{", "$", "result", "=", "false", ";", "$", "parts", "=", "$", "this", "->", "split", "(", "$", "path", ")", ";", "$", "name", "=", "array_shift", "(", "$", "parts", ")", ";", "if", "(", "!", "sizeof", "(", "$", "parts", ")", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_ownData", "[", "$", "name", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "_ownData", "[", "$", "name", "]", ")", ";", "$", "result", "=", "true", ";", "}", "}", "elseif", "(", "isset", "(", "$", "this", "->", "_subTrees", "[", "$", "name", "]", ")", ")", "{", "$", "subtree", "=", "$", "this", "->", "_subTrees", "[", "$", "name", "]", ";", "/* @var $subtree Wrapper_FS_Changes */", "$", "result", "=", "$", "subtree", "->", "delete", "(", "$", "parts", ")", ";", "if", "(", "$", "result", "&&", "!", "$", "subtree", "->", "count", "(", ")", ")", "{", "unset", "(", "$", "this", "->", "_subTrees", "[", "$", "name", "]", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
Delete stream entity from array @param string $path Path @return boolean
[ "Delete", "stream", "entity", "from", "array" ]
e9841b804190a9f624b9e44caa0af7a18f3816d1
https://github.com/covex-nn/JooS_Stream/blob/e9841b804190a9f624b9e44caa0af7a18f3816d1/src/JooS/Stream/Wrapper/FS/Changes.php#L86-L108
train
covex-nn/JooS_Stream
src/JooS/Stream/Wrapper/FS/Changes.php
Wrapper_FS_Changes.own
public function own($path = "") { if ($path) { $parts = $this->split($path); $name = array_shift($parts); $own = array(); if (isset($this->_subTrees[$name])) { $subtree = $this->_subTrees[$name]; /* @var $subtree Wrapper_FS_Changes */ $this->_appendChildren( $own, $name, $subtree->own($parts) ); } } else { $own = $this->_ownData; } return $own; }
php
public function own($path = "") { if ($path) { $parts = $this->split($path); $name = array_shift($parts); $own = array(); if (isset($this->_subTrees[$name])) { $subtree = $this->_subTrees[$name]; /* @var $subtree Wrapper_FS_Changes */ $this->_appendChildren( $own, $name, $subtree->own($parts) ); } } else { $own = $this->_ownData; } return $own; }
[ "public", "function", "own", "(", "$", "path", "=", "\"\"", ")", "{", "if", "(", "$", "path", ")", "{", "$", "parts", "=", "$", "this", "->", "split", "(", "$", "path", ")", ";", "$", "name", "=", "array_shift", "(", "$", "parts", ")", ";", "$", "own", "=", "array", "(", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "_subTrees", "[", "$", "name", "]", ")", ")", "{", "$", "subtree", "=", "$", "this", "->", "_subTrees", "[", "$", "name", "]", ";", "/* @var $subtree Wrapper_FS_Changes */", "$", "this", "->", "_appendChildren", "(", "$", "own", ",", "$", "name", ",", "$", "subtree", "->", "own", "(", "$", "parts", ")", ")", ";", "}", "}", "else", "{", "$", "own", "=", "$", "this", "->", "_ownData", ";", "}", "return", "$", "own", ";", "}" ]
Return subtree's own changes @param string $path Path @return array
[ "Return", "subtree", "s", "own", "changes" ]
e9841b804190a9f624b9e44caa0af7a18f3816d1
https://github.com/covex-nn/JooS_Stream/blob/e9841b804190a9f624b9e44caa0af7a18f3816d1/src/JooS/Stream/Wrapper/FS/Changes.php#L142-L160
train
covex-nn/JooS_Stream
src/JooS/Stream/Wrapper/FS/Changes.php
Wrapper_FS_Changes._appendChildren
private function _appendChildren(array &$children, $name, array $_children) { foreach ($_children as $key => $value) { $children[$name . "/" . $key] = $value; } }
php
private function _appendChildren(array &$children, $name, array $_children) { foreach ($_children as $key => $value) { $children[$name . "/" . $key] = $value; } }
[ "private", "function", "_appendChildren", "(", "array", "&", "$", "children", ",", "$", "name", ",", "array", "$", "_children", ")", "{", "foreach", "(", "$", "_children", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "children", "[", "$", "name", ".", "\"/\"", ".", "$", "key", "]", "=", "$", "value", ";", "}", "}" ]
Add new children to array @param array &$children Children array @param string $name Current name @param array $_children Children of subtrees @return null
[ "Add", "new", "children", "to", "array" ]
e9841b804190a9f624b9e44caa0af7a18f3816d1
https://github.com/covex-nn/JooS_Stream/blob/e9841b804190a9f624b9e44caa0af7a18f3816d1/src/JooS/Stream/Wrapper/FS/Changes.php#L205-L210
train
covex-nn/JooS_Stream
src/JooS/Stream/Wrapper/FS/Changes.php
Wrapper_FS_Changes.subtree
public function subtree($path, &$name, $create = false) { $parts = $this->split($path); $_name = array_shift($parts); if (!sizeof($parts)) { $name = $_name; $subtree = $this; } else { $exists = isset($this->_subTrees[$_name]); if (!$exists && !$create) { $subtree = null; $name = null; } else { if (!$exists && $create) { $this->_subTrees[$_name] = new self(); } $subtree = $this->_subTrees[$_name]->subtree($parts, $name, $create); } } return $subtree; }
php
public function subtree($path, &$name, $create = false) { $parts = $this->split($path); $_name = array_shift($parts); if (!sizeof($parts)) { $name = $_name; $subtree = $this; } else { $exists = isset($this->_subTrees[$_name]); if (!$exists && !$create) { $subtree = null; $name = null; } else { if (!$exists && $create) { $this->_subTrees[$_name] = new self(); } $subtree = $this->_subTrees[$_name]->subtree($parts, $name, $create); } } return $subtree; }
[ "public", "function", "subtree", "(", "$", "path", ",", "&", "$", "name", ",", "$", "create", "=", "false", ")", "{", "$", "parts", "=", "$", "this", "->", "split", "(", "$", "path", ")", ";", "$", "_name", "=", "array_shift", "(", "$", "parts", ")", ";", "if", "(", "!", "sizeof", "(", "$", "parts", ")", ")", "{", "$", "name", "=", "$", "_name", ";", "$", "subtree", "=", "$", "this", ";", "}", "else", "{", "$", "exists", "=", "isset", "(", "$", "this", "->", "_subTrees", "[", "$", "_name", "]", ")", ";", "if", "(", "!", "$", "exists", "&&", "!", "$", "create", ")", "{", "$", "subtree", "=", "null", ";", "$", "name", "=", "null", ";", "}", "else", "{", "if", "(", "!", "$", "exists", "&&", "$", "create", ")", "{", "$", "this", "->", "_subTrees", "[", "$", "_name", "]", "=", "new", "self", "(", ")", ";", "}", "$", "subtree", "=", "$", "this", "->", "_subTrees", "[", "$", "_name", "]", "->", "subtree", "(", "$", "parts", ",", "$", "name", ",", "$", "create", ")", ";", "}", "}", "return", "$", "subtree", ";", "}" ]
Return subtree by path @param string $path Path @param string &$name Name of new element @param boolean $create Auto create subtree ? @return Wrapper_FS_Changes
[ "Return", "subtree", "by", "path" ]
e9841b804190a9f624b9e44caa0af7a18f3816d1
https://github.com/covex-nn/JooS_Stream/blob/e9841b804190a9f624b9e44caa0af7a18f3816d1/src/JooS/Stream/Wrapper/FS/Changes.php#L221-L244
train
covex-nn/JooS_Stream
src/JooS/Stream/Wrapper/FS/Changes.php
Wrapper_FS_Changes.split
protected function split($path) { if (is_array($path)) { $parts = $path; } else { $parts = explode("/", $path); } return $parts; }
php
protected function split($path) { if (is_array($path)) { $parts = $path; } else { $parts = explode("/", $path); } return $parts; }
[ "protected", "function", "split", "(", "$", "path", ")", "{", "if", "(", "is_array", "(", "$", "path", ")", ")", "{", "$", "parts", "=", "$", "path", ";", "}", "else", "{", "$", "parts", "=", "explode", "(", "\"/\"", ",", "$", "path", ")", ";", "}", "return", "$", "parts", ";", "}" ]
Split path into dir names @param string $path Path @return array
[ "Split", "path", "into", "dir", "names" ]
e9841b804190a9f624b9e44caa0af7a18f3816d1
https://github.com/covex-nn/JooS_Stream/blob/e9841b804190a9f624b9e44caa0af7a18f3816d1/src/JooS/Stream/Wrapper/FS/Changes.php#L263-L271
train
eureka-framework/component-orm
src/Orm/DataMapper/DataAbstract.php
DataAbstract.isUpdated
public function isUpdated($property = null) { if (null === $property) { return (count($this->updated) > 0); } return (isset($this->updated[$property]) && $this->updated[$property] === true); }
php
public function isUpdated($property = null) { if (null === $property) { return (count($this->updated) > 0); } return (isset($this->updated[$property]) && $this->updated[$property] === true); }
[ "public", "function", "isUpdated", "(", "$", "property", "=", "null", ")", "{", "if", "(", "null", "===", "$", "property", ")", "{", "return", "(", "count", "(", "$", "this", "->", "updated", ")", ">", "0", ")", ";", "}", "return", "(", "isset", "(", "$", "this", "->", "updated", "[", "$", "property", "]", ")", "&&", "$", "this", "->", "updated", "[", "$", "property", "]", "===", "true", ")", ";", "}" ]
If at least one data has been updated. If property name is specified, check only property. @param string $property @return bool
[ "If", "at", "least", "one", "data", "has", "been", "updated", ".", "If", "property", "name", "is", "specified", "check", "only", "property", "." ]
bce48121d26c4e923534f9dc70da597634184316
https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/DataMapper/DataAbstract.php#L116-L123
train
eureka-framework/component-orm
src/Orm/DataMapper/DataAbstract.php
DataAbstract.initDependencyContainer
public function initDependencyContainer(Dependency\ContainerInterface $container = null) { if (null === $container) { $container = Dependency\Container::getInstance(); } $this->dependencyContainer = $container; return $this; }
php
public function initDependencyContainer(Dependency\ContainerInterface $container = null) { if (null === $container) { $container = Dependency\Container::getInstance(); } $this->dependencyContainer = $container; return $this; }
[ "public", "function", "initDependencyContainer", "(", "Dependency", "\\", "ContainerInterface", "$", "container", "=", "null", ")", "{", "if", "(", "null", "===", "$", "container", ")", "{", "$", "container", "=", "Dependency", "\\", "Container", "::", "getInstance", "(", ")", ";", "}", "$", "this", "->", "dependencyContainer", "=", "$", "container", ";", "return", "$", "this", ";", "}" ]
Initialize dependency container. @param Dependency\ContainerInterface $container @return self
[ "Initialize", "dependency", "container", "." ]
bce48121d26c4e923534f9dc70da597634184316
https://github.com/eureka-framework/component-orm/blob/bce48121d26c4e923534f9dc70da597634184316/src/Orm/DataMapper/DataAbstract.php#L143-L152
train
mtils/cmsable
src/Cmsable/Mail/Mailer.php
Mailer.overwrite
public function overwrite($key, $value=null) { if (!is_array($key)) { $this->overwrittenData[$key] = $value; return $this; } foreach ($key as $k=>$v) { $this->overwrite($k, $v); } return $this; }
php
public function overwrite($key, $value=null) { if (!is_array($key)) { $this->overwrittenData[$key] = $value; return $this; } foreach ($key as $k=>$v) { $this->overwrite($k, $v); } return $this; }
[ "public", "function", "overwrite", "(", "$", "key", ",", "$", "value", "=", "null", ")", "{", "if", "(", "!", "is_array", "(", "$", "key", ")", ")", "{", "$", "this", "->", "overwrittenData", "[", "$", "key", "]", "=", "$", "value", ";", "return", "$", "this", ";", "}", "foreach", "(", "$", "key", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "this", "->", "overwrite", "(", "$", "k", ",", "$", "v", ")", ";", "}", "return", "$", "this", ";", "}" ]
Overwrite one or more view variables @param string|array $key @param mixed $value (optional) @return self
[ "Overwrite", "one", "or", "more", "view", "variables" ]
03ae84ee3c7d46146f2a1cf687e5c29d6de4286d
https://github.com/mtils/cmsable/blob/03ae84ee3c7d46146f2a1cf687e5c29d6de4286d/src/Cmsable/Mail/Mailer.php#L195-L207
train
mtils/cmsable
src/Cmsable/Mail/Mailer.php
Mailer.finalRecipients
protected function finalRecipients($passedTo) { if (!$this->overwrittenTo) { return $passedTo; } $overwrittenTo = $this->overwrittenTo; $this->overwrittenTo = []; return $overwrittenTo; }
php
protected function finalRecipients($passedTo) { if (!$this->overwrittenTo) { return $passedTo; } $overwrittenTo = $this->overwrittenTo; $this->overwrittenTo = []; return $overwrittenTo; }
[ "protected", "function", "finalRecipients", "(", "$", "passedTo", ")", "{", "if", "(", "!", "$", "this", "->", "overwrittenTo", ")", "{", "return", "$", "passedTo", ";", "}", "$", "overwrittenTo", "=", "$", "this", "->", "overwrittenTo", ";", "$", "this", "->", "overwrittenTo", "=", "[", "]", ";", "return", "$", "overwrittenTo", ";", "}" ]
Returns only the overwritten recipients or if non set the passed ones @param array $passedTo @return array
[ "Returns", "only", "the", "overwritten", "recipients", "or", "if", "non", "set", "the", "passed", "ones" ]
03ae84ee3c7d46146f2a1cf687e5c29d6de4286d
https://github.com/mtils/cmsable/blob/03ae84ee3c7d46146f2a1cf687e5c29d6de4286d/src/Cmsable/Mail/Mailer.php#L254-L263
train
mtils/cmsable
src/Cmsable/Mail/Mailer.php
Mailer.finalView
protected function finalView($passedView) { if (!$this->overwrittenView ) { return $passedView; } $overwrittenView = $this->overwrittenView; $this->overwrittenView = ''; if (!is_array($overwrittenView) && !is_array($passedView)) { return $overwrittenView; } if (!is_array($overwrittenView) || !is_array($passedView)) { throw new RuntimeException("Overwritten view and passed can not be merged"); } foreach ($overwrittenView as $key=>$value) { $passedView[$key] = $value; } return $passedView; }
php
protected function finalView($passedView) { if (!$this->overwrittenView ) { return $passedView; } $overwrittenView = $this->overwrittenView; $this->overwrittenView = ''; if (!is_array($overwrittenView) && !is_array($passedView)) { return $overwrittenView; } if (!is_array($overwrittenView) || !is_array($passedView)) { throw new RuntimeException("Overwritten view and passed can not be merged"); } foreach ($overwrittenView as $key=>$value) { $passedView[$key] = $value; } return $passedView; }
[ "protected", "function", "finalView", "(", "$", "passedView", ")", "{", "if", "(", "!", "$", "this", "->", "overwrittenView", ")", "{", "return", "$", "passedView", ";", "}", "$", "overwrittenView", "=", "$", "this", "->", "overwrittenView", ";", "$", "this", "->", "overwrittenView", "=", "''", ";", "if", "(", "!", "is_array", "(", "$", "overwrittenView", ")", "&&", "!", "is_array", "(", "$", "passedView", ")", ")", "{", "return", "$", "overwrittenView", ";", "}", "if", "(", "!", "is_array", "(", "$", "overwrittenView", ")", "||", "!", "is_array", "(", "$", "passedView", ")", ")", "{", "throw", "new", "RuntimeException", "(", "\"Overwritten view and passed can not be merged\"", ")", ";", "}", "foreach", "(", "$", "overwrittenView", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "passedView", "[", "$", "key", "]", "=", "$", "value", ";", "}", "return", "$", "passedView", ";", "}" ]
Returns the overwritten view if one set, otherwise the passed one @param string|array $passedView @return string|array
[ "Returns", "the", "overwritten", "view", "if", "one", "set", "otherwise", "the", "passed", "one" ]
03ae84ee3c7d46146f2a1cf687e5c29d6de4286d
https://github.com/mtils/cmsable/blob/03ae84ee3c7d46146f2a1cf687e5c29d6de4286d/src/Cmsable/Mail/Mailer.php#L271-L295
train
mtils/cmsable
src/Cmsable/Mail/Mailer.php
Mailer.finalData
protected function finalData($passedData) { $overwrittenData = $this->overwrittenData; $this->overwrittenData = []; foreach ($overwrittenData as $key=>$value) { $passedData[$key] = $value; } return $passedData; }
php
protected function finalData($passedData) { $overwrittenData = $this->overwrittenData; $this->overwrittenData = []; foreach ($overwrittenData as $key=>$value) { $passedData[$key] = $value; } return $passedData; }
[ "protected", "function", "finalData", "(", "$", "passedData", ")", "{", "$", "overwrittenData", "=", "$", "this", "->", "overwrittenData", ";", "$", "this", "->", "overwrittenData", "=", "[", "]", ";", "foreach", "(", "$", "overwrittenData", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "passedData", "[", "$", "key", "]", "=", "$", "value", ";", "}", "return", "$", "passedData", ";", "}" ]
Merges the passed view data with the assigned one @param array $passedData @return array
[ "Merges", "the", "passed", "view", "data", "with", "the", "assigned", "one" ]
03ae84ee3c7d46146f2a1cf687e5c29d6de4286d
https://github.com/mtils/cmsable/blob/03ae84ee3c7d46146f2a1cf687e5c29d6de4286d/src/Cmsable/Mail/Mailer.php#L303-L315
train
mtils/cmsable
src/Cmsable/Mail/Mailer.php
Mailer.flushRecipients
protected function flushRecipients($closure) { $recipients = (array)$this->temporaryTo; $this->temporaryTo = null; if(!$recipients && !is_callable($closure)){ throw new BadMethodCallException('Recipient not determinable: Neither a recipient was set by to() nor a callable was passed'); } return $recipients; }
php
protected function flushRecipients($closure) { $recipients = (array)$this->temporaryTo; $this->temporaryTo = null; if(!$recipients && !is_callable($closure)){ throw new BadMethodCallException('Recipient not determinable: Neither a recipient was set by to() nor a callable was passed'); } return $recipients; }
[ "protected", "function", "flushRecipients", "(", "$", "closure", ")", "{", "$", "recipients", "=", "(", "array", ")", "$", "this", "->", "temporaryTo", ";", "$", "this", "->", "temporaryTo", "=", "null", ";", "if", "(", "!", "$", "recipients", "&&", "!", "is_callable", "(", "$", "closure", ")", ")", "{", "throw", "new", "BadMethodCallException", "(", "'Recipient not determinable: Neither a recipient was set by to() nor a callable was passed'", ")", ";", "}", "return", "$", "recipients", ";", "}" ]
Returns the recipients and clears em @param callable $closure @return array
[ "Returns", "the", "recipients", "and", "clears", "em" ]
03ae84ee3c7d46146f2a1cf687e5c29d6de4286d
https://github.com/mtils/cmsable/blob/03ae84ee3c7d46146f2a1cf687e5c29d6de4286d/src/Cmsable/Mail/Mailer.php#L323-L333
train
mtils/cmsable
src/Cmsable/Mail/Mailer.php
Mailer.createBuilder
protected function createBuilder(array $recipients, $data, $callback) { $messageBuilder = new MessageBuilder($recipients, $data, $callback); if ($developerTo = $this->config->get('mail.overwrite_to')) { $messageBuilder->setOverwriteTo($developerTo); } return $messageBuilder; }
php
protected function createBuilder(array $recipients, $data, $callback) { $messageBuilder = new MessageBuilder($recipients, $data, $callback); if ($developerTo = $this->config->get('mail.overwrite_to')) { $messageBuilder->setOverwriteTo($developerTo); } return $messageBuilder; }
[ "protected", "function", "createBuilder", "(", "array", "$", "recipients", ",", "$", "data", ",", "$", "callback", ")", "{", "$", "messageBuilder", "=", "new", "MessageBuilder", "(", "$", "recipients", ",", "$", "data", ",", "$", "callback", ")", ";", "if", "(", "$", "developerTo", "=", "$", "this", "->", "config", "->", "get", "(", "'mail.overwrite_to'", ")", ")", "{", "$", "messageBuilder", "->", "setOverwriteTo", "(", "$", "developerTo", ")", ";", "}", "return", "$", "messageBuilder", ";", "}" ]
Create the pseudo closure creator @param array $recipients @param array $data @param callable|null $callback @return \Cmsable\Mail\MessageBuilder
[ "Create", "the", "pseudo", "closure", "creator" ]
03ae84ee3c7d46146f2a1cf687e5c29d6de4286d
https://github.com/mtils/cmsable/blob/03ae84ee3c7d46146f2a1cf687e5c29d6de4286d/src/Cmsable/Mail/Mailer.php#L343-L352
train
mtils/cmsable
src/Cmsable/Mail/Mailer.php
Mailer.parseTexts
protected function parseTexts(array $data) { foreach ($this->parseKeys as $key) { if (!isset($data[$key]) || !is_string($data[$key])) { continue; } $data[$key] = $this->textParser->parse($data[$key], $data); } return $data; }
php
protected function parseTexts(array $data) { foreach ($this->parseKeys as $key) { if (!isset($data[$key]) || !is_string($data[$key])) { continue; } $data[$key] = $this->textParser->parse($data[$key], $data); } return $data; }
[ "protected", "function", "parseTexts", "(", "array", "$", "data", ")", "{", "foreach", "(", "$", "this", "->", "parseKeys", "as", "$", "key", ")", "{", "if", "(", "!", "isset", "(", "$", "data", "[", "$", "key", "]", ")", "||", "!", "is_string", "(", "$", "data", "[", "$", "key", "]", ")", ")", "{", "continue", ";", "}", "$", "data", "[", "$", "key", "]", "=", "$", "this", "->", "textParser", "->", "parse", "(", "$", "data", "[", "$", "key", "]", ",", "$", "data", ")", ";", "}", "return", "$", "data", ";", "}" ]
Parse all keys that have to be parsed by text parser @param array $data @return array
[ "Parse", "all", "keys", "that", "have", "to", "be", "parsed", "by", "text", "parser" ]
03ae84ee3c7d46146f2a1cf687e5c29d6de4286d
https://github.com/mtils/cmsable/blob/03ae84ee3c7d46146f2a1cf687e5c29d6de4286d/src/Cmsable/Mail/Mailer.php#L360-L373
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/caching/stores/MemcacheCacheStore.php
MemcacheCacheStore.getConnection
protected function getConnection() { if (empty($this->memcache)) { //ini_set('memcache.chunk_size', 32768); //ini_set('memcache.allow_failover', false); // default is usually true //ini_set('memcache.hash_strategy', 'consistent'); $this->memcache = new Memcache; // Add the servers if (!is_array($this->memcachedServers) || count($this->memcachedServers) < 1) throw new CacheException('At least one server must be specified.'); foreach ( $this->memcachedServers as $server ) { $options = array_merge(array('port' => 11211, 'persistent' => true, 'weight' => 1, 'timeout' => 1, 'retry_interval' => 15, 'status' => true, 'failure_callback' => null), array_change_key_case($server, CASE_LOWER)); $this->Logger->debug("Adding memcached server:\n"); $this->Logger->debug($options); // if(!array_key_exists('failure_callback', $options)) // $options['failure_callback'] = array(__CLASS__, '_failureCallback'); if ($this->memcache->addServer($options['host'], $options['port'], $options['persistent'], $options['weight'], $options['timeout'], $options['retry_interval'], $options['status'], $options['failure_callback']) === false) { throw new CacheException("Unable to add memcache server: {$options['host']}"); } } } return $this->memcache; }
php
protected function getConnection() { if (empty($this->memcache)) { //ini_set('memcache.chunk_size', 32768); //ini_set('memcache.allow_failover', false); // default is usually true //ini_set('memcache.hash_strategy', 'consistent'); $this->memcache = new Memcache; // Add the servers if (!is_array($this->memcachedServers) || count($this->memcachedServers) < 1) throw new CacheException('At least one server must be specified.'); foreach ( $this->memcachedServers as $server ) { $options = array_merge(array('port' => 11211, 'persistent' => true, 'weight' => 1, 'timeout' => 1, 'retry_interval' => 15, 'status' => true, 'failure_callback' => null), array_change_key_case($server, CASE_LOWER)); $this->Logger->debug("Adding memcached server:\n"); $this->Logger->debug($options); // if(!array_key_exists('failure_callback', $options)) // $options['failure_callback'] = array(__CLASS__, '_failureCallback'); if ($this->memcache->addServer($options['host'], $options['port'], $options['persistent'], $options['weight'], $options['timeout'], $options['retry_interval'], $options['status'], $options['failure_callback']) === false) { throw new CacheException("Unable to add memcache server: {$options['host']}"); } } } return $this->memcache; }
[ "protected", "function", "getConnection", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "memcache", ")", ")", "{", "//ini_set('memcache.chunk_size', 32768);", "//ini_set('memcache.allow_failover', false); // default is usually true", "//ini_set('memcache.hash_strategy', 'consistent');", "$", "this", "->", "memcache", "=", "new", "Memcache", ";", "// Add the servers", "if", "(", "!", "is_array", "(", "$", "this", "->", "memcachedServers", ")", "||", "count", "(", "$", "this", "->", "memcachedServers", ")", "<", "1", ")", "throw", "new", "CacheException", "(", "'At least one server must be specified.'", ")", ";", "foreach", "(", "$", "this", "->", "memcachedServers", "as", "$", "server", ")", "{", "$", "options", "=", "array_merge", "(", "array", "(", "'port'", "=>", "11211", ",", "'persistent'", "=>", "true", ",", "'weight'", "=>", "1", ",", "'timeout'", "=>", "1", ",", "'retry_interval'", "=>", "15", ",", "'status'", "=>", "true", ",", "'failure_callback'", "=>", "null", ")", ",", "array_change_key_case", "(", "$", "server", ",", "CASE_LOWER", ")", ")", ";", "$", "this", "->", "Logger", "->", "debug", "(", "\"Adding memcached server:\\n\"", ")", ";", "$", "this", "->", "Logger", "->", "debug", "(", "$", "options", ")", ";", "// if(!array_key_exists('failure_callback', $options))", "// $options['failure_callback'] = array(__CLASS__, '_failureCallback');", "if", "(", "$", "this", "->", "memcache", "->", "addServer", "(", "$", "options", "[", "'host'", "]", ",", "$", "options", "[", "'port'", "]", ",", "$", "options", "[", "'persistent'", "]", ",", "$", "options", "[", "'weight'", "]", ",", "$", "options", "[", "'timeout'", "]", ",", "$", "options", "[", "'retry_interval'", "]", ",", "$", "options", "[", "'status'", "]", ",", "$", "options", "[", "'failure_callback'", "]", ")", "===", "false", ")", "{", "throw", "new", "CacheException", "(", "\"Unable to add memcache server: {$options['host']}\"", ")", ";", "}", "}", "}", "return", "$", "this", "->", "memcache", ";", "}" ]
Returns a connection to the memcached server @return Memcache an active Memcache object
[ "Returns", "a", "connection", "to", "the", "memcached", "server" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/caching/stores/MemcacheCacheStore.php#L143-L182
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/caching/stores/MemcacheCacheStore.php
MemcacheCacheStore.getStats
public function getStats() { if (!$this->enabled) return array(); $stats = @$this->getConnection()->getStats(); $this->Logger->debug('Retrieved Stats'); $this->Logger->debug($stats); return $stats; }
php
public function getStats() { if (!$this->enabled) return array(); $stats = @$this->getConnection()->getStats(); $this->Logger->debug('Retrieved Stats'); $this->Logger->debug($stats); return $stats; }
[ "public", "function", "getStats", "(", ")", "{", "if", "(", "!", "$", "this", "->", "enabled", ")", "return", "array", "(", ")", ";", "$", "stats", "=", "@", "$", "this", "->", "getConnection", "(", ")", "->", "getStats", "(", ")", ";", "$", "this", "->", "Logger", "->", "debug", "(", "'Retrieved Stats'", ")", ";", "$", "this", "->", "Logger", "->", "debug", "(", "$", "stats", ")", ";", "return", "$", "stats", ";", "}" ]
Implementation specific array of statistics @return array An associative array of statistics, determined by the implementation
[ "Implementation", "specific", "array", "of", "statistics" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/caching/stores/MemcacheCacheStore.php#L434-L445
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/caching/stores/MemcacheCacheStore.php
MemcacheCacheStore.increment
public function increment($key, $step = 1) { if (!$this->enabled) return false; $has_replaced = $has_set = false; try { // Store the cache object $nKey = $this->key($key); $has_replaced = @$this->getConnection()->add($nKey, $step, 0); if (!$has_replaced) { $has_set = @$this->getConnection()->increment($nKey, $step); } } catch (Exception $e) { throw new CacheException($e->getMessage(), $e->getCode()); } $this->Logger->debug("". (($has_replaced || $has_set) ? "Successfully" : "Failed to") . " increment key '{$key}'\n"); // $this->Logger->debug($data); return $has_replaced ? $step : $has_set; }
php
public function increment($key, $step = 1) { if (!$this->enabled) return false; $has_replaced = $has_set = false; try { // Store the cache object $nKey = $this->key($key); $has_replaced = @$this->getConnection()->add($nKey, $step, 0); if (!$has_replaced) { $has_set = @$this->getConnection()->increment($nKey, $step); } } catch (Exception $e) { throw new CacheException($e->getMessage(), $e->getCode()); } $this->Logger->debug("". (($has_replaced || $has_set) ? "Successfully" : "Failed to") . " increment key '{$key}'\n"); // $this->Logger->debug($data); return $has_replaced ? $step : $has_set; }
[ "public", "function", "increment", "(", "$", "key", ",", "$", "step", "=", "1", ")", "{", "if", "(", "!", "$", "this", "->", "enabled", ")", "return", "false", ";", "$", "has_replaced", "=", "$", "has_set", "=", "false", ";", "try", "{", "// Store the cache object", "$", "nKey", "=", "$", "this", "->", "key", "(", "$", "key", ")", ";", "$", "has_replaced", "=", "@", "$", "this", "->", "getConnection", "(", ")", "->", "add", "(", "$", "nKey", ",", "$", "step", ",", "0", ")", ";", "if", "(", "!", "$", "has_replaced", ")", "{", "$", "has_set", "=", "@", "$", "this", "->", "getConnection", "(", ")", "->", "increment", "(", "$", "nKey", ",", "$", "step", ")", ";", "}", "}", "catch", "(", "Exception", "$", "e", ")", "{", "throw", "new", "CacheException", "(", "$", "e", "->", "getMessage", "(", ")", ",", "$", "e", "->", "getCode", "(", ")", ")", ";", "}", "$", "this", "->", "Logger", "->", "debug", "(", "\"\"", ".", "(", "(", "$", "has_replaced", "||", "$", "has_set", ")", "?", "\"Successfully\"", ":", "\"Failed to\"", ")", ".", "\" increment key '{$key}'\\n\"", ")", ";", "// $this->Logger->debug($data);", "return", "$", "has_replaced", "?", "$", "step", ":", "$", "has_set", ";", "}" ]
Increment a value in the cache store @param string $key Cache key associated to the data @param int $step Number to increment by @return int New value on success or FALSE on failure @throws CacheException
[ "Increment", "a", "value", "in", "the", "cache", "store" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/caching/stores/MemcacheCacheStore.php#L494-L516
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/caching/stores/MemcacheCacheStore.php
MemcacheCacheStore.decrement
public function decrement($key, $step = 1) { if (!$this->enabled) return false; $has_replaced = $has_set = false; try { // Store the cache object $nKey = $this->key($key); $has_set = @$this->getConnection()->decrement($nKey, $step); } catch (Exception $e) { throw new CacheException($e->getMessage(), $e->getCode()); } $this->Logger->debug("". (($has_replaced || $has_set) ? "Successfully" : "Failed to") . " decrement key '{$key}'\n"); // $this->Logger->debug($data); return $has_set; }
php
public function decrement($key, $step = 1) { if (!$this->enabled) return false; $has_replaced = $has_set = false; try { // Store the cache object $nKey = $this->key($key); $has_set = @$this->getConnection()->decrement($nKey, $step); } catch (Exception $e) { throw new CacheException($e->getMessage(), $e->getCode()); } $this->Logger->debug("". (($has_replaced || $has_set) ? "Successfully" : "Failed to") . " decrement key '{$key}'\n"); // $this->Logger->debug($data); return $has_set; }
[ "public", "function", "decrement", "(", "$", "key", ",", "$", "step", "=", "1", ")", "{", "if", "(", "!", "$", "this", "->", "enabled", ")", "return", "false", ";", "$", "has_replaced", "=", "$", "has_set", "=", "false", ";", "try", "{", "// Store the cache object", "$", "nKey", "=", "$", "this", "->", "key", "(", "$", "key", ")", ";", "$", "has_set", "=", "@", "$", "this", "->", "getConnection", "(", ")", "->", "decrement", "(", "$", "nKey", ",", "$", "step", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "throw", "new", "CacheException", "(", "$", "e", "->", "getMessage", "(", ")", ",", "$", "e", "->", "getCode", "(", ")", ")", ";", "}", "$", "this", "->", "Logger", "->", "debug", "(", "\"\"", ".", "(", "(", "$", "has_replaced", "||", "$", "has_set", ")", "?", "\"Successfully\"", ":", "\"Failed to\"", ")", ".", "\" decrement key '{$key}'\\n\"", ")", ";", "// $this->Logger->debug($data);", "return", "$", "has_set", ";", "}" ]
Decrement a value in the cache store @param string $key Cache key associated to the data @param int $step Number to decrement by @return int New value on success or FALSE on failure @throws CacheException
[ "Decrement", "a", "value", "in", "the", "cache", "store" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/caching/stores/MemcacheCacheStore.php#L527-L547
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/caching/stores/MemcacheCacheStore.php
MemcacheCacheStore.getIncrement
public function getIncrement($key) { if (!$this->enabled) return false; return @$this->getConnection()->get($this->key($key)); }
php
public function getIncrement($key) { if (!$this->enabled) return false; return @$this->getConnection()->get($this->key($key)); }
[ "public", "function", "getIncrement", "(", "$", "key", ")", "{", "if", "(", "!", "$", "this", "->", "enabled", ")", "return", "false", ";", "return", "@", "$", "this", "->", "getConnection", "(", ")", "->", "get", "(", "$", "this", "->", "key", "(", "$", "key", ")", ")", ";", "}" ]
Get incremented value in the cache store @param string $key Cache key associated to the data @return int Stored value on success or FALSE on failure @throws CacheException
[ "Get", "incremented", "value", "in", "the", "cache", "store" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/caching/stores/MemcacheCacheStore.php#L558-L565
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/caching/stores/MemcacheCacheStore.php
MemcacheCacheStore.add
public function add($key, $data, $ttl) { if (!$this->enabled) return true; try { $data = $this->storageFormat($key, $data, $ttl); $nKey = $this->key($key); // Store the cache object $ret = @$this->getConnection()->add($nKey, $data, $this->flags, $ttl); $this->Logger->debug("". (($ret) ? "Successful" : "Failed to") . " add '{$key}'\n"); return $ret; } catch (Exception $e) { throw new CacheException($e->getMessage(), $e->getCode()); } }
php
public function add($key, $data, $ttl) { if (!$this->enabled) return true; try { $data = $this->storageFormat($key, $data, $ttl); $nKey = $this->key($key); // Store the cache object $ret = @$this->getConnection()->add($nKey, $data, $this->flags, $ttl); $this->Logger->debug("". (($ret) ? "Successful" : "Failed to") . " add '{$key}'\n"); return $ret; } catch (Exception $e) { throw new CacheException($e->getMessage(), $e->getCode()); } }
[ "public", "function", "add", "(", "$", "key", ",", "$", "data", ",", "$", "ttl", ")", "{", "if", "(", "!", "$", "this", "->", "enabled", ")", "return", "true", ";", "try", "{", "$", "data", "=", "$", "this", "->", "storageFormat", "(", "$", "key", ",", "$", "data", ",", "$", "ttl", ")", ";", "$", "nKey", "=", "$", "this", "->", "key", "(", "$", "key", ")", ";", "// Store the cache object", "$", "ret", "=", "@", "$", "this", "->", "getConnection", "(", ")", "->", "add", "(", "$", "nKey", ",", "$", "data", ",", "$", "this", "->", "flags", ",", "$", "ttl", ")", ";", "$", "this", "->", "Logger", "->", "debug", "(", "\"\"", ".", "(", "(", "$", "ret", ")", "?", "\"Successful\"", ":", "\"Failed to\"", ")", ".", "\" add '{$key}'\\n\"", ")", ";", "return", "$", "ret", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "throw", "new", "CacheException", "(", "$", "e", "->", "getMessage", "(", ")", ",", "$", "e", "->", "getCode", "(", ")", ")", ";", "}", "}" ]
Stores data into the cache store by key, with a given timeout in seconds UNLESS an entry already exists under that key. The implementation must support native serialization of objects and arrays so that the caller does not need to serialize manually. @param string $key Cache key associated to the data @param mixed $data Data to be stored in the cache store. Only serializable data types or objects can be stored in the cache. @param int $ttl Time-to-live or duration in seconds the value is retained in the cache store before expiring or becoming invalid. If set to 0, the value will not expire. @return boolean True upon success, false on failure
[ "Stores", "data", "into", "the", "cache", "store", "by", "key", "with", "a", "given", "timeout", "in", "seconds", "UNLESS", "an", "entry", "already", "exists", "under", "that", "key", ".", "The", "implementation", "must", "support", "native", "serialization", "of", "objects", "and", "arrays", "so", "that", "the", "caller", "does", "not", "need", "to", "serialize", "manually", "." ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/caching/stores/MemcacheCacheStore.php#L582-L601
train
wb-crowdfusion/crowdfusion
system/core/classes/mvc/router/Router.php
Router.route
public function route() { $this->Logger->debug("Request: {$this->Request->getFullURL()}"); $uri = $this->Request->getAdjustedRequestURI(); // $uri = $this->sanitizeURI($uri); $this->Logger->debug("Routing URI: {$uri}"); $result = array(); $qs = array_merge($_POST, $_GET); $routes = $this->routeService->findAll(); // $regex = $this->compoundRegex(array_keys($routes)); // error_log($regex); // // if (! preg_match($regex, $uri, $matches)) { // $match = ''; // error_log('no match'); // exit; // return false; // } // $match = $matches[0]; // error_log('match = '.$match); // exit; $this->Logger->debug("Testing Routes\n"); foreach ((array)$routes as $test_uri => $nvps) { $this->Logger->debug("{$test_uri}"); $m = null; $re = str_replace('/', '\/', $test_uri); $match = preg_match('/^' . $re . '$/i', $uri, $m); if ($match) { if (!empty($nvps) && is_array($nvps)) { foreach ($nvps as $name => $value) { foreach ($m as $n => $v) { $value = str_replace('$'.$n, $v, $value); } foreach ($qs as $n => $v) { if (is_scalar($v)) $value = str_replace('$'.$n, $v, $value); } $varparts = null; if (preg_match("/(.+)\[(.+)\]/", $name, $varparts)) { $result[$varparts[1]][$varparts[2]] = $value; } else { $result[$name] = $value; } } } foreach ($m as $n => $v) if (is_int($n)) unset($m[$n]); $result = array_merge($m, $result); $this->Logger->debug('Routing result:'); $this->Logger->debug($result); return $result; } } $this->checkRedirects(); $this->Logger->debug("No routes matched."); return null; }
php
public function route() { $this->Logger->debug("Request: {$this->Request->getFullURL()}"); $uri = $this->Request->getAdjustedRequestURI(); // $uri = $this->sanitizeURI($uri); $this->Logger->debug("Routing URI: {$uri}"); $result = array(); $qs = array_merge($_POST, $_GET); $routes = $this->routeService->findAll(); // $regex = $this->compoundRegex(array_keys($routes)); // error_log($regex); // // if (! preg_match($regex, $uri, $matches)) { // $match = ''; // error_log('no match'); // exit; // return false; // } // $match = $matches[0]; // error_log('match = '.$match); // exit; $this->Logger->debug("Testing Routes\n"); foreach ((array)$routes as $test_uri => $nvps) { $this->Logger->debug("{$test_uri}"); $m = null; $re = str_replace('/', '\/', $test_uri); $match = preg_match('/^' . $re . '$/i', $uri, $m); if ($match) { if (!empty($nvps) && is_array($nvps)) { foreach ($nvps as $name => $value) { foreach ($m as $n => $v) { $value = str_replace('$'.$n, $v, $value); } foreach ($qs as $n => $v) { if (is_scalar($v)) $value = str_replace('$'.$n, $v, $value); } $varparts = null; if (preg_match("/(.+)\[(.+)\]/", $name, $varparts)) { $result[$varparts[1]][$varparts[2]] = $value; } else { $result[$name] = $value; } } } foreach ($m as $n => $v) if (is_int($n)) unset($m[$n]); $result = array_merge($m, $result); $this->Logger->debug('Routing result:'); $this->Logger->debug($result); return $result; } } $this->checkRedirects(); $this->Logger->debug("No routes matched."); return null; }
[ "public", "function", "route", "(", ")", "{", "$", "this", "->", "Logger", "->", "debug", "(", "\"Request: {$this->Request->getFullURL()}\"", ")", ";", "$", "uri", "=", "$", "this", "->", "Request", "->", "getAdjustedRequestURI", "(", ")", ";", "// $uri = $this->sanitizeURI($uri);", "$", "this", "->", "Logger", "->", "debug", "(", "\"Routing URI: {$uri}\"", ")", ";", "$", "result", "=", "array", "(", ")", ";", "$", "qs", "=", "array_merge", "(", "$", "_POST", ",", "$", "_GET", ")", ";", "$", "routes", "=", "$", "this", "->", "routeService", "->", "findAll", "(", ")", ";", "// $regex = $this->compoundRegex(array_keys($routes));", "// error_log($regex);", "//", "// if (! preg_match($regex, $uri, $matches)) {", "// $match = '';", "// error_log('no match');", "// exit;", "// return false;", "// }", "// $match = $matches[0];", "// error_log('match = '.$match);", "// exit;", "$", "this", "->", "Logger", "->", "debug", "(", "\"Testing Routes\\n\"", ")", ";", "foreach", "(", "(", "array", ")", "$", "routes", "as", "$", "test_uri", "=>", "$", "nvps", ")", "{", "$", "this", "->", "Logger", "->", "debug", "(", "\"{$test_uri}\"", ")", ";", "$", "m", "=", "null", ";", "$", "re", "=", "str_replace", "(", "'/'", ",", "'\\/'", ",", "$", "test_uri", ")", ";", "$", "match", "=", "preg_match", "(", "'/^'", ".", "$", "re", ".", "'$/i'", ",", "$", "uri", ",", "$", "m", ")", ";", "if", "(", "$", "match", ")", "{", "if", "(", "!", "empty", "(", "$", "nvps", ")", "&&", "is_array", "(", "$", "nvps", ")", ")", "{", "foreach", "(", "$", "nvps", "as", "$", "name", "=>", "$", "value", ")", "{", "foreach", "(", "$", "m", "as", "$", "n", "=>", "$", "v", ")", "{", "$", "value", "=", "str_replace", "(", "'$'", ".", "$", "n", ",", "$", "v", ",", "$", "value", ")", ";", "}", "foreach", "(", "$", "qs", "as", "$", "n", "=>", "$", "v", ")", "{", "if", "(", "is_scalar", "(", "$", "v", ")", ")", "$", "value", "=", "str_replace", "(", "'$'", ".", "$", "n", ",", "$", "v", ",", "$", "value", ")", ";", "}", "$", "varparts", "=", "null", ";", "if", "(", "preg_match", "(", "\"/(.+)\\[(.+)\\]/\"", ",", "$", "name", ",", "$", "varparts", ")", ")", "{", "$", "result", "[", "$", "varparts", "[", "1", "]", "]", "[", "$", "varparts", "[", "2", "]", "]", "=", "$", "value", ";", "}", "else", "{", "$", "result", "[", "$", "name", "]", "=", "$", "value", ";", "}", "}", "}", "foreach", "(", "$", "m", "as", "$", "n", "=>", "$", "v", ")", "if", "(", "is_int", "(", "$", "n", ")", ")", "unset", "(", "$", "m", "[", "$", "n", "]", ")", ";", "$", "result", "=", "array_merge", "(", "$", "m", ",", "$", "result", ")", ";", "$", "this", "->", "Logger", "->", "debug", "(", "'Routing result:'", ")", ";", "$", "this", "->", "Logger", "->", "debug", "(", "$", "result", ")", ";", "return", "$", "result", ";", "}", "}", "$", "this", "->", "checkRedirects", "(", ")", ";", "$", "this", "->", "Logger", "->", "debug", "(", "\"No routes matched.\"", ")", ";", "return", "null", ";", "}" ]
Returns an array that describes the result of the current route. The resultant array will contain keys like 'view', and 'paging', etc. For full details, see the routes file as the array is built from that. @return array
[ "Returns", "an", "array", "that", "describes", "the", "result", "of", "the", "current", "route", "." ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/router/Router.php#L119-L198
train
wb-crowdfusion/crowdfusion
system/core/classes/mvc/router/Router.php
Router.checkRedirects
public function checkRedirects() { // remove trailing slash and lowercase so there aren't multiple copies to cache $uri = strtolower(rtrim($this->Request->getAdjustedRequestURI(), '/')); $qs = $this->Request->getQueryString(); if (($previousRedirect = $this->TemplateCache->get('redirect:' . $uri)) !== false) { $this->Logger->debug('Using cached redirect: ' . $uri . ' -> ' . $previousRedirect); if ($previousRedirect == 'null') return; // let's not let the browser cache these permanently $this->Response->addHeader('Cache-Control', 'max-age=' . $this->cachedRedirectTTL); $this->Response->addHeader('Expires', $this->DateFactory->newLocalDate('+' . $this->cachedRedirectTTL . ' seconds')->toRFCDate()); $this->Response->sendStatus(Response::SC_MOVED_PERMANENTLY); $this->Response->sendRedirect($previousRedirect . (!empty($qs) ? '?' . $qs : '')); return; } $redirects = $this->redirectService->findAll(); foreach ((array)$redirects as $test_uri => $new_url ) { $this->Logger->debug($test_uri); $m = null; $re = str_replace('/', '\/', $test_uri); $match = preg_match("/^". $re . "$/i", $uri, $m); if ($match) { if (!empty($new_url)) { foreach ($m as $n => $v) { $new_url = str_replace('$' . $n, $v, $new_url); } } $this->TemplateCache->put('redirect:' . $uri, $new_url, $this->cachedRedirectTTL); // let's not let the browser cache these permanently $this->Response->addHeader('Cache-Control', 'max-age=' . $this->cachedRedirectTTL); $this->Response->addHeader('Expires', $this->DateFactory->newLocalDate('+' . $this->cachedRedirectTTL . ' seconds')->toRFCDate()); $this->Response->sendStatus(Response::SC_MOVED_PERMANENTLY); $this->Response->sendRedirect($new_url . (!empty($qs) ? '?' . $qs : '')); return; } } $this->TemplateCache->put('redirect:' . $uri, 'null', $this->cachedRedirectTTL); }
php
public function checkRedirects() { // remove trailing slash and lowercase so there aren't multiple copies to cache $uri = strtolower(rtrim($this->Request->getAdjustedRequestURI(), '/')); $qs = $this->Request->getQueryString(); if (($previousRedirect = $this->TemplateCache->get('redirect:' . $uri)) !== false) { $this->Logger->debug('Using cached redirect: ' . $uri . ' -> ' . $previousRedirect); if ($previousRedirect == 'null') return; // let's not let the browser cache these permanently $this->Response->addHeader('Cache-Control', 'max-age=' . $this->cachedRedirectTTL); $this->Response->addHeader('Expires', $this->DateFactory->newLocalDate('+' . $this->cachedRedirectTTL . ' seconds')->toRFCDate()); $this->Response->sendStatus(Response::SC_MOVED_PERMANENTLY); $this->Response->sendRedirect($previousRedirect . (!empty($qs) ? '?' . $qs : '')); return; } $redirects = $this->redirectService->findAll(); foreach ((array)$redirects as $test_uri => $new_url ) { $this->Logger->debug($test_uri); $m = null; $re = str_replace('/', '\/', $test_uri); $match = preg_match("/^". $re . "$/i", $uri, $m); if ($match) { if (!empty($new_url)) { foreach ($m as $n => $v) { $new_url = str_replace('$' . $n, $v, $new_url); } } $this->TemplateCache->put('redirect:' . $uri, $new_url, $this->cachedRedirectTTL); // let's not let the browser cache these permanently $this->Response->addHeader('Cache-Control', 'max-age=' . $this->cachedRedirectTTL); $this->Response->addHeader('Expires', $this->DateFactory->newLocalDate('+' . $this->cachedRedirectTTL . ' seconds')->toRFCDate()); $this->Response->sendStatus(Response::SC_MOVED_PERMANENTLY); $this->Response->sendRedirect($new_url . (!empty($qs) ? '?' . $qs : '')); return; } } $this->TemplateCache->put('redirect:' . $uri, 'null', $this->cachedRedirectTTL); }
[ "public", "function", "checkRedirects", "(", ")", "{", "// remove trailing slash and lowercase so there aren't multiple copies to cache", "$", "uri", "=", "strtolower", "(", "rtrim", "(", "$", "this", "->", "Request", "->", "getAdjustedRequestURI", "(", ")", ",", "'/'", ")", ")", ";", "$", "qs", "=", "$", "this", "->", "Request", "->", "getQueryString", "(", ")", ";", "if", "(", "(", "$", "previousRedirect", "=", "$", "this", "->", "TemplateCache", "->", "get", "(", "'redirect:'", ".", "$", "uri", ")", ")", "!==", "false", ")", "{", "$", "this", "->", "Logger", "->", "debug", "(", "'Using cached redirect: '", ".", "$", "uri", ".", "' -> '", ".", "$", "previousRedirect", ")", ";", "if", "(", "$", "previousRedirect", "==", "'null'", ")", "return", ";", "// let's not let the browser cache these permanently", "$", "this", "->", "Response", "->", "addHeader", "(", "'Cache-Control'", ",", "'max-age='", ".", "$", "this", "->", "cachedRedirectTTL", ")", ";", "$", "this", "->", "Response", "->", "addHeader", "(", "'Expires'", ",", "$", "this", "->", "DateFactory", "->", "newLocalDate", "(", "'+'", ".", "$", "this", "->", "cachedRedirectTTL", ".", "' seconds'", ")", "->", "toRFCDate", "(", ")", ")", ";", "$", "this", "->", "Response", "->", "sendStatus", "(", "Response", "::", "SC_MOVED_PERMANENTLY", ")", ";", "$", "this", "->", "Response", "->", "sendRedirect", "(", "$", "previousRedirect", ".", "(", "!", "empty", "(", "$", "qs", ")", "?", "'?'", ".", "$", "qs", ":", "''", ")", ")", ";", "return", ";", "}", "$", "redirects", "=", "$", "this", "->", "redirectService", "->", "findAll", "(", ")", ";", "foreach", "(", "(", "array", ")", "$", "redirects", "as", "$", "test_uri", "=>", "$", "new_url", ")", "{", "$", "this", "->", "Logger", "->", "debug", "(", "$", "test_uri", ")", ";", "$", "m", "=", "null", ";", "$", "re", "=", "str_replace", "(", "'/'", ",", "'\\/'", ",", "$", "test_uri", ")", ";", "$", "match", "=", "preg_match", "(", "\"/^\"", ".", "$", "re", ".", "\"$/i\"", ",", "$", "uri", ",", "$", "m", ")", ";", "if", "(", "$", "match", ")", "{", "if", "(", "!", "empty", "(", "$", "new_url", ")", ")", "{", "foreach", "(", "$", "m", "as", "$", "n", "=>", "$", "v", ")", "{", "$", "new_url", "=", "str_replace", "(", "'$'", ".", "$", "n", ",", "$", "v", ",", "$", "new_url", ")", ";", "}", "}", "$", "this", "->", "TemplateCache", "->", "put", "(", "'redirect:'", ".", "$", "uri", ",", "$", "new_url", ",", "$", "this", "->", "cachedRedirectTTL", ")", ";", "// let's not let the browser cache these permanently", "$", "this", "->", "Response", "->", "addHeader", "(", "'Cache-Control'", ",", "'max-age='", ".", "$", "this", "->", "cachedRedirectTTL", ")", ";", "$", "this", "->", "Response", "->", "addHeader", "(", "'Expires'", ",", "$", "this", "->", "DateFactory", "->", "newLocalDate", "(", "'+'", ".", "$", "this", "->", "cachedRedirectTTL", ".", "' seconds'", ")", "->", "toRFCDate", "(", ")", ")", ";", "$", "this", "->", "Response", "->", "sendStatus", "(", "Response", "::", "SC_MOVED_PERMANENTLY", ")", ";", "$", "this", "->", "Response", "->", "sendRedirect", "(", "$", "new_url", ".", "(", "!", "empty", "(", "$", "qs", ")", "?", "'?'", ".", "$", "qs", ":", "''", ")", ")", ";", "return", ";", "}", "}", "$", "this", "->", "TemplateCache", "->", "put", "(", "'redirect:'", ".", "$", "uri", ",", "'null'", ",", "$", "this", "->", "cachedRedirectTTL", ")", ";", "}" ]
Checks the redirects against the current URI and redirects the user's browser if they've hit a redirect URL @return void
[ "Checks", "the", "redirects", "against", "the", "current", "URI", "and", "redirects", "the", "user", "s", "browser", "if", "they", "ve", "hit", "a", "redirect", "URL" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/mvc/router/Router.php#L220-L270
train
horntell/php-sdk
lib/guzzle/GuzzleHttp/Message/Response.php
Response.handleOptions
protected function handleOptions(array &$options = []) { parent::handleOptions($options); if (isset($options['reason_phrase'])) { $this->reasonPhrase = $options['reason_phrase']; } }
php
protected function handleOptions(array &$options = []) { parent::handleOptions($options); if (isset($options['reason_phrase'])) { $this->reasonPhrase = $options['reason_phrase']; } }
[ "protected", "function", "handleOptions", "(", "array", "&", "$", "options", "=", "[", "]", ")", "{", "parent", "::", "handleOptions", "(", "$", "options", ")", ";", "if", "(", "isset", "(", "$", "options", "[", "'reason_phrase'", "]", ")", ")", "{", "$", "this", "->", "reasonPhrase", "=", "$", "options", "[", "'reason_phrase'", "]", ";", "}", "}" ]
Accepts and modifies the options provided to the response in the constructor. @param array $options Options array passed by reference.
[ "Accepts", "and", "modifies", "the", "options", "provided", "to", "the", "response", "in", "the", "constructor", "." ]
e5205e9396a21b754d5651a8aa5898da5922a1b7
https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Message/Response.php#L193-L199
train
phossa/phossa-event
src/Phossa/Event/Interfaces/EventManagerTrait.php
EventManagerTrait.runEventQueue
protected function runEventQueue( EventInterface $event, EventQueueInterface $queue, callable $callback = null )/*# : EventManagerInterface */ { try { foreach ($queue as $data) { // execute each callable from the queue $res = call_user_func($data['data'], $event); // set results $event->setResult($res); // stop propagation if callable returns FALSE if ($res === false) { $event->stopPropagation(); } // break if event stopped if ($event->isPropagationStopped()) { break; } // run callback if ($callback && call_user_func($callback, $event, $res) === false ) { break; } } return $this; } catch (\Exception $e) { // rethrow any exception caught throw new Exception\RuntimeException( Message::get(Message::CALLABLE_RUNTIME, $e->getMessage()), $e->getCode(), $e ); } }
php
protected function runEventQueue( EventInterface $event, EventQueueInterface $queue, callable $callback = null )/*# : EventManagerInterface */ { try { foreach ($queue as $data) { // execute each callable from the queue $res = call_user_func($data['data'], $event); // set results $event->setResult($res); // stop propagation if callable returns FALSE if ($res === false) { $event->stopPropagation(); } // break if event stopped if ($event->isPropagationStopped()) { break; } // run callback if ($callback && call_user_func($callback, $event, $res) === false ) { break; } } return $this; } catch (\Exception $e) { // rethrow any exception caught throw new Exception\RuntimeException( Message::get(Message::CALLABLE_RUNTIME, $e->getMessage()), $e->getCode(), $e ); } }
[ "protected", "function", "runEventQueue", "(", "EventInterface", "$", "event", ",", "EventQueueInterface", "$", "queue", ",", "callable", "$", "callback", "=", "null", ")", "/*# : EventManagerInterface */", "{", "try", "{", "foreach", "(", "$", "queue", "as", "$", "data", ")", "{", "// execute each callable from the queue", "$", "res", "=", "call_user_func", "(", "$", "data", "[", "'data'", "]", ",", "$", "event", ")", ";", "// set results", "$", "event", "->", "setResult", "(", "$", "res", ")", ";", "// stop propagation if callable returns FALSE", "if", "(", "$", "res", "===", "false", ")", "{", "$", "event", "->", "stopPropagation", "(", ")", ";", "}", "// break if event stopped", "if", "(", "$", "event", "->", "isPropagationStopped", "(", ")", ")", "{", "break", ";", "}", "// run callback", "if", "(", "$", "callback", "&&", "call_user_func", "(", "$", "callback", ",", "$", "event", ",", "$", "res", ")", "===", "false", ")", "{", "break", ";", "}", "}", "return", "$", "this", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "// rethrow any exception caught", "throw", "new", "Exception", "\\", "RuntimeException", "(", "Message", "::", "get", "(", "Message", "::", "CALLABLE_RUNTIME", ",", "$", "e", "->", "getMessage", "(", ")", ")", ",", "$", "e", "->", "getCode", "(", ")", ",", "$", "e", ")", ";", "}", "}" ]
Run an event with the provided queue The $callback defined as `function($event, $response) {}`, where $reponse is the return value from previous event handler. @param EventInterface $event @param EventQueueInterface $queue @param callable $callback (optional) a callback returns bool @return EventManagerInterface this @throws \Phossa\Event\Exception\RuntimeException rethrow any exception catched as RuntimeException @access protected
[ "Run", "an", "event", "with", "the", "provided", "queue" ]
0044888fcc9b21584233c73cf20fc160e1b1f295
https://github.com/phossa/phossa-event/blob/0044888fcc9b21584233c73cf20fc160e1b1f295/src/Phossa/Event/Interfaces/EventManagerTrait.php#L197-L237
train
phossa/phossa-event
src/Phossa/Event/Interfaces/EventManagerTrait.php
EventManagerTrait.isListener
protected function isListener($listener)/*# : bool */ { // object if (is_object($listener) && $listener instanceof EventListenerInterface) { return true; } // static class name if (is_string($listener) && is_a( $listener, '\\Phossa\\Event\\Interfaces\\EventListenerStaticInterface', true )) { return true; } return false; }
php
protected function isListener($listener)/*# : bool */ { // object if (is_object($listener) && $listener instanceof EventListenerInterface) { return true; } // static class name if (is_string($listener) && is_a( $listener, '\\Phossa\\Event\\Interfaces\\EventListenerStaticInterface', true )) { return true; } return false; }
[ "protected", "function", "isListener", "(", "$", "listener", ")", "/*# : bool */", "{", "// object", "if", "(", "is_object", "(", "$", "listener", ")", "&&", "$", "listener", "instanceof", "EventListenerInterface", ")", "{", "return", "true", ";", "}", "// static class name", "if", "(", "is_string", "(", "$", "listener", ")", "&&", "is_a", "(", "$", "listener", ",", "'\\\\Phossa\\\\Event\\\\Interfaces\\\\EventListenerStaticInterface'", ",", "true", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Test if it is a valid listener @param EventListenerInterface|string $listener object/static class name @return bool @access protected
[ "Test", "if", "it", "is", "a", "valid", "listener" ]
0044888fcc9b21584233c73cf20fc160e1b1f295
https://github.com/phossa/phossa-event/blob/0044888fcc9b21584233c73cf20fc160e1b1f295/src/Phossa/Event/Interfaces/EventManagerTrait.php#L246-L265
train