项目作者: narrowspark

项目描述 :
:satellite: Emitting psr-7 responses.
高级语言: PHP
项目地址: git://github.com/narrowspark/http-emitter.git
创建时间: 2017-04-03T15:45:05Z
项目社区:https://github.com/narrowspark/http-emitter

开源协议:MIT License

下载


Http Response Emitter

Emits a Response to the PHP Server API.









The available emitter implementations are.

  1. - `Narrowspark\HttpEmitter\SapiEmitter`
  2. - `Narrowspark\HttpEmitter\SapiStreamEmitter`.

Note: each use the native PHP functions header() and echo to 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, print, 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

  1. composer require narrowspark/http-emitter

Use

How to use the SapiEmitter:

  1. <?php
  2. use Narrowspark\HttpEmitter\SapiEmitter;
  3. $response = new \Response();
  4. $response->getBody()->write("some content\n");
  5. $emitter = new SapiEmitter();
  6. $emitter->emit($response);

If you missing the Content-Length header you can use the \Narrowspark\HttpEmitter\Util\Util::injectContentLength static method.

  1. <?php
  2. use Narrowspark\HttpEmitter\Util;
  3. $response = new \Response();
  4. $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 and check our Contributing guild.

Code of Conduct

Please have a look at CODE_OF_CONDUCT.md.

License

This package is licensed using the MIT License.

Please have a look at LICENSE.md.