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;
15 * Wraps another SessionHandlerInterface to only write the session when it has been modified.
17 * @author Adrien Brault <adrien.brault@gmail.com>
19 class WriteCheckSessionHandler implements \SessionHandlerInterface
22 * @var \SessionHandlerInterface
24 private $wrappedSessionHandler;
27 * @var array sessionId => session
29 private $readSessions;
31 public function __construct(\SessionHandlerInterface $wrappedSessionHandler)
33 $this->wrappedSessionHandler = $wrappedSessionHandler;
39 public function close()
41 return $this->wrappedSessionHandler->close();
47 public function destroy($sessionId)
49 return $this->wrappedSessionHandler->destroy($sessionId);
55 public function gc($maxlifetime)
57 return $this->wrappedSessionHandler->gc($maxlifetime);
63 public function open($savePath, $sessionName)
65 return $this->wrappedSessionHandler->open($savePath, $sessionName);
71 public function read($sessionId)
73 $session = $this->wrappedSessionHandler->read($sessionId);
75 $this->readSessions[$sessionId] = $session;
83 public function write($sessionId, $data)
85 if (isset($this->readSessions[$sessionId]) && $data === $this->readSessions[$sessionId]) {
89 return $this->wrappedSessionHandler->write($sessionId, $data);