-
Notifications
You must be signed in to change notification settings - Fork 189
/
GenerateFormPagePartsCommand.php
119 lines (101 loc) · 3.62 KB
/
GenerateFormPagePartsCommand.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
namespace Kunstmaan\GeneratorBundle\Command;
use Kunstmaan\GeneratorBundle\Generator\DefaultPagePartGenerator;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
/**
* Generates the default form pageparts
*/
class GenerateFormPagePartsCommand extends KunstmaanGenerateCommand
{
/**
* @var BundleInterface
*/
private $bundle;
/**
* @var string
*/
private $prefix;
/**
* @see Command
*/
protected function configure()
{
$this->setDescription('Generates default form pageparts')
->setHelp(
<<<'EOT'
The <info>kuma:generate:form-pageparts</info> command generates the default form pageparts and adds the pageparts configuration.
<info>php bin/console kuma:generate:form-pageparts</info>
EOT
)
->addOption('namespace', '', InputOption::VALUE_OPTIONAL, 'The namespace to generate the default form pageparts in')
->addOption('prefix', '', InputOption::VALUE_OPTIONAL, 'The prefix to be used in the table name of the generated entity')
->setName('kuma:generate:form-pageparts');
}
/**
* {@inheritdoc}
*/
protected function getWelcomeText()
{
return 'Welcome to the Kunstmaan default form pageparts generator';
}
/**
* {@inheritdoc}
*/
protected function doExecute()
{
$this->assistant->writeSection('Default Form PageParts generation');
$pagepartNames = [
'AbstractFormPagePart',
'CheckboxPagePart',
'ChoicePagePart',
'EmailPagePart',
'FileUploadPagePart',
'MultiLineTextPagePart',
'SingleLineTextPagePart',
'SubmitButtonPagePart',
];
foreach ($pagepartNames as $pagepartName) {
$this->createGenerator()->generate($this->bundle, $pagepartName, $this->prefix, [], false);
}
$this->assistant->writeSection('PageParts successfully created', 'bg=green;fg=black');
$this->assistant->writeLine(
[
'Make sure you update your database first before you test the pagepart:',
' Directly update your database: <comment>bin/console doctrine:schema:update --force</comment>',
' Create a Doctrine migration and run it: <comment>bin/console doctrine:migrations:diff && bin/console doctrine:migrations:migrate</comment>',
]
);
return 0;
}
/**
* {@inheritdoc}
*/
protected function doInteract()
{
if (!$this->isBundleAvailable('KunstmaanPagePartBundle')) {
$this->assistant->writeError('KunstmaanPagePartBundle not found', true);
}
$this->assistant->writeLine(["This command helps you to generate the form pageparts.\n"]);
/**
* Ask for which bundle we need to create the pagepart
*/
$bundleNamespace = $this->assistant->getOptionOrDefault('namespace', null);
$this->bundle = $this->askForBundleName('pagepart', $bundleNamespace);
/*
* Ask the database table prefix
*/
$this->prefix = $this->askForPrefix(null, $this->bundle->getNamespace());
}
/**
* Get the generator.
*
* @return DefaultPagePartGenerator
*/
protected function createGenerator()
{
$filesystem = $this->getContainer()->get('filesystem');
$registry = $this->getContainer()->get('doctrine');
return new DefaultPagePartGenerator($filesystem, $registry, '/pagepart', $this->assistant, $this->getContainer());
}
}