From 28fb5f2fc31d89c44dc99641503d811ae1f40f42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Wed, 10 Sep 2025 21:35:43 +0200 Subject: [PATCH 1/4] feat: add IANA fields for accredited registrars --- migrations/Version20250910171544.php | 48 +++++++++++ src/Config/RegistrarStatus.php | 10 +++ src/Entity/Entity.php | 81 +++++++++++++++++++ src/Entity/Tld.php | 3 +- .../UpdateRdapServersHandler.php | 7 ++ src/Service/RDAPService.php | 76 +++++++++++++---- 6 files changed, 207 insertions(+), 18 deletions(-) create mode 100644 migrations/Version20250910171544.php create mode 100644 src/Config/RegistrarStatus.php diff --git a/migrations/Version20250910171544.php b/migrations/Version20250910171544.php new file mode 100644 index 0000000..a1050d4 --- /dev/null +++ b/migrations/Version20250910171544.php @@ -0,0 +1,48 @@ +addSql('ALTER TABLE entity ADD registrar_name_iana VARCHAR(255) DEFAULT NULL'); + $this->addSql('ALTER TABLE entity ADD rdap_base_url_iana VARCHAR(255) DEFAULT NULL'); + $this->addSql('ALTER TABLE entity ADD status_iana VARCHAR(255) DEFAULT NULL'); + $this->addSql('ALTER TABLE entity ADD updated_iana DATE DEFAULT NULL'); + $this->addSql('ALTER TABLE entity ADD date_iana DATE DEFAULT NULL'); + $this->addSql('COMMENT ON COLUMN entity.updated_iana IS \'(DC2Type:date_immutable)\''); + $this->addSql('COMMENT ON COLUMN entity.date_iana IS \'(DC2Type:date_immutable)\''); + + $this->addSql("DELETE FROM domain_entity de USING entity e WHERE de.entity_uid = e.id AND e.handle ~ '^[0-9]+$'"); + $this->addSql("DELETE FROM entity_event ev USING entity e WHERE ev.entity_uid = e.id AND e.handle ~ '^[0-9]+$'"); + $this->addSql("DELETE FROM nameserver_entity ne USING entity e WHERE ne.entity_uid = e.id AND e.handle ~ '^[0-9]+$'"); + $this->addSql("DELETE FROM entity WHERE handle ~ '^[0-9]+$'"); + + + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE entity DROP registrar_name_iana'); + $this->addSql('ALTER TABLE entity DROP rdap_base_url_iana'); + $this->addSql('ALTER TABLE entity DROP status_iana'); + $this->addSql('ALTER TABLE entity DROP updated_iana'); + $this->addSql('ALTER TABLE entity DROP date_iana'); + } +} diff --git a/src/Config/RegistrarStatus.php b/src/Config/RegistrarStatus.php new file mode 100644 index 0000000..9cc9ace --- /dev/null +++ b/src/Config/RegistrarStatus.php @@ -0,0 +1,10 @@ +domainEntities = new ArrayCollection(); @@ -242,4 +263,64 @@ class Entity return $this; } + + public function getRegistrarNameIANA(): ?string + { + return $this->registrarNameIANA; + } + + public function setRegistrarNameIANA(?string $registrarNameIANA): static + { + $this->registrarNameIANA = $registrarNameIANA; + + return $this; + } + + public function getRdapBaseUrlIANA(): ?string + { + return $this->rdapBaseUrlIANA; + } + + public function setRdapBaseUrlIANA(?string $rdapBaseUrlIANA): static + { + $this->rdapBaseUrlIANA = $rdapBaseUrlIANA; + + return $this; + } + + public function getStatusIANA(): ?RegistrarStatus + { + return $this->statusIANA; + } + + public function setStatusIANA(?RegistrarStatus $statusIANA): static + { + $this->statusIANA = $statusIANA; + + return $this; + } + + public function getUpdatedIANA(): ?\DateTimeImmutable + { + return $this->updatedIANA; + } + + public function setUpdatedIANA(?\DateTimeImmutable $updatedIANA): static + { + $this->updatedIANA = $updatedIANA; + + return $this; + } + + public function getDateIANA(): ?\DateTimeImmutable + { + return $this->dateIANA; + } + + public function setDateIANA(?\DateTimeImmutable $dateIANA): static + { + $this->dateIANA = $dateIANA; + + return $this; + } } diff --git a/src/Entity/Tld.php b/src/Entity/Tld.php index c39f127..8bda5b5 100644 --- a/src/Entity/Tld.php +++ b/src/Entity/Tld.php @@ -115,12 +115,13 @@ class Tld public function getTld(): ?string { - return '' === $this->tld ? '.' : $this->tld; + return $this->tld; } public function setTld(string $tld): static { $this->tld = RDAPService::convertToIdn($tld); + if($this->tld === '') $this->tld = '.'; return $this; } diff --git a/src/MessageHandler/UpdateRdapServersHandler.php b/src/MessageHandler/UpdateRdapServersHandler.php index 5ccc811..49b1d9e 100644 --- a/src/MessageHandler/UpdateRdapServersHandler.php +++ b/src/MessageHandler/UpdateRdapServersHandler.php @@ -65,6 +65,13 @@ final readonly class UpdateRdapServersHandler $throws[] = $throwable; } + + try { + $this->RDAPService->updateRegistrarListIANA(); + } catch (\Throwable $throwable) { + $throws[] = $throwable; + } + if (!empty($throws)) { throw $throws[0]; } diff --git a/src/Service/RDAPService.php b/src/Service/RDAPService.php index f9deb11..b6520af 100644 --- a/src/Service/RDAPService.php +++ b/src/Service/RDAPService.php @@ -5,6 +5,7 @@ namespace App\Service; use App\Config\DnsKey\Algorithm; use App\Config\DnsKey\DigestType; use App\Config\EventAction; +use App\Config\RegistrarStatus; use App\Config\TldType; use App\Entity\DnsKey; use App\Entity\Domain; @@ -94,11 +95,6 @@ readonly class RDAPService 'Private', ]; - /* @see https://www.iana.org/assignments/registrar-ids/registrar-ids.xhtml */ - public const IANA_RESERVED_IDS = [ - 1, 3, 8, 119, 365, 376, 9994, 9995, 9996, 9997, 9998, 9999, 10009, 4000001, 8888888, - ]; - public function __construct(private HttpClientInterface $client, private EntityRepository $entityRepository, private DomainRepository $domainRepository, @@ -551,24 +547,31 @@ readonly class RDAPService $entity = $this->entityRepository->findOneBy([ 'handle' => $rdapEntity['handle'], - 'tld' => is_numeric($rdapEntity['handle']) ? null : $tld, + 'tld' => $tld, ]); + if(null === $entity) { + $entity = $this->entityRepository->findOneBy([ + 'handle' => $rdapEntity['handle'], + 'tld' => null, + ]); + } + if (null === $entity) { - $entity = new Entity(); + $entity = (new Entity())->setTld($tld); $this->logger->info('The entity {handle} was not known to this Domain Watchdog instance.', [ 'handle' => $rdapEntity['handle'], ]); } - $entity->setHandle($rdapEntity['handle'])->setTld(is_numeric($rdapEntity['handle']) ? null : $tld); + $entity->setHandle($rdapEntity['handle']); - if (isset($rdapEntity['remarks']) && is_array($rdapEntity['remarks']) && !is_numeric($rdapEntity['handle'])) { + if (isset($rdapEntity['remarks']) && is_array($rdapEntity['remarks']) && $entity->getStatusIANA() === null) { $entity->setRemarks($rdapEntity['remarks']); } - if (isset($rdapEntity['vcardArray']) && !in_array($rdapEntity['handle'], self::IANA_RESERVED_IDS)) { + if (isset($rdapEntity['vcardArray']) && $entity->getStatusIANA() === null) { if (empty($entity->getJCard())) { if (!array_key_exists('elements', $rdapEntity['vcardArray'])) { $entity->setJCard($rdapEntity['vcardArray']); @@ -602,7 +605,7 @@ readonly class RDAPService } } - if ($isIANAid || !isset($rdapEntity['events']) || in_array($rdapEntity['handle'], self::IANA_RESERVED_IDS)) { + if ($isIANAid || !isset($rdapEntity['events']) || $entity->getStatusIANA() !== null) { return $entity; } @@ -704,22 +707,26 @@ readonly class RDAPService { foreach ($dnsRoot['services'] as $service) { foreach ($service[0] as $tld) { - if ('' === $tld && null === $this->tldRepository->findOneBy(['tld' => $tld])) { - $this->em->persist((new Tld())->setTld('')->setType(TldType::root)); + if ('.' === $tld && null === $this->tldRepository->findOneBy(['tld' => $tld])) { + $this->em->persist((new Tld())->setTld('.')->setType(TldType::root)); $this->em->flush(); } - $tldReference = $this->em->getReference(Tld::class, $tld); + $tldEntity = $this->tldRepository->findOneBy(['tld' => $tld]); + if($tldEntity === null) { + $tldEntity = (new Tld())->setTld($tld)->setType(TldType::gTLD); + $this->em->persist($tldEntity); + } foreach ($service[1] as $rdapServerUrl) { - $server = $this->rdapServerRepository->findOneBy(['tld' => $tldReference, 'url' => $rdapServerUrl]); + $server = $this->rdapServerRepository->findOneBy(['tld' => $tldEntity->getTld(), 'url' => $rdapServerUrl]); if (null === $server) { $server = new RdapServer(); } $server - ->setTld($tldReference) + ->setTld($tldEntity) ->setUrl($rdapServerUrl) ->setUpdatedAt(new \DateTimeImmutable($dnsRoot['publication'] ?? 'now')); @@ -792,6 +799,41 @@ readonly class RDAPService $this->em->flush(); } + /** + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws \Exception + */ + public function updateRegistrarListIANA(): void + { + $this->logger->info('Start of retrieval of the list of Registrar IDs according to IANA.'); + $registrarList = $this->client->request( + 'GET', 'https://www.iana.org/assignments/registrar-ids/registrar-ids.xml' + ); + + $data = new \SimpleXMLElement($registrarList->getContent()); + + foreach($data->registry->record as $registrar) { + $entity = $this->entityRepository->findOneBy(['handle' => $registrar->value, 'tld' => null]); + if($entity === null) $entity = new Entity(); + $entity + ->setHandle(strval($registrar->value))->setTld(null) + ->setRegistrarNameIANA(strval($registrar->name)) + ->setStatusIANA(RegistrarStatus::from(strval($registrar->status))) + ->setRdapBaseUrlIANA($registrar->rdapurl->count() ? strval($registrar->rdapurl->server) : null) + ->setUpdatedIANA($registrar->attributes()->updated !== null ? new \DateTimeImmutable(strval($registrar->attributes()->updated)) : null) + ->setDateIANA($registrar->attributes()->date !== null ? new \DateTimeImmutable(strval($registrar->attributes()->date)) : null) + ->setJCard(["vcard", [["version", [], "text", "4.0"], ["fn", [], "text", $entity->getRegistrarNameIANA()]]]) + ->setRemarks(null); + + $this->em->persist($entity); + } + $this->em->flush(); + } + private function getTldType(string $tld): ?TldType { if (in_array(strtolower($tld), self::ISO_TLD_EXCEPTION)) { @@ -835,7 +877,7 @@ readonly class RDAPService if (null === $gtTldEntity) { $gtTldEntity = new Tld(); - $gtTldEntity->setTld($gTld['gTLD']); + $gtTldEntity->setTld($gTld['gTLD'])->setType(TldType::gTLD); $this->logger->notice('New gTLD detected according to ICANN ({tld}).', [ 'tld' => $gTld['gTLD'], ]); From 10e573e483432418761751a1d8894857bd0ea476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Wed, 10 Sep 2025 21:39:17 +0200 Subject: [PATCH 2/4] chore: code format --- migrations/Version20250910171544.php | 2 -- src/Entity/Entity.php | 1 - src/Entity/Tld.php | 4 +++- .../UpdateRdapServersHandler.php | 1 - src/Service/RDAPService.php | 22 ++++++++++--------- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/migrations/Version20250910171544.php b/migrations/Version20250910171544.php index a1050d4..95df1a7 100644 --- a/migrations/Version20250910171544.php +++ b/migrations/Version20250910171544.php @@ -32,8 +32,6 @@ final class Version20250910171544 extends AbstractMigration $this->addSql("DELETE FROM entity_event ev USING entity e WHERE ev.entity_uid = e.id AND e.handle ~ '^[0-9]+$'"); $this->addSql("DELETE FROM nameserver_entity ne USING entity e WHERE ne.entity_uid = e.id AND e.handle ~ '^[0-9]+$'"); $this->addSql("DELETE FROM entity WHERE handle ~ '^[0-9]+$'"); - - } public function down(Schema $schema): void diff --git a/src/Entity/Entity.php b/src/Entity/Entity.php index d1b9263..f593f71 100644 --- a/src/Entity/Entity.php +++ b/src/Entity/Entity.php @@ -92,7 +92,6 @@ class Entity #[Groups(['entity:item', 'domain:item'])] private ?string $registrarNameIANA = null; - #[ORM\Column(length: 255, nullable: true)] #[Groups(['entity:item', 'domain:item'])] private ?string $rdapBaseUrlIANA = null; diff --git a/src/Entity/Tld.php b/src/Entity/Tld.php index 8bda5b5..21ab3dc 100644 --- a/src/Entity/Tld.php +++ b/src/Entity/Tld.php @@ -121,7 +121,9 @@ class Tld public function setTld(string $tld): static { $this->tld = RDAPService::convertToIdn($tld); - if($this->tld === '') $this->tld = '.'; + if ('' === $this->tld) { + $this->tld = '.'; + } return $this; } diff --git a/src/MessageHandler/UpdateRdapServersHandler.php b/src/MessageHandler/UpdateRdapServersHandler.php index 49b1d9e..d73b2f7 100644 --- a/src/MessageHandler/UpdateRdapServersHandler.php +++ b/src/MessageHandler/UpdateRdapServersHandler.php @@ -65,7 +65,6 @@ final readonly class UpdateRdapServersHandler $throws[] = $throwable; } - try { $this->RDAPService->updateRegistrarListIANA(); } catch (\Throwable $throwable) { diff --git a/src/Service/RDAPService.php b/src/Service/RDAPService.php index b6520af..2374ff6 100644 --- a/src/Service/RDAPService.php +++ b/src/Service/RDAPService.php @@ -550,7 +550,7 @@ readonly class RDAPService 'tld' => $tld, ]); - if(null === $entity) { + if (null === $entity) { $entity = $this->entityRepository->findOneBy([ 'handle' => $rdapEntity['handle'], 'tld' => null, @@ -567,11 +567,11 @@ readonly class RDAPService $entity->setHandle($rdapEntity['handle']); - if (isset($rdapEntity['remarks']) && is_array($rdapEntity['remarks']) && $entity->getStatusIANA() === null) { + if (isset($rdapEntity['remarks']) && is_array($rdapEntity['remarks']) && null === $entity->getStatusIANA()) { $entity->setRemarks($rdapEntity['remarks']); } - if (isset($rdapEntity['vcardArray']) && $entity->getStatusIANA() === null) { + if (isset($rdapEntity['vcardArray']) && null === $entity->getStatusIANA()) { if (empty($entity->getJCard())) { if (!array_key_exists('elements', $rdapEntity['vcardArray'])) { $entity->setJCard($rdapEntity['vcardArray']); @@ -605,7 +605,7 @@ readonly class RDAPService } } - if ($isIANAid || !isset($rdapEntity['events']) || $entity->getStatusIANA() !== null) { + if ($isIANAid || !isset($rdapEntity['events']) || null !== $entity->getStatusIANA()) { return $entity; } @@ -713,7 +713,7 @@ readonly class RDAPService } $tldEntity = $this->tldRepository->findOneBy(['tld' => $tld]); - if($tldEntity === null) { + if (null === $tldEntity) { $tldEntity = (new Tld())->setTld($tld)->setType(TldType::gTLD); $this->em->persist($tldEntity); } @@ -816,17 +816,19 @@ readonly class RDAPService $data = new \SimpleXMLElement($registrarList->getContent()); - foreach($data->registry->record as $registrar) { + foreach ($data->registry->record as $registrar) { $entity = $this->entityRepository->findOneBy(['handle' => $registrar->value, 'tld' => null]); - if($entity === null) $entity = new Entity(); + if (null === $entity) { + $entity = new Entity(); + } $entity ->setHandle(strval($registrar->value))->setTld(null) ->setRegistrarNameIANA(strval($registrar->name)) ->setStatusIANA(RegistrarStatus::from(strval($registrar->status))) ->setRdapBaseUrlIANA($registrar->rdapurl->count() ? strval($registrar->rdapurl->server) : null) - ->setUpdatedIANA($registrar->attributes()->updated !== null ? new \DateTimeImmutable(strval($registrar->attributes()->updated)) : null) - ->setDateIANA($registrar->attributes()->date !== null ? new \DateTimeImmutable(strval($registrar->attributes()->date)) : null) - ->setJCard(["vcard", [["version", [], "text", "4.0"], ["fn", [], "text", $entity->getRegistrarNameIANA()]]]) + ->setUpdatedIANA(null !== $registrar->attributes()->updated ? new \DateTimeImmutable(strval($registrar->attributes()->updated)) : null) + ->setDateIANA(null !== $registrar->attributes()->date ? new \DateTimeImmutable(strval($registrar->attributes()->date)) : null) + ->setJCard(['vcard', [['version', [], 'text', '4.0'], ['fn', [], 'text', $entity->getRegistrarNameIANA()]]]) ->setRemarks(null); $this->em->persist($entity); From acc3a4550a08f107d6fa80efa1e17f512110fccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Wed, 10 Sep 2025 22:17:19 +0200 Subject: [PATCH 3/4] chore: rename table columns --- migrations/Version20250910201456.php | 54 +++++++++++++++++ src/Entity/Entity.php | 81 +++----------------------- src/Entity/IanaAccreditation.php | 87 ++++++++++++++++++++++++++++ src/Service/RDAPService.php | 27 +++++---- 4 files changed, 165 insertions(+), 84 deletions(-) create mode 100644 migrations/Version20250910201456.php create mode 100644 src/Entity/IanaAccreditation.php diff --git a/migrations/Version20250910201456.php b/migrations/Version20250910201456.php new file mode 100644 index 0000000..3424ca3 --- /dev/null +++ b/migrations/Version20250910201456.php @@ -0,0 +1,54 @@ +addSql('ALTER TABLE entity ADD iana_registrar_name VARCHAR(255) DEFAULT NULL'); + $this->addSql('ALTER TABLE entity ADD iana_rdap_base_url VARCHAR(255) DEFAULT NULL'); + $this->addSql('ALTER TABLE entity ADD iana_status VARCHAR(255) DEFAULT NULL'); + $this->addSql('ALTER TABLE entity ADD iana_updated DATE DEFAULT NULL'); + $this->addSql('ALTER TABLE entity ADD iana_date DATE DEFAULT NULL'); + $this->addSql('ALTER TABLE entity DROP registrar_name_iana'); + $this->addSql('ALTER TABLE entity DROP rdap_base_url_iana'); + $this->addSql('ALTER TABLE entity DROP status_iana'); + $this->addSql('ALTER TABLE entity DROP updated_iana'); + $this->addSql('ALTER TABLE entity DROP date_iana'); + $this->addSql('COMMENT ON COLUMN entity.iana_updated IS \'(DC2Type:date_immutable)\''); + $this->addSql('COMMENT ON COLUMN entity.iana_date IS \'(DC2Type:date_immutable)\''); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE SCHEMA public'); + $this->addSql('ALTER TABLE entity ADD registrar_name_iana VARCHAR(255) DEFAULT NULL'); + $this->addSql('ALTER TABLE entity ADD rdap_base_url_iana VARCHAR(255) DEFAULT NULL'); + $this->addSql('ALTER TABLE entity ADD status_iana VARCHAR(255) DEFAULT NULL'); + $this->addSql('ALTER TABLE entity ADD updated_iana DATE DEFAULT NULL'); + $this->addSql('ALTER TABLE entity ADD date_iana DATE DEFAULT NULL'); + $this->addSql('ALTER TABLE entity DROP iana_registrar_name'); + $this->addSql('ALTER TABLE entity DROP iana_rdap_base_url'); + $this->addSql('ALTER TABLE entity DROP iana_status'); + $this->addSql('ALTER TABLE entity DROP iana_updated'); + $this->addSql('ALTER TABLE entity DROP iana_date'); + $this->addSql('COMMENT ON COLUMN entity.updated_iana IS \'(DC2Type:date_immutable)\''); + $this->addSql('COMMENT ON COLUMN entity.date_iana IS \'(DC2Type:date_immutable)\''); + } +} diff --git a/src/Entity/Entity.php b/src/Entity/Entity.php index f593f71..b976339 100644 --- a/src/Entity/Entity.php +++ b/src/Entity/Entity.php @@ -3,13 +3,11 @@ namespace App\Entity; use ApiPlatform\Metadata\ApiResource; -use ApiPlatform\Metadata\Get; -use App\Config\RegistrarStatus; use App\Repository\EntityRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; -use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; +use Doctrine\ORM\Mapping\Embedded; use Symfony\Component\Serializer\Attribute\Groups; use Symfony\Component\Serializer\Attribute\SerializedName; @@ -88,23 +86,8 @@ class Entity #[Groups(['entity:item', 'domain:item'])] private ?array $remarks = null; - #[ORM\Column(length: 255, nullable: true)] - #[Groups(['entity:item', 'domain:item'])] - private ?string $registrarNameIANA = null; - - #[ORM\Column(length: 255, nullable: true)] - #[Groups(['entity:item', 'domain:item'])] - private ?string $rdapBaseUrlIANA = null; - - #[ORM\Column(nullable: true, enumType: RegistrarStatus::class)] - #[Groups(['entity:item', 'domain:item'])] - private ?RegistrarStatus $statusIANA = null; - - #[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)] - private ?\DateTimeImmutable $updatedIANA = null; - - #[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)] - private ?\DateTimeImmutable $dateIANA = null; + #[Embedded(class: IanaAccreditation::class, columnPrefix: 'iana_')] + private ?IanaAccreditation $ianaAccreditation; public function __construct() { @@ -263,63 +246,13 @@ class Entity return $this; } - public function getRegistrarNameIANA(): ?string + public function getIanaAccreditation(): ?IanaAccreditation { - return $this->registrarNameIANA; + return $this->ianaAccreditation; } - public function setRegistrarNameIANA(?string $registrarNameIANA): static + public function setIanaAccreditation(?IanaAccreditation $ianaAccreditation): void { - $this->registrarNameIANA = $registrarNameIANA; - - return $this; - } - - public function getRdapBaseUrlIANA(): ?string - { - return $this->rdapBaseUrlIANA; - } - - public function setRdapBaseUrlIANA(?string $rdapBaseUrlIANA): static - { - $this->rdapBaseUrlIANA = $rdapBaseUrlIANA; - - return $this; - } - - public function getStatusIANA(): ?RegistrarStatus - { - return $this->statusIANA; - } - - public function setStatusIANA(?RegistrarStatus $statusIANA): static - { - $this->statusIANA = $statusIANA; - - return $this; - } - - public function getUpdatedIANA(): ?\DateTimeImmutable - { - return $this->updatedIANA; - } - - public function setUpdatedIANA(?\DateTimeImmutable $updatedIANA): static - { - $this->updatedIANA = $updatedIANA; - - return $this; - } - - public function getDateIANA(): ?\DateTimeImmutable - { - return $this->dateIANA; - } - - public function setDateIANA(?\DateTimeImmutable $dateIANA): static - { - $this->dateIANA = $dateIANA; - - return $this; + $this->ianaAccreditation = $ianaAccreditation; } } diff --git a/src/Entity/IanaAccreditation.php b/src/Entity/IanaAccreditation.php new file mode 100644 index 0000000..e2f3b82 --- /dev/null +++ b/src/Entity/IanaAccreditation.php @@ -0,0 +1,87 @@ +registrarName; + } + + public function setRegistrarName(?string $registrarName): static + { + $this->registrarName = $registrarName; + + return $this; + } + + public function getRdapBaseUrl(): ?string + { + return $this->rdapBaseUrl; + } + + public function setRdapBaseUrl(?string $rdapBaseUrl): static + { + $this->rdapBaseUrl = $rdapBaseUrl; + + return $this; + } + + public function getStatus(): ?RegistrarStatus + { + return $this->status; + } + + public function setStatus(?RegistrarStatus $status): static + { + $this->status = $status; + + return $this; + } + + public function getUpdated(): ?\DateTimeImmutable + { + return $this->updated; + } + + public function setUpdated(?\DateTimeImmutable $updated): static + { + $this->updated = $updated; + + return $this; + } + + public function getDate(): ?\DateTimeImmutable + { + return $this->date; + } + + public function setDate(?\DateTimeImmutable $date): static + { + $this->date = $date; + + return $this; + } +} diff --git a/src/Service/RDAPService.php b/src/Service/RDAPService.php index 2374ff6..a9df2d0 100644 --- a/src/Service/RDAPService.php +++ b/src/Service/RDAPService.php @@ -14,6 +14,7 @@ use App\Entity\DomainEvent; use App\Entity\DomainStatus; use App\Entity\Entity; use App\Entity\EntityEvent; +use App\Entity\IanaAccreditation; use App\Entity\Nameserver; use App\Entity\NameserverEntity; use App\Entity\RdapServer; @@ -567,11 +568,11 @@ readonly class RDAPService $entity->setHandle($rdapEntity['handle']); - if (isset($rdapEntity['remarks']) && is_array($rdapEntity['remarks']) && null === $entity->getStatusIANA()) { + if (isset($rdapEntity['remarks']) && is_array($rdapEntity['remarks']) && null === $entity->getIanaAccreditation()) { $entity->setRemarks($rdapEntity['remarks']); } - if (isset($rdapEntity['vcardArray']) && null === $entity->getStatusIANA()) { + if (isset($rdapEntity['vcardArray']) && null === $entity->getIanaAccreditation()) { if (empty($entity->getJCard())) { if (!array_key_exists('elements', $rdapEntity['vcardArray'])) { $entity->setJCard($rdapEntity['vcardArray']); @@ -605,7 +606,7 @@ readonly class RDAPService } } - if ($isIANAid || !isset($rdapEntity['events']) || null !== $entity->getStatusIANA()) { + if ($isIANAid || !isset($rdapEntity['events']) || null !== $entity->getIanaAccreditation()) { return $entity; } @@ -822,15 +823,21 @@ readonly class RDAPService $entity = new Entity(); } $entity - ->setHandle(strval($registrar->value))->setTld(null) - ->setRegistrarNameIANA(strval($registrar->name)) - ->setStatusIANA(RegistrarStatus::from(strval($registrar->status))) - ->setRdapBaseUrlIANA($registrar->rdapurl->count() ? strval($registrar->rdapurl->server) : null) - ->setUpdatedIANA(null !== $registrar->attributes()->updated ? new \DateTimeImmutable(strval($registrar->attributes()->updated)) : null) - ->setDateIANA(null !== $registrar->attributes()->date ? new \DateTimeImmutable(strval($registrar->attributes()->date)) : null) - ->setJCard(['vcard', [['version', [], 'text', '4.0'], ['fn', [], 'text', $entity->getRegistrarNameIANA()]]]) + ->setHandle($registrar->value) + ->setTld(null) + ->setJCard(['vcard', [['version', [], 'text', '4.0'], ['fn', [], 'text', $registrar->name]]]) ->setRemarks(null); + if (null === $entity->getIanaAccreditation()) { + $entity->setIanaAccreditation(new IanaAccreditation()); + } + $entity->getIanaAccreditation() + ->setRegistrarName($registrar->name) + ->setStatus(RegistrarStatus::from($registrar->status)) + ->setRdapBaseUrl($registrar->rdapurl->count() ? ($registrar->rdapurl->server) : null) + ->setUpdated(null !== $registrar->attributes()->updated ? new \DateTimeImmutable($registrar->attributes()->updated) : null) + ->setDate(null !== $registrar->attributes()->date ? new \DateTimeImmutable($registrar->attributes()->date) : null); + $this->em->persist($entity); } $this->em->flush(); From a995866c3e2529324332ccf5051dbdf552d6e474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Wed, 10 Sep 2025 22:26:02 +0200 Subject: [PATCH 4/4] feat: add groups on properties --- src/Entity/Entity.php | 8 +++++--- src/Entity/IanaAccreditation.php | 6 ++++++ src/Service/RDAPService.php | 25 ++++++++++--------------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/Entity/Entity.php b/src/Entity/Entity.php index b976339..de6fcc9 100644 --- a/src/Entity/Entity.php +++ b/src/Entity/Entity.php @@ -87,13 +87,15 @@ class Entity private ?array $remarks = null; #[Embedded(class: IanaAccreditation::class, columnPrefix: 'iana_')] - private ?IanaAccreditation $ianaAccreditation; + #[Groups(['entity:item', 'domain:item'])] + private IanaAccreditation $ianaAccreditation; public function __construct() { $this->domainEntities = new ArrayCollection(); $this->nameserverEntities = new ArrayCollection(); $this->events = new ArrayCollection(); + $this->ianaAccreditation = new IanaAccreditation(); } public function getHandle(): ?string @@ -246,12 +248,12 @@ class Entity return $this; } - public function getIanaAccreditation(): ?IanaAccreditation + public function getIanaAccreditation(): IanaAccreditation { return $this->ianaAccreditation; } - public function setIanaAccreditation(?IanaAccreditation $ianaAccreditation): void + public function setIanaAccreditation(IanaAccreditation $ianaAccreditation): void { $this->ianaAccreditation = $ianaAccreditation; } diff --git a/src/Entity/IanaAccreditation.php b/src/Entity/IanaAccreditation.php index e2f3b82..72928f1 100644 --- a/src/Entity/IanaAccreditation.php +++ b/src/Entity/IanaAccreditation.php @@ -6,23 +6,29 @@ use App\Config\RegistrarStatus; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping\Embeddable; +use Symfony\Component\Serializer\Attribute\Groups; #[Embeddable] class IanaAccreditation { #[ORM\Column(length: 255, nullable: true)] + #[Groups(['entity:item', 'domain:item'])] private ?string $registrarName = null; #[ORM\Column(length: 255, nullable: true)] + #[Groups(['entity:item', 'domain:item'])] private ?string $rdapBaseUrl = null; #[ORM\Column(nullable: true, enumType: RegistrarStatus::class)] + #[Groups(['entity:item', 'domain:item'])] private ?RegistrarStatus $status = null; #[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)] + #[Groups(['entity:item', 'domain:item'])] private ?\DateTimeImmutable $updated = null; #[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)] + #[Groups(['entity:item', 'domain:item'])] private ?\DateTimeImmutable $date = null; public function getRegistrarName(): ?string diff --git a/src/Service/RDAPService.php b/src/Service/RDAPService.php index a9df2d0..d6b684d 100644 --- a/src/Service/RDAPService.php +++ b/src/Service/RDAPService.php @@ -14,7 +14,6 @@ use App\Entity\DomainEvent; use App\Entity\DomainStatus; use App\Entity\Entity; use App\Entity\EntityEvent; -use App\Entity\IanaAccreditation; use App\Entity\Nameserver; use App\Entity\NameserverEntity; use App\Entity\RdapServer; @@ -568,11 +567,11 @@ readonly class RDAPService $entity->setHandle($rdapEntity['handle']); - if (isset($rdapEntity['remarks']) && is_array($rdapEntity['remarks']) && null === $entity->getIanaAccreditation()) { + if (isset($rdapEntity['remarks']) && is_array($rdapEntity['remarks']) && null === $entity->getIanaAccreditation()->getStatus()) { $entity->setRemarks($rdapEntity['remarks']); } - if (isset($rdapEntity['vcardArray']) && null === $entity->getIanaAccreditation()) { + if (isset($rdapEntity['vcardArray']) && null === $entity->getIanaAccreditation()->getStatus()) { if (empty($entity->getJCard())) { if (!array_key_exists('elements', $rdapEntity['vcardArray'])) { $entity->setJCard($rdapEntity['vcardArray']); @@ -606,7 +605,7 @@ readonly class RDAPService } } - if ($isIANAid || !isset($rdapEntity['events']) || null !== $entity->getIanaAccreditation()) { + if ($isIANAid || !isset($rdapEntity['events']) || null !== $entity->getIanaAccreditation()->getStatus()) { return $entity; } @@ -826,17 +825,13 @@ readonly class RDAPService ->setHandle($registrar->value) ->setTld(null) ->setJCard(['vcard', [['version', [], 'text', '4.0'], ['fn', [], 'text', $registrar->name]]]) - ->setRemarks(null); - - if (null === $entity->getIanaAccreditation()) { - $entity->setIanaAccreditation(new IanaAccreditation()); - } - $entity->getIanaAccreditation() - ->setRegistrarName($registrar->name) - ->setStatus(RegistrarStatus::from($registrar->status)) - ->setRdapBaseUrl($registrar->rdapurl->count() ? ($registrar->rdapurl->server) : null) - ->setUpdated(null !== $registrar->attributes()->updated ? new \DateTimeImmutable($registrar->attributes()->updated) : null) - ->setDate(null !== $registrar->attributes()->date ? new \DateTimeImmutable($registrar->attributes()->date) : null); + ->setRemarks(null) + ->getIanaAccreditation() + ->setRegistrarName($registrar->name) + ->setStatus(RegistrarStatus::from($registrar->status)) + ->setRdapBaseUrl($registrar->rdapurl->count() ? ($registrar->rdapurl->server) : null) + ->setUpdated(null !== $registrar->attributes()->updated ? new \DateTimeImmutable($registrar->attributes()->updated) : null) + ->setDate(null !== $registrar->attributes()->date ? new \DateTimeImmutable($registrar->attributes()->date) : null); $this->em->persist($entity); }