TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
form/Classes/Mvc/Configuration/ConfigurationManager.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Form\Mvc\Configuration;
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 use TYPO3\CMS\Extbase\Configuration\ConfigurationManager as ExtbaseConfigurationManager;
21 
28 class ConfigurationManager extends ExtbaseConfigurationManager implements ConfigurationManagerInterface
29 {
33  protected $yamlSource;
34 
40  protected $configurationCache = [];
41 
46  public function injectYamlSource(\TYPO3\CMS\Form\Mvc\Configuration\YamlSource $yamlSource)
47  {
48  $this->yamlSource = $yamlSource;
49  }
50 
58  public function getConfiguration($configurationType, $extensionName = null, $pluginName = null)
59  {
60  switch ($configurationType) {
61  case self::CONFIGURATION_TYPE_YAML_SETTINGS:
62  return $this->getConfigurationFromYamlFile($extensionName);
63  default:
64  return parent::getConfiguration($configurationType, $extensionName, $pluginName);
65  }
66  }
67 
86  protected function getConfigurationFromYamlFile(string $extensionName): array
87  {
88  if (empty($extensionName)) {
90  'Please specify an extension key to load a YAML configuration',
91  1471473377
92  );
93  }
94  $ucFirstExtensioName = ucfirst($extensionName);
95 
96  // 1st level cache
97  $configurationCacheKey = strtolower(self::CONFIGURATION_TYPE_YAML_SETTINGS . '|' . $extensionName);
98  if (isset($this->configurationCache[$configurationCacheKey])) {
99  return $this->configurationCache[$configurationCacheKey];
100  }
101 
102  $typoscriptSettings = parent::getConfiguration(
104  $extensionName
105  );
106  $yamlSettingsFilePaths = isset($typoscriptSettings['yamlConfigurations'])
107  ? $typoscriptSettings['yamlConfigurations']
108  : [];
109  $yamlSettings = InheritancesResolverService::create($this->yamlSource->load($yamlSettingsFilePaths))
110  ->getResolvedConfiguration();
111 
112  $yamlSettings = ArrayUtility::removeNullValuesRecursive($yamlSettings);
113  $yamlSettings = is_array($yamlSettings['TYPO3']['CMS'][$ucFirstExtensioName])
114  ? $yamlSettings['TYPO3']['CMS'][$ucFirstExtensioName]
115  : [];
116  $yamlSettings = ArrayUtility::sortArrayWithIntegerKeysRecursive($yamlSettings);
117  $yamlSettings = $this->overrideConfigurationByTypoScript($yamlSettings, $extensionName);
118 
119  // 1st level cache
120  $this->configurationCache[$configurationCacheKey] = $yamlSettings;
121  return $yamlSettings;
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 }
getConfiguration($configurationType, $extensionName=null, $pluginName=null)
injectYamlSource(\TYPO3\CMS\Form\Mvc\Configuration\YamlSource $yamlSource)
static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)