@@ -55,6 +55,7 @@ protected function configure(): void
55
55
new InputOption ('show-aliases ' , null , InputOption::VALUE_NONE , 'Show aliases in overview ' ),
56
56
new InputOption ('format ' , null , InputOption::VALUE_REQUIRED , \sprintf ('The output format ("%s") ' , implode ('", " ' , $ this ->getAvailableFormatOptions ())), 'txt ' ),
57
57
new InputOption ('raw ' , null , InputOption::VALUE_NONE , 'To output raw route(s) ' ),
58
+ new InputOption ('method ' , null , InputOption::VALUE_REQUIRED , 'Filter by HTTP method ' , null , ['GET ' , 'POST ' , 'PUT ' , 'DELETE ' , 'PATCH ' ]),
58
59
])
59
60
->setHelp (<<<'EOF'
60
61
The <info>%command.name%</info> displays the configured routes:
@@ -76,6 +77,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
76
77
{
77
78
$ io = new SymfonyStyle ($ input , $ output );
78
79
$ name = $ input ->getArgument ('name ' );
80
+ $ methodOption = $ input ->getOption ('method ' );
81
+ $ method = $ methodOption ? strtoupper ($ methodOption ) : null ;
79
82
$ helper = new DescriptorHelper ($ this ->fileLinkFormatter );
80
83
$ routes = $ this ->router ->getRouteCollection ();
81
84
$ container = null ;
@@ -85,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
85
88
86
89
if ($ name ) {
87
90
$ route = $ routes ->get ($ name );
88
- $ matchingRoutes = $ this ->findRouteNameContaining ($ name , $ routes );
91
+ $ matchingRoutes = $ this ->findRouteNameContaining ($ name , $ routes, $ method );
89
92
90
93
if (!$ input ->isInteractive () && !$ route && \count ($ matchingRoutes ) > 1 ) {
91
94
$ helper ->describe ($ io , $ this ->findRouteContaining ($ name , $ routes ), [
@@ -94,6 +97,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
94
97
'show_controllers ' => $ input ->getOption ('show-controllers ' ),
95
98
'show_aliases ' => $ input ->getOption ('show-aliases ' ),
96
99
'output ' => $ io ,
100
+ 'method ' => $ method ,
97
101
]);
98
102
99
103
return 0 ;
@@ -124,17 +128,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int
124
128
'show_aliases ' => $ input ->getOption ('show-aliases ' ),
125
129
'output ' => $ io ,
126
130
'container ' => $ container ,
131
+ 'method ' => $ method ,
127
132
]);
128
133
}
129
134
130
135
return 0 ;
131
136
}
132
137
133
- private function findRouteNameContaining (string $ name , RouteCollection $ routes ): array
138
+ private function findRouteNameContaining (string $ name , RouteCollection $ routes, ? string $ method ): array
134
139
{
135
140
$ foundRoutesNames = [];
136
141
foreach ($ routes as $ routeName => $ route ) {
137
- if (false !== stripos ($ routeName , $ name )) {
142
+ if (
143
+ false !== stripos ($ routeName , $ name )
144
+ && (null === $ method || !$ route ->getMethods () || \in_array ($ method , $ route ->getMethods (), true ))
145
+ ) {
138
146
$ foundRoutesNames [] = $ routeName ;
139
147
}
140
148
}
0 commit comments