[CLEANUP] Replace wrong/old file copyright comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Mvc / RequestHandlerResolver.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Mvc;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2012 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
8 * Extbase is a backport of TYPO3 Flow. All credits go to the TYPO3 Flow team.
9 * All rights reserved
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 * A copy is found in the textfile GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30 /**
31 * Analyzes the raw request and delivers a request handler which can handle it.
32 */
33 class RequestHandlerResolver {
34
35 /**
36 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
37 */
38 protected $objectManager;
39
40 /**
41 * @var \TYPO3\CMS\Extbase\Reflection\ReflectionService
42 */
43 protected $reflectionService;
44
45 /**
46 * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
47 */
48 protected $configurationManager;
49
50 /**
51 * Injects the object manager
52 *
53 * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager A reference to the object manager
54 * @return void
55 */
56 public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager) {
57 $this->objectManager = $objectManager;
58 }
59
60 /**
61 * Injects the reflection service
62 *
63 * @param \TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService
64 * @return void
65 */
66 public function injectReflectionService(\TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService) {
67 $this->reflectionService = $reflectionService;
68 }
69
70 /**
71 * Injects the configuration manager
72 *
73 * @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager
74 * @return void
75 */
76 public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager) {
77 $this->configurationManager = $configurationManager;
78 }
79
80 /**
81 * Analyzes the raw request and tries to find a request handler which can handle
82 * it. If none is found, an exception is thrown.
83 *
84 * @return \TYPO3\CMS\Extbase\Mvc\RequestHandlerInterface A request handler
85 * @throws \TYPO3\CMS\Extbase\Mvc\Exception
86 */
87 public function resolveRequestHandler() {
88 $availableRequestHandlerClassNames = $this->getRegisteredRequestHandlerClassNames();
89 $suitableRequestHandlers = array();
90 foreach ($availableRequestHandlerClassNames as $requestHandlerClassName) {
91 $requestHandler = $this->objectManager->get($requestHandlerClassName);
92 if ($requestHandler->canHandleRequest()) {
93 $priority = $requestHandler->getPriority();
94 if (isset($suitableRequestHandlers[$priority])) {
95 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);
96 }
97 $suitableRequestHandlers[$priority] = $requestHandler;
98 }
99 }
100 if (count($suitableRequestHandlers) === 0) {
101 throw new \TYPO3\CMS\Extbase\Mvc\Exception('No suitable request handler found.', 1205414233);
102 }
103 ksort($suitableRequestHandlers);
104 return array_pop($suitableRequestHandlers);
105 }
106
107 /**
108 * Returns a list of all registered request handlers.
109 *
110 * @return array
111 */
112 public function getRegisteredRequestHandlerClassNames() {
113 $settings = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
114 return is_array($settings['mvc']['requestHandlers']) ? $settings['mvc']['requestHandlers'] : array();
115 }
116 }
117
118 ?>