misc_pterodactyl-panel/app/helpers.php
Matthew Penner cbcf62086f
Upgrade to Laravel 9 (#4413)
Co-authored-by: DaneEveritt <dane@daneeveritt.com>
2022-10-14 10:59:20 -06:00

35 lines
991 B
PHP

<?php
if (!function_exists('is_digit')) {
/**
* Deal with normal (and irritating) PHP behavior to determine if
* a value is a non-float positive integer.
*/
function is_digit(mixed $value): bool
{
return !is_bool($value) && ctype_digit(strval($value));
}
}
if (!function_exists('object_get_strict')) {
/**
* 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).
*/
function object_get_strict(object $object, ?string $key, $default = null): mixed
{
if (is_null($key) || trim($key) == '') {
return $object;
}
foreach (explode('.', $key) as $segment) {
if (!is_object($object) || !property_exists($object, $segment)) {
return value($default);
}
$object = $object->{$segment};
}
return $object;
}
}