diff --git a/formwork/defaults.php b/formwork/defaults.php index 3e3edad04..1c8c9fd8d 100644 --- a/formwork/defaults.php +++ b/formwork/defaults.php @@ -36,6 +36,9 @@ 'timezone' => 'UTC', 'week_starts' => 0 ], + 'errors' => [ + 'set_handlers' => true + ], 'files' => [ 'allowed_extensions' => [ '.jpg', diff --git a/formwork/src/Admin/Admin.php b/formwork/src/Admin/Admin.php index 7622d0a14..18577d681 100644 --- a/formwork/src/Admin/Admin.php +++ b/formwork/src/Admin/Admin.php @@ -279,11 +279,13 @@ protected function loadSchemes(): void */ protected function loadErrorHandler(): void { - $this->errors = new Controllers\ErrorsController(); - set_exception_handler(function (Throwable $exception): void { - $this->errors->internalServerError($exception)->send(); - throw $exception; - }); + if (Formwork::instance()->config()->get('errors.set_handlers')) { + $this->errors = new Controllers\ErrorsController(); + set_exception_handler(function (Throwable $exception): void { + $this->errors->internalServerError($exception)->send(); + throw $exception; + }); + } } /** diff --git a/formwork/src/Formwork.php b/formwork/src/Formwork.php index f64fedf12..806664174 100644 --- a/formwork/src/Formwork.php +++ b/formwork/src/Formwork.php @@ -94,11 +94,10 @@ public function __construct() { $this->initializeSingleton(); - Errors::setHandlers(); - $this->request = Uri::removeQuery(HTTPRequest::uri()); $this->loadConfig(); + $this->loadErrorHandlers(); $this->loadLanguages(); $this->loadTranslations(); $this->loadSchemes(); @@ -225,6 +224,16 @@ protected function loadConfig(): void date_default_timezone_set($this->config->get('date.timezone')); } + /** + * Load error handlers + */ + protected function loadErrorHandlers(): void + { + if ($this->config()->get('errors.set_handlers')) { + Errors::setHandlers(); + } + } + /** * Load language from request */