puff / pipeline
Lightweight container-aware pipeline for Puff
Requires
- php: ^8.2
- psr/container: ^2.0
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.0
This package is auto-updated.
Last update: 2026-08-27 13:44:17 UTC
README
Lightweight, framework-independent pipeline with optional PSR-11 service resolution.
$result = (new Pipeline($container)) ->send($request) ->through([ Authentication::class, static fn ($request, $next) => $next($request), ]) ->then(static fn ($request) => $controller($request));
send() and through() return cloned pipeline instances. A configured pipeline can therefore be reused safely by concurrent Fibers without sharing the current passable or stage list.
Stages
A stage may be:
- A Closure or another callable.
- An invokable object.
- An object exposing a public
handle()method. - A PSR-11 service name resolving to any of the above.
Each stage receives the passable followed by the next Closure:
final class Authentication { public function handle(Request $request, Closure $next): mixed { return $next($request); } }
String stages support a small comma-separated parameter syntax:
Authentication::class . ':admin, enabled'
The stage receives admin and enabled as trimmed strings after the next Closure. Commas and colons cannot be escaped; use a configured object or Closure for structured parameters.
A stage may return without calling $next to stop the pipeline. Exceptions are not intercepted and propagate to the caller. send() must be called before then().
Pipeline instances are Fiber-safe, but stateful stage objects must still be scoped per Fiber or implement their own synchronization.