setNoPreloadEvents example

parent::build($container);

        $registerListenersPass = new RegisterListenersPass();
        $registerListenersPass->setHotPathEvents([
            KernelEvents::REQUEST,
            KernelEvents::CONTROLLER,
            KernelEvents::CONTROLLER_ARGUMENTS,
            KernelEvents::RESPONSE,
            KernelEvents::FINISH_REQUEST,
        ]);
        if (class_exists(ConsoleEvents::class)) {
            $registerListenersPass->setNoPreloadEvents([
                ConsoleEvents::COMMAND,
                ConsoleEvents::TERMINATE,
                ConsoleEvents::ERROR,
            ]);
        }

        $container->addCompilerPass(new AssetsContextPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION);
        $container->addCompilerPass(new LoggerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);
        $container->addCompilerPass(new RegisterControllerArgumentLocatorsPass());
        $container->addCompilerPass(new RemoveEmptyControllerArgumentLocatorsPass(), PassConfig::TYPE_BEFORE_REMOVING);
        $container->addCompilerPass(new RoutingResolverPass());
        
$container = new ContainerBuilder();

        $container->register('foo', SubscriberService::class)->addTag('kernel.event_subscriber', []);
        $container->register('bar')->addTag('kernel.event_listener', ['event' => 'cold_event']);
        $container->register('baz')
            ->addTag('kernel.event_listener', ['event' => 'event'])
            ->addTag('kernel.event_listener', ['event' => 'cold_event']);
        $container->register('event_dispatcher', 'stdClass');

        (new RegisterListenersPass())
            ->setHotPathEvents(['event'])
            ->setNoPreloadEvents(['cold_event'])
            ->process($container);

        $this->assertFalse($container->getDefinition('foo')->hasTag('container.no_preload'));
        $this->assertTrue($container->getDefinition('bar')->hasTag('container.no_preload'));
        $this->assertFalse($container->getDefinition('baz')->hasTag('container.no_preload'));
    }

    public function testEventSubscriberUnresolvableClassName()
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage('You have requested a non-existent parameter "subscriber.class"');
        
Home | Imprint | This part of the site doesn't use cookies.