分享好友 最新动态首页 最新动态分类 切换频道
【影视小程序模板】2020.07新版苹果CMS影视小程序超完整网站源码.zip
2024-12-25 12:11
# 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 `GuzzleHttpPsr7AppendStream` Reads from multiple streams, one after the other. ```php use GuzzleHttpPsr7; $a = Psr7stream_for('abc, '); $b = Psr7stream_for('123.'); $composed = new Psr7AppendStream([$a, $b]); $composed->addStream(Psr7stream_for(' Above all listen to me')); echo $composed; // abc, 123. Above all listen to me. ``` ## BufferStream `GuzzleHttpPsr7BufferStream` 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 GuzzleHttpPsr7; // 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 Psr7BufferStream(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 GuzzleHttpPsr7; $original = Psr7stream_for(fopen('http://www.google.com', 'r')); $stream = new Psr7CachingStream($original); $stream->read(1024); echo $stream->tell(); // 1024 $stream->seek(0); echo $stream->tell(); // 0 ``` ## DroppingStream `GuzzleHttpPsr7DroppingStream` Stream decorator that begins dropping data once the size of the underlying stream becomes too full. ```php use GuzzleHttpPsr7; // Create an empty stream $stream = Psr7stream_for(); // Start dropping data when the stream has more than 10 bytes $dropping = new Psr7DroppingStream($stream, 10); $dropping->write('01234567890123456789'); echo $stream; // 0123456789 ``` ## FnStream `GuzzleHttpPsr7FnStream` 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 GuzzleHttpPsr7; $stream = Psr7stream_for('hi'); $fnStream = Psr7FnStream::decorate($stream, [ 'rewind' => function () use ($stream) { echo 'About to rewind - '; $stream->rewind(); echo 'rewound!'; } ]); $fnStream->rewind(); // Outputs: About to rewind - rewound! ``` ## InflateStream `GuzzleHttpPsr7InflateStream` 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 `GuzzleHttpPsr7LazyOpenStream` Lazily reads or writes to a file that is opened only after an IO operation take place on the stream. ```php use GuzzleHttpPsr7; $stream = new Psr7LazyOpenStream('/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 `GuzzleHttpPsr7LimitStream` 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 GuzzleHttpPsr7; $original = Psr7stream_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 Psr7LimitStream($original, 1024, 2048); echo $stream->getSize(); // >>> 1024 echo $stream->tell(); // >>> 0 ``` ## MultipartStream `GuzzleHttpPsr7MultipartStream` Stream that when read returns bytes for a streaming multipart or multipart/form-data stream. ## NoSeekStream `GuzzleHttpPsr7NoSeekStream` NoSeekStream wraps a stream and does not allow seeking. ```php use GuzzleHttpPsr7; $original = Psr7stream_for('foo'); $noSeek = new Psr7NoSeekStream($original); echo $noSeek->read(3); // foo var_export($noSeek->isSeekable()); // false $noSeek->seek(0); var_export($noSeek->read(3)); // NULL ``` ## PumpStream `GuzzleHttpPsr7PumpStream` 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 `GuzzleHttpPsr7StreamDecoratorTrait`. This trait provides methods that implement `PsrHttpMessageStreamInterface` 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 PsrHttpMessageStreamInterface; use GuzzleHttpPsr7StreamDecoratorTrait; 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 GuzzleHttpPsr7; $original = Psr7stream_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 `GuzzleHttpPsr7StreamWrapper` class if you need to use a PSR-7 stream as a PHP stream resource. Use the `GuzzleHttpPsr7StreamWrapper::getResource()` method to create a PHP stream from a PSR-7 stream. ```php use GuzzleHttpPsr7StreamWrapper; $stream = GuzzleHttpPsr7stream_for('hello!'); $resource = StreamWrapper::getResource($stream); echo fread($resource, 6); // outputs hello! ``` # Function API There are various functions available under the `GuzzleHttpPsr7` namespace. ## `function str` `function str(MessageInterface $message)` Returns the string representation of an HTTP message. ```php $request = new GuzzleHttpPsr7Request('GET', 'http://example.com'); echo GuzzleHttpPsr7str($request); ``` ## `function uri_for` `function uri_for($uri)` This function accepts a string or `PsrHttpMessageUriInterface` and returns a UriInterface for the given value. If the value is already a `UriInterface`, it is returned as-is. ```php $uri = GuzzleHttpPsr7or('http://example.com'); assert($uri === GuzzleHttpPsr7or($uri)); ``` ## `function stream_for`
最新文章
8月台湾手机销量前二十榜单出炉 第一是它 OPPO第三
  9月19日,手机中国了解到,2022年8月中国台湾智能手机销售排行榜TOP20新鲜出炉。虽然离iPhone 14系列发布只有1个月,不过也没有阻挡果粉购买其他机型的欲望,8月销量冠军的宝座依旧由iPhone 13(128GB)夺得。iPhone 13系列  根据榜
360逾期会怎么样逾期后果会有多严重
360逾期会怎么样?逾期后果严重吗?在现代社会,信用已经成为个人和企业进行经济活动的重要基础。随着互联网金融的发展,越来越多的人开始借助平台进行贷款,而360作为一个知名的互联网金融平台,吸引了大量用户。贷款逾期的问也随之而来。本
24免费资料大全天下|经典解释落实
  在数字化时代,信息的获取变得前所未有地便捷。这篇文章,我们不涉及违法词汇,如“博彩”等,旨在整合24个不同领域的免费资料大全,并为这些资源提供经典解释,并落到实处。我们将通过涵盖科技、健康、教育、艺术等领域的资料和解释,
AI编程,人工智能的第一个“杀手级应用”正在浮现
AI编程助手是帮助程序员写代码的智能工具。硅谷现在越来越相信,AI在编程领域的应用非常有前途,许多初创公司和科技巨头都在竞相开发能够帮助编写和修改代码的AI助手。自2023年初至今,相关企业已累计获得近10亿美元融资
2024手游热度排行榜最新大全 热门游戏盘点推荐
本期小编推荐的游戏主题是2024手游热度排行榜最新,回顾这一年,我们迎接了非常多游戏的出现,而在两年交接之时,又有很多精品好游上线,本期小编准备的是近期上线的五款新游榜上的评分很高的游戏,这五款都可以称之为各自领域的翘楚,大家
4yx盒子玩家评论
经典移植、完美还原,4yx盒子下载给大家带来最好的游戏体验。4yx盒子这是一款数万人攻城的《mir传说》手游。最经典的1.76版传奇所有核心玩法元素都完美还原给游戏玩家,各种经典复古神器免费提供。快来下载游戏,一起在血色沙城战斗吧!丰
2024年游戏笔记本十大品牌
一、游戏笔记本是什么意思游戏笔记本,也称为游戏本,是一种专为游戏而设计的笔记本电脑,其主要目的是提供高性能和流畅的游戏体验。与传统笔记本电脑相比,游戏本通常拥有更强大的硬件配置和更好的散热设计。在硬件配置方面,游戏本通常采
2024年新奥天天精准资料大全,重要性解释落实方法_3DM59.240
随着2024年的到来,新奥天天精准资料大全成为了众多行业和领域关注的焦点。这份资料大全不仅涵盖了最新的市场数据、行业趋势,还包括了精准的分析和预测,对于企业决策者和研究人员来说具有极高的参考价值。本文将详细介绍新奥天天精准资料
12月前两周呼和浩特二手房挂牌均价8727元/平 环比下跌1.45%
据房天下研究院监测,12月前两周呼和浩特二手房挂牌均价为8727元/平方米,环比下跌1.45%。12月前两周呼和浩特二手房各区县搜索排行榜中,赛罕、新城、回民占据热搜区县榜TOP3;玉泉大召的汇豪天下笑傲楼盘关注度榜单;价格方面,网友关注度
200期排列五历史上的今天奖号同期对比
22200期排列五开奖号码:4717021200期排列五开奖号码:5986320200期排列五开奖号码:9351519200期排列五开奖号码:5835918200期排列五开奖号码:9348017200期排列五开奖号码:0257416200期排列五开奖号码:4688815200期排列五开奖号码:2829614200
相关文章
推荐文章
发表评论
0评