# 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 `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);
```
##
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
引领WordPress下载类主题新风尚,CeoMax-Pro_v7.6开心版震撼登场!这款主题不仅拥有令人惊叹的极致美观设计,更蕴含着强大的功能内核,专为满足您所有付费资源下载的业务需求而生。 CeoMax-Pro,超越您的想象,释放无限可能。我们相信,优秀的主题不应是业务的枷锁,而是推动您创意与业务腾飞的翅膀。因此,我们持续投入,不断优化与升级,只为在未来能够成就您每一个关于下载站的梦想与幻想。 无论您是运营资源站、下载站、交易站、素材站、源码站、课程站还是其他任何类型的CMS平台,CeoMax-Pro都能完美适配,成为您追求极致道路上的得力助手。它融合了多风格、多样式、多类型、多行业、多功能于一体,让您的网站在视觉上独树一帜,在功能上全面领先。 更令人欣喜的是,CeoMax-Pro配备了功能全面且操作简便的后台管理系统。无论您是WordPress的资深玩家还是初出茅庐的小白,都能轻松上手,快速掌握各种功能,让网站管理变得得心应手,高效无忧。 立即下载CeoMax-Pro_v7.6开心版,开启您的WordPress下载类主题新篇章,让您的网站在竞争激烈的互联网世界中脱颖而出,成
资源推荐
资源详情
资源评论
收起资源包目录
【WordPress】CeoMax-Pro开心版下载类主题精美设计 (2000个子文件)
tougao.css 454KB
diy.css 437KB
uikit.css 275KB
ceoshop.css 116KB
style.css 102KB
style.min.css 82KB
DPlayer.min.css 44KB
style-rtl.css 9KB
style-rtl.min.css 5KB
styles.css 5KB
login.css 4KB
main.css 2KB
style.css 698B
.editorconfig 302B
.editorconfig 271B
ceo-member-loading.gif 6KB
.gitignore 100B
.gitignore 58B
.gitignore 37B
.gitignore 34B
.gitignore 34B
.gitignore 34B
.gitignore 34B
.gitignore 34B
.gitignore 23B
.gitignore 22B
404.html 4KB
loginAgent.html 4KB
loginAgent.html 4KB
loginAgent.html 4KB
loginAgent.html 4KB
loginAgent.html 4KB
loginAgent.html 4KB
loginAgent.html 4KB
loginAgent.html 3KB
loginAgent.html 3KB
purchase_to_admin.html 2KB
purchase_to_user.html 2KB
vip_to_admin.html 2KB
vip_to_user.html 2KB
order_to_admin.html 2KB
order_to_user.html 2KB
success.html 254B
ceo-mail-bg.jpg 144KB
hls.js 634KB
js21.js 380KB
ckplayer.js 254KB
hls.min.js 215KB
hls.min.js 209KB
plugins.js 184KB
flv.min.js 169KB
ckplayer.min.js 169KB
dplayer.min.js 157KB
uikit.min.js 131KB
index.js 108KB
main.js 98KB
jquery.min.js 95KB
plugins.min.js 85KB
wangEditor.min.js 64KB
main.min.js 46KB
tougao.js 45KB
lucky-canvas.min.js 44KB
jquery.form.js 38KB
ajax.js 34KB
member.js 27KB
product.js 27KB
question.js 16KB
audio.js 14KB
clipboard.min.js 10KB
base.js 6KB
ladda.min.js 5KB
plugin.js 3KB
jquery.cookie.js 3KB
danmu.js 3KB
gutenberg.js 2KB
aixintexiao.js 2KB
feedback.js 2KB
ceoshop.js 438B
style.json 114KB
style.json 114KB
style.mobile.json 111KB
installed.json 82KB
installed.json 28KB
ckplayer.mobile.json 12KB
ckplayer.json 10KB
ckplayer.json 10KB
installed.json 7KB
composer.json 3KB
composer.json 3KB
composer.json 3KB
composer.json 3KB
composer.json 2KB
installed.json 2KB
composer.json 2KB
composer.json 2KB
composer.json 2KB
composer.json 1KB
composer.json 1KB
composer.json 1KB
composer.json 1KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
抖码
- 粉丝: 294
- 资源: 32
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- BaldisBasicsClassic.apk
- 跨语言神经音频编解码模型VALL-E X实现语音合成与翻译
- IMG_20241225_230314.jpg
- AT89C51单片机阳台绿色植物自动喷灌系统设计
- 电视盒子的远程输入法应用,可跨屏远程输入和跨屏远程控制盒子.7z
- Web前端-HTML+CSS-炫酷圣诞树
- 2×300MW火电厂电气一次部分设计
- 110kV商桥-柳村架空送电线路设计
- 多媒体流媒体领域的多编解码器DASH数据集研究与评价
- AT89C51单片机智能小区电子门控制系统的设计
- AT89C51节水灌溉自动控制系统的设计
- 软件设计模式创建型模式五项作业
- 2008-2020年各省技术服务水平相关指标数据
- MINI发票打印助手v1.0
- 锂电池固态电解质的应用和研究进展
- 扫描全能王6.41.0.230531高级版.apk
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功