Skip to content

Commit

Permalink
Refactored exception/error handlers.
Browse files Browse the repository at this point in the history
  • Loading branch information
bbankowski committed Dec 11, 2023
1 parent 113b333 commit f0130a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
6 changes: 4 additions & 2 deletions src/Ouzo/Core/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
use InvalidArgumentException;
use Ouzo\Config\ConfigRepository;
use Ouzo\ExceptionHandling\DebugErrorHandler;
use Ouzo\ExceptionHandling\DebugExceptionHandler;
use Ouzo\ExceptionHandling\ErrorHandler;
use Ouzo\ExceptionHandling\ExceptionHandler;
use Ouzo\Injection\Injector;
use Ouzo\Injection\InjectorConfig;
use Ouzo\Injection\Scope;
Expand Down Expand Up @@ -109,15 +111,15 @@ public function runApplication(): FrontController
private function registerErrorHandlers(): void
{
if (Config::getValue('debug')) {
(new DebugErrorHandler())->register();
(new DebugErrorHandler(new DebugExceptionHandler()))->register();
return;
}

if (!is_null($this->errorHandler)) {
$this->errorHandler->register();
return;
}
(new ErrorHandler())->register();
(new ErrorHandler(new ExceptionHandler()))->register();
}

private function includeRoutes(): void
Expand Down
25 changes: 10 additions & 15 deletions src/Ouzo/Core/ExceptionHandling/DebugErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,22 @@

class DebugErrorHandler extends ErrorHandler
{
protected static function getRun(): Run
public function handleError(int $errorNumber, string $errorString, string $errorFile, int $errorLine): void
{
error_reporting(E_ALL);
$run = new Run();
$run->pushHandler(new PrettyPageHandler());
$run->pushHandler(new DebugErrorLogHandler());
return $run;
$this->createWhoops()->handleError($errorNumber, $errorString, $errorFile, $errorLine);
}

protected static function getExceptionHandler(): ExceptionHandler
public function handleShutdown(): void
{
return new DebugExceptionHandler();
$this->createWhoops()->handleShutdown();
}

public static function handleError(int $errorNumber, string $errorString, string $errorFile, int $errorLine): void
private function createWhoops(): Run
{
self::getRun()->handleError($errorNumber, $errorString, $errorFile, $errorLine);
}

public static function handleShutdown(): void
{
self::getRun()->handleShutdown();
error_reporting(E_ALL);
$run = new Run();
$run->pushHandler(new PrettyPageHandler());
$run->pushHandler(new DebugErrorLogHandler());
return $run;
}
}

0 comments on commit f0130a8

Please sign in to comment.