TYPO3  7.6
RequestHandlerResolver.php
Go to the documentation of this file.
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 
21 {
25  protected $objectManager;
26 
30  protected $reflectionService;
31 
36 
40  public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
41  {
42  $this->objectManager = $objectManager;
43  }
44 
48  public function injectReflectionService(\TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService)
49  {
50  $this->reflectionService = $reflectionService;
51  }
52 
56  public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)
57  {
58  $this->configurationManager = $configurationManager;
59  }
60 
68  public function resolveRequestHandler()
69  {
70  $availableRequestHandlerClassNames = $this->getRegisteredRequestHandlerClassNames();
71  $suitableRequestHandlers = array();
72  foreach ($availableRequestHandlerClassNames as $requestHandlerClassName) {
73  $requestHandler = $this->objectManager->get($requestHandlerClassName);
74  if ($requestHandler->canHandleRequest()) {
75  $priority = $requestHandler->getPriority();
76  if (isset($suitableRequestHandlers[$priority])) {
77  throw new \TYPO3\CMS\Extbase\Mvc\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);
78  }
79  $suitableRequestHandlers[$priority] = $requestHandler;
80  }
81  }
82  if (empty($suitableRequestHandlers)) {
83  throw new \TYPO3\CMS\Extbase\Mvc\Exception('No suitable request handler found.', 1205414233);
84  }
85  ksort($suitableRequestHandlers);
86  return array_pop($suitableRequestHandlers);
87  }
88 
95  {
96  $settings = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
97  return is_array($settings['mvc']['requestHandlers']) ? $settings['mvc']['requestHandlers'] : array();
98  }
99 }