You are here

protected function Lockr::request in Lockr 7

Same name and namespace in other branches
  1. 7.2 vendor/lockr/lockr-client/src/Lockr.php \Lockr\Lockr::request()
5 calls to Lockr::request()
Lockr::delete in src/Lockr/Lockr.php
Lockr::get in src/Lockr/Lockr.php
Lockr::head in src/Lockr/Lockr.php
Lockr::patch in src/Lockr/Lockr.php
Lockr::post in src/Lockr/Lockr.php

File

src/Lockr/Lockr.php, line 115

Class

Lockr
Primary interface for Lockr API calls.

Namespace

Lockr

Code

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);
  return array(
    $code,
    $resp,
  );
}