# PSR-7 Message Implementation
This repository contains a full [PSR-7](https://www.php-fig.org/psr/psr-7/)
message implementation, several stream decorators, and some helpful
functionality like query string parsing.
[![Build Status](https://travis-ci.org/guzzle/psr7.svg?branch=master)](https://travis-ci.org/guzzle/psr7)
# Stream implementation
This package comes with a number of stream implementations and stream
decorators.
## AppendStream
`GuzzleHttp\Psr7\AppendStream`
Reads from multiple streams, one after the other.
```php
use GuzzleHttp\Psr7;
$a = Psr7\Utils::streamFor('abc, ');
$b = Psr7\Utils::streamFor('123.');
$composed = new Psr7\AppendStream([$a, $b]);
$composed->addStream(Psr7\Utils::streamFor(' Above all listen to me'));
echo $composed; // abc, 123. Above all listen to me.
```
## BufferStream
`GuzzleHttp\Psr7\BufferStream`
Provides a buffer stream that can be written to fill a buffer, and read
from to remove bytes from the buffer.
This stream returns a "hwm" metadata value that tells upstream consumers
what the configured high water mark of the stream is, or the maximum
preferred size of the buffer.
```php
use GuzzleHttp\Psr7;
// When more than 1024 bytes are in the buffer, it will begin returning
// false to writes. This is an indication that writers should slow down.
$buffer = new Psr7\BufferStream(1024);
```
## CachingStream
The CachingStream is used to allow seeking over previously read bytes on
non-seekable streams. This can be useful when transferring a non-seekable
entity body fails due to needing to rewind the stream (for example, resulting
from a redirect). Data that is read from the remote stream will be buffered in
a PHP temp stream so that previously read bytes are cached first in memory,
then on disk.
```php
use GuzzleHttp\Psr7;
$original = Psr7\Utils::streamFor(fopen('http://www.google.com', 'r'));
$stream = new Psr7\CachingStream($original);
$stream->read(1024);
echo $stream->tell();
// 1024
$stream->seek(0);
echo $stream->tell();
// 0
```
## DroppingStream
`GuzzleHttp\Psr7\DroppingStream`
Stream decorator that begins dropping data once the size of the underlying
stream becomes too full.
```php
use GuzzleHttp\Psr7;
// Create an empty stream
$stream = Psr7\Utils::streamFor();
// Start dropping data when the stream has more than 10 bytes
$dropping = new Psr7\DroppingStream($stream, 10);
$dropping->write('01234567890123456789');
echo $stream; // 0123456789
```
## FnStream
`GuzzleHttp\Psr7\FnStream`
Compose stream implementations based on a hash of functions.
Allows for easy testing and extension of a provided stream without needing
to create a concrete class for a simple extension point.
```php
use GuzzleHttp\Psr7;
$stream = Psr7\Utils::streamFor('hi');
$fnStream = Psr7\FnStream::decorate($stream, [
'rewind' => function () use ($stream) {
echo 'About to rewind - ';
$stream->rewind();
echo 'rewound!';
}
]);
$fnStream->rewind();
// Outputs: About to rewind - rewound!
```
## InflateStream
`GuzzleHttp\Psr7\InflateStream`
Uses PHP's zlib.inflate filter to inflate deflate or gzipped content.
This stream decorator skips the first 10 bytes of the given stream to remove
the gzip header, converts the provided stream to a PHP stream resource,
then appends the zlib.inflate filter. The stream is then converted back
to a Guzzle stream resource to be used as a Guzzle stream.
## LazyOpenStream
`GuzzleHttp\Psr7\LazyOpenStream`
Lazily reads or writes to a file that is opened only after an IO operation
take place on the stream.
```php
use GuzzleHttp\Psr7;
$stream = new Psr7\LazyOpenStream('/path/to/file', 'r');
// The file has not yet been opened...
echo $stream->read(10);
// The file is opened and read from only when needed.
```
## LimitStream
`GuzzleHttp\Psr7\LimitStream`
LimitStream can be used to read a subset or slice of an existing stream object.
This can be useful for breaking a large file into smaller pieces to be sent in
chunks (e.g. Amazon S3's multipart upload API).
```php
use GuzzleHttp\Psr7;
$original = Psr7\Utils::streamFor(fopen('/tmp/test.txt', 'r+'));
echo $original->getSize();
// >>> 1048576
// Limit the size of the body to 1024 bytes and start reading from byte 2048
$stream = new Psr7\LimitStream($original, 1024, 2048);
echo $stream->getSize();
// >>> 1024
echo $stream->tell();
// >>> 0
```
## MultipartStream
`GuzzleHttp\Psr7\MultipartStream`
Stream that when read returns bytes for a streaming multipart or
multipart/form-data stream.
## NoSeekStream
`GuzzleHttp\Psr7\NoSeekStream`
NoSeekStream wraps a stream and does not allow seeking.
```php
use GuzzleHttp\Psr7;
$original = Psr7\Utils::streamFor('foo');
$noSeek = new Psr7\NoSeekStream($original);
echo $noSeek->read(3);
// foo
var_export($noSeek->isSeekable());
// false
$noSeek->seek(0);
var_export($noSeek->read(3));
// NULL
```
## PumpStream
`GuzzleHttp\Psr7\PumpStream`
Provides a read only stream that pumps data from a PHP callable.
When invoking the provided callable, the PumpStream will pass the amount of
data requested to read to the callable. The callable can choose to ignore
this value and return fewer or more bytes than requested. Any extra data
returned by the provided callable is buffered internally until drained using
the read() function of the PumpStream. The provided callable MUST return
false when there is no more data to read.
## Implementing stream decorators
Creating a stream decorator is very easy thanks to the
`GuzzleHttp\Psr7\StreamDecoratorTrait`. This trait provides methods that
implement `Psr\Http\Message\StreamInterface` by proxying to an underlying
stream. Just `use` the `StreamDecoratorTrait` and implement your custom
methods.
For example, let's say we wanted to call a specific function each time the last
byte is read from a stream. This could be implemented by overriding the
`read()` method.
```php
use Psr\Http\Message\StreamInterface;
use GuzzleHttp\Psr7\StreamDecoratorTrait;
class EofCallbackStream implements StreamInterface
{
use StreamDecoratorTrait;
private $callback;
public function __construct(StreamInterface $stream, callable $cb)
{
$this->stream = $stream;
$this->callback = $cb;
}
public function read($length)
{
$result = $this->stream->read($length);
// Invoke the callback when EOF is hit.
if ($this->eof()) {
call_user_func($this->callback);
}
return $result;
}
}
```
This decorator could be added to any existing stream and used like so:
```php
use GuzzleHttp\Psr7;
$original = Psr7\Utils::streamFor('foo');
$eofStream = new EofCallbackStream($original, function () {
echo 'EOF!';
});
$eofStream->read(2);
$eofStream->read(1);
// echoes "EOF!"
$eofStream->seek(0);
$eofStream->read(3);
// echoes "EOF!"
```
## PHP StreamWrapper
You can use the `GuzzleHttp\Psr7\StreamWrapper` class if you need to use a
PSR-7 stream as a PHP stream resource.
Use the `GuzzleHttp\Psr7\StreamWrapper::getResource()` method to create a PHP
stream from a PSR-7 stream.
```php
use GuzzleHttp\Psr7\StreamWrapper;
$stream = GuzzleHttp\Psr7\Utils::streamFor('hello!');
$resource = StreamWrapper::getResource($stream);
echo fread($resource, 6); // outputs hello!
```
# Static API
There are various static methods available under the `GuzzleHttp\Psr7` namespace.
## `GuzzleHttp\Psr7\Message::toString`
`public static function toString(MessageInterface $message): string`
Returns the string representation of an HTTP message.
```php
$request = new GuzzleHttp\Psr7\Request('GET', 'http://example.com');
echo GuzzleHttp\Psr7\Message::toString($request);
```
## `GuzzleHttp\Psr7\Message::bodySummary`
`public static function bodySummary(MessageInterface $message, int $truncateAt = 120): string|null`
Get a short summary of the message body.
Will return `null` if the response is not printable.
## `GuzzleHttp\Psr7\Message::rewindBody`
`public static
没有合适的资源?快使用搜索试试~ 我知道了~
全新的页面设计php + vue云海5.4计费源码开心版
共2007个文件
php:1209个
js:298个
txt:134个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 3 下载量 198 浏览量
2023-10-03
13:56:56
上传
评论
收藏 29.42MB RAR 举报
温馨提示
全新的页面设计php + vue云海5.4计费源码开心版。支持一键安装 2.计费系统全面重构,优化套餐包规则 3.增加套餐包的qps限制 (即每分钟最多调用次数) 4.更完善的计费系统逻辑,解决旧版本99%的bug 5.更完整的接口对接,支持 POST/GET 等多种请求方式 6.增加接口调用权重,支持后台配置cms对接,单次扣费点数 7.内置弹幕系统,全新的客户端(支持token认证防盗,弹幕)
资源推荐
资源详情
资源评论
收起资源包目录
全新的页面设计php + vue云海5.4计费源码开心版 (2007个子文件)
.phpunit.result.cache 2KB
element-plus.98c1996c.css 248KB
vue3-video-play.74881f83.css 27KB
mui-player.74270e1a.css 24KB
index.18b9e24a.css 19KB
@wangeditor.501cf061.css 14KB
mounted.css 7KB
htmlDescriptor.css 3KB
index.6c4c76af.css 2KB
picker.5611c2f9.css 1KB
highlight.5f5db245.css 1KB
console.a9163e0f.css 1KB
console.135aa779.css 1KB
nprogress.f5128a35.css 833B
extension.b806ef8b.css 572B
edit.cfefd7b2.css 451B
index.678b90a3.css 412B
index.d29ca41c.css 409B
myproduct.dc956808.css 363B
index.9bce7fe7.css 330B
edition.558fa0ff.css 325B
ConfigForm.css 301B
prolist.4780d547.css 276B
apimof.4780d547.css 276B
error.ded7a50b.css 240B
environment.ea94bda4.css 172B
success.3bddac78.css 123B
environment.9ca7572e.css 117B
register.9b157866.css 98B
login.1938ba87.css 93B
forget.d82a1e6e.css 93B
index.2cfd300b.css 52B
index.ea4c2e92.css 33B
phpunit.xml.dist 563B
.DS_Store 14KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.example.env 428B
.gitattributes 310B
.gitignore 205B
.gitignore 121B
.gitignore 18B
.gitignore 13B
.gitignore 6B
nginx.htaccess 97B
nginx.htaccess 97B
.htaccess 0B
index.html 4KB
index.html 280B
test.html 123B
index.html 0B
index.html 0B
web_favicon.ico 2KB
2022081217441468be46571.jpeg 268KB
web_logo.jpg 84KB
echarts.2818929a.js 806KB
@wangeditor.729e26c1.js 797KB
element-plus.4b5fa41f.js 416KB
element-plus.de4b9abf.js 416KB
hls.js.40a44b36.js 360KB
vue3-video-play.3108ab66.js 358KB
index.1572c202.js 221KB
index.719f1bf0.js 220KB
zrender.830a2a1a.js 209KB
@element-plus.dc21ce5c.js 191KB
highlight.js.4ebdf9a4.js 144KB
@vue.ac13fb95.js 83KB
lodash.0a3ba09e.js 71KB
moment.9709ab41.js 59KB
crypto-js.c87ef05e.js 56KB
mui-player.fa56b548.js 55KB
vuedraggable.5204151f.js 50KB
sortablejs.a8f12aae.js 44KB
console.4be0fabf.js 37KB
console.e712831e.js 37KB
vue-router.4ea8afcb.js 22KB
lodash-es.29c53eac.js 22KB
axios.209aaa05.js 19KB
@popperjs.36402333.js 19KB
index.0620d4a7.js 18KB
index.463526a7.js 18KB
async-validator.fb49d0f5.js 17KB
dayjs.dc07cbf4.js 14KB
@ctrl.82a509e0.js 14KB
@vueuse.30a07b8f.js 12KB
edit.4d0c2245.js 11KB
edit.fc3ae364.js 11KB
color-convert.755d189f.js 10KB
information.fa3bf00b.js 10KB
index.18adaa53.js 10KB
edit.vue_vue_type_script_setup_true_lang.bf77db48.js 9KB
edit.vue_vue_type_script_setup_true_lang.ae94bc4b.js 9KB
clipboard.c8578d38.js 9KB
information.0c4080a0.js 9KB
apimof.532fe03f.js 9KB
apimof.abf87e4c.js 9KB
共 2007 条
- 1
- 2
- 3
- 4
- 5
- 6
- 21
资源评论
- 河南星科软件2024-02-26资源简直太好了,完美解决了当下遇到的难题,这样的资源很难不支持~
- qq_422361152024-04-22资源值得借鉴的内容很多,那就浅学一下吧,值得下载!
- 2301_774853122024-03-19怎么能有这么好的资源!只能用感激涕零来形容TAT...
如鹿觅水
- 粉丝: 178
- 资源: 376
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功