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