-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔀 Merge pull request #115 from leafsphp/v3.x-dev
V3.x dev
- Loading branch information
Showing
7 changed files
with
67 additions
and
368 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
* The easiest way to build simple but powerful apps and APIs quickly. | ||
* | ||
* @author Michael Darko <[email protected]> | ||
* @copyright 2019-2021 Michael Darko | ||
* @copyright 2019-2022 Michael Darko | ||
* @link https://leafphp.dev | ||
* @license MIT | ||
* @package Leaf | ||
|
@@ -70,16 +70,17 @@ public function __construct(array $userSettings = []) | |
|
||
protected function setupErrorHandler() | ||
{ | ||
if ($this->config('debug')) { | ||
$debugConfig = [E_ALL, 1, ['\Leaf\Exception\General', 'handleErrors'], false]; | ||
if ($this->config('debug') === true) { | ||
$debugConfig = [E_ALL, 1]; | ||
$this->errorHandler = (new \Leaf\Exception\Run()); | ||
$this->errorHandler->register(); | ||
} else { | ||
$debugConfig = [0, 0, ['\Leaf\Exception\General', 'defaultError'], true]; | ||
$debugConfig = [0, 0]; | ||
$this->setErrorHandler(['\Leaf\Exception\General', 'defaultError'], true); | ||
} | ||
|
||
error_reporting($debugConfig[0]); | ||
ini_set('display_errors', (string) $debugConfig[1]); | ||
|
||
$this->setErrorHandler($debugConfig[2], $debugConfig[3]); | ||
} | ||
|
||
/** | ||
|
@@ -91,6 +92,15 @@ public function setErrorHandler($handler, bool $wrapper = true) | |
{ | ||
$errorHandler = $handler; | ||
|
||
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 ($wrapper) { | ||
$errorHandler = function ($errno, $errstr = '', $errfile = '', $errline = '') use ($handler) { | ||
$exception = Exception\General::toException($errno, $errstr, $errfile, $errline); | ||
|
@@ -241,6 +251,7 @@ public function config($name, $value = null) | |
} | ||
|
||
Config::set($name, $value); | ||
$this->setupErrorHandler(); | ||
} | ||
|
||
/******************************************************************************** | ||
|
@@ -361,35 +372,6 @@ public static function halt($status, $message = '') | |
exit(); | ||
} | ||
|
||
/** | ||
* Stop | ||
* | ||
* The thrown exception will be caught in application's `call()` method | ||
* and the response will be sent as is to the HTTP client. | ||
* | ||
* @throws \Leaf\Exception\Stop | ||
*/ | ||
public function stop() | ||
{ | ||
throw new \Leaf\Exception\Stop(); | ||
} | ||
|
||
/** | ||
* Pass | ||
* | ||
* The thrown exception is caught in the application's `call()` method causing | ||
* the router's current iteration to stop and continue to the subsequent route if available. | ||
* If no subsequent matching routes are found, a 404 response will be sent to the client. | ||
* | ||
* @throws \Leaf\Exception\Pass | ||
*/ | ||
public function pass() | ||
{ | ||
$this->cleanBuffer(); | ||
|
||
throw new \Leaf\Exception\Pass(); | ||
} | ||
|
||
/** | ||
* Evade CORS errors | ||
* | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.