domain-watchdog/src/Controller/DomainRefreshController.php

35 lines
987 B
PHP
Raw Normal View History

2024-07-17 18:18:11 +02:00
<?php
namespace App\Controller;
use App\Entity\Domain;
use App\Repository\DomainRepository;
2024-07-17 18:18:11 +02:00
use App\Service\RDAPService;
use DateTimeImmutable;
2024-07-17 18:18:11 +02:00
use Exception;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class DomainRefreshController extends AbstractController
{
public function __construct(private readonly DomainRepository $domainRepository,
private readonly RDAPService $RDAPService)
{
}
2024-07-17 18:18:11 +02:00
/**
* @throws Exception
*/
public function __invoke(string $ldhName,): ?Domain
2024-07-17 18:18:11 +02:00
{
/** @var Domain $domain */
$domain = $this->domainRepository->findOneBy(["ldhName" => $ldhName]);
if ($domain === null ||
$domain->getUpdatedAt()->diff(new DateTimeImmutable('now'))->days >= 7) {
//TODO : Domain search rate limit here, before the RDAP request
$domain = $this->RDAPService->registerDomain($ldhName);
}
return $domain;
2024-07-17 18:18:11 +02:00
}
}