enalquiler / lazy-middleware
Enalquiler PSR-15 Lazy Middleware
2.1.0
2018-10-03 21:19 UTC
Requires
- psr/http-factory: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
- guzzlehttp/psr7: ^1.4
- phpunit/phpunit: ^7.3
This package is not auto-updated.
Last update: 2025-03-28 10:44:26 UTC
README
A dead-simple lazy PSR-15 middleware.
Installation
composer require enalquiler/lazy-middleware
Usage
With Zend Stratigility
Zend Stratigility
<?php use Zend\Diactoros\Response; use Zend\Diactoros\Server; use Zend\Stratigility\MiddlewarePipe; use Zend\Stratigility\NoopFinalHandler; use Enalquiler\Middleware\SymfonyMiddleware; use function Enalquiler\Middleware\lazy; require __DIR__ . '/../vendor/autoload.php'; $app = new MiddlewarePipe(); $app->setResponsePrototype(new Response()); $server = Server::createServer($app, $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); $app ->pipe('/foo', lazy(function() { // Run heavy computations return new HardToBuildMiddleware(); })) ; $server->listen(new NoopFinalHandler());
With Middleman
<?php use Psr\Http\Message\RequestInterface as Request; use Zend\Diactoros\Response; use Zend\Diactoros\ServerRequest; use mindplay\middleman\Dispatcher; use Enalquiler\Middleware\lazy; $dispatcher = new Dispatcher([ lazy(function() { // Run heavy computations return new HardToBuildMiddleware(); }), function (Request $request) { return (new Response())->withBody(...); // abort middleware stack and return the response }, // ... ]); $response = $dispatcher->dispatch(new ServerRequest($_SERVER, $_FILES));
Running the tests
php vendor/bin/phpunit
Authors
- David MartÃnez - Initial work
- Christian Soronellas
- Enalquiler Engineering
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE.md file for details
Acknowledgments
- This middleware was inspired by the work of https://github.com/stackphp/LazyHttpKernel