componenta/pipeline

PSR-15 middleware pipeline for Componenta

Maintainers

Package info

github.com/componenta/pipeline

pkg:composer/componenta/pipeline

Statistics

Installs: 7

Dependents: 3

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-15 11:04 UTC

This package is auto-updated.

Last update: 2026-06-15 12:06:51 UTC


README

PHP PSR-15 License

PSR-15 middleware pipeline for the Componenta framework.

Installation

composer require componenta/pipeline

The package declares Componenta\Http\Middleware\PipelineConfigProvider in extra.componenta.config-providers. When componenta/composer-plugin is installed, the provider is added to the generated provider list automatically.

Related Packages

Package Why it matters here
psr/http-server-middleware Defines MiddlewareInterface and RequestHandlerInterface.
componenta/app-http Runs HTTP applications on top of the pipeline; concrete middleware and response emission live in separate HTTP packages.
componenta/router Usually sits near the end of the HTTP pipeline.
componenta/middleware-factory Creates middleware from strings, classes, groups, and callables.

Usage

As a top-level handler

use Componenta\Http\Middleware\Pipeline;

$pipeline = new Pipeline(
    [$errorMiddleware, $authMiddleware, $routerMiddleware],
    fallbackHandler: $notFoundHandler,
);

$response = $pipeline->handle($request);

If no fallbackHandler is supplied, EmptyPipelineHandler is installed and throws RuntimeException on invocation — this surfaces misconfiguration of an empty pipeline.

Nested pipelines

A pipeline is itself a middleware, so pipelines compose:

$api = new Pipeline([$apiAuth, $apiRouter]);
$web = new Pipeline([$sessionMiddleware, $webRouter]);

$app = new Pipeline([$errorMiddleware], $notFoundHandler)
    ->pipe($api)
    ->pipe($web);

Via the factory

$pipeline = $factory->createMiddlewarePipeline(
    [$auth, $router],
    $notFoundHandler,
);

Behavior

  • Middleware execute in registration order (FIFO).
  • pipe() returns a new pipeline; the original is not modified.
  • Returning a response from a middleware without calling the next handler halts the chain.
  • Exceptions from middleware and terminal handlers propagate unchanged.

Errors

Condition Exception
Non-middleware element in constructor / pipe() InvalidArgumentException
Pipeline appended to itself via pipe() RuntimeException
Pipeline passed as its own handler to process() RuntimeException
Empty pipeline invoked without a custom fallback RuntimeException