2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2005-2008 Blue Static
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
23 * ISSO Application Root (App.php)
28 // we need PHP 5.2.0 to run
29 if (!function_exists('array_fill_keys'))
31 print('You need PHP version 5.2.0 or newer to run ISSO');
35 // get rid of register_globals
36 if ((bool
)ini_get('register_globals') === true
)
38 $superglobals = array('_GET', '_COOKIE', '_FILES', '_POST', '_SERVER', '_ENV');
39 foreach ($superglobals AS $global)
41 if (is_array($
{$global}))
43 foreach ($
{$global} AS $_key => $_val)
54 require_once(ISSO
. '/Functions.php');
59 * This is an ISSO application class. It holds all of the ISSO system variables as well
60 * as serving as an object registry that is avaliable in the global scope to prevent
61 * globalization of variables. There can only be one instance of this existing
65 * @copyright Copyright (c)2005 - 2008, Blue Static
72 * Instance of this class
75 private static $instance;
81 private $debug = false
;
84 * The master registry list
87 private $registry = null
;
90 * An array of debug messages
93 private $debugInfo = array();
95 // ###################################################################
99 private function __construct()
101 $this->registry
= new BSVariableRegistry();
104 // ###################################################################
106 * Returns the single instance of the register
108 * @param string A string param
110 * @return object BSApp instance
112 private static function _instance()
114 if (!self
::$instance)
116 self
::$instance = new BSApp();
118 return self
::$instance;
121 // ###################################################################
123 * Sets the debug state
125 * @param bool Debug mode on?
127 public static function set_debug($debug)
129 self
::_instance()->debug
= $debug;
132 // ###################################################################
134 * Gets the debug mode state
136 * @return bool Debug mode on?
138 public static function get_debug()
140 return self
::_instance()->debug
;
143 // ###################################################################
145 * Returns the registry object without it ever being able to be cleared
150 public static function registry()
152 return self
::_instance()->registry
;
155 // ###################################################################
157 * Adds a debug message to the array. This only works when debug mode
160 * @param string Debug message
162 public static function debug($msg)
164 if (self
::_instance()->debug
)
166 self
::_instance()->debugInfo
[] = $msg;
170 // ###################################################################
172 * Returns a <select> menu of all the debug notices
174 * @return string Debug list
176 public static function get_debug_list()
178 $output = '<select><option>Debug Notices (' . sizeof(self
::_instance()->debugInfo
) . ')</option>';
179 foreach (self
::_instance()->debugInfo
AS $notice)
181 $output .= "<option>--- $notice</option>";
183 return "$output</select>";
186 // ###################################################################
188 * Loads the specified module.
190 * @param string Module name
192 * @return object Instantiated module
194 public static function load_module($name)
196 if (self
::get_debug())
198 include_once(ISSO
. "/$name.php");
202 @include_once(ISSO
. "/$name.php");
207 if (!class_exists($class))
209 throw new Exception('Specifed module does not conform to the ISSO specification, or the class is missing');
216 // ###################################################################
218 * This function is used by other framework modules to check and see if
219 * the passed array of module names have been loaded. If not, this will
220 * throw an error informing the developer that the given modules are
221 * required in order for the framework to work.
223 * @param array Array of module names to check for loadedness
225 public static function required_modules($modules)
227 foreach ($modules AS $module)
229 if (self
::registry()->getType($module) == null
)
231 throw new Exception('The ' . $module . ' module is required in order to use this framework module');
240 * This class can be used to store unlimited number of properties. It is a (make believe)
241 * inner class to BSApp and cannot be instantiated outside of it.
243 * @author Blue Static
244 * @copyright Copyright (c)2005 - 2008, Blue Static
249 class BSVariableRegistry
251 // ###################################################################
253 * Constructor: only able to be called by BSApp
255 public function __construct()
257 $bt = debug_backtrace();
258 if (!isset($bt[1]['class']) OR $bt[1]['class'] != 'BSApp')
260 exit('You cannot instantiate ' . __CLASS__
. ' directly. It is an internal class.');
264 // ###################################################################
266 * If you try and get a non-existent property, throw a new exception
268 public function __get($name)
270 throw new Exception('Failed to get nonexistent property "' . $name . '"');
273 // ###################################################################
275 * Returns the first value of the given type in the variable registry
279 public function getType($class)
281 $class = 'BS' . $class;
282 foreach ($this AS $object)
284 if ($object instanceof $class)
291 // ###################################################################
293 * Returns all the objects in the registry by iterating over it
297 public function allObjects()
300 foreach ($this AS $key => $value)
302 $registry[$key] = $value;