‪TYPO3CMS  9.5
MappableProcessor.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
20 
25 {
31  public function ‪resolve(‪Route $route, array &$attributes): bool
32  {
33  $mappers = $this->‪fetchMappers($route, $attributes);
34  if (empty($mappers)) {
35  return true;
36  }
37 
38  $values = [];
39  foreach ($mappers as $variableName => $mapper) {
40  $value = $mapper->resolve(
41  (string)($attributes[$variableName] ?? '')
42  );
43  if ($value === null) {
44  return false;
45  }
46  $values[$variableName] = $value;
47  }
48 
49  $attributes = array_merge($attributes, $values);
50  return true;
51  }
52 
58  public function ‪generate(‪Route $route, array &$attributes): bool
59  {
60  $mappers = $this->‪fetchMappers($route, $attributes);
61  if (empty($mappers)) {
62  return true;
63  }
64 
65  $values = [];
66  foreach ($mappers as $variableName => $mapper) {
67  $value = $mapper->generate(
68  (string)($attributes[$variableName] ?? '')
69  );
70  if ($value === null) {
71  return false;
72  }
73  $values[$variableName] = $value;
74  }
75 
76  $attributes = array_merge($attributes, $values);
77  return true;
78  }
79 
86  protected function ‪fetchMappers(‪Route $route, array $attributes, string $type = MappableAspectInterface::class): array
87  {
88  if (empty($attributes)) {
89  return [];
90  }
91  return $route->‪filterAspects([$type], array_keys($attributes));
92  }
93 }
‪TYPO3\CMS\Core\Routing\Aspect\MappableProcessor\fetchMappers
‪MappableAspectInterface[] fetchMappers(Route $route, array $attributes, string $type=MappableAspectInterface::class)
Definition: MappableProcessor.php:86
‪TYPO3\CMS\Core\Routing\Aspect\MappableProcessor\generate
‪bool generate(Route $route, array &$attributes)
Definition: MappableProcessor.php:58
‪TYPO3\CMS\Core\Routing\Aspect\MappableProcessor\resolve
‪bool resolve(Route $route, array &$attributes)
Definition: MappableProcessor.php:31
‪TYPO3\CMS\Core\Routing\Aspect\MappableAspectInterface
Definition: MappableAspectInterface.php:23
‪TYPO3\CMS\Core\Routing\Aspect\MappableProcessor
Definition: MappableProcessor.php:25
‪TYPO3\CMS\Core\Routing\Aspect
Definition: AspectFactory.php:4
‪TYPO3\CMS\Core\Routing\Route
Definition: Route.php:31
‪TYPO3\CMS\Core\Routing\Route\filterAspects
‪AspectInterface[] filterAspects(array $classNames, array $variableNames=[])
Definition: Route.php:181