thruster/http-modifier

Thruster HttpModifier 组件(修改 PSR-7 请求 & 响应)

2.0.0 2016-01-24 22:48 UTC

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)

[电子邮件] (mailto:team@thruster.io)

Thruster HttpModifier 组件。为修改 HTTP 客户端/服务器和其它使用 PSR-7 标准的实用工具提供基础。

Thruster Http 修改器集合

安装

通过 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

贡献

请参阅贡献指南行为准则以获取详细信息。

许可协议

有关更多信息,请参阅许可文件