/**
  * Dispatches a request to a controller
  *
  * @param \TYPO3\Flow\Mvc\RequestInterface $request The request to dispatch
  * @param \TYPO3\Flow\Mvc\ResponseInterface $response The response, to be modified by the controller
  * @return void
  * @throws \TYPO3\Flow\Mvc\Exception\InfiniteLoopException
  * @api
  */
 public function dispatch(RequestInterface $request, ResponseInterface $response)
 {
     $dispatchLoopCount = 0;
     while (!$request->isDispatched()) {
         if ($dispatchLoopCount++ > 99) {
             throw new \TYPO3\Flow\Mvc\Exception\InfiniteLoopException('Could not ultimately dispatch the request after ' . $dispatchLoopCount . ' iterations.', 1217839467);
         }
         $controller = $this->resolveController($request);
         try {
             $this->emitBeforeControllerInvocation($request, $response, $controller);
             $controller->processRequest($request, $response);
             $this->emitAfterControllerInvocation($request, $response, $controller);
         } catch (StopActionException $exception) {
             $this->emitAfterControllerInvocation($request, $response, $controller);
             if ($exception instanceof ForwardException) {
                 $request = $exception->getNextRequest();
             } elseif ($request->isMainRequest() === FALSE) {
                 $request = $request->getParentRequest();
             }
         }
     }
 }
 /**
  * Try processing the request until it is successfully marked "dispatched"
  *
  * @param RequestInterface $request
  * @param ResponseInterface $response
  * @throws InvalidControllerException|InfiniteLoopException|NoSuchOptionException
  */
 protected function initiateDispatchLoop(RequestInterface $request, ResponseInterface $response)
 {
     $dispatchLoopCount = 0;
     /** @var ActionRequest $request */
     while (!$request->isDispatched()) {
         if ($dispatchLoopCount++ > 99) {
             throw new Exception\InfiniteLoopException(sprintf('Could not ultimately dispatch the request after %d iterations.', $dispatchLoopCount), 1217839467);
         }
         $controller = $this->resolveController($request);
         try {
             $this->emitBeforeControllerInvocation($request, $response, $controller);
             $controller->processRequest($request, $response);
             $this->emitAfterControllerInvocation($request, $response, $controller);
         } catch (StopActionException $exception) {
             $this->emitAfterControllerInvocation($request, $response, $controller);
             if ($exception instanceof ForwardException) {
                 $request = $exception->getNextRequest();
             } elseif (!$request->isMainRequest()) {
                 $request = $request->getParentRequest();
             }
         }
     }
 }