Beispiel #1
0
 public function read($id)
 {
     $result = Cache::read($id, $this->cacheKey);
     if ($result) {
         return $result;
     }
     return parent::read($id);
 }
 private function __getUserIdFromSession($sessionId)
 {
     $dbs = new DatabaseSession();
     $sessionData = $dbs->read($sessionId);
     $unserializedData = [];
     $offset = 0;
     while ($offset < strlen($sessionData)) {
         if (!strstr(substr($sessionData, $offset), "|")) {
             throw new \Exception("invalid data, remaining: " . substr($sessionData, $offset));
         }
         $pos = strpos($sessionData, "|", $offset);
         $num = $pos - $offset;
         $varname = substr($sessionData, $offset, $num);
         $offset += $num + 1;
         $data = unserialize(substr($sessionData, $offset));
         $unserializedData[$varname] = $data;
         $offset += strlen(serialize($data));
     }
     return !empty($unserializedData['Auth']['User']['id']) ? $unserializedData['Auth']['User']['id'] : null;
 }
 /**
  * test the garbage collector
  *
  * @return void
  */
 public function testGc()
 {
     TableRegistry::clear();
     ini_set('session.gc_maxlifetime', 0);
     $storage = new DatabaseSession();
     $storage->write('foo', 'Some value');
     sleep(1);
     $storage->gc(0);
     $this->assertSame('', $storage->read('foo'));
 }
 /**
  * test the garbage collector
  *
  * @return void
  */
 public function testGc()
 {
     TableRegistry::clear();
     Configure::write('Session.timeout', 0);
     $storage = new DatabaseSession();
     $storage->write('foo', 'Some value');
     sleep(1);
     $storage->gc(0);
     $this->assertFalse($storage->read('foo'));
 }