Symfony2: Discussion on Before and After Methods for Controllers

There is a nice article written here about implementing some hooks for controllers right before and after processing the controller. This is ideal for RESTful APIs that would like to authenticate or provide execution of tasks for requests meeting certain criteria such as certain tokens on the parameters sent with the request.

There are several proposals to the solution, and really just reading the blog post and the github entry one can see the value on these approaches. There is even use of functional programming in php in one of the proposals. That is the use of closures to turn the controller and pass it as a closure with some pre- and after-logic details. There is also another approach that meets some demands in terms of checking the implementation of certain interfaces. The truth of the matter is that all of these approaches can be combined. That is the power of good design in PHP. Learning about these ideas and approaches is just what we are here for after all.

Leave a Reply

Your email address will not be published. Required fields are marked *