stefna / http-runner
Installs: 1 951
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^8.2
- nyholm/psr7: ^1.5.1
- psr/http-factory: ^1.0.1
- psr/http-message: ^1.0.1
- psr/http-server-handler: ^1.0.1
- psr/http-server-middleware: ^1.0.1
- psr/log: ^3.0
Requires (Dev)
- bnf/phpstan-psr-container: ^1.0
- phpstan/extension-installer: ^1.2
- phpstan/phpstan: ^1.8
- phpstan/phpstan-phpunit: ^1.1
- phpunit/phpunit: ^10.0
- squizlabs/php_codesniffer: dev-master
- stefna/codestyle: ^1.12
- tomasvotruba/type-coverage: ^0.0.7
README
This package provides a psr-15 implementation with helpers
Requirements
PHP 8.2 or higher.
Installation
composer require stefna/http-runner
Getting started
<?php use Psr\Container\ContainerInterface; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ServerRequestInterface; use Stefna\Http\Middleware\ContainerMiddlewareResolver; use Stefna\Http\Middleware\NullMiddlewareResolver; use Stefna\Http\Middleware\Runner; use Stefna\Http\Middleware\SimpleMiddlewarePipeline; use Stefna\Http\Request\ServerRequestMarshal; use Stefna\Http\ResponseHandler\HttpResponseHandler; /** @var ContainerInterface $container */ /** @var ResponseFactoryInterface $responseFactory */ $middlewares = new SimpleMiddlewarePipeline( new CrashMiddleware(), new SessionMiddleware(), new RouterMiddleware(), new RouteDispatchMiddleware(), ); // no resolving of middlewares all middlewares need to be instantiated earlier $middlewareResolver = new NullMiddlewareResolver(); // or if middleware is a string look in container for it and lazy create it when needed $middlewareResolver = new ContainerMiddlewareResolver($container); $runner = new Runner( $middlewares, $responseFactory, $middlewareResolver, ); // boot request /** @var ServerRequestInterface $request */ $request = (new ServerRequestMarshal())->marshal($_SERVER); // dispatch middlewares and get a response back $response = $runner->handle($request); // send response (new HttpResponseHandler())->handle($response);
Contribute
We are always happy to receive bug/security reports and bug/security fixes
License
The MIT License (MIT). Please see License File for more information.