id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
---|---|---|---|---|---|---|---|---|---|---|---|
14,300 | markwatkinson/luminous | src/Luminous/Utils/ColorUtils.php | ColorUtils.nearestColor | public static function nearestColor($refLabs, $lab, $algorithm, $returnArrayKey = false, $cacheKey = "")
{
// Calculating a unique cache key takes even longer than calculating the distance, so the caller needs to craft
// a cache key by hand
$subKey = $lab[0] . $lab[1] . $lab[2];
$result = array();
if (empty($cacheKey) || !isset(static::$nearestColors[$cacheKey]) ||
!isset(static::$nearestColors[$cacheKey][$subKey])) {
// Nearest color not yet in cache, needs to be calculated
$nearestColor = [0, 10000];
foreach ($refLabs as $key => $refLab) {
$distance = static::{$algorithm}($refLab, $lab);
if ($distance < $nearestColor[1]) {
// New low
$nearestColor = [$key, $distance];
}
}
$result = array($nearestColor[0], $refLabs[$nearestColor[0]]);
if (!empty($cacheKey)) {
// Put the result into the cache
if (!isset(static::$nearestColors[$cacheKey])) {
static::$nearestColors[$cacheKey] = array();
}
static::$nearestColors[$cacheKey][$subKey] = $result;
}
}
if (empty($result)) {
// Fetch nearest color from cache
$result = static::$nearestColors[$cacheKey][$subKey];
}
if ($returnArrayKey) {
return $result[0];
}
return $result[1];
} | php | public static function nearestColor($refLabs, $lab, $algorithm, $returnArrayKey = false, $cacheKey = "")
{
// Calculating a unique cache key takes even longer than calculating the distance, so the caller needs to craft
// a cache key by hand
$subKey = $lab[0] . $lab[1] . $lab[2];
$result = array();
if (empty($cacheKey) || !isset(static::$nearestColors[$cacheKey]) ||
!isset(static::$nearestColors[$cacheKey][$subKey])) {
// Nearest color not yet in cache, needs to be calculated
$nearestColor = [0, 10000];
foreach ($refLabs as $key => $refLab) {
$distance = static::{$algorithm}($refLab, $lab);
if ($distance < $nearestColor[1]) {
// New low
$nearestColor = [$key, $distance];
}
}
$result = array($nearestColor[0], $refLabs[$nearestColor[0]]);
if (!empty($cacheKey)) {
// Put the result into the cache
if (!isset(static::$nearestColors[$cacheKey])) {
static::$nearestColors[$cacheKey] = array();
}
static::$nearestColors[$cacheKey][$subKey] = $result;
}
}
if (empty($result)) {
// Fetch nearest color from cache
$result = static::$nearestColors[$cacheKey][$subKey];
}
if ($returnArrayKey) {
return $result[0];
}
return $result[1];
} | [
"public",
"static",
"function",
"nearestColor",
"(",
"$",
"refLabs",
",",
"$",
"lab",
",",
"$",
"algorithm",
",",
"$",
"returnArrayKey",
"=",
"false",
",",
"$",
"cacheKey",
"=",
"\"\"",
")",
"{",
"// Calculating a unique cache key takes even longer than calculating the distance, so the caller needs to craft",
"// a cache key by hand",
"$",
"subKey",
"=",
"$",
"lab",
"[",
"0",
"]",
".",
"$",
"lab",
"[",
"1",
"]",
".",
"$",
"lab",
"[",
"2",
"]",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"cacheKey",
")",
"||",
"!",
"isset",
"(",
"static",
"::",
"$",
"nearestColors",
"[",
"$",
"cacheKey",
"]",
")",
"||",
"!",
"isset",
"(",
"static",
"::",
"$",
"nearestColors",
"[",
"$",
"cacheKey",
"]",
"[",
"$",
"subKey",
"]",
")",
")",
"{",
"// Nearest color not yet in cache, needs to be calculated",
"$",
"nearestColor",
"=",
"[",
"0",
",",
"10000",
"]",
";",
"foreach",
"(",
"$",
"refLabs",
"as",
"$",
"key",
"=>",
"$",
"refLab",
")",
"{",
"$",
"distance",
"=",
"static",
"::",
"{",
"$",
"algorithm",
"}",
"(",
"$",
"refLab",
",",
"$",
"lab",
")",
";",
"if",
"(",
"$",
"distance",
"<",
"$",
"nearestColor",
"[",
"1",
"]",
")",
"{",
"// New low",
"$",
"nearestColor",
"=",
"[",
"$",
"key",
",",
"$",
"distance",
"]",
";",
"}",
"}",
"$",
"result",
"=",
"array",
"(",
"$",
"nearestColor",
"[",
"0",
"]",
",",
"$",
"refLabs",
"[",
"$",
"nearestColor",
"[",
"0",
"]",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"cacheKey",
")",
")",
"{",
"// Put the result into the cache",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"nearestColors",
"[",
"$",
"cacheKey",
"]",
")",
")",
"{",
"static",
"::",
"$",
"nearestColors",
"[",
"$",
"cacheKey",
"]",
"=",
"array",
"(",
")",
";",
"}",
"static",
"::",
"$",
"nearestColors",
"[",
"$",
"cacheKey",
"]",
"[",
"$",
"subKey",
"]",
"=",
"$",
"result",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"// Fetch nearest color from cache",
"$",
"result",
"=",
"static",
"::",
"$",
"nearestColors",
"[",
"$",
"cacheKey",
"]",
"[",
"$",
"subKey",
"]",
";",
"}",
"if",
"(",
"$",
"returnArrayKey",
")",
"{",
"return",
"$",
"result",
"[",
"0",
"]",
";",
"}",
"return",
"$",
"result",
"[",
"1",
"]",
";",
"}"
]
| Searches a list of colors for the one with the shortest distance to a given color | [
"Searches",
"a",
"list",
"of",
"colors",
"for",
"the",
"one",
"with",
"the",
"shortest",
"distance",
"to",
"a",
"given",
"color"
]
| 4adc18f414534abe986133d6d38e8e9787d32e69 | https://github.com/markwatkinson/luminous/blob/4adc18f414534abe986133d6d38e8e9787d32e69/src/Luminous/Utils/ColorUtils.php#L170-L204 |
14,301 | wpup/digster | src/cache/class-wordpress-cache-adapter.php | WordPress_Cache_Adapter.fetch | public function fetch( $key ) {
$key = $this->get_key( $key );
return wp_cache_get( $key, $this->group );
} | php | public function fetch( $key ) {
$key = $this->get_key( $key );
return wp_cache_get( $key, $this->group );
} | [
"public",
"function",
"fetch",
"(",
"$",
"key",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"get_key",
"(",
"$",
"key",
")",
";",
"return",
"wp_cache_get",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"group",
")",
";",
"}"
]
| Fetch cache data.
@param string $key
@return mixed | [
"Fetch",
"cache",
"data",
"."
]
| 9ef9626ce82673af698bc0976d6c38a532e4a6d9 | https://github.com/wpup/digster/blob/9ef9626ce82673af698bc0976d6c38a532e4a6d9/src/cache/class-wordpress-cache-adapter.php#L45-L48 |
14,302 | wpup/digster | src/cache/class-wordpress-cache-adapter.php | WordPress_Cache_Adapter.save | public function save( $key, $value, $expire = 0 ) {
$key = $this->get_key( $key );
wp_cache_set( $key, $value, $this->group, $expire );
} | php | public function save( $key, $value, $expire = 0 ) {
$key = $this->get_key( $key );
wp_cache_set( $key, $value, $this->group, $expire );
} | [
"public",
"function",
"save",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"expire",
"=",
"0",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"get_key",
"(",
"$",
"key",
")",
";",
"wp_cache_set",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"this",
"->",
"group",
",",
"$",
"expire",
")",
";",
"}"
]
| Save cache data.
@param string $key
@param mixed $value
@param int $expire | [
"Save",
"cache",
"data",
"."
]
| 9ef9626ce82673af698bc0976d6c38a532e4a6d9 | https://github.com/wpup/digster/blob/9ef9626ce82673af698bc0976d6c38a532e4a6d9/src/cache/class-wordpress-cache-adapter.php#L68-L71 |
14,303 | markwatkinson/luminous | src/Luminous/Luminous.php | Luminous.getFormatter | public function getFormatter()
{
$fmt = $this->settings->format;
$formatter = null;
if (!is_string($fmt) && is_subclass_of($fmt, 'Luminous\\Formatters\\Formatter')) {
$formatter = clone $fmt;
} elseif ($fmt === 'html') {
$formatter = new HtmlFormatter();
} elseif ($fmt === 'html-inline') {
$formatter = new InlineHtmlFormatter();
} elseif ($fmt === 'html-full') {
$formatter = new FullPageHtmlFormatter();
} elseif ($fmt === 'latex') {
$formatter = new LatexFormatter();
} elseif ($fmt === 'ansi') {
$formatter = new AnsiFormatter();
} elseif ($fmt === null || $fmt === 'none') {
$formatter = new IdentityFormatter();
}
if ($formatter === null) {
throw new Exception('Unknown formatter: ' . $this->settings->format);
return null;
}
$this->setFormatterOptions($formatter);
return $formatter;
} | php | public function getFormatter()
{
$fmt = $this->settings->format;
$formatter = null;
if (!is_string($fmt) && is_subclass_of($fmt, 'Luminous\\Formatters\\Formatter')) {
$formatter = clone $fmt;
} elseif ($fmt === 'html') {
$formatter = new HtmlFormatter();
} elseif ($fmt === 'html-inline') {
$formatter = new InlineHtmlFormatter();
} elseif ($fmt === 'html-full') {
$formatter = new FullPageHtmlFormatter();
} elseif ($fmt === 'latex') {
$formatter = new LatexFormatter();
} elseif ($fmt === 'ansi') {
$formatter = new AnsiFormatter();
} elseif ($fmt === null || $fmt === 'none') {
$formatter = new IdentityFormatter();
}
if ($formatter === null) {
throw new Exception('Unknown formatter: ' . $this->settings->format);
return null;
}
$this->setFormatterOptions($formatter);
return $formatter;
} | [
"public",
"function",
"getFormatter",
"(",
")",
"{",
"$",
"fmt",
"=",
"$",
"this",
"->",
"settings",
"->",
"format",
";",
"$",
"formatter",
"=",
"null",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"fmt",
")",
"&&",
"is_subclass_of",
"(",
"$",
"fmt",
",",
"'Luminous\\\\Formatters\\\\Formatter'",
")",
")",
"{",
"$",
"formatter",
"=",
"clone",
"$",
"fmt",
";",
"}",
"elseif",
"(",
"$",
"fmt",
"===",
"'html'",
")",
"{",
"$",
"formatter",
"=",
"new",
"HtmlFormatter",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"fmt",
"===",
"'html-inline'",
")",
"{",
"$",
"formatter",
"=",
"new",
"InlineHtmlFormatter",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"fmt",
"===",
"'html-full'",
")",
"{",
"$",
"formatter",
"=",
"new",
"FullPageHtmlFormatter",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"fmt",
"===",
"'latex'",
")",
"{",
"$",
"formatter",
"=",
"new",
"LatexFormatter",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"fmt",
"===",
"'ansi'",
")",
"{",
"$",
"formatter",
"=",
"new",
"AnsiFormatter",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"fmt",
"===",
"null",
"||",
"$",
"fmt",
"===",
"'none'",
")",
"{",
"$",
"formatter",
"=",
"new",
"IdentityFormatter",
"(",
")",
";",
"}",
"if",
"(",
"$",
"formatter",
"===",
"null",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Unknown formatter: '",
".",
"$",
"this",
"->",
"settings",
"->",
"format",
")",
";",
"return",
"null",
";",
"}",
"$",
"this",
"->",
"setFormatterOptions",
"(",
"$",
"formatter",
")",
";",
"return",
"$",
"formatter",
";",
"}"
]
| Returns an instance of the current formatter | [
"Returns",
"an",
"instance",
"of",
"the",
"current",
"formatter"
]
| 4adc18f414534abe986133d6d38e8e9787d32e69 | https://github.com/markwatkinson/luminous/blob/4adc18f414534abe986133d6d38e8e9787d32e69/src/Luminous/Luminous.php#L120-L146 |
14,304 | markwatkinson/luminous | src/Luminous/Luminous.php | Luminous.highlight | public function highlight($scanner, $source, $settings = null)
{
$oldSettings = null;
if ($settings !== null) {
if (!is_array($settings)) {
throw new Exception('Luminous internal error: Settings is not an array');
}
$oldSettings = clone $this->settings;
foreach ($settings as $k => $v) {
$this->settings->set($k, $v);
}
}
$shouldResetLanguage = false;
$this->cache = null;
if (!is_string($source)) {
throw new InvalidArgumentException('Non-string supplied for $source');
}
if (!($scanner instanceof Scanner)) {
if (!is_string($scanner)) {
throw new InvalidArgumentException('Non-string or LuminousScanner instance supplied for $scanner');
}
$code = $scanner;
$scanner = $this->scanners->GetScanner($code);
if ($scanner === null) {
throw new Exception("No known scanner for '$code' and no default set");
}
$shouldResetLanguage = true;
$this->language = $this->scanners->GetDescription($code);
}
$cacheHit = true;
$out = null;
if ($this->settings->cache) {
$cacheId = $this->cacheId($scanner, $source);
if ($this->settings->sqlFunction !== null) {
$this->cache = new SqlCache($cacheId);
$this->cache->setSqlFunction($this->settings->sqlFunction);
} else {
$this->cache = new FileSystemCache($cacheId);
}
$this->cache->setPurgeTime($this->settings->cacheAge);
$out = $this->cache->read();
}
if ($out === null) {
$cacheHit = false;
$outRaw = $scanner->highlight($source);
$formatter = $this->getFormatter();
$out = $formatter->format($outRaw);
}
if ($this->settings->cache && !$cacheHit) {
$this->cache->write($out);
}
if ($shouldResetLanguage) {
$this->language = null;
}
if ($oldSettings !== null) {
$this->settings = $oldSettings;
}
return $out;
} | php | public function highlight($scanner, $source, $settings = null)
{
$oldSettings = null;
if ($settings !== null) {
if (!is_array($settings)) {
throw new Exception('Luminous internal error: Settings is not an array');
}
$oldSettings = clone $this->settings;
foreach ($settings as $k => $v) {
$this->settings->set($k, $v);
}
}
$shouldResetLanguage = false;
$this->cache = null;
if (!is_string($source)) {
throw new InvalidArgumentException('Non-string supplied for $source');
}
if (!($scanner instanceof Scanner)) {
if (!is_string($scanner)) {
throw new InvalidArgumentException('Non-string or LuminousScanner instance supplied for $scanner');
}
$code = $scanner;
$scanner = $this->scanners->GetScanner($code);
if ($scanner === null) {
throw new Exception("No known scanner for '$code' and no default set");
}
$shouldResetLanguage = true;
$this->language = $this->scanners->GetDescription($code);
}
$cacheHit = true;
$out = null;
if ($this->settings->cache) {
$cacheId = $this->cacheId($scanner, $source);
if ($this->settings->sqlFunction !== null) {
$this->cache = new SqlCache($cacheId);
$this->cache->setSqlFunction($this->settings->sqlFunction);
} else {
$this->cache = new FileSystemCache($cacheId);
}
$this->cache->setPurgeTime($this->settings->cacheAge);
$out = $this->cache->read();
}
if ($out === null) {
$cacheHit = false;
$outRaw = $scanner->highlight($source);
$formatter = $this->getFormatter();
$out = $formatter->format($outRaw);
}
if ($this->settings->cache && !$cacheHit) {
$this->cache->write($out);
}
if ($shouldResetLanguage) {
$this->language = null;
}
if ($oldSettings !== null) {
$this->settings = $oldSettings;
}
return $out;
} | [
"public",
"function",
"highlight",
"(",
"$",
"scanner",
",",
"$",
"source",
",",
"$",
"settings",
"=",
"null",
")",
"{",
"$",
"oldSettings",
"=",
"null",
";",
"if",
"(",
"$",
"settings",
"!==",
"null",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"settings",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Luminous internal error: Settings is not an array'",
")",
";",
"}",
"$",
"oldSettings",
"=",
"clone",
"$",
"this",
"->",
"settings",
";",
"foreach",
"(",
"$",
"settings",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"this",
"->",
"settings",
"->",
"set",
"(",
"$",
"k",
",",
"$",
"v",
")",
";",
"}",
"}",
"$",
"shouldResetLanguage",
"=",
"false",
";",
"$",
"this",
"->",
"cache",
"=",
"null",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"source",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Non-string supplied for $source'",
")",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"scanner",
"instanceof",
"Scanner",
")",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"scanner",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Non-string or LuminousScanner instance supplied for $scanner'",
")",
";",
"}",
"$",
"code",
"=",
"$",
"scanner",
";",
"$",
"scanner",
"=",
"$",
"this",
"->",
"scanners",
"->",
"GetScanner",
"(",
"$",
"code",
")",
";",
"if",
"(",
"$",
"scanner",
"===",
"null",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"No known scanner for '$code' and no default set\"",
")",
";",
"}",
"$",
"shouldResetLanguage",
"=",
"true",
";",
"$",
"this",
"->",
"language",
"=",
"$",
"this",
"->",
"scanners",
"->",
"GetDescription",
"(",
"$",
"code",
")",
";",
"}",
"$",
"cacheHit",
"=",
"true",
";",
"$",
"out",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"settings",
"->",
"cache",
")",
"{",
"$",
"cacheId",
"=",
"$",
"this",
"->",
"cacheId",
"(",
"$",
"scanner",
",",
"$",
"source",
")",
";",
"if",
"(",
"$",
"this",
"->",
"settings",
"->",
"sqlFunction",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"cache",
"=",
"new",
"SqlCache",
"(",
"$",
"cacheId",
")",
";",
"$",
"this",
"->",
"cache",
"->",
"setSqlFunction",
"(",
"$",
"this",
"->",
"settings",
"->",
"sqlFunction",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"cache",
"=",
"new",
"FileSystemCache",
"(",
"$",
"cacheId",
")",
";",
"}",
"$",
"this",
"->",
"cache",
"->",
"setPurgeTime",
"(",
"$",
"this",
"->",
"settings",
"->",
"cacheAge",
")",
";",
"$",
"out",
"=",
"$",
"this",
"->",
"cache",
"->",
"read",
"(",
")",
";",
"}",
"if",
"(",
"$",
"out",
"===",
"null",
")",
"{",
"$",
"cacheHit",
"=",
"false",
";",
"$",
"outRaw",
"=",
"$",
"scanner",
"->",
"highlight",
"(",
"$",
"source",
")",
";",
"$",
"formatter",
"=",
"$",
"this",
"->",
"getFormatter",
"(",
")",
";",
"$",
"out",
"=",
"$",
"formatter",
"->",
"format",
"(",
"$",
"outRaw",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"settings",
"->",
"cache",
"&&",
"!",
"$",
"cacheHit",
")",
"{",
"$",
"this",
"->",
"cache",
"->",
"write",
"(",
"$",
"out",
")",
";",
"}",
"if",
"(",
"$",
"shouldResetLanguage",
")",
"{",
"$",
"this",
"->",
"language",
"=",
"null",
";",
"}",
"if",
"(",
"$",
"oldSettings",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"settings",
"=",
"$",
"oldSettings",
";",
"}",
"return",
"$",
"out",
";",
"}"
]
| The real highlighting function
@throw InvalidArgumentException if $scanner is not either a string or a
LuminousScanner instance, or if $source is not a string. | [
"The",
"real",
"highlighting",
"function"
]
| 4adc18f414534abe986133d6d38e8e9787d32e69 | https://github.com/markwatkinson/luminous/blob/4adc18f414534abe986133d6d38e8e9787d32e69/src/Luminous/Luminous.php#L200-L260 |
14,305 | mimmi20/Wurfl | src/Configuration/InMemoryConfig.php | InMemoryConfig.persistence | public function persistence($provider, array $params = array())
{
$this->persistence = array_merge(array(Config::PROVIDER => $provider), array(Config::PARAMS => $params));
return $this;
} | php | public function persistence($provider, array $params = array())
{
$this->persistence = array_merge(array(Config::PROVIDER => $provider), array(Config::PARAMS => $params));
return $this;
} | [
"public",
"function",
"persistence",
"(",
"$",
"provider",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"persistence",
"=",
"array_merge",
"(",
"array",
"(",
"Config",
"::",
"PROVIDER",
"=>",
"$",
"provider",
")",
",",
"array",
"(",
"Config",
"::",
"PARAMS",
"=>",
"$",
"params",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Set persistence provider
@param string $provider
@param array $params
@return \Wurfl\Configuration\InMemoryConfig $this | [
"Set",
"persistence",
"provider"
]
| 443ed0d73a0b9a21ebd0d6ddf1e32669b9de44ec | https://github.com/mimmi20/Wurfl/blob/443ed0d73a0b9a21ebd0d6ddf1e32669b9de44ec/src/Configuration/InMemoryConfig.php#L79-L84 |
14,306 | mimmi20/Wurfl | src/Configuration/InMemoryConfig.php | InMemoryConfig.cache | public function cache($provider, array $params = array())
{
$this->cache = array_merge(array(config::PROVIDER => $provider), array(Config::PARAMS => $params));
return $this;
} | php | public function cache($provider, array $params = array())
{
$this->cache = array_merge(array(config::PROVIDER => $provider), array(Config::PARAMS => $params));
return $this;
} | [
"public",
"function",
"cache",
"(",
"$",
"provider",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"cache",
"=",
"array_merge",
"(",
"array",
"(",
"config",
"::",
"PROVIDER",
"=>",
"$",
"provider",
")",
",",
"array",
"(",
"Config",
"::",
"PARAMS",
"=>",
"$",
"params",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Set Cache provider
@param string $provider
@param array $params
@return \Wurfl\Configuration\InMemoryConfig $this | [
"Set",
"Cache",
"provider"
]
| 443ed0d73a0b9a21ebd0d6ddf1e32669b9de44ec | https://github.com/mimmi20/Wurfl/blob/443ed0d73a0b9a21ebd0d6ddf1e32669b9de44ec/src/Configuration/InMemoryConfig.php#L94-L99 |
14,307 | mimmi20/Wurfl | src/Configuration/InMemoryConfig.php | InMemoryConfig.logDir | public function logDir($dir)
{
$this->logDir = $dir;
$this->buildFileLogger($this->logDir);
return $this;
} | php | public function logDir($dir)
{
$this->logDir = $dir;
$this->buildFileLogger($this->logDir);
return $this;
} | [
"public",
"function",
"logDir",
"(",
"$",
"dir",
")",
"{",
"$",
"this",
"->",
"logDir",
"=",
"$",
"dir",
";",
"$",
"this",
"->",
"buildFileLogger",
"(",
"$",
"this",
"->",
"logDir",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Set logging directory
@param string $dir
@return \Wurfl\Configuration\InMemoryConfig $this | [
"Set",
"logging",
"directory"
]
| 443ed0d73a0b9a21ebd0d6ddf1e32669b9de44ec | https://github.com/mimmi20/Wurfl/blob/443ed0d73a0b9a21ebd0d6ddf1e32669b9de44ec/src/Configuration/InMemoryConfig.php#L108-L115 |
14,308 | LordDashMe/php-static-class-interface | src/Facade.php | Facade.getResolvedClassInstance | protected static function getResolvedClassInstance()
{
$classNamespace = static::getStaticClassAccessor();
$resolvedClassInstance = self::getClass($classNamespace);
if (! $resolvedClassInstance) {
return self::resolveClassNameSpace($classNamespace);
}
return $resolvedClassInstance;
} | php | protected static function getResolvedClassInstance()
{
$classNamespace = static::getStaticClassAccessor();
$resolvedClassInstance = self::getClass($classNamespace);
if (! $resolvedClassInstance) {
return self::resolveClassNameSpace($classNamespace);
}
return $resolvedClassInstance;
} | [
"protected",
"static",
"function",
"getResolvedClassInstance",
"(",
")",
"{",
"$",
"classNamespace",
"=",
"static",
"::",
"getStaticClassAccessor",
"(",
")",
";",
"$",
"resolvedClassInstance",
"=",
"self",
"::",
"getClass",
"(",
"$",
"classNamespace",
")",
";",
"if",
"(",
"!",
"$",
"resolvedClassInstance",
")",
"{",
"return",
"self",
"::",
"resolveClassNameSpace",
"(",
"$",
"classNamespace",
")",
";",
"}",
"return",
"$",
"resolvedClassInstance",
";",
"}"
]
| Check if the class namespace already have a cached resolved instance,
if not then the class namespace must be resolve.
@return mixed | [
"Check",
"if",
"the",
"class",
"namespace",
"already",
"have",
"a",
"cached",
"resolved",
"instance",
"if",
"not",
"then",
"the",
"class",
"namespace",
"must",
"be",
"resolve",
"."
]
| 7c0855e47158c81e041723bede48a7b35652edb3 | https://github.com/LordDashMe/php-static-class-interface/blob/7c0855e47158c81e041723bede48a7b35652edb3/src/Facade.php#L83-L93 |
14,309 | LordDashMe/php-static-class-interface | src/Facade.php | Facade.resolveClassNameSpace | protected static function resolveClassNameSpace($classNamespace)
{
if (! \is_string($classNamespace)) {
throw ClassNamespaceResolverException::isNotString();
}
if (! \class_exists($classNamespace)) {
throw ClassNamespaceResolverException::isNotExist();
}
$classNamespace = self::classNamespaceDecorator($classNamespace);
$classInstance = new $classNamespace();
self::setClass($classNamespace, $classInstance);
return $classInstance;
} | php | protected static function resolveClassNameSpace($classNamespace)
{
if (! \is_string($classNamespace)) {
throw ClassNamespaceResolverException::isNotString();
}
if (! \class_exists($classNamespace)) {
throw ClassNamespaceResolverException::isNotExist();
}
$classNamespace = self::classNamespaceDecorator($classNamespace);
$classInstance = new $classNamespace();
self::setClass($classNamespace, $classInstance);
return $classInstance;
} | [
"protected",
"static",
"function",
"resolveClassNameSpace",
"(",
"$",
"classNamespace",
")",
"{",
"if",
"(",
"!",
"\\",
"is_string",
"(",
"$",
"classNamespace",
")",
")",
"{",
"throw",
"ClassNamespaceResolverException",
"::",
"isNotString",
"(",
")",
";",
"}",
"if",
"(",
"!",
"\\",
"class_exists",
"(",
"$",
"classNamespace",
")",
")",
"{",
"throw",
"ClassNamespaceResolverException",
"::",
"isNotExist",
"(",
")",
";",
"}",
"$",
"classNamespace",
"=",
"self",
"::",
"classNamespaceDecorator",
"(",
"$",
"classNamespace",
")",
";",
"$",
"classInstance",
"=",
"new",
"$",
"classNamespace",
"(",
")",
";",
"self",
"::",
"setClass",
"(",
"$",
"classNamespace",
",",
"$",
"classInstance",
")",
";",
"return",
"$",
"classInstance",
";",
"}"
]
| Resolver for service class namespace.
Set the resolved service class instance to the class property.
@param string $classNamespace
@return mixed | [
"Resolver",
"for",
"service",
"class",
"namespace",
".",
"Set",
"the",
"resolved",
"service",
"class",
"instance",
"to",
"the",
"class",
"property",
"."
]
| 7c0855e47158c81e041723bede48a7b35652edb3 | https://github.com/LordDashMe/php-static-class-interface/blob/7c0855e47158c81e041723bede48a7b35652edb3/src/Facade.php#L103-L120 |
14,310 | unimapper/unimapper | src/Entity/Reflection/Property.php | Property._initType | private function _initType($definition)
{
if (isset(self::$typeAliases[$definition])) {
$definition = self::$typeAliases[$definition];
}
if (self::isScalarType($definition)
|| in_array(
$definition,
[self::TYPE_ARRAY, self::TYPE_DATE, self::TYPE_DATETIME],
true
)
) {
// Scalar, array, date, datetime
$this->type = $definition;
} elseif (class_exists(Convention::nameToClass($definition, Convention::ENTITY_MASK))) {
// Entity
$this->type = self::TYPE_ENTITY;
$this->typeOption = $definition;
} elseif (substr($definition, -2) === "[]") {
// Collection
$this->type = self::TYPE_COLLECTION;
$this->typeOption = rtrim($definition, "[]");
} else {
throw new Exception\PropertyException(
"Unsupported type '" . $definition . "'!"
);
}
} | php | private function _initType($definition)
{
if (isset(self::$typeAliases[$definition])) {
$definition = self::$typeAliases[$definition];
}
if (self::isScalarType($definition)
|| in_array(
$definition,
[self::TYPE_ARRAY, self::TYPE_DATE, self::TYPE_DATETIME],
true
)
) {
// Scalar, array, date, datetime
$this->type = $definition;
} elseif (class_exists(Convention::nameToClass($definition, Convention::ENTITY_MASK))) {
// Entity
$this->type = self::TYPE_ENTITY;
$this->typeOption = $definition;
} elseif (substr($definition, -2) === "[]") {
// Collection
$this->type = self::TYPE_COLLECTION;
$this->typeOption = rtrim($definition, "[]");
} else {
throw new Exception\PropertyException(
"Unsupported type '" . $definition . "'!"
);
}
} | [
"private",
"function",
"_initType",
"(",
"$",
"definition",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"typeAliases",
"[",
"$",
"definition",
"]",
")",
")",
"{",
"$",
"definition",
"=",
"self",
"::",
"$",
"typeAliases",
"[",
"$",
"definition",
"]",
";",
"}",
"if",
"(",
"self",
"::",
"isScalarType",
"(",
"$",
"definition",
")",
"||",
"in_array",
"(",
"$",
"definition",
",",
"[",
"self",
"::",
"TYPE_ARRAY",
",",
"self",
"::",
"TYPE_DATE",
",",
"self",
"::",
"TYPE_DATETIME",
"]",
",",
"true",
")",
")",
"{",
"// Scalar, array, date, datetime",
"$",
"this",
"->",
"type",
"=",
"$",
"definition",
";",
"}",
"elseif",
"(",
"class_exists",
"(",
"Convention",
"::",
"nameToClass",
"(",
"$",
"definition",
",",
"Convention",
"::",
"ENTITY_MASK",
")",
")",
")",
"{",
"// Entity",
"$",
"this",
"->",
"type",
"=",
"self",
"::",
"TYPE_ENTITY",
";",
"$",
"this",
"->",
"typeOption",
"=",
"$",
"definition",
";",
"}",
"elseif",
"(",
"substr",
"(",
"$",
"definition",
",",
"-",
"2",
")",
"===",
"\"[]\"",
")",
"{",
"// Collection",
"$",
"this",
"->",
"type",
"=",
"self",
"::",
"TYPE_COLLECTION",
";",
"$",
"this",
"->",
"typeOption",
"=",
"rtrim",
"(",
"$",
"definition",
",",
"\"[]\"",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"\\",
"PropertyException",
"(",
"\"Unsupported type '\"",
".",
"$",
"definition",
".",
"\"'!\"",
")",
";",
"}",
"}"
]
| Initialize property type
@param string $definition
@return mixed
@throws Exception\PropertyException | [
"Initialize",
"property",
"type"
]
| a63b39f38a790fec7e852c8ef1e4c31653e689f7 | https://github.com/unimapper/unimapper/blob/a63b39f38a790fec7e852c8ef1e4c31653e689f7/src/Entity/Reflection/Property.php#L209-L240 |
14,311 | unimapper/unimapper | src/Entity/Reflection/Property.php | Property.convertValue | public function convertValue($value)
{
if ($value === null || ($value === "" && $this->type !== self::TYPE_STRING)) {
return;
}
if (self::isScalarType($this->type) || $this->type === self::TYPE_ARRAY) {
// Scalar and array
if ($this->type === self::TYPE_BOOLEAN && strtolower($value) === "false") {
return false;
}
if (is_scalar($value) || $this->type === self::TYPE_ARRAY) {
if (settype($value, $this->type)) {
return $value;
}
}
} elseif ($this->type === self::TYPE_DATETIME
|| $this->type === self::TYPE_DATE
) {
// DateTime
if ($value instanceof \DateTime) {
return $value;
} elseif (is_array($value) && isset($value["date"])) {
$date = $value["date"];
} elseif (is_object($value) && isset($value->date)) {
$date = $value->date;
} else {
$date = $value;
}
if (isset($date)) {
try {
return new \DateTime($date);
} catch (\Exception $e) {
}
}
} elseif ($this->type === self::TYPE_COLLECTION
&& Validator::isTraversable($value)
) {
// Collection
return new Entity\Collection($this->typeOption, $value);
} elseif ($this->type === self::TYPE_ENTITY
&& Validator::isTraversable($value)
) {
// Entity
return Entity\Reflection::load($this->typeOption)->createEntity($value);
}
throw new Exception\InvalidArgumentException(
"Can not convert value on property '" . $this->name
. "' automatically!",
$value
);
} | php | public function convertValue($value)
{
if ($value === null || ($value === "" && $this->type !== self::TYPE_STRING)) {
return;
}
if (self::isScalarType($this->type) || $this->type === self::TYPE_ARRAY) {
// Scalar and array
if ($this->type === self::TYPE_BOOLEAN && strtolower($value) === "false") {
return false;
}
if (is_scalar($value) || $this->type === self::TYPE_ARRAY) {
if (settype($value, $this->type)) {
return $value;
}
}
} elseif ($this->type === self::TYPE_DATETIME
|| $this->type === self::TYPE_DATE
) {
// DateTime
if ($value instanceof \DateTime) {
return $value;
} elseif (is_array($value) && isset($value["date"])) {
$date = $value["date"];
} elseif (is_object($value) && isset($value->date)) {
$date = $value->date;
} else {
$date = $value;
}
if (isset($date)) {
try {
return new \DateTime($date);
} catch (\Exception $e) {
}
}
} elseif ($this->type === self::TYPE_COLLECTION
&& Validator::isTraversable($value)
) {
// Collection
return new Entity\Collection($this->typeOption, $value);
} elseif ($this->type === self::TYPE_ENTITY
&& Validator::isTraversable($value)
) {
// Entity
return Entity\Reflection::load($this->typeOption)->createEntity($value);
}
throw new Exception\InvalidArgumentException(
"Can not convert value on property '" . $this->name
. "' automatically!",
$value
);
} | [
"public",
"function",
"convertValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
"||",
"(",
"$",
"value",
"===",
"\"\"",
"&&",
"$",
"this",
"->",
"type",
"!==",
"self",
"::",
"TYPE_STRING",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"self",
"::",
"isScalarType",
"(",
"$",
"this",
"->",
"type",
")",
"||",
"$",
"this",
"->",
"type",
"===",
"self",
"::",
"TYPE_ARRAY",
")",
"{",
"// Scalar and array",
"if",
"(",
"$",
"this",
"->",
"type",
"===",
"self",
"::",
"TYPE_BOOLEAN",
"&&",
"strtolower",
"(",
"$",
"value",
")",
"===",
"\"false\"",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"is_scalar",
"(",
"$",
"value",
")",
"||",
"$",
"this",
"->",
"type",
"===",
"self",
"::",
"TYPE_ARRAY",
")",
"{",
"if",
"(",
"settype",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"type",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"}",
"}",
"elseif",
"(",
"$",
"this",
"->",
"type",
"===",
"self",
"::",
"TYPE_DATETIME",
"||",
"$",
"this",
"->",
"type",
"===",
"self",
"::",
"TYPE_DATE",
")",
"{",
"// DateTime",
"if",
"(",
"$",
"value",
"instanceof",
"\\",
"DateTime",
")",
"{",
"return",
"$",
"value",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"isset",
"(",
"$",
"value",
"[",
"\"date\"",
"]",
")",
")",
"{",
"$",
"date",
"=",
"$",
"value",
"[",
"\"date\"",
"]",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"value",
")",
"&&",
"isset",
"(",
"$",
"value",
"->",
"date",
")",
")",
"{",
"$",
"date",
"=",
"$",
"value",
"->",
"date",
";",
"}",
"else",
"{",
"$",
"date",
"=",
"$",
"value",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"date",
")",
")",
"{",
"try",
"{",
"return",
"new",
"\\",
"DateTime",
"(",
"$",
"date",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"}",
"}",
"}",
"elseif",
"(",
"$",
"this",
"->",
"type",
"===",
"self",
"::",
"TYPE_COLLECTION",
"&&",
"Validator",
"::",
"isTraversable",
"(",
"$",
"value",
")",
")",
"{",
"// Collection",
"return",
"new",
"Entity",
"\\",
"Collection",
"(",
"$",
"this",
"->",
"typeOption",
",",
"$",
"value",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"type",
"===",
"self",
"::",
"TYPE_ENTITY",
"&&",
"Validator",
"::",
"isTraversable",
"(",
"$",
"value",
")",
")",
"{",
"// Entity",
"return",
"Entity",
"\\",
"Reflection",
"::",
"load",
"(",
"$",
"this",
"->",
"typeOption",
")",
"->",
"createEntity",
"(",
"$",
"value",
")",
";",
"}",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"\"Can not convert value on property '\"",
".",
"$",
"this",
"->",
"name",
".",
"\"' automatically!\"",
",",
"$",
"value",
")",
";",
"}"
]
| Try to convert value on required type automatically
@param mixed $value
@return mixed
@throws Exception\InvalidArgumentException | [
"Try",
"to",
"convert",
"value",
"on",
"required",
"type",
"automatically"
]
| a63b39f38a790fec7e852c8ef1e4c31653e689f7 | https://github.com/unimapper/unimapper/blob/a63b39f38a790fec7e852c8ef1e4c31653e689f7/src/Entity/Reflection/Property.php#L369-L428 |
14,312 | nyeholt/silverstripe-simplewiki | thirdparty/htmlpurifier-4.0.0-lite/library/HTMLPurifier/Printer/ConfigForm.php | HTMLPurifier_Printer_ConfigForm.renderNamespace | protected function renderNamespace($ns, $directives) {
$ret = '';
$ret .= $this->start('tbody', array('class' => 'namespace'));
$ret .= $this->start('tr');
$ret .= $this->element('th', $ns, array('colspan' => 2));
$ret .= $this->end('tr');
$ret .= $this->end('tbody');
$ret .= $this->start('tbody');
foreach ($directives as $directive => $value) {
$ret .= $this->start('tr');
$ret .= $this->start('th');
if ($this->docURL) {
$url = str_replace('%s', urlencode("$ns.$directive"), $this->docURL);
$ret .= $this->start('a', array('href' => $url));
}
$attr = array('for' => "{$this->name}:$ns.$directive");
// crop directive name if it's too long
if (!$this->compress || (strlen($directive) < $this->compress)) {
$directive_disp = $directive;
} else {
$directive_disp = substr($directive, 0, $this->compress - 2) . '...';
$attr['title'] = $directive;
}
$ret .= $this->element(
'label',
$directive_disp,
// component printers must create an element with this id
$attr
);
if ($this->docURL) $ret .= $this->end('a');
$ret .= $this->end('th');
$ret .= $this->start('td');
$def = $this->config->def->info["$ns.$directive"];
if (is_int($def)) {
$allow_null = $def < 0;
$type = abs($def);
} else {
$type = $def->type;
$allow_null = isset($def->allow_null);
}
if (!isset($this->fields[$type])) $type = 0; // default
$type_obj = $this->fields[$type];
if ($allow_null) {
$type_obj = new HTMLPurifier_Printer_ConfigForm_NullDecorator($type_obj);
}
$ret .= $type_obj->render($ns, $directive, $value, $this->name, array($this->genConfig, $this->config));
$ret .= $this->end('td');
$ret .= $this->end('tr');
}
$ret .= $this->end('tbody');
return $ret;
} | php | protected function renderNamespace($ns, $directives) {
$ret = '';
$ret .= $this->start('tbody', array('class' => 'namespace'));
$ret .= $this->start('tr');
$ret .= $this->element('th', $ns, array('colspan' => 2));
$ret .= $this->end('tr');
$ret .= $this->end('tbody');
$ret .= $this->start('tbody');
foreach ($directives as $directive => $value) {
$ret .= $this->start('tr');
$ret .= $this->start('th');
if ($this->docURL) {
$url = str_replace('%s', urlencode("$ns.$directive"), $this->docURL);
$ret .= $this->start('a', array('href' => $url));
}
$attr = array('for' => "{$this->name}:$ns.$directive");
// crop directive name if it's too long
if (!$this->compress || (strlen($directive) < $this->compress)) {
$directive_disp = $directive;
} else {
$directive_disp = substr($directive, 0, $this->compress - 2) . '...';
$attr['title'] = $directive;
}
$ret .= $this->element(
'label',
$directive_disp,
// component printers must create an element with this id
$attr
);
if ($this->docURL) $ret .= $this->end('a');
$ret .= $this->end('th');
$ret .= $this->start('td');
$def = $this->config->def->info["$ns.$directive"];
if (is_int($def)) {
$allow_null = $def < 0;
$type = abs($def);
} else {
$type = $def->type;
$allow_null = isset($def->allow_null);
}
if (!isset($this->fields[$type])) $type = 0; // default
$type_obj = $this->fields[$type];
if ($allow_null) {
$type_obj = new HTMLPurifier_Printer_ConfigForm_NullDecorator($type_obj);
}
$ret .= $type_obj->render($ns, $directive, $value, $this->name, array($this->genConfig, $this->config));
$ret .= $this->end('td');
$ret .= $this->end('tr');
}
$ret .= $this->end('tbody');
return $ret;
} | [
"protected",
"function",
"renderNamespace",
"(",
"$",
"ns",
",",
"$",
"directives",
")",
"{",
"$",
"ret",
"=",
"''",
";",
"$",
"ret",
".=",
"$",
"this",
"->",
"start",
"(",
"'tbody'",
",",
"array",
"(",
"'class'",
"=>",
"'namespace'",
")",
")",
";",
"$",
"ret",
".=",
"$",
"this",
"->",
"start",
"(",
"'tr'",
")",
";",
"$",
"ret",
".=",
"$",
"this",
"->",
"element",
"(",
"'th'",
",",
"$",
"ns",
",",
"array",
"(",
"'colspan'",
"=>",
"2",
")",
")",
";",
"$",
"ret",
".=",
"$",
"this",
"->",
"end",
"(",
"'tr'",
")",
";",
"$",
"ret",
".=",
"$",
"this",
"->",
"end",
"(",
"'tbody'",
")",
";",
"$",
"ret",
".=",
"$",
"this",
"->",
"start",
"(",
"'tbody'",
")",
";",
"foreach",
"(",
"$",
"directives",
"as",
"$",
"directive",
"=>",
"$",
"value",
")",
"{",
"$",
"ret",
".=",
"$",
"this",
"->",
"start",
"(",
"'tr'",
")",
";",
"$",
"ret",
".=",
"$",
"this",
"->",
"start",
"(",
"'th'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"docURL",
")",
"{",
"$",
"url",
"=",
"str_replace",
"(",
"'%s'",
",",
"urlencode",
"(",
"\"$ns.$directive\"",
")",
",",
"$",
"this",
"->",
"docURL",
")",
";",
"$",
"ret",
".=",
"$",
"this",
"->",
"start",
"(",
"'a'",
",",
"array",
"(",
"'href'",
"=>",
"$",
"url",
")",
")",
";",
"}",
"$",
"attr",
"=",
"array",
"(",
"'for'",
"=>",
"\"{$this->name}:$ns.$directive\"",
")",
";",
"// crop directive name if it's too long",
"if",
"(",
"!",
"$",
"this",
"->",
"compress",
"||",
"(",
"strlen",
"(",
"$",
"directive",
")",
"<",
"$",
"this",
"->",
"compress",
")",
")",
"{",
"$",
"directive_disp",
"=",
"$",
"directive",
";",
"}",
"else",
"{",
"$",
"directive_disp",
"=",
"substr",
"(",
"$",
"directive",
",",
"0",
",",
"$",
"this",
"->",
"compress",
"-",
"2",
")",
".",
"'...'",
";",
"$",
"attr",
"[",
"'title'",
"]",
"=",
"$",
"directive",
";",
"}",
"$",
"ret",
".=",
"$",
"this",
"->",
"element",
"(",
"'label'",
",",
"$",
"directive_disp",
",",
"// component printers must create an element with this id",
"$",
"attr",
")",
";",
"if",
"(",
"$",
"this",
"->",
"docURL",
")",
"$",
"ret",
".=",
"$",
"this",
"->",
"end",
"(",
"'a'",
")",
";",
"$",
"ret",
".=",
"$",
"this",
"->",
"end",
"(",
"'th'",
")",
";",
"$",
"ret",
".=",
"$",
"this",
"->",
"start",
"(",
"'td'",
")",
";",
"$",
"def",
"=",
"$",
"this",
"->",
"config",
"->",
"def",
"->",
"info",
"[",
"\"$ns.$directive\"",
"]",
";",
"if",
"(",
"is_int",
"(",
"$",
"def",
")",
")",
"{",
"$",
"allow_null",
"=",
"$",
"def",
"<",
"0",
";",
"$",
"type",
"=",
"abs",
"(",
"$",
"def",
")",
";",
"}",
"else",
"{",
"$",
"type",
"=",
"$",
"def",
"->",
"type",
";",
"$",
"allow_null",
"=",
"isset",
"(",
"$",
"def",
"->",
"allow_null",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"fields",
"[",
"$",
"type",
"]",
")",
")",
"$",
"type",
"=",
"0",
";",
"// default",
"$",
"type_obj",
"=",
"$",
"this",
"->",
"fields",
"[",
"$",
"type",
"]",
";",
"if",
"(",
"$",
"allow_null",
")",
"{",
"$",
"type_obj",
"=",
"new",
"HTMLPurifier_Printer_ConfigForm_NullDecorator",
"(",
"$",
"type_obj",
")",
";",
"}",
"$",
"ret",
".=",
"$",
"type_obj",
"->",
"render",
"(",
"$",
"ns",
",",
"$",
"directive",
",",
"$",
"value",
",",
"$",
"this",
"->",
"name",
",",
"array",
"(",
"$",
"this",
"->",
"genConfig",
",",
"$",
"this",
"->",
"config",
")",
")",
";",
"$",
"ret",
".=",
"$",
"this",
"->",
"end",
"(",
"'td'",
")",
";",
"$",
"ret",
".=",
"$",
"this",
"->",
"end",
"(",
"'tr'",
")",
";",
"}",
"$",
"ret",
".=",
"$",
"this",
"->",
"end",
"(",
"'tbody'",
")",
";",
"return",
"$",
"ret",
";",
"}"
]
| Renders a single namespace
@param $ns String namespace name
@param $directive Associative array of directives to values | [
"Renders",
"a",
"single",
"namespace"
]
| ecffed0d75be1454901e1cb24633472b8f67c967 | https://github.com/nyeholt/silverstripe-simplewiki/blob/ecffed0d75be1454901e1cb24633472b8f67c967/thirdparty/htmlpurifier-4.0.0-lite/library/HTMLPurifier/Printer/ConfigForm.php#L127-L181 |
14,313 | gorkalaucirica/HipchatAPIv2Client | Model/User.php | User.parseJson | public function parseJson($json)
{
$this->mentionName = $json['mention_name'];
$this->id = $json['id'];
$this->name = $json['name'];
if (isset($json['links'])) {
$this->links = $json['links'];
}
if(isset($json['xmpp_jid'])) {
$this->xmppJid = $json['xmpp_jid'];
$this->deleted = $json['is_deleted'];
$this->lastActive = $json['last_active'];
$this->title = $json['title'];
$this->created = new \Datetime($json['created']);
$this->groupAdmin = $json['is_group_admin'];
$this->timezone = $json['timezone'];
$this->guest = $json['is_guest'];
$this->email = $json['email'];
$this->photoUrl = $json['photo_url'];
}
} | php | public function parseJson($json)
{
$this->mentionName = $json['mention_name'];
$this->id = $json['id'];
$this->name = $json['name'];
if (isset($json['links'])) {
$this->links = $json['links'];
}
if(isset($json['xmpp_jid'])) {
$this->xmppJid = $json['xmpp_jid'];
$this->deleted = $json['is_deleted'];
$this->lastActive = $json['last_active'];
$this->title = $json['title'];
$this->created = new \Datetime($json['created']);
$this->groupAdmin = $json['is_group_admin'];
$this->timezone = $json['timezone'];
$this->guest = $json['is_guest'];
$this->email = $json['email'];
$this->photoUrl = $json['photo_url'];
}
} | [
"public",
"function",
"parseJson",
"(",
"$",
"json",
")",
"{",
"$",
"this",
"->",
"mentionName",
"=",
"$",
"json",
"[",
"'mention_name'",
"]",
";",
"$",
"this",
"->",
"id",
"=",
"$",
"json",
"[",
"'id'",
"]",
";",
"$",
"this",
"->",
"name",
"=",
"$",
"json",
"[",
"'name'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"json",
"[",
"'links'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"links",
"=",
"$",
"json",
"[",
"'links'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"json",
"[",
"'xmpp_jid'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"xmppJid",
"=",
"$",
"json",
"[",
"'xmpp_jid'",
"]",
";",
"$",
"this",
"->",
"deleted",
"=",
"$",
"json",
"[",
"'is_deleted'",
"]",
";",
"$",
"this",
"->",
"lastActive",
"=",
"$",
"json",
"[",
"'last_active'",
"]",
";",
"$",
"this",
"->",
"title",
"=",
"$",
"json",
"[",
"'title'",
"]",
";",
"$",
"this",
"->",
"created",
"=",
"new",
"\\",
"Datetime",
"(",
"$",
"json",
"[",
"'created'",
"]",
")",
";",
"$",
"this",
"->",
"groupAdmin",
"=",
"$",
"json",
"[",
"'is_group_admin'",
"]",
";",
"$",
"this",
"->",
"timezone",
"=",
"$",
"json",
"[",
"'timezone'",
"]",
";",
"$",
"this",
"->",
"guest",
"=",
"$",
"json",
"[",
"'is_guest'",
"]",
";",
"$",
"this",
"->",
"email",
"=",
"$",
"json",
"[",
"'email'",
"]",
";",
"$",
"this",
"->",
"photoUrl",
"=",
"$",
"json",
"[",
"'photo_url'",
"]",
";",
"}",
"}"
]
| Parses response given by the API and maps the fields to User object
@param array $json json_decoded response in json given by the server
@return void | [
"Parses",
"response",
"given",
"by",
"the",
"API",
"and",
"maps",
"the",
"fields",
"to",
"User",
"object"
]
| eef9c91d5efe5ae9cad27c503601ffff089c9547 | https://github.com/gorkalaucirica/HipchatAPIv2Client/blob/eef9c91d5efe5ae9cad27c503601ffff089c9547/Model/User.php#L61-L81 |
14,314 | f3ath/appnexusclient | src/HttpClient.php | HttpClient.call | public function call($method, $url, array $post = array(), array $headers = array())
{
$options = array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $headers,
);
switch ($method) {
case HttpMethod::GET:
$options[CURLOPT_POST] = false;
break;
case HttpMethod::POST:
$options[CURLOPT_POST] = true;
$options[CURLOPT_POSTFIELDS] = json_encode($post);
break;
case HttpMethod::PUT:
$options[CURLOPT_CUSTOMREQUEST] = 'PUT';
$options[CURLOPT_POSTFIELDS] = json_encode($post);
break;
case HttpMethod::DELETE:
$options[CURLOPT_CUSTOMREQUEST] = 'DELETE';
$options[CURLOPT_POSTFIELDS] = json_encode($post);
break;
default:
throw new InvalidArgumentException(sprintf('Invalid method: %s', $method));
}
$this->curl->init();
$this->curl->setOptArray($options);
$rawResponse = $this->curl->exec(1, true);
$contentType = $this->curl->getInfo(CURLINFO_CONTENT_TYPE);
if (strpos($contentType, self::CONTENT_TYPE_JSON) === false) {
return $rawResponse;
}
$response = json_decode($rawResponse);
if (!isset($response->response)) {
throw new RuntimeException(sprintf('Unexpected response: %s', $rawResponse));
}
$response = $response->response;
if ('OK' == @$response->status) {
return $response;
} elseif ('NOAUTH' == @$response->error_id || 'Authentication failed - not logged in' == @$response->error) {
throw new TokenExpiredException($response);
}
throw new ServerException($response);
} | php | public function call($method, $url, array $post = array(), array $headers = array())
{
$options = array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $headers,
);
switch ($method) {
case HttpMethod::GET:
$options[CURLOPT_POST] = false;
break;
case HttpMethod::POST:
$options[CURLOPT_POST] = true;
$options[CURLOPT_POSTFIELDS] = json_encode($post);
break;
case HttpMethod::PUT:
$options[CURLOPT_CUSTOMREQUEST] = 'PUT';
$options[CURLOPT_POSTFIELDS] = json_encode($post);
break;
case HttpMethod::DELETE:
$options[CURLOPT_CUSTOMREQUEST] = 'DELETE';
$options[CURLOPT_POSTFIELDS] = json_encode($post);
break;
default:
throw new InvalidArgumentException(sprintf('Invalid method: %s', $method));
}
$this->curl->init();
$this->curl->setOptArray($options);
$rawResponse = $this->curl->exec(1, true);
$contentType = $this->curl->getInfo(CURLINFO_CONTENT_TYPE);
if (strpos($contentType, self::CONTENT_TYPE_JSON) === false) {
return $rawResponse;
}
$response = json_decode($rawResponse);
if (!isset($response->response)) {
throw new RuntimeException(sprintf('Unexpected response: %s', $rawResponse));
}
$response = $response->response;
if ('OK' == @$response->status) {
return $response;
} elseif ('NOAUTH' == @$response->error_id || 'Authentication failed - not logged in' == @$response->error) {
throw new TokenExpiredException($response);
}
throw new ServerException($response);
} | [
"public",
"function",
"call",
"(",
"$",
"method",
",",
"$",
"url",
",",
"array",
"$",
"post",
"=",
"array",
"(",
")",
",",
"array",
"$",
"headers",
"=",
"array",
"(",
")",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"CURLOPT_URL",
"=>",
"$",
"url",
",",
"CURLOPT_RETURNTRANSFER",
"=>",
"true",
",",
"CURLOPT_HTTPHEADER",
"=>",
"$",
"headers",
",",
")",
";",
"switch",
"(",
"$",
"method",
")",
"{",
"case",
"HttpMethod",
"::",
"GET",
":",
"$",
"options",
"[",
"CURLOPT_POST",
"]",
"=",
"false",
";",
"break",
";",
"case",
"HttpMethod",
"::",
"POST",
":",
"$",
"options",
"[",
"CURLOPT_POST",
"]",
"=",
"true",
";",
"$",
"options",
"[",
"CURLOPT_POSTFIELDS",
"]",
"=",
"json_encode",
"(",
"$",
"post",
")",
";",
"break",
";",
"case",
"HttpMethod",
"::",
"PUT",
":",
"$",
"options",
"[",
"CURLOPT_CUSTOMREQUEST",
"]",
"=",
"'PUT'",
";",
"$",
"options",
"[",
"CURLOPT_POSTFIELDS",
"]",
"=",
"json_encode",
"(",
"$",
"post",
")",
";",
"break",
";",
"case",
"HttpMethod",
"::",
"DELETE",
":",
"$",
"options",
"[",
"CURLOPT_CUSTOMREQUEST",
"]",
"=",
"'DELETE'",
";",
"$",
"options",
"[",
"CURLOPT_POSTFIELDS",
"]",
"=",
"json_encode",
"(",
"$",
"post",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid method: %s'",
",",
"$",
"method",
")",
")",
";",
"}",
"$",
"this",
"->",
"curl",
"->",
"init",
"(",
")",
";",
"$",
"this",
"->",
"curl",
"->",
"setOptArray",
"(",
"$",
"options",
")",
";",
"$",
"rawResponse",
"=",
"$",
"this",
"->",
"curl",
"->",
"exec",
"(",
"1",
",",
"true",
")",
";",
"$",
"contentType",
"=",
"$",
"this",
"->",
"curl",
"->",
"getInfo",
"(",
"CURLINFO_CONTENT_TYPE",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"contentType",
",",
"self",
"::",
"CONTENT_TYPE_JSON",
")",
"===",
"false",
")",
"{",
"return",
"$",
"rawResponse",
";",
"}",
"$",
"response",
"=",
"json_decode",
"(",
"$",
"rawResponse",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"response",
"->",
"response",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Unexpected response: %s'",
",",
"$",
"rawResponse",
")",
")",
";",
"}",
"$",
"response",
"=",
"$",
"response",
"->",
"response",
";",
"if",
"(",
"'OK'",
"==",
"@",
"$",
"response",
"->",
"status",
")",
"{",
"return",
"$",
"response",
";",
"}",
"elseif",
"(",
"'NOAUTH'",
"==",
"@",
"$",
"response",
"->",
"error_id",
"||",
"'Authentication failed - not logged in'",
"==",
"@",
"$",
"response",
"->",
"error",
")",
"{",
"throw",
"new",
"TokenExpiredException",
"(",
"$",
"response",
")",
";",
"}",
"throw",
"new",
"ServerException",
"(",
"$",
"response",
")",
";",
"}"
]
| Do raw HTTP call
@param string $method
@param string $url
@param array $post POST data
@param array $headers
@return object response | [
"Do",
"raw",
"HTTP",
"call"
]
| cfe3f3a98a9c2883484154c8997c7459b1504742 | https://github.com/f3ath/appnexusclient/blob/cfe3f3a98a9c2883484154c8997c7459b1504742/src/HttpClient.php#L39-L84 |
14,315 | unimapper/unimapper | src/Repository.php | Repository.update | public function update(Entity $entity, $primaryValue)
{
if (!$entity->getValidator()->validate()) {
throw new Exception\ValidatorException($entity->getValidator());
}
try {
if (!$this->query()->updateOne($primaryValue, $entity->getData())->run($this->connection)) {
throw new Exception\RepositoryException("Entity was not successfully updated!");
}
} catch (Exception\QueryException $e) {
throw new Exception\RepositoryException($e->getMessage());
}
$this->_saveAssociated($primaryValue, $entity);
} | php | public function update(Entity $entity, $primaryValue)
{
if (!$entity->getValidator()->validate()) {
throw new Exception\ValidatorException($entity->getValidator());
}
try {
if (!$this->query()->updateOne($primaryValue, $entity->getData())->run($this->connection)) {
throw new Exception\RepositoryException("Entity was not successfully updated!");
}
} catch (Exception\QueryException $e) {
throw new Exception\RepositoryException($e->getMessage());
}
$this->_saveAssociated($primaryValue, $entity);
} | [
"public",
"function",
"update",
"(",
"Entity",
"$",
"entity",
",",
"$",
"primaryValue",
")",
"{",
"if",
"(",
"!",
"$",
"entity",
"->",
"getValidator",
"(",
")",
"->",
"validate",
"(",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"ValidatorException",
"(",
"$",
"entity",
"->",
"getValidator",
"(",
")",
")",
";",
"}",
"try",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"query",
"(",
")",
"->",
"updateOne",
"(",
"$",
"primaryValue",
",",
"$",
"entity",
"->",
"getData",
"(",
")",
")",
"->",
"run",
"(",
"$",
"this",
"->",
"connection",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"RepositoryException",
"(",
"\"Entity was not successfully updated!\"",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"\\",
"QueryException",
"$",
"e",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"RepositoryException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"_saveAssociated",
"(",
"$",
"primaryValue",
",",
"$",
"entity",
")",
";",
"}"
]
| Update single record
@param Entity $entity
@param mixed $primaryValue
@throws Exception\ValidatorException
@throws Exception\RepositoryException | [
"Update",
"single",
"record"
]
| a63b39f38a790fec7e852c8ef1e4c31653e689f7 | https://github.com/unimapper/unimapper/blob/a63b39f38a790fec7e852c8ef1e4c31653e689f7/src/Repository.php#L116-L132 |
14,316 | unimapper/unimapper | src/Repository.php | Repository.destroy | public function destroy(Entity $entity)
{
$requiredClass = Convention::nameToClass($this->getEntityName(), Convention::ENTITY_MASK);
if (!$entity instanceof $requiredClass) {
throw new Exception\RepositoryException(
"Entity must be instance of ". $requiredClass . "!"
);
}
$reflection = $entity::getReflection();
if (!$reflection->hasPrimary()) {
throw new Exception\RepositoryException(
"Can not delete entity without primary property!"
);
}
$primaryName = $reflection->getPrimaryProperty()->getName();
try {
return $this->query()->deleteOne($entity->{$primaryName})->run($this->connection);
} catch (Exception\QueryException $e) {
throw new Exception\RepositoryException($e->getMessage());
}
} | php | public function destroy(Entity $entity)
{
$requiredClass = Convention::nameToClass($this->getEntityName(), Convention::ENTITY_MASK);
if (!$entity instanceof $requiredClass) {
throw new Exception\RepositoryException(
"Entity must be instance of ". $requiredClass . "!"
);
}
$reflection = $entity::getReflection();
if (!$reflection->hasPrimary()) {
throw new Exception\RepositoryException(
"Can not delete entity without primary property!"
);
}
$primaryName = $reflection->getPrimaryProperty()->getName();
try {
return $this->query()->deleteOne($entity->{$primaryName})->run($this->connection);
} catch (Exception\QueryException $e) {
throw new Exception\RepositoryException($e->getMessage());
}
} | [
"public",
"function",
"destroy",
"(",
"Entity",
"$",
"entity",
")",
"{",
"$",
"requiredClass",
"=",
"Convention",
"::",
"nameToClass",
"(",
"$",
"this",
"->",
"getEntityName",
"(",
")",
",",
"Convention",
"::",
"ENTITY_MASK",
")",
";",
"if",
"(",
"!",
"$",
"entity",
"instanceof",
"$",
"requiredClass",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"RepositoryException",
"(",
"\"Entity must be instance of \"",
".",
"$",
"requiredClass",
".",
"\"!\"",
")",
";",
"}",
"$",
"reflection",
"=",
"$",
"entity",
"::",
"getReflection",
"(",
")",
";",
"if",
"(",
"!",
"$",
"reflection",
"->",
"hasPrimary",
"(",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"RepositoryException",
"(",
"\"Can not delete entity without primary property!\"",
")",
";",
"}",
"$",
"primaryName",
"=",
"$",
"reflection",
"->",
"getPrimaryProperty",
"(",
")",
"->",
"getName",
"(",
")",
";",
"try",
"{",
"return",
"$",
"this",
"->",
"query",
"(",
")",
"->",
"deleteOne",
"(",
"$",
"entity",
"->",
"{",
"$",
"primaryName",
"}",
")",
"->",
"run",
"(",
"$",
"this",
"->",
"connection",
")",
";",
"}",
"catch",
"(",
"Exception",
"\\",
"QueryException",
"$",
"e",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"RepositoryException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
]
| Delete single record
@param Entity $entity
@return boolean
@throws Exception\RepositoryException | [
"Delete",
"single",
"record"
]
| a63b39f38a790fec7e852c8ef1e4c31653e689f7 | https://github.com/unimapper/unimapper/blob/a63b39f38a790fec7e852c8ef1e4c31653e689f7/src/Repository.php#L185-L208 |
14,317 | unimapper/unimapper | src/Repository.php | Repository.find | public function find(array $filter = [], array $orderBy = [], $limit = 0,
$offset = 0, array $associate = []
) {
try {
$query = $this->query()
->select()
->associate($associate)
->setFilter($filter);
foreach ($orderBy as $orderByRule) {
$query->orderBy($orderByRule[0], $orderByRule[1]);
}
return $query->limit($limit)->offset($offset)->run($this->connection);
} catch (Exception\QueryException $e) {
throw new Exception\RepositoryException($e->getMessage());
}
} | php | public function find(array $filter = [], array $orderBy = [], $limit = 0,
$offset = 0, array $associate = []
) {
try {
$query = $this->query()
->select()
->associate($associate)
->setFilter($filter);
foreach ($orderBy as $orderByRule) {
$query->orderBy($orderByRule[0], $orderByRule[1]);
}
return $query->limit($limit)->offset($offset)->run($this->connection);
} catch (Exception\QueryException $e) {
throw new Exception\RepositoryException($e->getMessage());
}
} | [
"public",
"function",
"find",
"(",
"array",
"$",
"filter",
"=",
"[",
"]",
",",
"array",
"$",
"orderBy",
"=",
"[",
"]",
",",
"$",
"limit",
"=",
"0",
",",
"$",
"offset",
"=",
"0",
",",
"array",
"$",
"associate",
"=",
"[",
"]",
")",
"{",
"try",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"query",
"(",
")",
"->",
"select",
"(",
")",
"->",
"associate",
"(",
"$",
"associate",
")",
"->",
"setFilter",
"(",
"$",
"filter",
")",
";",
"foreach",
"(",
"$",
"orderBy",
"as",
"$",
"orderByRule",
")",
"{",
"$",
"query",
"->",
"orderBy",
"(",
"$",
"orderByRule",
"[",
"0",
"]",
",",
"$",
"orderByRule",
"[",
"1",
"]",
")",
";",
"}",
"return",
"$",
"query",
"->",
"limit",
"(",
"$",
"limit",
")",
"->",
"offset",
"(",
"$",
"offset",
")",
"->",
"run",
"(",
"$",
"this",
"->",
"connection",
")",
";",
"}",
"catch",
"(",
"Exception",
"\\",
"QueryException",
"$",
"e",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"RepositoryException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
]
| Find all records
@param array $filter
@param array $orderBy
@param int $limit
@param int $offset
@param array $associate
@return Entity\Collection
@throws Exception\RepositoryException | [
"Find",
"all",
"records"
]
| a63b39f38a790fec7e852c8ef1e4c31653e689f7 | https://github.com/unimapper/unimapper/blob/a63b39f38a790fec7e852c8ef1e4c31653e689f7/src/Repository.php#L254-L272 |
14,318 | unimapper/unimapper | src/Repository.php | Repository.findPrimaries | public function findPrimaries(array $primaryValues, array $associate = [])
{
$reflection = Entity\Reflection::load($this->getEntityName());
if (!$reflection->hasPrimary()) {
throw new Exception\RepositoryException(
"Method can not be used because entity " . $this->getEntityName()
. " has no primary property defined!"
);
}
if (empty($primaryValues)) {
throw new Exception\RepositoryException(
"Values can not be empty!"
);
}
try {
return $this->query()
->select()
->setFilter(
[
$reflection->getPrimaryProperty()->getName() => [
Filter::EQUAL => $primaryValues
]
]
)
->associate($associate)
->run($this->connection);
} catch (Exception\QueryException $e) {
throw new Exception\RepositoryException($e->getMessage());
}
} | php | public function findPrimaries(array $primaryValues, array $associate = [])
{
$reflection = Entity\Reflection::load($this->getEntityName());
if (!$reflection->hasPrimary()) {
throw new Exception\RepositoryException(
"Method can not be used because entity " . $this->getEntityName()
. " has no primary property defined!"
);
}
if (empty($primaryValues)) {
throw new Exception\RepositoryException(
"Values can not be empty!"
);
}
try {
return $this->query()
->select()
->setFilter(
[
$reflection->getPrimaryProperty()->getName() => [
Filter::EQUAL => $primaryValues
]
]
)
->associate($associate)
->run($this->connection);
} catch (Exception\QueryException $e) {
throw new Exception\RepositoryException($e->getMessage());
}
} | [
"public",
"function",
"findPrimaries",
"(",
"array",
"$",
"primaryValues",
",",
"array",
"$",
"associate",
"=",
"[",
"]",
")",
"{",
"$",
"reflection",
"=",
"Entity",
"\\",
"Reflection",
"::",
"load",
"(",
"$",
"this",
"->",
"getEntityName",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"reflection",
"->",
"hasPrimary",
"(",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"RepositoryException",
"(",
"\"Method can not be used because entity \"",
".",
"$",
"this",
"->",
"getEntityName",
"(",
")",
".",
"\" has no primary property defined!\"",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"primaryValues",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"RepositoryException",
"(",
"\"Values can not be empty!\"",
")",
";",
"}",
"try",
"{",
"return",
"$",
"this",
"->",
"query",
"(",
")",
"->",
"select",
"(",
")",
"->",
"setFilter",
"(",
"[",
"$",
"reflection",
"->",
"getPrimaryProperty",
"(",
")",
"->",
"getName",
"(",
")",
"=>",
"[",
"Filter",
"::",
"EQUAL",
"=>",
"$",
"primaryValues",
"]",
"]",
")",
"->",
"associate",
"(",
"$",
"associate",
")",
"->",
"run",
"(",
"$",
"this",
"->",
"connection",
")",
";",
"}",
"catch",
"(",
"Exception",
"\\",
"QueryException",
"$",
"e",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"RepositoryException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
]
| Find records by set of primary values
@param array $primaryValues
@param array $associate
@return Entity\Collection
@throws Exception\RepositoryException | [
"Find",
"records",
"by",
"set",
"of",
"primary",
"values"
]
| a63b39f38a790fec7e852c8ef1e4c31653e689f7 | https://github.com/unimapper/unimapper/blob/a63b39f38a790fec7e852c8ef1e4c31653e689f7/src/Repository.php#L295-L328 |
14,319 | antarestupin/Accessible | lib/Accessible/MethodManager/CollectionManager.php | CollectionManager.collectionContains | public static function collectionContains($needle, $haystack)
{
foreach ($haystack as $value) {
if ($value === $needle) {
return true;
}
}
return false;
} | php | public static function collectionContains($needle, $haystack)
{
foreach ($haystack as $value) {
if ($value === $needle) {
return true;
}
}
return false;
} | [
"public",
"static",
"function",
"collectionContains",
"(",
"$",
"needle",
",",
"$",
"haystack",
")",
"{",
"foreach",
"(",
"$",
"haystack",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"$",
"needle",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Indicates wether given collection contains the wanted item or not.
@param mixed $needle
@param array $haystack
@return bool | [
"Indicates",
"wether",
"given",
"collection",
"contains",
"the",
"wanted",
"item",
"or",
"not",
"."
]
| d12ce93d72f74c099dfd2109371fcd6ddfffdca4 | https://github.com/antarestupin/Accessible/blob/d12ce93d72f74c099dfd2109371fcd6ddfffdca4/lib/Accessible/MethodManager/CollectionManager.php#L15-L24 |
14,320 | crysalead/net | src/Transport/Protocol/Http/Curl.php | Curl._initRequest | protected function _initRequest($socket, $response)
{
$stream = $this->_classes['stream'];
$curlOptions = $socket->options();
$curlOptions[CURLOPT_INFILESIZE] = $socket->outgoing()->length();
if (isset($curlOptions[CURLOPT_FILE])) {
$response->body(fopen($curlOptions[CURLOPT_FILE], 'w+'));
}
$socket->incoming($response->stream());
if (!$handle = curl_init()) {
throw new ClientException('Unable to create a new cURL handle');
}
curl_setopt_array($handle, $curlOptions);
return $handle;
} | php | protected function _initRequest($socket, $response)
{
$stream = $this->_classes['stream'];
$curlOptions = $socket->options();
$curlOptions[CURLOPT_INFILESIZE] = $socket->outgoing()->length();
if (isset($curlOptions[CURLOPT_FILE])) {
$response->body(fopen($curlOptions[CURLOPT_FILE], 'w+'));
}
$socket->incoming($response->stream());
if (!$handle = curl_init()) {
throw new ClientException('Unable to create a new cURL handle');
}
curl_setopt_array($handle, $curlOptions);
return $handle;
} | [
"protected",
"function",
"_initRequest",
"(",
"$",
"socket",
",",
"$",
"response",
")",
"{",
"$",
"stream",
"=",
"$",
"this",
"->",
"_classes",
"[",
"'stream'",
"]",
";",
"$",
"curlOptions",
"=",
"$",
"socket",
"->",
"options",
"(",
")",
";",
"$",
"curlOptions",
"[",
"CURLOPT_INFILESIZE",
"]",
"=",
"$",
"socket",
"->",
"outgoing",
"(",
")",
"->",
"length",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"curlOptions",
"[",
"CURLOPT_FILE",
"]",
")",
")",
"{",
"$",
"response",
"->",
"body",
"(",
"fopen",
"(",
"$",
"curlOptions",
"[",
"CURLOPT_FILE",
"]",
",",
"'w+'",
")",
")",
";",
"}",
"$",
"socket",
"->",
"incoming",
"(",
"$",
"response",
"->",
"stream",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"handle",
"=",
"curl_init",
"(",
")",
")",
"{",
"throw",
"new",
"ClientException",
"(",
"'Unable to create a new cURL handle'",
")",
";",
"}",
"curl_setopt_array",
"(",
"$",
"handle",
",",
"$",
"curlOptions",
")",
";",
"return",
"$",
"handle",
";",
"}"
]
| Initialize a socket to be ready to send data.
@param integer $max The number of simultaneous allowed connections. | [
"Initialize",
"a",
"socket",
"to",
"be",
"ready",
"to",
"send",
"data",
"."
]
| 4d75abead39e954529b56cbffa3841a9cd3044bb | https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Transport/Protocol/Http/Curl.php#L117-L134 |
14,321 | crysalead/net | src/Transport/Protocol/Http/Curl.php | Curl.push | public function push($request, $response, $options = [])
{
$socket = $request instanceof $this->_classes['socket'] ? $request : $this($request, $options);
$this->_queue[$socket->id()] = [
'socket' => $socket,
'response' => $response
];
} | php | public function push($request, $response, $options = [])
{
$socket = $request instanceof $this->_classes['socket'] ? $request : $this($request, $options);
$this->_queue[$socket->id()] = [
'socket' => $socket,
'response' => $response
];
} | [
"public",
"function",
"push",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"socket",
"=",
"$",
"request",
"instanceof",
"$",
"this",
"->",
"_classes",
"[",
"'socket'",
"]",
"?",
"$",
"request",
":",
"$",
"this",
"(",
"$",
"request",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"_queue",
"[",
"$",
"socket",
"->",
"id",
"(",
")",
"]",
"=",
"[",
"'socket'",
"=>",
"$",
"socket",
",",
"'response'",
"=>",
"$",
"response",
"]",
";",
"}"
]
| Push a request in the queue. | [
"Push",
"a",
"request",
"in",
"the",
"queue",
"."
]
| 4d75abead39e954529b56cbffa3841a9cd3044bb | https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Transport/Protocol/Http/Curl.php#L296-L304 |
14,322 | crysalead/net | src/Transport/Protocol/Http/Curl.php | Curl.flush | public function flush($max = 10, $options = [])
{
$defaults = [
'selectTimeout' => 1.0
];
$options += $defaults;
do {
$this->select($options['selectTimeout']);
$this->process($max);
} while ($this->_running > 0);
$results = $this->_results;
$this->_results = [];
return $results;
} | php | public function flush($max = 10, $options = [])
{
$defaults = [
'selectTimeout' => 1.0
];
$options += $defaults;
do {
$this->select($options['selectTimeout']);
$this->process($max);
} while ($this->_running > 0);
$results = $this->_results;
$this->_results = [];
return $results;
} | [
"public",
"function",
"flush",
"(",
"$",
"max",
"=",
"10",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'selectTimeout'",
"=>",
"1.0",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"do",
"{",
"$",
"this",
"->",
"select",
"(",
"$",
"options",
"[",
"'selectTimeout'",
"]",
")",
";",
"$",
"this",
"->",
"process",
"(",
"$",
"max",
")",
";",
"}",
"while",
"(",
"$",
"this",
"->",
"_running",
">",
"0",
")",
";",
"$",
"results",
"=",
"$",
"this",
"->",
"_results",
";",
"$",
"this",
"->",
"_results",
"=",
"[",
"]",
";",
"return",
"$",
"results",
";",
"}"
]
| Runs until all outstanding requests have been completed.
@param integer $max The number of simultaneous allowed connections.
@return array The array of responses. | [
"Runs",
"until",
"all",
"outstanding",
"requests",
"have",
"been",
"completed",
"."
]
| 4d75abead39e954529b56cbffa3841a9cd3044bb | https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Transport/Protocol/Http/Curl.php#L312-L328 |
14,323 | crysalead/net | src/Transport/Protocol/Http/Curl.php | Curl._fillup | protected function _fillup($max)
{
$nb = $max - $this->_running;
$list = array_splice($this->_queue, 0, $nb);
foreach ($list as $item) {
$handle = $this->_initRequest($item['socket'], $item['response']);
$this->_handles[(integer) $handle] = $item;
curl_multi_add_handle($this->_curl, $handle);
}
} | php | protected function _fillup($max)
{
$nb = $max - $this->_running;
$list = array_splice($this->_queue, 0, $nb);
foreach ($list as $item) {
$handle = $this->_initRequest($item['socket'], $item['response']);
$this->_handles[(integer) $handle] = $item;
curl_multi_add_handle($this->_curl, $handle);
}
} | [
"protected",
"function",
"_fillup",
"(",
"$",
"max",
")",
"{",
"$",
"nb",
"=",
"$",
"max",
"-",
"$",
"this",
"->",
"_running",
";",
"$",
"list",
"=",
"array_splice",
"(",
"$",
"this",
"->",
"_queue",
",",
"0",
",",
"$",
"nb",
")",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"item",
")",
"{",
"$",
"handle",
"=",
"$",
"this",
"->",
"_initRequest",
"(",
"$",
"item",
"[",
"'socket'",
"]",
",",
"$",
"item",
"[",
"'response'",
"]",
")",
";",
"$",
"this",
"->",
"_handles",
"[",
"(",
"integer",
")",
"$",
"handle",
"]",
"=",
"$",
"item",
";",
"curl_multi_add_handle",
"(",
"$",
"this",
"->",
"_curl",
",",
"$",
"handle",
")",
";",
"}",
"}"
]
| Fill the multi handle up to the maximum allowed connections.
@param integer $max The number of simultaneous allowed connections. | [
"Fill",
"the",
"multi",
"handle",
"up",
"to",
"the",
"maximum",
"allowed",
"connections",
"."
]
| 4d75abead39e954529b56cbffa3841a9cd3044bb | https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Transport/Protocol/Http/Curl.php#L392-L401 |
14,324 | Webiny/AnalyticsDb | src/Webiny/AnalyticsDb/DateHelper.php | DateHelper.rangeThisWeek | public static function rangeThisWeek()
{
$ts = strtotime(date('Y-m-d')) + 86400;
do {
$ts -= 86400;
$startDate = date('N', $ts);
} while ($startDate != '1');
return [$ts, $ts + (86400 * 6)];
} | php | public static function rangeThisWeek()
{
$ts = strtotime(date('Y-m-d')) + 86400;
do {
$ts -= 86400;
$startDate = date('N', $ts);
} while ($startDate != '1');
return [$ts, $ts + (86400 * 6)];
} | [
"public",
"static",
"function",
"rangeThisWeek",
"(",
")",
"{",
"$",
"ts",
"=",
"strtotime",
"(",
"date",
"(",
"'Y-m-d'",
")",
")",
"+",
"86400",
";",
"do",
"{",
"$",
"ts",
"-=",
"86400",
";",
"$",
"startDate",
"=",
"date",
"(",
"'N'",
",",
"$",
"ts",
")",
";",
"}",
"while",
"(",
"$",
"startDate",
"!=",
"'1'",
")",
";",
"return",
"[",
"$",
"ts",
",",
"$",
"ts",
"+",
"(",
"86400",
"*",
"6",
")",
"]",
";",
"}"
]
| Returns a date range for the current week.
@return array | [
"Returns",
"a",
"date",
"range",
"for",
"the",
"current",
"week",
"."
]
| e0b1e920643cd63071406520767243736004052e | https://github.com/Webiny/AnalyticsDb/blob/e0b1e920643cd63071406520767243736004052e/src/Webiny/AnalyticsDb/DateHelper.php#L35-L44 |
14,325 | Webiny/AnalyticsDb | src/Webiny/AnalyticsDb/DateHelper.php | DateHelper.rangeThisMonth | public static function rangeThisMonth()
{
$currentMonth = date('Y-m-01', time());
$currentMonthTs = self::toTs($currentMonth);
return [$currentMonthTs, $currentMonthTs + (86400 * (date('t') - 1))];
} | php | public static function rangeThisMonth()
{
$currentMonth = date('Y-m-01', time());
$currentMonthTs = self::toTs($currentMonth);
return [$currentMonthTs, $currentMonthTs + (86400 * (date('t') - 1))];
} | [
"public",
"static",
"function",
"rangeThisMonth",
"(",
")",
"{",
"$",
"currentMonth",
"=",
"date",
"(",
"'Y-m-01'",
",",
"time",
"(",
")",
")",
";",
"$",
"currentMonthTs",
"=",
"self",
"::",
"toTs",
"(",
"$",
"currentMonth",
")",
";",
"return",
"[",
"$",
"currentMonthTs",
",",
"$",
"currentMonthTs",
"+",
"(",
"86400",
"*",
"(",
"date",
"(",
"'t'",
")",
"-",
"1",
")",
")",
"]",
";",
"}"
]
| Returns a date range for the current month.
@return array | [
"Returns",
"a",
"date",
"range",
"for",
"the",
"current",
"month",
"."
]
| e0b1e920643cd63071406520767243736004052e | https://github.com/Webiny/AnalyticsDb/blob/e0b1e920643cd63071406520767243736004052e/src/Webiny/AnalyticsDb/DateHelper.php#L75-L81 |
14,326 | Webiny/AnalyticsDb | src/Webiny/AnalyticsDb/DateHelper.php | DateHelper.rangeLastMonth | public static function rangeLastMonth()
{
$lastMonth = date('m') - 1;
if ($lastMonth <= 0) {
$lastMonth = 12;
}
$lastMonth = date('Y') . '-' . $lastMonth . '-01';
return [self::toTs($lastMonth), self::toTs($lastMonth) + (86400 * (date('t', strtotime($lastMonth))-1))];
} | php | public static function rangeLastMonth()
{
$lastMonth = date('m') - 1;
if ($lastMonth <= 0) {
$lastMonth = 12;
}
$lastMonth = date('Y') . '-' . $lastMonth . '-01';
return [self::toTs($lastMonth), self::toTs($lastMonth) + (86400 * (date('t', strtotime($lastMonth))-1))];
} | [
"public",
"static",
"function",
"rangeLastMonth",
"(",
")",
"{",
"$",
"lastMonth",
"=",
"date",
"(",
"'m'",
")",
"-",
"1",
";",
"if",
"(",
"$",
"lastMonth",
"<=",
"0",
")",
"{",
"$",
"lastMonth",
"=",
"12",
";",
"}",
"$",
"lastMonth",
"=",
"date",
"(",
"'Y'",
")",
".",
"'-'",
".",
"$",
"lastMonth",
".",
"'-01'",
";",
"return",
"[",
"self",
"::",
"toTs",
"(",
"$",
"lastMonth",
")",
",",
"self",
"::",
"toTs",
"(",
"$",
"lastMonth",
")",
"+",
"(",
"86400",
"*",
"(",
"date",
"(",
"'t'",
",",
"strtotime",
"(",
"$",
"lastMonth",
")",
")",
"-",
"1",
")",
")",
"]",
";",
"}"
]
| Returns a date range for the previous month.
@return array | [
"Returns",
"a",
"date",
"range",
"for",
"the",
"previous",
"month",
"."
]
| e0b1e920643cd63071406520767243736004052e | https://github.com/Webiny/AnalyticsDb/blob/e0b1e920643cd63071406520767243736004052e/src/Webiny/AnalyticsDb/DateHelper.php#L88-L97 |
14,327 | antarestupin/Accessible | lib/Accessible/Configuration.php | Configuration.getAnnotationReader | public static function getAnnotationReader()
{
if (self::$annotationReader === null) {
self::$annotationReader = new CachedReader(new AnnotationReader(), new ArrayCache());
}
return self::$annotationReader;
} | php | public static function getAnnotationReader()
{
if (self::$annotationReader === null) {
self::$annotationReader = new CachedReader(new AnnotationReader(), new ArrayCache());
}
return self::$annotationReader;
} | [
"public",
"static",
"function",
"getAnnotationReader",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"annotationReader",
"===",
"null",
")",
"{",
"self",
"::",
"$",
"annotationReader",
"=",
"new",
"CachedReader",
"(",
"new",
"AnnotationReader",
"(",
")",
",",
"new",
"ArrayCache",
"(",
")",
")",
";",
"}",
"return",
"self",
"::",
"$",
"annotationReader",
";",
"}"
]
| Get the annotation reader that is used.
Initializes it if it doesn't already exists.
@return Reader The annotation reader. | [
"Get",
"the",
"annotation",
"reader",
"that",
"is",
"used",
".",
"Initializes",
"it",
"if",
"it",
"doesn",
"t",
"already",
"exists",
"."
]
| d12ce93d72f74c099dfd2109371fcd6ddfffdca4 | https://github.com/antarestupin/Accessible/blob/d12ce93d72f74c099dfd2109371fcd6ddfffdca4/lib/Accessible/Configuration.php#L70-L77 |
14,328 | antarestupin/Accessible | lib/Accessible/Configuration.php | Configuration.getConstraintsValidator | public static function getConstraintsValidator()
{
if (self::$constraintsValidator === null) {
self::$constraintsValidator = Validation::createValidatorBuilder()
->enableAnnotationMapping(self::getAnnotationReader())
->getValidator();
}
return self::$constraintsValidator;
} | php | public static function getConstraintsValidator()
{
if (self::$constraintsValidator === null) {
self::$constraintsValidator = Validation::createValidatorBuilder()
->enableAnnotationMapping(self::getAnnotationReader())
->getValidator();
}
return self::$constraintsValidator;
} | [
"public",
"static",
"function",
"getConstraintsValidator",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"constraintsValidator",
"===",
"null",
")",
"{",
"self",
"::",
"$",
"constraintsValidator",
"=",
"Validation",
"::",
"createValidatorBuilder",
"(",
")",
"->",
"enableAnnotationMapping",
"(",
"self",
"::",
"getAnnotationReader",
"(",
")",
")",
"->",
"getValidator",
"(",
")",
";",
"}",
"return",
"self",
"::",
"$",
"constraintsValidator",
";",
"}"
]
| Get the constraints validator that is used.
Initializes it if it doesn't already exists.
@return ConstraintValidator The annotation reader. | [
"Get",
"the",
"constraints",
"validator",
"that",
"is",
"used",
".",
"Initializes",
"it",
"if",
"it",
"doesn",
"t",
"already",
"exists",
"."
]
| d12ce93d72f74c099dfd2109371fcd6ddfffdca4 | https://github.com/antarestupin/Accessible/blob/d12ce93d72f74c099dfd2109371fcd6ddfffdca4/lib/Accessible/Configuration.php#L95-L104 |
14,329 | antarestupin/Accessible | lib/Accessible/Configuration.php | Configuration.setCache | private static function setCache(Cache &$cacheToChange = null, Cache $cache = null, $namespace = null)
{
if ($namespace === null) {
$namespace = self::$cacheDefaultNamespace;
}
if (!is_string($namespace)) {
throw new \InvalidArgumentException("The namespace must be a string.");
}
$cacheToChange = $cache;
if ($cache !== null) {
$cacheToChange->setNamespace($namespace);
}
} | php | private static function setCache(Cache &$cacheToChange = null, Cache $cache = null, $namespace = null)
{
if ($namespace === null) {
$namespace = self::$cacheDefaultNamespace;
}
if (!is_string($namespace)) {
throw new \InvalidArgumentException("The namespace must be a string.");
}
$cacheToChange = $cache;
if ($cache !== null) {
$cacheToChange->setNamespace($namespace);
}
} | [
"private",
"static",
"function",
"setCache",
"(",
"Cache",
"&",
"$",
"cacheToChange",
"=",
"null",
",",
"Cache",
"$",
"cache",
"=",
"null",
",",
"$",
"namespace",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"namespace",
"===",
"null",
")",
"{",
"$",
"namespace",
"=",
"self",
"::",
"$",
"cacheDefaultNamespace",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"namespace",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"The namespace must be a string.\"",
")",
";",
"}",
"$",
"cacheToChange",
"=",
"$",
"cache",
";",
"if",
"(",
"$",
"cache",
"!==",
"null",
")",
"{",
"$",
"cacheToChange",
"->",
"setNamespace",
"(",
"$",
"namespace",
")",
";",
"}",
"}"
]
| Set a cache driver.
@param Cache $cacheToChange The cache to change.
@param Cache $cache The cache driver.
@param string $namespace The cache namespace. | [
"Set",
"a",
"cache",
"driver",
"."
]
| d12ce93d72f74c099dfd2109371fcd6ddfffdca4 | https://github.com/antarestupin/Accessible/blob/d12ce93d72f74c099dfd2109371fcd6ddfffdca4/lib/Accessible/Configuration.php#L173-L186 |
14,330 | antarestupin/Accessible | lib/Accessible/Configuration.php | Configuration.setCacheDriver | public static function setCacheDriver(Cache $cache = null, $namespace = null)
{
self::setCache(self::$cacheDriver, $cache, $namespace);
} | php | public static function setCacheDriver(Cache $cache = null, $namespace = null)
{
self::setCache(self::$cacheDriver, $cache, $namespace);
} | [
"public",
"static",
"function",
"setCacheDriver",
"(",
"Cache",
"$",
"cache",
"=",
"null",
",",
"$",
"namespace",
"=",
"null",
")",
"{",
"self",
"::",
"setCache",
"(",
"self",
"::",
"$",
"cacheDriver",
",",
"$",
"cache",
",",
"$",
"namespace",
")",
";",
"}"
]
| Set the cache driver that will be used.
@param Cache $cache The cache driver.
@param string $namespace The cache namespace. | [
"Set",
"the",
"cache",
"driver",
"that",
"will",
"be",
"used",
"."
]
| d12ce93d72f74c099dfd2109371fcd6ddfffdca4 | https://github.com/antarestupin/Accessible/blob/d12ce93d72f74c099dfd2109371fcd6ddfffdca4/lib/Accessible/Configuration.php#L204-L207 |
14,331 | sifophp/sifo-common-instance | classes/HelperPasswordGenerator.php | HelperPasswordGenerator.beNice | public static function beNice( $strength = self::ALL_LOWER_CASE, $lenght = 8, $append_numbers = 2 )
{
$password = '';
$vocals = self::EVEN_CHARS;
$consonants = self::ODD_CHARS;
// Strength 1: Add upper case to vocals.
if ( $strength > 0 )
{
$vocals .= strtoupper( $vocals );
}
// Strength 2: Add upper case to consonants.
if ( $strength > 1 )
{
$consonants .= strtoupper( $consonants );
}
for ( $i = 0; $i < $lenght; $i++ )
{
if ( ( $i % 2 ) > 0 )
{
$password .= $vocals[( rand() % strlen( $vocals ) )];
}
else
{
$password .= $consonants[( rand() % strlen( $consonants ) )];
}
}
// We want the first character to be upper.
$password[0] = strtoupper( $password[0] );
// If specified, we can add a number at the final of the password.
if ( $append_numbers > 0 )
{
$number = 0;
while ( strlen( $number ) < $append_numbers )
{
$number = ( rand() % ( pow( 10, $append_numbers ) - 1 ) );
}
$password .= $number;
}
return $password;
} | php | public static function beNice( $strength = self::ALL_LOWER_CASE, $lenght = 8, $append_numbers = 2 )
{
$password = '';
$vocals = self::EVEN_CHARS;
$consonants = self::ODD_CHARS;
// Strength 1: Add upper case to vocals.
if ( $strength > 0 )
{
$vocals .= strtoupper( $vocals );
}
// Strength 2: Add upper case to consonants.
if ( $strength > 1 )
{
$consonants .= strtoupper( $consonants );
}
for ( $i = 0; $i < $lenght; $i++ )
{
if ( ( $i % 2 ) > 0 )
{
$password .= $vocals[( rand() % strlen( $vocals ) )];
}
else
{
$password .= $consonants[( rand() % strlen( $consonants ) )];
}
}
// We want the first character to be upper.
$password[0] = strtoupper( $password[0] );
// If specified, we can add a number at the final of the password.
if ( $append_numbers > 0 )
{
$number = 0;
while ( strlen( $number ) < $append_numbers )
{
$number = ( rand() % ( pow( 10, $append_numbers ) - 1 ) );
}
$password .= $number;
}
return $password;
} | [
"public",
"static",
"function",
"beNice",
"(",
"$",
"strength",
"=",
"self",
"::",
"ALL_LOWER_CASE",
",",
"$",
"lenght",
"=",
"8",
",",
"$",
"append_numbers",
"=",
"2",
")",
"{",
"$",
"password",
"=",
"''",
";",
"$",
"vocals",
"=",
"self",
"::",
"EVEN_CHARS",
";",
"$",
"consonants",
"=",
"self",
"::",
"ODD_CHARS",
";",
"// Strength 1: Add upper case to vocals.",
"if",
"(",
"$",
"strength",
">",
"0",
")",
"{",
"$",
"vocals",
".=",
"strtoupper",
"(",
"$",
"vocals",
")",
";",
"}",
"// Strength 2: Add upper case to consonants.",
"if",
"(",
"$",
"strength",
">",
"1",
")",
"{",
"$",
"consonants",
".=",
"strtoupper",
"(",
"$",
"consonants",
")",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"lenght",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"(",
"$",
"i",
"%",
"2",
")",
">",
"0",
")",
"{",
"$",
"password",
".=",
"$",
"vocals",
"[",
"(",
"rand",
"(",
")",
"%",
"strlen",
"(",
"$",
"vocals",
")",
")",
"]",
";",
"}",
"else",
"{",
"$",
"password",
".=",
"$",
"consonants",
"[",
"(",
"rand",
"(",
")",
"%",
"strlen",
"(",
"$",
"consonants",
")",
")",
"]",
";",
"}",
"}",
"// We want the first character to be upper.",
"$",
"password",
"[",
"0",
"]",
"=",
"strtoupper",
"(",
"$",
"password",
"[",
"0",
"]",
")",
";",
"// If specified, we can add a number at the final of the password.",
"if",
"(",
"$",
"append_numbers",
">",
"0",
")",
"{",
"$",
"number",
"=",
"0",
";",
"while",
"(",
"strlen",
"(",
"$",
"number",
")",
"<",
"$",
"append_numbers",
")",
"{",
"$",
"number",
"=",
"(",
"rand",
"(",
")",
"%",
"(",
"pow",
"(",
"10",
",",
"$",
"append_numbers",
")",
"-",
"1",
")",
")",
";",
"}",
"$",
"password",
".=",
"$",
"number",
";",
"}",
"return",
"$",
"password",
";",
"}"
]
| Generate a random human readable password.
@param integer $strength Strength of the password.
@param integer $lenght Lenght of the password (excluding the final numbers).
@param integer $append_numbers Lenght of the number to append.
@return unknown | [
"Generate",
"a",
"random",
"human",
"readable",
"password",
"."
]
| 52d54ea3e565bd2bccd77e0b0a6a99b5cae3aff5 | https://github.com/sifophp/sifo-common-instance/blob/52d54ea3e565bd2bccd77e0b0a6a99b5cae3aff5/classes/HelperPasswordGenerator.php#L29-L76 |
14,332 | bariew/yii2-rbac-cms-module | models/AuthItem.php | AuthItem.checkAccess | public static function checkAccess($permissionName, $user = false, $params = [])
{
if (is_array($permissionName)) {
$permissionName = self::createPermissionName($permissionName);
}
if (!$user) {
$user = Yii::$app->user;
}
if (!$user->isGuest && !isset(self::$userRoles[$user->id])) {
self::$userRoles[$user->id] = Yii::$app->authManager->getRolesByUser($user->id);
}
if (isset(self::$userRoles[$user->id][self::ROLE_ROOT])) {
return true;
}
if (!self::$defaultRoles) {
self::setDefaultRoles($user->id);
}
if (in_array($permissionName, self::$defaultRoles)) {
return true;
}
return $user->can($permissionName, $params);
} | php | public static function checkAccess($permissionName, $user = false, $params = [])
{
if (is_array($permissionName)) {
$permissionName = self::createPermissionName($permissionName);
}
if (!$user) {
$user = Yii::$app->user;
}
if (!$user->isGuest && !isset(self::$userRoles[$user->id])) {
self::$userRoles[$user->id] = Yii::$app->authManager->getRolesByUser($user->id);
}
if (isset(self::$userRoles[$user->id][self::ROLE_ROOT])) {
return true;
}
if (!self::$defaultRoles) {
self::setDefaultRoles($user->id);
}
if (in_array($permissionName, self::$defaultRoles)) {
return true;
}
return $user->can($permissionName, $params);
} | [
"public",
"static",
"function",
"checkAccess",
"(",
"$",
"permissionName",
",",
"$",
"user",
"=",
"false",
",",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"permissionName",
")",
")",
"{",
"$",
"permissionName",
"=",
"self",
"::",
"createPermissionName",
"(",
"$",
"permissionName",
")",
";",
"}",
"if",
"(",
"!",
"$",
"user",
")",
"{",
"$",
"user",
"=",
"Yii",
"::",
"$",
"app",
"->",
"user",
";",
"}",
"if",
"(",
"!",
"$",
"user",
"->",
"isGuest",
"&&",
"!",
"isset",
"(",
"self",
"::",
"$",
"userRoles",
"[",
"$",
"user",
"->",
"id",
"]",
")",
")",
"{",
"self",
"::",
"$",
"userRoles",
"[",
"$",
"user",
"->",
"id",
"]",
"=",
"Yii",
"::",
"$",
"app",
"->",
"authManager",
"->",
"getRolesByUser",
"(",
"$",
"user",
"->",
"id",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"userRoles",
"[",
"$",
"user",
"->",
"id",
"]",
"[",
"self",
"::",
"ROLE_ROOT",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"self",
"::",
"$",
"defaultRoles",
")",
"{",
"self",
"::",
"setDefaultRoles",
"(",
"$",
"user",
"->",
"id",
")",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"permissionName",
",",
"self",
"::",
"$",
"defaultRoles",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"$",
"user",
"->",
"can",
"(",
"$",
"permissionName",
",",
"$",
"params",
")",
";",
"}"
]
| Check whether the user has access to permission.
@param mixed $permissionName permission name or its components for self::createPermissionName.
@param mixed $user user
@param array $params
@return boolean whether user has access to permission name. | [
"Check",
"whether",
"the",
"user",
"has",
"access",
"to",
"permission",
"."
]
| c1f0fd05bf6d1951a3fd929d974e6f4cc2b52262 | https://github.com/bariew/yii2-rbac-cms-module/blob/c1f0fd05bf6d1951a3fd929d974e6f4cc2b52262/models/AuthItem.php#L102-L127 |
14,333 | bariew/yii2-rbac-cms-module | models/AuthItem.php | AuthItem.move | public function move($oldParent, $newParent)
{
return $oldParent->removeChild($this)
? $newParent->addChild($this)
: false;
} | php | public function move($oldParent, $newParent)
{
return $oldParent->removeChild($this)
? $newParent->addChild($this)
: false;
} | [
"public",
"function",
"move",
"(",
"$",
"oldParent",
",",
"$",
"newParent",
")",
"{",
"return",
"$",
"oldParent",
"->",
"removeChild",
"(",
"$",
"this",
")",
"?",
"$",
"newParent",
"->",
"addChild",
"(",
"$",
"this",
")",
":",
"false",
";",
"}"
]
| Detaches this model from its old parent
and attaches to the new one.
@param AuthItem $oldParent item
@param AuthItem $newParent item
@return boolean whether model has been moved. | [
"Detaches",
"this",
"model",
"from",
"its",
"old",
"parent",
"and",
"attaches",
"to",
"the",
"new",
"one",
"."
]
| c1f0fd05bf6d1951a3fd929d974e6f4cc2b52262 | https://github.com/bariew/yii2-rbac-cms-module/blob/c1f0fd05bf6d1951a3fd929d974e6f4cc2b52262/models/AuthItem.php#L302-L307 |
14,334 | bariew/yii2-rbac-cms-module | models/AuthItem.php | AuthItem.addChild | public function addChild(AuthItem $item)
{
if ($item->isNewRecord && !$item->save()) {
return false;
}
return Yii::$app->authManager->addChild($this, $item);
} | php | public function addChild(AuthItem $item)
{
if ($item->isNewRecord && !$item->save()) {
return false;
}
return Yii::$app->authManager->addChild($this, $item);
} | [
"public",
"function",
"addChild",
"(",
"AuthItem",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"->",
"isNewRecord",
"&&",
"!",
"$",
"item",
"->",
"save",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"Yii",
"::",
"$",
"app",
"->",
"authManager",
"->",
"addChild",
"(",
"$",
"this",
",",
"$",
"item",
")",
";",
"}"
]
| Attaches child related to this model by AuthItemChild.
@param AuthItem $item child.
@return integer whether child is attached. | [
"Attaches",
"child",
"related",
"to",
"this",
"model",
"by",
"AuthItemChild",
"."
]
| c1f0fd05bf6d1951a3fd929d974e6f4cc2b52262 | https://github.com/bariew/yii2-rbac-cms-module/blob/c1f0fd05bf6d1951a3fd929d974e6f4cc2b52262/models/AuthItem.php#L314-L320 |
14,335 | soloproyectos-php/text-tokenizer | src/text/tokenizer/TextTokenizer.php | TextTokenizer.eq | public function eq($str, $flags = 0)
{
$ret = false;
if (list($str) = $this->match(preg_quote($str, "/"), $matches, $flags)
) {
$ret = array($str);
}
return $ret;
} | php | public function eq($str, $flags = 0)
{
$ret = false;
if (list($str) = $this->match(preg_quote($str, "/"), $matches, $flags)
) {
$ret = array($str);
}
return $ret;
} | [
"public",
"function",
"eq",
"(",
"$",
"str",
",",
"$",
"flags",
"=",
"0",
")",
"{",
"$",
"ret",
"=",
"false",
";",
"if",
"(",
"list",
"(",
"$",
"str",
")",
"=",
"$",
"this",
"->",
"match",
"(",
"preg_quote",
"(",
"$",
"str",
",",
"\"/\"",
")",
",",
"$",
"matches",
",",
"$",
"flags",
")",
")",
"{",
"$",
"ret",
"=",
"array",
"(",
"$",
"str",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
]
| Is the next token equal to a given string?
This function returns false if the next token is not equal to a given string
or an array with a single string.
@param string $str A string
@param integer $flags Flags (default is 0)
@return false|array of a single string | [
"Is",
"the",
"next",
"token",
"equal",
"to",
"a",
"given",
"string?"
]
| 792b463ad8790fa19a7120d1354ee852fc70c017 | https://github.com/soloproyectos-php/text-tokenizer/blob/792b463ad8790fa19a7120d1354ee852fc70c017/src/text/tokenizer/TextTokenizer.php#L146-L156 |
14,336 | soloproyectos-php/text-tokenizer | src/text/tokenizer/TextTokenizer.php | TextTokenizer.in | public function in($items, $flags = 0)
{
$ret = false;
// sorts the items in descending order according to their length
usort(
$items,
function ($item1, $item2) {
return strlen($item1) < strlen($item2);
}
);
foreach ($items as $item) {
if ($this->eq($item, $flags)) {
$ret = array($item);
break;
}
}
return $ret;
} | php | public function in($items, $flags = 0)
{
$ret = false;
// sorts the items in descending order according to their length
usort(
$items,
function ($item1, $item2) {
return strlen($item1) < strlen($item2);
}
);
foreach ($items as $item) {
if ($this->eq($item, $flags)) {
$ret = array($item);
break;
}
}
return $ret;
} | [
"public",
"function",
"in",
"(",
"$",
"items",
",",
"$",
"flags",
"=",
"0",
")",
"{",
"$",
"ret",
"=",
"false",
";",
"// sorts the items in descending order according to their length",
"usort",
"(",
"$",
"items",
",",
"function",
"(",
"$",
"item1",
",",
"$",
"item2",
")",
"{",
"return",
"strlen",
"(",
"$",
"item1",
")",
"<",
"strlen",
"(",
"$",
"item2",
")",
";",
"}",
")",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"eq",
"(",
"$",
"item",
",",
"$",
"flags",
")",
")",
"{",
"$",
"ret",
"=",
"array",
"(",
"$",
"item",
")",
";",
"break",
";",
"}",
"}",
"return",
"$",
"ret",
";",
"}"
]
| Is the next token the in a given list?
This function returns false if the next token is not in a given list
or an array with a single string.
@param array $items An array of strings
@param integer $flags Flags (default is 0)
@return false|array of a single string | [
"Is",
"the",
"next",
"token",
"the",
"in",
"a",
"given",
"list?"
]
| 792b463ad8790fa19a7120d1354ee852fc70c017 | https://github.com/soloproyectos-php/text-tokenizer/blob/792b463ad8790fa19a7120d1354ee852fc70c017/src/text/tokenizer/TextTokenizer.php#L169-L189 |
14,337 | soloproyectos-php/text-tokenizer | src/text/tokenizer/TextTokenizer.php | TextTokenizer.number | public function number($flags = 0)
{
$ret = false;
if ($number = $this->match(TextTokenizer::NUMBER, $matches, $flags)) {
$ret = $number;
}
return $ret;
} | php | public function number($flags = 0)
{
$ret = false;
if ($number = $this->match(TextTokenizer::NUMBER, $matches, $flags)) {
$ret = $number;
}
return $ret;
} | [
"public",
"function",
"number",
"(",
"$",
"flags",
"=",
"0",
")",
"{",
"$",
"ret",
"=",
"false",
";",
"if",
"(",
"$",
"number",
"=",
"$",
"this",
"->",
"match",
"(",
"TextTokenizer",
"::",
"NUMBER",
",",
"$",
"matches",
",",
"$",
"flags",
")",
")",
"{",
"$",
"ret",
"=",
"$",
"number",
";",
"}",
"return",
"$",
"ret",
";",
"}"
]
| Is the next token a number?
This function returns false if the next token is not a number or an array
with a single string.
@param integer $flags Flags (default is 0)
@return false|array of a single string | [
"Is",
"the",
"next",
"token",
"a",
"number?"
]
| 792b463ad8790fa19a7120d1354ee852fc70c017 | https://github.com/soloproyectos-php/text-tokenizer/blob/792b463ad8790fa19a7120d1354ee852fc70c017/src/text/tokenizer/TextTokenizer.php#L201-L210 |
14,338 | soloproyectos-php/text-tokenizer | src/text/tokenizer/TextTokenizer.php | TextTokenizer.str | public function str($flags = 0)
{
$ret = false;
if ($this->match(TextTokenizer::STRING, $matches, $flags)) {
$delimiter = $matches[2];
$str = $matches[3];
$str = str_replace("\\$delimiter", "$delimiter", $str);
$ret = array($str);
}
return $ret;
} | php | public function str($flags = 0)
{
$ret = false;
if ($this->match(TextTokenizer::STRING, $matches, $flags)) {
$delimiter = $matches[2];
$str = $matches[3];
$str = str_replace("\\$delimiter", "$delimiter", $str);
$ret = array($str);
}
return $ret;
} | [
"public",
"function",
"str",
"(",
"$",
"flags",
"=",
"0",
")",
"{",
"$",
"ret",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"match",
"(",
"TextTokenizer",
"::",
"STRING",
",",
"$",
"matches",
",",
"$",
"flags",
")",
")",
"{",
"$",
"delimiter",
"=",
"$",
"matches",
"[",
"2",
"]",
";",
"$",
"str",
"=",
"$",
"matches",
"[",
"3",
"]",
";",
"$",
"str",
"=",
"str_replace",
"(",
"\"\\\\$delimiter\"",
",",
"\"$delimiter\"",
",",
"$",
"str",
")",
";",
"$",
"ret",
"=",
"array",
"(",
"$",
"str",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
]
| Is the next token a string?
This function returns false if the next token is not a string or an array
with a single string.
@param integer $flags Flags (default is 0)
@return false|array of a single string | [
"Is",
"the",
"next",
"token",
"a",
"string?"
]
| 792b463ad8790fa19a7120d1354ee852fc70c017 | https://github.com/soloproyectos-php/text-tokenizer/blob/792b463ad8790fa19a7120d1354ee852fc70c017/src/text/tokenizer/TextTokenizer.php#L222-L234 |
14,339 | soloproyectos-php/text-tokenizer | src/text/tokenizer/TextTokenizer.php | TextTokenizer.id | public function id()
{
$ret = false;
if (list($id) = $this->match(TextTokenizer::IDENTIFIER)) {
$ret = array($id);
}
return $ret;
} | php | public function id()
{
$ret = false;
if (list($id) = $this->match(TextTokenizer::IDENTIFIER)) {
$ret = array($id);
}
return $ret;
} | [
"public",
"function",
"id",
"(",
")",
"{",
"$",
"ret",
"=",
"false",
";",
"if",
"(",
"list",
"(",
"$",
"id",
")",
"=",
"$",
"this",
"->",
"match",
"(",
"TextTokenizer",
"::",
"IDENTIFIER",
")",
")",
"{",
"$",
"ret",
"=",
"array",
"(",
"$",
"id",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
]
| Is the next token an identifier?
This function returns false if the next token is not an identifier or an
array with a single string.
@return false|array of a single string | [
"Is",
"the",
"next",
"token",
"an",
"identifier?"
]
| 792b463ad8790fa19a7120d1354ee852fc70c017 | https://github.com/soloproyectos-php/text-tokenizer/blob/792b463ad8790fa19a7120d1354ee852fc70c017/src/text/tokenizer/TextTokenizer.php#L272-L281 |
14,340 | soloproyectos-php/text-tokenizer | src/text/tokenizer/TextTokenizer.php | TextTokenizer.match | public function match($regexp, &$matches = array(), $flags = 0)
{
// we do not like empty strings
if (strlen($regexp) == 0) {
return false;
}
$ret = false;
$explicitRegexp = strlen($regexp) > 0 && $regexp[0] == "/";
$substr = substr($this->string, $this->offset);
if (!$explicitRegexp) {
$caseSensitive = TextTokenizer::CASE_SENSITIVE
& ($this->_flags | $flags);
$searchAnywhere = TextTokenizer::SEARCH_ANYWHERE
& ($this->_flags | $flags);
$modifiers = "us" . ($caseSensitive? "" : "i");
$regexp = $searchAnywhere
? "/($regexp)/$modifiers"
: "/^\s*($regexp)/$modifiers";
}
if (preg_match($regexp, $substr, $matches, PREG_OFFSET_CAPTURE)) {
$offsetCapture = TextTokenizer::OFFSET_CAPTURE
& ($this->_flags | $flags);
$str = $matches[0][0];
$offset = $matches[0][1] + strlen($str);
if ($offsetCapture) {
// fixes offsets
foreach ($matches as $i => $match) {
$matches[$i][1] += $this->offset;
}
} else {
// ignores offsets
foreach ($matches as $i => $match) {
$matches[$i] = $matches[$i][0];
}
}
if (!ctype_alnum($substr[$offset - 1])
|| $offset == strlen($substr)
|| !ctype_alnum($substr[$offset])
) {
$this->offset += $offset;
$ret = array(ltrim($str));
}
}
return $ret;
} | php | public function match($regexp, &$matches = array(), $flags = 0)
{
// we do not like empty strings
if (strlen($regexp) == 0) {
return false;
}
$ret = false;
$explicitRegexp = strlen($regexp) > 0 && $regexp[0] == "/";
$substr = substr($this->string, $this->offset);
if (!$explicitRegexp) {
$caseSensitive = TextTokenizer::CASE_SENSITIVE
& ($this->_flags | $flags);
$searchAnywhere = TextTokenizer::SEARCH_ANYWHERE
& ($this->_flags | $flags);
$modifiers = "us" . ($caseSensitive? "" : "i");
$regexp = $searchAnywhere
? "/($regexp)/$modifiers"
: "/^\s*($regexp)/$modifiers";
}
if (preg_match($regexp, $substr, $matches, PREG_OFFSET_CAPTURE)) {
$offsetCapture = TextTokenizer::OFFSET_CAPTURE
& ($this->_flags | $flags);
$str = $matches[0][0];
$offset = $matches[0][1] + strlen($str);
if ($offsetCapture) {
// fixes offsets
foreach ($matches as $i => $match) {
$matches[$i][1] += $this->offset;
}
} else {
// ignores offsets
foreach ($matches as $i => $match) {
$matches[$i] = $matches[$i][0];
}
}
if (!ctype_alnum($substr[$offset - 1])
|| $offset == strlen($substr)
|| !ctype_alnum($substr[$offset])
) {
$this->offset += $offset;
$ret = array(ltrim($str));
}
}
return $ret;
} | [
"public",
"function",
"match",
"(",
"$",
"regexp",
",",
"&",
"$",
"matches",
"=",
"array",
"(",
")",
",",
"$",
"flags",
"=",
"0",
")",
"{",
"// we do not like empty strings",
"if",
"(",
"strlen",
"(",
"$",
"regexp",
")",
"==",
"0",
")",
"{",
"return",
"false",
";",
"}",
"$",
"ret",
"=",
"false",
";",
"$",
"explicitRegexp",
"=",
"strlen",
"(",
"$",
"regexp",
")",
">",
"0",
"&&",
"$",
"regexp",
"[",
"0",
"]",
"==",
"\"/\"",
";",
"$",
"substr",
"=",
"substr",
"(",
"$",
"this",
"->",
"string",
",",
"$",
"this",
"->",
"offset",
")",
";",
"if",
"(",
"!",
"$",
"explicitRegexp",
")",
"{",
"$",
"caseSensitive",
"=",
"TextTokenizer",
"::",
"CASE_SENSITIVE",
"&",
"(",
"$",
"this",
"->",
"_flags",
"|",
"$",
"flags",
")",
";",
"$",
"searchAnywhere",
"=",
"TextTokenizer",
"::",
"SEARCH_ANYWHERE",
"&",
"(",
"$",
"this",
"->",
"_flags",
"|",
"$",
"flags",
")",
";",
"$",
"modifiers",
"=",
"\"us\"",
".",
"(",
"$",
"caseSensitive",
"?",
"\"\"",
":",
"\"i\"",
")",
";",
"$",
"regexp",
"=",
"$",
"searchAnywhere",
"?",
"\"/($regexp)/$modifiers\"",
":",
"\"/^\\s*($regexp)/$modifiers\"",
";",
"}",
"if",
"(",
"preg_match",
"(",
"$",
"regexp",
",",
"$",
"substr",
",",
"$",
"matches",
",",
"PREG_OFFSET_CAPTURE",
")",
")",
"{",
"$",
"offsetCapture",
"=",
"TextTokenizer",
"::",
"OFFSET_CAPTURE",
"&",
"(",
"$",
"this",
"->",
"_flags",
"|",
"$",
"flags",
")",
";",
"$",
"str",
"=",
"$",
"matches",
"[",
"0",
"]",
"[",
"0",
"]",
";",
"$",
"offset",
"=",
"$",
"matches",
"[",
"0",
"]",
"[",
"1",
"]",
"+",
"strlen",
"(",
"$",
"str",
")",
";",
"if",
"(",
"$",
"offsetCapture",
")",
"{",
"// fixes offsets",
"foreach",
"(",
"$",
"matches",
"as",
"$",
"i",
"=>",
"$",
"match",
")",
"{",
"$",
"matches",
"[",
"$",
"i",
"]",
"[",
"1",
"]",
"+=",
"$",
"this",
"->",
"offset",
";",
"}",
"}",
"else",
"{",
"// ignores offsets",
"foreach",
"(",
"$",
"matches",
"as",
"$",
"i",
"=>",
"$",
"match",
")",
"{",
"$",
"matches",
"[",
"$",
"i",
"]",
"=",
"$",
"matches",
"[",
"$",
"i",
"]",
"[",
"0",
"]",
";",
"}",
"}",
"if",
"(",
"!",
"ctype_alnum",
"(",
"$",
"substr",
"[",
"$",
"offset",
"-",
"1",
"]",
")",
"||",
"$",
"offset",
"==",
"strlen",
"(",
"$",
"substr",
")",
"||",
"!",
"ctype_alnum",
"(",
"$",
"substr",
"[",
"$",
"offset",
"]",
")",
")",
"{",
"$",
"this",
"->",
"offset",
"+=",
"$",
"offset",
";",
"$",
"ret",
"=",
"array",
"(",
"ltrim",
"(",
"$",
"str",
")",
")",
";",
"}",
"}",
"return",
"$",
"ret",
";",
"}"
]
| Matches the string against a regex.
This function matches the string against a regular expressión. If they
match, it advances the offset position and returns an array with a single
string. Otherwise, it returns false. You can use regex without delimiters.
Instead of using /^\s*(\w+)/, you can use simply '\w+'.
Example 1:
```php
// these two lines are identical
if ($t->match("\w+")) doSomething();
if ($t->match("/^\s*(\w+)/")) doSomething();
```
Example 2:
```php
// splits a string into "words"
$t = new TextTokenizer("Lorem ipsum dolor sit amet");
while (list($token) = $t->match("\w+", $matches)) {
echo "$token-";
}
```
Example 3:
```php
// captures the offset
$t = new TextTokenizer("I am 105 years old");
if ($t->match("/\d+/", $matches, TextTokenizer::OFFSET_CAPTURE)) {
print_r($matches);
}
```
Example 4:
```php
// parses a basic SQL sentence
$t = new TextTokenizer("Select Id, Name, Age From users Where Id = 101");
if ($t->match("select")) {
// columns
$columns = array();
while (list($column) = $t->match("\w+")) {
array_push($columns, $column);
if (!$t->match(",")) {
break;
}
}
// `from` clause
if ($t->match("from\s+(\w+)", $matches)) {
$tableName = $matches[1];
echo "You want to get the columns " . implode(", ", $columns) .
" from the table $tableName.";
}
}
```
@param string $regexp Regular expression
@param array $matches Matches (default is array(), passed by reference)
@param integer $flags Flags (default is 0)
@return false|array of a single string | [
"Matches",
"the",
"string",
"against",
"a",
"regex",
"."
]
| 792b463ad8790fa19a7120d1354ee852fc70c017 | https://github.com/soloproyectos-php/text-tokenizer/blob/792b463ad8790fa19a7120d1354ee852fc70c017/src/text/tokenizer/TextTokenizer.php#L344-L394 |
14,341 | chippyash/Strong-Type | src/Chippyash/Type/Number/Complex/GMPComplexType.php | GMPComplexType.isZero | public function isZero()
{
return (
gmp_sign($this->value['real']->numerator()->gmp()) == 0
&& gmp_sign($this->value['imaginary']->numerator()->gmp()) == 0
);
} | php | public function isZero()
{
return (
gmp_sign($this->value['real']->numerator()->gmp()) == 0
&& gmp_sign($this->value['imaginary']->numerator()->gmp()) == 0
);
} | [
"public",
"function",
"isZero",
"(",
")",
"{",
"return",
"(",
"gmp_sign",
"(",
"$",
"this",
"->",
"value",
"[",
"'real'",
"]",
"->",
"numerator",
"(",
")",
"->",
"gmp",
"(",
")",
")",
"==",
"0",
"&&",
"gmp_sign",
"(",
"$",
"this",
"->",
"value",
"[",
"'imaginary'",
"]",
"->",
"numerator",
"(",
")",
"->",
"gmp",
"(",
")",
")",
"==",
"0",
")",
";",
"}"
]
| Is this number equal to zero?
@return boolean | [
"Is",
"this",
"number",
"equal",
"to",
"zero?"
]
| 9d364c10c68c10f768254fb25b0b1db3dbef6fa9 | https://github.com/chippyash/Strong-Type/blob/9d364c10c68c10f768254fb25b0b1db3dbef6fa9/src/Chippyash/Type/Number/Complex/GMPComplexType.php#L67-L73 |
14,342 | ganlvtech/php-simple-cas | src/PhpCas.php | PhpCas.forceAuthentication | public function forceAuthentication()
{
if (self::isAuthenticated()) {
return true;
} elseif ($this->getTicket()) {
return $this->validateCas();
}
session_write_close();
$this->redirectToCas();
// never reached
return true;
} | php | public function forceAuthentication()
{
if (self::isAuthenticated()) {
return true;
} elseif ($this->getTicket()) {
return $this->validateCas();
}
session_write_close();
$this->redirectToCas();
// never reached
return true;
} | [
"public",
"function",
"forceAuthentication",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"isAuthenticated",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"getTicket",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"validateCas",
"(",
")",
";",
"}",
"session_write_close",
"(",
")",
";",
"$",
"this",
"->",
"redirectToCas",
"(",
")",
";",
"// never reached",
"return",
"true",
";",
"}"
]
| If not authenticated, redirect to CAS.
If authenticated, return true.
@return bool always true. | [
"If",
"not",
"authenticated",
"redirect",
"to",
"CAS",
".",
"If",
"authenticated",
"return",
"true",
"."
]
| 21ce1e0988f14136536ff705a1b39e3603ea4a5c | https://github.com/ganlvtech/php-simple-cas/blob/21ce1e0988f14136536ff705a1b39e3603ea4a5c/src/PhpCas.php#L79-L90 |
14,343 | ganlvtech/php-simple-cas | src/PhpCas.php | PhpCas.checkAuthentication | public function checkAuthentication()
{
if (self::isAuthenticated()) {
return true;
} elseif (self::isGatewayed()) {
return $this->validateCas();
}
self::setGatewayed(true);
session_write_close();
$this->redirectToCas(true);
// never reached
return true;
} | php | public function checkAuthentication()
{
if (self::isAuthenticated()) {
return true;
} elseif (self::isGatewayed()) {
return $this->validateCas();
}
self::setGatewayed(true);
session_write_close();
$this->redirectToCas(true);
// never reached
return true;
} | [
"public",
"function",
"checkAuthentication",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"isAuthenticated",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"elseif",
"(",
"self",
"::",
"isGatewayed",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"validateCas",
"(",
")",
";",
"}",
"self",
"::",
"setGatewayed",
"(",
"true",
")",
";",
"session_write_close",
"(",
")",
";",
"$",
"this",
"->",
"redirectToCas",
"(",
"true",
")",
";",
"// never reached",
"return",
"true",
";",
"}"
]
| If not gatewayed, redirect to CAS with gateway=true.
@return bool true - authenticated. false - guess mode. | [
"If",
"not",
"gatewayed",
"redirect",
"to",
"CAS",
"with",
"gateway",
"=",
"true",
"."
]
| 21ce1e0988f14136536ff705a1b39e3603ea4a5c | https://github.com/ganlvtech/php-simple-cas/blob/21ce1e0988f14136536ff705a1b39e3603ea4a5c/src/PhpCas.php#L97-L109 |
14,344 | ganlvtech/php-simple-cas | src/PhpCas.php | PhpCas.redirectToCas | protected function redirectToCas($gateway = false)
{
$query['service'] = self::getDefaultService();
if ($gateway) {
$query['gateway'] = 'true';
}
self::http_redirect($this->server['login_url'] . '?' . http_build_query($query));
// never reached
return true;
} | php | protected function redirectToCas($gateway = false)
{
$query['service'] = self::getDefaultService();
if ($gateway) {
$query['gateway'] = 'true';
}
self::http_redirect($this->server['login_url'] . '?' . http_build_query($query));
// never reached
return true;
} | [
"protected",
"function",
"redirectToCas",
"(",
"$",
"gateway",
"=",
"false",
")",
"{",
"$",
"query",
"[",
"'service'",
"]",
"=",
"self",
"::",
"getDefaultService",
"(",
")",
";",
"if",
"(",
"$",
"gateway",
")",
"{",
"$",
"query",
"[",
"'gateway'",
"]",
"=",
"'true'",
";",
"}",
"self",
"::",
"http_redirect",
"(",
"$",
"this",
"->",
"server",
"[",
"'login_url'",
"]",
".",
"'?'",
".",
"http_build_query",
"(",
"$",
"query",
")",
")",
";",
"// never reached",
"return",
"true",
";",
"}"
]
| Redirect to CAS server for login
@param bool $gateway
@return bool always true, but never reach. | [
"Redirect",
"to",
"CAS",
"server",
"for",
"login"
]
| 21ce1e0988f14136536ff705a1b39e3603ea4a5c | https://github.com/ganlvtech/php-simple-cas/blob/21ce1e0988f14136536ff705a1b39e3603ea4a5c/src/PhpCas.php#L166-L175 |
14,345 | ganlvtech/php-simple-cas | src/PhpCas.php | PhpCas.getDefaultService | protected static function getDefaultService()
{
$service = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$parts = parse_url($service);
if (isset($parts['query'])) {
parse_str($parts['query'], $query);
} else {
$query = array();
}
unset($query['ticket']);
$parts['query'] = http_build_query($query);
return self::build_url($parts);
} | php | protected static function getDefaultService()
{
$service = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$parts = parse_url($service);
if (isset($parts['query'])) {
parse_str($parts['query'], $query);
} else {
$query = array();
}
unset($query['ticket']);
$parts['query'] = http_build_query($query);
return self::build_url($parts);
} | [
"protected",
"static",
"function",
"getDefaultService",
"(",
")",
"{",
"$",
"service",
"=",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTPS'",
"]",
")",
"?",
"'https'",
":",
"'http'",
")",
".",
"'://'",
".",
"$",
"_SERVER",
"[",
"'SERVER_NAME'",
"]",
".",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
";",
"$",
"parts",
"=",
"parse_url",
"(",
"$",
"service",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"parts",
"[",
"'query'",
"]",
")",
")",
"{",
"parse_str",
"(",
"$",
"parts",
"[",
"'query'",
"]",
",",
"$",
"query",
")",
";",
"}",
"else",
"{",
"$",
"query",
"=",
"array",
"(",
")",
";",
"}",
"unset",
"(",
"$",
"query",
"[",
"'ticket'",
"]",
")",
";",
"$",
"parts",
"[",
"'query'",
"]",
"=",
"http_build_query",
"(",
"$",
"query",
")",
";",
"return",
"self",
"::",
"build_url",
"(",
"$",
"parts",
")",
";",
"}"
]
| Get the service name of this request
@return string default service name | [
"Get",
"the",
"service",
"name",
"of",
"this",
"request"
]
| 21ce1e0988f14136536ff705a1b39e3603ea4a5c | https://github.com/ganlvtech/php-simple-cas/blob/21ce1e0988f14136536ff705a1b39e3603ea4a5c/src/PhpCas.php#L287-L301 |
14,346 | keboola/juicer | Pagination/Decorator/ForceStopScrollerDecorator.php | ForceStopScrollerDecorator.checkPages | private function checkPages()
{
if (is_null($this->pageLimit)) {
return false;
}
if (++$this->pageCounter > $this->pageLimit) {
return true;
}
return false;
} | php | private function checkPages()
{
if (is_null($this->pageLimit)) {
return false;
}
if (++$this->pageCounter > $this->pageLimit) {
return true;
}
return false;
} | [
"private",
"function",
"checkPages",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"pageLimit",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"++",
"$",
"this",
"->",
"pageCounter",
">",
"$",
"this",
"->",
"pageLimit",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| Uses internal counter to check page limit
@return bool | [
"Uses",
"internal",
"counter",
"to",
"check",
"page",
"limit"
]
| 780e7900ccd23082ed234cc2c51b279a4223e9f5 | https://github.com/keboola/juicer/blob/780e7900ccd23082ed234cc2c51b279a4223e9f5/Pagination/Decorator/ForceStopScrollerDecorator.php#L118-L128 |
14,347 | keboola/juicer | Pagination/Decorator/ForceStopScrollerDecorator.php | ForceStopScrollerDecorator.checkTime | private function checkTime()
{
if (is_null($this->timeLimit)) {
return false;
}
if (($this->startTime + $this->timeLimit) <= time()) {
return true;
}
return false;
} | php | private function checkTime()
{
if (is_null($this->timeLimit)) {
return false;
}
if (($this->startTime + $this->timeLimit) <= time()) {
return true;
}
return false;
} | [
"private",
"function",
"checkTime",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"timeLimit",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"(",
"$",
"this",
"->",
"startTime",
"+",
"$",
"this",
"->",
"timeLimit",
")",
"<=",
"time",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| Checks time between first and current request
@return bool | [
"Checks",
"time",
"between",
"first",
"and",
"current",
"request"
]
| 780e7900ccd23082ed234cc2c51b279a4223e9f5 | https://github.com/keboola/juicer/blob/780e7900ccd23082ed234cc2c51b279a4223e9f5/Pagination/Decorator/ForceStopScrollerDecorator.php#L134-L144 |
14,348 | nyeholt/silverstripe-simplewiki | thirdparty/htmlpurifier-4.0.0-lite/library/HTMLPurifier/ConfigSchema.php | HTMLPurifier_ConfigSchema.add | public function add($key, $default, $type, $allow_null) {
$obj = new stdclass();
$obj->type = is_int($type) ? $type : HTMLPurifier_VarParser::$types[$type];
if ($allow_null) $obj->allow_null = true;
$this->info[$key] = $obj;
$this->defaults[$key] = $default;
$this->defaultPlist->set($key, $default);
} | php | public function add($key, $default, $type, $allow_null) {
$obj = new stdclass();
$obj->type = is_int($type) ? $type : HTMLPurifier_VarParser::$types[$type];
if ($allow_null) $obj->allow_null = true;
$this->info[$key] = $obj;
$this->defaults[$key] = $default;
$this->defaultPlist->set($key, $default);
} | [
"public",
"function",
"add",
"(",
"$",
"key",
",",
"$",
"default",
",",
"$",
"type",
",",
"$",
"allow_null",
")",
"{",
"$",
"obj",
"=",
"new",
"stdclass",
"(",
")",
";",
"$",
"obj",
"->",
"type",
"=",
"is_int",
"(",
"$",
"type",
")",
"?",
"$",
"type",
":",
"HTMLPurifier_VarParser",
"::",
"$",
"types",
"[",
"$",
"type",
"]",
";",
"if",
"(",
"$",
"allow_null",
")",
"$",
"obj",
"->",
"allow_null",
"=",
"true",
";",
"$",
"this",
"->",
"info",
"[",
"$",
"key",
"]",
"=",
"$",
"obj",
";",
"$",
"this",
"->",
"defaults",
"[",
"$",
"key",
"]",
"=",
"$",
"default",
";",
"$",
"this",
"->",
"defaultPlist",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"default",
")",
";",
"}"
]
| Defines a directive for configuration
@warning Will fail of directive's namespace is defined.
@warning This method's signature is slightly different from the legacy
define() static method! Beware!
@param $namespace Namespace the directive is in
@param $name Key of directive
@param $default Default value of directive
@param $type Allowed type of the directive. See
HTMLPurifier_DirectiveDef::$type for allowed values
@param $allow_null Whether or not to allow null values | [
"Defines",
"a",
"directive",
"for",
"configuration"
]
| ecffed0d75be1454901e1cb24633472b8f67c967 | https://github.com/nyeholt/silverstripe-simplewiki/blob/ecffed0d75be1454901e1cb24633472b8f67c967/thirdparty/htmlpurifier-4.0.0-lite/library/HTMLPurifier/ConfigSchema.php#L90-L97 |
14,349 | venta/framework | src/Console/src/ConsoleApplication.php | ConsoleApplication.run | public function run(InputInterface $input, OutputInterface $output): int
{
return $this->console->run($input, $output);
} | php | public function run(InputInterface $input, OutputInterface $output): int
{
return $this->console->run($input, $output);
} | [
"public",
"function",
"run",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
":",
"int",
"{",
"return",
"$",
"this",
"->",
"console",
"->",
"run",
"(",
"$",
"input",
",",
"$",
"output",
")",
";",
"}"
]
| Runs Console Application.
@param InputInterface $input
@param OutputInterface $output
@return int | [
"Runs",
"Console",
"Application",
"."
]
| 514a7854cc69f84f47e62a58cc55efd68b7c9f83 | https://github.com/venta/framework/blob/514a7854cc69f84f47e62a58cc55efd68b7c9f83/src/Console/src/ConsoleApplication.php#L47-L50 |
14,350 | venta/framework | src/Console/src/ConsoleApplication.php | ConsoleApplication.initConsole | private function initConsole(string $name, string $version)
{
$this->console = $this->container->get(SymfonyConsoleApplication::class);
$this->console->setName($name);
$this->console->setVersion($version);
$this->console->setCatchExceptions(false);
$this->console->setAutoExit(false);
/** @var CommandCollectionContract $commands */
$commands = $this->container->get(CommandCollectionContract::class);
foreach ($commands as $command) {
$this->console->add($this->resolveCommand($command));
}
} | php | private function initConsole(string $name, string $version)
{
$this->console = $this->container->get(SymfonyConsoleApplication::class);
$this->console->setName($name);
$this->console->setVersion($version);
$this->console->setCatchExceptions(false);
$this->console->setAutoExit(false);
/** @var CommandCollectionContract $commands */
$commands = $this->container->get(CommandCollectionContract::class);
foreach ($commands as $command) {
$this->console->add($this->resolveCommand($command));
}
} | [
"private",
"function",
"initConsole",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"version",
")",
"{",
"$",
"this",
"->",
"console",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"SymfonyConsoleApplication",
"::",
"class",
")",
";",
"$",
"this",
"->",
"console",
"->",
"setName",
"(",
"$",
"name",
")",
";",
"$",
"this",
"->",
"console",
"->",
"setVersion",
"(",
"$",
"version",
")",
";",
"$",
"this",
"->",
"console",
"->",
"setCatchExceptions",
"(",
"false",
")",
";",
"$",
"this",
"->",
"console",
"->",
"setAutoExit",
"(",
"false",
")",
";",
"/** @var CommandCollectionContract $commands */",
"$",
"commands",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"CommandCollectionContract",
"::",
"class",
")",
";",
"foreach",
"(",
"$",
"commands",
"as",
"$",
"command",
")",
"{",
"$",
"this",
"->",
"console",
"->",
"add",
"(",
"$",
"this",
"->",
"resolveCommand",
"(",
"$",
"command",
")",
")",
";",
"}",
"}"
]
| Initiates Symfony Console Application.
@param string $name
@param string $version | [
"Initiates",
"Symfony",
"Console",
"Application",
"."
]
| 514a7854cc69f84f47e62a58cc55efd68b7c9f83 | https://github.com/venta/framework/blob/514a7854cc69f84f47e62a58cc55efd68b7c9f83/src/Console/src/ConsoleApplication.php#L58-L71 |
14,351 | mimmi20/Wurfl | src/Device/CustomDeviceRepository.php | CustomDeviceRepository.getAllDevices | public function getAllDevices()
{
$devices = array();
$devicesId = $this->getAllDevicesID();
foreach ($devicesId as $deviceId) {
/** @var $device \Wurfl\Device\ModelDeviceInterface */
$device = $this->getDevice($deviceId);
$devices[] = $device;
}
return $devices;
} | php | public function getAllDevices()
{
$devices = array();
$devicesId = $this->getAllDevicesID();
foreach ($devicesId as $deviceId) {
/** @var $device \Wurfl\Device\ModelDeviceInterface */
$device = $this->getDevice($deviceId);
$devices[] = $device;
}
return $devices;
} | [
"public",
"function",
"getAllDevices",
"(",
")",
"{",
"$",
"devices",
"=",
"array",
"(",
")",
";",
"$",
"devicesId",
"=",
"$",
"this",
"->",
"getAllDevicesID",
"(",
")",
";",
"foreach",
"(",
"$",
"devicesId",
"as",
"$",
"deviceId",
")",
"{",
"/** @var $device \\Wurfl\\Device\\ModelDeviceInterface */",
"$",
"device",
"=",
"$",
"this",
"->",
"getDevice",
"(",
"$",
"deviceId",
")",
";",
"$",
"devices",
"[",
"]",
"=",
"$",
"device",
";",
"}",
"return",
"$",
"devices",
";",
"}"
]
| Returns all devices in the repository
@throws \Wurfl\Exception
@return \Wurfl\Device\ModelDeviceInterface[] | [
"Returns",
"all",
"devices",
"in",
"the",
"repository"
]
| 443ed0d73a0b9a21ebd0d6ddf1e32669b9de44ec | https://github.com/mimmi20/Wurfl/blob/443ed0d73a0b9a21ebd0d6ddf1e32669b9de44ec/src/Device/CustomDeviceRepository.php#L163-L175 |
14,352 | FWidm/dwd-hourly-crawler | src/fwidm/dwdHourlyCrawler/hourly/DWDStationsController.php | DWDStationsController.getNearestStation | public static function getNearestStation($stations, $coordinatesRequest)
{
$calculator = new Vincenty();
$nearestStation = null;
$nextDist = INF;
foreach ($stations as $activeStation) {
if (is_object($activeStation) && $activeStation instanceof DWDStation) {
$coordinatesStation = new Coordinate($activeStation->getLatitude(), $activeStation->getLongitude());
$diff = $calculator->getDistance($coordinatesRequest, $coordinatesStation);
if ($diff < $nextDist) {
$nearestStation = $activeStation;
$nextDist = $diff;
}
} else
throw new DWDLibException("Stations parameter does contain an object that is no instance of DWDStation");
}
return $nearestStation;
} | php | public static function getNearestStation($stations, $coordinatesRequest)
{
$calculator = new Vincenty();
$nearestStation = null;
$nextDist = INF;
foreach ($stations as $activeStation) {
if (is_object($activeStation) && $activeStation instanceof DWDStation) {
$coordinatesStation = new Coordinate($activeStation->getLatitude(), $activeStation->getLongitude());
$diff = $calculator->getDistance($coordinatesRequest, $coordinatesStation);
if ($diff < $nextDist) {
$nearestStation = $activeStation;
$nextDist = $diff;
}
} else
throw new DWDLibException("Stations parameter does contain an object that is no instance of DWDStation");
}
return $nearestStation;
} | [
"public",
"static",
"function",
"getNearestStation",
"(",
"$",
"stations",
",",
"$",
"coordinatesRequest",
")",
"{",
"$",
"calculator",
"=",
"new",
"Vincenty",
"(",
")",
";",
"$",
"nearestStation",
"=",
"null",
";",
"$",
"nextDist",
"=",
"INF",
";",
"foreach",
"(",
"$",
"stations",
"as",
"$",
"activeStation",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"activeStation",
")",
"&&",
"$",
"activeStation",
"instanceof",
"DWDStation",
")",
"{",
"$",
"coordinatesStation",
"=",
"new",
"Coordinate",
"(",
"$",
"activeStation",
"->",
"getLatitude",
"(",
")",
",",
"$",
"activeStation",
"->",
"getLongitude",
"(",
")",
")",
";",
"$",
"diff",
"=",
"$",
"calculator",
"->",
"getDistance",
"(",
"$",
"coordinatesRequest",
",",
"$",
"coordinatesStation",
")",
";",
"if",
"(",
"$",
"diff",
"<",
"$",
"nextDist",
")",
"{",
"$",
"nearestStation",
"=",
"$",
"activeStation",
";",
"$",
"nextDist",
"=",
"$",
"diff",
";",
"}",
"}",
"else",
"throw",
"new",
"DWDLibException",
"(",
"\"Stations parameter does contain an object that is no instance of DWDStation\"",
")",
";",
"}",
"return",
"$",
"nearestStation",
";",
"}"
]
| Return the nearest stations from a stations array.
@param $stations - array of DWDStation
@param $coordinatesRequest
@return DWDStation|null
@throws DWDLibException - if stations is empty | [
"Return",
"the",
"nearest",
"stations",
"from",
"a",
"stations",
"array",
"."
]
| 36dec7d84a85af599e9d4fb6a3bcc302378ce4a8 | https://github.com/FWidm/dwd-hourly-crawler/blob/36dec7d84a85af599e9d4fb6a3bcc302378ce4a8/src/fwidm/dwdHourlyCrawler/hourly/DWDStationsController.php#L30-L49 |
14,353 | FWidm/dwd-hourly-crawler | src/fwidm/dwdHourlyCrawler/hourly/DWDStationsController.php | DWDStationsController.getNearestStations | public static function getNearestStations($stations, Coordinate $coordinatesRequest, int $radiusKM = 200)
{
//todo: make radius loadable from the config.
DWDUtil::log(self::class, "Getting nearest stations from a list of " . count($stations) . ", around coordinates: " . $coordinatesRequest->format(new DecimalDegrees()));
$calculator = new Vincenty();
$nearestStations = array();
foreach ($stations as $activeStation) {
if (is_object($activeStation) && $activeStation instanceof DWDStation) {
$coordinatesStation = new Coordinate($activeStation->getLatitude(), $activeStation->getLongitude());
//distance in meters!
$diff = $calculator->getDistance($coordinatesRequest, $coordinatesStation);
if ($diff <= $radiusKM * DWDStationsController::kmToMeters) {
$nearestStations[intval($diff)] = $activeStation;
}
//sort by keys -> lowest distance first.
ksort($nearestStations);
}
}
DWDUtil::log(self::class, "Got nearest stations :" . count($nearestStations));
if (count($nearestStations) < 1) {
throw new DWDLibException("No Stations near the given Coordinates are available inside of a 200km radius around coordinates: " . $coordinatesRequest->format(new DecimalDegrees()));
}
return $nearestStations;
} | php | public static function getNearestStations($stations, Coordinate $coordinatesRequest, int $radiusKM = 200)
{
//todo: make radius loadable from the config.
DWDUtil::log(self::class, "Getting nearest stations from a list of " . count($stations) . ", around coordinates: " . $coordinatesRequest->format(new DecimalDegrees()));
$calculator = new Vincenty();
$nearestStations = array();
foreach ($stations as $activeStation) {
if (is_object($activeStation) && $activeStation instanceof DWDStation) {
$coordinatesStation = new Coordinate($activeStation->getLatitude(), $activeStation->getLongitude());
//distance in meters!
$diff = $calculator->getDistance($coordinatesRequest, $coordinatesStation);
if ($diff <= $radiusKM * DWDStationsController::kmToMeters) {
$nearestStations[intval($diff)] = $activeStation;
}
//sort by keys -> lowest distance first.
ksort($nearestStations);
}
}
DWDUtil::log(self::class, "Got nearest stations :" . count($nearestStations));
if (count($nearestStations) < 1) {
throw new DWDLibException("No Stations near the given Coordinates are available inside of a 200km radius around coordinates: " . $coordinatesRequest->format(new DecimalDegrees()));
}
return $nearestStations;
} | [
"public",
"static",
"function",
"getNearestStations",
"(",
"$",
"stations",
",",
"Coordinate",
"$",
"coordinatesRequest",
",",
"int",
"$",
"radiusKM",
"=",
"200",
")",
"{",
"//todo: make radius loadable from the config.",
"DWDUtil",
"::",
"log",
"(",
"self",
"::",
"class",
",",
"\"Getting nearest stations from a list of \"",
".",
"count",
"(",
"$",
"stations",
")",
".",
"\", around coordinates: \"",
".",
"$",
"coordinatesRequest",
"->",
"format",
"(",
"new",
"DecimalDegrees",
"(",
")",
")",
")",
";",
"$",
"calculator",
"=",
"new",
"Vincenty",
"(",
")",
";",
"$",
"nearestStations",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"stations",
"as",
"$",
"activeStation",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"activeStation",
")",
"&&",
"$",
"activeStation",
"instanceof",
"DWDStation",
")",
"{",
"$",
"coordinatesStation",
"=",
"new",
"Coordinate",
"(",
"$",
"activeStation",
"->",
"getLatitude",
"(",
")",
",",
"$",
"activeStation",
"->",
"getLongitude",
"(",
")",
")",
";",
"//distance in meters!",
"$",
"diff",
"=",
"$",
"calculator",
"->",
"getDistance",
"(",
"$",
"coordinatesRequest",
",",
"$",
"coordinatesStation",
")",
";",
"if",
"(",
"$",
"diff",
"<=",
"$",
"radiusKM",
"*",
"DWDStationsController",
"::",
"kmToMeters",
")",
"{",
"$",
"nearestStations",
"[",
"intval",
"(",
"$",
"diff",
")",
"]",
"=",
"$",
"activeStation",
";",
"}",
"//sort by keys -> lowest distance first.",
"ksort",
"(",
"$",
"nearestStations",
")",
";",
"}",
"}",
"DWDUtil",
"::",
"log",
"(",
"self",
"::",
"class",
",",
"\"Got nearest stations :\"",
".",
"count",
"(",
"$",
"nearestStations",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"nearestStations",
")",
"<",
"1",
")",
"{",
"throw",
"new",
"DWDLibException",
"(",
"\"No Stations near the given Coordinates are available inside of a 200km radius around coordinates: \"",
".",
"$",
"coordinatesRequest",
"->",
"format",
"(",
"new",
"DecimalDegrees",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"nearestStations",
";",
"}"
]
| Get all stations in an x km radius.
@param $stations - array of DWDStation
@param int $radiusKM - default 20km
@return array - of nearest stations in the given radius | [
"Get",
"all",
"stations",
"in",
"an",
"x",
"km",
"radius",
"."
]
| 36dec7d84a85af599e9d4fb6a3bcc302378ce4a8 | https://github.com/FWidm/dwd-hourly-crawler/blob/36dec7d84a85af599e9d4fb6a3bcc302378ce4a8/src/fwidm/dwdHourlyCrawler/hourly/DWDStationsController.php#L57-L84 |
14,354 | FWidm/dwd-hourly-crawler | src/fwidm/dwdHourlyCrawler/hourly/DWDStationsController.php | DWDStationsController.getStationFile | public static function getStationFile($stationFtpPath, $outputPath)
{
$ftpConfig = DWDConfiguration::getFTPConfiguration();
$ftp_connection = ftp_connect($ftpConfig->url);
$login_result = ftp_login($ftp_connection, $ftpConfig->userName, $ftpConfig->userPassword);
if ($login_result && ftp_size($ftp_connection, $stationFtpPath) > -1) {
$result = ftp_get($ftp_connection, $outputPath, $stationFtpPath, FTP_BINARY);
// DWDUtil::log(self::class, "out=" . $outputPath);
// DWDUtil::log(self::class, "ftp=" . $stationFtpPath);
ftp_close($ftp_connection);
if (!isset($result)) {
throw new DWDLibException("Could not retrieve data from ftp location: " . $stationFtpPath);
}
}
} | php | public static function getStationFile($stationFtpPath, $outputPath)
{
$ftpConfig = DWDConfiguration::getFTPConfiguration();
$ftp_connection = ftp_connect($ftpConfig->url);
$login_result = ftp_login($ftp_connection, $ftpConfig->userName, $ftpConfig->userPassword);
if ($login_result && ftp_size($ftp_connection, $stationFtpPath) > -1) {
$result = ftp_get($ftp_connection, $outputPath, $stationFtpPath, FTP_BINARY);
// DWDUtil::log(self::class, "out=" . $outputPath);
// DWDUtil::log(self::class, "ftp=" . $stationFtpPath);
ftp_close($ftp_connection);
if (!isset($result)) {
throw new DWDLibException("Could not retrieve data from ftp location: " . $stationFtpPath);
}
}
} | [
"public",
"static",
"function",
"getStationFile",
"(",
"$",
"stationFtpPath",
",",
"$",
"outputPath",
")",
"{",
"$",
"ftpConfig",
"=",
"DWDConfiguration",
"::",
"getFTPConfiguration",
"(",
")",
";",
"$",
"ftp_connection",
"=",
"ftp_connect",
"(",
"$",
"ftpConfig",
"->",
"url",
")",
";",
"$",
"login_result",
"=",
"ftp_login",
"(",
"$",
"ftp_connection",
",",
"$",
"ftpConfig",
"->",
"userName",
",",
"$",
"ftpConfig",
"->",
"userPassword",
")",
";",
"if",
"(",
"$",
"login_result",
"&&",
"ftp_size",
"(",
"$",
"ftp_connection",
",",
"$",
"stationFtpPath",
")",
">",
"-",
"1",
")",
"{",
"$",
"result",
"=",
"ftp_get",
"(",
"$",
"ftp_connection",
",",
"$",
"outputPath",
",",
"$",
"stationFtpPath",
",",
"FTP_BINARY",
")",
";",
"// DWDUtil::log(self::class, \"out=\" . $outputPath);",
"// DWDUtil::log(self::class, \"ftp=\" . $stationFtpPath);",
"ftp_close",
"(",
"$",
"ftp_connection",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"result",
")",
")",
"{",
"throw",
"new",
"DWDLibException",
"(",
"\"Could not retrieve data from ftp location: \"",
".",
"$",
"stationFtpPath",
")",
";",
"}",
"}",
"}"
]
| Tries to download the station file from the given path.
@param $stationFtpPath - path/to/the/station_file.txt
@param $outputPath - location of the resulting file
@throws DWDLibException - if result is empty | [
"Tries",
"to",
"download",
"the",
"station",
"file",
"from",
"the",
"given",
"path",
"."
]
| 36dec7d84a85af599e9d4fb6a3bcc302378ce4a8 | https://github.com/FWidm/dwd-hourly-crawler/blob/36dec7d84a85af599e9d4fb6a3bcc302378ce4a8/src/fwidm/dwdHourlyCrawler/hourly/DWDStationsController.php#L91-L109 |
14,355 | FWidm/dwd-hourly-crawler | src/fwidm/dwdHourlyCrawler/hourly/DWDStationsController.php | DWDStationsController.parseStations | public static function parseStations($filePath)
{
if (DIRECTORY_SEPARATOR == '\\')
$filePath = str_replace('/', '\\', $filePath);
ini_set('display_errors', 1);
error_reporting(E_ALL);
$stationConf = DWDConfiguration::getStationConfiguration();
$stations = array();
if (file_exists($filePath)) {
$handle = fopen($filePath, "r");
if ($handle) {
//skips the first N lines of input, requires the file handle.
self::skipDescriptionLines($stationConf->skipLines, $handle);
while (($line = fgets($handle)) !== false) {
$line = mb_convert_encoding($line, "UTF-8", "iso-8859-1");
// eliminate multiple spaces, replace by single space
$output = preg_replace('!\s+!', ' ', $line);
//remove trailing and leading spaces.
$output = trim($output, ' ');
// process the line read - split by spaces
// stationId, from, until, stationHeight, lat, long, station name, state
// Station name can contain spaces and needs further processing, thus we limit to keep station name + state
// in one field
$split = explode(" ", $output, 7);
$name = explode(" ", $split[count($split) - 1]);
//last cell contains the county name.
$county = $name[count($name) - 1];
// merge all other contents of the name, glue them together with spaces.
$nameSlice = array_slice($name, 0, count($name) - 1);
$name = implode(" ", $nameSlice);
//evtl. array_filter
$from = Carbon::createFromFormat($stationConf->dateFormat, $split[1], 'UTC');
$until = Carbon::createFromFormat($stationConf->dateFormat, $split[2], 'UTC');
$station = new DWDStation($split[0], $from, $until,
$split[3], $split[4], $split[5], $name, $county,
$stationConf->activeRequirementDays);
$stations[] = $station;
}
fclose($handle);
} else {
throw new DWDLibException("Error opening the file: " . $filePath);
}
} else
throw new DWDLibException("File does not exist - path: " . $filePath);
return $stations;
} | php | public static function parseStations($filePath)
{
if (DIRECTORY_SEPARATOR == '\\')
$filePath = str_replace('/', '\\', $filePath);
ini_set('display_errors', 1);
error_reporting(E_ALL);
$stationConf = DWDConfiguration::getStationConfiguration();
$stations = array();
if (file_exists($filePath)) {
$handle = fopen($filePath, "r");
if ($handle) {
//skips the first N lines of input, requires the file handle.
self::skipDescriptionLines($stationConf->skipLines, $handle);
while (($line = fgets($handle)) !== false) {
$line = mb_convert_encoding($line, "UTF-8", "iso-8859-1");
// eliminate multiple spaces, replace by single space
$output = preg_replace('!\s+!', ' ', $line);
//remove trailing and leading spaces.
$output = trim($output, ' ');
// process the line read - split by spaces
// stationId, from, until, stationHeight, lat, long, station name, state
// Station name can contain spaces and needs further processing, thus we limit to keep station name + state
// in one field
$split = explode(" ", $output, 7);
$name = explode(" ", $split[count($split) - 1]);
//last cell contains the county name.
$county = $name[count($name) - 1];
// merge all other contents of the name, glue them together with spaces.
$nameSlice = array_slice($name, 0, count($name) - 1);
$name = implode(" ", $nameSlice);
//evtl. array_filter
$from = Carbon::createFromFormat($stationConf->dateFormat, $split[1], 'UTC');
$until = Carbon::createFromFormat($stationConf->dateFormat, $split[2], 'UTC');
$station = new DWDStation($split[0], $from, $until,
$split[3], $split[4], $split[5], $name, $county,
$stationConf->activeRequirementDays);
$stations[] = $station;
}
fclose($handle);
} else {
throw new DWDLibException("Error opening the file: " . $filePath);
}
} else
throw new DWDLibException("File does not exist - path: " . $filePath);
return $stations;
} | [
"public",
"static",
"function",
"parseStations",
"(",
"$",
"filePath",
")",
"{",
"if",
"(",
"DIRECTORY_SEPARATOR",
"==",
"'\\\\'",
")",
"$",
"filePath",
"=",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"filePath",
")",
";",
"ini_set",
"(",
"'display_errors'",
",",
"1",
")",
";",
"error_reporting",
"(",
"E_ALL",
")",
";",
"$",
"stationConf",
"=",
"DWDConfiguration",
"::",
"getStationConfiguration",
"(",
")",
";",
"$",
"stations",
"=",
"array",
"(",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"filePath",
")",
")",
"{",
"$",
"handle",
"=",
"fopen",
"(",
"$",
"filePath",
",",
"\"r\"",
")",
";",
"if",
"(",
"$",
"handle",
")",
"{",
"//skips the first N lines of input, requires the file handle.",
"self",
"::",
"skipDescriptionLines",
"(",
"$",
"stationConf",
"->",
"skipLines",
",",
"$",
"handle",
")",
";",
"while",
"(",
"(",
"$",
"line",
"=",
"fgets",
"(",
"$",
"handle",
")",
")",
"!==",
"false",
")",
"{",
"$",
"line",
"=",
"mb_convert_encoding",
"(",
"$",
"line",
",",
"\"UTF-8\"",
",",
"\"iso-8859-1\"",
")",
";",
"// eliminate multiple spaces, replace by single space",
"$",
"output",
"=",
"preg_replace",
"(",
"'!\\s+!'",
",",
"' '",
",",
"$",
"line",
")",
";",
"//remove trailing and leading spaces.",
"$",
"output",
"=",
"trim",
"(",
"$",
"output",
",",
"' '",
")",
";",
"// process the line read - split by spaces",
"// stationId, from, until, stationHeight, lat, long, station name, state",
"// Station name can contain spaces and needs further processing, thus we limit to keep station name + state",
"// in one field",
"$",
"split",
"=",
"explode",
"(",
"\" \"",
",",
"$",
"output",
",",
"7",
")",
";",
"$",
"name",
"=",
"explode",
"(",
"\" \"",
",",
"$",
"split",
"[",
"count",
"(",
"$",
"split",
")",
"-",
"1",
"]",
")",
";",
"//last cell contains the county name.",
"$",
"county",
"=",
"$",
"name",
"[",
"count",
"(",
"$",
"name",
")",
"-",
"1",
"]",
";",
"// merge all other contents of the name, glue them together with spaces.",
"$",
"nameSlice",
"=",
"array_slice",
"(",
"$",
"name",
",",
"0",
",",
"count",
"(",
"$",
"name",
")",
"-",
"1",
")",
";",
"$",
"name",
"=",
"implode",
"(",
"\" \"",
",",
"$",
"nameSlice",
")",
";",
"//evtl. array_filter",
"$",
"from",
"=",
"Carbon",
"::",
"createFromFormat",
"(",
"$",
"stationConf",
"->",
"dateFormat",
",",
"$",
"split",
"[",
"1",
"]",
",",
"'UTC'",
")",
";",
"$",
"until",
"=",
"Carbon",
"::",
"createFromFormat",
"(",
"$",
"stationConf",
"->",
"dateFormat",
",",
"$",
"split",
"[",
"2",
"]",
",",
"'UTC'",
")",
";",
"$",
"station",
"=",
"new",
"DWDStation",
"(",
"$",
"split",
"[",
"0",
"]",
",",
"$",
"from",
",",
"$",
"until",
",",
"$",
"split",
"[",
"3",
"]",
",",
"$",
"split",
"[",
"4",
"]",
",",
"$",
"split",
"[",
"5",
"]",
",",
"$",
"name",
",",
"$",
"county",
",",
"$",
"stationConf",
"->",
"activeRequirementDays",
")",
";",
"$",
"stations",
"[",
"]",
"=",
"$",
"station",
";",
"}",
"fclose",
"(",
"$",
"handle",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"DWDLibException",
"(",
"\"Error opening the file: \"",
".",
"$",
"filePath",
")",
";",
"}",
"}",
"else",
"throw",
"new",
"DWDLibException",
"(",
"\"File does not exist - path: \"",
".",
"$",
"filePath",
")",
";",
"return",
"$",
"stations",
";",
"}"
]
| Parse the station files into station objects.
@param $filePath - path to the station file
@return array - of stations
@throws DWDLibException - if zip opening fails or zip does not exist | [
"Parse",
"the",
"station",
"files",
"into",
"station",
"objects",
"."
]
| 36dec7d84a85af599e9d4fb6a3bcc302378ce4a8 | https://github.com/FWidm/dwd-hourly-crawler/blob/36dec7d84a85af599e9d4fb6a3bcc302378ce4a8/src/fwidm/dwdHourlyCrawler/hourly/DWDStationsController.php#L117-L170 |
14,356 | abhi1693/yii2-enum | helpers/BaseEnum.php | BaseEnum.createByName | public static function createByName($name)
{
$constants = self::getConstantsByName();
if (!array_key_exists($name, $constants)) {
throw EnumException::invalidName(get_called_class(), $name);
}
return new static($constants[$name]);
} | php | public static function createByName($name)
{
$constants = self::getConstantsByName();
if (!array_key_exists($name, $constants)) {
throw EnumException::invalidName(get_called_class(), $name);
}
return new static($constants[$name]);
} | [
"public",
"static",
"function",
"createByName",
"(",
"$",
"name",
")",
"{",
"$",
"constants",
"=",
"self",
"::",
"getConstantsByName",
"(",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"constants",
")",
")",
"{",
"throw",
"EnumException",
"::",
"invalidName",
"(",
"get_called_class",
"(",
")",
",",
"$",
"name",
")",
";",
"}",
"return",
"new",
"static",
"(",
"$",
"constants",
"[",
"$",
"name",
"]",
")",
";",
"}"
]
| Creates a new type instance using the name of a value
@param string $name The name of a value
@return $this The new type instance
@throws EnumException If the name is invalid | [
"Creates",
"a",
"new",
"type",
"instance",
"using",
"the",
"name",
"of",
"a",
"value"
]
| 1def6522303fa8f0277f09d1123229c32c942cd9 | https://github.com/abhi1693/yii2-enum/blob/1def6522303fa8f0277f09d1123229c32c942cd9/helpers/BaseEnum.php#L69-L78 |
14,357 | abhi1693/yii2-enum | helpers/BaseEnum.php | BaseEnum.createByValue | public static function createByValue($value)
{
$constants = self::getConstantsByValue();
if (!array_key_exists($value, $constants)) {
throw EnumException::invalidValue(get_called_class(), $value);
}
return new static ($value);
} | php | public static function createByValue($value)
{
$constants = self::getConstantsByValue();
if (!array_key_exists($value, $constants)) {
throw EnumException::invalidValue(get_called_class(), $value);
}
return new static ($value);
} | [
"public",
"static",
"function",
"createByValue",
"(",
"$",
"value",
")",
"{",
"$",
"constants",
"=",
"self",
"::",
"getConstantsByValue",
"(",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"value",
",",
"$",
"constants",
")",
")",
"{",
"throw",
"EnumException",
"::",
"invalidValue",
"(",
"get_called_class",
"(",
")",
",",
"$",
"value",
")",
";",
"}",
"return",
"new",
"static",
"(",
"$",
"value",
")",
";",
"}"
]
| Creates a new type instance using the value
@param mixed $value The value
@throws EnumException If the value is invalid
@return $this The new instance | [
"Creates",
"a",
"new",
"type",
"instance",
"using",
"the",
"value"
]
| 1def6522303fa8f0277f09d1123229c32c942cd9 | https://github.com/abhi1693/yii2-enum/blob/1def6522303fa8f0277f09d1123229c32c942cd9/helpers/BaseEnum.php#L88-L97 |
14,358 | FWidm/dwd-hourly-crawler | src/fwidm/dwdHourlyCrawler/hourly/services/AbstractHourlyService.php | AbstractHourlyService.parseHourlyDataOld | public function parseHourlyDataOld(String $content, DWDStation $nearestStation, Coordinate $coordinate, Carbon $startDate = null, Carbon $endDate = null): array
{
$time = microtime(true);
$lines = explode('eor', $content);
$data = array();
/**
* steps to refactor:
* 1. get latest date from the last line, parse it
* 2. from this day, calculate the hour difference between requested and $start+$end
* 3. jump to the specific lines
* 4. parse
* DOES NOT PROVIDE CORRECT DATA - the dwd files do skip missing data instead of providing "-999" as value, as such the optimization will not work.
*/
// $newestDate = null;
// //retrieve the latest line that contains a valid date
// for ($i = count($lines) - 1; !isset($newestDate); $i++) {
// $newestData = str_replace(' ', '', $lines[count($lines) - $i]);
// $cols = explode(';', $newestData);
// if (sizeof($cols) > 3){
// $newestDate = Carbon::createFromFormat($this->getTimeFormat(), $cols[1], 'utc');
// break;
// }
// }
// /* @var $newestDate Carbon */
// $start = min($newestDate->diffInHours($startDate), $newestDate->diffInHours($endDate));
// $end = max($newestDate->diffInHours($startDate), $newestDate->diffInHours($endDate));
// DWDUtil::log("MAXMIN", "start=" .$start."; end=".$end. "available Lines=".count($lines));
// //Retrieve the rest of the data that is found between start and end.
// for ($i = $start; $i<count($lines) && $i < $end; $i++) {
// $lines[$i] = str_replace(' ', '', $lines[$i]);
// $cols = explode(';', $lines[$i]);
// $date = Carbon::createFromFormat($this->getTimeFormat(), $cols[1], 'utc');
// if (isset($date)) {
// $data[] = $this->createParameter($cols, $date, $nearestStation, $coordinate);
// } else
// throw new ParseError(self::class . " - Error while parsing date: col=" . $cols[1] . " | date=" . $date);
// }
DWDUtil::log("PARSER", "DATE=[" . $endDate->toIso8601String() . "," . $startDate->toIso8601String() . "]");
for ($i = sizeof($lines) - 1; $i > 0; $i--) {
$lines[$i] = str_replace(' ', '', $lines[$i]);
$cols = explode(';', $lines[$i]);
//skip empty lines
if (sizeof($cols) < 3)
continue;
$date = Carbon::createFromFormat($this->getTimeFormat(), $cols[1], 'utc');
if ($date) {
//todo: optimize search for values - currently i only parse from new to old values, find the window and add to the return list - something akin to a binary search might work.
switch (func_num_args()) {
//$start is set
case 4: {
if ($date >= $startDate) {
$temp = $this->createParameter($cols, $date, $nearestStation, $coordinate);
$data[] = $temp;
} else
//break from loop and switch
break 2;
break;
}
//$start & $end are set
case 5: {
if ($date <= $endDate && $date >= $startDate) {
$temp = $this->createParameter($cols, $date, $nearestStation, $coordinate);
$data[] = $temp;
} else
if ($date <= $startDate) {
//break from loop and switch
break 2;
}
break;
}
default: {
$temp = $this->createParameter($cols, $date, $nearestStation, $coordinate);
$data[] = $temp;
}
}
} else
throw new ParseError(self::class . " - Error while parsing date: col=" . $cols[1] . " | date=" . $date);
}
DWDUtil::log("PARSER", "RetCount=" . count($data));
DWDUtil::log("TIMER", "Duration=" . (microtime(true) - $time));
return $data;
} | php | public function parseHourlyDataOld(String $content, DWDStation $nearestStation, Coordinate $coordinate, Carbon $startDate = null, Carbon $endDate = null): array
{
$time = microtime(true);
$lines = explode('eor', $content);
$data = array();
/**
* steps to refactor:
* 1. get latest date from the last line, parse it
* 2. from this day, calculate the hour difference between requested and $start+$end
* 3. jump to the specific lines
* 4. parse
* DOES NOT PROVIDE CORRECT DATA - the dwd files do skip missing data instead of providing "-999" as value, as such the optimization will not work.
*/
// $newestDate = null;
// //retrieve the latest line that contains a valid date
// for ($i = count($lines) - 1; !isset($newestDate); $i++) {
// $newestData = str_replace(' ', '', $lines[count($lines) - $i]);
// $cols = explode(';', $newestData);
// if (sizeof($cols) > 3){
// $newestDate = Carbon::createFromFormat($this->getTimeFormat(), $cols[1], 'utc');
// break;
// }
// }
// /* @var $newestDate Carbon */
// $start = min($newestDate->diffInHours($startDate), $newestDate->diffInHours($endDate));
// $end = max($newestDate->diffInHours($startDate), $newestDate->diffInHours($endDate));
// DWDUtil::log("MAXMIN", "start=" .$start."; end=".$end. "available Lines=".count($lines));
// //Retrieve the rest of the data that is found between start and end.
// for ($i = $start; $i<count($lines) && $i < $end; $i++) {
// $lines[$i] = str_replace(' ', '', $lines[$i]);
// $cols = explode(';', $lines[$i]);
// $date = Carbon::createFromFormat($this->getTimeFormat(), $cols[1], 'utc');
// if (isset($date)) {
// $data[] = $this->createParameter($cols, $date, $nearestStation, $coordinate);
// } else
// throw new ParseError(self::class . " - Error while parsing date: col=" . $cols[1] . " | date=" . $date);
// }
DWDUtil::log("PARSER", "DATE=[" . $endDate->toIso8601String() . "," . $startDate->toIso8601String() . "]");
for ($i = sizeof($lines) - 1; $i > 0; $i--) {
$lines[$i] = str_replace(' ', '', $lines[$i]);
$cols = explode(';', $lines[$i]);
//skip empty lines
if (sizeof($cols) < 3)
continue;
$date = Carbon::createFromFormat($this->getTimeFormat(), $cols[1], 'utc');
if ($date) {
//todo: optimize search for values - currently i only parse from new to old values, find the window and add to the return list - something akin to a binary search might work.
switch (func_num_args()) {
//$start is set
case 4: {
if ($date >= $startDate) {
$temp = $this->createParameter($cols, $date, $nearestStation, $coordinate);
$data[] = $temp;
} else
//break from loop and switch
break 2;
break;
}
//$start & $end are set
case 5: {
if ($date <= $endDate && $date >= $startDate) {
$temp = $this->createParameter($cols, $date, $nearestStation, $coordinate);
$data[] = $temp;
} else
if ($date <= $startDate) {
//break from loop and switch
break 2;
}
break;
}
default: {
$temp = $this->createParameter($cols, $date, $nearestStation, $coordinate);
$data[] = $temp;
}
}
} else
throw new ParseError(self::class . " - Error while parsing date: col=" . $cols[1] . " | date=" . $date);
}
DWDUtil::log("PARSER", "RetCount=" . count($data));
DWDUtil::log("TIMER", "Duration=" . (microtime(true) - $time));
return $data;
} | [
"public",
"function",
"parseHourlyDataOld",
"(",
"String",
"$",
"content",
",",
"DWDStation",
"$",
"nearestStation",
",",
"Coordinate",
"$",
"coordinate",
",",
"Carbon",
"$",
"startDate",
"=",
"null",
",",
"Carbon",
"$",
"endDate",
"=",
"null",
")",
":",
"array",
"{",
"$",
"time",
"=",
"microtime",
"(",
"true",
")",
";",
"$",
"lines",
"=",
"explode",
"(",
"'eor'",
",",
"$",
"content",
")",
";",
"$",
"data",
"=",
"array",
"(",
")",
";",
"/**\n * steps to refactor:\n * 1. get latest date from the last line, parse it\n * 2. from this day, calculate the hour difference between requested and $start+$end\n * 3. jump to the specific lines\n * 4. parse\n * DOES NOT PROVIDE CORRECT DATA - the dwd files do skip missing data instead of providing \"-999\" as value, as such the optimization will not work.\n */",
"// $newestDate = null;",
"// //retrieve the latest line that contains a valid date",
"// for ($i = count($lines) - 1; !isset($newestDate); $i++) {",
"// $newestData = str_replace(' ', '', $lines[count($lines) - $i]);",
"// $cols = explode(';', $newestData);",
"// if (sizeof($cols) > 3){",
"// $newestDate = Carbon::createFromFormat($this->getTimeFormat(), $cols[1], 'utc');",
"// break;",
"// }",
"// }",
"// /* @var $newestDate Carbon */",
"// $start = min($newestDate->diffInHours($startDate), $newestDate->diffInHours($endDate));",
"// $end = max($newestDate->diffInHours($startDate), $newestDate->diffInHours($endDate));",
"// DWDUtil::log(\"MAXMIN\", \"start=\" .$start.\"; end=\".$end. \"available Lines=\".count($lines));",
"// //Retrieve the rest of the data that is found between start and end.",
"// for ($i = $start; $i<count($lines) && $i < $end; $i++) {",
"// $lines[$i] = str_replace(' ', '', $lines[$i]);",
"// $cols = explode(';', $lines[$i]);",
"// $date = Carbon::createFromFormat($this->getTimeFormat(), $cols[1], 'utc');",
"// if (isset($date)) {",
"// $data[] = $this->createParameter($cols, $date, $nearestStation, $coordinate);",
"// } else",
"// throw new ParseError(self::class . \" - Error while parsing date: col=\" . $cols[1] . \" | date=\" . $date);",
"// }",
"DWDUtil",
"::",
"log",
"(",
"\"PARSER\"",
",",
"\"DATE=[\"",
".",
"$",
"endDate",
"->",
"toIso8601String",
"(",
")",
".",
"\",\"",
".",
"$",
"startDate",
"->",
"toIso8601String",
"(",
")",
".",
"\"]\"",
")",
";",
"for",
"(",
"$",
"i",
"=",
"sizeof",
"(",
"$",
"lines",
")",
"-",
"1",
";",
"$",
"i",
">",
"0",
";",
"$",
"i",
"--",
")",
"{",
"$",
"lines",
"[",
"$",
"i",
"]",
"=",
"str_replace",
"(",
"' '",
",",
"''",
",",
"$",
"lines",
"[",
"$",
"i",
"]",
")",
";",
"$",
"cols",
"=",
"explode",
"(",
"';'",
",",
"$",
"lines",
"[",
"$",
"i",
"]",
")",
";",
"//skip empty lines",
"if",
"(",
"sizeof",
"(",
"$",
"cols",
")",
"<",
"3",
")",
"continue",
";",
"$",
"date",
"=",
"Carbon",
"::",
"createFromFormat",
"(",
"$",
"this",
"->",
"getTimeFormat",
"(",
")",
",",
"$",
"cols",
"[",
"1",
"]",
",",
"'utc'",
")",
";",
"if",
"(",
"$",
"date",
")",
"{",
"//todo: optimize search for values - currently i only parse from new to old values, find the window and add to the return list - something akin to a binary search might work.",
"switch",
"(",
"func_num_args",
"(",
")",
")",
"{",
"//$start is set",
"case",
"4",
":",
"{",
"if",
"(",
"$",
"date",
">=",
"$",
"startDate",
")",
"{",
"$",
"temp",
"=",
"$",
"this",
"->",
"createParameter",
"(",
"$",
"cols",
",",
"$",
"date",
",",
"$",
"nearestStation",
",",
"$",
"coordinate",
")",
";",
"$",
"data",
"[",
"]",
"=",
"$",
"temp",
";",
"}",
"else",
"//break from loop and switch",
"break",
"2",
";",
"break",
";",
"}",
"//$start & $end are set",
"case",
"5",
":",
"{",
"if",
"(",
"$",
"date",
"<=",
"$",
"endDate",
"&&",
"$",
"date",
">=",
"$",
"startDate",
")",
"{",
"$",
"temp",
"=",
"$",
"this",
"->",
"createParameter",
"(",
"$",
"cols",
",",
"$",
"date",
",",
"$",
"nearestStation",
",",
"$",
"coordinate",
")",
";",
"$",
"data",
"[",
"]",
"=",
"$",
"temp",
";",
"}",
"else",
"if",
"(",
"$",
"date",
"<=",
"$",
"startDate",
")",
"{",
"//break from loop and switch",
"break",
"2",
";",
"}",
"break",
";",
"}",
"default",
":",
"{",
"$",
"temp",
"=",
"$",
"this",
"->",
"createParameter",
"(",
"$",
"cols",
",",
"$",
"date",
",",
"$",
"nearestStation",
",",
"$",
"coordinate",
")",
";",
"$",
"data",
"[",
"]",
"=",
"$",
"temp",
";",
"}",
"}",
"}",
"else",
"throw",
"new",
"ParseError",
"(",
"self",
"::",
"class",
".",
"\" - Error while parsing date: col=\"",
".",
"$",
"cols",
"[",
"1",
"]",
".",
"\" | date=\"",
".",
"$",
"date",
")",
";",
"}",
"DWDUtil",
"::",
"log",
"(",
"\"PARSER\"",
",",
"\"RetCount=\"",
".",
"count",
"(",
"$",
"data",
")",
")",
";",
"DWDUtil",
"::",
"log",
"(",
"\"TIMER\"",
",",
"\"Duration=\"",
".",
"(",
"microtime",
"(",
"true",
")",
"-",
"$",
"time",
")",
")",
";",
"return",
"$",
"data",
";",
"}"
]
| Parse the textual representation of DWD Data, can be filtered by specifying before and after.
This means if you specify after - you will get timestamps after the specified team
If you also specify before you can pinpoint values.
@deprecated
@param String $content - Textual representation of a DWD Hourly/Recent pressure file.
@param Carbon|null $startDate - returns all values after the specific time
@param Carbon|null $endDate - returns all values after $after AND after if set.
@return array of parameters
@throws ParseError | [
"Parse",
"the",
"textual",
"representation",
"of",
"DWD",
"Data",
"can",
"be",
"filtered",
"by",
"specifying",
"before",
"and",
"after",
".",
"This",
"means",
"if",
"you",
"specify",
"after",
"-",
"you",
"will",
"get",
"timestamps",
"after",
"the",
"specified",
"team",
"If",
"you",
"also",
"specify",
"before",
"you",
"can",
"pinpoint",
"values",
"."
]
| 36dec7d84a85af599e9d4fb6a3bcc302378ce4a8 | https://github.com/FWidm/dwd-hourly-crawler/blob/36dec7d84a85af599e9d4fb6a3bcc302378ce4a8/src/fwidm/dwdHourlyCrawler/hourly/services/AbstractHourlyService.php#L54-L147 |
14,359 | FWidm/dwd-hourly-crawler | src/fwidm/dwdHourlyCrawler/hourly/services/AbstractHourlyService.php | AbstractHourlyService.getStationFTPPath | public function getStationFTPPath(string $ftpPath)
{
$fileName = DWDUtil::getFileNameFromPath($ftpPath);
$filePath = DWDConfiguration::getConfiguration()->baseDirectory . DWDConfiguration::getConfiguration()->dwdHourly->localBaseFolder . '/' . $fileName;
return $filePath;
} | php | public function getStationFTPPath(string $ftpPath)
{
$fileName = DWDUtil::getFileNameFromPath($ftpPath);
$filePath = DWDConfiguration::getConfiguration()->baseDirectory . DWDConfiguration::getConfiguration()->dwdHourly->localBaseFolder . '/' . $fileName;
return $filePath;
} | [
"public",
"function",
"getStationFTPPath",
"(",
"string",
"$",
"ftpPath",
")",
"{",
"$",
"fileName",
"=",
"DWDUtil",
"::",
"getFileNameFromPath",
"(",
"$",
"ftpPath",
")",
";",
"$",
"filePath",
"=",
"DWDConfiguration",
"::",
"getConfiguration",
"(",
")",
"->",
"baseDirectory",
".",
"DWDConfiguration",
"::",
"getConfiguration",
"(",
")",
"->",
"dwdHourly",
"->",
"localBaseFolder",
".",
"'/'",
".",
"$",
"fileName",
";",
"return",
"$",
"filePath",
";",
"}"
]
| Return the path to the file that contains the stations.
@param string $ftpPath
@return string | [
"Return",
"the",
"path",
"to",
"the",
"file",
"that",
"contains",
"the",
"stations",
"."
]
| 36dec7d84a85af599e9d4fb6a3bcc302378ce4a8 | https://github.com/FWidm/dwd-hourly-crawler/blob/36dec7d84a85af599e9d4fb6a3bcc302378ce4a8/src/fwidm/dwdHourlyCrawler/hourly/services/AbstractHourlyService.php#L238-L243 |
14,360 | PandaPlatform/framework | src/Panda/Foundation/Http/Kernel.php | Kernel.boot | public function boot($request = null)
{
// Initialize application
$this->getApp()->boot($request, $this->bootstrapRegistry->getItems());
// Set base controller router
Controller::setRouter($this->getRouter());
// Include routes
include_once $this->routesConfiguration->getRoutesPath($this->getApp()->getBasePath());
} | php | public function boot($request = null)
{
// Initialize application
$this->getApp()->boot($request, $this->bootstrapRegistry->getItems());
// Set base controller router
Controller::setRouter($this->getRouter());
// Include routes
include_once $this->routesConfiguration->getRoutesPath($this->getApp()->getBasePath());
} | [
"public",
"function",
"boot",
"(",
"$",
"request",
"=",
"null",
")",
"{",
"// Initialize application",
"$",
"this",
"->",
"getApp",
"(",
")",
"->",
"boot",
"(",
"$",
"request",
",",
"$",
"this",
"->",
"bootstrapRegistry",
"->",
"getItems",
"(",
")",
")",
";",
"// Set base controller router",
"Controller",
"::",
"setRouter",
"(",
"$",
"this",
"->",
"getRouter",
"(",
")",
")",
";",
"// Include routes",
"include_once",
"$",
"this",
"->",
"routesConfiguration",
"->",
"getRoutesPath",
"(",
"$",
"this",
"->",
"getApp",
"(",
")",
"->",
"getBasePath",
"(",
")",
")",
";",
"}"
]
| Init the panda application and start all the interfaces that
are needed for runtime.
@param Request|SymfonyRequest $request
@throws InvalidArgumentException
@throws \DI\DependencyException
@throws \DI\NotFoundException | [
"Init",
"the",
"panda",
"application",
"and",
"start",
"all",
"the",
"interfaces",
"that",
"are",
"needed",
"for",
"runtime",
"."
]
| a78cf051b379896b5a4d5df620988e37a0e632f5 | https://github.com/PandaPlatform/framework/blob/a78cf051b379896b5a4d5df620988e37a0e632f5/src/Panda/Foundation/Http/Kernel.php#L97-L107 |
14,361 | PandaPlatform/framework | src/Panda/Foundation/Http/Kernel.php | Kernel.handle | public function handle(SymfonyRequest $request)
{
// Boot kernel
$this->boot($request);
// Dispatch the response
return $this->getRouter()->dispatch($request);
} | php | public function handle(SymfonyRequest $request)
{
// Boot kernel
$this->boot($request);
// Dispatch the response
return $this->getRouter()->dispatch($request);
} | [
"public",
"function",
"handle",
"(",
"SymfonyRequest",
"$",
"request",
")",
"{",
"// Boot kernel",
"$",
"this",
"->",
"boot",
"(",
"$",
"request",
")",
";",
"// Dispatch the response",
"return",
"$",
"this",
"->",
"getRouter",
"(",
")",
"->",
"dispatch",
"(",
"$",
"request",
")",
";",
"}"
]
| Handle the incoming request and return a response.
@param Request|SymfonyRequest $request
@return Response
@throws InvalidArgumentException
@throws \DI\DependencyException
@throws \DI\NotFoundException
@throws \LogicException
@throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
@throws \UnexpectedValueException | [
"Handle",
"the",
"incoming",
"request",
"and",
"return",
"a",
"response",
"."
]
| a78cf051b379896b5a4d5df620988e37a0e632f5 | https://github.com/PandaPlatform/framework/blob/a78cf051b379896b5a4d5df620988e37a0e632f5/src/Panda/Foundation/Http/Kernel.php#L122-L129 |
14,362 | Webiny/AnalyticsDb | src/Webiny/AnalyticsDb/Query/Dimensions.php | Dimensions.setDimension | public function setDimension($dimensionName, $dimensionValue = null)
{
$this->pipeline['$match']['name'] = $dimensionName;
if (!empty($dimensionValue)) {
$this->pipeline['$match']['value'] = $dimensionValue;
}
return $this;
} | php | public function setDimension($dimensionName, $dimensionValue = null)
{
$this->pipeline['$match']['name'] = $dimensionName;
if (!empty($dimensionValue)) {
$this->pipeline['$match']['value'] = $dimensionValue;
}
return $this;
} | [
"public",
"function",
"setDimension",
"(",
"$",
"dimensionName",
",",
"$",
"dimensionValue",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"pipeline",
"[",
"'$match'",
"]",
"[",
"'name'",
"]",
"=",
"$",
"dimensionName",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"dimensionValue",
")",
")",
"{",
"$",
"this",
"->",
"pipeline",
"[",
"'$match'",
"]",
"[",
"'value'",
"]",
"=",
"$",
"dimensionValue",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Filter the dimension records.
@param string $dimensionName Dimension name.
@param string|null $dimensionValue Dimension value.
@return $this | [
"Filter",
"the",
"dimension",
"records",
"."
]
| e0b1e920643cd63071406520767243736004052e | https://github.com/Webiny/AnalyticsDb/blob/e0b1e920643cd63071406520767243736004052e/src/Webiny/AnalyticsDb/Query/Dimensions.php#L29-L38 |
14,363 | Webiny/AnalyticsDb | src/Webiny/AnalyticsDb/Query/Dimensions.php | Dimensions.sortByDimensionName | public function sortByDimensionName($direction)
{
if ($this->id != '$name' && $this->id != '$value') {
throw new AnalyticsDbException('In order to sort by dimension name, you need to first group by dimension name or dimension value.');
}
$direction = (int)$direction;
if ($this->id == '$name') {
$this->pipeline['$sort'] = ['_id' => $direction];
} else {
$this->pipeline['$sort'] = ['_id.name' => $direction];
}
return $this;
} | php | public function sortByDimensionName($direction)
{
if ($this->id != '$name' && $this->id != '$value') {
throw new AnalyticsDbException('In order to sort by dimension name, you need to first group by dimension name or dimension value.');
}
$direction = (int)$direction;
if ($this->id == '$name') {
$this->pipeline['$sort'] = ['_id' => $direction];
} else {
$this->pipeline['$sort'] = ['_id.name' => $direction];
}
return $this;
} | [
"public",
"function",
"sortByDimensionName",
"(",
"$",
"direction",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"id",
"!=",
"'$name'",
"&&",
"$",
"this",
"->",
"id",
"!=",
"'$value'",
")",
"{",
"throw",
"new",
"AnalyticsDbException",
"(",
"'In order to sort by dimension name, you need to first group by dimension name or dimension value.'",
")",
";",
"}",
"$",
"direction",
"=",
"(",
"int",
")",
"$",
"direction",
";",
"if",
"(",
"$",
"this",
"->",
"id",
"==",
"'$name'",
")",
"{",
"$",
"this",
"->",
"pipeline",
"[",
"'$sort'",
"]",
"=",
"[",
"'_id'",
"=>",
"$",
"direction",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"pipeline",
"[",
"'$sort'",
"]",
"=",
"[",
"'_id.name'",
"=>",
"$",
"direction",
"]",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Sort records by dimension name.
@param string $direction Mongo sort direction: 1 => ascending; -1 => descending
@return $this
@throws AnalyticsDbException | [
"Sort",
"records",
"by",
"dimension",
"name",
"."
]
| e0b1e920643cd63071406520767243736004052e | https://github.com/Webiny/AnalyticsDb/blob/e0b1e920643cd63071406520767243736004052e/src/Webiny/AnalyticsDb/Query/Dimensions.php#L48-L64 |
14,364 | Webiny/AnalyticsDb | src/Webiny/AnalyticsDb/Query/Dimensions.php | Dimensions.sortByDimensionValue | public function sortByDimensionValue($direction)
{
if ($this->id != '$value') {
throw new AnalyticsDbException('In order to sort by dimension value, you need to first group by dimension value.');
}
$direction = (int)$direction;
$this->pipeline['$sort'] = ['_id.value' => $direction];
return $this;
} | php | public function sortByDimensionValue($direction)
{
if ($this->id != '$value') {
throw new AnalyticsDbException('In order to sort by dimension value, you need to first group by dimension value.');
}
$direction = (int)$direction;
$this->pipeline['$sort'] = ['_id.value' => $direction];
return $this;
} | [
"public",
"function",
"sortByDimensionValue",
"(",
"$",
"direction",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"id",
"!=",
"'$value'",
")",
"{",
"throw",
"new",
"AnalyticsDbException",
"(",
"'In order to sort by dimension value, you need to first group by dimension value.'",
")",
";",
"}",
"$",
"direction",
"=",
"(",
"int",
")",
"$",
"direction",
";",
"$",
"this",
"->",
"pipeline",
"[",
"'$sort'",
"]",
"=",
"[",
"'_id.value'",
"=>",
"$",
"direction",
"]",
";",
"return",
"$",
"this",
";",
"}"
]
| Sort records by dimension value.
@param string $direction Mongo sort direction: 1 => ascending; -1 => descending
@return $this
@throws AnalyticsDbException | [
"Sort",
"records",
"by",
"dimension",
"value",
"."
]
| e0b1e920643cd63071406520767243736004052e | https://github.com/Webiny/AnalyticsDb/blob/e0b1e920643cd63071406520767243736004052e/src/Webiny/AnalyticsDb/Query/Dimensions.php#L74-L86 |
14,365 | nyeholt/silverstripe-simplewiki | thirdparty/htmlpurifier-4.0.0-lite/library/HTMLPurifier/LanguageFactory.php | HTMLPurifier_LanguageFactory.loadLanguage | public function loadLanguage($code) {
static $languages_seen = array(); // recursion guard
// abort if we've already loaded it
if (isset($this->cache[$code])) return;
// generate filename
$filename = $this->dir . '/Language/messages/' . $code . '.php';
// default fallback : may be overwritten by the ensuing include
$fallback = ($code != 'en') ? 'en' : false;
// load primary localisation
if (!file_exists($filename)) {
// skip the include: will rely solely on fallback
$filename = $this->dir . '/Language/messages/en.php';
$cache = array();
} else {
include $filename;
$cache = compact($this->keys);
}
// load fallback localisation
if (!empty($fallback)) {
// infinite recursion guard
if (isset($languages_seen[$code])) {
trigger_error('Circular fallback reference in language ' .
$code, E_USER_ERROR);
$fallback = 'en';
}
$language_seen[$code] = true;
// load the fallback recursively
$this->loadLanguage($fallback);
$fallback_cache = $this->cache[$fallback];
// merge fallback with current language
foreach ( $this->keys as $key ) {
if (isset($cache[$key]) && isset($fallback_cache[$key])) {
if (isset($this->mergeable_keys_map[$key])) {
$cache[$key] = $cache[$key] + $fallback_cache[$key];
} elseif (isset($this->mergeable_keys_list[$key])) {
$cache[$key] = array_merge( $fallback_cache[$key], $cache[$key] );
}
} else {
$cache[$key] = $fallback_cache[$key];
}
}
}
// save to cache for later retrieval
$this->cache[$code] = $cache;
return;
} | php | public function loadLanguage($code) {
static $languages_seen = array(); // recursion guard
// abort if we've already loaded it
if (isset($this->cache[$code])) return;
// generate filename
$filename = $this->dir . '/Language/messages/' . $code . '.php';
// default fallback : may be overwritten by the ensuing include
$fallback = ($code != 'en') ? 'en' : false;
// load primary localisation
if (!file_exists($filename)) {
// skip the include: will rely solely on fallback
$filename = $this->dir . '/Language/messages/en.php';
$cache = array();
} else {
include $filename;
$cache = compact($this->keys);
}
// load fallback localisation
if (!empty($fallback)) {
// infinite recursion guard
if (isset($languages_seen[$code])) {
trigger_error('Circular fallback reference in language ' .
$code, E_USER_ERROR);
$fallback = 'en';
}
$language_seen[$code] = true;
// load the fallback recursively
$this->loadLanguage($fallback);
$fallback_cache = $this->cache[$fallback];
// merge fallback with current language
foreach ( $this->keys as $key ) {
if (isset($cache[$key]) && isset($fallback_cache[$key])) {
if (isset($this->mergeable_keys_map[$key])) {
$cache[$key] = $cache[$key] + $fallback_cache[$key];
} elseif (isset($this->mergeable_keys_list[$key])) {
$cache[$key] = array_merge( $fallback_cache[$key], $cache[$key] );
}
} else {
$cache[$key] = $fallback_cache[$key];
}
}
}
// save to cache for later retrieval
$this->cache[$code] = $cache;
return;
} | [
"public",
"function",
"loadLanguage",
"(",
"$",
"code",
")",
"{",
"static",
"$",
"languages_seen",
"=",
"array",
"(",
")",
";",
"// recursion guard",
"// abort if we've already loaded it",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"cache",
"[",
"$",
"code",
"]",
")",
")",
"return",
";",
"// generate filename",
"$",
"filename",
"=",
"$",
"this",
"->",
"dir",
".",
"'/Language/messages/'",
".",
"$",
"code",
".",
"'.php'",
";",
"// default fallback : may be overwritten by the ensuing include",
"$",
"fallback",
"=",
"(",
"$",
"code",
"!=",
"'en'",
")",
"?",
"'en'",
":",
"false",
";",
"// load primary localisation",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"filename",
")",
")",
"{",
"// skip the include: will rely solely on fallback",
"$",
"filename",
"=",
"$",
"this",
"->",
"dir",
".",
"'/Language/messages/en.php'",
";",
"$",
"cache",
"=",
"array",
"(",
")",
";",
"}",
"else",
"{",
"include",
"$",
"filename",
";",
"$",
"cache",
"=",
"compact",
"(",
"$",
"this",
"->",
"keys",
")",
";",
"}",
"// load fallback localisation",
"if",
"(",
"!",
"empty",
"(",
"$",
"fallback",
")",
")",
"{",
"// infinite recursion guard",
"if",
"(",
"isset",
"(",
"$",
"languages_seen",
"[",
"$",
"code",
"]",
")",
")",
"{",
"trigger_error",
"(",
"'Circular fallback reference in language '",
".",
"$",
"code",
",",
"E_USER_ERROR",
")",
";",
"$",
"fallback",
"=",
"'en'",
";",
"}",
"$",
"language_seen",
"[",
"$",
"code",
"]",
"=",
"true",
";",
"// load the fallback recursively",
"$",
"this",
"->",
"loadLanguage",
"(",
"$",
"fallback",
")",
";",
"$",
"fallback_cache",
"=",
"$",
"this",
"->",
"cache",
"[",
"$",
"fallback",
"]",
";",
"// merge fallback with current language",
"foreach",
"(",
"$",
"this",
"->",
"keys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"cache",
"[",
"$",
"key",
"]",
")",
"&&",
"isset",
"(",
"$",
"fallback_cache",
"[",
"$",
"key",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"mergeable_keys_map",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"cache",
"[",
"$",
"key",
"]",
"=",
"$",
"cache",
"[",
"$",
"key",
"]",
"+",
"$",
"fallback_cache",
"[",
"$",
"key",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"this",
"->",
"mergeable_keys_list",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"cache",
"[",
"$",
"key",
"]",
"=",
"array_merge",
"(",
"$",
"fallback_cache",
"[",
"$",
"key",
"]",
",",
"$",
"cache",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"cache",
"[",
"$",
"key",
"]",
"=",
"$",
"fallback_cache",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"}",
"// save to cache for later retrieval",
"$",
"this",
"->",
"cache",
"[",
"$",
"code",
"]",
"=",
"$",
"cache",
";",
"return",
";",
"}"
]
| Loads language into the cache, handles message file and fallbacks
@param $code string language code | [
"Loads",
"language",
"into",
"the",
"cache",
"handles",
"message",
"file",
"and",
"fallbacks"
]
| ecffed0d75be1454901e1cb24633472b8f67c967 | https://github.com/nyeholt/silverstripe-simplewiki/blob/ecffed0d75be1454901e1cb24633472b8f67c967/thirdparty/htmlpurifier-4.0.0-lite/library/HTMLPurifier/LanguageFactory.php#L138-L194 |
14,366 | epierce/cas-rest-client | src/CasRestClient.php | CasRestClient.setCasServer | public function setCasServer($server)
{
$this->casServer = $server;
$this->guzzleClient = new Client(['base_uri' => $server, 'cookies' => true]);
} | php | public function setCasServer($server)
{
$this->casServer = $server;
$this->guzzleClient = new Client(['base_uri' => $server, 'cookies' => true]);
} | [
"public",
"function",
"setCasServer",
"(",
"$",
"server",
")",
"{",
"$",
"this",
"->",
"casServer",
"=",
"$",
"server",
";",
"$",
"this",
"->",
"guzzleClient",
"=",
"new",
"Client",
"(",
"[",
"'base_uri'",
"=>",
"$",
"server",
",",
"'cookies'",
"=>",
"true",
"]",
")",
";",
"}"
]
| Set the CAS server URL
@param string $server | [
"Set",
"the",
"CAS",
"server",
"URL"
]
| 342ce958ec5ce40d182a4ffad59c9fa123564ecd | https://github.com/epierce/cas-rest-client/blob/342ce958ec5ce40d182a4ffad59c9fa123564ecd/src/CasRestClient.php#L57-L61 |
14,367 | epierce/cas-rest-client | src/CasRestClient.php | CasRestClient.setTGT | public function setTGT($tgt)
{
$this->tgt = $tgt;
$this->tgtLocation = $this->casServer . $this->casRESTcontext . '/' . $tgt;
} | php | public function setTGT($tgt)
{
$this->tgt = $tgt;
$this->tgtLocation = $this->casServer . $this->casRESTcontext . '/' . $tgt;
} | [
"public",
"function",
"setTGT",
"(",
"$",
"tgt",
")",
"{",
"$",
"this",
"->",
"tgt",
"=",
"$",
"tgt",
";",
"$",
"this",
"->",
"tgtLocation",
"=",
"$",
"this",
"->",
"casServer",
".",
"$",
"this",
"->",
"casRESTcontext",
".",
"'/'",
".",
"$",
"tgt",
";",
"}"
]
| Accepts the Ticket-Granting Ticket from the app running the client.
@param string $tgt | [
"Accepts",
"the",
"Ticket",
"-",
"Granting",
"Ticket",
"from",
"the",
"app",
"running",
"the",
"client",
"."
]
| 342ce958ec5ce40d182a4ffad59c9fa123564ecd | https://github.com/epierce/cas-rest-client/blob/342ce958ec5ce40d182a4ffad59c9fa123564ecd/src/CasRestClient.php#L130-L134 |
14,368 | epierce/cas-rest-client | src/CasRestClient.php | CasRestClient.logout | public function logout()
{
// Make sure a TGT exists
$this->checkTgtExists();
$this->guzzleClient->delete($this->tgtLocation);
$this->tgtLocation = null;
$this->tgt = null;
// Remove the TGT storage file
if ($this->tgtStorageLocation) {
unlink($this->tgtStorageLocation);
}
return true;
} | php | public function logout()
{
// Make sure a TGT exists
$this->checkTgtExists();
$this->guzzleClient->delete($this->tgtLocation);
$this->tgtLocation = null;
$this->tgt = null;
// Remove the TGT storage file
if ($this->tgtStorageLocation) {
unlink($this->tgtStorageLocation);
}
return true;
} | [
"public",
"function",
"logout",
"(",
")",
"{",
"// Make sure a TGT exists",
"$",
"this",
"->",
"checkTgtExists",
"(",
")",
";",
"$",
"this",
"->",
"guzzleClient",
"->",
"delete",
"(",
"$",
"this",
"->",
"tgtLocation",
")",
";",
"$",
"this",
"->",
"tgtLocation",
"=",
"null",
";",
"$",
"this",
"->",
"tgt",
"=",
"null",
";",
"// Remove the TGT storage file",
"if",
"(",
"$",
"this",
"->",
"tgtStorageLocation",
")",
"{",
"unlink",
"(",
"$",
"this",
"->",
"tgtStorageLocation",
")",
";",
"}",
"return",
"true",
";",
"}"
]
| Logout of the CAS session and destroy the TGT.
@return bool
@throws \Exception | [
"Logout",
"of",
"the",
"CAS",
"session",
"and",
"destroy",
"the",
"TGT",
"."
]
| 342ce958ec5ce40d182a4ffad59c9fa123564ecd | https://github.com/epierce/cas-rest-client/blob/342ce958ec5ce40d182a4ffad59c9fa123564ecd/src/CasRestClient.php#L142-L157 |
14,369 | epierce/cas-rest-client | src/CasRestClient.php | CasRestClient.post | public function post($service, $headers = [], $body = '', $form_params = [])
{
return $this->callRestService('POST', $service, $headers, $body, $form_params);
} | php | public function post($service, $headers = [], $body = '', $form_params = [])
{
return $this->callRestService('POST', $service, $headers, $body, $form_params);
} | [
"public",
"function",
"post",
"(",
"$",
"service",
",",
"$",
"headers",
"=",
"[",
"]",
",",
"$",
"body",
"=",
"''",
",",
"$",
"form_params",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"callRestService",
"(",
"'POST'",
",",
"$",
"service",
",",
"$",
"headers",
",",
"$",
"body",
",",
"$",
"form_params",
")",
";",
"}"
]
| Request a Service Ticket for the CAS server and perform a HTTP POST operation.
@param $service
@param array $headers
@param array $body
@return mixed
@throws \Exception | [
"Request",
"a",
"Service",
"Ticket",
"for",
"the",
"CAS",
"server",
"and",
"perform",
"a",
"HTTP",
"POST",
"operation",
"."
]
| 342ce958ec5ce40d182a4ffad59c9fa123564ecd | https://github.com/epierce/cas-rest-client/blob/342ce958ec5ce40d182a4ffad59c9fa123564ecd/src/CasRestClient.php#L182-L185 |
14,370 | epierce/cas-rest-client | src/CasRestClient.php | CasRestClient.patch | public function patch($service, $headers = [], $body = '', $form_params = [])
{
return $this->callRestService('PATCH', $service, $headers, $body, $form_params);
} | php | public function patch($service, $headers = [], $body = '', $form_params = [])
{
return $this->callRestService('PATCH', $service, $headers, $body, $form_params);
} | [
"public",
"function",
"patch",
"(",
"$",
"service",
",",
"$",
"headers",
"=",
"[",
"]",
",",
"$",
"body",
"=",
"''",
",",
"$",
"form_params",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"callRestService",
"(",
"'PATCH'",
",",
"$",
"service",
",",
"$",
"headers",
",",
"$",
"body",
",",
"$",
"form_params",
")",
";",
"}"
]
| Request a Service Ticket for the CAS server and perform a HTTP PATCH operation.
@param $service
@param array $headers
@param array $body
@return mixed
@throws \Exception | [
"Request",
"a",
"Service",
"Ticket",
"for",
"the",
"CAS",
"server",
"and",
"perform",
"a",
"HTTP",
"PATCH",
"operation",
"."
]
| 342ce958ec5ce40d182a4ffad59c9fa123564ecd | https://github.com/epierce/cas-rest-client/blob/342ce958ec5ce40d182a4ffad59c9fa123564ecd/src/CasRestClient.php#L196-L199 |
14,371 | epierce/cas-rest-client | src/CasRestClient.php | CasRestClient.head | public function head($service, $headers = [], $body = '', $form_params = [])
{
return $this->callRestService('HEAD', $service, $headers, $body, $form_params);
} | php | public function head($service, $headers = [], $body = '', $form_params = [])
{
return $this->callRestService('HEAD', $service, $headers, $body, $form_params);
} | [
"public",
"function",
"head",
"(",
"$",
"service",
",",
"$",
"headers",
"=",
"[",
"]",
",",
"$",
"body",
"=",
"''",
",",
"$",
"form_params",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"callRestService",
"(",
"'HEAD'",
",",
"$",
"service",
",",
"$",
"headers",
",",
"$",
"body",
",",
"$",
"form_params",
")",
";",
"}"
]
| Request a Service Ticket for the CAS server and perform a HTTP HEAD operation.
@param $service
@param array $headers
@param array $body
@return mixed
@throws \Exception | [
"Request",
"a",
"Service",
"Ticket",
"for",
"the",
"CAS",
"server",
"and",
"perform",
"a",
"HTTP",
"HEAD",
"operation",
"."
]
| 342ce958ec5ce40d182a4ffad59c9fa123564ecd | https://github.com/epierce/cas-rest-client/blob/342ce958ec5ce40d182a4ffad59c9fa123564ecd/src/CasRestClient.php#L210-L213 |
14,372 | epierce/cas-rest-client | src/CasRestClient.php | CasRestClient.put | public function put($service, $headers = [], $body = '', $form_params = [])
{
return $this->callRestService('PUT', $service, $headers, $body, $form_params);
} | php | public function put($service, $headers = [], $body = '', $form_params = [])
{
return $this->callRestService('PUT', $service, $headers, $body, $form_params);
} | [
"public",
"function",
"put",
"(",
"$",
"service",
",",
"$",
"headers",
"=",
"[",
"]",
",",
"$",
"body",
"=",
"''",
",",
"$",
"form_params",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"callRestService",
"(",
"'PUT'",
",",
"$",
"service",
",",
"$",
"headers",
",",
"$",
"body",
",",
"$",
"form_params",
")",
";",
"}"
]
| Request a Service Ticket for the CAS server and perform a HTTP PUT operation.
@param $service
@param array $headers
@param array $body
@return mixed
@throws \Exception | [
"Request",
"a",
"Service",
"Ticket",
"for",
"the",
"CAS",
"server",
"and",
"perform",
"a",
"HTTP",
"PUT",
"operation",
"."
]
| 342ce958ec5ce40d182a4ffad59c9fa123564ecd | https://github.com/epierce/cas-rest-client/blob/342ce958ec5ce40d182a4ffad59c9fa123564ecd/src/CasRestClient.php#L224-L227 |
14,373 | epierce/cas-rest-client | src/CasRestClient.php | CasRestClient.options | public function options($service, $headers = [], $body = '', $form_params = [])
{
return $this->callRestService('OPTIONS', $service, $headers, $body, $form_params);
} | php | public function options($service, $headers = [], $body = '', $form_params = [])
{
return $this->callRestService('OPTIONS', $service, $headers, $body, $form_params);
} | [
"public",
"function",
"options",
"(",
"$",
"service",
",",
"$",
"headers",
"=",
"[",
"]",
",",
"$",
"body",
"=",
"''",
",",
"$",
"form_params",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"callRestService",
"(",
"'OPTIONS'",
",",
"$",
"service",
",",
"$",
"headers",
",",
"$",
"body",
",",
"$",
"form_params",
")",
";",
"}"
]
| Request a Service Ticket for the CAS server and perform a HTTP OPTIONS operation.
@param $service
@param array $headers
@param array $body
@return mixed
@throws \Exception | [
"Request",
"a",
"Service",
"Ticket",
"for",
"the",
"CAS",
"server",
"and",
"perform",
"a",
"HTTP",
"OPTIONS",
"operation",
"."
]
| 342ce958ec5ce40d182a4ffad59c9fa123564ecd | https://github.com/epierce/cas-rest-client/blob/342ce958ec5ce40d182a4ffad59c9fa123564ecd/src/CasRestClient.php#L238-L241 |
14,374 | epierce/cas-rest-client | src/CasRestClient.php | CasRestClient.delete | public function delete($service, $headers = [], $body = '', $form_params = [])
{
return $this->callRestService('DELETE', $service, $headers, $body, $form_params);
} | php | public function delete($service, $headers = [], $body = '', $form_params = [])
{
return $this->callRestService('DELETE', $service, $headers, $body, $form_params);
} | [
"public",
"function",
"delete",
"(",
"$",
"service",
",",
"$",
"headers",
"=",
"[",
"]",
",",
"$",
"body",
"=",
"''",
",",
"$",
"form_params",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"callRestService",
"(",
"'DELETE'",
",",
"$",
"service",
",",
"$",
"headers",
",",
"$",
"body",
",",
"$",
"form_params",
")",
";",
"}"
]
| Request a Service Ticket for the CAS server and perform a HTTP DELETE operation.
@param $service
@param array $headers
@param array $body
@return mixed
@throws \Exception | [
"Request",
"a",
"Service",
"Ticket",
"for",
"the",
"CAS",
"server",
"and",
"perform",
"a",
"HTTP",
"DELETE",
"operation",
"."
]
| 342ce958ec5ce40d182a4ffad59c9fa123564ecd | https://github.com/epierce/cas-rest-client/blob/342ce958ec5ce40d182a4ffad59c9fa123564ecd/src/CasRestClient.php#L252-L255 |
14,375 | epierce/cas-rest-client | src/CasRestClient.php | CasRestClient.callRestService | private function callRestService($method, $service, $headers = [], $body = '', $form_params = [])
{
// Make sure a TGT exists
$this->checkTgtExists();
$serviceTicket = $this->getServiceTicket($service);
// Append the ticket to the end of the service's parameters
if (strpos($service, '?') === false) {
$finalService = $service . '?ticket=' . $serviceTicket;
} else {
$finalService = $service . '&ticket=' . $serviceTicket;
}
$jar = new \GuzzleHttp\Cookie\CookieJar;
$options = [
'cookies' => $jar,
'body' => $body,
'form_params' => $form_params,
'headers' => $this->setGuzzleHeaders($headers),
'verify' => $this->verifySSL
];
switch ($method) {
case 'GET':
$result = $this->guzzleClient->get($finalService, $options);
break;
case 'HEAD':
$result = $this->guzzleClient->head($finalService, $options);
break;
case 'POST':
$result = $this->guzzleClient->post($finalService, $options);
break;
case 'PUT':
$result = $this->guzzleClient->put($finalService, $options);
break;
case 'PATCH':
$result = $this->guzzleClient->patch($finalService, $options);
break;
case 'DELETE':
$result = $this->guzzleClient->delete($finalService, $options);
break;
default:
throw new \Exception('Unsupported HTTP method: ' . $method, 500);
}
return $result;
} | php | private function callRestService($method, $service, $headers = [], $body = '', $form_params = [])
{
// Make sure a TGT exists
$this->checkTgtExists();
$serviceTicket = $this->getServiceTicket($service);
// Append the ticket to the end of the service's parameters
if (strpos($service, '?') === false) {
$finalService = $service . '?ticket=' . $serviceTicket;
} else {
$finalService = $service . '&ticket=' . $serviceTicket;
}
$jar = new \GuzzleHttp\Cookie\CookieJar;
$options = [
'cookies' => $jar,
'body' => $body,
'form_params' => $form_params,
'headers' => $this->setGuzzleHeaders($headers),
'verify' => $this->verifySSL
];
switch ($method) {
case 'GET':
$result = $this->guzzleClient->get($finalService, $options);
break;
case 'HEAD':
$result = $this->guzzleClient->head($finalService, $options);
break;
case 'POST':
$result = $this->guzzleClient->post($finalService, $options);
break;
case 'PUT':
$result = $this->guzzleClient->put($finalService, $options);
break;
case 'PATCH':
$result = $this->guzzleClient->patch($finalService, $options);
break;
case 'DELETE':
$result = $this->guzzleClient->delete($finalService, $options);
break;
default:
throw new \Exception('Unsupported HTTP method: ' . $method, 500);
}
return $result;
} | [
"private",
"function",
"callRestService",
"(",
"$",
"method",
",",
"$",
"service",
",",
"$",
"headers",
"=",
"[",
"]",
",",
"$",
"body",
"=",
"''",
",",
"$",
"form_params",
"=",
"[",
"]",
")",
"{",
"// Make sure a TGT exists",
"$",
"this",
"->",
"checkTgtExists",
"(",
")",
";",
"$",
"serviceTicket",
"=",
"$",
"this",
"->",
"getServiceTicket",
"(",
"$",
"service",
")",
";",
"// Append the ticket to the end of the service's parameters",
"if",
"(",
"strpos",
"(",
"$",
"service",
",",
"'?'",
")",
"===",
"false",
")",
"{",
"$",
"finalService",
"=",
"$",
"service",
".",
"'?ticket='",
".",
"$",
"serviceTicket",
";",
"}",
"else",
"{",
"$",
"finalService",
"=",
"$",
"service",
".",
"'&ticket='",
".",
"$",
"serviceTicket",
";",
"}",
"$",
"jar",
"=",
"new",
"\\",
"GuzzleHttp",
"\\",
"Cookie",
"\\",
"CookieJar",
";",
"$",
"options",
"=",
"[",
"'cookies'",
"=>",
"$",
"jar",
",",
"'body'",
"=>",
"$",
"body",
",",
"'form_params'",
"=>",
"$",
"form_params",
",",
"'headers'",
"=>",
"$",
"this",
"->",
"setGuzzleHeaders",
"(",
"$",
"headers",
")",
",",
"'verify'",
"=>",
"$",
"this",
"->",
"verifySSL",
"]",
";",
"switch",
"(",
"$",
"method",
")",
"{",
"case",
"'GET'",
":",
"$",
"result",
"=",
"$",
"this",
"->",
"guzzleClient",
"->",
"get",
"(",
"$",
"finalService",
",",
"$",
"options",
")",
";",
"break",
";",
"case",
"'HEAD'",
":",
"$",
"result",
"=",
"$",
"this",
"->",
"guzzleClient",
"->",
"head",
"(",
"$",
"finalService",
",",
"$",
"options",
")",
";",
"break",
";",
"case",
"'POST'",
":",
"$",
"result",
"=",
"$",
"this",
"->",
"guzzleClient",
"->",
"post",
"(",
"$",
"finalService",
",",
"$",
"options",
")",
";",
"break",
";",
"case",
"'PUT'",
":",
"$",
"result",
"=",
"$",
"this",
"->",
"guzzleClient",
"->",
"put",
"(",
"$",
"finalService",
",",
"$",
"options",
")",
";",
"break",
";",
"case",
"'PATCH'",
":",
"$",
"result",
"=",
"$",
"this",
"->",
"guzzleClient",
"->",
"patch",
"(",
"$",
"finalService",
",",
"$",
"options",
")",
";",
"break",
";",
"case",
"'DELETE'",
":",
"$",
"result",
"=",
"$",
"this",
"->",
"guzzleClient",
"->",
"delete",
"(",
"$",
"finalService",
",",
"$",
"options",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"Exception",
"(",
"'Unsupported HTTP method: '",
".",
"$",
"method",
",",
"500",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
]
| Set up and execute a REST request.
@param $method
@param $service
@param array $headers
@param array $body
@return mixed|null
@throws \Exception | [
"Set",
"up",
"and",
"execute",
"a",
"REST",
"request",
"."
]
| 342ce958ec5ce40d182a4ffad59c9fa123564ecd | https://github.com/epierce/cas-rest-client/blob/342ce958ec5ce40d182a4ffad59c9fa123564ecd/src/CasRestClient.php#L279-L333 |
14,376 | epierce/cas-rest-client | src/CasRestClient.php | CasRestClient.getServiceTicket | private function getServiceTicket($service)
{
try {
$response = $this->guzzleClient->request(
'POST',
$this->tgtLocation,
[
'verify' => $this->verifySSL,
'form_params' => [
'service' => $service
]
]
);
return (string) $response->getBody();
} catch (ClientException $e) {
// Bad TGT - login again
if ($e->getCode() == 404) {
// Force authentication and save the TGT
$this->login($this->tgtStorageLocation, true);
return $this->getServiceTicket($service);
// Unsupported Media Type
} elseif ($e->getCode() == 415) {
return false;
} else {
throw new \Exception($e->getMessage(), $e->getCode());
}
} catch (\Exception $e) {
throw new \Exception($e->getMessage(), $e->getCode());
}
} | php | private function getServiceTicket($service)
{
try {
$response = $this->guzzleClient->request(
'POST',
$this->tgtLocation,
[
'verify' => $this->verifySSL,
'form_params' => [
'service' => $service
]
]
);
return (string) $response->getBody();
} catch (ClientException $e) {
// Bad TGT - login again
if ($e->getCode() == 404) {
// Force authentication and save the TGT
$this->login($this->tgtStorageLocation, true);
return $this->getServiceTicket($service);
// Unsupported Media Type
} elseif ($e->getCode() == 415) {
return false;
} else {
throw new \Exception($e->getMessage(), $e->getCode());
}
} catch (\Exception $e) {
throw new \Exception($e->getMessage(), $e->getCode());
}
} | [
"private",
"function",
"getServiceTicket",
"(",
"$",
"service",
")",
"{",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"guzzleClient",
"->",
"request",
"(",
"'POST'",
",",
"$",
"this",
"->",
"tgtLocation",
",",
"[",
"'verify'",
"=>",
"$",
"this",
"->",
"verifySSL",
",",
"'form_params'",
"=>",
"[",
"'service'",
"=>",
"$",
"service",
"]",
"]",
")",
";",
"return",
"(",
"string",
")",
"$",
"response",
"->",
"getBody",
"(",
")",
";",
"}",
"catch",
"(",
"ClientException",
"$",
"e",
")",
"{",
"// Bad TGT - login again",
"if",
"(",
"$",
"e",
"->",
"getCode",
"(",
")",
"==",
"404",
")",
"{",
"// Force authentication and save the TGT",
"$",
"this",
"->",
"login",
"(",
"$",
"this",
"->",
"tgtStorageLocation",
",",
"true",
")",
";",
"return",
"$",
"this",
"->",
"getServiceTicket",
"(",
"$",
"service",
")",
";",
"// Unsupported Media Type",
"}",
"elseif",
"(",
"$",
"e",
"->",
"getCode",
"(",
")",
"==",
"415",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
")",
";",
"}",
"}"
]
| Request Service ticket from CAS server
@param $service
@return bool|\GuzzleHttp\Stream\StreamInterface|null
@throws \Exception | [
"Request",
"Service",
"ticket",
"from",
"CAS",
"server"
]
| 342ce958ec5ce40d182a4ffad59c9fa123564ecd | https://github.com/epierce/cas-rest-client/blob/342ce958ec5ce40d182a4ffad59c9fa123564ecd/src/CasRestClient.php#L342-L373 |
14,377 | epierce/cas-rest-client | src/CasRestClient.php | CasRestClient.login | public function login($tgtStorageLocation = '', $forceAuth = false)
{
if ((!$this->casServer) || (!$this->casPassword) || (!$this->casUsername)) {
throw new \Exception('CAS server and credentials must be set before calling login()', 1);
}
$this->tgtStorageLocation = $tgtStorageLocation;
// Try to load the TGT from the storage file
if (!$forceAuth && $tgtStorageLocation) {
if (file_exists($tgtStorageLocation)) {
if (! is_readable($tgtStorageLocation)) {
throw new \Exception('TGT storage file [' . $tgtStorageLocation . '] is not readable!', 500);
}
$this->loadTGTfromFile($tgtStorageLocation);
return true;
}
}
try {
$response = $this->guzzleClient->request(
'POST',
$this->casRESTcontext,
[
'verify' => $this->verifySSL,
'form_params' => [
'username' => $this->casUsername,
'password' => $this->casPassword
]
]
);
$responseHeaders = $response->getHeaders();
} catch (ClientException $e) {
// Bad username or password.
if ($e->getCode() == 400) {
return false;
// Unsupported Media Type
} elseif ($e->getCode() == 415) {
return false;
} else {
throw new \Exception($e->getMessage(), $e->getCode());
}
} catch (\Exception $e) {
throw new \Exception($e->getMessage(), $e->getCode());
}
if (isset($responseHeaders['Location'][0])) {
$this->tgtLocation = $responseHeaders['Location'][0];
$this->tgt = substr(strrchr($this->tgtLocation, '/'), 1);
}
// Save the TGT to a storage file.
if ($tgtStorageLocation) {
$this->writeTGTtoFile($tgtStorageLocation, $this->tgt);
}
return true;
} | php | public function login($tgtStorageLocation = '', $forceAuth = false)
{
if ((!$this->casServer) || (!$this->casPassword) || (!$this->casUsername)) {
throw new \Exception('CAS server and credentials must be set before calling login()', 1);
}
$this->tgtStorageLocation = $tgtStorageLocation;
// Try to load the TGT from the storage file
if (!$forceAuth && $tgtStorageLocation) {
if (file_exists($tgtStorageLocation)) {
if (! is_readable($tgtStorageLocation)) {
throw new \Exception('TGT storage file [' . $tgtStorageLocation . '] is not readable!', 500);
}
$this->loadTGTfromFile($tgtStorageLocation);
return true;
}
}
try {
$response = $this->guzzleClient->request(
'POST',
$this->casRESTcontext,
[
'verify' => $this->verifySSL,
'form_params' => [
'username' => $this->casUsername,
'password' => $this->casPassword
]
]
);
$responseHeaders = $response->getHeaders();
} catch (ClientException $e) {
// Bad username or password.
if ($e->getCode() == 400) {
return false;
// Unsupported Media Type
} elseif ($e->getCode() == 415) {
return false;
} else {
throw new \Exception($e->getMessage(), $e->getCode());
}
} catch (\Exception $e) {
throw new \Exception($e->getMessage(), $e->getCode());
}
if (isset($responseHeaders['Location'][0])) {
$this->tgtLocation = $responseHeaders['Location'][0];
$this->tgt = substr(strrchr($this->tgtLocation, '/'), 1);
}
// Save the TGT to a storage file.
if ($tgtStorageLocation) {
$this->writeTGTtoFile($tgtStorageLocation, $this->tgt);
}
return true;
} | [
"public",
"function",
"login",
"(",
"$",
"tgtStorageLocation",
"=",
"''",
",",
"$",
"forceAuth",
"=",
"false",
")",
"{",
"if",
"(",
"(",
"!",
"$",
"this",
"->",
"casServer",
")",
"||",
"(",
"!",
"$",
"this",
"->",
"casPassword",
")",
"||",
"(",
"!",
"$",
"this",
"->",
"casUsername",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'CAS server and credentials must be set before calling login()'",
",",
"1",
")",
";",
"}",
"$",
"this",
"->",
"tgtStorageLocation",
"=",
"$",
"tgtStorageLocation",
";",
"// Try to load the TGT from the storage file",
"if",
"(",
"!",
"$",
"forceAuth",
"&&",
"$",
"tgtStorageLocation",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"tgtStorageLocation",
")",
")",
"{",
"if",
"(",
"!",
"is_readable",
"(",
"$",
"tgtStorageLocation",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'TGT storage file ['",
".",
"$",
"tgtStorageLocation",
".",
"'] is not readable!'",
",",
"500",
")",
";",
"}",
"$",
"this",
"->",
"loadTGTfromFile",
"(",
"$",
"tgtStorageLocation",
")",
";",
"return",
"true",
";",
"}",
"}",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"guzzleClient",
"->",
"request",
"(",
"'POST'",
",",
"$",
"this",
"->",
"casRESTcontext",
",",
"[",
"'verify'",
"=>",
"$",
"this",
"->",
"verifySSL",
",",
"'form_params'",
"=>",
"[",
"'username'",
"=>",
"$",
"this",
"->",
"casUsername",
",",
"'password'",
"=>",
"$",
"this",
"->",
"casPassword",
"]",
"]",
")",
";",
"$",
"responseHeaders",
"=",
"$",
"response",
"->",
"getHeaders",
"(",
")",
";",
"}",
"catch",
"(",
"ClientException",
"$",
"e",
")",
"{",
"// Bad username or password.",
"if",
"(",
"$",
"e",
"->",
"getCode",
"(",
")",
"==",
"400",
")",
"{",
"return",
"false",
";",
"// Unsupported Media Type",
"}",
"elseif",
"(",
"$",
"e",
"->",
"getCode",
"(",
")",
"==",
"415",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"responseHeaders",
"[",
"'Location'",
"]",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"tgtLocation",
"=",
"$",
"responseHeaders",
"[",
"'Location'",
"]",
"[",
"0",
"]",
";",
"$",
"this",
"->",
"tgt",
"=",
"substr",
"(",
"strrchr",
"(",
"$",
"this",
"->",
"tgtLocation",
",",
"'/'",
")",
",",
"1",
")",
";",
"}",
"// Save the TGT to a storage file.",
"if",
"(",
"$",
"tgtStorageLocation",
")",
"{",
"$",
"this",
"->",
"writeTGTtoFile",
"(",
"$",
"tgtStorageLocation",
",",
"$",
"this",
"->",
"tgt",
")",
";",
"}",
"return",
"true",
";",
"}"
]
| Validate credentials against the CAS server and retrieve a Ticket-Granting Ticket. If a tgtStorageLocation is
specified, the fle is read and the saved TGT is used instead of validating credentials. If force_auth is TRUE,
always validate credentials.
@param string $tgtStorageLocation
@param bool $forceAuth
@return bool
@throws \Exception | [
"Validate",
"credentials",
"against",
"the",
"CAS",
"server",
"and",
"retrieve",
"a",
"Ticket",
"-",
"Granting",
"Ticket",
".",
"If",
"a",
"tgtStorageLocation",
"is",
"specified",
"the",
"fle",
"is",
"read",
"and",
"the",
"saved",
"TGT",
"is",
"used",
"instead",
"of",
"validating",
"credentials",
".",
"If",
"force_auth",
"is",
"TRUE",
"always",
"validate",
"credentials",
"."
]
| 342ce958ec5ce40d182a4ffad59c9fa123564ecd | https://github.com/epierce/cas-rest-client/blob/342ce958ec5ce40d182a4ffad59c9fa123564ecd/src/CasRestClient.php#L385-L445 |
14,378 | epierce/cas-rest-client | src/CasRestClient.php | CasRestClient.loadTGTfromFile | private function loadTGTfromFile($tgtStorageLocation)
{
$tgtStorageData = json_decode(file_get_contents($tgtStorageLocation), true);
if ($tgtStorageData['username']) {
$this->casUsername = $tgtStorageData['username'];
} else {
throw new \Exception('TGT storage missing "username" value!', 551);
}
if ($tgtStorageData['server']) {
$this->casServer = $tgtStorageData['server'];
} else {
throw new \Exception('TGT storage missing "server" value!', 552);
}
if ($tgtStorageData['context']) {
$this->casRESTcontext = $tgtStorageData['context'];
} else {
throw new \Exception('TGT storage missing "context" value!', 552);
}
if ($tgtStorageData['TGT']) {
$this->tgt = $tgtStorageData['TGT'];
$this->tgtLocation = $this->casServer . $this->casRESTcontext . '/' . $this->tgt;
} else {
throw new \Exception('TGT storage missing "TGT" value!', 552);
}
} | php | private function loadTGTfromFile($tgtStorageLocation)
{
$tgtStorageData = json_decode(file_get_contents($tgtStorageLocation), true);
if ($tgtStorageData['username']) {
$this->casUsername = $tgtStorageData['username'];
} else {
throw new \Exception('TGT storage missing "username" value!', 551);
}
if ($tgtStorageData['server']) {
$this->casServer = $tgtStorageData['server'];
} else {
throw new \Exception('TGT storage missing "server" value!', 552);
}
if ($tgtStorageData['context']) {
$this->casRESTcontext = $tgtStorageData['context'];
} else {
throw new \Exception('TGT storage missing "context" value!', 552);
}
if ($tgtStorageData['TGT']) {
$this->tgt = $tgtStorageData['TGT'];
$this->tgtLocation = $this->casServer . $this->casRESTcontext . '/' . $this->tgt;
} else {
throw new \Exception('TGT storage missing "TGT" value!', 552);
}
} | [
"private",
"function",
"loadTGTfromFile",
"(",
"$",
"tgtStorageLocation",
")",
"{",
"$",
"tgtStorageData",
"=",
"json_decode",
"(",
"file_get_contents",
"(",
"$",
"tgtStorageLocation",
")",
",",
"true",
")",
";",
"if",
"(",
"$",
"tgtStorageData",
"[",
"'username'",
"]",
")",
"{",
"$",
"this",
"->",
"casUsername",
"=",
"$",
"tgtStorageData",
"[",
"'username'",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'TGT storage missing \"username\" value!'",
",",
"551",
")",
";",
"}",
"if",
"(",
"$",
"tgtStorageData",
"[",
"'server'",
"]",
")",
"{",
"$",
"this",
"->",
"casServer",
"=",
"$",
"tgtStorageData",
"[",
"'server'",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'TGT storage missing \"server\" value!'",
",",
"552",
")",
";",
"}",
"if",
"(",
"$",
"tgtStorageData",
"[",
"'context'",
"]",
")",
"{",
"$",
"this",
"->",
"casRESTcontext",
"=",
"$",
"tgtStorageData",
"[",
"'context'",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'TGT storage missing \"context\" value!'",
",",
"552",
")",
";",
"}",
"if",
"(",
"$",
"tgtStorageData",
"[",
"'TGT'",
"]",
")",
"{",
"$",
"this",
"->",
"tgt",
"=",
"$",
"tgtStorageData",
"[",
"'TGT'",
"]",
";",
"$",
"this",
"->",
"tgtLocation",
"=",
"$",
"this",
"->",
"casServer",
".",
"$",
"this",
"->",
"casRESTcontext",
".",
"'/'",
".",
"$",
"this",
"->",
"tgt",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'TGT storage missing \"TGT\" value!'",
",",
"552",
")",
";",
"}",
"}"
]
| Read the TGT data from a file
@param string $tgtStorageLocation
@throws \Exception | [
"Read",
"the",
"TGT",
"data",
"from",
"a",
"file"
]
| 342ce958ec5ce40d182a4ffad59c9fa123564ecd | https://github.com/epierce/cas-rest-client/blob/342ce958ec5ce40d182a4ffad59c9fa123564ecd/src/CasRestClient.php#L453-L478 |
14,379 | epierce/cas-rest-client | src/CasRestClient.php | CasRestClient.writeTGTtoFile | private function writeTGTtoFile($tgtStorageLocation, $tgt)
{
$tgtStorageData = [
'TGT' => $tgt,
'username' => $this->casUsername,
'server' => $this->casServer,
'context' => $this->casRESTcontext,
'saved' => time()
];
file_put_contents($tgtStorageLocation, json_encode($tgtStorageData));
} | php | private function writeTGTtoFile($tgtStorageLocation, $tgt)
{
$tgtStorageData = [
'TGT' => $tgt,
'username' => $this->casUsername,
'server' => $this->casServer,
'context' => $this->casRESTcontext,
'saved' => time()
];
file_put_contents($tgtStorageLocation, json_encode($tgtStorageData));
} | [
"private",
"function",
"writeTGTtoFile",
"(",
"$",
"tgtStorageLocation",
",",
"$",
"tgt",
")",
"{",
"$",
"tgtStorageData",
"=",
"[",
"'TGT'",
"=>",
"$",
"tgt",
",",
"'username'",
"=>",
"$",
"this",
"->",
"casUsername",
",",
"'server'",
"=>",
"$",
"this",
"->",
"casServer",
",",
"'context'",
"=>",
"$",
"this",
"->",
"casRESTcontext",
",",
"'saved'",
"=>",
"time",
"(",
")",
"]",
";",
"file_put_contents",
"(",
"$",
"tgtStorageLocation",
",",
"json_encode",
"(",
"$",
"tgtStorageData",
")",
")",
";",
"}"
]
| Save the TGT data to a local file
@param string $tgtStorageLocation
@param string $tgt | [
"Save",
"the",
"TGT",
"data",
"to",
"a",
"local",
"file"
]
| 342ce958ec5ce40d182a4ffad59c9fa123564ecd | https://github.com/epierce/cas-rest-client/blob/342ce958ec5ce40d182a4ffad59c9fa123564ecd/src/CasRestClient.php#L486-L497 |
14,380 | lukebro/flash | src/lukebro/Flash/FlashFactory.php | FlashFactory.create | public function create($level, $message)
{
$this->next[] = ['level' => $level, 'message' => $message];
$this->session->flash($this->key, $this->next);
return $this;
} | php | public function create($level, $message)
{
$this->next[] = ['level' => $level, 'message' => $message];
$this->session->flash($this->key, $this->next);
return $this;
} | [
"public",
"function",
"create",
"(",
"$",
"level",
",",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"next",
"[",
"]",
"=",
"[",
"'level'",
"=>",
"$",
"level",
",",
"'message'",
"=>",
"$",
"message",
"]",
";",
"$",
"this",
"->",
"session",
"->",
"flash",
"(",
"$",
"this",
"->",
"key",
",",
"$",
"this",
"->",
"next",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Create a new flash message.
@param string $message
@param string $level
@return this | [
"Create",
"a",
"new",
"flash",
"message",
"."
]
| 5cecd16e6fe399cd8a222084f4f50fc813110ef9 | https://github.com/lukebro/flash/blob/5cecd16e6fe399cd8a222084f4f50fc813110ef9/src/lukebro/Flash/FlashFactory.php#L57-L64 |
14,381 | lukebro/flash | src/lukebro/Flash/FlashFactory.php | FlashFactory.again | public function again()
{
$this->next = $this->current->map(function ($item) {
return $item->toArray();
})->merge($this->next)->toArray();
$this->session->keep([$this->key]);
} | php | public function again()
{
$this->next = $this->current->map(function ($item) {
return $item->toArray();
})->merge($this->next)->toArray();
$this->session->keep([$this->key]);
} | [
"public",
"function",
"again",
"(",
")",
"{",
"$",
"this",
"->",
"next",
"=",
"$",
"this",
"->",
"current",
"->",
"map",
"(",
"function",
"(",
"$",
"item",
")",
"{",
"return",
"$",
"item",
"->",
"toArray",
"(",
")",
";",
"}",
")",
"->",
"merge",
"(",
"$",
"this",
"->",
"next",
")",
"->",
"toArray",
"(",
")",
";",
"$",
"this",
"->",
"session",
"->",
"keep",
"(",
"[",
"$",
"this",
"->",
"key",
"]",
")",
";",
"}"
]
| Reflash message to next session.
@return void | [
"Reflash",
"message",
"to",
"next",
"session",
"."
]
| 5cecd16e6fe399cd8a222084f4f50fc813110ef9 | https://github.com/lukebro/flash/blob/5cecd16e6fe399cd8a222084f4f50fc813110ef9/src/lukebro/Flash/FlashFactory.php#L92-L99 |
14,382 | lukebro/flash | src/lukebro/Flash/FlashFactory.php | FlashFactory.get | public function get($level = null)
{
if (isset($level)) {
return $this->getMessage();
}
return $this->current->where('level', $level);
} | php | public function get($level = null)
{
if (isset($level)) {
return $this->getMessage();
}
return $this->current->where('level', $level);
} | [
"public",
"function",
"get",
"(",
"$",
"level",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"level",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getMessage",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"current",
"->",
"where",
"(",
"'level'",
",",
"$",
"level",
")",
";",
"}"
]
| Get the current flash message.
@return string | [
"Get",
"the",
"current",
"flash",
"message",
"."
]
| 5cecd16e6fe399cd8a222084f4f50fc813110ef9 | https://github.com/lukebro/flash/blob/5cecd16e6fe399cd8a222084f4f50fc813110ef9/src/lukebro/Flash/FlashFactory.php#L126-L133 |
14,383 | lukebro/flash | src/lukebro/Flash/FlashFactory.php | FlashFactory.getFromSession | private function getFromSession()
{
if ($this->exists()) {
$flashes = $this->session->get($this->key);
foreach ($flashes as $flash) {
$this->current->push(new Flash($flash['level'], $flash['message']));
}
}
} | php | private function getFromSession()
{
if ($this->exists()) {
$flashes = $this->session->get($this->key);
foreach ($flashes as $flash) {
$this->current->push(new Flash($flash['level'], $flash['message']));
}
}
} | [
"private",
"function",
"getFromSession",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"exists",
"(",
")",
")",
"{",
"$",
"flashes",
"=",
"$",
"this",
"->",
"session",
"->",
"get",
"(",
"$",
"this",
"->",
"key",
")",
";",
"foreach",
"(",
"$",
"flashes",
"as",
"$",
"flash",
")",
"{",
"$",
"this",
"->",
"current",
"->",
"push",
"(",
"new",
"Flash",
"(",
"$",
"flash",
"[",
"'level'",
"]",
",",
"$",
"flash",
"[",
"'message'",
"]",
")",
")",
";",
"}",
"}",
"}"
]
| Get current flash message from session.
@return void | [
"Get",
"current",
"flash",
"message",
"from",
"session",
"."
]
| 5cecd16e6fe399cd8a222084f4f50fc813110ef9 | https://github.com/lukebro/flash/blob/5cecd16e6fe399cd8a222084f4f50fc813110ef9/src/lukebro/Flash/FlashFactory.php#L189-L198 |
14,384 | PandaPlatform/framework | src/Panda/Routing/Router.php | Router.gatherRoutes | protected function gatherRoutes()
{
// Get the base route path
$basePath = $this->container->get('app.base_path');
$routesPath = $this->container->get('app.routes_path');
// Include the route file
include $basePath . DIRECTORY_SEPARATOR . $routesPath;
} | php | protected function gatherRoutes()
{
// Get the base route path
$basePath = $this->container->get('app.base_path');
$routesPath = $this->container->get('app.routes_path');
// Include the route file
include $basePath . DIRECTORY_SEPARATOR . $routesPath;
} | [
"protected",
"function",
"gatherRoutes",
"(",
")",
"{",
"// Get the base route path",
"$",
"basePath",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'app.base_path'",
")",
";",
"$",
"routesPath",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'app.routes_path'",
")",
";",
"// Include the route file",
"include",
"$",
"basePath",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"routesPath",
";",
"}"
]
| Get all the routes that match to the given request.
@throws \DI\DependencyException
@throws \DI\NotFoundException
@throws \InvalidArgumentException | [
"Get",
"all",
"the",
"routes",
"that",
"match",
"to",
"the",
"given",
"request",
"."
]
| a78cf051b379896b5a4d5df620988e37a0e632f5 | https://github.com/PandaPlatform/framework/blob/a78cf051b379896b5a4d5df620988e37a0e632f5/src/Panda/Routing/Router.php#L402-L410 |
14,385 | markwatkinson/luminous | src/Luminous/Formatters/HtmlFormatter.php | HtmlFormatter.template | private static function template($t, $vars = array())
{
$t = preg_replace_callback('/\s+|<[^>]++>/', array('self', 'templateCb'), $t);
array_unshift($vars, $t);
$code = call_user_func_array('sprintf', $vars);
return $code;
} | php | private static function template($t, $vars = array())
{
$t = preg_replace_callback('/\s+|<[^>]++>/', array('self', 'templateCb'), $t);
array_unshift($vars, $t);
$code = call_user_func_array('sprintf', $vars);
return $code;
} | [
"private",
"static",
"function",
"template",
"(",
"$",
"t",
",",
"$",
"vars",
"=",
"array",
"(",
")",
")",
"{",
"$",
"t",
"=",
"preg_replace_callback",
"(",
"'/\\s+|<[^>]++>/'",
",",
"array",
"(",
"'self'",
",",
"'templateCb'",
")",
",",
"$",
"t",
")",
";",
"array_unshift",
"(",
"$",
"vars",
",",
"$",
"t",
")",
";",
"$",
"code",
"=",
"call_user_func_array",
"(",
"'sprintf'",
",",
"$",
"vars",
")",
";",
"return",
"$",
"code",
";",
"}"
]
| strips out unnecessary whitespace from a template | [
"strips",
"out",
"unnecessary",
"whitespace",
"from",
"a",
"template"
]
| 4adc18f414534abe986133d6d38e8e9787d32e69 | https://github.com/markwatkinson/luminous/blob/4adc18f414534abe986133d6d38e8e9787d32e69/src/Luminous/Formatters/HtmlFormatter.php#L41-L47 |
14,386 | markwatkinson/luminous | src/Luminous/Formatters/HtmlFormatter.php | HtmlFormatter.linkifyCb | protected function linkifyCb($matches)
{
$uri = (isset($matches[1]) && strlen(trim($matches[1]))) ? $matches[0] : "http://" . $matches[0];
// we dont want to link if it would cause malformed HTML
$openTags = array();
$closeTags = array();
preg_match_all("/<(?!\/)([^\s>]*).*?>/", $matches[0], $openTags, PREG_SET_ORDER);
preg_match_all("/<\/([^\s>]*).*?>/", $matches[0], $closeTags, PREG_SET_ORDER);
if (count($openTags) != count($closeTags)) {
return $matches[0];
}
if (isset($openTags[0]) && trim($openTags[0][1]) !== trim($closeTags[0][1])) {
return $matches[0];
}
$uri = strip_tags($uri);
$target = ($this->strictStandards) ? '' : ' target="_blank"';
return "<a href='{$uri}' class='link'{$target}>{$matches[0]}</a>";
} | php | protected function linkifyCb($matches)
{
$uri = (isset($matches[1]) && strlen(trim($matches[1]))) ? $matches[0] : "http://" . $matches[0];
// we dont want to link if it would cause malformed HTML
$openTags = array();
$closeTags = array();
preg_match_all("/<(?!\/)([^\s>]*).*?>/", $matches[0], $openTags, PREG_SET_ORDER);
preg_match_all("/<\/([^\s>]*).*?>/", $matches[0], $closeTags, PREG_SET_ORDER);
if (count($openTags) != count($closeTags)) {
return $matches[0];
}
if (isset($openTags[0]) && trim($openTags[0][1]) !== trim($closeTags[0][1])) {
return $matches[0];
}
$uri = strip_tags($uri);
$target = ($this->strictStandards) ? '' : ' target="_blank"';
return "<a href='{$uri}' class='link'{$target}>{$matches[0]}</a>";
} | [
"protected",
"function",
"linkifyCb",
"(",
"$",
"matches",
")",
"{",
"$",
"uri",
"=",
"(",
"isset",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
"&&",
"strlen",
"(",
"trim",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
")",
")",
"?",
"$",
"matches",
"[",
"0",
"]",
":",
"\"http://\"",
".",
"$",
"matches",
"[",
"0",
"]",
";",
"// we dont want to link if it would cause malformed HTML",
"$",
"openTags",
"=",
"array",
"(",
")",
";",
"$",
"closeTags",
"=",
"array",
"(",
")",
";",
"preg_match_all",
"(",
"\"/<(?!\\/)([^\\s>]*).*?>/\"",
",",
"$",
"matches",
"[",
"0",
"]",
",",
"$",
"openTags",
",",
"PREG_SET_ORDER",
")",
";",
"preg_match_all",
"(",
"\"/<\\/([^\\s>]*).*?>/\"",
",",
"$",
"matches",
"[",
"0",
"]",
",",
"$",
"closeTags",
",",
"PREG_SET_ORDER",
")",
";",
"if",
"(",
"count",
"(",
"$",
"openTags",
")",
"!=",
"count",
"(",
"$",
"closeTags",
")",
")",
"{",
"return",
"$",
"matches",
"[",
"0",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"openTags",
"[",
"0",
"]",
")",
"&&",
"trim",
"(",
"$",
"openTags",
"[",
"0",
"]",
"[",
"1",
"]",
")",
"!==",
"trim",
"(",
"$",
"closeTags",
"[",
"0",
"]",
"[",
"1",
"]",
")",
")",
"{",
"return",
"$",
"matches",
"[",
"0",
"]",
";",
"}",
"$",
"uri",
"=",
"strip_tags",
"(",
"$",
"uri",
")",
";",
"$",
"target",
"=",
"(",
"$",
"this",
"->",
"strictStandards",
")",
"?",
"''",
":",
"' target=\"_blank\"'",
";",
"return",
"\"<a href='{$uri}' class='link'{$target}>{$matches[0]}</a>\"",
";",
"}"
]
| Detects and links URLs - callback | [
"Detects",
"and",
"links",
"URLs",
"-",
"callback"
]
| 4adc18f414534abe986133d6d38e8e9787d32e69 | https://github.com/markwatkinson/luminous/blob/4adc18f414534abe986133d6d38e8e9787d32e69/src/Luminous/Formatters/HtmlFormatter.php#L114-L135 |
14,387 | markwatkinson/luminous | src/Luminous/Formatters/HtmlFormatter.php | HtmlFormatter.linkify | protected function linkify($src)
{
if (stripos($src, "http") === false && stripos($src, "www") === false) {
return $src;
}
$chars = "0-9a-zA-Z\$\-_\.+!\*,%";
$src_ = $src;
// everyone stand back, I know regular expressions
$src = preg_replace_callback(
"@(?<![\w])
(?:(https?://(?:www[0-9]*\.)?) | (?:www\d*\.) )
# domain and tld
(?:[$chars]+)+\.[$chars]{2,}
# we don't include tags at the EOL because these are likely to be
# line-enclosing tags.
(?:[/$chars/?=\#;]+|&|<[^>]+>(?!$))*
@xm",
array($this, 'linkifyCb'),
$src
);
// this can hit a backtracking limit, in which case it nulls our string
// FIXME: see if we can make the above regex more resiliant wrt
// backtracking
if (preg_last_error() !== PREG_NO_ERROR) {
$src = $src_;
}
return $src;
} | php | protected function linkify($src)
{
if (stripos($src, "http") === false && stripos($src, "www") === false) {
return $src;
}
$chars = "0-9a-zA-Z\$\-_\.+!\*,%";
$src_ = $src;
// everyone stand back, I know regular expressions
$src = preg_replace_callback(
"@(?<![\w])
(?:(https?://(?:www[0-9]*\.)?) | (?:www\d*\.) )
# domain and tld
(?:[$chars]+)+\.[$chars]{2,}
# we don't include tags at the EOL because these are likely to be
# line-enclosing tags.
(?:[/$chars/?=\#;]+|&|<[^>]+>(?!$))*
@xm",
array($this, 'linkifyCb'),
$src
);
// this can hit a backtracking limit, in which case it nulls our string
// FIXME: see if we can make the above regex more resiliant wrt
// backtracking
if (preg_last_error() !== PREG_NO_ERROR) {
$src = $src_;
}
return $src;
} | [
"protected",
"function",
"linkify",
"(",
"$",
"src",
")",
"{",
"if",
"(",
"stripos",
"(",
"$",
"src",
",",
"\"http\"",
")",
"===",
"false",
"&&",
"stripos",
"(",
"$",
"src",
",",
"\"www\"",
")",
"===",
"false",
")",
"{",
"return",
"$",
"src",
";",
"}",
"$",
"chars",
"=",
"\"0-9a-zA-Z\\$\\-_\\.+!\\*,%\"",
";",
"$",
"src_",
"=",
"$",
"src",
";",
"// everyone stand back, I know regular expressions",
"$",
"src",
"=",
"preg_replace_callback",
"(",
"\"@(?<![\\w])\n (?:(https?://(?:www[0-9]*\\.)?) | (?:www\\d*\\.) )\n\n # domain and tld\n (?:[$chars]+)+\\.[$chars]{2,}\n # we don't include tags at the EOL because these are likely to be\n # line-enclosing tags.\n (?:[/$chars/?=\\#;]+|&|<[^>]+>(?!$))*\n @xm\"",
",",
"array",
"(",
"$",
"this",
",",
"'linkifyCb'",
")",
",",
"$",
"src",
")",
";",
"// this can hit a backtracking limit, in which case it nulls our string",
"// FIXME: see if we can make the above regex more resiliant wrt",
"// backtracking",
"if",
"(",
"preg_last_error",
"(",
")",
"!==",
"PREG_NO_ERROR",
")",
"{",
"$",
"src",
"=",
"$",
"src_",
";",
"}",
"return",
"$",
"src",
";",
"}"
]
| Detects and links URLs | [
"Detects",
"and",
"links",
"URLs"
]
| 4adc18f414534abe986133d6d38e8e9787d32e69 | https://github.com/markwatkinson/luminous/blob/4adc18f414534abe986133d6d38e8e9787d32e69/src/Luminous/Formatters/HtmlFormatter.php#L140-L169 |
14,388 | guillaumemonet/Rad | src/Rad/Config/Config.php | Config.get | public static function get(string $section, $row = null) {
if ($row === null) {
return isset(self::$config[$section]) ? self::$config[$section] : null;
} else {
return isset(self::$config[$section][$row]) ? self::$config[$section][$row] : null;
}
} | php | public static function get(string $section, $row = null) {
if ($row === null) {
return isset(self::$config[$section]) ? self::$config[$section] : null;
} else {
return isset(self::$config[$section][$row]) ? self::$config[$section][$row] : null;
}
} | [
"public",
"static",
"function",
"get",
"(",
"string",
"$",
"section",
",",
"$",
"row",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"row",
"===",
"null",
")",
"{",
"return",
"isset",
"(",
"self",
"::",
"$",
"config",
"[",
"$",
"section",
"]",
")",
"?",
"self",
"::",
"$",
"config",
"[",
"$",
"section",
"]",
":",
"null",
";",
"}",
"else",
"{",
"return",
"isset",
"(",
"self",
"::",
"$",
"config",
"[",
"$",
"section",
"]",
"[",
"$",
"row",
"]",
")",
"?",
"self",
"::",
"$",
"config",
"[",
"$",
"section",
"]",
"[",
"$",
"row",
"]",
":",
"null",
";",
"}",
"}"
]
| Return current config
@param string $section
@param string $row
@return string | [
"Return",
"current",
"config"
]
| cb9932f570cf3c2a7197f81e1d959c2729989e59 | https://github.com/guillaumemonet/Rad/blob/cb9932f570cf3c2a7197f81e1d959c2729989e59/src/Rad/Config/Config.php#L88-L94 |
14,389 | nyeholt/silverstripe-simplewiki | thirdparty/htmlpurifier-4.0.0-lite/library/HTMLPurifier/UnitConverter.php | HTMLPurifier_UnitConverter.add | private function add($s1, $s2, $scale) {
if ($this->bcmath) return bcadd($s1, $s2, $scale);
else return $this->scale($s1 + $s2, $scale);
} | php | private function add($s1, $s2, $scale) {
if ($this->bcmath) return bcadd($s1, $s2, $scale);
else return $this->scale($s1 + $s2, $scale);
} | [
"private",
"function",
"add",
"(",
"$",
"s1",
",",
"$",
"s2",
",",
"$",
"scale",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"bcmath",
")",
"return",
"bcadd",
"(",
"$",
"s1",
",",
"$",
"s2",
",",
"$",
"scale",
")",
";",
"else",
"return",
"$",
"this",
"->",
"scale",
"(",
"$",
"s1",
"+",
"$",
"s2",
",",
"$",
"scale",
")",
";",
"}"
]
| Adds two numbers, using arbitrary precision when available. | [
"Adds",
"two",
"numbers",
"using",
"arbitrary",
"precision",
"when",
"available",
"."
]
| ecffed0d75be1454901e1cb24633472b8f67c967 | https://github.com/nyeholt/silverstripe-simplewiki/blob/ecffed0d75be1454901e1cb24633472b8f67c967/thirdparty/htmlpurifier-4.0.0-lite/library/HTMLPurifier/UnitConverter.php#L188-L191 |
14,390 | nyeholt/silverstripe-simplewiki | thirdparty/htmlpurifier-4.0.0-lite/library/HTMLPurifier/UnitConverter.php | HTMLPurifier_UnitConverter.mul | private function mul($s1, $s2, $scale) {
if ($this->bcmath) return bcmul($s1, $s2, $scale);
else return $this->scale($s1 * $s2, $scale);
} | php | private function mul($s1, $s2, $scale) {
if ($this->bcmath) return bcmul($s1, $s2, $scale);
else return $this->scale($s1 * $s2, $scale);
} | [
"private",
"function",
"mul",
"(",
"$",
"s1",
",",
"$",
"s2",
",",
"$",
"scale",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"bcmath",
")",
"return",
"bcmul",
"(",
"$",
"s1",
",",
"$",
"s2",
",",
"$",
"scale",
")",
";",
"else",
"return",
"$",
"this",
"->",
"scale",
"(",
"$",
"s1",
"*",
"$",
"s2",
",",
"$",
"scale",
")",
";",
"}"
]
| Multiples two numbers, using arbitrary precision when available. | [
"Multiples",
"two",
"numbers",
"using",
"arbitrary",
"precision",
"when",
"available",
"."
]
| ecffed0d75be1454901e1cb24633472b8f67c967 | https://github.com/nyeholt/silverstripe-simplewiki/blob/ecffed0d75be1454901e1cb24633472b8f67c967/thirdparty/htmlpurifier-4.0.0-lite/library/HTMLPurifier/UnitConverter.php#L196-L199 |
14,391 | PendoNL/pro6pp-php-wrapper | src/Pro6pp.php | Pro6pp.autocomplete | public function autocomplete($postalcode, $number = '', $extension = '')
{
$postalcode = $this->determinePostalType($postalcode);
$this->data = array_merge($postalcode, ['streetnumber' => $number, 'extension' => $extension]);
return $this->call('autocomplete', $this->prepareData($this->data));
} | php | public function autocomplete($postalcode, $number = '', $extension = '')
{
$postalcode = $this->determinePostalType($postalcode);
$this->data = array_merge($postalcode, ['streetnumber' => $number, 'extension' => $extension]);
return $this->call('autocomplete', $this->prepareData($this->data));
} | [
"public",
"function",
"autocomplete",
"(",
"$",
"postalcode",
",",
"$",
"number",
"=",
"''",
",",
"$",
"extension",
"=",
"''",
")",
"{",
"$",
"postalcode",
"=",
"$",
"this",
"->",
"determinePostalType",
"(",
"$",
"postalcode",
")",
";",
"$",
"this",
"->",
"data",
"=",
"array_merge",
"(",
"$",
"postalcode",
",",
"[",
"'streetnumber'",
"=>",
"$",
"number",
",",
"'extension'",
"=>",
"$",
"extension",
"]",
")",
";",
"return",
"$",
"this",
"->",
"call",
"(",
"'autocomplete'",
",",
"$",
"this",
"->",
"prepareData",
"(",
"$",
"this",
"->",
"data",
")",
")",
";",
"}"
]
| Get a full address after providing a postalcode and number, the results also
include the coordinates from the address.
@param $postalcode
@param $number
@return mixed | [
"Get",
"a",
"full",
"address",
"after",
"providing",
"a",
"postalcode",
"and",
"number",
"the",
"results",
"also",
"include",
"the",
"coordinates",
"from",
"the",
"address",
"."
]
| d3ad95ebb89a55b037a3a12689cd15431912f32f | https://github.com/PendoNL/pro6pp-php-wrapper/blob/d3ad95ebb89a55b037a3a12689cd15431912f32f/src/Pro6pp.php#L48-L55 |
14,392 | PendoNL/pro6pp-php-wrapper | src/Pro6pp.php | Pro6pp.reverse | public function reverse($lat, $lng)
{
$this->data = ['lat' => $lat, 'lng' => $lng];
return $this->call('reverse', $this->prepareData($this->data));
} | php | public function reverse($lat, $lng)
{
$this->data = ['lat' => $lat, 'lng' => $lng];
return $this->call('reverse', $this->prepareData($this->data));
} | [
"public",
"function",
"reverse",
"(",
"$",
"lat",
",",
"$",
"lng",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"[",
"'lat'",
"=>",
"$",
"lat",
",",
"'lng'",
"=>",
"$",
"lng",
"]",
";",
"return",
"$",
"this",
"->",
"call",
"(",
"'reverse'",
",",
"$",
"this",
"->",
"prepareData",
"(",
"$",
"this",
"->",
"data",
")",
")",
";",
"}"
]
| Find an address by their coordinates, returns a full address if found.
@param $lat
@param $lng
@return mixed | [
"Find",
"an",
"address",
"by",
"their",
"coordinates",
"returns",
"a",
"full",
"address",
"if",
"found",
"."
]
| d3ad95ebb89a55b037a3a12689cd15431912f32f | https://github.com/PendoNL/pro6pp-php-wrapper/blob/d3ad95ebb89a55b037a3a12689cd15431912f32f/src/Pro6pp.php#L65-L70 |
14,393 | PendoNL/pro6pp-php-wrapper | src/Pro6pp.php | Pro6pp.range | public function range($nl_fourpp, $range = 5000, $per_page = 10, $page = 1)
{
$this->data = ['nl_fourpp' => $nl_fourpp, 'range' => $range, 'per_page' => $per_page, 'page' => $page];
return $this->call('range', $this->prepareData($this->data));
} | php | public function range($nl_fourpp, $range = 5000, $per_page = 10, $page = 1)
{
$this->data = ['nl_fourpp' => $nl_fourpp, 'range' => $range, 'per_page' => $per_page, 'page' => $page];
return $this->call('range', $this->prepareData($this->data));
} | [
"public",
"function",
"range",
"(",
"$",
"nl_fourpp",
",",
"$",
"range",
"=",
"5000",
",",
"$",
"per_page",
"=",
"10",
",",
"$",
"page",
"=",
"1",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"[",
"'nl_fourpp'",
"=>",
"$",
"nl_fourpp",
",",
"'range'",
"=>",
"$",
"range",
",",
"'per_page'",
"=>",
"$",
"per_page",
",",
"'page'",
"=>",
"$",
"page",
"]",
";",
"return",
"$",
"this",
"->",
"call",
"(",
"'range'",
",",
"$",
"this",
"->",
"prepareData",
"(",
"$",
"this",
"->",
"data",
")",
")",
";",
"}"
]
| Returns a list of postalcodes within a given range.
@param $nl_fourpp
@param int $range
@param int $per_page
@param int $page
@return mixed | [
"Returns",
"a",
"list",
"of",
"postalcodes",
"within",
"a",
"given",
"range",
"."
]
| d3ad95ebb89a55b037a3a12689cd15431912f32f | https://github.com/PendoNL/pro6pp-php-wrapper/blob/d3ad95ebb89a55b037a3a12689cd15431912f32f/src/Pro6pp.php#L100-L105 |
14,394 | PendoNL/pro6pp-php-wrapper | src/Pro6pp.php | Pro6pp.suggest | public function suggest($nl_city, $per_page = 10)
{
$this->data = ['nl_city' => $nl_city, 'per_page' => $per_page];
return $this->call('suggest', $this->prepareData($this->data));
} | php | public function suggest($nl_city, $per_page = 10)
{
$this->data = ['nl_city' => $nl_city, 'per_page' => $per_page];
return $this->call('suggest', $this->prepareData($this->data));
} | [
"public",
"function",
"suggest",
"(",
"$",
"nl_city",
",",
"$",
"per_page",
"=",
"10",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"[",
"'nl_city'",
"=>",
"$",
"nl_city",
",",
"'per_page'",
"=>",
"$",
"per_page",
"]",
";",
"return",
"$",
"this",
"->",
"call",
"(",
"'suggest'",
",",
"$",
"this",
"->",
"prepareData",
"(",
"$",
"this",
"->",
"data",
")",
")",
";",
"}"
]
| Autocompletes a city name.
@param $nl_city
@param int $per_page
@return mixed | [
"Autocompletes",
"a",
"city",
"name",
"."
]
| d3ad95ebb89a55b037a3a12689cd15431912f32f | https://github.com/PendoNL/pro6pp-php-wrapper/blob/d3ad95ebb89a55b037a3a12689cd15431912f32f/src/Pro6pp.php#L115-L120 |
14,395 | PendoNL/pro6pp-php-wrapper | src/Pro6pp.php | Pro6pp.distance | public function distance($from_nl_fourpp, $to_nl_fourpp, $algorithm = 'road')
{
$this->data = ['from_nl_fourpp' => $from_nl_fourpp, 'to_nl_fourpp' => $to_nl_fourpp, 'algorithm' => $algorithm];
return $this->call('distance', $this->prepareData($this->data));
} | php | public function distance($from_nl_fourpp, $to_nl_fourpp, $algorithm = 'road')
{
$this->data = ['from_nl_fourpp' => $from_nl_fourpp, 'to_nl_fourpp' => $to_nl_fourpp, 'algorithm' => $algorithm];
return $this->call('distance', $this->prepareData($this->data));
} | [
"public",
"function",
"distance",
"(",
"$",
"from_nl_fourpp",
",",
"$",
"to_nl_fourpp",
",",
"$",
"algorithm",
"=",
"'road'",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"[",
"'from_nl_fourpp'",
"=>",
"$",
"from_nl_fourpp",
",",
"'to_nl_fourpp'",
"=>",
"$",
"to_nl_fourpp",
",",
"'algorithm'",
"=>",
"$",
"algorithm",
"]",
";",
"return",
"$",
"this",
"->",
"call",
"(",
"'distance'",
",",
"$",
"this",
"->",
"prepareData",
"(",
"$",
"this",
"->",
"data",
")",
")",
";",
"}"
]
| Calculates the distance between two nl_fourpp postalcodes. Optional you can choose between
road or straight distance.
@param $from_nl_fourpp
@param $to_nl_fourpp
@param $algorithm
@return mixed | [
"Calculates",
"the",
"distance",
"between",
"two",
"nl_fourpp",
"postalcodes",
".",
"Optional",
"you",
"can",
"choose",
"between",
"road",
"or",
"straight",
"distance",
"."
]
| d3ad95ebb89a55b037a3a12689cd15431912f32f | https://github.com/PendoNL/pro6pp-php-wrapper/blob/d3ad95ebb89a55b037a3a12689cd15431912f32f/src/Pro6pp.php#L132-L137 |
14,396 | PendoNL/pro6pp-php-wrapper | src/Pro6pp.php | Pro6pp.coordinatesDistance | public function coordinatesDistance($lat1, $lng1, $lat2, $lng2, $miles = false)
{
$pi80 = M_PI / 180;
$lat1 *= $pi80;
$lng1 *= $pi80;
$lat2 *= $pi80;
$lng2 *= $pi80;
$r = 6372.797;
$dlat = $lat2 - $lat1;
$dlng = $lng2 - $lng1;
$a = sin($dlat / 2) * sin($dlat / 2) + cos($lat1) * cos($lat2) * sin($dlng / 2) * sin($dlng / 2);
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));
$km = $r * $c;
return $miles ? ($km * 0.621371192) : $km;
} | php | public function coordinatesDistance($lat1, $lng1, $lat2, $lng2, $miles = false)
{
$pi80 = M_PI / 180;
$lat1 *= $pi80;
$lng1 *= $pi80;
$lat2 *= $pi80;
$lng2 *= $pi80;
$r = 6372.797;
$dlat = $lat2 - $lat1;
$dlng = $lng2 - $lng1;
$a = sin($dlat / 2) * sin($dlat / 2) + cos($lat1) * cos($lat2) * sin($dlng / 2) * sin($dlng / 2);
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));
$km = $r * $c;
return $miles ? ($km * 0.621371192) : $km;
} | [
"public",
"function",
"coordinatesDistance",
"(",
"$",
"lat1",
",",
"$",
"lng1",
",",
"$",
"lat2",
",",
"$",
"lng2",
",",
"$",
"miles",
"=",
"false",
")",
"{",
"$",
"pi80",
"=",
"M_PI",
"/",
"180",
";",
"$",
"lat1",
"*=",
"$",
"pi80",
";",
"$",
"lng1",
"*=",
"$",
"pi80",
";",
"$",
"lat2",
"*=",
"$",
"pi80",
";",
"$",
"lng2",
"*=",
"$",
"pi80",
";",
"$",
"r",
"=",
"6372.797",
";",
"$",
"dlat",
"=",
"$",
"lat2",
"-",
"$",
"lat1",
";",
"$",
"dlng",
"=",
"$",
"lng2",
"-",
"$",
"lng1",
";",
"$",
"a",
"=",
"sin",
"(",
"$",
"dlat",
"/",
"2",
")",
"*",
"sin",
"(",
"$",
"dlat",
"/",
"2",
")",
"+",
"cos",
"(",
"$",
"lat1",
")",
"*",
"cos",
"(",
"$",
"lat2",
")",
"*",
"sin",
"(",
"$",
"dlng",
"/",
"2",
")",
"*",
"sin",
"(",
"$",
"dlng",
"/",
"2",
")",
";",
"$",
"c",
"=",
"2",
"*",
"atan2",
"(",
"sqrt",
"(",
"$",
"a",
")",
",",
"sqrt",
"(",
"1",
"-",
"$",
"a",
")",
")",
";",
"$",
"km",
"=",
"$",
"r",
"*",
"$",
"c",
";",
"return",
"$",
"miles",
"?",
"(",
"$",
"km",
"*",
"0.621371192",
")",
":",
"$",
"km",
";",
"}"
]
| Helper method to calculate the distance between two coordinates.
@param $lat1
@param $lng1
@param $lat2
@param $lng2
@param bool $miles
@return float | [
"Helper",
"method",
"to",
"calculate",
"the",
"distance",
"between",
"two",
"coordinates",
"."
]
| d3ad95ebb89a55b037a3a12689cd15431912f32f | https://github.com/PendoNL/pro6pp-php-wrapper/blob/d3ad95ebb89a55b037a3a12689cd15431912f32f/src/Pro6pp.php#L150-L167 |
14,397 | PendoNL/pro6pp-php-wrapper | src/Pro6pp.php | Pro6pp.determinePostalType | public function determinePostalType($postalcode)
{
$postalcode = str_replace(' ', '', $postalcode);
if (strlen($postalcode) == 6) {
return ['nl_sixpp' => $postalcode];
}
if (strlen($postalcode) == 4) {
return ['nl_fourpp' => $postalcode];
}
throw new \Exception('No valid postalcode was found (nl_sixpp or nl_fourpp)');
} | php | public function determinePostalType($postalcode)
{
$postalcode = str_replace(' ', '', $postalcode);
if (strlen($postalcode) == 6) {
return ['nl_sixpp' => $postalcode];
}
if (strlen($postalcode) == 4) {
return ['nl_fourpp' => $postalcode];
}
throw new \Exception('No valid postalcode was found (nl_sixpp or nl_fourpp)');
} | [
"public",
"function",
"determinePostalType",
"(",
"$",
"postalcode",
")",
"{",
"$",
"postalcode",
"=",
"str_replace",
"(",
"' '",
",",
"''",
",",
"$",
"postalcode",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"postalcode",
")",
"==",
"6",
")",
"{",
"return",
"[",
"'nl_sixpp'",
"=>",
"$",
"postalcode",
"]",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"postalcode",
")",
"==",
"4",
")",
"{",
"return",
"[",
"'nl_fourpp'",
"=>",
"$",
"postalcode",
"]",
";",
"}",
"throw",
"new",
"\\",
"Exception",
"(",
"'No valid postalcode was found (nl_sixpp or nl_fourpp)'",
")",
";",
"}"
]
| Checks if one of two valid postal types was sent along.
@param $postalcode
@throws \Exception
@return array | [
"Checks",
"if",
"one",
"of",
"two",
"valid",
"postal",
"types",
"was",
"sent",
"along",
"."
]
| d3ad95ebb89a55b037a3a12689cd15431912f32f | https://github.com/PendoNL/pro6pp-php-wrapper/blob/d3ad95ebb89a55b037a3a12689cd15431912f32f/src/Pro6pp.php#L178-L191 |
14,398 | PendoNL/pro6pp-php-wrapper | src/Pro6pp.php | Pro6pp.prepareData | protected function prepareData($data)
{
$data['auth_key'] = $this->api_key;
$data['format'] = $this->api_format;
$data['pretty'] = $this->api_pretty;
return $data;
} | php | protected function prepareData($data)
{
$data['auth_key'] = $this->api_key;
$data['format'] = $this->api_format;
$data['pretty'] = $this->api_pretty;
return $data;
} | [
"protected",
"function",
"prepareData",
"(",
"$",
"data",
")",
"{",
"$",
"data",
"[",
"'auth_key'",
"]",
"=",
"$",
"this",
"->",
"api_key",
";",
"$",
"data",
"[",
"'format'",
"]",
"=",
"$",
"this",
"->",
"api_format",
";",
"$",
"data",
"[",
"'pretty'",
"]",
"=",
"$",
"this",
"->",
"api_pretty",
";",
"return",
"$",
"data",
";",
"}"
]
| Make sure the data contains the api_key and desired format.
@param $data
@return mixed | [
"Make",
"sure",
"the",
"data",
"contains",
"the",
"api_key",
"and",
"desired",
"format",
"."
]
| d3ad95ebb89a55b037a3a12689cd15431912f32f | https://github.com/PendoNL/pro6pp-php-wrapper/blob/d3ad95ebb89a55b037a3a12689cd15431912f32f/src/Pro6pp.php#L200-L207 |
14,399 | PendoNL/pro6pp-php-wrapper | src/Pro6pp.php | Pro6pp.call | protected function call($path, $data)
{
$url = $this->api_host.$path.'?'.http_build_query($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$return = curl_exec($ch);
curl_close($ch);
return $return;
} | php | protected function call($path, $data)
{
$url = $this->api_host.$path.'?'.http_build_query($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$return = curl_exec($ch);
curl_close($ch);
return $return;
} | [
"protected",
"function",
"call",
"(",
"$",
"path",
",",
"$",
"data",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"api_host",
".",
"$",
"path",
".",
"'?'",
".",
"http_build_query",
"(",
"$",
"data",
")",
";",
"$",
"ch",
"=",
"curl_init",
"(",
"$",
"url",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_TIMEOUT",
",",
"5",
")",
";",
"$",
"return",
"=",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"curl_close",
"(",
"$",
"ch",
")",
";",
"return",
"$",
"return",
";",
"}"
]
| Method to do the actual call to Pro6PP's API and return the data
in the given format.
@param $path
@param $data
@return mixed | [
"Method",
"to",
"do",
"the",
"actual",
"call",
"to",
"Pro6PP",
"s",
"API",
"and",
"return",
"the",
"data",
"in",
"the",
"given",
"format",
"."
]
| d3ad95ebb89a55b037a3a12689cd15431912f32f | https://github.com/PendoNL/pro6pp-php-wrapper/blob/d3ad95ebb89a55b037a3a12689cd15431912f32f/src/Pro6pp.php#L218-L232 |
Subsets and Splits