give
/
vendor
/
symfony
/
http-foundation
/
Session
/
Storage
/
Handler
/
WriteCheckSessionHandler.php
AbstractSessionHandler.php
4 years ago
MemcacheSessionHandler.php
4 years ago
MemcachedSessionHandler.php
4 years ago
MongoDbSessionHandler.php
4 years ago
NativeFileSessionHandler.php
4 years ago
NativeSessionHandler.php
4 years ago
NullSessionHandler.php
4 years ago
PdoSessionHandler.php
4 years ago
StrictSessionHandler.php
4 years ago
WriteCheckSessionHandler.php
4 years ago
WriteCheckSessionHandler.php
93 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | |
| 12 | namespace Symfony\Component\HttpFoundation\Session\Storage\Handler; |
| 13 | |
| 14 | /** |
| 15 | * Wraps another SessionHandlerInterface to only write the session when it has been modified. |
| 16 | * |
| 17 | * @author Adrien Brault <adrien.brault@gmail.com> |
| 18 | * |
| 19 | * @deprecated since version 3.4, to be removed in 4.0. Implement `SessionUpdateTimestampHandlerInterface` or extend `AbstractSessionHandler` instead. |
| 20 | */ |
| 21 | class WriteCheckSessionHandler implements \SessionHandlerInterface |
| 22 | { |
| 23 | private $wrappedSessionHandler; |
| 24 | |
| 25 | /** |
| 26 | * @var array sessionId => session |
| 27 | */ |
| 28 | private $readSessions; |
| 29 | |
| 30 | public function __construct(\SessionHandlerInterface $wrappedSessionHandler) |
| 31 | { |
| 32 | @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.', self::class), \E_USER_DEPRECATED); |
| 33 | |
| 34 | $this->wrappedSessionHandler = $wrappedSessionHandler; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * {@inheritdoc} |
| 39 | */ |
| 40 | public function close() |
| 41 | { |
| 42 | return $this->wrappedSessionHandler->close(); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * {@inheritdoc} |
| 47 | */ |
| 48 | public function destroy($sessionId) |
| 49 | { |
| 50 | return $this->wrappedSessionHandler->destroy($sessionId); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * {@inheritdoc} |
| 55 | */ |
| 56 | public function gc($maxlifetime) |
| 57 | { |
| 58 | return $this->wrappedSessionHandler->gc($maxlifetime); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * {@inheritdoc} |
| 63 | */ |
| 64 | public function open($savePath, $sessionName) |
| 65 | { |
| 66 | return $this->wrappedSessionHandler->open($savePath, $sessionName); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * {@inheritdoc} |
| 71 | */ |
| 72 | public function read($sessionId) |
| 73 | { |
| 74 | $session = $this->wrappedSessionHandler->read($sessionId); |
| 75 | |
| 76 | $this->readSessions[$sessionId] = $session; |
| 77 | |
| 78 | return $session; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * {@inheritdoc} |
| 83 | */ |
| 84 | public function write($sessionId, $data) |
| 85 | { |
| 86 | if (isset($this->readSessions[$sessionId]) && $data === $this->readSessions[$sessionId]) { |
| 87 | return true; |
| 88 | } |
| 89 | |
| 90 | return $this->wrappedSessionHandler->write($sessionId, $data); |
| 91 | } |
| 92 | } |
| 93 |