Download the PHP package yuloh/stream without Composer
On this page you can find all versions of the php package yuloh/stream. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package stream
Short Description A stream implementation for PSR-7
License MIT
Homepage https://github.com/yuloh/stream
Informations about the package stream
Stream
A PSR-7 stream implementation.
Introduction
This package provides an implementation of Psr\Http\Message\StreamInterface
for PSR-7. Sometimes you just need a stream but don't want to depend on an entire PSR-7 implementation.
Let's say you are writing a PSR-7 middleware, and it needs to set a new response body.
If you try to write the data with $response->getBody()->write()
, there might already be an existing body which is longer than what you want to write. The only way to make that work is to write padding to the end of the string, which is not ideal.
The only way to create a new response body is to instantiate a stream. A good way to do this is to require a factory object as a dependency, and use that to create the stream. The downside is you are adding another setup step that the user will have to configure.
This package lets you provide a default implementation, so your middleware will work without having to setup a stream factory. Since it's a separate package you don't need to pull in an entire PSR-7 implementation just for streams, and you won't end up with dependency conflicts with the user's PSR-7 implementation.
It also includes an interface and adapters for all of the common PSR-7 implementations, so the user doesn't need to set that up manually.
Install
Via Composer
Usage
Factory
The simplest way to use this package is to use the Stream
from a scalar, string, resource, or object (if it implements either JsonSerializable or __toString).
Constructor
You can also create a stream directly. You will need to provide a valid resource as the only argument to the constructor.
Allowing Different implementations
To allow the user to use their own stream, you should typehint against the adapters for all of the common implementations, so the user can easily use their own stream.
Testing
License
The MIT License (MIT). Please see License File for more information.