You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Attribute/Route.php
+14-5
Original file line number
Diff line number
Diff line change
@@ -22,6 +22,7 @@ class Route
22
22
privatearray$localizedPaths = [];
23
23
privatearray$methods;
24
24
privatearray$schemes;
25
+
privatearray$aliases;
25
26
26
27
/**
27
28
* @param string|array<string,string>|null $path The route path (i.e. "/user/login")
@@ -39,7 +40,7 @@ class Route
39
40
* @param bool|null $utf8 Whether the route accepts UTF-8 in its parameters
40
41
* @param bool|null $stateless Whether the route is defined as stateless or stateful, @see https://symfony.com/doc/current/routing.html#stateless-routes
41
42
* @param string|null $env The env in which the route is defined (i.e. "dev", "test", "prod")
42
-
* @param string[] $aliases The list of aliases for this route
43
+
* @param string|string[] $alias The list of aliases for this route
43
44
*/
44
45
publicfunction__construct(
45
46
string|array|null$path = null,
@@ -57,7 +58,7 @@ public function __construct(
57
58
?bool$utf8 = null,
58
59
?bool$stateless = null,
59
60
private ?string$env = null,
60
-
privatearray$aliases = [],
61
+
array|string$alias = [],
61
62
) {
62
63
if (\is_array($path)) {
63
64
$this->localizedPaths = $path;
@@ -66,7 +67,15 @@ public function __construct(
66
67
}
67
68
$this->setMethods($methods);
68
69
$this->setSchemes($schemes);
69
-
$this->setAliases($aliases);
70
+
71
+
if (\is_array($alias)) {
72
+
foreach ($aliasas$a) {
73
+
if (!\is_string($a)) {
74
+
thrownew \TypeError(\sprintf('The "alias" argument of the Route attribute must be a string or an array of strings, but got "%s".', \get_debug_type($a)));
75
+
}
76
+
}
77
+
}
78
+
$this->setAliases($alias);
70
79
71
80
if (null !== $locale) {
72
81
$this->defaults['_locale'] = $locale;
@@ -210,9 +219,9 @@ public function getAliases(): array
$this->expectExceptionMessage('Class "Symfony\Component\Routing\Tests\Fixtures\AttributeFixtures\AliasClassController" cannot have aliases as it does not have an "__invoke" method.');
384
+
$this->expectExceptionMessage('Route aliases cannot be used on non-invokable class "Symfony\Component\Routing\Tests\Fixtures\AttributeFixtures\AliasClassController".');
385
385
386
386
$this->loader->load(AliasClassController::class);
387
387
}
@@ -391,7 +391,7 @@ public function testAliasesOnInvokableClass()
0 commit comments