narrowspark / http-emitter
Emitting psr-7 responses.
Fund package maintenance!
prisis
Open Collective
Installs: 144 935
Dependents: 10
Suggesters: 0
Security: 0
Stars: 32
Watchers: 4
Forks: 10
Open Issues: 13
Requires
- php: ^8.0
- psr/http-message: ^1.0
- thecodingmachine/safe: ^1.3.3
Requires (Dev)
- ext-json: *
- laminas/laminas-diactoros: ^2.5.0
- mockery/mockery: ^1.4.2
- narrowspark/coding-standard: ^5.2.2
- phpunit/phpunit: ^9.5.2
- psalm/plugin-mockery: ^0.7.0
- thecodingmachine/phpstan-safe-rule: ^1.0.1
Provides
- dev-main / 2.0.x-dev
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.0.0
- 0.8.0
- 0.7.0
- v0.6.0
- v0.5.0
- v0.4.3
- v0.4.2
- v0.4.1
- v0.4.0
- v0.3.0
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- dev-renovate/node-16.x
- dev-renovate/stefanzweifel-git-auto-commit-action-4.x
- dev-renovate/node-14.x
- dev-renovate/actions-setup-node-3.x
- dev-renovate/anolilab-textlint-config-4.x
- dev-renovate/codecov-codecov-action-2.x
- dev-renovate/actions-stale-4.x
- dev-renovate/anolilab-textlint-config-3.x
- dev-renovate/major-2-dependencies-(major)
- dev-renovate/devdependencies-(non-major)
- dev-dependabot/add-v2-config-file
- dev-feature/template/sync/narrowspark/php-library-template
This package is auto-updated.
Last update: 2023-03-20 19:23:34 UTC
README
Emits a Response to the PHP Server API.
The available emitter implementations are.
- `Narrowspark\HttpEmitter\SapiEmitter`
- `Narrowspark\HttpEmitter\SapiStreamEmitter`.
Note: each use the native PHP functions
header()
andecho
to emit the response.
Note: if headers have been sent, or the output buffer exists, and has a non-zero length, the emitters raise an exception, as mixed PSR-7 / output buffer content creates a blocking issue.
If you are emitting content via
echo
,var_dump
, etc., or not catching PHP errors / exceptions, you will need to either fix your app to always work with a PSR-7 response. Or provide your own emitters that allow mixed output mechanisms.
Installation
composer require narrowspark/http-emitter
Use
How to use the SapiEmitter:
<?php use Narrowspark\HttpEmitter\SapiEmitter; $response = new \Response(); $response->getBody()->write("some content\n"); $emitter = new SapiEmitter(); $emitter->emit($response);
If you missing the Content-Length
header you can use the \Narrowspark\HttpEmitter\Util\Util::injectContentLength
static method.
<?php use Narrowspark\HttpEmitter\Util; $response = new \Response(); $response = Util::injectContentLength($response);
Versioning
This library follows semantic versioning, and additions to the code ruleset are performed in major releases.
Changelog
Please have a look at CHANGELOG.md
.
Contributing
If you would like to help take a look at the list of issues and check our Contributing guild.
Code of Conduct
Please have a look at CODE_OF_CONDUCT.md
.
License
This package is licensed using the MIT License.
Please have a look at LICENSE.md
.