17
17
use ApiPlatform \Metadata \Operation ;
18
18
use ApiPlatform \State \ProviderInterface ;
19
19
use ApiPlatform \State \SerializerContextBuilderInterface ;
20
+ use ApiPlatform \State \StopwatchAwareInterface ;
21
+ use ApiPlatform \State \StopwatchAwareTrait ;
20
22
use ApiPlatform \Validator \Exception \ValidationException ;
21
23
use Symfony \Component \HttpKernel \Exception \UnsupportedMediaTypeHttpException ;
22
24
use Symfony \Component \Serializer \Exception \NotNormalizableValueException ;
30
32
use Symfony \Contracts \Translation \TranslatorInterface ;
31
33
use Symfony \Contracts \Translation \TranslatorTrait ;
32
34
33
- final class DeserializeProvider implements ProviderInterface
35
+ final class DeserializeProvider implements ProviderInterface, StopwatchAwareInterface
34
36
{
37
+ use StopwatchAwareTrait;
38
+
35
39
public function __construct (
36
40
private readonly ?ProviderInterface $ decorated ,
37
41
private readonly SerializerInterface $ serializer ,
@@ -59,6 +63,8 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
59
63
return $ data ;
60
64
}
61
65
66
+ $ this ->stopwatch ?->start('api_platform.provider.deserialize ' );
67
+
62
68
$ contentType = $ request ->headers ->get ('CONTENT_TYPE ' );
63
69
if (null === $ contentType || '' === $ contentType ) {
64
70
throw new UnsupportedMediaTypeHttpException ('The "Content-Type" header must exist. ' );
@@ -94,7 +100,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
94
100
unset($ serializerContext [SerializerContextBuilderInterface::ASSIGN_OBJECT_TO_POPULATE ]);
95
101
96
102
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 );
98
104
} catch (PartialDenormalizationException $ e ) {
99
105
if (!class_exists (ConstraintViolationList::class)) {
100
106
throw $ e ;
@@ -118,6 +124,8 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
118
124
}
119
125
}
120
126
127
+ $ this ->stopwatch ?->stop('api_platform.provider.deserialize ' );
128
+
121
129
return $ data ;
122
130
}
123
131
0 commit comments