# 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 =
没有合适的资源?快使用搜索试试~ 我知道了~
打卡运动达人区块链运动商城源码、趣味答题打卡获得能量直接购能量积攒能量.zip
共2846个文件
php:1761个
js:289个
css:142个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 40 浏览量
2023-01-13
09:46:32
上传
评论
收藏 32.31MB ZIP 举报
温馨提示
源码简介与安装说明: 注册:通过邀请链接或者二维码注册,注册后实名认证,采用支付宝授权+身份证号输入认证,一人一号实名制,杜绝刷号。产出:用户认证后获得试用版运动手册,每天完成任务即可获得奖励,具体如下运动能量——获取-玩法 运动能量获取 1.用户通过每天的趣味答题打卡可获得指定能量 2.可在平台直接购买需要的能量运动能量用处 3.可以积攒能量购买手册,使得玩家能量值上涨,增加游戏机制可以增加玩家与平台的粘性 4.随着平台用户量的上涨,能量的价值上涨,,一定程度促进玩家的运动量,认识到健康的重要性,后期能量可在交易大厅进行交易 5.可用能量在商城兑换所需体育器械
资源推荐
资源详情
资源评论
收起资源包目录
打卡运动达人区块链运动商城源码、趣味答题打卡获得能量直接购能量积攒能量.zip (2846个子文件)
使用教程.bat 31B
test.bmp 0B
pimple.c 37KB
CHANGELOG 1KB
chunk-elementUI.81cf475c.css 220KB
chunk-elementUI.81cf475c.css 220KB
chunk-libs.bf8e6a23.css 34KB
chunk-libs.bf8e6a23.css 34KB
chunk-vendors.0d0a8191.css 28KB
chunk-vendors.b8283a23.css 26KB
app.1b565811.css 18KB
app.1b565811.css 18KB
chunk-f4e3388a.79d5973b.css 13KB
chunk-f69a0b2a.1719182e.css 10KB
app.980f5f13.css 9KB
chunk-0d913c82.bcd4d952.css 7KB
chunk-b5fdd248.a2cc0e3a.css 7KB
chunk-c6e2a460.6b0cb417.css 7KB
chunk-008863e2.4d32889e.css 7KB
chunk-e12199a4.47305bc2.css 6KB
chunk-e12199a4.d51363a1.css 6KB
chunk-1f6d1fba.0ef4b42e.css 6KB
chunk-03f71d9d.8143468b.css 6KB
chunk-1f6d1fba.f1c3ec4c.css 6KB
chunk-6650040c.fb650db2.css 6KB
chunk-9d926d82.45f142ea.css 6KB
chunk-dd0776f8.ea5afb07.css 6KB
chunk-9b6e366c.103509b3.css 6KB
chunk-f76709f0.96eb3d58.css 6KB
chunk-248805c4.763eb130.css 5KB
chunk-cc14ec34.5b465100.css 5KB
chunk-7844ea70.3300670a.css 5KB
chunk-0c540a2d.484202fe.css 5KB
chunk-5ba76700.2c4e627d.css 5KB
chunk-1ab26cc8.e83e1bb9.css 5KB
chunk-8bc39334.62f15fa8.css 5KB
chunk-3b6ff55e.9f4c8d2f.css 5KB
chunk-3c4fbafe.5d48dad4.css 5KB
chunk-77c6a1fa.6de17180.css 5KB
chunk-553785a3.ff8813f4.css 5KB
chunk-0153b5fe.7e6e44ee.css 4KB
chunk-2af2f395.153143b6.css 4KB
chunk-8192762e.17eb9049.css 4KB
chunk-07e96ba0.1b9301f7.css 4KB
chunk-cb864660.36907791.css 4KB
chunk-ecf18fa8.b3a44ac7.css 4KB
chunk-98914e8c.6af5efa4.css 4KB
chunk-7ab2bbd8.4bc10f6f.css 4KB
chunk-0153b5fe.21020b5a.css 4KB
chunk-896d0cb2.6d873de4.css 4KB
chunk-f6d9fb44.eebefd83.css 4KB
chunk-5762c0c2.2e7443ec.css 4KB
chunk-c882610c.d5762152.css 4KB
chunk-04934d60.ec043e1d.css 4KB
chunk-48100753.c2298713.css 4KB
chunk-5da76d1a.e332ff98.css 4KB
chunk-7e9dc40d.1dea5c0d.css 4KB
chunk-f3c4ec52.b01ca531.css 4KB
chunk-26345ca2.949f6c02.css 4KB
chunk-40c0daab.e1fa134f.css 4KB
chunk-8ccf65e2.76d72d44.css 3KB
chunk-45ae9a28.ab164644.css 3KB
chunk-07f4df07.f3125204.css 3KB
chunk-26345ca2.919ce5d5.css 3KB
chunk-8fbd1e8e.17ac15e7.css 3KB
chunk-041b5811.17ac15e7.css 3KB
chunk-41d04725.851c3cac.css 3KB
chunk-10b92324.aa377a46.css 3KB
chunk-d7c28d50.e977045b.css 3KB
chunk-49452de8.6394c634.css 3KB
chunk-cc2b8568.182808fa.css 3KB
chunk-d71a740e.a1e04462.css 3KB
chunk-bd3ec6ba.60632258.css 3KB
chunk-9f15e052.fb05f8ea.css 2KB
chunk-7082b173.76a05984.css 2KB
chunk-76ad8f11.dd6a5f09.css 2KB
chunk-76ad8f11.dd6a5f09.css 2KB
chunk-3e6f789e.6f83ecbc.css 2KB
chunk-f59bd8ea.dddc71ee.css 2KB
chunk-87bfb41c.57ae50e7.css 2KB
chunk-6424ae56.60c5d759.css 2KB
chunk-41835389.5e71b77c.css 2KB
chunk-a1dcbbe8.91ae05fa.css 2KB
chunk-52900a74.341ee032.css 2KB
chunk-4d656a51.f5f1239a.css 2KB
chunk-0eeb1f1f.b20b3eee.css 2KB
chunk-58a40729.247886bd.css 2KB
chunk-52fff882.8b389177.css 2KB
chunk-58a40729.247886bd.css 2KB
chunk-52fff882.8b389177.css 2KB
chunk-e6f3e6ae.41048d37.css 2KB
chunk-59121cf8.6f07dc2c.css 2KB
chunk-4f0c0d6c.fafbb98a.css 1KB
chunk-4f0c0d6c.fafbb98a.css 1KB
chunk-0c21a946.3997a22b.css 1KB
chunk-4cc87dba.43ab3d9e.css 1KB
chunk-4cc87dba.43ab3d9e.css 1KB
chunk-2c73fa90.b59fb7cb.css 1KB
chunk-4673683e.fb555927.css 1KB
chunk-b40a9768.fb555927.css 1KB
共 2846 条
- 1
- 2
- 3
- 4
- 5
- 6
- 29
资源评论
智慧浩海
- 粉丝: 1w+
- 资源: 5119
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功