2017-07-20 01:49:41 +00:00
|
|
|
<?php
|
2017-09-15 04:02:31 +00:00
|
|
|
|
2021-01-23 20:33:34 +00:00
|
|
|
if (!function_exists('is_digit')) {
|
2017-09-15 04:02:31 +00:00
|
|
|
/**
|
|
|
|
* Deal with normal (and irritating) PHP behavior to determine if
|
|
|
|
* a value is a non-float positive integer.
|
|
|
|
*
|
|
|
|
* @param mixed $value
|
2021-01-23 20:33:34 +00:00
|
|
|
*
|
2017-09-15 04:02:31 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
function is_digit($value)
|
|
|
|
{
|
|
|
|
return is_bool($value) ? false : ctype_digit(strval($value));
|
|
|
|
}
|
|
|
|
}
|
2017-10-05 04:42:04 +00:00
|
|
|
|
2021-01-23 20:33:34 +00:00
|
|
|
if (!function_exists('object_get_strict')) {
|
2017-10-05 04:42:04 +00: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).
|
|
|
|
*
|
|
|
|
* @param object $object
|
|
|
|
* @param string $key
|
2021-01-23 20:33:34 +00:00
|
|
|
* @param null $default
|
|
|
|
*
|
2017-10-05 04:42:04 +00:00
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
function object_get_strict($object, $key, $default = null)
|
|
|
|
{
|
|
|
|
if (is_null($key) || trim($key) == '') {
|
|
|
|
return $object;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (explode('.', $key) as $segment) {
|
2021-01-23 20:33:34 +00:00
|
|
|
if (!is_object($object) || !property_exists($object, $segment)) {
|
2017-10-05 04:42:04 +00:00
|
|
|
return value($default);
|
|
|
|
}
|
|
|
|
|
|
|
|
$object = $object->{$segment};
|
|
|
|
}
|
|
|
|
|
|
|
|
return $object;
|
|
|
|
}
|
|
|
|
}
|