]>
src.bluestatic.org Git - isso.git/blob - App.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2002-2007 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)2002 - 2007, Blue Static
72 * Instance of this class
75 private static $instance;
81 private $application = 'Unknown ISSO Project';
105 private $debug = false;
108 * The master registry list
111 private $registry = null;
114 * An array of debug messages
117 private $debugInfo = array();
119 // ###################################################################
123 private function __construct()
125 $this->registry
= new BSVariableRegistry();
128 // ###################################################################
130 * Returns the single instance of the register
132 * @param string A string param
134 * @return object BSApp instance
136 private static function _Instance()
138 if (!self
::$instance)
140 self
::$instance = new BSApp();
142 return self
::$instance;
145 // ###################################################################
147 * Sets the application name
149 * @param string Application name
151 public static function SetApplication($name)
153 self
::_Instance()->application
= $name;
156 // ###################################################################
158 * Gets the application name
160 * @return string Application name
162 public static function GetApplication()
164 return self
::_Instance()->application
;
167 // ###################################################################
169 * Sets the application's working path
173 public static function SetAppPath($path)
175 self
::_Instance()->appPath
= BSFunctions
::FetchSourcePath($path);
178 // ###################################################################
180 * Returns the path to the application
182 * @return string Application path
184 public static function GetAppPath()
186 return self
::_Instance()->appPath
;
189 // ###################################################################
191 * Sets the application version
193 * @param string Application version
195 public static function SetAppVersion($vers)
197 self
::_Instance()->appVersion
= $vers;
200 // ###################################################################
202 * Gets the application version
204 * @return string Application version
206 public static function GetAppVersion()
208 return self
::_Instance()->appVersion
;
211 // ###################################################################
213 * Sets the application's web path, which is the full path from the
218 public static function SetWebPath($path)
220 self
::_Instance()->webPath
= BSFunctions
::FetchSourcePath($path);
223 // ###################################################################
225 * Returns the web path to the application
227 * @return string Application's web path
229 public static function GetWebPath()
231 return self
::_Instance()->webPath
;
234 // ###################################################################
236 * Sets the debug state
238 * @param bool Debug mode on?
240 public static function SetDebug($debug)
242 self
::_Instance()->debug
= $debug;
245 // ###################################################################
247 * Gets the debug mode state
249 * @return bool Debug mode on?
251 public static function GetDebug()
253 return self
::_Instance()->debug
;
256 // ###################################################################
258 * Returns the registry object without it ever being able to be cleared
263 public static function Registry()
265 return self
::_Instance()->registry
;
268 // ###################################################################
270 * Adds a debug message to the array. This only works when debug mode
273 * @param string Debug message
275 public static function Debug($msg)
277 if (self
::_Instance()->debug
)
279 self
::_Instance()->debugInfo
[] = $msg;
283 // ###################################################################
285 * Returns a <select> menu of all the debug notices
287 * @return string Debug list
289 public static function GetDebugList()
291 $output = '<select><option>Debug Notices (' . sizeof(self
::_Instance()->debugInfo
) . ')</option>';
292 foreach (self
::_Instance()->debugInfo
AS $notice)
294 $output .= "<option>--- $notice</option>";
296 return "$output</select>";
299 // ###################################################################
301 * Loads the specified module.
303 * @param string Module name
305 * @return object Instantiated module
307 public static function LoadModule($name)
309 if (self
::GetDebug())
311 include_once("ISSO/$name.php");
315 @include_once("ISSO/$name.php");
320 if (!class_exists($class))
322 throw new Exception('Specifed module does not conform to the ISSO specification, or the class is missing');
329 // ###################################################################
331 * This function is used by other framework modules to check and see if
332 * the passed array of module names have been loaded. If not, this will
333 * throw an error informing the developer that the given modules are
334 * required in order for the framework to work.
336 * @param array Array of module names to check for loadedness
338 public static function RequiredModules($modules)
340 foreach ($modules AS $module)
342 if (self::Registry()->getType($module) == null)
344 throw new Exception('The ' . $module . ' module is required in order to use this framework module');
353 * This class can be used to store unlimited number of properties. It is a (make believe)
354 * inner class to BSApp and cannot be instantiated outside of it.
356 * @author Blue Static
357 * @copyright Copyright (c)2002 - 2007, Blue Static
362 class BSVariableRegistry
364 // ###################################################################
366 * Constructor: only able to be called by BSApp
368 public function __construct()
370 $bt = debug_backtrace();
371 if (!isset($bt[1]['class']) OR $bt[1]['class'] != 'BSApp')
373 exit('You cannot instantiate ' . __CLASS__ . ' directly. It is an internal class.');
377 // ###################################################################
379 * If you try and get a non-existent property, throw a new exception
381 public function __get($name)
383 throw new Exception('Failed to get nonexistent property "' . $name . '"');
386 // ###################################################################
388 * Returns the first value of the given type in the variable registry
392 public function getType($class)
394 $class = 'BS' . $class;
395 foreach ($this AS $object)
397 if ($object instanceof $class)
404 // ###################################################################
406 * Returns all the objects in the registry by iterating over it
410 public function allObjects()
413 foreach ($this AS $key => $value)
415 $registry[$key] = $value;