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 Symfony\Component\Console\Input\InputInterface; |
13
|
|
|
use Symfony\Component\Console\Input\InputOption; |
14
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
15
|
|
|
use Symfony\Component\HttpKernel\KernelInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* generator command |
19
|
|
|
* |
20
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
21
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
22
|
|
|
* @link http://swisscom.ch |
23
|
|
|
*/ |
24
|
|
|
class GenerateBundleCommand extends SymfonyGenerateBundleCommand |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* {@inheritDoc} |
29
|
|
|
* |
30
|
|
|
* @return void |
31
|
|
|
*/ |
32
|
14 |
|
protected function configure() |
33
|
|
|
{ |
34
|
14 |
|
parent::configure(); |
35
|
|
|
|
36
|
14 |
|
$this->addOption( |
37
|
14 |
|
'loaderBundleName', |
38
|
14 |
|
'lbn', |
39
|
14 |
|
InputOption::VALUE_OPTIONAL, |
40
|
14 |
|
'Name of the bundle to manipulate, defaults to GravitonCoreBundle', |
41
|
7 |
|
'GravitonCoreBundle' |
42
|
7 |
|
) |
43
|
14 |
|
->addOption( |
44
|
14 |
|
'doUpdateKernel', |
45
|
14 |
|
'dak', |
46
|
14 |
|
InputOption::VALUE_OPTIONAL, |
47
|
14 |
|
'If "true", update the kernel, "false" if we should skip that.', |
48
|
7 |
|
'true' |
49
|
7 |
|
) |
50
|
14 |
|
->setName('graviton:generate:bundle') |
51
|
14 |
|
->setDescription('Generates a graviton bundle'); |
52
|
14 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritDoc} |
56
|
|
|
* |
57
|
|
|
* @param InputInterface $input input |
58
|
|
|
* @param OutputInterface $output output |
59
|
|
|
* |
60
|
|
|
* @return void |
61
|
|
|
*/ |
62
|
12 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
63
|
|
|
{ |
64
|
12 |
|
parent::execute( |
65
|
6 |
|
$input, |
66
|
|
|
$output |
67
|
6 |
|
); |
68
|
|
|
|
69
|
12 |
|
$output->writeln( |
70
|
6 |
|
'Please review Resource/config/config.xml before commiting' |
71
|
6 |
|
); |
72
|
12 |
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritDoc} |
76
|
|
|
* Add the new bundle to the BundleBundle loader infrastructure instead of main kernel |
77
|
|
|
* |
78
|
|
|
* @param QuestionHelper $questionHelper dialog |
79
|
|
|
* @param InputInterface $input input |
80
|
|
|
* @param OutputInterface $output output |
81
|
|
|
* @param KernelInterface $kernel kernel |
82
|
|
|
* @param string $namespace namespace |
83
|
|
|
* @param string $bundle bundle |
84
|
|
|
* |
85
|
|
|
* @return string[] |
|
|
|
|
86
|
|
|
*/ |
87
|
|
|
protected function updateKernel( |
88
|
|
|
QuestionHelper $questionHelper, |
89
|
|
|
InputInterface $input, |
90
|
|
|
OutputInterface $output, |
91
|
|
|
KernelInterface $kernel, |
92
|
|
|
$namespace, |
93
|
|
|
$bundle |
94
|
|
|
) { |
95
|
|
|
|
96
|
|
|
// skip if kernel manipulation disabled by options (defaults to true) |
97
|
|
|
$doUpdate = $input->getOption('doUpdateKernel'); |
98
|
|
|
if ($doUpdate == 'false') { |
99
|
|
|
return; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
$auto = true; |
103
|
|
|
if ($input->isInteractive()) { |
104
|
|
|
$auto = $questionHelper->doAsk( |
105
|
|
|
$output, |
106
|
|
|
$questionHelper->getQuestion( |
107
|
|
|
'Confirm automatic update of your core bundle', |
108
|
|
|
'yes', |
109
|
|
|
'?' |
110
|
|
|
) |
111
|
|
|
); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
$output->write('Enabling the bundle inside the core bundle: '); |
115
|
|
|
$coreBundle = $kernel->getBundle($input->getOption('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 QuestionHelper $questionHelper dialog |
163
|
|
|
* @param InputInterface $input input |
164
|
|
|
* @param OutputInterface $output output |
165
|
|
|
* @param object $bundle bundle |
166
|
|
|
* @param object $format format |
167
|
|
|
* |
168
|
|
|
* @return string[] |
169
|
|
|
*/ |
170
|
12 |
|
protected function updateRouting( |
171
|
|
|
QuestionHelper $questionHelper, |
172
|
|
|
InputInterface $input, |
173
|
|
|
OutputInterface $output, |
174
|
|
|
$bundle, |
175
|
|
|
$format |
176
|
|
|
) { |
177
|
12 |
|
return array(); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* {@inheritDoc} |
182
|
|
|
* Use an overridden generator to make nicer code |
183
|
|
|
* |
184
|
|
|
* @return BundleGenerator |
185
|
|
|
*/ |
186
|
|
|
protected function createGenerator() |
187
|
|
|
{ |
188
|
|
|
return new BundleGenerator(); |
189
|
|
|
} |
190
|
|
|
} |
191
|
|
|
|
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.