Download the PHP package echo-fusion/middlewaremanager without Composer
On this page you can find all versions of the php package echo-fusion/middlewaremanager. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download echo-fusion/middlewaremanager
More information about echo-fusion/middlewaremanager
Files in echo-fusion/middlewaremanager
Package middlewaremanager
Short Description a middleware manager implements PSR-15 and PSR-7
License MIT
Homepage https://github.com/echo-fusion/middlewaremanager
Informations about the package middlewaremanager
MiddlewareManager
This is a flexible package for managing middleware in PHP applications. It enables you to create a middleware pipeline, where middleware processes a request and passes it on to the next, providing a clean and organized way to handle middleware logic.
This package is compliant with PSR-1, PSR-2, PSR-7 and PSR-15.
Part of EchoFusion, a modular PHP framework built from small packages.
Installation
Requirements
- PHP 8.1, 8.2 or 8.3
Usage
Here’s how to use the MiddlewareManager to set up and run a middleware pipeline.
1. Define handler
Define your handlers in proper directory and pass one of them to middleware manager to run it at the end of the pipeline:
2. Define middlewares
Define your middlewares in proper directory in separate files:
3. Run MiddlewareManager
To add middleware to the manager, you have two options:
- Add middleware as 'core middleware', which always runs before any middleware added later.
- Add middleware dynamically (e.g., useful for adding route-specific middleware).
Here is an example of how you can run MiddlewareManager:
Note: Don't forget to instantiate below injected dependencies in your container.
Behaviour worth knowing
- Lazy:
MiddlewareManagerputs a smallLazyMiddlewarestand-in in the pipeline and builds the real middleware from the container only when a request reaches it. A middleware that is never reached (because an earlier one answered) is never built, and each one is built once, not once per request. Classes that are not PSR-15 middleware are rejected when they are added. remove()removes the objects that were added for that class, even if the container builds a new object on everyget().
Testing
Credits
License
The MIT License (MIT). Please see LICENSE for more information.
All versions of middlewaremanager with dependencies
psr/container Version ^2.0
echo-fusion/contracts Version ^1.1 || ^2.0
psr/http-message Version ^2.0
guzzlehttp/psr7 Version ^2.5
psr/http-server-middleware Version ^1.0