2017-07-20 03:49:41 +02:00
|
|
|
<?php
|
2017-09-15 06:02:31 +02:00
|
|
|
|
2021-01-23 21:33:34 +01:00
|
|
|
if (!function_exists('is_digit')) {
|
2017-09-15 06:02:31 +02:00
|
|
|
/**
|
|
|
|
* Deal with normal (and irritating) PHP behavior to determine if
|
|
|
|
* a value is a non-float positive integer.
|
|
|
|
*/
|
2022-10-14 18:59:20 +02:00
|
|
|
function is_digit(mixed $value): bool
|
2017-09-15 06:02:31 +02:00
|
|
|
{
|
2022-10-14 18:59:20 +02:00
|
|
|
return !is_bool($value) && ctype_digit(strval($value));
|
2017-09-15 06:02:31 +02:00
|
|
|
}
|
|
|
|
}
|
2017-10-05 06:42:04 +02:00
|
|
|
|
2021-01-23 21:33:34 +01:00
|
|
|
if (!function_exists('object_get_strict')) {
|
2017-10-05 06:42:04 +02:00
|
|
|
/**
|
|
|
|
* Get an object using dot notation. An object key with a value of null is still considered valid
|
|
|
|
* and will not trigger the response of a default value (unlike object_get).
|
|
|
|
*/
|
2022-10-14 18:59:20 +02:00
|
|
|
function object_get_strict(object $object, ?string $key, $default = null): mixed
|
2017-10-05 06:42:04 +02:00
|
|
|
{
|
|
|
|
if (is_null($key) || trim($key) == '') {
|
|
|
|
return $object;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (explode('.', $key) as $segment) {
|
2021-01-23 21:33:34 +01:00
|
|
|
if (!is_object($object) || !property_exists($object, $segment)) {
|
2017-10-05 06:42:04 +02:00
|
|
|
return value($default);
|
|
|
|
}
|
|
|
|
|
|
|
|
$object = $object->{$segment};
|
|
|
|
}
|
|
|
|
|
|
|
|
return $object;
|
|
|
|
}
|
|
|
|
}
|