83a1f2c063c057443bad6152388f6b810059c5a6
[yaffs-website] / vendor / symfony / http-foundation / Session / Storage / Handler / StrictSessionHandler.php
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  * Adds basic `SessionUpdateTimestampHandlerInterface` behaviors to another `SessionHandlerInterface`.
16  *
17  * @author Nicolas Grekas <p@tchwork.com>
18  */
19 class StrictSessionHandler extends AbstractSessionHandler
20 {
21     private $handler;
22     private $doDestroy;
23
24     public function __construct(\SessionHandlerInterface $handler)
25     {
26         if ($handler instanceof \SessionUpdateTimestampHandlerInterface) {
27             throw new \LogicException(sprintf('"%s" is already an instance of "SessionUpdateTimestampHandlerInterface", you cannot wrap it with "%s".', \get_class($handler), self::class));
28         }
29
30         $this->handler = $handler;
31     }
32
33     /**
34      * {@inheritdoc}
35      */
36     public function open($savePath, $sessionName)
37     {
38         parent::open($savePath, $sessionName);
39
40         return $this->handler->open($savePath, $sessionName);
41     }
42
43     /**
44      * {@inheritdoc}
45      */
46     protected function doRead($sessionId)
47     {
48         return $this->handler->read($sessionId);
49     }
50
51     /**
52      * {@inheritdoc}
53      */
54     public function updateTimestamp($sessionId, $data)
55     {
56         return $this->write($sessionId, $data);
57     }
58
59     /**
60      * {@inheritdoc}
61      */
62     protected function doWrite($sessionId, $data)
63     {
64         return $this->handler->write($sessionId, $data);
65     }
66
67     /**
68      * {@inheritdoc}
69      */
70     public function destroy($sessionId)
71     {
72         $this->doDestroy = true;
73         $destroyed = parent::destroy($sessionId);
74
75         return $this->doDestroy ? $this->doDestroy($sessionId) : $destroyed;
76     }
77
78     /**
79      * {@inheritdoc}
80      */
81     protected function doDestroy($sessionId)
82     {
83         $this->doDestroy = false;
84
85         return $this->handler->destroy($sessionId);
86     }
87
88     /**
89      * {@inheritdoc}
90      */
91     public function close()
92     {
93         return $this->handler->close();
94     }
95
96     /**
97      * {@inheritdoc}
98      */
99     public function gc($maxlifetime)
100     {
101         return $this->handler->gc($maxlifetime);
102     }
103 }