1: <?php
2: namespace Ratchet\Session\Storage;
3: use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
4: use Ratchet\Session\Storage\Proxy\VirtualProxy;
5: use Ratchet\Session\Serialize\HandlerInterface;
6:
7: class VirtualSessionStorage extends NativeSessionStorage {
8: 9: 10:
11: protected $_serializer;
12:
13: 14: 15: 16: 17:
18: public function __construct(\SessionHandlerInterface $handler, $sessionId, HandlerInterface $serializer) {
19: $this->setSaveHandler($handler);
20: $this->saveHandler->setId($sessionId);
21: $this->_serializer = $serializer;
22: $this->setMetadataBag(null);
23: }
24:
25: 26: 27:
28: public function start() {
29: if ($this->started && !$this->closed) {
30: return true;
31: }
32:
33:
34:
35:
36:
37: $this->saveHandler->open(session_save_path(), session_name());
38:
39: $rawData = $this->saveHandler->read($this->saveHandler->getId());
40: $sessionData = $this->_serializer->unserialize($rawData);
41:
42: $this->loadSession($sessionData);
43:
44: if (!$this->saveHandler->isWrapper() && !$this->saveHandler->isSessionHandlerInterface()) {
45: $this->saveHandler->setActive(false);
46: }
47:
48: return true;
49: }
50:
51: 52: 53:
54: public function regenerate($destroy = false, $lifetime = null) {
55:
56: }
57:
58: 59: 60:
61: public function save() {
62:
63:
64:
65:
66:
67: if (!$this->saveHandler->isWrapper() && !$this->getSaveHandler()->isSessionHandlerInterface()) {
68: $this->saveHandler->setActive(false);
69: }
70:
71: $this->closed = true;
72: }
73:
74: 75: 76:
77: public function setSaveHandler($saveHandler = null) {
78: if (!($saveHandler instanceof \SessionHandlerInterface)) {
79: throw new \InvalidArgumentException('Handler must be instance of SessionHandlerInterface');
80: }
81:
82: if (!($saveHandler instanceof VirtualProxy)) {
83: $saveHandler = new VirtualProxy($saveHandler);
84: }
85:
86: $this->saveHandler = $saveHandler;
87: }
88: }
89: