From fe973177260c19cb696654f1b0f868a8388ee035 Mon Sep 17 00:00:00 2001 From: Phil Bennett Date: Wed, 20 Nov 2024 12:31:36 +0000 Subject: [PATCH] Further fix for type hinting bug --- CHANGELOG.md | 5 +++++ docs/_data/releases.yml | 2 +- src/RouteCollectionInterface.php | 20 ++++++++++++-------- src/RouteCollectionTrait.php | 16 ++++++++-------- src/RouteGroup.php | 7 +++++-- src/Router.php | 2 +- 6 files changed, 32 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9c80ee..660169b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [6.1.1] 2024-11 + +### Fixed +- Further fixes for type hinting bug related to array based callables with a string class name. + ## [6.1.0] 2024-11 ### Fixed diff --git a/docs/_data/releases.yml b/docs/_data/releases.yml index 3d9b23a..38879bb 100644 --- a/docs/_data/releases.yml +++ b/docs/_data/releases.yml @@ -22,7 +22,7 @@ name: League\Route 6.x type: Current requires: PHP >= 8.1.0 - release: 6.1.0 - 2024-11 + release: 6.1.1 - 2024-11 support: Ongoing url: /6.x/ menu: diff --git a/src/RouteCollectionInterface.php b/src/RouteCollectionInterface.php index 1ab7c17..ab1bd72 100644 --- a/src/RouteCollectionInterface.php +++ b/src/RouteCollectionInterface.php @@ -8,12 +8,16 @@ interface RouteCollectionInterface { - public function delete(string $path, string|callable $handler): Route; - public function get(string $path, string|callable $handler): Route; - public function head(string $path, string|callable $handler): Route; - public function map(string|array $method, string $path, string|callable|RequestHandlerInterface $handler): Route; - public function options(string $path, string|callable $handler): Route; - public function patch(string $path, string|callable $handler): Route; - public function post(string $path, string|callable $handler): Route; - public function put(string $path, string|callable $handler): Route; + public function delete(string $path, callable|array|string|RequestHandlerInterface $handler): Route; + public function get(string $path, callable|array|string|RequestHandlerInterface $handler): Route; + public function head(string $path, callable|array|string|RequestHandlerInterface $handler): Route; + public function map( + string|array $method, + string $path, + callable|array|string|RequestHandlerInterface $handler + ): Route; + public function options(string $path, callable|array|string|RequestHandlerInterface $handler): Route; + public function patch(string $path, callable|array|string|RequestHandlerInterface $handler): Route; + public function post(string $path, callable|array|string|RequestHandlerInterface $handler): Route; + public function put(string $path, callable|array|string|RequestHandlerInterface $handler): Route; } diff --git a/src/RouteCollectionTrait.php b/src/RouteCollectionTrait.php index 9db7a1f..c153107 100644 --- a/src/RouteCollectionTrait.php +++ b/src/RouteCollectionTrait.php @@ -12,40 +12,40 @@ trait RouteCollectionTrait abstract public function map( string|array $method, string $path, - string|callable|RequestHandlerInterface $handler + callable|array|string|RequestHandlerInterface $handler ): Route; - public function delete(string $path, string|callable $handler): Route + public function delete(string $path, callable|array|string|RequestHandlerInterface $handler): Route { return $this->map(Request::METHOD_DELETE, $path, $handler); } - public function get(string $path, string|callable $handler): Route + public function get(string $path, callable|array|string|RequestHandlerInterface $handler): Route { return $this->map(Request::METHOD_GET, $path, $handler); } - public function head(string $path, string|callable $handler): Route + public function head(string $path, callable|array|string|RequestHandlerInterface $handler): Route { return $this->map(Request::METHOD_HEAD, $path, $handler); } - public function options(string $path, string|callable $handler): Route + public function options(string $path, callable|array|string|RequestHandlerInterface $handler): Route { return $this->map(Request::METHOD_OPTIONS, $path, $handler); } - public function patch(string $path, string|callable $handler): Route + public function patch(string $path, callable|array|string|RequestHandlerInterface $handler): Route { return $this->map(Request::METHOD_PATCH, $path, $handler); } - public function post(string $path, string|callable $handler): Route + public function post(string $path, callable|array|string|RequestHandlerInterface $handler): Route { return $this->map(Request::METHOD_POST, $path, $handler); } - public function put(string $path, string|callable $handler): Route + public function put(string $path, callable|array|string|RequestHandlerInterface $handler): Route { return $this->map(Request::METHOD_PUT, $path, $handler); } diff --git a/src/RouteGroup.php b/src/RouteGroup.php index 12822ed..85a15b7 100644 --- a/src/RouteGroup.php +++ b/src/RouteGroup.php @@ -43,8 +43,11 @@ public function getPrefix(): string return $this->prefix; } - public function map(string|array $method, string $path, string|callable|RequestHandlerInterface $handler): Route - { + public function map( + string|array $method, + string $path, + callable|array|string|RequestHandlerInterface $handler + ): Route { $path = ($path === '/') ? $this->prefix : $this->prefix . sprintf('/%s', ltrim($path, '/')); $route = $this->collection->map($method, $path, $handler); diff --git a/src/Router.php b/src/Router.php index cd6458f..a8974d1 100644 --- a/src/Router.php +++ b/src/Router.php @@ -120,7 +120,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface public function map( string|array $method, string $path, - string|callable|RequestHandlerInterface $handler + callable|array|string|RequestHandlerInterface $handler ): Route { $path = sprintf('/%s', ltrim($path, '/')); $route = new Route($method, $path, $handler);