getNodeClass example

$message .= sprintf(' since version %s', $test->getDeprecatedVersion());
            }
            if ($test->getAlternative()) {
                $message .= sprintf('. Use "%s" instead', $test->getAlternative());
            }
            $src = $stream->getSourceContext();
            $message .= sprintf(' in %s at line %d.', $src->getPath() ?: $src->getName()$stream->getCurrent()->getLine());

            @trigger_error($message, \E_USER_DEPRECATED);
        }

        return $test->getNodeClass();
    }

    private function getFunctionNodeClass(string $name, int $line): string
    {
        if (!$function = $this->env->getFunction($name)) {
            $e = new SyntaxError(sprintf('Unknown "%s" function.', $name)$line$this->parser->getStream()->getSourceContext());
            $e->addSuggestions($namearray_keys($this->env->getFunctions()));

            throw $e;
        }

        
return $this->parent;
    }

    /** * Creates a child node. * * @throws \RuntimeException When the node type is not registered * @throws \RuntimeException When the node class is not found */
    public function node(?string $name, string $type): NodeDefinition
    {
        $class = $this->getNodeClass($type);

        $node = new $class($name);

        $this->append($node);

        return $node;
    }

    /** * Appends a node definition. * * Usage: * * $node = new ArrayNodeDefinition('name') * ->children() * ->scalarNode('foo')->end() * ->scalarNode('baz')->end() * ->append($this->getBarNodeDefinition()) * ->end() * ; * * @return $this */

    public function barNode(?string $name): NodeDefinition
    {
        return $this->node($name, 'bar');
    }

    protected function getNodeClass(string $type): string
    {
        return match ($type) {
            'bar',
            'variable' => __NAMESPACE__ . '\\' . ucfirst($type) . 'NodeDefinition',
            default => parent::getNodeClass($type),
        };
    }
}
Home | Imprint | This part of the site doesn't use cookies.