aac52d6f167580bf78bfcd918d0a8791304d6d77
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Configuration / ConfigurationManager.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * A configuration manager following the strategy pattern (GoF315). It hides the concrete
27 * implementation of the configuration manager and provides an unified acccess point.
28 *
29 * Use the shutdown() method to drop the concrete implementation.
30 *
31 * @package Extbase
32 * @subpackage Configuration
33 * @version $ID:$
34 */
35 class Tx_Extbase_Configuration_ConfigurationManager implements Tx_Extbase_Configuration_ConfigurationManagerInterface {
36
37 /**
38 * @var Tx_Extbase_Object_ObjectManagerInterface
39 */
40 protected $objectManager;
41
42 /**
43 * @var Tx_Extbase_Configuration_AbstractConfigurationManager
44 **/
45 protected $concreteConfigurationManager;
46
47 /**
48 * @param Tx_Extbase_Object_ObjectManagerInterface $objectManager
49 * @return void
50 */
51 public function injectObjectManager(Tx_Extbase_Object_ObjectManagerInterface $objectManager) {
52 $this->objectManager = $objectManager;
53 $this->initializeConcreteConfigurationManager();
54 }
55
56 /**
57 * @return void
58 */
59 protected function initializeConcreteConfigurationManager() {
60 if (TYPO3_MODE === 'FE') {
61 $this->concreteConfigurationManager = $this->objectManager->get('Tx_Extbase_Configuration_FrontendConfigurationManager');
62 } else {
63 $this->concreteConfigurationManager = $this->objectManager->get('Tx_Extbase_Configuration_BackendConfigurationManager');
64 }
65 }
66
67 /**
68 * @param tslib_cObj $contentObject
69 * @return void
70 */
71 public function setContentObject(tslib_cObj $contentObject = NULL) {
72 $this->concreteConfigurationManager->setContentObject($contentObject);
73 }
74
75 /**
76 * @return tslib_cObj
77 */
78 public function getContentObject() {
79 return $this->concreteConfigurationManager->getContentObject();
80 }
81
82 /**
83 * Sets the specified raw configuration coming from the outside.
84 * Note that this is a low level method and only makes sense to be used by Extbase internally.
85 *
86 * @param array $configuration The new configuration
87 * @return void
88 */
89 public function setConfiguration(array $configuration = array()) {
90 $this->concreteConfigurationManager->setConfiguration($configuration);
91 }
92
93 /**
94 * Returns the specified configuration.
95 * The actual configuration will be merged from different sources in a defined order.
96 *
97 * Note that this is a low level method and only makes sense to be used by Extbase internally.
98 *
99 * @param string $configurationType The kind of configuration to fetch - must be one of the CONFIGURATION_TYPE_* constants
100 * @param string $extensionName if specified, the configuration for the given extension will be returned.
101 * @param string $pluginName if specified, the configuration for the given plugin will be returned.
102 * @return array The configuration
103 */
104 public function getConfiguration($configurationType, $extensionName = NULL, $pluginName = NULL) {
105 switch ($configurationType) {
106 case self::CONFIGURATION_TYPE_SETTINGS :
107 $configuration = $this->concreteConfigurationManager->getConfiguration($extensionName, $pluginName);
108 return $configuration['settings'];
109 case self::CONFIGURATION_TYPE_FRAMEWORK :
110 return $this->concreteConfigurationManager->getConfiguration($extensionName, $pluginName);
111 case self::CONFIGURATION_TYPE_FULL_TYPOSCRIPT :
112 return $this->concreteConfigurationManager->getTypoScriptSetup();
113 default :
114 throw new Tx_Extbase_Configuration_Exception_InvalidConfigurationTypeException('Invalid configuration type "' . $configurationType . '"', 1206031879);
115 }
116 }
117
118 }
119 ?>