Exemple #1
0
 /**
  * Close session and save data.
  */
 public function close(Response $response)
 {
     if ($this->id) {
         if ($this->isRefreshReady()) {
             $this->backend->delete($this->id);
             $this->id = TokenGenerator::get();
             $this->data['refreshTime'] = time();
             $this->data['refreshVisits'] = 0;
         }
         $this->data['refreshVisits']++;
         $this->data['lastQuery'] = $this->request->url();
         $this->data['lastTime'] = time();
         $this->backend->save($this->id, $this->data, $this->ttl);
         $response->cookie($this->cookie, $this->id, time() + $this->ttl);
     }
     if (rand() / getrandmax() < $this->gcProbability) {
         $this->backend->clear($this->ttl);
     }
     $this->closed = true;
 }
Exemple #2
0
 /**
  * Register autologed session for currently authorized user.
  * 
  * @return self
  */
 public function forget(Request $request, Response $response)
 {
     if (!$this->autologin) {
         throw new \BadMethodCallException('To use AutoLogin functionality provide instance of AutologinProvider.');
     }
     if ($key = $request->cookie($this->autologinCookie)) {
         $response->cookie($this->autologinCookie, '', 1);
         $this->autologin->delete($key);
     }
     return $this;
 }