Index: includes/bootstrap.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v retrieving revision 1.320 diff -u -p -r1.320 bootstrap.inc --- includes/bootstrap.inc 2 Nov 2009 03:46:43 -0000 1.320 +++ includes/bootstrap.inc 2 Nov 2009 18:23:23 -0000 @@ -1447,7 +1447,41 @@ function drupal_bootstrap($phase = NULL, // phase. while ($phases && $phase > $completed_phase && $final_phase > $completed_phase) { $current_phase = array_shift($phases); - _drupal_bootstrap($current_phase); + 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) { @@ -1469,114 +1503,99 @@ function drupal_get_bootstrap_phase() { return drupal_bootstrap(); } -function _drupal_bootstrap($phase) { - global $conf, $user; - static $cache; - - switch ($phase) { - - case DRUPAL_BOOTSTRAP_CONFIGURATION: - drupal_environment_initialize(); - // Start a page timer: - timer_start('page'); - // Initialize the configuration, including variables from settings.php. - drupal_settings_initialize(); - break; - - case DRUPAL_BOOTSTRAP_PAGE_CACHE: - // Allow specifying special cache handlers in settings.php, like - // using memcached or files for storing cache information. - require_once DRUPAL_ROOT . '/' . variable_get('cache_inc', 'includes/cache.inc'); - // Check for a cache mode force from settings.php. - if (variable_get('page_cache_without_database')) { - $cache_mode = CACHE_NORMAL; - } - else { - drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES, FALSE); - $cache_mode = variable_get('cache'); - } - drupal_block_denied(ip_address()); - // If there is no session cookie and cache is enabled (or forced), try - // to serve a cached page. - if (!isset($_COOKIE[session_name()]) && $cache_mode == CACHE_NORMAL) { - // Make sure there is a user object because it's timestamp will be - // checked, hook_boot might check for anonymous user etc. - $user = drupal_anonymous_user(); - // Get the page from the cache. - $cache = drupal_page_get_cache(); - // If there is a cached page, display it. - if (is_object($cache)) { - // If the skipping of the bootstrap hooks is not enforced, call - // hook_boot. - if (variable_get('page_cache_invoke_hooks', TRUE)) { - bootstrap_invoke_all('boot'); - } - header('X-Drupal-Cache: HIT'); - drupal_serve_page_from_cache($cache); - // If the skipping of the bootstrap hooks is not enforced, call - // hook_exit. - if (variable_get('page_cache_invoke_hooks', TRUE)) { - bootstrap_invoke_all('exit'); - } - // We are done. - exit; - } - } - break; - - case DRUPAL_BOOTSTRAP_DATABASE: - // The user agent header is used to pass a database prefix in the request when - // running tests. However, for security reasons, it is imperative that we - // validate we ourselves made the request. - if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], "simpletest") !== FALSE) && !drupal_valid_test_ua($_SERVER['HTTP_USER_AGENT'])) { - header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden'); - exit; - } - // Initialize the database system. Note that the connection - // won't be initialized until it is actually requested. - require_once DRUPAL_ROOT . '/includes/database/database.inc'; - // Register autoload functions so that we can access classes and interfaces. - spl_autoload_register('drupal_autoload_class'); - spl_autoload_register('drupal_autoload_interface'); - break; - - case DRUPAL_BOOTSTRAP_VARIABLES: - // Load variables from the database, but do not overwrite variables set in settings.php. - $conf = variable_initialize(isset($conf) ? $conf : array()); - // Load bootstrap modules. - require_once DRUPAL_ROOT . '/includes/module.inc'; - module_load_all(TRUE); - 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: - bootstrap_invoke_all('boot'); - if (!$cache && drupal_page_is_cacheable()) { - header('X-Drupal-Cache: MISS'); - } - - // Prepare for non-cached page workflow. - require_once DRUPAL_ROOT . '/' . variable_get('lock_inc', 'includes/lock.inc'); - lock_initialize(); - - if (!drupal_is_cli()) { - ob_start(); - drupal_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; +function _drupal_bootstrap_configuration() { + drupal_environment_initialize(); + // Start a page timer: + timer_start('page'); + // Initialize the configuration, including variables from settings.php. + drupal_settings_initialize(); +} + +function _drupal_bootstrap_page_cache() { + global $user; + $cache = &drupal_static(__FUNCTION__); + + // Allow specifying special cache handlers in settings.php, like + // using memcached or files for storing cache information. + require_once DRUPAL_ROOT . '/' . variable_get('cache_inc', 'includes/cache.inc'); + // Check for a cache mode force from settings.php. + if (variable_get('page_cache_without_database')) { + $cache_mode = CACHE_NORMAL; + } + else { + drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES, FALSE); + $cache_mode = variable_get('cache'); + } + drupal_block_denied(ip_address()); + // If there is no session cookie and cache is enabled (or forced), try + // to serve a cached page. + if (!isset($_COOKIE[session_name()]) && $cache_mode == CACHE_NORMAL) { + // Make sure there is a user object because it's timestamp will be + // checked, hook_boot might check for anonymous user etc. + $user = drupal_anonymous_user(); + // Get the page from the cache. + $cache = drupal_page_get_cache(); + // If there is a cached page, display it. + if (is_object($cache)) { + // If the skipping of the bootstrap hooks is not enforced, call + // hook_boot. + if (variable_get('page_cache_invoke_hooks', TRUE)) { + bootstrap_invoke_all('boot'); + } + header('X-Drupal-Cache: HIT'); + drupal_serve_page_from_cache($cache); + // If the skipping of the bootstrap hooks is not enforced, call + // hook_exit. + if (variable_get('page_cache_invoke_hooks', TRUE)) { + bootstrap_invoke_all('exit'); + } + // We are done. + exit; + } + } +} + +function _drupal_bootstrap_database() { + // The user agent header is used to pass a database prefix in the request when + // running tests. However, for security reasons, it is imperative that we + // validate we ourselves made the request. + if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], "simpletest") !== FALSE) && !drupal_valid_test_ua($_SERVER['HTTP_USER_AGENT'])) { + header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden'); + exit; + } + // Initialize the database system. Note that the connection + // won't be initialized until it is actually requested. + require_once DRUPAL_ROOT . '/includes/database/database.inc'; + // Register autoload functions so that we can access classes and interfaces. + spl_autoload_register('drupal_autoload_class'); + spl_autoload_register('drupal_autoload_interface'); +} + +function _drupal_bootstrap_variables() { + global $conf; + + // Load variables from the database, but do not overwrite variables set in settings.php. + $conf = variable_initialize(isset($conf) ? $conf : array()); + // Load bootstrap modules. + require_once DRUPAL_ROOT . '/includes/module.inc'; + module_load_all(TRUE); +} + +function _drupal_bootstrap_page_header() { + $cache = &drupal_static('_drupal_bootstrap_page_cache'); + + bootstrap_invoke_all('boot'); + if (!$cache && drupal_page_is_cacheable()) { + header('X-Drupal-Cache: MISS'); + } + + // Prepare for non-cached page workflow. + require_once DRUPAL_ROOT . '/' . variable_get('lock_inc', 'includes/lock.inc'); + lock_initialize(); + + if (!drupal_is_cli()) { + ob_start(); + drupal_page_header(); } } Index: includes/module.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/module.inc,v retrieving revision 1.164 diff -u -p -r1.164 module.inc --- includes/module.inc 1 Nov 2009 22:10:07 -0000 1.164 +++ includes/module.inc 2 Nov 2009 18:06:55 -0000 @@ -499,13 +499,19 @@ function module_implements_write_cache() * @return * The return value of the hook implementation. */ -function module_invoke() { - $args = func_get_args(); - $module = $args[0]; - $hook = $args[1]; - unset($args[0], $args[1]); +function module_invoke($module, $hook, $a1 = NULL, $a2 = NULL, $a3 = NULL, $a4 = NULL, $a5 = NULL, $a6 = NULL, $a7 = NULL) { if (module_hook($module, $hook)) { - return call_user_func_array($module . '_' . $hook, $args); + $function = $module . '_' . $hook; + switch (func_num_args() - 2) { + case 0: return $function(); + case 1: return $function($a1); + case 2: return $function($a1, $a2); + case 3: return $function($a1, $a2, $a3); + case 4: return $function($a1, $a2, $a3, $a4); + case 5: return $function($a1, $a2, $a3, $a4, $a5); + case 6: return $function($a1, $a2, $a3, $a4, $a5, $a6); + case 7: return $function($a1, $a2, $a3, $a4, $a5, $a6, $a7); + } } } /** @@ -519,15 +525,21 @@ function module_invoke() { * An array of return values of the hook implementations. If modules return * arrays from their implementations, those are merged into one array. */ -function module_invoke_all() { - $args = func_get_args(); - $hook = $args[0]; - unset($args[0]); +function module_invoke_all($hook, $a1 = NULL, $a2 = NULL, $a3 = NULL, $a4 = NULL, $a5 = NULL, $a6 = NULL, $a7 = NULL) { $return = array(); foreach (module_implements($hook) as $module) { $function = $module . '_' . $hook; if (function_exists($function)) { - $result = call_user_func_array($function, $args); + switch (func_num_args() - 1) { + case 0: $result = $function(); break; + case 1: $result = $function($a1); break; + case 2: $result = $function($a1, $a2); break; + case 3: $result = $function($a1, $a2, $a3); break; + case 4: $result = $function($a1, $a2, $a3, $a4); break; + case 5: $result = $function($a1, $a2, $a3, $a4, $a5); break; + case 6: $result = $function($a1, $a2, $a3, $a4, $a5, $a6); break; + case 7: $result = $function($a1, $a2, $a3, $a4, $a5, $a6, $a7); break; + } if (isset($result) && is_array($result)) { $return = array_merge_recursive($return, $result); }