From 7ba9e761497fbb40f57529906d204aa58318d0da Mon Sep 17 00:00:00 2001 From: John Vincent Bonza Date: Wed, 28 Sep 2022 12:18:43 +0800 Subject: [PATCH 1/2] Fix redirect url --- src/Core/Response.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Core/Response.php b/src/Core/Response.php index fe875ff..d8409ec 100644 --- a/src/Core/Response.php +++ b/src/Core/Response.php @@ -20,7 +20,11 @@ public function Redirect($url = NULL) if(!array_key_exists($url, $router->GetRouteMap(Application::$app->request->GetMethod()))) { throw new NotFoundException(); } - header("Location: ?view=" . ltrim($url, '/')); + $url = ltrim($url, '/'); + if(empty($url)) { + $url = './'; + } + header("Location: " . $url); } public function RedirectWithConfirmation($url = NULL) { From 2217bf7be939dd62a175dd913d345602339322eb Mon Sep 17 00:00:00 2001 From: John Vincent Bonza Date: Wed, 28 Sep 2022 12:23:58 +0800 Subject: [PATCH 2/2] Fix application configuration initialization --- src/Core/Application.php | 16 ++++------------ src/Core/Request.php | 13 +++++++++++++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/Core/Application.php b/src/Core/Application.php index 8eba216..f6605e9 100644 --- a/src/Core/Application.php +++ b/src/Core/Application.php @@ -19,7 +19,6 @@ public function __construct($config = []) self::$app = $this; $this->user = null; - $this->userClass = $config['userClass']; $this->request = new Request(); $this->response = new Response(); $this->router = new Router($this->request, $this->response); @@ -40,15 +39,8 @@ public function __construct($config = []) */ public function LoadSettings($config) { self::$ROOT_DIR = $config['root']; - $this->config['app'] = $config['app']; - $this->config['auth'] = $config['auth']; - $this->config['environment'] = $config['environment']; - $this->config['connections'] = $config['connections']; - - // Load env file - $dotenv = Dotenv::createImmutable(self::$ROOT_DIR); - $env = $dotenv->load(); - $this->config['env'] = $this->ToObject($env); + $this->userClass = $config['auth']['userClass']; + $this->config = $config; // Transform config type (Array) to (Object) $this->config = $this->ToObject($this->config); @@ -70,7 +62,7 @@ public function Run() echo $this->router->RenderView('layouts/error', [ 'message' => $e->getMessage(), 'code' => $errorCode, - 'app' => Application::$app->config['app'] + 'app' => Application::$app->config->app ]); } } @@ -82,7 +74,7 @@ public function Debug($var) { } public function LogError($code, $message) { - $db = new Database(Application::$app->config['env']->APP_ENV == 'local' ? 'ils-local' : 'ils-live'); + $db = new Database('ils'); $db->InsertOne("exception_logs", ['code', 'message'], [':in_code' => $code, ':in_message' => $message]); } diff --git a/src/Core/Request.php b/src/Core/Request.php index a04e706..a79b952 100644 --- a/src/Core/Request.php +++ b/src/Core/Request.php @@ -94,6 +94,19 @@ public function GetBody() return $data; } + public function GetValue($key = NULL) { + if(is_null($key)) { + return FALSE; + } + $data = $this->GetBody(); + if(array_key_exists($key, $data)) { + if(empty($data[$key])) { + return FALSE; + } + return $data[$key]; + } + } + /** * @param $params * @return self