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