Can we use PSR-15 for Middlewares? #130
Replies: 4 comments 4 replies
-
@leonhusmann thanks for bringing this up 👍 This is indeed something we have in mind for Framework X. Before we added our Fiber support we always had to return a promise instead of the actual value behind it. This is actually against PSR-15 which requires a The implementation behind this is not that big, the most work will be the documentation. I hope this gives you some insights into our plans 🚀 |
Beta Was this translation helpful? Give feedback.
-
What's the status of this request? |
Beta Was this translation helpful? Give feedback.
-
FYI: If you want to use existing PSR-15 Middlewares you could write a simple adapter like: final class MiddlewareAdapter {
public function __construct(private readonly MiddlewareInterface $wrapped) {
}
public function __invoke(ServerRequestInterface $request, callable $next): ResponseInterface
{
$handler = new class(Closure::fromCallable($next)) implements RequestHandlerInterface {
public function __construct(private readonly Closure $next) {}
public function handle(ServerRequestInterface $request): ResponseInterface {
return ($this->next)($request);
}
};
return $this->wrapped->process($request, $handler);
}
} And use it like this: $app = new App(new MiddlewareAdapter($somePsr15Middleware)); It would be great if that work around wasn't required though :) |
Beta Was this translation helpful? Give feedback.
-
I just realized, that this topic was brought up with #185 too (maybe those threads can be merged?) |
Beta Was this translation helpful? Give feedback.
-
Hi, thanks for working on this very interesting framework!
I like how you stick to PSR-7 for your Requests and Responses. The community definitely benefits from those standards. That's why I wonder why you decided not to go for PSR-15 for your Middlewares. Is there any technical reason or just personal preference?
Best regards, Leon
Beta Was this translation helpful? Give feedback.
All reactions