[TASK] Replace inject methods with @inject
[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 * @inject
41 */
42 protected $objectManager;
43
44 /**
45 * @var \TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager
46 */
47 protected $concreteConfigurationManager;
48
49 /**
50 * @var \TYPO3\CMS\Extbase\Service\EnvironmentService
51 * @inject
52 */
53 protected $environmentService;
54
55 /**
56 * Initializes the object
57 *
58 * @return void
59 */
60 public function initializeObject() {
61 $this->initializeConcreteConfigurationManager();
62 }
63
64 /**
65 * @return void
66 */
67 protected function initializeConcreteConfigurationManager() {
68 if ($this->environmentService->isEnvironmentInFrontendMode()) {
69 $this->concreteConfigurationManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\FrontendConfigurationManager');
70 } else {
71 $this->concreteConfigurationManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\BackendConfigurationManager');
72 }
73 }
74
75 /**
76 * @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject
77 * @return void
78 */
79 public function setContentObject(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject = NULL) {
80 $this->concreteConfigurationManager->setContentObject($contentObject);
81 }
82
83 /**
84 * @return \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
85 */
86 public function getContentObject() {
87 return $this->concreteConfigurationManager->getContentObject();
88 }
89
90 /**
91 * Sets the specified raw configuration coming from the outside.
92 * Note that this is a low level method and only makes sense to be used by Extbase internally.
93 *
94 * @param array $configuration The new configuration
95 * @return void
96 */
97 public function setConfiguration(array $configuration = array()) {
98 $this->concreteConfigurationManager->setConfiguration($configuration);
99 }
100
101 /**
102 * Returns the specified configuration.
103 * The actual configuration will be merged from different sources in a defined order.
104 *
105 * You can get the following types of configuration invoking:
106 * CONFIGURATION_TYPE_EXTBASE: Extbase settings
107 * CONFIGURATION_TYPE_FRAMEWORK: the current module/plugin settings
108 * CONFIGURATION_TYPE_TYPOSCRIPT: a raw TS array
109 *
110 * Note that this is a low level method and only makes sense to be used by Extbase internally.
111 *
112 * @param string $configurationType The kind of configuration to fetch - must be one of the CONFIGURATION_TYPE_* constants
113 * @param string $extensionName if specified, the configuration for the given extension will be returned.
114 * @param string $pluginName if specified, the configuration for the given plugin will be returned.
115 * @throws Exception\InvalidConfigurationTypeException
116 * @return array The configuration
117 */
118 public function getConfiguration($configurationType, $extensionName = NULL, $pluginName = NULL) {
119 switch ($configurationType) {
120 case self::CONFIGURATION_TYPE_SETTINGS:
121 $configuration = $this->concreteConfigurationManager->getConfiguration($extensionName, $pluginName);
122 return $configuration['settings'];
123 case self::CONFIGURATION_TYPE_FRAMEWORK:
124 return $this->concreteConfigurationManager->getConfiguration($extensionName, $pluginName);
125 case self::CONFIGURATION_TYPE_FULL_TYPOSCRIPT:
126 return $this->concreteConfigurationManager->getTypoScriptSetup();
127 default:
128 throw new \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException('Invalid configuration type "' . $configurationType . '"', 1206031879);
129 }
130 }
131
132 /**
133 * Returns TRUE if a certain feature, identified by $featureName
134 * should be activated, FALSE for backwards-compatible behavior.
135 *
136 * This is an INTERNAL API used throughout Extbase and Fluid for providing backwards-compatibility.
137 * Do not use it in your custom code!
138 *
139 * @param string $featureName
140 * @return boolean
141 */
142 public function isFeatureEnabled($featureName) {
143 $configuration = $this->getConfiguration(self::CONFIGURATION_TYPE_FRAMEWORK);
144 return (boolean) (isset($configuration['features'][$featureName]) && $configuration['features'][$featureName]);
145 }
146 }
147
148 ?>