]> andersk Git - sql-web.git/blobdiff - lib/joe/site.lib.php
fixed handler processing for new argv
[sql-web.git] / lib / joe / site.lib.php
index c28c231a4f6a9973a7b346919e37c8c297268fd1..e780e8dbc15b70c6d2e38cc717e7b3b1c2aac595 100755 (executable)
@@ -4,8 +4,23 @@
  */
 
 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');
@@ -13,23 +28,14 @@ class Site {
                                $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)) {
+                               foreach($this->argv as $argk=>$argv) {
+                                       if (in_array($argk, $handlers) &&
+                                               false !== $page->Run($argk)) {
                                                $nCalls++;
                                        }
                                }
                                if ($nCalls == 0 && is_callable(array($page, '_default'))) {
-                                       $page->Call('_default', $argv);
+                                       $page->Run('_default');
                                        $nCalls++;
                                }
                                $page->Finish();
@@ -41,9 +47,16 @@ class Site {
 }
 
 class Page {
-       var $site, $method;
+       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;
        }
        function get_handlers() {
@@ -52,14 +65,17 @@ 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) {
-               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.055686 seconds and 4 git commands to generate.