From 2034fefbdffe9ecde0fa0c12e8187b26073837d8 Mon Sep 17 00:00:00 2001 From: TENMAJKL Date: Tue, 31 Aug 2021 12:53:59 +0200 Subject: [PATCH] Fix: Request, Env, Version, License Rename: Booter->app --- LICENCE.md => LICENSE.md | 0 README.md | 2 +- src/Http/Request.php | 74 ++++++++-------------- src/Kernel/Lemonade/Builders/templates.php | 2 +- src/Kernel/Lemonade/Helpers/info.php | 2 +- src/Utils/Env.php | 13 ++-- 6 files changed, 38 insertions(+), 55 deletions(-) rename LICENCE.md => LICENSE.md (100%) diff --git a/LICENCE.md b/LICENSE.md similarity index 100% rename from LICENCE.md rename to LICENSE.md diff --git a/README.md b/README.md index 82fb8679..9c4747c8 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # 🍋 Lemon Lemon is dead simple php micro framework.\ -Latest version: 2.4.4\ +Latest version: 2.5.1\ Documentation: WIP (Contribution welcomed) # Why? diff --git a/src/Http/Request.php b/src/Http/Request.php index 8e0bd705..f22d3907 100644 --- a/src/Http/Request.php +++ b/src/Http/Request.php @@ -5,126 +5,108 @@ class Request { /** - * * Request headers - * - * */ + */ public $headers; /** - * * Request method - * - * */ + */ public $method; /** - * - * Json sent to server - * - * */ + * JSON POST input + */ public $json; /** - * * POST input - * - * */ + */ public $input; /** - * - * GET input - * - * */ + * GET query + */ public $query; /** - * * All input data - * - * */ + */ public $data; /** - * - * Sets all request data + * Request body + */ + public $body; + + /** + * Parses all request data * * @param Array $query - * - * */ + */ function __construct($query) { - $this->headers = getallheaders(); + $this->headers = getallheaders(); $this->method = $_SERVER["REQUEST_METHOD"]; $this->json = json_decode(file_get_contents("php://input"), true); $this->input = $_POST; $this->data = array_merge($this->input, $query); $this->query = $query; + $this->body = file_get_contents("php://input"); } - + /** - * * Returns json value * * @return mixed - * - * */ + */ function json($key) { return $this->json[$key]; } /** - * - * Returns value from input + * Returns POST input value * * @return String - * - * */ + */ function input($key) { return $this->input[$key]; } /** + * Returns GET query value * - * Returns value from query - * * @return String - * - * */ + */ function query() { return $this->query; } - + /** - * * Returns value from data array * * @return mixed - * - * */ + */ function __get($key) { if (isset($this->data[$key])) - return $this->data[$key]; + return $this->data[$key]; return null; } /** - * * Returns value from header * * @return String - * - * */ + */ function header($name) { return $this->headers[$name]; } - + } ?> diff --git a/src/Kernel/Lemonade/Builders/templates.php b/src/Kernel/Lemonade/Builders/templates.php index 6dd4b3bc..f9d3eeaf 100644 --- a/src/Kernel/Lemonade/Builders/templates.php +++ b/src/Kernel/Lemonade/Builders/templates.php @@ -30,7 +30,7 @@ const FILES = [ "public/index.php" => "https://raw.githubusercontent.com/Lemon-Framework/Examples/master/templates/index.php", "routes/web.php" => "https://raw.githubusercontent.com/Lemon-Framework/Examples/master/templates/web_routes.php", - "booter.php" => "https://raw.githubusercontent.com/Lemon-Framework/Examples/master/templates/booter.php" + "app.php" => "https://raw.githubusercontent.com/Lemon-Framework/Examples/master/templates/booter.php" ]; diff --git a/src/Kernel/Lemonade/Helpers/info.php b/src/Kernel/Lemonade/Helpers/info.php index 0c4c53cc..f330f791 100644 --- a/src/Kernel/Lemonade/Helpers/info.php +++ b/src/Kernel/Lemonade/Helpers/info.php @@ -16,7 +16,7 @@ "; -const VERSION = "2.4.4"; +const VERSION = "2.5.1"; // Shows help function help() diff --git a/src/Utils/Env.php b/src/Utils/Env.php index 2c840499..b942cc95 100644 --- a/src/Utils/Env.php +++ b/src/Utils/Env.php @@ -2,7 +2,8 @@ namespace Lemon\Utils; -use ValueError; +use Exception; + /** * .env managing utility */ @@ -30,8 +31,8 @@ public static function setPath(String $path) public static function get(String $key) { $data = self::all(); - if (!in_array($key, $data)) - throw new ValueError("Env key $key does not exist!"); + if (!isset($data[$key])) + throw new Exception("Env key $key does not exist!"); return $data[$key]; } @@ -44,7 +45,7 @@ public static function get(String $key) public static function set(String $key, $value) { if (!is_string($value)) - throw new ValueError("Value can't be converted to string!"); + throw new Exception("Value can't be converted to string!"); $data = self::all(); $data[$key] = (String)$value; @@ -86,8 +87,8 @@ public static function clear() public static function remove(String $key) { $data = self::all(); - if (!in_array($key, $data)) - throw new ValueError("Env key $key does not exist!"); + if (!isset($data[$key])) + throw new Exception("Env key $key does not exist!"); unset($data[$key]); self::replace($data);