From ea3b4f8f1ccdea82d29975a7e18d5d992d8833ba Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sat, 21 May 2022 18:02:57 +0200 Subject: [PATCH] require all necessary psr implementations the code relies on psr7, psr17 and psr18 implementations to be available, with the discovery. it no longer uses the php-http httplug interface (which was made obsolete by psr-18). php-http/client-common is also not used in the code. --- README.md | 14 +++++--------- composer.json | 10 +++++++--- src/Common/RestClient.php | 5 ++--- src/MailerLite.php | 7 +++---- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 1ab6aad..5d24aae 100644 --- a/README.md +++ b/README.md @@ -14,17 +14,13 @@ There are two ways to use MailerLite PHP SDK: If you are not familiar with Composer, learn about it [here](https://getcomposer.org/doc/01-basic-usage.md). -Then you will need to run this simple command using CLI: - -``` -composer require mailerlite/mailerlite-api-v2-php-sdk -``` - This library is built atop of [PSR-7](https://www.php-fig.org/psr/psr-7/) and -[PSR-18](https://www.php-fig.org/psr/psr-18/). If you are receiving `Http\Discovery\Exception\DiscoveryFailedException` exception, you will need to run: +[PSR-18](https://www.php-fig.org/psr/psr-18/). + +To install the library, you also need to choose an HTTP client implementation. To install the mailerlite with guzzle, run this command line: -```bash -composer require php-http/guzzle6-adapter +``` +composer require mailerlite/mailerlite-api-v2-php-sdk guzzlehttp/guzzle ``` ##### Manual (preferable for shared hostings) diff --git a/composer.json b/composer.json index 214673a..b1b558b 100644 --- a/composer.json +++ b/composer.json @@ -7,13 +7,14 @@ "type": "library", "require": { "php" : "^7.1 || ^8.0", - "php-http/client-common": "^2.0", + "psr/http-message-implementation": "*", + "psr/http-factory-implementation": "*", + "psr/http-client-implementation": "*", "php-http/discovery": "^1.7", - "nyholm/psr7": "^1.0", "ext-json": "*" }, "require-dev": { - "php-http/guzzle6-adapter": "^2.0", + "guzzlehttp/guzzle": "^7.0", "phpunit/phpunit": "6.* | 7.* | 8.* | 9.*" }, "autoload": { @@ -25,5 +26,8 @@ "psr-4": { "MailerLiteApi\\Tests\\": "tests/" } + }, + "conflict": { + "php-http/httplug": "< 2" } } diff --git a/src/Common/RestClient.php b/src/Common/RestClient.php index 2ea0613..cb008ad 100644 --- a/src/Common/RestClient.php +++ b/src/Common/RestClient.php @@ -2,7 +2,6 @@ namespace MailerLiteApi\Common; -use Http\Client\HttpClient; use Http\Discovery\Psr17FactoryDiscovery; use Http\Discovery\Psr18ClientDiscovery; use Psr\Http\Client\ClientInterface; @@ -25,9 +24,9 @@ class RestClient { /** * @param string $baseUrl * @param string $apiKey - * @param \Http\Client\HttpClient|null $httpClient + * @param ClientInterface|null $httpClient */ - public function __construct($baseUrl, $apiKey, HttpClient $httpClient = null) + public function __construct($baseUrl, $apiKey, ClientInterface $httpClient = null) { $this->baseUrl = $baseUrl; $this->apiKey = $apiKey; diff --git a/src/MailerLite.php b/src/MailerLite.php index 17033e0..f75c0bf 100644 --- a/src/MailerLite.php +++ b/src/MailerLite.php @@ -2,11 +2,10 @@ namespace MailerLiteApi; -use Http\Client\HttpClient; - use MailerLiteApi\Common\ApiConstants; use MailerLiteApi\Common\RestClient; use MailerLiteApi\Exceptions\MailerLiteSdkException; +use Psr\Http\Client\ClientInterface; /** * Class MailerLite @@ -27,11 +26,11 @@ class MailerLite { /** * @param string|null $apiKey - * @param HttpClient $client + * @param ClientInterface|null $client */ public function __construct( $apiKey = null, - HttpClient $httpClient = null + ClientInterface $httpClient = null ) { if (is_null($apiKey)) { throw new MailerLiteSdkException("API key is not provided");