LightnCandy\Runtime::v PHP Метод

v() публичный статический Метод

Resursive lookup variable and helpers. This is slow and will only be used for instance property or method detection or lambdas.
public static v ( array\arraystring | integer> $cx, array | string | boolean | integer | double | null $in, arraystring | integer> $base, array $path, array | null $args = null ) : null | string
$cx array\arraystring | integer>
$in array | string | boolean | integer | double | null current context
$base arraystring | integer>
$path array
$args array | null extra arguments for lambda
Результат null | string Return the value or null when not found
    public static function v($cx, $in, $base, $path, $args = null)
    {
        $count = count($cx['scopes']);
        while ($base) {
            $v = $base;
            foreach ($path as $name) {
                if (is_array($v) && isset($v[$name])) {
                    $v = $v[$name];
                    continue;
                }
                if (is_object($v)) {
                    if ($cx['flags']['prop'] && !$v instanceof \Closure && isset($v->{$name})) {
                        $v = $v->{$name};
                        continue;
                    }
                    if ($cx['flags']['method'] && is_callable(array($v, $name))) {
                        $v = $v->{$name}();
                        continue;
                    }
                }
                if ($cx['flags']['mustlok']) {
                    unset($v);
                    break;
                }
                return null;
            }
            if (isset($v)) {
                if ($v instanceof \Closure) {
                    if ($cx['flags']['mustlam'] || $cx['flags']['lambda']) {
                        if (!$cx['flags']['knohlp'] && ($args || $args === 0)) {
                            $A = $args ? $args[0] : array();
                            $A[] = array('hash' => $args[1], '_this' => $in);
                        } else {
                            $A = array($in);
                        }
                        $v = call_user_func_array($v, $A);
                    }
                }
                return $v;
            }
            $count--;
            switch ($count) {
                case -1:
                    $base = $cx['sp_vars']['root'];
                    break;
                case -2:
                    return null;
                default:
                    $base = $cx['scopes'][$count];
            }
        }
        if ($args) {
            static::err($cx, 'Can not find helper or lambda: "' . implode('.', $path) . '" !');
        }
    }