kekos / http-emitter
Emitting PSR-7 responses.
Requires
- php: ^8.1
- psr/http-message: ^1.0 || ^2.0
Requires (Dev)
- ext-json: *
- friendsofphp/php-cs-fixer: ^3.95
- laminas/laminas-diactoros: ^3.7
- phpstan/phpstan: ^2.1
- phpstan/phpstan-phpunit: ^2.0
- phpunit/phpunit: ^10.5
This package is auto-updated.
Last update: 2026-05-13 17:56:28 UTC
README
Emits a Response to the PHP Server API.
This is a fork of the abandoned project narrowspark/http-emitter.
The available emitter implementations are.
- `Kekos\HttpEmitter\SapiEmitter`
- `Kekos\HttpEmitter\SapiStreamEmitter`.
Note: each use the native PHP functions
header()andechoto emit the response.
Note: if headers have been sent, or the output buffer exists, and has a non-zero length, the emitters raise an exception, as mixed PSR-7 / output buffer content creates a blocking issue.
If you are emitting content via
echo,var_dump, etc., or not catching PHP errors / exceptions, you will need to either fix your app to always work with a PSR-7 response. Or provide your own emitters that allow mixed output mechanisms.
Installation
composer require kekos/http-emitter
Use
How to use the SapiEmitter:
<?php use Kekos\HttpEmitter\SapiEmitter; $response = new \Response(); $response->getBody()->write("some content\n"); $emitter = new SapiEmitter(); $emitter->emit($response);
If you missing the Content-Length header you can use the \Kekos\HttpEmitter\Util\Util::injectContentLength static method.
<?php use Kekos\HttpEmitter\Util; $response = new \Response(); $response = Util::injectContentLength($response);
Versioning
This library follows semantic versioning, and additions to the code ruleset are performed in major releases.
Changelog
Please have a look at CHANGELOG.md.
Contributing
If you would like to help take a look at the list of issues.
License
This package is licensed using the MIT License.
Please have a look at LICENSE.md.