monii/nikic-fast-route-psr7-middleware
Composer 安装命令:
composer require monii/nikic-fast-route-psr7-middleware
包简介
PSR-7 Routing Middleware using Nikita Popov's fast request router (nikic/fast-route)
关键字:
README 文档
README
PSR-7 routing middleware built on top of nikic/fast-route.
Requirements
- PHP 5.5+
Installation
$> composer require monii/nikic-fast-route-psr7-middleware
Until a stable version has been released or if a development version is preferred, use:
$> composer require monii/nikic-fast-route-psr7-middleware:@dev
Usage
Instantiation
Instantiating NikicFastRoute requires providing an instance of FastRoute\Dispatcher. An optional action attribute
name and parameters attribute name may be specified as well. The default values for the action attribute name and
parameters attribute name are found in NikicFastRoute::DEFAULT_ACTION_ATTRIBUTE_NAME ("monii/nikic-fast-route:action")
and NikicFastRoute::DEFAULT_PARAMETERS_ATTRIBUTE_NAME ("monii/nikic-fast-route:parameters").
Middleware that execute after NikicFastRoute will be able to examine these request attributes to determine which
action and parameters should be used to dispatch the request.
Invocation
When invoked, NikicFastRoute will examine a PSR-7 ServerRequestInterface and pass relevant information from the
request to the FastRoute\Dispatcher instance to dispatch the request.
Dispatcher error conditions Dispatcher::NOT_FOUND and Dispatcher::METHOD_NOT_ALLOWED will result in returning the
provided PSR-7 ResponseInterface returned with status code 404 and 405 respectively.
Dispatcher condition Dispatcher::FOUND will result in the the dispatched action being added to the configured action
attribute and the dispatched parameters being added to the configured parameters attribute on the incoming request.
The response value of $next (called with the modified $request and original $response) will be returned.
If for some reason any other condition comes back from Dispatcher (it is unclear if this is even possible), then
the provided $response will be returned with the status code of 500.
Consuming
Consumers of NikicFastRoute managed requests can examine the request's attributes to determine how to handle the
request. The responsibility for handling the dispatched action can fall on a framework, an application, or another
middleware.
An example of middleware that consumes NikicFastRoute is
monii/action-handler-psr7-middleware. While this
middleware is configured by default to look at a different attribute name for its action, it can be easily configured
to use the same name as this middleware. Conversely, monii/nikic-fast-route-psr7-middleware itself can be configured
to use the same names as monii/action-handler-psr7-middleware.
In the case of a framework, both middleware can be configured to use an entirely different set of names. One framework that does this is Nimble. Nimble intentionally configures both of these middleware to use its own action attribute name.
Example
An example of using this middleware in conjuction with others can be seen in looking at now Nimble operates. Nimble leverages Relay for its middleware dispatcher and Laravel's container for dependency injection and service location.
$container->bind(Relay::class, function (Container $container) { /** @var RelayBuilder $relayBuilder */ $relayBuilder = $container->make(RelayBuilder::class); $queue = array_merge( [ $container->make(NikicFastRoute::class, [ 'actionAttributeName' => WebApp::ACTION_ATTRIBUTE_NAME, 'parametersAttributeName' => WebApp::PARAMETERS_ATTRIBUTE_NAME, ]), ], $container->tagged('middleware.error_handler'), $container->tagged('middleware.early'), $container->tagged('middleware'), $container->tagged('middleware.late'), [ $container->make(ActionHandler::class, [ 'actionAttributeName' => WebApp::ACTION_ATTRIBUTE_NAME, ]), ] ); return $relayBuilder->newInstance($queue); });
As shown in this example, Nimble configures both NikicFastRoute and ActionHandler to use the same attribute name
for the action, WebApp::DEFAULT_ACTION_ATTRIBUTE_NAME. This ensures that both middleware are able to communicate
effectively on the topic of the action that should be dispatched for a request.
License
MIT, see LICENSE.
Community
Want to get involved? Here are a few ways:
- Find us in the #monii IRC channel on irc.freenode.org.
- Mention @moniidev on Twitter.
monii/nikic-fast-route-psr7-middleware 适用场景与选型建议
monii/nikic-fast-route-psr7-middleware 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.09k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2015 年 08 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「routing」 「router」 「middleware」 「psr-7」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 monii/nikic-fast-route-psr7-middleware 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 monii/nikic-fast-route-psr7-middleware 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 monii/nikic-fast-route-psr7-middleware 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
Write down your routing mapping at one place
Flight routing is a simple, fast PHP router that is easy to get integrated with other routers.
Router
Slim Framework 3 CSRF protection middleware utilities
PMVC App Action Router
统计信息
- 总下载量: 1.09k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 25
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-08-31