Fenos\Notifynder\Parsers\NotifynderParser::mixedGet PHP Method

mixedGet() protected method

Get a value by dot-key of an array, object or mix of both.
protected mixedGet ( array | object $object, string $key, null $default = null ) : mixed
$object array | object
$key string
$default null
return mixed
    protected function mixedGet($object, $key, $default = null)
    {
        if (is_null($key) || trim($key) == '') {
            return '';
        }
        foreach (explode('.', $key) as $segment) {
            if (is_object($object) && isset($object->{$segment})) {
                $object = $object->{$segment};
            } elseif (is_object($object) && method_exists($object, '__get') && !is_null($object->__get($segment))) {
                $object = $object->__get($segment);
            } elseif (is_object($object) && method_exists($object, 'getAttribute') && !is_null($object->getAttribute($segment))) {
                $object = $object->getAttribute($segment);
            } elseif (is_array($object) && array_key_exists($segment, $object)) {
                $object = array_get($object, $segment, $default);
            } else {
                return value($default);
            }
        }
        return $object;
    }