kambo/httpstream
Composer 安装命令:
composer require kambo/httpstream
包简介
Kambo httpstream additional streams for the PSR-7
README 文档
README
Implementation of additional streams for the PSR-7 - HTTP message interfaces
Stream implementation
This package comes with a following stream implementations:
- string stream
- callback stream
Each of these stream offers additional functionality not provided by original PSR-7 stream implementations.
Install
Prefered way to install library is with composer:
composer require kambo/httpstream
Basic usage
StringStream
String stream is simple synthetic sugar that allows instantiation of stream from the string. Implementation create temporary resource which will be used as base for the StringStream and it is fully compatible with the PSR-7 stream.
$stringStream = new StringStream('foo'); $stringStream->getContents(); // returns 'foo'
CallbackStream
Callback stream provides a readonly stream wrapper around given callback function. Callback will be executed only once by invoking method getContents or by casting object into string. Result of function is not cached and whole stream is after callback invocation in unusable state. This gravely limit usage of methods tell, seek, rewind and read. They cannot be used and invoking any of them will throw exception.
$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.
License
The MIT License (MIT), https://opensource.org/licenses/MIT
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-07-31