summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Light <sam@lightscale.co.uk>2026-06-10 19:00:32 +0100
committerSam Light <sam@lightscale.co.uk>2026-06-10 19:00:32 +0100
commitc762531c8679dbb800346174913bfa21917ac0b5 (patch)
treefe8cea949acde5bc9a15c67b154a46d2d31a4e69 /src
parent0b6c1959528e97087ae1eb4bb098fdc8d689ce99 (diff)
strategy parameter parsing
Diffstat (limited to 'src')
-rw-r--r--src/AbstractStrategy.php14
-rw-r--r--src/Contracts/Strategy.php6
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;
}