Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Opensaucesystems\Lxd;

use GuzzleHttp\Psr7\Uri;
use Http\Discovery\Psr18ClientDiscovery;
use Http\Factory\Guzzle\StreamFactory;
use Opensaucesystems\Lxd\Exception\InvalidEndpointException;
use Opensaucesystems\Lxd\Exception\ClientConnectionException;
use Opensaucesystems\Lxd\Exception\ServerException;
Expand All @@ -13,9 +16,10 @@
use Http\Client\Common\PluginClient;
use Http\Client\HttpClient;
use Http\Discovery\HttpClientDiscovery;
use Http\Discovery\MessageFactoryDiscovery;
use Http\Discovery\UriFactoryDiscovery;
use Http\Message\MessageFactory;
use Nyholm\Psr7\Factory\Psr17Factory;
use GuzzleHttp\Psr7\HttpFactory;

class Client
{
Expand Down Expand Up @@ -66,7 +70,7 @@ class Client
public function __construct(HttpClient $httpClient = null, $apiVersion = null, $url = null)
{
$this->httpClient = $httpClient ?: HttpClientDiscovery::find();
$this->messageFactory = MessageFactoryDiscovery::find();
$this->messageFactory = new Psr17Factory();
$this->apiVersion = $apiVersion ?: '1.0';
$this->url = $url ?: 'https://127.0.0.1:8443';

Expand Down Expand Up @@ -96,7 +100,7 @@ public function setUrl($url)
$this->removePlugin(PathPrepend::class);
$this->removePlugin(PathTrimEnd::class);

$this->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri($this->url)));
$this->addPlugin(new Plugin\AddHostPlugin(new Uri($this->url)));
$this->addPlugin(new PathPrepend(sprintf('/%s', $this->getApiVersion())));
$this->addPlugin(new PathTrimEnd());
}
Expand Down Expand Up @@ -132,12 +136,15 @@ public function removePlugin($fqcn)
*/
public function getHttpClient()
{

if ($this->httpClientModified) {
$this->httpClientModified = false;
$streamFactory = new HttpFactory();

$this->pluginClient = new HttpMethodsClient(
new PluginClient($this->httpClient, $this->plugins),
$this->messageFactory
$this->messageFactory,
$streamFactory
);
}
return $this->pluginClient;
Expand Down