‪TYPO3CMS  10.4
MappableProcessor.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 
21 
26 {
32  public function ‪resolve(‪Route $route, array &$attributes): bool
33  {
34  $mappers = $this->‪fetchMappers($route, $attributes);
35  if (empty($mappers)) {
36  return true;
37  }
38 
39  $values = [];
40  foreach ($mappers as $variableName => $mapper) {
41  $value = $mapper->resolve(
42  (string)($attributes[$variableName] ?? '')
43  );
44  if ($value === null) {
45  return false;
46  }
47  $values[$variableName] = $value;
48  }
49 
50  $attributes = array_merge($attributes, $values);
51  return true;
52  }
53 
59  public function ‪generate(‪Route $route, array &$attributes): bool
60  {
61  $mappers = $this->‪fetchMappers($route, $attributes);
62  if (empty($mappers)) {
63  return true;
64  }
65 
66  $values = [];
67  foreach ($mappers as $variableName => $mapper) {
68  $value = $mapper->generate(
69  (string)($attributes[$variableName] ?? '')
70  );
71  if ($value === null) {
72  return false;
73  }
74  $values[$variableName] = $value;
75  }
76 
77  $attributes = array_merge($attributes, $values);
78  return true;
79  }
80 
87  protected function ‪fetchMappers(‪Route $route, array $attributes, string $type = MappableAspectInterface::class): array
88  {
89  if (empty($attributes)) {
90  return [];
91  }
92  return $route->‪filterAspects([$type], array_keys($attributes));
93  }
94 }
‪TYPO3\CMS\Core\Routing\Aspect\MappableProcessor\fetchMappers
‪MappableAspectInterface[] fetchMappers(Route $route, array $attributes, string $type=MappableAspectInterface::class)
Definition: MappableProcessor.php:87
‪TYPO3\CMS\Core\Routing\Aspect\MappableProcessor\generate
‪bool generate(Route $route, array &$attributes)
Definition: MappableProcessor.php:59
‪TYPO3\CMS\Core\Routing\Aspect\MappableProcessor\resolve
‪bool resolve(Route $route, array &$attributes)
Definition: MappableProcessor.php:32
‪TYPO3\CMS\Core\Routing\Aspect\MappableAspectInterface
Definition: MappableAspectInterface.php:24
‪TYPO3\CMS\Core\Routing\Aspect\MappableProcessor
Definition: MappableProcessor.php:26
‪TYPO3\CMS\Core\Routing\Aspect
Definition: AspectFactory.php:18
‪TYPO3\CMS\Core\Routing\Route
Definition: Route.php:32
‪TYPO3\CMS\Core\Routing\Route\filterAspects
‪AspectInterface[] filterAspects(array $classNames, array $variableNames=[])
Definition: Route.php:163