@@ -63,6 +63,7 @@ public function trans($key)
6363 public function doRun (InputInterface $ input , OutputInterface $ output )
6464 {
6565 $ this ->registerEvents ();
66+ $ this ->registerCommandsFromAutoWireConfiguration ();
6667 return parent ::doRun (
6768 $ input ,
6869 $ output
@@ -164,4 +165,79 @@ private function addOptions()
164165 )
165166 );
166167 }
168+
169+ private function registerCommandsFromAutoWireConfiguration ()
170+ {
171+ $ configuration = $ this ->container ->get ('console.configuration_manager ' )
172+ ->getConfiguration ();
173+
174+ $ autoWireForcedCommands = $ configuration ->get (
175+ sprintf (
176+ 'application.autowire.commands.forced '
177+ )
178+ );
179+
180+ foreach ($ autoWireForcedCommands as $ autoWireForcedCommand ) {
181+ try {
182+ $ reflectionClass = new \ReflectionClass (
183+ $ autoWireForcedCommand ['class ' ]
184+ );
185+
186+ $ command = $ reflectionClass ->newInstance ();
187+
188+ if (method_exists ($ command , 'setTranslator ' )) {
189+ $ command ->setTranslator (
190+ $ this ->container ->get ('console.translator_manager ' )
191+ );
192+ }
193+ if (method_exists ($ command , 'setContainer ' )) {
194+ $ command ->setContainer (
195+ $ this ->container ->get ('service_container ' )
196+ );
197+ }
198+
199+ $ this ->add ($ command );
200+ } catch (\Exception $ e ) {
201+ continue ;
202+ }
203+ }
204+
205+ $ autoWireNameCommand = $ configuration ->get (
206+ sprintf (
207+ 'application.autowire.commands.name.%s ' ,
208+ $ this ->commandName
209+ )
210+ );
211+
212+ if ($ autoWireNameCommand ) {
213+ try {
214+ $ arguments = [];
215+ if (array_key_exists ('arguments ' , $ autoWireNameCommand )) {
216+ foreach ($ autoWireNameCommand ['arguments ' ] as $ argument ) {
217+ $ argument = substr ($ argument , 1 );
218+ $ arguments [] = $ this ->container ->get ($ argument );
219+ }
220+ }
221+
222+ $ reflectionClass = new \ReflectionClass (
223+ $ autoWireNameCommand ['class ' ]
224+ );
225+ $ command = $ reflectionClass ->newInstanceArgs ($ arguments );
226+
227+ if (method_exists ($ command , 'setTranslator ' )) {
228+ $ command ->setTranslator (
229+ $ this ->container ->get ('console.translator_manager ' )
230+ );
231+ }
232+ if (method_exists ($ command , 'setContainer ' )) {
233+ $ command ->setContainer (
234+ $ this ->container ->get ('service_container ' )
235+ );
236+ }
237+
238+ $ this ->add ($ command );
239+ } catch (\Exception $ e ) {
240+ }
241+ }
242+ }
167243}
0 commit comments