Simple Extension functionality was imported into Shimmie core earlier this week. If you have this extension active, PHP will complain that you can't define SimpleExtension twice.
There were some changes during the import due to some problems with the Shimmie forum (broke during upgrade to phpBB3) and Shish ended up re-implementing it in core rather than performing a true import.
Unlike my version, which merely forwarded execution to functions of the same name as the event, this implementation prepends "on" and removes the trailing "Event." So an event PageRequestEvent will call a function onPageRequest.
This method, however, removes the need for the acrobatics my version was performing to prevent the forwarding from calling the receive_event and new i_am functions. The event_method_callable function is thus not needed and was not used.
I have not yet updated the source of my extensions that used this, though Shish has already made most (if not all) of the core and core-maintained extensions use it.
Showing posts with label shimmie.SimpleExtension. Show all posts
Showing posts with label shimmie.SimpleExtension. Show all posts
Saturday, May 16, 2009
Thursday, November 06, 2008
Shimmie Extension - Simple Extension
Got tired of defining Event::receive_event when making a new extension, and got tired of starting to code in the if statements, "Oh, it's just a little bit of code..." and then an hour later: "Crud. It's like, three pages long and 5 tabs deep now," and spend the next few days refactoring code.
Anyway, there's the inspiration. A few weeks ago I had thought that it would be easier to have an XML file control the event hooking, like WoW does, but that got kind of silly when I realized that the control would be split across the XML and extension code, and I'd have to figure out the XML DOM. Then I realized that the most basic use of the thing would essentially be exactly the same across extensions, I dropped it.
So today, I decided it wouldn't be too much of a loss if I defined the function once in such a manner that it gets the class type of the incoming event, looks for a function of the same name in the extension class, and calls that (passing the event along, of course.)
So there. Simple Extension creates another abstract of the Extension class, and does just that, as well as make the theme object, and so far it seems to work pretty well.
To use, install by uncompressing the archive into
After that, make a new extension, but instead of "
GitHub repository
Commit at time of post: 13434a2c
Dependencies:util.inc.patch (Ticket #360) to allow get_theme_object to skip non-existing base themes. Patch incorporated into core.
Anyway, there's the inspiration. A few weeks ago I had thought that it would be easier to have an XML file control the event hooking, like WoW does, but that got kind of silly when I realized that the control would be split across the XML and extension code, and I'd have to figure out the XML DOM. Then I realized that the most basic use of the thing would essentially be exactly the same across extensions, I dropped it.
So today, I decided it wouldn't be too much of a loss if I defined the function once in such a manner that it gets the class type of the incoming event, looks for a function of the same name in the extension class, and calls that (passing the event along, of course.)
So there. Simple Extension creates another abstract of the Extension class, and does just that, as well as make the theme object, and so far it seems to work pretty well.
To use, install by uncompressing the archive into
contrib/ and activate by creating a symlink in ext/ to contrib/!simple_extension or by using the Extension Manager. Until a dependency resolution system is created, removing the exclamation mark fromAfter that, make a new extension, but instead of "
class hello_world implements Extension" use "class hello_world extends SimpleExtension" and then write methods like this to use events:
public function PageRequestEvent(Event $event) {
// PageRequestEvent code here
}
GitHub repository
Commit at time of post: 13434a2c
Dependencies:
Subscribe to:
Posts (Atom)