idiosyncratic / http-runner
PSR-15 HTTP Request runner
0.2.0
2019-11-30 08:47 UTC
Requires
- php: >=7.3
- psr/http-factory: ^1.0
- psr/http-message: ^1.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
- psr/log: ^1.1
Requires (Dev)
- idiosyncratic/devtools: ^0.2
Suggests
- idiosyncratic/http-middlewarehandler: PSR-15 Request/Middleware handler
This package is auto-updated.
Last update: 2024-11-29 05:39:17 UTC
README
Library for running an HTTP request and emitting the generated response.
Inspired by zend-httphandlerrunner, this library
provides a class for executing PSR-15 request handlers and emitting
the generated PSR-7 response back to the waiting client. Differences from
the Zend library include:
- Requires an implementation of
Idiosyncratic\Http\Runner\ServerRequestFactory
to creates the initial PSR-7ServerRequestInterface
instance instead of accepting a callable - Internally, uses output buffering to suppress output to the client, including headers, until the final response is emitted. As a result, all headers and cookies (including for instance the PHP session cookie) must be set in the final
ResponseInterface
instance or they will not be sent to the client - The interface for the response emitter (
Idiosyncratic\Http\Runner\ResponseEmitter
) is not stackable
Installation
Install using Composer:
composer require idiosyncratic/http-runner
Usage
In order to user this library, you will need to provide:
- An implementation of
Idiosyncratic\Http\Runner\ServerRequestFactory
to create the initial PSR-7ServerRequestInterface
instance - An implementation of
Psr\Http\Server\RequestHandlerInterface
to handle generating a response - An implementation of
Idiosyncratic\Http\Runner\ResponseEmitter
to emit a PSR-7ResponseInterface
to the client. A basicIdiosyncratic\Http\Runner\PhpSapiResponseEmitter
is included. - An implementation of
Psr\Log\LoggerInterface
to log uncaught exceptions
use Idiosyncratic\Http\Runner\Runner;
use Idiosyncratic\Http\Runner\PhpSapiResponseEmitter;
use Psr\Log\NullLogger();
$runner = new Runner(
$serverRequestFactoryImplementation,
$requestHandlerImplementation,
new PhpSapiResponseEmitter(),
new NullLogger()
);
$runner->run();