diff --git a/README.md b/README.md index b9fc8b9..3a1da93 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Router::configure(static function (Routes $routes, MappingInterfaces $mappingInt $routes->redirect('docs', 'https://gacela-project.com/'); # http://localhost:8081?number=456 - $routes->get('/', CustomController::class); + $routes->match(['GET', 'POST'], '/', CustomController::class); # http://localhost:8081/custom/123 $routes->get('custom/{number}', CustomControllerWithDependencies::class, 'customAction'); diff --git a/example/example.php b/example/example.php index ca0e839..df7a6ee 100644 --- a/example/example.php +++ b/example/example.php @@ -21,12 +21,13 @@ public function __construct( public function __invoke(): string { $number = $this->request->get('number'); + $method = $this->request->get('REQUEST_METHOD'); if (!empty($number)) { - return "__invoke with GET 'number'={$number}"; + return sprintf("__invoke with %s 'number'=%d", $method, $number); } - return '__invoke'; + return '__invoke with ' . $method; } public function customAction(int $number = 0): string @@ -40,7 +41,7 @@ public function customAction(int $number = 0): string $routes->redirect('docs', 'https://gacela-project.com/'); # Try it out: http://localhost:8081?number=456 - $routes->get('/', Controller::class); + $routes->match(['GET', 'POST'], '/', Controller::class); # Try it out: http://localhost:8081/custom/123 $routes->get('custom/{number}', Controller::class, 'customAction'); diff --git a/src/Router/Entities/Request.php b/src/Router/Entities/Request.php index 0dbba79..c5d57d2 100644 --- a/src/Router/Entities/Request.php +++ b/src/Router/Entities/Request.php @@ -15,6 +15,7 @@ final class Request public const METHOD_POST = 'POST'; public const METHOD_PUT = 'PUT'; public const METHOD_TRACE = 'TRACE'; + public const ALL_METHODS = [ self::METHOD_CONNECT, self::METHOD_DELETE, @@ -58,6 +59,7 @@ public function get(string $key): mixed { return $this->request[$key] ?? $this->query[$key] + ?? $this->server[$key] ?? null; } }