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