‪TYPO3CMS  ‪main
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 
62  public function ‪getArguments(): array
63  {
64  return $this->getOption('_arguments') ?? [];
65  }
66 
67  public function ‪getEnhancer(): ?‪EnhancerInterface
68  {
69  return $this->getOption('_enhancer') ?? null;
70  }
71 
77  public function ‪getAspects(): array
78  {
79  return ‪$this->aspects;
80  }
81 
90  public function ‪setAspects(array ‪$aspects): self
91  {
92  $this->aspects = [];
93  return $this->‪addAspects($aspects);
94  }
95 
104  public function ‪addAspects(array ‪$aspects): self
105  {
106  foreach (‪$aspects as $key => $aspect) {
107  if (isset($this->aspects[$key])) {
108  throw new \OverflowException(
109  sprintf('Cannot override aspect %s', $key),
110  1538326791
111  );
112  }
113  $this->aspects[$key] = $aspect;
114  }
115  $this->compiled = null;
116  return $this;
117  }
118 
125  public function ‪getAspect(string $key): ?AspectInterface
126  {
127  return $this->aspects[$key] ?? null;
128  }
129 
136  public function ‪hasAspect(string $key): bool
137  {
138  return array_key_exists($key, $this->aspects);
139  }
140 
147  public function ‪setAspect(string $key, AspectInterface $aspect): self
148  {
149  $this->aspects[$key] = $aspect;
150  $this->compiled = null;
151  return $this;
152  }
153 
160  public function ‪filterAspects(array $classNames, array $variableNames = []): array
161  {
163  if (empty($classNames) && empty($variableNames)) {
164  return ‪$aspects;
165  }
166  if (!empty($variableNames)) {
167  ‪$aspects = array_filter(
168  $this->aspects,
169  static function (string $variableName) use ($variableNames) {
170  return in_array($variableName, $variableNames, true);
171  },
172  ARRAY_FILTER_USE_KEY
173  );
174  }
175  return array_filter(
176  ‪$aspects,
177  static function (AspectInterface $aspect) use ($classNames) {
178  $uses = class_uses($aspect) ?: [];
179  foreach ($classNames as $className) {
180  if (!is_a($aspect, $className)
181  && !in_array($className, $uses, true)
182  ) {
183  return false;
184  }
185  }
186  return true;
187  }
188  );
189  }
190 }
‪TYPO3\CMS\Core\Routing\Route\getArguments
‪getArguments()
Definition: Route.php:60
‪TYPO3\CMS\Core\Routing\Route\hasAspect
‪bool hasAspect(string $key)
Definition: Route.php:134
‪TYPO3\CMS\Core\Routing\Aspect\AspectInterface
Definition: AspectInterface.php:23
‪TYPO3\CMS\Core\Routing\Route\$aspects
‪AspectInterface[] $aspects
Definition: Route.php:40
‪TYPO3\CMS\Core\Routing\Route\setAspects
‪$this setAspects(array $aspects)
Definition: Route.php:88
‪TYPO3\CMS\Core\Routing\Route\getEnhancer
‪getEnhancer()
Definition: Route.php:65
‪TYPO3\CMS\Core\Routing
‪TYPO3\CMS\Core\Routing\Route\getAspect
‪AspectInterface null getAspect(string $key)
Definition: Route.php:123
‪TYPO3\CMS\Core\Routing\Route\setAspect
‪$this setAspect(string $key, AspectInterface $aspect)
Definition: Route.php:145
‪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:102
‪TYPO3\CMS\Core\Routing\Route
Definition: Route.php:32
‪TYPO3\CMS\Core\Routing\Route\getAspects
‪array getAspects()
Definition: Route.php:75
‪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:158
‪TYPO3\CMS\Core\Routing\Enhancer\EnhancerInterface
Definition: EnhancerInterface.php:27