TYPO3 CMS  TYPO3_7-6
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\Extbase\Service\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 
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) {
114  return $this->contentObject;
115  }
116  return null;
117  }
118 
126  public function setConfiguration(array $configuration = [])
127  {
128  // reset 1st level cache
129  $this->configurationCache = [];
130  $this->extensionName = isset($configuration['extensionName']) ? $configuration['extensionName'] : null;
131  $this->pluginName = isset($configuration['pluginName']) ? $configuration['pluginName'] : null;
132  $this->configuration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($configuration);
133  }
134 
145  public function getConfiguration($extensionName = null, $pluginName = null)
146  {
147  // 1st level cache
148  $configurationCacheKey = strtolower(($extensionName ?: $this->extensionName) . '_' . ($pluginName ?: $this->pluginName));
149  if (isset($this->configurationCache[$configurationCacheKey])) {
150  return $this->configurationCache[$configurationCacheKey];
151  }
152  $frameworkConfiguration = $this->getExtbaseConfiguration();
153  if (!isset($frameworkConfiguration['persistence']['storagePid'])) {
154  $frameworkConfiguration['persistence']['storagePid'] = $this->getDefaultBackendStoragePid();
155  }
156  // only merge $this->configuration and override switchableControllerActions when retrieving configuration of the current plugin
157  if ($extensionName === null || $extensionName === $this->extensionName && $pluginName === $this->pluginName) {
158  $pluginConfiguration = $this->getPluginConfiguration($this->extensionName, $this->pluginName);
159  \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($pluginConfiguration, $this->configuration);
160  $pluginConfiguration['controllerConfiguration'] = $this->getSwitchableControllerActions($this->extensionName, $this->pluginName);
161  if (isset($this->configuration['switchableControllerActions'])) {
162  $this->overrideSwitchableControllerActions($pluginConfiguration, $this->configuration['switchableControllerActions']);
163  }
164  } else {
165  $pluginConfiguration = $this->getPluginConfiguration($extensionName, $pluginName);
166  $pluginConfiguration['controllerConfiguration'] = $this->getSwitchableControllerActions($extensionName, $pluginName);
167  }
168  \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($frameworkConfiguration, $pluginConfiguration);
169  // only load context specific configuration when retrieving configuration of the current plugin
170  if ($extensionName === null || $extensionName === $this->extensionName && $pluginName === $this->pluginName) {
171  $frameworkConfiguration = $this->getContextSpecificFrameworkConfiguration($frameworkConfiguration);
172  }
173 
174  if (!empty($frameworkConfiguration['persistence']['storagePid'])) {
175  if (is_array($frameworkConfiguration['persistence']['storagePid'])) {
181  if (!$this->environmentService->isEnvironmentInFrontendMode()) {
183  }
184  $conf = $this->typoScriptService->convertPlainArrayToTypoScriptArray($frameworkConfiguration['persistence']);
185  $frameworkConfiguration['persistence']['storagePid'] = $GLOBALS['TSFE']->cObj->stdWrap($conf['storagePid'], $conf['storagePid.']);
186  if (!$this->environmentService->isEnvironmentInFrontendMode()) {
188  }
189  }
190 
191  if (!empty($frameworkConfiguration['persistence']['recursive'])) {
192  // All implementations of getTreeList allow to pass the ids negative to include them into the result
193  // otherwise only childpages are returned
194  $storagePids = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $frameworkConfiguration['persistence']['storagePid']);
195  array_walk($storagePids, function (&$storagePid) {
196  if ($storagePid > 0) {
197  $storagePid = -$storagePid;
198  }
199  });
200  $frameworkConfiguration['persistence']['storagePid'] = $this->getRecursiveStoragePids(
201  implode(',', $storagePids),
202  (int)$frameworkConfiguration['persistence']['recursive']
203  );
204  }
205  }
206  // 1st level cache
207  $this->configurationCache[$configurationCacheKey] = $frameworkConfiguration;
208  return $frameworkConfiguration;
209  }
210 
216  protected function getExtbaseConfiguration()
217  {
218  $setup = $this->getTypoScriptSetup();
219  $extbaseConfiguration = [];
220  if (isset($setup['config.']['tx_extbase.'])) {
221  $extbaseConfiguration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($setup['config.']['tx_extbase.']);
222  }
223  return $extbaseConfiguration;
224  }
225 
231  public function getDefaultBackendStoragePid()
232  {
233  return self::DEFAULT_BACKEND_STORAGE_PID;
234  }
235 
241  protected function overrideSwitchableControllerActions(array &$frameworkConfiguration, array $switchableControllerActions)
242  {
243  $overriddenSwitchableControllerActions = [];
244  foreach ($switchableControllerActions as $controllerName => $actions) {
245  if (!isset($frameworkConfiguration['controllerConfiguration'][$controllerName])) {
246  continue;
247  }
248  $overriddenSwitchableControllerActions[$controllerName] = ['actions' => $actions];
249  $nonCacheableActions = $frameworkConfiguration['controllerConfiguration'][$controllerName]['nonCacheableActions'];
250  if (!is_array($nonCacheableActions)) {
251  // There are no non-cacheable actions, thus we can directly continue
252  // with the next controller name.
253  continue;
254  }
255  $overriddenNonCacheableActions = array_intersect($nonCacheableActions, $actions);
256  if (!empty($overriddenNonCacheableActions)) {
257  $overriddenSwitchableControllerActions[$controllerName]['nonCacheableActions'] = $overriddenNonCacheableActions;
258  }
259  }
260  $frameworkConfiguration['controllerConfiguration'] = $overriddenSwitchableControllerActions;
261  }
262 
274  abstract protected function getContextSpecificFrameworkConfiguration(array $frameworkConfiguration);
275 
281  abstract public function getTypoScriptSetup();
282 
291  abstract protected function getPluginConfiguration($extensionName, $pluginName = null);
292 
304  abstract protected function getSwitchableControllerActions($extensionName, $pluginName);
305 
314  abstract protected function getRecursiveStoragePids($storagePid, $recursionDepth = 0);
315 }
static intExplode($delimiter, $string, $removeEmptyValues=false, $limit=0)
getPluginConfiguration($extensionName, $pluginName=null)
injectTypoScriptService(\TYPO3\CMS\Extbase\Service\TypoScriptService $typoScriptService)
setContentObject(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject=null)
getContextSpecificFrameworkConfiguration(array $frameworkConfiguration)
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)