drupal_bootstrap

Versions
4.7 – 6
drupal_bootstrap($phase)
7
drupal_bootstrap($phase = NULL, $new_phase = TRUE)

A string describing a phase of Drupal to load. Each phase adds to the previous one, so invoking a later phase automatically runs the earlier phases too. The most important usage is that if you want to access the Drupal database from a script without loading anything else, you can include bootstrap.inc, and call drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE).

Parameters

$phase A constant. Allowed values are the DRUPAL_BOOTSTRAP_* constants.

$new_phase A boolean, set to FALSE if calling drupal_bootstrap from inside a function called from drupal_bootstrap (recursion).

Return value

The most recently completed phase.

▾ 8 functions call drupal_bootstrap()

drupal_get_bootstrap_phase in includes/bootstrap.inc
Returns the current bootstrap phase for this Drupal process.
drupal_install_system in includes/install.inc
Callback to install the system module.
drupal_theme_initialize in includes/theme.inc
Initialize the theme system by loading the theme.
install_begin_request in ./install.php
Begin an installation request, modifying the installation state as needed.
install_bootstrap_full in ./install.php
Installation task; perform a full bootstrap of Drupal.
statistics_exit in modules/statistics/statistics.module
Implement hook_exit().
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.
_drupal_bootstrap_page_cache in includes/bootstrap.inc
Bootstrap page cache: Try to serve a page from cache.

Code

includes/bootstrap.inc, line 1468

<?php
function drupal_bootstrap($phase = NULL, $new_phase = TRUE) {
  // Not drupal_static(), because does not depend on any run-time information.
  static $phases = array(
    DRUPAL_BOOTSTRAP_CONFIGURATION,
    DRUPAL_BOOTSTRAP_PAGE_CACHE,
    DRUPAL_BOOTSTRAP_DATABASE,
    DRUPAL_BOOTSTRAP_VARIABLES,
    DRUPAL_BOOTSTRAP_SESSION,
    DRUPAL_BOOTSTRAP_PAGE_HEADER,
    DRUPAL_BOOTSTRAP_LANGUAGE,
    DRUPAL_BOOTSTRAP_FULL,
  );
  // Not drupal_static(), because the only legitimate API to control this is to
  // call drupal_bootstrap() with a new phase parameter.
  static $final_phase;
  // Not drupal_static(), because it's impossible to roll back to an earlier
  // bootstrap state.
  static $completed_phase = -1;

  // When not recursing, store the phase name so it's not forgotten while
  // recursing.
  if ($new_phase) {
    $final_phase = $phase;
  }
  if (isset($phase)) {
    // Call a phase if it has not been called before and is below the requested
    // phase.
    while ($phases && $phase > $completed_phase && $final_phase > $completed_phase) {
      $current_phase = array_shift($phases);
      switch ($current_phase) {
        case DRUPAL_BOOTSTRAP_CONFIGURATION:
          _drupal_bootstrap_configuration();
          break;

        case DRUPAL_BOOTSTRAP_PAGE_CACHE:
          _drupal_bootstrap_page_cache();
          break;

        case DRUPAL_BOOTSTRAP_DATABASE:
          _drupal_bootstrap_database();
          break;

        case DRUPAL_BOOTSTRAP_VARIABLES:
          _drupal_bootstrap_variables();
          break;

        case DRUPAL_BOOTSTRAP_SESSION:
          require_once DRUPAL_ROOT . '/' . variable_get('session_inc', 'includes/session.inc');
          drupal_session_initialize();
          break;

        case DRUPAL_BOOTSTRAP_PAGE_HEADER:
          _drupal_bootstrap_page_header();
          break;

        case DRUPAL_BOOTSTRAP_LANGUAGE:
          drupal_language_initialize();
          break;

        case DRUPAL_BOOTSTRAP_FULL:
          require_once DRUPAL_ROOT . '/includes/common.inc';
          _drupal_bootstrap_full();
          break;
      }
      // This function is reentrant. Only update the completed phase when the
      // current call actually resulted in a progress in the bootstrap process.
      if ($current_phase > $completed_phase) {
        $completed_phase = $current_phase;
      }
    }
  }
  return $completed_phase;
}
?>
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.