2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright ©2002-[#]year[#] 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 [#]gpl[#] 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 ©2002 - [#]year[#], Blue Static
73 * Instance of this class
76 private static $instance;
82 private $application = 'Unknown ISSO Project';
106 private $debug = false
;
109 * The master registry list
112 private $registry = null
;
115 * An array of debug messages
118 private $debugInfo = array();
120 // ###################################################################
124 private function __construct()
126 $this->registry
= new BSVariableRegistry();
129 // ###################################################################
131 * Returns the single instance of the register
133 * @param string A string param
135 * @return object BSApp instance
137 private static function _Instance()
139 if (!self
::$instance)
141 self
::$instance = new BSApp();
143 return self
::$instance;
146 // ###################################################################
148 * Sets the application name
150 * @param string Application name
152 public static function SetApplication($name)
154 self
::_Instance()->application
= $name;
157 // ###################################################################
159 * Gets the application name
161 * @return string Application name
163 public static function GetApplication()
165 return self
::_Instance()->application
;
168 // ###################################################################
170 * Sets the application's working path
174 public static function SetAppPath($path)
176 self
::_Instance()->appPath
= BSFunctions
::FetchSourcePath($path);
179 // ###################################################################
181 * Returns the path to the application
183 * @return string Application path
185 public static function GetAppPath()
187 return self
::_Instance()->appPath
;
190 // ###################################################################
192 * Sets the application version
194 * @param string Application version
196 public static function SetAppVersion($vers)
198 self
::_Instance()->appVersion
= $vers;
201 // ###################################################################
203 * Gets the application version
205 * @return string Application version
207 public static function GetAppVersion()
209 return self
::_Instance()->appVersion
;
212 // ###################################################################
214 * Sets the application's web path, which is the full path from the
219 public static function SetWebPath($path)
221 self
::_Instance()->webPath
= BSFunctions
::FetchSourcePath($path);
224 // ###################################################################
226 * Returns the web path to the application
228 * @return string Application's web path
230 public static function GetWebPath()
232 return self
::_Instance()->webPath
;
235 // ###################################################################
237 * Sets the debug state
239 * @param bool Debug mode on?
241 public static function SetDebug($debug)
243 self
::_Instance()->debug
= $debug;
246 // ###################################################################
248 * Gets the debug mode state
250 * @return bool Debug mode on?
252 public static function GetDebug()
254 return self
::_Instance()->debug
;
257 // ###################################################################
259 * Returns the registry object without it ever being able to be cleared
264 public static function Registry()
266 return self
::_Instance()->registry
;
269 // ###################################################################
271 * Adds a debug message to the array. This only works when debug mode
274 * @param string Debug message
276 public static function Debug($msg)
278 if (self
::_Instance()->debug
)
280 self
::_Instance()->debugInfo
[] = $msg;
284 // ###################################################################
286 * Returns a <select> menu of all the debug notices
288 * @return string Debug list
290 public static function GetDebugList()
292 $output = '<select><option>Debug Notices (' . sizeof(self
::_Instance()->debugInfo
) . ')</option>';
293 foreach (self
::_Instance()->debugInfo
AS $notice)
295 $output .= "<option>--- $notice</option>";
297 return "$output</select>";
300 // ###################################################################
302 * Loads the specified module.
304 * @param string Module name
306 * @return object Instantiated module
308 public static function LoadModule($name)
310 if (self
::GetDebug())
312 include_once("ISSO/$name.php");
316 @include_once("ISSO/$name.php");
321 if (!class_exists($class))
323 throw new Exception('Specifed module does not conform to the ISSO specification, or the class is missing');
330 // ###################################################################
332 * This function is used by other framework modules to check and see if
333 * the passed array of module names have been loaded. If not, this will
334 * throw an error informing the developer that the given modules are
335 * required in order for the framework to work.
337 * @param array Array of module names to check for loadedness
339 public static function RequiredModules($modules)
341 foreach ($modules AS $module)
343 if (self
::Registry()->getType($module) == null
AND !class_exists("BS$module"))
345 throw new Exception('The ' . $module . ' module is required in order to use this framework module');
354 * This class can be used to store unlimited number of properties. It is a (make believe)
355 * inner class to BSApp and cannot be instantiated outside of it.
357 * @author Blue Static
358 * @copyright Copyright (c)2002 - [#]year[#], Blue Static
363 class BSVariableRegistry
365 // ###################################################################
367 * Constructor: only able to be called by BSApp
369 public function __construct()
371 $bt = debug_backtrace();
372 if (!isset($bt[1]['class']) OR $bt[1]['class'] != 'BSApp')
374 exit('You cannot instantiate ' . __CLASS__
. ' directly. It is an internal class.');
378 // ###################################################################
380 * If you try and get a non-existent property, throw a new exception
382 public function __get($name)
384 throw new Exception('Failed to get nonexistent property "' . $name . '"');
387 // ###################################################################
389 * Returns the first value of the given type in the variable registry
393 public function getType($class)
395 $class = 'BS' . $class;
396 foreach ($this AS $object)
398 if ($object instanceof $class)
405 // ###################################################################
407 * Returns all the objects in the registry by iterating over it
411 public function allObjects()
414 foreach ($this AS $key => $value)
416 $registry[$key] = $value;
422 /*=====================================================================*\
423 || ###################################################################
426 || ###################################################################
427 \*=====================================================================*/