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,7 +86,12 @@ 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
+ // Converts a short notation service:method to a class::method.
90
+ if ('txt ' === $ input ->getOption ('format ' )) {
91
+ $ this ->convertControllerWithClassName ($ route );
92
+ } else {
93
+ $ this ->convertController ($ route );
94
+ }
89
95
90
96
$ helper ->describe ($ io , $ route , array (
91
97
'format ' => $ input ->getOption ('format ' ),
@@ -109,12 +115,38 @@ protected function execute(InputInterface $input, OutputInterface $output)
109
115
110
116
private function convertController (Route $ route )
111
117
{
112
- $ nameParser = $ this ->getContainer ()->get ('controller_name_converter ' );
113
118
if ($ route ->hasDefault ('_controller ' )) {
119
+ $ nameParser = $ this ->getContainer ()->get ('controller_name_converter ' );
114
120
try {
115
121
$ route ->setDefault ('_controller ' , $ nameParser ->build ($ route ->getDefault ('_controller ' )));
116
122
} catch (\InvalidArgumentException $ e ) {
117
123
}
118
124
}
119
125
}
126
+
127
+ private function convertControllerWithClassName (Route $ route )
128
+ {
129
+ if (!$ route ->hasDefault ('_controller ' )) {
130
+ return ;
131
+ }
132
+
133
+ $ controller = $ route ->getDefault ('_controller ' );
134
+
135
+ if (1 === substr_count ($ controller , ': ' )) {
136
+ list ($ service , $ method ) = explode (': ' , $ controller );
137
+ try {
138
+ $ route ->setDefault ('_controller ' , sprintf ("%s \n class: %s " , $ service , get_class ($ this ->getContainer ()->get ($ service )), $ method ));
139
+ } catch (ServiceNotFoundException $ e ) {
140
+ }
141
+
142
+ return ;
143
+ }
144
+
145
+ $ nameParser = $ this ->getContainer ()->get ('controller_name_converter ' );
146
+ try {
147
+ $ shortNotation = $ nameParser ->build ($ controller );
148
+ $ route ->setDefault ('_controller ' , sprintf ("%s \n class: %s " , $ shortNotation , $ controller ));
149
+ } catch (\InvalidArgumentException $ e ) {
150
+ }
151
+ }
120
152
}
0 commit comments