SimpleExtension, like Extension but with more Magic

This commit is contained in:
Shish 2009-05-11 14:08:32 -07:00
parent 6a5b8bd46d
commit 8dd3f8cbc0
2 changed files with 30 additions and 0 deletions

View file

@ -6,6 +6,26 @@ interface Extension {
public function receive_event(Event $event);
}
/*
* BlahEvent -> onBlah
*/
abstract class SimpleExtension implements Extension {
var $theme;
var $_child;
public function i_am($child) {
$this->_child = $child;
if(is_null($this->theme)) $this->theme = get_theme_object($child, false);
}
public function receive_event(Event $event) {
$name = get_class($event);
$name = "on".str_replace("Event", "", $name);
if(method_exists($this->_child, $name)) {
$this->_child->$name($event);
}
}
}
/*
* Several extensions have this in common, make a common API

View file

@ -52,6 +52,16 @@ try {
}
// initialise the extensions
foreach(get_declared_classes() as $class) {
if(is_subclass_of($class, "SimpleExtension")) {
$c = new $class();
$c->i_am($c);
add_event_listener($c);
}
}
// start the page generation waterfall
$page = new Page();
$user = _get_user($config, $database);