‪TYPO3CMS  9.5
AbstractConfigurationManager.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
22 {
27 
33  protected ‪$configuration = [];
34 
38  protected ‪$contentObject;
39 
43  protected ‪$objectManager;
44 
48  protected ‪$typoScriptService;
49 
55  protected ‪$extensionName;
56 
62  protected ‪$pluginName;
63 
69  protected ‪$configurationCache = [];
70 
74  protected ‪$environmentService;
75 
79  public function ‪injectObjectManager(\‪TYPO3\CMS\‪Extbase\Object\ObjectManagerInterface ‪$objectManager)
80  {
81  $this->objectManager = ‪$objectManager;
82  }
83 
87  public function ‪injectTypoScriptService(\‪TYPO3\CMS\Core\TypoScript\TypoScriptService ‪$typoScriptService)
88  {
89  $this->typoScriptService = ‪$typoScriptService;
90  }
91 
95  public function ‪injectEnvironmentService(\‪TYPO3\CMS\‪Extbase\Service\EnvironmentService ‪$environmentService)
96  {
97  $this->environmentService = ‪$environmentService;
98  }
99 
103  public function ‪setContentObject(\‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer ‪$contentObject = null)
104  {
105  $this->contentObject = ‪$contentObject;
106  }
107 
111  public function ‪getContentObject()
112  {
113  if ($this->contentObject !== null) {
115  }
116  return null;
117  }
118 
125  public function ‪setConfiguration(array ‪$configuration = [])
126  {
127  // reset 1st level cache
128  $this->configurationCache = [];
129  $this->extensionName = ‪$configuration['extensionName'] ?? null;
130  $this->pluginName = ‪$configuration['pluginName'] ?? null;
131  $this->configuration = $this->typoScriptService->convertTypoScriptArrayToPlainArray(‪$configuration);
132  }
133 
144  public function ‪getConfiguration(‪$extensionName = null, ‪$pluginName = null)
145  {
146  // 1st level cache
147  $configurationCacheKey = strtolower((‪$extensionName ?: $this->extensionName) . '_' . (‪$pluginName ?: $this->pluginName));
148  if (isset($this->configurationCache[$configurationCacheKey])) {
149  return $this->configurationCache[$configurationCacheKey];
150  }
151  $frameworkConfiguration = $this->‪getExtbaseConfiguration();
152  if (!isset($frameworkConfiguration['persistence']['storagePid'])) {
153  $frameworkConfiguration['persistence']['storagePid'] = $this->‪getDefaultBackendStoragePid();
154  }
155  // only merge $this->configuration and override switchableControllerActions when retrieving configuration of the current plugin
156  if (‪$extensionName === null || ‪$extensionName === $this->extensionName && ‪$pluginName === $this->pluginName) {
157  $pluginConfiguration = $this->‪getPluginConfiguration($this->extensionName, $this->pluginName);
158  ‪\TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($pluginConfiguration, $this->configuration);
159  $pluginConfiguration['controllerConfiguration'] = $this->‪getSwitchableControllerActions($this->extensionName, $this->pluginName);
160  if (isset($this->configuration['switchableControllerActions'])) {
161  $this->‪overrideSwitchableControllerActions($pluginConfiguration, $this->configuration['switchableControllerActions']);
162  }
163  } else {
164  $pluginConfiguration = $this->‪getPluginConfiguration(‪$extensionName, ‪$pluginName);
165  $pluginConfiguration['controllerConfiguration'] = $this->‪getSwitchableControllerActions(‪$extensionName, ‪$pluginName);
166  }
167  ‪\TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($frameworkConfiguration, $pluginConfiguration);
168  // only load context specific configuration when retrieving configuration of the current plugin
169  if (‪$extensionName === null || ‪$extensionName === $this->extensionName && ‪$pluginName === $this->pluginName) {
170  $frameworkConfiguration = $this->‪getContextSpecificFrameworkConfiguration($frameworkConfiguration);
171  }
172 
173  if (!empty($frameworkConfiguration['persistence']['storagePid'])) {
174  if (is_array($frameworkConfiguration['persistence']['storagePid'])) {
175  // We simulate the frontend to enable the use of cObjects in
176  // stdWrap. Than we convert the configuration to normal TypoScript
177  // and apply the stdWrap to the storagePid
178  if (!$this->environmentService->isEnvironmentInFrontendMode()) {
180  }
181  $conf = $this->typoScriptService->convertPlainArrayToTypoScriptArray($frameworkConfiguration['persistence']);
182  $frameworkConfiguration['persistence']['storagePid'] = ‪$GLOBALS['TSFE']->cObj->stdWrap($conf['storagePid'], $conf['storagePid.']);
183  if (!$this->environmentService->isEnvironmentInFrontendMode()) {
185  }
186  }
187 
188  if (!empty($frameworkConfiguration['persistence']['recursive'])) {
189  // All implementations of getTreeList allow to pass the ids negative to include them into the result
190  // otherwise only childpages are returned
191  $storagePids = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $frameworkConfiguration['persistence']['storagePid']);
192  array_walk($storagePids, function (&$storagePid) {
193  if ($storagePid > 0) {
194  $storagePid = -$storagePid;
195  }
196  });
197  $frameworkConfiguration['persistence']['storagePid'] = $this->‪getRecursiveStoragePids(
198  implode(',', $storagePids),
199  (int)$frameworkConfiguration['persistence']['recursive']
200  );
201  }
202  }
203  // 1st level cache
204  $this->configurationCache[$configurationCacheKey] = $frameworkConfiguration;
205  return $frameworkConfiguration;
206  }
207 
213  protected function ‪getExtbaseConfiguration()
214  {
215  $setup = $this->‪getTypoScriptSetup();
216  $extbaseConfiguration = [];
217  if (isset($setup['config.']['tx_extbase.'])) {
218  $extbaseConfiguration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($setup['config.']['tx_extbase.']);
219  }
220  return $extbaseConfiguration;
221  }
222 
228  public function ‪getDefaultBackendStoragePid()
229  {
231  }
232 
237  protected function ‪overrideSwitchableControllerActions(array &$frameworkConfiguration, array $switchableControllerActions)
238  {
239  $overriddenSwitchableControllerActions = [];
240  foreach ($switchableControllerActions as $controllerName => $actions) {
241  if (!isset($frameworkConfiguration['controllerConfiguration'][$controllerName])) {
242  continue;
243  }
244  $overriddenSwitchableControllerActions[$controllerName] = ['actions' => $actions];
245  $nonCacheableActions = $frameworkConfiguration['controllerConfiguration'][$controllerName]['nonCacheableActions'] ?? null;
246  if (!is_array($nonCacheableActions)) {
247  // There are no non-cacheable actions, thus we can directly continue
248  // with the next controller name.
249  continue;
250  }
251  $overriddenNonCacheableActions = array_intersect($nonCacheableActions, $actions);
252  if (!empty($overriddenNonCacheableActions)) {
253  $overriddenSwitchableControllerActions[$controllerName]['nonCacheableActions'] = $overriddenNonCacheableActions;
254  }
255  }
256  $frameworkConfiguration['controllerConfiguration'] = $overriddenSwitchableControllerActions;
257  }
258 
270  abstract protected function ‪getContextSpecificFrameworkConfiguration(array $frameworkConfiguration);
271 
277  abstract public function ‪getTypoScriptSetup();
278 
287  abstract protected function ‪getPluginConfiguration(‪$extensionName, ‪$pluginName = null);
288 
301 
310  abstract protected function ‪getRecursiveStoragePids($storagePid, $recursionDepth = 0);
311 }
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$pluginName
‪string $pluginName
Definition: AbstractConfigurationManager.php:56
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\getRecursiveStoragePids
‪string getRecursiveStoragePids($storagePid, $recursionDepth=0)
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\getContentObject
‪TYPO3 CMS Frontend ContentObject ContentObjectRenderer null getContentObject()
Definition: AbstractConfigurationManager.php:103
‪TYPO3
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\getExtbaseConfiguration
‪array getExtbaseConfiguration()
Definition: AbstractConfigurationManager.php:205
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\setContentObject
‪setContentObject(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject=null)
Definition: AbstractConfigurationManager.php:95
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:614
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager
Definition: AbstractConfigurationManager.php:22
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\getPluginConfiguration
‪array getPluginConfiguration($extensionName, $pluginName=null)
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\getTypoScriptSetup
‪array getTypoScriptSetup()
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$environmentService
‪TYPO3 CMS Extbase Service EnvironmentService $environmentService
Definition: AbstractConfigurationManager.php:66
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\getDefaultBackendStoragePid
‪string getDefaultBackendStoragePid()
Definition: AbstractConfigurationManager.php:220
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$typoScriptService
‪TYPO3 CMS Core TypoScript TypoScriptService $typoScriptService
Definition: AbstractConfigurationManager.php:44
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\getContextSpecificFrameworkConfiguration
‪array getContextSpecificFrameworkConfiguration(array $frameworkConfiguration)
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\overrideSwitchableControllerActions
‪overrideSwitchableControllerActions(array &$frameworkConfiguration, array $switchableControllerActions)
Definition: AbstractConfigurationManager.php:229
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$configuration
‪array $configuration
Definition: AbstractConfigurationManager.php:32
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\injectTypoScriptService
‪injectTypoScriptService(\TYPO3\CMS\Core\TypoScript\TypoScriptService $typoScriptService)
Definition: AbstractConfigurationManager.php:79
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$configurationCache
‪array $configurationCache
Definition: AbstractConfigurationManager.php:62
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\injectObjectManager
‪injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
Definition: AbstractConfigurationManager.php:71
‪TYPO3\CMS\Extbase\Utility\FrontendSimulatorUtility\resetFrontendEnvironment
‪static resetFrontendEnvironment()
Definition: FrontendSimulatorUtility.php:47
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$contentObject
‪TYPO3 CMS Frontend ContentObject ContentObjectRenderer $contentObject
Definition: AbstractConfigurationManager.php:36
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\getSwitchableControllerActions
‪array getSwitchableControllerActions($extensionName, $pluginName)
‪TYPO3\CMS\Extbase\Configuration
Definition: AbstractConfigurationManager.php:2
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\getConfiguration
‪array getConfiguration($extensionName=null, $pluginName=null)
Definition: AbstractConfigurationManager.php:136
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\injectEnvironmentService
‪injectEnvironmentService(\TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService)
Definition: AbstractConfigurationManager.php:87
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$extensionName
‪string $extensionName
Definition: AbstractConfigurationManager.php:50
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\setConfiguration
‪setConfiguration(array $configuration=[])
Definition: AbstractConfigurationManager.php:117
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\DEFAULT_BACKEND_STORAGE_PID
‪const DEFAULT_BACKEND_STORAGE_PID
Definition: AbstractConfigurationManager.php:26
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$objectManager
‪TYPO3 CMS Extbase Object ObjectManagerInterface $objectManager
Definition: AbstractConfigurationManager.php:40
‪TYPO3\CMS\Extbase\Utility\FrontendSimulatorUtility\simulateFrontendEnvironment
‪static simulateFrontendEnvironment(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj=null)
Definition: FrontendSimulatorUtility.php:34