Skip to content

Commit c47b529

Browse files
committed
check instance of deprecatedAlias instead of string and add deprecations in changelog
1 parent 82d4898 commit c47b529

File tree

5 files changed

+10
-13
lines changed

5 files changed

+10
-13
lines changed

src/Symfony/Component/Routing/Attribute/Route.php

-2
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,6 @@ public function getAliases(): array
221221

222222
/**
223223
* @param string|DeprecatedAlias|(string|DeprecatedAlias)[] $aliases
224-
*
225-
* @throws InvalidArgumentException if the "alias" argument is not a string or an array of strings
226224
*/
227225
public function setAliases(string|DeprecatedAlias|array $aliases): void
228226
{

src/Symfony/Component/Routing/CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CHANGELOG
44
7.3
55
---
66

7-
* Allow aliases in `#[Route]` attribute
7+
* Allow aliases and deprecations in `#[Route]` attribute
88

99
7.2
1010
---

src/Symfony/Component/Routing/Loader/AttributeClassLoader.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Config\Loader\LoaderInterface;
1515
use Symfony\Component\Config\Loader\LoaderResolverInterface;
1616
use Symfony\Component\Config\Resource\FileResource;
17+
use Symfony\Component\Routing\Attribute\DeprecatedAlias;
1718
use Symfony\Component\Routing\Attribute\Route as RouteAttribute;
1819
use Symfony\Component\Routing\Exception\InvalidArgumentException;
1920
use Symfony\Component\Routing\Exception\LogicException;
@@ -241,17 +242,17 @@ protected function addRoute(RouteCollection $collection, object $attr, array $gl
241242
$collection->add($name, $route, $priority);
242243
}
243244
foreach ($attr->getAliases() as $aliasAttribute) {
244-
if (\is_string($aliasAttribute)) {
245-
$collection->addAlias($aliasAttribute, $name);
245+
if ($aliasAttribute instanceof DeprecatedAlias) {
246+
$alias = $collection->addAlias($aliasAttribute->getAliasName(), $name);
247+
$alias->setDeprecated(
248+
$aliasAttribute->getPackage(),
249+
$aliasAttribute->getVersion(),
250+
$aliasAttribute->getMessage()
251+
);
246252
continue;
247253
}
248254

249-
$alias = $collection->addAlias($aliasAttribute->getAliasName(), $name);
250-
$alias->setDeprecated(
251-
$aliasAttribute->getPackage(),
252-
$aliasAttribute->getVersion(),
253-
$aliasAttribute->getMessage()
254-
);
255+
$collection->addAlias($aliasAttribute, $name);
255256
}
256257
}
257258
}

src/Symfony/Component/Routing/Tests/Fixtures/AttributeFixtures/DeprecatedAliasRouteController.php

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
class DeprecatedAliasRouteController
1818
{
19-
2019
#[Route('/path', name: 'action_with_deprecated_alias', alias: new DeprecatedAlias('my_other_alias_deprecated', 'MyBundleFixture', '1.0'))]
2120
public function action()
2221
{

src/Symfony/Component/Routing/Tests/Fixtures/AttributeFixtures/MultipleDeprecatedAliasRouteController.php

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
class MultipleDeprecatedAliasRouteController
1818
{
19-
2019
#[Route('/path', name: 'action_with_multiple_deprecated_alias', alias: [
2120
new DeprecatedAlias('my_first_alias_deprecated', 'MyFirstBundleFixture', '1.0'),
2221
new DeprecatedAlias('my_second_alias_deprecated', 'MySecondBundleFixture', '2.0'),

0 commit comments

Comments
 (0)