‪TYPO3CMS  10.4
Dispatcher.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
16 namespace ‪TYPO3\CMS\Extbase\Mvc;
17 
18 use Psr\Container\ContainerInterface;
19 use Psr\EventDispatcher\EventDispatcherInterface;
28 
35 {
39  protected ‪$objectManager;
40 
44  private ‪$container;
45 
49  protected ‪$eventDispatcher;
50 
54  protected ‪$settings = [];
55 
63  public function ‪__construct(
65  ContainerInterface ‪$container,
66  EventDispatcherInterface ‪$eventDispatcher
67  ) {
68  $this->objectManager = ‪$objectManager;
69  $this->container = ‪$container;
70  $this->eventDispatcher = ‪$eventDispatcher;
71  }
72 
80  public function ‪dispatch(‪RequestInterface $request, ‪ResponseInterface $response)
81  {
82  $dispatchLoopCount = 0;
83  while (!$request->‪isDispatched()) {
84  if ($dispatchLoopCount++ > 99) {
85  throw new ‪InfiniteLoopException('Could not ultimately dispatch the request after ' . $dispatchLoopCount . ' iterations. Most probably, a @' . IgnoreValidation::class . ' annotation is missing on re-displaying a form with validation errors.', 1217839467);
86  }
87  $controller = $this->‪resolveController($request);
88  try {
89  $controller->processRequest($request, $response);
90  } catch (StopActionException $ignoredException) {
91  }
92  }
93 
94  $this->eventDispatcher->dispatch(new AfterRequestDispatchedEvent($request, $response));
95  }
96 
105  protected function ‪resolveController(RequestInterface $request)
106  {
107  $controllerObjectName = $request->getControllerObjectName();
108  if ($this->container->has($controllerObjectName)) {
109  $controller = $this->container->get($controllerObjectName);
110  } else {
111  $controller = $this->objectManager->get($controllerObjectName);
112  }
113  if (!$controller instanceof ControllerInterface) {
114  throw new InvalidControllerException(
115  'Invalid controller "' . $request->getControllerObjectName() . '". The controller must implement the TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ControllerInterface.',
116  1476109646
117  );
118  }
119  return $controller;
120  }
121 }
‪TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
Definition: StopActionException.php:31
‪TYPO3\CMS\Extbase\Mvc\RequestInterface\isDispatched
‪bool isDispatched()
‪TYPO3\CMS\Extbase\Annotation\IgnoreValidation
Definition: IgnoreValidation.php:25
‪TYPO3\CMS\Extbase\Mvc\Dispatcher
Definition: Dispatcher.php:35
‪TYPO3\CMS\Extbase\Mvc\ResponseInterface
Definition: ResponseInterface.php:22
‪TYPO3\CMS\Extbase\Mvc
‪TYPO3\CMS\Extbase\Object\ObjectManagerInterface
Definition: ObjectManagerInterface.php:26
‪TYPO3\CMS\Extbase\Mvc\Dispatcher\resolveController
‪Controller ControllerInterface resolveController(RequestInterface $request)
Definition: Dispatcher.php:101
‪TYPO3\CMS\Extbase\Mvc\Dispatcher\dispatch
‪dispatch(RequestInterface $request, ResponseInterface $response)
Definition: Dispatcher.php:76
‪TYPO3\CMS\Extbase\Mvc\RequestInterface\getControllerObjectName
‪string getControllerObjectName()
‪TYPO3\CMS\Extbase\Mvc\Dispatcher\$objectManager
‪ObjectManagerInterface $objectManager
Definition: Dispatcher.php:38
‪TYPO3\CMS\Extbase\Mvc\Dispatcher\$container
‪ContainerInterface $container
Definition: Dispatcher.php:42
‪TYPO3\CMS\Extbase\Mvc\Exception\InvalidControllerException
Definition: InvalidControllerException.php:26
‪TYPO3\CMS\Extbase\Mvc\RequestInterface
Definition: RequestInterface.php:22
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:23
‪TYPO3\CMS\Extbase\Mvc\Dispatcher\__construct
‪__construct(ObjectManagerInterface $objectManager, ContainerInterface $container, EventDispatcherInterface $eventDispatcher)
Definition: Dispatcher.php:59
‪TYPO3\CMS\Extbase\Mvc\Controller\ControllerInterface
Definition: ControllerInterface.php:25
‪TYPO3\CMS\Extbase\Mvc\Dispatcher\$settings
‪array $settings
Definition: Dispatcher.php:50
‪TYPO3\CMS\Extbase\Event\Mvc\AfterRequestDispatchedEvent
Definition: AfterRequestDispatchedEvent.php:27
‪TYPO3\CMS\Extbase\Mvc\Dispatcher\$eventDispatcher
‪EventDispatcherInterface $eventDispatcher
Definition: Dispatcher.php:46
‪TYPO3\CMS\Extbase\Mvc\Exception\InfiniteLoopException
Definition: InfiniteLoopException.php:26