TYPO3 CMS  TYPO3_8-7
Dispatcher.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Extbase\Mvc;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
22 {
26  protected $objectManager;
27 
31  protected $reflectionService;
32 
37 
41  protected $settings = [];
42 
46  public function injectReflectionService(\TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService)
47  {
48  $this->reflectionService = $reflectionService;
49  }
50 
54  public function injectSignalSlotDispatcher(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher)
55  {
56  $this->signalSlotDispatcher = $signalSlotDispatcher;
57  }
58 
64  public function __construct(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
65  {
66  $this->objectManager = $objectManager;
67  }
68 
76  public function dispatch(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response)
77  {
78  $dispatchLoopCount = 0;
79  while (!$request->isDispatched()) {
80  if ($dispatchLoopCount++ > 99) {
81  throw new \TYPO3\CMS\Extbase\Mvc\Exception\InfiniteLoopException('Could not ultimately dispatch the request after ' . $dispatchLoopCount . ' iterations. Most probably, a @ignorevalidation annotation is missing on re-displaying a form with validation errors.', 1217839467);
82  }
83  $controller = $this->resolveController($request);
84  try {
85  $controller->processRequest($request, $response);
86  } catch (\TYPO3\CMS\Extbase\Mvc\Exception\StopActionException $ignoredException) {
87  }
88  }
89  $this->emitAfterRequestDispatchSignal($request, $response);
90  }
91 
98  protected function emitAfterRequestDispatchSignal(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response)
99  {
100  $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterRequestDispatch', [$request, $response]);
101  }
102 
111  protected function resolveController(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request)
112  {
113  $controllerObjectName = $request->getControllerObjectName();
114  $controller = $this->objectManager->get($controllerObjectName);
115  if (!$controller instanceof \TYPO3\CMS\Extbase\Mvc\Controller\ControllerInterface) {
116  throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidControllerException(
117  'Invalid controller "' . $request->getControllerObjectName() . '". The controller must implement the TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ControllerInterface.',
118  1476109646
119  );
120  }
121  return $controller;
122  }
123 }
__construct(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
Definition: Dispatcher.php:64
resolveController(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request)
Definition: Dispatcher.php:111
emitAfterRequestDispatchSignal(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response)
Definition: Dispatcher.php:98
dispatch(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response)
Definition: Dispatcher.php:76
injectSignalSlotDispatcher(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher)
Definition: Dispatcher.php:54
injectReflectionService(\TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService)
Definition: Dispatcher.php:46