TYPO3 CMS  TYPO3_8-7
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 
21 {
26 
32  protected $configuration = [];
33 
37  protected $contentObject;
38 
42  protected $objectManager;
43 
47  protected $typoScriptService;
48 
54  protected $extensionName;
55 
61  protected $pluginName;
62 
68  protected $configurationCache = [];
69 
74 
78  public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
79  {
80  $this->objectManager = $objectManager;
81  }
82 
86  public function injectTypoScriptService(\TYPO3\CMS\Core\TypoScript\TypoScriptService $typoScriptService)
87  {
88  $this->typoScriptService = $typoScriptService;
89  }
90 
94  public function injectEnvironmentService(\TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService)
95  {
96  $this->environmentService = $environmentService;
97  }
98 
102  public function setContentObject(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject = null)
103  {
104  $this->contentObject = $contentObject;
105  }
106 
110  public function getContentObject()
111  {
112  if ($this->contentObject !== null) {
113  return $this->contentObject;
114  }
115  return null;
116  }
117 
124  public function setConfiguration(array $configuration = [])
125  {
126  // reset 1st level cache
127  $this->configurationCache = [];
128  $this->extensionName = isset($configuration['extensionName']) ? $configuration['extensionName'] : null;
129  $this->pluginName = isset($configuration['pluginName']) ? $configuration['pluginName'] : null;
130  $this->configuration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($configuration);
131  }
132 
143  public function getConfiguration($extensionName = null, $pluginName = null)
144  {
145  // 1st level cache
146  $configurationCacheKey = strtolower(($extensionName ?: $this->extensionName) . '_' . ($pluginName ?: $this->pluginName));
147  if (isset($this->configurationCache[$configurationCacheKey])) {
148  return $this->configurationCache[$configurationCacheKey];
149  }
150  $frameworkConfiguration = $this->getExtbaseConfiguration();
151  if (!isset($frameworkConfiguration['persistence']['storagePid'])) {
152  $frameworkConfiguration['persistence']['storagePid'] = $this->getDefaultBackendStoragePid();
153  }
154  // only merge $this->configuration and override switchableControllerActions when retrieving configuration of the current plugin
155  if ($extensionName === null || $extensionName === $this->extensionName && $pluginName === $this->pluginName) {
156  $pluginConfiguration = $this->getPluginConfiguration($this->extensionName, $this->pluginName);
157  \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($pluginConfiguration, $this->configuration);
158  $pluginConfiguration['controllerConfiguration'] = $this->getSwitchableControllerActions($this->extensionName, $this->pluginName);
159  if (isset($this->configuration['switchableControllerActions'])) {
160  $this->overrideSwitchableControllerActions($pluginConfiguration, $this->configuration['switchableControllerActions']);
161  }
162  } else {
163  $pluginConfiguration = $this->getPluginConfiguration($extensionName, $pluginName);
164  $pluginConfiguration['controllerConfiguration'] = $this->getSwitchableControllerActions($extensionName, $pluginName);
165  }
166  \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($frameworkConfiguration, $pluginConfiguration);
167  // only load context specific configuration when retrieving configuration of the current plugin
168  if ($extensionName === null || $extensionName === $this->extensionName && $pluginName === $this->pluginName) {
169  $frameworkConfiguration = $this->getContextSpecificFrameworkConfiguration($frameworkConfiguration);
170  }
171 
172  if (!empty($frameworkConfiguration['persistence']['storagePid'])) {
173  if (is_array($frameworkConfiguration['persistence']['storagePid'])) {
179  if (!$this->environmentService->isEnvironmentInFrontendMode()) {
181  }
182  $conf = $this->typoScriptService->convertPlainArrayToTypoScriptArray($frameworkConfiguration['persistence']);
183  $frameworkConfiguration['persistence']['storagePid'] = $GLOBALS['TSFE']->cObj->stdWrap($conf['storagePid'], $conf['storagePid.']);
184  if (!$this->environmentService->isEnvironmentInFrontendMode()) {
186  }
187  }
188 
189  if (!empty($frameworkConfiguration['persistence']['recursive'])) {
190  // All implementations of getTreeList allow to pass the ids negative to include them into the result
191  // otherwise only childpages are returned
192  $storagePids = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $frameworkConfiguration['persistence']['storagePid']);
193  array_walk($storagePids, function (&$storagePid) {
194  if ($storagePid > 0) {
195  $storagePid = -$storagePid;
196  }
197  });
198  $frameworkConfiguration['persistence']['storagePid'] = $this->getRecursiveStoragePids(
199  implode(',', $storagePids),
200  (int)$frameworkConfiguration['persistence']['recursive']
201  );
202  }
203  }
204  // 1st level cache
205  $this->configurationCache[$configurationCacheKey] = $frameworkConfiguration;
206  return $frameworkConfiguration;
207  }
208 
214  protected function getExtbaseConfiguration()
215  {
216  $setup = $this->getTypoScriptSetup();
217  $extbaseConfiguration = [];
218  if (isset($setup['config.']['tx_extbase.'])) {
219  $extbaseConfiguration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($setup['config.']['tx_extbase.']);
220  }
221  return $extbaseConfiguration;
222  }
223 
229  public function getDefaultBackendStoragePid()
230  {
231  return self::DEFAULT_BACKEND_STORAGE_PID;
232  }
233 
238  protected function overrideSwitchableControllerActions(array &$frameworkConfiguration, array $switchableControllerActions)
239  {
240  $overriddenSwitchableControllerActions = [];
241  foreach ($switchableControllerActions as $controllerName => $actions) {
242  if (!isset($frameworkConfiguration['controllerConfiguration'][$controllerName])) {
243  continue;
244  }
245  $overriddenSwitchableControllerActions[$controllerName] = ['actions' => $actions];
246  $nonCacheableActions = $frameworkConfiguration['controllerConfiguration'][$controllerName]['nonCacheableActions'];
247  if (!is_array($nonCacheableActions)) {
248  // There are no non-cacheable actions, thus we can directly continue
249  // with the next controller name.
250  continue;
251  }
252  $overriddenNonCacheableActions = array_intersect($nonCacheableActions, $actions);
253  if (!empty($overriddenNonCacheableActions)) {
254  $overriddenSwitchableControllerActions[$controllerName]['nonCacheableActions'] = $overriddenNonCacheableActions;
255  }
256  }
257  $frameworkConfiguration['controllerConfiguration'] = $overriddenSwitchableControllerActions;
258  }
259 
271  abstract protected function getContextSpecificFrameworkConfiguration(array $frameworkConfiguration);
272 
278  abstract public function getTypoScriptSetup();
279 
288  abstract protected function getPluginConfiguration($extensionName, $pluginName = null);
289 
301  abstract protected function getSwitchableControllerActions($extensionName, $pluginName);
302 
311  abstract protected function getRecursiveStoragePids($storagePid, $recursionDepth = 0);
312 }
static intExplode($delimiter, $string, $removeEmptyValues=false, $limit=0)
getPluginConfiguration($extensionName, $pluginName=null)
setContentObject(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject=null)
getContextSpecificFrameworkConfiguration(array $frameworkConfiguration)
injectTypoScriptService(\TYPO3\CMS\Core\TypoScript\TypoScriptService $typoScriptService)
static simulateFrontendEnvironment(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj=null)
injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
injectEnvironmentService(\TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
overrideSwitchableControllerActions(array &$frameworkConfiguration, array $switchableControllerActions)