Skip to content

Commit

Permalink
Add HttpClientDiscovery support
Browse files Browse the repository at this point in the history
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
  • Loading branch information
shulard committed Dec 13, 2016
1 parent cf0ef79 commit 139b36d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
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
Expand Down Expand Up @@ -254,8 +255,7 @@ private function rawCall($method, $path, $content = null, $is_authenticated = tr
} elseif (isset($content)) {
$body = json_encode($content);
}
if(!is_array($headers))
{
if (!is_array($headers)) {
$headers = [];
}
$headers['Content-Type'] = 'application/json; charset=utf-8';
Expand Down Expand Up @@ -378,6 +378,10 @@ public function getConsumerKey()
*/
public function getHttpClient()
{
if ($this->http_client === null) {
$this->http_client = HttpClientDiscovery::find();
}

return $this->http_client;
}

Expand Down

0 comments on commit 139b36d

Please sign in to comment.