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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
237,500
|
bugotech/io
|
src/Filesystem.php
|
Filesystem.saveConfig
|
public function saveConfig($group, $environment = '')
{
// Path do arquivo
$path = config_path();
// Itens
$items = config($group, []);
// Nome do arquivo
$file = (! $environment || ($environment == 'production'))
? "{$path}/{$group}.php"
: "{$path}/{$environment}/{$group}.php";
// Salvar arquivo
$code = '<?php' . "\r\n\r\n";
$code .= 'return ' . var_export($items, true) . ';';
$this->put($file, $code);
}
|
php
|
public function saveConfig($group, $environment = '')
{
// Path do arquivo
$path = config_path();
// Itens
$items = config($group, []);
// Nome do arquivo
$file = (! $environment || ($environment == 'production'))
? "{$path}/{$group}.php"
: "{$path}/{$environment}/{$group}.php";
// Salvar arquivo
$code = '<?php' . "\r\n\r\n";
$code .= 'return ' . var_export($items, true) . ';';
$this->put($file, $code);
}
|
[
"public",
"function",
"saveConfig",
"(",
"$",
"group",
",",
"$",
"environment",
"=",
"''",
")",
"{",
"// Path do arquivo",
"$",
"path",
"=",
"config_path",
"(",
")",
";",
"// Itens",
"$",
"items",
"=",
"config",
"(",
"$",
"group",
",",
"[",
"]",
")",
";",
"// Nome do arquivo",
"$",
"file",
"=",
"(",
"!",
"$",
"environment",
"||",
"(",
"$",
"environment",
"==",
"'production'",
")",
")",
"?",
"\"{$path}/{$group}.php\"",
":",
"\"{$path}/{$environment}/{$group}.php\"",
";",
"// Salvar arquivo",
"$",
"code",
"=",
"'<?php'",
".",
"\"\\r\\n\\r\\n\"",
";",
"$",
"code",
".=",
"'return '",
".",
"var_export",
"(",
"$",
"items",
",",
"true",
")",
".",
"';'",
";",
"$",
"this",
"->",
"put",
"(",
"$",
"file",
",",
"$",
"code",
")",
";",
"}"
] |
Salvar arquivo Config.
@param $group
@param string $environment
|
[
"Salvar",
"arquivo",
"Config",
"."
] |
3c7601af1839d1cdfa2ba5c43bf33d6d79117ae0
|
https://github.com/bugotech/io/blob/3c7601af1839d1cdfa2ba5c43bf33d6d79117ae0/src/Filesystem.php#L176-L193
|
237,501
|
indigophp-archive/codeception-fuel-module
|
fuel/fuel/packages/orm/classes/relation.php
|
Relation.select
|
public function select($table)
{
$props = call_user_func(array($this->model_to, 'properties'));
$i = 0;
$properties = array();
foreach ($props as $pk => $pv)
{
$properties[] = array($table.'.'.$pk, $table.'_c'.$i);
$i++;
}
return $properties;
}
|
php
|
public function select($table)
{
$props = call_user_func(array($this->model_to, 'properties'));
$i = 0;
$properties = array();
foreach ($props as $pk => $pv)
{
$properties[] = array($table.'.'.$pk, $table.'_c'.$i);
$i++;
}
return $properties;
}
|
[
"public",
"function",
"select",
"(",
"$",
"table",
")",
"{",
"$",
"props",
"=",
"call_user_func",
"(",
"array",
"(",
"$",
"this",
"->",
"model_to",
",",
"'properties'",
")",
")",
";",
"$",
"i",
"=",
"0",
";",
"$",
"properties",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"props",
"as",
"$",
"pk",
"=>",
"$",
"pv",
")",
"{",
"$",
"properties",
"[",
"]",
"=",
"array",
"(",
"$",
"table",
".",
"'.'",
".",
"$",
"pk",
",",
"$",
"table",
".",
"'_c'",
".",
"$",
"i",
")",
";",
"$",
"i",
"++",
";",
"}",
"return",
"$",
"properties",
";",
"}"
] |
Should get the properties as associative array with alias => property, the table alias is
given to be included with the property
@param string
@return array
|
[
"Should",
"get",
"the",
"properties",
"as",
"associative",
"array",
"with",
"alias",
"=",
">",
"property",
"the",
"table",
"alias",
"is",
"given",
"to",
"be",
"included",
"with",
"the",
"property"
] |
0973b7cbd540a0e89cc5bb7af94627f77f09bf49
|
https://github.com/indigophp-archive/codeception-fuel-module/blob/0973b7cbd540a0e89cc5bb7af94627f77f09bf49/fuel/fuel/packages/orm/classes/relation.php#L88-L100
|
237,502
|
asbsoft/yii2-common_2_170212
|
helpers/BaseConfigsBuilder.php
|
BaseConfigsBuilder.includeConfigFile
|
public static function includeConfigFile($filename, $application = null)
{
if (empty($application)) {
$application = Yii::$app;
}
$appKey = UniApplication::appKey($application);
if (!isset(self::$_configFiles[$appKey][$filename])) {
if (is_file($filename)) {
self::$_configFiles[$appKey][$filename] = include($filename); // var $application can be used in $filename
} else {
throw new InvalidConfigException("Config file '$filename' required");
}
}
return self::$_configFiles[$appKey][$filename];
}
|
php
|
public static function includeConfigFile($filename, $application = null)
{
if (empty($application)) {
$application = Yii::$app;
}
$appKey = UniApplication::appKey($application);
if (!isset(self::$_configFiles[$appKey][$filename])) {
if (is_file($filename)) {
self::$_configFiles[$appKey][$filename] = include($filename); // var $application can be used in $filename
} else {
throw new InvalidConfigException("Config file '$filename' required");
}
}
return self::$_configFiles[$appKey][$filename];
}
|
[
"public",
"static",
"function",
"includeConfigFile",
"(",
"$",
"filename",
",",
"$",
"application",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"application",
")",
")",
"{",
"$",
"application",
"=",
"Yii",
"::",
"$",
"app",
";",
"}",
"$",
"appKey",
"=",
"UniApplication",
"::",
"appKey",
"(",
"$",
"application",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"_configFiles",
"[",
"$",
"appKey",
"]",
"[",
"$",
"filename",
"]",
")",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"filename",
")",
")",
"{",
"self",
"::",
"$",
"_configFiles",
"[",
"$",
"appKey",
"]",
"[",
"$",
"filename",
"]",
"=",
"include",
"(",
"$",
"filename",
")",
";",
"// var $application can be used in $filename",
"}",
"else",
"{",
"throw",
"new",
"InvalidConfigException",
"(",
"\"Config file '$filename' required\"",
")",
";",
"}",
"}",
"return",
"self",
"::",
"$",
"_configFiles",
"[",
"$",
"appKey",
"]",
"[",
"$",
"filename",
"]",
";",
"}"
] |
Get, save in cache and return result of include file
@param string $filename
@param Application $application
Note if config has some calculations caching may be not correct.
|
[
"Get",
"save",
"in",
"cache",
"and",
"return",
"result",
"of",
"include",
"file"
] |
6c58012ff89225d7d4e42b200cf39e009e9d9dac
|
https://github.com/asbsoft/yii2-common_2_170212/blob/6c58012ff89225d7d4e42b200cf39e009e9d9dac/helpers/BaseConfigsBuilder.php#L31-L45
|
237,503
|
asbsoft/yii2-common_2_170212
|
helpers/BaseConfigsBuilder.php
|
BaseConfigsBuilder.cleanConfigFileCache
|
public static function cleanConfigFileCache($application = null)
{
if (empty($application)) {
$application = Yii::$app;
}
$appKey = UniApplication::appKey($application);
static::$_configFiles[$appKey] = [];
}
|
php
|
public static function cleanConfigFileCache($application = null)
{
if (empty($application)) {
$application = Yii::$app;
}
$appKey = UniApplication::appKey($application);
static::$_configFiles[$appKey] = [];
}
|
[
"public",
"static",
"function",
"cleanConfigFileCache",
"(",
"$",
"application",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"application",
")",
")",
"{",
"$",
"application",
"=",
"Yii",
"::",
"$",
"app",
";",
"}",
"$",
"appKey",
"=",
"UniApplication",
"::",
"appKey",
"(",
"$",
"application",
")",
";",
"static",
"::",
"$",
"_configFiles",
"[",
"$",
"appKey",
"]",
"=",
"[",
"]",
";",
"}"
] |
Clean included files cache
|
[
"Clean",
"included",
"files",
"cache"
] |
6c58012ff89225d7d4e42b200cf39e009e9d9dac
|
https://github.com/asbsoft/yii2-common_2_170212/blob/6c58012ff89225d7d4e42b200cf39e009e9d9dac/helpers/BaseConfigsBuilder.php#L47-L54
|
237,504
|
a15lam/workspace
|
src/Utility/Logger.php
|
Logger.write
|
protected function write($level, $msg)
{
$time = date('Y-m-d H:i:s', time());
$msg = "[" . $time . "][" . static::getLevelName($level) . "] " . $msg . PHP_EOL;
if($this->debugOutput === true){
echo $msg;
}
if (static::$silent) {
return false;
}
if (!$this->isAllowed($level)) {
return false;
}
$fh = fopen($this->logFile, 'a');
if (!fwrite($fh, $msg)) {
throw new \Exception('Failed to write to log file at ' . $this->logFile);
}
return true;
}
|
php
|
protected function write($level, $msg)
{
$time = date('Y-m-d H:i:s', time());
$msg = "[" . $time . "][" . static::getLevelName($level) . "] " . $msg . PHP_EOL;
if($this->debugOutput === true){
echo $msg;
}
if (static::$silent) {
return false;
}
if (!$this->isAllowed($level)) {
return false;
}
$fh = fopen($this->logFile, 'a');
if (!fwrite($fh, $msg)) {
throw new \Exception('Failed to write to log file at ' . $this->logFile);
}
return true;
}
|
[
"protected",
"function",
"write",
"(",
"$",
"level",
",",
"$",
"msg",
")",
"{",
"$",
"time",
"=",
"date",
"(",
"'Y-m-d H:i:s'",
",",
"time",
"(",
")",
")",
";",
"$",
"msg",
"=",
"\"[\"",
".",
"$",
"time",
".",
"\"][\"",
".",
"static",
"::",
"getLevelName",
"(",
"$",
"level",
")",
".",
"\"] \"",
".",
"$",
"msg",
".",
"PHP_EOL",
";",
"if",
"(",
"$",
"this",
"->",
"debugOutput",
"===",
"true",
")",
"{",
"echo",
"$",
"msg",
";",
"}",
"if",
"(",
"static",
"::",
"$",
"silent",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"isAllowed",
"(",
"$",
"level",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"fh",
"=",
"fopen",
"(",
"$",
"this",
"->",
"logFile",
",",
"'a'",
")",
";",
"if",
"(",
"!",
"fwrite",
"(",
"$",
"fh",
",",
"$",
"msg",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Failed to write to log file at '",
".",
"$",
"this",
"->",
"logFile",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Writes to log file.
@param int $level
@param string $msg
@return bool
@throws \Exception
|
[
"Writes",
"to",
"log",
"file",
"."
] |
a17508b47b2db11a6e203a3cbd43b886a85e25aa
|
https://github.com/a15lam/workspace/blob/a17508b47b2db11a6e203a3cbd43b886a85e25aa/src/Utility/Logger.php#L65-L85
|
237,505
|
a15lam/workspace
|
src/Utility/Logger.php
|
Logger.getLevelName
|
protected static function getLevelName($value)
{
$map = array_flip((new \ReflectionClass(self::class))->getConstants());
return (array_key_exists($value, $map) ? $map[$value] : null);
}
|
php
|
protected static function getLevelName($value)
{
$map = array_flip((new \ReflectionClass(self::class))->getConstants());
return (array_key_exists($value, $map) ? $map[$value] : null);
}
|
[
"protected",
"static",
"function",
"getLevelName",
"(",
"$",
"value",
")",
"{",
"$",
"map",
"=",
"array_flip",
"(",
"(",
"new",
"\\",
"ReflectionClass",
"(",
"self",
"::",
"class",
")",
")",
"->",
"getConstants",
"(",
")",
")",
";",
"return",
"(",
"array_key_exists",
"(",
"$",
"value",
",",
"$",
"map",
")",
"?",
"$",
"map",
"[",
"$",
"value",
"]",
":",
"null",
")",
";",
"}"
] |
Gets the log level name by value
@param int $value
@return null|string
|
[
"Gets",
"the",
"log",
"level",
"name",
"by",
"value"
] |
a17508b47b2db11a6e203a3cbd43b886a85e25aa
|
https://github.com/a15lam/workspace/blob/a17508b47b2db11a6e203a3cbd43b886a85e25aa/src/Utility/Logger.php#L110-L115
|
237,506
|
a15lam/workspace
|
src/Utility/Logger.php
|
Logger.getLevelValue
|
public static function getLevelValue($name)
{
$name = strtoupper($name);
$map = (new \ReflectionClass(self::class))->getConstants();
return (isset($map[$name]))? $map[$name] : null;
}
|
php
|
public static function getLevelValue($name)
{
$name = strtoupper($name);
$map = (new \ReflectionClass(self::class))->getConstants();
return (isset($map[$name]))? $map[$name] : null;
}
|
[
"public",
"static",
"function",
"getLevelValue",
"(",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"strtoupper",
"(",
"$",
"name",
")",
";",
"$",
"map",
"=",
"(",
"new",
"\\",
"ReflectionClass",
"(",
"self",
"::",
"class",
")",
")",
"->",
"getConstants",
"(",
")",
";",
"return",
"(",
"isset",
"(",
"$",
"map",
"[",
"$",
"name",
"]",
")",
")",
"?",
"$",
"map",
"[",
"$",
"name",
"]",
":",
"null",
";",
"}"
] |
Gets the log level value by name
@param $name
@return null
|
[
"Gets",
"the",
"log",
"level",
"value",
"by",
"name"
] |
a17508b47b2db11a6e203a3cbd43b886a85e25aa
|
https://github.com/a15lam/workspace/blob/a17508b47b2db11a6e203a3cbd43b886a85e25aa/src/Utility/Logger.php#L124-L130
|
237,507
|
Attibee/Bumble-Validation
|
src/BaseValidator.php
|
BaseValidator.error
|
protected function error( $messageKey, $value = null ) {
//was a global message set? let's use the global key then
if( key_exists( self::GLOBAL_MESSAGE_KEY, $this->templates ) )
$messageKey = self::GLOBAL_MESSAGE_KEY;
//invalide message key
if( !key_exists( $messageKey, $this->templates ) )
throw new Exception\MessageTemplateDoesNotExist( "A message template does not exist for key $messageKey" );
$this->messages[ $messageKey ] = $this->buildMessage( $this->templates[$messageKey], $value );
}
|
php
|
protected function error( $messageKey, $value = null ) {
//was a global message set? let's use the global key then
if( key_exists( self::GLOBAL_MESSAGE_KEY, $this->templates ) )
$messageKey = self::GLOBAL_MESSAGE_KEY;
//invalide message key
if( !key_exists( $messageKey, $this->templates ) )
throw new Exception\MessageTemplateDoesNotExist( "A message template does not exist for key $messageKey" );
$this->messages[ $messageKey ] = $this->buildMessage( $this->templates[$messageKey], $value );
}
|
[
"protected",
"function",
"error",
"(",
"$",
"messageKey",
",",
"$",
"value",
"=",
"null",
")",
"{",
"//was a global message set? let's use the global key then\r",
"if",
"(",
"key_exists",
"(",
"self",
"::",
"GLOBAL_MESSAGE_KEY",
",",
"$",
"this",
"->",
"templates",
")",
")",
"$",
"messageKey",
"=",
"self",
"::",
"GLOBAL_MESSAGE_KEY",
";",
"//invalide message key\r",
"if",
"(",
"!",
"key_exists",
"(",
"$",
"messageKey",
",",
"$",
"this",
"->",
"templates",
")",
")",
"throw",
"new",
"Exception",
"\\",
"MessageTemplateDoesNotExist",
"(",
"\"A message template does not exist for key $messageKey\"",
")",
";",
"$",
"this",
"->",
"messages",
"[",
"$",
"messageKey",
"]",
"=",
"$",
"this",
"->",
"buildMessage",
"(",
"$",
"this",
"->",
"templates",
"[",
"$",
"messageKey",
"]",
",",
"$",
"value",
")",
";",
"}"
] |
Adds an error message to the list of errors.
@param $messageKey The key of the message template.
@param $value The value that is being validated.
@throws Exception\MessageTemplateDoesNotExist The message template does not exist.
|
[
"Adds",
"an",
"error",
"message",
"to",
"the",
"list",
"of",
"errors",
"."
] |
4623b4a9b8592e3f36e615391fd7ec9ab2344a03
|
https://github.com/Attibee/Bumble-Validation/blob/4623b4a9b8592e3f36e615391fd7ec9ab2344a03/src/BaseValidator.php#L105-L115
|
237,508
|
Attibee/Bumble-Validation
|
src/BaseValidator.php
|
BaseValidator.updateMessageTemplate
|
private function updateMessageTemplate( $template, $key ) {
//invalide message key
if( !key_exists( $messageKey, $this->templates ) && $key != self::DEFAULT_KEY )
throw new Exception\MessageTemplateDoesNotExist( "A message template does not exist for key $messageKey" );
$this->templates[$key] = $template;
}
|
php
|
private function updateMessageTemplate( $template, $key ) {
//invalide message key
if( !key_exists( $messageKey, $this->templates ) && $key != self::DEFAULT_KEY )
throw new Exception\MessageTemplateDoesNotExist( "A message template does not exist for key $messageKey" );
$this->templates[$key] = $template;
}
|
[
"private",
"function",
"updateMessageTemplate",
"(",
"$",
"template",
",",
"$",
"key",
")",
"{",
"//invalide message key\r",
"if",
"(",
"!",
"key_exists",
"(",
"$",
"messageKey",
",",
"$",
"this",
"->",
"templates",
")",
"&&",
"$",
"key",
"!=",
"self",
"::",
"DEFAULT_KEY",
")",
"throw",
"new",
"Exception",
"\\",
"MessageTemplateDoesNotExist",
"(",
"\"A message template does not exist for key $messageKey\"",
")",
";",
"$",
"this",
"->",
"templates",
"[",
"$",
"key",
"]",
"=",
"$",
"template",
";",
"}"
] |
Updates the message template. This overrides existing message templates.
@param $template The message template.
@param $key The message key.
|
[
"Updates",
"the",
"message",
"template",
".",
"This",
"overrides",
"existing",
"message",
"templates",
"."
] |
4623b4a9b8592e3f36e615391fd7ec9ab2344a03
|
https://github.com/Attibee/Bumble-Validation/blob/4623b4a9b8592e3f36e615391fd7ec9ab2344a03/src/BaseValidator.php#L122-L128
|
237,509
|
benkle-libs/feed-parser
|
src/Standards/Atom/Rules/SimpleAtomFieldRule.php
|
SimpleAtomFieldRule.getNodeContent
|
private function getNodeContent(\DOMNode $node)
{
$type = $node->attributes->getNamedItem('type');
if ($type && strtolower($type->nodeValue) == 'xhtml') {
$result = '';
foreach ($node->childNodes as $childNode) {
$result .= $node->ownerDocument->save($childNode);
}
return $result;
} else {
return $node->nodeValue;
}
}
|
php
|
private function getNodeContent(\DOMNode $node)
{
$type = $node->attributes->getNamedItem('type');
if ($type && strtolower($type->nodeValue) == 'xhtml') {
$result = '';
foreach ($node->childNodes as $childNode) {
$result .= $node->ownerDocument->save($childNode);
}
return $result;
} else {
return $node->nodeValue;
}
}
|
[
"private",
"function",
"getNodeContent",
"(",
"\\",
"DOMNode",
"$",
"node",
")",
"{",
"$",
"type",
"=",
"$",
"node",
"->",
"attributes",
"->",
"getNamedItem",
"(",
"'type'",
")",
";",
"if",
"(",
"$",
"type",
"&&",
"strtolower",
"(",
"$",
"type",
"->",
"nodeValue",
")",
"==",
"'xhtml'",
")",
"{",
"$",
"result",
"=",
"''",
";",
"foreach",
"(",
"$",
"node",
"->",
"childNodes",
"as",
"$",
"childNode",
")",
"{",
"$",
"result",
".=",
"$",
"node",
"->",
"ownerDocument",
"->",
"save",
"(",
"$",
"childNode",
")",
";",
"}",
"return",
"$",
"result",
";",
"}",
"else",
"{",
"return",
"$",
"node",
"->",
"nodeValue",
";",
"}",
"}"
] |
Enable XHTML types.
@param \DOMNode $node
@return string
@codeCoverageIgnore
|
[
"Enable",
"XHTML",
"types",
"."
] |
8b86daf9dfe57e6e7ccae83dbc65ac7ce462144f
|
https://github.com/benkle-libs/feed-parser/blob/8b86daf9dfe57e6e7ccae83dbc65ac7ce462144f/src/Standards/Atom/Rules/SimpleAtomFieldRule.php#L85-L97
|
237,510
|
unforge/array-toolkit
|
src/Arr.php
|
Arr.getInt
|
public static function getInt(array $array, $key, int $default = 0) : int
{
$key = (string) $key;
if ($array[$key] ?? 0) {
return (int) $array[$key];
}
return $default;
}
|
php
|
public static function getInt(array $array, $key, int $default = 0) : int
{
$key = (string) $key;
if ($array[$key] ?? 0) {
return (int) $array[$key];
}
return $default;
}
|
[
"public",
"static",
"function",
"getInt",
"(",
"array",
"$",
"array",
",",
"$",
"key",
",",
"int",
"$",
"default",
"=",
"0",
")",
":",
"int",
"{",
"$",
"key",
"=",
"(",
"string",
")",
"$",
"key",
";",
"if",
"(",
"$",
"array",
"[",
"$",
"key",
"]",
"??",
"0",
")",
"{",
"return",
"(",
"int",
")",
"$",
"array",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"default",
";",
"}"
] |
Return INT value from array
@param array $array
@param string|int $key
@param int $default
@return int
|
[
"Return",
"INT",
"value",
"from",
"array"
] |
734992061dca91e593b33bee5f4b48112749dc60
|
https://github.com/unforge/array-toolkit/blob/734992061dca91e593b33bee5f4b48112749dc60/src/Arr.php#L55-L64
|
237,511
|
unforge/array-toolkit
|
src/Arr.php
|
Arr.getFloat
|
public static function getFloat(array $array, $key, float $default = 0.0) : float
{
$key = (string) $key;
if ($array[$key] ?? 0) {
return (float) $array[$key];
}
return $default;
}
|
php
|
public static function getFloat(array $array, $key, float $default = 0.0) : float
{
$key = (string) $key;
if ($array[$key] ?? 0) {
return (float) $array[$key];
}
return $default;
}
|
[
"public",
"static",
"function",
"getFloat",
"(",
"array",
"$",
"array",
",",
"$",
"key",
",",
"float",
"$",
"default",
"=",
"0.0",
")",
":",
"float",
"{",
"$",
"key",
"=",
"(",
"string",
")",
"$",
"key",
";",
"if",
"(",
"$",
"array",
"[",
"$",
"key",
"]",
"??",
"0",
")",
"{",
"return",
"(",
"float",
")",
"$",
"array",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"default",
";",
"}"
] |
Return FLOAT value from array
@param array $array
@param string|int $key
@param float $default
@return float
|
[
"Return",
"FLOAT",
"value",
"from",
"array"
] |
734992061dca91e593b33bee5f4b48112749dc60
|
https://github.com/unforge/array-toolkit/blob/734992061dca91e593b33bee5f4b48112749dc60/src/Arr.php#L75-L84
|
237,512
|
unforge/array-toolkit
|
src/Arr.php
|
Arr.getString
|
public static function getString(array $array, $key, string $default = '') : string
{
$key = (string) $key;
if ($array[$key] ?? 0) {
return (string) $array[$key];
}
return $default;
}
|
php
|
public static function getString(array $array, $key, string $default = '') : string
{
$key = (string) $key;
if ($array[$key] ?? 0) {
return (string) $array[$key];
}
return $default;
}
|
[
"public",
"static",
"function",
"getString",
"(",
"array",
"$",
"array",
",",
"$",
"key",
",",
"string",
"$",
"default",
"=",
"''",
")",
":",
"string",
"{",
"$",
"key",
"=",
"(",
"string",
")",
"$",
"key",
";",
"if",
"(",
"$",
"array",
"[",
"$",
"key",
"]",
"??",
"0",
")",
"{",
"return",
"(",
"string",
")",
"$",
"array",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"default",
";",
"}"
] |
Return STRING value from array
@param array $array
@param string|int $key
@param string $default
@return string
|
[
"Return",
"STRING",
"value",
"from",
"array"
] |
734992061dca91e593b33bee5f4b48112749dc60
|
https://github.com/unforge/array-toolkit/blob/734992061dca91e593b33bee5f4b48112749dc60/src/Arr.php#L95-L104
|
237,513
|
unforge/array-toolkit
|
src/Arr.php
|
Arr.getBool
|
public static function getBool(array $array, $key, bool $default = false) : bool
{
$key = (string) $key;
if ($array[$key] ?? 0) {
return (bool) $array[$key];
}
return $default;
}
|
php
|
public static function getBool(array $array, $key, bool $default = false) : bool
{
$key = (string) $key;
if ($array[$key] ?? 0) {
return (bool) $array[$key];
}
return $default;
}
|
[
"public",
"static",
"function",
"getBool",
"(",
"array",
"$",
"array",
",",
"$",
"key",
",",
"bool",
"$",
"default",
"=",
"false",
")",
":",
"bool",
"{",
"$",
"key",
"=",
"(",
"string",
")",
"$",
"key",
";",
"if",
"(",
"$",
"array",
"[",
"$",
"key",
"]",
"??",
"0",
")",
"{",
"return",
"(",
"bool",
")",
"$",
"array",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"default",
";",
"}"
] |
Return BOOL value from array
@param array $array
@param string|int $key
@param bool $default
@return bool
|
[
"Return",
"BOOL",
"value",
"from",
"array"
] |
734992061dca91e593b33bee5f4b48112749dc60
|
https://github.com/unforge/array-toolkit/blob/734992061dca91e593b33bee5f4b48112749dc60/src/Arr.php#L115-L124
|
237,514
|
headzoo/core
|
src/Headzoo/Core/FunctionsTrait.php
|
FunctionsTrait.swapArgs
|
protected static function swapArgs(&$optional, &$swap, $default = null, $swap_required = true)
{
$is_swapped = false;
if (empty($swap) && !empty($optional)) {
$swap = $optional;
$optional = $default;
$is_swapped = true;
}
if ($swap_required && !$swap) {
if (is_string($swap_required)) {
$message = "Argument '{$swap_required}' is required.";
} else {
$message = "Missing argument.";
}
throw new Exceptions\InvalidArgumentException($message);
}
return $is_swapped;
}
|
php
|
protected static function swapArgs(&$optional, &$swap, $default = null, $swap_required = true)
{
$is_swapped = false;
if (empty($swap) && !empty($optional)) {
$swap = $optional;
$optional = $default;
$is_swapped = true;
}
if ($swap_required && !$swap) {
if (is_string($swap_required)) {
$message = "Argument '{$swap_required}' is required.";
} else {
$message = "Missing argument.";
}
throw new Exceptions\InvalidArgumentException($message);
}
return $is_swapped;
}
|
[
"protected",
"static",
"function",
"swapArgs",
"(",
"&",
"$",
"optional",
",",
"&",
"$",
"swap",
",",
"$",
"default",
"=",
"null",
",",
"$",
"swap_required",
"=",
"true",
")",
"{",
"$",
"is_swapped",
"=",
"false",
";",
"if",
"(",
"empty",
"(",
"$",
"swap",
")",
"&&",
"!",
"empty",
"(",
"$",
"optional",
")",
")",
"{",
"$",
"swap",
"=",
"$",
"optional",
";",
"$",
"optional",
"=",
"$",
"default",
";",
"$",
"is_swapped",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"swap_required",
"&&",
"!",
"$",
"swap",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"swap_required",
")",
")",
"{",
"$",
"message",
"=",
"\"Argument '{$swap_required}' is required.\"",
";",
"}",
"else",
"{",
"$",
"message",
"=",
"\"Missing argument.\"",
";",
"}",
"throw",
"new",
"Exceptions",
"\\",
"InvalidArgumentException",
"(",
"$",
"message",
")",
";",
"}",
"return",
"$",
"is_swapped",
";",
"}"
] |
Swaps two values when the second is empty and the first is not
Returns true when the arguments were swapped, and false if not.
Example:
```php
$env = "live";
$values = null;
public function fetch($env, $values = null)
{
$is_swapped = $this->swapArgs($env, $values, "dev");
var_dump($is_swapped);
var_dump($env);
var_dump($values);
// Outputs:
// bool(true)
// string(4) "dev"
// string(4) "live"
}
```
@param mixed $optional Swap when this value is not empty
@param mixed $swap Swap when this value is empty
@param null $default The new value for $optional when swapped
@param bool $swap_required Is the $swap argument required?
@throws Exceptions\InvalidArgumentException When the $swap value is required and is empty
@return bool
|
[
"Swaps",
"two",
"values",
"when",
"the",
"second",
"is",
"empty",
"and",
"the",
"first",
"is",
"not"
] |
1e574813e197aa827b3e952f8caa81be31a8b5b5
|
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/FunctionsTrait.php#L57-L75
|
237,515
|
headzoo/core
|
src/Headzoo/Core/FunctionsTrait.php
|
FunctionsTrait.swapCallable
|
protected static function swapCallable(&$optional, &$callable, $default = null, $callable_required = true)
{
$is_swapped = false;
if (is_callable($optional)) {
$callable = $optional;
$optional = $default;
$is_swapped = true;
}
if ($callable_required && !$callable) {
throw new Exceptions\InvalidArgumentException(
"A callable object is required."
);
}
return $is_swapped;
}
|
php
|
protected static function swapCallable(&$optional, &$callable, $default = null, $callable_required = true)
{
$is_swapped = false;
if (is_callable($optional)) {
$callable = $optional;
$optional = $default;
$is_swapped = true;
}
if ($callable_required && !$callable) {
throw new Exceptions\InvalidArgumentException(
"A callable object is required."
);
}
return $is_swapped;
}
|
[
"protected",
"static",
"function",
"swapCallable",
"(",
"&",
"$",
"optional",
",",
"&",
"$",
"callable",
",",
"$",
"default",
"=",
"null",
",",
"$",
"callable_required",
"=",
"true",
")",
"{",
"$",
"is_swapped",
"=",
"false",
";",
"if",
"(",
"is_callable",
"(",
"$",
"optional",
")",
")",
"{",
"$",
"callable",
"=",
"$",
"optional",
";",
"$",
"optional",
"=",
"$",
"default",
";",
"$",
"is_swapped",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"callable_required",
"&&",
"!",
"$",
"callable",
")",
"{",
"throw",
"new",
"Exceptions",
"\\",
"InvalidArgumentException",
"(",
"\"A callable object is required.\"",
")",
";",
"}",
"return",
"$",
"is_swapped",
";",
"}"
] |
Swaps two variables when the second is a callable object
Used to create functions/methods which have callbacks as the final argument, and
it's desirable to make middle argument optional, while the callback remains the
final argument.
Throws an exception when $callable_required is true, and the callable object is
empty.
Returns true if the arguments were swapped, false if not.
Examples:
```php
public function joinArray(array $values, $separator, callable $callback = null)
{
$this->swapCallable($separator, $callback, "-");
$values = array_map($callback, $values);
return join($separator, $values);
}
// The function above may be called normally, like this:
$values = ["headzoo", "joe"];
$this->joinArray($values, "-", 'Headzoo\Core\String::quote');
// Or the middle argument may be omitted, and called like this:
$this->joinArray($values, 'Headzoo\Core\String::quote');
```
@param mixed $optional The optional argument
@param mixed $callable Possibly a callable object
@param mixed $default The optional argument default value
@param bool $callable_required Whether the callable object is required (cannot be empty)
@throws Exceptions\InvalidArgumentException When the callable is required and empty
@return bool
|
[
"Swaps",
"two",
"variables",
"when",
"the",
"second",
"is",
"a",
"callable",
"object"
] |
1e574813e197aa827b3e952f8caa81be31a8b5b5
|
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/FunctionsTrait.php#L114-L129
|
237,516
|
headzoo/core
|
src/Headzoo/Core/FunctionsTrait.php
|
FunctionsTrait.throwOnInvalidArgument
|
protected static function throwOnInvalidArgument($arg, $type)
{
$args = func_get_args();
$arg = array_shift($args);
$arg_type = gettype($arg);
$found = false;
foreach($args as $type) {
if ((in_array($type, self::$native_php_types) && $arg_type == $type) || $arg instanceof $type) {
$found = true;
break;
}
}
if (!$found) {
throw new Exceptions\InvalidArgumentException(
sprintf(
"Argument must be of type %s.",
Arrays::conjunct($args, "or")
)
);
}
return true;
}
|
php
|
protected static function throwOnInvalidArgument($arg, $type)
{
$args = func_get_args();
$arg = array_shift($args);
$arg_type = gettype($arg);
$found = false;
foreach($args as $type) {
if ((in_array($type, self::$native_php_types) && $arg_type == $type) || $arg instanceof $type) {
$found = true;
break;
}
}
if (!$found) {
throw new Exceptions\InvalidArgumentException(
sprintf(
"Argument must be of type %s.",
Arrays::conjunct($args, "or")
)
);
}
return true;
}
|
[
"protected",
"static",
"function",
"throwOnInvalidArgument",
"(",
"$",
"arg",
",",
"$",
"type",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"arg",
"=",
"array_shift",
"(",
"$",
"args",
")",
";",
"$",
"arg_type",
"=",
"gettype",
"(",
"$",
"arg",
")",
";",
"$",
"found",
"=",
"false",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"type",
")",
"{",
"if",
"(",
"(",
"in_array",
"(",
"$",
"type",
",",
"self",
"::",
"$",
"native_php_types",
")",
"&&",
"$",
"arg_type",
"==",
"$",
"type",
")",
"||",
"$",
"arg",
"instanceof",
"$",
"type",
")",
"{",
"$",
"found",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"found",
")",
"{",
"throw",
"new",
"Exceptions",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"\"Argument must be of type %s.\"",
",",
"Arrays",
"::",
"conjunct",
"(",
"$",
"args",
",",
"\"or\"",
")",
")",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Throws an InvalidArgumentException when the argument is not one of the given types
The $type argument should be one of the native PHP types returned by gettype() or the name of
a class, in which case the argument must be an instance of that class.
This method always returns true.
Example:
public function fetch($values)
{
$this->throwOnInvalidArgument($values, "array", ArrayableInterface::class);
... other stuff ...
}
```
@param string $arg The argument
@param string $type The first type to check
@throws Exceptions\InvalidArgumentException
@internal param $string ... Additional types to check
@return bool
|
[
"Throws",
"an",
"InvalidArgumentException",
"when",
"the",
"argument",
"is",
"not",
"one",
"of",
"the",
"given",
"types"
] |
1e574813e197aa827b3e952f8caa81be31a8b5b5
|
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/FunctionsTrait.php#L201-L225
|
237,517
|
guru-digital/framework-types
|
GDM/Framework/Types/Url.php
|
Url.parse
|
private function parse()
{
$this->parameters = [];
$this->pathSegments = [];
$parsedUrl = parse_url($this->returnValue);
foreach ($parsedUrl as $key => $value) {
if ($key == 'query') {
parse_str($value, $this->parameters);
} elseif ($key == 'path') {
$this->pathSegments = ($value) ? explode('/', ltrim($value, '/')) : [];
} else {
$this->{$key} = $value;
}
}
return $this;
}
|
php
|
private function parse()
{
$this->parameters = [];
$this->pathSegments = [];
$parsedUrl = parse_url($this->returnValue);
foreach ($parsedUrl as $key => $value) {
if ($key == 'query') {
parse_str($value, $this->parameters);
} elseif ($key == 'path') {
$this->pathSegments = ($value) ? explode('/', ltrim($value, '/')) : [];
} else {
$this->{$key} = $value;
}
}
return $this;
}
|
[
"private",
"function",
"parse",
"(",
")",
"{",
"$",
"this",
"->",
"parameters",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"pathSegments",
"=",
"[",
"]",
";",
"$",
"parsedUrl",
"=",
"parse_url",
"(",
"$",
"this",
"->",
"returnValue",
")",
";",
"foreach",
"(",
"$",
"parsedUrl",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"key",
"==",
"'query'",
")",
"{",
"parse_str",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"parameters",
")",
";",
"}",
"elseif",
"(",
"$",
"key",
"==",
"'path'",
")",
"{",
"$",
"this",
"->",
"pathSegments",
"=",
"(",
"$",
"value",
")",
"?",
"explode",
"(",
"'/'",
",",
"ltrim",
"(",
"$",
"value",
",",
"'/'",
")",
")",
":",
"[",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"{",
"$",
"key",
"}",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Parses the current returnValue and fills this objects properties
@return $this
|
[
"Parses",
"the",
"current",
"returnValue",
"and",
"fills",
"this",
"objects",
"properties"
] |
f14e9b1e6cc2571414ba7d561bb205644e28e17d
|
https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/Url.php#L27-L42
|
237,518
|
guru-digital/framework-types
|
GDM/Framework/Types/Url.php
|
Url.compareTo
|
public function compareTo($url, $caseSensitive = true, $includeQuery = false, $ignoreSpecialChars = false)
{
/* @var $urlObj Url */
$urlObj = $url instanceof Url ? $url : self::create($url)->decodePath();
/* @var $urlObj2 Url */
$urlObj2 = clone $this;
$urlObj2->decodePath();
if ($ignoreSpecialChars) {
$urlObj->tidy();
$urlObj2->tidy();
}
if (!$includeQuery) {
$urlObj->parameters = [];
$urlObj2->parameters = [];
}
return $caseSensitive ? strcmp($urlObj, $urlObj2) : strcasecmp($urlObj, $urlObj2);
}
|
php
|
public function compareTo($url, $caseSensitive = true, $includeQuery = false, $ignoreSpecialChars = false)
{
/* @var $urlObj Url */
$urlObj = $url instanceof Url ? $url : self::create($url)->decodePath();
/* @var $urlObj2 Url */
$urlObj2 = clone $this;
$urlObj2->decodePath();
if ($ignoreSpecialChars) {
$urlObj->tidy();
$urlObj2->tidy();
}
if (!$includeQuery) {
$urlObj->parameters = [];
$urlObj2->parameters = [];
}
return $caseSensitive ? strcmp($urlObj, $urlObj2) : strcasecmp($urlObj, $urlObj2);
}
|
[
"public",
"function",
"compareTo",
"(",
"$",
"url",
",",
"$",
"caseSensitive",
"=",
"true",
",",
"$",
"includeQuery",
"=",
"false",
",",
"$",
"ignoreSpecialChars",
"=",
"false",
")",
"{",
"/* @var $urlObj Url */",
"$",
"urlObj",
"=",
"$",
"url",
"instanceof",
"Url",
"?",
"$",
"url",
":",
"self",
"::",
"create",
"(",
"$",
"url",
")",
"->",
"decodePath",
"(",
")",
";",
"/* @var $urlObj2 Url */",
"$",
"urlObj2",
"=",
"clone",
"$",
"this",
";",
"$",
"urlObj2",
"->",
"decodePath",
"(",
")",
";",
"if",
"(",
"$",
"ignoreSpecialChars",
")",
"{",
"$",
"urlObj",
"->",
"tidy",
"(",
")",
";",
"$",
"urlObj2",
"->",
"tidy",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"includeQuery",
")",
"{",
"$",
"urlObj",
"->",
"parameters",
"=",
"[",
"]",
";",
"$",
"urlObj2",
"->",
"parameters",
"=",
"[",
"]",
";",
"}",
"return",
"$",
"caseSensitive",
"?",
"strcmp",
"(",
"$",
"urlObj",
",",
"$",
"urlObj2",
")",
":",
"strcasecmp",
"(",
"$",
"urlObj",
",",
"$",
"urlObj2",
")",
";",
"}"
] |
Checks if this url object is equal to another.
@param string $str2 <p>
The string to compare against
</p>
@param bool $caseSensitive [optional] <p>
If true the string comparision is case sensitive
</p>
</p>
@param bool $includeQuery [optional] <p>
If true the query string is ignored from the string comparision
</p>
@param bool $ignoreSpecialChars [optional] <p>
If true the special characters are ignored from the string comparision
</p>
@return int < 0 if <i>str1</i> is less than
<i>str2</i>; > 0 if <i>str1</i>
is greater than <i>str2</i>, and 0 if they are
equal.
|
[
"Checks",
"if",
"this",
"url",
"object",
"is",
"equal",
"to",
"another",
"."
] |
f14e9b1e6cc2571414ba7d561bb205644e28e17d
|
https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/Url.php#L123-L139
|
237,519
|
guru-digital/framework-types
|
GDM/Framework/Types/Url.php
|
Url.fromObject
|
function fromObject($value)
{
$this->clear();
$this->orignalValue = $this->returnValue = (string) (method_exists($value, '__toString') ? $value : null);
return $this->parse();
}
|
php
|
function fromObject($value)
{
$this->clear();
$this->orignalValue = $this->returnValue = (string) (method_exists($value, '__toString') ? $value : null);
return $this->parse();
}
|
[
"function",
"fromObject",
"(",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"$",
"this",
"->",
"orignalValue",
"=",
"$",
"this",
"->",
"returnValue",
"=",
"(",
"string",
")",
"(",
"method_exists",
"(",
"$",
"value",
",",
"'__toString'",
")",
"?",
"$",
"value",
":",
"null",
")",
";",
"return",
"$",
"this",
"->",
"parse",
"(",
")",
";",
"}"
] |
Create a Url instance from an object.
@param object $value
@return $this
|
[
"Create",
"a",
"Url",
"instance",
"from",
"an",
"object",
"."
] |
f14e9b1e6cc2571414ba7d561bb205644e28e17d
|
https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/Url.php#L175-L180
|
237,520
|
guru-digital/framework-types
|
GDM/Framework/Types/Url.php
|
Url.fromString
|
function fromString($value)
{
$this->clear();
$this->orignalValue = $this->returnValue = (string) $value;
return $this->parse();
}
|
php
|
function fromString($value)
{
$this->clear();
$this->orignalValue = $this->returnValue = (string) $value;
return $this->parse();
}
|
[
"function",
"fromString",
"(",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"$",
"this",
"->",
"orignalValue",
"=",
"$",
"this",
"->",
"returnValue",
"=",
"(",
"string",
")",
"$",
"value",
";",
"return",
"$",
"this",
"->",
"parse",
"(",
")",
";",
"}"
] |
Create a Url instance from a string.
@param string $value
@return $this
|
[
"Create",
"a",
"Url",
"instance",
"from",
"a",
"string",
"."
] |
f14e9b1e6cc2571414ba7d561bb205644e28e17d
|
https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/Url.php#L188-L193
|
237,521
|
guru-digital/framework-types
|
GDM/Framework/Types/Url.php
|
Url.fromResource
|
function fromResource($value)
{
$this->clear();
$this->orignalValue = $this->returnValue = stream_get_contents($value);
return $this->parse();
}
|
php
|
function fromResource($value)
{
$this->clear();
$this->orignalValue = $this->returnValue = stream_get_contents($value);
return $this->parse();
}
|
[
"function",
"fromResource",
"(",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"$",
"this",
"->",
"orignalValue",
"=",
"$",
"this",
"->",
"returnValue",
"=",
"stream_get_contents",
"(",
"$",
"value",
")",
";",
"return",
"$",
"this",
"->",
"parse",
"(",
")",
";",
"}"
] |
Create a Url instance from a resource.
@param resource $value
@return $this
|
[
"Create",
"a",
"Url",
"instance",
"from",
"a",
"resource",
"."
] |
f14e9b1e6cc2571414ba7d561bb205644e28e17d
|
https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/Url.php#L201-L206
|
237,522
|
guru-digital/framework-types
|
GDM/Framework/Types/Url.php
|
Url.clear
|
protected function clear()
{
$this->scheme = null;
$this->host = null;
$this->port = null;
$this->user = null;
$this->pass = null;
$this->pathSegments = [];
$this->parameters = [];
$this->fragment = null;
$this->orignalValue = $this->returnValue = '';
return $this->parse();
}
|
php
|
protected function clear()
{
$this->scheme = null;
$this->host = null;
$this->port = null;
$this->user = null;
$this->pass = null;
$this->pathSegments = [];
$this->parameters = [];
$this->fragment = null;
$this->orignalValue = $this->returnValue = '';
return $this->parse();
}
|
[
"protected",
"function",
"clear",
"(",
")",
"{",
"$",
"this",
"->",
"scheme",
"=",
"null",
";",
"$",
"this",
"->",
"host",
"=",
"null",
";",
"$",
"this",
"->",
"port",
"=",
"null",
";",
"$",
"this",
"->",
"user",
"=",
"null",
";",
"$",
"this",
"->",
"pass",
"=",
"null",
";",
"$",
"this",
"->",
"pathSegments",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"parameters",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"fragment",
"=",
"null",
";",
"$",
"this",
"->",
"orignalValue",
"=",
"$",
"this",
"->",
"returnValue",
"=",
"''",
";",
"return",
"$",
"this",
"->",
"parse",
"(",
")",
";",
"}"
] |
Empties the values of this Url
@return $this
|
[
"Empties",
"the",
"values",
"of",
"this",
"Url"
] |
f14e9b1e6cc2571414ba7d561bb205644e28e17d
|
https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/Url.php#L213-L225
|
237,523
|
guru-digital/framework-types
|
GDM/Framework/Types/Url.php
|
Url.offsetGet
|
public function offsetGet($offset)
{
return isset($this->pathSegments[$offset]) ? $this->pathSegments[$offset] : null;
}
|
php
|
public function offsetGet($offset)
{
return isset($this->pathSegments[$offset]) ? $this->pathSegments[$offset] : null;
}
|
[
"public",
"function",
"offsetGet",
"(",
"$",
"offset",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"pathSegments",
"[",
"$",
"offset",
"]",
")",
"?",
"$",
"this",
"->",
"pathSegments",
"[",
"$",
"offset",
"]",
":",
"null",
";",
"}"
] |
Retrieve path segment
@link http://php.net/manual/en/arrayaccess.offsetget.php
@param int $offset <p>
The path segment offset to retrieve.
</p>
@return string|null The value of the path segement at the give offset or null if not set.
|
[
"Retrieve",
"path",
"segment"
] |
f14e9b1e6cc2571414ba7d561bb205644e28e17d
|
https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/Url.php#L262-L265
|
237,524
|
guru-digital/framework-types
|
GDM/Framework/Types/Url.php
|
Url.current
|
public function current($includeQuery = true)
{
$url = "";
if (!$this->serverVars && php_sapi_name() == 'cli') {
$url = "cli";
} else {
$url .= $this->currentScheme().$this->currentHost();
$port = $this->currentPort();
if (!in_array($port, [ false, 80])) {
$url .= ':'.$port;
}
$url .= $this->currentPath();
if ($includeQuery) {
$query = $this->currentQuery();
if ($query) {
$url .= '?'.$query;
}
}
}
return static::create($url);
}
|
php
|
public function current($includeQuery = true)
{
$url = "";
if (!$this->serverVars && php_sapi_name() == 'cli') {
$url = "cli";
} else {
$url .= $this->currentScheme().$this->currentHost();
$port = $this->currentPort();
if (!in_array($port, [ false, 80])) {
$url .= ':'.$port;
}
$url .= $this->currentPath();
if ($includeQuery) {
$query = $this->currentQuery();
if ($query) {
$url .= '?'.$query;
}
}
}
return static::create($url);
}
|
[
"public",
"function",
"current",
"(",
"$",
"includeQuery",
"=",
"true",
")",
"{",
"$",
"url",
"=",
"\"\"",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"serverVars",
"&&",
"php_sapi_name",
"(",
")",
"==",
"'cli'",
")",
"{",
"$",
"url",
"=",
"\"cli\"",
";",
"}",
"else",
"{",
"$",
"url",
".=",
"$",
"this",
"->",
"currentScheme",
"(",
")",
".",
"$",
"this",
"->",
"currentHost",
"(",
")",
";",
"$",
"port",
"=",
"$",
"this",
"->",
"currentPort",
"(",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"port",
",",
"[",
"false",
",",
"80",
"]",
")",
")",
"{",
"$",
"url",
".=",
"':'",
".",
"$",
"port",
";",
"}",
"$",
"url",
".=",
"$",
"this",
"->",
"currentPath",
"(",
")",
";",
"if",
"(",
"$",
"includeQuery",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"currentQuery",
"(",
")",
";",
"if",
"(",
"$",
"query",
")",
"{",
"$",
"url",
".=",
"'?'",
".",
"$",
"query",
";",
"}",
"}",
"}",
"return",
"static",
"::",
"create",
"(",
"$",
"url",
")",
";",
"}"
] |
Get the URL of current request.
@param bool $includeQuery <p>Include the query string in the result</p>
@return Url The URL of the current request or cli if called from the command line
|
[
"Get",
"the",
"URL",
"of",
"current",
"request",
"."
] |
f14e9b1e6cc2571414ba7d561bb205644e28e17d
|
https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/Url.php#L332-L352
|
237,525
|
guru-digital/framework-types
|
GDM/Framework/Types/Url.php
|
Url.currentPath
|
public function currentPath()
{
$requestURI = $this->serverVar('REQUEST_URI');
$sciptName = $this->serverVar('SCRIPT_NAME');
return rtrim(parse_url($requestURI? : $sciptName, PHP_URL_PATH), '/');
}
|
php
|
public function currentPath()
{
$requestURI = $this->serverVar('REQUEST_URI');
$sciptName = $this->serverVar('SCRIPT_NAME');
return rtrim(parse_url($requestURI? : $sciptName, PHP_URL_PATH), '/');
}
|
[
"public",
"function",
"currentPath",
"(",
")",
"{",
"$",
"requestURI",
"=",
"$",
"this",
"->",
"serverVar",
"(",
"'REQUEST_URI'",
")",
";",
"$",
"sciptName",
"=",
"$",
"this",
"->",
"serverVar",
"(",
"'SCRIPT_NAME'",
")",
";",
"return",
"rtrim",
"(",
"parse_url",
"(",
"$",
"requestURI",
"?",
":",
"$",
"sciptName",
",",
"PHP_URL_PATH",
")",
",",
"'/'",
")",
";",
"}"
] |
Get the path of the current request.
@return string
|
[
"Get",
"the",
"path",
"of",
"the",
"current",
"request",
"."
] |
f14e9b1e6cc2571414ba7d561bb205644e28e17d
|
https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/Url.php#L399-L404
|
237,526
|
guru-digital/framework-types
|
GDM/Framework/Types/Url.php
|
Url.fetch
|
public function fetch($forwardCookie = true, $contextOptions = [])
{
$cookie = $this->serverVar('HTTP_COOKIE');
if ($forwardCookie && $cookie !== false) {
$cookie = ['http' => ['header' => 'Cookie: '.$cookie."\r\n"]];
$contextOptions = array_merge($cookie, $contextOptions);
}
$context = stream_context_create($contextOptions);
return file_get_contents((string) $this, false, $context);
}
|
php
|
public function fetch($forwardCookie = true, $contextOptions = [])
{
$cookie = $this->serverVar('HTTP_COOKIE');
if ($forwardCookie && $cookie !== false) {
$cookie = ['http' => ['header' => 'Cookie: '.$cookie."\r\n"]];
$contextOptions = array_merge($cookie, $contextOptions);
}
$context = stream_context_create($contextOptions);
return file_get_contents((string) $this, false, $context);
}
|
[
"public",
"function",
"fetch",
"(",
"$",
"forwardCookie",
"=",
"true",
",",
"$",
"contextOptions",
"=",
"[",
"]",
")",
"{",
"$",
"cookie",
"=",
"$",
"this",
"->",
"serverVar",
"(",
"'HTTP_COOKIE'",
")",
";",
"if",
"(",
"$",
"forwardCookie",
"&&",
"$",
"cookie",
"!==",
"false",
")",
"{",
"$",
"cookie",
"=",
"[",
"'http'",
"=>",
"[",
"'header'",
"=>",
"'Cookie: '",
".",
"$",
"cookie",
".",
"\"\\r\\n\"",
"]",
"]",
";",
"$",
"contextOptions",
"=",
"array_merge",
"(",
"$",
"cookie",
",",
"$",
"contextOptions",
")",
";",
"}",
"$",
"context",
"=",
"stream_context_create",
"(",
"$",
"contextOptions",
")",
";",
"return",
"file_get_contents",
"(",
"(",
"string",
")",
"$",
"this",
",",
"false",
",",
"$",
"context",
")",
";",
"}"
] |
Make a request to the URL and retieve the result as a string
@param bool $forwardCookie <p>If true, the current request cookie will be forwarded in the request</p>
@param type $contextOptions [optional] <p>
Must be an associative array in the format
$arr['parameter'] = $value.
Refer to context parameters for
a listing of standard stream parameters.
</p>
@link http://www.php.net/manual/en/context.php Options that can be passed with $contectOptions
@link http://php.net/manual/en/function.file-get-contents.php The internal method used to fetch the url conetents
@return type
|
[
"Make",
"a",
"request",
"to",
"the",
"URL",
"and",
"retieve",
"the",
"result",
"as",
"a",
"string"
] |
f14e9b1e6cc2571414ba7d561bb205644e28e17d
|
https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/Url.php#L420-L429
|
237,527
|
guru-digital/framework-types
|
GDM/Framework/Types/Url.php
|
Url.toString
|
public function toString()
{
$result = "";
if ($this->scheme) {
$result .= $this->scheme.'://';
}
if ($this->user) {
$result .= $this->user;
if ($this->pass) {
$result .= $this->user;
}
$result .= '@';
}
if ($this->host) {
$result .= $this->host;
}
if ($this->port) {
$result .= ':'.$this->port;
}
if ($this->pathSegments) {
$result .= '/'.implode('/', $this->pathSegments);
}
if ($this->parameters) {
$result .= '?'.http_build_query($this->parameters);
}
if ($this->fragment) {
$result .= '#'.$this->fragment;
}
return $result;
}
|
php
|
public function toString()
{
$result = "";
if ($this->scheme) {
$result .= $this->scheme.'://';
}
if ($this->user) {
$result .= $this->user;
if ($this->pass) {
$result .= $this->user;
}
$result .= '@';
}
if ($this->host) {
$result .= $this->host;
}
if ($this->port) {
$result .= ':'.$this->port;
}
if ($this->pathSegments) {
$result .= '/'.implode('/', $this->pathSegments);
}
if ($this->parameters) {
$result .= '?'.http_build_query($this->parameters);
}
if ($this->fragment) {
$result .= '#'.$this->fragment;
}
return $result;
}
|
[
"public",
"function",
"toString",
"(",
")",
"{",
"$",
"result",
"=",
"\"\"",
";",
"if",
"(",
"$",
"this",
"->",
"scheme",
")",
"{",
"$",
"result",
".=",
"$",
"this",
"->",
"scheme",
".",
"'://'",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"user",
")",
"{",
"$",
"result",
".=",
"$",
"this",
"->",
"user",
";",
"if",
"(",
"$",
"this",
"->",
"pass",
")",
"{",
"$",
"result",
".=",
"$",
"this",
"->",
"user",
";",
"}",
"$",
"result",
".=",
"'@'",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"host",
")",
"{",
"$",
"result",
".=",
"$",
"this",
"->",
"host",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"port",
")",
"{",
"$",
"result",
".=",
"':'",
".",
"$",
"this",
"->",
"port",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"pathSegments",
")",
"{",
"$",
"result",
".=",
"'/'",
".",
"implode",
"(",
"'/'",
",",
"$",
"this",
"->",
"pathSegments",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"parameters",
")",
"{",
"$",
"result",
".=",
"'?'",
".",
"http_build_query",
"(",
"$",
"this",
"->",
"parameters",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"fragment",
")",
"{",
"$",
"result",
".=",
"'#'",
".",
"$",
"this",
"->",
"fragment",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Gets the current URL as a string
@return string The resulting URL as a string
|
[
"Gets",
"the",
"current",
"URL",
"as",
"a",
"string"
] |
f14e9b1e6cc2571414ba7d561bb205644e28e17d
|
https://github.com/guru-digital/framework-types/blob/f14e9b1e6cc2571414ba7d561bb205644e28e17d/GDM/Framework/Types/Url.php#L454-L483
|
237,528
|
yii2lab/yii2-test
|
src/traits/UnitAssertTrait.php
|
UnitAssertTrait.normalizeArrayForNewLines
|
private function normalizeArrayForNewLines(array $data) {
foreach($data as $k => $item) {
if(is_string($item)) {
$data[$k] = str_replace(["\r\n", "\n\r", "\r"], "\n", $item);
} elseif(is_array($item)) {
$data[$k] = $this->normalizeArrayForNewLines($item);
}
}
return $data;
}
|
php
|
private function normalizeArrayForNewLines(array $data) {
foreach($data as $k => $item) {
if(is_string($item)) {
$data[$k] = str_replace(["\r\n", "\n\r", "\r"], "\n", $item);
} elseif(is_array($item)) {
$data[$k] = $this->normalizeArrayForNewLines($item);
}
}
return $data;
}
|
[
"private",
"function",
"normalizeArrayForNewLines",
"(",
"array",
"$",
"data",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"k",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"item",
")",
")",
"{",
"$",
"data",
"[",
"$",
"k",
"]",
"=",
"str_replace",
"(",
"[",
"\"\\r\\n\"",
",",
"\"\\n\\r\"",
",",
"\"\\r\"",
"]",
",",
"\"\\n\"",
",",
"$",
"item",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"item",
")",
")",
"{",
"$",
"data",
"[",
"$",
"k",
"]",
"=",
"$",
"this",
"->",
"normalizeArrayForNewLines",
"(",
"$",
"item",
")",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] |
crutch for linux and windows
|
[
"crutch",
"for",
"linux",
"and",
"windows"
] |
68cccc925c0365daeb4344bbd7839d9217992357
|
https://github.com/yii2lab/yii2-test/blob/68cccc925c0365daeb4344bbd7839d9217992357/src/traits/UnitAssertTrait.php#L79-L88
|
237,529
|
samurai-fw/samurai
|
src/Samurai/Component/Spec/PHPSpec/DIContainerMaintainer.php
|
DIContainerMaintainer.isUseableRaikiri
|
public function isUseableRaikiri($class)
{
$traits = [];
do {
$traits = array_merge($traits, class_uses($class));
} while ($class = get_parent_class($class));
foreach ($traits as $trait) {
$traits = array_merge($traits, class_uses($trait));
}
return in_array('Samurai\\Raikiri\\DependencyInjectable', $traits);
}
|
php
|
public function isUseableRaikiri($class)
{
$traits = [];
do {
$traits = array_merge($traits, class_uses($class));
} while ($class = get_parent_class($class));
foreach ($traits as $trait) {
$traits = array_merge($traits, class_uses($trait));
}
return in_array('Samurai\\Raikiri\\DependencyInjectable', $traits);
}
|
[
"public",
"function",
"isUseableRaikiri",
"(",
"$",
"class",
")",
"{",
"$",
"traits",
"=",
"[",
"]",
";",
"do",
"{",
"$",
"traits",
"=",
"array_merge",
"(",
"$",
"traits",
",",
"class_uses",
"(",
"$",
"class",
")",
")",
";",
"}",
"while",
"(",
"$",
"class",
"=",
"get_parent_class",
"(",
"$",
"class",
")",
")",
";",
"foreach",
"(",
"$",
"traits",
"as",
"$",
"trait",
")",
"{",
"$",
"traits",
"=",
"array_merge",
"(",
"$",
"traits",
",",
"class_uses",
"(",
"$",
"trait",
")",
")",
";",
"}",
"return",
"in_array",
"(",
"'Samurai\\\\Raikiri\\\\DependencyInjectable'",
",",
"$",
"traits",
")",
";",
"}"
] |
useable raikiri ?
@param string $class
@return boolean
|
[
"useable",
"raikiri",
"?"
] |
7ca3847b13f86e2847a17ab5e8e4e20893021d5a
|
https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/Spec/PHPSpec/DIContainerMaintainer.php#L67-L78
|
237,530
|
maiklez/multimedia
|
src/Http/Controllers/EventosController.php
|
EventosController.show
|
public function show(Request $request, Evento $evento)
{
Debugbar::info($evento);
return view('multimedia::eventos/show', [
'evento' => $evento,
]);
}
|
php
|
public function show(Request $request, Evento $evento)
{
Debugbar::info($evento);
return view('multimedia::eventos/show', [
'evento' => $evento,
]);
}
|
[
"public",
"function",
"show",
"(",
"Request",
"$",
"request",
",",
"Evento",
"$",
"evento",
")",
"{",
"Debugbar",
"::",
"info",
"(",
"$",
"evento",
")",
";",
"return",
"view",
"(",
"'multimedia::eventos/show'",
",",
"[",
"'evento'",
"=>",
"$",
"evento",
",",
"]",
")",
";",
"}"
] |
show the given task.
@param Request $request
@param Task $task
@return Response
|
[
"show",
"the",
"given",
"task",
"."
] |
581a559f6670eea09c21ba1784aff20c363c29f7
|
https://github.com/maiklez/multimedia/blob/581a559f6670eea09c21ba1784aff20c363c29f7/src/Http/Controllers/EventosController.php#L90-L96
|
237,531
|
aerialls/MadalynnPlumBundle
|
Command/DeployCommand.php
|
DeployCommand.deploy
|
protected function deploy($server, $deployer, OutputInterface $output)
{
$plum = $this->getContainer()->get('madalynn.plum');
$options = $plum->getOptions($server);
$dryrun = '';
if (isset($options['dry_run']) && $options['dry_run']) {
$dryrun = '<comment>(dry run mode)</comment>';
}
$output->writeln(sprintf('Starting %s to <info>%s</info> %s', $deployer, $server, $dryrun));
// Let's go!
$plum->deploy($server, $deployer, $options);
$output->writeln(sprintf('Successfully %s to <info>%s</info>', $deployer, $server));
}
|
php
|
protected function deploy($server, $deployer, OutputInterface $output)
{
$plum = $this->getContainer()->get('madalynn.plum');
$options = $plum->getOptions($server);
$dryrun = '';
if (isset($options['dry_run']) && $options['dry_run']) {
$dryrun = '<comment>(dry run mode)</comment>';
}
$output->writeln(sprintf('Starting %s to <info>%s</info> %s', $deployer, $server, $dryrun));
// Let's go!
$plum->deploy($server, $deployer, $options);
$output->writeln(sprintf('Successfully %s to <info>%s</info>', $deployer, $server));
}
|
[
"protected",
"function",
"deploy",
"(",
"$",
"server",
",",
"$",
"deployer",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"plum",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'madalynn.plum'",
")",
";",
"$",
"options",
"=",
"$",
"plum",
"->",
"getOptions",
"(",
"$",
"server",
")",
";",
"$",
"dryrun",
"=",
"''",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'dry_run'",
"]",
")",
"&&",
"$",
"options",
"[",
"'dry_run'",
"]",
")",
"{",
"$",
"dryrun",
"=",
"'<comment>(dry run mode)</comment>'",
";",
"}",
"$",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"'Starting %s to <info>%s</info> %s'",
",",
"$",
"deployer",
",",
"$",
"server",
",",
"$",
"dryrun",
")",
")",
";",
"// Let's go!",
"$",
"plum",
"->",
"deploy",
"(",
"$",
"server",
",",
"$",
"deployer",
",",
"$",
"options",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"'Successfully %s to <info>%s</info>'",
",",
"$",
"deployer",
",",
"$",
"server",
")",
")",
";",
"}"
] |
Deploys the application to another server using a deployer.
@param string $server The server name
@param string $deployer The deployer name
@param OutputInterface $output The output object
|
[
"Deploys",
"the",
"application",
"to",
"another",
"server",
"using",
"a",
"deployer",
"."
] |
6f7032db7c31d8fcbf378c266cd82f032a2ee963
|
https://github.com/aerialls/MadalynnPlumBundle/blob/6f7032db7c31d8fcbf378c266cd82f032a2ee963/Command/DeployCommand.php#L70-L86
|
237,532
|
mrcoco/phalms-core
|
user/controllers/ProfilesController.php
|
ProfilesController.searchAction
|
public function searchAction()
{
$numberPage = 1;
if ($this->request->isPost()) {
$query = Criteria::fromInput($this->di, 'Modules\User\Models\Profiles', $this->request->getPost());
$this->persistent->searchParams = $query->getParams();
} else {
$numberPage = $this->request->getQuery("page", "int");
}
$parameters = [];
if ($this->persistent->searchParams) {
$parameters = $this->persistent->searchParams;
}
$profiles = Profiles::find($parameters);
if (count($profiles) == 0) {
$this->flash->notice("The search did not find any profiles");
return $this->dispatcher->forward([
"action" => "index"
]);
}
$paginator = new Paginator([
"data" => $profiles,
"limit" => 10,
"page" => $numberPage
]);
$this->view->page = $paginator->getPaginate();
}
|
php
|
public function searchAction()
{
$numberPage = 1;
if ($this->request->isPost()) {
$query = Criteria::fromInput($this->di, 'Modules\User\Models\Profiles', $this->request->getPost());
$this->persistent->searchParams = $query->getParams();
} else {
$numberPage = $this->request->getQuery("page", "int");
}
$parameters = [];
if ($this->persistent->searchParams) {
$parameters = $this->persistent->searchParams;
}
$profiles = Profiles::find($parameters);
if (count($profiles) == 0) {
$this->flash->notice("The search did not find any profiles");
return $this->dispatcher->forward([
"action" => "index"
]);
}
$paginator = new Paginator([
"data" => $profiles,
"limit" => 10,
"page" => $numberPage
]);
$this->view->page = $paginator->getPaginate();
}
|
[
"public",
"function",
"searchAction",
"(",
")",
"{",
"$",
"numberPage",
"=",
"1",
";",
"if",
"(",
"$",
"this",
"->",
"request",
"->",
"isPost",
"(",
")",
")",
"{",
"$",
"query",
"=",
"Criteria",
"::",
"fromInput",
"(",
"$",
"this",
"->",
"di",
",",
"'Modules\\User\\Models\\Profiles'",
",",
"$",
"this",
"->",
"request",
"->",
"getPost",
"(",
")",
")",
";",
"$",
"this",
"->",
"persistent",
"->",
"searchParams",
"=",
"$",
"query",
"->",
"getParams",
"(",
")",
";",
"}",
"else",
"{",
"$",
"numberPage",
"=",
"$",
"this",
"->",
"request",
"->",
"getQuery",
"(",
"\"page\"",
",",
"\"int\"",
")",
";",
"}",
"$",
"parameters",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"persistent",
"->",
"searchParams",
")",
"{",
"$",
"parameters",
"=",
"$",
"this",
"->",
"persistent",
"->",
"searchParams",
";",
"}",
"$",
"profiles",
"=",
"Profiles",
"::",
"find",
"(",
"$",
"parameters",
")",
";",
"if",
"(",
"count",
"(",
"$",
"profiles",
")",
"==",
"0",
")",
"{",
"$",
"this",
"->",
"flash",
"->",
"notice",
"(",
"\"The search did not find any profiles\"",
")",
";",
"return",
"$",
"this",
"->",
"dispatcher",
"->",
"forward",
"(",
"[",
"\"action\"",
"=>",
"\"index\"",
"]",
")",
";",
"}",
"$",
"paginator",
"=",
"new",
"Paginator",
"(",
"[",
"\"data\"",
"=>",
"$",
"profiles",
",",
"\"limit\"",
"=>",
"10",
",",
"\"page\"",
"=>",
"$",
"numberPage",
"]",
")",
";",
"$",
"this",
"->",
"view",
"->",
"page",
"=",
"$",
"paginator",
"->",
"getPaginate",
"(",
")",
";",
"}"
] |
Searches for profiles
|
[
"Searches",
"for",
"profiles"
] |
23486c3e75077896e708f0d2e257cde280a79ad4
|
https://github.com/mrcoco/phalms-core/blob/23486c3e75077896e708f0d2e257cde280a79ad4/user/controllers/ProfilesController.php#L47-L79
|
237,533
|
mrcoco/phalms-core
|
user/controllers/ProfilesController.php
|
ProfilesController.createAction
|
public function createAction()
{
if ($this->request->isPost()) {
$profile = new Profiles([
'name' => $this->request->getPost('name', 'striptags'),
'active' => $this->request->getPost('active')
]);
if (!$profile->save()) {
$this->flash->error($profile->getMessages());
} else {
$this->flash->success("Profile was created successfully");
}
Tag::resetInput();
}
$this->view->form = new ProfilesForm(null);
}
|
php
|
public function createAction()
{
if ($this->request->isPost()) {
$profile = new Profiles([
'name' => $this->request->getPost('name', 'striptags'),
'active' => $this->request->getPost('active')
]);
if (!$profile->save()) {
$this->flash->error($profile->getMessages());
} else {
$this->flash->success("Profile was created successfully");
}
Tag::resetInput();
}
$this->view->form = new ProfilesForm(null);
}
|
[
"public",
"function",
"createAction",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"request",
"->",
"isPost",
"(",
")",
")",
"{",
"$",
"profile",
"=",
"new",
"Profiles",
"(",
"[",
"'name'",
"=>",
"$",
"this",
"->",
"request",
"->",
"getPost",
"(",
"'name'",
",",
"'striptags'",
")",
",",
"'active'",
"=>",
"$",
"this",
"->",
"request",
"->",
"getPost",
"(",
"'active'",
")",
"]",
")",
";",
"if",
"(",
"!",
"$",
"profile",
"->",
"save",
"(",
")",
")",
"{",
"$",
"this",
"->",
"flash",
"->",
"error",
"(",
"$",
"profile",
"->",
"getMessages",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"flash",
"->",
"success",
"(",
"\"Profile was created successfully\"",
")",
";",
"}",
"Tag",
"::",
"resetInput",
"(",
")",
";",
"}",
"$",
"this",
"->",
"view",
"->",
"form",
"=",
"new",
"ProfilesForm",
"(",
"null",
")",
";",
"}"
] |
Creates a new Profile
|
[
"Creates",
"a",
"new",
"Profile"
] |
23486c3e75077896e708f0d2e257cde280a79ad4
|
https://github.com/mrcoco/phalms-core/blob/23486c3e75077896e708f0d2e257cde280a79ad4/user/controllers/ProfilesController.php#L84-L103
|
237,534
|
mrcoco/phalms-core
|
user/controllers/ProfilesController.php
|
ProfilesController.editAction
|
public function editAction($id)
{
$profile = Profiles::findFirstById($id);
if (!$profile) {
$this->flash->error("Profile was not found");
return $this->dispatcher->forward([
'action' => 'index'
]);
}
if ($this->request->isPost()) {
$profile->assign([
'name' => $this->request->getPost('name', 'striptags'),
'active' => $this->request->getPost('active')
]);
if (!$profile->save()) {
$this->flash->error($profile->getMessages());
} else {
$this->flash->success("Profile was updated successfully");
}
Tag::resetInput();
}
$this->view->form = new ProfilesForm($profile, [
'edit' => true
]);
$this->view->profile = $profile;
}
|
php
|
public function editAction($id)
{
$profile = Profiles::findFirstById($id);
if (!$profile) {
$this->flash->error("Profile was not found");
return $this->dispatcher->forward([
'action' => 'index'
]);
}
if ($this->request->isPost()) {
$profile->assign([
'name' => $this->request->getPost('name', 'striptags'),
'active' => $this->request->getPost('active')
]);
if (!$profile->save()) {
$this->flash->error($profile->getMessages());
} else {
$this->flash->success("Profile was updated successfully");
}
Tag::resetInput();
}
$this->view->form = new ProfilesForm($profile, [
'edit' => true
]);
$this->view->profile = $profile;
}
|
[
"public",
"function",
"editAction",
"(",
"$",
"id",
")",
"{",
"$",
"profile",
"=",
"Profiles",
"::",
"findFirstById",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"profile",
")",
"{",
"$",
"this",
"->",
"flash",
"->",
"error",
"(",
"\"Profile was not found\"",
")",
";",
"return",
"$",
"this",
"->",
"dispatcher",
"->",
"forward",
"(",
"[",
"'action'",
"=>",
"'index'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"request",
"->",
"isPost",
"(",
")",
")",
"{",
"$",
"profile",
"->",
"assign",
"(",
"[",
"'name'",
"=>",
"$",
"this",
"->",
"request",
"->",
"getPost",
"(",
"'name'",
",",
"'striptags'",
")",
",",
"'active'",
"=>",
"$",
"this",
"->",
"request",
"->",
"getPost",
"(",
"'active'",
")",
"]",
")",
";",
"if",
"(",
"!",
"$",
"profile",
"->",
"save",
"(",
")",
")",
"{",
"$",
"this",
"->",
"flash",
"->",
"error",
"(",
"$",
"profile",
"->",
"getMessages",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"flash",
"->",
"success",
"(",
"\"Profile was updated successfully\"",
")",
";",
"}",
"Tag",
"::",
"resetInput",
"(",
")",
";",
"}",
"$",
"this",
"->",
"view",
"->",
"form",
"=",
"new",
"ProfilesForm",
"(",
"$",
"profile",
",",
"[",
"'edit'",
"=>",
"true",
"]",
")",
";",
"$",
"this",
"->",
"view",
"->",
"profile",
"=",
"$",
"profile",
";",
"}"
] |
Edits an existing Profile
@param int $id
|
[
"Edits",
"an",
"existing",
"Profile"
] |
23486c3e75077896e708f0d2e257cde280a79ad4
|
https://github.com/mrcoco/phalms-core/blob/23486c3e75077896e708f0d2e257cde280a79ad4/user/controllers/ProfilesController.php#L110-L141
|
237,535
|
mrcoco/phalms-core
|
user/controllers/ProfilesController.php
|
ProfilesController.deleteAction
|
public function deleteAction($id)
{
$profile = Profiles::findFirstById($id);
if (!$profile) {
$this->flash->error("Profile was not found");
return $this->dispatcher->forward([
'action' => 'index'
]);
}
if (!$profile->delete()) {
$this->flash->error($profile->getMessages());
} else {
$this->flash->success("Profile was deleted");
}
return $this->dispatcher->forward([
'action' => 'index'
]);
}
|
php
|
public function deleteAction($id)
{
$profile = Profiles::findFirstById($id);
if (!$profile) {
$this->flash->error("Profile was not found");
return $this->dispatcher->forward([
'action' => 'index'
]);
}
if (!$profile->delete()) {
$this->flash->error($profile->getMessages());
} else {
$this->flash->success("Profile was deleted");
}
return $this->dispatcher->forward([
'action' => 'index'
]);
}
|
[
"public",
"function",
"deleteAction",
"(",
"$",
"id",
")",
"{",
"$",
"profile",
"=",
"Profiles",
"::",
"findFirstById",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"profile",
")",
"{",
"$",
"this",
"->",
"flash",
"->",
"error",
"(",
"\"Profile was not found\"",
")",
";",
"return",
"$",
"this",
"->",
"dispatcher",
"->",
"forward",
"(",
"[",
"'action'",
"=>",
"'index'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"$",
"profile",
"->",
"delete",
"(",
")",
")",
"{",
"$",
"this",
"->",
"flash",
"->",
"error",
"(",
"$",
"profile",
"->",
"getMessages",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"flash",
"->",
"success",
"(",
"\"Profile was deleted\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"dispatcher",
"->",
"forward",
"(",
"[",
"'action'",
"=>",
"'index'",
"]",
")",
";",
"}"
] |
Deletes a Profile
@param int $id
|
[
"Deletes",
"a",
"Profile"
] |
23486c3e75077896e708f0d2e257cde280a79ad4
|
https://github.com/mrcoco/phalms-core/blob/23486c3e75077896e708f0d2e257cde280a79ad4/user/controllers/ProfilesController.php#L148-L169
|
237,536
|
heyday/heystack-ecommerce-core
|
src/Currency/CurrencyService.php
|
CurrencyService.restoreState
|
public function restoreState()
{
if ($activeCurrency = $this->stateService->getByKey(self::ACTIVE_CURRENCY_KEY)) {
$this->activeCurrency = $activeCurrency;
}
}
|
php
|
public function restoreState()
{
if ($activeCurrency = $this->stateService->getByKey(self::ACTIVE_CURRENCY_KEY)) {
$this->activeCurrency = $activeCurrency;
}
}
|
[
"public",
"function",
"restoreState",
"(",
")",
"{",
"if",
"(",
"$",
"activeCurrency",
"=",
"$",
"this",
"->",
"stateService",
"->",
"getByKey",
"(",
"self",
"::",
"ACTIVE_CURRENCY_KEY",
")",
")",
"{",
"$",
"this",
"->",
"activeCurrency",
"=",
"$",
"activeCurrency",
";",
"}",
"}"
] |
Uses the State service to retrieve the active currency's identifier and sets the active currency.
If the retrieved identifier is not an instance of the Identifier Interface, then it checks if it is a string,
which it uses to create a new Identifier object to set the active currency.
@return void
|
[
"Uses",
"the",
"State",
"service",
"to",
"retrieve",
"the",
"active",
"currency",
"s",
"identifier",
"and",
"sets",
"the",
"active",
"currency",
"."
] |
b56c83839cd3396da6bc881d843fcb4f28b74685
|
https://github.com/heyday/heystack-ecommerce-core/blob/b56c83839cd3396da6bc881d843fcb4f28b74685/src/Currency/CurrencyService.php#L96-L101
|
237,537
|
heyday/heystack-ecommerce-core
|
src/Currency/CurrencyService.php
|
CurrencyService.convert
|
public function convert(Money $amount, IdentifierInterface $to)
{
if (!$toCurrency = $this->getCurrency($to)) {
throw new \InvalidArgumentException("Currency not supported");
}
/** @var \Heystack\Ecommerce\Currency\Interfaces\CurrencyInterface $fromCurrency */
$fromCurrency = $amount->getCurrency();
return $amount->multiply($toCurrency->getValue() / $fromCurrency->getValue());
}
|
php
|
public function convert(Money $amount, IdentifierInterface $to)
{
if (!$toCurrency = $this->getCurrency($to)) {
throw new \InvalidArgumentException("Currency not supported");
}
/** @var \Heystack\Ecommerce\Currency\Interfaces\CurrencyInterface $fromCurrency */
$fromCurrency = $amount->getCurrency();
return $amount->multiply($toCurrency->getValue() / $fromCurrency->getValue());
}
|
[
"public",
"function",
"convert",
"(",
"Money",
"$",
"amount",
",",
"IdentifierInterface",
"$",
"to",
")",
"{",
"if",
"(",
"!",
"$",
"toCurrency",
"=",
"$",
"this",
"->",
"getCurrency",
"(",
"$",
"to",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Currency not supported\"",
")",
";",
"}",
"/** @var \\Heystack\\Ecommerce\\Currency\\Interfaces\\CurrencyInterface $fromCurrency */",
"$",
"fromCurrency",
"=",
"$",
"amount",
"->",
"getCurrency",
"(",
")",
";",
"return",
"$",
"amount",
"->",
"multiply",
"(",
"$",
"toCurrency",
"->",
"getValue",
"(",
")",
"/",
"$",
"fromCurrency",
"->",
"getValue",
"(",
")",
")",
";",
"}"
] |
Converts amount from one currency to another using the currency's identifier
Warning this method can lose precision!
@param \SebastianBergmann\Money\Money $amount
@param \Heystack\Core\Identifier\IdentifierInterface $to
@return \SebastianBergmann\Money\Money
@throws \InvalidArgumentException
|
[
"Converts",
"amount",
"from",
"one",
"currency",
"to",
"another",
"using",
"the",
"currency",
"s",
"identifier"
] |
b56c83839cd3396da6bc881d843fcb4f28b74685
|
https://github.com/heyday/heystack-ecommerce-core/blob/b56c83839cd3396da6bc881d843fcb4f28b74685/src/Currency/CurrencyService.php#L179-L189
|
237,538
|
xinc-develop/xinc-core
|
src/Build/Scheduler/DefaultScheduler.php
|
DefaultScheduler.getNextBuildTime
|
public function getNextBuildTime(BuildInterface $build)
{
if ($build->getLastBuild()->getBuildTime() == null
&& $build->getStatus() !== BuildInterface::STOPPED
) {
if (!isset($this->_nextBuildTime)) {
$this->_nextBuildTime = time();
}
return $this->_nextBuildTime;
} else {
return;
}
}
|
php
|
public function getNextBuildTime(BuildInterface $build)
{
if ($build->getLastBuild()->getBuildTime() == null
&& $build->getStatus() !== BuildInterface::STOPPED
) {
if (!isset($this->_nextBuildTime)) {
$this->_nextBuildTime = time();
}
return $this->_nextBuildTime;
} else {
return;
}
}
|
[
"public",
"function",
"getNextBuildTime",
"(",
"BuildInterface",
"$",
"build",
")",
"{",
"if",
"(",
"$",
"build",
"->",
"getLastBuild",
"(",
")",
"->",
"getBuildTime",
"(",
")",
"==",
"null",
"&&",
"$",
"build",
"->",
"getStatus",
"(",
")",
"!==",
"BuildInterface",
"::",
"STOPPED",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_nextBuildTime",
")",
")",
"{",
"$",
"this",
"->",
"_nextBuildTime",
"=",
"time",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_nextBuildTime",
";",
"}",
"else",
"{",
"return",
";",
"}",
"}"
] |
Calculates the next build timestamp
this is a build once scheduler.
@return int
|
[
"Calculates",
"the",
"next",
"build",
"timestamp",
"this",
"is",
"a",
"build",
"once",
"scheduler",
"."
] |
4bb69a6afe19e1186950a3122cbfe0989823e0d6
|
https://github.com/xinc-develop/xinc-core/blob/4bb69a6afe19e1186950a3122cbfe0989823e0d6/src/Build/Scheduler/DefaultScheduler.php#L47-L60
|
237,539
|
open-orchestra/open-orchestra-bbcode-bundle
|
BBcodeBundle/ElementNode/BBcodeDocumentElement.php
|
BBcodeDocumentElement.getAsPreviewHTML
|
public function getAsPreviewHTML()
{
$html = "";
foreach ($this->getChildren() as $child) {
$html .= $child->getAsPreviewHTML();
}
return $html;
}
|
php
|
public function getAsPreviewHTML()
{
$html = "";
foreach ($this->getChildren() as $child) {
$html .= $child->getAsPreviewHTML();
}
return $html;
}
|
[
"public",
"function",
"getAsPreviewHTML",
"(",
")",
"{",
"$",
"html",
"=",
"\"\"",
";",
"foreach",
"(",
"$",
"this",
"->",
"getChildren",
"(",
")",
"as",
"$",
"child",
")",
"{",
"$",
"html",
".=",
"$",
"child",
"->",
"getAsPreviewHTML",
"(",
")",
";",
"}",
"return",
"$",
"html",
";",
"}"
] |
Iterates through the document's children to return a html version,
in a preview context
@return string
|
[
"Iterates",
"through",
"the",
"document",
"s",
"children",
"to",
"return",
"a",
"html",
"version",
"in",
"a",
"preview",
"context"
] |
4c3ccd668c9b6d2f5c0c8bac384da0c2cd08ad54
|
https://github.com/open-orchestra/open-orchestra-bbcode-bundle/blob/4c3ccd668c9b6d2f5c0c8bac384da0c2cd08ad54/BBcodeBundle/ElementNode/BBcodeDocumentElement.php#L18-L26
|
237,540
|
AnonymPHP/Anonym-Library
|
src/Anonym/Filesystem/Adapter.php
|
Adapter.chmod
|
public function chmod($path, $mod = 0777)
{
if ($this->adapter instanceof Local) {
return chmod($path, $mod);
}
return false;
}
|
php
|
public function chmod($path, $mod = 0777)
{
if ($this->adapter instanceof Local) {
return chmod($path, $mod);
}
return false;
}
|
[
"public",
"function",
"chmod",
"(",
"$",
"path",
",",
"$",
"mod",
"=",
"0777",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"adapter",
"instanceof",
"Local",
")",
"{",
"return",
"chmod",
"(",
"$",
"path",
",",
"$",
"mod",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
set the chmod to the file
@param string $path
@param int $mod
@return bool
|
[
"set",
"the",
"chmod",
"to",
"the",
"file"
] |
c967ad804f84e8fb204593a0959cda2fed5ae075
|
https://github.com/AnonymPHP/Anonym-Library/blob/c967ad804f84e8fb204593a0959cda2fed5ae075/src/Anonym/Filesystem/Adapter.php#L43-L50
|
237,541
|
cityware/city-utility
|
src/Recursivity/Tree.php
|
Tree.getNodes
|
public function getNodes()
{
$nodes = array();
foreach ($this->nodes[$this->options['rootid']]->getDescendants() as $subnode) {
$nodes[] = $subnode;
}
return $nodes;
}
|
php
|
public function getNodes()
{
$nodes = array();
foreach ($this->nodes[$this->options['rootid']]->getDescendants() as $subnode) {
$nodes[] = $subnode;
}
return $nodes;
}
|
[
"public",
"function",
"getNodes",
"(",
")",
"{",
"$",
"nodes",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"nodes",
"[",
"$",
"this",
"->",
"options",
"[",
"'rootid'",
"]",
"]",
"->",
"getDescendants",
"(",
")",
"as",
"$",
"subnode",
")",
"{",
"$",
"nodes",
"[",
"]",
"=",
"$",
"subnode",
";",
"}",
"return",
"$",
"nodes",
";",
"}"
] |
Returns a flat, sorted array of all node objects in the tree.
@return Node[] Nodes, sorted as if the tree was hierarchical,
i.e.: the first level 1 item, then the children of
the first level 1 item (and their children), then
the second level 1 item and so on.
|
[
"Returns",
"a",
"flat",
"sorted",
"array",
"of",
"all",
"node",
"objects",
"in",
"the",
"tree",
"."
] |
fadd33233cdaf743d87c3c30e341f2b96e96e476
|
https://github.com/cityware/city-utility/blob/fadd33233cdaf743d87c3c30e341f2b96e96e476/src/Recursivity/Tree.php#L86-L93
|
237,542
|
cityware/city-utility
|
src/Recursivity/Tree.php
|
Tree.getNodeById
|
public function getNodeById($id)
{
if (empty($this->nodes[$id])) {
throw new \InvalidArgumentException("Invalid node primary key $id");
}
return $this->nodes[$id];
}
|
php
|
public function getNodeById($id)
{
if (empty($this->nodes[$id])) {
throw new \InvalidArgumentException("Invalid node primary key $id");
}
return $this->nodes[$id];
}
|
[
"public",
"function",
"getNodeById",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"nodes",
"[",
"$",
"id",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid node primary key $id\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"nodes",
"[",
"$",
"id",
"]",
";",
"}"
] |
Returns a single node from the tree, identified by its ID.
@param int $id Node ID
@throws \InvalidArgumentException
@return Node
|
[
"Returns",
"a",
"single",
"node",
"from",
"the",
"tree",
"identified",
"by",
"its",
"ID",
"."
] |
fadd33233cdaf743d87c3c30e341f2b96e96e476
|
https://github.com/cityware/city-utility/blob/fadd33233cdaf743d87c3c30e341f2b96e96e476/src/Recursivity/Tree.php#L104-L110
|
237,543
|
cityware/city-utility
|
src/Recursivity/Tree.php
|
Tree.getNodeByValuePath
|
public function getNodeByValuePath($name, array $search)
{
$findNested = function (array $nodes, array $tokens) use ($name, &$findNested) {
$token = array_shift($tokens);
foreach ($nodes as $node) {
$nodeName = $node->get($name);
if ($nodeName === $token) {
// Match
if (count($tokens)) {
// Search next level
return $findNested($node->getChildren(), $tokens);
} else {
// We found the node we were looking for
return $node;
}
}
}
return null;
};
return $findNested($this->getRootNodes(), $search);
}
|
php
|
public function getNodeByValuePath($name, array $search)
{
$findNested = function (array $nodes, array $tokens) use ($name, &$findNested) {
$token = array_shift($tokens);
foreach ($nodes as $node) {
$nodeName = $node->get($name);
if ($nodeName === $token) {
// Match
if (count($tokens)) {
// Search next level
return $findNested($node->getChildren(), $tokens);
} else {
// We found the node we were looking for
return $node;
}
}
}
return null;
};
return $findNested($this->getRootNodes(), $search);
}
|
[
"public",
"function",
"getNodeByValuePath",
"(",
"$",
"name",
",",
"array",
"$",
"search",
")",
"{",
"$",
"findNested",
"=",
"function",
"(",
"array",
"$",
"nodes",
",",
"array",
"$",
"tokens",
")",
"use",
"(",
"$",
"name",
",",
"&",
"$",
"findNested",
")",
"{",
"$",
"token",
"=",
"array_shift",
"(",
"$",
"tokens",
")",
";",
"foreach",
"(",
"$",
"nodes",
"as",
"$",
"node",
")",
"{",
"$",
"nodeName",
"=",
"$",
"node",
"->",
"get",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"nodeName",
"===",
"$",
"token",
")",
"{",
"// Match",
"if",
"(",
"count",
"(",
"$",
"tokens",
")",
")",
"{",
"// Search next level",
"return",
"$",
"findNested",
"(",
"$",
"node",
"->",
"getChildren",
"(",
")",
",",
"$",
"tokens",
")",
";",
"}",
"else",
"{",
"// We found the node we were looking for",
"return",
"$",
"node",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}",
";",
"return",
"$",
"findNested",
"(",
"$",
"this",
"->",
"getRootNodes",
"(",
")",
",",
"$",
"search",
")",
";",
"}"
] |
Returns the first node for which a specific property's values of all ancestors
and the node are equal to the values in the given argument.
Example: If nodes have property "name", and on the root level there is a node with
name "A" which has a child with name "B" which has a child which has node "C", you
would get the latter one by invoking getNodeByValuePath('name', ['A', 'B', 'C']).
Comparison is case-sensitive and type-safe.
@param string $name
@param array $search
@return Node|null
|
[
"Returns",
"the",
"first",
"node",
"for",
"which",
"a",
"specific",
"property",
"s",
"values",
"of",
"all",
"ancestors",
"and",
"the",
"node",
"are",
"equal",
"to",
"the",
"values",
"in",
"the",
"given",
"argument",
"."
] |
fadd33233cdaf743d87c3c30e341f2b96e96e476
|
https://github.com/cityware/city-utility/blob/fadd33233cdaf743d87c3c30e341f2b96e96e476/src/Recursivity/Tree.php#L136-L157
|
237,544
|
cityware/city-utility
|
src/Recursivity/Tree.php
|
Tree.build
|
private function build(array $data)
{
$children = array();
// Create the root node
$this->nodes[$this->options['rootid']] = $this->createNode(
array(
'id' => $this->options['rootid'],
'parent' => null,
)
);
foreach ($data as $row) {
$this->nodes[$row['id']] = $this->createNode($row);
if (empty($children[$row['parent']])) {
$children[$row['parent']] = array($row['id']);
} else {
$children[$row['parent']][] = $row['id'];
}
}
foreach ($children as $pid => $childids) {
foreach ($childids as $id) {
if ($pid == $id) {
throw new InvalidParentException(
"Node with ID $id references its own ID as parent ID"
);
}
if (isset($this->nodes[$pid])) {
$this->nodes[$pid]->addChild($this->nodes[$id]);
} else {
throw new InvalidParentException(
"Node with ID $id points to non-existent parent with ID $pid"
);
}
}
}
}
|
php
|
private function build(array $data)
{
$children = array();
// Create the root node
$this->nodes[$this->options['rootid']] = $this->createNode(
array(
'id' => $this->options['rootid'],
'parent' => null,
)
);
foreach ($data as $row) {
$this->nodes[$row['id']] = $this->createNode($row);
if (empty($children[$row['parent']])) {
$children[$row['parent']] = array($row['id']);
} else {
$children[$row['parent']][] = $row['id'];
}
}
foreach ($children as $pid => $childids) {
foreach ($childids as $id) {
if ($pid == $id) {
throw new InvalidParentException(
"Node with ID $id references its own ID as parent ID"
);
}
if (isset($this->nodes[$pid])) {
$this->nodes[$pid]->addChild($this->nodes[$id]);
} else {
throw new InvalidParentException(
"Node with ID $id points to non-existent parent with ID $pid"
);
}
}
}
}
|
[
"private",
"function",
"build",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"children",
"=",
"array",
"(",
")",
";",
"// Create the root node",
"$",
"this",
"->",
"nodes",
"[",
"$",
"this",
"->",
"options",
"[",
"'rootid'",
"]",
"]",
"=",
"$",
"this",
"->",
"createNode",
"(",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"options",
"[",
"'rootid'",
"]",
",",
"'parent'",
"=>",
"null",
",",
")",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"row",
")",
"{",
"$",
"this",
"->",
"nodes",
"[",
"$",
"row",
"[",
"'id'",
"]",
"]",
"=",
"$",
"this",
"->",
"createNode",
"(",
"$",
"row",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"children",
"[",
"$",
"row",
"[",
"'parent'",
"]",
"]",
")",
")",
"{",
"$",
"children",
"[",
"$",
"row",
"[",
"'parent'",
"]",
"]",
"=",
"array",
"(",
"$",
"row",
"[",
"'id'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"children",
"[",
"$",
"row",
"[",
"'parent'",
"]",
"]",
"[",
"]",
"=",
"$",
"row",
"[",
"'id'",
"]",
";",
"}",
"}",
"foreach",
"(",
"$",
"children",
"as",
"$",
"pid",
"=>",
"$",
"childids",
")",
"{",
"foreach",
"(",
"$",
"childids",
"as",
"$",
"id",
")",
"{",
"if",
"(",
"$",
"pid",
"==",
"$",
"id",
")",
"{",
"throw",
"new",
"InvalidParentException",
"(",
"\"Node with ID $id references its own ID as parent ID\"",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"nodes",
"[",
"$",
"pid",
"]",
")",
")",
"{",
"$",
"this",
"->",
"nodes",
"[",
"$",
"pid",
"]",
"->",
"addChild",
"(",
"$",
"this",
"->",
"nodes",
"[",
"$",
"id",
"]",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidParentException",
"(",
"\"Node with ID $id points to non-existent parent with ID $pid\"",
")",
";",
"}",
"}",
"}",
"}"
] |
Core method for creating the tree
@param array $data The data from which to generate the tree
@throws InvalidParentException
|
[
"Core",
"method",
"for",
"creating",
"the",
"tree"
] |
fadd33233cdaf743d87c3c30e341f2b96e96e476
|
https://github.com/cityware/city-utility/blob/fadd33233cdaf743d87c3c30e341f2b96e96e476/src/Recursivity/Tree.php#L166-L203
|
237,545
|
headzoo/core
|
src/Headzoo/Core/ErrorHandler.php
|
ErrorHandler.setRunningEnvironment
|
public function setRunningEnvironment($running_env)
{
$running_env = (string)$running_env;
if (empty($running_env)) {
$this->toss(
"InvalidArgument",
"The environment name cannot be empty."
);
}
$previous = $this->running_env;
$this->running_env = $running_env;
if (!isset($this->callbacks[$this->running_env])) {
$this->setCallback(
$this->running_env,
$this->getDefaultCallback()
);
}
return $previous;
}
|
php
|
public function setRunningEnvironment($running_env)
{
$running_env = (string)$running_env;
if (empty($running_env)) {
$this->toss(
"InvalidArgument",
"The environment name cannot be empty."
);
}
$previous = $this->running_env;
$this->running_env = $running_env;
if (!isset($this->callbacks[$this->running_env])) {
$this->setCallback(
$this->running_env,
$this->getDefaultCallback()
);
}
return $previous;
}
|
[
"public",
"function",
"setRunningEnvironment",
"(",
"$",
"running_env",
")",
"{",
"$",
"running_env",
"=",
"(",
"string",
")",
"$",
"running_env",
";",
"if",
"(",
"empty",
"(",
"$",
"running_env",
")",
")",
"{",
"$",
"this",
"->",
"toss",
"(",
"\"InvalidArgument\"",
",",
"\"The environment name cannot be empty.\"",
")",
";",
"}",
"$",
"previous",
"=",
"$",
"this",
"->",
"running_env",
";",
"$",
"this",
"->",
"running_env",
"=",
"$",
"running_env",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"callbacks",
"[",
"$",
"this",
"->",
"running_env",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setCallback",
"(",
"$",
"this",
"->",
"running_env",
",",
"$",
"this",
"->",
"getDefaultCallback",
"(",
")",
")",
";",
"}",
"return",
"$",
"previous",
";",
"}"
] |
Sets the current runtime environment
Automatically sets the default error callback for this environment if none has been
set already. Returns the previously set running environment.
@param string $running_env Name of the environment
@return string
|
[
"Sets",
"the",
"current",
"runtime",
"environment"
] |
1e574813e197aa827b3e952f8caa81be31a8b5b5
|
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/ErrorHandler.php#L258-L278
|
237,546
|
headzoo/core
|
src/Headzoo/Core/ErrorHandler.php
|
ErrorHandler.handle
|
public function handle($running_env = self::DEFAULT_ENVIRONMENT, callable $callback = null)
{
$is_handled = false;
if (!$this->is_handling && !$this->last_error) {
$this->swapCallable($running_env, $callback, $this->running_env, false);
$this->setRunningEnvironment($running_env);
if ($callback) {
$this->setCallback($callback);
}
$this->prev_exception_handler = set_exception_handler($this->getUncaughtExceptionHandler());
$this->prev_error_handler = set_error_handler($this->getCoreErrorHandler());
register_shutdown_function(function() {
if ($error = error_get_last()) {
$this->handleCoreError(
$error["type"],
$error["message"],
$error["file"],
$error["line"]
);
}
});
$this->is_handling = true;
$is_handled = true;
}
return $is_handled;
}
|
php
|
public function handle($running_env = self::DEFAULT_ENVIRONMENT, callable $callback = null)
{
$is_handled = false;
if (!$this->is_handling && !$this->last_error) {
$this->swapCallable($running_env, $callback, $this->running_env, false);
$this->setRunningEnvironment($running_env);
if ($callback) {
$this->setCallback($callback);
}
$this->prev_exception_handler = set_exception_handler($this->getUncaughtExceptionHandler());
$this->prev_error_handler = set_error_handler($this->getCoreErrorHandler());
register_shutdown_function(function() {
if ($error = error_get_last()) {
$this->handleCoreError(
$error["type"],
$error["message"],
$error["file"],
$error["line"]
);
}
});
$this->is_handling = true;
$is_handled = true;
}
return $is_handled;
}
|
[
"public",
"function",
"handle",
"(",
"$",
"running_env",
"=",
"self",
"::",
"DEFAULT_ENVIRONMENT",
",",
"callable",
"$",
"callback",
"=",
"null",
")",
"{",
"$",
"is_handled",
"=",
"false",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"is_handling",
"&&",
"!",
"$",
"this",
"->",
"last_error",
")",
"{",
"$",
"this",
"->",
"swapCallable",
"(",
"$",
"running_env",
",",
"$",
"callback",
",",
"$",
"this",
"->",
"running_env",
",",
"false",
")",
";",
"$",
"this",
"->",
"setRunningEnvironment",
"(",
"$",
"running_env",
")",
";",
"if",
"(",
"$",
"callback",
")",
"{",
"$",
"this",
"->",
"setCallback",
"(",
"$",
"callback",
")",
";",
"}",
"$",
"this",
"->",
"prev_exception_handler",
"=",
"set_exception_handler",
"(",
"$",
"this",
"->",
"getUncaughtExceptionHandler",
"(",
")",
")",
";",
"$",
"this",
"->",
"prev_error_handler",
"=",
"set_error_handler",
"(",
"$",
"this",
"->",
"getCoreErrorHandler",
"(",
")",
")",
";",
"register_shutdown_function",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"$",
"error",
"=",
"error_get_last",
"(",
")",
")",
"{",
"$",
"this",
"->",
"handleCoreError",
"(",
"$",
"error",
"[",
"\"type\"",
"]",
",",
"$",
"error",
"[",
"\"message\"",
"]",
",",
"$",
"error",
"[",
"\"file\"",
"]",
",",
"$",
"error",
"[",
"\"line\"",
"]",
")",
";",
"}",
"}",
")",
";",
"$",
"this",
"->",
"is_handling",
"=",
"true",
";",
"$",
"is_handled",
"=",
"true",
";",
"}",
"return",
"$",
"is_handled",
";",
"}"
] |
Starts handling errors
Returns true when errors are now being handled, or false when errors were already
being handled. Possibly because ::handle() had already been called, or an error has
already been handled.
Examples:
```
$handler = new ErrorHandler();
$handler->handle();
$handler = new ErrorHandler();
$handler->setCallback(function() { echo "Look out!"; });
$handler->handle();
$handler = new ErrorHandler();
$handler->setRunningEnvironment("live");
$handler->setCallback("live", function() { echo "Look out!"; });
$handler->handle();
$handler = new ErrorHandler();
$handler->handle("live", function() { echo "Look out!"; });
```
@param string $running_env The running environment
@param callable $callback The error callback
@return bool
|
[
"Starts",
"handling",
"errors"
] |
1e574813e197aa827b3e952f8caa81be31a8b5b5
|
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/ErrorHandler.php#L309-L337
|
237,547
|
headzoo/core
|
src/Headzoo/Core/ErrorHandler.php
|
ErrorHandler.unhandle
|
public function unhandle()
{
$is_unhandled = false;
if ($this->is_handling && !$this->last_error) {
if ($this->prev_exception_handler) {
set_exception_handler($this->prev_exception_handler);
$this->prev_exception_handler = null;
}
if ($this->prev_error_handler) {
set_error_handler($this->prev_error_handler);
$this->prev_error_handler = null;
}
$this->is_handling = false;
$is_unhandled = true;
}
return $is_unhandled;
}
|
php
|
public function unhandle()
{
$is_unhandled = false;
if ($this->is_handling && !$this->last_error) {
if ($this->prev_exception_handler) {
set_exception_handler($this->prev_exception_handler);
$this->prev_exception_handler = null;
}
if ($this->prev_error_handler) {
set_error_handler($this->prev_error_handler);
$this->prev_error_handler = null;
}
$this->is_handling = false;
$is_unhandled = true;
}
return $is_unhandled;
}
|
[
"public",
"function",
"unhandle",
"(",
")",
"{",
"$",
"is_unhandled",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"is_handling",
"&&",
"!",
"$",
"this",
"->",
"last_error",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"prev_exception_handler",
")",
"{",
"set_exception_handler",
"(",
"$",
"this",
"->",
"prev_exception_handler",
")",
";",
"$",
"this",
"->",
"prev_exception_handler",
"=",
"null",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"prev_error_handler",
")",
"{",
"set_error_handler",
"(",
"$",
"this",
"->",
"prev_error_handler",
")",
";",
"$",
"this",
"->",
"prev_error_handler",
"=",
"null",
";",
"}",
"$",
"this",
"->",
"is_handling",
"=",
"false",
";",
"$",
"is_unhandled",
"=",
"true",
";",
"}",
"return",
"$",
"is_unhandled",
";",
"}"
] |
Stop handling errors
Restores the original uncaught exception handler, core error handler, and stops
handling errors.
Returns true when the original error handling state has been restored, or false when
the class was not handling errors. Possibly because ::handle() was never called, or
::unhandle() was already called, or an error has already been handled.
@return bool
|
[
"Stop",
"handling",
"errors"
] |
1e574813e197aa827b3e952f8caa81be31a8b5b5
|
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/ErrorHandler.php#L351-L368
|
237,548
|
headzoo/core
|
src/Headzoo/Core/ErrorHandler.php
|
ErrorHandler.setCallback
|
public function setCallback($env, callable $callable = null)
{
$this->swapCallable($env, $callable, $this->running_env);
$this->callbacks[$env] = $callable;
if (empty($this->errors[$env])) {
$this->setCoreErrors($env, self::getDefaultCoreErrors());
}
if (empty($this->exceptions[$env])) {
$this->setUncaughtExceptions($env, self::$default_exceptions);
}
return $this;
}
|
php
|
public function setCallback($env, callable $callable = null)
{
$this->swapCallable($env, $callable, $this->running_env);
$this->callbacks[$env] = $callable;
if (empty($this->errors[$env])) {
$this->setCoreErrors($env, self::getDefaultCoreErrors());
}
if (empty($this->exceptions[$env])) {
$this->setUncaughtExceptions($env, self::$default_exceptions);
}
return $this;
}
|
[
"public",
"function",
"setCallback",
"(",
"$",
"env",
",",
"callable",
"$",
"callable",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"swapCallable",
"(",
"$",
"env",
",",
"$",
"callable",
",",
"$",
"this",
"->",
"running_env",
")",
";",
"$",
"this",
"->",
"callbacks",
"[",
"$",
"env",
"]",
"=",
"$",
"callable",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"errors",
"[",
"$",
"env",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setCoreErrors",
"(",
"$",
"env",
",",
"self",
"::",
"getDefaultCoreErrors",
"(",
")",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"exceptions",
"[",
"$",
"env",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setUncaughtExceptions",
"(",
"$",
"env",
",",
"self",
"::",
"$",
"default_exceptions",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Sets the callback that will be called when an error is handled
Uses the currently running environment when none is given.
Examples:
```php
$handler->setCallback(function($handler) {
// The $handler parameter is the ErrorHandler instance.
// The $handler->getLastError() method returns an exception which
// describes the error.
include("templates/error.php");
});
$handler->setCallback("live", function($handler) {
include("templates/error_live.php");
});
$handler->setCallback("dev", function($handler) {
include("templates/error_dev.php");
});
```
@param string|callable $env Name of the environment
@param callable|null $callable The error callback
@return $this
|
[
"Sets",
"the",
"callback",
"that",
"will",
"be",
"called",
"when",
"an",
"error",
"is",
"handled"
] |
1e574813e197aa827b3e952f8caa81be31a8b5b5
|
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/ErrorHandler.php#L408-L421
|
237,549
|
headzoo/core
|
src/Headzoo/Core/ErrorHandler.php
|
ErrorHandler.getCallback
|
public function getCallback($env = null)
{
$env = $env ?: $this->running_env;
return isset($this->callbacks[$env]) ? $this->callbacks[$env] : null;
}
|
php
|
public function getCallback($env = null)
{
$env = $env ?: $this->running_env;
return isset($this->callbacks[$env]) ? $this->callbacks[$env] : null;
}
|
[
"public",
"function",
"getCallback",
"(",
"$",
"env",
"=",
"null",
")",
"{",
"$",
"env",
"=",
"$",
"env",
"?",
":",
"$",
"this",
"->",
"running_env",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"callbacks",
"[",
"$",
"env",
"]",
")",
"?",
"$",
"this",
"->",
"callbacks",
"[",
"$",
"env",
"]",
":",
"null",
";",
"}"
] |
Returns the callback that will be called when an error is handled
Uses the currently running environment when none is given.
@param string|null $env Name of the environment
@return callable
|
[
"Returns",
"the",
"callback",
"that",
"will",
"be",
"called",
"when",
"an",
"error",
"is",
"handled"
] |
1e574813e197aa827b3e952f8caa81be31a8b5b5
|
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/ErrorHandler.php#L432-L436
|
237,550
|
headzoo/core
|
src/Headzoo/Core/ErrorHandler.php
|
ErrorHandler.defaultCallback
|
public function defaultCallback($handler)
{
$exception = $handler->getLastError();
if (php_sapi_name() != "cli") {
$message = htmlspecialchars($exception->getMessage());
$trace = nl2br(htmlspecialchars($exception->getTraceAsString()));
echo "<!DOCTYPE html><html><head><title>Error</title></head><body>",
"<h1>{$message}</h1><p>{$trace}</p></body><html>";
} else {
echo $exception->getMessage() . PHP_EOL,
"-----------" . PHP_EOL,
$exception->getTraceAsString() . PHP_EOL;
}
}
|
php
|
public function defaultCallback($handler)
{
$exception = $handler->getLastError();
if (php_sapi_name() != "cli") {
$message = htmlspecialchars($exception->getMessage());
$trace = nl2br(htmlspecialchars($exception->getTraceAsString()));
echo "<!DOCTYPE html><html><head><title>Error</title></head><body>",
"<h1>{$message}</h1><p>{$trace}</p></body><html>";
} else {
echo $exception->getMessage() . PHP_EOL,
"-----------" . PHP_EOL,
$exception->getTraceAsString() . PHP_EOL;
}
}
|
[
"public",
"function",
"defaultCallback",
"(",
"$",
"handler",
")",
"{",
"$",
"exception",
"=",
"$",
"handler",
"->",
"getLastError",
"(",
")",
";",
"if",
"(",
"php_sapi_name",
"(",
")",
"!=",
"\"cli\"",
")",
"{",
"$",
"message",
"=",
"htmlspecialchars",
"(",
"$",
"exception",
"->",
"getMessage",
"(",
")",
")",
";",
"$",
"trace",
"=",
"nl2br",
"(",
"htmlspecialchars",
"(",
"$",
"exception",
"->",
"getTraceAsString",
"(",
")",
")",
")",
";",
"echo",
"\"<!DOCTYPE html><html><head><title>Error</title></head><body>\"",
",",
"\"<h1>{$message}</h1><p>{$trace}</p></body><html>\"",
";",
"}",
"else",
"{",
"echo",
"$",
"exception",
"->",
"getMessage",
"(",
")",
".",
"PHP_EOL",
",",
"\"-----------\"",
".",
"PHP_EOL",
",",
"$",
"exception",
"->",
"getTraceAsString",
"(",
")",
".",
"PHP_EOL",
";",
"}",
"}"
] |
The default error callback
This is the default error callback. It displays a web page with error information.
This should not be used in production. Ever.
@param ErrorHandler $handler The object that handled the error
@return mixed
|
[
"The",
"default",
"error",
"callback"
] |
1e574813e197aa827b3e952f8caa81be31a8b5b5
|
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/ErrorHandler.php#L463-L476
|
237,551
|
headzoo/core
|
src/Headzoo/Core/ErrorHandler.php
|
ErrorHandler.setCoreErrors
|
public function setCoreErrors($env, $errors = 0)
{
$this->swapArgs($env, $errors, $this->running_env, false);
$this->errors[$env] = $errors;
if (!$this->getCallback($env)) {
$this->setCallback($env, $this->getDefaultCallback());
}
return $this;
}
|
php
|
public function setCoreErrors($env, $errors = 0)
{
$this->swapArgs($env, $errors, $this->running_env, false);
$this->errors[$env] = $errors;
if (!$this->getCallback($env)) {
$this->setCallback($env, $this->getDefaultCallback());
}
return $this;
}
|
[
"public",
"function",
"setCoreErrors",
"(",
"$",
"env",
",",
"$",
"errors",
"=",
"0",
")",
"{",
"$",
"this",
"->",
"swapArgs",
"(",
"$",
"env",
",",
"$",
"errors",
",",
"$",
"this",
"->",
"running_env",
",",
"false",
")",
";",
"$",
"this",
"->",
"errors",
"[",
"$",
"env",
"]",
"=",
"$",
"errors",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"getCallback",
"(",
"$",
"env",
")",
")",
"{",
"$",
"this",
"->",
"setCallback",
"(",
"$",
"env",
",",
"$",
"this",
"->",
"getDefaultCallback",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Sets the core errors which will be handled
By default only a few fatal errors are handled, but you can specify exactly which
errors to handle with this method.
Uses the currently running environment when none is given.
Examples:
```php
$handler->setCoreErrors(E_ERROR | E_WARNING | E_DEPRECIATED);
$handler->setCoreErrors("live", E_ERROR | E_WARNING);
$handler->setCoreError("dev", E_ERROR | E_WARNING | E_NOTICE);
```
@param string|int $env Name of the environment
@param int $errors The errors to handle
@return $this
|
[
"Sets",
"the",
"core",
"errors",
"which",
"will",
"be",
"handled"
] |
1e574813e197aa827b3e952f8caa81be31a8b5b5
|
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/ErrorHandler.php#L500-L510
|
237,552
|
headzoo/core
|
src/Headzoo/Core/ErrorHandler.php
|
ErrorHandler.getCoreErrors
|
public function getCoreErrors($env = null)
{
$env = $env ?: $this->running_env;
return isset($this->errors[$env]) ? $this->errors[$env] : 0;
}
|
php
|
public function getCoreErrors($env = null)
{
$env = $env ?: $this->running_env;
return isset($this->errors[$env]) ? $this->errors[$env] : 0;
}
|
[
"public",
"function",
"getCoreErrors",
"(",
"$",
"env",
"=",
"null",
")",
"{",
"$",
"env",
"=",
"$",
"env",
"?",
":",
"$",
"this",
"->",
"running_env",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"errors",
"[",
"$",
"env",
"]",
")",
"?",
"$",
"this",
"->",
"errors",
"[",
"$",
"env",
"]",
":",
"0",
";",
"}"
] |
Returns the core errors which are being handled
Uses the currently running environment when none is given.
@param string|null $env Name of the environment
@return int
|
[
"Returns",
"the",
"core",
"errors",
"which",
"are",
"being",
"handled"
] |
1e574813e197aa827b3e952f8caa81be31a8b5b5
|
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/ErrorHandler.php#L521-L525
|
237,553
|
headzoo/core
|
src/Headzoo/Core/ErrorHandler.php
|
ErrorHandler.removeCoreError
|
public function removeCoreError($env, $error = 0)
{
$this->swapArgs($env, $error, $this->running_env);
$is_removed = false;
if (isset($this->errors[$env])) {
$orig = $this->errors[$env];
$this->errors[$env] = ($this->errors[$env] & ~ $error);
$is_removed = $this->errors[$env] !== $orig;
}
return $is_removed;
}
|
php
|
public function removeCoreError($env, $error = 0)
{
$this->swapArgs($env, $error, $this->running_env);
$is_removed = false;
if (isset($this->errors[$env])) {
$orig = $this->errors[$env];
$this->errors[$env] = ($this->errors[$env] & ~ $error);
$is_removed = $this->errors[$env] !== $orig;
}
return $is_removed;
}
|
[
"public",
"function",
"removeCoreError",
"(",
"$",
"env",
",",
"$",
"error",
"=",
"0",
")",
"{",
"$",
"this",
"->",
"swapArgs",
"(",
"$",
"env",
",",
"$",
"error",
",",
"$",
"this",
"->",
"running_env",
")",
";",
"$",
"is_removed",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"errors",
"[",
"$",
"env",
"]",
")",
")",
"{",
"$",
"orig",
"=",
"$",
"this",
"->",
"errors",
"[",
"$",
"env",
"]",
";",
"$",
"this",
"->",
"errors",
"[",
"$",
"env",
"]",
"=",
"(",
"$",
"this",
"->",
"errors",
"[",
"$",
"env",
"]",
"&",
"~",
"$",
"error",
")",
";",
"$",
"is_removed",
"=",
"$",
"this",
"->",
"errors",
"[",
"$",
"env",
"]",
"!==",
"$",
"orig",
";",
"}",
"return",
"$",
"is_removed",
";",
"}"
] |
Stops handling a core error
Uses the currently running environment when none is given. Passing E_ALL removes all error handling
for the given environment.
Examples:
```php
$handler->removeCoreError(E_NOTICE);
$handler->removeCoreError("live", E_NOTICE);
$handler->removeCoreError("dev", E_NOTICE | E_DEPRECIATED);
```
@param string|int $env Name of the environment
@param string|int $error The error to remove
@return bool
|
[
"Stops",
"handling",
"a",
"core",
"error"
] |
1e574813e197aa827b3e952f8caa81be31a8b5b5
|
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/ErrorHandler.php#L547-L559
|
237,554
|
headzoo/core
|
src/Headzoo/Core/ErrorHandler.php
|
ErrorHandler.setUncaughtExceptions
|
public function setUncaughtExceptions($env, array $exceptions = [])
{
$this->swapArgs($env, $exceptions, $this->running_env, false);
$this->exceptions[$env] = [];
if (!empty($exceptions)) {
foreach($exceptions as $exception) {
$this->exceptions[$env][] = Objects::getFullName($exception);
}
if (!$this->getCallback($env)) {
$this->setCallback($env, $this->getDefaultCallback());
}
}
return $this;
}
|
php
|
public function setUncaughtExceptions($env, array $exceptions = [])
{
$this->swapArgs($env, $exceptions, $this->running_env, false);
$this->exceptions[$env] = [];
if (!empty($exceptions)) {
foreach($exceptions as $exception) {
$this->exceptions[$env][] = Objects::getFullName($exception);
}
if (!$this->getCallback($env)) {
$this->setCallback($env, $this->getDefaultCallback());
}
}
return $this;
}
|
[
"public",
"function",
"setUncaughtExceptions",
"(",
"$",
"env",
",",
"array",
"$",
"exceptions",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"swapArgs",
"(",
"$",
"env",
",",
"$",
"exceptions",
",",
"$",
"this",
"->",
"running_env",
",",
"false",
")",
";",
"$",
"this",
"->",
"exceptions",
"[",
"$",
"env",
"]",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"exceptions",
")",
")",
"{",
"foreach",
"(",
"$",
"exceptions",
"as",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"exceptions",
"[",
"$",
"env",
"]",
"[",
"]",
"=",
"Objects",
"::",
"getFullName",
"(",
"$",
"exception",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"getCallback",
"(",
"$",
"env",
")",
")",
"{",
"$",
"this",
"->",
"setCallback",
"(",
"$",
"env",
",",
"$",
"this",
"->",
"getDefaultCallback",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Sets the uncaught exceptions which will be handled
By default every uncaught exception is handled, but specific types may be
specified using this method. The $exceptions argument may be an array of class
names, or array of objects.
Uncaught exceptions will not be handled when this method is given an empty
array.
Uses the currently running environment when none is given.
Examples:
```php
$handler->setUncaughtExceptions([RuntimeException::class, LogicException::class]);
$handler->setUncaughtException("live", [RuntimeException::class, LogicException::class]);
$handler->setUncaughtException("dev", [InvalidArgumentException::class, LogicException::class]);
```
@param string|string[]|Exception[] $env Name of the environment
@param string[]|Exception[] $exceptions The exceptions to handle
@return $this
|
[
"Sets",
"the",
"uncaught",
"exceptions",
"which",
"will",
"be",
"handled"
] |
1e574813e197aa827b3e952f8caa81be31a8b5b5
|
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/ErrorHandler.php#L587-L602
|
237,555
|
headzoo/core
|
src/Headzoo/Core/ErrorHandler.php
|
ErrorHandler.getUncaughtExceptions
|
public function getUncaughtExceptions($env = null)
{
$env = $env ?: $this->running_env;
return isset($this->exceptions[$env]) ? $this->exceptions[$env] : [];
}
|
php
|
public function getUncaughtExceptions($env = null)
{
$env = $env ?: $this->running_env;
return isset($this->exceptions[$env]) ? $this->exceptions[$env] : [];
}
|
[
"public",
"function",
"getUncaughtExceptions",
"(",
"$",
"env",
"=",
"null",
")",
"{",
"$",
"env",
"=",
"$",
"env",
"?",
":",
"$",
"this",
"->",
"running_env",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"exceptions",
"[",
"$",
"env",
"]",
")",
"?",
"$",
"this",
"->",
"exceptions",
"[",
"$",
"env",
"]",
":",
"[",
"]",
";",
"}"
] |
Returns the types of uncaught exceptions which are being handled
Returns an array of class names representing the types of uncaught exceptions the
class is handling.
Uses the currently running environment when none is given.
@param string|null $env Name of the environment
@return string[]
|
[
"Returns",
"the",
"types",
"of",
"uncaught",
"exceptions",
"which",
"are",
"being",
"handled"
] |
1e574813e197aa827b3e952f8caa81be31a8b5b5
|
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/ErrorHandler.php#L616-L620
|
237,556
|
headzoo/core
|
src/Headzoo/Core/ErrorHandler.php
|
ErrorHandler.removeUncaughtException
|
public function removeUncaughtException($env, $exception = null)
{
$this->swapArgs($env, $exception, $this->running_env);
$is_removed = false;
if (isset($this->exceptions[$env])) {
$exception = Objects::getFullName($exception);
$is_removed = (bool)Arrays::remove($this->exceptions[$env], $exception);
}
return $is_removed;
}
|
php
|
public function removeUncaughtException($env, $exception = null)
{
$this->swapArgs($env, $exception, $this->running_env);
$is_removed = false;
if (isset($this->exceptions[$env])) {
$exception = Objects::getFullName($exception);
$is_removed = (bool)Arrays::remove($this->exceptions[$env], $exception);
}
return $is_removed;
}
|
[
"public",
"function",
"removeUncaughtException",
"(",
"$",
"env",
",",
"$",
"exception",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"swapArgs",
"(",
"$",
"env",
",",
"$",
"exception",
",",
"$",
"this",
"->",
"running_env",
")",
";",
"$",
"is_removed",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"exceptions",
"[",
"$",
"env",
"]",
")",
")",
"{",
"$",
"exception",
"=",
"Objects",
"::",
"getFullName",
"(",
"$",
"exception",
")",
";",
"$",
"is_removed",
"=",
"(",
"bool",
")",
"Arrays",
"::",
"remove",
"(",
"$",
"this",
"->",
"exceptions",
"[",
"$",
"env",
"]",
",",
"$",
"exception",
")",
";",
"}",
"return",
"$",
"is_removed",
";",
"}"
] |
Stops handling an uncaught exception
Tells the class to stop handling the given type of exception, which may be either
a class name, or object. Returns true if the exception type has been successfully
unhandled. A false return value means the class wasn't handling the given
exception.
Uses the currently running environment when none is given.
Examples:
```php
$handler->removeUncaughtException(LogicError::class);
$handler->removeUncaughtException("live", LogicError::class);
$handler->removeUncaughtException("dev", InvalidArgumentException::class);
```
@param string|Exception|string $env Name of the environment
@param Exception|string|null $exception The exception to check
@return bool
|
[
"Stops",
"handling",
"an",
"uncaught",
"exception"
] |
1e574813e197aa827b3e952f8caa81be31a8b5b5
|
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/ErrorHandler.php#L646-L657
|
237,557
|
headzoo/core
|
src/Headzoo/Core/ErrorHandler.php
|
ErrorHandler.isHandlingCoreError
|
public function isHandlingCoreError($env, $error = 0)
{
$this->swapArgs($env, $error, $this->running_env);
return isset($this->errors[$env]) && (($this->errors[$env] & $error) === $error);
}
|
php
|
public function isHandlingCoreError($env, $error = 0)
{
$this->swapArgs($env, $error, $this->running_env);
return isset($this->errors[$env]) && (($this->errors[$env] & $error) === $error);
}
|
[
"public",
"function",
"isHandlingCoreError",
"(",
"$",
"env",
",",
"$",
"error",
"=",
"0",
")",
"{",
"$",
"this",
"->",
"swapArgs",
"(",
"$",
"env",
",",
"$",
"error",
",",
"$",
"this",
"->",
"running_env",
")",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"errors",
"[",
"$",
"env",
"]",
")",
"&&",
"(",
"(",
"$",
"this",
"->",
"errors",
"[",
"$",
"env",
"]",
"&",
"$",
"error",
")",
"===",
"$",
"error",
")",
";",
"}"
] |
Returns whether errors of the given type are being handled
Returns true when the given error -- one of the E_ERROR constants -- is one of
the errors being handled. Otherwise false is returned.
Uses the currently running environment when none is given.
Examples:
```php
$is_handled = $handler->isHandlingCoreError(E_WARNING);
$is_handled = $handler->isHandlingCoreError("live", E_WARNING);
```
@param string|int $env The environment to check
@param string|int $error The core error to check
@return bool
|
[
"Returns",
"whether",
"errors",
"of",
"the",
"given",
"type",
"are",
"being",
"handled"
] |
1e574813e197aa827b3e952f8caa81be31a8b5b5
|
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/ErrorHandler.php#L679-L683
|
237,558
|
headzoo/core
|
src/Headzoo/Core/ErrorHandler.php
|
ErrorHandler.isHandlingUncaughtException
|
public function isHandlingUncaughtException($env, $exception = null)
{
$this->swapArgs($env, $exception, $this->running_env);
$is_handling = false;
if (isset($this->exceptions[$env])) {
if (is_object($exception)) {
$exception = Objects::getFullName($exception);
}
foreach($this->exceptions[$env] as $e) {
if (is_subclass_of($exception, $e) || $exception == $e) {
$is_handling = true;
break;
}
}
}
return $is_handling;
}
|
php
|
public function isHandlingUncaughtException($env, $exception = null)
{
$this->swapArgs($env, $exception, $this->running_env);
$is_handling = false;
if (isset($this->exceptions[$env])) {
if (is_object($exception)) {
$exception = Objects::getFullName($exception);
}
foreach($this->exceptions[$env] as $e) {
if (is_subclass_of($exception, $e) || $exception == $e) {
$is_handling = true;
break;
}
}
}
return $is_handling;
}
|
[
"public",
"function",
"isHandlingUncaughtException",
"(",
"$",
"env",
",",
"$",
"exception",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"swapArgs",
"(",
"$",
"env",
",",
"$",
"exception",
",",
"$",
"this",
"->",
"running_env",
")",
";",
"$",
"is_handling",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"exceptions",
"[",
"$",
"env",
"]",
")",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"exception",
")",
")",
"{",
"$",
"exception",
"=",
"Objects",
"::",
"getFullName",
"(",
"$",
"exception",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"exceptions",
"[",
"$",
"env",
"]",
"as",
"$",
"e",
")",
"{",
"if",
"(",
"is_subclass_of",
"(",
"$",
"exception",
",",
"$",
"e",
")",
"||",
"$",
"exception",
"==",
"$",
"e",
")",
"{",
"$",
"is_handling",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"return",
"$",
"is_handling",
";",
"}"
] |
Returns whether the given exception is being handled
Returns true when the given exception is one of the exceptions being handled for
the given running environment. Otherwise false is returned. The $exception
argument can be a class name or object.
Uses the currently running environment when none is given.
Examples:
```php
$is_handled = $handler->isHandlingUncaughtException(LogicException::class);
$is_handled = $handler->isHandlingUncaughtException("live", LogicException::class);
```
@param string|int $env The environment to check
@param string|Exception|null $exception The exception to check
@return bool
|
[
"Returns",
"whether",
"the",
"given",
"exception",
"is",
"being",
"handled"
] |
1e574813e197aa827b3e952f8caa81be31a8b5b5
|
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/ErrorHandler.php#L706-L724
|
237,559
|
headzoo/core
|
src/Headzoo/Core/ErrorHandler.php
|
ErrorHandler.handleCoreError
|
public function handleCoreError($type, $message, $file, $line)
{
$is_handled = false;
if ($this->is_handling && $this->isHandlingCoreError($type)) {
$exception = new Exceptions\PHPErrorException(
$message,
$type,
$file,
$line
);
$is_handled = $this->triggerError($exception, "Core Error");
}
return $is_handled;
}
|
php
|
public function handleCoreError($type, $message, $file, $line)
{
$is_handled = false;
if ($this->is_handling && $this->isHandlingCoreError($type)) {
$exception = new Exceptions\PHPErrorException(
$message,
$type,
$file,
$line
);
$is_handled = $this->triggerError($exception, "Core Error");
}
return $is_handled;
}
|
[
"public",
"function",
"handleCoreError",
"(",
"$",
"type",
",",
"$",
"message",
",",
"$",
"file",
",",
"$",
"line",
")",
"{",
"$",
"is_handled",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"is_handling",
"&&",
"$",
"this",
"->",
"isHandlingCoreError",
"(",
"$",
"type",
")",
")",
"{",
"$",
"exception",
"=",
"new",
"Exceptions",
"\\",
"PHPErrorException",
"(",
"$",
"message",
",",
"$",
"type",
",",
"$",
"file",
",",
"$",
"line",
")",
";",
"$",
"is_handled",
"=",
"$",
"this",
"->",
"triggerError",
"(",
"$",
"exception",
",",
"\"Core Error\"",
")",
";",
"}",
"return",
"$",
"is_handled",
";",
"}"
] |
Handles core errors
Called by PHP when an error occures. This method determines whether the error is one
of the errors being handled. If it is, the the error will be captured, and the
error callback is called.
@param int $type The level of the error raised
@param string $message The error message
@param string $file The filename that the error was raised in
@param int $line The line number the error was raised at
@return bool
|
[
"Handles",
"core",
"errors"
] |
1e574813e197aa827b3e952f8caa81be31a8b5b5
|
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/ErrorHandler.php#L740-L754
|
237,560
|
headzoo/core
|
src/Headzoo/Core/ErrorHandler.php
|
ErrorHandler.getCoreErrorHandler
|
public function getCoreErrorHandler()
{
return function($type, $message, $file, $line) {
return $this->handleCoreError($type, $message, $file, $line);
};
}
|
php
|
public function getCoreErrorHandler()
{
return function($type, $message, $file, $line) {
return $this->handleCoreError($type, $message, $file, $line);
};
}
|
[
"public",
"function",
"getCoreErrorHandler",
"(",
")",
"{",
"return",
"function",
"(",
"$",
"type",
",",
"$",
"message",
",",
"$",
"file",
",",
"$",
"line",
")",
"{",
"return",
"$",
"this",
"->",
"handleCoreError",
"(",
"$",
"type",
",",
"$",
"message",
",",
"$",
"file",
",",
"$",
"line",
")",
";",
"}",
";",
"}"
] |
Returns the callback being used to handle core errors
This method is primarily used internally when setting up error callbacks, but
is left public for testing purposes. It essentially returns a reference to
the ::handleCoreError() method.
The returned closure has the following signature:
```php
function(int $type, string $message, string $file, int $line) {}
```
@return Closure
|
[
"Returns",
"the",
"callback",
"being",
"used",
"to",
"handle",
"core",
"errors"
] |
1e574813e197aa827b3e952f8caa81be31a8b5b5
|
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/ErrorHandler.php#L791-L796
|
237,561
|
headzoo/core
|
src/Headzoo/Core/ErrorHandler.php
|
ErrorHandler.triggerError
|
protected function triggerError(Exception $exception, $label)
{
$this->unhandle();
$this->last_error = $exception;
if ($exception instanceof Exceptions\PHPErrorException) {
$type = Errors::toString($exception->getCode());
} else {
$code = $exception->getCode();
$type = get_class($exception);
$type = "{$type}[{$code}]";
}
$this->logger->error(
'{label} {type}: "{message}" in file {file}[{line}].',
[
"label" => $label,
"type" => $type,
"message" => $exception->getMessage(),
"file" => $exception->getFile(),
"line" => $exception->getLine()
]
);
try {
call_user_func($this->getCallback(), $this);
} catch (Exception $e) {}
return true;
}
|
php
|
protected function triggerError(Exception $exception, $label)
{
$this->unhandle();
$this->last_error = $exception;
if ($exception instanceof Exceptions\PHPErrorException) {
$type = Errors::toString($exception->getCode());
} else {
$code = $exception->getCode();
$type = get_class($exception);
$type = "{$type}[{$code}]";
}
$this->logger->error(
'{label} {type}: "{message}" in file {file}[{line}].',
[
"label" => $label,
"type" => $type,
"message" => $exception->getMessage(),
"file" => $exception->getFile(),
"line" => $exception->getLine()
]
);
try {
call_user_func($this->getCallback(), $this);
} catch (Exception $e) {}
return true;
}
|
[
"protected",
"function",
"triggerError",
"(",
"Exception",
"$",
"exception",
",",
"$",
"label",
")",
"{",
"$",
"this",
"->",
"unhandle",
"(",
")",
";",
"$",
"this",
"->",
"last_error",
"=",
"$",
"exception",
";",
"if",
"(",
"$",
"exception",
"instanceof",
"Exceptions",
"\\",
"PHPErrorException",
")",
"{",
"$",
"type",
"=",
"Errors",
"::",
"toString",
"(",
"$",
"exception",
"->",
"getCode",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"code",
"=",
"$",
"exception",
"->",
"getCode",
"(",
")",
";",
"$",
"type",
"=",
"get_class",
"(",
"$",
"exception",
")",
";",
"$",
"type",
"=",
"\"{$type}[{$code}]\"",
";",
"}",
"$",
"this",
"->",
"logger",
"->",
"error",
"(",
"'{label} {type}: \"{message}\" in file {file}[{line}].'",
",",
"[",
"\"label\"",
"=>",
"$",
"label",
",",
"\"type\"",
"=>",
"$",
"type",
",",
"\"message\"",
"=>",
"$",
"exception",
"->",
"getMessage",
"(",
")",
",",
"\"file\"",
"=>",
"$",
"exception",
"->",
"getFile",
"(",
")",
",",
"\"line\"",
"=>",
"$",
"exception",
"->",
"getLine",
"(",
")",
"]",
")",
";",
"try",
"{",
"call_user_func",
"(",
"$",
"this",
"->",
"getCallback",
"(",
")",
",",
"$",
"this",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"}",
"return",
"true",
";",
"}"
] |
Calls the error callback
Called by ::handleCoreError() and ::handleUncaughtException() when the type of error
captured matches an error being handled. This method calls the error callback, and
effectively shuts down the handler.
@param Exception $exception The error
@param string $label Label for the reason the error is being triggered
@return bool
|
[
"Calls",
"the",
"error",
"callback"
] |
1e574813e197aa827b3e952f8caa81be31a8b5b5
|
https://github.com/headzoo/core/blob/1e574813e197aa827b3e952f8caa81be31a8b5b5/src/Headzoo/Core/ErrorHandler.php#L831-L859
|
237,562
|
dlabas/DlcDoctrine
|
src/DlcDoctrine/Module.php
|
Module.onBootstrap
|
public function onBootstrap($e)
{
$eventManager = $e->getApplication()->getEventManager();
$serviceManager = $e->getApplication()->getServiceManager();
$options = $serviceManager->get('dlcdoctrine_module_options');
if ($options->getEnableAutoFlushFinishListener()) {
$serviceManager->get('dlcdoctrine_event_finishlistener')
->attach($eventManager);
}
}
|
php
|
public function onBootstrap($e)
{
$eventManager = $e->getApplication()->getEventManager();
$serviceManager = $e->getApplication()->getServiceManager();
$options = $serviceManager->get('dlcdoctrine_module_options');
if ($options->getEnableAutoFlushFinishListener()) {
$serviceManager->get('dlcdoctrine_event_finishlistener')
->attach($eventManager);
}
}
|
[
"public",
"function",
"onBootstrap",
"(",
"$",
"e",
")",
"{",
"$",
"eventManager",
"=",
"$",
"e",
"->",
"getApplication",
"(",
")",
"->",
"getEventManager",
"(",
")",
";",
"$",
"serviceManager",
"=",
"$",
"e",
"->",
"getApplication",
"(",
")",
"->",
"getServiceManager",
"(",
")",
";",
"$",
"options",
"=",
"$",
"serviceManager",
"->",
"get",
"(",
"'dlcdoctrine_module_options'",
")",
";",
"if",
"(",
"$",
"options",
"->",
"getEnableAutoFlushFinishListener",
"(",
")",
")",
"{",
"$",
"serviceManager",
"->",
"get",
"(",
"'dlcdoctrine_event_finishlistener'",
")",
"->",
"attach",
"(",
"$",
"eventManager",
")",
";",
"}",
"}"
] |
Registering module-specific listeners
@param \Zend\Mvc\MvcEvent $e The MvcEvent instance
@return void
|
[
"Registering",
"module",
"-",
"specific",
"listeners"
] |
1e754c208197e9aa7a9d58efcc726e109aaa6edf
|
https://github.com/dlabas/DlcDoctrine/blob/1e754c208197e9aa7a9d58efcc726e109aaa6edf/src/DlcDoctrine/Module.php#L18-L28
|
237,563
|
poliander/rio
|
src/Rio/Common/SchemaGenerator.php
|
SchemaGenerator.generate
|
private function generate()
{
$schema = [];
foreach ($this->getTables() as $table) {
$schema[$table] = $this->getTableDefinition($table);
};
foreach (array_keys($schema) as $table) {
$constraints = $this->driver->getConstraints($table);
foreach ($constraints as $constraint) {
if (false === empty($constraint['REF_TABLE'])) {
$schema[$table]['properties'][$constraint['REF_TABLE']] = $this->mapConstraint($constraint);
}
}
}
return $schema;
}
|
php
|
private function generate()
{
$schema = [];
foreach ($this->getTables() as $table) {
$schema[$table] = $this->getTableDefinition($table);
};
foreach (array_keys($schema) as $table) {
$constraints = $this->driver->getConstraints($table);
foreach ($constraints as $constraint) {
if (false === empty($constraint['REF_TABLE'])) {
$schema[$table]['properties'][$constraint['REF_TABLE']] = $this->mapConstraint($constraint);
}
}
}
return $schema;
}
|
[
"private",
"function",
"generate",
"(",
")",
"{",
"$",
"schema",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getTables",
"(",
")",
"as",
"$",
"table",
")",
"{",
"$",
"schema",
"[",
"$",
"table",
"]",
"=",
"$",
"this",
"->",
"getTableDefinition",
"(",
"$",
"table",
")",
";",
"}",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"schema",
")",
"as",
"$",
"table",
")",
"{",
"$",
"constraints",
"=",
"$",
"this",
"->",
"driver",
"->",
"getConstraints",
"(",
"$",
"table",
")",
";",
"foreach",
"(",
"$",
"constraints",
"as",
"$",
"constraint",
")",
"{",
"if",
"(",
"false",
"===",
"empty",
"(",
"$",
"constraint",
"[",
"'REF_TABLE'",
"]",
")",
")",
"{",
"$",
"schema",
"[",
"$",
"table",
"]",
"[",
"'properties'",
"]",
"[",
"$",
"constraint",
"[",
"'REF_TABLE'",
"]",
"]",
"=",
"$",
"this",
"->",
"mapConstraint",
"(",
"$",
"constraint",
")",
";",
"}",
"}",
"}",
"return",
"$",
"schema",
";",
"}"
] |
Generate database schema definition
@return array
|
[
"Generate",
"database",
"schema",
"definition"
] |
d760ea6f0b93b88d5ca0b004a800d22359653321
|
https://github.com/poliander/rio/blob/d760ea6f0b93b88d5ca0b004a800d22359653321/src/Rio/Common/SchemaGenerator.php#L46-L65
|
237,564
|
poliander/rio
|
src/Rio/Common/SchemaGenerator.php
|
SchemaGenerator.get
|
public function get($table = null)
{
$schema = $this->generate();
if ($table !== null) {
if (isset($schema[$table]) === false) {
throw new Exception('Unknown table "' . $table . '"');
}
$schema = $schema[$table];
}
return $schema;
}
|
php
|
public function get($table = null)
{
$schema = $this->generate();
if ($table !== null) {
if (isset($schema[$table]) === false) {
throw new Exception('Unknown table "' . $table . '"');
}
$schema = $schema[$table];
}
return $schema;
}
|
[
"public",
"function",
"get",
"(",
"$",
"table",
"=",
"null",
")",
"{",
"$",
"schema",
"=",
"$",
"this",
"->",
"generate",
"(",
")",
";",
"if",
"(",
"$",
"table",
"!==",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"schema",
"[",
"$",
"table",
"]",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Unknown table \"'",
".",
"$",
"table",
".",
"'\"'",
")",
";",
"}",
"$",
"schema",
"=",
"$",
"schema",
"[",
"$",
"table",
"]",
";",
"}",
"return",
"$",
"schema",
";",
"}"
] |
Get schema definition for database or given table
@param string|null $table
@return array
@throws \Rio\Exception
|
[
"Get",
"schema",
"definition",
"for",
"database",
"or",
"given",
"table"
] |
d760ea6f0b93b88d5ca0b004a800d22359653321
|
https://github.com/poliander/rio/blob/d760ea6f0b93b88d5ca0b004a800d22359653321/src/Rio/Common/SchemaGenerator.php#L156-L169
|
237,565
|
ionutmilica/ionix-framework
|
src/Routing/ControllerDispatcher.php
|
ControllerDispatcher.dispatch
|
public function dispatch(Route $route)
{
$callback = $route->getCallback();
$params = array_values($route->getData());
if ($callback instanceof Closure) {
return $this->container->resolveClosure($callback, $params);
}
$class = $this->container->make($callback[0]);
return $this->container->resolveMethod($class, $callback[1], $params);
}
|
php
|
public function dispatch(Route $route)
{
$callback = $route->getCallback();
$params = array_values($route->getData());
if ($callback instanceof Closure) {
return $this->container->resolveClosure($callback, $params);
}
$class = $this->container->make($callback[0]);
return $this->container->resolveMethod($class, $callback[1], $params);
}
|
[
"public",
"function",
"dispatch",
"(",
"Route",
"$",
"route",
")",
"{",
"$",
"callback",
"=",
"$",
"route",
"->",
"getCallback",
"(",
")",
";",
"$",
"params",
"=",
"array_values",
"(",
"$",
"route",
"->",
"getData",
"(",
")",
")",
";",
"if",
"(",
"$",
"callback",
"instanceof",
"Closure",
")",
"{",
"return",
"$",
"this",
"->",
"container",
"->",
"resolveClosure",
"(",
"$",
"callback",
",",
"$",
"params",
")",
";",
"}",
"$",
"class",
"=",
"$",
"this",
"->",
"container",
"->",
"make",
"(",
"$",
"callback",
"[",
"0",
"]",
")",
";",
"return",
"$",
"this",
"->",
"container",
"->",
"resolveMethod",
"(",
"$",
"class",
",",
"$",
"callback",
"[",
"1",
"]",
",",
"$",
"params",
")",
";",
"}"
] |
Get and serve the controller
@param Route $route
@return mixed
@throws \Exception
|
[
"Get",
"and",
"serve",
"the",
"controller"
] |
a0363667ff677f1772bdd9ac9530a9f4710f9321
|
https://github.com/ionutmilica/ionix-framework/blob/a0363667ff677f1772bdd9ac9530a9f4710f9321/src/Routing/ControllerDispatcher.php#L27-L38
|
237,566
|
academic/VipaImportBundle
|
Importer/PKP/ArticleImporter.php
|
ArticleImporter.importJournalArticles
|
public function importJournalArticles($oldJournalId, $newJournalId, $issueIds, $sectionIds)
{
$articleSql = "SELECT article_id FROM articles WHERE journal_id = :journal_id";
$articleStatement = $this->dbalConnection->prepare($articleSql);
$articleStatement->bindValue('journal_id', $oldJournalId);
$articleStatement->execute();
$articles = $articleStatement->fetchAll();
$this->importArticles($articles, $newJournalId, $sectionIds, $issueIds);
}
|
php
|
public function importJournalArticles($oldJournalId, $newJournalId, $issueIds, $sectionIds)
{
$articleSql = "SELECT article_id FROM articles WHERE journal_id = :journal_id";
$articleStatement = $this->dbalConnection->prepare($articleSql);
$articleStatement->bindValue('journal_id', $oldJournalId);
$articleStatement->execute();
$articles = $articleStatement->fetchAll();
$this->importArticles($articles, $newJournalId, $sectionIds, $issueIds);
}
|
[
"public",
"function",
"importJournalArticles",
"(",
"$",
"oldJournalId",
",",
"$",
"newJournalId",
",",
"$",
"issueIds",
",",
"$",
"sectionIds",
")",
"{",
"$",
"articleSql",
"=",
"\"SELECT article_id FROM articles WHERE journal_id = :journal_id\"",
";",
"$",
"articleStatement",
"=",
"$",
"this",
"->",
"dbalConnection",
"->",
"prepare",
"(",
"$",
"articleSql",
")",
";",
"$",
"articleStatement",
"->",
"bindValue",
"(",
"'journal_id'",
",",
"$",
"oldJournalId",
")",
";",
"$",
"articleStatement",
"->",
"execute",
"(",
")",
";",
"$",
"articles",
"=",
"$",
"articleStatement",
"->",
"fetchAll",
"(",
")",
";",
"$",
"this",
"->",
"importArticles",
"(",
"$",
"articles",
",",
"$",
"newJournalId",
",",
"$",
"sectionIds",
",",
"$",
"issueIds",
")",
";",
"}"
] |
Imports the articles of given Journal.
@param int $oldJournalId Old journal's ID
@param int $newJournalId New journal's ID
@param array $issueIds Issue IDs of journal
@param array $sectionIds Section IDs of journal
@throws Exception
@throws \Doctrine\DBAL\ConnectionException
@throws \Doctrine\DBAL\DBALException
|
[
"Imports",
"the",
"articles",
"of",
"given",
"Journal",
"."
] |
cee7d9e51613706a4fd6e2eade44041ce1af9ad3
|
https://github.com/academic/VipaImportBundle/blob/cee7d9e51613706a4fd6e2eade44041ce1af9ad3/Importer/PKP/ArticleImporter.php#L62-L71
|
237,567
|
academic/VipaImportBundle
|
Importer/PKP/ArticleImporter.php
|
ArticleImporter.importCitations
|
public function importCitations($oldArticleId, $article)
{
$this->consoleOutput->writeln("Reading citations...");
$citationSql = "SELECT * FROM citations WHERE assoc_id = :id";
$citationStatement = $this->dbalConnection->prepare($citationSql);
$citationStatement->bindValue('id', $oldArticleId);
$citationStatement->execute();
$orderCounter = 0;
$citations = $citationStatement->fetchAll();
foreach ($citations as $pkpCitation) {
$citation = new Citation();
$citation->setRaw(!empty($pkpCitation['raw_citation']) ? $pkpCitation['raw_citation'] : '-');
$citation->setOrderNum(!empty($pkpCitation['seq']) ? $pkpCitation['seq'] : $orderCounter);
$article->addCitation($citation);
$orderCounter++;
}
}
|
php
|
public function importCitations($oldArticleId, $article)
{
$this->consoleOutput->writeln("Reading citations...");
$citationSql = "SELECT * FROM citations WHERE assoc_id = :id";
$citationStatement = $this->dbalConnection->prepare($citationSql);
$citationStatement->bindValue('id', $oldArticleId);
$citationStatement->execute();
$orderCounter = 0;
$citations = $citationStatement->fetchAll();
foreach ($citations as $pkpCitation) {
$citation = new Citation();
$citation->setRaw(!empty($pkpCitation['raw_citation']) ? $pkpCitation['raw_citation'] : '-');
$citation->setOrderNum(!empty($pkpCitation['seq']) ? $pkpCitation['seq'] : $orderCounter);
$article->addCitation($citation);
$orderCounter++;
}
}
|
[
"public",
"function",
"importCitations",
"(",
"$",
"oldArticleId",
",",
"$",
"article",
")",
"{",
"$",
"this",
"->",
"consoleOutput",
"->",
"writeln",
"(",
"\"Reading citations...\"",
")",
";",
"$",
"citationSql",
"=",
"\"SELECT * FROM citations WHERE assoc_id = :id\"",
";",
"$",
"citationStatement",
"=",
"$",
"this",
"->",
"dbalConnection",
"->",
"prepare",
"(",
"$",
"citationSql",
")",
";",
"$",
"citationStatement",
"->",
"bindValue",
"(",
"'id'",
",",
"$",
"oldArticleId",
")",
";",
"$",
"citationStatement",
"->",
"execute",
"(",
")",
";",
"$",
"orderCounter",
"=",
"0",
";",
"$",
"citations",
"=",
"$",
"citationStatement",
"->",
"fetchAll",
"(",
")",
";",
"foreach",
"(",
"$",
"citations",
"as",
"$",
"pkpCitation",
")",
"{",
"$",
"citation",
"=",
"new",
"Citation",
"(",
")",
";",
"$",
"citation",
"->",
"setRaw",
"(",
"!",
"empty",
"(",
"$",
"pkpCitation",
"[",
"'raw_citation'",
"]",
")",
"?",
"$",
"pkpCitation",
"[",
"'raw_citation'",
"]",
":",
"'-'",
")",
";",
"$",
"citation",
"->",
"setOrderNum",
"(",
"!",
"empty",
"(",
"$",
"pkpCitation",
"[",
"'seq'",
"]",
")",
"?",
"$",
"pkpCitation",
"[",
"'seq'",
"]",
":",
"$",
"orderCounter",
")",
";",
"$",
"article",
"->",
"addCitation",
"(",
"$",
"citation",
")",
";",
"$",
"orderCounter",
"++",
";",
"}",
"}"
] |
Imports citations of the given article.
@param int $oldArticleId Old article's ID
@param Article $article Newly imported Article's entity
|
[
"Imports",
"citations",
"of",
"the",
"given",
"article",
"."
] |
cee7d9e51613706a4fd6e2eade44041ce1af9ad3
|
https://github.com/academic/VipaImportBundle/blob/cee7d9e51613706a4fd6e2eade44041ce1af9ad3/Importer/PKP/ArticleImporter.php#L278-L297
|
237,568
|
academic/VipaImportBundle
|
Importer/PKP/ArticleImporter.php
|
ArticleImporter.importAuthors
|
public function importAuthors($oldArticleId, $article)
{
$this->consoleOutput->writeln("Reading authors...");
$authorSql = "SELECT first_name, last_name, email, seq FROM authors " .
"WHERE submission_id = :id ORDER BY first_name, last_name, email";
$authorStatement = $this->dbalConnection->prepare($authorSql);
$authorStatement->bindValue('id', $oldArticleId);
$authorStatement->execute();
$authors = $authorStatement->fetchAll();
foreach ($authors as $pkpAuthor) {
$author = new Author();
$author->setCurrentLocale('en');
$author->setFirstName(!empty($pkpAuthor['first_name']) ? $pkpAuthor['first_name'] : '-');
$author->setLastName(!empty($pkpAuthor['last_name']) ? $pkpAuthor['last_name'] : '-');
$author->setEmail(
!empty($pkpAuthor['email']) && $pkpAuthor['email'] !== '-' ?
$pkpAuthor['email'] :
'author@example.com'
);
$articleAuthor = new ArticleAuthor();
$articleAuthor->setAuthor($author);
$articleAuthor->setArticle($article);
$articleAuthor->setAuthorOrder(!empty($pkpAuthor['seq']) ? $pkpAuthor['seq'] : 0);
}
}
|
php
|
public function importAuthors($oldArticleId, $article)
{
$this->consoleOutput->writeln("Reading authors...");
$authorSql = "SELECT first_name, last_name, email, seq FROM authors " .
"WHERE submission_id = :id ORDER BY first_name, last_name, email";
$authorStatement = $this->dbalConnection->prepare($authorSql);
$authorStatement->bindValue('id', $oldArticleId);
$authorStatement->execute();
$authors = $authorStatement->fetchAll();
foreach ($authors as $pkpAuthor) {
$author = new Author();
$author->setCurrentLocale('en');
$author->setFirstName(!empty($pkpAuthor['first_name']) ? $pkpAuthor['first_name'] : '-');
$author->setLastName(!empty($pkpAuthor['last_name']) ? $pkpAuthor['last_name'] : '-');
$author->setEmail(
!empty($pkpAuthor['email']) && $pkpAuthor['email'] !== '-' ?
$pkpAuthor['email'] :
'author@example.com'
);
$articleAuthor = new ArticleAuthor();
$articleAuthor->setAuthor($author);
$articleAuthor->setArticle($article);
$articleAuthor->setAuthorOrder(!empty($pkpAuthor['seq']) ? $pkpAuthor['seq'] : 0);
}
}
|
[
"public",
"function",
"importAuthors",
"(",
"$",
"oldArticleId",
",",
"$",
"article",
")",
"{",
"$",
"this",
"->",
"consoleOutput",
"->",
"writeln",
"(",
"\"Reading authors...\"",
")",
";",
"$",
"authorSql",
"=",
"\"SELECT first_name, last_name, email, seq FROM authors \"",
".",
"\"WHERE submission_id = :id ORDER BY first_name, last_name, email\"",
";",
"$",
"authorStatement",
"=",
"$",
"this",
"->",
"dbalConnection",
"->",
"prepare",
"(",
"$",
"authorSql",
")",
";",
"$",
"authorStatement",
"->",
"bindValue",
"(",
"'id'",
",",
"$",
"oldArticleId",
")",
";",
"$",
"authorStatement",
"->",
"execute",
"(",
")",
";",
"$",
"authors",
"=",
"$",
"authorStatement",
"->",
"fetchAll",
"(",
")",
";",
"foreach",
"(",
"$",
"authors",
"as",
"$",
"pkpAuthor",
")",
"{",
"$",
"author",
"=",
"new",
"Author",
"(",
")",
";",
"$",
"author",
"->",
"setCurrentLocale",
"(",
"'en'",
")",
";",
"$",
"author",
"->",
"setFirstName",
"(",
"!",
"empty",
"(",
"$",
"pkpAuthor",
"[",
"'first_name'",
"]",
")",
"?",
"$",
"pkpAuthor",
"[",
"'first_name'",
"]",
":",
"'-'",
")",
";",
"$",
"author",
"->",
"setLastName",
"(",
"!",
"empty",
"(",
"$",
"pkpAuthor",
"[",
"'last_name'",
"]",
")",
"?",
"$",
"pkpAuthor",
"[",
"'last_name'",
"]",
":",
"'-'",
")",
";",
"$",
"author",
"->",
"setEmail",
"(",
"!",
"empty",
"(",
"$",
"pkpAuthor",
"[",
"'email'",
"]",
")",
"&&",
"$",
"pkpAuthor",
"[",
"'email'",
"]",
"!==",
"'-'",
"?",
"$",
"pkpAuthor",
"[",
"'email'",
"]",
":",
"'author@example.com'",
")",
";",
"$",
"articleAuthor",
"=",
"new",
"ArticleAuthor",
"(",
")",
";",
"$",
"articleAuthor",
"->",
"setAuthor",
"(",
"$",
"author",
")",
";",
"$",
"articleAuthor",
"->",
"setArticle",
"(",
"$",
"article",
")",
";",
"$",
"articleAuthor",
"->",
"setAuthorOrder",
"(",
"!",
"empty",
"(",
"$",
"pkpAuthor",
"[",
"'seq'",
"]",
")",
"?",
"$",
"pkpAuthor",
"[",
"'seq'",
"]",
":",
"0",
")",
";",
"}",
"}"
] |
Imports authors of the given article.
@param int $oldArticleId Old article's ID
@param Article $article Newly imported Article entity
|
[
"Imports",
"authors",
"of",
"the",
"given",
"article",
"."
] |
cee7d9e51613706a4fd6e2eade44041ce1af9ad3
|
https://github.com/academic/VipaImportBundle/blob/cee7d9e51613706a4fd6e2eade44041ce1af9ad3/Importer/PKP/ArticleImporter.php#L304-L331
|
237,569
|
tenside/core-bundle
|
src/Command/RunTaskCommand.php
|
RunTaskCommand.fork
|
private function fork()
{
/** @var LoggerInterface $logger */
$logger = $this->getContainer()->get('logger');
if (!$this->getContainer()->get('tenside.config')->isForkingAvailable()) {
$logger->warning('Forking disabled by configuration, execution will block until the command has finished.');
return false;
} elseif (!FunctionAvailabilityCheck::isFunctionEnabled('pcntl_fork', 'pcntl')) {
$logger->warning('pcntl_fork() is not available, execution will block until the command has finished.');
return false;
} else {
$pid = pcntl_fork();
if (-1 === $pid) {
throw new \RuntimeException('pcntl_fork() returned -1.');
} elseif (0 !== $pid) {
// Tell the calling method to exit now.
$logger->info('Forked process ' . posix_getpid() . ' to pid ' . $pid);
return true;
}
$logger->info('Processing task in forked process with pid ' . posix_getpid());
return false;
}
}
|
php
|
private function fork()
{
/** @var LoggerInterface $logger */
$logger = $this->getContainer()->get('logger');
if (!$this->getContainer()->get('tenside.config')->isForkingAvailable()) {
$logger->warning('Forking disabled by configuration, execution will block until the command has finished.');
return false;
} elseif (!FunctionAvailabilityCheck::isFunctionEnabled('pcntl_fork', 'pcntl')) {
$logger->warning('pcntl_fork() is not available, execution will block until the command has finished.');
return false;
} else {
$pid = pcntl_fork();
if (-1 === $pid) {
throw new \RuntimeException('pcntl_fork() returned -1.');
} elseif (0 !== $pid) {
// Tell the calling method to exit now.
$logger->info('Forked process ' . posix_getpid() . ' to pid ' . $pid);
return true;
}
$logger->info('Processing task in forked process with pid ' . posix_getpid());
return false;
}
}
|
[
"private",
"function",
"fork",
"(",
")",
"{",
"/** @var LoggerInterface $logger */",
"$",
"logger",
"=",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'logger'",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"getContainer",
"(",
")",
"->",
"get",
"(",
"'tenside.config'",
")",
"->",
"isForkingAvailable",
"(",
")",
")",
"{",
"$",
"logger",
"->",
"warning",
"(",
"'Forking disabled by configuration, execution will block until the command has finished.'",
")",
";",
"return",
"false",
";",
"}",
"elseif",
"(",
"!",
"FunctionAvailabilityCheck",
"::",
"isFunctionEnabled",
"(",
"'pcntl_fork'",
",",
"'pcntl'",
")",
")",
"{",
"$",
"logger",
"->",
"warning",
"(",
"'pcntl_fork() is not available, execution will block until the command has finished.'",
")",
";",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"pid",
"=",
"pcntl_fork",
"(",
")",
";",
"if",
"(",
"-",
"1",
"===",
"$",
"pid",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'pcntl_fork() returned -1.'",
")",
";",
"}",
"elseif",
"(",
"0",
"!==",
"$",
"pid",
")",
"{",
"// Tell the calling method to exit now.",
"$",
"logger",
"->",
"info",
"(",
"'Forked process '",
".",
"posix_getpid",
"(",
")",
".",
"' to pid '",
".",
"$",
"pid",
")",
";",
"return",
"true",
";",
"}",
"$",
"logger",
"->",
"info",
"(",
"'Processing task in forked process with pid '",
".",
"posix_getpid",
"(",
")",
")",
";",
"return",
"false",
";",
"}",
"}"
] |
Try to fork.
The return value determines if the caller shall exit (when forking was successful and it is the forking process)
or rather proceed execution (is the fork or unable to fork).
True means exit, false means go on in this process.
@return bool
@throws \RuntimeException When the forking caused an error.
|
[
"Try",
"to",
"fork",
"."
] |
a7ffad3649cddac1e5594b4f8b65a5504363fccd
|
https://github.com/tenside/core-bundle/blob/a7ffad3649cddac1e5594b4f8b65a5504363fccd/src/Command/RunTaskCommand.php#L98-L123
|
237,570
|
scholtz/AsyncWeb
|
src/AsyncWeb/Connectors/Page.php
|
Page.resolve_url
|
function resolve_url($base, $url) {
if (!strlen($base)) return $url;
// Step 2
if (!strlen($url)) return $base;
// Step 3
if (preg_match('!^[a-z]+:!i', $url)) return $url;
$base = parse_url($base);
if ($url{0} == "#") {
// Step 2 (fragment)
$base['fragment'] = substr($url, 1);
return Page::unparse_url($base);
}
unset($base['fragment']);
unset($base['query']);
if (substr($url, 0, 2) == "//") {
// Step 4
return Page::unparse_url(array('scheme' => $base['scheme'], 'path' => $url,));
} else if ($url{0} == "/") {
// Step 5
$base['path'] = $url;
} else {
// Step 6
$path = explode('/', $base['path']);
$url_path = explode('/', $url);
// Step 6a: drop file from base
array_pop($path);
// Step 6b, 6c, 6e: append url while removing "." and ".." from
// the directory portion
$end = array_pop($url_path);
foreach ($url_path as $segment) {
if ($segment == '.') {
// skip
} else if ($segment == '..' && $path && $path[sizeof($path) - 1] != '..') {
array_pop($path);
} else {
$path[] = $segment;
}
}
// Step 6d, 6f: remove "." and ".." from file portion
if ($end == '.') {
$path[] = '';
} else if ($end == '..' && $path && $path[sizeof($path) - 1] != '..') {
$path[sizeof($path) - 1] = '';
} else {
$path[] = $end;
}
// Step 6h
$base['path'] = join('/', $path);
}
// Step 7
return Page::unparse_url($base);
}
|
php
|
function resolve_url($base, $url) {
if (!strlen($base)) return $url;
// Step 2
if (!strlen($url)) return $base;
// Step 3
if (preg_match('!^[a-z]+:!i', $url)) return $url;
$base = parse_url($base);
if ($url{0} == "#") {
// Step 2 (fragment)
$base['fragment'] = substr($url, 1);
return Page::unparse_url($base);
}
unset($base['fragment']);
unset($base['query']);
if (substr($url, 0, 2) == "//") {
// Step 4
return Page::unparse_url(array('scheme' => $base['scheme'], 'path' => $url,));
} else if ($url{0} == "/") {
// Step 5
$base['path'] = $url;
} else {
// Step 6
$path = explode('/', $base['path']);
$url_path = explode('/', $url);
// Step 6a: drop file from base
array_pop($path);
// Step 6b, 6c, 6e: append url while removing "." and ".." from
// the directory portion
$end = array_pop($url_path);
foreach ($url_path as $segment) {
if ($segment == '.') {
// skip
} else if ($segment == '..' && $path && $path[sizeof($path) - 1] != '..') {
array_pop($path);
} else {
$path[] = $segment;
}
}
// Step 6d, 6f: remove "." and ".." from file portion
if ($end == '.') {
$path[] = '';
} else if ($end == '..' && $path && $path[sizeof($path) - 1] != '..') {
$path[sizeof($path) - 1] = '';
} else {
$path[] = $end;
}
// Step 6h
$base['path'] = join('/', $path);
}
// Step 7
return Page::unparse_url($base);
}
|
[
"function",
"resolve_url",
"(",
"$",
"base",
",",
"$",
"url",
")",
"{",
"if",
"(",
"!",
"strlen",
"(",
"$",
"base",
")",
")",
"return",
"$",
"url",
";",
"// Step 2",
"if",
"(",
"!",
"strlen",
"(",
"$",
"url",
")",
")",
"return",
"$",
"base",
";",
"// Step 3",
"if",
"(",
"preg_match",
"(",
"'!^[a-z]+:!i'",
",",
"$",
"url",
")",
")",
"return",
"$",
"url",
";",
"$",
"base",
"=",
"parse_url",
"(",
"$",
"base",
")",
";",
"if",
"(",
"$",
"url",
"{",
"0",
"}",
"==",
"\"#\"",
")",
"{",
"// Step 2 (fragment)",
"$",
"base",
"[",
"'fragment'",
"]",
"=",
"substr",
"(",
"$",
"url",
",",
"1",
")",
";",
"return",
"Page",
"::",
"unparse_url",
"(",
"$",
"base",
")",
";",
"}",
"unset",
"(",
"$",
"base",
"[",
"'fragment'",
"]",
")",
";",
"unset",
"(",
"$",
"base",
"[",
"'query'",
"]",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"url",
",",
"0",
",",
"2",
")",
"==",
"\"//\"",
")",
"{",
"// Step 4",
"return",
"Page",
"::",
"unparse_url",
"(",
"array",
"(",
"'scheme'",
"=>",
"$",
"base",
"[",
"'scheme'",
"]",
",",
"'path'",
"=>",
"$",
"url",
",",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"url",
"{",
"0",
"}",
"==",
"\"/\"",
")",
"{",
"// Step 5",
"$",
"base",
"[",
"'path'",
"]",
"=",
"$",
"url",
";",
"}",
"else",
"{",
"// Step 6",
"$",
"path",
"=",
"explode",
"(",
"'/'",
",",
"$",
"base",
"[",
"'path'",
"]",
")",
";",
"$",
"url_path",
"=",
"explode",
"(",
"'/'",
",",
"$",
"url",
")",
";",
"// Step 6a: drop file from base",
"array_pop",
"(",
"$",
"path",
")",
";",
"// Step 6b, 6c, 6e: append url while removing \".\" and \"..\" from",
"// the directory portion",
"$",
"end",
"=",
"array_pop",
"(",
"$",
"url_path",
")",
";",
"foreach",
"(",
"$",
"url_path",
"as",
"$",
"segment",
")",
"{",
"if",
"(",
"$",
"segment",
"==",
"'.'",
")",
"{",
"// skip",
"}",
"else",
"if",
"(",
"$",
"segment",
"==",
"'..'",
"&&",
"$",
"path",
"&&",
"$",
"path",
"[",
"sizeof",
"(",
"$",
"path",
")",
"-",
"1",
"]",
"!=",
"'..'",
")",
"{",
"array_pop",
"(",
"$",
"path",
")",
";",
"}",
"else",
"{",
"$",
"path",
"[",
"]",
"=",
"$",
"segment",
";",
"}",
"}",
"// Step 6d, 6f: remove \".\" and \"..\" from file portion",
"if",
"(",
"$",
"end",
"==",
"'.'",
")",
"{",
"$",
"path",
"[",
"]",
"=",
"''",
";",
"}",
"else",
"if",
"(",
"$",
"end",
"==",
"'..'",
"&&",
"$",
"path",
"&&",
"$",
"path",
"[",
"sizeof",
"(",
"$",
"path",
")",
"-",
"1",
"]",
"!=",
"'..'",
")",
"{",
"$",
"path",
"[",
"sizeof",
"(",
"$",
"path",
")",
"-",
"1",
"]",
"=",
"''",
";",
"}",
"else",
"{",
"$",
"path",
"[",
"]",
"=",
"$",
"end",
";",
"}",
"// Step 6h",
"$",
"base",
"[",
"'path'",
"]",
"=",
"join",
"(",
"'/'",
",",
"$",
"path",
")",
";",
"}",
"// Step 7",
"return",
"Page",
"::",
"unparse_url",
"(",
"$",
"base",
")",
";",
"}"
] |
Resolve a URL relative to a base path. This happens to work with POSIX
filenames as well. This is based on RFC 2396 section 5.2.
|
[
"Resolve",
"a",
"URL",
"relative",
"to",
"a",
"base",
"path",
".",
"This",
"happens",
"to",
"work",
"with",
"POSIX",
"filenames",
"as",
"well",
".",
"This",
"is",
"based",
"on",
"RFC",
"2396",
"section",
"5",
".",
"2",
"."
] |
66a906298080c2c66d8f0fb85211b6100b3776bf
|
https://github.com/scholtz/AsyncWeb/blob/66a906298080c2c66d8f0fb85211b6100b3776bf/src/AsyncWeb/Connectors/Page.php#L144-L196
|
237,571
|
idandtrust/goodid-phpasn1
|
lib/ASN1/Object.php
|
Object.getIdentifier
|
public function getIdentifier()
{
$firstOctet = $this->getType();
if (Identifier::isLongForm($firstOctet)) {
throw new LogicException(sprintf('Identifier of %s uses the long form and must therefor override "Object::getIdentifier()".', get_class($this)));
}
return chr($firstOctet);
}
|
php
|
public function getIdentifier()
{
$firstOctet = $this->getType();
if (Identifier::isLongForm($firstOctet)) {
throw new LogicException(sprintf('Identifier of %s uses the long form and must therefor override "Object::getIdentifier()".', get_class($this)));
}
return chr($firstOctet);
}
|
[
"public",
"function",
"getIdentifier",
"(",
")",
"{",
"$",
"firstOctet",
"=",
"$",
"this",
"->",
"getType",
"(",
")",
";",
"if",
"(",
"Identifier",
"::",
"isLongForm",
"(",
"$",
"firstOctet",
")",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"sprintf",
"(",
"'Identifier of %s uses the long form and must therefor override \"Object::getIdentifier()\".'",
",",
"get_class",
"(",
"$",
"this",
")",
")",
")",
";",
"}",
"return",
"chr",
"(",
"$",
"firstOctet",
")",
";",
"}"
] |
Returns all identifier octets. If an inheriting class models a tag with
the long form identifier format, it MUST reimplement this method to
return all octets of the identifier.
@throws LogicException If the identifier format is long form
@return string Identifier as a set of octets
|
[
"Returns",
"all",
"identifier",
"octets",
".",
"If",
"an",
"inheriting",
"class",
"models",
"a",
"tag",
"with",
"the",
"long",
"form",
"identifier",
"format",
"it",
"MUST",
"reimplement",
"this",
"method",
"to",
"return",
"all",
"octets",
"of",
"the",
"identifier",
"."
] |
b95183bb85e51fbaf725d5e318dee1dbc3416b80
|
https://github.com/idandtrust/goodid-phpasn1/blob/b95183bb85e51fbaf725d5e318dee1dbc3416b80/lib/ASN1/Object.php#L91-L100
|
237,572
|
adammbalogh/key-value-store-memcached
|
src/Adapter/MemcachedAdapter/ValueTrait.php
|
ValueTrait.get
|
public function get($key)
{
$getResult = $this->getValue($key);
$unserialized = @unserialize($getResult);
if (Util::hasInternalExpireTime($unserialized)) {
$getResult = $unserialized['v'];
}
return $getResult;
}
|
php
|
public function get($key)
{
$getResult = $this->getValue($key);
$unserialized = @unserialize($getResult);
if (Util::hasInternalExpireTime($unserialized)) {
$getResult = $unserialized['v'];
}
return $getResult;
}
|
[
"public",
"function",
"get",
"(",
"$",
"key",
")",
"{",
"$",
"getResult",
"=",
"$",
"this",
"->",
"getValue",
"(",
"$",
"key",
")",
";",
"$",
"unserialized",
"=",
"@",
"unserialize",
"(",
"$",
"getResult",
")",
";",
"if",
"(",
"Util",
"::",
"hasInternalExpireTime",
"(",
"$",
"unserialized",
")",
")",
"{",
"$",
"getResult",
"=",
"$",
"unserialized",
"[",
"'v'",
"]",
";",
"}",
"return",
"$",
"getResult",
";",
"}"
] |
Gets the value of a key.
@param string $key
@return mixed The value of the key.
@throws KeyNotFoundException
@throws \Exception
|
[
"Gets",
"the",
"value",
"of",
"a",
"key",
"."
] |
e9919d6ef75badf0b2caf4ad45629666af21cd67
|
https://github.com/adammbalogh/key-value-store-memcached/blob/e9919d6ef75badf0b2caf4ad45629666af21cd67/src/Adapter/MemcachedAdapter/ValueTrait.php#L24-L34
|
237,573
|
flowcode/AmulenShopBundle
|
src/Flowcode/ShopBundle/Controller/StockTransferItemController.php
|
StockTransferItemController.newAction
|
public function newAction(StockTransfer $stockTransfer)
{
$stocktransferitem = new StockTransferItem();
$stocktransferitem->setStockTransfer($stockTransfer);
$form = $this->createForm(new StockTransferItemType(), $stocktransferitem);
return array(
'stocktransferitem' => $stocktransferitem,
'form' => $form->createView(),
);
}
|
php
|
public function newAction(StockTransfer $stockTransfer)
{
$stocktransferitem = new StockTransferItem();
$stocktransferitem->setStockTransfer($stockTransfer);
$form = $this->createForm(new StockTransferItemType(), $stocktransferitem);
return array(
'stocktransferitem' => $stocktransferitem,
'form' => $form->createView(),
);
}
|
[
"public",
"function",
"newAction",
"(",
"StockTransfer",
"$",
"stockTransfer",
")",
"{",
"$",
"stocktransferitem",
"=",
"new",
"StockTransferItem",
"(",
")",
";",
"$",
"stocktransferitem",
"->",
"setStockTransfer",
"(",
"$",
"stockTransfer",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"StockTransferItemType",
"(",
")",
",",
"$",
"stocktransferitem",
")",
";",
"return",
"array",
"(",
"'stocktransferitem'",
"=>",
"$",
"stocktransferitem",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
")",
";",
"}"
] |
Displays a form to create a new StockTransferItem entity.
@Route("/{id}/new", name="stock_transfersitem_new")
@Method("GET")
@Template()
|
[
"Displays",
"a",
"form",
"to",
"create",
"a",
"new",
"StockTransferItem",
"entity",
"."
] |
500aaf4364be3c42fca69ecd10a449da03993814
|
https://github.com/flowcode/AmulenShopBundle/blob/500aaf4364be3c42fca69ecd10a449da03993814/src/Flowcode/ShopBundle/Controller/StockTransferItemController.php#L30-L40
|
237,574
|
flowcode/AmulenShopBundle
|
src/Flowcode/ShopBundle/Controller/StockTransferItemController.php
|
StockTransferItemController.createAction
|
public function createAction(Request $request)
{
$stocktransferitem = new StockTransferItem();
$form = $this->createForm(new StockTransferItemType(), $stocktransferitem);
if ($form->handleRequest($request)->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($stocktransferitem);
$em->flush();
return $this->redirect($this->generateUrl('stock_transfers_show', array(
'id' => $stocktransferitem->getStockTransfer()->getId(),
)));
}
return array(
'stocktransferitem' => $stocktransferitem,
'form' => $form->createView(),
);
}
|
php
|
public function createAction(Request $request)
{
$stocktransferitem = new StockTransferItem();
$form = $this->createForm(new StockTransferItemType(), $stocktransferitem);
if ($form->handleRequest($request)->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($stocktransferitem);
$em->flush();
return $this->redirect($this->generateUrl('stock_transfers_show', array(
'id' => $stocktransferitem->getStockTransfer()->getId(),
)));
}
return array(
'stocktransferitem' => $stocktransferitem,
'form' => $form->createView(),
);
}
|
[
"public",
"function",
"createAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"stocktransferitem",
"=",
"new",
"StockTransferItem",
"(",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"StockTransferItemType",
"(",
")",
",",
"$",
"stocktransferitem",
")",
";",
"if",
"(",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"request",
")",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"stocktransferitem",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'stock_transfers_show'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"stocktransferitem",
"->",
"getStockTransfer",
"(",
")",
"->",
"getId",
"(",
")",
",",
")",
")",
")",
";",
"}",
"return",
"array",
"(",
"'stocktransferitem'",
"=>",
"$",
"stocktransferitem",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
")",
";",
"}"
] |
Creates a new StockTransferItem entity.
@Route("/create", name="stock_transfersitem_create")
@Method("POST")
@Template("FlowerStockBundle:StockTransferItem:new.html.twig")
|
[
"Creates",
"a",
"new",
"StockTransferItem",
"entity",
"."
] |
500aaf4364be3c42fca69ecd10a449da03993814
|
https://github.com/flowcode/AmulenShopBundle/blob/500aaf4364be3c42fca69ecd10a449da03993814/src/Flowcode/ShopBundle/Controller/StockTransferItemController.php#L49-L67
|
237,575
|
flowcode/AmulenShopBundle
|
src/Flowcode/ShopBundle/Controller/StockTransferItemController.php
|
StockTransferItemController.editAction
|
public function editAction(StockTransferItem $stocktransferitem)
{
$editForm = $this->createForm(new StockTransferItemType(), $stocktransferitem, array(
'action' => $this->generateUrl('stock_transfersitem_update', array('id' => $stocktransferitem->getid())),
'method' => 'PUT',
));
$deleteForm = $this->createDeleteForm($stocktransferitem->getId(), 'stock_transfersitem_delete');
return array(
'stocktransferitem' => $stocktransferitem,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
|
php
|
public function editAction(StockTransferItem $stocktransferitem)
{
$editForm = $this->createForm(new StockTransferItemType(), $stocktransferitem, array(
'action' => $this->generateUrl('stock_transfersitem_update', array('id' => $stocktransferitem->getid())),
'method' => 'PUT',
));
$deleteForm = $this->createDeleteForm($stocktransferitem->getId(), 'stock_transfersitem_delete');
return array(
'stocktransferitem' => $stocktransferitem,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
|
[
"public",
"function",
"editAction",
"(",
"StockTransferItem",
"$",
"stocktransferitem",
")",
"{",
"$",
"editForm",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"StockTransferItemType",
"(",
")",
",",
"$",
"stocktransferitem",
",",
"array",
"(",
"'action'",
"=>",
"$",
"this",
"->",
"generateUrl",
"(",
"'stock_transfersitem_update'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"stocktransferitem",
"->",
"getid",
"(",
")",
")",
")",
",",
"'method'",
"=>",
"'PUT'",
",",
")",
")",
";",
"$",
"deleteForm",
"=",
"$",
"this",
"->",
"createDeleteForm",
"(",
"$",
"stocktransferitem",
"->",
"getId",
"(",
")",
",",
"'stock_transfersitem_delete'",
")",
";",
"return",
"array",
"(",
"'stocktransferitem'",
"=>",
"$",
"stocktransferitem",
",",
"'edit_form'",
"=>",
"$",
"editForm",
"->",
"createView",
"(",
")",
",",
"'delete_form'",
"=>",
"$",
"deleteForm",
"->",
"createView",
"(",
")",
",",
")",
";",
"}"
] |
Displays a form to edit an existing StockTransferItem entity.
@Route("/{id}/edit", name="stock_transfersitem_edit", requirements={"id"="\d+"})
@Method("GET")
@Template()
|
[
"Displays",
"a",
"form",
"to",
"edit",
"an",
"existing",
"StockTransferItem",
"entity",
"."
] |
500aaf4364be3c42fca69ecd10a449da03993814
|
https://github.com/flowcode/AmulenShopBundle/blob/500aaf4364be3c42fca69ecd10a449da03993814/src/Flowcode/ShopBundle/Controller/StockTransferItemController.php#L76-L89
|
237,576
|
flowcode/AmulenShopBundle
|
src/Flowcode/ShopBundle/Controller/StockTransferItemController.php
|
StockTransferItemController.updateAction
|
public function updateAction(StockTransferItem $stocktransferitem, Request $request)
{
$editForm = $this->createForm(new StockTransferItemType(), $stocktransferitem, array(
'action' => $this->generateUrl('stock_transfersitem_update', array('id' => $stocktransferitem->getid())),
'method' => 'PUT',
));
if ($editForm->handleRequest($request)->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirect($this->generateUrl('stock_transfersitem_show', array('id' => $stocktransferitem->getId())));
}
$deleteForm = $this->createDeleteForm($stocktransferitem->getId(), 'stock_transfersitem_delete');
return array(
'stocktransferitem' => $stocktransferitem,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
|
php
|
public function updateAction(StockTransferItem $stocktransferitem, Request $request)
{
$editForm = $this->createForm(new StockTransferItemType(), $stocktransferitem, array(
'action' => $this->generateUrl('stock_transfersitem_update', array('id' => $stocktransferitem->getid())),
'method' => 'PUT',
));
if ($editForm->handleRequest($request)->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirect($this->generateUrl('stock_transfersitem_show', array('id' => $stocktransferitem->getId())));
}
$deleteForm = $this->createDeleteForm($stocktransferitem->getId(), 'stock_transfersitem_delete');
return array(
'stocktransferitem' => $stocktransferitem,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
|
[
"public",
"function",
"updateAction",
"(",
"StockTransferItem",
"$",
"stocktransferitem",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"editForm",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"StockTransferItemType",
"(",
")",
",",
"$",
"stocktransferitem",
",",
"array",
"(",
"'action'",
"=>",
"$",
"this",
"->",
"generateUrl",
"(",
"'stock_transfersitem_update'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"stocktransferitem",
"->",
"getid",
"(",
")",
")",
")",
",",
"'method'",
"=>",
"'PUT'",
",",
")",
")",
";",
"if",
"(",
"$",
"editForm",
"->",
"handleRequest",
"(",
"$",
"request",
")",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'stock_transfersitem_show'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"stocktransferitem",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}",
"$",
"deleteForm",
"=",
"$",
"this",
"->",
"createDeleteForm",
"(",
"$",
"stocktransferitem",
"->",
"getId",
"(",
")",
",",
"'stock_transfersitem_delete'",
")",
";",
"return",
"array",
"(",
"'stocktransferitem'",
"=>",
"$",
"stocktransferitem",
",",
"'edit_form'",
"=>",
"$",
"editForm",
"->",
"createView",
"(",
")",
",",
"'delete_form'",
"=>",
"$",
"deleteForm",
"->",
"createView",
"(",
")",
",",
")",
";",
"}"
] |
Edits an existing StockTransferItem entity.
@Route("/{id}/update", name="stock_transfersitem_update", requirements={"id"="\d+"})
@Method("PUT")
@Template("FlowerStockBundle:StockTransferItem:edit.html.twig")
|
[
"Edits",
"an",
"existing",
"StockTransferItem",
"entity",
"."
] |
500aaf4364be3c42fca69ecd10a449da03993814
|
https://github.com/flowcode/AmulenShopBundle/blob/500aaf4364be3c42fca69ecd10a449da03993814/src/Flowcode/ShopBundle/Controller/StockTransferItemController.php#L98-L116
|
237,577
|
mszewcz/php-light-framework
|
src/Config/Reader/Ini.php
|
Ini.processNode
|
private function processNode(array $node): array
{
$config = [];
foreach ($node as $name => $value) {
if (\preg_match('/^num__([0-9]+)$/', $name, $matches)) {
$name = $matches[1];
}
if (\count($nameEx = \explode('.', $name)) > 1) {
$name = \array_shift($nameEx);
$mergeBase = isset($config[$name]) ? $config[$name] : [];
$mergeWith = $this->processNode([\implode('.', $nameEx) => $value]);
$config[$name] = \array_merge_recursive($mergeBase, $mergeWith);
} elseif (\is_array($value)) {
$config[$name] = $this->processNode($value);
} else {
$config[$name] = $this->castValue((string)$value);
}
}
return $config;
}
|
php
|
private function processNode(array $node): array
{
$config = [];
foreach ($node as $name => $value) {
if (\preg_match('/^num__([0-9]+)$/', $name, $matches)) {
$name = $matches[1];
}
if (\count($nameEx = \explode('.', $name)) > 1) {
$name = \array_shift($nameEx);
$mergeBase = isset($config[$name]) ? $config[$name] : [];
$mergeWith = $this->processNode([\implode('.', $nameEx) => $value]);
$config[$name] = \array_merge_recursive($mergeBase, $mergeWith);
} elseif (\is_array($value)) {
$config[$name] = $this->processNode($value);
} else {
$config[$name] = $this->castValue((string)$value);
}
}
return $config;
}
|
[
"private",
"function",
"processNode",
"(",
"array",
"$",
"node",
")",
":",
"array",
"{",
"$",
"config",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"node",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"\\",
"preg_match",
"(",
"'/^num__([0-9]+)$/'",
",",
"$",
"name",
",",
"$",
"matches",
")",
")",
"{",
"$",
"name",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"if",
"(",
"\\",
"count",
"(",
"$",
"nameEx",
"=",
"\\",
"explode",
"(",
"'.'",
",",
"$",
"name",
")",
")",
">",
"1",
")",
"{",
"$",
"name",
"=",
"\\",
"array_shift",
"(",
"$",
"nameEx",
")",
";",
"$",
"mergeBase",
"=",
"isset",
"(",
"$",
"config",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"config",
"[",
"$",
"name",
"]",
":",
"[",
"]",
";",
"$",
"mergeWith",
"=",
"$",
"this",
"->",
"processNode",
"(",
"[",
"\\",
"implode",
"(",
"'.'",
",",
"$",
"nameEx",
")",
"=>",
"$",
"value",
"]",
")",
";",
"$",
"config",
"[",
"$",
"name",
"]",
"=",
"\\",
"array_merge_recursive",
"(",
"$",
"mergeBase",
",",
"$",
"mergeWith",
")",
";",
"}",
"elseif",
"(",
"\\",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"config",
"[",
"$",
"name",
"]",
"=",
"$",
"this",
"->",
"processNode",
"(",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"config",
"[",
"$",
"name",
"]",
"=",
"$",
"this",
"->",
"castValue",
"(",
"(",
"string",
")",
"$",
"value",
")",
";",
"}",
"}",
"return",
"$",
"config",
";",
"}"
] |
Processes INI config node
@param array $node
@return array
|
[
"Processes",
"INI",
"config",
"node"
] |
4d3b46781c387202c2dfbdb8760151b3ae8ef49c
|
https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Config/Reader/Ini.php#L50-L69
|
237,578
|
mszewcz/php-light-framework
|
src/Config/Reader/Ini.php
|
Ini.castValue
|
private function castValue(string $value)
{
$value = $this->normalize($value);
if (\preg_match('/^[0-9]+$/', $value)) {
$value = (int)$value;
} elseif (\preg_match('/^[0-9\.]+$/', $value)) {
$value = (float)$value;
} elseif (\preg_match('/^true|false$/', $value)) {
$value = $value === 'true' ? true : false;
}
return $value;
}
|
php
|
private function castValue(string $value)
{
$value = $this->normalize($value);
if (\preg_match('/^[0-9]+$/', $value)) {
$value = (int)$value;
} elseif (\preg_match('/^[0-9\.]+$/', $value)) {
$value = (float)$value;
} elseif (\preg_match('/^true|false$/', $value)) {
$value = $value === 'true' ? true : false;
}
return $value;
}
|
[
"private",
"function",
"castValue",
"(",
"string",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"normalize",
"(",
"$",
"value",
")",
";",
"if",
"(",
"\\",
"preg_match",
"(",
"'/^[0-9]+$/'",
",",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"(",
"int",
")",
"$",
"value",
";",
"}",
"elseif",
"(",
"\\",
"preg_match",
"(",
"'/^[0-9\\.]+$/'",
",",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"(",
"float",
")",
"$",
"value",
";",
"}",
"elseif",
"(",
"\\",
"preg_match",
"(",
"'/^true|false$/'",
",",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"===",
"'true'",
"?",
"true",
":",
"false",
";",
"}",
"return",
"$",
"value",
";",
"}"
] |
Casts value to a specified type
@param string $value
@return mixed
|
[
"Casts",
"value",
"to",
"a",
"specified",
"type"
] |
4d3b46781c387202c2dfbdb8760151b3ae8ef49c
|
https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Config/Reader/Ini.php#L77-L88
|
237,579
|
mszewcz/php-light-framework
|
src/Config/Reader/Ini.php
|
Ini.normalize
|
private function normalize(string $string): string
{
return \str_replace($this->normalizeFrom, $this->normalizeTo, $string);
}
|
php
|
private function normalize(string $string): string
{
return \str_replace($this->normalizeFrom, $this->normalizeTo, $string);
}
|
[
"private",
"function",
"normalize",
"(",
"string",
"$",
"string",
")",
":",
"string",
"{",
"return",
"\\",
"str_replace",
"(",
"$",
"this",
"->",
"normalizeFrom",
",",
"$",
"this",
"->",
"normalizeTo",
",",
"$",
"string",
")",
";",
"}"
] |
Changes some characters from their utf-8 to normal representation
@param string $string
@return string
|
[
"Changes",
"some",
"characters",
"from",
"their",
"utf",
"-",
"8",
"to",
"normal",
"representation"
] |
4d3b46781c387202c2dfbdb8760151b3ae8ef49c
|
https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Config/Reader/Ini.php#L96-L99
|
237,580
|
Briareos/mongodb-odm
|
lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php
|
HydratorFactory.hydrate
|
public function hydrate($document, $data, array $hints = array())
{
$metadata = $this->dm->getClassMetadata(get_class($document));
// Invoke preLoad lifecycle events and listeners
if ( ! empty($metadata->lifecycleCallbacks[Events::preLoad])) {
$args = array(&$data);
$metadata->invokeLifecycleCallbacks(Events::preLoad, $document, $args);
}
if ($this->evm->hasListeners(Events::preLoad)) {
$this->evm->dispatchEvent(Events::preLoad, new PreLoadEventArgs($document, $this->dm, $data));
}
// alsoLoadMethods may transform the document before hydration
if ( ! empty($metadata->alsoLoadMethods)) {
foreach ($metadata->alsoLoadMethods as $method => $fieldNames) {
foreach ($fieldNames as $fieldName) {
// Invoke the method only once for the first field we find
if (array_key_exists($fieldName, $data)) {
$document->$method($data[$fieldName]);
continue 2;
}
}
}
}
$data = $this->getHydratorFor($metadata->name)->hydrate($document, $data, $hints);
if ($document instanceof Proxy) {
$document->__isInitialized__ = true;
}
// Invoke the postLoad lifecycle callbacks and listeners
if ( ! empty($metadata->lifecycleCallbacks[Events::postLoad])) {
$metadata->invokeLifecycleCallbacks(Events::postLoad, $document);
}
if ($this->evm->hasListeners(Events::postLoad)) {
$this->evm->dispatchEvent(Events::postLoad, new LifecycleEventArgs($document, $this->dm));
}
return $data;
}
|
php
|
public function hydrate($document, $data, array $hints = array())
{
$metadata = $this->dm->getClassMetadata(get_class($document));
// Invoke preLoad lifecycle events and listeners
if ( ! empty($metadata->lifecycleCallbacks[Events::preLoad])) {
$args = array(&$data);
$metadata->invokeLifecycleCallbacks(Events::preLoad, $document, $args);
}
if ($this->evm->hasListeners(Events::preLoad)) {
$this->evm->dispatchEvent(Events::preLoad, new PreLoadEventArgs($document, $this->dm, $data));
}
// alsoLoadMethods may transform the document before hydration
if ( ! empty($metadata->alsoLoadMethods)) {
foreach ($metadata->alsoLoadMethods as $method => $fieldNames) {
foreach ($fieldNames as $fieldName) {
// Invoke the method only once for the first field we find
if (array_key_exists($fieldName, $data)) {
$document->$method($data[$fieldName]);
continue 2;
}
}
}
}
$data = $this->getHydratorFor($metadata->name)->hydrate($document, $data, $hints);
if ($document instanceof Proxy) {
$document->__isInitialized__ = true;
}
// Invoke the postLoad lifecycle callbacks and listeners
if ( ! empty($metadata->lifecycleCallbacks[Events::postLoad])) {
$metadata->invokeLifecycleCallbacks(Events::postLoad, $document);
}
if ($this->evm->hasListeners(Events::postLoad)) {
$this->evm->dispatchEvent(Events::postLoad, new LifecycleEventArgs($document, $this->dm));
}
return $data;
}
|
[
"public",
"function",
"hydrate",
"(",
"$",
"document",
",",
"$",
"data",
",",
"array",
"$",
"hints",
"=",
"array",
"(",
")",
")",
"{",
"$",
"metadata",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"get_class",
"(",
"$",
"document",
")",
")",
";",
"// Invoke preLoad lifecycle events and listeners",
"if",
"(",
"!",
"empty",
"(",
"$",
"metadata",
"->",
"lifecycleCallbacks",
"[",
"Events",
"::",
"preLoad",
"]",
")",
")",
"{",
"$",
"args",
"=",
"array",
"(",
"&",
"$",
"data",
")",
";",
"$",
"metadata",
"->",
"invokeLifecycleCallbacks",
"(",
"Events",
"::",
"preLoad",
",",
"$",
"document",
",",
"$",
"args",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"evm",
"->",
"hasListeners",
"(",
"Events",
"::",
"preLoad",
")",
")",
"{",
"$",
"this",
"->",
"evm",
"->",
"dispatchEvent",
"(",
"Events",
"::",
"preLoad",
",",
"new",
"PreLoadEventArgs",
"(",
"$",
"document",
",",
"$",
"this",
"->",
"dm",
",",
"$",
"data",
")",
")",
";",
"}",
"// alsoLoadMethods may transform the document before hydration",
"if",
"(",
"!",
"empty",
"(",
"$",
"metadata",
"->",
"alsoLoadMethods",
")",
")",
"{",
"foreach",
"(",
"$",
"metadata",
"->",
"alsoLoadMethods",
"as",
"$",
"method",
"=>",
"$",
"fieldNames",
")",
"{",
"foreach",
"(",
"$",
"fieldNames",
"as",
"$",
"fieldName",
")",
"{",
"// Invoke the method only once for the first field we find",
"if",
"(",
"array_key_exists",
"(",
"$",
"fieldName",
",",
"$",
"data",
")",
")",
"{",
"$",
"document",
"->",
"$",
"method",
"(",
"$",
"data",
"[",
"$",
"fieldName",
"]",
")",
";",
"continue",
"2",
";",
"}",
"}",
"}",
"}",
"$",
"data",
"=",
"$",
"this",
"->",
"getHydratorFor",
"(",
"$",
"metadata",
"->",
"name",
")",
"->",
"hydrate",
"(",
"$",
"document",
",",
"$",
"data",
",",
"$",
"hints",
")",
";",
"if",
"(",
"$",
"document",
"instanceof",
"Proxy",
")",
"{",
"$",
"document",
"->",
"__isInitialized__",
"=",
"true",
";",
"}",
"// Invoke the postLoad lifecycle callbacks and listeners",
"if",
"(",
"!",
"empty",
"(",
"$",
"metadata",
"->",
"lifecycleCallbacks",
"[",
"Events",
"::",
"postLoad",
"]",
")",
")",
"{",
"$",
"metadata",
"->",
"invokeLifecycleCallbacks",
"(",
"Events",
"::",
"postLoad",
",",
"$",
"document",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"evm",
"->",
"hasListeners",
"(",
"Events",
"::",
"postLoad",
")",
")",
"{",
"$",
"this",
"->",
"evm",
"->",
"dispatchEvent",
"(",
"Events",
"::",
"postLoad",
",",
"new",
"LifecycleEventArgs",
"(",
"$",
"document",
",",
"$",
"this",
"->",
"dm",
")",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] |
Hydrate array of MongoDB document data into the given document object.
@param object $document The document object to hydrate the data into.
@param array $data The array of document data.
@param array $hints Any hints to account for during reconstitution/lookup of the document.
@return array $values The array of hydrated values.
|
[
"Hydrate",
"array",
"of",
"MongoDB",
"document",
"data",
"into",
"the",
"given",
"document",
"object",
"."
] |
29e28bed9a265efd7d05473b0a909fb7c83f76e0
|
https://github.com/Briareos/mongodb-odm/blob/29e28bed9a265efd7d05473b0a909fb7c83f76e0/lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php#L403-L442
|
237,581
|
lasallecrm/lasallecrm-l5-listmanagement-pkg
|
src/Helpers/Helpers.php
|
Helpers.isEmailAddressPrimaryType
|
public function isEmailAddressPrimaryType($emailID) {
// Must we accept "primary" email type only?
if (!Config::get('lasallecrmlistmanagement.listmgmt_emails_in_list_primary_type_only')) {
return false;
}
// "primary" type is #1
if ($this->getEmailType($emailID) != 1) {
return false;
}
return true;
}
|
php
|
public function isEmailAddressPrimaryType($emailID) {
// Must we accept "primary" email type only?
if (!Config::get('lasallecrmlistmanagement.listmgmt_emails_in_list_primary_type_only')) {
return false;
}
// "primary" type is #1
if ($this->getEmailType($emailID) != 1) {
return false;
}
return true;
}
|
[
"public",
"function",
"isEmailAddressPrimaryType",
"(",
"$",
"emailID",
")",
"{",
"// Must we accept \"primary\" email type only?",
"if",
"(",
"!",
"Config",
"::",
"get",
"(",
"'lasallecrmlistmanagement.listmgmt_emails_in_list_primary_type_only'",
")",
")",
"{",
"return",
"false",
";",
"}",
"// \"primary\" type is #1",
"if",
"(",
"$",
"this",
"->",
"getEmailType",
"(",
"$",
"emailID",
")",
"!=",
"1",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Is the email type "primary" AND must we accept "primary" type only?
Both conditions must be true to return true
@param int $emailID Emails db table's ID
@return bool
|
[
"Is",
"the",
"email",
"type",
"primary",
"AND",
"must",
"we",
"accept",
"primary",
"type",
"only?"
] |
4b5da1af5d25d5fb4be5199f3cf22da313d475f3
|
https://github.com/lasallecrm/lasallecrm-l5-listmanagement-pkg/blob/4b5da1af5d25d5fb4be5199f3cf22da313d475f3/src/Helpers/Helpers.php#L103-L116
|
237,582
|
faustbrian/binary
|
src/UnsignedInteger/Reader.php
|
Reader.bit16
|
public static function bit16(string $data, int $offset = 0, $endianness = false): int
{
// big-endian
if (true === $endianness) {
return unpack('n', $data, $offset)[1];
}
// little-endian
if (false === $endianness) {
return unpack('v', $data, $offset)[1];
}
// machine byte order
if (null === $endianness) {
return unpack('S', $data, $offset)[1];
}
}
|
php
|
public static function bit16(string $data, int $offset = 0, $endianness = false): int
{
// big-endian
if (true === $endianness) {
return unpack('n', $data, $offset)[1];
}
// little-endian
if (false === $endianness) {
return unpack('v', $data, $offset)[1];
}
// machine byte order
if (null === $endianness) {
return unpack('S', $data, $offset)[1];
}
}
|
[
"public",
"static",
"function",
"bit16",
"(",
"string",
"$",
"data",
",",
"int",
"$",
"offset",
"=",
"0",
",",
"$",
"endianness",
"=",
"false",
")",
":",
"int",
"{",
"// big-endian",
"if",
"(",
"true",
"===",
"$",
"endianness",
")",
"{",
"return",
"unpack",
"(",
"'n'",
",",
"$",
"data",
",",
"$",
"offset",
")",
"[",
"1",
"]",
";",
"}",
"// little-endian",
"if",
"(",
"false",
"===",
"$",
"endianness",
")",
"{",
"return",
"unpack",
"(",
"'v'",
",",
"$",
"data",
",",
"$",
"offset",
")",
"[",
"1",
"]",
";",
"}",
"// machine byte order",
"if",
"(",
"null",
"===",
"$",
"endianness",
")",
"{",
"return",
"unpack",
"(",
"'S'",
",",
"$",
"data",
",",
"$",
"offset",
")",
"[",
"1",
"]",
";",
"}",
"}"
] |
Read an unsigned 16 bit integer.
@param string $data
@param int $offset
@param mixed $endianness
@return int
|
[
"Read",
"an",
"unsigned",
"16",
"bit",
"integer",
"."
] |
7d845497460c2dabf7e369ec8e55baf989ef74cb
|
https://github.com/faustbrian/binary/blob/7d845497460c2dabf7e369ec8e55baf989ef74cb/src/UnsignedInteger/Reader.php#L45-L61
|
237,583
|
faustbrian/binary
|
src/UnsignedInteger/Reader.php
|
Reader.bit64
|
public static function bit64(string $data, int $offset = 0, bool $endianness = false): int
{
// big-endian
if (true === $endianness) {
return unpack('J', $data, $offset)[1];
}
// little-endian
if (false === $endianness) {
return unpack('P', $data, $offset)[1];
}
// machine byte order
if (null === $endianness) {
return unpack('Q', $data, $offset)[1];
}
}
|
php
|
public static function bit64(string $data, int $offset = 0, bool $endianness = false): int
{
// big-endian
if (true === $endianness) {
return unpack('J', $data, $offset)[1];
}
// little-endian
if (false === $endianness) {
return unpack('P', $data, $offset)[1];
}
// machine byte order
if (null === $endianness) {
return unpack('Q', $data, $offset)[1];
}
}
|
[
"public",
"static",
"function",
"bit64",
"(",
"string",
"$",
"data",
",",
"int",
"$",
"offset",
"=",
"0",
",",
"bool",
"$",
"endianness",
"=",
"false",
")",
":",
"int",
"{",
"// big-endian",
"if",
"(",
"true",
"===",
"$",
"endianness",
")",
"{",
"return",
"unpack",
"(",
"'J'",
",",
"$",
"data",
",",
"$",
"offset",
")",
"[",
"1",
"]",
";",
"}",
"// little-endian",
"if",
"(",
"false",
"===",
"$",
"endianness",
")",
"{",
"return",
"unpack",
"(",
"'P'",
",",
"$",
"data",
",",
"$",
"offset",
")",
"[",
"1",
"]",
";",
"}",
"// machine byte order",
"if",
"(",
"null",
"===",
"$",
"endianness",
")",
"{",
"return",
"unpack",
"(",
"'Q'",
",",
"$",
"data",
",",
"$",
"offset",
")",
"[",
"1",
"]",
";",
"}",
"}"
] |
Read an unsigned 64 bit integer.
@param string $data
@param int $offset
@param mixed $endianness
@return int
|
[
"Read",
"an",
"unsigned",
"64",
"bit",
"integer",
"."
] |
7d845497460c2dabf7e369ec8e55baf989ef74cb
|
https://github.com/faustbrian/binary/blob/7d845497460c2dabf7e369ec8e55baf989ef74cb/src/UnsignedInteger/Reader.php#L99-L115
|
237,584
|
samsonos/cms_app_materialtable
|
src/MaterialTableTable.php
|
MaterialTableTable.row
|
public function row(& $material, Pager & $pager = null, $module = NULL)
{
/** @var string $tdHTML Table cell HTML code */
$tdHTML = '';
$input = null;
/** @var \samson\cms\CMSField $field Field of current table structure (Table column) */
foreach ($this->fields as $field) {
/** @var \samson\activerecord\materialfield $materialField Materialfield object (Table cell) */
foreach ($material->onetomany['_materialfield'] as $materialField) {
// If materialfield relates to field (column)
$isRightField = $materialField->FieldID == $field->FieldID;
// If field has same locale as passed
$isRightLocale = $materialField->locale == $this->locale;
// If field not localized then output it
$isNotLocalizedField = $materialField->locale == '';
if ($isRightField && (($isRightLocale) || ($isNotLocalizedField))) {
$this->headerFields[$field->id] = $field;
if ($field->Type < 9 || $field->Type > 10) {
$input = m('samsoncms_input_application')
->createFieldByType($this->dbQuery, $field->Type, $materialField);
}
// If current field has select type then go to build his value
if ($field->Type == 4) {
/** @var \samsoncms\input\select\Select $input Select input type */
$input->build($field->Value);
}
// When render the input of table then call all subscribers
\samsonphp\event\Event::fire('samson.cms.input.table.render', array($input));
// Set HTML row code
$tdHTML .= $this->renderModule->view('table/tdView')->set($input, 'input')->output();
break;
}
}
}
// Render field row
return $this->renderModule
->view($this->row_tmpl)
->set(m('samsoncms_input_text_application')->createField($this->dbQuery, $material, 'Url'), 'materialName')
->set($material->id, 'materialID')
->set($material->priority, 'priority')
->set($material->parent_id, 'parentID')
->set($this->structure->StructureID, 'structureId')
->set($tdHTML, 'td_view')
->set($pager, 'pager')
->output();
}
|
php
|
public function row(& $material, Pager & $pager = null, $module = NULL)
{
/** @var string $tdHTML Table cell HTML code */
$tdHTML = '';
$input = null;
/** @var \samson\cms\CMSField $field Field of current table structure (Table column) */
foreach ($this->fields as $field) {
/** @var \samson\activerecord\materialfield $materialField Materialfield object (Table cell) */
foreach ($material->onetomany['_materialfield'] as $materialField) {
// If materialfield relates to field (column)
$isRightField = $materialField->FieldID == $field->FieldID;
// If field has same locale as passed
$isRightLocale = $materialField->locale == $this->locale;
// If field not localized then output it
$isNotLocalizedField = $materialField->locale == '';
if ($isRightField && (($isRightLocale) || ($isNotLocalizedField))) {
$this->headerFields[$field->id] = $field;
if ($field->Type < 9 || $field->Type > 10) {
$input = m('samsoncms_input_application')
->createFieldByType($this->dbQuery, $field->Type, $materialField);
}
// If current field has select type then go to build his value
if ($field->Type == 4) {
/** @var \samsoncms\input\select\Select $input Select input type */
$input->build($field->Value);
}
// When render the input of table then call all subscribers
\samsonphp\event\Event::fire('samson.cms.input.table.render', array($input));
// Set HTML row code
$tdHTML .= $this->renderModule->view('table/tdView')->set($input, 'input')->output();
break;
}
}
}
// Render field row
return $this->renderModule
->view($this->row_tmpl)
->set(m('samsoncms_input_text_application')->createField($this->dbQuery, $material, 'Url'), 'materialName')
->set($material->id, 'materialID')
->set($material->priority, 'priority')
->set($material->parent_id, 'parentID')
->set($this->structure->StructureID, 'structureId')
->set($tdHTML, 'td_view')
->set($pager, 'pager')
->output();
}
|
[
"public",
"function",
"row",
"(",
"&",
"$",
"material",
",",
"Pager",
"&",
"$",
"pager",
"=",
"null",
",",
"$",
"module",
"=",
"NULL",
")",
"{",
"/** @var string $tdHTML Table cell HTML code */",
"$",
"tdHTML",
"=",
"''",
";",
"$",
"input",
"=",
"null",
";",
"/** @var \\samson\\cms\\CMSField $field Field of current table structure (Table column) */",
"foreach",
"(",
"$",
"this",
"->",
"fields",
"as",
"$",
"field",
")",
"{",
"/** @var \\samson\\activerecord\\materialfield $materialField Materialfield object (Table cell) */",
"foreach",
"(",
"$",
"material",
"->",
"onetomany",
"[",
"'_materialfield'",
"]",
"as",
"$",
"materialField",
")",
"{",
"// If materialfield relates to field (column)",
"$",
"isRightField",
"=",
"$",
"materialField",
"->",
"FieldID",
"==",
"$",
"field",
"->",
"FieldID",
";",
"// If field has same locale as passed",
"$",
"isRightLocale",
"=",
"$",
"materialField",
"->",
"locale",
"==",
"$",
"this",
"->",
"locale",
";",
"// If field not localized then output it",
"$",
"isNotLocalizedField",
"=",
"$",
"materialField",
"->",
"locale",
"==",
"''",
";",
"if",
"(",
"$",
"isRightField",
"&&",
"(",
"(",
"$",
"isRightLocale",
")",
"||",
"(",
"$",
"isNotLocalizedField",
")",
")",
")",
"{",
"$",
"this",
"->",
"headerFields",
"[",
"$",
"field",
"->",
"id",
"]",
"=",
"$",
"field",
";",
"if",
"(",
"$",
"field",
"->",
"Type",
"<",
"9",
"||",
"$",
"field",
"->",
"Type",
">",
"10",
")",
"{",
"$",
"input",
"=",
"m",
"(",
"'samsoncms_input_application'",
")",
"->",
"createFieldByType",
"(",
"$",
"this",
"->",
"dbQuery",
",",
"$",
"field",
"->",
"Type",
",",
"$",
"materialField",
")",
";",
"}",
"// If current field has select type then go to build his value",
"if",
"(",
"$",
"field",
"->",
"Type",
"==",
"4",
")",
"{",
"/** @var \\samsoncms\\input\\select\\Select $input Select input type */",
"$",
"input",
"->",
"build",
"(",
"$",
"field",
"->",
"Value",
")",
";",
"}",
"// When render the input of table then call all subscribers",
"\\",
"samsonphp",
"\\",
"event",
"\\",
"Event",
"::",
"fire",
"(",
"'samson.cms.input.table.render'",
",",
"array",
"(",
"$",
"input",
")",
")",
";",
"// Set HTML row code",
"$",
"tdHTML",
".=",
"$",
"this",
"->",
"renderModule",
"->",
"view",
"(",
"'table/tdView'",
")",
"->",
"set",
"(",
"$",
"input",
",",
"'input'",
")",
"->",
"output",
"(",
")",
";",
"break",
";",
"}",
"}",
"}",
"// Render field row",
"return",
"$",
"this",
"->",
"renderModule",
"->",
"view",
"(",
"$",
"this",
"->",
"row_tmpl",
")",
"->",
"set",
"(",
"m",
"(",
"'samsoncms_input_text_application'",
")",
"->",
"createField",
"(",
"$",
"this",
"->",
"dbQuery",
",",
"$",
"material",
",",
"'Url'",
")",
",",
"'materialName'",
")",
"->",
"set",
"(",
"$",
"material",
"->",
"id",
",",
"'materialID'",
")",
"->",
"set",
"(",
"$",
"material",
"->",
"priority",
",",
"'priority'",
")",
"->",
"set",
"(",
"$",
"material",
"->",
"parent_id",
",",
"'parentID'",
")",
"->",
"set",
"(",
"$",
"this",
"->",
"structure",
"->",
"StructureID",
",",
"'structureId'",
")",
"->",
"set",
"(",
"$",
"tdHTML",
",",
"'td_view'",
")",
"->",
"set",
"(",
"$",
"pager",
",",
"'pager'",
")",
"->",
"output",
"(",
")",
";",
"}"
] |
Function to view table row
@param \samson\activerecord\material $material Tale material represented as row
@param Pager $pager Pager for multi page table
@return string
|
[
"Function",
"to",
"view",
"table",
"row"
] |
550fb1916070b6cf8cbd4fa7d61a19ca9a2d090e
|
https://github.com/samsonos/cms_app_materialtable/blob/550fb1916070b6cf8cbd4fa7d61a19ca9a2d090e/src/MaterialTableTable.php#L143-L197
|
237,585
|
jamiehannaford/php-opencloud-zf2
|
src/Factory/AbstractProviderFactory.php
|
AbstractProviderFactory.extractAuthEndpoint
|
private function extractAuthEndpoint()
{
$auth = empty($this->config['auth_endpoint']) ? self::DEFAULT_AUTH_ENDPOINT : $this->config['auth_endpoint'];
switch ($auth) {
case Endpoint::UK:
$endpoint = Rackspace::UK_IDENTITY_ENDPOINT;
break;
case Endpoint::US:
$endpoint = Rackspace::US_IDENTITY_ENDPOINT;
break;
default:
$endpoint = $auth;
break;
}
return Url::factory($endpoint);
}
|
php
|
private function extractAuthEndpoint()
{
$auth = empty($this->config['auth_endpoint']) ? self::DEFAULT_AUTH_ENDPOINT : $this->config['auth_endpoint'];
switch ($auth) {
case Endpoint::UK:
$endpoint = Rackspace::UK_IDENTITY_ENDPOINT;
break;
case Endpoint::US:
$endpoint = Rackspace::US_IDENTITY_ENDPOINT;
break;
default:
$endpoint = $auth;
break;
}
return Url::factory($endpoint);
}
|
[
"private",
"function",
"extractAuthEndpoint",
"(",
")",
"{",
"$",
"auth",
"=",
"empty",
"(",
"$",
"this",
"->",
"config",
"[",
"'auth_endpoint'",
"]",
")",
"?",
"self",
"::",
"DEFAULT_AUTH_ENDPOINT",
":",
"$",
"this",
"->",
"config",
"[",
"'auth_endpoint'",
"]",
";",
"switch",
"(",
"$",
"auth",
")",
"{",
"case",
"Endpoint",
"::",
"UK",
":",
"$",
"endpoint",
"=",
"Rackspace",
"::",
"UK_IDENTITY_ENDPOINT",
";",
"break",
";",
"case",
"Endpoint",
"::",
"US",
":",
"$",
"endpoint",
"=",
"Rackspace",
"::",
"US_IDENTITY_ENDPOINT",
";",
"break",
";",
"default",
":",
"$",
"endpoint",
"=",
"$",
"auth",
";",
"break",
";",
"}",
"return",
"Url",
"::",
"factory",
"(",
"$",
"endpoint",
")",
";",
"}"
] |
Searchs the configuration values provided and attempts to build a suitable URL for authentication.
@return \Guzzle\Http\Url
|
[
"Searchs",
"the",
"configuration",
"values",
"provided",
"and",
"attempts",
"to",
"build",
"a",
"suitable",
"URL",
"for",
"authentication",
"."
] |
74140adaffc0b46d7bbe1d7b3441c61f2cf6a656
|
https://github.com/jamiehannaford/php-opencloud-zf2/blob/74140adaffc0b46d7bbe1d7b3441c61f2cf6a656/src/Factory/AbstractProviderFactory.php#L83-L100
|
237,586
|
emaphp/eMapper
|
lib/eMapper/Cache/Key/CacheKeyFormatter.php
|
CacheKeyFormatter.getDefaultTypeHandler
|
protected function getDefaultTypeHandler($value) {
//get value type
$type = gettype($value);
switch ($type) {
case 'null':
return null;
case 'array':
//check empty array
if (count($value) == 0)
return null;
elseif (count($value) == 1) //get first value type hanlder
return $this->getDefaultTypeHandler(current($value));
$typeHandler = null;
//obtain type by checking inner values
foreach ($value as $val) {
$typeHandler = $this->getDefaultTypeHandler($val);
//get type of the first not null value
if (!is_null($typeHandler))
break;
}
return $typeHandler;
case 'object':
//get object class
$classname = get_class($value);
//use class as type
$typeHandler = $this->typeManager->getTypeHandler($classname);
if ($typeHandler !== false)
return $typeHandler;
//no typehandler found, throw exception
throw new \RuntimeException("No default type handler found for class '$classname'");
case 'resource':
//unsupported, throw exception
throw new \RuntimeException("Argument of type 'resource' is not supported");
default:
//generic type
return $this->typeManager->getTypeHandler($type);
}
}
|
php
|
protected function getDefaultTypeHandler($value) {
//get value type
$type = gettype($value);
switch ($type) {
case 'null':
return null;
case 'array':
//check empty array
if (count($value) == 0)
return null;
elseif (count($value) == 1) //get first value type hanlder
return $this->getDefaultTypeHandler(current($value));
$typeHandler = null;
//obtain type by checking inner values
foreach ($value as $val) {
$typeHandler = $this->getDefaultTypeHandler($val);
//get type of the first not null value
if (!is_null($typeHandler))
break;
}
return $typeHandler;
case 'object':
//get object class
$classname = get_class($value);
//use class as type
$typeHandler = $this->typeManager->getTypeHandler($classname);
if ($typeHandler !== false)
return $typeHandler;
//no typehandler found, throw exception
throw new \RuntimeException("No default type handler found for class '$classname'");
case 'resource':
//unsupported, throw exception
throw new \RuntimeException("Argument of type 'resource' is not supported");
default:
//generic type
return $this->typeManager->getTypeHandler($type);
}
}
|
[
"protected",
"function",
"getDefaultTypeHandler",
"(",
"$",
"value",
")",
"{",
"//get value type",
"$",
"type",
"=",
"gettype",
"(",
"$",
"value",
")",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'null'",
":",
"return",
"null",
";",
"case",
"'array'",
":",
"//check empty array",
"if",
"(",
"count",
"(",
"$",
"value",
")",
"==",
"0",
")",
"return",
"null",
";",
"elseif",
"(",
"count",
"(",
"$",
"value",
")",
"==",
"1",
")",
"//get first value type hanlder",
"return",
"$",
"this",
"->",
"getDefaultTypeHandler",
"(",
"current",
"(",
"$",
"value",
")",
")",
";",
"$",
"typeHandler",
"=",
"null",
";",
"//obtain type by checking inner values",
"foreach",
"(",
"$",
"value",
"as",
"$",
"val",
")",
"{",
"$",
"typeHandler",
"=",
"$",
"this",
"->",
"getDefaultTypeHandler",
"(",
"$",
"val",
")",
";",
"//get type of the first not null value",
"if",
"(",
"!",
"is_null",
"(",
"$",
"typeHandler",
")",
")",
"break",
";",
"}",
"return",
"$",
"typeHandler",
";",
"case",
"'object'",
":",
"//get object class",
"$",
"classname",
"=",
"get_class",
"(",
"$",
"value",
")",
";",
"//use class as type",
"$",
"typeHandler",
"=",
"$",
"this",
"->",
"typeManager",
"->",
"getTypeHandler",
"(",
"$",
"classname",
")",
";",
"if",
"(",
"$",
"typeHandler",
"!==",
"false",
")",
"return",
"$",
"typeHandler",
";",
"//no typehandler found, throw exception",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"No default type handler found for class '$classname'\"",
")",
";",
"case",
"'resource'",
":",
"//unsupported, throw exception",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Argument of type 'resource' is not supported\"",
")",
";",
"default",
":",
"//generic type",
"return",
"$",
"this",
"->",
"typeManager",
"->",
"getTypeHandler",
"(",
"$",
"type",
")",
";",
"}",
"}"
] |
Obtains the default type handler for a given value
@param mixed $value
@throws \RuntimeException
@return NULL | TypeHandler
|
[
"Obtains",
"the",
"default",
"type",
"handler",
"for",
"a",
"given",
"value"
] |
df7100e601d2a1363d07028a786b6ceb22271829
|
https://github.com/emaphp/eMapper/blob/df7100e601d2a1363d07028a786b6ceb22271829/lib/eMapper/Cache/Key/CacheKeyFormatter.php#L66-L110
|
237,587
|
emaphp/eMapper
|
lib/eMapper/Cache/Key/CacheKeyFormatter.php
|
CacheKeyFormatter.castArray
|
protected function castArray($value, TypeHandler $typeHandler, $join_string = ',') {
$list = [];
//build expression list
foreach ($value as $val) {
$val = $typeHandler->castParameter($val);
if (is_null($val))
$new_elem = 'NULL';
else {
$new_elem = $typeHandler->setParameter($val);
if (is_null($new_elem))
$new_elem = 'NULL';
elseif (!is_string($new_elem))
$new_elem = strval($new_elem);
}
$list[] = $new_elem;
}
//return joined expression
return implode($join_string, $list);
}
|
php
|
protected function castArray($value, TypeHandler $typeHandler, $join_string = ',') {
$list = [];
//build expression list
foreach ($value as $val) {
$val = $typeHandler->castParameter($val);
if (is_null($val))
$new_elem = 'NULL';
else {
$new_elem = $typeHandler->setParameter($val);
if (is_null($new_elem))
$new_elem = 'NULL';
elseif (!is_string($new_elem))
$new_elem = strval($new_elem);
}
$list[] = $new_elem;
}
//return joined expression
return implode($join_string, $list);
}
|
[
"protected",
"function",
"castArray",
"(",
"$",
"value",
",",
"TypeHandler",
"$",
"typeHandler",
",",
"$",
"join_string",
"=",
"','",
")",
"{",
"$",
"list",
"=",
"[",
"]",
";",
"//build expression list",
"foreach",
"(",
"$",
"value",
"as",
"$",
"val",
")",
"{",
"$",
"val",
"=",
"$",
"typeHandler",
"->",
"castParameter",
"(",
"$",
"val",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"val",
")",
")",
"$",
"new_elem",
"=",
"'NULL'",
";",
"else",
"{",
"$",
"new_elem",
"=",
"$",
"typeHandler",
"->",
"setParameter",
"(",
"$",
"val",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"new_elem",
")",
")",
"$",
"new_elem",
"=",
"'NULL'",
";",
"elseif",
"(",
"!",
"is_string",
"(",
"$",
"new_elem",
")",
")",
"$",
"new_elem",
"=",
"strval",
"(",
"$",
"new_elem",
")",
";",
"}",
"$",
"list",
"[",
"]",
"=",
"$",
"new_elem",
";",
"}",
"//return joined expression",
"return",
"implode",
"(",
"$",
"join_string",
",",
"$",
"list",
")",
";",
"}"
] |
Casts all elements in an array with the given type handler
@param array $value
@param TypeHandler $typeHandler
@param string $join_string
@return string
|
[
"Casts",
"all",
"elements",
"in",
"an",
"array",
"with",
"the",
"given",
"type",
"handler"
] |
df7100e601d2a1363d07028a786b6ceb22271829
|
https://github.com/emaphp/eMapper/blob/df7100e601d2a1363d07028a786b6ceb22271829/lib/eMapper/Cache/Key/CacheKeyFormatter.php#L119-L141
|
237,588
|
emaphp/eMapper
|
lib/eMapper/Cache/Key/CacheKeyFormatter.php
|
CacheKeyFormatter.castParameter
|
protected function castParameter($value, $type = null) {
//check null value
if (is_null($value))
return 'NULL';
elseif (is_null($type)) {
//obtain default type handler
$typeHandler = $this->getDefaultTypeHandler($value);
if (is_null($typeHandler))
return 'NULL';
if (is_array($value))
return $this->castArray($value, $typeHandler, '_');
}
else {
//cast value to the specified type
$typeHandler = $this->typeManager->getTypeHandler($type);
if ($typeHandler === false)
throw new \RuntimeException("No type handler found for type '$type'");
if (is_array($value))
return $this->castArray($value, $typeHandler, '_');
//check if returned value is null
$value = $typeHandler->castParameter($value);
if (is_null($value))
return 'NULL';
}
//get parameter expression
$value = $typeHandler->setParameter($value);
//check null value
if (is_null($value))
return 'NULL';
//cast to string
if (!is_string($value))
$value = strval($value);
return $value;
}
|
php
|
protected function castParameter($value, $type = null) {
//check null value
if (is_null($value))
return 'NULL';
elseif (is_null($type)) {
//obtain default type handler
$typeHandler = $this->getDefaultTypeHandler($value);
if (is_null($typeHandler))
return 'NULL';
if (is_array($value))
return $this->castArray($value, $typeHandler, '_');
}
else {
//cast value to the specified type
$typeHandler = $this->typeManager->getTypeHandler($type);
if ($typeHandler === false)
throw new \RuntimeException("No type handler found for type '$type'");
if (is_array($value))
return $this->castArray($value, $typeHandler, '_');
//check if returned value is null
$value = $typeHandler->castParameter($value);
if (is_null($value))
return 'NULL';
}
//get parameter expression
$value = $typeHandler->setParameter($value);
//check null value
if (is_null($value))
return 'NULL';
//cast to string
if (!is_string($value))
$value = strval($value);
return $value;
}
|
[
"protected",
"function",
"castParameter",
"(",
"$",
"value",
",",
"$",
"type",
"=",
"null",
")",
"{",
"//check null value",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"return",
"'NULL'",
";",
"elseif",
"(",
"is_null",
"(",
"$",
"type",
")",
")",
"{",
"//obtain default type handler",
"$",
"typeHandler",
"=",
"$",
"this",
"->",
"getDefaultTypeHandler",
"(",
"$",
"value",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"typeHandler",
")",
")",
"return",
"'NULL'",
";",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"return",
"$",
"this",
"->",
"castArray",
"(",
"$",
"value",
",",
"$",
"typeHandler",
",",
"'_'",
")",
";",
"}",
"else",
"{",
"//cast value to the specified type",
"$",
"typeHandler",
"=",
"$",
"this",
"->",
"typeManager",
"->",
"getTypeHandler",
"(",
"$",
"type",
")",
";",
"if",
"(",
"$",
"typeHandler",
"===",
"false",
")",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"No type handler found for type '$type'\"",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"return",
"$",
"this",
"->",
"castArray",
"(",
"$",
"value",
",",
"$",
"typeHandler",
",",
"'_'",
")",
";",
"//check if returned value is null",
"$",
"value",
"=",
"$",
"typeHandler",
"->",
"castParameter",
"(",
"$",
"value",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"return",
"'NULL'",
";",
"}",
"//get parameter expression",
"$",
"value",
"=",
"$",
"typeHandler",
"->",
"setParameter",
"(",
"$",
"value",
")",
";",
"//check null value",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"return",
"'NULL'",
";",
"//cast to string",
"if",
"(",
"!",
"is_string",
"(",
"$",
"value",
")",
")",
"$",
"value",
"=",
"strval",
"(",
"$",
"value",
")",
";",
"return",
"$",
"value",
";",
"}"
] |
Casts a value to a given type
@param mixed $value
@param string $type
@return string
@throws \RuntimeException
|
[
"Casts",
"a",
"value",
"to",
"a",
"given",
"type"
] |
df7100e601d2a1363d07028a786b6ceb22271829
|
https://github.com/emaphp/eMapper/blob/df7100e601d2a1363d07028a786b6ceb22271829/lib/eMapper/Cache/Key/CacheKeyFormatter.php#L150-L188
|
237,589
|
emaphp/eMapper
|
lib/eMapper/Cache/Key/CacheKeyFormatter.php
|
CacheKeyFormatter.replaceConfigExpression
|
protected function replaceConfigExpression($matches) {
$property = $matches[1];
//check key existence
if (!array_key_exists($property, $this->config))
return '';
//convert to string, if possible
if (($str = $this->toString($this->config[$property])) === false)
return '';
return $str;
}
|
php
|
protected function replaceConfigExpression($matches) {
$property = $matches[1];
//check key existence
if (!array_key_exists($property, $this->config))
return '';
//convert to string, if possible
if (($str = $this->toString($this->config[$property])) === false)
return '';
return $str;
}
|
[
"protected",
"function",
"replaceConfigExpression",
"(",
"$",
"matches",
")",
"{",
"$",
"property",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"//check key existence",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"property",
",",
"$",
"this",
"->",
"config",
")",
")",
"return",
"''",
";",
"//convert to string, if possible",
"if",
"(",
"(",
"$",
"str",
"=",
"$",
"this",
"->",
"toString",
"(",
"$",
"this",
"->",
"config",
"[",
"$",
"property",
"]",
")",
")",
"===",
"false",
")",
"return",
"''",
";",
"return",
"$",
"str",
";",
"}"
] |
Returns a string that replaces a configuration expression within a string
@param array $matches
@return string
|
[
"Returns",
"a",
"string",
"that",
"replaces",
"a",
"configuration",
"expression",
"within",
"a",
"string"
] |
df7100e601d2a1363d07028a786b6ceb22271829
|
https://github.com/emaphp/eMapper/blob/df7100e601d2a1363d07028a786b6ceb22271829/lib/eMapper/Cache/Key/CacheKeyFormatter.php#L360-L369
|
237,590
|
emaphp/eMapper
|
lib/eMapper/Cache/Key/CacheKeyFormatter.php
|
CacheKeyFormatter.replacePropertyExpression
|
protected function replacePropertyExpression($matches) {
//count available matches
//this indicates the type of expression to replace
$total_matches = count($matches);
$type = $subindex = null;
switch ($total_matches) {
/*
* Property
*/
case 4: //#{PROPERTY@1[INDEX]@2?:TYPE@3}
$type = substr($matches[3], 1);
case 3: //#{PROPERTY@1[INDEX]@2}
$subindex = empty($matches[2]) ? null : substr($matches[2], 1, -1);
case 2: //#{PROPERTY@1}
$key = $matches[1];
//obtain type from annotation (when possible)
if (is_null($type) && $this->wrappedArg instanceof ObjectArgumentWrapper) {
if ($this->wrappedArg->getClassProfile()->isEntity()) {
$property = $this->wrappedArg->getClassProfile()->getProperty($key);
$type = $property->getType();
}
}
return $this->getIndex($key, $subindex, $type);
break;
/*
* Interval
*/
case 9: //#{PROPERTY@4[LEFT_INDEX@6..RIGHT_INDEX@7]:TYPE@8}
$type = substr($matches[8], 1);
case 8: //#{PROPERTY@4[LEFT_INDEX@6..RIGHT_INDEX@7]}
$key = $matches[4];
//obtain type from annotation (when possible)
if (is_null($type) && $this->wrappedArg instanceof ObjectArgumentWrapper) {
if ($this->wrappedArg->getClassProfile()->isEntity()) {
$property = $this->wrappedArg->getClassProfile()->getProperty($key);
$type = $property->getType();
}
}
return $this->getRange($key, $matches[6], $matches[7], $type);
break;
}
}
|
php
|
protected function replacePropertyExpression($matches) {
//count available matches
//this indicates the type of expression to replace
$total_matches = count($matches);
$type = $subindex = null;
switch ($total_matches) {
/*
* Property
*/
case 4: //#{PROPERTY@1[INDEX]@2?:TYPE@3}
$type = substr($matches[3], 1);
case 3: //#{PROPERTY@1[INDEX]@2}
$subindex = empty($matches[2]) ? null : substr($matches[2], 1, -1);
case 2: //#{PROPERTY@1}
$key = $matches[1];
//obtain type from annotation (when possible)
if (is_null($type) && $this->wrappedArg instanceof ObjectArgumentWrapper) {
if ($this->wrappedArg->getClassProfile()->isEntity()) {
$property = $this->wrappedArg->getClassProfile()->getProperty($key);
$type = $property->getType();
}
}
return $this->getIndex($key, $subindex, $type);
break;
/*
* Interval
*/
case 9: //#{PROPERTY@4[LEFT_INDEX@6..RIGHT_INDEX@7]:TYPE@8}
$type = substr($matches[8], 1);
case 8: //#{PROPERTY@4[LEFT_INDEX@6..RIGHT_INDEX@7]}
$key = $matches[4];
//obtain type from annotation (when possible)
if (is_null($type) && $this->wrappedArg instanceof ObjectArgumentWrapper) {
if ($this->wrappedArg->getClassProfile()->isEntity()) {
$property = $this->wrappedArg->getClassProfile()->getProperty($key);
$type = $property->getType();
}
}
return $this->getRange($key, $matches[6], $matches[7], $type);
break;
}
}
|
[
"protected",
"function",
"replacePropertyExpression",
"(",
"$",
"matches",
")",
"{",
"//count available matches",
"//this indicates the type of expression to replace",
"$",
"total_matches",
"=",
"count",
"(",
"$",
"matches",
")",
";",
"$",
"type",
"=",
"$",
"subindex",
"=",
"null",
";",
"switch",
"(",
"$",
"total_matches",
")",
"{",
"/*\n\t\t\t * Property\n\t\t\t */",
"case",
"4",
":",
"//#{PROPERTY@1[INDEX]@2?:TYPE@3}",
"$",
"type",
"=",
"substr",
"(",
"$",
"matches",
"[",
"3",
"]",
",",
"1",
")",
";",
"case",
"3",
":",
"//#{PROPERTY@1[INDEX]@2}",
"$",
"subindex",
"=",
"empty",
"(",
"$",
"matches",
"[",
"2",
"]",
")",
"?",
"null",
":",
"substr",
"(",
"$",
"matches",
"[",
"2",
"]",
",",
"1",
",",
"-",
"1",
")",
";",
"case",
"2",
":",
"//#{PROPERTY@1}",
"$",
"key",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"//obtain type from annotation (when possible)",
"if",
"(",
"is_null",
"(",
"$",
"type",
")",
"&&",
"$",
"this",
"->",
"wrappedArg",
"instanceof",
"ObjectArgumentWrapper",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"wrappedArg",
"->",
"getClassProfile",
"(",
")",
"->",
"isEntity",
"(",
")",
")",
"{",
"$",
"property",
"=",
"$",
"this",
"->",
"wrappedArg",
"->",
"getClassProfile",
"(",
")",
"->",
"getProperty",
"(",
"$",
"key",
")",
";",
"$",
"type",
"=",
"$",
"property",
"->",
"getType",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"getIndex",
"(",
"$",
"key",
",",
"$",
"subindex",
",",
"$",
"type",
")",
";",
"break",
";",
"/*\n\t\t\t * Interval\n\t\t\t */",
"case",
"9",
":",
"//#{PROPERTY@4[LEFT_INDEX@6..RIGHT_INDEX@7]:TYPE@8}",
"$",
"type",
"=",
"substr",
"(",
"$",
"matches",
"[",
"8",
"]",
",",
"1",
")",
";",
"case",
"8",
":",
"//#{PROPERTY@4[LEFT_INDEX@6..RIGHT_INDEX@7]}",
"$",
"key",
"=",
"$",
"matches",
"[",
"4",
"]",
";",
"//obtain type from annotation (when possible)",
"if",
"(",
"is_null",
"(",
"$",
"type",
")",
"&&",
"$",
"this",
"->",
"wrappedArg",
"instanceof",
"ObjectArgumentWrapper",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"wrappedArg",
"->",
"getClassProfile",
"(",
")",
"->",
"isEntity",
"(",
")",
")",
"{",
"$",
"property",
"=",
"$",
"this",
"->",
"wrappedArg",
"->",
"getClassProfile",
"(",
")",
"->",
"getProperty",
"(",
"$",
"key",
")",
";",
"$",
"type",
"=",
"$",
"property",
"->",
"getType",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"getRange",
"(",
"$",
"key",
",",
"$",
"matches",
"[",
"6",
"]",
",",
"$",
"matches",
"[",
"7",
"]",
",",
"$",
"type",
")",
";",
"break",
";",
"}",
"}"
] |
Returns a string that replaces a property expression
@param array $matches
@return string
|
[
"Returns",
"a",
"string",
"that",
"replaces",
"a",
"property",
"expression"
] |
df7100e601d2a1363d07028a786b6ceb22271829
|
https://github.com/emaphp/eMapper/blob/df7100e601d2a1363d07028a786b6ceb22271829/lib/eMapper/Cache/Key/CacheKeyFormatter.php#L376-L423
|
237,591
|
emaphp/eMapper
|
lib/eMapper/Cache/Key/CacheKeyFormatter.php
|
CacheKeyFormatter.replaceArgumentExpression
|
protected function replaceArgumentExpression($matches) {
//count available matches
//this indicates the type of expression to replace
$total_matches = count($matches);
$type = $subindex = null;
//%{TYPE|CLASS@1}
if ($total_matches == 2) {
//check if there are arguments left
if ($this->counter >= count($this->args))
throw new \OutOfBoundsException("No arguments left for expression '{$matches[0]}'");
return $this->castParameter($this->args[$this->counter++], $matches[1]);
}
switch ($total_matches) {
/*
* Simple index
*/
case 5: //%{NUMBER@2[INDEX]@3?:TYPE@4}
$type = substr($matches[4], 1);
case 4: //%{NUMBER@2[INDEX]@3}
$subindex = empty($matches[3]) ? null : substr($matches[3], 1, -1);
case 3: //%{NUMBER@2}
$index = intval($matches[2]);
if (!array_key_exists($index, $this->args))
throw new \InvalidArgumentException("No value found on index $index");
if ($index == 0 && !is_null($subindex))
return $this->getIndex($subindex, null, $type);
return $this->getSubIndex($this->args[$index], $subindex, $type);
/*
* Interval
*/
case 10: //%{NUMBER@5[LEFT@7?..RIGHT@8?]:TYPE@9}
$type = substr($matches[9], 1);
case 9: //%{NUMBER@5[LEFT@7?..RIGHT@8?]}
$index = intval($matches[5]);
if (!array_key_exists($index, $this->args))
throw new \InvalidArgumentException("No value found on index $index");
return $this->getSubRange($this->args[$index], $matches[7], $matches[8], $type);
}
}
|
php
|
protected function replaceArgumentExpression($matches) {
//count available matches
//this indicates the type of expression to replace
$total_matches = count($matches);
$type = $subindex = null;
//%{TYPE|CLASS@1}
if ($total_matches == 2) {
//check if there are arguments left
if ($this->counter >= count($this->args))
throw new \OutOfBoundsException("No arguments left for expression '{$matches[0]}'");
return $this->castParameter($this->args[$this->counter++], $matches[1]);
}
switch ($total_matches) {
/*
* Simple index
*/
case 5: //%{NUMBER@2[INDEX]@3?:TYPE@4}
$type = substr($matches[4], 1);
case 4: //%{NUMBER@2[INDEX]@3}
$subindex = empty($matches[3]) ? null : substr($matches[3], 1, -1);
case 3: //%{NUMBER@2}
$index = intval($matches[2]);
if (!array_key_exists($index, $this->args))
throw new \InvalidArgumentException("No value found on index $index");
if ($index == 0 && !is_null($subindex))
return $this->getIndex($subindex, null, $type);
return $this->getSubIndex($this->args[$index], $subindex, $type);
/*
* Interval
*/
case 10: //%{NUMBER@5[LEFT@7?..RIGHT@8?]:TYPE@9}
$type = substr($matches[9], 1);
case 9: //%{NUMBER@5[LEFT@7?..RIGHT@8?]}
$index = intval($matches[5]);
if (!array_key_exists($index, $this->args))
throw new \InvalidArgumentException("No value found on index $index");
return $this->getSubRange($this->args[$index], $matches[7], $matches[8], $type);
}
}
|
[
"protected",
"function",
"replaceArgumentExpression",
"(",
"$",
"matches",
")",
"{",
"//count available matches",
"//this indicates the type of expression to replace",
"$",
"total_matches",
"=",
"count",
"(",
"$",
"matches",
")",
";",
"$",
"type",
"=",
"$",
"subindex",
"=",
"null",
";",
"//%{TYPE|CLASS@1}",
"if",
"(",
"$",
"total_matches",
"==",
"2",
")",
"{",
"//check if there are arguments left",
"if",
"(",
"$",
"this",
"->",
"counter",
">=",
"count",
"(",
"$",
"this",
"->",
"args",
")",
")",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"\"No arguments left for expression '{$matches[0]}'\"",
")",
";",
"return",
"$",
"this",
"->",
"castParameter",
"(",
"$",
"this",
"->",
"args",
"[",
"$",
"this",
"->",
"counter",
"++",
"]",
",",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"}",
"switch",
"(",
"$",
"total_matches",
")",
"{",
"/*\n\t\t\t * Simple index\n\t\t\t */",
"case",
"5",
":",
"//%{NUMBER@2[INDEX]@3?:TYPE@4}",
"$",
"type",
"=",
"substr",
"(",
"$",
"matches",
"[",
"4",
"]",
",",
"1",
")",
";",
"case",
"4",
":",
"//%{NUMBER@2[INDEX]@3}",
"$",
"subindex",
"=",
"empty",
"(",
"$",
"matches",
"[",
"3",
"]",
")",
"?",
"null",
":",
"substr",
"(",
"$",
"matches",
"[",
"3",
"]",
",",
"1",
",",
"-",
"1",
")",
";",
"case",
"3",
":",
"//%{NUMBER@2}",
"$",
"index",
"=",
"intval",
"(",
"$",
"matches",
"[",
"2",
"]",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"index",
",",
"$",
"this",
"->",
"args",
")",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"No value found on index $index\"",
")",
";",
"if",
"(",
"$",
"index",
"==",
"0",
"&&",
"!",
"is_null",
"(",
"$",
"subindex",
")",
")",
"return",
"$",
"this",
"->",
"getIndex",
"(",
"$",
"subindex",
",",
"null",
",",
"$",
"type",
")",
";",
"return",
"$",
"this",
"->",
"getSubIndex",
"(",
"$",
"this",
"->",
"args",
"[",
"$",
"index",
"]",
",",
"$",
"subindex",
",",
"$",
"type",
")",
";",
"/*\n\t\t\t * Interval\n\t\t\t */",
"case",
"10",
":",
"//%{NUMBER@5[LEFT@7?..RIGHT@8?]:TYPE@9}",
"$",
"type",
"=",
"substr",
"(",
"$",
"matches",
"[",
"9",
"]",
",",
"1",
")",
";",
"case",
"9",
":",
"//%{NUMBER@5[LEFT@7?..RIGHT@8?]}",
"$",
"index",
"=",
"intval",
"(",
"$",
"matches",
"[",
"5",
"]",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"index",
",",
"$",
"this",
"->",
"args",
")",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"No value found on index $index\"",
")",
";",
"return",
"$",
"this",
"->",
"getSubRange",
"(",
"$",
"this",
"->",
"args",
"[",
"$",
"index",
"]",
",",
"$",
"matches",
"[",
"7",
"]",
",",
"$",
"matches",
"[",
"8",
"]",
",",
"$",
"type",
")",
";",
"}",
"}"
] |
Returns a string that replaces an argument expression
@param array$matches
@throws \OutOfBoundsException
@throws \InvalidArgumentException
@return string
|
[
"Returns",
"a",
"string",
"that",
"replaces",
"an",
"argument",
"expression"
] |
df7100e601d2a1363d07028a786b6ceb22271829
|
https://github.com/emaphp/eMapper/blob/df7100e601d2a1363d07028a786b6ceb22271829/lib/eMapper/Cache/Key/CacheKeyFormatter.php#L432-L479
|
237,592
|
novuso/system
|
src/Utility/Validate.php
|
Validate.isEmail
|
public static function isEmail($value): bool
{
if (!static::isStringCastable($value)) {
return false;
}
return filter_var((string) $value, FILTER_VALIDATE_EMAIL) !== false;
}
|
php
|
public static function isEmail($value): bool
{
if (!static::isStringCastable($value)) {
return false;
}
return filter_var((string) $value, FILTER_VALIDATE_EMAIL) !== false;
}
|
[
"public",
"static",
"function",
"isEmail",
"(",
"$",
"value",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"static",
"::",
"isStringCastable",
"(",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"filter_var",
"(",
"(",
"string",
")",
"$",
"value",
",",
"FILTER_VALIDATE_EMAIL",
")",
"!==",
"false",
";",
"}"
] |
Checks if value is an email address
@param mixed $value The value
@return bool
|
[
"Checks",
"if",
"value",
"is",
"an",
"email",
"address"
] |
e34038b391826edc68d0b5fccfba96642de9d6f0
|
https://github.com/novuso/system/blob/e34038b391826edc68d0b5fccfba96642de9d6f0/src/Utility/Validate.php#L338-L345
|
237,593
|
novuso/system
|
src/Utility/Validate.php
|
Validate.isIpAddress
|
public static function isIpAddress($value): bool
{
if (!static::isStringCastable($value)) {
return false;
}
return filter_var((string) $value, FILTER_VALIDATE_IP) !== false;
}
|
php
|
public static function isIpAddress($value): bool
{
if (!static::isStringCastable($value)) {
return false;
}
return filter_var((string) $value, FILTER_VALIDATE_IP) !== false;
}
|
[
"public",
"static",
"function",
"isIpAddress",
"(",
"$",
"value",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"static",
"::",
"isStringCastable",
"(",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"filter_var",
"(",
"(",
"string",
")",
"$",
"value",
",",
"FILTER_VALIDATE_IP",
")",
"!==",
"false",
";",
"}"
] |
Checks if value is an IP address
@param mixed $value The value
@return bool
|
[
"Checks",
"if",
"value",
"is",
"an",
"IP",
"address"
] |
e34038b391826edc68d0b5fccfba96642de9d6f0
|
https://github.com/novuso/system/blob/e34038b391826edc68d0b5fccfba96642de9d6f0/src/Utility/Validate.php#L354-L361
|
237,594
|
novuso/system
|
src/Utility/Validate.php
|
Validate.isIpV4Address
|
public static function isIpV4Address($value): bool
{
if (!static::isStringCastable($value)) {
return false;
}
return filter_var((string) $value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false;
}
|
php
|
public static function isIpV4Address($value): bool
{
if (!static::isStringCastable($value)) {
return false;
}
return filter_var((string) $value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false;
}
|
[
"public",
"static",
"function",
"isIpV4Address",
"(",
"$",
"value",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"static",
"::",
"isStringCastable",
"(",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"filter_var",
"(",
"(",
"string",
")",
"$",
"value",
",",
"FILTER_VALIDATE_IP",
",",
"FILTER_FLAG_IPV4",
")",
"!==",
"false",
";",
"}"
] |
Checks if value is an IPv4 address
@param mixed $value The value
@return bool
|
[
"Checks",
"if",
"value",
"is",
"an",
"IPv4",
"address"
] |
e34038b391826edc68d0b5fccfba96642de9d6f0
|
https://github.com/novuso/system/blob/e34038b391826edc68d0b5fccfba96642de9d6f0/src/Utility/Validate.php#L370-L377
|
237,595
|
novuso/system
|
src/Utility/Validate.php
|
Validate.isIpV6Address
|
public static function isIpV6Address($value): bool
{
if (!static::isStringCastable($value)) {
return false;
}
return filter_var((string) $value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false;
}
|
php
|
public static function isIpV6Address($value): bool
{
if (!static::isStringCastable($value)) {
return false;
}
return filter_var((string) $value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false;
}
|
[
"public",
"static",
"function",
"isIpV6Address",
"(",
"$",
"value",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"static",
"::",
"isStringCastable",
"(",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"filter_var",
"(",
"(",
"string",
")",
"$",
"value",
",",
"FILTER_VALIDATE_IP",
",",
"FILTER_FLAG_IPV6",
")",
"!==",
"false",
";",
"}"
] |
Checks if value is an IPv6 address
@param mixed $value The value
@return bool
|
[
"Checks",
"if",
"value",
"is",
"an",
"IPv6",
"address"
] |
e34038b391826edc68d0b5fccfba96642de9d6f0
|
https://github.com/novuso/system/blob/e34038b391826edc68d0b5fccfba96642de9d6f0/src/Utility/Validate.php#L386-L393
|
237,596
|
novuso/system
|
src/Utility/Validate.php
|
Validate.isUri
|
public static function isUri($value): bool
{
if (!static::isStringCastable($value)) {
return false;
}
// http://tools.ietf.org/html/rfc3986
//
// URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
// hier-part = "//" authority path-abempty
// / path-absolute
// / path-rootless
// / path-empty
$pattern = sprintf(
'/\A%s%s%s%s%s\z/',
'(?:([^:\/?#]+)(:))?',
'(?:(\/\/)([^\/?#]*))?',
'([^?#]*)',
'(?:(\?)([^#]*))?',
'(?:(#)(.*))?'
);
preg_match($pattern, (string) $value, $matches);
$uri = self::uriComponentsFromMatches($matches);
return self::isValidUri($uri);
}
|
php
|
public static function isUri($value): bool
{
if (!static::isStringCastable($value)) {
return false;
}
// http://tools.ietf.org/html/rfc3986
//
// URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
// hier-part = "//" authority path-abempty
// / path-absolute
// / path-rootless
// / path-empty
$pattern = sprintf(
'/\A%s%s%s%s%s\z/',
'(?:([^:\/?#]+)(:))?',
'(?:(\/\/)([^\/?#]*))?',
'([^?#]*)',
'(?:(\?)([^#]*))?',
'(?:(#)(.*))?'
);
preg_match($pattern, (string) $value, $matches);
$uri = self::uriComponentsFromMatches($matches);
return self::isValidUri($uri);
}
|
[
"public",
"static",
"function",
"isUri",
"(",
"$",
"value",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"static",
"::",
"isStringCastable",
"(",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"// http://tools.ietf.org/html/rfc3986",
"//",
"// URI = scheme \":\" hier-part [ \"?\" query ] [ \"#\" fragment ]",
"// hier-part = \"//\" authority path-abempty",
"// / path-absolute",
"// / path-rootless",
"// / path-empty",
"$",
"pattern",
"=",
"sprintf",
"(",
"'/\\A%s%s%s%s%s\\z/'",
",",
"'(?:([^:\\/?#]+)(:))?'",
",",
"'(?:(\\/\\/)([^\\/?#]*))?'",
",",
"'([^?#]*)'",
",",
"'(?:(\\?)([^#]*))?'",
",",
"'(?:(#)(.*))?'",
")",
";",
"preg_match",
"(",
"$",
"pattern",
",",
"(",
"string",
")",
"$",
"value",
",",
"$",
"matches",
")",
";",
"$",
"uri",
"=",
"self",
"::",
"uriComponentsFromMatches",
"(",
"$",
"matches",
")",
";",
"return",
"self",
"::",
"isValidUri",
"(",
"$",
"uri",
")",
";",
"}"
] |
Checks if value is a URI
@param mixed $value The value
@return bool
|
[
"Checks",
"if",
"value",
"is",
"a",
"URI"
] |
e34038b391826edc68d0b5fccfba96642de9d6f0
|
https://github.com/novuso/system/blob/e34038b391826edc68d0b5fccfba96642de9d6f0/src/Utility/Validate.php#L402-L428
|
237,597
|
novuso/system
|
src/Utility/Validate.php
|
Validate.isUrn
|
public static function isUrn($value): bool
{
if (!static::isStringCastable($value)) {
return false;
}
// http://tools.ietf.org/html/rfc2141#section-2.1
// To avoid confusion with the "urn:" identifier, the NID "urn" is
// reserved and MUST NOT be used
if (substr((string) $value, 0, 8) === "urn:urn:") {
return false;
}
// http://tools.ietf.org/html/rfc2141
//
// <URN> ::= "urn:" <NID> ":" <NSS>
//
// <NID> ::= <let-num> [ 1,31<let-num-hyp> ]
// <let-num-hyp> ::= <upper> | <lower> | <number> | "-"
// <let-num> ::= <upper> | <lower> | <number>
// <upper> ::= "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" |
// "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" |
// "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" |
// "Y" | "Z"
// <lower> ::= "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" |
// "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" |
// "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" |
// "y" | "z"
// <number> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" |
// "8" | "9"
//
// <NSS> ::= 1*<URN chars>
// <URN chars> ::= <trans> | "%" <hex> <hex>
// <trans> ::= <upper> | <lower> | <number> | <other> | <reserved>
// <hex> ::= <number> | "A" | "B" | "C" | "D" | "E" | "F" |
// "a" | "b" | "c" | "d" | "e" | "f"
// <other> ::= "(" | ")" | "+" | "," | "-" | "." |
// ":" | "=" | "@" | ";" | "$" |
// "_" | "!" | "*" | "'"
//
// Therefore, these characters are RESERVED for future developments.
// Namespace developers SHOULD NOT use these characters in unencoded
// form, but rather use the appropriate %-encoding for each character.
//
// In addition, octet 0 (0 hex) should NEVER be used, in either
// unencoded or %-encoded form.
$pattern = sprintf(
'/\Aurn:%s:%s\z/i',
'[a-z0-9](?:[a-z0-9\-]{1,31})?',
'(?:[a-z0-9()+,\-.:=@;$_!*\']|%(?:0[a-f1-9]|[a-f1-9][a-f0-9]))+'
);
return !!preg_match($pattern, (string) $value);
}
|
php
|
public static function isUrn($value): bool
{
if (!static::isStringCastable($value)) {
return false;
}
// http://tools.ietf.org/html/rfc2141#section-2.1
// To avoid confusion with the "urn:" identifier, the NID "urn" is
// reserved and MUST NOT be used
if (substr((string) $value, 0, 8) === "urn:urn:") {
return false;
}
// http://tools.ietf.org/html/rfc2141
//
// <URN> ::= "urn:" <NID> ":" <NSS>
//
// <NID> ::= <let-num> [ 1,31<let-num-hyp> ]
// <let-num-hyp> ::= <upper> | <lower> | <number> | "-"
// <let-num> ::= <upper> | <lower> | <number>
// <upper> ::= "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" |
// "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" |
// "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" |
// "Y" | "Z"
// <lower> ::= "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" |
// "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" |
// "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" |
// "y" | "z"
// <number> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" |
// "8" | "9"
//
// <NSS> ::= 1*<URN chars>
// <URN chars> ::= <trans> | "%" <hex> <hex>
// <trans> ::= <upper> | <lower> | <number> | <other> | <reserved>
// <hex> ::= <number> | "A" | "B" | "C" | "D" | "E" | "F" |
// "a" | "b" | "c" | "d" | "e" | "f"
// <other> ::= "(" | ")" | "+" | "," | "-" | "." |
// ":" | "=" | "@" | ";" | "$" |
// "_" | "!" | "*" | "'"
//
// Therefore, these characters are RESERVED for future developments.
// Namespace developers SHOULD NOT use these characters in unencoded
// form, but rather use the appropriate %-encoding for each character.
//
// In addition, octet 0 (0 hex) should NEVER be used, in either
// unencoded or %-encoded form.
$pattern = sprintf(
'/\Aurn:%s:%s\z/i',
'[a-z0-9](?:[a-z0-9\-]{1,31})?',
'(?:[a-z0-9()+,\-.:=@;$_!*\']|%(?:0[a-f1-9]|[a-f1-9][a-f0-9]))+'
);
return !!preg_match($pattern, (string) $value);
}
|
[
"public",
"static",
"function",
"isUrn",
"(",
"$",
"value",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"static",
"::",
"isStringCastable",
"(",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"// http://tools.ietf.org/html/rfc2141#section-2.1",
"// To avoid confusion with the \"urn:\" identifier, the NID \"urn\" is",
"// reserved and MUST NOT be used",
"if",
"(",
"substr",
"(",
"(",
"string",
")",
"$",
"value",
",",
"0",
",",
"8",
")",
"===",
"\"urn:urn:\"",
")",
"{",
"return",
"false",
";",
"}",
"// http://tools.ietf.org/html/rfc2141",
"//",
"// <URN> ::= \"urn:\" <NID> \":\" <NSS>",
"//",
"// <NID> ::= <let-num> [ 1,31<let-num-hyp> ]",
"// <let-num-hyp> ::= <upper> | <lower> | <number> | \"-\"",
"// <let-num> ::= <upper> | <lower> | <number>",
"// <upper> ::= \"A\" | \"B\" | \"C\" | \"D\" | \"E\" | \"F\" | \"G\" | \"H\" |",
"// \"I\" | \"J\" | \"K\" | \"L\" | \"M\" | \"N\" | \"O\" | \"P\" |",
"// \"Q\" | \"R\" | \"S\" | \"T\" | \"U\" | \"V\" | \"W\" | \"X\" |",
"// \"Y\" | \"Z\"",
"// <lower> ::= \"a\" | \"b\" | \"c\" | \"d\" | \"e\" | \"f\" | \"g\" | \"h\" |",
"// \"i\" | \"j\" | \"k\" | \"l\" | \"m\" | \"n\" | \"o\" | \"p\" |",
"// \"q\" | \"r\" | \"s\" | \"t\" | \"u\" | \"v\" | \"w\" | \"x\" |",
"// \"y\" | \"z\"",
"// <number> ::= \"0\" | \"1\" | \"2\" | \"3\" | \"4\" | \"5\" | \"6\" | \"7\" |",
"// \"8\" | \"9\"",
"//",
"// <NSS> ::= 1*<URN chars>",
"// <URN chars> ::= <trans> | \"%\" <hex> <hex>",
"// <trans> ::= <upper> | <lower> | <number> | <other> | <reserved>",
"// <hex> ::= <number> | \"A\" | \"B\" | \"C\" | \"D\" | \"E\" | \"F\" |",
"// \"a\" | \"b\" | \"c\" | \"d\" | \"e\" | \"f\"",
"// <other> ::= \"(\" | \")\" | \"+\" | \",\" | \"-\" | \".\" |",
"// \":\" | \"=\" | \"@\" | \";\" | \"$\" |",
"// \"_\" | \"!\" | \"*\" | \"'\"",
"//",
"// Therefore, these characters are RESERVED for future developments.",
"// Namespace developers SHOULD NOT use these characters in unencoded",
"// form, but rather use the appropriate %-encoding for each character.",
"//",
"// In addition, octet 0 (0 hex) should NEVER be used, in either",
"// unencoded or %-encoded form.",
"$",
"pattern",
"=",
"sprintf",
"(",
"'/\\Aurn:%s:%s\\z/i'",
",",
"'[a-z0-9](?:[a-z0-9\\-]{1,31})?'",
",",
"'(?:[a-z0-9()+,\\-.:=@;$_!*\\']|%(?:0[a-f1-9]|[a-f1-9][a-f0-9]))+'",
")",
";",
"return",
"!",
"!",
"preg_match",
"(",
"$",
"pattern",
",",
"(",
"string",
")",
"$",
"value",
")",
";",
"}"
] |
Checks if value is a URN
@param mixed $value The value
@return bool
|
[
"Checks",
"if",
"value",
"is",
"a",
"URN"
] |
e34038b391826edc68d0b5fccfba96642de9d6f0
|
https://github.com/novuso/system/blob/e34038b391826edc68d0b5fccfba96642de9d6f0/src/Utility/Validate.php#L437-L490
|
237,598
|
novuso/system
|
src/Utility/Validate.php
|
Validate.isUuid
|
public static function isUuid($value): bool
{
if (!static::isStringCastable($value)) {
return false;
}
// http://tools.ietf.org/html/rfc4122
//
// UUID = time-low "-" time-mid "-"
// time-high-and-version "-"
// clock-seq-and-reserved
// clock-seq-low "-" node
// time-low = 4hexOctet
// time-mid = 2hexOctet
// time-high-and-version = 2hexOctet
// clock-seq-and-reserved = hexOctet
// clock-seq-low = hexOctet
// node = 6hexOctet
// hexOctet = hexDigit hexDigit
// hexDigit =
// "0" / "1" / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9" /
// "a" / "b" / "c" / "d" / "e" / "f" /
// "A" / "B" / "C" / "D" / "E" / "F"
$pattern = sprintf(
'/\A%s-%s-%s-%s%s-%s\z/i',
'[a-f0-9]{8}',
'[a-f0-9]{4}',
'[a-f0-9]{4}',
'[a-f0-9]{2}',
'[a-f0-9]{2}',
'[a-f0-9]{12}'
);
$value = str_replace(['urn:', 'uuid:', '{', '}'], '', (string) $value);
return !!preg_match($pattern, $value);
}
|
php
|
public static function isUuid($value): bool
{
if (!static::isStringCastable($value)) {
return false;
}
// http://tools.ietf.org/html/rfc4122
//
// UUID = time-low "-" time-mid "-"
// time-high-and-version "-"
// clock-seq-and-reserved
// clock-seq-low "-" node
// time-low = 4hexOctet
// time-mid = 2hexOctet
// time-high-and-version = 2hexOctet
// clock-seq-and-reserved = hexOctet
// clock-seq-low = hexOctet
// node = 6hexOctet
// hexOctet = hexDigit hexDigit
// hexDigit =
// "0" / "1" / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9" /
// "a" / "b" / "c" / "d" / "e" / "f" /
// "A" / "B" / "C" / "D" / "E" / "F"
$pattern = sprintf(
'/\A%s-%s-%s-%s%s-%s\z/i',
'[a-f0-9]{8}',
'[a-f0-9]{4}',
'[a-f0-9]{4}',
'[a-f0-9]{2}',
'[a-f0-9]{2}',
'[a-f0-9]{12}'
);
$value = str_replace(['urn:', 'uuid:', '{', '}'], '', (string) $value);
return !!preg_match($pattern, $value);
}
|
[
"public",
"static",
"function",
"isUuid",
"(",
"$",
"value",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"static",
"::",
"isStringCastable",
"(",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"// http://tools.ietf.org/html/rfc4122",
"//",
"// UUID = time-low \"-\" time-mid \"-\"",
"// time-high-and-version \"-\"",
"// clock-seq-and-reserved",
"// clock-seq-low \"-\" node",
"// time-low = 4hexOctet",
"// time-mid = 2hexOctet",
"// time-high-and-version = 2hexOctet",
"// clock-seq-and-reserved = hexOctet",
"// clock-seq-low = hexOctet",
"// node = 6hexOctet",
"// hexOctet = hexDigit hexDigit",
"// hexDigit =",
"// \"0\" / \"1\" / \"2\" / \"3\" / \"4\" / \"5\" / \"6\" / \"7\" / \"8\" / \"9\" /",
"// \"a\" / \"b\" / \"c\" / \"d\" / \"e\" / \"f\" /",
"// \"A\" / \"B\" / \"C\" / \"D\" / \"E\" / \"F\"",
"$",
"pattern",
"=",
"sprintf",
"(",
"'/\\A%s-%s-%s-%s%s-%s\\z/i'",
",",
"'[a-f0-9]{8}'",
",",
"'[a-f0-9]{4}'",
",",
"'[a-f0-9]{4}'",
",",
"'[a-f0-9]{2}'",
",",
"'[a-f0-9]{2}'",
",",
"'[a-f0-9]{12}'",
")",
";",
"$",
"value",
"=",
"str_replace",
"(",
"[",
"'urn:'",
",",
"'uuid:'",
",",
"'{'",
",",
"'}'",
"]",
",",
"''",
",",
"(",
"string",
")",
"$",
"value",
")",
";",
"return",
"!",
"!",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"value",
")",
";",
"}"
] |
Checks if value is a UUID
@param mixed $value The value
@return bool
|
[
"Checks",
"if",
"value",
"is",
"a",
"UUID"
] |
e34038b391826edc68d0b5fccfba96642de9d6f0
|
https://github.com/novuso/system/blob/e34038b391826edc68d0b5fccfba96642de9d6f0/src/Utility/Validate.php#L499-L535
|
237,599
|
novuso/system
|
src/Utility/Validate.php
|
Validate.isTimezone
|
public static function isTimezone($value): bool
{
if ($value instanceof DateTimeZone) {
return true;
}
if (!static::isStringCastable($value)) {
return false;
}
return self::isValidTimezone((string) $value);
}
|
php
|
public static function isTimezone($value): bool
{
if ($value instanceof DateTimeZone) {
return true;
}
if (!static::isStringCastable($value)) {
return false;
}
return self::isValidTimezone((string) $value);
}
|
[
"public",
"static",
"function",
"isTimezone",
"(",
"$",
"value",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"DateTimeZone",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"static",
"::",
"isStringCastable",
"(",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"self",
"::",
"isValidTimezone",
"(",
"(",
"string",
")",
"$",
"value",
")",
";",
"}"
] |
Checks if value is a timezone
@param mixed $value The value
@return bool
|
[
"Checks",
"if",
"value",
"is",
"a",
"timezone"
] |
e34038b391826edc68d0b5fccfba96642de9d6f0
|
https://github.com/novuso/system/blob/e34038b391826edc68d0b5fccfba96642de9d6f0/src/Utility/Validate.php#L544-L555
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.