@@ -42,11 +42,11 @@ zenpipe(100)
4242 - [ Class Methods as Operations] ( #class-methods-as-operations )
4343 - [ Context Passing] ( #context-passing )
4444 - [ Exception Handling] ( #exception-handling )
45+ - [ PSR-15 Middleware] ( #psr-15-middleware )
4546 - [ More Examples] ( #more-examples )
46475 . [ API Reference] ( #api-reference )
47486 . [ Contributing] ( #contributing )
48497 . [ License] ( #license )
49- 8 . [ Roadmap] ( #roadmap )
5050
5151## Requirements
5252
@@ -239,6 +239,52 @@ The catch handler receives:
239239
240240If no catch handler is set, exceptions propagate normally.
241241
242+ ### PSR-15 Middleware
243+
244+ ZenPipe provides bidirectional PSR-15 middleware support. Requires ` psr/http-server-middleware ` .
245+
246+ #### Using PSR-15 Middleware in a Pipeline
247+
248+ Pass any ` MiddlewareInterface ` directly to ` pipe() ` :
249+
250+ ``` php
251+ $response = zenpipe($request)
252+ ->pipe(new CorsMiddleware())
253+ ->pipe(new AuthMiddleware())
254+ ->pipe(fn($req, $next, $return) => $return(new Response(200)))
255+ ->process();
256+ ```
257+
258+ When using PSR-15 middleware, the pipeline must return a ` ResponseInterface ` .
259+
260+ #### Using ZenPipe as PSR-15 Middleware
261+
262+ Wrap a pipeline with ` asMiddleware() ` for use in PSR-15 frameworks:
263+
264+ ``` php
265+ $pipeline = zenpipe()
266+ ->pipe(fn($req, $next) => $next($req->withAttribute('processed', true)));
267+
268+ $app->middleware($pipeline->asMiddleware());
269+ ```
270+
271+ ** Behavior:**
272+ - If the pipeline returns a ` ResponseInterface ` , it's returned directly
273+ - If the pipeline returns a ` ServerRequestInterface ` , it's passed to the next handler
274+ - The PSR-15 handler is available via ` $context->handler ` for explicit delegation
275+
276+ ``` php
277+ $authPipeline = zenpipe()
278+ ->pipe(function ($req, $next, $return, $ctx) {
279+ if (!$req->hasHeader('Authorization')) {
280+ return $return(new Response(401));
281+ }
282+ return $ctx->handler->handle($req);
283+ });
284+
285+ $app->middleware($authPipeline->asMiddleware());
286+ ```
287+
242288### More Examples
243289
244290#### RAG Processes
@@ -325,5 +371,3 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
325371## License
326372
327373The MIT License (MIT). See [ LICENSE] ( LICENSE ) for details.
328-
329- ## Roadmap
0 commit comments