Hi all, I am using lots of tasks and they are parts of plugins. I would like to expand functionality of them using Observer pattern -> Events.
Problem is that: When I run the task number of listeners is doubled so each function is running twice! example: ------------------- | myMajorPlugin | ------------------- // myMajorPlugin/config/myMajorPluginConfiguration.class.php: class myMajorPluginConfiguration extends sfPluginConfiguration { public function initialize() { $this->dispatcher->connect('task.import.finish', array('myMajorListener', 'listenToTaskImportFinishEvent')); } } // myMajorPlugin/lib/listener/myMajorListener.class.php: class myMajorListener { static public $num = 0; static public function listenToTaskImportFinishEvent(sfEvent $event) { // action 1 echo "\nMajor: " . ++self::$num . "\n"; } } // myMajorPlugin/lib/task/productItemimportTask.class.php: //[...] protected function execute($arguments = array(), $options = array()) { // some action $this->dispatcher->notify(new sfEvent($this, 'task.import.finish')); } ----------------------- | myExtensionPlugin | ----------------------- // myExtensionPlugin/config/myExtensionPluginConfiguration.class.php: class myExtensionPluginConfiguration extends sfPluginConfiguration { public function initialize() { $this->dispatcher->connect('task.import.finish', array('myExtensionListener', 'listenToTaskImportFinishEvent')); } } // myExtensionPlugin/lib/listener/myExtensionListener.class.php: class myExtensionListener { static public $num = 0; static public function listenToTaskImportFinishEvent(sfEvent $event) { // action 2 echo "\nExtension: " . ++self::$num . "\n"; } } Now when I run task: > ./symfony product:item-import it is displaying: > Major: 1 > Extension: 1 > Major: 2 > Extension: 2 It shows that each function runs twice but should only once. In addition if I put code from above to task's execute() function: print_r($this->dispatcher->getListeners('task.import.finish'); Now when I run task I see: Array ( [0] => Array ( [0] => myMajorListener [1] => listenToTaskImportFinishEvent ) [1] => Array ( [0] => myExtensionListener [1] => listenToTaskImportFinishEvent ) [2] => Array ( [0] => myMajorListener [1] => listenToTaskImportFinishEvent ) [3] => Array ( [0] => myExtensionListener [1] => listenToTaskImportFinishEvent ) ) I did a research and found that problem is not new: 1. http://trac.symfony-project.org/ticket/7948 2. http://groups.google.com/group/symfony-users/browse_thread/thread/e7a27d65e4436692/fd59ac0bdbc56ae1?hl=en&lnk=gst&q=Event+Dispatcher+connect+twice+times+same+function+to+same+event#fd59ac0bdbc56ae1 Examples are not showing situation when you are using own events but only built into symfony like here: http://www.symfony-project.org/jobeet/1_4/Propel/en/20#chapter_20_sub_the_user Little help please Thanks, Bogumil -- 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 users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en