Skip to content

Commit

Permalink
bug #205 [HttpKernel] Move the backed enum value resolver deprecation…
Browse files Browse the repository at this point in the history
… trigger to the constructor (ogizanagi)

This PR was merged into the 2.x-dev branch.

Discussion
----------

[HttpKernel] Move the backed enum value resolver deprecation trigger to the constructor

Since the controller arg resolvers are added to the `annotations.map` [file from the `FrameworkExtension`](symfony/symfony@feb5e62), the class was loaded during warmup and the deprec was triggered even if the class is not used in the app.

So let's move it to the constructor.

Commits
-------

60513b6 [HttpKernel] Move the backed enum value resolver deprecation trigger to the constructor
  • Loading branch information
ogizanagi committed Nov 25, 2022
2 parents baae644 + 60513b6 commit d32d60a
Showing 1 changed file with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

// Suggest using Symfony 6.1+ resolver
if (class_exists(SymfonyBackedEnumValueResolver::class)) {
trigger_deprecation(
'elao/enum',
'2.1',
'The "%s" class is deprecated with "symfony/http-kernel" >= 6.1, use "%s" instead.',
BackedEnumValueResolver::class,
SymfonyBackedEnumValueResolver::class
);
}

// Legacy (<6.1) resolver
/**
* Attempt to resolve backed enum cases from request attributes, for a route path parameter,
Expand All @@ -40,6 +29,20 @@
*/
class BackedEnumValueResolver implements ArgumentValueResolverInterface
{
public function __construct()
{
// Suggest using Symfony 6.1+ resolver
if (class_exists(SymfonyBackedEnumValueResolver::class)) {
trigger_deprecation(
'elao/enum',
'2.1',
'The "%s" class is deprecated with "symfony/http-kernel" >= 6.1, use "%s" instead.',
__CLASS__,
SymfonyBackedEnumValueResolver::class
);
}
}

public function supports(Request $request, ArgumentMetadata $argument): bool
{
if (!is_subclass_of($argument->getType(), \BackedEnum::class)) {
Expand Down

0 comments on commit d32d60a

Please sign in to comment.