diff --git a/core/authorize.php b/core/authorize.php index 3a340462ed0740dda26648b68a3cb7909671d1a3..b44c1215cfb66c773f739184f784cd112b667770 100644 --- a/core/authorize.php +++ b/core/authorize.php @@ -49,7 +49,7 @@ * TRUE if the current user can run authorize.php, and FALSE if not. */ function authorize_access_allowed() { - \Drupal::service('session_manager')->startLazy(); + \Drupal::service('session_manager')->start(); return Settings::get('allow_authorize_operations', TRUE) && \Drupal::currentUser()->hasPermission('administer software updates'); } diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index aaab2254583da2704b05b99a3beb9cc25fe855b7..6e7194caf472c8cf59d08125d0e66d281c348b5f 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1453,7 +1453,7 @@ function install_load_profile(&$install_state) { * An array of information about the current installation state. */ function install_bootstrap_full() { - \Drupal::service('session_manager')->startLazy(); + \Drupal::service('session_manager')->start(); } /** diff --git a/core/lib/Drupal/Core/Authentication/Provider/Cookie.php b/core/lib/Drupal/Core/Authentication/Provider/Cookie.php index c5f23c865b7721bcee36bd6f18716f2f0e88c758..5f88c4789ceae3852446399130d979f8c3aaa022 100644 --- a/core/lib/Drupal/Core/Authentication/Provider/Cookie.php +++ b/core/lib/Drupal/Core/Authentication/Provider/Cookie.php @@ -47,7 +47,7 @@ public function applies(Request $request) { public function authenticate(Request $request) { // Global $user is deprecated, but the session system is still based on it. global $user; - $this->sessionManager->startLazy(); + $this->sessionManager->start(); if ($this->sessionManager->isStarted()) { return $user; } diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 19a0fa9865a71685c3c782f55ef17a7d47c389a3..b75b470f0659e5d418049640ededef21ddae8f37 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -672,16 +672,13 @@ protected function getKernelParameters() { */ protected function initializeContainer($rebuild = FALSE) { $this->containerNeedsDumping = FALSE; - $session_manager_state = 0; + $session_manager_started = FALSE; if (isset($this->container)) { // If there is a session manager, close and save the session. if ($this->container->initialized('session_manager')) { $session_manager = $this->container->get('session_manager'); - if ($session_manager->isStartedLazy()) { - $session_manager_state |= 0x1; - } if ($session_manager->isStarted()) { - $session_manager_state |= 0x2; + $session_manager_started = TRUE; $session_manager->save(); } unset($session_manager); @@ -712,10 +709,7 @@ protected function initializeContainer($rebuild = FALSE) { $this->attachSynthetic($container); $this->container = $container; - if ($session_manager_state & 0x1) { - $this->container->get('session_manager')->startLazy(); - } - if ($session_manager_state & 0x2) { + if ($session_manager_started) { $this->container->get('session_manager')->start(); } \Drupal::setContainer($this->container); diff --git a/core/lib/Drupal/Core/Session/SessionManager.php b/core/lib/Drupal/Core/Session/SessionManager.php index b0fcc33ef7dc1302a221c39c531846edd6411899..64b8fddffca198f48d5aa643644eb84f6de5beb3 100644 --- a/core/lib/Drupal/Core/Session/SessionManager.php +++ b/core/lib/Drupal/Core/Session/SessionManager.php @@ -114,7 +114,7 @@ public function __construct(RequestStack $request_stack, Connection $connection, /** * {@inheritdoc} */ - public function startLazy() { + public function start() { global $user; if (($this->started || $this->startedLazy) && !$this->closed) { @@ -129,53 +129,66 @@ public function startLazy() { // session is only started on demand in save(), making // anonymous users not use a session cookie unless something is stored in // $_SESSION. This allows HTTP proxies to cache anonymous pageviews. - $result = $this->start(); + $result = $this->startNow(); if ($user->isAuthenticated() || !$this->isSessionObsolete()) { drupal_page_is_cacheable(FALSE); } } - else { - // Set a session identifier for this request. This is necessary because - // we lazily start sessions at the end of this request, and some - // processes (like \Drupal::csrfToken()) needs to know the future - // session ID in advance. + + if (empty($result)) { $user = new AnonymousUserSession(); + + // Randomly generate a session identifier for this request. This is + // necessary because \Drupal\user\TempStoreFactory::get() wants to know + // the future session ID of a lazily started session in advance. + // + // @todo: With current versions of PHP there is little reason to generate + // the session id from within application code. Consider using the + // default php session id instead of generating a custom one: + // https://www.drupal.org/node/2238561 $this->setId(Crypt::randomBytesBase64()); if ($is_https && $this->isMixedMode()) { $session_id = Crypt::randomBytesBase64(); $cookies->set($insecure_session_name, $session_id); } + + // Initialize the session global and attach the Symfony session bags. + $_SESSION = array(); + $this->loadSession(); + + // NativeSessionStorage::loadSession() sets started to TRUE, reset it to + // FALSE here. + $this->started = FALSE; + $this->startedLazy = TRUE; + $result = FALSE; } date_default_timezone_set(drupal_get_user_timezone()); - $this->startedLazy = TRUE; - return $result; } /** - * {@inheritdoc} - */ - public function isStartedLazy() { - return $this->startedLazy; - } - - /** - * {@inheritdoc} + * Forcibly start a PHP session. + * + * @return boolean + * TRUE if the session is started. */ - public function start() { + protected function startNow() { if (!$this->isEnabled() || $this->isCli()) { - return; + return FALSE; + } + + if ($this->startedLazy) { + // Save current session data before starting it, as PHP will destroy it. + $session_data = $_SESSION; } - // Save current session data before starting it, as PHP will destroy it. - $session_data = isset($_SESSION) ? $_SESSION : NULL; $result = parent::start(); // Restore session data. - if (!empty($session_data)) { - $_SESSION += $session_data; + if ($this->startedLazy) { + $_SESSION = $session_data; } return $result; @@ -203,7 +216,7 @@ public function save() { // There is session data to store. Start the session if it is not already // started. if (!$this->getSaveHandler()->isActive()) { - $this->start(); + $this->startNow(); if ($this->requestStack->getCurrentRequest()->isSecure() && $this->isMixedMode()) { $insecure_session_name = $this->getInsecureName(); $params = session_get_cookie_params(); @@ -282,7 +295,7 @@ public function regenerate($destroy = FALSE, $lifetime = NULL) { // Preserve the logged in user, as it will be reset to anonymous // by \Drupal\Core\Session\SessionHandler::read(). $account = $user; - $this->start(); + $this->startNow(); $user = $account; } date_default_timezone_set(drupal_get_user_timezone()); diff --git a/core/lib/Drupal/Core/Session/SessionManagerInterface.php b/core/lib/Drupal/Core/Session/SessionManagerInterface.php index e7ea14d3f58f43437ac9fd1e76bb26c27a534f07..b620c6630d2b4e478c45df8bbddb840fea4242a5 100644 --- a/core/lib/Drupal/Core/Session/SessionManagerInterface.php +++ b/core/lib/Drupal/Core/Session/SessionManagerInterface.php @@ -14,22 +14,6 @@ */ interface SessionManagerInterface extends SessionStorageInterface { - /** - * Starts a session if appropriate cookies are on the request. - * - * @return bool - * TRUE if the session was started. - */ - public function startLazy(); - - /** - * Determines whether the session was started lazily. - * - * @return bool - * TRUE if the session was started lazily. - */ - public function isStartedLazy(); - /** * Ends a specific user's session(s). * diff --git a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php index 7a93554fc0ca3eac8e9a9119a5db164d01073bb9..48fd3b1411aa6428263ebbb06e31aa0977422866 100644 --- a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php +++ b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php @@ -55,7 +55,7 @@ protected function setUp() { * Checks the order of CRUD hook execution messages. * * entity_crud_hook_test.module implements all core entity CRUD hooks and - * stores a message for each in $_SESSION['entity_crud_hook_test']. + * stores a message for each in $GLOBALS['entity_crud_hook_test']. * * @param $messages * An array of plain-text messages in the order they should appear. @@ -64,7 +64,7 @@ protected function assertHookMessageOrder($messages) { $positions = array(); foreach ($messages as $message) { // Verify that each message is found and record its position. - $position = array_search($message, $_SESSION['entity_crud_hook_test']); + $position = array_search($message, $GLOBALS['entity_crud_hook_test']); if ($this->assertTrue($position !== FALSE, $message)) { $positions[] = $position; } @@ -91,7 +91,7 @@ public function testBlockHooks() { 'entity_crud_hook_test_entity_create called for type block', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $entity->save(); $this->assertHookMessageOrder(array( @@ -101,7 +101,7 @@ public function testBlockHooks() { 'entity_crud_hook_test_entity_insert called for type block', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $entity = Block::load($entity->id()); $this->assertHookMessageOrder(array( @@ -109,7 +109,7 @@ public function testBlockHooks() { 'entity_crud_hook_test_block_load called', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $entity->label = 'New label'; $entity->save(); @@ -120,7 +120,7 @@ public function testBlockHooks() { 'entity_crud_hook_test_entity_update called for type block', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $entity->delete(); $this->assertHookMessageOrder(array( @@ -155,7 +155,7 @@ public function testCommentHooks() { )); $node->save(); $nid = $node->id(); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $comment = entity_create('comment', array( 'cid' => NULL, @@ -176,7 +176,7 @@ public function testCommentHooks() { 'entity_crud_hook_test_entity_create called for type comment', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $comment->save(); $this->assertHookMessageOrder(array( @@ -186,7 +186,7 @@ public function testCommentHooks() { 'entity_crud_hook_test_entity_insert called for type comment', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $comment = Comment::load($comment->id()); $this->assertHookMessageOrder(array( @@ -194,7 +194,7 @@ public function testCommentHooks() { 'entity_crud_hook_test_comment_load called', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $comment->setSubject('New subject'); $comment->save(); @@ -205,7 +205,7 @@ public function testCommentHooks() { 'entity_crud_hook_test_entity_update called for type comment', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $comment->delete(); $this->assertHookMessageOrder(array( @@ -241,7 +241,7 @@ public function testFileHooks() { 'entity_crud_hook_test_entity_create called for type file', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $file->save(); $this->assertHookMessageOrder(array( @@ -251,7 +251,7 @@ public function testFileHooks() { 'entity_crud_hook_test_entity_insert called for type file', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $file = file_load($file->id()); $this->assertHookMessageOrder(array( @@ -259,7 +259,7 @@ public function testFileHooks() { 'entity_crud_hook_test_file_load called', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $file->setFilename('new.entity_crud_hook_test.file'); $file->save(); @@ -270,7 +270,7 @@ public function testFileHooks() { 'entity_crud_hook_test_entity_update called for type file', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $file->delete(); $this->assertHookMessageOrder(array( @@ -304,7 +304,7 @@ public function testNodeHooks() { 'entity_crud_hook_test_entity_create called for type node', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $node->save(); $this->assertHookMessageOrder(array( @@ -314,7 +314,7 @@ public function testNodeHooks() { 'entity_crud_hook_test_entity_insert called for type node', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $node = node_load($node->id()); $this->assertHookMessageOrder(array( @@ -322,7 +322,7 @@ public function testNodeHooks() { 'entity_crud_hook_test_node_load called', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $node->title = 'New title'; $node->save(); @@ -333,7 +333,7 @@ public function testNodeHooks() { 'entity_crud_hook_test_entity_update called for type node', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $node->delete(); $this->assertHookMessageOrder(array( @@ -358,7 +358,7 @@ public function testTaxonomyTermHooks() { 'module' => 'entity_crud_hook_test', )); $vocabulary->save(); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $term = entity_create('taxonomy_term', array( 'vid' => $vocabulary->id(), @@ -373,7 +373,7 @@ public function testTaxonomyTermHooks() { 'entity_crud_hook_test_entity_create called for type taxonomy_term', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $term->save(); $this->assertHookMessageOrder(array( @@ -383,7 +383,7 @@ public function testTaxonomyTermHooks() { 'entity_crud_hook_test_entity_insert called for type taxonomy_term', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $term = entity_load('taxonomy_term', $term->id()); $this->assertHookMessageOrder(array( @@ -391,7 +391,7 @@ public function testTaxonomyTermHooks() { 'entity_crud_hook_test_taxonomy_term_load called', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $term->setName('New name'); $term->save(); @@ -402,7 +402,7 @@ public function testTaxonomyTermHooks() { 'entity_crud_hook_test_entity_update called for type taxonomy_term', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $term->delete(); $this->assertHookMessageOrder(array( @@ -432,7 +432,7 @@ public function testTaxonomyVocabularyHooks() { 'entity_crud_hook_test_entity_create called for type taxonomy_vocabulary', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $vocabulary->save(); $this->assertHookMessageOrder(array( @@ -442,7 +442,7 @@ public function testTaxonomyVocabularyHooks() { 'entity_crud_hook_test_entity_insert called for type taxonomy_vocabulary', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $vocabulary = entity_load('taxonomy_vocabulary', $vocabulary->id()); $this->assertHookMessageOrder(array( @@ -450,7 +450,7 @@ public function testTaxonomyVocabularyHooks() { 'entity_crud_hook_test_taxonomy_vocabulary_load called', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $vocabulary->name = 'New name'; $vocabulary->save(); @@ -461,7 +461,7 @@ public function testTaxonomyVocabularyHooks() { 'entity_crud_hook_test_entity_update called for type taxonomy_vocabulary', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $vocabulary->delete(); $this->assertHookMessageOrder(array( @@ -489,7 +489,7 @@ public function testUserHooks() { 'entity_crud_hook_test_entity_create called for type user', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $account->save(); $this->assertHookMessageOrder(array( @@ -499,7 +499,7 @@ public function testUserHooks() { 'entity_crud_hook_test_entity_insert called for type user', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); user_load($account->id()); $this->assertHookMessageOrder(array( @@ -507,7 +507,7 @@ public function testUserHooks() { 'entity_crud_hook_test_user_load called', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); $account->name = 'New name'; $account->save(); @@ -518,7 +518,7 @@ public function testUserHooks() { 'entity_crud_hook_test_entity_update called for type user', )); - $_SESSION['entity_crud_hook_test'] = array(); + $GLOBALS['entity_crud_hook_test'] = array(); user_delete($account->id()); $this->assertHookMessageOrder(array( diff --git a/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module b/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module index c7f20c366d84474ba11458ed6506fd2c759e030f..0325dbdbb49329413279fcda74e319d45bafe91b 100644 --- a/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module +++ b/core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module @@ -11,390 +11,390 @@ * Implements hook_entity_create(). */ function entity_crud_hook_test_entity_create(EntityInterface $entity) { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called for type ' . $entity->getEntityTypeId()); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called for type ' . $entity->getEntityTypeId()); } /** * Implements hook_ENTITY_TYPE_create() for block entities. */ function entity_crud_hook_test_block_create() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_create() for comment entities. */ function entity_crud_hook_test_comment_create() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_create() for file entities. */ function entity_crud_hook_test_file_create() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_create() for node entities. */ function entity_crud_hook_test_node_create() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_create() for taxonomy_term entities. */ function entity_crud_hook_test_taxonomy_term_create() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_create() for taxonomy_vocabulary entities. */ function entity_crud_hook_test_taxonomy_vocabulary_create() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_create() for user entities. */ function entity_crud_hook_test_user_create() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_entity_presave(). */ function entity_crud_hook_test_entity_presave(EntityInterface $entity) { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called for type ' . $entity->getEntityTypeId()); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called for type ' . $entity->getEntityTypeId()); } /** * Implements hook_ENTITY_TYPE_presave() for block entities. */ function entity_crud_hook_test_block_presave() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_presave() for comment entities. */ function entity_crud_hook_test_comment_presave() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_presave() for file entities. */ function entity_crud_hook_test_file_presave() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_presave() for node entities. */ function entity_crud_hook_test_node_presave() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_presave() for taxonomy_term entities. */ function entity_crud_hook_test_taxonomy_term_presave() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_presave() for taxonomy_vocabulary entities. */ function entity_crud_hook_test_taxonomy_vocabulary_presave() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_presave() for user entities. */ function entity_crud_hook_test_user_presave() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_entity_insert(). */ function entity_crud_hook_test_entity_insert(EntityInterface $entity) { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called for type ' . $entity->getEntityTypeId()); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called for type ' . $entity->getEntityTypeId()); } /** * Implements hook_ENTITY_TYPE_insert() for block entities. */ function entity_crud_hook_test_block_insert() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_insert() for comment entities. */ function entity_crud_hook_test_comment_insert() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_insert() for file entities. */ function entity_crud_hook_test_file_insert() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_insert() for node entities. */ function entity_crud_hook_test_node_insert() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_insert() for taxonomy_term entities. */ function entity_crud_hook_test_taxonomy_term_insert() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_insert() for taxonomy_vocabulary entities. */ function entity_crud_hook_test_taxonomy_vocabulary_insert() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_insert() for user entities. */ function entity_crud_hook_test_user_insert() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_entity_load(). */ function entity_crud_hook_test_entity_load(array $entities, $type) { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called for type ' . $type); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called for type ' . $type); } /** * Implements hook_ENTITY_TYPE_load() for block entities. */ function entity_crud_hook_test_block_load() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_load() for comment entities. */ function entity_crud_hook_test_comment_load() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_load() for file entities. */ function entity_crud_hook_test_file_load() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_load() for node entities. */ function entity_crud_hook_test_node_load() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_load() for taxonomy_term entities. */ function entity_crud_hook_test_taxonomy_term_load() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_load() for taxonomy_vocabulary entities. */ function entity_crud_hook_test_taxonomy_vocabulary_load() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_load() for user entities. */ function entity_crud_hook_test_user_load() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_entity_update(). */ function entity_crud_hook_test_entity_update(EntityInterface $entity) { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called for type ' . $entity->getEntityTypeId()); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called for type ' . $entity->getEntityTypeId()); } /** * Implements hook_ENTITY_TYPE_update() for block entities. */ function entity_crud_hook_test_block_update() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_update() for comment entities. */ function entity_crud_hook_test_comment_update() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_update() for file entities. */ function entity_crud_hook_test_file_update() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_update() for node entities. */ function entity_crud_hook_test_node_update() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_update() for taxonomy_term entities. */ function entity_crud_hook_test_taxonomy_term_update() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_update() for taxonomy_vocabulary entities. */ function entity_crud_hook_test_taxonomy_vocabulary_update() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_update() for user entities. */ function entity_crud_hook_test_user_update() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_entity_predelete(). */ function entity_crud_hook_test_entity_predelete(EntityInterface $entity) { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called for type ' . $entity->getEntityTypeId()); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called for type ' . $entity->getEntityTypeId()); } /** * Implements hook_ENTITY_TYPE_predelete() for block entities. */ function entity_crud_hook_test_block_predelete() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_predelete() for comment entities. */ function entity_crud_hook_test_comment_predelete() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_predelete() for file entities. */ function entity_crud_hook_test_file_predelete() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_predelete() for node entities. */ function entity_crud_hook_test_node_predelete() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_predelete() for taxonomy_term entities. */ function entity_crud_hook_test_taxonomy_term_predelete() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_predelete() for taxonomy_vocabulary entities. */ function entity_crud_hook_test_taxonomy_vocabulary_predelete() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_predelete() for user entities. */ function entity_crud_hook_test_user_predelete() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_entity_delete(). */ function entity_crud_hook_test_entity_delete(EntityInterface $entity) { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called for type ' . $entity->getEntityTypeId()); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called for type ' . $entity->getEntityTypeId()); } /** * Implements hook_ENTITY_TYPE_delete() for block entities. */ function entity_crud_hook_test_block_delete() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_delete() for comment entities. */ function entity_crud_hook_test_comment_delete() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_delete() for file entities. */ function entity_crud_hook_test_file_delete() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_delete() for node entities. */ function entity_crud_hook_test_node_delete() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_delete() for taxonomy_term entities. */ function entity_crud_hook_test_taxonomy_term_delete() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_delete() for taxonomy_vocabulary entities. */ function entity_crud_hook_test_taxonomy_vocabulary_delete() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } /** * Implements hook_ENTITY_TYPE_delete() for user entities. */ function entity_crud_hook_test_user_delete() { - $_SESSION['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); + $GLOBALS['entity_crud_hook_test'][] = (__FUNCTION__ . ' called'); } diff --git a/core/modules/system/tests/modules/service_provider_test/src/TestClass.php b/core/modules/system/tests/modules/service_provider_test/src/TestClass.php index aa0a5f2328f885b363254193db9d3579e60cf227..e46accd04f89b404e57f6283f8f097cecffc5e8f 100644 --- a/core/modules/system/tests/modules/service_provider_test/src/TestClass.php +++ b/core/modules/system/tests/modules/service_provider_test/src/TestClass.php @@ -46,7 +46,7 @@ public function onKernelRequestTest(GetResponseEvent $event) { * An array of event listener definitions. */ static function getSubscribedEvents() { - $events[KernelEvents::REQUEST][] = array('onKernelRequestTest', 100); + $events[KernelEvents::REQUEST][] = array('onKernelRequestTest'); return $events; } diff --git a/core/modules/system/tests/modules/session_test/session_test.services.yml b/core/modules/system/tests/modules/session_test/session_test.services.yml index 8ef2e204dec0150831c8cd0c428109a9d4b5a20b..281b09d2165facfcecf849302b8fe1a8dd2a673d 100644 --- a/core/modules/system/tests/modules/session_test/session_test.services.yml +++ b/core/modules/system/tests/modules/session_test/session_test.services.yml @@ -1,5 +1,6 @@ services: session_test.subscriber: class: Drupal\session_test\EventSubscriber\SessionTestSubscriber + arguments: ['@session_manager'] tags: - { name: event_subscriber } diff --git a/core/modules/system/tests/modules/session_test/src/EventSubscriber/SessionTestSubscriber.php b/core/modules/system/tests/modules/session_test/src/EventSubscriber/SessionTestSubscriber.php index 55225ae50bae199d44236c149245564581e5cd5f..9029093c64d09d99e62694671f29a001dd9f84d9 100644 --- a/core/modules/system/tests/modules/session_test/src/EventSubscriber/SessionTestSubscriber.php +++ b/core/modules/system/tests/modules/session_test/src/EventSubscriber/SessionTestSubscriber.php @@ -7,6 +7,7 @@ namespace Drupal\session_test\EventSubscriber; +use Drupal\Core\Session\SessionManagerInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpKernel\KernelEvents; @@ -18,11 +19,27 @@ */ class SessionTestSubscriber implements EventSubscriberInterface { - /* + /** + * The session manager. + * + * @var \Drupal\Core\Session\SessionManagerInterface + */ + protected $sessionManager; + + /** * Stores whether $_SESSION is empty at the beginning of the request. + * + * @var bool */ protected $emptySession; + /** + * Constructs a new session test subscriber. + */ + public function __construct(SessionManagerInterface $session_manager) { + $this->sessionManager = $session_manager; + } + /** * Set header for session testing. * @@ -30,12 +47,7 @@ class SessionTestSubscriber implements EventSubscriberInterface { * The Event to process. */ public function onKernelRequestSessionTest(GetResponseEvent $event) { - // Trigger the authentication in the test to ensure that $_SESSION has the - // needed data. - // @todo: On the longrun the session will be lazy initialized, so we no - // longer have to force it here. - \Drupal::currentUser()->getAccount(); - $this->emptySession = intval(empty($_SESSION)); + $this->emptySession = (int) !$this->sessionManager->start(); } /**