diff --git a/src/Ouzo/Core/Bootstrap.php b/src/Ouzo/Core/Bootstrap.php index 8442410d..b107c725 100644 --- a/src/Ouzo/Core/Bootstrap.php +++ b/src/Ouzo/Core/Bootstrap.php @@ -108,27 +108,25 @@ public function runApplication(): FrontController private function registerErrorHandlers(): void { - if (!is_null($this->errorHandler)) { - $this->errorHandler->register(); + if (Config::getValue('debug')) { + (new DebugErrorHandler())->register(); return; } - if (Config::getValue('debug')) { - (new DebugErrorHandler())->register(); + if (!is_null($this->errorHandler)) { + $this->errorHandler->register(); return; } (new ErrorHandler())->register(); } - private - function includeRoutes(): void + private function includeRoutes(): void { $routesPath = Path::join(ROOT_PATH, 'config', 'routes.php'); Files::loadIfExists($routesPath); } - public - function setupInjector(): Injector + public function setupInjector(): Injector { $injector = $this->createInjector(); @@ -146,15 +144,13 @@ function setupInjector(): Injector return $injector; } - private - function createInjector(): Injector + private function createInjector(): Injector { $injectorConfig = $this->injectorConfig ?: new InjectorConfig(); return $this->injector ?: new Injector($injectorConfig); } - private - function createMiddlewareRepository(Injector $injector): MiddlewareRepository + private function createMiddlewareRepository(Injector $injector): MiddlewareRepository { $middlewareRepository = new MiddlewareRepository(); @@ -177,8 +173,7 @@ function createMiddlewareRepository(Injector $injector): MiddlewareRepository return $middlewareRepository; } - private - function createInterceptor(Injector $injector): Closure + private function createInterceptor(Injector $injector): Closure { return function ($interceptor) use ($injector) { $instance = $injector->getInstance($interceptor); diff --git a/src/Ouzo/Core/ExceptionHandling/DebugErrorHandler.php b/src/Ouzo/Core/ExceptionHandling/DebugErrorHandler.php index 49b4171f..3389bb80 100644 --- a/src/Ouzo/Core/ExceptionHandling/DebugErrorHandler.php +++ b/src/Ouzo/Core/ExceptionHandling/DebugErrorHandler.php @@ -6,19 +6,11 @@ namespace Ouzo\ExceptionHandling; -use Throwable; use Whoops\Handler\PrettyPageHandler; use Whoops\Run; class DebugErrorHandler extends ErrorHandler { - public function register(): void - { - set_exception_handler(fn(Throwable $exception) => DebugErrorHandler::exceptionHandler($exception)); - set_error_handler(fn(...$args) => DebugErrorHandler::errorHandler(...$args)); - register_shutdown_function(fn() => DebugErrorHandler::shutdownHandler()); - } - protected static function getRun(): Run { error_reporting(E_ALL); diff --git a/src/Ouzo/Core/ExceptionHandling/ErrorHandler.php b/src/Ouzo/Core/ExceptionHandling/ErrorHandler.php index 099196c2..acc6c39a 100644 --- a/src/Ouzo/Core/ExceptionHandling/ErrorHandler.php +++ b/src/Ouzo/Core/ExceptionHandling/ErrorHandler.php @@ -13,9 +13,9 @@ class ErrorHandler { public function register(): void { - set_exception_handler(fn(Throwable $exception) => ErrorHandler::exceptionHandler($exception)); - set_error_handler(fn(...$args) => ErrorHandler::errorHandler(...$args), E_ALL & ~E_DEPRECATED & ~E_STRICT); - register_shutdown_function(fn() => ErrorHandler::shutdownHandler()); + set_exception_handler(fn(Throwable $exception) => static::exceptionHandler($exception)); + set_error_handler(fn(...$args) => static::errorHandler(...$args), E_ALL & ~E_DEPRECATED & ~E_STRICT); + register_shutdown_function(fn() => static::shutdownHandler()); } public static function exceptionHandler(Throwable $exception): void