src/Entity/Tag.php line 26

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace App\Entity;
  11. use Doctrine\ORM\Mapping as ORM;
  12. /**
  13.  * @ORM\Entity()
  14.  * @ORM\Table(name="symfony_demo_tag")
  15.  *
  16.  * Defines the properties of the Tag entity to represent the post tags.
  17.  *
  18.  * See https://symfony.com/doc/current/doctrine.html#creating-an-entity-class
  19.  *
  20.  * @author Yonel Ceruto <yonelceruto@gmail.com>
  21.  */
  22. class Tag implements \JsonSerializable
  23. {
  24.     /**
  25.      * @ORM\Id
  26.      * @ORM\GeneratedValue
  27.      * @ORM\Column(type="integer")
  28.      */
  29.     private ?int $id null;
  30.     /**
  31.      * @ORM\Column(type="string", unique=true)
  32.      */
  33.     private ?string $name null;
  34.     public function getId(): ?int
  35.     {
  36.         return $this->id;
  37.     }
  38.     public function setName(string $name): void
  39.     {
  40.         $this->name $name;
  41.     }
  42.     public function getName(): ?string
  43.     {
  44.         return $this->name;
  45.     }
  46.     /**
  47.      * {@inheritdoc}
  48.      */
  49.     public function jsonSerialize(): string
  50.     {
  51.         // This entity implements JsonSerializable (http://php.net/manual/en/class.jsonserializable.php)
  52.         // so this method is used to customize its JSON representation when json_encode()
  53.         // is called, for example in tags|json_encode (templates/form/fields.html.twig)
  54.         return $this->name;
  55.     }
  56.     public function __toString(): string
  57.     {
  58.         return $this->name;
  59.     }
  60. }