1 | <?php |
||
20 | class GenerateCommand extends AbstractCommand |
||
21 | { |
||
22 | private static $_template = |
||
23 | '<?php declare(strict_types = 1); |
||
24 | |||
25 | namespace <namespace>; |
||
26 | |||
27 | use Doctrine\DBAL\Migrations\AbstractMigration; |
||
28 | use Doctrine\DBAL\Schema\Schema; |
||
29 | |||
30 | /** |
||
31 | * Auto-generated Migration: Please modify to your needs! |
||
32 | */ |
||
33 | class Version<version> extends AbstractMigration |
||
34 | { |
||
35 | public function up(Schema $schema) |
||
36 | { |
||
37 | // this up() migration is auto-generated, please modify it to your needs |
||
38 | <up> |
||
39 | } |
||
40 | |||
41 | public function down(Schema $schema) |
||
42 | { |
||
43 | // this down() migration is auto-generated, please modify it to your needs |
||
44 | <down> |
||
45 | } |
||
46 | } |
||
47 | '; |
||
48 | |||
49 | private $instanceTemplate; |
||
50 | |||
51 | 13 | protected function configure() |
|
52 | { |
||
53 | $this |
||
54 | 13 | ->setName('migrations:generate') |
|
55 | 13 | ->setDescription('Generate a blank migration class.') |
|
56 | 13 | ->addOption('editor-cmd', null, InputOption::VALUE_OPTIONAL, 'Open file with this command upon creation.') |
|
57 | 13 | ->setHelp(<<<EOT |
|
58 | 13 | The <info>%command.name%</info> command generates a blank migration class: |
|
59 | |||
60 | <info>%command.full_name%</info> |
||
61 | |||
62 | You can optionally specify a <comment>--editor-cmd</comment> option to open the generated file in your favorite editor: |
||
63 | |||
64 | <info>%command.full_name% --editor-cmd=mate</info> |
||
65 | EOT |
||
66 | ); |
||
67 | |||
68 | 13 | parent::configure(); |
|
69 | 13 | } |
|
70 | |||
71 | 6 | public function execute(InputInterface $input, OutputInterface $output) |
|
72 | { |
||
73 | 6 | $configuration = $this->getMigrationConfiguration($input, $output); |
|
74 | |||
75 | 6 | $this->loadCustomTemplate($configuration, $output); |
|
76 | |||
77 | 5 | $version = $configuration->generateVersionNumber(); |
|
78 | 5 | $path = $this->generateMigration($configuration, $input, $version); |
|
79 | |||
80 | 5 | $output->writeln(sprintf('Generated new migration class to "<info>%s</info>"', $path)); |
|
81 | 5 | } |
|
82 | |||
83 | 11 | protected function getTemplate() |
|
91 | |||
92 | 11 | protected function generateMigration(Configuration $configuration, InputInterface $input, $version, $up = null, $down = null) |
|
93 | { |
||
122 | |||
123 | 6 | private function loadCustomTemplate(Configuration $configuration, OutputInterface $output) : void |
|
146 | } |
||
147 |