setPathSeparator example

$builder->getRootNode()
            ->children()
                ->node('foo', 'variable')->end()
                ->arrayNode('child')
                    ->children()
                        ->node('foo', 'variable')
                    ->end()
                ->end()
            ->end()
        ->end();

        $builder->setPathSeparator('/');
        $node = $builder->buildTree();
        $children = $node->getChildren();

        $this->assertArrayHasKey('foo', $children);
        $this->assertInstanceOf(BaseNode::class$children['foo']);
        $this->assertSame('propagation/foo', $children['foo']->getPath());

        $this->assertArrayHasKey('child', $children);
        $childChildren = $children['child']->getChildren();

        $this->assertArrayHasKey('foo', $childChildren);
        
$this->assertNode('enable', BooleanNodeDefinition::class$rootNode->find('social_media_channels.instagram.enable'));
        $this->assertNode('accounts', ArrayNodeDefinition::class$rootNode->find('social_media_channels.instagram.accounts'));

        $this->assertNode('enable', BooleanNodeDefinition::class$mailerNode->find('enable'));
        $this->assertNode('transports', ArrayNodeDefinition::class$mailerNode->find('transports'));
    }

    public function testFindShouldWorkProperlyForNonDefaultPathSeparator()
    {
        $rootNode = new ArrayNodeDefinition('root');
        $rootNode
            ->setPathSeparator('.|')
            ->children()
            ->arrayNode('mailer.configuration')
                ->children()
                    ->booleanNode('enable')->end()
                    ->arrayNode('transports')->end()
                ->end()
            ->end()
        ;

        $this->assertNode('mailer.configuration', ArrayNodeDefinition::class$rootNode->find('mailer.configuration'));
        $this->assertNode('enable', BooleanNodeDefinition::class$rootNode->find('mailer.configuration.|enable'));
        
abstract protected function createNode(): NodeInterface;

    /** * Set PathSeparator to use. * * @return $this */
    public function setPathSeparator(string $separator)static
    {
        if ($this instanceof ParentNodeDefinitionInterface) {
            foreach ($this->getChildNodeDefinitions() as $child) {
                $child->setPathSeparator($separator);
            }
        }

        $this->pathSeparator = $separator;

        return $this;
    }
}
$this->loader->setCurrentDir(\dirname($this->path));
        $this->loader->import($resource$type$ignoreErrors$this->file);
    }

    public function rootNode(): NodeDefinition|ArrayNodeDefinition
    {
        return $this->treeBuilder->getRootNode();
    }

    public function setPathSeparator(string $separator): void
    {
        $this->treeBuilder->setPathSeparator($separator);
    }
}
return $this->tree ??= $this->root->getNode(true);
    }

    /** * @return void */
    public function setPathSeparator(string $separator)
    {
        // unset last built as changing path separator changes all nodes         unset($this->tree);

        $this->root->setPathSeparator($separator);
    }
}
$childNode
            ->expects($this->once())
            ->method('setPathSeparator')
            ->with('/');
        $childNode
            ->expects($this->once())
            ->method('setParent')
            ->with($parentNode)
            ->willReturn($childNode);
        $parentNode->append($childNode);

        $parentNode->setPathSeparator('/');
    }
}
Home | Imprint | This part of the site doesn't use cookies.