1
0
mirror of https://github.com/ovh/php-ovh.git synced 2023-11-05 03:20:26 +01:00

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
This commit is contained in:
Stéphane HULARD 2016-04-04 19:12:12 +02:00
parent cf0ef79c42
commit 139b36db54
No known key found for this signature in database
GPG Key ID: 6E911128BF65AB99

View File

@ -37,6 +37,7 @@ use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\Response;
use Http\Client\HttpClient; use Http\Client\HttpClient;
use Http\Message\MessageFactory; use Http\Message\MessageFactory;
use Http\Discovery\HttpClientDiscovery;
/** /**
* Wrapper to manage login and exchanges with simpliest Ovh API * Wrapper to manage login and exchanges with simpliest Ovh API
@ -254,8 +255,7 @@ class Api
} elseif (isset($content)) { } elseif (isset($content)) {
$body = json_encode($content); $body = json_encode($content);
} }
if(!is_array($headers)) if (!is_array($headers)) {
{
$headers = []; $headers = [];
} }
$headers['Content-Type'] = 'application/json; charset=utf-8'; $headers['Content-Type'] = 'application/json; charset=utf-8';
@ -378,6 +378,10 @@ class Api
*/ */
public function getHttpClient() public function getHttpClient()
{ {
if ($this->http_client === null) {
$this->http_client = HttpClientDiscovery::find();
}
return $this->http_client; return $this->http_client;
} }