Skip to content

Commit

Permalink
fix: patch up issues with debug and env
Browse files Browse the repository at this point in the history
  • Loading branch information
mychidarko committed Oct 3, 2022
1 parent 17bd3ea commit 7f25664
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
}

/**
Expand Down Expand Up @@ -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,
],
]);
}

Expand Down

0 comments on commit 7f25664

Please sign in to comment.