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
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
koldy/framework | src/Koldy/Validator.php | Validator.validateHex | protected function validateHex($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = trim((string)$value);
if ($value === '') {
return null;
}
if ($value[0] == '-') {
$value = substr($value, 1);
}
if (!ctype_xdigit($value)) {
return Message::getMessage(Message::HEX, [
'param' => $parameter,
'value' => $value
]);
}
return null;
} | php | protected function validateHex($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = trim((string)$value);
if ($value === '') {
return null;
}
if ($value[0] == '-') {
$value = substr($value, 1);
}
if (!ctype_xdigit($value)) {
return Message::getMessage(Message::HEX, [
'param' => $parameter,
'value' => $value
]);
}
return null;
} | [
"protected",
"function",
"validateHex",
"(",
"$",
"value",
",",
"string",
"$",
"parameter",
",",
"array",
"$",
"args",
"=",
"[",
"]",
",",
"array",
"$",
"rules",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"null",
")",
":",
"?",
"string",
"{",
"//$value = $this->getValue($parameter);",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"PRIMITIVE",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
"]",
")",
";",
"}",
"$",
"value",
"=",
"trim",
"(",
"(",
"string",
")",
"$",
"value",
")",
";",
"if",
"(",
"$",
"value",
"===",
"''",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"value",
"[",
"0",
"]",
"==",
"'-'",
")",
"{",
"$",
"value",
"=",
"substr",
"(",
"$",
"value",
",",
"1",
")",
";",
"}",
"if",
"(",
"!",
"ctype_xdigit",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"HEX",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
",",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Validate if given value is hexadecimal number or not
@param mixed $value
@param string $parameter
@param array $args
@param array $rules other rules
@return null|string
@throws ValidatorConfigException
@example 'param' => 'hex' | [
"Validate",
"if",
"given",
"value",
"is",
"hexadecimal",
"number",
"or",
"not"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Validator.php#L1174-L1206 | train |
koldy/framework | src/Koldy/Validator.php | Validator.validateAlpha | protected function validateAlpha($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = trim((string)$value);
if ($value === '') {
return null;
}
if (!ctype_alpha($value)) {
return Message::getMessage(Message::ALPHA, [
'param' => $parameter,
'value' => $value
]);
}
return null;
} | php | protected function validateAlpha($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = trim((string)$value);
if ($value === '') {
return null;
}
if (!ctype_alpha($value)) {
return Message::getMessage(Message::ALPHA, [
'param' => $parameter,
'value' => $value
]);
}
return null;
} | [
"protected",
"function",
"validateAlpha",
"(",
"$",
"value",
",",
"string",
"$",
"parameter",
",",
"array",
"$",
"args",
"=",
"[",
"]",
",",
"array",
"$",
"rules",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"null",
")",
":",
"?",
"string",
"{",
"//$value = $this->getValue($parameter);",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"PRIMITIVE",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
"]",
")",
";",
"}",
"$",
"value",
"=",
"trim",
"(",
"(",
"string",
")",
"$",
"value",
")",
";",
"if",
"(",
"$",
"value",
"===",
"''",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"ctype_alpha",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"ALPHA",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
",",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Validate if given value contains alpha chars only or not, allowing lower and uppercase English letters
@param mixed $value
@param string $parameter
@param array $args
@param array $rules other rules
@return null|string
@throws ValidatorConfigException
@example 'param' => 'alpha' | [
"Validate",
"if",
"given",
"value",
"contains",
"alpha",
"chars",
"only",
"or",
"not",
"allowing",
"lower",
"and",
"uppercase",
"English",
"letters"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Validator.php#L1220-L1248 | train |
koldy/framework | src/Koldy/Validator.php | Validator.validateEmail | protected function validateEmail($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = trim((string)$value);
if ($value === '') {
return null;
}
if (!Validate::isEmail($value)) {
return Message::getMessage(Message::EMAIL, [
'param' => $parameter,
'value' => $value
]);
}
return null;
} | php | protected function validateEmail($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = trim((string)$value);
if ($value === '') {
return null;
}
if (!Validate::isEmail($value)) {
return Message::getMessage(Message::EMAIL, [
'param' => $parameter,
'value' => $value
]);
}
return null;
} | [
"protected",
"function",
"validateEmail",
"(",
"$",
"value",
",",
"string",
"$",
"parameter",
",",
"array",
"$",
"args",
"=",
"[",
"]",
",",
"array",
"$",
"rules",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"null",
")",
":",
"?",
"string",
"{",
"//$value = $this->getValue($parameter);",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"PRIMITIVE",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
"]",
")",
";",
"}",
"$",
"value",
"=",
"trim",
"(",
"(",
"string",
")",
"$",
"value",
")",
";",
"if",
"(",
"$",
"value",
"===",
"''",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"Validate",
"::",
"isEmail",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"EMAIL",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
",",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Validate if given value is valid email address by syntax
@param mixed $value
@param string $parameter
@param array $args
@param array $rules other rules
@return null|string
@throws ValidatorConfigException
@example 'param' => 'email' | [
"Validate",
"if",
"given",
"value",
"is",
"valid",
"email",
"address",
"by",
"syntax"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Validator.php#L1262-L1290 | train |
koldy/framework | src/Koldy/Validator.php | Validator.validateSlug | protected function validateSlug($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = trim((string)$value);
if ($value === '') {
return null;
}
if (!Validate::isSlug($value)) {
return Message::getMessage(Message::SLUG, [
'param' => $parameter,
'value' => $value
]);
}
return null;
} | php | protected function validateSlug($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = trim((string)$value);
if ($value === '') {
return null;
}
if (!Validate::isSlug($value)) {
return Message::getMessage(Message::SLUG, [
'param' => $parameter,
'value' => $value
]);
}
return null;
} | [
"protected",
"function",
"validateSlug",
"(",
"$",
"value",
",",
"string",
"$",
"parameter",
",",
"array",
"$",
"args",
"=",
"[",
"]",
",",
"array",
"$",
"rules",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"null",
")",
":",
"?",
"string",
"{",
"//$value = $this->getValue($parameter);",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"PRIMITIVE",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
"]",
")",
";",
"}",
"$",
"value",
"=",
"trim",
"(",
"(",
"string",
")",
"$",
"value",
")",
";",
"if",
"(",
"$",
"value",
"===",
"''",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"Validate",
"::",
"isSlug",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"SLUG",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
",",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Validate if given value is valid URL slug
@param mixed $value
@param string $parameter
@param array $args
@param array $rules other rules
@return null|string
@throws ValidatorConfigException
@example 'param' => 'slug' | [
"Validate",
"if",
"given",
"value",
"is",
"valid",
"URL",
"slug"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Validator.php#L1304-L1332 | train |
koldy/framework | src/Koldy/Validator.php | Validator.validateDecimal | protected function validateDecimal($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
if (count($args) == 0) {
throw new ValidatorConfigException("Validator 'decimal' must have argument in validator list for parameter {$parameter}");
}
$decimals = (int)$args[0];
if ($decimals <= 0) {
throw new ValidatorConfigException("Validator 'decimal' has invalid value which is lower or equal to zero; for parameter={$parameter}");
}
if ($decimals > 100) {
throw new ValidatorConfigException("Validator 'decimal' can't have that large argument; parameter={$parameter}");
}
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = trim((string)$value);
if ($value === '') {
return null;
}
if (!is_numeric($value)) {
return Message::getMessage(Message::NUMERIC, [
'param' => $parameter,
'value' => $value
]);
}
$parts = explode('.', $value);
if (count($parts) == 1) {
return null; // value is not decimal, it's probably integer, so it's ok
}
$valueDecimals = $parts[1];
if (strlen($valueDecimals) > $decimals) {
return Message::getMessage(Message::DECIMAL, [
'param' => $parameter,
'value' => $value,
'decimals' => $decimals
]);
}
return null;
} | php | protected function validateDecimal($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
if (count($args) == 0) {
throw new ValidatorConfigException("Validator 'decimal' must have argument in validator list for parameter {$parameter}");
}
$decimals = (int)$args[0];
if ($decimals <= 0) {
throw new ValidatorConfigException("Validator 'decimal' has invalid value which is lower or equal to zero; for parameter={$parameter}");
}
if ($decimals > 100) {
throw new ValidatorConfigException("Validator 'decimal' can't have that large argument; parameter={$parameter}");
}
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = trim((string)$value);
if ($value === '') {
return null;
}
if (!is_numeric($value)) {
return Message::getMessage(Message::NUMERIC, [
'param' => $parameter,
'value' => $value
]);
}
$parts = explode('.', $value);
if (count($parts) == 1) {
return null; // value is not decimal, it's probably integer, so it's ok
}
$valueDecimals = $parts[1];
if (strlen($valueDecimals) > $decimals) {
return Message::getMessage(Message::DECIMAL, [
'param' => $parameter,
'value' => $value,
'decimals' => $decimals
]);
}
return null;
} | [
"protected",
"function",
"validateDecimal",
"(",
"$",
"value",
",",
"string",
"$",
"parameter",
",",
"array",
"$",
"args",
"=",
"[",
"]",
",",
"array",
"$",
"rules",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"null",
")",
":",
"?",
"string",
"{",
"if",
"(",
"count",
"(",
"$",
"args",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"\"Validator 'decimal' must have argument in validator list for parameter {$parameter}\"",
")",
";",
"}",
"$",
"decimals",
"=",
"(",
"int",
")",
"$",
"args",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"decimals",
"<=",
"0",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"\"Validator 'decimal' has invalid value which is lower or equal to zero; for parameter={$parameter}\"",
")",
";",
"}",
"if",
"(",
"$",
"decimals",
">",
"100",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"\"Validator 'decimal' can't have that large argument; parameter={$parameter}\"",
")",
";",
"}",
"//$value = $this->getValue($parameter);",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"PRIMITIVE",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
"]",
")",
";",
"}",
"$",
"value",
"=",
"trim",
"(",
"(",
"string",
")",
"$",
"value",
")",
";",
"if",
"(",
"$",
"value",
"===",
"''",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"NUMERIC",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
",",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"}",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"value",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
"==",
"1",
")",
"{",
"return",
"null",
";",
"// value is not decimal, it's probably integer, so it's ok",
"}",
"$",
"valueDecimals",
"=",
"$",
"parts",
"[",
"1",
"]",
";",
"if",
"(",
"strlen",
"(",
"$",
"valueDecimals",
")",
">",
"$",
"decimals",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"DECIMAL",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
",",
"'value'",
"=>",
"$",
"value",
",",
"'decimals'",
"=>",
"$",
"decimals",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Validate if given value has equal or less number of required decimals
@param mixed $value
@param string $parameter
@param array $args
@param array $rules other rules
@return null|string
@throws ValidatorConfigException
@example 'param' => 'decimal:2' | [
"Validate",
"if",
"given",
"value",
"has",
"equal",
"or",
"less",
"number",
"of",
"required",
"decimals"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Validator.php#L1393-L1451 | train |
koldy/framework | src/Koldy/Validator.php | Validator.validateSame | protected function validateSame($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
if (count($args) == 0) {
throw new ValidatorConfigException("Validator 'same' must have argument in validator list for parameter {$parameter}");
}
$sameAsField = trim($args[0]);
if (strlen($sameAsField) == 0) {
throw new ValidatorConfigException("Validator 'same' must have non-empty argument; parameter={$parameter}");
}
$present = $this->validatePresent($value, $sameAsField, [], $rules, $context);
if ($present !== null) {
return $present;
}
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$sameAsValue = $context[$sameAsField] ?? null;
if (!is_scalar($sameAsValue)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $sameAsField
]);
}
if ($value != $sameAsValue) {
return Message::getMessage(Message::SAME, [
'param' => $parameter,
'value' => $value,
'otherField' => $sameAsField,
'otherValue' => $sameAsValue
]);
}
return null;
} | php | protected function validateSame($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
if (count($args) == 0) {
throw new ValidatorConfigException("Validator 'same' must have argument in validator list for parameter {$parameter}");
}
$sameAsField = trim($args[0]);
if (strlen($sameAsField) == 0) {
throw new ValidatorConfigException("Validator 'same' must have non-empty argument; parameter={$parameter}");
}
$present = $this->validatePresent($value, $sameAsField, [], $rules, $context);
if ($present !== null) {
return $present;
}
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$sameAsValue = $context[$sameAsField] ?? null;
if (!is_scalar($sameAsValue)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $sameAsField
]);
}
if ($value != $sameAsValue) {
return Message::getMessage(Message::SAME, [
'param' => $parameter,
'value' => $value,
'otherField' => $sameAsField,
'otherValue' => $sameAsValue
]);
}
return null;
} | [
"protected",
"function",
"validateSame",
"(",
"$",
"value",
",",
"string",
"$",
"parameter",
",",
"array",
"$",
"args",
"=",
"[",
"]",
",",
"array",
"$",
"rules",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"null",
")",
":",
"?",
"string",
"{",
"if",
"(",
"count",
"(",
"$",
"args",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"\"Validator 'same' must have argument in validator list for parameter {$parameter}\"",
")",
";",
"}",
"$",
"sameAsField",
"=",
"trim",
"(",
"$",
"args",
"[",
"0",
"]",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"sameAsField",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"\"Validator 'same' must have non-empty argument; parameter={$parameter}\"",
")",
";",
"}",
"$",
"present",
"=",
"$",
"this",
"->",
"validatePresent",
"(",
"$",
"value",
",",
"$",
"sameAsField",
",",
"[",
"]",
",",
"$",
"rules",
",",
"$",
"context",
")",
";",
"if",
"(",
"$",
"present",
"!==",
"null",
")",
"{",
"return",
"$",
"present",
";",
"}",
"//$value = $this->getValue($parameter);",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"PRIMITIVE",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
"]",
")",
";",
"}",
"$",
"sameAsValue",
"=",
"$",
"context",
"[",
"$",
"sameAsField",
"]",
"??",
"null",
";",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"sameAsValue",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"PRIMITIVE",
",",
"[",
"'param'",
"=>",
"$",
"sameAsField",
"]",
")",
";",
"}",
"if",
"(",
"$",
"value",
"!=",
"$",
"sameAsValue",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"SAME",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
",",
"'value'",
"=>",
"$",
"value",
",",
"'otherField'",
"=>",
"$",
"sameAsField",
",",
"'otherValue'",
"=>",
"$",
"sameAsValue",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Validate if value is the same as value in other field
@param mixed $value
@param string $parameter
@param array $args
@param array $rules other rules
@return null|string
@throws ValidatorConfigException
@example
'param1' => 'required',
'param2' => 'same:param1' | [
"Validate",
"if",
"value",
"is",
"the",
"same",
"as",
"value",
"in",
"other",
"field"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Validator.php#L1467-L1514 | train |
koldy/framework | src/Koldy/Validator.php | Validator.validateDifferent | protected function validateDifferent($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
if (count($args) == 0) {
throw new ValidatorConfigException("Validator 'different' must have argument in validator list for parameter {$parameter}");
}
$differentAsField = trim($args[0]);
if (strlen($differentAsField) == 0) {
throw new ValidatorConfigException("Validator 'different' must have non-empty argument; parameter={$parameter}");
}
$present = $this->validatePresent($value, $differentAsField, [], $rules, $context);
if ($present !== null) {
return $present;
}
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$differentAsValue = $context[$differentAsField] ?? null;
if (!is_scalar($differentAsValue)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $differentAsField
]);
}
if ($value == $differentAsValue) {
return Message::getMessage(Message::DIFFERENT, [
'param' => $parameter,
'value' => $value,
'otherField' => $differentAsField,
'otherValue' => $differentAsValue
]);
}
return null;
} | php | protected function validateDifferent($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
if (count($args) == 0) {
throw new ValidatorConfigException("Validator 'different' must have argument in validator list for parameter {$parameter}");
}
$differentAsField = trim($args[0]);
if (strlen($differentAsField) == 0) {
throw new ValidatorConfigException("Validator 'different' must have non-empty argument; parameter={$parameter}");
}
$present = $this->validatePresent($value, $differentAsField, [], $rules, $context);
if ($present !== null) {
return $present;
}
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$differentAsValue = $context[$differentAsField] ?? null;
if (!is_scalar($differentAsValue)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $differentAsField
]);
}
if ($value == $differentAsValue) {
return Message::getMessage(Message::DIFFERENT, [
'param' => $parameter,
'value' => $value,
'otherField' => $differentAsField,
'otherValue' => $differentAsValue
]);
}
return null;
} | [
"protected",
"function",
"validateDifferent",
"(",
"$",
"value",
",",
"string",
"$",
"parameter",
",",
"array",
"$",
"args",
"=",
"[",
"]",
",",
"array",
"$",
"rules",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"null",
")",
":",
"?",
"string",
"{",
"if",
"(",
"count",
"(",
"$",
"args",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"\"Validator 'different' must have argument in validator list for parameter {$parameter}\"",
")",
";",
"}",
"$",
"differentAsField",
"=",
"trim",
"(",
"$",
"args",
"[",
"0",
"]",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"differentAsField",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"\"Validator 'different' must have non-empty argument; parameter={$parameter}\"",
")",
";",
"}",
"$",
"present",
"=",
"$",
"this",
"->",
"validatePresent",
"(",
"$",
"value",
",",
"$",
"differentAsField",
",",
"[",
"]",
",",
"$",
"rules",
",",
"$",
"context",
")",
";",
"if",
"(",
"$",
"present",
"!==",
"null",
")",
"{",
"return",
"$",
"present",
";",
"}",
"//$value = $this->getValue($parameter);",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"PRIMITIVE",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
"]",
")",
";",
"}",
"$",
"differentAsValue",
"=",
"$",
"context",
"[",
"$",
"differentAsField",
"]",
"??",
"null",
";",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"differentAsValue",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"PRIMITIVE",
",",
"[",
"'param'",
"=>",
"$",
"differentAsField",
"]",
")",
";",
"}",
"if",
"(",
"$",
"value",
"==",
"$",
"differentAsValue",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"DIFFERENT",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
",",
"'value'",
"=>",
"$",
"value",
",",
"'otherField'",
"=>",
"$",
"differentAsField",
",",
"'otherValue'",
"=>",
"$",
"differentAsValue",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Opposite of "same", passes if value is different then value in other field
@param mixed $value
@param string $parameter
@param array $args
@param array $rules other rules
@return null|string
@throws ValidatorConfigException
@example
'param1' => 'required',
'param2' => 'different:param1' | [
"Opposite",
"of",
"same",
"passes",
"if",
"value",
"is",
"different",
"then",
"value",
"in",
"other",
"field"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Validator.php#L1530-L1577 | train |
koldy/framework | src/Koldy/Validator.php | Validator.validateDate | protected function validateDate($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
$format = $args[0] ?? null;
if ($format === '') {
throw new ValidatorConfigException("Invalid format specified in 'date' validator for parameter {$parameter}");
}
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = trim((string)$value);
if ($value === '') {
return null;
}
if ($format === null) {
// no format, use simple strtotime()
if (strtotime($value) === false) {
return Message::getMessage(Message::DATE, [
'param' => $parameter,
'value' => $value
]);
}
} else {
$dateTime = \DateTime::createFromFormat($format, $value);
if ($dateTime === false || $dateTime->format($format) !== $value) {
return Message::getMessage(Message::DATE, [
'param' => $parameter,
'value' => $value
]);
}
}
return null;
} | php | protected function validateDate($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
$format = $args[0] ?? null;
if ($format === '') {
throw new ValidatorConfigException("Invalid format specified in 'date' validator for parameter {$parameter}");
}
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = trim((string)$value);
if ($value === '') {
return null;
}
if ($format === null) {
// no format, use simple strtotime()
if (strtotime($value) === false) {
return Message::getMessage(Message::DATE, [
'param' => $parameter,
'value' => $value
]);
}
} else {
$dateTime = \DateTime::createFromFormat($format, $value);
if ($dateTime === false || $dateTime->format($format) !== $value) {
return Message::getMessage(Message::DATE, [
'param' => $parameter,
'value' => $value
]);
}
}
return null;
} | [
"protected",
"function",
"validateDate",
"(",
"$",
"value",
",",
"string",
"$",
"parameter",
",",
"array",
"$",
"args",
"=",
"[",
"]",
",",
"array",
"$",
"rules",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"null",
")",
":",
"?",
"string",
"{",
"$",
"format",
"=",
"$",
"args",
"[",
"0",
"]",
"??",
"null",
";",
"if",
"(",
"$",
"format",
"===",
"''",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"\"Invalid format specified in 'date' validator for parameter {$parameter}\"",
")",
";",
"}",
"//$value = $this->getValue($parameter);",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"PRIMITIVE",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
"]",
")",
";",
"}",
"$",
"value",
"=",
"trim",
"(",
"(",
"string",
")",
"$",
"value",
")",
";",
"if",
"(",
"$",
"value",
"===",
"''",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"format",
"===",
"null",
")",
"{",
"// no format, use simple strtotime()",
"if",
"(",
"strtotime",
"(",
"$",
"value",
")",
"===",
"false",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"DATE",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
",",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"dateTime",
"=",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"$",
"format",
",",
"$",
"value",
")",
";",
"if",
"(",
"$",
"dateTime",
"===",
"false",
"||",
"$",
"dateTime",
"->",
"format",
"(",
"$",
"format",
")",
"!==",
"$",
"value",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"DATE",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
",",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
]
| Validate if given value is properly formatted date
@param mixed $value
@param string $parameter
@param array $args
@param array $rules other rules
@return null|string
@throws ValidatorConfigException
@example 'param' => 'date'
@example 'param' => 'date:Y-m-d' | [
"Validate",
"if",
"given",
"value",
"is",
"properly",
"formatted",
"date"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Validator.php#L1592-L1637 | train |
koldy/framework | src/Koldy/Validator.php | Validator.validateAnyOf | protected function validateAnyOf($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
if (count($args) == 0) {
throw new ValidatorConfigException("Validator 'anyOf' must have at least one defined value; parameter={$parameter}");
}
if ($args[0] == '') {
throw new ValidatorConfigException("Validator 'anyOf' must have non-empty string for argument; parameter={$parameter}");
}
foreach ($args as $i => $arg) {
$args[$i] = urldecode(trim($arg));
}
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = trim((string)$value);
if ($value === '') {
return null;
}
if (!in_array($value, $args)) {
return Message::getMessage(Message::ANY_OF, [
'param' => $parameter,
'value' => $value,
'allowedValues' => implode(', ', $args)
]);
}
return null;
} | php | protected function validateAnyOf($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
if (count($args) == 0) {
throw new ValidatorConfigException("Validator 'anyOf' must have at least one defined value; parameter={$parameter}");
}
if ($args[0] == '') {
throw new ValidatorConfigException("Validator 'anyOf' must have non-empty string for argument; parameter={$parameter}");
}
foreach ($args as $i => $arg) {
$args[$i] = urldecode(trim($arg));
}
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = trim((string)$value);
if ($value === '') {
return null;
}
if (!in_array($value, $args)) {
return Message::getMessage(Message::ANY_OF, [
'param' => $parameter,
'value' => $value,
'allowedValues' => implode(', ', $args)
]);
}
return null;
} | [
"protected",
"function",
"validateAnyOf",
"(",
"$",
"value",
",",
"string",
"$",
"parameter",
",",
"array",
"$",
"args",
"=",
"[",
"]",
",",
"array",
"$",
"rules",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"null",
")",
":",
"?",
"string",
"{",
"if",
"(",
"count",
"(",
"$",
"args",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"\"Validator 'anyOf' must have at least one defined value; parameter={$parameter}\"",
")",
";",
"}",
"if",
"(",
"$",
"args",
"[",
"0",
"]",
"==",
"''",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"\"Validator 'anyOf' must have non-empty string for argument; parameter={$parameter}\"",
")",
";",
"}",
"foreach",
"(",
"$",
"args",
"as",
"$",
"i",
"=>",
"$",
"arg",
")",
"{",
"$",
"args",
"[",
"$",
"i",
"]",
"=",
"urldecode",
"(",
"trim",
"(",
"$",
"arg",
")",
")",
";",
"}",
"//$value = $this->getValue($parameter);",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"PRIMITIVE",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
"]",
")",
";",
"}",
"$",
"value",
"=",
"trim",
"(",
"(",
"string",
")",
"$",
"value",
")",
";",
"if",
"(",
"$",
"value",
"===",
"''",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"value",
",",
"$",
"args",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"ANY_OF",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
",",
"'value'",
"=>",
"$",
"value",
",",
"'allowedValues'",
"=>",
"implode",
"(",
"', '",
",",
"$",
"args",
")",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Validate if value is any of allowed values
@param mixed $value
@param string $parameter
@param array $args
@param array $rules other rules
@return null|string
@throws ValidatorConfigException
@example 'param' => 'anyOf:one,two,3,four'
@example 'param' => 'anyOf:one,two%2C maybe three' // if comma needs to be used, then urlencode it | [
"Validate",
"if",
"value",
"is",
"any",
"of",
"allowed",
"values"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Validator.php#L1652-L1693 | train |
koldy/framework | src/Koldy/Validator.php | Validator.validateUnique | protected function validateUnique($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
if (count($args) < 2) {
throw new ValidatorConfigException("Validator 'unique' must have at least two defined arguments; parameter={$parameter}");
}
array_walk($args, 'trim');
if ($args[0] == '') {
throw new ValidatorConfigException("Validator 'unique' must have non-empty string for argument=0; parameter={$parameter}");
}
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = trim((string)$value);
if ($value === '') {
return null;
}
for ($i = count($args); $i < 4; $i++) {
if (!isset($args[$i])) {
$args[$i] = null;
}
}
/** @var Model $modelClass */
list($modelClass, $uniqueField, $exceptionValue, $exceptionField) = $args;
if (is_string($exceptionValue)) {
if (substr($exceptionValue, 0, 6) == 'field:') {
$exceptionFieldName = substr($exceptionValue, 6);
$exceptionFieldValue = $context[$exceptionFieldName] ?? null;
if ($exceptionFieldValue === null) {
throw new ValidatorConfigException("Can not validate unique parameter={$parameter} when exception field name={$exceptionFieldName} is not present or has the value of null");
}
$exceptionValue = $exceptionFieldValue;
} else {
$exceptionValue = urldecode(trim($exceptionValue));
}
}
if (!$modelClass::isUnique($uniqueField, $value, $exceptionValue, $exceptionField)) {
return Message::getMessage(Message::NOT_UNIQUE, [
'param' => $parameter,
'value' => $value,
'exceptionField' => $exceptionField,
'exceptionValue' => $exceptionValue
]);
}
return null;
} | php | protected function validateUnique($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
if (count($args) < 2) {
throw new ValidatorConfigException("Validator 'unique' must have at least two defined arguments; parameter={$parameter}");
}
array_walk($args, 'trim');
if ($args[0] == '') {
throw new ValidatorConfigException("Validator 'unique' must have non-empty string for argument=0; parameter={$parameter}");
}
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = trim((string)$value);
if ($value === '') {
return null;
}
for ($i = count($args); $i < 4; $i++) {
if (!isset($args[$i])) {
$args[$i] = null;
}
}
/** @var Model $modelClass */
list($modelClass, $uniqueField, $exceptionValue, $exceptionField) = $args;
if (is_string($exceptionValue)) {
if (substr($exceptionValue, 0, 6) == 'field:') {
$exceptionFieldName = substr($exceptionValue, 6);
$exceptionFieldValue = $context[$exceptionFieldName] ?? null;
if ($exceptionFieldValue === null) {
throw new ValidatorConfigException("Can not validate unique parameter={$parameter} when exception field name={$exceptionFieldName} is not present or has the value of null");
}
$exceptionValue = $exceptionFieldValue;
} else {
$exceptionValue = urldecode(trim($exceptionValue));
}
}
if (!$modelClass::isUnique($uniqueField, $value, $exceptionValue, $exceptionField)) {
return Message::getMessage(Message::NOT_UNIQUE, [
'param' => $parameter,
'value' => $value,
'exceptionField' => $exceptionField,
'exceptionValue' => $exceptionValue
]);
}
return null;
} | [
"protected",
"function",
"validateUnique",
"(",
"$",
"value",
",",
"string",
"$",
"parameter",
",",
"array",
"$",
"args",
"=",
"[",
"]",
",",
"array",
"$",
"rules",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"null",
")",
":",
"?",
"string",
"{",
"if",
"(",
"count",
"(",
"$",
"args",
")",
"<",
"2",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"\"Validator 'unique' must have at least two defined arguments; parameter={$parameter}\"",
")",
";",
"}",
"array_walk",
"(",
"$",
"args",
",",
"'trim'",
")",
";",
"if",
"(",
"$",
"args",
"[",
"0",
"]",
"==",
"''",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"\"Validator 'unique' must have non-empty string for argument=0; parameter={$parameter}\"",
")",
";",
"}",
"//$value = $this->getValue($parameter);",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"PRIMITIVE",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
"]",
")",
";",
"}",
"$",
"value",
"=",
"trim",
"(",
"(",
"string",
")",
"$",
"value",
")",
";",
"if",
"(",
"$",
"value",
"===",
"''",
")",
"{",
"return",
"null",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"count",
"(",
"$",
"args",
")",
";",
"$",
"i",
"<",
"4",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"args",
"[",
"$",
"i",
"]",
")",
")",
"{",
"$",
"args",
"[",
"$",
"i",
"]",
"=",
"null",
";",
"}",
"}",
"/** @var Model $modelClass */",
"list",
"(",
"$",
"modelClass",
",",
"$",
"uniqueField",
",",
"$",
"exceptionValue",
",",
"$",
"exceptionField",
")",
"=",
"$",
"args",
";",
"if",
"(",
"is_string",
"(",
"$",
"exceptionValue",
")",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"exceptionValue",
",",
"0",
",",
"6",
")",
"==",
"'field:'",
")",
"{",
"$",
"exceptionFieldName",
"=",
"substr",
"(",
"$",
"exceptionValue",
",",
"6",
")",
";",
"$",
"exceptionFieldValue",
"=",
"$",
"context",
"[",
"$",
"exceptionFieldName",
"]",
"??",
"null",
";",
"if",
"(",
"$",
"exceptionFieldValue",
"===",
"null",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"\"Can not validate unique parameter={$parameter} when exception field name={$exceptionFieldName} is not present or has the value of null\"",
")",
";",
"}",
"$",
"exceptionValue",
"=",
"$",
"exceptionFieldValue",
";",
"}",
"else",
"{",
"$",
"exceptionValue",
"=",
"urldecode",
"(",
"trim",
"(",
"$",
"exceptionValue",
")",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"modelClass",
"::",
"isUnique",
"(",
"$",
"uniqueField",
",",
"$",
"value",
",",
"$",
"exceptionValue",
",",
"$",
"exceptionField",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"NOT_UNIQUE",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
",",
"'value'",
"=>",
"$",
"value",
",",
"'exceptionField'",
"=>",
"$",
"exceptionField",
",",
"'exceptionValue'",
"=>",
"$",
"exceptionValue",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Return error if value is not unique in database
@param mixed $value
@param string $parameter
@param array $args
@param array $rules other rules (Class\Name,uniqueField[,exceptionValue][,exceptionField])
@throws Exception
@return true|string
@example 'email' => 'email|unique:\Db\User,email,[email protected]'
@example
'id' => 'required|integer|min:1',
'email' => 'email|unique:\Db\User,email,field:id,id' // check if email exists in \Db\User model, but exclude ID with value from param 'id' | [
"Return",
"error",
"if",
"value",
"is",
"not",
"unique",
"in",
"database"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Validator.php#L1710-L1774 | train |
koldy/framework | src/Koldy/Validator.php | Validator.validateExists | protected function validateExists($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
if (count($args) < 2) {
throw new ValidatorConfigException("Validator 'exists' must have at least two defined arguments; parameter={$parameter}");
}
array_walk($args, 'trim');
if ($args[0] == '') {
throw new ValidatorConfigException("Validator 'exists' must have non-empty string for argument=0; parameter={$parameter}");
}
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = trim((string)$value);
if ($value === '') {
return null;
}
/** @var Model $modelClass */
list($modelClass, $queryField) = $args;
if ($modelClass::count([$queryField => $value]) == 0) {
return Message::getMessage(Message::NO_RECORD, [
'param' => $parameter,
'value' => $value,
'field' => $queryField
]);
}
return null;
} | php | protected function validateExists($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
if (count($args) < 2) {
throw new ValidatorConfigException("Validator 'exists' must have at least two defined arguments; parameter={$parameter}");
}
array_walk($args, 'trim');
if ($args[0] == '') {
throw new ValidatorConfigException("Validator 'exists' must have non-empty string for argument=0; parameter={$parameter}");
}
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = trim((string)$value);
if ($value === '') {
return null;
}
/** @var Model $modelClass */
list($modelClass, $queryField) = $args;
if ($modelClass::count([$queryField => $value]) == 0) {
return Message::getMessage(Message::NO_RECORD, [
'param' => $parameter,
'value' => $value,
'field' => $queryField
]);
}
return null;
} | [
"protected",
"function",
"validateExists",
"(",
"$",
"value",
",",
"string",
"$",
"parameter",
",",
"array",
"$",
"args",
"=",
"[",
"]",
",",
"array",
"$",
"rules",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"null",
")",
":",
"?",
"string",
"{",
"if",
"(",
"count",
"(",
"$",
"args",
")",
"<",
"2",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"\"Validator 'exists' must have at least two defined arguments; parameter={$parameter}\"",
")",
";",
"}",
"array_walk",
"(",
"$",
"args",
",",
"'trim'",
")",
";",
"if",
"(",
"$",
"args",
"[",
"0",
"]",
"==",
"''",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"\"Validator 'exists' must have non-empty string for argument=0; parameter={$parameter}\"",
")",
";",
"}",
"//$value = $this->getValue($parameter);",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"PRIMITIVE",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
"]",
")",
";",
"}",
"$",
"value",
"=",
"trim",
"(",
"(",
"string",
")",
"$",
"value",
")",
";",
"if",
"(",
"$",
"value",
"===",
"''",
")",
"{",
"return",
"null",
";",
"}",
"/** @var Model $modelClass */",
"list",
"(",
"$",
"modelClass",
",",
"$",
"queryField",
")",
"=",
"$",
"args",
";",
"if",
"(",
"$",
"modelClass",
"::",
"count",
"(",
"[",
"$",
"queryField",
"=>",
"$",
"value",
"]",
")",
"==",
"0",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"NO_RECORD",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
",",
"'value'",
"=>",
"$",
"value",
",",
"'field'",
"=>",
"$",
"queryField",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Return error if value does not exists in database
@param mixed $value
@param string $parameter
@param array $args
@param array $rules other rules (Class\Name,fieldName)
@throws Exception
@return true|string
@example 'user_id' => 'required|integer|exists:\Db\User,id' // e.g. user_id = 5, so this will check if there is record in \Db\User model under id=5 | [
"Return",
"error",
"if",
"value",
"does",
"not",
"exists",
"in",
"database"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Validator.php#L1788-L1830 | train |
koldy/framework | src/Koldy/Validator.php | Validator.validateCsrf | protected function validateCsrf($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = trim((string)$value);
if (Csrf::isTokenValid($value)) {
return null;
}
if (!in_array($value, $args)) {
return Message::getMessage(Message::CSRF_FAILED, [
'param' => $parameter
]);
}
return null;
} | php | protected function validateCsrf($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = trim((string)$value);
if (Csrf::isTokenValid($value)) {
return null;
}
if (!in_array($value, $args)) {
return Message::getMessage(Message::CSRF_FAILED, [
'param' => $parameter
]);
}
return null;
} | [
"protected",
"function",
"validateCsrf",
"(",
"$",
"value",
",",
"string",
"$",
"parameter",
",",
"array",
"$",
"args",
"=",
"[",
"]",
",",
"array",
"$",
"rules",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"null",
")",
":",
"?",
"string",
"{",
"//$value = $this->getValue($parameter);",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"PRIMITIVE",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
"]",
")",
";",
"}",
"$",
"value",
"=",
"trim",
"(",
"(",
"string",
")",
"$",
"value",
")",
";",
"if",
"(",
"Csrf",
"::",
"isTokenValid",
"(",
"$",
"value",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"value",
",",
"$",
"args",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"CSRF_FAILED",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Validate if given value has valid CSRF token
@param mixed $value
@param string $parameter
@param array $args
@param array $rules other rules
@param array|null $context
@return null|string
@throws Config\Exception
@throws Exception
@throws Security\Exception
@throws ValidatorConfigException
@example 'csrf_token' => 'anyOf:one,two,3,four' | [
"Validate",
"if",
"given",
"value",
"has",
"valid",
"CSRF",
"token"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Validator.php#L1848-L1875 | train |
koldy/framework | src/Koldy/Validator.php | Validator.validateArray | protected function validateArray($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
$count = $args[0] ?? null;
if ($count !== null) {
if ($count == '' || !is_numeric($count)) {
throw new ValidatorConfigException("Invalid array count definition for parameter {$parameter}");
}
$count = (int)$count;
if ($count < 0) {
throw new ValidatorConfigException("Invalid array count definition for parameter {$parameter}, argument can not be negative");
}
}
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (is_string($value) && $value === '') {
return null;
}
if (!is_array($value)) {
return Message::getMessage(Message::IS_NOT_ARRAY, [
'param' => $parameter
]);
}
if ($count !== null) {
$currentCount = count($value);
if ($currentCount != $count) {
if (ctype_digit($parameter)) {
$parameter = "Element on position {$parameter}";
}
return Message::getMessage(Message::ARRAY_WRONG_COUNT, [
'param' => $parameter,
'requiredCount' => $count,
'currentCount' => $currentCount
]);
}
}
return null;
} | php | protected function validateArray($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
$count = $args[0] ?? null;
if ($count !== null) {
if ($count == '' || !is_numeric($count)) {
throw new ValidatorConfigException("Invalid array count definition for parameter {$parameter}");
}
$count = (int)$count;
if ($count < 0) {
throw new ValidatorConfigException("Invalid array count definition for parameter {$parameter}, argument can not be negative");
}
}
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (is_string($value) && $value === '') {
return null;
}
if (!is_array($value)) {
return Message::getMessage(Message::IS_NOT_ARRAY, [
'param' => $parameter
]);
}
if ($count !== null) {
$currentCount = count($value);
if ($currentCount != $count) {
if (ctype_digit($parameter)) {
$parameter = "Element on position {$parameter}";
}
return Message::getMessage(Message::ARRAY_WRONG_COUNT, [
'param' => $parameter,
'requiredCount' => $count,
'currentCount' => $currentCount
]);
}
}
return null;
} | [
"protected",
"function",
"validateArray",
"(",
"$",
"value",
",",
"string",
"$",
"parameter",
",",
"array",
"$",
"args",
"=",
"[",
"]",
",",
"array",
"$",
"rules",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"null",
")",
":",
"?",
"string",
"{",
"$",
"count",
"=",
"$",
"args",
"[",
"0",
"]",
"??",
"null",
";",
"if",
"(",
"$",
"count",
"!==",
"null",
")",
"{",
"if",
"(",
"$",
"count",
"==",
"''",
"||",
"!",
"is_numeric",
"(",
"$",
"count",
")",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"\"Invalid array count definition for parameter {$parameter}\"",
")",
";",
"}",
"$",
"count",
"=",
"(",
"int",
")",
"$",
"count",
";",
"if",
"(",
"$",
"count",
"<",
"0",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"\"Invalid array count definition for parameter {$parameter}, argument can not be negative\"",
")",
";",
"}",
"}",
"//$value = $this->getValue($parameter);",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
"&&",
"$",
"value",
"===",
"''",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"IS_NOT_ARRAY",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
"]",
")",
";",
"}",
"if",
"(",
"$",
"count",
"!==",
"null",
")",
"{",
"$",
"currentCount",
"=",
"count",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"currentCount",
"!=",
"$",
"count",
")",
"{",
"if",
"(",
"ctype_digit",
"(",
"$",
"parameter",
")",
")",
"{",
"$",
"parameter",
"=",
"\"Element on position {$parameter}\"",
";",
"}",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"ARRAY_WRONG_COUNT",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
",",
"'requiredCount'",
"=>",
"$",
"count",
",",
"'currentCount'",
"=>",
"$",
"currentCount",
"]",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
]
| Validate if given value is PHP array
@param mixed $value
@param string $parameter
@param array $args
@param array $rules other rules
@return null|string
@throws ValidatorConfigException
@example 'param' => 'array'
@example 'param' => 'array:5' | [
"Validate",
"if",
"given",
"value",
"is",
"PHP",
"array"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Validator.php#L1999-L2048 | train |
koldy/framework | src/Koldy/Http/Response.php | Response.getHeaders | public function getHeaders(): array
{
if ($this->headers === null && $this->headersText !== null) {
$this->headers = [];
foreach (explode("\n", $this->headersText) as $line) {
$pos = strpos($line, ':');
if ($pos === false) {
// this is one-line header
$this->headers[$line] = null;
} else {
$name = substr($line, 0, $pos);
$value = substr($line, $pos + 1);
$this->headers[$name] = trim($value);
}
}
}
return $this->headers ?? [];
} | php | public function getHeaders(): array
{
if ($this->headers === null && $this->headersText !== null) {
$this->headers = [];
foreach (explode("\n", $this->headersText) as $line) {
$pos = strpos($line, ':');
if ($pos === false) {
// this is one-line header
$this->headers[$line] = null;
} else {
$name = substr($line, 0, $pos);
$value = substr($line, $pos + 1);
$this->headers[$name] = trim($value);
}
}
}
return $this->headers ?? [];
} | [
"public",
"function",
"getHeaders",
"(",
")",
":",
"array",
"{",
"if",
"(",
"$",
"this",
"->",
"headers",
"===",
"null",
"&&",
"$",
"this",
"->",
"headersText",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"headers",
"=",
"[",
"]",
";",
"foreach",
"(",
"explode",
"(",
"\"\\n\"",
",",
"$",
"this",
"->",
"headersText",
")",
"as",
"$",
"line",
")",
"{",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"line",
",",
"':'",
")",
";",
"if",
"(",
"$",
"pos",
"===",
"false",
")",
"{",
"// this is one-line header",
"$",
"this",
"->",
"headers",
"[",
"$",
"line",
"]",
"=",
"null",
";",
"}",
"else",
"{",
"$",
"name",
"=",
"substr",
"(",
"$",
"line",
",",
"0",
",",
"$",
"pos",
")",
";",
"$",
"value",
"=",
"substr",
"(",
"$",
"line",
",",
"$",
"pos",
"+",
"1",
")",
";",
"$",
"this",
"->",
"headers",
"[",
"$",
"name",
"]",
"=",
"trim",
"(",
"$",
"value",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"headers",
"??",
"[",
"]",
";",
"}"
]
| Get all response headers as array where key is the header name and value is header value
@return array | [
"Get",
"all",
"response",
"headers",
"as",
"array",
"where",
"key",
"is",
"the",
"header",
"name",
"and",
"value",
"is",
"header",
"value"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Http/Response.php#L183-L203 | train |
koldy/framework | src/Koldy/Log.php | Log.init | public static function init(): void
{
if (static::$adapters === null) {
static::$randomNumber = rand(100000, 999999);
// set the "who"
static::resetWho();
static::$adapters = [];
$configs = Application::getConfig('application')->get('log', []);
$count = 0;
foreach ($configs as $index => $config) {
$enabled = $config['enabled'] && is_array($config['options']['log']) && count($config['options']['log']) > 0;
// TODO: Register module if needed
if ($enabled) {
if (!isset($config['adapter_class'])) {
throw new ConfigException("Logger[{$index}] defined in application config is missing adapter_class key");
}
// if the config is enabled, then make new instance
$adapter = $config['adapter_class'];
static::$adapters[$count] = new $adapter($config['options']);
// Log class must be instance of AbstractLogAdapter
if (!(static::$adapters[$count] instanceof AbstractLogAdapter)) {
throw new Exception("Log adapter {$adapter} must extend AbstractLogAdapter");
}
static::$enabledAdapters[$config['adapter_class']] = true;
foreach ($config['options']['log'] as $level) {
static::$enabledLevels[$level] = true;
}
$count++;
}
}
}
} | php | public static function init(): void
{
if (static::$adapters === null) {
static::$randomNumber = rand(100000, 999999);
// set the "who"
static::resetWho();
static::$adapters = [];
$configs = Application::getConfig('application')->get('log', []);
$count = 0;
foreach ($configs as $index => $config) {
$enabled = $config['enabled'] && is_array($config['options']['log']) && count($config['options']['log']) > 0;
// TODO: Register module if needed
if ($enabled) {
if (!isset($config['adapter_class'])) {
throw new ConfigException("Logger[{$index}] defined in application config is missing adapter_class key");
}
// if the config is enabled, then make new instance
$adapter = $config['adapter_class'];
static::$adapters[$count] = new $adapter($config['options']);
// Log class must be instance of AbstractLogAdapter
if (!(static::$adapters[$count] instanceof AbstractLogAdapter)) {
throw new Exception("Log adapter {$adapter} must extend AbstractLogAdapter");
}
static::$enabledAdapters[$config['adapter_class']] = true;
foreach ($config['options']['log'] as $level) {
static::$enabledLevels[$level] = true;
}
$count++;
}
}
}
} | [
"public",
"static",
"function",
"init",
"(",
")",
":",
"void",
"{",
"if",
"(",
"static",
"::",
"$",
"adapters",
"===",
"null",
")",
"{",
"static",
"::",
"$",
"randomNumber",
"=",
"rand",
"(",
"100000",
",",
"999999",
")",
";",
"// set the \"who\"",
"static",
"::",
"resetWho",
"(",
")",
";",
"static",
"::",
"$",
"adapters",
"=",
"[",
"]",
";",
"$",
"configs",
"=",
"Application",
"::",
"getConfig",
"(",
"'application'",
")",
"->",
"get",
"(",
"'log'",
",",
"[",
"]",
")",
";",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"configs",
"as",
"$",
"index",
"=>",
"$",
"config",
")",
"{",
"$",
"enabled",
"=",
"$",
"config",
"[",
"'enabled'",
"]",
"&&",
"is_array",
"(",
"$",
"config",
"[",
"'options'",
"]",
"[",
"'log'",
"]",
")",
"&&",
"count",
"(",
"$",
"config",
"[",
"'options'",
"]",
"[",
"'log'",
"]",
")",
">",
"0",
";",
"// TODO: Register module if needed",
"if",
"(",
"$",
"enabled",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'adapter_class'",
"]",
")",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"\"Logger[{$index}] defined in application config is missing adapter_class key\"",
")",
";",
"}",
"// if the config is enabled, then make new instance",
"$",
"adapter",
"=",
"$",
"config",
"[",
"'adapter_class'",
"]",
";",
"static",
"::",
"$",
"adapters",
"[",
"$",
"count",
"]",
"=",
"new",
"$",
"adapter",
"(",
"$",
"config",
"[",
"'options'",
"]",
")",
";",
"// Log class must be instance of AbstractLogAdapter",
"if",
"(",
"!",
"(",
"static",
"::",
"$",
"adapters",
"[",
"$",
"count",
"]",
"instanceof",
"AbstractLogAdapter",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Log adapter {$adapter} must extend AbstractLogAdapter\"",
")",
";",
"}",
"static",
"::",
"$",
"enabledAdapters",
"[",
"$",
"config",
"[",
"'adapter_class'",
"]",
"]",
"=",
"true",
";",
"foreach",
"(",
"$",
"config",
"[",
"'options'",
"]",
"[",
"'log'",
"]",
"as",
"$",
"level",
")",
"{",
"static",
"::",
"$",
"enabledLevels",
"[",
"$",
"level",
"]",
"=",
"true",
";",
"}",
"$",
"count",
"++",
";",
"}",
"}",
"}",
"}"
]
| Initialize, load config and etc.
@throws Exception | [
"Initialize",
"load",
"config",
"and",
"etc",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Log.php#L93-L135 | train |
koldy/framework | src/Koldy/Log.php | Log.resetWho | public static function resetWho(): void
{
if (Application::isCli()) {
static::$who = Application::getCliName() . '-' . static::$randomNumber;
} else {
static::$who = Request::ip() . '-' . static::$randomNumber;
}
} | php | public static function resetWho(): void
{
if (Application::isCli()) {
static::$who = Application::getCliName() . '-' . static::$randomNumber;
} else {
static::$who = Request::ip() . '-' . static::$randomNumber;
}
} | [
"public",
"static",
"function",
"resetWho",
"(",
")",
":",
"void",
"{",
"if",
"(",
"Application",
"::",
"isCli",
"(",
")",
")",
"{",
"static",
"::",
"$",
"who",
"=",
"Application",
"::",
"getCliName",
"(",
")",
".",
"'-'",
".",
"static",
"::",
"$",
"randomNumber",
";",
"}",
"else",
"{",
"static",
"::",
"$",
"who",
"=",
"Request",
"::",
"ip",
"(",
")",
".",
"'-'",
".",
"static",
"::",
"$",
"randomNumber",
";",
"}",
"}"
]
| Reset the "who" value
@throws Exception | [
"Reset",
"the",
"who",
"value"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Log.php#L187-L194 | train |
koldy/framework | src/Koldy/Log.php | Log.temporaryDisable | public static function temporaryDisable($levels = null): void
{
$disable = true;
if (is_array($levels)) {
$disable = $levels;
} else if (is_string($levels)) {
$disable = [$levels];
}
static::$temporaryDisabled = $disable;
} | php | public static function temporaryDisable($levels = null): void
{
$disable = true;
if (is_array($levels)) {
$disable = $levels;
} else if (is_string($levels)) {
$disable = [$levels];
}
static::$temporaryDisabled = $disable;
} | [
"public",
"static",
"function",
"temporaryDisable",
"(",
"$",
"levels",
"=",
"null",
")",
":",
"void",
"{",
"$",
"disable",
"=",
"true",
";",
"if",
"(",
"is_array",
"(",
"$",
"levels",
")",
")",
"{",
"$",
"disable",
"=",
"$",
"levels",
";",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"levels",
")",
")",
"{",
"$",
"disable",
"=",
"[",
"$",
"levels",
"]",
";",
"}",
"static",
"::",
"$",
"temporaryDisabled",
"=",
"$",
"disable",
";",
"}"
]
| Temporary disable all logging
@param array|null ...$levels | [
"Temporary",
"disable",
"all",
"logging"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Log.php#L222-L233 | train |
koldy/framework | src/Koldy/Log.php | Log.emergency | public static function emergency(...$messages): void
{
static::init();
if (!static::isTemporaryDisabled('emergency')) {
foreach (static::$adapters as $adapter) {
/* @var $adapter \Koldy\Log\Adapter\AbstractLogAdapter */
if ($adapter->isLevelEnabled(self::EMERGENCY)) {
$adapter->emergency((new Message(self::EMERGENCY))->setMessages($messages));
}
}
}
} | php | public static function emergency(...$messages): void
{
static::init();
if (!static::isTemporaryDisabled('emergency')) {
foreach (static::$adapters as $adapter) {
/* @var $adapter \Koldy\Log\Adapter\AbstractLogAdapter */
if ($adapter->isLevelEnabled(self::EMERGENCY)) {
$adapter->emergency((new Message(self::EMERGENCY))->setMessages($messages));
}
}
}
} | [
"public",
"static",
"function",
"emergency",
"(",
"...",
"$",
"messages",
")",
":",
"void",
"{",
"static",
"::",
"init",
"(",
")",
";",
"if",
"(",
"!",
"static",
"::",
"isTemporaryDisabled",
"(",
"'emergency'",
")",
")",
"{",
"foreach",
"(",
"static",
"::",
"$",
"adapters",
"as",
"$",
"adapter",
")",
"{",
"/* @var $adapter \\Koldy\\Log\\Adapter\\AbstractLogAdapter */",
"if",
"(",
"$",
"adapter",
"->",
"isLevelEnabled",
"(",
"self",
"::",
"EMERGENCY",
")",
")",
"{",
"$",
"adapter",
"->",
"emergency",
"(",
"(",
"new",
"Message",
"(",
"self",
"::",
"EMERGENCY",
")",
")",
"->",
"setMessages",
"(",
"$",
"messages",
")",
")",
";",
"}",
"}",
"}",
"}"
]
| Write EMERGENCY message to log
@param array|string ...$messages
@link http://koldy.net/docs/log#usage | [
"Write",
"EMERGENCY",
"message",
"to",
"log"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Log.php#L265-L277 | train |
koldy/framework | src/Koldy/Log.php | Log.alert | public static function alert(...$messages): void
{
static::init();
if (!static::isTemporaryDisabled('alert')) {
foreach (static::$adapters as $adapter) {
/* @var $adapter \Koldy\Log\Adapter\AbstractLogAdapter */
if ($adapter->isLevelEnabled(self::ALERT)) {
$adapter->alert((new Message(self::ALERT))->setMessages($messages));
}
}
}
} | php | public static function alert(...$messages): void
{
static::init();
if (!static::isTemporaryDisabled('alert')) {
foreach (static::$adapters as $adapter) {
/* @var $adapter \Koldy\Log\Adapter\AbstractLogAdapter */
if ($adapter->isLevelEnabled(self::ALERT)) {
$adapter->alert((new Message(self::ALERT))->setMessages($messages));
}
}
}
} | [
"public",
"static",
"function",
"alert",
"(",
"...",
"$",
"messages",
")",
":",
"void",
"{",
"static",
"::",
"init",
"(",
")",
";",
"if",
"(",
"!",
"static",
"::",
"isTemporaryDisabled",
"(",
"'alert'",
")",
")",
"{",
"foreach",
"(",
"static",
"::",
"$",
"adapters",
"as",
"$",
"adapter",
")",
"{",
"/* @var $adapter \\Koldy\\Log\\Adapter\\AbstractLogAdapter */",
"if",
"(",
"$",
"adapter",
"->",
"isLevelEnabled",
"(",
"self",
"::",
"ALERT",
")",
")",
"{",
"$",
"adapter",
"->",
"alert",
"(",
"(",
"new",
"Message",
"(",
"self",
"::",
"ALERT",
")",
")",
"->",
"setMessages",
"(",
"$",
"messages",
")",
")",
";",
"}",
"}",
"}",
"}"
]
| Write ALERT message to log
@param array|string ...$messages
@link http://koldy.net/docs/log#usage | [
"Write",
"ALERT",
"message",
"to",
"log"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Log.php#L286-L298 | train |
koldy/framework | src/Koldy/Log.php | Log.critical | public static function critical(...$messages): void
{
static::init();
if (!static::isTemporaryDisabled('critical')) {
foreach (static::$adapters as $adapter) {
/* @var $adapter \Koldy\Log\Adapter\AbstractLogAdapter */
if ($adapter->isLevelEnabled(self::CRITICAL)) {
$adapter->critical((new Message(self::CRITICAL))->setMessages($messages));
}
}
}
} | php | public static function critical(...$messages): void
{
static::init();
if (!static::isTemporaryDisabled('critical')) {
foreach (static::$adapters as $adapter) {
/* @var $adapter \Koldy\Log\Adapter\AbstractLogAdapter */
if ($adapter->isLevelEnabled(self::CRITICAL)) {
$adapter->critical((new Message(self::CRITICAL))->setMessages($messages));
}
}
}
} | [
"public",
"static",
"function",
"critical",
"(",
"...",
"$",
"messages",
")",
":",
"void",
"{",
"static",
"::",
"init",
"(",
")",
";",
"if",
"(",
"!",
"static",
"::",
"isTemporaryDisabled",
"(",
"'critical'",
")",
")",
"{",
"foreach",
"(",
"static",
"::",
"$",
"adapters",
"as",
"$",
"adapter",
")",
"{",
"/* @var $adapter \\Koldy\\Log\\Adapter\\AbstractLogAdapter */",
"if",
"(",
"$",
"adapter",
"->",
"isLevelEnabled",
"(",
"self",
"::",
"CRITICAL",
")",
")",
"{",
"$",
"adapter",
"->",
"critical",
"(",
"(",
"new",
"Message",
"(",
"self",
"::",
"CRITICAL",
")",
")",
"->",
"setMessages",
"(",
"$",
"messages",
")",
")",
";",
"}",
"}",
"}",
"}"
]
| Write CRITICAL message to log
@param array|string ...$messages
@link http://koldy.net/docs/log#usage | [
"Write",
"CRITICAL",
"message",
"to",
"log"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Log.php#L307-L319 | train |
koldy/framework | src/Koldy/Log.php | Log.debug | public static function debug(...$messages): void
{
static::init();
if (!static::isTemporaryDisabled('debug')) {
foreach (static::$adapters as $adapter) {
/* @var $adapter \Koldy\Log\Adapter\AbstractLogAdapter */
if ($adapter->isLevelEnabled(self::DEBUG)) {
$adapter->debug((new Message(self::DEBUG))->setMessages($messages));
}
}
}
} | php | public static function debug(...$messages): void
{
static::init();
if (!static::isTemporaryDisabled('debug')) {
foreach (static::$adapters as $adapter) {
/* @var $adapter \Koldy\Log\Adapter\AbstractLogAdapter */
if ($adapter->isLevelEnabled(self::DEBUG)) {
$adapter->debug((new Message(self::DEBUG))->setMessages($messages));
}
}
}
} | [
"public",
"static",
"function",
"debug",
"(",
"...",
"$",
"messages",
")",
":",
"void",
"{",
"static",
"::",
"init",
"(",
")",
";",
"if",
"(",
"!",
"static",
"::",
"isTemporaryDisabled",
"(",
"'debug'",
")",
")",
"{",
"foreach",
"(",
"static",
"::",
"$",
"adapters",
"as",
"$",
"adapter",
")",
"{",
"/* @var $adapter \\Koldy\\Log\\Adapter\\AbstractLogAdapter */",
"if",
"(",
"$",
"adapter",
"->",
"isLevelEnabled",
"(",
"self",
"::",
"DEBUG",
")",
")",
"{",
"$",
"adapter",
"->",
"debug",
"(",
"(",
"new",
"Message",
"(",
"self",
"::",
"DEBUG",
")",
")",
"->",
"setMessages",
"(",
"$",
"messages",
")",
")",
";",
"}",
"}",
"}",
"}"
]
| Write DEBUG message to log
@param array|string ...$messages
@link http://koldy.net/docs/log#usage | [
"Write",
"DEBUG",
"message",
"to",
"log"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Log.php#L328-L340 | train |
koldy/framework | src/Koldy/Log.php | Log.notice | public static function notice(...$messages): void
{
static::init();
if (!static::isTemporaryDisabled('notice')) {
foreach (static::$adapters as $adapter) {
/* @var $adapter \Koldy\Log\Adapter\AbstractLogAdapter */
if ($adapter->isLevelEnabled(self::NOTICE)) {
$adapter->notice((new Message(self::NOTICE))->setMessages($messages));
}
}
}
} | php | public static function notice(...$messages): void
{
static::init();
if (!static::isTemporaryDisabled('notice')) {
foreach (static::$adapters as $adapter) {
/* @var $adapter \Koldy\Log\Adapter\AbstractLogAdapter */
if ($adapter->isLevelEnabled(self::NOTICE)) {
$adapter->notice((new Message(self::NOTICE))->setMessages($messages));
}
}
}
} | [
"public",
"static",
"function",
"notice",
"(",
"...",
"$",
"messages",
")",
":",
"void",
"{",
"static",
"::",
"init",
"(",
")",
";",
"if",
"(",
"!",
"static",
"::",
"isTemporaryDisabled",
"(",
"'notice'",
")",
")",
"{",
"foreach",
"(",
"static",
"::",
"$",
"adapters",
"as",
"$",
"adapter",
")",
"{",
"/* @var $adapter \\Koldy\\Log\\Adapter\\AbstractLogAdapter */",
"if",
"(",
"$",
"adapter",
"->",
"isLevelEnabled",
"(",
"self",
"::",
"NOTICE",
")",
")",
"{",
"$",
"adapter",
"->",
"notice",
"(",
"(",
"new",
"Message",
"(",
"self",
"::",
"NOTICE",
")",
")",
"->",
"setMessages",
"(",
"$",
"messages",
")",
")",
";",
"}",
"}",
"}",
"}"
]
| Write NOTICE message to log
@param array|string ...$messages
@link http://koldy.net/docs/log#usage | [
"Write",
"NOTICE",
"message",
"to",
"log"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Log.php#L349-L361 | train |
koldy/framework | src/Koldy/Log.php | Log.info | public static function info(...$messages): void
{
static::init();
if (!static::isTemporaryDisabled('info')) {
foreach (static::$adapters as $adapter) {
/* @var $adapter \Koldy\Log\Adapter\AbstractLogAdapter */
if ($adapter->isLevelEnabled(self::INFO)) {
$adapter->info((new Message(self::INFO))->setMessages($messages));
}
}
}
} | php | public static function info(...$messages): void
{
static::init();
if (!static::isTemporaryDisabled('info')) {
foreach (static::$adapters as $adapter) {
/* @var $adapter \Koldy\Log\Adapter\AbstractLogAdapter */
if ($adapter->isLevelEnabled(self::INFO)) {
$adapter->info((new Message(self::INFO))->setMessages($messages));
}
}
}
} | [
"public",
"static",
"function",
"info",
"(",
"...",
"$",
"messages",
")",
":",
"void",
"{",
"static",
"::",
"init",
"(",
")",
";",
"if",
"(",
"!",
"static",
"::",
"isTemporaryDisabled",
"(",
"'info'",
")",
")",
"{",
"foreach",
"(",
"static",
"::",
"$",
"adapters",
"as",
"$",
"adapter",
")",
"{",
"/* @var $adapter \\Koldy\\Log\\Adapter\\AbstractLogAdapter */",
"if",
"(",
"$",
"adapter",
"->",
"isLevelEnabled",
"(",
"self",
"::",
"INFO",
")",
")",
"{",
"$",
"adapter",
"->",
"info",
"(",
"(",
"new",
"Message",
"(",
"self",
"::",
"INFO",
")",
")",
"->",
"setMessages",
"(",
"$",
"messages",
")",
")",
";",
"}",
"}",
"}",
"}"
]
| Write INFO message to log
@param array|string ...$messages
@link http://koldy.net/docs/log#usage | [
"Write",
"INFO",
"message",
"to",
"log"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Log.php#L370-L382 | train |
koldy/framework | src/Koldy/Log.php | Log.warning | public static function warning(...$messages): void
{
static::init();
if (!static::isTemporaryDisabled('warning')) {
foreach (static::$adapters as $adapter) {
/* @var $adapter \Koldy\Log\Adapter\AbstractLogAdapter */
if ($adapter->isLevelEnabled(self::WARNING)) {
$adapter->warning((new Message(self::WARNING))->setMessages($messages));
}
}
}
} | php | public static function warning(...$messages): void
{
static::init();
if (!static::isTemporaryDisabled('warning')) {
foreach (static::$adapters as $adapter) {
/* @var $adapter \Koldy\Log\Adapter\AbstractLogAdapter */
if ($adapter->isLevelEnabled(self::WARNING)) {
$adapter->warning((new Message(self::WARNING))->setMessages($messages));
}
}
}
} | [
"public",
"static",
"function",
"warning",
"(",
"...",
"$",
"messages",
")",
":",
"void",
"{",
"static",
"::",
"init",
"(",
")",
";",
"if",
"(",
"!",
"static",
"::",
"isTemporaryDisabled",
"(",
"'warning'",
")",
")",
"{",
"foreach",
"(",
"static",
"::",
"$",
"adapters",
"as",
"$",
"adapter",
")",
"{",
"/* @var $adapter \\Koldy\\Log\\Adapter\\AbstractLogAdapter */",
"if",
"(",
"$",
"adapter",
"->",
"isLevelEnabled",
"(",
"self",
"::",
"WARNING",
")",
")",
"{",
"$",
"adapter",
"->",
"warning",
"(",
"(",
"new",
"Message",
"(",
"self",
"::",
"WARNING",
")",
")",
"->",
"setMessages",
"(",
"$",
"messages",
")",
")",
";",
"}",
"}",
"}",
"}"
]
| Write WARNING message to log
@param array|string ...$messages
@link http://koldy.net/docs/log#usage | [
"Write",
"WARNING",
"message",
"to",
"log"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Log.php#L391-L403 | train |
koldy/framework | src/Koldy/Log.php | Log.error | public static function error(...$messages): void
{
static::init();
if (!static::isTemporaryDisabled('error')) {
foreach (static::$adapters as $adapter) {
/* @var $adapter \Koldy\Log\Adapter\AbstractLogAdapter */
if ($adapter->isLevelEnabled(self::ERROR)) {
$adapter->error((new Message(self::ERROR))->setMessages($messages));
}
}
}
} | php | public static function error(...$messages): void
{
static::init();
if (!static::isTemporaryDisabled('error')) {
foreach (static::$adapters as $adapter) {
/* @var $adapter \Koldy\Log\Adapter\AbstractLogAdapter */
if ($adapter->isLevelEnabled(self::ERROR)) {
$adapter->error((new Message(self::ERROR))->setMessages($messages));
}
}
}
} | [
"public",
"static",
"function",
"error",
"(",
"...",
"$",
"messages",
")",
":",
"void",
"{",
"static",
"::",
"init",
"(",
")",
";",
"if",
"(",
"!",
"static",
"::",
"isTemporaryDisabled",
"(",
"'error'",
")",
")",
"{",
"foreach",
"(",
"static",
"::",
"$",
"adapters",
"as",
"$",
"adapter",
")",
"{",
"/* @var $adapter \\Koldy\\Log\\Adapter\\AbstractLogAdapter */",
"if",
"(",
"$",
"adapter",
"->",
"isLevelEnabled",
"(",
"self",
"::",
"ERROR",
")",
")",
"{",
"$",
"adapter",
"->",
"error",
"(",
"(",
"new",
"Message",
"(",
"self",
"::",
"ERROR",
")",
")",
"->",
"setMessages",
"(",
"$",
"messages",
")",
")",
";",
"}",
"}",
"}",
"}"
]
| Write ERROR message to log
@param array|string ...$messages
@link http://koldy.net/docs/log#usage | [
"Write",
"ERROR",
"message",
"to",
"log"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Log.php#L412-L424 | train |
koldy/framework | src/Koldy/Log.php | Log.sql | public static function sql(...$messages): void
{
static::init();
if (!static::isTemporaryDisabled('sql')) {
foreach (static::$adapters as $adapter) {
/* @var $adapter \Koldy\Log\Adapter\AbstractLogAdapter */
if ($adapter->isLevelEnabled(self::SQL)) {
$adapter->sql((new Message(self::SQL))->setMessages($messages));
}
}
}
} | php | public static function sql(...$messages): void
{
static::init();
if (!static::isTemporaryDisabled('sql')) {
foreach (static::$adapters as $adapter) {
/* @var $adapter \Koldy\Log\Adapter\AbstractLogAdapter */
if ($adapter->isLevelEnabled(self::SQL)) {
$adapter->sql((new Message(self::SQL))->setMessages($messages));
}
}
}
} | [
"public",
"static",
"function",
"sql",
"(",
"...",
"$",
"messages",
")",
":",
"void",
"{",
"static",
"::",
"init",
"(",
")",
";",
"if",
"(",
"!",
"static",
"::",
"isTemporaryDisabled",
"(",
"'sql'",
")",
")",
"{",
"foreach",
"(",
"static",
"::",
"$",
"adapters",
"as",
"$",
"adapter",
")",
"{",
"/* @var $adapter \\Koldy\\Log\\Adapter\\AbstractLogAdapter */",
"if",
"(",
"$",
"adapter",
"->",
"isLevelEnabled",
"(",
"self",
"::",
"SQL",
")",
")",
"{",
"$",
"adapter",
"->",
"sql",
"(",
"(",
"new",
"Message",
"(",
"self",
"::",
"SQL",
")",
")",
"->",
"setMessages",
"(",
"$",
"messages",
")",
")",
";",
"}",
"}",
"}",
"}"
]
| Write SQL query to log
@param array|string ...$messages
@link http://koldy.net/docs/log#usage | [
"Write",
"SQL",
"query",
"to",
"log"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Log.php#L433-L445 | train |
koldy/framework | src/Koldy/Log.php | Log.message | public static function message(Message $message): void
{
static::init();
foreach (static::$adapters as $adapter) {
/* @var $adapter \Koldy\Log\Adapter\AbstractLogAdapter */
if ($adapter->isLevelEnabled($message->getLevel())) {
$adapter->logMessage($message);
}
}
} | php | public static function message(Message $message): void
{
static::init();
foreach (static::$adapters as $adapter) {
/* @var $adapter \Koldy\Log\Adapter\AbstractLogAdapter */
if ($adapter->isLevelEnabled($message->getLevel())) {
$adapter->logMessage($message);
}
}
} | [
"public",
"static",
"function",
"message",
"(",
"Message",
"$",
"message",
")",
":",
"void",
"{",
"static",
"::",
"init",
"(",
")",
";",
"foreach",
"(",
"static",
"::",
"$",
"adapters",
"as",
"$",
"adapter",
")",
"{",
"/* @var $adapter \\Koldy\\Log\\Adapter\\AbstractLogAdapter */",
"if",
"(",
"$",
"adapter",
"->",
"isLevelEnabled",
"(",
"$",
"message",
"->",
"getLevel",
"(",
")",
")",
")",
"{",
"$",
"adapter",
"->",
"logMessage",
"(",
"$",
"message",
")",
";",
"}",
"}",
"}"
]
| Log message with prepared Log\Message instance
@param Message $message | [
"Log",
"message",
"with",
"prepared",
"Log",
"\\",
"Message",
"instance"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Log.php#L452-L462 | train |
koldy/framework | src/Koldy/Util.php | Util.str2hex | public static function str2hex(string $x): string
{
$string = '';
foreach (str_split($x) as $char) {
$string .= sprintf('%02X', ord($char));
}
return $string;
} | php | public static function str2hex(string $x): string
{
$string = '';
foreach (str_split($x) as $char) {
$string .= sprintf('%02X', ord($char));
}
return $string;
} | [
"public",
"static",
"function",
"str2hex",
"(",
"string",
"$",
"x",
")",
":",
"string",
"{",
"$",
"string",
"=",
"''",
";",
"foreach",
"(",
"str_split",
"(",
"$",
"x",
")",
"as",
"$",
"char",
")",
"{",
"$",
"string",
".=",
"sprintf",
"(",
"'%02X'",
",",
"ord",
"(",
"$",
"char",
")",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
]
| Get the hex representation of string
@param string $x
@return string | [
"Get",
"the",
"hex",
"representation",
"of",
"string"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Util.php#L49-L58 | train |
koldy/framework | src/Koldy/Util.php | Util.truncate | public static function truncate(string $string, int $length = 80, string $etc = '...', bool $breakWords = false, bool $middle = false): string
{
if ($length == 0) {
return '';
}
$encoding = Application::getEncoding();
if (mb_strlen($string, $encoding) > $length) {
$length -= min($length, mb_strlen($etc, $encoding));
if (!$breakWords && !$middle) {
$string = preg_replace('/\s+?(\S+)?$/', '', mb_substr($string, 0, $length + 1, $encoding));
}
if (!$middle) {
return mb_substr($string, 0, $length, $encoding) . $etc;
} else {
return mb_substr($string, 0, (int)round($length / 2), $encoding) . $etc . mb_substr($string, (int)round(-$length / 2), null, $encoding);
}
} else {
return $string;
}
} | php | public static function truncate(string $string, int $length = 80, string $etc = '...', bool $breakWords = false, bool $middle = false): string
{
if ($length == 0) {
return '';
}
$encoding = Application::getEncoding();
if (mb_strlen($string, $encoding) > $length) {
$length -= min($length, mb_strlen($etc, $encoding));
if (!$breakWords && !$middle) {
$string = preg_replace('/\s+?(\S+)?$/', '', mb_substr($string, 0, $length + 1, $encoding));
}
if (!$middle) {
return mb_substr($string, 0, $length, $encoding) . $etc;
} else {
return mb_substr($string, 0, (int)round($length / 2), $encoding) . $etc . mb_substr($string, (int)round(-$length / 2), null, $encoding);
}
} else {
return $string;
}
} | [
"public",
"static",
"function",
"truncate",
"(",
"string",
"$",
"string",
",",
"int",
"$",
"length",
"=",
"80",
",",
"string",
"$",
"etc",
"=",
"'...'",
",",
"bool",
"$",
"breakWords",
"=",
"false",
",",
"bool",
"$",
"middle",
"=",
"false",
")",
":",
"string",
"{",
"if",
"(",
"$",
"length",
"==",
"0",
")",
"{",
"return",
"''",
";",
"}",
"$",
"encoding",
"=",
"Application",
"::",
"getEncoding",
"(",
")",
";",
"if",
"(",
"mb_strlen",
"(",
"$",
"string",
",",
"$",
"encoding",
")",
">",
"$",
"length",
")",
"{",
"$",
"length",
"-=",
"min",
"(",
"$",
"length",
",",
"mb_strlen",
"(",
"$",
"etc",
",",
"$",
"encoding",
")",
")",
";",
"if",
"(",
"!",
"$",
"breakWords",
"&&",
"!",
"$",
"middle",
")",
"{",
"$",
"string",
"=",
"preg_replace",
"(",
"'/\\s+?(\\S+)?$/'",
",",
"''",
",",
"mb_substr",
"(",
"$",
"string",
",",
"0",
",",
"$",
"length",
"+",
"1",
",",
"$",
"encoding",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"middle",
")",
"{",
"return",
"mb_substr",
"(",
"$",
"string",
",",
"0",
",",
"$",
"length",
",",
"$",
"encoding",
")",
".",
"$",
"etc",
";",
"}",
"else",
"{",
"return",
"mb_substr",
"(",
"$",
"string",
",",
"0",
",",
"(",
"int",
")",
"round",
"(",
"$",
"length",
"/",
"2",
")",
",",
"$",
"encoding",
")",
".",
"$",
"etc",
".",
"mb_substr",
"(",
"$",
"string",
",",
"(",
"int",
")",
"round",
"(",
"-",
"$",
"length",
"/",
"2",
")",
",",
"null",
",",
"$",
"encoding",
")",
";",
"}",
"}",
"else",
"{",
"return",
"$",
"string",
";",
"}",
"}"
]
| Truncate the long string properly
@param string $string
@param int $length default 80 [optional]
@param string $etc suffix string [optional] default '...'
@param bool $breakWords [optional] default false, true to cut the words in text
@param bool $middle [optional] default false
@return string
@throws Exception | [
"Truncate",
"the",
"long",
"string",
"properly"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Util.php#L127-L150 | train |
koldy/framework | src/Koldy/Util.php | Util.a | public static function a(string $text, string $target = null): string
{
return preg_replace('@((https?://)?([-\w]+\.[-\w\.]+)+\w(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)*)@',
"<a href=\"\$1\"" . ($target != null ? " target=\"{$target}\"" : '') . ">$1</a>", $text);
} | php | public static function a(string $text, string $target = null): string
{
return preg_replace('@((https?://)?([-\w]+\.[-\w\.]+)+\w(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)*)@',
"<a href=\"\$1\"" . ($target != null ? " target=\"{$target}\"" : '') . ">$1</a>", $text);
} | [
"public",
"static",
"function",
"a",
"(",
"string",
"$",
"text",
",",
"string",
"$",
"target",
"=",
"null",
")",
":",
"string",
"{",
"return",
"preg_replace",
"(",
"'@((https?://)?([-\\w]+\\.[-\\w\\.]+)+\\w(:\\d+)?(/([-\\w/_\\.]*(\\?\\S+)?)?)*)@'",
",",
"\"<a href=\\\"\\$1\\\"\"",
".",
"(",
"$",
"target",
"!=",
"null",
"?",
"\" target=\\\"{$target}\\\"\"",
":",
"''",
")",
".",
"\">$1</a>\"",
",",
"$",
"text",
")",
";",
"}"
]
| Detect URLs in text and replace them with HTML A tag
@param string $text
@param string $target optional, default _blank
@return string | [
"Detect",
"URLs",
"in",
"text",
"and",
"replace",
"them",
"with",
"HTML",
"A",
"tag"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Util.php#L177-L181 | train |
koldy/framework | src/Koldy/Util.php | Util.startsWith | public static function startsWith(string $yourString, string $startsWith, string $encoding = null): bool
{
return mb_substr($yourString, 0, mb_strlen($startsWith, $encoding ?? Application::getEncoding()), $encoding ?? Application::getEncoding()) === $startsWith;
} | php | public static function startsWith(string $yourString, string $startsWith, string $encoding = null): bool
{
return mb_substr($yourString, 0, mb_strlen($startsWith, $encoding ?? Application::getEncoding()), $encoding ?? Application::getEncoding()) === $startsWith;
} | [
"public",
"static",
"function",
"startsWith",
"(",
"string",
"$",
"yourString",
",",
"string",
"$",
"startsWith",
",",
"string",
"$",
"encoding",
"=",
"null",
")",
":",
"bool",
"{",
"return",
"mb_substr",
"(",
"$",
"yourString",
",",
"0",
",",
"mb_strlen",
"(",
"$",
"startsWith",
",",
"$",
"encoding",
"??",
"Application",
"::",
"getEncoding",
"(",
")",
")",
",",
"$",
"encoding",
"??",
"Application",
"::",
"getEncoding",
"(",
")",
")",
"===",
"$",
"startsWith",
";",
"}"
]
| Check if string starts with given string - it supports UTF-8, but it's case sensitive
@param string $yourString
@param string $startsWith
@param string|null $encoding - by default, using application config (encoding) or uses UTF-8 by default
@return bool
@throws Exception | [
"Check",
"if",
"string",
"starts",
"with",
"given",
"string",
"-",
"it",
"supports",
"UTF",
"-",
"8",
"but",
"it",
"s",
"case",
"sensitive"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Util.php#L205-L208 | train |
koldy/framework | src/Koldy/Util.php | Util.endsWith | public static function endsWith(string $yourString, string $endsWith, string $encoding = null): bool
{
return mb_substr($yourString, 0 - mb_strlen($endsWith, $encoding ?? Application::getEncoding()), null, $encoding ?? Application::getEncoding()) === $endsWith;
} | php | public static function endsWith(string $yourString, string $endsWith, string $encoding = null): bool
{
return mb_substr($yourString, 0 - mb_strlen($endsWith, $encoding ?? Application::getEncoding()), null, $encoding ?? Application::getEncoding()) === $endsWith;
} | [
"public",
"static",
"function",
"endsWith",
"(",
"string",
"$",
"yourString",
",",
"string",
"$",
"endsWith",
",",
"string",
"$",
"encoding",
"=",
"null",
")",
":",
"bool",
"{",
"return",
"mb_substr",
"(",
"$",
"yourString",
",",
"0",
"-",
"mb_strlen",
"(",
"$",
"endsWith",
",",
"$",
"encoding",
"??",
"Application",
"::",
"getEncoding",
"(",
")",
")",
",",
"null",
",",
"$",
"encoding",
"??",
"Application",
"::",
"getEncoding",
"(",
")",
")",
"===",
"$",
"endsWith",
";",
"}"
]
| Check if string ends with given string - it supports UTF-8, but it's case sensitive
@param string $yourString
@param string $endsWith
@param string|null $encoding - by default, using application config (encoding) or uses UTF-8 by default
@return bool
@throws Exception | [
"Check",
"if",
"string",
"ends",
"with",
"given",
"string",
"-",
"it",
"supports",
"UTF",
"-",
"8",
"but",
"it",
"s",
"case",
"sensitive"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Util.php#L220-L223 | train |
koldy/framework | src/Koldy/Util.php | Util.camelCase | public static function camelCase(string $string, array $noStrip = null, bool $lowerCaseFirstLetter = null)
{
// non-alpha and non-numeric characters become spaces
$string = preg_replace('/[^a-z0-9' . implode('', $noStrip ?? []) . ']+/i', ' ', $string);
$string = trim($string);
$string = ucwords($string);
$string = str_replace(' ', '', $string);
if ($lowerCaseFirstLetter === null || $lowerCaseFirstLetter === true) {
$string = lcfirst($string);
}
return $string;
} | php | public static function camelCase(string $string, array $noStrip = null, bool $lowerCaseFirstLetter = null)
{
// non-alpha and non-numeric characters become spaces
$string = preg_replace('/[^a-z0-9' . implode('', $noStrip ?? []) . ']+/i', ' ', $string);
$string = trim($string);
$string = ucwords($string);
$string = str_replace(' ', '', $string);
if ($lowerCaseFirstLetter === null || $lowerCaseFirstLetter === true) {
$string = lcfirst($string);
}
return $string;
} | [
"public",
"static",
"function",
"camelCase",
"(",
"string",
"$",
"string",
",",
"array",
"$",
"noStrip",
"=",
"null",
",",
"bool",
"$",
"lowerCaseFirstLetter",
"=",
"null",
")",
"{",
"// non-alpha and non-numeric characters become spaces",
"$",
"string",
"=",
"preg_replace",
"(",
"'/[^a-z0-9'",
".",
"implode",
"(",
"''",
",",
"$",
"noStrip",
"??",
"[",
"]",
")",
".",
"']+/i'",
",",
"' '",
",",
"$",
"string",
")",
";",
"$",
"string",
"=",
"trim",
"(",
"$",
"string",
")",
";",
"$",
"string",
"=",
"ucwords",
"(",
"$",
"string",
")",
";",
"$",
"string",
"=",
"str_replace",
"(",
"' '",
",",
"''",
",",
"$",
"string",
")",
";",
"if",
"(",
"$",
"lowerCaseFirstLetter",
"===",
"null",
"||",
"$",
"lowerCaseFirstLetter",
"===",
"true",
")",
"{",
"$",
"string",
"=",
"lcfirst",
"(",
"$",
"string",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
]
| Make a camel case string out of given string
@param string $string
@param array|null $noStrip
@param bool|null $lowerCaseFirstLetter
@return mixed|string | [
"Make",
"a",
"camel",
"case",
"string",
"out",
"of",
"given",
"string"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Util.php#L383-L396 | train |
koldy/framework | src/Koldy/Log/Adapter/AbstractLogAdapter.php | AbstractLogAdapter.dump | public function dump(): void
{
$dump = $this->config['dump'] ?? [];
if (is_array($dump) && count($dump) > 0) {
// 'speed', 'included_files', 'include_path', 'whitespace'
$dump = array_flip($dump);
$url = isset($_SERVER['REQUEST_METHOD']) ? ($_SERVER['REQUEST_METHOD'] . '=' . Application::getCurrentURL()) : ('CLI=' . Application::getCliName());
if (array_key_exists('speed', $dump)) {
$executedIn = Application::getRequestExecutionTime();
$count = count(get_included_files());
$this->logMessage(new Message('notice', "{$url} EXECUTED IN {$executedIn}ms, used {$count} files"));
}
if (array_key_exists('memory', $dump)) {
$memory = memory_get_usage();
$peak = memory_get_peak_usage();
$allocatedMemory = memory_get_peak_usage(true);
$memoryLimit = ini_get('memory_limit') ?? -1;
$memoryKb = round($memory / 1024, 2);
$peakKb = round($peak / 1024, 2);
$allocatedMemoryKb = round($allocatedMemory / 1024, 2);
$limit = '';
$peakSpent = '';
if ($memoryLimit > 0) {
$limitInt = Convert::stringToBytes($memoryLimit);
$limit = ", limit: {$memoryLimit}";
$spent = round($peak / $limitInt * 100, 2);
$peakSpent = " ({$spent}% of limit)";
}
$this->logMessage(new Message('notice', "{$url} CONSUMED MEM: current: {$memoryKb}kb, peak: {$peakKb}kb{$peakSpent}, allocated: {$allocatedMemoryKb}kb{$limit}"));
}
if (array_key_exists('included_files', $dump)) {
$this->logMessage(new Message('notice', 'Included files: ' . print_r(get_included_files(), true)));
}
if (array_key_exists('whitespace', $dump)) {
$this->logMessage(new Message('notice', "END OF {$url}\n" . str_repeat('#', 120) . "\n\n"));
}
}
} | php | public function dump(): void
{
$dump = $this->config['dump'] ?? [];
if (is_array($dump) && count($dump) > 0) {
// 'speed', 'included_files', 'include_path', 'whitespace'
$dump = array_flip($dump);
$url = isset($_SERVER['REQUEST_METHOD']) ? ($_SERVER['REQUEST_METHOD'] . '=' . Application::getCurrentURL()) : ('CLI=' . Application::getCliName());
if (array_key_exists('speed', $dump)) {
$executedIn = Application::getRequestExecutionTime();
$count = count(get_included_files());
$this->logMessage(new Message('notice', "{$url} EXECUTED IN {$executedIn}ms, used {$count} files"));
}
if (array_key_exists('memory', $dump)) {
$memory = memory_get_usage();
$peak = memory_get_peak_usage();
$allocatedMemory = memory_get_peak_usage(true);
$memoryLimit = ini_get('memory_limit') ?? -1;
$memoryKb = round($memory / 1024, 2);
$peakKb = round($peak / 1024, 2);
$allocatedMemoryKb = round($allocatedMemory / 1024, 2);
$limit = '';
$peakSpent = '';
if ($memoryLimit > 0) {
$limitInt = Convert::stringToBytes($memoryLimit);
$limit = ", limit: {$memoryLimit}";
$spent = round($peak / $limitInt * 100, 2);
$peakSpent = " ({$spent}% of limit)";
}
$this->logMessage(new Message('notice', "{$url} CONSUMED MEM: current: {$memoryKb}kb, peak: {$peakKb}kb{$peakSpent}, allocated: {$allocatedMemoryKb}kb{$limit}"));
}
if (array_key_exists('included_files', $dump)) {
$this->logMessage(new Message('notice', 'Included files: ' . print_r(get_included_files(), true)));
}
if (array_key_exists('whitespace', $dump)) {
$this->logMessage(new Message('notice', "END OF {$url}\n" . str_repeat('#', 120) . "\n\n"));
}
}
} | [
"public",
"function",
"dump",
"(",
")",
":",
"void",
"{",
"$",
"dump",
"=",
"$",
"this",
"->",
"config",
"[",
"'dump'",
"]",
"??",
"[",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"dump",
")",
"&&",
"count",
"(",
"$",
"dump",
")",
">",
"0",
")",
"{",
"// 'speed', 'included_files', 'include_path', 'whitespace'",
"$",
"dump",
"=",
"array_flip",
"(",
"$",
"dump",
")",
";",
"$",
"url",
"=",
"isset",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
")",
"?",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
".",
"'='",
".",
"Application",
"::",
"getCurrentURL",
"(",
")",
")",
":",
"(",
"'CLI='",
".",
"Application",
"::",
"getCliName",
"(",
")",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'speed'",
",",
"$",
"dump",
")",
")",
"{",
"$",
"executedIn",
"=",
"Application",
"::",
"getRequestExecutionTime",
"(",
")",
";",
"$",
"count",
"=",
"count",
"(",
"get_included_files",
"(",
")",
")",
";",
"$",
"this",
"->",
"logMessage",
"(",
"new",
"Message",
"(",
"'notice'",
",",
"\"{$url} EXECUTED IN {$executedIn}ms, used {$count} files\"",
")",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"'memory'",
",",
"$",
"dump",
")",
")",
"{",
"$",
"memory",
"=",
"memory_get_usage",
"(",
")",
";",
"$",
"peak",
"=",
"memory_get_peak_usage",
"(",
")",
";",
"$",
"allocatedMemory",
"=",
"memory_get_peak_usage",
"(",
"true",
")",
";",
"$",
"memoryLimit",
"=",
"ini_get",
"(",
"'memory_limit'",
")",
"??",
"-",
"1",
";",
"$",
"memoryKb",
"=",
"round",
"(",
"$",
"memory",
"/",
"1024",
",",
"2",
")",
";",
"$",
"peakKb",
"=",
"round",
"(",
"$",
"peak",
"/",
"1024",
",",
"2",
")",
";",
"$",
"allocatedMemoryKb",
"=",
"round",
"(",
"$",
"allocatedMemory",
"/",
"1024",
",",
"2",
")",
";",
"$",
"limit",
"=",
"''",
";",
"$",
"peakSpent",
"=",
"''",
";",
"if",
"(",
"$",
"memoryLimit",
">",
"0",
")",
"{",
"$",
"limitInt",
"=",
"Convert",
"::",
"stringToBytes",
"(",
"$",
"memoryLimit",
")",
";",
"$",
"limit",
"=",
"\", limit: {$memoryLimit}\"",
";",
"$",
"spent",
"=",
"round",
"(",
"$",
"peak",
"/",
"$",
"limitInt",
"*",
"100",
",",
"2",
")",
";",
"$",
"peakSpent",
"=",
"\" ({$spent}% of limit)\"",
";",
"}",
"$",
"this",
"->",
"logMessage",
"(",
"new",
"Message",
"(",
"'notice'",
",",
"\"{$url} CONSUMED MEM: current: {$memoryKb}kb, peak: {$peakKb}kb{$peakSpent}, allocated: {$allocatedMemoryKb}kb{$limit}\"",
")",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"'included_files'",
",",
"$",
"dump",
")",
")",
"{",
"$",
"this",
"->",
"logMessage",
"(",
"new",
"Message",
"(",
"'notice'",
",",
"'Included files: '",
".",
"print_r",
"(",
"get_included_files",
"(",
")",
",",
"true",
")",
")",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"'whitespace'",
",",
"$",
"dump",
")",
")",
"{",
"$",
"this",
"->",
"logMessage",
"(",
"new",
"Message",
"(",
"'notice'",
",",
"\"END OF {$url}\\n\"",
".",
"str_repeat",
"(",
"'#'",
",",
"120",
")",
".",
"\"\\n\\n\"",
")",
")",
";",
"}",
"}",
"}"
]
| Dump some common stuff into log according to config
@throws Convert\Exception
@throws \Koldy\Exception | [
"Dump",
"some",
"common",
"stuff",
"into",
"log",
"according",
"to",
"config"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Log/Adapter/AbstractLogAdapter.php#L185-L233 | train |
koldy/framework | src/Koldy/Server.php | Server.getServerLoad | public static function getServerLoad(): string
{
if (function_exists('sys_getloadavg')) {
$a = sys_getloadavg();
foreach ($a as $k => $v) {
$a[$k] = round($v, 2);
}
return implode(', ', $a);
} else {
$os = strtolower(PHP_OS);
if (strpos($os, 'win') === false) {
if (@file_exists('/proc/loadavg') && @is_readable('/proc/loadavg')) {
$load = file_get_contents('/proc/loadavg');
$load = explode(' ', $load);
return implode(',', $load);
} else if (function_exists('shell_exec')) {
$load = @shell_exec('uptime');
$load = explode('load average' . (PHP_OS == 'Darwin' ? 's' : '') . ':', $load);
return implode(',', $load);
//return $load[count($load)-1];
} else {
throw new Exception('Unable to get server load');
}
} else if (class_exists('COM')) {
$wmi = new \COM("WinMgmts:\\\\.");
$CPUs = $wmi->InstancesOf('Win32_Processor');
$cpuLoad = 0;
$i = 0;
while ($cpu = $CPUs->Next()) {
$cpuLoad += $cpu->LoadPercentage;
$i++;
}
$cpuLoad = round($cpuLoad / $i, 2);
return $cpuLoad . '%';
}
}
throw new Exception('Unable to get server load');
} | php | public static function getServerLoad(): string
{
if (function_exists('sys_getloadavg')) {
$a = sys_getloadavg();
foreach ($a as $k => $v) {
$a[$k] = round($v, 2);
}
return implode(', ', $a);
} else {
$os = strtolower(PHP_OS);
if (strpos($os, 'win') === false) {
if (@file_exists('/proc/loadavg') && @is_readable('/proc/loadavg')) {
$load = file_get_contents('/proc/loadavg');
$load = explode(' ', $load);
return implode(',', $load);
} else if (function_exists('shell_exec')) {
$load = @shell_exec('uptime');
$load = explode('load average' . (PHP_OS == 'Darwin' ? 's' : '') . ':', $load);
return implode(',', $load);
//return $load[count($load)-1];
} else {
throw new Exception('Unable to get server load');
}
} else if (class_exists('COM')) {
$wmi = new \COM("WinMgmts:\\\\.");
$CPUs = $wmi->InstancesOf('Win32_Processor');
$cpuLoad = 0;
$i = 0;
while ($cpu = $CPUs->Next()) {
$cpuLoad += $cpu->LoadPercentage;
$i++;
}
$cpuLoad = round($cpuLoad / $i, 2);
return $cpuLoad . '%';
}
}
throw new Exception('Unable to get server load');
} | [
"public",
"static",
"function",
"getServerLoad",
"(",
")",
":",
"string",
"{",
"if",
"(",
"function_exists",
"(",
"'sys_getloadavg'",
")",
")",
"{",
"$",
"a",
"=",
"sys_getloadavg",
"(",
")",
";",
"foreach",
"(",
"$",
"a",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"a",
"[",
"$",
"k",
"]",
"=",
"round",
"(",
"$",
"v",
",",
"2",
")",
";",
"}",
"return",
"implode",
"(",
"', '",
",",
"$",
"a",
")",
";",
"}",
"else",
"{",
"$",
"os",
"=",
"strtolower",
"(",
"PHP_OS",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"os",
",",
"'win'",
")",
"===",
"false",
")",
"{",
"if",
"(",
"@",
"file_exists",
"(",
"'/proc/loadavg'",
")",
"&&",
"@",
"is_readable",
"(",
"'/proc/loadavg'",
")",
")",
"{",
"$",
"load",
"=",
"file_get_contents",
"(",
"'/proc/loadavg'",
")",
";",
"$",
"load",
"=",
"explode",
"(",
"' '",
",",
"$",
"load",
")",
";",
"return",
"implode",
"(",
"','",
",",
"$",
"load",
")",
";",
"}",
"else",
"if",
"(",
"function_exists",
"(",
"'shell_exec'",
")",
")",
"{",
"$",
"load",
"=",
"@",
"shell_exec",
"(",
"'uptime'",
")",
";",
"$",
"load",
"=",
"explode",
"(",
"'load average'",
".",
"(",
"PHP_OS",
"==",
"'Darwin'",
"?",
"'s'",
":",
"''",
")",
".",
"':'",
",",
"$",
"load",
")",
";",
"return",
"implode",
"(",
"','",
",",
"$",
"load",
")",
";",
"//return $load[count($load)-1];",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"'Unable to get server load'",
")",
";",
"}",
"}",
"else",
"if",
"(",
"class_exists",
"(",
"'COM'",
")",
")",
"{",
"$",
"wmi",
"=",
"new",
"\\",
"COM",
"(",
"\"WinMgmts:\\\\\\\\.\"",
")",
";",
"$",
"CPUs",
"=",
"$",
"wmi",
"->",
"InstancesOf",
"(",
"'Win32_Processor'",
")",
";",
"$",
"cpuLoad",
"=",
"0",
";",
"$",
"i",
"=",
"0",
";",
"while",
"(",
"$",
"cpu",
"=",
"$",
"CPUs",
"->",
"Next",
"(",
")",
")",
"{",
"$",
"cpuLoad",
"+=",
"$",
"cpu",
"->",
"LoadPercentage",
";",
"$",
"i",
"++",
";",
"}",
"$",
"cpuLoad",
"=",
"round",
"(",
"$",
"cpuLoad",
"/",
"$",
"i",
",",
"2",
")",
";",
"return",
"$",
"cpuLoad",
".",
"'%'",
";",
"}",
"}",
"throw",
"new",
"Exception",
"(",
"'Unable to get server load'",
")",
";",
"}"
]
| Get server load ... if linux, returns all three averages, if windows, returns
average load for all CPU cores
@return string
@throws Exception | [
"Get",
"server",
"load",
"...",
"if",
"linux",
"returns",
"all",
"three",
"averages",
"if",
"windows",
"returns",
"average",
"load",
"for",
"all",
"CPU",
"cores"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Server.php#L20-L61 | train |
koldy/framework | src/Koldy/Server.php | Server.signatureArray | public static function signatureArray(): array
{
$numberOfIncludedFiles = count(get_included_files());
$serverIP = static::ip();
$domain = Application::getDomain();
$signature = [];
// add the server IP and domain
$signature[] = "server: {$serverIP} ({$domain})";
if (PHP_SAPI != 'cli') {
// this is regular HTTP request
$method = Request::method();
$url = Application::getCurrentURL();
// add info about the current request
$signature[] = "URL: {$method}={$url}";
// some end user IP and host stuff
$endUserIp = Request::ip();
$endUserHost = Request::host() ?? 'no host detected';
$proxy = '';
if ($endUserIp == $endUserHost) {
$endUserHost = 'no host detected';
}
if (Request::hasProxy()) {
$proxySignature = Request::proxySignature();
$forwardedFor = Request::httpXForwardedFor();
$proxy = " via {$proxySignature} for {$forwardedFor}";
}
$signature[] = "Origin: {$endUserIp} ({$endUserHost}){$proxy}";
$uas = Request::userAgent() ?? 'no user agent set';
$signature[] = "UAS: {$uas}";
} else {
$cliName = Application::getCliName();
$cliScript = Application::getCliScriptPath();
$signature[] = "CLI Name: {$cliName}";
$signature[] = "CLI Script: {$cliScript}";
$params = Cli::getParameters();
if (count($params) > 0) {
$signature[] = 'CLI Params: ' . print_r($params, true);
}
}
$serverLoad = static::getServerLoad();
$signature[] = "Server Load: {$serverLoad}";
$memory = memory_get_usage();
$peak = memory_get_peak_usage();
$allocatedMemory = memory_get_peak_usage(true);
$memoryLimit = ini_get('memory_limit') ?? -1;
$memoryKb = round($memory / 1024, 2);
$peakKb = round($peak / 1024, 2);
$allocatedMemoryKb = round($allocatedMemory / 1024, 2);
$limit = '';
$peakSpent = '';
if ($memoryLimit > 0) {
$limitInt = Convert::stringToBytes($memoryLimit);
$limit = ", limit: {$memoryLimit}";
$spent = round($peak / $limitInt * 100, 2);
$peakSpent = " ({$spent}% of limit)";
}
$signature[] = "Memory: current: {$memoryKb}kb, peak: {$peakKb}kb{$peakSpent}, allocated: {$allocatedMemoryKb}kb{$limit}";
$signature[] = "No. of included files: {$numberOfIncludedFiles}";
return $signature;
} | php | public static function signatureArray(): array
{
$numberOfIncludedFiles = count(get_included_files());
$serverIP = static::ip();
$domain = Application::getDomain();
$signature = [];
// add the server IP and domain
$signature[] = "server: {$serverIP} ({$domain})";
if (PHP_SAPI != 'cli') {
// this is regular HTTP request
$method = Request::method();
$url = Application::getCurrentURL();
// add info about the current request
$signature[] = "URL: {$method}={$url}";
// some end user IP and host stuff
$endUserIp = Request::ip();
$endUserHost = Request::host() ?? 'no host detected';
$proxy = '';
if ($endUserIp == $endUserHost) {
$endUserHost = 'no host detected';
}
if (Request::hasProxy()) {
$proxySignature = Request::proxySignature();
$forwardedFor = Request::httpXForwardedFor();
$proxy = " via {$proxySignature} for {$forwardedFor}";
}
$signature[] = "Origin: {$endUserIp} ({$endUserHost}){$proxy}";
$uas = Request::userAgent() ?? 'no user agent set';
$signature[] = "UAS: {$uas}";
} else {
$cliName = Application::getCliName();
$cliScript = Application::getCliScriptPath();
$signature[] = "CLI Name: {$cliName}";
$signature[] = "CLI Script: {$cliScript}";
$params = Cli::getParameters();
if (count($params) > 0) {
$signature[] = 'CLI Params: ' . print_r($params, true);
}
}
$serverLoad = static::getServerLoad();
$signature[] = "Server Load: {$serverLoad}";
$memory = memory_get_usage();
$peak = memory_get_peak_usage();
$allocatedMemory = memory_get_peak_usage(true);
$memoryLimit = ini_get('memory_limit') ?? -1;
$memoryKb = round($memory / 1024, 2);
$peakKb = round($peak / 1024, 2);
$allocatedMemoryKb = round($allocatedMemory / 1024, 2);
$limit = '';
$peakSpent = '';
if ($memoryLimit > 0) {
$limitInt = Convert::stringToBytes($memoryLimit);
$limit = ", limit: {$memoryLimit}";
$spent = round($peak / $limitInt * 100, 2);
$peakSpent = " ({$spent}% of limit)";
}
$signature[] = "Memory: current: {$memoryKb}kb, peak: {$peakKb}kb{$peakSpent}, allocated: {$allocatedMemoryKb}kb{$limit}";
$signature[] = "No. of included files: {$numberOfIncludedFiles}";
return $signature;
} | [
"public",
"static",
"function",
"signatureArray",
"(",
")",
":",
"array",
"{",
"$",
"numberOfIncludedFiles",
"=",
"count",
"(",
"get_included_files",
"(",
")",
")",
";",
"$",
"serverIP",
"=",
"static",
"::",
"ip",
"(",
")",
";",
"$",
"domain",
"=",
"Application",
"::",
"getDomain",
"(",
")",
";",
"$",
"signature",
"=",
"[",
"]",
";",
"// add the server IP and domain",
"$",
"signature",
"[",
"]",
"=",
"\"server: {$serverIP} ({$domain})\"",
";",
"if",
"(",
"PHP_SAPI",
"!=",
"'cli'",
")",
"{",
"// this is regular HTTP request",
"$",
"method",
"=",
"Request",
"::",
"method",
"(",
")",
";",
"$",
"url",
"=",
"Application",
"::",
"getCurrentURL",
"(",
")",
";",
"// add info about the current request",
"$",
"signature",
"[",
"]",
"=",
"\"URL: {$method}={$url}\"",
";",
"// some end user IP and host stuff",
"$",
"endUserIp",
"=",
"Request",
"::",
"ip",
"(",
")",
";",
"$",
"endUserHost",
"=",
"Request",
"::",
"host",
"(",
")",
"??",
"'no host detected'",
";",
"$",
"proxy",
"=",
"''",
";",
"if",
"(",
"$",
"endUserIp",
"==",
"$",
"endUserHost",
")",
"{",
"$",
"endUserHost",
"=",
"'no host detected'",
";",
"}",
"if",
"(",
"Request",
"::",
"hasProxy",
"(",
")",
")",
"{",
"$",
"proxySignature",
"=",
"Request",
"::",
"proxySignature",
"(",
")",
";",
"$",
"forwardedFor",
"=",
"Request",
"::",
"httpXForwardedFor",
"(",
")",
";",
"$",
"proxy",
"=",
"\" via {$proxySignature} for {$forwardedFor}\"",
";",
"}",
"$",
"signature",
"[",
"]",
"=",
"\"Origin: {$endUserIp} ({$endUserHost}){$proxy}\"",
";",
"$",
"uas",
"=",
"Request",
"::",
"userAgent",
"(",
")",
"??",
"'no user agent set'",
";",
"$",
"signature",
"[",
"]",
"=",
"\"UAS: {$uas}\"",
";",
"}",
"else",
"{",
"$",
"cliName",
"=",
"Application",
"::",
"getCliName",
"(",
")",
";",
"$",
"cliScript",
"=",
"Application",
"::",
"getCliScriptPath",
"(",
")",
";",
"$",
"signature",
"[",
"]",
"=",
"\"CLI Name: {$cliName}\"",
";",
"$",
"signature",
"[",
"]",
"=",
"\"CLI Script: {$cliScript}\"",
";",
"$",
"params",
"=",
"Cli",
"::",
"getParameters",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"params",
")",
">",
"0",
")",
"{",
"$",
"signature",
"[",
"]",
"=",
"'CLI Params: '",
".",
"print_r",
"(",
"$",
"params",
",",
"true",
")",
";",
"}",
"}",
"$",
"serverLoad",
"=",
"static",
"::",
"getServerLoad",
"(",
")",
";",
"$",
"signature",
"[",
"]",
"=",
"\"Server Load: {$serverLoad}\"",
";",
"$",
"memory",
"=",
"memory_get_usage",
"(",
")",
";",
"$",
"peak",
"=",
"memory_get_peak_usage",
"(",
")",
";",
"$",
"allocatedMemory",
"=",
"memory_get_peak_usage",
"(",
"true",
")",
";",
"$",
"memoryLimit",
"=",
"ini_get",
"(",
"'memory_limit'",
")",
"??",
"-",
"1",
";",
"$",
"memoryKb",
"=",
"round",
"(",
"$",
"memory",
"/",
"1024",
",",
"2",
")",
";",
"$",
"peakKb",
"=",
"round",
"(",
"$",
"peak",
"/",
"1024",
",",
"2",
")",
";",
"$",
"allocatedMemoryKb",
"=",
"round",
"(",
"$",
"allocatedMemory",
"/",
"1024",
",",
"2",
")",
";",
"$",
"limit",
"=",
"''",
";",
"$",
"peakSpent",
"=",
"''",
";",
"if",
"(",
"$",
"memoryLimit",
">",
"0",
")",
"{",
"$",
"limitInt",
"=",
"Convert",
"::",
"stringToBytes",
"(",
"$",
"memoryLimit",
")",
";",
"$",
"limit",
"=",
"\", limit: {$memoryLimit}\"",
";",
"$",
"spent",
"=",
"round",
"(",
"$",
"peak",
"/",
"$",
"limitInt",
"*",
"100",
",",
"2",
")",
";",
"$",
"peakSpent",
"=",
"\" ({$spent}% of limit)\"",
";",
"}",
"$",
"signature",
"[",
"]",
"=",
"\"Memory: current: {$memoryKb}kb, peak: {$peakKb}kb{$peakSpent}, allocated: {$allocatedMemoryKb}kb{$limit}\"",
";",
"$",
"signature",
"[",
"]",
"=",
"\"No. of included files: {$numberOfIncludedFiles}\"",
";",
"return",
"$",
"signature",
";",
"}"
]
| Get the server's "signature" in this moment with all useful debug data
@return array
@throws Convert\Exception
@throws Exception | [
"Get",
"the",
"server",
"s",
"signature",
"in",
"this",
"moment",
"with",
"all",
"useful",
"debug",
"data"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Server.php#L70-L148 | train |
koldy/framework | src/Koldy/Db/Model.php | Model.setData | final public function setData(array $values): Model
{
if (!is_array($this->data)) {
$this->data = $values;
} else {
$this->data = array_merge($this->data, $values);
}
return $this;
} | php | final public function setData(array $values): Model
{
if (!is_array($this->data)) {
$this->data = $values;
} else {
$this->data = array_merge($this->data, $values);
}
return $this;
} | [
"final",
"public",
"function",
"setData",
"(",
"array",
"$",
"values",
")",
":",
"Model",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"data",
")",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"$",
"values",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"data",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"values",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Set the array of values
@param array $values
@return Model | [
"Set",
"the",
"array",
"of",
"values"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Model.php#L138-L147 | train |
koldy/framework | src/Koldy/Db/Model.php | Model.create | public static function create(array $data): Model
{
$insert = new Insert(static::getTableName(), $data, static::getAdapterConnection());
$insert->exec();
if (static::$autoIncrement) {
// ID should be fetched if $data contains ID, so, let's check
if (is_string(static::$primaryKey) && isset($data[static::$primaryKey])) {
// there there, we already have it, let's do nothing
} else {
$data[static::$primaryKey] = static::getLastInsertId();
}
}
return new static($data);
} | php | public static function create(array $data): Model
{
$insert = new Insert(static::getTableName(), $data, static::getAdapterConnection());
$insert->exec();
if (static::$autoIncrement) {
// ID should be fetched if $data contains ID, so, let's check
if (is_string(static::$primaryKey) && isset($data[static::$primaryKey])) {
// there there, we already have it, let's do nothing
} else {
$data[static::$primaryKey] = static::getLastInsertId();
}
}
return new static($data);
} | [
"public",
"static",
"function",
"create",
"(",
"array",
"$",
"data",
")",
":",
"Model",
"{",
"$",
"insert",
"=",
"new",
"Insert",
"(",
"static",
"::",
"getTableName",
"(",
")",
",",
"$",
"data",
",",
"static",
"::",
"getAdapterConnection",
"(",
")",
")",
";",
"$",
"insert",
"->",
"exec",
"(",
")",
";",
"if",
"(",
"static",
"::",
"$",
"autoIncrement",
")",
"{",
"// ID should be fetched if $data contains ID, so, let's check",
"if",
"(",
"is_string",
"(",
"static",
"::",
"$",
"primaryKey",
")",
"&&",
"isset",
"(",
"$",
"data",
"[",
"static",
"::",
"$",
"primaryKey",
"]",
")",
")",
"{",
"// there there, we already have it, let's do nothing",
"}",
"else",
"{",
"$",
"data",
"[",
"static",
"::",
"$",
"primaryKey",
"]",
"=",
"static",
"::",
"getLastInsertId",
"(",
")",
";",
"}",
"}",
"return",
"new",
"static",
"(",
"$",
"data",
")",
";",
"}"
]
| Insert the record in database with given array of data
@param array $data pass array of data for this model \Koldy\Db\Model
@return Model
@throws Exception
@throws Json\Exception
@throws Query\Exception
@throws \Koldy\Exception | [
"Insert",
"the",
"record",
"in",
"database",
"with",
"given",
"array",
"of",
"data"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Model.php#L295-L310 | train |
koldy/framework | src/Koldy/Db/Model.php | Model.reload | public function reload(): Model
{
$pk = static::$primaryKey;
$condition = null;
if (is_array($pk)) {
if (count($pk) === 0) {
$class = get_class($this);
throw new Exception("Can not reload model of {$class}, primary key definition is incorrect, it can't be empty array");
}
$select = [];
foreach ($pk as $column) {
if (!$this->has($column)) {
$class = get_class($this);
throw new Exception("Can not reload model of {$class}, primary key column {$column} is not set in model");
}
$pkValue = $this->$column;
$select[$column] = $pkValue;
}
$condition = $select;
$row = static::select()->where($select)->fetchFirst();
} else {
if (!$this->has($pk)) {
$class = get_class($this);
throw new Exception("Can not reload model of {$class}, primary key {$pk} is not set in model");
}
$pkValue = $this->$pk;
$condition = [$pk => $pkValue];
$row = static::select()->where($pk, $pkValue)->fetchFirst();
}
if ($row === null) {
$class = get_class($this);
$conditions = [];
foreach ($condition as $key => $value) {
$conditions[] = "{$key}={$value}";
}
$conditions = implode(', ', $conditions);
throw new Exception("Can not reload model of {$class}, there is no record in database under {$conditions}");
}
return $this->setData($row);
} | php | public function reload(): Model
{
$pk = static::$primaryKey;
$condition = null;
if (is_array($pk)) {
if (count($pk) === 0) {
$class = get_class($this);
throw new Exception("Can not reload model of {$class}, primary key definition is incorrect, it can't be empty array");
}
$select = [];
foreach ($pk as $column) {
if (!$this->has($column)) {
$class = get_class($this);
throw new Exception("Can not reload model of {$class}, primary key column {$column} is not set in model");
}
$pkValue = $this->$column;
$select[$column] = $pkValue;
}
$condition = $select;
$row = static::select()->where($select)->fetchFirst();
} else {
if (!$this->has($pk)) {
$class = get_class($this);
throw new Exception("Can not reload model of {$class}, primary key {$pk} is not set in model");
}
$pkValue = $this->$pk;
$condition = [$pk => $pkValue];
$row = static::select()->where($pk, $pkValue)->fetchFirst();
}
if ($row === null) {
$class = get_class($this);
$conditions = [];
foreach ($condition as $key => $value) {
$conditions[] = "{$key}={$value}";
}
$conditions = implode(', ', $conditions);
throw new Exception("Can not reload model of {$class}, there is no record in database under {$conditions}");
}
return $this->setData($row);
} | [
"public",
"function",
"reload",
"(",
")",
":",
"Model",
"{",
"$",
"pk",
"=",
"static",
"::",
"$",
"primaryKey",
";",
"$",
"condition",
"=",
"null",
";",
"if",
"(",
"is_array",
"(",
"$",
"pk",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"pk",
")",
"===",
"0",
")",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"this",
")",
";",
"throw",
"new",
"Exception",
"(",
"\"Can not reload model of {$class}, primary key definition is incorrect, it can't be empty array\"",
")",
";",
"}",
"$",
"select",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"pk",
"as",
"$",
"column",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"has",
"(",
"$",
"column",
")",
")",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"this",
")",
";",
"throw",
"new",
"Exception",
"(",
"\"Can not reload model of {$class}, primary key column {$column} is not set in model\"",
")",
";",
"}",
"$",
"pkValue",
"=",
"$",
"this",
"->",
"$",
"column",
";",
"$",
"select",
"[",
"$",
"column",
"]",
"=",
"$",
"pkValue",
";",
"}",
"$",
"condition",
"=",
"$",
"select",
";",
"$",
"row",
"=",
"static",
"::",
"select",
"(",
")",
"->",
"where",
"(",
"$",
"select",
")",
"->",
"fetchFirst",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"has",
"(",
"$",
"pk",
")",
")",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"this",
")",
";",
"throw",
"new",
"Exception",
"(",
"\"Can not reload model of {$class}, primary key {$pk} is not set in model\"",
")",
";",
"}",
"$",
"pkValue",
"=",
"$",
"this",
"->",
"$",
"pk",
";",
"$",
"condition",
"=",
"[",
"$",
"pk",
"=>",
"$",
"pkValue",
"]",
";",
"$",
"row",
"=",
"static",
"::",
"select",
"(",
")",
"->",
"where",
"(",
"$",
"pk",
",",
"$",
"pkValue",
")",
"->",
"fetchFirst",
"(",
")",
";",
"}",
"if",
"(",
"$",
"row",
"===",
"null",
")",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"this",
")",
";",
"$",
"conditions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"condition",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"conditions",
"[",
"]",
"=",
"\"{$key}={$value}\"",
";",
"}",
"$",
"conditions",
"=",
"implode",
"(",
"', '",
",",
"$",
"conditions",
")",
";",
"throw",
"new",
"Exception",
"(",
"\"Can not reload model of {$class}, there is no record in database under {$conditions}\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"setData",
"(",
"$",
"row",
")",
";",
"}"
]
| Reloads this model with the latest data from database. It's using primary key to fetch the data. If primary key
contains multiple columns, then all columns must be present in the model in order to refresh the data successfully.
@return Model
@throws Exception
@throws Query\Exception
@throws \Koldy\Exception | [
"Reloads",
"this",
"model",
"with",
"the",
"latest",
"data",
"from",
"database",
".",
"It",
"s",
"using",
"primary",
"key",
"to",
"fetch",
"the",
"data",
".",
"If",
"primary",
"key",
"contains",
"multiple",
"columns",
"then",
"all",
"columns",
"must",
"be",
"present",
"in",
"the",
"model",
"in",
"order",
"to",
"refresh",
"the",
"data",
"successfully",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Model.php#L321-L371 | train |
koldy/framework | src/Koldy/Db/Model.php | Model.getLastInsertId | public static function getLastInsertId(string $keyName = null)
{
if (static::$autoIncrement) {
if (is_string(static::$autoIncrement)) {
$keyName = static::$autoIncrement;
} else if (is_string(static::$primaryKey)) {
$keyName = static::getTableName() . '_' . static::$primaryKey . '_seq';
}
return static::getAdapter()->getLastInsertId($keyName);
} else {
throw new Exception('Can not get last insert ID when model ' . get_called_class() . ' doesn\'t have auto_increment field');
}
} | php | public static function getLastInsertId(string $keyName = null)
{
if (static::$autoIncrement) {
if (is_string(static::$autoIncrement)) {
$keyName = static::$autoIncrement;
} else if (is_string(static::$primaryKey)) {
$keyName = static::getTableName() . '_' . static::$primaryKey . '_seq';
}
return static::getAdapter()->getLastInsertId($keyName);
} else {
throw new Exception('Can not get last insert ID when model ' . get_called_class() . ' doesn\'t have auto_increment field');
}
} | [
"public",
"static",
"function",
"getLastInsertId",
"(",
"string",
"$",
"keyName",
"=",
"null",
")",
"{",
"if",
"(",
"static",
"::",
"$",
"autoIncrement",
")",
"{",
"if",
"(",
"is_string",
"(",
"static",
"::",
"$",
"autoIncrement",
")",
")",
"{",
"$",
"keyName",
"=",
"static",
"::",
"$",
"autoIncrement",
";",
"}",
"else",
"if",
"(",
"is_string",
"(",
"static",
"::",
"$",
"primaryKey",
")",
")",
"{",
"$",
"keyName",
"=",
"static",
"::",
"getTableName",
"(",
")",
".",
"'_'",
".",
"static",
"::",
"$",
"primaryKey",
".",
"'_seq'",
";",
"}",
"return",
"static",
"::",
"getAdapter",
"(",
")",
"->",
"getLastInsertId",
"(",
"$",
"keyName",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"'Can not get last insert ID when model '",
".",
"get_called_class",
"(",
")",
".",
"' doesn\\'t have auto_increment field'",
")",
";",
"}",
"}"
]
| If you statically created new record in database to the table with auto
incrementing field, then you can use this static method to get the
generated primary key
@param null|string $keyName
@return int|string
@throws Exception
@throws \Koldy\Config\Exception
@throws \Koldy\Exception
@example
if (User::create(array('first_name' => 'John', 'last_name' => 'Doe'))) {
echo User::getLastInsertId();
} | [
"If",
"you",
"statically",
"created",
"new",
"record",
"in",
"database",
"to",
"the",
"table",
"with",
"auto",
"incrementing",
"field",
"then",
"you",
"can",
"use",
"this",
"static",
"method",
"to",
"get",
"the",
"generated",
"primary",
"key"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Model.php#L390-L403 | train |
koldy/framework | src/Koldy/Db/Model.php | Model.increment | public static function increment(string $field, $where, int $howMuch = 1): int
{
$update = new Update(static::getTableName(), null, static::getAdapterConnection());
$update->increment($field, $howMuch);
if ($where instanceof Where) {
$update->where($where);
} else if (is_array($where)) {
foreach ($where as $field => $value) {
$update->where($field, $value);
}
} else if (!is_array(static::$primaryKey) && (is_numeric($where) || is_string($where))) {
$update->where(static::$primaryKey, $where);
} else {
throw new Exception('Unhandled increment case in DB model');
}
return $update->exec()->rowCount();
} | php | public static function increment(string $field, $where, int $howMuch = 1): int
{
$update = new Update(static::getTableName(), null, static::getAdapterConnection());
$update->increment($field, $howMuch);
if ($where instanceof Where) {
$update->where($where);
} else if (is_array($where)) {
foreach ($where as $field => $value) {
$update->where($field, $value);
}
} else if (!is_array(static::$primaryKey) && (is_numeric($where) || is_string($where))) {
$update->where(static::$primaryKey, $where);
} else {
throw new Exception('Unhandled increment case in DB model');
}
return $update->exec()->rowCount();
} | [
"public",
"static",
"function",
"increment",
"(",
"string",
"$",
"field",
",",
"$",
"where",
",",
"int",
"$",
"howMuch",
"=",
"1",
")",
":",
"int",
"{",
"$",
"update",
"=",
"new",
"Update",
"(",
"static",
"::",
"getTableName",
"(",
")",
",",
"null",
",",
"static",
"::",
"getAdapterConnection",
"(",
")",
")",
";",
"$",
"update",
"->",
"increment",
"(",
"$",
"field",
",",
"$",
"howMuch",
")",
";",
"if",
"(",
"$",
"where",
"instanceof",
"Where",
")",
"{",
"$",
"update",
"->",
"where",
"(",
"$",
"where",
")",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"where",
")",
")",
"{",
"foreach",
"(",
"$",
"where",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"$",
"update",
"->",
"where",
"(",
"$",
"field",
",",
"$",
"value",
")",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"is_array",
"(",
"static",
"::",
"$",
"primaryKey",
")",
"&&",
"(",
"is_numeric",
"(",
"$",
"where",
")",
"||",
"is_string",
"(",
"$",
"where",
")",
")",
")",
"{",
"$",
"update",
"->",
"where",
"(",
"static",
"::",
"$",
"primaryKey",
",",
"$",
"where",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"'Unhandled increment case in DB model'",
")",
";",
"}",
"return",
"$",
"update",
"->",
"exec",
"(",
")",
"->",
"rowCount",
"(",
")",
";",
"}"
]
| Increment one numeric field in table on the row identified by primary key.
You can use this only if your primary key is just one field.
@param string $field
@param mixed $where the primary key value of the record
@param int $howMuch default 1
@return int number of affected rows
@throws Exception
@throws Query\Exception
@throws \Koldy\Exception | [
"Increment",
"one",
"numeric",
"field",
"in",
"table",
"on",
"the",
"row",
"identified",
"by",
"primary",
"key",
".",
"You",
"can",
"use",
"this",
"only",
"if",
"your",
"primary",
"key",
"is",
"just",
"one",
"field",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Model.php#L559-L577 | train |
koldy/framework | src/Koldy/Db/Model.php | Model.delete | public static function delete($where): int
{
$delete = new Delete(static::getTableName(), static::getAdapterConnection());
if ($where instanceof Where) {
$delete->where($where);
} else if (is_array($where)) {
foreach ($where as $field => $value) {
$delete->where($field, $value);
}
} else if (!is_array(static::$primaryKey) && (is_numeric($where) || is_string($where))) {
$delete->where(static::$primaryKey, $where);
}
return $delete->exec()->rowCount();
} | php | public static function delete($where): int
{
$delete = new Delete(static::getTableName(), static::getAdapterConnection());
if ($where instanceof Where) {
$delete->where($where);
} else if (is_array($where)) {
foreach ($where as $field => $value) {
$delete->where($field, $value);
}
} else if (!is_array(static::$primaryKey) && (is_numeric($where) || is_string($where))) {
$delete->where(static::$primaryKey, $where);
}
return $delete->exec()->rowCount();
} | [
"public",
"static",
"function",
"delete",
"(",
"$",
"where",
")",
":",
"int",
"{",
"$",
"delete",
"=",
"new",
"Delete",
"(",
"static",
"::",
"getTableName",
"(",
")",
",",
"static",
"::",
"getAdapterConnection",
"(",
")",
")",
";",
"if",
"(",
"$",
"where",
"instanceof",
"Where",
")",
"{",
"$",
"delete",
"->",
"where",
"(",
"$",
"where",
")",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"where",
")",
")",
"{",
"foreach",
"(",
"$",
"where",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"$",
"delete",
"->",
"where",
"(",
"$",
"field",
",",
"$",
"value",
")",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"is_array",
"(",
"static",
"::",
"$",
"primaryKey",
")",
"&&",
"(",
"is_numeric",
"(",
"$",
"where",
")",
"||",
"is_string",
"(",
"$",
"where",
")",
")",
")",
"{",
"$",
"delete",
"->",
"where",
"(",
"static",
"::",
"$",
"primaryKey",
",",
"$",
"where",
")",
";",
"}",
"return",
"$",
"delete",
"->",
"exec",
"(",
")",
"->",
"rowCount",
"(",
")",
";",
"}"
]
| Delete one or more records from the table defined in this model. If you
pass array, then array must contain field names and values that will be
used in WHERE statement. If you pass primitive value, method will treat
that as passed value for primary key field.
@param mixed $where
@return integer How many records is deleted
@throws Query\Exception
@throws \Koldy\Exception
@example User::delete(1);
@example User::delete(array('group_id' => 5, 'parent_id' => 10));
@example User::delete(array('parent_id' => 10, array('time', '>', '2013-08-01 00:00:00')))
@link http://koldy.net/docs/database/models#delete | [
"Delete",
"one",
"or",
"more",
"records",
"from",
"the",
"table",
"defined",
"in",
"this",
"model",
".",
"If",
"you",
"pass",
"array",
"then",
"array",
"must",
"contain",
"field",
"names",
"and",
"values",
"that",
"will",
"be",
"used",
"in",
"WHERE",
"statement",
".",
"If",
"you",
"pass",
"primitive",
"value",
"method",
"will",
"treat",
"that",
"as",
"passed",
"value",
"for",
"primary",
"key",
"field",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Model.php#L596-L611 | train |
koldy/framework | src/Koldy/Db/Model.php | Model.fetch | public static function fetch(
$where,
array $fields = null,
string $orderField = null,
string $orderDirection = null,
int $limit = null,
int $start = null
): array {
$select = static::select();
if ($fields !== null) {
$select->fields($fields);
}
if ($where instanceof Where) {
$select->where(clone $where);
} else if (is_array($where)) {
foreach ($where as $field => $value) {
$select->where($field, $value);
}
} else if (!is_array(static::$primaryKey) && (is_numeric($where) || is_string($where))) {
$select->where(static::$primaryKey, $where);
}
if ($orderField !== null) {
$select->orderBy($orderField, $orderDirection);
}
if ($limit !== null) {
$select->limit($start ?? 0, $limit);
}
$data = [];
foreach ($select->fetchAll() as $r) {
$data[] = new static($r);
}
return $data;
} | php | public static function fetch(
$where,
array $fields = null,
string $orderField = null,
string $orderDirection = null,
int $limit = null,
int $start = null
): array {
$select = static::select();
if ($fields !== null) {
$select->fields($fields);
}
if ($where instanceof Where) {
$select->where(clone $where);
} else if (is_array($where)) {
foreach ($where as $field => $value) {
$select->where($field, $value);
}
} else if (!is_array(static::$primaryKey) && (is_numeric($where) || is_string($where))) {
$select->where(static::$primaryKey, $where);
}
if ($orderField !== null) {
$select->orderBy($orderField, $orderDirection);
}
if ($limit !== null) {
$select->limit($start ?? 0, $limit);
}
$data = [];
foreach ($select->fetchAll() as $r) {
$data[] = new static($r);
}
return $data;
} | [
"public",
"static",
"function",
"fetch",
"(",
"$",
"where",
",",
"array",
"$",
"fields",
"=",
"null",
",",
"string",
"$",
"orderField",
"=",
"null",
",",
"string",
"$",
"orderDirection",
"=",
"null",
",",
"int",
"$",
"limit",
"=",
"null",
",",
"int",
"$",
"start",
"=",
"null",
")",
":",
"array",
"{",
"$",
"select",
"=",
"static",
"::",
"select",
"(",
")",
";",
"if",
"(",
"$",
"fields",
"!==",
"null",
")",
"{",
"$",
"select",
"->",
"fields",
"(",
"$",
"fields",
")",
";",
"}",
"if",
"(",
"$",
"where",
"instanceof",
"Where",
")",
"{",
"$",
"select",
"->",
"where",
"(",
"clone",
"$",
"where",
")",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"where",
")",
")",
"{",
"foreach",
"(",
"$",
"where",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"$",
"select",
"->",
"where",
"(",
"$",
"field",
",",
"$",
"value",
")",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"is_array",
"(",
"static",
"::",
"$",
"primaryKey",
")",
"&&",
"(",
"is_numeric",
"(",
"$",
"where",
")",
"||",
"is_string",
"(",
"$",
"where",
")",
")",
")",
"{",
"$",
"select",
"->",
"where",
"(",
"static",
"::",
"$",
"primaryKey",
",",
"$",
"where",
")",
";",
"}",
"if",
"(",
"$",
"orderField",
"!==",
"null",
")",
"{",
"$",
"select",
"->",
"orderBy",
"(",
"$",
"orderField",
",",
"$",
"orderDirection",
")",
";",
"}",
"if",
"(",
"$",
"limit",
"!==",
"null",
")",
"{",
"$",
"select",
"->",
"limit",
"(",
"$",
"start",
"??",
"0",
",",
"$",
"limit",
")",
";",
"}",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"select",
"->",
"fetchAll",
"(",
")",
"as",
"$",
"r",
")",
"{",
"$",
"data",
"[",
"]",
"=",
"new",
"static",
"(",
"$",
"r",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
]
| Fetch the array of initialized records from database
@param mixed $where the WHERE condition
@param array $fields array of fields to select; by default, all fields will be fetched
@param string|null $orderField
@param string|null $orderDirection
@param int|null $limit
@param int|null $start
@return Model[]
@throws Query\Exception
@throws \Koldy\Exception
@link http://koldy.net/docs/database/models#fetch | [
"Fetch",
"the",
"array",
"of",
"initialized",
"records",
"from",
"database"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Model.php#L745-L783 | train |
koldy/framework | src/Koldy/Db/Model.php | Model.fetchWithKey | public static function fetchWithKey(
string $key,
$where,
array $fields = null,
string $orderField = null,
string $orderDirection = null,
int $limit = null,
int $start = null
): array {
$data = [];
foreach (static::fetch($where, $fields, $orderField, $orderDirection, $limit, $start) as $record) {
$data[$record->$key] = $record;
}
return $data;
} | php | public static function fetchWithKey(
string $key,
$where,
array $fields = null,
string $orderField = null,
string $orderDirection = null,
int $limit = null,
int $start = null
): array {
$data = [];
foreach (static::fetch($where, $fields, $orderField, $orderDirection, $limit, $start) as $record) {
$data[$record->$key] = $record;
}
return $data;
} | [
"public",
"static",
"function",
"fetchWithKey",
"(",
"string",
"$",
"key",
",",
"$",
"where",
",",
"array",
"$",
"fields",
"=",
"null",
",",
"string",
"$",
"orderField",
"=",
"null",
",",
"string",
"$",
"orderDirection",
"=",
"null",
",",
"int",
"$",
"limit",
"=",
"null",
",",
"int",
"$",
"start",
"=",
"null",
")",
":",
"array",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"static",
"::",
"fetch",
"(",
"$",
"where",
",",
"$",
"fields",
",",
"$",
"orderField",
",",
"$",
"orderDirection",
",",
"$",
"limit",
",",
"$",
"start",
")",
"as",
"$",
"record",
")",
"{",
"$",
"data",
"[",
"$",
"record",
"->",
"$",
"key",
"]",
"=",
"$",
"record",
";",
"}",
"return",
"$",
"data",
";",
"}"
]
| Fetch the array of initialized records from database, where key in the returned array is something from the
results
@param string $key The name of the column which will be taken from results to be used as key in array
@param mixed $where the WHERE condition
@param array $fields array of fields to select; by default, all fields will be fetched
@param string|null $orderField
@param string|null $orderDirection
@param int|null $limit
@param int|null $start
@return array
@throws Query\Exception
@throws \Koldy\Exception
@link http://koldy.net/docs/database/models#fetch | [
"Fetch",
"the",
"array",
"of",
"initialized",
"records",
"from",
"database",
"where",
"key",
"in",
"the",
"returned",
"array",
"is",
"something",
"from",
"the",
"results"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Model.php#L803-L819 | train |
koldy/framework | src/Koldy/Db/Model.php | Model.all | public static function all(string $orderField = null, string $orderDirection = null): array
{
$select = static::select();
if ($orderField !== null) {
$select->orderBy($orderField, $orderDirection);
}
$data = [];
foreach ($select->fetchAll() as $r) {
$data[] = new static($r);
}
return $data;
} | php | public static function all(string $orderField = null, string $orderDirection = null): array
{
$select = static::select();
if ($orderField !== null) {
$select->orderBy($orderField, $orderDirection);
}
$data = [];
foreach ($select->fetchAll() as $r) {
$data[] = new static($r);
}
return $data;
} | [
"public",
"static",
"function",
"all",
"(",
"string",
"$",
"orderField",
"=",
"null",
",",
"string",
"$",
"orderDirection",
"=",
"null",
")",
":",
"array",
"{",
"$",
"select",
"=",
"static",
"::",
"select",
"(",
")",
";",
"if",
"(",
"$",
"orderField",
"!==",
"null",
")",
"{",
"$",
"select",
"->",
"orderBy",
"(",
"$",
"orderField",
",",
"$",
"orderDirection",
")",
";",
"}",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"select",
"->",
"fetchAll",
"(",
")",
"as",
"$",
"r",
")",
"{",
"$",
"data",
"[",
"]",
"=",
"new",
"static",
"(",
"$",
"r",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
]
| Fetch all records from database
@param string $orderField
@param string $orderDirection
@return Model[]
@throws Query\Exception
@throws \Koldy\Exception
@link http://www.php.net/manual/en/pdo.constants.php | [
"Fetch",
"all",
"records",
"from",
"database"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Model.php#L832-L846 | train |
koldy/framework | src/Koldy/Db/Model.php | Model.isUnique | public static function isUnique(
string $field,
$value,
$exceptionValue = null,
string $exceptionField = null
): bool {
$select = static::select();
$select->field('COUNT(*)', 'total')->where($field, $value);
if ($exceptionValue !== null) {
if ($exceptionField === null) {
$exceptionField = $field;
}
$select->where($exceptionField, '!=', $exceptionValue);
}
$results = $select->fetchAll();
if (isset($results[0])) {
return ($results[0]['total'] == 0);
}
return true;
} | php | public static function isUnique(
string $field,
$value,
$exceptionValue = null,
string $exceptionField = null
): bool {
$select = static::select();
$select->field('COUNT(*)', 'total')->where($field, $value);
if ($exceptionValue !== null) {
if ($exceptionField === null) {
$exceptionField = $field;
}
$select->where($exceptionField, '!=', $exceptionValue);
}
$results = $select->fetchAll();
if (isset($results[0])) {
return ($results[0]['total'] == 0);
}
return true;
} | [
"public",
"static",
"function",
"isUnique",
"(",
"string",
"$",
"field",
",",
"$",
"value",
",",
"$",
"exceptionValue",
"=",
"null",
",",
"string",
"$",
"exceptionField",
"=",
"null",
")",
":",
"bool",
"{",
"$",
"select",
"=",
"static",
"::",
"select",
"(",
")",
";",
"$",
"select",
"->",
"field",
"(",
"'COUNT(*)'",
",",
"'total'",
")",
"->",
"where",
"(",
"$",
"field",
",",
"$",
"value",
")",
";",
"if",
"(",
"$",
"exceptionValue",
"!==",
"null",
")",
"{",
"if",
"(",
"$",
"exceptionField",
"===",
"null",
")",
"{",
"$",
"exceptionField",
"=",
"$",
"field",
";",
"}",
"$",
"select",
"->",
"where",
"(",
"$",
"exceptionField",
",",
"'!='",
",",
"$",
"exceptionValue",
")",
";",
"}",
"$",
"results",
"=",
"$",
"select",
"->",
"fetchAll",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"results",
"[",
"0",
"]",
")",
")",
"{",
"return",
"(",
"$",
"results",
"[",
"0",
"]",
"[",
"'total'",
"]",
"==",
"0",
")",
";",
"}",
"return",
"true",
";",
"}"
]
| Check if some value exists in database or not. This is useful if you
want, for an example, check if user's e-mail already is in database
before you try to insert your data.
@param string $field
@param mixed $value
@param mixed $exceptionValue OPTIONAL
@param string $exceptionField OPTIONAL
@return bool
@throws Query\Exception
@throws \Koldy\Exception
@link http://koldy.net/docs/database/models#isUnique
@example
User::isUnique('email', '[email protected]'); will execute:
SELECT COUNT(*) FROM user WHERE email = '[email protected]'
User::isUnique('email', '[email protected]', '[email protected]');
SELECT COUNT(*) FROM user WHERE email = '[email protected]' AND email != '[email protected]'
User::isUnique('email', '[email protected]', 5, 'id');
SELECT COUNT(*) FROM user WHERE email = '[email protected]' AND id != 5 | [
"Check",
"if",
"some",
"value",
"exists",
"in",
"database",
"or",
"not",
".",
"This",
"is",
"useful",
"if",
"you",
"want",
"for",
"an",
"example",
"check",
"if",
"user",
"s",
"e",
"-",
"mail",
"already",
"is",
"in",
"database",
"before",
"you",
"try",
"to",
"insert",
"your",
"data",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Model.php#L1047-L1071 | train |
koldy/framework | src/Koldy/Db/Model.php | Model.count | public static function count($where = null): int
{
$select = static::select();
if ($where !== null) {
if ($where instanceof Where) {
$select->field('COUNT(*)', 'total');
$select->where(clone $where);
} else if (is_array($where)) {
$select->field('COUNT(*)', 'total');
foreach ($where as $field => $value) {
$select->where($field, $value);
}
} else if (!is_array(static::$primaryKey) && (is_numeric($where) || is_string($where))) {
$select->field('COUNT(' . static::$primaryKey . ')', 'total');
$select->where(static::$primaryKey, $where);
}
} else {
$pk = is_string(static::$primaryKey) ? static::$primaryKey : '*';
$select->field('COUNT(' . $pk . ')', 'total');
}
$results = $select->fetchAll();
if (isset($results[0])) {
$r = $results[0];
if (array_key_exists('total', $r)) {
return (int)$r['total'];
} else {
return 0;
}
} else {
return 0;
}
} | php | public static function count($where = null): int
{
$select = static::select();
if ($where !== null) {
if ($where instanceof Where) {
$select->field('COUNT(*)', 'total');
$select->where(clone $where);
} else if (is_array($where)) {
$select->field('COUNT(*)', 'total');
foreach ($where as $field => $value) {
$select->where($field, $value);
}
} else if (!is_array(static::$primaryKey) && (is_numeric($where) || is_string($where))) {
$select->field('COUNT(' . static::$primaryKey . ')', 'total');
$select->where(static::$primaryKey, $where);
}
} else {
$pk = is_string(static::$primaryKey) ? static::$primaryKey : '*';
$select->field('COUNT(' . $pk . ')', 'total');
}
$results = $select->fetchAll();
if (isset($results[0])) {
$r = $results[0];
if (array_key_exists('total', $r)) {
return (int)$r['total'];
} else {
return 0;
}
} else {
return 0;
}
} | [
"public",
"static",
"function",
"count",
"(",
"$",
"where",
"=",
"null",
")",
":",
"int",
"{",
"$",
"select",
"=",
"static",
"::",
"select",
"(",
")",
";",
"if",
"(",
"$",
"where",
"!==",
"null",
")",
"{",
"if",
"(",
"$",
"where",
"instanceof",
"Where",
")",
"{",
"$",
"select",
"->",
"field",
"(",
"'COUNT(*)'",
",",
"'total'",
")",
";",
"$",
"select",
"->",
"where",
"(",
"clone",
"$",
"where",
")",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"where",
")",
")",
"{",
"$",
"select",
"->",
"field",
"(",
"'COUNT(*)'",
",",
"'total'",
")",
";",
"foreach",
"(",
"$",
"where",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"$",
"select",
"->",
"where",
"(",
"$",
"field",
",",
"$",
"value",
")",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"is_array",
"(",
"static",
"::",
"$",
"primaryKey",
")",
"&&",
"(",
"is_numeric",
"(",
"$",
"where",
")",
"||",
"is_string",
"(",
"$",
"where",
")",
")",
")",
"{",
"$",
"select",
"->",
"field",
"(",
"'COUNT('",
".",
"static",
"::",
"$",
"primaryKey",
".",
"')'",
",",
"'total'",
")",
";",
"$",
"select",
"->",
"where",
"(",
"static",
"::",
"$",
"primaryKey",
",",
"$",
"where",
")",
";",
"}",
"}",
"else",
"{",
"$",
"pk",
"=",
"is_string",
"(",
"static",
"::",
"$",
"primaryKey",
")",
"?",
"static",
"::",
"$",
"primaryKey",
":",
"'*'",
";",
"$",
"select",
"->",
"field",
"(",
"'COUNT('",
".",
"$",
"pk",
".",
"')'",
",",
"'total'",
")",
";",
"}",
"$",
"results",
"=",
"$",
"select",
"->",
"fetchAll",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"results",
"[",
"0",
"]",
")",
")",
"{",
"$",
"r",
"=",
"$",
"results",
"[",
"0",
"]",
";",
"if",
"(",
"array_key_exists",
"(",
"'total'",
",",
"$",
"r",
")",
")",
"{",
"return",
"(",
"int",
")",
"$",
"r",
"[",
"'total'",
"]",
";",
"}",
"else",
"{",
"return",
"0",
";",
"}",
"}",
"else",
"{",
"return",
"0",
";",
"}",
"}"
]
| Count the records in table according to the parameters
@param mixed $where
@return int
@throws Query\Exception
@throws \Koldy\Exception
@link http://koldy.net/docs/database/models#count | [
"Count",
"the",
"records",
"in",
"table",
"according",
"to",
"the",
"parameters"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Model.php#L1083-L1120 | train |
koldy/framework | src/Koldy/Db/Model.php | Model.resultSet | public static function resultSet(string $tableAlias = null): ResultSet
{
$rs = new ResultSet(static::getTableName(), $tableAlias);
$rs->setModelClass(get_called_class())->setAdapter(static::getAdapterConnection());
return $rs;
} | php | public static function resultSet(string $tableAlias = null): ResultSet
{
$rs = new ResultSet(static::getTableName(), $tableAlias);
$rs->setModelClass(get_called_class())->setAdapter(static::getAdapterConnection());
return $rs;
} | [
"public",
"static",
"function",
"resultSet",
"(",
"string",
"$",
"tableAlias",
"=",
"null",
")",
":",
"ResultSet",
"{",
"$",
"rs",
"=",
"new",
"ResultSet",
"(",
"static",
"::",
"getTableName",
"(",
")",
",",
"$",
"tableAlias",
")",
";",
"$",
"rs",
"->",
"setModelClass",
"(",
"get_called_class",
"(",
")",
")",
"->",
"setAdapter",
"(",
"static",
"::",
"getAdapterConnection",
"(",
")",
")",
";",
"return",
"$",
"rs",
";",
"}"
]
| Get the ResultSet object of this model
@param null|string $tableAlias
@return ResultSet
@throws \Koldy\Config\Exception
@throws \Koldy\Exception | [
"Get",
"the",
"ResultSet",
"object",
"of",
"this",
"model"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Model.php#L1131-L1136 | train |
koldy/framework | src/Koldy/Db/Model.php | Model.select | public static function select(string $tableAlias = null): Select
{
$select = new Select(static::getTableName(), $tableAlias);
$select->setAdapter(static::getAdapterConnection());
return $select;
} | php | public static function select(string $tableAlias = null): Select
{
$select = new Select(static::getTableName(), $tableAlias);
$select->setAdapter(static::getAdapterConnection());
return $select;
} | [
"public",
"static",
"function",
"select",
"(",
"string",
"$",
"tableAlias",
"=",
"null",
")",
":",
"Select",
"{",
"$",
"select",
"=",
"new",
"Select",
"(",
"static",
"::",
"getTableName",
"(",
")",
",",
"$",
"tableAlias",
")",
";",
"$",
"select",
"->",
"setAdapter",
"(",
"static",
"::",
"getAdapterConnection",
"(",
")",
")",
";",
"return",
"$",
"select",
";",
"}"
]
| Get the initialized Select object with populated FROM and connection adapter set
@param string $tableAlias
@return Select
@throws \Koldy\Config\Exception
@throws \Koldy\Exception | [
"Get",
"the",
"initialized",
"Select",
"object",
"with",
"populated",
"FROM",
"and",
"connection",
"adapter",
"set"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Model.php#L1147-L1152 | train |
koldy/framework | src/Koldy/Filesystem/Directory.php | Directory.read | public static function read(string $path, string $filter = null): array
{
if (is_dir($path) && $handle = opendir($path)) {
$files = [];
if (substr($path, -1) != '/') {
$path .= '/';
}
while (false !== ($entry = readdir($handle))) {
if ($entry !== '.' && $entry !== '..') {
if ($filter === null || preg_match($filter, $entry)) {
$fullPath = $path . $entry;
if (substr($fullPath, 0, 1) == '.') {
$fullPath = stream_resolve_include_path($path . $entry);
}
$files[$fullPath] = $entry;
}
}
}
return $files;
} else {
throw new FilesystemException("Unable to open directory on path={$path}");
}
} | php | public static function read(string $path, string $filter = null): array
{
if (is_dir($path) && $handle = opendir($path)) {
$files = [];
if (substr($path, -1) != '/') {
$path .= '/';
}
while (false !== ($entry = readdir($handle))) {
if ($entry !== '.' && $entry !== '..') {
if ($filter === null || preg_match($filter, $entry)) {
$fullPath = $path . $entry;
if (substr($fullPath, 0, 1) == '.') {
$fullPath = stream_resolve_include_path($path . $entry);
}
$files[$fullPath] = $entry;
}
}
}
return $files;
} else {
throw new FilesystemException("Unable to open directory on path={$path}");
}
} | [
"public",
"static",
"function",
"read",
"(",
"string",
"$",
"path",
",",
"string",
"$",
"filter",
"=",
"null",
")",
":",
"array",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"path",
")",
"&&",
"$",
"handle",
"=",
"opendir",
"(",
"$",
"path",
")",
")",
"{",
"$",
"files",
"=",
"[",
"]",
";",
"if",
"(",
"substr",
"(",
"$",
"path",
",",
"-",
"1",
")",
"!=",
"'/'",
")",
"{",
"$",
"path",
".=",
"'/'",
";",
"}",
"while",
"(",
"false",
"!==",
"(",
"$",
"entry",
"=",
"readdir",
"(",
"$",
"handle",
")",
")",
")",
"{",
"if",
"(",
"$",
"entry",
"!==",
"'.'",
"&&",
"$",
"entry",
"!==",
"'..'",
")",
"{",
"if",
"(",
"$",
"filter",
"===",
"null",
"||",
"preg_match",
"(",
"$",
"filter",
",",
"$",
"entry",
")",
")",
"{",
"$",
"fullPath",
"=",
"$",
"path",
".",
"$",
"entry",
";",
"if",
"(",
"substr",
"(",
"$",
"fullPath",
",",
"0",
",",
"1",
")",
"==",
"'.'",
")",
"{",
"$",
"fullPath",
"=",
"stream_resolve_include_path",
"(",
"$",
"path",
".",
"$",
"entry",
")",
";",
"}",
"$",
"files",
"[",
"$",
"fullPath",
"]",
"=",
"$",
"entry",
";",
"}",
"}",
"}",
"return",
"$",
"files",
";",
"}",
"else",
"{",
"throw",
"new",
"FilesystemException",
"(",
"\"Unable to open directory on path={$path}\"",
")",
";",
"}",
"}"
]
| Get the list of all files and folders from the given folder
@param string $path the directory path to read
@param string $filter [optional] regex for filtering the list
@return array assoc; the key is full path of the file and value is only file name
@throws FilesystemException
@example return array('/var/www/site.tld/folder/croatia.png' => 'croatia.png') | [
"Get",
"the",
"list",
"of",
"all",
"files",
"and",
"folders",
"from",
"the",
"given",
"folder"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Filesystem/Directory.php#L25-L52 | train |
koldy/framework | src/Koldy/Filesystem/Directory.php | Directory.mkdir | public static function mkdir(string $path, $chmod = null): void
{
if (!is_dir($path)) {
if ($chmod === null) {
$chmod = Application::getConfig('application')->getArrayItem('filesystem', 'default_chmod', 0644);
}
if (!mkdir($path, $chmod, true)) {
throw new FilesystemException("Can not create directory on path={$path}");
}
}
} | php | public static function mkdir(string $path, $chmod = null): void
{
if (!is_dir($path)) {
if ($chmod === null) {
$chmod = Application::getConfig('application')->getArrayItem('filesystem', 'default_chmod', 0644);
}
if (!mkdir($path, $chmod, true)) {
throw new FilesystemException("Can not create directory on path={$path}");
}
}
} | [
"public",
"static",
"function",
"mkdir",
"(",
"string",
"$",
"path",
",",
"$",
"chmod",
"=",
"null",
")",
":",
"void",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"if",
"(",
"$",
"chmod",
"===",
"null",
")",
"{",
"$",
"chmod",
"=",
"Application",
"::",
"getConfig",
"(",
"'application'",
")",
"->",
"getArrayItem",
"(",
"'filesystem'",
",",
"'default_chmod'",
",",
"0644",
")",
";",
"}",
"if",
"(",
"!",
"mkdir",
"(",
"$",
"path",
",",
"$",
"chmod",
",",
"true",
")",
")",
"{",
"throw",
"new",
"FilesystemException",
"(",
"\"Can not create directory on path={$path}\"",
")",
";",
"}",
"}",
"}"
]
| Create the target directory recursively if needed
@param string $path
@param int $chmod default 0644
@return void
@throws Exception
@throws \Koldy\Config\Exception
@throws \Koldy\Exception
@example $chmod 0777, 0755, 0700 | [
"Create",
"the",
"target",
"directory",
"recursively",
"if",
"needed"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Filesystem/Directory.php#L151-L162 | train |
koldy/framework | src/Koldy/Filesystem/Directory.php | Directory.rmdirRecursive | public static function rmdirRecursive(string $directory): void
{
if (is_dir($directory)) {
static::emptyDirectory($directory);
if (!rmdir($directory)) {
throw new FilesystemException("Unable to remove directory on path={$directory}");
}
}
} | php | public static function rmdirRecursive(string $directory): void
{
if (is_dir($directory)) {
static::emptyDirectory($directory);
if (!rmdir($directory)) {
throw new FilesystemException("Unable to remove directory on path={$directory}");
}
}
} | [
"public",
"static",
"function",
"rmdirRecursive",
"(",
"string",
"$",
"directory",
")",
":",
"void",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"directory",
")",
")",
"{",
"static",
"::",
"emptyDirectory",
"(",
"$",
"directory",
")",
";",
"if",
"(",
"!",
"rmdir",
"(",
"$",
"directory",
")",
")",
"{",
"throw",
"new",
"FilesystemException",
"(",
"\"Unable to remove directory on path={$directory}\"",
")",
";",
"}",
"}",
"}"
]
| Remove directory and content inside recursively
@param string $directory
@throws FilesystemException | [
"Remove",
"directory",
"and",
"content",
"inside",
"recursively"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Filesystem/Directory.php#L171-L180 | train |
koldy/framework | src/Koldy/Filesystem/Directory.php | Directory.emptyDirectory | public static function emptyDirectory(string $directory): void
{
if (is_dir($directory)) {
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST) as $path) {
if ($path->isFile()) {
if (!unlink($path->getPathname())) {
throw new FilesystemException("Unable to empty directory while emptying directory on path={$path->getPathname()}");
}
} else {
if (!rmdir($path->getPathname())) {
throw new FilesystemException("Unable to empty directory while emptying directory on path={$path->getPathname()}");
}
}
}
}
} | php | public static function emptyDirectory(string $directory): void
{
if (is_dir($directory)) {
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST) as $path) {
if ($path->isFile()) {
if (!unlink($path->getPathname())) {
throw new FilesystemException("Unable to empty directory while emptying directory on path={$path->getPathname()}");
}
} else {
if (!rmdir($path->getPathname())) {
throw new FilesystemException("Unable to empty directory while emptying directory on path={$path->getPathname()}");
}
}
}
}
} | [
"public",
"static",
"function",
"emptyDirectory",
"(",
"string",
"$",
"directory",
")",
":",
"void",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"directory",
")",
")",
"{",
"foreach",
"(",
"new",
"\\",
"RecursiveIteratorIterator",
"(",
"new",
"\\",
"RecursiveDirectoryIterator",
"(",
"$",
"directory",
",",
"\\",
"FilesystemIterator",
"::",
"SKIP_DOTS",
")",
",",
"\\",
"RecursiveIteratorIterator",
"::",
"CHILD_FIRST",
")",
"as",
"$",
"path",
")",
"{",
"if",
"(",
"$",
"path",
"->",
"isFile",
"(",
")",
")",
"{",
"if",
"(",
"!",
"unlink",
"(",
"$",
"path",
"->",
"getPathname",
"(",
")",
")",
")",
"{",
"throw",
"new",
"FilesystemException",
"(",
"\"Unable to empty directory while emptying directory on path={$path->getPathname()}\"",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"rmdir",
"(",
"$",
"path",
"->",
"getPathname",
"(",
")",
")",
")",
"{",
"throw",
"new",
"FilesystemException",
"(",
"\"Unable to empty directory while emptying directory on path={$path->getPathname()}\"",
")",
";",
"}",
"}",
"}",
"}",
"}"
]
| Empty all directory content, but do not delete the directory
@param string $directory
@return void
@throws FilesystemException | [
"Empty",
"all",
"directory",
"content",
"but",
"do",
"not",
"delete",
"the",
"directory"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Filesystem/Directory.php#L190-L205 | train |
koldy/framework | src/Koldy/Route/AbstractRoute.php | AbstractRoute.asset | public function asset(string $path, string $assetSite = null): string
{
if (strlen($path) == 0) {
throw new \InvalidArgumentException('Expected non-empty string');
}
// if you pass the full URL that contains "//" part, it'll be immediately
// returned without any kind of building or parsing
$pos = strpos($path, '//');
if (($pos !== false && $pos < 10) || substr($path, 0, 2) == '//') {
return $path;
}
$assets = Application::getConfig('application')->get('assets') ?? [];
if ($path[0] != '/') {
$path = '/' . $path;
}
$url = null;
if ($assetSite != null) {
if (isset($assets[$assetSite])) {
$url = $assets[$assetSite];
} else {
$backtrace = debug_backtrace();
$caller = $backtrace[1]['function'] ?? '[unknown caller]'; // TODO: Possible fix needed
Log::warning("Asset site {$assetSite} is used in {$caller}, but not set in application config; using first asset site if any");
if (count($assets) > 0) {
$url = array_values($assets)[0];
}
}
} else {
if (count($assets) > 0) {
$url = array_values($assets)[0];
}
}
if ($url == null) {
return static::makeUrl($path);
} else {
if (substr($url, -1) != '/') {
$url .= '/';
}
if (substr($path, 0, 1) == '/') {
$path = substr($path, 1);
}
return $url . $path;
}
} | php | public function asset(string $path, string $assetSite = null): string
{
if (strlen($path) == 0) {
throw new \InvalidArgumentException('Expected non-empty string');
}
// if you pass the full URL that contains "//" part, it'll be immediately
// returned without any kind of building or parsing
$pos = strpos($path, '//');
if (($pos !== false && $pos < 10) || substr($path, 0, 2) == '//') {
return $path;
}
$assets = Application::getConfig('application')->get('assets') ?? [];
if ($path[0] != '/') {
$path = '/' . $path;
}
$url = null;
if ($assetSite != null) {
if (isset($assets[$assetSite])) {
$url = $assets[$assetSite];
} else {
$backtrace = debug_backtrace();
$caller = $backtrace[1]['function'] ?? '[unknown caller]'; // TODO: Possible fix needed
Log::warning("Asset site {$assetSite} is used in {$caller}, but not set in application config; using first asset site if any");
if (count($assets) > 0) {
$url = array_values($assets)[0];
}
}
} else {
if (count($assets) > 0) {
$url = array_values($assets)[0];
}
}
if ($url == null) {
return static::makeUrl($path);
} else {
if (substr($url, -1) != '/') {
$url .= '/';
}
if (substr($path, 0, 1) == '/') {
$path = substr($path, 1);
}
return $url . $path;
}
} | [
"public",
"function",
"asset",
"(",
"string",
"$",
"path",
",",
"string",
"$",
"assetSite",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"strlen",
"(",
"$",
"path",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Expected non-empty string'",
")",
";",
"}",
"// if you pass the full URL that contains \"//\" part, it'll be immediately",
"// returned without any kind of building or parsing",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"path",
",",
"'//'",
")",
";",
"if",
"(",
"(",
"$",
"pos",
"!==",
"false",
"&&",
"$",
"pos",
"<",
"10",
")",
"||",
"substr",
"(",
"$",
"path",
",",
"0",
",",
"2",
")",
"==",
"'//'",
")",
"{",
"return",
"$",
"path",
";",
"}",
"$",
"assets",
"=",
"Application",
"::",
"getConfig",
"(",
"'application'",
")",
"->",
"get",
"(",
"'assets'",
")",
"??",
"[",
"]",
";",
"if",
"(",
"$",
"path",
"[",
"0",
"]",
"!=",
"'/'",
")",
"{",
"$",
"path",
"=",
"'/'",
".",
"$",
"path",
";",
"}",
"$",
"url",
"=",
"null",
";",
"if",
"(",
"$",
"assetSite",
"!=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"assets",
"[",
"$",
"assetSite",
"]",
")",
")",
"{",
"$",
"url",
"=",
"$",
"assets",
"[",
"$",
"assetSite",
"]",
";",
"}",
"else",
"{",
"$",
"backtrace",
"=",
"debug_backtrace",
"(",
")",
";",
"$",
"caller",
"=",
"$",
"backtrace",
"[",
"1",
"]",
"[",
"'function'",
"]",
"??",
"'[unknown caller]'",
";",
"// TODO: Possible fix needed",
"Log",
"::",
"warning",
"(",
"\"Asset site {$assetSite} is used in {$caller}, but not set in application config; using first asset site if any\"",
")",
";",
"if",
"(",
"count",
"(",
"$",
"assets",
")",
">",
"0",
")",
"{",
"$",
"url",
"=",
"array_values",
"(",
"$",
"assets",
")",
"[",
"0",
"]",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"count",
"(",
"$",
"assets",
")",
">",
"0",
")",
"{",
"$",
"url",
"=",
"array_values",
"(",
"$",
"assets",
")",
"[",
"0",
"]",
";",
"}",
"}",
"if",
"(",
"$",
"url",
"==",
"null",
")",
"{",
"return",
"static",
"::",
"makeUrl",
"(",
"$",
"path",
")",
";",
"}",
"else",
"{",
"if",
"(",
"substr",
"(",
"$",
"url",
",",
"-",
"1",
")",
"!=",
"'/'",
")",
"{",
"$",
"url",
".=",
"'/'",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"path",
",",
"0",
",",
"1",
")",
"==",
"'/'",
")",
"{",
"$",
"path",
"=",
"substr",
"(",
"$",
"path",
",",
"1",
")",
";",
"}",
"return",
"$",
"url",
".",
"$",
"path",
";",
"}",
"}"
]
| Generate link to the resource file on the same domain
@param string $path
@param string $assetSite [optional]
@return string
@throws \InvalidArgumentException | [
"Generate",
"link",
"to",
"the",
"resource",
"file",
"on",
"the",
"same",
"domain"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Route/AbstractRoute.php#L180-L233 | train |
koldy/framework | src/Koldy/Security/Csrf.php | Csrf.init | public static function init(array $config = null, bool $reInit = false)
{
if (static::$config === null || $reInit) {
if ($config === null) {
$config = Application::getConfig('application');
static::$config = $config->getArrayItem('security', 'csrf', [
//self::ENABLED => false,
self::PARAMETER_NAME => 'csrf',
self::COOKIE_NAME => 'csrf_token',
self::SESSION_KEY_NAME => 'csrf_token'
]);
} else {
static::$config = $config;
}
/* // CSRF is not started by default by framework any more
if (!array_key_exists(self::ENABLED, static::$config)) {
throw new ConfigException('Missing key \'enabled\' in security/CSRF config');
}
*/
//if (static::$config['enabled']) {
// check CSRF config
foreach ([self::PARAMETER_NAME, self::COOKIE_NAME, self::SESSION_KEY_NAME] as $key) {
if (!array_key_exists($key, static::$config)) {
throw new ConfigException("Missing {$key} key in security/CSRF config");
}
}
//}
}
} | php | public static function init(array $config = null, bool $reInit = false)
{
if (static::$config === null || $reInit) {
if ($config === null) {
$config = Application::getConfig('application');
static::$config = $config->getArrayItem('security', 'csrf', [
//self::ENABLED => false,
self::PARAMETER_NAME => 'csrf',
self::COOKIE_NAME => 'csrf_token',
self::SESSION_KEY_NAME => 'csrf_token'
]);
} else {
static::$config = $config;
}
/* // CSRF is not started by default by framework any more
if (!array_key_exists(self::ENABLED, static::$config)) {
throw new ConfigException('Missing key \'enabled\' in security/CSRF config');
}
*/
//if (static::$config['enabled']) {
// check CSRF config
foreach ([self::PARAMETER_NAME, self::COOKIE_NAME, self::SESSION_KEY_NAME] as $key) {
if (!array_key_exists($key, static::$config)) {
throw new ConfigException("Missing {$key} key in security/CSRF config");
}
}
//}
}
} | [
"public",
"static",
"function",
"init",
"(",
"array",
"$",
"config",
"=",
"null",
",",
"bool",
"$",
"reInit",
"=",
"false",
")",
"{",
"if",
"(",
"static",
"::",
"$",
"config",
"===",
"null",
"||",
"$",
"reInit",
")",
"{",
"if",
"(",
"$",
"config",
"===",
"null",
")",
"{",
"$",
"config",
"=",
"Application",
"::",
"getConfig",
"(",
"'application'",
")",
";",
"static",
"::",
"$",
"config",
"=",
"$",
"config",
"->",
"getArrayItem",
"(",
"'security'",
",",
"'csrf'",
",",
"[",
"//self::ENABLED => false,",
"self",
"::",
"PARAMETER_NAME",
"=>",
"'csrf'",
",",
"self",
"::",
"COOKIE_NAME",
"=>",
"'csrf_token'",
",",
"self",
"::",
"SESSION_KEY_NAME",
"=>",
"'csrf_token'",
"]",
")",
";",
"}",
"else",
"{",
"static",
"::",
"$",
"config",
"=",
"$",
"config",
";",
"}",
"/* // CSRF is not started by default by framework any more\n if (!array_key_exists(self::ENABLED, static::$config)) {\n throw new ConfigException('Missing key \\'enabled\\' in security/CSRF config');\n }\n */",
"//if (static::$config['enabled']) {",
"// check CSRF config",
"foreach",
"(",
"[",
"self",
"::",
"PARAMETER_NAME",
",",
"self",
"::",
"COOKIE_NAME",
",",
"self",
"::",
"SESSION_KEY_NAME",
"]",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"static",
"::",
"$",
"config",
")",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"\"Missing {$key} key in security/CSRF config\"",
")",
";",
"}",
"}",
"//}",
"}",
"}"
]
| Initialize CSRF config
@param array $config
@param bool $reInit
@throws ConfigException
@throws \Koldy\Exception | [
"Initialize",
"CSRF",
"config"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Security/Csrf.php#L45-L76 | train |
koldy/framework | src/Koldy/Security/Csrf.php | Csrf.generate | public static function generate(string $token = null, int $length = null): Token
{
if ($token == null) {
if ($length == null) {
$length = 64;
}
// generate token here
if (function_exists('openssl_random_pseudo_bytes')) {
$token = bin2hex(openssl_random_pseudo_bytes($length));
if (strlen($token) > $length) {
// we have a string, now, take some random part there
$token = substr($token, rand(0, strlen($token) - $length), $length);
}
} else {
// a fallback if openssl_random_pseudo_bytes is not accessible for some reason
$someString = time() . '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' . Application::getKey();
$token = substr(str_shuffle($someString), 0, $length);
}
}
$config = Application::getConfig('session');
$cookieName = static::getCookieName();
if (is_string($cookieName) && strlen($cookieName) > 0) {
$cookie = Cookie::rawSet($cookieName, $token, 0, '/', $config->get('domain', ''), $config->get('cookie_secure', false), false);
} else {
$cookie = null;
}
$token = new Token($token, $cookie);
static::$token = $token;
$sessionKeyName = static::getSessionKeyName();
if (is_string($sessionKeyName) && strlen($sessionKeyName) > 0) {
Session::set($sessionKeyName, $token);
}
return $token;
} | php | public static function generate(string $token = null, int $length = null): Token
{
if ($token == null) {
if ($length == null) {
$length = 64;
}
// generate token here
if (function_exists('openssl_random_pseudo_bytes')) {
$token = bin2hex(openssl_random_pseudo_bytes($length));
if (strlen($token) > $length) {
// we have a string, now, take some random part there
$token = substr($token, rand(0, strlen($token) - $length), $length);
}
} else {
// a fallback if openssl_random_pseudo_bytes is not accessible for some reason
$someString = time() . '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' . Application::getKey();
$token = substr(str_shuffle($someString), 0, $length);
}
}
$config = Application::getConfig('session');
$cookieName = static::getCookieName();
if (is_string($cookieName) && strlen($cookieName) > 0) {
$cookie = Cookie::rawSet($cookieName, $token, 0, '/', $config->get('domain', ''), $config->get('cookie_secure', false), false);
} else {
$cookie = null;
}
$token = new Token($token, $cookie);
static::$token = $token;
$sessionKeyName = static::getSessionKeyName();
if (is_string($sessionKeyName) && strlen($sessionKeyName) > 0) {
Session::set($sessionKeyName, $token);
}
return $token;
} | [
"public",
"static",
"function",
"generate",
"(",
"string",
"$",
"token",
"=",
"null",
",",
"int",
"$",
"length",
"=",
"null",
")",
":",
"Token",
"{",
"if",
"(",
"$",
"token",
"==",
"null",
")",
"{",
"if",
"(",
"$",
"length",
"==",
"null",
")",
"{",
"$",
"length",
"=",
"64",
";",
"}",
"// generate token here",
"if",
"(",
"function_exists",
"(",
"'openssl_random_pseudo_bytes'",
")",
")",
"{",
"$",
"token",
"=",
"bin2hex",
"(",
"openssl_random_pseudo_bytes",
"(",
"$",
"length",
")",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"token",
")",
">",
"$",
"length",
")",
"{",
"// we have a string, now, take some random part there",
"$",
"token",
"=",
"substr",
"(",
"$",
"token",
",",
"rand",
"(",
"0",
",",
"strlen",
"(",
"$",
"token",
")",
"-",
"$",
"length",
")",
",",
"$",
"length",
")",
";",
"}",
"}",
"else",
"{",
"// a fallback if openssl_random_pseudo_bytes is not accessible for some reason",
"$",
"someString",
"=",
"time",
"(",
")",
".",
"'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'",
".",
"Application",
"::",
"getKey",
"(",
")",
";",
"$",
"token",
"=",
"substr",
"(",
"str_shuffle",
"(",
"$",
"someString",
")",
",",
"0",
",",
"$",
"length",
")",
";",
"}",
"}",
"$",
"config",
"=",
"Application",
"::",
"getConfig",
"(",
"'session'",
")",
";",
"$",
"cookieName",
"=",
"static",
"::",
"getCookieName",
"(",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"cookieName",
")",
"&&",
"strlen",
"(",
"$",
"cookieName",
")",
">",
"0",
")",
"{",
"$",
"cookie",
"=",
"Cookie",
"::",
"rawSet",
"(",
"$",
"cookieName",
",",
"$",
"token",
",",
"0",
",",
"'/'",
",",
"$",
"config",
"->",
"get",
"(",
"'domain'",
",",
"''",
")",
",",
"$",
"config",
"->",
"get",
"(",
"'cookie_secure'",
",",
"false",
")",
",",
"false",
")",
";",
"}",
"else",
"{",
"$",
"cookie",
"=",
"null",
";",
"}",
"$",
"token",
"=",
"new",
"Token",
"(",
"$",
"token",
",",
"$",
"cookie",
")",
";",
"static",
"::",
"$",
"token",
"=",
"$",
"token",
";",
"$",
"sessionKeyName",
"=",
"static",
"::",
"getSessionKeyName",
"(",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"sessionKeyName",
")",
"&&",
"strlen",
"(",
"$",
"sessionKeyName",
")",
">",
"0",
")",
"{",
"Session",
"::",
"set",
"(",
"$",
"sessionKeyName",
",",
"$",
"token",
")",
";",
"}",
"return",
"$",
"token",
";",
"}"
]
| Set the CSRF token into current session.
@param null|string $token Your token, leave null if you want framework to generate it
@param null|int $length
@return Token
@throws ConfigException
@throws Session\Exception
@throws \Koldy\Exception | [
"Set",
"the",
"CSRF",
"token",
"into",
"current",
"session",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Security/Csrf.php#L115-L155 | train |
koldy/framework | src/Koldy/Security/Csrf.php | Csrf.isEnabled | public static function isEnabled(): bool
{
static::init();
if (array_key_exists(self::ENABLED, static::$config)) {
return static::$config[self::ENABLED] ?? false;
}
return static::getParameterName() !== null;
} | php | public static function isEnabled(): bool
{
static::init();
if (array_key_exists(self::ENABLED, static::$config)) {
return static::$config[self::ENABLED] ?? false;
}
return static::getParameterName() !== null;
} | [
"public",
"static",
"function",
"isEnabled",
"(",
")",
":",
"bool",
"{",
"static",
"::",
"init",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"self",
"::",
"ENABLED",
",",
"static",
"::",
"$",
"config",
")",
")",
"{",
"return",
"static",
"::",
"$",
"config",
"[",
"self",
"::",
"ENABLED",
"]",
"??",
"false",
";",
"}",
"return",
"static",
"::",
"getParameterName",
"(",
")",
"!==",
"null",
";",
"}"
]
| Is CSRF check enabled in config or not
@return bool
@throws ConfigException
@throws \Koldy\Exception | [
"Is",
"CSRF",
"check",
"enabled",
"in",
"config",
"or",
"not"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Security/Csrf.php#L164-L173 | train |
koldy/framework | src/Koldy/Security/Csrf.php | Csrf.hasTokenStored | public static function hasTokenStored(): bool
{
if (static::$token === null) {
try {
static::$token = static::getStoredToken();
} catch (SecurityException $e) {
// do nothing, so false will be returned
}
}
return static::$token !== null;
} | php | public static function hasTokenStored(): bool
{
if (static::$token === null) {
try {
static::$token = static::getStoredToken();
} catch (SecurityException $e) {
// do nothing, so false will be returned
}
}
return static::$token !== null;
} | [
"public",
"static",
"function",
"hasTokenStored",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"static",
"::",
"$",
"token",
"===",
"null",
")",
"{",
"try",
"{",
"static",
"::",
"$",
"token",
"=",
"static",
"::",
"getStoredToken",
"(",
")",
";",
"}",
"catch",
"(",
"SecurityException",
"$",
"e",
")",
"{",
"// do nothing, so false will be returned",
"}",
"}",
"return",
"static",
"::",
"$",
"token",
"!==",
"null",
";",
"}"
]
| Is there CSRF token stored in the session?
@return bool
@throws ConfigException
@throws \Koldy\Exception | [
"Is",
"there",
"CSRF",
"token",
"stored",
"in",
"the",
"session?"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Security/Csrf.php#L182-L193 | train |
koldy/framework | src/Koldy/Security/Csrf.php | Csrf.getStoredToken | public static function getStoredToken(): Token
{
if (static::$token !== null) {
return static::$token;
}
$sessionKeyName = static::getSessionKeyName();
if ($sessionKeyName === null || strlen($sessionKeyName) == 0) {
throw new Exception('Can not get stored CSRF token when session key is not set');
}
$token = Session::get($sessionKeyName);
if ($token === null) {
throw new SecurityException('There is no stored token on backend');
}
static::$token = $token;
return $token;
} | php | public static function getStoredToken(): Token
{
if (static::$token !== null) {
return static::$token;
}
$sessionKeyName = static::getSessionKeyName();
if ($sessionKeyName === null || strlen($sessionKeyName) == 0) {
throw new Exception('Can not get stored CSRF token when session key is not set');
}
$token = Session::get($sessionKeyName);
if ($token === null) {
throw new SecurityException('There is no stored token on backend');
}
static::$token = $token;
return $token;
} | [
"public",
"static",
"function",
"getStoredToken",
"(",
")",
":",
"Token",
"{",
"if",
"(",
"static",
"::",
"$",
"token",
"!==",
"null",
")",
"{",
"return",
"static",
"::",
"$",
"token",
";",
"}",
"$",
"sessionKeyName",
"=",
"static",
"::",
"getSessionKeyName",
"(",
")",
";",
"if",
"(",
"$",
"sessionKeyName",
"===",
"null",
"||",
"strlen",
"(",
"$",
"sessionKeyName",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Can not get stored CSRF token when session key is not set'",
")",
";",
"}",
"$",
"token",
"=",
"Session",
"::",
"get",
"(",
"$",
"sessionKeyName",
")",
";",
"if",
"(",
"$",
"token",
"===",
"null",
")",
"{",
"throw",
"new",
"SecurityException",
"(",
"'There is no stored token on backend'",
")",
";",
"}",
"static",
"::",
"$",
"token",
"=",
"$",
"token",
";",
"return",
"$",
"token",
";",
"}"
]
| Get currently stored CSRF token from session
@return Token
@throws ConfigException
@throws Exception
@throws \Koldy\Exception | [
"Get",
"currently",
"stored",
"CSRF",
"token",
"from",
"session"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Security/Csrf.php#L202-L222 | train |
koldy/framework | src/Koldy/Security/Csrf.php | Csrf.hasCookieToken | public static function hasCookieToken(): bool
{
$cookieName = static::getCookieName();
if ($cookieName === null || strlen($cookieName) == 0) {
throw new Exception('Can not check if CSRF token is in cookie when cookie name is not set in CSRF configuration');
}
return Cookie::has($cookieName);
} | php | public static function hasCookieToken(): bool
{
$cookieName = static::getCookieName();
if ($cookieName === null || strlen($cookieName) == 0) {
throw new Exception('Can not check if CSRF token is in cookie when cookie name is not set in CSRF configuration');
}
return Cookie::has($cookieName);
} | [
"public",
"static",
"function",
"hasCookieToken",
"(",
")",
":",
"bool",
"{",
"$",
"cookieName",
"=",
"static",
"::",
"getCookieName",
"(",
")",
";",
"if",
"(",
"$",
"cookieName",
"===",
"null",
"||",
"strlen",
"(",
"$",
"cookieName",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Can not check if CSRF token is in cookie when cookie name is not set in CSRF configuration'",
")",
";",
"}",
"return",
"Cookie",
"::",
"has",
"(",
"$",
"cookieName",
")",
";",
"}"
]
| Is there a cookie with CSRF token present in this request?
@return bool
@throws ConfigException
@throws Exception
@throws \Koldy\Exception | [
"Is",
"there",
"a",
"cookie",
"with",
"CSRF",
"token",
"present",
"in",
"this",
"request?"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Security/Csrf.php#L232-L241 | train |
koldy/framework | src/Koldy/Security/Csrf.php | Csrf.isTokenValid | public static function isTokenValid(string $token): bool
{
if (!static::hasTokenStored()) {
return false;
}
$storedToken = static::getStoredToken();
return $storedToken->getToken() === $token;
} | php | public static function isTokenValid(string $token): bool
{
if (!static::hasTokenStored()) {
return false;
}
$storedToken = static::getStoredToken();
return $storedToken->getToken() === $token;
} | [
"public",
"static",
"function",
"isTokenValid",
"(",
"string",
"$",
"token",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"static",
"::",
"hasTokenStored",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"storedToken",
"=",
"static",
"::",
"getStoredToken",
"(",
")",
";",
"return",
"$",
"storedToken",
"->",
"getToken",
"(",
")",
"===",
"$",
"token",
";",
"}"
]
| Check if given CSRF token is valid
@param string $token
@return bool
@throws ConfigException
@throws Exception
@throws \Koldy\Exception | [
"Check",
"if",
"given",
"CSRF",
"token",
"is",
"valid"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Security/Csrf.php#L253-L261 | train |
koldy/framework | src/Koldy/Security/Csrf.php | Csrf.getHtmlInputHidden | public static function getHtmlInputHidden(): string
{
static::init();
if (($parameterName = static::getParameterName()) !== null) {
$csrfValue = static::getStoredToken()->getToken();
return sprintf('<input type="hidden" name="%s" value="%s"/>', $parameterName, $csrfValue);
} else {
return '';
}
} | php | public static function getHtmlInputHidden(): string
{
static::init();
if (($parameterName = static::getParameterName()) !== null) {
$csrfValue = static::getStoredToken()->getToken();
return sprintf('<input type="hidden" name="%s" value="%s"/>', $parameterName, $csrfValue);
} else {
return '';
}
} | [
"public",
"static",
"function",
"getHtmlInputHidden",
"(",
")",
":",
"string",
"{",
"static",
"::",
"init",
"(",
")",
";",
"if",
"(",
"(",
"$",
"parameterName",
"=",
"static",
"::",
"getParameterName",
"(",
")",
")",
"!==",
"null",
")",
"{",
"$",
"csrfValue",
"=",
"static",
"::",
"getStoredToken",
"(",
")",
"->",
"getToken",
"(",
")",
";",
"return",
"sprintf",
"(",
"'<input type=\"hidden\" name=\"%s\" value=\"%s\"/>'",
",",
"$",
"parameterName",
",",
"$",
"csrfValue",
")",
";",
"}",
"else",
"{",
"return",
"''",
";",
"}",
"}"
]
| Get prepared HTML input that can be used directly in forms
@return string
@throws ConfigException
@throws Exception
@throws \Koldy\Exception | [
"Get",
"prepared",
"HTML",
"input",
"that",
"can",
"be",
"used",
"directly",
"in",
"forms"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Security/Csrf.php#L284-L294 | train |
dewsign/maxfactor-laravel-support | src/Video/Video.php | Video.embedCodeFor | public function embedCodeFor(string $url)
{
if (!$parsedUrl = $this->embedder->parseUrl($url)) {
return null;
}
return $parsedUrl->getEmbedCode();
} | php | public function embedCodeFor(string $url)
{
if (!$parsedUrl = $this->embedder->parseUrl($url)) {
return null;
}
return $parsedUrl->getEmbedCode();
} | [
"public",
"function",
"embedCodeFor",
"(",
"string",
"$",
"url",
")",
"{",
"if",
"(",
"!",
"$",
"parsedUrl",
"=",
"$",
"this",
"->",
"embedder",
"->",
"parseUrl",
"(",
"$",
"url",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"parsedUrl",
"->",
"getEmbedCode",
"(",
")",
";",
"}"
]
| Get the embed code for almost any hosted video service simply by peroviding its URL
@param string $url
@return string | [
"Get",
"the",
"embed",
"code",
"for",
"almost",
"any",
"hosted",
"video",
"service",
"simply",
"by",
"peroviding",
"its",
"URL"
]
| 49ad96edfdd7480a5f50ddea96800d1fe379a2b8 | https://github.com/dewsign/maxfactor-laravel-support/blob/49ad96edfdd7480a5f50ddea96800d1fe379a2b8/src/Video/Video.php#L22-L29 | train |
koldy/framework | src/Koldy/Http/Mime.php | Mime.getMimeByExtension | public static function getMimeByExtension(string $extension): string
{
$extension = strtolower($extension);
if (!isset(static::$types[$extension])) {
throw new HttpException("Unknown file extension={$extension}");
}
return static::$types[$extension];
} | php | public static function getMimeByExtension(string $extension): string
{
$extension = strtolower($extension);
if (!isset(static::$types[$extension])) {
throw new HttpException("Unknown file extension={$extension}");
}
return static::$types[$extension];
} | [
"public",
"static",
"function",
"getMimeByExtension",
"(",
"string",
"$",
"extension",
")",
":",
"string",
"{",
"$",
"extension",
"=",
"strtolower",
"(",
"$",
"extension",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"types",
"[",
"$",
"extension",
"]",
")",
")",
"{",
"throw",
"new",
"HttpException",
"(",
"\"Unknown file extension={$extension}\"",
")",
";",
"}",
"return",
"static",
"::",
"$",
"types",
"[",
"$",
"extension",
"]",
";",
"}"
]
| Get the MIME type by extension
@param string $extension
@return string
@throws Exception | [
"Get",
"the",
"MIME",
"type",
"by",
"extension"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Http/Mime.php#L1040-L1049 | train |
koldy/framework | src/Koldy/Db/Query/ResultSet.php | ResultSet.getCountQuery | protected function getCountQuery(): Select
{
if ($this->countQuery instanceof Select) {
return $this->countQuery;
}
if ($this->searchTerm !== null && $this->searchFields === null) {
$fields = $this->getFields();
$searchFields = [];
foreach ($fields as $field) {
$searchFields[] = $field['name'];
}
} else {
$searchFields = null;
}
$query = clone $this;
$query->resetFields();
$query->resetLimit();
$query->resetOrderBy();
$query->field('COUNT(*)', 'total');
if ($this->resetGroupBy) {
$query->resetGroupBy();
}
if ($searchFields !== null) {
$query->setSearchFields($searchFields);
}
return $query;
} | php | protected function getCountQuery(): Select
{
if ($this->countQuery instanceof Select) {
return $this->countQuery;
}
if ($this->searchTerm !== null && $this->searchFields === null) {
$fields = $this->getFields();
$searchFields = [];
foreach ($fields as $field) {
$searchFields[] = $field['name'];
}
} else {
$searchFields = null;
}
$query = clone $this;
$query->resetFields();
$query->resetLimit();
$query->resetOrderBy();
$query->field('COUNT(*)', 'total');
if ($this->resetGroupBy) {
$query->resetGroupBy();
}
if ($searchFields !== null) {
$query->setSearchFields($searchFields);
}
return $query;
} | [
"protected",
"function",
"getCountQuery",
"(",
")",
":",
"Select",
"{",
"if",
"(",
"$",
"this",
"->",
"countQuery",
"instanceof",
"Select",
")",
"{",
"return",
"$",
"this",
"->",
"countQuery",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"searchTerm",
"!==",
"null",
"&&",
"$",
"this",
"->",
"searchFields",
"===",
"null",
")",
"{",
"$",
"fields",
"=",
"$",
"this",
"->",
"getFields",
"(",
")",
";",
"$",
"searchFields",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"$",
"searchFields",
"[",
"]",
"=",
"$",
"field",
"[",
"'name'",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"searchFields",
"=",
"null",
";",
"}",
"$",
"query",
"=",
"clone",
"$",
"this",
";",
"$",
"query",
"->",
"resetFields",
"(",
")",
";",
"$",
"query",
"->",
"resetLimit",
"(",
")",
";",
"$",
"query",
"->",
"resetOrderBy",
"(",
")",
";",
"$",
"query",
"->",
"field",
"(",
"'COUNT(*)'",
",",
"'total'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"resetGroupBy",
")",
"{",
"$",
"query",
"->",
"resetGroupBy",
"(",
")",
";",
"}",
"if",
"(",
"$",
"searchFields",
"!==",
"null",
")",
"{",
"$",
"query",
"->",
"setSearchFields",
"(",
"$",
"searchFields",
")",
";",
"}",
"return",
"$",
"query",
";",
"}"
]
| Get SELECT query for total count
@return Select | [
"Get",
"SELECT",
"query",
"for",
"total",
"count"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Query/ResultSet.php#L91-L122 | train |
koldy/framework | src/Koldy/Log/Adapter/File.php | File.getFileName | protected function getFileName(): string
{
if ($this->generatedFileName === null || Application::isCli()) {
if ($this->fileNameFn !== null) {
$this->generatedFileName = call_user_func($this->fileNameFn);
} else {
$this->generatedFileName = gmdate('Y-m-d') . '.log';
}
}
return $this->generatedFileName;
} | php | protected function getFileName(): string
{
if ($this->generatedFileName === null || Application::isCli()) {
if ($this->fileNameFn !== null) {
$this->generatedFileName = call_user_func($this->fileNameFn);
} else {
$this->generatedFileName = gmdate('Y-m-d') . '.log';
}
}
return $this->generatedFileName;
} | [
"protected",
"function",
"getFileName",
"(",
")",
":",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"generatedFileName",
"===",
"null",
"||",
"Application",
"::",
"isCli",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"fileNameFn",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"generatedFileName",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"fileNameFn",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"generatedFileName",
"=",
"gmdate",
"(",
"'Y-m-d'",
")",
".",
"'.log'",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"generatedFileName",
";",
"}"
]
| Get the name of log file
@return string | [
"Get",
"the",
"name",
"of",
"log",
"file"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Log/Adapter/File.php#L141-L152 | train |
koldy/framework | src/Koldy/Log/Adapter/File.php | File.logMessage | public function logMessage(Message $message): void
{
if (in_array($message->getLevel(), $this->config['log'])) {
// If script is running for very long time (e.g. CRON), then date might change if time passes midnight.
// In that case, log will continue to write messages to new file.
$fpFile = $this->getFileName();
if ($fpFile !== $this->fpFile) {
//date has changed? or we need to init?
if ($this->fp) {
// close pointer to old file
@fclose($this->fp);
}
if ($this->config['path'] === null) {
$path = Application::getStoragePath('log' . DS . $fpFile);
} else {
$path = str_replace(DS . DS, DS, $this->config['path'] . DS . $fpFile);
}
$this->fpFile = $fpFile;
if (!($this->fp = @fopen($path, 'a'))) {
// file failed to open, maybe directory doesn't exists?
$dir = dirname($path);
if (!is_dir($dir)) {
Directory::mkdir($dir, $this->mode);
}
if (!($this->fp = @fopen($path, 'a'))) {
// now the directory should exists, so try to open file again
throw new Exception('Can not write to log file on path=' . $path);
}
}
}
if (!$this->fp || $this->fp === null) {
if ($this->config['path'] === null) {
$path = Application::getStoragePath('log' . DS . $fpFile);
} else {
$path = str_replace(DS . DS, DS, $this->config['path'] . DS . $fpFile);
}
throw new Exception("Can not write to log file path={$path}");
}
if ($this->getMessageFunction !== null) {
$line = call_user_func($this->getMessageFunction, $message);
} else {
$time = $message->getTime()->format('y-m-d H:i:s.v');
$level = strtoupper($message->getLevel());
$space = str_repeat(' ', 10 - strlen($level));
$who = $message->getWho() ?? Log::getWho();
$line = "{$time} {$level}{$space}{$who}\t{$message->getMessage()}\n";
}
if (!@fwrite($this->fp, $line)) { // actually write it in file
throw new Exception('Unable to write to log file');
}
}
} | php | public function logMessage(Message $message): void
{
if (in_array($message->getLevel(), $this->config['log'])) {
// If script is running for very long time (e.g. CRON), then date might change if time passes midnight.
// In that case, log will continue to write messages to new file.
$fpFile = $this->getFileName();
if ($fpFile !== $this->fpFile) {
//date has changed? or we need to init?
if ($this->fp) {
// close pointer to old file
@fclose($this->fp);
}
if ($this->config['path'] === null) {
$path = Application::getStoragePath('log' . DS . $fpFile);
} else {
$path = str_replace(DS . DS, DS, $this->config['path'] . DS . $fpFile);
}
$this->fpFile = $fpFile;
if (!($this->fp = @fopen($path, 'a'))) {
// file failed to open, maybe directory doesn't exists?
$dir = dirname($path);
if (!is_dir($dir)) {
Directory::mkdir($dir, $this->mode);
}
if (!($this->fp = @fopen($path, 'a'))) {
// now the directory should exists, so try to open file again
throw new Exception('Can not write to log file on path=' . $path);
}
}
}
if (!$this->fp || $this->fp === null) {
if ($this->config['path'] === null) {
$path = Application::getStoragePath('log' . DS . $fpFile);
} else {
$path = str_replace(DS . DS, DS, $this->config['path'] . DS . $fpFile);
}
throw new Exception("Can not write to log file path={$path}");
}
if ($this->getMessageFunction !== null) {
$line = call_user_func($this->getMessageFunction, $message);
} else {
$time = $message->getTime()->format('y-m-d H:i:s.v');
$level = strtoupper($message->getLevel());
$space = str_repeat(' ', 10 - strlen($level));
$who = $message->getWho() ?? Log::getWho();
$line = "{$time} {$level}{$space}{$who}\t{$message->getMessage()}\n";
}
if (!@fwrite($this->fp, $line)) { // actually write it in file
throw new Exception('Unable to write to log file');
}
}
} | [
"public",
"function",
"logMessage",
"(",
"Message",
"$",
"message",
")",
":",
"void",
"{",
"if",
"(",
"in_array",
"(",
"$",
"message",
"->",
"getLevel",
"(",
")",
",",
"$",
"this",
"->",
"config",
"[",
"'log'",
"]",
")",
")",
"{",
"// If script is running for very long time (e.g. CRON), then date might change if time passes midnight.",
"// In that case, log will continue to write messages to new file.",
"$",
"fpFile",
"=",
"$",
"this",
"->",
"getFileName",
"(",
")",
";",
"if",
"(",
"$",
"fpFile",
"!==",
"$",
"this",
"->",
"fpFile",
")",
"{",
"//date has changed? or we need to init?",
"if",
"(",
"$",
"this",
"->",
"fp",
")",
"{",
"// close pointer to old file",
"@",
"fclose",
"(",
"$",
"this",
"->",
"fp",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"config",
"[",
"'path'",
"]",
"===",
"null",
")",
"{",
"$",
"path",
"=",
"Application",
"::",
"getStoragePath",
"(",
"'log'",
".",
"DS",
".",
"$",
"fpFile",
")",
";",
"}",
"else",
"{",
"$",
"path",
"=",
"str_replace",
"(",
"DS",
".",
"DS",
",",
"DS",
",",
"$",
"this",
"->",
"config",
"[",
"'path'",
"]",
".",
"DS",
".",
"$",
"fpFile",
")",
";",
"}",
"$",
"this",
"->",
"fpFile",
"=",
"$",
"fpFile",
";",
"if",
"(",
"!",
"(",
"$",
"this",
"->",
"fp",
"=",
"@",
"fopen",
"(",
"$",
"path",
",",
"'a'",
")",
")",
")",
"{",
"// file failed to open, maybe directory doesn't exists?",
"$",
"dir",
"=",
"dirname",
"(",
"$",
"path",
")",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"Directory",
"::",
"mkdir",
"(",
"$",
"dir",
",",
"$",
"this",
"->",
"mode",
")",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"this",
"->",
"fp",
"=",
"@",
"fopen",
"(",
"$",
"path",
",",
"'a'",
")",
")",
")",
"{",
"// now the directory should exists, so try to open file again",
"throw",
"new",
"Exception",
"(",
"'Can not write to log file on path='",
".",
"$",
"path",
")",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"fp",
"||",
"$",
"this",
"->",
"fp",
"===",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"config",
"[",
"'path'",
"]",
"===",
"null",
")",
"{",
"$",
"path",
"=",
"Application",
"::",
"getStoragePath",
"(",
"'log'",
".",
"DS",
".",
"$",
"fpFile",
")",
";",
"}",
"else",
"{",
"$",
"path",
"=",
"str_replace",
"(",
"DS",
".",
"DS",
",",
"DS",
",",
"$",
"this",
"->",
"config",
"[",
"'path'",
"]",
".",
"DS",
".",
"$",
"fpFile",
")",
";",
"}",
"throw",
"new",
"Exception",
"(",
"\"Can not write to log file path={$path}\"",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getMessageFunction",
"!==",
"null",
")",
"{",
"$",
"line",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"getMessageFunction",
",",
"$",
"message",
")",
";",
"}",
"else",
"{",
"$",
"time",
"=",
"$",
"message",
"->",
"getTime",
"(",
")",
"->",
"format",
"(",
"'y-m-d H:i:s.v'",
")",
";",
"$",
"level",
"=",
"strtoupper",
"(",
"$",
"message",
"->",
"getLevel",
"(",
")",
")",
";",
"$",
"space",
"=",
"str_repeat",
"(",
"' '",
",",
"10",
"-",
"strlen",
"(",
"$",
"level",
")",
")",
";",
"$",
"who",
"=",
"$",
"message",
"->",
"getWho",
"(",
")",
"??",
"Log",
"::",
"getWho",
"(",
")",
";",
"$",
"line",
"=",
"\"{$time} {$level}{$space}{$who}\\t{$message->getMessage()}\\n\"",
";",
"}",
"if",
"(",
"!",
"@",
"fwrite",
"(",
"$",
"this",
"->",
"fp",
",",
"$",
"line",
")",
")",
"{",
"// actually write it in file",
"throw",
"new",
"Exception",
"(",
"'Unable to write to log file'",
")",
";",
"}",
"}",
"}"
]
| Actually log message to file
@param Message $message
@throws ConfigException
@throws Exception
@throws \Koldy\Exception
@throws \Koldy\Filesystem\Exception | [
"Actually",
"log",
"message",
"to",
"file"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Log/Adapter/File.php#L164-L224 | train |
koldy/framework | src/Koldy/Url.php | Url.getScheme | public function getScheme(): string
{
if (!isset($this->segments['scheme'])) {
throw new UrlException('Unable to get scheme for ' . $this->url);
}
return $this->segments['scheme'];
} | php | public function getScheme(): string
{
if (!isset($this->segments['scheme'])) {
throw new UrlException('Unable to get scheme for ' . $this->url);
}
return $this->segments['scheme'];
} | [
"public",
"function",
"getScheme",
"(",
")",
":",
"string",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"segments",
"[",
"'scheme'",
"]",
")",
")",
"{",
"throw",
"new",
"UrlException",
"(",
"'Unable to get scheme for '",
".",
"$",
"this",
"->",
"url",
")",
";",
"}",
"return",
"$",
"this",
"->",
"segments",
"[",
"'scheme'",
"]",
";",
"}"
]
| Get URL's scheme
@return string
@throws \Koldy\Url\Exception | [
"Get",
"URL",
"s",
"scheme"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Url.php#L46-L53 | train |
koldy/framework | src/Koldy/Url.php | Url.getHost | public function getHost(): string
{
if (!isset($this->segments['host'])) {
throw new UrlException('Unable to get host for ' . $this->url);
}
return $this->segments['host'];
} | php | public function getHost(): string
{
if (!isset($this->segments['host'])) {
throw new UrlException('Unable to get host for ' . $this->url);
}
return $this->segments['host'];
} | [
"public",
"function",
"getHost",
"(",
")",
":",
"string",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"segments",
"[",
"'host'",
"]",
")",
")",
"{",
"throw",
"new",
"UrlException",
"(",
"'Unable to get host for '",
".",
"$",
"this",
"->",
"url",
")",
";",
"}",
"return",
"$",
"this",
"->",
"segments",
"[",
"'host'",
"]",
";",
"}"
]
| Get URL's host
@return string
@throws \Koldy\Url\Exception | [
"Get",
"URL",
"s",
"host"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Url.php#L61-L68 | train |
koldy/framework | src/Koldy/Url.php | Url.getPort | public function getPort(): int
{
if (!isset($this->segments['port'])) {
throw new UrlException('Unable to get port for ' . $this->url);
}
return (int)$this->segments['port'];
} | php | public function getPort(): int
{
if (!isset($this->segments['port'])) {
throw new UrlException('Unable to get port for ' . $this->url);
}
return (int)$this->segments['port'];
} | [
"public",
"function",
"getPort",
"(",
")",
":",
"int",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"segments",
"[",
"'port'",
"]",
")",
")",
"{",
"throw",
"new",
"UrlException",
"(",
"'Unable to get port for '",
".",
"$",
"this",
"->",
"url",
")",
";",
"}",
"return",
"(",
"int",
")",
"$",
"this",
"->",
"segments",
"[",
"'port'",
"]",
";",
"}"
]
| Get URL's port
@return int
@throws \Koldy\Url\Exception | [
"Get",
"URL",
"s",
"port"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Url.php#L76-L83 | train |
koldy/framework | src/Koldy/Url.php | Url.getUser | public function getUser(): string
{
if (!isset($this->segments['user'])) {
throw new UrlException('Unable to get user for ' . $this->url);
}
return $this->segments['user'];
} | php | public function getUser(): string
{
if (!isset($this->segments['user'])) {
throw new UrlException('Unable to get user for ' . $this->url);
}
return $this->segments['user'];
} | [
"public",
"function",
"getUser",
"(",
")",
":",
"string",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"segments",
"[",
"'user'",
"]",
")",
")",
"{",
"throw",
"new",
"UrlException",
"(",
"'Unable to get user for '",
".",
"$",
"this",
"->",
"url",
")",
";",
"}",
"return",
"$",
"this",
"->",
"segments",
"[",
"'user'",
"]",
";",
"}"
]
| Get URL's user
@return string
@throws \Koldy\Url\Exception | [
"Get",
"URL",
"s",
"user"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Url.php#L91-L98 | train |
koldy/framework | src/Koldy/Url.php | Url.getPass | public function getPass(): string
{
if (!isset($this->segments['pass'])) {
throw new UrlException('Unable to get pass for ' . $this->url);
}
return $this->segments['pass'];
} | php | public function getPass(): string
{
if (!isset($this->segments['pass'])) {
throw new UrlException('Unable to get pass for ' . $this->url);
}
return $this->segments['pass'];
} | [
"public",
"function",
"getPass",
"(",
")",
":",
"string",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"segments",
"[",
"'pass'",
"]",
")",
")",
"{",
"throw",
"new",
"UrlException",
"(",
"'Unable to get pass for '",
".",
"$",
"this",
"->",
"url",
")",
";",
"}",
"return",
"$",
"this",
"->",
"segments",
"[",
"'pass'",
"]",
";",
"}"
]
| Get URL's pass
@return string
@throws \Koldy\Url\Exception | [
"Get",
"URL",
"s",
"pass"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Url.php#L106-L113 | train |
koldy/framework | src/Koldy/Db/Adapter/PostgreSQL.php | PostgreSQL.close | public function close(): void
{
if ($this->pdo instanceof PDO) {
if ($this->stmt !== null) {
$this->stmt->closeCursor();
}
$this->stmt = null;
$this->pdo = null;
} else if ($this->pdo === null) {
// to nothing
} else {
throw new AdapterException('Unable to close database connection when PDO handler is not an instance of PDO');
}
} | php | public function close(): void
{
if ($this->pdo instanceof PDO) {
if ($this->stmt !== null) {
$this->stmt->closeCursor();
}
$this->stmt = null;
$this->pdo = null;
} else if ($this->pdo === null) {
// to nothing
} else {
throw new AdapterException('Unable to close database connection when PDO handler is not an instance of PDO');
}
} | [
"public",
"function",
"close",
"(",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"pdo",
"instanceof",
"PDO",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"stmt",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"stmt",
"->",
"closeCursor",
"(",
")",
";",
"}",
"$",
"this",
"->",
"stmt",
"=",
"null",
";",
"$",
"this",
"->",
"pdo",
"=",
"null",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"pdo",
"===",
"null",
")",
"{",
"// to nothing",
"}",
"else",
"{",
"throw",
"new",
"AdapterException",
"(",
"'Unable to close database connection when PDO handler is not an instance of PDO'",
")",
";",
"}",
"}"
]
| Close connection to database if it was opened
@throws Exception | [
"Close",
"connection",
"to",
"database",
"if",
"it",
"was",
"opened"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Adapter/PostgreSQL.php#L87-L103 | train |
koldy/framework | src/Koldy/Db/Adapter/PostgreSQL.php | PostgreSQL.isBoolTrue | public static function isBoolTrue(?string $input): ?bool
{
if ($input === null) {
return null;
}
$input = strtolower($input);
if ($input === 'true' || $input === '1') {
return true;
} else if ($input === 'false' || $input === '0' || $input === '') {
return false;
}
throw new LanguageException('Unable to determine if given $input is boolean');
} | php | public static function isBoolTrue(?string $input): ?bool
{
if ($input === null) {
return null;
}
$input = strtolower($input);
if ($input === 'true' || $input === '1') {
return true;
} else if ($input === 'false' || $input === '0' || $input === '') {
return false;
}
throw new LanguageException('Unable to determine if given $input is boolean');
} | [
"public",
"static",
"function",
"isBoolTrue",
"(",
"?",
"string",
"$",
"input",
")",
":",
"?",
"bool",
"{",
"if",
"(",
"$",
"input",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"$",
"input",
"=",
"strtolower",
"(",
"$",
"input",
")",
";",
"if",
"(",
"$",
"input",
"===",
"'true'",
"||",
"$",
"input",
"===",
"'1'",
")",
"{",
"return",
"true",
";",
"}",
"else",
"if",
"(",
"$",
"input",
"===",
"'false'",
"||",
"$",
"input",
"===",
"'0'",
"||",
"$",
"input",
"===",
"''",
")",
"{",
"return",
"false",
";",
"}",
"throw",
"new",
"LanguageException",
"(",
"'Unable to determine if given $input is boolean'",
")",
";",
"}"
]
| Helper for Postgres determining if there's a boolean value in database. This is useful because PDO on Postgres
returns string for boolean values.
If you pass null as parameter, you'll get null back.
@param null|string $input
@return bool|null
@throws LanguageException | [
"Helper",
"for",
"Postgres",
"determining",
"if",
"there",
"s",
"a",
"boolean",
"value",
"in",
"database",
".",
"This",
"is",
"useful",
"because",
"PDO",
"on",
"Postgres",
"returns",
"string",
"for",
"boolean",
"values",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Adapter/PostgreSQL.php#L116-L132 | train |
dewsign/maxfactor-laravel-support | src/Webpage/Traits/IsWebpage.php | IsWebpage.render | public function render($content = null)
{
if (method_exists($this, 'seed')) {
$this->append('seed', $this->seed()->all());
}
return view("{$this->namespace}{$this->template}", $content ? : $this->content);
} | php | public function render($content = null)
{
if (method_exists($this, 'seed')) {
$this->append('seed', $this->seed()->all());
}
return view("{$this->namespace}{$this->template}", $content ? : $this->content);
} | [
"public",
"function",
"render",
"(",
"$",
"content",
"=",
"null",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"'seed'",
")",
")",
"{",
"$",
"this",
"->",
"append",
"(",
"'seed'",
",",
"$",
"this",
"->",
"seed",
"(",
")",
"->",
"all",
"(",
")",
")",
";",
"}",
"return",
"view",
"(",
"\"{$this->namespace}{$this->template}\"",
",",
"$",
"content",
"?",
":",
"$",
"this",
"->",
"content",
")",
";",
"}"
]
| Render the page content into the relevant template. Can pass in optional
replacement content to render instead of the default.
@param $content
@return View/Redirect | [
"Render",
"the",
"page",
"content",
"into",
"the",
"relevant",
"template",
".",
"Can",
"pass",
"in",
"optional",
"replacement",
"content",
"to",
"render",
"instead",
"of",
"the",
"default",
"."
]
| 49ad96edfdd7480a5f50ddea96800d1fe379a2b8 | https://github.com/dewsign/maxfactor-laravel-support/blob/49ad96edfdd7480a5f50ddea96800d1fe379a2b8/src/Webpage/Traits/IsWebpage.php#L31-L38 | train |
dewsign/maxfactor-laravel-support | src/Webpage/Traits/IsWebpage.php | IsWebpage.raw | public function raw(bool $collapsed = false): \Illuminate\Support\Collection
{
if ($collapsed) {
return $this->content->collapse();
}
return $this->content;
} | php | public function raw(bool $collapsed = false): \Illuminate\Support\Collection
{
if ($collapsed) {
return $this->content->collapse();
}
return $this->content;
} | [
"public",
"function",
"raw",
"(",
"bool",
"$",
"collapsed",
"=",
"false",
")",
":",
"\\",
"Illuminate",
"\\",
"Support",
"\\",
"Collection",
"{",
"if",
"(",
"$",
"collapsed",
")",
"{",
"return",
"$",
"this",
"->",
"content",
"->",
"collapse",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"content",
";",
"}"
]
| Return the raw content retrieved from the api for out-of-class processing.
@param bool $collapsed
@return \Illuminate\Support\Collection | [
"Return",
"the",
"raw",
"content",
"retrieved",
"from",
"the",
"api",
"for",
"out",
"-",
"of",
"-",
"class",
"processing",
"."
]
| 49ad96edfdd7480a5f50ddea96800d1fe379a2b8 | https://github.com/dewsign/maxfactor-laravel-support/blob/49ad96edfdd7480a5f50ddea96800d1fe379a2b8/src/Webpage/Traits/IsWebpage.php#L46-L53 | train |
koldy/framework | src/Koldy/Db/ModelTraits/CreatedAt.php | CreatedAt.setCreatedAtDateTime | public function setCreatedAtDateTime(?DateTime $createdAt)
{
$this->created_at = $createdAt === null ? null : $createdAt->format('Y-m-d H:i:s');
return $this;
} | php | public function setCreatedAtDateTime(?DateTime $createdAt)
{
$this->created_at = $createdAt === null ? null : $createdAt->format('Y-m-d H:i:s');
return $this;
} | [
"public",
"function",
"setCreatedAtDateTime",
"(",
"?",
"DateTime",
"$",
"createdAt",
")",
"{",
"$",
"this",
"->",
"created_at",
"=",
"$",
"createdAt",
"===",
"null",
"?",
"null",
":",
"$",
"createdAt",
"->",
"format",
"(",
"'Y-m-d H:i:s'",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Set the created at date time by passing instance of createdAt
@param DateTime $createdAt
@return $this | [
"Set",
"the",
"created",
"at",
"date",
"time",
"by",
"passing",
"instance",
"of",
"createdAt"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/ModelTraits/CreatedAt.php#L112-L116 | train |
koldy/framework | src/Koldy/Mail.php | Mail.isEnabled | public static function isEnabled(string $adapter): bool
{
$config = static::getConfig();
if (!$config->has($adapter)) {
return false;
}
$enabled = $config->getArrayItem($adapter, 'enabled');
if ($enabled === null) {
return false;
}
return (bool)$enabled;
} | php | public static function isEnabled(string $adapter): bool
{
$config = static::getConfig();
if (!$config->has($adapter)) {
return false;
}
$enabled = $config->getArrayItem($adapter, 'enabled');
if ($enabled === null) {
return false;
}
return (bool)$enabled;
} | [
"public",
"static",
"function",
"isEnabled",
"(",
"string",
"$",
"adapter",
")",
":",
"bool",
"{",
"$",
"config",
"=",
"static",
"::",
"getConfig",
"(",
")",
";",
"if",
"(",
"!",
"$",
"config",
"->",
"has",
"(",
"$",
"adapter",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"enabled",
"=",
"$",
"config",
"->",
"getArrayItem",
"(",
"$",
"adapter",
",",
"'enabled'",
")",
";",
"if",
"(",
"$",
"enabled",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
"bool",
")",
"$",
"enabled",
";",
"}"
]
| You can check if configure mail adapter is enabled or not.
@param string $adapter
@return boolean
@throws ConfigException
@throws Exception | [
"You",
"can",
"check",
"if",
"configure",
"mail",
"adapter",
"is",
"enabled",
"or",
"not",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Mail.php#L111-L125 | train |
koldy/framework | src/Koldy/Log/Adapter/Other.php | Other.logMessage | public function logMessage(Message $message): void
{
if (in_array($message->getLevel(), $this->config['log'])) {
if ($this->config['send_immediately']) {
call_user_func($this->config['exec'], $message);
} else {
$this->messages[] = $message;
if (count($this->messages) == 1) {
// register shutdown on first message in queue
$self = $this;
register_shutdown_function(function () use ($self) {
$fn = $self->getExecFunction();
call_user_func($fn, $self->getMessages());
});
}
}
}
} | php | public function logMessage(Message $message): void
{
if (in_array($message->getLevel(), $this->config['log'])) {
if ($this->config['send_immediately']) {
call_user_func($this->config['exec'], $message);
} else {
$this->messages[] = $message;
if (count($this->messages) == 1) {
// register shutdown on first message in queue
$self = $this;
register_shutdown_function(function () use ($self) {
$fn = $self->getExecFunction();
call_user_func($fn, $self->getMessages());
});
}
}
}
} | [
"public",
"function",
"logMessage",
"(",
"Message",
"$",
"message",
")",
":",
"void",
"{",
"if",
"(",
"in_array",
"(",
"$",
"message",
"->",
"getLevel",
"(",
")",
",",
"$",
"this",
"->",
"config",
"[",
"'log'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"config",
"[",
"'send_immediately'",
"]",
")",
"{",
"call_user_func",
"(",
"$",
"this",
"->",
"config",
"[",
"'exec'",
"]",
",",
"$",
"message",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"messages",
"[",
"]",
"=",
"$",
"message",
";",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"messages",
")",
"==",
"1",
")",
"{",
"// register shutdown on first message in queue",
"$",
"self",
"=",
"$",
"this",
";",
"register_shutdown_function",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"self",
")",
"{",
"$",
"fn",
"=",
"$",
"self",
"->",
"getExecFunction",
"(",
")",
";",
"call_user_func",
"(",
"$",
"fn",
",",
"$",
"self",
"->",
"getMessages",
"(",
")",
")",
";",
"}",
")",
";",
"}",
"}",
"}",
"}"
]
| Actually execute something with our messages
@param Message $message | [
"Actually",
"execute",
"something",
"with",
"our",
"messages"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Log/Adapter/Other.php#L67-L87 | train |
koldy/framework | src/Koldy/Db.php | Db.registerType | public static function registerType(string $type, string $class): void
{
if (isset(static::$types[$type])) {
throw new ConfigException("Can not register database type={$type} when it was already registered");
}
static::$types[$type] = $class;
} | php | public static function registerType(string $type, string $class): void
{
if (isset(static::$types[$type])) {
throw new ConfigException("Can not register database type={$type} when it was already registered");
}
static::$types[$type] = $class;
} | [
"public",
"static",
"function",
"registerType",
"(",
"string",
"$",
"type",
",",
"string",
"$",
"class",
")",
":",
"void",
"{",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"types",
"[",
"$",
"type",
"]",
")",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"\"Can not register database type={$type} when it was already registered\"",
")",
";",
"}",
"static",
"::",
"$",
"types",
"[",
"$",
"type",
"]",
"=",
"$",
"class",
";",
"}"
]
| Register another database type
@param string $type
@param string $class
@throws ConfigException | [
"Register",
"another",
"database",
"type"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db.php#L108-L115 | train |
koldy/framework | src/Koldy/Db.php | Db.hasAdapter | public static function hasAdapter(string $name): bool
{
return isset(static::$adapters[$name]) && static::$adapters[$name] instanceof AbstractAdapter;
} | php | public static function hasAdapter(string $name): bool
{
return isset(static::$adapters[$name]) && static::$adapters[$name] instanceof AbstractAdapter;
} | [
"public",
"static",
"function",
"hasAdapter",
"(",
"string",
"$",
"name",
")",
":",
"bool",
"{",
"return",
"isset",
"(",
"static",
"::",
"$",
"adapters",
"[",
"$",
"name",
"]",
")",
"&&",
"static",
"::",
"$",
"adapters",
"[",
"$",
"name",
"]",
"instanceof",
"AbstractAdapter",
";",
"}"
]
| Is there already adapter with given name
@param string $name
@return bool | [
"Is",
"there",
"already",
"adapter",
"with",
"given",
"name"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db.php#L139-L142 | train |
koldy/framework | src/Koldy/Db.php | Db.removeAdapter | public static function removeAdapter(string $keyIdentifier): void
{
if (isset(static::$adapters[$keyIdentifier])) {
static::$adapters[$keyIdentifier]->close();
unset(static::$adapters[$keyIdentifier]);
}
} | php | public static function removeAdapter(string $keyIdentifier): void
{
if (isset(static::$adapters[$keyIdentifier])) {
static::$adapters[$keyIdentifier]->close();
unset(static::$adapters[$keyIdentifier]);
}
} | [
"public",
"static",
"function",
"removeAdapter",
"(",
"string",
"$",
"keyIdentifier",
")",
":",
"void",
"{",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"adapters",
"[",
"$",
"keyIdentifier",
"]",
")",
")",
"{",
"static",
"::",
"$",
"adapters",
"[",
"$",
"keyIdentifier",
"]",
"->",
"close",
"(",
")",
";",
"unset",
"(",
"static",
"::",
"$",
"adapters",
"[",
"$",
"keyIdentifier",
"]",
")",
";",
"}",
"}"
]
| Delete registered adapter. This action will also remove connection if it was connected to database
@param string $keyIdentifier | [
"Delete",
"registered",
"adapter",
".",
"This",
"action",
"will",
"also",
"remove",
"connection",
"if",
"it",
"was",
"connected",
"to",
"database"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db.php#L149-L155 | train |
koldy/framework | src/Koldy/Db.php | Db.select | public static function select(string $table = null, string $tableAlias = null): Query\Select
{
return static::getAdapter()->select($table, $tableAlias);
} | php | public static function select(string $table = null, string $tableAlias = null): Query\Select
{
return static::getAdapter()->select($table, $tableAlias);
} | [
"public",
"static",
"function",
"select",
"(",
"string",
"$",
"table",
"=",
"null",
",",
"string",
"$",
"tableAlias",
"=",
"null",
")",
":",
"Query",
"\\",
"Select",
"{",
"return",
"static",
"::",
"getAdapter",
"(",
")",
"->",
"select",
"(",
"$",
"table",
",",
"$",
"tableAlias",
")",
";",
"}"
]
| Get the SELECT query instance on default adapter
@param string|null $table
@param string|null $tableAlias
@return Query\Select
@throws Config\Exception
@throws DbException
@throws Exception | [
"Get",
"the",
"SELECT",
"query",
"instance",
"on",
"default",
"adapter"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db.php#L235-L238 | train |
koldy/framework | src/Koldy/Db.php | Db.insert | public static function insert(string $table = null, array $rowValues = null): Query\Insert
{
return static::getAdapter()->insert($table, $rowValues);
} | php | public static function insert(string $table = null, array $rowValues = null): Query\Insert
{
return static::getAdapter()->insert($table, $rowValues);
} | [
"public",
"static",
"function",
"insert",
"(",
"string",
"$",
"table",
"=",
"null",
",",
"array",
"$",
"rowValues",
"=",
"null",
")",
":",
"Query",
"\\",
"Insert",
"{",
"return",
"static",
"::",
"getAdapter",
"(",
")",
"->",
"insert",
"(",
"$",
"table",
",",
"$",
"rowValues",
")",
";",
"}"
]
| Get the INSERT query instance on default adapter
@param string|null $table
@param array|null $rowValues
@return Query\Insert
@throws Config\Exception
@throws DbException
@throws Exception
@throws Json\Exception | [
"Get",
"the",
"INSERT",
"query",
"instance",
"on",
"default",
"adapter"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db.php#L252-L255 | train |
koldy/framework | src/Koldy/Db.php | Db.update | public static function update(string $table = null, array $values = null): Query\Update
{
return static::getAdapter()->update($table, $values);
} | php | public static function update(string $table = null, array $values = null): Query\Update
{
return static::getAdapter()->update($table, $values);
} | [
"public",
"static",
"function",
"update",
"(",
"string",
"$",
"table",
"=",
"null",
",",
"array",
"$",
"values",
"=",
"null",
")",
":",
"Query",
"\\",
"Update",
"{",
"return",
"static",
"::",
"getAdapter",
"(",
")",
"->",
"update",
"(",
"$",
"table",
",",
"$",
"values",
")",
";",
"}"
]
| Get the UPDATE query instance on default adapter
@param string|null $table
@param array|null $values
@return Query\Update
@throws Config\Exception
@throws DbException
@throws Exception | [
"Get",
"the",
"UPDATE",
"query",
"instance",
"on",
"default",
"adapter"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db.php#L268-L271 | train |
koldy/framework | src/Koldy/Response/ContentDownload.php | ContentDownload.create | public static function create(string $content, string $asName, string $contentType = null): ContentDownload
{
$self = new static($content);
$self->setAsName($asName);
if ($contentType !== null) {
$self->setContentType($contentType);
}
return $self;
} | php | public static function create(string $content, string $asName, string $contentType = null): ContentDownload
{
$self = new static($content);
$self->setAsName($asName);
if ($contentType !== null) {
$self->setContentType($contentType);
}
return $self;
} | [
"public",
"static",
"function",
"create",
"(",
"string",
"$",
"content",
",",
"string",
"$",
"asName",
",",
"string",
"$",
"contentType",
"=",
"null",
")",
":",
"ContentDownload",
"{",
"$",
"self",
"=",
"new",
"static",
"(",
"$",
"content",
")",
";",
"$",
"self",
"->",
"setAsName",
"(",
"$",
"asName",
")",
";",
"if",
"(",
"$",
"contentType",
"!==",
"null",
")",
"{",
"$",
"self",
"->",
"setContentType",
"(",
"$",
"contentType",
")",
";",
"}",
"return",
"$",
"self",
";",
"}"
]
| Shorthand for creating this class, pass all required parameters at once
@param string $content
@param string $asName
@param string $contentType [optional]
@return ContentDownload | [
"Shorthand",
"for",
"creating",
"this",
"class",
"pass",
"all",
"required",
"parameters",
"at",
"once"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Response/ContentDownload.php#L78-L88 | train |
koldy/framework | src/Koldy/Cache.php | Cache.set | public static function set(string $key, $value, int $seconds = null): void
{
static::getAdapter()->set($key, $value, $seconds);
} | php | public static function set(string $key, $value, int $seconds = null): void
{
static::getAdapter()->set($key, $value, $seconds);
} | [
"public",
"static",
"function",
"set",
"(",
"string",
"$",
"key",
",",
"$",
"value",
",",
"int",
"$",
"seconds",
"=",
"null",
")",
":",
"void",
"{",
"static",
"::",
"getAdapter",
"(",
")",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"seconds",
")",
";",
"}"
]
| Set the value to default cache engine and overwrite if keys already exists
@param string $key
@param mixed $value
@param int $seconds [optional]
@throws Exception
@link http://koldy.net/docs/cache#set | [
"Set",
"the",
"value",
"to",
"default",
"cache",
"engine",
"and",
"overwrite",
"if",
"keys",
"already",
"exists"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Cache.php#L115-L118 | train |
koldy/framework | src/Koldy/Cache.php | Cache.setMulti | public static function setMulti(array $keyValuePairs, int $seconds = null): void
{
static::getAdapter()->setMulti($keyValuePairs, $seconds);
} | php | public static function setMulti(array $keyValuePairs, int $seconds = null): void
{
static::getAdapter()->setMulti($keyValuePairs, $seconds);
} | [
"public",
"static",
"function",
"setMulti",
"(",
"array",
"$",
"keyValuePairs",
",",
"int",
"$",
"seconds",
"=",
"null",
")",
":",
"void",
"{",
"static",
"::",
"getAdapter",
"(",
")",
"->",
"setMulti",
"(",
"$",
"keyValuePairs",
",",
"$",
"seconds",
")",
";",
"}"
]
| Set multiple values to default cache engine and overwrite if keys already exists
@param array $keyValuePairs
@param int $seconds [optional]
@throws Exception
@link http://koldy.net/docs/cache#set-multi | [
"Set",
"multiple",
"values",
"to",
"default",
"cache",
"engine",
"and",
"overwrite",
"if",
"keys",
"already",
"exists"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Cache.php#L129-L132 | train |
koldy/framework | src/Koldy/Cache.php | Cache.getOrSet | public static function getOrSet(string $key, \Closure $functionOnSet, int $seconds = null)
{
return static::getAdapter()->getOrSet($key, $functionOnSet, $seconds);
} | php | public static function getOrSet(string $key, \Closure $functionOnSet, int $seconds = null)
{
return static::getAdapter()->getOrSet($key, $functionOnSet, $seconds);
} | [
"public",
"static",
"function",
"getOrSet",
"(",
"string",
"$",
"key",
",",
"\\",
"Closure",
"$",
"functionOnSet",
",",
"int",
"$",
"seconds",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"getAdapter",
"(",
")",
"->",
"getOrSet",
"(",
"$",
"key",
",",
"$",
"functionOnSet",
",",
"$",
"seconds",
")",
";",
"}"
]
| Get or set the key's value
@param string $key
@param \Closure $functionOnSet
@param int $seconds
@return mixed
@throws Exception
@link http://koldy.net/docs/cache#get-or-set | [
"Get",
"or",
"set",
"the",
"key",
"s",
"value"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Cache.php#L185-L188 | train |
koldy/framework | src/Koldy/Cache.php | Cache.increment | public static function increment(string $key, int $howMuch = 1): int
{
return static::getAdapter()->increment($key, $howMuch);
} | php | public static function increment(string $key, int $howMuch = 1): int
{
return static::getAdapter()->increment($key, $howMuch);
} | [
"public",
"static",
"function",
"increment",
"(",
"string",
"$",
"key",
",",
"int",
"$",
"howMuch",
"=",
"1",
")",
":",
"int",
"{",
"return",
"static",
"::",
"getAdapter",
"(",
")",
"->",
"increment",
"(",
"$",
"key",
",",
"$",
"howMuch",
")",
";",
"}"
]
| Increment value in cache
@param string $key
@param int $howMuch
@return int
@throws Exception
@link http://koldy.net/docs/cache#increment-decrement | [
"Increment",
"value",
"in",
"cache"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Cache.php#L201-L204 | train |
koldy/framework | src/Koldy/Cache.php | Cache.decrement | public static function decrement(string $key, int $howMuch = 1): int
{
return static::getAdapter()->decrement($key, $howMuch);
} | php | public static function decrement(string $key, int $howMuch = 1): int
{
return static::getAdapter()->decrement($key, $howMuch);
} | [
"public",
"static",
"function",
"decrement",
"(",
"string",
"$",
"key",
",",
"int",
"$",
"howMuch",
"=",
"1",
")",
":",
"int",
"{",
"return",
"static",
"::",
"getAdapter",
"(",
")",
"->",
"decrement",
"(",
"$",
"key",
",",
"$",
"howMuch",
")",
";",
"}"
]
| Decrement value in cache
@param string $key
@param int $howMuch
@return int
@throws Exception
@link http://koldy.net/docs/cache#increment-decrement | [
"Decrement",
"value",
"in",
"cache"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Cache.php#L217-L220 | train |
koldy/framework | src/Koldy/Db/Query.php | Query.setQuery | public function setQuery(string $query, $bindings = null): Query
{
$this->query = $query;
if ($bindings === null) {
$this->bindings = new Bindings();
} else if (is_array($bindings)) {
$this->bindings = new Bindings();
$this->bindings->setFromArray($bindings);
} else if ($bindings instanceof Bindings) {
$this->bindings = $bindings;
} else {
throw new \InvalidArgumentException('Invalid second argument provided, expected null, array or instance of Bindings');
}
return $this;
} | php | public function setQuery(string $query, $bindings = null): Query
{
$this->query = $query;
if ($bindings === null) {
$this->bindings = new Bindings();
} else if (is_array($bindings)) {
$this->bindings = new Bindings();
$this->bindings->setFromArray($bindings);
} else if ($bindings instanceof Bindings) {
$this->bindings = $bindings;
} else {
throw new \InvalidArgumentException('Invalid second argument provided, expected null, array or instance of Bindings');
}
return $this;
} | [
"public",
"function",
"setQuery",
"(",
"string",
"$",
"query",
",",
"$",
"bindings",
"=",
"null",
")",
":",
"Query",
"{",
"$",
"this",
"->",
"query",
"=",
"$",
"query",
";",
"if",
"(",
"$",
"bindings",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"bindings",
"=",
"new",
"Bindings",
"(",
")",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"bindings",
")",
")",
"{",
"$",
"this",
"->",
"bindings",
"=",
"new",
"Bindings",
"(",
")",
";",
"$",
"this",
"->",
"bindings",
"->",
"setFromArray",
"(",
"$",
"bindings",
")",
";",
"}",
"else",
"if",
"(",
"$",
"bindings",
"instanceof",
"Bindings",
")",
"{",
"$",
"this",
"->",
"bindings",
"=",
"$",
"bindings",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Invalid second argument provided, expected null, array or instance of Bindings'",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Set query that will be executed
@param string $query
@param Bindings|array|null $bindings
@return Query | [
"Set",
"query",
"that",
"will",
"be",
"executed"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Query.php#L83-L102 | train |
koldy/framework | src/Koldy/Db/Query.php | Query.getSQL | public function getSQL(): string
{
if ($this->query === null) {
throw new Exception('Query wasn\'t set');
}
if (is_object($this->query)) {
if (method_exists($this->query, '__toString')) {
return $this->query->__toString();
}
} else {
return trim($this->query);
}
$className = get_class($this->query);
throw new Exception("Can not use class={$className} as database query because it can't be used as string");
} | php | public function getSQL(): string
{
if ($this->query === null) {
throw new Exception('Query wasn\'t set');
}
if (is_object($this->query)) {
if (method_exists($this->query, '__toString')) {
return $this->query->__toString();
}
} else {
return trim($this->query);
}
$className = get_class($this->query);
throw new Exception("Can not use class={$className} as database query because it can't be used as string");
} | [
"public",
"function",
"getSQL",
"(",
")",
":",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"query",
"===",
"null",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Query wasn\\'t set'",
")",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"this",
"->",
"query",
")",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"this",
"->",
"query",
",",
"'__toString'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"query",
"->",
"__toString",
"(",
")",
";",
"}",
"}",
"else",
"{",
"return",
"trim",
"(",
"$",
"this",
"->",
"query",
")",
";",
"}",
"$",
"className",
"=",
"get_class",
"(",
"$",
"this",
"->",
"query",
")",
";",
"throw",
"new",
"Exception",
"(",
"\"Can not use class={$className} as database query because it can't be used as string\"",
")",
";",
"}"
]
| Get the SQL query, without bindings
@return string
@throws Exception | [
"Get",
"the",
"SQL",
"query",
"without",
"bindings"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Query.php#L110-L126 | train |
koldy/framework | src/Koldy/Db/Query.php | Query.fetchAllObj | public function fetchAllObj(string $class = null): array
{
if (!$this->wasExecuted()) {
$this->exec();
}
if ($class === null) {
return $this->getAdapter()->getStatement()->fetchAll(\PDO::FETCH_OBJ);
} else {
$objectInstances = [];
foreach ($this->fetchAll() as $r) {
$objectInstances[] = new $class($r);
}
return $objectInstances;
}
} | php | public function fetchAllObj(string $class = null): array
{
if (!$this->wasExecuted()) {
$this->exec();
}
if ($class === null) {
return $this->getAdapter()->getStatement()->fetchAll(\PDO::FETCH_OBJ);
} else {
$objectInstances = [];
foreach ($this->fetchAll() as $r) {
$objectInstances[] = new $class($r);
}
return $objectInstances;
}
} | [
"public",
"function",
"fetchAllObj",
"(",
"string",
"$",
"class",
"=",
"null",
")",
":",
"array",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"wasExecuted",
"(",
")",
")",
"{",
"$",
"this",
"->",
"exec",
"(",
")",
";",
"}",
"if",
"(",
"$",
"class",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"getStatement",
"(",
")",
"->",
"fetchAll",
"(",
"\\",
"PDO",
"::",
"FETCH_OBJ",
")",
";",
"}",
"else",
"{",
"$",
"objectInstances",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"fetchAll",
"(",
")",
"as",
"$",
"r",
")",
"{",
"$",
"objectInstances",
"[",
"]",
"=",
"new",
"$",
"class",
"(",
"$",
"r",
")",
";",
"}",
"return",
"$",
"objectInstances",
";",
"}",
"}"
]
| Fetch all results from this query and get array of stdClass instances or your custom class instances
@param string $class
@return array
@throws QueryException
@throws \Koldy\Exception | [
"Fetch",
"all",
"results",
"from",
"this",
"query",
"and",
"get",
"array",
"of",
"stdClass",
"instances",
"or",
"your",
"custom",
"class",
"instances"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Query.php#L285-L302 | train |
koldy/framework | src/Koldy/Db/Query.php | Query.getKeyIndex | public static function getKeyIndex(): int
{
if (self::$keyIndex == PHP_INT_MAX) {
self::$keyIndex = 0;
} else {
self::$keyIndex++;
}
return self::$keyIndex;
} | php | public static function getKeyIndex(): int
{
if (self::$keyIndex == PHP_INT_MAX) {
self::$keyIndex = 0;
} else {
self::$keyIndex++;
}
return self::$keyIndex;
} | [
"public",
"static",
"function",
"getKeyIndex",
"(",
")",
":",
"int",
"{",
"if",
"(",
"self",
"::",
"$",
"keyIndex",
"==",
"PHP_INT_MAX",
")",
"{",
"self",
"::",
"$",
"keyIndex",
"=",
"0",
";",
"}",
"else",
"{",
"self",
"::",
"$",
"keyIndex",
"++",
";",
"}",
"return",
"self",
"::",
"$",
"keyIndex",
";",
"}"
]
| Get next key index
@return int
@deprecated | [
"Get",
"next",
"key",
"index"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Query.php#L339-L348 | train |
koldy/framework | src/Koldy/Db/Query.php | Query.debug | public function debug(bool $oneLine = false): string
{
$query = $this->getSQL();
foreach ($this->getBindings()->getBindings() as $parameter => $bind) {
if ($parameter[0] == ':') {
$parameter = substr($parameter, 1);
}
$value = $bind->getValue();
$type = gettype($value);
switch ($type) {
case 'string':
$query = str_replace(":{$parameter}", ("'" . addslashes((string) $value) . "'"), $query);
break;
case 'integer':
case 'float':
case 'double':
$query = str_replace(":{$parameter}", $value, $query);
break;
case 'NULL':
$query = str_replace(":{$parameter}", 'NULL', $query);
break;
case 'boolean':
$true = (bool)$value;
$query = str_replace(":{$parameter}", $true ? 'true' : 'false', $query);
break;
case 'object':
case 'array':
case 'resource':
case 'unknown type':
throw new QueryException("Unsupported type ({$type}) was passed as parameter ({$parameter}) to SQL statement");
break;
default:
throw new \Koldy\Exception('Unknown data type (' . $type . ') was passed to SQL statement');
break;
}
}
if ($oneLine) {
$query = str_replace("\t", '', $query);
$query = str_replace("\n", ' ', $query);
$query = str_replace(' ', ' ', $query);
}
return $query;
} | php | public function debug(bool $oneLine = false): string
{
$query = $this->getSQL();
foreach ($this->getBindings()->getBindings() as $parameter => $bind) {
if ($parameter[0] == ':') {
$parameter = substr($parameter, 1);
}
$value = $bind->getValue();
$type = gettype($value);
switch ($type) {
case 'string':
$query = str_replace(":{$parameter}", ("'" . addslashes((string) $value) . "'"), $query);
break;
case 'integer':
case 'float':
case 'double':
$query = str_replace(":{$parameter}", $value, $query);
break;
case 'NULL':
$query = str_replace(":{$parameter}", 'NULL', $query);
break;
case 'boolean':
$true = (bool)$value;
$query = str_replace(":{$parameter}", $true ? 'true' : 'false', $query);
break;
case 'object':
case 'array':
case 'resource':
case 'unknown type':
throw new QueryException("Unsupported type ({$type}) was passed as parameter ({$parameter}) to SQL statement");
break;
default:
throw new \Koldy\Exception('Unknown data type (' . $type . ') was passed to SQL statement');
break;
}
}
if ($oneLine) {
$query = str_replace("\t", '', $query);
$query = str_replace("\n", ' ', $query);
$query = str_replace(' ', ' ', $query);
}
return $query;
} | [
"public",
"function",
"debug",
"(",
"bool",
"$",
"oneLine",
"=",
"false",
")",
":",
"string",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"getSQL",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getBindings",
"(",
")",
"->",
"getBindings",
"(",
")",
"as",
"$",
"parameter",
"=>",
"$",
"bind",
")",
"{",
"if",
"(",
"$",
"parameter",
"[",
"0",
"]",
"==",
"':'",
")",
"{",
"$",
"parameter",
"=",
"substr",
"(",
"$",
"parameter",
",",
"1",
")",
";",
"}",
"$",
"value",
"=",
"$",
"bind",
"->",
"getValue",
"(",
")",
";",
"$",
"type",
"=",
"gettype",
"(",
"$",
"value",
")",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'string'",
":",
"$",
"query",
"=",
"str_replace",
"(",
"\":{$parameter}\"",
",",
"(",
"\"'\"",
".",
"addslashes",
"(",
"(",
"string",
")",
"$",
"value",
")",
".",
"\"'\"",
")",
",",
"$",
"query",
")",
";",
"break",
";",
"case",
"'integer'",
":",
"case",
"'float'",
":",
"case",
"'double'",
":",
"$",
"query",
"=",
"str_replace",
"(",
"\":{$parameter}\"",
",",
"$",
"value",
",",
"$",
"query",
")",
";",
"break",
";",
"case",
"'NULL'",
":",
"$",
"query",
"=",
"str_replace",
"(",
"\":{$parameter}\"",
",",
"'NULL'",
",",
"$",
"query",
")",
";",
"break",
";",
"case",
"'boolean'",
":",
"$",
"true",
"=",
"(",
"bool",
")",
"$",
"value",
";",
"$",
"query",
"=",
"str_replace",
"(",
"\":{$parameter}\"",
",",
"$",
"true",
"?",
"'true'",
":",
"'false'",
",",
"$",
"query",
")",
";",
"break",
";",
"case",
"'object'",
":",
"case",
"'array'",
":",
"case",
"'resource'",
":",
"case",
"'unknown type'",
":",
"throw",
"new",
"QueryException",
"(",
"\"Unsupported type ({$type}) was passed as parameter ({$parameter}) to SQL statement\"",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"Koldy",
"\\",
"Exception",
"(",
"'Unknown data type ('",
".",
"$",
"type",
".",
"') was passed to SQL statement'",
")",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"oneLine",
")",
"{",
"$",
"query",
"=",
"str_replace",
"(",
"\"\\t\"",
",",
"''",
",",
"$",
"query",
")",
";",
"$",
"query",
"=",
"str_replace",
"(",
"\"\\n\"",
",",
"' '",
",",
"$",
"query",
")",
";",
"$",
"query",
"=",
"str_replace",
"(",
"' '",
",",
"' '",
",",
"$",
"query",
")",
";",
"}",
"return",
"$",
"query",
";",
"}"
]
| Return some debug information about the query you built
@param bool $oneLine return query in one line
@return string
@throws QueryException
@throws \Koldy\Exception | [
"Return",
"some",
"debug",
"information",
"about",
"the",
"query",
"you",
"built"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Query.php#L377-L429 | train |
koldy/framework | src/Koldy/Db/Query/Insert.php | Insert.addRows | public function addRows(array $rows): Insert
{
foreach ($rows as $index => $row) {
$this->add($row);
}
return $this;
} | php | public function addRows(array $rows): Insert
{
foreach ($rows as $index => $row) {
$this->add($row);
}
return $this;
} | [
"public",
"function",
"addRows",
"(",
"array",
"$",
"rows",
")",
":",
"Insert",
"{",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"index",
"=>",
"$",
"row",
")",
"{",
"$",
"this",
"->",
"add",
"(",
"$",
"row",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Add multiple rows into insert
@param array $rows
@return Insert | [
"Add",
"multiple",
"rows",
"into",
"insert"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Query/Insert.php#L183-L189 | train |
koldy/framework | src/Koldy/Db/Query/Insert.php | Insert.getQuery | public function getQuery(): Query
{
$bindings = new Bindings();
if (count($this->data) == 0 && $this->select === null) {
throw new Exception('Can not execute Insert query, no records to insert');
}
if ($this->table === null) {
throw new Exception('Can not execute Insert query when table name is not set');
}
$hasFields = count($this->fields) > 0;
$query = "INSERT INTO {$this->table}";
if ($hasFields) {
$query .= ' (';
foreach ($this->fields as $field) {
$query .= $field . ',';
}
$query = substr($query, 0, -1) . ')';
}
if ($this->select !== null) {
if ($this->select instanceof Select || $this->select instanceof Query) {
$query .= "\n(\n\t" . str_replace("\n", "\n\t", $this->select->__toString()) . "\n)";
$bindings->addBindingsFromInstance($this->select->getBindings());
} else {
throw new Exception('Can not use non-Select or non-Query instance in INSERT INTO SELECT statement - use Query instance to pass Select query');
}
} else {
$query .= "\nVALUES\n";
foreach ($this->data as $i1 => $row) {
$query .= "\t(";
if ($hasFields) {
foreach ($this->fields as $field) {
if (isset($row[$field])) {
$val = $row[$field];
if ($val instanceof Expr) {
$query .= "{$val},";
} else {
//$key = 'i' . $i1 . Query::getKeyIndex();
$key = $bindings->makeAndSet("i{$i1}", $val);
$query .= ":{$key},";
}
} else {
$query .= 'NULL,';
}
}
$query = substr($query, 0, -1);
} else {
$values = array_values($row);
foreach ($values as $i2 => $val) {
if ($val instanceof Expr) {
$query .= "{$val},";
} else {
//$key = 'i' . $i2 . Query::getKeyIndex();
$key = $bindings->makeAndSet("i{$i2}", $val);
$query .= ":{$key},";
}
}
$query = substr($query, 0, -1);
}
$query .= "),\n";
}
$query = substr($query, 0, -2);
}
return new Query($query, $bindings, $this->getAdapterConnection());
} | php | public function getQuery(): Query
{
$bindings = new Bindings();
if (count($this->data) == 0 && $this->select === null) {
throw new Exception('Can not execute Insert query, no records to insert');
}
if ($this->table === null) {
throw new Exception('Can not execute Insert query when table name is not set');
}
$hasFields = count($this->fields) > 0;
$query = "INSERT INTO {$this->table}";
if ($hasFields) {
$query .= ' (';
foreach ($this->fields as $field) {
$query .= $field . ',';
}
$query = substr($query, 0, -1) . ')';
}
if ($this->select !== null) {
if ($this->select instanceof Select || $this->select instanceof Query) {
$query .= "\n(\n\t" . str_replace("\n", "\n\t", $this->select->__toString()) . "\n)";
$bindings->addBindingsFromInstance($this->select->getBindings());
} else {
throw new Exception('Can not use non-Select or non-Query instance in INSERT INTO SELECT statement - use Query instance to pass Select query');
}
} else {
$query .= "\nVALUES\n";
foreach ($this->data as $i1 => $row) {
$query .= "\t(";
if ($hasFields) {
foreach ($this->fields as $field) {
if (isset($row[$field])) {
$val = $row[$field];
if ($val instanceof Expr) {
$query .= "{$val},";
} else {
//$key = 'i' . $i1 . Query::getKeyIndex();
$key = $bindings->makeAndSet("i{$i1}", $val);
$query .= ":{$key},";
}
} else {
$query .= 'NULL,';
}
}
$query = substr($query, 0, -1);
} else {
$values = array_values($row);
foreach ($values as $i2 => $val) {
if ($val instanceof Expr) {
$query .= "{$val},";
} else {
//$key = 'i' . $i2 . Query::getKeyIndex();
$key = $bindings->makeAndSet("i{$i2}", $val);
$query .= ":{$key},";
}
}
$query = substr($query, 0, -1);
}
$query .= "),\n";
}
$query = substr($query, 0, -2);
}
return new Query($query, $bindings, $this->getAdapterConnection());
} | [
"public",
"function",
"getQuery",
"(",
")",
":",
"Query",
"{",
"$",
"bindings",
"=",
"new",
"Bindings",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"data",
")",
"==",
"0",
"&&",
"$",
"this",
"->",
"select",
"===",
"null",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Can not execute Insert query, no records to insert'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"table",
"===",
"null",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Can not execute Insert query when table name is not set'",
")",
";",
"}",
"$",
"hasFields",
"=",
"count",
"(",
"$",
"this",
"->",
"fields",
")",
">",
"0",
";",
"$",
"query",
"=",
"\"INSERT INTO {$this->table}\"",
";",
"if",
"(",
"$",
"hasFields",
")",
"{",
"$",
"query",
".=",
"' ('",
";",
"foreach",
"(",
"$",
"this",
"->",
"fields",
"as",
"$",
"field",
")",
"{",
"$",
"query",
".=",
"$",
"field",
".",
"','",
";",
"}",
"$",
"query",
"=",
"substr",
"(",
"$",
"query",
",",
"0",
",",
"-",
"1",
")",
".",
"')'",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"select",
"!==",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"select",
"instanceof",
"Select",
"||",
"$",
"this",
"->",
"select",
"instanceof",
"Query",
")",
"{",
"$",
"query",
".=",
"\"\\n(\\n\\t\"",
".",
"str_replace",
"(",
"\"\\n\"",
",",
"\"\\n\\t\"",
",",
"$",
"this",
"->",
"select",
"->",
"__toString",
"(",
")",
")",
".",
"\"\\n)\"",
";",
"$",
"bindings",
"->",
"addBindingsFromInstance",
"(",
"$",
"this",
"->",
"select",
"->",
"getBindings",
"(",
")",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"'Can not use non-Select or non-Query instance in INSERT INTO SELECT statement - use Query instance to pass Select query'",
")",
";",
"}",
"}",
"else",
"{",
"$",
"query",
".=",
"\"\\nVALUES\\n\"",
";",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"i1",
"=>",
"$",
"row",
")",
"{",
"$",
"query",
".=",
"\"\\t(\"",
";",
"if",
"(",
"$",
"hasFields",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"fields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"$",
"field",
"]",
")",
")",
"{",
"$",
"val",
"=",
"$",
"row",
"[",
"$",
"field",
"]",
";",
"if",
"(",
"$",
"val",
"instanceof",
"Expr",
")",
"{",
"$",
"query",
".=",
"\"{$val},\"",
";",
"}",
"else",
"{",
"//$key = 'i' . $i1 . Query::getKeyIndex();",
"$",
"key",
"=",
"$",
"bindings",
"->",
"makeAndSet",
"(",
"\"i{$i1}\"",
",",
"$",
"val",
")",
";",
"$",
"query",
".=",
"\":{$key},\"",
";",
"}",
"}",
"else",
"{",
"$",
"query",
".=",
"'NULL,'",
";",
"}",
"}",
"$",
"query",
"=",
"substr",
"(",
"$",
"query",
",",
"0",
",",
"-",
"1",
")",
";",
"}",
"else",
"{",
"$",
"values",
"=",
"array_values",
"(",
"$",
"row",
")",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"i2",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"val",
"instanceof",
"Expr",
")",
"{",
"$",
"query",
".=",
"\"{$val},\"",
";",
"}",
"else",
"{",
"//$key = 'i' . $i2 . Query::getKeyIndex();",
"$",
"key",
"=",
"$",
"bindings",
"->",
"makeAndSet",
"(",
"\"i{$i2}\"",
",",
"$",
"val",
")",
";",
"$",
"query",
".=",
"\":{$key},\"",
";",
"}",
"}",
"$",
"query",
"=",
"substr",
"(",
"$",
"query",
",",
"0",
",",
"-",
"1",
")",
";",
"}",
"$",
"query",
".=",
"\"),\\n\"",
";",
"}",
"$",
"query",
"=",
"substr",
"(",
"$",
"query",
",",
"0",
",",
"-",
"2",
")",
";",
"}",
"return",
"new",
"Query",
"(",
"$",
"query",
",",
"$",
"bindings",
",",
"$",
"this",
"->",
"getAdapterConnection",
"(",
")",
")",
";",
"}"
]
| Get the Query string
@return Query
@throws Exception
@throws \Koldy\Db\Query\Exception
@throws \Koldy\Exception | [
"Get",
"the",
"Query",
"string"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Query/Insert.php#L212-L293 | train |
koldy/framework | src/Koldy/Cli.php | Cli.parseArgvIntoParameters | protected static function parseArgvIntoParameters(): void
{
if (static::$parameters === null) {
static::$parameters = [];
$argv = static::getArgv();
array_shift($argv); // remove the script name, it's not needed
$sizeof = count($argv);
for ($i = 0; $i < $sizeof; $i++) {
$p = $argv[$i];
if (substr($p, 0, 2) == '--') {
$tmp = explode('=', $p);
static::$parameters[substr($tmp[0], 2)] = $tmp[1] ?? null;
} else if (substr($p, 0, 1) == '-' && isset($argv[$i + 1]) && substr($argv[$i + 1], 0, 1) != '-') {
static::$parameters[substr($p, 1)] = $argv[$i + 1] ?? null;
} else if (substr($p, 0, 1) == '-' && preg_match('/^[a-zA-Z]$/', substr($p, 1, 1))) {
static::$parameters[substr($p, 1, 1)] = null;
}
}
}
} | php | protected static function parseArgvIntoParameters(): void
{
if (static::$parameters === null) {
static::$parameters = [];
$argv = static::getArgv();
array_shift($argv); // remove the script name, it's not needed
$sizeof = count($argv);
for ($i = 0; $i < $sizeof; $i++) {
$p = $argv[$i];
if (substr($p, 0, 2) == '--') {
$tmp = explode('=', $p);
static::$parameters[substr($tmp[0], 2)] = $tmp[1] ?? null;
} else if (substr($p, 0, 1) == '-' && isset($argv[$i + 1]) && substr($argv[$i + 1], 0, 1) != '-') {
static::$parameters[substr($p, 1)] = $argv[$i + 1] ?? null;
} else if (substr($p, 0, 1) == '-' && preg_match('/^[a-zA-Z]$/', substr($p, 1, 1))) {
static::$parameters[substr($p, 1, 1)] = null;
}
}
}
} | [
"protected",
"static",
"function",
"parseArgvIntoParameters",
"(",
")",
":",
"void",
"{",
"if",
"(",
"static",
"::",
"$",
"parameters",
"===",
"null",
")",
"{",
"static",
"::",
"$",
"parameters",
"=",
"[",
"]",
";",
"$",
"argv",
"=",
"static",
"::",
"getArgv",
"(",
")",
";",
"array_shift",
"(",
"$",
"argv",
")",
";",
"// remove the script name, it's not needed",
"$",
"sizeof",
"=",
"count",
"(",
"$",
"argv",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"sizeof",
";",
"$",
"i",
"++",
")",
"{",
"$",
"p",
"=",
"$",
"argv",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"substr",
"(",
"$",
"p",
",",
"0",
",",
"2",
")",
"==",
"'--'",
")",
"{",
"$",
"tmp",
"=",
"explode",
"(",
"'='",
",",
"$",
"p",
")",
";",
"static",
"::",
"$",
"parameters",
"[",
"substr",
"(",
"$",
"tmp",
"[",
"0",
"]",
",",
"2",
")",
"]",
"=",
"$",
"tmp",
"[",
"1",
"]",
"??",
"null",
";",
"}",
"else",
"if",
"(",
"substr",
"(",
"$",
"p",
",",
"0",
",",
"1",
")",
"==",
"'-'",
"&&",
"isset",
"(",
"$",
"argv",
"[",
"$",
"i",
"+",
"1",
"]",
")",
"&&",
"substr",
"(",
"$",
"argv",
"[",
"$",
"i",
"+",
"1",
"]",
",",
"0",
",",
"1",
")",
"!=",
"'-'",
")",
"{",
"static",
"::",
"$",
"parameters",
"[",
"substr",
"(",
"$",
"p",
",",
"1",
")",
"]",
"=",
"$",
"argv",
"[",
"$",
"i",
"+",
"1",
"]",
"??",
"null",
";",
"}",
"else",
"if",
"(",
"substr",
"(",
"$",
"p",
",",
"0",
",",
"1",
")",
"==",
"'-'",
"&&",
"preg_match",
"(",
"'/^[a-zA-Z]$/'",
",",
"substr",
"(",
"$",
"p",
",",
"1",
",",
"1",
")",
")",
")",
"{",
"static",
"::",
"$",
"parameters",
"[",
"substr",
"(",
"$",
"p",
",",
"1",
",",
"1",
")",
"]",
"=",
"null",
";",
"}",
"}",
"}",
"}"
]
| Parse the script arguments into parameters ready for later use
@throws CliException | [
"Parse",
"the",
"script",
"arguments",
"into",
"parameters",
"ready",
"for",
"later",
"use"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Cli.php#L59-L84 | train |
koldy/framework | src/Koldy/Db/ModelTraits/UpdatedAt.php | UpdatedAt.setUpdatedAtDateTime | public function setUpdatedAtDateTime(?DateTime $updatedAt): void
{
$this->updated_at = $updatedAt === null ? null : $updatedAt->format('Y-m-d H:i:s');
} | php | public function setUpdatedAtDateTime(?DateTime $updatedAt): void
{
$this->updated_at = $updatedAt === null ? null : $updatedAt->format('Y-m-d H:i:s');
} | [
"public",
"function",
"setUpdatedAtDateTime",
"(",
"?",
"DateTime",
"$",
"updatedAt",
")",
":",
"void",
"{",
"$",
"this",
"->",
"updated_at",
"=",
"$",
"updatedAt",
"===",
"null",
"?",
"null",
":",
"$",
"updatedAt",
"->",
"format",
"(",
"'Y-m-d H:i:s'",
")",
";",
"}"
]
| Set the updated at date time by passing instance of updatedAt
@param DateTime $updatedAt | [
"Set",
"the",
"updated",
"at",
"date",
"time",
"by",
"passing",
"instance",
"of",
"updatedAt"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/ModelTraits/UpdatedAt.php#L93-L96 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.