From a0edd0eb305966bad73ac90e6aaf11252be1d5bd Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Fri, 30 Oct 2015 14:36:08 +0100 Subject: [PATCH] Updates to the php-http library --- composer.json | 9 +++++---- src/Mailgun/Connection/RestClient.php | 22 +++++++++++++++++----- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index b7b4338..21ea5d9 100644 --- a/composer.json +++ b/composer.json @@ -2,15 +2,16 @@ "name": "mailgun/mailgun-php", "description": "The Mailgun SDK provides methods for all API functions.", "require": { + "php": ">=5.4.0", "guzzlehttp/psr7": "~1.2", - "php-http/httplug": "@dev", "php-http/client-implementation": "@dev", - "php-http/discovery": "@dev" + "php-http/discovery": "dev-master" }, "require-dev": { - "php": ">=5.4.0", "phpunit/phpunit": "~4.6", - "php-http/guzzle6-adapter": "@dev" + "php-http/guzzle6-adapter": "dev-master", + "php-http/httplug": "dev-master", + "php-http/message-factory": "dev-master" }, "autoload": { "psr-0": { diff --git a/src/Mailgun/Connection/RestClient.php b/src/Mailgun/Connection/RestClient.php index 1ade48f..d86d709 100644 --- a/src/Mailgun/Connection/RestClient.php +++ b/src/Mailgun/Connection/RestClient.php @@ -5,7 +5,7 @@ namespace Mailgun\Connection; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use Http\Client\HttpClient; -use Http\Discovery\HttpAdapterDiscovery; +use Http\Discovery\HttpClientDiscovery; use Mailgun\Connection\Exceptions\GenericHTTPError; use Mailgun\Connection\Exceptions\InvalidCredentials; use Mailgun\Connection\Exceptions\MissingRequiredParameters; @@ -64,9 +64,7 @@ class RestClient */ protected function send($method, $uri, $body = null, $files = [], array $headers = []) { - if ($this->httpClient === null) { - $this->httpClient = HttpAdapterDiscovery::find(); - } + $client = $this->getHttpClient(); $headers['User-Agent'] = Api::SDK_USER_AGENT.'/'.Api::SDK_VERSION; $headers['Authorization'] = 'Basic '.base64_encode(sprintf('%s:%s', Api::API_USER, $this->apiKey)); @@ -77,7 +75,7 @@ class RestClient } $request = new Request($method, $this->apiEndpoint.$uri, $headers, $body); - $response = $this->httpClient->sendRequest($request); + $response = $client->sendRequest($request); return $this->responseHandler($response); } @@ -267,4 +265,18 @@ class RestClient 'filename' => $filename, ]; } + + + /** + * + * @return HttpClient + */ + protected function getHttpClient() + { + if ($this->httpClient === null) { + $this->httpClient = HttpClientDiscovery::find(); + } + + return $this->httpClient; + } }