Awesome
Northwoods Lazy Middleware
Lazy loading for PSR-15 middleware and request handlers that supports "just in time" instantiation using a PSR-11 container.
Installation
The best way to install and use this package is with composer:
composer require northwoods/lazy-middleware
Usage
This package contains two factories: one for request handlers and one for middleware.
LazyHandlerFactory::defer($handler)
Create a new lazy handler.
The $handler
identifier is not required to be a class name. Any string
that refers to a container identifier can be used.
use Northwoods\Middleware\LazyHandlerFactory;
/** @var ContainerInterface */
$container = /* any container */;
$lazyHandler = new LazyHandlerFactory($container);
/** @var \Psr\Http\Server\RequestHandlerInterface */
$handler = $lazyHandler->defer(Acme\FooHandler::class);
LazyMiddlewareFactory::defer($middleware)
Create a new lazy middleware.
The $middleware
identifier is not required to be a class name. Any string
that refers to a container identifier can be used.
use Northwoods\Middleware\LazyMiddlewareFactory;
/** @var ContainerInterface */
$container = /* any container */;
$lazyMiddleware = new LazyMiddlewareFactory($container);
/** @var \Psr\Http\Server\MiddlewareInterface */
$middleware = $lazyMiddleware->defer(Acme\BarMiddleware::class);