2023-03-15 20:40:49 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace SPC\exception;
|
|
|
|
|
|
|
|
|
|
class ExceptionHandler
|
|
|
|
|
{
|
2023-08-25 16:32:56 +02:00
|
|
|
protected mixed $whoops = null;
|
2023-03-15 20:40:49 +08:00
|
|
|
|
2023-08-20 19:51:45 +08:00
|
|
|
private static ?ExceptionHandler $obj = null;
|
2023-03-15 20:40:49 +08:00
|
|
|
|
|
|
|
|
public static function getInstance(): ExceptionHandler
|
|
|
|
|
{
|
|
|
|
|
if (self::$obj === null) {
|
|
|
|
|
self::$obj = new self();
|
|
|
|
|
}
|
|
|
|
|
return self::$obj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function handle(\Throwable $e): void
|
|
|
|
|
{
|
2025-08-01 01:29:35 +08:00
|
|
|
logger()->error('Uncaught ' . get_class($e) . ': ' . $e->getMessage() . ' at ' . $e->getFile() . '(' . $e->getLine() . ')');
|
|
|
|
|
logger()->error($e->getTraceAsString());
|
2023-08-08 20:23:38 +08:00
|
|
|
logger()->critical('You can report this exception to static-php-cli GitHub repo.');
|
2023-03-15 20:40:49 +08:00
|
|
|
}
|
|
|
|
|
}
|