]> andersk Git - sql-web.git/blobdiff - lib/joe/site.lib.php
git-svn-id: svn://presbrey.mit.edu/php/lib@127 a142d4bd-2cfb-0310-9673-cb33a7e74f58
[sql-web.git] / lib / joe / site.lib.php
index 1321a8b08a471be088f270d1240076e6cdfe2b21..cf09c22513498d6193f235fa94d976ef03f55624 100755 (executable)
@@ -4,34 +4,39 @@
  */
 
 class Site {
-       function Start() {}
-       function Call($MODULE, $METHOD) {
+       var $URI, $ARGV;
+       function __construct($uri) {
+               $this->URI = $uri;
+               $this->ARGV = array_merge(
+                       array_prepend_keys($_COOKIE,'c_'),
+                       array_prepend_keys($_FILES,'f_'),
+                       array_prepend_keys($_GET,'g_'),
+                       array_prepend_keys($_POST,'p_'));
+       }
+       function Start() {
+               if (isset($_SESSION)) {
+                       $this->ARGV = array_merge(
+                               $this->ARGV,
+                               array_prepend_keys($_SESSION,'s_'));
+               }
+       }
+       function Run($MODULE, $METHOD) {
                $nCalls = 0;
                if (file_exists(strtolower('site/'.$MODULE.'.php'))) {
                        require_once strtolower('site/'.$MODULE.'.php');
                        if (class_exists($MODULE)) {
                                $page = new $MODULE($this, $METHOD);
                                $page->Start();
-                               $handlers = $page->get_handlers($METHOD);
-                               switch ($METHOD) {
-                                       case 'GET':
-                                       case 'get':
-                                               $argv = array_merge($_COOKIE, $_FILES, $_POST, $_GET, isset($_SESSION)?$_SESSION:array()); break;
-                                       case 'POST':
-                                       case 'post':
-                                       default:
-                                               $argv = array_merge($_COOKIE, $_FILES, $_GET, $_POST, isset($_SESSION)?$_SESSION:array()); break;
-                               }
+                               $handlers = array_intersect(
+                                       $page->get_handlers($METHOD),
+                                       array_keys($this->ARGV));
                                foreach($handlers as $handler) {
-                                       if (isset($argv[$handler]) &&
-                                               false !== $page->Call($handler, $argv)) {
+                                       if (false !== $page->Run($handler)) {
                                                $nCalls++;
                                        }
                                }
-                               echo $nCalls;
-                               print_r($page);
-                               if ($nCalls == 0 && is_callable($page, '_default')) {
-                                       $page->Call('_default', $argv);
+                               if ($nCalls == 0 && is_callable(array($page, '_default'))) {
+                                       $page->Run('_default');
                                        $nCalls++;
                                }
                                $page->Finish();
@@ -43,25 +48,31 @@ class Site {
 }
 
 class Page {
-       var $site, $method;
+       var $SITE, $METHOD, $URI;
        function __construct($site, $method) {
-               $this->site = $site;
-               $this->method = $method;
+               $this->SITE = $site;
+               $this->METHOD = $method;
+               foreach($site->ARGV as $k=>$v)
+                       $this->$k = $v;
+               $this->URI = $site->URI;
        }
        function get_handlers() {
-               $handlers = isset($this->handlers[$this->method]) ?
-                                       $this->handlers[$this->method] : array();
+               $handlers = isset($this->handlers[$this->METHOD]) ?
+                                       $this->handlers[$this->METHOD] : array();
                return $handlers;
        }
        function has_handler($handler) {
-               return isset($this->handlers[$this->method]) ? in_array($handler, $this->handlers[$this->method]) : false;
+               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 Run($handler) {
+               if (is_callable(array($this, $handler))) {
+                       return array(0, call_user_func(array($this, $handler)));
+               } else {
+                       return false;
+               }
        }
        function Finish() {}
 }
This page took 0.029285 seconds and 4 git commands to generate.