2024-07-10 23:30:59 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Entity;
|
|
|
|
|
|
2024-07-17 00:19:27 +02:00
|
|
|
use ApiPlatform\Metadata\ApiResource;
|
|
|
|
|
use ApiPlatform\Metadata\Get;
|
2024-07-17 14:00:46 +02:00
|
|
|
use ApiPlatform\Metadata\GetCollection;
|
2024-07-17 18:18:11 +02:00
|
|
|
use ApiPlatform\Metadata\Post;
|
|
|
|
|
use App\Controller\DomainRefreshController;
|
2024-07-10 23:30:59 +02:00
|
|
|
use App\Repository\DomainRepository;
|
2024-07-17 19:29:43 +02:00
|
|
|
use DateTimeImmutable;
|
2024-07-10 23:30:59 +02:00
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
|
use Doctrine\Common\Collections\Collection;
|
|
|
|
|
use Doctrine\DBAL\Types\Types;
|
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
2024-07-17 00:19:27 +02:00
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
|
|
|
|
use Symfony\Component\Serializer\Attribute\Groups;
|
2024-07-10 23:30:59 +02:00
|
|
|
|
|
|
|
|
#[ORM\Entity(repositoryClass: DomainRepository::class)]
|
2024-07-17 00:19:27 +02:00
|
|
|
#[UniqueEntity('handle')]
|
|
|
|
|
#[ApiResource(
|
|
|
|
|
operations: [
|
2024-07-17 14:00:46 +02:00
|
|
|
new GetCollection(
|
|
|
|
|
uriTemplate: '/domains',
|
|
|
|
|
normalizationContext: [
|
|
|
|
|
'groups' => [
|
|
|
|
|
'domain:list'
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
),
|
2024-07-17 00:19:27 +02:00
|
|
|
new Get(
|
|
|
|
|
uriTemplate: '/domains/{ldhName}',
|
2024-07-17 14:00:46 +02:00
|
|
|
normalizationContext: [
|
|
|
|
|
'groups' => [
|
|
|
|
|
'domain:item',
|
|
|
|
|
'event:list',
|
|
|
|
|
'entity:list',
|
|
|
|
|
'domain-entity:entity',
|
2024-07-17 18:18:11 +02:00
|
|
|
'nameserver-entity:nameserver'
|
2024-07-17 14:00:46 +02:00
|
|
|
]
|
|
|
|
|
]
|
2024-07-17 18:18:11 +02:00
|
|
|
),
|
|
|
|
|
new Post(
|
|
|
|
|
uriTemplate: '/domains/{ldhName}',
|
|
|
|
|
status: 204,
|
|
|
|
|
controller: DomainRefreshController::class,
|
|
|
|
|
openapiContext: [
|
|
|
|
|
'summary' => 'Request an update of domain name data',
|
|
|
|
|
'description' => 'Triggers a refresh of the domain information.',
|
|
|
|
|
'requestBody' => false
|
|
|
|
|
],
|
|
|
|
|
deserialize: false
|
2024-07-17 00:19:27 +02:00
|
|
|
)
|
|
|
|
|
]
|
|
|
|
|
)]
|
2024-07-10 23:30:59 +02:00
|
|
|
class Domain
|
|
|
|
|
{
|
2024-07-13 12:49:11 +02:00
|
|
|
#[ORM\Id]
|
2024-07-10 23:30:59 +02:00
|
|
|
#[ORM\Column(length: 255)]
|
2024-07-17 14:00:46 +02:00
|
|
|
#[Groups(['domain:item', 'domain:list'])]
|
2024-07-11 17:01:16 +02:00
|
|
|
private ?string $ldhName = null;
|
2024-07-10 23:30:59 +02:00
|
|
|
|
|
|
|
|
#[ORM\Column(length: 255)]
|
2024-07-17 14:00:46 +02:00
|
|
|
#[Groups(['domain:item', 'domain:list'])]
|
2024-07-10 23:30:59 +02:00
|
|
|
private ?string $handle = null;
|
|
|
|
|
|
|
|
|
|
/**
|
2024-07-11 17:01:16 +02:00
|
|
|
* @var Collection<int, DomainEvent>
|
2024-07-10 23:30:59 +02:00
|
|
|
*/
|
2024-07-12 00:50:30 +02:00
|
|
|
#[ORM\OneToMany(targetEntity: DomainEvent::class, mappedBy: 'domain', cascade: ['persist'], orphanRemoval: true)]
|
2024-07-17 00:19:27 +02:00
|
|
|
#[Groups(['domain:item'])]
|
2024-07-10 23:30:59 +02:00
|
|
|
private Collection $events;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var Collection<int, DomainEntity>
|
|
|
|
|
*/
|
2024-07-12 00:50:30 +02:00
|
|
|
#[ORM\OneToMany(targetEntity: DomainEntity::class, mappedBy: 'domain', cascade: ['persist'], orphanRemoval: true)]
|
2024-07-17 00:19:27 +02:00
|
|
|
#[Groups(['domain:item'])]
|
2024-07-10 23:30:59 +02:00
|
|
|
private Collection $domainEntities;
|
|
|
|
|
|
2024-07-14 21:15:13 +02:00
|
|
|
#[ORM\Column(type: Types::SIMPLE_ARRAY)]
|
2024-07-17 00:19:27 +02:00
|
|
|
#[Groups(['domain:item'])]
|
2024-07-11 13:15:04 +02:00
|
|
|
private array $status = [];
|
|
|
|
|
|
2024-07-11 22:20:20 +02:00
|
|
|
/**
|
2024-07-12 15:20:24 +02:00
|
|
|
* @var Collection<int, WatchList>
|
2024-07-11 22:20:20 +02:00
|
|
|
*/
|
2024-07-12 15:20:24 +02:00
|
|
|
#[ORM\ManyToMany(targetEntity: WatchList::class, mappedBy: 'domains', cascade: ['persist'])]
|
|
|
|
|
private Collection $watchLists;
|
2024-07-11 22:20:20 +02:00
|
|
|
|
2024-07-11 17:01:16 +02:00
|
|
|
/**
|
|
|
|
|
* @var Collection<int, Nameserver>
|
|
|
|
|
*/
|
2024-07-12 00:50:30 +02:00
|
|
|
#[ORM\ManyToMany(targetEntity: Nameserver::class, inversedBy: 'domains', cascade: ['persist'])]
|
2024-07-11 22:20:20 +02:00
|
|
|
#[ORM\JoinTable(name: 'domain_nameservers',
|
2024-07-13 15:52:52 +02:00
|
|
|
joinColumns: [new ORM\JoinColumn(name: 'domain_ldh_name', referencedColumnName: 'ldh_name')],
|
2024-07-13 00:22:17 +02:00
|
|
|
inverseJoinColumns: [new ORM\JoinColumn(name: 'nameserver_ldh_name', referencedColumnName: 'ldh_name')]
|
2024-07-11 22:20:20 +02:00
|
|
|
)]
|
2024-07-17 00:19:27 +02:00
|
|
|
#[Groups(['domain:item'])]
|
2024-07-11 17:01:16 +02:00
|
|
|
private Collection $nameservers;
|
|
|
|
|
|
2024-07-17 19:29:43 +02:00
|
|
|
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
|
|
|
|
|
private ?DateTimeImmutable $createdAt = null;
|
|
|
|
|
|
|
|
|
|
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
|
|
|
|
|
private ?DateTimeImmutable $updatedAt = null;
|
|
|
|
|
|
2024-07-10 23:30:59 +02:00
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->events = new ArrayCollection();
|
|
|
|
|
$this->domainEntities = new ArrayCollection();
|
2024-07-12 15:20:24 +02:00
|
|
|
$this->watchLists = new ArrayCollection();
|
2024-07-11 17:01:16 +02:00
|
|
|
$this->nameservers = new ArrayCollection();
|
2024-07-10 23:30:59 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-11 17:01:16 +02:00
|
|
|
public function getLdhName(): ?string
|
2024-07-10 23:30:59 +02:00
|
|
|
{
|
2024-07-11 17:01:16 +02:00
|
|
|
return $this->ldhName;
|
2024-07-10 23:30:59 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-11 17:01:16 +02:00
|
|
|
public function setLdhName(string $ldhName): static
|
2024-07-10 23:30:59 +02:00
|
|
|
{
|
2024-07-13 00:22:17 +02:00
|
|
|
$this->ldhName = strtolower($ldhName);
|
2024-07-10 23:30:59 +02:00
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getHandle(): ?string
|
|
|
|
|
{
|
|
|
|
|
return $this->handle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function setHandle(string $handle): static
|
|
|
|
|
{
|
|
|
|
|
$this->handle = $handle;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-07-11 17:01:16 +02:00
|
|
|
* @return Collection<int, DomainEvent>
|
2024-07-10 23:30:59 +02:00
|
|
|
*/
|
|
|
|
|
public function getEvents(): Collection
|
|
|
|
|
{
|
|
|
|
|
return $this->events;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-11 17:01:16 +02:00
|
|
|
public function addEvent(DomainEvent $event): static
|
2024-07-10 23:30:59 +02:00
|
|
|
{
|
|
|
|
|
if (!$this->events->contains($event)) {
|
|
|
|
|
$this->events->add($event);
|
|
|
|
|
$event->setDomain($this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-11 17:01:16 +02:00
|
|
|
public function removeEvent(DomainEvent $event): static
|
2024-07-10 23:30:59 +02:00
|
|
|
{
|
|
|
|
|
if ($this->events->removeElement($event)) {
|
|
|
|
|
// set the owning side to null (unless already changed)
|
|
|
|
|
if ($event->getDomain() === $this) {
|
|
|
|
|
$event->setDomain(null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return Collection<int, DomainEntity>
|
|
|
|
|
*/
|
|
|
|
|
public function getDomainEntities(): Collection
|
|
|
|
|
{
|
|
|
|
|
return $this->domainEntities;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addDomainEntity(DomainEntity $domainEntity): static
|
|
|
|
|
{
|
|
|
|
|
if (!$this->domainEntities->contains($domainEntity)) {
|
|
|
|
|
$this->domainEntities->add($domainEntity);
|
|
|
|
|
$domainEntity->setDomain($this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function removeDomainEntity(DomainEntity $domainEntity): static
|
|
|
|
|
{
|
|
|
|
|
if ($this->domainEntities->removeElement($domainEntity)) {
|
|
|
|
|
// set the owning side to null (unless already changed)
|
|
|
|
|
if ($domainEntity->getDomain() === $this) {
|
|
|
|
|
$domainEntity->setDomain(null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-11 13:15:04 +02:00
|
|
|
public function getStatus(): array
|
|
|
|
|
{
|
|
|
|
|
return $this->status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function setStatus(array $status): static
|
|
|
|
|
{
|
|
|
|
|
$this->status = $status;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
2024-07-11 17:01:16 +02:00
|
|
|
|
2024-07-11 22:20:20 +02:00
|
|
|
/**
|
2024-07-12 15:20:24 +02:00
|
|
|
* @return Collection<int, WatchList>
|
2024-07-11 22:20:20 +02:00
|
|
|
*/
|
2024-07-12 15:20:24 +02:00
|
|
|
public function getWatchLists(): Collection
|
2024-07-11 22:20:20 +02:00
|
|
|
{
|
2024-07-12 15:20:24 +02:00
|
|
|
return $this->watchLists;
|
2024-07-11 22:20:20 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-12 15:20:24 +02:00
|
|
|
public function addWatchList(WatchList $watchList): static
|
2024-07-11 22:20:20 +02:00
|
|
|
{
|
2024-07-12 15:20:24 +02:00
|
|
|
if (!$this->watchLists->contains($watchList)) {
|
|
|
|
|
$this->watchLists->add($watchList);
|
|
|
|
|
$watchList->addDomain($this);
|
2024-07-11 22:20:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-12 15:20:24 +02:00
|
|
|
public function removeWatchList(WatchList $watchList): static
|
2024-07-11 22:20:20 +02:00
|
|
|
{
|
2024-07-12 15:20:24 +02:00
|
|
|
if ($this->watchLists->removeElement($watchList)) {
|
|
|
|
|
$watchList->removeDomain($this);
|
2024-07-11 22:20:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-11 17:01:16 +02:00
|
|
|
/**
|
|
|
|
|
* @return Collection<int, Nameserver>
|
|
|
|
|
*/
|
|
|
|
|
public function getNameservers(): Collection
|
|
|
|
|
{
|
|
|
|
|
return $this->nameservers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addNameserver(Nameserver $nameserver): static
|
|
|
|
|
{
|
|
|
|
|
if (!$this->nameservers->contains($nameserver)) {
|
|
|
|
|
$this->nameservers->add($nameserver);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function removeNameserver(Nameserver $nameserver): static
|
|
|
|
|
{
|
|
|
|
|
$this->nameservers->removeElement($nameserver);
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
2024-07-17 19:29:43 +02:00
|
|
|
|
|
|
|
|
public function getUpdatedAt(): ?DateTimeImmutable
|
|
|
|
|
{
|
|
|
|
|
return $this->updatedAt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[ORM\PrePersist]
|
|
|
|
|
#[ORM\PreUpdate]
|
|
|
|
|
public function updateTimestamps(): void
|
|
|
|
|
{
|
|
|
|
|
$this->setUpdatedAt(new DateTimeImmutable('now'));
|
|
|
|
|
if ($this->getCreatedAt() === null) {
|
|
|
|
|
$this->setCreatedAt(new DateTimeImmutable('now'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function setUpdatedAt(?DateTimeImmutable $updatedAt): void
|
|
|
|
|
{
|
|
|
|
|
$this->updatedAt = $updatedAt;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getCreatedAt(): ?DateTimeImmutable
|
|
|
|
|
{
|
|
|
|
|
return $this->createdAt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function setCreatedAt(?DateTimeImmutable $createdAt): void
|
|
|
|
|
{
|
|
|
|
|
$this->createdAt = $createdAt;
|
|
|
|
|
|
|
|
|
|
}
|
2024-07-10 23:30:59 +02:00
|
|
|
}
|