Re: Events, multiple listeners, and return data
Yes, it certainly helps to understand your reasoning. On May 14, 9:50 pm, José Lorenzo jose@gmail.com wrote: If you think about it, collecting return values is actually the edge case: A save operation has a single result wich is data to be saved A redirect operation has a single result, the URL to redirect to A dispatching operation has a single response value as result There a very few cases where collecting the result is desired, an it is often the consequence of a wrong software design. If you want to collect return, pass an object as parameter and have listeners modify this object at will. An example of this type of callbacks is JavaScript, an events language, wich usually don't take in account result values for events but 'false'. If you want to alter any result you should be modifying an object. I hope my answer helps understand the resonance we had for making the event system work this way. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Events, multiple listeners, and return data
I'm wondering if anyone else has come across this: I have a situation in which I'm dispatching an event with 2.1's event system, and have multiple listeners for that event. Each listener returns its own set of data, with the idea being that all of the returned data is compiled into one set (in this case, it's for displaying admin navigation in a CMS). However, it seems that CakeEventManager overwrites the return data in each iteration of the loop over the listeners: foreach ($this-listeners($event-name()) as $listener) { ... if ($listener['passParams'] === true) { $result = call_user_func_array($listener['callable'], $event-data); } else { $result = call_user_func($listener['callable'], $event); } ... if ($result !== null) { $event-result = $result; } continue; } I would expect $event-result to be a multidimensional array, but nope, it just gets overwritten. Has anyone else come across this issue? Am I just missing a really obvious way to get data from multiple listeners for the same event? - Jamie -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Events, multiple listeners, and return data
Basically you have two options, one is writing the result property directly on each listener to push new values on the array as needed, wich is the option I would recommend. The other option is to use the ObjectCollection instead of the event sustem and pass the collectReturn param -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Events, multiple listeners, and return data
Thanks. Just curious - why is the result data overwritten in this way? For me, at least, using the event system to get information from multiple listeners (as in my situation) was one of the first uses I thought of, especially since it can replace a bunch of custom stuff I had written previously. It seems a bit odd not to handle return data from multiple listeners without resorting to the methods you outlined below. On May 14, 3:58 pm, José Lorenzo jose@gmail.com wrote: Basically you have two options, one is writing the result property directly on each listener to push new values on the array as needed, wich is the option I would recommend. The other option is to use the ObjectCollection instead of the event sustem and pass the collectReturn param -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
Re: Events, multiple listeners, and return data
If you think about it, collecting return values is actually the edge case: A save operation has a single result wich is data to be saved A redirect operation has a single result, the URL to redirect to A dispatching operation has a single response value as result There a very few cases where collecting the result is desired, an it is often the consequence of a wrong software design. If you want to collect return, pass an object as parameter and have listeners modify this object at will. An example of this type of callbacks is JavaScript, an events language, wich usually don't take in account result values for events but 'false'. If you want to alter any result you should be modifying an object. I hope my answer helps understand the resonance we had for making the event system work this way. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php