ellipse / handlers-callable
Psr-15 request handler proxying a callable
Installs: 1 211
Dependents: 1
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)
- eloquent/phony-kahlan: ^1.0
- kahlan/kahlan: ^4.0
This package is auto-updated.
Last update: 2024-10-26 00:54:27 UTC
README
This package provides a Psr-15 request handler proxying a callable.
Require php >= 7.0
Installation composer require ellipse/handlers-callable
Run tests ./vendor/bin/kahlan
Using callables as request handlers
The class Ellipse\Handlers\CallableRequestHandler
can be wrapped around a callable in order to use it as a request handler.
As any request handler ->handle()
method, the callable takes an implementation of Psr\Http\Message\ServerRequestInterface
as parameter and should return an implementation of Psr\Http\Message\ResponseInterface
.
<?php namespace App; use Psr\Http\Message\ServerRequestInterface; use Ellipse\Handlers\CallableRequestHandler; // This request handler is wrapped around the given callable. $handler = new CallableRequestHandler(function (ServerRequestInterface $request) { // ... return $response; }); // The handler ->handle() method proxy the callable. $response = $handler->handle($request);