Neos\FluidAdaptor\Core\Widget\AbstractWidgetController::processRequest PHP Method

processRequest() public method

Handles a request. The result output is returned by altering the given response.
public processRequest ( Neos\Flow\Mvc\RequestInterface $request, Neos\Flow\Mvc\ResponseInterface $response ) : void
$request Neos\Flow\Mvc\RequestInterface The request object
$response Neos\Flow\Mvc\ResponseInterface The response, modified by this handler
return void
    public function processRequest(RequestInterface $request, ResponseInterface $response)
    {
        /** @var $request \Neos\Flow\Mvc\ActionRequest */
        /** @var $widgetContext WidgetContext */
        $widgetContext = $request->getInternalArgument('__widgetContext');
        if ($widgetContext === null) {
            throw new WidgetContextNotFoundException('The widget context could not be found in the request.', 1307450180);
        }
        $this->widgetConfiguration = $widgetContext->getWidgetConfiguration();
        parent::processRequest($request, $response);
    }

Usage Example

 /**
  * Initiate a sub request to $this->controller. Make sure to fill $this->controller
  * via Dependency Injection.
  * @return Response the response of this request.
  * @throws Exception\InvalidControllerException
  * @throws Exception\MissingControllerException
  * @throws InfiniteLoopException
  * @throws StopActionException
  * @api
  */
 protected function initiateSubRequest()
 {
     if ($this->controller instanceof DependencyProxy) {
         $this->controller->_activateDependency();
     }
     if (!$this->controller instanceof AbstractWidgetController) {
         throw new Exception\MissingControllerException('initiateSubRequest() can not be called if there is no controller inside $this->controller. Make sure to add the @Neos\\Flow\\Annotations\\Inject annotation in your widget class.', 1284401632);
     }
     /** @var $subRequest ActionRequest */
     $subRequest = $this->objectManager->get(ActionRequest::class, $this->controllerContext->getRequest());
     /** @var $subResponse Response */
     $subResponse = $this->objectManager->get(Response::class, $this->controllerContext->getResponse());
     $this->passArgumentsToSubRequest($subRequest);
     $subRequest->setArgument('__widgetContext', $this->widgetContext);
     $subRequest->setArgumentNamespace('--' . $this->widgetContext->getWidgetIdentifier());
     $dispatchLoopCount = 0;
     while (!$subRequest->isDispatched()) {
         if ($dispatchLoopCount++ > 99) {
             throw new InfiniteLoopException('Could not ultimately dispatch the widget request after ' . $dispatchLoopCount . ' iterations.', 1380282310);
         }
         $widgetControllerObjectName = $this->widgetContext->getControllerObjectName();
         if ($subRequest->getControllerObjectName() !== '' && $subRequest->getControllerObjectName() !== $widgetControllerObjectName) {
             throw new Exception\InvalidControllerException(sprintf('You are not allowed to initiate requests to different controllers from a widget.' . chr(10) . 'widget controller: "%s", requested controller: "%s".', $widgetControllerObjectName, $subRequest->getControllerObjectName()), 1380284579);
         }
         $subRequest->setControllerObjectName($this->widgetContext->getControllerObjectName());
         try {
             $this->controller->processRequest($subRequest, $subResponse);
         } catch (StopActionException $exception) {
             if ($exception instanceof ForwardException) {
                 $subRequest = $exception->getNextRequest();
                 continue;
             }
             /** @var $parentResponse Response */
             $parentResponse = $this->controllerContext->getResponse();
             $parentResponse->setStatus($subResponse->getStatusCode())->setContent($subResponse->getContent())->setHeader('Location', $subResponse->getHeader('Location'));
             throw $exception;
         }
     }
     return $subResponse;
 }
AbstractWidgetController