rootNode example

<?php
use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;

return static function DDefinitionConfigurator $definition) {
    $definition->rootNode()
        ->children()
            ->scalarNode('ping')->defaultValue('pong')->end()
        ->end()
    ;
};
<?php
use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;

return static function DDefinitionConfigurator $definition) {
    $definition->rootNode()
        ->children()
            ->scalarNode('bar')->defaultValue('multi')->end()
        ->end()
    ;
};
<?php
use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;

return static function DDefinitionConfigurator $definition) {
    $definition->rootNode()
        ->children()
            ->scalarNode('baz')->defaultValue('multi')->end()
        ->end()
    ;
};
namespace Symfony\Component\HttpKernel\Tests\Fixtures\AcmeFooBundle;

use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpKernel\Bundle\AbstractBundle;

class AcmeFooBundle extends AbstractBundle
{
    public function configure(DefinitionConfigurator $definition): void
    {
        $definition->rootNode()
            ->children()
                ->scalarNode('foo')->defaultValue('bar')->end()
            ->end()
        ;

        $definition->import('Resources/config/definition.php');
    }

    public function prependExtension(ContainerConfigurator $container, ContainerBuilder $builder): void
    {
        $container->extension('loaded', ['bar' => 'baz']);
    }
<?php
use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;

return static function DDefinitionConfigurator $definition) {
    $definition->rootNode()
        ->children()
            ->scalarNode('foo')->defaultValue('one')->end()
        ->end()
    ;
};

        $extension = new class() extends AbstractExtension {
            public function configure(DefinitionConfigurator $definition): void
            {
                // load one                 $definition->import('../Fixtures/config/definition/foo.php');

                // load multiples                 $definition->import('../Fixtures/config/definition/multiple/*.php');

                // inline                 $definition->rootNode()
                    ->children()
                        ->scalarNode('ping')->defaultValue('inline')->end()
                    ->end();
            }
        };

        $expected = [
            'foo' => 'one',
            'bar' => 'multi',
            'baz' => 'multi',
            'ping' => 'inline',
        ];
Home | Imprint | This part of the site doesn't use cookies.