[Console] Check for ErrorHandler classes
This commit is contained in:
parent
fdaf0e0cf4
commit
48b358d036
@ -41,8 +41,10 @@ use Symfony\Component\Console\Output\ConsoleOutput;
|
|||||||
use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
use Symfony\Component\Debug\ErrorHandler;
|
use Symfony\Component\Debug\ErrorHandler as LegacyErrorHandler;
|
||||||
use Symfony\Component\Debug\Exception\FatalThrowableError;
|
use Symfony\Component\Debug\Exception\FatalThrowableError as LegacyFatalThrowableError;
|
||||||
|
use Symfony\Component\ErrorHandler\ErrorHandler;
|
||||||
|
use Symfony\Component\ErrorHandler\Exception\FatalThrowableError;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
|
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
|
||||||
use Symfony\Contracts\Service\ResetInterface;
|
use Symfony\Contracts\Service\ResetInterface;
|
||||||
@ -127,7 +129,7 @@ class Application implements ResetInterface
|
|||||||
|
|
||||||
$renderException = function ($e) use ($output) {
|
$renderException = function ($e) use ($output) {
|
||||||
if (!$e instanceof \Exception) {
|
if (!$e instanceof \Exception) {
|
||||||
$e = class_exists(FatalThrowableError::class) ? new FatalThrowableError($e) : new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine());
|
$e = class_exists(FatalThrowableError::class) ? new FatalThrowableError($e) : (class_exists(LegacyFatalThrowableError::class) ? new LegacyFatalThrowableError($e) : new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine()));
|
||||||
}
|
}
|
||||||
if ($output instanceof ConsoleOutputInterface) {
|
if ($output instanceof ConsoleOutputInterface) {
|
||||||
$this->renderException($e, $output->getErrorOutput());
|
$this->renderException($e, $output->getErrorOutput());
|
||||||
@ -137,10 +139,10 @@ class Application implements ResetInterface
|
|||||||
};
|
};
|
||||||
if ($phpHandler = set_exception_handler($renderException)) {
|
if ($phpHandler = set_exception_handler($renderException)) {
|
||||||
restore_exception_handler();
|
restore_exception_handler();
|
||||||
if (!\is_array($phpHandler) || !$phpHandler[0] instanceof ErrorHandler) {
|
if (!\is_array($phpHandler) || (!$phpHandler[0] instanceof ErrorHandler && !$phpHandler[0] instanceof LegacyErrorHandler)) {
|
||||||
$debugHandler = true;
|
$errorHandler = true;
|
||||||
} elseif ($debugHandler = $phpHandler[0]->setExceptionHandler($renderException)) {
|
} elseif ($errorHandler = $phpHandler[0]->setExceptionHandler($renderException)) {
|
||||||
$phpHandler[0]->setExceptionHandler($debugHandler);
|
$phpHandler[0]->setExceptionHandler($errorHandler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +174,7 @@ class Application implements ResetInterface
|
|||||||
restore_exception_handler();
|
restore_exception_handler();
|
||||||
}
|
}
|
||||||
restore_exception_handler();
|
restore_exception_handler();
|
||||||
} elseif (!$debugHandler) {
|
} elseif (!$errorHandler) {
|
||||||
$finalHandler = $phpHandler[0]->setExceptionHandler(null);
|
$finalHandler = $phpHandler[0]->setExceptionHandler(null);
|
||||||
if ($finalHandler !== $renderException) {
|
if ($finalHandler !== $renderException) {
|
||||||
$phpHandler[0]->setExceptionHandler($finalHandler);
|
$phpHandler[0]->setExceptionHandler($finalHandler);
|
||||||
|
Reference in New Issue
Block a user