From 4a2d086ae42195e3cda0007fe184c0b48d2897d3 Mon Sep 17 00:00:00 2001 From: Igor Ilic Date: Wed, 15 Sep 2021 23:55:16 +0200 Subject: [PATCH] Fix not getting request body for PATCH and PUT --- Request.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Request.php b/Request.php index 2c1237b..23148c3 100644 --- a/Request.php +++ b/Request.php @@ -16,7 +16,13 @@ class Request */ public function __construct() { - $input = json_decode(file_get_contents('php://input')) ?? []; + $rawInput = file_get_contents('php://input'); + + $input = json_decode($rawInput) ?? []; + if ( count($input) == 0 ) { + mb_parse_str($rawInput, $input); + } + if ( isset($_SERVER["REQUEST_METHOD"]) && $_SERVER['REQUEST_METHOD'] == 'PATCH' ) { if ( isset($_REQUEST["parameters"]) ) { $_REQUEST = array_merge($_REQUEST, $_REQUEST['parameters']); @@ -78,4 +84,4 @@ public function send(string|array|object $output) { echo json_encode($output); } - } \ No newline at end of file + }