File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -46,12 +46,27 @@ public function init()
46
46
$ contentType = (string ) $ this ->request ->getHeader ('Content-Type ' );
47
47
48
48
if (strpos ($ contentType , 'application/json ' ) !== false ) {
49
- $ input = json_decode (file_get_contents ("php://input " ), true );
49
+ $ jsonPayload = trim (file_get_contents ("php://input " ));
50
+ $ input = json_decode ($ jsonPayload , true );
50
51
51
52
if ($ input ) {
52
53
$ this ->vars = array_merge ($ input , $ this ->request ->getVars ());
54
+ } else if ($ jsonPayload ) {
55
+ $ error = json_last_error ();
56
+
57
+ switch ($ error ) {
58
+ case JSON_ERROR_NONE :
59
+ $ this ->vars = $ this ->request ->getVars ();
60
+ break ;
61
+ default :
62
+ $ this ->failure ([
63
+ 'error ' => 'Invalid JSON ' ,
64
+ 'code ' => $ error
65
+ ]);
66
+ break ;
67
+ }
53
68
} else {
54
- $ this ->vars = $ this ->request ->getVars ();
69
+ $ this ->vars = $ this ->request ->requestVars ();
55
70
}
56
71
} else {
57
72
$ this ->vars = $ this ->request ->requestVars ();
@@ -377,7 +392,6 @@ public function getVar($name)
377
392
public function hasVar ($ name )
378
393
{
379
394
$ key = strtolower ($ name );
380
-
381
395
return (isset ($ this ->vars [$ key ]));
382
396
}
383
397
You can’t perform that action at this time.
0 commit comments