italystrap/pipeline

A lightweight middleware pipeline for PHP — chain handlers and middleware to process messages through a composable pipeline

Maintainers

Package info

github.com/ItalyStrap/pipeline

pkg:composer/italystrap/pipeline

Statistics

Installs: 5

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2026-04-07 14:28 UTC

This package is auto-updated.

Last update: 2026-04-07 14:28:37 UTC


README

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).

Installation

composer require italystrap/pipeline

Quick Start

use 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.

Documentation

License

MIT — see LICENSE.