分享好友 最新动态首页 最新动态分类 切换频道
在线视频图片小说综合网站源码_粉色精美
2024-12-26 15:58
# 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`
最新文章
ai怎么制作网格logo_如何制作优雅美观的网格Logo?AI教你实现
网格Logo是一种经典的设计形式,在现代设计中也十分常见。本文将从四个方面详细阐述如何制作优雅美观的网格Logo,同时介绍AI的使用方法,目的是帮助读者更好地制作出高质量的网格Logo。网格Logo设计最基本的原理就是利用网格来限制和排布图
linux简单快速启用web
Python的SimpleHTTPServer需要先安装python,然后执行$ python -m SimpleHTTPServer //当前目录为根目录,端口在8000的服务$ python -m SimpleHTTPServer 9000//当前目录为根目录,端口在9000的服务为了更快速的使用,我们可以在.bashrc或
2024 狠狠搞钱,8 个大火 AI 副业!
不要取悦别人,除非那个人给你打钱。祝各位马上有钱,别的先放放。2024 年一起搞钱,抓紧搞钱,努力搞钱!今年以来 AI 大火,很多人看着都很焦虑,那么怎么靠 AI 变现呢?AI 绘画就是其中
A股全球第一的龙头40家打破国外垄断21科特估顶尖科技龙头梳理
工业富联:全球领先的智能制造服务商和工业互联网整体解决方案提供商。海光信息:国内x86服务器CPU与协处理器领先企业,部分产品已较接近国际厂商同期水平。中芯国际:全球领先的集成电路晶圆代工企业之一,中国大陆技术最先进、规模最大、
AI绘画 Comfyui迎来重大更新,更简单易用的桌面程序版Comfyui-V1安装教程!
Comfui官方组织Comfy Org宣布了Comfyui V1的发布,这是一个类似于桌面程序的客户端,同时支持Windous、MacOS和Linux系统。一键安装使用,更简单易用,对于普通用户更友好。 准确的说Comfyui已经不止是图像生成工具
2024最新股民电销获客渠道,运营商SDK/DPI实时捕捉电销股民数据手拨一手料子
随着互联网的不断发展和普及,作为运营商早已发现了大数据的重要性。运用大数据技术,可以深挖用户需求,运营商可以更加精准地获客,提高用户满意度,增加收入。运营商大数据抓取原理,精准数据获客 渗透稳定料商TG@shuju96精准数据SDK/DPI
16.59万就能开回家,奥迪A3配置怎么选
新车采用奥迪家族最新的设计理念,整体造型与以往产品有很大不同,颜值明显提升看着非常漂亮。总体而言,新一代的前脸造型变得更加有力,并且在发动机盖增加一些突起线条,看上去颇具肌肉感,两侧犀利的大灯的造型,内部灯组错落有致,点亮
360浏览器怎么升级
360浏览器是360公司推出的一款安全浏览器,因其出色的性能和丰富的功能而备受用户青睐。然而,随着技术的不断进步和网络安全威胁的日益复杂,浏览器也需要不断更新以提供更好的用户体验和安全保障。那么,如何升级360浏览器呢?以下是几种
77777788888王中王中特亮点|精选解释解析落实
  摘要:本文将深入探讨一组数字代码——77777888888所蕴含的特殊含义和价值。我们将从不同角度解析这些数字如何在商业、科技和文化等多个领域中被赋予特别的意义,并探讨如何在实际应用中利用这些数字来实现目标。通过精选案例分析,我
2024淘宝无痕代码标题技术应用介绍
2024淘宝无痕代码标题技术应用介绍淘宝各种图片,标题,转链接,客服,综合技术过排除查防排查如有不懂请咨询下面请忽略2024年,淘宝无痕代码标题技术应用正成为电子商务领域的焦点。这项技术的引入将彻底改变消费者和商家的交互方式,并为
相关文章
推荐文章
发表评论
0评