‪TYPO3CMS  10.4
AbstractConfigurationManager.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 
28 
34 {
39 
45  protected ‪$configuration = [];
46 
50  protected ‪$contentObject;
51 
55  protected ‪$objectManager;
56 
60  protected ‪$typoScriptService;
61 
67  protected ‪$extensionName;
68 
74  protected ‪$pluginName;
75 
81  protected ‪$configurationCache = [];
82 
86  protected ‪$environmentService;
87 
93  public function ‪__construct(
97  ) {
98  $this->objectManager = ‪$objectManager;
99  $this->typoScriptService = ‪$typoScriptService;
100  $this->environmentService = ‪$environmentService;
101  }
102 
107  {
108  $this->contentObject = ‪$contentObject;
109  }
110 
115  {
117  }
118 
125  public function ‪setConfiguration(array ‪$configuration = []): void
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(?string ‪$extensionName = null, ?string ‪$pluginName = null): array
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 controller configuration when retrieving configuration of the current plugin
156  if ($extensionName === null || ‪$extensionName === $this->extensionName && ‪$pluginName === $this->pluginName) {
157  $pluginConfiguration = $this->‪getPluginConfiguration((string)$this->extensionName, (string)$this->pluginName);
158  ‪ArrayUtility::mergeRecursiveWithOverrule($pluginConfiguration, $this->configuration);
159  $pluginConfiguration['controllerConfiguration'] = $this->‪getControllerConfiguration((string)$this->extensionName, (string)$this->pluginName);
160  if (isset($this->configuration['switchableControllerActions'])) {
161  $this->‪overrideControllerConfigurationWithSwitchableControllerActions($pluginConfiguration, $this->configuration['switchableControllerActions']);
162  }
163  } else {
164  $pluginConfiguration = $this->‪getPluginConfiguration((string)$extensionName, (string)‪$pluginName);
165  $pluginConfiguration['controllerConfiguration'] = $this->‪getControllerConfiguration((string)$extensionName, (string)‪$pluginName);
166  }
167  ‪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 = ‪GeneralUtility::intExplode(',', $frameworkConfiguration['persistence']['storagePid']);
192  array_walk($storagePids, function (&$storagePid) {
193  if ($storagePid > 0) {
194  $storagePid = -$storagePid;
195  }
196  });
197  $storagePids = $this->‪getRecursiveStoragePids(
198  $storagePids,
199  (int)$frameworkConfiguration['persistence']['recursive']
200  );
201 
202  $frameworkConfiguration['persistence']['storagePid'] = implode(',', $storagePids);
203  }
204  }
205  // 1st level cache
206  $this->configurationCache[$configurationCacheKey] = $frameworkConfiguration;
207  return $frameworkConfiguration;
208  }
209 
215  protected function ‪getExtbaseConfiguration(): array
216  {
217  $setup = $this->‪getTypoScriptSetup();
218  $extbaseConfiguration = [];
219  if (isset($setup['config.']['tx_extbase.'])) {
220  $extbaseConfiguration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($setup['config.']['tx_extbase.']);
221  }
222  return $extbaseConfiguration;
223  }
224 
230  public function ‪getDefaultBackendStoragePid(): int
231  {
233  }
234 
256  protected function ‪overrideControllerConfigurationWithSwitchableControllerActions(array &$frameworkConfiguration, array $switchableControllerActions): void
257  {
258  trigger_error(
259  sprintf(
260  'Plugin "%s" of extension "%s" uses switchable controller actions which has been marked as deprecated as of version TYPO3 10 and will be removed in one of the next major versions of TYPO3, probably version 11.0 or 12.0',
261  $frameworkConfiguration['pluginName'],
262  $frameworkConfiguration['extensionName']
263  ),
264  E_USER_DEPRECATED
265  );
266 
267  $controllerAliasToClass = [];
268  foreach ($frameworkConfiguration['controllerConfiguration'] as $controllerClass => $controllerConfiguration) {
269  $controllerAliasToClass[$controllerConfiguration['alias']] = $controllerClass;
270  }
271 
272  $overriddenControllerConfiguration = [];
273  foreach ($switchableControllerActions as $controllerName => $actions) {
274  // Trim leading backslashes if a fully qualified controller class name with leading slashes is used.
275  $controllerName = ltrim($controllerName, '\\');
276 
277  $controllerIsConfigured = false;
278  if (array_key_exists($controllerName, $controllerAliasToClass)) {
279  /*
280  * If $controllerName can be found in the keys of $controllerAliasToClass, $controllerName is a
281  * controller alias and not a FQCN. In this case switchable controller actions have been defined with
282  * controller aliases as such:
283  *
284  * tt_content.list.20.indexedsearch_pi2.switchableControllerActions {
285  * Search {
286  * 0 = search
287  * }
288  * }
289  */
290  $controllerIsConfigured = true;
291  $controllerClassName = $controllerAliasToClass[$controllerName];
292  $controllerAlias = $controllerName;
293  }
294 
295  if (in_array($controllerName, $controllerAliasToClass, true)) {
296  /*
297  * If $controllerName can be found in the values of $controllerAliasToClass, $controllerName is a
298  * FQCN. In this case switchable controller actions have been defined with fully qualified controller
299  * class names as such:
300  *
301  * tt_content.list.20.indexedsearch_pi2.switchableControllerActions {
302  * TYPO3\CMS\IndexedSearch\Controller\SearchController {
303  * 0 = search
304  * }
305  * }
306  */
307  $controllerIsConfigured = true;
308  $controllerClassName = $controllerName;
309  $controllerAlias = $frameworkConfiguration['controllerConfiguration'][$controllerName]['alias'];
310  }
311 
312  if (!$controllerIsConfigured) {
313  continue;
314  }
315 
316  if (!isset($overriddenControllerConfiguration[$controllerClassName])) {
317  $overriddenControllerConfiguration[$controllerClassName] = [
318  'alias' => $controllerAlias,
319  'className' => $controllerClassName,
320  'actions' => []
321  ];
322  }
323  $overriddenControllerConfiguration[$controllerClassName]['actions'] = array_merge(
324  $overriddenControllerConfiguration[$controllerClassName]['actions'],
325  $actions
326  );
327  $nonCacheableActions = $frameworkConfiguration['controllerConfiguration'][$controllerClassName]['nonCacheableActions'] ?? null;
328  if (!is_array($nonCacheableActions)) {
329  // There are no non-cacheable actions, thus we can directly continue
330  // with the next controller name.
331  continue;
332  }
333  $overriddenNonCacheableActions = array_intersect($nonCacheableActions, $actions);
334  if (!empty($overriddenNonCacheableActions)) {
335  $overriddenControllerConfiguration[$controllerClassName]['nonCacheableActions'] = $overriddenNonCacheableActions;
336  }
337  }
338  $frameworkConfiguration['controllerConfiguration'] = $overriddenControllerConfiguration;
339  }
340 
352  abstract protected function ‪getContextSpecificFrameworkConfiguration(array $frameworkConfiguration): array;
353 
359  abstract public function ‪getTypoScriptSetup(): array;
360 
369  abstract protected function ‪getPluginConfiguration(string ‪$extensionName, string ‪$pluginName = null): array;
370 
382  abstract protected function ‪getControllerConfiguration(string ‪$extensionName, string ‪$pluginName): array;
383 
392  abstract protected function ‪getRecursiveStoragePids(array $storagePids, int $recursionDepth = 0): array;
393 }
‪TYPO3\CMS\Extbase\Utility\FrontendSimulatorUtility
Definition: FrontendSimulatorUtility.php:30
‪TYPO3\CMS\Extbase\Utility\FrontendSimulatorUtility\simulateFrontendEnvironment
‪static simulateFrontendEnvironment(ContentObjectRenderer $cObj=null)
Definition: FrontendSimulatorUtility.php:41
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$pluginName
‪string $pluginName
Definition: AbstractConfigurationManager.php:68
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\setContentObject
‪setContentObject(ContentObjectRenderer $contentObject)
Definition: AbstractConfigurationManager.php:98
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\getContentObject
‪TYPO3 CMS Frontend ContentObject ContentObjectRenderer null getContentObject()
Definition: AbstractConfigurationManager.php:106
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\getExtbaseConfiguration
‪array getExtbaseConfiguration()
Definition: AbstractConfigurationManager.php:207
‪TYPO3\CMS\Core\Utility\ArrayUtility\mergeRecursiveWithOverrule
‪static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
Definition: ArrayUtility.php:654
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager
Definition: AbstractConfigurationManager.php:34
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\getTypoScriptSetup
‪array getTypoScriptSetup()
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$environmentService
‪TYPO3 CMS Extbase Service EnvironmentService $environmentService
Definition: AbstractConfigurationManager.php:78
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\getConfiguration
‪array getConfiguration(?string $extensionName=null, ?string $pluginName=null)
Definition: AbstractConfigurationManager.php:136
‪TYPO3\CMS\Extbase\Object\ObjectManagerInterface
Definition: ObjectManagerInterface.php:26
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$typoScriptService
‪TYPO3 CMS Core TypoScript TypoScriptService $typoScriptService
Definition: AbstractConfigurationManager.php:56
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\getContextSpecificFrameworkConfiguration
‪array getContextSpecificFrameworkConfiguration(array $frameworkConfiguration)
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$configuration
‪array $configuration
Definition: AbstractConfigurationManager.php:44
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\getControllerConfiguration
‪array getControllerConfiguration(string $extensionName, string $pluginName)
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\getRecursiveStoragePids
‪array int[] getRecursiveStoragePids(array $storagePids, int $recursionDepth=0)
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$configurationCache
‪array $configurationCache
Definition: AbstractConfigurationManager.php:74
‪TYPO3\CMS\Extbase\Service\EnvironmentService
Definition: EnvironmentService.php:27
‪TYPO3\CMS\Extbase\Utility\FrontendSimulatorUtility\resetFrontendEnvironment
‪static resetFrontendEnvironment()
Definition: FrontendSimulatorUtility.php:54
‪TYPO3\CMS\Core\TypoScript\TypoScriptService
Definition: TypoScriptService.php:25
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$contentObject
‪TYPO3 CMS Frontend ContentObject ContentObjectRenderer $contentObject
Definition: AbstractConfigurationManager.php:48
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\__construct
‪__construct(ObjectManagerInterface $objectManager, TypoScriptService $typoScriptService, EnvironmentService $environmentService)
Definition: AbstractConfigurationManager.php:85
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:23
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility\intExplode
‪static int[] intExplode($delimiter, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:988
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:97
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\overrideControllerConfigurationWithSwitchableControllerActions
‪overrideControllerConfigurationWithSwitchableControllerActions(array &$frameworkConfiguration, array $switchableControllerActions)
Definition: AbstractConfigurationManager.php:248
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\getDefaultBackendStoragePid
‪int getDefaultBackendStoragePid()
Definition: AbstractConfigurationManager.php:222
‪TYPO3\CMS\Extbase\Configuration
Definition: AbstractConfigurationManager.php:18
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\getPluginConfiguration
‪array getPluginConfiguration(string $extensionName, string $pluginName=null)
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$extensionName
‪string $extensionName
Definition: AbstractConfigurationManager.php:62
‪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:38
‪TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager\$objectManager
‪TYPO3 CMS Extbase Object ObjectManagerInterface $objectManager
Definition: AbstractConfigurationManager.php:52