Skip to content

Commit 614e093

Browse files
committed
Fix Symfony Console 8.0 compatibility
Add backwards compatible add() method that delegates to addCommand() on Symfony 8.x where add() was removed, while still working with Symfony 6.x/7.x where add() exists.
1 parent 1f940d3 commit 614e093

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/Phinx/Console/PhinxApplication.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Phinx\Console\Command\Status;
2121
use Phinx\Console\Command\Test;
2222
use Symfony\Component\Console\Application;
23+
use Symfony\Component\Console\Command\Command;
2324
use Symfony\Component\Console\Input\InputDefinition;
2425
use Symfony\Component\Console\Input\InputInterface;
2526
use Symfony\Component\Console\Input\InputOption;
@@ -90,6 +91,25 @@ public function doRun(InputInterface $input, OutputInterface $output): int
9091
return parent::doRun($input, $output);
9192
}
9293

94+
/**
95+
* Adds a command object.
96+
*
97+
* Provides backwards compatibility for Symfony Console 6.x/7.x where
98+
* the add() method exists, and Symfony 8.x where it was removed in
99+
* favor of addCommand().
100+
*
101+
* @param \Symfony\Component\Console\Command\Command $command A Command object
102+
* @return \Symfony\Component\Console\Command\Command|null
103+
*/
104+
public function add(Command $command): ?Command
105+
{
106+
if (method_exists(Application::class, 'addCommand')) {
107+
return parent::addCommand($command);
108+
}
109+
110+
return parent::add($command);
111+
}
112+
93113
/**
94114
* Get the current application version.
95115
*

0 commit comments

Comments
 (0)