2 declare(strict_types = 1);
20 use TYPO3\CMS\Core\Package\PackageManager;
127 public function get(
string $extension,
string $path =
'')
129 $hasBeenSynchronized =
false;
130 if (!isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTENSIONS'][$extension]) || !is_array(
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTENSIONS'][$extension])) {
133 $hasBeenSynchronized =
true;
134 if (!isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTENSIONS'][$extension]) || !is_array(
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTENSIONS'][$extension])) {
137 'No extension configuration for extension ' . $extension .
' found. Either this extension'
138 .
' has no extension configuration or the configuration is not up to date. Execute the'
139 .
' install tool to update configuration.',
145 return $GLOBALS[
'TYPO3_CONF_VARS'][
'EXTENSIONS'][$extension];
149 if (!$hasBeenSynchronized) {
155 'Path ' . $path .
' does not exist in extension configuration',
194 public function set(
string $extension,
string $path =
'', $value =
null)
196 if (empty($extension)) {
197 throw new \RuntimeException(
'extension name must not be empty', 1509715852);
201 $extensionConfiguration = $this->
get($extension);
204 $configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
205 if ($value ===
null) {
207 $configurationManager->removeLocalConfigurationKeysByPath([
'EXTENSIONS/' . $extension]);
208 if (isset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTENSIONS'][$extension])) {
209 unset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTENSIONS'][$extension]);
213 $configurationManager->setLocalConfigurationValueByPath(
'EXTENSIONS/' . $extension, $value);
214 $GLOBALS[
'TYPO3_CONF_VARS'][
'EXTENSIONS'][$extension] = $value;
219 if (!empty(
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTENSIONS'])) {
221 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTENSIONS'] as $extensionName => $extensionConfig) {
224 $configurationManager->setLocalConfigurationValueByPath(
'EXT/extConf', $extConfArray);
225 $GLOBALS[
'TYPO3_CONF_VARS'][
'EXT'][
'extConf'] = $extConfArray;
237 public function setAll(array $configuration)
239 $configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
240 $configurationManager->setLocalConfigurationValueByPath(
'EXTENSIONS', $configuration);
241 $GLOBALS[
'TYPO3_CONF_VARS'][
'EXTENSIONS'] = $configuration;
246 foreach ($configuration as $extensionName => $extensionConfig) {
249 $configurationManager->setLocalConfigurationValueByPath(
'EXT/extConf', $extConfArray);
250 $GLOBALS[
'TYPO3_CONF_VARS'][
'EXT'][
'extConf'] = $extConfArray;
264 $activePackages = GeneralUtility::makeInstance(PackageManager::class)->getActivePackages();
265 $fullConfiguration = [];
266 $currentLocalConfiguration =
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTENSIONS'] ?? [];
267 foreach ($activePackages as $package) {
268 if (!@is_file($package->getPackagePath() .
'ext_conf_template.txt')) {
271 $extensionKey = $package->getPackageKey();
272 $currentExtensionConfig = $currentLocalConfiguration[$extensionKey] ?? [];
275 if (!empty($extConfTemplateConfiguration)) {
276 $fullConfiguration[$extensionKey] = $extConfTemplateConfiguration;
280 if ($fullConfiguration != $currentLocalConfiguration) {
281 $this->
setAll($fullConfiguration);
296 $package = GeneralUtility::makeInstance(PackageManager::class)->getPackage($extensionKey);
297 if (!@is_file($package->getPackagePath() .
'ext_conf_template.txt')) {
300 $currentLocalConfiguration =
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTENSIONS'][$extensionKey] ?? [];
304 if ($extConfTemplateConfiguration != $currentLocalConfiguration) {
305 $this->
set($extensionKey,
'', $extConfTemplateConfiguration);
338 foreach ($extensionConfig as $key => $value) {
339 if (is_array($value)) {
342 $newArray[$key] = $value;
376 if ((
string)$rawConfigurationString !==
'') {
377 $this->raw = explode(LF, $rawConfigurationString);
378 $this->rawPointer = 0;
381 if ($this->inBrace) {
382 throw new \RuntimeException(
383 'Line ' . ($this->rawPointer - 1) .
': The script is short of ' . $this->inBrace .
' end brace(s)',
389 return $configuration;
404 $extConfTemplateFileLocation = GeneralUtility::getFileAbsFileName(
405 'EXT:' . $extensionKey .
'/ext_conf_template.txt'
407 if (file_exists($extConfTemplateFileLocation)) {
408 $rawString = file_get_contents($extConfTemplateFileLocation);
442 foreach ($config as $key => $value) {
443 if (substr($key, -2) ===
'..') {
446 if (substr($key, -1) ===
'.') {
449 $cleanedConfig[$key] = $value;
452 return $cleanedConfig;
464 while (isset($this->raw[$this->rawPointer])) {
465 $line = ltrim($this->raw[$this->rawPointer]);
468 if (strpos($line,
'/*') === 0) {
469 $this->commentSet = 1;
471 if (!$this->commentSet && $line) {
472 if ($line[0] !==
'}' && $line[0] !==
'#' && $line[0] !==
'/') {
475 $varL = strcspn($line,
"\t" .
' {=<>(');
477 if ($varL > 0 && substr($line, $varL - 1, 2) ===
':=') {
481 $objStrName = substr($line, 0, $varL);
482 if ($objStrName !==
'') {
484 if (preg_match(
'/[^[:alnum:]_\\\\\\.:-]/i', $objStrName, $r)) {
485 throw new \RuntimeException(
486 'Line ' . ($this->rawPointer - 1) .
': Object Name String, "' . htmlspecialchars($objStrName) .
'" contains invalid character "' . $r[0] .
'". Must be alphanumeric or one of: "_:-\\."',
490 $line = ltrim(substr($line, $varL));
492 throw new \RuntimeException(
493 'Line ' . ($this->rawPointer - 1) .
': Object Name String, "' . htmlspecialchars($objStrName) .
'" was not followed by any operator, =<>({',
499 if (strpos($objStrName,
'.') !==
false) {
501 $value[0] = trim(substr($line, 1));
504 $setup[$objStrName] = trim(substr($line, 1));
505 if ($this->lastComment) {
513 if (strpos($objStrName,
'.') !==
false) {
516 if (!isset(
$setup[$objStrName .
'.'])) {
517 $setup[$objStrName .
'.'] = [];
519 $this->
parseSub($setup[$objStrName .
'.']);
523 throw new \RuntimeException(
524 'Line ' . ($this->rawPointer - 1) .
': Object Name String, "' . htmlspecialchars($objStrName) .
'" was not followed by any operator, =<>({',
529 $this->lastComment =
'';
531 } elseif ($line[0] ===
'}') {
533 $this->lastComment =
'';
534 if ($this->inBrace < 0) {
535 throw new \RuntimeException(
536 'Line ' . ($this->rawPointer - 1) .
': An end brace is in excess.',
542 $this->lastComment .= rtrim($line) . LF;
546 if ($this->commentSet) {
547 if (strpos($line,
'*/') === 0) {
548 $this->commentSet = 0;
565 if ((
string)$string ===
'') {
589 if ((
string)$string ===
'') {
594 $subKey = $key .
'.';
595 if ($remainingKey ===
'') {
596 if (isset($value[0])) {
599 if (isset($value[1])) {
602 if ($this->lastComment) {
606 if (!isset(
$setup[$subKey])) {
629 $dotPosition = strpos($key,
'.');
630 if ($dotPosition ===
false) {
634 if (strpos($key,
'\\') !==
false) {
636 while ($dotPosition !==
false) {
637 if ($dotPosition > 0 && $key[$dotPosition - 1] !==
'\\' || $dotPosition > 1 && $key[$dotPosition - 2] ===
'\\') {
641 $dotPosition = strpos($key,
'.', $dotPosition + 1);
644 if ($dotPosition ===
false) {
649 if ($dotPosition > 1 && $key[$dotPosition - 2] ===
'\\' && $key[$dotPosition - 1] ===
'\\') {
650 $keySegment = substr($key, 0, $dotPosition - 1);
652 $keySegment = substr($key, 0, $dotPosition);
654 $remainingKey = substr($key, $dotPosition + 1);
658 $keySegment = str_replace(
'\\.',
'.', $keySegment);
661 list($keySegment, $remainingKey) = explode(
'.', $key, 2);
663 return [$keySegment, $remainingKey];