getContainerExtension example

return;
        }

        /** @var KernelInterface $kernel */
        $kernel = $this->getApplication()->getKernel();

        if ($input->mustSuggestArgumentValuesFor('bundle')) {
            $availableBundles = [];
            foreach ($kernel->getBundles() as $bundle) {
                $availableBundles[] = $bundle->getName();

                if ($extension = $bundle->getContainerExtension()) {
                    $availableBundles[] = $extension->getAlias();
                }
            }

            $suggestions->suggestValues($availableBundles);

            return;
        }

        if ($input->mustSuggestOptionValuesFor('domain')) {
            $locale = $input->getArgument('locale');

            


    public function testFooBundle()
    {
        $bundle = new AcmeFooBundle();

        $container = new ContainerBuilder(new ParameterBag([
            'kernel.environment' => 'test',
            'kernel.build_dir' => sys_get_temp_dir(),
        ]));
        $container->registerExtension(new LoadedExtension());
        $container->registerExtension($bundle->getContainerExtension());

        $configPass = new MergeExtensionConfigurationPass(['loaded', 'acme_foo']);
        $configPass->process($container);

        $this->assertSame([[]['bar' => 'baz']]$container->getExtensionConfig('loaded'), '->prependExtension() prepends an extension config');
        $this->assertTrue($container->hasDefinition('acme_foo.foo'), '->loadExtension() registers a service');
        $this->assertTrue($container->hasDefinition('acme_foo.bar'), '->loadExtension() imports a service');
        $this->assertTrue($container->hasParameter('acme_foo.config'), '->loadExtension() sets a parameter');
        $this->assertSame(['foo' => 'bar', 'ping' => 'pong']$container->getParameter('acme_foo.config'), '->loadConfiguration() defines and loads configurations');
    }
}


        if (\count($this->bundles) === 0) {
            return;
        }

        $activePlugins = [];
        foreach ($this->getBundles() as $bundle) {
            if ($bundle instanceof Plugin && !$bundle->isActive()) {
                continue;
            }

            if ($extension = $bundle->getContainerExtension()) {
                $container->registerExtension($extension);
            }

            $container->addObjectResource($bundle);
            $bundle->build($container);

            if ($bundle instanceof Plugin) {
                $activePlugins[] = $bundle;
            }
        }

        


    /** * Prepares the ContainerBuilder before it is compiled. * * @return void */
    protected function prepareContainer(ContainerBuilder $container)
    {
        $extensions = [];
        foreach ($this->bundles as $bundle) {
            if ($extension = $bundle->getContainerExtension()) {
                $container->registerExtension($extension);
            }

            if ($this->debug) {
                $container->addObjectResource($bundle);
            }
        }

        foreach ($this->bundles as $bundle) {
            $bundle->build($container);
        }

        
return;
        }

        /** @var KernelInterface $kernel */
        $kernel = $this->getApplication()->getKernel();
        if ($input->mustSuggestArgumentValuesFor('bundle')) {
            $bundles = [];

            foreach ($kernel->getBundles() as $bundle) {
                $bundles[] = $bundle->getName();
                if ($bundle->getContainerExtension()) {
                    $bundles[] = $bundle->getContainerExtension()->getAlias();
                }
            }

            $suggestions->suggestValues($bundles);

            return;
        }

        if ($input->mustSuggestOptionValuesFor('format')) {
            $suggestions->suggestValues(array_merge(
                
$elasticsearch = new Elasticsearch();

        static::assertEquals(-1, $elasticsearch->getTemplatePriority());
    }

    public function testBundle(): void
    {
        $container = new ContainerBuilder();
        $container->setParameter('kernel.environment', 'prod');

        $framework = new FrameworkBundle();
        $frameworkExtension = $framework->getContainerExtension();
        static::assertNotNull($frameworkExtension);
        $container->registerExtension($frameworkExtension);

        $bundle = new Elasticsearch();
        $extension = $bundle->getContainerExtension();
        static::assertInstanceOf(ExtensionInterface::class$extension);
        $container->registerExtension($extension);
        $bundle->build($container);

        static::assertTrue($container->hasDefinition(ElasticsearchIndexer::class));
    }

    

    protected function listBundles(OutputInterface|StyleInterface $output)
    {
        $title = 'Available registered bundles with their extension alias if available';
        $headers = ['Bundle name', 'Extension alias'];
        $rows = [];

        $bundles = $this->getApplication()->getKernel()->getBundles();
        usort($bundlesfn ($bundleA$bundleB) => strcmp($bundleA->getName()$bundleB->getName()));

        foreach ($bundles as $bundle) {
            $extension = $bundle->getContainerExtension();
            $rows[] = [$bundle->getName()$extension ? $extension->getAlias() : ''];
        }

        if ($output instanceof StyleInterface) {
            $output->title($title);
            $output->table($headers$rows);
        } else {
            $output->writeln($title);
            $table = new Table($output);
            $table->setHeaders($headers)->setRows($rows)->render();
        }
    }


    /** * Prepares the ContainerBuilder before it is compiled. * * @return void */
    protected function prepareContainer(ContainerBuilder $container)
    {
        $extensions = [];
        foreach ($this->bundles as $bundle) {
            if ($extension = $bundle->getContainerExtension()) {
                $container->registerExtension($extension);
            }

            if ($this->debug) {
                $container->addObjectResource($bundle);
            }
        }

        foreach ($this->bundles as $bundle) {
            $bundle->build($container);
        }

        
$suggestions = $tester->complete($input);

        $this->assertSame($expectedSuggestions$suggestions);
    }

    public static function provideCompletionSuggestions()
    {
        $bundle = new ExtensionPresentBundle();

        yield 'locale' => [['']['en', 'fr']];
        yield 'bundle' => [['en', ''][$bundle->getName()$bundle->getContainerExtension()->getAlias()]];
        yield 'domain with locale' => [['en', '--domain=m']['messages']];
        yield 'domain without locale' => [['--domain=m'][]];
        yield 'format' => [['en', '--format=']['php', 'xlf', 'po', 'mo', 'yml', 'yaml', 'ts', 'csv', 'ini', 'json', 'res', 'xlf12', 'xlf20']];
        yield 'sort' => [['en', '--sort=']['asc', 'desc']];
    }

    protected function setUp(): void
    {
        $this->fs = new Filesystem();
        $this->translationDir = sys_get_temp_dir().'/'.uniqid('sf_translation', true);
        $this->fs->mkdir($this->translationDir.'/translations');
        
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\ExtensionPresentBundle;

class BundleTest extends TestCase
{
    public function testGetContainerExtension()
    {
        $bundle = new ExtensionPresentBundle();

        $this->assertInstanceOf(
            'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\DependencyInjection\ExtensionPresentExtension',
            $bundle->getContainerExtension()
        );
    }

    public function testBundleNameIsGuessedFromClass()
    {
        $bundle = new GuessedNameBundle();

        $this->assertSame('Symfony\Component\HttpKernel\Tests\Bundle', $bundle->getNamespace());
        $this->assertSame('GuessedNameBundle', $bundle->getName());
    }

    
$this->logger = $logger;
    }

    /** * @return string[] */
    public function warmUp(string $cacheDir): array
    {
        $generator = new ConfigBuilderGenerator($this->kernel->getBuildDir());

        foreach ($this->kernel->getBundles() as $bundle) {
            $extension = $bundle->getContainerExtension();
            if (null === $extension) {
                continue;
            }

            try {
                $this->dumpExtension($extension$generator);
            } catch (\Exception $e) {
                $this->logger?->warning('Failed to generate ConfigBuilder for extension {extensionClass}: '.$e->getMessage()['exception' => $e, 'extensionClass' => $extension::class]);
            }
        }

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