Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/helpers.php
7382 views
1
<?php
2
3
if (!function_exists('is_digit')) {
4
/**
5
* Deal with normal (and irritating) PHP behavior to determine if
6
* a value is a non-float positive integer.
7
*/
8
function is_digit(mixed $value): bool
9
{
10
return !is_bool($value) && ctype_digit(strval($value));
11
}
12
}
13
14
if (!function_exists('object_get_strict')) {
15
/**
16
* Get an object using dot notation. An object key with a value of null is still considered valid
17
* and will not trigger the response of a default value (unlike object_get).
18
*/
19
function object_get_strict(object $object, ?string $key, $default = null): mixed
20
{
21
if (is_null($key) || trim($key) == '') {
22
return $object;
23
}
24
25
foreach (explode('.', $key) as $segment) {
26
if (!is_object($object) || !property_exists($object, $segment)) {
27
return value($default);
28
}
29
30
$object = $object->{$segment};
31
}
32
33
return $object;
34
}
35
}
36
37