Skip to content

Commit

Permalink
read json from request body provide it as first argument to controller
Browse files Browse the repository at this point in the history
  • Loading branch information
rmahoney-bl committed Nov 10, 2016
1 parent 157bc3a commit d1b23d3
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down

0 comments on commit d1b23d3

Please sign in to comment.