Add DatabaseCredentials class and implement database picker question

This commit is contained in:
Tim
2021-12-16 00:06:38 +01:00
parent d78f52b965
commit 0ff9021d6e
5 changed files with 96 additions and 3 deletions

View File

@ -0,0 +1,42 @@
<?php
namespace App\Console;
use App\Service\DatabaseManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
class BackupDatabase extends Command
{
protected static $defaultName = 'app:db:create';
public function __construct(
private DatabaseManager $db,
)
{
parent::__construct();
}
protected function configure(): void
{
$this->addArgument('name', InputArgument::OPTIONAL, 'Database name');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$question = $this->getHelper('question');
if (!$name = $input->getArgument('name')) {
$name = $question->ask($input, $output, new Question('Database name: '));
}
$this->db->createDatabase($name);
$output->writeln(sprintf('Database "%s" successfully created', $name));
return Command::SUCCESS;
}
}