1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dami\Cli\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Input\InputArgument, |
6
|
|
|
Symfony\Component\Console\Input\InputOption, |
7
|
|
|
Symfony\Component\Console\Command\Command, |
8
|
|
|
Symfony\Component\Console\Input\InputInterface, |
9
|
|
|
Symfony\Component\Console\Output\OutputInterface, |
10
|
|
|
Symfony\Component\Filesystem\Filesystem; |
11
|
|
|
|
12
|
|
|
use Dami\Migration\TemplateRenderer, |
13
|
|
|
Dami\Migration\FileNameBuilder; |
14
|
|
|
|
15
|
|
|
class CreateCommand extends ContainerAwareCommand |
16
|
|
|
{ |
17
|
|
|
protected function configure() |
18
|
|
|
{ |
19
|
|
|
parent::configure(); |
20
|
|
|
|
21
|
|
|
$this |
22
|
|
|
->setDescription('Create a new migration.') |
23
|
|
|
->addArgument('migration_name', InputArgument::REQUIRED, 'Migration name'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
27
|
|
|
{ |
28
|
|
|
parent::execute($input, $output); |
29
|
|
|
|
30
|
|
|
$arguments = $input->getArguments(); |
31
|
|
|
$migrationName = $arguments['migration_name']; |
32
|
|
|
|
33
|
|
|
$filenameBuilder = new FileNameBuilder($migrationName); |
34
|
|
|
$fileSystem = new Filesystem(); |
35
|
|
|
$templateRenderer = $this->getContainer()->get('dami.template_renderer'); |
36
|
|
|
$migrationDirectory = $this->getContainer()->getparameter('dami.migrations_directory'); |
37
|
|
|
|
38
|
|
|
try { |
39
|
|
|
$fileName = $filenameBuilder->build(); |
40
|
|
|
$path = $migrationDirectory . '/' . $fileName; |
41
|
|
|
$fileSystem->dumpFile($path, $templateRenderer->render($migrationName)); |
42
|
|
|
|
43
|
|
|
$output->writeln('<info>Migration has been created.</info>'); |
44
|
|
|
$output->writeln(sprintf('<comment>Location: %s</comment>', $path)); |
45
|
|
|
} catch (\Exception $e) { |
46
|
|
|
$output->writeln(sprintf("<error>Something went wrong.</error>\n\n%s", $e->getMessage())); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|