/** * Get site default global prefix * * @return string */ static public function getGlobalPrefix() { // Provide a fallback for multisite. This is on purpose not inside the // getPrefixForBin() function in order to decouple the unified prefix // variable logic and custom module related security logic, that is not // necessary for all backends. We can't just use HTTP_HOST, as multiple // hosts might be using the same database. Or, more commonly, a site // might not be a multisite at all, but might be using Drush leading to // a separate HTTP_HOST of 'default'. Likewise, we can't rely on // conf_path(), as settings.php might be modifying what database to // connect to. To mirror what core does with database caching we use // the DB credentials to inform our cache key. if (null === self::$globalPrefix) { if (isset($GLOBALS['db_url']) && is_string($GLOBALS['db_url'])) { // Drupal 6 specifics when using the cache_backport module, we // therefore cannot use \Database class to determine database // settings. self::$globalPrefix = md5($GLOBALS['db_url']); } else { require_once DRUPAL_ROOT . '/includes/database/database.inc'; $dbInfo = Database::getConnectionInfo(); $active = $dbInfo['default']; self::$globalPrefix = md5($active['host'] . $active['database'] . $active['prefix']['default']); } } return self::$globalPrefix; }
/** * For unit testing only reset internals. */ public static function reset() { self::$globalPrefix = null; self::$_clientInterface = null; self::$_client = null; }