debuss-a / fastroute-router
A PSR-15 router implementation using FastRoute as the routing engine.
Installs: 9
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/debuss-a/fastroute-router
Requires
- php: ^8.2
- nikic/fast-route: ^1.3
- psr/http-factory: ^1
- psr/http-server-middleware: ^1.0
Requires (Dev)
- mockery/mockery: ^1.6
- pestphp/pest: ^4.3
- phpstan/phpstan: ^2.1
This package is auto-updated.
Last update: 2026-02-09 20:50:00 UTC
README
A PSR-15 router implementation using nikic/fast-route as the routing engine.
Installation
Install via Composer:
composer require debuss-a/fastroute-router
Requirements
- PHP 8.2 or higher
- nikic/fast-route ^1.0
Usage
An example controller :
<?php namespace Application\Controller; use Psr\Http\Message\{ResponseInterface, ServerRequestInterface}; use Router\Attribute\Route; class HomePageController extends RequestHandlerInterface { #[Route('/', methods: ['GET'])] public function handle(ServerRequestInterface $request): ResponseInterface { $this->logger->info('Displaying home page'); return $this->response()->view('home'); } }
Use the router and attribute route loader in your application:
$request = ServerRequestFactory::fromGlobals(); $dispatcher = simpleDispatcher(function (RouteCollector $collector): void { // This part will scan the specified directory for // controller classes and load their route attributes $loader = new AttributeRouteLoader( 'Application\\Controller\\', source_path('Application/Controller') ); $loader->load($collector); // You can also add routes manually if needed $collector->addRoute('GET', '/about', Application\Controller\AboutPageController::class); }); $response = $dispatcher->dispatch($request->getMethod(), $request->getUri());
The handler can be :
- instanceof MiddlewareInterface
- instanceof RequestHandlerInterface
- a callable
Testing
This project includes a comprehensive Pest test suite with 87+ passing tests covering all components.
Running Tests
./vendor/bin/pest
License
MIT