]> andersk Git - sql-web.git/commitdiff
PHP: generic site class
authorJoe Presbrey <presbrey@mit.edu>
Mon, 9 Apr 2007 21:19:25 +0000 (21:19 +0000)
committerJoe Presbrey <presbrey@mit.edu>
Mon, 9 Apr 2007 21:19:25 +0000 (21:19 +0000)
git-svn-id: svn://presbrey.mit.edu/php/lib@119 a142d4bd-2cfb-0310-9673-cb33a7e74f58

lib/joe/site.lib.php [new file with mode: 0755]

diff --git a/lib/joe/site.lib.php b/lib/joe/site.lib.php
new file mode 100755 (executable)
index 0000000..3496242
--- /dev/null
@@ -0,0 +1,58 @@
+<?php
+/* Generic Site Classes
+ * 2007/04/09 Joe Presbrey <presbrey@mit.edu>
+ */
+
+class Site {
+       function Start() {}
+       function Finish() {}
+
+       function Call($MODULE, $METHOD) {
+               $nCalls = 0;
+               if (file_exists('site/'.$MODULE.'.php')) {
+                       require_once strtolower('site/'.$MODULE.'.php');
+                       if (class_exists($MODULE)) {
+                               $object = new $MODULE;
+                               $object->Start();
+                               $handlers = $object->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]) &&
+                                               is_callable($object, $handler)) {
+                                               call_user_func_array(array($object, $handler), $argv);
+                                               $nCalls++;
+                                       }
+                               }
+                               if ($nCalls == 0 && is_callable($object, 'default')) {
+                                       call_user_func_array(array($object, $handler), $argv);
+                                       $nCalls++;
+                               }
+                               $object->Finish();
+                       }
+               }
+               return $nCalls;
+       }
+}
+
+class Page {
+       function Start() {}
+       function Finish() {}
+
+       function get_handlers($method) {
+               $handlers = isset($this->handlers[$method]) ?
+                                       $this->handlers[$method] :
+                                       array('default');
+               return $handlers;
+               //return array_map(
+               //      create_function('$a','return "_'.$method.'_".$a;'),
+               //      $this->handlers[$method]);
+       }
+}
This page took 0.051302 seconds and 5 git commands to generate.