Mercurial > hg > isophonics-drupal-site
diff core/lib/Drupal/Core/Session/WriteSafeSessionHandler.php @ 18:af1871eacc83
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:33:08 +0100 |
parents | 4c8ae668cc8c |
children |
line wrap: on
line diff
--- a/core/lib/Drupal/Core/Session/WriteSafeSessionHandler.php Thu Feb 28 13:21:36 2019 +0000 +++ b/core/lib/Drupal/Core/Session/WriteSafeSessionHandler.php Thu May 09 15:33:08 2019 +0100 @@ -3,7 +3,7 @@ namespace Drupal\Core\Session; /** - * Wraps another SessionHandlerInterface to prevent writes when not allowed. + * Wraps the session handler to prevent writes when not necessary or allowed. */ class WriteSafeSessionHandler implements \SessionHandlerInterface, WriteSafeSessionHandlerInterface { @@ -20,6 +20,14 @@ protected $sessionWritable; /** + * The read sessions. + * + * @var array + * Session data keyed by the session ID. + */ + private $readSessions; + + /** * Constructs a new write safe session handler. * * @param \SessionHandlerInterface $wrapped_session_handler @@ -64,19 +72,23 @@ * {@inheritdoc} */ public function read($session_id) { - return $this->wrappedSessionHandler->read($session_id); + $value = $this->wrappedSessionHandler->read($session_id); + $this->readSessions[$session_id] = $value; + return $value; } /** * {@inheritdoc} */ public function write($session_id, $session_data) { + // Only write the session when it has been modified. + if (isset($this->readSessions[$session_id]) && $this->readSessions[$session_id] === $session_data) { + return TRUE; + } if ($this->isSessionWritable()) { return $this->wrappedSessionHandler->write($session_id, $session_data); } - else { - return TRUE; - } + return TRUE; } /**