You are here

function CMISRepositoryWrapper::doRequest in CMIS API 7

Same name and namespace in other branches
  1. 6.4 cmis_common/lib/cmis_repository_wrapper.php \CMISRepositoryWrapper::doRequest()
  2. 6.3 cmis_common/lib/cmis_repository_wrapper.php \CMISRepositoryWrapper::doRequest()
4 calls to CMISRepositoryWrapper::doRequest()
CMISRepositoryWrapper::doDelete in cmis_common/lib/cmis_repository_wrapper.php
CMISRepositoryWrapper::doGet in cmis_common/lib/cmis_repository_wrapper.php
CMISRepositoryWrapper::doPost in cmis_common/lib/cmis_repository_wrapper.php
CMISRepositoryWrapper::doPut in cmis_common/lib/cmis_repository_wrapper.php
1 method overrides CMISRepositoryWrapper::doRequest()
CommonCMISService::doRequest in cmis_common/cmis_common.utils.inc

File

cmis_common/lib/cmis_repository_wrapper.php, line 71

Class

CMISRepositoryWrapper

Code

function doRequest($url, $method = "GET", $content = null, $contentType = null, $charset = null) {

  // Process the HTTP request
  // 'til now only the GET request has been tested
  // Does not URL encode any inputs yet
  if (is_array($this->auth_options)) {
    $url = CMISRepositoryWrapper::getOpUrl($url, $this->auth_options);
  }
  $session = curl_init($url);
  curl_setopt($session, CURLOPT_HEADER, false);
  curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
  if ($this->username) {
    curl_setopt($session, CURLOPT_USERPWD, $this->username . ":" . $this->password);
  }
  curl_setopt($session, CURLOPT_CUSTOMREQUEST, $method);
  if ($contentType) {
    $headers = array();
    $headers["Content-Type"] = $contentType;
    curl_setopt($session, CURLOPT_HTTPHEADER, $headers);
  }
  if ($method == "POST" && is_resource($content) && get_resource_type($content) == 'stream') {
    curl_setopt($session, CURLOPT_PUT, true);
    curl_setopt($session, CURLOPT_CUSTOMREQUEST, 'POST');
    curl_setopt($session, CURLOPT_HTTPHEADER, array(
      "Content-Type: " . $contentType,
    ));
    curl_setopt($session, CURLOPT_INFILE, $content);
  }
  else {
    if ($content) {
      curl_setopt($session, CURLOPT_POSTFIELDS, $content);
    }
    if ($method == "POST") {
      curl_setopt($session, CURLOPT_HTTPHEADER, array(
        "Content-Type: " . $contentType,
      ));
      curl_setopt($session, CURLOPT_POST, true);
    }
  }

  //TODO: Make this storage optional
  $retval = new stdClass();
  $retval->url = $url;
  $retval->method = $method;
  $retval->content_sent = $content;
  $retval->content_type_sent = $contentType;
  $retval->body = curl_exec($session);
  $retval->code = curl_getinfo($session, CURLINFO_HTTP_CODE);
  $retval->content_type = curl_getinfo($session, CURLINFO_CONTENT_TYPE);
  $retval->content_length = curl_getinfo($session, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
  curl_close($session);
  $this->last_request = $retval;
  return $retval;
}