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