id int32 0 241k | repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 |
|---|---|---|---|---|---|---|---|---|---|---|---|
35,500 | hail-framework/framework | src/Template/Engine.php | Engine.compile | public function compile($name): string
{
[
'template' => $template,
'cache' => $cache,
] = $this->getTemplateFile($name);
if (\filemtime($template) < @\filemtime($cache)) {
return $cache;
}
$root = Tokenizer\Tokenizer::parseFile($template);
Processor::parseToken($root, $this->processors);
\file_put_contents($cache, (string) $root);
return $cache;
} | php | public function compile($name): string
{
[
'template' => $template,
'cache' => $cache,
] = $this->getTemplateFile($name);
if (\filemtime($template) < @\filemtime($cache)) {
return $cache;
}
$root = Tokenizer\Tokenizer::parseFile($template);
Processor::parseToken($root, $this->processors);
\file_put_contents($cache, (string) $root);
return $cache;
} | [
"public",
"function",
"compile",
"(",
"$",
"name",
")",
":",
"string",
"{",
"[",
"'template'",
"=>",
"$",
"template",
",",
"'cache'",
"=>",
"$",
"cache",
",",
"]",
"=",
"$",
"this",
"->",
"getTemplateFile",
"(",
"$",
"name",
")",
";",
"if",
"(",
"\\",
"filemtime",
"(",
"$",
"template",
")",
"<",
"@",
"\\",
"filemtime",
"(",
"$",
"cache",
")",
")",
"{",
"return",
"$",
"cache",
";",
"}",
"$",
"root",
"=",
"Tokenizer",
"\\",
"Tokenizer",
"::",
"parseFile",
"(",
"$",
"template",
")",
";",
"Processor",
"::",
"parseToken",
"(",
"$",
"root",
",",
"$",
"this",
"->",
"processors",
")",
";",
"\\",
"file_put_contents",
"(",
"$",
"cache",
",",
"(",
"string",
")",
"$",
"root",
")",
";",
"return",
"$",
"cache",
";",
"}"
] | Compile the html, and return the compiled file.
@return string the compiled file. | [
"Compile",
"the",
"html",
"and",
"return",
"the",
"compiled",
"file",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Template/Engine.php#L340-L358 |
35,501 | hail-framework/framework | src/Filesystem/Adapter/Memory.php | Memory.doListContents | protected function doListContents($directory, $recursive)
{
$filter = function ($path) use ($directory, $recursive) {
// Remove the root directory from any listing.
if ($path === '') {
return false;
}
if (Util::dirname($path) === $directory) {
return true;
}
return $recursive && $this->pathIsInDirectory($path, $directory);
};
return \array_filter(\array_keys($this->storage), $filter);
} | php | protected function doListContents($directory, $recursive)
{
$filter = function ($path) use ($directory, $recursive) {
// Remove the root directory from any listing.
if ($path === '') {
return false;
}
if (Util::dirname($path) === $directory) {
return true;
}
return $recursive && $this->pathIsInDirectory($path, $directory);
};
return \array_filter(\array_keys($this->storage), $filter);
} | [
"protected",
"function",
"doListContents",
"(",
"$",
"directory",
",",
"$",
"recursive",
")",
"{",
"$",
"filter",
"=",
"function",
"(",
"$",
"path",
")",
"use",
"(",
"$",
"directory",
",",
"$",
"recursive",
")",
"{",
"// Remove the root directory from any listing.",
"if",
"(",
"$",
"path",
"===",
"''",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"Util",
"::",
"dirname",
"(",
"$",
"path",
")",
"===",
"$",
"directory",
")",
"{",
"return",
"true",
";",
"}",
"return",
"$",
"recursive",
"&&",
"$",
"this",
"->",
"pathIsInDirectory",
"(",
"$",
"path",
",",
"$",
"directory",
")",
";",
"}",
";",
"return",
"\\",
"array_filter",
"(",
"\\",
"array_keys",
"(",
"$",
"this",
"->",
"storage",
")",
",",
"$",
"filter",
")",
";",
"}"
] | Filters the file system returning paths inside the directory.
@param string $directory
@param bool $recursive
@return string[] | [
"Filters",
"the",
"file",
"system",
"returning",
"paths",
"inside",
"the",
"directory",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Filesystem/Adapter/Memory.php#L269-L285 |
35,502 | hail-framework/framework | src/Util/Validator.php | Validator.validateRequired | protected function validateRequired($field, $value, array $params = [], array $fields = [])
{
if (isset($params[0]) && (bool) $params[0]) {
$find = $this->getPart($fields, \explode('.', $field), true);
return $find[1];
}
if (null === $value) {
return false;
}
if (\is_string($value) && \trim($value) === '') {
return false;
}
return true;
} | php | protected function validateRequired($field, $value, array $params = [], array $fields = [])
{
if (isset($params[0]) && (bool) $params[0]) {
$find = $this->getPart($fields, \explode('.', $field), true);
return $find[1];
}
if (null === $value) {
return false;
}
if (\is_string($value) && \trim($value) === '') {
return false;
}
return true;
} | [
"protected",
"function",
"validateRequired",
"(",
"$",
"field",
",",
"$",
"value",
",",
"array",
"$",
"params",
"=",
"[",
"]",
",",
"array",
"$",
"fields",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"0",
"]",
")",
"&&",
"(",
"bool",
")",
"$",
"params",
"[",
"0",
"]",
")",
"{",
"$",
"find",
"=",
"$",
"this",
"->",
"getPart",
"(",
"$",
"fields",
",",
"\\",
"explode",
"(",
"'.'",
",",
"$",
"field",
")",
",",
"true",
")",
";",
"return",
"$",
"find",
"[",
"1",
"]",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"value",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"value",
")",
"&&",
"\\",
"trim",
"(",
"$",
"value",
")",
"===",
"''",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Required field validator
@param string $field
@param mixed $value
@param array $params
@param array $fields
@return bool | [
"Required",
"field",
"validator"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L131-L148 |
35,503 | hail-framework/framework | src/Util/Validator.php | Validator.validateEquals | protected function validateEquals($field, $value, array $params)
{
// extract the second field value, this accounts for nested array values
[$field2Value, $multiple] = $this->getPart($this->_fields, \explode('.', $params[0]));
return null !== $field2Value && $value === $field2Value;
} | php | protected function validateEquals($field, $value, array $params)
{
// extract the second field value, this accounts for nested array values
[$field2Value, $multiple] = $this->getPart($this->_fields, \explode('.', $params[0]));
return null !== $field2Value && $value === $field2Value;
} | [
"protected",
"function",
"validateEquals",
"(",
"$",
"field",
",",
"$",
"value",
",",
"array",
"$",
"params",
")",
"{",
"// extract the second field value, this accounts for nested array values",
"[",
"$",
"field2Value",
",",
"$",
"multiple",
"]",
"=",
"$",
"this",
"->",
"getPart",
"(",
"$",
"this",
"->",
"_fields",
",",
"\\",
"explode",
"(",
"'.'",
",",
"$",
"params",
"[",
"0",
"]",
")",
")",
";",
"return",
"null",
"!==",
"$",
"field2Value",
"&&",
"$",
"value",
"===",
"$",
"field2Value",
";",
"}"
] | Validate that two values match
@param string $field
@param mixed $value
@param array $params
@internal param array $fields
@return bool | [
"Validate",
"that",
"two",
"values",
"match"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L160-L166 |
35,504 | hail-framework/framework | src/Util/Validator.php | Validator.validateInteger | protected function validateInteger($field, $value, $params)
{
if (isset($params[0]) && (bool) $params[0]) {
//strict mode
return preg_match('/^(\d|-[1-9]|-?[1-9]\d*)$/i', $value);
}
return \filter_var($value, \FILTER_VALIDATE_INT) !== false;
} | php | protected function validateInteger($field, $value, $params)
{
if (isset($params[0]) && (bool) $params[0]) {
//strict mode
return preg_match('/^(\d|-[1-9]|-?[1-9]\d*)$/i', $value);
}
return \filter_var($value, \FILTER_VALIDATE_INT) !== false;
} | [
"protected",
"function",
"validateInteger",
"(",
"$",
"field",
",",
"$",
"value",
",",
"$",
"params",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"0",
"]",
")",
"&&",
"(",
"bool",
")",
"$",
"params",
"[",
"0",
"]",
")",
"{",
"//strict mode",
"return",
"preg_match",
"(",
"'/^(\\d|-[1-9]|-?[1-9]\\d*)$/i'",
",",
"$",
"value",
")",
";",
"}",
"return",
"\\",
"filter_var",
"(",
"$",
"value",
",",
"\\",
"FILTER_VALIDATE_INT",
")",
"!==",
"false",
";",
"}"
] | Validate that a field is an integer
@param string $field
@param mixed $value
@return bool | [
"Validate",
"that",
"a",
"field",
"is",
"an",
"integer"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L237-L245 |
35,505 | hail-framework/framework | src/Util/Validator.php | Validator.validateLength | protected function validateLength($field, $value, $params)
{
$length = $this->stringLength($value);
// Length between
if (isset($params[1])) {
return $length >= $params[0] && $length <= $params[1];
}
// Length same
return ($length !== false) && $length == $params[0];
} | php | protected function validateLength($field, $value, $params)
{
$length = $this->stringLength($value);
// Length between
if (isset($params[1])) {
return $length >= $params[0] && $length <= $params[1];
}
// Length same
return ($length !== false) && $length == $params[0];
} | [
"protected",
"function",
"validateLength",
"(",
"$",
"field",
",",
"$",
"value",
",",
"$",
"params",
")",
"{",
"$",
"length",
"=",
"$",
"this",
"->",
"stringLength",
"(",
"$",
"value",
")",
";",
"// Length between",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"1",
"]",
")",
")",
"{",
"return",
"$",
"length",
">=",
"$",
"params",
"[",
"0",
"]",
"&&",
"$",
"length",
"<=",
"$",
"params",
"[",
"1",
"]",
";",
"}",
"// Length same",
"return",
"(",
"$",
"length",
"!==",
"false",
")",
"&&",
"$",
"length",
"==",
"$",
"params",
"[",
"0",
"]",
";",
"}"
] | Validate the length of a string
@param string $field
@param mixed $value
@param array $params
@internal param array $fields
@return bool | [
"Validate",
"the",
"length",
"of",
"a",
"string"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L257-L267 |
35,506 | hail-framework/framework | src/Util/Validator.php | Validator.validateMin | protected function validateMin($field, $value, $params)
{
if (!\is_numeric($value)) {
return false;
}
if (\function_exists('\bccomp')) {
return !(\bccomp($params[0], $value, 14) === 1);
}
return $params[0] <= $value;
} | php | protected function validateMin($field, $value, $params)
{
if (!\is_numeric($value)) {
return false;
}
if (\function_exists('\bccomp')) {
return !(\bccomp($params[0], $value, 14) === 1);
}
return $params[0] <= $value;
} | [
"protected",
"function",
"validateMin",
"(",
"$",
"field",
",",
"$",
"value",
",",
"$",
"params",
")",
"{",
"if",
"(",
"!",
"\\",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"\\",
"function_exists",
"(",
"'\\bccomp'",
")",
")",
"{",
"return",
"!",
"(",
"\\",
"bccomp",
"(",
"$",
"params",
"[",
"0",
"]",
",",
"$",
"value",
",",
"14",
")",
"===",
"1",
")",
";",
"}",
"return",
"$",
"params",
"[",
"0",
"]",
"<=",
"$",
"value",
";",
"}"
] | Validate the size of a field is greater than a minimum value.
@param string $field
@param mixed $value
@param array $params
@internal param array $fields
@return bool | [
"Validate",
"the",
"size",
"of",
"a",
"field",
"is",
"greater",
"than",
"a",
"minimum",
"value",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L343-L354 |
35,507 | hail-framework/framework | src/Util/Validator.php | Validator.validateMax | protected function validateMax($field, $value, $params)
{
if (!\is_numeric($value)) {
return false;
}
if (\function_exists('\bccomp')) {
return !(\bccomp($value, $params[0], 14) === 1);
}
return $params[0] >= $value;
} | php | protected function validateMax($field, $value, $params)
{
if (!\is_numeric($value)) {
return false;
}
if (\function_exists('\bccomp')) {
return !(\bccomp($value, $params[0], 14) === 1);
}
return $params[0] >= $value;
} | [
"protected",
"function",
"validateMax",
"(",
"$",
"field",
",",
"$",
"value",
",",
"$",
"params",
")",
"{",
"if",
"(",
"!",
"\\",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"\\",
"function_exists",
"(",
"'\\bccomp'",
")",
")",
"{",
"return",
"!",
"(",
"\\",
"bccomp",
"(",
"$",
"value",
",",
"$",
"params",
"[",
"0",
"]",
",",
"14",
")",
"===",
"1",
")",
";",
"}",
"return",
"$",
"params",
"[",
"0",
"]",
">=",
"$",
"value",
";",
"}"
] | Validate the size of a field is less than a maximum value
@param string $field
@param mixed $value
@param array $params
@internal param array $fields
@return bool | [
"Validate",
"the",
"size",
"of",
"a",
"field",
"is",
"less",
"than",
"a",
"maximum",
"value"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L366-L377 |
35,508 | hail-framework/framework | src/Util/Validator.php | Validator.validateBetween | protected function validateBetween($field, $value, $params)
{
if (!\is_numeric($value)) {
return false;
}
if (!isset($params[0]) || !\is_array($params[0]) || \count($params[0]) !== 2) {
return false;
}
list($min, $max) = $params[0];
return $this->validateMin($field, $value, [$min]) && $this->validateMax($field, $value, [$max]);
} | php | protected function validateBetween($field, $value, $params)
{
if (!\is_numeric($value)) {
return false;
}
if (!isset($params[0]) || !\is_array($params[0]) || \count($params[0]) !== 2) {
return false;
}
list($min, $max) = $params[0];
return $this->validateMin($field, $value, [$min]) && $this->validateMax($field, $value, [$max]);
} | [
"protected",
"function",
"validateBetween",
"(",
"$",
"field",
",",
"$",
"value",
",",
"$",
"params",
")",
"{",
"if",
"(",
"!",
"\\",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"params",
"[",
"0",
"]",
")",
"||",
"!",
"\\",
"is_array",
"(",
"$",
"params",
"[",
"0",
"]",
")",
"||",
"\\",
"count",
"(",
"$",
"params",
"[",
"0",
"]",
")",
"!==",
"2",
")",
"{",
"return",
"false",
";",
"}",
"list",
"(",
"$",
"min",
",",
"$",
"max",
")",
"=",
"$",
"params",
"[",
"0",
"]",
";",
"return",
"$",
"this",
"->",
"validateMin",
"(",
"$",
"field",
",",
"$",
"value",
",",
"[",
"$",
"min",
"]",
")",
"&&",
"$",
"this",
"->",
"validateMax",
"(",
"$",
"field",
",",
"$",
"value",
",",
"[",
"$",
"max",
"]",
")",
";",
"}"
] | Validate the size of a field is between min and max values
@param string $field
@param mixed $value
@param array $params
@return bool | [
"Validate",
"the",
"size",
"of",
"a",
"field",
"is",
"between",
"min",
"and",
"max",
"values"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L388-L400 |
35,509 | hail-framework/framework | src/Util/Validator.php | Validator.validateIn | protected function validateIn($field, $value, $params)
{
$isAssoc = \array_values($params[0]) !== $params[0];
if ($isAssoc) {
$params[0] = \array_keys($params[0]);
}
$strict = false;
if (isset($params[1])) {
$strict = $params[1];
}
return \in_array($value, $params[0], $strict);
} | php | protected function validateIn($field, $value, $params)
{
$isAssoc = \array_values($params[0]) !== $params[0];
if ($isAssoc) {
$params[0] = \array_keys($params[0]);
}
$strict = false;
if (isset($params[1])) {
$strict = $params[1];
}
return \in_array($value, $params[0], $strict);
} | [
"protected",
"function",
"validateIn",
"(",
"$",
"field",
",",
"$",
"value",
",",
"$",
"params",
")",
"{",
"$",
"isAssoc",
"=",
"\\",
"array_values",
"(",
"$",
"params",
"[",
"0",
"]",
")",
"!==",
"$",
"params",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"isAssoc",
")",
"{",
"$",
"params",
"[",
"0",
"]",
"=",
"\\",
"array_keys",
"(",
"$",
"params",
"[",
"0",
"]",
")",
";",
"}",
"$",
"strict",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"1",
"]",
")",
")",
"{",
"$",
"strict",
"=",
"$",
"params",
"[",
"1",
"]",
";",
"}",
"return",
"\\",
"in_array",
"(",
"$",
"value",
",",
"$",
"params",
"[",
"0",
"]",
",",
"$",
"strict",
")",
";",
"}"
] | Validate a field is contained within a list of values
@param string $field
@param mixed $value
@param array $params
@internal param array $fields
@return bool | [
"Validate",
"a",
"field",
"is",
"contained",
"within",
"a",
"list",
"of",
"values"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L412-L425 |
35,510 | hail-framework/framework | src/Util/Validator.php | Validator.validateContains | protected function validateContains($field, $value, $params)
{
if (!isset($params[0])) {
return false;
}
if (!\is_string($value) || !\is_string($params[0])) {
return false;
}
$strict = true;
if (isset($params[1])) {
$strict = (bool) $params[1];
}
if ($strict) {
return \mb_strpos($value, $params[0]) !== false;
}
return \mb_stripos($value, $params[0]) !== false;
} | php | protected function validateContains($field, $value, $params)
{
if (!isset($params[0])) {
return false;
}
if (!\is_string($value) || !\is_string($params[0])) {
return false;
}
$strict = true;
if (isset($params[1])) {
$strict = (bool) $params[1];
}
if ($strict) {
return \mb_strpos($value, $params[0]) !== false;
}
return \mb_stripos($value, $params[0]) !== false;
} | [
"protected",
"function",
"validateContains",
"(",
"$",
"field",
",",
"$",
"value",
",",
"$",
"params",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"params",
"[",
"0",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"\\",
"is_string",
"(",
"$",
"value",
")",
"||",
"!",
"\\",
"is_string",
"(",
"$",
"params",
"[",
"0",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"strict",
"=",
"true",
";",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"1",
"]",
")",
")",
"{",
"$",
"strict",
"=",
"(",
"bool",
")",
"$",
"params",
"[",
"1",
"]",
";",
"}",
"if",
"(",
"$",
"strict",
")",
"{",
"return",
"\\",
"mb_strpos",
"(",
"$",
"value",
",",
"$",
"params",
"[",
"0",
"]",
")",
"!==",
"false",
";",
"}",
"return",
"\\",
"mb_stripos",
"(",
"$",
"value",
",",
"$",
"params",
"[",
"0",
"]",
")",
"!==",
"false",
";",
"}"
] | Validate a field contains a given string
@param string $field
@param string $value
@param array $params
@return bool | [
"Validate",
"a",
"field",
"contains",
"a",
"given",
"string"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L451-L470 |
35,511 | hail-framework/framework | src/Util/Validator.php | Validator.validateSubset | protected function validateSubset($field, $value, $params)
{
if (!isset($params[0])) {
return false;
}
if (!\is_array($params[0])) {
$params[0] = [$params[0]];
}
if (\is_scalar($value)) {
return $this->validateIn($field, $value, $params);
}
$intersect = \array_intersect($value, $params[0]);
return \array_diff($value, $intersect) === \array_diff($intersect, $value);
} | php | protected function validateSubset($field, $value, $params)
{
if (!isset($params[0])) {
return false;
}
if (!\is_array($params[0])) {
$params[0] = [$params[0]];
}
if (\is_scalar($value)) {
return $this->validateIn($field, $value, $params);
}
$intersect = \array_intersect($value, $params[0]);
return \array_diff($value, $intersect) === \array_diff($intersect, $value);
} | [
"protected",
"function",
"validateSubset",
"(",
"$",
"field",
",",
"$",
"value",
",",
"$",
"params",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"params",
"[",
"0",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"params",
"[",
"0",
"]",
")",
")",
"{",
"$",
"params",
"[",
"0",
"]",
"=",
"[",
"$",
"params",
"[",
"0",
"]",
"]",
";",
"}",
"if",
"(",
"\\",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"this",
"->",
"validateIn",
"(",
"$",
"field",
",",
"$",
"value",
",",
"$",
"params",
")",
";",
"}",
"$",
"intersect",
"=",
"\\",
"array_intersect",
"(",
"$",
"value",
",",
"$",
"params",
"[",
"0",
"]",
")",
";",
"return",
"\\",
"array_diff",
"(",
"$",
"value",
",",
"$",
"intersect",
")",
"===",
"\\",
"array_diff",
"(",
"$",
"intersect",
",",
"$",
"value",
")",
";",
"}"
] | Validate that all field values contains a given array
@param string $field
@param array $value
@param array $params
@return bool | [
"Validate",
"that",
"all",
"field",
"values",
"contains",
"a",
"given",
"array"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L481-L495 |
35,512 | hail-framework/framework | src/Util/Validator.php | Validator.validateContainsUnique | protected function validateContainsUnique($field, $value)
{
if (!\is_array($value)) {
return false;
}
return $value === \array_unique($value, SORT_REGULAR);
} | php | protected function validateContainsUnique($field, $value)
{
if (!\is_array($value)) {
return false;
}
return $value === \array_unique($value, SORT_REGULAR);
} | [
"protected",
"function",
"validateContainsUnique",
"(",
"$",
"field",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"value",
"===",
"\\",
"array_unique",
"(",
"$",
"value",
",",
"SORT_REGULAR",
")",
";",
"}"
] | Validate that field array has only unique values
@param string $field
@param array $value
@return bool | [
"Validate",
"that",
"field",
"array",
"has",
"only",
"unique",
"values"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L505-L512 |
35,513 | hail-framework/framework | src/Util/Validator.php | Validator.validateEmailDNS | protected function validateEmailDNS($field, $value)
{
if ($this->validateEmail($field, $value)) {
$domain = \ltrim(\strstr($value, '@'), '@') . '.';
if (\defined('INTL_IDNA_VARIANT_UTS46') && \function_exists('\idn_to_ascii')) {
$domain = \idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46);
}
return \checkdnsrr($domain, 'ANY');
}
return false;
} | php | protected function validateEmailDNS($field, $value)
{
if ($this->validateEmail($field, $value)) {
$domain = \ltrim(\strstr($value, '@'), '@') . '.';
if (\defined('INTL_IDNA_VARIANT_UTS46') && \function_exists('\idn_to_ascii')) {
$domain = \idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46);
}
return \checkdnsrr($domain, 'ANY');
}
return false;
} | [
"protected",
"function",
"validateEmailDNS",
"(",
"$",
"field",
",",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"validateEmail",
"(",
"$",
"field",
",",
"$",
"value",
")",
")",
"{",
"$",
"domain",
"=",
"\\",
"ltrim",
"(",
"\\",
"strstr",
"(",
"$",
"value",
",",
"'@'",
")",
",",
"'@'",
")",
".",
"'.'",
";",
"if",
"(",
"\\",
"defined",
"(",
"'INTL_IDNA_VARIANT_UTS46'",
")",
"&&",
"\\",
"function_exists",
"(",
"'\\idn_to_ascii'",
")",
")",
"{",
"$",
"domain",
"=",
"\\",
"idn_to_ascii",
"(",
"$",
"domain",
",",
"0",
",",
"INTL_IDNA_VARIANT_UTS46",
")",
";",
"}",
"return",
"\\",
"checkdnsrr",
"(",
"$",
"domain",
",",
"'ANY'",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Validate that a field is a valid e-mail address and the domain name is active
@param string $field
@param mixed $value
@return bool | [
"Validate",
"that",
"a",
"field",
"is",
"a",
"valid",
"e",
"-",
"mail",
"address",
"and",
"the",
"domain",
"name",
"is",
"active"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L593-L605 |
35,514 | hail-framework/framework | src/Util/Validator.php | Validator.validateUrl | protected function validateUrl($field, $value)
{
foreach (static::$validUrlPrefixes as $prefix) {
if (\strpos($value, $prefix) !== false) {
return \filter_var($value, \FILTER_VALIDATE_URL) !== false;
}
}
return false;
} | php | protected function validateUrl($field, $value)
{
foreach (static::$validUrlPrefixes as $prefix) {
if (\strpos($value, $prefix) !== false) {
return \filter_var($value, \FILTER_VALIDATE_URL) !== false;
}
}
return false;
} | [
"protected",
"function",
"validateUrl",
"(",
"$",
"field",
",",
"$",
"value",
")",
"{",
"foreach",
"(",
"static",
"::",
"$",
"validUrlPrefixes",
"as",
"$",
"prefix",
")",
"{",
"if",
"(",
"\\",
"strpos",
"(",
"$",
"value",
",",
"$",
"prefix",
")",
"!==",
"false",
")",
"{",
"return",
"\\",
"filter_var",
"(",
"$",
"value",
",",
"\\",
"FILTER_VALIDATE_URL",
")",
"!==",
"false",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Validate that a field is a valid URL by syntax
@param string $field
@param mixed $value
@return bool | [
"Validate",
"that",
"a",
"field",
"is",
"a",
"valid",
"URL",
"by",
"syntax"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L615-L624 |
35,515 | hail-framework/framework | src/Util/Validator.php | Validator.validateUrlActive | protected function validateUrlActive($field, $value)
{
foreach (static::$validUrlPrefixes as $prefix) {
if (\strpos($value, $prefix) !== false) {
$host = \parse_url(\strtolower($value), PHP_URL_HOST);
return \checkdnsrr($host, 'A') || \checkdnsrr($host, 'AAAA') || \checkdnsrr($host, 'CNAME');
}
}
return false;
} | php | protected function validateUrlActive($field, $value)
{
foreach (static::$validUrlPrefixes as $prefix) {
if (\strpos($value, $prefix) !== false) {
$host = \parse_url(\strtolower($value), PHP_URL_HOST);
return \checkdnsrr($host, 'A') || \checkdnsrr($host, 'AAAA') || \checkdnsrr($host, 'CNAME');
}
}
return false;
} | [
"protected",
"function",
"validateUrlActive",
"(",
"$",
"field",
",",
"$",
"value",
")",
"{",
"foreach",
"(",
"static",
"::",
"$",
"validUrlPrefixes",
"as",
"$",
"prefix",
")",
"{",
"if",
"(",
"\\",
"strpos",
"(",
"$",
"value",
",",
"$",
"prefix",
")",
"!==",
"false",
")",
"{",
"$",
"host",
"=",
"\\",
"parse_url",
"(",
"\\",
"strtolower",
"(",
"$",
"value",
")",
",",
"PHP_URL_HOST",
")",
";",
"return",
"\\",
"checkdnsrr",
"(",
"$",
"host",
",",
"'A'",
")",
"||",
"\\",
"checkdnsrr",
"(",
"$",
"host",
",",
"'AAAA'",
")",
"||",
"\\",
"checkdnsrr",
"(",
"$",
"host",
",",
"'CNAME'",
")",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Validate that a field is an active URL by verifying DNS record
@param string $field
@param mixed $value
@return bool | [
"Validate",
"that",
"a",
"field",
"is",
"an",
"active",
"URL",
"by",
"verifying",
"DNS",
"record"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L634-L645 |
35,516 | hail-framework/framework | src/Util/Validator.php | Validator.validateDateFormat | protected function validateDateFormat($field, $value, $params)
{
$parsed = \date_parse_from_format($params[0], $value);
return $parsed['error_count'] === 0 && $parsed['warning_count'] === 0;
} | php | protected function validateDateFormat($field, $value, $params)
{
$parsed = \date_parse_from_format($params[0], $value);
return $parsed['error_count'] === 0 && $parsed['warning_count'] === 0;
} | [
"protected",
"function",
"validateDateFormat",
"(",
"$",
"field",
",",
"$",
"value",
",",
"$",
"params",
")",
"{",
"$",
"parsed",
"=",
"\\",
"date_parse_from_format",
"(",
"$",
"params",
"[",
"0",
"]",
",",
"$",
"value",
")",
";",
"return",
"$",
"parsed",
"[",
"'error_count'",
"]",
"===",
"0",
"&&",
"$",
"parsed",
"[",
"'warning_count'",
"]",
"===",
"0",
";",
"}"
] | Validate that a field matches a date format
@param string $field
@param mixed $value
@param array $params
@internal param array $fields
@return bool | [
"Validate",
"that",
"a",
"field",
"matches",
"a",
"date",
"format"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L731-L736 |
35,517 | hail-framework/framework | src/Util/Validator.php | Validator.validateCreditCard | protected function validateCreditCard($field, $value, $params)
{
/**
* I there has been an array of valid cards supplied, or the name of the users card
* or the name and an array of valid cards
*/
if (!empty($params)) {
/**
* array of valid cards
*/
if (\is_array($params[0])) {
$cards = $params[0];
} elseif (\is_string($params[0])) {
$cardType = $params[0];
if (isset($params[1]) && \is_array($params[1])) {
$cards = $params[1];
if (!\in_array($cardType, $cards, true)) {
return false;
}
}
}
}
if ($this->creditCardNumberIsValid($value)) {
$cardRegex = [
'visa' => '#^4[0-9]{12}(?:[0-9]{3})?$#',
'mastercard' => '#^(5[1-5]|2[2-7])[0-9]{14}$#',
'amex' => '#^3[47][0-9]{13}$#',
'dinersclub' => '#^3(?:0[0-5]|[68][0-9])[0-9]{11}$#',
'discover' => '#^6(?:011|5[0-9]{2})[0-9]{12}$#',
];
if (isset($cardType)) {
// if we don't have any valid cards specified and the card we've been given isn't in our regex array
if (!isset($cards) && !isset($cardRegex[$cardType])) {
return false;
}
// we only need to test against one card type
return (\preg_match($cardRegex[$cardType], $value) === 1);
}
if (isset($cards)) {
// if we have cards, check our users card against only the ones we have
foreach ($cards as $card) {
if (
isset($cardRegex[$card]) &&
\preg_match($cardRegex[$card], $value) === 1 // if the card is valid, we want to stop looping
) {
return true;
}
}
} else {
// loop through every card
foreach ($cardRegex as $regex) {
// until we find a valid one
if (\preg_match($regex, $value) === 1) {
return true;
}
}
}
}
// if we've got this far, the card has passed no validation so it's invalid!
return false;
} | php | protected function validateCreditCard($field, $value, $params)
{
/**
* I there has been an array of valid cards supplied, or the name of the users card
* or the name and an array of valid cards
*/
if (!empty($params)) {
/**
* array of valid cards
*/
if (\is_array($params[0])) {
$cards = $params[0];
} elseif (\is_string($params[0])) {
$cardType = $params[0];
if (isset($params[1]) && \is_array($params[1])) {
$cards = $params[1];
if (!\in_array($cardType, $cards, true)) {
return false;
}
}
}
}
if ($this->creditCardNumberIsValid($value)) {
$cardRegex = [
'visa' => '#^4[0-9]{12}(?:[0-9]{3})?$#',
'mastercard' => '#^(5[1-5]|2[2-7])[0-9]{14}$#',
'amex' => '#^3[47][0-9]{13}$#',
'dinersclub' => '#^3(?:0[0-5]|[68][0-9])[0-9]{11}$#',
'discover' => '#^6(?:011|5[0-9]{2})[0-9]{12}$#',
];
if (isset($cardType)) {
// if we don't have any valid cards specified and the card we've been given isn't in our regex array
if (!isset($cards) && !isset($cardRegex[$cardType])) {
return false;
}
// we only need to test against one card type
return (\preg_match($cardRegex[$cardType], $value) === 1);
}
if (isset($cards)) {
// if we have cards, check our users card against only the ones we have
foreach ($cards as $card) {
if (
isset($cardRegex[$card]) &&
\preg_match($cardRegex[$card], $value) === 1 // if the card is valid, we want to stop looping
) {
return true;
}
}
} else {
// loop through every card
foreach ($cardRegex as $regex) {
// until we find a valid one
if (\preg_match($regex, $value) === 1) {
return true;
}
}
}
}
// if we've got this far, the card has passed no validation so it's invalid!
return false;
} | [
"protected",
"function",
"validateCreditCard",
"(",
"$",
"field",
",",
"$",
"value",
",",
"$",
"params",
")",
"{",
"/**\n * I there has been an array of valid cards supplied, or the name of the users card\n * or the name and an array of valid cards\n */",
"if",
"(",
"!",
"empty",
"(",
"$",
"params",
")",
")",
"{",
"/**\n * array of valid cards\n */",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"params",
"[",
"0",
"]",
")",
")",
"{",
"$",
"cards",
"=",
"$",
"params",
"[",
"0",
"]",
";",
"}",
"elseif",
"(",
"\\",
"is_string",
"(",
"$",
"params",
"[",
"0",
"]",
")",
")",
"{",
"$",
"cardType",
"=",
"$",
"params",
"[",
"0",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"1",
"]",
")",
"&&",
"\\",
"is_array",
"(",
"$",
"params",
"[",
"1",
"]",
")",
")",
"{",
"$",
"cards",
"=",
"$",
"params",
"[",
"1",
"]",
";",
"if",
"(",
"!",
"\\",
"in_array",
"(",
"$",
"cardType",
",",
"$",
"cards",
",",
"true",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"creditCardNumberIsValid",
"(",
"$",
"value",
")",
")",
"{",
"$",
"cardRegex",
"=",
"[",
"'visa'",
"=>",
"'#^4[0-9]{12}(?:[0-9]{3})?$#'",
",",
"'mastercard'",
"=>",
"'#^(5[1-5]|2[2-7])[0-9]{14}$#'",
",",
"'amex'",
"=>",
"'#^3[47][0-9]{13}$#'",
",",
"'dinersclub'",
"=>",
"'#^3(?:0[0-5]|[68][0-9])[0-9]{11}$#'",
",",
"'discover'",
"=>",
"'#^6(?:011|5[0-9]{2})[0-9]{12}$#'",
",",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"cardType",
")",
")",
"{",
"// if we don't have any valid cards specified and the card we've been given isn't in our regex array",
"if",
"(",
"!",
"isset",
"(",
"$",
"cards",
")",
"&&",
"!",
"isset",
"(",
"$",
"cardRegex",
"[",
"$",
"cardType",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"// we only need to test against one card type",
"return",
"(",
"\\",
"preg_match",
"(",
"$",
"cardRegex",
"[",
"$",
"cardType",
"]",
",",
"$",
"value",
")",
"===",
"1",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"cards",
")",
")",
"{",
"// if we have cards, check our users card against only the ones we have",
"foreach",
"(",
"$",
"cards",
"as",
"$",
"card",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"cardRegex",
"[",
"$",
"card",
"]",
")",
"&&",
"\\",
"preg_match",
"(",
"$",
"cardRegex",
"[",
"$",
"card",
"]",
",",
"$",
"value",
")",
"===",
"1",
"// if the card is valid, we want to stop looping",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"else",
"{",
"// loop through every card",
"foreach",
"(",
"$",
"cardRegex",
"as",
"$",
"regex",
")",
"{",
"// until we find a valid one",
"if",
"(",
"\\",
"preg_match",
"(",
"$",
"regex",
",",
"$",
"value",
")",
"===",
"1",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"}",
"// if we've got this far, the card has passed no validation so it's invalid!",
"return",
"false",
";",
"}"
] | Validate that a field contains a valid credit card
optionally filtered by an array
@param string $field
@param mixed $value
@param array $params
@return bool | [
"Validate",
"that",
"a",
"field",
"contains",
"a",
"valid",
"credit",
"card",
"optionally",
"filtered",
"by",
"an",
"array"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L797-L863 |
35,518 | hail-framework/framework | src/Util/Validator.php | Validator.data | public function data(array $data, array $fields = [])
{
// Allows filtering of used input fields against optional second array of field names allowed
// This is useful for limiting raw $_POST or $_GET data to only known fields
$this->_fields = $fields !== [] ? \array_intersect_key($data, \array_flip($fields)) : $data;
return $this;
} | php | public function data(array $data, array $fields = [])
{
// Allows filtering of used input fields against optional second array of field names allowed
// This is useful for limiting raw $_POST or $_GET data to only known fields
$this->_fields = $fields !== [] ? \array_intersect_key($data, \array_flip($fields)) : $data;
return $this;
} | [
"public",
"function",
"data",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"fields",
"=",
"[",
"]",
")",
"{",
"// Allows filtering of used input fields against optional second array of field names allowed",
"// This is useful for limiting raw $_POST or $_GET data to only known fields",
"$",
"this",
"->",
"_fields",
"=",
"$",
"fields",
"!==",
"[",
"]",
"?",
"\\",
"array_intersect_key",
"(",
"$",
"data",
",",
"\\",
"array_flip",
"(",
"$",
"fields",
")",
")",
":",
"$",
"data",
";",
"return",
"$",
"this",
";",
"}"
] | Set data for validator
@param array $data
@param array $fields
@return $this | [
"Set",
"data",
"for",
"validator"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L936-L943 |
35,519 | hail-framework/framework | src/Util/Validator.php | Validator.errors | public function errors(string $field = null)
{
if ($field !== null) {
return $this->_errors[$field] ?? false;
}
return $this->_errors;
} | php | public function errors(string $field = null)
{
if ($field !== null) {
return $this->_errors[$field] ?? false;
}
return $this->_errors;
} | [
"public",
"function",
"errors",
"(",
"string",
"$",
"field",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"field",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_errors",
"[",
"$",
"field",
"]",
"??",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"_errors",
";",
"}"
] | Get array of error messages
@param null|string $field
@return array|bool | [
"Get",
"array",
"of",
"error",
"messages"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L962-L969 |
35,520 | hail-framework/framework | src/Util/Validator.php | Validator.error | public function error(string $field, string $message, array $params = [])
{
$message = $this->checkAndSetLabel($field, $message, $params);
$values = [];
// Printed values need to be in string format
foreach ($params as $param) {
if (\is_array($param)) {
$param = "['" . implode("', '", $param) . "']";
} elseif ($param instanceof \DateTime) {
$param = $param->format('Y-m-d');
} elseif (\is_object($param)) {
$param = \get_class($param);
}
// Use custom label instead of field name if set
if (\is_string($params[0]) && isset($this->_labels[$param])) {
$param = $this->_labels[$param];
}
$values[] = $param;
}
$this->_errors[$field][] = \vsprintf($message, $values);
} | php | public function error(string $field, string $message, array $params = [])
{
$message = $this->checkAndSetLabel($field, $message, $params);
$values = [];
// Printed values need to be in string format
foreach ($params as $param) {
if (\is_array($param)) {
$param = "['" . implode("', '", $param) . "']";
} elseif ($param instanceof \DateTime) {
$param = $param->format('Y-m-d');
} elseif (\is_object($param)) {
$param = \get_class($param);
}
// Use custom label instead of field name if set
if (\is_string($params[0]) && isset($this->_labels[$param])) {
$param = $this->_labels[$param];
}
$values[] = $param;
}
$this->_errors[$field][] = \vsprintf($message, $values);
} | [
"public",
"function",
"error",
"(",
"string",
"$",
"field",
",",
"string",
"$",
"message",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"message",
"=",
"$",
"this",
"->",
"checkAndSetLabel",
"(",
"$",
"field",
",",
"$",
"message",
",",
"$",
"params",
")",
";",
"$",
"values",
"=",
"[",
"]",
";",
"// Printed values need to be in string format",
"foreach",
"(",
"$",
"params",
"as",
"$",
"param",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"param",
")",
")",
"{",
"$",
"param",
"=",
"\"['\"",
".",
"implode",
"(",
"\"', '\"",
",",
"$",
"param",
")",
".",
"\"']\"",
";",
"}",
"elseif",
"(",
"$",
"param",
"instanceof",
"\\",
"DateTime",
")",
"{",
"$",
"param",
"=",
"$",
"param",
"->",
"format",
"(",
"'Y-m-d'",
")",
";",
"}",
"elseif",
"(",
"\\",
"is_object",
"(",
"$",
"param",
")",
")",
"{",
"$",
"param",
"=",
"\\",
"get_class",
"(",
"$",
"param",
")",
";",
"}",
"// Use custom label instead of field name if set",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"params",
"[",
"0",
"]",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"_labels",
"[",
"$",
"param",
"]",
")",
")",
"{",
"$",
"param",
"=",
"$",
"this",
"->",
"_labels",
"[",
"$",
"param",
"]",
";",
"}",
"$",
"values",
"[",
"]",
"=",
"$",
"param",
";",
"}",
"$",
"this",
"->",
"_errors",
"[",
"$",
"field",
"]",
"[",
"]",
"=",
"\\",
"vsprintf",
"(",
"$",
"message",
",",
"$",
"values",
")",
";",
"}"
] | Add an error to error messages array
@param string $field
@param string $message
@param array $params | [
"Add",
"an",
"error",
"to",
"error",
"messages",
"array"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L978-L1001 |
35,521 | hail-framework/framework | src/Util/Validator.php | Validator.message | public function message(string $message)
{
$this->_validations[\count($this->_validations) - 1]['message'] = $message;
return $this;
} | php | public function message(string $message)
{
$this->_validations[\count($this->_validations) - 1]['message'] = $message;
return $this;
} | [
"public",
"function",
"message",
"(",
"string",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"_validations",
"[",
"\\",
"count",
"(",
"$",
"this",
"->",
"_validations",
")",
"-",
"1",
"]",
"[",
"'message'",
"]",
"=",
"$",
"message",
";",
"return",
"$",
"this",
";",
"}"
] | Specify validation message to use for error for the last validation rule
@param string $message
@return $this | [
"Specify",
"validation",
"message",
"to",
"use",
"for",
"error",
"for",
"the",
"last",
"validation",
"rule"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L1010-L1015 |
35,522 | hail-framework/framework | src/Util/Validator.php | Validator.reset | public function reset()
{
$this->_fields = [];
$this->_errors = [];
$this->_validations = [];
$this->_labels = [];
$this->_skips = [];
return $this;
} | php | public function reset()
{
$this->_fields = [];
$this->_errors = [];
$this->_validations = [];
$this->_labels = [];
$this->_skips = [];
return $this;
} | [
"public",
"function",
"reset",
"(",
")",
"{",
"$",
"this",
"->",
"_fields",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"_errors",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"_validations",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"_labels",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"_skips",
"=",
"[",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Reset object properties
@return $this | [
"Reset",
"object",
"properties"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L1022-L1031 |
35,523 | hail-framework/framework | src/Util/Validator.php | Validator.validate | public function validate()
{
$setToBreak = false;
foreach ($this->_validations as $v) {
foreach ($v['fields'] as $field) {
if (isset($this->_skips[$field])) {
if ($this->_skips[$field] === self::SKIP_ALL) {
break 2;
}
if ($this->_skips[$field] === self::SKIP_ONE) {
break;
}
}
[$values, $multiple] = $this->getPart($this->_fields, \explode('.', $field));
// Don't validate if the field is not required and the value is empty
if (null !== $values && $this->hasRule('optional', $field)) {
//Continue with execution below if statement
} elseif (
$v['rule'] !== 'accepted' &&
$v['rule'] !== 'required' && !$this->hasRule('required', $field) &&
(null === $values || $values === '' || ($multiple && \count($values) === 0))
) {
continue;
}
// Callback is user-specified or assumed method on class
$errors = $this->getRules();
if (isset($errors[$v['rule']])) {
$callback = $errors[$v['rule']];
} else {
$callback = [$this, 'validate' . \ucfirst($v['rule'])];
}
if (!$multiple) {
$values = [$values];
}
$result = true;
foreach ($values as $value) {
$result = $result && $callback($field, $value, $v['params'], $this->_fields);
}
if (!$result) {
$this->error($field, $v['message'], $v['params']);
if ($this->stopOnFirstFail) {
$setToBreak = true;
break;
}
$this->_skips[$field] = $v['skip'];
}
}
if ($setToBreak) {
break;
}
}
return \count($this->errors()) === 0;
} | php | public function validate()
{
$setToBreak = false;
foreach ($this->_validations as $v) {
foreach ($v['fields'] as $field) {
if (isset($this->_skips[$field])) {
if ($this->_skips[$field] === self::SKIP_ALL) {
break 2;
}
if ($this->_skips[$field] === self::SKIP_ONE) {
break;
}
}
[$values, $multiple] = $this->getPart($this->_fields, \explode('.', $field));
// Don't validate if the field is not required and the value is empty
if (null !== $values && $this->hasRule('optional', $field)) {
//Continue with execution below if statement
} elseif (
$v['rule'] !== 'accepted' &&
$v['rule'] !== 'required' && !$this->hasRule('required', $field) &&
(null === $values || $values === '' || ($multiple && \count($values) === 0))
) {
continue;
}
// Callback is user-specified or assumed method on class
$errors = $this->getRules();
if (isset($errors[$v['rule']])) {
$callback = $errors[$v['rule']];
} else {
$callback = [$this, 'validate' . \ucfirst($v['rule'])];
}
if (!$multiple) {
$values = [$values];
}
$result = true;
foreach ($values as $value) {
$result = $result && $callback($field, $value, $v['params'], $this->_fields);
}
if (!$result) {
$this->error($field, $v['message'], $v['params']);
if ($this->stopOnFirstFail) {
$setToBreak = true;
break;
}
$this->_skips[$field] = $v['skip'];
}
}
if ($setToBreak) {
break;
}
}
return \count($this->errors()) === 0;
} | [
"public",
"function",
"validate",
"(",
")",
"{",
"$",
"setToBreak",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"_validations",
"as",
"$",
"v",
")",
"{",
"foreach",
"(",
"$",
"v",
"[",
"'fields'",
"]",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_skips",
"[",
"$",
"field",
"]",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_skips",
"[",
"$",
"field",
"]",
"===",
"self",
"::",
"SKIP_ALL",
")",
"{",
"break",
"2",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_skips",
"[",
"$",
"field",
"]",
"===",
"self",
"::",
"SKIP_ONE",
")",
"{",
"break",
";",
"}",
"}",
"[",
"$",
"values",
",",
"$",
"multiple",
"]",
"=",
"$",
"this",
"->",
"getPart",
"(",
"$",
"this",
"->",
"_fields",
",",
"\\",
"explode",
"(",
"'.'",
",",
"$",
"field",
")",
")",
";",
"// Don't validate if the field is not required and the value is empty",
"if",
"(",
"null",
"!==",
"$",
"values",
"&&",
"$",
"this",
"->",
"hasRule",
"(",
"'optional'",
",",
"$",
"field",
")",
")",
"{",
"//Continue with execution below if statement",
"}",
"elseif",
"(",
"$",
"v",
"[",
"'rule'",
"]",
"!==",
"'accepted'",
"&&",
"$",
"v",
"[",
"'rule'",
"]",
"!==",
"'required'",
"&&",
"!",
"$",
"this",
"->",
"hasRule",
"(",
"'required'",
",",
"$",
"field",
")",
"&&",
"(",
"null",
"===",
"$",
"values",
"||",
"$",
"values",
"===",
"''",
"||",
"(",
"$",
"multiple",
"&&",
"\\",
"count",
"(",
"$",
"values",
")",
"===",
"0",
")",
")",
")",
"{",
"continue",
";",
"}",
"// Callback is user-specified or assumed method on class",
"$",
"errors",
"=",
"$",
"this",
"->",
"getRules",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"errors",
"[",
"$",
"v",
"[",
"'rule'",
"]",
"]",
")",
")",
"{",
"$",
"callback",
"=",
"$",
"errors",
"[",
"$",
"v",
"[",
"'rule'",
"]",
"]",
";",
"}",
"else",
"{",
"$",
"callback",
"=",
"[",
"$",
"this",
",",
"'validate'",
".",
"\\",
"ucfirst",
"(",
"$",
"v",
"[",
"'rule'",
"]",
")",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"multiple",
")",
"{",
"$",
"values",
"=",
"[",
"$",
"values",
"]",
";",
"}",
"$",
"result",
"=",
"true",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"$",
"result",
"=",
"$",
"result",
"&&",
"$",
"callback",
"(",
"$",
"field",
",",
"$",
"value",
",",
"$",
"v",
"[",
"'params'",
"]",
",",
"$",
"this",
"->",
"_fields",
")",
";",
"}",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"$",
"field",
",",
"$",
"v",
"[",
"'message'",
"]",
",",
"$",
"v",
"[",
"'params'",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"stopOnFirstFail",
")",
"{",
"$",
"setToBreak",
"=",
"true",
";",
"break",
";",
"}",
"$",
"this",
"->",
"_skips",
"[",
"$",
"field",
"]",
"=",
"$",
"v",
"[",
"'skip'",
"]",
";",
"}",
"}",
"if",
"(",
"$",
"setToBreak",
")",
"{",
"break",
";",
"}",
"}",
"return",
"\\",
"count",
"(",
"$",
"this",
"->",
"errors",
"(",
")",
")",
"===",
"0",
";",
"}"
] | Run validations and return boolean result
@return bool | [
"Run",
"validations",
"and",
"return",
"boolean",
"result"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L1094-L1156 |
35,524 | hail-framework/framework | src/Util/Validator.php | Validator.onErrorSkipField | public function onErrorSkipField(): self
{
$this->_validations[\count($this->_validations) - 1]['skip'] = self::SKIP_ONE;
return $this;
} | php | public function onErrorSkipField(): self
{
$this->_validations[\count($this->_validations) - 1]['skip'] = self::SKIP_ONE;
return $this;
} | [
"public",
"function",
"onErrorSkipField",
"(",
")",
":",
"self",
"{",
"$",
"this",
"->",
"_validations",
"[",
"\\",
"count",
"(",
"$",
"this",
"->",
"_validations",
")",
"-",
"1",
"]",
"[",
"'skip'",
"]",
"=",
"self",
"::",
"SKIP_ONE",
";",
"return",
"$",
"this",
";",
"}"
] | If the validation for a field fails, skip all other checks for this field.
@return static | [
"If",
"the",
"validation",
"for",
"a",
"field",
"fails",
"skip",
"all",
"other",
"checks",
"for",
"this",
"field",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L1177-L1182 |
35,525 | hail-framework/framework | src/Util/Validator.php | Validator.onErrorQuit | public function onErrorQuit(): self
{
$this->_validations[\count($this->_validations) - 1]['skip'] = self::SKIP_ALL;
return $this;
} | php | public function onErrorQuit(): self
{
$this->_validations[\count($this->_validations) - 1]['skip'] = self::SKIP_ALL;
return $this;
} | [
"public",
"function",
"onErrorQuit",
"(",
")",
":",
"self",
"{",
"$",
"this",
"->",
"_validations",
"[",
"\\",
"count",
"(",
"$",
"this",
"->",
"_validations",
")",
"-",
"1",
"]",
"[",
"'skip'",
"]",
"=",
"self",
"::",
"SKIP_ALL",
";",
"return",
"$",
"this",
";",
"}"
] | If the validation of a field fails, stop the validation process.
@return static | [
"If",
"the",
"validation",
"of",
"a",
"field",
"fails",
"stop",
"the",
"validation",
"process",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L1189-L1194 |
35,526 | hail-framework/framework | src/Util/Validator.php | Validator.hasRule | protected function hasRule(string $name, string $field): bool
{
foreach ($this->_validations as $validation) {
if ($validation['rule'] === $name && \in_array($field, $validation['fields'], true)) {
return true;
}
}
return false;
} | php | protected function hasRule(string $name, string $field): bool
{
foreach ($this->_validations as $validation) {
if ($validation['rule'] === $name && \in_array($field, $validation['fields'], true)) {
return true;
}
}
return false;
} | [
"protected",
"function",
"hasRule",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"field",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_validations",
"as",
"$",
"validation",
")",
"{",
"if",
"(",
"$",
"validation",
"[",
"'rule'",
"]",
"===",
"$",
"name",
"&&",
"\\",
"in_array",
"(",
"$",
"field",
",",
"$",
"validation",
"[",
"'fields'",
"]",
",",
"true",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Determine whether a field is being validated by the given rule.
@param string $name The name of the rule
@param string $field The name of the field
@return bool | [
"Determine",
"whether",
"a",
"field",
"is",
"being",
"validated",
"by",
"the",
"given",
"rule",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L1224-L1233 |
35,527 | hail-framework/framework | src/Util/Validator.php | Validator.addInstanceRule | public function addInstanceRule(string $name, callable $callback, string $message = null): self
{
static::assertRuleCallback($callback);
$this->_instanceRules[$name] = $callback;
$this->_instanceRuleMessage[$name] = $message;
return $this;
} | php | public function addInstanceRule(string $name, callable $callback, string $message = null): self
{
static::assertRuleCallback($callback);
$this->_instanceRules[$name] = $callback;
$this->_instanceRuleMessage[$name] = $message;
return $this;
} | [
"public",
"function",
"addInstanceRule",
"(",
"string",
"$",
"name",
",",
"callable",
"$",
"callback",
",",
"string",
"$",
"message",
"=",
"null",
")",
":",
"self",
"{",
"static",
"::",
"assertRuleCallback",
"(",
"$",
"callback",
")",
";",
"$",
"this",
"->",
"_instanceRules",
"[",
"$",
"name",
"]",
"=",
"$",
"callback",
";",
"$",
"this",
"->",
"_instanceRuleMessage",
"[",
"$",
"name",
"]",
"=",
"$",
"message",
";",
"return",
"$",
"this",
";",
"}"
] | Adds a new validation rule callback that is tied to the current
instance only.
@param string $name
@param callable $callback
@param string $message
@return $this
@throws \InvalidArgumentException | [
"Adds",
"a",
"new",
"validation",
"rule",
"callback",
"that",
"is",
"tied",
"to",
"the",
"current",
"instance",
"only",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L1253-L1261 |
35,528 | hail-framework/framework | src/Util/Validator.php | Validator.addRule | public function addRule(string $name, callable $callback, string $message = null): self
{
if ($message === null) {
$message = static::ERROR_DEFAULT;
}
static::assertRuleCallback($callback);
static::$_rules[$name] = $callback;
static::$_ruleMessages[$name] = $message;
return $this;
} | php | public function addRule(string $name, callable $callback, string $message = null): self
{
if ($message === null) {
$message = static::ERROR_DEFAULT;
}
static::assertRuleCallback($callback);
static::$_rules[$name] = $callback;
static::$_ruleMessages[$name] = $message;
return $this;
} | [
"public",
"function",
"addRule",
"(",
"string",
"$",
"name",
",",
"callable",
"$",
"callback",
",",
"string",
"$",
"message",
"=",
"null",
")",
":",
"self",
"{",
"if",
"(",
"$",
"message",
"===",
"null",
")",
"{",
"$",
"message",
"=",
"static",
"::",
"ERROR_DEFAULT",
";",
"}",
"static",
"::",
"assertRuleCallback",
"(",
"$",
"callback",
")",
";",
"static",
"::",
"$",
"_rules",
"[",
"$",
"name",
"]",
"=",
"$",
"callback",
";",
"static",
"::",
"$",
"_ruleMessages",
"[",
"$",
"name",
"]",
"=",
"$",
"message",
";",
"return",
"$",
"this",
";",
"}"
] | Register new validation rule callback
@param string $name
@param callable $callback
@param string $message
@return $this
@throws \InvalidArgumentException | [
"Register",
"new",
"validation",
"rule",
"callback"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L1273-L1285 |
35,529 | hail-framework/framework | src/Util/Validator.php | Validator.hasValidator | public function hasValidator(string $name): bool
{
$rules = $this->getRules();
return \method_exists($this, 'validate' . \ucfirst($name)) || isset($rules[$name]);
} | php | public function hasValidator(string $name): bool
{
$rules = $this->getRules();
return \method_exists($this, 'validate' . \ucfirst($name)) || isset($rules[$name]);
} | [
"public",
"function",
"hasValidator",
"(",
"string",
"$",
"name",
")",
":",
"bool",
"{",
"$",
"rules",
"=",
"$",
"this",
"->",
"getRules",
"(",
")",
";",
"return",
"\\",
"method_exists",
"(",
"$",
"this",
",",
"'validate'",
".",
"\\",
"ucfirst",
"(",
"$",
"name",
")",
")",
"||",
"isset",
"(",
"$",
"rules",
"[",
"$",
"name",
"]",
")",
";",
"}"
] | Returns true if either a validator with the given name has been
registered or there is a default validator by that name.
@param string $name
@return bool | [
"Returns",
"true",
"if",
"either",
"a",
"validator",
"with",
"the",
"given",
"name",
"has",
"been",
"registered",
"or",
"there",
"is",
"a",
"default",
"validator",
"by",
"that",
"name",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L1316-L1321 |
35,530 | hail-framework/framework | src/Util/Validator.php | Validator.rule | public function rule($rule, $fields, ...$params)
{
if (\is_callable($rule)
&& !(\is_string($rule) && $this->hasValidator($rule))
) {
$name = $this->getUniqueRuleName($fields);
$message = $params[0] ?? null;
$this->addInstanceRule($name, $rule, $message);
$rule = $name;
}
$errors = $this->getRules();
if (!isset($errors[$rule])) {
$ruleMethod = 'validate' . \ucfirst($rule);
if (!\method_exists($this, $ruleMethod)) {
throw new \InvalidArgumentException("Rule '" . $rule . "' has not been registered with " . __CLASS__ . "::addRule().");
}
}
// Ensure rule has an accompanying message
$messages = $this->getRuleMessages();
$message = $messages[$rule] ?? self::ERROR_DEFAULT;
// Ensure message contains field label
if (\strpos($message, '{field}') === false) {
$message = '{field} ' . $message;
}
$this->_validations[] = [
'rule' => $rule,
'fields' => (array) $fields,
'params' => (array) $params,
'message' => '{field} ' . $message,
'skip' => self::SKIP_CONTINUE,
];
return $this;
} | php | public function rule($rule, $fields, ...$params)
{
if (\is_callable($rule)
&& !(\is_string($rule) && $this->hasValidator($rule))
) {
$name = $this->getUniqueRuleName($fields);
$message = $params[0] ?? null;
$this->addInstanceRule($name, $rule, $message);
$rule = $name;
}
$errors = $this->getRules();
if (!isset($errors[$rule])) {
$ruleMethod = 'validate' . \ucfirst($rule);
if (!\method_exists($this, $ruleMethod)) {
throw new \InvalidArgumentException("Rule '" . $rule . "' has not been registered with " . __CLASS__ . "::addRule().");
}
}
// Ensure rule has an accompanying message
$messages = $this->getRuleMessages();
$message = $messages[$rule] ?? self::ERROR_DEFAULT;
// Ensure message contains field label
if (\strpos($message, '{field}') === false) {
$message = '{field} ' . $message;
}
$this->_validations[] = [
'rule' => $rule,
'fields' => (array) $fields,
'params' => (array) $params,
'message' => '{field} ' . $message,
'skip' => self::SKIP_CONTINUE,
];
return $this;
} | [
"public",
"function",
"rule",
"(",
"$",
"rule",
",",
"$",
"fields",
",",
"...",
"$",
"params",
")",
"{",
"if",
"(",
"\\",
"is_callable",
"(",
"$",
"rule",
")",
"&&",
"!",
"(",
"\\",
"is_string",
"(",
"$",
"rule",
")",
"&&",
"$",
"this",
"->",
"hasValidator",
"(",
"$",
"rule",
")",
")",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"getUniqueRuleName",
"(",
"$",
"fields",
")",
";",
"$",
"message",
"=",
"$",
"params",
"[",
"0",
"]",
"??",
"null",
";",
"$",
"this",
"->",
"addInstanceRule",
"(",
"$",
"name",
",",
"$",
"rule",
",",
"$",
"message",
")",
";",
"$",
"rule",
"=",
"$",
"name",
";",
"}",
"$",
"errors",
"=",
"$",
"this",
"->",
"getRules",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"errors",
"[",
"$",
"rule",
"]",
")",
")",
"{",
"$",
"ruleMethod",
"=",
"'validate'",
".",
"\\",
"ucfirst",
"(",
"$",
"rule",
")",
";",
"if",
"(",
"!",
"\\",
"method_exists",
"(",
"$",
"this",
",",
"$",
"ruleMethod",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Rule '\"",
".",
"$",
"rule",
".",
"\"' has not been registered with \"",
".",
"__CLASS__",
".",
"\"::addRule().\"",
")",
";",
"}",
"}",
"// Ensure rule has an accompanying message",
"$",
"messages",
"=",
"$",
"this",
"->",
"getRuleMessages",
"(",
")",
";",
"$",
"message",
"=",
"$",
"messages",
"[",
"$",
"rule",
"]",
"??",
"self",
"::",
"ERROR_DEFAULT",
";",
"// Ensure message contains field label",
"if",
"(",
"\\",
"strpos",
"(",
"$",
"message",
",",
"'{field}'",
")",
"===",
"false",
")",
"{",
"$",
"message",
"=",
"'{field} '",
".",
"$",
"message",
";",
"}",
"$",
"this",
"->",
"_validations",
"[",
"]",
"=",
"[",
"'rule'",
"=>",
"$",
"rule",
",",
"'fields'",
"=>",
"(",
"array",
")",
"$",
"fields",
",",
"'params'",
"=>",
"(",
"array",
")",
"$",
"params",
",",
"'message'",
"=>",
"'{field} '",
".",
"$",
"message",
",",
"'skip'",
"=>",
"self",
"::",
"SKIP_CONTINUE",
",",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Convenience method to add a single validation rule
@param string|callable $rule
@param array|string $fields
@param mixed ...$params
@return $this
@throws \InvalidArgumentException | [
"Convenience",
"method",
"to",
"add",
"a",
"single",
"validation",
"rule"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L1333-L1370 |
35,531 | hail-framework/framework | src/Util/Validator.php | Validator.rules | public function rules(array $rules)
{
foreach ($rules as $ruleType => $params) {
if (\is_array($params)) {
foreach ($params as $innerParams) {
$innerParams = (array) $innerParams;
$this->rule($ruleType, ...$innerParams);
}
} else {
$this->rule($ruleType, $params);
}
}
return $this;
} | php | public function rules(array $rules)
{
foreach ($rules as $ruleType => $params) {
if (\is_array($params)) {
foreach ($params as $innerParams) {
$innerParams = (array) $innerParams;
$this->rule($ruleType, ...$innerParams);
}
} else {
$this->rule($ruleType, $params);
}
}
return $this;
} | [
"public",
"function",
"rules",
"(",
"array",
"$",
"rules",
")",
"{",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"ruleType",
"=>",
"$",
"params",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"params",
")",
")",
"{",
"foreach",
"(",
"$",
"params",
"as",
"$",
"innerParams",
")",
"{",
"$",
"innerParams",
"=",
"(",
"array",
")",
"$",
"innerParams",
";",
"$",
"this",
"->",
"rule",
"(",
"$",
"ruleType",
",",
"...",
"$",
"innerParams",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"rule",
"(",
"$",
"ruleType",
",",
"$",
"params",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Convenience method to add multiple validation rules with an array
@param array $rules
@return $this
@throws \InvalidArgumentException | [
"Convenience",
"method",
"to",
"add",
"multiple",
"validation",
"rules",
"with",
"an",
"array"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L1441-L1455 |
35,532 | hail-framework/framework | src/Util/Validator.php | Validator.withData | public function withData(array $data, array $fields = [])
{
$clone = clone $this;
$clone->_fields = !empty($fields) ? \array_intersect_key($data, \array_flip($fields)) : $data;
$clone->_errors = [];
return $clone;
} | php | public function withData(array $data, array $fields = [])
{
$clone = clone $this;
$clone->_fields = !empty($fields) ? \array_intersect_key($data, \array_flip($fields)) : $data;
$clone->_errors = [];
return $clone;
} | [
"public",
"function",
"withData",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"fields",
"=",
"[",
"]",
")",
"{",
"$",
"clone",
"=",
"clone",
"$",
"this",
";",
"$",
"clone",
"->",
"_fields",
"=",
"!",
"empty",
"(",
"$",
"fields",
")",
"?",
"\\",
"array_intersect_key",
"(",
"$",
"data",
",",
"\\",
"array_flip",
"(",
"$",
"fields",
")",
")",
":",
"$",
"data",
";",
"$",
"clone",
"->",
"_errors",
"=",
"[",
"]",
";",
"return",
"$",
"clone",
";",
"}"
] | Replace data on cloned instance
@param array $data
@param array $fields
@return \Hail\Util\Validator | [
"Replace",
"data",
"on",
"cloned",
"instance"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Validator.php#L1465-L1472 |
35,533 | hail-framework/framework | src/Console/Buffer.php | Buffer.appendLine | public function appendLine($line, $indent = 0)
{
$this->content .= ($indent ? $this->makeIndent($indent) : $this->indentCache) . $line . $this->newline;
} | php | public function appendLine($line, $indent = 0)
{
$this->content .= ($indent ? $this->makeIndent($indent) : $this->indentCache) . $line . $this->newline;
} | [
"public",
"function",
"appendLine",
"(",
"$",
"line",
",",
"$",
"indent",
"=",
"0",
")",
"{",
"$",
"this",
"->",
"content",
".=",
"(",
"$",
"indent",
"?",
"$",
"this",
"->",
"makeIndent",
"(",
"$",
"indent",
")",
":",
"$",
"this",
"->",
"indentCache",
")",
".",
"$",
"line",
".",
"$",
"this",
"->",
"newline",
";",
"}"
] | Append a line with indent to the buffer
@param string $line
@param int $indent | [
"Append",
"a",
"line",
"with",
"indent",
"to",
"the",
"buffer"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/Buffer.php#L99-L102 |
35,534 | hail-framework/framework | src/Console/Buffer.php | Buffer.appendLines | public function appendLines($lines, $indent = 0)
{
foreach ($lines as $line) {
$this->appendLine($line, $indent);
}
} | php | public function appendLines($lines, $indent = 0)
{
foreach ($lines as $line) {
$this->appendLine($line, $indent);
}
} | [
"public",
"function",
"appendLines",
"(",
"$",
"lines",
",",
"$",
"indent",
"=",
"0",
")",
"{",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"{",
"$",
"this",
"->",
"appendLine",
"(",
"$",
"line",
",",
"$",
"indent",
")",
";",
"}",
"}"
] | Append multiple lines with indent to the buffer
@param string[] $lines
@param int $indent | [
"Append",
"multiple",
"lines",
"with",
"indent",
"to",
"the",
"buffer"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/Buffer.php#L111-L116 |
35,535 | hail-framework/framework | src/Console/Buffer.php | Buffer.setFormat | public function setFormat($format)
{
$this->format = $format;
if ($this->format === self::FORMAT_UNIX) {
$this->newline = "\n";
} elseif ($this->format === self::FORMAT_DOS) {
$this->newline = "\r\n";
}
} | php | public function setFormat($format)
{
$this->format = $format;
if ($this->format === self::FORMAT_UNIX) {
$this->newline = "\n";
} elseif ($this->format === self::FORMAT_DOS) {
$this->newline = "\r\n";
}
} | [
"public",
"function",
"setFormat",
"(",
"$",
"format",
")",
"{",
"$",
"this",
"->",
"format",
"=",
"$",
"format",
";",
"if",
"(",
"$",
"this",
"->",
"format",
"===",
"self",
"::",
"FORMAT_UNIX",
")",
"{",
"$",
"this",
"->",
"newline",
"=",
"\"\\n\"",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"format",
"===",
"self",
"::",
"FORMAT_DOS",
")",
"{",
"$",
"this",
"->",
"newline",
"=",
"\"\\r\\n\"",
";",
"}",
"}"
] | Set line format
@param int $format Buffer::FORMAT_UNIX or Buffer::FORMAT_DOS | [
"Set",
"line",
"format"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/Buffer.php#L175-L183 |
35,536 | hail-framework/framework | src/Console/Buffer.php | Buffer.appendBuffer | public function appendBuffer(Buffer $buf, $indent = 0)
{
if ($indent) {
$this->setIndent($indent);
$lines = $buf->lines();
foreach ($lines as $line) {
$this->appendLine($line);
}
} else {
$this->content .= $buf->__toString();
}
} | php | public function appendBuffer(Buffer $buf, $indent = 0)
{
if ($indent) {
$this->setIndent($indent);
$lines = $buf->lines();
foreach ($lines as $line) {
$this->appendLine($line);
}
} else {
$this->content .= $buf->__toString();
}
} | [
"public",
"function",
"appendBuffer",
"(",
"Buffer",
"$",
"buf",
",",
"$",
"indent",
"=",
"0",
")",
"{",
"if",
"(",
"$",
"indent",
")",
"{",
"$",
"this",
"->",
"setIndent",
"(",
"$",
"indent",
")",
";",
"$",
"lines",
"=",
"$",
"buf",
"->",
"lines",
"(",
")",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"{",
"$",
"this",
"->",
"appendLine",
"(",
"$",
"line",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"content",
".=",
"$",
"buf",
"->",
"__toString",
"(",
")",
";",
"}",
"}"
] | Append a buffer object
@param Buffer $buf
@param int $indent = 0 | [
"Append",
"a",
"buffer",
"object"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/Buffer.php#L207-L218 |
35,537 | htmlburger/wpemerge-cli | src/App.php | App.install | public static function install( Event $event ) {
$binary_name = 'wpemerge';
$binary = dirname( __DIR__ ) . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . $binary_name;
$event->getIO()->write( '' );
$process = new Process( $binary . ' install' );
$process->setTimeout( null );
try {
$process->setTty( true );
$process->run( function ( $type, $line ) use ( $event ) {
$event->getIO()->write( $line );
});
} catch ( RuntimeException $e ) {
$event->getIO()->write( '<error>' . $e->getMessage() . '</error>' );
$event->getIO()->write( '' );
$event->getIO()->write( 'Use <comment>./vendor/bin/' . $binary_name . ' install</comment> instead.' );
}
} | php | public static function install( Event $event ) {
$binary_name = 'wpemerge';
$binary = dirname( __DIR__ ) . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . $binary_name;
$event->getIO()->write( '' );
$process = new Process( $binary . ' install' );
$process->setTimeout( null );
try {
$process->setTty( true );
$process->run( function ( $type, $line ) use ( $event ) {
$event->getIO()->write( $line );
});
} catch ( RuntimeException $e ) {
$event->getIO()->write( '<error>' . $e->getMessage() . '</error>' );
$event->getIO()->write( '' );
$event->getIO()->write( 'Use <comment>./vendor/bin/' . $binary_name . ' install</comment> instead.' );
}
} | [
"public",
"static",
"function",
"install",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"binary_name",
"=",
"'wpemerge'",
";",
"$",
"binary",
"=",
"dirname",
"(",
"__DIR__",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"'bin'",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"binary_name",
";",
"$",
"event",
"->",
"getIO",
"(",
")",
"->",
"write",
"(",
"''",
")",
";",
"$",
"process",
"=",
"new",
"Process",
"(",
"$",
"binary",
".",
"' install'",
")",
";",
"$",
"process",
"->",
"setTimeout",
"(",
"null",
")",
";",
"try",
"{",
"$",
"process",
"->",
"setTty",
"(",
"true",
")",
";",
"$",
"process",
"->",
"run",
"(",
"function",
"(",
"$",
"type",
",",
"$",
"line",
")",
"use",
"(",
"$",
"event",
")",
"{",
"$",
"event",
"->",
"getIO",
"(",
")",
"->",
"write",
"(",
"$",
"line",
")",
";",
"}",
")",
";",
"}",
"catch",
"(",
"RuntimeException",
"$",
"e",
")",
"{",
"$",
"event",
"->",
"getIO",
"(",
")",
"->",
"write",
"(",
"'<error>'",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
".",
"'</error>'",
")",
";",
"$",
"event",
"->",
"getIO",
"(",
")",
"->",
"write",
"(",
"''",
")",
";",
"$",
"event",
"->",
"getIO",
"(",
")",
"->",
"write",
"(",
"'Use <comment>./vendor/bin/'",
".",
"$",
"binary_name",
".",
"' install</comment> instead.'",
")",
";",
"}",
"}"
] | Run with the install command.
@param Event $event
@return void | [
"Run",
"with",
"the",
"install",
"command",
"."
] | 075f1982b7dd87039a4e7bbc05caf676a10fe862 | https://github.com/htmlburger/wpemerge-cli/blob/075f1982b7dd87039a4e7bbc05caf676a10fe862/src/App.php#L71-L91 |
35,538 | htmlburger/wpemerge-cli | src/App.php | App.createConfigJson | public static function createConfigJson( Event $event ) {
if ( ! defined( 'WPEMERGE_CLI_DIR' ) ) {
define( 'WPEMERGE_CLI_DIR', dirname( __DIR__ ) );
}
$input = new ArrayInput( [ 'config:create' ] );
$output = new BufferedOutput();
try {
$application = static::create();
$command = $application->find('config:create');
$command->run( $input, $output );
$event->getIO()->write( $output->fetch() );
} catch ( RuntimeException $e ) {
$event->getIO()->write( '<error>' . $e->getMessage() . '</error>' );
}
} | php | public static function createConfigJson( Event $event ) {
if ( ! defined( 'WPEMERGE_CLI_DIR' ) ) {
define( 'WPEMERGE_CLI_DIR', dirname( __DIR__ ) );
}
$input = new ArrayInput( [ 'config:create' ] );
$output = new BufferedOutput();
try {
$application = static::create();
$command = $application->find('config:create');
$command->run( $input, $output );
$event->getIO()->write( $output->fetch() );
} catch ( RuntimeException $e ) {
$event->getIO()->write( '<error>' . $e->getMessage() . '</error>' );
}
} | [
"public",
"static",
"function",
"createConfigJson",
"(",
"Event",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"defined",
"(",
"'WPEMERGE_CLI_DIR'",
")",
")",
"{",
"define",
"(",
"'WPEMERGE_CLI_DIR'",
",",
"dirname",
"(",
"__DIR__",
")",
")",
";",
"}",
"$",
"input",
"=",
"new",
"ArrayInput",
"(",
"[",
"'config:create'",
"]",
")",
";",
"$",
"output",
"=",
"new",
"BufferedOutput",
"(",
")",
";",
"try",
"{",
"$",
"application",
"=",
"static",
"::",
"create",
"(",
")",
";",
"$",
"command",
"=",
"$",
"application",
"->",
"find",
"(",
"'config:create'",
")",
";",
"$",
"command",
"->",
"run",
"(",
"$",
"input",
",",
"$",
"output",
")",
";",
"$",
"event",
"->",
"getIO",
"(",
")",
"->",
"write",
"(",
"$",
"output",
"->",
"fetch",
"(",
")",
")",
";",
"}",
"catch",
"(",
"RuntimeException",
"$",
"e",
")",
"{",
"$",
"event",
"->",
"getIO",
"(",
")",
"->",
"write",
"(",
"'<error>'",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
".",
"'</error>'",
")",
";",
"}",
"}"
] | Create a config.json in the theme root directory.
@param Event $event
@return void | [
"Create",
"a",
"config",
".",
"json",
"in",
"the",
"theme",
"root",
"directory",
"."
] | 075f1982b7dd87039a4e7bbc05caf676a10fe862 | https://github.com/htmlburger/wpemerge-cli/blob/075f1982b7dd87039a4e7bbc05caf676a10fe862/src/App.php#L99-L115 |
35,539 | htmlburger/wpemerge-cli | src/App.php | App.installDependencies | public static function installDependencies( Event $event ) {
if ( ! defined( 'WPEMERGE_CLI_DIR' ) ) {
define( 'WPEMERGE_CLI_DIR', dirname( __DIR__ ) );
}
$input = new ArrayInput( [ 'install:dependencies' ] );
$output = new ConsoleOutput();
try {
$application = static::create();
$command = $application->find('install:dependencies');
$command->run( $input, $output );
} catch ( RuntimeException $e ) {
$event->getIO()->write( '<error>' . $e->getMessage() . '</error>' );
}
} | php | public static function installDependencies( Event $event ) {
if ( ! defined( 'WPEMERGE_CLI_DIR' ) ) {
define( 'WPEMERGE_CLI_DIR', dirname( __DIR__ ) );
}
$input = new ArrayInput( [ 'install:dependencies' ] );
$output = new ConsoleOutput();
try {
$application = static::create();
$command = $application->find('install:dependencies');
$command->run( $input, $output );
} catch ( RuntimeException $e ) {
$event->getIO()->write( '<error>' . $e->getMessage() . '</error>' );
}
} | [
"public",
"static",
"function",
"installDependencies",
"(",
"Event",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"defined",
"(",
"'WPEMERGE_CLI_DIR'",
")",
")",
"{",
"define",
"(",
"'WPEMERGE_CLI_DIR'",
",",
"dirname",
"(",
"__DIR__",
")",
")",
";",
"}",
"$",
"input",
"=",
"new",
"ArrayInput",
"(",
"[",
"'install:dependencies'",
"]",
")",
";",
"$",
"output",
"=",
"new",
"ConsoleOutput",
"(",
")",
";",
"try",
"{",
"$",
"application",
"=",
"static",
"::",
"create",
"(",
")",
";",
"$",
"command",
"=",
"$",
"application",
"->",
"find",
"(",
"'install:dependencies'",
")",
";",
"$",
"command",
"->",
"run",
"(",
"$",
"input",
",",
"$",
"output",
")",
";",
"}",
"catch",
"(",
"RuntimeException",
"$",
"e",
")",
"{",
"$",
"event",
"->",
"getIO",
"(",
")",
"->",
"write",
"(",
"'<error>'",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
".",
"'</error>'",
")",
";",
"}",
"}"
] | Install dependencies in the theme root directory.
@param Event $event
@return void | [
"Install",
"dependencies",
"in",
"the",
"theme",
"root",
"directory",
"."
] | 075f1982b7dd87039a4e7bbc05caf676a10fe862 | https://github.com/htmlburger/wpemerge-cli/blob/075f1982b7dd87039a4e7bbc05caf676a10fe862/src/App.php#L123-L138 |
35,540 | htmlburger/wpemerge-cli | src/App.php | App.isWordPressThemeDirectory | protected static function isWordPressThemeDirectory( $directory ) {
$composer = Composer::getComposerJson( $directory );
if ( ! $composer ) {
return false;
}
if ( $composer['type'] !== 'wordpress-theme' ) {
return false;
}
return true;
} | php | protected static function isWordPressThemeDirectory( $directory ) {
$composer = Composer::getComposerJson( $directory );
if ( ! $composer ) {
return false;
}
if ( $composer['type'] !== 'wordpress-theme' ) {
return false;
}
return true;
} | [
"protected",
"static",
"function",
"isWordPressThemeDirectory",
"(",
"$",
"directory",
")",
"{",
"$",
"composer",
"=",
"Composer",
"::",
"getComposerJson",
"(",
"$",
"directory",
")",
";",
"if",
"(",
"!",
"$",
"composer",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"composer",
"[",
"'type'",
"]",
"!==",
"'wordpress-theme'",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Check if a directory is a WordPress theme root.
@param string $directory
@return boolean | [
"Check",
"if",
"a",
"directory",
"is",
"a",
"WordPress",
"theme",
"root",
"."
] | 075f1982b7dd87039a4e7bbc05caf676a10fe862 | https://github.com/htmlburger/wpemerge-cli/blob/075f1982b7dd87039a4e7bbc05caf676a10fe862/src/App.php#L207-L219 |
35,541 | htmlburger/wpemerge-cli | src/App.php | App.execute | public static function execute( $command, $directory = null, $timeout = 120 ) {
$directory = $directory !== null ? $directory : getcwd();
$process = new Process( $command, null, null, null, $timeout );
$process->setWorkingDirectory( $directory );
$process->mustRun();
return $process->getOutput();
} | php | public static function execute( $command, $directory = null, $timeout = 120 ) {
$directory = $directory !== null ? $directory : getcwd();
$process = new Process( $command, null, null, null, $timeout );
$process->setWorkingDirectory( $directory );
$process->mustRun();
return $process->getOutput();
} | [
"public",
"static",
"function",
"execute",
"(",
"$",
"command",
",",
"$",
"directory",
"=",
"null",
",",
"$",
"timeout",
"=",
"120",
")",
"{",
"$",
"directory",
"=",
"$",
"directory",
"!==",
"null",
"?",
"$",
"directory",
":",
"getcwd",
"(",
")",
";",
"$",
"process",
"=",
"new",
"Process",
"(",
"$",
"command",
",",
"null",
",",
"null",
",",
"null",
",",
"$",
"timeout",
")",
";",
"$",
"process",
"->",
"setWorkingDirectory",
"(",
"$",
"directory",
")",
";",
"$",
"process",
"->",
"mustRun",
"(",
")",
";",
"return",
"$",
"process",
"->",
"getOutput",
"(",
")",
";",
"}"
] | Run a shell command.
@param string $command
@param string|null $directory
@param integer $timeout
@return string | [
"Run",
"a",
"shell",
"command",
"."
] | 075f1982b7dd87039a4e7bbc05caf676a10fe862 | https://github.com/htmlburger/wpemerge-cli/blob/075f1982b7dd87039a4e7bbc05caf676a10fe862/src/App.php#L229-L237 |
35,542 | htmlburger/wpemerge-cli | src/App.php | App.liveExecute | public static function liveExecute( $command, OutputInterface $output, $directory = null, $timeout = 120 ) {
$directory = $directory !== null ? $directory : getcwd();
$process = new Process( $command, null, null, null, $timeout );
$process->setWorkingDirectory( $directory );
$process->start();
$process->wait( function( $type, $buffer ) use ( $output ) {
$output->writeln( $buffer );
} );
if ( ! $process->isSuccessful() ) {
throw new ProcessFailedException( $process );
}
return $process;
} | php | public static function liveExecute( $command, OutputInterface $output, $directory = null, $timeout = 120 ) {
$directory = $directory !== null ? $directory : getcwd();
$process = new Process( $command, null, null, null, $timeout );
$process->setWorkingDirectory( $directory );
$process->start();
$process->wait( function( $type, $buffer ) use ( $output ) {
$output->writeln( $buffer );
} );
if ( ! $process->isSuccessful() ) {
throw new ProcessFailedException( $process );
}
return $process;
} | [
"public",
"static",
"function",
"liveExecute",
"(",
"$",
"command",
",",
"OutputInterface",
"$",
"output",
",",
"$",
"directory",
"=",
"null",
",",
"$",
"timeout",
"=",
"120",
")",
"{",
"$",
"directory",
"=",
"$",
"directory",
"!==",
"null",
"?",
"$",
"directory",
":",
"getcwd",
"(",
")",
";",
"$",
"process",
"=",
"new",
"Process",
"(",
"$",
"command",
",",
"null",
",",
"null",
",",
"null",
",",
"$",
"timeout",
")",
";",
"$",
"process",
"->",
"setWorkingDirectory",
"(",
"$",
"directory",
")",
";",
"$",
"process",
"->",
"start",
"(",
")",
";",
"$",
"process",
"->",
"wait",
"(",
"function",
"(",
"$",
"type",
",",
"$",
"buffer",
")",
"use",
"(",
"$",
"output",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"$",
"buffer",
")",
";",
"}",
")",
";",
"if",
"(",
"!",
"$",
"process",
"->",
"isSuccessful",
"(",
")",
")",
"{",
"throw",
"new",
"ProcessFailedException",
"(",
"$",
"process",
")",
";",
"}",
"return",
"$",
"process",
";",
"}"
] | Run a shell command and return the output as it comes in.
@param string $command
@param OutputInterface $output
@param string|null $directory
@param integer $timeout
@return Process | [
"Run",
"a",
"shell",
"command",
"and",
"return",
"the",
"output",
"as",
"it",
"comes",
"in",
"."
] | 075f1982b7dd87039a4e7bbc05caf676a10fe862 | https://github.com/htmlburger/wpemerge-cli/blob/075f1982b7dd87039a4e7bbc05caf676a10fe862/src/App.php#L248-L264 |
35,543 | wikimedia/ObjectFactory | src/ObjectFactory.php | ObjectFactory.getObjectFromSpec | public static function getObjectFromSpec( $spec ) {
$args = isset( $spec['args'] ) ? $spec['args'] : [];
$expandArgs = !isset( $spec['closure_expansion'] ) ||
$spec['closure_expansion'] === true;
if ( $expandArgs ) {
$args = static::expandClosures( $args );
}
if ( isset( $spec['class'] ) ) {
$clazz = $spec['class'];
if ( !$args ) {
$obj = new $clazz();
} else {
$obj = static::constructClassInstance( $clazz, $args );
}
} elseif ( isset( $spec['factory'] ) ) {
$obj = call_user_func_array( $spec['factory'], $args );
} else {
throw new InvalidArgumentException(
'Provided specification lacks both factory and class parameters.'
);
}
if ( isset( $spec['calls'] ) && is_array( $spec['calls'] ) ) {
// Call additional methods on the newly created object
foreach ( $spec['calls'] as $method => $margs ) {
if ( $expandArgs ) {
$margs = static::expandClosures( $margs );
}
call_user_func_array( [ $obj, $method ], $margs );
}
}
return $obj;
} | php | public static function getObjectFromSpec( $spec ) {
$args = isset( $spec['args'] ) ? $spec['args'] : [];
$expandArgs = !isset( $spec['closure_expansion'] ) ||
$spec['closure_expansion'] === true;
if ( $expandArgs ) {
$args = static::expandClosures( $args );
}
if ( isset( $spec['class'] ) ) {
$clazz = $spec['class'];
if ( !$args ) {
$obj = new $clazz();
} else {
$obj = static::constructClassInstance( $clazz, $args );
}
} elseif ( isset( $spec['factory'] ) ) {
$obj = call_user_func_array( $spec['factory'], $args );
} else {
throw new InvalidArgumentException(
'Provided specification lacks both factory and class parameters.'
);
}
if ( isset( $spec['calls'] ) && is_array( $spec['calls'] ) ) {
// Call additional methods on the newly created object
foreach ( $spec['calls'] as $method => $margs ) {
if ( $expandArgs ) {
$margs = static::expandClosures( $margs );
}
call_user_func_array( [ $obj, $method ], $margs );
}
}
return $obj;
} | [
"public",
"static",
"function",
"getObjectFromSpec",
"(",
"$",
"spec",
")",
"{",
"$",
"args",
"=",
"isset",
"(",
"$",
"spec",
"[",
"'args'",
"]",
")",
"?",
"$",
"spec",
"[",
"'args'",
"]",
":",
"[",
"]",
";",
"$",
"expandArgs",
"=",
"!",
"isset",
"(",
"$",
"spec",
"[",
"'closure_expansion'",
"]",
")",
"||",
"$",
"spec",
"[",
"'closure_expansion'",
"]",
"===",
"true",
";",
"if",
"(",
"$",
"expandArgs",
")",
"{",
"$",
"args",
"=",
"static",
"::",
"expandClosures",
"(",
"$",
"args",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"spec",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"clazz",
"=",
"$",
"spec",
"[",
"'class'",
"]",
";",
"if",
"(",
"!",
"$",
"args",
")",
"{",
"$",
"obj",
"=",
"new",
"$",
"clazz",
"(",
")",
";",
"}",
"else",
"{",
"$",
"obj",
"=",
"static",
"::",
"constructClassInstance",
"(",
"$",
"clazz",
",",
"$",
"args",
")",
";",
"}",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"spec",
"[",
"'factory'",
"]",
")",
")",
"{",
"$",
"obj",
"=",
"call_user_func_array",
"(",
"$",
"spec",
"[",
"'factory'",
"]",
",",
"$",
"args",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Provided specification lacks both factory and class parameters.'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"spec",
"[",
"'calls'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"spec",
"[",
"'calls'",
"]",
")",
")",
"{",
"// Call additional methods on the newly created object",
"foreach",
"(",
"$",
"spec",
"[",
"'calls'",
"]",
"as",
"$",
"method",
"=>",
"$",
"margs",
")",
"{",
"if",
"(",
"$",
"expandArgs",
")",
"{",
"$",
"margs",
"=",
"static",
"::",
"expandClosures",
"(",
"$",
"margs",
")",
";",
"}",
"call_user_func_array",
"(",
"[",
"$",
"obj",
",",
"$",
"method",
"]",
",",
"$",
"margs",
")",
";",
"}",
"}",
"return",
"$",
"obj",
";",
"}"
] | Instantiate an object based on a specification array.
The specification array must contain a 'class' key with string value
that specifies the class name to instantiate or a 'factory' key with
a callable (is_callable() === true). It can optionally contain
an 'args' key that provides arguments to pass to the
constructor/callable.
Values in the arguments collection which are Closure instances will be
expanded by invoking them with no arguments before passing the
resulting value on to the constructor/callable. This can be used to
pass IDatabase instances or other live objects to the
constructor/callable. This behavior can be suppressed by adding
closure_expansion => false to the specification.
The specification may also contain a 'calls' key that describes method
calls to make on the newly created object before returning it. This
pattern is often known as "setter injection". The value of this key is
expected to be an associative array with method names as keys and
argument lists as values. The argument list will be expanded (or not)
in the same way as the 'args' key for the main object.
@param array $spec Object specification
@return object
@throws InvalidArgumentException when object specification does not
contain 'class' or 'factory' keys
@throws ReflectionException when 'args' are supplied and 'class'
constructor is non-public or non-existent | [
"Instantiate",
"an",
"object",
"based",
"on",
"a",
"specification",
"array",
"."
] | 7e7ed475dfa09516f2d06a5cf0b61b8e3afba170 | https://github.com/wikimedia/ObjectFactory/blob/7e7ed475dfa09516f2d06a5cf0b61b8e3afba170/src/ObjectFactory.php#L64-L99 |
35,544 | wikimedia/ObjectFactory | src/ObjectFactory.php | ObjectFactory.expandClosures | protected static function expandClosures( $list ) {
return array_map( function ( $value ) {
if ( is_object( $value ) && $value instanceof Closure ) {
// If $value is a Closure, call it.
return $value();
} else {
return $value;
}
}, $list );
} | php | protected static function expandClosures( $list ) {
return array_map( function ( $value ) {
if ( is_object( $value ) && $value instanceof Closure ) {
// If $value is a Closure, call it.
return $value();
} else {
return $value;
}
}, $list );
} | [
"protected",
"static",
"function",
"expandClosures",
"(",
"$",
"list",
")",
"{",
"return",
"array_map",
"(",
"function",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
"&&",
"$",
"value",
"instanceof",
"Closure",
")",
"{",
"// If $value is a Closure, call it.",
"return",
"$",
"value",
"(",
")",
";",
"}",
"else",
"{",
"return",
"$",
"value",
";",
"}",
"}",
",",
"$",
"list",
")",
";",
"}"
] | Iterate a list and call any closures it contains.
@param array $list List of things
@return array List with any Closures replaced with their output | [
"Iterate",
"a",
"list",
"and",
"call",
"any",
"closures",
"it",
"contains",
"."
] | 7e7ed475dfa09516f2d06a5cf0b61b8e3afba170 | https://github.com/wikimedia/ObjectFactory/blob/7e7ed475dfa09516f2d06a5cf0b61b8e3afba170/src/ObjectFactory.php#L107-L116 |
35,545 | wikimedia/ObjectFactory | src/ObjectFactory.php | ObjectFactory.constructClassInstance | public static function constructClassInstance( $clazz, $args ) {
// $args should be a non-associative array; show nice error if that's not the case
if ( $args && array_keys( $args ) !== range( 0, count( $args ) - 1 ) ) {
throw new InvalidArgumentException( __METHOD__ . ': $args cannot be an associative array' );
}
return new $clazz( ...$args );
} | php | public static function constructClassInstance( $clazz, $args ) {
// $args should be a non-associative array; show nice error if that's not the case
if ( $args && array_keys( $args ) !== range( 0, count( $args ) - 1 ) ) {
throw new InvalidArgumentException( __METHOD__ . ': $args cannot be an associative array' );
}
return new $clazz( ...$args );
} | [
"public",
"static",
"function",
"constructClassInstance",
"(",
"$",
"clazz",
",",
"$",
"args",
")",
"{",
"// $args should be a non-associative array; show nice error if that's not the case",
"if",
"(",
"$",
"args",
"&&",
"array_keys",
"(",
"$",
"args",
")",
"!==",
"range",
"(",
"0",
",",
"count",
"(",
"$",
"args",
")",
"-",
"1",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"': $args cannot be an associative array'",
")",
";",
"}",
"return",
"new",
"$",
"clazz",
"(",
"...",
"$",
"args",
")",
";",
"}"
] | Construct an instance of the given class using the given arguments.
@param string $clazz Class name
@param array $args Constructor arguments
@return mixed Constructed instance | [
"Construct",
"an",
"instance",
"of",
"the",
"given",
"class",
"using",
"the",
"given",
"arguments",
"."
] | 7e7ed475dfa09516f2d06a5cf0b61b8e3afba170 | https://github.com/wikimedia/ObjectFactory/blob/7e7ed475dfa09516f2d06a5cf0b61b8e3afba170/src/ObjectFactory.php#L125-L132 |
35,546 | cedx/enum.php | lib/EnumTrait.php | EnumTrait.getEntries | final static function getEntries(): array {
static $entries;
if (!isset($entries)) {
$entries = [];
foreach ((new \ReflectionClass(static::class))->getConstants() as $name => $value) {
$reflection = new \ReflectionClassConstant(static::class, $name);
if ($reflection->isPublic()) $entries[$name] = $reflection->getValue();
}
}
return $entries;
} | php | final static function getEntries(): array {
static $entries;
if (!isset($entries)) {
$entries = [];
foreach ((new \ReflectionClass(static::class))->getConstants() as $name => $value) {
$reflection = new \ReflectionClassConstant(static::class, $name);
if ($reflection->isPublic()) $entries[$name] = $reflection->getValue();
}
}
return $entries;
} | [
"final",
"static",
"function",
"getEntries",
"(",
")",
":",
"array",
"{",
"static",
"$",
"entries",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"entries",
")",
")",
"{",
"$",
"entries",
"=",
"[",
"]",
";",
"foreach",
"(",
"(",
"new",
"\\",
"ReflectionClass",
"(",
"static",
"::",
"class",
")",
")",
"->",
"getConstants",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClassConstant",
"(",
"static",
"::",
"class",
",",
"$",
"name",
")",
";",
"if",
"(",
"$",
"reflection",
"->",
"isPublic",
"(",
")",
")",
"$",
"entries",
"[",
"$",
"name",
"]",
"=",
"$",
"reflection",
"->",
"getValue",
"(",
")",
";",
"}",
"}",
"return",
"$",
"entries",
";",
"}"
] | Gets an associative array of the pairs of names and values of the constants in this enumeration.
@return array An associative array that contains the pairs of names and values of the constants in this enumeration. | [
"Gets",
"an",
"associative",
"array",
"of",
"the",
"pairs",
"of",
"names",
"and",
"values",
"of",
"the",
"constants",
"in",
"this",
"enumeration",
"."
] | 96ad9b95bb140ef009148aaa66598c7bbbd21c5a | https://github.com/cedx/enum.php/blob/96ad9b95bb140ef009148aaa66598c7bbbd21c5a/lib/EnumTrait.php#L44-L55 |
35,547 | cedx/enum.php | lib/EnumTrait.php | EnumTrait.getIndex | final static function getIndex($value): int {
$index = array_search($value, static::getValues(), true);
return $index !== false ? $index : -1;
} | php | final static function getIndex($value): int {
$index = array_search($value, static::getValues(), true);
return $index !== false ? $index : -1;
} | [
"final",
"static",
"function",
"getIndex",
"(",
"$",
"value",
")",
":",
"int",
"{",
"$",
"index",
"=",
"array_search",
"(",
"$",
"value",
",",
"static",
"::",
"getValues",
"(",
")",
",",
"true",
")",
";",
"return",
"$",
"index",
"!==",
"false",
"?",
"$",
"index",
":",
"-",
"1",
";",
"}"
] | Gets the zero-based position of the constant in this enumeration that has the specified value.
@param mixed $value The value of a constant in this enumeration.
@return int The zero-based position of the constant that has the specified value, or `-1` if no such constant is found. | [
"Gets",
"the",
"zero",
"-",
"based",
"position",
"of",
"the",
"constant",
"in",
"this",
"enumeration",
"that",
"has",
"the",
"specified",
"value",
"."
] | 96ad9b95bb140ef009148aaa66598c7bbbd21c5a | https://github.com/cedx/enum.php/blob/96ad9b95bb140ef009148aaa66598c7bbbd21c5a/lib/EnumTrait.php#L62-L65 |
35,548 | hail-framework/framework | src/Image/Commands/EllipseCommand.php | EllipseCommand.execute | public function execute($image)
{
$width = $this->argument(0)->type('numeric')->required()->value();
$height = $this->argument(1)->type('numeric')->required()->value();
$x = $this->argument(2)->type('numeric')->required()->value();
$y = $this->argument(3)->type('numeric')->required()->value();
$callback = $this->argument(4)->type('closure')->value();
$namespace = $image->getDriver()->getNamespace();
$ellipse_classname = "\{$namespace}\Shapes\EllipseShape";
$ellipse = new $ellipse_classname($width, $height);
if ($callback instanceof Closure) {
$callback($ellipse);
}
$ellipse->applyToImage($image, $x, $y);
return true;
} | php | public function execute($image)
{
$width = $this->argument(0)->type('numeric')->required()->value();
$height = $this->argument(1)->type('numeric')->required()->value();
$x = $this->argument(2)->type('numeric')->required()->value();
$y = $this->argument(3)->type('numeric')->required()->value();
$callback = $this->argument(4)->type('closure')->value();
$namespace = $image->getDriver()->getNamespace();
$ellipse_classname = "\{$namespace}\Shapes\EllipseShape";
$ellipse = new $ellipse_classname($width, $height);
if ($callback instanceof Closure) {
$callback($ellipse);
}
$ellipse->applyToImage($image, $x, $y);
return true;
} | [
"public",
"function",
"execute",
"(",
"$",
"image",
")",
"{",
"$",
"width",
"=",
"$",
"this",
"->",
"argument",
"(",
"0",
")",
"->",
"type",
"(",
"'numeric'",
")",
"->",
"required",
"(",
")",
"->",
"value",
"(",
")",
";",
"$",
"height",
"=",
"$",
"this",
"->",
"argument",
"(",
"1",
")",
"->",
"type",
"(",
"'numeric'",
")",
"->",
"required",
"(",
")",
"->",
"value",
"(",
")",
";",
"$",
"x",
"=",
"$",
"this",
"->",
"argument",
"(",
"2",
")",
"->",
"type",
"(",
"'numeric'",
")",
"->",
"required",
"(",
")",
"->",
"value",
"(",
")",
";",
"$",
"y",
"=",
"$",
"this",
"->",
"argument",
"(",
"3",
")",
"->",
"type",
"(",
"'numeric'",
")",
"->",
"required",
"(",
")",
"->",
"value",
"(",
")",
";",
"$",
"callback",
"=",
"$",
"this",
"->",
"argument",
"(",
"4",
")",
"->",
"type",
"(",
"'closure'",
")",
"->",
"value",
"(",
")",
";",
"$",
"namespace",
"=",
"$",
"image",
"->",
"getDriver",
"(",
")",
"->",
"getNamespace",
"(",
")",
";",
"$",
"ellipse_classname",
"=",
"\"\\{$namespace}\\Shapes\\EllipseShape\"",
";",
"$",
"ellipse",
"=",
"new",
"$",
"ellipse_classname",
"(",
"$",
"width",
",",
"$",
"height",
")",
";",
"if",
"(",
"$",
"callback",
"instanceof",
"Closure",
")",
"{",
"$",
"callback",
"(",
"$",
"ellipse",
")",
";",
"}",
"$",
"ellipse",
"->",
"applyToImage",
"(",
"$",
"image",
",",
"$",
"x",
",",
"$",
"y",
")",
";",
"return",
"true",
";",
"}"
] | Draws ellipse on given image
@param \Hail\Image\Image $image
@return bool | [
"Draws",
"ellipse",
"on",
"given",
"image"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Image/Commands/EllipseCommand.php#L16-L36 |
35,549 | Kajna/K-Core | Core/Core/Core.php | Core.getInstance | public static function getInstance(Container $container = null)
{
if (null === self::$instance) {
self::$instance = new Core($container);
}
return self::$instance;
} | php | public static function getInstance(Container $container = null)
{
if (null === self::$instance) {
self::$instance = new Core($container);
}
return self::$instance;
} | [
"public",
"static",
"function",
"getInstance",
"(",
"Container",
"$",
"container",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"self",
"::",
"$",
"instance",
")",
"{",
"self",
"::",
"$",
"instance",
"=",
"new",
"Core",
"(",
"$",
"container",
")",
";",
"}",
"return",
"self",
"::",
"$",
"instance",
";",
"}"
] | Get singleton instance of Core class.
@param Container|null $container
@return Core | [
"Get",
"singleton",
"instance",
"of",
"Core",
"class",
"."
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Core/Core.php#L81-L87 |
35,550 | Kajna/K-Core | Core/Core/Core.php | Core.execute | public function execute($silent = false)
{
try {
// Execute middleware stack
/** @var callable $start */
$start = $this->middleware->top();
$response = $start();
} catch (NotFoundException $e) {
$response = $this->notFound($e);
} catch (Exception $e) {
$response = $this->internalError($e);
}
// Send response
if (isset($response) && !$silent) {
if (!$response instanceof ResponseInterface) {
throw new Exception("Controllers, hooks and middleware must return instance of ResponseInterface");
}
$response->send();
}
// Post response hook.
if (isset($this->hooks['after.execute'])) {
$this->hooks['after.execute']();
}
return $response;
} | php | public function execute($silent = false)
{
try {
// Execute middleware stack
/** @var callable $start */
$start = $this->middleware->top();
$response = $start();
} catch (NotFoundException $e) {
$response = $this->notFound($e);
} catch (Exception $e) {
$response = $this->internalError($e);
}
// Send response
if (isset($response) && !$silent) {
if (!$response instanceof ResponseInterface) {
throw new Exception("Controllers, hooks and middleware must return instance of ResponseInterface");
}
$response->send();
}
// Post response hook.
if (isset($this->hooks['after.execute'])) {
$this->hooks['after.execute']();
}
return $response;
} | [
"public",
"function",
"execute",
"(",
"$",
"silent",
"=",
"false",
")",
"{",
"try",
"{",
"// Execute middleware stack",
"/** @var callable $start */",
"$",
"start",
"=",
"$",
"this",
"->",
"middleware",
"->",
"top",
"(",
")",
";",
"$",
"response",
"=",
"$",
"start",
"(",
")",
";",
"}",
"catch",
"(",
"NotFoundException",
"$",
"e",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"notFound",
"(",
"$",
"e",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"internalError",
"(",
"$",
"e",
")",
";",
"}",
"// Send response",
"if",
"(",
"isset",
"(",
"$",
"response",
")",
"&&",
"!",
"$",
"silent",
")",
"{",
"if",
"(",
"!",
"$",
"response",
"instanceof",
"ResponseInterface",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Controllers, hooks and middleware must return instance of ResponseInterface\"",
")",
";",
"}",
"$",
"response",
"->",
"send",
"(",
")",
";",
"}",
"// Post response hook.",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"hooks",
"[",
"'after.execute'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"hooks",
"[",
"'after.execute'",
"]",
"(",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Route request and execute associated action.
@param bool $silent
@return ResponseInterface
@throws Exception | [
"Route",
"request",
"and",
"execute",
"associated",
"action",
"."
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Core/Core.php#L96-L123 |
35,551 | Kajna/K-Core | Core/Core/Core.php | Core.notFound | protected function notFound(NotFoundException $e)
{
if (isset($this->hooks['not.found'])) {
return $this->hooks['not.found']($e);
} else {
return (new Response())
->setStatusCode(404)
->setBody($e->getMessage());
}
} | php | protected function notFound(NotFoundException $e)
{
if (isset($this->hooks['not.found'])) {
return $this->hooks['not.found']($e);
} else {
return (new Response())
->setStatusCode(404)
->setBody($e->getMessage());
}
} | [
"protected",
"function",
"notFound",
"(",
"NotFoundException",
"$",
"e",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"hooks",
"[",
"'not.found'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"hooks",
"[",
"'not.found'",
"]",
"(",
"$",
"e",
")",
";",
"}",
"else",
"{",
"return",
"(",
"new",
"Response",
"(",
")",
")",
"->",
"setStatusCode",
"(",
"404",
")",
"->",
"setBody",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | Handle 404.
@param NotFoundException $e
@return ResponseInterface | [
"Handle",
"404",
"."
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Core/Core.php#L170-L179 |
35,552 | hail-framework/framework | src/Image/Commands/RectangleCommand.php | RectangleCommand.execute | public function execute($image)
{
$x1 = $this->argument(0)->type('numeric')->required()->value();
$y1 = $this->argument(1)->type('numeric')->required()->value();
$x2 = $this->argument(2)->type('numeric')->required()->value();
$y2 = $this->argument(3)->type('numeric')->required()->value();
$callback = $this->argument(4)->type('closure')->value();
$namespace = $image->getDriver()->getNamespace();
$rectangle_classname = "\{$namespace}\Shapes\RectangleShape";
$rectangle = new $rectangle_classname($x1, $y1, $x2, $y2);
if ($callback instanceof Closure) {
$callback($rectangle);
}
$rectangle->applyToImage($image, $x1, $y1);
return true;
} | php | public function execute($image)
{
$x1 = $this->argument(0)->type('numeric')->required()->value();
$y1 = $this->argument(1)->type('numeric')->required()->value();
$x2 = $this->argument(2)->type('numeric')->required()->value();
$y2 = $this->argument(3)->type('numeric')->required()->value();
$callback = $this->argument(4)->type('closure')->value();
$namespace = $image->getDriver()->getNamespace();
$rectangle_classname = "\{$namespace}\Shapes\RectangleShape";
$rectangle = new $rectangle_classname($x1, $y1, $x2, $y2);
if ($callback instanceof Closure) {
$callback($rectangle);
}
$rectangle->applyToImage($image, $x1, $y1);
return true;
} | [
"public",
"function",
"execute",
"(",
"$",
"image",
")",
"{",
"$",
"x1",
"=",
"$",
"this",
"->",
"argument",
"(",
"0",
")",
"->",
"type",
"(",
"'numeric'",
")",
"->",
"required",
"(",
")",
"->",
"value",
"(",
")",
";",
"$",
"y1",
"=",
"$",
"this",
"->",
"argument",
"(",
"1",
")",
"->",
"type",
"(",
"'numeric'",
")",
"->",
"required",
"(",
")",
"->",
"value",
"(",
")",
";",
"$",
"x2",
"=",
"$",
"this",
"->",
"argument",
"(",
"2",
")",
"->",
"type",
"(",
"'numeric'",
")",
"->",
"required",
"(",
")",
"->",
"value",
"(",
")",
";",
"$",
"y2",
"=",
"$",
"this",
"->",
"argument",
"(",
"3",
")",
"->",
"type",
"(",
"'numeric'",
")",
"->",
"required",
"(",
")",
"->",
"value",
"(",
")",
";",
"$",
"callback",
"=",
"$",
"this",
"->",
"argument",
"(",
"4",
")",
"->",
"type",
"(",
"'closure'",
")",
"->",
"value",
"(",
")",
";",
"$",
"namespace",
"=",
"$",
"image",
"->",
"getDriver",
"(",
")",
"->",
"getNamespace",
"(",
")",
";",
"$",
"rectangle_classname",
"=",
"\"\\{$namespace}\\Shapes\\RectangleShape\"",
";",
"$",
"rectangle",
"=",
"new",
"$",
"rectangle_classname",
"(",
"$",
"x1",
",",
"$",
"y1",
",",
"$",
"x2",
",",
"$",
"y2",
")",
";",
"if",
"(",
"$",
"callback",
"instanceof",
"Closure",
")",
"{",
"$",
"callback",
"(",
"$",
"rectangle",
")",
";",
"}",
"$",
"rectangle",
"->",
"applyToImage",
"(",
"$",
"image",
",",
"$",
"x1",
",",
"$",
"y1",
")",
";",
"return",
"true",
";",
"}"
] | Draws rectangle on given image
@param \Hail\Image\Image $image
@return bool | [
"Draws",
"rectangle",
"on",
"given",
"image"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Image/Commands/RectangleCommand.php#L16-L36 |
35,553 | hail-framework/framework | src/Redis/Sentinel.php | Sentinel.createMasterClient | public function createMasterClient($name)
{
$master = $this->getMasterAddressByName($name);
if (!isset($master[0], $master[1])) {
throw new RedisException('Master not found');
}
return Factory::client([
'host' => $master[0],
'port' => $master[1],
'timeout' => $this->timeout,
'persistent' => $this->persistent,
'database' => $this->database,
'password' => $this->getPassword(),
]);
} | php | public function createMasterClient($name)
{
$master = $this->getMasterAddressByName($name);
if (!isset($master[0], $master[1])) {
throw new RedisException('Master not found');
}
return Factory::client([
'host' => $master[0],
'port' => $master[1],
'timeout' => $this->timeout,
'persistent' => $this->persistent,
'database' => $this->database,
'password' => $this->getPassword(),
]);
} | [
"public",
"function",
"createMasterClient",
"(",
"$",
"name",
")",
"{",
"$",
"master",
"=",
"$",
"this",
"->",
"getMasterAddressByName",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"master",
"[",
"0",
"]",
",",
"$",
"master",
"[",
"1",
"]",
")",
")",
"{",
"throw",
"new",
"RedisException",
"(",
"'Master not found'",
")",
";",
"}",
"return",
"Factory",
"::",
"client",
"(",
"[",
"'host'",
"=>",
"$",
"master",
"[",
"0",
"]",
",",
"'port'",
"=>",
"$",
"master",
"[",
"1",
"]",
",",
"'timeout'",
"=>",
"$",
"this",
"->",
"timeout",
",",
"'persistent'",
"=>",
"$",
"this",
"->",
"persistent",
",",
"'database'",
"=>",
"$",
"this",
"->",
"database",
",",
"'password'",
"=>",
"$",
"this",
"->",
"getPassword",
"(",
")",
",",
"]",
")",
";",
"}"
] | Discover the master node automatically and return an instance of Credis_Client that connects to the master
@param string $name
@return RedisInterface
@throws RedisException | [
"Discover",
"the",
"master",
"node",
"automatically",
"and",
"return",
"an",
"instance",
"of",
"Credis_Client",
"that",
"connects",
"to",
"the",
"master"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Redis/Sentinel.php#L127-L142 |
35,554 | hail-framework/framework | src/Redis/Sentinel.php | Sentinel.getMasterClient | public function getMasterClient($name)
{
if (!isset($this->master[$name])) {
$this->master[$name] = $this->createMasterClient($name);
}
return $this->master[$name];
} | php | public function getMasterClient($name)
{
if (!isset($this->master[$name])) {
$this->master[$name] = $this->createMasterClient($name);
}
return $this->master[$name];
} | [
"public",
"function",
"getMasterClient",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"master",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"master",
"[",
"$",
"name",
"]",
"=",
"$",
"this",
"->",
"createMasterClient",
"(",
"$",
"name",
")",
";",
"}",
"return",
"$",
"this",
"->",
"master",
"[",
"$",
"name",
"]",
";",
"}"
] | If a Credis_Client object exists for a master, return it. Otherwise create one and return it
@param string $name
@return Client
@throws RedisException | [
"If",
"a",
"Credis_Client",
"object",
"exists",
"for",
"a",
"master",
"return",
"it",
".",
"Otherwise",
"create",
"one",
"and",
"return",
"it"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Redis/Sentinel.php#L152-L159 |
35,555 | hail-framework/framework | src/Redis/Sentinel.php | Sentinel.createSlaveClients | public function createSlaveClients($name)
{
$slaves = $this->slaves($name);
$workingSlaves = [];
foreach ($slaves as $slave) {
if (!isset($slave[9])) {
throw new RedisException('Can\' retrieve slave status');
}
if (\strpos($slave[9], 's_down') === false && \strpos($slave[9], 'disconnected') === false) {
$workingSlaves[] = Factory::client([
'host' => $slave[3],
'port' => $slave[5],
'timeout' => $this->timeout,
'persistent' => $this->persistent,
'database' => $this->database,
'password' => $this->getPassword(),
]);
}
}
return $workingSlaves;
} | php | public function createSlaveClients($name)
{
$slaves = $this->slaves($name);
$workingSlaves = [];
foreach ($slaves as $slave) {
if (!isset($slave[9])) {
throw new RedisException('Can\' retrieve slave status');
}
if (\strpos($slave[9], 's_down') === false && \strpos($slave[9], 'disconnected') === false) {
$workingSlaves[] = Factory::client([
'host' => $slave[3],
'port' => $slave[5],
'timeout' => $this->timeout,
'persistent' => $this->persistent,
'database' => $this->database,
'password' => $this->getPassword(),
]);
}
}
return $workingSlaves;
} | [
"public",
"function",
"createSlaveClients",
"(",
"$",
"name",
")",
"{",
"$",
"slaves",
"=",
"$",
"this",
"->",
"slaves",
"(",
"$",
"name",
")",
";",
"$",
"workingSlaves",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"slaves",
"as",
"$",
"slave",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"slave",
"[",
"9",
"]",
")",
")",
"{",
"throw",
"new",
"RedisException",
"(",
"'Can\\' retrieve slave status'",
")",
";",
"}",
"if",
"(",
"\\",
"strpos",
"(",
"$",
"slave",
"[",
"9",
"]",
",",
"'s_down'",
")",
"===",
"false",
"&&",
"\\",
"strpos",
"(",
"$",
"slave",
"[",
"9",
"]",
",",
"'disconnected'",
")",
"===",
"false",
")",
"{",
"$",
"workingSlaves",
"[",
"]",
"=",
"Factory",
"::",
"client",
"(",
"[",
"'host'",
"=>",
"$",
"slave",
"[",
"3",
"]",
",",
"'port'",
"=>",
"$",
"slave",
"[",
"5",
"]",
",",
"'timeout'",
"=>",
"$",
"this",
"->",
"timeout",
",",
"'persistent'",
"=>",
"$",
"this",
"->",
"persistent",
",",
"'database'",
"=>",
"$",
"this",
"->",
"database",
",",
"'password'",
"=>",
"$",
"this",
"->",
"getPassword",
"(",
")",
",",
"]",
")",
";",
"}",
"}",
"return",
"$",
"workingSlaves",
";",
"}"
] | Discover the slave nodes automatically and return an array of Credis_Client objects
@param string $name
@return RedisInterface[]
@throws RedisException | [
"Discover",
"the",
"slave",
"nodes",
"automatically",
"and",
"return",
"an",
"array",
"of",
"Credis_Client",
"objects"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Redis/Sentinel.php#L169-L190 |
35,556 | hail-framework/framework | src/Redis/Sentinel.php | Sentinel.getSlaveClients | public function getSlaveClients($name)
{
if (!isset($this->slaves[$name])) {
$this->slaves[$name] = $this->createSlaveClients($name);
}
return $this->slaves[$name];
} | php | public function getSlaveClients($name)
{
if (!isset($this->slaves[$name])) {
$this->slaves[$name] = $this->createSlaveClients($name);
}
return $this->slaves[$name];
} | [
"public",
"function",
"getSlaveClients",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"slaves",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"slaves",
"[",
"$",
"name",
"]",
"=",
"$",
"this",
"->",
"createSlaveClients",
"(",
"$",
"name",
")",
";",
"}",
"return",
"$",
"this",
"->",
"slaves",
"[",
"$",
"name",
"]",
";",
"}"
] | If an array of Credis_Client objects exist for a set of slaves, return them. Otherwise create and return them
@param string $name
@return Client[]
@throws RedisException | [
"If",
"an",
"array",
"of",
"Credis_Client",
"objects",
"exist",
"for",
"a",
"set",
"of",
"slaves",
"return",
"them",
".",
"Otherwise",
"create",
"and",
"return",
"them"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Redis/Sentinel.php#L200-L207 |
35,557 | hail-framework/framework | src/Redis/Sentinel.php | Sentinel.info | public function info($section = null)
{
if ($section) {
return $this->client->info($section);
}
return $this->client->info();
} | php | public function info($section = null)
{
if ($section) {
return $this->client->info($section);
}
return $this->client->info();
} | [
"public",
"function",
"info",
"(",
"$",
"section",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"section",
")",
"{",
"return",
"$",
"this",
"->",
"client",
"->",
"info",
"(",
"$",
"section",
")",
";",
"}",
"return",
"$",
"this",
"->",
"client",
"->",
"info",
"(",
")",
";",
"}"
] | get information block for the sentinel instance
@param string|NUll $section
@return array | [
"get",
"information",
"block",
"for",
"the",
"sentinel",
"instance"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Redis/Sentinel.php#L232-L239 |
35,558 | hail-framework/framework | src/Console/CommandTrait.php | CommandTrait.name | public function name(): string
{
static $name = null;
if ($name === null) {
// Extract command name from the class name.
$class = substr(strrchr(static::class, '\\'), 1);
$name = CommandLoader::inverseTranslate($class);
}
return $name;
} | php | public function name(): string
{
static $name = null;
if ($name === null) {
// Extract command name from the class name.
$class = substr(strrchr(static::class, '\\'), 1);
$name = CommandLoader::inverseTranslate($class);
}
return $name;
} | [
"public",
"function",
"name",
"(",
")",
":",
"string",
"{",
"static",
"$",
"name",
"=",
"null",
";",
"if",
"(",
"$",
"name",
"===",
"null",
")",
"{",
"// Extract command name from the class name.",
"$",
"class",
"=",
"substr",
"(",
"strrchr",
"(",
"static",
"::",
"class",
",",
"'\\\\'",
")",
",",
"1",
")",
";",
"$",
"name",
"=",
"CommandLoader",
"::",
"inverseTranslate",
"(",
"$",
"class",
")",
";",
"}",
"return",
"$",
"name",
";",
"}"
] | Translate current class name to command name.
@return string command name | [
"Translate",
"current",
"class",
"name",
"to",
"command",
"name",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/CommandTrait.php#L132-L142 |
35,559 | hail-framework/framework | src/Console/CommandTrait.php | CommandTrait.addCommandGroup | public function addCommandGroup($groupName, $commands = [])
{
$group = new CommandGroup($groupName);
foreach ($commands as $val) {
$cmd = $this->addCommand($val);
$group->addCommand($cmd);
}
$this->commandGroups[] = $group;
return $group;
} | php | public function addCommandGroup($groupName, $commands = [])
{
$group = new CommandGroup($groupName);
foreach ($commands as $val) {
$cmd = $this->addCommand($val);
$group->addCommand($cmd);
}
$this->commandGroups[] = $group;
return $group;
} | [
"public",
"function",
"addCommandGroup",
"(",
"$",
"groupName",
",",
"$",
"commands",
"=",
"[",
"]",
")",
"{",
"$",
"group",
"=",
"new",
"CommandGroup",
"(",
"$",
"groupName",
")",
";",
"foreach",
"(",
"$",
"commands",
"as",
"$",
"val",
")",
"{",
"$",
"cmd",
"=",
"$",
"this",
"->",
"addCommand",
"(",
"$",
"val",
")",
";",
"$",
"group",
"->",
"addCommand",
"(",
"$",
"cmd",
")",
";",
"}",
"$",
"this",
"->",
"commandGroups",
"[",
"]",
"=",
"$",
"group",
";",
"return",
"$",
"group",
";",
"}"
] | Add a command group and register the commands automatically
@param string $groupName The group name
@param array $commands Command array combines indexed command names or command class assoc array.
@return CommandGroup | [
"Add",
"a",
"command",
"group",
"and",
"register",
"the",
"commands",
"automatically"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/CommandTrait.php#L161-L171 |
35,560 | hail-framework/framework | src/Console/CommandTrait.php | CommandTrait.getApplication | public function getApplication(): ?Application
{
if ($this instanceof Application) {
return $this;
}
if ($p = $this->parent) {
return $p->getApplication();
}
return null;
} | php | public function getApplication(): ?Application
{
if ($this instanceof Application) {
return $this;
}
if ($p = $this->parent) {
return $p->getApplication();
}
return null;
} | [
"public",
"function",
"getApplication",
"(",
")",
":",
"?",
"Application",
"{",
"if",
"(",
"$",
"this",
"instanceof",
"Application",
")",
"{",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"$",
"p",
"=",
"$",
"this",
"->",
"parent",
")",
"{",
"return",
"$",
"p",
"->",
"getApplication",
"(",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Get the main application object from parents or the object itself.
@return Application|null | [
"Get",
"the",
"main",
"application",
"object",
"from",
"parents",
"or",
"the",
"object",
"itself",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/CommandTrait.php#L188-L199 |
35,561 | hail-framework/framework | src/Console/CommandTrait.php | CommandTrait.connectCommand | public function connectCommand(Command $cmd)
{
$name = $cmd->name();
$this->commands[$name] = $cmd;
// regsiter command aliases to the alias table.
$aliases = $cmd->aliases();
if (is_string($aliases)) {
$aliases = preg_split('/\s+/', $aliases);
}
if (!is_array($aliases)) {
throw new InvalidArgumentException('Aliases needs to be an array or a space-separated string.');
}
foreach ($aliases as $alias) {
$this->aliases[$alias] = $cmd;
}
} | php | public function connectCommand(Command $cmd)
{
$name = $cmd->name();
$this->commands[$name] = $cmd;
// regsiter command aliases to the alias table.
$aliases = $cmd->aliases();
if (is_string($aliases)) {
$aliases = preg_split('/\s+/', $aliases);
}
if (!is_array($aliases)) {
throw new InvalidArgumentException('Aliases needs to be an array or a space-separated string.');
}
foreach ($aliases as $alias) {
$this->aliases[$alias] = $cmd;
}
} | [
"public",
"function",
"connectCommand",
"(",
"Command",
"$",
"cmd",
")",
"{",
"$",
"name",
"=",
"$",
"cmd",
"->",
"name",
"(",
")",
";",
"$",
"this",
"->",
"commands",
"[",
"$",
"name",
"]",
"=",
"$",
"cmd",
";",
"// regsiter command aliases to the alias table.",
"$",
"aliases",
"=",
"$",
"cmd",
"->",
"aliases",
"(",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"aliases",
")",
")",
"{",
"$",
"aliases",
"=",
"preg_split",
"(",
"'/\\s+/'",
",",
"$",
"aliases",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"aliases",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Aliases needs to be an array or a space-separated string.'",
")",
";",
"}",
"foreach",
"(",
"$",
"aliases",
"as",
"$",
"alias",
")",
"{",
"$",
"this",
"->",
"aliases",
"[",
"$",
"alias",
"]",
"=",
"$",
"cmd",
";",
"}",
"}"
] | connectCommand connects a command name with a command object.
@param Command $cmd | [
"connectCommand",
"connects",
"a",
"command",
"name",
"with",
"a",
"command",
"object",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/CommandTrait.php#L320-L338 |
35,562 | hail-framework/framework | src/Console/CommandTrait.php | CommandTrait.aggregate | public function aggregate()
{
$commands = [];
foreach ($this->getVisibleCommands() as $name => $cmd) {
$commands[$name] = $cmd;
}
foreach ($this->commandGroups as $g) {
if ($g->isHidden) {
continue;
}
foreach ($g->getCommands() as $name => $cmd) {
unset($commands[$name]);
}
}
uasort($this->commandGroups, function ($a, $b) {
if ($a->getId() === 'dev') {
return 1;
}
return 0;
});
return [
'groups' => $this->commandGroups,
'commands' => $commands,
];
} | php | public function aggregate()
{
$commands = [];
foreach ($this->getVisibleCommands() as $name => $cmd) {
$commands[$name] = $cmd;
}
foreach ($this->commandGroups as $g) {
if ($g->isHidden) {
continue;
}
foreach ($g->getCommands() as $name => $cmd) {
unset($commands[$name]);
}
}
uasort($this->commandGroups, function ($a, $b) {
if ($a->getId() === 'dev') {
return 1;
}
return 0;
});
return [
'groups' => $this->commandGroups,
'commands' => $commands,
];
} | [
"public",
"function",
"aggregate",
"(",
")",
"{",
"$",
"commands",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getVisibleCommands",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"cmd",
")",
"{",
"$",
"commands",
"[",
"$",
"name",
"]",
"=",
"$",
"cmd",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"commandGroups",
"as",
"$",
"g",
")",
"{",
"if",
"(",
"$",
"g",
"->",
"isHidden",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"g",
"->",
"getCommands",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"cmd",
")",
"{",
"unset",
"(",
"$",
"commands",
"[",
"$",
"name",
"]",
")",
";",
"}",
"}",
"uasort",
"(",
"$",
"this",
"->",
"commandGroups",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"if",
"(",
"$",
"a",
"->",
"getId",
"(",
")",
"===",
"'dev'",
")",
"{",
"return",
"1",
";",
"}",
"return",
"0",
";",
"}",
")",
";",
"return",
"[",
"'groups'",
"=>",
"$",
"this",
"->",
"commandGroups",
",",
"'commands'",
"=>",
"$",
"commands",
",",
"]",
";",
"}"
] | Aggregate command info | [
"Aggregate",
"command",
"info"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/CommandTrait.php#L344-L372 |
35,563 | hail-framework/framework | src/Console/CommandTrait.php | CommandTrait.getVisibleCommands | public function getVisibleCommands(): array
{
$commands = [];
foreach ($this->commands as $name => $command) {
if ($name[0] === '_') {
continue;
}
$commands[$name] = $command;
}
return $commands;
} | php | public function getVisibleCommands(): array
{
$commands = [];
foreach ($this->commands as $name => $command) {
if ($name[0] === '_') {
continue;
}
$commands[$name] = $command;
}
return $commands;
} | [
"public",
"function",
"getVisibleCommands",
"(",
")",
":",
"array",
"{",
"$",
"commands",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"commands",
"as",
"$",
"name",
"=>",
"$",
"command",
")",
"{",
"if",
"(",
"$",
"name",
"[",
"0",
"]",
"===",
"'_'",
")",
"{",
"continue",
";",
"}",
"$",
"commands",
"[",
"$",
"name",
"]",
"=",
"$",
"command",
";",
"}",
"return",
"$",
"commands",
";",
"}"
] | Some commands are not visible. when user runs 'help', we should just
show them these visible commands
@return string[] CommandBase command map | [
"Some",
"commands",
"are",
"not",
"visible",
".",
"when",
"user",
"runs",
"help",
"we",
"should",
"just",
"show",
"them",
"these",
"visible",
"commands"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/CommandTrait.php#L414-L426 |
35,564 | hail-framework/framework | src/Console/CommandTrait.php | CommandTrait.getCommandNameTraceArray | public function getCommandNameTraceArray()
{
$cmdStacks = [$this->name()];
$p = $this->parent;
while ($p) {
if (!$p instanceof Application) {
$cmdStacks[] = $p->name();
}
$p = $p->parent;
}
return array_reverse($cmdStacks);
} | php | public function getCommandNameTraceArray()
{
$cmdStacks = [$this->name()];
$p = $this->parent;
while ($p) {
if (!$p instanceof Application) {
$cmdStacks[] = $p->name();
}
$p = $p->parent;
}
return array_reverse($cmdStacks);
} | [
"public",
"function",
"getCommandNameTraceArray",
"(",
")",
"{",
"$",
"cmdStacks",
"=",
"[",
"$",
"this",
"->",
"name",
"(",
")",
"]",
";",
"$",
"p",
"=",
"$",
"this",
"->",
"parent",
";",
"while",
"(",
"$",
"p",
")",
"{",
"if",
"(",
"!",
"$",
"p",
"instanceof",
"Application",
")",
"{",
"$",
"cmdStacks",
"[",
"]",
"=",
"$",
"p",
"->",
"name",
"(",
")",
";",
"}",
"$",
"p",
"=",
"$",
"p",
"->",
"parent",
";",
"}",
"return",
"array_reverse",
"(",
"$",
"cmdStacks",
")",
";",
"}"
] | Return the command name stack
@return string[] | [
"Return",
"the",
"command",
"name",
"stack"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/CommandTrait.php#L446-L458 |
35,565 | hail-framework/framework | src/Console/CommandTrait.php | CommandTrait.getCommand | public function getCommand($command): Command
{
if (isset($this->aliases[$command])) {
return $this->aliases[$command];
}
if (isset($this->commands[$command])) {
return $this->commands[$command];
}
throw new CommandNotFoundException($this, $command);
} | php | public function getCommand($command): Command
{
if (isset($this->aliases[$command])) {
return $this->aliases[$command];
}
if (isset($this->commands[$command])) {
return $this->commands[$command];
}
throw new CommandNotFoundException($this, $command);
} | [
"public",
"function",
"getCommand",
"(",
"$",
"command",
")",
":",
"Command",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"command",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"aliases",
"[",
"$",
"command",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"commands",
"[",
"$",
"command",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"commands",
"[",
"$",
"command",
"]",
";",
"}",
"throw",
"new",
"CommandNotFoundException",
"(",
"$",
"this",
",",
"$",
"command",
")",
";",
"}"
] | Get subcommand object from current command
by command name.
@param string $command
@return Command initialized command object.
@throws CommandNotFoundException | [
"Get",
"subcommand",
"object",
"from",
"current",
"command",
"by",
"command",
"name",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/CommandTrait.php#L485-L496 |
35,566 | hail-framework/framework | src/Console/CommandTrait.php | CommandTrait.getArguments | public function getArguments(): array
{
// if user not define any arguments, get argument info from method parameters
if ($this->arguments === null) {
$this->arguments = [];
$ro = new \ReflectionObject($this);
if (!$ro->hasMethod('execute')) {
throw new ExecuteMethodNotDefinedException($this);
}
$method = $ro->getMethod('execute');
$parameters = $method->getParameters();
foreach ($parameters as $param) {
$a = $this->addArgument($param->getName());
if ($param->isOptional()) {
$a->optional();
if ($param->isDefaultValueAvailable()) {
$a->setValue($param->getDefaultValue());
}
}
}
}
return $this->arguments;
} | php | public function getArguments(): array
{
// if user not define any arguments, get argument info from method parameters
if ($this->arguments === null) {
$this->arguments = [];
$ro = new \ReflectionObject($this);
if (!$ro->hasMethod('execute')) {
throw new ExecuteMethodNotDefinedException($this);
}
$method = $ro->getMethod('execute');
$parameters = $method->getParameters();
foreach ($parameters as $param) {
$a = $this->addArgument($param->getName());
if ($param->isOptional()) {
$a->optional();
if ($param->isDefaultValueAvailable()) {
$a->setValue($param->getDefaultValue());
}
}
}
}
return $this->arguments;
} | [
"public",
"function",
"getArguments",
"(",
")",
":",
"array",
"{",
"// if user not define any arguments, get argument info from method parameters",
"if",
"(",
"$",
"this",
"->",
"arguments",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"arguments",
"=",
"[",
"]",
";",
"$",
"ro",
"=",
"new",
"\\",
"ReflectionObject",
"(",
"$",
"this",
")",
";",
"if",
"(",
"!",
"$",
"ro",
"->",
"hasMethod",
"(",
"'execute'",
")",
")",
"{",
"throw",
"new",
"ExecuteMethodNotDefinedException",
"(",
"$",
"this",
")",
";",
"}",
"$",
"method",
"=",
"$",
"ro",
"->",
"getMethod",
"(",
"'execute'",
")",
";",
"$",
"parameters",
"=",
"$",
"method",
"->",
"getParameters",
"(",
")",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"param",
")",
"{",
"$",
"a",
"=",
"$",
"this",
"->",
"addArgument",
"(",
"$",
"param",
"->",
"getName",
"(",
")",
")",
";",
"if",
"(",
"$",
"param",
"->",
"isOptional",
"(",
")",
")",
"{",
"$",
"a",
"->",
"optional",
"(",
")",
";",
"if",
"(",
"$",
"param",
"->",
"isDefaultValueAvailable",
"(",
")",
")",
"{",
"$",
"a",
"->",
"setValue",
"(",
"$",
"param",
"->",
"getDefaultValue",
"(",
")",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"arguments",
";",
"}"
] | Return the defined argument info objects.
@return Argument[]
@throws ExecuteMethodNotDefinedException | [
"Return",
"the",
"defined",
"argument",
"info",
"objects",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/CommandTrait.php#L659-L686 |
35,567 | hail-framework/framework | src/Console/CommandTrait.php | CommandTrait.executeWrapper | public function executeWrapper(array $args)
{
if (!method_exists($this, 'execute')) {
$cmd = $this->createCommand(Help::class);
$cmd->executeWrapper([$this->name()]);
return;
}
// Validating arguments
foreach ($this->getArguments() as $k => $argument) {
if (!isset($args[$k])) {
if ($argument->isRequired()) {
throw new RequireValueException("Argument pos {$k} '{$argument->name()}' requires a value.");
}
continue;
}
if (!$argument->validate($args[$k])) {
$this->logger->error("Invalid argument {$args[$k]}");
return;
}
$args[$k] = $argument->getValue();
}
$refMethod = new \ReflectionMethod($this, 'execute');
$requiredNumber = $refMethod->getNumberOfRequiredParameters();
$count = count($args);
if ($count < $requiredNumber) {
throw new CommandArgumentNotEnoughException($this, $count, $requiredNumber);
}
foreach ($this->extensions as $extension) {
$extension->execute();
}
$this->execute(...$args);
} | php | public function executeWrapper(array $args)
{
if (!method_exists($this, 'execute')) {
$cmd = $this->createCommand(Help::class);
$cmd->executeWrapper([$this->name()]);
return;
}
// Validating arguments
foreach ($this->getArguments() as $k => $argument) {
if (!isset($args[$k])) {
if ($argument->isRequired()) {
throw new RequireValueException("Argument pos {$k} '{$argument->name()}' requires a value.");
}
continue;
}
if (!$argument->validate($args[$k])) {
$this->logger->error("Invalid argument {$args[$k]}");
return;
}
$args[$k] = $argument->getValue();
}
$refMethod = new \ReflectionMethod($this, 'execute');
$requiredNumber = $refMethod->getNumberOfRequiredParameters();
$count = count($args);
if ($count < $requiredNumber) {
throw new CommandArgumentNotEnoughException($this, $count, $requiredNumber);
}
foreach ($this->extensions as $extension) {
$extension->execute();
}
$this->execute(...$args);
} | [
"public",
"function",
"executeWrapper",
"(",
"array",
"$",
"args",
")",
"{",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"this",
",",
"'execute'",
")",
")",
"{",
"$",
"cmd",
"=",
"$",
"this",
"->",
"createCommand",
"(",
"Help",
"::",
"class",
")",
";",
"$",
"cmd",
"->",
"executeWrapper",
"(",
"[",
"$",
"this",
"->",
"name",
"(",
")",
"]",
")",
";",
"return",
";",
"}",
"// Validating arguments",
"foreach",
"(",
"$",
"this",
"->",
"getArguments",
"(",
")",
"as",
"$",
"k",
"=>",
"$",
"argument",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"args",
"[",
"$",
"k",
"]",
")",
")",
"{",
"if",
"(",
"$",
"argument",
"->",
"isRequired",
"(",
")",
")",
"{",
"throw",
"new",
"RequireValueException",
"(",
"\"Argument pos {$k} '{$argument->name()}' requires a value.\"",
")",
";",
"}",
"continue",
";",
"}",
"if",
"(",
"!",
"$",
"argument",
"->",
"validate",
"(",
"$",
"args",
"[",
"$",
"k",
"]",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"error",
"(",
"\"Invalid argument {$args[$k]}\"",
")",
";",
"return",
";",
"}",
"$",
"args",
"[",
"$",
"k",
"]",
"=",
"$",
"argument",
"->",
"getValue",
"(",
")",
";",
"}",
"$",
"refMethod",
"=",
"new",
"\\",
"ReflectionMethod",
"(",
"$",
"this",
",",
"'execute'",
")",
";",
"$",
"requiredNumber",
"=",
"$",
"refMethod",
"->",
"getNumberOfRequiredParameters",
"(",
")",
";",
"$",
"count",
"=",
"count",
"(",
"$",
"args",
")",
";",
"if",
"(",
"$",
"count",
"<",
"$",
"requiredNumber",
")",
"{",
"throw",
"new",
"CommandArgumentNotEnoughException",
"(",
"$",
"this",
",",
"$",
"count",
",",
"$",
"requiredNumber",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"extensions",
"as",
"$",
"extension",
")",
"{",
"$",
"extension",
"->",
"execute",
"(",
")",
";",
"}",
"$",
"this",
"->",
"execute",
"(",
"...",
"$",
"args",
")",
";",
"}"
] | Execute command object, this is a wrapper method for execution.
In this method, we check the command arguments by the Reflection feature
provided by PHP.
@param array $args command argument list (not associative array).
@throws CommandArgumentNotEnoughException
@throws RequireValueException
@throws \ReflectionException | [
"Execute",
"command",
"object",
"this",
"is",
"a",
"wrapper",
"method",
"for",
"execution",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/CommandTrait.php#L700-L742 |
35,568 | hail-framework/framework | src/Http/Middleware/Payload.php | Payload.csvParser | protected static function csvParser(StreamInterface $stream): array
{
if ($stream->isSeekable()) {
$stream->rewind();
}
$handle = $stream->detach();
$data = [];
while (($row = \fgetcsv($handle)) !== false) {
$data[] = $row;
}
\fclose($handle);
return ['body' => $data];
} | php | protected static function csvParser(StreamInterface $stream): array
{
if ($stream->isSeekable()) {
$stream->rewind();
}
$handle = $stream->detach();
$data = [];
while (($row = \fgetcsv($handle)) !== false) {
$data[] = $row;
}
\fclose($handle);
return ['body' => $data];
} | [
"protected",
"static",
"function",
"csvParser",
"(",
"StreamInterface",
"$",
"stream",
")",
":",
"array",
"{",
"if",
"(",
"$",
"stream",
"->",
"isSeekable",
"(",
")",
")",
"{",
"$",
"stream",
"->",
"rewind",
"(",
")",
";",
"}",
"$",
"handle",
"=",
"$",
"stream",
"->",
"detach",
"(",
")",
";",
"$",
"data",
"=",
"[",
"]",
";",
"while",
"(",
"(",
"$",
"row",
"=",
"\\",
"fgetcsv",
"(",
"$",
"handle",
")",
")",
"!==",
"false",
")",
"{",
"$",
"data",
"[",
"]",
"=",
"$",
"row",
";",
"}",
"\\",
"fclose",
"(",
"$",
"handle",
")",
";",
"return",
"[",
"'body'",
"=>",
"$",
"data",
"]",
";",
"}"
] | Parses csv strings.
@param StreamInterface $stream
@return array
@throws \RuntimeException | [
"Parses",
"csv",
"strings",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Http/Middleware/Payload.php#L177-L191 |
35,569 | hail-framework/framework | src/Console/Component/Table/Table.php | Table.getNumberOfColumns | private function getNumberOfColumns()
{
if (null !== $this->numberOfColumns) {
return $this->numberOfColumns;
}
$columns = [\count($this->headers)];
foreach ($this->rows as $row) {
$columns[] = \count($row);
}
return $this->numberOfColumns = \max($columns);
} | php | private function getNumberOfColumns()
{
if (null !== $this->numberOfColumns) {
return $this->numberOfColumns;
}
$columns = [\count($this->headers)];
foreach ($this->rows as $row) {
$columns[] = \count($row);
}
return $this->numberOfColumns = \max($columns);
} | [
"private",
"function",
"getNumberOfColumns",
"(",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"numberOfColumns",
")",
"{",
"return",
"$",
"this",
"->",
"numberOfColumns",
";",
"}",
"$",
"columns",
"=",
"[",
"\\",
"count",
"(",
"$",
"this",
"->",
"headers",
")",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"rows",
"as",
"$",
"row",
")",
"{",
"$",
"columns",
"[",
"]",
"=",
"\\",
"count",
"(",
"$",
"row",
")",
";",
"}",
"return",
"$",
"this",
"->",
"numberOfColumns",
"=",
"\\",
"max",
"(",
"$",
"columns",
")",
";",
"}"
] | Gets number of columns for this table.
@return int | [
"Gets",
"number",
"of",
"columns",
"for",
"this",
"table",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/Component/Table/Table.php#L112-L124 |
35,570 | hiqdev/hipanel-module-dns | src/controllers/RecordController.php | RecordController.actionCreate | public function actionCreate()
{
$collection = (new Collection([
'model' => $this->newModel(['scenario' => 'create']),
]))->load();
if ($collection->count() && $collection->save()) {
Yii::$app->session->addFlash('success', Yii::t('hipanel:dns', '{0, plural, one{DNS record} other{# DNS records}} created successfully', $collection->count()));
return $this->renderZoneView($collection->first->hdomain_id);
} elseif ($id = $collection->first->hdomain_id) {
return $this->redirect(['@dns/zone/view', 'id' => $id]);
}
throw new BadRequestHttpException('Bad request');
} | php | public function actionCreate()
{
$collection = (new Collection([
'model' => $this->newModel(['scenario' => 'create']),
]))->load();
if ($collection->count() && $collection->save()) {
Yii::$app->session->addFlash('success', Yii::t('hipanel:dns', '{0, plural, one{DNS record} other{# DNS records}} created successfully', $collection->count()));
return $this->renderZoneView($collection->first->hdomain_id);
} elseif ($id = $collection->first->hdomain_id) {
return $this->redirect(['@dns/zone/view', 'id' => $id]);
}
throw new BadRequestHttpException('Bad request');
} | [
"public",
"function",
"actionCreate",
"(",
")",
"{",
"$",
"collection",
"=",
"(",
"new",
"Collection",
"(",
"[",
"'model'",
"=>",
"$",
"this",
"->",
"newModel",
"(",
"[",
"'scenario'",
"=>",
"'create'",
"]",
")",
",",
"]",
")",
")",
"->",
"load",
"(",
")",
";",
"if",
"(",
"$",
"collection",
"->",
"count",
"(",
")",
"&&",
"$",
"collection",
"->",
"save",
"(",
")",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"session",
"->",
"addFlash",
"(",
"'success'",
",",
"Yii",
"::",
"t",
"(",
"'hipanel:dns'",
",",
"'{0, plural, one{DNS record} other{# DNS records}} created successfully'",
",",
"$",
"collection",
"->",
"count",
"(",
")",
")",
")",
";",
"return",
"$",
"this",
"->",
"renderZoneView",
"(",
"$",
"collection",
"->",
"first",
"->",
"hdomain_id",
")",
";",
"}",
"elseif",
"(",
"$",
"id",
"=",
"$",
"collection",
"->",
"first",
"->",
"hdomain_id",
")",
"{",
"return",
"$",
"this",
"->",
"redirect",
"(",
"[",
"'@dns/zone/view'",
",",
"'id'",
"=>",
"$",
"id",
"]",
")",
";",
"}",
"throw",
"new",
"BadRequestHttpException",
"(",
"'Bad request'",
")",
";",
"}"
] | Created the DNS record.
@throws BadRequestHttpException
@throws NotFoundHttpException
@return string|\yii\web\Response | [
"Created",
"the",
"DNS",
"record",
"."
] | 7e9199c95d91a979b7bd4fd07fe801dbe9e69183 | https://github.com/hiqdev/hipanel-module-dns/blob/7e9199c95d91a979b7bd4fd07fe801dbe9e69183/src/controllers/RecordController.php#L62-L77 |
35,571 | hiqdev/hipanel-module-dns | src/controllers/RecordController.php | RecordController.actionUpdate | public function actionUpdate($id = null, $hdomain_id = null)
{
if ($id && $hdomain_id && $model = $this->newModel()->findOne(compact('id', 'hdomain_id'))) {
$model->scenario = 'update';
return $this->renderAjax('update', ['model' => $model]);
}
$collection = (new Collection([
'model' => $this->newModel(['scenario' => 'update']),
]))->load();
if ($collection->first->id && $collection->save()) {
Yii::$app->session->addFlash('success', Yii::t('hipanel:dns', '{0, plural, one{DNS record} other{# DNS records}} updated successfully', $collection->count()));
return $this->renderZoneView($collection->first->hdomain_id);
}
throw new BadRequestHttpException('Bad request');
} | php | public function actionUpdate($id = null, $hdomain_id = null)
{
if ($id && $hdomain_id && $model = $this->newModel()->findOne(compact('id', 'hdomain_id'))) {
$model->scenario = 'update';
return $this->renderAjax('update', ['model' => $model]);
}
$collection = (new Collection([
'model' => $this->newModel(['scenario' => 'update']),
]))->load();
if ($collection->first->id && $collection->save()) {
Yii::$app->session->addFlash('success', Yii::t('hipanel:dns', '{0, plural, one{DNS record} other{# DNS records}} updated successfully', $collection->count()));
return $this->renderZoneView($collection->first->hdomain_id);
}
throw new BadRequestHttpException('Bad request');
} | [
"public",
"function",
"actionUpdate",
"(",
"$",
"id",
"=",
"null",
",",
"$",
"hdomain_id",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"id",
"&&",
"$",
"hdomain_id",
"&&",
"$",
"model",
"=",
"$",
"this",
"->",
"newModel",
"(",
")",
"->",
"findOne",
"(",
"compact",
"(",
"'id'",
",",
"'hdomain_id'",
")",
")",
")",
"{",
"$",
"model",
"->",
"scenario",
"=",
"'update'",
";",
"return",
"$",
"this",
"->",
"renderAjax",
"(",
"'update'",
",",
"[",
"'model'",
"=>",
"$",
"model",
"]",
")",
";",
"}",
"$",
"collection",
"=",
"(",
"new",
"Collection",
"(",
"[",
"'model'",
"=>",
"$",
"this",
"->",
"newModel",
"(",
"[",
"'scenario'",
"=>",
"'update'",
"]",
")",
",",
"]",
")",
")",
"->",
"load",
"(",
")",
";",
"if",
"(",
"$",
"collection",
"->",
"first",
"->",
"id",
"&&",
"$",
"collection",
"->",
"save",
"(",
")",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"session",
"->",
"addFlash",
"(",
"'success'",
",",
"Yii",
"::",
"t",
"(",
"'hipanel:dns'",
",",
"'{0, plural, one{DNS record} other{# DNS records}} updated successfully'",
",",
"$",
"collection",
"->",
"count",
"(",
")",
")",
")",
";",
"return",
"$",
"this",
"->",
"renderZoneView",
"(",
"$",
"collection",
"->",
"first",
"->",
"hdomain_id",
")",
";",
"}",
"throw",
"new",
"BadRequestHttpException",
"(",
"'Bad request'",
")",
";",
"}"
] | Updates the DNS record.
@param integer $id
@param integer $hdomain_id
@throws BadRequestHttpException
@throws NotFoundHttpException
@return string | [
"Updates",
"the",
"DNS",
"record",
"."
] | 7e9199c95d91a979b7bd4fd07fe801dbe9e69183 | https://github.com/hiqdev/hipanel-module-dns/blob/7e9199c95d91a979b7bd4fd07fe801dbe9e69183/src/controllers/RecordController.php#L88-L106 |
35,572 | jormin/aliyun | sdk/aliyun-mq-http-php-sdk/MQClient.php | MQClient.getProducer | public function getProducer($instanceId, $topicName)
{
if ($topicName == NULL || $topicName == "") {
throw new InvalidArgumentException(400, "TopicName is null or empty");
}
return new MQProducer($this->client, $instanceId, $topicName);
} | php | public function getProducer($instanceId, $topicName)
{
if ($topicName == NULL || $topicName == "") {
throw new InvalidArgumentException(400, "TopicName is null or empty");
}
return new MQProducer($this->client, $instanceId, $topicName);
} | [
"public",
"function",
"getProducer",
"(",
"$",
"instanceId",
",",
"$",
"topicName",
")",
"{",
"if",
"(",
"$",
"topicName",
"==",
"NULL",
"||",
"$",
"topicName",
"==",
"\"\"",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"400",
",",
"\"TopicName is null or empty\"",
")",
";",
"}",
"return",
"new",
"MQProducer",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"instanceId",
",",
"$",
"topicName",
")",
";",
"}"
] | Returns a Producer reference for publish message to topic
@param string $instanceId: instance id
@param string $topicName: the topic name
@return MQProducer $topic: the Producer instance | [
"Returns",
"a",
"Producer",
"reference",
"for",
"publish",
"message",
"to",
"topic"
] | c0eb19f5c265dba1f463af1db7347acdcfddb240 | https://github.com/jormin/aliyun/blob/c0eb19f5c265dba1f463af1db7347acdcfddb240/sdk/aliyun-mq-http-php-sdk/MQClient.php#L46-L52 |
35,573 | jormin/aliyun | sdk/aliyun-mq-http-php-sdk/MQClient.php | MQClient.getConsumer | public function getConsumer($instanceId, $topicName, $consumer, $messageTag = NULL)
{
if ($topicName == NULL || $topicName == "") {
throw new InvalidArgumentException(400, "TopicName is null or empty");
}
if ($consumer == NULL || $consumer == "" ) {
throw new InvalidArgumentException(400, "Consumer is null or empty");
}
return new MQConsumer($this->client, $instanceId, $topicName, $consumer, $messageTag);
} | php | public function getConsumer($instanceId, $topicName, $consumer, $messageTag = NULL)
{
if ($topicName == NULL || $topicName == "") {
throw new InvalidArgumentException(400, "TopicName is null or empty");
}
if ($consumer == NULL || $consumer == "" ) {
throw new InvalidArgumentException(400, "Consumer is null or empty");
}
return new MQConsumer($this->client, $instanceId, $topicName, $consumer, $messageTag);
} | [
"public",
"function",
"getConsumer",
"(",
"$",
"instanceId",
",",
"$",
"topicName",
",",
"$",
"consumer",
",",
"$",
"messageTag",
"=",
"NULL",
")",
"{",
"if",
"(",
"$",
"topicName",
"==",
"NULL",
"||",
"$",
"topicName",
"==",
"\"\"",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"400",
",",
"\"TopicName is null or empty\"",
")",
";",
"}",
"if",
"(",
"$",
"consumer",
"==",
"NULL",
"||",
"$",
"consumer",
"==",
"\"\"",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"400",
",",
"\"Consumer is null or empty\"",
")",
";",
"}",
"return",
"new",
"MQConsumer",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"instanceId",
",",
"$",
"topicName",
",",
"$",
"consumer",
",",
"$",
"messageTag",
")",
";",
"}"
] | Returns a Consumer reference for consume and ack message to topic
@param string $instanceId: instance id
@param string $topicName: the topic name
@param string $consumer: the consumer name / ons cid
@param string $messageTag: filter tag for consumer. If not empty, only consume the message which's messageTag is equal to it.
@return MQConsumer $topic: the Producer instance | [
"Returns",
"a",
"Consumer",
"reference",
"for",
"consume",
"and",
"ack",
"message",
"to",
"topic"
] | c0eb19f5c265dba1f463af1db7347acdcfddb240 | https://github.com/jormin/aliyun/blob/c0eb19f5c265dba1f463af1db7347acdcfddb240/sdk/aliyun-mq-http-php-sdk/MQClient.php#L64-L73 |
35,574 | hail-framework/framework | src/I18n/Gettext/Utils/HeadersExtractorTrait.php | HeadersExtractorTrait.extractHeaders | private static function extractHeaders($headers, Translations $translations)
{
$headers = explode("\n", $headers);
$currentHeader = null;
foreach ($headers as $line) {
$line = self::convertString($line);
if ($line === '') {
continue;
}
if (self::isHeaderDefinition($line)) {
$header = \array_map('\trim', \explode(':', $line, 2));
$currentHeader = $header[0];
$translations->setHeader($currentHeader, $header[1]);
} else {
$entry = $translations->getHeader($currentHeader);
$translations->setHeader($currentHeader, $entry.$line);
}
}
} | php | private static function extractHeaders($headers, Translations $translations)
{
$headers = explode("\n", $headers);
$currentHeader = null;
foreach ($headers as $line) {
$line = self::convertString($line);
if ($line === '') {
continue;
}
if (self::isHeaderDefinition($line)) {
$header = \array_map('\trim', \explode(':', $line, 2));
$currentHeader = $header[0];
$translations->setHeader($currentHeader, $header[1]);
} else {
$entry = $translations->getHeader($currentHeader);
$translations->setHeader($currentHeader, $entry.$line);
}
}
} | [
"private",
"static",
"function",
"extractHeaders",
"(",
"$",
"headers",
",",
"Translations",
"$",
"translations",
")",
"{",
"$",
"headers",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"headers",
")",
";",
"$",
"currentHeader",
"=",
"null",
";",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"line",
")",
"{",
"$",
"line",
"=",
"self",
"::",
"convertString",
"(",
"$",
"line",
")",
";",
"if",
"(",
"$",
"line",
"===",
"''",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"self",
"::",
"isHeaderDefinition",
"(",
"$",
"line",
")",
")",
"{",
"$",
"header",
"=",
"\\",
"array_map",
"(",
"'\\trim'",
",",
"\\",
"explode",
"(",
"':'",
",",
"$",
"line",
",",
"2",
")",
")",
";",
"$",
"currentHeader",
"=",
"$",
"header",
"[",
"0",
"]",
";",
"$",
"translations",
"->",
"setHeader",
"(",
"$",
"currentHeader",
",",
"$",
"header",
"[",
"1",
"]",
")",
";",
"}",
"else",
"{",
"$",
"entry",
"=",
"$",
"translations",
"->",
"getHeader",
"(",
"$",
"currentHeader",
")",
";",
"$",
"translations",
"->",
"setHeader",
"(",
"$",
"currentHeader",
",",
"$",
"entry",
".",
"$",
"line",
")",
";",
"}",
"}",
"}"
] | Add the headers found to the translations instance.
@param string $headers
@param Translations $translations | [
"Add",
"the",
"headers",
"found",
"to",
"the",
"translations",
"instance",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/I18n/Gettext/Utils/HeadersExtractorTrait.php#L18-L39 |
35,575 | mcrumm/pecan | src/Console/Output/ConsoleOutput.php | ConsoleOutput.once | public function once($event, callable $listener)
{
parent::once($event, $listener);
$this->stderr->once($event, $listener);
} | php | public function once($event, callable $listener)
{
parent::once($event, $listener);
$this->stderr->once($event, $listener);
} | [
"public",
"function",
"once",
"(",
"$",
"event",
",",
"callable",
"$",
"listener",
")",
"{",
"parent",
"::",
"once",
"(",
"$",
"event",
",",
"$",
"listener",
")",
";",
"$",
"this",
"->",
"stderr",
"->",
"once",
"(",
"$",
"event",
",",
"$",
"listener",
")",
";",
"}"
] | Helper method to proxy event listeners to the wrapped stream.
@param $event
@param callable $listener | [
"Helper",
"method",
"to",
"proxy",
"event",
"listeners",
"to",
"the",
"wrapped",
"stream",
"."
] | f35f01249587a4df45c7d3ab78f3e51919471177 | https://github.com/mcrumm/pecan/blob/f35f01249587a4df45c7d3ab78f3e51919471177/src/Console/Output/ConsoleOutput.php#L62-L66 |
35,576 | jormin/aliyun | sdk/aliyun-mns-php-sdk/AliyunMNS/Client.php | Client.getAccountAttributes | public function getAccountAttributes()
{
$request = new GetAccountAttributesRequest();
$response = new GetAccountAttributesResponse();
return $this->client->sendRequest($request, $response);
} | php | public function getAccountAttributes()
{
$request = new GetAccountAttributesRequest();
$response = new GetAccountAttributesResponse();
return $this->client->sendRequest($request, $response);
} | [
"public",
"function",
"getAccountAttributes",
"(",
")",
"{",
"$",
"request",
"=",
"new",
"GetAccountAttributesRequest",
"(",
")",
";",
"$",
"response",
"=",
"new",
"GetAccountAttributesResponse",
"(",
")",
";",
"return",
"$",
"this",
"->",
"client",
"->",
"sendRequest",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"}"
] | Query the AccountAttributes
@return GetAccountAttributesResponse: the response containing topicNames
@throws MnsException if any exception happends | [
"Query",
"the",
"AccountAttributes"
] | c0eb19f5c265dba1f463af1db7347acdcfddb240 | https://github.com/jormin/aliyun/blob/c0eb19f5c265dba1f463af1db7347acdcfddb240/sdk/aliyun-mns-php-sdk/AliyunMNS/Client.php#L210-L215 |
35,577 | jormin/aliyun | sdk/aliyun-mns-php-sdk/AliyunMNS/Client.php | Client.setAccountAttributes | public function setAccountAttributes(AccountAttributes $attributes)
{
$request = new SetAccountAttributesRequest($attributes);
$response = new SetAccountAttributesResponse();
return $this->client->sendRequest($request, $response);
} | php | public function setAccountAttributes(AccountAttributes $attributes)
{
$request = new SetAccountAttributesRequest($attributes);
$response = new SetAccountAttributesResponse();
return $this->client->sendRequest($request, $response);
} | [
"public",
"function",
"setAccountAttributes",
"(",
"AccountAttributes",
"$",
"attributes",
")",
"{",
"$",
"request",
"=",
"new",
"SetAccountAttributesRequest",
"(",
"$",
"attributes",
")",
";",
"$",
"response",
"=",
"new",
"SetAccountAttributesResponse",
"(",
")",
";",
"return",
"$",
"this",
"->",
"client",
"->",
"sendRequest",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"}"
] | Set the AccountAttributes
@param AccountAttributes $attributes: the AccountAttributes to set
@return SetAccountAttributesResponse: the response
@throws MnsException if any exception happends | [
"Set",
"the",
"AccountAttributes"
] | c0eb19f5c265dba1f463af1db7347acdcfddb240 | https://github.com/jormin/aliyun/blob/c0eb19f5c265dba1f463af1db7347acdcfddb240/sdk/aliyun-mns-php-sdk/AliyunMNS/Client.php#L233-L238 |
35,578 | hail-framework/framework | src/I18n/Gettext/Translation.php | Translation.getPluralTranslations | public function getPluralTranslations($size = null)
{
if ($size === null) {
return $this->pluralTranslation;
}
$current = \count($this->pluralTranslation);
if ($size > $current) {
return $this->pluralTranslation + \array_fill(0, $size, '');
}
if ($size < $current) {
return \array_slice($this->pluralTranslation, 0, $size);
}
return $this->pluralTranslation;
} | php | public function getPluralTranslations($size = null)
{
if ($size === null) {
return $this->pluralTranslation;
}
$current = \count($this->pluralTranslation);
if ($size > $current) {
return $this->pluralTranslation + \array_fill(0, $size, '');
}
if ($size < $current) {
return \array_slice($this->pluralTranslation, 0, $size);
}
return $this->pluralTranslation;
} | [
"public",
"function",
"getPluralTranslations",
"(",
"$",
"size",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"size",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"pluralTranslation",
";",
"}",
"$",
"current",
"=",
"\\",
"count",
"(",
"$",
"this",
"->",
"pluralTranslation",
")",
";",
"if",
"(",
"$",
"size",
">",
"$",
"current",
")",
"{",
"return",
"$",
"this",
"->",
"pluralTranslation",
"+",
"\\",
"array_fill",
"(",
"0",
",",
"$",
"size",
",",
"''",
")",
";",
"}",
"if",
"(",
"$",
"size",
"<",
"$",
"current",
")",
"{",
"return",
"\\",
"array_slice",
"(",
"$",
"this",
"->",
"pluralTranslation",
",",
"0",
",",
"$",
"size",
")",
";",
"}",
"return",
"$",
"this",
"->",
"pluralTranslation",
";",
"}"
] | Gets all plural translations.
@param int $size
@return array | [
"Gets",
"all",
"plural",
"translations",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/I18n/Gettext/Translation.php#L228-L245 |
35,579 | hail-framework/framework | src/I18n/Gettext/Translation.php | Translation.hasPluralTranslations | public function hasPluralTranslations($checkContent = false)
{
if ($checkContent) {
return \implode('', $this->pluralTranslation) !== '';
}
return !empty($this->pluralTranslation);
} | php | public function hasPluralTranslations($checkContent = false)
{
if ($checkContent) {
return \implode('', $this->pluralTranslation) !== '';
}
return !empty($this->pluralTranslation);
} | [
"public",
"function",
"hasPluralTranslations",
"(",
"$",
"checkContent",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"checkContent",
")",
"{",
"return",
"\\",
"implode",
"(",
"''",
",",
"$",
"this",
"->",
"pluralTranslation",
")",
"!==",
"''",
";",
"}",
"return",
"!",
"empty",
"(",
"$",
"this",
"->",
"pluralTranslation",
")",
";",
"}"
] | Checks if there are any plural translation.
@param bool $checkContent
@return bool | [
"Checks",
"if",
"there",
"are",
"any",
"plural",
"translation",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/I18n/Gettext/Translation.php#L254-L261 |
35,580 | hail-framework/framework | src/I18n/Gettext/Translation.php | Translation.addExtractedComment | public function addExtractedComment($comment)
{
if (!\in_array($comment, $this->extractedComments, true)) {
$this->extractedComments[] = $comment;
}
return $this;
} | php | public function addExtractedComment($comment)
{
if (!\in_array($comment, $this->extractedComments, true)) {
$this->extractedComments[] = $comment;
}
return $this;
} | [
"public",
"function",
"addExtractedComment",
"(",
"$",
"comment",
")",
"{",
"if",
"(",
"!",
"\\",
"in_array",
"(",
"$",
"comment",
",",
"$",
"this",
"->",
"extractedComments",
",",
"true",
")",
")",
"{",
"$",
"this",
"->",
"extractedComments",
"[",
"]",
"=",
"$",
"comment",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Adds a new extracted comment for this translation.
@param string $comment
@return self | [
"Adds",
"a",
"new",
"extracted",
"comment",
"for",
"this",
"translation",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/I18n/Gettext/Translation.php#L398-L405 |
35,581 | htmlburger/wpemerge-cli | src/Helpers/Boolean.php | Boolean.fromString | public static function fromString( $string ) {
$values = [
'1' => true,
'y' => true,
'yes' => true,
'true' => true,
'0' => false,
'n' => false,
'no' => false,
'false' => false,
];
foreach ( $values as $value => $boolean ) {
if ( strtolower( $value ) === strtolower( $string ) ) {
return $boolean;
}
}
// rely on PHP's string to boolean conversion in all other cases
return (bool) $string;
} | php | public static function fromString( $string ) {
$values = [
'1' => true,
'y' => true,
'yes' => true,
'true' => true,
'0' => false,
'n' => false,
'no' => false,
'false' => false,
];
foreach ( $values as $value => $boolean ) {
if ( strtolower( $value ) === strtolower( $string ) ) {
return $boolean;
}
}
// rely on PHP's string to boolean conversion in all other cases
return (bool) $string;
} | [
"public",
"static",
"function",
"fromString",
"(",
"$",
"string",
")",
"{",
"$",
"values",
"=",
"[",
"'1'",
"=>",
"true",
",",
"'y'",
"=>",
"true",
",",
"'yes'",
"=>",
"true",
",",
"'true'",
"=>",
"true",
",",
"'0'",
"=>",
"false",
",",
"'n'",
"=>",
"false",
",",
"'no'",
"=>",
"false",
",",
"'false'",
"=>",
"false",
",",
"]",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
"=>",
"$",
"boolean",
")",
"{",
"if",
"(",
"strtolower",
"(",
"$",
"value",
")",
"===",
"strtolower",
"(",
"$",
"string",
")",
")",
"{",
"return",
"$",
"boolean",
";",
"}",
"}",
"// rely on PHP's string to boolean conversion in all other cases",
"return",
"(",
"bool",
")",
"$",
"string",
";",
"}"
] | Convert a string to boolean
@param string $string
@return boolean | [
"Convert",
"a",
"string",
"to",
"boolean"
] | 075f1982b7dd87039a4e7bbc05caf676a10fe862 | https://github.com/htmlburger/wpemerge-cli/blob/075f1982b7dd87039a4e7bbc05caf676a10fe862/src/Helpers/Boolean.php#L12-L33 |
35,582 | cfxmarkets/php-public-models | src/Brokerage/OrderIntent.php | OrderIntent.serializeAttribute | public function serializeAttribute($name)
{
if ($name === 'createdOn') {
$val = $this->getCreatedOn();
if ($val instanceof \DateTimeInterface) {
$val = $val->format("Y-m-d H:i:s");
}
return (string)$val;
}
return parent::serializeAttribute($name);
} | php | public function serializeAttribute($name)
{
if ($name === 'createdOn') {
$val = $this->getCreatedOn();
if ($val instanceof \DateTimeInterface) {
$val = $val->format("Y-m-d H:i:s");
}
return (string)$val;
}
return parent::serializeAttribute($name);
} | [
"public",
"function",
"serializeAttribute",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"name",
"===",
"'createdOn'",
")",
"{",
"$",
"val",
"=",
"$",
"this",
"->",
"getCreatedOn",
"(",
")",
";",
"if",
"(",
"$",
"val",
"instanceof",
"\\",
"DateTimeInterface",
")",
"{",
"$",
"val",
"=",
"$",
"val",
"->",
"format",
"(",
"\"Y-m-d H:i:s\"",
")",
";",
"}",
"return",
"(",
"string",
")",
"$",
"val",
";",
"}",
"return",
"parent",
"::",
"serializeAttribute",
"(",
"$",
"name",
")",
";",
"}"
] | Serialize createdOn field to a value that SQL understands
We have to do this here because when order intents are serialized that already have a createdOn date
set, they end up sending malformed data to the API. This is because \DateTime actually does implement
jsonSerialize, but in a way that breaks our implementation. | [
"Serialize",
"createdOn",
"field",
"to",
"a",
"value",
"that",
"SQL",
"understands"
] | b91a58f7d9519b98b29c58f0911e976e361a5f65 | https://github.com/cfxmarkets/php-public-models/blob/b91a58f7d9519b98b29c58f0911e976e361a5f65/src/Brokerage/OrderIntent.php#L448-L458 |
35,583 | hail-framework/framework | src/Util/Crypto.php | Crypto.encrypt | public static function encrypt(
string $plaintext,
string $key,
string $ad = '',
string $format = null,
bool $password = false
): string {
if (\mb_strlen($key, '8bit') !== self::KEY_BYTE_SIZE) {
throw new CryptoException('Bad key length.');
}
$salt = \random_bytes(self::SALT_BYTE_SIZE);
[$authKey, $encryptKey] = self::deriveKeys($key, $salt, $password);
$iv = \random_bytes(self::BLOCK_BYTE_SIZE);
$ad = self::getAd($ad);
$tag = '';
if (self::$sodium) {
$cipherText = \sodium_crypto_aead_aes256gcm_encrypt($plaintext, $ad, $iv, $encryptKey);
} else {
$cipherText = \openssl_encrypt(
$plaintext,
self::CIPHER_METHOD,
$encryptKey,
\OPENSSL_RAW_DATA,
$iv, $tag, $ad
);
}
if ($cipherText === false) {
throw new CryptoException('Encrypt failed.');
}
$cipherText = self::CURRENT_VERSION . $salt . $iv . $cipherText . $tag;
$auth = \hash_hmac(self::HASH_TYPE, $cipherText, $authKey, true);
$cipherText .= $auth;
return self::fromRaw($cipherText, $format);
} | php | public static function encrypt(
string $plaintext,
string $key,
string $ad = '',
string $format = null,
bool $password = false
): string {
if (\mb_strlen($key, '8bit') !== self::KEY_BYTE_SIZE) {
throw new CryptoException('Bad key length.');
}
$salt = \random_bytes(self::SALT_BYTE_SIZE);
[$authKey, $encryptKey] = self::deriveKeys($key, $salt, $password);
$iv = \random_bytes(self::BLOCK_BYTE_SIZE);
$ad = self::getAd($ad);
$tag = '';
if (self::$sodium) {
$cipherText = \sodium_crypto_aead_aes256gcm_encrypt($plaintext, $ad, $iv, $encryptKey);
} else {
$cipherText = \openssl_encrypt(
$plaintext,
self::CIPHER_METHOD,
$encryptKey,
\OPENSSL_RAW_DATA,
$iv, $tag, $ad
);
}
if ($cipherText === false) {
throw new CryptoException('Encrypt failed.');
}
$cipherText = self::CURRENT_VERSION . $salt . $iv . $cipherText . $tag;
$auth = \hash_hmac(self::HASH_TYPE, $cipherText, $authKey, true);
$cipherText .= $auth;
return self::fromRaw($cipherText, $format);
} | [
"public",
"static",
"function",
"encrypt",
"(",
"string",
"$",
"plaintext",
",",
"string",
"$",
"key",
",",
"string",
"$",
"ad",
"=",
"''",
",",
"string",
"$",
"format",
"=",
"null",
",",
"bool",
"$",
"password",
"=",
"false",
")",
":",
"string",
"{",
"if",
"(",
"\\",
"mb_strlen",
"(",
"$",
"key",
",",
"'8bit'",
")",
"!==",
"self",
"::",
"KEY_BYTE_SIZE",
")",
"{",
"throw",
"new",
"CryptoException",
"(",
"'Bad key length.'",
")",
";",
"}",
"$",
"salt",
"=",
"\\",
"random_bytes",
"(",
"self",
"::",
"SALT_BYTE_SIZE",
")",
";",
"[",
"$",
"authKey",
",",
"$",
"encryptKey",
"]",
"=",
"self",
"::",
"deriveKeys",
"(",
"$",
"key",
",",
"$",
"salt",
",",
"$",
"password",
")",
";",
"$",
"iv",
"=",
"\\",
"random_bytes",
"(",
"self",
"::",
"BLOCK_BYTE_SIZE",
")",
";",
"$",
"ad",
"=",
"self",
"::",
"getAd",
"(",
"$",
"ad",
")",
";",
"$",
"tag",
"=",
"''",
";",
"if",
"(",
"self",
"::",
"$",
"sodium",
")",
"{",
"$",
"cipherText",
"=",
"\\",
"sodium_crypto_aead_aes256gcm_encrypt",
"(",
"$",
"plaintext",
",",
"$",
"ad",
",",
"$",
"iv",
",",
"$",
"encryptKey",
")",
";",
"}",
"else",
"{",
"$",
"cipherText",
"=",
"\\",
"openssl_encrypt",
"(",
"$",
"plaintext",
",",
"self",
"::",
"CIPHER_METHOD",
",",
"$",
"encryptKey",
",",
"\\",
"OPENSSL_RAW_DATA",
",",
"$",
"iv",
",",
"$",
"tag",
",",
"$",
"ad",
")",
";",
"}",
"if",
"(",
"$",
"cipherText",
"===",
"false",
")",
"{",
"throw",
"new",
"CryptoException",
"(",
"'Encrypt failed.'",
")",
";",
"}",
"$",
"cipherText",
"=",
"self",
"::",
"CURRENT_VERSION",
".",
"$",
"salt",
".",
"$",
"iv",
".",
"$",
"cipherText",
".",
"$",
"tag",
";",
"$",
"auth",
"=",
"\\",
"hash_hmac",
"(",
"self",
"::",
"HASH_TYPE",
",",
"$",
"cipherText",
",",
"$",
"authKey",
",",
"true",
")",
";",
"$",
"cipherText",
".=",
"$",
"auth",
";",
"return",
"self",
"::",
"fromRaw",
"(",
"$",
"cipherText",
",",
"$",
"format",
")",
";",
"}"
] | Encrypts a string with a Key.
@param string $plaintext
@param string $key
@param string $ad
@param string $format
@param bool $password
@throws CryptoException
@return string
@throws \Exception | [
"Encrypts",
"a",
"string",
"with",
"a",
"Key",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Crypto.php#L204-L245 |
35,584 | hail-framework/framework | src/Util/Crypto.php | Crypto.encryptWithPassword | public static function encryptWithPassword(
string $plaintext,
string $password,
string $ad = '',
string $format = null
): string {
return self::encrypt($plaintext, $password, $ad, $format, true);
} | php | public static function encryptWithPassword(
string $plaintext,
string $password,
string $ad = '',
string $format = null
): string {
return self::encrypt($plaintext, $password, $ad, $format, true);
} | [
"public",
"static",
"function",
"encryptWithPassword",
"(",
"string",
"$",
"plaintext",
",",
"string",
"$",
"password",
",",
"string",
"$",
"ad",
"=",
"''",
",",
"string",
"$",
"format",
"=",
"null",
")",
":",
"string",
"{",
"return",
"self",
"::",
"encrypt",
"(",
"$",
"plaintext",
",",
"$",
"password",
",",
"$",
"ad",
",",
"$",
"format",
",",
"true",
")",
";",
"}"
] | Encrypts a string with a password, using a slow key derivation function
to make password cracking more expensive.
@param string $plaintext
@param string $password
@param string $ad
@param string $format
@throws \Exception
@return string | [
"Encrypts",
"a",
"string",
"with",
"a",
"password",
"using",
"a",
"slow",
"key",
"derivation",
"function",
"to",
"make",
"password",
"cracking",
"more",
"expensive",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Crypto.php#L260-L267 |
35,585 | hail-framework/framework | src/Util/Crypto.php | Crypto.decryptWithPassword | public static function decryptWithPassword(
string $cipherText,
string $password,
string $ad = '',
string $format = null
): string {
return self::decrypt($cipherText, $password, $ad, $format, true);
} | php | public static function decryptWithPassword(
string $cipherText,
string $password,
string $ad = '',
string $format = null
): string {
return self::decrypt($cipherText, $password, $ad, $format, true);
} | [
"public",
"static",
"function",
"decryptWithPassword",
"(",
"string",
"$",
"cipherText",
",",
"string",
"$",
"password",
",",
"string",
"$",
"ad",
"=",
"''",
",",
"string",
"$",
"format",
"=",
"null",
")",
":",
"string",
"{",
"return",
"self",
"::",
"decrypt",
"(",
"$",
"cipherText",
",",
"$",
"password",
",",
"$",
"ad",
",",
"$",
"format",
",",
"true",
")",
";",
"}"
] | Decrypts a ciphertext to a string with a password, using a slow key
derivation function to make password cracking more expensive.
@param string $cipherText
@param string $password
@param string $ad
@param string $format
@throws CryptoException
@return string | [
"Decrypts",
"a",
"ciphertext",
"to",
"a",
"string",
"with",
"a",
"password",
"using",
"a",
"slow",
"key",
"derivation",
"function",
"to",
"make",
"password",
"cracking",
"more",
"expensive",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Crypto.php#L396-L403 |
35,586 | hail-framework/framework | src/Util/Crypto.php | Crypto.deriveKeys | private static function deriveKeys(string $key, string $salt, bool $password = false)
{
if ($password) {
$preHash = \hash(self::HASH_TYPE, $key, true);
$key = self::pbkdf2(
self::HASH_TYPE,
$preHash,
$salt,
self::PBKDF2_ITERATIONS,
self::KEY_BYTE_SIZE,
true
);
}
$authKey = self::hkdf(
self::HASH_TYPE,
$key,
self::KEY_BYTE_SIZE,
self::AUTHENTICATION_INFO_STRING,
$salt
);
$encryptKey = self::hkdf(
self::HASH_TYPE,
$key,
self::KEY_BYTE_SIZE,
self::ENCRYPTION_INFO_STRING,
$salt
);
return [$authKey, $encryptKey];
} | php | private static function deriveKeys(string $key, string $salt, bool $password = false)
{
if ($password) {
$preHash = \hash(self::HASH_TYPE, $key, true);
$key = self::pbkdf2(
self::HASH_TYPE,
$preHash,
$salt,
self::PBKDF2_ITERATIONS,
self::KEY_BYTE_SIZE,
true
);
}
$authKey = self::hkdf(
self::HASH_TYPE,
$key,
self::KEY_BYTE_SIZE,
self::AUTHENTICATION_INFO_STRING,
$salt
);
$encryptKey = self::hkdf(
self::HASH_TYPE,
$key,
self::KEY_BYTE_SIZE,
self::ENCRYPTION_INFO_STRING,
$salt
);
return [$authKey, $encryptKey];
} | [
"private",
"static",
"function",
"deriveKeys",
"(",
"string",
"$",
"key",
",",
"string",
"$",
"salt",
",",
"bool",
"$",
"password",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"password",
")",
"{",
"$",
"preHash",
"=",
"\\",
"hash",
"(",
"self",
"::",
"HASH_TYPE",
",",
"$",
"key",
",",
"true",
")",
";",
"$",
"key",
"=",
"self",
"::",
"pbkdf2",
"(",
"self",
"::",
"HASH_TYPE",
",",
"$",
"preHash",
",",
"$",
"salt",
",",
"self",
"::",
"PBKDF2_ITERATIONS",
",",
"self",
"::",
"KEY_BYTE_SIZE",
",",
"true",
")",
";",
"}",
"$",
"authKey",
"=",
"self",
"::",
"hkdf",
"(",
"self",
"::",
"HASH_TYPE",
",",
"$",
"key",
",",
"self",
"::",
"KEY_BYTE_SIZE",
",",
"self",
"::",
"AUTHENTICATION_INFO_STRING",
",",
"$",
"salt",
")",
";",
"$",
"encryptKey",
"=",
"self",
"::",
"hkdf",
"(",
"self",
"::",
"HASH_TYPE",
",",
"$",
"key",
",",
"self",
"::",
"KEY_BYTE_SIZE",
",",
"self",
"::",
"ENCRYPTION_INFO_STRING",
",",
"$",
"salt",
")",
";",
"return",
"[",
"$",
"authKey",
",",
"$",
"encryptKey",
"]",
";",
"}"
] | Derives authentication and encryption keys from the secret, using a slow
key derivation function if the secret is a password.
@param string $key
@param string $salt
@param bool $password
@throws CryptoException
@return array | [
"Derives",
"authentication",
"and",
"encryption",
"keys",
"from",
"the",
"secret",
"using",
"a",
"slow",
"key",
"derivation",
"function",
"if",
"the",
"secret",
"is",
"a",
"password",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Crypto.php#L425-L456 |
35,587 | hail-framework/framework | src/Util/Crypto.php | Crypto.pbkdf2 | public static function pbkdf2(
string $algorithm,
string $password,
string $salt,
int $count,
int $length,
bool $raw = false
) {
$algorithm = \strtolower($algorithm);
// Whitelist, or we could end up with people using CRC32.
if (!isset(self::$hashList[$algorithm])) {
throw new CryptoException('Algorithm is not a secure cryptographic hash function.');
}
if ($count <= 0 || $length <= 0) {
throw new CryptoException('Invalid PBKDF2 parameters.');
}
// The output length is in NIBBLES (4-bits) if $raw_output is false!
if (!$raw) {
$length *= 2;
}
return \hash_pbkdf2($algorithm, $password, $salt, $count, $length, $raw);
} | php | public static function pbkdf2(
string $algorithm,
string $password,
string $salt,
int $count,
int $length,
bool $raw = false
) {
$algorithm = \strtolower($algorithm);
// Whitelist, or we could end up with people using CRC32.
if (!isset(self::$hashList[$algorithm])) {
throw new CryptoException('Algorithm is not a secure cryptographic hash function.');
}
if ($count <= 0 || $length <= 0) {
throw new CryptoException('Invalid PBKDF2 parameters.');
}
// The output length is in NIBBLES (4-bits) if $raw_output is false!
if (!$raw) {
$length *= 2;
}
return \hash_pbkdf2($algorithm, $password, $salt, $count, $length, $raw);
} | [
"public",
"static",
"function",
"pbkdf2",
"(",
"string",
"$",
"algorithm",
",",
"string",
"$",
"password",
",",
"string",
"$",
"salt",
",",
"int",
"$",
"count",
",",
"int",
"$",
"length",
",",
"bool",
"$",
"raw",
"=",
"false",
")",
"{",
"$",
"algorithm",
"=",
"\\",
"strtolower",
"(",
"$",
"algorithm",
")",
";",
"// Whitelist, or we could end up with people using CRC32.",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"hashList",
"[",
"$",
"algorithm",
"]",
")",
")",
"{",
"throw",
"new",
"CryptoException",
"(",
"'Algorithm is not a secure cryptographic hash function.'",
")",
";",
"}",
"if",
"(",
"$",
"count",
"<=",
"0",
"||",
"$",
"length",
"<=",
"0",
")",
"{",
"throw",
"new",
"CryptoException",
"(",
"'Invalid PBKDF2 parameters.'",
")",
";",
"}",
"// The output length is in NIBBLES (4-bits) if $raw_output is false!",
"if",
"(",
"!",
"$",
"raw",
")",
"{",
"$",
"length",
"*=",
"2",
";",
"}",
"return",
"\\",
"hash_pbkdf2",
"(",
"$",
"algorithm",
",",
"$",
"password",
",",
"$",
"salt",
",",
"$",
"count",
",",
"$",
"length",
",",
"$",
"raw",
")",
";",
"}"
] | Computes the PBKDF2 password-based key derivation function.
The PBKDF2 function is defined in RFC 2898. Test vectors can be found in
RFC 6070. This implementation of PBKDF2 was originally created by Taylor
Hornby, with improvements from http://www.variations-of-shadow.com/.
@param string $algorithm The hash algorithm to use. Recommended: SHA256
@param string $password The password.
@param string $salt A salt that is unique to the password.
@param int $count Iteration count. Higher is better, but slower. Recommended: At least 1000.
@param int $length The length of the derived key in bytes.
@param bool $raw If true, the key is returned in raw binary format. Hex encoded otherwise.
@throws CryptoException
@return string A $key_length-byte key derived from the password and salt. | [
"Computes",
"the",
"PBKDF2",
"password",
"-",
"based",
"key",
"derivation",
"function",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Crypto.php#L581-L605 |
35,588 | hiqdev/hipanel-module-server | src/models/Consumption.php | Consumption.getTypeLabel | public function getTypeLabel(): string
{
$provider = Yii::createObject(BillTypesProvider::class);
$types = ArrayHelper::index($provider->getTypes(), 'name');
if (!isset($types[$this->type])) {
return '--';
}
return $types[$this->type]->label;
} | php | public function getTypeLabel(): string
{
$provider = Yii::createObject(BillTypesProvider::class);
$types = ArrayHelper::index($provider->getTypes(), 'name');
if (!isset($types[$this->type])) {
return '--';
}
return $types[$this->type]->label;
} | [
"public",
"function",
"getTypeLabel",
"(",
")",
":",
"string",
"{",
"$",
"provider",
"=",
"Yii",
"::",
"createObject",
"(",
"BillTypesProvider",
"::",
"class",
")",
";",
"$",
"types",
"=",
"ArrayHelper",
"::",
"index",
"(",
"$",
"provider",
"->",
"getTypes",
"(",
")",
",",
"'name'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"types",
"[",
"$",
"this",
"->",
"type",
"]",
")",
")",
"{",
"return",
"'--'",
";",
"}",
"return",
"$",
"types",
"[",
"$",
"this",
"->",
"type",
"]",
"->",
"label",
";",
"}"
] | Get type label.
@throws \yii\base\InvalidConfigException
@return string | [
"Get",
"type",
"label",
"."
] | e40c3601952cf1fd420ebb97093ee17a33ff3207 | https://github.com/hiqdev/hipanel-module-server/blob/e40c3601952cf1fd420ebb97093ee17a33ff3207/src/models/Consumption.php#L51-L60 |
35,589 | byjg/webrequest | src/WebRequest.php | WebRequest.setCredentials | public function setCredentials($username, $password)
{
$this->setCurlOption(CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$this->setCurlOption(CURLOPT_USERPWD, $username . ":" . $password);
} | php | public function setCredentials($username, $password)
{
$this->setCurlOption(CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$this->setCurlOption(CURLOPT_USERPWD, $username . ":" . $password);
} | [
"public",
"function",
"setCredentials",
"(",
"$",
"username",
",",
"$",
"password",
")",
"{",
"$",
"this",
"->",
"setCurlOption",
"(",
"CURLOPT_HTTPAUTH",
",",
"CURLAUTH_BASIC",
")",
";",
"$",
"this",
"->",
"setCurlOption",
"(",
"CURLOPT_USERPWD",
",",
"$",
"username",
".",
"\":\"",
".",
"$",
"password",
")",
";",
"}"
] | Defines Basic credentials for access the service.
@param string $username
@param string $password | [
"Defines",
"Basic",
"credentials",
"for",
"access",
"the",
"service",
"."
] | 779045160a8ca88044ab41a00d30c4dc6201b619 | https://github.com/byjg/webrequest/blob/779045160a8ca88044ab41a00d30c4dc6201b619/src/WebRequest.php#L53-L57 |
35,590 | byjg/webrequest | src/WebRequest.php | WebRequest.setProxy | public function setProxy($url, $username = null, $password = "")
{
$this->setCurlOption(CURLOPT_PROXY, $url);
if (!is_null($username)) {
$this->setCurlOption(CURLOPT_PROXYUSERPWD, "$username:$password");
}
} | php | public function setProxy($url, $username = null, $password = "")
{
$this->setCurlOption(CURLOPT_PROXY, $url);
if (!is_null($username)) {
$this->setCurlOption(CURLOPT_PROXYUSERPWD, "$username:$password");
}
} | [
"public",
"function",
"setProxy",
"(",
"$",
"url",
",",
"$",
"username",
"=",
"null",
",",
"$",
"password",
"=",
"\"\"",
")",
"{",
"$",
"this",
"->",
"setCurlOption",
"(",
"CURLOPT_PROXY",
",",
"$",
"url",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"username",
")",
")",
"{",
"$",
"this",
"->",
"setCurlOption",
"(",
"CURLOPT_PROXYUSERPWD",
",",
"\"$username:$password\"",
")",
";",
"}",
"}"
] | Setting the Proxy
The full representation of the proxy is scheme://url:port,
but the only required is the URL;
Some examples:
my.proxy.com
my.proxy.com:1080
https://my.proxy.com:1080
socks4://my.proxysocks.com
socks5://my.proxysocks.com
@param string $url The Proxy URL in the format scheme://url:port
@param string $username
@param string $password | [
"Setting",
"the",
"Proxy"
] | 779045160a8ca88044ab41a00d30c4dc6201b619 | https://github.com/byjg/webrequest/blob/779045160a8ca88044ab41a00d30c4dc6201b619/src/WebRequest.php#L193-L199 |
35,591 | byjg/webrequest | src/WebRequest.php | WebRequest.soapCall | public function soapCall($method, $params = null, $soapOptions = null)
{
$soapParams = null;
if (is_array($params)) {
$soapParams = array();
foreach ($params as $key => $value) {
$soapParams[] = new SoapParam($value, $key);
}
}
if (!is_array($soapOptions) || (is_null($soapOptions))) {
$soapOptions = array(
"uri" => "urn:xmethods-delayed-quotes",
"soapaction" => "urn:xmethods-delayed-quotes#getQuote"
);
}
// Chamando método do webservice
$result = $this->getSoapClient()->__soapCall(
$method,
$soapParams,
$soapOptions
);
return $result;
} | php | public function soapCall($method, $params = null, $soapOptions = null)
{
$soapParams = null;
if (is_array($params)) {
$soapParams = array();
foreach ($params as $key => $value) {
$soapParams[] = new SoapParam($value, $key);
}
}
if (!is_array($soapOptions) || (is_null($soapOptions))) {
$soapOptions = array(
"uri" => "urn:xmethods-delayed-quotes",
"soapaction" => "urn:xmethods-delayed-quotes#getQuote"
);
}
// Chamando método do webservice
$result = $this->getSoapClient()->__soapCall(
$method,
$soapParams,
$soapOptions
);
return $result;
} | [
"public",
"function",
"soapCall",
"(",
"$",
"method",
",",
"$",
"params",
"=",
"null",
",",
"$",
"soapOptions",
"=",
"null",
")",
"{",
"$",
"soapParams",
"=",
"null",
";",
"if",
"(",
"is_array",
"(",
"$",
"params",
")",
")",
"{",
"$",
"soapParams",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"soapParams",
"[",
"]",
"=",
"new",
"SoapParam",
"(",
"$",
"value",
",",
"$",
"key",
")",
";",
"}",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"soapOptions",
")",
"||",
"(",
"is_null",
"(",
"$",
"soapOptions",
")",
")",
")",
"{",
"$",
"soapOptions",
"=",
"array",
"(",
"\"uri\"",
"=>",
"\"urn:xmethods-delayed-quotes\"",
",",
"\"soapaction\"",
"=>",
"\"urn:xmethods-delayed-quotes#getQuote\"",
")",
";",
"}",
"// Chamando método do webservice",
"$",
"result",
"=",
"$",
"this",
"->",
"getSoapClient",
"(",
")",
"->",
"__soapCall",
"(",
"$",
"method",
",",
"$",
"soapParams",
",",
"$",
"soapOptions",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Call a Soap client.
For example:
$webreq = new WebRequest("http://www.byjg.com.br/webservice.php/ws/cep");
$result = $webreq->soapCall("obterCep", new array("cep", "11111233"));
@param string $method
@param array $params
@param array $soapOptions
@return string | [
"Call",
"a",
"Soap",
"client",
"."
] | 779045160a8ca88044ab41a00d30c4dc6201b619 | https://github.com/byjg/webrequest/blob/779045160a8ca88044ab41a00d30c4dc6201b619/src/WebRequest.php#L244-L270 |
35,592 | byjg/webrequest | src/WebRequest.php | WebRequest.defaultCurlOptions | protected function defaultCurlOptions()
{
$this->curlOptions[CURLOPT_CONNECTTIMEOUT] = 30;
$this->curlOptions[CURLOPT_TIMEOUT] = 30;
$this->curlOptions[CURLOPT_HEADER] = true;
$this->curlOptions[CURLOPT_RETURNTRANSFER] = true;
$this->curlOptions[CURLOPT_USERAGENT] = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
$this->curlOptions[CURLOPT_FOLLOWLOCATION] = true;
$this->curlOptions[CURLOPT_SSL_VERIFYHOST] = false;
$this->curlOptions[CURLOPT_SSL_VERIFYPEER] = false;
} | php | protected function defaultCurlOptions()
{
$this->curlOptions[CURLOPT_CONNECTTIMEOUT] = 30;
$this->curlOptions[CURLOPT_TIMEOUT] = 30;
$this->curlOptions[CURLOPT_HEADER] = true;
$this->curlOptions[CURLOPT_RETURNTRANSFER] = true;
$this->curlOptions[CURLOPT_USERAGENT] = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
$this->curlOptions[CURLOPT_FOLLOWLOCATION] = true;
$this->curlOptions[CURLOPT_SSL_VERIFYHOST] = false;
$this->curlOptions[CURLOPT_SSL_VERIFYPEER] = false;
} | [
"protected",
"function",
"defaultCurlOptions",
"(",
")",
"{",
"$",
"this",
"->",
"curlOptions",
"[",
"CURLOPT_CONNECTTIMEOUT",
"]",
"=",
"30",
";",
"$",
"this",
"->",
"curlOptions",
"[",
"CURLOPT_TIMEOUT",
"]",
"=",
"30",
";",
"$",
"this",
"->",
"curlOptions",
"[",
"CURLOPT_HEADER",
"]",
"=",
"true",
";",
"$",
"this",
"->",
"curlOptions",
"[",
"CURLOPT_RETURNTRANSFER",
"]",
"=",
"true",
";",
"$",
"this",
"->",
"curlOptions",
"[",
"CURLOPT_USERAGENT",
"]",
"=",
"\"Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)\"",
";",
"$",
"this",
"->",
"curlOptions",
"[",
"CURLOPT_FOLLOWLOCATION",
"]",
"=",
"true",
";",
"$",
"this",
"->",
"curlOptions",
"[",
"CURLOPT_SSL_VERIFYHOST",
"]",
"=",
"false",
";",
"$",
"this",
"->",
"curlOptions",
"[",
"CURLOPT_SSL_VERIFYPEER",
"]",
"=",
"false",
";",
"}"
] | Set the default curl options.
You can override this method to setup your own default options.
You can pass the options to the constructor also; | [
"Set",
"the",
"default",
"curl",
"options",
".",
"You",
"can",
"override",
"this",
"method",
"to",
"setup",
"your",
"own",
"default",
"options",
".",
"You",
"can",
"pass",
"the",
"options",
"to",
"the",
"constructor",
"also",
";"
] | 779045160a8ca88044ab41a00d30c4dc6201b619 | https://github.com/byjg/webrequest/blob/779045160a8ca88044ab41a00d30c4dc6201b619/src/WebRequest.php#L277-L287 |
35,593 | byjg/webrequest | src/WebRequest.php | WebRequest.setCurlOption | public function setCurlOption($key, $value)
{
if (!is_int($key)) {
throw new InvalidArgumentException('It is not a CURL_OPT argument');
}
if ($key == CURLOPT_HEADER || $key == CURLOPT_RETURNTRANSFER) {
throw new InvalidArgumentException('You cannot change CURLOPT_HEADER or CURLOPT_RETURNTRANSFER');
}
if (!is_null($value)) {
$this->curlOptions[$key] = $value;
} else {
unset($this->curlOptions[$key]);
}
} | php | public function setCurlOption($key, $value)
{
if (!is_int($key)) {
throw new InvalidArgumentException('It is not a CURL_OPT argument');
}
if ($key == CURLOPT_HEADER || $key == CURLOPT_RETURNTRANSFER) {
throw new InvalidArgumentException('You cannot change CURLOPT_HEADER or CURLOPT_RETURNTRANSFER');
}
if (!is_null($value)) {
$this->curlOptions[$key] = $value;
} else {
unset($this->curlOptions[$key]);
}
} | [
"public",
"function",
"setCurlOption",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'It is not a CURL_OPT argument'",
")",
";",
"}",
"if",
"(",
"$",
"key",
"==",
"CURLOPT_HEADER",
"||",
"$",
"key",
"==",
"CURLOPT_RETURNTRANSFER",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'You cannot change CURLOPT_HEADER or CURLOPT_RETURNTRANSFER'",
")",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"$",
"this",
"->",
"curlOptions",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"unset",
"(",
"$",
"this",
"->",
"curlOptions",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}"
] | Set a custom CURL option
@param int $key
@param mixed $value
@throws InvalidArgumentException | [
"Set",
"a",
"custom",
"CURL",
"option"
] | 779045160a8ca88044ab41a00d30c4dc6201b619 | https://github.com/byjg/webrequest/blob/779045160a8ca88044ab41a00d30c4dc6201b619/src/WebRequest.php#L296-L310 |
35,594 | byjg/webrequest | src/WebRequest.php | WebRequest.getCurlOption | public function getCurlOption($key)
{
return (isset($this->curlOptions[$key]) ? $this->curlOptions[$key] : null);
} | php | public function getCurlOption($key)
{
return (isset($this->curlOptions[$key]) ? $this->curlOptions[$key] : null);
} | [
"public",
"function",
"getCurlOption",
"(",
"$",
"key",
")",
"{",
"return",
"(",
"isset",
"(",
"$",
"this",
"->",
"curlOptions",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"this",
"->",
"curlOptions",
"[",
"$",
"key",
"]",
":",
"null",
")",
";",
"}"
] | Get the current Curl option
@param int $key
@return mixed | [
"Get",
"the",
"current",
"Curl",
"option"
] | 779045160a8ca88044ab41a00d30c4dc6201b619 | https://github.com/byjg/webrequest/blob/779045160a8ca88044ab41a00d30c4dc6201b619/src/WebRequest.php#L318-L321 |
35,595 | byjg/webrequest | src/WebRequest.php | WebRequest.curlInit | protected function curlInit()
{
$curlHandle = curl_init();
curl_setopt($curlHandle, CURLOPT_URL, $this->requestUrl);
$this->requestUrl = $this->url; // Reset request URL
// Set Curl Options
foreach ($this->curlOptions as $key => $value) {
curl_setopt($curlHandle, $key, $value);
}
// Check if have header
if (count($this->requestHeader) > 0) {
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, $this->requestHeader);
$this->requestHeader = []; // Reset request Header
}
// Add Cookies
if (count($this->cookies) > 0) {
curl_setopt($curlHandle, CURLOPT_COOKIE, implode(";", $this->cookies));
$this->cookies = []; // Reset request Header
}
// Set last fetched URL
$this->lastFetchedUrl = null;
return $curlHandle;
} | php | protected function curlInit()
{
$curlHandle = curl_init();
curl_setopt($curlHandle, CURLOPT_URL, $this->requestUrl);
$this->requestUrl = $this->url; // Reset request URL
// Set Curl Options
foreach ($this->curlOptions as $key => $value) {
curl_setopt($curlHandle, $key, $value);
}
// Check if have header
if (count($this->requestHeader) > 0) {
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, $this->requestHeader);
$this->requestHeader = []; // Reset request Header
}
// Add Cookies
if (count($this->cookies) > 0) {
curl_setopt($curlHandle, CURLOPT_COOKIE, implode(";", $this->cookies));
$this->cookies = []; // Reset request Header
}
// Set last fetched URL
$this->lastFetchedUrl = null;
return $curlHandle;
} | [
"protected",
"function",
"curlInit",
"(",
")",
"{",
"$",
"curlHandle",
"=",
"curl_init",
"(",
")",
";",
"curl_setopt",
"(",
"$",
"curlHandle",
",",
"CURLOPT_URL",
",",
"$",
"this",
"->",
"requestUrl",
")",
";",
"$",
"this",
"->",
"requestUrl",
"=",
"$",
"this",
"->",
"url",
";",
"// Reset request URL",
"// Set Curl Options",
"foreach",
"(",
"$",
"this",
"->",
"curlOptions",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"curl_setopt",
"(",
"$",
"curlHandle",
",",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"// Check if have header",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"requestHeader",
")",
">",
"0",
")",
"{",
"curl_setopt",
"(",
"$",
"curlHandle",
",",
"CURLOPT_HTTPHEADER",
",",
"$",
"this",
"->",
"requestHeader",
")",
";",
"$",
"this",
"->",
"requestHeader",
"=",
"[",
"]",
";",
"// Reset request Header",
"}",
"// Add Cookies",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"cookies",
")",
">",
"0",
")",
"{",
"curl_setopt",
"(",
"$",
"curlHandle",
",",
"CURLOPT_COOKIE",
",",
"implode",
"(",
"\";\"",
",",
"$",
"this",
"->",
"cookies",
")",
")",
";",
"$",
"this",
"->",
"cookies",
"=",
"[",
"]",
";",
"// Reset request Header",
"}",
"// Set last fetched URL",
"$",
"this",
"->",
"lastFetchedUrl",
"=",
"null",
";",
"return",
"$",
"curlHandle",
";",
"}"
] | Request the method using the CURLOPT defined previously;
@return resource | [
"Request",
"the",
"method",
"using",
"the",
"CURLOPT",
"defined",
"previously",
";"
] | 779045160a8ca88044ab41a00d30c4dc6201b619 | https://github.com/byjg/webrequest/blob/779045160a8ca88044ab41a00d30c4dc6201b619/src/WebRequest.php#L372-L398 |
35,596 | byjg/webrequest | src/WebRequest.php | WebRequest.get | public function get($params = null)
{
$curlHandle = $this->prepareGet($params);
return $this->curlGetResponse($curlHandle);
} | php | public function get($params = null)
{
$curlHandle = $this->prepareGet($params);
return $this->curlGetResponse($curlHandle);
} | [
"public",
"function",
"get",
"(",
"$",
"params",
"=",
"null",
")",
"{",
"$",
"curlHandle",
"=",
"$",
"this",
"->",
"prepareGet",
"(",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"curlGetResponse",
"(",
"$",
"curlHandle",
")",
";",
"}"
] | Make a REST Get method call
@param array|null $params
@return string
@throws \ByJG\Util\CurlException | [
"Make",
"a",
"REST",
"Get",
"method",
"call"
] | 779045160a8ca88044ab41a00d30c4dc6201b619 | https://github.com/byjg/webrequest/blob/779045160a8ca88044ab41a00d30c4dc6201b619/src/WebRequest.php#L488-L492 |
35,597 | byjg/webrequest | src/WebRequest.php | WebRequest.put | public function put($params = null)
{
$handle = $this->preparePut($params);
return $this->curlGetResponse($handle);
} | php | public function put($params = null)
{
$handle = $this->preparePut($params);
return $this->curlGetResponse($handle);
} | [
"public",
"function",
"put",
"(",
"$",
"params",
"=",
"null",
")",
"{",
"$",
"handle",
"=",
"$",
"this",
"->",
"preparePut",
"(",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"curlGetResponse",
"(",
"$",
"handle",
")",
";",
"}"
] | Make a REST PUT method call with parameters
@param array|string $params
@return string
@throws \ByJG\Util\CurlException | [
"Make",
"a",
"REST",
"PUT",
"method",
"call",
"with",
"parameters"
] | 779045160a8ca88044ab41a00d30c4dc6201b619 | https://github.com/byjg/webrequest/blob/779045160a8ca88044ab41a00d30c4dc6201b619/src/WebRequest.php#L614-L618 |
35,598 | byjg/webrequest | src/WebRequest.php | WebRequest.delete | public function delete($params = null)
{
$handle = $this->prepareDelete($params);
return $this->curlGetResponse($handle);
} | php | public function delete($params = null)
{
$handle = $this->prepareDelete($params);
return $this->curlGetResponse($handle);
} | [
"public",
"function",
"delete",
"(",
"$",
"params",
"=",
"null",
")",
"{",
"$",
"handle",
"=",
"$",
"this",
"->",
"prepareDelete",
"(",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"curlGetResponse",
"(",
"$",
"handle",
")",
";",
"}"
] | Make a REST DELETE method call with parameters
@param array|string $params
@return string
@throws \ByJG\Util\CurlException | [
"Make",
"a",
"REST",
"DELETE",
"method",
"call",
"with",
"parameters"
] | 779045160a8ca88044ab41a00d30c4dc6201b619 | https://github.com/byjg/webrequest/blob/779045160a8ca88044ab41a00d30c4dc6201b619/src/WebRequest.php#L652-L656 |
35,599 | byjg/webrequest | src/WebRequest.php | WebRequest.deletePayload | public function deletePayload($data = null, $contentType = "text/plain")
{
$this->addRequestHeader("Content-Type", $contentType);
return $this->delete($data);
} | php | public function deletePayload($data = null, $contentType = "text/plain")
{
$this->addRequestHeader("Content-Type", $contentType);
return $this->delete($data);
} | [
"public",
"function",
"deletePayload",
"(",
"$",
"data",
"=",
"null",
",",
"$",
"contentType",
"=",
"\"text/plain\"",
")",
"{",
"$",
"this",
"->",
"addRequestHeader",
"(",
"\"Content-Type\"",
",",
"$",
"contentType",
")",
";",
"return",
"$",
"this",
"->",
"delete",
"(",
"$",
"data",
")",
";",
"}"
] | Make a REST DELETE method call sending a payload
@param string $data
@param string $contentType
@return string
@throws \ByJG\Util\CurlException | [
"Make",
"a",
"REST",
"DELETE",
"method",
"call",
"sending",
"a",
"payload"
] | 779045160a8ca88044ab41a00d30c4dc6201b619 | https://github.com/byjg/webrequest/blob/779045160a8ca88044ab41a00d30c4dc6201b619/src/WebRequest.php#L666-L670 |
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.