mrmadclown / ennodia
Ennodia a PHP Router
v3.0
2023-01-26 21:39 UTC
Requires
- php: ^8.1
- psr/container: ^2.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- guzzlehttp/psr7: 2.4.3
- infection/infection: 0.26.18
- phpunit/phpunit: 9.5.28
- dev-master
- v3.0
- v2.1
- v2.0
- v1.0
- dev-renovate/actions-checkout-5.x
- dev-renovate/phpunit-phpunit-9.x-lockfile
- dev-renovate/infection-infection-0.x
- dev-renovate/guzzlehttp-psr7-2.x-lockfile
- dev-renovate/phpunit-phpunit-12.x
- dev-dependabot/composer/symfony/process-6.4.14
- dev-renovate/actions-cache-4.x
- dev-renovate/actions-checkout-4.x
This package is auto-updated.
Last update: 2025-08-11 14:58:15 UTC
README
This is a pretty straight forward Router, a Route consists of a regular expression, a qualified Controller path and optionally a HTTP Method.
Installation
composer require mrmadclown/ennodia
The Router gets constructed by passing an Implementation of Psr\Container\ContainerInterface::class
and a MrMadClown\Ennodia\RouteCollection::class
.
Usage
use MrMadClown\Ennodia\RouteCollection; use MrMadClown\Ennodia\SingleRoute; use MrMadClown\Ennodia\Router; use MrMadClown\Ennodia\MiddlewareGroup; use MrMadClown\Ennodia\RouteCollection; use Symfony\Component\HttpFoundation\Request; use App\Http\Controllers\IndexController; use App\Container; // implements Psr\Container\ContainerInterface; $routes = RouteCollection::collect([ SingleRoute::get('#^index$#', IndexController::class), ]); $request = Request::createFromGlobals(); $router = new Router(new Container(), $routes, new MiddlewareGroup([])); $response = $router->handle($request);
A Controller either implements __invoke
or get, post, put, patch, delete, etc..
Route Params
Define a route with a variable:
SingleRoute::get('#^user/(?P<userId>\d+)$#', UserController::class), SingleRoute::get('#^(?P<user>[a-z]+)/(?P<repository>[a-z]+)$#i', UserRepositoryController::class),
The variables from the route are passed to the respective function in the controller:
class UserController { public function get(int $userId): Response { //... } } class UserRepositoryController { public function __invoke(string $user, string $repository): Response { //... } }