[TASK] Re-work/simplify copyright header in PHP files - Part 7
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Mvc / Dispatcher.php
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 /**
17 * Dispatches requests to the controller which was specified by the request and
18 * returns the response the controller generated.
19 */
20 class Dispatcher implements \TYPO3\CMS\Core\SingletonInterface {
21
22 /**
23 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface A reference to the object manager
24 */
25 protected $objectManager;
26
27 /**
28 * @var \TYPO3\CMS\Extbase\Reflection\ReflectionService
29 * @inject
30 */
31 protected $reflectionService;
32
33 /**
34 * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
35 * @inject
36 */
37 protected $signalSlotDispatcher;
38
39 /**
40 * @var array
41 */
42 protected $settings = array();
43
44 /**
45 * Constructs the global dispatcher
46 *
47 * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager A reference to the object manager
48 */
49 public function __construct(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager) {
50 $this->objectManager = $objectManager;
51 }
52
53 /**
54 * Dispatches a request to a controller and initializes the security framework.
55 *
56 * @param \TYPO3\CMS\Extbase\Mvc\RequestInterface $request The request to dispatch
57 * @param \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response The response, to be modified by the controller
58 * @throws Exception\InfiniteLoopException
59 * @return void
60 */
61 public function dispatch(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response) {
62 $dispatchLoopCount = 0;
63 while (!$request->isDispatched()) {
64 if ($dispatchLoopCount++ > 99) {
65 throw new \TYPO3\CMS\Extbase\Mvc\Exception\InfiniteLoopException('Could not ultimately dispatch the request after ' . $dispatchLoopCount . ' iterations. Most probably, a @ignorevalidation or @dontvalidate (old propertymapper) annotation is missing on re-displaying a form with validation errors.', 1217839467);
66 }
67 $controller = $this->resolveController($request);
68 try {
69 $controller->processRequest($request, $response);
70 } catch (\TYPO3\CMS\Extbase\Mvc\Exception\StopActionException $ignoredException) {
71 }
72 }
73 $this->emitAfterRequestDispatchSignal($request, $response);
74 }
75
76 /**
77 * Emits a signal after a request was dispatched
78 *
79 * @param RequestInterface $request
80 * @param ResponseInterface $response
81 */
82 protected function emitAfterRequestDispatchSignal(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response) {
83 $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterRequestDispatch', array('request' => $request, 'response' => $response));
84 }
85
86 /**
87 * Finds and instanciates a controller that matches the current request.
88 * If no controller can be found, an instance of NotFoundControllerInterface is returned.
89 *
90 * @param \TYPO3\CMS\Extbase\Mvc\RequestInterface $request The request to dispatch
91 * @throws Exception\InvalidControllerException
92 * @return \TYPO3\CMS\Extbase\Mvc\Controller\ControllerInterface
93 */
94 protected function resolveController(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request) {
95 $controllerObjectName = $request->getControllerObjectName();
96 $controller = $this->objectManager->get($controllerObjectName);
97 if (!$controller instanceof \TYPO3\CMS\Extbase\Mvc\Controller\ControllerInterface) {
98 throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidControllerException('Invalid controller "' . $request->getControllerObjectName() . '". The controller must implement the TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ControllerInterface.', 1202921619);
99 }
100 return $controller;
101 }
102 }