1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the TYPO3 CMS project. |
7
|
|
|
* |
8
|
|
|
* It is free software; you can redistribute it and/or modify it under |
9
|
|
|
* the terms of the GNU General Public License, either version 2 |
10
|
|
|
* of the License, or any later version. |
11
|
|
|
* |
12
|
|
|
* For the full copyright and license information, please read the |
13
|
|
|
* LICENSE.txt file that was distributed with this source code. |
14
|
|
|
* |
15
|
|
|
* The TYPO3 project - inspiring people to share! |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace TYPO3\CMS\Extbase\Configuration; |
19
|
|
|
|
20
|
|
|
use Psr\Container\ContainerInterface; |
21
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
22
|
|
|
use TYPO3\CMS\Core\Http\ApplicationType; |
23
|
|
|
use TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException; |
24
|
|
|
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* A configuration manager following the strategy pattern (GoF315). It hides the concrete |
28
|
|
|
* implementation of the configuration manager and provides a unified access point. |
29
|
|
|
* |
30
|
|
|
* Use the shutdown() method to drop the concrete implementation. |
31
|
|
|
* @internal only to be used within Extbase, not part of TYPO3 Core API. |
32
|
|
|
*/ |
33
|
|
|
class ConfigurationManager implements ConfigurationManagerInterface |
34
|
|
|
{ |
35
|
|
|
private ContainerInterface $container; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var AbstractConfigurationManager |
39
|
|
|
*/ |
40
|
|
|
protected $concreteConfigurationManager; |
41
|
|
|
|
42
|
|
|
public function __construct(ContainerInterface $container) |
43
|
|
|
{ |
44
|
|
|
$this->container = $container; |
45
|
|
|
$this->initializeConcreteConfigurationManager(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
protected function initializeConcreteConfigurationManager(): void |
49
|
|
|
{ |
50
|
|
|
if (($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface |
51
|
|
|
&& ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend() |
52
|
|
|
) { |
53
|
|
|
$this->concreteConfigurationManager = $this->container->get(FrontendConfigurationManager::class); |
54
|
|
|
} else { |
55
|
|
|
$this->concreteConfigurationManager = $this->container->get(BackendConfigurationManager::class); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject |
61
|
|
|
*/ |
62
|
|
|
public function setContentObject(ContentObjectRenderer $contentObject): void |
63
|
|
|
{ |
64
|
|
|
$this->concreteConfigurationManager->setContentObject($contentObject); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer|null |
69
|
|
|
*/ |
70
|
|
|
public function getContentObject(): ?ContentObjectRenderer |
71
|
|
|
{ |
72
|
|
|
return $this->concreteConfigurationManager->getContentObject(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Sets the specified raw configuration coming from the outside. |
77
|
|
|
* Note that this is a low level method and only makes sense to be used by Extbase internally. |
78
|
|
|
* |
79
|
|
|
* @param array $configuration The new configuration |
80
|
|
|
*/ |
81
|
|
|
public function setConfiguration(array $configuration = []): void |
82
|
|
|
{ |
83
|
|
|
$this->concreteConfigurationManager->setConfiguration($configuration); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Returns the specified configuration. |
88
|
|
|
* The actual configuration will be merged from different sources in a defined order. |
89
|
|
|
* |
90
|
|
|
* You can get the following types of configuration invoking: |
91
|
|
|
* CONFIGURATION_TYPE_SETTINGS: Extbase settings |
92
|
|
|
* CONFIGURATION_TYPE_FRAMEWORK: the current module/plugin settings |
93
|
|
|
* CONFIGURATION_TYPE_FULL_TYPOSCRIPT: a raw TS array |
94
|
|
|
* |
95
|
|
|
* Note that this is a low level method and only makes sense to be used by Extbase internally. |
96
|
|
|
* |
97
|
|
|
* @param string $configurationType The kind of configuration to fetch - must be one of the CONFIGURATION_TYPE_* constants |
98
|
|
|
* @param string|null $extensionName if specified, the configuration for the given extension will be returned. |
99
|
|
|
* @param string|null $pluginName if specified, the configuration for the given plugin will be returned. |
100
|
|
|
* @throws Exception\InvalidConfigurationTypeException |
101
|
|
|
* @return array The configuration |
102
|
|
|
*/ |
103
|
|
|
public function getConfiguration(string $configurationType, string $extensionName = null, string $pluginName = null): array |
104
|
|
|
{ |
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 InvalidConfigurationTypeException('Invalid configuration type "' . $configurationType . '"', 1206031879); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Returns TRUE if a certain feature, identified by $featureName |
120
|
|
|
* should be activated, FALSE for backwards-compatible behavior. |
121
|
|
|
* |
122
|
|
|
* This is an INTERNAL API used throughout Extbase and Fluid for providing backwards-compatibility. |
123
|
|
|
* Do not use it in your custom code! |
124
|
|
|
* |
125
|
|
|
* @param string $featureName |
126
|
|
|
* @return bool |
127
|
|
|
*/ |
128
|
|
|
public function isFeatureEnabled(string $featureName): bool |
129
|
|
|
{ |
130
|
|
|
$configuration = $this->getConfiguration(self::CONFIGURATION_TYPE_FRAMEWORK); |
131
|
|
|
return (bool)(isset($configuration['features'][$featureName]) && $configuration['features'][$featureName]); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|