From 7f25664e2cc38b422e596d40365741b87731d3cd Mon Sep 17 00:00:00 2001 From: mychidarko Date: Mon, 3 Oct 2022 22:20:29 +0000 Subject: [PATCH] fix: patch up issues with debug and env --- src/App.php | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/App.php b/src/App.php index 97f5fa0..e754104 100755 --- a/src/App.php +++ b/src/App.php @@ -72,7 +72,7 @@ protected function loadConfig(array $userSettings = []) protected function setupErrorHandler() { - if ($this->config('debug') === true) { + if (Anchor::toBool($this->config('debug')) === true) { $debugConfig = [E_ALL, 1]; $this->errorHandler = (new \Leaf\Exception\Run()); $this->errorHandler->register(); @@ -92,27 +92,29 @@ protected function setupErrorHandler() */ public function setErrorHandler($handler, bool $wrapper = true) { - $errorHandler = $handler; + if (Anchor::toBool($this->config('debug')) === false) { + $errorHandler = $handler; - if ($this->errorHandler instanceof \Leaf\Exception\Run) { - $this->errorHandler->unregister(); - } + if ($this->errorHandler instanceof \Leaf\Exception\Run) { + $this->errorHandler->unregister(); + } - if ($handler instanceof \Leaf\Exception\Handler\Handler) { - $this->errorHandler = new \Leaf\Exception\Run(); - $this->errorHandler->pushHandler($handler)->register(); - } + if ($handler instanceof \Leaf\Exception\Handler\Handler) { + $this->errorHandler = new \Leaf\Exception\Run(); + $this->errorHandler->pushHandler($handler)->register(); + } - if ($wrapper) { - $errorHandler = function ($errno, $errstr = '', $errfile = '', $errline = '') use ($handler) { - $exception = Exception\General::toException($errno, $errstr, $errfile, $errline); - Http\Headers::resetStatus(500); - call_user_func_array($handler, [$exception]); - exit(); - }; - } + if ($wrapper) { + $errorHandler = function ($errno, $errstr = '', $errfile = '', $errline = '') use ($handler) { + $exception = Exception\General::toException($errno, $errstr, $errfile, $errline); + Http\Headers::resetStatus(500); + call_user_func_array($handler, [$exception]); + exit(); + }; + } - set_error_handler($errorHandler); + set_error_handler($errorHandler); + } } /** @@ -198,11 +200,11 @@ private function setupDefaultContainer() } Config::set([ - 'mode' => $mode, - 'app' => [ - 'instance' => $this, - 'container' => $this->container, - ], + 'mode' => $mode, + 'app' => [ + 'instance' => $this, + 'container' => $this->container, + ], ]); }