clayfreeman / string-stream
一个利用PSR-7流接口方便与字符串交互的库。
1.1.0
2021-09-20 19:10 UTC
Requires
- php: ^8.0 || ^7.4
- psr/http-message: ^1.0
Requires (Dev)
- drupal/coder: ^8.3
- phpstan/phpstan: ^0.12.27
- phpunit/phpunit: ^9.2
README
string-stream
此包提供了一个库,用于通过PSR-7流接口与字符串交互。
此包的目标是在PHP中提供类似于C++的iostream
的功能;类似的方法被期望以类似的方式表现。
安装
要使用Composer安装此包,请运行以下命令。
composer require clayfreeman/string-stream
或者,您可以从GitHub上的发布页面下载此包。
用法
以下展示了几个通用用法示例。对于更详细的信息,请参考PSR-7流接口。
use ClayFreeman\StringStream\StringStream; $stream = new StringStream('sample string'); var_export((string) $stream); // 'sample string' // Reset the stream offset to the beginning. var_export($stream->read(2)); // 'sa' var_export($stream->getContents()); // 'mple string' $stream->write('some more contents'); var_export((string) $stream); // 'sample stringsome more contents'
测试
此包的测试是用PHPUnit 9编写的。要运行测试,您需要安装PHP 7.4和Composer。
git clone https://github.com/clayfreeman/string-stream.git cd string-stream && ./vendor/bin/phpunit
许可证
本项目受MIT许可证条款约束。有关更多信息,请参阅LICENSE.txt
文件,或访问以下URL获取许可证副本:https://open-source.org.cn/licenses/MIT