ellipse / dispatcher-callable
Psr-15 middleware dispatcher factory resolving callables
Requires
- php: >=7.0
- ellipse/dispatcher: ^1.6
- ellipse/handlers-callable: ^1.0
- ellipse/middleware-callable: ^1.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
README
This package provides a factory decorator for objects implementing Ellipse\DispatcherFactoryInterface
from ellipse/dispatcher package. It allows to produce instances of Ellipse\Dispatcher
using callables as middleware and request handler.
Require php >= 7.0
Installation composer require ellipse/dispatcher-callable
Run tests ./vendor/bin/kahlan
Create a dispatcher factory resolving callables
This package provides an Ellipse\Dispatcher\CallableResolver
class implementing Ellipse\DispatcherFactoryInterface
which allows to decorate any other object implementing this interface.
Once decorated, the resulting dispatcher factory can be used to produce instances of Ellipse\Dispatcher
by resolving callables as Ellipse\Middleware\CallableMiddleware
from the ellipse/middleware-callable package or as Ellipse\Handlers\CallableRequestHandler
from the ellipse/handlers-callable package.
CallableMiddleware
and CallableRequestHandler
logic is described on the ellipse/middleware-callable and ellipse/handlers-callable documentation pages.
<?php namespace App; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; use Ellipse\DispatcherFactory; use Ellipse\Dispatcher\CallableResolver; // Decorate a DispatcherFactoryInterface implementation with a CallableResolver. $factory = new CallableResolver(new DispatcherFactory); // This callable acts as a middleware. $middleware = function (ServerRequestInterface $request, RequestHandlerInterface $handler) { // ... } // This callable acts as a request handler. $handler = function (ServerRequestInterface $request) { // ... } // A dispatcher using both callables and Psr-15 instances can now be created. $dispatcher = $factory($handler, [$middleware, new SomeMiddleware]);