original_string: public function put($id, $data)
    {
      if(!$this->db) {
        throw new SagException('No database specified');
      }
  
      if(!is_string($id)) {
        throw new SagException('put() expected a string for the doc id.');
      }
  
      if(!isset($data) || (!is_object($data) && !is_string($data) && !is_array($data))) {
        throw new SagException('put() needs an object for data - are you trying to use delete()?');
      }
  
      $toSend = (is_string($data)) ? $data : json_encode($data);
      $id = urlencode($id);
  
      $url = "/{$this->db}/$id";
      $response = $this->procPacket('PUT', $url, $toSend);
  
      unset($toSend);
  
      /*
       * We're going to pretend like we issued a GET or HEAD by replacing the PUT
       * response's body with the data we sent. We then update that data with the
       * _rev from the PUT's response's body. Of course this should only run when
       * there is a successful write to the database: we don't want to be caching
       * failures.
       */
      if($this->cache && $response->body->ok) {
        if(is_string($data)) {
          $data = json_decode($data);
        }
  
        $data->_rev = $response->body->rev;
  
        $toCache = clone $response;
        $toCache->body = $data;
  
        $this->cache->set($url, $toCache);
  
        unset($toCache);
      }
  
      return $response;
    }
code: public function put($id, $data)
    {
      if(!$this->db) {
        throw new SagException('No database specified');
      }
  
      if(!is_string($id)) {
        throw new SagException('put() expected a string for the doc id.');
      }
  
      if(!isset($data) || (!is_object($data) && !is_string($data) && !is_array($data))) {
        throw new SagException('put() needs an object for data - are you trying to use delete()?');
      }
  
      $toSend = (is_string($data)) ? $data : json_encode($data);
      $id = urlencode($id);
  
      $url = "/{$this->db}/$id";
      $response = $this->procPacket('PUT', $url, $toSend);
  
      unset($toSend);
  
      /*
       * We're going to pretend like we issued a GET or HEAD by replacing the PUT
       * response's body with the data we sent. We then update that data with the
       * _rev from the PUT's response's body. Of course this should only run when
       * there is a successful write to the database: we don't want to be caching
       * failures.
       */
      if($this->cache && $response->body->ok) {
        if(is_string($data)) {
          $data = json_decode($data);
        }
  
        $data->_rev = $response->body->rev;
  
        $toCache = clone $response;
        $toCache->body = $data;
  
        $this->cache->set($url, $toCache);
  
        unset($toCache);
      }
  
      return $response;
    }
code_tokens: public function put ( $ id , $ data ) { if ( ! $ this -> db ) { throw new SagException ( 'No database specified' ) ; } if ( ! is_string ( $ id ) ) { throw new SagException ( 'put() expected a string for the doc id.' ) ; } if ( ! isset ( $ data ) || ( ! is_object ( $ data ) && ! is_string ( $ data ) && ! is_array ( $ data ) ) ) { throw new SagException ( 'put() needs an object for data - are you trying to use delete()?' ) ; } $ toSend = ( is_string ( $ data ) ) ? $ data : json_encode ( $ data ) ; $ id = urlencode ( $ id ) ; $ url = "/{$this->db}/$id" ; $ response = $ this -> procPacket ( 'PUT' , $ url , $ toSend ) ; unset ( $ toSend ) ; /*
       * We're going to pretend like we issued a GET or HEAD by replacing the PUT
       * response's body with the data we sent. We then update that data with the
       * _rev from the PUT's response's body. Of course this should only run when
       * there is a successful write to the database: we don't want to be caching
       * failures.
       */ if ( $ this -> cache && $ response -> body -> ok ) { if ( is_string ( $ data ) ) { $ data = json_decode ( $ data ) ; } $ data -> _rev = $ response -> body -> rev ; $ toCache = clone $ response ; $ toCache -> body = $ data ; $ this -> cache -> set ( $ url , $ toCache ) ; unset ( $ toCache ) ; } return $ response ; }
docstring: PUT's the data to the document.
  
  @param string $id The document's _id.
  @param mixed $data The document, which should have _id and _rev
  properties. Can be an object, array, or string.
  
  @return mixed
docstring_tokens: PUT s the data to the document .