public function dispatch(RequestInterface $request, ResponseInterface $response)
    {
        if ($request instanceof CliRequest) {
            $this->initiateDispatchLoop($request, $response);
            return;
        }

        // NOTE: The dispatcher is used for both Action- and CLI-Requests. For the latter case dispatching might happen during compile-time, that's why we can't inject the following dependencies

        /** @var Context $securityContext */
        $securityContext = $this->objectManager->get(Context::class);
        if ($securityContext->areAuthorizationChecksDisabled()) {
            $this->initiateDispatchLoop($request, $response);
            return;
        }

        /** @var FirewallInterface $firewall */
        $firewall = $this->objectManager->get(FirewallInterface::class);
        /** @var PsrLoggerFactoryInterface $securityLogger */
        $securityLogger = $this->objectManager->get(PsrLoggerFactoryInterface::class)->get('securityLogger');

        try {
            /** @var ActionRequest $request */
            $firewall->blockIllegalRequests($request);
            $this->initiateDispatchLoop($request, $response);
        } catch (AuthenticationRequiredException $exception) {
            $entryPointFound = false;
            /** @var $token TokenInterface */
            foreach ($securityContext->getAuthenticationTokens() as $token) {
                $entryPoint = $token->getAuthenticationEntryPoint();
                if ($entryPoint === null) {
                    continue;
                }
                $entryPointFound = true;
                if ($entryPoint instanceof WebRedirect) {
                    $securityLogger->info('Redirecting to authentication entry point', $entryPoint->getOptions(), LogEnvironment::fromMethodName(__METHOD__));
                } else {
                    $securityLogger->info(sprintf('Starting authentication with entry point of type "%s"', get_class($entryPoint)), LogEnvironment::fromMethodName(__METHOD__));
                }
                $securityContext->setInterceptedRequest($request->getMainRequest());
                /** @var HttpResponse $response */
                $entryPoint->startAuthentication($request->getHttpRequest(), $response);
            }
            if ($entryPointFound === false) {
                $securityLogger->notice('No authentication entry point found for active tokens, therefore cannot authenticate or redirect to authentication automatically.');
                throw $exception;
            }
        } catch (AccessDeniedException $exception) {
            $securityLogger->warning('Access denied', LogEnvironment::fromMethodName(__METHOD__));
            throw $exception;
        }
    }
public function dispatch(RequestInterface $request, ResponseInterface $response)
    {
        if ($request instanceof CliRequest) {
            $this->initiateDispatchLoop($request, $response);
            return;
        }

        // NOTE: The dispatcher is used for both Action- and CLI-Requests. For the latter case dispatching might happen during compile-time, that's why we can't inject the following dependencies

        /** @var Context $securityContext */
        $securityContext = $this->objectManager->get(Context::class);
        if ($securityContext->areAuthorizationChecksDisabled()) {
            $this->initiateDispatchLoop($request, $response);
            return;
        }

        /** @var FirewallInterface $firewall */
        $firewall = $this->objectManager->get(FirewallInterface::class);
        /** @var PsrLoggerFactoryInterface $securityLogger */
        $securityLogger = $this->objectManager->get(PsrLoggerFactoryInterface::class)->get('securityLogger');

        try {
            /** @var ActionRequest $request */
            $firewall->blockIllegalRequests($request);
            $this->initiateDispatchLoop($request, $response);
        } catch (AuthenticationRequiredException $exception) {
            $entryPointFound = false;
            /** @var $token TokenInterface */
            foreach ($securityContext->getAuthenticationTokens() as $token) {
                $entryPoint = $token->getAuthenticationEntryPoint();
                if ($entryPoint === null) {
                    continue;
                }
                $entryPointFound = true;
                if ($entryPoint instanceof WebRedirect) {
                    $securityLogger->info('Redirecting to authentication entry point', $entryPoint->getOptions(), LogEnvironment::fromMethodName(__METHOD__));
                } else {
                    $securityLogger->info(sprintf('Starting authentication with entry point of type "%s"', get_class($entryPoint)), LogEnvironment::fromMethodName(__METHOD__));
                }
                $securityContext->setInterceptedRequest($request->getMainRequest());
                /** @var HttpResponse $response */
                $entryPoint->startAuthentication($request->getHttpRequest(), $response);
            }
            if ($entryPointFound === false) {
                $securityLogger->notice('No authentication entry point found for active tokens, therefore cannot authenticate or redirect to authentication automatically.');
                throw $exception;
            }
        } catch (AccessDeniedException $exception) {
            $securityLogger->warning('Access denied', LogEnvironment::fromMethodName(__METHOD__));
            throw $exception;
        }
    }
public function dispatch ( RequestInterface $ request , ResponseInterface $ response ) { if ( $ request instanceof CliRequest ) { $ this -> initiateDispatchLoop ( $ request , $ response ) ; return ; } // NOTE: The dispatcher is used for both Action- and CLI-Requests. For the latter case dispatching might happen during compile-time, that's why we can't inject the following dependencies /** @var Context $securityContext */ $ securityContext = $ this -> objectManager -> get ( Context :: class ) ; if ( $ securityContext -> areAuthorizationChecksDisabled ( ) ) { $ this -> initiateDispatchLoop ( $ request , $ response ) ; return ; } /** @var FirewallInterface $firewall */ $ firewall = $ this -> objectManager -> get ( FirewallInterface :: class ) ; /** @var PsrLoggerFactoryInterface $securityLogger */ $ securityLogger = $ this -> objectManager -> get ( PsrLoggerFactoryInterface :: class ) -> get ( 'securityLogger' ) ; try { /** @var ActionRequest $request */ $ firewall -> blockIllegalRequests ( $ request ) ; $ this -> initiateDispatchLoop ( $ request , $ response ) ; } catch ( AuthenticationRequiredException $ exception ) { $ entryPointFound = false ; /** @var $token TokenInterface */ foreach ( $ securityContext -> getAuthenticationTokens ( ) as $ token ) { $ entryPoint = $ token -> getAuthenticationEntryPoint ( ) ; if ( $ entryPoint === null ) { continue ; } $ entryPointFound = true ; if ( $ entryPoint instanceof WebRedirect ) { $ securityLogger -> info ( 'Redirecting to authentication entry point' , $ entryPoint -> getOptions ( ) , LogEnvironment :: fromMethodName ( __METHOD__ ) ) ; } else { $ securityLogger -> info ( sprintf ( 'Starting authentication with entry point of type "%s"' , get_class ( $ entryPoint ) ) , LogEnvironment :: fromMethodName ( __METHOD__ ) ) ; } $ securityContext -> setInterceptedRequest ( $ request -> getMainRequest ( ) ) ; /** @var HttpResponse $response */ $ entryPoint -> startAuthentication ( $ request -> getHttpRequest ( ) , $ response ) ; } if ( $ entryPointFound === false ) { $ securityLogger -> notice ( 'No authentication entry point found for active tokens, therefore cannot authenticate or redirect to authentication automatically.' ) ; throw $ exception ; } } catch ( AccessDeniedException $ exception ) { $ securityLogger -> warning ( 'Access denied' , LogEnvironment :: fromMethodName ( __METHOD__ ) ) ; throw $ exception ; } }
Dispatches a request to a controller

@param RequestInterface $request The request to dispatch
@param ResponseInterface $response The response, to be modified by the controller
@return void
@throws AccessDeniedException
@throws AuthenticationRequiredException
@throws InfiniteLoopException
@throws InvalidControllerException
@throws NoSuchOptionException
@throws MissingConfigurationException
@api
Dispatches a request to a controller