thruster / http-modifier
Thruster HttpModifier 组件(修改 PSR-7 请求 & 响应)
2.0.0
2016-01-24 22:48 UTC
Requires
- php: >=7.0
- psr/http-message: ~1.0
Requires (Dev)
- phpunit/phpunit: ~5.0
This package is auto-updated.
Last update: 2024-09-14 02:40:18 UTC
README
[] (https://github.com/ThrusterIO/http-modifier/releases) [
] (LICENSE) [
] (https://travis-ci.org/ThrusterIO/http-modifier) [
] (https://scrutinizer-ci.com/g/ThrusterIO/http-modifier) [
] (https://scrutinizer-ci.com/g/ThrusterIO/http-modifier) [
] (https://packagist.org.cn/packages/thruster/http-modifier)
Thruster HttpModifier 组件。为修改 HTTP 客户端/服务器和其它使用 PSR-7 标准的实用工具提供基础。
安装
通过 Composer
$ composer require thruster/http-modifier
对于 PHP < 7.0
对于 PHP7 以前的旧版本,存在 php5 分支
$ composer require thruster/http-modifier ">=1.0,<2.0"
用法
有四种类型的修改器
- ServerRequestModifierInterface
- RequestModifierInterface
- 响应修改器接口
- 消息修改器接口
每个接口都有自己的集合来组织它们,并对每个修改器执行 modify
操作。
独立修改器
$modifier = new class implements ResponseModifierInterface { public function modify(ResponseInterface $response) : ResponseInterface { return $response->withHeader('X-Powered-By', 'Thruster/1.0'); } } $response = $modifier->modify($response);
使用集合
$collection = new ResponseModifierCollection(); $collection->add(new ServerTimeModifier()); $collection->add(new PoweredByModifier('Thruster/1.0')); $response = $collection->modify($response);
嵌套集合
$collectionA = new ResponseModifierCollection(); $collectionA->add(new ServerTimeModifier()); $collectionA->add(new PoweredByModifier('Thruster/1.0')); $collectionB = new ResponseModifierCollection(); $collectionB->add($collectionA); $response = $collectionB->modify($response);
测试
$ composer test
贡献
许可协议
有关更多信息,请参阅许可文件。