RomaricDrigon\MetaYaml\MetaYaml::findNode PHP Method

findNode() private method

private findNode ( array $array, array $keys, $unfold_all )
$array array
$keys array
    private function findNode(array $array, array $keys, $unfold_all)
    {
        // first, if it's a partial, let's naviguate
        if (isset($array[$this->prefix . 'type']) && $array[$this->prefix . 'type'] === 'partial') {
            $p_name = $array[$this->prefix . 'partial'];
            if (!isset($this->schema['partials']) || !isset($this->schema['partials'][$p_name])) {
                throw new \Exception("You're using a partial but partial '{$p_name}' is not defined in your schema");
            }
            return $this->findNode($this->schema['partials'][$p_name], $keys, $unfold_all);
        }
        // we're on target, return the result
        if ($keys === array()) {
            // on more thing: dig one more level of partial
            return $this->unfoldPartials($array, $unfold_all);
        }
        // they're still some keys, dig deeper
        if (isset($array[$this->prefix . 'type'])) {
            switch ($array[$this->prefix . 'type']) {
                case 'prototype':
                    //we have to ignore one key
                    array_shift($keys);
                    return $this->findNode($array[$this->prefix . 'prototype'], $keys, $unfold_all);
                case 'array':
                    // let's check the children
                    if (isset($array[$this->prefix . 'children'][$keys[0]])) {
                        $child = $array[$this->prefix . 'children'][$keys[0]];
                        array_shift($keys);
                        return $this->findNode($child, $keys, $unfold_all);
                    }
                    break;
                case 'choice':
                    // choice, return an array of possibilities
                    $choices = array();
                    foreach ($array[$this->prefix . 'choices'] as $name => $choice) {
                        try {
                            $choices[$name] = $this->findNode($choice, $keys, $unfold_all);
                        } catch (\Exception $e) {
                        }
                        // exception = invalid choice, so skip it
                    }
                    return $choices + array($this->prefix . 'is_choice' => 'true');
            }
        }
        throw new \Exception("Unable to find child {$keys[0]}");
    }