vendor/mapeveri/multi-tenancy-bundle/src/Entity/Tenant.php line 16

  1. <?php
  2. declare (strict_types=1);
  3. namespace MultiTenancyBundle\Entity;
  4. use DateTime;
  5. use MultiTenancyBundle\Repository\TenantRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. /**
  10.  * @ORM\Entity(repositoryClass=TenantRepository::class)
  11.  */
  12. class Tenant implements \JsonSerializable
  13. {
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private $id;
  20.     /**
  21.      * @ORM\Column(type="string", unique=true)
  22.      */
  23.     private $uuid;
  24.     /**
  25.      * @ORM\Column(type="datetime", nullable=true)
  26.      */
  27.     private $created_at;
  28.     /**
  29.      * @ORM\Column(type="datetime", nullable=true)
  30.      */
  31.     private $updated_at;
  32.     /**
  33.      * @ORM\Column(type="datetime", nullable=true)
  34.      */
  35.     private $deleted_at;
  36.     /**
  37.      * @ORM\Column(type="boolean", nullable=true)
  38.      */
  39.     private $local;
  40.     /**
  41.      * @ORM\OneToMany(targetEntity=Hostname::class, mappedBy="tenant", orphanRemoval=true)
  42.      */
  43.     private $hostnames;
  44.     public function __construct()
  45.     {
  46.         $this->hostnames = new ArrayCollection();
  47.         $this->created_at = new DateTime();
  48.         $this->updated_at = new DateTime();
  49.     }
  50.     public function getId(): ?int
  51.     {
  52.         return $this->id;
  53.     }
  54.     public function getUuid(): ?string
  55.     {
  56.         return $this->uuid;
  57.     }
  58.     public function setUuid(string $uuid): self
  59.     {
  60.         $this->uuid $uuid;
  61.         return $this;
  62.     }
  63.     public function getCreatedAt(): ?\DateTimeInterface
  64.     {
  65.         return $this->created_at;
  66.     }
  67.     public function setCreatedAt(?\DateTimeInterface $created_at): self
  68.     {
  69.         $this->created_at $created_at;
  70.         return $this;
  71.     }
  72.     public function getUpdatedAt(): ?\DateTimeInterface
  73.     {
  74.         return $this->updated_at;
  75.     }
  76.     public function setUpdatedAt(?\DateTimeInterface $updated_at): self
  77.     {
  78.         $this->updated_at $updated_at;
  79.         return $this;
  80.     }
  81.     public function getDeletedAt(): ?\DateTimeInterface
  82.     {
  83.         return $this->deleted_at;
  84.     }
  85.     public function isLocal(): ?bool
  86.     {
  87.         return $this->local;
  88.     }
  89.     public function setLocal(bool $local): self
  90.     {
  91.         $this->local $local;
  92.         return $this;
  93.     }
  94.     public function setDeletedAt(?\DateTimeInterface $deleted_at): self
  95.     {
  96.         $this->deleted_at $deleted_at;
  97.         return $this;
  98.     }
  99.     /**
  100.      * @return Collection|Hostname[]
  101.      */
  102.     public function getHostnames(): Collection
  103.     {
  104.         return $this->hostnames;
  105.     }
  106.     public function addHostname(Hostname $hostname): self
  107.     {
  108.         if (!$this->hostnames->contains($hostname)) {
  109.             $this->hostnames[] = $hostname;
  110.             $hostname->setTenant($this);
  111.         }
  112.         return $this;
  113.     }
  114.     public function removeHostname(Hostname $hostname): self
  115.     {
  116.         if ($this->hostnames->removeElement($hostname)) {
  117.             // set the owning side to null (unless already changed)
  118.             if ($hostname->getTenant() === $this) {
  119.                 $hostname->setTenant(null);
  120.             }
  121.         }
  122.         return $this;
  123.     }
  124.     public function jsonSerialize(): mixed
  125.     {
  126.         return [
  127.             'id' => $this->getId(),
  128.             'uuid' => $this->getUuid(),
  129.             'created_at' => $this->getCreatedAt(),
  130.             'hostnames' => $this->getHostnames()->map(function ($object) {
  131.                 return $object->getFqdn();
  132.             })
  133.         ];
  134.     }
  135. }