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