function cmis_common_cmis_invoke in CMIS API 6.4
Same name and namespace in other branches
- 7.2 cmis_common/cmis_common.module \cmis_common_cmis_invoke()
- 7 cmis_common/cmis_common.module \cmis_common_cmis_invoke()
Implementation of hook_cmis_invoke($url, $properties, $settings)
1 call to cmis_common_cmis_invoke()
- cmis_headerswing_cmis_invoke in cmis_headerswing/
cmis_headerswing.module - Implementation of hook_cmis_invoke($url, $properties, $settings)
File
- cmis_common/
cmis_common.module, line 54
Code
function cmis_common_cmis_invoke($url, $properties, $settings, $dry_run = FALSE) {
$session = curl_init($url);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
if ($settings['user']) {
curl_setopt($session, CURLOPT_USERPWD, $settings['user'] . ":" . $settings['password']);
}
curl_setopt($session, CURLOPT_CUSTOMREQUEST, $properties['method']);
if ($properties['headers']) {
$headers = array();
foreach ($properties['headers'] as $header_name => $header_value) {
$headers[] = $header_name . ': ' . $header_value;
}
curl_setopt($session, CURLOPT_HTTPHEADER, $headers);
}
if ($properties['data']) {
curl_setopt($session, CURLOPT_POSTFIELDS, $properties['data']);
}
if ($properties['method'] == "POST") {
curl_setopt($session, CURLOPT_POST, true);
}
$retval = new stdClass();
$retval->url = $url;
$retval->method = $properties['method'];
$retval->content_sent = $properties['data'];
$retval->content_type_sent = $properties['headers']['Content-Type'];
if (!$dry_run) {
$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);
if (!in_array($retval->code, array(
200,
201,
204,
))) {
throw new CMISException(t("HTTP call to [@url] returned [@code]. Response: @response", array(
'@code' => $retval->code,
'@response' => strip_tags($retval->body),
'@url' => $url,
)));
}
}
else {
$retval->body = NULL;
$retval->curl_session = $session;
$retval->code = 0;
$retval->content_type = NULL;
$retval->content_length = NULL;
}
return $retval;
}