diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/AbstractStrategy.php | 14 | ||||
| -rw-r--r-- | src/Contracts/Strategy.php | 6 |
2 files changed, 20 insertions, 0 deletions
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<string, mixed> $parameters + * @return array<string, string> + */ + public function parseParameters(array $parameters): array; } |
