|
36 | 36 | use Symfony\Component\Console\Event\ConsoleTerminateEvent; |
37 | 37 | use Symfony\Component\Console\Exception\CommandNotFoundException; |
38 | 38 | use Symfony\Component\Console\Exception\LogicException; |
| 39 | +use Symfony\Component\Debug\Debug; |
| 40 | +use Symfony\Component\Debug\ErrorHandler; |
39 | 41 | use Symfony\Component\Debug\Exception\FatalThrowableError; |
40 | 42 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
41 | 43 |
|
@@ -120,6 +122,21 @@ public function run(InputInterface $input = null, OutputInterface $output = null |
120 | 122 | $this->configureIO($input, $output); |
121 | 123 |
|
122 | 124 | try { |
| 125 | + if (PHP_MAJOR_VERSION < 7 && $this->catchErrors) { |
| 126 | + Debug::enable(); |
| 127 | + $handler = set_exception_handler('var_dump'); |
| 128 | + $handler = is_array($handler) ? $handler[0] : null; |
| 129 | + restore_exception_handler(); |
| 130 | + |
| 131 | + if (!
8000
$handler instanceof ErrorHandler) { |
| 132 | + throw new \RuntimeException(sprintf('Expected instance of "%s". Got "%s".', ErrorHandler::class, get_class($handler))); |
| 133 | + } |
| 134 | + |
| 135 | + $handler->setExceptionHandler(function ($e) use ($output) { |
| 136 | + $this->renderThrowable($e, $output); |
| 137 | + }); |
| 138 | + } |
| 139 | + |
123 | 140 | $exitCode = $this->doRun($input, $output); |
124 | 141 | } catch (\Exception $e) { |
125 | 142 | if (!$this->catchExceptions) { |
@@ -291,6 +308,10 @@ public function areErrorsCaught() |
291 | 308 | */ |
292 | 309 | public function setCatchErrors($boolean) |
293 | 310 | { |
| 311 | + if (PHP_VERSION_ID < 70000 && $this->catchErrors && !class_exists(Debug::class)) { |
| 312 | + throw new \LogicException('The "symfony/debug" component is required for using "catchErrors" along with php < 7.'); |
| 313 | + } |
| 314 | + |
294 | 315 | $this->catchErrors = (bool) $boolean; |
295 | 316 | } |
296 | 317 |
|
|
0 commit comments