registerBundles example

/** * Initializes bundles. * * @return void * * @throws \LogicException if two bundles share a common name */
    protected function initializeBundles()
    {
        // init bundles         $this->bundles = [];
        foreach ($this->registerBundles() as $bundle) {
            $name = $bundle->getName();
            if (isset($this->bundles[$name])) {
                throw new \LogicException(sprintf('Trying to register two bundles with the same name "%s".', $name));
            }
            $this->bundles[$name] = $bundle;
        }
    }

    /** * The extension point similar to the Bundle::build() method. * * Use this method to register compiler passes and manipulate the container during the building process. * * @return void */
/** * Initializes bundles. * * @return void * * @throws \LogicException if two bundles share a common name */
    protected function initializeBundles()
    {
        // init bundles         $this->bundles = [];
        foreach ($this->registerBundles() as $bundle) {
            $name = $bundle->getName();
            if (isset($this->bundles[$name])) {
                throw new \LogicException(sprintf('Trying to register two bundles with the same name "%s".', $name));
            }
            $this->bundles[$name] = $bundle;
        }
    }

    /** * The extension point similar to the Bundle::build() method. * * Use this method to register compiler passes and manipulate the container during the building process. * * @return void */
public function testKernel(): void
    {
        $kernel = new Kernel('test', true);

        static::assertSame('test', $kernel->getEnvironment());
    }

    public function testBundles(): void
    {
        $kernel = new Kernel('test', true);

        $bundles = $kernel->registerBundles();

        static::assertCount(2, $bundles);
        static::assertInstanceOf(FrameworkBundle::class$bundles[0]);
        static::assertInstanceOf(TwigBundle::class$bundles[1]);
    }

    public function testProjectDir(): void
    {
        $kernel = new Kernel('test', true);

        static::assertSame(realpath(__DIR__ . '/..')$kernel->getProjectDir());
    }

                return $name === $this->simpleTheme->getName() ? $this->simpleTheme : $this->kernel->getBundle($name);
            }

            public function handle(Request $request, int $type = self::MAIN_REQUEST, bool $catch = true): Response
            {
                return $this->kernel->handle(...\func_get_args());
            }

            public function registerBundles(): iterable
            {
                return $this->kernel->registerBundles();
            }

            public function registerContainerConfiguration(LoaderInterface $loader): void
            {
                $this->kernel->registerContainerConfiguration(...\func_get_args());
            }

            public function boot(): void
            {
                $this->kernel->boot();
            }

            

#[Package('core')] class TestKernel extends Kernel
{
    /** * @return \Generator<BundleInterface> */
    public function registerBundles(): \Generator
    {
        yield from parent::registerBundles();

        yield new TestBundle();
    }
}
Home | Imprint | This part of the site doesn't use cookies.