diff --git a/src/Condition/ConditionHandler.php b/src/Condition/ConditionHandler.php index 3672a0f..1bec5ed 100644 --- a/src/Condition/ConditionHandler.php +++ b/src/Condition/ConditionHandler.php @@ -5,9 +5,15 @@ namespace IngeniozIT\Router\Condition; use Closure; +use IngeniozIT\Router\Condition\Exception\InvalidConditionHandler; +use IngeniozIT\Router\Condition\Exception\InvalidConditionResponse; use Psr\Container\ContainerInterface; use Psr\Http\Message\ServerRequestInterface; +use function is_array; +use function is_callable; +use function is_string; + readonly final class ConditionHandler { private Closure $handler; diff --git a/src/Condition/InvalidConditionHandler.php b/src/Condition/Exception/InvalidConditionHandler.php similarity index 77% rename from src/Condition/InvalidConditionHandler.php rename to src/Condition/Exception/InvalidConditionHandler.php index b9cba50..1a79fb0 100644 --- a/src/Condition/InvalidConditionHandler.php +++ b/src/Condition/Exception/InvalidConditionHandler.php @@ -2,8 +2,9 @@ declare(strict_types=1); -namespace IngeniozIT\Router\Condition; +namespace IngeniozIT\Router\Condition\Exception; +use IngeniozIT\Router\Condition\ConditionException; use InvalidArgumentException; final class InvalidConditionHandler extends InvalidArgumentException implements ConditionException diff --git a/src/Condition/InvalidConditionResponse.php b/src/Condition/Exception/InvalidConditionResponse.php similarity index 73% rename from src/Condition/InvalidConditionResponse.php rename to src/Condition/Exception/InvalidConditionResponse.php index 6e68931..0de93f2 100644 --- a/src/Condition/InvalidConditionResponse.php +++ b/src/Condition/Exception/InvalidConditionResponse.php @@ -2,10 +2,13 @@ declare(strict_types=1); -namespace IngeniozIT\Router\Condition; +namespace IngeniozIT\Router\Condition\Exception; +use IngeniozIT\Router\Condition\ConditionException; use InvalidArgumentException; +use function get_debug_type; + final class InvalidConditionResponse extends InvalidArgumentException implements ConditionException { public function __construct(public mixed $response) diff --git a/src/Middleware/Exception/InvalidMiddlewareHandler.php b/src/Middleware/Exception/InvalidMiddlewareHandler.php new file mode 100644 index 0000000..1576949 --- /dev/null +++ b/src/Middleware/Exception/InvalidMiddlewareHandler.php @@ -0,0 +1,20 @@ +parameters as $parameter) { - if (!preg_match('#^' . $this->parameterPattern($parameter) . '$#', (string) $parameters[$parameter])) { + if (!preg_match('#^' . $this->parameterPattern($parameter) . '$#', (string)$parameters[$parameter])) { throw new InvalidRouteParameter($this->name ?? '', $parameter, $this->parameterPattern($parameter)); } } diff --git a/src/Route/RouteHandler.php b/src/Route/RouteHandler.php index be6b2f8..7f1effa 100644 --- a/src/Route/RouteHandler.php +++ b/src/Route/RouteHandler.php @@ -5,12 +5,17 @@ namespace IngeniozIT\Router\Route; use Closure; +use IngeniozIT\Router\Route\Exception\InvalidRouteHandler; +use IngeniozIT\Router\Route\Exception\InvalidRouteResponse; use Psr\Container\ContainerInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; +use function is_callable; +use function is_string; + readonly final class RouteHandler { private Closure|MiddlewareInterface|RequestHandlerInterface $handler; diff --git a/src/RouteGroup.php b/src/RouteGroup.php index ed53340..34b15f8 100644 --- a/src/RouteGroup.php +++ b/src/RouteGroup.php @@ -6,6 +6,8 @@ use IngeniozIT\Router\Route\RouteElement; +use function array_map; + final class RouteGroup { /** @var RouteElement[]|RouteGroup[] */ diff --git a/src/Router.php b/src/Router.php index 253b989..8880828 100644 --- a/src/Router.php +++ b/src/Router.php @@ -6,9 +6,9 @@ use IngeniozIT\Router\Condition\ConditionHandler; use IngeniozIT\Router\Middleware\MiddlewareHandler; +use IngeniozIT\Router\Route\Exception\RouteNotFound; use IngeniozIT\Router\Route\RouteElement; use IngeniozIT\Router\Route\RouteHandler; -use IngeniozIT\Router\Route\RouteNotFound; use Psr\Container\ContainerInterface; use Psr\Http\Message\{ResponseInterface, ServerRequestInterface}; use Psr\Http\Server\RequestHandlerInterface; diff --git a/tests/CallbackTest.php b/tests/CallbackTest.php index 23ebfc2..247af00 100644 --- a/tests/CallbackTest.php +++ b/tests/CallbackTest.php @@ -5,8 +5,8 @@ use Closure; use IngeniozIT\Http\Message\UriFactory; use IngeniozIT\Router\Route; -use IngeniozIT\Router\Route\InvalidRouteHandler; -use IngeniozIT\Router\Route\InvalidRouteResponse; +use IngeniozIT\Router\Route\Exception\InvalidRouteHandler; +use IngeniozIT\Router\Route\Exception\InvalidRouteResponse; use IngeniozIT\Router\RouteGroup; use IngeniozIT\Router\Tests\Utils\RouterCase; use IngeniozIT\Router\Tests\Utils\TestHandler; diff --git a/tests/ConditionsTest.php b/tests/ConditionsTest.php index 37014f0..89c4fed 100644 --- a/tests/ConditionsTest.php +++ b/tests/ConditionsTest.php @@ -4,8 +4,8 @@ use Closure; use IngeniozIT\Http\Message\UriFactory; -use IngeniozIT\Router\Condition\InvalidConditionHandler; -use IngeniozIT\Router\Condition\InvalidConditionResponse; +use IngeniozIT\Router\Condition\Exception\InvalidConditionHandler; +use IngeniozIT\Router\Condition\Exception\InvalidConditionResponse; use IngeniozIT\Router\Route; use IngeniozIT\Router\RouteGroup; use IngeniozIT\Router\Tests\Utils\RouterCase; diff --git a/tests/MiddlewaresTest.php b/tests/MiddlewaresTest.php index f23bceb..9279d8c 100644 --- a/tests/MiddlewaresTest.php +++ b/tests/MiddlewaresTest.php @@ -4,8 +4,8 @@ use Exception; use IngeniozIT\Http\Message\UriFactory; -use IngeniozIT\Router\Middleware\InvalidMiddlewareHandler; -use IngeniozIT\Router\Middleware\InvalidMiddlewareResponse; +use IngeniozIT\Router\Middleware\Exception\InvalidMiddlewareHandler; +use IngeniozIT\Router\Middleware\Exception\InvalidMiddlewareResponse; use IngeniozIT\Router\Route; use IngeniozIT\Router\RouteGroup; use IngeniozIT\Router\Tests\Utils\RouterCase; diff --git a/tests/NameTest.php b/tests/NameTest.php index be1a55e..fb71215 100644 --- a/tests/NameTest.php +++ b/tests/NameTest.php @@ -3,9 +3,9 @@ namespace IngeniozIT\Router\Tests; use IngeniozIT\Router\Route; -use IngeniozIT\Router\Route\InvalidRouteParameter; -use IngeniozIT\Router\Route\MissingRouteParameters; -use IngeniozIT\Router\Route\RouteNotFound; +use IngeniozIT\Router\Route\Exception\InvalidRouteParameter; +use IngeniozIT\Router\Route\Exception\MissingRouteParameters; +use IngeniozIT\Router\Route\Exception\RouteNotFound; use IngeniozIT\Router\RouteGroup; use IngeniozIT\Router\Tests\Utils\RouterCase;