]> andersk Git - sql-web.git/commitdiff
git-svn-id: svn://presbrey.mit.edu/php/lib@120 a142d4bd-2cfb-0310-9673-cb33a7e74f58
authorJoe Presbrey <presbrey@mit.edu>
Mon, 9 Apr 2007 22:16:44 +0000 (22:16 +0000)
committerJoe Presbrey <presbrey@mit.edu>
Mon, 9 Apr 2007 22:16:44 +0000 (22:16 +0000)
lib/joe/site.lib.php

index 3496242ae8920edab9ea0abd876dcfa3f02c4f61..1321a8b08a471be088f270d1240076e6cdfe2b21 100755 (executable)
@@ -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() {}
 }
This page took 0.036749 seconds and 5 git commands to generate.