From 7e7b0f7d1c8bbbf1da4d8bf3f9f4a86ee13ec11d Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 16 Oct 2005 09:00:14 +0000 Subject: [PATCH] Removed locate() in place of moving all code to load() --- kernel.php | 51 +++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/kernel.php b/kernel.php index 328cd61..9f1379b 100644 --- a/kernel.php +++ b/kernel.php @@ -215,33 +215,19 @@ class Shared_Object_Framework } /** - * Loads a framework extension + * Loads a framework module * - * @param string Name of the framework + * @param string Name of the framework file to load + * @param string Internal variable to initialize as; to not instantiate (just require) leave it as NULL + * @param bool Globalize the internal variable? */ - function load($framework) + function &load($framework, $asobject, $globalize = false) { - if (!$this->is_loaded($framework)) + if ($this->is_loaded($framework)) { - $newobj = $this->locate($framework); - $this->$newobj['OBJ'] = new $newobj['CLASS']($this); - $GLOBALS["$newobj[OBJ]"] =& $this->$newobj['OBJ']; - $this->modules["$framework"] = $newobj['OBJECT']; + return $this->getobj($framework); } - } - - /** - * Includes a framework module. Module definitions need three variables: - * class, object, and obj. Class is the name of the class, object is - * the name human-readable name, and obj is the name that the module - * should be initialized as; this is used in class extensions. - * - * @param string Name of the framework - * - * @return array List of initialization variables - */ - function locate($framework) - { + if ($this->sourcepath == '') { trigger_error('Invalid sourcepath specified', E_USER_ERROR); @@ -250,13 +236,30 @@ class Shared_Object_Framework if (file_exists($this->sourcepath . $framework . '.php')) { require_once($this->sourcepath . $framework . '.php'); - return array('CLASS' => $CLASS, 'OBJECT' => $OBJECT, 'OBJ' => $OBJ); } else { trigger_error('Could not find the framework ' . $this->sourcepath . $framework . '.php', E_USER_ERROR); - exit; } + + if ($asobject === null) + { + return; + } + + if (isset($this->$asobject)) + { + trigger_error('Cannot instantiate framework `' . $framework . '` into `' . $asobject '`', E_USER_ERROR); + } + + $this->$asobject = new $framework(); + + if ($globalize) + { + $GLOBALS["$asobject"] =& $this->$asobject; + } + + return $this->$asobject; } /** -- 2.43.5