mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-27 15:18:23 +00:00
refactor: use Dto class instead of array
This commit is contained in:
parent
11f4b65dbf
commit
52e0459233
@ -30,7 +30,7 @@ abstract class AbstractProvider
|
|||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected CacheItemPoolInterface $cacheItemPool,
|
protected CacheItemPoolInterface $cacheItemPool,
|
||||||
private readonly DenormalizerInterface&NormalizerInterface $serializer,
|
protected readonly DenormalizerInterface&NormalizerInterface $serializer,
|
||||||
private readonly ValidatorInterface $validator,
|
private readonly ValidatorInterface $validator,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Service\Connector;
|
namespace App\Service\Connector;
|
||||||
|
|
||||||
|
use App\Dto\Connector\DefaultProviderDto;
|
||||||
use App\Dto\Connector\EppClientProviderDto;
|
use App\Dto\Connector\EppClientProviderDto;
|
||||||
use App\Entity\Domain;
|
use App\Entity\Domain;
|
||||||
use Metaregistrar\EPP\eppCheckContactRequest;
|
use Metaregistrar\EPP\eppCheckContactRequest;
|
||||||
@ -18,6 +19,7 @@ use Psr\Cache\CacheItemInterface;
|
|||||||
use Psr\Cache\CacheItemPoolInterface;
|
use Psr\Cache\CacheItemPoolInterface;
|
||||||
use Psr\Cache\InvalidArgumentException;
|
use Psr\Cache\InvalidArgumentException;
|
||||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||||
|
use Symfony\Component\Serializer\Exception\ExceptionInterface;
|
||||||
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
||||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
@ -25,6 +27,10 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
|
|||||||
class EppClientProvider extends AbstractProvider implements CheckDomainProviderInterface
|
class EppClientProvider extends AbstractProvider implements CheckDomainProviderInterface
|
||||||
{
|
{
|
||||||
protected string $dtoClass = EppClientProviderDto::class;
|
protected string $dtoClass = EppClientProviderDto::class;
|
||||||
|
|
||||||
|
/** @var EppClientProviderDto */
|
||||||
|
protected DefaultProviderDto $authData;
|
||||||
|
|
||||||
private ?eppConnection $eppClient = null;
|
private ?eppConnection $eppClient = null;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
@ -42,8 +48,8 @@ class EppClientProvider extends AbstractProvider implements CheckDomainProviderI
|
|||||||
|
|
||||||
$this->eppClient->request(new eppHelloRequest());
|
$this->eppClient->request(new eppHelloRequest());
|
||||||
|
|
||||||
$contacts = [new eppContactHandle($this->authData['domain']['registrant'], eppContactHandle::CONTACT_TYPE_REGISTRANT)];
|
$contacts = [new eppContactHandle($this->authData->domain->registrant, eppContactHandle::CONTACT_TYPE_REGISTRANT)];
|
||||||
foreach ($this->authData['domain']['contacts'] as $role => $roid) {
|
foreach ($this->authData->domain->contacts as $role => $roid) {
|
||||||
$contacts[] = new eppContactHandle($roid, $role);
|
$contacts[] = new eppContactHandle($roid, $role);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,12 +73,12 @@ class EppClientProvider extends AbstractProvider implements CheckDomainProviderI
|
|||||||
$this->connect();
|
$this->connect();
|
||||||
|
|
||||||
$d = new eppDomain($domain->getLdhName());
|
$d = new eppDomain($domain->getLdhName());
|
||||||
$d->setRegistrant($this->authData['domain']['registrant']);
|
$d->setRegistrant($this->authData->domain->registrant);
|
||||||
$d->setPeriodUnit($this->authData['domain']['unit']);
|
$d->setPeriodUnit($this->authData->domain->unit);
|
||||||
$d->setPeriod($this->authData['domain']['period']);
|
$d->setPeriod($this->authData->domain->period);
|
||||||
$d->setAuthorisationCode($this->authData['domain']['password']);
|
$d->setAuthorisationCode($this->authData->domain->password);
|
||||||
|
|
||||||
foreach ($this->authData['domain']['contacts'] as $type => $contact) {
|
foreach ($this->authData->domain->contacts as $type => $contact) {
|
||||||
$d->addContact(new eppContactHandle($contact, $type));
|
$d->addContact(new eppContactHandle($contact, $type));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,6 +148,7 @@ class EppClientProvider extends AbstractProvider implements CheckDomainProviderI
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws eppException
|
* @throws eppException
|
||||||
|
* @throws ExceptionInterface
|
||||||
*/
|
*/
|
||||||
private function connect(): void
|
private function connect(): void
|
||||||
{
|
{
|
||||||
@ -150,27 +157,29 @@ class EppClientProvider extends AbstractProvider implements CheckDomainProviderI
|
|||||||
}
|
}
|
||||||
|
|
||||||
$conn = new eppConnection(false, null);
|
$conn = new eppConnection(false, null);
|
||||||
$conn->setHostname($this->authData['hostname']);
|
$conn->setHostname($this->authData->hostname);
|
||||||
$conn->setVersion($this->authData['version']);
|
$conn->setVersion($this->authData->version);
|
||||||
$conn->setLanguage($this->authData['language']);
|
$conn->setLanguage($this->authData->language);
|
||||||
$conn->setPort($this->authData['port']);
|
$conn->setPort($this->authData->port);
|
||||||
|
|
||||||
$conn->setUsername($this->authData['auth']['username']);
|
$conn->setUsername($this->authData->auth->username);
|
||||||
$conn->setPassword($this->authData['auth']['password']);
|
$conn->setPassword($this->authData->auth->password);
|
||||||
|
|
||||||
if (isset($this->authData['file_certificate_pem'], $this->authData['file_certificate_key'])) {
|
$ssl = (array) $this->serializer->normalize($this->authData->auth->ssl, 'json');
|
||||||
|
|
||||||
|
if (isset($this->authData->file_certificate_pem, $this->authData->file_certificate_key)) {
|
||||||
$conn->setSslContext(stream_context_create(['ssl' => [
|
$conn->setSslContext(stream_context_create(['ssl' => [
|
||||||
...$this->authData['auth']['ssl'],
|
...$ssl,
|
||||||
'local_cert' => $this->authData['file_certificate_pem'],
|
'local_cert' => $this->authData->file_certificate_pem,
|
||||||
'local_pk' => $this->authData['file_certificate_key'],
|
'local_pk' => $this->authData->file_certificate_key,
|
||||||
]]));
|
]]));
|
||||||
} else {
|
} else {
|
||||||
unset($this->authData['file_certificate_pem'], $this->authData['file_certificate_key']);
|
unset($ssl['local_cert'], $ssl['local_pk']);
|
||||||
$conn->setSslContext(stream_context_create(['ssl' => $this->authData['auth']['ssl']]));
|
$conn->setSslContext(stream_context_create(['ssl' => $ssl]));
|
||||||
}
|
}
|
||||||
|
|
||||||
$conn->setExtensions($this->authData['extURI']);
|
$conn->setExtensions($this->authData->extURI);
|
||||||
$conn->setServices($this->authData['objURI']);
|
$conn->setServices($this->authData->objURI);
|
||||||
|
|
||||||
$conn->connect();
|
$conn->connect();
|
||||||
$this->eppClient = $conn;
|
$this->eppClient = $conn;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user