# 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.
![CI](https://github.com/guzzle/psr7/workflows/CI/badge.svg)
![Static analysis](https://github.com/guzzle/psr7/workflows/Static%20analysis/badge.svg)
## Features
This package comes with a number of stream implementations and stream
decorators.
## Installation
```shell
composer require guzzlehttp/psr7
```
## Version Guidance
| Version | Status | PHP Version |
|---------|---------------------|--------------|
| 1.x | Security fixes only | >=5.4,<8.1 |
| 2.x | Latest | >=7.2.5,<8.4 |
## 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 zlib (HTTP deflate, RFC1950) or gzipped (RFC1952) content.
This stream decorator 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;
private $stream;
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 `GuzzleH
没有合适的资源?快使用搜索试试~ 我知道了~
小狐狸AI系统源码最新版2.6.2版
共2000个文件
js:373个
png:298个
php:242个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 28 浏览量
2023-12-19
12:37:43
上传
评论
收藏 40.56MB ZIP 举报
温馨提示
小狐狸AI系统源码最新版2.6.2版基于百度文心一言、通义千问等ChatGPT源码小狐狸AI系统是一款基于GPT-4.0的人工智能聊天系统,它以小狐狸为形象,为用户提供了智能而互动的聊天体验。此外,该系统还集成了全开源的GPT4.0M,增加功能等
资源推荐
资源详情
资源评论
收起资源包目录
小狐狸AI系统源码最新版2.6.2版 (2000个子文件)
config 459B
chunk-elementUI.f92cd1c5.css 235KB
chunk-elementUI.f92cd1c5.css 235KB
chunk-elementUI.f92cd1c5.css 235KB
app.80d013a5.css 125KB
index.97465e7b.css 94KB
ueditor.css 45KB
ueditor.min.css 34KB
chunk-libs.e6ce6701.css 32KB
video-js.css 22KB
image.css 19KB
video.css 15KB
attachment.css 15KB
app.2072a995.css 13KB
app.df2c741d.css 13KB
light.css 13KB
video-js.min.css 11KB
shCoreDefault.css 7KB
main.css 7KB
light.css 6KB
dark.css 6KB
light.css 5KB
light.css 5KB
chunk-410c77e3.16f94a39.css 5KB
chunk-cd887a08.b78afde8.css 5KB
chunk-6c7f4df2.d688e6db.css 5KB
scrawl.css 4KB
chunk-libs.3dfb7769.css 3KB
chunk-libs.3dfb7769.css 3KB
htmlDescriptor.css 3KB
codemirror.css 3KB
charts.css 3KB
chunk-3fc30c6a.206627f8.css 2KB
chunk-8cc27e1e.ac6f6ba4.css 2KB
chunk-01ea2f58.286fc439.css 2KB
chunk-3aa22e50.10729fdb.css 2KB
background.css 2KB
main.css 2KB
chunk-e9780286.4ec27e23.css 2KB
main.css 2KB
chunk-12a94422.a87d33fc.css 2KB
emotion.css 2KB
dialogbase.css 2KB
chunk-6e570620.7d8561eb.css 2KB
chunk-7b2a1c88.8b9cf6fd.css 2KB
music.css 2KB
chunk-5aa30cff.bfe3316e.css 2KB
chunk-d919c0d4.6d3a654d.css 1KB
edittable.css 1KB
chunk-41aa6dc1.5f81c429.css 1KB
chunk-5c2b934f.8efb8194.css 1KB
chunk-61444b10.d57f30dc.css 1KB
template.css 1KB
chunk-37ee4fdb.5c484d7e.css 1KB
chunk-79bb5458.d7208bdd.css 1KB
chunk-5ddf9082.41c3087c.css 1KB
chunk-0382c796.847ec3f0.css 1KB
chunk-381d938c.670a2752.css 1KB
chunk-e4a88f34.3a94108c.css 1KB
chunk-369e5555.0cd94104.css 1KB
chunk-beca1f50.68737032.css 1KB
chunk-05e6d48e.db30946b.css 1KB
chunk-81f73ab8.6c98c2a2.css 1KB
chunk-429fd430.dbf2a1d9.css 1KB
chunk-cacb450c.1f1358db.css 1KB
chunk-40a0c2f5.7394d82e.css 1KB
chunk-32a2941a.f5a4242c.css 1KB
chunk-74f41ed7.21d7c73e.css 1KB
chunk-0a26bf54.b13df673.css 1KB
chunk-55d9b948.6b167cdf.css 1KB
chunk-05c131be.47d38326.css 1KB
chunk-8bd8f12a.436192f1.css 1KB
chunk-49d30bde.4ca8f3b3.css 911B
chunk-45e051b2.805b04d8.css 911B
chunk-332fae69.eddba89f.css 808B
chunk-426edff0.77b817b3.css 808B
chunk-a735b826.dfc2b954.css 808B
chunk-740ba390.6e8252e8.css 808B
chunk-f4ca0144.e47dabac.css 808B
chunk-d716cca2.e8fbbd2d.css 791B
chunk-7388a573.4c422a94.css 791B
chunk-0e350832.ca5b1080.css 791B
chunk-67e2d223.7ce3a0e3.css 791B
chunk-e134f16c.5ef16341.css 791B
chunk-2d3fe79e.97276458.css 791B
chunk-781dd7fa.af006f08.css 738B
chunk-440e9944.3370a900.css 738B
chunk-d8ac5ca2.c925cf59.css 669B
chunk-b8350746.14ba30bb.css 661B
chunk-7ca39e4a.8e9568b2.css 580B
chunk-12624c5b.2108c0d2.css 580B
chunk-43809e13.86ffdfbe.css 580B
chunk-4d1260f8.3875a38f.css 580B
chunk-11f9b190.6a9f83c3.css 580B
chunk-ce5d151c.4553e9a0.css 580B
chunk-160237c3.7ec96776.css 580B
chunk-1cd67802.238a4ef1.css 580B
chunk-222c140d.1051b034.css 580B
chunk-a56d7b3e.253da94e.css 550B
chunk-8f720d0a.9a41abfe.css 544B
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
瑆箫
- 粉丝: 835
- 资源: 124
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功