Add In The Ability To Do Rack-Like Middleware?

I’ve been looking at the idea of middleware from Ruby’s Rack setup and have been wondering if it would be beneficial to add to Yii 2.

More info about Rack here:

http://ofps.oreilly.com/titles/9780596521424/rack.html

Some thoughts on implementing a similar setup in Symfony 2:

https://igor.io/2013/02/02/http-kernel-middlewares.html

Seems like we’ve got the rudiments of handling this type of setup using before/afterRequest events in Yii, but that the Rack setup is more developed (and advanced) and allows for injecting an event handler (in Yii parlance) at a certain point in the stack.

https://github.com/yiisoft/yii2/blob/master/framework/yii/base/Application.php#L186-193

Github recently used an addition to their Rack middleware as a way to implement additional security checks on cookies. Seems like the real value of an addition like this would be for retrofitting an application with additional features once it’d already grown fairly large.

Interested any your thoughts …

How is this related to yii? As far as I understood rack sits between webserver and ruby. This would be between webserver and php in our case but yii is on the php side.

Can you explain what you expect from this or how it would look like?

Regarding this, sorry took so long to respond. I’ve thought about it more and you’re right, by and large Rack is rebuilding the webserver we already use.

However, I think the one thing I like about Rack that we’re currently missing in Yii is the ability to specify where in the request stack an app behavior is loaded. I’m working on a project now that uses multiple app behaviors and (although I don’t have this problem at the moment) it might be nice to be able to specify which behavior gets loaded first.

Does that already happen just by the location in the behaviors array for the app? Haven’t actually checked …

Thinking about it further, this may be a solution in search of a problem :wink:

Yes that is exactly how it works, they are loaded in the order they are defined.