diff --git a/README.md b/README.md index aeb31d0..b04fd8d 100644 --- a/README.md +++ b/README.md @@ -673,12 +673,11 @@ ip - IP address of the client ajax - Whether the request is an AJAX request scheme - The server protocol (http, https) user_agent - Browser information -body - Raw data from the request body type - The content type length - The content length query - Query string parameters -data - Post parameters -cookies - Cookie parameters +data - Post data or JSON data +cookies - Cookie data files - Uploaded files secure - Whether the connection is secure accept - HTTP accept parameters @@ -700,6 +699,23 @@ Or you can do: $id = Flight::request()->query->id; ``` +## RAW Request Body + +To get the raw HTTP request body, for example when dealing with PUT requests, you can do: + +```php +$body = Flight::request()->getBody(); +``` + +## JSON Input + +If you send request with the type `application/json` and the data `{"id": 123}` it will be availabe +from the `data` property: + +```php +$id = Flight::request()->data->id; +``` + # HTTP Caching Flight provides built-in support for HTTP level caching. If the caching condition diff --git a/VERSION b/VERSION index 5ed5faa..9ee1f78 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.10 +1.1.11 diff --git a/flight/net/Request.php b/flight/net/Request.php index 587475b..369dc13 100644 --- a/flight/net/Request.php +++ b/flight/net/Request.php @@ -93,11 +93,6 @@ class Request { */ public $data; - /** - * @var \flight\util\Collection JSON decoded body - */ - public $json; - /** * @var \flight\util\Collection Cookie parameters */ @@ -146,7 +141,6 @@ class Request { 'data' => new Collection($_POST), 'cookies' => new Collection($_COOKIE), 'files' => new Collection($_FILES), - 'json' => new Collection(), 'secure' => self::getVar('HTTPS', 'off') != 'off', 'accept' => self::getVar('HTTP_ACCEPT'), 'proxy_ip' => self::getProxyIpAddress() @@ -186,9 +180,11 @@ class Request { // Check for JSON input if (strpos($this->type, 'application/json') === 0) { $body = $this->getBody(); - if ($body != '') { - $this->json->setData(json_decode($body, true)); + $data = json_decode($body, true); + if ($data != null) { + $this->data->setData($data); + } } } }