Re: Minimal HTTP middleware

2017-04-21 Thread Matthieu Napoli
> > > This is Symfony's HttpKernelInterface and StackPHP and it has already > been discussed at length > > Same principle, yes, but what I recall being discussed at length was the > lambda-style vs double-pass aspect, which seems unrelated to this > discussion. > > I found one or two older thre

Re: Minimal HTTP middleware

2017-04-21 Thread Rasmus Schultz
> Since it is impossible to enforce constructors via interface this will mean inspecting each middleware to determine the correct parameter That problem is not specific to middleware though. You're just describing a general problem in dynamic languages, for which you can either use an IDE (or oth

Re: Minimal HTTP middleware

2017-04-21 Thread Rasmus Schultz
> This is Symfony's HttpKernelInterface and StackPHP and it has already been discussed at length Same principle, yes, but what I recall being discussed at length was the lambda-style vs double-pass aspect, which seems unrelated to this discussion. I found one or two older threads on this subject,

Re: Minimal HTTP middleware

2017-04-21 Thread Woody Gilk
Rasmus, I get where you are coming from here. On the one hand it makes a lot of sense and *appears* to greatly simplify things. However, I'm not sure that it really does in the long term. Creating a dependency graph of middleware complicates things significantly at the injection level. We go from

Re: Minimal HTTP middleware

2017-04-21 Thread Matthieu Napoli
Hi, This is Symfony's HttpKernelInterface and StackPHP and it has already been discussed at length, I'm not sure why we are starting it all again? Matthieu Le vendredi 21 avril 2017 17:42:11 UTC+2, Rasmus Schultz a écrit : > > I hate to do this at a time when the middleware PSR is probably clos

Re: Minimal HTTP middleware

2017-04-21 Thread Rasmus Schultz
Hi Michael :-) > As a handler objects holds a reference to the next handler object, it is not reusable anymore. Well, the instance itself isn't "reusable" - but the code is, that's what matters, isn't it? > you will create multiple instances of you middleware – even if your middleware is just an

Re: Minimal HTTP middleware

2017-04-21 Thread Michael Mayer
What you're proposing is known as a variant of the Chain of Responsibility Pattern – it's a GangOfFour-Pattern; hence should be well known. Calling it Middleware disregards the fact that the Middleware pattern is known as a Func

Re: Minimal HTTP middleware

2017-04-21 Thread Rivera, John
That makes sense — my view of middleware is more broad than that; it’s the application layer between the front end and the back end (domain) that controls access to the backend and how the data is conveyed to the front end. Hence ‘middle’ in the name :) But your interpretation is just as valid,

Re: Minimal HTTP middleware

2017-04-21 Thread Rasmus Schultz
I'm sorry, I don't really follow this explanation at all. The purpose of middleware, as I understand it, is a means of structuring the processing of HTTP requests into discrete (reusable) units. Authenticating a user is probably a domain concern. Uploading or viewing a blog post are definitely d

Re: Minimal HTTP middleware

2017-04-21 Thread Rivera, John
Sure — here’s an example. Let’s say you have a UploadBlogPost and a ViewBlogPost request. Let’s say the UploadBlogPost request takes an unique id and the post’s body and sticks it into a database. And let’s say ViewBlogPost takes an id, and returns the blog post associated with that id. The Up

Re: Minimal HTTP middleware

2017-04-21 Thread Rasmus Schultz
I'm not sure what you mean by "fine-grained" middleware? This "fine-grained" middleware performs request-to-response processing the same as "general" middleware - they have the same method signature. This is pretty abstract, so can you support this point of view with code-samples or scenario/use-

Re: Minimal HTTP middleware

2017-04-21 Thread Rasmus Schultz
> How would the container know which $kernel to use in the constructor for the object at $id? This looks nice, API-wise, but it is ignoring how this object would actually be constructed. Of course this "skips the constructor part", that's what the DI container is for - if you're using one, that's

Re: Minimal HTTP middleware

2017-04-21 Thread Rivera, John
This is exactly how I handle most of my middleware as well — I have a project that uses the CQRS architectural pattern, and I decorate each command handler using this exact pattern. I build the dependency graph in my dependency injection container, and use a mediator to dispatch commands to the

Re: Minimal HTTP middleware

2017-04-21 Thread Beau Simensen
On Friday, April 21, 2017 at 10:42:11 AM UTC-5, Rasmus Schultz wrote: > > > $kernel = new NotFoundMiddleware(); > $kernel = new RouterMiddleware(new Router(...), $kernel); > $kernel = new CacheMiddleware($kernel); > $kernel = new ErrorHandlerMiddleware(); > > Off the top of my head, it feels like

Minimal HTTP middleware

2017-04-21 Thread Rasmus Schultz
I hate to do this at a time when the middleware PSR is probably close to finished, but since this occurred to me, I can't shake the thought, and so I have to bring this up, so that at least others are aware and informed about this option with regards to middleware. I think I saw some framework