/** * Return an instance of this class based on the index given. * This will create the instance if it doesn't exist. * * @param string $index * @param boolean $replace. Defaults to false. If true and * $index is non null, then we create a new instance at $index. * @return I2CE_MagicData */ public static function instance($index = NULL, $replace = FALSE) { if (!is_array(self::$instances)) { self::$instances = array(); } if ($index === NULL) { $index = self::$last_instance; } if (!is_string($index) || empty($index)) { I2CE_MagicDataNode::raiseError("Invalid index passed to " . "I2CE_MagicData::instance(): " . "{$index}"); return NULL; } self::$last_instance = $index; if (!array_key_exists($index, self::$instances) || !self::$instances[$index] instanceof I2CE_MagicData || $replace) { self::$instances[$index] = new I2CE_MagicData($index); self::$instances[$index]->instance = $index; } return self::$instances[$index]; }