Skip to content

Commit 7b19f53

Browse files
bug #60796 [Console] fix backwards-compatibility with overridden add() methods (xabbuh)
This PR was merged into the 7.4 branch. Discussion ---------- [Console] fix backwards-compatibility with overridden add() methods | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | | License | MIT The current (wrong) behaviour can be observed in the high deps job on the `7.3` branch: https://github.com/symfony/symfony/actions/runs/15662516138/job/44122290781#step:9:9940 The reason for the failure is that the `Application` class in `init()` no longer calls `add()` which is overridden in the extending `Application` class from FrameworkBundle doing the container-based command registration. Commits ------- de0b107 fix backwards-compatibility with overridden add() methods
2 parents 440e337 + de0b107 commit 7b19f53

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1352,8 +1352,14 @@ private function init(): void
13521352
}
13531353
$this->initialized = true;
13541354

1355+
if ((new \ReflectionMethod($this, 'add'))->getDeclaringClass()->getName() !== (new \ReflectionMethod($this, 'addCommand'))->getDeclaringClass()->getName()) {
1356+
$adder = $this->add(...);
1357+
} else {
1358+
$adder = $this->addCommand(...);
1359+
}
1360+
13551361
foreach ($this->getDefaultCommands() as $command) {
1356-
$this->addCommand($command);
1362+
$adder($command);
13571363
}
13581364
}
13591365
}

src/Symfony/Component/Runtime/SymfonyRuntime.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,11 @@ public function getRunner(?object $application): RunnerInterface
162162

163163
if (!$application->getName() || !$console->has($application->getName())) {
164164
$application->setName($_SERVER['argv'][0]);
165-
if (method_exists($console, 'addCommand')) {
166-
$console->addCommand($application);
167-
} else {
165+
166+
if (!method_exists($console, 'addCommand') || (new \ReflectionMethod($console, 'add'))->getDeclaringClass()->getName() !== (new \ReflectionMethod($console, 'addCommand'))->getDeclaringClass()->getName()) {
168167
$console->add($application);
168+
} else {
169+
$console->addCommand($application);
169170
}
170171
}
171172

0 commit comments

Comments
 (0)