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
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
|
---|---|---|---|---|---|---|---|---|---|---|---|
7,300 | svanderburg/pndp | src/PNDP/NixGenerator.php | NixGenerator.generateIndentation | public static function generateIndentation($indentLevel, $format)
{
if($format)
{
$expr = "";
for($i = 0; $i < $indentLevel; $i++)
$expr .= " ";
return $expr;
}
else
return "";
} | php | public static function generateIndentation($indentLevel, $format)
{
if($format)
{
$expr = "";
for($i = 0; $i < $indentLevel; $i++)
$expr .= " ";
return $expr;
}
else
return "";
} | [
"public",
"static",
"function",
"generateIndentation",
"(",
"$",
"indentLevel",
",",
"$",
"format",
")",
"{",
"if",
"(",
"$",
"format",
")",
"{",
"$",
"expr",
"=",
"\"\"",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"indentLevel",
";",
"$",
"i",
"++",
")",
"$",
"expr",
".=",
"\" \"",
";",
"return",
"$",
"expr",
";",
"}",
"else",
"return",
"\"\"",
";",
"}"
] | Generates indentation to format the resulting output expression more nicely.
@param int $indentLevel The indentation level of the resulting sub expression
@param bool $format Indicates whether to nicely format to expression (i.e. generating whitespaces) or not
@return string A string with the amount of whitespaces corresponding to the indent level | [
"Generates",
"indentation",
"to",
"format",
"the",
"resulting",
"output",
"expression",
"more",
"nicely",
"."
] | 4bfe9c4120c23354ab8dc295957dc3009a39bff0 | https://github.com/svanderburg/pndp/blob/4bfe9c4120c23354ab8dc295957dc3009a39bff0/src/PNDP/NixGenerator.php#L20-L32 |
7,301 | svanderburg/pndp | src/PNDP/NixGenerator.php | NixGenerator.sequentialArrayToIndentedNix | public static function sequentialArrayToIndentedNix(array $array, $indentLevel, $format)
{
if(count($array) == 0)
return "[]"; // Not strictly required, but printing an empty list like this is better than putting a newline between the brackets
else
{
$expr = "[\n";
foreach($array as $value)
{
$listMemberExpr = NixGenerator::phpToIndentedNix($value, $indentLevel + 1, $format);
/* Some objects in a list require ( ) wrapped around them to make them work, because whitespaces are in principle the delimiter symbols in lists */
if($value instanceof NixBlock) {
$listMemberExpr = $value->wrapInParenthesis($listMemberExpr);
}
$expr .= NixGenerator::generateIndentation($indentLevel + 1, $format).$listMemberExpr."\n";
}
$expr .= NixGenerator::generateIndentation($indentLevel, $format)."]";
return $expr;
}
} | php | public static function sequentialArrayToIndentedNix(array $array, $indentLevel, $format)
{
if(count($array) == 0)
return "[]"; // Not strictly required, but printing an empty list like this is better than putting a newline between the brackets
else
{
$expr = "[\n";
foreach($array as $value)
{
$listMemberExpr = NixGenerator::phpToIndentedNix($value, $indentLevel + 1, $format);
/* Some objects in a list require ( ) wrapped around them to make them work, because whitespaces are in principle the delimiter symbols in lists */
if($value instanceof NixBlock) {
$listMemberExpr = $value->wrapInParenthesis($listMemberExpr);
}
$expr .= NixGenerator::generateIndentation($indentLevel + 1, $format).$listMemberExpr."\n";
}
$expr .= NixGenerator::generateIndentation($indentLevel, $format)."]";
return $expr;
}
} | [
"public",
"static",
"function",
"sequentialArrayToIndentedNix",
"(",
"array",
"$",
"array",
",",
"$",
"indentLevel",
",",
"$",
"format",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"array",
")",
"==",
"0",
")",
"return",
"\"[]\"",
";",
"// Not strictly required, but printing an empty list like this is better than putting a newline between the brackets",
"else",
"{",
"$",
"expr",
"=",
"\"[\\n\"",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"value",
")",
"{",
"$",
"listMemberExpr",
"=",
"NixGenerator",
"::",
"phpToIndentedNix",
"(",
"$",
"value",
",",
"$",
"indentLevel",
"+",
"1",
",",
"$",
"format",
")",
";",
"/* Some objects in a list require ( ) wrapped around them to make them work, because whitespaces are in principle the delimiter symbols in lists */",
"if",
"(",
"$",
"value",
"instanceof",
"NixBlock",
")",
"{",
"$",
"listMemberExpr",
"=",
"$",
"value",
"->",
"wrapInParenthesis",
"(",
"$",
"listMemberExpr",
")",
";",
"}",
"$",
"expr",
".=",
"NixGenerator",
"::",
"generateIndentation",
"(",
"$",
"indentLevel",
"+",
"1",
",",
"$",
"format",
")",
".",
"$",
"listMemberExpr",
".",
"\"\\n\"",
";",
"}",
"$",
"expr",
".=",
"NixGenerator",
"::",
"generateIndentation",
"(",
"$",
"indentLevel",
",",
"$",
"format",
")",
".",
"\"]\"",
";",
"return",
"$",
"expr",
";",
"}",
"}"
] | Converts an array to a Nix list.
@param array $array Array to convert
@param int $indentLevel The indentation level of the resulting sub expression
@param bool $format Indicates whether to nicely format to expression (i.e. generating whitespaces) or not
@return A string representing the corresponding Nix list | [
"Converts",
"an",
"array",
"to",
"a",
"Nix",
"list",
"."
] | 4bfe9c4120c23354ab8dc295957dc3009a39bff0 | https://github.com/svanderburg/pndp/blob/4bfe9c4120c23354ab8dc295957dc3009a39bff0/src/PNDP/NixGenerator.php#L61-L85 |
7,302 | svanderburg/pndp | src/PNDP/NixGenerator.php | NixGenerator.arrayMembersToAttrsMembers | public static function arrayMembersToAttrsMembers(array $array, $indentLevel, $format)
{
$expr = "";
/* Convert inherit objects separately, since they have to be generated differently */
$first = true;
$haveInherits = false;
$previousInherit = null;
foreach($array as $key => $value)
{
if($value instanceof NixInherit)
{
$haveInherits = true;
if($previousInherit === null || !$value->equals($previousInherit)) // If the current inherit applies to the same scope as the previous inherit we can merge them into a single inherit statement. If not, we must terminate it, and generate a new one
{
if($first)
$first = false;
else
$expr .= ";\n";
$expr .= NixGenerator::generateIndentation($indentLevel, $format).$value->toNixExpr($indentLevel, $format);
}
$expr .= " ".NixGenerator::objectKeyToAttrName($key);
$previousInherit = $value;
}
}
if($haveInherits)
$expr .= ";\n"; // If we have inherits we must terminate it with a semicolon
/* Process "ordinary" object members */
foreach($array as $key => $value)
{
if(!($value instanceof NixInherit))
$expr .= NixGenerator::generateIndentation($indentLevel, $format).NixGenerator::objectKeyToAttrName($key)." = ".NixGenerator::phpToIndentedNix($value, $indentLevel, $format).";\n";
}
return $expr;
} | php | public static function arrayMembersToAttrsMembers(array $array, $indentLevel, $format)
{
$expr = "";
/* Convert inherit objects separately, since they have to be generated differently */
$first = true;
$haveInherits = false;
$previousInherit = null;
foreach($array as $key => $value)
{
if($value instanceof NixInherit)
{
$haveInherits = true;
if($previousInherit === null || !$value->equals($previousInherit)) // If the current inherit applies to the same scope as the previous inherit we can merge them into a single inherit statement. If not, we must terminate it, and generate a new one
{
if($first)
$first = false;
else
$expr .= ";\n";
$expr .= NixGenerator::generateIndentation($indentLevel, $format).$value->toNixExpr($indentLevel, $format);
}
$expr .= " ".NixGenerator::objectKeyToAttrName($key);
$previousInherit = $value;
}
}
if($haveInherits)
$expr .= ";\n"; // If we have inherits we must terminate it with a semicolon
/* Process "ordinary" object members */
foreach($array as $key => $value)
{
if(!($value instanceof NixInherit))
$expr .= NixGenerator::generateIndentation($indentLevel, $format).NixGenerator::objectKeyToAttrName($key)." = ".NixGenerator::phpToIndentedNix($value, $indentLevel, $format).";\n";
}
return $expr;
} | [
"public",
"static",
"function",
"arrayMembersToAttrsMembers",
"(",
"array",
"$",
"array",
",",
"$",
"indentLevel",
",",
"$",
"format",
")",
"{",
"$",
"expr",
"=",
"\"\"",
";",
"/* Convert inherit objects separately, since they have to be generated differently */",
"$",
"first",
"=",
"true",
";",
"$",
"haveInherits",
"=",
"false",
";",
"$",
"previousInherit",
"=",
"null",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"NixInherit",
")",
"{",
"$",
"haveInherits",
"=",
"true",
";",
"if",
"(",
"$",
"previousInherit",
"===",
"null",
"||",
"!",
"$",
"value",
"->",
"equals",
"(",
"$",
"previousInherit",
")",
")",
"// If the current inherit applies to the same scope as the previous inherit we can merge them into a single inherit statement. If not, we must terminate it, and generate a new one",
"{",
"if",
"(",
"$",
"first",
")",
"$",
"first",
"=",
"false",
";",
"else",
"$",
"expr",
".=",
"\";\\n\"",
";",
"$",
"expr",
".=",
"NixGenerator",
"::",
"generateIndentation",
"(",
"$",
"indentLevel",
",",
"$",
"format",
")",
".",
"$",
"value",
"->",
"toNixExpr",
"(",
"$",
"indentLevel",
",",
"$",
"format",
")",
";",
"}",
"$",
"expr",
".=",
"\" \"",
".",
"NixGenerator",
"::",
"objectKeyToAttrName",
"(",
"$",
"key",
")",
";",
"$",
"previousInherit",
"=",
"$",
"value",
";",
"}",
"}",
"if",
"(",
"$",
"haveInherits",
")",
"$",
"expr",
".=",
"\";\\n\"",
";",
"// If we have inherits we must terminate it with a semicolon",
"/* Process \"ordinary\" object members */",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"value",
"instanceof",
"NixInherit",
")",
")",
"$",
"expr",
".=",
"NixGenerator",
"::",
"generateIndentation",
"(",
"$",
"indentLevel",
",",
"$",
"format",
")",
".",
"NixGenerator",
"::",
"objectKeyToAttrName",
"(",
"$",
"key",
")",
".",
"\" = \"",
".",
"NixGenerator",
"::",
"phpToIndentedNix",
"(",
"$",
"value",
",",
"$",
"indentLevel",
",",
"$",
"format",
")",
".",
"\";\\n\"",
";",
"}",
"return",
"$",
"expr",
";",
"}"
] | Converts members of an array to members of an attribute set
@param array $array Array to convert
@param int $indentLevel The indentation level of the resulting sub expression
@param bool $format Indicates whether to nicely format to expression (i.e. generating whitespaces) or not
@return string A string containing the Nix attribute set members | [
"Converts",
"members",
"of",
"an",
"array",
"to",
"members",
"of",
"an",
"attribute",
"set"
] | 4bfe9c4120c23354ab8dc295957dc3009a39bff0 | https://github.com/svanderburg/pndp/blob/4bfe9c4120c23354ab8dc295957dc3009a39bff0/src/PNDP/NixGenerator.php#L103-L146 |
7,303 | svanderburg/pndp | src/PNDP/NixGenerator.php | NixGenerator.associativeArrayToIndentedNix | public static function associativeArrayToIndentedNix(array $array, $indentLevel, $format)
{
if(count($array) == 0)
return "{}"; // Not strictly required, but printing an empty attribute set like this is better that putting a newline between the braces
else
return "{\n".NixGenerator::arrayMembersToAttrsMembers($array, $indentLevel + 1, $format).NixGenerator::generateIndentation($indentLevel, $format)."}";
} | php | public static function associativeArrayToIndentedNix(array $array, $indentLevel, $format)
{
if(count($array) == 0)
return "{}"; // Not strictly required, but printing an empty attribute set like this is better that putting a newline between the braces
else
return "{\n".NixGenerator::arrayMembersToAttrsMembers($array, $indentLevel + 1, $format).NixGenerator::generateIndentation($indentLevel, $format)."}";
} | [
"public",
"static",
"function",
"associativeArrayToIndentedNix",
"(",
"array",
"$",
"array",
",",
"$",
"indentLevel",
",",
"$",
"format",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"array",
")",
"==",
"0",
")",
"return",
"\"{}\"",
";",
"// Not strictly required, but printing an empty attribute set like this is better that putting a newline between the braces",
"else",
"return",
"\"{\\n\"",
".",
"NixGenerator",
"::",
"arrayMembersToAttrsMembers",
"(",
"$",
"array",
",",
"$",
"indentLevel",
"+",
"1",
",",
"$",
"format",
")",
".",
"NixGenerator",
"::",
"generateIndentation",
"(",
"$",
"indentLevel",
",",
"$",
"format",
")",
".",
"\"}\"",
";",
"}"
] | Converts an array to a Nix attribute set.
@param array $array Array to convert
@param int $indentLevel The indentation level of the resulting sub expression
@param bool $format Indicates whether to nicely format to expression (i.e. generating whitespaces) or not
@return A string representing the corresponding Nix list | [
"Converts",
"an",
"array",
"to",
"a",
"Nix",
"attribute",
"set",
"."
] | 4bfe9c4120c23354ab8dc295957dc3009a39bff0 | https://github.com/svanderburg/pndp/blob/4bfe9c4120c23354ab8dc295957dc3009a39bff0/src/PNDP/NixGenerator.php#L156-L162 |
7,304 | svanderburg/pndp | src/PNDP/NixGenerator.php | NixGenerator.phpToIndentedNix | public static function phpToIndentedNix($obj, $indentLevel, $format)
{
$expr = "";
switch(gettype($obj))
{
case "boolean":
$expr .= NixGenerator::booleanToIndentedNix($obj);
break;
case "integer":
$expr .= $obj;
break;
case "double":
$expr .= $obj;
break;
case "string":
$expr .= NixGenerator::stringToIndentedNix($obj);
break;
case "array":
$expr .= NixGenerator::arrayToIndentedNix($obj, $indentLevel, $format);
break;
case "object":
$expr .= NixGenerator::objectToIndentedNix($obj, $indentLevel, $format);
break;
case "resource":
throw new Exception("Cannot convert a resource to a Nix expression");
break;
case "NULL":
$expr .= "null";
break;
case "unknown type":
throw new Exception("Cannot convert object of unknown type: ".$obj);
default:
throw new Exception("Encountered a totally unrecognizable type: ".$obj);
}
return $expr;
} | php | public static function phpToIndentedNix($obj, $indentLevel, $format)
{
$expr = "";
switch(gettype($obj))
{
case "boolean":
$expr .= NixGenerator::booleanToIndentedNix($obj);
break;
case "integer":
$expr .= $obj;
break;
case "double":
$expr .= $obj;
break;
case "string":
$expr .= NixGenerator::stringToIndentedNix($obj);
break;
case "array":
$expr .= NixGenerator::arrayToIndentedNix($obj, $indentLevel, $format);
break;
case "object":
$expr .= NixGenerator::objectToIndentedNix($obj, $indentLevel, $format);
break;
case "resource":
throw new Exception("Cannot convert a resource to a Nix expression");
break;
case "NULL":
$expr .= "null";
break;
case "unknown type":
throw new Exception("Cannot convert object of unknown type: ".$obj);
default:
throw new Exception("Encountered a totally unrecognizable type: ".$obj);
}
return $expr;
} | [
"public",
"static",
"function",
"phpToIndentedNix",
"(",
"$",
"obj",
",",
"$",
"indentLevel",
",",
"$",
"format",
")",
"{",
"$",
"expr",
"=",
"\"\"",
";",
"switch",
"(",
"gettype",
"(",
"$",
"obj",
")",
")",
"{",
"case",
"\"boolean\"",
":",
"$",
"expr",
".=",
"NixGenerator",
"::",
"booleanToIndentedNix",
"(",
"$",
"obj",
")",
";",
"break",
";",
"case",
"\"integer\"",
":",
"$",
"expr",
".=",
"$",
"obj",
";",
"break",
";",
"case",
"\"double\"",
":",
"$",
"expr",
".=",
"$",
"obj",
";",
"break",
";",
"case",
"\"string\"",
":",
"$",
"expr",
".=",
"NixGenerator",
"::",
"stringToIndentedNix",
"(",
"$",
"obj",
")",
";",
"break",
";",
"case",
"\"array\"",
":",
"$",
"expr",
".=",
"NixGenerator",
"::",
"arrayToIndentedNix",
"(",
"$",
"obj",
",",
"$",
"indentLevel",
",",
"$",
"format",
")",
";",
"break",
";",
"case",
"\"object\"",
":",
"$",
"expr",
".=",
"NixGenerator",
"::",
"objectToIndentedNix",
"(",
"$",
"obj",
",",
"$",
"indentLevel",
",",
"$",
"format",
")",
";",
"break",
";",
"case",
"\"resource\"",
":",
"throw",
"new",
"Exception",
"(",
"\"Cannot convert a resource to a Nix expression\"",
")",
";",
"break",
";",
"case",
"\"NULL\"",
":",
"$",
"expr",
".=",
"\"null\"",
";",
"break",
";",
"case",
"\"unknown type\"",
":",
"throw",
"new",
"Exception",
"(",
"\"Cannot convert object of unknown type: \"",
".",
"$",
"obj",
")",
";",
"default",
":",
"throw",
"new",
"Exception",
"(",
"\"Encountered a totally unrecognizable type: \"",
".",
"$",
"obj",
")",
";",
"}",
"return",
"$",
"expr",
";",
"}"
] | Converts a PHP variable of any type to a semantically equivalent or
similar Nix expression language object. It also uses indentation to
format the resulting sub expression more nicely.
@param mixed $obj A variable of any type
@param int $indentLevel Contains the indentation level
@param bool $format Indicates whether to nicely format the generated expression
@return string A string containing the converted Nix expression language object | [
"Converts",
"a",
"PHP",
"variable",
"of",
"any",
"type",
"to",
"a",
"semantically",
"equivalent",
"or",
"similar",
"Nix",
"expression",
"language",
"object",
".",
"It",
"also",
"uses",
"indentation",
"to",
"format",
"the",
"resulting",
"sub",
"expression",
"more",
"nicely",
"."
] | 4bfe9c4120c23354ab8dc295957dc3009a39bff0 | https://github.com/svanderburg/pndp/blob/4bfe9c4120c23354ab8dc295957dc3009a39bff0/src/PNDP/NixGenerator.php#L206-L243 |
7,305 | skgroup/php-rbac | src/Permission.php | Permission.addRuleCallback | public function addRuleCallback($name, Callable $callback)
{
if (!is_string($name)) {
throw new \InvalidArgumentException('Rule must be a string');
}
$rule = $this->createRuleCallback($name, $callback);
$this->addRule($rule);
} | php | public function addRuleCallback($name, Callable $callback)
{
if (!is_string($name)) {
throw new \InvalidArgumentException('Rule must be a string');
}
$rule = $this->createRuleCallback($name, $callback);
$this->addRule($rule);
} | [
"public",
"function",
"addRuleCallback",
"(",
"$",
"name",
",",
"Callable",
"$",
"callback",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Rule must be a string'",
")",
";",
"}",
"$",
"rule",
"=",
"$",
"this",
"->",
"createRuleCallback",
"(",
"$",
"name",
",",
"$",
"callback",
")",
";",
"$",
"this",
"->",
"addRule",
"(",
"$",
"rule",
")",
";",
"}"
] | Adds a rule callback to the Permission.
@param string $name
@param Callable $callback
@return void | [
"Adds",
"a",
"rule",
"callback",
"to",
"the",
"Permission",
"."
] | 89b08cacda9b1376b8f07d16038d2eade6dfb9e8 | https://github.com/skgroup/php-rbac/blob/89b08cacda9b1376b8f07d16038d2eade6dfb9e8/src/Permission.php#L60-L68 |
7,306 | skgroup/php-rbac | src/Permission.php | Permission.revokeRule | public function revokeRule($rule)
{
if ($this->hasRule($rule)) {
unset($this->rules[$rule]);
return true;
} else {
return false;
}
} | php | public function revokeRule($rule)
{
if ($this->hasRule($rule)) {
unset($this->rules[$rule]);
return true;
} else {
return false;
}
} | [
"public",
"function",
"revokeRule",
"(",
"$",
"rule",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasRule",
"(",
"$",
"rule",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"rules",
"[",
"$",
"rule",
"]",
")",
";",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Revokes a rule from the Permission.
@param string $rule
@return bool | [
"Revokes",
"a",
"rule",
"from",
"the",
"Permission",
"."
] | 89b08cacda9b1376b8f07d16038d2eade6dfb9e8 | https://github.com/skgroup/php-rbac/blob/89b08cacda9b1376b8f07d16038d2eade6dfb9e8/src/Permission.php#L102-L110 |
7,307 | skgroup/php-rbac | src/Permission.php | Permission.getRule | public function getRule($name)
{
if ($this->hasRule($name)) {
return $this->rules[$name];
}
throw new \InvalidArgumentException(sprintf('No rule with name "%s" could be found', $name));
} | php | public function getRule($name)
{
if ($this->hasRule($name)) {
return $this->rules[$name];
}
throw new \InvalidArgumentException(sprintf('No rule with name "%s" could be found', $name));
} | [
"public",
"function",
"getRule",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasRule",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"this",
"->",
"rules",
"[",
"$",
"name",
"]",
";",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'No rule with name \"%s\" could be found'",
",",
"$",
"name",
")",
")",
";",
"}"
] | Returns the named rule from the Permission.
@param string $name
@return RuleInterface | [
"Returns",
"the",
"named",
"rule",
"from",
"the",
"Permission",
"."
] | 89b08cacda9b1376b8f07d16038d2eade6dfb9e8 | https://github.com/skgroup/php-rbac/blob/89b08cacda9b1376b8f07d16038d2eade6dfb9e8/src/Permission.php#L118-L125 |
7,308 | skgroup/php-rbac | src/Permission.php | Permission.checkRules | public function checkRules($rules, Array $params = null)
{
if (is_string($rules)) {
$rules = (array)explode(',', $rules);
}
foreach ($rules as $name) {
if (!$this->hasRule($name) || !$this->getRule($name)->execute($this, $params)) {
return false;
}
}
return true;
} | php | public function checkRules($rules, Array $params = null)
{
if (is_string($rules)) {
$rules = (array)explode(',', $rules);
}
foreach ($rules as $name) {
if (!$this->hasRule($name) || !$this->getRule($name)->execute($this, $params)) {
return false;
}
}
return true;
} | [
"public",
"function",
"checkRules",
"(",
"$",
"rules",
",",
"Array",
"$",
"params",
"=",
"null",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"rules",
")",
")",
"{",
"$",
"rules",
"=",
"(",
"array",
")",
"explode",
"(",
"','",
",",
"$",
"rules",
")",
";",
"}",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasRule",
"(",
"$",
"name",
")",
"||",
"!",
"$",
"this",
"->",
"getRule",
"(",
"$",
"name",
")",
"->",
"execute",
"(",
"$",
"this",
",",
"$",
"params",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Checks the rules for the Permission.
@param string|array $rules
@param array $params
@return bool | [
"Checks",
"the",
"rules",
"for",
"the",
"Permission",
"."
] | 89b08cacda9b1376b8f07d16038d2eade6dfb9e8 | https://github.com/skgroup/php-rbac/blob/89b08cacda9b1376b8f07d16038d2eade6dfb9e8/src/Permission.php#L144-L157 |
7,309 | Puzzlout/FrameworkMvcLegacy | src/Core/ResourceManagers/CommonResxBase.php | CommonResxBase.GetValue | public function GetValue($key) {
$resources = $this->GetList();
$keyExist = array_key_exists($key, $resources);
if ($keyExist) {
return $resources[$key][\Puzzlout\Framework\BO\F_common_resource::F_COMMON_RESOURCE_VALUE];
} else {
// throw new \Puzzlout\Framework\Exceptions\ResourceNotFoundException(
// "The resource value doesn't exist for Group => " . $this->GroupValue . " and Key => " . $key, 0, null);
return "???";
}
} | php | public function GetValue($key) {
$resources = $this->GetList();
$keyExist = array_key_exists($key, $resources);
if ($keyExist) {
return $resources[$key][\Puzzlout\Framework\BO\F_common_resource::F_COMMON_RESOURCE_VALUE];
} else {
// throw new \Puzzlout\Framework\Exceptions\ResourceNotFoundException(
// "The resource value doesn't exist for Group => " . $this->GroupValue . " and Key => " . $key, 0, null);
return "???";
}
} | [
"public",
"function",
"GetValue",
"(",
"$",
"key",
")",
"{",
"$",
"resources",
"=",
"$",
"this",
"->",
"GetList",
"(",
")",
";",
"$",
"keyExist",
"=",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"resources",
")",
";",
"if",
"(",
"$",
"keyExist",
")",
"{",
"return",
"$",
"resources",
"[",
"$",
"key",
"]",
"[",
"\\",
"Puzzlout",
"\\",
"Framework",
"\\",
"BO",
"\\",
"F_common_resource",
"::",
"F_COMMON_RESOURCE_VALUE",
"]",
";",
"}",
"else",
"{",
"// throw new \\Puzzlout\\Framework\\Exceptions\\ResourceNotFoundException(",
"// \"The resource value doesn't exist for Group => \" . $this->GroupValue . \" and Key => \" . $key, 0, null);",
"return",
"\"???\"",
";",
"}",
"}"
] | Get the resource value by group and key.
@param string $key the resource key to find
@return string the resource value | [
"Get",
"the",
"resource",
"value",
"by",
"group",
"and",
"key",
"."
] | 14e0fc5b16978cbd209f552ee9c649f66a0dfc6e | https://github.com/Puzzlout/FrameworkMvcLegacy/blob/14e0fc5b16978cbd209f552ee9c649f66a0dfc6e/src/Core/ResourceManagers/CommonResxBase.php#L37-L47 |
7,310 | Puzzlout/FrameworkMvcLegacy | src/Core/ResourceManagers/CommonResxBase.php | CommonResxBase.GetComment | public function GetComment($key) {
$resources = $this->GetList();
$keyExist = array_key_exists($key, $resources);
if ($keyExist) {
return $resources[$key][\Puzzlout\Framework\BO\F_common_resource::F_COMMON_RESOURCE_COMMENT];
} else {
// throw new \Puzzlout\Framework\Exceptions\ResourceNotFoundException(
// "The resource comment doesn't exist for Group => " . $this->GroupValue . " and Key => " . $key, 0, null);
return "???";
}
} | php | public function GetComment($key) {
$resources = $this->GetList();
$keyExist = array_key_exists($key, $resources);
if ($keyExist) {
return $resources[$key][\Puzzlout\Framework\BO\F_common_resource::F_COMMON_RESOURCE_COMMENT];
} else {
// throw new \Puzzlout\Framework\Exceptions\ResourceNotFoundException(
// "The resource comment doesn't exist for Group => " . $this->GroupValue . " and Key => " . $key, 0, null);
return "???";
}
} | [
"public",
"function",
"GetComment",
"(",
"$",
"key",
")",
"{",
"$",
"resources",
"=",
"$",
"this",
"->",
"GetList",
"(",
")",
";",
"$",
"keyExist",
"=",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"resources",
")",
";",
"if",
"(",
"$",
"keyExist",
")",
"{",
"return",
"$",
"resources",
"[",
"$",
"key",
"]",
"[",
"\\",
"Puzzlout",
"\\",
"Framework",
"\\",
"BO",
"\\",
"F_common_resource",
"::",
"F_COMMON_RESOURCE_COMMENT",
"]",
";",
"}",
"else",
"{",
"// throw new \\Puzzlout\\Framework\\Exceptions\\ResourceNotFoundException(",
"// \"The resource comment doesn't exist for Group => \" . $this->GroupValue . \" and Key => \" . $key, 0, null);",
"return",
"\"???\"",
";",
"}",
"}"
] | Get the resource comment by group and key.
@param string $key the resource key to find
@return string the resource comment | [
"Get",
"the",
"resource",
"comment",
"by",
"group",
"and",
"key",
"."
] | 14e0fc5b16978cbd209f552ee9c649f66a0dfc6e | https://github.com/Puzzlout/FrameworkMvcLegacy/blob/14e0fc5b16978cbd209f552ee9c649f66a0dfc6e/src/Core/ResourceManagers/CommonResxBase.php#L55-L65 |
7,311 | remote-office/libx | src/Util/Address.php | Address.toArray | public function toArray()
{
$_address = [];
if($this->hasCountry())
$_address['country'] = $this->getCountry();
if($this->hasState())
$_address['state'] = $this->getState();
if($this->hasMunicipality())
$_address['municipality'] = $this->getMunicipality();
if($this->hasCity())
$_address['city'] = $this->getCity();
if($this->hasDistrict())
$_address['district'] = $this->getDistrict();
if($this->hasNeighbourhood())
$_address['neighbourhood'] = $this->getNeighbourhood();
if($this->hasStreet())
$_address['street'] = $this->getStreet();
if($this->hasNumber())
$_address['number'] = $this->getNumber();
if($this->hasAddition())
$_address['addition'] = $this->getAddition();
if($this->hasZipcode())
$_address['zipcode'] = $this->getZipcode();
return $_address;
} | php | public function toArray()
{
$_address = [];
if($this->hasCountry())
$_address['country'] = $this->getCountry();
if($this->hasState())
$_address['state'] = $this->getState();
if($this->hasMunicipality())
$_address['municipality'] = $this->getMunicipality();
if($this->hasCity())
$_address['city'] = $this->getCity();
if($this->hasDistrict())
$_address['district'] = $this->getDistrict();
if($this->hasNeighbourhood())
$_address['neighbourhood'] = $this->getNeighbourhood();
if($this->hasStreet())
$_address['street'] = $this->getStreet();
if($this->hasNumber())
$_address['number'] = $this->getNumber();
if($this->hasAddition())
$_address['addition'] = $this->getAddition();
if($this->hasZipcode())
$_address['zipcode'] = $this->getZipcode();
return $_address;
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"$",
"_address",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"hasCountry",
"(",
")",
")",
"$",
"_address",
"[",
"'country'",
"]",
"=",
"$",
"this",
"->",
"getCountry",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasState",
"(",
")",
")",
"$",
"_address",
"[",
"'state'",
"]",
"=",
"$",
"this",
"->",
"getState",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasMunicipality",
"(",
")",
")",
"$",
"_address",
"[",
"'municipality'",
"]",
"=",
"$",
"this",
"->",
"getMunicipality",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasCity",
"(",
")",
")",
"$",
"_address",
"[",
"'city'",
"]",
"=",
"$",
"this",
"->",
"getCity",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasDistrict",
"(",
")",
")",
"$",
"_address",
"[",
"'district'",
"]",
"=",
"$",
"this",
"->",
"getDistrict",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasNeighbourhood",
"(",
")",
")",
"$",
"_address",
"[",
"'neighbourhood'",
"]",
"=",
"$",
"this",
"->",
"getNeighbourhood",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasStreet",
"(",
")",
")",
"$",
"_address",
"[",
"'street'",
"]",
"=",
"$",
"this",
"->",
"getStreet",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasNumber",
"(",
")",
")",
"$",
"_address",
"[",
"'number'",
"]",
"=",
"$",
"this",
"->",
"getNumber",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasAddition",
"(",
")",
")",
"$",
"_address",
"[",
"'addition'",
"]",
"=",
"$",
"this",
"->",
"getAddition",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasZipcode",
"(",
")",
")",
"$",
"_address",
"[",
"'zipcode'",
"]",
"=",
"$",
"this",
"->",
"getZipcode",
"(",
")",
";",
"return",
"$",
"_address",
";",
"}"
] | Convert address to array
@param void
@return NULL[] | [
"Convert",
"address",
"to",
"array"
] | 8baeaae99a6110e7c588bc0388df89a0dc0768b5 | https://github.com/remote-office/libx/blob/8baeaae99a6110e7c588bc0388df89a0dc0768b5/src/Util/Address.php#L208-L243 |
7,312 | remote-office/libx | src/Util/Address.php | Address.fromStdClass | public static function fromStdClass($_address)
{
$address = new static();
if(isset($_address->country))
$address->setCountry($_address->country);
if(isset($_address->state))
$address->setState($_address->state);
if(isset($_address->municipality))
$address->setMunicipality($_address->municipality);
if(isset($_address->city))
$address->setCity($_address->city);
if(isset($_address->district))
$address->setDistrict($_address->district);
if(isset($_address->neighbourhood))
$address->setNeighbourhood($_address->neighbourhood);
if(isset($_address->street))
$address->setStreet($_address->street);
if(isset($_address->number))
$address->setNumber($_address->number);
if(isset($_address->addition))
$address->setAddition($_address->addition);
if(isset($_address->zipcode))
$address->setZipcode($_address->zipcode);
return $address;
} | php | public static function fromStdClass($_address)
{
$address = new static();
if(isset($_address->country))
$address->setCountry($_address->country);
if(isset($_address->state))
$address->setState($_address->state);
if(isset($_address->municipality))
$address->setMunicipality($_address->municipality);
if(isset($_address->city))
$address->setCity($_address->city);
if(isset($_address->district))
$address->setDistrict($_address->district);
if(isset($_address->neighbourhood))
$address->setNeighbourhood($_address->neighbourhood);
if(isset($_address->street))
$address->setStreet($_address->street);
if(isset($_address->number))
$address->setNumber($_address->number);
if(isset($_address->addition))
$address->setAddition($_address->addition);
if(isset($_address->zipcode))
$address->setZipcode($_address->zipcode);
return $address;
} | [
"public",
"static",
"function",
"fromStdClass",
"(",
"$",
"_address",
")",
"{",
"$",
"address",
"=",
"new",
"static",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_address",
"->",
"country",
")",
")",
"$",
"address",
"->",
"setCountry",
"(",
"$",
"_address",
"->",
"country",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_address",
"->",
"state",
")",
")",
"$",
"address",
"->",
"setState",
"(",
"$",
"_address",
"->",
"state",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_address",
"->",
"municipality",
")",
")",
"$",
"address",
"->",
"setMunicipality",
"(",
"$",
"_address",
"->",
"municipality",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_address",
"->",
"city",
")",
")",
"$",
"address",
"->",
"setCity",
"(",
"$",
"_address",
"->",
"city",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_address",
"->",
"district",
")",
")",
"$",
"address",
"->",
"setDistrict",
"(",
"$",
"_address",
"->",
"district",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_address",
"->",
"neighbourhood",
")",
")",
"$",
"address",
"->",
"setNeighbourhood",
"(",
"$",
"_address",
"->",
"neighbourhood",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_address",
"->",
"street",
")",
")",
"$",
"address",
"->",
"setStreet",
"(",
"$",
"_address",
"->",
"street",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_address",
"->",
"number",
")",
")",
"$",
"address",
"->",
"setNumber",
"(",
"$",
"_address",
"->",
"number",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_address",
"->",
"addition",
")",
")",
"$",
"address",
"->",
"setAddition",
"(",
"$",
"_address",
"->",
"addition",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_address",
"->",
"zipcode",
")",
")",
"$",
"address",
"->",
"setZipcode",
"(",
"$",
"_address",
"->",
"zipcode",
")",
";",
"return",
"$",
"address",
";",
"}"
] | Convert from StdClass
@param StdClass $_address
@return \LibX\Util\Address | [
"Convert",
"from",
"StdClass"
] | 8baeaae99a6110e7c588bc0388df89a0dc0768b5 | https://github.com/remote-office/libx/blob/8baeaae99a6110e7c588bc0388df89a0dc0768b5/src/Util/Address.php#L251-L286 |
7,313 | vinala/kernel | src/Config/Config.php | Config.getPath | protected static function getPath($param)
{
$path = (is_null(Application::$root) ? "config/$param.php" : Application::$root."config/$param.php");
//
return Bus::need((is_null(Application::$root) ? "config/$param.php" : Application::$root."config/$param.php"));
} | php | protected static function getPath($param)
{
$path = (is_null(Application::$root) ? "config/$param.php" : Application::$root."config/$param.php");
//
return Bus::need((is_null(Application::$root) ? "config/$param.php" : Application::$root."config/$param.php"));
} | [
"protected",
"static",
"function",
"getPath",
"(",
"$",
"param",
")",
"{",
"$",
"path",
"=",
"(",
"is_null",
"(",
"Application",
"::",
"$",
"root",
")",
"?",
"\"config/$param.php\"",
":",
"Application",
"::",
"$",
"root",
".",
"\"config/$param.php\"",
")",
";",
"//",
"return",
"Bus",
"::",
"need",
"(",
"(",
"is_null",
"(",
"Application",
"::",
"$",
"root",
")",
"?",
"\"config/$param.php\"",
":",
"Application",
"::",
"$",
"root",
".",
"\"config/$param.php\"",
")",
")",
";",
"}"
] | get path of config files.
@param $param(string) : file name | [
"get",
"path",
"of",
"config",
"files",
"."
] | 346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a | https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/Config/Config.php#L26-L31 |
7,314 | vinala/kernel | src/Config/Config.php | Config.load | public static function load($kernelTest = false)
{
if ($kernelTest) {
return self::mock();
} else {
$levels = self::getFirstLevel();
//
foreach ($levels as $level) {
self::$params[$level] = self::getPath($level);
}
//
return true;
}
} | php | public static function load($kernelTest = false)
{
if ($kernelTest) {
return self::mock();
} else {
$levels = self::getFirstLevel();
//
foreach ($levels as $level) {
self::$params[$level] = self::getPath($level);
}
//
return true;
}
} | [
"public",
"static",
"function",
"load",
"(",
"$",
"kernelTest",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"kernelTest",
")",
"{",
"return",
"self",
"::",
"mock",
"(",
")",
";",
"}",
"else",
"{",
"$",
"levels",
"=",
"self",
"::",
"getFirstLevel",
"(",
")",
";",
"//",
"foreach",
"(",
"$",
"levels",
"as",
"$",
"level",
")",
"{",
"self",
"::",
"$",
"params",
"[",
"$",
"level",
"]",
"=",
"self",
"::",
"getPath",
"(",
"$",
"level",
")",
";",
"}",
"//",
"return",
"true",
";",
"}",
"}"
] | load all params from file to virtual array. | [
"load",
"all",
"params",
"from",
"file",
"to",
"virtual",
"array",
"."
] | 346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a | https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/Config/Config.php#L56-L69 |
7,315 | vinala/kernel | src/Config/Config.php | Config.check | public static function check($param, $default = false)
{
$p = self::separate($param);
//
if ($p['first'] == 'database') {
self::checkDatabase($p['second']);
}
//
else {
if (!in_array($p['first'], self::getFirstLevel())) {
if (!$default) {
self::exception($p['first'], $p['second']);
}
return true;
} elseif (!array_key_exists($p['second'], self::$params[$p['first']])) {
if (!$default) {
self::exception($p['first'], $p['second']);
}
return true;
}
}
//
return true;
} | php | public static function check($param, $default = false)
{
$p = self::separate($param);
//
if ($p['first'] == 'database') {
self::checkDatabase($p['second']);
}
//
else {
if (!in_array($p['first'], self::getFirstLevel())) {
if (!$default) {
self::exception($p['first'], $p['second']);
}
return true;
} elseif (!array_key_exists($p['second'], self::$params[$p['first']])) {
if (!$default) {
self::exception($p['first'], $p['second']);
}
return true;
}
}
//
return true;
} | [
"public",
"static",
"function",
"check",
"(",
"$",
"param",
",",
"$",
"default",
"=",
"false",
")",
"{",
"$",
"p",
"=",
"self",
"::",
"separate",
"(",
"$",
"param",
")",
";",
"//",
"if",
"(",
"$",
"p",
"[",
"'first'",
"]",
"==",
"'database'",
")",
"{",
"self",
"::",
"checkDatabase",
"(",
"$",
"p",
"[",
"'second'",
"]",
")",
";",
"}",
"//",
"else",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"p",
"[",
"'first'",
"]",
",",
"self",
"::",
"getFirstLevel",
"(",
")",
")",
")",
"{",
"if",
"(",
"!",
"$",
"default",
")",
"{",
"self",
"::",
"exception",
"(",
"$",
"p",
"[",
"'first'",
"]",
",",
"$",
"p",
"[",
"'second'",
"]",
")",
";",
"}",
"return",
"true",
";",
"}",
"elseif",
"(",
"!",
"array_key_exists",
"(",
"$",
"p",
"[",
"'second'",
"]",
",",
"self",
"::",
"$",
"params",
"[",
"$",
"p",
"[",
"'first'",
"]",
"]",
")",
")",
"{",
"if",
"(",
"!",
"$",
"default",
")",
"{",
"self",
"::",
"exception",
"(",
"$",
"p",
"[",
"'first'",
"]",
",",
"$",
"p",
"[",
"'second'",
"]",
")",
";",
"}",
"return",
"true",
";",
"}",
"}",
"//",
"return",
"true",
";",
"}"
] | check if parameter exists.
@param $param(string) primary and secondary parameter concatenated | [
"check",
"if",
"parameter",
"exists",
"."
] | 346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a | https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/Config/Config.php#L87-L112 |
7,316 | vinala/kernel | src/Config/Config.php | Config.reach | protected static function reach($param, $default = null)
{
$p = self::separate($param);
//
if ($p['first'] == 'database') {
return self::callDatabase($p['second']);
}
return array_get(self::$params, $param, $default);
} | php | protected static function reach($param, $default = null)
{
$p = self::separate($param);
//
if ($p['first'] == 'database') {
return self::callDatabase($p['second']);
}
return array_get(self::$params, $param, $default);
} | [
"protected",
"static",
"function",
"reach",
"(",
"$",
"param",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"p",
"=",
"self",
"::",
"separate",
"(",
"$",
"param",
")",
";",
"//",
"if",
"(",
"$",
"p",
"[",
"'first'",
"]",
"==",
"'database'",
")",
"{",
"return",
"self",
"::",
"callDatabase",
"(",
"$",
"p",
"[",
"'second'",
"]",
")",
";",
"}",
"return",
"array_get",
"(",
"self",
"::",
"$",
"params",
",",
"$",
"param",
",",
"$",
"default",
")",
";",
"}"
] | find request parameter.
@param $param(string) primary and secondary parameter concatenated | [
"find",
"request",
"parameter",
"."
] | 346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a | https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/Config/Config.php#L131-L140 |
7,317 | vinala/kernel | src/Config/Config.php | Config.checkDatabase | protected static function checkDatabase($key)
{
$driver = self::$params['database']['default'];
//
if (array_key_exists($key, self::$params['database'])) {
return true;
} elseif (array_key_exists($key, self::$params['database']['connections'][$driver])) {
return true;
} else {
self::exception('database', $key);
}
} | php | protected static function checkDatabase($key)
{
$driver = self::$params['database']['default'];
//
if (array_key_exists($key, self::$params['database'])) {
return true;
} elseif (array_key_exists($key, self::$params['database']['connections'][$driver])) {
return true;
} else {
self::exception('database', $key);
}
} | [
"protected",
"static",
"function",
"checkDatabase",
"(",
"$",
"key",
")",
"{",
"$",
"driver",
"=",
"self",
"::",
"$",
"params",
"[",
"'database'",
"]",
"[",
"'default'",
"]",
";",
"//",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"self",
"::",
"$",
"params",
"[",
"'database'",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"elseif",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"self",
"::",
"$",
"params",
"[",
"'database'",
"]",
"[",
"'connections'",
"]",
"[",
"$",
"driver",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"self",
"::",
"exception",
"(",
"'database'",
",",
"$",
"key",
")",
";",
"}",
"}"
] | check if secondary parameter exists if primary parameter is 'database'.
@param $key(string) primary and secondary parameter concatenated | [
"check",
"if",
"secondary",
"parameter",
"exists",
"if",
"primary",
"parameter",
"is",
"database",
"."
] | 346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a | https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/Config/Config.php#L147-L158 |
7,318 | vinala/kernel | src/Config/Config.php | Config.callDatabase | protected static function callDatabase($key)
{
$params = ['migration', 'prefixing', 'prefixe', 'default'];
$data = self::$params['database'];
$driver = $data['default'];
//
exception_if(!array_has($data['connections'], $driver), DatabaseDriverNotFoundException::class, $driver);
//
return (!in_array($key, $params)) ? $data['connections'][$driver][$key] : $data[$key];
} | php | protected static function callDatabase($key)
{
$params = ['migration', 'prefixing', 'prefixe', 'default'];
$data = self::$params['database'];
$driver = $data['default'];
//
exception_if(!array_has($data['connections'], $driver), DatabaseDriverNotFoundException::class, $driver);
//
return (!in_array($key, $params)) ? $data['connections'][$driver][$key] : $data[$key];
} | [
"protected",
"static",
"function",
"callDatabase",
"(",
"$",
"key",
")",
"{",
"$",
"params",
"=",
"[",
"'migration'",
",",
"'prefixing'",
",",
"'prefixe'",
",",
"'default'",
"]",
";",
"$",
"data",
"=",
"self",
"::",
"$",
"params",
"[",
"'database'",
"]",
";",
"$",
"driver",
"=",
"$",
"data",
"[",
"'default'",
"]",
";",
"//",
"exception_if",
"(",
"!",
"array_has",
"(",
"$",
"data",
"[",
"'connections'",
"]",
",",
"$",
"driver",
")",
",",
"DatabaseDriverNotFoundException",
"::",
"class",
",",
"$",
"driver",
")",
";",
"//",
"return",
"(",
"!",
"in_array",
"(",
"$",
"key",
",",
"$",
"params",
")",
")",
"?",
"$",
"data",
"[",
"'connections'",
"]",
"[",
"$",
"driver",
"]",
"[",
"$",
"key",
"]",
":",
"$",
"data",
"[",
"$",
"key",
"]",
";",
"}"
] | find request parameter if primary parameter is 'database'.
@param $key(string) secondary parameter concatenated | [
"find",
"request",
"parameter",
"if",
"primary",
"parameter",
"is",
"database",
"."
] | 346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a | https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/Config/Config.php#L165-L174 |
7,319 | vinala/kernel | src/Config/Config.php | Config.get | public static function get($key, $value = null)
{
if (self::check($key, !is_null($value))) {
return self::reach($key, $value);
}
static::set($key, $value);
return $value;
} | php | public static function get($key, $value = null)
{
if (self::check($key, !is_null($value))) {
return self::reach($key, $value);
}
static::set($key, $value);
return $value;
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"key",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"self",
"::",
"check",
"(",
"$",
"key",
",",
"!",
"is_null",
"(",
"$",
"value",
")",
")",
")",
"{",
"return",
"self",
"::",
"reach",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"static",
"::",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"return",
"$",
"value",
";",
"}"
] | get value of config parameter.
@param $value(string) primary and secondary parameter concatenated | [
"get",
"value",
"of",
"config",
"parameter",
"."
] | 346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a | https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/Config/Config.php#L181-L190 |
7,320 | GrupaZero/core | src/Gzero/Core/Policies/UserPolicy.php | UserPolicy.delete | public function delete(User $user, User $entity)
{
if ($entity->id === $user->id) {
return true;
}
return $user->hasPermission('user-delete');
} | php | public function delete(User $user, User $entity)
{
if ($entity->id === $user->id) {
return true;
}
return $user->hasPermission('user-delete');
} | [
"public",
"function",
"delete",
"(",
"User",
"$",
"user",
",",
"User",
"$",
"entity",
")",
"{",
"if",
"(",
"$",
"entity",
"->",
"id",
"===",
"$",
"user",
"->",
"id",
")",
"{",
"return",
"true",
";",
"}",
"return",
"$",
"user",
"->",
"hasPermission",
"(",
"'user-delete'",
")",
";",
"}"
] | Policy for deleting single element
@param User $user User trying to do it
@param User $entity User that we're trying to update
@return boolean | [
"Policy",
"for",
"deleting",
"single",
"element"
] | 093e515234fa0385b259ba4d8bc7832174a44eab | https://github.com/GrupaZero/core/blob/093e515234fa0385b259ba4d8bc7832174a44eab/src/Gzero/Core/Policies/UserPolicy.php#L71-L77 |
7,321 | phapi/serializer | src/Phapi/Serializer/Deserializer.php | Deserializer.getContentType | protected function getContentType(ServerRequestInterface $request)
{
// Check for an attribute
if (null !== $accept = $request->getAttribute('Content-Type', null)) {
return $accept;
}
// Check for an accept header
if ($request->hasHeader('Content-Type')) {
return $request->getHeaderLine('Content-Type');
}
return null;
} | php | protected function getContentType(ServerRequestInterface $request)
{
// Check for an attribute
if (null !== $accept = $request->getAttribute('Content-Type', null)) {
return $accept;
}
// Check for an accept header
if ($request->hasHeader('Content-Type')) {
return $request->getHeaderLine('Content-Type');
}
return null;
} | [
"protected",
"function",
"getContentType",
"(",
"ServerRequestInterface",
"$",
"request",
")",
"{",
"// Check for an attribute",
"if",
"(",
"null",
"!==",
"$",
"accept",
"=",
"$",
"request",
"->",
"getAttribute",
"(",
"'Content-Type'",
",",
"null",
")",
")",
"{",
"return",
"$",
"accept",
";",
"}",
"// Check for an accept header",
"if",
"(",
"$",
"request",
"->",
"hasHeader",
"(",
"'Content-Type'",
")",
")",
"{",
"return",
"$",
"request",
"->",
"getHeaderLine",
"(",
"'Content-Type'",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Get content type from request. First check for an attribute. An attribute
is usually set if content negotiation are done.
If no attribute can be found, use the content type header.
@param ServerRequestInterface $request
@return mixed|null|string | [
"Get",
"content",
"type",
"from",
"request",
".",
"First",
"check",
"for",
"an",
"attribute",
".",
"An",
"attribute",
"is",
"usually",
"set",
"if",
"content",
"negotiation",
"are",
"done",
"."
] | 231b85de75f8e3bcf4907751110639bf8b6d7982 | https://github.com/phapi/serializer/blob/231b85de75f8e3bcf4907751110639bf8b6d7982/src/Phapi/Serializer/Deserializer.php#L126-L139 |
7,322 | mvccore/ext-form | src/MvcCore/Ext/Forms/Validator.php | Validator.& | public static function & CreateInstance (array $constructorConfig = []) {
$validator = new static($constructorConfig);
$validator::$toolClass = \MvcCore\Application::GetInstance()->GetToolClass();
return $validator;
} | php | public static function & CreateInstance (array $constructorConfig = []) {
$validator = new static($constructorConfig);
$validator::$toolClass = \MvcCore\Application::GetInstance()->GetToolClass();
return $validator;
} | [
"public",
"static",
"function",
"&",
"CreateInstance",
"(",
"array",
"$",
"constructorConfig",
"=",
"[",
"]",
")",
"{",
"$",
"validator",
"=",
"new",
"static",
"(",
"$",
"constructorConfig",
")",
";",
"$",
"validator",
"::",
"$",
"toolClass",
"=",
"\\",
"MvcCore",
"\\",
"Application",
"::",
"GetInstance",
"(",
")",
"->",
"GetToolClass",
"(",
")",
";",
"return",
"$",
"validator",
";",
"}"
] | Create every time new validator instance with configured form instance. No singleton.
@param array $constructorConfig Configuration arguments for constructor,
validator's constructor first param.
@return \MvcCore\Ext\Forms\Validator|\MvcCore\Ext\Forms\IValidator | [
"Create",
"every",
"time",
"new",
"validator",
"instance",
"with",
"configured",
"form",
"instance",
".",
"No",
"singleton",
"."
] | 8d81a3c7326236702f37dc4b9d968907b3230b9f | https://github.com/mvccore/ext-form/blob/8d81a3c7326236702f37dc4b9d968907b3230b9f/src/MvcCore/Ext/Forms/Validator.php#L80-L84 |
7,323 | mvccore/ext-form | src/MvcCore/Ext/Forms/Validator.php | Validator.throwNewInvalidArgumentException | protected function throwNewInvalidArgumentException ($errorMsg) {
$msgs = [];
if ($this->field)
$msgs[] = 'Field name: `'.$this->field->GetName() . '`, Field type: `'.get_class($this->field).'`';
if ($this->form)
$msgs[] = 'Form id: `'.$this->form->GetId() . '`, Form type: `'.get_class($this->form).'`';
$selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__;
throw new \InvalidArgumentException(
'['.$selfClass.'] ' . $errorMsg . ($msgs ? ' '.implode(', ', $msgs) : '')
);
} | php | protected function throwNewInvalidArgumentException ($errorMsg) {
$msgs = [];
if ($this->field)
$msgs[] = 'Field name: `'.$this->field->GetName() . '`, Field type: `'.get_class($this->field).'`';
if ($this->form)
$msgs[] = 'Form id: `'.$this->form->GetId() . '`, Form type: `'.get_class($this->form).'`';
$selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__;
throw new \InvalidArgumentException(
'['.$selfClass.'] ' . $errorMsg . ($msgs ? ' '.implode(', ', $msgs) : '')
);
} | [
"protected",
"function",
"throwNewInvalidArgumentException",
"(",
"$",
"errorMsg",
")",
"{",
"$",
"msgs",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"field",
")",
"$",
"msgs",
"[",
"]",
"=",
"'Field name: `'",
".",
"$",
"this",
"->",
"field",
"->",
"GetName",
"(",
")",
".",
"'`, Field type: `'",
".",
"get_class",
"(",
"$",
"this",
"->",
"field",
")",
".",
"'`'",
";",
"if",
"(",
"$",
"this",
"->",
"form",
")",
"$",
"msgs",
"[",
"]",
"=",
"'Form id: `'",
".",
"$",
"this",
"->",
"form",
"->",
"GetId",
"(",
")",
".",
"'`, Form type: `'",
".",
"get_class",
"(",
"$",
"this",
"->",
"form",
")",
".",
"'`'",
";",
"$",
"selfClass",
"=",
"version_compare",
"(",
"PHP_VERSION",
",",
"'5.5'",
",",
"'>'",
")",
"?",
"self",
"::",
"class",
":",
"__CLASS__",
";",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'['",
".",
"$",
"selfClass",
".",
"'] '",
".",
"$",
"errorMsg",
".",
"(",
"$",
"msgs",
"?",
"' '",
".",
"implode",
"(",
"', '",
",",
"$",
"msgs",
")",
":",
"''",
")",
")",
";",
"}"
] | Throw new `\InvalidArgumentException` with given
error message and append automatically current class,
field name, form id, field class name and form class name.
@param string $errorMsg
@throws \InvalidArgumentException | [
"Throw",
"new",
"\\",
"InvalidArgumentException",
"with",
"given",
"error",
"message",
"and",
"append",
"automatically",
"current",
"class",
"field",
"name",
"form",
"id",
"field",
"class",
"name",
"and",
"form",
"class",
"name",
"."
] | 8d81a3c7326236702f37dc4b9d968907b3230b9f | https://github.com/mvccore/ext-form/blob/8d81a3c7326236702f37dc4b9d968907b3230b9f/src/MvcCore/Ext/Forms/Validator.php#L160-L170 |
7,324 | slickframework/mvc | src/Controller/EntityBasedMethods.php | EntityBasedMethods.getEntity | protected function getEntity($entityId)
{
$entity = $this->getRepository()->get($entityId);
if (!$entity instanceof EntityInterface) {
throw new EntityNotFoundException(
"There are no entities with provided entity ID."
);
}
return $entity;
} | php | protected function getEntity($entityId)
{
$entity = $this->getRepository()->get($entityId);
if (!$entity instanceof EntityInterface) {
throw new EntityNotFoundException(
"There are no entities with provided entity ID."
);
}
return $entity;
} | [
"protected",
"function",
"getEntity",
"(",
"$",
"entityId",
")",
"{",
"$",
"entity",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"get",
"(",
"$",
"entityId",
")",
";",
"if",
"(",
"!",
"$",
"entity",
"instanceof",
"EntityInterface",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"\"There are no entities with provided entity ID.\"",
")",
";",
"}",
"return",
"$",
"entity",
";",
"}"
] | Gets entity with provided primary key
@param mixed $entityId
@return EntityInterface
@throws EntityNotFoundException If no entity was found with
provided primary key | [
"Gets",
"entity",
"with",
"provided",
"primary",
"key"
] | 91a6c512f8aaa5a7fb9c1a96f8012d2274dc30ab | https://github.com/slickframework/mvc/blob/91a6c512f8aaa5a7fb9c1a96f8012d2274dc30ab/src/Controller/EntityBasedMethods.php#L47-L56 |
7,325 | youlweb/_Chain_ | src/Operator/_OR_.php | _OR_.EXE | public function EXE(I_O $IO)
{
while (true) {
try {
if (true === $IO->I_(Type::BOOL)) {
return $IO->_O(true);
}
} catch (I_O_InputIndexException $e) {
break;
}
}
return $IO->_O(false);
} | php | public function EXE(I_O $IO)
{
while (true) {
try {
if (true === $IO->I_(Type::BOOL)) {
return $IO->_O(true);
}
} catch (I_O_InputIndexException $e) {
break;
}
}
return $IO->_O(false);
} | [
"public",
"function",
"EXE",
"(",
"I_O",
"$",
"IO",
")",
"{",
"while",
"(",
"true",
")",
"{",
"try",
"{",
"if",
"(",
"true",
"===",
"$",
"IO",
"->",
"I_",
"(",
"Type",
"::",
"BOOL",
")",
")",
"{",
"return",
"$",
"IO",
"->",
"_O",
"(",
"true",
")",
";",
"}",
"}",
"catch",
"(",
"I_O_InputIndexException",
"$",
"e",
")",
"{",
"break",
";",
"}",
"}",
"return",
"$",
"IO",
"->",
"_O",
"(",
"false",
")",
";",
"}"
] | Applies the OR operator to the input values.
I/O contract
------------
<pre>
I bool
... bool
O bool Result of the OR operation.
X no
</pre>
@param I_O $IO
@return I_O | [
"Applies",
"the",
"OR",
"operator",
"to",
"the",
"input",
"values",
"."
] | 6ac1b8c0d5a056ab1a7ff3cc521f1a246a9ffed2 | https://github.com/youlweb/_Chain_/blob/6ac1b8c0d5a056ab1a7ff3cc521f1a246a9ffed2/src/Operator/_OR_.php#L38-L50 |
7,326 | artscorestudio/layout-bundle | Twig/FlashMessagesExtension.php | FlashMessagesExtension.flashMessages | public function flashMessages($environment, array $options = array())
{
$params = array_merge(array(
'close_button' => true, 'trans_domain' => null,
), $options);
$template = $environment->loadTemplate('ASFLayoutBundle:session:flash-messages.html.twig');
return $template->renderBlock('flash_messages', array_merge($environment->getGlobals(), $params));
} | php | public function flashMessages($environment, array $options = array())
{
$params = array_merge(array(
'close_button' => true, 'trans_domain' => null,
), $options);
$template = $environment->loadTemplate('ASFLayoutBundle:session:flash-messages.html.twig');
return $template->renderBlock('flash_messages', array_merge($environment->getGlobals(), $params));
} | [
"public",
"function",
"flashMessages",
"(",
"$",
"environment",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"params",
"=",
"array_merge",
"(",
"array",
"(",
"'close_button'",
"=>",
"true",
",",
"'trans_domain'",
"=>",
"null",
",",
")",
",",
"$",
"options",
")",
";",
"$",
"template",
"=",
"$",
"environment",
"->",
"loadTemplate",
"(",
"'ASFLayoutBundle:session:flash-messages.html.twig'",
")",
";",
"return",
"$",
"template",
"->",
"renderBlock",
"(",
"'flash_messages'",
",",
"array_merge",
"(",
"$",
"environment",
"->",
"getGlobals",
"(",
")",
",",
"$",
"params",
")",
")",
";",
"}"
] | Return HTML of flash messages according to flash-messages.html.twig.
@param \Twig_Environment $environment
@param array $options
- button_close : display a close button
- trans_domain set the domain for translation
@return string | [
"Return",
"HTML",
"of",
"flash",
"messages",
"according",
"to",
"flash",
"-",
"messages",
".",
"html",
".",
"twig",
"."
] | 5ccd5f4a133e8af90fb2c46e1f68b6bcb4b66740 | https://github.com/artscorestudio/layout-bundle/blob/5ccd5f4a133e8af90fb2c46e1f68b6bcb4b66740/Twig/FlashMessagesExtension.php#L45-L54 |
7,327 | weew/console | src/Weew/Console/OutputBuffer.php | OutputBuffer.write | public function write($string) {
if ( ! is_array($string)) {
$string = [$string];
}
foreach ($string as $item) {
$this->buffer .= $item;
}
} | php | public function write($string) {
if ( ! is_array($string)) {
$string = [$string];
}
foreach ($string as $item) {
$this->buffer .= $item;
}
} | [
"public",
"function",
"write",
"(",
"$",
"string",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"string",
")",
")",
"{",
"$",
"string",
"=",
"[",
"$",
"string",
"]",
";",
"}",
"foreach",
"(",
"$",
"string",
"as",
"$",
"item",
")",
"{",
"$",
"this",
"->",
"buffer",
".=",
"$",
"item",
";",
"}",
"}"
] | Add a string to buffer.
@param string $string | [
"Add",
"a",
"string",
"to",
"buffer",
"."
] | 083703f21fdeff3cfe6036ebd21ab9cb84ca74c7 | https://github.com/weew/console/blob/083703f21fdeff3cfe6036ebd21ab9cb84ca74c7/src/Weew/Console/OutputBuffer.php#L16-L24 |
7,328 | weew/console | src/Weew/Console/OutputBuffer.php | OutputBuffer.slice | public function slice($from, $length = null) {
if ($length === null) {
return substr($this->buffer, $from);
}
return substr($this->buffer, $from, $length);
} | php | public function slice($from, $length = null) {
if ($length === null) {
return substr($this->buffer, $from);
}
return substr($this->buffer, $from, $length);
} | [
"public",
"function",
"slice",
"(",
"$",
"from",
",",
"$",
"length",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"length",
"===",
"null",
")",
"{",
"return",
"substr",
"(",
"$",
"this",
"->",
"buffer",
",",
"$",
"from",
")",
";",
"}",
"return",
"substr",
"(",
"$",
"this",
"->",
"buffer",
",",
"$",
"from",
",",
"$",
"length",
")",
";",
"}"
] | Get a slice from the buffer.
@param int $from
@param int $length
@return string|false | [
"Get",
"a",
"slice",
"from",
"the",
"buffer",
"."
] | 083703f21fdeff3cfe6036ebd21ab9cb84ca74c7 | https://github.com/weew/console/blob/083703f21fdeff3cfe6036ebd21ab9cb84ca74c7/src/Weew/Console/OutputBuffer.php#L34-L40 |
7,329 | calgamo/util | src/Util.php | Util.dumpBacktrace | public static function dumpBacktrace(array $backtraces, string $format = "[%INDEX%]%CLASS%%TYPE%%FUNCTION%() in %FILE%(%LINE%)")
{
self::walkBacktrace($backtraces, function($index, $file, $line, $class, $type, $func) use($format){
$line = strtr($format, [
'%INDEX%' => $index + 1,
'%FILE%' => $file,
'%LINE%' => $line,
'%CLASS%' => $class,
'%TYPE%' => $type,
'%FUNCTION%' => $func,
]);
echo $line . PHP_EOL;
});
} | php | public static function dumpBacktrace(array $backtraces, string $format = "[%INDEX%]%CLASS%%TYPE%%FUNCTION%() in %FILE%(%LINE%)")
{
self::walkBacktrace($backtraces, function($index, $file, $line, $class, $type, $func) use($format){
$line = strtr($format, [
'%INDEX%' => $index + 1,
'%FILE%' => $file,
'%LINE%' => $line,
'%CLASS%' => $class,
'%TYPE%' => $type,
'%FUNCTION%' => $func,
]);
echo $line . PHP_EOL;
});
} | [
"public",
"static",
"function",
"dumpBacktrace",
"(",
"array",
"$",
"backtraces",
",",
"string",
"$",
"format",
"=",
"\"[%INDEX%]%CLASS%%TYPE%%FUNCTION%() in %FILE%(%LINE%)\"",
")",
"{",
"self",
"::",
"walkBacktrace",
"(",
"$",
"backtraces",
",",
"function",
"(",
"$",
"index",
",",
"$",
"file",
",",
"$",
"line",
",",
"$",
"class",
",",
"$",
"type",
",",
"$",
"func",
")",
"use",
"(",
"$",
"format",
")",
"{",
"$",
"line",
"=",
"strtr",
"(",
"$",
"format",
",",
"[",
"'%INDEX%'",
"=>",
"$",
"index",
"+",
"1",
",",
"'%FILE%'",
"=>",
"$",
"file",
",",
"'%LINE%'",
"=>",
"$",
"line",
",",
"'%CLASS%'",
"=>",
"$",
"class",
",",
"'%TYPE%'",
"=>",
"$",
"type",
",",
"'%FUNCTION%'",
"=>",
"$",
"func",
",",
"]",
")",
";",
"echo",
"$",
"line",
".",
"PHP_EOL",
";",
"}",
")",
";",
"}"
] | Dump back traces
@param array $backtraces
@param string $format | [
"Dump",
"back",
"traces"
] | 13ef5caf3d4cce423854a0cb8fb8010c0d40326a | https://github.com/calgamo/util/blob/13ef5caf3d4cce423854a0cb8fb8010c0d40326a/src/Util.php#L72-L85 |
7,330 | calgamo/util | src/Util.php | Util.walkBacktrace | public static function walkBacktrace($backtraces, callable $callback)
{
foreach($backtraces as $index => $item){
$func = $item['function'] ?? '';
$class = $item['class'] ?? '';
$type = $item['type'] ?? '';
$file = $item['file'] ?? '';
$line = $item['line'] ?? '';
($callback)($index, $file, $line, $class, $type, $func);
}
} | php | public static function walkBacktrace($backtraces, callable $callback)
{
foreach($backtraces as $index => $item){
$func = $item['function'] ?? '';
$class = $item['class'] ?? '';
$type = $item['type'] ?? '';
$file = $item['file'] ?? '';
$line = $item['line'] ?? '';
($callback)($index, $file, $line, $class, $type, $func);
}
} | [
"public",
"static",
"function",
"walkBacktrace",
"(",
"$",
"backtraces",
",",
"callable",
"$",
"callback",
")",
"{",
"foreach",
"(",
"$",
"backtraces",
"as",
"$",
"index",
"=>",
"$",
"item",
")",
"{",
"$",
"func",
"=",
"$",
"item",
"[",
"'function'",
"]",
"??",
"''",
";",
"$",
"class",
"=",
"$",
"item",
"[",
"'class'",
"]",
"??",
"''",
";",
"$",
"type",
"=",
"$",
"item",
"[",
"'type'",
"]",
"??",
"''",
";",
"$",
"file",
"=",
"$",
"item",
"[",
"'file'",
"]",
"??",
"''",
";",
"$",
"line",
"=",
"$",
"item",
"[",
"'line'",
"]",
"??",
"''",
";",
"(",
"$",
"callback",
")",
"(",
"$",
"index",
",",
"$",
"file",
",",
"$",
"line",
",",
"$",
"class",
",",
"$",
"type",
",",
"$",
"func",
")",
";",
"}",
"}"
] | Walk back traces
@param array|\Traversable $backtraces
@param callable $callback | [
"Walk",
"back",
"traces"
] | 13ef5caf3d4cce423854a0cb8fb8010c0d40326a | https://github.com/calgamo/util/blob/13ef5caf3d4cce423854a0cb8fb8010c0d40326a/src/Util.php#L93-L103 |
7,331 | calgamo/util | src/Util.php | Util.isBitSet | public static function isBitSet( int $target, int $flag, int $mode ) : bool
{
switch($mode){
case self::BITTEST_MODE_ALL:
return ($target & $flag) === $flag;
break;
case self::BITTEST_MODE_ANY:
return ($target & $flag) != 0;
}
return false;
} | php | public static function isBitSet( int $target, int $flag, int $mode ) : bool
{
switch($mode){
case self::BITTEST_MODE_ALL:
return ($target & $flag) === $flag;
break;
case self::BITTEST_MODE_ANY:
return ($target & $flag) != 0;
}
return false;
} | [
"public",
"static",
"function",
"isBitSet",
"(",
"int",
"$",
"target",
",",
"int",
"$",
"flag",
",",
"int",
"$",
"mode",
")",
":",
"bool",
"{",
"switch",
"(",
"$",
"mode",
")",
"{",
"case",
"self",
"::",
"BITTEST_MODE_ALL",
":",
"return",
"(",
"$",
"target",
"&",
"$",
"flag",
")",
"===",
"$",
"flag",
";",
"break",
";",
"case",
"self",
"::",
"BITTEST_MODE_ANY",
":",
"return",
"(",
"$",
"target",
"&",
"$",
"flag",
")",
"!=",
"0",
";",
"}",
"return",
"false",
";",
"}"
] | Test if specified bit flag is set
@param int $target target value to test
@param int $flag target flag to test
@param int $mode test mode(see BITTEST_MODE_XXX constants)
@return bool | [
"Test",
"if",
"specified",
"bit",
"flag",
"is",
"set"
] | 13ef5caf3d4cce423854a0cb8fb8010c0d40326a | https://github.com/calgamo/util/blob/13ef5caf3d4cce423854a0cb8fb8010c0d40326a/src/Util.php#L145-L156 |
7,332 | calgamo/util | src/Util.php | Util.formatByteSize | public static function formatByteSize( $size, $precision = 1, $symbols = NULL )
{
if ( $symbols === NULL ){
$symbols = array('B', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb');
}
$i=0;
while (($size/1024)>1) {
$size=$size/1024;
$i++;
}
return (round($size,$precision)." ".$symbols[$i]);
} | php | public static function formatByteSize( $size, $precision = 1, $symbols = NULL )
{
if ( $symbols === NULL ){
$symbols = array('B', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb');
}
$i=0;
while (($size/1024)>1) {
$size=$size/1024;
$i++;
}
return (round($size,$precision)." ".$symbols[$i]);
} | [
"public",
"static",
"function",
"formatByteSize",
"(",
"$",
"size",
",",
"$",
"precision",
"=",
"1",
",",
"$",
"symbols",
"=",
"NULL",
")",
"{",
"if",
"(",
"$",
"symbols",
"===",
"NULL",
")",
"{",
"$",
"symbols",
"=",
"array",
"(",
"'B'",
",",
"'Kb'",
",",
"'Mb'",
",",
"'Gb'",
",",
"'Tb'",
",",
"'Pb'",
")",
";",
"}",
"$",
"i",
"=",
"0",
";",
"while",
"(",
"(",
"$",
"size",
"/",
"1024",
")",
">",
"1",
")",
"{",
"$",
"size",
"=",
"$",
"size",
"/",
"1024",
";",
"$",
"i",
"++",
";",
"}",
"return",
"(",
"round",
"(",
"$",
"size",
",",
"$",
"precision",
")",
".",
"\" \"",
".",
"$",
"symbols",
"[",
"$",
"i",
"]",
")",
";",
"}"
] | format byte size
@param int $size
@param int $precision
@param array $symbols
@return string | [
"format",
"byte",
"size"
] | 13ef5caf3d4cce423854a0cb8fb8010c0d40326a | https://github.com/calgamo/util/blob/13ef5caf3d4cce423854a0cb8fb8010c0d40326a/src/Util.php#L218-L229 |
7,333 | calgamo/util | src/Util.php | Util.hash | public static function hash( string $algo = 'sha1', string $data = NULL )
{
if (!$data){
$data = microtime().uniqid(mt_rand(),1);
}
return hash( $algo, $data );
} | php | public static function hash( string $algo = 'sha1', string $data = NULL )
{
if (!$data){
$data = microtime().uniqid(mt_rand(),1);
}
return hash( $algo, $data );
} | [
"public",
"static",
"function",
"hash",
"(",
"string",
"$",
"algo",
"=",
"'sha1'",
",",
"string",
"$",
"data",
"=",
"NULL",
")",
"{",
"if",
"(",
"!",
"$",
"data",
")",
"{",
"$",
"data",
"=",
"microtime",
"(",
")",
".",
"uniqid",
"(",
"mt_rand",
"(",
")",
",",
"1",
")",
";",
"}",
"return",
"hash",
"(",
"$",
"algo",
",",
"$",
"data",
")",
";",
"}"
] | generate hash value
@param string $algo
@param string $data
@return string | [
"generate",
"hash",
"value"
] | 13ef5caf3d4cce423854a0cb8fb8010c0d40326a | https://github.com/calgamo/util/blob/13ef5caf3d4cce423854a0cb8fb8010c0d40326a/src/Util.php#L239-L245 |
7,334 | calgamo/util | src/Util.php | Util.escape | public static function escape( $value )
{
if ( is_string($value) ){
$res = htmlspecialchars($value, ENT_QUOTES, mb_internal_encoding());
//log_debug( "debug", "escape:" . print_r($res,true) );
return $res;
}
elseif ( is_array($value) ){
$ret = array();
foreach( $value as $key => $item ){
$ret[$key] = self::escape( $item );
}
return $ret;
}
elseif ( is_object($value) ){
$object = $value;
$vars = get_object_vars($object);
foreach( $vars as $key => $value ){
$object->$key = self::escape( $value );
}
return $object;
}
return $value;
} | php | public static function escape( $value )
{
if ( is_string($value) ){
$res = htmlspecialchars($value, ENT_QUOTES, mb_internal_encoding());
//log_debug( "debug", "escape:" . print_r($res,true) );
return $res;
}
elseif ( is_array($value) ){
$ret = array();
foreach( $value as $key => $item ){
$ret[$key] = self::escape( $item );
}
return $ret;
}
elseif ( is_object($value) ){
$object = $value;
$vars = get_object_vars($object);
foreach( $vars as $key => $value ){
$object->$key = self::escape( $value );
}
return $object;
}
return $value;
} | [
"public",
"static",
"function",
"escape",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"res",
"=",
"htmlspecialchars",
"(",
"$",
"value",
",",
"ENT_QUOTES",
",",
"mb_internal_encoding",
"(",
")",
")",
";",
"//log_debug( \"debug\", \"escape:\" . print_r($res,true) );",
"return",
"$",
"res",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"$",
"ret",
"[",
"$",
"key",
"]",
"=",
"self",
"::",
"escape",
"(",
"$",
"item",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"$",
"object",
"=",
"$",
"value",
";",
"$",
"vars",
"=",
"get_object_vars",
"(",
"$",
"object",
")",
";",
"foreach",
"(",
"$",
"vars",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"object",
"->",
"$",
"key",
"=",
"self",
"::",
"escape",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"object",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | escape variable for HTML
@param mixed $value
@return mixed | [
"escape",
"variable",
"for",
"HTML"
] | 13ef5caf3d4cce423854a0cb8fb8010c0d40326a | https://github.com/calgamo/util/blob/13ef5caf3d4cce423854a0cb8fb8010c0d40326a/src/Util.php#L254-L277 |
7,335 | calgamo/util | src/Util.php | Util.decode | public static function decode( $value )
{
if ( is_string($value) ){
//log_debug( "debug", "decode before:" . print_r($value,true) );
$res = htmlspecialchars_decode($value, ENT_QUOTES);
//log_debug( "debug", "decode after:" . print_r($res,true) );
return $res;
}
elseif ( is_array($value) ){
return array_map('Charcoal_System::decode', $value);
}
elseif ( is_object($value) ){
$object = $value;
$vars = get_object_vars($object);
foreach( $vars as $key => $value ){
$object->$key = self::decode( $value );
}
return $object;
}
return $value;
} | php | public static function decode( $value )
{
if ( is_string($value) ){
//log_debug( "debug", "decode before:" . print_r($value,true) );
$res = htmlspecialchars_decode($value, ENT_QUOTES);
//log_debug( "debug", "decode after:" . print_r($res,true) );
return $res;
}
elseif ( is_array($value) ){
return array_map('Charcoal_System::decode', $value);
}
elseif ( is_object($value) ){
$object = $value;
$vars = get_object_vars($object);
foreach( $vars as $key => $value ){
$object->$key = self::decode( $value );
}
return $object;
}
return $value;
} | [
"public",
"static",
"function",
"decode",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"//log_debug( \"debug\", \"decode before:\" . print_r($value,true) );",
"$",
"res",
"=",
"htmlspecialchars_decode",
"(",
"$",
"value",
",",
"ENT_QUOTES",
")",
";",
"//log_debug( \"debug\", \"decode after:\" . print_r($res,true) );",
"return",
"$",
"res",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"array_map",
"(",
"'Charcoal_System::decode'",
",",
"$",
"value",
")",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"$",
"object",
"=",
"$",
"value",
";",
"$",
"vars",
"=",
"get_object_vars",
"(",
"$",
"object",
")",
";",
"foreach",
"(",
"$",
"vars",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"object",
"->",
"$",
"key",
"=",
"self",
"::",
"decode",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"object",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | decode escaped value
@param mixed $value
@return mixed | [
"decode",
"escaped",
"value"
] | 13ef5caf3d4cce423854a0cb8fb8010c0d40326a | https://github.com/calgamo/util/blob/13ef5caf3d4cce423854a0cb8fb8010c0d40326a/src/Util.php#L286-L306 |
7,336 | calgamo/util | src/Util.php | Util.stripTags | public static function stripTags( $value, $allowable_tags = NULL )
{
if ( is_string($value) ){
$res = strip_tags($value, $allowable_tags);
return $res;
}
elseif ( is_array($value) ){
$array = $value;
foreach( $array as $key => $value ){
$array[$key] = self::stripTags( $value, $allowable_tags );
}
return $array;
}
elseif ( is_object($value) ){
$object = $value;
$vars = get_object_vars($object);
foreach( $vars as $key => $value ){
$object->$key = self::stripTags( $value );
}
return $object;
}
return $value;
} | php | public static function stripTags( $value, $allowable_tags = NULL )
{
if ( is_string($value) ){
$res = strip_tags($value, $allowable_tags);
return $res;
}
elseif ( is_array($value) ){
$array = $value;
foreach( $array as $key => $value ){
$array[$key] = self::stripTags( $value, $allowable_tags );
}
return $array;
}
elseif ( is_object($value) ){
$object = $value;
$vars = get_object_vars($object);
foreach( $vars as $key => $value ){
$object->$key = self::stripTags( $value );
}
return $object;
}
return $value;
} | [
"public",
"static",
"function",
"stripTags",
"(",
"$",
"value",
",",
"$",
"allowable_tags",
"=",
"NULL",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"res",
"=",
"strip_tags",
"(",
"$",
"value",
",",
"$",
"allowable_tags",
")",
";",
"return",
"$",
"res",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"array",
"=",
"$",
"value",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"array",
"[",
"$",
"key",
"]",
"=",
"self",
"::",
"stripTags",
"(",
"$",
"value",
",",
"$",
"allowable_tags",
")",
";",
"}",
"return",
"$",
"array",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"$",
"object",
"=",
"$",
"value",
";",
"$",
"vars",
"=",
"get_object_vars",
"(",
"$",
"object",
")",
";",
"foreach",
"(",
"$",
"vars",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"object",
"->",
"$",
"key",
"=",
"self",
"::",
"stripTags",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"object",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | remove HTML tags
@param mixed $value
@param string $allowable_tags
@return mixed | [
"remove",
"HTML",
"tags"
] | 13ef5caf3d4cce423854a0cb8fb8010c0d40326a | https://github.com/calgamo/util/blob/13ef5caf3d4cce423854a0cb8fb8010c0d40326a/src/Util.php#L316-L338 |
7,337 | calgamo/util | src/Util.php | Util.escapeString | public static function escapeString( $string_data, $options = NULL )
{
if ( !$options ){
$options = array(
'quote_style' => 'ENT_QUOTES',
);
}
$quote_style = ENT_NOQUOTES;
if ( isset($options['quote_style']) && $options['quote_style'] == 'ENT_QUOTES' ){
$quote_style = ENT_QUOTES;
}
$str = htmlspecialchars( $string_data, $quote_style );
return $str;
} | php | public static function escapeString( $string_data, $options = NULL )
{
if ( !$options ){
$options = array(
'quote_style' => 'ENT_QUOTES',
);
}
$quote_style = ENT_NOQUOTES;
if ( isset($options['quote_style']) && $options['quote_style'] == 'ENT_QUOTES' ){
$quote_style = ENT_QUOTES;
}
$str = htmlspecialchars( $string_data, $quote_style );
return $str;
} | [
"public",
"static",
"function",
"escapeString",
"(",
"$",
"string_data",
",",
"$",
"options",
"=",
"NULL",
")",
"{",
"if",
"(",
"!",
"$",
"options",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"'quote_style'",
"=>",
"'ENT_QUOTES'",
",",
")",
";",
"}",
"$",
"quote_style",
"=",
"ENT_NOQUOTES",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'quote_style'",
"]",
")",
"&&",
"$",
"options",
"[",
"'quote_style'",
"]",
"==",
"'ENT_QUOTES'",
")",
"{",
"$",
"quote_style",
"=",
"ENT_QUOTES",
";",
"}",
"$",
"str",
"=",
"htmlspecialchars",
"(",
"$",
"string_data",
",",
"$",
"quote_style",
")",
";",
"return",
"$",
"str",
";",
"}"
] | escape string for HTML
@param string $string_data
@param array $options
@return mixed | [
"escape",
"string",
"for",
"HTML"
] | 13ef5caf3d4cce423854a0cb8fb8010c0d40326a | https://github.com/calgamo/util/blob/13ef5caf3d4cce423854a0cb8fb8010c0d40326a/src/Util.php#L378-L394 |
7,338 | calgamo/util | src/Util.php | Util.makeRandomString | public static function makeRandomString( $length, $char_set = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_' )
{
$ret = '';
$char_set_cnt = strlen($char_set);
mt_srand();
for($i = 0; $i < $length; $i++){
$idx = mt_rand(0, $char_set_cnt - 1);
$ret .= $char_set[ $idx ];
}
return $ret;
} | php | public static function makeRandomString( $length, $char_set = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_' )
{
$ret = '';
$char_set_cnt = strlen($char_set);
mt_srand();
for($i = 0; $i < $length; $i++){
$idx = mt_rand(0, $char_set_cnt - 1);
$ret .= $char_set[ $idx ];
}
return $ret;
} | [
"public",
"static",
"function",
"makeRandomString",
"(",
"$",
"length",
",",
"$",
"char_set",
"=",
"'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'",
")",
"{",
"$",
"ret",
"=",
"''",
";",
"$",
"char_set_cnt",
"=",
"strlen",
"(",
"$",
"char_set",
")",
";",
"mt_srand",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"idx",
"=",
"mt_rand",
"(",
"0",
",",
"$",
"char_set_cnt",
"-",
"1",
")",
";",
"$",
"ret",
".=",
"$",
"char_set",
"[",
"$",
"idx",
"]",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | make random string
@param int $length
@param string $char_set
@return string | [
"make",
"random",
"string"
] | 13ef5caf3d4cce423854a0cb8fb8010c0d40326a | https://github.com/calgamo/util/blob/13ef5caf3d4cce423854a0cb8fb8010c0d40326a/src/Util.php#L404-L416 |
7,339 | calgamo/util | src/Util.php | Util.caller | public static function caller(int $back = 0)
{
$bt = debug_backtrace();
$trace = $bt[$back] ?? null;
$file = $trace['file'] ?? '';
$line = $trace['line'] ?? -1;
return array( $file, intval($line) );
} | php | public static function caller(int $back = 0)
{
$bt = debug_backtrace();
$trace = $bt[$back] ?? null;
$file = $trace['file'] ?? '';
$line = $trace['line'] ?? -1;
return array( $file, intval($line) );
} | [
"public",
"static",
"function",
"caller",
"(",
"int",
"$",
"back",
"=",
"0",
")",
"{",
"$",
"bt",
"=",
"debug_backtrace",
"(",
")",
";",
"$",
"trace",
"=",
"$",
"bt",
"[",
"$",
"back",
"]",
"??",
"null",
";",
"$",
"file",
"=",
"$",
"trace",
"[",
"'file'",
"]",
"??",
"''",
";",
"$",
"line",
"=",
"$",
"trace",
"[",
"'line'",
"]",
"??",
"-",
"1",
";",
"return",
"array",
"(",
"$",
"file",
",",
"intval",
"(",
"$",
"line",
")",
")",
";",
"}"
] | return file and line number of called position
@param int $back
@return array | [
"return",
"file",
"and",
"line",
"number",
"of",
"called",
"position"
] | 13ef5caf3d4cce423854a0cb8fb8010c0d40326a | https://github.com/calgamo/util/blob/13ef5caf3d4cce423854a0cb8fb8010c0d40326a/src/Util.php#L425-L434 |
7,340 | calgamo/util | src/Util.php | Util.callerAsString | public static function callerAsString( $back = 0, $fullpath = FALSE )
{
list( $file, $line ) = self::caller( $back );
if ( $fullpath ){
return "$file($line)";
}
$file = basename($file);
return "$file($line)";
} | php | public static function callerAsString( $back = 0, $fullpath = FALSE )
{
list( $file, $line ) = self::caller( $back );
if ( $fullpath ){
return "$file($line)";
}
$file = basename($file);
return "$file($line)";
} | [
"public",
"static",
"function",
"callerAsString",
"(",
"$",
"back",
"=",
"0",
",",
"$",
"fullpath",
"=",
"FALSE",
")",
"{",
"list",
"(",
"$",
"file",
",",
"$",
"line",
")",
"=",
"self",
"::",
"caller",
"(",
"$",
"back",
")",
";",
"if",
"(",
"$",
"fullpath",
")",
"{",
"return",
"\"$file($line)\"",
";",
"}",
"$",
"file",
"=",
"basename",
"(",
"$",
"file",
")",
";",
"return",
"\"$file($line)\"",
";",
"}"
] | return file and line number of called position as string
@param int $back
@param bool $fullpath
@return string | [
"return",
"file",
"and",
"line",
"number",
"of",
"called",
"position",
"as",
"string"
] | 13ef5caf3d4cce423854a0cb8fb8010c0d40326a | https://github.com/calgamo/util/blob/13ef5caf3d4cce423854a0cb8fb8010c0d40326a/src/Util.php#L444-L455 |
7,341 | calgamo/util | src/Util.php | Util.getType | public static function getType( $value )
{
$type = gettype($value);
switch( $type ){
case 'string':
return $type . '(' . strlen($value) . ')';
break;
case 'integer':
case 'float':
case 'boolean':
return $type . '(' . $value . ')';
break;
case 'NULL':
case 'unknown type':
return $type;
break;
case 'array':
return $type . '(' . count($value) . ')';
break;
case 'object':
if ( $value instanceof \Countable ){
return get_class( $value ) . '(' . count($value) . ')';
}
elseif ( $value instanceof HashableInterface ){
return get_class( $value ) . '(hash=' . $value->hash() . ')';
}
return get_class( $value );
break;
}
return '';
} | php | public static function getType( $value )
{
$type = gettype($value);
switch( $type ){
case 'string':
return $type . '(' . strlen($value) . ')';
break;
case 'integer':
case 'float':
case 'boolean':
return $type . '(' . $value . ')';
break;
case 'NULL':
case 'unknown type':
return $type;
break;
case 'array':
return $type . '(' . count($value) . ')';
break;
case 'object':
if ( $value instanceof \Countable ){
return get_class( $value ) . '(' . count($value) . ')';
}
elseif ( $value instanceof HashableInterface ){
return get_class( $value ) . '(hash=' . $value->hash() . ')';
}
return get_class( $value );
break;
}
return '';
} | [
"public",
"static",
"function",
"getType",
"(",
"$",
"value",
")",
"{",
"$",
"type",
"=",
"gettype",
"(",
"$",
"value",
")",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'string'",
":",
"return",
"$",
"type",
".",
"'('",
".",
"strlen",
"(",
"$",
"value",
")",
".",
"')'",
";",
"break",
";",
"case",
"'integer'",
":",
"case",
"'float'",
":",
"case",
"'boolean'",
":",
"return",
"$",
"type",
".",
"'('",
".",
"$",
"value",
".",
"')'",
";",
"break",
";",
"case",
"'NULL'",
":",
"case",
"'unknown type'",
":",
"return",
"$",
"type",
";",
"break",
";",
"case",
"'array'",
":",
"return",
"$",
"type",
".",
"'('",
".",
"count",
"(",
"$",
"value",
")",
".",
"')'",
";",
"break",
";",
"case",
"'object'",
":",
"if",
"(",
"$",
"value",
"instanceof",
"\\",
"Countable",
")",
"{",
"return",
"get_class",
"(",
"$",
"value",
")",
".",
"'('",
".",
"count",
"(",
"$",
"value",
")",
".",
"')'",
";",
"}",
"elseif",
"(",
"$",
"value",
"instanceof",
"HashableInterface",
")",
"{",
"return",
"get_class",
"(",
"$",
"value",
")",
".",
"'(hash='",
".",
"$",
"value",
"->",
"hash",
"(",
")",
".",
"')'",
";",
"}",
"return",
"get_class",
"(",
"$",
"value",
")",
";",
"break",
";",
"}",
"return",
"''",
";",
"}"
] | get type of primitive, resource, array, or object
@param mixed $value
@return string | [
"get",
"type",
"of",
"primitive",
"resource",
"array",
"or",
"object"
] | 13ef5caf3d4cce423854a0cb8fb8010c0d40326a | https://github.com/calgamo/util/blob/13ef5caf3d4cce423854a0cb8fb8010c0d40326a/src/Util.php#L464-L494 |
7,342 | calgamo/util | src/Util.php | Util.toString | public static function toString( $value, $with_type = FALSE, $max_size = self::TOSTRING_MAX_LENGTH, $tostring_methods = '__toString,toString' )
{
$ret = '';
if ( $value === NULL ){
$ret = 'NULL';
}
else{
$type = gettype($value);
switch( $type ){
case 'string':
case 'integer':
case 'double':
case 'boolean':
case 'NULL':
case 'unknown type':
$ret = strval($value);
if ( $with_type ){
$ret .= '(' . $type . ')';
}
break;
case 'array':
$ret = '';
foreach( $value as $k => $v ){
if ( strlen($ret) > 0 ) $ret .= '/';
$ret .= "$k=" . self::toString( $v );
if ( $with_type ){
$ret .= '(' . gettype($v) . ')';
}
}
break;
case 'object':
{
$methods = explode( ',', $tostring_methods );
foreach( $methods as $method ){
if ( method_exists($value, $method) ){
$ret = $value->{$method}();
break;
}
}
if ( $with_type ){
$ret .= '(' . get_class($value) . ')';
}
}
break;
}
}
if ( $max_size > 0 ){
return strlen($ret) > $max_size ? substr($ret,0,$max_size) . '...' : $ret;
}
else{
return $ret;
}
} | php | public static function toString( $value, $with_type = FALSE, $max_size = self::TOSTRING_MAX_LENGTH, $tostring_methods = '__toString,toString' )
{
$ret = '';
if ( $value === NULL ){
$ret = 'NULL';
}
else{
$type = gettype($value);
switch( $type ){
case 'string':
case 'integer':
case 'double':
case 'boolean':
case 'NULL':
case 'unknown type':
$ret = strval($value);
if ( $with_type ){
$ret .= '(' . $type . ')';
}
break;
case 'array':
$ret = '';
foreach( $value as $k => $v ){
if ( strlen($ret) > 0 ) $ret .= '/';
$ret .= "$k=" . self::toString( $v );
if ( $with_type ){
$ret .= '(' . gettype($v) . ')';
}
}
break;
case 'object':
{
$methods = explode( ',', $tostring_methods );
foreach( $methods as $method ){
if ( method_exists($value, $method) ){
$ret = $value->{$method}();
break;
}
}
if ( $with_type ){
$ret .= '(' . get_class($value) . ')';
}
}
break;
}
}
if ( $max_size > 0 ){
return strlen($ret) > $max_size ? substr($ret,0,$max_size) . '...' : $ret;
}
else{
return $ret;
}
} | [
"public",
"static",
"function",
"toString",
"(",
"$",
"value",
",",
"$",
"with_type",
"=",
"FALSE",
",",
"$",
"max_size",
"=",
"self",
"::",
"TOSTRING_MAX_LENGTH",
",",
"$",
"tostring_methods",
"=",
"'__toString,toString'",
")",
"{",
"$",
"ret",
"=",
"''",
";",
"if",
"(",
"$",
"value",
"===",
"NULL",
")",
"{",
"$",
"ret",
"=",
"'NULL'",
";",
"}",
"else",
"{",
"$",
"type",
"=",
"gettype",
"(",
"$",
"value",
")",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'string'",
":",
"case",
"'integer'",
":",
"case",
"'double'",
":",
"case",
"'boolean'",
":",
"case",
"'NULL'",
":",
"case",
"'unknown type'",
":",
"$",
"ret",
"=",
"strval",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"with_type",
")",
"{",
"$",
"ret",
".=",
"'('",
".",
"$",
"type",
".",
"')'",
";",
"}",
"break",
";",
"case",
"'array'",
":",
"$",
"ret",
"=",
"''",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"ret",
")",
">",
"0",
")",
"$",
"ret",
".=",
"'/'",
";",
"$",
"ret",
".=",
"\"$k=\"",
".",
"self",
"::",
"toString",
"(",
"$",
"v",
")",
";",
"if",
"(",
"$",
"with_type",
")",
"{",
"$",
"ret",
".=",
"'('",
".",
"gettype",
"(",
"$",
"v",
")",
".",
"')'",
";",
"}",
"}",
"break",
";",
"case",
"'object'",
":",
"{",
"$",
"methods",
"=",
"explode",
"(",
"','",
",",
"$",
"tostring_methods",
")",
";",
"foreach",
"(",
"$",
"methods",
"as",
"$",
"method",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"value",
",",
"$",
"method",
")",
")",
"{",
"$",
"ret",
"=",
"$",
"value",
"->",
"{",
"$",
"method",
"}",
"(",
")",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"with_type",
")",
"{",
"$",
"ret",
".=",
"'('",
".",
"get_class",
"(",
"$",
"value",
")",
".",
"')'",
";",
"}",
"}",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"max_size",
">",
"0",
")",
"{",
"return",
"strlen",
"(",
"$",
"ret",
")",
">",
"$",
"max_size",
"?",
"substr",
"(",
"$",
"ret",
",",
"0",
",",
"$",
"max_size",
")",
".",
"'...'",
":",
"$",
"ret",
";",
"}",
"else",
"{",
"return",
"$",
"ret",
";",
"}",
"}"
] | make string expression about a variable
@param mixed $value
@param bool $with_type
@param int $max_size
@param string $tostring_methods
@return string | [
"make",
"string",
"expression",
"about",
"a",
"variable"
] | 13ef5caf3d4cce423854a0cb8fb8010c0d40326a | https://github.com/calgamo/util/blob/13ef5caf3d4cce423854a0cb8fb8010c0d40326a/src/Util.php#L506-L560 |
7,343 | calgamo/util | src/Util.php | Util.dump | public static function dump( $var, $format = 'html', $back = 0, $options = NULL, $return = FALSE, $max_depth = 6 )
{
list( $file, $line ) = self::caller( $back );
if ( !$options ){
$options = array();
}
$default_options = array(
'title' => 'system dump',
'font_size' => 11,
'max_string_length' => self::DUMP_MAX_LENGTH,
'type' => 'textarea',
);
$options = array_merge( $default_options, $options );
$title = $options['title'];
$font_size = $options['font_size'];
$max_string_length = $options['max_string_length'];
$type = $options['type'];
$lines = array();
$recursion = array();
self::_dump( '-', $var, 0, $max_string_length, $lines, $max_depth, $recursion );
switch( $format )
{
case "html":
switch( $type ){
case 'div':
$output = "<div style=\"font-size:12px; margin: 2px\"> $title:" . implode('',$lines) . " @$file($line)</div>";
break;
case 'textarea':
default:
$output = "<h3 style=\"font-size:12px; margin: 0; color:black; background-color:white; text-align: left\"> $title @$file($line)</h3>";
$output .= "<textarea rows=14 style=\"width:100%; font-size:{$font_size}px; margin: 0; color:black; background-color:white; border: 1px solid silver;\">";
$output .= implode(PHP_EOL,$lines);
$output .= "</textarea>";
break;
}
break;
case "shell":
default:
$output = "$title @$file($line)" . PHP_EOL;
$output .= implode(PHP_EOL,$lines) . PHP_EOL;
break;
}
if ( $return ){
return $output;
}
else{
echo $output;
return null;
}
} | php | public static function dump( $var, $format = 'html', $back = 0, $options = NULL, $return = FALSE, $max_depth = 6 )
{
list( $file, $line ) = self::caller( $back );
if ( !$options ){
$options = array();
}
$default_options = array(
'title' => 'system dump',
'font_size' => 11,
'max_string_length' => self::DUMP_MAX_LENGTH,
'type' => 'textarea',
);
$options = array_merge( $default_options, $options );
$title = $options['title'];
$font_size = $options['font_size'];
$max_string_length = $options['max_string_length'];
$type = $options['type'];
$lines = array();
$recursion = array();
self::_dump( '-', $var, 0, $max_string_length, $lines, $max_depth, $recursion );
switch( $format )
{
case "html":
switch( $type ){
case 'div':
$output = "<div style=\"font-size:12px; margin: 2px\"> $title:" . implode('',$lines) . " @$file($line)</div>";
break;
case 'textarea':
default:
$output = "<h3 style=\"font-size:12px; margin: 0; color:black; background-color:white; text-align: left\"> $title @$file($line)</h3>";
$output .= "<textarea rows=14 style=\"width:100%; font-size:{$font_size}px; margin: 0; color:black; background-color:white; border: 1px solid silver;\">";
$output .= implode(PHP_EOL,$lines);
$output .= "</textarea>";
break;
}
break;
case "shell":
default:
$output = "$title @$file($line)" . PHP_EOL;
$output .= implode(PHP_EOL,$lines) . PHP_EOL;
break;
}
if ( $return ){
return $output;
}
else{
echo $output;
return null;
}
} | [
"public",
"static",
"function",
"dump",
"(",
"$",
"var",
",",
"$",
"format",
"=",
"'html'",
",",
"$",
"back",
"=",
"0",
",",
"$",
"options",
"=",
"NULL",
",",
"$",
"return",
"=",
"FALSE",
",",
"$",
"max_depth",
"=",
"6",
")",
"{",
"list",
"(",
"$",
"file",
",",
"$",
"line",
")",
"=",
"self",
"::",
"caller",
"(",
"$",
"back",
")",
";",
"if",
"(",
"!",
"$",
"options",
")",
"{",
"$",
"options",
"=",
"array",
"(",
")",
";",
"}",
"$",
"default_options",
"=",
"array",
"(",
"'title'",
"=>",
"'system dump'",
",",
"'font_size'",
"=>",
"11",
",",
"'max_string_length'",
"=>",
"self",
"::",
"DUMP_MAX_LENGTH",
",",
"'type'",
"=>",
"'textarea'",
",",
")",
";",
"$",
"options",
"=",
"array_merge",
"(",
"$",
"default_options",
",",
"$",
"options",
")",
";",
"$",
"title",
"=",
"$",
"options",
"[",
"'title'",
"]",
";",
"$",
"font_size",
"=",
"$",
"options",
"[",
"'font_size'",
"]",
";",
"$",
"max_string_length",
"=",
"$",
"options",
"[",
"'max_string_length'",
"]",
";",
"$",
"type",
"=",
"$",
"options",
"[",
"'type'",
"]",
";",
"$",
"lines",
"=",
"array",
"(",
")",
";",
"$",
"recursion",
"=",
"array",
"(",
")",
";",
"self",
"::",
"_dump",
"(",
"'-'",
",",
"$",
"var",
",",
"0",
",",
"$",
"max_string_length",
",",
"$",
"lines",
",",
"$",
"max_depth",
",",
"$",
"recursion",
")",
";",
"switch",
"(",
"$",
"format",
")",
"{",
"case",
"\"html\"",
":",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'div'",
":",
"$",
"output",
"=",
"\"<div style=\\\"font-size:12px; margin: 2px\\\"> $title:\"",
".",
"implode",
"(",
"''",
",",
"$",
"lines",
")",
".",
"\" @$file($line)</div>\"",
";",
"break",
";",
"case",
"'textarea'",
":",
"default",
":",
"$",
"output",
"=",
"\"<h3 style=\\\"font-size:12px; margin: 0; color:black; background-color:white; text-align: left\\\"> $title @$file($line)</h3>\"",
";",
"$",
"output",
".=",
"\"<textarea rows=14 style=\\\"width:100%; font-size:{$font_size}px; margin: 0; color:black; background-color:white; border: 1px solid silver;\\\">\"",
";",
"$",
"output",
".=",
"implode",
"(",
"PHP_EOL",
",",
"$",
"lines",
")",
";",
"$",
"output",
".=",
"\"</textarea>\"",
";",
"break",
";",
"}",
"break",
";",
"case",
"\"shell\"",
":",
"default",
":",
"$",
"output",
"=",
"\"$title @$file($line)\"",
".",
"PHP_EOL",
";",
"$",
"output",
".=",
"implode",
"(",
"PHP_EOL",
",",
"$",
"lines",
")",
".",
"PHP_EOL",
";",
"break",
";",
"}",
"if",
"(",
"$",
"return",
")",
"{",
"return",
"$",
"output",
";",
"}",
"else",
"{",
"echo",
"$",
"output",
";",
"return",
"null",
";",
"}",
"}"
] | dump a variable
@param mixed $var
@param string $format
@param int $back
@param array $options
@param bool $return
@param int $max_depth
@return string | [
"dump",
"a",
"variable"
] | 13ef5caf3d4cce423854a0cb8fb8010c0d40326a | https://github.com/calgamo/util/blob/13ef5caf3d4cce423854a0cb8fb8010c0d40326a/src/Util.php#L574-L628 |
7,344 | calgamo/util | src/Util.php | Util.convertEncodingRecursive | public static function convertEncodingRecursive( $var, $to_encoding = NULL, $from_encoding = NULL )
{
$type = gettype($var);
switch( $type ){
case 'string':
{
return mb_convert_encoding($var,$to_encoding, $from_encoding);
}
break;
case 'integer':
case 'double':
case 'boolean':
case 'NULL':
case 'unknown type':
break;
case 'array':
{
$newArray = array();
foreach( $var as $key => $value ){
$value = self::convertEncodingRecursive( $value, $to_encoding, $from_encoding );
$newArray[ $key ] = $value;
}
return $newArray;
}
break;
case 'object':
{
$newObject = clone $var;
if ( $var instanceof \Traversable ){
foreach( $var as $key => $value ){
$value = self::convertEncodingRecursive( $value, $to_encoding, $from_encoding );
$newObject->$key = $value;
}
return $newObject;
}
else{
$obj_vars = get_object_vars( $var );
foreach( $obj_vars as $key => $value ){
$value = self::convertEncodingRecursive( $value, $to_encoding, $from_encoding );
$newObject->$key = $value;
}
return $newObject;
}
}
break;
}
return $var;
} | php | public static function convertEncodingRecursive( $var, $to_encoding = NULL, $from_encoding = NULL )
{
$type = gettype($var);
switch( $type ){
case 'string':
{
return mb_convert_encoding($var,$to_encoding, $from_encoding);
}
break;
case 'integer':
case 'double':
case 'boolean':
case 'NULL':
case 'unknown type':
break;
case 'array':
{
$newArray = array();
foreach( $var as $key => $value ){
$value = self::convertEncodingRecursive( $value, $to_encoding, $from_encoding );
$newArray[ $key ] = $value;
}
return $newArray;
}
break;
case 'object':
{
$newObject = clone $var;
if ( $var instanceof \Traversable ){
foreach( $var as $key => $value ){
$value = self::convertEncodingRecursive( $value, $to_encoding, $from_encoding );
$newObject->$key = $value;
}
return $newObject;
}
else{
$obj_vars = get_object_vars( $var );
foreach( $obj_vars as $key => $value ){
$value = self::convertEncodingRecursive( $value, $to_encoding, $from_encoding );
$newObject->$key = $value;
}
return $newObject;
}
}
break;
}
return $var;
} | [
"public",
"static",
"function",
"convertEncodingRecursive",
"(",
"$",
"var",
",",
"$",
"to_encoding",
"=",
"NULL",
",",
"$",
"from_encoding",
"=",
"NULL",
")",
"{",
"$",
"type",
"=",
"gettype",
"(",
"$",
"var",
")",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'string'",
":",
"{",
"return",
"mb_convert_encoding",
"(",
"$",
"var",
",",
"$",
"to_encoding",
",",
"$",
"from_encoding",
")",
";",
"}",
"break",
";",
"case",
"'integer'",
":",
"case",
"'double'",
":",
"case",
"'boolean'",
":",
"case",
"'NULL'",
":",
"case",
"'unknown type'",
":",
"break",
";",
"case",
"'array'",
":",
"{",
"$",
"newArray",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"var",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"self",
"::",
"convertEncodingRecursive",
"(",
"$",
"value",
",",
"$",
"to_encoding",
",",
"$",
"from_encoding",
")",
";",
"$",
"newArray",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"newArray",
";",
"}",
"break",
";",
"case",
"'object'",
":",
"{",
"$",
"newObject",
"=",
"clone",
"$",
"var",
";",
"if",
"(",
"$",
"var",
"instanceof",
"\\",
"Traversable",
")",
"{",
"foreach",
"(",
"$",
"var",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"self",
"::",
"convertEncodingRecursive",
"(",
"$",
"value",
",",
"$",
"to_encoding",
",",
"$",
"from_encoding",
")",
";",
"$",
"newObject",
"->",
"$",
"key",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"newObject",
";",
"}",
"else",
"{",
"$",
"obj_vars",
"=",
"get_object_vars",
"(",
"$",
"var",
")",
";",
"foreach",
"(",
"$",
"obj_vars",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"self",
"::",
"convertEncodingRecursive",
"(",
"$",
"value",
",",
"$",
"to_encoding",
",",
"$",
"from_encoding",
")",
";",
"$",
"newObject",
"->",
"$",
"key",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"newObject",
";",
"}",
"}",
"break",
";",
"}",
"return",
"$",
"var",
";",
"}"
] | convert encoding recursively
@param mixed $var
@param string $to_encoding
@param string $from_encoding
@return mixed | [
"convert",
"encoding",
"recursively"
] | 13ef5caf3d4cce423854a0cb8fb8010c0d40326a | https://github.com/calgamo/util/blob/13ef5caf3d4cce423854a0cb8fb8010c0d40326a/src/Util.php#L731-L779 |
7,345 | nattreid/app-manager | src/Helpers/Deploy/Deploy.php | Deploy.authentication | protected function authentication(): bool
{
if ($this->url === null) {
throw new InvalidArgumentException('Project URL is not set');
}
$payload = file_get_contents('php://input');
switch ($this->type) {
case 'gitlab':
$authenticated = $this->authenticateGitlab($payload);
break;
case 'github':
$authenticated = $this->authenticateGithub($payload);
break;
case 'bitbucket':
$authenticated = $this->authenticateBitbucket($payload);
break;
default:
throw new InvalidArgumentException("Unsupported type '$this->type'");
}
if ($authenticated) {
return true;
} else {
Debugger::log('Unknown access from ' . $this->request->getRemoteHost() . '(' . $this->request->getRemoteAddress() . ')', 'deploy');
return false;
}
} | php | protected function authentication(): bool
{
if ($this->url === null) {
throw new InvalidArgumentException('Project URL is not set');
}
$payload = file_get_contents('php://input');
switch ($this->type) {
case 'gitlab':
$authenticated = $this->authenticateGitlab($payload);
break;
case 'github':
$authenticated = $this->authenticateGithub($payload);
break;
case 'bitbucket':
$authenticated = $this->authenticateBitbucket($payload);
break;
default:
throw new InvalidArgumentException("Unsupported type '$this->type'");
}
if ($authenticated) {
return true;
} else {
Debugger::log('Unknown access from ' . $this->request->getRemoteHost() . '(' . $this->request->getRemoteAddress() . ')', 'deploy');
return false;
}
} | [
"protected",
"function",
"authentication",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"url",
"===",
"null",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Project URL is not set'",
")",
";",
"}",
"$",
"payload",
"=",
"file_get_contents",
"(",
"'php://input'",
")",
";",
"switch",
"(",
"$",
"this",
"->",
"type",
")",
"{",
"case",
"'gitlab'",
":",
"$",
"authenticated",
"=",
"$",
"this",
"->",
"authenticateGitlab",
"(",
"$",
"payload",
")",
";",
"break",
";",
"case",
"'github'",
":",
"$",
"authenticated",
"=",
"$",
"this",
"->",
"authenticateGithub",
"(",
"$",
"payload",
")",
";",
"break",
";",
"case",
"'bitbucket'",
":",
"$",
"authenticated",
"=",
"$",
"this",
"->",
"authenticateBitbucket",
"(",
"$",
"payload",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Unsupported type '$this->type'\"",
")",
";",
"}",
"if",
"(",
"$",
"authenticated",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"Debugger",
"::",
"log",
"(",
"'Unknown access from '",
".",
"$",
"this",
"->",
"request",
"->",
"getRemoteHost",
"(",
")",
".",
"'('",
".",
"$",
"this",
"->",
"request",
"->",
"getRemoteAddress",
"(",
")",
".",
"')'",
",",
"'deploy'",
")",
";",
"return",
"false",
";",
"}",
"}"
] | Je povolen pristup
@return bool
@throws InvalidArgumentException | [
"Je",
"povolen",
"pristup"
] | 7821d09a0b3e58ba9c6eb81d44e35aacce55de75 | https://github.com/nattreid/app-manager/blob/7821d09a0b3e58ba9c6eb81d44e35aacce55de75/src/Helpers/Deploy/Deploy.php#L41-L72 |
7,346 | mizmoz/config | src/Config.php | Config.parseReferences | private function parseReferences($name): string
{
if (preg_match_all('/\$\{(.*[a-z\.0-9])\}/si', $name, $results, PREG_SET_ORDER)) {
foreach ($results as $match) {
$replace = $match[0];
$key = $match[1];
// Handle using relative placement like get('db.${.default}.host');
if (strpos($key, '.') === 0) {
// using relative placement
$key = substr($name, 0, strpos($name, $replace) - 1) . $key;
}
// get the value
$value = $this->get($key);
if ($value === null || $value === '' || $value === false) {
throw new InvalidArgumentException(
$key . ' replacement for ' . $name . ' must not be null or empty'
);
}
$name = str_replace($replace, $value, $name);
}
}
return $name;
} | php | private function parseReferences($name): string
{
if (preg_match_all('/\$\{(.*[a-z\.0-9])\}/si', $name, $results, PREG_SET_ORDER)) {
foreach ($results as $match) {
$replace = $match[0];
$key = $match[1];
// Handle using relative placement like get('db.${.default}.host');
if (strpos($key, '.') === 0) {
// using relative placement
$key = substr($name, 0, strpos($name, $replace) - 1) . $key;
}
// get the value
$value = $this->get($key);
if ($value === null || $value === '' || $value === false) {
throw new InvalidArgumentException(
$key . ' replacement for ' . $name . ' must not be null or empty'
);
}
$name = str_replace($replace, $value, $name);
}
}
return $name;
} | [
"private",
"function",
"parseReferences",
"(",
"$",
"name",
")",
":",
"string",
"{",
"if",
"(",
"preg_match_all",
"(",
"'/\\$\\{(.*[a-z\\.0-9])\\}/si'",
",",
"$",
"name",
",",
"$",
"results",
",",
"PREG_SET_ORDER",
")",
")",
"{",
"foreach",
"(",
"$",
"results",
"as",
"$",
"match",
")",
"{",
"$",
"replace",
"=",
"$",
"match",
"[",
"0",
"]",
";",
"$",
"key",
"=",
"$",
"match",
"[",
"1",
"]",
";",
"// Handle using relative placement like get('db.${.default}.host');",
"if",
"(",
"strpos",
"(",
"$",
"key",
",",
"'.'",
")",
"===",
"0",
")",
"{",
"// using relative placement",
"$",
"key",
"=",
"substr",
"(",
"$",
"name",
",",
"0",
",",
"strpos",
"(",
"$",
"name",
",",
"$",
"replace",
")",
"-",
"1",
")",
".",
"$",
"key",
";",
"}",
"// get the value",
"$",
"value",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"value",
"===",
"null",
"||",
"$",
"value",
"===",
"''",
"||",
"$",
"value",
"===",
"false",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"key",
".",
"' replacement for '",
".",
"$",
"name",
".",
"' must not be null or empty'",
")",
";",
"}",
"$",
"name",
"=",
"str_replace",
"(",
"$",
"replace",
",",
"$",
"value",
",",
"$",
"name",
")",
";",
"}",
"}",
"return",
"$",
"name",
";",
"}"
] | Parse any references in the name
@param $name
@return string | [
"Parse",
"any",
"references",
"in",
"the",
"name"
] | 777f66de31603fc65a88416a7b502c1a2fe6d62b | https://github.com/mizmoz/config/blob/777f66de31603fc65a88416a7b502c1a2fe6d62b/src/Config.php#L34-L60 |
7,347 | mizmoz/config | src/Config.php | Config.fromDirectory | public static function fromDirectory(string $directory, string $suffix = '.php'): ConfigInterface
{
$config = [];
foreach (new \DirectoryIterator($directory) as $file) {
if ($file->isDot()) {
continue;
}
$suffixLen = strlen($suffix);
if (! (substr($file->getFilename(), -$suffixLen) === $suffix)) {
continue;
}
// get the file namespace like app.php will be app.
$namespace = substr($file->getFilename(), 0, -($suffixLen));
// create the file resolver so we can resolve the
$config[$namespace] = new File($file->getPathname());
}
return new static($config);
} | php | public static function fromDirectory(string $directory, string $suffix = '.php'): ConfigInterface
{
$config = [];
foreach (new \DirectoryIterator($directory) as $file) {
if ($file->isDot()) {
continue;
}
$suffixLen = strlen($suffix);
if (! (substr($file->getFilename(), -$suffixLen) === $suffix)) {
continue;
}
// get the file namespace like app.php will be app.
$namespace = substr($file->getFilename(), 0, -($suffixLen));
// create the file resolver so we can resolve the
$config[$namespace] = new File($file->getPathname());
}
return new static($config);
} | [
"public",
"static",
"function",
"fromDirectory",
"(",
"string",
"$",
"directory",
",",
"string",
"$",
"suffix",
"=",
"'.php'",
")",
":",
"ConfigInterface",
"{",
"$",
"config",
"=",
"[",
"]",
";",
"foreach",
"(",
"new",
"\\",
"DirectoryIterator",
"(",
"$",
"directory",
")",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"->",
"isDot",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"suffixLen",
"=",
"strlen",
"(",
"$",
"suffix",
")",
";",
"if",
"(",
"!",
"(",
"substr",
"(",
"$",
"file",
"->",
"getFilename",
"(",
")",
",",
"-",
"$",
"suffixLen",
")",
"===",
"$",
"suffix",
")",
")",
"{",
"continue",
";",
"}",
"// get the file namespace like app.php will be app.",
"$",
"namespace",
"=",
"substr",
"(",
"$",
"file",
"->",
"getFilename",
"(",
")",
",",
"0",
",",
"-",
"(",
"$",
"suffixLen",
")",
")",
";",
"// create the file resolver so we can resolve the",
"$",
"config",
"[",
"$",
"namespace",
"]",
"=",
"new",
"File",
"(",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
";",
"}",
"return",
"new",
"static",
"(",
"$",
"config",
")",
";",
"}"
] | Fetch the config from the directory
@param string $directory
@param string $suffix
@return ConfigInterface | [
"Fetch",
"the",
"config",
"from",
"the",
"directory"
] | 777f66de31603fc65a88416a7b502c1a2fe6d62b | https://github.com/mizmoz/config/blob/777f66de31603fc65a88416a7b502c1a2fe6d62b/src/Config.php#L145-L166 |
7,348 | mizmoz/config | src/Config.php | Config.fromEnvironment | public static function fromEnvironment(
EnvironmentInterface $environment,
string $directory = './config'
): ConfigInterface
{
$name = $environment->name();
$projectRoot = $environment->projectRoot();
// get the config directory
$directory = (strpos($directory, '/') === 0 ? $directory : $projectRoot . substr($directory, 1));
$config = [];
foreach (new \DirectoryIterator($directory) as $file) {
if ($file->isDot() || $file->getExtension() !== 'php') {
continue;
}
// get the file parts
$parts = explode('.', $file->getFilename());
$namespace = $parts[0];
$fileEnvironment = (count($parts) === 3 ? $parts[1] : EnvironmentInterface::ENV_PRODUCTION);
if ($fileEnvironment === EnvironmentInterface::ENV_PRODUCTION && ! array_key_exists($namespace, $config)) {
// use the production configs by default
$config[$namespace] = new File($file->getPathname());
}
if ($fileEnvironment === $name) {
// create the file resolver so we can resolve the
$config[$namespace] = new File($file->getPathname());
}
}
// add the environment variables to the config
$config['environment'] = [
'name' => $name,
'projectRoot' => $projectRoot,
];
return new static($config);
} | php | public static function fromEnvironment(
EnvironmentInterface $environment,
string $directory = './config'
): ConfigInterface
{
$name = $environment->name();
$projectRoot = $environment->projectRoot();
// get the config directory
$directory = (strpos($directory, '/') === 0 ? $directory : $projectRoot . substr($directory, 1));
$config = [];
foreach (new \DirectoryIterator($directory) as $file) {
if ($file->isDot() || $file->getExtension() !== 'php') {
continue;
}
// get the file parts
$parts = explode('.', $file->getFilename());
$namespace = $parts[0];
$fileEnvironment = (count($parts) === 3 ? $parts[1] : EnvironmentInterface::ENV_PRODUCTION);
if ($fileEnvironment === EnvironmentInterface::ENV_PRODUCTION && ! array_key_exists($namespace, $config)) {
// use the production configs by default
$config[$namespace] = new File($file->getPathname());
}
if ($fileEnvironment === $name) {
// create the file resolver so we can resolve the
$config[$namespace] = new File($file->getPathname());
}
}
// add the environment variables to the config
$config['environment'] = [
'name' => $name,
'projectRoot' => $projectRoot,
];
return new static($config);
} | [
"public",
"static",
"function",
"fromEnvironment",
"(",
"EnvironmentInterface",
"$",
"environment",
",",
"string",
"$",
"directory",
"=",
"'./config'",
")",
":",
"ConfigInterface",
"{",
"$",
"name",
"=",
"$",
"environment",
"->",
"name",
"(",
")",
";",
"$",
"projectRoot",
"=",
"$",
"environment",
"->",
"projectRoot",
"(",
")",
";",
"// get the config directory",
"$",
"directory",
"=",
"(",
"strpos",
"(",
"$",
"directory",
",",
"'/'",
")",
"===",
"0",
"?",
"$",
"directory",
":",
"$",
"projectRoot",
".",
"substr",
"(",
"$",
"directory",
",",
"1",
")",
")",
";",
"$",
"config",
"=",
"[",
"]",
";",
"foreach",
"(",
"new",
"\\",
"DirectoryIterator",
"(",
"$",
"directory",
")",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"->",
"isDot",
"(",
")",
"||",
"$",
"file",
"->",
"getExtension",
"(",
")",
"!==",
"'php'",
")",
"{",
"continue",
";",
"}",
"// get the file parts",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"file",
"->",
"getFilename",
"(",
")",
")",
";",
"$",
"namespace",
"=",
"$",
"parts",
"[",
"0",
"]",
";",
"$",
"fileEnvironment",
"=",
"(",
"count",
"(",
"$",
"parts",
")",
"===",
"3",
"?",
"$",
"parts",
"[",
"1",
"]",
":",
"EnvironmentInterface",
"::",
"ENV_PRODUCTION",
")",
";",
"if",
"(",
"$",
"fileEnvironment",
"===",
"EnvironmentInterface",
"::",
"ENV_PRODUCTION",
"&&",
"!",
"array_key_exists",
"(",
"$",
"namespace",
",",
"$",
"config",
")",
")",
"{",
"// use the production configs by default",
"$",
"config",
"[",
"$",
"namespace",
"]",
"=",
"new",
"File",
"(",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"fileEnvironment",
"===",
"$",
"name",
")",
"{",
"// create the file resolver so we can resolve the",
"$",
"config",
"[",
"$",
"namespace",
"]",
"=",
"new",
"File",
"(",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
";",
"}",
"}",
"// add the environment variables to the config",
"$",
"config",
"[",
"'environment'",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'projectRoot'",
"=>",
"$",
"projectRoot",
",",
"]",
";",
"return",
"new",
"static",
"(",
"$",
"config",
")",
";",
"}"
] | From the environment object
@param EnvironmentInterface $environment
@param string $directory To be relative to the environment project root use ./config or /configs for full path
@return ConfigInterface | [
"From",
"the",
"environment",
"object"
] | 777f66de31603fc65a88416a7b502c1a2fe6d62b | https://github.com/mizmoz/config/blob/777f66de31603fc65a88416a7b502c1a2fe6d62b/src/Config.php#L175-L216 |
7,349 | ellipsephp/type-errors | src/Value.php | Value.type | public function type(): string
{
if (is_string($this->value)) {
return $this->string($this->value);
}
if (is_array($this->value)) {
return $this->array($this->value);
}
if (is_object($this->value)) {
return $this->object($this->value);
}
return gettype($this->value);
} | php | public function type(): string
{
if (is_string($this->value)) {
return $this->string($this->value);
}
if (is_array($this->value)) {
return $this->array($this->value);
}
if (is_object($this->value)) {
return $this->object($this->value);
}
return gettype($this->value);
} | [
"public",
"function",
"type",
"(",
")",
":",
"string",
"{",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"value",
")",
")",
"{",
"return",
"$",
"this",
"->",
"string",
"(",
"$",
"this",
"->",
"value",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"value",
")",
")",
"{",
"return",
"$",
"this",
"->",
"array",
"(",
"$",
"this",
"->",
"value",
")",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"this",
"->",
"value",
")",
")",
"{",
"return",
"$",
"this",
"->",
"object",
"(",
"$",
"this",
"->",
"value",
")",
";",
"}",
"return",
"gettype",
"(",
"$",
"this",
"->",
"value",
")",
";",
"}"
] | Return a detailled string representation of the value.
@return string | [
"Return",
"a",
"detailled",
"string",
"representation",
"of",
"the",
"value",
"."
] | 822df4d5d4df9ff2a09e903315d9aeadbe80be67 | https://github.com/ellipsephp/type-errors/blob/822df4d5d4df9ff2a09e903315d9aeadbe80be67/src/Value.php#L31-L52 |
7,350 | dms-org/package.content | src/Cms/Definition/ContentGroupDefiner.php | ContentGroupDefiner.withHtml | public function withHtml(string $name, string $label, string $containerElementCssSelector = null)
{
$this->contentGroup->htmlAreas[$name] = [
'name' => $name,
'label' => $label,
'selector' => $containerElementCssSelector,
'order' => $this->order++,
];
return $this;
} | php | public function withHtml(string $name, string $label, string $containerElementCssSelector = null)
{
$this->contentGroup->htmlAreas[$name] = [
'name' => $name,
'label' => $label,
'selector' => $containerElementCssSelector,
'order' => $this->order++,
];
return $this;
} | [
"public",
"function",
"withHtml",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"label",
",",
"string",
"$",
"containerElementCssSelector",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"contentGroup",
"->",
"htmlAreas",
"[",
"$",
"name",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'label'",
"=>",
"$",
"label",
",",
"'selector'",
"=>",
"$",
"containerElementCssSelector",
",",
"'order'",
"=>",
"$",
"this",
"->",
"order",
"++",
",",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Defines a HTML field.
@param string $name
@param string $label
@param string $containerElementCssSelector
@return static | [
"Defines",
"a",
"HTML",
"field",
"."
] | 6511e805c5be586c1f3740e095b49adabd621f80 | https://github.com/dms-org/package.content/blob/6511e805c5be586c1f3740e095b49adabd621f80/src/Cms/Definition/ContentGroupDefiner.php#L79-L89 |
7,351 | dms-org/package.content | src/Cms/Definition/ContentGroupDefiner.php | ContentGroupDefiner.withText | public function withText(string $name, string $label)
{
$this->contentGroup->textAreas[$name] = ['name' => $name, 'label' => $label, 'order' => $this->order++];
return $this;
} | php | public function withText(string $name, string $label)
{
$this->contentGroup->textAreas[$name] = ['name' => $name, 'label' => $label, 'order' => $this->order++];
return $this;
} | [
"public",
"function",
"withText",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"label",
")",
"{",
"$",
"this",
"->",
"contentGroup",
"->",
"textAreas",
"[",
"$",
"name",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'label'",
"=>",
"$",
"label",
",",
"'order'",
"=>",
"$",
"this",
"->",
"order",
"++",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Defines a text field.
@param string $name
@param string $label
@return static | [
"Defines",
"a",
"text",
"field",
"."
] | 6511e805c5be586c1f3740e095b49adabd621f80 | https://github.com/dms-org/package.content/blob/6511e805c5be586c1f3740e095b49adabd621f80/src/Cms/Definition/ContentGroupDefiner.php#L99-L104 |
7,352 | dms-org/package.content | src/Cms/Definition/ContentGroupDefiner.php | ContentGroupDefiner.withFile | public function withFile(string $name, string $label, array $allowedExtensions = null)
{
$this->contentGroup->fileAreas[$name] = ['name' => $name, 'label' => $label, 'allowed_extensions' => $allowedExtensions, 'order' => $this->order++];
return $this;
} | php | public function withFile(string $name, string $label, array $allowedExtensions = null)
{
$this->contentGroup->fileAreas[$name] = ['name' => $name, 'label' => $label, 'allowed_extensions' => $allowedExtensions, 'order' => $this->order++];
return $this;
} | [
"public",
"function",
"withFile",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"label",
",",
"array",
"$",
"allowedExtensions",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"contentGroup",
"->",
"fileAreas",
"[",
"$",
"name",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'label'",
"=>",
"$",
"label",
",",
"'allowed_extensions'",
"=>",
"$",
"allowedExtensions",
",",
"'order'",
"=>",
"$",
"this",
"->",
"order",
"++",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Defines a file upload field.
@param string $name
@param string $label
@param array|null $allowedExtensions
@return static | [
"Defines",
"a",
"file",
"upload",
"field",
"."
] | 6511e805c5be586c1f3740e095b49adabd621f80 | https://github.com/dms-org/package.content/blob/6511e805c5be586c1f3740e095b49adabd621f80/src/Cms/Definition/ContentGroupDefiner.php#L115-L120 |
7,353 | dms-org/package.content | src/Cms/Definition/ContentGroupDefiner.php | ContentGroupDefiner.withTextFromOptions | public function withTextFromOptions(string $name, string $label, array $valueLabelMap)
{
$this->contentGroup->textAreas[$name] = ['name' => $name, 'label' => $label, 'options' => $valueLabelMap, 'order' => $this->order++];
return $this;
} | php | public function withTextFromOptions(string $name, string $label, array $valueLabelMap)
{
$this->contentGroup->textAreas[$name] = ['name' => $name, 'label' => $label, 'options' => $valueLabelMap, 'order' => $this->order++];
return $this;
} | [
"public",
"function",
"withTextFromOptions",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"label",
",",
"array",
"$",
"valueLabelMap",
")",
"{",
"$",
"this",
"->",
"contentGroup",
"->",
"textAreas",
"[",
"$",
"name",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'label'",
"=>",
"$",
"label",
",",
"'options'",
"=>",
"$",
"valueLabelMap",
",",
"'order'",
"=>",
"$",
"this",
"->",
"order",
"++",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Defines a text field that must contain a value from one of the supplied options.
@param string $name
@param string $label
@param string[] $valueLabelMap
@return static | [
"Defines",
"a",
"text",
"field",
"that",
"must",
"contain",
"a",
"value",
"from",
"one",
"of",
"the",
"supplied",
"options",
"."
] | 6511e805c5be586c1f3740e095b49adabd621f80 | https://github.com/dms-org/package.content/blob/6511e805c5be586c1f3740e095b49adabd621f80/src/Cms/Definition/ContentGroupDefiner.php#L131-L136 |
7,354 | dms-org/package.content | src/Cms/Definition/ContentGroupDefiner.php | ContentGroupDefiner.withMetadata | public function withMetadata(string $name, string $label)
{
$this->contentGroup->metadata[$name] = ['name' => $name, 'label' => $label, 'order' => $this->order++];
return $this;
} | php | public function withMetadata(string $name, string $label)
{
$this->contentGroup->metadata[$name] = ['name' => $name, 'label' => $label, 'order' => $this->order++];
return $this;
} | [
"public",
"function",
"withMetadata",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"label",
")",
"{",
"$",
"this",
"->",
"contentGroup",
"->",
"metadata",
"[",
"$",
"name",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'label'",
"=>",
"$",
"label",
",",
"'order'",
"=>",
"$",
"this",
"->",
"order",
"++",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Defines a metadata field.
@param string $name
@param string $label
@return static | [
"Defines",
"a",
"metadata",
"field",
"."
] | 6511e805c5be586c1f3740e095b49adabd621f80 | https://github.com/dms-org/package.content/blob/6511e805c5be586c1f3740e095b49adabd621f80/src/Cms/Definition/ContentGroupDefiner.php#L146-L151 |
7,355 | dms-org/package.content | src/Cms/Definition/ContentGroupDefiner.php | ContentGroupDefiner.withArrayOf | public function withArrayOf(string $name, string $label, callable $elementContentDefinitionCallback)
{
$definition = new ContentGroupDefinition('__element__', $name);
$elementContentDefinitionCallback(new self($definition));
$this->contentGroup->nestedArrayContentGroups[$name] = [
'name' => $name,
'label' => $label,
'order' => $this->order++,
'definition' => $definition,
];
return $this;
} | php | public function withArrayOf(string $name, string $label, callable $elementContentDefinitionCallback)
{
$definition = new ContentGroupDefinition('__element__', $name);
$elementContentDefinitionCallback(new self($definition));
$this->contentGroup->nestedArrayContentGroups[$name] = [
'name' => $name,
'label' => $label,
'order' => $this->order++,
'definition' => $definition,
];
return $this;
} | [
"public",
"function",
"withArrayOf",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"label",
",",
"callable",
"$",
"elementContentDefinitionCallback",
")",
"{",
"$",
"definition",
"=",
"new",
"ContentGroupDefinition",
"(",
"'__element__'",
",",
"$",
"name",
")",
";",
"$",
"elementContentDefinitionCallback",
"(",
"new",
"self",
"(",
"$",
"definition",
")",
")",
";",
"$",
"this",
"->",
"contentGroup",
"->",
"nestedArrayContentGroups",
"[",
"$",
"name",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'label'",
"=>",
"$",
"label",
",",
"'order'",
"=>",
"$",
"this",
"->",
"order",
"++",
",",
"'definition'",
"=>",
"$",
"definition",
",",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Defines an array field.
Example:
<code>
->withArrayOf('some-slider', 'Multiple Images', function (ContentGroupDefiner $group) {
$group->withImage(...);
})
</code>
@param string $name
@param string $label
@param callable $elementContentDefinitionCallback
@return static | [
"Defines",
"an",
"array",
"field",
"."
] | 6511e805c5be586c1f3740e095b49adabd621f80 | https://github.com/dms-org/package.content/blob/6511e805c5be586c1f3740e095b49adabd621f80/src/Cms/Definition/ContentGroupDefiner.php#L169-L182 |
7,356 | indigophp-archive/queue | src/Connector/BeanstalkdConnector.php | BeanstalkdConnector.doClear | protected function doClear($queue, $state)
{
try {
while ($item = $this->pheanstalk->{'peek'.$state}($queue)) {
$this->pheanstalk->delete($item);
}
} catch (ServerException $e) {
}
return true;
} | php | protected function doClear($queue, $state)
{
try {
while ($item = $this->pheanstalk->{'peek'.$state}($queue)) {
$this->pheanstalk->delete($item);
}
} catch (ServerException $e) {
}
return true;
} | [
"protected",
"function",
"doClear",
"(",
"$",
"queue",
",",
"$",
"state",
")",
"{",
"try",
"{",
"while",
"(",
"$",
"item",
"=",
"$",
"this",
"->",
"pheanstalk",
"->",
"{",
"'peek'",
".",
"$",
"state",
"}",
"(",
"$",
"queue",
")",
")",
"{",
"$",
"this",
"->",
"pheanstalk",
"->",
"delete",
"(",
"$",
"item",
")",
";",
"}",
"}",
"catch",
"(",
"ServerException",
"$",
"e",
")",
"{",
"}",
"return",
"true",
";",
"}"
] | Clears a specific state
@param string $queue
@param string $state
@return boolean
@codeCoverageIgnore | [
"Clears",
"a",
"specific",
"state"
] | d364d5a1fc3b00d59846b19aa472d7f2aa130ff8 | https://github.com/indigophp-archive/queue/blob/d364d5a1fc3b00d59846b19aa472d7f2aa130ff8/src/Connector/BeanstalkdConnector.php#L174-L184 |
7,357 | sirgrimorum/crudgenerator | src/Traits/CrudModels.php | CrudModels.checkPermission | public static function checkPermission(array $config, $registro = 0, $action = "") {
if ($action == "") {
$action = substr(request()->route()->getName(), stripos(request()->route()->getName(), "::") + 2);
}
$resultado = true;
$general = false;
if (isset($config['permissions'])) {
if (isset($config['permissions'][$action])) {
$callback = $config['permissions'][$action];
} elseif (isset($config['permissions']['default'])) {
$callback = $config['permissions']['default'];
} else {
$general = true;
}
} else {
$general = true;
}
if ($general) {
$callback = config('sirgrimorum.crudgenerator.permission');
}
if (is_callable($callback)) {
if ($registro > 0) {
$objModelo = $config['modelo']::find($registro);
$resultado = (bool) $callback($objModelo);
} else {
$resultado = (bool) $callback();
}
} else {
$resultado = (bool) $callback;
}
return $resultado;
} | php | public static function checkPermission(array $config, $registro = 0, $action = "") {
if ($action == "") {
$action = substr(request()->route()->getName(), stripos(request()->route()->getName(), "::") + 2);
}
$resultado = true;
$general = false;
if (isset($config['permissions'])) {
if (isset($config['permissions'][$action])) {
$callback = $config['permissions'][$action];
} elseif (isset($config['permissions']['default'])) {
$callback = $config['permissions']['default'];
} else {
$general = true;
}
} else {
$general = true;
}
if ($general) {
$callback = config('sirgrimorum.crudgenerator.permission');
}
if (is_callable($callback)) {
if ($registro > 0) {
$objModelo = $config['modelo']::find($registro);
$resultado = (bool) $callback($objModelo);
} else {
$resultado = (bool) $callback();
}
} else {
$resultado = (bool) $callback;
}
return $resultado;
} | [
"public",
"static",
"function",
"checkPermission",
"(",
"array",
"$",
"config",
",",
"$",
"registro",
"=",
"0",
",",
"$",
"action",
"=",
"\"\"",
")",
"{",
"if",
"(",
"$",
"action",
"==",
"\"\"",
")",
"{",
"$",
"action",
"=",
"substr",
"(",
"request",
"(",
")",
"->",
"route",
"(",
")",
"->",
"getName",
"(",
")",
",",
"stripos",
"(",
"request",
"(",
")",
"->",
"route",
"(",
")",
"->",
"getName",
"(",
")",
",",
"\"::\"",
")",
"+",
"2",
")",
";",
"}",
"$",
"resultado",
"=",
"true",
";",
"$",
"general",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'permissions'",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'permissions'",
"]",
"[",
"$",
"action",
"]",
")",
")",
"{",
"$",
"callback",
"=",
"$",
"config",
"[",
"'permissions'",
"]",
"[",
"$",
"action",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"config",
"[",
"'permissions'",
"]",
"[",
"'default'",
"]",
")",
")",
"{",
"$",
"callback",
"=",
"$",
"config",
"[",
"'permissions'",
"]",
"[",
"'default'",
"]",
";",
"}",
"else",
"{",
"$",
"general",
"=",
"true",
";",
"}",
"}",
"else",
"{",
"$",
"general",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"general",
")",
"{",
"$",
"callback",
"=",
"config",
"(",
"'sirgrimorum.crudgenerator.permission'",
")",
";",
"}",
"if",
"(",
"is_callable",
"(",
"$",
"callback",
")",
")",
"{",
"if",
"(",
"$",
"registro",
">",
"0",
")",
"{",
"$",
"objModelo",
"=",
"$",
"config",
"[",
"'modelo'",
"]",
"::",
"find",
"(",
"$",
"registro",
")",
";",
"$",
"resultado",
"=",
"(",
"bool",
")",
"$",
"callback",
"(",
"$",
"objModelo",
")",
";",
"}",
"else",
"{",
"$",
"resultado",
"=",
"(",
"bool",
")",
"$",
"callback",
"(",
")",
";",
"}",
"}",
"else",
"{",
"$",
"resultado",
"=",
"(",
"bool",
")",
"$",
"callback",
";",
"}",
"return",
"$",
"resultado",
";",
"}"
] | Evaluate the "permissions" callbacks in the configuration array
@param array $config The configuration array
@param int $registro Optional The id of the registry
@param string $action Optional The actual action
@return boolean if the user has or not permission | [
"Evaluate",
"the",
"permissions",
"callbacks",
"in",
"the",
"configuration",
"array"
] | 4431e9991a705689be50c4367776dc611bffb863 | https://github.com/sirgrimorum/crudgenerator/blob/4431e9991a705689be50c4367776dc611bffb863/src/Traits/CrudModels.php#L14-L46 |
7,358 | sirgrimorum/crudgenerator | src/Traits/CrudModels.php | CrudModels.evaluateFilterWithSingleQuery | private static function evaluateFilterWithSingleQuery($registro, $query, $attri) {
//echo "<p>evaluando {$registro->name}</p><pre>" . print_r([$query, $attri], true) . "</pre>";
$contiene = false;
if (stripos($query, "*%") !== false) {
$contiene = true;
$query = str_replace("*%", "", $query);
}
if (($numArgs = \Sirgrimorum\CrudGenerator\CrudGenerator::isFunction($registro, $attri)) !== false) {
//echo "<p>NumArgs $numArgs</p>";
if (\Sirgrimorum\CrudGenerator\CrudGenerator::isJsonString($query)) {
$queryArr = json_decode($query, true);
} else {
$queryArr = [$query];
}
$result = \Sirgrimorum\CrudGenerator\CrudGenerator::callFunction($registro, $attri, $queryArr, $numArgs);
if ($result === false || $result === null) {
return false;
} else {
$queryObj = array_pop($queryArr);
if ($result != $queryObj) {
return false;
}
}
} elseif (is_string($registro->{$attri})) {
//echo "<p> stripos es " . stripos($registro->{$attri}, $query) . " jajaj</p>";
if ($contiene) {
if (stripos($registro->{$attri}, $query) === false) {
return false;
}
} else {
if ($registro->{$attri} != $query) {
return false;
}
}
} else {
if ((string) $registro->{$attri} != $query) {
return false;
}
}
return true;
} | php | private static function evaluateFilterWithSingleQuery($registro, $query, $attri) {
//echo "<p>evaluando {$registro->name}</p><pre>" . print_r([$query, $attri], true) . "</pre>";
$contiene = false;
if (stripos($query, "*%") !== false) {
$contiene = true;
$query = str_replace("*%", "", $query);
}
if (($numArgs = \Sirgrimorum\CrudGenerator\CrudGenerator::isFunction($registro, $attri)) !== false) {
//echo "<p>NumArgs $numArgs</p>";
if (\Sirgrimorum\CrudGenerator\CrudGenerator::isJsonString($query)) {
$queryArr = json_decode($query, true);
} else {
$queryArr = [$query];
}
$result = \Sirgrimorum\CrudGenerator\CrudGenerator::callFunction($registro, $attri, $queryArr, $numArgs);
if ($result === false || $result === null) {
return false;
} else {
$queryObj = array_pop($queryArr);
if ($result != $queryObj) {
return false;
}
}
} elseif (is_string($registro->{$attri})) {
//echo "<p> stripos es " . stripos($registro->{$attri}, $query) . " jajaj</p>";
if ($contiene) {
if (stripos($registro->{$attri}, $query) === false) {
return false;
}
} else {
if ($registro->{$attri} != $query) {
return false;
}
}
} else {
if ((string) $registro->{$attri} != $query) {
return false;
}
}
return true;
} | [
"private",
"static",
"function",
"evaluateFilterWithSingleQuery",
"(",
"$",
"registro",
",",
"$",
"query",
",",
"$",
"attri",
")",
"{",
"//echo \"<p>evaluando {$registro->name}</p><pre>\" . print_r([$query, $attri], true) . \"</pre>\";",
"$",
"contiene",
"=",
"false",
";",
"if",
"(",
"stripos",
"(",
"$",
"query",
",",
"\"*%\"",
")",
"!==",
"false",
")",
"{",
"$",
"contiene",
"=",
"true",
";",
"$",
"query",
"=",
"str_replace",
"(",
"\"*%\"",
",",
"\"\"",
",",
"$",
"query",
")",
";",
"}",
"if",
"(",
"(",
"$",
"numArgs",
"=",
"\\",
"Sirgrimorum",
"\\",
"CrudGenerator",
"\\",
"CrudGenerator",
"::",
"isFunction",
"(",
"$",
"registro",
",",
"$",
"attri",
")",
")",
"!==",
"false",
")",
"{",
"//echo \"<p>NumArgs $numArgs</p>\";",
"if",
"(",
"\\",
"Sirgrimorum",
"\\",
"CrudGenerator",
"\\",
"CrudGenerator",
"::",
"isJsonString",
"(",
"$",
"query",
")",
")",
"{",
"$",
"queryArr",
"=",
"json_decode",
"(",
"$",
"query",
",",
"true",
")",
";",
"}",
"else",
"{",
"$",
"queryArr",
"=",
"[",
"$",
"query",
"]",
";",
"}",
"$",
"result",
"=",
"\\",
"Sirgrimorum",
"\\",
"CrudGenerator",
"\\",
"CrudGenerator",
"::",
"callFunction",
"(",
"$",
"registro",
",",
"$",
"attri",
",",
"$",
"queryArr",
",",
"$",
"numArgs",
")",
";",
"if",
"(",
"$",
"result",
"===",
"false",
"||",
"$",
"result",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"queryObj",
"=",
"array_pop",
"(",
"$",
"queryArr",
")",
";",
"if",
"(",
"$",
"result",
"!=",
"$",
"queryObj",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"registro",
"->",
"{",
"$",
"attri",
"}",
")",
")",
"{",
"//echo \"<p> stripos es \" . stripos($registro->{$attri}, $query) . \" jajaj</p>\";",
"if",
"(",
"$",
"contiene",
")",
"{",
"if",
"(",
"stripos",
"(",
"$",
"registro",
"->",
"{",
"$",
"attri",
"}",
",",
"$",
"query",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"registro",
"->",
"{",
"$",
"attri",
"}",
"!=",
"$",
"query",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"(",
"string",
")",
"$",
"registro",
"->",
"{",
"$",
"attri",
"}",
"!=",
"$",
"query",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Filter an object of a model with a single query. It will use AND operation.
If $attri is a method or function fo the object it will try to evaluate it with
$query as parametter. Use a Json string to pass more than one parametter.
If the returned value is not a boolean or null, will use the $query or the las value of
the $query array to comare.
If $attri is only an attribute, it will compare against $query as it is.
if $query contains "*%" it will erase them and evaluate if $query is contained in the attribute value.
Not aplicable for function or methods returns
@param object $registro The model object
@param string $query The query to evaluate
@param string $attri The attribute to compare
@return boolean | [
"Filter",
"an",
"object",
"of",
"a",
"model",
"with",
"a",
"single",
"query",
".",
"It",
"will",
"use",
"AND",
"operation",
"."
] | 4431e9991a705689be50c4367776dc611bffb863 | https://github.com/sirgrimorum/crudgenerator/blob/4431e9991a705689be50c4367776dc611bffb863/src/Traits/CrudModels.php#L539-L580 |
7,359 | sirgrimorum/crudgenerator | src/Traits/CrudModels.php | CrudModels.filterWithQuery | private static function filterWithQuery($registros, $config, $datos = [], $orOperation = "_or", $queryStr = "_q", $attriStr = "_a", $aByAStr = "_aByA") {
if (count($datos) == 0) {
$datos = request()->all();
}
//echo "<pre>" . print_r($datos, true) . "</pre>";
if (!is_bool($orOperation)) {
if (isset($datos[$orOperation])) {
$orOperation = !($datos[$orOperation] === 'false');
} else {
$orOperation = true;
}
}
if (isset($datos[$queryStr])) {
$query = $datos[$queryStr];
if (\Sirgrimorum\CrudGenerator\CrudGenerator::isJsonString($query)) {
$query = json_decode($query, true);
} elseif (stripos($query, "|")) {
$query = explode("|", $query);
}
if (isset($datos[$attriStr])) {
$attri = $datos[$attriStr];
if (\Sirgrimorum\CrudGenerator\CrudGenerator::isJsonString($attri)) {
$attri = json_decode($attri, true);
} elseif (stripos($attri, "|")) {
$attri = explode("|", $attri);
}
} else {
$attri = $config['nombre'];
}
$fbf = isset($datos[$aByAStr]);
$registros = $registros->filter(function($registro) use($query, $attri, $fbf, $orOperation) {
return \Sirgrimorum\CrudGenerator\CrudGenerator::evaluateFilter($registro, $query, $attri, $orOperation, $fbf);
});
}
return $registros;
} | php | private static function filterWithQuery($registros, $config, $datos = [], $orOperation = "_or", $queryStr = "_q", $attriStr = "_a", $aByAStr = "_aByA") {
if (count($datos) == 0) {
$datos = request()->all();
}
//echo "<pre>" . print_r($datos, true) . "</pre>";
if (!is_bool($orOperation)) {
if (isset($datos[$orOperation])) {
$orOperation = !($datos[$orOperation] === 'false');
} else {
$orOperation = true;
}
}
if (isset($datos[$queryStr])) {
$query = $datos[$queryStr];
if (\Sirgrimorum\CrudGenerator\CrudGenerator::isJsonString($query)) {
$query = json_decode($query, true);
} elseif (stripos($query, "|")) {
$query = explode("|", $query);
}
if (isset($datos[$attriStr])) {
$attri = $datos[$attriStr];
if (\Sirgrimorum\CrudGenerator\CrudGenerator::isJsonString($attri)) {
$attri = json_decode($attri, true);
} elseif (stripos($attri, "|")) {
$attri = explode("|", $attri);
}
} else {
$attri = $config['nombre'];
}
$fbf = isset($datos[$aByAStr]);
$registros = $registros->filter(function($registro) use($query, $attri, $fbf, $orOperation) {
return \Sirgrimorum\CrudGenerator\CrudGenerator::evaluateFilter($registro, $query, $attri, $orOperation, $fbf);
});
}
return $registros;
} | [
"private",
"static",
"function",
"filterWithQuery",
"(",
"$",
"registros",
",",
"$",
"config",
",",
"$",
"datos",
"=",
"[",
"]",
",",
"$",
"orOperation",
"=",
"\"_or\"",
",",
"$",
"queryStr",
"=",
"\"_q\"",
",",
"$",
"attriStr",
"=",
"\"_a\"",
",",
"$",
"aByAStr",
"=",
"\"_aByA\"",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"datos",
")",
"==",
"0",
")",
"{",
"$",
"datos",
"=",
"request",
"(",
")",
"->",
"all",
"(",
")",
";",
"}",
"//echo \"<pre>\" . print_r($datos, true) . \"</pre>\";",
"if",
"(",
"!",
"is_bool",
"(",
"$",
"orOperation",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"datos",
"[",
"$",
"orOperation",
"]",
")",
")",
"{",
"$",
"orOperation",
"=",
"!",
"(",
"$",
"datos",
"[",
"$",
"orOperation",
"]",
"===",
"'false'",
")",
";",
"}",
"else",
"{",
"$",
"orOperation",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"datos",
"[",
"$",
"queryStr",
"]",
")",
")",
"{",
"$",
"query",
"=",
"$",
"datos",
"[",
"$",
"queryStr",
"]",
";",
"if",
"(",
"\\",
"Sirgrimorum",
"\\",
"CrudGenerator",
"\\",
"CrudGenerator",
"::",
"isJsonString",
"(",
"$",
"query",
")",
")",
"{",
"$",
"query",
"=",
"json_decode",
"(",
"$",
"query",
",",
"true",
")",
";",
"}",
"elseif",
"(",
"stripos",
"(",
"$",
"query",
",",
"\"|\"",
")",
")",
"{",
"$",
"query",
"=",
"explode",
"(",
"\"|\"",
",",
"$",
"query",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"datos",
"[",
"$",
"attriStr",
"]",
")",
")",
"{",
"$",
"attri",
"=",
"$",
"datos",
"[",
"$",
"attriStr",
"]",
";",
"if",
"(",
"\\",
"Sirgrimorum",
"\\",
"CrudGenerator",
"\\",
"CrudGenerator",
"::",
"isJsonString",
"(",
"$",
"attri",
")",
")",
"{",
"$",
"attri",
"=",
"json_decode",
"(",
"$",
"attri",
",",
"true",
")",
";",
"}",
"elseif",
"(",
"stripos",
"(",
"$",
"attri",
",",
"\"|\"",
")",
")",
"{",
"$",
"attri",
"=",
"explode",
"(",
"\"|\"",
",",
"$",
"attri",
")",
";",
"}",
"}",
"else",
"{",
"$",
"attri",
"=",
"$",
"config",
"[",
"'nombre'",
"]",
";",
"}",
"$",
"fbf",
"=",
"isset",
"(",
"$",
"datos",
"[",
"$",
"aByAStr",
"]",
")",
";",
"$",
"registros",
"=",
"$",
"registros",
"->",
"filter",
"(",
"function",
"(",
"$",
"registro",
")",
"use",
"(",
"$",
"query",
",",
"$",
"attri",
",",
"$",
"fbf",
",",
"$",
"orOperation",
")",
"{",
"return",
"\\",
"Sirgrimorum",
"\\",
"CrudGenerator",
"\\",
"CrudGenerator",
"::",
"evaluateFilter",
"(",
"$",
"registro",
",",
"$",
"query",
",",
"$",
"attri",
",",
"$",
"orOperation",
",",
"$",
"fbf",
")",
";",
"}",
")",
";",
"}",
"return",
"$",
"registros",
";",
"}"
] | Filter a collection of object models using a query an attribute sets in an array.
The values in the $datos object must be strings, if using arrays, use json notation or separate the values with an |.
If not attribute is given, it will compare against the $config('nombre'] attribute
If $query contains "*%" it will erase them and evaluate if $query is contained in the attribute value.
Not aplicable for function or methods returns
@param object $registros Collection of elocuent model objects
@param array $config Configuration array for the Model
@param boolean|string $orOperation Optional boolean or the key of the or value in $datos. if True: use or operation (just one query must be true), false will use and operation (all the querys must be true).
@param array $datos Optional the data. if empty, it will get the current request data.
@param string $queryStr Optional the key of the query in $datos
@param string $attriStr Optional the key of the attributes in $datos
@param string $aByAStr Optional the key of the value indicating if the $query and $attribute must be evaluated one by one (ej: $query[0] vs $attribute[0] AND $query[1] vs $attribute[1], ...)
@return array Collection filtered | [
"Filter",
"a",
"collection",
"of",
"object",
"models",
"using",
"a",
"query",
"an",
"attribute",
"sets",
"in",
"an",
"array",
"."
] | 4431e9991a705689be50c4367776dc611bffb863 | https://github.com/sirgrimorum/crudgenerator/blob/4431e9991a705689be50c4367776dc611bffb863/src/Traits/CrudModels.php#L745-L780 |
7,360 | sirgrimorum/crudgenerator | src/Traits/CrudModels.php | CrudModels.syncHasMany | public static function syncHasMany($model, $campo, $children_items, $config) {
$children = $model->{$campo};
$children_items = collect($children_items);
$deleted_ids = $children->filter(
function ($child) use ($children_items) {
return empty(
$children_items->where($config[$campo]['id'], $child->$config[$campo]['id'])->first()
);
}
)->map(function ($child) {
$id = $child->id;
$child->delete();
return $id;
}
);
$attachments = $children_items->filter(
function ($children_item) {
return empty($children_item->$config[$campo]['id']);
}
)->map(function ($children_item) use ($deleted_ids) {
$children_item->$config[$campo]['id'] = $deleted_ids->pop();
return new $config[$campo]['modelo']($children_item);
});
$model->{$campo}()->saveMany($attachments);
} | php | public static function syncHasMany($model, $campo, $children_items, $config) {
$children = $model->{$campo};
$children_items = collect($children_items);
$deleted_ids = $children->filter(
function ($child) use ($children_items) {
return empty(
$children_items->where($config[$campo]['id'], $child->$config[$campo]['id'])->first()
);
}
)->map(function ($child) {
$id = $child->id;
$child->delete();
return $id;
}
);
$attachments = $children_items->filter(
function ($children_item) {
return empty($children_item->$config[$campo]['id']);
}
)->map(function ($children_item) use ($deleted_ids) {
$children_item->$config[$campo]['id'] = $deleted_ids->pop();
return new $config[$campo]['modelo']($children_item);
});
$model->{$campo}()->saveMany($attachments);
} | [
"public",
"static",
"function",
"syncHasMany",
"(",
"$",
"model",
",",
"$",
"campo",
",",
"$",
"children_items",
",",
"$",
"config",
")",
"{",
"$",
"children",
"=",
"$",
"model",
"->",
"{",
"$",
"campo",
"}",
";",
"$",
"children_items",
"=",
"collect",
"(",
"$",
"children_items",
")",
";",
"$",
"deleted_ids",
"=",
"$",
"children",
"->",
"filter",
"(",
"function",
"(",
"$",
"child",
")",
"use",
"(",
"$",
"children_items",
")",
"{",
"return",
"empty",
"(",
"$",
"children_items",
"->",
"where",
"(",
"$",
"config",
"[",
"$",
"campo",
"]",
"[",
"'id'",
"]",
",",
"$",
"child",
"->",
"$",
"config",
"[",
"$",
"campo",
"]",
"[",
"'id'",
"]",
")",
"->",
"first",
"(",
")",
")",
";",
"}",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"child",
")",
"{",
"$",
"id",
"=",
"$",
"child",
"->",
"id",
";",
"$",
"child",
"->",
"delete",
"(",
")",
";",
"return",
"$",
"id",
";",
"}",
")",
";",
"$",
"attachments",
"=",
"$",
"children_items",
"->",
"filter",
"(",
"function",
"(",
"$",
"children_item",
")",
"{",
"return",
"empty",
"(",
"$",
"children_item",
"->",
"$",
"config",
"[",
"$",
"campo",
"]",
"[",
"'id'",
"]",
")",
";",
"}",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"children_item",
")",
"use",
"(",
"$",
"deleted_ids",
")",
"{",
"$",
"children_item",
"->",
"$",
"config",
"[",
"$",
"campo",
"]",
"[",
"'id'",
"]",
"=",
"$",
"deleted_ids",
"->",
"pop",
"(",
")",
";",
"return",
"new",
"$",
"config",
"[",
"$",
"campo",
"]",
"[",
"'modelo'",
"]",
"(",
"$",
"children_item",
")",
";",
"}",
")",
";",
"$",
"model",
"->",
"{",
"$",
"campo",
"}",
"(",
")",
"->",
"saveMany",
"(",
"$",
"attachments",
")",
";",
"}"
] | Sync a HasMany relationsihp
@param object $model The model to sync
@param string $campo The name of the method with the hasMany relationsihp
@param array $children_items An array with the models to sync with
@param array $config The configuration array of the model | [
"Sync",
"a",
"HasMany",
"relationsihp"
] | 4431e9991a705689be50c4367776dc611bffb863 | https://github.com/sirgrimorum/crudgenerator/blob/4431e9991a705689be50c4367776dc611bffb863/src/Traits/CrudModels.php#L789-L813 |
7,361 | sirgrimorum/crudgenerator | src/Traits/CrudModels.php | CrudModels.validateModel | public static function validateModel(array $config, \Illuminate\Http\Request $request = null) {
if (is_null($request)) {
$request = request();
}
$rules = [];
$modeloM = class_basename($config["modelo"]);
$modelo = strtolower($modeloM);
if (isset($config['rules'])) {
if (is_array($config['rules'])) {
$rules = $config['rules'];
}
}
if (count($rules) == 0) {
$objModelo = new $config['modelo'];
if (isset($objModelo->rules)) {
if (is_array($objModelo->rules)) {
$rules = $objModelo->rules;
}
}
}
$auxIdCambio = $request->get($config["id"]);
$rules = \Sirgrimorum\CrudGenerator\CrudGenerator::translateArray($rules, ":model", function($string) use ($auxIdCambio) {
return $auxIdCambio;
}, "Id");
if (count($rules) > 0) {
$customAttributes = [];
foreach ($rules as $field => $datos) {
if (array_has($config, "campos." . $field . ".label")) {
$customAttributes[$field] = array_get($config, "campos." . $field . ".label");
}
}
$error_messages = [];
if (isset($config['error_messages'])) {
if (is_array($config['error_messages'])) {
$error_messages = $config['error_messages'];
}
}
if (count($error_messages) == 0) {
$objModelo = new $config['modelo'];
if (isset($objModelo->error_messages)) {
if (is_array($objModelo->error_messages)) {
$error_messages = $objModelo->error_messages;
}
}
}
$error_messages = array_merge(trans("crudgenerator::admin.error_messages"), $error_messages);
$validator = \Illuminate\Support\Facades\Validator::make($request->all(), $rules, $error_messages, $customAttributes);
return $validator;
}
return false;
} | php | public static function validateModel(array $config, \Illuminate\Http\Request $request = null) {
if (is_null($request)) {
$request = request();
}
$rules = [];
$modeloM = class_basename($config["modelo"]);
$modelo = strtolower($modeloM);
if (isset($config['rules'])) {
if (is_array($config['rules'])) {
$rules = $config['rules'];
}
}
if (count($rules) == 0) {
$objModelo = new $config['modelo'];
if (isset($objModelo->rules)) {
if (is_array($objModelo->rules)) {
$rules = $objModelo->rules;
}
}
}
$auxIdCambio = $request->get($config["id"]);
$rules = \Sirgrimorum\CrudGenerator\CrudGenerator::translateArray($rules, ":model", function($string) use ($auxIdCambio) {
return $auxIdCambio;
}, "Id");
if (count($rules) > 0) {
$customAttributes = [];
foreach ($rules as $field => $datos) {
if (array_has($config, "campos." . $field . ".label")) {
$customAttributes[$field] = array_get($config, "campos." . $field . ".label");
}
}
$error_messages = [];
if (isset($config['error_messages'])) {
if (is_array($config['error_messages'])) {
$error_messages = $config['error_messages'];
}
}
if (count($error_messages) == 0) {
$objModelo = new $config['modelo'];
if (isset($objModelo->error_messages)) {
if (is_array($objModelo->error_messages)) {
$error_messages = $objModelo->error_messages;
}
}
}
$error_messages = array_merge(trans("crudgenerator::admin.error_messages"), $error_messages);
$validator = \Illuminate\Support\Facades\Validator::make($request->all(), $rules, $error_messages, $customAttributes);
return $validator;
}
return false;
} | [
"public",
"static",
"function",
"validateModel",
"(",
"array",
"$",
"config",
",",
"\\",
"Illuminate",
"\\",
"Http",
"\\",
"Request",
"$",
"request",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"request",
")",
")",
"{",
"$",
"request",
"=",
"request",
"(",
")",
";",
"}",
"$",
"rules",
"=",
"[",
"]",
";",
"$",
"modeloM",
"=",
"class_basename",
"(",
"$",
"config",
"[",
"\"modelo\"",
"]",
")",
";",
"$",
"modelo",
"=",
"strtolower",
"(",
"$",
"modeloM",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'rules'",
"]",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"config",
"[",
"'rules'",
"]",
")",
")",
"{",
"$",
"rules",
"=",
"$",
"config",
"[",
"'rules'",
"]",
";",
"}",
"}",
"if",
"(",
"count",
"(",
"$",
"rules",
")",
"==",
"0",
")",
"{",
"$",
"objModelo",
"=",
"new",
"$",
"config",
"[",
"'modelo'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"objModelo",
"->",
"rules",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"objModelo",
"->",
"rules",
")",
")",
"{",
"$",
"rules",
"=",
"$",
"objModelo",
"->",
"rules",
";",
"}",
"}",
"}",
"$",
"auxIdCambio",
"=",
"$",
"request",
"->",
"get",
"(",
"$",
"config",
"[",
"\"id\"",
"]",
")",
";",
"$",
"rules",
"=",
"\\",
"Sirgrimorum",
"\\",
"CrudGenerator",
"\\",
"CrudGenerator",
"::",
"translateArray",
"(",
"$",
"rules",
",",
"\":model\"",
",",
"function",
"(",
"$",
"string",
")",
"use",
"(",
"$",
"auxIdCambio",
")",
"{",
"return",
"$",
"auxIdCambio",
";",
"}",
",",
"\"Id\"",
")",
";",
"if",
"(",
"count",
"(",
"$",
"rules",
")",
">",
"0",
")",
"{",
"$",
"customAttributes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"field",
"=>",
"$",
"datos",
")",
"{",
"if",
"(",
"array_has",
"(",
"$",
"config",
",",
"\"campos.\"",
".",
"$",
"field",
".",
"\".label\"",
")",
")",
"{",
"$",
"customAttributes",
"[",
"$",
"field",
"]",
"=",
"array_get",
"(",
"$",
"config",
",",
"\"campos.\"",
".",
"$",
"field",
".",
"\".label\"",
")",
";",
"}",
"}",
"$",
"error_messages",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'error_messages'",
"]",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"config",
"[",
"'error_messages'",
"]",
")",
")",
"{",
"$",
"error_messages",
"=",
"$",
"config",
"[",
"'error_messages'",
"]",
";",
"}",
"}",
"if",
"(",
"count",
"(",
"$",
"error_messages",
")",
"==",
"0",
")",
"{",
"$",
"objModelo",
"=",
"new",
"$",
"config",
"[",
"'modelo'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"objModelo",
"->",
"error_messages",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"objModelo",
"->",
"error_messages",
")",
")",
"{",
"$",
"error_messages",
"=",
"$",
"objModelo",
"->",
"error_messages",
";",
"}",
"}",
"}",
"$",
"error_messages",
"=",
"array_merge",
"(",
"trans",
"(",
"\"crudgenerator::admin.error_messages\"",
")",
",",
"$",
"error_messages",
")",
";",
"$",
"validator",
"=",
"\\",
"Illuminate",
"\\",
"Support",
"\\",
"Facades",
"\\",
"Validator",
"::",
"make",
"(",
"$",
"request",
"->",
"all",
"(",
")",
",",
"$",
"rules",
",",
"$",
"error_messages",
",",
"$",
"customAttributes",
")",
";",
"return",
"$",
"validator",
";",
"}",
"return",
"false",
";",
"}"
] | Runs a validation of a request based on a model and its configuration array
@param array $config The configuration array
@param Request $request Optional the request. If null, it will use request() function
@return mix Retuns the validator or false if there are no rules | [
"Runs",
"a",
"validation",
"of",
"a",
"request",
"based",
"on",
"a",
"model",
"and",
"its",
"configuration",
"array"
] | 4431e9991a705689be50c4367776dc611bffb863 | https://github.com/sirgrimorum/crudgenerator/blob/4431e9991a705689be50c4367776dc611bffb863/src/Traits/CrudModels.php#L821-L872 |
7,362 | sirgrimorum/crudgenerator | src/Traits/CrudModels.php | CrudModels.buildConditionalArray | public static function buildConditionalArray(array $config, string $action = "-") {
if ($action == "") {
$action = substr(request()->route()->getName(), stripos(request()->route()->getName(), "::") + 2);
}
$condiciones = [];
$validadores = [];
$tabla = $config['tabla'];
foreach ($config['campos'] as $campo => $datos) {
if (\Sirgrimorum\CrudGenerator\CrudGenerator::inside_array($datos, "hide", $action) === false) {
if (isset($datos['conditional'])) {
if (is_array($datos['conditional'])) {
$validadores["{$tabla}_{$campo}"] = [];
foreach ($datos['conditional'] as $conCampo => $conValor) {
if (!isset($condiciones["{$tabla}_{$conCampo}"])) {
$condiciones["{$tabla}_{$conCampo}"] = [];
}
$condiciones["{$tabla}_{$conCampo}"][] = "{$tabla}_{$campo}";
$validadores["{$tabla}_{$campo}"]["{$tabla}_{$conCampo}"] = $conValor;
}
}
}
}
}
return [$condiciones, $validadores];
} | php | public static function buildConditionalArray(array $config, string $action = "-") {
if ($action == "") {
$action = substr(request()->route()->getName(), stripos(request()->route()->getName(), "::") + 2);
}
$condiciones = [];
$validadores = [];
$tabla = $config['tabla'];
foreach ($config['campos'] as $campo => $datos) {
if (\Sirgrimorum\CrudGenerator\CrudGenerator::inside_array($datos, "hide", $action) === false) {
if (isset($datos['conditional'])) {
if (is_array($datos['conditional'])) {
$validadores["{$tabla}_{$campo}"] = [];
foreach ($datos['conditional'] as $conCampo => $conValor) {
if (!isset($condiciones["{$tabla}_{$conCampo}"])) {
$condiciones["{$tabla}_{$conCampo}"] = [];
}
$condiciones["{$tabla}_{$conCampo}"][] = "{$tabla}_{$campo}";
$validadores["{$tabla}_{$campo}"]["{$tabla}_{$conCampo}"] = $conValor;
}
}
}
}
}
return [$condiciones, $validadores];
} | [
"public",
"static",
"function",
"buildConditionalArray",
"(",
"array",
"$",
"config",
",",
"string",
"$",
"action",
"=",
"\"-\"",
")",
"{",
"if",
"(",
"$",
"action",
"==",
"\"\"",
")",
"{",
"$",
"action",
"=",
"substr",
"(",
"request",
"(",
")",
"->",
"route",
"(",
")",
"->",
"getName",
"(",
")",
",",
"stripos",
"(",
"request",
"(",
")",
"->",
"route",
"(",
")",
"->",
"getName",
"(",
")",
",",
"\"::\"",
")",
"+",
"2",
")",
";",
"}",
"$",
"condiciones",
"=",
"[",
"]",
";",
"$",
"validadores",
"=",
"[",
"]",
";",
"$",
"tabla",
"=",
"$",
"config",
"[",
"'tabla'",
"]",
";",
"foreach",
"(",
"$",
"config",
"[",
"'campos'",
"]",
"as",
"$",
"campo",
"=>",
"$",
"datos",
")",
"{",
"if",
"(",
"\\",
"Sirgrimorum",
"\\",
"CrudGenerator",
"\\",
"CrudGenerator",
"::",
"inside_array",
"(",
"$",
"datos",
",",
"\"hide\"",
",",
"$",
"action",
")",
"===",
"false",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"datos",
"[",
"'conditional'",
"]",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"datos",
"[",
"'conditional'",
"]",
")",
")",
"{",
"$",
"validadores",
"[",
"\"{$tabla}_{$campo}\"",
"]",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"datos",
"[",
"'conditional'",
"]",
"as",
"$",
"conCampo",
"=>",
"$",
"conValor",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"condiciones",
"[",
"\"{$tabla}_{$conCampo}\"",
"]",
")",
")",
"{",
"$",
"condiciones",
"[",
"\"{$tabla}_{$conCampo}\"",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"condiciones",
"[",
"\"{$tabla}_{$conCampo}\"",
"]",
"[",
"]",
"=",
"\"{$tabla}_{$campo}\"",
";",
"$",
"validadores",
"[",
"\"{$tabla}_{$campo}\"",
"]",
"[",
"\"{$tabla}_{$conCampo}\"",
"]",
"=",
"$",
"conValor",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"[",
"$",
"condiciones",
",",
"$",
"validadores",
"]",
";",
"}"
] | Build the array for conditional fields using a configuration array
@param array $config The ocnfiguration array
@param string $action Optional the action (create, edit, etc) where the conditionals are needed | [
"Build",
"the",
"array",
"for",
"conditional",
"fields",
"using",
"a",
"configuration",
"array"
] | 4431e9991a705689be50c4367776dc611bffb863 | https://github.com/sirgrimorum/crudgenerator/blob/4431e9991a705689be50c4367776dc611bffb863/src/Traits/CrudModels.php#L1278-L1302 |
7,363 | lucidphp/xml | src/Writer.php | Writer.useKeyAsValue | public function useKeyAsValue($key, $normalize = false)
{
if (true !== $normalize && !$this->isValidNodeName($key)) {
throw new \InvalidArgumentException(sprintf('%s is an invalid node name', $key));
}
$this->nodeValueKey = $normalize ? $this->normalizer->normalize($key) : $key;
} | php | public function useKeyAsValue($key, $normalize = false)
{
if (true !== $normalize && !$this->isValidNodeName($key)) {
throw new \InvalidArgumentException(sprintf('%s is an invalid node name', $key));
}
$this->nodeValueKey = $normalize ? $this->normalizer->normalize($key) : $key;
} | [
"public",
"function",
"useKeyAsValue",
"(",
"$",
"key",
",",
"$",
"normalize",
"=",
"false",
")",
"{",
"if",
"(",
"true",
"!==",
"$",
"normalize",
"&&",
"!",
"$",
"this",
"->",
"isValidNodeName",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'%s is an invalid node name'",
",",
"$",
"key",
")",
")",
";",
"}",
"$",
"this",
"->",
"nodeValueKey",
"=",
"$",
"normalize",
"?",
"$",
"this",
"->",
"normalizer",
"->",
"normalize",
"(",
"$",
"key",
")",
":",
"$",
"key",
";",
"}"
] | Sets the key that indicates a node value.
@param string $key
@param bool $normalize
@throws \InvalidArgumentException if $key is not null and an invalid nodename.
@return void | [
"Sets",
"the",
"key",
"that",
"indicates",
"a",
"node",
"value",
"."
] | 4ff1e92c4071887c2802eb7ee3f3c46632ad7db2 | https://github.com/lucidphp/xml/blob/4ff1e92c4071887c2802eb7ee3f3c46632ad7db2/src/Writer.php#L181-L188 |
7,364 | lucidphp/xml | src/Writer.php | Writer.useKeyAsIndex | public function useKeyAsIndex($key, $normalize = false)
{
if (null === $key) {
$this->indexKey = null;
return;
}
if (true !== $normalize && !$this->isValidNodeName($key)) {
throw new \InvalidArgumentException(sprintf('%s is an invalid node name', $key));
}
$this->indexKey = $normalize ? $this->normalizer->normalize($key) : $key;
} | php | public function useKeyAsIndex($key, $normalize = false)
{
if (null === $key) {
$this->indexKey = null;
return;
}
if (true !== $normalize && !$this->isValidNodeName($key)) {
throw new \InvalidArgumentException(sprintf('%s is an invalid node name', $key));
}
$this->indexKey = $normalize ? $this->normalizer->normalize($key) : $key;
} | [
"public",
"function",
"useKeyAsIndex",
"(",
"$",
"key",
",",
"$",
"normalize",
"=",
"false",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"indexKey",
"=",
"null",
";",
"return",
";",
"}",
"if",
"(",
"true",
"!==",
"$",
"normalize",
"&&",
"!",
"$",
"this",
"->",
"isValidNodeName",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'%s is an invalid node name'",
",",
"$",
"key",
")",
")",
";",
"}",
"$",
"this",
"->",
"indexKey",
"=",
"$",
"normalize",
"?",
"$",
"this",
"->",
"normalizer",
"->",
"normalize",
"(",
"$",
"key",
")",
":",
"$",
"key",
";",
"}"
] | Sets the index key used as key -> node identifier.
@param string $key
@param bool $normalize
@throws \InvalidArgumentException if $key is an invalid nodename.
@return void | [
"Sets",
"the",
"index",
"key",
"used",
"as",
"key",
"-",
">",
"node",
"identifier",
"."
] | 4ff1e92c4071887c2802eb7ee3f3c46632ad7db2 | https://github.com/lucidphp/xml/blob/4ff1e92c4071887c2802eb7ee3f3c46632ad7db2/src/Writer.php#L199-L211 |
7,365 | lucidphp/xml | src/Writer.php | Writer.useKeyAsIndexAttribute | public function useKeyAsIndexAttribute($key, $normalize = false)
{
if (null === $key) {
$this->indexAttrKey = null;
return;
}
if (true !== $normalize && !$this->isValidNodeName($key)) {
throw new \InvalidArgumentException(sprintf('%s is an invalid attribute name', $key));
}
$this->indexAttrKey = $normalize ? $this->normalizer->normalize($key) : $key;
} | php | public function useKeyAsIndexAttribute($key, $normalize = false)
{
if (null === $key) {
$this->indexAttrKey = null;
return;
}
if (true !== $normalize && !$this->isValidNodeName($key)) {
throw new \InvalidArgumentException(sprintf('%s is an invalid attribute name', $key));
}
$this->indexAttrKey = $normalize ? $this->normalizer->normalize($key) : $key;
} | [
"public",
"function",
"useKeyAsIndexAttribute",
"(",
"$",
"key",
",",
"$",
"normalize",
"=",
"false",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"indexAttrKey",
"=",
"null",
";",
"return",
";",
"}",
"if",
"(",
"true",
"!==",
"$",
"normalize",
"&&",
"!",
"$",
"this",
"->",
"isValidNodeName",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'%s is an invalid attribute name'",
",",
"$",
"key",
")",
")",
";",
"}",
"$",
"this",
"->",
"indexAttrKey",
"=",
"$",
"normalize",
"?",
"$",
"this",
"->",
"normalizer",
"->",
"normalize",
"(",
"$",
"key",
")",
":",
"$",
"key",
";",
"}"
] | Sets the index key used in attributes.
@param string $key
@param bool $normalize
@return void | [
"Sets",
"the",
"index",
"key",
"used",
"in",
"attributes",
"."
] | 4ff1e92c4071887c2802eb7ee3f3c46632ad7db2 | https://github.com/lucidphp/xml/blob/4ff1e92c4071887c2802eb7ee3f3c46632ad7db2/src/Writer.php#L221-L233 |
7,366 | lucidphp/xml | src/Writer.php | Writer.dump | public function dump($data, $rootName = 'root')
{
$dom = $this->writeToDom($data, $rootName);
return $dom->saveXML();
} | php | public function dump($data, $rootName = 'root')
{
$dom = $this->writeToDom($data, $rootName);
return $dom->saveXML();
} | [
"public",
"function",
"dump",
"(",
"$",
"data",
",",
"$",
"rootName",
"=",
"'root'",
")",
"{",
"$",
"dom",
"=",
"$",
"this",
"->",
"writeToDom",
"(",
"$",
"data",
",",
"$",
"rootName",
")",
";",
"return",
"$",
"dom",
"->",
"saveXML",
"(",
")",
";",
"}"
] | Dump the input data to a xml string.
@param mixed $data
@param string $rootName the xml root element name
@return string | [
"Dump",
"the",
"input",
"data",
"to",
"a",
"xml",
"string",
"."
] | 4ff1e92c4071887c2802eb7ee3f3c46632ad7db2 | https://github.com/lucidphp/xml/blob/4ff1e92c4071887c2802eb7ee3f3c46632ad7db2/src/Writer.php#L243-L248 |
7,367 | lucidphp/xml | src/Writer.php | Writer.writeToDom | public function writeToDom($data, $rootName = 'root')
{
$this->buildXML(
$dom = new DOMDocument('1.0', $this->getEncoding()),
$root = $dom->createElement($rootName),
$data
);
$dom->appendChild($root);
return $dom;
} | php | public function writeToDom($data, $rootName = 'root')
{
$this->buildXML(
$dom = new DOMDocument('1.0', $this->getEncoding()),
$root = $dom->createElement($rootName),
$data
);
$dom->appendChild($root);
return $dom;
} | [
"public",
"function",
"writeToDom",
"(",
"$",
"data",
",",
"$",
"rootName",
"=",
"'root'",
")",
"{",
"$",
"this",
"->",
"buildXML",
"(",
"$",
"dom",
"=",
"new",
"DOMDocument",
"(",
"'1.0'",
",",
"$",
"this",
"->",
"getEncoding",
"(",
")",
")",
",",
"$",
"root",
"=",
"$",
"dom",
"->",
"createElement",
"(",
"$",
"rootName",
")",
",",
"$",
"data",
")",
";",
"$",
"dom",
"->",
"appendChild",
"(",
"$",
"root",
")",
";",
"return",
"$",
"dom",
";",
"}"
] | Write the input data to a DOMDocument
@param mixed $data
@param string $rootName the xml root element name
@return DOMDocument | [
"Write",
"the",
"input",
"data",
"to",
"a",
"DOMDocument"
] | 4ff1e92c4071887c2802eb7ee3f3c46632ad7db2 | https://github.com/lucidphp/xml/blob/4ff1e92c4071887c2802eb7ee3f3c46632ad7db2/src/Writer.php#L258-L268 |
7,368 | lucidphp/xml | src/Writer.php | Writer.appendDOMNode | private function appendDOMNode(\DOMDocument $dom, $node, $name, $value = null, $hasAttributes = false)
{
$element = $dom->createElement($name);
if ($hasAttributes && $this->nodeValueKey === $name) {
$this->setElementValue($dom, $node, $value);
return;
}
$this->setElementValue($dom, $element, $value);
$node->appendChild($element);
} | php | private function appendDOMNode(\DOMDocument $dom, $node, $name, $value = null, $hasAttributes = false)
{
$element = $dom->createElement($name);
if ($hasAttributes && $this->nodeValueKey === $name) {
$this->setElementValue($dom, $node, $value);
return;
}
$this->setElementValue($dom, $element, $value);
$node->appendChild($element);
} | [
"private",
"function",
"appendDOMNode",
"(",
"\\",
"DOMDocument",
"$",
"dom",
",",
"$",
"node",
",",
"$",
"name",
",",
"$",
"value",
"=",
"null",
",",
"$",
"hasAttributes",
"=",
"false",
")",
"{",
"$",
"element",
"=",
"$",
"dom",
"->",
"createElement",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"hasAttributes",
"&&",
"$",
"this",
"->",
"nodeValueKey",
"===",
"$",
"name",
")",
"{",
"$",
"this",
"->",
"setElementValue",
"(",
"$",
"dom",
",",
"$",
"node",
",",
"$",
"value",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"setElementValue",
"(",
"$",
"dom",
",",
"$",
"element",
",",
"$",
"value",
")",
";",
"$",
"node",
"->",
"appendChild",
"(",
"$",
"element",
")",
";",
"}"
] | Appends a dom node to the DOM.
@param DOMNode $node
@param string $name
@param mixed $value
@param bool $hasAttributes
@return void | [
"Appends",
"a",
"dom",
"node",
"to",
"the",
"DOM",
"."
] | 4ff1e92c4071887c2802eb7ee3f3c46632ad7db2 | https://github.com/lucidphp/xml/blob/4ff1e92c4071887c2802eb7ee3f3c46632ad7db2/src/Writer.php#L525-L537 |
7,369 | lucidphp/xml | src/Writer.php | Writer.getAttributeName | private function getAttributeName($key)
{
if (0 === strpos($key, '@') && $this->isValidNodeName($attrName = substr($key, 1))) {
return $attrName;
}
return null;
} | php | private function getAttributeName($key)
{
if (0 === strpos($key, '@') && $this->isValidNodeName($attrName = substr($key, 1))) {
return $attrName;
}
return null;
} | [
"private",
"function",
"getAttributeName",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"0",
"===",
"strpos",
"(",
"$",
"key",
",",
"'@'",
")",
"&&",
"$",
"this",
"->",
"isValidNodeName",
"(",
"$",
"attrName",
"=",
"substr",
"(",
"$",
"key",
",",
"1",
")",
")",
")",
"{",
"return",
"$",
"attrName",
";",
"}",
"return",
"null",
";",
"}"
] | Extracts the raw attribute indicator.
@param string $key string with leading `@`.
@return string | [
"Extracts",
"the",
"raw",
"attribute",
"indicator",
"."
] | 4ff1e92c4071887c2802eb7ee3f3c46632ad7db2 | https://github.com/lucidphp/xml/blob/4ff1e92c4071887c2802eb7ee3f3c46632ad7db2/src/Writer.php#L546-L553 |
7,370 | lucidphp/xml | src/Writer.php | Writer.createText | private function createText(\DOMDocument $dom, \DOMNode $node, $value)
{
$text = $dom->createTextNode($value);
$node->appendChild($text);
} | php | private function createText(\DOMDocument $dom, \DOMNode $node, $value)
{
$text = $dom->createTextNode($value);
$node->appendChild($text);
} | [
"private",
"function",
"createText",
"(",
"\\",
"DOMDocument",
"$",
"dom",
",",
"\\",
"DOMNode",
"$",
"node",
",",
"$",
"value",
")",
"{",
"$",
"text",
"=",
"$",
"dom",
"->",
"createTextNode",
"(",
"$",
"value",
")",
";",
"$",
"node",
"->",
"appendChild",
"(",
"$",
"text",
")",
";",
"}"
] | Creates a text node on a DOMNode.
@param DOMNode $node
@param string $value
@return bool | [
"Creates",
"a",
"text",
"node",
"on",
"a",
"DOMNode",
"."
] | 4ff1e92c4071887c2802eb7ee3f3c46632ad7db2 | https://github.com/lucidphp/xml/blob/4ff1e92c4071887c2802eb7ee3f3c46632ad7db2/src/Writer.php#L563-L567 |
7,371 | lucidphp/xml | src/Writer.php | Writer.createCDATASection | private function createCDATASection(\DOMDocument $dom, \DOMNode $node, $value)
{
$cdata = $dom->createCDATASection($value);
$node->appendChild($cdata);
} | php | private function createCDATASection(\DOMDocument $dom, \DOMNode $node, $value)
{
$cdata = $dom->createCDATASection($value);
$node->appendChild($cdata);
} | [
"private",
"function",
"createCDATASection",
"(",
"\\",
"DOMDocument",
"$",
"dom",
",",
"\\",
"DOMNode",
"$",
"node",
",",
"$",
"value",
")",
"{",
"$",
"cdata",
"=",
"$",
"dom",
"->",
"createCDATASection",
"(",
"$",
"value",
")",
";",
"$",
"node",
"->",
"appendChild",
"(",
"$",
"cdata",
")",
";",
"}"
] | Creates a CDATA section node on a DOMNode.
@param DOMNode $node
@param string $value
@return void | [
"Creates",
"a",
"CDATA",
"section",
"node",
"on",
"a",
"DOMNode",
"."
] | 4ff1e92c4071887c2802eb7ee3f3c46632ad7db2 | https://github.com/lucidphp/xml/blob/4ff1e92c4071887c2802eb7ee3f3c46632ad7db2/src/Writer.php#L577-L581 |
7,372 | lucidphp/xml | src/Writer.php | Writer.createTextNodeWithTypeAttribute | private function createTextNodeWithTypeAttribute(\DOMDocument $dom, \DOMNode $node, $value, $type = 'int')
{
$text = $dom->createTextNode($value);
$attr = $dom->createAttribute('type');
$attr->value = $type;
$node->appendChild($text);
$node->appendChild($attr);
} | php | private function createTextNodeWithTypeAttribute(\DOMDocument $dom, \DOMNode $node, $value, $type = 'int')
{
$text = $dom->createTextNode($value);
$attr = $dom->createAttribute('type');
$attr->value = $type;
$node->appendChild($text);
$node->appendChild($attr);
} | [
"private",
"function",
"createTextNodeWithTypeAttribute",
"(",
"\\",
"DOMDocument",
"$",
"dom",
",",
"\\",
"DOMNode",
"$",
"node",
",",
"$",
"value",
",",
"$",
"type",
"=",
"'int'",
")",
"{",
"$",
"text",
"=",
"$",
"dom",
"->",
"createTextNode",
"(",
"$",
"value",
")",
";",
"$",
"attr",
"=",
"$",
"dom",
"->",
"createAttribute",
"(",
"'type'",
")",
";",
"$",
"attr",
"->",
"value",
"=",
"$",
"type",
";",
"$",
"node",
"->",
"appendChild",
"(",
"$",
"text",
")",
";",
"$",
"node",
"->",
"appendChild",
"(",
"$",
"attr",
")",
";",
"}"
] | Add a value and an associated type attribute to a DOMNode.
@param DOMNode $node
@param mixed $value
@param string $type
@return void | [
"Add",
"a",
"value",
"and",
"an",
"associated",
"type",
"attribute",
"to",
"a",
"DOMNode",
"."
] | 4ff1e92c4071887c2802eb7ee3f3c46632ad7db2 | https://github.com/lucidphp/xml/blob/4ff1e92c4071887c2802eb7ee3f3c46632ad7db2/src/Writer.php#L592-L600 |
7,373 | GustavSoftware/Cache | src/CacheException.php | CacheException.invalidImplementation | public static function invalidImplementation(
string $className,
\Exception $previous = null
): self {
return new self(
"invalid class name: {$className}",
self::INVALID_IMPLEMENTATION,
$previous
);
} | php | public static function invalidImplementation(
string $className,
\Exception $previous = null
): self {
return new self(
"invalid class name: {$className}",
self::INVALID_IMPLEMENTATION,
$previous
);
} | [
"public",
"static",
"function",
"invalidImplementation",
"(",
"string",
"$",
"className",
",",
"\\",
"Exception",
"$",
"previous",
"=",
"null",
")",
":",
"self",
"{",
"return",
"new",
"self",
"(",
"\"invalid class name: {$className}\"",
",",
"self",
"::",
"INVALID_IMPLEMENTATION",
",",
"$",
"previous",
")",
";",
"}"
] | This method creates an exception if the given class name of the cache
implementation to use does not implement \Gustav\Cache\ACacheManager.
@param string $className
The class name
@param \Exception|null $previous
Previous exception
@return \Gustav\Cache\CacheException
The new exception | [
"This",
"method",
"creates",
"an",
"exception",
"if",
"the",
"given",
"class",
"name",
"of",
"the",
"cache",
"implementation",
"to",
"use",
"does",
"not",
"implement",
"\\",
"Gustav",
"\\",
"Cache",
"\\",
"ACacheManager",
"."
] | 2a70db567aa13499487c24b399f7c9d46937df0d | https://github.com/GustavSoftware/Cache/blob/2a70db567aa13499487c24b399f7c9d46937df0d/src/CacheException.php#L57-L66 |
7,374 | GustavSoftware/Cache | src/CacheException.php | CacheException.badFileName | public static function badFileName(
string $fileName,
\Exception $previous = null
): self {
return new self(
"bad file name: {$fileName}",
self::BAD_FILE_NAME,
$previous
);
} | php | public static function badFileName(
string $fileName,
\Exception $previous = null
): self {
return new self(
"bad file name: {$fileName}",
self::BAD_FILE_NAME,
$previous
);
} | [
"public",
"static",
"function",
"badFileName",
"(",
"string",
"$",
"fileName",
",",
"\\",
"Exception",
"$",
"previous",
"=",
"null",
")",
":",
"self",
"{",
"return",
"new",
"self",
"(",
"\"bad file name: {$fileName}\"",
",",
"self",
"::",
"BAD_FILE_NAME",
",",
"$",
"previous",
")",
";",
"}"
] | This method creates an exception if the given file-name contains
invalid symbols.
@param string $fileName
The file-name
@param \Exception|null $previous
Previous exception
@return \Gustav\Cache\CacheException
The new exception | [
"This",
"method",
"creates",
"an",
"exception",
"if",
"the",
"given",
"file",
"-",
"name",
"contains",
"invalid",
"symbols",
"."
] | 2a70db567aa13499487c24b399f7c9d46937df0d | https://github.com/GustavSoftware/Cache/blob/2a70db567aa13499487c24b399f7c9d46937df0d/src/CacheException.php#L79-L88 |
7,375 | GustavSoftware/Cache | src/CacheException.php | CacheException.fileUnreadable | public static function fileUnreadable(
$fileName,
\Exception $previous = null
): self {
return new self(
"cannot read file: {$fileName}",
self::FILE_UNREADABLE,
$previous
);
} | php | public static function fileUnreadable(
$fileName,
\Exception $previous = null
): self {
return new self(
"cannot read file: {$fileName}",
self::FILE_UNREADABLE,
$previous
);
} | [
"public",
"static",
"function",
"fileUnreadable",
"(",
"$",
"fileName",
",",
"\\",
"Exception",
"$",
"previous",
"=",
"null",
")",
":",
"self",
"{",
"return",
"new",
"self",
"(",
"\"cannot read file: {$fileName}\"",
",",
"self",
"::",
"FILE_UNREADABLE",
",",
"$",
"previous",
")",
";",
"}"
] | This method creates an exception if reading of this file failed.
@param string $fileName
The file-name
@param \Exception|null $previous
Previous exception
@return \Gustav\Cache\CacheException
The new exception | [
"This",
"method",
"creates",
"an",
"exception",
"if",
"reading",
"of",
"this",
"file",
"failed",
"."
] | 2a70db567aa13499487c24b399f7c9d46937df0d | https://github.com/GustavSoftware/Cache/blob/2a70db567aa13499487c24b399f7c9d46937df0d/src/CacheException.php#L100-L109 |
7,376 | lembarek/auth | src/Repositories/UserRepository.php | UserRepository.byUsername | public function byUsername($username, $with=[])
{
$user = $this->model->whereUsername($username);
foreach($with as $relation)
$user = $user->with($relation);
return $user->first();
} | php | public function byUsername($username, $with=[])
{
$user = $this->model->whereUsername($username);
foreach($with as $relation)
$user = $user->with($relation);
return $user->first();
} | [
"public",
"function",
"byUsername",
"(",
"$",
"username",
",",
"$",
"with",
"=",
"[",
"]",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"model",
"->",
"whereUsername",
"(",
"$",
"username",
")",
";",
"foreach",
"(",
"$",
"with",
"as",
"$",
"relation",
")",
"$",
"user",
"=",
"$",
"user",
"->",
"with",
"(",
"$",
"relation",
")",
";",
"return",
"$",
"user",
"->",
"first",
"(",
")",
";",
"}"
] | get a single user by its username
@param string $username
@return User | [
"get",
"a",
"single",
"user",
"by",
"its",
"username"
] | 783aad2bcde9d8014be34092ba0cbe38b2bbc60a | https://github.com/lembarek/auth/blob/783aad2bcde9d8014be34092ba0cbe38b2bbc60a/src/Repositories/UserRepository.php#L23-L29 |
7,377 | AfterBug/afterbug-php | src/Exceptions/Formatter.php | Formatter.getWhoopsRunner | private function getWhoopsRunner()
{
$whoops = new Whoops();
$whoops->allowQuit(false);
$whoops->writeToOutput(false);
return $whoops;
} | php | private function getWhoopsRunner()
{
$whoops = new Whoops();
$whoops->allowQuit(false);
$whoops->writeToOutput(false);
return $whoops;
} | [
"private",
"function",
"getWhoopsRunner",
"(",
")",
"{",
"$",
"whoops",
"=",
"new",
"Whoops",
"(",
")",
";",
"$",
"whoops",
"->",
"allowQuit",
"(",
"false",
")",
";",
"$",
"whoops",
"->",
"writeToOutput",
"(",
"false",
")",
";",
"return",
"$",
"whoops",
";",
"}"
] | Get Whoops Runner.
@return Whoops | [
"Get",
"Whoops",
"Runner",
"."
] | 3eba5ed782a5922b09170c0ae29679afea6839d8 | https://github.com/AfterBug/afterbug-php/blob/3eba5ed782a5922b09170c0ae29679afea6839d8/src/Exceptions/Formatter.php#L52-L59 |
7,378 | AfterBug/afterbug-php | src/Exceptions/Formatter.php | Formatter.toArray | public function toArray()
{
$hasChainedException = PHP_VERSION_ID >= 50300;
$exception = $this->exception;
do {
$whoops = $this->getWhoopsRunner();
$whoops->pushHandler(new WhoopsHandler($this->config))->register();
$exceptions[] = json_decode(
$whoops->handleException($exception),
true
);
} while ($hasChainedException && $exception = $exception->getPrevious());
$data = [
'title' => get_class($this->exception),
'message' => $this->exception->getMessage(),
'exception' => [
'file' => $this->exception->getFile(),
'line' => $this->exception->getLine(),
'code' => $this->exception->getCode(),
],
'platform' => 'php',
'environment' => $this->config->getEnvironment(),
'events' => [
'exceptions' => $exceptions,
'meta_data' => $this->config->getMetaData(),
'user' => $this->config->getUser(),
'sdk' => $this->config->getSdk(),
],
];
if (empty($data['level'])) {
if (method_exists($exception, 'getSeverity')) {
$data['level'] = $this->translateSeverity($exception->getSeverity());
} else {
$data['level'] = self::ERROR;
}
}
return $data;
} | php | public function toArray()
{
$hasChainedException = PHP_VERSION_ID >= 50300;
$exception = $this->exception;
do {
$whoops = $this->getWhoopsRunner();
$whoops->pushHandler(new WhoopsHandler($this->config))->register();
$exceptions[] = json_decode(
$whoops->handleException($exception),
true
);
} while ($hasChainedException && $exception = $exception->getPrevious());
$data = [
'title' => get_class($this->exception),
'message' => $this->exception->getMessage(),
'exception' => [
'file' => $this->exception->getFile(),
'line' => $this->exception->getLine(),
'code' => $this->exception->getCode(),
],
'platform' => 'php',
'environment' => $this->config->getEnvironment(),
'events' => [
'exceptions' => $exceptions,
'meta_data' => $this->config->getMetaData(),
'user' => $this->config->getUser(),
'sdk' => $this->config->getSdk(),
],
];
if (empty($data['level'])) {
if (method_exists($exception, 'getSeverity')) {
$data['level'] = $this->translateSeverity($exception->getSeverity());
} else {
$data['level'] = self::ERROR;
}
}
return $data;
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"$",
"hasChainedException",
"=",
"PHP_VERSION_ID",
">=",
"50300",
";",
"$",
"exception",
"=",
"$",
"this",
"->",
"exception",
";",
"do",
"{",
"$",
"whoops",
"=",
"$",
"this",
"->",
"getWhoopsRunner",
"(",
")",
";",
"$",
"whoops",
"->",
"pushHandler",
"(",
"new",
"WhoopsHandler",
"(",
"$",
"this",
"->",
"config",
")",
")",
"->",
"register",
"(",
")",
";",
"$",
"exceptions",
"[",
"]",
"=",
"json_decode",
"(",
"$",
"whoops",
"->",
"handleException",
"(",
"$",
"exception",
")",
",",
"true",
")",
";",
"}",
"while",
"(",
"$",
"hasChainedException",
"&&",
"$",
"exception",
"=",
"$",
"exception",
"->",
"getPrevious",
"(",
")",
")",
";",
"$",
"data",
"=",
"[",
"'title'",
"=>",
"get_class",
"(",
"$",
"this",
"->",
"exception",
")",
",",
"'message'",
"=>",
"$",
"this",
"->",
"exception",
"->",
"getMessage",
"(",
")",
",",
"'exception'",
"=>",
"[",
"'file'",
"=>",
"$",
"this",
"->",
"exception",
"->",
"getFile",
"(",
")",
",",
"'line'",
"=>",
"$",
"this",
"->",
"exception",
"->",
"getLine",
"(",
")",
",",
"'code'",
"=>",
"$",
"this",
"->",
"exception",
"->",
"getCode",
"(",
")",
",",
"]",
",",
"'platform'",
"=>",
"'php'",
",",
"'environment'",
"=>",
"$",
"this",
"->",
"config",
"->",
"getEnvironment",
"(",
")",
",",
"'events'",
"=>",
"[",
"'exceptions'",
"=>",
"$",
"exceptions",
",",
"'meta_data'",
"=>",
"$",
"this",
"->",
"config",
"->",
"getMetaData",
"(",
")",
",",
"'user'",
"=>",
"$",
"this",
"->",
"config",
"->",
"getUser",
"(",
")",
",",
"'sdk'",
"=>",
"$",
"this",
"->",
"config",
"->",
"getSdk",
"(",
")",
",",
"]",
",",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"data",
"[",
"'level'",
"]",
")",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"exception",
",",
"'getSeverity'",
")",
")",
"{",
"$",
"data",
"[",
"'level'",
"]",
"=",
"$",
"this",
"->",
"translateSeverity",
"(",
"$",
"exception",
"->",
"getSeverity",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"'level'",
"]",
"=",
"self",
"::",
"ERROR",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Format exception as array.
@return array | [
"Format",
"exception",
"as",
"array",
"."
] | 3eba5ed782a5922b09170c0ae29679afea6839d8 | https://github.com/AfterBug/afterbug-php/blob/3eba5ed782a5922b09170c0ae29679afea6839d8/src/Exceptions/Formatter.php#L104-L147 |
7,379 | cundd/test-flight | src/Assert.php | Assert.assert | public static function assert($assertion, string $message = '')
{
self::$count += 1;
assert($assertion, new AssertionError($message));
} | php | public static function assert($assertion, string $message = '')
{
self::$count += 1;
assert($assertion, new AssertionError($message));
} | [
"public",
"static",
"function",
"assert",
"(",
"$",
"assertion",
",",
"string",
"$",
"message",
"=",
"''",
")",
"{",
"self",
"::",
"$",
"count",
"+=",
"1",
";",
"assert",
"(",
"$",
"assertion",
",",
"new",
"AssertionError",
"(",
"$",
"message",
")",
")",
";",
"}"
] | Test if the assertion is true
@example
\Cundd\TestFlight\Assert::assert(true);
test_flight_throws(function() {
\Cundd\TestFlight\Assert::assert(false);
});
@param mixed $assertion
@param string $message | [
"Test",
"if",
"the",
"assertion",
"is",
"true"
] | 9d8424dfb586f823f9dad2dcb81ff3986e255d56 | https://github.com/cundd/test-flight/blob/9d8424dfb586f823f9dad2dcb81ff3986e255d56/src/Assert.php#L33-L37 |
7,380 | cundd/test-flight | src/Assert.php | Assert.assertSame | public static function assertSame($expected, $actual, string $message = '')
{
self::$count += 1;
if ($expected === $actual) {
return;
}
if (!$message) {
$message = sprintf(
'Failed asserting that %s matches %s',
var_export($actual, true),
var_export($expected, true)
);
}
throw new AssertionError($message);
} | php | public static function assertSame($expected, $actual, string $message = '')
{
self::$count += 1;
if ($expected === $actual) {
return;
}
if (!$message) {
$message = sprintf(
'Failed asserting that %s matches %s',
var_export($actual, true),
var_export($expected, true)
);
}
throw new AssertionError($message);
} | [
"public",
"static",
"function",
"assertSame",
"(",
"$",
"expected",
",",
"$",
"actual",
",",
"string",
"$",
"message",
"=",
"''",
")",
"{",
"self",
"::",
"$",
"count",
"+=",
"1",
";",
"if",
"(",
"$",
"expected",
"===",
"$",
"actual",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"message",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'Failed asserting that %s matches %s'",
",",
"var_export",
"(",
"$",
"actual",
",",
"true",
")",
",",
"var_export",
"(",
"$",
"expected",
",",
"true",
")",
")",
";",
"}",
"throw",
"new",
"AssertionError",
"(",
"$",
"message",
")",
";",
"}"
] | Test if the actual value matches the expected
@example
\Cundd\TestFlight\Assert::assertSame([], []);
\Cundd\TestFlight\Assert::assertSame(true, true);
\Cundd\TestFlight\Assert::assertSame(PHP_INT_MAX, PHP_INT_MAX);
$object = new stdClass(); \Cundd\TestFlight\Assert::assertSame($object, $object);
test_flight_throws(function() { \Cundd\TestFlight\Assert::assertSame(true, false); });
test_flight_throws(function() { \Cundd\TestFlight\Assert::assertSame([], [1]); });
test_flight_throws(function() use($object) { \Cundd\TestFlight\Assert::assertSame($object, new stdClass()); });
@param mixed $expected
@param mixed $actual
@param string $message
@throws AssertionError if the values are not equal | [
"Test",
"if",
"the",
"actual",
"value",
"matches",
"the",
"expected"
] | 9d8424dfb586f823f9dad2dcb81ff3986e255d56 | https://github.com/cundd/test-flight/blob/9d8424dfb586f823f9dad2dcb81ff3986e255d56/src/Assert.php#L56-L71 |
7,381 | cundd/test-flight | src/Assert.php | Assert.assertTrue | public static function assertTrue($actual, string $message = '')
{
self::$count += 1;
if ((bool)$actual) {
return;
}
if (!$message) {
$message = sprintf(
'Failed asserting that %s is truthy',
var_export($actual, true)
);
}
throw new AssertionError($message);
} | php | public static function assertTrue($actual, string $message = '')
{
self::$count += 1;
if ((bool)$actual) {
return;
}
if (!$message) {
$message = sprintf(
'Failed asserting that %s is truthy',
var_export($actual, true)
);
}
throw new AssertionError($message);
} | [
"public",
"static",
"function",
"assertTrue",
"(",
"$",
"actual",
",",
"string",
"$",
"message",
"=",
"''",
")",
"{",
"self",
"::",
"$",
"count",
"+=",
"1",
";",
"if",
"(",
"(",
"bool",
")",
"$",
"actual",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"message",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'Failed asserting that %s is truthy'",
",",
"var_export",
"(",
"$",
"actual",
",",
"true",
")",
")",
";",
"}",
"throw",
"new",
"AssertionError",
"(",
"$",
"message",
")",
";",
"}"
] | Test if the value is truthy
@example
\Cundd\TestFlight\Assert::assertTrue(true);
\Cundd\TestFlight\Assert::assertTrue(1);
\Cundd\TestFlight\Assert::assertTrue(' ');
\Cundd\TestFlight\Assert::assertTrue('1');
\Cundd\TestFlight\Assert::assertTrue(new stdClass());
\Cundd\TestFlight\Assert::assertTrue([1]);
test_flight_throws(function() { \Cundd\TestFlight\Assert::assertTrue(false); });
test_flight_throws(function() { \Cundd\TestFlight\Assert::assertTrue(0); });
test_flight_throws(function() { \Cundd\TestFlight\Assert::assertTrue(''); });
test_flight_throws(function() { \Cundd\TestFlight\Assert::assertTrue(null); });
test_flight_throws(function() { \Cundd\TestFlight\Assert::assertTrue([]); });
@param mixed $actual
@param string $message
@throws AssertionError if the value is false, null, 0, '', '0', ... | [
"Test",
"if",
"the",
"value",
"is",
"truthy"
] | 9d8424dfb586f823f9dad2dcb81ff3986e255d56 | https://github.com/cundd/test-flight/blob/9d8424dfb586f823f9dad2dcb81ff3986e255d56/src/Assert.php#L93-L108 |
7,382 | cundd/test-flight | src/Assert.php | Assert.assertFalse | public static function assertFalse($actual, string $message = '')
{
self::$count += 1;
if (false === (bool)$actual) {
return;
}
if (!$message) {
$message = sprintf(
'Failed asserting that %s is falsy',
var_export($actual, true)
);
}
throw new AssertionError($message);
} | php | public static function assertFalse($actual, string $message = '')
{
self::$count += 1;
if (false === (bool)$actual) {
return;
}
if (!$message) {
$message = sprintf(
'Failed asserting that %s is falsy',
var_export($actual, true)
);
}
throw new AssertionError($message);
} | [
"public",
"static",
"function",
"assertFalse",
"(",
"$",
"actual",
",",
"string",
"$",
"message",
"=",
"''",
")",
"{",
"self",
"::",
"$",
"count",
"+=",
"1",
";",
"if",
"(",
"false",
"===",
"(",
"bool",
")",
"$",
"actual",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"message",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'Failed asserting that %s is falsy'",
",",
"var_export",
"(",
"$",
"actual",
",",
"true",
")",
")",
";",
"}",
"throw",
"new",
"AssertionError",
"(",
"$",
"message",
")",
";",
"}"
] | Test if the value is falsy
@example
\Cundd\TestFlight\Assert::assertFalse(false);
\Cundd\TestFlight\Assert::assertFalse(0);
\Cundd\TestFlight\Assert::assertFalse('');
\Cundd\TestFlight\Assert::assertFalse(null);
\Cundd\TestFlight\Assert::assertFalse([]);
test_flight_throws(function() { \Cundd\TestFlight\Assert::assertFalse(true); });
test_flight_throws(function() { \Cundd\TestFlight\Assert::assertFalse(1); });
test_flight_throws(function() { \Cundd\TestFlight\Assert::assertFalse(' '); });
test_flight_throws(function() { \Cundd\TestFlight\Assert::assertFalse('1'); });
test_flight_throws(function() { \Cundd\TestFlight\Assert::assertFalse(new stdClass()); });
test_flight_throws(function() { \Cundd\TestFlight\Assert::assertFalse([1]); });
@param mixed $actual
@param string $message
@throws AssertionError if the value is false, null, 0, '', '0', ... | [
"Test",
"if",
"the",
"value",
"is",
"falsy"
] | 9d8424dfb586f823f9dad2dcb81ff3986e255d56 | https://github.com/cundd/test-flight/blob/9d8424dfb586f823f9dad2dcb81ff3986e255d56/src/Assert.php#L130-L145 |
7,383 | cundd/test-flight | src/Assert.php | Assert.throws | public static function throws(callable $callback, string $expectedException = '', string $message = '')
{
self::$count += 1;
$exception = null;
try {
$callback();
} catch (\Error $exception) {
} catch (\Exception $exception) {
}
if ($exception === null) {
throw new AssertionError($message ?: 'No exception thrown');
} elseif ($expectedException && !is_a($exception, $expectedException)) {
throw new AssertionError(
$message ?: sprintf(
'Expected %s got %s',
$expectedException,
get_class($exception)
)
);
}
} | php | public static function throws(callable $callback, string $expectedException = '', string $message = '')
{
self::$count += 1;
$exception = null;
try {
$callback();
} catch (\Error $exception) {
} catch (\Exception $exception) {
}
if ($exception === null) {
throw new AssertionError($message ?: 'No exception thrown');
} elseif ($expectedException && !is_a($exception, $expectedException)) {
throw new AssertionError(
$message ?: sprintf(
'Expected %s got %s',
$expectedException,
get_class($exception)
)
);
}
} | [
"public",
"static",
"function",
"throws",
"(",
"callable",
"$",
"callback",
",",
"string",
"$",
"expectedException",
"=",
"''",
",",
"string",
"$",
"message",
"=",
"''",
")",
"{",
"self",
"::",
"$",
"count",
"+=",
"1",
";",
"$",
"exception",
"=",
"null",
";",
"try",
"{",
"$",
"callback",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Error",
"$",
"exception",
")",
"{",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"}",
"if",
"(",
"$",
"exception",
"===",
"null",
")",
"{",
"throw",
"new",
"AssertionError",
"(",
"$",
"message",
"?",
":",
"'No exception thrown'",
")",
";",
"}",
"elseif",
"(",
"$",
"expectedException",
"&&",
"!",
"is_a",
"(",
"$",
"exception",
",",
"$",
"expectedException",
")",
")",
"{",
"throw",
"new",
"AssertionError",
"(",
"$",
"message",
"?",
":",
"sprintf",
"(",
"'Expected %s got %s'",
",",
"$",
"expectedException",
",",
"get_class",
"(",
"$",
"exception",
")",
")",
")",
";",
"}",
"}"
] | Test if the callback throws an exception
@example
test_flight_throws(function() { throw new \Exception(); });
test_flight_throws(function() { throw new \RuntimeException(); }, 'RuntimeException');
$didThrow = false;
try {
test_flight_throws(function() { return true; });
} catch (\Cundd\TestFlight\Exception\AssertionError $e) {
$didThrow = true;
}
assert($didThrow);
$didThrowWrongException = false;
$exceptionMessage = '';
try {
test_flight_throws(function() { throw new \LogicException(); }, 'RuntimeException');
} catch (\Cundd\TestFlight\Exception\AssertionError $e) {
$didThrowWrongException = true;
$exceptionMessage = $e->getMessage();
}
assert($didThrowWrongException, 'No exception thrown');
assert('Expected RuntimeException got LogicException' === $exceptionMessage, 'Exception message does not match');
@param callable $callback
@param string $expectedException
@param string $message
@throws AssertionError | [
"Test",
"if",
"the",
"callback",
"throws",
"an",
"exception"
] | 9d8424dfb586f823f9dad2dcb81ff3986e255d56 | https://github.com/cundd/test-flight/blob/9d8424dfb586f823f9dad2dcb81ff3986e255d56/src/Assert.php#L179-L203 |
7,384 | cundd/test-flight | src/Assert.php | Assert.assertInstanceOf | public static function assertInstanceOf(string $className, $actual, string $message = '')
{
self::$count += 1;
if ($actual instanceof $className) {
return;
}
if (!$message) {
$message = sprintf(
'Failed asserting that %s is an instance of %s',
static::getType($actual),
$className
);
}
throw new AssertionError($message);
} | php | public static function assertInstanceOf(string $className, $actual, string $message = '')
{
self::$count += 1;
if ($actual instanceof $className) {
return;
}
if (!$message) {
$message = sprintf(
'Failed asserting that %s is an instance of %s',
static::getType($actual),
$className
);
}
throw new AssertionError($message);
} | [
"public",
"static",
"function",
"assertInstanceOf",
"(",
"string",
"$",
"className",
",",
"$",
"actual",
",",
"string",
"$",
"message",
"=",
"''",
")",
"{",
"self",
"::",
"$",
"count",
"+=",
"1",
";",
"if",
"(",
"$",
"actual",
"instanceof",
"$",
"className",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"message",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'Failed asserting that %s is an instance of %s'",
",",
"static",
"::",
"getType",
"(",
"$",
"actual",
")",
",",
"$",
"className",
")",
";",
"}",
"throw",
"new",
"AssertionError",
"(",
"$",
"message",
")",
";",
"}"
] | Test if the given object is an instance of the given class
@example
\Cundd\TestFlight\Assert::assertInstanceOf(stdClass::class, new stdClass());
\Cundd\TestFlight\Assert::assertInstanceOf('stdClass', new stdClass());
test_flight_throws(function() { \Cundd\TestFlight\Assert::assertInstanceOf('stdClass', new Exception()); });
@param string $className
@param mixed $actual
@param string $message
@throws AssertionError | [
"Test",
"if",
"the",
"given",
"object",
"is",
"an",
"instance",
"of",
"the",
"given",
"class"
] | 9d8424dfb586f823f9dad2dcb81ff3986e255d56 | https://github.com/cundd/test-flight/blob/9d8424dfb586f823f9dad2dcb81ff3986e255d56/src/Assert.php#L218-L234 |
7,385 | cundd/test-flight | src/Assert.php | Assert.assertTypeOf | public static function assertTypeOf(string $type, $actual, string $message = '')
{
self::$count += 1;
switch (strtolower($type)) {
case 'array':
if (is_array($actual)) {
return;
}
break;
case 'resource':
if (is_resource($actual)) {
return;
}
break;
case 'object':
if (is_object($actual)) {
return;
}
break;
case 'int':
case 'integer':
case 'long':
if (is_int($actual)) {
return;
}
break;
case 'double':
case 'float':
if (is_float($actual)) {
return;
}
break;
case 'numeric':
if (is_numeric($actual)) {
return;
}
break;
case 'bool':
case 'boolean':
if (is_bool($actual)) {
return;
}
break;
case 'callable':
if (is_callable($actual)) {
return;
}
break;
case 'null':
if (is_null($actual)) {
return;
}
break;
case 'string':
if (is_string($actual)) {
return;
}
break;
default:
throw new AssertionLogicError(sprintf('No assertion defined for type %s', $type));
}
if (!$message) {
$message = sprintf(
'Failed asserting that %s is of type %s',
static::getType($actual),
$type
);
}
throw new AssertionError($message);
} | php | public static function assertTypeOf(string $type, $actual, string $message = '')
{
self::$count += 1;
switch (strtolower($type)) {
case 'array':
if (is_array($actual)) {
return;
}
break;
case 'resource':
if (is_resource($actual)) {
return;
}
break;
case 'object':
if (is_object($actual)) {
return;
}
break;
case 'int':
case 'integer':
case 'long':
if (is_int($actual)) {
return;
}
break;
case 'double':
case 'float':
if (is_float($actual)) {
return;
}
break;
case 'numeric':
if (is_numeric($actual)) {
return;
}
break;
case 'bool':
case 'boolean':
if (is_bool($actual)) {
return;
}
break;
case 'callable':
if (is_callable($actual)) {
return;
}
break;
case 'null':
if (is_null($actual)) {
return;
}
break;
case 'string':
if (is_string($actual)) {
return;
}
break;
default:
throw new AssertionLogicError(sprintf('No assertion defined for type %s', $type));
}
if (!$message) {
$message = sprintf(
'Failed asserting that %s is of type %s',
static::getType($actual),
$type
);
}
throw new AssertionError($message);
} | [
"public",
"static",
"function",
"assertTypeOf",
"(",
"string",
"$",
"type",
",",
"$",
"actual",
",",
"string",
"$",
"message",
"=",
"''",
")",
"{",
"self",
"::",
"$",
"count",
"+=",
"1",
";",
"switch",
"(",
"strtolower",
"(",
"$",
"type",
")",
")",
"{",
"case",
"'array'",
":",
"if",
"(",
"is_array",
"(",
"$",
"actual",
")",
")",
"{",
"return",
";",
"}",
"break",
";",
"case",
"'resource'",
":",
"if",
"(",
"is_resource",
"(",
"$",
"actual",
")",
")",
"{",
"return",
";",
"}",
"break",
";",
"case",
"'object'",
":",
"if",
"(",
"is_object",
"(",
"$",
"actual",
")",
")",
"{",
"return",
";",
"}",
"break",
";",
"case",
"'int'",
":",
"case",
"'integer'",
":",
"case",
"'long'",
":",
"if",
"(",
"is_int",
"(",
"$",
"actual",
")",
")",
"{",
"return",
";",
"}",
"break",
";",
"case",
"'double'",
":",
"case",
"'float'",
":",
"if",
"(",
"is_float",
"(",
"$",
"actual",
")",
")",
"{",
"return",
";",
"}",
"break",
";",
"case",
"'numeric'",
":",
"if",
"(",
"is_numeric",
"(",
"$",
"actual",
")",
")",
"{",
"return",
";",
"}",
"break",
";",
"case",
"'bool'",
":",
"case",
"'boolean'",
":",
"if",
"(",
"is_bool",
"(",
"$",
"actual",
")",
")",
"{",
"return",
";",
"}",
"break",
";",
"case",
"'callable'",
":",
"if",
"(",
"is_callable",
"(",
"$",
"actual",
")",
")",
"{",
"return",
";",
"}",
"break",
";",
"case",
"'null'",
":",
"if",
"(",
"is_null",
"(",
"$",
"actual",
")",
")",
"{",
"return",
";",
"}",
"break",
";",
"case",
"'string'",
":",
"if",
"(",
"is_string",
"(",
"$",
"actual",
")",
")",
"{",
"return",
";",
"}",
"break",
";",
"default",
":",
"throw",
"new",
"AssertionLogicError",
"(",
"sprintf",
"(",
"'No assertion defined for type %s'",
",",
"$",
"type",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"message",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'Failed asserting that %s is of type %s'",
",",
"static",
"::",
"getType",
"(",
"$",
"actual",
")",
",",
"$",
"type",
")",
";",
"}",
"throw",
"new",
"AssertionError",
"(",
"$",
"message",
")",
";",
"}"
] | Test if the given value is an instance of the given type
@example
\Cundd\TestFlight\Assert::assertTypeOf('array', []);
\Cundd\TestFlight\Assert::assertTypeOf('Array', []);
\Cundd\TestFlight\Assert::assertTypeOf('object', new stdClass());
\Cundd\TestFlight\Assert::assertTypeOf('int', 0);
\Cundd\TestFlight\Assert::assertTypeOf('integer', 1);
\Cundd\TestFlight\Assert::assertTypeOf('long', 1);
\Cundd\TestFlight\Assert::assertTypeOf('float', 0.1);
\Cundd\TestFlight\Assert::assertTypeOf('double', 0.1);
\Cundd\TestFlight\Assert::assertTypeOf('numeric', 1);
\Cundd\TestFlight\Assert::assertTypeOf('numeric', 0.1);
\Cundd\TestFlight\Assert::assertTypeOf('numeric', '1');
\Cundd\TestFlight\Assert::assertTypeOf('numeric', '0.1');
\Cundd\TestFlight\Assert::assertTypeOf('null', null);
\Cundd\TestFlight\Assert::assertTypeOf('string', 'a string');
\Cundd\TestFlight\Assert::assertTypeOf('string', 'null');
\Cundd\TestFlight\Assert::assertTypeOf('resource', fopen('php://temp', 'a+'));
@param string $type
@param mixed $actual
@param string $message
@throws AssertionError | [
"Test",
"if",
"the",
"given",
"value",
"is",
"an",
"instance",
"of",
"the",
"given",
"type"
] | 9d8424dfb586f823f9dad2dcb81ff3986e255d56 | https://github.com/cundd/test-flight/blob/9d8424dfb586f823f9dad2dcb81ff3986e255d56/src/Assert.php#L262-L343 |
7,386 | blenderdeluxe/khipu | src/Khipu.php | Khipu.loadService | public function loadService($service_name) {
// Definimos el nombre de la clase completa del servicio.
$class = 'BlenderDeluxe\Khipu\KhipuService\KhipuService' . $service_name;
// Asignamos la ruta del archivo que contiene la clase.
// Consultamos si existe el archivo.
if (class_exists($class)) {
// Si existe se llama.
$services_name = self::getAllServicesName();
if ($services_name[$service_name]) {
// Es requerido identificarse para usar estos servicios.
if ($this->receiver_id && $this->secret) {
$service = new $class($this->receiver_id, $this->secret);
} else {
// Invocamos un Exception
throw new Exception("Is necessary to authenticate to use the service \"$service_name\"");
}
}
else {
$service = new $class();
}
$service->setAgent($this->agent);
return $service;
}
// Si no existe el servicio se invoca un Exception
throw new Exception("The service \"$service_name\" does not exist");
} | php | public function loadService($service_name) {
// Definimos el nombre de la clase completa del servicio.
$class = 'BlenderDeluxe\Khipu\KhipuService\KhipuService' . $service_name;
// Asignamos la ruta del archivo que contiene la clase.
// Consultamos si existe el archivo.
if (class_exists($class)) {
// Si existe se llama.
$services_name = self::getAllServicesName();
if ($services_name[$service_name]) {
// Es requerido identificarse para usar estos servicios.
if ($this->receiver_id && $this->secret) {
$service = new $class($this->receiver_id, $this->secret);
} else {
// Invocamos un Exception
throw new Exception("Is necessary to authenticate to use the service \"$service_name\"");
}
}
else {
$service = new $class();
}
$service->setAgent($this->agent);
return $service;
}
// Si no existe el servicio se invoca un Exception
throw new Exception("The service \"$service_name\" does not exist");
} | [
"public",
"function",
"loadService",
"(",
"$",
"service_name",
")",
"{",
"// Definimos el nombre de la clase completa del servicio.",
"$",
"class",
"=",
"'BlenderDeluxe\\Khipu\\KhipuService\\KhipuService'",
".",
"$",
"service_name",
";",
"// Asignamos la ruta del archivo que contiene la clase.",
"// Consultamos si existe el archivo.",
"if",
"(",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"// Si existe se llama.",
"$",
"services_name",
"=",
"self",
"::",
"getAllServicesName",
"(",
")",
";",
"if",
"(",
"$",
"services_name",
"[",
"$",
"service_name",
"]",
")",
"{",
"// Es requerido identificarse para usar estos servicios.",
"if",
"(",
"$",
"this",
"->",
"receiver_id",
"&&",
"$",
"this",
"->",
"secret",
")",
"{",
"$",
"service",
"=",
"new",
"$",
"class",
"(",
"$",
"this",
"->",
"receiver_id",
",",
"$",
"this",
"->",
"secret",
")",
";",
"}",
"else",
"{",
"// Invocamos un Exception",
"throw",
"new",
"Exception",
"(",
"\"Is necessary to authenticate to use the service \\\"$service_name\\\"\"",
")",
";",
"}",
"}",
"else",
"{",
"$",
"service",
"=",
"new",
"$",
"class",
"(",
")",
";",
"}",
"$",
"service",
"->",
"setAgent",
"(",
"$",
"this",
"->",
"agent",
")",
";",
"return",
"$",
"service",
";",
"}",
"// Si no existe el servicio se invoca un Exception",
"throw",
"new",
"Exception",
"(",
"\"The service \\\"$service_name\\\" does not exist\"",
")",
";",
"}"
] | Carga el servicio y retorna el objeto, en caso de no existir el servicio,
se invoca un excepcion. | [
"Carga",
"el",
"servicio",
"y",
"retorna",
"el",
"objeto",
"en",
"caso",
"de",
"no",
"existir",
"el",
"servicio",
"se",
"invoca",
"un",
"excepcion",
"."
] | ef78fa8ba372c7784936ce95a3d0bd46a35e0143 | https://github.com/blenderdeluxe/khipu/blob/ef78fa8ba372c7784936ce95a3d0bd46a35e0143/src/Khipu.php#L75-L104 |
7,387 | blenderdeluxe/khipu | src/Khipu.php | Khipu.getUrlService | public static function getUrlService($service_name) {
$url_khipu = 'https://khipu.com/api/' . self::VERSION_KHIPU_SERVICE . '/';
$services_name = self::getAllServicesName();
if (array_key_exists($service_name, $services_name)) {
$str = $service_name;
$str[0] = strtolower($str[0]);
return $url_khipu . (string)$str;
}
return FALSE;
} | php | public static function getUrlService($service_name) {
$url_khipu = 'https://khipu.com/api/' . self::VERSION_KHIPU_SERVICE . '/';
$services_name = self::getAllServicesName();
if (array_key_exists($service_name, $services_name)) {
$str = $service_name;
$str[0] = strtolower($str[0]);
return $url_khipu . (string)$str;
}
return FALSE;
} | [
"public",
"static",
"function",
"getUrlService",
"(",
"$",
"service_name",
")",
"{",
"$",
"url_khipu",
"=",
"'https://khipu.com/api/'",
".",
"self",
"::",
"VERSION_KHIPU_SERVICE",
".",
"'/'",
";",
"$",
"services_name",
"=",
"self",
"::",
"getAllServicesName",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"service_name",
",",
"$",
"services_name",
")",
")",
"{",
"$",
"str",
"=",
"$",
"service_name",
";",
"$",
"str",
"[",
"0",
"]",
"=",
"strtolower",
"(",
"$",
"str",
"[",
"0",
"]",
")",
";",
"return",
"$",
"url_khipu",
".",
"(",
"string",
")",
"$",
"str",
";",
"}",
"return",
"FALSE",
";",
"}"
] | Funcion que retorna las URL de los servicios de Khipu.
@param string $service_name
Nombre del servicio | [
"Funcion",
"que",
"retorna",
"las",
"URL",
"de",
"los",
"servicios",
"de",
"Khipu",
"."
] | ef78fa8ba372c7784936ce95a3d0bd46a35e0143 | https://github.com/blenderdeluxe/khipu/blob/ef78fa8ba372c7784936ce95a3d0bd46a35e0143/src/Khipu.php#L112-L123 |
7,388 | blenderdeluxe/khipu | src/Khipu.php | Khipu.getAllServicesName | public static function getAllServicesName() {
return array(
'CreateEmail' => TRUE,
'CreatePaymentPage' => TRUE,
'CreatePaymentURL' => TRUE,
'VerifyPaymentNotification' => FALSE,
'ReceiverStatus' => TRUE,
'SetBillExpired' => TRUE,
'SetPaidByReceiver' => TRUE,
'SetRejectedByPayer' => TRUE,
'PaymentStatus' => TRUE,
'UpdatePaymentNotificationUrl' => TRUE,
'ReceiverBanks' => TRUE,
'GetPaymentNotification' => TRUE,
);
} | php | public static function getAllServicesName() {
return array(
'CreateEmail' => TRUE,
'CreatePaymentPage' => TRUE,
'CreatePaymentURL' => TRUE,
'VerifyPaymentNotification' => FALSE,
'ReceiverStatus' => TRUE,
'SetBillExpired' => TRUE,
'SetPaidByReceiver' => TRUE,
'SetRejectedByPayer' => TRUE,
'PaymentStatus' => TRUE,
'UpdatePaymentNotificationUrl' => TRUE,
'ReceiverBanks' => TRUE,
'GetPaymentNotification' => TRUE,
);
} | [
"public",
"static",
"function",
"getAllServicesName",
"(",
")",
"{",
"return",
"array",
"(",
"'CreateEmail'",
"=>",
"TRUE",
",",
"'CreatePaymentPage'",
"=>",
"TRUE",
",",
"'CreatePaymentURL'",
"=>",
"TRUE",
",",
"'VerifyPaymentNotification'",
"=>",
"FALSE",
",",
"'ReceiverStatus'",
"=>",
"TRUE",
",",
"'SetBillExpired'",
"=>",
"TRUE",
",",
"'SetPaidByReceiver'",
"=>",
"TRUE",
",",
"'SetRejectedByPayer'",
"=>",
"TRUE",
",",
"'PaymentStatus'",
"=>",
"TRUE",
",",
"'UpdatePaymentNotificationUrl'",
"=>",
"TRUE",
",",
"'ReceiverBanks'",
"=>",
"TRUE",
",",
"'GetPaymentNotification'",
"=>",
"TRUE",
",",
")",
";",
"}"
] | Funcion que retorna los nombre de servicios que existen y si se requiere
identificarse. | [
"Funcion",
"que",
"retorna",
"los",
"nombre",
"de",
"servicios",
"que",
"existen",
"y",
"si",
"se",
"requiere",
"identificarse",
"."
] | ef78fa8ba372c7784936ce95a3d0bd46a35e0143 | https://github.com/blenderdeluxe/khipu/blob/ef78fa8ba372c7784936ce95a3d0bd46a35e0143/src/Khipu.php#L130-L145 |
7,389 | Dhii/normalization-helper-base | src/NormalizeStringableCapableTrait.php | NormalizeStringableCapableTrait._normalizeStringable | protected function _normalizeStringable($stringable)
{
if (!is_scalar($stringable)
&& !($stringable instanceof Stringable)
) {
throw $this->_createInvalidArgumentException($this->__('Not a stringable value'), null, null, $stringable);
}
return $stringable;
} | php | protected function _normalizeStringable($stringable)
{
if (!is_scalar($stringable)
&& !($stringable instanceof Stringable)
) {
throw $this->_createInvalidArgumentException($this->__('Not a stringable value'), null, null, $stringable);
}
return $stringable;
} | [
"protected",
"function",
"_normalizeStringable",
"(",
"$",
"stringable",
")",
"{",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"stringable",
")",
"&&",
"!",
"(",
"$",
"stringable",
"instanceof",
"Stringable",
")",
")",
"{",
"throw",
"$",
"this",
"->",
"_createInvalidArgumentException",
"(",
"$",
"this",
"->",
"__",
"(",
"'Not a stringable value'",
")",
",",
"null",
",",
"null",
",",
"$",
"stringable",
")",
";",
"}",
"return",
"$",
"stringable",
";",
"}"
] | Normalizes a stringable value.
Useful to make sure that a value can be converted to string in a meaningful way.
@since [*next-version*]
@param Stringable|string|int|float|bool $stringable The value to normalize.
Can be an object that implements {@see Stringable}, or scalar type -
basically anything that can be converted to a string in a meaningful way.
@throws InvalidArgumentException If the value could not be normalized.
@return Stringable|string|int|float|bool The normalized stringable.
If the original value was stringable, that same value will be returned without any modification. | [
"Normalizes",
"a",
"stringable",
"value",
"."
] | 1b64f0ea6b3e32f9478f854f6049500795b51da7 | https://github.com/Dhii/normalization-helper-base/blob/1b64f0ea6b3e32f9478f854f6049500795b51da7/src/NormalizeStringableCapableTrait.php#L32-L41 |
7,390 | dmitrymomot/slim-mvc | src/Model.php | Model.setConnectionConfig | public static function setConnectionConfig()
{
if (!static::$_dbConnectionConfig) {
$config = static::_getDbConnectionConfig();
if (!is_array($config) || empty($config))
throw new \ErrorException(
'Not set configuration of database in file '
.APPPATH.'config/database.php. '
.'See example '.__DIR__.'database.php.config_example'
);
static::_setDbConnectionConfig($config);
static::$_dbConnectionConfig = $config;
}
} | php | public static function setConnectionConfig()
{
if (!static::$_dbConnectionConfig) {
$config = static::_getDbConnectionConfig();
if (!is_array($config) || empty($config))
throw new \ErrorException(
'Not set configuration of database in file '
.APPPATH.'config/database.php. '
.'See example '.__DIR__.'database.php.config_example'
);
static::_setDbConnectionConfig($config);
static::$_dbConnectionConfig = $config;
}
} | [
"public",
"static",
"function",
"setConnectionConfig",
"(",
")",
"{",
"if",
"(",
"!",
"static",
"::",
"$",
"_dbConnectionConfig",
")",
"{",
"$",
"config",
"=",
"static",
"::",
"_getDbConnectionConfig",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"config",
")",
"||",
"empty",
"(",
"$",
"config",
")",
")",
"throw",
"new",
"\\",
"ErrorException",
"(",
"'Not set configuration of database in file '",
".",
"APPPATH",
".",
"'config/database.php. '",
".",
"'See example '",
".",
"__DIR__",
".",
"'database.php.config_example'",
")",
";",
"static",
"::",
"_setDbConnectionConfig",
"(",
"$",
"config",
")",
";",
"static",
"::",
"$",
"_dbConnectionConfig",
"=",
"$",
"config",
";",
"}",
"}"
] | Set connection settings
@return void | [
"Set",
"connection",
"settings"
] | 432f694bc7263204e09a1261177d5df84353a8af | https://github.com/dmitrymomot/slim-mvc/blob/432f694bc7263204e09a1261177d5df84353a8af/src/Model.php#L21-L34 |
7,391 | dmitrymomot/slim-mvc | src/Model.php | Model._setDbConnectionConfig | protected static function _setDbConnectionConfig(array $config)
{
$app = \Slim\Slim::getInstance();
$cfg = Config::instance();
$cfg->set_connections($config);
$cfg->set_default_connection($app->config('mode'));
} | php | protected static function _setDbConnectionConfig(array $config)
{
$app = \Slim\Slim::getInstance();
$cfg = Config::instance();
$cfg->set_connections($config);
$cfg->set_default_connection($app->config('mode'));
} | [
"protected",
"static",
"function",
"_setDbConnectionConfig",
"(",
"array",
"$",
"config",
")",
"{",
"$",
"app",
"=",
"\\",
"Slim",
"\\",
"Slim",
"::",
"getInstance",
"(",
")",
";",
"$",
"cfg",
"=",
"Config",
"::",
"instance",
"(",
")",
";",
"$",
"cfg",
"->",
"set_connections",
"(",
"$",
"config",
")",
";",
"$",
"cfg",
"->",
"set_default_connection",
"(",
"$",
"app",
"->",
"config",
"(",
"'mode'",
")",
")",
";",
"}"
] | Sets database configs
@param array $config
@return void | [
"Sets",
"database",
"configs"
] | 432f694bc7263204e09a1261177d5df84353a8af | https://github.com/dmitrymomot/slim-mvc/blob/432f694bc7263204e09a1261177d5df84353a8af/src/Model.php#L54-L60 |
7,392 | hglattergotz/metrics | src/HGG/Metrics/Metrics.php | Metrics.toArray | public function toArray()
{
if ($this->timer !== null) {
$this->values['elapsed-time'] = $this->timer->getElapsedTime(true);
}
return $this->values;
} | php | public function toArray()
{
if ($this->timer !== null) {
$this->values['elapsed-time'] = $this->timer->getElapsedTime(true);
}
return $this->values;
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"timer",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"values",
"[",
"'elapsed-time'",
"]",
"=",
"$",
"this",
"->",
"timer",
"->",
"getElapsedTime",
"(",
"true",
")",
";",
"}",
"return",
"$",
"this",
"->",
"values",
";",
"}"
] | Return the results as an array
If the timer option is on also add the elapsed time to the result array and
format it to hh:mm:ss if greater than one second
@return array | [
"Return",
"the",
"results",
"as",
"an",
"array"
] | 0fc0c445ee78a53b0b1fa4c36179e47ac1fa0538 | https://github.com/hglattergotz/metrics/blob/0fc0c445ee78a53b0b1fa4c36179e47ac1fa0538/src/HGG/Metrics/Metrics.php#L123-L130 |
7,393 | stakhanovist/worker | library/ProcessStrategy/ForwardProcessorStrategy.php | ForwardProcessorStrategy.postProcess | public function postProcess(ProcessEvent $e)
{
$appEvent = clone $e->getWorker()->getEvent();
$appEvent->setTarget($appEvent->getApplication());
$appEvents = $appEvent->getApplication()->getEventManager();
$appResponse = clone $appEvent->getResponse();
$appEvent->setResponse($appResponse);
$appEvent->setResult($e->getResult());
$appEvents->trigger(MvcEvent::EVENT_RENDER, $appEvent);
$e->setResult($appEvent->getResponse()->getContent());
if (Console::isConsole() && is_string($e->getResult())) {
echo $e->getResult();
}
} | php | public function postProcess(ProcessEvent $e)
{
$appEvent = clone $e->getWorker()->getEvent();
$appEvent->setTarget($appEvent->getApplication());
$appEvents = $appEvent->getApplication()->getEventManager();
$appResponse = clone $appEvent->getResponse();
$appEvent->setResponse($appResponse);
$appEvent->setResult($e->getResult());
$appEvents->trigger(MvcEvent::EVENT_RENDER, $appEvent);
$e->setResult($appEvent->getResponse()->getContent());
if (Console::isConsole() && is_string($e->getResult())) {
echo $e->getResult();
}
} | [
"public",
"function",
"postProcess",
"(",
"ProcessEvent",
"$",
"e",
")",
"{",
"$",
"appEvent",
"=",
"clone",
"$",
"e",
"->",
"getWorker",
"(",
")",
"->",
"getEvent",
"(",
")",
";",
"$",
"appEvent",
"->",
"setTarget",
"(",
"$",
"appEvent",
"->",
"getApplication",
"(",
")",
")",
";",
"$",
"appEvents",
"=",
"$",
"appEvent",
"->",
"getApplication",
"(",
")",
"->",
"getEventManager",
"(",
")",
";",
"$",
"appResponse",
"=",
"clone",
"$",
"appEvent",
"->",
"getResponse",
"(",
")",
";",
"$",
"appEvent",
"->",
"setResponse",
"(",
"$",
"appResponse",
")",
";",
"$",
"appEvent",
"->",
"setResult",
"(",
"$",
"e",
"->",
"getResult",
"(",
")",
")",
";",
"$",
"appEvents",
"->",
"trigger",
"(",
"MvcEvent",
"::",
"EVENT_RENDER",
",",
"$",
"appEvent",
")",
";",
"$",
"e",
"->",
"setResult",
"(",
"$",
"appEvent",
"->",
"getResponse",
"(",
")",
"->",
"getContent",
"(",
")",
")",
";",
"if",
"(",
"Console",
"::",
"isConsole",
"(",
")",
"&&",
"is_string",
"(",
"$",
"e",
"->",
"getResult",
"(",
")",
")",
")",
"{",
"echo",
"$",
"e",
"->",
"getResult",
"(",
")",
";",
"}",
"}"
] | Render the processor result.
The result is rendered triggering a "render" event on a cloned MvcEvent,
simulating the usual MVC render flow.
@todo investigate if simulation works in all cases
@param ProcessEvent $e | [
"Render",
"the",
"processor",
"result",
"."
] | 63f6aaeb06986a7c39b5e5c4be742b92942b5d3f | https://github.com/stakhanovist/worker/blob/63f6aaeb06986a7c39b5e5c4be742b92942b5d3f/library/ProcessStrategy/ForwardProcessorStrategy.php#L88-L106 |
7,394 | FelixOnline/Core | src/FelixOnline/Core/CurrentUser.php | CurrentUser.createSession | public function createSession()
{
if (!$this->getUser()) {
throw new \Exceptions\InternalException('Will not create session where no user is set');
}
$this->destroySessions(); // Delete old sessions for user
$app = App::getInstance();
$sql = $app['safesql']->query(
"INSERT INTO `login`
(
session_id,
session_name,
ip,
browser,
user,
logged_in,
deleted
) VALUES (
'%s',
'%s',
'%s',
'%s',
'%s',
1,
0
)",
array(
$app['env']['session']->getId(),
SESSION_NAME,
$app['env']['RemoteIP'],
$app['env']['RemoteUA'],
$this->getUser(),
));
$app['db']->query($sql);
$app['env']['session']['uname'] = $this->getUser();
$app['env']['session']['loggedin'] = true;
} | php | public function createSession()
{
if (!$this->getUser()) {
throw new \Exceptions\InternalException('Will not create session where no user is set');
}
$this->destroySessions(); // Delete old sessions for user
$app = App::getInstance();
$sql = $app['safesql']->query(
"INSERT INTO `login`
(
session_id,
session_name,
ip,
browser,
user,
logged_in,
deleted
) VALUES (
'%s',
'%s',
'%s',
'%s',
'%s',
1,
0
)",
array(
$app['env']['session']->getId(),
SESSION_NAME,
$app['env']['RemoteIP'],
$app['env']['RemoteUA'],
$this->getUser(),
));
$app['db']->query($sql);
$app['env']['session']['uname'] = $this->getUser();
$app['env']['session']['loggedin'] = true;
} | [
"public",
"function",
"createSession",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getUser",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"Exceptions",
"\\",
"InternalException",
"(",
"'Will not create session where no user is set'",
")",
";",
"}",
"$",
"this",
"->",
"destroySessions",
"(",
")",
";",
"// Delete old sessions for user",
"$",
"app",
"=",
"App",
"::",
"getInstance",
"(",
")",
";",
"$",
"sql",
"=",
"$",
"app",
"[",
"'safesql'",
"]",
"->",
"query",
"(",
"\"INSERT INTO `login`\n (\n session_id,\n session_name,\n ip,\n browser,\n user,\n logged_in,\n deleted\n ) VALUES (\n '%s',\n '%s',\n '%s',\n '%s',\n '%s',\n 1,\n 0\n )\"",
",",
"array",
"(",
"$",
"app",
"[",
"'env'",
"]",
"[",
"'session'",
"]",
"->",
"getId",
"(",
")",
",",
"SESSION_NAME",
",",
"$",
"app",
"[",
"'env'",
"]",
"[",
"'RemoteIP'",
"]",
",",
"$",
"app",
"[",
"'env'",
"]",
"[",
"'RemoteUA'",
"]",
",",
"$",
"this",
"->",
"getUser",
"(",
")",
",",
")",
")",
";",
"$",
"app",
"[",
"'db'",
"]",
"->",
"query",
"(",
"$",
"sql",
")",
";",
"$",
"app",
"[",
"'env'",
"]",
"[",
"'session'",
"]",
"[",
"'uname'",
"]",
"=",
"$",
"this",
"->",
"getUser",
"(",
")",
";",
"$",
"app",
"[",
"'env'",
"]",
"[",
"'session'",
"]",
"[",
"'loggedin'",
"]",
"=",
"true",
";",
"}"
] | Create session for user | [
"Create",
"session",
"for",
"user"
] | b29f50cd96cee73da83968ee1eb88d8b3ab1c430 | https://github.com/FelixOnline/Core/blob/b29f50cd96cee73da83968ee1eb88d8b3ab1c430/src/FelixOnline/Core/CurrentUser.php#L73-L113 |
7,395 | indigophp-archive/codeception-fuel-module | fuel/fuel/packages/email/classes/email/driver/sendmail.php | Email_Driver_Sendmail._send | protected function _send()
{
// Build the message
$message = $this->build_message();
// Open a connection
$return_path = ($this->config['return_path'] !== false) ? $this->config['return_path'] : $this->config['from']['email'];
$handle = @popen($this->config['sendmail_path'] . " -oi -f ".$return_path." -t", 'w');
// No connection?
if(! is_resource($handle))
{
throw new \SendmailConnectionException('Could not open a sendmail connection at: '.$this->config['sendmail_path']);
}
// Send the headers
fputs($handle, $message['header']);
// Send the body
fputs($handle, $message['body']);
if(pclose($handle) === -1)
{
throw new \SendmailFailedException('Failed sending email through sendmail.');
}
return true;
} | php | protected function _send()
{
// Build the message
$message = $this->build_message();
// Open a connection
$return_path = ($this->config['return_path'] !== false) ? $this->config['return_path'] : $this->config['from']['email'];
$handle = @popen($this->config['sendmail_path'] . " -oi -f ".$return_path." -t", 'w');
// No connection?
if(! is_resource($handle))
{
throw new \SendmailConnectionException('Could not open a sendmail connection at: '.$this->config['sendmail_path']);
}
// Send the headers
fputs($handle, $message['header']);
// Send the body
fputs($handle, $message['body']);
if(pclose($handle) === -1)
{
throw new \SendmailFailedException('Failed sending email through sendmail.');
}
return true;
} | [
"protected",
"function",
"_send",
"(",
")",
"{",
"// Build the message",
"$",
"message",
"=",
"$",
"this",
"->",
"build_message",
"(",
")",
";",
"// Open a connection",
"$",
"return_path",
"=",
"(",
"$",
"this",
"->",
"config",
"[",
"'return_path'",
"]",
"!==",
"false",
")",
"?",
"$",
"this",
"->",
"config",
"[",
"'return_path'",
"]",
":",
"$",
"this",
"->",
"config",
"[",
"'from'",
"]",
"[",
"'email'",
"]",
";",
"$",
"handle",
"=",
"@",
"popen",
"(",
"$",
"this",
"->",
"config",
"[",
"'sendmail_path'",
"]",
".",
"\" -oi -f \"",
".",
"$",
"return_path",
".",
"\" -t\"",
",",
"'w'",
")",
";",
"// No connection?",
"if",
"(",
"!",
"is_resource",
"(",
"$",
"handle",
")",
")",
"{",
"throw",
"new",
"\\",
"SendmailConnectionException",
"(",
"'Could not open a sendmail connection at: '",
".",
"$",
"this",
"->",
"config",
"[",
"'sendmail_path'",
"]",
")",
";",
"}",
"// Send the headers",
"fputs",
"(",
"$",
"handle",
",",
"$",
"message",
"[",
"'header'",
"]",
")",
";",
"// Send the body",
"fputs",
"(",
"$",
"handle",
",",
"$",
"message",
"[",
"'body'",
"]",
")",
";",
"if",
"(",
"pclose",
"(",
"$",
"handle",
")",
"===",
"-",
"1",
")",
"{",
"throw",
"new",
"\\",
"SendmailFailedException",
"(",
"'Failed sending email through sendmail.'",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Initalted all needed for Sendmail mailing.
@throws \SendmailConnectionException Could not open a sendmail connection
@throws \SendmailFailedException Failed sending email through sendmail
@return bool Success boolean | [
"Initalted",
"all",
"needed",
"for",
"Sendmail",
"mailing",
"."
] | 0973b7cbd540a0e89cc5bb7af94627f77f09bf49 | https://github.com/indigophp-archive/codeception-fuel-module/blob/0973b7cbd540a0e89cc5bb7af94627f77f09bf49/fuel/fuel/packages/email/classes/email/driver/sendmail.php#L32-L59 |
7,396 | bd808/moar-net-http | src/Moar/Net/Http/Request.php | Request.addQueryData | public function addQueryData ($parms) {
$this->setUrl(Util::addQueryData($this->getUrl(), $parms));
return $this;
} | php | public function addQueryData ($parms) {
$this->setUrl(Util::addQueryData($this->getUrl(), $parms));
return $this;
} | [
"public",
"function",
"addQueryData",
"(",
"$",
"parms",
")",
"{",
"$",
"this",
"->",
"setUrl",
"(",
"Util",
"::",
"addQueryData",
"(",
"$",
"this",
"->",
"getUrl",
"(",
")",
",",
"$",
"parms",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Append a query string to the current URL.
@param string|array $parms Parameters to add as query string to url
@return Request Self, for message chaining | [
"Append",
"a",
"query",
"string",
"to",
"the",
"current",
"URL",
"."
] | 828ddb020f6f6b87d0e5e4506c17b5b9c0c25eaf | https://github.com/bd808/moar-net-http/blob/828ddb020f6f6b87d0e5e4506c17b5b9c0c25eaf/src/Moar/Net/Http/Request.php#L267-L270 |
7,397 | bd808/moar-net-http | src/Moar/Net/Http/Request.php | Request.setCredentials | public function setCredentials ($user, $password, $type = CURLAUTH_ANYSAFE) {
$this->addCurlOption(CURLOPT_HTTPAUTH, $type);
$this->addCurlOption(CURLOPT_USERPWD, "{$user}:{$password}");
return $this;
} | php | public function setCredentials ($user, $password, $type = CURLAUTH_ANYSAFE) {
$this->addCurlOption(CURLOPT_HTTPAUTH, $type);
$this->addCurlOption(CURLOPT_USERPWD, "{$user}:{$password}");
return $this;
} | [
"public",
"function",
"setCredentials",
"(",
"$",
"user",
",",
"$",
"password",
",",
"$",
"type",
"=",
"CURLAUTH_ANYSAFE",
")",
"{",
"$",
"this",
"->",
"addCurlOption",
"(",
"CURLOPT_HTTPAUTH",
",",
"$",
"type",
")",
";",
"$",
"this",
"->",
"addCurlOption",
"(",
"CURLOPT_USERPWD",
",",
"\"{$user}:{$password}\"",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set credentials for authenticating to remote host.
@param string $user Username
@param string $password Password
@param int $type Auth type to attempt. See CURLOPT_HTTPAUTH section of
curl_setopt page at php.net for options.
@return Request Self, for message chaining | [
"Set",
"credentials",
"for",
"authenticating",
"to",
"remote",
"host",
"."
] | 828ddb020f6f6b87d0e5e4506c17b5b9c0c25eaf | https://github.com/bd808/moar-net-http/blob/828ddb020f6f6b87d0e5e4506c17b5b9c0c25eaf/src/Moar/Net/Http/Request.php#L385-L389 |
7,398 | bd808/moar-net-http | src/Moar/Net/Http/Request.php | Request.setX509Credentials | public function setX509Credentials ($cert, $key, $keypass, $type = 'PEM') {
$this->addCurlOption(CURLOPT_SSLCERTTYPE, $type);
$this->addCurlOption(CURLOPT_SSLCERT, $cert);
$this->addCurlOption(CURLOPT_SSLKEY, $key);
$this->addCurlOption(CURLOPT_SSLKEYPASSWD, $keypass);
return $this;
} | php | public function setX509Credentials ($cert, $key, $keypass, $type = 'PEM') {
$this->addCurlOption(CURLOPT_SSLCERTTYPE, $type);
$this->addCurlOption(CURLOPT_SSLCERT, $cert);
$this->addCurlOption(CURLOPT_SSLKEY, $key);
$this->addCurlOption(CURLOPT_SSLKEYPASSWD, $keypass);
return $this;
} | [
"public",
"function",
"setX509Credentials",
"(",
"$",
"cert",
",",
"$",
"key",
",",
"$",
"keypass",
",",
"$",
"type",
"=",
"'PEM'",
")",
"{",
"$",
"this",
"->",
"addCurlOption",
"(",
"CURLOPT_SSLCERTTYPE",
",",
"$",
"type",
")",
";",
"$",
"this",
"->",
"addCurlOption",
"(",
"CURLOPT_SSLCERT",
",",
"$",
"cert",
")",
";",
"$",
"this",
"->",
"addCurlOption",
"(",
"CURLOPT_SSLKEY",
",",
"$",
"key",
")",
";",
"$",
"this",
"->",
"addCurlOption",
"(",
"CURLOPT_SSLKEYPASSWD",
",",
"$",
"keypass",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set x509 credentials for authenticating to remote host.
@param string $cert Path to x509 certificate
@param string $key Patch to x509 private key
@param string $keypass Passphrase to decrypt private key
@param string $type Certificate encoding (PEM|DER|ENG)
@return Request Self, for message chaining | [
"Set",
"x509",
"credentials",
"for",
"authenticating",
"to",
"remote",
"host",
"."
] | 828ddb020f6f6b87d0e5e4506c17b5b9c0c25eaf | https://github.com/bd808/moar-net-http/blob/828ddb020f6f6b87d0e5e4506c17b5b9c0c25eaf/src/Moar/Net/Http/Request.php#L401-L407 |
7,399 | bd808/moar-net-http | src/Moar/Net/Http/Request.php | Request.setCookieJar | public function setCookieJar ($file) {
if (null !== $file) {
$this->addCurlOption(CURLOPT_COOKIEFILE, $file); //read from file
$this->addCurlOption(CURLOPT_COOKIEJAR, $file); //write to file
}
return $this;
} | php | public function setCookieJar ($file) {
if (null !== $file) {
$this->addCurlOption(CURLOPT_COOKIEFILE, $file); //read from file
$this->addCurlOption(CURLOPT_COOKIEJAR, $file); //write to file
}
return $this;
} | [
"public",
"function",
"setCookieJar",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"addCurlOption",
"(",
"CURLOPT_COOKIEFILE",
",",
"$",
"file",
")",
";",
"//read from file",
"$",
"this",
"->",
"addCurlOption",
"(",
"CURLOPT_COOKIEJAR",
",",
"$",
"file",
")",
";",
"//write to file",
"}",
"return",
"$",
"this",
";",
"}"
] | Read and store cookies in the provided file.
@param string $file Path to cookie storage file
@return Request Self, for message chaining | [
"Read",
"and",
"store",
"cookies",
"in",
"the",
"provided",
"file",
"."
] | 828ddb020f6f6b87d0e5e4506c17b5b9c0c25eaf | https://github.com/bd808/moar-net-http/blob/828ddb020f6f6b87d0e5e4506c17b5b9c0c25eaf/src/Moar/Net/Http/Request.php#L416-L422 |
Subsets and Splits