17
17
use Symfony \Component \Console \Input \InputOption ;
18
18
use Symfony \Component \Console \Output \OutputInterface ;
19
19
use Symfony \Component \Console \Style \SymfonyStyle ;
20
+ use Symfony \Component \DependencyInjection \Exception \ServiceNotFoundException ;
20
21
use Symfony \Component \Routing \RouterInterface ;
21
22
use Symfony \Component \Routing \Route ;
22
23
@@ -85,13 +86,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
85
86
throw new \InvalidArgumentException (sprintf ('The route "%s" does not exist. ' , $ name ));
86
87
}
87
88
88
- $ this ->convertController ($ route );
89
+ $ callable = $ this ->extractCallable ($ route );
89
90
90
91
$ helper ->describe ($ io , $ route , array (
91
92
'format ' => $ input ->getOption ('format ' ),
92
93
'raw_text ' => $ input ->getOption ('raw ' ),
93
94
'name ' => $ name ,
94
95
'output ' => $ io ,
96
+ 'callable ' => $ callable ,
95
97
));
96
98
} else {
97
99
foreach ($ routes as $ route ) {
@@ -109,12 +111,38 @@ protected function execute(InputInterface $input, OutputInterface $output)
109
111
110
112
private function convertController (Route $ route )
111
113
{
112
- $ nameParser = $ this ->getContainer ()->get ('controller_name_converter ' );
113
114
if ($ route ->hasDefault ('_controller ' )) {
115
+ $ nameParser = $ this ->getContainer ()->get ('controller_name_converter ' );
114
116
try {
115
117
$ route ->setDefault ('_controller ' , $ nameParser ->build ($ route ->getDefault ('_controller ' )));
116
118
} catch (\InvalidArgumentException $ e ) {
117
119
}
118
120
}
119
121
}
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
+ }
120
148
}
0 commit comments