From b842dc2121896ca946ff84ef9fc42a752de23a00 Mon Sep 17 00:00:00 2001 From: Joe Presbrey Date: Mon, 9 Apr 2007 22:16:44 +0000 Subject: [PATCH] git-svn-id: svn://presbrey.mit.edu/php/lib@120 a142d4bd-2cfb-0310-9673-cb33a7e74f58 --- lib/joe/site.lib.php | 51 ++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/lib/joe/site.lib.php b/lib/joe/site.lib.php index 3496242..1321a8b 100755 --- a/lib/joe/site.lib.php +++ b/lib/joe/site.lib.php @@ -5,16 +5,14 @@ class Site { function Start() {} - function Finish() {} - function Call($MODULE, $METHOD) { $nCalls = 0; - if (file_exists('site/'.$MODULE.'.php')) { + if (file_exists(strtolower('site/'.$MODULE.'.php'))) { require_once strtolower('site/'.$MODULE.'.php'); if (class_exists($MODULE)) { - $object = new $MODULE; - $object->Start(); - $handlers = $object->get_handlers($METHOD); + $page = new $MODULE($this, $METHOD); + $page->Start(); + $handlers = $page->get_handlers($METHOD); switch ($METHOD) { case 'GET': case 'get': @@ -26,33 +24,44 @@ class Site { } foreach($handlers as $handler) { if (isset($argv[$handler]) && - is_callable($object, $handler)) { - call_user_func_array(array($object, $handler), $argv); + false !== $page->Call($handler, $argv)) { $nCalls++; } } - if ($nCalls == 0 && is_callable($object, 'default')) { - call_user_func_array(array($object, $handler), $argv); + echo $nCalls; + print_r($page); + if ($nCalls == 0 && is_callable($page, '_default')) { + $page->Call('_default', $argv); $nCalls++; } - $object->Finish(); + $page->Finish(); } } return $nCalls; } + function Finish() {} } class Page { - function Start() {} - function Finish() {} - - function get_handlers($method) { - $handlers = isset($this->handlers[$method]) ? - $this->handlers[$method] : - array('default'); + var $site, $method; + function __construct($site, $method) { + $this->site = $site; + $this->method = $method; + } + function get_handlers() { + $handlers = isset($this->handlers[$this->method]) ? + $this->handlers[$this->method] : array(); return $handlers; - //return array_map( - // create_function('$a','return "_'.$method.'_".$a;'), - // $this->handlers[$method]); } + function has_handler($handler) { + return isset($this->handlers[$this->method]) ? in_array($handler, $this->handlers[$this->method]) : false; + } + + function Start() {} + function Call($handler, $argv) { + if (is_callable(array($this, $handler))) + return array(0, call_user_func_array(array($this, $handler), $argv)); + else return false; + } + function Finish() {} } -- 2.45.0