# 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 =
没有合适的资源?快使用搜索试试~ 我知道了~
微信小程序校园跑腿小程序v1.1.64+前端
共1747个文件
php:555个
png:231个
js:121个
0 下载量 3 浏览量
2022-12-25
14:53:46
上传
评论
收藏 20.95MB ZIP 举报
温馨提示
注意看搭建教程 CentOS Linux 7.6.1810 (Core); 运行环境: 宝塔 Linux v7.0.3(专业版); 网站环境: Nginx 1.15.10 + MySQL 5.6.46 + PHP-7.1 / PHP-5.6 常见插件:ionCube ;fileinfo ; redis ; Swoole ; sg11 搭建安装说明: 1.上传到wq框架应用目录,安装应用,进入应用后台配置小程序参数; 2、用微信开发折工具导入小程序前端,修改siteinfo.js页面数据(uniacid: acid: 是wq后台对应平台的ID数字) 程序仅供大家研究~
资源推荐
资源详情
资源评论
收起资源包目录
微信小程序校园跑腿小程序v1.1.64+前端 (1747个子文件)
00626eb3f1665922f5b6945d33084e700482bb 3KB
007e2c0acf798521460397f94f12488490723f 301B
00f2380f10b824832ee8de9ab58391bc08c609 7KB
0169c9845cbd338a343c0eccfe56121381c2a0 958B
0173740693be3f5da700de3ef7621ef2e350e5 1KB
02bd09875c7f7ae37a851324c32d57d4ceca89 1KB
0396197b392322ff5fa90fc8c08ec51a0328a5 62B
039e5daf65715140d5d94d1031430f100efdda 1010B
04218fe851c01779c854c7b5c44268b138a2f5 1KB
0440ce89f2a408aa699b65100e18f15e0f09ca 8KB
04c53bcfcae560f6fb9120921616a1d34560e2 15KB
0541ec6d3a9ac9e69887e2ae91de7daf52abb6 924B
06cd138879e41e6e72b5a150e00307e48fd974 637B
07dcca185f090b3361ab4f8f1eb7c658c5a013 833B
07ff9115f3d6b291c06ff290d239753183637d 934B
0a1d4658ee8ff22e40ec9731af4ff25bff5b7d 4KB
0a8ecef4a7f51ec31ffc71e7850da64ce539fd 6KB
0b4d9a42de1999b11c6b5f4adb56107b15b244 877B
0cf7083e78d9e421004e426e959e25fbe5135b 2KB
0d292a6cdf59df1ef936283d4bd63b89062d29 144B
0d39da5161cc8e890b0675e61b1ef6b6942685 638B
0d61bfe31f31505cd62eb32ccd26f188265244 5KB
0da93011640c44d8992bc9f34252d6f33b74b4 4KB
0dc7e4523293dd4ee378b57687c198b99b7beb 94B
0e57d3d183af9590f455cd59258f5d0218b003 5KB
0fb06fc81b4814730382638e957d149475f173 5KB
0fefcf91f6cfb5d3c2d3b7f1584bf4cb8cf70f 7KB
100b9776b72e4617ebc92c93974f73762b0053 49B
10f5d9a07d02884875fb452f4529aff4681112 3KB
117b1ee7a37eadde3d8295c4e7b0195c62be3e 3KB
118bf02d2051ac18e0d918875077ecebabb207 87B
11eb9b2ed361f9063e180f16fde0e3311e7c7b 2KB
132b02d4d9ca90d509b31d1434d3b47b1e1ab6 528B
13596d1fe55b22460bd5404b600822f7087fbf 709B
1366909195167c6a1b45757c3c95e224b3971b 2KB
137862275a0ea32676da474a490f6421d7aeb5 8KB
140aae03a701a5b6e872838f952ee29c2702bb 2KB
14d0007852c1a041de4cd4f722d4b0ec99d20d 4KB
1620473cf0c8ffc7d6772471a64524879de721 3KB
169452585c947d760a85ca9fa6fc8c5ca06ba8 59B
16f8c3b8ac291915f205c61a56687059064609 981B
17bdce182d90314b1241e5a3e6856cca85ec56 1KB
17ffe2e365c2fd9402902a0ea7ec1280a4a355 2KB
19de4a3ffcb8f776f8a567346f3a652ecbcc1c 7KB
19f0e2e7c3457a27cb21245a9a666f7b2dc59d 9KB
1a8045103f0f2411d03f116bf1eda75034e5c1 2KB
1b6c729c436f9e28d1b8ac46263bcf540cf43a 20KB
1c72bfbf86905694f3cc933845aa0e78fcd3bf 2KB
1d54019e930c77b8bc58430234e02b52959b04 8KB
1ddcad435fc88328fe7789687550ec257d4614 574B
1e6000f1c75913201f1b00110f0850a69cdc70 638B
1e8e15aa9de0fbfd30d2f6e56bd2ea74282e0a 2KB
1ef89df17dee2662a25196597c2852fb884670 2KB
1f3858418a6d52a8f337fdd4681d08db4b1121 309B
21d7c22c923212288415c2d658b3a13ae8000f 24KB
241980de6feebfdc5a9166308f26edb3017c9c 65B
257fb7334daa6e25a9801c4c62e551c5ac494f 1KB
25ef2acfe897556a2e3723607cf4d047d3e2fe 5KB
26623e27c05ebf0ed24087a2b2d41af6593d43 1KB
26f48467b89ec2087b9d4afb8e62df88471dd9 2KB
272d85e19724dc49fcc65d1d62866ab6d7d13e 2KB
27d9acb27b9f2e80c96ce10af054d4ceda9ee5 55B
290d02f5812ff7f76f527293aab3b050497550 5KB
297c47abe6fcdf650baf0a7e92b8530c36e928 93B
2b71a52e210543299a40b37b75b73248d99bd1 1KB
2b89c71e999ed3e05b00be4af17a2b8ebfe0df 2KB
2cae7e5ddd50d0dd9649c446cf0cc9e165fcec 5KB
2cb2100dd98ce363f361949b0ca4de4f503b42 5KB
2cda1d9804f4b0043a7a441ae9de40c1ff192b 87B
2e47e634963002a6cb8993b86e2fbc79022424 549B
2e4c03020dc49a344e3048a769797024b08939 4KB
3027588d8e2ee6a94a93578dc4d53e96c1a57f 153B
335257e859eac72d931795dd4663f3cb467c39 3KB
346cad5049d24c6d58a0ae759eae7d1efdecca 3KB
3498e5e5008753f1ae8d76e1dda695865568c3 4KB
3507f4afc40b6a9d393394be7fd2f85004ddaa 142B
350dd1755459d0a7e1d4d37c4d469ecdcaa5f5 8KB
359f81006ecff1aa37518fc8d8cf186f0948ad 987B
36dd6121e92e866bed875036669e15478f278e 9KB
38e85ef77721ee65b000817dc5e9c90e6ad196 5KB
3993c0690b9c229d14b6d8b5b3df301ab5b0e4 3KB
3a6f09d71132d9049924b613d98b48b15c6a17 73B
3be54e5162bbcbc9a847d728fe44a7e67e0ec7 73B
3c2c8a6dbcdd9c5addf9b32f35bbde7ce455fa 659B
3c3b491ad887c782fe5f2795ea199c7b96a871 2KB
3f6e92ad68dc7f05fbb4d0dff52939ef19110e 1KB
414a3ec534466f0a139a7fafcfbbf8aa58efdb 3KB
43e1303026580c5080c7cfd7c9143fd178d555 247B
43e4d0b9200a4734f8cad46ec249f7bcd99c00 4KB
45353d81255a0a1edadcb03d3b50d0a5c732a4 1KB
460c6641f1ee2afd0ba5fa354aa866e9bcfa19 734B
46bd9a59ecda647f1a6d69a104aef656fe0346 2KB
470a32ef586ee32bdd5d9145477a1154d4ec3d 1KB
4769f9547175d92da48d51425e400b58fc1908 1KB
49b70bc029c54383ce8db5611c397af9f919b1 222B
4a04a7c1290b2634b94835ab8e8ba09e108065 2KB
4a2b80e1f18864f1a70a00b4c7274c766253ad 789B
4a7e3a3edca1eb73d61bd9ed2a6dcf7fdcf0fe 1KB
4ba02bbe7076bb58993cec12b4874c9e6859f0 20KB
4c33de5a403a666cf08c5ebfb1309abdc48fe4 1KB
共 1747 条
- 1
- 2
- 3
- 4
- 5
- 6
- 18
资源评论
什么是快乐代码
- 粉丝: 39
- 资源: 66
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功