‪TYPO3CMS  10.4
Route.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 
20 use Symfony\Component\Routing\CompiledRoute;
21 use Symfony\Component\Routing\Route as SymfonyRoute;
24 
31 class ‪Route extends SymfonyRoute
32 {
37  protected ‪$compiled;
38 
42  protected ‪$aspects = [];
43 
44  public function ‪__construct(
45  string $path,
46  array $defaults = [],
47  array $requirements = [],
48  array $options = [],
49  ?string $host = '',
50  $schemes = [],
51  $methods = [],
52  ?string $condition = '',
53  array ‪$aspects = []
54  ) {
55  parent::__construct($path, $defaults, $requirements, $options, $host, $schemes, $methods, $condition);
56  $this->‪setAspects(‪$aspects);
57  }
58 
63  public function ‪getArguments(): array
64  {
65  return $this->getOption('_arguments') ?? [];
66  }
67 
71  public function ‪getEnhancer(): ?EnhancerInterface
72  {
73  return $this->getOption('_enhancer') ?? null;
74  }
75 
81  public function ‪getAspects(): array
82  {
83  return ‪$this->aspects;
84  }
85 
94  public function ‪setAspects(array ‪$aspects): self
95  {
96  $this->aspects = [];
97  return $this->‪addAspects($aspects);
98  }
99 
108  public function ‪addAspects(array ‪$aspects): self
109  {
110  foreach (‪$aspects as $key => $aspect) {
111  if (isset($this->aspects[$key])) {
112  throw new \OverflowException(
113  sprintf('Cannot override aspect %s', $key),
114  1538326791
115  );
116  }
117  $this->aspects[$key] = $aspect;
118  }
119  $this->compiled = null;
120  return $this;
121  }
122 
129  public function ‪getAspect(string $key): ?AspectInterface
130  {
131  return $this->aspects[$key] ?? null;
132  }
133 
140  public function ‪hasAspect(string $key): bool
141  {
142  return array_key_exists($key, $this->aspects);
143  }
144 
152  public function ‪setAspect(string $key, AspectInterface $aspect): self
153  {
154  $this->aspects[$key] = $aspect;
155  $this->compiled = null;
156  return $this;
157  }
158 
165  public function ‪filterAspects(array $classNames, array $variableNames = []): array
166  {
168  if (empty($classNames) && empty($variableNames)) {
169  return ‪$aspects;
170  }
171  if (!empty($variableNames)) {
172  ‪$aspects = array_filter(
173  $this->aspects,
174  function (string $variableName) use ($variableNames) {
175  return in_array($variableName, $variableNames, true);
176  },
177  ARRAY_FILTER_USE_KEY
178  );
179  }
180  return array_filter(
181  ‪$aspects,
182  function (AspectInterface $aspect) use ($classNames) {
183  $uses = class_uses($aspect);
184  foreach ($classNames as $className) {
185  if (!is_a($aspect, $className)
186  && !in_array($className, $uses, true)
187  ) {
188  return false;
189  }
190  }
191  return true;
192  }
193  );
194  }
195 }
‪TYPO3\CMS\Core\Routing\Route\hasAspect
‪bool hasAspect(string $key)
Definition: Route.php:138
‪TYPO3\CMS\Core\Routing\Aspect\AspectInterface
Definition: AspectInterface.php:24
‪TYPO3\CMS\Core\Routing\Route\$aspects
‪AspectInterface[] $aspects
Definition: Route.php:40
‪TYPO3\CMS\Core\Routing\Route\getArguments
‪array getArguments()
Definition: Route.php:61
‪TYPO3\CMS\Core\Routing\Route\setAspects
‪$this setAspects(array $aspects)
Definition: Route.php:92
‪TYPO3\CMS\Core\Routing
‪TYPO3\CMS\Core\Routing\Route\getAspect
‪AspectInterface null getAspect(string $key)
Definition: Route.php:127
‪TYPO3\CMS\Core\Routing\Route\setAspect
‪$this setAspect(string $key, AspectInterface $aspect)
Definition: Route.php:150
‪TYPO3\CMS\Core\Routing\Route\getEnhancer
‪EnhancerInterface null getEnhancer()
Definition: Route.php:69
‪TYPO3\CMS\Core\Routing\Route\$compiled
‪CompiledRoute null $compiled
Definition: Route.php:36
‪TYPO3\CMS\Core\Routing\Route\addAspects
‪$this addAspects(array $aspects)
Definition: Route.php:106
‪TYPO3\CMS\Core\Routing\Route
Definition: Route.php:32
‪TYPO3\CMS\Core\Routing\Route\getAspects
‪array getAspects()
Definition: Route.php:79
‪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:42
‪TYPO3\CMS\Core\Routing\Route\filterAspects
‪AspectInterface[] filterAspects(array $classNames, array $variableNames=[])
Definition: Route.php:163
‪TYPO3\CMS\Core\Routing\Enhancer\EnhancerInterface
Definition: EnhancerInterface.php:27