read() public method

public read ( $session_id )
 /**
  * {@inheritdoc}
  */
 public function read($session_id)
 {
     $trace = \Drupal::service('session_test.session_handler_proxy_trace');
     $trace[] = ['BEGIN', $this->optionalArgument, __FUNCTION__, $session_id];
     $result = $this->sessionHandler->read($session_id);
     $trace[] = ['END', $this->optionalArgument, __FUNCTION__, $session_id];
     return $result;
 }
Esempio n. 2
0
 /**
  * @param \Wandu\Http\Contracts\CookieJarInterface $cookieJar
  * @return \Wandu\Http\Contracts\SessionInterface
  */
 public function fromCookieJar(CookieJarInterface $cookieJar)
 {
     $sessionName = $this->config['name'];
     if ($cookieJar->has($sessionName)) {
         $sessionId = $cookieJar->get($sessionName);
     } else {
         $sessionId = $this->generateId();
     }
     $data = @unserialize($this->handler->read($sessionId));
     return new Session($sessionId, $data ? $data : []);
 }
Esempio n. 3
0
 /**
  * @param ServerRequestInterface $request
  * @return Storage
  */
 public function readFromRequest(ServerRequestInterface $request)
 {
     $cookies = $request->getCookieParams();
     if (isset($cookies[$this->name])) {
         $this->id = $cookies[$this->name];
     } else {
         $this->id = $this->generateId();
         $this->reset = true;
     }
     return new Storage($this->handler->read($this->id));
 }
Esempio n. 4
0
 protected function initializeSession()
 {
     $this->data = [];
     $this->dataHash = null;
     $this->handler->open(null, $this->name);
     if (empty($this->id)) {
         $this->id = $this->generator->generateId();
     }
     $this->collectGarbage();
     // Must be done before read
     $data = $this->handler->read($this->id);
     if (!$data) {
         // Intentionally catch falsely values
         return;
     }
     if ($this->options->getBoolean('lazy_write', false)) {
         $this->dataHash = md5($data);
     }
     try {
         $this->data = $this->serializer->unserialize($data);
     } catch (\Exception $e) {
         // Destroy data upon unserialization error
         $this->handler->destroy($this->id);
     }
 }
Esempio n. 5
0
 /**
  * Read the session data from the handler.
  *
  * @return array
  */
 private function readFromHandler() : array
 {
     $data = $this->handler->read($this->id);
     if ($data) {
         return json_decode($this->encrypter->decrypt($data), true);
     }
     return [];
 }
Esempio n. 6
0
 /**
  * Read the session data from the handler.
  *
  * @return array
  */
 protected function readFromHandler()
 {
     $data = $this->handler->read($this->getId());
     if ($data) {
         $data = @unserialize($this->prepareForUnserialize($data));
         if ($data !== false) {
             return $data;
         }
     }
     return [];
 }
Esempio n. 7
0
 protected function initializeSession()
 {
     $this->handler->open(null, $this->id);
     $data = $this->handler->read($this->id);
     try {
         $this->data = $this->serializer->unserialize($data);
     } catch (\Exception $e) {
         // Destroy data upon unserialization error
         $this->handler->destroy($this->id);
     }
 }
Esempio n. 8
0
 public function testGarbageCollection()
 {
     $countOfSessionFiles = $this->getCountOfSessionFiles();
     $this->adapter->write('1', 'string 1');
     $this->adapter->write('2', 'string 2');
     $this->adapter->write('3', 'string 3');
     // increase 3 files
     $this->assertEquals($this->getCountOfSessionFiles(), $countOfSessionFiles + 3);
     $this->assertTrue($this->adapter->gc(1));
     $this->assertEquals('string 1', $this->adapter->read('1'));
     $this->assertEquals('string 2', $this->adapter->read('2'));
     $this->assertEquals('string 3', $this->adapter->read('3'));
     sleep(2);
     $this->assertTrue($this->adapter->gc(1));
     // decrease 3 files
     $this->assertEquals($this->getCountOfSessionFiles(), $countOfSessionFiles);
     $this->assertEquals('', $this->adapter->read('1'));
     $this->assertEquals('', $this->adapter->read('2'));
     $this->assertEquals('', $this->adapter->read('3'));
 }
Esempio n. 9
0
 /**
  * Read the session data from the handler.
  *
  * @return array
  */
 protected function readFromHandler()
 {
     $data = $this->handler->read($this->getId());
     return $data ? unserialize($data) : array();
 }
Esempio n. 10
0
 /**
  * {@inheritdoc}
  */
 public function read($sessionId)
 {
     return (string) $this->handler->read($sessionId);
 }
 /**
  * {@inheritdoc}
  */
 public function read($sessionId)
 {
     $session = $this->wrappedSessionHandler->read($sessionId);
     $this->readSessions[$sessionId] = $session;
     return $session;
 }
Esempio n. 12
0
 /**
  * {@inheritdoc}
  */
 public function read($session_id)
 {
     return $this->wrappedSessionHandler->read($session_id);
 }