Skip to content

Commit

Permalink
Review fixes and small cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
ksucherek committed Sep 27, 2023
1 parent ca1a8b7 commit c33a299
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
23 changes: 9 additions & 14 deletions src/Ouzo/Core/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();

Expand All @@ -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);
Expand Down
8 changes: 0 additions & 8 deletions src/Ouzo/Core/ExceptionHandling/DebugErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/Ouzo/Core/ExceptionHandling/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c33a299

Please sign in to comment.