ellipse / dispatcher-container
Psr-15 middleware dispatcher factory resolving class names from a Psr-11 container
Requires
- php: >=7.0
- ellipse/dispatcher: ^1.6
- ellipse/handlers-container: ^1.0
- ellipse/middleware-container: ^1.0
- psr/container: ^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 middleware and request handler class names.
Require php >= 7.0
Installation composer require ellipse/dispatcher-container
Run tests ./vendor/bin/kahlan
Create a dispatcher factory resolving Psr-15 class names
This package provides an Ellipse\Dispatcher\ContainerResolver
class implementing Ellipse\DispatcherFactoryInterface
which allows to decorate any other object implementing this interface.
It takes a container implementing Psr\Container\ContainerInterface
as first parameter and the factory to decorate as second parameter.
Once decorated, the resulting dispatcher factory can be used to produce instances of Ellipse\Dispatcher
by resolving middleware class names as Ellipse\Middleware\ContainerMiddleware
from the ellipse/middleware-container package and request handler class names as Ellipse\Handlers\ContainerRequestHandler
from the ellipse/handlers-container package.
ContainerMiddleware
and ContainerRequestHandler
logic is described on the ellipse/middleware-container and ellipse/handlers-container documentation pages.
<?php namespace App; use SomePsr11Container; use Ellipse\DispatcherFactory; use Ellipse\Dispatcher\ContainerResolver; // Get some Psr-11 container. $container = new SomePsr11Container; // Decorate a DispatcherFactoryInterface implementation with a ContainerResolver. $factory = new ContainerResolver($container, new DispatcherFactory); // A dispatcher using both class names and Psr-15 instances can now be created. $dispatcher = $factory(SomeRequestHandler::class, [SomeMiddleware1::class, new SomeMiddleware2]);