TYPO3 CMS  TYPO3_6-2
AbstractConfigurationManager.php
Go to the documentation of this file.
1 <?php
3 
20 
25 
31  protected $configuration = array();
32 
36  protected $contentObject;
37 
42  protected $objectManager;
43 
48  protected $typoScriptService;
49 
55  protected $extensionName;
56 
62  protected $pluginName;
63 
69  protected $configurationCache = array();
70 
76 
81  public function setContentObject(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject = NULL) {
82  $this->contentObject = $contentObject;
83  }
84 
88  public function getContentObject() {
89  if ($this->contentObject !== NULL) {
90  return $this->contentObject;
91  }
92  return NULL;
93  }
94 
102  public function setConfiguration(array $configuration = array()) {
103  // reset 1st level cache
104  $this->configurationCache = array();
105  $this->extensionName = isset($configuration['extensionName']) ? $configuration['extensionName'] : NULL;
106  $this->pluginName = isset($configuration['pluginName']) ? $configuration['pluginName'] : NULL;
107  $this->configuration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($configuration);
108  }
109 
120  public function getConfiguration($extensionName = NULL, $pluginName = NULL) {
121  // 1st level cache
122  $configurationCacheKey = strtolower(($extensionName ?: $this->extensionName) . '_' . ($pluginName ?: $this->pluginName));
123  if (isset($this->configurationCache[$configurationCacheKey])) {
124  return $this->configurationCache[$configurationCacheKey];
125  }
126  $frameworkConfiguration = $this->getExtbaseConfiguration();
127  if (!isset($frameworkConfiguration['persistence']['storagePid'])) {
128  $frameworkConfiguration['persistence']['storagePid'] = $this->getDefaultBackendStoragePid();
129  }
130  // only merge $this->configuration and override switchableControllerActions when retrieving configuration of the current plugin
131  if ($extensionName === NULL || $extensionName === $this->extensionName && $pluginName === $this->pluginName) {
132  $pluginConfiguration = $this->getPluginConfiguration($this->extensionName, $this->pluginName);
133  \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($pluginConfiguration, $this->configuration);
134  $pluginConfiguration['controllerConfiguration'] = $this->getSwitchableControllerActions($this->extensionName, $this->pluginName);
135  if (isset($this->configuration['switchableControllerActions'])) {
136  $this->overrideSwitchableControllerActions($pluginConfiguration, $this->configuration['switchableControllerActions']);
137  }
138  } else {
139  $pluginConfiguration = $this->getPluginConfiguration($extensionName, $pluginName);
140  $pluginConfiguration['controllerConfiguration'] = $this->getSwitchableControllerActions($extensionName, $pluginName);
141  }
142  \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($frameworkConfiguration, $pluginConfiguration);
143  // only load context specific configuration when retrieving configuration of the current plugin
144  if ($extensionName === NULL || $extensionName === $this->extensionName && $pluginName === $this->pluginName) {
145  $frameworkConfiguration = $this->getContextSpecificFrameworkConfiguration($frameworkConfiguration);
146  }
147 
148  if (!empty($frameworkConfiguration['persistence']['storagePid'])) {
149  if (is_array($frameworkConfiguration['persistence']['storagePid'])) {
155  if (!$this->environmentService->isEnvironmentInFrontendMode()) {
157  }
158  $conf = $this->typoScriptService->convertPlainArrayToTypoScriptArray($frameworkConfiguration['persistence']);
159  $frameworkConfiguration['persistence']['storagePid'] = $GLOBALS['TSFE']->cObj->stdWrap($conf['storagePid'], $conf['storagePid.']);
160  if (!$this->environmentService->isEnvironmentInFrontendMode()) {
162  }
163  }
164 
165  if (!empty($frameworkConfiguration['persistence']['recursive'])) {
166  // All implementations of getTreeList allow to pass the ids negative to include them into the result
167  // otherwise only childpages are returned
168  $storagePids = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $frameworkConfiguration['persistence']['storagePid']);
169  array_walk($storagePids, function (&$storagePid) {
170  if ($storagePid > 0) {
171  $storagePid = -$storagePid;
172  }
173  });
174  $frameworkConfiguration['persistence']['storagePid'] = $this->getRecursiveStoragePids(
175  implode(',', $storagePids),
176  (int)$frameworkConfiguration['persistence']['recursive']
177  );
178  }
179  }
180  // 1st level cache
181  $this->configurationCache[$configurationCacheKey] = $frameworkConfiguration;
182  return $frameworkConfiguration;
183  }
184 
190  protected function getExtbaseConfiguration() {
191  $setup = $this->getTypoScriptSetup();
192  $extbaseConfiguration = array();
193  if (isset($setup['config.']['tx_extbase.'])) {
194  $extbaseConfiguration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($setup['config.']['tx_extbase.']);
195  }
196  return $extbaseConfiguration;
197  }
198 
204  public function getDefaultBackendStoragePid() {
205  return self::DEFAULT_BACKEND_STORAGE_PID;
206  }
207 
213  protected function overrideSwitchableControllerActions(array &$frameworkConfiguration, array $switchableControllerActions) {
214  $overriddenSwitchableControllerActions = array();
215  foreach ($switchableControllerActions as $controllerName => $actions) {
216  if (!isset($frameworkConfiguration['controllerConfiguration'][$controllerName])) {
217  continue;
218  }
219  $overriddenSwitchableControllerActions[$controllerName] = array('actions' => $actions);
220  $nonCacheableActions = $frameworkConfiguration['controllerConfiguration'][$controllerName]['nonCacheableActions'];
221  if (!is_array($nonCacheableActions)) {
222  // There are no non-cacheable actions, thus we can directly continue
223  // with the next controller name.
224  continue;
225  }
226  $overriddenNonCacheableActions = array_intersect($nonCacheableActions, $actions);
227  if (!empty($overriddenNonCacheableActions)) {
228  $overriddenSwitchableControllerActions[$controllerName]['nonCacheableActions'] = $overriddenNonCacheableActions;
229  }
230  }
231  $frameworkConfiguration['controllerConfiguration'] = $overriddenSwitchableControllerActions;
232  }
233 
245  abstract protected function getContextSpecificFrameworkConfiguration(array $frameworkConfiguration);
246 
252  abstract public function getTypoScriptSetup();
253 
262  abstract protected function getPluginConfiguration($extensionName, $pluginName = NULL);
263 
275  abstract protected function getSwitchableControllerActions($extensionName, $pluginName);
276 
285  abstract protected function getRecursiveStoragePids($storagePid, $recursionDepth = 0);
286 
287 }
static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=TRUE, $includeEmptyValues=TRUE, $enableUnsetFeature=TRUE)
getContextSpecificFrameworkConfiguration(array $frameworkConfiguration)
static simulateFrontendEnvironment(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj=NULL)
static intExplode($delimiter, $string, $removeEmptyValues=FALSE, $limit=0)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
getPluginConfiguration($extensionName, $pluginName=NULL)
overrideSwitchableControllerActions(array &$frameworkConfiguration, array $switchableControllerActions)
setContentObject(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject=NULL)