Example #1
0
 /**
  * @param \Wandu\Http\Contracts\SessionInterface $session
  * @param \Wandu\Http\Contracts\CookieJarInterface $cookieJar
  */
 public function toCookieJar(SessionInterface $session, CookieJarInterface $cookieJar)
 {
     $sessionName = $this->config['name'];
     $this->adapter->write($session->getId(), $session->toArray());
     if (!$cookieJar->has($sessionName)) {
         $sessionId = $this->generateId();
         $cookieJar->set($sessionName, $sessionId, (new DateTime())->setTimestamp(time() + $this->config['timeout']));
     }
 }
Example #2
0
 /**
  * @param \Wandu\Http\Contracts\SessionInterface $session
  * @param \Wandu\Http\Contracts\CookieJarInterface $cookieJar
  * @return \Wandu\Http\Contracts\SessionInterface $session
  */
 public function toCookieJar(SessionInterface $session, CookieJarInterface $cookieJar)
 {
     $sessionName = $this->config['name'];
     // save to handler
     $this->handler->write($session->getId(), serialize($session->getRawParams()));
     // apply to cookie-jar
     $cookieJar->set($sessionName, $session->getId(), (new DateTime())->setTimestamp(time() + $this->config['timeout']));
     // garbage collection
     $pick = rand(1, max(1, $this->config['gc_frequency']));
     if ($pick === 1) {
         $this->handler->gc($this->config['timeout']);
     }
     return $session;
 }