Exemplo n.º 1
0
 /**
  * Reads data from this storage.
  * Reading non-existent key will return null.
  *
  * @param string $key key to the data
  *
  * @returns mixed Data associated with the key
  *
  * @throws sfStorageException on failure
  */
 public function read($key)
 {
     Preconditions::checkIsString($key);
     if ($this->selectStatement === null) {
         $this->selectStatement = $this->prepareSelect();
     }
     $statement = $this->selectStatement;
     $statement->bindValue('key', $key);
     if (!$statement->execute()) {
         $info = $statement->errorInfo();
         throw new sfStorageException("Problem reading key '{$key}' : " . $info[2]);
     }
     // Warning: do not use $statement->rowCount, as it may not return correct values on SELECTs
     $result = $statement->fetchAll();
     if (count($result) == 0) {
         return null;
     }
     if (count($result) != 1) {
         throw new sfStorageException("There are duplicate entries for key '{$key}'");
     }
     $data = $result[0][0];
     return Serializer::deserialize($data);
 }
Exemplo n.º 2
0
 private function serializeDeserialize($value)
 {
     return Serializer::deserialize(Serializer::serialize($value));
 }