# 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\Mess
没有合适的资源?快使用搜索试试~ 我知道了~
WordPress图床聚合 免费图片加速 外链分发插件
共557个文件
php:265个
sample:84个
head:28个
0 下载量 84 浏览量
2023-09-30
21:26:56
上传
评论
收藏 3.64MB ZIP 举报
温馨提示
喵容工具箱是喵容独立开发的WordPress插件,在内部公司网站已经正常运行 很长一段时间。现在就公布给大家分享一下应用。 喵容工具箱的关键功能,喵容 WP 汇聚 图床 :喵喵工具箱可以自动帮助你 WordPress 里的图 将照片分发上传到图床上,自动用图床连接取代文章中的照片,自动加快媒体库图床,自动修复无效链 连接,部分图床甚至适用于鉴黄、webp等服务。应用图床可以帮助小带宽云服务器站长和未备案站长 未使用CDN的海外服务器网站和站长都有了很大的进步。 应用注意不要在关键和隐私图片的网站上打开这个插件。这个插件被上传到公共图片床上,以加快站内照片。它不是插件作者 的图床。公共图床不能保证图片的安全,所以备份照片必须保存在当地。 禁止向图床提交非法照片,上传图片在公共服务器(非作者服务器),不能删除。 第一张正式启动图床后,可能会占用服务器带宽传输图纸,造成非常卡住。照片上传后就可以了。提交条件可以自行提交 开放地址: www.域名.com/mrtb/img_host_list 使用帮助在使用本插件的图床之前,PHP的超时间必须至少提高到900,建议设置为86400,宝塔面板可以
资源推荐
资源详情
资源评论
收起资源包目录
WordPress图床聚合 免费图片加速 外链分发插件 (557个子文件)
config 490B
config 490B
config 486B
config 481B
config 475B
config 460B
config 448B
csf.css 87KB
style.min.css 67KB
csf.min.css 66KB
csf-rtl.css 9KB
style-rtl.min.css 5KB
csf-rtl.min.css 5KB
description 73B
description 73B
description 73B
description 73B
description 73B
description 73B
description 73B
develop 227B
develop 41B
phpunit.xml.dist 668B
phpunit.xml.dist 604B
phpunit.xml.dist 331B
phpstan.neon.dist 96B
Dockerfile 405B
.editorconfig 247B
.editorconfig 156B
.editorconfig 156B
exclude 240B
exclude 240B
exclude 240B
exclude 240B
exclude 240B
exclude 240B
exclude 240B
.gitattributes 453B
.gitattributes 231B
.gitattributes 190B
.gitattributes 158B
.gitignore 145B
.gitignore 96B
.gitignore 58B
.gitignore 49B
HEAD 576B
HEAD 576B
HEAD 573B
HEAD 571B
HEAD 566B
HEAD 413B
HEAD 391B
HEAD 229B
HEAD 229B
HEAD 227B
HEAD 226B
HEAD 224B
HEAD 219B
HEAD 215B
HEAD 41B
HEAD 41B
HEAD 33B
HEAD 32B
HEAD 32B
HEAD 32B
HEAD 32B
HEAD 32B
HEAD 32B
HEAD 23B
HEAD 23B
HEAD 23B
HEAD 23B
HEAD 23B
404.html 36KB
pack-875fff85849a5575c127dc68b4a1d846857a40d5.idx 70KB
pack-5a12cf68bc35f513b6f78d19e66ffbcea95d1432.idx 25KB
pack-82cb8855ab33b0808da2e7c31f9eb2b147be9418.idx 11KB
pack-651cc94dcd1f746920a9da021efe14f8dd99216f.idx 7KB
pack-52c0d422c1300f86a2d4959ca4d1adb31ddc8e2f.idx 6KB
pack-7e27a11f35af774d888c74ac53440bc2d5d8e10e.idx 5KB
pack-e138bebed8a1c5f42f2247a6c64bb6760c25d12d.idx 3KB
index 5KB
index 3KB
index 1KB
index 851B
index 811B
index 441B
index 441B
miaoroom.jpg 37KB
csf.js 97KB
csf-plugins.js 67KB
csf.min.js 45KB
main.min.js 44KB
csf-plugins.min.js 37KB
plugins.min.js 37KB
server.js 8KB
installed.json 15KB
composer.json 1KB
composer.json 1KB
composer.json 1KB
共 557 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
行动之上
- 粉丝: 1973
- 资源: 929
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 论文(最终)_20240430235101.pdf
- 基于python编写的Keras深度学习框架开发,利用卷积神经网络CNN,快速识别图片并进行分类
- 最全空间计量实证方法(空间杜宾模型和检验以及结果解释文档).txt
- 5uonly.apk
- 蓝桥杯Python组的历年真题
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 前端开发技术实验报告:内含4四实验&实验报告
- Highlight Plus v20.0.1
- 林周瑜-论文.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功