Esempio n. 1
0
 /**
  * Make a request to the database webservice.
  *
  * @param string       $method The HTTP method to use [POST, PUT, GET].
  * @param string       $url    The URL to send the request to.
  * @param array|string $data   The data to send along with the request.
  *
  * @return mixed the answer from the database webservice
  */
 protected function request($method, $url, $data = null)
 {
     switch ($method) {
         case "POST":
             $this->curl->setOption(CURLOPT_POST, 1);
             if ($data) {
                 $this->curl->setOption(CURLOPT_POSTFIELDS, $data);
             }
             break;
         case "PUT":
             $this->curl->setOption(CURLOPT_CUSTOMREQUEST, "PUT");
             if ($data) {
                 $this->curl->setOption(CURLOPT_POSTFIELDS, http_build_query($data));
             }
             break;
         default:
             if ($data) {
                 $url = sprintf("%s?%s", $url, http_build_query($data));
             }
     }
     $this->curl->setOption(CURLOPT_URL, $url);
     $this->curl->setOption(CURLOPT_RETURNTRANSFER, 1);
     $result = $this->curl->execute();
     $this->curl->close();
     return $result;
 }