Skip to content

Commit

Permalink
Updates for getPost and quick fix for routing
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertGrubb committed Jun 30, 2020
1 parent ad12dbd commit f1a628c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/CoolApi/Core/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ public function get($key = null) {

// Retrieve POST variables
public function post($key = null) {
if (is_null($key)) return $_POST;
if (isset($_POST[$key])) {
return $_POST[$key];
$post = \CoolApi\Core\Utilities::getPost();

if (is_null($key)) return $post;
if (isset($post[$key])) {
return $post[$key];
} else {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/CoolApi/Core/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ private function route ($route, $method) {

// Do checks for baseUri
if ($this->instance->config->baseUri !== '/') {
$route = ltrim($route, $this->instance->config->baseUri);
$route = str_replace($this->instance->config->baseUri, '', $route);
}

// If the route is empty, load the home route.
Expand Down
9 changes: 9 additions & 0 deletions src/CoolApi/Core/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,13 @@ public static function merge_config (array &$array1, array &$array2) {
print_r($merged);
}

public static function getPost () {
if(!empty($_POST)) return $_POST;

$post = json_decode(file_get_contents('php://input'), true);
if(json_last_error() == JSON_ERROR_NONE) return $post;

return [];
}

}

0 comments on commit f1a628c

Please sign in to comment.