4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
14 @trigger_error(sprintf('The %s class is deprecated since Symfony 3.4 and will be removed in 4.0. Implement `SessionUpdateTimestampHandlerInterface` or extend `AbstractSessionHandler` instead.', WriteCheckSessionHandler::class), E_USER_DEPRECATED);
17 * Wraps another SessionHandlerInterface to only write the session when it has been modified.
19 * @author Adrien Brault <adrien.brault@gmail.com>
21 * @deprecated since version 3.4, to be removed in 4.0. Implement `SessionUpdateTimestampHandlerInterface` or extend `AbstractSessionHandler` instead.
23 class WriteCheckSessionHandler implements \SessionHandlerInterface
25 private $wrappedSessionHandler;
28 * @var array sessionId => session
30 private $readSessions;
32 public function __construct(\SessionHandlerInterface $wrappedSessionHandler)
34 $this->wrappedSessionHandler = $wrappedSessionHandler;
40 public function close()
42 return $this->wrappedSessionHandler->close();
48 public function destroy($sessionId)
50 return $this->wrappedSessionHandler->destroy($sessionId);
56 public function gc($maxlifetime)
58 return $this->wrappedSessionHandler->gc($maxlifetime);
64 public function open($savePath, $sessionName)
66 return $this->wrappedSessionHandler->open($savePath, $sessionName);
72 public function read($sessionId)
74 $session = $this->wrappedSessionHandler->read($sessionId);
76 $this->readSessions[$sessionId] = $session;
84 public function write($sessionId, $data)
86 if (isset($this->readSessions[$sessionId]) && $data === $this->readSessions[$sessionId]) {
90 return $this->wrappedSessionHandler->write($sessionId, $data);