From 60513b6dad55bcbfe45e53a472101a633eb0b67c Mon Sep 17 00:00:00 2001 From: Maxime Steinhausser Date: Thu, 24 Nov 2022 09:43:49 +0100 Subject: [PATCH] [HttpKernel] Move the backed enum value resolver deprecation trigger to the constructor --- .../BackedEnumValueResolver.php | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Bridge/Symfony/HttpKernel/Controller/ArgumentResolver/BackedEnumValueResolver.php b/src/Bridge/Symfony/HttpKernel/Controller/ArgumentResolver/BackedEnumValueResolver.php index 202f18c..7b2feb1 100644 --- a/src/Bridge/Symfony/HttpKernel/Controller/ArgumentResolver/BackedEnumValueResolver.php +++ b/src/Bridge/Symfony/HttpKernel/Controller/ArgumentResolver/BackedEnumValueResolver.php @@ -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, @@ -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)) {