From: Joe Presbrey Date: Sun, 15 Apr 2007 00:01:58 +0000 (+0000) Subject: git-svn-id: svn://presbrey.mit.edu/php/lib@124 a142d4bd-2cfb-0310-9673-cb33a7e74f58 X-Git-Url: http://andersk.mit.edu/gitweb/sql-web.git/commitdiff_plain/d7499d0f413743f6b45448a4d0614a046169b63d git-svn-id: svn://presbrey.mit.edu/php/lib@124 a142d4bd-2cfb-0310-9673-cb33a7e74f58 --- diff --git a/lib/joe/site.lib.php b/lib/joe/site.lib.php index c2a2e3a..743c061 100755 --- a/lib/joe/site.lib.php +++ b/lib/joe/site.lib.php @@ -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; }