]> andersk Git - sql-web.git/commitdiff
git-svn-id: svn://presbrey.mit.edu/php/lib@124 a142d4bd-2cfb-0310-9673-cb33a7e74f58
authorJoe Presbrey <presbrey@mit.edu>
Sun, 15 Apr 2007 00:01:58 +0000 (00:01 +0000)
committerJoe Presbrey <presbrey@mit.edu>
Sun, 15 Apr 2007 00:01:58 +0000 (00:01 +0000)
lib/joe/site.lib.php

index c2a2e3a62b030b19413e8b07cf60e1eb526e7645..743c061640755947771747e1eb8914343399c5e6 100755 (executable)
@@ -4,32 +4,38 @@
  */
 
 class Site {
-       function Start() {}
-       function Call($MODULE, $METHOD, $ARGP=array()) {
+       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, $ARGP);
+                               $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;
-                               }
                                foreach($handlers as $handler) {
-                                       if (isset($argv[$handler]) &&
-                                               false !== $page->Call($handler, $argv)) {
+                                       if (isset($this->argv[$handler]) &&
+                                               false !== $page->Run($handler)) {
                                                $nCalls++;
                                        }
                                }
                                if ($nCalls == 0 && is_callable(array($page, '_default'))) {
-                                       $page->Call('_default', $argv);
+                                       $page->Run('_default');
                                        $nCalls++;
                                }
                                $page->Finish();
@@ -41,11 +47,17 @@ class Site {
 }
 
 class Page {
-       var $site, $method, $argp;
-       function __construct($site, $method, $argp) {
+       var $site;
+       var $method;
+       var $uri;
+       var $argv;
+       function __construct($site, $method) {
+               $this->argv = $site->argv;
+               foreach($this->argv as $k=>$v)
+                       $this->$k = $v;
                $this->site = $site;
+               $this->uri = $site->uri;
                $this->method = $method;
-               $this->argp = $argp;
        }
        function get_handlers() {
                $handlers = isset($this->handlers[$this->method]) ?
@@ -53,13 +65,14 @@ class Page {
                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) {
+       function Run($handler) {
                if (is_callable(array($this, $handler))) {
-                       return array(0, call_user_func(array($this, $handler), $argv));
+                       return array(0, call_user_func(array($this, $handler)));
                } else {
                        return false;
                }
This page took 0.28606 seconds and 5 git commands to generate.