marekskopal / router
Attributes extension for league/route router
v1.1.0
2024-11-18 21:19 UTC
Requires
- php: >=8.1
- league/route: ^6.0
- nette/utils: ^4.0
- psr/simple-cache: ^1.0|^2.0|^3.0
Requires (Dev)
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^10.2
- slevomat/coding-standard: ^8.14
- spatie/ray: ^1.39
README
Install
composer require marekskopal/router
Usage
Create Router
instance with RouterBuilder
and set class directories of your controllers or actions. Optionally you can set CacheInterface
instance for caching routes.
use MarekSkopal\Router\Builder\RouterBuilder; $router = (new RouterBuilder()) ->setClassDirectories([__DIR__ . '/../Controllers']) ->setCache(new Cache()) // optional ->build();
Add Route
(or RouteGet
,RoutePost
,RoutePut
,RouteDelete
...) attribute on Class or Method you want to route to.
use MarekSkopal\Router\Attribute\Route; use MarekSkopal\Router\Attribute\RoutePost; class MyController { #[Route('GET', '/api/my/name')] public function getName(): void { } #[RoutePost('/api/my/address')] public function postAddress(): void { } }
use MarekSkopal\Router\Attribute\RouteGet; #[RouteGet('/api/my/action')] class MyAction { public function __invoke(): void { } }