diff --git a/composer.json b/composer.json index 10ad1aee60089e63395d5e5c93cc1bdb57b826c4..45b13262c6062607069ad2eeada0d174bb24ab65 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ "source": "http://cgit.drupalcode.org/sparkpost" }, "require": { - "php-http/guzzle6-adapter": "^1.1", + "php-http/guzzle7-adapter": "^1.0", "sparkpost/sparkpost": "^2.0" } } diff --git a/modules/sparkpost_requeue/sparkpost_requeue.info.yml b/modules/sparkpost_requeue/sparkpost_requeue.info.yml index e21f3bcdbefd9ab17899d483ce75ff2451014b60..e9a99e0a2ea8d23e1530598bd3ce7fcbfafec274 100644 --- a/modules/sparkpost_requeue/sparkpost_requeue.info.yml +++ b/modules/sparkpost_requeue/sparkpost_requeue.info.yml @@ -2,7 +2,7 @@ name: "Sparkpost Requeue" type: module description: "Requeue failed Sparpost messages" core: 8.x -core_version_requirement: ^8 || ^9 +core_version_requirement: ^10 package: Sparkpost configure: sparkpost_requeue.settings_form dependencies: diff --git a/sparkpost.info.yml b/sparkpost.info.yml index fc5b43758cce24b52a12c1cf97d2ec8af66337af..43f5ce4a79fb193804aadc88a8855285af8c5dff 100644 --- a/sparkpost.info.yml +++ b/sparkpost.info.yml @@ -2,6 +2,6 @@ name: Sparkpost type: module description: Integrates Drupal site with Sparkpost - transactional mail service. core: 8.x -core_version_requirement: ^8 || ^9 +core_version_requirement: ^10 package: Sparkpost configure: sparkpost.settings_form diff --git a/src/ClientService.php b/src/ClientService.php index 3e2cfa7f2e76890f18a1b86ce78452940cd69fb1..38dfb414417fa10474a79a6967336db1c3aefb78 100644 --- a/src/ClientService.php +++ b/src/ClientService.php @@ -5,7 +5,6 @@ namespace Drupal\sparkpost; use Drupal\Core\Config\ConfigFactory; use GuzzleHttp\Client; use SparkPost\SparkPost; -use Http\Adapter\Guzzle6\Client as GuzzleAdapter; /** * Client service that sends the mails. @@ -14,6 +13,10 @@ use Http\Adapter\Guzzle6\Client as GuzzleAdapter; */ class ClientService implements ClientServiceInterface { + const GUZZLE6_ADAPTER = '\Http\Adapter\Guzzle6\Client'; + + const GUZZLE7_ADAPTER = '\Http\Adapter\Guzzle7\Client'; + /** * Regex for parsing email. */ @@ -41,12 +44,28 @@ class ClientService implements ClientServiceInterface { $this->configFactory = $configFactory; } + /** + * Get the http client adapter class. + * + * Class is different depending on the version + * of php guzzle adapter library. + * + * @return string + */ + protected function getHttpClientAdapterClass() { + if (class_exists(static::GUZZLE6_ADAPTER)) { + return static::GUZZLE6_ADAPTER; + } + return static::GUZZLE7_ADAPTER; + } + /** * {@inheritdoc} */ public function getClient() { $config = $this->configFactory->get('sparkpost.settings'); - $httpClient = new GuzzleAdapter($this->client); + $http_client_class = $this->getHttpClientAdapterClass(); + $httpClient = new $http_client_class($this->client); $options = [ 'key' => $config->get('api_key'), ];