idiosyncratic/http-router
Composer 安装命令:
composer require idiosyncratic/http-router
包简介
A lightweight PSR-15 based HTTP router implementation
README 文档
README
A lightweight PSR-15 HTTP router implementation.
Installation
Use Composer:
composer require idiosyncratic/http-router
Usage
Idiosyncratic\Http\Router\Router implementing the PSR-15 Psr\Http\Server\RequestHandlerInterface is the main class. It has two dependencies:
- An implementation of
Idiosyncratic\Http\Router\RouteCollection, a collection of routes implementing a single method:/** * @throws Idiosyncratic\Http\Exception\Client\NotFound * @throws Idiosyncratic\Http\Exception\Client\MethodNotAllowed */ public function findRoute(ServerRequestInterface $request) : Idiosyncratic\Http\Router\Route;
Psr\Container\ContainerInterface, responsible for retrieving the handler for the matched route.
Also included is Idiosyncratic\Http\Router\RouteGroup, a basic implementation of the RouteCollection interface based on FastRoute. The interface for defining routes is nearly identical to FastRoute's, with two notable exceptions:
- The argument order for
RouteGroup::addRouteis different. Route methods are defined last as string parameters. - The route handler must be the name of a class implementing
Psr\Http\Server\RequestHandlerInterface.
Basic usage of the library (using the PHP League Container):
$container = new League\Container\Container(); $container->add(ServerRequestInterfaceImplementation::class); $routes = new Idiosyncratic\Http\Router\RouteGroup(); $routes->addRoute('/hello', ServerRequestInterfaceImplementation::class, 'GET', 'POST'); $router = new Idiosyncratic\Http\Router\Router($routes, $container); // Create instance of Psr\Http\Message\ServerRequestInterface... $response = $router->handle($serverRequest);
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: ISC
- 更新时间: 2019-11-26