Le 17/05/2011 01:14, renegare a écrit :
Hey, just got my head around how to setup an event listener via the
configuration:

services:
     my_listerner_service_name:
         class: Namespace\For\My\Listener\CustomListener
         tags:
             - { name: kernel.listener, priority: 0 }

Then you need to create your class (Namespace\For\My\Listener
\CustomListener) with a 'register' method.
The register method was the old implementation. Please update to the current one.
But I'm thinking (magento experience) this could be simplified.
Configuration could simply be this:

listeners:
     event_name_sting:
         class: Namespace\For\My\Listener\CustomListener
         method: observe
         singleton: true
         priority: 0

There will be a class/bundle that knows how to compile this, but the
logic is simply, when the event 'event_name_sting' is dispatched, the
class Namespace\For\My\Listener\CustomListener is initiated and the
method 'observe' (which has only one argument - Event object) is
called.

Note: the singleton parameter, should give added functionality so the
listener created should be kept in memory and not recreated if it were
to be called again for another event ... possibly through another
method.

What you guys think ... or can already be done?

M.
The issue with your proposal is that all listeners would have to be registered in the configuration of the ListenerBundle. And other bundles *cannot* change this configuration so all listeners would have to be registered by the end-user. This does not make any sense. Thus, as soon as your listener needs to observe several events or have dependencies, you need to use a service to reuse the listener and inject the dependencies. This cannot be done with your proposal.

Tags are what is needed here: the FrameworkBundle needs to be able to get all listeners to register them in the event dispatcher, whatever bundle they come from.

--
Christophe | Stof

--
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to