1 | <?php |
||
24 | class GenerateBundleCommand extends SymfonyGenerateBundleCommand |
||
25 | { |
||
26 | |||
27 | /** |
||
28 | * {@inheritDoc} |
||
29 | * |
||
30 | * @return void |
||
31 | */ |
||
32 | 6 | protected function configure() |
|
33 | { |
||
34 | 6 | parent::configure(); |
|
35 | |||
36 | 6 | $this->addOption( |
|
37 | 6 | 'loaderBundleName', |
|
38 | 6 | 'lbn', |
|
39 | 6 | InputOption::VALUE_OPTIONAL, |
|
40 | 6 | 'Name of the bundle to manipulate, defaults to GravitonCoreBundle', |
|
41 | 'GravitonCoreBundle' |
||
42 | 6 | ) |
|
43 | 6 | ->addOption( |
|
44 | 6 | 'doUpdateKernel', |
|
45 | 6 | 'dak', |
|
46 | 6 | InputOption::VALUE_OPTIONAL, |
|
47 | 6 | 'If "true", update the kernel, "false" if we should skip that.', |
|
48 | 'true' |
||
49 | 6 | ) |
|
50 | 6 | ->setName('graviton:generate:bundle') |
|
51 | 6 | ->setDescription('Generates a graviton bundle'); |
|
52 | 6 | } |
|
53 | |||
54 | /** |
||
55 | * {@inheritDoc} |
||
56 | * |
||
57 | * @param InputInterface $input input |
||
58 | * @param OutputInterface $output output |
||
59 | * |
||
60 | * @return void |
||
61 | */ |
||
62 | 6 | protected function execute(InputInterface $input, OutputInterface $output) |
|
63 | { |
||
64 | 6 | parent::execute( |
|
65 | 6 | $input, |
|
66 | $output |
||
67 | 6 | ); |
|
68 | |||
69 | 6 | $output->writeln( |
|
70 | 'Please review Resource/config/config.xml before commiting' |
||
71 | 6 | ); |
|
72 | 6 | } |
|
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 | 6 | protected function updateRouting( |
|
171 | QuestionHelper $questionHelper, |
||
172 | InputInterface $input, |
||
173 | OutputInterface $output, |
||
174 | $bundle, |
||
175 | $format |
||
176 | ) { |
||
177 | 6 | 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() |
||
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.