Skip to content

Commit 8d83a90

Browse files
GromNaNfabpot
authored andcommitted
Enable controller service with #[Route] attribute instead of #[AsController]
1 parent 90cd2c4 commit 8d83a90

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ CHANGELOG
1919
* Add DI alias from `ServicesResetterInterface` to `services_resetter`
2020
* Add `methods` argument in `#[IsCsrfTokenValid]` attribute
2121
* Allow configuring the logging channel per type of exceptions
22+
* Enable service argument resolution on classes that use the `#[Route]` attribute,
23+
the `#[AsController]` attribute is no longer required
2224

2325
7.2
2426
---

DependencyInjection/FrameworkExtension.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@
164164
use Symfony\Component\RateLimiter\Storage\CacheStorage;
165165
use Symfony\Component\RemoteEvent\Attribute\AsRemoteEventConsumer;
166166
use Symfony\Component\RemoteEvent\RemoteEvent;
167+
use Symfony\Component\Routing\Attribute\Route;
167168
use Symfony\Component\Scheduler\Attribute\AsCronTask;
168169
use Symfony\Component\Scheduler\Attribute\AsPeriodicTask;
169170
use Symfony\Component\Scheduler\Attribute\AsSchedule;
@@ -429,7 +430,7 @@ public function load(array $configs, ContainerBuilder $container): void
429430
}
430431
$loggers[$exception['log_channel']] = new Reference('monolog.logger.'.$exception['log_channel'], ContainerInterface::NULL_ON_INVALID_REFERENCE);
431432
}
432-
433+
433434
$exceptionListener
434435
->replaceArgument(3, $config['exceptions'])
435436
->setArgument(4, $loggers)
@@ -739,6 +740,9 @@ public function load(array $configs, ContainerBuilder $container): void
739740
$container->registerAttributeForAutoconfiguration(AsController::class, static function (ChildDefinition $definition, AsController $attribute): void {
740741
$definition->addTag('controller.service_arguments');
741742
});
743+
$container->registerAttributeForAutoconfiguration(Route::class, static function (ChildDefinition $definition, Route $attribute, \ReflectionClass|\ReflectionMethod $reflection): void {
744+
$definition->addTag('controller.service_arguments');
745+
});
742746
$container->registerAttributeForAutoconfiguration(AsRemoteEventConsumer::class, static function (ChildDefinition $definition, AsRemoteEventConsumer $attribute): void {
743747
$definition->addTag('remote_event.consumer', ['consumer' => $attribute->name]);
744748
});

0 commit comments

Comments
 (0)