juhara / zzzstream
PSR-7 StreamInterface 实现集合
v1.0.6
2018-05-05 03:06 UTC
This package is not auto-updated.
Last update: 2024-09-20 08:17:20 UTC
README
PSR-7 StreamInterface 实现集合
需求
安装
通过 composer 运行
$ composer require juhara/zzzstream
可用的 StreamInterface 实现
StringStream基于字符串的 StreamInterface 实现。ReadOnlyStringStream只读字符串的 StreamInterface 实现。WriteOnlyStringStream只写字符串的 StreamInterface 实现。WrapperStream实现了 StreamInterface 的装饰器类,除了包装其他 StreamInterface 实例外不做任何事情。ReadOnlyStream将其他 StreamInterface 转换为只读流的装饰器类。WriteOnlyStream将其他 StreamInterface 转换为只写流的装饰器类。FileStream基于文件的 StreamInterface 实现。TempStream临时流 StreamInterface 实现。
如何使用
从字符串创建流实例
<?php
use Juhara\ZzzStream\StringStream;
...
$stream = new StringStream('hello world');
//replace PSR-7 ResponseInterface instance with new body
$newResponse = $response->withBody($stream);
创建只读字符串流实例
<?php
use Juhara\ZzzStream\ReadOnlyStringStream;
...
$stream = new ReadOnlyStringStream('hello world');
//replace PSR-7 ResponseInterface instance with new body
$newResponse = $response->withBody($stream);
强制字符串流实例变为只读
<?php
use Juhara\ZzzStream\StringStream;
use Juhara\ZzzStream\ReadOnlyStream;
...
$stream = new ReadOnlyStream(new StringStream('hello world'));
//replace PSR-7 ResponseInterface instance with new body
$newResponse = $response->withBody($stream);
单元测试
要运行单元测试,请将 phpunit.xml.dist 复制到 phpunit.xml 并运行
$ ./vendor/bin/phpunit
贡献
如果您有任何改进或问题,请提交 PR。
谢谢。