PHPackages                             yuloh/stream - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. yuloh/stream

AbandonedArchivedLibrary[PSR &amp; Standards](/categories/psr-standards)

yuloh/stream
============

A stream implementation for PSR-7

0.1.0(10y ago)31.8kMITPHPPHP ~5.5|~7.0

Since May 13Pushed 10y agoCompare

[ Source](https://github.com/matt-allan/stream)[ Packagist](https://packagist.org/packages/yuloh/stream)[ Docs](https://github.com/yuloh/stream)[ RSS](/packages/yuloh-stream/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (8)Versions (2)Used By (0)

Stream
======

[](#stream)

[![Latest Version on Packagist](https://camo.githubusercontent.com/075f95c72bb8afa8baf75969a0134530d5467be40018679a866869e594ec827a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f79756c6f682f73747265616d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/yuloh/stream)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/e84d325a94e378b26585ded84d88b53b27b718b95a0db62feaa347a94a2f10b4/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f79756c6f682f73747265616d2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/yuloh/stream)[![Coverage Status](https://camo.githubusercontent.com/1ecc72d68cd12a4e04f2e5eea46f18f7d1907ef856c7518400c2abf2b0ddccd9/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f79756c6f682f73747265616d2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/yuloh/stream/code-structure)[![Quality Score](https://camo.githubusercontent.com/895a2267e38878ae0cc7a7fb8bf891b7355ccd1d8fdbd8f3911084d56867786f/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f79756c6f682f73747265616d2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/yuloh/stream)[![Total Downloads](https://camo.githubusercontent.com/9166d53e01bd3e1df18d8b108832acb088c730397ababb4651f306e02cdc6c78/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f79756c6f682f73747265616d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/yuloh/stream)

A PSR-7 stream implementation.

Introduction
------------

[](#introduction)

This package provides an implementation of `Psr\Http\Message\StreamInterface` for [PSR-7](http://www.php-fig.org/psr/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
-------

[](#install)

Via Composer

```
$ composer require yuloh/stream
```

Usage
-----

[](#usage)

### Factory

[](#factory)

The simplest way to use this package is to use the [`StreamFactory`](./src/StreamFactory.php). The `create` method will create a [`Stream`](./src/Stream.php) from a scalar, string, resource, or object (if it implements either JsonSerializable or \_\_toString).

```
$stream   = (new StreamFactory())->create('Hello world!');
```

### Constructor

[](#constructor)

You can also create a stream directly. You will need to provide a valid [resource](http://php.net/manual/en/language.types.resource.php) as the only argument to the constructor.

```
use Yuloh\Stream\Stream;

$resource = fopen('php://temp', 'r+');
$stream = new Stream($resource);
```

### Allowing Different implementations

[](#allowing-different-implementations)

To allow the user to use their own stream, you should typehint against the [`StreamFactoryInterface`](src/StreamFactoryInterface) instead of using a concrete implementation. This package ships with [adapters](src/Adapters) for all of the common implementations, so the user can easily use their own stream.

```
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
use Yuloh\Stream\StreamFactoryInterface;
use Yuloh\Stream\StreamFactory;

class HelloMiddleware
{
    public function __construct(StreamFactoryInterface $streamFactory = null)
    {
        $this->streamFactory = $streamFactory ?: new StreamFactory();
    }

    public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next)
    {
        $stream   = $this->streamFactory->create('Hello world!');
        $response = $response->withBody($stream);
        return $next($request, $response);
    }
}
```

```
use Yuloh\Stream\Adapters;

// Usage with default implementation:
new HelloMiddleware();

// Usage with Zend Diactoros:
new HelloMiddleware(new Adapters\DiactorosStreamFactory());

// Usage with Guzzle PSR7:
new HelloMiddleware(new Adapters\GuzzleStreamFactory());

// Usage With Slim Framework:
new HelloMiddleware(new Adapters\SlimStreamFactory());
```

Testing
-------

[](#testing)

```
$ composer test
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

25

—

LowBetter than 36% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3693d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/9440455?v=4)[Matt A](/maintainers/matt-allan)[@matt-allan](https://github.com/matt-allan)

---

Tags

streamyuloh

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/yuloh-stream/health.svg)

```
[![Health](https://phpackages.com/badges/yuloh-stream/health.svg)](https://phpackages.com/packages/yuloh-stream)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.1B3.7k](/packages/guzzlehttp-psr7)[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.2k532.1M2.5k](/packages/aws-aws-sdk-php)[symfony/symfony

The Symfony PHP framework

31.4k86.9M2.2k](/packages/symfony-symfony)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k496.1k33](/packages/neuron-core-neuron-ai)[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k12](/packages/tempest-framework)[moonshine/moonshine

Laravel administration panel

1.3k239.9k75](/packages/moonshine-moonshine)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
