php - How to add new listener in the best way? -
i have project on zf 1.x , want use eventdispatcher symfony component. have 2 services user , topic. after success user authentication need activate user's topics. create event - authenticationevent , fire event after authentication in user service this
$dispatcher->dispatch('user.authentication.success', new authenticationevent($user));
but need add listener? code looks like
$listener = new topiclistener(); $dispatcher->addlistener('user.authentication.success', array($listener, 'onauthenticationaction'));
i had method authenticate in user service , there code lines calling method activate($user) activate topics in success case of authentication. whereupon had coupling between user , topic service. why decided use eventdispatcher.
so best place adding listeners? in bootstrap part of code?
i don't know zf. must add listener before dispatch event.
has "bootsrap" file? add listener there (or in front controller).
Comments
Post a Comment