webservco / emitter
A PHP component/library. Sends a PSR-7 response to the client, with its status line, headers and body.
Requires
- php: ^8.4
- psr/http-message: ^2
Requires (Dev)
- pds/skeleton: ^1
- phan/phan: ^6
- php-parallel-lint/php-console-highlighter: ^1
- php-parallel-lint/php-parallel-lint: ^1
- phpmd/phpmd: ^3
- phpstan/phpstan: ^2
- phpstan/phpstan-deprecation-rules: ^2
- phpstan/phpstan-phpunit: ^2
- phpstan/phpstan-strict-rules: ^2
- phpunit/phpunit: ^13
- slevomat/coding-standard: ^8
- squizlabs/php_codesniffer: ^4
- vimeo/psalm: ^6
- webservco/coding-standards: ^2
- webservco/component-common: ^2
Suggests
None
Provides
None
Conflicts
None
Replaces
None
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