Skip to content

Commit 139b36d

Browse files
committed
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
1 parent cf0ef79 commit 139b36d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Diff for: src/Api.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use GuzzleHttp\Psr7\Response;
3838
use Http\Client\HttpClient;
3939
use Http\Message\MessageFactory;
40+
use Http\Discovery\HttpClientDiscovery;
4041

4142
/**
4243
* Wrapper to manage login and exchanges with simpliest Ovh API
@@ -254,8 +255,7 @@ private function rawCall($method, $path, $content = null, $is_authenticated = tr
254255
} elseif (isset($content)) {
255256
$body = json_encode($content);
256257
}
257-
if(!is_array($headers))
258-
{
258+
if (!is_array($headers)) {
259259
$headers = [];
260260
}
261261
$headers['Content-Type'] = 'application/json; charset=utf-8';
@@ -378,6 +378,10 @@ public function getConsumerKey()
378378
*/
379379
public function getHttpClient()
380380
{
381+
if ($this->http_client === null) {
382+
$this->http_client = HttpClientDiscovery::find();
383+
}
384+
381385
return $this->http_client;
382386
}
383387

0 commit comments

Comments
 (0)