public static function create(CouchDb $db, $data, $class = null)
 {
     if (null === $class) {
         $data = CouchData::makeArray($data);
         $class = isset($data['php_class']) ? $data['php_class'] : __CLASS__;
     }
     return new $class($db, $data);
 }
 /**
  * checks if the request was succesful, if not it throws a CouchException
  *
  * @return void
  * @throws CouchException The exception thrown by the server
  * @author The Young Shepherd
  **/
 protected function checkSuccess()
 {
     if (!$this->response->isSuccessful()) {
         $responseBody = CouchData::makeArray($this->response->getBody());
         $error = isset($responseBody['error']) ? $responseBody['error'] : 'Unknown';
         // camelize the error
         $error = implode('', array_map('ucfirst', explode('_', $error)));
         $class = 'Couch' . $error . 'Exception';
         if (!class_exists($class)) {
             $class = 'CouchException';
         }
         $code = $this->response->getStatus();
         $message = strtr("Received error (%status%): %error% (%reason%).", array('%status%' => $code, '%error%' => $error, '%reason%' => isset($responseBody['reason']) ? $responseBody['reason'] : 'Unknown reason'));
         throw new $class($message, $code, null, $this->getObject());
     }
 }