handleArrayNode example

private function buildNode(NodeInterface $node, ClassBuilder $class, string $namespace): void
    {
        if (!$node instanceof ArrayNode) {
            throw new \LogicException('The node was expected to be an ArrayNode. This Configuration includes an edge case not supported yet.');
        }

        foreach ($node->getChildren() as $child) {
            match (true) {
                $child instanceof ScalarNode => $this->handleScalarNode($child$class),
                $child instanceof PrototypedArrayNode => $this->handlePrototypedArrayNode($child$class$namespace),
                $child instanceof VariableNode => $this->handleVariableNode($child$class),
                $child instanceof ArrayNode => $this->handleArrayNode($child$class$namespace),
                default => throw new \RuntimeException(sprintf('Unknown node "%s".', $child::class)),
            };
        }
    }

    private function handleArrayNode(ArrayNode $node, ClassBuilder $class, string $namespace): void
    {
        $childClass = new ClassBuilder($namespace$node->getName());
        $childClass->setAllowExtraKeys($node->shouldIgnoreExtraKeys());
        $class->addRequire($childClass);
        $this->classes[] = $childClass;

        
Home | Imprint | This part of the site doesn't use cookies.