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