kambo / httpstream
Kambo httpstream 为 PSR-7 添加额外流
v0.9.0
2016-08-13 07:11 UTC
Requires
- php: >=5.5
- kambo/httpmessage: v0.9.0
Requires (Dev)
- mikey179/vfsstream: ~1
- phpunit/phpunit: 4.6.10
This package is auto-updated.
Last update: 2024-09-19 18:01:49 UTC
README
PSR-7 添加额外流 - HTTP 消息接口的实现
流实现
此包包含以下流实现:
- 字符串流
- 回调流
这些流中的每一个都提供了原始 PSR-7 流实现所不具备的额外功能。
安装
安装库的首选方式是使用 composer
composer require kambo/httpstream
基本用法
StringStream
字符串流是一个简单的合成糖,允许从字符串实例化流。实现创建一个临时资源,该资源将被用作 StringStream 的基础,并且与 PSR-7 流完全兼容。
$stringStream = new StringStream('foo'); $stringStream->getContents(); // returns 'foo'
CallbackStream
回调流提供围绕给定回调函数的只读流包装器。回调函数将在调用 getContents 方法或将对象转换为字符串时执行一次。函数的结果不会缓存,并且在回调调用之后整个流将处于不可用状态。这严重限制了方法 tell、seek、rewind 和 read 的使用。它们不能被使用,调用任何这些方法将抛出异常。
$callback = function () { return 'bar'; }; $callbackStream = new CallbackStream($callback); $callbackStream->getContents(); // Invoke function and returns 'bar'. $callbackStream->getContents(); // stream is in detached state empty string ('') has been returned.
许可证
MIT 许可证 (MIT),https://open-source.org.cn/licenses/MIT