1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* generator command |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Graviton\GeneratorBundle\Command; |
7
|
|
|
|
8
|
|
|
use Graviton\GeneratorBundle\Generator\BundleGenerator; |
9
|
|
|
use Graviton\GeneratorBundle\Manipulator\BundleBundleManipulator; |
10
|
|
|
use Sensio\Bundle\GeneratorBundle\Command\GenerateBundleCommand as SymfonyGenerateBundleCommand; |
11
|
|
|
use Sensio\Bundle\GeneratorBundle\Command\Helper\QuestionHelper; |
12
|
|
|
use Sensio\Bundle\GeneratorBundle\Model\Bundle; |
13
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
14
|
|
|
use Symfony\Component\Console\Input\InputOption; |
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
16
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
17
|
|
|
use Symfony\Component\HttpKernel\KernelInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* generator command |
21
|
|
|
* |
22
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
23
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
24
|
|
|
* @link http://swisscom.ch |
25
|
|
|
*/ |
26
|
|
|
class GenerateBundleCommand extends SymfonyGenerateBundleCommand |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
private $loaderBundleName; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var boolean |
35
|
|
|
*/ |
36
|
|
|
private $doUpdate; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritDoc} |
40
|
|
|
* |
41
|
|
|
* @return void |
42
|
|
|
*/ |
43
|
18 |
|
protected function configure() |
44
|
|
|
{ |
45
|
18 |
|
parent::configure(); |
46
|
|
|
|
47
|
18 |
|
$this->addOption( |
48
|
18 |
|
'loaderBundleName', |
49
|
18 |
|
'lbn', |
50
|
18 |
|
InputOption::VALUE_OPTIONAL, |
51
|
18 |
|
'Name of the bundle to manipulate, defaults to GravitonCoreBundle', |
52
|
18 |
|
'GravitonCoreBundle' |
53
|
|
|
) |
54
|
18 |
|
->addOption( |
55
|
18 |
|
'doUpdateKernel', |
56
|
18 |
|
'dak', |
57
|
18 |
|
InputOption::VALUE_OPTIONAL, |
58
|
18 |
|
'If "true", update the kernel, "false" if we should skip that.', |
59
|
18 |
|
'true' |
60
|
|
|
) |
61
|
18 |
|
->addOption( |
62
|
18 |
|
'deleteBefore', |
63
|
18 |
|
'delbef', |
64
|
18 |
|
InputOption::VALUE_OPTIONAL, |
65
|
18 |
|
'If a string, that directory will be deleted prior to generation', |
66
|
18 |
|
null |
67
|
|
|
) |
68
|
18 |
|
->setName('graviton:generate:bundle') |
69
|
18 |
|
->setDescription('Generates a graviton bundle'); |
70
|
18 |
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* {@inheritDoc} |
74
|
|
|
* |
75
|
|
|
* @param InputInterface $input input |
76
|
|
|
* @param OutputInterface $output output |
77
|
|
|
* |
78
|
|
|
* @return void |
79
|
|
|
*/ |
80
|
14 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
81
|
|
|
{ |
82
|
14 |
|
$this->loaderBundleName = $input->getOption('loaderBundleName'); |
83
|
14 |
|
$this->doUpdate = $input->getOption('doUpdateKernel'); |
84
|
|
|
|
85
|
14 |
|
$deleteBefore = $input->getOption('deleteBefore'); |
86
|
14 |
|
$fs = new Filesystem(); |
87
|
14 |
|
if ($deleteBefore != null && $fs->exists($deleteBefore)) { |
88
|
|
|
$fs->remove($deleteBefore); |
89
|
|
|
} |
90
|
|
|
|
91
|
14 |
|
parent::execute( |
92
|
|
|
$input, |
93
|
|
|
$output |
94
|
|
|
); |
95
|
14 |
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* {@inheritDoc} |
99
|
|
|
* Add the new bundle to the BundleBundle loader infrastructure instead of main kernel |
100
|
|
|
* |
101
|
|
|
* @param OutputInterface $output output |
102
|
|
|
* @param KernelInterface $kernel kernel |
103
|
|
|
* @param Bundle $bundle bundle |
104
|
|
|
* |
105
|
|
|
* @return string[] |
|
|
|
|
106
|
|
|
*/ |
107
|
|
|
protected function updateKernel(OutputInterface $output, KernelInterface $kernel, Bundle $bundle) |
108
|
|
|
{ |
109
|
|
|
// skip if kernel manipulation disabled by options (defaults to true) |
110
|
|
|
if ($this->doUpdate == 'false') { |
111
|
|
|
return; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
$output->write('Enabling the bundle inside the core bundle: '); |
115
|
|
|
$coreBundle = $kernel->getBundle($this->loaderBundleName); |
116
|
|
|
if (!is_a( |
117
|
|
|
$coreBundle, |
118
|
|
|
'\Graviton\BundleBundle\GravitonBundleInterface' |
119
|
|
|
) |
120
|
|
|
) { |
121
|
|
|
throw new \LogicException( |
122
|
|
|
'GravitonCoreBundle does not implement GravitonBundleInterface' |
123
|
|
|
); |
124
|
|
|
} |
125
|
|
|
$manip = new BundleBundleManipulator($coreBundle); |
126
|
|
|
try { |
127
|
|
|
$ret = $auto ? $manip->addBundle($namespace . '\\' . $bundle) : false; |
128
|
|
|
|
129
|
|
|
if (!$ret) { |
130
|
|
|
$reflected = new \ReflectionObject($kernel); |
131
|
|
|
|
132
|
|
|
return array( |
133
|
|
|
sprintf( |
134
|
|
|
'- Edit <comment>%s</comment>', |
135
|
|
|
$reflected->getFilename() |
136
|
|
|
), |
137
|
|
|
' and add the following bundle in the <comment>GravitonCoreBundle::getBundles()</comment> method:', |
138
|
|
|
'', |
139
|
|
|
sprintf( |
140
|
|
|
' <comment>new %s(),</comment>', |
141
|
|
|
$namespace . '\\' . $bundle |
142
|
|
|
), |
143
|
|
|
'' |
144
|
|
|
); |
145
|
|
|
} |
146
|
|
|
} catch (\RuntimeException $e) { |
147
|
|
|
return array( |
148
|
|
|
sprintf( |
149
|
|
|
'Bundle <comment>%s</comment> is already defined in <comment>%s)</comment>.', |
150
|
|
|
$namespace . '\\' . $bundle, |
151
|
|
|
'sGravitonCoreBundle::getBundles()' |
152
|
|
|
), |
153
|
|
|
'' |
154
|
|
|
); |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* {@inheritDoc} |
160
|
|
|
* Don't check routing since graviton bundles usually get routed explicitly based on their naming. |
161
|
|
|
* |
162
|
|
|
* @param OutputInterface $output output |
163
|
|
|
* @param Bundle $bundle bundle |
164
|
|
|
* |
165
|
|
|
* @return string[] |
166
|
|
|
*/ |
167
|
14 |
|
protected function updateRouting(OutputInterface $output, Bundle $bundle) |
168
|
|
|
{ |
169
|
14 |
|
return array(); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* {@inheritDoc} |
174
|
|
|
* Don't do anything with the configuration since we load our bundles dynamically using the bundle-bundle-bundle |
175
|
|
|
* |
176
|
|
|
* @param OutputInterface $output output |
177
|
|
|
* @param Bundle $bundle bundle |
178
|
|
|
* |
179
|
|
|
* @return void |
180
|
|
|
*/ |
181
|
4 |
|
protected function updateConfiguration(OutputInterface $output, Bundle $bundle) |
182
|
|
|
{ |
183
|
4 |
|
return; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* {@inheritDoc} |
188
|
|
|
* Use an overridden generator to make nicer code |
189
|
|
|
* |
190
|
|
|
* @return BundleGenerator |
191
|
|
|
*/ |
192
|
|
|
protected function createGenerator() |
193
|
|
|
{ |
194
|
|
|
return new BundleGenerator(); |
195
|
|
|
} |
196
|
|
|
} |
197
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.