/** * A static method implementing the Singleton pattern, persisting in between sessions * * @param boolean $forceCreate Forcibly create a new instance of the object * @param boolean $OnlyDBMode Create an object that only runs on DB mode. * @return JoomlapackCUBE * @static */ function &getInstance($forceCreate = false, $OnlyDBMode = false) { static $instance; if (is_object($instance) && !$forceCreate) { JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackCUBE::getInstance - Object in memory (OK)"); // An object already exists in memory. Return this. return $instance; } else { if ($forceCreate) { // If we are forced to create, we fool the code below by making it think that the CUBE // doesn't exist in the database. JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackCUBE::getInstance - Forced creation, removing CUBEObject"); $count = -1; JoomlapackTables::DeleteVar('CUBEObject'); } else { // Otherwise, look into the database for a stored CUBE object $count = JoomlapackTables::CountVar('CUBEObject'); } if ($count != 1) { // No stored object, we are forced to create a fresh object or something really // odd is going on with MySQL! JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackCUBE::getInstance - Not found in database, creating new instance"); $instance = new JoomlapackCUBE($OnlyDBMode); return $instance; } else { // Load from db JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackCUBE::getInstance - Loading from database"); // Get the includes first! JoomlapackCUBE::retrieveEngineIncludes(); // Then load the object $serialized = JoomlapackTables::ReadVar('CUBEObject'); $instance = unserialize($serialized); return $instance; } } }