ztsu / reacon
PSR-7 middleware runner compatible with PSR-15
Installs: 4 791
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^7.0
- psr/http-message: ^1.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- mockery/mockery: 1.0
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^5.6
- zendframework/zend-diactoros: ^1.3
Provides
This package is not auto-updated.
Last update: 2024-12-02 07:57:39 UTC
README
The simplest PSR-15 complaint middleware runner.
The PSR-15 providers a standard for recommendations that defines the interface for server middleware-component compatible with PSR-7 HTTP Messages.
There are a few of another PSR-15 compatible dispatchers. Middleman is the best known. Also there are a lot of PSR-15 middleware-components collected in the middlewares/psr15-middlewares.
Installation
Via Composer:
$ composer require ztsu/reacon
Usage
<?php use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; class CreateRequestMiddleware implements MiddlewareInterface { public function process( ServerRequestInterface $request, RequestHandlerInterface $handler ): ResponseInterface { return new Zend\Diactoros\Response(); } } class HelloMiddleware implements MiddlewareInterface { public function process( ServerRequestInterface $request, RequestHandlerInterface $handler ): ResponseInterface { $response = $handler->handle($request); $response->getBody()->write("Hello, World!"); return $response; } } $reacon = new Ztsu\Reacon\Reacon( new HelloMiddleware(), new CreateRequestMiddleware() ); $request = Zend\Diactoros\ServerRequestFactory::fromGlobals(); $response = $reacon->handle($request); (new Zend\Diactoros\Response\SapiEmitter)->emit($response);
License
MIT.