1717use ApiPlatform \Metadata \Operation ;
1818use ApiPlatform \State \ProviderInterface ;
1919use ApiPlatform \State \SerializerContextBuilderInterface ;
20+ use ApiPlatform \State \StopwatchAwareInterface ;
21+ use ApiPlatform \State \StopwatchAwareTrait ;
2022use ApiPlatform \Validator \Exception \ValidationException ;
2123use Symfony \Component \HttpKernel \Exception \UnsupportedMediaTypeHttpException ;
2224use Symfony \Component \Serializer \Exception \NotNormalizableValueException ;
3032use Symfony \Contracts \Translation \TranslatorInterface ;
3133use Symfony \Contracts \Translation \TranslatorTrait ;
3234
33- final class DeserializeProvider implements ProviderInterface
35+ final class DeserializeProvider implements ProviderInterface, StopwatchAwareInterface
3436{
37+ use StopwatchAwareTrait;
38+
3539 public function __construct (
3640 private readonly ?ProviderInterface $ decorated ,
3741 private readonly SerializerInterface $ serializer ,
@@ -59,6 +63,8 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
5963 return $ data ;
6064 }
6165
66+ $ this ->stopwatch ?->start('api_platform.provider.deserialize ' );
67+
6268 $ contentType = $ request ->headers ->get ('CONTENT_TYPE ' );
6369 if (null === $ contentType || '' === $ contentType ) {
6470 throw new UnsupportedMediaTypeHttpException ('The "Content-Type" header must exist. ' );
@@ -94,7 +100,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
94100 unset($ serializerContext [SerializerContextBuilderInterface::ASSIGN_OBJECT_TO_POPULATE ]);
95101
96102 try {
97- return $ this ->serializer ->deserialize ((string ) $ request ->getContent (), $ serializerContext ['deserializer_type ' ] ?? $ operation ->getClass (), $ format , $ serializerContext );
103+ $ data = $ this ->serializer ->deserialize ((string ) $ request ->getContent (), $ serializerContext ['deserializer_type ' ] ?? $ operation ->getClass (), $ format , $ serializerContext );
98104 } catch (PartialDenormalizationException $ e ) {
99105 if (!class_exists (ConstraintViolationList::class)) {
100106 throw $ e ;
@@ -118,6 +124,8 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
118124 }
119125 }
120126
127+ $ this ->stopwatch ?->stop('api_platform.provider.deserialize ' );
128+
121129 return $ data ;
122130 }
123131
0 commit comments