[TASK] Update ckeditor to 4.13.0
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Mvc / Dispatcher.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Mvc;
3
4 use Psr\Container\ContainerInterface;
5 use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
6 use TYPO3\CMS\Extbase\SignalSlot\Dispatcher as SignalSlotDispatcher;
7
8 /*
9 * This file is part of the TYPO3 CMS project.
10 *
11 * It is free software; you can redistribute it and/or modify it under
12 * the terms of the GNU General Public License, either version 2
13 * of the License, or any later version.
14 *
15 * For the full copyright and license information, please read the
16 * LICENSE.txt file that was distributed with this source code.
17 *
18 * The TYPO3 project - inspiring people to share!
19 */
20
21 /**
22 * Dispatches requests to the controller which was specified by the request and
23 * returns the response the controller generated.
24 * @internal only to be used within Extbase, not part of TYPO3 Core API.
25 */
26 class Dispatcher implements \TYPO3\CMS\Core\SingletonInterface
27 {
28 /**
29 * @var ObjectManagerInterface A reference to the object manager
30 */
31 protected $objectManager;
32
33 /**
34 * @var ContainerInterface
35 */
36 private $container;
37
38 /**
39 * @var SignalSlotDispatcher
40 */
41 protected $signalSlotDispatcher;
42
43 /**
44 * @var array
45 */
46 protected $settings = [];
47
48 /**
49 * Constructs the global dispatcher
50 *
51 * @param ObjectManagerInterface $objectManager A reference to the object manager
52 * @param ContainerInterface $container
53 * @param SignalSlotDispatcher $signalSlotDispatcher
54 */
55 public function __construct(
56 ObjectManagerInterface $objectManager,
57 ContainerInterface $container,
58 SignalSlotDispatcher $signalSlotDispatcher
59 ) {
60 $this->objectManager = $objectManager;
61 $this->container = $container;
62 $this->signalSlotDispatcher = $signalSlotDispatcher;
63 }
64
65 /**
66 * Dispatches a request to a controller and initializes the security framework.
67 *
68 * @param \TYPO3\CMS\Extbase\Mvc\RequestInterface $request The request to dispatch
69 * @param \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response The response, to be modified by the controller
70 * @throws Exception\InfiniteLoopException
71 */
72 public function dispatch(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response)
73 {
74 $dispatchLoopCount = 0;
75 while (!$request->isDispatched()) {
76 if ($dispatchLoopCount++ > 99) {
77 throw new \TYPO3\CMS\Extbase\Mvc\Exception\InfiniteLoopException('Could not ultimately dispatch the request after ' . $dispatchLoopCount . ' iterations. Most probably, a @' . \TYPO3\CMS\Extbase\Annotation\IgnoreValidation::class . ' annotation is missing on re-displaying a form with validation errors.', 1217839467);
78 }
79 $controller = $this->resolveController($request);
80 try {
81 $controller->processRequest($request, $response);
82 } catch (\TYPO3\CMS\Extbase\Mvc\Exception\StopActionException $ignoredException) {
83 }
84 }
85 $this->emitAfterRequestDispatchSignal($request, $response);
86 }
87
88 /**
89 * Emits a signal after a request was dispatched
90 *
91 * @param RequestInterface $request
92 * @param ResponseInterface $response
93 */
94 protected function emitAfterRequestDispatchSignal(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response)
95 {
96 $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterRequestDispatch', [$request, $response]);
97 }
98
99 /**
100 * Finds and instantiates a controller that matches the current request.
101 * If no controller can be found, an instance of NotFoundControllerInterface is returned.
102 *
103 * @param \TYPO3\CMS\Extbase\Mvc\RequestInterface $request The request to dispatch
104 * @throws Exception\InvalidControllerException
105 * @return \TYPO3\CMS\Extbase\Mvc\Controller\ControllerInterface
106 */
107 protected function resolveController(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request)
108 {
109 $controllerObjectName = $request->getControllerObjectName();
110 if ($this->container->has($controllerObjectName)) {
111 $controller = $this->container->get($controllerObjectName);
112 } else {
113 $controller = $this->objectManager->get($controllerObjectName);
114 }
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 }