| 3 |
// $Id$ |
// $Id$ |
| 4 |
// ------------------------------------------------------------------------- |
// ------------------------------------------------------------------------- |
| 5 |
// $Log$ |
// $Log$ |
| 6 |
|
// Revision 1.3 2003/02/09 17:10:34 joko |
| 7 |
|
// + minor update related to new log level constants |
| 8 |
|
// |
| 9 |
|
// Revision 1.2 2003/02/04 08:20:34 joko |
| 10 |
|
// + should now be independent from former encapsulation inside the 'Site'-object |
| 11 |
|
// |
| 12 |
// Revision 1.1 2003/02/03 14:44:35 joko |
// Revision 1.1 2003/02/03 14:44:35 joko |
| 13 |
// + initial commit |
// + initial commit |
| 14 |
// + refactored from flib/Site/Loader.php |
// + refactored from flib/Site/Loader.php |
| 32 |
|
|
| 33 |
class DesignPattern_Loader extends DesignPattern_Logger { |
class DesignPattern_Loader extends DesignPattern_Logger { |
| 34 |
|
|
| 35 |
|
var $parent; |
| 36 |
|
|
| 37 |
function includeFile($filename, $args = array()) { |
function includeFile($filename, $args = array()) { |
| 38 |
$this->log( get_class($this) . "->includeFile( filename $filename )", LOG_DEBUG); |
$this->log( get_class($this) . "->includeFile( filename $filename )", PEAR_LOG_DEBUG); |
| 39 |
|
// TODO: capture errors (e.g. via an eval) here? |
| 40 |
|
//global $site; |
| 41 |
|
//print "parent: " . $this->parent . "<br>"; |
| 42 |
if (include($filename)) { |
if (include($filename)) { |
| 43 |
return 1; |
return 1; |
| 44 |
} |
} |
| 47 |
function loadComponent($name, $type = "", $arguments = array()) { |
function loadComponent($name, $type = "", $arguments = array()) { |
| 48 |
$prefix = ""; |
$prefix = ""; |
| 49 |
$postfix = ""; |
$postfix = ""; |
| 50 |
$this->log( get_class($this) . "->loadComponent( name $name, type $type )", LOG_DEBUG); |
$this->log( get_class($this) . "->loadComponent( name $name, type $type )", PEAR_LOG_DEBUG); |
| 51 |
|
|
| 52 |
|
$parent = $this->parent; |
| 53 |
|
|
| 54 |
// TODO: croak somewhere (STDOUT?, logger?) if unknown type gets used here |
// TODO: croak somewhere (STDOUT?, logger?) if unknown type gets used here |
| 55 |
switch ($type) { |
switch ($type) { |
| 56 |
|
|
| 57 |
case "handler": |
case "handler": |
| 58 |
$prefix = $this->site->config[path][base] . 'core/handler/'; |
$prefix = $this->$parent->config[path][handler]; |
| 59 |
//$postfix = ".handler.php"; |
//$postfix = ".handler.php"; |
| 60 |
$postfix = ".php"; |
$postfix = ".php"; |
| 61 |
$includefile = "$prefix$name$postfix"; |
$includefile = "$prefix$name$postfix"; |
| 63 |
break; |
break; |
| 64 |
|
|
| 65 |
case "page": |
case "page": |
| 66 |
$prefix = $this->site->config[path][base] . 'core/pages/'; |
$prefix = $this->$parent->config[path][pages]; |
| 67 |
$postfix = ".page"; |
$postfix = ".page"; |
| 68 |
$includefile = "$prefix$name$postfix"; |
$includefile = "$prefix$name$postfix"; |
| 69 |
return $this->includeFile($includefile, $arguments ); |
return $this->includeFile($includefile, $arguments ); |
| 71 |
|
|
| 72 |
case "template": |
case "template": |
| 73 |
// TODO: re-activate this (unset smarty's default directory or handle differently (generic)) |
// TODO: re-activate this (unset smarty's default directory or handle differently (generic)) |
| 74 |
//$prefix = $this->site->config[path][base] . 'core/templates/'; |
//$prefix = $this->$parent->config[path][base] . 'core/templates/'; |
| 75 |
$prefix = ''; |
$prefix = ''; |
| 76 |
$postfix = ".html"; |
$postfix = ".html"; |
| 77 |
$includefile = "$prefix$name$postfix"; |
$includefile = "$prefix$name$postfix"; |
| 78 |
//return $this->includeFile($includefile); |
//return $this->includeFile($includefile); |
| 79 |
return $this->site->template->display($includefile, array( |
return $this->$parent->template->display($includefile, array( |
| 80 |
'cache_key' => $arguments[cache_key], |
'cache_key' => $arguments[cache_key], |
| 81 |
'interpolate' => $arguments['vars'], |
'interpolate' => $arguments['vars'], |
| 82 |
'return' => $arguments['return'] |
'return' => $arguments['return'] |
| 86 |
} |
} |
| 87 |
|
|
| 88 |
function loadHandler($name) { |
function loadHandler($name) { |
| 89 |
$this->log( get_class($this) . "->loadHandler( name $name )", LOG_DEBUG); |
$this->log( get_class($this) . "->loadHandler( name $name )", PEAR_LOG_DEBUG); |
| 90 |
return $this->loadComponent($name, "handler"); |
return $this->loadComponent($name, "handler"); |
| 91 |
} |
} |
| 92 |
|
|
| 93 |
function loadPage($name, $args = array()) { |
function loadPage($name, $args = array()) { |
| 94 |
$this->log( get_class($this) . "->loadPage( name $name )", LOG_DEBUG); |
$this->log( get_class($this) . "->loadPage( name $name )", PEAR_LOG_DEBUG); |
| 95 |
return $this->loadComponent($name, "page", $args); |
return $this->loadComponent($name, "page", $args); |
| 96 |
} |
} |
| 97 |
|
|
| 98 |
function loadTemplate($name, $template_variables = array(), $cache_key = "") { |
function loadTemplate($name, $template_variables = array(), $cache_key = "") { |
| 99 |
$this->log( get_class($this) . "->loadTemplate( name $name cache_key $cache_key )", LOG_DEBUG); |
$this->log( get_class($this) . "->loadTemplate( name $name cache_key $cache_key )", PEAR_LOG_DEBUG); |
| 100 |
return $this->loadComponent($name, "template", array( 'cache_key' => $cache_key, 'vars' => $template_variables) ); |
return $this->loadComponent($name, "template", array( 'cache_key' => $cache_key, 'vars' => $template_variables) ); |
| 101 |
} |
} |
| 102 |
|
|