# 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
没有合适的资源?快使用搜索试试~ 我知道了~
PHPRmTop-CMS企业官网管理系统.rar
共1723个文件
php:1129个
html:85个
css:61个
0 下载量 110 浏览量
2023-03-13
13:46:03
上传
评论
收藏 51.3MB RAR 举报
温馨提示
PHPRmTop-CMS企业官网管理系统.rar
资源推荐
资源详情
资源评论
收起资源包目录
PHPRmTop-CMS企业官网管理系统.rar (1723个子文件)
00bd81f72dc46f7ece1b9d2d02d24e3f1de08c 251B
05327841859a1eb970602a0275deaf78b8eeb9 7KB
06e0f32f0d0f9a45e56c84a33f7bdeebc059ad 524B
09fb28aa81a1f7bd4a67da50a5ebb23c5e2b94 2KB
0c8fa472552dbfb7ec9f44e9276f13142b1743 1KB
0dc96c65458a3cde37a97df179c2c9fa59fbad 973B
0f27b3775b203bd8911d5cafc8184a99dc905a 119B
10582cdc08c44b4f3bfd942d3a74b47af159d8 13KB
194011b4013016bc722e89df2a4d08dac2e216 98B
1a63687cea46425047d05cc48682fc00a76455 140B
1af4dc2fe44db59d5eaec96d8a908450dfc1bf 977B
1bf6ec4a07def6027bb2d8da0f9e3734eeb607 211B
203b017f4a45c7ce1da2b063c2ca35efd2a0bd 1KB
24f466525b45dd815fa2fb7eff424fd67b0bea 119B
26aa85888f101fe2b5d4a7d28d561647c4f0c3 146B
27bcb2f1cc5ea46a1394fe2856cb7e71f00ae7 979B
2a392d02171f37651f124f1b0c6c3fa9343716 564B
2ba2d38b1d99708f143c1a6d7823b39cbca2b7 1KB
2d3f6ae17fb75b1e1a07d5c77004edf2fdb91d 4KB
3178ba7241a87c5f147afedb4e73067c2da7fc 414B
3ac58a0d50535f836b97c44a68cb58ea8120f6 251B
3c3dd4a5c6f1b4c61d3a3e542890e955e55d2a 762B
3d627dfa916828d87d5a999d7ee0777c9171d7 363B
40c8a88e8d3969dc125d2db0060090a0bdefe3 641B
41da402af4128ad83db3cf01ee6781f7fc7740 170KB
42b92bcb603a059ee79019b0864fd48ed80cd0 975B
42bf8ebb2d63a7af6494f5bfc7ed8c5e1bb43f 2KB
435a529e2624d309f01e2dbc461506db8fb320 4KB
46e684c47a898803ec8cdd9d95728f8574017f 6KB
4854fce5b95a3195c219a925d89cceb0f7a767 2KB
4c425899bb5d81d8a57d27a18ae917e7242764 3KB
4d84923c61b27a03a6643e40a82ac5d5eb514a 56B
4f2051b909a21a37a2414b21cd7e031d0c1c85 139B
52e55e1b38f60dce13ce8b50dc1d38723a3640 2KB
596c3cf6f051a2c80b4548c1c398a82f67aedf 170B
5a68a5e4bae53983d108b199ca370d3ac40466 57B
5be5659b1d7fb0759a90fa1b40aaccc7e0a10a 446KB
63e73eaf7065c04fcb83b0d2f7cb09b68a7eb2 132B
650542a7d544964fc05fae7008128f4762e121 139B
6f373f17093710b279a7b6727cffc14391929e 363B
701b925adfd8c3c6f083733024bf1eada878ce 2KB
717f6700083ab6274ab4d6fd6dc219f36f4939 258B
74f1fbc30a20b60117cc12952fd3e51f8823a9 294B
757fe7172660ff1683dcfd24276d5711a8417c 159B
76cee57b7835f1a68865de619be79badacf27d 2KB
77809485607d246a2a27f1716a437162f38d16 1KB
7c435ccf61ac042f317bd79871c904b3d89954 995B
7d238d74b88925809abc4014366bb55ce27538 2KB
7fd1161931c6732d99baaa885a5dbc53f5633b 805B
809719a811e47613f6dc835952575d1f39110a 1KB
8378dee1f0a7433e457ac370776b4e058a177f 303B
842dec31d513bf7d81a9b47791ad0720cad6fc 806B
86f9d6299ed7a5166bc73575e85356a049bf78 3KB
879f96f1a2a485cb97eaa44114b4caa97dcaff 2KB
880810a42691a593c2c1047b3a36c570453453 2KB
8a567b6860d7b44d5eeb58133bf4cacae9258c 1KB
8fa79a344e51f25f822ed1ad1646c516ffbf3b 54B
8fc370ae4e2577c354225a03f68741bd937c5b 13KB
97c8aa668f471ffc621b49812e053e3b6a1d6c 2KB
980ab4c85ce826317a32aca4e951f3ae4d7fee 2KB
9909203efea18caf5e7e03d91f77ecabeee9a4 2KB
998760a49dedf253616b2c20e6a71d7a79f01e 446KB
9b4aed63160d76d3bf099f851e6092962d5341 301B
9ce88fd99ae74c4bb22cf883cebcde894a1277 149B
9d870b3675213cf26d11fb77d7187db99ab4d8 139B
a2df0da6bf262c95fd199f1c7bf9649eab2006 2KB
a64393382836a2679413173fb5ffcbce182a5f 303B
a6939fab3f32a71b5a71e4b3c307990b6083bd 427B
a6d28ce38211116c44ec3242c9737ab0d57051 2KB
a7a2384481d68b607d1f1bc39526f600ef5c4e 265B
ae6be163afa21599cb8a3af657af6e7b01a9fb 3KB
af6c83050f678ecb31bdf23594d076eb9c7bdf 996B
b0efc4b713b726c11889c7885add611f0e7589 145B
b480de8542d70b6dc8de816a378174e1217f44 425B
b5651ab7743a93946afce28ee8e0b246f30acf 6KB
b5a7755a1d7690234177a484a972c8cf1ccff4 145B
b840b0e3b1c39fd73ec6490d09785f9fa282dd 426B
var-dump-server.bat 142B
bb4daec0a03cb9863b5bd9eceb91c2d9f33a29 524B
bd1231bb57e4fcbae72c7f699fe3f0b4795e25 2KB
bdaa7fa9a92eb3172744e573c53bcddb2196ec 647B
be4632027dbe8a8f7aa39cfbd52b782507a481 426B
befa32b303957f0e1de0b2fc07c8b6b0ac2c26 170B
bfa30ba4829055bfe2383a4478347340b5add1 4KB
c3c7cb81b72725c7d7b5520a02068b4479e4dd 131B
c40598a4cec4ff323ce3651e84f1e902223861 301B
c6b421139a2c58b0860fee4aeda44c17eab8b9 642B
c831a74da8e7e6a0ccda9039fa031eda4b6bf6 414B
c8f266e871a527163b22a399eeca21230816d3 2KB
c949a7088b2ca85808444c33e89cbc89af3844 2KB
COMMIT_EDITMSG 2B
config 339B
index.e48bdaac.css 316KB
style.css 98KB
skin.css 76KB
skin.css 75KB
skin.css 73KB
skin.css 73KB
animate.css 71KB
skin.min.css 64KB
共 1723 条
- 1
- 2
- 3
- 4
- 5
- 6
- 18
资源评论
qq_38220914
- 粉丝: 606
- 资源: 4311
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 腾讯全端Bootstrap响应式布局
- SCons:一款Python语言的软件构建工具
- JavaScript语言教程&案例
- 基于Cortex-M0的BLDC电机驱动与PID控制实现(原理图,数据手册,源码和相关固件)
- 使用Android辅助功能AccessibilityService 进行自动化测试demo 源码
- Activity活动详简总结
- tensorflow-2.16.1-cp312-cp312-macosx-12-0-arm64.whl
- PHP语言教程&简单案例
- PID-小车类-手机遥控十分mimi蓝牙小车V2全部资料(购买物料清单,Android源码,STM32,PCB等)
- C#语言教程&简单案例
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功