From 139b36db542e5747a8c48e7fb276f8e0cb4bdc9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20HULARD?= Date: Mon, 4 Apr 2016 19:12:12 +0200 Subject: [PATCH] Add `HttpClientDiscovery` support Allow to perform a dynamic client resolution based on the current context. Require the puli composer extension to be registered : https://php-http.readthedocs.org/en/latest/discovery.html#installation --- src/Api.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Api.php b/src/Api.php index f2f7cc2..e068f2e 100644 --- a/src/Api.php +++ b/src/Api.php @@ -37,6 +37,7 @@ use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use Http\Client\HttpClient; use Http\Message\MessageFactory; +use Http\Discovery\HttpClientDiscovery; /** * Wrapper to manage login and exchanges with simpliest Ovh API @@ -254,8 +255,7 @@ class Api } elseif (isset($content)) { $body = json_encode($content); } - if(!is_array($headers)) - { + if (!is_array($headers)) { $headers = []; } $headers['Content-Type'] = 'application/json; charset=utf-8'; @@ -378,6 +378,10 @@ class Api */ public function getHttpClient() { + if ($this->http_client === null) { + $this->http_client = HttpClientDiscovery::find(); + } + return $this->http_client; }