mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
Merged master
This commit is contained in:
64
src/Service/Connector/AbstractProvider.php
Normal file
64
src/Service/Connector/AbstractProvider.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\Connector;
|
||||
|
||||
use App\Entity\Domain;
|
||||
use Psr\Cache\CacheItemInterface;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
abstract class AbstractProvider
|
||||
{
|
||||
protected array $authData;
|
||||
|
||||
public function __construct(
|
||||
protected CacheItemPoolInterface $cacheItemPool
|
||||
) {
|
||||
}
|
||||
|
||||
abstract public static function verifyAuthData(array $authData, HttpClientInterface $client): array;
|
||||
|
||||
abstract public function orderDomain(Domain $domain, bool $dryRun): void;
|
||||
|
||||
public function isSupported(Domain ...$domainList): bool
|
||||
{
|
||||
$item = $this->getCachedTldList();
|
||||
if (!$item->isHit()) {
|
||||
$supportedTldList = $this->getSupportedTldList();
|
||||
$item
|
||||
->set($supportedTldList)
|
||||
->expiresAfter(new \DateInterval('PT1H'));
|
||||
$this->cacheItemPool->saveDeferred($item);
|
||||
} else {
|
||||
$supportedTldList = $item->get();
|
||||
}
|
||||
|
||||
$extensionList = [];
|
||||
foreach ($domainList as $domain) {
|
||||
// We want to check the support of TLDs and SLDs here.
|
||||
// For example, it is not enough for the Connector to support .fr for it to support the domain name example.asso.fr.
|
||||
// It must support .asso.fr.
|
||||
$extension = explode('.', $domain->getLdhName(), 2)[1];
|
||||
if (!in_array($extension, $extensionList)) {
|
||||
$extensionList[] = $extension;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($extensionList as $extension) {
|
||||
if (!in_array($extension, $supportedTldList)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function authenticate(array $authData): void
|
||||
{
|
||||
$this->authData = $authData;
|
||||
}
|
||||
|
||||
abstract protected function getCachedTldList(): CacheItemInterface;
|
||||
|
||||
abstract protected function getSupportedTldList(): array;
|
||||
}
|
||||
Reference in New Issue
Block a user