Talking JSON in Symfony2, like really!
A while ago I posted about some issues I ran into trying to use 3rd party controllers as well as in my own controllers when supporting multiple output formats. I was dreaming of a world where the controllers could for the most part be totally oblivious to how they would be rendered. I have been talking to Jordi for a while now about adopting an "Agavi-Light" approach by adding a simple view layer that would enable users to easily support different formats without having to mess with their controllers yet still being able to handle stuff like redirects, encoding to JSON, XML or generating PDF's or images. After an intensive work session which lasted about 5 hours (thank you Liip for hackday budget to do this sort of stuff on company time) plus a much deserved lunch break we had pushed the results on to github.
I am very happy with the outcome. I think we struck a good balance between useful out of the box functionality, no additional complexity for beginners. Furthermore even for advanced use cases people can get away with no additional code. For even more specialized use cases we offer the option of adding additional handlers via callbacks or by extending the view layer. Via the DI developers can of course also simply replace our implementation. Finally for those people who do think the view layer is too much overhead, they can also easily by pass it entirely and work just like they did before.
I would really appreciate feedback as I would love to see this make it into upstream in time for the PR4 which is aimed for next week. Jordi and I are prepared to write documentation and tests of course. Not sure when PR4 will hit exactly, but maybe we can iron out the last details at the next Symfony2 IRC meeting. Speaking of which, still need to write the summary for the last meeting (until another volunteers steps forwards ASAP *wink wink*).