Exemple #1
0
 /**
  * Test expiration of namespaces and namespace variables.
  * @return void
  */
 public function testSetExpiration()
 {
     // try to expire whole namespace
     $s = $this->session->getNamespace('expire');
     $s->a = 'apple';
     $s->p = 'pear';
     $s['o'] = 'orange';
     $s->setExpiration('+ 5 seconds');
     $this->session->close();
     sleep(6);
     $this->session->start();
     $s = $this->session->getNamespace('expire');
     $result = $this->serialize($s->getIterator());
     $this->assertEquals('', $result, 'iteration over named Session namespace failed');
     // try to expire only 1 of the keys
     $s = $this->session->getNamespace('expireSingle');
     $s->setExpiration(5, 'g');
     $s->g = 'guava';
     $s->p = 'plum';
     $this->session->close();
     sleep(6);
     $this->session->start();
     $s = $this->session->getNamespace('expireSingle');
     $result = $this->serialize($s->getIterator());
     $this->assertEquals('p=plum;', $result, 'iteration over named Session namespace failed');
 }
Exemple #2
0
 /**
  * Gets current session
  * @param string $namespace
  * @return \Stupid\Session|\Stupid\SessionNamespace
  */
 public static function getSession($namespace = null)
 {
     if (self::$session === null) {
         $s = new Session();
         self::$session = $namespace === null ? $s : $s->getNamespace($namespace);
         return self::$session;
     }
     return $namespace === null ? self::$session : self::$session->getNamespace($namespace);
 }