bb9e913f529cf32925d8ac5c34e1438def8b9261
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Configuration / ConfigurationManager.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Configuration;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2013 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 * A configuration manager following the strategy pattern (GoF315). It hides the concrete
32 * implementation of the configuration manager and provides an unified acccess point.
33 *
34 * Use the shutdown() method to drop the concrete implementation.
35 */
36 class ConfigurationManager implements \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface {
37
38 /**
39 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
40 */
41 protected $objectManager;
42
43 /**
44 * @var \TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager
45 */
46 protected $concreteConfigurationManager;
47
48 /**
49 * @var \TYPO3\CMS\Extbase\Service\EnvironmentService
50 */
51 protected $environmentService;
52
53 /**
54 * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
55 * @return void
56 */
57 public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager) {
58 $this->objectManager = $objectManager;
59 }
60
61 /**
62 * @param \TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService
63 * @return void
64 */
65 public function injectEnvironmentService(\TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService) {
66 $this->environmentService = $environmentService;
67 }
68
69 /**
70 * Initializes the object
71 *
72 * @return void
73 */
74 public function initializeObject() {
75 $this->initializeConcreteConfigurationManager();
76 }
77
78 /**
79 * @return void
80 */
81 protected function initializeConcreteConfigurationManager() {
82 if ($this->environmentService->isEnvironmentInFrontendMode()) {
83 $this->concreteConfigurationManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\FrontendConfigurationManager');
84 } else {
85 $this->concreteConfigurationManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\BackendConfigurationManager');
86 }
87 }
88
89 /**
90 * @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject
91 * @return void
92 */
93 public function setContentObject(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject = NULL) {
94 $this->concreteConfigurationManager->setContentObject($contentObject);
95 }
96
97 /**
98 * @return \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
99 */
100 public function getContentObject() {
101 return $this->concreteConfigurationManager->getContentObject();
102 }
103
104 /**
105 * Sets the specified raw configuration coming from the outside.
106 * Note that this is a low level method and only makes sense to be used by Extbase internally.
107 *
108 * @param array $configuration The new configuration
109 * @return void
110 */
111 public function setConfiguration(array $configuration = array()) {
112 $this->concreteConfigurationManager->setConfiguration($configuration);
113 }
114
115 /**
116 * Returns the specified configuration.
117 * The actual configuration will be merged from different sources in a defined order.
118 *
119 * You can get the following types of configuration invoking:
120 * CONFIGURATION_TYPE_EXTBASE: Extbase settings
121 * CONFIGURATION_TYPE_FRAMEWORK: the current module/plugin settings
122 * CONFIGURATION_TYPE_TYPOSCRIPT: a raw TS array
123 *
124 * Note that this is a low level method and only makes sense to be used by Extbase internally.
125 *
126 * @param string $configurationType The kind of configuration to fetch - must be one of the CONFIGURATION_TYPE_* constants
127 * @param string $extensionName if specified, the configuration for the given extension will be returned.
128 * @param string $pluginName if specified, the configuration for the given plugin will be returned.
129 * @throws Exception\InvalidConfigurationTypeException
130 * @return array The configuration
131 */
132 public function getConfiguration($configurationType, $extensionName = NULL, $pluginName = NULL) {
133 switch ($configurationType) {
134 case self::CONFIGURATION_TYPE_SETTINGS:
135 $configuration = $this->concreteConfigurationManager->getConfiguration($extensionName, $pluginName);
136 return $configuration['settings'];
137 case self::CONFIGURATION_TYPE_FRAMEWORK:
138 return $this->concreteConfigurationManager->getConfiguration($extensionName, $pluginName);
139 case self::CONFIGURATION_TYPE_FULL_TYPOSCRIPT:
140 return $this->concreteConfigurationManager->getTypoScriptSetup();
141 default:
142 throw new \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException('Invalid configuration type "' . $configurationType . '"', 1206031879);
143 }
144 }
145
146 /**
147 * Returns TRUE if a certain feature, identified by $featureName
148 * should be activated, FALSE for backwards-compatible behavior.
149 *
150 * This is an INTERNAL API used throughout Extbase and Fluid for providing backwards-compatibility.
151 * Do not use it in your custom code!
152 *
153 * @param string $featureName
154 * @return boolean
155 */
156 public function isFeatureEnabled($featureName) {
157 $configuration = $this->getConfiguration(self::CONFIGURATION_TYPE_FRAMEWORK);
158 return (boolean) (isset($configuration['features'][$featureName]) && $configuration['features'][$featureName]);
159 }
160 }
161
162 ?>