From 2f841f012723e46d22db302b3e39ced8e77d1fd2 Mon Sep 17 00:00:00 2001 From: Vincent Date: Fri, 23 Aug 2024 13:38:16 +0200 Subject: [PATCH] refactor: connector abstraction --- src/Service/Connector/AbstractConnector.php | 13 +++++++++++++ src/Service/Connector/ConnectorInterface.php | 2 +- src/Service/Connector/GandiConnector.php | 4 ++-- src/Service/Connector/NamecheapConnector.php | 4 ++-- src/Service/Connector/OvhConnector.php | 4 ++-- 5 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 src/Service/Connector/AbstractConnector.php diff --git a/src/Service/Connector/AbstractConnector.php b/src/Service/Connector/AbstractConnector.php new file mode 100644 index 0000000..dd6ab4b --- /dev/null +++ b/src/Service/Connector/AbstractConnector.php @@ -0,0 +1,13 @@ +authData = $authData; + } +} diff --git a/src/Service/Connector/ConnectorInterface.php b/src/Service/Connector/ConnectorInterface.php index 3989b5e..b7d9bf5 100644 --- a/src/Service/Connector/ConnectorInterface.php +++ b/src/Service/Connector/ConnectorInterface.php @@ -7,7 +7,7 @@ use Symfony\Contracts\HttpClient\HttpClientInterface; interface ConnectorInterface { - public function __construct(array $authData, HttpClientInterface $client); + public function authenticate(array $authData); public function orderDomain(Domain $domain, bool $dryRun): void; diff --git a/src/Service/Connector/GandiConnector.php b/src/Service/Connector/GandiConnector.php index 9a35bc8..3ce7eac 100644 --- a/src/Service/Connector/GandiConnector.php +++ b/src/Service/Connector/GandiConnector.php @@ -12,11 +12,11 @@ use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; -readonly class GandiConnector implements ConnectorInterface +class GandiConnector extends AbstractConnector { private const BASE_URL = 'https://api.gandi.net/v5'; - public function __construct(private array $authData, private HttpClientInterface $client) + public function __construct(private HttpClientInterface $client) { } diff --git a/src/Service/Connector/NamecheapConnector.php b/src/Service/Connector/NamecheapConnector.php index c8ab383..609182d 100644 --- a/src/Service/Connector/NamecheapConnector.php +++ b/src/Service/Connector/NamecheapConnector.php @@ -5,13 +5,13 @@ namespace App\Service\Connector; use App\Entity\Domain; use Symfony\Contracts\HttpClient\HttpClientInterface; -readonly class NamecheapConnector implements ConnectorInterface +class NamecheapConnector extends AbstractConnector { public const BASE_URL = 'https://api.namecheap.com/xml.response'; public const SANDBOX_BASE_URL = 'http://api.sandbox.namecheap.com/xml.response'; - public function __construct(private array $authData, private HttpClientInterface $client) + public function __construct(private HttpClientInterface $client) { } diff --git a/src/Service/Connector/OvhConnector.php b/src/Service/Connector/OvhConnector.php index b99dc73..3651370 100644 --- a/src/Service/Connector/OvhConnector.php +++ b/src/Service/Connector/OvhConnector.php @@ -8,7 +8,7 @@ use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Contracts\HttpClient\HttpClientInterface; -readonly class OvhConnector implements ConnectorInterface +class OvhConnector extends AbstractConnector { public const REQUIRED_ROUTES = [ [ @@ -33,7 +33,7 @@ readonly class OvhConnector implements ConnectorInterface ], ]; - public function __construct(private array $authData, private HttpClientInterface $client) + public function __construct(private HttpClientInterface $client) { }