TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
extbase/Classes/Mvc/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 
77  public function dispatch(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response)
78  {
79  $dispatchLoopCount = 0;
80  while (!$request->isDispatched()) {
81  if ($dispatchLoopCount++ > 99) {
82  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);
83  }
84  $controller = $this->resolveController($request);
85  try {
86  $controller->processRequest($request, $response);
87  } catch (\TYPO3\CMS\Extbase\Mvc\Exception\StopActionException $ignoredException) {
88  }
89  }
90  $this->emitAfterRequestDispatchSignal($request, $response);
91  }
92 
99  protected function emitAfterRequestDispatchSignal(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response)
100  {
101  $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterRequestDispatch', [$request, $response]);
102  }
103 
112  protected function resolveController(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request)
113  {
114  $controllerObjectName = $request->getControllerObjectName();
115  $controller = $this->objectManager->get($controllerObjectName);
116  if (!$controller instanceof \TYPO3\CMS\Extbase\Mvc\Controller\ControllerInterface) {
117  throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidControllerException(
118  'Invalid controller "' . $request->getControllerObjectName() . '". The controller must implement the TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ControllerInterface.',
119  1476109646
120  );
121  }
122  return $controller;
123  }
124 }
injectReflectionService(\TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService)
emitAfterRequestDispatchSignal(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request,\TYPO3\CMS\Extbase\Mvc\ResponseInterface $response)
dispatch(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request,\TYPO3\CMS\Extbase\Mvc\ResponseInterface $response)
resolveController(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request)
__construct(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
injectSignalSlotDispatcher(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher)