8000 [Console] Check for ErrorHandler classes · symfony/symfony@48b358d · GitHub
[go: up one dir, main page]

Skip to content

Commit 48b358d

Browse files
committed
[Console] Check for ErrorHandler classes
1 parent fdaf0e0 commit 48b358d

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@
4141
use Symfony\Component\Console\Output\ConsoleOutputInterface;
4242
use Symfony\Component\Console\Output\OutputInterface;
4343
use Symfony\Component\Console\Style\SymfonyStyle;
44-
use Symfony\Component\Debug\ErrorHandler;
45-
use Symfony\Component\Debug\Exception\FatalThrowableError;
44+
use Symfony\Component\Debug\ErrorHandler as LegacyErrorHandler;
45+
use Symfony\Component\Debug\Exception\FatalThrowableError as LegacyFatalThrowableError;
46+
use Symfony\Component\ErrorHandler\ErrorHandler;
47+
use Symfony\Component\ErrorHandler\Exception\FatalThrowableError;
4648
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
4749
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
4850
use Symfony\Contracts\Service\ResetInterface;
@@ -127,7 +129,7 @@ public function run(InputInterface $input = null, OutputInterface $output = null
127129

128130
$renderException = function ($e) use ($output) {
129131
if (!$e instanceof \Exception) {
130-
$e = class_exists(FatalThrowableError::class) ? new FatalThrowableError($e) : new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine());
132+
$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()));
131133
}
132134
if ($output instanceof ConsoleOutputInterface) {
133135
$this->renderException($e, $output->getErrorOutput());
@@ -137,10 +139,10 @@ public function run(InputInterface $input = null, OutputInterface $output = null
137139
};
138140
if ($phpHandler = set_exception_handler($renderException)) {
139141
restore_exception_handler();
140-
if (!\is_array($phpHandler) || !$phpHandler[0] instanceof ErrorHandler) {
141-
$debugHandler = true;
142-
} elseif ($debugHandler = $phpHandler[0]->setExceptionHandler($renderException)) {
143-
$phpHandler[0]->setExceptionHandler($debugHandler);
142+
if (!\is_array($phpHandler) || (!$phpHandler[0] instanceof ErrorHandler && !$phpHandler[0] instanceof LegacyErrorHandler)) {
143+
$errorHandler = true;
144+
} elseif ($errorHandler = $phpHandler[0]->setExceptionHandler($renderException)) {
145+
$phpHandler[0]->setExceptionHandler($errorHandler);
144146
}
145147
}
146148

@@ -172,7 +174,7 @@ public function run(InputInterface $input = null, OutputInterface $output = null
172174
restore_exception_handler();
173175
}
174176
restore_exception_handler();
175-
} elseif (!$debugHandler) {
177+
} elseif (!$errorHandler) {
176178
$finalHandler = $phpHandler[0]->setExceptionHandler(null);
177179
if ($finalHandler !== $renderException) {
178180
$phpHandler[0]->setExceptionHandler($finalHandler);

0 commit comments

Comments
 (0)
0