*/
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');
$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();
}
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() {
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() {}
}