Neos\Flow\Mvc\Dispatcher::dispatch PHP Метод

dispatch() публичный Метод

Dispatches a request to a controller
public dispatch ( Neos\Flow\Mvc\RequestInterface $request, Neos\Flow\Mvc\ResponseInterface $response ) : void
$request Neos\Flow\Mvc\RequestInterface The request to dispatch
$response Neos\Flow\Mvc\ResponseInterface The response, to be modified by the controller
Результат void
    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 SecurityLoggerInterface $securityLogger */
        $securityLogger = $this->objectManager->get(SecurityLoggerInterface::class);
        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->log('Redirecting to authentication entry point', LOG_INFO, $entryPoint->getOptions());
                } else {
                    $securityLogger->log(sprintf('Starting authentication with entry point of type "%s"', get_class($entryPoint)), LOG_INFO);
                }
                $securityContext->setInterceptedRequest($request->getMainRequest());
                /** @var HttpResponse $response */
                $entryPoint->startAuthentication($request->getHttpRequest(), $response);
            }
            if ($entryPointFound === false) {
                $securityLogger->log('No authentication entry point found for active tokens, therefore cannot authenticate or redirect to authentication automatically.', LOG_NOTICE);
                throw $exception;
            }
        } catch (AccessDeniedException $exception) {
            $securityLogger->log('Access denied', LOG_WARNING);
            throw $exception;
        }
    }

Usage Example

 /**
  * Create an action request from stored route match values and dispatch to that
  *
  * @param ComponentContext $componentContext
  * @return void
  */
 public function handle(ComponentContext $componentContext)
 {
     $httpRequest = $componentContext->getHttpRequest();
     /** @var $actionRequest ActionRequest */
     $actionRequest = $this->objectManager->get(ActionRequest::class, $httpRequest);
     $this->securityContext->setRequest($actionRequest);
     $routingMatchResults = $componentContext->getParameter(Routing\RoutingComponent::class, 'matchResults');
     $actionRequest->setArguments($this->mergeArguments($httpRequest, $routingMatchResults));
     $this->setDefaultControllerAndActionNameIfNoneSpecified($actionRequest);
     $componentContext->setParameter(self::class, 'actionRequest', $actionRequest);
     $this->dispatcher->dispatch($actionRequest, $componentContext->getHttpResponse());
 }
All Usage Examples Of Neos\Flow\Mvc\Dispatcher::dispatch