Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Client.php

function Client::prepareDefaults

Merges default options into the array.

Parameters

array $options Options to modify by reference:

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 283

Class

Client
@final

Namespace

GuzzleHttp

Code

private function prepareDefaults(array $options) : array {
    $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'] = [];
            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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal