Search by

webservco / emitter

ariademur

A PHP component/library. Sends a PSR-7 response to the client, with its status line, headers and body.

Package info

github.com/webservco/emitter

Homepage

pkg:composer/webservco/emitter

Statistics

Installs: 109

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v2.3.0 2026-10-11 16:34 UTC

This package is auto-updated.

Last update: 2026-10-11 16:45:39 UTC


README

A PHP component/library. Please see webservco/sandbox for an example project using these types of components.

Sends a PSR-7 response to the client, with its status line, headers and body.

  • Related: webservco/application-runner (emits the response after the request is handled)

Installation

composer require webservco/emitter

Usage

use WebServCo\Emitter\Service\SapiEmitter;
use WebServCo\Emitter\Service\StackEmitter;

// \WebServCo\Emitter\Contract\EmitterInterface
$emitter = new StackEmitter([new SapiEmitter()]);
$emitter->emit($response);

StackEmitter tries each emitter in order and stops at the first one that returns true. Add your own emitter to the list for environments that SapiEmitter doesn't handle.

Contracts

Interface Implementation Purpose
Contract\EmitterInterface Service\SapiEmitter Sends the response through the PHP SAPI (header() and echo).
Service\StackEmitter Tries a list of emitters until one succeeds.

Namespaces are relative to WebServCo\Emitter\.

Notes

Under the cli and cgi-fcgi SAPIs, SapiEmitter returns false and leaves the response to the next emitter in the stack. If headers were already sent, it throws an OverflowException.

StackEmitter throws an UnderflowException when no emitter handles the response.

A header with several values is sent as one line, with the values joined by , .

Development

# Start project.
ddev start
# Install dependencies.
ddev c u
# Run all validations.
ddev c c
# Run unit tests.
ddev c test:dox

License

MIT