protected function Lockr::request in Lockr 7.2
Same name and namespace in other branches
- 7 src/Lockr/Lockr.php \Lockr\Lockr::request()
5 calls to Lockr::request()
- Lockr::delete in vendor/
lockr/ lockr-client/ src/ Lockr.php - Lockr::get in vendor/
lockr/ lockr-client/ src/ Lockr.php - Lockr::head in vendor/
lockr/ lockr-client/ src/ Lockr.php - Lockr::patch in vendor/
lockr/ lockr-client/ src/ Lockr.php - Lockr::post in vendor/
lockr/ lockr-client/ src/ Lockr.php
File
- vendor/
lockr/ lockr-client/ src/ Lockr.php, line 120
Class
- Lockr
- Primary interface for Lockr API calls.
Namespace
LockrCode
protected function request($method, $uri, array $options = array()) {
$opts = array(
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_PORT => 443,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_URL => $uri,
CURLOPT_HTTPHEADER => array(
'Content-Type:',
),
);
if (in_array($method, array(
'POST',
'PATCH',
))) {
$data = json_encode($options['data']);
$opts[CURLOPT_POSTFIELDS] = $data;
$opts[CURLOPT_HTTPHEADER] = array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data),
);
}
if (isset($options['cert'])) {
$opts[CURLOPT_SSLCERT] = $options['cert'];
}
if (isset($options['auth'])) {
$opts[CURLOPT_USERPWD] = $options['auth'];
}
$ch = curl_init();
curl_setopt_array($ch, $opts);
$resp = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$body = json_decode($resp, true);
$json_error = json_last_error();
if ($code >= 400) {
if ($json_error !== JSON_ERROR_NONE) {
$body = array(
'title' => 'Unrecognized body',
'description' => $resp,
);
}
$this
->handleError($code, $body);
}
if (!$resp) {
return true;
}
if ($json_error !== JSON_ERROR_NONE) {
throw new LockrException(array(
'message' => $resp,
'code' => $code,
));
}
return $body;
}