Added $apppath global variable, changed procedure for ISSO::fetch_sourcepath(), finis...
[isso.git] / kernel.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Iris Studios Shared Object Framework [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # All parts of this file are ©2003-[#]year[#] Iris Studios, Inc. No # ||
7 || # part of this file may be reproduced in any way: part or whole. # ||
8 || # --------------------------------------------------------------- # ||
9 || # ©2003 - [#]year[#] Iris Studios, Inc. | http://www.iris-studios.com # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 define('ERR_FATAL', E_USER_ERROR);
14 define('ERR_ERROR', E_USER_WARNING);
15 define('ERR_WARNING', E_USER_NOTICE);
16
17 /**
18 * Iris Studios Shared Object Framework (ISSO)
19 *
20 * This framework allows a common backend to be used amongst all Iris
21 * Studios applications and can is built to be abstract and flexible.
22 * The base framework handles all loading and module management.
23 *
24 * @author Iris Studios, Inc.
25 * @copyright Copyright ©2003 - [#]year[#], Iris Studios, Inc.
26 * @version $Revision$
27 *
28 */
29 class Shared_Object_Framework
30 {
31 /**
32 * Global environment variables
33 *
34 * This is where we keep the global variables that are used within the shared framework
35 *
36 * @var version ISSO version
37 * @var sourcepath The location of the framework sources
38 * @var appath The path to the application's location
39 * @var application The name of the application that is using the framework
40 * @var modules An array of loaded framework modules
41 */
42 var $version = '[#]version[#]';
43 var $sourcepath = '';
44 var $apppath = '';
45 var $application = '';
46 var $modules = array();
47
48 /**
49 * Constructor
50 */
51 function Shared_Object_Framework()
52 {
53 set_error_handler(array(&$this, '_error_handler'));
54 $this->modules['kernel'] = 'Shared Object Framework Core';
55 }
56
57 /**
58 * Prepares a path for being set as the sourcepath
59 *
60 * @param str Source path or URL
61 *
62 * @return str Prepared source path
63 */
64 function fetch_sourcepath($source)
65 {
66 if (substr($source, strlen($source) - 1) != '/')
67 {
68 $source .= '/';
69 }
70 return $source;
71 }
72
73 /**
74 * Loads a framework extension
75 *
76 * @param str Name of the framework
77 */
78 function load($framework)
79 {
80 if (!$this->is_loaded($framework))
81 {
82 $newobj = $this->locate($framework);
83 $this->$newobj['OBJ'] = new $newobj['CLASS']();
84 $GLOBALS["$newobj[OBJ]"] =& $this->$newobj['OBJ'];
85 $this->modules["$framework"] = $newobj['OBJECT'];
86 }
87 }
88
89 /**
90 * Includes a framework module. Module definitions need three variables:
91 * class, object, and obj. Class is the name of the class, object is
92 * the name human-readable name, and obj is the name that the module
93 * should be initialized as; this is used in class extensions.
94 *
95 * @param str Name of the framework
96 *
97 * @return array List of initialization variables
98 */
99 function locate($framework)
100 {
101 require_once($this->sourcepath . $framework . '.php');
102 return array('CLASS' => $CLASS, 'OBJECT' => $OBJECT, 'OBJ' => $OBJ);
103 }
104
105 /**
106 * Prints a list of all currently loaded framework modules
107 *
108 * @param bool Return the data as an array?
109 *
110 * @return mixed HTML output or an array of loaded modules
111 */
112 function show_modules($return = false)
113 {
114 if ($return)
115 {
116 return $this->modules;
117 }
118 else
119 {
120 $output = "\n\n<ul>\n\t<li>";
121 $output .= implode("</li>\n\t<li>", $this->modules);
122 $output .= "</li>\n</ul>\n\n";
123 $this->_message('Loaded Modules', $output, 1);
124 }
125 }
126
127 /**
128 * Verifies to see if a framework has been loaded
129 *
130 * @param str Framework name
131 *
132 * @return bool Whether or not the framework has been loaded
133 */
134 function is_loaded($framework)
135 {
136 if (isset($this->modules["$framework"]))
137 {
138 return true;
139 }
140 else
141 {
142 return false;
143 }
144 }
145
146 /**
147 * Prints an ISSO message
148 *
149 * @param str The title of the message
150 * @param str The content of the message
151 * @param int Type of message to be printed
152 * @param bool Return the output?
153 *
154 * @return mixed Output or null
155 */
156 function _message($title, $message, $type, $return = false)
157 {
158 switch ($type)
159 {
160 // Message
161 case 1:
162 $prefix = 'Message';
163 $color = '#669900';
164 $font = '#000000';
165 break;
166
167 // Warning
168 case 2:
169 $prefix = 'Warning';
170 $color = '#003399';
171 $font = '#FFFFFF';
172 break;
173
174 case 3:
175 $prefix = 'Error';
176 $color = '#990000';
177 $font = '#EFEFEF';
178 break;
179 }
180
181 $output = "\n<br />\n<table cellpadding=\"4\" cellspacing=\"1\" border=\"0\" width=\"500\" style=\"background-color: $color\">";
182 $output .= "\n<tr style=\"color: $font\">\n\t<td><strong>$prefix: $title</strong></td>\n</tr>";
183 $output .= "\n<tr style=\"background-color: #FFFFFF\">\n\t<td>$message</td>\n</tr>\n</table>\n<br />\n";
184
185 if ($return)
186 {
187 return $output;
188 }
189 else
190 {
191 print($output);
192 }
193 }
194
195 /**
196 * Custom error handler for ISSO
197 *
198 * @param int Error number
199 * @param str Error message string
200 * @param str File that contains the error
201 * @param str The line number of the error
202 * @param str The active symbol table at which point the error occurred
203 */
204 function _error_handler($errno, $errstr, $errfile, $errline)
205 {
206 switch ($errno)
207 {
208 // Fatal
209 case ERR_FATAL:
210 $title = 'Fatal';
211 break;
212
213 // Error
214 case ERR_ERROR:
215 $title = 'Error';
216 break;
217
218 // Warning
219 case ERR_WARNING:
220 default:
221 $title = 'Warning';
222 break;
223 }
224
225 $errstr .= " in <strong>$errfile</strong> on line <strong>$errline</strong>";
226
227 $this->_message($title, $errstr, 3);
228 }
229 }
230
231 $_isso = new Shared_Object_Framework();
232
233 /*=====================================================================*\
234 || ###################################################################
235 || # $HeadURL$
236 || # $Id$
237 || ###################################################################
238 \*=====================================================================*/
239 ?>