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