extension example

$arguments[] = $configBuilder;
            }
        }

        // Force load ContainerConfigurator to make env(), param() etc available.         class_exists(ContainerConfigurator::class);

        $callback(...$arguments);

        /** @var ConfigBuilderInterface $configBuilder */
        foreach ($configBuilders as $configBuilder) {
            $containerConfigurator->extension($configBuilder->getExtensionAlias()$configBuilder->toArray());
        }
    }

    /** * @param string $namespace FQCN string for a class implementing ConfigBuilderInterface */
    private function configBuilder(string $namespace): ConfigBuilderInterface
    {
        if (!class_exists(ConfigBuilderGenerator::class)) {
            throw new \LogicException('You cannot use the config builder as the Config component is not installed. Try running "composer require symfony/config".');
        }

        
public function testAnonymousMicroKernel()
    {
        $kernel = $this->kernel = new class('anonymous_kernel') extends MinimalKernel {
            public function helloAction(): Response
            {
                return new Response('Hello World!');
            }

            protected function configureContainer(ContainerConfigurator $c): void
            {
                $c->extension('framework', [
                    'annotations' => false,
                    'http_method_override' => false,
                    'handle_all_throwables' => true,
                    'php_errors' => ['log' => true],
                    'router' => ['utf8' => true],
                ]);
                $c->services()->set('logger', NullLogger::class);
            }

            protected function configureRoutes(RoutingConfigurator $routes): void
            {
                

            $this->get_base();
        }

        if ($type & SIMPLEPIE_LOCATOR_AUTODISCOVERY && $working = $this->autodiscovery())
        {
            return $working[0];
        }

        if ($type & (SIMPLEPIE_LOCATOR_LOCAL_EXTENSION | SIMPLEPIE_LOCATOR_LOCAL_BODY | SIMPLEPIE_LOCATOR_REMOTE_EXTENSION | SIMPLEPIE_LOCATOR_REMOTE_BODY) && $this->get_links())
        {
            if ($type & SIMPLEPIE_LOCATOR_LOCAL_EXTENSION && $working = $this->extension($this->local))
            {
                return $working[0];
            }

            if ($type & SIMPLEPIE_LOCATOR_LOCAL_BODY && $working = $this->body($this->local))
            {
                return $working[0];
            }

            if ($type & SIMPLEPIE_LOCATOR_REMOTE_EXTENSION && $working = $this->extension($this->elsewhere))
            {
                
$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']);
    }

    public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
    {
        $container->parameters()
            ->set('acme_foo.config', $config)
        ;

        $container->services()
            ->set('acme_foo.foo', \stdClass::class)
        ;

        


        self::assertSame($expected$this->processConfiguration($extension));
    }

    public function testPrependAppendExtensionConfig()
    {
        $extension = new class() extends AbstractExtension {
            public function prependExtension(ContainerConfigurator $container, ContainerBuilder $builder): void
            {
                // append config                 $container->extension('third', ['foo' => 'append']);

                // prepend config                 $builder->prependExtensionConfig('third', ['foo' => 'prepend']);
            }
        };

        $container = $this->processPrependExtension($extension);

        $expected = [
            ['foo' => 'prepend'],
            ['foo' => 'bar'],
            [
<?php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return static function DContainerConfigurator $container) {
    $container->extension('framework', [
        'annotations' => false,
        'http_method_override' => false,
    'handle_all_throwables' => true,
    'php_errors' => ['log' => true],
        'mailer' => [
            'transports' => [
                'transport1' => 'smtp://example1.com',
                'transport2' => 'smtp://example2.com',
            ],
            'envelope' => [
                'sender' => 'sender@example.org',
                
$arguments[] = $configBuilder;
            }
        }

        // Force load ContainerConfigurator to make env(), param() etc available.         class_exists(ContainerConfigurator::class);

        $callback(...$arguments);

        /** @var ConfigBuilderInterface $configBuilder */
        foreach ($configBuilders as $configBuilder) {
            $containerConfigurator->extension($configBuilder->getExtensionAlias()$configBuilder->toArray());
        }
    }

    /** * @param string $namespace FQCN string for a class implementing ConfigBuilderInterface */
    private function configBuilder(string $namespace): ConfigBuilderInterface
    {
        if (!class_exists(ConfigBuilderGenerator::class)) {
            throw new \LogicException('You cannot use the config builder as the Config component is not installed. Try running "composer require symfony/config".');
        }

        
<?php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return static function DContainerConfigurator $container) {
    $container->extension('framework', [
        'annotations' => false,
        'http_method_override' => false,
    'handle_all_throwables' => true,
    'php_errors' => ['log' => true],
        'mailer' => [
            'dsn' => 'smtp://example.com',
            'envelope' => [
                'sender' => 'sender@example.org',
                'recipients' => ['redirected@example.org', 'redirected1@example.org'],
            ],
            'headers' => [
                
protected function configureRoutes(RoutingConfigurator $routes): void
    {
        $routes
            ->add('server_request', '/server-request')->controller([PsrRequestController::class, 'serverRequestAction'])->methods(['GET'])
            ->add('request', '/request')->controller([PsrRequestController::class, 'requestAction'])->methods(['POST'])
            ->add('message', '/message')->controller([PsrRequestController::class, 'messageAction'])->methods(['PUT'])
        ;
    }

    protected function configureContainer(ContainerConfigurator $container): void
    {
        $container->extension('framework', [
            'router' => ['utf8' => true],
            'secret' => 'for your eyes only',
            'test' => true,
            'annotations' => false,
            'http_method_override' => false,
            'handle_all_throwables' => true,
            'php_errors' => ['log' => true],
        ]);

        $container->services()
            ->set('nyholm.psr_factory', Psr17Factory::class)
            

        $c->parameters()
            ->set('halloween', 'Have a great day!');

        $c->services()
            ->set('logger', NullLogger::class)
            ->set('stdClass', 'stdClass')
                ->autowire()
                ->factory([$this, 'createHalloween'])
                ->arg('$halloween', '%halloween%');

        $c->extension('framework', [
            'annotations' => false,
            'http_method_override' => false,
            'handle_all_throwables' => true,
            'php_errors' => ['log' => true],
            'router' => ['utf8' => true],
        ]);
    }
}
Home | Imprint | This part of the site doesn't use cookies.