Skip to content

Commit de0b107

Browse files
xabbuhnicolas-grekas
authored andcommitted
fix backwards-compatibility with overridden add() methods
1 parent 440e337 commit de0b107

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)