Index: includes/bootstrap.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v retrieving revision 1.228 diff -u -r1.228 bootstrap.inc --- includes/bootstrap.inc 20 Sep 2008 20:22:23 -0000 1.228 +++ includes/bootstrap.inc 4 Oct 2008 21:57:37 -0000 @@ -277,32 +277,28 @@ * will be recognized. Defaults to TRUE. During initial installation, * this is set to FALSE so that Drupal can detect a matching directory, * then create a new settings.php file in it. - * @param reset - * Force a full search for matching directories even if one had been - * found previously. + * * @return * The path of the matching directory. */ -function conf_path($require_settings = TRUE, $reset = FALSE) { - static $conf = ''; - - if ($conf && !$reset) { - return $conf; - } +function conf_path($require_settings = TRUE) { + $conf = &drupal_static('conf_path', ''); - $confdir = 'sites'; - $uri = explode('/', $_SERVER['SCRIPT_NAME'] ? $_SERVER['SCRIPT_NAME'] : $_SERVER['SCRIPT_FILENAME']); - $server = explode('.', implode('.', array_reverse(explode(':', rtrim($_SERVER['HTTP_HOST'], '.'))))); - for ($i = count($uri) - 1; $i > 0; $i--) { - for ($j = count($server); $j > 0; $j--) { - $dir = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, 0, $i)); - if (file_exists("$confdir/$dir/settings.php") || (!$require_settings && file_exists("$confdir/$dir"))) { - $conf = "$confdir/$dir"; - return $conf; + if (!$conf) { + $confdir = 'sites'; + $uri = explode('/', $_SERVER['SCRIPT_NAME'] ? $_SERVER['SCRIPT_NAME'] : $_SERVER['SCRIPT_FILENAME']); + $server = explode('.', implode('.', array_reverse(explode(':', rtrim($_SERVER['HTTP_HOST'], '.'))))); + for ($i = count($uri) - 1; $i > 0; $i--) { + for ($j = count($server); $j > 0; $j--) { + $dir = implode('.', array_slice($server, -$j)) . implode('.', array_slice($uri, 0, $i)); + if (file_exists("$confdir/$dir/settings.php") || (!$require_settings && file_exists("$confdir/$dir"))) { + $conf = "$confdir/$dir"; + return $conf; + } } } + $conf = "$confdir/default"; } - $conf = "$confdir/default"; return $conf; } @@ -429,7 +425,7 @@ * The filename of the requested item. */ function drupal_get_filename($type, $name, $filename = NULL) { - static $files = array(); + $files = &drupal_static('drupal_get_filename', array()); if (!isset($files[$type])) { $files[$type] = array(); @@ -593,7 +589,7 @@ * TRUE if the item is loaded or has already been loaded. */ function drupal_load($type, $name) { - static $files = array(); + $files = &drupal_static('drupal_load', array()); if (isset($files[$type][$name])) { return TRUE; @@ -966,7 +962,8 @@ * DRUPAL_BOOTSTRAP_FULL: Drupal is fully loaded, validate and fix input data. */ function drupal_bootstrap($phase) { - static $phases = array(DRUPAL_BOOTSTRAP_CONFIGURATION, DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE, DRUPAL_BOOTSTRAP_DATABASE, DRUPAL_BOOTSTRAP_ACCESS, DRUPAL_BOOTSTRAP_SESSION, DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE, DRUPAL_BOOTSTRAP_LANGUAGE, DRUPAL_BOOTSTRAP_PATH, DRUPAL_BOOTSTRAP_FULL), $phase_index = 0; + $phases = &drupal_static('drupal_bootstrap_phases', array(DRUPAL_BOOTSTRAP_CONFIGURATION, DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE, DRUPAL_BOOTSTRAP_DATABASE, DRUPAL_BOOTSTRAP_ACCESS, DRUPAL_BOOTSTRAP_SESSION, DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE, DRUPAL_BOOTSTRAP_LANGUAGE, DRUPAL_BOOTSTRAP_PATH, DRUPAL_BOOTSTRAP_FULL)); + $phase_index = &drupal_static('drupal_bootstrap_phase_index', 0); while ($phase >= $phase_index && isset($phases[$phase_index])) { $current_phase = $phases[$phase_index]; @@ -1101,11 +1098,7 @@ * run both during installation and normal operation. */ function get_t() { - static $t; - if (is_null($t)) { - $t = function_exists('install_main') ? 'st' : 't'; - } - return $t; + return drupal_static('get_t', function_exists('install_main') ? 'st' : 't'); } /** @@ -1129,16 +1122,9 @@ * Get a list of languages set up indexed by the specified key * * @param $field The field to index the list with. - * @param $reset Boolean to request a reset of the list. */ -function language_list($field = 'language', $reset = FALSE) { - static $languages = NULL; - - // Reset language list - if ($reset) { - $languages = NULL; - } - +function language_list($field = 'language') { + $languages = &drupal_static('language_list'); // Init language list if (!isset($languages)) { if (variable_get('language_count', 1) > 1 || module_exists('locale')) { @@ -1194,7 +1180,7 @@ * environments. */ function ip_address($reset = FALSE) { - static $ip_address = NULL; + $ip_address = &drupal_static('ip_address'); if (!isset($ip_address) || $reset) { $ip_address = $_SERVER['REMOTE_ADDR']; @@ -1224,6 +1210,41 @@ } /** + * Central static facility with a reset. + * + * @param $name + * Name of the static bin. It's practical to use the caller function name as + * prefix or as the name itself. + * @param $default + * Optional default value. drupal_static_reset will reload this value. Note + * that the first non-NULL value will be stored. + * @param $reset + * TRUE to reset. Internal use only. + */ +function &drupal_static($name, $default = NULL, $reset = FALSE) { + static $cache; + // Store the default, if not yet set to a non-NULL value. + if (!isset($cache[$name]['default'])) { + $cache[$name]['default'] = $default; + $cache[$name]['data'] = $default; + } + elseif ($reset) { + $cache[$name]['data'] = $cache[$name]['default']; + } + return $cache[$name]['data']; +} + +/** + * Central static facility reset method. + * + * @param $name + * Name of the static bin to reset. + */ +function drupal_static_reset($name) { + drupal_static($name, NULL, TRUE); +} + +/** * @ingroup schemaapi * @{ */ Index: includes/install.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/install.inc,v retrieving revision 1.72 diff -u -r1.72 install.inc --- includes/install.inc 1 Oct 2008 00:27:29 -0000 1.72 +++ includes/install.inc 4 Oct 2008 21:58:57 -0000 @@ -331,7 +331,8 @@ */ function drupal_rewrite_settings($settings = array(), $prefix = '') { $default_settings = 'sites/default/default.settings.php'; - $settings_file = conf_path(FALSE, TRUE) . '/' . $prefix . 'settings.php'; + drupal_static_reset('conf_path'); + $settings_file = './' . conf_path(FALSE) . '/' . $prefix . 'settings.php'; // Build list of setting names and insert the values into the global namespace. $keys = array(); Index: includes/locale.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/locale.inc,v retrieving revision 1.187 diff -u -r1.187 locale.inc --- includes/locale.inc 27 Sep 2008 20:23:30 -0000 1.187 +++ includes/locale.inc 4 Oct 2008 22:03:23 -0000 @@ -32,7 +32,8 @@ * User interface for the language overview screen. */ function locale_languages_overview_form() { - $languages = language_list('language', TRUE); + drupal_static_reset('language'); + $languages = language_list('language'); $options = array(); $form['weight'] = array('#tree' => TRUE); @@ -491,7 +492,8 @@ * Overview screen for translations. */ function locale_translate_overview_screen() { - $languages = language_list('language', TRUE); + drupal_static_reset('language_list'); + $languages = language_list('language'); $groups = module_invoke_all('locale', 'groups'); // Build headers with all groups in order. @@ -545,7 +547,8 @@ */ function locale_translate_seek_form() { // Get all languages, except English - $languages = locale_language_list('name', TRUE); + drupal_static_reset('language_list'); + $languages = locale_language_list('name'); unset($languages['en']); // Present edit form preserving previous user settings @@ -598,7 +601,8 @@ */ function locale_translate_import_form() { // Get all languages, except English - $names = locale_language_list('name', TRUE); + drupal_static_reset('language_list'); + $names = locale_language_list('name'); unset($names['en']); if (!count($names)) { @@ -656,7 +660,8 @@ if ($file = file_save_upload('file')) { // Add language, if not yet supported - $languages = language_list('language', TRUE); + drupal_static_reset('language_list'); + $languages = language_list('language'); $langcode = $form_state['values']['langcode']; if (!isset($languages[$langcode])) { $predefined = _locale_get_predefined_list(); @@ -693,7 +698,8 @@ */ function locale_translate_export_screen() { // Get all languages, except English - $names = locale_language_list('name', TRUE); + drupal_static_reset('language_list'); + $names = locale_language_list('name'); unset($names['en']); $output = ''; // Offer translation export if any language is set up. Index: install.php =================================================================== RCS file: /cvs/drupal/drupal/install.php,v retrieving revision 1.134 diff -u -r1.134 install.php --- install.php 1 Oct 2008 00:27:29 -0000 1.134 +++ install.php 4 Oct 2008 22:09:20 -0000 @@ -184,7 +184,8 @@ include_once DRUPAL_ROOT . '/includes/form.inc'; $database = $databases['default']['default']; - $settings_file = './' . conf_path(FALSE, TRUE) . '/settings.php'; + drupal_static_reset('conf_path'); + $settings_file = './' . conf_path(FALSE) . '/settings.php'; $form_state = array(); _install_settings_form_validate($database, $settings_file, $form_state); @@ -201,8 +202,8 @@ function install_change_settings($profile = 'default', $install_locale = '') { global $databases, $db_prefix; - $conf_path = './' . conf_path(FALSE, TRUE); - $settings_file = $conf_path . '/settings.php'; + drupal_static_reset('conf_path'); + $settings_file = './' . conf_path(FALSE) . '/settings.php'; $database = isset($databases['default']['default']) ? $databases['default']['default'] : array(); // We always need this because we want to run form_get_errors. @@ -900,7 +901,8 @@ // If Drupal is not set up already, we need to create a settings file. if (!$verify) { $writable = FALSE; - $conf_path = './' . conf_path(FALSE, TRUE); + drupal_static_reset('conf_path'); + $conf_path = './' . conf_path(FALSE); $settings_file = $conf_path . '/settings.php'; $file = $conf_path; $exists = FALSE; Index: modules/translation/translation.test =================================================================== RCS file: /cvs/drupal/drupal/modules/translation/translation.test,v retrieving revision 1.3 diff -u -r1.3 translation.test --- modules/translation/translation.test 30 May 2008 07:30:53 -0000 1.3 +++ modules/translation/translation.test 4 Oct 2008 22:11:17 -0000 @@ -87,7 +87,8 @@ $edit['langcode'] = $language_code; $this->drupalPost('admin/settings/language/add', $edit, t('Add language')); - $languages = language_list('language', TRUE); // make sure not using cached version + drupal_static_reset('language_list'); + $languages = language_list(); $this->assertTrue(array_key_exists($language_code, $languages), t('Language was installed successfully.')); if (array_key_exists($language_code, $languages)) {