Initial SVN for base framework.
[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 application The name of the application that is using the framework
39 * @var modules An array of loaded framework modules
40 */
41 var $version = '[#]version[#]';
42 var $sourcepath = '';
43 var $application = '';
44 var $modules = array();
45
46 /**
47 * Constructor
48 */
49 function Shared_Object_Framework()
50 {
51 set_error_handler(array(&$this, '_error_handler'));
52 $this->modules[] = 'Shared Object Framework Core';
53 }
54
55 /**
56 * Prepares a path for being set as the sourcepath
57 *
58 * @param str Source path or URL
59 *
60 * @return str Prepared source path
61 */
62 function fetch_sourcepath($source)
63 {
64 if (substr($source, strlen($source) - 1) == '/')
65 {
66 $source = substr($source, 0, strlen($source) - 1);
67 }
68 return $source;
69 }
70
71 /**
72 * Loads a framework extension
73 *
74 * @param str Name of the framework
75 */
76 function load($framework)
77 {
78 if (!in_array($framework, $this->modules))
79 {
80 require_once($this->sourcepath . $framework);
81 $this->modules[] = $framework;
82 }
83 }
84
85 /**
86 * Prints a list of all currently loaded framework modules
87 *
88 * @param bool Return the data as an array?
89 *
90 * @return mixed HTML output or an array of loaded modules
91 */
92 function show_modules($return = false)
93 {
94 if ($return)
95 {
96 return $this->modules;
97 }
98 else
99 {
100 $output = "\n\n<ul>\n\t<li>";
101 $output .= implode("</li>\n\t<li>", $this->modules);
102 $output .= "</li>\n</ul>\n\n";
103 $this->_message('Loaded Modules', $output, 1);
104 }
105 }
106
107 /**
108 * Prints an ISSO message
109 *
110 * @param str The title of the message
111 * @param str The content of the message
112 * @param int Type of message to be printed
113 * @param bool Return the output?
114 *
115 * @return mixed Output or null
116 */
117 function _message($title, $message, $type, $return = false)
118 {
119 switch ($type)
120 {
121 // Message
122 case 1:
123 $prefix = 'Message';
124 $color = '#669900';
125 $font = '#000000';
126 break;
127
128 // Warning
129 case 2:
130 $prefix = 'Warning';
131 $color = '#003399';
132 $font = '#FFFFFF';
133 break;
134
135 case 3:
136 $prefix = 'Error';
137 $color = '#990000';
138 $font = '#EFEFEF';
139 break;
140 }
141
142 $output = "\n<br />\n<table cellpadding=\"4\" cellspacing=\"1\" border=\"0\" width=\"500\" style=\"background-color: $color\">";
143 $output .= "\n<tr style=\"color: $font\">\n\t<td><strong>$prefix: $title</strong></td>\n</tr>";
144 $output .= "\n<tr style=\"background-color: #FFFFFF\">\n\t<td>$message</td>\n</tr>\n</table>\n<br />\n";
145
146 if ($return)
147 {
148 return $output;
149 }
150 else
151 {
152 print($output);
153 }
154 }
155
156 /**
157 * Custom error handler for ISSO
158 *
159 * @param int Error number
160 * @param str Error message string
161 * @param str File that contains the error
162 * @param str The line number of the error
163 * @param str The active symbol table at which point the error occurred
164 */
165 function _error_handler($errno, $errstr, $errfile, $errline)
166 {
167 switch ($errno)
168 {
169 // Fatal
170 case ERR_FATAL:
171 $title = 'Fatal';
172 break;
173
174 // Error
175 case ERR_ERROR:
176 $title = 'Error';
177 break;
178
179 // Warning
180 case ERR_WARNING:
181 default:
182 $title = 'Warning';
183 break;
184 }
185
186 $errstr .= " in <strong>$errfile</strong> on line <strong>$errline</strong>";
187
188 $this->_message($title, $errstr, 3);
189 }
190 }
191
192 /*=====================================================================*\
193 || ###################################################################
194 || # $HeadURL$
195 || # $Id$
196 || ###################################################################
197 \*=====================================================================*/
198 ?>