WriteSafeSessionHandler.php in Drupal 8
File
core/lib/Drupal/Core/Session/WriteSafeSessionHandler.php
View source
<?php
namespace Drupal\Core\Session;
class WriteSafeSessionHandler implements \SessionHandlerInterface, WriteSafeSessionHandlerInterface {
protected $wrappedSessionHandler;
protected $sessionWritable;
private $readSessions;
public function __construct(\SessionHandlerInterface $wrapped_session_handler, $session_writable = TRUE) {
$this->wrappedSessionHandler = $wrapped_session_handler;
$this->sessionWritable = $session_writable;
}
public function close() {
return $this->wrappedSessionHandler
->close();
}
public function destroy($session_id) {
return $this->wrappedSessionHandler
->destroy($session_id);
}
public function gc($max_lifetime) {
return $this->wrappedSessionHandler
->gc($max_lifetime);
}
public function open($save_path, $session_id) {
return $this->wrappedSessionHandler
->open($save_path, $session_id);
}
public function read($session_id) {
$value = $this->wrappedSessionHandler
->read($session_id);
$this->readSessions[$session_id] = $value;
return $value;
}
public function write($session_id, $session_data) {
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);
}
return TRUE;
}
public function setSessionWritable($flag) {
$this->sessionWritable = (bool) $flag;
}
public function isSessionWritable() {
return $this->sessionWritable;
}
}