|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Command\Installer; |
|
4
|
|
|
|
|
5
|
|
|
use App\Command\Helper\CommandsRunner; |
|
6
|
|
|
use App\Installer\Provider\DatabaseSetupCommandsProviderInterface; |
|
7
|
|
|
use Symfony\Component\Console\Command\Command; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
10
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
11
|
|
|
|
|
12
|
|
|
class InstallDatabaseCommand extends Command |
|
13
|
|
|
{ |
|
14
|
|
|
/** @var DatabaseSetupCommandsProviderInterface */ |
|
15
|
|
|
private $databaseSetupCommandsProvider; |
|
16
|
|
|
|
|
17
|
|
|
/** @var CommandsRunner */ |
|
18
|
|
|
private $commandsRunner; |
|
19
|
|
|
|
|
20
|
|
|
/** @var string */ |
|
21
|
|
|
private $environment; |
|
22
|
|
|
|
|
23
|
|
|
public function __construct( |
|
24
|
|
|
DatabaseSetupCommandsProviderInterface $databaseSetupCommandsProvider, |
|
25
|
|
|
CommandsRunner $commandsRunner, |
|
26
|
|
|
string $environment |
|
27
|
|
|
) { |
|
28
|
|
|
$this->databaseSetupCommandsProvider = $databaseSetupCommandsProvider; |
|
29
|
|
|
$this->commandsRunner = $commandsRunner; |
|
30
|
|
|
$this->environment = $environment; |
|
31
|
|
|
|
|
32
|
|
|
parent::__construct(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritdoc} |
|
37
|
|
|
*/ |
|
38
|
|
|
protected function configure() |
|
39
|
|
|
{ |
|
40
|
|
|
$this |
|
41
|
|
|
->setName('app:install:database') |
|
42
|
|
|
->setDescription('Install AppName database.') |
|
43
|
|
|
->setHelp(<<<EOT |
|
44
|
|
|
The <info>%command.name%</info> command creates AppName database. |
|
45
|
|
|
EOT |
|
46
|
|
|
) |
|
47
|
|
|
; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* {@inheritdoc} |
|
52
|
|
|
* |
|
53
|
|
|
* @throws \Exception |
|
54
|
|
|
*/ |
|
55
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
56
|
|
|
{ |
|
57
|
|
|
$outputStyle = new SymfonyStyle($input, $output); |
|
58
|
|
|
$outputStyle->writeln(sprintf( |
|
59
|
|
|
'Creating AppName database for environment <info>%s</info>.', |
|
60
|
|
|
$this->environment |
|
61
|
|
|
)); |
|
62
|
|
|
$commands = $this |
|
63
|
|
|
->databaseSetupCommandsProvider |
|
64
|
|
|
->getCommands($input, $output, $this->getHelper('question')) |
|
|
|
|
|
|
65
|
|
|
; |
|
66
|
|
|
$this->commandsRunner->run($commands, $input, $output, $this->getApplication()); |
|
|
|
|
|
|
67
|
|
|
$outputStyle->newLine(); |
|
68
|
|
|
$commandExecutor = new CommandExecutor($input, $output, $this->getApplication()); |
|
|
|
|
|
|
69
|
|
|
$commandExecutor->runCommand('app:install:sample-data', [], $output); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.