narrowspark/http-emitter

v0.4.3 2017-10-19 19:53 UTC

README

Emits a Response to the PHP Server API.

68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6172726f77737061726b2f687474702d656d69747465722e7376673f7374796c653d666c61742d737175617265 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545372e312e302d3838393242462e7376673f7374796c653d666c61742d737175617265 68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f727573742d6c616e672f727573742f6d61737465722e7376673f7374796c653d666c61742d737175617265 68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6e6172726f77737061726b2f687474702d656d69747465722f6d61737465722e7376673f7374796c653d666c61742d737175617265 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265

Two implementations currently available: Narrowspark\HttpEmitter\SapiEmitter and Narrowspark\HttpEmitter\SapiStreamEmitter. Each use the native PHP functions header() and echo in order to emit the response.

If you are using a non-SAPI implementation, you will need to create your own Narrowspark\HttpEmitter\EmitterInterface implementation.

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, print, var_dump, etc., or not catching PHP errors / exceptions, you will need to either fix your application to always work with a PSR-7 response. Or provide your own emitters that allow mixed output mechanisms.

Installation

composer require narrowspark/http-emitter

Use

<?php

use Narrowspark\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 need to use

<?php

$response = new \Response();

$response = Util::injectContentLength($response);

Contributing

If you would like to help take a look at the list of issues and check our Contributing guild.

Note: Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

License

The Narrowspark http-emitter is open-sourced software licensed under the MIT license