8000 [FrameworkBundle][Routing] Deprecate annotations · symfony/symfony@94c5354 · GitHub
[go: up one dir, main page]

Skip to content

Commit 94c5354

Browse files
[FrameworkBundle][Routing] Deprecate annotations
1 parent 7074da9 commit 94c5354

33 files changed

+276
-78
lines changed

UPGRADE-6.4.md

+7
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ FrameworkBundle
9696
* Deprecate not setting the `framework.validation.email_validation_mode` config option; it will default to `html5` in 7.0
9797
* Deprecate `framework.validation.enable_annotations`, use `framework.validation.enable_attributes` instead
9898
* Deprecate `framework.serializer.enable_annotations`, use `framework.serializer.enable_attributes` instead
99+
* Deprecate the `routing.loader.annotation` service, use the `routing.loader.attribute` service instead
100+
* Deprecate the `routing.loader.annotation.directory` service, use the `routing.loader.attribute.directory` service instead
101+
* Deprecate the `routing.loader.annotation.file` service, use the `routing.loader.attribute.file` service instead
102+
* Deprecate `AnnotatedRouteControllerLoader`, use `AttributeRouteControllerLoader` instead
99103

100104
HttpFoundation
101105
--------------
@@ -137,6 +141,9 @@ Routing
137141
* [BC break] Add native return type to `AnnotationClassLoader::setResolver()`
138142
* Deprecate Doctrine annotations support in favor of native attributes
139143
* Deprecate passing an annotation reader as first argument to `AnnotationClassLoader` (new signature: `__construct(?string $env = null)`)
144+
* Deprecate `AnnotationClassLoader`, use `AttributeClassLoader` instead
145+
* Deprecate `AnnotationDirectoryLoader`, use `AttributeDirectoryLoader` instead
146+
* Deprecate `AnnotationFileLoader`, use `AttributeFileLoader` instead
140147

141148
Security
142149
--------

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ CHANGELOG
3131
* Deprecate the `framework.asset_mapper.provider` config option
3232
* Add `--exclude` option to the `cache:pool:clear` command
3333
* Add parameters deprecations to the output of `debug:container` command
34+
* Deprecate the `routing.loader.annotation` service, use the `routing.loader.attribute` service instead
35+
* Deprecate the `routing.loader.annotation.directory` service, use the `routing.loader.attribute.directory` service instead
36+
* Deprecate the `routing.loader.annotation.file` service, use the `routing.loader.attribute.file` service instead
37+
* Deprecate `AnnotatedRouteControllerLoader`, use `AttributeRouteControllerLoader` instead
3438

3539
6.3
3640
---

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
use Symfony\Component\RateLimiter\Storage\CacheStorage;
144144
use Symfony\Component\RemoteEvent\Attribute\AsRemoteEventConsumer;
145145
use Symfony\Component\RemoteEvent\RemoteEvent;
146-
use Symfony\Component\Routing\Loader\AnnotationClassLoader;
146+
use Symfony\Component\Routing\Loader\AttributeClassLoader;
147147
use Symfony\Component\Scheduler\Attribute\AsCronTask;
148148
use Symfony\Component\Scheduler\Attribute\AsPeriodicTask;
149149
use Symfony\Component\Scheduler\Attribute\AsSchedule;
@@ -1221,8 +1221,8 @@ private function registerRouterConfiguration(array $config, ContainerBuilder $co
12211221
->replaceArgument(0, $config['default_uri']);
12221222
}
12231223

1224-
if ($this->isInitializedConfigEnabled('annotations') && (new \ReflectionClass(AnnotationClassLoader::class))->hasProperty('reader')) {
1225-
$container->getDefinition('routing.loader.annotation')->setArguments([
1224+
if ($this->isInitializedConfigEnabled('annotations') && (new \ReflectionClass(AttributeClassLoader::class))->hasProperty('reader')) {
1225+
$container->getDefinition('routing.loader.attribute')->setArguments([
12261226
new Reference('annotation_reader'),
12271227
'%kernel.environment%',
12281228
]);

src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private function configureRoutes(RoutingConfigurator $routes): void
8585
}
8686

8787
if (false !== ($fileName = (new \ReflectionObject($this))->getFileName())) {
88-
$routes->import($fileName, 'annotation');
88+
$routes->import($fileName, 'attribute');
8989
}
9090
}
9191

src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.php

+17-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Symfony\Bundle\FrameworkBundle\CacheWarmer\RouterCacheWarmer;
1616
use Symfony\Bundle\FrameworkBundle\Controller\RedirectController;
1717
use Symfony\Bundle\FrameworkBundle\Controller\TemplateController;
18-
use Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader;
18+
use Symfony\Bundle\FrameworkBundle\Routing\AttributeRouteControllerLoader;
1919
use Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader;
2020
use Symfony\Bundle\FrameworkBundle\Routing\RedirectableCompiledUrlMatcher;
2121
use Symfony\Bundle\FrameworkBundle\Routing\Router;
@@ -24,8 +24,8 @@
2424
use Symfony\Component\Routing\Generator\CompiledUrlGenerator;
2525
use Symfony\Component\Routing\Generator\Dumper\CompiledUrlGeneratorDumper;
2626
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
27-
use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader;
28-
use Symfony\Component\Routing\Loader\AnnotationFileLoader;
27+
use Symfony\Component\Routing\Loader\AttributeDirectoryLoader;
28+
use Symfony\Component\Routing\Loader\AttributeFileLoader;
2929
use Symfony\Component\Routing\Loader\ContainerLoader;
3030
use Symfony\Component\Routing\Loader\DirectoryLoader;
3131
use Symfony\Component\Routing\Loader\GlobFileLoader;
@@ -92,26 +92,35 @@
9292
])
9393
->tag('routing.loader')
9494

95-
->set('routing.loader.annotation', AnnotatedRouteControllerLoader::class)
95+
->set('routing.loader.attribute', AttributeRouteControllerLoader::class)
9696
->args([
9797
'%kernel.environment%',
9898
])
9999
->tag('routing.loader', ['priority' => -10])
100100

101-
->set('routing.loader.annotation.directory', AnnotationDirectoryLoader::class)
101+
->alias('routing.loader.annotation', 'routing.loader.attribute')
102+
->deprecate('symfony/routing', '6.4', 'The "%alias_id%" service is deprecated, use the "routing.loader.attribute" service instead.')
103+
104+
->set('routing.loader.attribute.directory', AttributeDirectoryLoader::class)
102105
->args([
103106
service('file_locator'),
104-
service('routing.loader.annotation'),
107+
service('routing.loader.attribute'),
105108
])
106109
->tag('routing.loader', ['priority' => -10])
107110

108-
->set('routing.loader.annotation.file', AnnotationFileLoader::class)
111+
->alias('routing.loader.annotation.directory', 'routing.loader.attribute.directory')
112+
->deprecate('symfony/routing', '6.4', 'The "%alias_id%" service is deprecated, use the "routing.loader.attribute.directory" service instead.')
113+
114+
->set('routing.loader.attribute.file', AttributeFileLoader::class)
109115
->args([
110116
service('file_locator'),
111-
service('routing.loader.annotation'),
117+
service('routing.loader.attribute'),
112118
])
113119
->tag('routing.loader', ['priority' => -10])
114120

121+
->alias('routing.loader.annotation.file', 'routing.loader.attribute.file')
122+
->deprecate('symfony/routing', '6.4', 'The "%alias_id%" service is deprecated, use the "routing.loader.attribute.file" service instead.')
123+
115124
->set('routing.loader.psr4', Psr4DirectoryLoader::class)
116125
->args([
117126
service('file_locator'),

src/Symfony/Bundle/FrameworkBundle/Routing/AnnotatedRouteControllerLoader.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Routing;
1313

14-
use Symfony\Component\Routing\Loader\AnnotationClassLoader;
14+
use Symfony\Component\Routing\Loader\AttributeClassLoader;
1515
use Symfony\Component\Routing\Route;
1616

1717
/**
18-
* AnnotatedRouteControllerLoader is an implementation of AnnotationClassLoader
18+
* AnnotatedRouteControllerLoader is an implementation of AttributeClassLoader
1919
* that sets the '_controller' default based on the class and method names.
2020
*
21+
* @deprecated since Symfony 6.4, use {@see AttributeRouteControllerLoader} instead
22+
*
2123
* @author Fabien Potencier <fabien@symfony.com>
2224
*/
23-
class AnnotatedRouteControllerLoader extends AnnotationClassLoader
25+
class AnnotatedRouteControllerLoader extends AttributeClassLoader
2426
{
2527
/**
2628
* Configures the _controller default parameter of a given Route instance.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Routing;
13+
14+
/**
15+
* AttributeRouteControllerLoader is an implementation of AttributeClassLoader
16+
* that sets the '_controller' default based on the class and method names.
17+
*
18+
* @author Fabien Potencier <fabien@symfony.com>
19+
* @author Alexandre Daubois <alex.daubois@gmail.com>
20+
*/
21+
class AttributeRouteControllerLoader extends AnnotatedRouteControllerLoader
22+
{
23+
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Resources/config/routing.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ http_client_call:
6767

6868
uid:
6969
resource: "../../Controller/UidController.php"
70-
type: "annotation"
70+
type: "attribute"
7171

7272
send_notification:
7373
path: /send_notification
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
_routingconditionservice_bundle:
22
prefix: /
33
resource: "@RoutingConditionServiceBundle/Controller"
4-
type: annotation
4+
type: attribute

src/Symfony/Component/Routing/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ CHANGELOG
88
* Add native return type to `AnnotationClassLoader::setResolver()`
99
* Deprecate Doctrine annotations support in favor of native attributes
1010
* Change the constructor signature of `AnnotationClassLoader` to `__construct(?string $env = null)`, passing an annotation reader as first argument is deprecated
11+
* Deprecate `AnnotationClassLoader`, use `AttributeClassLoader` instead
12+
* Deprecate `AnnotationDirectoryLoader`, use `AttributeDirectoryLoader` instead
13+
* Deprecate `AnnotationFileLoader`, use `AttributeFileLoader` instead
1114

1215
6.2
1316
---

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

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
* }
4848
* }
4949
*
50+
* @deprecated since Symfony 6.4, use {@see AttributeClassLoader} instead
51+
*
5052
* @author Fabien Potencier <fabien@symfony.com>
5153
* @author Alexander M. Turek <me@derrabus.de>
5254
*/
@@ -262,6 +264,10 @@ protected function addRoute(RouteCollection $collection, object $annot, array $g
262264

263265
public function supports(mixed $resource, string $type = null): bool
264266
{
267+
if ('annotation' === $type) {
268+
trigger_deprecation('symfony/routing', '6.4', 'The "annotation" route type is deprecated, use the "attribute" route type instead.');
269+
}
270+
265271
return \is_string($resource) && preg_match('/^(?:\\\\?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)+$/', $resource) && (!$type || \in_array($type, ['annotation', 'attribute'], true));
266272
}
267273

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
* AnnotationDirectoryLoader loads routing information from annotations set
1919
* on PHP classes and methods.
2020
*
21+
* @deprecated since Symfony 6.4, use {@see AttributeDirectoryLoader} instead
22+
*
2123
* @author Fabien Potencier <fabien@symfony.com>
2224
*/
23-
class AnnotationDirectoryLoader extends AnnotationFileLoader
25+
class AnnotationDirectoryLoader extends AttributeFileLoader
2426
{
2527
/**
2628
* @throws \InvalidArgumentException When the directory does not exist or its routes cannot be parsed
@@ -67,6 +69,10 @@ public function supports(mixed $resource, string $type = null): bool
6769
}
6870

6971
if (\in_array($type, ['annotation', 'attribute'], true)) {
72+
if ('annotation' === $type) {
73+
trigger_deprecation('symfony/routing', '6.4', 'The "annotation" route type is deprecated, use the "attribute" route type instead.');
74+
}
75+
7076
return true;
7177
}
7278

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
* AnnotationFileLoader loads routing information from annotations set
2121
* on a PHP class and its methods.
2222
*
23+
* @deprecated since Symfony 6.4, use {@see AttributeFileLoader} instead
24+
*
2325
* @author Fabien Potencier <fabien@symfony.com>
2426
*/
2527
class AnnotationFileLoader extends FileLoader
2628
{
2729
protected $loader;
2830

29-
public function __construct(FileLocatorInterface $locator, AnnotationClassLoader $loader)
31+
public function __construct(FileLocatorInterface $locator, AttributeClassLoader $loader)
3032
{
3133
if (!\function_exists('token_get_all')) {
3234
throw new \LogicException('The Tokenizer extension is required for the routing annotation loaders.');
@@ -64,6 +66,10 @@ public function load(mixed $file, string $type = null): ?RouteCollection
6466

6567
public function supports(mixed $resource, string $type = null): bool
6668
{
69+
if ('annotation' === $type) {
70+
trigger_deprecation('symfony/routing', '6.4', 'The "annotation" route type is deprecated, use the "attribute" route type instead.');
71+
}
72+
6773
return \is_string($resource) && 'php' === pathinfo($resource, \PATHINFO_EXTENSION) && (!$type || \in_array($type, ['annotation', 'attribute'], true));
6874
}
6975

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Routing\Loader;
13+
14+
/**
15+
* AttributeClassLoader loads routing information from a PHP class and its methods.
16+
*
17+
* You need to define an implementation for the configureRoute() method. Most of the
18+
* time, this method should define some PHP callable to be called for the route
19+
* (a controller in MVC speak).
20+
*
21+
* The #[Route] attribute can be set on the class (for global parameters),
22+
* and on each method.
23+
*
24+
* The #[Route] attribute main value is the route path. The attribute also
25+
* recognizes several parameters: requirements, options, defaults, schemes,
26+
* methods, host, and name. The name parameter is mandatory.
27+
* Here is an example of how you should be able to use it:
28+
*
29+
* #[Route('/Blog')]
30+
* class Blog
31+
* {
32+
* #[Route('/', name: 'blog_index')]
33+
* public function index()
34+
* {
35+
* }
36+
* #[Route('/{id}', name: 'blog_post', requirements: ["id" => '\d+'])]
37+
* public function show()
38+
* {
39+
* }
40+
* }
41+
*
42+
* @author Fabien Potencier <fabien@symfony.com>
43+
* @author Alexander M. Turek <me@derrabus.de>
44+
* @author Alexandre Daubois <alex.daubois@gmail.com>
45+
*/
46+
abstract class AttributeClassLoader extends AnnotationClassLoader
47+
{
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Routing\Loader;
13+
14+
/**
15+
* AttributeDirectoryLoader loads routing information from attributes set
16+
* on PHP classes and methods.
17+
*
18+
* @author Fabien Potencier <fabien@symfony.com>
19+
* @author Alexandre Daubois <alex.daubois@gmail.com>
20+
*/
21+
class AttributeDirectoryLoader extends AnnotationDirectoryLoader
22+
{
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Routing\Loader;
13+
14+
/**
15+
* AttributeFileLoader loads routing information from attributes set
16+
* on a PHP class and its methods.
17+
*
18+
* @author Fabien Potencier <fabien@symfony.com>
19+
* @author Alexandre Daubois <alex.daubois@gmail.com>
20+
*/
21+
class AttributeFileLoader extends AnnotationFileLoader
22+
{
23+
}

src/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/AbstractClass.php renamed to src/Symfony/Component/Routing/Tests/Fixtures/AttributedClasses/AbstractClass.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses;
12+
namespace Symfony\Component\Routing\Tests\Fixtures\AttributedClasses;
1313

1414
use Symfony\Component\Routing\Annotation\Route;
1515

src/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/BarClass.php renamed to src/Symfony/Component/Routing/Tests/Fixtures/AttributedClasses/BarClass.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses;
12+
namespace Symfony\Component\Routing\Tests\Fixtures\AttributedClasses;
1313

1414
class BarClass
1515
{

src/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/BazClass.php renamed to src/Symfony/Component/Routing/Tests/Fixtures/AttributedClasses/BazClass.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses;
12+
namespace Symfony\Component\Routing\Tests\Fixtures\AttributedClasses;
1313

1414
class BazClass
1515
{

src/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/EncodingClass.php renamed to src/Symfony/Component/Routing/Tests/Fixtures/AttributedClasses/EncodingClass.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses;
3+
namespace Symfony\Component\Routing\Tests\Fixtures\AttributedClasses;
44

55
class EncodingClass
66
{

0 commit comments

Comments
 (0)
0