src/Entity/PostType.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. #[ORM\Entity(repositoryClass\App\Repository\PostTypeRepository::class)]
  7. class PostType implements \Stringable
  8. {
  9.     #[ORM\Id]
  10.     #[ORM\GeneratedValue]
  11.     #[ORM\Column(type'integer')]
  12.     private int $id;
  13.     #[ORM\Column(type'string'length255nullabletrue)]
  14.     private ?string $typenull;
  15.     #[ORM\Column(type'string'length255nullabletrue)]
  16.     private ?string $display_namenull;
  17.     #[ORM\OneToMany(targetEntity\App\Entity\Post::class, mappedBy'type')]
  18.     private mixed $posts;
  19.     public function __construct()
  20.     {
  21.         $this->posts = new ArrayCollection();
  22.     }
  23.     public function getId(): ?int
  24.     {
  25.         return $this->id;
  26.     }
  27.     public function getType(): ?string
  28.     {
  29.         return $this->type;
  30.     }
  31.     public function setType(?string $type): self
  32.     {
  33.         $this->type $type;
  34.         return $this;
  35.     }
  36.     public function getDisplayName(): ?string
  37.     {
  38.         return $this->display_name;
  39.     }
  40.     public function setDisplayName(?string $display_name): self
  41.     {
  42.         $this->display_name $display_name;
  43.         return $this;
  44.     }
  45.     /**
  46.      * @return Collection|Post[]
  47.      */
  48.     public function getPosts(): Collection
  49.     {
  50.         return $this->posts;
  51.     }
  52.     public function addPost(Post $post): self
  53.     {
  54.         if (!$this->posts->contains($post)) {
  55.             $this->posts[] = $post;
  56.             $post->setType($this);
  57.         }
  58.         return $this;
  59.     }
  60.     public function removePost(Post $post): self
  61.     {
  62.         if ($this->posts->contains($post)) {
  63.             $this->posts->removeElement($post);
  64.             // set the owning side to null (unless already changed)
  65.             if ($post->getType() === $this) {
  66.                 $post->setType(null);
  67.             }
  68.         }
  69.         return $this;
  70.     }
  71.     public function __toString(): string
  72.     {
  73.         return (string) $this->display_name;
  74.     }
  75. }