debuss-a/fastroute-router
最新稳定版本:2.0.1
Composer 安装命令:
composer require debuss-a/fastroute-router
包简介
A PSR-15 router implementation using FastRoute as the routing engine.
README 文档
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\Method; class HomePageController extends RequestHandlerInterface { #[Method('/', 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
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-09