Overview

Namespaces

  • Evenement
  • None
  • PHP
  • Psr
    • Http
      • Message
  • Ratchet
    • Http
    • RFC6455
      • Handshake
      • Messaging
    • Server
    • Session
      • Serialize
      • Storage
        • Proxy
    • Wamp
    • WebSocket
  • React
    • EventLoop
      • Tick
      • Timer
    • Socket
    • Stream
  • Symfony
    • Component
      • HttpFoundation
        • Session
          • Attribute
          • Flash
          • Storage
            • Handler
            • Proxy
      • Routing
        • Annotation
        • Exception
        • Generator
          • Dumper
        • Loader
          • DependencyInjection
        • Matcher
          • Dumper
        • Tests
          • Annotation
          • Fixtures
            • AnnotatedClasses
            • OtherAnnotatedClasses
          • Generator
            • Dumper
          • Loader
          • Matcher
            • Dumper

Classes

  • VirtualSessionStorage
  • Overview
  • Namespace
  • Class
  • Tree
 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:      * @var \Ratchet\Session\Serialize\HandlerInterface
10:      */
11:     protected $_serializer;
12: 
13:     /**
14:      * @param \SessionHandlerInterface                    $handler
15:      * @param string                                      $sessionId The ID of the session to retrieve
16:      * @param \Ratchet\Session\Serialize\HandlerInterface $serializer
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:      * {@inheritdoc}
27:      */
28:     public function start() {
29:         if ($this->started && !$this->closed) {
30:             return true;
31:         }
32: 
33:         // You have to call Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler::open() to use
34:         // pdo_sqlite (and possible pdo_*) as session storage, if you are using a DSN string instead of a \PDO object
35:         // in the constructor. The method arguments are filled with the values, which are also used by the symfony
36:         // framework in this case. This must not be the best choice, but it works.
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:      * {@inheritdoc}
53:      */
54:     public function regenerate($destroy = false, $lifetime = null) {
55:         // .. ?
56:     }
57: 
58:     /**
59:      * {@inheritdoc}
60:      */
61:     public function save() {
62:         // get the data from the bags?
63:         // serialize the data
64:         // save the data using the saveHandler
65: //        $this->saveHandler->write($this->saveHandler->getId(),
66: 
67:         if (!$this->saveHandler->isWrapper() && !$this->getSaveHandler()->isSessionHandlerInterface()) {
68:             $this->saveHandler->setActive(false);
69:         }
70: 
71:         $this->closed = true;
72:     }
73: 
74:     /**
75:      * {@inheritdoc}
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: 
Ratchet API documentation generated by ApiGen 2.8.0