Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f4738d9

Browse files
committed
Add support for Application::setCatchErrors in symfony 6.4+, refs symfony/symfony#50420
1 parent ff70ab7 commit f4738d9

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

src/Composer/Console/Application.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ class Application extends BaseApplication
8787

8888
public function __construct(string $name = 'Composer', string $version = '')
8989
{
90+
if (method_exists($this, 'setCatchErrors')) {
91+
$this->setCatchErrors(true);
92+
}
93+
9094
static $shutdownRegistered = false;
9195
if ($version === '') {
9296
$version = Composer::getVersion();
@@ -395,9 +399,10 @@ function_exists('php_uname') ? php_uname('s') . ' / ' . php_uname('r') : 'Unknow
395399

396400
$this->hintCommonErrors($e, $output);
397401

398-
// symfony/console does not handle \Error subtypes so we have to renderThrowable ourselves
402+
// symfony/console <6.4 does not handle \Error subtypes so we have to renderThrowable ourselves
399403
// instead of rethrowing those for consumption by the parent class
400-
if (!$e instanceof \Exception) {
404+
// can be removed when Composer supports PHP 8.1+
405+
if (!method_exists($this, 'setCatchErrors') && !$e instanceof \Exception) {
401406
if ($output instanceof ConsoleOutputInterface) {
402407
$this->renderThrowable($e, $output->getErrorOutput());
403408
} else {

src/Composer/EventDispatcher/EventDispatcher.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ protected function doDispatch(Event $event)
277277

278278
$app = new Application();
279279
$app->setCatchExceptions(false);
280+
if (method_exists($app, 'setCatchErrors')) {
281+
$app->setCatchErrors(false);
282+
}
280283
$app->setAutoExit(false);
281284
$cmd = new $className($event->getName());
282285
$app->add($cmd);

tests/Composer/Test/DocumentationTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public static function provideCommandCases(): \Generator
5353
{
5454
$application = new Application();
5555
$application->setAutoExit(false);
56+
if (method_exists($application, 'setCatchErrors')) {
57+
$application->setCatchErrors(false);
58+
}
5659
$application->setCatchExceptions(false);
5760

5861
$description = new ApplicationDescription($application);

tests/Composer/Test/TestCase.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ public function getApplicationTester(): ApplicationTester
198198
$application = new Application();
199199
$application->setAutoExit(false);
200200
$application->setCatchExceptions(false);
201+
if (method_exists($application, 'setCatchErrors')) {
202+
$application->setCatchErrors(false);
203+
}
201204

202205
return new ApplicationTester($application);
203206
}

0 commit comments

Comments
 (0)