/** * Singleton function used to manage this object. * * @param bool $loadFromDB * whether to load from the database. * @param bool $force * whether to force a reconstruction. * * @return CRM_Core_Config */ public static function &singleton($loadFromDB = TRUE, $force = FALSE) { if (self::$_singleton === NULL || $force) { // goto a simple error handler $GLOBALS['civicrm_default_error_scope'] = CRM_Core_TemporaryErrorScope::create(array('CRM_Core_Error', 'handle')); $errorScope = CRM_Core_TemporaryErrorScope::create(array('CRM_Core_Error', 'simpleHandler')); // lets ensure we set E_DEPRECATED to minimize errors // CRM-6327 if (defined('E_DEPRECATED')) { error_reporting(error_reporting() & ~E_DEPRECATED); } // first, attempt to get configuration object from cache $cache = CRM_Utils_Cache::singleton(); self::$_singleton = $cache->get('CRM_Core_Config' . CRM_Core_Config::domainID()); // if not in cache, fire off config construction if (!self::$_singleton) { self::$_singleton = new CRM_Core_Config(); self::$_singleton->_initialize($loadFromDB); //initialize variables. for gencode we cannot load from the //db since the db might not be initialized if ($loadFromDB) { // initialize stuff from the settings file self::$_singleton->setCoreVariables(); self::$_singleton->_initVariables(); // I don't think we need to do this twice // however just keeping this commented for now in 4.4 // in case we hit any issues - CRM-13064 // We can safely delete this once we release 4.4.4 // self::$_singleton->setCoreVariables(); } $cache->set('CRM_Core_Config' . CRM_Core_Config::domainID(), self::$_singleton); } else { // we retrieve the object from memcache, so we now initialize the objects self::$_singleton->_initialize($loadFromDB); // CRM-9803, NYSS-4822 // this causes various settings to be reset and hence we should // only use the config object that we retrieved from memcache } self::$_singleton->initialized = 1; if (isset(self::$_singleton->customPHPPathDir) && self::$_singleton->customPHPPathDir) { $include_path = self::$_singleton->customPHPPathDir . PATH_SEPARATOR . get_include_path(); set_include_path($include_path); } // set the callback at the very very end, to avoid an infinite loop // set the error callback unset($errorScope); // call the hook so other modules can add to the config // again doing this at the very very end CRM_Utils_Hook::config(self::$_singleton); // make sure session is always initialised $session = CRM_Core_Session::singleton(); // for logging purposes, pass the userID to the db $userID = $session->get('userID'); if ($userID) { CRM_Core_DAO::executeQuery('SET @civicrm_user_id = %1', array(1 => array($userID, 'Integer'))); } // initialize authentication source self::$_singleton->initAuthSrc(); } return self::$_singleton; }