- b2evolution CMS Support Forums
- b2evolution Development
- A look into the future
- Feature requests and Feedback
- Re-write of plugin's event handling
1 balupton Aug 19, 2006 17:38
Hey, i've talked about this with Yabba, and decided i might as well post it here.
Atm grabbing the events from a plugin goes;
Load Plugin, Scan plugin's class for functions, remove any found functions that are not known events, and then keep the result.
I believe it should be done like so;
Have a variable inside the plugin called $events, which is like so;
$events = array ( 'SessionLoaded', 'another event', 'etc' );
And to get the events do the following;
Load Plugin, Use $Plugin->events
No checks to see if the plugin exists would be necessary, as the only 'problem' that could occur would be if that array contains a event that the plugin doesn't have, in which case a php warning would be displayed when the missing function is called, but this will only happen on developer setups, so on the base b2evo install it wouldn't matter, and a developer would prefer seeing a warning to know something went wrong than to just not register the event for that plugin.
So yeh thats the basic idea.
Heres some other ideas i have.
In the Plugins class, have it so when a event is being 'recorded/registered', what happens is this;
$Plugins->events = array (
array( 'event' => 'SessionLoaded', 'plugins' => array( 'gallery_plugin', 'another_plugin' ) ),
//another of the above
)
$Plugins->ref_events = array (
'SessionLoaded' = & $Plugins->events[0]
// this would be automatic
)
So plugins can easily register additional events, and the plugins class can easily fire events.
So events would become dynamic.
So am i a crazy man, or am i on to something?
We've talked already above the first case and decided, that there could be an extra event/method which provides the list of events and if this one is present, the tokenizer would not be used to detect them.
This would allow to bypass the tokenizer, but still keep the old behaviour.
About "Heres some other ideas i have. ": I don't see what's new about it?! We already store the list of available events and the associated Plugins, though in another way.