mrmadclown/ennodia
最新稳定版本:v3.0
Composer 安装命令:
composer require mrmadclown/ennodia
包简介
Ennodia a PHP Router
README 文档
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 { //... } }
统计信息
- 总下载量: 22
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-12