componenta / pipeline
PSR-15 middleware pipeline for Componenta
v1.0.0
2026-06-15 11:04 UTC
Requires
- php: ^8.4
- psr/http-message: ^2.0
- psr/http-server-middleware: ^1.0
README
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 |