class Client
Same name in this branch
- 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\Guzzle7View 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 |