| @@ 39-70 (lines=32) @@ | ||
| 36 | * @return int|null|void |
|
| 37 | * @throws \Exception |
|
| 38 | */ |
|
| 39 | protected function execute(InputInterface $input, OutputInterface $output) |
|
| 40 | { |
|
| 41 | $output->writeln(['<comment>Welcome to the migration generator</comment>']); |
|
| 42 | ||
| 43 | $helper = $this->getHelper('question'); |
|
| 44 | $question = new Question('<info>Please enter the name of the migration: </info>'); |
|
| 45 | $question->setValidator(function($answer) { |
|
| 46 | if (strlen(trim($answer)) === 0) { |
|
| 47 | throw new \RunTimeException('The name of the migration should be not empty'); |
|
| 48 | } |
|
| 49 | ||
| 50 | return $answer; |
|
| 51 | }); |
|
| 52 | ||
| 53 | $migrationName = $helper->ask($input, $output, $question); |
|
| 54 | $baseName = date('YmdHis').'_'.$migrationName.'.php'; |
|
| 55 | $path = $this->getPath($baseName, MIGRATIONS_PATH); |
|
| 56 | ||
| 57 | $placeHolders = [ |
|
| 58 | '<class>', |
|
| 59 | '<tableName>', |
|
| 60 | ]; |
|
| 61 | $replacements = [ |
|
| 62 | Helper::underscoreToCamelCase($migrationName, true), |
|
| 63 | strtolower($migrationName), |
|
| 64 | ]; |
|
| 65 | ||
| 66 | $this->generateCode($placeHolders, $replacements, 'MigrationTemplate.tpl', $path); |
|
| 67 | ||
| 68 | $output->writeln(sprintf('Generated new migration class to "<info>%s</info>"', realpath($path))); |
|
| 69 | ||
| 70 | return; |
|
| 71 | } |
|
| 72 | } |
|
| 73 | ||
| @@ 38-67 (lines=30) @@ | ||
| 35 | * @return int|null|void |
|
| 36 | * @throws \Exception |
|
| 37 | */ |
|
| 38 | protected function execute(InputInterface $input, OutputInterface $output) |
|
| 39 | { |
|
| 40 | $output->writeln(['<comment>Welcome to the seed generator</comment>']); |
|
| 41 | ||
| 42 | $helper = $this->getHelper('question'); |
|
| 43 | $question = new Question('<info>Please enter the name of the seed: </info>'); |
|
| 44 | $question->setValidator(function($answer) { |
|
| 45 | if (strlen(trim($answer)) === 0) { |
|
| 46 | throw new \RunTimeException('The name of the seed should be not empty'); |
|
| 47 | } |
|
| 48 | ||
| 49 | return $answer; |
|
| 50 | }); |
|
| 51 | ||
| 52 | $seedName = $helper->ask($input, $output, $question); |
|
| 53 | $baseName = date('YmdHis').'_'.$seedName.'.php'; |
|
| 54 | $path = $this->getPath($baseName, SEEDS_PATH); |
|
| 55 | $placeHolders = [ |
|
| 56 | '<class>', |
|
| 57 | ]; |
|
| 58 | $replacements = [ |
|
| 59 | Helper::underscoreToCamelCase($seedName, true), |
|
| 60 | ]; |
|
| 61 | ||
| 62 | $this->generateCode($placeHolders, $replacements, 'SeedTemplate.tpl', $path); |
|
| 63 | ||
| 64 | $output->writeln(sprintf('Generated new seed class to "<info>%s</info>"', realpath($path))); |
|
| 65 | ||
| 66 | return; |
|
| 67 | } |
|
| 68 | } |
|
| 69 | ||