41
41
use Symfony \Component \Console \Output \ConsoleOutputInterface ;
42
42
use Symfony \Component \Console \Output \OutputInterface ;
43
43
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 ;
46
48
use Symfony \Component \EventDispatcher \EventDispatcherInterface ;
47
49
use Symfony \Component \EventDispatcher \LegacyEventDispatcherProxy ;
48
50
use Symfony \Contracts \Service \ResetInterface ;
@@ -127,7 +129,7 @@ public function run(InputInterface $input = null, OutputInterface $output = null
127
129
128
130
$ renderException = function ($ e ) use ($ output ) {
129
131
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 () ));
131
133
}
132
134
if ($ output instanceof ConsoleOutputInterface) {
133
135
$ this ->renderException ($ e , $ output ->getErrorOutput ());
@@ -137,10 +139,10 @@ public function run(InputInterface $input = null, OutputInterface $output = null
137
139
};
138
140
if ($ phpHandler = set_exception_handler ($ renderException )) {
139
141
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 );
144
146
}
145
147
}
146
148
@@ -172,7 +174,7 @@ public function run(InputInterface $input = null, OutputInterface $output = null
172
174
restore_exception_handler ();
173
175
}
174
176
restore_exception_handler ();
175
- } elseif (!$ debugHandler ) {
177
+ } elseif (!$ errorHandler ) {
176
178
$ finalHandler = $ phpHandler [0 ]->setExceptionHandler (null );
177
179
if ($ finalHandler !== $ renderException ) {
178
180
$ phpHandler [0 ]->setExceptionHandler ($ finalHandler );
0 commit comments