‪TYPO3CMS  10.4
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 
25 {
36  public function ‪convertTypoScriptArrayToPlainArray(array $typoScriptArray): array
37  {
38  foreach ($typoScriptArray as $key => $value) {
39  if (substr((string)$key, -1) === '.') {
40  $keyWithoutDot = substr((string)$key, 0, -1);
41  $typoScriptNodeValue = $typoScriptArray[$keyWithoutDot] ?? null;
42  if (is_array($value)) {
43  $typoScriptArray[$keyWithoutDot] = $this->‪convertTypoScriptArrayToPlainArray($value);
44  if ($typoScriptNodeValue !== null) {
45  $typoScriptArray[$keyWithoutDot]['_typoScriptNodeValue'] = $typoScriptNodeValue;
46  }
47  unset($typoScriptArray[$key]);
48  } else {
49  $typoScriptArray[$keyWithoutDot] = null;
50  }
51  }
52  }
53  return $typoScriptArray;
54  }
55 
67  public function ‪convertPlainArrayToTypoScriptArray(array $plainArray): array
68  {
69  $typoScriptArray = [];
70  foreach ($plainArray as $key => $value) {
71  if (is_array($value)) {
72  if (isset($value['_typoScriptNodeValue'])) {
73  $typoScriptArray[$key] = $value['_typoScriptNodeValue'];
74  unset($value['_typoScriptNodeValue']);
75  }
76  $typoScriptArray[$key . '.'] = $this->‪convertPlainArrayToTypoScriptArray($value);
77  } else {
78  $typoScriptArray[$key] = $value ?? '';
79  }
80  }
81  return $typoScriptArray;
82  }
83 
97  public function ‪explodeConfigurationForOptionSplit(array $originalConfiguration, int $splitCount): array
98  {
99  $finalConfiguration = [];
100  if (!$splitCount) {
101  return $finalConfiguration;
102  }
103  // Initialize output to carry at least the keys
104  for ($aKey = 0; $aKey < $splitCount; $aKey++) {
105  $finalConfiguration[$aKey] = [];
106  }
107  // Recursive processing of array keys
108  foreach ($originalConfiguration as $cKey => $val) {
109  if (is_array($val)) {
110  $tempConf = $this->‪explodeConfigurationForOptionSplit($val, $splitCount);
111  foreach ($tempConf as $aKey => $val2) {
112  $finalConfiguration[$aKey][$cKey] = $val2;
113  }
114  } elseif (is_string($val)) {
115  // Splitting of all values on this level of the TypoScript object tree:
116  if ($cKey === 'noTrimWrap' || (strpos($val, '|*|') === false && strpos($val, '||') === false)) {
117  for ($aKey = 0; $aKey < $splitCount; $aKey++) {
118  $finalConfiguration[$aKey][$cKey] = $val;
119  }
120  } else {
121  $main = explode('|*|', $val);
122  $lastC = 0;
123  $middleC = 0;
124  $firstC = 0;
125  if ($main[0]) {
126  $first = explode('||', $main[0]);
127  $firstC = count($first);
128  }
129  $middle = [];
130  if (!empty($main[1])) {
131  $middle = explode('||', $main[1]);
132  $middleC = count($middle);
133  }
134  $last = [];
135  $value = '';
136  if (!empty($main[2])) {
137  $last = explode('||', $main[2]);
138  $lastC = count($last);
139  $value = $last[0];
140  }
141  for ($aKey = 0; $aKey < $splitCount; $aKey++) {
142  if ($firstC && isset($first[$aKey])) {
143  $value = $first[$aKey];
144  } elseif ($middleC) {
145  $value = $middle[($aKey - $firstC) % $middleC];
146  }
147  if ($lastC && $lastC >= $splitCount - $aKey) {
148  $value = $last[$lastC - ($splitCount - $aKey)];
149  }
150  $finalConfiguration[$aKey][$cKey] = trim($value);
151  }
152  }
153  }
154  }
155  return $finalConfiguration;
156  }
157 }
‪TYPO3\CMS\Core\TypoScript\TypoScriptService\explodeConfigurationForOptionSplit
‪array explodeConfigurationForOptionSplit(array $originalConfiguration, int $splitCount)
Definition: TypoScriptService.php:97
‪TYPO3\CMS\Core\TypoScript\TypoScriptService\convertTypoScriptArrayToPlainArray
‪array convertTypoScriptArrayToPlainArray(array $typoScriptArray)
Definition: TypoScriptService.php:36
‪TYPO3\CMS\Core\TypoScript\TypoScriptService\convertPlainArrayToTypoScriptArray
‪array convertPlainArrayToTypoScriptArray(array $plainArray)
Definition: TypoScriptService.php:67
‪TYPO3\CMS\Core\TypoScript
Definition: ExtendedTemplateService.php:16
‪TYPO3\CMS\Core\TypoScript\TypoScriptService
Definition: TypoScriptService.php:25