JsonResponse.php
9 years ago
Request.php
9 years ago
Response.php
8 years ago
Router.php
8 years ago
Request.php
42 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Wpae\Http; |
| 4 | |
| 5 | |
| 6 | class Request |
| 7 | { |
| 8 | private $content; |
| 9 | |
| 10 | public function __construct($content) |
| 11 | { |
| 12 | $this->content = $content; |
| 13 | } |
| 14 | |
| 15 | public function getRawContent() |
| 16 | { |
| 17 | return $this->content; |
| 18 | } |
| 19 | |
| 20 | public function getJsonParams() |
| 21 | { |
| 22 | if(!empty($this->content) && $this->content !== "null") { |
| 23 | |
| 24 | $jsonDecodedContent = json_decode($this->content, true); |
| 25 | |
| 26 | if (is_null($jsonDecodedContent)) { |
| 27 | throw new \Exception('Invalid JON Provided'); |
| 28 | } |
| 29 | |
| 30 | return $jsonDecodedContent; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | public function get($element, $default = null) |
| 35 | { |
| 36 | if(isset($_GET[$element])) { |
| 37 | return $_GET[$element]; |
| 38 | } else { |
| 39 | return $default; |
| 40 | } |
| 41 | } |
| 42 | } |