setDispatcher example


    public function factory(
        Container $container,
        Enlight_Event_EventManager $eventManager,
        array $options,
        RequestStack $requestStack
    ) {
        /** @var Enlight_Controller_Front $front */
        $front = Enlight_Class::Instance('Enlight_Controller_Front', [$eventManager]);

        $front->setDispatcher($container->get('dispatcher'));

        $front->setRouter($container->get(RouterInterface::class));

        $front->setParams($options);

        $front->setRequestStack($requestStack);

        /** @var Enlight_Plugin_PluginManager $plugins */
        $plugins = $container->get('plugins');

        $plugins->registerNamespace($front->Plugins());

        


        $this->eventManager->notify(
            'Enlight_Controller_Front_StartDispatch',
            $eventArgs
        );

        if (!$this->router) {
            $this->setRouter(Router::class);
        }
        if (!$this->dispatcher) {
            $this->setDispatcher('Enlight_Controller_Dispatcher_Default');
        }

        if (!$this->request) {
            $this->setRequest('Enlight_Controller_Request_RequestHttp');
        }
        if (!$this->response) {
            $this->setResponse('Enlight_Controller_Response_ResponseHttp');
        }

        if ($this->request instanceof SymfonyRequest) {
            $this->requestStack->push($this->request);
        }
public function testRunDispatchesIntegerExitCode()
    {
        $passedRightValue = false;

        // We can assume here that some other test asserts that the event is dispatched at all         $dispatcher = new EventDispatcher();
        $dispatcher->addListener('console.terminate', function DConsoleTerminateEvent $event) use (&$passedRightValue) {
            $passedRightValue = (4 === $event->getExitCode());
        });

        $application = new Application();
        $application->setDispatcher($dispatcher);
        $application->setAutoExit(false);

        $application->register('test')->setCode(function DInputInterface $input, OutputInterface $output) {
            throw new \Exception('', 4);
        });

        $tester = new ApplicationTester($application);
        $tester->run(['command' => 'test']);

        $this->assertTrue($passedRightValue, '-> exit code 4 was passed in the console.terminate event');
    }

    


    public function handleSignal(int $signal, int|false $previousExitCode = 0): int|false
    {
        echo "Received signal!";

        return 0;
    }
}

$app = new Application();
$app->setDispatcher(new \Symfony\Component\EventDispatcher\EventDispatcher());
$app->add(new MyCommand('foo'));

$app
    ->setDefaultCommand('foo', true)
    ->run()
;
--EXPECT--
Received signal!

    public function doRun(InputInterface $input, OutputInterface $output): int
    {
        $this->registerCommands();

        if ($this->registrationErrors) {
            $this->renderRegistrationErrors($input$output);
        }

        $this->setDispatcher($this->kernel->getContainer()->get('event_dispatcher'));

        return parent::doRun($input$output);
    }

    protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output): int
    {
        if (!$command instanceof ListCommand) {
            if ($this->registrationErrors) {
                $this->renderRegistrationErrors($input$output);
                $this->registrationErrors = [];
            }

            

            $fs->mkdir($realCacheDir);
        }

        $io->comment(sprintf('Clearing the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment()var_export($kernel->isDebug(), true)));
        if ($useBuildDir) {
            $this->cacheClearer->clear($realBuildDir);
        }
        $this->cacheClearer->clear($realCacheDir);

        // The current event dispatcher is stale, let's not use it anymore         $this->getApplication()->setDispatcher(new EventDispatcher());

        $containerFile = (new \ReflectionObject($kernel->getContainer()))->getFileName();
        $containerDir = basename(\dirname($containerFile));

        // the warmup cache dir name must have the same length as the real one         // to avoid the many problems in serialized resources files         $warmupDir = substr($realBuildDir, 0, -1).(str_ends_with($realBuildDir, '_') ? '-' : '_');

        if ($output->isVerbose() && $fs->exists($warmupDir)) {
            $io->comment('Clearing outdated warmup directory...');
        }
        
Home | Imprint | This part of the site doesn't use cookies.