Skip to content

Commit

Permalink
Further fix for type hinting bug
Browse files Browse the repository at this point in the history
  • Loading branch information
philipobenito committed Nov 20, 2024
1 parent 9a8fa6c commit fe97317
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 20 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/_data/releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 12 additions & 8 deletions src/RouteCollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
16 changes: 8 additions & 8 deletions src/RouteCollectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 5 additions & 2 deletions src/RouteGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit fe97317

Please sign in to comment.