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
Kris-Kuiper/sFire-Framework
src/Logger/Logger.php
Logger.setDirectory
public function setDirectory($directory) { if(false === is_string($directory)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($directory)), E_USER_ERROR); } $this -> directory = new Directory($directory); if(false === $this -> directory -> isWritable()) { return trigger_error(sprintf('Directory "%s" passed to %s() is not writable', $directory, __METHOD__), E_USER_ERROR); } return $this; }
php
public function setDirectory($directory) { if(false === is_string($directory)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($directory)), E_USER_ERROR); } $this -> directory = new Directory($directory); if(false === $this -> directory -> isWritable()) { return trigger_error(sprintf('Directory "%s" passed to %s() is not writable', $directory, __METHOD__), E_USER_ERROR); } return $this; }
[ "public", "function", "setDirectory", "(", "$", "directory", ")", "{", "if", "(", "false", "===", "is_string", "(", "$", "directory", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 1 passed to %s() must be of the type string, \"%s\" given'", ",", "__METHOD__", ",", "gettype", "(", "$", "directory", ")", ")", ",", "E_USER_ERROR", ")", ";", "}", "$", "this", "->", "directory", "=", "new", "Directory", "(", "$", "directory", ")", ";", "if", "(", "false", "===", "$", "this", "->", "directory", "->", "isWritable", "(", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Directory \"%s\" passed to %s() is not writable'", ",", "$", "directory", ",", "__METHOD__", ")", ",", "E_USER_ERROR", ")", ";", "}", "return", "$", "this", ";", "}" ]
Sets the directory to write to @param string $directory @return sFire\Logger\Logger
[ "Sets", "the", "directory", "to", "write", "to" ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Logger/Logger.php#L55-L68
train
Kris-Kuiper/sFire-Framework
src/Logger/Logger.php
Logger.setExtension
public function setExtension($extension) { if(false === is_string($extension)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($extension)), E_USER_ERROR); } //Prepend dot for extension if necessary $extension = ($extension[0] === '.') ? $extension : '.' . $extension; $this -> extension = $extension; return $this; }
php
public function setExtension($extension) { if(false === is_string($extension)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($extension)), E_USER_ERROR); } //Prepend dot for extension if necessary $extension = ($extension[0] === '.') ? $extension : '.' . $extension; $this -> extension = $extension; return $this; }
[ "public", "function", "setExtension", "(", "$", "extension", ")", "{", "if", "(", "false", "===", "is_string", "(", "$", "extension", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 1 passed to %s() must be of the type string, \"%s\" given'", ",", "__METHOD__", ",", "gettype", "(", "$", "extension", ")", ")", ",", "E_USER_ERROR", ")", ";", "}", "//Prepend dot for extension if necessary\r", "$", "extension", "=", "(", "$", "extension", "[", "0", "]", "===", "'.'", ")", "?", "$", "extension", ":", "'.'", ".", "$", "extension", ";", "$", "this", "->", "extension", "=", "$", "extension", ";", "return", "$", "this", ";", "}" ]
Set file extension @param string $extension @return sFire\Logger\Logger
[ "Set", "file", "extension" ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Logger/Logger.php#L85-L97
train
Kris-Kuiper/sFire-Framework
src/Logger/Logger.php
Logger.setMode
public function setMode($mode) { if(false === is_string($mode)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($mode)), E_USER_ERROR); } $this -> mode = $mode; return $this; }
php
public function setMode($mode) { if(false === is_string($mode)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($mode)), E_USER_ERROR); } $this -> mode = $mode; return $this; }
[ "public", "function", "setMode", "(", "$", "mode", ")", "{", "if", "(", "false", "===", "is_string", "(", "$", "mode", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 1 passed to %s() must be of the type string, \"%s\" given'", ",", "__METHOD__", ",", "gettype", "(", "$", "mode", ")", ")", ",", "E_USER_ERROR", ")", ";", "}", "$", "this", "->", "mode", "=", "$", "mode", ";", "return", "$", "this", ";", "}" ]
Sets the log rotate mode @param string $mode @return sFire\Logger\Logger
[ "Sets", "the", "log", "rotate", "mode" ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Logger/Logger.php#L119-L128
train
Kris-Kuiper/sFire-Framework
src/Logger/Logger.php
Logger.setSuffix
public function setSuffix($suffix) { if(false === is_string($suffix)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($suffix)), E_USER_ERROR); } $this -> suffix = $suffix; return $this; }
php
public function setSuffix($suffix) { if(false === is_string($suffix)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($suffix)), E_USER_ERROR); } $this -> suffix = $suffix; return $this; }
[ "public", "function", "setSuffix", "(", "$", "suffix", ")", "{", "if", "(", "false", "===", "is_string", "(", "$", "suffix", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 1 passed to %s() must be of the type string, \"%s\" given'", ",", "__METHOD__", ",", "gettype", "(", "$", "suffix", ")", ")", ",", "E_USER_ERROR", ")", ";", "}", "$", "this", "->", "suffix", "=", "$", "suffix", ";", "return", "$", "this", ";", "}" ]
Sets the suffix @param string $suffix @return sFire\Logger\Logger
[ "Sets", "the", "suffix" ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Logger/Logger.php#L136-L145
train
Kris-Kuiper/sFire-Framework
src/Logger/Logger.php
Logger.generateFileName
private function generateFileName() { return $this -> directory -> entity() -> getPath() . date($this -> getMode()) . $this -> getSuffix() . $this -> getExtension(); }
php
private function generateFileName() { return $this -> directory -> entity() -> getPath() . date($this -> getMode()) . $this -> getSuffix() . $this -> getExtension(); }
[ "private", "function", "generateFileName", "(", ")", "{", "return", "$", "this", "->", "directory", "->", "entity", "(", ")", "->", "getPath", "(", ")", ".", "date", "(", "$", "this", "->", "getMode", "(", ")", ")", ".", "$", "this", "->", "getSuffix", "(", ")", ".", "$", "this", "->", "getExtension", "(", ")", ";", "}" ]
Generates a filename with current rotation mode @return string
[ "Generates", "a", "filename", "with", "current", "rotation", "mode" ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Logger/Logger.php#L200-L202
train
rzajac/phptools
src/Lang/Calendar.php
Calendar.getDay
public static function getDay($day, $langCode, $style = self::STYLE_LONG) { $langCode = static::checkLanguageCode($langCode); return self::$i18n[$langCode]['day'][$style][$day]; }
php
public static function getDay($day, $langCode, $style = self::STYLE_LONG) { $langCode = static::checkLanguageCode($langCode); return self::$i18n[$langCode]['day'][$style][$day]; }
[ "public", "static", "function", "getDay", "(", "$", "day", ",", "$", "langCode", ",", "$", "style", "=", "self", "::", "STYLE_LONG", ")", "{", "$", "langCode", "=", "static", "::", "checkLanguageCode", "(", "$", "langCode", ")", ";", "return", "self", "::", "$", "i18n", "[", "$", "langCode", "]", "[", "'day'", "]", "[", "$", "style", "]", "[", "$", "day", "]", ";", "}" ]
Get translated day of the week. @param int $day The day of the week number 1 - 7 @param string $langCode The supported language code ex: en @param string $style The style to return day name in. One of the self::STYLE_* constants @return mixed
[ "Get", "translated", "day", "of", "the", "week", "." ]
3cbece7645942d244603c14ba897d8a676ee3088
https://github.com/rzajac/phptools/blob/3cbece7645942d244603c14ba897d8a676ee3088/src/Lang/Calendar.php#L58-L63
train
rzajac/phptools
src/Lang/Calendar.php
Calendar.getMonth
public static function getMonth($month, $langCode, $style = self::STYLE_LONG) { $langCode = static::checkLanguageCode($langCode); return self::$i18n[$langCode]['month'][$style][$month]; }
php
public static function getMonth($month, $langCode, $style = self::STYLE_LONG) { $langCode = static::checkLanguageCode($langCode); return self::$i18n[$langCode]['month'][$style][$month]; }
[ "public", "static", "function", "getMonth", "(", "$", "month", ",", "$", "langCode", ",", "$", "style", "=", "self", "::", "STYLE_LONG", ")", "{", "$", "langCode", "=", "static", "::", "checkLanguageCode", "(", "$", "langCode", ")", ";", "return", "self", "::", "$", "i18n", "[", "$", "langCode", "]", "[", "'month'", "]", "[", "$", "style", "]", "[", "$", "month", "]", ";", "}" ]
Get translated month. @param int $month The month number 1 - 12 @param string $langCode The supported language code ex: en @param string $style The style to return month name in. One of the self::STYLE_* constants @return mixed
[ "Get", "translated", "month", "." ]
3cbece7645942d244603c14ba897d8a676ee3088
https://github.com/rzajac/phptools/blob/3cbece7645942d244603c14ba897d8a676ee3088/src/Lang/Calendar.php#L74-L79
train
Wedeto/DB
src/Query/Direction.php
Direction.toSQL
public function toSQL(Parameters $params, bool $inner_clause) { $expr = $this->getOperand(); $direction = $this->getDirection(); return $params->getDriver()->toSQL($params, $expr, false) . " " . $direction; }
php
public function toSQL(Parameters $params, bool $inner_clause) { $expr = $this->getOperand(); $direction = $this->getDirection(); return $params->getDriver()->toSQL($params, $expr, false) . " " . $direction; }
[ "public", "function", "toSQL", "(", "Parameters", "$", "params", ",", "bool", "$", "inner_clause", ")", "{", "$", "expr", "=", "$", "this", "->", "getOperand", "(", ")", ";", "$", "direction", "=", "$", "this", "->", "getDirection", "(", ")", ";", "return", "$", "params", "->", "getDriver", "(", ")", "->", "toSQL", "(", "$", "params", ",", "$", "expr", ",", "false", ")", ".", "\" \"", ".", "$", "direction", ";", "}" ]
Write a order direction clause as SQL query syntax @param Parameters $params The query parameters: tables and placeholder values @param bool $inner_clause Unused @return string The generated SQL
[ "Write", "a", "order", "direction", "clause", "as", "SQL", "query", "syntax" ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/Query/Direction.php#L64-L70
train
Rivsen/ladybug-service-provider
src/DataCollector/LadybugDataCollector.php
LadybugDataCollector.log
public function log() { $content = call_user_func_array(array($this->ladybug,'dump'), func_get_args()); $trace = debug_backtrace(); $this->data['vars'][] = array( 'file' => isset($trace[0]['file']) ? $trace[0]['file'] : '', 'line' => isset($trace[0]['line']) ? $trace[0]['line'] : '', 'content' => $content ); }
php
public function log() { $content = call_user_func_array(array($this->ladybug,'dump'), func_get_args()); $trace = debug_backtrace(); $this->data['vars'][] = array( 'file' => isset($trace[0]['file']) ? $trace[0]['file'] : '', 'line' => isset($trace[0]['line']) ? $trace[0]['line'] : '', 'content' => $content ); }
[ "public", "function", "log", "(", ")", "{", "$", "content", "=", "call_user_func_array", "(", "array", "(", "$", "this", "->", "ladybug", ",", "'dump'", ")", ",", "func_get_args", "(", ")", ")", ";", "$", "trace", "=", "debug_backtrace", "(", ")", ";", "$", "this", "->", "data", "[", "'vars'", "]", "[", "]", "=", "array", "(", "'file'", "=>", "isset", "(", "$", "trace", "[", "0", "]", "[", "'file'", "]", ")", "?", "$", "trace", "[", "0", "]", "[", "'file'", "]", ":", "''", ",", "'line'", "=>", "isset", "(", "$", "trace", "[", "0", "]", "[", "'line'", "]", ")", "?", "$", "trace", "[", "0", "]", "[", "'line'", "]", ":", "''", ",", "'content'", "=>", "$", "content", ")", ";", "}" ]
Log an info.
[ "Log", "an", "info", "." ]
af0103ceb696fb133c00989bfcda82424e39d660
https://github.com/Rivsen/ladybug-service-provider/blob/af0103ceb696fb133c00989bfcda82424e39d660/src/DataCollector/LadybugDataCollector.php#L38-L49
train
Repkit/PluginManager
src/RpkPluginManager/PluginChain.php
PluginChain.load
public function load() { static::$loaded = true; $container = $this->getContainer(); if($container){ $config = $container->get('config'); $events = $config['plugin-manager']; foreach($events as $event => $plugins){ foreach($plugins as $type => $plugin){ $this->attach($event, $plugin, $plugin->Priority); } } } return true; }
php
public function load() { static::$loaded = true; $container = $this->getContainer(); if($container){ $config = $container->get('config'); $events = $config['plugin-manager']; foreach($events as $event => $plugins){ foreach($plugins as $type => $plugin){ $this->attach($event, $plugin, $plugin->Priority); } } } return true; }
[ "public", "function", "load", "(", ")", "{", "static", "::", "$", "loaded", "=", "true", ";", "$", "container", "=", "$", "this", "->", "getContainer", "(", ")", ";", "if", "(", "$", "container", ")", "{", "$", "config", "=", "$", "container", "->", "get", "(", "'config'", ")", ";", "$", "events", "=", "$", "config", "[", "'plugin-manager'", "]", ";", "foreach", "(", "$", "events", "as", "$", "event", "=>", "$", "plugins", ")", "{", "foreach", "(", "$", "plugins", "as", "$", "type", "=>", "$", "plugin", ")", "{", "$", "this", "->", "attach", "(", "$", "event", ",", "$", "plugin", ",", "$", "plugin", "->", "Priority", ")", ";", "}", "}", "}", "return", "true", ";", "}" ]
load events with their plugins
[ "load", "events", "with", "their", "plugins" ]
e5a333acb6b543a6b98aca9c3b1e4620ad3410b4
https://github.com/Repkit/PluginManager/blob/e5a333acb6b543a6b98aca9c3b1e4620ad3410b4/src/RpkPluginManager/PluginChain.php#L220-L237
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/assetaggregator/AssetAggregator.php
AssetAggregator.buildCacheKey
protected function buildCacheKey(array $assets, array $options) { $cachekey = $this->Request->getServerName(); $cachekey .= "(asset(".implode('|', $assets).")(".implode('|', $options)."))"; return $cachekey; }
php
protected function buildCacheKey(array $assets, array $options) { $cachekey = $this->Request->getServerName(); $cachekey .= "(asset(".implode('|', $assets).")(".implode('|', $options)."))"; return $cachekey; }
[ "protected", "function", "buildCacheKey", "(", "array", "$", "assets", ",", "array", "$", "options", ")", "{", "$", "cachekey", "=", "$", "this", "->", "Request", "->", "getServerName", "(", ")", ";", "$", "cachekey", ".=", "\"(asset(\"", ".", "implode", "(", "'|'", ",", "$", "assets", ")", ".", "\")(\"", ".", "implode", "(", "'|'", ",", "$", "options", ")", ".", "\"))\"", ";", "return", "$", "cachekey", ";", "}" ]
Builds a unique cache key based on the asset array and options @param array $assets Array of asset file names @param array $options Array of scalar option values @return string Unique cache key
[ "Builds", "a", "unique", "cache", "key", "based", "on", "the", "asset", "array", "and", "options" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/assetaggregator/AssetAggregator.php#L268-L274
train
dubhunter/talon
src/Http/Response.php
Response.permanentRedirect
public static function permanentRedirect($url, $externalRedirect = false) { /** @var Response $response */ $response = new static(); $response->redirect($url, $externalRedirect, self::HTTP_PERMANENT_REDIRECT); return $response; }
php
public static function permanentRedirect($url, $externalRedirect = false) { /** @var Response $response */ $response = new static(); $response->redirect($url, $externalRedirect, self::HTTP_PERMANENT_REDIRECT); return $response; }
[ "public", "static", "function", "permanentRedirect", "(", "$", "url", ",", "$", "externalRedirect", "=", "false", ")", "{", "/** @var Response $response */", "$", "response", "=", "new", "static", "(", ")", ";", "$", "response", "->", "redirect", "(", "$", "url", ",", "$", "externalRedirect", ",", "self", "::", "HTTP_PERMANENT_REDIRECT", ")", ";", "return", "$", "response", ";", "}" ]
Convenience function to create a 301 response @see Response::redirect() @static @param string $url The url to redirect to @param boolean $externalRedirect Treat the redirect as external @return Response
[ "Convenience", "function", "to", "create", "a", "301", "response" ]
308b7284556dfaff0d9ac4c7739dc6a46930ef36
https://github.com/dubhunter/talon/blob/308b7284556dfaff0d9ac4c7739dc6a46930ef36/src/Http/Response.php#L240-L245
train
dubhunter/talon
src/Http/Response.php
Response.temporaryRedirect
public static function temporaryRedirect($url, $externalRedirect = false) { /** @var Response $response */ $response = new static(); $response->redirect($url, $externalRedirect, self::HTTP_TEMPORARY_REDIRECT); return $response; }
php
public static function temporaryRedirect($url, $externalRedirect = false) { /** @var Response $response */ $response = new static(); $response->redirect($url, $externalRedirect, self::HTTP_TEMPORARY_REDIRECT); return $response; }
[ "public", "static", "function", "temporaryRedirect", "(", "$", "url", ",", "$", "externalRedirect", "=", "false", ")", "{", "/** @var Response $response */", "$", "response", "=", "new", "static", "(", ")", ";", "$", "response", "->", "redirect", "(", "$", "url", ",", "$", "externalRedirect", ",", "self", "::", "HTTP_TEMPORARY_REDIRECT", ")", ";", "return", "$", "response", ";", "}" ]
Convenience function to create a 302 response @see Response::redirect() @static @param string $url The url to redirect to @param boolean $externalRedirect Treat the redirect as external @return Response HTTP 302 Response with URL
[ "Convenience", "function", "to", "create", "a", "302", "response" ]
308b7284556dfaff0d9ac4c7739dc6a46930ef36
https://github.com/dubhunter/talon/blob/308b7284556dfaff0d9ac4c7739dc6a46930ef36/src/Http/Response.php#L255-L260
train
MasterkeyInformatica/browser-kit
CookieJar.php
CookieJar.expire
public function expire($name, $path = '/', $domain = null) { if (null === $path) { $path = '/'; } if (empty($domain)) { // an empty domain means any domain // this should never happen but it allows for a better BC $domains = array_keys($this->cookieJar); } else { $domains = array($domain); } foreach ($domains as $domain) { unset($this->cookieJar[$domain][$path][$name]); if (empty($this->cookieJar[$domain][$path])) { unset($this->cookieJar[$domain][$path]); if (empty($this->cookieJar[$domain])) { unset($this->cookieJar[$domain]); } } } }
php
public function expire($name, $path = '/', $domain = null) { if (null === $path) { $path = '/'; } if (empty($domain)) { // an empty domain means any domain // this should never happen but it allows for a better BC $domains = array_keys($this->cookieJar); } else { $domains = array($domain); } foreach ($domains as $domain) { unset($this->cookieJar[$domain][$path][$name]); if (empty($this->cookieJar[$domain][$path])) { unset($this->cookieJar[$domain][$path]); if (empty($this->cookieJar[$domain])) { unset($this->cookieJar[$domain]); } } } }
[ "public", "function", "expire", "(", "$", "name", ",", "$", "path", "=", "'/'", ",", "$", "domain", "=", "null", ")", "{", "if", "(", "null", "===", "$", "path", ")", "{", "$", "path", "=", "'/'", ";", "}", "if", "(", "empty", "(", "$", "domain", ")", ")", "{", "// an empty domain means any domain", "// this should never happen but it allows for a better BC", "$", "domains", "=", "array_keys", "(", "$", "this", "->", "cookieJar", ")", ";", "}", "else", "{", "$", "domains", "=", "array", "(", "$", "domain", ")", ";", "}", "foreach", "(", "$", "domains", "as", "$", "domain", ")", "{", "unset", "(", "$", "this", "->", "cookieJar", "[", "$", "domain", "]", "[", "$", "path", "]", "[", "$", "name", "]", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "cookieJar", "[", "$", "domain", "]", "[", "$", "path", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "cookieJar", "[", "$", "domain", "]", "[", "$", "path", "]", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "cookieJar", "[", "$", "domain", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "cookieJar", "[", "$", "domain", "]", ")", ";", "}", "}", "}", "}" ]
Removes a cookie by name. You should never use an empty domain, but if you do so, all cookies for the given name/path expire (this behavior ensures a BC behavior with previous versions of Symfony). @param string $name The cookie name @param string $path The cookie path @param string $domain The cookie domain
[ "Removes", "a", "cookie", "by", "name", "." ]
fd735ad31c00af54d5c060d01218aa48308557f7
https://github.com/MasterkeyInformatica/browser-kit/blob/fd735ad31c00af54d5c060d01218aa48308557f7/CookieJar.php#L92-L117
train
MasterkeyInformatica/browser-kit
CookieJar.php
CookieJar.all
public function all() { $this->flushExpiredCookies(); $flattenedCookies = array(); foreach ($this->cookieJar as $path) { foreach ($path as $cookies) { foreach ($cookies as $cookie) { $flattenedCookies[] = $cookie; } } } return $flattenedCookies; }
php
public function all() { $this->flushExpiredCookies(); $flattenedCookies = array(); foreach ($this->cookieJar as $path) { foreach ($path as $cookies) { foreach ($cookies as $cookie) { $flattenedCookies[] = $cookie; } } } return $flattenedCookies; }
[ "public", "function", "all", "(", ")", "{", "$", "this", "->", "flushExpiredCookies", "(", ")", ";", "$", "flattenedCookies", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "cookieJar", "as", "$", "path", ")", "{", "foreach", "(", "$", "path", "as", "$", "cookies", ")", "{", "foreach", "(", "$", "cookies", "as", "$", "cookie", ")", "{", "$", "flattenedCookies", "[", "]", "=", "$", "cookie", ";", "}", "}", "}", "return", "$", "flattenedCookies", ";", "}" ]
Returns not yet expired cookies. @return Cookie[] An array of cookies
[ "Returns", "not", "yet", "expired", "cookies", "." ]
fd735ad31c00af54d5c060d01218aa48308557f7
https://github.com/MasterkeyInformatica/browser-kit/blob/fd735ad31c00af54d5c060d01218aa48308557f7/CookieJar.php#L172-L186
train
MasterkeyInformatica/browser-kit
CookieJar.php
CookieJar.allValues
public function allValues($uri, $returnsRawValue = false) { $this->flushExpiredCookies(); $parts = array_replace(array('path' => '/'), parse_url($uri)); $cookies = array(); foreach ($this->cookieJar as $domain => $pathCookies) { if ($domain) { $domain = '.'.ltrim($domain, '.'); if ($domain != substr('.'.$parts['host'], -strlen($domain))) { continue; } } foreach ($pathCookies as $path => $namedCookies) { if ($path != substr($parts['path'], 0, strlen($path))) { continue; } foreach ($namedCookies as $cookie) { if ($cookie->isSecure() && 'https' != $parts['scheme']) { continue; } $cookies[$cookie->getName()] = $returnsRawValue ? $cookie->getRawValue() : $cookie->getValue(); } } } return $cookies; }
php
public function allValues($uri, $returnsRawValue = false) { $this->flushExpiredCookies(); $parts = array_replace(array('path' => '/'), parse_url($uri)); $cookies = array(); foreach ($this->cookieJar as $domain => $pathCookies) { if ($domain) { $domain = '.'.ltrim($domain, '.'); if ($domain != substr('.'.$parts['host'], -strlen($domain))) { continue; } } foreach ($pathCookies as $path => $namedCookies) { if ($path != substr($parts['path'], 0, strlen($path))) { continue; } foreach ($namedCookies as $cookie) { if ($cookie->isSecure() && 'https' != $parts['scheme']) { continue; } $cookies[$cookie->getName()] = $returnsRawValue ? $cookie->getRawValue() : $cookie->getValue(); } } } return $cookies; }
[ "public", "function", "allValues", "(", "$", "uri", ",", "$", "returnsRawValue", "=", "false", ")", "{", "$", "this", "->", "flushExpiredCookies", "(", ")", ";", "$", "parts", "=", "array_replace", "(", "array", "(", "'path'", "=>", "'/'", ")", ",", "parse_url", "(", "$", "uri", ")", ")", ";", "$", "cookies", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "cookieJar", "as", "$", "domain", "=>", "$", "pathCookies", ")", "{", "if", "(", "$", "domain", ")", "{", "$", "domain", "=", "'.'", ".", "ltrim", "(", "$", "domain", ",", "'.'", ")", ";", "if", "(", "$", "domain", "!=", "substr", "(", "'.'", ".", "$", "parts", "[", "'host'", "]", ",", "-", "strlen", "(", "$", "domain", ")", ")", ")", "{", "continue", ";", "}", "}", "foreach", "(", "$", "pathCookies", "as", "$", "path", "=>", "$", "namedCookies", ")", "{", "if", "(", "$", "path", "!=", "substr", "(", "$", "parts", "[", "'path'", "]", ",", "0", ",", "strlen", "(", "$", "path", ")", ")", ")", "{", "continue", ";", "}", "foreach", "(", "$", "namedCookies", "as", "$", "cookie", ")", "{", "if", "(", "$", "cookie", "->", "isSecure", "(", ")", "&&", "'https'", "!=", "$", "parts", "[", "'scheme'", "]", ")", "{", "continue", ";", "}", "$", "cookies", "[", "$", "cookie", "->", "getName", "(", ")", "]", "=", "$", "returnsRawValue", "?", "$", "cookie", "->", "getRawValue", "(", ")", ":", "$", "cookie", "->", "getValue", "(", ")", ";", "}", "}", "}", "return", "$", "cookies", ";", "}" ]
Returns not yet expired cookie values for the given URI. @param string $uri A URI @param bool $returnsRawValue Returns raw value or urldecoded value @return array An array of cookie values
[ "Returns", "not", "yet", "expired", "cookie", "values", "for", "the", "given", "URI", "." ]
fd735ad31c00af54d5c060d01218aa48308557f7
https://github.com/MasterkeyInformatica/browser-kit/blob/fd735ad31c00af54d5c060d01218aa48308557f7/CookieJar.php#L196-L226
train
D3strukt0r/oauth2-orbitrondev
src/Provider/OrbitronDevResourceOwner.php
OrbitronDevResourceOwner.getActiveAddress
public function getActiveAddress() { if (null === $this->getAddresses()) { return null; } if (1 === count($this->getAddresses())) { foreach ($this->getAddresses() as $address) { return $address; } } if (null === $this->response['active_address']) { return null; } return $this->getAddresses()[$this->response['active_address']]; }
php
public function getActiveAddress() { if (null === $this->getAddresses()) { return null; } if (1 === count($this->getAddresses())) { foreach ($this->getAddresses() as $address) { return $address; } } if (null === $this->response['active_address']) { return null; } return $this->getAddresses()[$this->response['active_address']]; }
[ "public", "function", "getActiveAddress", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "getAddresses", "(", ")", ")", "{", "return", "null", ";", "}", "if", "(", "1", "===", "count", "(", "$", "this", "->", "getAddresses", "(", ")", ")", ")", "{", "foreach", "(", "$", "this", "->", "getAddresses", "(", ")", "as", "$", "address", ")", "{", "return", "$", "address", ";", "}", "}", "if", "(", "null", "===", "$", "this", "->", "response", "[", "'active_address'", "]", ")", "{", "return", "null", ";", "}", "return", "$", "this", "->", "getAddresses", "(", ")", "[", "$", "this", "->", "response", "[", "'active_address'", "]", "]", ";", "}" ]
Return the surname. @return array|null
[ "Return", "the", "surname", "." ]
9b8d4656254cb60d20d45ded269f147d487b1e4d
https://github.com/D3strukt0r/oauth2-orbitrondev/blob/9b8d4656254cb60d20d45ded269f147d487b1e4d/src/Provider/OrbitronDevResourceOwner.php#L106-L123
train
koolkode/lexer
src/AbstractTokenContainer.php
AbstractTokenContainer.serialize
public function serialize() { $it = new SerializedTokenIterator([]); $this->preSerialize($it); foreach($this->tokens as $token) { $token->serialize($it); } $this->postSerialize($it); return json_encode($it->getArrayCopy()); }
php
public function serialize() { $it = new SerializedTokenIterator([]); $this->preSerialize($it); foreach($this->tokens as $token) { $token->serialize($it); } $this->postSerialize($it); return json_encode($it->getArrayCopy()); }
[ "public", "function", "serialize", "(", ")", "{", "$", "it", "=", "new", "SerializedTokenIterator", "(", "[", "]", ")", ";", "$", "this", "->", "preSerialize", "(", "$", "it", ")", ";", "foreach", "(", "$", "this", "->", "tokens", "as", "$", "token", ")", "{", "$", "token", "->", "serialize", "(", "$", "it", ")", ";", "}", "$", "this", "->", "postSerialize", "(", "$", "it", ")", ";", "return", "json_encode", "(", "$", "it", "->", "getArrayCopy", "(", ")", ")", ";", "}" ]
Serializes a token container into an encoded string that consumes a minimal amount of storage memory. @return string
[ "Serializes", "a", "token", "container", "into", "an", "encoded", "string", "that", "consumes", "a", "minimal", "amount", "of", "storage", "memory", "." ]
1f33fb4e95bf3b6b21c63187e503bbe612a1646c
https://github.com/koolkode/lexer/blob/1f33fb4e95bf3b6b21c63187e503bbe612a1646c/src/AbstractTokenContainer.php#L99-L113
train
koolkode/lexer
src/AbstractTokenContainer.php
AbstractTokenContainer.unserialize
public function unserialize($serialized) { $this->tokens = []; $tokenFactory = $this->getTokenFactory(); $it = new SerializedTokenIterator(json_decode($serialized, true)); $this->preUnserialize($it); while($it->valid()) { $this->tokens[] = $tokenFactory->createToken($it); } $this->postUnserialize($it); }
php
public function unserialize($serialized) { $this->tokens = []; $tokenFactory = $this->getTokenFactory(); $it = new SerializedTokenIterator(json_decode($serialized, true)); $this->preUnserialize($it); while($it->valid()) { $this->tokens[] = $tokenFactory->createToken($it); } $this->postUnserialize($it); }
[ "public", "function", "unserialize", "(", "$", "serialized", ")", "{", "$", "this", "->", "tokens", "=", "[", "]", ";", "$", "tokenFactory", "=", "$", "this", "->", "getTokenFactory", "(", ")", ";", "$", "it", "=", "new", "SerializedTokenIterator", "(", "json_decode", "(", "$", "serialized", ",", "true", ")", ")", ";", "$", "this", "->", "preUnserialize", "(", "$", "it", ")", ";", "while", "(", "$", "it", "->", "valid", "(", ")", ")", "{", "$", "this", "->", "tokens", "[", "]", "=", "$", "tokenFactory", "->", "createToken", "(", "$", "it", ")", ";", "}", "$", "this", "->", "postUnserialize", "(", "$", "it", ")", ";", "}" ]
Reads a serialized token container and reconstitus all token objects. @param string $serialized
[ "Reads", "a", "serialized", "token", "container", "and", "reconstitus", "all", "token", "objects", "." ]
1f33fb4e95bf3b6b21c63187e503bbe612a1646c
https://github.com/koolkode/lexer/blob/1f33fb4e95bf3b6b21c63187e503bbe612a1646c/src/AbstractTokenContainer.php#L120-L135
train
koolkode/lexer
src/AbstractTokenContainer.php
AbstractTokenContainer.offsetGet
public function offsetGet($offset) { if(empty($this->tokens[$offset])) { throw new \OutOfBoundsException('No token found at offset ' . $offset); } return $this->tokens[$offset]; }
php
public function offsetGet($offset) { if(empty($this->tokens[$offset])) { throw new \OutOfBoundsException('No token found at offset ' . $offset); } return $this->tokens[$offset]; }
[ "public", "function", "offsetGet", "(", "$", "offset", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "tokens", "[", "$", "offset", "]", ")", ")", "{", "throw", "new", "\\", "OutOfBoundsException", "(", "'No token found at offset '", ".", "$", "offset", ")", ";", "}", "return", "$", "this", "->", "tokens", "[", "$", "offset", "]", ";", "}" ]
Get the token at the given position. @param integer $offset @return AbstractToken @throws \OutOfBoundsException
[ "Get", "the", "token", "at", "the", "given", "position", "." ]
1f33fb4e95bf3b6b21c63187e503bbe612a1646c
https://github.com/koolkode/lexer/blob/1f33fb4e95bf3b6b21c63187e503bbe612a1646c/src/AbstractTokenContainer.php#L187-L195
train
jenskooij/cloudcontrol
src/storage/Cache.php
Cache.clearCache
public function clearCache() { $dbInstace = $this->getDbInstance(); $sql = ' DELETE FROM `cache`; VACUUM; '; $stmt = $dbInstace->prepare($sql); if ($stmt->execute()) { return; } else { $error = $stmt->errorInfo(); $errorMsg = $error[2]; throw new \RuntimeException('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); } }
php
public function clearCache() { $dbInstace = $this->getDbInstance(); $sql = ' DELETE FROM `cache`; VACUUM; '; $stmt = $dbInstace->prepare($sql); if ($stmt->execute()) { return; } else { $error = $stmt->errorInfo(); $errorMsg = $error[2]; throw new \RuntimeException('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>'); } }
[ "public", "function", "clearCache", "(", ")", "{", "$", "dbInstace", "=", "$", "this", "->", "getDbInstance", "(", ")", ";", "$", "sql", "=", "'\n DELETE FROM `cache`;\n VACUUM;\n '", ";", "$", "stmt", "=", "$", "dbInstace", "->", "prepare", "(", "$", "sql", ")", ";", "if", "(", "$", "stmt", "->", "execute", "(", ")", ")", "{", "return", ";", "}", "else", "{", "$", "error", "=", "$", "stmt", "->", "errorInfo", "(", ")", ";", "$", "errorMsg", "=", "$", "error", "[", "2", "]", ";", "throw", "new", "\\", "RuntimeException", "(", "'SQLite Exception: '", ".", "$", "errorMsg", ".", "' in SQL: <br /><pre>'", ".", "$", "sql", ".", "'</pre>'", ")", ";", "}", "}" ]
Clears all cache
[ "Clears", "all", "cache" ]
76e5d9ac8f9c50d06d39a995d13cc03742536548
https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/storage/Cache.php#L71-L86
train
phpffcms/ffcms-core
src/Debug/DebugMeasure.php
DebugMeasure.startMeasure
public function startMeasure(string $name): void { if (App::$Debug) { App::$Debug->startMeasure($name); } }
php
public function startMeasure(string $name): void { if (App::$Debug) { App::$Debug->startMeasure($name); } }
[ "public", "function", "startMeasure", "(", "string", "$", "name", ")", ":", "void", "{", "if", "(", "App", "::", "$", "Debug", ")", "{", "App", "::", "$", "Debug", "->", "startMeasure", "(", "$", "name", ")", ";", "}", "}" ]
Start timeline measure @param string $name
[ "Start", "timeline", "measure" ]
44a309553ef9f115ccfcfd71f2ac6e381c612082
https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Debug/DebugMeasure.php#L17-L22
train
phpffcms/ffcms-core
src/Debug/DebugMeasure.php
DebugMeasure.stopMeasure
public function stopMeasure(string $name): void { if (App::$Debug) { App::$Debug->stopMeasure($name); } }
php
public function stopMeasure(string $name): void { if (App::$Debug) { App::$Debug->stopMeasure($name); } }
[ "public", "function", "stopMeasure", "(", "string", "$", "name", ")", ":", "void", "{", "if", "(", "App", "::", "$", "Debug", ")", "{", "App", "::", "$", "Debug", "->", "stopMeasure", "(", "$", "name", ")", ";", "}", "}" ]
Stop timeline measure @param string $name
[ "Stop", "timeline", "measure" ]
44a309553ef9f115ccfcfd71f2ac6e381c612082
https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Debug/DebugMeasure.php#L28-L33
train
liip/DataAggregator
src/Liip/DataAggregator/DataAggregator.php
DataAggregator.load
protected function load() { $data = array(); /** @var LoaderInterface $loader */ foreach ($this->loaders as $loader) { try { $data = array_merge($data, $loader->load()); if ($loader->stopPropagation()) { break; } } catch (LoaderException $e) { $this->getLogger()->error($e->getMessage()); } } return $data; }
php
protected function load() { $data = array(); /** @var LoaderInterface $loader */ foreach ($this->loaders as $loader) { try { $data = array_merge($data, $loader->load()); if ($loader->stopPropagation()) { break; } } catch (LoaderException $e) { $this->getLogger()->error($e->getMessage()); } } return $data; }
[ "protected", "function", "load", "(", ")", "{", "$", "data", "=", "array", "(", ")", ";", "/** @var LoaderInterface $loader */", "foreach", "(", "$", "this", "->", "loaders", "as", "$", "loader", ")", "{", "try", "{", "$", "data", "=", "array_merge", "(", "$", "data", ",", "$", "loader", "->", "load", "(", ")", ")", ";", "if", "(", "$", "loader", "->", "stopPropagation", "(", ")", ")", "{", "break", ";", "}", "}", "catch", "(", "LoaderException", "$", "e", ")", "{", "$", "this", "->", "getLogger", "(", ")", "->", "error", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "}", "return", "$", "data", ";", "}" ]
Loads and aggregates information from each registered loader. @return array
[ "Loads", "and", "aggregates", "information", "from", "each", "registered", "loader", "." ]
53da08ed3f5f24597be9f40ecf8ec44da7765e47
https://github.com/liip/DataAggregator/blob/53da08ed3f5f24597be9f40ecf8ec44da7765e47/src/Liip/DataAggregator/DataAggregator.php#L175-L193
train
phpffcms/ffcms-core
src/Helper/Type/Arr.php
Arr.merge
public static function merge(): array { $arguments = []; foreach (func_get_args() as $key => $val) { if (!Any::isArray($val)) { $val = []; } $arguments[$key] = $val; } return call_user_func_array('array_merge', $arguments); }
php
public static function merge(): array { $arguments = []; foreach (func_get_args() as $key => $val) { if (!Any::isArray($val)) { $val = []; } $arguments[$key] = $val; } return call_user_func_array('array_merge', $arguments); }
[ "public", "static", "function", "merge", "(", ")", ":", "array", "{", "$", "arguments", "=", "[", "]", ";", "foreach", "(", "func_get_args", "(", ")", "as", "$", "key", "=>", "$", "val", ")", "{", "if", "(", "!", "Any", "::", "isArray", "(", "$", "val", ")", ")", "{", "$", "val", "=", "[", "]", ";", "}", "$", "arguments", "[", "$", "key", "]", "=", "$", "val", ";", "}", "return", "call_user_func_array", "(", "'array_merge'", ",", "$", "arguments", ")", ";", "}" ]
Alternative function for array_merge - safe for use with any-type params. @return array
[ "Alternative", "function", "for", "array_merge", "-", "safe", "for", "use", "with", "any", "-", "type", "params", "." ]
44a309553ef9f115ccfcfd71f2ac6e381c612082
https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Helper/Type/Arr.php#L33-L44
train
phpffcms/ffcms-core
src/Helper/Type/Arr.php
Arr.pluck
public static function pluck(?string $key = null, ?array $array = null): array { if (!Any::isArray($array) || !Any::isStr($key)) { return []; } $output = []; foreach ($array as $item) { $object = $item[$key]; if (!self::in($object, $output)) { $output[] = $object; } } return $output; }
php
public static function pluck(?string $key = null, ?array $array = null): array { if (!Any::isArray($array) || !Any::isStr($key)) { return []; } $output = []; foreach ($array as $item) { $object = $item[$key]; if (!self::in($object, $output)) { $output[] = $object; } } return $output; }
[ "public", "static", "function", "pluck", "(", "?", "string", "$", "key", "=", "null", ",", "?", "array", "$", "array", "=", "null", ")", ":", "array", "{", "if", "(", "!", "Any", "::", "isArray", "(", "$", "array", ")", "||", "!", "Any", "::", "isStr", "(", "$", "key", ")", ")", "{", "return", "[", "]", ";", "}", "$", "output", "=", "[", "]", ";", "foreach", "(", "$", "array", "as", "$", "item", ")", "{", "$", "object", "=", "$", "item", "[", "$", "key", "]", ";", "if", "(", "!", "self", "::", "in", "(", "$", "object", ",", "$", "output", ")", ")", "{", "$", "output", "[", "]", "=", "$", "object", ";", "}", "}", "return", "$", "output", ";", "}" ]
Extract from multi-array elements by key to single-level array @param string $key @param array $array @return array
[ "Extract", "from", "multi", "-", "array", "elements", "by", "key", "to", "single", "-", "level", "array" ]
44a309553ef9f115ccfcfd71f2ac6e381c612082
https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Helper/Type/Arr.php#L100-L114
train
phpffcms/ffcms-core
src/Helper/Type/Arr.php
Arr.exportVar
public static function exportVar($var, $indent = null, $guessTypes = false) { switch (gettype($var)) { case 'string': // guess boolean type for "1" and "0" if (true === $guessTypes) { if ($var === '0' || $var === '') { return 'false'; } elseif ($var === '1') { return 'true'; } } return '\'' . $var . '\''; case 'array': $indexed = array_keys($var) === range(0, count($var) - 1); $row = []; foreach ($var as $key => $value) { $row[] = $indent . "\t" . ($indexed ? null : self::exportVar($key, null, $guessTypes) . ' => ') . self::exportVar($value, $indent . "\t", $guessTypes); } return "[\n" . implode(",\n", $row) . "\n" . $indent . ']'; case 'boolean': return $var ? 'true' : 'false'; default: return var_export($var, true); } }
php
public static function exportVar($var, $indent = null, $guessTypes = false) { switch (gettype($var)) { case 'string': // guess boolean type for "1" and "0" if (true === $guessTypes) { if ($var === '0' || $var === '') { return 'false'; } elseif ($var === '1') { return 'true'; } } return '\'' . $var . '\''; case 'array': $indexed = array_keys($var) === range(0, count($var) - 1); $row = []; foreach ($var as $key => $value) { $row[] = $indent . "\t" . ($indexed ? null : self::exportVar($key, null, $guessTypes) . ' => ') . self::exportVar($value, $indent . "\t", $guessTypes); } return "[\n" . implode(",\n", $row) . "\n" . $indent . ']'; case 'boolean': return $var ? 'true' : 'false'; default: return var_export($var, true); } }
[ "public", "static", "function", "exportVar", "(", "$", "var", ",", "$", "indent", "=", "null", ",", "$", "guessTypes", "=", "false", ")", "{", "switch", "(", "gettype", "(", "$", "var", ")", ")", "{", "case", "'string'", ":", "// guess boolean type for \"1\" and \"0\"", "if", "(", "true", "===", "$", "guessTypes", ")", "{", "if", "(", "$", "var", "===", "'0'", "||", "$", "var", "===", "''", ")", "{", "return", "'false'", ";", "}", "elseif", "(", "$", "var", "===", "'1'", ")", "{", "return", "'true'", ";", "}", "}", "return", "'\\''", ".", "$", "var", ".", "'\\''", ";", "case", "'array'", ":", "$", "indexed", "=", "array_keys", "(", "$", "var", ")", "===", "range", "(", "0", ",", "count", "(", "$", "var", ")", "-", "1", ")", ";", "$", "row", "=", "[", "]", ";", "foreach", "(", "$", "var", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "row", "[", "]", "=", "$", "indent", ".", "\"\\t\"", ".", "(", "$", "indexed", "?", "null", ":", "self", "::", "exportVar", "(", "$", "key", ",", "null", ",", "$", "guessTypes", ")", ".", "' => '", ")", ".", "self", "::", "exportVar", "(", "$", "value", ",", "$", "indent", ".", "\"\\t\"", ",", "$", "guessTypes", ")", ";", "}", "return", "\"[\\n\"", ".", "implode", "(", "\",\\n\"", ",", "$", "row", ")", ".", "\"\\n\"", ".", "$", "indent", ".", "']'", ";", "case", "'boolean'", ":", "return", "$", "var", "?", "'true'", ":", "'false'", ";", "default", ":", "return", "var_export", "(", "$", "var", ",", "true", ")", ";", "}", "}" ]
Alternative var_export function for php >= 5.4 syntax @param array|string $var @param string|null $indent @param boolean $guessTypes @return string|null
[ "Alternative", "var_export", "function", "for", "php", ">", "=", "5", ".", "4", "syntax" ]
44a309553ef9f115ccfcfd71f2ac6e381c612082
https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Helper/Type/Arr.php#L123-L150
train
PSchwisow/phergie-irc-plugin-react-url-shorten
src/Adapter/AbstractAdapter.php
AbstractAdapter.getApiRequest
public function getApiRequest($apiUrl, $deferred) { return new Request([ 'url' => $apiUrl, 'resolveCallback' => function (Response $response) use ($deferred) { $data = (string) $response->getBody(); $headers = $response->getHeaders(); $code = $response->getStatusCode(); $shortUrl = $this->handleResponse($data, $headers, $code); if ($shortUrl === false) { $deferred->reject(); } else { $deferred->resolve($shortUrl); } }, 'rejectCallback' => [$deferred, 'reject'] ]); }
php
public function getApiRequest($apiUrl, $deferred) { return new Request([ 'url' => $apiUrl, 'resolveCallback' => function (Response $response) use ($deferred) { $data = (string) $response->getBody(); $headers = $response->getHeaders(); $code = $response->getStatusCode(); $shortUrl = $this->handleResponse($data, $headers, $code); if ($shortUrl === false) { $deferred->reject(); } else { $deferred->resolve($shortUrl); } }, 'rejectCallback' => [$deferred, 'reject'] ]); }
[ "public", "function", "getApiRequest", "(", "$", "apiUrl", ",", "$", "deferred", ")", "{", "return", "new", "Request", "(", "[", "'url'", "=>", "$", "apiUrl", ",", "'resolveCallback'", "=>", "function", "(", "Response", "$", "response", ")", "use", "(", "$", "deferred", ")", "{", "$", "data", "=", "(", "string", ")", "$", "response", "->", "getBody", "(", ")", ";", "$", "headers", "=", "$", "response", "->", "getHeaders", "(", ")", ";", "$", "code", "=", "$", "response", "->", "getStatusCode", "(", ")", ";", "$", "shortUrl", "=", "$", "this", "->", "handleResponse", "(", "$", "data", ",", "$", "headers", ",", "$", "code", ")", ";", "if", "(", "$", "shortUrl", "===", "false", ")", "{", "$", "deferred", "->", "reject", "(", ")", ";", "}", "else", "{", "$", "deferred", "->", "resolve", "(", "$", "shortUrl", ")", ";", "}", "}", ",", "'rejectCallback'", "=>", "[", "$", "deferred", ",", "'reject'", "]", "]", ")", ";", "}" ]
Create the API Request @param string $apiUrl @param Deferred $deferred @return Request
[ "Create", "the", "API", "Request" ]
6147d7541520a99fe00e92e334a556650b3daa1f
https://github.com/PSchwisow/phergie-irc-plugin-react-url-shorten/blob/6147d7541520a99fe00e92e334a556650b3daa1f/src/Adapter/AbstractAdapter.php#L67-L85
train
codemojo-dr/startkit-php-sdk
src/CodeMojo/Client/Http/HttpGuzzle.php
HttpGuzzle.fetch
public function fetch($protected_resource_url, $parameters = array(), $http_method = self::HTTP_METHOD_GET, array $http_headers = array(), $form_content_type = self::HTTP_FORM_CONTENT_TYPE_MULTIPART) { if ($this->access_token) { switch ($this->access_token_type) { case self::ACCESS_TOKEN_URI: if (is_array($parameters)) { $parameters[$this->access_token_param_name] = $this->access_token; } else { throw new InvalidArgumentException( 'You need to give parameters as array if you want to give the token within the URI.', InvalidArgumentException::REQUIRE_PARAMS_AS_ARRAY ); } break; case self::ACCESS_TOKEN_BEARER: $http_headers['Authorization'] = 'Bearer ' . $this->access_token; break; case self::ACCESS_TOKEN_OAUTH: $http_headers['Authorization'] = 'OAuth ' . $this->access_token; break; case self::ACCESS_TOKEN_MAC: $http_headers['Authorization'] = 'MAC ' . $this->generateMACSignature($protected_resource_url, $parameters, $http_method); break; default: throw new Exception('Unknown access token type.', Exception::INVALID_ACCESS_TOKEN_TYPE); break; } } $http_headers['User-Agent'] = 'drewards/sdk v' . Endpoints::API_VERSION; return $this->executeRequest($protected_resource_url, $parameters, $http_method, $http_headers, $form_content_type); }
php
public function fetch($protected_resource_url, $parameters = array(), $http_method = self::HTTP_METHOD_GET, array $http_headers = array(), $form_content_type = self::HTTP_FORM_CONTENT_TYPE_MULTIPART) { if ($this->access_token) { switch ($this->access_token_type) { case self::ACCESS_TOKEN_URI: if (is_array($parameters)) { $parameters[$this->access_token_param_name] = $this->access_token; } else { throw new InvalidArgumentException( 'You need to give parameters as array if you want to give the token within the URI.', InvalidArgumentException::REQUIRE_PARAMS_AS_ARRAY ); } break; case self::ACCESS_TOKEN_BEARER: $http_headers['Authorization'] = 'Bearer ' . $this->access_token; break; case self::ACCESS_TOKEN_OAUTH: $http_headers['Authorization'] = 'OAuth ' . $this->access_token; break; case self::ACCESS_TOKEN_MAC: $http_headers['Authorization'] = 'MAC ' . $this->generateMACSignature($protected_resource_url, $parameters, $http_method); break; default: throw new Exception('Unknown access token type.', Exception::INVALID_ACCESS_TOKEN_TYPE); break; } } $http_headers['User-Agent'] = 'drewards/sdk v' . Endpoints::API_VERSION; return $this->executeRequest($protected_resource_url, $parameters, $http_method, $http_headers, $form_content_type); }
[ "public", "function", "fetch", "(", "$", "protected_resource_url", ",", "$", "parameters", "=", "array", "(", ")", ",", "$", "http_method", "=", "self", "::", "HTTP_METHOD_GET", ",", "array", "$", "http_headers", "=", "array", "(", ")", ",", "$", "form_content_type", "=", "self", "::", "HTTP_FORM_CONTENT_TYPE_MULTIPART", ")", "{", "if", "(", "$", "this", "->", "access_token", ")", "{", "switch", "(", "$", "this", "->", "access_token_type", ")", "{", "case", "self", "::", "ACCESS_TOKEN_URI", ":", "if", "(", "is_array", "(", "$", "parameters", ")", ")", "{", "$", "parameters", "[", "$", "this", "->", "access_token_param_name", "]", "=", "$", "this", "->", "access_token", ";", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "'You need to give parameters as array if you want to give the token within the URI.'", ",", "InvalidArgumentException", "::", "REQUIRE_PARAMS_AS_ARRAY", ")", ";", "}", "break", ";", "case", "self", "::", "ACCESS_TOKEN_BEARER", ":", "$", "http_headers", "[", "'Authorization'", "]", "=", "'Bearer '", ".", "$", "this", "->", "access_token", ";", "break", ";", "case", "self", "::", "ACCESS_TOKEN_OAUTH", ":", "$", "http_headers", "[", "'Authorization'", "]", "=", "'OAuth '", ".", "$", "this", "->", "access_token", ";", "break", ";", "case", "self", "::", "ACCESS_TOKEN_MAC", ":", "$", "http_headers", "[", "'Authorization'", "]", "=", "'MAC '", ".", "$", "this", "->", "generateMACSignature", "(", "$", "protected_resource_url", ",", "$", "parameters", ",", "$", "http_method", ")", ";", "break", ";", "default", ":", "throw", "new", "Exception", "(", "'Unknown access token type.'", ",", "Exception", "::", "INVALID_ACCESS_TOKEN_TYPE", ")", ";", "break", ";", "}", "}", "$", "http_headers", "[", "'User-Agent'", "]", "=", "'drewards/sdk v'", ".", "Endpoints", "::", "API_VERSION", ";", "return", "$", "this", "->", "executeRequest", "(", "$", "protected_resource_url", ",", "$", "parameters", ",", "$", "http_method", ",", "$", "http_headers", ",", "$", "form_content_type", ")", ";", "}" ]
Fetch a protected resource @param string $protected_ressource_url Protected resource URL @param array $parameters Array of parameters @param string $http_method HTTP Method to use (POST, PUT, GET, HEAD, DELETE) @param array $http_headers HTTP headers @param int $form_content_type HTTP form content type to use @return array
[ "Fetch", "a", "protected", "resource" ]
cd2227e1a221be2cd75dc96d1c9e0acfda936fb3
https://github.com/codemojo-dr/startkit-php-sdk/blob/cd2227e1a221be2cd75dc96d1c9e0acfda936fb3/src/CodeMojo/Client/Http/HttpGuzzle.php#L153-L183
train
brightnucleus/options-store
src/ConfigurableOptionsStore.php
ConfigurableOptionsStore.configureRepository
protected function configureRepository(Config $config): OptionRepository { $repositories = []; foreach ($config->getAll() as $class => $optionsArray) { $prefix = array_key_exists(OptionRepository::PREFIX, $optionsArray) ? $optionsArray[OptionRepository::PREFIX] : ''; $options = $this->configureOptions((array)$optionsArray); try { $repositories[] = $this->isPrefixable($class) ? new $class($prefix, $options->getValues()) : new $class($options->getValues()); } catch (Exception $exception) { throw InvalidOptionRepository::fromInstantiationException($class, $exception); } } if (empty($repositories)) { throw InvalidOptionRepository::fromConfig($config); } if (1 === count($repositories)) { return $repositories[0]; } return new AggregateOptionRepository($repositories); }
php
protected function configureRepository(Config $config): OptionRepository { $repositories = []; foreach ($config->getAll() as $class => $optionsArray) { $prefix = array_key_exists(OptionRepository::PREFIX, $optionsArray) ? $optionsArray[OptionRepository::PREFIX] : ''; $options = $this->configureOptions((array)$optionsArray); try { $repositories[] = $this->isPrefixable($class) ? new $class($prefix, $options->getValues()) : new $class($options->getValues()); } catch (Exception $exception) { throw InvalidOptionRepository::fromInstantiationException($class, $exception); } } if (empty($repositories)) { throw InvalidOptionRepository::fromConfig($config); } if (1 === count($repositories)) { return $repositories[0]; } return new AggregateOptionRepository($repositories); }
[ "protected", "function", "configureRepository", "(", "Config", "$", "config", ")", ":", "OptionRepository", "{", "$", "repositories", "=", "[", "]", ";", "foreach", "(", "$", "config", "->", "getAll", "(", ")", "as", "$", "class", "=>", "$", "optionsArray", ")", "{", "$", "prefix", "=", "array_key_exists", "(", "OptionRepository", "::", "PREFIX", ",", "$", "optionsArray", ")", "?", "$", "optionsArray", "[", "OptionRepository", "::", "PREFIX", "]", ":", "''", ";", "$", "options", "=", "$", "this", "->", "configureOptions", "(", "(", "array", ")", "$", "optionsArray", ")", ";", "try", "{", "$", "repositories", "[", "]", "=", "$", "this", "->", "isPrefixable", "(", "$", "class", ")", "?", "new", "$", "class", "(", "$", "prefix", ",", "$", "options", "->", "getValues", "(", ")", ")", ":", "new", "$", "class", "(", "$", "options", "->", "getValues", "(", ")", ")", ";", "}", "catch", "(", "Exception", "$", "exception", ")", "{", "throw", "InvalidOptionRepository", "::", "fromInstantiationException", "(", "$", "class", ",", "$", "exception", ")", ";", "}", "}", "if", "(", "empty", "(", "$", "repositories", ")", ")", "{", "throw", "InvalidOptionRepository", "::", "fromConfig", "(", "$", "config", ")", ";", "}", "if", "(", "1", "===", "count", "(", "$", "repositories", ")", ")", "{", "return", "$", "repositories", "[", "0", "]", ";", "}", "return", "new", "AggregateOptionRepository", "(", "$", "repositories", ")", ";", "}" ]
Configure a single repository from a Config file. This will automatically regroup an array of repositories into an AggregateOptionRepository. @since 0.1.4 @param Config $config Config instance to use. @return OptionRepository Option repository that was built from the passed-in repository. @throws InvalidOptionRepository If the repository could not be configured. @throws InvalidOptionRepository If the repository could not be instantiated.
[ "Configure", "a", "single", "repository", "from", "a", "Config", "file", "." ]
9a9ef2a160bbacd69fe3e9db0be8ed89e6905ef1
https://github.com/brightnucleus/options-store/blob/9a9ef2a160bbacd69fe3e9db0be8ed89e6905ef1/src/ConfigurableOptionsStore.php#L70-L98
train
brightnucleus/options-store
src/ConfigurableOptionsStore.php
ConfigurableOptionsStore.configureOptions
protected function configureOptions(array $optionsArray): OptionCollection { $options = new OptionCollection\ArrayOptionCollection(); foreach ($optionsArray as $key => $option) { if ($key === OptionRepository::PREFIX) { continue; } if ($option instanceof Option) { $options->add($option); continue; } if (is_callable($option)) { $option = $option($this->config); } if (is_string($option)) { $option = new $option(); } if (! $option instanceof Option) { throw InvalidOption::fromOption($option); } $options->add($option); } return $options; }
php
protected function configureOptions(array $optionsArray): OptionCollection { $options = new OptionCollection\ArrayOptionCollection(); foreach ($optionsArray as $key => $option) { if ($key === OptionRepository::PREFIX) { continue; } if ($option instanceof Option) { $options->add($option); continue; } if (is_callable($option)) { $option = $option($this->config); } if (is_string($option)) { $option = new $option(); } if (! $option instanceof Option) { throw InvalidOption::fromOption($option); } $options->add($option); } return $options; }
[ "protected", "function", "configureOptions", "(", "array", "$", "optionsArray", ")", ":", "OptionCollection", "{", "$", "options", "=", "new", "OptionCollection", "\\", "ArrayOptionCollection", "(", ")", ";", "foreach", "(", "$", "optionsArray", "as", "$", "key", "=>", "$", "option", ")", "{", "if", "(", "$", "key", "===", "OptionRepository", "::", "PREFIX", ")", "{", "continue", ";", "}", "if", "(", "$", "option", "instanceof", "Option", ")", "{", "$", "options", "->", "add", "(", "$", "option", ")", ";", "continue", ";", "}", "if", "(", "is_callable", "(", "$", "option", ")", ")", "{", "$", "option", "=", "$", "option", "(", "$", "this", "->", "config", ")", ";", "}", "if", "(", "is_string", "(", "$", "option", ")", ")", "{", "$", "option", "=", "new", "$", "option", "(", ")", ";", "}", "if", "(", "!", "$", "option", "instanceof", "Option", ")", "{", "throw", "InvalidOption", "::", "fromOption", "(", "$", "option", ")", ";", "}", "$", "options", "->", "add", "(", "$", "option", ")", ";", "}", "return", "$", "options", ";", "}" ]
Build a collection of options from an array of Config values. @since 0.1.0 @param array $optionsArray Array of config values that are used to build the options. @return OptionCollection Collection of instantiated options.
[ "Build", "a", "collection", "of", "options", "from", "an", "array", "of", "Config", "values", "." ]
9a9ef2a160bbacd69fe3e9db0be8ed89e6905ef1
https://github.com/brightnucleus/options-store/blob/9a9ef2a160bbacd69fe3e9db0be8ed89e6905ef1/src/ConfigurableOptionsStore.php#L109-L138
train
brightnucleus/options-store
src/ConfigurableOptionsStore.php
ConfigurableOptionsStore.isPrefixable
protected function isPrefixable($objectOrClassName): bool { if (is_string($objectOrClassName)) { return in_array(Prefixable::class, class_implements($objectOrClassName), true); } if (is_object($objectOrClassName)) { return $objectOrClassName instanceof Prefixable; } return false; }
php
protected function isPrefixable($objectOrClassName): bool { if (is_string($objectOrClassName)) { return in_array(Prefixable::class, class_implements($objectOrClassName), true); } if (is_object($objectOrClassName)) { return $objectOrClassName instanceof Prefixable; } return false; }
[ "protected", "function", "isPrefixable", "(", "$", "objectOrClassName", ")", ":", "bool", "{", "if", "(", "is_string", "(", "$", "objectOrClassName", ")", ")", "{", "return", "in_array", "(", "Prefixable", "::", "class", ",", "class_implements", "(", "$", "objectOrClassName", ")", ",", "true", ")", ";", "}", "if", "(", "is_object", "(", "$", "objectOrClassName", ")", ")", "{", "return", "$", "objectOrClassName", "instanceof", "Prefixable", ";", "}", "return", "false", ";", "}" ]
Check whether a FQCN or an object implements the Prefixable interface. @since 0.1.0 @param OptionRepository|string $objectOrClassName Object instance or FQCN. @return bool Whether the passed-in argument is prefixable.
[ "Check", "whether", "a", "FQCN", "or", "an", "object", "implements", "the", "Prefixable", "interface", "." ]
9a9ef2a160bbacd69fe3e9db0be8ed89e6905ef1
https://github.com/brightnucleus/options-store/blob/9a9ef2a160bbacd69fe3e9db0be8ed89e6905ef1/src/ConfigurableOptionsStore.php#L149-L160
train
Sectorr/Core
Sectorr/Core/Config.php
Config.get
public static function get($key) { $config = json_decode(file_get_contents(PATH . '/app/config.json'), true); if (! array_key_exists($key, $config)) { throw new ConfigItemNotSetException($key); } return $config[$key]; }
php
public static function get($key) { $config = json_decode(file_get_contents(PATH . '/app/config.json'), true); if (! array_key_exists($key, $config)) { throw new ConfigItemNotSetException($key); } return $config[$key]; }
[ "public", "static", "function", "get", "(", "$", "key", ")", "{", "$", "config", "=", "json_decode", "(", "file_get_contents", "(", "PATH", ".", "'/app/config.json'", ")", ",", "true", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "key", ",", "$", "config", ")", ")", "{", "throw", "new", "ConfigItemNotSetException", "(", "$", "key", ")", ";", "}", "return", "$", "config", "[", "$", "key", "]", ";", "}" ]
Get Config item by key. @param $key @return mixed @throws ConfigItemNotSetException
[ "Get", "Config", "item", "by", "key", "." ]
31df852dc6cc61642b0b87d9f0ae56c8e7da5a27
https://github.com/Sectorr/Core/blob/31df852dc6cc61642b0b87d9f0ae56c8e7da5a27/Sectorr/Core/Config.php#L16-L25
train
johnkrovitch/Sam
Task/Task.php
Task.setSources
public function setSources(array $sources) { $parameters = $this ->configuration ->getParameters(); $parameters['sources'] = $sources; $this ->configuration ->setParameters($parameters); }
php
public function setSources(array $sources) { $parameters = $this ->configuration ->getParameters(); $parameters['sources'] = $sources; $this ->configuration ->setParameters($parameters); }
[ "public", "function", "setSources", "(", "array", "$", "sources", ")", "{", "$", "parameters", "=", "$", "this", "->", "configuration", "->", "getParameters", "(", ")", ";", "$", "parameters", "[", "'sources'", "]", "=", "$", "sources", ";", "$", "this", "->", "configuration", "->", "setParameters", "(", "$", "parameters", ")", ";", "}" ]
Define the task new sources. @param array $sources
[ "Define", "the", "task", "new", "sources", "." ]
fbd3770c11eecc0a6d8070f439f149062316f606
https://github.com/johnkrovitch/Sam/blob/fbd3770c11eecc0a6d8070f439f149062316f606/Task/Task.php#L67-L77
train
jabernardo/lollipop-php
Library/Session.php
Session.getDriver
static private function getDriver() { if (self::$_driver != null) return self::$_driver; $driver = Utils::spare(Config::get('session.driver'), 'default'); switch (strtolower($driver)) { case 'cookie': self::$_driver = new \Lollipop\Session\Cookie(); break; case 'default': default: self::$_driver = new \Lollipop\Session\Session(); break; } return self::$_driver; }
php
static private function getDriver() { if (self::$_driver != null) return self::$_driver; $driver = Utils::spare(Config::get('session.driver'), 'default'); switch (strtolower($driver)) { case 'cookie': self::$_driver = new \Lollipop\Session\Cookie(); break; case 'default': default: self::$_driver = new \Lollipop\Session\Session(); break; } return self::$_driver; }
[ "static", "private", "function", "getDriver", "(", ")", "{", "if", "(", "self", "::", "$", "_driver", "!=", "null", ")", "return", "self", "::", "$", "_driver", ";", "$", "driver", "=", "Utils", "::", "spare", "(", "Config", "::", "get", "(", "'session.driver'", ")", ",", "'default'", ")", ";", "switch", "(", "strtolower", "(", "$", "driver", ")", ")", "{", "case", "'cookie'", ":", "self", "::", "$", "_driver", "=", "new", "\\", "Lollipop", "\\", "Session", "\\", "Cookie", "(", ")", ";", "break", ";", "case", "'default'", ":", "default", ":", "self", "::", "$", "_driver", "=", "new", "\\", "Lollipop", "\\", "Session", "\\", "Session", "(", ")", ";", "break", ";", "}", "return", "self", "::", "$", "_driver", ";", "}" ]
Get session driver @return object
[ "Get", "session", "driver" ]
004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5
https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/Session.php#L32-L49
train
kambalabs/KmbZendDbInfrastructure
src/KmbZendDbInfrastructure/Proxy/RevisionProxy.php
RevisionProxy.addGroup
public function addGroup($group) { if ($this->groups === null) { $this->setGroups($this->groupRepository->getAllByRevision($this)); } $this->groups[] = $group; return $this; }
php
public function addGroup($group) { if ($this->groups === null) { $this->setGroups($this->groupRepository->getAllByRevision($this)); } $this->groups[] = $group; return $this; }
[ "public", "function", "addGroup", "(", "$", "group", ")", "{", "if", "(", "$", "this", "->", "groups", "===", "null", ")", "{", "$", "this", "->", "setGroups", "(", "$", "this", "->", "groupRepository", "->", "getAllByRevision", "(", "$", "this", ")", ")", ";", "}", "$", "this", "->", "groups", "[", "]", "=", "$", "group", ";", "return", "$", "this", ";", "}" ]
Add a group. @param \KmbDomain\Model\GroupInterface $group @return RevisionProxy
[ "Add", "a", "group", "." ]
9bf4df4272d2064965202d0e689f944d56a4c6bb
https://github.com/kambalabs/KmbZendDbInfrastructure/blob/9bf4df4272d2064965202d0e689f944d56a4c6bb/src/KmbZendDbInfrastructure/Proxy/RevisionProxy.php#L244-L251
train
kambalabs/KmbZendDbInfrastructure
src/KmbZendDbInfrastructure/Proxy/RevisionProxy.php
RevisionProxy.getGroups
public function getGroups() { if ($this->groups === null) { $this->setGroups($this->groupRepository->getAllByRevision($this)); } return $this->groups; }
php
public function getGroups() { if ($this->groups === null) { $this->setGroups($this->groupRepository->getAllByRevision($this)); } return $this->groups; }
[ "public", "function", "getGroups", "(", ")", "{", "if", "(", "$", "this", "->", "groups", "===", "null", ")", "{", "$", "this", "->", "setGroups", "(", "$", "this", "->", "groupRepository", "->", "getAllByRevision", "(", "$", "this", ")", ")", ";", "}", "return", "$", "this", "->", "groups", ";", "}" ]
Get Groups. @return \KmbDomain\Model\GroupInterface[]
[ "Get", "Groups", "." ]
9bf4df4272d2064965202d0e689f944d56a4c6bb
https://github.com/kambalabs/KmbZendDbInfrastructure/blob/9bf4df4272d2064965202d0e689f944d56a4c6bb/src/KmbZendDbInfrastructure/Proxy/RevisionProxy.php#L258-L264
train
locomotivemtl/charcoal-queue
src/Charcoal/Queue/QueueItemTrait.php
QueueItemTrait.setQueueItemData
public function setQueueItemData(array $data) { if (isset($data['queue_id'])) { $this->setQueueId($data['queue_id']); } if (isset($data['processed'])) { $this->setProcessed($data['processed']); } if (isset($data['queued_date'])) { $this->setQueuedDate($data['queue_date']); } if (isset($data['processed_date'])) { $this->setProcessedDate($data['processed_date']); } return $this; }
php
public function setQueueItemData(array $data) { if (isset($data['queue_id'])) { $this->setQueueId($data['queue_id']); } if (isset($data['processed'])) { $this->setProcessed($data['processed']); } if (isset($data['queued_date'])) { $this->setQueuedDate($data['queue_date']); } if (isset($data['processed_date'])) { $this->setProcessedDate($data['processed_date']); } return $this; }
[ "public", "function", "setQueueItemData", "(", "array", "$", "data", ")", "{", "if", "(", "isset", "(", "$", "data", "[", "'queue_id'", "]", ")", ")", "{", "$", "this", "->", "setQueueId", "(", "$", "data", "[", "'queue_id'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'processed'", "]", ")", ")", "{", "$", "this", "->", "setProcessed", "(", "$", "data", "[", "'processed'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'queued_date'", "]", ")", ")", "{", "$", "this", "->", "setQueuedDate", "(", "$", "data", "[", "'queue_date'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'processed_date'", "]", ")", ")", "{", "$", "this", "->", "setProcessedDate", "(", "$", "data", "[", "'processed_date'", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set the queue item's data. @param array $data The queue item data to set. @return self
[ "Set", "the", "queue", "item", "s", "data", "." ]
90c47581cd35fbb554eca513f909171a70325b44
https://github.com/locomotivemtl/charcoal-queue/blob/90c47581cd35fbb554eca513f909171a70325b44/src/Charcoal/Queue/QueueItemTrait.php#L73-L92
train
marando/Units
src/Marando/Units/Velocity.php
Velocity.create
public static function create($value, $units) { // Explode units... list($distUnit, $timeUnit) = static::explUnits($units); // Create distance and time placeholders. $dist = Distance::m(0); $time = Time::sec(0); // Set each distance/time unit. $dist->{$distUnit} = $value; $time->{$timeUnit} = 1; // Create the velocity and set the format. $velocity = new Velocity($dist, $time); $velocity->format = static::FORMAT_DEFAULT . $units; return $velocity; }
php
public static function create($value, $units) { // Explode units... list($distUnit, $timeUnit) = static::explUnits($units); // Create distance and time placeholders. $dist = Distance::m(0); $time = Time::sec(0); // Set each distance/time unit. $dist->{$distUnit} = $value; $time->{$timeUnit} = 1; // Create the velocity and set the format. $velocity = new Velocity($dist, $time); $velocity->format = static::FORMAT_DEFAULT . $units; return $velocity; }
[ "public", "static", "function", "create", "(", "$", "value", ",", "$", "units", ")", "{", "// Explode units...", "list", "(", "$", "distUnit", ",", "$", "timeUnit", ")", "=", "static", "::", "explUnits", "(", "$", "units", ")", ";", "// Create distance and time placeholders.", "$", "dist", "=", "Distance", "::", "m", "(", "0", ")", ";", "$", "time", "=", "Time", "::", "sec", "(", "0", ")", ";", "// Set each distance/time unit.", "$", "dist", "->", "{", "$", "distUnit", "}", "=", "$", "value", ";", "$", "time", "->", "{", "$", "timeUnit", "}", "=", "1", ";", "// Create the velocity and set the format.", "$", "velocity", "=", "new", "Velocity", "(", "$", "dist", ",", "$", "time", ")", ";", "$", "velocity", "->", "format", "=", "static", "::", "FORMAT_DEFAULT", ".", "$", "units", ";", "return", "$", "velocity", ";", "}" ]
Creates a new velocity from a value and velocity unit. @param $value Value of the velocity @param $units Unit of measurement, e.g. m/s @return static
[ "Creates", "a", "new", "velocity", "from", "a", "value", "and", "velocity", "unit", "." ]
1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70
https://github.com/marando/Units/blob/1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70/src/Marando/Units/Velocity.php#L84-L102
train
marando/Units
src/Marando/Units/Velocity.php
Velocity.units
public function units($units, $string = false) { // Explode units list($distUnit, $timeUnit) = static::explUnits($units); // Get and format the distance and time unit values $distVal = $this->dist->unit($distUnit); $timeVal = $this->time->{$timeUnit}; $distVal = number_format($distVal, 99, '.', ''); $timeVal = number_format($timeVal, 99, '.', ''); // Calculate the velocity value $velocity = bcdiv($distVal, $timeVal, 999); $velocity = static::removeTrailingZeros($velocity); // Return either string or double return $string ? $velocity : (double)$velocity; }
php
public function units($units, $string = false) { // Explode units list($distUnit, $timeUnit) = static::explUnits($units); // Get and format the distance and time unit values $distVal = $this->dist->unit($distUnit); $timeVal = $this->time->{$timeUnit}; $distVal = number_format($distVal, 99, '.', ''); $timeVal = number_format($timeVal, 99, '.', ''); // Calculate the velocity value $velocity = bcdiv($distVal, $timeVal, 999); $velocity = static::removeTrailingZeros($velocity); // Return either string or double return $string ? $velocity : (double)$velocity; }
[ "public", "function", "units", "(", "$", "units", ",", "$", "string", "=", "false", ")", "{", "// Explode units", "list", "(", "$", "distUnit", ",", "$", "timeUnit", ")", "=", "static", "::", "explUnits", "(", "$", "units", ")", ";", "// Get and format the distance and time unit values", "$", "distVal", "=", "$", "this", "->", "dist", "->", "unit", "(", "$", "distUnit", ")", ";", "$", "timeVal", "=", "$", "this", "->", "time", "->", "{", "$", "timeUnit", "}", ";", "$", "distVal", "=", "number_format", "(", "$", "distVal", ",", "99", ",", "'.'", ",", "''", ")", ";", "$", "timeVal", "=", "number_format", "(", "$", "timeVal", ",", "99", ",", "'.'", ",", "''", ")", ";", "// Calculate the velocity value", "$", "velocity", "=", "bcdiv", "(", "$", "distVal", ",", "$", "timeVal", ",", "999", ")", ";", "$", "velocity", "=", "static", "::", "removeTrailingZeros", "(", "$", "velocity", ")", ";", "// Return either string or double", "return", "$", "string", "?", "$", "velocity", ":", "(", "double", ")", "$", "velocity", ";", "}" ]
Gets the value of this instance at the specified units. @param $units Units, e.g. m/s @param bool $string True to return as string for higher precision @return double|string
[ "Gets", "the", "value", "of", "this", "instance", "at", "the", "specified", "units", "." ]
1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70
https://github.com/marando/Units/blob/1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70/src/Marando/Units/Velocity.php#L279-L296
train
marando/Units
src/Marando/Units/Velocity.php
Velocity.format
public function format($format) { // Sprintf and unit regex $pattern = '/(%(?:\d+\$)?[+-]?(?:[ 0]|\'.{1})?-?\d*(?:\.\d+)?[bcdeEufFgGosxX])([ ]*)(.*)/'; // Check if string has sprintf and unit... if (preg_match_all($pattern, $format, $m)) { $sprintf = $m[1][0]; $space = $m[2][0]; $units = $m[3][0]; $velocity = $this->units($units); // Should just display as scientific notation? if (sprintf($sprintf, $velocity) == 0 || $velocity > 10e9) { // Change sprintf to use e for scientific notation $sprintf = preg_replace('/[bcdeEufFgGosxX]/', 'e', $sprintf); } // Return format return sprintf($sprintf, $velocity) . $space . $units; } }
php
public function format($format) { // Sprintf and unit regex $pattern = '/(%(?:\d+\$)?[+-]?(?:[ 0]|\'.{1})?-?\d*(?:\.\d+)?[bcdeEufFgGosxX])([ ]*)(.*)/'; // Check if string has sprintf and unit... if (preg_match_all($pattern, $format, $m)) { $sprintf = $m[1][0]; $space = $m[2][0]; $units = $m[3][0]; $velocity = $this->units($units); // Should just display as scientific notation? if (sprintf($sprintf, $velocity) == 0 || $velocity > 10e9) { // Change sprintf to use e for scientific notation $sprintf = preg_replace('/[bcdeEufFgGosxX]/', 'e', $sprintf); } // Return format return sprintf($sprintf, $velocity) . $space . $units; } }
[ "public", "function", "format", "(", "$", "format", ")", "{", "// Sprintf and unit regex", "$", "pattern", "=", "'/(%(?:\\d+\\$)?[+-]?(?:[ 0]|\\'.{1})?-?\\d*(?:\\.\\d+)?[bcdeEufFgGosxX])([ ]*)(.*)/'", ";", "// Check if string has sprintf and unit...", "if", "(", "preg_match_all", "(", "$", "pattern", ",", "$", "format", ",", "$", "m", ")", ")", "{", "$", "sprintf", "=", "$", "m", "[", "1", "]", "[", "0", "]", ";", "$", "space", "=", "$", "m", "[", "2", "]", "[", "0", "]", ";", "$", "units", "=", "$", "m", "[", "3", "]", "[", "0", "]", ";", "$", "velocity", "=", "$", "this", "->", "units", "(", "$", "units", ")", ";", "// Should just display as scientific notation?", "if", "(", "sprintf", "(", "$", "sprintf", ",", "$", "velocity", ")", "==", "0", "||", "$", "velocity", ">", "10e9", ")", "{", "// Change sprintf to use e for scientific notation", "$", "sprintf", "=", "preg_replace", "(", "'/[bcdeEufFgGosxX]/'", ",", "'e'", ",", "$", "sprintf", ")", ";", "}", "// Return format", "return", "sprintf", "(", "$", "sprintf", ",", "$", "velocity", ")", ".", "$", "space", ".", "$", "units", ";", "}", "}" ]
Formats this instance as a string with the provided format. @param $format Format, e.g. %1.3f m/s @return string
[ "Formats", "this", "instance", "as", "a", "string", "with", "the", "provided", "format", "." ]
1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70
https://github.com/marando/Units/blob/1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70/src/Marando/Units/Velocity.php#L305-L327
train
marando/Units
src/Marando/Units/Velocity.php
Velocity.add
public function add(Velocity $b) { $dist = $this->dist->add($b->dist); $velocity = new Velocity($dist, $this->time); $velocity->format = $this->format; return $velocity; }
php
public function add(Velocity $b) { $dist = $this->dist->add($b->dist); $velocity = new Velocity($dist, $this->time); $velocity->format = $this->format; return $velocity; }
[ "public", "function", "add", "(", "Velocity", "$", "b", ")", "{", "$", "dist", "=", "$", "this", "->", "dist", "->", "add", "(", "$", "b", "->", "dist", ")", ";", "$", "velocity", "=", "new", "Velocity", "(", "$", "dist", ",", "$", "this", "->", "time", ")", ";", "$", "velocity", "->", "format", "=", "$", "this", "->", "format", ";", "return", "$", "velocity", ";", "}" ]
Adds another velocity to this instance and returns a new instance with the sum. @param Velocity $b Velocity to add @return static Sum of the two velocity instances
[ "Adds", "another", "velocity", "to", "this", "instance", "and", "returns", "a", "new", "instance", "with", "the", "sum", "." ]
1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70
https://github.com/marando/Units/blob/1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70/src/Marando/Units/Velocity.php#L337-L345
train
marando/Units
src/Marando/Units/Velocity.php
Velocity.sub
public function sub(Velocity $b) { $dist = $this->dist->sub($b->dist); $velocity = new Velocity($dist, $this->time); $velocity->format = $this->format; return $velocity; }
php
public function sub(Velocity $b) { $dist = $this->dist->sub($b->dist); $velocity = new Velocity($dist, $this->time); $velocity->format = $this->format; return $velocity; }
[ "public", "function", "sub", "(", "Velocity", "$", "b", ")", "{", "$", "dist", "=", "$", "this", "->", "dist", "->", "sub", "(", "$", "b", "->", "dist", ")", ";", "$", "velocity", "=", "new", "Velocity", "(", "$", "dist", ",", "$", "this", "->", "time", ")", ";", "$", "velocity", "->", "format", "=", "$", "this", "->", "format", ";", "return", "$", "velocity", ";", "}" ]
Subtracts another velocity from this instance and returns a new instance with the difference. @param Velocity $b Velocity to subtract @return static Difference of the two velocity instances
[ "Subtracts", "another", "velocity", "from", "this", "instance", "and", "returns", "a", "new", "instance", "with", "the", "difference", "." ]
1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70
https://github.com/marando/Units/blob/1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70/src/Marando/Units/Velocity.php#L355-L363
train
marando/Units
src/Marando/Units/Velocity.php
Velocity.time
public function time(Distance $dist) { return Time::sec(($dist->m / $this->dist->m) * $this->time->sec); }
php
public function time(Distance $dist) { return Time::sec(($dist->m / $this->dist->m) * $this->time->sec); }
[ "public", "function", "time", "(", "Distance", "$", "dist", ")", "{", "return", "Time", "::", "sec", "(", "(", "$", "dist", "->", "m", "/", "$", "this", "->", "dist", "->", "m", ")", "*", "$", "this", "->", "time", "->", "sec", ")", ";", "}" ]
Calculates the time required to travel the provided distance at the velocity of this instance. @param Distance $dist @return Time
[ "Calculates", "the", "time", "required", "to", "travel", "the", "provided", "distance", "at", "the", "velocity", "of", "this", "instance", "." ]
1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70
https://github.com/marando/Units/blob/1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70/src/Marando/Units/Velocity.php#L373-L376
train
marando/Units
src/Marando/Units/Velocity.php
Velocity.removeTrailingZeros
private static function removeTrailingZeros($num) { // Only do this if number has a decimal value. if (strstr($num, '.')) { $num = rtrim($num, '0'); $last = substr($num, strlen($num) - 1, 1) == '.'; $num = $last ? substr($num, 0, strlen($num) - 1) : $num; return $num; } else { // No decimal value, don't modify number return $num; } }
php
private static function removeTrailingZeros($num) { // Only do this if number has a decimal value. if (strstr($num, '.')) { $num = rtrim($num, '0'); $last = substr($num, strlen($num) - 1, 1) == '.'; $num = $last ? substr($num, 0, strlen($num) - 1) : $num; return $num; } else { // No decimal value, don't modify number return $num; } }
[ "private", "static", "function", "removeTrailingZeros", "(", "$", "num", ")", "{", "// Only do this if number has a decimal value.", "if", "(", "strstr", "(", "$", "num", ",", "'.'", ")", ")", "{", "$", "num", "=", "rtrim", "(", "$", "num", ",", "'0'", ")", ";", "$", "last", "=", "substr", "(", "$", "num", ",", "strlen", "(", "$", "num", ")", "-", "1", ",", "1", ")", "==", "'.'", ";", "$", "num", "=", "$", "last", "?", "substr", "(", "$", "num", ",", "0", ",", "strlen", "(", "$", "num", ")", "-", "1", ")", ":", "$", "num", ";", "return", "$", "num", ";", "}", "else", "{", "// No decimal value, don't modify number", "return", "$", "num", ";", "}", "}" ]
Removes trailing zeros for a numeric value expressed as a string. @param $num @return string
[ "Removes", "trailing", "zeros", "for", "a", "numeric", "value", "expressed", "as", "a", "string", "." ]
1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70
https://github.com/marando/Units/blob/1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70/src/Marando/Units/Velocity.php#L470-L483
train
duncan3dc/php-ini
src/State.php
State.set
public function set(string $key, string $value): ConfigInterface { $this->settings[$key] = $value; return $this; }
php
public function set(string $key, string $value): ConfigInterface { $this->settings[$key] = $value; return $this; }
[ "public", "function", "set", "(", "string", "$", "key", ",", "string", "$", "value", ")", ":", "ConfigInterface", "{", "$", "this", "->", "settings", "[", "$", "key", "]", "=", "$", "value", ";", "return", "$", "this", ";", "}" ]
Set an ini directive to be used when calling. @param string $key The name of the setting @param string $value The value to use @return $this
[ "Set", "an", "ini", "directive", "to", "be", "used", "when", "calling", "." ]
e07435d7ddbbc466e535783e5c4d2b92e3715c7a
https://github.com/duncan3dc/php-ini/blob/e07435d7ddbbc466e535783e5c4d2b92e3715c7a/src/State.php#L35-L40
train
duncan3dc/php-ini
src/State.php
State.call
public function call(callable $callable, ...$params) { foreach ($this->settings as $key => $value) { $this->ini->set($key, $value); } $result = null; $exception = null; try { $result = $callable(...$params); } catch (\Throwable $e) { $exception = $e; } $this->ini->cleanup(); if ($exception) { throw $exception; } return $result; }
php
public function call(callable $callable, ...$params) { foreach ($this->settings as $key => $value) { $this->ini->set($key, $value); } $result = null; $exception = null; try { $result = $callable(...$params); } catch (\Throwable $e) { $exception = $e; } $this->ini->cleanup(); if ($exception) { throw $exception; } return $result; }
[ "public", "function", "call", "(", "callable", "$", "callable", ",", "...", "$", "params", ")", "{", "foreach", "(", "$", "this", "->", "settings", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "this", "->", "ini", "->", "set", "(", "$", "key", ",", "$", "value", ")", ";", "}", "$", "result", "=", "null", ";", "$", "exception", "=", "null", ";", "try", "{", "$", "result", "=", "$", "callable", "(", "...", "$", "params", ")", ";", "}", "catch", "(", "\\", "Throwable", "$", "e", ")", "{", "$", "exception", "=", "$", "e", ";", "}", "$", "this", "->", "ini", "->", "cleanup", "(", ")", ";", "if", "(", "$", "exception", ")", "{", "throw", "$", "exception", ";", "}", "return", "$", "result", ";", "}" ]
Run some code using the previous provided ini settings. @param callable $callable $the code to run @param mixed ...$params Any parameters to pass to the callable @return mixed The result of the callable
[ "Run", "some", "code", "using", "the", "previous", "provided", "ini", "settings", "." ]
e07435d7ddbbc466e535783e5c4d2b92e3715c7a
https://github.com/duncan3dc/php-ini/blob/e07435d7ddbbc466e535783e5c4d2b92e3715c7a/src/State.php#L64-L85
train
spartan/console
src/App.php
App.withPath
public function withPath($path = __DIR__) { $before = get_declared_classes(); $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path)); foreach ($iterator as $item) { if (!$item->isDir() && substr($item->getPathname(), -4) == '.php') { require_once $item->getPathname(); } } $after = get_declared_classes(); $commands = array_diff($after, $before); $this->withCommands($commands); return $this; }
php
public function withPath($path = __DIR__) { $before = get_declared_classes(); $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path)); foreach ($iterator as $item) { if (!$item->isDir() && substr($item->getPathname(), -4) == '.php') { require_once $item->getPathname(); } } $after = get_declared_classes(); $commands = array_diff($after, $before); $this->withCommands($commands); return $this; }
[ "public", "function", "withPath", "(", "$", "path", "=", "__DIR__", ")", "{", "$", "before", "=", "get_declared_classes", "(", ")", ";", "$", "iterator", "=", "new", "\\", "RecursiveIteratorIterator", "(", "new", "\\", "RecursiveDirectoryIterator", "(", "$", "path", ")", ")", ";", "foreach", "(", "$", "iterator", "as", "$", "item", ")", "{", "if", "(", "!", "$", "item", "->", "isDir", "(", ")", "&&", "substr", "(", "$", "item", "->", "getPathname", "(", ")", ",", "-", "4", ")", "==", "'.php'", ")", "{", "require_once", "$", "item", "->", "getPathname", "(", ")", ";", "}", "}", "$", "after", "=", "get_declared_classes", "(", ")", ";", "$", "commands", "=", "array_diff", "(", "$", "after", ",", "$", "before", ")", ";", "$", "this", "->", "withCommands", "(", "$", "commands", ")", ";", "return", "$", "this", ";", "}" ]
Add commands from path recursively @param string $path @return $this
[ "Add", "commands", "from", "path", "recursively" ]
66e3e595b9bf9e274ce35d2f50f7cdd5d9e5e838
https://github.com/spartan/console/blob/66e3e595b9bf9e274ce35d2f50f7cdd5d9e5e838/src/App.php#L25-L42
train
spartan/console
src/App.php
App.withStyles
public function withStyles(array $styles) { foreach ($styles as $name => $args) { $this->formatter()->setStyle($name, new OutputFormatterStyle(...$args)); } return $this; }
php
public function withStyles(array $styles) { foreach ($styles as $name => $args) { $this->formatter()->setStyle($name, new OutputFormatterStyle(...$args)); } return $this; }
[ "public", "function", "withStyles", "(", "array", "$", "styles", ")", "{", "foreach", "(", "$", "styles", "as", "$", "name", "=>", "$", "args", ")", "{", "$", "this", "->", "formatter", "(", ")", "->", "setStyle", "(", "$", "name", ",", "new", "OutputFormatterStyle", "(", "...", "$", "args", ")", ")", ";", "}", "return", "$", "this", ";", "}" ]
Change output formatting styles @param array $styles @return $this
[ "Change", "output", "formatting", "styles" ]
66e3e595b9bf9e274ce35d2f50f7cdd5d9e5e838
https://github.com/spartan/console/blob/66e3e595b9bf9e274ce35d2f50f7cdd5d9e5e838/src/App.php#L72-L79
train
ringoteam/RingoPhpRedmonBundle
Controller/DashController.php
DashController.indexAction
public function indexAction() { $instance = $this->getCurrentInstance(); if($instance) { $worker = $this->getWorker(); // Worker can be undefined if server went away // For the current instance or if there is no instance selected if($worker) { return $this->render( $this->getTemplatePath().'index.html.twig', array( 'instance' => $worker->getInstance(), 'infos' => $worker->getInfos(), 'slowLogs' => $worker->getSlowLogs(), 'keyspace' => $worker->getKeyspace() ) ); } } return new RedirectResponse($this->generateUrl('ringo_php_redmon_instances')); }
php
public function indexAction() { $instance = $this->getCurrentInstance(); if($instance) { $worker = $this->getWorker(); // Worker can be undefined if server went away // For the current instance or if there is no instance selected if($worker) { return $this->render( $this->getTemplatePath().'index.html.twig', array( 'instance' => $worker->getInstance(), 'infos' => $worker->getInfos(), 'slowLogs' => $worker->getSlowLogs(), 'keyspace' => $worker->getKeyspace() ) ); } } return new RedirectResponse($this->generateUrl('ringo_php_redmon_instances')); }
[ "public", "function", "indexAction", "(", ")", "{", "$", "instance", "=", "$", "this", "->", "getCurrentInstance", "(", ")", ";", "if", "(", "$", "instance", ")", "{", "$", "worker", "=", "$", "this", "->", "getWorker", "(", ")", ";", "// Worker can be undefined if server went away", "// For the current instance or if there is no instance selected", "if", "(", "$", "worker", ")", "{", "return", "$", "this", "->", "render", "(", "$", "this", "->", "getTemplatePath", "(", ")", ".", "'index.html.twig'", ",", "array", "(", "'instance'", "=>", "$", "worker", "->", "getInstance", "(", ")", ",", "'infos'", "=>", "$", "worker", "->", "getInfos", "(", ")", ",", "'slowLogs'", "=>", "$", "worker", "->", "getSlowLogs", "(", ")", ",", "'keyspace'", "=>", "$", "worker", "->", "getKeyspace", "(", ")", ")", ")", ";", "}", "}", "return", "new", "RedirectResponse", "(", "$", "this", "->", "generateUrl", "(", "'ringo_php_redmon_instances'", ")", ")", ";", "}" ]
Render choose action or dashboard action @return mixed
[ "Render", "choose", "action", "or", "dashboard", "action" ]
9aab989a9bee9e6152ec19f8a30bc24f3bde6012
https://github.com/ringoteam/RingoPhpRedmonBundle/blob/9aab989a9bee9e6152ec19f8a30bc24f3bde6012/Controller/DashController.php#L28-L50
train
ringoteam/RingoPhpRedmonBundle
Controller/DashController.php
DashController.clientAction
public function clientAction() { $worker = $this->getWorker(); // Worker can be undefined if server went away // For the current instance or if we have no instance selected if(!$worker) { return new RedirectResponse($this->generateUrl('ringo_php_redmon')); } return $this->render( $this->getTemplatePath().'client.html.twig', array( 'instance' => $worker->getInstance(), 'clients'=> $worker->getClients() ) ); }
php
public function clientAction() { $worker = $this->getWorker(); // Worker can be undefined if server went away // For the current instance or if we have no instance selected if(!$worker) { return new RedirectResponse($this->generateUrl('ringo_php_redmon')); } return $this->render( $this->getTemplatePath().'client.html.twig', array( 'instance' => $worker->getInstance(), 'clients'=> $worker->getClients() ) ); }
[ "public", "function", "clientAction", "(", ")", "{", "$", "worker", "=", "$", "this", "->", "getWorker", "(", ")", ";", "// Worker can be undefined if server went away", "// For the current instance or if we have no instance selected", "if", "(", "!", "$", "worker", ")", "{", "return", "new", "RedirectResponse", "(", "$", "this", "->", "generateUrl", "(", "'ringo_php_redmon'", ")", ")", ";", "}", "return", "$", "this", "->", "render", "(", "$", "this", "->", "getTemplatePath", "(", ")", ".", "'client.html.twig'", ",", "array", "(", "'instance'", "=>", "$", "worker", "->", "getInstance", "(", ")", ",", "'clients'", "=>", "$", "worker", "->", "getClients", "(", ")", ")", ")", ";", "}" ]
Render client list for the current instance @return \Symfony\Component\HttpFoundation\RedirectResponse
[ "Render", "client", "list", "for", "the", "current", "instance" ]
9aab989a9bee9e6152ec19f8a30bc24f3bde6012
https://github.com/ringoteam/RingoPhpRedmonBundle/blob/9aab989a9bee9e6152ec19f8a30bc24f3bde6012/Controller/DashController.php#L57-L72
train
ringoteam/RingoPhpRedmonBundle
Controller/DashController.php
DashController.configurationAction
public function configurationAction() { $worker = $this->getWorker(); // Worker can be undefined if server went away // For the current instance or if we have no instance selected if(!$worker) { return new RedirectResponse($this->generateUrl('ringo_php_redmon')); } return $this->render( $this->getTemplatePath().'configuration.html.twig', array( 'instance' => $worker->getInstance(), 'configs' => $worker->getConfiguration() ) ); }
php
public function configurationAction() { $worker = $this->getWorker(); // Worker can be undefined if server went away // For the current instance or if we have no instance selected if(!$worker) { return new RedirectResponse($this->generateUrl('ringo_php_redmon')); } return $this->render( $this->getTemplatePath().'configuration.html.twig', array( 'instance' => $worker->getInstance(), 'configs' => $worker->getConfiguration() ) ); }
[ "public", "function", "configurationAction", "(", ")", "{", "$", "worker", "=", "$", "this", "->", "getWorker", "(", ")", ";", "// Worker can be undefined if server went away", "// For the current instance or if we have no instance selected", "if", "(", "!", "$", "worker", ")", "{", "return", "new", "RedirectResponse", "(", "$", "this", "->", "generateUrl", "(", "'ringo_php_redmon'", ")", ")", ";", "}", "return", "$", "this", "->", "render", "(", "$", "this", "->", "getTemplatePath", "(", ")", ".", "'configuration.html.twig'", ",", "array", "(", "'instance'", "=>", "$", "worker", "->", "getInstance", "(", ")", ",", "'configs'", "=>", "$", "worker", "->", "getConfiguration", "(", ")", ")", ")", ";", "}" ]
Render configuration list for the current instance @return \Symfony\Component\HttpFoundation\RedirectResponse
[ "Render", "configuration", "list", "for", "the", "current", "instance" ]
9aab989a9bee9e6152ec19f8a30bc24f3bde6012
https://github.com/ringoteam/RingoPhpRedmonBundle/blob/9aab989a9bee9e6152ec19f8a30bc24f3bde6012/Controller/DashController.php#L79-L95
train
ringoteam/RingoPhpRedmonBundle
Controller/DashController.php
DashController.selectAction
public function selectAction($id) { $instance = $this->getManager()->find($id); // If instance exists if($instance) { $this->getRequest()->getSession()->set('instance', $instance); if($this->getWorker()) { $this->get('session')->getFlashBag()->add('success', 'Instance '.$instance->getName().' selected'); }else { $this->get('session')->getFlashBag()->add('error', 'Instance '.$instance->getName().' cannot be selected'); } }else { $this->get('session')->getFlashBag()->add('error', 'This instance does not exist'); } return new RedirectResponse($this->generateUrl('ringo_php_redmon')); }
php
public function selectAction($id) { $instance = $this->getManager()->find($id); // If instance exists if($instance) { $this->getRequest()->getSession()->set('instance', $instance); if($this->getWorker()) { $this->get('session')->getFlashBag()->add('success', 'Instance '.$instance->getName().' selected'); }else { $this->get('session')->getFlashBag()->add('error', 'Instance '.$instance->getName().' cannot be selected'); } }else { $this->get('session')->getFlashBag()->add('error', 'This instance does not exist'); } return new RedirectResponse($this->generateUrl('ringo_php_redmon')); }
[ "public", "function", "selectAction", "(", "$", "id", ")", "{", "$", "instance", "=", "$", "this", "->", "getManager", "(", ")", "->", "find", "(", "$", "id", ")", ";", "// If instance exists", "if", "(", "$", "instance", ")", "{", "$", "this", "->", "getRequest", "(", ")", "->", "getSession", "(", ")", "->", "set", "(", "'instance'", ",", "$", "instance", ")", ";", "if", "(", "$", "this", "->", "getWorker", "(", ")", ")", "{", "$", "this", "->", "get", "(", "'session'", ")", "->", "getFlashBag", "(", ")", "->", "add", "(", "'success'", ",", "'Instance '", ".", "$", "instance", "->", "getName", "(", ")", ".", "' selected'", ")", ";", "}", "else", "{", "$", "this", "->", "get", "(", "'session'", ")", "->", "getFlashBag", "(", ")", "->", "add", "(", "'error'", ",", "'Instance '", ".", "$", "instance", "->", "getName", "(", ")", ".", "' cannot be selected'", ")", ";", "}", "}", "else", "{", "$", "this", "->", "get", "(", "'session'", ")", "->", "getFlashBag", "(", ")", "->", "add", "(", "'error'", ",", "'This instance does not exist'", ")", ";", "}", "return", "new", "RedirectResponse", "(", "$", "this", "->", "generateUrl", "(", "'ringo_php_redmon'", ")", ")", ";", "}" ]
Select action Change the current instance @param string $id @return \Symfony\Component\HttpFoundation\RedirectResponse
[ "Select", "action", "Change", "the", "current", "instance" ]
9aab989a9bee9e6152ec19f8a30bc24f3bde6012
https://github.com/ringoteam/RingoPhpRedmonBundle/blob/9aab989a9bee9e6152ec19f8a30bc24f3bde6012/Controller/DashController.php#L104-L120
train
tjwlucas/phpjstore
src/jstore.php
jstore.dir
public static function dir() { $JSTORE_DIR = str_replace(DIRECTORY_SEPARATOR, '/', __DIR__); $JSTORE_DOCS_ROOT = str_replace(DIRECTORY_SEPARATOR, '/', isset($_SERVER['DOCUMENT_ROOT']) ? realpath($_SERVER['DOCUMENT_ROOT']) : dirname(__DIR__)); return trim(str_replace($JSTORE_DOCS_ROOT, '', $JSTORE_DIR), "/"); }
php
public static function dir() { $JSTORE_DIR = str_replace(DIRECTORY_SEPARATOR, '/', __DIR__); $JSTORE_DOCS_ROOT = str_replace(DIRECTORY_SEPARATOR, '/', isset($_SERVER['DOCUMENT_ROOT']) ? realpath($_SERVER['DOCUMENT_ROOT']) : dirname(__DIR__)); return trim(str_replace($JSTORE_DOCS_ROOT, '', $JSTORE_DIR), "/"); }
[ "public", "static", "function", "dir", "(", ")", "{", "$", "JSTORE_DIR", "=", "str_replace", "(", "DIRECTORY_SEPARATOR", ",", "'/'", ",", "__DIR__", ")", ";", "$", "JSTORE_DOCS_ROOT", "=", "str_replace", "(", "DIRECTORY_SEPARATOR", ",", "'/'", ",", "isset", "(", "$", "_SERVER", "[", "'DOCUMENT_ROOT'", "]", ")", "?", "realpath", "(", "$", "_SERVER", "[", "'DOCUMENT_ROOT'", "]", ")", ":", "dirname", "(", "__DIR__", ")", ")", ";", "return", "trim", "(", "str_replace", "(", "$", "JSTORE_DOCS_ROOT", ",", "''", ",", "$", "JSTORE_DIR", ")", ",", "\"/\"", ")", ";", "}" ]
Used to get the directory where this class file is located
[ "Used", "to", "get", "the", "directory", "where", "this", "class", "file", "is", "located" ]
ebc8f821de38757724efb89992a9d3aa9f9834d2
https://github.com/tjwlucas/phpjstore/blob/ebc8f821de38757724efb89992a9d3aa9f9834d2/src/jstore.php#L43-L48
train
tjwlucas/phpjstore
src/jstore.php
jstore.ArrayToObj
public function ArrayToObj($array, $root = False){ $obj = !$root ? new jstoreRootObject($this) : new jstoreObject($this); foreach( $array as $arraykey => $arrayval){ if( is_array($arrayval) ){ $obj->$arraykey = $this->ArrayToObj($arrayval); } else{ $obj->$arraykey = $arrayval; } } return $obj; }
php
public function ArrayToObj($array, $root = False){ $obj = !$root ? new jstoreRootObject($this) : new jstoreObject($this); foreach( $array as $arraykey => $arrayval){ if( is_array($arrayval) ){ $obj->$arraykey = $this->ArrayToObj($arrayval); } else{ $obj->$arraykey = $arrayval; } } return $obj; }
[ "public", "function", "ArrayToObj", "(", "$", "array", ",", "$", "root", "=", "False", ")", "{", "$", "obj", "=", "!", "$", "root", "?", "new", "jstoreRootObject", "(", "$", "this", ")", ":", "new", "jstoreObject", "(", "$", "this", ")", ";", "foreach", "(", "$", "array", "as", "$", "arraykey", "=>", "$", "arrayval", ")", "{", "if", "(", "is_array", "(", "$", "arrayval", ")", ")", "{", "$", "obj", "->", "$", "arraykey", "=", "$", "this", "->", "ArrayToObj", "(", "$", "arrayval", ")", ";", "}", "else", "{", "$", "obj", "->", "$", "arraykey", "=", "$", "arrayval", ";", "}", "}", "return", "$", "obj", ";", "}" ]
Same as JsonToObj, except it takes in an array, rather than a JSON For both methods, this is where the work actually happens
[ "Same", "as", "JsonToObj", "except", "it", "takes", "in", "an", "array", "rather", "than", "a", "JSON", "For", "both", "methods", "this", "is", "where", "the", "work", "actually", "happens" ]
ebc8f821de38757724efb89992a9d3aa9f9834d2
https://github.com/tjwlucas/phpjstore/blob/ebc8f821de38757724efb89992a9d3aa9f9834d2/src/jstore.php#L86-L97
train
Krinkle/toollabs-base
src/GitInfo.php
GitInfo.getHeadSHA1
public function getHeadSHA1() { $headFile = "{$this->dir}/HEAD"; if ( !is_readable( $headFile ) ) { return false; } $head = file_get_contents( $headFile ); if ( preg_match( "/ref: (.*)/", $head, $m ) ) { $head = rtrim( $m[1] ); } else { $head = rtrim( $head ); } if ( self::isSHA1( $head ) ) { // Detached head return $head; } // Resolve ref $refFile = "{$this->dir}/{$head}"; if ( !is_readable( $refFile ) ) { return false; } return rtrim( file_get_contents( $refFile ) ); }
php
public function getHeadSHA1() { $headFile = "{$this->dir}/HEAD"; if ( !is_readable( $headFile ) ) { return false; } $head = file_get_contents( $headFile ); if ( preg_match( "/ref: (.*)/", $head, $m ) ) { $head = rtrim( $m[1] ); } else { $head = rtrim( $head ); } if ( self::isSHA1( $head ) ) { // Detached head return $head; } // Resolve ref $refFile = "{$this->dir}/{$head}"; if ( !is_readable( $refFile ) ) { return false; } return rtrim( file_get_contents( $refFile ) ); }
[ "public", "function", "getHeadSHA1", "(", ")", "{", "$", "headFile", "=", "\"{$this->dir}/HEAD\"", ";", "if", "(", "!", "is_readable", "(", "$", "headFile", ")", ")", "{", "return", "false", ";", "}", "$", "head", "=", "file_get_contents", "(", "$", "headFile", ")", ";", "if", "(", "preg_match", "(", "\"/ref: (.*)/\"", ",", "$", "head", ",", "$", "m", ")", ")", "{", "$", "head", "=", "rtrim", "(", "$", "m", "[", "1", "]", ")", ";", "}", "else", "{", "$", "head", "=", "rtrim", "(", "$", "head", ")", ";", "}", "if", "(", "self", "::", "isSHA1", "(", "$", "head", ")", ")", "{", "// Detached head", "return", "$", "head", ";", "}", "// Resolve ref", "$", "refFile", "=", "\"{$this->dir}/{$head}\"", ";", "if", "(", "!", "is_readable", "(", "$", "refFile", ")", ")", "{", "return", "false", ";", "}", "return", "rtrim", "(", "file_get_contents", "(", "$", "refFile", ")", ")", ";", "}" ]
Return the SHA1 for the current HEAD of the Git repository. @return string|bool A SHA1, or boolean false
[ "Return", "the", "SHA1", "for", "the", "current", "HEAD", "of", "the", "Git", "repository", "." ]
784150ca58f4b48cc89534fd6142c54b4f138cd2
https://github.com/Krinkle/toollabs-base/blob/784150ca58f4b48cc89534fd6142c54b4f138cd2/src/GitInfo.php#L40-L65
train
Werkint/SpritesBundle
src/Service/Sprites.php
Sprites.getList
public function getList() { $data = []; foreach ($this->providers as $provider) { /** @var ProviderInterface $provider */ $data = array_merge_recursive( $data, $provider->getImages() ); } return $data; }
php
public function getList() { $data = []; foreach ($this->providers as $provider) { /** @var ProviderInterface $provider */ $data = array_merge_recursive( $data, $provider->getImages() ); } return $data; }
[ "public", "function", "getList", "(", ")", "{", "$", "data", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "providers", "as", "$", "provider", ")", "{", "/** @var ProviderInterface $provider */", "$", "data", "=", "array_merge_recursive", "(", "$", "data", ",", "$", "provider", "->", "getImages", "(", ")", ")", ";", "}", "return", "$", "data", ";", "}" ]
Returns list of images to merge @return array
[ "Returns", "list", "of", "images", "to", "merge" ]
d0f2dd1f862cc79b6fe7a295302057aef6a01d91
https://github.com/Werkint/SpritesBundle/blob/d0f2dd1f862cc79b6fe7a295302057aef6a01d91/src/Service/Sprites.php#L107-L118
train
Werkint/SpritesBundle
src/Service/Sprites.php
Sprites.compile
public function compile() { // Path prefix $prefix = $this->getNewPrefix(); // List of images $data = $this->getList(); // sizes $sizes = []; foreach ($this->providers as $provider) { if ($provider instanceof SizeProviderInterface) { $sizes = array_merge($sizes, $provider->getSizes()); } } $num = 0; $scss = []; foreach ($data as $name => $list) { // Sprite size $size = !isset($sizes[$name]) ? null : $sizes[$name]; $size = $this->getSize($name, $size); if (is_array($size)) { $border = $size[1]; $sizeH = isset($size[2]) ? $size[2] : $size[0]; $sizeW = $size[0]; } else { $border = static::BORDER_WIDTH; $sizeH = $sizeW = $size; } $scss[] = $this->compileFile($prefix, $name, $list, [$sizeW, $sizeH], $border); $num += count($list); } // Populating template $template = file_get_contents($this->template); $scss = str_replace( static::TEMPLATE_NEEDLE, join("\n", $scss), $template ); // Creating global classes if (static::CREATE_CLASSES) { foreach ($data as $name => $list) { $scss .= '.#{$' . static::NAMESPACE_NAME . '}'; $scss .= ', .#{$' . static::NAMESPACE_NAME . '}-' . $name . ' {' . "\n"; $scss .= '@include ' . static::PREFIX_SPRITE . $name . ';' . "\n"; $scss .= '};' . "\n"; } } // Writing the file file_put_contents($this->stylePath, $scss); return $num; }
php
public function compile() { // Path prefix $prefix = $this->getNewPrefix(); // List of images $data = $this->getList(); // sizes $sizes = []; foreach ($this->providers as $provider) { if ($provider instanceof SizeProviderInterface) { $sizes = array_merge($sizes, $provider->getSizes()); } } $num = 0; $scss = []; foreach ($data as $name => $list) { // Sprite size $size = !isset($sizes[$name]) ? null : $sizes[$name]; $size = $this->getSize($name, $size); if (is_array($size)) { $border = $size[1]; $sizeH = isset($size[2]) ? $size[2] : $size[0]; $sizeW = $size[0]; } else { $border = static::BORDER_WIDTH; $sizeH = $sizeW = $size; } $scss[] = $this->compileFile($prefix, $name, $list, [$sizeW, $sizeH], $border); $num += count($list); } // Populating template $template = file_get_contents($this->template); $scss = str_replace( static::TEMPLATE_NEEDLE, join("\n", $scss), $template ); // Creating global classes if (static::CREATE_CLASSES) { foreach ($data as $name => $list) { $scss .= '.#{$' . static::NAMESPACE_NAME . '}'; $scss .= ', .#{$' . static::NAMESPACE_NAME . '}-' . $name . ' {' . "\n"; $scss .= '@include ' . static::PREFIX_SPRITE . $name . ';' . "\n"; $scss .= '};' . "\n"; } } // Writing the file file_put_contents($this->stylePath, $scss); return $num; }
[ "public", "function", "compile", "(", ")", "{", "// Path prefix", "$", "prefix", "=", "$", "this", "->", "getNewPrefix", "(", ")", ";", "// List of images", "$", "data", "=", "$", "this", "->", "getList", "(", ")", ";", "// sizes", "$", "sizes", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "providers", "as", "$", "provider", ")", "{", "if", "(", "$", "provider", "instanceof", "SizeProviderInterface", ")", "{", "$", "sizes", "=", "array_merge", "(", "$", "sizes", ",", "$", "provider", "->", "getSizes", "(", ")", ")", ";", "}", "}", "$", "num", "=", "0", ";", "$", "scss", "=", "[", "]", ";", "foreach", "(", "$", "data", "as", "$", "name", "=>", "$", "list", ")", "{", "// Sprite size", "$", "size", "=", "!", "isset", "(", "$", "sizes", "[", "$", "name", "]", ")", "?", "null", ":", "$", "sizes", "[", "$", "name", "]", ";", "$", "size", "=", "$", "this", "->", "getSize", "(", "$", "name", ",", "$", "size", ")", ";", "if", "(", "is_array", "(", "$", "size", ")", ")", "{", "$", "border", "=", "$", "size", "[", "1", "]", ";", "$", "sizeH", "=", "isset", "(", "$", "size", "[", "2", "]", ")", "?", "$", "size", "[", "2", "]", ":", "$", "size", "[", "0", "]", ";", "$", "sizeW", "=", "$", "size", "[", "0", "]", ";", "}", "else", "{", "$", "border", "=", "static", "::", "BORDER_WIDTH", ";", "$", "sizeH", "=", "$", "sizeW", "=", "$", "size", ";", "}", "$", "scss", "[", "]", "=", "$", "this", "->", "compileFile", "(", "$", "prefix", ",", "$", "name", ",", "$", "list", ",", "[", "$", "sizeW", ",", "$", "sizeH", "]", ",", "$", "border", ")", ";", "$", "num", "+=", "count", "(", "$", "list", ")", ";", "}", "// Populating template", "$", "template", "=", "file_get_contents", "(", "$", "this", "->", "template", ")", ";", "$", "scss", "=", "str_replace", "(", "static", "::", "TEMPLATE_NEEDLE", ",", "join", "(", "\"\\n\"", ",", "$", "scss", ")", ",", "$", "template", ")", ";", "// Creating global classes", "if", "(", "static", "::", "CREATE_CLASSES", ")", "{", "foreach", "(", "$", "data", "as", "$", "name", "=>", "$", "list", ")", "{", "$", "scss", ".=", "'.#{$'", ".", "static", "::", "NAMESPACE_NAME", ".", "'}'", ";", "$", "scss", ".=", "', .#{$'", ".", "static", "::", "NAMESPACE_NAME", ".", "'}-'", ".", "$", "name", ".", "' {'", ".", "\"\\n\"", ";", "$", "scss", ".=", "'@include '", ".", "static", "::", "PREFIX_SPRITE", ".", "$", "name", ".", "';'", ".", "\"\\n\"", ";", "$", "scss", ".=", "'};'", ".", "\"\\n\"", ";", "}", "}", "// Writing the file", "file_put_contents", "(", "$", "this", "->", "stylePath", ",", "$", "scss", ")", ";", "return", "$", "num", ";", "}" ]
Compiles all sprites @return int Number of images merged
[ "Compiles", "all", "sprites" ]
d0f2dd1f862cc79b6fe7a295302057aef6a01d91
https://github.com/Werkint/SpritesBundle/blob/d0f2dd1f862cc79b6fe7a295302057aef6a01d91/src/Service/Sprites.php#L125-L178
train
Werkint/SpritesBundle
src/Service/Sprites.php
Sprites.getNewPrefix
protected function getNewPrefix() { // Removing old sprites $find = new Finder(); $fs = new Filesystem(); $fs->remove( $find->in($this->imgDir)->directories(), $this->stylePath ); // New prefix $prefix = substr(sha1(microtime(true) . 'sprites'), 1, 10); $fs->mkdir($this->imgDir . '/' . $prefix); return $prefix; }
php
protected function getNewPrefix() { // Removing old sprites $find = new Finder(); $fs = new Filesystem(); $fs->remove( $find->in($this->imgDir)->directories(), $this->stylePath ); // New prefix $prefix = substr(sha1(microtime(true) . 'sprites'), 1, 10); $fs->mkdir($this->imgDir . '/' . $prefix); return $prefix; }
[ "protected", "function", "getNewPrefix", "(", ")", "{", "// Removing old sprites", "$", "find", "=", "new", "Finder", "(", ")", ";", "$", "fs", "=", "new", "Filesystem", "(", ")", ";", "$", "fs", "->", "remove", "(", "$", "find", "->", "in", "(", "$", "this", "->", "imgDir", ")", "->", "directories", "(", ")", ",", "$", "this", "->", "stylePath", ")", ";", "// New prefix", "$", "prefix", "=", "substr", "(", "sha1", "(", "microtime", "(", "true", ")", ".", "'sprites'", ")", ",", "1", ",", "10", ")", ";", "$", "fs", "->", "mkdir", "(", "$", "this", "->", "imgDir", ".", "'/'", ".", "$", "prefix", ")", ";", "return", "$", "prefix", ";", "}" ]
Creates new prefix for sprites @return string
[ "Creates", "new", "prefix", "for", "sprites" ]
d0f2dd1f862cc79b6fe7a295302057aef6a01d91
https://github.com/Werkint/SpritesBundle/blob/d0f2dd1f862cc79b6fe7a295302057aef6a01d91/src/Service/Sprites.php#L277-L292
train
wb-crowdfusion/crowdfusion
system/core/classes/nodedb/daos/NodeDAO.php
NodeDAO.insertIntoTree
protected function insertIntoTree(&$node, $existingNode = null) { $treeOriginTagDef = $node->getNodeRef()->getElement()->getSchema()->getTreeOriginTagDef(); if(empty($treeOriginTagDef)) throw new NodeException('Cannot insert a node in tree order mode without a tree origin tag definition'); if($treeOriginTagDef->isMultiple()) throw new NodeException('Cannot have more than 1 tree origin tag'); if($treeOriginTagDef->Direction == 'out') $treeOrigin = $node->getOutTag($treeOriginTagDef->Id); else $treeOrigin = $node->getInTag($treeOriginTagDef->Id); if(empty($treeOrigin)) throw new NodeException('Cannot insert a node into the tree without the tree origin tag'); $treeOriginPartial = $treeOrigin->toPartial(); $parentTreeID = ''; if($node->getTreeParent() != false) { $parentNode = $this->NodeLookupDAO->getByNodeRef(new NodeRef($node->getNodeRef()->getElement(), $node->getTreeParent())); $parentTreeID = $parentNode->TreeID; } // fetch max tree id (if parentTreeID is blank, return last top-level tree id) $maxChildTreeID = $this->fetchMaxChildTreeID($node, $treeOriginTagDef, $treeOriginPartial, $parentTreeID); if(!is_null($existingNode) && $maxChildTreeID == $existingNode->TreeID) { $node->TreeID = $existingNode->TreeID; return; } if(empty($maxChildTreeID)) { $newTreeID = $parentTreeID . '0001'; // add this to the children } else { $last4 = substr($maxChildTreeID, -4); if(strtolower($last4) == 'ffff') throw new NodeException('This tree leaf has reached the limit of its children'); $newTreeID = $parentTreeID . str_pad(dechex(hexdec($last4)+1), 4, '0', STR_PAD_LEFT); } while(!$this->Locks->getLock('treeid:'.$treeOriginPartial.':'.$newTreeID, 0)) { $last4 = substr($newTreeID, -4); if(strtolower($last4) == 'ffff') throw new NodeException('This tree leaf has reached the limit of its children'); $newTreeID = $parentTreeID . str_pad(dechex(hexdec($last4)+1), 4, '0', STR_PAD_LEFT); } $node->TreeID = $newTreeID; }
php
protected function insertIntoTree(&$node, $existingNode = null) { $treeOriginTagDef = $node->getNodeRef()->getElement()->getSchema()->getTreeOriginTagDef(); if(empty($treeOriginTagDef)) throw new NodeException('Cannot insert a node in tree order mode without a tree origin tag definition'); if($treeOriginTagDef->isMultiple()) throw new NodeException('Cannot have more than 1 tree origin tag'); if($treeOriginTagDef->Direction == 'out') $treeOrigin = $node->getOutTag($treeOriginTagDef->Id); else $treeOrigin = $node->getInTag($treeOriginTagDef->Id); if(empty($treeOrigin)) throw new NodeException('Cannot insert a node into the tree without the tree origin tag'); $treeOriginPartial = $treeOrigin->toPartial(); $parentTreeID = ''; if($node->getTreeParent() != false) { $parentNode = $this->NodeLookupDAO->getByNodeRef(new NodeRef($node->getNodeRef()->getElement(), $node->getTreeParent())); $parentTreeID = $parentNode->TreeID; } // fetch max tree id (if parentTreeID is blank, return last top-level tree id) $maxChildTreeID = $this->fetchMaxChildTreeID($node, $treeOriginTagDef, $treeOriginPartial, $parentTreeID); if(!is_null($existingNode) && $maxChildTreeID == $existingNode->TreeID) { $node->TreeID = $existingNode->TreeID; return; } if(empty($maxChildTreeID)) { $newTreeID = $parentTreeID . '0001'; // add this to the children } else { $last4 = substr($maxChildTreeID, -4); if(strtolower($last4) == 'ffff') throw new NodeException('This tree leaf has reached the limit of its children'); $newTreeID = $parentTreeID . str_pad(dechex(hexdec($last4)+1), 4, '0', STR_PAD_LEFT); } while(!$this->Locks->getLock('treeid:'.$treeOriginPartial.':'.$newTreeID, 0)) { $last4 = substr($newTreeID, -4); if(strtolower($last4) == 'ffff') throw new NodeException('This tree leaf has reached the limit of its children'); $newTreeID = $parentTreeID . str_pad(dechex(hexdec($last4)+1), 4, '0', STR_PAD_LEFT); } $node->TreeID = $newTreeID; }
[ "protected", "function", "insertIntoTree", "(", "&", "$", "node", ",", "$", "existingNode", "=", "null", ")", "{", "$", "treeOriginTagDef", "=", "$", "node", "->", "getNodeRef", "(", ")", "->", "getElement", "(", ")", "->", "getSchema", "(", ")", "->", "getTreeOriginTagDef", "(", ")", ";", "if", "(", "empty", "(", "$", "treeOriginTagDef", ")", ")", "throw", "new", "NodeException", "(", "'Cannot insert a node in tree order mode without a tree origin tag definition'", ")", ";", "if", "(", "$", "treeOriginTagDef", "->", "isMultiple", "(", ")", ")", "throw", "new", "NodeException", "(", "'Cannot have more than 1 tree origin tag'", ")", ";", "if", "(", "$", "treeOriginTagDef", "->", "Direction", "==", "'out'", ")", "$", "treeOrigin", "=", "$", "node", "->", "getOutTag", "(", "$", "treeOriginTagDef", "->", "Id", ")", ";", "else", "$", "treeOrigin", "=", "$", "node", "->", "getInTag", "(", "$", "treeOriginTagDef", "->", "Id", ")", ";", "if", "(", "empty", "(", "$", "treeOrigin", ")", ")", "throw", "new", "NodeException", "(", "'Cannot insert a node into the tree without the tree origin tag'", ")", ";", "$", "treeOriginPartial", "=", "$", "treeOrigin", "->", "toPartial", "(", ")", ";", "$", "parentTreeID", "=", "''", ";", "if", "(", "$", "node", "->", "getTreeParent", "(", ")", "!=", "false", ")", "{", "$", "parentNode", "=", "$", "this", "->", "NodeLookupDAO", "->", "getByNodeRef", "(", "new", "NodeRef", "(", "$", "node", "->", "getNodeRef", "(", ")", "->", "getElement", "(", ")", ",", "$", "node", "->", "getTreeParent", "(", ")", ")", ")", ";", "$", "parentTreeID", "=", "$", "parentNode", "->", "TreeID", ";", "}", "// fetch max tree id (if parentTreeID is blank, return last top-level tree id)", "$", "maxChildTreeID", "=", "$", "this", "->", "fetchMaxChildTreeID", "(", "$", "node", ",", "$", "treeOriginTagDef", ",", "$", "treeOriginPartial", ",", "$", "parentTreeID", ")", ";", "if", "(", "!", "is_null", "(", "$", "existingNode", ")", "&&", "$", "maxChildTreeID", "==", "$", "existingNode", "->", "TreeID", ")", "{", "$", "node", "->", "TreeID", "=", "$", "existingNode", "->", "TreeID", ";", "return", ";", "}", "if", "(", "empty", "(", "$", "maxChildTreeID", ")", ")", "{", "$", "newTreeID", "=", "$", "parentTreeID", ".", "'0001'", ";", "// add this to the children", "}", "else", "{", "$", "last4", "=", "substr", "(", "$", "maxChildTreeID", ",", "-", "4", ")", ";", "if", "(", "strtolower", "(", "$", "last4", ")", "==", "'ffff'", ")", "throw", "new", "NodeException", "(", "'This tree leaf has reached the limit of its children'", ")", ";", "$", "newTreeID", "=", "$", "parentTreeID", ".", "str_pad", "(", "dechex", "(", "hexdec", "(", "$", "last4", ")", "+", "1", ")", ",", "4", ",", "'0'", ",", "STR_PAD_LEFT", ")", ";", "}", "while", "(", "!", "$", "this", "->", "Locks", "->", "getLock", "(", "'treeid:'", ".", "$", "treeOriginPartial", ".", "':'", ".", "$", "newTreeID", ",", "0", ")", ")", "{", "$", "last4", "=", "substr", "(", "$", "newTreeID", ",", "-", "4", ")", ";", "if", "(", "strtolower", "(", "$", "last4", ")", "==", "'ffff'", ")", "throw", "new", "NodeException", "(", "'This tree leaf has reached the limit of its children'", ")", ";", "$", "newTreeID", "=", "$", "parentTreeID", ".", "str_pad", "(", "dechex", "(", "hexdec", "(", "$", "last4", ")", "+", "1", ")", ",", "4", ",", "'0'", ",", "STR_PAD_LEFT", ")", ";", "}", "$", "node", "->", "TreeID", "=", "$", "newTreeID", ";", "}" ]
This only supports inserting nodes at the end of the tree or at the end of a list of children to a parent, which inherently means the 2nd criteria to the tree beyond parent is creation date @param $node @return unknown_type
[ "This", "only", "supports", "inserting", "nodes", "at", "the", "end", "of", "the", "tree", "or", "at", "the", "end", "of", "a", "list", "of", "children", "to", "a", "parent", "which", "inherently", "means", "the", "2nd", "criteria", "to", "the", "tree", "beyond", "parent", "is", "creation", "date" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/nodedb/daos/NodeDAO.php#L602-L665
train
SlabPHP/bundle-stack
src/Cache/Directories.php
Directories.buildCache
public function buildCache() { if (!empty($this->viewDirectories) || !empty($this->configDirectories) || !empty($this->resourceDirectories)) { return; } foreach ($this->orderReference as $namespace) { /** * @var \Slab\Components\BundleInterface $bundle */ $bundle =& $this->bundleReference[$namespace]; $this->viewDirectories[] = $bundle->getViewDirectory(); $this->configDirectories[] = $bundle->getConfigDirectory(); $this->resourceDirectories[] = $bundle->getResourceDirectory(); } }
php
public function buildCache() { if (!empty($this->viewDirectories) || !empty($this->configDirectories) || !empty($this->resourceDirectories)) { return; } foreach ($this->orderReference as $namespace) { /** * @var \Slab\Components\BundleInterface $bundle */ $bundle =& $this->bundleReference[$namespace]; $this->viewDirectories[] = $bundle->getViewDirectory(); $this->configDirectories[] = $bundle->getConfigDirectory(); $this->resourceDirectories[] = $bundle->getResourceDirectory(); } }
[ "public", "function", "buildCache", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "viewDirectories", ")", "||", "!", "empty", "(", "$", "this", "->", "configDirectories", ")", "||", "!", "empty", "(", "$", "this", "->", "resourceDirectories", ")", ")", "{", "return", ";", "}", "foreach", "(", "$", "this", "->", "orderReference", "as", "$", "namespace", ")", "{", "/**\n * @var \\Slab\\Components\\BundleInterface $bundle\n */", "$", "bundle", "=", "&", "$", "this", "->", "bundleReference", "[", "$", "namespace", "]", ";", "$", "this", "->", "viewDirectories", "[", "]", "=", "$", "bundle", "->", "getViewDirectory", "(", ")", ";", "$", "this", "->", "configDirectories", "[", "]", "=", "$", "bundle", "->", "getConfigDirectory", "(", ")", ";", "$", "this", "->", "resourceDirectories", "[", "]", "=", "$", "bundle", "->", "getResourceDirectory", "(", ")", ";", "}", "}" ]
Build directory cache, so we only do it once
[ "Build", "directory", "cache", "so", "we", "only", "do", "it", "once" ]
d96c4de469e58040968044d2d6525cb60d9dd8c6
https://github.com/SlabPHP/bundle-stack/blob/d96c4de469e58040968044d2d6525cb60d9dd8c6/src/Cache/Directories.php#L52-L69
train
spiral/console
src/Traits/HelpersTrait.php
HelpersTrait.sprintf
protected function sprintf(string $format, ...$args) { return $this->output->write(sprintf($format, ...$args), false); }
php
protected function sprintf(string $format, ...$args) { return $this->output->write(sprintf($format, ...$args), false); }
[ "protected", "function", "sprintf", "(", "string", "$", "format", ",", "...", "$", "args", ")", "{", "return", "$", "this", "->", "output", "->", "write", "(", "sprintf", "(", "$", "format", ",", "...", "$", "args", ")", ",", "false", ")", ";", "}" ]
Identical to write function but provides ability to format message. Does not add new line. @param string $format @param array ...$args
[ "Identical", "to", "write", "function", "but", "provides", "ability", "to", "format", "message", ".", "Does", "not", "add", "new", "line", "." ]
c3d99450ddd32bcc6f87e2b2ed40821054a93da3
https://github.com/spiral/console/blob/c3d99450ddd32bcc6f87e2b2ed40821054a93da3/src/Traits/HelpersTrait.php#L74-L77
train
agentmedia/phine-core
src/Core/Snippets/BackendRights/ContainerRights.php
ContainerRights.Save
function Save() { $this->contentRights->Save(); if (!$this->rights) { $this->rights = new BackendContainerRights(); } $this->rights->SetEdit($this->Value('Edit')); $this->rights->SetRemove($this->Value('Remove')); $this->rights->SetContentRights($this->contentRights->Rights()); $this->rights->Save(); }
php
function Save() { $this->contentRights->Save(); if (!$this->rights) { $this->rights = new BackendContainerRights(); } $this->rights->SetEdit($this->Value('Edit')); $this->rights->SetRemove($this->Value('Remove')); $this->rights->SetContentRights($this->contentRights->Rights()); $this->rights->Save(); }
[ "function", "Save", "(", ")", "{", "$", "this", "->", "contentRights", "->", "Save", "(", ")", ";", "if", "(", "!", "$", "this", "->", "rights", ")", "{", "$", "this", "->", "rights", "=", "new", "BackendContainerRights", "(", ")", ";", "}", "$", "this", "->", "rights", "->", "SetEdit", "(", "$", "this", "->", "Value", "(", "'Edit'", ")", ")", ";", "$", "this", "->", "rights", "->", "SetRemove", "(", "$", "this", "->", "Value", "(", "'Remove'", ")", ")", ";", "$", "this", "->", "rights", "->", "SetContentRights", "(", "$", "this", "->", "contentRights", "->", "Rights", "(", ")", ")", ";", "$", "this", "->", "rights", "->", "Save", "(", ")", ";", "}" ]
Saves the container rights
[ "Saves", "the", "container", "rights" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Snippets/BackendRights/ContainerRights.php#L43-L54
train
net-tools/core
src/Containers/Cache.php
Cache.unregister
public function unregister($k) { if ( array_key_exists($k, $this->_items) ) { $item = $this->_items[$k]; unset($this->_items[$k]); return $item; } else return FALSE; }
php
public function unregister($k) { if ( array_key_exists($k, $this->_items) ) { $item = $this->_items[$k]; unset($this->_items[$k]); return $item; } else return FALSE; }
[ "public", "function", "unregister", "(", "$", "k", ")", "{", "if", "(", "array_key_exists", "(", "$", "k", ",", "$", "this", "->", "_items", ")", ")", "{", "$", "item", "=", "$", "this", "->", "_items", "[", "$", "k", "]", ";", "unset", "(", "$", "this", "->", "_items", "[", "$", "k", "]", ")", ";", "return", "$", "item", ";", "}", "else", "return", "FALSE", ";", "}" ]
Delete an item from cache @param string $k Item key to remove @return bool|mixed $item Returns the item removed or FALSE if item not found in cache
[ "Delete", "an", "item", "from", "cache" ]
51446641cee22c0cf53d2b409c76cc8bd1a187e7
https://github.com/net-tools/core/blob/51446641cee22c0cf53d2b409c76cc8bd1a187e7/src/Containers/Cache.php#L60-L70
train
net-tools/core
src/Containers/Cache.php
Cache.get
public function get($k) { if ( array_key_exists($k, $this->_items) ) return $this->_items[$k]; else return FALSE; }
php
public function get($k) { if ( array_key_exists($k, $this->_items) ) return $this->_items[$k]; else return FALSE; }
[ "public", "function", "get", "(", "$", "k", ")", "{", "if", "(", "array_key_exists", "(", "$", "k", ",", "$", "this", "->", "_items", ")", ")", "return", "$", "this", "->", "_items", "[", "$", "k", "]", ";", "else", "return", "FALSE", ";", "}" ]
Fetch an item from cache @param string $k Item to fetch @return bool|mixed $item Returns the item or FALSE if item not found in cache
[ "Fetch", "an", "item", "from", "cache" ]
51446641cee22c0cf53d2b409c76cc8bd1a187e7
https://github.com/net-tools/core/blob/51446641cee22c0cf53d2b409c76cc8bd1a187e7/src/Containers/Cache.php#L79-L85
train
bartonlp/site-class
includes/SiteClass.class.php
SiteClass.counter2
protected function counter2() { if($this->nodb) { return; } $this->query("select count(*) from information_schema.tables " . "where (table_schema = '$this->masterdb') ". "and (table_name = 'counter2')"); list($ok) = $this->fetchrow('num'); if($ok) { if($this->isBot) { // BLP 2017-11-01 -- add left to keep from getting too long errors $sql = "insert into $this->masterdb.counter2 (site, date, filename, count, bots, lasttime) ". "values('$this->siteName', now(), left('$this->requestUri', 254), 0, 1, now()) ". "on duplicate key update bots=bots+1, lasttime=now()"; } else { $member = 0; $memberUpdate = ''; if($this->id) { $member = 1; $memberUpdate = ", members=members+1"; } // BLP 2017-11-01 -- add left to keep from getting too long errors $sql = "insert into $this->masterdb.counter2 (site, date, filename, count, members, lasttime) ". "values('$this->siteName', now(), left('$this->requestUri', 254), 1, $member, now()) ". "on duplicate key update count=count+1$memberUpdate, lasttime=now()"; } $this->query($sql); } else { $this->debug("$this->siteName: $this->self: table bots does not exist in the $this->masterdb database"); } }
php
protected function counter2() { if($this->nodb) { return; } $this->query("select count(*) from information_schema.tables " . "where (table_schema = '$this->masterdb') ". "and (table_name = 'counter2')"); list($ok) = $this->fetchrow('num'); if($ok) { if($this->isBot) { // BLP 2017-11-01 -- add left to keep from getting too long errors $sql = "insert into $this->masterdb.counter2 (site, date, filename, count, bots, lasttime) ". "values('$this->siteName', now(), left('$this->requestUri', 254), 0, 1, now()) ". "on duplicate key update bots=bots+1, lasttime=now()"; } else { $member = 0; $memberUpdate = ''; if($this->id) { $member = 1; $memberUpdate = ", members=members+1"; } // BLP 2017-11-01 -- add left to keep from getting too long errors $sql = "insert into $this->masterdb.counter2 (site, date, filename, count, members, lasttime) ". "values('$this->siteName', now(), left('$this->requestUri', 254), 1, $member, now()) ". "on duplicate key update count=count+1$memberUpdate, lasttime=now()"; } $this->query($sql); } else { $this->debug("$this->siteName: $this->self: table bots does not exist in the $this->masterdb database"); } }
[ "protected", "function", "counter2", "(", ")", "{", "if", "(", "$", "this", "->", "nodb", ")", "{", "return", ";", "}", "$", "this", "->", "query", "(", "\"select count(*) from information_schema.tables \"", ".", "\"where (table_schema = '$this->masterdb') \"", ".", "\"and (table_name = 'counter2')\"", ")", ";", "list", "(", "$", "ok", ")", "=", "$", "this", "->", "fetchrow", "(", "'num'", ")", ";", "if", "(", "$", "ok", ")", "{", "if", "(", "$", "this", "->", "isBot", ")", "{", "// BLP 2017-11-01 -- add left to keep from getting too long errors", "$", "sql", "=", "\"insert into $this->masterdb.counter2 (site, date, filename, count, bots, lasttime) \"", ".", "\"values('$this->siteName', now(), left('$this->requestUri', 254), 0, 1, now()) \"", ".", "\"on duplicate key update bots=bots+1, lasttime=now()\"", ";", "}", "else", "{", "$", "member", "=", "0", ";", "$", "memberUpdate", "=", "''", ";", "if", "(", "$", "this", "->", "id", ")", "{", "$", "member", "=", "1", ";", "$", "memberUpdate", "=", "\", members=members+1\"", ";", "}", "// BLP 2017-11-01 -- add left to keep from getting too long errors", "$", "sql", "=", "\"insert into $this->masterdb.counter2 (site, date, filename, count, members, lasttime) \"", ".", "\"values('$this->siteName', now(), left('$this->requestUri', 254), 1, $member, now()) \"", ".", "\"on duplicate key update count=count+1$memberUpdate, lasttime=now()\"", ";", "}", "$", "this", "->", "query", "(", "$", "sql", ")", ";", "}", "else", "{", "$", "this", "->", "debug", "(", "\"$this->siteName: $this->self: table bots does not exist in the $this->masterdb database\"", ")", ";", "}", "}" ]
counter2 count files accessed per day WARNING this may be overriden is a child class
[ "counter2", "count", "files", "accessed", "per", "day", "WARNING", "this", "may", "be", "overriden", "is", "a", "child", "class" ]
9095b101701ef0ae12ea9a2b4587a18072d04438
https://github.com/bartonlp/site-class/blob/9095b101701ef0ae12ea9a2b4587a18072d04438/includes/SiteClass.class.php#L900-L934
train
phpffcms/ffcms-core
src/Managers/MigrationsManager.php
MigrationsManager.makeUp
public function makeUp($file) { // check if argument is array of files and run recursion if (Any::isArray($file)) { $success = true; foreach ($file as $single) { $exec = $this->makeUp($single); if (!$exec) { $success = false; } } return $success; } // check if migration file is exists if (!File::exist($this->dir . '/' . $file)) { return false; } // check if migration file located in extend directory and copy to default if (Normalize::diskFullPath($this->dir) !== Normalize::diskFullPath(static::DEFAULT_DIR)) { File::copy($this->dir . DIRECTORY_SEPARATOR . $file, static::DEFAULT_DIR . DIRECTORY_SEPARATOR . $file); } // include migration and get class name File::inc($this->dir . '/' . $file, false, false); $fullName = Str::cleanExtension($file); $class = Str::firstIn($fullName, '-'); // check if class is instance of migration interface if (!class_exists($class) || !is_a($class, 'Ffcms\Core\Migrations\MigrationInterface', true)) { return false; } // implement migration $init = new $class($fullName, $this->connection); $init->up(); $init->seed(); return true; }
php
public function makeUp($file) { // check if argument is array of files and run recursion if (Any::isArray($file)) { $success = true; foreach ($file as $single) { $exec = $this->makeUp($single); if (!$exec) { $success = false; } } return $success; } // check if migration file is exists if (!File::exist($this->dir . '/' . $file)) { return false; } // check if migration file located in extend directory and copy to default if (Normalize::diskFullPath($this->dir) !== Normalize::diskFullPath(static::DEFAULT_DIR)) { File::copy($this->dir . DIRECTORY_SEPARATOR . $file, static::DEFAULT_DIR . DIRECTORY_SEPARATOR . $file); } // include migration and get class name File::inc($this->dir . '/' . $file, false, false); $fullName = Str::cleanExtension($file); $class = Str::firstIn($fullName, '-'); // check if class is instance of migration interface if (!class_exists($class) || !is_a($class, 'Ffcms\Core\Migrations\MigrationInterface', true)) { return false; } // implement migration $init = new $class($fullName, $this->connection); $init->up(); $init->seed(); return true; }
[ "public", "function", "makeUp", "(", "$", "file", ")", "{", "// check if argument is array of files and run recursion", "if", "(", "Any", "::", "isArray", "(", "$", "file", ")", ")", "{", "$", "success", "=", "true", ";", "foreach", "(", "$", "file", "as", "$", "single", ")", "{", "$", "exec", "=", "$", "this", "->", "makeUp", "(", "$", "single", ")", ";", "if", "(", "!", "$", "exec", ")", "{", "$", "success", "=", "false", ";", "}", "}", "return", "$", "success", ";", "}", "// check if migration file is exists", "if", "(", "!", "File", "::", "exist", "(", "$", "this", "->", "dir", ".", "'/'", ".", "$", "file", ")", ")", "{", "return", "false", ";", "}", "// check if migration file located in extend directory and copy to default", "if", "(", "Normalize", "::", "diskFullPath", "(", "$", "this", "->", "dir", ")", "!==", "Normalize", "::", "diskFullPath", "(", "static", "::", "DEFAULT_DIR", ")", ")", "{", "File", "::", "copy", "(", "$", "this", "->", "dir", ".", "DIRECTORY_SEPARATOR", ".", "$", "file", ",", "static", "::", "DEFAULT_DIR", ".", "DIRECTORY_SEPARATOR", ".", "$", "file", ")", ";", "}", "// include migration and get class name", "File", "::", "inc", "(", "$", "this", "->", "dir", ".", "'/'", ".", "$", "file", ",", "false", ",", "false", ")", ";", "$", "fullName", "=", "Str", "::", "cleanExtension", "(", "$", "file", ")", ";", "$", "class", "=", "Str", "::", "firstIn", "(", "$", "fullName", ",", "'-'", ")", ";", "// check if class is instance of migration interface", "if", "(", "!", "class_exists", "(", "$", "class", ")", "||", "!", "is_a", "(", "$", "class", ",", "'Ffcms\\Core\\Migrations\\MigrationInterface'", ",", "true", ")", ")", "{", "return", "false", ";", "}", "// implement migration", "$", "init", "=", "new", "$", "class", "(", "$", "fullName", ",", "$", "this", "->", "connection", ")", ";", "$", "init", "->", "up", "(", ")", ";", "$", "init", "->", "seed", "(", ")", ";", "return", "true", ";", "}" ]
Run migration up @param string|array $file @return bool
[ "Run", "migration", "up" ]
44a309553ef9f115ccfcfd71f2ac6e381c612082
https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Managers/MigrationsManager.php#L91-L131
train
phpffcms/ffcms-core
src/Managers/MigrationsManager.php
MigrationsManager.makeDown
public function makeDown($file) { if (Any::isArray($file)) { $success = true; foreach ($file as $item) { $exec = $this->makeDown($file); if (!$exec) { $success = false; } return $success; } } // check if exists if (!File::exist($this->dir . '/' . $file)) { return false; } File::inc($this->dir . '/' . $file, false, false); $fullName = Str::cleanExtension($file); $class = Str::firstIn($fullName, '-'); // check if class is instance of migration interface if (!class_exists($class) || !is_a($class, 'Ffcms\Core\Migrations\MigrationInterface', true)) { return false; } // init migration and execute down method $init = new $class($fullName, $this->connection); $init->down(); return true; }
php
public function makeDown($file) { if (Any::isArray($file)) { $success = true; foreach ($file as $item) { $exec = $this->makeDown($file); if (!$exec) { $success = false; } return $success; } } // check if exists if (!File::exist($this->dir . '/' . $file)) { return false; } File::inc($this->dir . '/' . $file, false, false); $fullName = Str::cleanExtension($file); $class = Str::firstIn($fullName, '-'); // check if class is instance of migration interface if (!class_exists($class) || !is_a($class, 'Ffcms\Core\Migrations\MigrationInterface', true)) { return false; } // init migration and execute down method $init = new $class($fullName, $this->connection); $init->down(); return true; }
[ "public", "function", "makeDown", "(", "$", "file", ")", "{", "if", "(", "Any", "::", "isArray", "(", "$", "file", ")", ")", "{", "$", "success", "=", "true", ";", "foreach", "(", "$", "file", "as", "$", "item", ")", "{", "$", "exec", "=", "$", "this", "->", "makeDown", "(", "$", "file", ")", ";", "if", "(", "!", "$", "exec", ")", "{", "$", "success", "=", "false", ";", "}", "return", "$", "success", ";", "}", "}", "// check if exists", "if", "(", "!", "File", "::", "exist", "(", "$", "this", "->", "dir", ".", "'/'", ".", "$", "file", ")", ")", "{", "return", "false", ";", "}", "File", "::", "inc", "(", "$", "this", "->", "dir", ".", "'/'", ".", "$", "file", ",", "false", ",", "false", ")", ";", "$", "fullName", "=", "Str", "::", "cleanExtension", "(", "$", "file", ")", ";", "$", "class", "=", "Str", "::", "firstIn", "(", "$", "fullName", ",", "'-'", ")", ";", "// check if class is instance of migration interface", "if", "(", "!", "class_exists", "(", "$", "class", ")", "||", "!", "is_a", "(", "$", "class", ",", "'Ffcms\\Core\\Migrations\\MigrationInterface'", ",", "true", ")", ")", "{", "return", "false", ";", "}", "// init migration and execute down method", "$", "init", "=", "new", "$", "class", "(", "$", "fullName", ",", "$", "this", "->", "connection", ")", ";", "$", "init", "->", "down", "(", ")", ";", "return", "true", ";", "}" ]
Make migration down @param array|string $file @return bool
[ "Make", "migration", "down" ]
44a309553ef9f115ccfcfd71f2ac6e381c612082
https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Managers/MigrationsManager.php#L138-L170
train
OpenConext/Stepup-bundle
src/EventListener/RequestIdRequestResponseListener.php
RequestIdRequestResponseListener.onKernelRequest
public function onKernelRequest(GetResponseEvent $event) { $headers = $event->getRequest()->headers; if (!$headers->has(self::HEADER_NAME)) { return; } $this->requestId->set($headers->get(self::HEADER_NAME, null, true), true); }
php
public function onKernelRequest(GetResponseEvent $event) { $headers = $event->getRequest()->headers; if (!$headers->has(self::HEADER_NAME)) { return; } $this->requestId->set($headers->get(self::HEADER_NAME, null, true), true); }
[ "public", "function", "onKernelRequest", "(", "GetResponseEvent", "$", "event", ")", "{", "$", "headers", "=", "$", "event", "->", "getRequest", "(", ")", "->", "headers", ";", "if", "(", "!", "$", "headers", "->", "has", "(", "self", "::", "HEADER_NAME", ")", ")", "{", "return", ";", "}", "$", "this", "->", "requestId", "->", "set", "(", "$", "headers", "->", "get", "(", "self", "::", "HEADER_NAME", ",", "null", ",", "true", ")", ",", "true", ")", ";", "}" ]
If present, reads the request ID from the appropriate header and sets it on a RequestId instance. @param GetResponseEvent $event
[ "If", "present", "reads", "the", "request", "ID", "from", "the", "appropriate", "header", "and", "sets", "it", "on", "a", "RequestId", "instance", "." ]
94178ddb421889df9e068109293a8da880793ed2
https://github.com/OpenConext/Stepup-bundle/blob/94178ddb421889df9e068109293a8da880793ed2/src/EventListener/RequestIdRequestResponseListener.php#L51-L60
train
OpenConext/Stepup-bundle
src/EventListener/RequestIdRequestResponseListener.php
RequestIdRequestResponseListener.onKernelResponse
public function onKernelResponse(FilterResponseEvent $event) { $event->getResponse()->headers->set(self::HEADER_NAME, $this->requestId->get()); }
php
public function onKernelResponse(FilterResponseEvent $event) { $event->getResponse()->headers->set(self::HEADER_NAME, $this->requestId->get()); }
[ "public", "function", "onKernelResponse", "(", "FilterResponseEvent", "$", "event", ")", "{", "$", "event", "->", "getResponse", "(", ")", "->", "headers", "->", "set", "(", "self", "::", "HEADER_NAME", ",", "$", "this", "->", "requestId", "->", "get", "(", ")", ")", ";", "}" ]
If enabled, sets the request ID on the appropriate response header. @param FilterResponseEvent $event
[ "If", "enabled", "sets", "the", "request", "ID", "on", "the", "appropriate", "response", "header", "." ]
94178ddb421889df9e068109293a8da880793ed2
https://github.com/OpenConext/Stepup-bundle/blob/94178ddb421889df9e068109293a8da880793ed2/src/EventListener/RequestIdRequestResponseListener.php#L67-L70
train
buflix/SimpleCollection
src/SimpleCollection/AbstractCollection.php
AbstractCollection.current
public function current() { $sKey = key($this->values); return (true === isset($this->values[$sKey])) ? $this->values[$sKey] : null; }
php
public function current() { $sKey = key($this->values); return (true === isset($this->values[$sKey])) ? $this->values[$sKey] : null; }
[ "public", "function", "current", "(", ")", "{", "$", "sKey", "=", "key", "(", "$", "this", "->", "values", ")", ";", "return", "(", "true", "===", "isset", "(", "$", "this", "->", "values", "[", "$", "sKey", "]", ")", ")", "?", "$", "this", "->", "values", "[", "$", "sKey", "]", ":", "null", ";", "}" ]
returns current value @return mixed
[ "returns", "current", "value" ]
405504d8be6415a872a5a49ce8223c22a932831a
https://github.com/buflix/SimpleCollection/blob/405504d8be6415a872a5a49ce8223c22a932831a/src/SimpleCollection/AbstractCollection.php#L47-L52
train
buflix/SimpleCollection
src/SimpleCollection/AbstractCollection.php
AbstractCollection.scNext
public function scNext() { $mValue = $this->next(); return (false === $mValue and false === $this->valid()) ? self::NOT_SET_FLAG : $mValue; }
php
public function scNext() { $mValue = $this->next(); return (false === $mValue and false === $this->valid()) ? self::NOT_SET_FLAG : $mValue; }
[ "public", "function", "scNext", "(", ")", "{", "$", "mValue", "=", "$", "this", "->", "next", "(", ")", ";", "return", "(", "false", "===", "$", "mValue", "and", "false", "===", "$", "this", "->", "valid", "(", ")", ")", "?", "self", "::", "NOT_SET_FLAG", ":", "$", "mValue", ";", "}" ]
Like next, but return Not_Set_Flag if there are no next value instead of false @return mixed
[ "Like", "next", "but", "return", "Not_Set_Flag", "if", "there", "are", "no", "next", "value", "instead", "of", "false" ]
405504d8be6415a872a5a49ce8223c22a932831a
https://github.com/buflix/SimpleCollection/blob/405504d8be6415a872a5a49ce8223c22a932831a/src/SimpleCollection/AbstractCollection.php#L69-L74
train
buflix/SimpleCollection
src/SimpleCollection/AbstractCollection.php
AbstractCollection.scPrev
public function scPrev() { $mValue = $this->prev(); return (false === $mValue and false === $this->valid()) ? self::NOT_SET_FLAG : $mValue; }
php
public function scPrev() { $mValue = $this->prev(); return (false === $mValue and false === $this->valid()) ? self::NOT_SET_FLAG : $mValue; }
[ "public", "function", "scPrev", "(", ")", "{", "$", "mValue", "=", "$", "this", "->", "prev", "(", ")", ";", "return", "(", "false", "===", "$", "mValue", "and", "false", "===", "$", "this", "->", "valid", "(", ")", ")", "?", "self", "::", "NOT_SET_FLAG", ":", "$", "mValue", ";", "}" ]
rewind the pointer for one position @return mixed|false
[ "rewind", "the", "pointer", "for", "one", "position" ]
405504d8be6415a872a5a49ce8223c22a932831a
https://github.com/buflix/SimpleCollection/blob/405504d8be6415a872a5a49ce8223c22a932831a/src/SimpleCollection/AbstractCollection.php#L91-L96
train
buflix/SimpleCollection
src/SimpleCollection/AbstractCollection.php
AbstractCollection.valid
public function valid() { $bIsValid = false; if (null !== $this->values) { $sKey = $this->key(); $bIsValid = isset($sKey); } return $bIsValid; }
php
public function valid() { $bIsValid = false; if (null !== $this->values) { $sKey = $this->key(); $bIsValid = isset($sKey); } return $bIsValid; }
[ "public", "function", "valid", "(", ")", "{", "$", "bIsValid", "=", "false", ";", "if", "(", "null", "!==", "$", "this", "->", "values", ")", "{", "$", "sKey", "=", "$", "this", "->", "key", "(", ")", ";", "$", "bIsValid", "=", "isset", "(", "$", "sKey", ")", ";", "}", "return", "$", "bIsValid", ";", "}" ]
check if the the current value is set @return bool True if set, otherwise false
[ "check", "if", "the", "the", "current", "value", "is", "set" ]
405504d8be6415a872a5a49ce8223c22a932831a
https://github.com/buflix/SimpleCollection/blob/405504d8be6415a872a5a49ce8223c22a932831a/src/SimpleCollection/AbstractCollection.php#L113-L122
train
buflix/SimpleCollection
src/SimpleCollection/AbstractCollection.php
AbstractCollection.get
public function get($mOffset, $mDefault = null) { return (true === isset($this->values[$mOffset])) ? $this->values[$mOffset] : $mDefault; }
php
public function get($mOffset, $mDefault = null) { return (true === isset($this->values[$mOffset])) ? $this->values[$mOffset] : $mDefault; }
[ "public", "function", "get", "(", "$", "mOffset", ",", "$", "mDefault", "=", "null", ")", "{", "return", "(", "true", "===", "isset", "(", "$", "this", "->", "values", "[", "$", "mOffset", "]", ")", ")", "?", "$", "this", "->", "values", "[", "$", "mOffset", "]", ":", "$", "mDefault", ";", "}" ]
Return the value with the given offset, if is not set return the default @param mixed $mOffset @param mixed $mDefault @return mixed
[ "Return", "the", "value", "with", "the", "given", "offset", "if", "is", "not", "set", "return", "the", "default" ]
405504d8be6415a872a5a49ce8223c22a932831a
https://github.com/buflix/SimpleCollection/blob/405504d8be6415a872a5a49ce8223c22a932831a/src/SimpleCollection/AbstractCollection.php#L176-L179
train
buflix/SimpleCollection
src/SimpleCollection/AbstractCollection.php
AbstractCollection.offsetSet
public function offsetSet($mOffset, $mValue) { if (false === is_string($mOffset) and false === is_integer($mOffset)) { throw new \InvalidArgumentException('Invalid offset given: ' . gettype($mOffset)); } $this->values[$mOffset] = $mValue; return $this; }
php
public function offsetSet($mOffset, $mValue) { if (false === is_string($mOffset) and false === is_integer($mOffset)) { throw new \InvalidArgumentException('Invalid offset given: ' . gettype($mOffset)); } $this->values[$mOffset] = $mValue; return $this; }
[ "public", "function", "offsetSet", "(", "$", "mOffset", ",", "$", "mValue", ")", "{", "if", "(", "false", "===", "is_string", "(", "$", "mOffset", ")", "and", "false", "===", "is_integer", "(", "$", "mOffset", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid offset given: '", ".", "gettype", "(", "$", "mOffset", ")", ")", ";", "}", "$", "this", "->", "values", "[", "$", "mOffset", "]", "=", "$", "mValue", ";", "return", "$", "this", ";", "}" ]
set the value by the given offset @param string|int $mOffset Offset @param mixed $mValue ProxyServer @return $this @throws \InvalidArgumentException
[ "set", "the", "value", "by", "the", "given", "offset" ]
405504d8be6415a872a5a49ce8223c22a932831a
https://github.com/buflix/SimpleCollection/blob/405504d8be6415a872a5a49ce8223c22a932831a/src/SimpleCollection/AbstractCollection.php#L204-L212
train
buflix/SimpleCollection
src/SimpleCollection/AbstractCollection.php
AbstractCollection.seek
public function seek($iOffset) { $this->rewind(); $iPosition = 0; while ($iPosition < $iOffset and true === $this->valid()) { $this->next(); $iPosition++; } if (false === $this->valid()) { throw new \OutOfBoundsException('Invalid seek position: ' . $iOffset); } return $this->current(); }
php
public function seek($iOffset) { $this->rewind(); $iPosition = 0; while ($iPosition < $iOffset and true === $this->valid()) { $this->next(); $iPosition++; } if (false === $this->valid()) { throw new \OutOfBoundsException('Invalid seek position: ' . $iOffset); } return $this->current(); }
[ "public", "function", "seek", "(", "$", "iOffset", ")", "{", "$", "this", "->", "rewind", "(", ")", ";", "$", "iPosition", "=", "0", ";", "while", "(", "$", "iPosition", "<", "$", "iOffset", "and", "true", "===", "$", "this", "->", "valid", "(", ")", ")", "{", "$", "this", "->", "next", "(", ")", ";", "$", "iPosition", "++", ";", "}", "if", "(", "false", "===", "$", "this", "->", "valid", "(", ")", ")", "{", "throw", "new", "\\", "OutOfBoundsException", "(", "'Invalid seek position: '", ".", "$", "iOffset", ")", ";", "}", "return", "$", "this", "->", "current", "(", ")", ";", "}" ]
seek the pointer to the offset position @param int $iOffset Seek position @return mixed @throws \OutOfBoundsException
[ "seek", "the", "pointer", "to", "the", "offset", "position" ]
405504d8be6415a872a5a49ce8223c22a932831a
https://github.com/buflix/SimpleCollection/blob/405504d8be6415a872a5a49ce8223c22a932831a/src/SimpleCollection/AbstractCollection.php#L246-L261
train
buflix/SimpleCollection
src/SimpleCollection/AbstractCollection.php
AbstractCollection.seekToKey
public function seekToKey($mKey, $bStrictMode = true) { $this->rewind(); if ($bStrictMode === true) { while (true === $this->valid() and $mKey !== $this->key()) { $this->next(); } } else { while (true === $this->valid() and $mKey != $this->key()) { $this->next(); } } if (false === $this->valid()) { throw new \OutOfBoundsException('Invalid seek position: ' . $mKey); } return $this->current(); }
php
public function seekToKey($mKey, $bStrictMode = true) { $this->rewind(); if ($bStrictMode === true) { while (true === $this->valid() and $mKey !== $this->key()) { $this->next(); } } else { while (true === $this->valid() and $mKey != $this->key()) { $this->next(); } } if (false === $this->valid()) { throw new \OutOfBoundsException('Invalid seek position: ' . $mKey); } return $this->current(); }
[ "public", "function", "seekToKey", "(", "$", "mKey", ",", "$", "bStrictMode", "=", "true", ")", "{", "$", "this", "->", "rewind", "(", ")", ";", "if", "(", "$", "bStrictMode", "===", "true", ")", "{", "while", "(", "true", "===", "$", "this", "->", "valid", "(", ")", "and", "$", "mKey", "!==", "$", "this", "->", "key", "(", ")", ")", "{", "$", "this", "->", "next", "(", ")", ";", "}", "}", "else", "{", "while", "(", "true", "===", "$", "this", "->", "valid", "(", ")", "and", "$", "mKey", "!=", "$", "this", "->", "key", "(", ")", ")", "{", "$", "this", "->", "next", "(", ")", ";", "}", "}", "if", "(", "false", "===", "$", "this", "->", "valid", "(", ")", ")", "{", "throw", "new", "\\", "OutOfBoundsException", "(", "'Invalid seek position: '", ".", "$", "mKey", ")", ";", "}", "return", "$", "this", "->", "current", "(", ")", ";", "}" ]
Try to seek to given offset @param mixed $mKey @param bool $bStrictMode @return mixed @throws \OutOfBoundsException
[ "Try", "to", "seek", "to", "given", "offset" ]
405504d8be6415a872a5a49ce8223c22a932831a
https://github.com/buflix/SimpleCollection/blob/405504d8be6415a872a5a49ce8223c22a932831a/src/SimpleCollection/AbstractCollection.php#L272-L289
train
buflix/SimpleCollection
src/SimpleCollection/AbstractCollection.php
AbstractCollection.filter
public function filter(\Closure $cClosure) { $sClassName = get_class($this); $aFilteredValues = array(); foreach ($this->values as $sKey => $mValue) { if (true === $cClosure($mValue, $sKey)) { $aFilteredValues[$sKey] = $mValue; } } return new $sClassName($aFilteredValues); }
php
public function filter(\Closure $cClosure) { $sClassName = get_class($this); $aFilteredValues = array(); foreach ($this->values as $sKey => $mValue) { if (true === $cClosure($mValue, $sKey)) { $aFilteredValues[$sKey] = $mValue; } } return new $sClassName($aFilteredValues); }
[ "public", "function", "filter", "(", "\\", "Closure", "$", "cClosure", ")", "{", "$", "sClassName", "=", "get_class", "(", "$", "this", ")", ";", "$", "aFilteredValues", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "values", "as", "$", "sKey", "=>", "$", "mValue", ")", "{", "if", "(", "true", "===", "$", "cClosure", "(", "$", "mValue", ",", "$", "sKey", ")", ")", "{", "$", "aFilteredValues", "[", "$", "sKey", "]", "=", "$", "mValue", ";", "}", "}", "return", "new", "$", "sClassName", "(", "$", "aFilteredValues", ")", ";", "}" ]
Filters the current values and return a new collection @param \Closure $cClosure @return AbstractCollection
[ "Filters", "the", "current", "values", "and", "return", "a", "new", "collection" ]
405504d8be6415a872a5a49ce8223c22a932831a
https://github.com/buflix/SimpleCollection/blob/405504d8be6415a872a5a49ce8223c22a932831a/src/SimpleCollection/AbstractCollection.php#L353-L364
train
buflix/SimpleCollection
src/SimpleCollection/AbstractCollection.php
AbstractCollection.forAll
public function forAll(\Closure $cClosure) { foreach ($this->values as $mKey => $mValue) { $this->offsetSet($mKey, $cClosure($mValue, $mKey)); } return $this; }
php
public function forAll(\Closure $cClosure) { foreach ($this->values as $mKey => $mValue) { $this->offsetSet($mKey, $cClosure($mValue, $mKey)); } return $this; }
[ "public", "function", "forAll", "(", "\\", "Closure", "$", "cClosure", ")", "{", "foreach", "(", "$", "this", "->", "values", "as", "$", "mKey", "=>", "$", "mValue", ")", "{", "$", "this", "->", "offsetSet", "(", "$", "mKey", ",", "$", "cClosure", "(", "$", "mValue", ",", "$", "mKey", ")", ")", ";", "}", "return", "$", "this", ";", "}" ]
Use a function on all values of the collection, and set the result as new values for the key @param \Closure $cClosure @return $this
[ "Use", "a", "function", "on", "all", "values", "of", "the", "collection", "and", "set", "the", "result", "as", "new", "values", "for", "the", "key" ]
405504d8be6415a872a5a49ce8223c22a932831a
https://github.com/buflix/SimpleCollection/blob/405504d8be6415a872a5a49ce8223c22a932831a/src/SimpleCollection/AbstractCollection.php#L373-L380
train
buflix/SimpleCollection
src/SimpleCollection/AbstractCollection.php
AbstractCollection.sliceByKey
public function sliceByKey($mStartKey, $bStrict = true, $iLength = PHP_INT_MAX) { $aSlice = array(); try { $this->seekToKey($mStartKey, $bStrict); if ($iLength > 0) { $aSlice[$this->key()] = $this->current(); $iLength--; $this->next(); } while ($iLength > 0 and true === $this->valid()) { $aSlice[$this->key()] = $this->current(); $iLength--; $this->next(); } } catch (\OutOfBoundsException $e) { //do nothing if key not exists } $sClassName = get_class($this); return new $sClassName($aSlice); }
php
public function sliceByKey($mStartKey, $bStrict = true, $iLength = PHP_INT_MAX) { $aSlice = array(); try { $this->seekToKey($mStartKey, $bStrict); if ($iLength > 0) { $aSlice[$this->key()] = $this->current(); $iLength--; $this->next(); } while ($iLength > 0 and true === $this->valid()) { $aSlice[$this->key()] = $this->current(); $iLength--; $this->next(); } } catch (\OutOfBoundsException $e) { //do nothing if key not exists } $sClassName = get_class($this); return new $sClassName($aSlice); }
[ "public", "function", "sliceByKey", "(", "$", "mStartKey", ",", "$", "bStrict", "=", "true", ",", "$", "iLength", "=", "PHP_INT_MAX", ")", "{", "$", "aSlice", "=", "array", "(", ")", ";", "try", "{", "$", "this", "->", "seekToKey", "(", "$", "mStartKey", ",", "$", "bStrict", ")", ";", "if", "(", "$", "iLength", ">", "0", ")", "{", "$", "aSlice", "[", "$", "this", "->", "key", "(", ")", "]", "=", "$", "this", "->", "current", "(", ")", ";", "$", "iLength", "--", ";", "$", "this", "->", "next", "(", ")", ";", "}", "while", "(", "$", "iLength", ">", "0", "and", "true", "===", "$", "this", "->", "valid", "(", ")", ")", "{", "$", "aSlice", "[", "$", "this", "->", "key", "(", ")", "]", "=", "$", "this", "->", "current", "(", ")", ";", "$", "iLength", "--", ";", "$", "this", "->", "next", "(", ")", ";", "}", "}", "catch", "(", "\\", "OutOfBoundsException", "$", "e", ")", "{", "//do nothing if key not exists", "}", "$", "sClassName", "=", "get_class", "(", "$", "this", ")", ";", "return", "new", "$", "sClassName", "(", "$", "aSlice", ")", ";", "}" ]
Slice elements and create a new instance @param mixed $mStartKey @param bool $bStrict @param int $iLength @return AbstractCollection
[ "Slice", "elements", "and", "create", "a", "new", "instance" ]
405504d8be6415a872a5a49ce8223c22a932831a
https://github.com/buflix/SimpleCollection/blob/405504d8be6415a872a5a49ce8223c22a932831a/src/SimpleCollection/AbstractCollection.php#L391-L414
train
SagittariusX/Beluga.Core
src/Beluga/TypeTool.php
TypeTool.XmlToType
public static function XmlToType( \SimpleXMLElement $xmlElement ) { $type = null; $value = null; if ( false !== ( $type = XmlAttributeHelper::GetAttributeValue( $xmlElement, 'type' ) ) ) { $type = (string) $type; } else if ( isset( $xmlElement->type ) ) { $type = (string) $xmlElement->type; } else if ( isset( $xmlElement->Type ) ) { $type = (string) $xmlElement->Type; } else { return $value; } if ( false !== ( $value = XmlAttributeHelper::GetAttributeValue( $xmlElement, 'value' ) ) ) { $value = (string) $value; } elseif ( isset( $xmlElement->value ) ) { $value = (string) $xmlElement->value; } elseif ( isset( $xmlElement->Value ) ) { $value = (string) $xmlElement->Value; } else { $value = (string) $xmlElement; } return static::StrToType( $value, $type ); }
php
public static function XmlToType( \SimpleXMLElement $xmlElement ) { $type = null; $value = null; if ( false !== ( $type = XmlAttributeHelper::GetAttributeValue( $xmlElement, 'type' ) ) ) { $type = (string) $type; } else if ( isset( $xmlElement->type ) ) { $type = (string) $xmlElement->type; } else if ( isset( $xmlElement->Type ) ) { $type = (string) $xmlElement->Type; } else { return $value; } if ( false !== ( $value = XmlAttributeHelper::GetAttributeValue( $xmlElement, 'value' ) ) ) { $value = (string) $value; } elseif ( isset( $xmlElement->value ) ) { $value = (string) $xmlElement->value; } elseif ( isset( $xmlElement->Value ) ) { $value = (string) $xmlElement->Value; } else { $value = (string) $xmlElement; } return static::StrToType( $value, $type ); }
[ "public", "static", "function", "XmlToType", "(", "\\", "SimpleXMLElement", "$", "xmlElement", ")", "{", "$", "type", "=", "null", ";", "$", "value", "=", "null", ";", "if", "(", "false", "!==", "(", "$", "type", "=", "XmlAttributeHelper", "::", "GetAttributeValue", "(", "$", "xmlElement", ",", "'type'", ")", ")", ")", "{", "$", "type", "=", "(", "string", ")", "$", "type", ";", "}", "else", "if", "(", "isset", "(", "$", "xmlElement", "->", "type", ")", ")", "{", "$", "type", "=", "(", "string", ")", "$", "xmlElement", "->", "type", ";", "}", "else", "if", "(", "isset", "(", "$", "xmlElement", "->", "Type", ")", ")", "{", "$", "type", "=", "(", "string", ")", "$", "xmlElement", "->", "Type", ";", "}", "else", "{", "return", "$", "value", ";", "}", "if", "(", "false", "!==", "(", "$", "value", "=", "XmlAttributeHelper", "::", "GetAttributeValue", "(", "$", "xmlElement", ",", "'value'", ")", ")", ")", "{", "$", "value", "=", "(", "string", ")", "$", "value", ";", "}", "elseif", "(", "isset", "(", "$", "xmlElement", "->", "value", ")", ")", "{", "$", "value", "=", "(", "string", ")", "$", "xmlElement", "->", "value", ";", "}", "elseif", "(", "isset", "(", "$", "xmlElement", "->", "Value", ")", ")", "{", "$", "value", "=", "(", "string", ")", "$", "xmlElement", "->", "Value", ";", "}", "else", "{", "$", "value", "=", "(", "string", ")", "$", "xmlElement", ";", "}", "return", "static", "::", "StrToType", "(", "$", "value", ",", "$", "type", ")", ";", "}" ]
Extracts typed data from defined XML element. For it, the XML element must define the data of a single value. The type name can be defined by 'type' attribute or by the &lt;Type&gt;Typename&lt;/Type&gt; element. The type value can be defined as string by 'value' attribute or by the &lt;Value&gt;A value&lt;/Value&gt; element, or by the string value defined inside the XML element it self. (&lt;XmlElement type="..."&gt;A Value&lt;/XmlElement&gt;) @param \SimpleXMLElement $xmlElement The XML element defining the typed value. @return mixed The typed value, or NULL if no usable data are defined
[ "Extracts", "typed", "data", "from", "defined", "XML", "element", "." ]
51057b362707157a4b075df42bb49f397e2d310b
https://github.com/SagittariusX/Beluga.Core/blob/51057b362707157a4b075df42bb49f397e2d310b/src/Beluga/TypeTool.php#L424-L466
train
SagittariusX/Beluga.Core
src/Beluga/TypeTool.php
TypeTool.WriteTypedXmlValue
public static function WriteTypedXmlValue( \XMLWriter $w, $value, string $name, bool $short = true, bool $separateElements = false) { if ( ! ( $value instanceof Type ) ) { $value = new Type( $value ); } $v = null; $t = null; switch ( $value->getType() ) { case Type::PHP_ARRAY: $v = \serialize( $value->getValue() ); $t = Type::PHP_ARRAY; break; case Type::PHP_BOOLEAN: $v = $value->getValue() ? 'true' : 'false'; $t = Type::PHP_BOOLEAN; break; case Type::PHP_DOUBLE: case Type::PHP_FLOAT: case Type::PHP_INTEGER: $v = $value->getValue(); $t = $value->getType(); break; case Type::PHP_NULL: $v = ''; $t = Type::PHP_NULL; break; case Type::PHP_RESOURCE: # Ignore some resources break; case Type::PHP_STRING: $v = $value->getValue(); $t = Type::PHP_STRING; break; case Type::PHP_UNKNOWN: $v = $value->getStringValue(); $t = Type::PHP_STRING; break; default: $v = \serialize( $value->getValue() ); $t = $value->getType(); break; } if ( ! \is_null( $t ) && ! \is_null( $v ) ) { $w->startElement( $name ); if ( $short ) { $w->writeAttribute( 'type', $t ); $w->writeAttribute( 'value', $v ); } else { if ( $separateElements ) { $w->writeElement( 'type', $t ); $w->writeElement( 'value', $v ); } else { $w->writeAttribute( 'type', $t ); $w->text( $v ); } } $w->endElement(); } }
php
public static function WriteTypedXmlValue( \XMLWriter $w, $value, string $name, bool $short = true, bool $separateElements = false) { if ( ! ( $value instanceof Type ) ) { $value = new Type( $value ); } $v = null; $t = null; switch ( $value->getType() ) { case Type::PHP_ARRAY: $v = \serialize( $value->getValue() ); $t = Type::PHP_ARRAY; break; case Type::PHP_BOOLEAN: $v = $value->getValue() ? 'true' : 'false'; $t = Type::PHP_BOOLEAN; break; case Type::PHP_DOUBLE: case Type::PHP_FLOAT: case Type::PHP_INTEGER: $v = $value->getValue(); $t = $value->getType(); break; case Type::PHP_NULL: $v = ''; $t = Type::PHP_NULL; break; case Type::PHP_RESOURCE: # Ignore some resources break; case Type::PHP_STRING: $v = $value->getValue(); $t = Type::PHP_STRING; break; case Type::PHP_UNKNOWN: $v = $value->getStringValue(); $t = Type::PHP_STRING; break; default: $v = \serialize( $value->getValue() ); $t = $value->getType(); break; } if ( ! \is_null( $t ) && ! \is_null( $v ) ) { $w->startElement( $name ); if ( $short ) { $w->writeAttribute( 'type', $t ); $w->writeAttribute( 'value', $v ); } else { if ( $separateElements ) { $w->writeElement( 'type', $t ); $w->writeElement( 'value', $v ); } else { $w->writeAttribute( 'type', $t ); $w->text( $v ); } } $w->endElement(); } }
[ "public", "static", "function", "WriteTypedXmlValue", "(", "\\", "XMLWriter", "$", "w", ",", "$", "value", ",", "string", "$", "name", ",", "bool", "$", "short", "=", "true", ",", "bool", "$", "separateElements", "=", "false", ")", "{", "if", "(", "!", "(", "$", "value", "instanceof", "Type", ")", ")", "{", "$", "value", "=", "new", "Type", "(", "$", "value", ")", ";", "}", "$", "v", "=", "null", ";", "$", "t", "=", "null", ";", "switch", "(", "$", "value", "->", "getType", "(", ")", ")", "{", "case", "Type", "::", "PHP_ARRAY", ":", "$", "v", "=", "\\", "serialize", "(", "$", "value", "->", "getValue", "(", ")", ")", ";", "$", "t", "=", "Type", "::", "PHP_ARRAY", ";", "break", ";", "case", "Type", "::", "PHP_BOOLEAN", ":", "$", "v", "=", "$", "value", "->", "getValue", "(", ")", "?", "'true'", ":", "'false'", ";", "$", "t", "=", "Type", "::", "PHP_BOOLEAN", ";", "break", ";", "case", "Type", "::", "PHP_DOUBLE", ":", "case", "Type", "::", "PHP_FLOAT", ":", "case", "Type", "::", "PHP_INTEGER", ":", "$", "v", "=", "$", "value", "->", "getValue", "(", ")", ";", "$", "t", "=", "$", "value", "->", "getType", "(", ")", ";", "break", ";", "case", "Type", "::", "PHP_NULL", ":", "$", "v", "=", "''", ";", "$", "t", "=", "Type", "::", "PHP_NULL", ";", "break", ";", "case", "Type", "::", "PHP_RESOURCE", ":", "# Ignore some resources", "break", ";", "case", "Type", "::", "PHP_STRING", ":", "$", "v", "=", "$", "value", "->", "getValue", "(", ")", ";", "$", "t", "=", "Type", "::", "PHP_STRING", ";", "break", ";", "case", "Type", "::", "PHP_UNKNOWN", ":", "$", "v", "=", "$", "value", "->", "getStringValue", "(", ")", ";", "$", "t", "=", "Type", "::", "PHP_STRING", ";", "break", ";", "default", ":", "$", "v", "=", "\\", "serialize", "(", "$", "value", "->", "getValue", "(", ")", ")", ";", "$", "t", "=", "$", "value", "->", "getType", "(", ")", ";", "break", ";", "}", "if", "(", "!", "\\", "is_null", "(", "$", "t", ")", "&&", "!", "\\", "is_null", "(", "$", "v", ")", ")", "{", "$", "w", "->", "startElement", "(", "$", "name", ")", ";", "if", "(", "$", "short", ")", "{", "$", "w", "->", "writeAttribute", "(", "'type'", ",", "$", "t", ")", ";", "$", "w", "->", "writeAttribute", "(", "'value'", ",", "$", "v", ")", ";", "}", "else", "{", "if", "(", "$", "separateElements", ")", "{", "$", "w", "->", "writeElement", "(", "'type'", ",", "$", "t", ")", ";", "$", "w", "->", "writeElement", "(", "'value'", ",", "$", "v", ")", ";", "}", "else", "{", "$", "w", "->", "writeAttribute", "(", "'type'", ",", "$", "t", ")", ";", "$", "w", "->", "text", "(", "$", "v", ")", ";", "}", "}", "$", "w", "->", "endElement", "(", ")", ";", "}", "}" ]
Writes all data of the defined Value to the XmlWriter. You can write it in 3 different ways: - &lt;$name type="..." value="..." /&gt; Is created if $short is boolean TRUE. If $short is FALSE you can write in the following 2 ways: - &lt;$name type="..."&gt;$value&lt;/$name&gt; Is created if $separateElements is boolean FALSE. - &lt;$name&gt;&lt;Type&gt;...&lt;/Type&gt;&lt;Value&gt;$value&lt;/Value&gt;&lt;/$name&gt; Is created if $separateElements is boolean TRUE. @param \XMLWriter $w The XmlWriter to use. @param mixed $value The value to write. @param string $name The name of the element to write @param boolean $short Use the short notation? (type and value as attributes) @param boolean $separateElements Write type and value in separate elements, if $short is FALSE
[ "Writes", "all", "data", "of", "the", "defined", "Value", "to", "the", "XmlWriter", "." ]
51057b362707157a4b075df42bb49f397e2d310b
https://github.com/SagittariusX/Beluga.Core/blob/51057b362707157a4b075df42bb49f397e2d310b/src/Beluga/TypeTool.php#L489-L575
train
SagittariusX/Beluga.Core
src/Beluga/TypeTool.php
TypeTool.IsNativeType
public static function IsNativeType( $value ) : bool { return ( \is_bool( $value ) || \is_int( $value ) || \is_string( $value ) || \is_double( $value ) || \is_float( $value ) || \is_array( $value ) ); }
php
public static function IsNativeType( $value ) : bool { return ( \is_bool( $value ) || \is_int( $value ) || \is_string( $value ) || \is_double( $value ) || \is_float( $value ) || \is_array( $value ) ); }
[ "public", "static", "function", "IsNativeType", "(", "$", "value", ")", ":", "bool", "{", "return", "(", "\\", "is_bool", "(", "$", "value", ")", "||", "\\", "is_int", "(", "$", "value", ")", "||", "\\", "is_string", "(", "$", "value", ")", "||", "\\", "is_double", "(", "$", "value", ")", "||", "\\", "is_float", "(", "$", "value", ")", "||", "\\", "is_array", "(", "$", "value", ")", ")", ";", "}" ]
Returns if the type of defined value is a native PHP type. Native types are: boolean, integer, double, float, string, array @param mixed $value THe value to check. @return boolean
[ "Returns", "if", "the", "type", "of", "defined", "value", "is", "a", "native", "PHP", "type", "." ]
51057b362707157a4b075df42bb49f397e2d310b
https://github.com/SagittariusX/Beluga.Core/blob/51057b362707157a4b075df42bb49f397e2d310b/src/Beluga/TypeTool.php#L585-L597
train
SagittariusX/Beluga.Core
src/Beluga/TypeTool.php
TypeTool.GetTypeName
public static function GetTypeName( $value ) : string { if ( \is_null( $value ) ) { return Type::PHP_NULL; } if ( \is_object( $value ) ) { return \get_class( $value ); } if ( \is_string( $value ) ) { return Type::PHP_STRING; } if ( \is_int( $value ) ) { return Type::PHP_INTEGER; } if ( \is_bool( $value ) ) { return Type::PHP_BOOLEAN; } if ( \is_double( $value ) ) { return Type::PHP_DOUBLE; } if ( \is_float( $value ) ) { return Type::PHP_FLOAT; } if ( \is_resource( $value ) ) { return Type::PHP_RESOURCE; } if ( \is_array( $value ) ) { return Type::PHP_ARRAY; } return Type::PHP_UNKNOWN; }
php
public static function GetTypeName( $value ) : string { if ( \is_null( $value ) ) { return Type::PHP_NULL; } if ( \is_object( $value ) ) { return \get_class( $value ); } if ( \is_string( $value ) ) { return Type::PHP_STRING; } if ( \is_int( $value ) ) { return Type::PHP_INTEGER; } if ( \is_bool( $value ) ) { return Type::PHP_BOOLEAN; } if ( \is_double( $value ) ) { return Type::PHP_DOUBLE; } if ( \is_float( $value ) ) { return Type::PHP_FLOAT; } if ( \is_resource( $value ) ) { return Type::PHP_RESOURCE; } if ( \is_array( $value ) ) { return Type::PHP_ARRAY; } return Type::PHP_UNKNOWN; }
[ "public", "static", "function", "GetTypeName", "(", "$", "value", ")", ":", "string", "{", "if", "(", "\\", "is_null", "(", "$", "value", ")", ")", "{", "return", "Type", "::", "PHP_NULL", ";", "}", "if", "(", "\\", "is_object", "(", "$", "value", ")", ")", "{", "return", "\\", "get_class", "(", "$", "value", ")", ";", "}", "if", "(", "\\", "is_string", "(", "$", "value", ")", ")", "{", "return", "Type", "::", "PHP_STRING", ";", "}", "if", "(", "\\", "is_int", "(", "$", "value", ")", ")", "{", "return", "Type", "::", "PHP_INTEGER", ";", "}", "if", "(", "\\", "is_bool", "(", "$", "value", ")", ")", "{", "return", "Type", "::", "PHP_BOOLEAN", ";", "}", "if", "(", "\\", "is_double", "(", "$", "value", ")", ")", "{", "return", "Type", "::", "PHP_DOUBLE", ";", "}", "if", "(", "\\", "is_float", "(", "$", "value", ")", ")", "{", "return", "Type", "::", "PHP_FLOAT", ";", "}", "if", "(", "\\", "is_resource", "(", "$", "value", ")", ")", "{", "return", "Type", "::", "PHP_RESOURCE", ";", "}", "if", "(", "\\", "is_array", "(", "$", "value", ")", ")", "{", "return", "Type", "::", "PHP_ARRAY", ";", "}", "return", "Type", "::", "PHP_UNKNOWN", ";", "}" ]
Returns the type name of the defined value. @param mixed $value The value. @return string
[ "Returns", "the", "type", "name", "of", "the", "defined", "value", "." ]
51057b362707157a4b075df42bb49f397e2d310b
https://github.com/SagittariusX/Beluga.Core/blob/51057b362707157a4b075df42bb49f397e2d310b/src/Beluga/TypeTool.php#L643-L693
train
kawanamiyuu/Maye.OAuthClient
src/AbstractOAuthClient.php
AbstractOAuthClient.clearCachedAccessToken
protected function clearCachedAccessToken() { /** @var TokenStorageInterface $storage */ $storage = $this->service->getStorage(); $storage->clearToken($this->getServiceName()); return $this; }
php
protected function clearCachedAccessToken() { /** @var TokenStorageInterface $storage */ $storage = $this->service->getStorage(); $storage->clearToken($this->getServiceName()); return $this; }
[ "protected", "function", "clearCachedAccessToken", "(", ")", "{", "/** @var TokenStorageInterface $storage */", "$", "storage", "=", "$", "this", "->", "service", "->", "getStorage", "(", ")", ";", "$", "storage", "->", "clearToken", "(", "$", "this", "->", "getServiceName", "(", ")", ")", ";", "return", "$", "this", ";", "}" ]
clear Cached Access token @return self
[ "clear", "Cached", "Access", "token" ]
6001a66bb76d6477606d1d3700258b459f556226
https://github.com/kawanamiyuu/Maye.OAuthClient/blob/6001a66bb76d6477606d1d3700258b459f556226/src/AbstractOAuthClient.php#L54-L61
train
geoffadams/bedrest-core
library/BedRest/Resource/Mapping/ResourceMetadataFactory.php
ResourceMetadataFactory.getMetadataByResourceName
public function getMetadataByResourceName($resourceName) { $this->getAllMetadata(); if (!isset($this->resourceClassMap[$resourceName])) { throw Exception::resourceNotFound($resourceName); } return $this->loadedMetadata[$this->resourceClassMap[$resourceName]]; }
php
public function getMetadataByResourceName($resourceName) { $this->getAllMetadata(); if (!isset($this->resourceClassMap[$resourceName])) { throw Exception::resourceNotFound($resourceName); } return $this->loadedMetadata[$this->resourceClassMap[$resourceName]]; }
[ "public", "function", "getMetadataByResourceName", "(", "$", "resourceName", ")", "{", "$", "this", "->", "getAllMetadata", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "resourceClassMap", "[", "$", "resourceName", "]", ")", ")", "{", "throw", "Exception", "::", "resourceNotFound", "(", "$", "resourceName", ")", ";", "}", "return", "$", "this", "->", "loadedMetadata", "[", "$", "this", "->", "resourceClassMap", "[", "$", "resourceName", "]", "]", ";", "}" ]
Returns ResourceMetadata for the specified resource. @param string $resourceName @throws \BedRest\Resource\Mapping\Exception @return \BedRest\Resource\Mapping\ResourceMetadata
[ "Returns", "ResourceMetadata", "for", "the", "specified", "resource", "." ]
a77bf8b7492dfbfb720b201f7ec91a4f03417b5c
https://github.com/geoffadams/bedrest-core/blob/a77bf8b7492dfbfb720b201f7ec91a4f03417b5c/library/BedRest/Resource/Mapping/ResourceMetadataFactory.php#L150-L159
train
geoffadams/bedrest-core
library/BedRest/Resource/Mapping/ResourceMetadataFactory.php
ResourceMetadataFactory.getAllMetadata
public function getAllMetadata() { $resourceClasses = $this->driver->getAllClassNames(); foreach ($resourceClasses as $class) { $this->getMetadataFor($class); } return $this->loadedMetadata; }
php
public function getAllMetadata() { $resourceClasses = $this->driver->getAllClassNames(); foreach ($resourceClasses as $class) { $this->getMetadataFor($class); } return $this->loadedMetadata; }
[ "public", "function", "getAllMetadata", "(", ")", "{", "$", "resourceClasses", "=", "$", "this", "->", "driver", "->", "getAllClassNames", "(", ")", ";", "foreach", "(", "$", "resourceClasses", "as", "$", "class", ")", "{", "$", "this", "->", "getMetadataFor", "(", "$", "class", ")", ";", "}", "return", "$", "this", "->", "loadedMetadata", ";", "}" ]
Returns the entire collection of ResourceMetadata objects for all mapped resources. Entities not marked as resources are not included. @return array
[ "Returns", "the", "entire", "collection", "of", "ResourceMetadata", "objects", "for", "all", "mapped", "resources", ".", "Entities", "not", "marked", "as", "resources", "are", "not", "included", "." ]
a77bf8b7492dfbfb720b201f7ec91a4f03417b5c
https://github.com/geoffadams/bedrest-core/blob/a77bf8b7492dfbfb720b201f7ec91a4f03417b5c/library/BedRest/Resource/Mapping/ResourceMetadataFactory.php#L167-L176
train
geoffadams/bedrest-core
library/BedRest/Resource/Mapping/ResourceMetadataFactory.php
ResourceMetadataFactory.loadMetadata
protected function loadMetadata($className) { $resource = new ResourceMetadata($className); $this->driver->loadMetadataForClass($className, $resource); $this->loadedMetadata[$className] = $resource; $this->resourceClassMap[$resource->getName()] = $className; }
php
protected function loadMetadata($className) { $resource = new ResourceMetadata($className); $this->driver->loadMetadataForClass($className, $resource); $this->loadedMetadata[$className] = $resource; $this->resourceClassMap[$resource->getName()] = $className; }
[ "protected", "function", "loadMetadata", "(", "$", "className", ")", "{", "$", "resource", "=", "new", "ResourceMetadata", "(", "$", "className", ")", ";", "$", "this", "->", "driver", "->", "loadMetadataForClass", "(", "$", "className", ",", "$", "resource", ")", ";", "$", "this", "->", "loadedMetadata", "[", "$", "className", "]", "=", "$", "resource", ";", "$", "this", "->", "resourceClassMap", "[", "$", "resource", "->", "getName", "(", ")", "]", "=", "$", "className", ";", "}" ]
Loads the ResourceMetadata for the specified class. @param string $className
[ "Loads", "the", "ResourceMetadata", "for", "the", "specified", "class", "." ]
a77bf8b7492dfbfb720b201f7ec91a4f03417b5c
https://github.com/geoffadams/bedrest-core/blob/a77bf8b7492dfbfb720b201f7ec91a4f03417b5c/library/BedRest/Resource/Mapping/ResourceMetadataFactory.php#L183-L191
train
drdplusinfo/drdplus-skills
DrdPlus/Skills/Physical/ShieldUsage.php
ShieldUsage.getMalusToFightNumber
public function getMalusToFightNumber(Tables $tables, $shieldRestriction): int { /** * using shield as a weapon means using something without skill (zero skill ShieldAsAWeapon respectively) *, @see PPH page 86 right column top */ return $this->getRestrictionWithShield($tables, $shieldRestriction) + $tables->getMissingWeaponSkillTable()->getFightNumberMalusForSkillRank(0); }
php
public function getMalusToFightNumber(Tables $tables, $shieldRestriction): int { /** * using shield as a weapon means using something without skill (zero skill ShieldAsAWeapon respectively) *, @see PPH page 86 right column top */ return $this->getRestrictionWithShield($tables, $shieldRestriction) + $tables->getMissingWeaponSkillTable()->getFightNumberMalusForSkillRank(0); }
[ "public", "function", "getMalusToFightNumber", "(", "Tables", "$", "tables", ",", "$", "shieldRestriction", ")", ":", "int", "{", "/**\n * using shield as a weapon means using something without skill (zero skill ShieldAsAWeapon respectively)\n *, @see PPH page 86 right column top\n */", "return", "$", "this", "->", "getRestrictionWithShield", "(", "$", "tables", ",", "$", "shieldRestriction", ")", "+", "$", "tables", "->", "getMissingWeaponSkillTable", "(", ")", "->", "getFightNumberMalusForSkillRank", "(", "0", ")", ";", "}" ]
Only for using shield as a weapon! @param Tables $tables @param int $shieldRestriction as a negative number @return int negative number or zero @throws \Granam\Integer\Tools\Exceptions\WrongParameterType @throws \Granam\Integer\Tools\Exceptions\ValueLostOnCast @throws \Granam\Integer\Tools\Exceptions\NegativeIntegerCanNotBePositive
[ "Only", "for", "using", "shield", "as", "a", "weapon!" ]
9ae6ecdbaadf594d6572ec0c190fc13572c0a53f
https://github.com/drdplusinfo/drdplus-skills/blob/9ae6ecdbaadf594d6572ec0c190fc13572c0a53f/DrdPlus/Skills/Physical/ShieldUsage.php#L37-L46
train
mwyatt/core
src/Iterator/Collection.php
Collection.pluck
public function pluck($key, $unique = false) { $results = []; foreach ($this as $item) { $value = is_object($item) ? $item->$key : $item[$key]; if ($unique) { $results[$value] = $value; } else { $results[] = $value; } } $collection = new static($results); return $collection->resetKeys(); }
php
public function pluck($key, $unique = false) { $results = []; foreach ($this as $item) { $value = is_object($item) ? $item->$key : $item[$key]; if ($unique) { $results[$value] = $value; } else { $results[] = $value; } } $collection = new static($results); return $collection->resetKeys(); }
[ "public", "function", "pluck", "(", "$", "key", ",", "$", "unique", "=", "false", ")", "{", "$", "results", "=", "[", "]", ";", "foreach", "(", "$", "this", "as", "$", "item", ")", "{", "$", "value", "=", "is_object", "(", "$", "item", ")", "?", "$", "item", "->", "$", "key", ":", "$", "item", "[", "$", "key", "]", ";", "if", "(", "$", "unique", ")", "{", "$", "results", "[", "$", "value", "]", "=", "$", "value", ";", "}", "else", "{", "$", "results", "[", "]", "=", "$", "value", ";", "}", "}", "$", "collection", "=", "new", "static", "(", "$", "results", ")", ";", "return", "$", "collection", "->", "resetKeys", "(", ")", ";", "}" ]
get a collection of values from property @param string $property @return Object
[ "get", "a", "collection", "of", "values", "from", "property" ]
8ea9d67cc84fe6aff17a469c703d5492dbcd93ed
https://github.com/mwyatt/core/blob/8ea9d67cc84fe6aff17a469c703d5492dbcd93ed/src/Iterator/Collection.php#L45-L58
train
mwyatt/core
src/Iterator/Collection.php
Collection.getByPropertyValues
public function getByPropertyValues($property, $values, $strict = false) { $results = []; foreach ($this as $item) { foreach ($values as $value) { if ($strict) { if ($item->$property === $value) { $results[] = $item; } } else { if ($item->$property == $value) { $results[] = $item; } } } } return new static($results); }
php
public function getByPropertyValues($property, $values, $strict = false) { $results = []; foreach ($this as $item) { foreach ($values as $value) { if ($strict) { if ($item->$property === $value) { $results[] = $item; } } else { if ($item->$property == $value) { $results[] = $item; } } } } return new static($results); }
[ "public", "function", "getByPropertyValues", "(", "$", "property", ",", "$", "values", ",", "$", "strict", "=", "false", ")", "{", "$", "results", "=", "[", "]", ";", "foreach", "(", "$", "this", "as", "$", "item", ")", "{", "foreach", "(", "$", "values", "as", "$", "value", ")", "{", "if", "(", "$", "strict", ")", "{", "if", "(", "$", "item", "->", "$", "property", "===", "$", "value", ")", "{", "$", "results", "[", "]", "=", "$", "item", ";", "}", "}", "else", "{", "if", "(", "$", "item", "->", "$", "property", "==", "$", "value", ")", "{", "$", "results", "[", "]", "=", "$", "item", ";", "}", "}", "}", "}", "return", "new", "static", "(", "$", "results", ")", ";", "}" ]
get the models which match the property values loose matching not strict @param string $property @param mixed $value @return object ModelIterator
[ "get", "the", "models", "which", "match", "the", "property", "values", "loose", "matching", "not", "strict" ]
8ea9d67cc84fe6aff17a469c703d5492dbcd93ed
https://github.com/mwyatt/core/blob/8ea9d67cc84fe6aff17a469c703d5492dbcd93ed/src/Iterator/Collection.php#L79-L96
train
mwyatt/core
src/Iterator/Collection.php
Collection.getKeyedByProperty
public function getKeyedByProperty($property) { $results = []; foreach ($this as $item) { $results[$item->$property] = $item; } return new static($results); }
php
public function getKeyedByProperty($property) { $results = []; foreach ($this as $item) { $results[$item->$property] = $item; } return new static($results); }
[ "public", "function", "getKeyedByProperty", "(", "$", "property", ")", "{", "$", "results", "=", "[", "]", ";", "foreach", "(", "$", "this", "as", "$", "item", ")", "{", "$", "results", "[", "$", "item", "->", "$", "property", "]", "=", "$", "item", ";", "}", "return", "new", "static", "(", "$", "results", ")", ";", "}" ]
key the iterator by the specified property @param string $property @return Object
[ "key", "the", "iterator", "by", "the", "specified", "property" ]
8ea9d67cc84fe6aff17a469c703d5492dbcd93ed
https://github.com/mwyatt/core/blob/8ea9d67cc84fe6aff17a469c703d5492dbcd93ed/src/Iterator/Collection.php#L110-L117
train
mwyatt/core
src/Iterator/Collection.php
Collection.sort
public function sort(callable $callback = null) { $items = $this->getArrayCopy(); $callback ? uasort($items, $callback) : asort($items); return new static($items); }
php
public function sort(callable $callback = null) { $items = $this->getArrayCopy(); $callback ? uasort($items, $callback) : asort($items); return new static($items); }
[ "public", "function", "sort", "(", "callable", "$", "callback", "=", "null", ")", "{", "$", "items", "=", "$", "this", "->", "getArrayCopy", "(", ")", ";", "$", "callback", "?", "uasort", "(", "$", "items", ",", "$", "callback", ")", ":", "asort", "(", "$", "items", ")", ";", "return", "new", "static", "(", "$", "items", ")", ";", "}" ]
how to reset array keys here? as when jsonencoded the keys must be reset not sure you would always want to reset as may need to maintain sometimes?
[ "how", "to", "reset", "array", "keys", "here?", "as", "when", "jsonencoded", "the", "keys", "must", "be", "reset", "not", "sure", "you", "would", "always", "want", "to", "reset", "as", "may", "need", "to", "maintain", "sometimes?" ]
8ea9d67cc84fe6aff17a469c703d5492dbcd93ed
https://github.com/mwyatt/core/blob/8ea9d67cc84fe6aff17a469c703d5492dbcd93ed/src/Iterator/Collection.php#L136-L141
train
mwyatt/core
src/Iterator/Collection.php
Collection.offsetAppend
public function offsetAppend($index, $value) { $items = []; if ($this->offsetExists($index)) { $items = $this->offsetGet($index); if (!is_array($items)) { $itemsType = gettype($items); throw new \Exception("Offset '$index' is '$itemsType' and must be array to append."); } } $items[] = $value; $this->offsetSet($index, $items); }
php
public function offsetAppend($index, $value) { $items = []; if ($this->offsetExists($index)) { $items = $this->offsetGet($index); if (!is_array($items)) { $itemsType = gettype($items); throw new \Exception("Offset '$index' is '$itemsType' and must be array to append."); } } $items[] = $value; $this->offsetSet($index, $items); }
[ "public", "function", "offsetAppend", "(", "$", "index", ",", "$", "value", ")", "{", "$", "items", "=", "[", "]", ";", "if", "(", "$", "this", "->", "offsetExists", "(", "$", "index", ")", ")", "{", "$", "items", "=", "$", "this", "->", "offsetGet", "(", "$", "index", ")", ";", "if", "(", "!", "is_array", "(", "$", "items", ")", ")", "{", "$", "itemsType", "=", "gettype", "(", "$", "items", ")", ";", "throw", "new", "\\", "Exception", "(", "\"Offset '$index' is '$itemsType' and must be array to append.\"", ")", ";", "}", "}", "$", "items", "[", "]", "=", "$", "value", ";", "$", "this", "->", "offsetSet", "(", "$", "index", ",", "$", "items", ")", ";", "}" ]
adds a value to an offset array, if there is an array @param mixed $index @param mixed $value @return bool
[ "adds", "a", "value", "to", "an", "offset", "array", "if", "there", "is", "an", "array" ]
8ea9d67cc84fe6aff17a469c703d5492dbcd93ed
https://github.com/mwyatt/core/blob/8ea9d67cc84fe6aff17a469c703d5492dbcd93ed/src/Iterator/Collection.php#L184-L196
train
maddoger/yii2-cms-user
common/models/User.php
User.getRoleDescription
public function getRoleDescription() { static $list = null; if ($list === null) { $list = static::getRoles(); } return (isset($list[$this->role])) ? $list[$this->role] : $this->role; }
php
public function getRoleDescription() { static $list = null; if ($list === null) { $list = static::getRoles(); } return (isset($list[$this->role])) ? $list[$this->role] : $this->role; }
[ "public", "function", "getRoleDescription", "(", ")", "{", "static", "$", "list", "=", "null", ";", "if", "(", "$", "list", "===", "null", ")", "{", "$", "list", "=", "static", "::", "getRoles", "(", ")", ";", "}", "return", "(", "isset", "(", "$", "list", "[", "$", "this", "->", "role", "]", ")", ")", "?", "$", "list", "[", "$", "this", "->", "role", "]", ":", "$", "this", "->", "role", ";", "}" ]
Role sting representation @return string
[ "Role", "sting", "representation" ]
6792d1d0d2c0bf01fe87729985b5659de4c1aac1
https://github.com/maddoger/yii2-cms-user/blob/6792d1d0d2c0bf01fe87729985b5659de4c1aac1/common/models/User.php#L292-L299
train
maddoger/yii2-cms-user
common/models/User.php
User.getStatusDescription
public function getStatusDescription() { static $list = null; if ($list === null) { $list = static::getStatuses(); } return (isset($list[$this->status])) ? $list[$this->status] : $this->status; }
php
public function getStatusDescription() { static $list = null; if ($list === null) { $list = static::getStatuses(); } return (isset($list[$this->status])) ? $list[$this->status] : $this->status; }
[ "public", "function", "getStatusDescription", "(", ")", "{", "static", "$", "list", "=", "null", ";", "if", "(", "$", "list", "===", "null", ")", "{", "$", "list", "=", "static", "::", "getStatuses", "(", ")", ";", "}", "return", "(", "isset", "(", "$", "list", "[", "$", "this", "->", "status", "]", ")", ")", "?", "$", "list", "[", "$", "this", "->", "status", "]", ":", "$", "this", "->", "status", ";", "}" ]
Status sting representation @return string
[ "Status", "sting", "representation" ]
6792d1d0d2c0bf01fe87729985b5659de4c1aac1
https://github.com/maddoger/yii2-cms-user/blob/6792d1d0d2c0bf01fe87729985b5659de4c1aac1/common/models/User.php#L305-L312
train
maddoger/yii2-cms-user
common/models/User.php
User.findByEmail
public static function findByEmail($email, $checkStatus = true) { return static::findOne( $checkStatus ? ['email' => $email, 'status' => self::STATUS_ACTIVE] : ['email' => $email] ); }
php
public static function findByEmail($email, $checkStatus = true) { return static::findOne( $checkStatus ? ['email' => $email, 'status' => self::STATUS_ACTIVE] : ['email' => $email] ); }
[ "public", "static", "function", "findByEmail", "(", "$", "email", ",", "$", "checkStatus", "=", "true", ")", "{", "return", "static", "::", "findOne", "(", "$", "checkStatus", "?", "[", "'email'", "=>", "$", "email", ",", "'status'", "=>", "self", "::", "STATUS_ACTIVE", "]", ":", "[", "'email'", "=>", "$", "email", "]", ")", ";", "}" ]
Finds user by email @param string $email @param bool $checkStatus @return null|static
[ "Finds", "user", "by", "email" ]
6792d1d0d2c0bf01fe87729985b5659de4c1aac1
https://github.com/maddoger/yii2-cms-user/blob/6792d1d0d2c0bf01fe87729985b5659de4c1aac1/common/models/User.php#L358-L365
train
maddoger/yii2-cms-user
common/models/User.php
User.findByUsernameOrEmail
public static function findByUsernameOrEmail($username, $checkStatus = true) { $query = static::find(); $query->where(['or', ['username' => $username], ['email' => $username]]); if ($checkStatus) { $query->andWhere(['status' => self::STATUS_ACTIVE]); } return $query->limit(1)->one(); }
php
public static function findByUsernameOrEmail($username, $checkStatus = true) { $query = static::find(); $query->where(['or', ['username' => $username], ['email' => $username]]); if ($checkStatus) { $query->andWhere(['status' => self::STATUS_ACTIVE]); } return $query->limit(1)->one(); }
[ "public", "static", "function", "findByUsernameOrEmail", "(", "$", "username", ",", "$", "checkStatus", "=", "true", ")", "{", "$", "query", "=", "static", "::", "find", "(", ")", ";", "$", "query", "->", "where", "(", "[", "'or'", ",", "[", "'username'", "=>", "$", "username", "]", ",", "[", "'email'", "=>", "$", "username", "]", "]", ")", ";", "if", "(", "$", "checkStatus", ")", "{", "$", "query", "->", "andWhere", "(", "[", "'status'", "=>", "self", "::", "STATUS_ACTIVE", "]", ")", ";", "}", "return", "$", "query", "->", "limit", "(", "1", ")", "->", "one", "(", ")", ";", "}" ]
Finds user by username or email @param string $username @param bool $checkStatus @return null|static
[ "Finds", "user", "by", "username", "or", "email" ]
6792d1d0d2c0bf01fe87729985b5659de4c1aac1
https://github.com/maddoger/yii2-cms-user/blob/6792d1d0d2c0bf01fe87729985b5659de4c1aac1/common/models/User.php#L374-L382
train
maddoger/yii2-cms-user
common/models/User.php
User.updateLastVisit
public static function updateLastVisit($event) { if ($event->isValid) { /** * @var User $user */ $user = $event->identity; $user->last_visit_at = time(); $user->updateAttributes(['last_visit_at']); return true; } return false; }
php
public static function updateLastVisit($event) { if ($event->isValid) { /** * @var User $user */ $user = $event->identity; $user->last_visit_at = time(); $user->updateAttributes(['last_visit_at']); return true; } return false; }
[ "public", "static", "function", "updateLastVisit", "(", "$", "event", ")", "{", "if", "(", "$", "event", "->", "isValid", ")", "{", "/**\n * @var User $user\n */", "$", "user", "=", "$", "event", "->", "identity", ";", "$", "user", "->", "last_visit_at", "=", "time", "(", ")", ";", "$", "user", "->", "updateAttributes", "(", "[", "'last_visit_at'", "]", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Update last visit time event handler in user component: 'on afterLogin' => ['maddoger\user\common\models\User', 'updateLastVisit'], 'on afterLogout' => ['maddoger\user\common\models\User', 'updateLastVisit'], @param $event @return bool
[ "Update", "last", "visit", "time", "event", "handler" ]
6792d1d0d2c0bf01fe87729985b5659de4c1aac1
https://github.com/maddoger/yii2-cms-user/blob/6792d1d0d2c0bf01fe87729985b5659de4c1aac1/common/models/User.php#L472-L484
train