A lightweight, zero-dependency middleware pipeline for PHP.
Route any object through a composable pipeline of middleware before reaching a final handler — inspired by the HTTP middleware pattern (PSR-15).
composer require italystrap/pipelineuse ItalyStrap\Pipeline\Pipeline;
use ItalyStrap\Pipeline\CallbackHandler;
use ItalyStrap\Pipeline\HandlerInterface;
use ItalyStrap\Pipeline\MiddlewareInterface;
// 1. Define a message (any object mutable or immutable)
$message = new User(name: 'Alice', email: 'alice@example.com');
// 2. Create a pipeline with a handler and middleware
$handler = new Pipeline(
new CallbackHandler(static function (object $message): string {
// final handler logic
return 'User created: ' . $message->name;
}),
new LoggingMiddleware(),
new ValidationMiddleware(),
);
// 3. Dispatch when ready
$result = $handler->handle($message);The message flows through middleware in the order they were provided, then reaches the handler.
- Overview — Architecture, pattern, and design rationale
- Interfaces —
HandlerInterfaceandMiddlewareInterface - Pipeline — The main pipeline dispatcher
- Helpers —
CallbackHandler,DecorateHandler,NoHandlerProvided - Pipeline vs DecorateHandler — When to use which
- Wrapping the Pipeline — Adapting the generic pipeline to typed contracts (e.g. CLI exit codes)
MIT — see LICENSE.