‪TYPO3CMS  ‪main
TypoScriptService.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 
27 {
41  {
42  foreach (‪$typoScriptArray as $key => $value) {
43  if (str_ends_with((string)$key, '.')) {
44  $keyWithoutDot = substr((string)$key, 0, -1);
45  $typoScriptNodeValue = ‪$typoScriptArray[$keyWithoutDot] ?? null;
46  if (is_array($value)) {
48  if ($typoScriptNodeValue !== null) {
49  ‪$typoScriptArray[$keyWithoutDot]['_typoScriptNodeValue'] = $typoScriptNodeValue;
50  }
51  unset(‪$typoScriptArray[$key]);
52  } else {
53  ‪$typoScriptArray[$keyWithoutDot] = null;
54  }
55  }
56  }
58  }
59 
74  public function ‪convertPlainArrayToTypoScriptArray(array $plainArray): array
75  {
77  foreach ($plainArray as $key => $value) {
78  if (is_array($value)) {
79  if (isset($value['_typoScriptNodeValue'])) {
80  ‪$typoScriptArray[$key] = $value['_typoScriptNodeValue'];
81  unset($value['_typoScriptNodeValue']);
82  }
84  } else {
85  ‪$typoScriptArray[$key] = $value ?? '';
86  }
87  }
88  return ‪$typoScriptArray;
89  }
90 
104  public function ‪explodeConfigurationForOptionSplit(array $originalConfiguration, int $splitCount): array
105  {
106  $finalConfiguration = [];
107  if (!$splitCount) {
108  return $finalConfiguration;
109  }
110  // Initialize output to carry at least the keys
111  for ($aKey = 0; $aKey < $splitCount; $aKey++) {
112  $finalConfiguration[$aKey] = [];
113  }
114  // Recursive processing of array keys
115  foreach ($originalConfiguration as $cKey => $val) {
116  if (is_array($val)) {
117  $tempConf = $this->‪explodeConfigurationForOptionSplit($val, $splitCount);
118  foreach ($tempConf as $aKey => $val2) {
119  $finalConfiguration[$aKey][$cKey] = $val2;
120  }
121  } elseif (is_string($val)) {
122  // Splitting of all values on this level of the TypoScript object tree:
123  if ($cKey === 'noTrimWrap' || (!str_contains($val, '|*|') && !str_contains($val, '||'))) {
124  for ($aKey = 0; $aKey < $splitCount; $aKey++) {
125  $finalConfiguration[$aKey][$cKey] = $val;
126  }
127  } else {
128  $main = explode('|*|', $val);
129  $lastC = 0;
130  $middleC = 0;
131  $firstC = 0;
132  if ($main[0]) {
133  $first = explode('||', $main[0]);
134  $firstC = count($first);
135  }
136  $middle = [];
137  if (!empty($main[1])) {
138  $middle = explode('||', $main[1]);
139  $middleC = count($middle);
140  }
141  $last = [];
142  $value = '';
143  if (!empty($main[2])) {
144  $last = explode('||', $main[2]);
145  $lastC = count($last);
146  $value = $last[0];
147  }
148  for ($aKey = 0; $aKey < $splitCount; $aKey++) {
149  if ($firstC && isset($first[$aKey])) {
150  $value = $first[$aKey];
151  } elseif ($middleC) {
152  $value = $middle[($aKey - $firstC) % $middleC];
153  }
154  if ($lastC && $lastC >= $splitCount - $aKey) {
155  $value = $last[$lastC - ($splitCount - $aKey)];
156  }
157  $finalConfiguration[$aKey][$cKey] = trim($value);
158  }
159  }
160  }
161  }
162  return $finalConfiguration;
163  }
164 }
‪TYPO3\CMS\Core\TypoScript\TypoScriptService\$typoScriptArray
‪return $typoScriptArray
Definition: TypoScriptService.php:57
‪TYPO3\CMS\Core\TypoScript\TypoScriptService\explodeConfigurationForOptionSplit
‪array explodeConfigurationForOptionSplit(array $originalConfiguration, int $splitCount)
Definition: TypoScriptService.php:104
‪TYPO3\CMS\Core\TypoScript\TypoScriptService\convertPlainArrayToTypoScriptArray
‪array convertPlainArrayToTypoScriptArray(array $plainArray)
Definition: TypoScriptService.php:74
‪TYPO3\CMS\Core\TypoScript
‪TYPO3\CMS\Core\TypoScript\TypoScriptService\convertTypoScriptArrayToPlainArray
‪array< string|int, convertTypoScriptArrayToPlainArray(array $typoScriptArray):array { foreach( $typoScriptArray as $key=> $value) { if(str_ends_with((string) $key, '.')) { $keyWithoutDot=substr((string) $key, 0, -1);$typoScriptNodeValue=$typoScriptArray[ $keyWithoutDot] ?? null;if(is_array( $value)) { $typoScriptArray[ $keyWithoutDot]=$this-> convertTypoScriptArrayToPlainArray($value)
‪TYPO3\CMS\Core\TypoScript\TypoScriptService
Definition: TypoScriptService.php:27