]>
src.bluestatic.org Git - isso.git/blob - Loader.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework [#]issoversion[#]
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 * System loader (Loader.php)
31 * This class contains static methods that are used to create new registers and
35 * @copyright Copyright ©2002 - [#]year[#], Blue Static
46 private static $instance;
49 * Array of all the registers
52 private $registers = array();
60 // ###################################################################
64 private function __construct() {}
66 // ###################################################################
68 * Returns the shared instance of the BSLoader singleton class.
70 * @return object The BSLoader shared instance
72 private function SharedInstance()
76 self
::$instance = new BSLoader
;
78 return self
::$instance;
81 // ###################################################################
83 * Creates a new BSRegister instance and returns it.
85 * @return object New register
87 public static function NewRegister()
89 require_once('ISSO/Register.php');
91 self
::SharedInstance()->registers
[] = new BSRegister();
93 return end(self
::SharedInstance()->registers
);
96 // ###################################################################
98 * Returns the array of all the registers
100 * @return array The array of all the registers
102 public static function GetAllRegisters()
104 return self
::SharedInstance()->registers
;
107 // ###################################################################
109 * Sets the main register
111 * @param object New main register
113 public static function SetRegister(BSRegister
$newreg)
115 if (get_class($newreg) != 'BSRegister')
117 throw new Exception('BSLoader::SetRegister() was not passed a BSRegister object');
120 self
::SharedInstance()->main
= $register;
123 // ###################################################################
125 * Gets the main register if no argument is passed, or an arbitrary
126 * one if the index of a register is passed.
128 * @param integer Register index
130 * @return object Specified register
132 public static function &GetRegister($index = null)
136 if (!isset(self
::SharedInstance()->main
))
138 throw new Exception('Cannot fetch the main register because it has not been set with BSLoader::SetRegister()');
140 return self
::SharedInstance()->main
;
144 if (!isset(self
::SharedInstance()->registers
["$index"]))
146 throw new Exception('Invalid register index passed to BSLoader::GetRegister()');
148 return self::SharedInstance()->registers["$index"];
152 // ###################################################################
154 * Loads the specified module.
156 * @param string Module name
158 * @return object Instantiated module
160 public static function LoadModule($name)
162 if (!file_exists("ISSO/$name.php"))
164 throw new Exception('Specified module does not exist');
167 require_once("ISSO/$name.php");
171 if (!class_exists($class))
173 throw new Exception('Specifed module does not conform to the ISSO specification, or the class is missing');
180 /*=====================================================================*\
181 || ###################################################################
184 || ###################################################################
185 \*=====================================================================*/