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

Skip to content

Commit 708b1b6

Browse files
alexandre-dauboisnicolas-grekas
authored andcommitted
[FrameworkBundle][Routing] Deprecate annotations
1 parent 6337e5f commit 708b1b6

34 files changed

+1087
-895
lines changed

.github/expected-missing-return-types.diff

+209-209
Large diffs are not rendered by default.

UPGRADE-6.4.md

+7
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ FrameworkBundle
139139
| `framework.validation.email_validation_mode` | `'loose'` | `'html5'` |
140140
* Deprecate `framework.validation.enable_annotations`, use `framework.validation.enable_attributes` instead
141141
* Deprecate `framework.serializer.enable_annotations`, use `framework.serializer.enable_attributes` instead
142+
* Deprecate the `routing.loader.annotation` service, use the `routing.loader.attribute` service instead
143+
* Deprecate the `routing.loader.annotation.directory` service, use the `routing.loader.attribute.directory` service instead
144+
* Deprecate the `routing.loader.annotation.file` service, use the `routing.loader.attribute.file` service instead
145+
* Deprecate `AnnotatedRouteControllerLoader`, use `AttributeRouteControllerLoader` instead
142146

143147
HttpFoundation
144148
--------------
@@ -181,6 +185,9 @@ Routing
181185
* [BC break] Add native return type to `AnnotationClassLoader::setResolver()`
182186
* Deprecate Doctrine annotations support in favor of native attributes
183187
* Deprecate passing an annotation reader as first argument to `AnnotationClassLoader` (new signature: `__construct(?string $env = null)`)
188+
* Deprecate `AnnotationClassLoader`, use `AttributeClassLoader` instead
189+
* Deprecate `AnnotationDirectoryLoader`, use `AttributeDirectoryLoader` instead
190+
* Deprecate `AnnotationFileLoader`, use `AttributeFileLoader` instead
184191

185192
Security
186193
--------

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ CHANGELOG
3434
* Change `framework.asset_mapper.importmap_polyfill` from a URL to the name of an item in the importmap
3535
* Provide `$buildDir` when running `CacheWarmer` to build read-only resources
3636
* Add the global `--profile` option to the console to enable profiling commands
37+
* Deprecate the `routing.loader.annotation` service, use the `routing.loader.attribute` service instead
38+
* Deprecate the `routing.loader.annotation.directory` service, use the `routing.loader.attribute.directory` service instead
39+
* Deprecate the `routing.loader.annotation.file` service, use the `routing.loader.attribute.file` service instead
40+
* Deprecate `AnnotatedRouteControllerLoader`, use `AttributeRouteControllerLoader` instead
3741

3842
6.3
3943
---

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;
@@ -1226,8 +1226,8 @@ private function registerRouterConfiguration(array $config, ContainerBuilder $co
12261226
->replaceArgument(0, $config['default_uri']);
12271227
}
12281228

1229-
if ($this->isInitializedConfigEnabled('annotations') && (new \ReflectionClass(AnnotationClassLoader::class))->hasProperty('reader')) {
1230-
$container->getDefinition('routing.loader.annotation')->setArguments([
1229+
if ($this->isInitializedConfigEnabled('annotations') && (new \ReflectionClass(AttributeClassLoader::class))->hasProperty('reader')) {
1230+
$container->getDefinition('routing.loader.attribute')->setArguments([
12311231
new Reference('annotation_reader'),
12321232
'%kernel.environment%',
12331233
]);

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-32
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,15 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Routing;
1313

14-
use Symfony\Component\Routing\Loader\AnnotationClassLoader;
15-
use Symfony\Component\Routing\Route;
14+
trigger_deprecation('symfony/framework-bundle', '6.4', 'The "%s" class is deprecated, use "%s" instead.', AnnotatedRouteControllerLoader::class, AttributeRouteControllerLoader::class);
1615

17-
/**
18-
* AnnotatedRouteControllerLoader is an implementation of AnnotationClassLoader
19-
* that sets the '_controller' default based on the class and method names.
20-
*
21-
* @author Fabien Potencier <fabien@symfony.com>
22-
*/
23-
class AnnotatedRouteControllerLoader extends AnnotationClassLoader
24-
{
25-
/**
26-
* Configures the _controller default parameter of a given Route instance.
27-
*
28-
* @return void
29-
*/
30-
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot)
31-
{
32-
if ('__invoke' === $method->getName()) {
33-
$route->setDefault('_controller', $class->getName());
34-
} else {
35-
$route->setDefault('_controller', $class->getName().'::'.$method->getName());
36-
}
37-
}
16+
class_exists(AttributeRouteControllerLoader::class);
3817

18+
if (false) {
3919
/**
40-
* Makes the default route name more sane by removing common keywords.
20+
* @deprecated since Symfony 6.4, to be removed in 7.0, use {@link AttributeRouteControllerLoader} instead
4121
*/
42-
protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method): string
22+
class AnnotatedRouteControllerLoader
4323
{
44-
$name = preg_replace('/(bundle|controller)_/', '_', parent::getDefaultRouteName($class, $method));
45-
46-
if (str_ends_with($method->name, 'Action') || str_ends_with($method->name, '_action')) {
47-
$name = preg_replace('/action(_\d+)?$/', '\\1', $name);
48-
}
49-
50-
return str_replace('__', '_', $name);
5124
}
5225
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
use Symfony\Component\Routing\Loader\AttributeClassLoader;
15+
use Symfony\Component\Routing\Route;
16+
17+
/**
18+
* AttributeRouteControllerLoader is an implementation of AttributeClassLoader
19+
* that sets the '_controller' default based on the class and method names.
20+
*
21+
* @author Fabien Potencier <fabien@symfony.com>
22+
* @author Alexandre Daubois <alex.daubois@gmail.com>
23+
*/
24+
class AttributeRouteControllerLoader extends AttributeClassLoader
25+
{
26+
/**
27+
* Configures the _controller default parameter of a given Route instance.
28+
*
29+
* @return void
30+
*/
31+
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot)
32+
{
33+
if ('__invoke' === $method->getName()) {
34+
$route->setDefault('_controller', $class->getName());
35+
} else {
36+
$route->setDefault('_controller', $class->getName().'::'.$method->getName());
37+
}
38+
}
39+
40+
/**
41+
* Makes the default route name more sane by removing common keywords.
42+
*/
43+
protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method): string
44+
{
45+
$name = preg_replace('/(bundle|controller)_/', '_', parent::getDefaultRouteName($class, $method));
46+
47+
if (str_ends_with($method->name, 'Action') || str_ends_with($method->name, '_action')) {
48+
$name = preg_replace('/action(_\d+)?$/', '\\1', $name);
49+
}
50+
51+
return str_replace('__', '_', $name);
52+
}
53+
}
54+
55+
if (!class_exists(AnnotatedRouteControllerLoader::class, false)) {
56+
class_alias(AttributeRouteControllerLoader::class, AnnotatedRouteControllerLoader::class);
57+
}

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
---

0 commit comments

Comments
 (0)
0