Skip to content

Commit 1b95086

Browse files
LOBsTerrjmolivas
authored andcommitted
Add new arguments key and target. Make it possible use not only default target for db connections (#3804)
1 parent 43db14f commit 1b95086

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/Command/Database/ConnectCommand.php

+11-4
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,15 @@ protected function configure()
2626
->setName('database:connect')
2727
->setDescription($this->trans('commands.database.connect.description'))
2828
->addArgument(
29-
'database',
29+
'key',
3030
InputArgument::OPTIONAL,
31-
$this->trans('commands.database.connect.arguments.database'),
31+
$this->trans('commands.database.connect.arguments.key'),
32+
'default'
33+
)
34+
->addArgument(
35+
'target',
36+
InputArgument::OPTIONAL,
37+
$this->trans('commands.database.connect.arguments.target'),
3238
'default'
3339
)
3440
->setHelp($this->trans('commands.database.connect.help'))
@@ -40,8 +46,9 @@ protected function configure()
4046
*/
4147
protected function execute(InputInterface $input, OutputInterface $output)
4248
{
43-
$database = $input->getArgument('database');
44-
$databaseConnection = $this->resolveConnection($database);
49+
$key = $input->getArgument('key');
50+
$target = $input->getArgument('target');
51+
$databaseConnection = $this->resolveConnection($key, $target);
4552

4653
$connection = sprintf(
4754
'%s -A --database=%s --user=%s --password=%s --host=%s --port=%s',

src/Command/Shared/ConnectTrait.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@
1111

1212
trait ConnectTrait
1313
{
14-
protected $supportedDrivers = ['mysql','pgsql'];
14+
protected $supportedDrivers = ['mysql', 'pgsql'];
1515

16-
public function resolveConnection($database = 'default')
16+
public function resolveConnection($key = 'default', $target = 'default')
1717
{
18-
$connectionInfo = Database::getConnectionInfo();
19-
20-
if (!$connectionInfo || !isset($connectionInfo[$database])) {
18+
$connectionInfo = Database::getConnectionInfo($key);
19+
if (!$connectionInfo || !isset($connectionInfo[$target])) {
2120
$this->getIo()->error(
2221
sprintf(
2322
$this->trans('commands.database.connect.messages.database-not-found'),
24-
$database
23+
$key,
24+
$target
2525
)
2626
);
2727

2828
return null;
2929
}
3030

31-
$databaseConnection = $connectionInfo[$database];
31+
$databaseConnection = $connectionInfo[$target];
3232
if (!in_array($databaseConnection['driver'], $this->supportedDrivers)) {
3333
$this->getIo()->error(
3434
sprintf(

0 commit comments

Comments
 (0)