-
-
Notifications
You must be signed in to change notification settings - Fork 384
/
GenerateCommand.php
71 lines (56 loc) · 2.16 KB
/
GenerateCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
declare(strict_types=1);
namespace Doctrine\Migrations\Tools\Console\Command;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use function sprintf;
/**
* The GenerateCommand class is responsible for generating a blank migration class for you to modify to your needs.
*/
#[AsCommand(name: 'migrations:generate', description: 'Generate a blank migration class.')]
final class GenerateCommand extends DoctrineCommand
{
/** @var string|null */
protected static $defaultName = 'migrations:generate';
protected function configure(): void
{
$this
->setAliases(['generate'])
->setDescription('Generate a blank migration class.')
->addOption(
'namespace',
null,
InputOption::VALUE_REQUIRED,
'The namespace to use for the migration (must be in the list of configured namespaces)',
)
->setHelp(<<<'EOT'
The <info>%command.name%</info> command generates a blank migration class:
<info>%command.full_name%</info>
EOT);
parent::configure();
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$migrationGenerator = $this->getDependencyFactory()->getMigrationGenerator();
$namespace = $this->getNamespace($input, $output);
$fqcn = $this->getDependencyFactory()->getClassNameGenerator()->generateClassName($namespace);
$path = $migrationGenerator->generateMigration($fqcn);
$this->io->text([
sprintf('Generated new migration class to "<info>%s</info>"', $path),
'',
sprintf(
'To run just this migration for testing purposes, you can use <info>migrations:execute --up \'%s\'</info>',
$fqcn,
),
'',
sprintf(
'To revert the migration you can use <info>migrations:execute --down \'%s\'</info>',
$fqcn,
),
'',
]);
return 0;
}
}