]> andersk Git - sql-web.git/blame_incremental - lib/joe/site.lib.php
git-svn-id: svn://presbrey.mit.edu/php/lib@120 a142d4bd-2cfb-0310-9673-cb33a7e74f58
[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 echo $nCalls;
32 print_r($page);
33 if ($nCalls == 0 && is_callable($page, '_default')) {
34 $page->Call('_default', $argv);
35 $nCalls++;
36 }
37 $page->Finish();
38 }
39 }
40 return $nCalls;
41 }
42 function Finish() {}
43}
44
45class Page {
46 var $site, $method;
47 function __construct($site, $method) {
48 $this->site = $site;
49 $this->method = $method;
50 }
51 function get_handlers() {
52 $handlers = isset($this->handlers[$this->method]) ?
53 $this->handlers[$this->method] : array();
54 return $handlers;
55 }
56 function has_handler($handler) {
57 return isset($this->handlers[$this->method]) ? in_array($handler, $this->handlers[$this->method]) : false;
58 }
59
60 function Start() {}
61 function Call($handler, $argv) {
62 if (is_callable(array($this, $handler)))
63 return array(0, call_user_func_array(array($this, $handler), $argv));
64 else return false;
65 }
66 function Finish() {}
67}
This page took 0.029227 seconds and 5 git commands to generate.