httpsoft / http-emitter
Emitting of PSR-7 Response implementation
Installs: 44 803
Dependents: 12
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ^7.4|^8.0
- psr/http-message: ^1.1|^2.0
Requires (Dev)
- httpsoft/http-message: ^1.1
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.7
- vimeo/psalm: ^4.9|^5.2
Provides
README
This package emitting implementations of Psr\Http\Message\ResponseInterface from PSR-7 HTTP Message.
Documentation
Installation
This package requires PHP version 7.4 or later.
composer require httpsoft/http-emitter
Usage SapiEmitter
use HttpSoft\Emitter\SapiEmitter; use Psr\Http\Message\ResponseInterface; /** @var ResponseInterface $response */ $response->getBody()->write('Content'); $emitter = new SapiEmitter(); $emitter->emit($response); // Output result: 'Content'
By default, the entire content of the response is emitted. To emit the content in parts, it is necessary to specify a maximum buffer length:
$emitter = new SapiEmitter(8192); $emitter->emit($response); // Output result: 'Content'
Emitting only part of the content using the Content-Range
header:
$emitter = new SapiEmitter(8192); $emitter->emit($response->withHeader('Content-Range', 'bytes 0-3/7')); // Output result: 'Cont'
To emitting only the status line and headers without a body, it is necessary to specify true
as the second parameter:
$emitter = new SapiEmitter(8192); $emitter->emit($response, true); // Output result: ''