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 实现

如何使用

从字符串创建流实例

<?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。

谢谢。