In an effort to keep our controllers thin, and to maintain our sanity as our projects grow larger, it becomes increasingly more important to shift logic out of our Symfony Controller and into a designated Handler class.
The idea behind our Handler class is that we want to abstract the whys and wherefores of where our data is actually coming from. Ultimately it's not the Controller's job to care about such things. So we pass the responsibility over to a specific Handler class which implements a common Handler interface.
At first this looks like you're creating way more code to handle (ahem, no pun intended) quite a simple task. And there is some truth to that. Really this methodology only starts to show its benefits as your projects grow - which they always seem to do in the real world, if the project is making money for the business.
This is really laying the foundations for the rest of our project. All our end points will use and re-use the various Handlers that we create, and in doing so, we can keep our code DRY and ensure shared logic only ever exists in one place.
By the end of this video you will have gained a good understanding of how to structure a real world RESTful API project in Symfony 2 using the FOS REST Bundle.
If you have found this video helpful, please consider sharing. I really appreciate it.
|3||GET Handled, thin Controllers and fun with Services||17:49|
|4||Automatic Route Generation||11:32|
|5||GETting a Collection||12:53|
|7||Acceptance Testing our POST Method||05:40|
|8||Unit Testing our Symfony Form||22:55|
|9||Implementing and Testing the Form Handler||03:01|
|10||POST Form Handler Implementation||11:12|