You are here

10 完成阶段

admin 的头像
Submitted by admin on 星期五, 2015-07-24 09:55

作者:老葛,北京亚艾元软件有限责任公司,http://www.yaiyuan.com

我们来看阶段7,也就是完成阶段,对应的代码:

        case DRUPAL_BOOTSTRAP_FULL:

          require_once DRUPAL_ROOT . '/includes/common.inc';

          _drupal_bootstrap_full();

          break;

在这里,首先加载includes/common.inc文件,接着将这个阶段的工作,委托给了_drupal_bootstrap_full函数,注意这个函数位于common.inc文件中。我们打开这个文件,找到这个函数的定义:

function _drupal_bootstrap_full() {

  static $called = FALSE;

 

  if ($called) {

    return;

  }

  $called = TRUE;

  require_once DRUPAL_ROOT . '/' . variable_get('path_inc', 'includes/path.inc');

  require_once DRUPAL_ROOT . '/includes/theme.inc';

  require_once DRUPAL_ROOT . '/includes/pager.inc';

  require_once DRUPAL_ROOT . '/' . variable_get('menu_inc', 'includes/menu.inc');

  require_once DRUPAL_ROOT . '/includes/tablesort.inc';

  require_once DRUPAL_ROOT . '/includes/file.inc';

  require_once DRUPAL_ROOT . '/includes/unicode.inc';

  require_once DRUPAL_ROOT . '/includes/image.inc';

  require_once DRUPAL_ROOT . '/includes/form.inc';

  require_once DRUPAL_ROOT . '/includes/mail.inc';

  require_once DRUPAL_ROOT . '/includes/actions.inc';

  require_once DRUPAL_ROOT . '/includes/ajax.inc';

  require_once DRUPAL_ROOT . '/includes/token.inc';

  require_once DRUPAL_ROOT . '/includes/errors.inc';

 

  // Detect string handling method

  unicode_check();

  // Undo magic quotes

  fix_gpc_magic();

  // Load all enabled modules

  module_load_all();

  // Make sure all stream wrappers are registered.

  file_get_stream_wrappers();

 

  $test_info = &$GLOBALS['drupal_test_info'];

  if (!empty($test_info['in_child_site'])) {

    // Running inside the simpletest child site, log fatal errors to test

    // specific file directory.

    ini_set('log_errors', 1);

    ini_set('error_log', 'public://error.log');

  }

 

  // Initialize $_GET['q'] prior to invoking hook_init().

  drupal_path_initialize();

 

  // Let all modules take action before the menu system handles the request.

  // We do not want this while running update.php.

  if (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update') {

    // Prior to invoking hook_init(), initialize the theme (potentially a custom

    // one for this page), so that:

    // - Modules with hook_init() implementations that call theme() or

    //   theme_get_registry() don't initialize the incorrect theme.

    // - The theme can have hook_*_alter() implementations affect page building

    //   (e.g., hook_form_alter(), hook_node_view_alter(), hook_page_alter()),

    //   ahead of when rendering starts.

    menu_set_custom_theme();

    drupal_theme_initialize();

    module_invoke_all('init');

  }

}

这个函数里面做的第一个工作,就是加载文件,path.inctheme.incpager.incmenu.inctablesort.incfile.incunicode.incimage.incform.incmail.incactions.incajax.inctoken.incerrors.inc就是在这个时候加载的。

unicode_check用来判断字符串处理方法,Drupal能够处理各种字符,这里需要检查一下PHPunicode的支持。fix_gpc_magic,这个函数比较陌生,我后来查看函数的具体定义,和相关的文档,才弄明白的这个函数的作用,这个函数最终调用的是stripslashes,它的作用是去除转义反斜线,比如:

\') 转换为('

双反斜线(\\)被转换为单个反斜线(\

 

module_load_all负责加载所有的module文件。file_get_stream_wrappers负责注册Drupal的流包装器(stream wrappers)。

$test_info这段代码,与simpletest有关,我们这里没有用到,所以跳过。

drupal_path_initialize负责路径的初始化,具体工作就是正确的设置$_GET['q']

最后设置当前的主题,初始化主题,触发hook_init钩子。到此,整个引导指令就全部完成了,Drupal已经启动起来了。


Drupal版本: