Skip to content

Commit

Permalink
require all necessary psr implementations
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dbu committed May 21, 2022
1 parent 9fb6b8a commit ea3b4f8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -25,5 +26,8 @@
"psr-4": {
"MailerLiteApi\\Tests\\": "tests/"
}
},
"conflict": {
"php-http/httplug": "< 2"
}
}
5 changes: 2 additions & 3 deletions src/Common/RestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace MailerLiteApi\Common;

use Http\Client\HttpClient;
use Http\Discovery\Psr17FactoryDiscovery;
use Http\Discovery\Psr18ClientDiscovery;
use Psr\Http\Client\ClientInterface;
Expand All @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions src/MailerLite.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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");
Expand Down

0 comments on commit ea3b4f8

Please sign in to comment.