console-helpers /
svn-buddy
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 SVN-Buddy 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/svn-buddy |
||
| 9 | */ |
||
| 10 | |||
| 11 | namespace ConsoleHelpers\SVNBuddy\Command; |
||
| 12 | |||
| 13 | |||
| 14 | use ConsoleHelpers\SVNBuddy\Database\Migration\MigrationManager; |
||
| 15 | use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; |
||
| 16 | use Symfony\Component\Console\Input\InputArgument; |
||
| 17 | use Symfony\Component\Console\Input\InputInterface; |
||
| 18 | use Symfony\Component\Console\Input\InputOption; |
||
| 19 | use Symfony\Component\Console\Output\OutputInterface; |
||
| 20 | |||
| 21 | class MigrationCreateCommand extends AbstractCommand implements IAggregatorAwareCommand |
||
| 22 | { |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Migration manager. |
||
| 26 | * |
||
| 27 | * @var MigrationManager |
||
| 28 | */ |
||
| 29 | private $_migrationManager; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * {@inheritdoc} |
||
|
1 ignored issue
–
show
introduced
by
Loading history...
|
|||
| 33 | */ |
||
|
1 ignored issue
–
show
|
|||
| 34 | protected function configure() |
||
| 35 | { |
||
| 36 | $this |
||
| 37 | ->setName('migration:create') |
||
| 38 | ->setDescription( |
||
| 39 | 'Creates new database migration' |
||
| 40 | ) |
||
| 41 | ->addArgument( |
||
| 42 | 'name', |
||
| 43 | InputArgument::REQUIRED, |
||
| 44 | 'Migration name' |
||
| 45 | ) |
||
| 46 | ->addOption( |
||
| 47 | 'extension', |
||
| 48 | 'e', |
||
| 49 | InputOption::VALUE_REQUIRED, |
||
| 50 | 'Migration file extension', |
||
| 51 | 'sql' |
||
| 52 | ); |
||
| 53 | |||
| 54 | parent::configure(); |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Prepare dependencies. |
||
| 59 | * |
||
| 60 | * @return void |
||
| 61 | */ |
||
| 62 | protected function prepareDependencies() |
||
| 63 | { |
||
| 64 | parent::prepareDependencies(); |
||
| 65 | |||
| 66 | $container = $this->getContainer(); |
||
| 67 | |||
| 68 | $this->_migrationManager = $container['migration_manager']; |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Return possible values for the named option |
||
| 73 | * |
||
| 74 | * @param string $optionName Option name. |
||
| 75 | * @param CompletionContext $context Completion context. |
||
| 76 | * |
||
| 77 | * @return array |
||
| 78 | */ |
||
| 79 | public function completeOptionValues($optionName, CompletionContext $context) |
||
| 80 | { |
||
| 81 | $ret = parent::completeOptionValues($optionName, $context); |
||
| 82 | |||
| 83 | if ( $optionName === 'extension' ) { |
||
| 84 | return $this->_migrationManager->getMigrationFileExtensions(); |
||
| 85 | } |
||
| 86 | |||
| 87 | return $ret; |
||
| 88 | } |
||
| 89 | |||
| 90 | /** |
||
|
2 ignored issues
–
show
|
|||
| 91 | * {@inheritdoc} |
||
|
1 ignored issue
–
show
|
|||
| 92 | */ |
||
|
1 ignored issue
–
show
|
|||
| 93 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 94 | { |
||
| 95 | $migration_name = $this->_migrationManager->createMigration( |
||
| 96 | $this->io->getArgument('name'), |
||
| 97 | $this->io->getOption('extension') |
||
| 98 | ); |
||
| 99 | |||
| 100 | $this->io->writeln('Migration <info>' . $migration_name . '</info> created.'); |
||
| 101 | } |
||
| 102 | |||
| 103 | } |
||
| 104 |