306 lines
7.8 KiB
PHP
Raw Normal View History

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;
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(
normalizationContext: [
'groups' => [
'domain:list'
]
]
),
2024-07-17 00:19:27 +02:00
new Get(
uriTemplate: '/domains/{ldhName}', # Do not delete this line, otherwise Symfony interprets the TLD of the domain name as a return type
controller: DomainRefreshController::class,
2024-07-17 14:00:46 +02:00
normalizationContext: [
'groups' => [
'domain:item',
'event:list',
'entity:list',
'domain-entity:entity',
2024-07-18 03:03:46 +02:00
'nameserver-entity:nameserver',
'nameserver-entity:entity',
'tld:item'
2024-07-17 14:00:46 +02:00
]
2024-07-17 18:18:11 +02:00
],
read: 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-20 23:14:03 +02:00
#[Groups(['domain:item', 'domain:list', 'watchlist:item'])]
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-18 13:40:49 +02:00
#[Groups(['domain:item', 'domain:list', 'watchlist:item'])]
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')],
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;
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
private ?DateTimeImmutable $createdAt = null;
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
private ?DateTimeImmutable $updatedAt = null;
2024-07-19 18:59:21 +02:00
#[ORM\ManyToOne]
#[ORM\JoinColumn(referencedColumnName: 'tld', nullable: false)]
#[Groups(['domain:item'])]
2024-07-19 18:59:21 +02:00
private ?Tld $tld = 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();
$this->createdAt = new DateTimeImmutable('now');
$this->updatedAt = new DateTimeImmutable('now');
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
{
$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;
}
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-19 18:59:21 +02:00
public function getTld(): ?Tld
{
return $this->tld;
}
public function setTld(?Tld $tld): static
{
$this->tld = $tld;
return $this;
}
2024-07-10 23:30:59 +02:00
}