@@ -81,7 +81,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int
81
81
$ routes = $ this ->router ->getRouteCollection ();
82
82
83
83
if ($ name ) {
84
- if (!($ route = $ routes ->get ($ name )) && $ matchingRoutes = $ this ->findRouteNameContaining ($ name , $ routes )) {
84
+ $ route = $ routes ->get ($ name );
85
+ $ matchingRoutes = $ this ->findRouteNameContaining ($ name , $ routes );
86
+
87
+ if (!$ input ->isInteractive () && !$ route && \count ($ matchingRoutes ) > 1 ) {
88
+ $ helper ->describe ($ io , $ this ->findRouteContaining ($ name , $ routes ), [
89
+ 'format ' => $ input ->getOption ('format ' ),
90
+ 'raw_text ' => $ input ->getOption ('raw ' ),
91
+ 'show_controllers ' => $ input ->getOption ('show-controllers ' ),
92
+ 'output ' => $ io ,
93
+ ]);
94
+
95
+ return 0 ;
96
+ }
97
+
98
+ if (!$ route && $ matchingRoutes ) {
85
99
$ default = 1 === \count ($ matchingRoutes ) ? $ matchingRoutes [0 ] : null ;
86
100
$ name = $ io ->choice ('Select one of the matching routes ' , $ matchingRoutes , $ default );
87
101
$ route = $ routes ->get ($ name );
@@ -120,4 +134,16 @@ private function findRouteNameContaining(string $name, RouteCollection $routes):
120
134
121
135
return $ foundRoutesNames ;
122
136
}
137
+
138
+ private function findRouteContaining (string $ name , RouteCollection $ routes ): RouteCollection
139
+ {
140
+ $ foundRoutes = new RouteCollection ();
141
+ foreach ($ routes as $ routeName => $ route ) {
142
+ if (false !== stripos ($ routeName , $ name )) {
143
+ $ foundRoutes ->add ($ routeName , $ route );
144
+ }
145
+ }
146
+
147
+ return $ foundRoutes ;
148
+ }
123
149
}
0 commit comments