コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function write($user, $remember = false)
 {
     if ($token = $this->getToken()) {
         $this->connection->delete($this->config['table'], ['id' => sha1($token)]);
     }
     $id = $this->random->generateString(64);
     $this->cookie->set($this->config['cookie']['name'], $id, $this->config['cookie']['lifetime'] + time());
     $this->createTable();
     $this->connection->insert($this->config['table'], ['id' => sha1($id), 'user_id' => $user, 'access' => date('Y-m-d H:i:s'), 'status' => $remember ? self::STATUS_REMEMBERED : self::STATUS_ACTIVE, 'data' => json_encode(['ip' => $this->getRequest()->getClientIp(), 'user-agent' => $this->getRequest()->headers->get('User-Agent')])]);
 }
コード例 #2
0
 /**
  * Deletes an entity.
  *
  * @param  object $entity
  * @throws \InvalidArgumentException
  */
 public function delete($entity)
 {
     $metadata = $this->getMetadata($entity);
     $identifier = $metadata->getIdentifier(true);
     if ($value = $metadata->getValue($entity, $identifier, true)) {
         $this->trigger(Events::DELETING, $metadata, [$entity]);
         $this->connection->delete($metadata->getTable(), [$identifier => $value]);
         $this->trigger(Events::DELETED, $metadata, [$entity]);
         $metadata->setValue($entity, $identifier, null, true);
     } else {
         throw new \InvalidArgumentException("Can't remove entity with empty identifier value.");
     }
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function write($id, $data)
 {
     try {
         $params = ['id' => $id, 'data' => base64_encode($data), 'time' => date('Y-m-d H:i:s')];
         if (null !== ($sql = $this->getMergeSql())) {
             $this->connection->executeQuery($sql, $params);
             return true;
         }
         $this->connection->beginTransaction();
         try {
             $this->connection->delete($this->table, ['id' => $id]);
             $this->connection->insert($this->table, $params);
             $this->connection->commit();
         } catch (ConnectionException $e) {
             $this->connection->rollback();
             throw $e;
         }
     } catch (\PDOException $e) {
         throw new \RuntimeException(sprintf('PDOException was thrown when trying to write the session data: %s', $e->getMessage()), 0, $e);
     }
     return true;
 }