function drupal_bootstrap

Ensures Drupal is bootstrapped to the specified phase.

In order to bootstrap Drupal from another PHP script, you can use this code:

define('DRUPAL_ROOT', '/path/to/drupal');
require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

Parameters

$phase: A constant telling which phase to bootstrap to. When you bootstrap to a particular phase, all earlier phases are run automatically. Possible values:

$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.

11 calls to drupal_bootstrap()
authorize.php in drupal/core/authorize.php
Administrative script for running authorized file operations.
drupal_get_bootstrap_phase in drupal/core/includes/bootstrap.inc
Returns the current bootstrap phase for this Drupal process.
drupal_handle_request in drupal/core/includes/bootstrap.inc
Handles an entire PHP request.
drupal_theme_initialize in drupal/core/includes/theme.inc
Initializes the theme system by loading the theme.
install_begin_request in drupal/core/includes/install.core.inc
Begins an installation request, modifying the installation state as needed.

... See full list

File

drupal/core/includes/bootstrap.inc, line 1776
Functions that need to be loaded on every Drupal request.

Code

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_KERNEL,
    DRUPAL_BOOTSTRAP_PAGE_CACHE,
    DRUPAL_BOOTSTRAP_DATABASE,
    DRUPAL_BOOTSTRAP_VARIABLES,
    DRUPAL_BOOTSTRAP_SESSION,
    DRUPAL_BOOTSTRAP_CODE,
    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 = -1;

  // Not drupal_static(), because it's impossible to roll back to an earlier
  // bootstrap state.
  static $stored_phase = -1;

  // When not recursing, store the phase name so it's not forgotten during
  // recursion. Additionally, ensure that $final_phase is never rolled back to an
  // earlier bootstrap state.
  if ($new_phase && $phase > $final_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 > $stored_phase && $final_phase > $stored_phase) {
      $current_phase = array_shift($phases);

      // This function is re-entrant. Only update the completed phase when the
      // current call actually resulted in a progress in the bootstrap process.
      if ($current_phase > $stored_phase) {
        $stored_phase = $current_phase;
      }
      switch ($current_phase) {
        case DRUPAL_BOOTSTRAP_CONFIGURATION:
          _drupal_bootstrap_configuration();
          break;
        case DRUPAL_BOOTSTRAP_KERNEL:
          _drupal_bootstrap_kernel();
          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 . '/' . settings()
            ->get('session_inc', 'core/includes/session.inc');
          drupal_session_initialize();
          break;
        case DRUPAL_BOOTSTRAP_CODE:
          require_once __DIR__ . '/common.inc';
          _drupal_bootstrap_code();
          break;
        case DRUPAL_BOOTSTRAP_FULL:
          _drupal_bootstrap_full();
          break;
      }
    }
  }
  return $stored_phase;
}