From 62c4f2fa0bdcff6568d4153dfd3d7861d4fd23b7 Mon Sep 17 00:00:00 2001 From: Berkus Date: Fri, 23 May 2014 03:29:33 +0300 Subject: [PATCH 1/2] Add support for parsed JSON property in Request. --- flight/net/Request.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/flight/net/Request.php b/flight/net/Request.php index 1947b37..81c64a3 100644 --- a/flight/net/Request.php +++ b/flight/net/Request.php @@ -28,7 +28,8 @@ use flight\util\Collection; * type - The content type * length - The content length * query - Query string parameters - * data - Post parameters + * data - Post parameters + * json - JSON decoded body for application/json requests * cookies - Cookie parameters * files - Uploaded files */ @@ -98,6 +99,11 @@ class Request { */ public $data; + /** + * @var \flight\util\Collection JSON decoded body + */ + public $json; + /** * @var \flight\util\Collection Cookie parameters */ @@ -178,6 +184,14 @@ class Request { $this->query->setData($_GET); } + + if ($this->type == 'application/json' && $this->body != '') + { + $v = json_decode($this->body, true); + if ($v) { + $this->json = /*new Collection(*/$v;//); + } + } } /** From c0c7b9dcd948d7e5facd9ca878ddbe5b61d71bd1 Mon Sep 17 00:00:00 2001 From: Berkus Decker Date: Fri, 23 May 2014 10:03:55 +0300 Subject: [PATCH 2/2] Modify Request based on feedback from Mike. --- flight/net/Request.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/flight/net/Request.php b/flight/net/Request.php index 81c64a3..7ac0773 100644 --- a/flight/net/Request.php +++ b/flight/net/Request.php @@ -185,12 +185,8 @@ class Request { $this->query->setData($_GET); } - if ($this->type == 'application/json' && $this->body != '') - { - $v = json_decode($this->body, true); - if ($v) { - $this->json = /*new Collection(*/$v;//); - } + if ($this->type == 'application/json' && $this->body != '') { + $this->json = json_decode($this->body, true); } }