-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Middleware #1
Comments
Thanks for this feature request! Good question, not sure yet whether middleware has a place in this project or not. As you may have seen, this project is intended to be super lightweight and simple, positioning it somewhere between plain PHP and complex frameworks. But middleware may really be important to many people. Great that you have found a way to add middleware yourself with minimal code and a modular approach. That approach doesn't look that bad! Are these other middleware libraries incompatible with this project because we don't have HTTP message interfaces as defined in PSR-7 here? Might be another idea then to add those message interfaces, at least optionally, so that middleware libraries work here. What do you think? |
Thanks for considering this. I agree that middleware is not necessary for many projects, and may add much complexity. Perhaps it fits into an optional module (e.g. "PHP-Middleware"). The popular middleware libs I investigated did seem to use PSR-7 interfaces; they are structured around passing through HTTP requests and responses. However, I fail to see an elegant place to share data between layers. Maybe I'm missing some key understanding of that architecture. One advantage of implementing PSR-7 is being able to reuse prewritten middleware. Some examples: |
(however, I now see that these prewritten middleware require significant dependencies) |
Do they? As for "Relay", this repository seems to contain the actual core, while the other one seems to just contain some exemplary pieces of middleware, right? Again, this other repository is just a collection of exemplary pieces that can be used. For the three repositories mentioned so far, what we'd need, judging from their Doesn't look too bad, does it?
Yes, optional would be perfect. Because right now, almost everything in this project is optional. It basically just bootstraps several components, options and directives for you but then does not force any particular coding style on you, which means you're free to choose one yourself.
The documentation for "Relay" is here. It does look similar to your implementation. Might be worth finding out about the major differences between your quick implementation and these dedicated libraries then.
Definitely a huge advantage! |
Maybe I'm not understanding
I should clarify: the PSR-7 request/response interfaces only provide http header/body information which doesn't seem extremely useful to pipe through a series of middleware layers. However, since they are merely interfaces, anything else can be added to their instances (including the global
It seems like the biggest difference is what data gets passed to the handlers (as mentioned above). Their choice of a queue vs my choice of a stack is trivial. |
100% correct! It's generally up to them how they use the "suggested" dependencies exactly, but they're usually required for some parts, at least. The core of "Relay" has no such requirements, however. It's just the pieces of middleware that you may re-use. So you have to import some dependencies for some of them, which makes sense, depending on what they do.
Right. You may add something to your response's body or headers in some layers via the implementations of the PSR-7 interfaces, though. Apart from that, we could certainly add the And that's what you hoped to get from the existing middleware as well: compatibility. So it's best if everyone just uses the PSR-7 interfaces. If that's possible. Everything on top of that just prevents easy re-use between implementations. |
Good point about reuse. I suppose simple HTTP header/body data would be suitable for many middleware implementations. In terms of OOP, each layer could take what it needs from |
Hello
This framework is really great and I am very glad to be using it.
However, one feature that I think might be missing is middleware. I have managed to implement a very simple solution, but it is kind of sloppy. Here is an example of my implementation:
It may not be pretty but it works. I was wondering, do you think such features have a place in this framework? Or perhaps you prefer another solution or library? It seems like relayphp isn't appropriate for use with this framework, and the other middleware libs are also tailored for other frameworks...
The text was updated successfully, but these errors were encountered: