/**
  *   @see parent::sessionRead
  */
 public function sessionRead($id)
 {
     $result = parent::sessionRead($id);
     $this->setSessionKey($id);
     // Find session persistent object
     $session = SessionQuery::create()->filterBySessionKey($id)->findOne();
     // Associate an IP address with the session & user
     if (!is_null($session) && $session instanceof Session) {
         $context = sfContext::getInstance();
         if ($session->getClientIpAddress() == null) {
             $session->setClientIpAddress($context->getRequest()->getRemoteAddress());
         }
         // Associate User with session
         $user = $context->getUser();
         if ($session->getUserId() == null && !is_null($user) && $user->isAuthenticated()) {
             $session->setUser($user->getProfile());
         }
         $session->save();
     }
     return $result;
 }
Ejemplo n.º 2
0
$newSessionData = 'foo:bar:baz';
$storage->sessionWrite(session_id(), $newSessionData);
$t->isnt(session_id(), $session_id, 'regenerate() regenerated the session with a different session id');
// checking if the old session record still exists
$result = $connection->query(sprintf('SELECT sess_id, sess_data FROM session WHERE sess_id = "%s"', $session_id));
$data = $result->fetchAll();
$t->is(count($data), 1, 'regenerate() has kept destroyed old session');
// checking if the new session record has been created
$result = $connection->query(sprintf('SELECT sess_id, sess_data FROM session WHERE sess_id = "%s"', session_id()));
$data = $result->fetchAll();
$t->is(count($data), 1, 'regenerate() has created a new session record');
$t->is($data[0]['sess_data'], $newSessionData, 'regenerate() has created a new record with correct data');
$session_id = session_id();
// sessionRead()
try {
    $retrieved_data = $storage->sessionRead($session_id);
    $t->pass('sessionRead() does not throw an exception');
} catch (Exception $e) {
    $t->fail('sessionRead() does not throw an exception');
}
$t->is($retrieved_data, $newSessionData, 'sessionRead() reads session data');
// sessionWrite()
$otherSessionData = 'foo:foo:foo';
try {
    $write = $storage->sessionWrite($session_id, $otherSessionData);
    $t->pass('sessionWrite() does not throw an exception');
} catch (Exception $e) {
    $t->fail('sessionWrite() does not throw an exception');
}
$t->ok($write, 'sessionWrite() returns true');
$t->is($storage->sessionRead($session_id), $otherSessionData, 'sessionWrite() wrote session data');