2024-07-10 23:30:59 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Entity;
|
|
|
|
|
|
2024-07-17 18:18:11 +02:00
|
|
|
use ApiPlatform\Metadata\ApiResource;
|
|
|
|
|
use ApiPlatform\Metadata\Get;
|
|
|
|
|
use ApiPlatform\Metadata\GetCollection;
|
2024-07-10 23:30:59 +02:00
|
|
|
use App\Repository\NameserverRepository;
|
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
|
use Doctrine\Common\Collections\Collection;
|
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
2024-07-17 00:19:27 +02:00
|
|
|
use Symfony\Component\Serializer\Attribute\Groups;
|
2024-07-21 02:25:37 +02:00
|
|
|
use Symfony\Component\Serializer\Attribute\SerializedName;
|
2024-07-10 23:30:59 +02:00
|
|
|
|
|
|
|
|
#[ORM\Entity(repositoryClass: NameserverRepository::class)]
|
2024-07-17 18:18:11 +02:00
|
|
|
#[ApiResource(
|
|
|
|
|
operations: [
|
|
|
|
|
new GetCollection(
|
|
|
|
|
uriTemplate: '/nameservers',
|
|
|
|
|
normalizationContext: [
|
|
|
|
|
'groups' => [
|
2024-08-02 23:24:52 +02:00
|
|
|
'nameserver:list',
|
|
|
|
|
],
|
2024-07-17 18:18:11 +02:00
|
|
|
]
|
|
|
|
|
),
|
|
|
|
|
new Get(
|
|
|
|
|
uriTemplate: '/nameservers/{ldhName}',
|
|
|
|
|
normalizationContext: [
|
|
|
|
|
'groups' => [
|
|
|
|
|
'nameserver:item',
|
|
|
|
|
'nameserver-entity:entity',
|
|
|
|
|
'entity:list',
|
2024-08-02 23:24:52 +02:00
|
|
|
'event:list',
|
|
|
|
|
],
|
2024-07-17 18:18:11 +02:00
|
|
|
]
|
2024-08-02 23:24:52 +02:00
|
|
|
),
|
2024-07-17 18:18:11 +02:00
|
|
|
]
|
|
|
|
|
)]
|
2024-07-10 23:30:59 +02:00
|
|
|
class Nameserver
|
|
|
|
|
{
|
2024-07-13 00:22:17 +02:00
|
|
|
#[ORM\Id]
|
2024-07-10 23:30:59 +02:00
|
|
|
#[ORM\Column(length: 255)]
|
2024-07-17 18:18:11 +02:00
|
|
|
#[Groups(['nameserver:item', 'nameserver:list', 'domain:item'])]
|
2024-07-11 17:01:16 +02:00
|
|
|
private ?string $ldhName = null;
|
2024-07-10 23:30:59 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var Collection<int, NameserverEntity>
|
|
|
|
|
*/
|
2024-07-12 00:50:30 +02:00
|
|
|
#[ORM\OneToMany(targetEntity: NameserverEntity::class, mappedBy: 'nameserver', cascade: ['persist'], orphanRemoval: true)]
|
2024-07-17 18:18:11 +02:00
|
|
|
#[Groups(['nameserver:item', 'domain:item'])]
|
2024-07-21 02:25:37 +02:00
|
|
|
#[SerializedName('entities')]
|
2024-07-10 23:30:59 +02:00
|
|
|
private Collection $nameserverEntities;
|
|
|
|
|
|
2024-07-11 22:20:20 +02:00
|
|
|
/**
|
|
|
|
|
* @var Collection<int, Domain>
|
|
|
|
|
*/
|
|
|
|
|
#[ORM\ManyToMany(targetEntity: Domain::class, mappedBy: 'nameservers')]
|
2024-07-17 18:18:11 +02:00
|
|
|
#[Groups(['nameserver:item'])]
|
2024-07-11 22:20:20 +02:00
|
|
|
private Collection $domains;
|
|
|
|
|
|
2024-07-10 23:30:59 +02:00
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->nameserverEntities = new ArrayCollection();
|
2024-07-11 22:20:20 +02:00
|
|
|
$this->domains = 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return Collection<int, NameserverEntity>
|
|
|
|
|
*/
|
|
|
|
|
public function getNameserverEntities(): Collection
|
|
|
|
|
{
|
|
|
|
|
return $this->nameserverEntities;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addNameserverEntity(NameserverEntity $nameserverEntity): static
|
|
|
|
|
{
|
|
|
|
|
if (!$this->nameserverEntities->contains($nameserverEntity)) {
|
|
|
|
|
$this->nameserverEntities->add($nameserverEntity);
|
|
|
|
|
$nameserverEntity->setNameserver($this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function removeNameserverEntity(NameserverEntity $nameserverEntity): static
|
|
|
|
|
{
|
|
|
|
|
if ($this->nameserverEntities->removeElement($nameserverEntity)) {
|
|
|
|
|
// set the owning side to null (unless already changed)
|
|
|
|
|
if ($nameserverEntity->getNameserver() === $this) {
|
|
|
|
|
$nameserverEntity->setNameserver(null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-11 22:20:20 +02:00
|
|
|
/**
|
|
|
|
|
* @return Collection<int, Domain>
|
|
|
|
|
*/
|
|
|
|
|
public function getDomains(): Collection
|
|
|
|
|
{
|
|
|
|
|
return $this->domains;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addDomain(Domain $domain): static
|
|
|
|
|
{
|
|
|
|
|
if (!$this->domains->contains($domain)) {
|
|
|
|
|
$this->domains->add($domain);
|
|
|
|
|
$domain->addNameserver($this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function removeDomain(Domain $domain): static
|
|
|
|
|
{
|
|
|
|
|
if ($this->domains->removeElement($domain)) {
|
|
|
|
|
$domain->removeNameserver($this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
2024-07-10 23:30:59 +02:00
|
|
|
}
|