# PSR-7 Message Implementation
This repository contains a full [PSR-7](http://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\stream_for('abc, ');
$b = Psr7\stream_for('123.');
$composed = new Psr7\AppendStream([$a, $b]);
$composed->addStream(Psr7\stream_for(' 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\stream_for(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\stream_for();
// 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\stream_for('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\stream_for(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\stream_for('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\stream_for('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\stream_for('hello!');
$resource = StreamWrapper::getResource($stream);
echo fread($resource, 6); // outputs hello!
```
# Function API
There are various functions available under the `GuzzleHttp\Psr7` namespace.
## `function str`
`function str(MessageInterface $message)`
Returns the string representation of an HTTP message.
```php
$request = new GuzzleHttp\Psr7\Request('GET', 'http://example.com');
echo GuzzleHttp\Psr7\str($request);
```
## `function uri_for`
`function uri_for($uri)`
This function accepts a string or `Psr\Http\Message\UriInterface` and returns a
UriInterface for the given value. If the value is already a `UriInterface`, it
is returned as-is.
```php
$uri = GuzzleHttp\Psr7\uri_for('http://example.com');
assert($uri === GuzzleHttp\Psr7\uri_for($uri));
```
## `function stream_for`
`function stream_for($resource = '', array $options =
没有合适的资源?快使用搜索试试~ 我知道了~
云之道智慧预约微信小程序系统源码下载,适用于百余种预约场景
共2000个文件
js:1283个
php:454个
css:447个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 38 下载量 186 浏览量
2021-10-22
18:00:39
上传
评论 4
收藏 186.13MB ZIP 举报
温馨提示
云之道智慧预约适用于百余种预约场景 例如:美容美发预约、医院预约、试乘试驾预约、家政预约、 婚庆预约、活动预约、会议室预约、驾校预约、景区预约等更多场景 帮助用户打通微信渠道,轻松获取流量红利 拥有自己私域流量池运营管理,搞定拓、留、锁、升,使路人变新客,新客变老客,老客带更多新客。
资源推荐
资源详情
资源评论
收起资源包目录
云之道智慧预约微信小程序系统源码下载,适用于百余种预约场景 (2000个子文件)
0272d2455ef583dbce3929f4ce984eb088ee71 2KB
04294c639a0787de48878fac2bae2f4b436ba3 3KB
07d505514f811cd78f7d401b9fa9edefcd557d 472B
0b80d0708621c94fa4b1c7e6a81e573c4ac671 472B
0d470cc4c3e3e2f9afa3ce98145c51189713af 48B
0e9861d6726d7ea1c719fd8e08b555ba033c14 48B
0eb2ec5cd73f0bfa70003c77a30671e8744754 727B
12eb614680226c0c47538dcd7aa5677a232dbb 193B
13fdb945b59cef127687200a95df2cb9ee0203 587B
15c04276f694fb4d6460f29064107a2435fe75 48B
1a44ef1b8eb0060245b8a84dc829d1c2be297f 154B
1ad592bd74d66bbddadbf6a89a1c184a9a89cc 547B
1b20aa356de941237c319921b1f86c3154d7c4 473B
1bd1ee4414c6b5f4618a37eb520f9167524a38 807B
216d10fb3161e26c8b05bcdc5e5d6eaa157ba3 567B
2253d3c81d7a18826e1e683a6104003d6d43f6 318B
250b2800e1cabc1092dea334e3aa4a27d72379 48B
25fd0fcb58500632a0787fe90f77cbeca1ac16 317B
285ed1740cc942f07d2f47a17bc48d9d52feba 49B
292edc5d894ced9633467fa85d181d078940da 48B
298050256a8dc38f807baf511c5ec7e96b33b9 48B
2b912f31abfb39cccca9225616627a57db59d0 45B
2cdcf2e8f843c27badd2c3baba78ab7d5a5f0b 45B
v2.0.3 41B
346fbe215df316459723835c17d357b80f0d8e 48B
35da2c4a3fc949f2d6935a426cf1dc67797e39 3KB
35e04cd3c898f84ed73c74309140585f502fee 46B
370411d6dcb71e8d6c63f0fdc4ff565522e54f 318B
3a1c16a2f93da7159a97e264abb7d8691b33fd 549B
3d61a6f9eb5fdedecf8c1f256c9aa792bc792e 824B
3e28c6d74b3b869c783c99ac744b85b0bd2c46 558B
v2.0.4 41B
400003146fec196295f3d0fcf84f8850d531b1 318B
425e7bb230c4037866bbdd12d8919000017cd5 471B
427eac1e42b0722fe1c62756a91e7d343dab3c 318B
44dc6ee4adc2f0c60325433934375f7ee1a317 471B
459a9bd1d5f5d9645768723eabb9c23eb1eb67 318B
48a7437f1aa0fdbcf4e251b380a8e799bf72e1 317B
4ac12589b19878b9a55f8372c5d82993e6784b 318B
4b83fbbc5fa4864451b41f6c0fe28e1b7897a2 7KB
4b89aecdacf01dd9adeb9dc080eb8535f3f155 547B
index.css 227KB
app.83ef03fd.css 208KB
app.b20136c0.css 208KB
app.ec8b167d.css 208KB
app.7807a26f.css 208KB
app.f4e16334.css 207KB
ueditor.css 44KB
ueditor.min.css 34KB
chunk-890d15ac.2bc40564.css 30KB
chunk-be81c69e.4f7730fb.css 30KB
chunk-10a559d6.809016ff.css 30KB
chunk-011433d8.ca62b5dc.css 30KB
chunk-01064d28.b3d292fa.css 30KB
chunk-fffb07d8.a2b75b3c.css 30KB
chunk-0e66034e.48c7a896.css 29KB
chunk-7e56eb43.5a4f5408.css 29KB
chunk-5bbfd0f3.48c7a896.css 29KB
chunk-3bc06252.46e97a23.css 29KB
chunk-16ec92cb.d07595f8.css 29KB
chunk-3bc06252.6849f1bb.css 28KB
chunk-8e7a0d54.6849f1bb.css 28KB
chunk-140aef67.c71a2441.css 24KB
chunk-4abc36a3.c42851e2.css 24KB
chunk-462f6618.66b67479.css 23KB
chunk-cb72af7e.66b67479.css 23KB
video-js.css 21KB
image.css 19KB
video.css 15KB
attachment.css 15KB
video-js.min.css 11KB
shCoreDefault.css 7KB
chunk-705dbcb8.5d22fb7f.css 6KB
chunk-705dbcb8.fa42d46c.css 6KB
chunk-d9b58518.fa42d46c.css 6KB
chunk-a6a326b6.0b749625.css 6KB
chunk-e3c5bd56.0b749625.css 6KB
chunk-e3c5bd56.eb4f992a.css 6KB
chunk-70f1e02f.e4150932.css 6KB
chunk-769c2135.80a70d64.css 6KB
chunk-5b2a8ce1.25d17209.css 6KB
chunk-5ca0ea18.dd2c3f61.css 6KB
chunk-b404910e.5037cfd1.css 5KB
chunk-059707c5.5037cfd1.css 5KB
chunk-559a3496.5d47382c.css 5KB
chunk-cc1a113e.3dd4bd7f.css 5KB
chunk-68950643.d40e55c9.css 5KB
chunk-24827059.de02c22e.css 5KB
chunk-12c587fd.b8bd3322.css 5KB
chunk-24827059.e0d7b6d5.css 5KB
scrawl.css 4KB
chunk-31ee0a10.2020e8ce.css 3KB
chunk-6bbd94f7.68852635.css 3KB
chunk-095377a0.68852635.css 3KB
chunk-8ec14c96.fe440df2.css 3KB
chunk-55e45cbc.c19ee4ca.css 3KB
codemirror.css 3KB
chunk-15d438e2.28ea6af2.css 3KB
chunk-22d23522.c392a03b.css 3KB
chunk-5ea19674.6871a35e.css 3KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
我爱软件资源库
- 粉丝: 456
- 资源: 261
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页