1717use Symfony \Component \Console \Input \InputOption ;
1818use Symfony \Component \Console \Output \OutputInterface ;
1919use Symfony \Component \Console \Style \SymfonyStyle ;
20+ use Symfony \Component \DependencyInjection \Exception \ServiceNotFoundException ;
2021use Symfony \Component \Routing \RouterInterface ;
2122use Symfony \Component \Routing \Route ;
2223
@@ -85,13 +86,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
8586 throw new \InvalidArgumentException (sprintf ('The route "%s" does not exist. ' , $ name ));
8687 }
8788
88- $ this ->convertController ($ route );
89+ $ callable = $ this ->extractCallable ($ route );
8990
9091 $ helper ->describe ($ io , $ route , array (
9192 'format ' => $ input ->getOption ('format ' ),
9293 'raw_text ' => $ input ->getOption ('raw ' ),
9394 'name ' => $ name ,
9495 'output ' => $ io ,
96+ 'callable ' => $ callable ,
9597 ));
9698 } else {
9799 foreach ($ routes as $ route ) {
@@ -109,12 +111,38 @@ protected function execute(InputInterface $input, OutputInterface $output)
109111
110112 private function convertController (Route $ route )
111113 {
112- $ nameParser = $ this ->getContainer ()->get ('controller_name_converter ' );
113114 if ($ route ->hasDefault ('_controller ' )) {
115+ $ nameParser = $ this ->getContainer ()->get ('controller_name_converter ' );
114116 try {
115117 $ route ->setDefault ('_controller ' , $ nameParser ->build ($ route ->getDefault ('_controller ' )));
116118 } catch (\InvalidArgumentException $ e ) {
117119 }
118120 }
119121 }
122+
123+ private function extractCallable (Route $ route )
124+ {
125+ if (!$ route ->hasDefault ('_controller ' )) {
126+ return ;
127+ }
128+
129+ $ controller = $ route ->getDefault ('_controller ' );
130+
131+ if (1 === substr_count ($ controller , ': ' )) {
132+ list ($ service , $ method ) = explode (': ' , $ controller );
133+ try {
134+ return sprintf ('%s::%s ' , get_class ($ this ->getContainer ()->get ($ service )), $ method );
135+ } catch (ServiceNotFoundException $ e ) {
136+ }
137+ }
138+
139+ $ nameParser = $ this ->getContainer ()->get ('controller_name_converter ' );
140+ try {
141+ $ shortNotation = $ nameParser ->build ($ controller );
142+ $ route ->setDefault ('_controller ' , $ shortNotation );
143+
144+ return $ controller ;
145+ } catch (\InvalidArgumentException $ e ) {
146+ }
147+ }
120148}
0 commit comments