‪TYPO3CMS  9.5
Route.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 
19 use Symfony\Component\Routing\CompiledRoute;
20 use Symfony\Component\Routing\Route as SymfonyRoute;
23 
30 class ‪Route extends SymfonyRoute
31 {
36  protected ‪$compiled;
37 
41  protected ‪$aspects = [];
42 
43  public function ‪__construct(
44  string $path,
45  array $defaults = [],
46  array $requirements = [],
47  array $options = [],
48  ?string $host = '',
49  $schemes = [],
50  $methods = [],
51  ?string $condition = '',
52  array ‪$aspects = []
53  ) {
54  parent::__construct($path, $defaults, $requirements, $options, $host, $schemes, $methods, $condition);
55  $this->‪setAspects(‪$aspects);
56  }
57 
62  public function ‪getArguments(): array
63  {
64  return $this->getOption('_arguments') ?? [];
65  }
66 
71  public function ‪addArguments(array $arguments)
72  {
73  $mergedArguments = $this->‪getArguments();
74  foreach ($arguments as $key => $argument) {
75  if (isset($mergedArguments[$key])) {
76  throw new \OverflowException(
77  sprintf('Cannot override argument %s', $key),
78  1538326790
79  );
80  }
81  $mergedArguments[$key] = $argument;
82  }
83  $this->setOption('_arguments', $mergedArguments);
84  }
85 
89  public function ‪getEnhancer(): ?EnhancerInterface
90  {
91  return $this->getOption('_enhancer') ?? null;
92  }
93 
99  public function ‪getAspects(): array
100  {
101  return ‪$this->aspects;
102  }
103 
112  public function ‪setAspects(array ‪$aspects): self
113  {
114  $this->aspects = [];
115  return $this->‪addAspects($aspects);
116  }
117 
126  public function ‪addAspects(array ‪$aspects): self
127  {
128  foreach (‪$aspects as $key => $aspect) {
129  if (isset($this->aspects[$key])) {
130  throw new \OverflowException(
131  sprintf('Cannot override aspect %s', $key),
132  1538326791
133  );
134  }
135  $this->aspects[$key] = $aspect;
136  }
137  $this->compiled = null;
138  return $this;
139  }
140 
147  public function ‪getAspect(string $key): ?AspectInterface
148  {
149  return $this->aspects[$key] ?? null;
150  }
151 
158  public function ‪hasAspect(string $key): bool
159  {
160  return array_key_exists($key, $this->aspects);
161  }
162 
170  public function ‪setAspect(string $key, AspectInterface $aspect): self
171  {
172  $this->aspects[$key] = $aspect;
173  $this->compiled = null;
174  return $this;
175  }
176 
183  public function ‪filterAspects(array $classNames, array $variableNames = []): array
184  {
186  if (empty($classNames) && empty($variableNames)) {
187  return ‪$aspects;
188  }
189  if (!empty($variableNames)) {
190  ‪$aspects = array_filter(
191  $this->aspects,
192  function (string $variableName) use ($variableNames) {
193  return in_array($variableName, $variableNames, true);
194  },
195  ARRAY_FILTER_USE_KEY
196  );
197  }
198  return array_filter(
199  ‪$aspects,
200  function (AspectInterface $aspect) use ($classNames) {
201  $uses = class_uses($aspect);
202  foreach ($classNames as $className) {
203  if (!is_a($aspect, $className)
204  && !in_array($className, $uses, true)
205  ) {
206  return false;
207  }
208  }
209  return true;
210  }
211  );
212  }
213 }
‪TYPO3\CMS\Core\Routing\Route\hasAspect
‪bool hasAspect(string $key)
Definition: Route.php:156
‪TYPO3\CMS\Core\Routing\Aspect\AspectInterface
Definition: AspectInterface.php:23
‪TYPO3\CMS\Core\Routing\Route\$aspects
‪AspectInterface[] $aspects
Definition: Route.php:39
‪TYPO3\CMS\Core\Routing\Route\getArguments
‪array getArguments()
Definition: Route.php:60
‪TYPO3\CMS\Core\Routing\Route\addArguments
‪addArguments(array $arguments)
Definition: Route.php:69
‪TYPO3\CMS\Core\Routing\Route\setAspects
‪$this setAspects(array $aspects)
Definition: Route.php:110
‪TYPO3\CMS\Core\Routing
‪TYPO3\CMS\Core\Routing\Route\getAspect
‪AspectInterface null getAspect(string $key)
Definition: Route.php:145
‪TYPO3\CMS\Core\Routing\Route\setAspect
‪$this setAspect(string $key, AspectInterface $aspect)
Definition: Route.php:168
‪TYPO3\CMS\Core\Routing\Route\getEnhancer
‪EnhancerInterface null getEnhancer()
Definition: Route.php:87
‪TYPO3\CMS\Core\Routing\Route\$compiled
‪CompiledRoute null $compiled
Definition: Route.php:35
‪TYPO3\CMS\Core\Routing\Route\addAspects
‪$this addAspects(array $aspects)
Definition: Route.php:124
‪TYPO3\CMS\Core\Routing\Route
Definition: Route.php:31
‪TYPO3\CMS\Core\Routing\Route\getAspects
‪array getAspects()
Definition: Route.php:97
‪TYPO3\CMS\Core\Routing\Route\__construct
‪array __construct(string $path, array $defaults=[], array $requirements=[], array $options=[], ?string $host='', $schemes=[], $methods=[], ?string $condition='', array $aspects=[])
Definition: Route.php:41
‪TYPO3\CMS\Core\Routing\Route\filterAspects
‪AspectInterface[] filterAspects(array $classNames, array $variableNames=[])
Definition: Route.php:181
‪TYPO3\CMS\Core\Routing\Enhancer\EnhancerInterface
Definition: EnhancerInterface.php:26