From 8dd3f8cbc04fb63465085562edfbb459e8d97cb0 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 11 May 2009 14:08:32 -0700 Subject: [PATCH] SimpleExtension, like Extension but with more Magic --- core/extension.class.php | 20 ++++++++++++++++++++ index.php | 10 ++++++++++ 2 files changed, 30 insertions(+) diff --git a/core/extension.class.php b/core/extension.class.php index f6d059fa..30712919 100644 --- a/core/extension.class.php +++ b/core/extension.class.php @@ -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 diff --git a/index.php b/index.php index a2f88173..538688c6 100644 --- a/index.php +++ b/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);