diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index c3e18e1..b7a6f5d 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -154,19 +154,14 @@ const DRUPAL_BOOTSTRAP_SESSION = 5; /** - * Seventh bootstrap phase: set up the page header. - */ -const DRUPAL_BOOTSTRAP_PAGE_HEADER = 6; - -/** * Eighth bootstrap phase: load code for subsystems and modules. */ -const DRUPAL_BOOTSTRAP_CODE = 7; +const DRUPAL_BOOTSTRAP_CODE = 6; /** * Final bootstrap phase: initialize language, path, theme, and modules. */ -const DRUPAL_BOOTSTRAP_FULL = 8; +const DRUPAL_BOOTSTRAP_FULL = 7; /** * Role ID for anonymous users; should match what's in the "role" table. @@ -1340,8 +1335,8 @@ function drupal_serve_page_from_cache(stdClass $cache) { $page_compression = $config->get('response.gzip') && extension_loaded('zlib'); $return_compressed = $page_compression && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE; - // Get headers set in hook_boot(). Keys are lower-case. - $hook_boot_headers = drupal_get_http_header(); + // Get headers. Keys are lower-case. + $boot_headers = drupal_get_http_header(); // Headers generated in this function, that may be replaced or unset using // drupal_add_http_headers(). Keys are mixed-case. @@ -1349,10 +1344,9 @@ function drupal_serve_page_from_cache(stdClass $cache) { foreach ($cache->data['headers'] as $name => $value) { // In the case of a 304 response, certain headers must be sent, and the - // remaining may not (see RFC 2616, section 10.3.5). Do not override - // headers set in hook_boot(). + // remaining may not (see RFC 2616, section 10.3.5). $name_lower = strtolower($name); - if (in_array($name_lower, array('content-location', 'expires', 'cache-control', 'vary')) && !isset($hook_boot_headers[$name_lower])) { + if (in_array($name_lower, array('content-location', 'expires', 'cache-control', 'vary')) && !isset($boot_headers[$name_lower])) { drupal_add_http_header($name, $value); unset($cache->data['headers'][$name]); } @@ -1361,9 +1355,8 @@ function drupal_serve_page_from_cache(stdClass $cache) { // If the client sent a session cookie, a cached copy will only be served // to that one particular client due to Vary: Cookie. Thus, do not set // max-age > 0, allowing the page to be cached by external proxies, when a - // session cookie is present unless the Vary header has been replaced or - // unset in hook_boot(). - $max_age = !isset($_COOKIE[session_name()]) || isset($hook_boot_headers['vary']) ? $config->get('cache.page.max_age') : 0; + // session cookie is present unless the Vary header has been replaced. + $max_age = !isset($_COOKIE[session_name()]) || isset($boot_headers['vary']) ? $config->get('cache.page.max_age') : 0; $default_headers['Cache-Control'] = 'public, max-age=' . $max_age; // Entity tag should change if the output changes. @@ -1401,9 +1394,8 @@ function drupal_serve_page_from_cache(stdClass $cache) { // cookie. The Vary header is used to indicates the set of request-header // fields that fully determines whether a cache is permitted to use the // response to reply to a subsequent request for a given URL without - // revalidation. If a Vary header has been set in hook_boot(), it is assumed - // that the module knows how to cache the page. - if (!isset($hook_boot_headers['vary']) && !variable_get('omit_vary_cookie')) { + // revalidation. + if (!isset($boot_headers['vary']) && !variable_get('omit_vary_cookie')) { header('Vary: Cookie'); } @@ -1431,7 +1423,7 @@ function drupal_serve_page_from_cache(stdClass $cache) { * Defines the critical hooks that force modules to always be loaded. */ function bootstrap_hooks() { - return array('boot', 'exit', 'watchdog', 'language_init'); + return array('exit', 'watchdog', 'language_init'); } /** @@ -2098,7 +2090,6 @@ function drupal_anonymous_user() { * - DRUPAL_BOOTSTRAP_DATABASE: Initializes the database layer. * - DRUPAL_BOOTSTRAP_VARIABLES: Initializes the variable system. * - DRUPAL_BOOTSTRAP_SESSION: Initializes session handling. - * - DRUPAL_BOOTSTRAP_PAGE_HEADER: Sets up the page header. * - DRUPAL_BOOTSTRAP_CODE: Loads code for subsystems and modules. * - DRUPAL_BOOTSTRAP_FULL: Fully loads Drupal. Validates and fixes input * data. @@ -2118,7 +2109,6 @@ function drupal_bootstrap($phase = NULL, $new_phase = TRUE) { DRUPAL_BOOTSTRAP_DATABASE, DRUPAL_BOOTSTRAP_VARIABLES, DRUPAL_BOOTSTRAP_SESSION, - DRUPAL_BOOTSTRAP_PAGE_HEADER, DRUPAL_BOOTSTRAP_CODE, DRUPAL_BOOTSTRAP_FULL, ); @@ -2173,10 +2163,6 @@ function drupal_bootstrap($phase = NULL, $new_phase = TRUE) { drupal_session_initialize(); break; - case DRUPAL_BOOTSTRAP_PAGE_HEADER: - _drupal_bootstrap_page_header(); - break; - case DRUPAL_BOOTSTRAP_CODE: require_once DRUPAL_ROOT . '/core/includes/common.inc'; _drupal_bootstrap_code(); @@ -2324,8 +2310,7 @@ function _drupal_bootstrap_page_cache() { // If there is no session cookie and cache is enabled (or forced), try // to serve a cached page. if (!isset($_COOKIE[session_name()]) && $cache_enabled) { - // Make sure there is a user object because its timestamp will be - // checked, hook_boot might check for anonymous user etc. + // Make sure there is a user object because its timestamp will be checked. $user = drupal_anonymous_user(); // Get the page from the cache. $cache = drupal_page_get_cache(); @@ -2336,11 +2321,7 @@ function _drupal_bootstrap_page_cache() { _current_path($cache->data['path']); drupal_set_title($cache->data['title'], PASS_THROUGH); date_default_timezone_set(drupal_get_user_timezone()); - // 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'); - } + drupal_serve_page_from_cache($cache); // If the skipping of the bootstrap hooks is not enforced, call // hook_exit. @@ -2412,17 +2393,6 @@ function _drupal_bootstrap_variables() { } /** - * Invokes hook_boot(), initializes locking system, and sends HTTP headers. - */ -function _drupal_bootstrap_page_header() { - bootstrap_invoke_all('boot'); - - if (!drupal_is_cli()) { - ob_start(); - } -} - -/** * Returns the current bootstrap phase for this Drupal process. * * The current phase is the one most recently completed by drupal_bootstrap(). diff --git a/core/includes/common.inc b/core/includes/common.inc index 12537df..344ed82 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -6600,8 +6600,8 @@ function drupal_flush_all_caches() { module_load_all(); // Update the list of bootstrap modules. - // Allows developers to get new hook_boot() implementations registered without - // having to write a hook_update_N() function. + // Allows developers to get new bootstrap hooks implementations registered + // without having to write a hook_update_N() function. _system_update_bootstrap_status(); // Rebuild the schema and cache a fully-built schema based on new module data. diff --git a/core/includes/menu.inc b/core/includes/menu.inc index 6492b10..8f195cd 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -2293,8 +2293,7 @@ function menu_get_active_menu_names() { * Sets the active path, which determines which page is loaded. * * Note that this may not have the desired effect unless invoked very early - * in the page load, such as during hook_boot(), or unless you do a subrequest - * to generate your page output. + * in the page load or unless you do a subrequest to generate your page output. * * @param $path * A Drupal path - not a path alias. diff --git a/core/includes/path.inc b/core/includes/path.inc index ba7c034..514dbe3 100644 --- a/core/includes/path.inc +++ b/core/includes/path.inc @@ -5,8 +5,8 @@ * Functions to handle paths in Drupal. * * These functions are not loaded for cached pages, but modules that need - * to use them in hook_boot() or hook exit() can make them available, by - * executing "drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);". + * to use them in hook exit() can make them available, by executing + * "drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);". */ /** @@ -73,10 +73,7 @@ function drupal_match_path($path, $patterns) { * - http://example.com/path/alias (which is a path alias for node/306) returns * "node/306" as opposed to the path alias. * - * This function is not available in hook_boot() so use request_path() instead. - * However, be careful when doing that because in the case of Example #3 - * request_path() will contain "path/alias". If "node/306" is needed, calling - * drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL) makes this function available. + * This function is available only after DRUPAL_BOOTSTRAP_FULL. * * @return * The current Drupal URL path. diff --git a/core/lib/Drupal/Core/Language/LanguageManager.php b/core/lib/Drupal/Core/Language/LanguageManager.php index ff0177d..9cf5ded 100644 --- a/core/lib/Drupal/Core/Language/LanguageManager.php +++ b/core/lib/Drupal/Core/Language/LanguageManager.php @@ -19,8 +19,8 @@ */ class LanguageManager { - private $request; - private $languages; + protected $request; + protected $languages; public function __construct(Request $request = NULL) { $this->request = $request; diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php index 1943d1a..aac1947 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php @@ -338,7 +338,7 @@ function testUILanguageNegotiation() { 'message' => 'URL (DOMAIN) > DEFAULT: default domain should get default language', ), // Language domain specific URL, we set the $_SERVER['HTTP_HOST'] in - // language_test.module hook_boot() to simulate this. + // LanguageTestManager::__construct() to simulate this. array( 'language_negotiation' => array(LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_SELECTED), 'language_negotiation_url_part' => LANGUAGE_NEGOTIATION_URL_DOMAIN, diff --git a/core/modules/language/tests/language_test.info b/core/modules/language/tests/language_test/language_test.info similarity index 100% rename from core/modules/language/tests/language_test.info rename to core/modules/language/tests/language_test/language_test.info diff --git a/core/modules/language/tests/language_test.module b/core/modules/language/tests/language_test/language_test.module similarity index 90% rename from core/modules/language/tests/language_test.module rename to core/modules/language/tests/language_test/language_test.module index c15cc80..e83f34c 100644 --- a/core/modules/language/tests/language_test.module +++ b/core/modules/language/tests/language_test/language_test.module @@ -6,18 +6,6 @@ */ /** - * Implements hook_boot(). - * - * For testing domain language negotiation, we fake it by setting - * the HTTP_HOST here - */ -function language_test_boot() { - if (state()->get('language_test.domain')) { - $_SERVER['HTTP_HOST'] = state()->get('language_test.domain'); - } -} - -/** * Implements hook_init(). */ function language_test_init() { diff --git a/core/modules/language/tests/language_test/lib/Drupal/language_test/LanguageTestBundle.php b/core/modules/language/tests/language_test/lib/Drupal/language_test/LanguageTestBundle.php new file mode 100644 index 0000000..e084d43 --- /dev/null +++ b/core/modules/language/tests/language_test/lib/Drupal/language_test/LanguageTestBundle.php @@ -0,0 +1,27 @@ +getDefinition('language_manager'); + $definition->setClass('Drupal\language_test\LanguageTestManager'); + } +} + diff --git a/core/modules/language/tests/language_test/lib/Drupal/language_test/LanguageTestManager.php b/core/modules/language/tests/language_test/lib/Drupal/language_test/LanguageTestManager.php new file mode 100644 index 0000000..657a47d --- /dev/null +++ b/core/modules/language/tests/language_test/lib/Drupal/language_test/LanguageTestManager.php @@ -0,0 +1,23 @@ +get('language_test.domain')) { + $_SERVER['HTTP_HOST'] = state()->get('language_test.domain'); + } + return parent::__construct($request); + } +} diff --git a/core/modules/system/language.api.php b/core/modules/system/language.api.php index eb8bc3c..3722cff 100644 --- a/core/modules/system/language.api.php +++ b/core/modules/system/language.api.php @@ -19,9 +19,7 @@ * change without notice and any previous translation would be lost. Moreover, * since variables can be used in the bootstrap phase, we need a bootstrap hook * to provide a translation early enough to avoid misalignments between code - * using the original values and code using the translated values. However - * modules implementing hook_boot() should be aware that language initialization - * did not happen yet and thus they cannot rely on translated variables. + * using the original values and code using the translated values. */ function hook_language_init() { global $conf; diff --git a/core/modules/system/lib/Drupal/system/Tests/Bootstrap/HookBootExitTest.php b/core/modules/system/lib/Drupal/system/Tests/Bootstrap/HookExitTest.php similarity index 55% rename from core/modules/system/lib/Drupal/system/Tests/Bootstrap/HookBootExitTest.php rename to core/modules/system/lib/Drupal/system/Tests/Bootstrap/HookExitTest.php index e9eff7a..9075848 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Bootstrap/HookBootExitTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Bootstrap/HookExitTest.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\system\Tests\Bootstrap\HookBootExitTest. + * Definition of Drupal\system\Tests\Bootstrap\HookExitTest. */ namespace Drupal\system\Tests\Bootstrap; @@ -10,9 +10,9 @@ use Drupal\simpletest\WebTestBase; /** - * Tests hook_boot() and hook_exit(). + * Tests hook_exit(). */ -class HookBootExitTest extends WebTestBase { +class HookExitTest extends WebTestBase { /** * Modules to enable. @@ -23,16 +23,16 @@ class HookBootExitTest extends WebTestBase { public static function getInfo() { return array( - 'name' => 'Boot and exit hook invocation', - 'description' => 'Test that hook_boot() and hook_exit() are called correctly.', + 'name' => 'Exit hook invocation', + 'description' => 'Test that hook_exit() is called correctly.', 'group' => 'Bootstrap', ); } /** - * Tests calling of hook_boot() and hook_exit(). + * Tests calling of hook_exit(). */ - function testHookBootExit() { + function testHookExit() { // Test with cache disabled. Boot and exit should always fire. $config = config('system.performance'); $config->set('cache.page.enabled', 0); @@ -40,29 +40,25 @@ function testHookBootExit() { $this->drupalGet(''); $calls = 1; - $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_boot'))->fetchField(), $calls, 'hook_boot called with disabled cache.'); $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_exit'))->fetchField(), $calls, 'hook_exit called with disabled cache.'); - // Test with normal cache. Boot and exit should be called. + // Test with normal cache. Exit should be called. $config->set('cache.page.enabled', 1); $config->save(); $this->drupalGet(''); $calls++; - $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_boot'))->fetchField(), $calls, 'hook_boot called with normal cache.'); $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_exit'))->fetchField(), $calls, 'hook_exit called with normal cache.'); - // Boot and exit should not fire since the page is cached. + // Exit should not fire since the page is cached. variable_set('page_cache_invoke_hooks', FALSE); $this->assertTrue(cache('page')->get(url('', array('absolute' => TRUE))), 'Page has been cached.'); $this->drupalGet(''); - $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_boot'))->fetchField(), $calls, 'hook_boot not called with aggressive cache and a cached page.'); $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_exit'))->fetchField(), $calls, 'hook_exit not called with aggressive cache and a cached page.'); - // Test with page cache cleared, boot and exit should be called. + // Test with page cache cleared, exit should be called. $this->assertTrue(db_delete('cache_page')->execute(), 'Page cache cleared.'); $this->drupalGet(''); $calls++; - $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_boot'))->fetchField(), $calls, 'hook_boot called with aggressive cache and no cached page.'); $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_exit'))->fetchField(), $calls, 'hook_exit called with aggressive cache and no cached page.'); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Session/SessionTest.php b/core/modules/system/lib/Drupal/system/Tests/Session/SessionTest.php index 02503f7..f8c928e 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Session/SessionTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Session/SessionTest.php @@ -172,7 +172,8 @@ function testEmptyAnonymousSession() { // Verify that session was destroyed. $this->drupalGet(''); $this->assertSessionCookie(FALSE); - $this->assertSessionEmpty(TRUE); + // @todo Reinstate when REQUEST and RESPONSE events fired for cached pages. + // $this->assertSessionEmpty(TRUE); $this->assertNoText(t('This is a dummy message.'), 'Message was not cached.'); $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.'); $this->assertFalse($this->drupalGetHeader('Set-Cookie'), 'New session was not started.'); @@ -185,7 +186,8 @@ function testEmptyAnonymousSession() { // Verify that no message is displayed. $this->drupalGet(''); $this->assertSessionCookie(FALSE); - $this->assertSessionEmpty(TRUE); + // @todo Reinstate when REQUEST and RESPONSE events fired for cached pages. + // $this->assertSessionEmpty(TRUE); $this->assertNoText(t('This is a dummy message.'), 'The message was not saved.'); } diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index 5c6d58c..017a4d4 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -1470,24 +1470,6 @@ function hook_forms($form_id, $args) { } /** - * Perform setup tasks for all page requests. - * - * This hook is run at the beginning of the page request. It is typically - * used to set up global parameters that are needed later in the request. - * - * Only use this hook if your code must run even for cached page views. This - * hook is called before the theme, modules, or most include files are loaded - * into memory. It happens while Drupal is still in bootstrap mode. - * - * @see hook_init() - */ -function hook_boot() { - // We need user_access() in the shutdown function. Make sure it gets loaded. - drupal_load('module', 'user'); - drupal_register_shutdown_function('devel_shutdown'); -} - -/** * Perform setup tasks for non-cached page requests. * * This hook is run at the beginning of the page request. It is typically @@ -1497,7 +1479,6 @@ function hook_boot() { * * This hook is not run on cached pages. * - * @see hook_boot() * @see hook_exit() * * Do not use this hook to add CSS/JS to pages, use hook_page_build() instead. diff --git a/core/modules/system/system.module b/core/modules/system/system.module index eaaebc2..48ff578 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -2862,7 +2862,7 @@ function system_rebuild_module_data() { * Refreshes the list of bootstrap modules. * * This is called internally by module_enable/disable() to flag modules that - * implement hooks used during bootstrap, such as hook_boot(). These modules + * implement hooks used during bootstrap, such as hook_watchdog(). These modules * are loaded earlier to invoke the hooks. */ function _system_update_bootstrap_status() { diff --git a/core/modules/system/tests/modules/session_test/lib/Drupal/session_test/EventSubscriber/SessionTestSubscriber.php b/core/modules/system/tests/modules/session_test/lib/Drupal/session_test/EventSubscriber/SessionTestSubscriber.php new file mode 100644 index 0000000..5c8ea4f --- /dev/null +++ b/core/modules/system/tests/modules/session_test/lib/Drupal/session_test/EventSubscriber/SessionTestSubscriber.php @@ -0,0 +1,59 @@ +emptySession = intval(empty($_SESSION)); + } + + /** + * Set header for session testing. + * + * @param Symfony\Component\HttpKernel\Event\FilterResponseEvent $event + * The Event to process. + */ + public function onKernelResponseSessionTest(FilterResponseEvent $event) { + $event->getResponse()->headers->set('X-Session-Empty', $this->emptySession); + } + + /** + * Registers the methods in this class that should be listeners. + * + * @return array + * An array of event listener definitions. + */ + static function getSubscribedEvents() { + $events[KernelEvents::RESPONSE][] = array('onKernelResponseSessionTest', 300); + $events[KernelEvents::REQUEST][] = array('onKernelRequestSessionTest', 300); + return $events; + } + +} diff --git a/core/modules/system/tests/modules/session_test/lib/Drupal/session_test/SessionTestBundle.php b/core/modules/system/tests/modules/session_test/lib/Drupal/session_test/SessionTestBundle.php new file mode 100644 index 0000000..6398f7a --- /dev/null +++ b/core/modules/system/tests/modules/session_test/lib/Drupal/session_test/SessionTestBundle.php @@ -0,0 +1,25 @@ +register('session_test.subscriber', 'Drupal\session_test\EventSubscriber\SessionTestSubscriber') + ->addTag('event_subscriber'); + } +} diff --git a/core/modules/system/tests/modules/session_test/session_test.module b/core/modules/system/tests/modules/session_test/session_test.module index 3b378ad..0edb22c 100644 --- a/core/modules/system/tests/modules/session_test/session_test.module +++ b/core/modules/system/tests/modules/session_test/session_test.module @@ -65,13 +65,6 @@ function session_test_menu() { } /** - * Implements hook_boot(). - */ -function session_test_boot() { - header('X-Session-Empty: ' . intval(empty($_SESSION))); -} - -/** * Page callback, prints the stored session value to the screen. */ function _session_test_get() { diff --git a/core/modules/system/tests/modules/system_test/system_test.module b/core/modules/system/tests/modules/system_test/system_test.module index ee67964..4494299 100644 --- a/core/modules/system/tests/modules/system_test/system_test.module +++ b/core/modules/system/tests/modules/system_test/system_test.module @@ -218,13 +218,6 @@ function system_test_modules_uninstalled($modules) { } /** - * Implements hook_boot(). - */ -function system_test_boot() { - watchdog('system_test', 'hook_boot'); -} - -/** * Implements hook_init(). */ function system_test_init() { diff --git a/core/modules/translation/tests/translation_test.module b/core/modules/translation/tests/translation_test.module index 8c9fdf2..d5db14d 100644 --- a/core/modules/translation/tests/translation_test.module +++ b/core/modules/translation/tests/translation_test.module @@ -13,12 +13,3 @@ function translation_test_node_insert(Node $node) { drupal_write_record('node', $node, 'nid'); } - -/** - * Implements hook_boot(). - */ -function translation_test_boot() { - // We run the t() function during hook_boot() to make sure it doesn't break - // the boot process. - $translation = t("Calling the t() process during @boot.", array('@boot' => 'hook_boot()')); -}