davidecesarano/embryo-middleware
Composer 安装命令:
composer require davidecesarano/embryo-middleware
包简介
A PSR-15 middleware dispatcher.
关键字:
README 文档
README
Simple dispatcher (PSR-15 server request handler) for a queue of PSR-15 middleware entries. Request handlers and middleware components are a fundamental part of any web application. Server side code receives a request message, processes it, and produces a response message. HTTP middleware is a way to move common request and response processing away from the application layer.
Requirements
- PHP >= 7.1
- A PSR-7 http message implementation and PSR-17 http factory implementation (ex. Embryo-Http)
Installation
Using Composer:
$ composer require davidecesarano/embryo-middleware
Usage
The RequestHandler is a container for a queue of PSR-15 middleware. It takes three methods:
- the method
addadd a middleware to the end of the queue. - the method
prependadd a middleware to the beginning of the queue. - the method
dispatchrequires two arguments, aServerRequestobject and aResponseobject (used by terminator to return an empty response).
Set ServerRequest and Response
Create ServerRequest and Response objects.
use Embryo\Http\Server\RequestHandler; use Embryo\Http\Factory\{ServerRequestFactory, ResponseFactory}; use Middlewares\{Uuid, ResponseTime}; use Psr\Http\Message\ServerRequestInterface; // PSR-7 implementation $request = (new ServerRequestFactory)->createServerRequestFromServer(); $response = (new ResponseFactory)->createResponse(200);
Add middleware
Create a queue of PSR-15 middleware with the add method or constructor.
The add (and prepend) method must be a string or a instance of MiddlewareInterface. In constructor you may create a queue with array of string or instance of MiddlewareInterface.
In this example we use two PSR-15 compatible middleware: Uuid Middleware and ResponseTime Middleware.
// PSR-15 MiddlewareInterface implementation $middleware = new RequestHandler([ Uuid::class, ResponseTime::class ]); $response = $middleware->dispatch($request, $response);
Result
The dispatch produces a response messages.
echo 'X-Response-Time: ' . $response->getHeaderLine('X-Response-Time').'<br/>'; echo 'X-Uuid: ' . $response->getHeaderLine('X-Uuid').'<br/>'; echo '<pre>'; print_r($response->getHeaders()); echo '</pre>';
Example
You may quickly test this using the built-in PHP server going to http://localhost:8000.
$ cd example
$ php -S localhost:8000
davidecesarano/embryo-middleware 适用场景与选型建议
davidecesarano/embryo-middleware 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 176 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 03 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「middleware」 「psr-15」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 davidecesarano/embryo-middleware 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 davidecesarano/embryo-middleware 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 davidecesarano/embryo-middleware 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
Slim Framework 3 CSRF protection middleware utilities
Cloudflare Middleware For Guzzle
PSR-15 middleware to handle CSRF-token verification
A simple HTTP application builder using PSR-15 HTTP Server Request Handler and Middleware.
A PSR-7 / PSR-15 compatible router interface and a PSR-15 server request handler implementation for routing.
统计信息
- 总下载量: 176
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 7
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-03-18