diff --git a/core/core.services.yml b/core/core.services.yml index 3f68677200..0d5ea4a312 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -1672,7 +1672,7 @@ services: - { name: event_subscriber } messenger: class: Drupal\Core\Messenger\Messenger - arguments: ['@session.flash_bag', '@page_cache_kill_switch'] + arguments: ['@session', '@page_cache_kill_switch'] tempstore.private: class: Drupal\Core\TempStore\PrivateTempStoreFactory arguments: ['@keyvalue.expirable', '@lock', '@current_user', '@request_stack', '%tempstore.expire%'] diff --git a/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php b/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php index dd4ae5f470..3af9d99a79 100644 --- a/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php +++ b/core/lib/Drupal/Core/Installer/InstallerServiceProvider.php @@ -60,6 +60,13 @@ public function register(ContainerBuilder $container) { // we don't need to ship with a custom proxy class. ->setLazy(FALSE); + // Replace the session_manager with an implementation that does not use the + // database. + $container->getDefinition('session_manager') + ->setClass('Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage') + ->setArguments([]) + ->setMethodCalls([]); + // Use a performance optimised module extension list. $container->getDefinition('extension.list.module')->setClass('Drupal\Core\Installer\InstallerModuleExtensionList'); } diff --git a/core/lib/Drupal/Core/Messenger/Messenger.php b/core/lib/Drupal/Core/Messenger/Messenger.php index c0949438cc..d71f1719e0 100644 --- a/core/lib/Drupal/Core/Messenger/Messenger.php +++ b/core/lib/Drupal/Core/Messenger/Messenger.php @@ -5,7 +5,7 @@ use Drupal\Component\Render\MarkupInterface; use Drupal\Core\PageCache\ResponsePolicy\KillSwitch; use Drupal\Core\Render\Markup; -use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; +use Symfony\Component\HttpFoundation\Session\SessionInterface; /** * The messenger service. @@ -13,11 +13,11 @@ class Messenger implements MessengerInterface { /** - * The flash bag. + * The session. * - * @var \Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface + * @var \Symfony\Component\HttpFoundation\Session\SessionInterface */ - protected $flashBag; + protected $session; /** * The kill switch. @@ -29,16 +29,26 @@ class Messenger implements MessengerInterface { /** * Messenger constructor. * - * @param \Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface $flash_bag - * The flash bag. + * @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session + * The session. * @param \Drupal\Core\PageCache\ResponsePolicy\KillSwitch $killSwitch * The kill switch. */ - public function __construct(FlashBagInterface $flash_bag, KillSwitch $killSwitch) { - $this->flashBag = $flash_bag; + public function __construct(SessionInterface $session, KillSwitch $killSwitch) { + $this->session = $session; $this->killSwitch = $killSwitch; } + /** + * Gets the flash bag. + * + * @return \Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface + * The flash bag. + */ + protected function getFlashBag() { + return $this->session->getFlashBag(); + } + /** * {@inheritdoc} */ @@ -56,8 +66,8 @@ public function addMessage($message, $type = self::TYPE_STATUS, $repeat = FALSE) // Do not use strict type checking so that equivalent string and // MarkupInterface objects are detected. - if ($repeat || !in_array($message, $this->flashBag->peek($type))) { - $this->flashBag->add($type, $message); + if ($repeat || !in_array($message, $this->getFlashBag()->peek($type))) { + $this->getFlashBag()->add($type, $message); } // Mark this page as being uncacheable. @@ -84,29 +94,41 @@ public function addWarning($message, $repeat = FALSE) { * {@inheritdoc} */ public function all() { - return $this->flashBag->peekAll(); + if (!$this->session->isStarted()) { + return []; + } + return $this->getFlashBag()->peekAll(); } /** * {@inheritdoc} */ public function deleteAll() { - return $this->flashBag->clear(); + if (!$this->session->isStarted()) { + return []; + } + return $this->getFlashBag()->clear(); } /** * {@inheritdoc} */ public function deleteByType($type) { + if (!$this->session->isStarted()) { + return []; + } // Flash bag gets and clears flash messages from the stack. - return $this->flashBag->get($type); + return $this->getFlashBag()->get($type); } /** * {@inheritdoc} */ public function messagesByType($type) { - return $this->flashBag->peek($type); + if (!$this->session->isStarted()) { + return []; + } + return $this->getFlashBag()->peek($type); } } diff --git a/core/lib/Drupal/Core/Session/SessionManager.php b/core/lib/Drupal/Core/Session/SessionManager.php index 607103109d..f87435c56d 100644 --- a/core/lib/Drupal/Core/Session/SessionManager.php +++ b/core/lib/Drupal/Core/Session/SessionManager.php @@ -5,6 +5,7 @@ use Drupal\Component\Utility\Crypt; use Drupal\Core\Database\Connection; use Drupal\Core\DependencyInjection\DependencySerializationTrait; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage; @@ -108,6 +109,11 @@ public function start() { } $request = $this->requestStack->getCurrentRequest(); + // If a session is started prior to the the request stack having the request + // create one from globals. + if (!$request) { + $request = Request::createFromGlobals(); + } $this->setOptions($this->sessionConfiguration->getOptions($request)); if ($this->sessionConfiguration->hasSession($request)) {