SimpleExtension, like Extension but with more Magic
This commit is contained in:
parent
6a5b8bd46d
commit
8dd3f8cbc0
2 changed files with 30 additions and 0 deletions
|
@ -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
|
||||
|
|
10
index.php
10
index.php
|
@ -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);
|
||||
|
|
Reference in a new issue