‪TYPO3CMS  9.5
ConfigurationManager.php
Go to the documentation of this file.
1 <?php
2 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 
22 use ‪TYPO3\CMS\Extbase\Configuration\ConfigurationManager as ExtbaseConfigurationManager;
24 
31 class ‪ConfigurationManager extends ExtbaseConfigurationManager implements ‪ConfigurationManagerInterface
32 {
33 
37  protected ‪$cache;
38 
42  protected ‪$yamlSource;
43 
48  public function ‪injectYamlSource(\‪TYPO3\CMS\Form\Mvc\Configuration\‪YamlSource ‪$yamlSource)
49  {
50  $this->yamlSource = ‪$yamlSource;
51  }
52 
60  public function ‪getConfiguration($configurationType, $extensionName = null, $pluginName = null)
61  {
62  switch ($configurationType) {
64  return $this->‪getConfigurationFromYamlFile($extensionName);
65  default:
66  return parent::getConfiguration($configurationType, $extensionName, $pluginName);
67  }
68  }
69 
88  protected function ‪getConfigurationFromYamlFile(string $extensionName): array
89  {
90  if (empty($extensionName)) {
92  'Please specify an extension key to load a YAML configuration',
93  1471473377
94  );
95  }
96  $ucFirstExtensioName = ucfirst($extensionName);
97 
98  $typoscriptSettings = $this->‪getTypoScriptSettings($extensionName);
99 
100  $yamlSettingsFilePaths = isset($typoscriptSettings['yamlConfigurations'])
101  ? ‪ArrayUtility::sortArrayWithIntegerKeys($typoscriptSettings['yamlConfigurations'])
102  : [];
103 
104  $cacheKeySuffix = $extensionName . md5(json_encode($yamlSettingsFilePaths));
105 
106  $yamlSettings = $this->‪getYamlSettingsFromCache($cacheKeySuffix);
107  if (!empty($yamlSettings)) {
108  return $this->‪overrideConfigurationByTypoScript($yamlSettings, $extensionName);
109  }
110 
111  $yamlSettings = ‪InheritancesResolverService::create($this->yamlSource->load($yamlSettingsFilePaths))
113 
114  $yamlSettings = ‪ArrayUtility::removeNullValuesRecursive($yamlSettings);
115  $yamlSettings = is_array($yamlSettings['TYPO3']['CMS'][$ucFirstExtensioName])
116  ? $yamlSettings['TYPO3']['CMS'][$ucFirstExtensioName]
117  : [];
118  $yamlSettings = ‪ArrayUtility::sortArrayWithIntegerKeysRecursive($yamlSettings);
119  $this->‪setYamlSettingsIntoCache($cacheKeySuffix, $yamlSettings);
120 
121  return $this->‪overrideConfigurationByTypoScript($yamlSettings, $extensionName);
122  }
123 
129  protected function ‪overrideConfigurationByTypoScript(array $yamlSettings, string $extensionName): array
130  {
131  $typoScript = parent::getConfiguration(self::CONFIGURATION_TYPE_SETTINGS, $extensionName);
132  if (is_array($typoScript['yamlSettingsOverrides']) && !empty($typoScript['yamlSettingsOverrides'])) {
134  $yamlSettings,
135  $typoScript['yamlSettingsOverrides']
136  );
137 
138  if ($this->environmentService->isEnvironmentInFrontendMode()) {
139  $yamlSettings = $this->objectManager->get(TypoScriptService::class)
140  ->resolvePossibleTypoScriptConfiguration($yamlSettings);
141  }
142  }
143  return $yamlSettings;
144  }
145 
149  protected function ‪getCacheFrontend(): ‪FrontendInterface
150  {
151  if ($this->cache === null) {
152  $this->cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('assets');
153  }
154  return ‪$this->cache;
155  }
156 
161  protected function ‪getConfigurationCacheKey(string $cacheKeySuffix): string
162  {
163  return strtolower(self::CONFIGURATION_TYPE_YAML_SETTINGS . '_' . $cacheKeySuffix);
164  }
165 
170  protected function ‪getYamlSettingsFromCache(string $cacheKeySuffix)
171  {
172  return $this->‪getCacheFrontend()->‪get(
173  $this->‪getConfigurationCacheKey($cacheKeySuffix)
174  );
175  }
176 
181  protected function ‪setYamlSettingsIntoCache(
182  string $cacheKeySuffix,
183  array $yamlSettings
184  ) {
185  $this->‪getCacheFrontend()->‪set(
186  $this->‪getConfigurationCacheKey($cacheKeySuffix),
187  $yamlSettings
188  );
189  }
190 
195  protected function ‪getTypoScriptSettings(string $extensionName)
196  {
197  return parent::getConfiguration(
199  $extensionName
200  );
201  }
202 }
‪TYPO3\CMS\Form\Mvc\Configuration
Definition: ConfigurationManager.php:3
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager\getCacheFrontend
‪TYPO3 CMS Core Cache Frontend FrontendInterface getCacheFrontend()
Definition: ConfigurationManager.php:147
‪TYPO3
‪TYPO3\CMS\Form\Mvc\Configuration\Exception\ExtensionNameRequiredException
Definition: ExtensionNameRequiredException.php:27
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager\overrideConfigurationByTypoScript
‪array overrideConfigurationByTypoScript(array $yamlSettings, string $extensionName)
Definition: ConfigurationManager.php:127
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:614
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager\getConfigurationCacheKey
‪string getConfigurationCacheKey(string $cacheKeySuffix)
Definition: ConfigurationManager.php:159
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManager
Definition: ConfigurationManager.php:25
‪TYPO3\CMS\Form\Mvc\Configuration\InheritancesResolverService\getResolvedConfiguration
‪array getResolvedConfiguration()
Definition: InheritancesResolverService.php:144
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface\get
‪mixed get($entryIdentifier)
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager\getConfigurationFromYamlFile
‪array getConfigurationFromYamlFile(string $extensionName)
Definition: ConfigurationManager.php:86
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager\$yamlSource
‪TYPO3 CMS Form Mvc Configuration YamlSource $yamlSource
Definition: ConfigurationManager.php:40
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:34
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager\setYamlSettingsIntoCache
‪setYamlSettingsIntoCache(string $cacheKeySuffix, array $yamlSettings)
Definition: ConfigurationManager.php:179
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface\CONFIGURATION_TYPE_SETTINGS
‪const CONFIGURATION_TYPE_SETTINGS
Definition: ConfigurationManagerInterface.php:24
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager\getYamlSettingsFromCache
‪mixed getYamlSettingsFromCache(string $cacheKeySuffix)
Definition: ConfigurationManager.php:168
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:21
‪TYPO3\CMS\Form\Mvc\Configuration\YamlSource
Definition: YamlSource.php:39
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager\getConfiguration
‪array getConfiguration($configurationType, $extensionName=null, $pluginName=null)
Definition: ConfigurationManager.php:58
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager\$cache
‪TYPO3 CMS Core Cache Frontend FrontendInterface $cache
Definition: ConfigurationManager.php:36
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager\injectYamlSource
‪injectYamlSource(\TYPO3\CMS\Form\Mvc\Configuration\YamlSource $yamlSource)
Definition: ConfigurationManager.php:46
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:23
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager\getTypoScriptSettings
‪null[] getTypoScriptSettings(string $extensionName)
Definition: ConfigurationManager.php:193
‪TYPO3\CMS\Form\Mvc\Configuration\InheritancesResolverService\create
‪static InheritancesResolverService create(array $configuration=[])
Definition: InheritancesResolverService.php:99
‪TYPO3\CMS\Core\Utility\ArrayUtility\removeNullValuesRecursive
‪static array removeNullValuesRecursive(array $array)
Definition: ArrayUtility.php:232
‪TYPO3\CMS\Core\Utility\ArrayUtility\sortArrayWithIntegerKeysRecursive
‪static array sortArrayWithIntegerKeysRecursive(array $array)
Definition: ArrayUtility.php:808
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManagerInterface\CONFIGURATION_TYPE_YAML_SETTINGS
‪const CONFIGURATION_TYPE_YAML_SETTINGS
Definition: ConfigurationManagerInterface.php:28
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface\set
‪set($entryIdentifier, $data, array $tags=[], $lifetime=null)
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Utility\ArrayUtility\sortArrayWithIntegerKeys
‪static array sortArrayWithIntegerKeys(array $array)
Definition: ArrayUtility.php:793
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManager
Definition: ConfigurationManager.php:32
‪TYPO3\CMS\Form\Mvc\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:27