Skip to content

Commit

Permalink
Merge pull request #28 from Lemon-Framework/v2.x
Browse files Browse the repository at this point in the history
V2.x Bug fixes
  • Loading branch information
tenmajkl authored Aug 31, 2021
2 parents 0c68277 + 618e0c5 commit 0ef07d6
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 55 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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?
Expand Down
74 changes: 28 additions & 46 deletions src/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

}

?>
2 changes: 1 addition & 1 deletion src/Kernel/Lemonade/Builders/templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"
];


Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/Lemonade/Helpers/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
";

const VERSION = "2.4.4";
const VERSION = "2.5.1";

// Shows help
function help()
Expand Down
13 changes: 7 additions & 6 deletions src/Utils/Env.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace Lemon\Utils;

use ValueError;
use Exception;

/**
* .env managing utility
*/
Expand Down Expand Up @@ -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];
}

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0ef07d6

Please sign in to comment.