From c762531c8679dbb800346174913bfa21917ac0b5 Mon Sep 17 00:00:00 2001 From: Sam Light Date: Wed, 10 Jun 2026 19:00:32 +0100 Subject: strategy parameter parsing --- src/AbstractStrategy.php | 14 ++++++++++++++ src/Contracts/Strategy.php | 6 ++++++ 2 files changed, 20 insertions(+) (limited to 'src') diff --git a/src/AbstractStrategy.php b/src/AbstractStrategy.php index 29d9651..206fd0d 100644 --- a/src/AbstractStrategy.php +++ b/src/AbstractStrategy.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Lightscale\Router; +use InvalidArgumentException; use Lightscale\Router\Contracts\Middleware; use Lightscale\Router\Contracts\Strategy; use Psr\Http\Message\RequestInterface; @@ -29,4 +30,17 @@ abstract class AbstractStrategy implements Strategy return $handler($request); } + + public function parseParameters(array $parameters): array + { + foreach ($parameters as $key => $value) { + if (!is_string($value)) { + throw new InvalidArgumentException( + "Parameter {$key} is not a string." + ); + } + } + + return $parameters; + } } diff --git a/src/Contracts/Strategy.php b/src/Contracts/Strategy.php index 7dea459..bf447c3 100644 --- a/src/Contracts/Strategy.php +++ b/src/Contracts/Strategy.php @@ -23,4 +23,10 @@ interface Strategy public function runRoute(RouteCall $call): ResponseInterface; public function notFound(RequestInterface $request): ResponseInterface; + + /** + * @param array $parameters + * @return array + */ + public function parseParameters(array $parameters): array; } -- cgit v1.2.3