currently I’m working with Symfony2 and it is an awesome framework.
I worked with SpringMVC and it has the concept of “interceptor” which catches requests to any “controller” and allows to make, for example, checks too know if user is logged.
Is there any annotation of router way to do something similar with Symfony2.
Thanks in advance.
You can attach event listeners to respond to a framework event. Take a look at:
http://symfony.com/doc/current/cookbook/service_container/event_listener.html
There are a number of events you can subscribe to, all of them available on the docs:
http://api.symfony.com/2.1/Symfony/Component/HttpKernel/KernelEvents.html
Probably you are looking for the REQUEST event, it should look something like:
And on services.xml:
You define the event you are listening to with
And the arguments injected into the __construct() method (see http://symfony.com/doc/current/components/dependency_injection/introduction.html) with: