-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question - Best way for modules to attach listeners #7
Comments
Good question. I resolve it by creating module for that: https://github.com/snapshotpl/ZfConfigListener Originally posted by @snapshotpl at zendframework/zend-eventmanager#40 (comment) |
So your module is kind-of a mix and matches of the options I described This is nice but you are limiting yourself to services defined in the service_manager Thank you for your input though I am going to use it to build the perfect solution for me Originally posted by @cgaube at zendframework/zend-eventmanager#40 (comment) |
There is a big problem with delegators with zend-eventmanager >= 3.0. The event manager in classes that implements The If you want to use delegators, you should be sure that a complete event manager with the shared event manager is injected in the object. Originally posted by @thomasvargiu at zendframework/zend-eventmanager#40 (comment) |
This is what I was planning to do anyway, because like you said, the SharedEvent Manager is not injected to any event manager by default anymore - See my first comment
Doing so allow you to have full control on the event manager
Originally posted by @cgaube at zendframework/zend-eventmanager#40 (comment) |
Why would you use another SharedEventManager instance for your service? You can do something like this with zend-mvc: $userForm = new UserForm();
// zend-mvc defines the 'EventManager' not shared, creating a new EventManager each time
$eventManager = $container->get('EventManager');
$userForm->setEventManager($eventManager); For libraries without zend-mvc I would suggest something like this: $userForm = new UserForm();
// zend-mvc defines the 'SharedEventManager'
$sharedEventManager = $container->has('SharedEventManager') ? $container->get('SharedEventManager') : null;
$eventManager = new EventManager($sharedEventManager);
$userForm->setEventManager($eventManager); In this way you can use the default SharedEventManager, using the identifiers. Originally posted by @thomasvargiu at zendframework/zend-eventmanager#40 (comment) |
Probably because I did not know/check that zend-mvc was defining a service called "EventManager" that was automatically inject the default SharedEventManager. This is why I opened that discussion - I am trying to understand what would be the best way to do it
I could also have another separate ShareEventManager for my Models Is this method overkill ? Should I just attach all my listeners to the default SharedEvent manager ? Originally posted by @cgaube at zendframework/zend-eventmanager#40 (comment) |
It's just my opinion. Originally posted by @thomasvargiu at zendframework/zend-eventmanager#40 (comment) |
Hello
First my apologies if this is not the right place to ask questions.
Please let me know if there is a better place -
Thank you
Here is my issue
I was wondering what would be the best way to attach listeners to an Event Manager from a Different Module
Here is my scenario, I have a user form lets call it Application\UserForm
In its class factory I inject an Event Manager and a Shared Event Manager
factory:
What is the Best way for another module (lets call it Module X) to attach its listener to this Form (and any other forms really that use the same FormSharedEventManager ) ?
Here are my choices
Delegators
I could add Delegators in the Module X Config
Option 1: at the UserForm level
--> so that everytime UserForm is created My delegator class would fetch the event manager and directly attach listeners
Option 2
-> Same idea but at the shared event manager level
Everytime FormSharedEventManager is created i would attach the listeners
(That also allow me to use the identifiers )
Config file parameters
Option 3:
i could create a new config parameter
And I would have a to use a new Factory to create FormSharedEventManager
My new Factory (AggregateAwareSharedEventManagerFACTORY)
Would then fetch all the listeners aggregates from the "shared_event_manager_listers" config attached to the requested class (FormSharedEventManager::class)
I want to use the fastest or cleanest way to attach those listeners
Ideally the Module would also add listeners to other part of the process
Pros and Cons
Option 1:
Option 2:
Option 3:
Need to create new parameter in the config, Need to create a new factory
Ideally Module X would also want to listen to other events like Controller Events
For e.g When a user submit the form Module X will want to send an email
Would it be smarter to Inject the default Shared Event Manager into my Form instead of creating a new FormSharedEventManager
and attaching the listeners into the Default shared event manager ?
Originally posted by @cgaube at zendframework/zend-eventmanager#40
The text was updated successfully, but these errors were encountered: