Make sure the init callback is only called once.

pull/11/head
Mike Cao 14 years ago
parent 1958c1f1a5
commit 9d43930d2d

@ -102,10 +102,12 @@ class Flight {
/** /**
* Loads a registered class. * Loads a registered class.
* *
* @param string $class Class name * @param string $name Method name
* @param array $method List of methods to load * @param bool $shared Shared instance
*/ */
public static function load($name, $shared = true) { public static function load($name, $shared = true) {
static $loaded = array();
if (isset(self::$classes[$name])) { if (isset(self::$classes[$name])) {
list($class, $params, $callback) = self::$classes[$name]; list($class, $params, $callback) = self::$classes[$name];
@ -113,14 +115,19 @@ class Flight {
self::getInstance($class, $params) : self::getInstance($class, $params) :
self::getClass($class, $params); self::getClass($class, $params);
if (!$shared || !isset($loaded[$name])) {
if ($callback) self::execute($callback, $ref = array($obj)); if ($callback) self::execute($callback, $ref = array($obj));
$loaded[$name] = true;
}
return $obj; return $obj;
} }
$class = ucfirst($name);
return ($shared) ? return ($shared) ?
self::getInstance(ucfirst($name)) : self::getInstance($class) :
self::getClass(ucfirst($name)); self::getClass($class);
} }
/** /**

Loading…
Cancel
Save