]> andersk Git - sql-web.git/blame_incremental - lib/joe/site.lib.php
PHP: fixed site class _default handler
[sql-web.git] / lib / joe / site.lib.php
... / ...
CommitLineData
1<?php
2/* Generic Site Classes
3 * 2007/04/09 Joe Presbrey <presbrey@mit.edu>
4 */
5
6class Site {
7 function Start() {}
8 function Call($MODULE, $METHOD) {
9 $nCalls = 0;
10 if (file_exists(strtolower('site/'.$MODULE.'.php'))) {
11 require_once strtolower('site/'.$MODULE.'.php');
12 if (class_exists($MODULE)) {
13 $page = new $MODULE($this, $METHOD);
14 $page->Start();
15 $handlers = $page->get_handlers($METHOD);
16 switch ($METHOD) {
17 case 'GET':
18 case 'get':
19 $argv = array_merge($_COOKIE, $_FILES, $_POST, $_GET, isset($_SESSION)?$_SESSION:array()); break;
20 case 'POST':
21 case 'post':
22 default:
23 $argv = array_merge($_COOKIE, $_FILES, $_GET, $_POST, isset($_SESSION)?$_SESSION:array()); break;
24 }
25 foreach($handlers as $handler) {
26 if (isset($argv[$handler]) &&
27 false !== $page->Call($handler, $argv)) {
28 $nCalls++;
29 }
30 }
31 if ($nCalls == 0 && is_callable(array($page, '_default'))) {
32 $page->Call('_default', $argv);
33 $nCalls++;
34 }
35 $page->Finish();
36 }
37 }
38 return $nCalls;
39 }
40 function Finish() {}
41}
42
43class Page {
44 var $site, $method;
45 function __construct($site, $method) {
46 $this->site = $site;
47 $this->method = $method;
48 }
49 function get_handlers() {
50 $handlers = isset($this->handlers[$this->method]) ?
51 $this->handlers[$this->method] : array();
52 return $handlers;
53 }
54 function has_handler($handler) {
55 return isset($this->handlers[$this->method]) ? in_array($handler, $this->handlers[$this->method]) : false;
56 }
57
58 function Start() {}
59 function Call($handler, $argv) {
60 if (is_callable(array($this, $handler)))
61 return array(0, call_user_func_array(array($this, $handler), $argv));
62 else return false;
63 }
64 function Finish() {}
65}
This page took 0.026566 seconds and 5 git commands to generate.