Middlewares approach is used in Java web apps for years. After being adopted well in JavaScript server frameworks recently and acceptance of PSR-7 it starts its raise in PHP community.
Yes, you got it right. It’s a bare thing which is getting request and response references and could do something with these. $next thing for passing processing to other middlewares. It could be read as $allOtherMiddlewaresDoSomethingWith($request, $response).
This would mean that the people who prefer the Laravel approach (Slim, Express.js, etc.) to routing could just plug in their favorite routing middleware and have the cake while eating it
I’ve been using middlewares (mostly for APIs), there are cons and pros, but overall, our team love the middleware approach. It makes development more simple and transparent
Are middlewares really that important? I mean we can use Yii2 Core Filters and beforeAction() to achieve anything that needs to run before an action. I find that to be much simpler than using a different class to control a certain controller for example.
Are there any important use cases for middlewares that are currently holding us back from achieving the same goal in Yii2?
Not really. Filters are, in fact middlewares. Just Yii-specific ones. It makes sense to introduce PSR middlewares because we’ll be able to use existing third party code.
So using middleware, for instance feeding something to the View object before the controller is loaded, such as navigation from the DB, can that be implemented using Yii now or would a new application layer need to be created first? If it can be, what would be an an example of it?