net-http-response
![Software License][ico-license]
, (*1)
Install
Via composer:, (*2)
``` bash
$ composer require binsoul/net-http-response, (*3)
This package provides PSR-7 ResponseInterface compatible response classes specialized for known HTTP status codes and body implementations which extend the PSR-7 StreamInterface with some useful methods. The included response emitter can output responses to different target environments.
## Usage
Output a text response on a web server:
``` php
emit($response, new SapiTarget());
```
Capture and display response headers and body:
``` php
\s+/m", ' => ', var_export($value, true)));
}
$response = new OkResponse(new TextBody('Hello world!'));
$target = new CaptureTarget();
$emitter = new DefaultEmitter();
$emitter->emit($response, $target);
?>
<!DOCTYPE html>
<html>
<body>
<h1>Headers</h1>
<pre><?= dump($target->getHeaders()) ?></pre>
<h1>Body</h1>
<pre><?= dump($target->getBody()) ?></pre>
</body>
</html>
Testing
bash
$ composer test
, (*4)
License
The MIT License (MIT). Please see License File for more information., (*5)