Add support for Application::setCatchErrors in symfony 6.4+, refs symfony/symfony#50420

上级 ff70ab7c
...@@ -87,6 +87,10 @@ class Application extends BaseApplication ...@@ -87,6 +87,10 @@ class Application extends BaseApplication
public function __construct(string $name = 'Composer', string $version = '') public function __construct(string $name = 'Composer', string $version = '')
{ {
if (method_exists($this, 'setCatchErrors')) {
$this->setCatchErrors(true);
}
static $shutdownRegistered = false; static $shutdownRegistered = false;
if ($version === '') { if ($version === '') {
$version = Composer::getVersion(); $version = Composer::getVersion();
...@@ -395,9 +399,10 @@ function_exists('php_uname') ? php_uname('s') . ' / ' . php_uname('r') : 'Unknow ...@@ -395,9 +399,10 @@ function_exists('php_uname') ? php_uname('s') . ' / ' . php_uname('r') : 'Unknow
$this->hintCommonErrors($e, $output); $this->hintCommonErrors($e, $output);
// symfony/console does not handle \Error subtypes so we have to renderThrowable ourselves // symfony/console <6.4 does not handle \Error subtypes so we have to renderThrowable ourselves
// instead of rethrowing those for consumption by the parent class // instead of rethrowing those for consumption by the parent class
if (!$e instanceof \Exception) { // can be removed when Composer supports PHP 8.1+
if (!method_exists($this, 'setCatchErrors') && !$e instanceof \Exception) {
if ($output instanceof ConsoleOutputInterface) { if ($output instanceof ConsoleOutputInterface) {
$this->renderThrowable($e, $output->getErrorOutput()); $this->renderThrowable($e, $output->getErrorOutput());
} else { } else {
......
...@@ -277,6 +277,9 @@ protected function doDispatch(Event $event) ...@@ -277,6 +277,9 @@ protected function doDispatch(Event $event)
$app = new Application(); $app = new Application();
$app->setCatchExceptions(false); $app->setCatchExceptions(false);
if (method_exists($app, 'setCatchErrors')) {
$app->setCatchErrors(false);
}
$app->setAutoExit(false); $app->setAutoExit(false);
$cmd = new $className($event->getName()); $cmd = new $className($event->getName());
$app->add($cmd); $app->add($cmd);
......
...@@ -53,6 +53,9 @@ public static function provideCommandCases(): \Generator ...@@ -53,6 +53,9 @@ public static function provideCommandCases(): \Generator
{ {
$application = new Application(); $application = new Application();
$application->setAutoExit(false); $application->setAutoExit(false);
if (method_exists($application, 'setCatchErrors')) {
$application->setCatchErrors(false);
}
$application->setCatchExceptions(false); $application->setCatchExceptions(false);
$description = new ApplicationDescription($application); $description = new ApplicationDescription($application);
......
...@@ -198,6 +198,9 @@ public function getApplicationTester(): ApplicationTester ...@@ -198,6 +198,9 @@ public function getApplicationTester(): ApplicationTester
$application = new Application(); $application = new Application();
$application->setAutoExit(false); $application->setAutoExit(false);
$application->setCatchExceptions(false); $application->setCatchExceptions(false);
if (method_exists($application, 'setCatchErrors')) {
$application->setCatchErrors(false);
}
return new ApplicationTester($application); return new ApplicationTester($application);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册