From 3ecf2c643ef2189d26a42b34209ed3dd4a6bccf3 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Tue, 15 Aug 2006 23:53:29 +0000 Subject: [PATCH] Adding Loader module --- Loader.php | 186 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 Loader.php diff --git a/Loader.php b/Loader.php new file mode 100644 index 0000000..6b16b36 --- /dev/null +++ b/Loader.php @@ -0,0 +1,186 @@ +instance) + { + $this->instance = self::__construct(); + } + return $this->instance; + } + + // ################################################################### + /** + * Creates a new BSRegister instance and returns it. + * + * @return object New register + */ + public static function NewRegister() + { + require_once('ISSO/Register.php'); + + self::SharedInstance()->registers[] = new BSRegister(); + + return end(self::SharedInstance()->registers); + } + + // ################################################################### + /** + * Returns the array of all the registers + * + * @return array The array of all the registers + */ + public static function GetAllRegisters() + { + return self::SharedInstance()->registers; + } + + // ################################################################### + /** + * Sets the main register + * + * @param object New main register + */ + public static function SetRegister(BSRegister $newreg) + { + if (get_class($newreg) != 'BSRegister') + { + trigger_error('BSLoader::SetRegister() was not passed a BSRegister object', E_USER_ERROR); + } + + self::SharedInstance()->main = $register; + } + + // ################################################################### + /** + * Gets the main register if no argument is passed, or an arbitrary + * one if the index of a register is passed. + * + * @param integer Register index + * + * @return object Specified register + */ + public static function &GetRegister($index = null) + { + if (is_null($index)) + { + if (!isset(self::SharedInstance()->main)) + { + trigger_error('Cannot fetch the main register because it has not been set with BSLoader::SetRegister()', E_USER_ERROR); + } + return self::SharedInstance()->main; + } + else + { + if (!isset(self::SharedInstance()->registers["$index"])) + { + trigger_error('Invalid register index passed to BSLoader::GetRegister()', E_USER_ERROR); + } + return self::SharedInstance()->registers["$index"]; + } + } + + // ################################################################### + /** + * Loads the specified module. + * + * @param string Module name + * + * @return object Instantiated module + */ + public static function LoadModule($name) + { + if (!file_exists("ISSO/$name.php")) + { + trigger_error('Specified module does not exist', E_USER_ERROR); + } + + require_once("ISSO/$name.php"); + + $class = "BS$name"; + + if (!class_exists($class)) + { + trigger_error('Specifed module does not conform to the ISSO specification, or the class is missing', E_USER_ERROR); + } + + return new $class; + } +} + +/*=====================================================================*\ +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file -- 2.43.5