‪TYPO3CMS  10.4
ConfigurationManager.php
Go to the documentation of this file.
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 
19 
24 use ‪TYPO3\CMS\Extbase\Configuration\ConfigurationManager as ExtbaseConfigurationManager;
26 
33 class ‪ConfigurationManager extends ExtbaseConfigurationManager implements ‪ConfigurationManagerInterface
34 {
35 
39  protected ‪$cache;
40 
44  protected ‪$yamlSource;
45 
51  {
52  $this->yamlSource = ‪$yamlSource;
53  }
54 
62  public function ‪getConfiguration(string $configurationType, string $extensionName = null, string $pluginName = null): array
63  {
64  switch ($configurationType) {
66  return $this->‪getConfigurationFromYamlFile($extensionName);
67  default:
68  return parent::getConfiguration($configurationType, $extensionName, $pluginName);
69  }
70  }
71 
90  protected function ‪getConfigurationFromYamlFile(string $extensionName): array
91  {
92  if (empty($extensionName)) {
94  'Please specify an extension key to load a YAML configuration',
95  1471473377
96  );
97  }
98  $ucFirstExtensionName = ucfirst($extensionName);
99 
100  $typoscriptSettings = $this->‪getTypoScriptSettings($extensionName);
101 
102  $yamlSettingsFilePaths = isset($typoscriptSettings['yamlConfigurations'])
103  ? ‪ArrayUtility::sortArrayWithIntegerKeys($typoscriptSettings['yamlConfigurations'])
104  : [];
105 
106  $cacheKeySuffix = $extensionName . md5(json_encode($yamlSettingsFilePaths));
107 
108  $yamlSettings = $this->‪getYamlSettingsFromCache($cacheKeySuffix);
109  if (!empty($yamlSettings)) {
110  return $this->‪overrideConfigurationByTypoScript($yamlSettings, $extensionName);
111  }
112 
113  $yamlSettings = ‪InheritancesResolverService::create($this->yamlSource->load($yamlSettingsFilePaths))
115 
116  $yamlSettings = ‪ArrayUtility::removeNullValuesRecursive($yamlSettings);
117  $yamlSettings = is_array($yamlSettings['TYPO3']['CMS'][$ucFirstExtensionName])
118  ? $yamlSettings['TYPO3']['CMS'][$ucFirstExtensionName]
119  : [];
120  $yamlSettings = ‪ArrayUtility::sortArrayWithIntegerKeysRecursive($yamlSettings);
121  $this->‪setYamlSettingsIntoCache($cacheKeySuffix, $yamlSettings);
122 
123  return $this->‪overrideConfigurationByTypoScript($yamlSettings, $extensionName);
124  }
125 
131  protected function ‪overrideConfigurationByTypoScript(array $yamlSettings, string $extensionName): array
132  {
133  $typoScript = parent::getConfiguration(self::CONFIGURATION_TYPE_SETTINGS, $extensionName);
134  if (is_array($typoScript['yamlSettingsOverrides'] ?? null) && !empty($typoScript['yamlSettingsOverrides'])) {
135  $yamlSettingsOverrides = $typoScript['yamlSettingsOverrides'];
136  if ($this->environmentService->isEnvironmentInFrontendMode()) {
137  $yamlSettingsOverrides = $this->objectManager->get(TypoScriptService::class)
138  ->resolvePossibleTypoScriptConfiguration($yamlSettingsOverrides);
139  }
140 
142  $yamlSettings,
143  $yamlSettingsOverrides
144  );
145  }
146  return $yamlSettings;
147  }
148 
152  protected function ‪getCacheFrontend(): ‪FrontendInterface
153  {
154  if ($this->cache === null) {
155  $this->cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('assets');
156  }
157  return ‪$this->cache;
158  }
159 
164  protected function ‪getConfigurationCacheKey(string $cacheKeySuffix): string
165  {
166  return strtolower(self::CONFIGURATION_TYPE_YAML_SETTINGS . '_' . $cacheKeySuffix);
167  }
168 
173  protected function ‪getYamlSettingsFromCache(string $cacheKeySuffix)
174  {
175  return $this->‪getCacheFrontend()->‪get(
176  $this->‪getConfigurationCacheKey($cacheKeySuffix)
177  );
178  }
179 
184  protected function ‪setYamlSettingsIntoCache(
185  string $cacheKeySuffix,
186  array $yamlSettings
187  ) {
188  $this->‪getCacheFrontend()->‪set(
189  $this->‪getConfigurationCacheKey($cacheKeySuffix),
190  $yamlSettings
191  );
192  }
193 
198  protected function ‪getTypoScriptSettings(string $extensionName)
199  {
200  return parent::getConfiguration(
202  $extensionName
203  );
204  }
205 }
‪TYPO3\CMS\Form\Mvc\Configuration
Definition: ConfigurationManager.php:18
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager\getCacheFrontend
‪TYPO3 CMS Core Cache Frontend FrontendInterface getCacheFrontend()
Definition: ConfigurationManager.php:150
‪TYPO3\CMS\Form\Mvc\Configuration\Exception\ExtensionNameRequiredException
Definition: ExtensionNameRequiredException.php:29
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager\overrideConfigurationByTypoScript
‪array overrideConfigurationByTypoScript(array $yamlSettings, string $extensionName)
Definition: ConfigurationManager.php:129
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:654
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager\getConfigurationCacheKey
‪string getConfigurationCacheKey(string $cacheKeySuffix)
Definition: ConfigurationManager.php:162
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManager
Definition: ConfigurationManager.php:33
‪TYPO3\CMS\Form\Mvc\Configuration\InheritancesResolverService\getResolvedConfiguration
‪array getResolvedConfiguration()
Definition: InheritancesResolverService.php:147
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface\get
‪mixed get($entryIdentifier)
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager\getConfigurationFromYamlFile
‪array getConfigurationFromYamlFile(string $extensionName)
Definition: ConfigurationManager.php:88
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager\getTypoScriptSettings
‪array getTypoScriptSettings(string $extensionName)
Definition: ConfigurationManager.php:196
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager\$yamlSource
‪TYPO3 CMS Form Mvc Configuration YamlSource $yamlSource
Definition: ConfigurationManager.php:42
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:35
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager\getConfiguration
‪array getConfiguration(string $configurationType, string $extensionName=null, string $pluginName=null)
Definition: ConfigurationManager.php:60
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager\setYamlSettingsIntoCache
‪setYamlSettingsIntoCache(string $cacheKeySuffix, array $yamlSettings)
Definition: ConfigurationManager.php:182
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface\CONFIGURATION_TYPE_SETTINGS
‪const CONFIGURATION_TYPE_SETTINGS
Definition: ConfigurationManagerInterface.php:30
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager\getYamlSettingsFromCache
‪mixed getYamlSettingsFromCache(string $cacheKeySuffix)
Definition: ConfigurationManager.php:171
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪TYPO3\CMS\Form\Mvc\Configuration\YamlSource
Definition: YamlSource.php:44
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager\$cache
‪TYPO3 CMS Core Cache Frontend FrontendInterface $cache
Definition: ConfigurationManager.php:38
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪TYPO3\CMS\Form\Mvc\Configuration\InheritancesResolverService\create
‪static InheritancesResolverService create(array $configuration=[])
Definition: InheritancesResolverService.php:102
‪TYPO3\CMS\Core\Utility\ArrayUtility\removeNullValuesRecursive
‪static array removeNullValuesRecursive(array $array)
Definition: ArrayUtility.php:233
‪TYPO3\CMS\Core\Utility\ArrayUtility\sortArrayWithIntegerKeysRecursive
‪static array sortArrayWithIntegerKeysRecursive(array $array)
Definition: ArrayUtility.php:880
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManagerInterface\CONFIGURATION_TYPE_YAML_SETTINGS
‪const CONFIGURATION_TYPE_YAML_SETTINGS
Definition: ConfigurationManagerInterface.php:30
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface\set
‪set($entryIdentifier, $data, array $tags=[], $lifetime=null)
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Utility\ArrayUtility\sortArrayWithIntegerKeys
‪static array sortArrayWithIntegerKeys(array $array)
Definition: ArrayUtility.php:865
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager\injectYamlSource
‪injectYamlSource(YamlSource $yamlSource)
Definition: ConfigurationManager.php:48
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager
Definition: ConfigurationManager.php:34
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:29