@@ -21,16 +21,11 @@ public function __construct(PayloadValidator $payloadValidator)
21
21
public function onKernelRequest (GetResponseEvent $ event )
22
22
{
23
23
$ request = $ event ->getRequest ();
24
- $ method = $ request ->getMethod ();
25
-
26
- if (count ($ request ->request ->all ())
27
- || !in_array ($ method , ['POST ' , 'PUT ' , 'PATCH ' , 'DELETE ' , 'LINK ' , 'UNLINK ' ])
28
- ) {
24
+ if (!in_array ($ request ->getMethod (), ['POST ' , 'PUT ' , 'PATCH ' , 'DELETE ' , 'LINK ' , 'UNLINK ' ])) {
29
25
return ;
30
26
}
31
27
32
28
$ contentType = $ request ->headers ->get ('Content-Type ' );
33
-
34
29
$ format = null === $ contentType
35
30
? $ request ->getRequestFormat ()
36
31
: $ request ->getFormat ($ contentType );
@@ -40,20 +35,20 @@ public function onKernelRequest(GetResponseEvent $event)
40
35
}
41
36
42
37
$ content = $ request ->getContent ();
38
+ if (empty ($ content )) {
39
+ return ;
40
+ }
43
41
44
- if (!empty ($ content )) {
45
- $ data = @json_decode ($ content , true );
46
-
47
- if (!is_array ($ data )) {
48
- throw new BadRequestHttpException ('Invalid ' . $ format . ' message received ' );
49
- }
50
-
51
- $ jsonSchema = $ request ->get ('_jsonSchema ' );
52
- if (is_array ($ jsonSchema ) && array_key_exists ('request ' , $ jsonSchema )) {
53
- $ this ->payloadValidator ->validate ($ content , $ jsonSchema ['request ' ]);
54
- }
42
+ $ data = @json_decode ($ content , true );
43
+ if (!is_array ($ data )) {
44
+ throw new BadRequestHttpException ('Invalid ' . $ format . ' message received ' );
45
+ }
55
46
56
- $ request ->request = new ParameterBag ($ data );
47
+ $ jsonSchema = $ request ->get ('_jsonSchema ' );
48
+ if (is_array ($ jsonSchema ) && array_key_exists ('request ' , $ jsonSchema )) {
49
+ $ this ->payloadValidator ->validate ($ content , $ jsonSchema ['request ' ]);
57
50
}
51
+
52
+ $ request ->request = new ParameterBag ($ data );
58
53
}
59
54
}
0 commit comments