File tree Expand file tree Collapse file tree 6 files changed +42
-8
lines changed
Expand file tree Collapse file tree 6 files changed +42
-8
lines changed Original file line number Diff line number Diff line change 66
77use Attribute ;
88
9- #[Attribute]
9+ #[Attribute(Attribute:: IS_REPEATABLE | Attribute:: TARGET_METHOD ) ]
1010final class Get extends Route
1111{
1212 public function __construct (
Original file line number Diff line number Diff line change 66
77use Attribute ;
88
9- #[Attribute]
9+ #[Attribute(Attribute:: IS_REPEATABLE | Attribute:: TARGET_METHOD ) ]
1010final class Post extends Route
1111{
1212 public function __construct (
Original file line number Diff line number Diff line change 77use Attribute ;
88use Tempest \Reflection \MethodReflector ;
99
10- #[Attribute]
10+ #[Attribute(Attribute:: IS_REPEATABLE | Attribute:: TARGET_METHOD ) ]
1111class Route
1212{
1313 public MethodReflector $ handler ;
Original file line number Diff line number Diff line change @@ -18,13 +18,11 @@ public function __construct(
1818 public function discover (ClassReflector $ class ): void
1919 {
2020 foreach ($ class ->getPublicMethods () as $ method ) {
21- $ routeAttribute = $ method ->getAttribute (Route::class);
21+ $ routeAttributes = $ method ->getAttributes (Route::class);
2222
23- if (! $ routeAttribute ) {
24- continue ;
23+ foreach ( $ routeAttributes as $ routeAttribute ) {
24+ $ this -> routeConfig -> addRoute ( $ method , $ routeAttribute ) ;
2525 }
26-
27- $ this ->routeConfig ->addRoute ($ method , $ routeAttribute );
2826 }
2927 }
3028
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Tests \Tempest \Fixtures \Controllers ;
6+
7+ use Tempest \Http \Get ;
8+ use Tempest \Http \Method ;
9+ use Tempest \Http \Post ;
10+ use Tempest \Http \Response ;
11+ use Tempest \Http \Responses \Ok ;
12+ use Tempest \Http \Route ;
13+
14+ final readonly class ControllerWithRepeatedRoutes
15+ {
16+ #[Route('/repeated/a ' , Method::GET )]
17+ #[Route('/repeated/b ' , Method::GET )]
18+ #[Get('/repeated/c ' )]
19+ #[Get('/repeated/d ' )]
20+ #[Post('/repeated/e ' )]
21+ #[Post('/repeated/f ' )]
22+ public function __invoke (): Response
23+ {
24+ return new Ok ();
25+ }
26+ }
Original file line number Diff line number Diff line change @@ -137,4 +137,14 @@ public function test_trailing_slash(): void
137137 ->get ('/test/1/a/ ' )
138138 ->assertOk ();
139139 }
140+
141+ public function test_repeated_routes (): void
142+ {
143+ $ this ->http ->get ('/repeated/a ' )->assertOk ();
144+ $ this ->http ->get ('/repeated/b ' )->assertOk ();
145+ $ this ->http ->get ('/repeated/c ' )->assertOk ();
146+ $ this ->http ->get ('/repeated/d ' )->assertOk ();
147+ $ this ->http ->post ('/repeated/e ' )->assertOk ();
148+ $ this ->http ->post ('/repeated/f ' )->assertOk ();
149+ }
140150}
You can’t perform that action at this time.
0 commit comments