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

Breadcrumb

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

class Client

Same name in this branch
  1. 11.1.x vendor/guzzlehttp/guzzle/src/Client.php \GuzzleHttp\Client

HTTP Adapter for Guzzle 7.

@author Tobias Nyholm <tobias.nyholm@gmail.com>

Hierarchy

  • class \Http\Adapter\Guzzle7\Client implements \Http\Client\HttpClient, \Http\Client\HttpAsyncClient

Expanded class hierarchy of Client

1 file declares its use of Client
CommonClassesStrategy.php in vendor/php-http/discovery/src/Strategy/CommonClassesStrategy.php

File

vendor/php-http/guzzle7-adapter/src/Client.php, line 22

Namespace

Http\Adapter\Guzzle7
View source
final class Client implements HttpClient, HttpAsyncClient {
    
    /**
     * @var ClientInterface
     */
    private $guzzle;
    public function __construct(?ClientInterface $guzzle = null) {
        if (!$guzzle) {
            $guzzle = self::buildClient();
        }
        $this->guzzle = $guzzle;
    }
    
    /**
     * Factory method to create the Guzzle 7 adapter with custom Guzzle configuration.
     */
    public static function createWithConfig(array $config) : Client {
        return new self(self::buildClient($config));
    }
    public function sendRequest(RequestInterface $request) : ResponseInterface {
        return $this->sendAsyncRequest($request)
            ->wait();
    }
    public function sendAsyncRequest(RequestInterface $request) {
        $promise = $this->guzzle
            ->sendAsync($request);
        return new Promise($promise, $request);
    }
    
    /**
     * Build the Guzzle client instance.
     */
    private static function buildClient(array $config = []) : GuzzleClient {
        $handlerStack = new HandlerStack(Utils::chooseHandler());
        $handlerStack->push(Middleware::prepareBody(), 'prepare_body');
        $config = array_merge([
            'handler' => $handlerStack,
        ], $config);
        return new GuzzleClient($config);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
Client::$guzzle private property
Client::buildClient private static function Build the Guzzle client instance.
Client::createWithConfig public static function Factory method to create the Guzzle 7 adapter with custom Guzzle configuration.
Client::sendAsyncRequest public function Sends a PSR-7 request in an asynchronous way. Overrides HttpAsyncClient::sendAsyncRequest
Client::sendRequest public function
Client::__construct public function

API Navigation

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