# Class HttpSoft\Emitter\SapiEmitter

Class, that implements HttpSoft\Emitter\EmitterInterface and uses of the PHP SAPI for emitting Psr\Http\Message\ResponseInterface implementations.

Source code on GitHub

use HttpSoft\Emitter\SapiEmitter;
use Psr\Http\Message\ResponseInterface;

/** @var ResponseInterface $response */

$emitter = new SapiEmitter();
// 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);
// 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: ''

# Public methods

See the original detailed description of the methods in the HttpSoft\Emitter\EmitterInterface.

public function __construct(int $bufferLength = null);

If $bufferLength is an integer and its value is less than 1, the \InvalidArgumentException exception will be thrown.

# emit

Emits HTTP responses that implements Psr\Http\Message\ResponseInterface.

public function emit(ResponseInterface $response, bool $withoutBody = false): void;

If the headers have already been sent, the HttpSoft\Emitter\Exception\HeadersAlreadySentException exception will be thrown.

If output has been emitted previously, the HttpSoft\Emitter\Exception\OutputAlreadySentException exception will be thrown.

If $withoutBody === true or the response body is not readable, the response will be emit without a body.