You are here

private function Client::prepareDefaults in Lockr 7.3

Merges default options into the array.

Parameters

array $options Options to modify by reference:

Return value

array

2 calls to Client::prepareDefaults()
Client::requestAsync in vendor/guzzlehttp/guzzle/src/Client.php
Create and send an asynchronous HTTP request.
Client::sendAsync in vendor/guzzlehttp/guzzle/src/Client.php
Asynchronously send an HTTP request.

File

vendor/guzzlehttp/guzzle/src/Client.php, line 213

Class

Client
@method ResponseInterface get(string|UriInterface $uri, array $options = []) @method ResponseInterface head(string|UriInterface $uri, array $options = []) @method ResponseInterface put(string|UriInterface $uri, array $options = []) @method…

Namespace

GuzzleHttp

Code

private function prepareDefaults($options) {
  $defaults = $this->config;
  if (!empty($defaults['headers'])) {

    // Default headers are only added if they are not present.
    $defaults['_conditional'] = $defaults['headers'];
    unset($defaults['headers']);
  }

  // Special handling for headers is required as they are added as
  // conditional headers and as headers passed to a request ctor.
  if (array_key_exists('headers', $options)) {

    // Allows default headers to be unset.
    if ($options['headers'] === null) {
      $defaults['_conditional'] = null;
      unset($options['headers']);
    }
    elseif (!is_array($options['headers'])) {
      throw new \InvalidArgumentException('headers must be an array');
    }
  }

  // Shallow merge defaults underneath options.
  $result = $options + $defaults;

  // Remove null values.
  foreach ($result as $k => $v) {
    if ($v === null) {
      unset($result[$k]);
    }
  }
  return $result;
}