jowy/routing-middleware
最新稳定版本:v1.0.1
Composer 安装命令:
composer require jowy/routing-middleware
包简介
PSR 7 routing middleware
关键字:
README 文档
README
PSR 7 routing middleware based on nikic/fast-route
Installation & Requirements
Install using composer
$ composer require jowy/routing-middleware
This library has following dependencies:
zendframework/zend-diactoros, used for PSR 7 implementationzendframework/zend-stratigility, provide abstraction for PSR 7 middlewarenikic/fast-route, used for routingdoctrine/cache, used for caching routes
Usage
Usage on zendframework/zend-stratigility
use Zend\Stratigility\MiddlewarePipe; use Jowy\Routing\Routing; $app = new MiddlewarePipe(); $route_middleware = new Routing($options); $app->pipe($route_middleware);
Usage on relay/relay
It advised to use container to resolve middleware when using relay/relay
use Pimple\Container; use Relay\Relay; use Jowy\Routing\Routing; $container = new Container(); $container["middleware"] = [ Routing::class => function() { return new Routing($options); } ]; $resolver = function ($class) use ($container) { return $container[$class]; } new Relay(array_keys($container["middleware"], $resolver);
Options
All options is in array, with key => value format.
-
collection (callable or string) contains registered route from
RouteCollector[ "collection" => function (RouteCollector $collector) { $collector->addRoute("GET", "/", function (ServerRequestInterface $req, ResponseInterface $res) { return $res; }); $collector->addRoute("GET", "/home", function (ServerRequestInterface $req, ResponseInterface $res) { return $res; }); } ]optionally you use class instead of closure for handling matched request
[ "collection" => function (RouteCollector $collector) { $collector->addRoute("GET", "/", "Fully\\Qualified\\ClassName:yourMethod"); } ] -
generator (object) implementation of
FastRoute\DataGenerator[ "generator" => new FastRoute\DataGenerator\GroupCountBased(); ] -
parser (object) implementation of
FastRoute\RouteParser[ "parser" => new FastRoute\RouteParser\Std(); ] -
dispatcher (callable) callable that return implementation of
FastRoute\Dispatcher[ "dispatcher" => function ($dispatch_data) { return new FastRoute\Dispatcher\GroupCountBased($dispatch_data); } ] -
cache (boolean) toggle routes caching, default value is false
[ "cache" => true ] -
cacheDriver (object) if
cacheis enabled you have to pass this param to options. It must contain implementation ofDoctrine\Common\Cache\Cache[ "cacheDriver" => new ArrayCache() ]
License
MIT, see LICENSE
统计信息
- 总下载量: 23
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-06-21