Start on project with the connection services and first command to list databases

This commit is contained in:
Tim
2021-09-19 11:00:41 +02:00
parent 5e2bc3505f
commit 2fd43ed717
7 changed files with 161 additions and 59 deletions

View File

@ -0,0 +1,38 @@
<?php
namespace App\Console;
use App\Service\DatabaseManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ListDatabasesCommand extends Command
{
// the name of the command (the part after "bin/console")
protected static $defaultName = 'app:db:list';
public function __construct(
private DatabaseManager $db,
)
{
parent::__construct();
}
protected function configure(): void
{
// ...
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$dbs = $this->db->listDatabases();
$output->writeln('List of databases:');
foreach ($dbs as $db) {
$output->writeln(sprintf(' -%s', $db));
}
return Command::SUCCESS;
}
}