11<?php
22namespace Gt \Routing ;
33
4+ use Gt \Routing \Method \Any ;
5+ use Gt \Routing \Method \Connect ;
6+ use Gt \Routing \Method \Delete ;
7+ use Gt \Routing \Method \Get ;
8+ use Gt \Routing \Method \Head ;
49use Gt \Routing \Method \HttpMethodHandler ;
10+ use Gt \Routing \Method \Options ;
11+ use Gt \Routing \Method \Patch ;
12+ use Gt \Routing \Method \Post ;
13+ use Gt \Routing \Method \Put ;
14+ use Gt \Routing \Method \Trace ;
515use Gt \ServiceContainer \Container ;
616use Gt \ServiceContainer \Injector ;
717use Negotiation \Accept ;
1020use ReflectionMethod ;
1121use Gt \Routing \Method \HttpRouteMethod ;
1222
23+
24+ /**
25+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
26+ * @phpcs:disable Generic.Metrics.CyclomaticComplexity
27+ */
1328class RouterCallback {
1429 private Container $ container ;
1530 private Injector $ injector ;
1631 private ContentNegotiator $ contentNegotiator ;
32+ /** @phpstan-ignore-next-line */
1733 private HttpMethodHandler $ httpMethodHandler ;
1834
1935 /** @param ReflectionAttribute<HttpRouteMethod> $attribute */
@@ -38,11 +54,26 @@ public function call(BaseRouter $router):void {
3854
3955 public function isAllowedMethod (string $ requestMethod ):bool {
4056 $ methodsArgument = $ this ->attribute ->getArguments ()["methods " ] ?? [];
41- return $ this ->httpMethodHandler ->isAllowedMethod (
42- $ requestMethod ,
43- $ this ->attribute ->getName (),
44- $ methodsArgument
57+
58+ $ allowedMethods = match ($ this ->attribute ->getName ()) {
59+ Any::class => HttpRoute::METHODS_ALL ,
60+ Connect::class => [HttpRoute::METHOD_CONNECT ],
61+ Delete::class => [HttpRoute::METHOD_DELETE ],
62+ Get::class => [HttpRoute::METHOD_GET ],
63+ Head::class => [HttpRoute::METHOD_HEAD ],
64+ Options::class => [HttpRoute::METHOD_OPTIONS ],
65+ Patch::class => [HttpRoute::METHOD_PATCH ],
66+ Post::class => [HttpRoute::METHOD_POST ],
67+ Put::class => [HttpRoute::METHOD_PUT ],
68+ Trace::class => [HttpRoute::METHOD_TRACE ],
69+ default => $ methodsArgument ,
70+ };
71+ $ allowedMethods = array_map (
72+ "strtoupper " ,
73+ $ allowedMethods
4574 );
75+
76+ return in_array ($ requestMethod , $ allowedMethods );
4677 }
4778
4879 public function matchesPath (string $ requestPath ):bool {
0 commit comments