| 1 | <? | 
| 2 | //    ------------------------------------------------------------------------- | 
| 3 | //    $Id: Loader.php,v 1.2 2003/02/04 08:20:34 joko Exp $ | 
| 4 | //    ------------------------------------------------------------------------- | 
| 5 | //    $Log: Loader.php,v $ | 
| 6 | //    Revision 1.2  2003/02/04 08:20:34  joko | 
| 7 | //    + should now be independent from former encapsulation inside the 'Site'-object | 
| 8 | // | 
| 9 | //    Revision 1.1  2003/02/03 14:44:35  joko | 
| 10 | //    + initial commit | 
| 11 | //    + refactored from flib/Site/Loader.php | 
| 12 | //    + now inherits from DesignPattern::Logger | 
| 13 | // | 
| 14 | //    Revision 1.4  2002/12/23 11:33:32  jonen | 
| 15 | //    + minor changes | 
| 16 | // | 
| 17 | //    Revision 1.3  2002/12/19 06:21:37  joko | 
| 18 | //    + loadTemplate | 
| 19 | //    + case 'template' for 'function loadComponent' | 
| 20 | // | 
| 21 | //    Revision 1.2  2002/12/12 21:37:46  joko | 
| 22 | //    + fixes: now returning success-/error-status | 
| 23 | // | 
| 24 | //    Revision 1.1  2002/11/12 05:42:31  joko | 
| 25 | //    + initial checkin | 
| 26 | // | 
| 27 | //    ------------------------------------------------------------------------- | 
| 28 |  | 
| 29 |  | 
| 30 | class DesignPattern_Loader extends DesignPattern_Logger { | 
| 31 |  | 
| 32 | var $parent; | 
| 33 |  | 
| 34 | function includeFile($filename, $args = array()) { | 
| 35 | $this->log( get_class($this) . "->includeFile( filename $filename )", PEAR_LOG_DEBUG); | 
| 36 | // TODO: capture errors (e.g. via an eval) here? | 
| 37 | //global $site; | 
| 38 | //print "parent: " . $this->parent . "<br>"; | 
| 39 | if (include($filename)) { | 
| 40 | return 1; | 
| 41 | } | 
| 42 | } | 
| 43 |  | 
| 44 | function loadComponent($name, $type = "", $arguments = array()) { | 
| 45 | $prefix = ""; | 
| 46 | $postfix = ""; | 
| 47 | $this->log( get_class($this) . "->loadComponent( name $name, type $type )", PEAR_LOG_DEBUG); | 
| 48 |  | 
| 49 | $parent = $this->parent; | 
| 50 |  | 
| 51 | // TODO: croak somewhere (STDOUT?, logger?) if unknown type gets used here | 
| 52 | switch ($type) { | 
| 53 |  | 
| 54 | case "handler": | 
| 55 | $prefix = $this->$parent->config[path][handler]; | 
| 56 | //$postfix = ".handler.php"; | 
| 57 | $postfix = ".php"; | 
| 58 | $includefile = "$prefix$name$postfix"; | 
| 59 | return $this->includeFile($includefile); | 
| 60 | break; | 
| 61 |  | 
| 62 | case "page": | 
| 63 | $prefix = $this->$parent->config[path][pages]; | 
| 64 | $postfix = ".page"; | 
| 65 | $includefile = "$prefix$name$postfix"; | 
| 66 | return $this->includeFile($includefile, $arguments ); | 
| 67 | break; | 
| 68 |  | 
| 69 | case "template": | 
| 70 | // TODO: re-activate this (unset smarty's default directory or handle differently (generic)) | 
| 71 | //$prefix = $this->$parent->config[path][base] . 'core/templates/'; | 
| 72 | $prefix = ''; | 
| 73 | $postfix = ".html"; | 
| 74 | $includefile = "$prefix$name$postfix"; | 
| 75 | //return $this->includeFile($includefile); | 
| 76 | return $this->$parent->template->display($includefile, array( | 
| 77 | 'cache_key' => $arguments[cache_key], | 
| 78 | 'interpolate' => $arguments['vars'], | 
| 79 | 'return' => $arguments['return'] | 
| 80 | )); | 
| 81 | break; | 
| 82 | } | 
| 83 | } | 
| 84 |  | 
| 85 | function loadHandler($name) { | 
| 86 | $this->log( get_class($this) . "->loadHandler( name $name )", PEAR_LOG_DEBUG); | 
| 87 | return $this->loadComponent($name, "handler"); | 
| 88 | } | 
| 89 |  | 
| 90 | function loadPage($name, $args = array()) { | 
| 91 | $this->log( get_class($this) . "->loadPage( name $name )", PEAR_LOG_DEBUG); | 
| 92 | return $this->loadComponent($name, "page", $args); | 
| 93 | } | 
| 94 |  | 
| 95 | function loadTemplate($name, $template_variables = array(), $cache_key = "") { | 
| 96 | $this->log( get_class($this) . "->loadTemplate( name $name cache_key $cache_key )", PEAR_LOG_DEBUG); | 
| 97 | return $this->loadComponent($name, "template", array( 'cache_key' => $cache_key, 'vars' => $template_variables) ); | 
| 98 | } | 
| 99 |  | 
| 100 | function loadClass() { | 
| 101 | } | 
| 102 |  | 
| 103 | function loadBusinessClass() { | 
| 104 | } | 
| 105 |  | 
| 106 |  | 
| 107 |  | 
| 108 | } | 
| 109 | ?> |