Re: Firing and handling events
Posted: Tue Oct 05, 2010 10:35 pm
I meant -- why use an extension and why do you need the aggregate() function?Weirdan wrote:Christopher:VladSun wrote: [...] in order to implement the aggregate() function.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
I meant -- why use an extension and why do you need the aggregate() function?Weirdan wrote:Christopher:VladSun wrote: [...] in order to implement the aggregate() function.
Thanks, it did the trickWeirdan wrote:Vlad, there's a fork of runkit (that is actually being developed) available on github, with support for php 5.3. pecl install http://github.com/downloads/zenovich/ru ... -1.0.2.tgz should do the trick.
Christopher:VladSun wrote: [...] in order to implement the aggregate() function.
It's not clear for me yetChristopher wrote:... why do you need the aggregate() function?
I use this approach in order to have a fully pluggable modular system. Also, I like the idea of using events to intercept with method flows instead of explicitly overriding these methods.Jonah Bron wrote:What would be an application for an event system in PHP? This is new to me.
OKVladSun wrote:It's not clear for me yet![]()
Something like achieving runtime class inheritance (multiple)![]()
I was thinking of something much simpler (see my example)VladSun wrote:You said - "you may use composition vs. inheritance" and I respond with aggregation
It looks like a composition to me...Christopher wrote:I was thinking of something much simpler (see my example)VladSun wrote:You said - "you may use composition vs. inheritance" and I respond with aggregation
I can't get it. Can you elaborate, please.Christopher wrote:Have you also thought of inverting the process so instead in putting the fireEvent() calls between function calls -- you could register functions calls associated with events?
If you want people to be able to write "plugins" for your system. Or if you wanted to obfuscate your own code. (It makes the software more flexible but also more complex basically). It reverses dependencies.Jonah Bron wrote:What would be an application for an event system in PHP? This is new to me.
As mentioned above, it's especially useful for letting other developers extend the functionality of your code, without having to dig into the source.What would be an application for an event system in PHP? This is new to me.
So, so. The plugin is loaded into the "system" and *listens* for specific events. If an event is received, the plugin performs some actions and may alter the data passed in the Event, so it may change the way the "system" process this data. An event may in turn fire another event which is processed by the "system" by performing some additional actions.Jonah Bron wrote:That makes sense (I think). So, say you load some text file while the program is running, and you can setup an event called "beforeLoadFile" and maybe another called "afterLoadFile" so that a plugin can be fired when that happens. Is that a realistic example?
I think I understand what you mean by "reverses dependencies". Instead of your base code calling the plugin, the plugin sort of "inserts" itself into the base code through the event system. Is that right?
In what way would it alter the data, and how would that be helpful?VladSun wrote: If an event is received, the plugin performs some actions and may alter the data passed in the Event, so it may change the way the "system" process this data
Ah, so you're saying that the system can listen to events fired by a plugin?VladSun wrote:An event may in turn fire another event which is processed by the "system" by performing some additional actions.
Lets use this forum as an example. Perhaps we have an event onMessageSubmit().. being when we submit a post to a thread. Now, we could implement a BB parser plugin which would take the existing data the system passes through, and alters it to create the smilies, code tags, etc.Jonah Bron wrote:In what way would it alter the data, and how would that be helpful?VladSun wrote: If an event is received, the plugin performs some actions and may alter the data passed in the Event, so it may change the way the "system" process this data
No. The plugins listen for the events. Plugins may, or may not, also request additional events to be fired, however, it is usually the core system that fires the events that the plugins can attach themselves to.Jonah Bron wrote:Ah, so you're saying that the system can listen to events fired by a plugin?VladSun wrote:An event may in turn fire another event which is processed by the "system" by performing some additional actions.
Oh, so I didn't quite understand. By the nature of your example event, it sounds like you're saying that it's basically one event per HTTP request.John Cartwright wrote:Lets use this forum as an example. Perhaps we have an event onMessageSubmit().. being when we submit a post to a thread. Now, we could implement a BB parser plugin which would take the existing data the system passes through, and alters it to create the smilies, code tags, etc.
Not sure if you are asking or not, but...Oh, so I didn't quite understand. By the nature of your example event, it sounds like you're saying that it's basically one event per HTTP request.