northwoods / lazy-middleware
Lazy loading for middleware and request handlers
Installs: 204 604
Dependents: 2
Suggesters: 2
Security: 0
Stars: 5
Watchers: 3
Forks: 2
Open Issues: 0
Requires
- php: ^7.2
- psr/container: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- nyholm/psr7: ^1.1
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: ^0.11
- phpstan/phpstan-phpunit: ^0.11
- phpunit/phpunit: ^8.3
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2024-10-11 03:41:42 UTC
README
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);