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 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 from


After 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: util.inc.patch (Ticket #360) to allow get_theme_object to skip non-existing base themes. Patch incorporated into core.

No comments:

Post a Comment