8000 feature #49358 [Routing] Deprecate annotations in favor of attributes… · symfony/framework-bundle@c1e3cbb · GitHub
[go: up one dir, main page]

Skip to content

Commit c1e3cbb

Browse files
feature #49358 [Routing] Deprecate annotations in favor of attributes (derrabus)
This PR was merged into the 6.4 branch. Discussion ---------- [Routing] Deprecate annotations in favor of attributes | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | yes | Deprecations? | yes | Tickets | Follows #50888 | License | MIT | Doc PR | TODO, see symfony/symfony-docs#18589 This PR deprecates the integration of Doctrine Annotations for the Routing component. Attributes are the way to go now if we want to annotate controllers with routing information. Existing applications can be migrated easily using [Rector](https://getrector.com/blog/how-to-upgrade-annotations-to-attributes). Thus I believe that keeping support for oldschool Doctrine Annotations is not necessary anymore. If this PR is accepted, I would work on a follow-up that renames all `Annotation*Loader` classes because the names of those classes are probably misleading as soon as they support attributes only. Commits ------- 6ce15f22b1 [Routing] Deprecate annotations in favor of attributes
2 parents 9e7fc15 + 0af35fc commit c1e3cbb

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

DependencyInjection/FrameworkExtension.php

+8
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
use Symfony\Component\RateLimiter\Storage\CacheStorage;
145145
use Symfony\Component\RemoteEvent\Attribute\AsRemoteEventConsumer;
146146
use Symfony\Component\RemoteEvent\RemoteEvent;
147+
use Symfony\Component\Routing\Loader\AnnotationClassLoader;
147148
use Symfony\Component\Routing\Loader\Psr4DirectoryLoader;
148149
use Symfony\Component\Scheduler\Attribute\AsSchedule;
149150
use Symfony\Component\Scheduler\Messenger\SchedulerTransportFactory;
@@ -1180,6 +1181,13 @@ private function registerRouterConfiguration(array $config, ContainerBuilder $co
11801181
if (!class_exists(Psr4DirectoryLoader::class)) {
11811182
$container->removeDefinition('routing.loader.psr4');
11821183
}
1184+
1185+
if ($this->isInitializedConfigEnabled('annotations') && (new \ReflectionClass(AnnotationClassLoader::class))->hasProperty('reader')) {
1186+
$container->getDefinition('routing.loader.annotation')->setArguments([
1187+
new Reference('annotation_reader'),
1188+
'%kernel.environment%',
1189+
]);
1190+
}
11831191
}
11841192

11851193
private function registerSessionConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader): void

Resources/config/routing.php

-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@
9494

9595
->set('routing.loader.annotation', AnnotatedRouteControllerLoader::class)
9696
->args([
97-
service('annotation_reader')->nullOnInvalid(),
9897
'%kernel.environment%',
9998
])
10099
->tag('routing.loader', ['priority' => -10])

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"symfony/polyfill-mbstring": "~1.0",
3131
"symfony/filesystem": "^5.4|^6.0|^7.0",
3232
"symfony/finder": "^5.4|^6.0|^7.0",
33-
"symfony/routing": "^6.1|^7.0"
33+
"symfony/routing": "^6.4|^7.0"
3434
},
3535
"require-dev": {
3636
"doctrine/annotations": "^1.13.1|^2",

0 commit comments

Comments
 (0)
0