Skip to content

Commit 5dea2ba

Browse files
[Routing] add union types
1 parent 7f571f3 commit 5dea2ba

27 files changed

+49
-207
lines changed

CompiledRoute.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function __unserialize(array $data): void
8686
/**
8787
* @internal
8888
*/
89-
final public function unserialize($serialized)
89+
final public function unserialize(string $serialized)
9090
{
9191
$this->__unserialize(unserialize($serialized, ['allowed_classes' => false]));
9292
}

Loader/AnnotationClassLoader.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,11 @@ public function setRouteAnnotationClass(string $class)
102102
/**
103103
* Loads from annotations from a class.
104104
*
105-
* @param string $class A class name
106-
*
107105
* @return RouteCollection A RouteCollection instance
108106
*
109107
* @throws \InvalidArgumentException When route can't be parsed
110108
*/
111-
public function load($class, string $type = null)
109+
public function load(mixed $class, string $type = null)
112110
{
113111
if (!class_exists($class)) {
114112
throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
@@ -239,7 +237,7 @@ protected function addRoute(RouteCollection $collection, object $annot, array $g
239237
/**
240238
* {@inheritdoc}
241239
*/
242-
public function supports($resource, string $type = null)
240+
public function supports(mixed $resource, string $type = null)
243241
{
244242
return \is_string($resource) && preg_match('/^(?:\\\\?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)+$/', $resource) && (!$type || 'annotation' === $type);
245243
}

Loader/AnnotationDirectoryLoader.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,11 @@
2323
class AnnotationDirectoryLoader extends AnnotationFileLoader
2424
{
2525
/**
26-
* Loads from annotations from a directory.
27-
*
28-
* @param string $path A directory path
29-
* @param string|null $type The resource type
30-
*
3126
* @return RouteCollection A RouteCollection instance
3227
*
3328
* @throws \InvalidArgumentException When the directory does not exist or its routes cannot be parsed
3429
*/
35-
public function load($path, string $type = null)
30+
public function load(mixed $path, string $type = null)
3631
{
3732
if (!is_dir($dir = $this->locator->locate($path))) {
3833
return parent::supports($path, $type) ? parent::load($path, $type) : new RouteCollection();
@@ -74,7 +69,7 @@ function (\SplFileInfo $current) {
7469
/**
7570
* {@inheritdoc}
7671
*/
77-
public function supports($resource, string $type = null)
72+
public function supports(mixed $resource, string $type = null)
7873
{
7974
if ('annotation' === $type) {
8075
return true;

Loader/AnnotationFileLoader.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ class AnnotationFileLoader extends FileLoader
2626
{
2727
protected $loader;
2828

29-
/**
30-
* @throws \RuntimeException
31-
*/
3229
public function __construct(FileLocatorInterface $locator, AnnotationClassLoader $loader)
3330
{
3431
if (!\function_exists('token_get_all')) {
@@ -43,14 +40,11 @@ public function __construct(FileLocatorInterface $locator, AnnotationClassLoader
4340
/**
4441
* Loads from annotations from a file.
4542
*
46-
* @param string $file A PHP file path
47-
* @param string|null $type The resource type
48-
*
4943
* @return RouteCollection|null A RouteCollection instance
5044
*
5145
* @throws \InvalidArgumentException When the file does not exist or its routes cannot be parsed
5246
*/
53-
public function load($file, string $type = null)
47+
public function load(mixed $file, string $type = null)
5448
{
5549
$path = $this->locator->locate($file);
5650

@@ -73,7 +67,7 @@ public function load($file, string $type = null)
7367
/**
7468
* {@inheritdoc}
7569
*/
76-
public function supports($resource, string $type = null)
70+
public function supports(mixed $resource, string $type = null)
7771
{
7872
return \is_string($resource) && 'php' === pathinfo($resource, \PATHINFO_EXTENSION) && (!$type || 'annotation' === $type);
7973
}

Loader/ClosureLoader.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@ class ClosureLoader extends Loader
2626
/**
2727
* Loads a Closure.
2828
*
29-
* @param \Closure $closure A Closure
30-
* @param string|null $type The resource type
31-
*
3229
* @return RouteCollection A RouteCollection instance
3330
*/
34-
public function load($closure, string $type = null)
31+
public function load(mixed $closure, string $type = null)
3532
{
3633
return $closure($this->env);
3734
}

Loader/Configurator/CollectionConfigurator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ final public function collection(string $name = ''): self
7575
*
7676
* @return $this
7777
*/
78-
final public function prefix($prefix): self
78+
final public function prefix(string|array $prefix): self
7979
{
8080
if (\is_array($prefix)) {
8181
if (null === $this->parentPrefixes) {
@@ -108,7 +108,7 @@ final public function prefix($prefix): self
108108
*
109109
* @return $this
110110
*/
111-
final public function host($host): self
111+
final public function host(string|array $host): self
112112
{
113113
$this->host = $host;
114114

Loader/Configurator/ImportConfigurator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __destruct()
5252
*
5353
* @return $this
5454
*/
55-
final public function prefix($prefix, bool $trailingSlashOnRoot = true): self
55+
final public function prefix(string|array $prefix, bool $trailingSlashOnRoot = true): self
5656
{
5757
$this->addPrefix($this->route, $prefix, $trailingSlashOnRoot);
5858

@@ -78,7 +78,7 @@ final public function namePrefix(string $namePrefix): self
7878
*
7979
* @return $this
8080
*/
81-
final public function host($host): self
81+
final public function host(string|array $host): self
8282
{
8383
$this->addHost($this->route, $host);
8484

Loader/Configurator/RouteConfigurator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(RouteCollection $collection, $route, string $name =
4040
*
4141
* @return $this
4242
*/
43-
final public function host($host): self
43+
final public function host(string|array $host): self
4444
{
4545
$this->addHost($this->route, $host);
4646

Loader/Configurator/RoutingConfigurator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(RouteCollection $collection, PhpFileLoader $loader,
3838
/**
3939
* @param string|string[]|null $exclude Glob patterns to exclude from the import
4040
*/
41-
final public function import($resource, string $type = null, bool $ignoreErrors = false, $exclude = null): ImportConfigurator
41+
final public function import(string|array $resource, string $type = null, bool $ignoreErrors = false, string|array|null $exclude = null): ImportConfigurator
4242
{
4343
$this->loader->setCurrentDir(\dirname($this->path));
4444

Loader/Configurator/Traits/AddTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ trait AddTrait
3434
*
3535
* @param string|array $path the path, or the localized paths of the route
3636
*/
37-
public function add(string $name, $path): RouteConfigurator
37+
public function add(string $name, string|array $path): RouteConfigurator
3838
{
3939
$parentConfigurator = $this instanceof CollectionConfigurator ? $this : ($this instanceof RouteConfigurator ? $this->parentConfigurator : null);
4040
$route = $this->createLocalizedRoute($this->collection, $name, $path, $this->name, $this->prefixes);
@@ -47,7 +47,7 @@ public function add(string $name, $path): RouteConfigurator
4747
*
4848
* @param string|array $path the path, or the localized paths of the route
4949
*/
50-
public function __invoke(string $name, $path): RouteConfigurator
50+
public function __invoke(string $name, string|array $path): RouteConfigurator
5151
{
5252
return $this->add($name, $path);
5353
}

0 commit comments

Comments
 (0)