console-helpers /
code-insight
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * This file is part of the Code-Insight library. |
||
| 4 | * For the full copyright and license information, please view |
||
| 5 | * the LICENSE file that was distributed with this source code. |
||
| 6 | * |
||
| 7 | * @copyright Alexander Obuhovich <[email protected]> |
||
| 8 | * @link https://github.com/console-helpers/code-insight |
||
| 9 | */ |
||
| 10 | |||
| 11 | namespace ConsoleHelpers\CodeInsight\Command\Dev; |
||
| 12 | |||
| 13 | |||
| 14 | use ConsoleHelpers\CodeInsight\Command\AbstractCommand; |
||
| 15 | use ConsoleHelpers\DatabaseMigration\MigrationManager; |
||
| 16 | use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; |
||
| 17 | use Symfony\Component\Console\Input\InputArgument; |
||
| 18 | use Symfony\Component\Console\Input\InputInterface; |
||
| 19 | use Symfony\Component\Console\Input\InputOption; |
||
| 20 | use Symfony\Component\Console\Output\OutputInterface; |
||
| 21 | |||
| 22 | class MigrationCreateCommand extends AbstractCommand |
||
| 23 | { |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Migration manager. |
||
| 27 | * |
||
| 28 | * @var MigrationManager |
||
| 29 | */ |
||
| 30 | private $_migrationManager; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * {@inheritdoc} |
||
| 34 | */ |
||
| 35 | protected function configure() |
||
| 36 | { |
||
| 37 | $this |
||
| 38 | ->setName('dev:migration-create') |
||
| 39 | ->setDescription( |
||
| 40 | 'Creates new database migration' |
||
| 41 | ) |
||
| 42 | ->addArgument( |
||
| 43 | 'name', |
||
| 44 | InputArgument::REQUIRED, |
||
| 45 | 'Migration name' |
||
| 46 | ) |
||
| 47 | ->addOption( |
||
| 48 | 'extension', |
||
| 49 | 'e', |
||
| 50 | InputOption::VALUE_REQUIRED, |
||
| 51 | 'Migration file extension', |
||
| 52 | 'sql' |
||
| 53 | ); |
||
| 54 | |||
| 55 | parent::configure(); |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Prepare dependencies. |
||
| 60 | * |
||
| 61 | * @return void |
||
| 62 | */ |
||
| 63 | protected function prepareDependencies() |
||
| 64 | { |
||
| 65 | parent::prepareDependencies(); |
||
| 66 | |||
| 67 | $container = $this->getContainer(); |
||
| 68 | |||
| 69 | $this->_migrationManager = $container['migration_manager']; |
||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Return possible values for the named option |
||
| 74 | * |
||
| 75 | * @param string $optionName Option name. |
||
| 76 | * @param CompletionContext $context Completion context. |
||
| 77 | * |
||
| 78 | * @return array |
||
| 79 | */ |
||
| 80 | public function completeOptionValues($optionName, CompletionContext $context) |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 81 | { |
||
| 82 | $ret = parent::completeOptionValues($optionName, $context); |
||
|
0 ignored issues
–
show
|
|||
| 83 | |||
| 84 | if ( $optionName === 'extension' ) { |
||
|
0 ignored issues
–
show
|
|||
| 85 | return $this->_migrationManager->getMigrationFileExtensions(); |
||
| 86 | } |
||
| 87 | |||
| 88 | return $ret; |
||
| 89 | } |
||
| 90 | |||
| 91 | /** |
||
| 92 | * {@inheritdoc} |
||
| 93 | */ |
||
| 94 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 95 | { |
||
| 96 | $migration_name = $this->_migrationManager->createMigration( |
||
| 97 | $this->io->getArgument('name'), |
||
| 98 | $this->io->getOption('extension') |
||
| 99 | ); |
||
| 100 | |||
| 101 | $this->io->writeln('Migration <info>' . $migration_name . '</info> created.'); |
||
| 102 | } |
||
| 103 | |||
| 104 | } |
||
| 105 |