‪TYPO3CMS  10.4
ArrayProcessor.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 
22 
30 {
31 
35  protected ‪$data;
36 
40  public function ‪__construct(array ‪$data)
41  {
43  }
44 
49  public function ‪forEach(...$processings): array
50  {
51  $result = [];
52 
53  $processings = $this->‪getValidProcessings($processings);
54  foreach ($this->data as $key => $value) {
55  foreach ($processings as $processing) {
56  // explicitly escaping non-escaped '#' which is used
57  // as PCRE delimiter in the following processing
58  ‪$expression = preg_replace(
59  '/(?<!\\\\)#/',
60  '\\#',
61  $processing->getExpression()
62  );
63 
64  if (preg_match('#' . ‪$expression . '#', $key, $matches)) {
65  ‪$identifier = $processing->getIdentifier();
66  ‪$processor = $processing->getProcessor();
67  $result[‪$identifier] = $result[‪$identifier] ?? [];
68  $result[‪$identifier][$key] = ‪$processor($key, $value, $matches);
69  }
70  }
71  }
72 
73  return $result;
74  }
75 
81  protected function ‪getValidProcessings(array $allProcessings): array
82  {
83  $validProcessings = [];
84  $identifiers = [];
85  foreach ($allProcessings as $processing) {
86  if ($processing instanceof ‪ArrayProcessing) {
87  if (in_array($processing->getIdentifier(), $identifiers, true)) {
89  'ArrayProcessing identifier must be unique.',
90  1528638085
91  );
92  }
93  $identifiers[] = $processing->getIdentifier();
94  $validProcessings[] = $processing;
95  }
96  }
97  return $validProcessings;
98  }
99 }
‪TYPO3\CMS\Form\Domain\Configuration\Exception\ArrayProcessorException
Definition: ArrayProcessorException.php:26
‪TYPO3\CMS\Form\Domain\Configuration\ArrayProcessing\ArrayProcessor\forEach
‪array forEach(... $processings)
Definition: ArrayProcessor.php:48
‪TYPO3\CMS\Form\Domain\Configuration\ArrayProcessing\ArrayProcessing\$expression
‪string $expression
Definition: ArrayProcessing.php:35
‪TYPO3\CMS\Form\Domain\Configuration\ArrayProcessing
Definition: ArrayProcessing.php:18
‪TYPO3\CMS\Form\Domain\Configuration\ArrayProcessing\ArrayProcessing\$identifier
‪string $identifier
Definition: ArrayProcessing.php:31
‪TYPO3\CMS\Form\Domain\Configuration\ArrayProcessing\ArrayProcessing
Definition: ArrayProcessing.php:27
‪TYPO3\CMS\Core\Utility\ArrayUtility\flattenPlain
‪static array flattenPlain(array $array)
Definition: ArrayUtility.php:515
‪TYPO3\CMS\Form\Domain\Configuration\ArrayProcessing\ArrayProcessing\$processor
‪callable $processor
Definition: ArrayProcessing.php:39
‪TYPO3\CMS\Form\Domain\Configuration\ArrayProcessing\ArrayProcessor
Definition: ArrayProcessor.php:30
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪TYPO3\CMS\Form\Domain\Configuration\ArrayProcessing\ArrayProcessor\$data
‪array $data
Definition: ArrayProcessor.php:34
‪TYPO3\CMS\Form\Domain\Configuration\ArrayProcessing\ArrayProcessor\getValidProcessings
‪ArrayProcessing[] getValidProcessings(array $allProcessings)
Definition: ArrayProcessor.php:80
‪TYPO3\CMS\Form\Domain\Configuration\ArrayProcessing\ArrayProcessor\__construct
‪__construct(array $data)
Definition: ArrayProcessor.php:39