Skip to content

Commit 3640a88

Browse files
committed
feature #40555 [HttpKernel] Add #[AsController] attribute for declaring standalone controllers on PHP 8 (nicolas-grekas)
This PR was merged into the 5.3-dev branch. Discussion ---------- [HttpKernel] Add `#[AsController]` attribute for declaring standalone controllers on PHP 8 | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - This PR adds an `#[AsController]` attribute to allow autoconfiguring controllers even when they don't extend `AbstractController`. This should allow removing the line about `controller.service_arguments` in `services.yaml` to cover this need (but that is noise to most.) Commits ------- 437f5fe [HttpKernel] Add `#[AsController]` attribute for declaring listeners on PHP 8
2 parents 019e29b + 437f5fe commit 3640a88

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
use Symfony\Component\HttpClient\ScopingHttpClient;
7575
use Symfony\Component\HttpFoundation\Request;
7676
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface;
77+
use Symfony\Component\HttpKernel\Attribute\AsController;
7778
use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;
7879
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
7980
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
@@ -558,6 +559,9 @@ public function load(array $configs, ContainerBuilder $container)
558559
$container->registerAttributeForAutoconfiguration(EventListener::class, static function (ChildDefinition $definition, EventListener $attribute): void {
559560
$definition->addTag('kernel.event_listener', get_object_vars($attribute));
560561
});
562+
$container->registerAttributeForAutoconfiguration(AsController::class, static function (ChildDefinition $definition, AsController $attribute): void {
563+
$definition->addTag('controller.service_arguments');
564+
});
561565

562566
if (!$container->getParameter('kernel.debug')) {
563567
// remove tagged iterator argument for resource checkers
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\HttpKernel\Attribute;
13+
14+
/**
15+
* Service tag to autoconfigure controllers.
16+
*/
17+
#[\Attribute(\Attribute::TARGET_CLASS)]
18+
class AsController
19+
{
20+
public function __construct()
21+
{
22+
}
23+
}

src/Symfony/Component/HttpKernel/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ CHANGELOG
1111
* Deprecate returning a `ContainerBuilder` from `KernelInterface::registerContainerConfiguration()`
1212
* Deprecate `HttpKernelInterface::MASTER_REQUEST` and add `HttpKernelInterface::MAIN_REQUEST` as replacement
1313
* Deprecate `KernelEvent::isMasterRequest()` and add `isMainRequest()` as replacement
14+
* Add `#[AsController]` attribute for declaring standalone controllers on PHP 8
1415

1516
5.2.0
1617
-----

0 commit comments

Comments
 (0)