[+BUGFIX] Extbase (Persistence): Extbase still used PHPs current() on some QueryResul...
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / MVC / RequestHandlerResolver.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This class is a backport of the corresponding class of FLOW3.
9 * All credits go to the v5 team.
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Analyzes the raw request and delivers a request handler which can handle it.
30 */
31 class Tx_Extbase_MVC_RequestHandlerResolver {
32
33 /**
34 * @var Tx_Extbase_Object_ObjectManagerInterface
35 */
36 protected $objectManager;
37
38 /**
39 * @var Tx_Extbase_Reflection_ReflectionService
40 */
41 protected $reflectionService;
42
43 /**
44 * @var Tx_Extbase_Configuration_ConfigurationManagerInterface
45 */
46 protected $configurationManager;
47
48 /**
49 * Injects the object manager
50 *
51 * @param Tx_Extbase_Object_ObjectManagerInterface $objectManager A reference to the object manager
52 * @return void
53 */
54 public function injectObjectManager(Tx_Extbase_Object_ObjectManagerInterface $objectManager) {
55 $this->objectManager = $objectManager;
56 }
57
58 /**
59 * Injects the reflection service
60 *
61 * @param Tx_Extbase_Reflection_Service $reflectionService
62 * @return void
63 */
64 public function injectReflectionService(Tx_Extbase_Reflection_Service $reflectionService) {
65 $this->reflectionService = $reflectionService;
66 }
67
68 /**
69 * Injects the configuration manager
70 *
71 * @param Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager
72 * @return void
73 */
74 public function injectConfigurationManager(Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager) {
75 $this->configurationManager = $configurationManager;
76 }
77
78 /**
79 * Analyzes the raw request and tries to find a request handler which can handle
80 * it. If none is found, an exception is thrown.
81 *
82 * @return Tx_Extbase_MVC_RequestHandler A request handler
83 * @throws Tx_Extbase_MVC_Exception
84 */
85 public function resolveRequestHandler() {
86 $availableRequestHandlerClassNames = $this->getRegisteredRequestHandlerClassNames();
87
88 $suitableRequestHandlers = array();
89 foreach ($availableRequestHandlerClassNames as $requestHandlerClassName) {
90 $requestHandler = $this->objectManager->get($requestHandlerClassName);
91 if ($requestHandler->canHandleRequest()) {
92 $priority = $requestHandler->getPriority();
93 if (isset($suitableRequestHandlers[$priority])) throw new Tx_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);
94 $suitableRequestHandlers[$priority] = $requestHandler;
95 }
96 }
97 if (count($suitableRequestHandlers) === 0) throw new Tx_Extbase_MVC_Exception('No suitable request handler found.', 1205414233);
98 ksort($suitableRequestHandlers);
99 return array_pop($suitableRequestHandlers);
100 }
101
102 public function getRegisteredRequestHandlerClassNames() {
103 $settings = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
104 return is_array($settings['mvc']['requestHandlers']) ? $settings['mvc']['requestHandlers'] : array();
105 }
106 }
107 ?>