conf_path

Versions
4.7 – 5
conf_path()
6 – 7
conf_path($require_settings = TRUE, $reset = FALSE)

Find the appropriate configuration directory.

Try finding a matching configuration directory by stripping the website's hostname from left to right and pathname from right to left. The first configuration file found will be used; the remaining will ignored. If no configuration file is found, return a default value '$confdir/default'.

Example for a fictitious site installed at http://www.drupal.org:8080/mysite/test/ the 'settings.php' is searched in the following directories:

1. $confdir/8080.www.drupal.org.mysite.test 2. $confdir/www.drupal.org.mysite.test 3. $confdir/drupal.org.mysite.test 4. $confdir/org.mysite.test

5. $confdir/8080.www.drupal.org.mysite 6. $confdir/www.drupal.org.mysite 7. $confdir/drupal.org.mysite 8. $confdir/org.mysite

9. $confdir/8080.www.drupal.org 10. $confdir/www.drupal.org 11. $confdir/drupal.org 12. $confdir/org

13. $confdir/default

If a file named sites.php is present in the $confdir, it will be loaded prior to scanning for directories. It should define an associative array named $sites, which maps domains to directories. It should be in the form of:

$sites = array( 'The url to alias' => 'A directory within the sites directory' );

For example:

$sites = array( 'devexample.com' => 'example.com', 'localhost/example' => 'example.com', );

The above array will cause Drupal to look for a directory named "example.com" in the sites directory whenever a request comes from "example.com", "devexample.com", or "localhost/example". That is useful on development servers, where the domain name may not be the same as the domain of the live server. Since Drupal stores file paths into the database (files, system table, etc.) this will ensure the paths are correct while accessed on development servers.

Parameters

$require_settings Only configuration directories with an existing settings.php file 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.

reset Force a full search for matching directories even if one had been found previously.

Return value

The path of the matching directory.

▾ 9 functions call conf_path()

drupal_rewrite_settings in includes/install.inc
Replace values in settings.php with values in the submitted array.
drupal_settings_initialize in includes/bootstrap.inc
Loads the configuration and sets the base URL, cookie domain, and session name correctly.
drupal_system_listing in includes/common.inc
Return an array of system file objects.
system_requirements in modules/system/system.install
Test and report Drupal installation requirements.
system_update_7035 in modules/system/system.install
Migrate upload module files to the new {file} table.
update_fix_d7_requirements in includes/update.inc
Perform Drupal 6.x to 7.x updates that are required for update.php to function properly.
update_manager_confirm_update_form_submit in modules/update/update.manager.inc
Submit handler for the form to confirm that an update should continue.
update_manager_install_form_submit in modules/update/update.manager.inc
Handle form submission when installing new projects via the update manager.
update_prepare_d7_bootstrap in includes/update.inc
Users who still have a Drupal 6 database (and are in the process of updating to Drupal 7) need extra help before a full bootstrap can be achieved. This function does the necessary preliminary work that allows the bootstrap to be successful.

Code

includes/bootstrap.inc, line 365

<?php
function conf_path($require_settings = TRUE, $reset = FALSE) {
  $conf = &drupal_static(__FUNCTION__, '');

  if ($conf && !$reset) {
    return $conf;
  }

  $confdir = 'sites';

  $sites = array();
  if (file_exists(DRUPAL_ROOT . '/' . $confdir . '/sites.php')) {
    // This will overwrite $sites with the desired mappings.
    include(DRUPAL_ROOT . '/' . $confdir . '/sites.php');
  }

  $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 (isset($sites[$dir]) && file_exists(DRUPAL_ROOT . '/' . $confdir . '/' . $sites[$dir])) {
        $dir = $sites[$dir];
      }
      if (file_exists(DRUPAL_ROOT . '/' . $confdir . '/' . $dir . '/settings.php') || (!$require_settings && file_exists(DRUPAL_ROOT . '/' . $confdir . '/' . $dir))) {
        $conf = "$confdir/$dir";
        return $conf;
      }
    }
  }
  $conf = "$confdir/default";
  return $conf;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.