Skip to content

Commit

Permalink
[HttpKernel] Move the backed enum value resolver deprecation trigger …
Browse files Browse the repository at this point in the history
…to the constructor
  • Loading branch information
ogizanagi committed Nov 24, 2022
1 parent baae644 commit 60513b6
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 60513b6

Please sign in to comment.