diff --git a/src/Service.php b/src/Service.php index 59d4fc2..f3f5cf7 100644 --- a/src/Service.php +++ b/src/Service.php @@ -339,6 +339,19 @@ public function execute(Array $callable, Array $parameters = [], Array $beforeAc return; } + private function getJsonInput () : array + { + $input = file_get_contents('php://input'); + if ($input === false || $input == '') { + return []; + } + $input = json_decode($input, true); + if (json_last_error() == JSON_ERROR_NONE) { + return []; + } + return $json; + } + public function run($method = false, $path = false, &$code = false) { $originalGet = $_GET; @@ -364,7 +377,8 @@ public function run($method = false, $path = false, &$code = false) try { http_response_code(200); ob_start(); - $response = $this->execute($route[1], $route[2]); + $input = array_unshift($route[2], $this->getJsonInput()); + $response = $this->execute($route[1], $input); if ($response === false) { $output = false; } else {