src/Entity/Link.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\LinkRepository::class)]
  7. class Link 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 $display_namenull;
  15.     #[ORM\Column(type'string'length255nullabletrue)]
  16.     private ?string $urlnull;
  17.     #[ORM\ManyToMany(targetEntity\App\Entity\Post::class, mappedBy'links')]
  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 getDisplayName(): ?string
  28.     {
  29.         return $this->display_name;
  30.     }
  31.     public function setDisplayName(?string $display_name): self
  32.     {
  33.         $this->display_name $display_name;
  34.         return $this;
  35.     }
  36.     public function getUrl(): ?string
  37.     {
  38.         return $this->url;
  39.     }
  40.     public function setUrl(?string $url): self
  41.     {
  42.         $this->url $url;
  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->addLink($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.             $post->removeLink($this);
  65.         }
  66.         return $this;
  67.     }
  68.     public function __toString(): string
  69.     {
  70.         return (string) $this->display_name;
  71.     }
  72. }