fabpot/Silex — pull request #277 by chrismsnz (2012-03-11 22:48:42+00:00)
Title: Show route middlewares using DI container in the documentation

When implementing route middleware for my application, I found it very useful to store the middleware callable in the Silex application DI container. That way it was available everywhere that a route may be defined e.g. a Controller Provider.

The reason I think this should be documented is it wasn't immediately apparent to me, but after implementing this way a lot of problems ceased to exist as opposed to the documented method that uses a variable to store the closure.

Also has a small gotcha that you have to protect the closure or the DI container will attempt to execute it when accessed.

This PR contains a small change to the documentation changing the example to store the middleware within the application object and a small note as to why you may want to do it.

Feel free to use it or not, I just found it useful in my project!