Today we are going to look at StackPHP and try to understand what this thing is all about. Although this post will have some code, this article will be rather theoretical as we are interested in learning what StackPHP actually is, where it comes from and why it is useful.
As the front page of the StackPHP project says, Stack is a convention for composing HttpKernelInterface middlewares. But, in order to actually understand this definition, we will have to cover a few concepts first. At the end, we will also illustrate the concepts we learned in the context of StackPHP with some example code. This usually makes things much easier to understand.
In the last part when you demonstrate the pushing to the stack, I get a bit confused by the terminology. You push 3 Kernels to the stack but conclude to push Middlewares. What is right here? As far as I ahve seen it from Laravel 5 you provider Middlewares which are then handled by the Kernel. I could be wrong though.
In broad strokes, an HTTPKernelInterface implementation is what a Middleware is in this case. So basically any class that respects the StackPHP “rules” (convention) - is a stackable middleware.