‪TYPO3CMS  10.4
RequestHandlerResolver.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 
20 
26 {
30  protected ‪$objectManager;
31 
36 
41  {
42  $this->objectManager = ‪$objectManager;
43  }
44 
48  public function ‪__construct(‪RequestHandlersConfigurationFactory $requestHandlersConfigurationFactory)
49  {
50  $this->requestHandlersConfiguration = $requestHandlersConfigurationFactory->‪createRequestHandlersConfiguration();
51  }
52 
60  public function ‪resolveRequestHandler()
61  {
62  $suitableRequestHandlers = [];
63  foreach ($this->requestHandlersConfiguration->getRegisteredRequestHandlers() as $requestHandlerClassName) {
65  $requestHandler = $this->objectManager->get($requestHandlerClassName);
66  if ($requestHandler->canHandleRequest()) {
67  $priority = $requestHandler->‪getPriority();
68  if (isset($suitableRequestHandlers[$priority])) {
69  throw new ‪Exception('More than one request handler with the same priority can handle the request, but only one handler may be active at a time!', 1176475350);
70  }
71  $suitableRequestHandlers[$priority] = $requestHandler;
72  }
73  }
74  if (empty($suitableRequestHandlers)) {
75  throw new ‪Exception('No suitable request handler found.', 1205414233);
76  }
77  ksort($suitableRequestHandlers);
78  return array_pop($suitableRequestHandlers);
79  }
80 }
‪TYPO3\CMS\Extbase\Mvc\Exception
Definition: Exception.php:26
‪TYPO3\CMS\Extbase\Mvc\RequestHandlerResolver\injectObjectManager
‪injectObjectManager(ObjectManagerInterface $objectManager)
Definition: RequestHandlerResolver.php:38
‪TYPO3\CMS\Extbase\Configuration\RequestHandlersConfigurationFactory
Definition: RequestHandlersConfigurationFactory.php:35
‪TYPO3\CMS\Extbase\Mvc
‪TYPO3\CMS\Extbase\Mvc\RequestHandlerResolver\$requestHandlersConfiguration
‪TYPO3 CMS Extbase Configuration RequestHandlersConfiguration $requestHandlersConfiguration
Definition: RequestHandlerResolver.php:33
‪TYPO3\CMS\Extbase\Mvc\RequestHandlerResolver\resolveRequestHandler
‪TYPO3 CMS Extbase Mvc RequestHandlerInterface resolveRequestHandler()
Definition: RequestHandlerResolver.php:58
‪TYPO3\CMS\Extbase\Object\ObjectManagerInterface
Definition: ObjectManagerInterface.php:26
‪TYPO3\CMS\Extbase\Mvc\RequestHandlerResolver\__construct
‪__construct(RequestHandlersConfigurationFactory $requestHandlersConfigurationFactory)
Definition: RequestHandlerResolver.php:46
‪TYPO3\CMS\Extbase\Mvc\RequestHandlerResolver\$objectManager
‪TYPO3 CMS Extbase Object ObjectManagerInterface $objectManager
Definition: RequestHandlerResolver.php:29
‪TYPO3\CMS\Extbase\Mvc\RequestHandlerInterface\getPriority
‪int getPriority()
‪TYPO3\CMS\Extbase\Mvc\RequestHandlerResolver
Definition: RequestHandlerResolver.php:26
‪TYPO3\CMS\Extbase\Configuration\RequestHandlersConfigurationFactory\createRequestHandlersConfiguration
‪RequestHandlersConfiguration createRequestHandlersConfiguration()
Definition: RequestHandlersConfigurationFactory.php:64