]> src.bluestatic.org Git - isso.git/blob - Loader.php
We need to return; when we trigger an error
[isso.git] / Loader.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework [#]issoversion[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
6 || #
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.
10 || #
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
14 || # more details.
15 || #
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 \*=====================================================================*/
21
22 /**
23 * System loader (Loader.php)
24 *
25 * @package ISSO
26 */
27
28 /**
29 * System Loader
30 *
31 * This class contains static methods that are used to create new registers and
32 * load modules.
33 *
34 * @author Blue Static
35 * @copyright Copyright ©2002 - [#]year[#], Blue Static
36 * @version $Revision$
37 * @package ISSO
38 *
39 */
40 class BSLoader
41 {
42 /**
43 * Singleton instance
44 * @var object
45 */
46 private static $instance;
47
48 /**
49 * Array of all the registers
50 * @var array
51 */
52 private $registers = array();
53
54 /**
55 * The main register
56 * @var object
57 */
58 private $main;
59
60 // ###################################################################
61 /**
62 * Constructor
63 */
64 private function __construct() {}
65
66 // ###################################################################
67 /**
68 * Returns the shared instance of the BSLoader singleton class.
69 *
70 * @return object The BSLoader shared instance
71 */
72 private function SharedInstance()
73 {
74 if (!self::$instance)
75 {
76 self::$instance = new BSLoader;
77 }
78 return self::$instance;
79 }
80
81 // ###################################################################
82 /**
83 * Creates a new BSRegister instance and returns it.
84 *
85 * @return object New register
86 */
87 public static function NewRegister()
88 {
89 require_once('ISSO/Register.php');
90
91 self::SharedInstance()->registers[] = new BSRegister();
92
93 return end(self::SharedInstance()->registers);
94 }
95
96 // ###################################################################
97 /**
98 * Returns the array of all the registers
99 *
100 * @return array The array of all the registers
101 */
102 public static function GetAllRegisters()
103 {
104 return self::SharedInstance()->registers;
105 }
106
107 // ###################################################################
108 /**
109 * Sets the main register
110 *
111 * @param object New main register
112 */
113 public static function SetRegister($register)
114 {
115 if (get_class($register) != 'BSRegister')
116 {
117 trigger_error('BSLoader::SetRegister() was not passed a BSRegister object');
118 return;
119 }
120
121 self::SharedInstance()->main = $register;
122 }
123
124 // ###################################################################
125 /**
126 * Gets the main register if no argument is passed, or an arbitrary
127 * one if the index of a register is passed.
128 *
129 * @param integer Register index
130 *
131 * @return object Specified register
132 */
133 public static function &GetRegister($index = null)
134 {
135 if (is_null($index))
136 {
137 if (!isset(self::SharedInstance()->main))
138 {
139 trigger_error('Cannot fetch the main register because it has not been set with BSLoader::SetRegister()');
140 return;
141 }
142 return self::SharedInstance()->main;
143 }
144 else
145 {
146 if (!isset(self::SharedInstance()->registers["$index"]))
147 {
148 trigger_error('Invalid register index passed to BSLoader::GetRegister()');
149 return;
150 }
151 return self::SharedInstance()->registers["$index"];
152 }
153 }
154
155 // ###################################################################
156 /**
157 * Loads the specified module.
158 *
159 * @param string Module name
160 *
161 * @return object Instantiated module
162 */
163 public static function LoadModule($name)
164 {
165 if (!file_exists("ISSO/$name.php"))
166 {
167 trigger_error('Specified module does not exist');
168 return;
169 }
170
171 require_once("ISSO/$name.php");
172
173 $class = "BS$name";
174
175 if (!class_exists($class))
176 {
177 trigger_error('Specifed module does not conform to the ISSO specification, or the class is missing');
178 return
179 }
180
181 return new $class;
182 }
183 }
184
185 /*=====================================================================*\
186 || ###################################################################
187 || # $HeadURL$
188 || # $Id$
189 || ###################################################################
190 \*=====================================================================*/
191 ?>