1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Migrations\Tools\Console\Command; |
6
|
|
|
|
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
use function escapeshellarg; |
11
|
|
|
use function proc_open; |
12
|
|
|
use function sprintf; |
13
|
|
|
|
14
|
|
|
class GenerateCommand extends AbstractCommand |
15
|
|
|
{ |
16
|
9 |
|
protected function configure() : void |
17
|
|
|
{ |
18
|
|
|
$this |
19
|
9 |
|
->setName('migrations:generate') |
20
|
9 |
|
->setDescription('Generate a blank migration class.') |
21
|
9 |
|
->addOption( |
22
|
9 |
|
'editor-cmd', |
23
|
9 |
|
null, |
24
|
9 |
|
InputOption::VALUE_OPTIONAL, |
25
|
9 |
|
'Open file with this command upon creation.' |
26
|
|
|
) |
27
|
9 |
|
->setHelp(<<<EOT |
28
|
9 |
|
The <info>%command.name%</info> command generates a blank migration class: |
29
|
|
|
|
30
|
|
|
<info>%command.full_name%</info> |
31
|
|
|
|
32
|
|
|
You can optionally specify a <comment>--editor-cmd</comment> option to open the generated file in your favorite editor: |
33
|
|
|
|
34
|
|
|
<info>%command.full_name% --editor-cmd=mate</info> |
35
|
|
|
EOT |
36
|
|
|
); |
37
|
|
|
|
38
|
9 |
|
parent::configure(); |
39
|
9 |
|
} |
40
|
|
|
|
41
|
3 |
|
public function execute(InputInterface $input, OutputInterface $output) : void |
42
|
|
|
{ |
43
|
3 |
|
$versionNumber = $this->configuration->generateVersionNumber(); |
44
|
|
|
|
45
|
3 |
|
$migrationGenerator = $this->dependencyFactory->getMigrationGenerator(); |
46
|
|
|
|
47
|
3 |
|
$path = $migrationGenerator->generateMigration($versionNumber); |
48
|
|
|
|
49
|
3 |
|
$editorCommand = $input->getOption('editor-cmd'); |
50
|
|
|
|
51
|
3 |
|
if ($editorCommand !== null) { |
52
|
1 |
|
$this->procOpen($editorCommand, $path); |
53
|
|
|
} |
54
|
|
|
|
55
|
3 |
|
$output->writeln(sprintf('Generated new migration class to "<info>%s</info>"', $path)); |
56
|
3 |
|
} |
57
|
|
|
|
58
|
|
|
protected function procOpen(string $editorCommand, string $path) : void |
59
|
|
|
{ |
60
|
|
|
proc_open($editorCommand . ' ' . escapeshellarg($path), [], $pipes); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|