SimpleExtension, like Extension but with more Magic
This commit is contained in:
parent
6a5b8bd46d
commit
8dd3f8cbc0
@ -6,6 +6,26 @@ interface Extension {
|
|||||||
public function receive_event(Event $event);
|
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
|
* 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
|
// start the page generation waterfall
|
||||||
$page = new Page();
|
$page = new Page();
|
||||||
$user = _get_user($config, $database);
|
$user = _get_user($config, $database);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user